From 60a154401903b338304b368832c6a4c7d1069099 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 00:21:39 +0000 Subject: [PATCH 0001/1077] Copying new classes (cxx) and cpp files to src Will remove cpp and header files and make phreeqc an external directory. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@785 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Conc.cxx | 233 + Conc.h | 70 + ExchComp.cxx | 554 +++ ExchComp.h | 52 + Exchange.cxx | 413 ++ Exchange.h | 47 + GasPhase.cxx | 474 ++ GasPhase.h | 50 + ISolution.cxx | 334 ++ ISolution.h | 56 + Isotope.cxx | 241 + Isotope.h | 56 + KineticsComp.cxx | 504 ++ KineticsComp.h | 44 + KineticsCxx.cxx | 538 +++ KineticsCxx.h | 51 + Makefile | 348 ++ Mix.cxx | 200 + Mix.h | 39 + NameDouble.cxx | 259 + NameDouble.h | 57 + NumKeyword.cxx | 138 + NumKeyword.h | 43 + PPassemblage.cxx | 191 + PPassemblage.h | 43 + PPassemblageComp.cxx | 278 ++ PPassemblageComp.h | 47 + Parser.cxx | 1070 +++++ Parser.h | 205 + Pe_Data.cxx | 45 + Pe_Data.h | 28 + Reaction.cxx | 323 ++ Reaction.h | 45 + ReadClass.cpp | 701 +++ SAXPhreeqc.cpp | 888 ++++ SAXPhreeqc.h | 20 + SSassemblage.cxx | 171 + SSassemblage.h | 42 + SSassemblageSS.cxx | 443 ++ SSassemblageSS.h | 65 + SaxPhreeqcHandlers.h | 154 + Solution.cxx | 1102 +++++ Solution.h | 94 + Sun/examples/ex1.log | 0 Sun/examples/ex1.out | 325 ++ Sun/examples/ex10.log | 0 Sun/examples/ex10.out | 9431 +++++++++++++++++++++++++++++++++++++ Sun/examples/ex10.sel | 701 +++ Sun/examples/ex11.log | 0 Sun/examples/ex11.out | 2858 +++++++++++ Sun/examples/ex11adv.sel | 125 + Sun/examples/ex11trn.sel | 125 + Sun/examples/ex12.log | 0 Sun/examples/ex12.out | 99 + Sun/examples/ex12.sel | 44 + Sun/examples/ex12a.log | 0 Sun/examples/ex12a.out | 188 + Sun/examples/ex12a.sel | 169 + Sun/examples/ex13a.log | 0 Sun/examples/ex13a.out | 310 ++ Sun/examples/ex13a.sel | 42 + Sun/examples/ex13b.log | 0 Sun/examples/ex13b.out | 430 ++ Sun/examples/ex13b.sel | 42 + Sun/examples/ex13c.log | 0 Sun/examples/ex13c.out | 751 +++ Sun/examples/ex13c.sel | 42 + Sun/examples/ex14.log | 0 Sun/examples/ex14.out | 3000 ++++++++++++ Sun/examples/ex14.sel | 202 + Sun/examples/ex15.log | 0 Sun/examples/ex15.out | 2299 +++++++++ Sun/examples/ex15.sel | 78 + Sun/examples/ex16.log | 0 Sun/examples/ex16.out | 435 ++ Sun/examples/ex17.log | 0 Sun/examples/ex17.out | 349 ++ Sun/examples/ex18.log | 0 Sun/examples/ex18.out | 550 +++ Sun/examples/ex2.log | 0 Sun/examples/ex2.out | 4037 ++++++++++++++++ Sun/examples/ex2.sel | 53 + Sun/examples/ex3.log | 0 Sun/examples/ex3.out | 789 ++++ Sun/examples/ex4.log | 0 Sun/examples/ex4.out | 478 ++ Sun/examples/ex5.log | 0 Sun/examples/ex5.out | 942 ++++ Sun/examples/ex5.sel | 7 + Sun/examples/ex6.log | 0 Sun/examples/ex6.out | 3053 ++++++++++++ Sun/examples/ex6A-B.sel | 22 + Sun/examples/ex6C.sel | 9 + Sun/examples/ex7.log | 0 Sun/examples/ex7.out | 2819 +++++++++++ Sun/examples/ex7.sel | 27 + Sun/examples/ex8.log | 0 Sun/examples/ex8.out | 3612 ++++++++++++++ Sun/examples/ex8.sel | 27 + Sun/examples/ex9.log | 0 Sun/examples/ex9.out | 1284 +++++ Sun/examples/ex9.sel | 13 + SurfCharge.cxx | 493 ++ SurfCharge.h | 50 + SurfComp.cxx | 537 +++ SurfComp.h | 52 + Surface.cxx | 557 +++ Surface.h | 56 + Utils.cxx | 79 + Utils.h | 31 + advection.cpp | 103 + basic.cpp | 4400 +++++++++++++++++ basicsubs.cpp | 1774 +++++++ char_star.h | 11 + cl1.cpp | 753 +++ cl1mp.cpp | 974 ++++ classes/Conc.cxx | 188 + classes/Conc.h | 60 + classes/Isotope.cxx | 100 + classes/Isotope.h | 40 + classes/Makefile | 35 + classes/NumKeyword.cxx | 119 + classes/NumKeyword.h | 34 + classes/Parser.cxx | 836 ++++ classes/Parser.h | 196 + classes/Pe_Data.cxx | 45 + classes/Pe_Data.h | 27 + classes/Solution.cxx | 312 ++ classes/Solution.h | 72 + classes/TestCIsotope.cxx | 164 + classes/TestCIsotope.h | 39 + classes/TestCParser.cxx | 192 + classes/TestCParser.h | 48 + classes/TestCSolution.cxx | 124 + classes/TestCSolution.h | 24 + classes/main.cxx | 83 + classes/test.cxx | 23 + classes/utilities.cxx | 68 + classes/utilities.h | 28 + cpp.dsw | 29 + cvdense.cpp | 473 ++ cvdense.h | 224 + cvode.cpp | 3330 +++++++++++++ cvode.h | 882 ++++ dense.cpp | 114 + dense.h | 298 ++ distribution.checklist | 85 + distribution.mk | 368 ++ dw.cpp | 349 ++ ex1 | 77 + global.h | 1638 +++++++ input.cpp | 249 + input.h | 24 + integrate.cpp | 851 ++++ inverse.cpp | 3014 ++++++++++++ isotopes.cpp | 1540 ++++++ kinetics.cpp | 2288 +++++++++ kinetics.h | 21 + main.cpp | 140 + mainsubs.cpp | 2486 ++++++++++ model.cpp | 3102 ++++++++++++ nvector.cpp | 193 + nvector.h | 441 ++ nvector_serial.cpp | 869 ++++ nvector_serial.h | 325 ++ output.cpp | 182 + output.h | 57 + p2c.h | 543 +++ p2clib.cpp | 936 ++++ parse.cpp | 904 ++++ phast.xsd | 98 + phqalloc.cpp | 246 + phqalloc.h | 46 + phreeqc.dat | 1556 ++++++ phreeqc.rev | 4579 ++++++++++++++++++ phreeqc_files.cpp | 524 +++ phrqproto.h | 515 ++ phrqtype.h | 19 + pitzer.cpp | 1587 +++++++ pitzer.h | 50 + pitzer_structures.cpp | 195 + prep.cpp | 4055 ++++++++++++++++ print.cpp | 2259 +++++++++ read.cpp | 7904 +++++++++++++++++++++++++++++++ readtr.cpp | 1121 +++++ revisions | 1401 ++++++ smalldense.cpp | 243 + smalldense.h | 224 + spread.cpp | 1069 +++++ step.cpp | 1028 ++++ structures.cpp | 6059 ++++++++++++++++++++++++ sundialsmath.cpp | 76 + sundialsmath.h | 130 + sundialstypes.h | 144 + tally.cpp | 1006 ++++ test.xml | 70 + tidy.cpp | 3333 +++++++++++++ transport.cpp | 844 ++++ utilities.cpp | 1471 ++++++ 199 files changed, 131134 insertions(+) create mode 100644 Conc.cxx create mode 100644 Conc.h create mode 100644 ExchComp.cxx create mode 100644 ExchComp.h create mode 100644 Exchange.cxx create mode 100644 Exchange.h create mode 100644 GasPhase.cxx create mode 100644 GasPhase.h create mode 100644 ISolution.cxx create mode 100644 ISolution.h create mode 100644 Isotope.cxx create mode 100644 Isotope.h create mode 100644 KineticsComp.cxx create mode 100644 KineticsComp.h create mode 100644 KineticsCxx.cxx create mode 100644 KineticsCxx.h create mode 100644 Makefile create mode 100644 Mix.cxx create mode 100644 Mix.h create mode 100644 NameDouble.cxx create mode 100644 NameDouble.h create mode 100644 NumKeyword.cxx create mode 100644 NumKeyword.h create mode 100644 PPassemblage.cxx create mode 100644 PPassemblage.h create mode 100644 PPassemblageComp.cxx create mode 100644 PPassemblageComp.h create mode 100644 Parser.cxx create mode 100644 Parser.h create mode 100644 Pe_Data.cxx create mode 100644 Pe_Data.h create mode 100644 Reaction.cxx create mode 100644 Reaction.h create mode 100644 ReadClass.cpp create mode 100644 SAXPhreeqc.cpp create mode 100644 SAXPhreeqc.h create mode 100644 SSassemblage.cxx create mode 100644 SSassemblage.h create mode 100644 SSassemblageSS.cxx create mode 100644 SSassemblageSS.h create mode 100644 SaxPhreeqcHandlers.h create mode 100644 Solution.cxx create mode 100644 Solution.h create mode 100644 Sun/examples/ex1.log create mode 100644 Sun/examples/ex1.out create mode 100644 Sun/examples/ex10.log create mode 100644 Sun/examples/ex10.out create mode 100644 Sun/examples/ex10.sel create mode 100644 Sun/examples/ex11.log create mode 100644 Sun/examples/ex11.out create mode 100644 Sun/examples/ex11adv.sel create mode 100644 Sun/examples/ex11trn.sel create mode 100644 Sun/examples/ex12.log create mode 100644 Sun/examples/ex12.out create mode 100644 Sun/examples/ex12.sel create mode 100644 Sun/examples/ex12a.log create mode 100644 Sun/examples/ex12a.out create mode 100644 Sun/examples/ex12a.sel create mode 100644 Sun/examples/ex13a.log create mode 100644 Sun/examples/ex13a.out create mode 100644 Sun/examples/ex13a.sel create mode 100644 Sun/examples/ex13b.log create mode 100644 Sun/examples/ex13b.out create mode 100644 Sun/examples/ex13b.sel create mode 100644 Sun/examples/ex13c.log create mode 100644 Sun/examples/ex13c.out create mode 100644 Sun/examples/ex13c.sel create mode 100644 Sun/examples/ex14.log create mode 100644 Sun/examples/ex14.out create mode 100644 Sun/examples/ex14.sel create mode 100644 Sun/examples/ex15.log create mode 100644 Sun/examples/ex15.out create mode 100644 Sun/examples/ex15.sel create mode 100644 Sun/examples/ex16.log create mode 100644 Sun/examples/ex16.out create mode 100644 Sun/examples/ex17.log create mode 100644 Sun/examples/ex17.out create mode 100644 Sun/examples/ex18.log create mode 100644 Sun/examples/ex18.out create mode 100644 Sun/examples/ex2.log create mode 100644 Sun/examples/ex2.out create mode 100644 Sun/examples/ex2.sel create mode 100644 Sun/examples/ex3.log create mode 100644 Sun/examples/ex3.out create mode 100644 Sun/examples/ex4.log create mode 100644 Sun/examples/ex4.out create mode 100644 Sun/examples/ex5.log create mode 100644 Sun/examples/ex5.out create mode 100644 Sun/examples/ex5.sel create mode 100644 Sun/examples/ex6.log create mode 100644 Sun/examples/ex6.out create mode 100644 Sun/examples/ex6A-B.sel create mode 100644 Sun/examples/ex6C.sel create mode 100644 Sun/examples/ex7.log create mode 100644 Sun/examples/ex7.out create mode 100644 Sun/examples/ex7.sel create mode 100644 Sun/examples/ex8.log create mode 100644 Sun/examples/ex8.out create mode 100644 Sun/examples/ex8.sel create mode 100644 Sun/examples/ex9.log create mode 100644 Sun/examples/ex9.out create mode 100644 Sun/examples/ex9.sel create mode 100644 SurfCharge.cxx create mode 100644 SurfCharge.h create mode 100644 SurfComp.cxx create mode 100644 SurfComp.h create mode 100644 Surface.cxx create mode 100644 Surface.h create mode 100644 Utils.cxx create mode 100644 Utils.h create mode 100644 advection.cpp create mode 100644 basic.cpp create mode 100644 basicsubs.cpp create mode 100644 char_star.h create mode 100644 cl1.cpp create mode 100644 cl1mp.cpp create mode 100644 classes/Conc.cxx create mode 100644 classes/Conc.h create mode 100644 classes/Isotope.cxx create mode 100644 classes/Isotope.h create mode 100644 classes/Makefile create mode 100644 classes/NumKeyword.cxx create mode 100644 classes/NumKeyword.h create mode 100644 classes/Parser.cxx create mode 100644 classes/Parser.h create mode 100644 classes/Pe_Data.cxx create mode 100644 classes/Pe_Data.h create mode 100644 classes/Solution.cxx create mode 100644 classes/Solution.h create mode 100644 classes/TestCIsotope.cxx create mode 100644 classes/TestCIsotope.h create mode 100644 classes/TestCParser.cxx create mode 100644 classes/TestCParser.h create mode 100644 classes/TestCSolution.cxx create mode 100644 classes/TestCSolution.h create mode 100644 classes/main.cxx create mode 100644 classes/test.cxx create mode 100644 classes/utilities.cxx create mode 100644 classes/utilities.h create mode 100644 cpp.dsw create mode 100644 cvdense.cpp create mode 100644 cvdense.h create mode 100644 cvode.cpp create mode 100644 cvode.h create mode 100644 dense.cpp create mode 100644 dense.h create mode 100644 distribution.checklist create mode 100644 distribution.mk create mode 100644 dw.cpp create mode 100644 ex1 create mode 100644 global.h create mode 100644 input.cpp create mode 100644 input.h create mode 100644 integrate.cpp create mode 100644 inverse.cpp create mode 100644 isotopes.cpp create mode 100644 kinetics.cpp create mode 100644 kinetics.h create mode 100644 main.cpp create mode 100644 mainsubs.cpp create mode 100644 model.cpp create mode 100644 nvector.cpp create mode 100644 nvector.h create mode 100644 nvector_serial.cpp create mode 100644 nvector_serial.h create mode 100644 output.cpp create mode 100644 output.h create mode 100644 p2c.h create mode 100644 p2clib.cpp create mode 100644 parse.cpp create mode 100644 phast.xsd create mode 100644 phqalloc.cpp create mode 100644 phqalloc.h create mode 100644 phreeqc.dat create mode 100644 phreeqc.rev create mode 100644 phreeqc_files.cpp create mode 100644 phrqproto.h create mode 100644 phrqtype.h create mode 100644 pitzer.cpp create mode 100644 pitzer.h create mode 100644 pitzer_structures.cpp create mode 100644 prep.cpp create mode 100644 print.cpp create mode 100644 read.cpp create mode 100644 readtr.cpp create mode 100644 revisions create mode 100644 smalldense.cpp create mode 100644 smalldense.h create mode 100644 spread.cpp create mode 100644 step.cpp create mode 100644 structures.cpp create mode 100644 sundialsmath.cpp create mode 100644 sundialsmath.h create mode 100644 sundialstypes.h create mode 100644 tally.cpp create mode 100644 test.xml create mode 100644 tidy.cpp create mode 100644 transport.cpp create mode 100644 utilities.cpp diff --git a/Conc.cxx b/Conc.cxx new file mode 100644 index 00000000..c4e78dbf --- /dev/null +++ b/Conc.cxx @@ -0,0 +1,233 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Conc.h" +#include "ISolution.h" +#include "Utils.h" +#include +#define EXTERNAL extern +#include "global.h" +#include "phrqproto.h" +#include "phqalloc.h" + +cxxConc::cxxConc(void) +: description(NULL) +, moles(0.0) +, input_conc(0.0) +, units(NULL) +, equation_name(NULL) +, phase_si(0.0) +, n_pe(-1) +, as(NULL) +, gfw(0.0) + //, skip(0); + //, phase(NULL) +{ +} +cxxConc::cxxConc(struct conc *conc_ptr) +{ + description = conc_ptr->description; + moles = conc_ptr->moles; + input_conc = conc_ptr->input_conc; + units = conc_ptr->units; + equation_name = conc_ptr->equation_name; + phase_si = conc_ptr->phase_si; + n_pe = conc_ptr->n_pe; + as = conc_ptr->as; + gfw = conc_ptr->gfw; + //skip = conc_ptr->skip; + //phase = conc_ptr->phase; +} + +cxxConc::~cxxConc(void) +{ +} +/* +struct conc *cxxConc::concarray(std::map &totals) + // for Solutions, not ISolutions + // takes a map of (elt name, moles) + // returns list of conc structures +{ + struct conc *c; + c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); + if (c == NULL) malloc_error(); + int i = 0; + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + c[i].description = (char *)it->first; + c[i].moles = it->second; + c[i].input_conc = it->second; + c[i].units = NULL; + c[i].equation_name = NULL; + c[i].phase_si = 0.0; + c[i].n_pe = 0; + c[i].as = NULL; + c[i].gfw = 0.0; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return(c); +} +*/ +struct conc *cxxConc::cxxConc2conc(const std::set &totals) + // for ISolutions + // takes a std::vector cxxConc structures + // returns list of conc structures +{ + struct conc *c; + c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); + if (c == NULL) malloc_error(); + int i = 0; + for (std::set::const_iterator it = totals.begin(); it != totals.end(); ++it) { + c[i].description = it->description; + c[i].moles = it->moles; + c[i].input_conc = it->input_conc; + c[i].units = it->units; + c[i].equation_name = it->equation_name; + c[i].phase_si = it->phase_si; + c[i].n_pe = it->n_pe; + c[i].as = it->as; + c[i].gfw = it->gfw; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return(c); +} + +#ifdef SKIP +cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) +{ + // std::string& str = parser.line(); + std::string str = parser.line(); + + // defaults set in ctor + + // Remove space between "kg" and "solution" or "water" in units + Utilities::replace("Kg", "kg", str); + Utilities::replace("KG", "kg", str); + while (Utilities::replace("kg ", "kg", str)); + + std::istream::pos_type ptr = 0; + + // + // Read master species list for mass balance equation + // + std::string token; + std::string token1; + int count_redox_states = 0; + CParser::TOKEN_TYPE j; + while ( ((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER ) || + ( token[0] == '[' ) || + ( Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0 ) || + ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) ) + { + ++count_redox_states; + Utilities::replace("(+", "(", token); + if (count_redox_states > 1) token1 += " "; + token1 += token; + } + if (count_redox_states == 0) { + parser.incr_input_error(); + parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE); + return cxxConc::ERROR; + } + description = token1; + + // Determine if reading alkalinity, allow equivalents for units + Utilities::str_tolower(token1); + bool alk = false; + if (token1.find("alk") == 0) { + alk = true; + } + + // Read concentration + if (!(std::istringstream(token) >> this->input_conc)) { + std::ostringstream err; + err << "Concentration data error for " << token1 << " in solution input."; + parser.error_msg(err, CParser::OT_CONTINUE); + return cxxConc::ERROR; + } + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + + // Read optional data + token1 = token; + + // Check for units info + if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) { + if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) { + this->units = token1; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + } else { + return cxxConc::ERROR; + } + } + + // Check for "as" followed by formula to be used for gfw + token1 = token; + Utilities::str_tolower(token1); + if (token1.compare("as") == 0) + { + parser.copy_token(token, ptr); + this->as = token; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + } + // Check for "gfw" followed by gram formula weight + else if (token1.compare("gfw") == 0) + { + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { + parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); + return cxxConc::ERROR; + } else { + parser.get_iss() >> this->gfw; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + } + } + + // Check for redox couple for pe + if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { + this->n_pe = cxxPe_Data::store(solution.pe, token); + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + } else if (token.find("/") != std::string::npos) { + if (parser.parse_couple(token) == CParser::OK) { + this->n_pe = cxxPe_Data::store(solution.pe, token); + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + } else { + return cxxConc::ERROR; + } + } + + // Must have phase + this->equation_name = token; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + + // Check for saturation index + if (!(std::istringstream(token) >> this->phase_si)) + { + parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); + return cxxConc::ERROR; + } + return cxxConc::OK; +} +#endif + +#ifdef SKIP +void cxxConc::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + unsigned int i; + std::string indent0(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + + s_oss << indent0; + s_oss << "description << "\"" ; + + s_oss << " conc_moles=\"" << this->moles << "\"" ; + + s_oss << "\">" << std::endl; +} +#endif diff --git a/Conc.h b/Conc.h new file mode 100644 index 00000000..a792408c --- /dev/null +++ b/Conc.h @@ -0,0 +1,70 @@ +#if !defined(CONC_H_INCLUDED) +#define CONC_H_INCLUDED + +//#include "Parser.h" +#include "Utils.h" + +#include +#include // std::map +#include +#include +#include "char_star.h" + +// forward declarations +class cxxISolution; // reqd for read and dump_xml + +class cxxConc +{ +public: + cxxConc(void); + cxxConc(struct conc *conc_ptr); + ~cxxConc(void); + + enum STATUS_TYPE { + ERROR = 0, + OK = 1 + }; + +public: + + //STATUS_TYPE read(CParser& parser, CSolution& sol); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + double get_input_conc()const {return this->input_conc;} + void set_input_conc(double input_conc) {this->input_conc = input_conc;} + + std::string get_equation_name()const {return this->equation_name;} + void set_equation_name(char * equation_name) {this->equation_name = equation_name;} + + std::string get_description()const {return this->description;} + void set_description(char * description) {this->description = description;} + + std::string get_units()const {return this->units;} + void set_units(char * units) {this->units = units;} + + int get_n_pe()const {return this->n_pe;} + void set_n_pe(int n_pe) {this->n_pe = n_pe;} + + //bool operator<(const cxxConc& conc)const { return (this->description < conc.description); } + bool operator<(const cxxConc& conc)const { return ::strcmp(this->description, conc.description) < 0; } + + //static struct conc * concarray(std::map &t ); + + static struct conc * cxxConc2conc(const std::set &t ); + +private: + char * description; + double moles; + double input_conc; + char * units; + char * equation_name; + //struct phase *phase; + double phase_si; + int n_pe; + char * as; + double gfw; + //int skip; +}; + +#endif // CONC_H_INCLUDED diff --git a/ExchComp.cxx b/ExchComp.cxx new file mode 100644 index 00000000..e0832c5d --- /dev/null +++ b/ExchComp.cxx @@ -0,0 +1,554 @@ +// ExchComp.cxx: implementation of the cxxExchComp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "ExchComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include "output.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxExchComp::cxxExchComp() + // + // default constructor for cxxExchComp + // +{ + moles = 0.0; + la = 0.0; + charge_balance = 0.0; + phase_name = NULL; + phase_proportion = 0.0; + rate_name = NULL; + totals.type = cxxNameDouble::ND_ELT_MOLES; + formula_totals.type = cxxNameDouble::ND_ELT_MOLES; +} + +cxxExchComp::cxxExchComp(struct exch_comp *exch_comp_ptr) + // + // constructor for cxxExchComp from struct exch_comp + // +: +formula_totals(exch_comp_ptr->formula_totals), +totals(exch_comp_ptr->totals) +{ + formula = exch_comp_ptr->formula; + moles = exch_comp_ptr->moles; + // totals in constructor + //formula_totals in constructor + la = exch_comp_ptr->la; + charge_balance = exch_comp_ptr->charge_balance; + phase_name = exch_comp_ptr->phase_name; + phase_proportion = exch_comp_ptr->phase_proportion; + rate_name = exch_comp_ptr->rate_name; + formula_z = exch_comp_ptr->formula_z; +} + +cxxExchComp::~cxxExchComp() +{ +} + +struct master *cxxExchComp::get_master() +{ + struct master *master_ptr = NULL; + for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { + + /* Find master species */ + char *eltName = it->first; + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; + //Utilities::error_msg(error_oss.str(), STOP); + error_msg(error_oss.str().c_str(), CONTINUE); + return(NULL); + } + if (elt_ptr->master->type != EX) continue; + master_ptr = elt_ptr->master; + break; + } + if (master_ptr == NULL) { + std::ostringstream error_oss; + error_oss << "Exchange formula does not contain an exchange master species, " << this->formula << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); + } + return(master_ptr); +} + +struct exch_comp *cxxExchComp::cxxExchComp2exch_comp(std::list& el) + // + // Builds exch_comp structure from of cxxExchComp + // +{ + struct exch_comp *exch_comp_ptr = (struct exch_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); + if (exch_comp_ptr == NULL) malloc_error(); + + int i = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + exch_comp_ptr[i].formula = it->formula; + exch_comp_ptr[i].formula_z = it->formula_z; + exch_comp_ptr[i].totals = it->totals.elt_list(); + exch_comp_ptr[i].moles = it->moles; + exch_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); + exch_comp_ptr[i].la = it->la; + exch_comp_ptr[i].charge_balance = it->charge_balance; + exch_comp_ptr[i].phase_name = it->phase_name; + exch_comp_ptr[i].phase_proportion = it->phase_proportion; + exch_comp_ptr[i].rate_name = it->rate_name; + exch_comp_ptr[i].master = it->get_master(); + i++; + } + return(exch_comp_ptr); +} + +void cxxExchComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Exch_Comp element and attributes + + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) { + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) { + s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); + + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); +} + +void cxxExchComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Exch_Comp element and attributes + + s_oss << indent0 << "-formula " << this->formula << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-la " << this->la << std::endl; + s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; + if (this->phase_name != NULL) { + s_oss << indent0 << "-phase_name " << this->phase_name << std::endl; + } + if (this->rate_name != NULL) { + s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; + } + s_oss << indent0 << "-phase_proportion " << this->phase_proportion << 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 + s_oss << indent0; + s_oss << "-formula_totals" << std::endl; + this->formula_totals.dump_raw(s_oss, indent + 1); +} + +void cxxExchComp::read_raw(CParser& parser) +{ + std::string str; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("formula"); // 0 + vopts.push_back("moles"); // 1 + vopts.push_back("la"); // 2 + vopts.push_back("charge_balance"); // 3 + vopts.push_back("phase_name"); // 4 + vopts.push_back("rate_name"); // 5 + vopts.push_back("formula_z"); // 6 + vopts.push_back("phase_proportion"); // 7 + vopts.push_back("totals"); // 8 + vopts.push_back("formula_totals"); // 9 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool formula_defined(false); + bool moles_defined(false); + bool la_defined(false); + bool charge_balance_defined(false); + bool formula_z_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in EXCH_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // formula + if (!(parser.get_iss() >> str)) + { + this->formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); + } else { + this->formula = string_hsave(str.c_str()); + } + formula_defined = true; + break; + + case 1: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); + } + moles_defined = true; + break; + + case 2: // la + if (!(parser.get_iss() >> this->la)) + { + this->la = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la.", CParser::OT_CONTINUE); + } + la_defined = true; + break; + + case 3: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; + + case 4: // phase_name + if (!(parser.get_iss() >> str)) + { + this->phase_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); + } else { + this->phase_name = string_hsave(str.c_str()); + } + break; + + case 5: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); + } else { + this->rate_name = string_hsave(str.c_str()); + } + break; + + case 6: // formula_z + if (!(parser.get_iss() >> this->formula_z)) + { + this->formula_z = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for formula_z.", CParser::OT_CONTINUE); + } + formula_z_defined = true; + break; + + case 7: // phase_proportion + if (!(parser.get_iss() >> this->phase_proportion)) + { + this->phase_proportion = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for phase_proportion.", CParser::OT_CONTINUE); + } + break; + + case 8: // totals + if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for ExchComp totals.", CParser::OT_CONTINUE); + } + opt_save = 8; + break; + + case 9: // formula_totals + if ( this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for ExchComp formula totals.", CParser::OT_CONTINUE); + } + opt_save = 9; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (formula_defined == false) { + parser.incr_input_error(); + parser.error_msg("Formula not defined for ExchComp input.", CParser::OT_CONTINUE); + } + if (moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Moles not defined for ExchComp input.", CParser::OT_CONTINUE); + } + if (la_defined == false) { + parser.incr_input_error(); + parser.error_msg("La not defined for ExchComp input.", CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for ExchComp input.", CParser::OT_CONTINUE); + } + if (formula_z_defined == false) { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); + } +} + +#ifdef SKIP +cxxExchComp& cxxExchComp::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxExchComp numkey; + + // Read exch_comp number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxExchComp& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in EXCH_COMP keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.exch_comp_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in exch_comp.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif + diff --git a/ExchComp.h b/ExchComp.h new file mode 100644 index 00000000..1684c9ab --- /dev/null +++ b/ExchComp.h @@ -0,0 +1,52 @@ +#if !defined(EXCHCOMP_H_INCLUDED) +#define EXCHCOMP_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxExchComp +{ + +public: + cxxExchComp(); + cxxExchComp(struct exch_comp *); + ~cxxExchComp(); + + + struct master *get_master(); + char *get_phase_name()const {return this->phase_name;} + char *get_rate_name()const {return this->rate_name;} + + static struct exch_comp *cxxExchComp2exch_comp(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + char * formula; + double moles; + cxxNameDouble formula_totals; + cxxNameDouble totals; + double la; + double charge_balance; + char *phase_name; + double phase_proportion; + char *rate_name; + double formula_z; // charge on formula + +public: + +}; + +#endif // !defined(EXCHCOMP_H_INCLUDED) diff --git a/Exchange.cxx b/Exchange.cxx new file mode 100644 index 00000000..146c2c38 --- /dev/null +++ b/Exchange.cxx @@ -0,0 +1,413 @@ +// Exchange.cxx: implementation of the cxxExchange class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Exchange.h" +#include "ExchComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxExchange::cxxExchange() + // + // default constructor for cxxExchange + // +: cxxNumKeyword() +{ + pitzer_exchange_gammas = false; +} + +cxxExchange::cxxExchange(struct exchange *exchange_ptr) + // + // constructor for cxxExchange from struct exchange + // +: +cxxNumKeyword() + +{ + int i; + + this->set_description(exchange_ptr->description); + n_user = exchange_ptr->n_user; + n_user_end = exchange_ptr->n_user_end; + pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); + for (i = 0; i < exchange_ptr->count_comps; i++) { + cxxExchComp ec(&(exchange_ptr->comps[i])); + exchComps.push_back(ec); + } + + + + +} + +cxxExchange::~cxxExchange() +{ +} + +bool cxxExchange::get_related_phases() +{ + for (std::list::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { + if (it->get_phase_name() == NULL) continue; + return(true); + } + return(false); +} + +bool cxxExchange::get_related_rate() +{ + for (std::list::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { + if (it->get_rate_name() == NULL) continue; + return(true); + } + return(false); +} + +struct exchange *cxxExchange::cxxExchange2exchange() + // + // Builds a exchange structure from instance of cxxExchange + // +{ + struct exchange *exchange_ptr = exchange_alloc(); + + exchange_ptr->description = this->get_description(); + exchange_ptr->n_user = this->n_user; + exchange_ptr->n_user_end = this->n_user_end; + exchange_ptr->new_def = FALSE; + exchange_ptr->solution_equilibria = FALSE; + exchange_ptr->n_solution = -2; + exchange_ptr->related_phases = (int) this->get_related_phases(); + exchange_ptr->related_rate = (int) this->get_related_rate(); + exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; + exchange_ptr->count_comps = this->exchComps.size(); + exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps); + exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); + return(exchange_ptr); +} + +void cxxExchange::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Exchange element and attributes + s_oss << indent0; + s_oss << "pitzer_exchange_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} + +void cxxExchange::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Exchange element and attributes + s_oss << indent0; + s_oss << "EXCHANGE_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-pitzer_exchange_gammas " << this->pitzer_exchange_gammas << std::endl; + + // exchComps structures + for (std::list::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } + + return; +} + +void cxxExchange::read_raw(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("pitzer_exchange_gammas"); // 0 + vopts.push_back("component"); // 1 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read exchange number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool pitzer_exchange_gammas_defined(false); + + for (;;) + { + int opt; + if (useLastLine == false) { + opt = parser.get_option(vopts, next_char); + } else { + opt = parser.getOptionFromLastLine(vopts, next_char); + } + 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 EXCH_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // pitzer_exchange_gammas + if (!(parser.get_iss() >> this->pitzer_exchange_gammas)) + { + this->pitzer_exchange_gammas = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for pitzer_exchange_gammas.", CParser::OT_CONTINUE); + } + pitzer_exchange_gammas_defined = true; + useLastLine = false; + break; + case 1: // component + { + cxxExchComp ec; + ec.read_raw(parser); + this->exchComps.push_back(ec); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (pitzer_exchange_gammas_defined == false) { + parser.incr_input_error(); + parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE); + } +} +#ifdef SKIP +cxxExchange& cxxExchange::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxExchange numkey; + + // Read exchange number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxExchange& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in EXCHANGE keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.exchange_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in exchange.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif diff --git a/Exchange.h b/Exchange.h new file mode 100644 index 00000000..08c06fee --- /dev/null +++ b/Exchange.h @@ -0,0 +1,47 @@ +#if !defined(EXCHANGE_H_INCLUDED) +#define EXCHANGE_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "ExchComp.h" + +class cxxExchange : public cxxNumKeyword +{ + +public: + cxxExchange(); + cxxExchange(struct exchange *); + ~cxxExchange(); + + struct exchange *cxxExchange2exchange(); + + struct exch_comp *cxxExchComp2exch_comp(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + + bool get_related_phases(void); + + bool get_related_rate(void); + +protected: + std::list exchComps; + bool pitzer_exchange_gammas; + +public: + //static std::map& map; + +}; + +#endif // !defined(EXCHANGE_H_INCLUDED) diff --git a/GasPhase.cxx b/GasPhase.cxx new file mode 100644 index 00000000..aef606b3 --- /dev/null +++ b/GasPhase.cxx @@ -0,0 +1,474 @@ +// GasPhase.cxx: implementation of the cxxGasPhase class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "GasPhase.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxGasPhase::cxxGasPhase() + // + // default constructor for cxxGasPhase + // +: cxxNumKeyword() +{ + total_p = 0; + volume = 0; + gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; +} + +cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr) + // + // constructor for cxxGasPhase from struct gas_phase + // +: +cxxNumKeyword() +{ + int i; + + this->set_description(gas_phase_ptr->description); + n_user = gas_phase_ptr->n_user; + n_user_end = gas_phase_ptr->n_user_end; + if (gas_phase_ptr->type == PRESSURE) { + type = cxxGasPhase::GP_PRESSURE; + } else { + type = cxxGasPhase::GP_VOLUME; + } + total_p = gas_phase_ptr->total_p; + volume = gas_phase_ptr->volume; + + // gas_phase components + for (i = 0; i < gas_phase_ptr->count_comps; i++) { + gasPhaseComps[gas_phase_ptr->comps[i].name] = gas_phase_ptr->comps[i].moles; + } +} + +cxxGasPhase::~cxxGasPhase() +{ +} + +struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp() +{ + struct gas_comp *gas_comp_ptr(NULL); + if (this->gasPhaseComps.size() > 0) { + int i = 0; + int n; + gas_comp_ptr = (struct gas_comp *) PHRQ_malloc((size_t) (this->gasPhaseComps.size() * sizeof(struct gas_comp))); + if (gas_comp_ptr == NULL) malloc_error(); + for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { + gas_comp_ptr[i].name = it->first; + gas_comp_ptr[i].phase = phase_bsearch(it->first, &n, TRUE); + gas_comp_ptr[i].p_read = 0; + gas_comp_ptr[i].moles = it->second; + gas_comp_ptr[i].initial_moles = 0; + i++; + } + } + return(gas_comp_ptr); +} + +struct gas_phase *cxxGasPhase::cxxGasPhase2gas_phase() + // + // Builds a gas_phase structure from instance of cxxGasPhase + // +{ + struct gas_phase *gas_phase_ptr = gas_phase_alloc(); + + gas_phase_ptr->description = this->get_description(); + gas_phase_ptr->n_user = this->n_user; + gas_phase_ptr->n_user_end = this->n_user_end; + gas_phase_ptr->new_def = FALSE; + gas_phase_ptr->solution_equilibria = FALSE; + gas_phase_ptr->n_solution = -2; + if (this->type == cxxGasPhase::GP_PRESSURE) { + gas_phase_ptr->type = PRESSURE; + } else { + gas_phase_ptr->type = VOLUME; + } + gas_phase_ptr->total_p = this->total_p; + gas_phase_ptr->volume = this->volume; + gas_phase_ptr->temperature = 273.15; + + // comps + gas_phase_ptr->count_comps = this->gasPhaseComps.size(); + gas_phase_ptr->comps = (struct gas_comp *) free_check_null(gas_phase_ptr->comps); + gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(); + + return(gas_phase_ptr); +} + +#ifdef SKIP +void cxxGasPhase::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // GasPhase element and attributes + s_oss << indent0; + s_oss << "pitzer_gas_phase_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxGasPhase::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // GasPhase element and attributes + s_oss << indent0; + s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-type " << this->type << std::endl; + + s_oss << indent1; + s_oss << "-total_p " << this->total_p << std::endl; + + s_oss << indent1; + s_oss << "-volume " << this->volume << std::endl; + + // gasPhaseComps + s_oss << indent1; + s_oss << "-component" << std::endl; + this->gasPhaseComps.dump_raw(s_oss, indent + 2); +} + +void cxxGasPhase::read_raw(CParser& parser) +{ + + int i; + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("type"); //0 + vopts.push_back("total_p"); //1 + vopts.push_back("volume"); //2 + vopts.push_back("component"); //3 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read gas_phase number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool type_defined(false); + bool total_p_defined(false); + bool volume_defined(false); + + 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 GAS_PHASE_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // type + if (!(parser.get_iss() >> i)) + //if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type)) + { + this->type = cxxGasPhase::GP_PRESSURE; + parser.incr_input_error(); + parser.error_msg("Expected enum for type.", CParser::OT_CONTINUE); + } else { + this->type = (cxxGasPhase::GP_TYPE) i; + } + type_defined = true; + useLastLine = false; + break; + + case 1: // total_p + if (!(parser.get_iss() >> this->total_p)) + { + this->total_p = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total_p.", CParser::OT_CONTINUE); + } + total_p_defined = true; + useLastLine = false; + break; + + case 2: // volume + if (!(parser.get_iss() >> this->volume)) + { + this->volume = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for volume.", CParser::OT_CONTINUE); + } + volume_defined = true; + useLastLine = false; + break; + + case 3: // component + if ( this->gasPhaseComps.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected gas component name and moles for gasPhaseComps.", CParser::OT_CONTINUE); + } + opt_save = 3; + useLastLine = false; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (type_defined == false) { + parser.incr_input_error(); + parser.error_msg("Type not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); + } + if (total_p_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); + } + if (volume_defined == false) { + parser.incr_input_error(); + parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); + } +} +#ifdef SKIP +cxxGasPhase& cxxGasPhase::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxGasPhase numkey; + + // Read gas_phase number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxGasPhase& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in GAS_PHASE keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.gas_phase_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in gas_phase.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif diff --git a/GasPhase.h b/GasPhase.h new file mode 100644 index 00000000..b0bb7c63 --- /dev/null +++ b/GasPhase.h @@ -0,0 +1,50 @@ +#if !defined(GASPHASE_H_INCLUDED) +#define GASPHASE_H_INCLUDED + +#include "NumKeyword.h" +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxGasPhase : public cxxNumKeyword +{ + +public: + cxxGasPhase(); + cxxGasPhase(struct gas_phase *); + ~cxxGasPhase(); + + enum GP_TYPE { + GP_PRESSURE = 0, + GP_VOLUME = 1 + }; + + struct gas_phase *cxxGasPhase2gas_phase(); + + struct gas_comp *cxxGasPhaseComp2gas_comp(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + + +protected: + cxxNameDouble gasPhaseComps; + GP_TYPE type; + double total_p; + double volume; +public: + //static std::map& map; + +}; + +#endif // !defined(GASPHASE_H_INCLUDED) diff --git a/ISolution.cxx b/ISolution.cxx new file mode 100644 index 00000000..a8ea03bb --- /dev/null +++ b/ISolution.cxx @@ -0,0 +1,334 @@ +// ISolution.cxx: implementation of the cxxSolutionxx class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "ISolution.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" + +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +//static std::map ss_map; +//std::map& cxxISolution::s_map = ss_map; + +cxxISolution::cxxISolution() +: +units("mMol/kgw") +{ + density = 1.0; + default_pe = -1; +} + +cxxISolution::cxxISolution(struct solution *solution_ptr) +: cxxSolution(solution_ptr) + //, pe(cxxPe_Data::alloc()) +{ + density = solution_ptr->density; + units = solution_ptr->units; + // totals + for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { + cxxConc c(&(solution_ptr->totals[i])); + concs.insert(c); + } + default_pe = solution_ptr->default_pe; + // pe_data + pes = pe_data_dup(solution_ptr->pe); +} + +cxxISolution::~cxxISolution() +{ + pe_data_free(this->pes); +} + +struct solution *cxxISolution::cxxISolution2solution() + // + // Builds a solution structure from instance of cxxISolution + // +{ + struct solution *soln_ptr = this->cxxSolution2solution(); + soln_ptr->new_def = TRUE; + soln_ptr->density = this->density; + soln_ptr->units = string_hsave(this->units.c_str()); + soln_ptr->default_pe = this->default_pe; + // pe + soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe); + soln_ptr->pe = pe_data_dup(this->pes); + // totals + soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); + soln_ptr->totals = cxxConc::cxxConc2conc(this->concs); + return(soln_ptr); +} +#ifdef SKIP +cxxISolution& cxxISolution::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxISolution numkey; + + // Read solution number and description + numkey.read_number_description(parser); + + // Malloc space for solution data + //// g_solution_map[numkey.n_user()] = numkey; + s_map[numkey.n_user()] = numkey; + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + cxxISolution& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.solution_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif +#ifdef SKIP +void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "\n"; + + cxxNumKeyword::dump_xml(os, indent); + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_tc() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_ph() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_solution_pe() << "" << "\n"; + + assert(this->pe.size() > 0); + assert(this->default_pe >= 0); + assert(this->pe.size() > (unsigned int) this->default_pe); + //this->pe[this->default_pe].dump_xml(os, indent + 1); + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_units() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_density() << "" << "\n"; + + // foreach conc + if (!this->totals.empty()) + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + + std::vector::const_iterator iter = this->totals.begin(); + for(; iter != this->totals.end(); ++iter) + { + (*iter).dump_xml(*this, os, indent + 2); + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + } + + // foreach isotope + if (!this->isotopes.empty()) + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + + std::list::const_iterator iter = this->isotopes.begin(); + for(; iter != this->isotopes.end(); ++iter) + { + (*iter).dump_xml(os, indent + 2); + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_mass_water() << "" << "\n"; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "" << "\n"; +} +#endif diff --git a/ISolution.h b/ISolution.h new file mode 100644 index 00000000..c80d7925 --- /dev/null +++ b/ISolution.h @@ -0,0 +1,56 @@ +#if !defined(ISOLUTION_H_INCLUDED) +#define ISOLUTION_H_INCLUDED + +//#include "Parser.h" +#include "NumKeyword.h" +#include "Solution.h" +#include "Conc.h" +//#include "Isotope.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector +#include // std::set + + +class cxxISolution : public cxxSolution +{ + +public: + cxxISolution(); + cxxISolution(struct solution *); + //cxxISolution(const cxxISolution&); + ~cxxISolution(); + + //static cxxISolution& read(CParser& parser); + + //void add(cxxConc conc) { this->concs.push_back(conc); } + + struct solution *cxxISolution2solution(); + + double get_density()const {return this->density;} + void set_density(double density) {this->density = density;} + + std::string get_units()const {return units;} + void set_units(std::string units) {units = units;} + + //char * get_redox()const {return this->pe[this->default_pe].get_name();} + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + +protected: + friend class cxxConc; // for this->pe access + double density; + std::string units; + std::set concs; + //std::map pe; + struct pe_data *pes; + int default_pe; + +public: + //static std::map& map; + +}; + +#endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/Isotope.cxx b/Isotope.cxx new file mode 100644 index 00000000..244d71fe --- /dev/null +++ b/Isotope.cxx @@ -0,0 +1,241 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "Isotope.h" +#include "Utils.h" +#include "Parser.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include +#include // std::ostrstream + +cxxIsotope::cxxIsotope(void) +: isotope_number(0.0) +{ +} + +cxxIsotope::cxxIsotope(struct isotope *isotope_ptr) +{ + isotope_number = isotope_ptr->isotope_number; + elt_name = isotope_ptr->elt_name; + isotope_name = isotope_ptr->isotope_name; + total = isotope_ptr->total; + ratio = isotope_ptr->ratio; + ratio_uncertainty = isotope_ptr->ratio_uncertainty; +} + +cxxIsotope::~cxxIsotope(void) +{ +} + +struct isotope *cxxIsotope::list2isotope(std::list &isolist) + // takes a std::list of cxxIsotope structures + // returns array of isotope structures +{ + struct isotope *iso; + if (isolist.size() <= 0) { + return NULL; + } else { + iso = (struct isotope *) PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); + if (iso == NULL) malloc_error(); + int i = 0; + for (std::list ::iterator it = isolist.begin(); it != isolist.end(); ++it) { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return(iso); +} + +#ifdef SKIP +std::string cxxIsotope::get_name()const +{ + std::ostringstream oss; + //std::ostrstream oss; + oss << this->isotope_number << this->elt_name; + return oss.str(); +} +#endif + +void cxxIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + unsigned int i; + + std::string indent0(""), indent1(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + + s_oss << indent0; + s_oss << "isotope_number << "\"" << std::endl; + + s_oss << indent1; + s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl; + + s_oss << indent1; + s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl; + + s_oss << indent1; + s_oss << "iso_total=\"" << this->total << "\"" << std::endl; + + s_oss << indent1; + s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl; + + if (this->ratio_uncertainty != NAN) { + s_oss << indent1; + s_oss << "iso_ratio_uncertainty=\"" << this->ratio_uncertainty << "\"" << std::endl; + } + s_oss << indent0; + s_oss << "\">" << std::endl; +} + +void cxxIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + unsigned int i; + + std::string indent0(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + + s_oss << indent0; + s_oss << this->isotope_name << " "; + s_oss << this->isotope_number << " "; + s_oss << this->elt_name << " "; + s_oss << this->total << " "; + s_oss << this->ratio << " "; + if (this->ratio_uncertainty != NAN) { + s_oss << this->ratio_uncertainty << " "; + } + s_oss << std::endl; +} + +CParser::STATUS_TYPE cxxIsotope::read_raw(CParser& parser) +{ + std::string token; + std::istream::pos_type next_char; + CParser::TOKEN_TYPE j; + + // isotope_name + j = parser.copy_token(token, next_char); + + if (j == CParser::TT_EMPTY) { + this->isotope_name = NULL; + return(CParser::PARSER_OK); + } + this->isotope_name = string_hsave(token.c_str()); + + // isotope_number + if( !(parser.get_iss() >> isotope_number)) { + return CParser::PARSER_ERROR; + } + + // elt_name + if( !(parser.get_iss() >> token)) { + return CParser::PARSER_ERROR; + } + this->elt_name = string_hsave(token.c_str()); + + // total + if( !(parser.get_iss() >> this->total)) { + return CParser::PARSER_ERROR; + } + + // ratio + if( !(parser.get_iss() >> this->ratio)) { + return CParser::PARSER_ERROR; + } + + // ratio_uncertainty + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + this->ratio_uncertainty = NAN; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> this->ratio_uncertainty; + } + + return CParser::PARSER_OK; +} + +bool cxxIsotope::operator<(const cxxIsotope& isotope)const +{ + int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); + if (i != 0) return (i < 0); + return ( this->isotope_number < isotope.isotope_number ); +} + +struct master *cxxIsotope::master(void) +{ + return (master_bsearch(this->elt_name)); +} + +struct master *cxxIsotope::primary(void) +{ + return (master_bsearch_primary(this->elt_name)); +} + +#ifdef SKIP +cxxIsotope::STATUS cxxIsotope::read(CParser& parser) +{ + if ( !(parser.get_iss() >> this->isotope_number) ) { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected isotope name to" + " begin with an isotopic number.", CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + + // read and save element name + std::istringstream::int_type c = parser.get_iss().peek(); + if ( c == std::char_traits::eof() || !(::isupper(c)) ) { + parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + parser.incr_input_error(); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + if ( !(parser.get_iss() >> this->elt_name) ) { + // should never get here + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + assert(!this->elt_name.empty() && ::isupper(this->elt_name[0])); + + // read and store isotope ratio + if ( !(parser.get_iss() >> this->ratio) ) { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected numeric value for isotope ratio.", CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + + // read and store isotope ratio + this->ratio_uncertainty_defined = false; + if ( !(parser.get_iss() >> this->ratio_uncertainty)) { + if ( !parser.get_iss().eof() ) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for uncertainty in isotope ratio.", CParser::OT_CONTINUE); + return ERROR; + } + } else { + this->ratio_uncertainty_defined = true; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + return OK; +} + + +#endif diff --git a/Isotope.h b/Isotope.h new file mode 100644 index 00000000..0da740a8 --- /dev/null +++ b/Isotope.h @@ -0,0 +1,56 @@ +#if !defined(ISOTOPE_H_INCLUDED) +#define ISOTOPE_H_INCLUDED + +#include "Parser.h" +#include // std::ostream +#include // std::string +#include // std::list + +class cxxIsotope +{ +public: + cxxIsotope(void); + cxxIsotope(struct isotope *isotope_ptr); + ~cxxIsotope(void); + + enum STATUS { + ERROR = 0, + OK = 1 + }; + + //cxxIsotope::STATUS read(CParser& parser); + static struct isotope * list2isotope(std::list &t); + + void dump_xml(std::ostream& os, unsigned int indent)const; + void dump_raw(std::ostream& os, unsigned int indent)const; + + CParser::STATUS_TYPE cxxIsotope::read_raw(CParser& parser); + + char * get_isotope_name()const { return this->isotope_name;} + void set_isotope_name(char * cstring) { this->isotope_name = cstring;} + char * get_elt_name()const { return this->elt_name;} + void set_elt_name(char * cstring) { this->elt_name = cstring;} + + double get_ratio()const { return this->ratio; } + + double get_ratio_uncertainty()const { return this->ratio_uncertainty; } + + bool get_ratio_uncertainty_defined()const { return this->ratio_uncertainty_defined; } + + bool operator<(const cxxIsotope& conc)const; + + struct master *master(void); + struct master *primary(void); + +private: + double isotope_number; + char * elt_name; + char * isotope_name; + double total; + double ratio; + double ratio_uncertainty; + //struct master *master; + //struct master *primary; + bool ratio_uncertainty_defined; +}; +#endif // ISOTOPE_H_INCLUDED diff --git a/KineticsComp.cxx b/KineticsComp.cxx new file mode 100644 index 00000000..ab9b374e --- /dev/null +++ b/KineticsComp.cxx @@ -0,0 +1,504 @@ +// KineticsComp.cxx: implementation of the cxxKineticsComp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "KineticsComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxKineticsComp::cxxKineticsComp() + // + // default constructor for cxxKineticsComp + // +{ + rate_name = NULL; + tol = 1e-8; + m = 0.0; + m0 = 0.0; + moles = 0.0; + namecoef.type = cxxNameDouble::ND_NAME_COEF; +} + +cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr) + // + // constructor for cxxKineticsComp from struct kinetics_comp + // +: +namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list, cxxNameDouble::ND_NAME_COEF) +{ + rate_name = kinetics_comp_ptr->rate_name; + tol = kinetics_comp_ptr->tol; + m = kinetics_comp_ptr->m; + m0 = kinetics_comp_ptr->m0; + moles = kinetics_comp_ptr->moles; + for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++) { + this->d_params.push_back(kinetics_comp_ptr->d_params[i]); + } +} + +cxxKineticsComp::~cxxKineticsComp() +{ +} + +struct kinetics_comp *cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list& el) + // + // Builds kinetics_comp structure from of cxxKineticsComp + // +{ + struct kinetics_comp *kinetics_comp_ptr = (struct kinetics_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); + if (kinetics_comp_ptr == NULL) malloc_error(); + + int i = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + kinetics_comp_ptr[i].rate_name = it->rate_name; + kinetics_comp_ptr[i].list = it->namecoef.name_coef(); + kinetics_comp_ptr[i].count_list = it->namecoef.size(); + kinetics_comp_ptr[i].tol = it->tol; + kinetics_comp_ptr[i].m = it->m; + kinetics_comp_ptr[i].initial_moles = 0.; + kinetics_comp_ptr[i].m0 = it->m0; + kinetics_comp_ptr[i].moles = it->moles; + kinetics_comp_ptr[i].count_c_params = 0; + kinetics_comp_ptr[i].c_params = NULL; +/* + kinetics_comp_ptr[i].count_d_params = 0; + kinetics_comp_ptr[i].d_params = NULL; +*/ + + kinetics_comp_ptr[i].count_d_params = it->d_params.size(); + kinetics_comp_ptr[i].d_params = NULL; + if (it->d_params.size() > 0) { + kinetics_comp_ptr[i].d_params = (double *) PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double))); + if (kinetics_comp_ptr[i].d_params == NULL) malloc_error(); + std::copy(it->d_params.begin(), it->d_params.end(), kinetics_comp_ptr[i].d_params); + } + i++; + } + return(kinetics_comp_ptr); +} +#ifdef SKIP +void cxxKineticsComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Kinetics_Comp element and attributes + + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) { + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) { + s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); + + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); +} +#endif +void cxxKineticsComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Kinetics_Comp element and attributes + + s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; + s_oss << indent0 << "-tol " << this->tol << std::endl; + s_oss << indent0 << "-m " << this->m << std::endl; + s_oss << indent0 << "-m0 " << this->m0 << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + + // namecoef + s_oss << indent0; + s_oss << "-namecoef" << std::endl; + this->namecoef.dump_raw(s_oss, indent + 1); + + // d_params + s_oss << indent0; + s_oss << "-d_params" << std::endl; + { + int i = 0; + s_oss << indent1; + for (std::vector::const_iterator it = d_params.begin(); it != d_params.end(); it++) { + if (i++ == 5) { + s_oss << std::endl; + s_oss << indent1; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } +} + +void cxxKineticsComp::read_raw(CParser& parser) +{ + std::string str; + double d; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("rate_name"); // 0 + vopts.push_back("tol"); // 1 + vopts.push_back("m"); // 2 + vopts.push_back("m0"); // 3 + vopts.push_back("moles"); // 4 + vopts.push_back("namecoef"); // 5 + vopts.push_back("d_params"); // 6 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool rate_name_defined(false); + bool tol_defined(false); + bool m_defined(false); + bool m0_defined(false); + bool moles_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Kinetics for more processing + //parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); + } else { + this->rate_name = string_hsave(str.c_str()); + } + rate_name_defined = true; + break; + + case 1: // tol + if (!(parser.get_iss() >> this->tol)) + { + this->tol = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for tol.", CParser::OT_CONTINUE); + } + tol_defined = true; + break; + + case 2: // m + if (!(parser.get_iss() >> this->m)) + { + this->m = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for m.", CParser::OT_CONTINUE); + } + m_defined = true; + break; + + case 3: // m0 + if (!(parser.get_iss() >> this->m0)) + { + this->m0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for m0.", CParser::OT_CONTINUE); + } + m0_defined = true; + break; + + + case 4: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); + } + moles_defined = true; + break; + + + case 5: // namecoef + if ( this->namecoef.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for namecoef.", CParser::OT_CONTINUE); + } + opt_save = 5; + break; + + case 6: // d_params + while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { + sscanf(token.c_str(), "%lf", &d); + this->d_params.push_back(d); + } + opt_save = 6; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (rate_name_defined == false) { + parser.incr_input_error(); + parser.error_msg("Rate_name not defined for KineticsComp input.", CParser::OT_CONTINUE); + } + if (tol_defined == false) { + parser.incr_input_error(); + parser.error_msg("Tol not defined for KineticsComp input.", CParser::OT_CONTINUE); + } + if (m_defined == false) { + parser.incr_input_error(); + parser.error_msg("M not defined for KineticsComp input.", CParser::OT_CONTINUE); + } + if (m0_defined == false) { + parser.incr_input_error(); + parser.error_msg("M0 not defined for KineticsComp input.", CParser::OT_CONTINUE); + } + if (moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE); + } +} + +#ifdef SKIP +cxxKineticsComp& cxxKineticsComp::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxKineticsComp numkey; + + // Read kinetics_comp number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxKineticsComp& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in KINETICS_COMP keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.kinetics_comp_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in kinetics_comp.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif + diff --git a/KineticsComp.h b/KineticsComp.h new file mode 100644 index 00000000..899e114e --- /dev/null +++ b/KineticsComp.h @@ -0,0 +1,44 @@ +#if !defined(KINETICSCOMP_H_INCLUDED) +#define KINETICSCOMP_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxKineticsComp +{ + +public: + cxxKineticsComp(); + cxxKineticsComp(struct kinetics_comp *); + ~cxxKineticsComp(); + + static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + char * rate_name; + cxxNameDouble namecoef; + double tol; + double m; + double m0; + double moles; + std::vector d_params; + +public: + +}; + +#endif // !defined(KINETICSCOMP_H_INCLUDED) diff --git a/KineticsCxx.cxx b/KineticsCxx.cxx new file mode 100644 index 00000000..d440bbda --- /dev/null +++ b/KineticsCxx.cxx @@ -0,0 +1,538 @@ +// Kinetics.cxx: implementation of the cxxKinetics class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "KineticsCxx.h" +#include "KineticsComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxKinetics::cxxKinetics() + // + // default constructor for cxxKinetics + // +: cxxNumKeyword() +{ + step_divide = 1.0; + rk = 3; + bad_step_max = 500; + use_cvode = false; + totals.type = cxxNameDouble::ND_ELT_MOLES; +} + +cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr) + // + // constructor for cxxKinetics from struct kinetics + // +: +cxxNumKeyword(), +totals(kinetics_ptr->totals) +{ + int i; + + this->set_description(kinetics_ptr->description); + n_user = kinetics_ptr->n_user; + n_user_end = kinetics_ptr->n_user_end; + step_divide = kinetics_ptr->step_divide; + rk = kinetics_ptr->rk; + bad_step_max = kinetics_ptr->bad_step_max; + use_cvode = (kinetics_ptr->use_cvode == TRUE); + + // kinetics components + for (i = 0; i < kinetics_ptr->count_comps; i++) { + cxxKineticsComp ec(&(kinetics_ptr->comps[i])); + this->kineticsComps.push_back(ec); + } + + // steps + for (i = 0; i < kinetics_ptr->count_steps; i++) { + this->steps.push_back(kinetics_ptr->steps[i]); + } +} + +cxxKinetics::~cxxKinetics() +{ +} + +struct kinetics *cxxKinetics::cxxKinetics2kinetics() + // + // Builds a kinetics structure from instance of cxxKinetics + // +{ + struct kinetics *kinetics_ptr = kinetics_alloc(); + + kinetics_ptr->description = this->get_description(); + kinetics_ptr->n_user = this->n_user; + kinetics_ptr->n_user_end = this->n_user_end; + kinetics_ptr->step_divide = this->step_divide; + kinetics_ptr->rk = this->rk; + kinetics_ptr->bad_step_max = this->bad_step_max; + kinetics_ptr->use_cvode = (int) this->use_cvode; + + // totals + kinetics_ptr->totals = this->totals.elt_list(); + + // comps + kinetics_ptr->count_comps = this->kineticsComps.size(); + kinetics_ptr->comps = (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); + kinetics_ptr->comps = cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps); + + // steps + kinetics_ptr->count_steps = this->steps.size(); + kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps); + if (this->steps.size() > 0) { + kinetics_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + if (kinetics_ptr->steps == NULL) malloc_error(); + std::copy(this->steps.begin(), this->steps.end(), kinetics_ptr->steps); + /* + int i = 0; + for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { + kinetics_ptr->steps[i] = *it; + } + */ + } + return(kinetics_ptr); +} + +#ifdef SKIP +void cxxKinetics::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Kinetics element and attributes + s_oss << indent0; + s_oss << "pitzer_kinetics_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxKinetics::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Kinetics element and attributes + s_oss << indent0; + s_oss << "KINETICS_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-step_divide " << this->step_divide << std::endl; + + s_oss << indent1; + s_oss << "-rk " << this->rk << std::endl; + + s_oss << indent1; + s_oss << "-bad_step_max " << this->bad_step_max << std::endl; + + s_oss << indent1; + s_oss << "-use_cvode " << this->use_cvode << std::endl; + + // kineticsComps structures + for (std::list::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } + + // totals + s_oss << indent1; + s_oss << "-totals " << std::endl; + this->totals.dump_raw(s_oss, indent + 2); + + // steps + s_oss << indent1; + s_oss << "-steps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { + if (i++ == 5) { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } + return; +} + +void cxxKinetics::read_raw(CParser& parser) +{ + + double d; + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("step_divide"); + vopts.push_back("rk"); + vopts.push_back("bad_step_max"); + vopts.push_back("use_cvode"); + vopts.push_back("component"); + vopts.push_back("totals"); + vopts.push_back("steps"); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read kinetics number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool step_divide_defined(false); + bool rk_defined(false); + bool bad_step_max_defined(false); + bool use_cvode_defined(false); + + 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 KINETICS_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // step_divide + if (!(parser.get_iss() >> this->step_divide)) + { + this->step_divide = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for step_divide.", CParser::OT_CONTINUE); + } + step_divide_defined = true; + useLastLine = false; + break; + + case 1: // rk + if (!(parser.get_iss() >> this->rk)) + { + this->rk = 3; + parser.incr_input_error(); + parser.error_msg("Expected integer value for rk.", CParser::OT_CONTINUE); + } + rk_defined = true; + useLastLine = false; + break; + + case 2: // bad_step_max + if (!(parser.get_iss() >> this->bad_step_max)) + { + this->bad_step_max = 500; + parser.incr_input_error(); + parser.error_msg("Expected integer value for bad_step_max.", CParser::OT_CONTINUE); + } + bad_step_max_defined = true; + useLastLine = false; + break; + + case 3: // use_cvode + if (!(parser.get_iss() >> this->use_cvode)) + { + this->use_cvode = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for use_cvode.", CParser::OT_CONTINUE); + } + use_cvode_defined = true; + useLastLine = false; + break; + + case 4: // component + { + cxxKineticsComp kc; + kc.read_raw(parser); + this->kineticsComps.push_back(kc); + } + useLastLine = true; + break; + + case 5: // totals + if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for KineticsComp totals.", CParser::OT_CONTINUE); + } + opt_save = 5; + useLastLine = false; + + case 6: // steps + while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { + //sscanf(token.c_str(), "%lf", &d); + //this->steps.push_back(d); + std::istringstream iss(token); + if (!(iss >> d)) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE); + } else { + this->steps.push_back(d); + } + } + opt_save = 6; + useLastLine = false; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (step_divide_defined == false) { + parser.incr_input_error(); + parser.error_msg("Step_divide not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } + if (rk_defined == false) { + parser.incr_input_error(); + parser.error_msg("Rk not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } + if (bad_step_max_defined == false) { + parser.incr_input_error(); + parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } + if (use_cvode_defined == false) { + parser.incr_input_error(); + parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } +} +#ifdef SKIP +cxxKinetics& cxxKinetics::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxKinetics numkey; + + // Read kinetics number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxKinetics& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in KINETICS keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.kinetics_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in kinetics.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif diff --git a/KineticsCxx.h b/KineticsCxx.h new file mode 100644 index 00000000..ec218cfa --- /dev/null +++ b/KineticsCxx.h @@ -0,0 +1,51 @@ +#if !defined(KINETICS_H_INCLUDED) +#define KINETICS_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "KineticsComp.h" + +class cxxKinetics : public cxxNumKeyword +{ + +public: + cxxKinetics(); + cxxKinetics(struct kinetics *); + ~cxxKinetics(); + + struct kinetics *cxxKinetics2kinetics(); + + struct kinetics_comp *cxxKineticsComp2kinetics_comp(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + + bool get_related_phases(void); + + bool get_related_rate(void); + +protected: + std::list kineticsComps; + std::vector steps; + cxxNameDouble totals; + double step_divide; + int rk; + int bad_step_max; + bool use_cvode; +public: + //static std::map& map; + +}; + +#endif // !defined(KINETICS_H_INCLUDED) diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..293b837f --- /dev/null +++ b/Makefile @@ -0,0 +1,348 @@ +# +# Make file for PHREEQC +# +# $(CURDIR) is current directory +TOPDIR:=$(CURDIR)/.. +PROGRAM=phreeqcsax +EXE=$(TOPDIR)/bin/$(PROGRAM) +EXE=$(PROGRAM) +SRC:=$(CURDIR) + +# Do not print commands before executing +#.SILENT: + +# Provides compatibility with GNU make +#.SUFFIXES: + +# Change to pawd if using automounter +PWD=pwd + +# Change to C compiler on your system +CC=gcc + +USE_XML=TRUE +XERCESCROOT=/z/parkplace/home/dlpark/packages/xerces-c-src_2_7_0 + +# Change to C compiler options on your system +ifdef OPTIMIZE + CCFLAGS=-O3 -Wall -ansi -pedantic -I${XERCESCROOT}/include # -frounding-math # -pg + CCFLAGS_MODEL=-O2 -Wall -ansi -pedantic # -pg +else + CCFLAGS=-g -Wall -ansi -pedantic -I${XERCESCROOT}/include # -frounding-math # -pg + CCFLAGS_MODEL=-g -Wall -ansi -pedantic # -pg +endif +# Remove the following definition if you do not have +# gmp (Gnu Multiple Precision) package on your system +INVERSE_CL1MP=TRUE + +LOADFLAGS= -lm -lxerces-c # -pg + +PLATFORM= LINUX +CXX= g++ -c -D${PLATFORM} -D_REENTRANT -fpic +ifdef OPTIMIZE + CXXFLAGS= -O3 +else + CXXFLAGS= -Wall -g +endif +LINK= g++ -D${PLATFORM} -fpic +PLATFORM_LIB_LINK_OPTIONS=-L/usr/lib -L/usr/local/lib +EXTRA_LINK_OPTIONS=-lc +LIBRARY_NAMES= -lxerces-c +LIBRARY_SEARCH_PATHS= -L${XERCESCROOT}/lib # -L/home/dlpark/lib # +INCLUDES= -I${XERCESCROOT}/include + +#.c.o : +# ${CC} ${CCFLAGS} -c -o $@ $< +#%.o : $(SRC)/%.c +# ${CC} ${CCFLAGS} -c -o $@ $< +%.o : $(SRC)/%.cpp + ${CXX} ${CXXFLAGS} $(INCLUDES) -c -o $@ $< +%.o : $(SRC)/%.cxx + ${CXX} ${CXXFLAGS} $(INCLUDES) -c -o $@ $< + +# Location to copy scripts on installation +BINDIR=$(HOME)/bin + +OBJECTS= main.o \ + advection.o \ + basic.o \ + basicsubs.o \ + cl1.o \ + input.o \ + integrate.o \ + inverse.o \ + isotopes.o \ + kinetics.o \ + mainsubs.o \ + output.o \ + model.o \ + p2clib.o \ + parse.o \ + phreeqc_files.o \ + phqalloc.o \ + prep.o \ + print.o \ + read.o \ + readtr.o \ + spread.o \ + step.o \ + structures.o \ + tally.o \ + tidy.o \ + transport.o \ + utilities.o \ + cvdense.o \ + cvode.o \ + dense.o \ + nvector.o \ + nvector_serial.o \ + smalldense.o \ + sundialsmath.o \ + dw.o \ + pitzer.o \ + pitzer_structures.o \ + +CLASS_OBJECTS= Conc.o \ + Exchange.o \ + ExchComp.o \ + GasPhase.o \ + ISolution.o \ + Isotope.o \ + KineticsCxx.o \ + KineticsComp.o \ + Mix.o \ + NameDouble.o \ + NumKeyword.o \ + Parser.o \ + PPassemblage.o \ + PPassemblageComp.o \ + Reaction.o \ + ReadClass.o \ + Solution.o \ + SSassemblage.o \ + SSassemblageSS.o \ + Surface.o \ + SurfComp.o \ + SurfCharge.o \ + Temperature.o \ + Utils.o + +OBJECTS += $(CLASS_OBJECTS) + +ifdef USE_XML + OBJECTS += SAXPhreeqc.o +endif + +ifdef INVERSE_CL1MP + LOADFLAGS += /z/parkplace/usr/lib/libgmp.a + CCFLAGS += -DINVERSE_CL1MP + CXXFLAGS += -DINVERSE_CL1MP + OBJECTS += cl1mp.o +endif + +all: $(EXE) + +install: +# +# Create directory for binary and scripts if necessary +# + if [ ! -d $(BINDIR) ]; \ + then \ + mkdir $(BINDIR); \ + echo Created directory $(BINDIR); \ + fi +# +# Put path name of current directory into script for +# locating data files, put script in top directory, +# put symbolic link in BINDIR +# + cd $(TOPDIR); dir1=`$(PWD)`/bin; cd $(BINDIR); if [ `$(PWD)` = $$dir1 ]; \ + then \ + echo "Can not install to $(BINDIR). Choose another directory."; \ + exit 4 ; \ + fi + cd $(TOPDIR); \ + rm -f $(BINDIR)/$(PROGRAM); \ + rm -f $(PROGRAM); \ + sed "s?TOPDIR=.\{0,80\}?TOPDIR=`$(PWD)`?" bin/$(PROGRAM).orig > $(PROGRAM); \ + chmod 755 $(PROGRAM) + cd $(TOPDIR); dir1=`$(PWD)`; cd $(BINDIR); if [ `$(PWD)` != $$dir1 ]; then \ + ln -s $$dir1/$(PROGRAM) $(BINDIR); \ + echo Symbolic link for $(PROGRAM) has been placed in $(BINDIR). ; \ + fi +# +# Check that all necessary files are in place. +# + if [ -f $(BINDIR)/$(PROGRAM) -a \ + -f $(TOPDIR)/bin/$(PROGRAM) -a \ + -f $(TOPDIR)/$(PROGRAM) ]; \ + then echo "Installation complete."; \ + else echo "Installation incomplete."; \ + for FILE in $(BINDIR)/$(PROGRAM) \ + $(TOPDIR)/bin/$(PROGRAM) $(TOPDIR)/$(PROGRAM) ; \ + do \ + if [ ! -f $$FILE ]; then echo $$FILE is missing.; fi; \ + done; \ + fi + echo "Add directory $(BINDIR) to PATH." + +clean: + rm -f $(BINDIR)/$(PROGRAM) + rm -f $(TOPDIR)/bin/$(PROGRAM) + rm -f $(TOPDIR)/src/*.o + rm -f $(SUN_DIR)/bin/$(PROGRAM) + rm -f $(SUN_DIR)/src/*.o + rm -f $(TOPDIR)/src/$(PROGRAM) + rm -f $(DEBUG_DIR)/src/*.o + echo Removed object and executable files generated by make. + +$(EXE): $(OBJECTS) + echo $(TOPDIR) +ifdef USE_XML + ${LINK} ${PLATFORM_LIB_LINK_OPTIONS} ${OBJECTS} -o $(EXE) ${LIBRARY_SEARCH_PATHS} ${LIBRARY_NAMES} ${EXTRA_LINK_OPTIONS} ${LOADFLAGS} +else + $(CC) -o $(EXE) $(OBJECTS) $(LOADFLAGS) # -L/z/estespark/home/dlpark/packages/efence -lefence +endif + echo Compilation complete, $(EXE). + +advection.o: $(SRC)/advection.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +basic.o: $(SRC)/basic.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/p2c.h + +basicsubs.o: $(SRC)/basicsubs.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +cl1.o: $(SRC)/cl1.cpp $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h + +cl1mp.o: $(SRC)/cl1mp.cpp $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h + +cvdense.o: $(SRC)/cvdense.cpp $(SRC)/cvdense.h $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +cvode.o: $(SRC)/cvode.cpp $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/kinetics.h $(SRC)/phqalloc.h + +dense.o: $(SRC)/dense.cpp $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/output.h $(SRC)/phqalloc.h + +input.o: $(SRC)/input.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/input.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h + +integrate.o: $(SRC)/integrate.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +inverse.o: $(SRC)/inverse.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +isotopes.o: $(SRC)/isotopes.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +kinetics.o: $(SRC)/kinetics.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/sundialstypes.h $(SRC)/cvode.h $(SRC)/nvector.h $(SRC)/cvdense.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/nvector_serial.h $(SRC)/kinetics.h + +main.o: $(SRC)/main.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +mainsubs.o: $(SRC)/mainsubs.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +model.o: $(SRC)/model.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + ${CC} $(SRC)/model.cpp ${CCFLAGS_MODEL} -c -o model.o #-ffloat-store + +nvector.o: $(SRC)/nvector.cpp $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h + +nvector_serial.o: $(SRC)/nvector_serial.cpp $(SRC)/nvector_serial.h $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +output.o: $(SRC)/output.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h + +p2clib.o: $(SRC)/p2clib.cpp $(SRC)/p2c.h $(SRC)/output.h + +parse.o: $(SRC)/parse.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +phqalloc.o: $(SRC)/phqalloc.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h + +phreeqc_files.o: $(SRC)/phreeqc_files.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +pitzer.o: $(SRC)/pitzer.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer.h + +dw.o: $(SRC)/dw.cpp $(SRC)/pitzer.h + +pitzer_structures.o: $(SRC)/pitzer_structures.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer.h + +prep.o: $(SRC)/prep.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +prep.o: $(SRC)/prep.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +print.o: $(SRC)/print.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +read.o: $(SRC)/read.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +readtr.o: $(SRC)/readtr.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +SAXPhreeqc.o: $(SRC)/SAXPhreeqc.cpp $(SRC)/SAXPhreeqc.h $(SRC)/SaxPhreeqcHandlers.h + ${CXX} ${CXXFLAGS} $(INCLUDES) -o SAXPhreeqc.o $(SRC)/SAXPhreeqc.cpp + +smalldense.o: $(SRC)/smalldense.cpp $(SRC)/smalldense.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +spread.o: $(SRC)/spread.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +step.o: $(SRC)/step.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +structures.o: $(SRC)/structures.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +sundialsmath.o: $(SRC)/sundialsmath.cpp $(SRC)/sundialsmath.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h + +tally.o: $(SRC)/tally.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +tidy.o: $(SRC)/tidy.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +transport.o: $(SRC)/transport.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +utilities.o: $(SRC)/utilities.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +Conc.o: $(SRC)/Conc.cxx $(SRC)/Conc.h $(SRC)/Utils.h $(SRC)/char_star.h $(SRC)/ISolution.h $(SRC)/NumKeyword.h \ + $(SRC)/Parser.h $(SRC)/Solution.h $(SRC)/Isotope.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ + $(SRC)/phrqproto.h $(SRC)/phqalloc.h +Exchange.o: $(SRC)/Exchange.cxx $(SRC)/Utils.h $(SRC)/Exchange.h $(SRC)/NumKeyword.h Parser.h \ + $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/ExchComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ + $(SRC)/phrqproto.h +ExchComp.o: $(SRC)/ExchComp.cxx $(SRC)/Utils.h $(SRC)/ExchComp.h $(SRC)/NameDouble.h $(SRC)/global.h \ + $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +GasPhase.o: $(SRC)/GasPhase.cxx $(SRC)/Utils.h $(SRC)/GasPhase.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ + $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +ISolution.o: $(SRC)/ISolution.cxx $(SRC)/ISolution.h $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h \ + $(SRC)/Solution.h $(SRC)/Isotope.h $(SRC)/Conc.h $(SRC)/Utils.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ + $(SRC)/phqalloc.h $(SRC)/phrqproto.h +Isotope.o: $(SRC)/Isotope.cxx $(SRC)/Isotope.h $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/Utils.h $(SRC)/global.h \ + $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +KineticsComp.o: $(SRC)/KineticsComp.cxx $(SRC)/Utils.h $(SRC)/KineticsComp.h $(SRC)/NameDouble.h \ + $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +KineticsCxx.o: $(SRC)/KineticsCxx.cxx $(SRC)/Utils.h $(SRC)/KineticsCxx.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ + $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/KineticsComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ + $(SRC)/phrqproto.h +Mix.o: $(SRC)/Mix.cxx $(SRC)/Utils.h $(SRC)/Mix.h $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h \ + $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +NameDouble.o: $(SRC)/NameDouble.cxx $(SRC)/Utils.h $(SRC)/Conc.h $(SRC)/char_star.h $(SRC)/NameDouble.h \ + $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +NumKeyword.o: $(SRC)/NumKeyword.cxx $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h +Reaction.o: $(SRC)/Reaction.cxx $(SRC)/Utils.h $(SRC)/Reaction.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ + $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +ReadClass.o: $(SRC)/ReadClass.cpp +Parser.o: $(SRC)/Parser.cxx $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/Utils.h +PPassemblageComp.o: $(SRC)/PPassemblageComp.cxx $(SRC)/Utils.h $(SRC)/NameDouble.h \ + $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +PPassemblage.o: $(SRC)/PPassemblage.cxx $(SRC)/Utils.h $(SRC)/PPassemblage.h $(SRC)/NumKeyword.h \ + $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/PPassemblageComp.h \ + $(SRC)/NameDouble.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +Solution.o: $(SRC)/Solution.cxx $(SRC)/Utils.h $(SRC)/Solution.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ + $(SRC)/char_star.h $(SRC)/Isotope.h $(SRC)/Conc.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ + $(SRC)/phqalloc.h $(SRC)/phrqproto.h $(SRC)/ISolution.h +SSassemblage.o: $(SRC)/SSassemblage.cxx $(SRC)/Utils.h $(SRC)/SSassemblage.h $(SRC)/NumKeyword.h \ + $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/SSassemblageSS.h \ + $(SRC)/NameDouble.h $(SRC)/SSassemblageSS.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h +SSassemblageSS.o: $(SRC)/SSassemblageSS.cxx $(SRC)/Utils.h $(SRC)/SSassemblageSS.h \ + $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h \ + $(SRC)/phrqproto.h +Surface.o: $(SRC)/Surface.cxx $(SRC)/Utils.h $(SRC)/Surface.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ + $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/SurfComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ + $(SRC)/phrqproto.h +SurfComp.o: $(SRC)/SurfComp.cxx $(SRC)/Utils.h $(SRC)/SurfComp.h $(SRC)/NameDouble.h $(SRC)/global.h \ + $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h + +Temperature.o: $(SRC)/Temperature.cxx $(SRC)/Utils.h $(SRC)/Temperature.h $(SRC)/NumKeyword.h \ + $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h \ + $(SRC)/phrqproto.h +Utils.o: $(SRC)/Utils.cxx $(SRC)/Utils.h $(SRC)/Parser.h $(SRC)/char_star.h + +-include $(SRC)/distribution.mk + + diff --git a/Mix.cxx b/Mix.cxx new file mode 100644 index 00000000..bc65783f --- /dev/null +++ b/Mix.cxx @@ -0,0 +1,200 @@ +// Mix.cxx: implementation of the cxxMix class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Mix.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxMix::cxxMix() + // + // default constructor for cxxMix + // +: cxxNumKeyword() +{ +} + +cxxMix::cxxMix(struct mix *mix_ptr) + // + // constructor for cxxMix from struct mix + // +: +cxxNumKeyword() +{ + int i; + + this->set_description(mix_ptr->description); + this->n_user = mix_ptr->n_user; + this->n_user_end = mix_ptr->n_user_end; + // comps + if (mix_ptr->count_comps > 0) { + for (i = 0; i < mix_ptr->count_comps; i++) { + this->mixComps[mix_ptr->comps[i].n_solution] = mix_ptr->comps[i].fraction; + } + } +} + +cxxMix::~cxxMix() +{ +} + + +struct mix *cxxMix::cxxMix2mix() + // + // Builds a mix structure from instance of cxxMix + // +{ + struct mix *mix_ptr; + mix_ptr = (struct mix *) PHRQ_malloc(sizeof (struct mix)); + if (mix_ptr == NULL) malloc_error(); + + mix_ptr->description = this->get_description(); + mix_ptr->n_user = this->n_user; + mix_ptr->n_user_end = this->n_user_end; + + // comps + mix_ptr->comps = NULL; + if (this->mixComps.size() > 0) { + int i = 0; + mix_ptr->comps = (struct mix_comp *) PHRQ_malloc((size_t) (this->mixComps.size() * sizeof(struct mix_comp))); + if (mix_ptr->comps == NULL) malloc_error(); + for (std::map::iterator it = mixComps.begin(); it != mixComps.end(); it++) { + mix_ptr->comps[i].n_solution = it->first; + mix_ptr->comps[i].fraction = it->second; + i++; + } + } + mix_ptr->count_comps = this->mixComps.size(); + return(mix_ptr); +} + +#ifdef SKIP +void cxxMix::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Mix element and attributes + s_oss << indent0; + s_oss << "pitzer_mix_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxMix::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Mix element and attributes + s_oss << indent0; + s_oss << "MIX " << this->n_user << " " << this->description << std::endl; + + for (std::map::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { + s_oss << indent1 << it->first << " " << it->second << std::endl; + } +} + +void cxxMix::read_raw(CParser& parser) +{ + + int i; + double d; + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read mix number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_DEFAULT; + + 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_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input in MIX_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case CParser::OPT_DEFAULT: // solution number, mix fraction + if (parser.copy_token(token, next_char) != CParser::TT_EMPTY) { + std::istringstream iss(token); + if (!(iss >> i)) + { + parser.incr_input_error(); + parser.error_msg("Expected integer value for solution number.", CParser::OT_CONTINUE); + break; + } + if (!(parser.get_iss() >> d)) + { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for solution fraction.", CParser::OT_CONTINUE); + break; + } + this->mixComps[i] = d; + } + opt_save = CParser::OPT_DEFAULT; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined +} diff --git a/Mix.h b/Mix.h new file mode 100644 index 00000000..9180c5b6 --- /dev/null +++ b/Mix.h @@ -0,0 +1,39 @@ +#if !defined(MIX_H_INCLUDED) +#define MIX_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxMix : public cxxNumKeyword +{ + +public: + cxxMix(); + cxxMix(struct mix *); + ~cxxMix(); + + struct mix *cxxMix2mix(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + std::map mixComps; + +public: + //static std::map& map; + +}; + +#endif // !defined(MIX_H_INCLUDED) diff --git a/NameDouble.cxx b/NameDouble.cxx new file mode 100644 index 00000000..b4385bf8 --- /dev/null +++ b/NameDouble.cxx @@ -0,0 +1,259 @@ +// NameDouble.cxx: implementation of the cxxNameDouble class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Conc.h" +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxNameDouble::cxxNameDouble() + // + // default constructor for cxxNameDouble + // +{ +} + +cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + int i; + if (elt_list_ptr != NULL) { + for (i = 0; elt_list_ptr[i].elt != NULL; i++) { + (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; + } + } + this->type = ND_ELT_MOLES; +} +cxxNameDouble::cxxNameDouble(struct conc *tots) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + int i; + for (i = 0; tots[i].description != NULL; i++) { + (*this)[tots[i].description] = tots[i].moles; + } + this->type = ND_ELT_MOLES; +} +cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + int i; + for (i = 0; i < count; i++) { + if (ma[i].description == NULL) continue; + (*this)[ma[i].description] = ma[i].la; + } + this->type = ND_SPECIES_LA; +} +cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count, cxxNameDouble::ND_TYPE) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + int i; + for (i = 0; i < count; i++) { + if (nc[i].name == NULL) continue; + (*this)[nc[i].name] = nc[i].coef; + } + this->type = ND_NAME_COEF; +} +cxxNameDouble::~cxxNameDouble() +{ +} + +struct elt_list *cxxNameDouble::elt_list() + // + // Builds a exch_comp structure from instance of cxxNameDouble + // +{ + assert (this->type == cxxNameDouble::ND_ELT_MOLES); + struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((size_t)((this->size() + 1) *sizeof(struct elt_list))); + if (elt_list_ptr == NULL) malloc_error(); + int i = 0; + for (iterator it = this->begin(); it != this->end(); ++it) { + elt_list_ptr[i].elt = element_store(it->first); + elt_list_ptr[i].coef = it->second; + i++; + } + elt_list_ptr[i].elt = NULL; + elt_list_ptr[i].coef = 0; + return(elt_list_ptr); +} + +struct master_activity *cxxNameDouble::master_activity()const + // + // Builds a list of master_activity structures from instance of cxxNameDouble + // +{ + int i = 0; + assert (this->type == cxxNameDouble::ND_SPECIES_LA || this->type == cxxNameDouble::ND_SPECIES_GAMMA); + struct master_activity *master_activity_ptr = NULL; + switch ((*this).type) { + case cxxNameDouble::ND_SPECIES_LA: + { + master_activity_ptr= (struct master_activity *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct master_activity))); + if (master_activity_ptr == NULL) malloc_error(); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { + master_activity_ptr[i].description = (char *)it->first; + master_activity_ptr[i].la = it->second; + i++; + } + } + master_activity_ptr[i].description = NULL; + break; + case cxxNameDouble::ND_SPECIES_GAMMA: + { + if ((*this).size() > 0) { + master_activity_ptr = (struct master_activity *) PHRQ_malloc((size_t) (((*this).size()) * sizeof(struct master_activity))); + if (master_activity_ptr == NULL) malloc_error(); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { + master_activity_ptr[i].description = (char *)it->first; + master_activity_ptr[i].la = it->second; + i++; + } + } + } + break; + case cxxNameDouble::ND_ELT_MOLES: + case cxxNameDouble::ND_NAME_COEF: + break; + } + return(master_activity_ptr); +} + +struct conc *cxxNameDouble::conc()const + // for Solutions, not ISolutions + // takes a map of (elt name, moles) + // returns list of conc structures +{ + struct conc *c; + assert (this->type == cxxNameDouble::ND_ELT_MOLES); + c = (struct conc *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); + if (c == NULL) malloc_error(); + int i = 0; + for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { + c[i].description = (char *)it->first; + c[i].moles = it->second; + c[i].input_conc = it->second; + c[i].units = NULL; + c[i].equation_name = NULL; + c[i].phase_si = 0.0; + c[i].n_pe = 0; + c[i].as = NULL; + c[i].gfw = 0.0; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return(c); +} + +struct name_coef *cxxNameDouble::name_coef()const + // + // Builds a name_coef structure from instance of cxxNameDouble + // +{ + assert (this->type == cxxNameDouble::ND_NAME_COEF); + struct name_coef *name_coef_ptr = (struct name_coef *) PHRQ_malloc((size_t)((this->size()) *sizeof(struct name_coef))); + if (name_coef_ptr == NULL) malloc_error(); + int i = 0; + for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { + name_coef_ptr[i].name = it->first; + name_coef_ptr[i].coef = it->second; + i++; + } + return(name_coef_ptr); +} + +void cxxNameDouble::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + std::string xmlElement, xmlAtt1, xmlAtt2; + + switch ((*this).type) { + case cxxNameDouble::ND_SPECIES_LA: + xmlElement = "first << xmlAtt2 << it->second << "/>" << std::endl; + } +} + +void cxxNameDouble::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { + s_oss << indent0; + s_oss << it->first << " " << it->second << std::endl; + } +} +CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_type& pos) +{ + std::string token; + char * ctoken; + double d; + + CParser::TOKEN_TYPE j; + + //m_line_iss.seekg(pos); + + j = parser.copy_token(token, pos); + + if (j == CParser::TT_EMPTY) return CParser::PARSER_OK; + + if( !(parser.get_iss() >> d)) { + return CParser::PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + (*this)[ctoken] = d; + return CParser::PARSER_OK; +} diff --git a/NameDouble.h b/NameDouble.h new file mode 100644 index 00000000..0977d958 --- /dev/null +++ b/NameDouble.h @@ -0,0 +1,57 @@ +#if !defined(NAMEDOUBLE_H_INCLUDED) +#define NAMEDOUBLE_H_INCLUDED + +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "Parser.h" +class cxxNameDouble : public std::map +{ + +public: + enum ND_TYPE { + ND_ELT_MOLES = 1, + ND_SPECIES_LA = 2, + ND_SPECIES_GAMMA = 3, + ND_NAME_COEF = 4 + }; + + cxxNameDouble(); + cxxNameDouble(struct elt_list *); + cxxNameDouble(struct conc *); + cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); + cxxNameDouble(struct name_coef *nc, int count, ND_TYPE); + ~cxxNameDouble(); + + struct elt_list *elt_list(); + + struct master_activity *master_activity()const; + + struct conc *conc()const; + + struct name_coef *name_coef()const; + + void cxxNameDouble::dump_xml(std::ostream& s_oss, unsigned int indent)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); + + enum ND_TYPE type; + +protected: + //std::map totals; + + +public: + //static std::map& map; + +}; + +#endif // !defined(NAMEDOUBLE_H_INCLUDED) diff --git a/NumKeyword.cxx b/NumKeyword.cxx new file mode 100644 index 00000000..c0d3e64d --- /dev/null +++ b/NumKeyword.cxx @@ -0,0 +1,138 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +// NumKeyword.cxx: implementation of the cxxNumKeyword class. +// +////////////////////////////////////////////////////////////////////// + +#include "NumKeyword.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxNumKeyword::cxxNumKeyword() +{ +} + +cxxNumKeyword::~cxxNumKeyword() +{ +} + +void cxxNumKeyword::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->n_user << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->n_user_end << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->description << "" << "\n"; +} + +void cxxNumKeyword::read_number_description(CParser& parser) +{ + std::string keyword; + std::istream::pos_type ptr; + + // skip keyword + parser.copy_token(keyword, ptr); + + std::istream::pos_type ptr1 = ptr; + std::string::size_type pos; + std::string token; + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) + { + this->n_user = 1; + this->n_user_end = 1; + } else { + std::istringstream iss(token); + iss >> this->n_user; + this->n_user_end = this->n_user; + std::string token1; + iss >> token1; + if ( (pos = token1.find_first_of("-")) != std::string::npos ) { + token1.replace(pos, 1, " "); + std::istringstream iss1(token1); + iss1 >> this->n_user_end; + // ptr1 = ptr; + } + } + /* + else if ( (pos = token.find_first_of("-")) != std::string::npos ) + { + token.replace(pos, 1, " "); + std::istringstream iss(token); + if (!(iss >> this->n_user >> this->n_user_end)) + { + std::ostringstream err_oss; + if (parser.next_keyword() >= 0) + { + err_oss << "Reading number range for " << keyword << "."; + } + else + { + err_oss << "Reading number range for keyword."; + } + parser.error_msg(err_oss, CParser::OT_CONTINUE); + parser.incr_input_error(); + } + ptr1 = ptr; + } + else + { + std::istringstream iss(token); + iss >> this->n_user; + this->n_user_end = this->n_user; + ptr1 = ptr; + } + */ + // reset get position + //parser.get_iss().seekg(ptr1); + + // skip whitespace + while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore(); + + // copy description + std::getline(parser.get_iss(), this->description); +} + + +void cxxNumKeyword::read_number_description(std::istream& is) +{ + // KEYWORD [[1[-20]] [This is the description]] + + // eat keyword + std::string token; + is >> token; + + // skip whitespace + while (::isspace(is.peek())) is.ignore(); + + if (::isdigit(is.peek())) + { + is >> this->n_user; + char ch = is.peek(); + if (ch == '-') + { + is >> ch; // eat '-' + is >> this->n_user_end; + } + else + { + this->n_user_end = this->n_user; + } + } + else + { + this->n_user = this->n_user_end = 1; + } + + while (::isspace(is.peek())) is.ignore(); + + std::getline(is, this->description); +} + diff --git a/NumKeyword.h b/NumKeyword.h new file mode 100644 index 00000000..55298566 --- /dev/null +++ b/NumKeyword.h @@ -0,0 +1,43 @@ +#if !defined(NUMKEYWORD_H_INCLUDED) +#define NUMKEYWORD_H_INCLUDED + +#include "Parser.h" +#include // std::ostream +#include // std::string +//#define EXTERNAL extern +//#include "global.h" +//#include "phrqproto.h" +extern char *string_duplicate(const char *); + +class cxxNumKeyword +{ +public: + cxxNumKeyword(); + virtual ~cxxNumKeyword(); + + + char * get_description()const { return string_duplicate(this->description.c_str()); } + void set_description(std::string str) { this->description = str; } + void set_description(char * str) { if (str != NULL) this->description = str; } + + int get_n_user()const { return this->n_user; } + void set_n_user(int user) { this->n_user = user; } + + int get_n_user_end()const { return this->n_user_end; } + void set_n_user_end(int user_end) { this->n_user_end = user_end; } + + bool operator<(const cxxNumKeyword& key)const { return (this->n_user < key.n_user); } + + virtual void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void read_number_description(CParser& parser); + +protected: + int n_user; + int n_user_end; + std::string description; + +private: + void read_number_description(std::istream& is); +}; +#endif // !defined(NUMKEYWORD_H_INCLUDED) diff --git a/PPassemblage.cxx b/PPassemblage.cxx new file mode 100644 index 00000000..a258959b --- /dev/null +++ b/PPassemblage.cxx @@ -0,0 +1,191 @@ +// PPassemblage.cxx: implementation of the cxxPPassemblage class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "PPassemblage.h" +#include "PPassemblageComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxPPassemblage::cxxPPassemblage() + // + // default constructor for cxxPPassemblage + // +: cxxNumKeyword() +{ + eltList.type = cxxNameDouble::ND_ELT_MOLES; +} + +cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr) + // + // constructor for cxxPPassemblage from struct PPassemblage + // +: +cxxNumKeyword(), +eltList(pp_assemblage_ptr->next_elt) +{ + int i; + + this->set_description(pp_assemblage_ptr->description); + n_user = pp_assemblage_ptr->n_user; + n_user_end = pp_assemblage_ptr->n_user_end; + for (i = 0; i < pp_assemblage_ptr->count_comps; i++) { + cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i])); + ppAssemblageComps.push_back(ppComp); + } +} + +cxxPPassemblage::~cxxPPassemblage() +{ +} + +struct pp_assemblage *cxxPPassemblage::cxxPPassemblage2pp_assemblage() + // + // Builds a pp_assemblage structure from instance of cxxPPassemblage + // +{ + struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); + + pp_assemblage_ptr->description = this->get_description(); + pp_assemblage_ptr->n_user = this->n_user; + pp_assemblage_ptr->n_user_end = this->n_user_end; + pp_assemblage_ptr->new_def = FALSE; + pp_assemblage_ptr->count_comps = this->ppAssemblageComps.size(); + pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); + pp_assemblage_ptr->pure_phases = cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps); + pp_assemblage_ptr->next_elt = this->eltList.elt_list(); + return(pp_assemblage_ptr); +} + +void cxxPPassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // PPassemblage element and attributes + s_oss << indent0; + s_oss << "eltList.dump_xml(s_oss, indent + 1); + + // ppAssemblageComps + s_oss << indent1; + s_oss << "::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } +} + +void cxxPPassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // PPassemblage element and attributes + s_oss << indent0; + s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this->description << std::endl; + + // eltList + + s_oss << indent1; + s_oss << "-eltList " << std::endl; + this->eltList.dump_raw(s_oss, indent + 2); + + // ppAssemblagComps + for (std::list::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } +} + +void cxxPPassemblage::read_raw(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("eltlist"); // 0 + vopts.push_back("component"); // 1 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read PPassemblage 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 EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // eltList + if ( this->eltList.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and moles for totals.", CParser::OT_CONTINUE); + } + opt_save = 0; + break; + + case 1: // component + { + cxxPPassemblageComp ppComp; + ppComp.read_raw(parser); + this->ppAssemblageComps.push_back(ppComp); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined +} diff --git a/PPassemblage.h b/PPassemblage.h new file mode 100644 index 00000000..34af42e8 --- /dev/null +++ b/PPassemblage.h @@ -0,0 +1,43 @@ +#if !defined(PPASSEMBLAGE_H_INCLUDED) +#define PPASSEMBLAGE_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "PPassemblageComp.h" + +class cxxPPassemblage : public cxxNumKeyword +{ + +public: + cxxPPassemblage(); + cxxPPassemblage(struct pp_assemblage *); + ~cxxPPassemblage(); + + struct pp_assemblage *cxxPPassemblage2pp_assemblage(); + + struct pure_phase *cxxPPassemblageComp2pure_phase(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + std::list ppAssemblageComps; + cxxNameDouble eltList; + +public: + //static std::map& map; + +}; + +#endif // !defined(PPASSEMBLAGE_H_INCLUDED) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx new file mode 100644 index 00000000..0ba431f6 --- /dev/null +++ b/PPassemblageComp.cxx @@ -0,0 +1,278 @@ +// PPassemblageComp.cxx: implementation of the cxxPPassemblageComp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "PPassemblageComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxPPassemblageComp::cxxPPassemblageComp() + // + // default constructor for cxxPPassemblageComp + // +{ + name = NULL; + add_formula = NULL; + si = 0; + moles = 0; + delta = 0; + initial_moles = 0; + dissolve_only = false; +} + +cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase *pure_phase_ptr) + // + // constructor for cxxPPassemblageComp from struct pure_phase + // + +{ + name = pure_phase_ptr->name; + add_formula = pure_phase_ptr->add_formula; + si = pure_phase_ptr->si; + moles = pure_phase_ptr->moles; + delta = pure_phase_ptr->delta; + initial_moles = pure_phase_ptr->initial_moles; + dissolve_only = ( pure_phase_ptr->dissolve_only == TRUE); +} + +cxxPPassemblageComp::~cxxPPassemblageComp() +{ +} + +struct phase *cxxPPassemblageComp::get_phase() { + int i; + return phase_bsearch(this->name, &i, FALSE); +} + +struct pure_phase *cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list& el) + // + // Builds pure_phase structure from of cxxPPassemblageComp + // +{ + struct pure_phase *pure_phase_ptr = (struct pure_phase *) PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); + if (pure_phase_ptr == NULL) malloc_error(); + + int i = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + pure_phase_ptr[i].phase = it->get_phase(); + pure_phase_ptr[i].name = it->name; + pure_phase_ptr[i].add_formula = it->add_formula; + pure_phase_ptr[i].si = it->si; + pure_phase_ptr[i].moles = it->moles; + pure_phase_ptr[i].delta = it->delta; + pure_phase_ptr[i].initial_moles = it->initial_moles; + pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; + i++; + } + return(pure_phase_ptr); +} + +void cxxPPassemblageComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Pure_Phase element and attributes + + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl; + s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl; + s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl; + +} + +void cxxPPassemblageComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Pure_Phase element and attributes + + if (this->name != NULL) s_oss << indent0 << "-name " << this->name << std::endl; + if (this->add_formula != NULL) s_oss << indent0 << "-add_formula " << this->add_formula << std::endl; + s_oss << indent0 << "-si " << this->si << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-delta " << this->delta << std::endl; + s_oss << indent0 << "-initial_moles " << this->initial_moles << std::endl; + s_oss << indent0 << "-dissolve_only " << this->dissolve_only << std::endl; +} + +void cxxPPassemblageComp::read_raw(CParser& parser) +{ + std::string str; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("add_formula"); // 1 + vopts.push_back("si"); // 2 + vopts.push_back("moles"); // 3 + vopts.push_back("delta"); // 4 + vopts.push_back("initial_moles"); // 5 + vopts.push_back("dissolve_only"); // 6 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + bool si_defined(false); + bool moles_defined(false); + bool delta_defined(false); + bool initial_moles_defined(false); + bool dissolve_only_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); + } else { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + break; + + case 1: // add_formula + if (!(parser.get_iss() >> str)) + { + this->add_formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for add_formula.", CParser::OT_CONTINUE); + } else { + this->add_formula = string_hsave(str.c_str()); + } + break; + + case 2: // si + if (!(parser.get_iss() >> this->si)) + { + this->si = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for si.", CParser::OT_CONTINUE); + } + si_defined = true; + break; + + case 3: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); + } + moles_defined = true; + break; + + case 4: // delta + if (!(parser.get_iss() >> this->delta)) + { + this->delta = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for delta.", CParser::OT_CONTINUE); + } + delta_defined = true; + break; + + case 5: // initial_moles + if (!(parser.get_iss() >> this->initial_moles)) + { + this->initial_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial_moles.", CParser::OT_CONTINUE); + } + initial_moles_defined = true; + break; + + + case 6: // dissolve_only + if (!(parser.get_iss() >> this->dissolve_only)) + { + this->dissolve_only = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for dissolve_only.", CParser::OT_CONTINUE); + } + dissolve_only_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (name_defined == false) { + parser.incr_input_error(); + parser.error_msg("Name not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } + if (si_defined == false) { + parser.incr_input_error(); + parser.error_msg("Si not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } + if (moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } + if (delta_defined == false) { + parser.incr_input_error(); + parser.error_msg("Delta not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } + if (initial_moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Initial_moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } + if (dissolve_only_defined == false) { + parser.incr_input_error(); + parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } +} + diff --git a/PPassemblageComp.h b/PPassemblageComp.h new file mode 100644 index 00000000..7020a055 --- /dev/null +++ b/PPassemblageComp.h @@ -0,0 +1,47 @@ +#if !defined(PPASSEMBLAGECOMP_H_INCLUDED) +#define PPASSEMBLAGECOMP_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxPPassemblageComp +{ + +public: + cxxPPassemblageComp(); + cxxPPassemblageComp(struct pure_phase *); + ~cxxPPassemblageComp(); + + + static struct pure_phase *cxxPPassemblageComp2pure_phase(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + + struct phase *get_phase(); + +protected: + char * name; + char *add_formula; + double si; + double moles; + double delta; + double initial_moles; + bool dissolve_only; + +public: + +}; + +#endif // !defined(PPASSEMBLAGECOMP_H_INCLUDED) diff --git a/Parser.cxx b/Parser.cxx new file mode 100644 index 00000000..48f78c22 --- /dev/null +++ b/Parser.cxx @@ -0,0 +1,1070 @@ +// Parser.cpp: implementation of the CParser class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Parser.h" +#include "Utils.h" +#include // std::transform +#include // std::map +#include // assert +#include // std::cout std::cerr +#include "char_star.h" +extern char *string_hsave (const char *str); + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CParser::CParser(std::istream& input) +: m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::CParser(std::istream& input, std::ostream& output) +: m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) +: m_input_stream(input), m_output_stream(output), m_error_stream(error) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::~CParser() +{ +} + +CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print) +{ + LINE_TYPE i; + + // Get line + do { + i = get_line(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + + if (true) // pr.echo_input == TRUE + { + if ((print && i != LT_EOF) || i == LT_KEYWORD) + { + get_output() << "\t" << m_line_save << "\n"; + } + } + + } while (i == LT_EMPTY && allow_empty == false); + + // Check eof + if (i == LT_EOF && allow_eof == false) + { + std::ostringstream msg; + msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; + error_msg(msg, OT_STOP); + } + + // Check keyword + if (i == LT_KEYWORD && allow_keyword == false) + { + std::ostringstream msg; + msg << "Expected data for " << str << ", but got a keyword ending data block."; + error_msg(msg, OT_CONTINUE); + incr_input_error(); + } + m_line_type = i; + return i; +} + +CParser::LINE_TYPE CParser::get_line() +{ + CParser::LINE_TYPE return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + // + // Eliminate all characters after # sign as a comment + // + + // + // Get line, check for eof + // + if (get_logical_line() == LT_EOF) + { + if (!m_input_stream.eof()) + { + error_msg("Reading input file.", OT_CONTINUE); + error_msg("istream::get() returned an error.", OT_STOP); + } + else + { + //{{MOD + m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + //}}MOD + m_next_keyword = KT_EOF; + return LT_EOF; + } + } + + // + // Get long lines + // + bool empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + } + + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' && ::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + return return_value; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +CParser::LINE_TYPE CParser::get_logical_line() +{ + int j; + unsigned int pos; + char c; + + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + + while ((j = m_input_stream.get()) != std::char_traits::eof()) { + c = (char) j; + if (c == '#') { + // ignore all chars after # until newline + do { + c = (char) j; + if (c == '\n') { + break; + } + m_line_save += c; + } while ((j = m_input_stream.get()) != std::char_traits::eof()); + } + if (c == ';') break; + if (c == '\n') { + break; + } + if (c == '\\') { + pos = m_line_save.size(); + m_line_save += c; + while ((j = m_input_stream.get()) != std::char_traits::eof()) { + c = (char) j; + if (c == '\\') { + pos = m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') { + // remove '\\' + for (; pos < m_line_save.size(); pos++) { + m_line_save[pos] = m_line_save[pos+1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) break; + } + } else { + m_line_save += c; + } + } + if (j == std::char_traits::eof() && m_line_save.size() == 0) { + return(LT_EOF); + } + return(LT_OK); +} + + +//bool CParser::check_key(const std::string::iterator ptr) +bool CParser::check_key(std::string::iterator begin, std::string::iterator end) +{ + static std::map s_keyword_map; + if (s_keyword_map.size() == 0) + { + s_keyword_map.insert(std::map::value_type("solution", KT_SOLUTION)); + s_keyword_map.insert(std::map::value_type("solution_raw", KT_SOLUTION_RAW)); + s_keyword_map.insert(std::map::value_type("end", KT_END)); + } + + std::string lowercase; + copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); + + m_next_keyword = KT_NONE; + std::map::iterator map_iter = s_keyword_map.find(lowercase); + if (map_iter == s_keyword_map.end()) + return false; + m_next_keyword = (*map_iter).second; + return true; +} + +CParser::STATUS_TYPE CParser::check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, + const std::string& default_units, bool print) +{ +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity true if alkalinity, false if any other total, + * check_compatibility true check alk and default units, false otherwise + * default_units character string of default units (check /L, /kg, etc) + * print true print warning messages + * Output: + * tot_units standard form for unit + */ + using Utilities::str_tolower; + using Utilities::replace; + using Utilities::squeeze_white; + + static const char *units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + + std::string::size_type end; + if ((end = tot_units.find("/l")) != std::string::npos) { + tot_units.resize(end + 2); + } + if ((end = tot_units.find("/kgs")) != std::string::npos) { + tot_units.resize(end + 4); + } + if ((end = tot_units.find("/kgw")) != std::string::npos) { + tot_units.resize(end + 4); + } + + // + // Check if unit in list + // + bool found = false; + for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) { + if (tot_units.compare(units[i]) == 0) { + found = true; + break; + } + } + if (!found) { + if (print) { + std::ostringstream err; + err << "Unknown unit, " << tot_units; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // Check if units are compatible with default_units + // + if (check_compatibility == false) return PARSER_OK; + + // + // Special cases for alkalinity + // + if (alkalinity == true && tot_units.find("Mol") != std::string::npos) { + if (print) { + warning_msg("Alkalinity given in moles, assumed to be equivalents."); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == false && tot_units.find("eq") != std::string::npos) { + if (print) { + error_msg("Only alkalinity can be entered in equivalents.", OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // See if default_units are compatible with tot_units + // + if (default_units.find("/l") != std::string::npos && tot_units.find("/l") != std::string::npos) return PARSER_OK; + if (default_units.find("/kgs") != std::string::npos && tot_units.find("/kgs") != std::string::npos) return PARSER_OK; + if (default_units.find("/kgw") != std::string::npos && tot_units.find("/kgw") != std::string::npos) return PARSER_OK; + + std::string str = default_units; + replace("kgs", "kg solution", str); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", str); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", str); + replace("Mol", "mol", str); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); + + if (print) { + std::ostringstream err; + err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; +} + +CParser::TOKEN_TYPE CParser::token_type(const std::string& token) +{ + if (!token.empty()) { + if (::isupper(token[0])) { + return CParser::TT_UPPER; + } else if (::islower(token[0])) { + return CParser::TT_LOWER; + } else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') { + return CParser::TT_DIGIT; + } else { + assert(!::isspace(token[0])); + return CParser::TT_UNKNOWN; + } + } + else { + return CParser::TT_EMPTY; + } +} + +CParser::TOKEN_TYPE CParser::peek_token() +{ + std::istringstream::pos_type pos = m_line_iss.tellg(); + std::string token; + m_line_iss >> token; + m_line_iss.seekg(pos); + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end) +{ + if (begin != end) + { + std::string::iterator b = begin; + for (; b < end && ::isspace(*b); ++b); + + begin = b; + for (; begin < end && !::isspace(*begin); ++begin); + + token.assign(b, begin); + } + else + { + token.resize(0); + } + + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream& is) +{ + is >> token; + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream::pos_type& pos) +{ + m_line_iss.seekg(pos); + // m_line_iss >> token; + if( !(m_line_iss >> token)) { + token.erase(token.begin(), token.end()); // token.clear(); + } + pos = m_line_iss.tellg(); + return token_type(token); +} + +CParser::FIND_TYPE CParser::find_option(const std::string& item, int *n, const std::vector& list, bool exact) +{ + std::string token(item); + std::transform(token.begin(), token.end(), token.begin(), tolower); + for (unsigned int i = 0; i < list.size(); i++) + { + if (exact == true) + { + if (list[i].compare(token) == 0) + { + *n = i; + return FT_OK; + } + } + else + { + if(list[i].find(token) == 0) + { + *n = i; + return FT_OK; + } + } + } + + *n = -1; + return FT_ERROR; +} + +// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) +// OPTION_TYPE CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +int CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; + + // char option[MAX_LENGTH]; + std::string option; + + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, false); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); + + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; + + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int CParser::get_option(const std::vector& opt_list, std::istream::pos_type& next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, false); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //error_msg("Unknown option.", OT_CONTINUE); + //error_msg(m_line_save.c_str(), OT_CONTINUE); + incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) +{ + m_error_stream << "ERROR: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "ERROR: " << err_str << "\n"; + m_output_stream.flush(); + + if (ot == OT_STOP) + { + exit(1); + } + return 0; +} + +int CParser::warning_msg(const char *err_str) +{ + m_error_stream << "WARNING: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "WARNING: " << err_str << "\n"; + m_output_stream.flush(); + + return 0; +} + +CParser::STATUS_TYPE CParser::get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element) +{ + element.erase(element.begin(), element.end()); // element.clear(); + + if (begin == end) { + error_msg("Empty string in get_elt. Expected an element name.", OT_CONTINUE); + return PARSER_ERROR; + } + + // + // Load name into char array element + // + char c = *begin; + ++begin; + element.insert(element.end(), c); // element.push_back(c); + if (c == '[') { + while ( (c = *begin) != ']' ) { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if ( (c = *begin) == ']' ) { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + break; + } else if (begin == end) { + error_msg("No ending bracket (]) for element name", OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + } + while (::islower(c = *begin) || c == '_') { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) break; + } + } else { + while (::islower(c = *begin) || c == '_') { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) break; + } + } + return PARSER_OK; +} + +CParser::STATUS_TYPE CParser::parse_couple(std::string& token) +{ + // Parse couple puts redox couples in standard form + // "+" is removed and couples are rewritten in sort + // order. + + if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) { + Utilities::str_tolower(token); + return PARSER_OK; + } + + while ( Utilities::replace("+", "", token) ); + + std::string::iterator ptr = token.begin(); + std::string elt1; + get_elt(ptr, token.end(), elt1); + + if (*ptr != '(') { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " << + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + + int paren_count = 1; + std::string paren1 = "("; + while ( ptr != token.end() ) { + ++ptr; + if (*ptr == '/' || ptr == token.end()) { + std::ostringstream err_msg; + err_msg << "End of line or ""/"" encountered before end of parentheses, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren1.insert(paren1.end(), *ptr); // element.push_back(c); + if (*ptr == '(') ++paren_count; + if (*ptr == ')') --paren_count; + if (paren_count == 0) break; + } + + ++ptr; + if (ptr == token.end() || *ptr != '/') { + std::ostringstream err_msg; + err_msg << " ""/"" must follow parentheses " << + "ending first half of redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + ++ptr; + std::string elt2; + get_elt(ptr, token.end(), elt2); + if (elt1.compare(elt2) != 0) { + std::ostringstream err_msg; + err_msg << "Redox couple must be two redox states " << + "of the same element, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + if (*ptr != '(') { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + std::string paren2 = "("; + paren_count = 1; + + while ( ptr != token.end() ) { + ++ptr; + if (*ptr == '/' || ptr == token.end()) { + std::ostringstream err_msg; + err_msg << "End of line or ""/"" encountered before end of parentheses, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren2.insert(paren2.end(), *ptr); // element.push_back(c); + if (*ptr == '(') ++paren_count; + if (*ptr == ')') --paren_count; + if (paren_count == 0) break; + } + if (paren1.compare(paren2) < 0) { + token = elt1 + paren1 + std::string("/") + elt2 + paren2; + } else if (paren1.compare(paren2) > 0) { + token = elt2 + paren2 + std::string("/") + elt1 + paren1; + } else { + std::ostringstream err_msg; + err_msg << "Both parts of redox couple are the same, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + return PARSER_OK; +} + +CParser::STATUS_TYPE CParser::addPair(std::map &totals, std::istream::pos_type& pos) +{ + std::string token; + char * ctoken; + double d; + + CParser::TOKEN_TYPE j; + + m_line_iss.seekg(pos); + + j = copy_token(token, pos); + + if (j == TT_EMPTY) return PARSER_OK; + + if( !(m_line_iss >> d)) { + return PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + totals[ctoken] = d; + return PARSER_OK; +} + +CParser::STATUS_TYPE CParser::addPair(std::map &totals, std::istream::pos_type& pos) +{ + std::string token; + char * ctoken; + double d; + CParser::TOKEN_TYPE j; + + m_line_iss.seekg(pos); + + j = copy_token(token, pos); + + if (j == TT_EMPTY) return PARSER_OK; + + if( !(m_line_iss >> d)) { + return PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + totals[ctoken] = d; + return PARSER_OK; +} +int CParser::getOptionFromLastLine(const std::vector& opt_list, std::string::iterator& next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; + + // char option[MAX_LENGTH]; + std::string option; + + // + // Read line + // + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); + + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; + + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} +int CParser::getOptionFromLastLine(const std::vector& opt_list, std::istream::pos_type& next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + //LINE_TYPE lt = check_line("get_option", false, true, true, false); + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + error_msg("Unknown option.", OT_CONTINUE); + error_msg(m_line_save.c_str(), OT_CONTINUE); + incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} diff --git a/Parser.h b/Parser.h new file mode 100644 index 00000000..2ed217a5 --- /dev/null +++ b/Parser.h @@ -0,0 +1,205 @@ +#if !defined(PARSER_H_INCLUDED) +#define PARSER_H_INCLUDED + +#include // std::string +#include // std::map +#include // std::vector +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include "char_star.h" + +class CParser +{ +public: + CParser(std::istream& input); + CParser(std::istream& input, std::ostream& output); + CParser(std::istream& input, std::ostream& output, std::ostream& error); + + virtual ~CParser(); + + enum LINE_TYPE { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; + + enum TOKEN_TYPE { + TT_EMPTY = 2, + TT_UPPER = 4, + TT_LOWER = 5, + TT_DIGIT = 6, + TT_UNKNOWN = 7 + }; + + enum FIND_TYPE { + FT_OK = 0, + FT_ERROR = 1 + }; + + enum KEY_TYPE { + KT_NONE = -1, + KT_END = 0, + KT_EOF = 1, + KT_SOLUTION = 4, + KT_SOLUTION_RAW = 5 + }; + + enum OPT_TYPE { + OPT_DEFAULT = -4, + OPT_ERROR = -3, + OPT_KEYWORD = -2, + OPT_EOF = -1 + }; + + enum ONERROR_TYPE { + OT_CONTINUE = 0, + OT_STOP = 1, + }; + + enum STATUS_TYPE { + PARSER_ERROR = 0, + PARSER_OK = 1 + }; + + /** + Function gets a new line and checks for empty, eof, and keywords. + + Arguments: + string Input, character string used in printing error message + allow_empty Input, True or false, if a blank line is accepable + if false, another line is read + allow_eof Input, True or false, if EOF is acceptable + allow_keyword Input, True or false, if a keyword is acceptable + + Returns: + LT_EMPTY if empty line read and allow_empty == true + LT_KEYWORD if line begins with keyword + LT_EOF if eof and allow_eof == true + LT_OK otherwise + LT_OPTION if line begins with -[alpha] + + Terminates if EOF and allow_eof == false. + */ + LINE_TYPE check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print); + + /** + Read a line from input file put in "line". + Copy of input line is stored in "line_save". + Characters after # are discarded in line but retained in "line_save" + + Arguments: + None + Returns: + LT_EMPTY, + LT_EOF, + LT_KEYWORD, + LT_OK, + LT_OPTION + */ + LINE_TYPE get_line(); + + // bool check_key(const std::string::iterator ptr); + bool check_key(std::string::iterator begin, std::string::iterator end); + + STATUS_TYPE check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, + const std::string& default_units, bool print); + + + KEY_TYPE next_keyword()const { return m_next_keyword; } + int get_option(const std::vector& opt_list, std::string::iterator& next_char); + int get_option(const std::vector& opt_list, std::istream::pos_type& next_pos); + int getOptionFromLastLine(const std::vector& opt_list, std::string::iterator& next_char); + int getOptionFromLastLine(const std::vector& opt_list, std::istream::pos_type& next_pos); + + + std::string& line() {return m_line;} + std::istringstream& get_iss() {return m_line_iss;} + int incr_input_error() {return ++m_input_error;} + std::ostream& get_output() {return m_output_stream;} + int get_input_error() {return m_input_error;} + + + /** + Copies from begin to token until first space is encountered. + + Arguments: + token output, the token + begin input, begin iterator + end input, end iterator + + Returns: + TT_EMPTY + TT_UPPER + TT_LOWER + TT_DIGIT + TT_UNKNOWN + */ + static TOKEN_TYPE copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end); + static TOKEN_TYPE token_type(const std::string& token); + static TOKEN_TYPE copy_token(std::string& token, std::istream& is); + TOKEN_TYPE copy_token(std::string& token, std::istream::pos_type& pos); + CParser::TOKEN_TYPE peek_token(); + + /** + Function reads an element name out of the equation string. + An element name is composed of a capital letter followed by any number + of lower case characters. + + Arguments: + begin input, points to position in the equation to begin + output, points to next character of equation after + element name. + end input, points to last position in the equation + element input pointer to place to return element character string + */ + STATUS_TYPE get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element); + + + /** + Compares a string value to match beginning letters of a list of options + + Arguments: + item entry: pointer to string to compare + n exit: item in list that was matched + list entry: pointer to list of character values, assumed to + be lower case + count_list entry: number of character values in list + + Returns: + OK item matched + ERROR item not matched + n -1 item not matched + i position of match in list + */ + static FIND_TYPE find_option(const std::string& item, int *n, const std::vector& list, bool exact); + + + int error_msg(const std::ostringstream& err_str, ONERROR_TYPE stop) {return error_msg(err_str.str().c_str(), stop);} + int error_msg(const char *err_str, ONERROR_TYPE stop); + int warning_msg(const char *err_str); + + + STATUS_TYPE parse_couple(std::string& token); + + STATUS_TYPE addPair(std::map &totals, std::istream::pos_type& pos); + STATUS_TYPE addPair(std::map &totals, std::istream::pos_type& pos); + +protected: + LINE_TYPE get_logical_line(); + +private: + std::istream& m_input_stream; + std::ostream& m_output_stream; + std::ostream& m_error_stream; + int m_input_error; + KEY_TYPE m_next_keyword; + std::string m_line; + std::string m_line_save; + std::istringstream m_line_iss; + LINE_TYPE m_line_type; +}; + +#endif // PARSER_H_INCLUDED diff --git a/Pe_Data.cxx b/Pe_Data.cxx new file mode 100644 index 00000000..19070934 --- /dev/null +++ b/Pe_Data.cxx @@ -0,0 +1,45 @@ +#include "Pe_Data.h" +#include "Utilities.h" +#include // std::ostream + +cxxPe_Data::cxxPe_Data() +: name("") +{ +} + +cxxPe_Data::cxxPe_Data(const std::string& name) +: name(name) +{ +} + +cxxPe_Data::~cxxPe_Data() +{ +} + +int cxxPe_Data::store(std::vector& vec_pe_data, const std::string& token) +{ + unsigned int i = 0; + unsigned int size = vec_pe_data.size(); + for (; i < size; ++i) { + if (vec_pe_data[i].name.compare(token) == 0) + return i; + } + vec_pe_data.push_back(token); + return i; +} + +std::vector cxxPe_Data::alloc() +{ + std::vector vec; + vec.push_back(cxxPe_Data("pe")); + // TODO: see pe_data_alloc + return vec; +} + +void cxxPe_Data::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "" << this->name << "\n"; +} + diff --git a/Pe_Data.h b/Pe_Data.h new file mode 100644 index 00000000..b26ff260 --- /dev/null +++ b/Pe_Data.h @@ -0,0 +1,28 @@ +#if !defined(PE_DATA_H_INCLUDED) +#define PE_DATA_H_INCLUDED + +#include +#include + +class cxxPe_Data +{ +public: + cxxPe_Data(); + cxxPe_Data(struct pe *pe_ptr); + cxxPe_Data(const std::string& name); + + ~cxxPe_Data(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + std::string get_name()const {return this->name;}; + void set_name(std::string name) {this->name = name;}; + + static int store(std::vector& vec, const std::string& token); + static std::vector cxxPe_Data::alloc(); + +private: + std::string name; +}; + +#endif // PE_DATA_H_INCLUDED diff --git a/Reaction.cxx b/Reaction.cxx new file mode 100644 index 00000000..6a0af474 --- /dev/null +++ b/Reaction.cxx @@ -0,0 +1,323 @@ +// Reaction.cxx: implementation of the cxxReaction class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Reaction.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxReaction::cxxReaction() + // + // default constructor for cxxReaction + // +: cxxNumKeyword() +{ + units = string_hsave("Mol"); + countSteps = 0; + equalIncrements = false; + reactantList.type = cxxNameDouble::ND_NAME_COEF; + elementList.type = cxxNameDouble::ND_ELT_MOLES; +} + +cxxReaction::cxxReaction(struct irrev *irrev_ptr) + // + // constructor for cxxReaction from struct irrev + // +: +cxxNumKeyword(), +reactantList(irrev_ptr->list, irrev_ptr->count_list, cxxNameDouble::ND_NAME_COEF), +elementList(irrev_ptr->elts) +{ + int i; + + this->set_description(irrev_ptr->description); + this->n_user = irrev_ptr->n_user; + this->n_user_end = irrev_ptr->n_user_end; + this->units = irrev_ptr->units; + // steps + if (irrev_ptr->count_steps < 0) { + for (i = 0; i < 1; i++) { + this->steps.push_back(irrev_ptr->steps[i]); + } + this->countSteps = -irrev_ptr->count_steps; + this->equalIncrements = true; + } else { + for (i = 0; i < irrev_ptr->count_steps; i++) { + this->steps.push_back(irrev_ptr->steps[i]); + } + this->countSteps = irrev_ptr->count_steps; + this->equalIncrements = false; + } +} + +cxxReaction::~cxxReaction() +{ +} + + +struct irrev *cxxReaction::cxxReaction2irrev() + // + // Builds a irrev structure from instance of cxxReaction + // +{ + struct irrev *irrev_ptr; + irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof (struct irrev)); + if (irrev_ptr == NULL) malloc_error(); + + irrev_ptr->description = this->get_description(); + irrev_ptr->n_user = this->n_user; + irrev_ptr->n_user_end = this->n_user_end; + + irrev_ptr->list = this->reactantList.name_coef(); + irrev_ptr->count_list = this->reactantList.size(); + if (this->elementList.size() > 0) { + irrev_ptr->elts = this->elementList.elt_list(); + } else { + // NULL value causes reaction stoichiometry to be calculated + irrev_ptr->elts = NULL; + } + // steps + irrev_ptr->steps = NULL; + if (this->steps.size() > 0) { + irrev_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + if (irrev_ptr->steps == NULL) malloc_error(); + std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); + } + if (this->equalIncrements) { + irrev_ptr->count_steps = -this->countSteps; + } else { + irrev_ptr->count_steps = this->steps.size(); + } + irrev_ptr->units = this->units; + return(irrev_ptr); +} + +#ifdef SKIP +void cxxReaction::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Reaction element and attributes + s_oss << indent0; + s_oss << "pitzer_irrev_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = irrevComps.begin(); it != irrevComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxReaction::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Reaction element and attributes + s_oss << indent0; + s_oss << "REACTION_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-units " << this->units << std::endl; + + s_oss << indent1; + s_oss << "-reactant_list " << std::endl; + this->reactantList.dump_raw(s_oss, indent + 2); + + s_oss << indent1; + s_oss << "-element_list " << std::endl; + this->elementList.dump_raw(s_oss, indent + 2); + + s_oss << indent1; + s_oss << "-steps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { + if (i++ == 5) { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } + + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; + + s_oss << indent1; + s_oss << "-count_steps " << this->countSteps << std::endl; + + +} + +void cxxReaction::read_raw(CParser& parser) +{ + + int j; + double d; + CParser::TOKEN_TYPE k; + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("units"); //0 + vopts.push_back("reactant_list"); //1 + vopts.push_back("element_list"); //2 + vopts.push_back("steps"); //3 + vopts.push_back("equal_increments"); //4 + vopts.push_back("count_steps"); //5 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read irrev number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool units_defined(false); + bool equalIncrements_defined(false); + bool countSteps_defined(false); + + 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 IRREV_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // units + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) break; + this->units = string_hsave(token.c_str()); + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + units_defined = true; + break; + + case 1: // reactant_list + if ( this->reactantList.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected reactant formula and coefficient.", CParser::OT_CONTINUE); + } + opt_save = 1; + useLastLine = false; + break; + + case 2: // element_list + if ( this->elementList.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element formula and coefficient.", CParser::OT_CONTINUE); + } + opt_save = 2; + useLastLine = false; + break; + + case 3: // steps + while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { + std::istringstream iss(token); + if (!(iss >> d)) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE); + } else { + this->steps.push_back(d); + } + } + opt_save = 3; + useLastLine = false; + break; + + case 4: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; + + case 5: // countSteps + if (!(parser.get_iss() >> this->countSteps)) + { + this->countSteps = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for countSteps.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + countSteps_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (units_defined == false) { + parser.incr_input_error(); + parser.error_msg("Units not defined for REACTION_RAW input.", CParser::OT_CONTINUE); + } + if (equalIncrements_defined == false) { + parser.incr_input_error(); + parser.error_msg("Equal_increments not defined for REACTION_RAW input.", CParser::OT_CONTINUE); + } + if (countSteps_defined == false) { + parser.incr_input_error(); + parser.error_msg("Count_steps not defined for REACTION_RAW input.", CParser::OT_CONTINUE); + } +} diff --git a/Reaction.h b/Reaction.h new file mode 100644 index 00000000..8c5e6dd0 --- /dev/null +++ b/Reaction.h @@ -0,0 +1,45 @@ +#if !defined(REACTION_H_INCLUDED) +#define REACTION_H_INCLUDED + +#include "NumKeyword.h" +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxReaction : public cxxNumKeyword +{ + +public: + cxxReaction(); + cxxReaction(struct irrev *); + ~cxxReaction(); + + struct irrev *cxxReaction2irrev(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + cxxNameDouble reactantList; + cxxNameDouble elementList; + std::vector steps; + int countSteps; + bool equalIncrements; + char *units; + +public: + //static std::map& map; + +}; + +#endif // !defined(REACTION_H_INCLUDED) diff --git a/ReadClass.cpp b/ReadClass.cpp new file mode 100644 index 00000000..188f9881 --- /dev/null +++ b/ReadClass.cpp @@ -0,0 +1,701 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "Parser.h" +#include "Solution.h" +#include "Exchange.h" +#include "Surface.h" +#include "PPassemblage.h" +#include "KineticsCxx.h" +#include "SSassemblage.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "Mix.h" +#include "Temperature.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, + int print); + +/* ---------------------------------------------------------------------- */ +int read_solution_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SOLUTION_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + + cxxSolution sol; + sol.read_raw(parser); + struct solution *soln_ptr = sol.cxxSolution2solution(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) { + solution_free(solution[n]); + } else { + n=count_solution++; + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); + } + } + solution[n] = soln_ptr; + + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_exchange_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads EXCHANGE_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxExchange ex; + ex.read_raw(parser); + struct exchange *exchange_ptr = ex.cxxExchange2exchange(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) { + exchange_free(&exchange[n]); + } else { + n=count_exchange++; + if (count_exchange >= max_exchange) { + space ((void **) ((void *) &(exchange)), count_exchange, &max_exchange, sizeof (struct exchange *) ); + } + } + exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); + exchange_free(exchange_ptr); + free_check_null(exchange_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_surface_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SURFACE_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("surface_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxSurface ex; + ex.read_raw(parser); + struct surface *surface_ptr = ex.cxxSurface2surface(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (surface_bsearch(surface_ptr->n_user, &n) != NULL) { + surface_free(&surface[n]); + } else { + n=count_surface++; + if (count_surface >= max_surface) { + space ((void **) ((void *) &(surface)), count_surface, &max_surface, sizeof (struct surface *) ); + } + } + surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); + surface_free(surface_ptr); + free_check_null(surface_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_equilibrium_phases_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads EQUILIBRIUM_PHASES_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxPPassemblage ex; + ex.read_raw(parser); + struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) { + pp_assemblage_free(&pp_assemblage[n]); + } else { + n=count_pp_assemblage++; + if (count_pp_assemblage >= max_pp_assemblage) { + space ((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, &max_pp_assemblage, sizeof (struct pp_assemblage *) ); + } + } + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); + pp_assemblage_free(pp_assemblage_ptr); + free_check_null(pp_assemblage_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_kinetics_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads KINETICS_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxKinetics ex; + ex.read_raw(parser); + struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) { + kinetics_free(&kinetics[n]); + } else { + n=count_kinetics++; + if (count_kinetics >= max_kinetics) { + space ((void **) ((void *) &(kinetics)), count_kinetics, &max_kinetics, sizeof (struct kinetics *) ); + } + } + kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); + kinetics_free(kinetics_ptr); + free_check_null(kinetics_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_solid_solutions_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SOLID_SOLUTION_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxSSassemblage ex; + ex.read_raw(parser); + struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) { + s_s_assemblage_free(&s_s_assemblage[n]); + } else { + n=count_s_s_assemblage++; + if (count_s_s_assemblage >= max_s_s_assemblage) { + space ((void **) ((void *) &(s_s_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, sizeof (struct s_s_assemblage *) ); + } + } + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); + s_s_assemblage_free(s_s_assemblage_ptr); + free_check_null(s_s_assemblage_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_gas_phase_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads GAS_PHASE_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxGasPhase ex; + ex.read_raw(parser); + struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) { + gas_phase_free(&gas_phase[n]); + } else { + n=count_gas_phase++; + if (count_gas_phase >= max_gas_phase) { + space ((void **) ((void *) &(gas_phase)), count_gas_phase, &max_gas_phase, sizeof (struct gas_phase *) ); + } + } + gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); + gas_phase_free(gas_phase_ptr); + free_check_null(gas_phase_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_reaction_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads REACTION_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxReaction ex; + ex.read_raw(parser); + struct irrev *irrev_ptr = ex.cxxReaction2irrev(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) { + irrev_free(&irrev[n]); + } else { + n=count_irrev++; + irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev)); + if (irrev == NULL) malloc_error(); + } + irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); + irrev_free(irrev_ptr); + free_check_null(irrev_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_mix_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads MIX (_RAW) data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxMix ex; + ex.read_raw(parser); + struct mix *mix_ptr = ex.cxxMix2mix(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (mix_bsearch(mix_ptr->n_user, &n) != NULL) { + mix_free(&mix[n]); + } else { + n=count_mix++; + mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix)); + if (mix == NULL) malloc_error(); + } + mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); + mix_free(mix_ptr); + free_check_null(mix_ptr); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_temperature_raw (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads TEMPERATURE (_RAW) data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; + keywordLines.append(line); + keywordLines.append("\n"); + } + + std::istringstream iss_in(keywordLines); + std::ostringstream oss_out; + std::ostringstream oss_err; + + CParser parser(iss_in, oss_out, oss_err); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxTemperature ex; + ex.read_raw(parser); + struct temperature *temperature_ptr = ex.cxxTemperature2temperature(); + int n; + + /* + * This is not quite right, may not produce sort order + */ + + if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) { + temperature_free(&temperature[n]); + } else { + n=count_temperature++; + temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature)); + if (temperature == NULL) malloc_error(); + } + temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); + temperature_free(temperature_ptr); + free_check_null(temperature_ptr); + return(return_value); +} diff --git a/SAXPhreeqc.cpp b/SAXPhreeqc.cpp new file mode 100644 index 00000000..d3010c9d --- /dev/null +++ b/SAXPhreeqc.cpp @@ -0,0 +1,888 @@ +// SAXPhreeqc.cpp +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include // DBL_DIG +#include // sprintf +#include // iswspace + +#include // assert +//#include // std::ostrstream +#include +#include // std::cerr +#ifdef SKIP +#endif +#ifdef _DEBUG +#define _CRTDBG_MAP_ALLOC +#include +#endif + + +#include +#include +#include +#include +#include +#include + +//#include // SAXParser +#include // AttributeList +#include // Unicode definitions +#include // MemBufInputSource +#include +#include +#include // XMLPlatformUtils::getCurrentMillis +#include + +#include +#include + +#include "SAXPhreeqc.h" // SAX_ functions +#include "SaxPhreeqcHandlers.h" // SaxPhreeqcHandlers + +//XERCES_CPP_NAMESPACE_USE +#define xns XERCES_CPP_NAMESPACE + +///static char buffer[300000]; +///static std::ostrstream s_oss(buffer, 300000); // must never go out of scope +static std::ostringstream s_oss; // must never go out of scope +static bool s_bSysIsOpen = false; // must never go out of scope + +#include +// extern routines + #include "phqalloc.h" + #include "global.h" +#include "phrqproto.h" +#include "output.h" +#ifdef SKIP + int conc_init(struct conc *conc_ptr); + void *free_check_null(void *ptr); + int pe_data_store (struct pe_data **pe, const char *token); + struct phase *phase_bsearch (char *ptr, int *j, int print); + struct solution *solution_alloc(void); + struct solution *solution_bsearch(int k, int *n, int print); + int solution_free (struct solution *solution_ptr); + void space (void **ptr, int i, int *max, int struct_size); + char * string_duplicate (const char *token); + char *string_hsave (const char *str); + int error_msg (const char *err_str, const int stop); + struct master *master_bsearch (const char *ptr); + void malloc_error(void); +#endif +//} + + +class Initializer +{ +public: + Initializer(){ +#if defined(_DEBUG) + int tmpDbgFlag; + + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + //tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); +#endif + + xns::XMLPlatformUtils::Initialize(); + } +}; + +static Initializer sInit; // initialize xerces once +static SaxPhreeqcHandlers s_handler; // one and only instance + +void SAX_StartSystem() +{ + + assert(!s_bSysIsOpen); // system already open and has not been closed + + // init stream + //s_oss.freeze(false); + s_oss.seekp(0); + + // write stream + // s_oss << ""; + s_oss << ""; + s_oss << ""; + s_oss << " "; + s_bSysIsOpen = true; + +} + +char * stringify_null(char * string) { + if (string == NULL) return(string_hsave("")); + return(string); +} +int SAX_AddSolution(struct solution* solution_ptr) +{ + //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; + int i, newd; + assert(s_bSysIsOpen); // must call SAX_StartSystem first + s_oss.precision(DBL_DIG - 1); + // Solution element and attributes + newd = solution_ptr->new_def; + s_oss << " new_def << "\"" << std::endl; + s_oss << " soln_n_user=\"" << solution_ptr->n_user << "\" " << std::endl; + s_oss << " soln_n_user_end=\"" << solution_ptr->n_user_end << "\"" << std::endl; + s_oss << " soln_description=\"" << solution_ptr->description << "\"" << std::endl; + s_oss << " soln_tc=\"" << solution_ptr->tc << "\"" << std::endl; + s_oss << " soln_ph=\"" << solution_ptr->ph << "\"" << std::endl; + s_oss << " soln_solution_pe=\"" << solution_ptr->solution_pe << "\"" << std::endl; + s_oss << " soln_mu=\"" << solution_ptr->mu << "\"" << std::endl; + s_oss << " soln_ah2o=\"" << solution_ptr->ah2o << "\"" << std::endl; + s_oss << " soln_density=\"" << solution_ptr->density << "\"" << std::endl; + s_oss << " soln_total_h=\"" << solution_ptr->total_h << "\"" << std::endl; + s_oss << " soln_total_o=\"" << solution_ptr->total_o << "\"" << std::endl; + s_oss << " soln_cb=\"" << solution_ptr->cb << "\"" << std::endl; + s_oss << " soln_mass_water=\"" << solution_ptr->mass_water << "\"" << std::endl; + s_oss << " soln_total_alkalinity=\"" << solution_ptr->total_alkalinity << "\"" << std::endl; + //s_oss << " soln_total_co2=\"" << solution_ptr->total_co2 << "\"" << std::endl; + s_oss << " soln_units=\"" << solution_ptr->units << "\"" << std::endl; + s_oss << " soln_default_pe=\"" << solution_ptr->default_pe << "\"" << std::endl; + s_oss << " soln_count_master_activity=\"" << solution_ptr->count_master_activity << "\"" << std::endl; + s_oss << " soln_count_isotopes=\"" << solution_ptr->count_isotopes << "\"" << std::endl; + s_oss << " soln_count_species_gamma=\"" << solution_ptr->count_species_gamma << "\">" << std::endl; + // end of solution attributes + // pe structures + for (i=0; solution_ptr->pe[i].name != NULL; i++) { + s_oss << " pe[i].name << "\"/>"<< std::endl; + } + // soln_total conc structures + for (i=0; solution_ptr->totals[i].description != NULL; i++) { + struct conc *c = &(solution_ptr->totals[i]); + s_oss << " description << "\"" << std::endl; + s_oss << " conc_moles=\"" << c->moles << "\"" << std::endl; + if (newd == TRUE) { + s_oss << " conc_input_conc=\"" << c->input_conc << "\"" << std::endl; + if (c->units != NULL) s_oss << " conc_units=\"" << c->units << "\"" << std::endl; + if (c->equation_name != NULL) { + s_oss << " conc_equation_name=\"" << stringify_null(c->equation_name) << "\"" << std::endl; + s_oss << " conc_phase_si=\"" << c->phase_si << "\"" << std::endl; + } + if (c->as != NULL) s_oss << " conc_as=\"" << stringify_null(c->as) << "\"" << std::endl; + s_oss << " conc_gfw=\"" << c->gfw << "\"" << std::endl; + } + s_oss << " conc_n_pe=\"" << c->n_pe << "\"" << std::endl; + s_oss << " />" << std::endl; + } + // master_activity, master_activity structure + + for (i=0; i < solution_ptr->count_master_activity; i++) { + s_oss << " master_activity[i].description) << "\" m_a_la=\"" << solution_ptr->master_activity[i].la << "\"/>" << std::endl; + } + /* + if (solution_ptr->count_master_activity > 0) { + s_oss << " count_master_activity; i++) { + if (solution_ptr->master_activity[i].description != NULL) { + s_oss << stringify_null(solution_ptr->master_activity[i].description) << " "; + s_oss << solution_ptr->master_activity[i].la << std::endl; + } else { + s_oss << "null 0.0" << std::endl; + } + } + s_oss << "\"/>" << std::endl; + } + */ + // species_gamma, mater_activity structure + for (i=0; i < solution_ptr->count_species_gamma; i++) { + s_oss << " species_gamma[i].description) << "\" m_a_la=\"" << solution_ptr->species_gamma[i].la << "\"/>" << std::endl; + } + // isotopes, isotope structure + for (i=0; solution_ptr->count_isotopes; i++) { + s_oss << " isotopes[i].isotope_number << "\"" << std::endl; + s_oss << " iso_elt_name=\"" << solution_ptr->isotopes[i].elt_name << "\"" << std::endl; + s_oss << " iso_isotope_name=\"" << solution_ptr->isotopes[i].isotope_name << "\"" << std::endl; + s_oss << " iso_total=\"" << solution_ptr->isotopes[i].total << "\"" << std::endl; + s_oss << " iso_ratio=\"" << solution_ptr->isotopes[i].ratio << "\"" << std::endl; + s_oss << " iso_ratio_uncertainty=\"" << solution_ptr->isotopes[i].ratio_uncertainty << "\"" << std::endl; + s_oss << " iso_coef=\"" << solution_ptr->isotopes[i].coef << "\"" << std::endl; + } + // End of solution + s_oss << " " << std::endl; + + return(OK); +} + +void SAX_EndSystem() +{ + assert(s_bSysIsOpen); // must call SAX_StartSystem first + + s_oss << " " << std::endl; + s_oss << "" << std::endl; + s_oss << '\0'; + + s_bSysIsOpen = false; + //delete[] s_handler; + return; +} + +int SAX_GetXMLLength() +{ + assert(!s_bSysIsOpen); // must call SAX_EndSystem first + //return s_oss.pcount(); + return s_oss.str().size(); +} + +const char* SAX_GetXMLStr() +{ + assert(!s_bSysIsOpen); // must call SAX_EndSystem first + return s_oss.str().c_str(); +} + +void SAX_cleanup() +{ + //delete s_handler; + //s_oss.freeze(false); +} + +// utility routines + +int XMLCh2Int(const XMLCh* const attValue) { + char *string = xns::XMLString::transcode(attValue); + int i = strtol(string, NULL, 10); + xns::XMLString::release(&string); + return i; + //return (xns::XMLString::parseInt(attValue)); +} +double XMLCh2Double(const XMLCh* const attValue) { + char *string = xns::XMLString::transcode(attValue); + double d = strtod(string, NULL); + xns::XMLString::release(&string); + return d; +} +char * XMLCh2String(const XMLCh* const attValue) { + char *string = xns::XMLString::transcode(attValue); + char *s = string_duplicate(string); + xns::XMLString::release(&string); + return s; +} +char * XMLCh_hsave(const XMLCh* const attValue, bool allow_null) { + char *string = xns::XMLString::transcode(attValue); + char *s = string_hsave(string); + if (allow_null && strlen(s) == 0) s = NULL; + xns::XMLString::release(&string); + return s; +} + + +int SAX_UnpackSolutions(void* pvBuffer, int buf_size) +{ + // Create MemBufferInputSource from the buffer containing the XML + // statements. + xns::MemBufInputSource memBufIS((const XMLByte*)pvBuffer, buf_size, "solution_id", false); + fprintf(stderr,"%s", (char *) pvBuffer); + return 0; + // + // Create a SAX2 parser object. + // + xns::SAX2XMLReader * parser = xns::XMLReaderFactory::createXMLReader(); + parser->setFeature(xns::XMLUni::fgXercesSchemaFullChecking, false); + parser->setFeature(xns::XMLUni::fgSAX2CoreNameSpaces, false); + parser->setFeature(xns::XMLUni::fgXercesSchema, false); + parser->setFeature(xns::XMLUni::fgXercesIdentityConstraintChecking, false); + // + // Create the handler object and install it as the document and error + // handler for the parser. Then parse the MemBufferInputSource and + // catch any exceptions that propogate out + // + try + { + unsigned long duration = 0; + parser->setContentHandler(&s_handler); + parser->setErrorHandler(&s_handler); + int t = 0; + for (; t < 1000; ++t) + { + const unsigned long startMillis = xns::XMLPlatformUtils::getCurrentMillis(); + parser->parse(memBufIS); + const unsigned long endMillis = xns::XMLPlatformUtils::getCurrentMillis(); + duration += endMillis - startMillis; + } + std::cerr << "\nSaxParse time = " << duration << " millis\n"; + } + catch (const xns::SAXException& toCatch) + { + char* psz = xns::XMLString::transcode(toCatch.getMessage()); + input_error++; + sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&psz); + return ERROR; + } + catch (const xns::XMLException& toCatch) + { + char* psz = xns::XMLString::transcode(toCatch.getMessage()); + input_error++; + sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&psz); + return ERROR; + } + catch (...) + { + input_error++; + sprintf(error_string,"SAX_UnpackSolutions: %s\n", "Unknown error occured."); + error_msg(error_string, CONTINUE); + return ERROR; + } + + return(OK); +} + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +// element names + +SaxPhreeqcHandlers::SaxPhreeqcHandlers() + : eltType(typeNULL), attType(attNULL), totals(), acts(), solution_ptr(NULL) +{ + int i; + + int count_elementInfo, count_attributeInfo; + struct mapElementInfo {char *key; enum elementType type;}; + struct mapAttributeInfo {enum attributeType type; char *key;}; + struct mapElementInfo elementInfo[] = { + {"phast_state", typePHAST_STATE}, + {"system", typeSYSTEM}, + {"solution", typeSOLUTION}, + {"soln_pe", typeSOLN_PE}, + {"soln_total", typeSOLN_TOTAL}, + {"soln_m_a", typeSOLN_MASTER_ACTIVITY}, + {"soln_isotope", typeSOLN_ISOTOPE}, + {"soln_s_g", typeSOLN_SPECIES_GAMMA} + }; + count_elementInfo = sizeof(elementInfo)/sizeof(struct mapElementInfo); + struct mapAttributeInfo attributeInfo[] = { + // Solution structure + {attSOLN_new_def, "soln_new_def"}, + {attSOLN_n_user, "soln_n_user"}, + {attSOLN_n_user_end, "soln_n_user_end"}, + {attSOLN_description, "soln_description"}, + {attSOLN_tc, "soln_tc"}, + {attSOLN_ph, "soln_ph"}, + {attSOLN_solution_pe, "soln_solution_pe"}, + {attSOLN_mu, "soln_mu"}, + {attSOLN_ah2o, "soln_ah2o"}, + {attSOLN_density, "soln_density"}, + {attSOLN_total_h, "soln_total_h"}, + {attSOLN_total_o, "soln_total_o"}, + {attSOLN_cb, "soln_cb"}, + {attSOLN_mass_water, "soln_mass_water"}, + {attSOLN_total_alkalinity, "soln_total_alkalinity"}, + {attSOLN_total_co2, "soln_total_co2"}, + {attSOLN_units, "soln_units"}, + {attSOLN_default_pe, "soln_default_pe"}, + {attSOLN_count_master_activity, "soln_count_master_activity"}, + {attSOLN_count_isotopes, "soln_count_isotopes"}, + {attSOLN_count_species_gamma, "soln_count_species_gamma"}, + {attSOLN_PE_name, "soln_pe_name"}, + // master_activity structure + {attM_A_description, "m_a_desc"}, + {attM_A_la, "m_a_la"}, + {attM_A_list, "m_a_list"}, + // isotope structure + {attISO_isotope_number, "iso_isotope_number"}, + {attISO_elt_name, "iso_elt_name"}, + {attISO_isotope_name, "iso_isotope_name"}, + {attISO_total, "iso_total"}, + {attISO_ratio, "iso_ratio"}, + {attISO_ratio_uncertainty, "iso_ratio_uncertainty"}, + {attISO_x_ratio_uncertainty, "iso_x_ratio_uncertainty"}, + {attISO_coef, "iso_coef"}, + // conc structure + {attCONC_description, "conc_desc"}, + {attCONC_moles, "conc_moles"}, + {attCONC_input_conc, "conc_input_conc"}, + {attCONC_units, "conc_units"}, + {attCONC_equation_name, "conc_equation_name"}, + {attCONC_phase_si, "conc_phase_si"}, + {attCONC_n_pe, "conc_n_pe"}, + {attCONC_as, "conc_as"}, + {attCONC_gfw, "conc_gfw"}, + + }; + + count_attributeInfo = sizeof(attributeInfo)/sizeof(struct mapAttributeInfo); + for (i = 0; i < count_elementInfo; i++) { + // memory freed in destructor + this->mapXMLCh2Type[xns::XMLString::transcode(elementInfo[i].key)] = elementInfo[i].type; + } + for (i = 0; i < count_attributeInfo; i++) { + // memory freed in destructor + this->mapXMLCh2AttType[xns::XMLString::transcode(attributeInfo[i].key)] = attributeInfo[i].type; + } + + this->totals.reserve(50); + this->acts.reserve(50); +} + +SaxPhreeqcHandlers::~SaxPhreeqcHandlers() +{ + std::map::iterator it = this->mapXMLCh2Type.begin(); + for (; it != this->mapXMLCh2Type.end(); ++it) + { + XMLCh* p = (XMLCh*)it->first; + xns::XMLString::release(&p); + } + this->mapXMLCh2Type.clear(); + std::map::iterator ita = this->mapXMLCh2AttType.begin(); + for (; ita != this->mapXMLCh2AttType.end(); ++ita) + { + XMLCh* p = (XMLCh*)ita->first; + xns::XMLString::release(&p); + } + this->mapXMLCh2AttType.clear(); + +} + +// ----------------------------------------------------------------------- +// Implementations of the SAX DocumentHandler interface +// ----------------------------------------------------------------------- + +void SaxPhreeqcHandlers::endDocument() +{ +} + +void SaxPhreeqcHandlers::endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname) +{ + switch (this->mapXMLCh2Type[name]) + { + case typeSOLUTION: + // solution is finished now copy into solutions array + { + int n; + // copy vector of conc's to solution + this->solution_ptr->totals = (struct conc*) PHRQ_realloc(this->solution_ptr->totals, (size_t) (this->totals.size() + 1) * sizeof(struct conc)); + std::copy(this->totals.begin(), this->totals.end(), this->solution_ptr->totals); + this->solution_ptr->totals[this->totals.size()].description=NULL; + this->totals.clear(); + assert(this->totals.size() == 0); + + // copy vector of master_activities's to solution + this->solution_ptr->master_activity = (struct master_activity *) free_check_null(this->solution_ptr->master_activity); + if (this->acts.size() > 0) { + this->solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(this->solution_ptr->master_activity, (size_t) (this->acts.size()) * sizeof(struct master_activity)); + std::copy(this->acts.begin(), this->acts.end(), this->solution_ptr->master_activity); + } + this->solution_ptr->count_master_activity = this->acts.size(); + this->acts.clear(); + assert(this->acts.size() == 0); + + // copy vector of s_gamma's to solution + this->solution_ptr->species_gamma = (struct master_activity *) free_check_null(this->solution_ptr->species_gamma); + if (this->s_gammas.size() > 0) { + this->solution_ptr->species_gamma = (struct master_activity *) PHRQ_realloc(this->solution_ptr->species_gamma, (size_t) (this->s_gammas.size()) * sizeof(struct master_activity)); + std::copy(this->s_gammas.begin(), this->s_gammas.end(), this->solution_ptr->species_gamma); + } + this->solution_ptr->count_species_gamma = this->s_gammas.size(); + this->s_gammas.clear(); + assert(this->s_gammas.size() == 0); + + // copy vector of isotopes's to solution + this->solution_ptr->isotopes = (struct isotope *) free_check_null(this->solution_ptr->isotopes); + if (this->isotopes.size() > 0) { + this->solution_ptr->isotopes = (struct isotope *) PHRQ_realloc(this->solution_ptr->isotopes, (size_t) (this->isotopes.size()) * sizeof(struct isotope)); + std::copy(this->isotopes.begin(), this->isotopes.end(), this->solution_ptr->isotopes); + } + this->solution_ptr->count_isotopes = this->isotopes.size(); + this->isotopes.clear(); + assert(this->isotopes.size() == 0); + + + // store solution for now + if (solution_bsearch(this->solution_ptr->n_user, &n, FALSE) != NULL) { + solution_free(solution[n]); + solution[n] = this->solution_ptr; + } else { + n = count_solution++; + if (count_solution >= max_solution) + { + space ((void **) &(solution), count_solution, &max_solution, sizeof (struct solution *) ); + } + solution[n] = this->solution_ptr; + } + this->solution_ptr = NULL; + } + break; + default: + break; + } +} + +void SaxPhreeqcHandlers::characters(const XMLCh* const chars, const unsigned int length) +{ + // skip whitespace + + //XMLCh* pChar = (XMLCh*)chars; + //while(pChar && iswspace(*pChar)) ++pChar; + //if (*pChar) + // { +/* + switch(this->eltType) + { + case typeSOLN_MASTER_ACTIVITY: + //xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(chars); + for ( i = 0; i < arg->size() - 1; i+=2 ) { + struct master_activity *ma = new master_activity(); + ma->description = XMLCh_hsave( arg->elementAt(i), true); + ma->la = XMLCh2Double( arg->elementAt(i + 1)); + this->acts.push_back(*ma); + } + //struct master_activity *ma = new master_activity(); + //ma->description = NULL; + //this->acts.push_back(*ma); + break; + } + */ + +} + +void SaxPhreeqcHandlers::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) +{ +} + +void SaxPhreeqcHandlers::processingInstruction(const XMLCh* const target, const XMLCh* const data) +{ +} + +void SaxPhreeqcHandlers::startDocument() +{ +} + +void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname, const xns::Attributes& attributes) +{ + //const char ERR_MSG[] = "Unpacking solution message: %s, element not found\n"; + char *string; + + int i; + + string = xns::XMLString::transcode(name); + this->eltType = this->mapXMLCh2Type[name]; + xns::XMLString::release(&string); + switch (this->eltType) + { + case typePHAST_STATE: + XMLCh *x; + x = xns::XMLString::transcode("nx"); + i = XMLCh2Int(attributes.getValue(x)); + xns::XMLString::release(&x); + break; + case typeSOLUTION: + assert(this->solution_ptr == NULL); + assert(this->totals.size() == 0); + assert(this->acts.size() == 0); + + // allocate space for solution + this->solution_ptr = solution_alloc(); + + // process attributes for solution + processSolutionAttributes(attributes); + break; + case typeSOLN_PE: + assert(this->solution_ptr->pe != NULL); + // store pe, no need to clean up at end of solution + if ((attributes.getLength() >= 1) && (this->mapXMLCh2AttType[attributes.getLocalName(0)] == attSOLN_PE_name)){ + string = xns::XMLString::transcode(attributes.getValue((unsigned int) 0)); + pe_data_store(&(this->solution_ptr->pe), string); + xns::XMLString::release(&string); + } else { + ++input_error; + sprintf(error_string, "No attribute data for SOLN_PE.\n"); + error_msg(error_string, CONTINUE); + } + break; + case typeSOLN_TOTAL: + { + // store in c, push_back on totals + // need to copy and clean up at end of + struct conc c; + processSolutionTotalAttributes(attributes, &c); + this->totals.push_back(c); + } + break; + case typeSOLN_MASTER_ACTIVITY: + { + // store in ma, push_back on acts + // need to copy and clean up at end of + struct master_activity ma; + processMasterActivityAttributes(attributes, &ma); + this->acts.push_back(ma); + //processMasterActivityAttributes(attributes, &this->acts); + } + break; + case typeSOLN_SPECIES_GAMMA: + { + // store in ma, push_back on s_gammas + // need to copy and clean up at end of + struct master_activity ma; + processMasterActivityAttributes(attributes, &ma); + this->s_gammas.push_back(ma); + } + break; + case typeSOLN_ISOTOPE: + { + // store in iso, push_back on isotopes + // need to copy and clean up at end of + struct isotope iso; + processIsotopeAttributes(attributes, &iso); + this->isotopes.push_back(iso); + } + break; + + default: + break; + } +} +int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attributes) +{ + const char ERR_MSG[] = "Unpacking solution attributes: %s, attribute not found\n"; + unsigned int i; + char *string; + attributeType attType; + assert(this->eltType == typeSOLUTION); + assert(this->solution_ptr != NULL); + + // Get attribute name, map to attribute type, process + + for (i = 0; i < attributes.getLength(); i++) { + attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; + switch (attType) { + case attSOLN_new_def: + this->solution_ptr->new_def = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_n_user: + this->solution_ptr->n_user = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_n_user_end: + this->solution_ptr->n_user_end = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_description: + this->solution_ptr->description = XMLCh2String(attributes.getValue(i)); + break; + case attSOLN_tc: + this->solution_ptr->tc = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_ph: + this->solution_ptr->ph = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_solution_pe: + this->solution_ptr->solution_pe = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_mu: + this->solution_ptr->mu = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_ah2o: + this->solution_ptr->ah2o = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_density: + this->solution_ptr->density = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_total_h: + this->solution_ptr->total_h = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_total_o: + this->solution_ptr->total_o = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_cb: + this->solution_ptr->cb = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_mass_water: + this->solution_ptr->mass_water = XMLCh2Double(attributes.getValue(i)); + break; + case attSOLN_total_alkalinity: + this->solution_ptr->total_alkalinity = XMLCh2Double(attributes.getValue(i)); + break; + //case attSOLN_total_co2: + //this->solution_ptr->total_co2 = XMLCh2Double(attributes.getValue(i)); + //break; + case attSOLN_units: + this->solution_ptr->units = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attSOLN_default_pe: + this->solution_ptr->default_pe = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_count_master_activity: + this->solution_ptr->count_master_activity = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_count_isotopes: + this->solution_ptr->count_isotopes = XMLCh2Int(attributes.getValue(i)); + break; + case attSOLN_count_species_gamma: + this->solution_ptr->count_species_gamma = XMLCh2Int(attributes.getValue(i)); + break; + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } + } + return 0; +} +int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& attributes, struct conc *c) +{ + const char ERR_MSG[] = "Unpacking solution totals attributes: %s, attribute not found\n"; + unsigned int i; + char *string; + conc_init(c); + attributeType attType; + assert(this->eltType == typeSOLN_TOTAL); + + + // Get attribute name, map to attribute type, process + + for (i = 0; i < attributes.getLength(); i++) { + attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; + switch (attType) { + case attCONC_description: + c->description = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attCONC_moles: + c->moles = XMLCh2Double(attributes.getValue(i)); + break; + case attCONC_input_conc: + c->input_conc = XMLCh2Double(attributes.getValue(i)); + break; + case attCONC_units: + c->units = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attCONC_equation_name: + c->equation_name = XMLCh_hsave(attributes.getValue(i), TRUE); + c->phase = NULL; + break; + case attCONC_phase_si: + c->phase_si = XMLCh2Double(attributes.getValue(i)); + break; + case attCONC_n_pe: + c->n_pe = XMLCh2Int(attributes.getValue(i)); + break; + case attCONC_as: + c->as = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attCONC_gfw: + c->gfw = XMLCh2Double(attributes.getValue(i)); + break; + + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } + } + return(OK); +} +int SaxPhreeqcHandlers::processMasterActivityAttributes(const xns::Attributes& attributes, struct master_activity *ma) +//int SaxPhreeqcHandlers::processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v) +{ + int i; + char *string; + const char ERR_MSG[] = "Unpacking master activity attributes: %s, attribute not found\n"; + ma->description = NULL; + ma->la = 0.0; + attributeType attType; + for (i = 0; i < (int) attributes.getLength(); i++) { + attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; + + switch (attType) { + + case attM_A_description: + ma->description = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attM_A_la: + ma->la = XMLCh2Double(attributes.getValue(i)); + break; + /* + case attM_A_list: + { + struct master_activity ma; + xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(attributes.getValue((unsigned int) 0)); + + for ( i = 0; i < arg->size(); i+=2 ) { + ma.description = XMLCh_hsave( arg->elementAt(i), TRUE); + if (strcmp(ma.description, "null") == 0) { + ma.description = NULL; + } + ma.la = XMLCh2Double( arg->elementAt(i+1)); + //this->acts.push_back(ma); + (*v).push_back(ma); + } + } + break; + */ + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } + } + return (OK); +} +int SaxPhreeqcHandlers::processIsotopeAttributes(const xns::Attributes& attributes, struct isotope *iso) +{ + int i; + char *string; + const char ERR_MSG[] = "Unpacking isotope attributes: %s, attribute not found\n"; + + iso->primary = iso->master = NULL; + iso->elt_name = iso->isotope_name = NULL; + attributeType attType; + for (i = 0; i < (int) attributes.getLength(); i++) { + attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; + switch (attType) { + case attISO_isotope_number: + iso->isotope_number = XMLCh2Int(attributes.getValue(i)); + break; + case attISO_elt_name: + iso->elt_name = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attISO_isotope_name: + iso->isotope_name = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attISO_total: + iso->total = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_ratio: + iso->ratio = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_ratio_uncertainty: + iso->ratio_uncertainty = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_coef: + iso->coef = XMLCh2Double(attributes.getValue(i)); + break; + + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } + } + return (OK); +} + diff --git a/SAXPhreeqc.h b/SAXPhreeqc.h new file mode 100644 index 00000000..68a1f587 --- /dev/null +++ b/SAXPhreeqc.h @@ -0,0 +1,20 @@ +#ifndef _INC_SAXPHREEQC_H +#define _INC_SAXPHREEQC_H + +#if defined(__cplusplus) | defined(_CPP) +extern "C" { +#endif + +void SAX_StartSystem (); +int SAX_AddSolution (struct solution* solution_ptr); +void SAX_EndSystem (); +int SAX_GetXMLLength (); +const char* SAX_GetXMLStr (); +int SAX_UnpackSolutions(void* pvBuffer, int buf_size); + + +#if defined(__cplusplus) | defined(_CPP) +} +#endif + +#endif diff --git a/SSassemblage.cxx b/SSassemblage.cxx new file mode 100644 index 00000000..8bc3082e --- /dev/null +++ b/SSassemblage.cxx @@ -0,0 +1,171 @@ +// SSassemblage.cxx: implementation of the cxxSSassemblage class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "SSassemblage.h" +#include "SSassemblageSS.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSSassemblage::cxxSSassemblage() + // + // default constructor for cxxSSassemblage + // +: cxxNumKeyword() +{ +} + +cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage *s_s_assemblage_ptr) + // + // constructor for cxxSSassemblage from struct SSassemblage + // +: +cxxNumKeyword() +{ + int i; + this->set_description(s_s_assemblage_ptr->description); + n_user = s_s_assemblage_ptr->n_user; + n_user_end = s_s_assemblage_ptr->n_user_end; + for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { + cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i])); + ssAssemblageSSs.push_back(ssSS); + } +} + +cxxSSassemblage::~cxxSSassemblage() +{ +} + +struct s_s_assemblage *cxxSSassemblage::cxxSSassemblage2s_s_assemblage() + // + // Builds a s_s_assemblage structure from instance of cxxSSassemblage + // +{ + struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc(); + + s_s_assemblage_ptr->description = this->get_description(); + s_s_assemblage_ptr->n_user = this->n_user; + s_s_assemblage_ptr->n_user_end = this->n_user_end; + s_s_assemblage_ptr->new_def = FALSE; + s_s_assemblage_ptr->count_s_s = this->ssAssemblageSSs.size(); + s_s_assemblage_ptr->s_s = cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs); + return(s_s_assemblage_ptr); +} + +#ifdef SKIP +void cxxSSassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // SSassemblage element and attributes + s_oss << indent0; + s_oss << "eltList.dump_xml(s_oss, indent + 1); + + // ssAssemblageSSs + s_oss << indent1; + s_oss << "::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } +} +#endif +void cxxSSassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // SSassemblage element and attributes + s_oss << indent0; + s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this->description << std::endl; + + // ssAssemblageSSs + for (std::list::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { + s_oss << indent1; + s_oss << "-solid_solution" << std::endl; + it->dump_raw(s_oss, indent + 2); + } +} + +void cxxSSassemblage::read_raw(CParser& parser) +{ + static std::vector 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); + + // 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 EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // solid_solution + { + cxxSSassemblageSS ssSS; + ssSS.read_raw(parser); + this->ssAssemblageSSs.push_back(ssSS); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } +} diff --git a/SSassemblage.h b/SSassemblage.h new file mode 100644 index 00000000..416c9e34 --- /dev/null +++ b/SSassemblage.h @@ -0,0 +1,42 @@ +#if !defined(SSASSEMBLAGE_H_INCLUDED) +#define SSASSEMBLAGE_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "SSassemblageSS.h" + +class cxxSSassemblage : public cxxNumKeyword +{ + +public: + cxxSSassemblage(); + cxxSSassemblage(struct s_s_assemblage *); + ~cxxSSassemblage(); + + struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); + + struct s_s *cxxSSassemblageComp2s_s(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + std::list ssAssemblageSSs; + +public: + //static std::map& map; + +}; + +#endif // !defined(SSASSEMBLAGE_H_INCLUDED) diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx new file mode 100644 index 00000000..2730621a --- /dev/null +++ b/SSassemblageSS.cxx @@ -0,0 +1,443 @@ +// SSassemblageSS.cxx: implementation of the cxxSSassemblageSS class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "SSassemblageSS.h" +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSSassemblageSS::cxxSSassemblageSS() + // + // default constructor for cxxSSassemblageSS + // +{ + name = NULL; + //total_moles = 0; + a0 = 0; + a1 = 0; + ag0 = 0; + ag1 = 0; + miscibility = false; + //spinodal = false; + //tk = 25.; + xb1 = 0; + xb2 = 0; + //SS_PARAMETER_TYPE type = SS_PARM_NONE; + //double p[4]; +} + +cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr) + // + // constructor for cxxSSassemblageSS from struct s_s + // + +{ + name = s_s_ptr->name; + //total_moles = s_s_ptr->total_moles; + a0 = s_s_ptr->a0; + a1 = s_s_ptr->a1; + ag0 = s_s_ptr->ag0; + ag1 = s_s_ptr->ag1; + miscibility = (s_s_ptr->miscibility == TRUE); + //spinodal = (s_s_ptr->spinodal == TRUE); + //tk = s_s_ptr->tk; + xb1 = s_s_ptr->xb1; + xb2 = s_s_ptr->xb2; + //type = s_s_ptr->input_case; + /* + for (i = 0; i < 4; i++) { + p[i] = s_s_ptr->p[i]; + } + */ + int i; + for (i = 0; i < s_s_ptr->count_comps; i++) { + comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles; + } +} + +cxxSSassemblageSS::~cxxSSassemblageSS() +{ +} + +struct s_s *cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list& el) + // + // Builds s_s structure from of cxxSSassemblageSS + // +{ + + // + // generate s_s structures + // + struct s_s *s_s_ptr = (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); + if (s_s_ptr == NULL) malloc_error(); + int j = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + s_s_ptr[j].name = it->name; + //s_s_ptr[j].total_moles = it->total_moles; + s_s_ptr[j].total_moles = 0; + s_s_ptr[j].dn = 0; + s_s_ptr[j].a0 = it->a0; + s_s_ptr[j].a1 = it->a1; + s_s_ptr[j].ag0 = it->ag0; + s_s_ptr[j].ag1 = it->ag1; + //s_s_ptr[j].ag0 = 0; + //s_s_ptr[j].ag1 = 0; + s_s_ptr[j].s_s_in = TRUE; + s_s_ptr[j].miscibility = it->miscibility; + //s_s_ptr[j].spinodal = it->spinodal; + s_s_ptr[j].spinodal = FALSE; + //s_s_ptr[j].tk = it->tk; + s_s_ptr[j].tk = 273.15; + s_s_ptr[j].xb1 = it->xb1; + s_s_ptr[j].xb2 = it->xb2; + s_s_ptr[j].input_case = 0; + s_s_ptr[j].p[0] = 0; + s_s_ptr[j].p[1] = 0; + s_s_ptr[j].p[2] = 0; + s_s_ptr[j].p[3] = 0; + // + // generate s_s_comp structures + // + s_s_ptr[j].count_comps = it->comps.size(); + s_s_ptr[j].comps = NULL; + if (it->comps.size() > 0) { + int i = 0; + int n; + struct s_s_comp *s_s_comp_ptr = (struct s_s_comp *) PHRQ_malloc((size_t) (it->comps.size() * sizeof(struct s_s_comp))); + if (s_s_comp_ptr == NULL) malloc_error(); + for (cxxNameDouble::iterator itc = it->comps.begin(); itc != it->comps.end(); ++ itc) { + s_s_comp_ptr[i].name = itc->first; + s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE); + s_s_comp_ptr[i].initial_moles = 0; + s_s_comp_ptr[i].moles = itc->second; + s_s_comp_ptr[i].init_moles = 0; + s_s_comp_ptr[i].delta = 0; + s_s_comp_ptr[i].fraction_x = 0; + s_s_comp_ptr[i].log10_lambda = 0; + s_s_comp_ptr[i].log10_fraction_x = 0; + s_s_comp_ptr[i].dn = 0; + s_s_comp_ptr[i].dnc = 0; + s_s_comp_ptr[i].dnb = 0; + i++; + } + s_s_ptr[j].comps = s_s_comp_ptr; + } + j++; + } + return(s_s_ptr); +} + +#ifdef SKIP +void cxxSSassemblageSS::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // S_S element and attributes + + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl; + s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl; + s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl; + +} +#endif +void cxxSSassemblageSS::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + + // S_S element and attributes + + s_oss << indent0 << "-name " << this->name << std::endl; + //s_oss << indent0 << "-total_moles " << this->total_moles << std::endl; + s_oss << indent0 << "-a0 " << this->a0 << std::endl; + s_oss << indent0 << "-a1 " << this->a1 << std::endl; + s_oss << indent0 << "-ag0 " << this->ag0 << std::endl; + s_oss << indent0 << "-ag1 " << this->ag1 << std::endl; + s_oss << indent0 << "-miscibility " << this->miscibility << std::endl; + //s_oss << indent0 << "-spinodal " << this->spinodal << std::endl; + //s_oss << indent0 << "-tk " << this->tk << std::endl; + s_oss << indent0 << "-xb1 " << this->xb1 << std::endl; + s_oss << indent0 << "-xb2 " << this->xb2 << std::endl; + s_oss << indent0 << "-component " << std::endl; + this->comps.dump_raw(s_oss, indent + 1); +} + +void cxxSSassemblageSS::read_raw(CParser& parser) +{ + std::string str; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("total_moles"); // 1 + vopts.push_back("a0"); // 2 + vopts.push_back("a1"); // 3 + vopts.push_back("components"); // 4 + vopts.push_back("miscibility"); // 5 + vopts.push_back("spinodal"); // 6 + vopts.push_back("tk"); // 7 + vopts.push_back("xb1"); // 8 + vopts.push_back("xb2"); // 9 + vopts.push_back("ag0"); // 10 + vopts.push_back("ag1"); // 11 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + //bool total_moles_defined(false); + bool a0_defined(false); + bool a1_defined(false); + bool ag0_defined(false); + bool ag1_defined(false); + bool miscibility_defined(false); + //bool spinodal_defined(false); + //bool tk_defined(false); + bool xb1_defined(false); + bool xb2_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); + } else { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + opt_save = CParser::OPT_DEFAULT; + 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.", CParser::OT_CONTINUE); + } + total_moles_defined = true; + */ + opt_save = CParser::OPT_DEFAULT; + break; + + case 2: // a0 + if (!(parser.get_iss() >> this->a0)) + { + this->a0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for a0.", CParser::OT_CONTINUE); + } + a0_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 3: // a1 + if (!(parser.get_iss() >> this->a1)) + { + this->a1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for a1.", CParser::OT_CONTINUE); + } + a1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 4: // components + if ( this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected phase name and moles for comps.", CParser::OT_CONTINUE); + } + opt_save = 4; + break; + + case 5: // miscibility + if (!(parser.get_iss() >> this->miscibility)) + { + this->miscibility = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for miscibility.", CParser::OT_CONTINUE); + } + miscibility_defined = true; + opt_save = CParser::OPT_DEFAULT; + 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.", CParser::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.", CParser::OT_CONTINUE); + } + tk_defined = true; + */ + opt_save = CParser::OPT_DEFAULT; + break; + + case 8: // xb1 + if (!(parser.get_iss() >> this->xb1)) + { + this->xb1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for xb1.", CParser::OT_CONTINUE); + } + xb1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 9: // xb2 + if (!(parser.get_iss() >> this->xb2)) + { + this->xb2 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for xb2.", CParser::OT_CONTINUE); + } + xb2_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 10: // ag0 + if (!(parser.get_iss() >> this->ag0)) + { + this->ag0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ag0.", CParser::OT_CONTINUE); + } + ag0_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 11: // ag1 + if (!(parser.get_iss() >> this->ag1)) + { + this->ag1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ag1.", CParser::OT_CONTINUE); + } + ag1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (name_defined == false) { + parser.incr_input_error(); + parser.error_msg("Name not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + /* + if (total_moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (a0_defined == false) { + parser.incr_input_error(); + parser.error_msg("A0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (a1_defined == false) { + parser.incr_input_error(); + parser.error_msg("A1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (ag0_defined == false) { + parser.incr_input_error(); + parser.error_msg("Ag0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (ag1_defined == false) { + parser.incr_input_error(); + parser.error_msg("Ag1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (miscibility_defined == false) { + parser.incr_input_error(); + parser.error_msg("Miscibility not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + /* + if (spinodal_defined == false) { + parser.incr_input_error(); + parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (tk_defined == false) { + parser.incr_input_error(); + parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (xb1_defined == false) { + parser.incr_input_error(); + parser.error_msg("Xb1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (xb2_defined == false) { + parser.incr_input_error(); + parser.error_msg("Xb2 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } +} + diff --git a/SSassemblageSS.h b/SSassemblageSS.h new file mode 100644 index 00000000..cf9c5261 --- /dev/null +++ b/SSassemblageSS.h @@ -0,0 +1,65 @@ +#if !defined(SSASSEMBLAGESS_H_INCLUDED) +#define SSASSEMBLAGESS_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxSSassemblageSS +{ + +public: + cxxSSassemblageSS(); + cxxSSassemblageSS(struct s_s *); + ~cxxSSassemblageSS(); + + enum SS_PARAMETER_TYPE { + SS_PARM_NONE = -1, + SS_PARM_A0_A1 = 0, + SS_PARM_GAMMAS = 1, + SS_PARM_DIST_COEF = 2, + SS_PARM_MISCIBILITY = 3, + SS_PARM_SPINODAL = 4, + SS_PARM_CRITICAL = 5, + SS_PARM_ALYOTROPIC = 6, + SS_PARM_DIM_GUGG = 7, + SS_PARM_WALDBAUM = 8, + SS_PARM_MARGULES = 9 + }; + + static struct s_s *cxxSSassemblageSS2s_s(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + char *name; + //std::list ppAssemblageSS; + cxxNameDouble comps; + //double total_moles; + //double dn; + double a0, a1; + double ag0, ag1; + //bool s_s_in; + bool miscibility; + //bool spinodal; + //double tk; + double xb1, xb2; + //SS_PARAMETER_TYPE type; + //double p[4]; + +public: + +}; + +#endif // !defined(SSASSEMBLAGESS_H_INCLUDED) diff --git a/SaxPhreeqcHandlers.h b/SaxPhreeqcHandlers.h new file mode 100644 index 00000000..2eb590a7 --- /dev/null +++ b/SaxPhreeqcHandlers.h @@ -0,0 +1,154 @@ +// SaxPhreeqcHandlers.h: interface for the SaxPhreeqcHandlers class. +// +////////////////////////////////////////////////////////////////////// + +#if !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_) +#define AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#include // iswspace sprintf +#include // SAX2XMLReader +/** +#include +**/ +#include +#include + +#define xns XERCES_CPP_NAMESPACE + +#ifdef USE_LONG_DOUBLE +#define LDBLE long double +#else +#define LDBLE double +#endif + +struct XMLCH_LESS : std::binary_function { +bool operator()(const XMLCh* _X, const XMLCh* _Y) const +{ + return xns::XMLString::compareString( _X, _Y) < 0;} +}; + +#include +//extern "C" { +#define EXTERNAL extern +//#include "phqalloc.h" +#include "global.h" +#include "phrqproto.h" +// int conc_init(struct conc *conc_ptr); +//} + + +class Cconc : public conc +{ +public: + Cconc() { conc_init(this); } + ~Cconc() { ; } +}; + + +class SaxPhreeqcHandlers : public xns::DefaultHandler +{ +public: + SaxPhreeqcHandlers(); + virtual ~SaxPhreeqcHandlers(); + + // ----------------------------------------------------------------------- + // Implementations of the SAX DocumentHandler interface + // ----------------------------------------------------------------------- + void endDocument(); + + void endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname); + + void characters(const XMLCh* const chars, const unsigned int length); + + void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); + + void processingInstruction(const XMLCh* const target, const XMLCh* const data); + + void startDocument(); + + void startElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname, const xns::Attributes& attributes); + + // element types + enum elementType + { + typeNULL, + typePHAST_STATE, + typeSYSTEM, + typeSOLUTION, + typeSOLN_PE, + typeSOLN_TOTAL, + typeSOLN_MASTER_ACTIVITY, + typeSOLN_ISOTOPE, + typeSOLN_SPECIES_GAMMA + } eltType; + // attribute types + enum attributeType + { + attNULL, + attSOLN_new_def, + attSOLN_n_user, + attSOLN_n_user_end, + attSOLN_description, + attSOLN_tc, + attSOLN_ph, + attSOLN_solution_pe, + attSOLN_mu, + attSOLN_ah2o, + attSOLN_density, + attSOLN_total_h, + attSOLN_total_o, + attSOLN_cb, + attSOLN_mass_water, + attSOLN_total_alkalinity, + attSOLN_total_co2, + attSOLN_units, + attSOLN_default_pe, + attSOLN_count_master_activity, + attSOLN_count_isotopes, + attSOLN_count_species_gamma, + attSOLN_PE_name, + attM_A_description, + attM_A_la, + attM_A_list, + attISO_isotope_number, + attISO_elt_name, + attISO_isotope_name, + attISO_total, + attISO_ratio, + attISO_ratio_uncertainty, + attISO_x_ratio_uncertainty, + attISO_coef, + attCONC_description, + attCONC_moles, + attCONC_input_conc, + attCONC_units, + attCONC_equation_name, + attCONC_phase_si, + attCONC_n_pe, + attCONC_as, + attCONC_gfw, + } attType; + + int processSolutionAttributes(const xns::Attributes& attributes); + int processSolutionTotalAttributes(const xns::Attributes& attributes, struct conc *c); + int processMasterActivityAttributes(const xns::Attributes& attributes, struct master_activity *ma); + //int processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v); + int processIsotopeAttributes(const xns::Attributes& attributes, struct isotope *iso); + +protected: + std::vector totals; + std::vector acts, s_gammas; + std::vector isotopes; + std::map< const XMLCh*, elementType, XMLCH_LESS > mapXMLCh2Type; + std::map< const XMLCh*, attributeType, XMLCH_LESS > mapXMLCh2AttType; + /** + std::hash_map, XMLCH_EQUALS> m_hashmapXMLCh2Type; + **/ + struct solution* solution_ptr; +}; + +#endif // !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_) diff --git a/Solution.cxx b/Solution.cxx new file mode 100644 index 00000000..9331295c --- /dev/null +++ b/Solution.cxx @@ -0,0 +1,1102 @@ +// Solution.cxx: implementation of the cxxSolution class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Solution.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSolution::cxxSolution() + // + // default constructor for cxxSolution + // +: cxxNumKeyword() +{ + tc = 25.0; + ph = 7.0; + pe = 4.0; + mu = 1e-7; + ah2o = 1.0; + total_h = 111.1; + total_o = 55.55; + cb = 0.0; + mass_water = 1.0; + total_alkalinity = 0.0; + totals.type = cxxNameDouble::ND_ELT_MOLES; + master_activity.type = cxxNameDouble::ND_SPECIES_LA; + species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; +} + +cxxSolution::cxxSolution(struct solution *solution_ptr) + // + // constructor for cxxSolution from struct solution + // +: +cxxNumKeyword(), +totals(solution_ptr->totals), +master_activity(solution_ptr->master_activity, solution_ptr->count_master_activity, cxxNameDouble::ND_SPECIES_LA), +species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA) +{ + int i; + + this->set_description(solution_ptr->description); + n_user = solution_ptr->n_user; + n_user_end = solution_ptr->n_user_end; + tc = solution_ptr->tc; + ph = solution_ptr->ph; + pe = solution_ptr->solution_pe; + mu = solution_ptr->mu; + ah2o = solution_ptr->ah2o; + total_h = solution_ptr->total_h; + total_o = solution_ptr->total_o; + cb = solution_ptr->cb; + mass_water = solution_ptr->mass_water; + total_alkalinity = solution_ptr->total_alkalinity; + + // Totals filled in constructor, just save description and moles + + // Isotopes + for (i = 0; i < solution_ptr->count_isotopes; i++) { + cxxIsotope iso(&solution_ptr->isotopes[i]); + isotopes.push_back(iso); + } + + // Master_activity in constructor + // Species_gamma in constructor +} + +cxxSolution::~cxxSolution() +{ +} + +struct solution *cxxSolution::cxxSolution2solution() + // + // Builds a solution structure from instance of cxxSolution + // +{ + + struct solution *solution_ptr = solution_alloc(); + + solution_ptr->description = this->get_description(); + solution_ptr->n_user = this->n_user; + solution_ptr->n_user_end = this->n_user_end; + solution_ptr->new_def = FALSE; + solution_ptr->tc = this->tc; + solution_ptr->ph = this->ph; + solution_ptr->solution_pe = this->pe; + solution_ptr->mu = this->mu; + solution_ptr->ah2o = this->ah2o; + solution_ptr->total_h = this->total_h; + solution_ptr->total_o = this->total_o; + solution_ptr->cb = this->cb; + solution_ptr->mass_water = this->mass_water; + solution_ptr->total_alkalinity = this->total_alkalinity; + solution_ptr->density = 1.0; + solution_ptr->units = moles_per_kilogram_string; + solution_ptr->default_pe = 0; + // pe_data + + // totals + solution_ptr->totals = (struct conc *) free_check_null(solution_ptr->totals); + solution_ptr->totals = this->totals.conc(); + + // master_activity + solution_ptr->master_activity = (struct master_activity *) free_check_null(solution_ptr->master_activity); + solution_ptr->master_activity = this->master_activity.master_activity(); + solution_ptr->count_master_activity = this->master_activity.size() + 1; + + // species_gamma + solution_ptr->species_gamma = this->species_gamma.master_activity(); + solution_ptr->count_species_gamma = this->species_gamma.size(); + + // isotopes + solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); + solution_ptr->isotopes = cxxIsotope::list2isotope(this->isotopes); + solution_ptr->count_isotopes = this->isotopes.size(); + + return(solution_ptr); +} +void cxxSolution::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + + // Solution element and attributes + s_oss << indent0; + s_oss << "new_def << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_n_user=\"" << this->n_user << "\" " << std::endl; + + s_oss << indent1; + s_oss << "soln_description=\"" << this->description << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_tc=\"" << this->tc << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_ph=\"" << this->ph << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_solution_pe=\"" << this->pe << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_mu=\"" << this->mu << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_ah2o=\"" << this->ah2o << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_total_h=\"" << this->total_h << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_total_o=\"" << this->total_o << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_cb=\"" << this->cb << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << std::endl; + + s_oss << indent1; + s_oss << "soln_total_alkalinity=\"" << this->total_alkalinity << "\"" << std::endl; + + s_oss << indent1; + s_oss << "\">" << std::endl; + + // soln_total conc structures + this->totals.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\""; + s_oss << " conc_moles=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ + // master_activity map + this->master_activity.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\"" ; + s_oss << " m_a_la=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ + // species_gamma map + this->species_gamma.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\"" ; + s_oss << " m_a_la=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ + + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_xml(s_oss, indent + 1); + } + + // End of solution + s_oss << indent0; + s_oss << "" << std::endl; + + return; +} + +void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Solution element and attributes + s_oss << indent0; + s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-temp " << this->tc << std::endl; + + s_oss << indent1; + s_oss << "-pH " << this->ph << std::endl; + + s_oss << indent1; + s_oss << "-pe " << this->pe << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-mu " << this->mu << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-ah2o " << this->ah2o << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_h " << this->total_h << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_o " << this->total_o << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-cb " << this->cb << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-mass_water " << this->mass_water << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + + // soln_total conc structures + s_oss << indent1; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 2); + /* + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + */ + + // master_activity map + s_oss << indent1; + s_oss << "-activities" << std::endl; + this->master_activity.dump_raw(s_oss, indent + 2); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + */ + // species_gamma map + s_oss << indent1; + s_oss << "-gammas" << std::endl; + this->species_gamma.dump_raw(s_oss, indent + 2); + /* + { + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + } + */ + // Isotopes + s_oss << indent1; + s_oss << "-Isotopes" << std::endl; + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + + return; +} + +void cxxSolution::read_raw(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(21); + vopts.push_back("totals"); // 0 + vopts.push_back("activities"); // 1 + vopts.push_back("gammas"); // 2 + vopts.push_back("isotopes"); // 3 + vopts.push_back("temp"); // 4 + vopts.push_back("tc"); // 5 + vopts.push_back("temperature"); // 6 + vopts.push_back("ph"); // 7 + vopts.push_back("pe"); // 8 + vopts.push_back("mu"); // 9 + vopts.push_back("ionic_strength"); // 10 + vopts.push_back("ah2o"); // 11 + vopts.push_back("activity_water"); // 12 + vopts.push_back("total_h"); // 13 + vopts.push_back("total_o"); // 14 + vopts.push_back("mass_water"); // 15 + vopts.push_back("mass_h2o"); // 16 + vopts.push_back("total_alkalinity"); // 17 + vopts.push_back("total_alk"); // 18 + vopts.push_back("cb"); // 19 + vopts.push_back("charge_balance"); // 20 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + // Read solution number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool tc_defined(false); + bool ph_defined(false); + bool pe_defined(false); + bool mu_defined(false); + bool ah2o_defined(false); + bool total_h_defined(false); + bool total_o_defined(false); + bool cb_defined(false); + bool mass_water_defined(false); + bool total_alkalinity_defined(false); + + for (;;) + { + int opt = parser.get_option(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 SOLUTION_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // totals + if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and moles for totals.", CParser::OT_CONTINUE); + } + opt_save = 0; + break; + + case 1: // activities + if ( this->master_activity.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected species name and log activity for activities.", CParser::OT_CONTINUE); + } + opt_save = 1; + break; + + case 2: // gammas + if ( this->species_gamma.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected species name and activity coefficient for gammas.", CParser::OT_CONTINUE); + } + opt_save = 2; + break; + + case 3: // isotopes + { + cxxIsotope iso; + if ( iso.read_raw(parser) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected data for isotopes.", CParser::OT_CONTINUE); + } else { + if (iso.get_isotope_name() != NULL) { + this->isotopes.push_back(iso); + } + } + } + opt_save = 3; + break; + + case 4: // temp + case 5: // tc + case 6: // temperature + if (!(parser.get_iss() >> this->tc)) + { + this->tc = 25.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for temperature.", CParser::OT_CONTINUE); + } + tc_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 7: // ph + if (!(parser.get_iss() >> this->ph)) + { + this->ph = 7.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pH.", CParser::OT_CONTINUE); + } + ph_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 8: // pe + if (!(parser.get_iss() >> this->pe)) + { + this->pe = 4.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pe.", CParser::OT_CONTINUE); + } + pe_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 9: // mu + case 10: // ionic_strength + if (!(parser.get_iss() >> this->mu)) + { + this->mu = 1e-7; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ionic strength.", CParser::OT_CONTINUE); + } + mu_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 11: // ah2o + case 12: // activity_water + if (!(parser.get_iss() >> this->ah2o)) + { + this->ah2o = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for activity of water.", CParser::OT_CONTINUE); + } + ah2o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 13: // total_h + if (!(parser.get_iss() >> this->total_h)) + { + this->total_h = 111.1; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total hydrogen.", CParser::OT_CONTINUE); + } + total_h_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 14: // total_o + if (!(parser.get_iss() >> this->total_o)) + { + this->total_o = 55.55; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total oxygen.", CParser::OT_CONTINUE); + } + total_o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 15: // mass_water + case 16: // mass_h2o + if (!(parser.get_iss() >> this->mass_water)) + { + this->mass_water = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water.", CParser::OT_CONTINUE); + } + mass_water_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 17: // total_alkalinity + case 18: // total_alk + if (!(parser.get_iss() >> this->total_alkalinity)) + { + this->total_alkalinity = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total_alkalinity.", CParser::OT_CONTINUE); + } + total_alkalinity_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 19: // cb + case 20: // charge_balance + if (!(parser.get_iss() >> this->cb)) + { + this->cb = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge balance.", CParser::OT_CONTINUE); + } + cb_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // all members must be defined + if (tc_defined == false) { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (ph_defined == false) { + parser.incr_input_error(); + parser.error_msg("pH not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (pe_defined == false) { + parser.incr_input_error(); + parser.error_msg("pe not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (mu_defined == false) { + parser.incr_input_error(); + parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (ah2o_defined == false) { + parser.incr_input_error(); + parser.error_msg("Activity of water not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (total_h_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (total_o_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (cb_defined == false) { + parser.incr_input_error(); + parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (mass_water_defined == false) { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + if (total_alkalinity_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total alkalinity not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); + } + return; +} + +#ifdef SKIP +cxxSolution& cxxSolution::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxSolution numkey; + + // Read solution number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxSolution& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.solution_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif + + +#include "ISolution.h" +#include "Exchange.h" +#include "Surface.h" +#include "PPassemblage.h" +#include "KineticsCxx.h" +#include "SSassemblage.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "Mix.h" +#include "Temperature.h" +#include // std::cout std::cerr +//#include +#include +#include +void test_classes(void) +{ + int i; + bool b(true); + i = (int) b; + for (i=0; i < count_solution; i++) { + if (solution[i]->new_def == TRUE) { + cxxISolution sol(solution[i]); + solution[i] = (struct solution *) solution_free(solution[i]); + solution[i] = sol.cxxISolution2solution(); + struct solution *soln_ptr; + soln_ptr = solution[i]; + soln_ptr = solution[i]; + } else { + std::ostringstream oss; + cxxSolution sol(solution[i]); + solution[i] = (struct solution *) solution_free(solution[i]); + sol.dump_raw(oss, 0); + + //std::fstream myfile("t"); + //CParser cparser(myfile, std::cout, std::cerr); + cxxSolution sol1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + + sol1.read_raw(cparser); + + solution[i] = sol1.cxxSolution2solution(); + } + } + for (i=0; i < count_exchange; i++) { + if (exchange[i].new_def != TRUE) { + std::ostringstream oss; + cxxExchange ex(&(exchange[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + cxxExchange ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); + exchange_free(&exchange[i]); + exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); + exchange_free(exchange_ptr); + free_check_null(exchange_ptr); + } + } + for (i=0; i < count_surface; i++) { + if (surface[i].new_def != TRUE) { + std::ostringstream oss; + cxxSurface ex(&(surface[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxSurface ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct surface *surface_ptr = ex1.cxxSurface2surface(); + surface_free(&surface[i]); + surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); + surface_free(surface_ptr); + free_check_null(surface_ptr); + + } + + } + for (i=0; i < count_pp_assemblage; i++) { + if (pp_assemblage[i].new_def != TRUE) { + std::ostringstream oss; + cxxPPassemblage ex(&(pp_assemblage[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxPPassemblage ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct pp_assemblage *pp_assemblage_ptr = ex1.cxxPPassemblage2pp_assemblage(); + pp_assemblage_free(&pp_assemblage[i]); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], pp_assemblage_ptr->n_user); + pp_assemblage_free(pp_assemblage_ptr); + free_check_null(pp_assemblage_ptr); + + } + + } + for (i=0; i < count_kinetics; i++) { + std::ostringstream oss; + cxxKinetics ex(&(kinetics[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxKinetics ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + + ex1.read_raw(cparser); + + struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); + kinetics_free(&kinetics[i]); + kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); + kinetics_free(kinetics_ptr); + free_check_null(kinetics_ptr); + } + for (i=0; i < count_s_s_assemblage; i++) { + if (s_s_assemblage[i].new_def != TRUE) { + std::ostringstream oss; + cxxSSassemblage ex(&(s_s_assemblage[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxSSassemblage ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct s_s_assemblage *s_s_assemblage_ptr = ex1.cxxSSassemblage2s_s_assemblage(); + s_s_assemblage_free(&s_s_assemblage[i]); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], s_s_assemblage_ptr->n_user); + s_s_assemblage_free(s_s_assemblage_ptr); + free_check_null(s_s_assemblage_ptr); + + } + + } + for (i=0; i < count_gas_phase; i++) { + if (gas_phase[i].new_def != TRUE) { + std::ostringstream oss; + cxxGasPhase ex(&(gas_phase[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxGasPhase ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); + gas_phase_free(&gas_phase[i]); + gas_phase_copy(gas_phase_ptr, &gas_phase[i], gas_phase_ptr->n_user); + gas_phase_free(gas_phase_ptr); + free_check_null(gas_phase_ptr); + + } + + } + for (i=0; i < count_irrev; i++) { + std::ostringstream oss; + cxxReaction ex(&(irrev[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxReaction ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); + + irrev_free(&irrev[i]); + irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); + + irrev_free(irrev_ptr); + free_check_null(irrev_ptr); + + } + for (i=0; i < count_mix; i++) { + std::ostringstream oss; + cxxMix ex(&(mix[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxMix ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct mix *mix_ptr = ex1.cxxMix2mix(); + + mix_free(&mix[i]); + mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); + + mix_free(mix_ptr); + free_check_null(mix_ptr); + + } + for (i=0; i < count_temperature; i++) { + std::ostringstream oss; + cxxTemperature ex(&(temperature[i])); + ex.dump_raw(oss, 0); + std::cerr << oss.str(); + + + cxxTemperature ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct temperature *temperature_ptr = ex1.cxxTemperature2temperature(); + + temperature_free(&temperature[i]); + temperature_copy(temperature_ptr, &temperature[i], temperature_ptr->n_user); + + temperature_free(temperature_ptr); + free_check_null(temperature_ptr); + + } +} diff --git a/Solution.h b/Solution.h new file mode 100644 index 00000000..e9225701 --- /dev/null +++ b/Solution.h @@ -0,0 +1,94 @@ +#if !defined(SOLUTION_H_INCLUDED) +#define SOLUTION_H_INCLUDED + +#include "NumKeyword.h" +#include "Isotope.h" +#include "Conc.h" +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxSolution : public cxxNumKeyword +{ + +public: + cxxSolution(); + cxxSolution(struct solution *); + //cxxSolution(const cxxSolution&); + ~cxxSolution(); + + //static cxxSolution& read(CParser& parser); + + double get_tc()const {return this->tc;} + void set_tc(double tc) {this->tc = tc;} + + double get_ph()const {return this->ph;} + void set_ph(double pH) {this->ph = pH;} + + double get_pe()const {return this->pe;} + void set_pe(double pe) {this->pe =pe;} + + double get_mu()const {return this->mu;} + void set_mu(double mu) {this->pe = mu;} + + double get_ah2o()const {return this->ah2o;} + void set_ah2o(double ah2o) {this->pe = ah2o;} + + double get_total_h()const {return this->total_h;} + void set_total_h(double total_h) {this->pe = mu;} + + double get_total_o()const {return this->total_o;} + void set_total_o(double total_o) {this->pe = mu;} + + double get_mass_water()const {return this->mass_water;}; + void set_mass_water(long double mass_water) {this->mass_water = mass_water;}; + + double get_total_alkalinity()const {return this->total_alkalinity;} + void set_total_alkalinity(double total_alkalinity) {this->pe = total_alkalinity;} + + //char * get_pe_reaction()const {return this->pe_reaction;} + //void set_pe_reaction(char * pe_reaction) {this->pe_reaction = pe_reaction;} + + struct solution *cxxSolution2solution(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void cxxSolution::read_raw(CParser& parser); + + +protected: + double tc; + double ph; + double pe; + double mu; + double ah2o; + double total_h; + double total_o; + double cb; + double mass_water; + double total_alkalinity; + // maps element name to moles + //std::map totals; + cxxNameDouble totals; + std::list isotopes; + // maps master species name log activity + //std::map master_activity; + cxxNameDouble master_activity; + // maps species name to Pitzer activty coefficient + //std::map species_gamma; + cxxNameDouble species_gamma; +public: + //static std::map& map; + +}; + +#endif // !defined(SOLUTION_H_INCLUDED) diff --git a/Sun/examples/ex1.log b/Sun/examples/ex1.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex1.out b/Sun/examples/ex1.out new file mode 100644 index 00000000..658d1320 --- /dev/null +++ b/Sun/examples/ex1.out @@ -0,0 +1,325 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex1 + Output file: ex1.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 1.--Add uranium and speciate seawater. + SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979) + units ppm + pH 8.22 + pe 8.451 + density 1.023 + temp 25.0 + redox O(0)/O(-2) + Ca 412.3 + Mg 1291.8 + Na 10768.0 + K 399.1 + Fe 0.002 + Mn 0.0002 pe + Si 4.28 + Cl 19353.0 + Alkalinity 141.682 as HCO3 + S(6) 2712.0 + N(5) 0.29 gfw 62.0 + N(-3) 0.03 as NH4 + U 3.3 ppb N(5)/N(-3) + O(0) 1.0 O2(g) -0.7 + SOLUTION_MASTER_SPECIES + U U+4 0.0 238.0290 238.0290 + U(4) U+4 0.0 238.0290 + U(5) UO2+ 0.0 238.0290 + U(6) UO2+2 0.0 238.0290 + SOLUTION_SPECIES + U+4 = U+4 + log_k 0.0 + U+4 + 4 H2O = U(OH)4 + 4 H+ + log_k -8.538 + delta_h 24.760 kcal + U+4 + 5 H2O = U(OH)5- + 5 H+ + log_k -13.147 + delta_h 27.580 kcal + U+4 + 2 H2O = UO2+ + 4 H+ + e- + log_k -6.432 + delta_h 31.130 kcal + U+4 + 2 H2O = UO2+2 + 4 H+ + 2 e- + log_k -9.217 + delta_h 34.430 kcal + UO2+2 + H2O = UO2OH+ + H+ + log_k -5.782 + delta_h 11.015 kcal + 2UO2+2 + 2H2O = (UO2)2(OH)2+2 + 2H+ + log_k -5.626 + delta_h -36.04 kcal + 3UO2+2 + 5H2O = (UO2)3(OH)5+ + 5H+ + log_k -15.641 + delta_h -44.27 kcal + UO2+2 + CO3-2 = UO2CO3 + log_k 10.064 + delta_h 0.84 kcal + UO2+2 + 2CO3-2 = UO2(CO3)2-2 + log_k 16.977 + delta_h 3.48 kcal + UO2+2 + 3CO3-2 = UO2(CO3)3-4 + log_k 21.397 + delta_h -8.78 kcal + PHASES + Uraninite + UO2 + 4 H+ = U+4 + 2 H2O + log_k -3.490 + delta_h -18.630 kcal + END +----- +TITLE +----- + + Example 1.--Add uranium and speciate seawater. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. SEAWATER FROM NORDSTROM ET AL. (1979) + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Alkalinity 2.406e-03 2.406e-03 + Ca 1.066e-02 1.066e-02 + Cl 5.657e-01 5.657e-01 + Fe 3.711e-08 3.711e-08 + K 1.058e-02 1.058e-02 + Mg 5.507e-02 5.507e-02 + Mn 3.773e-09 3.773e-09 + N(-3) 1.724e-06 1.724e-06 + N(5) 4.847e-06 4.847e-06 + Na 4.854e-01 4.854e-01 + O(0) 3.746e-04 3.746e-04 Equilibrium with O2(g) + S(6) 2.926e-02 2.926e-02 + Si 7.382e-05 7.382e-05 + U 1.437e-08 1.437e-08 + +----------------------------Description of solution---------------------------- + + pH = 8.220 + pe = 8.451 + Activity of water = 0.981 + Ionic strength = 6.748e-01 + Mass of water (kg) = 1.000e+00 + Total carbon (mol/kg) = 2.180e-03 + Total CO2 (mol/kg) = 2.180e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.936e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.07 + Iterations = 7 + Total H = 1.110147e+02 + Total O = 5.563047e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + N(-3)/N(5) 4.6750 0.2766 + O(-2)/O(0) 12.3893 0.7329 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.674e-06 1.629e-06 -5.573 -5.788 -0.215 + H+ 7.981e-09 6.026e-09 -8.098 -8.220 -0.122 + H2O 5.551e+01 9.806e-01 1.744 -0.009 0.000 +C(4) 2.180e-03 + HCO3- 1.514e-03 1.023e-03 -2.820 -2.990 -0.170 + MgHCO3+ 2.195e-04 1.640e-04 -3.658 -3.785 -0.127 + NaHCO3 1.667e-04 1.948e-04 -3.778 -3.710 0.067 + MgCO3 8.913e-05 1.041e-04 -4.050 -3.982 0.067 + NaCO3- 6.718e-05 5.020e-05 -4.173 -4.299 -0.127 + CaHCO3+ 4.597e-05 3.106e-05 -4.337 -4.508 -0.170 + CO3-2 3.821e-05 7.959e-06 -4.418 -5.099 -0.681 + CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 + CO2 1.210e-05 1.413e-05 -4.917 -4.850 0.067 + UO2(CO3)3-4 1.255e-08 1.184e-10 -7.901 -9.927 -2.025 + UO2(CO3)2-2 1.814e-09 5.653e-10 -8.741 -9.248 -0.506 + MnCO3 2.696e-10 3.150e-10 -9.569 -9.502 0.067 + MnHCO3+ 6.077e-11 4.541e-11 -10.216 -10.343 -0.127 + UO2CO3 7.429e-12 8.678e-12 -11.129 -11.062 0.067 + FeCO3 1.952e-20 2.281e-20 -19.709 -19.642 0.067 + FeHCO3+ 1.635e-20 1.222e-20 -19.786 -19.913 -0.127 +Ca 1.066e-02 + Ca+2 9.504e-03 2.380e-03 -2.022 -2.623 -0.601 + CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 + CaHCO3+ 4.597e-05 3.106e-05 -4.337 -4.508 -0.170 + CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 + CaOH+ 8.604e-08 6.429e-08 -7.065 -7.192 -0.127 + CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 +Cl 5.657e-01 + Cl- 5.657e-01 3.528e-01 -0.247 -0.452 -0.205 + MnCl+ 9.582e-10 7.160e-10 -9.019 -9.145 -0.127 + MnCl2 9.439e-11 1.103e-10 -10.025 -9.958 0.067 + MnCl3- 1.434e-11 1.071e-11 -10.844 -10.970 -0.127 + FeCl+2 9.557e-19 2.978e-19 -18.020 -18.526 -0.506 + FeCl2+ 6.281e-19 4.693e-19 -18.202 -18.329 -0.127 + FeCl+ 7.786e-20 5.817e-20 -19.109 -19.235 -0.127 + FeCl3 1.417e-20 1.656e-20 -19.849 -19.781 0.067 +Fe(2) 6.909e-19 + Fe+2 5.205e-19 1.195e-19 -18.284 -18.923 -0.639 + FeCl+ 7.786e-20 5.817e-20 -19.109 -19.235 -0.127 + FeSO4 4.845e-20 5.660e-20 -19.315 -19.247 0.067 + FeCO3 1.952e-20 2.281e-20 -19.709 -19.642 0.067 + FeHCO3+ 1.635e-20 1.222e-20 -19.786 -19.913 -0.127 + FeOH+ 8.227e-21 6.147e-21 -20.085 -20.211 -0.127 + FeHSO4+ 3.000e-27 2.242e-27 -26.523 -26.649 -0.127 +Fe(3) 3.711e-08 + Fe(OH)3 2.841e-08 3.318e-08 -7.547 -7.479 0.067 + Fe(OH)4- 6.591e-09 4.924e-09 -8.181 -8.308 -0.127 + Fe(OH)2+ 2.118e-09 1.583e-09 -8.674 -8.801 -0.127 + FeOH+2 9.425e-14 2.937e-14 -13.026 -13.532 -0.506 + FeSO4+ 1.093e-18 8.167e-19 -17.961 -18.088 -0.127 + FeCl+2 9.557e-19 2.978e-19 -18.020 -18.526 -0.506 + FeCl2+ 6.281e-19 4.693e-19 -18.202 -18.329 -0.127 + Fe+3 3.509e-19 2.796e-20 -18.455 -19.554 -1.099 + Fe(SO4)2- 6.372e-20 4.761e-20 -19.196 -19.322 -0.127 + FeCl3 1.417e-20 1.656e-20 -19.849 -19.781 0.067 + Fe2(OH)2+4 2.462e-24 2.322e-26 -23.609 -25.634 -2.025 + FeHSO4+2 4.228e-26 1.318e-26 -25.374 -25.880 -0.506 + Fe3(OH)4+5 1.122e-29 7.679e-33 -28.950 -32.115 -3.165 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.436 -44.369 0.067 +K 1.058e-02 + K+ 1.042e-02 6.495e-03 -1.982 -2.187 -0.205 + KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 + KOH 3.137e-09 3.665e-09 -8.503 -8.436 0.067 +Mg 5.507e-02 + Mg+2 4.742e-02 1.371e-02 -1.324 -1.863 -0.539 + MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 + MgHCO3+ 2.195e-04 1.640e-04 -3.658 -3.785 -0.127 + MgCO3 8.913e-05 1.041e-04 -4.050 -3.982 0.067 + MgOH+ 1.084e-05 8.100e-06 -4.965 -5.092 -0.127 +Mn(2) 3.773e-09 + Mn+2 2.171e-09 4.982e-10 -8.663 -9.303 -0.639 + MnCl+ 9.582e-10 7.160e-10 -9.019 -9.145 -0.127 + MnCO3 2.696e-10 3.150e-10 -9.569 -9.502 0.067 + MnSO4 2.021e-10 2.360e-10 -9.695 -9.627 0.067 + MnCl2 9.439e-11 1.103e-10 -10.025 -9.958 0.067 + MnHCO3+ 6.077e-11 4.541e-11 -10.216 -10.343 -0.127 + MnCl3- 1.434e-11 1.071e-11 -10.844 -10.970 -0.127 + MnOH+ 2.789e-12 2.084e-12 -11.555 -11.681 -0.127 + Mn(NO3)2 1.375e-20 1.607e-20 -19.862 -19.794 0.067 +Mn(3) 5.993e-26 + Mn+3 5.993e-26 4.349e-27 -25.222 -26.362 -1.139 +N(-3) 1.724e-06 + NH4+ 1.609e-06 9.049e-07 -5.794 -6.043 -0.250 + NH3 7.326e-08 8.558e-08 -7.135 -7.068 0.067 + NH4SO4- 4.157e-08 3.106e-08 -7.381 -7.508 -0.127 +N(5) 4.847e-06 + NO3- 4.847e-06 2.846e-06 -5.314 -5.546 -0.231 + Mn(NO3)2 1.375e-20 1.607e-20 -19.862 -19.794 0.067 +Na 4.854e-01 + Na+ 4.791e-01 3.387e-01 -0.320 -0.470 -0.151 + NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 + NaHCO3 1.667e-04 1.948e-04 -3.778 -3.710 0.067 + NaCO3- 6.718e-05 5.020e-05 -4.173 -4.299 -0.127 + NaOH 3.117e-07 3.641e-07 -6.506 -6.439 0.067 +O(0) 3.746e-04 + O2 1.873e-04 2.188e-04 -3.727 -3.660 0.067 +S(6) 2.926e-02 + SO4-2 1.463e-02 2.664e-03 -1.835 -2.574 -0.740 + MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 + NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 + CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 + KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 + NH4SO4- 4.157e-08 3.106e-08 -7.381 -7.508 -0.127 + HSO4- 2.089e-09 1.561e-09 -8.680 -8.807 -0.127 + MnSO4 2.021e-10 2.360e-10 -9.695 -9.627 0.067 + CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 + FeSO4+ 1.093e-18 8.167e-19 -17.961 -18.088 -0.127 + Fe(SO4)2- 6.372e-20 4.761e-20 -19.196 -19.322 -0.127 + FeSO4 4.845e-20 5.660e-20 -19.315 -19.247 0.067 + FeHSO4+2 4.228e-26 1.318e-26 -25.374 -25.880 -0.506 + FeHSO4+ 3.000e-27 2.242e-27 -26.523 -26.649 -0.127 +Si 7.382e-05 + H4SiO4 7.110e-05 8.306e-05 -4.148 -4.081 0.067 + H3SiO4- 2.720e-06 2.032e-06 -5.565 -5.692 -0.127 + H2SiO4-2 7.362e-11 2.294e-11 -10.133 -10.639 -0.506 +U(4) 1.034e-21 + U(OH)5- 1.034e-21 7.725e-22 -20.985 -21.112 -0.127 + U(OH)4 1.652e-25 1.930e-25 -24.782 -24.715 0.067 + U+4 0.000e+00 0.000e+00 -46.997 -49.022 -2.025 +U(5) 1.622e-18 + UO2+ 1.622e-18 1.212e-18 -17.790 -17.916 -0.127 +U(6) 1.437e-08 + UO2(CO3)3-4 1.255e-08 1.184e-10 -7.901 -9.927 -2.025 + UO2(CO3)2-2 1.814e-09 5.653e-10 -8.741 -9.248 -0.506 + UO2CO3 7.429e-12 8.678e-12 -11.129 -11.062 0.067 + UO2OH+ 3.385e-14 2.530e-14 -13.470 -13.597 -0.127 + UO2+2 3.019e-16 9.409e-17 -15.520 -16.026 -0.506 + (UO2)2(OH)2+2 1.780e-21 5.547e-22 -20.750 -21.256 -0.506 + (UO2)3(OH)5+ 2.908e-23 2.173e-23 -22.536 -22.663 -0.127 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.84 -5.20 -4.36 CaSO4 + Aragonite 0.61 -7.72 -8.34 CaCO3 + Calcite 0.76 -7.72 -8.48 CaCO3 + Chalcedony -0.51 -4.06 -3.55 SiO2 + Chrysotile 3.36 35.56 32.20 Mg3Si2O5(OH)4 + CO2(g) -3.38 -4.85 -1.47 CO2 + Dolomite 2.41 -14.68 -17.09 CaMg(CO3)2 + Fe(OH)3(a) 0.19 5.08 4.89 Fe(OH)3 + Goethite 6.09 5.09 -1.00 FeOOH + Gypsum -0.63 -5.21 -4.58 CaSO4:2H2O + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.52 -0.01 1.51 H2O + Halite -2.50 -0.92 1.58 NaCl + Hausmannite 1.57 62.60 61.03 Mn3O4 + Hematite 14.20 10.19 -4.01 Fe2O3 + Jarosite-K -7.52 -16.73 -9.21 KFe3(SO4)2(OH)6 + Manganite 2.39 27.73 25.34 MnOOH + Melanterite -19.35 -21.56 -2.21 FeSO4:7H2O + NH3(g) -8.84 -7.07 1.77 NH3 + O2(g) -0.70 -3.66 -2.96 O2 + Pyrochroite -8.08 7.12 15.20 Mn(OH)2 + Pyrolusite 6.96 48.34 41.38 MnO2 + Quartz -0.08 -4.06 -3.98 SiO2 + Rhodochrosite -3.27 -14.40 -11.13 MnCO3 + Sepiolite 1.16 16.92 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -1.74 16.92 18.66 Mg2Si3O7.5OH:3H2O + Siderite -13.13 -24.02 -10.89 FeCO3 + SiO2(a) -1.35 -4.06 -2.71 SiO2 + Talc 6.04 27.44 21.40 Mg3Si4O10(OH)2 + Uraninite -12.67 -16.16 -3.49 UO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex10.log b/Sun/examples/ex10.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex10.out b/Sun/examples/ex10.out new file mode 100644 index 00000000..3b193583 --- /dev/null +++ b/Sun/examples/ex10.out @@ -0,0 +1,9431 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex10 + Output file: ex10.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 10.--Solid solution of strontianite and aragonite. + PHASES + Strontianite + SrCO3 = CO3-2 + Sr+2 + log_k -9.271 + Aragonite + CaCO3 = CO3-2 + Ca+2 + log_k -8.336 + END +----- +TITLE +----- + + Example 10.--Solid solution of strontianite and aragonite. + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLID_SOLUTIONS 1 + Ca(x)Sr(1-x)CO3 + comp1 Aragonite 0 + comp2 Strontianite 0 + gugg_nondimensional 3.43 -1.82 + END +--------------------------------------------- +Description of Solid Solution Ca(x)Sr(1-x)CO3 +--------------------------------------------- + + Temperature: 298.15 kelvin + A0 (dimensionless): 3.43 + A1 (dimensionless): -1.82 + A0 (kJ/mol): 8.50307 + A1 (kJ/mol): -4.51183 + + Critical mole-fraction of component 2: 0.297625 + Critical temperature: 703.036 kelvin + +(The critical temperature calculation assumes that the Guggenheim model +defined at 298.15 kelvin is valid at the critical temperature.) + + + Spinodal-gap mole fractions, component 2: 0.0654427 0.619798 + Miscibility-gap fractions, component 2: 0.0048032 0.857863 + + Eutectic Point Calculations + + Aqueous activity ratio (comp2/comp1): 0.0981043 + Log aqueous activity ratio (comp2/comp1): -1.00831 + Aqueous activity fraction of component 2: 0.0893397 + Log IAP (component 2): -9.34631 + Log IAP (component 1): -8.338 + Log Sum Pi: -8.29736 + +Local minimum in the solidus curve coresponding to a maximum +in the minimum stoichiometric saturation curve. + + Solid mole fraction of component 2: 0.198353 + Log IAP (component 2): -8.91133 + Log IAP (component 1): -8.30479 + Log Sum Pi: -8.20877 +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + SOLUTION 1 + units mmol/kgw + pH 5.93 charge + Ca 3.932 + C 7.864 + EQUILIBRIUM_PHASES 1 + CO2(g) -0.01265 10 + Aragonite + SAVE solution 1 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 7.864e-03 7.864e-03 + Ca 3.932e-03 3.932e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.969 Charge balance + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.105e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 7.864e-03 + Total CO2 (mol/kg) = 7.864e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.985e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 9 + Total H = 1.110200e+02 + Total O = 5.552965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.039e-06 9.312e-07 -5.983 -6.031 -0.048 + H+ 1.181e-08 1.075e-08 -7.928 -7.969 -0.041 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -75.157 -75.156 0.001 +C(4) 7.864e-03 + HCO3- 7.325e-03 6.602e-03 -2.135 -2.180 -0.045 + CaHCO3+ 2.216e-04 1.997e-04 -3.654 -3.700 -0.045 + CO2 1.592e-04 1.596e-04 -3.798 -3.797 0.001 + CaCO3 1.145e-04 1.147e-04 -3.941 -3.940 0.001 + CO3-2 4.365e-05 2.881e-05 -4.360 -4.541 -0.181 +Ca 3.932e-03 + Ca+2 3.596e-03 2.371e-03 -2.444 -2.625 -0.181 + CaHCO3+ 2.216e-04 1.997e-04 -3.654 -3.700 -0.045 + CaCO3 1.145e-04 1.147e-04 -3.941 -3.940 0.001 + CaOH+ 4.077e-08 3.661e-08 -7.390 -7.436 -0.047 +H(0) 1.632e-27 + H2 8.158e-28 8.179e-28 -27.088 -27.087 0.001 +O(0) 1.243e-38 + O2 6.213e-39 6.229e-39 -38.207 -38.206 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 1.17 -7.17 -8.34 CaCO3 + Calcite 1.31 -7.17 -8.48 CaCO3 + CH4(g) -72.30 -75.16 -2.86 CH4 + CO2(g) -2.33 -3.80 -1.47 CO2 + H2(g) -23.94 -27.09 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -35.25 -38.21 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Aragonite 0.00 -8.34 -8.34 1.000e+01 9.993e+00 -6.605e-03 + CO2(g) -0.01 -18.16 -18.15 1.000e+01 9.961e+00 -3.944e-02 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.392e-02 5.391e-02 + Ca 1.054e-02 1.054e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.063 Charge balance + pe = 11.813 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 2.906e-02 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 2.108e-02 + Total CO2 (mol/kg) = 5.392e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.292e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 10 + Total H = 1.110200e+02 + Total O = 5.562835e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.885e-07 8.654e-07 -6.005 -6.063 -0.058 + OH- 1.366e-08 1.155e-08 -7.865 -7.937 -0.073 + H2O 5.551e+01 9.989e-01 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -120.096 -120.093 0.003 +C(4) 5.392e-02 + CO2 3.285e-02 3.307e-02 -1.483 -1.481 0.003 + HCO3- 1.979e-02 1.698e-02 -1.703 -1.770 -0.067 + CaHCO3+ 1.266e-03 1.086e-03 -2.897 -2.964 -0.067 + CaCO3 7.698e-06 7.750e-06 -5.114 -5.111 0.003 + CO3-2 1.700e-06 9.199e-07 -5.770 -6.036 -0.267 +Ca 1.054e-02 + Ca+2 9.265e-03 5.015e-03 -2.033 -2.300 -0.267 + CaHCO3+ 1.266e-03 1.086e-03 -2.897 -2.964 -0.067 + CaCO3 7.698e-06 7.750e-06 -5.114 -5.111 0.003 + CaOH+ 1.128e-09 9.606e-10 -8.948 -9.017 -0.070 +H(0) 2.496e-39 + H2 1.248e-39 1.257e-39 -38.904 -38.901 0.003 +O(0) 5.234e-15 + O2 2.617e-15 2.635e-15 -14.582 -14.579 0.003 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.00 -8.34 -8.34 CaCO3 + Calcite 0.14 -8.34 -8.48 CaCO3 + CH4(g) -117.23 -120.09 -2.86 CH4 + CO2(g) -0.01 -1.48 -1.47 CO2 + H2(g) -35.75 -38.90 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -11.62 -14.58 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + USE solution 1 + USE solid_solution 1 + REACTION 1 + SrCO3 1.0 + .005 in 500 steps + PRINT + reset false + user_print true + USER_PRINT + start + 10 sum = (S_S("Strontianite") + S_S("Aragonite")) + 20 if sum = 0 THEN GOTO 110 + 30 xb = S_S("Strontianite")/sum + 40 xc = S_S("Aragonite")/sum + 50 PRINT "Simulation number: ", SIM_NO + 60 PRINT "Reaction step number: ", STEP_NO + 70 PRINT "SrCO3 added: ", RXN + 80 PRINT "Log Sigma pi: ", LOG10 (ACT("CO3-2") * (ACT("Ca+2") + ACT("Sr+2"))) + 90 PRINT "XAragonite: ", xc + 100 PRINT "XStrontianite: ", xb + 110 PRINT "XCa: ", TOT("Ca")/(TOT("Ca") + TOT("Sr")) + 120 PRINT "XSr: ", TOT("Sr")/(TOT("Ca") + TOT("Sr")) + 130 PRINT "Misc 1: ", MISC1("Ca(x)Sr(1-x)CO3") + 140 PRINT "Misc 2: ", MISC2("Ca(x)Sr(1-x)CO3") + end + SELECTED_OUTPUT + file ex10.sel + reset false + reaction true + USER_PUNCH + heading lg_SigmaPi X_Arag X_Stront X_Ca_aq X_Sr_aq mol_Misc1 mol_Misc2 mol_Arag mol_Stront + start + 10 sum = (S_S("Strontianite") + S_S("Aragonite")) + 20 if sum = 0 THEN GOTO 60 + 30 xb = S_S("Strontianite")/(S_S("Strontianite") + S_S("Aragonite")) + 40 xc = S_S("Aragonite")/(S_S("Strontianite") + S_S("Aragonite")) + 50 REM Sigma Pi + 60 PUNCH LOG10(ACT("CO3-2") * (ACT("Ca+2") + ACT("Sr+2"))) + 70 PUNCH xc # Mole fraction aragonite + 80 PUNCH xb # Mole fraction strontianite + 90 PUNCH TOT("Ca")/(TOT("Ca") + TOT("Sr")) # Mole aqueous calcium + 100 PUNCH TOT("Sr")/(TOT("Ca") + TOT("Sr")) # Mole aqueous strontium + 110 x1 = MISC1("Ca(x)Sr(1-x)CO3") + 120 x2 = MISC2("Ca(x)Sr(1-x)CO3") + 130 if (xb < x1 OR xb > x2) THEN GOTO 250 + 140 nc = S_S("Aragonite") + 150 nb = S_S("Strontianite") + 160 mol2 = ((x1 - 1)/x1)*nb + nc + 170 mol2 = mol2 / ( ((x1 -1)/x1)*x2 + (1 - x2)) + 180 mol1 = (nb - mol2*x2)/x1 + 190 REM # Moles of misc. end members if in gap + 200 PUNCH mol1 + 210 PUNCH mol2 + 220 GOTO 300 + 250 REM # Moles of misc. end members if not in gap + 260 PUNCH 1e-10 + 270 PUNCH 1e-10 + 300 PUNCH S_S("Aragonite") # Moles aragonite + 310 PUNCH S_S("Strontianite") # Moles Strontianite + end + END +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 1 +SrCO3 added: 1.0000e-05 +Log Sigma pi: -8.3356e+00 +XAragonite: 9.9996e-01 +XStrontianite: 4.2096e-05 +XCa: 9.9905e-01 +XSr: 9.4867e-04 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 2 +SrCO3 added: 2.0000e-05 +Log Sigma pi: -8.3352e+00 +XAragonite: 9.9992e-01 +XStrontianite: 8.4301e-05 +XCa: 9.9810e-01 +XSr: 1.8967e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 3 +SrCO3 added: 3.0000e-05 +Log Sigma pi: -8.3348e+00 +XAragonite: 9.9987e-01 +XStrontianite: 1.2662e-04 +XCa: 9.9716e-01 +XSr: 2.8440e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 4 +SrCO3 added: 4.0000e-05 +Log Sigma pi: -8.3345e+00 +XAragonite: 9.9983e-01 +XStrontianite: 1.6904e-04 +XCa: 9.9621e-01 +XSr: 3.7906e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 5 +SrCO3 added: 5.0000e-05 +Log Sigma pi: -8.3341e+00 +XAragonite: 9.9979e-01 +XStrontianite: 2.1158e-04 +XCa: 9.9526e-01 +XSr: 4.7366e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 6 +SrCO3 added: 6.0000e-05 +Log Sigma pi: -8.3337e+00 +XAragonite: 9.9975e-01 +XStrontianite: 2.5422e-04 +XCa: 9.9432e-01 +XSr: 5.6819e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 7 +SrCO3 added: 7.0000e-05 +Log Sigma pi: -8.3333e+00 +XAragonite: 9.9970e-01 +XStrontianite: 2.9698e-04 +XCa: 9.9337e-01 +XSr: 6.6265e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 8 +SrCO3 added: 8.0000e-05 +Log Sigma pi: -8.3329e+00 +XAragonite: 9.9966e-01 +XStrontianite: 3.3985e-04 +XCa: 9.9243e-01 +XSr: 7.5705e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 9 +SrCO3 added: 9.0000e-05 +Log Sigma pi: -8.3325e+00 +XAragonite: 9.9962e-01 +XStrontianite: 3.8284e-04 +XCa: 9.9149e-01 +XSr: 8.5137e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 10 +SrCO3 added: 1.0000e-04 +Log Sigma pi: -8.3321e+00 +XAragonite: 9.9957e-01 +XStrontianite: 4.2593e-04 +XCa: 9.9054e-01 +XSr: 9.4563e-03 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 11 +SrCO3 added: 1.1000e-04 +Log Sigma pi: -8.3318e+00 +XAragonite: 9.9953e-01 +XStrontianite: 4.6914e-04 +XCa: 9.8960e-01 +XSr: 1.0398e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 12 +SrCO3 added: 1.2000e-04 +Log Sigma pi: -8.3314e+00 +XAragonite: 9.9949e-01 +XStrontianite: 5.1247e-04 +XCa: 9.8866e-01 +XSr: 1.1340e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 13 +SrCO3 added: 1.3000e-04 +Log Sigma pi: -8.3310e+00 +XAragonite: 9.9944e-01 +XStrontianite: 5.5591e-04 +XCa: 9.8772e-01 +XSr: 1.2280e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 14 +SrCO3 added: 1.4000e-04 +Log Sigma pi: -8.3306e+00 +XAragonite: 9.9940e-01 +XStrontianite: 5.9946e-04 +XCa: 9.8678e-01 +XSr: 1.3220e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 15 +SrCO3 added: 1.5000e-04 +Log Sigma pi: -8.3302e+00 +XAragonite: 9.9936e-01 +XStrontianite: 6.4313e-04 +XCa: 9.8584e-01 +XSr: 1.4159e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 16 +SrCO3 added: 1.6000e-04 +Log Sigma pi: -8.3298e+00 +XAragonite: 9.9931e-01 +XStrontianite: 6.8692e-04 +XCa: 9.8490e-01 +XSr: 1.5098e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 17 +SrCO3 added: 1.7000e-04 +Log Sigma pi: -8.3294e+00 +XAragonite: 9.9927e-01 +XStrontianite: 7.3082e-04 +XCa: 9.8396e-01 +XSr: 1.6036e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 18 +SrCO3 added: 1.8000e-04 +Log Sigma pi: -8.3290e+00 +XAragonite: 9.9923e-01 +XStrontianite: 7.7484e-04 +XCa: 9.8303e-01 +XSr: 1.6973e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 19 +SrCO3 added: 1.9000e-04 +Log Sigma pi: -8.3287e+00 +XAragonite: 9.9918e-01 +XStrontianite: 8.1897e-04 +XCa: 9.8209e-01 +XSr: 1.7909e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 20 +SrCO3 added: 2.0000e-04 +Log Sigma pi: -8.3283e+00 +XAragonite: 9.9914e-01 +XStrontianite: 8.6323e-04 +XCa: 9.8115e-01 +XSr: 1.8845e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 21 +SrCO3 added: 2.1000e-04 +Log Sigma pi: -8.3279e+00 +XAragonite: 9.9909e-01 +XStrontianite: 9.0760e-04 +XCa: 9.8022e-01 +XSr: 1.9780e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 22 +SrCO3 added: 2.2000e-04 +Log Sigma pi: -8.3275e+00 +XAragonite: 9.9905e-01 +XStrontianite: 9.5209e-04 +XCa: 9.7929e-01 +XSr: 2.0715e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 23 +SrCO3 added: 2.3000e-04 +Log Sigma pi: -8.3271e+00 +XAragonite: 9.9900e-01 +XStrontianite: 9.9670e-04 +XCa: 9.7835e-01 +XSr: 2.1649e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 24 +SrCO3 added: 2.4000e-04 +Log Sigma pi: -8.3267e+00 +XAragonite: 9.9896e-01 +XStrontianite: 1.0414e-03 +XCa: 9.7742e-01 +XSr: 2.2582e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 25 +SrCO3 added: 2.5000e-04 +Log Sigma pi: -8.3263e+00 +XAragonite: 9.9891e-01 +XStrontianite: 1.0863e-03 +XCa: 9.7649e-01 +XSr: 2.3514e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 26 +SrCO3 added: 2.6000e-04 +Log Sigma pi: -8.3259e+00 +XAragonite: 9.9887e-01 +XStrontianite: 1.1313e-03 +XCa: 9.7555e-01 +XSr: 2.4446e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 27 +SrCO3 added: 2.7000e-04 +Log Sigma pi: -8.3256e+00 +XAragonite: 9.9882e-01 +XStrontianite: 1.1764e-03 +XCa: 9.7462e-01 +XSr: 2.5377e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 28 +SrCO3 added: 2.8000e-04 +Log Sigma pi: -8.3252e+00 +XAragonite: 9.9878e-01 +XStrontianite: 1.2216e-03 +XCa: 9.7369e-01 +XSr: 2.6308e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 29 +SrCO3 added: 2.9000e-04 +Log Sigma pi: -8.3248e+00 +XAragonite: 9.9873e-01 +XStrontianite: 1.2669e-03 +XCa: 9.7276e-01 +XSr: 2.7238e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 30 +SrCO3 added: 3.0000e-04 +Log Sigma pi: -8.3244e+00 +XAragonite: 9.9869e-01 +XStrontianite: 1.3124e-03 +XCa: 9.7183e-01 +XSr: 2.8167e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 31 +SrCO3 added: 3.1000e-04 +Log Sigma pi: -8.3240e+00 +XAragonite: 9.9864e-01 +XStrontianite: 1.3580e-03 +XCa: 9.7090e-01 +XSr: 2.9095e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 32 +SrCO3 added: 3.2000e-04 +Log Sigma pi: -8.3236e+00 +XAragonite: 9.9860e-01 +XStrontianite: 1.4037e-03 +XCa: 9.6998e-01 +XSr: 3.0023e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 33 +SrCO3 added: 3.3000e-04 +Log Sigma pi: -8.3232e+00 +XAragonite: 9.9855e-01 +XStrontianite: 1.4495e-03 +XCa: 9.6905e-01 +XSr: 3.0950e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 34 +SrCO3 added: 3.4000e-04 +Log Sigma pi: -8.3228e+00 +XAragonite: 9.9850e-01 +XStrontianite: 1.4955e-03 +XCa: 9.6812e-01 +XSr: 3.1877e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 35 +SrCO3 added: 3.5000e-04 +Log Sigma pi: -8.3225e+00 +XAragonite: 9.9846e-01 +XStrontianite: 1.5416e-03 +XCa: 9.6720e-01 +XSr: 3.2802e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 36 +SrCO3 added: 3.6000e-04 +Log Sigma pi: -8.3221e+00 +XAragonite: 9.9841e-01 +XStrontianite: 1.5878e-03 +XCa: 9.6627e-01 +XSr: 3.3727e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 37 +SrCO3 added: 3.7000e-04 +Log Sigma pi: -8.3217e+00 +XAragonite: 9.9837e-01 +XStrontianite: 1.6341e-03 +XCa: 9.6535e-01 +XSr: 3.4652e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 38 +SrCO3 added: 3.8000e-04 +Log Sigma pi: -8.3213e+00 +XAragonite: 9.9832e-01 +XStrontianite: 1.6806e-03 +XCa: 9.6442e-01 +XSr: 3.5576e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 39 +SrCO3 added: 3.9000e-04 +Log Sigma pi: -8.3209e+00 +XAragonite: 9.9827e-01 +XStrontianite: 1.7272e-03 +XCa: 9.6350e-01 +XSr: 3.6499e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 40 +SrCO3 added: 4.0000e-04 +Log Sigma pi: -8.3205e+00 +XAragonite: 9.9823e-01 +XStrontianite: 1.7739e-03 +XCa: 9.6258e-01 +XSr: 3.7421e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 41 +SrCO3 added: 4.1000e-04 +Log Sigma pi: -8.3201e+00 +XAragonite: 9.9818e-01 +XStrontianite: 1.8208e-03 +XCa: 9.6166e-01 +XSr: 3.8343e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 42 +SrCO3 added: 4.2000e-04 +Log Sigma pi: -8.3197e+00 +XAragonite: 9.9813e-01 +XStrontianite: 1.8677e-03 +XCa: 9.6074e-01 +XSr: 3.9264e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 43 +SrCO3 added: 4.3000e-04 +Log Sigma pi: -8.3193e+00 +XAragonite: 9.9809e-01 +XStrontianite: 1.9149e-03 +XCa: 9.5982e-01 +XSr: 4.0184e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 44 +SrCO3 added: 4.4000e-04 +Log Sigma pi: -8.3190e+00 +XAragonite: 9.9804e-01 +XStrontianite: 1.9621e-03 +XCa: 9.5890e-01 +XSr: 4.1104e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 45 +SrCO3 added: 4.5000e-04 +Log Sigma pi: -8.3186e+00 +XAragonite: 9.9799e-01 +XStrontianite: 2.0095e-03 +XCa: 9.5798e-01 +XSr: 4.2023e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 46 +SrCO3 added: 4.6000e-04 +Log Sigma pi: -8.3182e+00 +XAragonite: 9.9794e-01 +XStrontianite: 2.0570e-03 +XCa: 9.5706e-01 +XSr: 4.2941e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 47 +SrCO3 added: 4.7000e-04 +Log Sigma pi: -8.3178e+00 +XAragonite: 9.9790e-01 +XStrontianite: 2.1046e-03 +XCa: 9.5614e-01 +XSr: 4.3859e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 48 +SrCO3 added: 4.8000e-04 +Log Sigma pi: -8.3174e+00 +XAragonite: 9.9785e-01 +XStrontianite: 2.1524e-03 +XCa: 9.5522e-01 +XSr: 4.4776e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 49 +SrCO3 added: 4.9000e-04 +Log Sigma pi: -8.3170e+00 +XAragonite: 9.9780e-01 +XStrontianite: 2.2003e-03 +XCa: 9.5431e-01 +XSr: 4.5692e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 50 +SrCO3 added: 5.0000e-04 +Log Sigma pi: -8.3166e+00 +XAragonite: 9.9775e-01 +XStrontianite: 2.2484e-03 +XCa: 9.5339e-01 +XSr: 4.6608e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 51 +SrCO3 added: 5.1000e-04 +Log Sigma pi: -8.3162e+00 +XAragonite: 9.9770e-01 +XStrontianite: 2.2966e-03 +XCa: 9.5248e-01 +XSr: 4.7523e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 52 +SrCO3 added: 5.2000e-04 +Log Sigma pi: -8.3159e+00 +XAragonite: 9.9766e-01 +XStrontianite: 2.3449e-03 +XCa: 9.5156e-01 +XSr: 4.8437e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 53 +SrCO3 added: 5.3000e-04 +Log Sigma pi: -8.3155e+00 +XAragonite: 9.9761e-01 +XStrontianite: 2.3933e-03 +XCa: 9.5065e-01 +XSr: 4.9351e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 54 +SrCO3 added: 5.4000e-04 +Log Sigma pi: -8.3151e+00 +XAragonite: 9.9756e-01 +XStrontianite: 2.4419e-03 +XCa: 9.4974e-01 +XSr: 5.0264e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 55 +SrCO3 added: 5.5000e-04 +Log Sigma pi: -8.3147e+00 +XAragonite: 9.9751e-01 +XStrontianite: 2.4907e-03 +XCa: 9.4882e-01 +XSr: 5.1176e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 56 +SrCO3 added: 5.6000e-04 +Log Sigma pi: -8.3143e+00 +XAragonite: 9.9746e-01 +XStrontianite: 2.5395e-03 +XCa: 9.4791e-01 +XSr: 5.2088e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 57 +SrCO3 added: 5.7000e-04 +Log Sigma pi: -8.3139e+00 +XAragonite: 9.9741e-01 +XStrontianite: 2.5885e-03 +XCa: 9.4700e-01 +XSr: 5.2999e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 58 +SrCO3 added: 5.8000e-04 +Log Sigma pi: -8.3135e+00 +XAragonite: 9.9736e-01 +XStrontianite: 2.6377e-03 +XCa: 9.4609e-01 +XSr: 5.3909e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 59 +SrCO3 added: 5.9000e-04 +Log Sigma pi: -8.3131e+00 +XAragonite: 9.9731e-01 +XStrontianite: 2.6870e-03 +XCa: 9.4518e-01 +XSr: 5.4819e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 60 +SrCO3 added: 6.0000e-04 +Log Sigma pi: -8.3127e+00 +XAragonite: 9.9726e-01 +XStrontianite: 2.7364e-03 +XCa: 9.4427e-01 +XSr: 5.5728e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 61 +SrCO3 added: 6.1000e-04 +Log Sigma pi: -8.3123e+00 +XAragonite: 9.9721e-01 +XStrontianite: 2.7860e-03 +XCa: 9.4336e-01 +XSr: 5.6636e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 62 +SrCO3 added: 6.2000e-04 +Log Sigma pi: -8.3120e+00 +XAragonite: 9.9716e-01 +XStrontianite: 2.8357e-03 +XCa: 9.4246e-01 +XSr: 5.7544e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 63 +SrCO3 added: 6.3000e-04 +Log Sigma pi: -8.3116e+00 +XAragonite: 9.9711e-01 +XStrontianite: 2.8856e-03 +XCa: 9.4155e-01 +XSr: 5.8451e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 64 +SrCO3 added: 6.4000e-04 +Log Sigma pi: -8.3112e+00 +XAragonite: 9.9706e-01 +XStrontianite: 2.9356e-03 +XCa: 9.4064e-01 +XSr: 5.9357e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 65 +SrCO3 added: 6.5000e-04 +Log Sigma pi: -8.3108e+00 +XAragonite: 9.9701e-01 +XStrontianite: 2.9857e-03 +XCa: 9.3974e-01 +XSr: 6.0263e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 66 +SrCO3 added: 6.6000e-04 +Log Sigma pi: -8.3104e+00 +XAragonite: 9.9696e-01 +XStrontianite: 3.0360e-03 +XCa: 9.3883e-01 +XSr: 6.1167e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 67 +SrCO3 added: 6.7000e-04 +Log Sigma pi: -8.3100e+00 +XAragonite: 9.9691e-01 +XStrontianite: 3.0864e-03 +XCa: 9.3793e-01 +XSr: 6.2072e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 68 +SrCO3 added: 6.8000e-04 +Log Sigma pi: -8.3096e+00 +XAragonite: 9.9686e-01 +XStrontianite: 3.1370e-03 +XCa: 9.3702e-01 +XSr: 6.2975e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 69 +SrCO3 added: 6.9000e-04 +Log Sigma pi: -8.3092e+00 +XAragonite: 9.9681e-01 +XStrontianite: 3.1878e-03 +XCa: 9.3612e-01 +XSr: 6.3878e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 70 +SrCO3 added: 7.0000e-04 +Log Sigma pi: -8.3088e+00 +XAragonite: 9.9676e-01 +XStrontianite: 3.2386e-03 +XCa: 9.3522e-01 +XSr: 6.4780e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 71 +SrCO3 added: 7.1000e-04 +Log Sigma pi: -8.3084e+00 +XAragonite: 9.9671e-01 +XStrontianite: 3.2897e-03 +XCa: 9.3432e-01 +XSr: 6.5682e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 72 +SrCO3 added: 7.2000e-04 +Log Sigma pi: -8.3081e+00 +XAragonite: 9.9666e-01 +XStrontianite: 3.3409e-03 +XCa: 9.3342e-01 +XSr: 6.6583e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 73 +SrCO3 added: 7.3000e-04 +Log Sigma pi: -8.3077e+00 +XAragonite: 9.9661e-01 +XStrontianite: 3.3922e-03 +XCa: 9.3252e-01 +XSr: 6.7483e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 74 +SrCO3 added: 7.4000e-04 +Log Sigma pi: -8.3073e+00 +XAragonite: 9.9656e-01 +XStrontianite: 3.4437e-03 +XCa: 9.3162e-01 +XSr: 6.8383e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 75 +SrCO3 added: 7.5000e-04 +Log Sigma pi: -8.3069e+00 +XAragonite: 9.9650e-01 +XStrontianite: 3.4953e-03 +XCa: 9.3072e-01 +XSr: 6.9282e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 76 +SrCO3 added: 7.6000e-04 +Log Sigma pi: -8.3065e+00 +XAragonite: 9.9645e-01 +XStrontianite: 3.5471e-03 +XCa: 9.2982e-01 +XSr: 7.0180e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 77 +SrCO3 added: 7.7000e-04 +Log Sigma pi: -8.3061e+00 +XAragonite: 9.9640e-01 +XStrontianite: 3.5990e-03 +XCa: 9.2892e-01 +XSr: 7.1077e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 78 +SrCO3 added: 7.8000e-04 +Log Sigma pi: -8.3057e+00 +XAragonite: 9.9635e-01 +XStrontianite: 3.6511e-03 +XCa: 9.2803e-01 +XSr: 7.1974e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 79 +SrCO3 added: 7.9000e-04 +Log Sigma pi: -8.3053e+00 +XAragonite: 9.9630e-01 +XStrontianite: 3.7034e-03 +XCa: 9.2713e-01 +XSr: 7.2870e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 80 +SrCO3 added: 8.0000e-04 +Log Sigma pi: -8.3049e+00 +XAragonite: 9.9624e-01 +XStrontianite: 3.7558e-03 +XCa: 9.2623e-01 +XSr: 7.3766e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 81 +SrCO3 added: 8.1000e-04 +Log Sigma pi: -8.3045e+00 +XAragonite: 9.9619e-01 +XStrontianite: 3.8083e-03 +XCa: 9.2534e-01 +XSr: 7.4661e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 82 +SrCO3 added: 8.2000e-04 +Log Sigma pi: -8.3042e+00 +XAragonite: 9.9614e-01 +XStrontianite: 3.8611e-03 +XCa: 9.2445e-01 +XSr: 7.5555e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 83 +SrCO3 added: 8.3000e-04 +Log Sigma pi: -8.3038e+00 +XAragonite: 9.9609e-01 +XStrontianite: 3.9139e-03 +XCa: 9.2355e-01 +XSr: 7.6448e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 84 +SrCO3 added: 8.4000e-04 +Log Sigma pi: -8.3034e+00 +XAragonite: 9.9603e-01 +XStrontianite: 3.9670e-03 +XCa: 9.2266e-01 +XSr: 7.7341e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 85 +SrCO3 added: 8.5000e-04 +Log Sigma pi: -8.3030e+00 +XAragonite: 9.9598e-01 +XStrontianite: 4.0202e-03 +XCa: 9.2177e-01 +XSr: 7.8233e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 86 +SrCO3 added: 8.6000e-04 +Log Sigma pi: -8.3026e+00 +XAragonite: 9.9593e-01 +XStrontianite: 4.0735e-03 +XCa: 9.2088e-01 +XSr: 7.9125e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 87 +SrCO3 added: 8.7000e-04 +Log Sigma pi: -8.3022e+00 +XAragonite: 9.9587e-01 +XStrontianite: 4.1270e-03 +XCa: 9.1998e-01 +XSr: 8.0016e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 88 +SrCO3 added: 8.8000e-04 +Log Sigma pi: -8.3018e+00 +XAragonite: 9.9582e-01 +XStrontianite: 4.1807e-03 +XCa: 9.1909e-01 +XSr: 8.0906e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 89 +SrCO3 added: 8.9000e-04 +Log Sigma pi: -8.3014e+00 +XAragonite: 9.9577e-01 +XStrontianite: 4.2346e-03 +XCa: 9.1820e-01 +XSr: 8.1795e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 90 +SrCO3 added: 9.0000e-04 +Log Sigma pi: -8.3010e+00 +XAragonite: 9.9571e-01 +XStrontianite: 4.2886e-03 +XCa: 9.1732e-01 +XSr: 8.2684e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 91 +SrCO3 added: 9.1000e-04 +Log Sigma pi: -8.3006e+00 +XAragonite: 9.9566e-01 +XStrontianite: 4.3427e-03 +XCa: 9.1643e-01 +XSr: 8.3572e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 92 +SrCO3 added: 9.2000e-04 +Log Sigma pi: -8.3002e+00 +XAragonite: 9.9560e-01 +XStrontianite: 4.3971e-03 +XCa: 9.1554e-01 +XSr: 8.4460e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 93 +SrCO3 added: 9.3000e-04 +Log Sigma pi: -8.2999e+00 +XAragonite: 9.9555e-01 +XStrontianite: 4.4516e-03 +XCa: 9.1465e-01 +XSr: 8.5347e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 94 +SrCO3 added: 9.4000e-04 +Log Sigma pi: -8.2995e+00 +XAragonite: 9.9549e-01 +XStrontianite: 4.5062e-03 +XCa: 9.1377e-01 +XSr: 8.6233e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 95 +SrCO3 added: 9.5000e-04 +Log Sigma pi: -8.2991e+00 +XAragonite: 9.9544e-01 +XStrontianite: 4.5611e-03 +XCa: 9.1288e-01 +XSr: 8.7118e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 96 +SrCO3 added: 9.6000e-04 +Log Sigma pi: -8.2987e+00 +XAragonite: 9.9538e-01 +XStrontianite: 4.6161e-03 +XCa: 9.1200e-01 +XSr: 8.8003e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 97 +SrCO3 added: 9.7000e-04 +Log Sigma pi: -8.2983e+00 +XAragonite: 9.9533e-01 +XStrontianite: 4.6713e-03 +XCa: 9.1111e-01 +XSr: 8.8887e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 98 +SrCO3 added: 9.8000e-04 +Log Sigma pi: -8.2979e+00 +XAragonite: 9.9527e-01 +XStrontianite: 4.7266e-03 +XCa: 9.1023e-01 +XSr: 8.9770e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 99 +SrCO3 added: 9.9000e-04 +Log Sigma pi: -8.2975e+00 +XAragonite: 9.9522e-01 +XStrontianite: 4.7821e-03 +XCa: 9.0935e-01 +XSr: 9.0653e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 100 +SrCO3 added: 1.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.8567e-01 +XStrontianite: 1.4329e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 101 +SrCO3 added: 1.0100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.7071e-01 +XStrontianite: 2.9286e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 102 +SrCO3 added: 1.0200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.5620e-01 +XStrontianite: 4.3796e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 103 +SrCO3 added: 1.0300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.4212e-01 +XStrontianite: 5.7879e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 104 +SrCO3 added: 1.0400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.2845e-01 +XStrontianite: 7.1552e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 105 +SrCO3 added: 1.0500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.1516e-01 +XStrontianite: 8.4835e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 106 +SrCO3 added: 1.0600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.0226e-01 +XStrontianite: 9.7743e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 107 +SrCO3 added: 1.0700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.8971e-01 +XStrontianite: 1.1029e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 108 +SrCO3 added: 1.0800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.7750e-01 +XStrontianite: 1.2250e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 109 +SrCO3 added: 1.0900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.6563e-01 +XStrontianite: 1.3437e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 110 +SrCO3 added: 1.1000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.5407e-01 +XStrontianite: 1.4593e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 111 +SrCO3 added: 1.1100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.4282e-01 +XStrontianite: 1.5718e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 112 +SrCO3 added: 1.1200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.3186e-01 +XStrontianite: 1.6814e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 113 +SrCO3 added: 1.1300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.2118e-01 +XStrontianite: 1.7882e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 114 +SrCO3 added: 1.1400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.1077e-01 +XStrontianite: 1.8923e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 115 +SrCO3 added: 1.1500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 8.0063e-01 +XStrontianite: 1.9937e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 116 +SrCO3 added: 1.1600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.9073e-01 +XStrontianite: 2.0927e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 117 +SrCO3 added: 1.1700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.8107e-01 +XStrontianite: 2.1893e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 118 +SrCO3 added: 1.1800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.7165e-01 +XStrontianite: 2.2835e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 119 +SrCO3 added: 1.1900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.6246e-01 +XStrontianite: 2.3754e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 120 +SrCO3 added: 1.2000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.5348e-01 +XStrontianite: 2.4652e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 121 +SrCO3 added: 1.2100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.4470e-01 +XStrontianite: 2.5530e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 122 +SrCO3 added: 1.2200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.3613e-01 +XStrontianite: 2.6387e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 123 +SrCO3 added: 1.2300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.2776e-01 +XStrontianite: 2.7224e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 124 +SrCO3 added: 1.2400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.1957e-01 +XStrontianite: 2.8043e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 125 +SrCO3 added: 1.2500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.1157e-01 +XStrontianite: 2.8843e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 126 +SrCO3 added: 1.2600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 7.0374e-01 +XStrontianite: 2.9626e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 127 +SrCO3 added: 1.2700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.9608e-01 +XStrontianite: 3.0392e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 128 +SrCO3 added: 1.2800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.8859e-01 +XStrontianite: 3.1141e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 129 +SrCO3 added: 1.2900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.8126e-01 +XStrontianite: 3.1874e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 130 +SrCO3 added: 1.3000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.7408e-01 +XStrontianite: 3.2592e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 131 +SrCO3 added: 1.3100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.6705e-01 +XStrontianite: 3.3295e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 132 +SrCO3 added: 1.3200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.6017e-01 +XStrontianite: 3.3983e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 133 +SrCO3 added: 1.3300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.5342e-01 +XStrontianite: 3.4658e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 134 +SrCO3 added: 1.3400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.4682e-01 +XStrontianite: 3.5318e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 135 +SrCO3 added: 1.3500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.4034e-01 +XStrontianite: 3.5966e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 136 +SrCO3 added: 1.3600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.3399e-01 +XStrontianite: 3.6601e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 137 +SrCO3 added: 1.3700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.2777e-01 +XStrontianite: 3.7223e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 138 +SrCO3 added: 1.3800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.2167e-01 +XStrontianite: 3.7833e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 139 +SrCO3 added: 1.3900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.1569e-01 +XStrontianite: 3.8431e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 140 +SrCO3 added: 1.4000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.0982e-01 +XStrontianite: 3.9018e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 141 +SrCO3 added: 1.4100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 6.0406e-01 +XStrontianite: 3.9594e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 142 +SrCO3 added: 1.4200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.9841e-01 +XStrontianite: 4.0159e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 143 +SrCO3 added: 1.4300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.9286e-01 +XStrontianite: 4.0714e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 144 +SrCO3 added: 1.4400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.8742e-01 +XStrontianite: 4.1258e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 145 +SrCO3 added: 1.4500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.8207e-01 +XStrontianite: 4.1793e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 146 +SrCO3 added: 1.4600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.7683e-01 +XStrontianite: 4.2317e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 147 +SrCO3 added: 1.4700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.7167e-01 +XStrontianite: 4.2833e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 148 +SrCO3 added: 1.4800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.6661e-01 +XStrontianite: 4.3339e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 149 +SrCO3 added: 1.4900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.6163e-01 +XStrontianite: 4.3837e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 150 +SrCO3 added: 1.5000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.5675e-01 +XStrontianite: 4.4325e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 151 +SrCO3 added: 1.5100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.5194e-01 +XStrontianite: 4.4806e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 152 +SrCO3 added: 1.5200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.4722e-01 +XStrontianite: 4.5278e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 153 +SrCO3 added: 1.5300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.4258e-01 +XStrontianite: 4.5742e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 154 +SrCO3 added: 1.5400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.3802e-01 +XStrontianite: 4.6198e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 155 +SrCO3 added: 1.5500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.3353e-01 +XStrontianite: 4.6647e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 156 +SrCO3 added: 1.5600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.2912e-01 +XStrontianite: 4.7088e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 157 +SrCO3 added: 1.5700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.2477e-01 +XStrontianite: 4.7523e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 158 +SrCO3 added: 1.5800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.2050e-01 +XStrontianite: 4.7950e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 159 +SrCO3 added: 1.5900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.1630e-01 +XStrontianite: 4.8370e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 160 +SrCO3 added: 1.6000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.1217e-01 +XStrontianite: 4.8783e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 161 +SrCO3 added: 1.6100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.0810e-01 +XStrontianite: 4.9190e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 162 +SrCO3 added: 1.6200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.0410e-01 +XStrontianite: 4.9590e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 163 +SrCO3 added: 1.6300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 5.0016e-01 +XStrontianite: 4.9984e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 164 +SrCO3 added: 1.6400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.9628e-01 +XStrontianite: 5.0372e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 165 +SrCO3 added: 1.6500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.9246e-01 +XStrontianite: 5.0754e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 166 +SrCO3 added: 1.6600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.8869e-01 +XStrontianite: 5.1131e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 167 +SrCO3 added: 1.6700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.8499e-01 +XStrontianite: 5.1501e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 168 +SrCO3 added: 1.6800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.8134e-01 +XStrontianite: 5.1866e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 169 +SrCO3 added: 1.6900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.7774e-01 +XStrontianite: 5.2226e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 170 +SrCO3 added: 1.7000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.7420e-01 +XStrontianite: 5.2580e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 171 +SrCO3 added: 1.7100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.7071e-01 +XStrontianite: 5.2929e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 172 +SrCO3 added: 1.7200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.6728e-01 +XStrontianite: 5.3272e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 173 +SrCO3 added: 1.7300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.6389e-01 +XStrontianite: 5.3611e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 174 +SrCO3 added: 1.7400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.6055e-01 +XStrontianite: 5.3945e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 175 +SrCO3 added: 1.7500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.5726e-01 +XStrontianite: 5.4274e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 176 +SrCO3 added: 1.7600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.5401e-01 +XStrontianite: 5.4599e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 177 +SrCO3 added: 1.7700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.5081e-01 +XStrontianite: 5.4919e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 178 +SrCO3 added: 1.7800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.4766e-01 +XStrontianite: 5.5234e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 179 +SrCO3 added: 1.7900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.4455e-01 +XStrontianite: 5.5545e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 180 +SrCO3 added: 1.8000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.4148e-01 +XStrontianite: 5.5852e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 181 +SrCO3 added: 1.8100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.3845e-01 +XStrontianite: 5.6155e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 182 +SrCO3 added: 1.8200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.3547e-01 +XStrontianite: 5.6453e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 183 +SrCO3 added: 1.8300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.3252e-01 +XStrontianite: 5.6748e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 184 +SrCO3 added: 1.8400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.2962e-01 +XStrontianite: 5.7038e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 185 +SrCO3 added: 1.8500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.2675e-01 +XStrontianite: 5.7325e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 186 +SrCO3 added: 1.8600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.2392e-01 +XStrontianite: 5.7608e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 187 +SrCO3 added: 1.8700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.2113e-01 +XStrontianite: 5.7887e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 188 +SrCO3 added: 1.8800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.1838e-01 +XStrontianite: 5.8162e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 189 +SrCO3 added: 1.8900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.1566e-01 +XStrontianite: 5.8434e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 190 +SrCO3 added: 1.9000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.1298e-01 +XStrontianite: 5.8702e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 191 +SrCO3 added: 1.9100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.1033e-01 +XStrontianite: 5.8967e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 192 +SrCO3 added: 1.9200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.0771e-01 +XStrontianite: 5.9229e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 193 +SrCO3 added: 1.9300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.0513e-01 +XStrontianite: 5.9487e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 194 +SrCO3 added: 1.9400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.0258e-01 +XStrontianite: 5.9742e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 195 +SrCO3 added: 1.9500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 4.0006e-01 +XStrontianite: 5.9994e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 196 +SrCO3 added: 1.9600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.9758e-01 +XStrontianite: 6.0242e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 197 +SrCO3 added: 1.9700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.9512e-01 +XStrontianite: 6.0488e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 198 +SrCO3 added: 1.9800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.9270e-01 +XStrontianite: 6.0730e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 199 +SrCO3 added: 1.9900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.9030e-01 +XStrontianite: 6.0970e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 200 +SrCO3 added: 2.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.8793e-01 +XStrontianite: 6.1207e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 201 +SrCO3 added: 2.0100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.8559e-01 +XStrontianite: 6.1441e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 202 +SrCO3 added: 2.0200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.8328e-01 +XStrontianite: 6.1672e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 203 +SrCO3 added: 2.0300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.8100e-01 +XStrontianite: 6.1900e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 204 +SrCO3 added: 2.0400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.7875e-01 +XStrontianite: 6.2125e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 205 +SrCO3 added: 2.0500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.7652e-01 +XStrontianite: 6.2348e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 206 +SrCO3 added: 2.0600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.7431e-01 +XStrontianite: 6.2569e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 207 +SrCO3 added: 2.0700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.7214e-01 +XStrontianite: 6.2786e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 208 +SrCO3 added: 2.0800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.6998e-01 +XStrontianite: 6.3002e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 209 +SrCO3 added: 2.0900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.6786e-01 +XStrontianite: 6.3214e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 210 +SrCO3 added: 2.1000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.6575e-01 +XStrontianite: 6.3425e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 211 +SrCO3 added: 2.1100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.6367e-01 +XStrontianite: 6.3633e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 212 +SrCO3 added: 2.1200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.6162e-01 +XStrontianite: 6.3838e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 213 +SrCO3 added: 2.1300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.5958e-01 +XStrontianite: 6.4042e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 214 +SrCO3 added: 2.1400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.5757e-01 +XStrontianite: 6.4243e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 215 +SrCO3 added: 2.1500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.5559e-01 +XStrontianite: 6.4441e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 216 +SrCO3 added: 2.1600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.5362e-01 +XStrontianite: 6.4638e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 217 +SrCO3 added: 2.1700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.5168e-01 +XStrontianite: 6.4832e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 218 +SrCO3 added: 2.1800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4975e-01 +XStrontianite: 6.5025e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 219 +SrCO3 added: 2.1900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4785e-01 +XStrontianite: 6.5215e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 220 +SrCO3 added: 2.2000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4597e-01 +XStrontianite: 6.5403e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 221 +SrCO3 added: 2.2100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4411e-01 +XStrontianite: 6.5589e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 222 +SrCO3 added: 2.2200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4227e-01 +XStrontianite: 6.5773e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 223 +SrCO3 added: 2.2300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.4045e-01 +XStrontianite: 6.5955e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 224 +SrCO3 added: 2.2400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.3864e-01 +XStrontianite: 6.6136e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 225 +SrCO3 added: 2.2500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.3686e-01 +XStrontianite: 6.6314e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 226 +SrCO3 added: 2.2600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.3510e-01 +XStrontianite: 6.6490e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 227 +SrCO3 added: 2.2700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.3335e-01 +XStrontianite: 6.6665e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 228 +SrCO3 added: 2.2800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.3162e-01 +XStrontianite: 6.6838e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 229 +SrCO3 added: 2.2900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2991e-01 +XStrontianite: 6.7009e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 230 +SrCO3 added: 2.3000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2822e-01 +XStrontianite: 6.7178e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 231 +SrCO3 added: 2.3100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2654e-01 +XStrontianite: 6.7346e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 232 +SrCO3 added: 2.3200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2489e-01 +XStrontianite: 6.7511e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 233 +SrCO3 added: 2.3300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2324e-01 +XStrontianite: 6.7676e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 234 +SrCO3 added: 2.3400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2162e-01 +XStrontianite: 6.7838e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 235 +SrCO3 added: 2.3500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.2001e-01 +XStrontianite: 6.7999e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 236 +SrCO3 added: 2.3600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1842e-01 +XStrontianite: 6.8158e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 237 +SrCO3 added: 2.3700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1684e-01 +XStrontianite: 6.8316e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 238 +SrCO3 added: 2.3800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1528e-01 +XStrontianite: 6.8472e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 239 +SrCO3 added: 2.3900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1373e-01 +XStrontianite: 6.8627e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 240 +SrCO3 added: 2.4000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1220e-01 +XStrontianite: 6.8780e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 241 +SrCO3 added: 2.4100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.1068e-01 +XStrontianite: 6.8932e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 242 +SrCO3 added: 2.4200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0918e-01 +XStrontianite: 6.9082e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 243 +SrCO3 added: 2.4300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0770e-01 +XStrontianite: 6.9230e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 244 +SrCO3 added: 2.4400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0622e-01 +XStrontianite: 6.9378e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 245 +SrCO3 added: 2.4500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0476e-01 +XStrontianite: 6.9524e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 246 +SrCO3 added: 2.4600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0332e-01 +XStrontianite: 6.9668e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 247 +SrCO3 added: 2.4700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0189e-01 +XStrontianite: 6.9811e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 248 +SrCO3 added: 2.4800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.0047e-01 +XStrontianite: 6.9953e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 249 +SrCO3 added: 2.4900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9907e-01 +XStrontianite: 7.0093e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 250 +SrCO3 added: 2.5000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9767e-01 +XStrontianite: 7.0233e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 251 +SrCO3 added: 2.5100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9629e-01 +XStrontianite: 7.0371e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 252 +SrCO3 added: 2.5200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9493e-01 +XStrontianite: 7.0507e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 253 +SrCO3 added: 2.5300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9358e-01 +XStrontianite: 7.0642e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 254 +SrCO3 added: 2.5400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9223e-01 +XStrontianite: 7.0777e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 255 +SrCO3 added: 2.5500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.9091e-01 +XStrontianite: 7.0909e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 256 +SrCO3 added: 2.5600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8959e-01 +XStrontianite: 7.1041e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 257 +SrCO3 added: 2.5700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8828e-01 +XStrontianite: 7.1172e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 258 +SrCO3 added: 2.5800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8699e-01 +XStrontianite: 7.1301e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 259 +SrCO3 added: 2.5900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8571e-01 +XStrontianite: 7.1429e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 260 +SrCO3 added: 2.6000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8444e-01 +XStrontianite: 7.1556e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 261 +SrCO3 added: 2.6100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8318e-01 +XStrontianite: 7.1682e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 262 +SrCO3 added: 2.6200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8193e-01 +XStrontianite: 7.1807e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 263 +SrCO3 added: 2.6300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.8069e-01 +XStrontianite: 7.1931e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 264 +SrCO3 added: 2.6400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7947e-01 +XStrontianite: 7.2053e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 265 +SrCO3 added: 2.6500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7825e-01 +XStrontianite: 7.2175e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 266 +SrCO3 added: 2.6600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7705e-01 +XStrontianite: 7.2295e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 267 +SrCO3 added: 2.6700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7585e-01 +XStrontianite: 7.2415e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 268 +SrCO3 added: 2.6800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7467e-01 +XStrontianite: 7.2533e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 269 +SrCO3 added: 2.6900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7349e-01 +XStrontianite: 7.2651e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 270 +SrCO3 added: 2.7000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7233e-01 +XStrontianite: 7.2767e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 271 +SrCO3 added: 2.7100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7117e-01 +XStrontianite: 7.2883e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 272 +SrCO3 added: 2.7200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.7003e-01 +XStrontianite: 7.2997e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 273 +SrCO3 added: 2.7300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6889e-01 +XStrontianite: 7.3111e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 274 +SrCO3 added: 2.7400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6777e-01 +XStrontianite: 7.3223e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 275 +SrCO3 added: 2.7500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6665e-01 +XStrontianite: 7.3335e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 276 +SrCO3 added: 2.7600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6555e-01 +XStrontianite: 7.3445e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 277 +SrCO3 added: 2.7700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6445e-01 +XStrontianite: 7.3555e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 278 +SrCO3 added: 2.7800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6336e-01 +XStrontianite: 7.3664e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 279 +SrCO3 added: 2.7900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6228e-01 +XStrontianite: 7.3772e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 280 +SrCO3 added: 2.8000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6121e-01 +XStrontianite: 7.3879e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 281 +SrCO3 added: 2.8100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.6015e-01 +XStrontianite: 7.3985e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 282 +SrCO3 added: 2.8200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5909e-01 +XStrontianite: 7.4091e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 283 +SrCO3 added: 2.8300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5805e-01 +XStrontianite: 7.4195e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 284 +SrCO3 added: 2.8400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5701e-01 +XStrontianite: 7.4299e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 285 +SrCO3 added: 2.8500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5598e-01 +XStrontianite: 7.4402e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 286 +SrCO3 added: 2.8600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5496e-01 +XStrontianite: 7.4504e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 287 +SrCO3 added: 2.8700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5395e-01 +XStrontianite: 7.4605e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 288 +SrCO3 added: 2.8800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5295e-01 +XStrontianite: 7.4705e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 289 +SrCO3 added: 2.8900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5195e-01 +XStrontianite: 7.4805e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 290 +SrCO3 added: 2.9000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.5096e-01 +XStrontianite: 7.4904e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 291 +SrCO3 added: 2.9100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4998e-01 +XStrontianite: 7.5002e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 292 +SrCO3 added: 2.9200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4901e-01 +XStrontianite: 7.5099e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 293 +SrCO3 added: 2.9300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4804e-01 +XStrontianite: 7.5196e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 294 +SrCO3 added: 2.9400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4708e-01 +XStrontianite: 7.5292e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 295 +SrCO3 added: 2.9500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4613e-01 +XStrontianite: 7.5387e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 296 +SrCO3 added: 2.9600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4519e-01 +XStrontianite: 7.5481e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 297 +SrCO3 added: 2.9700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4425e-01 +XStrontianite: 7.5575e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 298 +SrCO3 added: 2.9800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4332e-01 +XStrontianite: 7.5668e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 299 +SrCO3 added: 2.9900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4240e-01 +XStrontianite: 7.5760e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 300 +SrCO3 added: 3.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4149e-01 +XStrontianite: 7.5851e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 301 +SrCO3 added: 3.0100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4058e-01 +XStrontianite: 7.5942e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 302 +SrCO3 added: 3.0200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3968e-01 +XStrontianite: 7.6032e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 303 +SrCO3 added: 3.0300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3878e-01 +XStrontianite: 7.6122e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 304 +SrCO3 added: 3.0400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3790e-01 +XStrontianite: 7.6210e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 305 +SrCO3 added: 3.0500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3701e-01 +XStrontianite: 7.6299e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 306 +SrCO3 added: 3.0600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3614e-01 +XStrontianite: 7.6386e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 307 +SrCO3 added: 3.0700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3527e-01 +XStrontianite: 7.6473e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 308 +SrCO3 added: 3.0800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3441e-01 +XStrontianite: 7.6559e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 309 +SrCO3 added: 3.0900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3355e-01 +XStrontianite: 7.6645e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 310 +SrCO3 added: 3.1000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3270e-01 +XStrontianite: 7.6730e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 311 +SrCO3 added: 3.1100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3186e-01 +XStrontianite: 7.6814e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 312 +SrCO3 added: 3.1200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3102e-01 +XStrontianite: 7.6898e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 313 +SrCO3 added: 3.1300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.3019e-01 +XStrontianite: 7.6981e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 314 +SrCO3 added: 3.1400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2937e-01 +XStrontianite: 7.7063e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 315 +SrCO3 added: 3.1500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2855e-01 +XStrontianite: 7.7145e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 316 +SrCO3 added: 3.1600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2773e-01 +XStrontianite: 7.7227e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 317 +SrCO3 added: 3.1700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2692e-01 +XStrontianite: 7.7308e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 318 +SrCO3 added: 3.1800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2612e-01 +XStrontianite: 7.7388e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 319 +SrCO3 added: 3.1900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2533e-01 +XStrontianite: 7.7467e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 320 +SrCO3 added: 3.2000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2454e-01 +XStrontianite: 7.7546e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 321 +SrCO3 added: 3.2100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2375e-01 +XStrontianite: 7.7625e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 322 +SrCO3 added: 3.2200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2297e-01 +XStrontianite: 7.7703e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 323 +SrCO3 added: 3.2300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2220e-01 +XStrontianite: 7.7780e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 324 +SrCO3 added: 3.2400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2143e-01 +XStrontianite: 7.7857e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 325 +SrCO3 added: 3.2500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.2066e-01 +XStrontianite: 7.7934e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 326 +SrCO3 added: 3.2600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1990e-01 +XStrontianite: 7.8010e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 327 +SrCO3 added: 3.2700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1915e-01 +XStrontianite: 7.8085e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 328 +SrCO3 added: 3.2800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1840e-01 +XStrontianite: 7.8160e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 329 +SrCO3 added: 3.2900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1766e-01 +XStrontianite: 7.8234e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 330 +SrCO3 added: 3.3000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1692e-01 +XStrontianite: 7.8308e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 331 +SrCO3 added: 3.3100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1619e-01 +XStrontianite: 7.8381e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 332 +SrCO3 added: 3.3200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1546e-01 +XStrontianite: 7.8454e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 333 +SrCO3 added: 3.3300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1474e-01 +XStrontianite: 7.8526e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 334 +SrCO3 added: 3.3400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1402e-01 +XStrontianite: 7.8598e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 335 +SrCO3 added: 3.3500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1330e-01 +XStrontianite: 7.8670e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 336 +SrCO3 added: 3.3600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1260e-01 +XStrontianite: 7.8740e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 337 +SrCO3 added: 3.3700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1189e-01 +XStrontianite: 7.8811e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 338 +SrCO3 added: 3.3800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1119e-01 +XStrontianite: 7.8881e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 339 +SrCO3 added: 3.3900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.1050e-01 +XStrontianite: 7.8950e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 340 +SrCO3 added: 3.4000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0981e-01 +XStrontianite: 7.9019e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 341 +SrCO3 added: 3.4100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0912e-01 +XStrontianite: 7.9088e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 342 +SrCO3 added: 3.4200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0844e-01 +XStrontianite: 7.9156e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 343 +SrCO3 added: 3.4300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0776e-01 +XStrontianite: 7.9224e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 344 +SrCO3 added: 3.4400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0709e-01 +XStrontianite: 7.9291e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 345 +SrCO3 added: 3.4500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0642e-01 +XStrontianite: 7.9358e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 346 +SrCO3 added: 3.4600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0576e-01 +XStrontianite: 7.9424e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 347 +SrCO3 added: 3.4700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0510e-01 +XStrontianite: 7.9490e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 348 +SrCO3 added: 3.4800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0444e-01 +XStrontianite: 7.9556e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 349 +SrCO3 added: 3.4900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0379e-01 +XStrontianite: 7.9621e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 350 +SrCO3 added: 3.5000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0314e-01 +XStrontianite: 7.9686e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 351 +SrCO3 added: 3.5100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0250e-01 +XStrontianite: 7.9750e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 352 +SrCO3 added: 3.5200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0186e-01 +XStrontianite: 7.9814e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 353 +SrCO3 added: 3.5300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0123e-01 +XStrontianite: 7.9877e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 354 +SrCO3 added: 3.5400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.0060e-01 +XStrontianite: 7.9940e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 355 +SrCO3 added: 3.5500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9997e-01 +XStrontianite: 8.0003e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 356 +SrCO3 added: 3.5600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9935e-01 +XStrontianite: 8.0065e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 357 +SrCO3 added: 3.5700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9873e-01 +XStrontianite: 8.0127e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 358 +SrCO3 added: 3.5800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9811e-01 +XStrontianite: 8.0189e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 359 +SrCO3 added: 3.5900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9750e-01 +XStrontianite: 8.0250e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 360 +SrCO3 added: 3.6000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9689e-01 +XStrontianite: 8.0311e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 361 +SrCO3 added: 3.6100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9629e-01 +XStrontianite: 8.0371e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 362 +SrCO3 added: 3.6200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9569e-01 +XStrontianite: 8.0431e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 363 +SrCO3 added: 3.6300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9509e-01 +XStrontianite: 8.0491e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 364 +SrCO3 added: 3.6400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9450e-01 +XStrontianite: 8.0550e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 365 +SrCO3 added: 3.6500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9391e-01 +XStrontianite: 8.0609e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 366 +SrCO3 added: 3.6600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9332e-01 +XStrontianite: 8.0668e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 367 +SrCO3 added: 3.6700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9274e-01 +XStrontianite: 8.0726e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 368 +SrCO3 added: 3.6800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9216e-01 +XStrontianite: 8.0784e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 369 +SrCO3 added: 3.6900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9158e-01 +XStrontianite: 8.0842e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 370 +SrCO3 added: 3.7000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9101e-01 +XStrontianite: 8.0899e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 371 +SrCO3 added: 3.7100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.9044e-01 +XStrontianite: 8.0956e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 372 +SrCO3 added: 3.7200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8988e-01 +XStrontianite: 8.1012e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 373 +SrCO3 added: 3.7300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8932e-01 +XStrontianite: 8.1068e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 374 +SrCO3 added: 3.7400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8876e-01 +XStrontianite: 8.1124e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 375 +SrCO3 added: 3.7500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8820e-01 +XStrontianite: 8.1180e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 376 +SrCO3 added: 3.7600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8765e-01 +XStrontianite: 8.1235e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 377 +SrCO3 added: 3.7700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8710e-01 +XStrontianite: 8.1290e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 378 +SrCO3 added: 3.7800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8656e-01 +XStrontianite: 8.1344e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 379 +SrCO3 added: 3.7900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8601e-01 +XStrontianite: 8.1399e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 380 +SrCO3 added: 3.8000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8547e-01 +XStrontianite: 8.1453e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 381 +SrCO3 added: 3.8100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8494e-01 +XStrontianite: 8.1506e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 382 +SrCO3 added: 3.8200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8440e-01 +XStrontianite: 8.1560e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 383 +SrCO3 added: 3.8300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8387e-01 +XStrontianite: 8.1613e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 384 +SrCO3 added: 3.8400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8335e-01 +XStrontianite: 8.1665e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 385 +SrCO3 added: 3.8500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8282e-01 +XStrontianite: 8.1718e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 386 +SrCO3 added: 3.8600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8230e-01 +XStrontianite: 8.1770e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 387 +SrCO3 added: 3.8700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8178e-01 +XStrontianite: 8.1822e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 388 +SrCO3 added: 3.8800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8127e-01 +XStrontianite: 8.1873e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 389 +SrCO3 added: 3.8900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8076e-01 +XStrontianite: 8.1924e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 390 +SrCO3 added: 3.9000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.8025e-01 +XStrontianite: 8.1975e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 391 +SrCO3 added: 3.9100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7974e-01 +XStrontianite: 8.2026e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 392 +SrCO3 added: 3.9200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7924e-01 +XStrontianite: 8.2076e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 393 +SrCO3 added: 3.9300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7874e-01 +XStrontianite: 8.2126e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 394 +SrCO3 added: 3.9400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7824e-01 +XStrontianite: 8.2176e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 395 +SrCO3 added: 3.9500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7774e-01 +XStrontianite: 8.2226e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 396 +SrCO3 added: 3.9600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7725e-01 +XStrontianite: 8.2275e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 397 +SrCO3 added: 3.9700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7676e-01 +XStrontianite: 8.2324e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 398 +SrCO3 added: 3.9800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7627e-01 +XStrontianite: 8.2373e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 399 +SrCO3 added: 3.9900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7579e-01 +XStrontianite: 8.2421e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 400 +SrCO3 added: 4.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7531e-01 +XStrontianite: 8.2469e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 401 +SrCO3 added: 4.0100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7483e-01 +XStrontianite: 8.2517e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 402 +SrCO3 added: 4.0200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7435e-01 +XStrontianite: 8.2565e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 403 +SrCO3 added: 4.0300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7388e-01 +XStrontianite: 8.2612e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 404 +SrCO3 added: 4.0400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7341e-01 +XStrontianite: 8.2659e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 405 +SrCO3 added: 4.0500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7294e-01 +XStrontianite: 8.2706e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 406 +SrCO3 added: 4.0600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7247e-01 +XStrontianite: 8.2753e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 407 +SrCO3 added: 4.0700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7201e-01 +XStrontianite: 8.2799e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 408 +SrCO3 added: 4.0800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7155e-01 +XStrontianite: 8.2845e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 409 +SrCO3 added: 4.0900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7109e-01 +XStrontianite: 8.2891e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 410 +SrCO3 added: 4.1000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7063e-01 +XStrontianite: 8.2937e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 411 +SrCO3 added: 4.1100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7018e-01 +XStrontianite: 8.2982e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 412 +SrCO3 added: 4.1200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6973e-01 +XStrontianite: 8.3027e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 413 +SrCO3 added: 4.1300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6928e-01 +XStrontianite: 8.3072e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 414 +SrCO3 added: 4.1400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6883e-01 +XStrontianite: 8.3117e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 415 +SrCO3 added: 4.1500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6839e-01 +XStrontianite: 8.3161e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 416 +SrCO3 added: 4.1600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6794e-01 +XStrontianite: 8.3206e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 417 +SrCO3 added: 4.1700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6750e-01 +XStrontianite: 8.3250e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 418 +SrCO3 added: 4.1800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6707e-01 +XStrontianite: 8.3293e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 419 +SrCO3 added: 4.1900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6663e-01 +XStrontianite: 8.3337e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 420 +SrCO3 added: 4.2000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6620e-01 +XStrontianite: 8.3380e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 421 +SrCO3 added: 4.2100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6577e-01 +XStrontianite: 8.3423e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 422 +SrCO3 added: 4.2200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6534e-01 +XStrontianite: 8.3466e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 423 +SrCO3 added: 4.2300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6491e-01 +XStrontianite: 8.3509e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 424 +SrCO3 added: 4.2400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6449e-01 +XStrontianite: 8.3551e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 425 +SrCO3 added: 4.2500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6407e-01 +XStrontianite: 8.3593e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 426 +SrCO3 added: 4.2600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6365e-01 +XStrontianite: 8.3635e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 427 +SrCO3 added: 4.2700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6323e-01 +XStrontianite: 8.3677e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 428 +SrCO3 added: 4.2800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6282e-01 +XStrontianite: 8.3718e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 429 +SrCO3 added: 4.2900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6240e-01 +XStrontianite: 8.3760e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 430 +SrCO3 added: 4.3000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6199e-01 +XStrontianite: 8.3801e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 431 +SrCO3 added: 4.3100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6158e-01 +XStrontianite: 8.3842e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 432 +SrCO3 added: 4.3200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6117e-01 +XStrontianite: 8.3883e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 433 +SrCO3 added: 4.3300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6077e-01 +XStrontianite: 8.3923e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 434 +SrCO3 added: 4.3400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.6037e-01 +XStrontianite: 8.3963e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 435 +SrCO3 added: 4.3500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5997e-01 +XStrontianite: 8.4003e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 436 +SrCO3 added: 4.3600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5957e-01 +XStrontianite: 8.4043e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 437 +SrCO3 added: 4.3700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5917e-01 +XStrontianite: 8.4083e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 438 +SrCO3 added: 4.3800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5877e-01 +XStrontianite: 8.4123e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 439 +SrCO3 added: 4.3900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5838e-01 +XStrontianite: 8.4162e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 440 +SrCO3 added: 4.4000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5799e-01 +XStrontianite: 8.4201e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 441 +SrCO3 added: 4.4100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5760e-01 +XStrontianite: 8.4240e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 442 +SrCO3 added: 4.4200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5721e-01 +XStrontianite: 8.4279e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 443 +SrCO3 added: 4.4300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5683e-01 +XStrontianite: 8.4317e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 444 +SrCO3 added: 4.4400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5644e-01 +XStrontianite: 8.4356e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 445 +SrCO3 added: 4.4500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5606e-01 +XStrontianite: 8.4394e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 446 +SrCO3 added: 4.4600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5568e-01 +XStrontianite: 8.4432e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 447 +SrCO3 added: 4.4700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5530e-01 +XStrontianite: 8.4470e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 448 +SrCO3 added: 4.4800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5493e-01 +XStrontianite: 8.4507e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 449 +SrCO3 added: 4.4900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5455e-01 +XStrontianite: 8.4545e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 450 +SrCO3 added: 4.5000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5418e-01 +XStrontianite: 8.4582e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 451 +SrCO3 added: 4.5100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5381e-01 +XStrontianite: 8.4619e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 452 +SrCO3 added: 4.5200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5344e-01 +XStrontianite: 8.4656e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 453 +SrCO3 added: 4.5300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5307e-01 +XStrontianite: 8.4693e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 454 +SrCO3 added: 4.5400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5271e-01 +XStrontianite: 8.4729e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 455 +SrCO3 added: 4.5500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5235e-01 +XStrontianite: 8.4765e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 456 +SrCO3 added: 4.5600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5198e-01 +XStrontianite: 8.4802e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 457 +SrCO3 added: 4.5700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5162e-01 +XStrontianite: 8.4838e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 458 +SrCO3 added: 4.5800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5127e-01 +XStrontianite: 8.4873e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 459 +SrCO3 added: 4.5900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5091e-01 +XStrontianite: 8.4909e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 460 +SrCO3 added: 4.6000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5055e-01 +XStrontianite: 8.4945e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 461 +SrCO3 added: 4.6100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.5020e-01 +XStrontianite: 8.4980e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 462 +SrCO3 added: 4.6200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4985e-01 +XStrontianite: 8.5015e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 463 +SrCO3 added: 4.6300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4950e-01 +XStrontianite: 8.5050e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 464 +SrCO3 added: 4.6400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4915e-01 +XStrontianite: 8.5085e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 465 +SrCO3 added: 4.6500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4880e-01 +XStrontianite: 8.5120e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 466 +SrCO3 added: 4.6600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4846e-01 +XStrontianite: 8.5154e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 467 +SrCO3 added: 4.6700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4811e-01 +XStrontianite: 8.5189e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 468 +SrCO3 added: 4.6800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4777e-01 +XStrontianite: 8.5223e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 469 +SrCO3 added: 4.6900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4743e-01 +XStrontianite: 8.5257e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 470 +SrCO3 added: 4.7000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4709e-01 +XStrontianite: 8.5291e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 471 +SrCO3 added: 4.7100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4675e-01 +XStrontianite: 8.5325e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 472 +SrCO3 added: 4.7200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4642e-01 +XStrontianite: 8.5358e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 473 +SrCO3 added: 4.7300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4608e-01 +XStrontianite: 8.5392e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 474 +SrCO3 added: 4.7400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4575e-01 +XStrontianite: 8.5425e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 475 +SrCO3 added: 4.7500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4542e-01 +XStrontianite: 8.5458e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 476 +SrCO3 added: 4.7600e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4509e-01 +XStrontianite: 8.5491e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 477 +SrCO3 added: 4.7700e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4476e-01 +XStrontianite: 8.5524e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 478 +SrCO3 added: 4.7800e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4443e-01 +XStrontianite: 8.5557e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 479 +SrCO3 added: 4.7900e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4411e-01 +XStrontianite: 8.5589e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 480 +SrCO3 added: 4.8000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4379e-01 +XStrontianite: 8.5621e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 481 +SrCO3 added: 4.8100e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4346e-01 +XStrontianite: 8.5654e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 482 +SrCO3 added: 4.8200e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4314e-01 +XStrontianite: 8.5686e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 483 +SrCO3 added: 4.8300e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4282e-01 +XStrontianite: 8.5718e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 484 +SrCO3 added: 4.8400e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4250e-01 +XStrontianite: 8.5750e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 485 +SrCO3 added: 4.8500e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.4219e-01 +XStrontianite: 8.5781e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 486 +SrCO3 added: 4.8600e-03 +Log Sigma pi: -8.2975e+00 +XAragonite: 1.4210e-01 +XStrontianite: 8.5790e-01 +XCa: 9.0899e-01 +XSr: 9.1014e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 487 +SrCO3 added: 4.8700e-03 +Log Sigma pi: -8.2976e+00 +XAragonite: 1.4206e-01 +XStrontianite: 8.5794e-01 +XCa: 9.0895e-01 +XSr: 9.1046e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 488 +SrCO3 added: 4.8800e-03 +Log Sigma pi: -8.2977e+00 +XAragonite: 1.4202e-01 +XStrontianite: 8.5798e-01 +XCa: 9.0892e-01 +XSr: 9.1078e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 489 +SrCO3 added: 4.8900e-03 +Log Sigma pi: -8.2979e+00 +XAragonite: 1.4197e-01 +XStrontianite: 8.5803e-01 +XCa: 9.0889e-01 +XSr: 9.1110e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 490 +SrCO3 added: 4.9000e-03 +Log Sigma pi: -8.2980e+00 +XAragonite: 1.4193e-01 +XStrontianite: 8.5807e-01 +XCa: 9.0886e-01 +XSr: 9.1142e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 491 +SrCO3 added: 4.9100e-03 +Log Sigma pi: -8.2981e+00 +XAragonite: 1.4189e-01 +XStrontianite: 8.5811e-01 +XCa: 9.0883e-01 +XSr: 9.1174e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 492 +SrCO3 added: 4.9200e-03 +Log Sigma pi: -8.2982e+00 +XAragonite: 1.4185e-01 +XStrontianite: 8.5815e-01 +XCa: 9.0879e-01 +XSr: 9.1206e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 493 +SrCO3 added: 4.9300e-03 +Log Sigma pi: -8.2984e+00 +XAragonite: 1.4181e-01 +XStrontianite: 8.5819e-01 +XCa: 9.0876e-01 +XSr: 9.1238e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 494 +SrCO3 added: 4.9400e-03 +Log Sigma pi: -8.2985e+00 +XAragonite: 1.4176e-01 +XStrontianite: 8.5824e-01 +XCa: 9.0873e-01 +XSr: 9.1270e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 495 +SrCO3 added: 4.9500e-03 +Log Sigma pi: -8.2986e+00 +XAragonite: 1.4172e-01 +XStrontianite: 8.5828e-01 +XCa: 9.0870e-01 +XSr: 9.1302e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 496 +SrCO3 added: 4.9600e-03 +Log Sigma pi: -8.2988e+00 +XAragonite: 1.4168e-01 +XStrontianite: 8.5832e-01 +XCa: 9.0867e-01 +XSr: 9.1334e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 497 +SrCO3 added: 4.9700e-03 +Log Sigma pi: -8.2989e+00 +XAragonite: 1.4164e-01 +XStrontianite: 8.5836e-01 +XCa: 9.0863e-01 +XSr: 9.1366e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 498 +SrCO3 added: 4.9800e-03 +Log Sigma pi: -8.2990e+00 +XAragonite: 1.4160e-01 +XStrontianite: 8.5840e-01 +XCa: 9.0860e-01 +XSr: 9.1398e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 499 +SrCO3 added: 4.9900e-03 +Log Sigma pi: -8.2991e+00 +XAragonite: 1.4155e-01 +XStrontianite: 8.5845e-01 +XCa: 9.0857e-01 +XSr: 9.1429e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 4 +Reaction step number: 500 +SrCO3 added: 5.0000e-03 +Log Sigma pi: -8.2993e+00 +XAragonite: 1.4151e-01 +XStrontianite: 8.5849e-01 +XCa: 9.0854e-01 +XSr: 9.1461e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + + USE solution 1 + USE solid_solution 1 + REACTION 1 + SrCO3 1.0 + .1 in 100 steps + END +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 1 +SrCO3 added: 1.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 9.8567e-01 +XStrontianite: 1.4329e-02 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 2 +SrCO3 added: 2.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 3.8793e-01 +XStrontianite: 6.1207e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 3 +SrCO3 added: 3.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 2.4149e-01 +XStrontianite: 7.5851e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 4 +SrCO3 added: 4.0000e-03 +Log Sigma pi: -8.2974e+00 +XAragonite: 1.7531e-01 +XStrontianite: 8.2469e-01 +XCa: 9.0901e-01 +XSr: 9.0987e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 5 +SrCO3 added: 5.0000e-03 +Log Sigma pi: -8.2993e+00 +XAragonite: 1.4151e-01 +XStrontianite: 8.5849e-01 +XCa: 9.0854e-01 +XSr: 9.1461e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 6 +SrCO3 added: 6.0000e-03 +Log Sigma pi: -8.3118e+00 +XAragonite: 1.3751e-01 +XStrontianite: 8.6249e-01 +XCa: 9.0539e-01 +XSr: 9.4606e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 7 +SrCO3 added: 7.0000e-03 +Log Sigma pi: -8.3236e+00 +XAragonite: 1.3383e-01 +XStrontianite: 8.6617e-01 +XCa: 9.0233e-01 +XSr: 9.7673e-02 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 8 +SrCO3 added: 8.0000e-03 +Log Sigma pi: -8.3349e+00 +XAragonite: 1.3043e-01 +XStrontianite: 8.6957e-01 +XCa: 8.9933e-01 +XSr: 1.0067e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 9 +SrCO3 added: 9.0000e-03 +Log Sigma pi: -8.3456e+00 +XAragonite: 1.2726e-01 +XStrontianite: 8.7274e-01 +XCa: 8.9640e-01 +XSr: 1.0360e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 10 +SrCO3 added: 1.0000e-02 +Log Sigma pi: -8.3559e+00 +XAragonite: 1.2431e-01 +XStrontianite: 8.7569e-01 +XCa: 8.9352e-01 +XSr: 1.0648e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 11 +SrCO3 added: 1.1000e-02 +Log Sigma pi: -8.3658e+00 +XAragonite: 1.2155e-01 +XStrontianite: 8.7845e-01 +XCa: 8.9070e-01 +XSr: 1.0930e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 12 +SrCO3 added: 1.2000e-02 +Log Sigma pi: -8.3752e+00 +XAragonite: 1.1895e-01 +XStrontianite: 8.8105e-01 +XCa: 8.8792e-01 +XSr: 1.1208e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 13 +SrCO3 added: 1.3000e-02 +Log Sigma pi: -8.3843e+00 +XAragonite: 1.1650e-01 +XStrontianite: 8.8350e-01 +XCa: 8.8519e-01 +XSr: 1.1481e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 14 +SrCO3 added: 1.4000e-02 +Log Sigma pi: -8.3931e+00 +XAragonite: 1.1419e-01 +XStrontianite: 8.8581e-01 +XCa: 8.8251e-01 +XSr: 1.1749e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 15 +SrCO3 added: 1.5000e-02 +Log Sigma pi: -8.4016e+00 +XAragonite: 1.1199e-01 +XStrontianite: 8.8801e-01 +XCa: 8.7986e-01 +XSr: 1.2014e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 16 +SrCO3 added: 1.6000e-02 +Log Sigma pi: -8.4098e+00 +XAragonite: 1.0991e-01 +XStrontianite: 8.9009e-01 +XCa: 8.7725e-01 +XSr: 1.2275e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 17 +SrCO3 added: 1.7000e-02 +Log Sigma pi: -8.4178e+00 +XAragonite: 1.0793e-01 +XStrontianite: 8.9207e-01 +XCa: 8.7468e-01 +XSr: 1.2532e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 18 +SrCO3 added: 1.8000e-02 +Log Sigma pi: -8.4254e+00 +XAragonite: 1.0604e-01 +XStrontianite: 8.9396e-01 +XCa: 8.7214e-01 +XSr: 1.2786e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 19 +SrCO3 added: 1.9000e-02 +Log Sigma pi: -8.4329e+00 +XAragonite: 1.0423e-01 +XStrontianite: 8.9577e-01 +XCa: 8.6963e-01 +XSr: 1.3037e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 20 +SrCO3 added: 2.0000e-02 +Log Sigma pi: -8.4401e+00 +XAragonite: 1.0251e-01 +XStrontianite: 8.9749e-01 +XCa: 8.6716e-01 +XSr: 1.3284e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 21 +SrCO3 added: 2.1000e-02 +Log Sigma pi: -8.4472e+00 +XAragonite: 1.0086e-01 +XStrontianite: 8.9914e-01 +XCa: 8.6471e-01 +XSr: 1.3529e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 22 +SrCO3 added: 2.2000e-02 +Log Sigma pi: -8.4540e+00 +XAragonite: 9.9270e-02 +XStrontianite: 9.0073e-01 +XCa: 8.6230e-01 +XSr: 1.3770e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 23 +SrCO3 added: 2.3000e-02 +Log Sigma pi: -8.4607e+00 +XAragonite: 9.7747e-02 +XStrontianite: 9.0225e-01 +XCa: 8.5991e-01 +XSr: 1.4009e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 24 +SrCO3 added: 2.4000e-02 +Log Sigma pi: -8.4672e+00 +XAragonite: 9.6283e-02 +XStrontianite: 9.0372e-01 +XCa: 8.5754e-01 +XSr: 1.4246e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 25 +SrCO3 added: 2.5000e-02 +Log Sigma pi: -8.4735e+00 +XAragonite: 9.4874e-02 +XStrontianite: 9.0513e-01 +XCa: 8.5520e-01 +XSr: 1.4480e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 26 +SrCO3 added: 2.6000e-02 +Log Sigma pi: -8.4797e+00 +XAragonite: 9.3517e-02 +XStrontianite: 9.0648e-01 +XCa: 8.5289e-01 +XSr: 1.4711e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 27 +SrCO3 added: 2.7000e-02 +Log Sigma pi: -8.4857e+00 +XAragonite: 9.2208e-02 +XStrontianite: 9.0779e-01 +XCa: 8.5060e-01 +XSr: 1.4940e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 28 +SrCO3 added: 2.8000e-02 +Log Sigma pi: -8.4915e+00 +XAragonite: 9.0944e-02 +XStrontianite: 9.0906e-01 +XCa: 8.4833e-01 +XSr: 1.5167e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 29 +SrCO3 added: 2.9000e-02 +Log Sigma pi: -8.4973e+00 +XAragonite: 8.9723e-02 +XStrontianite: 9.1028e-01 +XCa: 8.4608e-01 +XSr: 1.5392e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 30 +SrCO3 added: 3.0000e-02 +Log Sigma pi: -8.5029e+00 +XAragonite: 8.8542e-02 +XStrontianite: 9.1146e-01 +XCa: 8.4386e-01 +XSr: 1.5614e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 31 +SrCO3 added: 3.1000e-02 +Log Sigma pi: -8.5084e+00 +XAragonite: 8.7400e-02 +XStrontianite: 9.1260e-01 +XCa: 8.4166e-01 +XSr: 1.5834e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 32 +SrCO3 added: 3.2000e-02 +Log Sigma pi: -8.5137e+00 +XAragonite: 8.6294e-02 +XStrontianite: 9.1371e-01 +XCa: 8.3947e-01 +XSr: 1.6053e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 33 +SrCO3 added: 3.3000e-02 +Log Sigma pi: -8.5190e+00 +XAragonite: 8.5221e-02 +XStrontianite: 9.1478e-01 +XCa: 8.3731e-01 +XSr: 1.6269e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 34 +SrCO3 added: 3.4000e-02 +Log Sigma pi: -8.5241e+00 +XAragonite: 8.4182e-02 +XStrontianite: 9.1582e-01 +XCa: 8.3516e-01 +XSr: 1.6484e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 35 +SrCO3 added: 3.5000e-02 +Log Sigma pi: -8.5292e+00 +XAragonite: 8.3173e-02 +XStrontianite: 9.1683e-01 +XCa: 8.3304e-01 +XSr: 1.6696e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 36 +SrCO3 added: 3.6000e-02 +Log Sigma pi: -8.5341e+00 +XAragonite: 8.2193e-02 +XStrontianite: 9.1781e-01 +XCa: 8.3093e-01 +XSr: 1.6907e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 37 +SrCO3 added: 3.7000e-02 +Log Sigma pi: -8.5390e+00 +XAragonite: 8.1241e-02 +XStrontianite: 9.1876e-01 +XCa: 8.2884e-01 +XSr: 1.7116e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 38 +SrCO3 added: 3.8000e-02 +Log Sigma pi: -8.5437e+00 +XAragonite: 8.0316e-02 +XStrontianite: 9.1968e-01 +XCa: 8.2677e-01 +XSr: 1.7323e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 39 +SrCO3 added: 3.9000e-02 +Log Sigma pi: -8.5484e+00 +XAragonite: 7.9416e-02 +XStrontianite: 9.2058e-01 +XCa: 8.2471e-01 +XSr: 1.7529e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 40 +SrCO3 added: 4.0000e-02 +Log Sigma pi: -8.5529e+00 +XAragonite: 7.8540e-02 +XStrontianite: 9.2146e-01 +XCa: 8.2267e-01 +XSr: 1.7733e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 41 +SrCO3 added: 4.1000e-02 +Log Sigma pi: -8.5574e+00 +XAragonite: 7.7688e-02 +XStrontianite: 9.2231e-01 +XCa: 8.2065e-01 +XSr: 1.7935e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 42 +SrCO3 added: 4.2000e-02 +Log Sigma pi: -8.5618e+00 +XAragonite: 7.6857e-02 +XStrontianite: 9.2314e-01 +XCa: 8.1865e-01 +XSr: 1.8135e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 43 +SrCO3 added: 4.3000e-02 +Log Sigma pi: -8.5662e+00 +XAragonite: 7.6048e-02 +XStrontianite: 9.2395e-01 +XCa: 8.1665e-01 +XSr: 1.8335e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 44 +SrCO3 added: 4.4000e-02 +Log Sigma pi: -8.5704e+00 +XAragonite: 7.5259e-02 +XStrontianite: 9.2474e-01 +XCa: 8.1468e-01 +XSr: 1.8532e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 45 +SrCO3 added: 4.5000e-02 +Log Sigma pi: -8.5746e+00 +XAragonite: 7.4489e-02 +XStrontianite: 9.2551e-01 +XCa: 8.1272e-01 +XSr: 1.8728e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 46 +SrCO3 added: 4.6000e-02 +Log Sigma pi: -8.5787e+00 +XAragonite: 7.3738e-02 +XStrontianite: 9.2626e-01 +XCa: 8.1077e-01 +XSr: 1.8923e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 47 +SrCO3 added: 4.7000e-02 +Log Sigma pi: -8.5827e+00 +XAragonite: 7.3005e-02 +XStrontianite: 9.2699e-01 +XCa: 8.0884e-01 +XSr: 1.9116e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 48 +SrCO3 added: 4.8000e-02 +Log Sigma pi: -8.5867e+00 +XAragonite: 7.2290e-02 +XStrontianite: 9.2771e-01 +XCa: 8.0692e-01 +XSr: 1.9308e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 49 +SrCO3 added: 4.9000e-02 +Log Sigma pi: -8.5906e+00 +XAragonite: 7.1590e-02 +XStrontianite: 9.2841e-01 +XCa: 8.0502e-01 +XSr: 1.9498e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 50 +SrCO3 added: 5.0000e-02 +Log Sigma pi: -8.5945e+00 +XAragonite: 7.0907e-02 +XStrontianite: 9.2909e-01 +XCa: 8.0313e-01 +XSr: 1.9687e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 51 +SrCO3 added: 5.1000e-02 +Log Sigma pi: -8.5982e+00 +XAragonite: 7.0239e-02 +XStrontianite: 9.2976e-01 +XCa: 8.0125e-01 +XSr: 1.9875e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 52 +SrCO3 added: 5.2000e-02 +Log Sigma pi: -8.6020e+00 +XAragonite: 6.9586e-02 +XStrontianite: 9.3041e-01 +XCa: 7.9939e-01 +XSr: 2.0061e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 53 +SrCO3 added: 5.3000e-02 +Log Sigma pi: -8.6056e+00 +XAragonite: 6.8947e-02 +XStrontianite: 9.3105e-01 +XCa: 7.9753e-01 +XSr: 2.0247e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 54 +SrCO3 added: 5.4000e-02 +Log Sigma pi: -8.6092e+00 +XAragonite: 6.8322e-02 +XStrontianite: 9.3168e-01 +XCa: 7.9570e-01 +XSr: 2.0430e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 55 +SrCO3 added: 5.5000e-02 +Log Sigma pi: -8.6128e+00 +XAragonite: 6.7710e-02 +XStrontianite: 9.3229e-01 +XCa: 7.9387e-01 +XSr: 2.0613e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 56 +SrCO3 added: 5.6000e-02 +Log Sigma pi: -8.6163e+00 +XAragonite: 6.7111e-02 +XStrontianite: 9.3289e-01 +XCa: 7.9206e-01 +XSr: 2.0794e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 57 +SrCO3 added: 5.7000e-02 +Log Sigma pi: -8.6198e+00 +XAragonite: 6.6524e-02 +XStrontianite: 9.3348e-01 +XCa: 7.9026e-01 +XSr: 2.0974e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 58 +SrCO3 added: 5.8000e-02 +Log Sigma pi: -8.6232e+00 +XAragonite: 6.5950e-02 +XStrontianite: 9.3405e-01 +XCa: 7.8847e-01 +XSr: 2.1153e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 59 +SrCO3 added: 5.9000e-02 +Log Sigma pi: -8.6265e+00 +XAragonite: 6.5386e-02 +XStrontianite: 9.3461e-01 +XCa: 7.8669e-01 +XSr: 2.1331e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 60 +SrCO3 added: 6.0000e-02 +Log Sigma pi: -8.6298e+00 +XAragonite: 6.4834e-02 +XStrontianite: 9.3517e-01 +XCa: 7.8492e-01 +XSr: 2.1508e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 61 +SrCO3 added: 6.1000e-02 +Log Sigma pi: -8.6331e+00 +XAragonite: 6.4293e-02 +XStrontianite: 9.3571e-01 +XCa: 7.8317e-01 +XSr: 2.1683e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 62 +SrCO3 added: 6.2000e-02 +Log Sigma pi: -8.6363e+00 +XAragonite: 6.3762e-02 +XStrontianite: 9.3624e-01 +XCa: 7.8142e-01 +XSr: 2.1858e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 63 +SrCO3 added: 6.3000e-02 +Log Sigma pi: -8.6395e+00 +XAragonite: 6.3242e-02 +XStrontianite: 9.3676e-01 +XCa: 7.7969e-01 +XSr: 2.2031e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 64 +SrCO3 added: 6.4000e-02 +Log Sigma pi: -8.6426e+00 +XAragonite: 6.2731e-02 +XStrontianite: 9.3727e-01 +XCa: 7.7797e-01 +XSr: 2.2203e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 65 +SrCO3 added: 6.5000e-02 +Log Sigma pi: -8.6457e+00 +XAragonite: 6.2230e-02 +XStrontianite: 9.3777e-01 +XCa: 7.7626e-01 +XSr: 2.2374e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 66 +SrCO3 added: 6.6000e-02 +Log Sigma pi: -8.6487e+00 +XAragonite: 6.1738e-02 +XStrontianite: 9.3826e-01 +XCa: 7.7456e-01 +XSr: 2.2544e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 67 +SrCO3 added: 6.7000e-02 +Log Sigma pi: -8.6517e+00 +XAragonite: 6.1255e-02 +XStrontianite: 9.3875e-01 +XCa: 7.7287e-01 +XSr: 2.2713e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 68 +SrCO3 added: 6.8000e-02 +Log Sigma pi: -8.6547e+00 +XAragonite: 6.0780e-02 +XStrontianite: 9.3922e-01 +XCa: 7.7119e-01 +XSr: 2.2881e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 69 +SrCO3 added: 6.9000e-02 +Log Sigma pi: -8.6576e+00 +XAragonite: 6.0314e-02 +XStrontianite: 9.3969e-01 +XCa: 7.6952e-01 +XSr: 2.3048e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 70 +SrCO3 added: 7.0000e-02 +Log Sigma pi: -8.6605e+00 +XAragonite: 5.9857e-02 +XStrontianite: 9.4014e-01 +XCa: 7.6786e-01 +XSr: 2.3214e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 71 +SrCO3 added: 7.1000e-02 +Log Sigma pi: -8.6634e+00 +XAragonite: 5.9407e-02 +XStrontianite: 9.4059e-01 +XCa: 7.6621e-01 +XSr: 2.3379e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 72 +SrCO3 added: 7.2000e-02 +Log Sigma pi: -8.6662e+00 +XAragonite: 5.8965e-02 +XStrontianite: 9.4103e-01 +XCa: 7.6457e-01 +XSr: 2.3543e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 73 +SrCO3 added: 7.3000e-02 +Log Sigma pi: -8.6690e+00 +XAragonite: 5.8531e-02 +XStrontianite: 9.4147e-01 +XCa: 7.6294e-01 +XSr: 2.3706e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 74 +SrCO3 added: 7.4000e-02 +Log Sigma pi: -8.6718e+00 +XAragonite: 5.8104e-02 +XStrontianite: 9.4190e-01 +XCa: 7.6132e-01 +XSr: 2.3868e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 75 +SrCO3 added: 7.5000e-02 +Log Sigma pi: -8.6745e+00 +XAragonite: 5.7684e-02 +XStrontianite: 9.4232e-01 +XCa: 7.5970e-01 +XSr: 2.4030e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 76 +SrCO3 added: 7.6000e-02 +Log Sigma pi: -8.6772e+00 +XAragonite: 5.7271e-02 +XStrontianite: 9.4273e-01 +XCa: 7.5810e-01 +XSr: 2.4190e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 77 +SrCO3 added: 7.7000e-02 +Log Sigma pi: -8.6798e+00 +XAragonite: 5.6864e-02 +XStrontianite: 9.4314e-01 +XCa: 7.5651e-01 +XSr: 2.4349e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 78 +SrCO3 added: 7.8000e-02 +Log Sigma pi: -8.6824e+00 +XAragonite: 5.6465e-02 +XStrontianite: 9.4354e-01 +XCa: 7.5492e-01 +XSr: 2.4508e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 79 +SrCO3 added: 7.9000e-02 +Log Sigma pi: -8.6850e+00 +XAragonite: 5.6071e-02 +XStrontianite: 9.4393e-01 +XCa: 7.5335e-01 +XSr: 2.4665e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 80 +SrCO3 added: 8.0000e-02 +Log Sigma pi: -8.6876e+00 +XAragonite: 5.5684e-02 +XStrontianite: 9.4432e-01 +XCa: 7.5178e-01 +XSr: 2.4822e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 81 +SrCO3 added: 8.1000e-02 +Log Sigma pi: -8.6901e+00 +XAragonite: 5.5303e-02 +XStrontianite: 9.4470e-01 +XCa: 7.5023e-01 +XSr: 2.4977e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 82 +SrCO3 added: 8.2000e-02 +Log Sigma pi: -8.6926e+00 +XAragonite: 5.4928e-02 +XStrontianite: 9.4507e-01 +XCa: 7.4868e-01 +XSr: 2.5132e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 83 +SrCO3 added: 8.3000e-02 +Log Sigma pi: -8.6951e+00 +XAragonite: 5.4559e-02 +XStrontianite: 9.4544e-01 +XCa: 7.4714e-01 +XSr: 2.5286e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 84 +SrCO3 added: 8.4000e-02 +Log Sigma pi: -8.6976e+00 +XAragonite: 5.4196e-02 +XStrontianite: 9.4580e-01 +XCa: 7.4560e-01 +XSr: 2.5440e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 85 +SrCO3 added: 8.5000e-02 +Log Sigma pi: -8.7000e+00 +XAragonite: 5.3837e-02 +XStrontianite: 9.4616e-01 +XCa: 7.4408e-01 +XSr: 2.5592e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 86 +SrCO3 added: 8.6000e-02 +Log Sigma pi: -8.7024e+00 +XAragonite: 5.3485e-02 +XStrontianite: 9.4652e-01 +XCa: 7.4256e-01 +XSr: 2.5744e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 87 +SrCO3 added: 8.7000e-02 +Log Sigma pi: -8.7047e+00 +XAragonite: 5.3137e-02 +XStrontianite: 9.4686e-01 +XCa: 7.4106e-01 +XSr: 2.5894e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 88 +SrCO3 added: 8.8000e-02 +Log Sigma pi: -8.7071e+00 +XAragonite: 5.2795e-02 +XStrontianite: 9.4721e-01 +XCa: 7.3956e-01 +XSr: 2.6044e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 89 +SrCO3 added: 8.9000e-02 +Log Sigma pi: -8.7094e+00 +XAragonite: 5.2457e-02 +XStrontianite: 9.4754e-01 +XCa: 7.3807e-01 +XSr: 2.6193e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 90 +SrCO3 added: 9.0000e-02 +Log Sigma pi: -8.7117e+00 +XAragonite: 5.2125e-02 +XStrontianite: 9.4788e-01 +XCa: 7.3658e-01 +XSr: 2.6342e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 91 +SrCO3 added: 9.1000e-02 +Log Sigma pi: -8.7140e+00 +XAragonite: 5.1797e-02 +XStrontianite: 9.4820e-01 +XCa: 7.3511e-01 +XSr: 2.6489e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 92 +SrCO3 added: 9.2000e-02 +Log Sigma pi: -8.7162e+00 +XAragonite: 5.1474e-02 +XStrontianite: 9.4853e-01 +XCa: 7.3364e-01 +XSr: 2.6636e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 93 +SrCO3 added: 9.3000e-02 +Log Sigma pi: -8.7185e+00 +XAragonite: 5.1155e-02 +XStrontianite: 9.4884e-01 +XCa: 7.3218e-01 +XSr: 2.6782e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 94 +SrCO3 added: 9.4000e-02 +Log Sigma pi: -8.7207e+00 +XAragonite: 5.0841e-02 +XStrontianite: 9.4916e-01 +XCa: 7.3073e-01 +XSr: 2.6927e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 95 +SrCO3 added: 9.5000e-02 +Log Sigma pi: -8.7228e+00 +XAragonite: 5.0531e-02 +XStrontianite: 9.4947e-01 +XCa: 7.2928e-01 +XSr: 2.7072e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 96 +SrCO3 added: 9.6000e-02 +Log Sigma pi: -8.7250e+00 +XAragonite: 5.0226e-02 +XStrontianite: 9.4977e-01 +XCa: 7.2784e-01 +XSr: 2.7216e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 97 +SrCO3 added: 9.7000e-02 +Log Sigma pi: -8.7271e+00 +XAragonite: 4.9924e-02 +XStrontianite: 9.5008e-01 +XCa: 7.2641e-01 +XSr: 2.7359e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 98 +SrCO3 added: 9.8000e-02 +Log Sigma pi: -8.7292e+00 +XAragonite: 4.9627e-02 +XStrontianite: 9.5037e-01 +XCa: 7.2499e-01 +XSr: 2.7501e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 99 +SrCO3 added: 9.9000e-02 +Log Sigma pi: -8.7313e+00 +XAragonite: 4.9334e-02 +XStrontianite: 9.5067e-01 +XCa: 7.2357e-01 +XSr: 2.7643e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 5 +Reaction step number: 100 +SrCO3 added: 1.0000e-01 +Log Sigma pi: -8.7334e+00 +XAragonite: 4.9044e-02 +XStrontianite: 9.5096e-01 +XCa: 7.2216e-01 +XSr: 2.7784e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + + USE solution 1 + USE solid_solution 1 + REACTION 1 + SrCO3 1.0 + 10.0 in 100 steps + END +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 1 +SrCO3 added: 1.0000e-01 +Log Sigma pi: -8.7334e+00 +XAragonite: 4.9044e-02 +XStrontianite: 9.5096e-01 +XCa: 7.2216e-01 +XSr: 2.7784e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 2 +SrCO3 added: 2.0000e-01 +Log Sigma pi: -8.8746e+00 +XAragonite: 3.1529e-02 +XStrontianite: 9.6847e-01 +XCa: 6.0843e-01 +XSr: 3.9157e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 3 +SrCO3 added: 3.0000e-01 +Log Sigma pi: -8.9515e+00 +XAragonite: 2.3611e-02 +XStrontianite: 9.7639e-01 +XCa: 5.2912e-01 +XSr: 4.7088e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 4 +SrCO3 added: 4.0000e-01 +Log Sigma pi: -9.0015e+00 +XAragonite: 1.8992e-02 +XStrontianite: 9.8101e-01 +XCa: 4.6954e-01 +XSr: 5.3046e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 5 +SrCO3 added: 5.0000e-01 +Log Sigma pi: -9.0371e+00 +XAragonite: 1.5935e-02 +XStrontianite: 9.8407e-01 +XCa: 4.2272e-01 +XSr: 5.7728e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 6 +SrCO3 added: 6.0000e-01 +Log Sigma pi: -9.0640e+00 +XAragonite: 1.3750e-02 +XStrontianite: 9.8625e-01 +XCa: 3.8479e-01 +XSr: 6.1521e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 7 +SrCO3 added: 7.0000e-01 +Log Sigma pi: -9.0851e+00 +XAragonite: 1.2105e-02 +XStrontianite: 9.8790e-01 +XCa: 3.5335e-01 +XSr: 6.4665e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 8 +SrCO3 added: 8.0000e-01 +Log Sigma pi: -9.1022e+00 +XAragonite: 1.0819e-02 +XStrontianite: 9.8918e-01 +XCa: 3.2680e-01 +XSr: 6.7320e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 9 +SrCO3 added: 9.0000e-01 +Log Sigma pi: -9.1162e+00 +XAragonite: 9.7855e-03 +XStrontianite: 9.9021e-01 +XCa: 3.0406e-01 +XSr: 6.9594e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 10 +SrCO3 added: 1 +Log Sigma pi: -9.1281e+00 +XAragonite: 8.9352e-03 +XStrontianite: 9.9106e-01 +XCa: 2.8435e-01 +XSr: 7.1565e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 11 +SrCO3 added: 1.1000e+00 +Log Sigma pi: -9.1382e+00 +XAragonite: 8.2229e-03 +XStrontianite: 9.9178e-01 +XCa: 2.6708e-01 +XSr: 7.3292e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 12 +SrCO3 added: 1.2000e+00 +Log Sigma pi: -9.1470e+00 +XAragonite: 7.6172e-03 +XStrontianite: 9.9238e-01 +XCa: 2.5183e-01 +XSr: 7.4817e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 13 +SrCO3 added: 1.3000e+00 +Log Sigma pi: -9.1547e+00 +XAragonite: 7.0957e-03 +XStrontianite: 9.9290e-01 +XCa: 2.3825e-01 +XSr: 7.6175e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 14 +SrCO3 added: 1.4000e+00 +Log Sigma pi: -9.1614e+00 +XAragonite: 6.6418e-03 +XStrontianite: 9.9336e-01 +XCa: 2.2608e-01 +XSr: 7.7392e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 15 +SrCO3 added: 1.5000e+00 +Log Sigma pi: -9.1674e+00 +XAragonite: 6.2431e-03 +XStrontianite: 9.9376e-01 +XCa: 2.1511e-01 +XSr: 7.8489e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 16 +SrCO3 added: 1.6000e+00 +Log Sigma pi: -9.1728e+00 +XAragonite: 5.8899e-03 +XStrontianite: 9.9411e-01 +XCa: 2.0516e-01 +XSr: 7.9484e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 17 +SrCO3 added: 1.7000e+00 +Log Sigma pi: -9.1776e+00 +XAragonite: 5.5749e-03 +XStrontianite: 9.9443e-01 +XCa: 1.9610e-01 +XSr: 8.0390e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 18 +SrCO3 added: 1.8000e+00 +Log Sigma pi: -9.1820e+00 +XAragonite: 5.2921e-03 +XStrontianite: 9.9471e-01 +XCa: 1.8782e-01 +XSr: 8.1218e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 19 +SrCO3 added: 1.9000e+00 +Log Sigma pi: -9.1860e+00 +XAragonite: 5.0369e-03 +XStrontianite: 9.9496e-01 +XCa: 1.8021e-01 +XSr: 8.1979e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 20 +SrCO3 added: 2 +Log Sigma pi: -9.1896e+00 +XAragonite: 4.8052e-03 +XStrontianite: 9.9519e-01 +XCa: 1.7320e-01 +XSr: 8.2680e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 21 +SrCO3 added: 2.1000e+00 +Log Sigma pi: -9.1929e+00 +XAragonite: 4.5941e-03 +XStrontianite: 9.9541e-01 +XCa: 1.6672e-01 +XSr: 8.3328e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 22 +SrCO3 added: 2.2000e+00 +Log Sigma pi: -9.1960e+00 +XAragonite: 4.4009e-03 +XStrontianite: 9.9560e-01 +XCa: 1.6071e-01 +XSr: 8.3929e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 23 +SrCO3 added: 2.3000e+00 +Log Sigma pi: -9.1988e+00 +XAragonite: 4.2233e-03 +XStrontianite: 9.9578e-01 +XCa: 1.5512e-01 +XSr: 8.4488e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 24 +SrCO3 added: 2.4000e+00 +Log Sigma pi: -9.2015e+00 +XAragonite: 4.0596e-03 +XStrontianite: 9.9594e-01 +XCa: 1.4990e-01 +XSr: 8.5010e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 25 +SrCO3 added: 2.5000e+00 +Log Sigma pi: -9.2039e+00 +XAragonite: 3.9082e-03 +XStrontianite: 9.9609e-01 +XCa: 1.4503e-01 +XSr: 8.5497e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 26 +SrCO3 added: 2.6000e+00 +Log Sigma pi: -9.2062e+00 +XAragonite: 3.7677e-03 +XStrontianite: 9.9623e-01 +XCa: 1.4047e-01 +XSr: 8.5953e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 27 +SrCO3 added: 2.7000e+00 +Log Sigma pi: -9.2083e+00 +XAragonite: 3.6370e-03 +XStrontianite: 9.9636e-01 +XCa: 1.3618e-01 +XSr: 8.6382e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 28 +SrCO3 added: 2.8000e+00 +Log Sigma pi: -9.2103e+00 +XAragonite: 3.5151e-03 +XStrontianite: 9.9648e-01 +XCa: 1.3216e-01 +XSr: 8.6784e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 29 +SrCO3 added: 2.9000e+00 +Log Sigma pi: -9.2122e+00 +XAragonite: 3.4011e-03 +XStrontianite: 9.9660e-01 +XCa: 1.2836e-01 +XSr: 8.7164e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 30 +SrCO3 added: 3 +Log Sigma pi: -9.2139e+00 +XAragonite: 3.2944e-03 +XStrontianite: 9.9671e-01 +XCa: 1.2478e-01 +XSr: 8.7522e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 31 +SrCO3 added: 3.1000e+00 +Log Sigma pi: -9.2156e+00 +XAragonite: 3.1941e-03 +XStrontianite: 9.9681e-01 +XCa: 1.2139e-01 +XSr: 8.7861e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 32 +SrCO3 added: 3.2000e+00 +Log Sigma pi: -9.2171e+00 +XAragonite: 3.0998e-03 +XStrontianite: 9.9690e-01 +XCa: 1.1818e-01 +XSr: 8.8182e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 33 +SrCO3 added: 3.3000e+00 +Log Sigma pi: -9.2186e+00 +XAragonite: 3.0109e-03 +XStrontianite: 9.9699e-01 +XCa: 1.1514e-01 +XSr: 8.8486e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 34 +SrCO3 added: 3.4000e+00 +Log Sigma pi: -9.2200e+00 +XAragonite: 2.9270e-03 +XStrontianite: 9.9707e-01 +XCa: 1.1225e-01 +XSr: 8.8775e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 35 +SrCO3 added: 3.5000e+00 +Log Sigma pi: -9.2213e+00 +XAragonite: 2.8476e-03 +XStrontianite: 9.9715e-01 +XCa: 1.0950e-01 +XSr: 8.9050e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 36 +SrCO3 added: 3.6000e+00 +Log Sigma pi: -9.2226e+00 +XAragonite: 2.7725e-03 +XStrontianite: 9.9723e-01 +XCa: 1.0688e-01 +XSr: 8.9312e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 37 +SrCO3 added: 3.7000e+00 +Log Sigma pi: -9.2238e+00 +XAragonite: 2.7012e-03 +XStrontianite: 9.9730e-01 +XCa: 1.0439e-01 +XSr: 8.9561e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 38 +SrCO3 added: 3.8000e+00 +Log Sigma pi: -9.2249e+00 +XAragonite: 2.6335e-03 +XStrontianite: 9.9737e-01 +XCa: 1.0201e-01 +XSr: 8.9799e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 39 +SrCO3 added: 3.9000e+00 +Log Sigma pi: -9.2260e+00 +XAragonite: 2.5691e-03 +XStrontianite: 9.9743e-01 +XCa: 9.9738e-02 +XSr: 9.0026e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 40 +SrCO3 added: 4 +Log Sigma pi: -9.2270e+00 +XAragonite: 2.5078e-03 +XStrontianite: 9.9749e-01 +XCa: 9.7564e-02 +XSr: 9.0244e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 41 +SrCO3 added: 4.1000e+00 +Log Sigma pi: -9.2280e+00 +XAragonite: 2.4494e-03 +XStrontianite: 9.9755e-01 +XCa: 9.5483e-02 +XSr: 9.0452e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 42 +SrCO3 added: 4.2000e+00 +Log Sigma pi: -9.2289e+00 +XAragonite: 2.3936e-03 +XStrontianite: 9.9761e-01 +XCa: 9.3489e-02 +XSr: 9.0651e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 43 +SrCO3 added: 4.3000e+00 +Log Sigma pi: -9.2298e+00 +XAragonite: 2.3404e-03 +XStrontianite: 9.9766e-01 +XCa: 9.1577e-02 +XSr: 9.0842e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 44 +SrCO3 added: 4.4000e+00 +Log Sigma pi: -9.2307e+00 +XAragonite: 2.2894e-03 +XStrontianite: 9.9771e-01 +XCa: 8.9742e-02 +XSr: 9.1026e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 45 +SrCO3 added: 4.5000e+00 +Log Sigma pi: -9.2315e+00 +XAragonite: 2.2406e-03 +XStrontianite: 9.9776e-01 +XCa: 8.7979e-02 +XSr: 9.1202e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 46 +SrCO3 added: 4.6000e+00 +Log Sigma pi: -9.2323e+00 +XAragonite: 2.1939e-03 +XStrontianite: 9.9781e-01 +XCa: 8.6284e-02 +XSr: 9.1372e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 47 +SrCO3 added: 4.7000e+00 +Log Sigma pi: -9.2331e+00 +XAragonite: 2.1491e-03 +XStrontianite: 9.9785e-01 +XCa: 8.4653e-02 +XSr: 9.1535e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 48 +SrCO3 added: 4.8000e+00 +Log Sigma pi: -9.2338e+00 +XAragonite: 2.1060e-03 +XStrontianite: 9.9789e-01 +XCa: 8.3083e-02 +XSr: 9.1692e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 49 +SrCO3 added: 4.9000e+00 +Log Sigma pi: -9.2345e+00 +XAragonite: 2.0647e-03 +XStrontianite: 9.9794e-01 +XCa: 8.1570e-02 +XSr: 9.1843e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 50 +SrCO3 added: 5 +Log Sigma pi: -9.2352e+00 +XAragonite: 2.0249e-03 +XStrontianite: 9.9798e-01 +XCa: 8.0112e-02 +XSr: 9.1989e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 51 +SrCO3 added: 5.1000e+00 +Log Sigma pi: -9.2359e+00 +XAragonite: 1.9867e-03 +XStrontianite: 9.9801e-01 +XCa: 7.8704e-02 +XSr: 9.2130e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 52 +SrCO3 added: 5.2000e+00 +Log Sigma pi: -9.2365e+00 +XAragonite: 1.9499e-03 +XStrontianite: 9.9805e-01 +XCa: 7.7346e-02 +XSr: 9.2265e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 53 +SrCO3 added: 5.3000e+00 +Log Sigma pi: -9.2371e+00 +XAragonite: 1.9144e-03 +XStrontianite: 9.9809e-01 +XCa: 7.6033e-02 +XSr: 9.2397e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 54 +SrCO3 added: 5.4000e+00 +Log Sigma pi: -9.2377e+00 +XAragonite: 1.8802e-03 +XStrontianite: 9.9812e-01 +XCa: 7.4765e-02 +XSr: 9.2524e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 55 +SrCO3 added: 5.5000e+00 +Log Sigma pi: -9.2383e+00 +XAragonite: 1.8472e-03 +XStrontianite: 9.9815e-01 +XCa: 7.3538e-02 +XSr: 9.2646e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 56 +SrCO3 added: 5.6000e+00 +Log Sigma pi: -9.2388e+00 +XAragonite: 1.8153e-03 +XStrontianite: 9.9818e-01 +XCa: 7.2350e-02 +XSr: 9.2765e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 57 +SrCO3 added: 5.7000e+00 +Log Sigma pi: -9.2393e+00 +XAragonite: 1.7845e-03 +XStrontianite: 9.9822e-01 +XCa: 7.1201e-02 +XSr: 9.2880e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 58 +SrCO3 added: 5.8000e+00 +Log Sigma pi: -9.2398e+00 +XAragonite: 1.7548e-03 +XStrontianite: 9.9825e-01 +XCa: 7.0087e-02 +XSr: 9.2991e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 59 +SrCO3 added: 5.9000e+00 +Log Sigma pi: -9.2403e+00 +XAragonite: 1.7260e-03 +XStrontianite: 9.9827e-01 +XCa: 6.9008e-02 +XSr: 9.3099e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 60 +SrCO3 added: 6 +Log Sigma pi: -9.2408e+00 +XAragonite: 1.6982e-03 +XStrontianite: 9.9830e-01 +XCa: 6.7962e-02 +XSr: 9.3204e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 61 +SrCO3 added: 6.1000e+00 +Log Sigma pi: -9.2413e+00 +XAragonite: 1.6712e-03 +XStrontianite: 9.9833e-01 +XCa: 6.6947e-02 +XSr: 9.3305e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 62 +SrCO3 added: 6.2000e+00 +Log Sigma pi: -9.2417e+00 +XAragonite: 1.6451e-03 +XStrontianite: 9.9835e-01 +XCa: 6.5961e-02 +XSr: 9.3404e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 63 +SrCO3 added: 6.3000e+00 +Log Sigma pi: -9.2422e+00 +XAragonite: 1.6198e-03 +XStrontianite: 9.9838e-01 +XCa: 6.5005e-02 +XSr: 9.3500e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 64 +SrCO3 added: 6.4000e+00 +Log Sigma pi: -9.2426e+00 +XAragonite: 1.5952e-03 +XStrontianite: 9.9840e-01 +XCa: 6.4076e-02 +XSr: 9.3592e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 65 +SrCO3 added: 6.5000e+00 +Log Sigma pi: -9.2430e+00 +XAragonite: 1.5714e-03 +XStrontianite: 9.9843e-01 +XCa: 6.3173e-02 +XSr: 9.3683e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 66 +SrCO3 added: 6.6000e+00 +Log Sigma pi: -9.2434e+00 +XAragonite: 1.5483e-03 +XStrontianite: 9.9845e-01 +XCa: 6.2295e-02 +XSr: 9.3771e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 67 +SrCO3 added: 6.7000e+00 +Log Sigma pi: -9.2438e+00 +XAragonite: 1.5258e-03 +XStrontianite: 9.9847e-01 +XCa: 6.1441e-02 +XSr: 9.3856e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 68 +SrCO3 added: 6.8000e+00 +Log Sigma pi: -9.2442e+00 +XAragonite: 1.5040e-03 +XStrontianite: 9.9850e-01 +XCa: 6.0610e-02 +XSr: 9.3939e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 69 +SrCO3 added: 6.9000e+00 +Log Sigma pi: -9.2446e+00 +XAragonite: 1.4829e-03 +XStrontianite: 9.9852e-01 +XCa: 5.9802e-02 +XSr: 9.4020e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 70 +SrCO3 added: 7 +Log Sigma pi: -9.2449e+00 +XAragonite: 1.4623e-03 +XStrontianite: 9.9854e-01 +XCa: 5.9015e-02 +XSr: 9.4099e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 71 +SrCO3 added: 7.1000e+00 +Log Sigma pi: -9.2453e+00 +XAragonite: 1.4422e-03 +XStrontianite: 9.9856e-01 +XCa: 5.8248e-02 +XSr: 9.4175e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 72 +SrCO3 added: 7.2000e+00 +Log Sigma pi: -9.2456e+00 +XAragonite: 1.4227e-03 +XStrontianite: 9.9858e-01 +XCa: 5.7501e-02 +XSr: 9.4250e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 73 +SrCO3 added: 7.3000e+00 +Log Sigma pi: -9.2459e+00 +XAragonite: 1.4038e-03 +XStrontianite: 9.9860e-01 +XCa: 5.6773e-02 +XSr: 9.4323e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 74 +SrCO3 added: 7.4000e+00 +Log Sigma pi: -9.2463e+00 +XAragonite: 1.3853e-03 +XStrontianite: 9.9861e-01 +XCa: 5.6063e-02 +XSr: 9.4394e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 75 +SrCO3 added: 7.5000e+00 +Log Sigma pi: -9.2466e+00 +XAragonite: 1.3673e-03 +XStrontianite: 9.9863e-01 +XCa: 5.5370e-02 +XSr: 9.4463e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 76 +SrCO3 added: 7.6000e+00 +Log Sigma pi: -9.2469e+00 +XAragonite: 1.3498e-03 +XStrontianite: 9.9865e-01 +XCa: 5.4695e-02 +XSr: 9.4530e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 77 +SrCO3 added: 7.7000e+00 +Log Sigma pi: -9.2472e+00 +XAragonite: 1.3327e-03 +XStrontianite: 9.9867e-01 +XCa: 5.4036e-02 +XSr: 9.4596e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 78 +SrCO3 added: 7.8000e+00 +Log Sigma pi: -9.2475e+00 +XAragonite: 1.3160e-03 +XStrontianite: 9.9868e-01 +XCa: 5.3392e-02 +XSr: 9.4661e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 79 +SrCO3 added: 7.9000e+00 +Log Sigma pi: -9.2478e+00 +XAragonite: 1.2998e-03 +XStrontianite: 9.9870e-01 +XCa: 5.2764e-02 +XSr: 9.4724e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 80 +SrCO3 added: 8 +Log Sigma pi: -9.2480e+00 +XAragonite: 1.2840e-03 +XStrontianite: 9.9872e-01 +XCa: 5.2150e-02 +XSr: 9.4785e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 81 +SrCO3 added: 8.1000e+00 +Log Sigma pi: -9.2483e+00 +XAragonite: 1.2685e-03 +XStrontianite: 9.9873e-01 +XCa: 5.1551e-02 +XSr: 9.4845e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 82 +SrCO3 added: 8.2000e+00 +Log Sigma pi: -9.2486e+00 +XAragonite: 1.2534e-03 +XStrontianite: 9.9875e-01 +XCa: 5.0965e-02 +XSr: 9.4903e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 83 +SrCO3 added: 8.3000e+00 +Log Sigma pi: -9.2488e+00 +XAragonite: 1.2386e-03 +XStrontianite: 9.9876e-01 +XCa: 5.0392e-02 +XSr: 9.4961e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 84 +SrCO3 added: 8.4000e+00 +Log Sigma pi: -9.2491e+00 +XAragonite: 1.2242e-03 +XStrontianite: 9.9878e-01 +XCa: 4.9832e-02 +XSr: 9.5017e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 85 +SrCO3 added: 8.5000e+00 +Log Sigma pi: -9.2493e+00 +XAragonite: 1.2102e-03 +XStrontianite: 9.9879e-01 +XCa: 4.9285e-02 +XSr: 9.5072e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 86 +SrCO3 added: 8.6000e+00 +Log Sigma pi: -9.2496e+00 +XAragonite: 1.1964e-03 +XStrontianite: 9.9880e-01 +XCa: 4.8749e-02 +XSr: 9.5125e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 87 +SrCO3 added: 8.7000e+00 +Log Sigma pi: -9.2498e+00 +XAragonite: 1.1830e-03 +XStrontianite: 9.9882e-01 +XCa: 4.8225e-02 +XSr: 9.5178e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 88 +SrCO3 added: 8.8000e+00 +Log Sigma pi: -9.2500e+00 +XAragonite: 1.1698e-03 +XStrontianite: 9.9883e-01 +XCa: 4.7712e-02 +XSr: 9.5229e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 89 +SrCO3 added: 8.9000e+00 +Log Sigma pi: -9.2503e+00 +XAragonite: 1.1570e-03 +XStrontianite: 9.9884e-01 +XCa: 4.7209e-02 +XSr: 9.5279e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 90 +SrCO3 added: 9 +Log Sigma pi: -9.2505e+00 +XAragonite: 1.1444e-03 +XStrontianite: 9.9886e-01 +XCa: 4.6718e-02 +XSr: 9.5328e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 91 +SrCO3 added: 9.1000e+00 +Log Sigma pi: -9.2507e+00 +XAragonite: 1.1321e-03 +XStrontianite: 9.9887e-01 +XCa: 4.6236e-02 +XSr: 9.5376e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 92 +SrCO3 added: 9.2000e+00 +Log Sigma pi: -9.2509e+00 +XAragonite: 1.1201e-03 +XStrontianite: 9.9888e-01 +XCa: 4.5764e-02 +XSr: 9.5424e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 93 +SrCO3 added: 9.3000e+00 +Log Sigma pi: -9.2511e+00 +XAragonite: 1.1083e-03 +XStrontianite: 9.9889e-01 +XCa: 4.5302e-02 +XSr: 9.5470e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 94 +SrCO3 added: 9.4000e+00 +Log Sigma pi: -9.2513e+00 +XAragonite: 1.0967e-03 +XStrontianite: 9.9890e-01 +XCa: 4.4849e-02 +XSr: 9.5515e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 95 +SrCO3 added: 9.5000e+00 +Log Sigma pi: -9.2515e+00 +XAragonite: 1.0854e-03 +XStrontianite: 9.9891e-01 +XCa: 4.4405e-02 +XSr: 9.5560e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 96 +SrCO3 added: 9.6000e+00 +Log Sigma pi: -9.2517e+00 +XAragonite: 1.0744e-03 +XStrontianite: 9.9893e-01 +XCa: 4.3969e-02 +XSr: 9.5603e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 97 +SrCO3 added: 9.7000e+00 +Log Sigma pi: -9.2519e+00 +XAragonite: 1.0635e-03 +XStrontianite: 9.9894e-01 +XCa: 4.3543e-02 +XSr: 9.5646e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 98 +SrCO3 added: 9.8000e+00 +Log Sigma pi: -9.2521e+00 +XAragonite: 1.0529e-03 +XStrontianite: 9.9895e-01 +XCa: 4.3124e-02 +XSr: 9.5688e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 99 +SrCO3 added: 9.9000e+00 +Log Sigma pi: -9.2523e+00 +XAragonite: 1.0425e-03 +XStrontianite: 9.9896e-01 +XCa: 4.2713e-02 +XSr: 9.5729e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +----------------------------------User print----------------------------------- + +Simulation number: 6 +Reaction step number: 100 +SrCO3 added: 10 +Log Sigma pi: -9.2525e+00 +XAragonite: 1.0323e-03 +XStrontianite: 9.9897e-01 +XCa: 4.2310e-02 +XSr: 9.5769e-01 +Misc 1: 4.8032e-03 +Misc 2: 8.5786e-01 + +No memory leaks diff --git a/Sun/examples/ex10.sel b/Sun/examples/ex10.sel new file mode 100644 index 00000000..a04f5970 --- /dev/null +++ b/Sun/examples/ex10.sel @@ -0,0 +1,701 @@ + reaction lg_SigmaPi X_Arag X_Stront X_Ca_aq X_Sr_aq mol_Misc1 mol_Misc2 mol_Arag mol_Stront + 1.0000e-05 -8.3356e+00 9.9996e-01 4.2096e-05 9.9905e-01 9.4867e-04 1.0000e-10 1.0000e-10 6.5428e-06 2.7544e-10 + 2.0000e-05 -8.3352e+00 9.9992e-01 8.4301e-05 9.9810e-01 1.8967e-03 1.0000e-10 1.0000e-10 1.3083e-05 1.1030e-09 + 3.0000e-05 -8.3348e+00 9.9987e-01 1.2662e-04 9.9716e-01 2.8440e-03 1.0000e-10 1.0000e-10 1.9622e-05 2.4848e-09 + 4.0000e-05 -8.3345e+00 9.9983e-01 1.6904e-04 9.9621e-01 3.7906e-03 1.0000e-10 1.0000e-10 2.6159e-05 4.4226e-09 + 5.0000e-05 -8.3341e+00 9.9979e-01 2.1158e-04 9.9526e-01 4.7366e-03 1.0000e-10 1.0000e-10 3.2693e-05 6.9185e-09 + 6.0000e-05 -8.3337e+00 9.9975e-01 2.5422e-04 9.9432e-01 5.6819e-03 1.0000e-10 1.0000e-10 3.9225e-05 9.9745e-09 + 7.0000e-05 -8.3333e+00 9.9970e-01 2.9698e-04 9.9337e-01 6.6265e-03 1.0000e-10 1.0000e-10 4.5755e-05 1.3593e-08 + 8.0000e-05 -8.3329e+00 9.9966e-01 3.3985e-04 9.9243e-01 7.5705e-03 1.0000e-10 1.0000e-10 5.2283e-05 1.7775e-08 + 9.0000e-05 -8.3325e+00 9.9962e-01 3.8284e-04 9.9149e-01 8.5137e-03 1.0000e-10 1.0000e-10 5.8809e-05 2.2523e-08 + 1.0000e-04 -8.3321e+00 9.9957e-01 4.2593e-04 9.9054e-01 9.4563e-03 1.0000e-10 1.0000e-10 6.5333e-05 2.7839e-08 + 1.1000e-04 -8.3318e+00 9.9953e-01 4.6914e-04 9.8960e-01 1.0398e-02 1.0000e-10 1.0000e-10 7.1855e-05 3.3726e-08 + 1.2000e-04 -8.3314e+00 9.9949e-01 5.1247e-04 9.8866e-01 1.1340e-02 1.0000e-10 1.0000e-10 7.8374e-05 4.0185e-08 + 1.3000e-04 -8.3310e+00 9.9944e-01 5.5591e-04 9.8772e-01 1.2280e-02 1.0000e-10 1.0000e-10 8.4891e-05 4.7218e-08 + 1.4000e-04 -8.3306e+00 9.9940e-01 5.9946e-04 9.8678e-01 1.3220e-02 1.0000e-10 1.0000e-10 9.1407e-05 5.4828e-08 + 1.5000e-04 -8.3302e+00 9.9936e-01 6.4313e-04 9.8584e-01 1.4159e-02 1.0000e-10 1.0000e-10 9.7920e-05 6.3016e-08 + 1.6000e-04 -8.3298e+00 9.9931e-01 6.8692e-04 9.8490e-01 1.5098e-02 1.0000e-10 1.0000e-10 1.0443e-04 7.1784e-08 + 1.7000e-04 -8.3294e+00 9.9927e-01 7.3082e-04 9.8396e-01 1.6036e-02 1.0000e-10 1.0000e-10 1.1094e-04 8.1136e-08 + 1.8000e-04 -8.3290e+00 9.9923e-01 7.7484e-04 9.8303e-01 1.6973e-02 1.0000e-10 1.0000e-10 1.1745e-04 9.1072e-08 + 1.9000e-04 -8.3287e+00 9.9918e-01 8.1897e-04 9.8209e-01 1.7909e-02 1.0000e-10 1.0000e-10 1.2395e-04 1.0160e-07 + 2.0000e-04 -8.3283e+00 9.9914e-01 8.6323e-04 9.8115e-01 1.8845e-02 1.0000e-10 1.0000e-10 1.3045e-04 1.1271e-07 + 2.1000e-04 -8.3279e+00 9.9909e-01 9.0760e-04 9.8022e-01 1.9780e-02 1.0000e-10 1.0000e-10 1.3695e-04 1.2441e-07 + 2.2000e-04 -8.3275e+00 9.9905e-01 9.5209e-04 9.7929e-01 2.0715e-02 1.0000e-10 1.0000e-10 1.4345e-04 1.3671e-07 + 2.3000e-04 -8.3271e+00 9.9900e-01 9.9670e-04 9.7835e-01 2.1649e-02 1.0000e-10 1.0000e-10 1.4995e-04 1.4960e-07 + 2.4000e-04 -8.3267e+00 9.9896e-01 1.0414e-03 9.7742e-01 2.2582e-02 1.0000e-10 1.0000e-10 1.5644e-04 1.6309e-07 + 2.5000e-04 -8.3263e+00 9.9891e-01 1.0863e-03 9.7649e-01 2.3514e-02 1.0000e-10 1.0000e-10 1.6293e-04 1.7719e-07 + 2.6000e-04 -8.3259e+00 9.9887e-01 1.1313e-03 9.7555e-01 2.4446e-02 1.0000e-10 1.0000e-10 1.6942e-04 1.9188e-07 + 2.7000e-04 -8.3256e+00 9.9882e-01 1.1764e-03 9.7462e-01 2.5377e-02 1.0000e-10 1.0000e-10 1.7591e-04 2.0718e-07 + 2.8000e-04 -8.3252e+00 9.9878e-01 1.2216e-03 9.7369e-01 2.6308e-02 1.0000e-10 1.0000e-10 1.8240e-04 2.2308e-07 + 2.9000e-04 -8.3248e+00 9.9873e-01 1.2669e-03 9.7276e-01 2.7238e-02 1.0000e-10 1.0000e-10 1.8888e-04 2.3960e-07 + 3.0000e-04 -8.3244e+00 9.9869e-01 1.3124e-03 9.7183e-01 2.8167e-02 1.0000e-10 1.0000e-10 1.9536e-04 2.5672e-07 + 3.1000e-04 -8.3240e+00 9.9864e-01 1.3580e-03 9.7090e-01 2.9095e-02 1.0000e-10 1.0000e-10 2.0184e-04 2.7446e-07 + 3.2000e-04 -8.3236e+00 9.9860e-01 1.4037e-03 9.6998e-01 3.0023e-02 1.0000e-10 1.0000e-10 2.0832e-04 2.9282e-07 + 3.3000e-04 -8.3232e+00 9.9855e-01 1.4495e-03 9.6905e-01 3.0950e-02 1.0000e-10 1.0000e-10 2.1479e-04 3.1179e-07 + 3.4000e-04 -8.3228e+00 9.9850e-01 1.4955e-03 9.6812e-01 3.1877e-02 1.0000e-10 1.0000e-10 2.2126e-04 3.3139e-07 + 3.5000e-04 -8.3225e+00 9.9846e-01 1.5416e-03 9.6720e-01 3.2802e-02 1.0000e-10 1.0000e-10 2.2773e-04 3.5161e-07 + 3.6000e-04 -8.3221e+00 9.9841e-01 1.5878e-03 9.6627e-01 3.3727e-02 1.0000e-10 1.0000e-10 2.3420e-04 3.7245e-07 + 3.7000e-04 -8.3217e+00 9.9837e-01 1.6341e-03 9.6535e-01 3.4652e-02 1.0000e-10 1.0000e-10 2.4067e-04 3.9392e-07 + 3.8000e-04 -8.3213e+00 9.9832e-01 1.6806e-03 9.6442e-01 3.5576e-02 1.0000e-10 1.0000e-10 2.4713e-04 4.1602e-07 + 3.9000e-04 -8.3209e+00 9.9827e-01 1.7272e-03 9.6350e-01 3.6499e-02 1.0000e-10 1.0000e-10 2.5359e-04 4.3876e-07 + 4.0000e-04 -8.3205e+00 9.9823e-01 1.7739e-03 9.6258e-01 3.7421e-02 1.0000e-10 1.0000e-10 2.6005e-04 4.6213e-07 + 4.1000e-04 -8.3201e+00 9.9818e-01 1.8208e-03 9.6166e-01 3.8343e-02 1.0000e-10 1.0000e-10 2.6651e-04 4.8614e-07 + 4.2000e-04 -8.3197e+00 9.9813e-01 1.8677e-03 9.6074e-01 3.9264e-02 1.0000e-10 1.0000e-10 2.7297e-04 5.1078e-07 + 4.3000e-04 -8.3193e+00 9.9809e-01 1.9149e-03 9.5982e-01 4.0184e-02 1.0000e-10 1.0000e-10 2.7942e-04 5.3607e-07 + 4.4000e-04 -8.3190e+00 9.9804e-01 1.9621e-03 9.5890e-01 4.1104e-02 1.0000e-10 1.0000e-10 2.8587e-04 5.6201e-07 + 4.5000e-04 -8.3186e+00 9.9799e-01 2.0095e-03 9.5798e-01 4.2023e-02 1.0000e-10 1.0000e-10 2.9232e-04 5.8859e-07 + 4.6000e-04 -8.3182e+00 9.9794e-01 2.0570e-03 9.5706e-01 4.2941e-02 1.0000e-10 1.0000e-10 2.9877e-04 6.1583e-07 + 4.7000e-04 -8.3178e+00 9.9790e-01 2.1046e-03 9.5614e-01 4.3859e-02 1.0000e-10 1.0000e-10 3.0521e-04 6.4371e-07 + 4.8000e-04 -8.3174e+00 9.9785e-01 2.1524e-03 9.5522e-01 4.4776e-02 1.0000e-10 1.0000e-10 3.1165e-04 6.7225e-07 + 4.9000e-04 -8.3170e+00 9.9780e-01 2.2003e-03 9.5431e-01 4.5692e-02 1.0000e-10 1.0000e-10 3.1809e-04 7.0145e-07 + 5.0000e-04 -8.3166e+00 9.9775e-01 2.2484e-03 9.5339e-01 4.6608e-02 1.0000e-10 1.0000e-10 3.2453e-04 7.3131e-07 + 5.1000e-04 -8.3162e+00 9.9770e-01 2.2966e-03 9.5248e-01 4.7523e-02 1.0000e-10 1.0000e-10 3.3097e-04 7.6183e-07 + 5.2000e-04 -8.3159e+00 9.9766e-01 2.3449e-03 9.5156e-01 4.8437e-02 1.0000e-10 1.0000e-10 3.3740e-04 7.9302e-07 + 5.3000e-04 -8.3155e+00 9.9761e-01 2.3933e-03 9.5065e-01 4.9351e-02 1.0000e-10 1.0000e-10 3.4383e-04 8.2488e-07 + 5.4000e-04 -8.3151e+00 9.9756e-01 2.4419e-03 9.4974e-01 5.0264e-02 1.0000e-10 1.0000e-10 3.5026e-04 8.5740e-07 + 5.5000e-04 -8.3147e+00 9.9751e-01 2.4907e-03 9.4882e-01 5.1176e-02 1.0000e-10 1.0000e-10 3.5669e-04 8.9060e-07 + 5.6000e-04 -8.3143e+00 9.9746e-01 2.5395e-03 9.4791e-01 5.2088e-02 1.0000e-10 1.0000e-10 3.6311e-04 9.2448e-07 + 5.7000e-04 -8.3139e+00 9.9741e-01 2.5885e-03 9.4700e-01 5.2999e-02 1.0000e-10 1.0000e-10 3.6954e-04 9.5904e-07 + 5.8000e-04 -8.3135e+00 9.9736e-01 2.6377e-03 9.4609e-01 5.3909e-02 1.0000e-10 1.0000e-10 3.7596e-04 9.9428e-07 + 5.9000e-04 -8.3131e+00 9.9731e-01 2.6870e-03 9.4518e-01 5.4819e-02 1.0000e-10 1.0000e-10 3.8237e-04 1.0302e-06 + 6.0000e-04 -8.3127e+00 9.9726e-01 2.7364e-03 9.4427e-01 5.5728e-02 1.0000e-10 1.0000e-10 3.8879e-04 1.0668e-06 + 6.1000e-04 -8.3123e+00 9.9721e-01 2.7860e-03 9.4336e-01 5.6636e-02 1.0000e-10 1.0000e-10 3.9520e-04 1.1041e-06 + 6.2000e-04 -8.3120e+00 9.9716e-01 2.8357e-03 9.4246e-01 5.7544e-02 1.0000e-10 1.0000e-10 4.0162e-04 1.1421e-06 + 6.3000e-04 -8.3116e+00 9.9711e-01 2.8856e-03 9.4155e-01 5.8451e-02 1.0000e-10 1.0000e-10 4.0803e-04 1.1808e-06 + 6.4000e-04 -8.3112e+00 9.9706e-01 2.9356e-03 9.4064e-01 5.9357e-02 1.0000e-10 1.0000e-10 4.1443e-04 1.2202e-06 + 6.5000e-04 -8.3108e+00 9.9701e-01 2.9857e-03 9.3974e-01 6.0263e-02 1.0000e-10 1.0000e-10 4.2084e-04 1.2603e-06 + 6.6000e-04 -8.3104e+00 9.9696e-01 3.0360e-03 9.3883e-01 6.1167e-02 1.0000e-10 1.0000e-10 4.2724e-04 1.3011e-06 + 6.7000e-04 -8.3100e+00 9.9691e-01 3.0864e-03 9.3793e-01 6.2072e-02 1.0000e-10 1.0000e-10 4.3364e-04 1.3426e-06 + 6.8000e-04 -8.3096e+00 9.9686e-01 3.1370e-03 9.3702e-01 6.2975e-02 1.0000e-10 1.0000e-10 4.4004e-04 1.3848e-06 + 6.9000e-04 -8.3092e+00 9.9681e-01 3.1878e-03 9.3612e-01 6.3878e-02 1.0000e-10 1.0000e-10 4.4644e-04 1.4277e-06 + 7.0000e-04 -8.3088e+00 9.9676e-01 3.2386e-03 9.3522e-01 6.4780e-02 1.0000e-10 1.0000e-10 4.5283e-04 1.4713e-06 + 7.1000e-04 -8.3084e+00 9.9671e-01 3.2897e-03 9.3432e-01 6.5682e-02 1.0000e-10 1.0000e-10 4.5922e-04 1.5157e-06 + 7.2000e-04 -8.3081e+00 9.9666e-01 3.3409e-03 9.3342e-01 6.6583e-02 1.0000e-10 1.0000e-10 4.6561e-04 1.5608e-06 + 7.3000e-04 -8.3077e+00 9.9661e-01 3.3922e-03 9.3252e-01 6.7483e-02 1.0000e-10 1.0000e-10 4.7200e-04 1.6066e-06 + 7.4000e-04 -8.3073e+00 9.9656e-01 3.4437e-03 9.3162e-01 6.8383e-02 1.0000e-10 1.0000e-10 4.7839e-04 1.6531e-06 + 7.5000e-04 -8.3069e+00 9.9650e-01 3.4953e-03 9.3072e-01 6.9282e-02 1.0000e-10 1.0000e-10 4.8477e-04 1.7004e-06 + 7.6000e-04 -8.3065e+00 9.9645e-01 3.5471e-03 9.2982e-01 7.0180e-02 1.0000e-10 1.0000e-10 4.9115e-04 1.7484e-06 + 7.7000e-04 -8.3061e+00 9.9640e-01 3.5990e-03 9.2892e-01 7.1077e-02 1.0000e-10 1.0000e-10 4.9753e-04 1.7971e-06 + 7.8000e-04 -8.3057e+00 9.9635e-01 3.6511e-03 9.2803e-01 7.1974e-02 1.0000e-10 1.0000e-10 5.0391e-04 1.8466e-06 + 7.9000e-04 -8.3053e+00 9.9630e-01 3.7034e-03 9.2713e-01 7.2870e-02 1.0000e-10 1.0000e-10 5.1028e-04 1.8968e-06 + 8.0000e-04 -8.3049e+00 9.9624e-01 3.7558e-03 9.2623e-01 7.3766e-02 1.0000e-10 1.0000e-10 5.1665e-04 1.9477e-06 + 8.1000e-04 -8.3045e+00 9.9619e-01 3.8083e-03 9.2534e-01 7.4661e-02 1.0000e-10 1.0000e-10 5.2302e-04 1.9995e-06 + 8.2000e-04 -8.3042e+00 9.9614e-01 3.8611e-03 9.2445e-01 7.5555e-02 1.0000e-10 1.0000e-10 5.2939e-04 2.0519e-06 + 8.3000e-04 -8.3038e+00 9.9609e-01 3.9139e-03 9.2355e-01 7.6448e-02 1.0000e-10 1.0000e-10 5.3576e-04 2.1052e-06 + 8.4000e-04 -8.3034e+00 9.9603e-01 3.9670e-03 9.2266e-01 7.7341e-02 1.0000e-10 1.0000e-10 5.4212e-04 2.1591e-06 + 8.5000e-04 -8.3030e+00 9.9598e-01 4.0202e-03 9.2177e-01 7.8233e-02 1.0000e-10 1.0000e-10 5.4848e-04 2.2139e-06 + 8.6000e-04 -8.3026e+00 9.9593e-01 4.0735e-03 9.2088e-01 7.9125e-02 1.0000e-10 1.0000e-10 5.5484e-04 2.2694e-06 + 8.7000e-04 -8.3022e+00 9.9587e-01 4.1270e-03 9.1998e-01 8.0016e-02 1.0000e-10 1.0000e-10 5.6120e-04 2.3257e-06 + 8.8000e-04 -8.3018e+00 9.9582e-01 4.1807e-03 9.1909e-01 8.0906e-02 1.0000e-10 1.0000e-10 5.6755e-04 2.3827e-06 + 8.9000e-04 -8.3014e+00 9.9577e-01 4.2346e-03 9.1820e-01 8.1795e-02 1.0000e-10 1.0000e-10 5.7390e-04 2.4406e-06 + 9.0000e-04 -8.3010e+00 9.9571e-01 4.2886e-03 9.1732e-01 8.2684e-02 1.0000e-10 1.0000e-10 5.8025e-04 2.4992e-06 + 9.1000e-04 -8.3006e+00 9.9566e-01 4.3427e-03 9.1643e-01 8.3572e-02 1.0000e-10 1.0000e-10 5.8660e-04 2.5586e-06 + 9.2000e-04 -8.3002e+00 9.9560e-01 4.3971e-03 9.1554e-01 8.4460e-02 1.0000e-10 1.0000e-10 5.9295e-04 2.6187e-06 + 9.3000e-04 -8.2999e+00 9.9555e-01 4.4516e-03 9.1465e-01 8.5347e-02 1.0000e-10 1.0000e-10 5.9929e-04 2.6797e-06 + 9.4000e-04 -8.2995e+00 9.9549e-01 4.5062e-03 9.1377e-01 8.6233e-02 1.0000e-10 1.0000e-10 6.0563e-04 2.7415e-06 + 9.5000e-04 -8.2991e+00 9.9544e-01 4.5611e-03 9.1288e-01 8.7118e-02 1.0000e-10 1.0000e-10 6.1197e-04 2.8040e-06 + 9.6000e-04 -8.2987e+00 9.9538e-01 4.6161e-03 9.1200e-01 8.8003e-02 1.0000e-10 1.0000e-10 6.1831e-04 2.8674e-06 + 9.7000e-04 -8.2983e+00 9.9533e-01 4.6713e-03 9.1111e-01 8.8887e-02 1.0000e-10 1.0000e-10 6.2464e-04 2.9316e-06 + 9.8000e-04 -8.2979e+00 9.9527e-01 4.7266e-03 9.1023e-01 8.9770e-02 1.0000e-10 1.0000e-10 6.3097e-04 2.9965e-06 + 9.9000e-04 -8.2975e+00 9.9522e-01 4.7821e-03 9.0935e-01 9.0653e-02 1.0000e-10 1.0000e-10 6.3730e-04 3.0623e-06 + 1.0000e-03 -8.2974e+00 9.8567e-01 1.4329e-02 9.0901e-01 9.0987e-02 6.4175e-04 7.2473e-06 6.3970e-04 9.2997e-06 + 1.0100e-03 -8.2974e+00 9.7071e-01 2.9286e-02 9.0901e-01 9.0987e-02 6.4009e-04 1.8914e-05 6.3970e-04 1.9300e-05 + 1.0200e-03 -8.2974e+00 9.5620e-01 4.3796e-02 9.0901e-01 9.0987e-02 6.3842e-04 3.0580e-05 6.3970e-04 2.9300e-05 + 1.0300e-03 -8.2974e+00 9.4212e-01 5.7879e-02 9.0901e-01 9.0987e-02 6.3675e-04 4.2246e-05 6.3970e-04 3.9300e-05 + 1.0400e-03 -8.2974e+00 9.2845e-01 7.1552e-02 9.0901e-01 9.0987e-02 6.3509e-04 5.3912e-05 6.3970e-04 4.9300e-05 + 1.0500e-03 -8.2974e+00 9.1516e-01 8.4835e-02 9.0901e-01 9.0987e-02 6.3342e-04 6.5578e-05 6.3970e-04 5.9300e-05 + 1.0600e-03 -8.2974e+00 9.0226e-01 9.7743e-02 9.0901e-01 9.0987e-02 6.3176e-04 7.7245e-05 6.3970e-04 6.9300e-05 + 1.0700e-03 -8.2974e+00 8.8971e-01 1.1029e-01 9.0901e-01 9.0987e-02 6.3009e-04 8.8911e-05 6.3970e-04 7.9300e-05 + 1.0800e-03 -8.2974e+00 8.7750e-01 1.2250e-01 9.0901e-01 9.0987e-02 6.2842e-04 1.0058e-04 6.3970e-04 8.9300e-05 + 1.0900e-03 -8.2974e+00 8.6563e-01 1.3437e-01 9.0901e-01 9.0987e-02 6.2676e-04 1.1224e-04 6.3970e-04 9.9300e-05 + 1.1000e-03 -8.2974e+00 8.5407e-01 1.4593e-01 9.0901e-01 9.0987e-02 6.2509e-04 1.2391e-04 6.3970e-04 1.0930e-04 + 1.1100e-03 -8.2974e+00 8.4282e-01 1.5718e-01 9.0901e-01 9.0987e-02 6.2342e-04 1.3558e-04 6.3970e-04 1.1930e-04 + 1.1200e-03 -8.2974e+00 8.3186e-01 1.6814e-01 9.0901e-01 9.0987e-02 6.2176e-04 1.4724e-04 6.3970e-04 1.2930e-04 + 1.1300e-03 -8.2974e+00 8.2118e-01 1.7882e-01 9.0901e-01 9.0987e-02 6.2009e-04 1.5891e-04 6.3970e-04 1.3930e-04 + 1.1400e-03 -8.2974e+00 8.1077e-01 1.8923e-01 9.0901e-01 9.0987e-02 6.1843e-04 1.7057e-04 6.3970e-04 1.4930e-04 + 1.1500e-03 -8.2974e+00 8.0063e-01 1.9937e-01 9.0901e-01 9.0987e-02 6.1676e-04 1.8224e-04 6.3970e-04 1.5930e-04 + 1.1600e-03 -8.2974e+00 7.9073e-01 2.0927e-01 9.0901e-01 9.0987e-02 6.1509e-04 1.9391e-04 6.3970e-04 1.6930e-04 + 1.1700e-03 -8.2974e+00 7.8107e-01 2.1893e-01 9.0901e-01 9.0987e-02 6.1343e-04 2.0557e-04 6.3970e-04 1.7930e-04 + 1.1800e-03 -8.2974e+00 7.7165e-01 2.2835e-01 9.0901e-01 9.0987e-02 6.1176e-04 2.1724e-04 6.3970e-04 1.8930e-04 + 1.1900e-03 -8.2974e+00 7.6246e-01 2.3754e-01 9.0901e-01 9.0987e-02 6.1009e-04 2.2891e-04 6.3970e-04 1.9930e-04 + 1.2000e-03 -8.2974e+00 7.5348e-01 2.4652e-01 9.0901e-01 9.0987e-02 6.0843e-04 2.4057e-04 6.3970e-04 2.0930e-04 + 1.2100e-03 -8.2974e+00 7.4470e-01 2.5530e-01 9.0901e-01 9.0987e-02 6.0676e-04 2.5224e-04 6.3970e-04 2.1930e-04 + 1.2200e-03 -8.2974e+00 7.3613e-01 2.6387e-01 9.0901e-01 9.0987e-02 6.0510e-04 2.6390e-04 6.3970e-04 2.2930e-04 + 1.2300e-03 -8.2974e+00 7.2776e-01 2.7224e-01 9.0901e-01 9.0987e-02 6.0343e-04 2.7557e-04 6.3970e-04 2.3930e-04 + 1.2400e-03 -8.2974e+00 7.1957e-01 2.8043e-01 9.0901e-01 9.0987e-02 6.0176e-04 2.8724e-04 6.3970e-04 2.4930e-04 + 1.2500e-03 -8.2974e+00 7.1157e-01 2.8843e-01 9.0901e-01 9.0987e-02 6.0010e-04 2.9890e-04 6.3970e-04 2.5930e-04 + 1.2600e-03 -8.2974e+00 7.0374e-01 2.9626e-01 9.0901e-01 9.0987e-02 5.9843e-04 3.1057e-04 6.3970e-04 2.6930e-04 + 1.2700e-03 -8.2974e+00 6.9608e-01 3.0392e-01 9.0901e-01 9.0987e-02 5.9677e-04 3.2223e-04 6.3970e-04 2.7930e-04 + 1.2800e-03 -8.2974e+00 6.8859e-01 3.1141e-01 9.0901e-01 9.0987e-02 5.9510e-04 3.3390e-04 6.3970e-04 2.8930e-04 + 1.2900e-03 -8.2974e+00 6.8126e-01 3.1874e-01 9.0901e-01 9.0987e-02 5.9343e-04 3.4557e-04 6.3970e-04 2.9930e-04 + 1.3000e-03 -8.2974e+00 6.7408e-01 3.2592e-01 9.0901e-01 9.0987e-02 5.9177e-04 3.5723e-04 6.3970e-04 3.0930e-04 + 1.3100e-03 -8.2974e+00 6.6705e-01 3.3295e-01 9.0901e-01 9.0987e-02 5.9010e-04 3.6890e-04 6.3970e-04 3.1930e-04 + 1.3200e-03 -8.2974e+00 6.6017e-01 3.3983e-01 9.0901e-01 9.0987e-02 5.8843e-04 3.8057e-04 6.3970e-04 3.2930e-04 + 1.3300e-03 -8.2974e+00 6.5342e-01 3.4658e-01 9.0901e-01 9.0987e-02 5.8677e-04 3.9223e-04 6.3970e-04 3.3930e-04 + 1.3400e-03 -8.2974e+00 6.4682e-01 3.5318e-01 9.0901e-01 9.0987e-02 5.8510e-04 4.0390e-04 6.3970e-04 3.4930e-04 + 1.3500e-03 -8.2974e+00 6.4034e-01 3.5966e-01 9.0901e-01 9.0987e-02 5.8344e-04 4.1556e-04 6.3970e-04 3.5930e-04 + 1.3600e-03 -8.2974e+00 6.3399e-01 3.6601e-01 9.0901e-01 9.0987e-02 5.8177e-04 4.2723e-04 6.3970e-04 3.6930e-04 + 1.3700e-03 -8.2974e+00 6.2777e-01 3.7223e-01 9.0901e-01 9.0987e-02 5.8010e-04 4.3890e-04 6.3970e-04 3.7930e-04 + 1.3800e-03 -8.2974e+00 6.2167e-01 3.7833e-01 9.0901e-01 9.0987e-02 5.7844e-04 4.5056e-04 6.3970e-04 3.8930e-04 + 1.3900e-03 -8.2974e+00 6.1569e-01 3.8431e-01 9.0901e-01 9.0987e-02 5.7677e-04 4.6223e-04 6.3970e-04 3.9930e-04 + 1.4000e-03 -8.2974e+00 6.0982e-01 3.9018e-01 9.0901e-01 9.0987e-02 5.7510e-04 4.7390e-04 6.3970e-04 4.0930e-04 + 1.4100e-03 -8.2974e+00 6.0406e-01 3.9594e-01 9.0901e-01 9.0987e-02 5.7344e-04 4.8556e-04 6.3970e-04 4.1930e-04 + 1.4200e-03 -8.2974e+00 5.9841e-01 4.0159e-01 9.0901e-01 9.0987e-02 5.7177e-04 4.9723e-04 6.3970e-04 4.2930e-04 + 1.4300e-03 -8.2974e+00 5.9286e-01 4.0714e-01 9.0901e-01 9.0987e-02 5.7011e-04 5.0889e-04 6.3970e-04 4.3930e-04 + 1.4400e-03 -8.2974e+00 5.8742e-01 4.1258e-01 9.0901e-01 9.0987e-02 5.6844e-04 5.2056e-04 6.3970e-04 4.4930e-04 + 1.4500e-03 -8.2974e+00 5.8207e-01 4.1793e-01 9.0901e-01 9.0987e-02 5.6677e-04 5.3223e-04 6.3970e-04 4.5930e-04 + 1.4600e-03 -8.2974e+00 5.7683e-01 4.2317e-01 9.0901e-01 9.0987e-02 5.6511e-04 5.4389e-04 6.3970e-04 4.6930e-04 + 1.4700e-03 -8.2974e+00 5.7167e-01 4.2833e-01 9.0901e-01 9.0987e-02 5.6344e-04 5.5556e-04 6.3970e-04 4.7930e-04 + 1.4800e-03 -8.2974e+00 5.6661e-01 4.3339e-01 9.0901e-01 9.0987e-02 5.6178e-04 5.6723e-04 6.3970e-04 4.8930e-04 + 1.4900e-03 -8.2974e+00 5.6163e-01 4.3837e-01 9.0901e-01 9.0987e-02 5.6011e-04 5.7889e-04 6.3970e-04 4.9930e-04 + 1.5000e-03 -8.2974e+00 5.5675e-01 4.4325e-01 9.0901e-01 9.0987e-02 5.5844e-04 5.9056e-04 6.3970e-04 5.0930e-04 + 1.5100e-03 -8.2974e+00 5.5194e-01 4.4806e-01 9.0901e-01 9.0987e-02 5.5678e-04 6.0222e-04 6.3970e-04 5.1930e-04 + 1.5200e-03 -8.2974e+00 5.4722e-01 4.5278e-01 9.0901e-01 9.0987e-02 5.5511e-04 6.1389e-04 6.3970e-04 5.2930e-04 + 1.5300e-03 -8.2974e+00 5.4258e-01 4.5742e-01 9.0901e-01 9.0987e-02 5.5344e-04 6.2556e-04 6.3970e-04 5.3930e-04 + 1.5400e-03 -8.2974e+00 5.3802e-01 4.6198e-01 9.0901e-01 9.0987e-02 5.5178e-04 6.3722e-04 6.3970e-04 5.4930e-04 + 1.5500e-03 -8.2974e+00 5.3353e-01 4.6647e-01 9.0901e-01 9.0987e-02 5.5011e-04 6.4889e-04 6.3970e-04 5.5930e-04 + 1.5600e-03 -8.2974e+00 5.2912e-01 4.7088e-01 9.0901e-01 9.0987e-02 5.4845e-04 6.6055e-04 6.3970e-04 5.6930e-04 + 1.5700e-03 -8.2974e+00 5.2477e-01 4.7523e-01 9.0901e-01 9.0987e-02 5.4678e-04 6.7222e-04 6.3970e-04 5.7930e-04 + 1.5800e-03 -8.2974e+00 5.2050e-01 4.7950e-01 9.0901e-01 9.0987e-02 5.4511e-04 6.8389e-04 6.3970e-04 5.8930e-04 + 1.5900e-03 -8.2974e+00 5.1630e-01 4.8370e-01 9.0901e-01 9.0987e-02 5.4345e-04 6.9555e-04 6.3970e-04 5.9930e-04 + 1.6000e-03 -8.2974e+00 5.1217e-01 4.8783e-01 9.0901e-01 9.0987e-02 5.4178e-04 7.0722e-04 6.3970e-04 6.0930e-04 + 1.6100e-03 -8.2974e+00 5.0810e-01 4.9190e-01 9.0901e-01 9.0987e-02 5.4011e-04 7.1889e-04 6.3970e-04 6.1930e-04 + 1.6200e-03 -8.2974e+00 5.0410e-01 4.9590e-01 9.0901e-01 9.0987e-02 5.3845e-04 7.3055e-04 6.3970e-04 6.2930e-04 + 1.6300e-03 -8.2974e+00 5.0016e-01 4.9984e-01 9.0901e-01 9.0987e-02 5.3678e-04 7.4222e-04 6.3970e-04 6.3930e-04 + 1.6400e-03 -8.2974e+00 4.9628e-01 5.0372e-01 9.0901e-01 9.0987e-02 5.3512e-04 7.5388e-04 6.3970e-04 6.4930e-04 + 1.6500e-03 -8.2974e+00 4.9246e-01 5.0754e-01 9.0901e-01 9.0987e-02 5.3345e-04 7.6555e-04 6.3970e-04 6.5930e-04 + 1.6600e-03 -8.2974e+00 4.8869e-01 5.1131e-01 9.0901e-01 9.0987e-02 5.3178e-04 7.7722e-04 6.3970e-04 6.6930e-04 + 1.6700e-03 -8.2974e+00 4.8499e-01 5.1501e-01 9.0901e-01 9.0987e-02 5.3012e-04 7.8888e-04 6.3970e-04 6.7930e-04 + 1.6800e-03 -8.2974e+00 4.8134e-01 5.1866e-01 9.0901e-01 9.0987e-02 5.2845e-04 8.0055e-04 6.3970e-04 6.8930e-04 + 1.6900e-03 -8.2974e+00 4.7774e-01 5.2226e-01 9.0901e-01 9.0987e-02 5.2678e-04 8.1222e-04 6.3970e-04 6.9930e-04 + 1.7000e-03 -8.2974e+00 4.7420e-01 5.2580e-01 9.0901e-01 9.0987e-02 5.2512e-04 8.2388e-04 6.3970e-04 7.0930e-04 + 1.7100e-03 -8.2974e+00 4.7071e-01 5.2929e-01 9.0901e-01 9.0987e-02 5.2345e-04 8.3555e-04 6.3970e-04 7.1930e-04 + 1.7200e-03 -8.2974e+00 4.6728e-01 5.3272e-01 9.0901e-01 9.0987e-02 5.2179e-04 8.4721e-04 6.3970e-04 7.2930e-04 + 1.7300e-03 -8.2974e+00 4.6389e-01 5.3611e-01 9.0901e-01 9.0987e-02 5.2012e-04 8.5888e-04 6.3970e-04 7.3930e-04 + 1.7400e-03 -8.2974e+00 4.6055e-01 5.3945e-01 9.0901e-01 9.0987e-02 5.1845e-04 8.7055e-04 6.3970e-04 7.4930e-04 + 1.7500e-03 -8.2974e+00 4.5726e-01 5.4274e-01 9.0901e-01 9.0987e-02 5.1679e-04 8.8221e-04 6.3970e-04 7.5930e-04 + 1.7600e-03 -8.2974e+00 4.5401e-01 5.4599e-01 9.0901e-01 9.0987e-02 5.1512e-04 8.9388e-04 6.3970e-04 7.6930e-04 + 1.7700e-03 -8.2974e+00 4.5081e-01 5.4919e-01 9.0901e-01 9.0987e-02 5.1346e-04 9.0554e-04 6.3970e-04 7.7930e-04 + 1.7800e-03 -8.2974e+00 4.4766e-01 5.5234e-01 9.0901e-01 9.0987e-02 5.1179e-04 9.1721e-04 6.3970e-04 7.8930e-04 + 1.7900e-03 -8.2974e+00 4.4455e-01 5.5545e-01 9.0901e-01 9.0987e-02 5.1012e-04 9.2888e-04 6.3970e-04 7.9930e-04 + 1.8000e-03 -8.2974e+00 4.4148e-01 5.5852e-01 9.0901e-01 9.0987e-02 5.0846e-04 9.4054e-04 6.3970e-04 8.0930e-04 + 1.8100e-03 -8.2974e+00 4.3845e-01 5.6155e-01 9.0901e-01 9.0987e-02 5.0679e-04 9.5221e-04 6.3970e-04 8.1930e-04 + 1.8200e-03 -8.2974e+00 4.3547e-01 5.6453e-01 9.0901e-01 9.0987e-02 5.0512e-04 9.6388e-04 6.3970e-04 8.2930e-04 + 1.8300e-03 -8.2974e+00 4.3252e-01 5.6748e-01 9.0901e-01 9.0987e-02 5.0346e-04 9.7554e-04 6.3970e-04 8.3930e-04 + 1.8400e-03 -8.2974e+00 4.2962e-01 5.7038e-01 9.0901e-01 9.0987e-02 5.0179e-04 9.8721e-04 6.3970e-04 8.4930e-04 + 1.8500e-03 -8.2974e+00 4.2675e-01 5.7325e-01 9.0901e-01 9.0987e-02 5.0013e-04 9.9887e-04 6.3970e-04 8.5930e-04 + 1.8600e-03 -8.2974e+00 4.2392e-01 5.7608e-01 9.0901e-01 9.0987e-02 4.9846e-04 1.0105e-03 6.3970e-04 8.6930e-04 + 1.8700e-03 -8.2974e+00 4.2113e-01 5.7887e-01 9.0901e-01 9.0987e-02 4.9679e-04 1.0222e-03 6.3970e-04 8.7930e-04 + 1.8800e-03 -8.2974e+00 4.1838e-01 5.8162e-01 9.0901e-01 9.0987e-02 4.9513e-04 1.0339e-03 6.3970e-04 8.8930e-04 + 1.8900e-03 -8.2974e+00 4.1566e-01 5.8434e-01 9.0901e-01 9.0987e-02 4.9346e-04 1.0455e-03 6.3970e-04 8.9930e-04 + 1.9000e-03 -8.2974e+00 4.1298e-01 5.8702e-01 9.0901e-01 9.0987e-02 4.9179e-04 1.0572e-03 6.3970e-04 9.0930e-04 + 1.9100e-03 -8.2974e+00 4.1033e-01 5.8967e-01 9.0901e-01 9.0987e-02 4.9013e-04 1.0689e-03 6.3970e-04 9.1930e-04 + 1.9200e-03 -8.2974e+00 4.0771e-01 5.9229e-01 9.0901e-01 9.0987e-02 4.8846e-04 1.0805e-03 6.3970e-04 9.2930e-04 + 1.9300e-03 -8.2974e+00 4.0513e-01 5.9487e-01 9.0901e-01 9.0987e-02 4.8680e-04 1.0922e-03 6.3970e-04 9.3930e-04 + 1.9400e-03 -8.2974e+00 4.0258e-01 5.9742e-01 9.0901e-01 9.0987e-02 4.8513e-04 1.1039e-03 6.3970e-04 9.4930e-04 + 1.9500e-03 -8.2974e+00 4.0006e-01 5.9994e-01 9.0901e-01 9.0987e-02 4.8346e-04 1.1155e-03 6.3970e-04 9.5930e-04 + 1.9600e-03 -8.2974e+00 3.9758e-01 6.0242e-01 9.0901e-01 9.0987e-02 4.8180e-04 1.1272e-03 6.3970e-04 9.6930e-04 + 1.9700e-03 -8.2974e+00 3.9512e-01 6.0488e-01 9.0901e-01 9.0987e-02 4.8013e-04 1.1389e-03 6.3970e-04 9.7930e-04 + 1.9800e-03 -8.2974e+00 3.9270e-01 6.0730e-01 9.0901e-01 9.0987e-02 4.7846e-04 1.1505e-03 6.3970e-04 9.8930e-04 + 1.9900e-03 -8.2974e+00 3.9030e-01 6.0970e-01 9.0901e-01 9.0987e-02 4.7680e-04 1.1622e-03 6.3970e-04 9.9930e-04 + 2.0000e-03 -8.2974e+00 3.8793e-01 6.1207e-01 9.0901e-01 9.0987e-02 4.7513e-04 1.1739e-03 6.3970e-04 1.0093e-03 + 2.0100e-03 -8.2974e+00 3.8559e-01 6.1441e-01 9.0901e-01 9.0987e-02 4.7347e-04 1.1855e-03 6.3970e-04 1.0193e-03 + 2.0200e-03 -8.2974e+00 3.8328e-01 6.1672e-01 9.0901e-01 9.0987e-02 4.7180e-04 1.1972e-03 6.3970e-04 1.0293e-03 + 2.0300e-03 -8.2974e+00 3.8100e-01 6.1900e-01 9.0901e-01 9.0987e-02 4.7013e-04 1.2089e-03 6.3970e-04 1.0393e-03 + 2.0400e-03 -8.2974e+00 3.7875e-01 6.2125e-01 9.0901e-01 9.0987e-02 4.6847e-04 1.2205e-03 6.3970e-04 1.0493e-03 + 2.0500e-03 -8.2974e+00 3.7652e-01 6.2348e-01 9.0901e-01 9.0987e-02 4.6680e-04 1.2322e-03 6.3970e-04 1.0593e-03 + 2.0600e-03 -8.2974e+00 3.7431e-01 6.2569e-01 9.0901e-01 9.0987e-02 4.6514e-04 1.2439e-03 6.3970e-04 1.0693e-03 + 2.0700e-03 -8.2974e+00 3.7214e-01 6.2786e-01 9.0901e-01 9.0987e-02 4.6347e-04 1.2555e-03 6.3970e-04 1.0793e-03 + 2.0800e-03 -8.2974e+00 3.6998e-01 6.3002e-01 9.0901e-01 9.0987e-02 4.6180e-04 1.2672e-03 6.3970e-04 1.0893e-03 + 2.0900e-03 -8.2974e+00 3.6786e-01 6.3214e-01 9.0901e-01 9.0987e-02 4.6014e-04 1.2789e-03 6.3970e-04 1.0993e-03 + 2.1000e-03 -8.2974e+00 3.6575e-01 6.3425e-01 9.0901e-01 9.0987e-02 4.5847e-04 1.2905e-03 6.3970e-04 1.1093e-03 + 2.1100e-03 -8.2974e+00 3.6367e-01 6.3633e-01 9.0901e-01 9.0987e-02 4.5680e-04 1.3022e-03 6.3970e-04 1.1193e-03 + 2.1200e-03 -8.2974e+00 3.6162e-01 6.3838e-01 9.0901e-01 9.0987e-02 4.5514e-04 1.3139e-03 6.3970e-04 1.1293e-03 + 2.1300e-03 -8.2974e+00 3.5958e-01 6.4042e-01 9.0901e-01 9.0987e-02 4.5347e-04 1.3255e-03 6.3970e-04 1.1393e-03 + 2.1400e-03 -8.2974e+00 3.5757e-01 6.4243e-01 9.0901e-01 9.0987e-02 4.5181e-04 1.3372e-03 6.3970e-04 1.1493e-03 + 2.1500e-03 -8.2974e+00 3.5559e-01 6.4441e-01 9.0901e-01 9.0987e-02 4.5014e-04 1.3489e-03 6.3970e-04 1.1593e-03 + 2.1600e-03 -8.2974e+00 3.5362e-01 6.4638e-01 9.0901e-01 9.0987e-02 4.4847e-04 1.3605e-03 6.3970e-04 1.1693e-03 + 2.1700e-03 -8.2974e+00 3.5168e-01 6.4832e-01 9.0901e-01 9.0987e-02 4.4681e-04 1.3722e-03 6.3970e-04 1.1793e-03 + 2.1800e-03 -8.2974e+00 3.4975e-01 6.5025e-01 9.0901e-01 9.0987e-02 4.4514e-04 1.3839e-03 6.3970e-04 1.1893e-03 + 2.1900e-03 -8.2974e+00 3.4785e-01 6.5215e-01 9.0901e-01 9.0987e-02 4.4347e-04 1.3955e-03 6.3970e-04 1.1993e-03 + 2.2000e-03 -8.2974e+00 3.4597e-01 6.5403e-01 9.0901e-01 9.0987e-02 4.4181e-04 1.4072e-03 6.3970e-04 1.2093e-03 + 2.2100e-03 -8.2974e+00 3.4411e-01 6.5589e-01 9.0901e-01 9.0987e-02 4.4014e-04 1.4189e-03 6.3970e-04 1.2193e-03 + 2.2200e-03 -8.2974e+00 3.4227e-01 6.5773e-01 9.0901e-01 9.0987e-02 4.3848e-04 1.4305e-03 6.3970e-04 1.2293e-03 + 2.2300e-03 -8.2974e+00 3.4045e-01 6.5955e-01 9.0901e-01 9.0987e-02 4.3681e-04 1.4422e-03 6.3970e-04 1.2393e-03 + 2.2400e-03 -8.2974e+00 3.3864e-01 6.6136e-01 9.0901e-01 9.0987e-02 4.3514e-04 1.4539e-03 6.3970e-04 1.2493e-03 + 2.2500e-03 -8.2974e+00 3.3686e-01 6.6314e-01 9.0901e-01 9.0987e-02 4.3348e-04 1.4655e-03 6.3970e-04 1.2593e-03 + 2.2600e-03 -8.2974e+00 3.3510e-01 6.6490e-01 9.0901e-01 9.0987e-02 4.3181e-04 1.4772e-03 6.3970e-04 1.2693e-03 + 2.2700e-03 -8.2974e+00 3.3335e-01 6.6665e-01 9.0901e-01 9.0987e-02 4.3015e-04 1.4889e-03 6.3970e-04 1.2793e-03 + 2.2800e-03 -8.2974e+00 3.3162e-01 6.6838e-01 9.0901e-01 9.0987e-02 4.2848e-04 1.5005e-03 6.3970e-04 1.2893e-03 + 2.2900e-03 -8.2974e+00 3.2991e-01 6.7009e-01 9.0901e-01 9.0987e-02 4.2681e-04 1.5122e-03 6.3970e-04 1.2993e-03 + 2.3000e-03 -8.2974e+00 3.2822e-01 6.7178e-01 9.0901e-01 9.0987e-02 4.2515e-04 1.5239e-03 6.3970e-04 1.3093e-03 + 2.3100e-03 -8.2974e+00 3.2654e-01 6.7346e-01 9.0901e-01 9.0987e-02 4.2348e-04 1.5355e-03 6.3970e-04 1.3193e-03 + 2.3200e-03 -8.2974e+00 3.2489e-01 6.7511e-01 9.0901e-01 9.0987e-02 4.2181e-04 1.5472e-03 6.3970e-04 1.3293e-03 + 2.3300e-03 -8.2974e+00 3.2324e-01 6.7676e-01 9.0901e-01 9.0987e-02 4.2015e-04 1.5589e-03 6.3970e-04 1.3393e-03 + 2.3400e-03 -8.2974e+00 3.2162e-01 6.7838e-01 9.0901e-01 9.0987e-02 4.1848e-04 1.5705e-03 6.3970e-04 1.3493e-03 + 2.3500e-03 -8.2974e+00 3.2001e-01 6.7999e-01 9.0901e-01 9.0987e-02 4.1682e-04 1.5822e-03 6.3970e-04 1.3593e-03 + 2.3600e-03 -8.2974e+00 3.1842e-01 6.8158e-01 9.0901e-01 9.0987e-02 4.1515e-04 1.5939e-03 6.3970e-04 1.3693e-03 + 2.3700e-03 -8.2974e+00 3.1684e-01 6.8316e-01 9.0901e-01 9.0987e-02 4.1348e-04 1.6055e-03 6.3970e-04 1.3793e-03 + 2.3800e-03 -8.2974e+00 3.1528e-01 6.8472e-01 9.0901e-01 9.0987e-02 4.1182e-04 1.6172e-03 6.3970e-04 1.3893e-03 + 2.3900e-03 -8.2974e+00 3.1373e-01 6.8627e-01 9.0901e-01 9.0987e-02 4.1015e-04 1.6288e-03 6.3970e-04 1.3993e-03 + 2.4000e-03 -8.2974e+00 3.1220e-01 6.8780e-01 9.0901e-01 9.0987e-02 4.0848e-04 1.6405e-03 6.3970e-04 1.4093e-03 + 2.4100e-03 -8.2974e+00 3.1068e-01 6.8932e-01 9.0901e-01 9.0987e-02 4.0682e-04 1.6522e-03 6.3970e-04 1.4193e-03 + 2.4200e-03 -8.2974e+00 3.0918e-01 6.9082e-01 9.0901e-01 9.0987e-02 4.0515e-04 1.6638e-03 6.3970e-04 1.4293e-03 + 2.4300e-03 -8.2974e+00 3.0770e-01 6.9230e-01 9.0901e-01 9.0987e-02 4.0349e-04 1.6755e-03 6.3970e-04 1.4393e-03 + 2.4400e-03 -8.2974e+00 3.0622e-01 6.9378e-01 9.0901e-01 9.0987e-02 4.0182e-04 1.6872e-03 6.3970e-04 1.4493e-03 + 2.4500e-03 -8.2974e+00 3.0476e-01 6.9524e-01 9.0901e-01 9.0987e-02 4.0015e-04 1.6988e-03 6.3970e-04 1.4593e-03 + 2.4600e-03 -8.2974e+00 3.0332e-01 6.9668e-01 9.0901e-01 9.0987e-02 3.9849e-04 1.7105e-03 6.3970e-04 1.4693e-03 + 2.4700e-03 -8.2974e+00 3.0189e-01 6.9811e-01 9.0901e-01 9.0987e-02 3.9682e-04 1.7222e-03 6.3970e-04 1.4793e-03 + 2.4800e-03 -8.2974e+00 3.0047e-01 6.9953e-01 9.0901e-01 9.0987e-02 3.9515e-04 1.7338e-03 6.3970e-04 1.4893e-03 + 2.4900e-03 -8.2974e+00 2.9907e-01 7.0093e-01 9.0901e-01 9.0987e-02 3.9349e-04 1.7455e-03 6.3970e-04 1.4993e-03 + 2.5000e-03 -8.2974e+00 2.9767e-01 7.0233e-01 9.0901e-01 9.0987e-02 3.9182e-04 1.7572e-03 6.3970e-04 1.5093e-03 + 2.5100e-03 -8.2974e+00 2.9629e-01 7.0371e-01 9.0901e-01 9.0987e-02 3.9016e-04 1.7688e-03 6.3970e-04 1.5193e-03 + 2.5200e-03 -8.2974e+00 2.9493e-01 7.0507e-01 9.0901e-01 9.0987e-02 3.8849e-04 1.7805e-03 6.3970e-04 1.5293e-03 + 2.5300e-03 -8.2974e+00 2.9358e-01 7.0642e-01 9.0901e-01 9.0987e-02 3.8682e-04 1.7922e-03 6.3970e-04 1.5393e-03 + 2.5400e-03 -8.2974e+00 2.9223e-01 7.0777e-01 9.0901e-01 9.0987e-02 3.8516e-04 1.8038e-03 6.3970e-04 1.5493e-03 + 2.5500e-03 -8.2974e+00 2.9091e-01 7.0909e-01 9.0901e-01 9.0987e-02 3.8349e-04 1.8155e-03 6.3970e-04 1.5593e-03 + 2.5600e-03 -8.2974e+00 2.8959e-01 7.1041e-01 9.0901e-01 9.0987e-02 3.8183e-04 1.8272e-03 6.3970e-04 1.5693e-03 + 2.5700e-03 -8.2974e+00 2.8828e-01 7.1172e-01 9.0901e-01 9.0987e-02 3.8016e-04 1.8388e-03 6.3970e-04 1.5793e-03 + 2.5800e-03 -8.2974e+00 2.8699e-01 7.1301e-01 9.0901e-01 9.0987e-02 3.7849e-04 1.8505e-03 6.3970e-04 1.5893e-03 + 2.5900e-03 -8.2974e+00 2.8571e-01 7.1429e-01 9.0901e-01 9.0987e-02 3.7683e-04 1.8622e-03 6.3970e-04 1.5993e-03 + 2.6000e-03 -8.2974e+00 2.8444e-01 7.1556e-01 9.0901e-01 9.0987e-02 3.7516e-04 1.8738e-03 6.3970e-04 1.6093e-03 + 2.6100e-03 -8.2974e+00 2.8318e-01 7.1682e-01 9.0901e-01 9.0987e-02 3.7349e-04 1.8855e-03 6.3970e-04 1.6193e-03 + 2.6200e-03 -8.2974e+00 2.8193e-01 7.1807e-01 9.0901e-01 9.0987e-02 3.7183e-04 1.8972e-03 6.3970e-04 1.6293e-03 + 2.6300e-03 -8.2974e+00 2.8069e-01 7.1931e-01 9.0901e-01 9.0987e-02 3.7016e-04 1.9088e-03 6.3970e-04 1.6393e-03 + 2.6400e-03 -8.2974e+00 2.7947e-01 7.2053e-01 9.0901e-01 9.0987e-02 3.6850e-04 1.9205e-03 6.3970e-04 1.6493e-03 + 2.6500e-03 -8.2974e+00 2.7825e-01 7.2175e-01 9.0901e-01 9.0987e-02 3.6683e-04 1.9322e-03 6.3970e-04 1.6593e-03 + 2.6600e-03 -8.2974e+00 2.7705e-01 7.2295e-01 9.0901e-01 9.0987e-02 3.6516e-04 1.9438e-03 6.3970e-04 1.6693e-03 + 2.6700e-03 -8.2974e+00 2.7585e-01 7.2415e-01 9.0901e-01 9.0987e-02 3.6350e-04 1.9555e-03 6.3970e-04 1.6793e-03 + 2.6800e-03 -8.2974e+00 2.7467e-01 7.2533e-01 9.0901e-01 9.0987e-02 3.6183e-04 1.9672e-03 6.3970e-04 1.6893e-03 + 2.6900e-03 -8.2974e+00 2.7349e-01 7.2651e-01 9.0901e-01 9.0987e-02 3.6016e-04 1.9788e-03 6.3970e-04 1.6993e-03 + 2.7000e-03 -8.2974e+00 2.7233e-01 7.2767e-01 9.0901e-01 9.0987e-02 3.5850e-04 1.9905e-03 6.3970e-04 1.7093e-03 + 2.7100e-03 -8.2974e+00 2.7117e-01 7.2883e-01 9.0901e-01 9.0987e-02 3.5683e-04 2.0022e-03 6.3970e-04 1.7193e-03 + 2.7200e-03 -8.2974e+00 2.7003e-01 7.2997e-01 9.0901e-01 9.0987e-02 3.5517e-04 2.0138e-03 6.3970e-04 1.7293e-03 + 2.7300e-03 -8.2974e+00 2.6889e-01 7.3111e-01 9.0901e-01 9.0987e-02 3.5350e-04 2.0255e-03 6.3970e-04 1.7393e-03 + 2.7400e-03 -8.2974e+00 2.6777e-01 7.3223e-01 9.0901e-01 9.0987e-02 3.5183e-04 2.0372e-03 6.3970e-04 1.7493e-03 + 2.7500e-03 -8.2974e+00 2.6665e-01 7.3335e-01 9.0901e-01 9.0987e-02 3.5017e-04 2.0488e-03 6.3970e-04 1.7593e-03 + 2.7600e-03 -8.2974e+00 2.6555e-01 7.3445e-01 9.0901e-01 9.0987e-02 3.4850e-04 2.0605e-03 6.3970e-04 1.7693e-03 + 2.7700e-03 -8.2974e+00 2.6445e-01 7.3555e-01 9.0901e-01 9.0987e-02 3.4683e-04 2.0722e-03 6.3970e-04 1.7793e-03 + 2.7800e-03 -8.2974e+00 2.6336e-01 7.3664e-01 9.0901e-01 9.0987e-02 3.4517e-04 2.0838e-03 6.3970e-04 1.7893e-03 + 2.7900e-03 -8.2974e+00 2.6228e-01 7.3772e-01 9.0901e-01 9.0987e-02 3.4350e-04 2.0955e-03 6.3970e-04 1.7993e-03 + 2.8000e-03 -8.2974e+00 2.6121e-01 7.3879e-01 9.0901e-01 9.0987e-02 3.4184e-04 2.1072e-03 6.3970e-04 1.8093e-03 + 2.8100e-03 -8.2974e+00 2.6015e-01 7.3985e-01 9.0901e-01 9.0987e-02 3.4017e-04 2.1188e-03 6.3970e-04 1.8193e-03 + 2.8200e-03 -8.2974e+00 2.5909e-01 7.4091e-01 9.0901e-01 9.0987e-02 3.3850e-04 2.1305e-03 6.3970e-04 1.8293e-03 + 2.8300e-03 -8.2974e+00 2.5805e-01 7.4195e-01 9.0901e-01 9.0987e-02 3.3684e-04 2.1422e-03 6.3970e-04 1.8393e-03 + 2.8400e-03 -8.2974e+00 2.5701e-01 7.4299e-01 9.0901e-01 9.0987e-02 3.3517e-04 2.1538e-03 6.3970e-04 1.8493e-03 + 2.8500e-03 -8.2974e+00 2.5598e-01 7.4402e-01 9.0901e-01 9.0987e-02 3.3351e-04 2.1655e-03 6.3970e-04 1.8593e-03 + 2.8600e-03 -8.2974e+00 2.5496e-01 7.4504e-01 9.0901e-01 9.0987e-02 3.3184e-04 2.1772e-03 6.3970e-04 1.8693e-03 + 2.8700e-03 -8.2974e+00 2.5395e-01 7.4605e-01 9.0901e-01 9.0987e-02 3.3017e-04 2.1888e-03 6.3970e-04 1.8793e-03 + 2.8800e-03 -8.2974e+00 2.5295e-01 7.4705e-01 9.0901e-01 9.0987e-02 3.2851e-04 2.2005e-03 6.3970e-04 1.8893e-03 + 2.8900e-03 -8.2974e+00 2.5195e-01 7.4805e-01 9.0901e-01 9.0987e-02 3.2684e-04 2.2122e-03 6.3970e-04 1.8993e-03 + 2.9000e-03 -8.2974e+00 2.5096e-01 7.4904e-01 9.0901e-01 9.0987e-02 3.2517e-04 2.2238e-03 6.3970e-04 1.9093e-03 + 2.9100e-03 -8.2974e+00 2.4998e-01 7.5002e-01 9.0901e-01 9.0987e-02 3.2351e-04 2.2355e-03 6.3970e-04 1.9193e-03 + 2.9200e-03 -8.2974e+00 2.4901e-01 7.5099e-01 9.0901e-01 9.0987e-02 3.2184e-04 2.2472e-03 6.3970e-04 1.9293e-03 + 2.9300e-03 -8.2974e+00 2.4804e-01 7.5196e-01 9.0901e-01 9.0987e-02 3.2018e-04 2.2588e-03 6.3970e-04 1.9393e-03 + 2.9400e-03 -8.2974e+00 2.4708e-01 7.5292e-01 9.0901e-01 9.0987e-02 3.1851e-04 2.2705e-03 6.3970e-04 1.9493e-03 + 2.9500e-03 -8.2974e+00 2.4613e-01 7.5387e-01 9.0901e-01 9.0987e-02 3.1684e-04 2.2822e-03 6.3970e-04 1.9593e-03 + 2.9600e-03 -8.2974e+00 2.4519e-01 7.5481e-01 9.0901e-01 9.0987e-02 3.1518e-04 2.2938e-03 6.3970e-04 1.9693e-03 + 2.9700e-03 -8.2974e+00 2.4425e-01 7.5575e-01 9.0901e-01 9.0987e-02 3.1351e-04 2.3055e-03 6.3970e-04 1.9793e-03 + 2.9800e-03 -8.2974e+00 2.4332e-01 7.5668e-01 9.0901e-01 9.0987e-02 3.1184e-04 2.3172e-03 6.3970e-04 1.9893e-03 + 2.9900e-03 -8.2974e+00 2.4240e-01 7.5760e-01 9.0901e-01 9.0987e-02 3.1018e-04 2.3288e-03 6.3970e-04 1.9993e-03 + 3.0000e-03 -8.2974e+00 2.4149e-01 7.5851e-01 9.0901e-01 9.0987e-02 3.0851e-04 2.3405e-03 6.3970e-04 2.0093e-03 + 3.0100e-03 -8.2974e+00 2.4058e-01 7.5942e-01 9.0901e-01 9.0987e-02 3.0685e-04 2.3522e-03 6.3970e-04 2.0193e-03 + 3.0200e-03 -8.2974e+00 2.3968e-01 7.6032e-01 9.0901e-01 9.0987e-02 3.0518e-04 2.3638e-03 6.3970e-04 2.0293e-03 + 3.0300e-03 -8.2974e+00 2.3878e-01 7.6122e-01 9.0901e-01 9.0987e-02 3.0351e-04 2.3755e-03 6.3970e-04 2.0393e-03 + 3.0400e-03 -8.2974e+00 2.3790e-01 7.6210e-01 9.0901e-01 9.0987e-02 3.0185e-04 2.3872e-03 6.3970e-04 2.0493e-03 + 3.0500e-03 -8.2974e+00 2.3701e-01 7.6299e-01 9.0901e-01 9.0987e-02 3.0018e-04 2.3988e-03 6.3970e-04 2.0593e-03 + 3.0600e-03 -8.2974e+00 2.3614e-01 7.6386e-01 9.0901e-01 9.0987e-02 2.9852e-04 2.4105e-03 6.3970e-04 2.0693e-03 + 3.0700e-03 -8.2974e+00 2.3527e-01 7.6473e-01 9.0901e-01 9.0987e-02 2.9685e-04 2.4222e-03 6.3970e-04 2.0793e-03 + 3.0800e-03 -8.2974e+00 2.3441e-01 7.6559e-01 9.0901e-01 9.0987e-02 2.9518e-04 2.4338e-03 6.3970e-04 2.0893e-03 + 3.0900e-03 -8.2974e+00 2.3355e-01 7.6645e-01 9.0901e-01 9.0987e-02 2.9352e-04 2.4455e-03 6.3970e-04 2.0993e-03 + 3.1000e-03 -8.2974e+00 2.3270e-01 7.6730e-01 9.0901e-01 9.0987e-02 2.9185e-04 2.4571e-03 6.3970e-04 2.1093e-03 + 3.1100e-03 -8.2974e+00 2.3186e-01 7.6814e-01 9.0901e-01 9.0987e-02 2.9018e-04 2.4688e-03 6.3970e-04 2.1193e-03 + 3.1200e-03 -8.2974e+00 2.3102e-01 7.6898e-01 9.0901e-01 9.0987e-02 2.8852e-04 2.4805e-03 6.3970e-04 2.1293e-03 + 3.1300e-03 -8.2974e+00 2.3019e-01 7.6981e-01 9.0901e-01 9.0987e-02 2.8685e-04 2.4921e-03 6.3970e-04 2.1393e-03 + 3.1400e-03 -8.2974e+00 2.2937e-01 7.7063e-01 9.0901e-01 9.0987e-02 2.8519e-04 2.5038e-03 6.3970e-04 2.1493e-03 + 3.1500e-03 -8.2974e+00 2.2855e-01 7.7145e-01 9.0901e-01 9.0987e-02 2.8352e-04 2.5155e-03 6.3970e-04 2.1593e-03 + 3.1600e-03 -8.2974e+00 2.2773e-01 7.7227e-01 9.0901e-01 9.0987e-02 2.8185e-04 2.5271e-03 6.3970e-04 2.1693e-03 + 3.1700e-03 -8.2974e+00 2.2692e-01 7.7308e-01 9.0901e-01 9.0987e-02 2.8019e-04 2.5388e-03 6.3970e-04 2.1793e-03 + 3.1800e-03 -8.2974e+00 2.2612e-01 7.7388e-01 9.0901e-01 9.0987e-02 2.7852e-04 2.5505e-03 6.3970e-04 2.1893e-03 + 3.1900e-03 -8.2974e+00 2.2533e-01 7.7467e-01 9.0901e-01 9.0987e-02 2.7685e-04 2.5621e-03 6.3970e-04 2.1993e-03 + 3.2000e-03 -8.2974e+00 2.2454e-01 7.7546e-01 9.0901e-01 9.0987e-02 2.7519e-04 2.5738e-03 6.3970e-04 2.2093e-03 + 3.2100e-03 -8.2974e+00 2.2375e-01 7.7625e-01 9.0901e-01 9.0987e-02 2.7352e-04 2.5855e-03 6.3970e-04 2.2193e-03 + 3.2200e-03 -8.2974e+00 2.2297e-01 7.7703e-01 9.0901e-01 9.0987e-02 2.7186e-04 2.5971e-03 6.3970e-04 2.2293e-03 + 3.2300e-03 -8.2974e+00 2.2220e-01 7.7780e-01 9.0901e-01 9.0987e-02 2.7019e-04 2.6088e-03 6.3970e-04 2.2393e-03 + 3.2400e-03 -8.2974e+00 2.2143e-01 7.7857e-01 9.0901e-01 9.0987e-02 2.6852e-04 2.6205e-03 6.3970e-04 2.2493e-03 + 3.2500e-03 -8.2974e+00 2.2066e-01 7.7934e-01 9.0901e-01 9.0987e-02 2.6686e-04 2.6321e-03 6.3970e-04 2.2593e-03 + 3.2600e-03 -8.2974e+00 2.1990e-01 7.8010e-01 9.0901e-01 9.0987e-02 2.6519e-04 2.6438e-03 6.3970e-04 2.2693e-03 + 3.2700e-03 -8.2974e+00 2.1915e-01 7.8085e-01 9.0901e-01 9.0987e-02 2.6352e-04 2.6555e-03 6.3970e-04 2.2793e-03 + 3.2800e-03 -8.2974e+00 2.1840e-01 7.8160e-01 9.0901e-01 9.0987e-02 2.6186e-04 2.6671e-03 6.3970e-04 2.2893e-03 + 3.2900e-03 -8.2974e+00 2.1766e-01 7.8234e-01 9.0901e-01 9.0987e-02 2.6019e-04 2.6788e-03 6.3970e-04 2.2993e-03 + 3.3000e-03 -8.2974e+00 2.1692e-01 7.8308e-01 9.0901e-01 9.0987e-02 2.5853e-04 2.6905e-03 6.3970e-04 2.3093e-03 + 3.3100e-03 -8.2974e+00 2.1619e-01 7.8381e-01 9.0901e-01 9.0987e-02 2.5686e-04 2.7021e-03 6.3970e-04 2.3193e-03 + 3.3200e-03 -8.2974e+00 2.1546e-01 7.8454e-01 9.0901e-01 9.0987e-02 2.5519e-04 2.7138e-03 6.3970e-04 2.3293e-03 + 3.3300e-03 -8.2974e+00 2.1474e-01 7.8526e-01 9.0901e-01 9.0987e-02 2.5353e-04 2.7255e-03 6.3970e-04 2.3393e-03 + 3.3400e-03 -8.2974e+00 2.1402e-01 7.8598e-01 9.0901e-01 9.0987e-02 2.5186e-04 2.7371e-03 6.3970e-04 2.3493e-03 + 3.3500e-03 -8.2974e+00 2.1330e-01 7.8670e-01 9.0901e-01 9.0987e-02 2.5020e-04 2.7488e-03 6.3970e-04 2.3593e-03 + 3.3600e-03 -8.2974e+00 2.1260e-01 7.8740e-01 9.0901e-01 9.0987e-02 2.4853e-04 2.7605e-03 6.3970e-04 2.3693e-03 + 3.3700e-03 -8.2974e+00 2.1189e-01 7.8811e-01 9.0901e-01 9.0987e-02 2.4686e-04 2.7721e-03 6.3970e-04 2.3793e-03 + 3.3800e-03 -8.2974e+00 2.1119e-01 7.8881e-01 9.0901e-01 9.0987e-02 2.4520e-04 2.7838e-03 6.3970e-04 2.3893e-03 + 3.3900e-03 -8.2974e+00 2.1050e-01 7.8950e-01 9.0901e-01 9.0987e-02 2.4353e-04 2.7955e-03 6.3970e-04 2.3993e-03 + 3.4000e-03 -8.2974e+00 2.0981e-01 7.9019e-01 9.0901e-01 9.0987e-02 2.4186e-04 2.8071e-03 6.3970e-04 2.4093e-03 + 3.4100e-03 -8.2974e+00 2.0912e-01 7.9088e-01 9.0901e-01 9.0987e-02 2.4020e-04 2.8188e-03 6.3970e-04 2.4193e-03 + 3.4200e-03 -8.2974e+00 2.0844e-01 7.9156e-01 9.0901e-01 9.0987e-02 2.3853e-04 2.8305e-03 6.3970e-04 2.4293e-03 + 3.4300e-03 -8.2974e+00 2.0776e-01 7.9224e-01 9.0901e-01 9.0987e-02 2.3687e-04 2.8421e-03 6.3970e-04 2.4393e-03 + 3.4400e-03 -8.2974e+00 2.0709e-01 7.9291e-01 9.0901e-01 9.0987e-02 2.3520e-04 2.8538e-03 6.3970e-04 2.4493e-03 + 3.4500e-03 -8.2974e+00 2.0642e-01 7.9358e-01 9.0901e-01 9.0987e-02 2.3353e-04 2.8655e-03 6.3970e-04 2.4593e-03 + 3.4600e-03 -8.2974e+00 2.0576e-01 7.9424e-01 9.0901e-01 9.0987e-02 2.3187e-04 2.8771e-03 6.3970e-04 2.4693e-03 + 3.4700e-03 -8.2974e+00 2.0510e-01 7.9490e-01 9.0901e-01 9.0987e-02 2.3020e-04 2.8888e-03 6.3970e-04 2.4793e-03 + 3.4800e-03 -8.2974e+00 2.0444e-01 7.9556e-01 9.0901e-01 9.0987e-02 2.2853e-04 2.9005e-03 6.3970e-04 2.4893e-03 + 3.4900e-03 -8.2974e+00 2.0379e-01 7.9621e-01 9.0901e-01 9.0987e-02 2.2687e-04 2.9121e-03 6.3970e-04 2.4993e-03 + 3.5000e-03 -8.2974e+00 2.0314e-01 7.9686e-01 9.0901e-01 9.0987e-02 2.2520e-04 2.9238e-03 6.3970e-04 2.5093e-03 + 3.5100e-03 -8.2974e+00 2.0250e-01 7.9750e-01 9.0901e-01 9.0987e-02 2.2354e-04 2.9355e-03 6.3970e-04 2.5193e-03 + 3.5200e-03 -8.2974e+00 2.0186e-01 7.9814e-01 9.0901e-01 9.0987e-02 2.2187e-04 2.9471e-03 6.3970e-04 2.5293e-03 + 3.5300e-03 -8.2974e+00 2.0123e-01 7.9877e-01 9.0901e-01 9.0987e-02 2.2020e-04 2.9588e-03 6.3970e-04 2.5393e-03 + 3.5400e-03 -8.2974e+00 2.0060e-01 7.9940e-01 9.0901e-01 9.0987e-02 2.1854e-04 2.9705e-03 6.3970e-04 2.5493e-03 + 3.5500e-03 -8.2974e+00 1.9997e-01 8.0003e-01 9.0901e-01 9.0987e-02 2.1687e-04 2.9821e-03 6.3970e-04 2.5593e-03 + 3.5600e-03 -8.2974e+00 1.9935e-01 8.0065e-01 9.0901e-01 9.0987e-02 2.1520e-04 2.9938e-03 6.3970e-04 2.5693e-03 + 3.5700e-03 -8.2974e+00 1.9873e-01 8.0127e-01 9.0901e-01 9.0987e-02 2.1354e-04 3.0055e-03 6.3970e-04 2.5793e-03 + 3.5800e-03 -8.2974e+00 1.9811e-01 8.0189e-01 9.0901e-01 9.0987e-02 2.1187e-04 3.0171e-03 6.3970e-04 2.5893e-03 + 3.5900e-03 -8.2974e+00 1.9750e-01 8.0250e-01 9.0901e-01 9.0987e-02 2.1021e-04 3.0288e-03 6.3970e-04 2.5993e-03 + 3.6000e-03 -8.2974e+00 1.9689e-01 8.0311e-01 9.0901e-01 9.0987e-02 2.0854e-04 3.0405e-03 6.3970e-04 2.6093e-03 + 3.6100e-03 -8.2974e+00 1.9629e-01 8.0371e-01 9.0901e-01 9.0987e-02 2.0687e-04 3.0521e-03 6.3970e-04 2.6193e-03 + 3.6200e-03 -8.2974e+00 1.9569e-01 8.0431e-01 9.0901e-01 9.0987e-02 2.0521e-04 3.0638e-03 6.3970e-04 2.6293e-03 + 3.6300e-03 -8.2974e+00 1.9509e-01 8.0491e-01 9.0901e-01 9.0987e-02 2.0354e-04 3.0755e-03 6.3970e-04 2.6393e-03 + 3.6400e-03 -8.2974e+00 1.9450e-01 8.0550e-01 9.0901e-01 9.0987e-02 2.0188e-04 3.0871e-03 6.3970e-04 2.6493e-03 + 3.6500e-03 -8.2974e+00 1.9391e-01 8.0609e-01 9.0901e-01 9.0987e-02 2.0021e-04 3.0988e-03 6.3970e-04 2.6593e-03 + 3.6600e-03 -8.2974e+00 1.9332e-01 8.0668e-01 9.0901e-01 9.0987e-02 1.9854e-04 3.1105e-03 6.3970e-04 2.6693e-03 + 3.6700e-03 -8.2974e+00 1.9274e-01 8.0726e-01 9.0901e-01 9.0987e-02 1.9688e-04 3.1221e-03 6.3970e-04 2.6793e-03 + 3.6800e-03 -8.2974e+00 1.9216e-01 8.0784e-01 9.0901e-01 9.0987e-02 1.9521e-04 3.1338e-03 6.3970e-04 2.6893e-03 + 3.6900e-03 -8.2974e+00 1.9158e-01 8.0842e-01 9.0901e-01 9.0987e-02 1.9354e-04 3.1455e-03 6.3970e-04 2.6993e-03 + 3.7000e-03 -8.2974e+00 1.9101e-01 8.0899e-01 9.0901e-01 9.0987e-02 1.9188e-04 3.1571e-03 6.3970e-04 2.7093e-03 + 3.7100e-03 -8.2974e+00 1.9044e-01 8.0956e-01 9.0901e-01 9.0987e-02 1.9021e-04 3.1688e-03 6.3970e-04 2.7193e-03 + 3.7200e-03 -8.2974e+00 1.8988e-01 8.1012e-01 9.0901e-01 9.0987e-02 1.8855e-04 3.1805e-03 6.3970e-04 2.7293e-03 + 3.7300e-03 -8.2974e+00 1.8932e-01 8.1068e-01 9.0901e-01 9.0987e-02 1.8688e-04 3.1921e-03 6.3970e-04 2.7393e-03 + 3.7400e-03 -8.2974e+00 1.8876e-01 8.1124e-01 9.0901e-01 9.0987e-02 1.8521e-04 3.2038e-03 6.3970e-04 2.7493e-03 + 3.7500e-03 -8.2974e+00 1.8820e-01 8.1180e-01 9.0901e-01 9.0987e-02 1.8355e-04 3.2155e-03 6.3970e-04 2.7593e-03 + 3.7600e-03 -8.2974e+00 1.8765e-01 8.1235e-01 9.0901e-01 9.0987e-02 1.8188e-04 3.2271e-03 6.3970e-04 2.7693e-03 + 3.7700e-03 -8.2974e+00 1.8710e-01 8.1290e-01 9.0901e-01 9.0987e-02 1.8021e-04 3.2388e-03 6.3970e-04 2.7793e-03 + 3.7800e-03 -8.2974e+00 1.8656e-01 8.1344e-01 9.0901e-01 9.0987e-02 1.7855e-04 3.2505e-03 6.3970e-04 2.7893e-03 + 3.7900e-03 -8.2974e+00 1.8601e-01 8.1399e-01 9.0901e-01 9.0987e-02 1.7688e-04 3.2621e-03 6.3970e-04 2.7993e-03 + 3.8000e-03 -8.2974e+00 1.8547e-01 8.1453e-01 9.0901e-01 9.0987e-02 1.7522e-04 3.2738e-03 6.3970e-04 2.8093e-03 + 3.8100e-03 -8.2974e+00 1.8494e-01 8.1506e-01 9.0901e-01 9.0987e-02 1.7355e-04 3.2855e-03 6.3970e-04 2.8193e-03 + 3.8200e-03 -8.2974e+00 1.8440e-01 8.1560e-01 9.0901e-01 9.0987e-02 1.7188e-04 3.2971e-03 6.3970e-04 2.8293e-03 + 3.8300e-03 -8.2974e+00 1.8387e-01 8.1613e-01 9.0901e-01 9.0987e-02 1.7022e-04 3.3088e-03 6.3970e-04 2.8393e-03 + 3.8400e-03 -8.2974e+00 1.8335e-01 8.1665e-01 9.0901e-01 9.0987e-02 1.6855e-04 3.3204e-03 6.3970e-04 2.8493e-03 + 3.8500e-03 -8.2974e+00 1.8282e-01 8.1718e-01 9.0901e-01 9.0987e-02 1.6689e-04 3.3321e-03 6.3970e-04 2.8593e-03 + 3.8600e-03 -8.2974e+00 1.8230e-01 8.1770e-01 9.0901e-01 9.0987e-02 1.6522e-04 3.3438e-03 6.3970e-04 2.8693e-03 + 3.8700e-03 -8.2974e+00 1.8178e-01 8.1822e-01 9.0901e-01 9.0987e-02 1.6355e-04 3.3554e-03 6.3970e-04 2.8793e-03 + 3.8800e-03 -8.2974e+00 1.8127e-01 8.1873e-01 9.0901e-01 9.0987e-02 1.6189e-04 3.3671e-03 6.3970e-04 2.8893e-03 + 3.8900e-03 -8.2974e+00 1.8076e-01 8.1924e-01 9.0901e-01 9.0987e-02 1.6022e-04 3.3788e-03 6.3970e-04 2.8993e-03 + 3.9000e-03 -8.2974e+00 1.8025e-01 8.1975e-01 9.0901e-01 9.0987e-02 1.5855e-04 3.3904e-03 6.3970e-04 2.9093e-03 + 3.9100e-03 -8.2974e+00 1.7974e-01 8.2026e-01 9.0901e-01 9.0987e-02 1.5689e-04 3.4021e-03 6.3970e-04 2.9193e-03 + 3.9200e-03 -8.2974e+00 1.7924e-01 8.2076e-01 9.0901e-01 9.0987e-02 1.5522e-04 3.4138e-03 6.3970e-04 2.9293e-03 + 3.9300e-03 -8.2974e+00 1.7874e-01 8.2126e-01 9.0901e-01 9.0987e-02 1.5356e-04 3.4254e-03 6.3970e-04 2.9393e-03 + 3.9400e-03 -8.2974e+00 1.7824e-01 8.2176e-01 9.0901e-01 9.0987e-02 1.5189e-04 3.4371e-03 6.3970e-04 2.9493e-03 + 3.9500e-03 -8.2974e+00 1.7774e-01 8.2226e-01 9.0901e-01 9.0987e-02 1.5022e-04 3.4488e-03 6.3970e-04 2.9593e-03 + 3.9600e-03 -8.2974e+00 1.7725e-01 8.2275e-01 9.0901e-01 9.0987e-02 1.4856e-04 3.4604e-03 6.3970e-04 2.9693e-03 + 3.9700e-03 -8.2974e+00 1.7676e-01 8.2324e-01 9.0901e-01 9.0987e-02 1.4689e-04 3.4721e-03 6.3970e-04 2.9793e-03 + 3.9800e-03 -8.2974e+00 1.7627e-01 8.2373e-01 9.0901e-01 9.0987e-02 1.4522e-04 3.4838e-03 6.3970e-04 2.9893e-03 + 3.9900e-03 -8.2974e+00 1.7579e-01 8.2421e-01 9.0901e-01 9.0987e-02 1.4356e-04 3.4954e-03 6.3970e-04 2.9993e-03 + 4.0000e-03 -8.2974e+00 1.7531e-01 8.2469e-01 9.0901e-01 9.0987e-02 1.4189e-04 3.5071e-03 6.3970e-04 3.0093e-03 + 4.0100e-03 -8.2974e+00 1.7483e-01 8.2517e-01 9.0901e-01 9.0987e-02 1.4023e-04 3.5188e-03 6.3970e-04 3.0193e-03 + 4.0200e-03 -8.2974e+00 1.7435e-01 8.2565e-01 9.0901e-01 9.0987e-02 1.3856e-04 3.5304e-03 6.3970e-04 3.0293e-03 + 4.0300e-03 -8.2974e+00 1.7388e-01 8.2612e-01 9.0901e-01 9.0987e-02 1.3689e-04 3.5421e-03 6.3970e-04 3.0393e-03 + 4.0400e-03 -8.2974e+00 1.7341e-01 8.2659e-01 9.0901e-01 9.0987e-02 1.3523e-04 3.5538e-03 6.3970e-04 3.0493e-03 + 4.0500e-03 -8.2974e+00 1.7294e-01 8.2706e-01 9.0901e-01 9.0987e-02 1.3356e-04 3.5654e-03 6.3970e-04 3.0593e-03 + 4.0600e-03 -8.2974e+00 1.7247e-01 8.2753e-01 9.0901e-01 9.0987e-02 1.3189e-04 3.5771e-03 6.3970e-04 3.0693e-03 + 4.0700e-03 -8.2974e+00 1.7201e-01 8.2799e-01 9.0901e-01 9.0987e-02 1.3023e-04 3.5888e-03 6.3970e-04 3.0793e-03 + 4.0800e-03 -8.2974e+00 1.7155e-01 8.2845e-01 9.0901e-01 9.0987e-02 1.2856e-04 3.6004e-03 6.3970e-04 3.0893e-03 + 4.0900e-03 -8.2974e+00 1.7109e-01 8.2891e-01 9.0901e-01 9.0987e-02 1.2690e-04 3.6121e-03 6.3970e-04 3.0993e-03 + 4.1000e-03 -8.2974e+00 1.7063e-01 8.2937e-01 9.0901e-01 9.0987e-02 1.2523e-04 3.6238e-03 6.3970e-04 3.1093e-03 + 4.1100e-03 -8.2974e+00 1.7018e-01 8.2982e-01 9.0901e-01 9.0987e-02 1.2356e-04 3.6354e-03 6.3970e-04 3.1193e-03 + 4.1200e-03 -8.2974e+00 1.6973e-01 8.3027e-01 9.0901e-01 9.0987e-02 1.2190e-04 3.6471e-03 6.3970e-04 3.1293e-03 + 4.1300e-03 -8.2974e+00 1.6928e-01 8.3072e-01 9.0901e-01 9.0987e-02 1.2023e-04 3.6588e-03 6.3970e-04 3.1393e-03 + 4.1400e-03 -8.2974e+00 1.6883e-01 8.3117e-01 9.0901e-01 9.0987e-02 1.1857e-04 3.6704e-03 6.3970e-04 3.1493e-03 + 4.1500e-03 -8.2974e+00 1.6839e-01 8.3161e-01 9.0901e-01 9.0987e-02 1.1690e-04 3.6821e-03 6.3970e-04 3.1593e-03 + 4.1600e-03 -8.2974e+00 1.6794e-01 8.3206e-01 9.0901e-01 9.0987e-02 1.1523e-04 3.6938e-03 6.3970e-04 3.1693e-03 + 4.1700e-03 -8.2974e+00 1.6750e-01 8.3250e-01 9.0901e-01 9.0987e-02 1.1357e-04 3.7054e-03 6.3970e-04 3.1793e-03 + 4.1800e-03 -8.2974e+00 1.6707e-01 8.3293e-01 9.0901e-01 9.0987e-02 1.1190e-04 3.7171e-03 6.3970e-04 3.1893e-03 + 4.1900e-03 -8.2974e+00 1.6663e-01 8.3337e-01 9.0901e-01 9.0987e-02 1.1023e-04 3.7288e-03 6.3970e-04 3.1993e-03 + 4.2000e-03 -8.2974e+00 1.6620e-01 8.3380e-01 9.0901e-01 9.0987e-02 1.0857e-04 3.7404e-03 6.3970e-04 3.2093e-03 + 4.2100e-03 -8.2974e+00 1.6577e-01 8.3423e-01 9.0901e-01 9.0987e-02 1.0690e-04 3.7521e-03 6.3970e-04 3.2193e-03 + 4.2200e-03 -8.2974e+00 1.6534e-01 8.3466e-01 9.0901e-01 9.0987e-02 1.0524e-04 3.7638e-03 6.3970e-04 3.2293e-03 + 4.2300e-03 -8.2974e+00 1.6491e-01 8.3509e-01 9.0901e-01 9.0987e-02 1.0357e-04 3.7754e-03 6.3970e-04 3.2393e-03 + 4.2400e-03 -8.2974e+00 1.6449e-01 8.3551e-01 9.0901e-01 9.0987e-02 1.0190e-04 3.7871e-03 6.3970e-04 3.2493e-03 + 4.2500e-03 -8.2974e+00 1.6407e-01 8.3593e-01 9.0901e-01 9.0987e-02 1.0024e-04 3.7988e-03 6.3970e-04 3.2593e-03 + 4.2600e-03 -8.2974e+00 1.6365e-01 8.3635e-01 9.0901e-01 9.0987e-02 9.8571e-05 3.8104e-03 6.3970e-04 3.2693e-03 + 4.2700e-03 -8.2974e+00 1.6323e-01 8.3677e-01 9.0901e-01 9.0987e-02 9.6905e-05 3.8221e-03 6.3970e-04 3.2793e-03 + 4.2800e-03 -8.2974e+00 1.6282e-01 8.3718e-01 9.0901e-01 9.0987e-02 9.5238e-05 3.8338e-03 6.3970e-04 3.2893e-03 + 4.2900e-03 -8.2974e+00 1.6240e-01 8.3760e-01 9.0901e-01 9.0987e-02 9.3572e-05 3.8454e-03 6.3970e-04 3.2993e-03 + 4.3000e-03 -8.2974e+00 1.6199e-01 8.3801e-01 9.0901e-01 9.0987e-02 9.1906e-05 3.8571e-03 6.3970e-04 3.3093e-03 + 4.3100e-03 -8.2974e+00 1.6158e-01 8.3842e-01 9.0901e-01 9.0987e-02 9.0240e-05 3.8688e-03 6.3970e-04 3.3193e-03 + 4.3200e-03 -8.2974e+00 1.6117e-01 8.3883e-01 9.0901e-01 9.0987e-02 8.8574e-05 3.8804e-03 6.3970e-04 3.3293e-03 + 4.3300e-03 -8.2974e+00 1.6077e-01 8.3923e-01 9.0901e-01 9.0987e-02 8.6907e-05 3.8921e-03 6.3970e-04 3.3393e-03 + 4.3400e-03 -8.2974e+00 1.6037e-01 8.3963e-01 9.0901e-01 9.0987e-02 8.5241e-05 3.9038e-03 6.3970e-04 3.3493e-03 + 4.3500e-03 -8.2974e+00 1.5997e-01 8.4003e-01 9.0901e-01 9.0987e-02 8.3575e-05 3.9154e-03 6.3970e-04 3.3593e-03 + 4.3600e-03 -8.2974e+00 1.5957e-01 8.4043e-01 9.0901e-01 9.0987e-02 8.1909e-05 3.9271e-03 6.3970e-04 3.3693e-03 + 4.3700e-03 -8.2974e+00 1.5917e-01 8.4083e-01 9.0901e-01 9.0987e-02 8.0243e-05 3.9388e-03 6.3970e-04 3.3793e-03 + 4.3800e-03 -8.2974e+00 1.5877e-01 8.4123e-01 9.0901e-01 9.0987e-02 7.8576e-05 3.9504e-03 6.3970e-04 3.3893e-03 + 4.3900e-03 -8.2974e+00 1.5838e-01 8.4162e-01 9.0901e-01 9.0987e-02 7.6910e-05 3.9621e-03 6.3970e-04 3.3993e-03 + 4.4000e-03 -8.2974e+00 1.5799e-01 8.4201e-01 9.0901e-01 9.0987e-02 7.5244e-05 3.9738e-03 6.3970e-04 3.4093e-03 + 4.4100e-03 -8.2974e+00 1.5760e-01 8.4240e-01 9.0901e-01 9.0987e-02 7.3578e-05 3.9854e-03 6.3970e-04 3.4193e-03 + 4.4200e-03 -8.2974e+00 1.5721e-01 8.4279e-01 9.0901e-01 9.0987e-02 7.1912e-05 3.9971e-03 6.3970e-04 3.4293e-03 + 4.4300e-03 -8.2974e+00 1.5683e-01 8.4317e-01 9.0901e-01 9.0987e-02 7.0245e-05 4.0088e-03 6.3970e-04 3.4393e-03 + 4.4400e-03 -8.2974e+00 1.5644e-01 8.4356e-01 9.0901e-01 9.0987e-02 6.8579e-05 4.0204e-03 6.3970e-04 3.4493e-03 + 4.4500e-03 -8.2974e+00 1.5606e-01 8.4394e-01 9.0901e-01 9.0987e-02 6.6913e-05 4.0321e-03 6.3970e-04 3.4593e-03 + 4.4600e-03 -8.2974e+00 1.5568e-01 8.4432e-01 9.0901e-01 9.0987e-02 6.5247e-05 4.0438e-03 6.3970e-04 3.4693e-03 + 4.4700e-03 -8.2974e+00 1.5530e-01 8.4470e-01 9.0901e-01 9.0987e-02 6.3581e-05 4.0554e-03 6.3970e-04 3.4793e-03 + 4.4800e-03 -8.2974e+00 1.5493e-01 8.4507e-01 9.0901e-01 9.0987e-02 6.1914e-05 4.0671e-03 6.3970e-04 3.4893e-03 + 4.4900e-03 -8.2974e+00 1.5455e-01 8.4545e-01 9.0901e-01 9.0987e-02 6.0248e-05 4.0788e-03 6.3970e-04 3.4993e-03 + 4.5000e-03 -8.2974e+00 1.5418e-01 8.4582e-01 9.0901e-01 9.0987e-02 5.8582e-05 4.0904e-03 6.3970e-04 3.5093e-03 + 4.5100e-03 -8.2974e+00 1.5381e-01 8.4619e-01 9.0901e-01 9.0987e-02 5.6916e-05 4.1021e-03 6.3970e-04 3.5193e-03 + 4.5200e-03 -8.2974e+00 1.5344e-01 8.4656e-01 9.0901e-01 9.0987e-02 5.5250e-05 4.1138e-03 6.3970e-04 3.5293e-03 + 4.5300e-03 -8.2974e+00 1.5307e-01 8.4693e-01 9.0901e-01 9.0987e-02 5.3583e-05 4.1254e-03 6.3970e-04 3.5393e-03 + 4.5400e-03 -8.2974e+00 1.5271e-01 8.4729e-01 9.0901e-01 9.0987e-02 5.1917e-05 4.1371e-03 6.3970e-04 3.5493e-03 + 4.5500e-03 -8.2974e+00 1.5235e-01 8.4765e-01 9.0901e-01 9.0987e-02 5.0251e-05 4.1487e-03 6.3970e-04 3.5593e-03 + 4.5600e-03 -8.2974e+00 1.5198e-01 8.4802e-01 9.0901e-01 9.0987e-02 4.8585e-05 4.1604e-03 6.3970e-04 3.5693e-03 + 4.5700e-03 -8.2974e+00 1.5162e-01 8.4838e-01 9.0901e-01 9.0987e-02 4.6919e-05 4.1721e-03 6.3970e-04 3.5793e-03 + 4.5800e-03 -8.2974e+00 1.5127e-01 8.4873e-01 9.0901e-01 9.0987e-02 4.5252e-05 4.1837e-03 6.3970e-04 3.5893e-03 + 4.5900e-03 -8.2974e+00 1.5091e-01 8.4909e-01 9.0901e-01 9.0987e-02 4.3586e-05 4.1954e-03 6.3970e-04 3.5993e-03 + 4.6000e-03 -8.2974e+00 1.5055e-01 8.4945e-01 9.0901e-01 9.0987e-02 4.1920e-05 4.2071e-03 6.3970e-04 3.6093e-03 + 4.6100e-03 -8.2974e+00 1.5020e-01 8.4980e-01 9.0901e-01 9.0987e-02 4.0254e-05 4.2187e-03 6.3970e-04 3.6193e-03 + 4.6200e-03 -8.2974e+00 1.4985e-01 8.5015e-01 9.0901e-01 9.0987e-02 3.8588e-05 4.2304e-03 6.3970e-04 3.6293e-03 + 4.6300e-03 -8.2974e+00 1.4950e-01 8.5050e-01 9.0901e-01 9.0987e-02 3.6921e-05 4.2421e-03 6.3970e-04 3.6393e-03 + 4.6400e-03 -8.2974e+00 1.4915e-01 8.5085e-01 9.0901e-01 9.0987e-02 3.5255e-05 4.2537e-03 6.3970e-04 3.6493e-03 + 4.6500e-03 -8.2974e+00 1.4880e-01 8.5120e-01 9.0901e-01 9.0987e-02 3.3589e-05 4.2654e-03 6.3970e-04 3.6593e-03 + 4.6600e-03 -8.2974e+00 1.4846e-01 8.5154e-01 9.0901e-01 9.0987e-02 3.1923e-05 4.2771e-03 6.3970e-04 3.6693e-03 + 4.6700e-03 -8.2974e+00 1.4811e-01 8.5189e-01 9.0901e-01 9.0987e-02 3.0257e-05 4.2887e-03 6.3970e-04 3.6793e-03 + 4.6800e-03 -8.2974e+00 1.4777e-01 8.5223e-01 9.0901e-01 9.0987e-02 2.8590e-05 4.3004e-03 6.3970e-04 3.6893e-03 + 4.6900e-03 -8.2974e+00 1.4743e-01 8.5257e-01 9.0901e-01 9.0987e-02 2.6924e-05 4.3121e-03 6.3970e-04 3.6993e-03 + 4.7000e-03 -8.2974e+00 1.4709e-01 8.5291e-01 9.0901e-01 9.0987e-02 2.5258e-05 4.3237e-03 6.3970e-04 3.7093e-03 + 4.7100e-03 -8.2974e+00 1.4675e-01 8.5325e-01 9.0901e-01 9.0987e-02 2.3592e-05 4.3354e-03 6.3970e-04 3.7193e-03 + 4.7200e-03 -8.2974e+00 1.4642e-01 8.5358e-01 9.0901e-01 9.0987e-02 2.1926e-05 4.3471e-03 6.3970e-04 3.7293e-03 + 4.7300e-03 -8.2974e+00 1.4608e-01 8.5392e-01 9.0901e-01 9.0987e-02 2.0259e-05 4.3587e-03 6.3970e-04 3.7393e-03 + 4.7400e-03 -8.2974e+00 1.4575e-01 8.5425e-01 9.0901e-01 9.0987e-02 1.8593e-05 4.3704e-03 6.3970e-04 3.7493e-03 + 4.7500e-03 -8.2974e+00 1.4542e-01 8.5458e-01 9.0901e-01 9.0987e-02 1.6927e-05 4.3821e-03 6.3970e-04 3.7593e-03 + 4.7600e-03 -8.2974e+00 1.4509e-01 8.5491e-01 9.0901e-01 9.0987e-02 1.5261e-05 4.3937e-03 6.3970e-04 3.7693e-03 + 4.7700e-03 -8.2974e+00 1.4476e-01 8.5524e-01 9.0901e-01 9.0987e-02 1.3595e-05 4.4054e-03 6.3970e-04 3.7793e-03 + 4.7800e-03 -8.2974e+00 1.4443e-01 8.5557e-01 9.0901e-01 9.0987e-02 1.1928e-05 4.4171e-03 6.3970e-04 3.7893e-03 + 4.7900e-03 -8.2974e+00 1.4411e-01 8.5589e-01 9.0901e-01 9.0987e-02 1.0262e-05 4.4287e-03 6.3970e-04 3.7993e-03 + 4.8000e-03 -8.2974e+00 1.4379e-01 8.5621e-01 9.0901e-01 9.0987e-02 8.5959e-06 4.4404e-03 6.3970e-04 3.8093e-03 + 4.8100e-03 -8.2974e+00 1.4346e-01 8.5654e-01 9.0901e-01 9.0987e-02 6.9297e-06 4.4521e-03 6.3970e-04 3.8193e-03 + 4.8200e-03 -8.2974e+00 1.4314e-01 8.5686e-01 9.0901e-01 9.0987e-02 5.2635e-06 4.4637e-03 6.3970e-04 3.8293e-03 + 4.8300e-03 -8.2974e+00 1.4282e-01 8.5718e-01 9.0901e-01 9.0987e-02 3.5973e-06 4.4754e-03 6.3970e-04 3.8393e-03 + 4.8400e-03 -8.2974e+00 1.4250e-01 8.5750e-01 9.0901e-01 9.0987e-02 1.9311e-06 4.4871e-03 6.3970e-04 3.8493e-03 + 4.8500e-03 -8.2974e+00 1.4219e-01 8.5781e-01 9.0901e-01 9.0987e-02 2.6493e-07 4.4987e-03 6.3970e-04 3.8593e-03 + 4.8600e-03 -8.2975e+00 1.4210e-01 8.5790e-01 9.0899e-01 9.1014e-02 1.0000e-10 1.0000e-10 6.4087e-04 3.8691e-03 + 4.8700e-03 -8.2976e+00 1.4206e-01 8.5794e-01 9.0895e-01 9.1046e-02 1.0000e-10 1.0000e-10 6.4227e-04 3.8789e-03 + 4.8800e-03 -8.2977e+00 1.4202e-01 8.5798e-01 9.0892e-01 9.1078e-02 1.0000e-10 1.0000e-10 6.4366e-04 3.8886e-03 + 4.8900e-03 -8.2979e+00 1.4197e-01 8.5803e-01 9.0889e-01 9.1110e-02 1.0000e-10 1.0000e-10 6.4505e-04 3.8984e-03 + 4.9000e-03 -8.2980e+00 1.4193e-01 8.5807e-01 9.0886e-01 9.1142e-02 1.0000e-10 1.0000e-10 6.4644e-04 3.9081e-03 + 4.9100e-03 -8.2981e+00 1.4189e-01 8.5811e-01 9.0883e-01 9.1174e-02 1.0000e-10 1.0000e-10 6.4783e-04 3.9179e-03 + 4.9200e-03 -8.2982e+00 1.4185e-01 8.5815e-01 9.0879e-01 9.1206e-02 1.0000e-10 1.0000e-10 6.4922e-04 3.9276e-03 + 4.9300e-03 -8.2984e+00 1.4181e-01 8.5819e-01 9.0876e-01 9.1238e-02 1.0000e-10 1.0000e-10 6.5060e-04 3.9374e-03 + 4.9400e-03 -8.2985e+00 1.4176e-01 8.5824e-01 9.0873e-01 9.1270e-02 1.0000e-10 1.0000e-10 6.5199e-04 3.9471e-03 + 4.9500e-03 -8.2986e+00 1.4172e-01 8.5828e-01 9.0870e-01 9.1302e-02 1.0000e-10 1.0000e-10 6.5338e-04 3.9569e-03 + 4.9600e-03 -8.2988e+00 1.4168e-01 8.5832e-01 9.0867e-01 9.1334e-02 1.0000e-10 1.0000e-10 6.5476e-04 3.9667e-03 + 4.9700e-03 -8.2989e+00 1.4164e-01 8.5836e-01 9.0863e-01 9.1366e-02 1.0000e-10 1.0000e-10 6.5615e-04 3.9764e-03 + 4.9800e-03 -8.2990e+00 1.4160e-01 8.5840e-01 9.0860e-01 9.1398e-02 1.0000e-10 1.0000e-10 6.5753e-04 3.9862e-03 + 4.9900e-03 -8.2991e+00 1.4155e-01 8.5845e-01 9.0857e-01 9.1429e-02 1.0000e-10 1.0000e-10 6.5891e-04 3.9959e-03 + 5.0000e-03 -8.2993e+00 1.4151e-01 8.5849e-01 9.0854e-01 9.1461e-02 1.0000e-10 1.0000e-10 6.6029e-04 4.0057e-03 + 1.0000e-03 -8.2974e+00 9.8567e-01 1.4329e-02 9.0901e-01 9.0987e-02 6.4175e-04 7.2473e-06 6.3970e-04 9.2997e-06 + 2.0000e-03 -8.2974e+00 3.8793e-01 6.1207e-01 9.0901e-01 9.0987e-02 4.7513e-04 1.1739e-03 6.3970e-04 1.0093e-03 + 3.0000e-03 -8.2974e+00 2.4149e-01 7.5851e-01 9.0901e-01 9.0987e-02 3.0851e-04 2.3405e-03 6.3970e-04 2.0093e-03 + 4.0000e-03 -8.2974e+00 1.7531e-01 8.2469e-01 9.0901e-01 9.0987e-02 1.4189e-04 3.5071e-03 6.3970e-04 3.0093e-03 + 5.0000e-03 -8.2993e+00 1.4151e-01 8.5849e-01 9.0854e-01 9.1461e-02 1.0000e-10 1.0000e-10 6.6029e-04 4.0057e-03 + 6.0000e-03 -8.3118e+00 1.3751e-01 8.6249e-01 9.0539e-01 9.4606e-02 1.0000e-10 1.0000e-10 7.9428e-04 4.9819e-03 + 7.0000e-03 -8.3236e+00 1.3383e-01 8.6617e-01 9.0233e-01 9.7673e-02 1.0000e-10 1.0000e-10 9.2071e-04 5.9590e-03 + 8.0000e-03 -8.3349e+00 1.3043e-01 8.6957e-01 8.9933e-01 1.0067e-01 1.0000e-10 1.0000e-10 1.0405e-03 6.9369e-03 + 9.0000e-03 -8.3456e+00 1.2726e-01 8.7274e-01 8.9640e-01 1.0360e-01 1.0000e-10 1.0000e-10 1.1543e-03 7.9155e-03 + 1.0000e-02 -8.3559e+00 1.2431e-01 8.7569e-01 8.9352e-01 1.0648e-01 1.0000e-10 1.0000e-10 1.2627e-03 8.8947e-03 + 1.1000e-02 -8.3658e+00 1.2155e-01 8.7845e-01 8.9070e-01 1.0930e-01 1.0000e-10 1.0000e-10 1.3663e-03 9.8746e-03 + 1.2000e-02 -8.3752e+00 1.1895e-01 8.8105e-01 8.8792e-01 1.1208e-01 1.0000e-10 1.0000e-10 1.4655e-03 1.0855e-02 + 1.3000e-02 -8.3843e+00 1.1650e-01 8.8350e-01 8.8519e-01 1.1481e-01 1.0000e-10 1.0000e-10 1.5607e-03 1.1836e-02 + 1.4000e-02 -8.3931e+00 1.1419e-01 8.8581e-01 8.8251e-01 1.1749e-01 1.0000e-10 1.0000e-10 1.6522e-03 1.2817e-02 + 1.5000e-02 -8.4016e+00 1.1199e-01 8.8801e-01 8.7986e-01 1.2014e-01 1.0000e-10 1.0000e-10 1.7403e-03 1.3799e-02 + 1.6000e-02 -8.4098e+00 1.0991e-01 8.9009e-01 8.7725e-01 1.2275e-01 1.0000e-10 1.0000e-10 1.8252e-03 1.4781e-02 + 1.7000e-02 -8.4178e+00 1.0793e-01 8.9207e-01 8.7468e-01 1.2532e-01 1.0000e-10 1.0000e-10 1.9072e-03 1.5764e-02 + 1.8000e-02 -8.4254e+00 1.0604e-01 8.9396e-01 8.7214e-01 1.2786e-01 1.0000e-10 1.0000e-10 1.9864e-03 1.6746e-02 + 1.9000e-02 -8.4329e+00 1.0423e-01 8.9577e-01 8.6963e-01 1.3037e-01 1.0000e-10 1.0000e-10 2.0631e-03 1.7730e-02 + 2.0000e-02 -8.4401e+00 1.0251e-01 8.9749e-01 8.6716e-01 1.3284e-01 1.0000e-10 1.0000e-10 2.1374e-03 1.8713e-02 + 2.1000e-02 -8.4472e+00 1.0086e-01 8.9914e-01 8.6471e-01 1.3529e-01 1.0000e-10 1.0000e-10 2.2094e-03 1.9697e-02 + 2.2000e-02 -8.4540e+00 9.9270e-02 9.0073e-01 8.6230e-01 1.3770e-01 1.0000e-10 1.0000e-10 2.2793e-03 2.0681e-02 + 2.3000e-02 -8.4607e+00 9.7747e-02 9.0225e-01 8.5991e-01 1.4009e-01 1.0000e-10 1.0000e-10 2.3472e-03 2.1666e-02 + 2.4000e-02 -8.4672e+00 9.6283e-02 9.0372e-01 8.5754e-01 1.4246e-01 1.0000e-10 1.0000e-10 2.4132e-03 2.2650e-02 + 2.5000e-02 -8.4735e+00 9.4874e-02 9.0513e-01 8.5520e-01 1.4480e-01 1.0000e-10 1.0000e-10 2.4774e-03 2.3635e-02 + 2.6000e-02 -8.4797e+00 9.3517e-02 9.0648e-01 8.5289e-01 1.4711e-01 1.0000e-10 1.0000e-10 2.5400e-03 2.4621e-02 + 2.7000e-02 -8.4857e+00 9.2208e-02 9.0779e-01 8.5060e-01 1.4940e-01 1.0000e-10 1.0000e-10 2.6009e-03 2.5606e-02 + 2.8000e-02 -8.4915e+00 9.0944e-02 9.0906e-01 8.4833e-01 1.5167e-01 1.0000e-10 1.0000e-10 2.6603e-03 2.6592e-02 + 2.9000e-02 -8.4973e+00 8.9723e-02 9.1028e-01 8.4608e-01 1.5392e-01 1.0000e-10 1.0000e-10 2.7182e-03 2.7578e-02 + 3.0000e-02 -8.5029e+00 8.8542e-02 9.1146e-01 8.4386e-01 1.5614e-01 1.0000e-10 1.0000e-10 2.7748e-03 2.8564e-02 + 3.1000e-02 -8.5084e+00 8.7400e-02 9.1260e-01 8.4166e-01 1.5834e-01 1.0000e-10 1.0000e-10 2.8300e-03 2.9550e-02 + 3.2000e-02 -8.5137e+00 8.6294e-02 9.1371e-01 8.3947e-01 1.6053e-01 1.0000e-10 1.0000e-10 2.8840e-03 3.0536e-02 + 3.3000e-02 -8.5190e+00 8.5221e-02 9.1478e-01 8.3731e-01 1.6269e-01 1.0000e-10 1.0000e-10 2.9367e-03 3.1523e-02 + 3.4000e-02 -8.5241e+00 8.4182e-02 9.1582e-01 8.3516e-01 1.6484e-01 1.0000e-10 1.0000e-10 2.9883e-03 3.2510e-02 + 3.5000e-02 -8.5292e+00 8.3173e-02 9.1683e-01 8.3304e-01 1.6696e-01 1.0000e-10 1.0000e-10 3.0388e-03 3.3497e-02 + 3.6000e-02 -8.5341e+00 8.2193e-02 9.1781e-01 8.3093e-01 1.6907e-01 1.0000e-10 1.0000e-10 3.0882e-03 3.4484e-02 + 3.7000e-02 -8.5390e+00 8.1241e-02 9.1876e-01 8.2884e-01 1.7116e-01 1.0000e-10 1.0000e-10 3.1366e-03 3.5472e-02 + 3.8000e-02 -8.5437e+00 8.0316e-02 9.1968e-01 8.2677e-01 1.7323e-01 1.0000e-10 1.0000e-10 3.1840e-03 3.6459e-02 + 3.9000e-02 -8.5484e+00 7.9416e-02 9.2058e-01 8.2471e-01 1.7529e-01 1.0000e-10 1.0000e-10 3.2304e-03 3.7447e-02 + 4.0000e-02 -8.5529e+00 7.8540e-02 9.2146e-01 8.2267e-01 1.7733e-01 1.0000e-10 1.0000e-10 3.2760e-03 3.8435e-02 + 4.1000e-02 -8.5574e+00 7.7688e-02 9.2231e-01 8.2065e-01 1.7935e-01 1.0000e-10 1.0000e-10 3.3206e-03 3.9423e-02 + 4.2000e-02 -8.5618e+00 7.6857e-02 9.2314e-01 8.1865e-01 1.8135e-01 1.0000e-10 1.0000e-10 3.3645e-03 4.0411e-02 + 4.3000e-02 -8.5662e+00 7.6048e-02 9.2395e-01 8.1665e-01 1.8335e-01 1.0000e-10 1.0000e-10 3.4075e-03 4.1399e-02 + 4.4000e-02 -8.5704e+00 7.5259e-02 9.2474e-01 8.1468e-01 1.8532e-01 1.0000e-10 1.0000e-10 3.4497e-03 4.2388e-02 + 4.5000e-02 -8.5746e+00 7.4489e-02 9.2551e-01 8.1272e-01 1.8728e-01 1.0000e-10 1.0000e-10 3.4911e-03 4.3376e-02 + 4.6000e-02 -8.5787e+00 7.3738e-02 9.2626e-01 8.1077e-01 1.8923e-01 1.0000e-10 1.0000e-10 3.5318e-03 4.4365e-02 + 4.7000e-02 -8.5827e+00 7.3005e-02 9.2699e-01 8.0884e-01 1.9116e-01 1.0000e-10 1.0000e-10 3.5718e-03 4.5354e-02 + 4.8000e-02 -8.5867e+00 7.2290e-02 9.2771e-01 8.0692e-01 1.9308e-01 1.0000e-10 1.0000e-10 3.6111e-03 4.6343e-02 + 4.9000e-02 -8.5906e+00 7.1590e-02 9.2841e-01 8.0502e-01 1.9498e-01 1.0000e-10 1.0000e-10 3.6498e-03 4.7332e-02 + 5.0000e-02 -8.5945e+00 7.0907e-02 9.2909e-01 8.0313e-01 1.9687e-01 1.0000e-10 1.0000e-10 3.6878e-03 4.8321e-02 + 5.1000e-02 -8.5982e+00 7.0239e-02 9.2976e-01 8.0125e-01 1.9875e-01 1.0000e-10 1.0000e-10 3.7252e-03 4.9310e-02 + 5.2000e-02 -8.6020e+00 6.9586e-02 9.3041e-01 7.9939e-01 2.0061e-01 1.0000e-10 1.0000e-10 3.7619e-03 5.0300e-02 + 5.3000e-02 -8.6056e+00 6.8947e-02 9.3105e-01 7.9753e-01 2.0247e-01 1.0000e-10 1.0000e-10 3.7981e-03 5.1289e-02 + 5.4000e-02 -8.6092e+00 6.8322e-02 9.3168e-01 7.9570e-01 2.0430e-01 1.0000e-10 1.0000e-10 3.8337e-03 5.2279e-02 + 5.5000e-02 -8.6128e+00 6.7710e-02 9.3229e-01 7.9387e-01 2.0613e-01 1.0000e-10 1.0000e-10 3.8688e-03 5.3269e-02 + 5.6000e-02 -8.6163e+00 6.7111e-02 9.3289e-01 7.9206e-01 2.0794e-01 1.0000e-10 1.0000e-10 3.9033e-03 5.4258e-02 + 5.7000e-02 -8.6198e+00 6.6524e-02 9.3348e-01 7.9026e-01 2.0974e-01 1.0000e-10 1.0000e-10 3.9373e-03 5.5248e-02 + 5.8000e-02 -8.6232e+00 6.5950e-02 9.3405e-01 7.8847e-01 2.1153e-01 1.0000e-10 1.0000e-10 3.9708e-03 5.6238e-02 + 5.9000e-02 -8.6265e+00 6.5386e-02 9.3461e-01 7.8669e-01 2.1331e-01 1.0000e-10 1.0000e-10 4.0037e-03 5.7228e-02 + 6.0000e-02 -8.6298e+00 6.4834e-02 9.3517e-01 7.8492e-01 2.1508e-01 1.0000e-10 1.0000e-10 4.0362e-03 5.8219e-02 + 6.1000e-02 -8.6331e+00 6.4293e-02 9.3571e-01 7.8317e-01 2.1683e-01 1.0000e-10 1.0000e-10 4.0683e-03 5.9209e-02 + 6.2000e-02 -8.6363e+00 6.3762e-02 9.3624e-01 7.8142e-01 2.1858e-01 1.0000e-10 1.0000e-10 4.0999e-03 6.0199e-02 + 6.3000e-02 -8.6395e+00 6.3242e-02 9.3676e-01 7.7969e-01 2.2031e-01 1.0000e-10 1.0000e-10 4.1310e-03 6.1190e-02 + 6.4000e-02 -8.6426e+00 6.2731e-02 9.3727e-01 7.7797e-01 2.2203e-01 1.0000e-10 1.0000e-10 4.1617e-03 6.2180e-02 + 6.5000e-02 -8.6457e+00 6.2230e-02 9.3777e-01 7.7626e-01 2.2374e-01 1.0000e-10 1.0000e-10 4.1920e-03 6.3171e-02 + 6.6000e-02 -8.6487e+00 6.1738e-02 9.3826e-01 7.7456e-01 2.2544e-01 1.0000e-10 1.0000e-10 4.2218e-03 6.4162e-02 + 6.7000e-02 -8.6517e+00 6.1255e-02 9.3875e-01 7.7287e-01 2.2713e-01 1.0000e-10 1.0000e-10 4.2513e-03 6.5153e-02 + 6.8000e-02 -8.6547e+00 6.0780e-02 9.3922e-01 7.7119e-01 2.2881e-01 1.0000e-10 1.0000e-10 4.2804e-03 6.6144e-02 + 6.9000e-02 -8.6576e+00 6.0314e-02 9.3969e-01 7.6952e-01 2.3048e-01 1.0000e-10 1.0000e-10 4.3091e-03 6.7135e-02 + 7.0000e-02 -8.6605e+00 5.9857e-02 9.4014e-01 7.6786e-01 2.3214e-01 1.0000e-10 1.0000e-10 4.3374e-03 6.8126e-02 + 7.1000e-02 -8.6634e+00 5.9407e-02 9.4059e-01 7.6621e-01 2.3379e-01 1.0000e-10 1.0000e-10 4.3654e-03 6.9117e-02 + 7.2000e-02 -8.6662e+00 5.8965e-02 9.4103e-01 7.6457e-01 2.3543e-01 1.0000e-10 1.0000e-10 4.3930e-03 7.0108e-02 + 7.3000e-02 -8.6690e+00 5.8531e-02 9.4147e-01 7.6294e-01 2.3706e-01 1.0000e-10 1.0000e-10 4.4202e-03 7.1099e-02 + 7.4000e-02 -8.6718e+00 5.8104e-02 9.4190e-01 7.6132e-01 2.3868e-01 1.0000e-10 1.0000e-10 4.4471e-03 7.2091e-02 + 7.5000e-02 -8.6745e+00 5.7684e-02 9.4232e-01 7.5970e-01 2.4030e-01 1.0000e-10 1.0000e-10 4.4737e-03 7.3082e-02 + 7.6000e-02 -8.6772e+00 5.7271e-02 9.4273e-01 7.5810e-01 2.4190e-01 1.0000e-10 1.0000e-10 4.5000e-03 7.4074e-02 + 7.7000e-02 -8.6798e+00 5.6864e-02 9.4314e-01 7.5651e-01 2.4349e-01 1.0000e-10 1.0000e-10 4.5259e-03 7.5065e-02 + 7.8000e-02 -8.6824e+00 5.6465e-02 9.4354e-01 7.5492e-01 2.4508e-01 1.0000e-10 1.0000e-10 4.5515e-03 7.6057e-02 + 7.9000e-02 -8.6850e+00 5.6071e-02 9.4393e-01 7.5335e-01 2.4665e-01 1.0000e-10 1.0000e-10 4.5769e-03 7.7049e-02 + 8.0000e-02 -8.6876e+00 5.5684e-02 9.4432e-01 7.5178e-01 2.4822e-01 1.0000e-10 1.0000e-10 4.6019e-03 7.8040e-02 + 8.1000e-02 -8.6901e+00 5.5303e-02 9.4470e-01 7.5023e-01 2.4977e-01 1.0000e-10 1.0000e-10 4.6266e-03 7.9032e-02 + 8.2000e-02 -8.6926e+00 5.4928e-02 9.4507e-01 7.4868e-01 2.5132e-01 1.0000e-10 1.0000e-10 4.6511e-03 8.0024e-02 + 8.3000e-02 -8.6951e+00 5.4559e-02 9.4544e-01 7.4714e-01 2.5286e-01 1.0000e-10 1.0000e-10 4.6752e-03 8.1016e-02 + 8.4000e-02 -8.6976e+00 5.4196e-02 9.4580e-01 7.4560e-01 2.5440e-01 1.0000e-10 1.0000e-10 4.6991e-03 8.2008e-02 + 8.5000e-02 -8.7000e+00 5.3837e-02 9.4616e-01 7.4408e-01 2.5592e-01 1.0000e-10 1.0000e-10 4.7228e-03 8.3000e-02 + 8.6000e-02 -8.7024e+00 5.3485e-02 9.4652e-01 7.4256e-01 2.5744e-01 1.0000e-10 1.0000e-10 4.7461e-03 8.3992e-02 + 8.7000e-02 -8.7047e+00 5.3137e-02 9.4686e-01 7.4106e-01 2.5894e-01 1.0000e-10 1.0000e-10 4.7693e-03 8.4984e-02 + 8.8000e-02 -8.7071e+00 5.2795e-02 9.4721e-01 7.3956e-01 2.6044e-01 1.0000e-10 1.0000e-10 4.7921e-03 8.5977e-02 + 8.9000e-02 -8.7094e+00 5.2457e-02 9.4754e-01 7.3807e-01 2.6193e-01 1.0000e-10 1.0000e-10 4.8147e-03 8.6969e-02 + 9.0000e-02 -8.7117e+00 5.2125e-02 9.4788e-01 7.3658e-01 2.6342e-01 1.0000e-10 1.0000e-10 4.8371e-03 8.7961e-02 + 9.1000e-02 -8.7140e+00 5.1797e-02 9.4820e-01 7.3511e-01 2.6489e-01 1.0000e-10 1.0000e-10 4.8592e-03 8.8954e-02 + 9.2000e-02 -8.7162e+00 5.1474e-02 9.4853e-01 7.3364e-01 2.6636e-01 1.0000e-10 1.0000e-10 4.8811e-03 8.9946e-02 + 9.3000e-02 -8.7185e+00 5.1155e-02 9.4884e-01 7.3218e-01 2.6782e-01 1.0000e-10 1.0000e-10 4.9028e-03 9.0939e-02 + 9.4000e-02 -8.7207e+00 5.0841e-02 9.4916e-01 7.3073e-01 2.6927e-01 1.0000e-10 1.0000e-10 4.9243e-03 9.1932e-02 + 9.5000e-02 -8.7228e+00 5.0531e-02 9.4947e-01 7.2928e-01 2.7072e-01 1.0000e-10 1.0000e-10 4.9455e-03 9.2924e-02 + 9.6000e-02 -8.7250e+00 5.0226e-02 9.4977e-01 7.2784e-01 2.7216e-01 1.0000e-10 1.0000e-10 4.9665e-03 9.3917e-02 + 9.7000e-02 -8.7271e+00 4.9924e-02 9.5008e-01 7.2641e-01 2.7359e-01 1.0000e-10 1.0000e-10 4.9873e-03 9.4910e-02 + 9.8000e-02 -8.7292e+00 4.9627e-02 9.5037e-01 7.2499e-01 2.7501e-01 1.0000e-10 1.0000e-10 5.0079e-03 9.5903e-02 + 9.9000e-02 -8.7313e+00 4.9334e-02 9.5067e-01 7.2357e-01 2.7643e-01 1.0000e-10 1.0000e-10 5.0283e-03 9.6895e-02 + 1.0000e-01 -8.7334e+00 4.9044e-02 9.5096e-01 7.2216e-01 2.7784e-01 1.0000e-10 1.0000e-10 5.0485e-03 9.7888e-02 + 1.0000e-01 -8.7334e+00 4.9044e-02 9.5096e-01 7.2216e-01 2.7784e-01 1.0000e-10 1.0000e-10 5.0485e-03 9.7888e-02 + 2.0000e-01 -8.8746e+00 3.1529e-02 9.6847e-01 6.0843e-01 3.9157e-01 1.0000e-10 1.0000e-10 6.4250e-03 1.9735e-01 + 3.0000e-01 -8.9515e+00 2.3611e-02 9.7639e-01 5.2912e-01 4.7088e-01 1.0000e-10 1.0000e-10 7.1824e-03 2.9701e-01 + 4.0000e-01 -9.0015e+00 1.8992e-02 9.8101e-01 4.6954e-01 5.3046e-01 1.0000e-10 1.0000e-10 7.6814e-03 3.9677e-01 + 5.0000e-01 -9.0371e+00 1.5935e-02 9.8407e-01 4.2272e-01 5.7728e-01 1.0000e-10 1.0000e-10 8.0411e-03 4.9659e-01 + 6.0000e-01 -9.0640e+00 1.3750e-02 9.8625e-01 3.8479e-01 6.1521e-01 1.0000e-10 1.0000e-10 8.3153e-03 5.9645e-01 + 7.0000e-01 -9.0851e+00 1.2105e-02 9.8790e-01 3.5335e-01 6.4665e-01 1.0000e-10 1.0000e-10 8.5323e-03 6.9633e-01 + 8.0000e-01 -9.1022e+00 1.0819e-02 9.8918e-01 3.2680e-01 6.7320e-01 1.0000e-10 1.0000e-10 8.7090e-03 7.9623e-01 + 9.0000e-01 -9.1162e+00 9.7855e-03 9.9021e-01 3.0406e-01 6.9594e-01 1.0000e-10 1.0000e-10 8.8560e-03 8.9615e-01 + 1.0000e+00 -9.1281e+00 8.9352e-03 9.9106e-01 2.8435e-01 7.1565e-01 1.0000e-10 1.0000e-10 8.9804e-03 9.9608e-01 + 1.1000e+00 -9.1382e+00 8.2229e-03 9.9178e-01 2.6708e-01 7.3292e-01 1.0000e-10 1.0000e-10 9.0872e-03 1.0960e+00 + 1.2000e+00 -9.1470e+00 7.6172e-03 9.9238e-01 2.5183e-01 7.4817e-01 1.0000e-10 1.0000e-10 9.1799e-03 1.1960e+00 + 1.3000e+00 -9.1547e+00 7.0957e-03 9.9290e-01 2.3825e-01 7.6175e-01 1.0000e-10 1.0000e-10 9.2612e-03 1.2959e+00 + 1.4000e+00 -9.1614e+00 6.6418e-03 9.9336e-01 2.2608e-01 7.7392e-01 1.0000e-10 1.0000e-10 9.3332e-03 1.3959e+00 + 1.5000e+00 -9.1674e+00 6.2431e-03 9.9376e-01 2.1511e-01 7.8489e-01 1.0000e-10 1.0000e-10 9.3973e-03 1.4958e+00 + 1.6000e+00 -9.1728e+00 5.8899e-03 9.9411e-01 2.0516e-01 7.9484e-01 1.0000e-10 1.0000e-10 9.4548e-03 1.5958e+00 + 1.7000e+00 -9.1776e+00 5.5749e-03 9.9443e-01 1.9610e-01 8.0390e-01 1.0000e-10 1.0000e-10 9.5068e-03 1.6958e+00 + 1.8000e+00 -9.1820e+00 5.2921e-03 9.9471e-01 1.8782e-01 8.1218e-01 1.0000e-10 1.0000e-10 9.5539e-03 1.7957e+00 + 1.9000e+00 -9.1860e+00 5.0369e-03 9.9496e-01 1.8021e-01 8.1979e-01 1.0000e-10 1.0000e-10 9.5968e-03 1.8957e+00 + 2.0000e+00 -9.1896e+00 4.8052e-03 9.9519e-01 1.7320e-01 8.2680e-01 1.0000e-10 1.0000e-10 9.6361e-03 1.9957e+00 + 2.1000e+00 -9.1929e+00 4.5941e-03 9.9541e-01 1.6672e-01 8.3328e-01 1.0000e-10 1.0000e-10 9.6722e-03 2.0957e+00 + 2.2000e+00 -9.1960e+00 4.4009e-03 9.9560e-01 1.6071e-01 8.3929e-01 1.0000e-10 1.0000e-10 9.7055e-03 2.1957e+00 + 2.3000e+00 -9.1988e+00 4.2233e-03 9.9578e-01 1.5512e-01 8.4488e-01 1.0000e-10 1.0000e-10 9.7364e-03 2.2956e+00 + 2.4000e+00 -9.2015e+00 4.0596e-03 9.9594e-01 1.4990e-01 8.5010e-01 1.0000e-10 1.0000e-10 9.7650e-03 2.3956e+00 + 2.5000e+00 -9.2039e+00 3.9082e-03 9.9609e-01 1.4503e-01 8.5497e-01 1.0000e-10 1.0000e-10 9.7916e-03 2.4956e+00 + 2.6000e+00 -9.2062e+00 3.7677e-03 9.9623e-01 1.4047e-01 8.5953e-01 1.0000e-10 1.0000e-10 9.8164e-03 2.5956e+00 + 2.7000e+00 -9.2083e+00 3.6370e-03 9.9636e-01 1.3618e-01 8.6382e-01 1.0000e-10 1.0000e-10 9.8396e-03 2.6956e+00 + 2.8000e+00 -9.2103e+00 3.5151e-03 9.9648e-01 1.3216e-01 8.6784e-01 1.0000e-10 1.0000e-10 9.8614e-03 2.7956e+00 + 2.9000e+00 -9.2122e+00 3.4011e-03 9.9660e-01 1.2836e-01 8.7164e-01 1.0000e-10 1.0000e-10 9.8818e-03 2.8955e+00 + 3.0000e+00 -9.2139e+00 3.2944e-03 9.9671e-01 1.2478e-01 8.7522e-01 1.0000e-10 1.0000e-10 9.9010e-03 2.9955e+00 + 3.1000e+00 -9.2156e+00 3.1941e-03 9.9681e-01 1.2139e-01 8.7861e-01 1.0000e-10 1.0000e-10 9.9191e-03 3.0955e+00 + 3.2000e+00 -9.2171e+00 3.0998e-03 9.9690e-01 1.1818e-01 8.8182e-01 1.0000e-10 1.0000e-10 9.9363e-03 3.1955e+00 + 3.3000e+00 -9.2186e+00 3.0109e-03 9.9699e-01 1.1514e-01 8.8486e-01 1.0000e-10 1.0000e-10 9.9524e-03 3.2955e+00 + 3.4000e+00 -9.2200e+00 2.9270e-03 9.9707e-01 1.1225e-01 8.8775e-01 1.0000e-10 1.0000e-10 9.9678e-03 3.3955e+00 + 3.5000e+00 -9.2213e+00 2.8476e-03 9.9715e-01 1.0950e-01 8.9050e-01 1.0000e-10 1.0000e-10 9.9823e-03 3.4955e+00 + 3.6000e+00 -9.2226e+00 2.7725e-03 9.9723e-01 1.0688e-01 8.9312e-01 1.0000e-10 1.0000e-10 9.9961e-03 3.5955e+00 + 3.7000e+00 -9.2238e+00 2.7012e-03 9.9730e-01 1.0439e-01 8.9561e-01 1.0000e-10 1.0000e-10 1.0009e-02 3.6955e+00 + 3.8000e+00 -9.2249e+00 2.6335e-03 9.9737e-01 1.0201e-01 8.9799e-01 1.0000e-10 1.0000e-10 1.0022e-02 3.7955e+00 + 3.9000e+00 -9.2260e+00 2.5691e-03 9.9743e-01 9.9738e-02 9.0026e-01 1.0000e-10 1.0000e-10 1.0034e-02 3.8955e+00 + 4.0000e+00 -9.2270e+00 2.5078e-03 9.9749e-01 9.7564e-02 9.0244e-01 1.0000e-10 1.0000e-10 1.0045e-02 3.9954e+00 + 4.1000e+00 -9.2280e+00 2.4494e-03 9.9755e-01 9.5483e-02 9.0452e-01 1.0000e-10 1.0000e-10 1.0056e-02 4.0954e+00 + 4.2000e+00 -9.2289e+00 2.3936e-03 9.9761e-01 9.3489e-02 9.0651e-01 1.0000e-10 1.0000e-10 1.0066e-02 4.1954e+00 + 4.3000e+00 -9.2298e+00 2.3404e-03 9.9766e-01 9.1577e-02 9.0842e-01 1.0000e-10 1.0000e-10 1.0076e-02 4.2954e+00 + 4.4000e+00 -9.2307e+00 2.2894e-03 9.9771e-01 8.9742e-02 9.1026e-01 1.0000e-10 1.0000e-10 1.0086e-02 4.3954e+00 + 4.5000e+00 -9.2315e+00 2.2406e-03 9.9776e-01 8.7979e-02 9.1202e-01 1.0000e-10 1.0000e-10 1.0095e-02 4.4954e+00 + 4.6000e+00 -9.2323e+00 2.1939e-03 9.9781e-01 8.6284e-02 9.1372e-01 1.0000e-10 1.0000e-10 1.0104e-02 4.5954e+00 + 4.7000e+00 -9.2331e+00 2.1491e-03 9.9785e-01 8.4653e-02 9.1535e-01 1.0000e-10 1.0000e-10 1.0112e-02 4.6954e+00 + 4.8000e+00 -9.2338e+00 2.1060e-03 9.9789e-01 8.3083e-02 9.1692e-01 1.0000e-10 1.0000e-10 1.0121e-02 4.7954e+00 + 4.9000e+00 -9.2345e+00 2.0647e-03 9.9794e-01 8.1570e-02 9.1843e-01 1.0000e-10 1.0000e-10 1.0128e-02 4.8954e+00 + 5.0000e+00 -9.2352e+00 2.0249e-03 9.9798e-01 8.0112e-02 9.1989e-01 1.0000e-10 1.0000e-10 1.0136e-02 4.9954e+00 + 5.1000e+00 -9.2359e+00 1.9867e-03 9.9801e-01 7.8704e-02 9.2130e-01 1.0000e-10 1.0000e-10 1.0143e-02 5.0954e+00 + 5.2000e+00 -9.2365e+00 1.9499e-03 9.9805e-01 7.7346e-02 9.2265e-01 1.0000e-10 1.0000e-10 1.0150e-02 5.1954e+00 + 5.3000e+00 -9.2371e+00 1.9144e-03 9.9809e-01 7.6033e-02 9.2397e-01 1.0000e-10 1.0000e-10 1.0157e-02 5.2954e+00 + 5.4000e+00 -9.2377e+00 1.8802e-03 9.9812e-01 7.4765e-02 9.2524e-01 1.0000e-10 1.0000e-10 1.0163e-02 5.3954e+00 + 5.5000e+00 -9.2383e+00 1.8472e-03 9.9815e-01 7.3538e-02 9.2646e-01 1.0000e-10 1.0000e-10 1.0170e-02 5.4954e+00 + 5.6000e+00 -9.2388e+00 1.8153e-03 9.9818e-01 7.2350e-02 9.2765e-01 1.0000e-10 1.0000e-10 1.0176e-02 5.5954e+00 + 5.7000e+00 -9.2393e+00 1.7845e-03 9.9822e-01 7.1201e-02 9.2880e-01 1.0000e-10 1.0000e-10 1.0182e-02 5.6954e+00 + 5.8000e+00 -9.2398e+00 1.7548e-03 9.9825e-01 7.0087e-02 9.2991e-01 1.0000e-10 1.0000e-10 1.0187e-02 5.7954e+00 + 5.9000e+00 -9.2403e+00 1.7260e-03 9.9827e-01 6.9008e-02 9.3099e-01 1.0000e-10 1.0000e-10 1.0193e-02 5.8954e+00 + 6.0000e+00 -9.2408e+00 1.6982e-03 9.9830e-01 6.7962e-02 9.3204e-01 1.0000e-10 1.0000e-10 1.0198e-02 5.9954e+00 + 6.1000e+00 -9.2413e+00 1.6712e-03 9.9833e-01 6.6947e-02 9.3305e-01 1.0000e-10 1.0000e-10 1.0204e-02 6.0953e+00 + 6.2000e+00 -9.2417e+00 1.6451e-03 9.9835e-01 6.5961e-02 9.3404e-01 1.0000e-10 1.0000e-10 1.0209e-02 6.1953e+00 + 6.3000e+00 -9.2422e+00 1.6198e-03 9.9838e-01 6.5005e-02 9.3500e-01 1.0000e-10 1.0000e-10 1.0213e-02 6.2953e+00 + 6.4000e+00 -9.2426e+00 1.5952e-03 9.9840e-01 6.4076e-02 9.3592e-01 1.0000e-10 1.0000e-10 1.0218e-02 6.3953e+00 + 6.5000e+00 -9.2430e+00 1.5714e-03 9.9843e-01 6.3173e-02 9.3683e-01 1.0000e-10 1.0000e-10 1.0223e-02 6.4953e+00 + 6.6000e+00 -9.2434e+00 1.5483e-03 9.9845e-01 6.2295e-02 9.3771e-01 1.0000e-10 1.0000e-10 1.0227e-02 6.5953e+00 + 6.7000e+00 -9.2438e+00 1.5258e-03 9.9847e-01 6.1441e-02 9.3856e-01 1.0000e-10 1.0000e-10 1.0232e-02 6.6953e+00 + 6.8000e+00 -9.2442e+00 1.5040e-03 9.9850e-01 6.0610e-02 9.3939e-01 1.0000e-10 1.0000e-10 1.0236e-02 6.7953e+00 + 6.9000e+00 -9.2446e+00 1.4829e-03 9.9852e-01 5.9802e-02 9.4020e-01 1.0000e-10 1.0000e-10 1.0240e-02 6.8953e+00 + 7.0000e+00 -9.2449e+00 1.4623e-03 9.9854e-01 5.9015e-02 9.4099e-01 1.0000e-10 1.0000e-10 1.0244e-02 6.9953e+00 + 7.1000e+00 -9.2453e+00 1.4422e-03 9.9856e-01 5.8248e-02 9.4175e-01 1.0000e-10 1.0000e-10 1.0248e-02 7.0953e+00 + 7.2000e+00 -9.2456e+00 1.4227e-03 9.9858e-01 5.7501e-02 9.4250e-01 1.0000e-10 1.0000e-10 1.0252e-02 7.1953e+00 + 7.3000e+00 -9.2459e+00 1.4038e-03 9.9860e-01 5.6773e-02 9.4323e-01 1.0000e-10 1.0000e-10 1.0255e-02 7.2953e+00 + 7.4000e+00 -9.2463e+00 1.3853e-03 9.9861e-01 5.6063e-02 9.4394e-01 1.0000e-10 1.0000e-10 1.0259e-02 7.3953e+00 + 7.5000e+00 -9.2466e+00 1.3673e-03 9.9863e-01 5.5370e-02 9.4463e-01 1.0000e-10 1.0000e-10 1.0262e-02 7.4953e+00 + 7.6000e+00 -9.2469e+00 1.3498e-03 9.9865e-01 5.4695e-02 9.4530e-01 1.0000e-10 1.0000e-10 1.0266e-02 7.5953e+00 + 7.7000e+00 -9.2472e+00 1.3327e-03 9.9867e-01 5.4036e-02 9.4596e-01 1.0000e-10 1.0000e-10 1.0269e-02 7.6953e+00 + 7.8000e+00 -9.2475e+00 1.3160e-03 9.9868e-01 5.3392e-02 9.4661e-01 1.0000e-10 1.0000e-10 1.0273e-02 7.7953e+00 + 7.9000e+00 -9.2478e+00 1.2998e-03 9.9870e-01 5.2764e-02 9.4724e-01 1.0000e-10 1.0000e-10 1.0276e-02 7.8953e+00 + 8.0000e+00 -9.2480e+00 1.2840e-03 9.9872e-01 5.2150e-02 9.4785e-01 1.0000e-10 1.0000e-10 1.0279e-02 7.9953e+00 + 8.1000e+00 -9.2483e+00 1.2685e-03 9.9873e-01 5.1551e-02 9.4845e-01 1.0000e-10 1.0000e-10 1.0282e-02 8.0953e+00 + 8.2000e+00 -9.2486e+00 1.2534e-03 9.9875e-01 5.0965e-02 9.4903e-01 1.0000e-10 1.0000e-10 1.0285e-02 8.1953e+00 + 8.3000e+00 -9.2488e+00 1.2386e-03 9.9876e-01 5.0392e-02 9.4961e-01 1.0000e-10 1.0000e-10 1.0288e-02 8.2953e+00 + 8.4000e+00 -9.2491e+00 1.2242e-03 9.9878e-01 4.9832e-02 9.5017e-01 1.0000e-10 1.0000e-10 1.0290e-02 8.3953e+00 + 8.5000e+00 -9.2493e+00 1.2102e-03 9.9879e-01 4.9285e-02 9.5072e-01 1.0000e-10 1.0000e-10 1.0293e-02 8.4953e+00 + 8.6000e+00 -9.2496e+00 1.1964e-03 9.9880e-01 4.8749e-02 9.5125e-01 1.0000e-10 1.0000e-10 1.0296e-02 8.5953e+00 + 8.7000e+00 -9.2498e+00 1.1830e-03 9.9882e-01 4.8225e-02 9.5178e-01 1.0000e-10 1.0000e-10 1.0299e-02 8.6953e+00 + 8.8000e+00 -9.2500e+00 1.1698e-03 9.9883e-01 4.7712e-02 9.5229e-01 1.0000e-10 1.0000e-10 1.0301e-02 8.7953e+00 + 8.9000e+00 -9.2503e+00 1.1570e-03 9.9884e-01 4.7209e-02 9.5279e-01 1.0000e-10 1.0000e-10 1.0304e-02 8.8953e+00 + 9.0000e+00 -9.2505e+00 1.1444e-03 9.9886e-01 4.6718e-02 9.5328e-01 1.0000e-10 1.0000e-10 1.0306e-02 8.9953e+00 + 9.1000e+00 -9.2507e+00 1.1321e-03 9.9887e-01 4.6236e-02 9.5376e-01 1.0000e-10 1.0000e-10 1.0309e-02 9.0953e+00 + 9.2000e+00 -9.2509e+00 1.1201e-03 9.9888e-01 4.5764e-02 9.5424e-01 1.0000e-10 1.0000e-10 1.0311e-02 9.1953e+00 + 9.3000e+00 -9.2511e+00 1.1083e-03 9.9889e-01 4.5302e-02 9.5470e-01 1.0000e-10 1.0000e-10 1.0313e-02 9.2953e+00 + 9.4000e+00 -9.2513e+00 1.0967e-03 9.9890e-01 4.4849e-02 9.5515e-01 1.0000e-10 1.0000e-10 1.0316e-02 9.3953e+00 + 9.5000e+00 -9.2515e+00 1.0854e-03 9.9891e-01 4.4405e-02 9.5560e-01 1.0000e-10 1.0000e-10 1.0318e-02 9.4953e+00 + 9.6000e+00 -9.2517e+00 1.0744e-03 9.9893e-01 4.3969e-02 9.5603e-01 1.0000e-10 1.0000e-10 1.0320e-02 9.5953e+00 + 9.7000e+00 -9.2519e+00 1.0635e-03 9.9894e-01 4.3543e-02 9.5646e-01 1.0000e-10 1.0000e-10 1.0322e-02 9.6953e+00 + 9.8000e+00 -9.2521e+00 1.0529e-03 9.9895e-01 4.3124e-02 9.5688e-01 1.0000e-10 1.0000e-10 1.0324e-02 9.7953e+00 + 9.9000e+00 -9.2523e+00 1.0425e-03 9.9896e-01 4.2713e-02 9.5729e-01 1.0000e-10 1.0000e-10 1.0326e-02 9.8953e+00 + 1.0000e+01 -9.2525e+00 1.0323e-03 9.9897e-01 4.2310e-02 9.5769e-01 1.0000e-10 1.0000e-10 1.0328e-02 9.9953e+00 diff --git a/Sun/examples/ex11.log b/Sun/examples/ex11.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex11.out b/Sun/examples/ex11.out new file mode 100644 index 00000000..fcfa23e9 --- /dev/null +++ b/Sun/examples/ex11.out @@ -0,0 +1,2858 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex11 + Output file: ex11.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + PRINT + TITLE Example 11.--Transport and ion exchange. + SOLUTION 0 CaCl2 + units mmol/kgw + temp 25.0 + pH 7.0 charge + pe 12.5 O2(g) -0.68 + Ca 0.6 + Cl 1.2 + SOLUTION 1-40 Initial solution for column + units mmol/kgw + temp 25.0 + pH 7.0 charge + pe 12.5 O2(g) -0.68 + Na 1.0 + K 0.2 + N(5) 1.2 + EXCHANGE 1-40 + equilibrate 1 + X 0.0011 + ADVECTION + cells 40 + shifts 120 + punch_cells 40 + punch_frequency 1 + print_cells 40 + print_frequency 20 + SELECTED_OUTPUT + file ex11adv.sel + reset false + step + totals Na Cl K Ca + USER_PUNCH + heading Pore_vol + 10 PUNCH (STEP_NO + .5) / 40. + END +----- +TITLE +----- + + Example 11.--Transport and ion exchange. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. CaCl2 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 6.000e-04 6.000e-04 + Cl 1.200e-03 1.200e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.800e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -5.732e-20 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 4.630e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 4 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 6.000e-04 + Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 + CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.68 -3.64 -2.96 O2 + +Initial solution 1. Initial solution for column + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 2.000e-04 2.000e-04 + N(5) 1.200e-03 1.200e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.114e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -8.455e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(5) 1.200e-03 + NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.68 -3.64 -2.96 O2 + +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 0. CaCl2 +Using exchange 1. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 4.933e-04 9.866e-04 8.969e-01 -0.069 + KX 9.224e-05 9.224e-05 8.385e-02 -0.018 + NaX 2.120e-05 2.120e-05 1.928e-02 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.067e-04 1.067e-04 + Cl 1.200e-03 1.200e-03 + K 4.584e-04 4.584e-04 + Na 5.281e-04 5.281e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.307e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.215e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 9.601e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 8 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.042e-07 1.003e-07 -6.982 -6.999 -0.017 + OH- 1.040e-07 9.983e-08 -6.983 -7.001 -0.018 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 1.067e-04 + Ca+2 1.067e-04 9.098e-05 -3.972 -4.041 -0.069 + CaOH+ 1.568e-10 1.506e-10 -9.805 -9.822 -0.018 +Cl 1.200e-03 + Cl- 1.200e-03 1.152e-03 -2.921 -2.938 -0.018 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 4.584e-04 + K+ 4.584e-04 4.402e-04 -3.339 -3.356 -0.018 + KOH 1.522e-11 1.522e-11 -10.818 -10.818 0.000 +Na 5.281e-04 + Na+ 5.281e-04 5.073e-04 -3.277 -3.295 -0.017 + NaOH 3.342e-11 3.343e-11 -10.476 -10.476 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.82 -6.23 1.58 NaCl + O2(g) -0.68 -3.64 -2.96 O2 + +------------------------------------ +Beginning of advection calculations. +------------------------------------ + +Beginning of advection time step 1, cumulative pore volumes 0.025000. +Beginning of advection time step 2, cumulative pore volumes 0.050000. +Beginning of advection time step 3, cumulative pore volumes 0.075000. +Beginning of advection time step 4, cumulative pore volumes 0.100000. +Beginning of advection time step 5, cumulative pore volumes 0.125000. +Beginning of advection time step 6, cumulative pore volumes 0.150000. +Beginning of advection time step 7, cumulative pore volumes 0.175000. +Beginning of advection time step 8, cumulative pore volumes 0.200000. +Beginning of advection time step 9, cumulative pore volumes 0.225000. +Beginning of advection time step 10, cumulative pore volumes 0.250000. +Beginning of advection time step 11, cumulative pore volumes 0.275000. +Beginning of advection time step 12, cumulative pore volumes 0.300000. +Beginning of advection time step 13, cumulative pore volumes 0.325000. +Beginning of advection time step 14, cumulative pore volumes 0.350000. +Beginning of advection time step 15, cumulative pore volumes 0.375000. +Beginning of advection time step 16, cumulative pore volumes 0.400000. +Beginning of advection time step 17, cumulative pore volumes 0.425000. +Beginning of advection time step 18, cumulative pore volumes 0.450000. +Beginning of advection time step 19, cumulative pore volumes 0.475000. +Beginning of advection time step 20, cumulative pore volumes 0.500000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 2.000e-04 2.000e-04 + N 1.200e-03 1.200e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.114e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.539e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 + NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 +N(0) 2.552e-19 + N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 +N(3) 2.686e-16 + NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 +N(5) 1.200e-03 + NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.63 -18.89 -3.26 N2 + NH3(g) -66.75 -64.98 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Beginning of advection time step 21, cumulative pore volumes 0.525000. +Beginning of advection time step 22, cumulative pore volumes 0.550000. +Beginning of advection time step 23, cumulative pore volumes 0.575000. +Beginning of advection time step 24, cumulative pore volumes 0.600000. +Beginning of advection time step 25, cumulative pore volumes 0.625000. +Beginning of advection time step 26, cumulative pore volumes 0.650000. +Beginning of advection time step 27, cumulative pore volumes 0.675000. +Beginning of advection time step 28, cumulative pore volumes 0.700000. +Beginning of advection time step 29, cumulative pore volumes 0.725000. +Beginning of advection time step 30, cumulative pore volumes 0.750000. +Beginning of advection time step 31, cumulative pore volumes 0.775000. +Beginning of advection time step 32, cumulative pore volumes 0.800000. +Beginning of advection time step 33, cumulative pore volumes 0.825000. +Beginning of advection time step 34, cumulative pore volumes 0.850000. +Beginning of advection time step 35, cumulative pore volumes 0.875000. +Beginning of advection time step 36, cumulative pore volumes 0.900000. +Beginning of advection time step 37, cumulative pore volumes 0.925000. +Beginning of advection time step 38, cumulative pore volumes 0.950000. +Beginning of advection time step 39, cumulative pore volumes 0.975000. +Beginning of advection time step 40, cumulative pore volumes 1.000000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.200e-03 1.200e-03 + K 2.000e-04 2.000e-04 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.450e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.960e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Cl 1.200e-03 + Cl- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.54 -5.95 1.58 NaCl + O2(g) -0.68 -3.64 -2.96 O2 + +Beginning of advection time step 41, cumulative pore volumes 1.025000. +Beginning of advection time step 42, cumulative pore volumes 1.050000. +Beginning of advection time step 43, cumulative pore volumes 1.075000. +Beginning of advection time step 44, cumulative pore volumes 1.100000. +Beginning of advection time step 45, cumulative pore volumes 1.125000. +Beginning of advection time step 46, cumulative pore volumes 1.150000. +Beginning of advection time step 47, cumulative pore volumes 1.175000. +Beginning of advection time step 48, cumulative pore volumes 1.200000. +Beginning of advection time step 49, cumulative pore volumes 1.225000. +Beginning of advection time step 50, cumulative pore volumes 1.250000. +Beginning of advection time step 51, cumulative pore volumes 1.275000. +Beginning of advection time step 52, cumulative pore volumes 1.300000. +Beginning of advection time step 53, cumulative pore volumes 1.325000. +Beginning of advection time step 54, cumulative pore volumes 1.350000. +Beginning of advection time step 55, cumulative pore volumes 1.375000. +Beginning of advection time step 56, cumulative pore volumes 1.400000. +Beginning of advection time step 57, cumulative pore volumes 1.425000. +Beginning of advection time step 58, cumulative pore volumes 1.450000. +Beginning of advection time step 59, cumulative pore volumes 1.475000. +Beginning of advection time step 60, cumulative pore volumes 1.500000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 7.000e-04 7.000e-04 6.363e-01 -0.017 + NaX 4.000e-04 4.000e-04 3.637e-01 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.200e-03 1.200e-03 + K 3.105e-04 3.105e-04 + Na 8.895e-04 8.895e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -2.836e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 3.548e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 4 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Cl 1.200e-03 + Cl- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 3.105e-04 + K+ 3.105e-04 2.986e-04 -3.508 -3.525 -0.017 + KOH 1.033e-11 1.033e-11 -10.986 -10.986 0.000 +Na 8.895e-04 + Na+ 8.895e-04 8.558e-04 -3.051 -3.068 -0.017 + NaOH 5.641e-11 5.643e-11 -10.249 -10.249 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.59 -6.01 1.58 NaCl + O2(g) -0.68 -3.64 -2.96 O2 + +Beginning of advection time step 61, cumulative pore volumes 1.525000. +Beginning of advection time step 62, cumulative pore volumes 1.550000. +Beginning of advection time step 63, cumulative pore volumes 1.575000. +Beginning of advection time step 64, cumulative pore volumes 1.600000. +Beginning of advection time step 65, cumulative pore volumes 1.625000. +Beginning of advection time step 66, cumulative pore volumes 1.650000. +Beginning of advection time step 67, cumulative pore volumes 1.675000. +Beginning of advection time step 68, cumulative pore volumes 1.700000. +Beginning of advection time step 69, cumulative pore volumes 1.725000. +Beginning of advection time step 70, cumulative pore volumes 1.750000. +Beginning of advection time step 71, cumulative pore volumes 1.775000. +Beginning of advection time step 72, cumulative pore volumes 1.800000. +Beginning of advection time step 73, cumulative pore volumes 1.825000. +Beginning of advection time step 74, cumulative pore volumes 1.850000. +Beginning of advection time step 75, cumulative pore volumes 1.875000. +Beginning of advection time step 76, cumulative pore volumes 1.900000. +Beginning of advection time step 77, cumulative pore volumes 1.925000. +Beginning of advection time step 78, cumulative pore volumes 1.950000. +Beginning of advection time step 79, cumulative pore volumes 1.975000. +Beginning of advection time step 80, cumulative pore volumes 2.000000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 + KX 6.870e-09 6.870e-09 6.246e-06 -0.021 + NaX 2.513e-21 2.513e-21 2.285e-18 -0.020 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 6.000e-04 6.000e-04 + Cl 1.200e-03 1.200e-03 + K 7.667e-08 7.667e-08 + Na 1.406e-19 1.406e-19 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.800e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.294e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 3.976e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 6 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 6.000e-04 + Ca+2 6.000e-04 4.984e-04 -3.222 -3.302 -0.081 + CaOH+ 8.617e-10 8.220e-10 -9.065 -9.085 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 7.667e-08 + K+ 7.667e-08 7.312e-08 -7.115 -7.136 -0.021 + KOH 2.519e-15 2.520e-15 -14.599 -14.599 0.000 +Na 1.406e-19 + Na+ 1.406e-19 1.341e-19 -18.852 -18.872 -0.020 + NaOH 8.804e-27 8.807e-27 -26.055 -26.055 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -23.40 -21.81 1.58 NaCl + O2(g) -0.68 -3.64 -2.96 O2 + +Beginning of advection time step 81, cumulative pore volumes 2.025000. +Beginning of advection time step 82, cumulative pore volumes 2.050000. +Beginning of advection time step 83, cumulative pore volumes 2.075000. +Beginning of advection time step 84, cumulative pore volumes 2.100000. +Beginning of advection time step 85, cumulative pore volumes 2.125000. +Beginning of advection time step 86, cumulative pore volumes 2.150000. +Beginning of advection time step 87, cumulative pore volumes 2.175000. +Beginning of advection time step 88, cumulative pore volumes 2.200000. +Beginning of advection time step 89, cumulative pore volumes 2.225000. +Beginning of advection time step 90, cumulative pore volumes 2.250000. +Beginning of advection time step 91, cumulative pore volumes 2.275000. +Beginning of advection time step 92, cumulative pore volumes 2.300000. +Beginning of advection time step 93, cumulative pore volumes 2.325000. +Beginning of advection time step 94, cumulative pore volumes 2.350000. +Beginning of advection time step 95, cumulative pore volumes 2.375000. +Beginning of advection time step 96, cumulative pore volumes 2.400000. +Beginning of advection time step 97, cumulative pore volumes 2.425000. +Beginning of advection time step 98, cumulative pore volumes 2.450000. +Beginning of advection time step 99, cumulative pore volumes 2.475000. +Beginning of advection time step 100, cumulative pore volumes 2.500000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 6.000e-04 6.000e-04 + Cl 1.200e-03 1.200e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.800e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -5.732e-20 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 3.546e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 6.000e-04 + Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 + CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.68 -3.64 -2.96 O2 + +Beginning of advection time step 101, cumulative pore volumes 2.525000. +Beginning of advection time step 102, cumulative pore volumes 2.550000. +Beginning of advection time step 103, cumulative pore volumes 2.575000. +Beginning of advection time step 104, cumulative pore volumes 2.600000. +Beginning of advection time step 105, cumulative pore volumes 2.625000. +Beginning of advection time step 106, cumulative pore volumes 2.650000. +Beginning of advection time step 107, cumulative pore volumes 2.675000. +Beginning of advection time step 108, cumulative pore volumes 2.700000. +Beginning of advection time step 109, cumulative pore volumes 2.725000. +Beginning of advection time step 110, cumulative pore volumes 2.750000. +Beginning of advection time step 111, cumulative pore volumes 2.775000. +Beginning of advection time step 112, cumulative pore volumes 2.800000. +Beginning of advection time step 113, cumulative pore volumes 2.825000. +Beginning of advection time step 114, cumulative pore volumes 2.850000. +Beginning of advection time step 115, cumulative pore volumes 2.875000. +Beginning of advection time step 116, cumulative pore volumes 2.900000. +Beginning of advection time step 117, cumulative pore volumes 2.925000. +Beginning of advection time step 118, cumulative pore volumes 2.950000. +Beginning of advection time step 119, cumulative pore volumes 2.975000. +Beginning of advection time step 120, cumulative pore volumes 3.000000. + +Cell 40. + +Using solution 40. Solution after simulation 1. +Using exchange 40. Exchange assemblage after simulation 1. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 6.000e-04 6.000e-04 + Cl 1.200e-03 1.200e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.800e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -5.732e-20 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 3.546e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 6.000e-04 + Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 + CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.68 -3.64 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1-40 Initial solution for column + units mmol/kgw + temp 25.0 + pH 7.0 charge + pe 12.5 O2(g) -0.68 + Na 1.0 + K 0.2 + N(5) 1.2 + EXCHANGE 1-40 + equilibrate 1 + X 0.0011 + TRANSPORT + cells 40 + length 0.002 + shifts 120 + time_step 720.0 + flow_direction forward + boundary_conditions flux flux + diffc 0.0e-9 + dispersivity 0.002 + correct_disp true + punch 40 + punch_frequency 1 + print 40 + print_frequency 20 + SELECTED_OUTPUT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 40. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 40. + file ex11trn.sel + reset false + step + totals Na Cl K Ca + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Initial solution for column + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 2.000e-04 2.000e-04 + N(5) 1.200e-03 1.200e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.114e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -8.455e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(5) 1.200e-03 + NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.68 -3.64 -2.96 O2 + +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Initial solution for column +Using exchange 1. Exchange assemblage after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 2.000e-04 2.000e-04 + N 1.200e-03 1.200e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.114e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.532e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 + NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 +N(0) 2.552e-19 + N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 +N(3) 2.686e-16 + NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 +N(5) 1.200e-03 + NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.63 -18.89 -3.26 N2 + NH3(g) -66.75 -64.98 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +------------------------------------ +Beginning of transport calculations. +------------------------------------ + +------------------------------- +Equilibrating initial solutions +------------------------------- + +Using solution 40. Initial solution for column +Using exchange 40. Exchanger defined in simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 2.000e-04 2.000e-04 + N 1.200e-03 1.200e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.114e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.532e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 + NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 +N(0) 2.552e-19 + N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 +N(3) 2.686e-16 + NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 +N(5) 1.200e-03 + NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.63 -18.89 -3.26 N2 + NH3(g) -66.75 -64.98 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 1. + +Transport step 1. Mixrun 1. + +Transport step 1. Mixrun 2. + +Transport step 1. Mixrun 3. + +Transport step 1. Mixrun 4. + +Transport step 2. + +Transport step 2. Mixrun 1. + +Transport step 2. Mixrun 2. + +Transport step 2. Mixrun 3. + +Transport step 2. Mixrun 4. + +Transport step 3. + +Transport step 3. Mixrun 1. + +Transport step 3. Mixrun 2. + +Transport step 3. Mixrun 3. + +Transport step 3. Mixrun 4. + +Transport step 4. + +Transport step 4. Mixrun 1. + +Transport step 4. Mixrun 2. + +Transport step 4. Mixrun 3. + +Transport step 4. Mixrun 4. + +Transport step 5. + +Transport step 5. Mixrun 1. + +Transport step 5. Mixrun 2. + +Transport step 5. Mixrun 3. + +Transport step 5. Mixrun 4. + +Transport step 6. + +Transport step 6. Mixrun 1. + +Transport step 6. Mixrun 2. + +Transport step 6. Mixrun 3. + +Transport step 6. Mixrun 4. + +Transport step 7. + +Transport step 7. Mixrun 1. + +Transport step 7. Mixrun 2. + +Transport step 7. Mixrun 3. + +Transport step 7. Mixrun 4. + +Transport step 8. + +Transport step 8. Mixrun 1. + +Transport step 8. Mixrun 2. + +Transport step 8. Mixrun 3. + +Transport step 8. Mixrun 4. + +Transport step 9. + +Transport step 9. Mixrun 1. + +Transport step 9. Mixrun 2. + +Transport step 9. Mixrun 3. + +Transport step 9. Mixrun 4. + +Transport step 10. + +Transport step 10. Mixrun 1. + +Transport step 10. Mixrun 2. + +Transport step 10. Mixrun 3. + +Transport step 10. Mixrun 4. + +Transport step 11. + +Transport step 11. Mixrun 1. + +Transport step 11. Mixrun 2. + +Transport step 11. Mixrun 3. + +Transport step 11. Mixrun 4. + +Transport step 12. + +Transport step 12. Mixrun 1. + +Transport step 12. Mixrun 2. + +Transport step 12. Mixrun 3. + +Transport step 12. Mixrun 4. + +Transport step 13. + +Transport step 13. Mixrun 1. + +Transport step 13. Mixrun 2. + +Transport step 13. Mixrun 3. + +Transport step 13. Mixrun 4. + +Transport step 14. + +Transport step 14. Mixrun 1. + +Transport step 14. Mixrun 2. + +Transport step 14. Mixrun 3. + +Transport step 14. Mixrun 4. + +Transport step 15. + +Transport step 15. Mixrun 1. + +Transport step 15. Mixrun 2. + +Transport step 15. Mixrun 3. + +Transport step 15. Mixrun 4. + +Transport step 16. + +Transport step 16. Mixrun 1. + +Transport step 16. Mixrun 2. + +Transport step 16. Mixrun 3. + +Transport step 16. Mixrun 4. + +Transport step 17. + +Transport step 17. Mixrun 1. + +Transport step 17. Mixrun 2. + +Transport step 17. Mixrun 3. + +Transport step 17. Mixrun 4. + +Transport step 18. + +Transport step 18. Mixrun 1. + +Transport step 18. Mixrun 2. + +Transport step 18. Mixrun 3. + +Transport step 18. Mixrun 4. + +Transport step 19. + +Transport step 19. Mixrun 1. + +Transport step 19. Mixrun 2. + +Transport step 19. Mixrun 3. + +Transport step 19. Mixrun 4. + +Transport step 20. + +Transport step 20. Mixrun 1. + +Transport step 20. Mixrun 2. + +Transport step 20. Mixrun 3. + +Transport step 20. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.507e-04 5.507e-04 5.006e-01 -0.017 + NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 + NH4X 4.141e-63 4.141e-63 3.765e-60 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.848e-06 1.848e-06 + K 2.000e-04 2.000e-04 + N 1.198e-03 1.198e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.424e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 1.564e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.551027e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Cl 1.848e-06 + Cl- 1.848e-06 1.777e-06 -5.733 -5.750 -0.017 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.000e-04 + K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 + KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.723 -62.740 -0.017 + NH3 0.000e+00 0.000e+00 -64.985 -64.985 0.000 +N(0) 2.544e-19 + N2 1.272e-19 1.272e-19 -18.895 -18.895 0.000 +N(3) 2.682e-16 + NO2- 2.682e-16 2.579e-16 -15.571 -15.589 -0.017 +N(5) 1.198e-03 + NO3- 1.198e-03 1.152e-03 -2.921 -2.939 -0.017 +Na 1.000e-03 + Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 + NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -10.35 -8.77 1.58 NaCl + N2(g) -15.64 -18.90 -3.26 N2 + NH3(g) -66.75 -64.98 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 21. + +Transport step 21. Mixrun 1. + +Transport step 21. Mixrun 2. + +Transport step 21. Mixrun 3. + +Transport step 21. Mixrun 4. + +Transport step 22. + +Transport step 22. Mixrun 1. + +Transport step 22. Mixrun 2. + +Transport step 22. Mixrun 3. + +Transport step 22. Mixrun 4. + +Transport step 23. + +Transport step 23. Mixrun 1. + +Transport step 23. Mixrun 2. + +Transport step 23. Mixrun 3. + +Transport step 23. Mixrun 4. + +Transport step 24. + +Transport step 24. Mixrun 1. + +Transport step 24. Mixrun 2. + +Transport step 24. Mixrun 3. + +Transport step 24. Mixrun 4. + +Transport step 25. + +Transport step 25. Mixrun 1. + +Transport step 25. Mixrun 2. + +Transport step 25. Mixrun 3. + +Transport step 25. Mixrun 4. + +Transport step 26. + +Transport step 26. Mixrun 1. + +Transport step 26. Mixrun 2. + +Transport step 26. Mixrun 3. + +Transport step 26. Mixrun 4. + +Transport step 27. + +Transport step 27. Mixrun 1. + +Transport step 27. Mixrun 2. + +Transport step 27. Mixrun 3. + +Transport step 27. Mixrun 4. + +Transport step 28. + +Transport step 28. Mixrun 1. + +Transport step 28. Mixrun 2. + +Transport step 28. Mixrun 3. + +Transport step 28. Mixrun 4. + +Transport step 29. + +Transport step 29. Mixrun 1. + +Transport step 29. Mixrun 2. + +Transport step 29. Mixrun 3. + +Transport step 29. Mixrun 4. + +Transport step 30. + +Transport step 30. Mixrun 1. + +Transport step 30. Mixrun 2. + +Transport step 30. Mixrun 3. + +Transport step 30. Mixrun 4. + +Transport step 31. + +Transport step 31. Mixrun 1. + +Transport step 31. Mixrun 2. + +Transport step 31. Mixrun 3. + +Transport step 31. Mixrun 4. + +Transport step 32. + +Transport step 32. Mixrun 1. + +Transport step 32. Mixrun 2. + +Transport step 32. Mixrun 3. + +Transport step 32. Mixrun 4. + +Transport step 33. + +Transport step 33. Mixrun 1. + +Transport step 33. Mixrun 2. + +Transport step 33. Mixrun 3. + +Transport step 33. Mixrun 4. + +Transport step 34. + +Transport step 34. Mixrun 1. + +Transport step 34. Mixrun 2. + +Transport step 34. Mixrun 3. + +Transport step 34. Mixrun 4. + +Transport step 35. + +Transport step 35. Mixrun 1. + +Transport step 35. Mixrun 2. + +Transport step 35. Mixrun 3. + +Transport step 35. Mixrun 4. + +Transport step 36. + +Transport step 36. Mixrun 1. + +Transport step 36. Mixrun 2. + +Transport step 36. Mixrun 3. + +Transport step 36. Mixrun 4. + +Transport step 37. + +Transport step 37. Mixrun 1. + +Transport step 37. Mixrun 2. + +Transport step 37. Mixrun 3. + +Transport step 37. Mixrun 4. + +Transport step 38. + +Transport step 38. Mixrun 1. + +Transport step 38. Mixrun 2. + +Transport step 38. Mixrun 3. + +Transport step 38. Mixrun 4. + +Transport step 39. + +Transport step 39. Mixrun 1. + +Transport step 39. Mixrun 2. + +Transport step 39. Mixrun 3. + +Transport step 39. Mixrun 4. + +Transport step 40. + +Transport step 40. Mixrun 1. + +Transport step 40. Mixrun 2. + +Transport step 40. Mixrun 3. + +Transport step 40. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 5.512e-04 5.512e-04 5.011e-01 -0.017 + NaX 5.488e-04 5.488e-04 4.989e-01 -0.017 + NH4X 1.796e-63 1.796e-63 1.633e-60 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 6.801e-04 6.801e-04 + K 2.004e-04 2.004e-04 + N 5.199e-04 5.199e-04 + Na 9.996e-04 9.996e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.848e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.884e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550823e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Cl 6.801e-04 + Cl- 6.801e-04 6.540e-04 -3.167 -3.184 -0.017 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 2.004e-04 + K+ 2.004e-04 1.927e-04 -3.698 -3.715 -0.017 + KOH 6.666e-12 6.668e-12 -11.176 -11.176 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -63.085 -63.102 -0.017 + NH3 0.000e+00 0.000e+00 -65.348 -65.347 0.000 +N(0) 4.792e-20 + N2 2.396e-20 2.397e-20 -19.621 -19.620 0.000 +N(3) 1.164e-16 + NO2- 1.164e-16 1.119e-16 -15.934 -15.951 -0.017 +N(5) 5.199e-04 + NO3- 5.199e-04 4.999e-04 -3.284 -3.301 -0.017 +Na 9.996e-04 + Na+ 9.996e-04 9.617e-04 -3.000 -3.017 -0.017 + NaOH 6.340e-11 6.341e-11 -10.198 -10.198 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.78 -6.20 1.58 NaCl + N2(g) -16.36 -19.62 -3.26 N2 + NH3(g) -67.12 -65.35 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 41. + +Transport step 41. Mixrun 1. + +Transport step 41. Mixrun 2. + +Transport step 41. Mixrun 3. + +Transport step 41. Mixrun 4. + +Transport step 42. + +Transport step 42. Mixrun 1. + +Transport step 42. Mixrun 2. + +Transport step 42. Mixrun 3. + +Transport step 42. Mixrun 4. + +Transport step 43. + +Transport step 43. Mixrun 1. + +Transport step 43. Mixrun 2. + +Transport step 43. Mixrun 3. + +Transport step 43. Mixrun 4. + +Transport step 44. + +Transport step 44. Mixrun 1. + +Transport step 44. Mixrun 2. + +Transport step 44. Mixrun 3. + +Transport step 44. Mixrun 4. + +Transport step 45. + +Transport step 45. Mixrun 1. + +Transport step 45. Mixrun 2. + +Transport step 45. Mixrun 3. + +Transport step 45. Mixrun 4. + +Transport step 46. + +Transport step 46. Mixrun 1. + +Transport step 46. Mixrun 2. + +Transport step 46. Mixrun 3. + +Transport step 46. Mixrun 4. + +Transport step 47. + +Transport step 47. Mixrun 1. + +Transport step 47. Mixrun 2. + +Transport step 47. Mixrun 3. + +Transport step 47. Mixrun 4. + +Transport step 48. + +Transport step 48. Mixrun 1. + +Transport step 48. Mixrun 2. + +Transport step 48. Mixrun 3. + +Transport step 48. Mixrun 4. + +Transport step 49. + +Transport step 49. Mixrun 1. + +Transport step 49. Mixrun 2. + +Transport step 49. Mixrun 3. + +Transport step 49. Mixrun 4. + +Transport step 50. + +Transport step 50. Mixrun 1. + +Transport step 50. Mixrun 2. + +Transport step 50. Mixrun 3. + +Transport step 50. Mixrun 4. + +Transport step 51. + +Transport step 51. Mixrun 1. + +Transport step 51. Mixrun 2. + +Transport step 51. Mixrun 3. + +Transport step 51. Mixrun 4. + +Transport step 52. + +Transport step 52. Mixrun 1. + +Transport step 52. Mixrun 2. + +Transport step 52. Mixrun 3. + +Transport step 52. Mixrun 4. + +Transport step 53. + +Transport step 53. Mixrun 1. + +Transport step 53. Mixrun 2. + +Transport step 53. Mixrun 3. + +Transport step 53. Mixrun 4. + +Transport step 54. + +Transport step 54. Mixrun 1. + +Transport step 54. Mixrun 2. + +Transport step 54. Mixrun 3. + +Transport step 54. Mixrun 4. + +Transport step 55. + +Transport step 55. Mixrun 1. + +Transport step 55. Mixrun 2. + +Transport step 55. Mixrun 3. + +Transport step 55. Mixrun 4. + +Transport step 56. + +Transport step 56. Mixrun 1. + +Transport step 56. Mixrun 2. + +Transport step 56. Mixrun 3. + +Transport step 56. Mixrun 4. + +Transport step 57. + +Transport step 57. Mixrun 1. + +Transport step 57. Mixrun 2. + +Transport step 57. Mixrun 3. + +Transport step 57. Mixrun 4. + +Transport step 58. + +Transport step 58. Mixrun 1. + +Transport step 58. Mixrun 2. + +Transport step 58. Mixrun 3. + +Transport step 58. Mixrun 4. + +Transport step 59. + +Transport step 59. Mixrun 1. + +Transport step 59. Mixrun 2. + +Transport step 59. Mixrun 3. + +Transport step 59. Mixrun 4. + +Transport step 60. + +Transport step 60. Mixrun 1. + +Transport step 60. Mixrun 2. + +Transport step 60. Mixrun 3. + +Transport step 60. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 9.451e-04 9.451e-04 8.592e-01 -0.017 + NaX 1.549e-04 1.549e-04 1.408e-01 -0.017 + CaX2 2.150e-20 4.300e-20 3.909e-17 -0.067 + NH4X 5.255e-65 5.255e-65 4.777e-62 -0.017 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 9.153e-23 9.153e-23 + Cl 1.171e-03 1.171e-03 + K 6.589e-04 6.589e-04 + N 2.918e-05 2.918e-05 + Na 5.411e-04 5.411e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.999 Charge balance + pe = 13.611 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.200e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.591e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 3.043e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550676e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 + OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 9.153e-23 + Ca+2 9.153e-23 7.852e-23 -22.038 -22.105 -0.067 + CaOH+ 1.352e-28 1.301e-28 -27.869 -27.886 -0.017 +Cl 1.171e-03 + Cl- 1.171e-03 1.126e-03 -2.932 -2.948 -0.017 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 6.589e-04 + K+ 6.589e-04 6.337e-04 -3.181 -3.198 -0.017 + KOH 2.192e-11 2.193e-11 -10.659 -10.659 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -64.336 -64.353 -0.017 + NH3 0.000e+00 0.000e+00 -66.598 -66.598 0.000 +N(0) 1.509e-22 + N2 7.545e-23 7.547e-23 -22.122 -22.122 0.000 +N(3) 6.532e-18 + NO2- 6.532e-18 6.281e-18 -17.185 -17.202 -0.017 +N(5) 2.918e-05 + NO3- 2.918e-05 2.805e-05 -4.535 -4.552 -0.017 +Na 5.411e-04 + Na+ 5.411e-04 5.206e-04 -3.267 -3.284 -0.017 + NaOH 3.432e-11 3.433e-11 -10.464 -10.464 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.81 -6.23 1.58 NaCl + N2(g) -18.86 -22.12 -3.26 N2 + NH3(g) -68.37 -66.60 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 61. + +Transport step 61. Mixrun 1. + +Transport step 61. Mixrun 2. + +Transport step 61. Mixrun 3. + +Transport step 61. Mixrun 4. + +Transport step 62. + +Transport step 62. Mixrun 1. + +Transport step 62. Mixrun 2. + +Transport step 62. Mixrun 3. + +Transport step 62. Mixrun 4. + +Transport step 63. + +Transport step 63. Mixrun 1. + +Transport step 63. Mixrun 2. + +Transport step 63. Mixrun 3. + +Transport step 63. Mixrun 4. + +Transport step 64. + +Transport step 64. Mixrun 1. + +Transport step 64. Mixrun 2. + +Transport step 64. Mixrun 3. + +Transport step 64. Mixrun 4. + +Transport step 65. + +Transport step 65. Mixrun 1. + +Transport step 65. Mixrun 2. + +Transport step 65. Mixrun 3. + +Transport step 65. Mixrun 4. + +Transport step 66. + +Transport step 66. Mixrun 1. + +Transport step 66. Mixrun 2. + +Transport step 66. Mixrun 3. + +Transport step 66. Mixrun 4. + +Transport step 67. + +Transport step 67. Mixrun 1. + +Transport step 67. Mixrun 2. + +Transport step 67. Mixrun 3. + +Transport step 67. Mixrun 4. + +Transport step 68. + +Transport step 68. Mixrun 1. + +Transport step 68. Mixrun 2. + +Transport step 68. Mixrun 3. + +Transport step 68. Mixrun 4. + +Transport step 69. + +Transport step 69. Mixrun 1. + +Transport step 69. Mixrun 2. + +Transport step 69. Mixrun 3. + +Transport step 69. Mixrun 4. + +Transport step 70. + +Transport step 70. Mixrun 1. + +Transport step 70. Mixrun 2. + +Transport step 70. Mixrun 3. + +Transport step 70. Mixrun 4. + +Transport step 71. + +Transport step 71. Mixrun 1. + +Transport step 71. Mixrun 2. + +Transport step 71. Mixrun 3. + +Transport step 71. Mixrun 4. + +Transport step 72. + +Transport step 72. Mixrun 1. + +Transport step 72. Mixrun 2. + +Transport step 72. Mixrun 3. + +Transport step 72. Mixrun 4. + +Transport step 73. + +Transport step 73. Mixrun 1. + +Transport step 73. Mixrun 2. + +Transport step 73. Mixrun 3. + +Transport step 73. Mixrun 4. + +Transport step 74. + +Transport step 74. Mixrun 1. + +Transport step 74. Mixrun 2. + +Transport step 74. Mixrun 3. + +Transport step 74. Mixrun 4. + +Transport step 75. + +Transport step 75. Mixrun 1. + +Transport step 75. Mixrun 2. + +Transport step 75. Mixrun 3. + +Transport step 75. Mixrun 4. + +Transport step 76. + +Transport step 76. Mixrun 1. + +Transport step 76. Mixrun 2. + +Transport step 76. Mixrun 3. + +Transport step 76. Mixrun 4. + +Transport step 77. + +Transport step 77. Mixrun 1. + +Transport step 77. Mixrun 2. + +Transport step 77. Mixrun 3. + +Transport step 77. Mixrun 4. + +Transport step 78. + +Transport step 78. Mixrun 1. + +Transport step 78. Mixrun 2. + +Transport step 78. Mixrun 3. + +Transport step 78. Mixrun 4. + +Transport step 79. + +Transport step 79. Mixrun 1. + +Transport step 79. Mixrun 2. + +Transport step 79. Mixrun 3. + +Transport step 79. Mixrun 4. + +Transport step 80. + +Transport step 80. Mixrun 1. + +Transport step 80. Mixrun 2. + +Transport step 80. Mixrun 3. + +Transport step 80. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.430e-04 1.086e-03 9.874e-01 -0.079 + KX 1.370e-05 1.370e-05 1.245e-02 -0.020 + NaX 2.152e-07 2.152e-07 1.956e-04 -0.020 + NH4X 7.135e-68 7.135e-68 6.486e-65 -0.020 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 5.226e-04 5.226e-04 + Cl 1.199e-03 1.199e-03 + K 1.436e-04 1.436e-04 + N 5.912e-07 5.912e-07 + Na 1.130e-05 1.130e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.998 Charge balance + pe = 13.612 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.723e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.957e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 9.758e-12 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550668e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.050e-07 1.006e-07 -6.979 -6.998 -0.019 + OH- 1.043e-07 9.954e-08 -6.982 -7.002 -0.020 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 5.226e-04 + Ca+2 5.226e-04 4.358e-04 -3.282 -3.361 -0.079 + CaOH+ 7.530e-10 7.191e-10 -9.123 -9.143 -0.020 +Cl 1.199e-03 + Cl- 1.199e-03 1.145e-03 -2.921 -2.941 -0.020 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 1.436e-04 + K+ 1.436e-04 1.370e-04 -3.843 -3.863 -0.020 + KOH 4.723e-12 4.725e-12 -11.326 -11.326 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -66.026 -66.047 -0.020 + NH3 0.000e+00 0.000e+00 -68.293 -68.293 0.000 +N(0) 6.148e-26 + N2 3.074e-26 3.075e-26 -25.512 -25.512 0.000 +N(3) 1.324e-19 + NO2- 1.324e-19 1.263e-19 -18.878 -18.899 -0.020 +N(5) 5.912e-07 + NO3- 5.912e-07 5.642e-07 -6.228 -6.249 -0.020 +Na 1.130e-05 + Na+ 1.130e-05 1.080e-05 -4.947 -4.967 -0.020 + NaOH 7.089e-13 7.092e-13 -12.149 -12.149 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -9.49 -7.91 1.58 NaCl + N2(g) -22.25 -25.51 -3.26 N2 + NH3(g) -70.06 -68.29 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 81. + +Transport step 81. Mixrun 1. + +Transport step 81. Mixrun 2. + +Transport step 81. Mixrun 3. + +Transport step 81. Mixrun 4. + +Transport step 82. + +Transport step 82. Mixrun 1. + +Transport step 82. Mixrun 2. + +Transport step 82. Mixrun 3. + +Transport step 82. Mixrun 4. + +Transport step 83. + +Transport step 83. Mixrun 1. + +Transport step 83. Mixrun 2. + +Transport step 83. Mixrun 3. + +Transport step 83. Mixrun 4. + +Transport step 84. + +Transport step 84. Mixrun 1. + +Transport step 84. Mixrun 2. + +Transport step 84. Mixrun 3. + +Transport step 84. Mixrun 4. + +Transport step 85. + +Transport step 85. Mixrun 1. + +Transport step 85. Mixrun 2. + +Transport step 85. Mixrun 3. + +Transport step 85. Mixrun 4. + +Transport step 86. + +Transport step 86. Mixrun 1. + +Transport step 86. Mixrun 2. + +Transport step 86. Mixrun 3. + +Transport step 86. Mixrun 4. + +Transport step 87. + +Transport step 87. Mixrun 1. + +Transport step 87. Mixrun 2. + +Transport step 87. Mixrun 3. + +Transport step 87. Mixrun 4. + +Transport step 88. + +Transport step 88. Mixrun 1. + +Transport step 88. Mixrun 2. + +Transport step 88. Mixrun 3. + +Transport step 88. Mixrun 4. + +Transport step 89. + +Transport step 89. Mixrun 1. + +Transport step 89. Mixrun 2. + +Transport step 89. Mixrun 3. + +Transport step 89. Mixrun 4. + +Transport step 90. + +Transport step 90. Mixrun 1. + +Transport step 90. Mixrun 2. + +Transport step 90. Mixrun 3. + +Transport step 90. Mixrun 4. + +Transport step 91. + +Transport step 91. Mixrun 1. + +Transport step 91. Mixrun 2. + +Transport step 91. Mixrun 3. + +Transport step 91. Mixrun 4. + +Transport step 92. + +Transport step 92. Mixrun 1. + +Transport step 92. Mixrun 2. + +Transport step 92. Mixrun 3. + +Transport step 92. Mixrun 4. + +Transport step 93. + +Transport step 93. Mixrun 1. + +Transport step 93. Mixrun 2. + +Transport step 93. Mixrun 3. + +Transport step 93. Mixrun 4. + +Transport step 94. + +Transport step 94. Mixrun 1. + +Transport step 94. Mixrun 2. + +Transport step 94. Mixrun 3. + +Transport step 94. Mixrun 4. + +Transport step 95. + +Transport step 95. Mixrun 1. + +Transport step 95. Mixrun 2. + +Transport step 95. Mixrun 3. + +Transport step 95. Mixrun 4. + +Transport step 96. + +Transport step 96. Mixrun 1. + +Transport step 96. Mixrun 2. + +Transport step 96. Mixrun 3. + +Transport step 96. Mixrun 4. + +Transport step 97. + +Transport step 97. Mixrun 1. + +Transport step 97. Mixrun 2. + +Transport step 97. Mixrun 3. + +Transport step 97. Mixrun 4. + +Transport step 98. + +Transport step 98. Mixrun 1. + +Transport step 98. Mixrun 2. + +Transport step 98. Mixrun 3. + +Transport step 98. Mixrun 4. + +Transport step 99. + +Transport step 99. Mixrun 1. + +Transport step 99. Mixrun 2. + +Transport step 99. Mixrun 3. + +Transport step 99. Mixrun 4. + +Transport step 100. + +Transport step 100. Mixrun 1. + +Transport step 100. Mixrun 2. + +Transport step 100. Mixrun 3. + +Transport step 100. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.499e-04 1.100e-03 9.999e-01 -0.080 + KX 1.363e-07 1.363e-07 1.239e-04 -0.021 + NaX 1.851e-09 1.851e-09 1.683e-06 -0.020 + NH4X 8.683e-70 8.683e-70 7.894e-67 -0.021 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 5.992e-04 5.992e-04 + Cl 1.200e-03 1.200e-03 + K 1.520e-06 1.520e-06 + N 7.648e-09 7.648e-09 + Na 1.035e-07 1.035e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.799e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 6.006e-20 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.774e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 5.992e-04 + Ca+2 5.992e-04 4.978e-04 -3.222 -3.303 -0.080 + CaOH+ 8.606e-10 8.210e-10 -9.065 -9.086 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 1.520e-06 + K+ 1.520e-06 1.450e-06 -5.818 -5.839 -0.021 + KOH 4.994e-14 4.996e-14 -13.302 -13.301 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -67.914 -67.935 -0.021 + NH3 0.000e+00 0.000e+00 -70.182 -70.182 0.000 +N(0) 1.028e-29 + N2 5.139e-30 5.141e-30 -29.289 -29.289 0.000 +N(3) 1.712e-21 + NO2- 1.712e-21 1.632e-21 -20.766 -20.787 -0.021 +N(5) 7.648e-09 + NO3- 7.648e-09 7.291e-09 -8.116 -8.137 -0.021 +Na 1.035e-07 + Na+ 1.035e-07 9.874e-08 -6.985 -7.006 -0.020 + NaOH 6.480e-15 6.483e-15 -14.188 -14.188 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -11.53 -9.95 1.58 NaCl + N2(g) -26.03 -29.29 -3.26 N2 + NH3(g) -71.95 -70.18 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +Transport step 101. + +Transport step 101. Mixrun 1. + +Transport step 101. Mixrun 2. + +Transport step 101. Mixrun 3. + +Transport step 101. Mixrun 4. + +Transport step 102. + +Transport step 102. Mixrun 1. + +Transport step 102. Mixrun 2. + +Transport step 102. Mixrun 3. + +Transport step 102. Mixrun 4. + +Transport step 103. + +Transport step 103. Mixrun 1. + +Transport step 103. Mixrun 2. + +Transport step 103. Mixrun 3. + +Transport step 103. Mixrun 4. + +Transport step 104. + +Transport step 104. Mixrun 1. + +Transport step 104. Mixrun 2. + +Transport step 104. Mixrun 3. + +Transport step 104. Mixrun 4. + +Transport step 105. + +Transport step 105. Mixrun 1. + +Transport step 105. Mixrun 2. + +Transport step 105. Mixrun 3. + +Transport step 105. Mixrun 4. + +Transport step 106. + +Transport step 106. Mixrun 1. + +Transport step 106. Mixrun 2. + +Transport step 106. Mixrun 3. + +Transport step 106. Mixrun 4. + +Transport step 107. + +Transport step 107. Mixrun 1. + +Transport step 107. Mixrun 2. + +Transport step 107. Mixrun 3. + +Transport step 107. Mixrun 4. + +Transport step 108. + +Transport step 108. Mixrun 1. + +Transport step 108. Mixrun 2. + +Transport step 108. Mixrun 3. + +Transport step 108. Mixrun 4. + +Transport step 109. + +Transport step 109. Mixrun 1. + +Transport step 109. Mixrun 2. + +Transport step 109. Mixrun 3. + +Transport step 109. Mixrun 4. + +Transport step 110. + +Transport step 110. Mixrun 1. + +Transport step 110. Mixrun 2. + +Transport step 110. Mixrun 3. + +Transport step 110. Mixrun 4. + +Transport step 111. + +Transport step 111. Mixrun 1. + +Transport step 111. Mixrun 2. + +Transport step 111. Mixrun 3. + +Transport step 111. Mixrun 4. + +Transport step 112. + +Transport step 112. Mixrun 1. + +Transport step 112. Mixrun 2. + +Transport step 112. Mixrun 3. + +Transport step 112. Mixrun 4. + +Transport step 113. + +Transport step 113. Mixrun 1. + +Transport step 113. Mixrun 2. + +Transport step 113. Mixrun 3. + +Transport step 113. Mixrun 4. + +Transport step 114. + +Transport step 114. Mixrun 1. + +Transport step 114. Mixrun 2. + +Transport step 114. Mixrun 3. + +Transport step 114. Mixrun 4. + +Transport step 115. + +Transport step 115. Mixrun 1. + +Transport step 115. Mixrun 2. + +Transport step 115. Mixrun 3. + +Transport step 115. Mixrun 4. + +Transport step 116. + +Transport step 116. Mixrun 1. + +Transport step 116. Mixrun 2. + +Transport step 116. Mixrun 3. + +Transport step 116. Mixrun 4. + +Transport step 117. + +Transport step 117. Mixrun 1. + +Transport step 117. Mixrun 2. + +Transport step 117. Mixrun 3. + +Transport step 117. Mixrun 4. + +Transport step 118. + +Transport step 118. Mixrun 1. + +Transport step 118. Mixrun 2. + +Transport step 118. Mixrun 3. + +Transport step 118. Mixrun 4. + +Transport step 119. + +Transport step 119. Mixrun 1. + +Transport step 119. Mixrun 2. + +Transport step 119. Mixrun 3. + +Transport step 119. Mixrun 4. + +Transport step 120. + +Transport step 120. Mixrun 1. + +Transport step 120. Mixrun 2. + +Transport step 120. Mixrun 3. + +Transport step 120. Mixrun 4. + +Using mix 40. +Using exchange 40. Exchange assemblage after simulation 2. + +Mixture 40. + + 2.625e-01 Solution 39 Solution after simulation 2. + 0.000e+00 Solution 41 Initial solution for column + 7.375e-01 Solution 40 Solution after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.100e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 + KX 1.753e-09 1.753e-09 1.593e-06 -0.021 + NaX 1.743e-11 1.743e-11 1.585e-08 -0.020 + NH4X 8.965e-72 8.965e-72 8.150e-69 -0.021 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 6.000e-04 6.000e-04 + Cl 1.200e-03 1.200e-03 + K 1.956e-08 1.956e-08 + N 7.901e-11 7.901e-11 + Na 9.751e-10 9.751e-10 + +----------------------------Description of solution---------------------------- + + pH = 6.997 Charge balance + pe = 13.613 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.800e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -5.732e-19 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 1.157e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550667e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 + OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Ca 6.000e-04 + Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 + CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 +Cl 1.200e-03 + Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 +K 1.956e-08 + K+ 1.956e-08 1.865e-08 -7.709 -7.729 -0.021 + KOH 6.425e-16 6.428e-16 -15.192 -15.192 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -69.900 -69.921 -0.021 + NH3 0.000e+00 0.000e+00 -72.168 -72.168 0.000 +N(0) 1.097e-33 + N2 5.484e-34 5.487e-34 -33.261 -33.261 0.000 +N(3) 1.769e-23 + NO2- 1.769e-23 1.686e-23 -22.752 -22.773 -0.021 +N(5) 7.901e-11 + NO3- 7.901e-11 7.532e-11 -10.102 -10.123 -0.021 +Na 9.751e-10 + Na+ 9.751e-10 9.305e-10 -9.011 -9.031 -0.020 + NaOH 6.107e-17 6.109e-17 -16.214 -16.214 0.000 +O(0) 4.580e-04 + O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.22 -44.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -13.55 -11.97 1.58 NaCl + N2(g) -30.00 -33.26 -3.26 N2 + NH3(g) -73.94 -72.17 1.77 NH3 + O2(g) -0.68 -3.64 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex11adv.sel b/Sun/examples/ex11adv.sel new file mode 100644 index 00000000..1958435f --- /dev/null +++ b/Sun/examples/ex11adv.sel @@ -0,0 +1,125 @@ + step Na Cl K Ca Pore_vol + -99 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 1.2500e-02 + -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 + -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 + 1 5.2815e-04 1.2000e-03 4.5842e-04 1.0672e-04 3.7500e-02 + 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 + 2 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.2500e-02 + 3 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.7500e-02 + 4 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.1250e-01 + 5 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.3750e-01 + 6 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.6250e-01 + 7 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.8750e-01 + 8 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.1250e-01 + 9 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.3750e-01 + 10 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.6250e-01 + 11 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.8750e-01 + 12 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.1250e-01 + 13 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.3750e-01 + 14 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.6250e-01 + 15 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.8750e-01 + 16 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.1250e-01 + 17 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.3750e-01 + 18 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.6250e-01 + 19 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.8750e-01 + 20 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.1250e-01 + 21 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.3750e-01 + 22 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.6250e-01 + 23 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.8750e-01 + 24 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.1250e-01 + 25 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.3750e-01 + 26 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.6250e-01 + 27 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.8750e-01 + 28 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.1250e-01 + 29 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.3750e-01 + 30 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.6250e-01 + 31 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.8750e-01 + 32 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.1250e-01 + 33 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.3750e-01 + 34 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.6250e-01 + 35 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.8750e-01 + 36 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.1250e-01 + 37 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.3750e-01 + 38 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.6250e-01 + 39 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.8750e-01 + 40 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0125e+00 + 41 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0375e+00 + 42 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0625e+00 + 43 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0875e+00 + 44 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1125e+00 + 45 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1375e+00 + 46 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1625e+00 + 47 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1875e+00 + 48 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2125e+00 + 49 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2375e+00 + 50 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2625e+00 + 51 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2875e+00 + 52 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.3125e+00 + 53 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.3375e+00 + 54 9.9998e-04 1.2000e-03 2.0002e-04 0.0000e+00 1.3625e+00 + 55 9.9993e-04 1.2000e-03 2.0007e-04 0.0000e+00 1.3875e+00 + 56 9.9969e-04 1.2000e-03 2.0031e-04 0.0000e+00 1.4125e+00 + 57 9.9860e-04 1.2000e-03 2.0140e-04 0.0000e+00 1.4375e+00 + 58 9.9376e-04 1.2000e-03 2.0624e-04 0.0000e+00 1.4625e+00 + 59 9.7266e-04 1.2000e-03 2.2734e-04 0.0000e+00 1.4875e+00 + 60 8.8947e-04 1.2000e-03 3.1053e-04 0.0000e+00 1.5125e+00 + 61 6.5396e-04 1.2000e-03 5.4604e-04 0.0000e+00 1.5375e+00 + 62 3.1876e-04 1.2000e-03 8.8124e-04 0.0000e+00 1.5625e+00 + 63 1.0663e-04 1.2000e-03 1.0934e-03 0.0000e+00 1.5875e+00 + 64 2.9829e-05 1.2000e-03 1.1702e-03 0.0000e+00 1.6125e+00 + 65 7.8763e-06 1.2000e-03 1.1921e-03 1.2216e-27 1.6375e+00 + 66 2.0460e-06 1.2000e-03 1.1980e-03 1.8112e-25 1.6625e+00 + 67 5.2878e-07 1.2000e-03 1.1995e-03 2.6557e-23 1.6875e+00 + 68 1.3629e-07 1.2000e-03 1.1999e-03 3.9376e-21 1.7125e+00 + 69 3.5021e-08 1.2000e-03 1.2000e-03 5.8912e-19 1.7375e+00 + 70 8.9558e-09 1.2000e-03 1.2000e-03 8.8181e-17 1.7625e+00 + 71 2.2719e-09 1.2000e-03 1.2000e-03 1.3080e-14 1.7875e+00 + 72 5.6835e-10 1.2000e-03 1.2000e-03 1.9126e-12 1.8125e+00 + 73 1.3869e-10 1.2000e-03 1.2000e-03 2.7576e-10 1.8375e+00 + 74 3.2281e-11 1.2000e-03 1.1999e-03 3.9374e-08 1.8625e+00 + 75 6.7673e-12 1.2000e-03 1.1890e-03 5.4946e-06 1.8875e+00 + 76 8.0510e-13 1.2000e-03 7.0494e-04 2.4753e-04 1.9125e+00 + 77 2.1968e-14 1.2000e-03 9.6079e-05 5.5196e-04 1.9375e+00 + 78 4.1771e-16 1.2000e-03 9.1269e-06 5.9544e-04 1.9625e+00 + 79 7.6748e-18 1.2000e-03 8.3782e-07 5.9958e-04 1.9875e+00 + 80 1.4057e-19 1.2000e-03 7.6671e-08 5.9996e-04 2.0125e+00 + 81 2.5740e-21 1.2000e-03 7.0147e-09 6.0000e-04 2.0375e+00 + 82 4.7052e-23 1.2000e-03 6.4179e-10 6.0000e-04 2.0625e+00 + 83 8.2642e-25 1.2000e-03 5.8721e-11 6.0000e-04 2.0875e+00 + 84 0.0000e+00 1.2000e-03 5.3731e-12 6.0000e-04 2.1125e+00 + 85 0.0000e+00 1.2000e-03 4.9168e-13 6.0000e-04 2.1375e+00 + 86 0.0000e+00 1.2000e-03 4.4995e-14 6.0000e-04 2.1625e+00 + 87 0.0000e+00 1.2000e-03 4.1178e-15 6.0000e-04 2.1875e+00 + 88 0.0000e+00 1.2000e-03 3.7688e-16 6.0000e-04 2.2125e+00 + 89 0.0000e+00 1.2000e-03 3.4497e-17 6.0000e-04 2.2375e+00 + 90 0.0000e+00 1.2000e-03 3.1577e-18 6.0000e-04 2.2625e+00 + 91 0.0000e+00 1.2000e-03 2.8907e-19 6.0000e-04 2.2875e+00 + 92 0.0000e+00 1.2000e-03 2.6465e-20 6.0000e-04 2.3125e+00 + 93 0.0000e+00 1.2000e-03 2.4231e-21 6.0000e-04 2.3375e+00 + 94 0.0000e+00 1.2000e-03 2.2183e-22 6.0000e-04 2.3625e+00 + 95 0.0000e+00 1.2000e-03 2.0287e-23 6.0000e-04 2.3875e+00 + 96 0.0000e+00 1.2000e-03 1.8364e-24 6.0000e-04 2.4125e+00 + 97 0.0000e+00 1.2000e-03 1.5102e-25 6.0000e-04 2.4375e+00 + 98 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.4625e+00 + 99 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.4875e+00 + 100 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5125e+00 + 101 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5375e+00 + 102 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5625e+00 + 103 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5875e+00 + 104 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6125e+00 + 105 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6375e+00 + 106 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6625e+00 + 107 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6875e+00 + 108 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7125e+00 + 109 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7375e+00 + 110 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7625e+00 + 111 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7875e+00 + 112 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8125e+00 + 113 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8375e+00 + 114 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8625e+00 + 115 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8875e+00 + 116 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9125e+00 + 117 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9375e+00 + 118 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9625e+00 + 119 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9875e+00 + 120 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 3.0125e+00 diff --git a/Sun/examples/ex11trn.sel b/Sun/examples/ex11trn.sel new file mode 100644 index 00000000..ca370b4c --- /dev/null +++ b/Sun/examples/ex11trn.sel @@ -0,0 +1,125 @@ + step Na Cl K Ca Pore_vol + -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 + -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 + 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 + 0 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 + 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 + 2 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.2500e-02 + 3 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.7500e-02 + 4 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.1250e-01 + 5 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.3750e-01 + 6 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.6250e-01 + 7 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.8750e-01 + 8 1.0000e-03 3.0997e-22 2.0000e-04 0.0000e+00 2.1250e-01 + 9 1.0000e-03 1.5009e-17 2.0000e-04 0.0000e+00 2.3750e-01 + 10 1.0000e-03 6.3378e-15 2.0000e-04 0.0000e+00 2.6250e-01 + 11 1.0000e-03 4.4948e-13 2.0000e-04 0.0000e+00 2.8750e-01 + 12 1.0000e-03 1.1487e-11 2.0000e-04 0.0000e+00 3.1250e-01 + 13 1.0000e-03 1.5022e-10 2.0000e-04 0.0000e+00 3.3750e-01 + 14 1.0000e-03 1.2225e-09 2.0000e-04 0.0000e+00 3.6250e-01 + 15 1.0000e-03 6.9925e-09 2.0000e-04 0.0000e+00 3.8750e-01 + 16 1.0000e-03 3.0480e-08 2.0000e-04 0.0000e+00 4.1250e-01 + 17 1.0000e-03 1.0717e-07 2.0000e-04 0.0000e+00 4.3750e-01 + 18 1.0000e-03 3.1679e-07 2.0000e-04 0.0000e+00 4.6250e-01 + 19 1.0000e-03 8.1192e-07 2.0000e-04 0.0000e+00 4.8750e-01 + 20 1.0000e-03 1.8478e-06 2.0000e-04 0.0000e+00 5.1250e-01 + 21 1.0000e-03 3.8042e-06 2.0000e-04 0.0000e+00 5.3750e-01 + 22 1.0000e-03 7.1918e-06 2.0000e-04 0.0000e+00 5.6250e-01 + 23 1.0000e-03 1.2635e-05 2.0000e-04 0.0000e+00 5.8750e-01 + 24 1.0000e-03 2.0834e-05 2.0000e-04 0.0000e+00 6.1250e-01 + 25 1.0000e-03 3.2507e-05 2.0000e-04 0.0000e+00 6.3750e-01 + 26 1.0000e-03 4.8325e-05 2.0000e-04 0.0000e+00 6.6250e-01 + 27 1.0000e-03 6.8844e-05 2.0000e-04 0.0000e+00 6.8750e-01 + 28 1.0000e-03 9.4449e-05 2.0000e-04 0.0000e+00 7.1250e-01 + 29 1.0000e-03 1.2532e-04 2.0000e-04 0.0000e+00 7.3750e-01 + 30 1.0000e-03 1.6140e-04 2.0000e-04 0.0000e+00 7.6250e-01 + 31 1.0000e-03 2.0242e-04 2.0000e-04 0.0000e+00 7.8750e-01 + 32 1.0000e-03 2.4790e-04 2.0000e-04 0.0000e+00 8.1250e-01 + 33 9.9999e-04 2.9719e-04 2.0001e-04 0.0000e+00 8.3750e-01 + 34 9.9999e-04 3.4951e-04 2.0001e-04 0.0000e+00 8.6250e-01 + 35 9.9998e-04 4.0403e-04 2.0002e-04 0.0000e+00 8.8750e-01 + 36 9.9996e-04 4.5987e-04 2.0004e-04 0.0000e+00 9.1250e-01 + 37 9.9993e-04 5.1616e-04 2.0007e-04 0.0000e+00 9.3750e-01 + 38 9.9988e-04 5.7209e-04 2.0012e-04 0.0000e+00 9.6250e-01 + 39 9.9979e-04 6.2694e-04 2.0021e-04 0.0000e+00 9.8750e-01 + 40 9.9964e-04 6.8006e-04 2.0036e-04 0.0000e+00 1.0125e+00 + 41 9.9940e-04 7.3093e-04 2.0060e-04 0.0000e+00 1.0375e+00 + 42 9.9902e-04 7.7913e-04 2.0098e-04 0.0000e+00 1.0625e+00 + 43 9.9842e-04 8.2437e-04 2.0158e-04 0.0000e+00 1.0875e+00 + 44 9.9749e-04 8.6644e-04 2.0251e-04 0.0000e+00 1.1125e+00 + 45 9.9606e-04 9.0523e-04 2.0394e-04 0.0000e+00 1.1375e+00 + 46 9.9390e-04 9.4071e-04 2.0610e-04 0.0000e+00 1.1625e+00 + 47 9.9067e-04 9.7294e-04 2.0933e-04 0.0000e+00 1.1875e+00 + 48 9.8590e-04 1.0020e-03 2.1410e-04 0.0000e+00 1.2125e+00 + 49 9.7896e-04 1.0281e-03 2.2104e-04 0.0000e+00 1.2375e+00 + 50 9.6900e-04 1.0513e-03 2.3100e-04 0.0000e+00 1.2625e+00 + 51 9.5496e-04 1.0718e-03 2.4504e-04 0.0000e+00 1.2875e+00 + 52 9.3563e-04 1.0899e-03 2.6437e-04 0.0000e+00 1.3125e+00 + 53 9.0974e-04 1.1058e-03 2.9026e-04 0.0000e+00 1.3375e+00 + 54 8.7620e-04 1.1196e-03 3.2380e-04 0.0000e+00 1.3625e+00 + 55 8.3445e-04 1.1316e-03 3.6555e-04 0.0000e+00 1.3875e+00 + 56 7.8479e-04 1.1420e-03 4.1521e-04 0.0000e+00 1.4125e+00 + 57 7.2845e-04 1.1510e-03 4.7155e-04 3.5277e-28 1.4375e+00 + 58 6.6747e-04 1.1587e-03 5.3253e-04 4.2108e-26 1.4625e+00 + 59 6.0423e-04 1.1652e-03 5.9577e-04 2.1113e-24 1.4875e+00 + 60 5.4107e-04 1.1708e-03 6.5893e-04 9.1531e-23 1.5125e+00 + 61 4.7992e-04 1.1756e-03 7.2008e-04 3.5143e-21 1.5375e+00 + 62 4.2217e-04 1.1796e-03 7.7783e-04 1.2072e-19 1.5625e+00 + 63 3.6873e-04 1.1830e-03 8.3127e-04 3.6941e-18 1.5875e+00 + 64 3.2004e-04 1.1859e-03 8.7996e-04 1.0357e-16 1.6125e+00 + 65 2.7623e-04 1.1883e-03 9.2377e-04 2.6573e-15 1.6375e+00 + 66 2.3720e-04 1.1903e-03 9.6280e-04 6.2721e-14 1.6625e+00 + 67 2.0268e-04 1.1920e-03 9.9732e-04 1.4041e-12 1.6875e+00 + 68 1.7232e-04 1.1934e-03 1.0277e-03 2.9709e-11 1.7125e+00 + 69 1.4570e-04 1.1945e-03 1.0543e-03 5.8657e-10 1.7375e+00 + 70 1.2238e-04 1.1955e-03 1.0776e-03 1.1507e-08 1.7625e+00 + 71 1.0193e-04 1.1963e-03 1.0977e-03 2.0826e-07 1.7875e+00 + 72 8.3815e-05 1.1970e-03 1.1095e-03 3.3299e-06 1.8125e+00 + 73 6.6682e-05 1.1975e-03 1.0249e-03 5.4190e-05 1.8375e+00 + 74 5.0532e-05 1.1980e-03 7.3505e-04 2.0721e-04 1.8625e+00 + 75 3.8797e-05 1.1983e-03 5.3569e-04 3.1276e-04 1.8875e+00 + 76 3.0077e-05 1.1986e-03 4.0212e-04 3.8390e-04 1.9125e+00 + 77 2.3445e-05 1.1989e-03 3.0685e-04 4.3485e-04 1.9375e+00 + 78 1.8340e-05 1.1991e-03 2.3662e-04 4.7252e-04 1.9625e+00 + 79 1.4384e-05 1.1993e-03 1.8380e-04 5.0091e-04 1.9875e+00 + 80 1.1303e-05 1.1994e-03 1.4355e-04 5.2257e-04 2.0125e+00 + 81 8.8949e-06 1.1995e-03 1.1260e-04 5.3925e-04 2.0375e+00 + 82 7.0081e-06 1.1996e-03 8.8613e-05 5.5219e-04 2.0625e+00 + 83 5.5269e-06 1.1997e-03 6.9934e-05 5.6227e-04 2.0875e+00 + 84 4.3622e-06 1.1997e-03 5.5321e-05 5.7016e-04 2.1125e+00 + 85 3.4452e-06 1.1998e-03 4.3847e-05 5.7635e-04 2.1375e+00 + 86 2.7225e-06 1.1998e-03 3.4813e-05 5.8123e-04 2.1625e+00 + 87 2.1523e-06 1.1999e-03 2.7680e-05 5.8508e-04 2.1875e+00 + 88 1.7023e-06 1.1999e-03 2.2038e-05 5.8813e-04 2.2125e+00 + 89 1.3467e-06 1.1999e-03 1.7565e-05 5.9054e-04 2.2375e+00 + 90 1.0658e-06 1.1999e-03 1.4014e-05 5.9246e-04 2.2625e+00 + 91 8.4359e-07 1.1999e-03 1.1192e-05 5.9398e-04 2.2875e+00 + 92 6.6787e-07 1.2000e-03 8.9443e-06 5.9519e-04 2.3125e+00 + 93 5.2883e-07 1.2000e-03 7.1535e-06 5.9616e-04 2.3375e+00 + 94 4.1880e-07 1.2000e-03 5.7250e-06 5.9693e-04 2.3625e+00 + 95 3.3169e-07 1.2000e-03 4.5844e-06 5.9754e-04 2.3875e+00 + 96 2.6273e-07 1.2000e-03 3.6730e-06 5.9803e-04 2.4125e+00 + 97 2.0811e-07 1.2000e-03 2.9442e-06 5.9842e-04 2.4375e+00 + 98 1.6486e-07 1.2000e-03 2.3611e-06 5.9874e-04 2.4625e+00 + 99 1.3060e-07 1.2000e-03 1.8942e-06 5.9899e-04 2.4875e+00 + 100 1.0347e-07 1.2000e-03 1.5202e-06 5.9919e-04 2.5125e+00 + 101 8.1970e-08 1.2000e-03 1.2205e-06 5.9935e-04 2.5375e+00 + 102 6.4939e-08 1.2000e-03 9.8015e-07 5.9948e-04 2.5625e+00 + 103 5.1446e-08 1.2000e-03 7.8736e-07 5.9958e-04 2.5875e+00 + 104 4.0756e-08 1.2000e-03 6.3266e-07 5.9966e-04 2.6125e+00 + 105 3.2287e-08 1.2000e-03 5.0848e-07 5.9973e-04 2.6375e+00 + 106 2.5577e-08 1.2000e-03 4.0877e-07 5.9978e-04 2.6625e+00 + 107 2.0260e-08 1.2000e-03 3.2868e-07 5.9983e-04 2.6875e+00 + 108 1.6048e-08 1.2000e-03 2.6433e-07 5.9986e-04 2.7125e+00 + 109 1.2712e-08 1.2000e-03 2.1262e-07 5.9989e-04 2.7375e+00 + 110 1.0068e-08 1.2000e-03 1.7105e-07 5.9991e-04 2.7625e+00 + 111 7.9740e-09 1.2000e-03 1.3763e-07 5.9993e-04 2.7875e+00 + 112 6.3151e-09 1.2000e-03 1.1076e-07 5.9994e-04 2.8125e+00 + 113 5.0010e-09 1.2000e-03 8.9141e-08 5.9995e-04 2.8375e+00 + 114 3.9601e-09 1.2000e-03 7.1753e-08 5.9996e-04 2.8625e+00 + 115 3.1357e-09 1.2000e-03 5.7764e-08 5.9997e-04 2.8875e+00 + 116 2.4828e-09 1.2000e-03 4.6507e-08 5.9998e-04 2.9125e+00 + 117 1.9657e-09 1.2000e-03 3.7447e-08 5.9998e-04 2.9375e+00 + 118 1.5562e-09 1.2000e-03 3.0156e-08 5.9998e-04 2.9625e+00 + 119 1.2319e-09 1.2000e-03 2.4286e-08 5.9999e-04 2.9875e+00 + 120 9.7513e-10 1.2000e-03 1.9560e-08 5.9999e-04 3.0125e+00 diff --git a/Sun/examples/ex12.log b/Sun/examples/ex12.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex12.out b/Sun/examples/ex12.out new file mode 100644 index 00000000..8ed928a7 --- /dev/null +++ b/Sun/examples/ex12.out @@ -0,0 +1,99 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex12 + Output file: ex12.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 12.--Advective and diffusive transport of heat and solutes. + Constant boundary condition at one end, closed at other. + The problem is designed so that temperature should equal Na-conc + (in mmol/kgw) after diffusion. + EXCHANGE_SPECIES + Na+ + X- = NaX + log_k 0.0 + gamma 4.0 0.075 + H+ + X- = HX + log_k -99. + gamma 9.0 0.0 + K+ + X- = KX + log_k 0.0 + gamma 3.5 0.015 + SOLUTION 0 24.0 mM KNO3 + units mol/kgw + temp 0 # Incoming solution 0C + pH 7.0 + pe 12.0 O2(g) -0.67 + K 24.e-3 + N(5) 24.e-3 + SOLUTION 1-20 0.001 mM KCl + units mol/kgw + temp 25 # Column is at 25C + pH 7.0 + pe 12.0 O2(g) -0.67 + K 1e-6 + Cl 1e-6 + EXCHANGE 1-20 + KX 0.048 + TRANSPORT # Make column temperature 0C, displace Cl + cells 20 + shifts 19 + flow_direction forward + bcond flux flux + length 1.0 + disp 0.0 # No dispersion + diffc 0.0 # No diffusion + thermal_diffusion 1.0 # No retardation for heat + PRINT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. + reset false + END + SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + SOLUTION 20 Same as soln 0 in cell 20 at closed column end (second type boundary cond) + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + EXCHANGE 20 + NaX 0.048 + TRANSPORT # Diffuse 24C, NaCl solution from column end + shifts 1 + flow_direction diffusion + bcond constant closed + thermal_diffusion 3.0 # heat is retarded equal to Na + diffc 0.3e-9 # m^2/s + timest 1.0e+10 # 317 years, 19 substeps will be used + SELECTED_OUTPUT + file ex12.sel + high_precision true + reset false + distance true + temperature true + USER_PUNCH + heading Na_mmol K_mmol Cl_mmol + 10 PUNCH TOT("Na")*1000, TOT("K")*1000, TOT("Cl")*1000 + END +No memory leaks diff --git a/Sun/examples/ex12.sel b/Sun/examples/ex12.sel new file mode 100644 index 00000000..84fd56c2 --- /dev/null +++ b/Sun/examples/ex12.sel @@ -0,0 +1,44 @@ + dist_x temp Na_mmol K_mmol Cl_mmol + -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 + 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 19.5 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + 0.5 1.686181418415e+01 1.686181416184e+01 7.138185829939e+00 2.011377529332e+01 + 1.5 6.421492325960e+00 6.421492342616e+00 1.757850764418e+01 1.294968671951e+01 + 2.5 1.759908541854e+00 1.759908557221e+00 2.224009143309e+01 7.342808261321e+00 + 3.5 3.571924631562e-01 3.571924666823e-01 2.364280752813e+01 3.623408283684e+00 + 4.5 5.490209781370e-02 5.490209803302e-02 2.394509789974e+01 1.538555967129e+00 + 5.5 6.484238380348e-03 6.484238322345e-03 2.399351576095e+01 5.556625533113e-01 + 6.5 5.926340095484e-04 5.926339925265e-04 2.399940736587e+01 1.684990632469e-01 + 7.5 4.190926756604e-05 4.190926525116e-05 2.399995809080e+01 4.224784404205e-02 + 8.5 2.276345750780e-06 2.276345548554e-06 2.399999772377e+01 8.664946370896e-03 + 9.5 1.396593677778e-07 1.396593266673e-07 2.399999986046e+01 2.055609847093e-03 + 10.5 1.138869021831e-06 1.138868368161e-06 2.399999886125e+01 4.374443607427e-03 + 11.5 2.090811414205e-05 2.090810331638e-05 2.399997909199e+01 2.044715368548e-02 + 12.5 2.951795282278e-04 2.951793938629e-04 2.399970482061e+01 7.995922685941e-02 + 13.5 3.221164570742e-03 3.221163321490e-03 2.399677883641e+01 2.567109777341e-01 + 14.5 2.715473190226e-02 2.715472330367e-02 2.397284527577e+01 6.850286499844e-01 + 15.5 1.753541123879e-01 1.753540697297e-01 2.382464592812e+01 1.533872870596e+00 + 16.5 8.525032220200e-01 8.525030769812e-01 2.314749691919e+01 2.902126148041e+00 + 17.5 3.032149931402e+00 3.032149625513e+00 2.096785036949e+01 4.663139220104e+00 + 18.5 7.550952821146e+00 7.550952502686e+00 1.644904749357e+01 6.385483516941e+00 + 19.5 1.235834674495e+01 1.235834658501e+01 1.164165341481e+01 7.468268986482e+00 diff --git a/Sun/examples/ex12a.log b/Sun/examples/ex12a.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex12a.out b/Sun/examples/ex12a.out new file mode 100644 index 00000000..1dc02b37 --- /dev/null +++ b/Sun/examples/ex12a.out @@ -0,0 +1,188 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex12a + Output file: ex12a.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 12a.--Advective and diffusive transport of heat and solutes. + Constant boundary condition at one end, closed at other. + The problem is designed so that temperature should equal Na-conc + (in mmol/kgw) after diffusion. Compares with analytical solution + for 20-cell and 60-cell models. + EXCHANGE_SPECIES + Na+ + X- = NaX + log_k 0.0 + gamma 4.0 0.075 + H+ + X- = HX + log_k -99. + gamma 9.0 0.0 + K+ + X- = KX + log_k 0.0 + gamma 3.5 0.015 + SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + SOLUTION 1-19 24.0 mM KNO3 + units mol/kgw + temp 0 # Incoming solution 0C + pH 7.0 + pe 12.0 O2(g) -0.67 + K 24.e-3 + N(5) 24.e-3 + EXCHANGE 1-19 + KX 0.048 + SOLUTION 20 Same as soln 0 in cell 20 at closed column end (second type boundary cond) + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + EXCHANGE 20 + NaX 0.048 + PRINT + reset false + END + TRANSPORT # Diffuse 24C, NaCl solution from column end + cells 20 + shifts 1 + flow_direction diffusion + bcond constant closed + length 1.0 + thermal_diffusion 3.0 # Heat is retarded equal to Na + disp 0.0 # No dispersion + diffc 0.3e-9 # m^2/s + timest 1.0e+10 # 317 years, 19 substeps will be used + SELECTED_OUTPUT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. + file ex12a.sel + high_precision true + reset false + distance true + temperature true + USER_PUNCH + heading Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic + 10 PUNCH TOT("Na")*1000, TOT("K")*1000, TOT("Cl")*1000 + 20 DATA 0.254829592, -0.284496736, 1.421413741, -1.453152027, 1.061405429 + 30 x = DIST + 40 if (x > 8.5 OR SIM_TIME <= 0) THEN END + 50 IF (ABS(x MOD 0.5) > 1e-3) OR (TC <= 0) THEN END + 60 READ a1, a2, a3, a4, a5 + 70 REM calculate error in Cl + 80 Arg = x / (2*SQRT(3e-10 * SIM_TIME / 1.0)) + 90 e = 1/(1 + 0.3275911 * Arg) + 100 erfc_Cl = (e*(a1+e*(a2+e*(a3+e*(a4+e*a5)))))*EXP(-Arg*Arg) + 110 REM calculate error in Na + 120 Arg = x / (2*SQRT(3e-10 * SIM_TIME / 3.0)) + 130 e = 1/(1 + 0.3275911 * Arg) + 140 erfc_Na = (e*(a1+e*(a2+e*(a3+e*(a4+e*a5)))))*EXP(-Arg*Arg) + 150 REM punch results + 160 error_Cl = 0.024 * erfc_Cl - TOT("Cl") + 170 error_Na = 0.024 * erfc_Na - TOT("Na") + 180 PUNCH error_Cl, error_Na + 190 REM store results + 200 j = x - 0.5 + 210 PUT(error_Cl, SIM_NO, j, 1) + 220 PUT(error_Na, SIM_NO, j, 2) + 500 END + END + SELECTED_OUTPUT + user_punch false + SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + SOLUTION 1-59 24.0 mM KNO3 + units mol/kgw + temp 0 # Incoming solution 0C + pH 7.0 + pe 12.0 O2(g) -0.67 + K 24.e-3 + N(5) 24.e-3 + EXCHANGE 1-59 + KX 0.048 + SOLUTION 60 Same as soln 0 in cell 60 at closed column end (second type boundary cond) + units mol/kgw + temp 24 + pH 7.0 + pe 12.0 O2(g) -0.67 + Na 24.e-3 + Cl 24.e-3 + EXCHANGE 60 + NaX 0.048 + END + TRANSPORT # Diffuse 24C, NaCl solution from column end + cells 60 + shifts 1 + flow_direction diffusion + bcond constant closed + thermal_diffusion 3.0 # Heat is retarded equal to Na + disp 0.0 # No dispersion + diffc 0.3e-9 # m^2/s + length .33333333333333333 + timest 1.0e+10 # 317 years + punch_cells 1-60 + SELECTED_OUTPUT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 60. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 60. + high_precision true + user_punch true + reset false + distance true + temperature true + END + SOLUTION # Initial solution calculation for pure water + PRINT + reset false # Initial solution calculation not printed + user_print true + SELECTED_OUTPUT + high_precision false # Controls precision for USER_PRINT too. + USER_PRINT + 10 PRINT " Error in Cl concentration Error in Na concentration" + 20 PRINT " ------------------------- -------------------------" + 30 PRINT " Distance 20-cell 60-cell 20-cell 60-cell" + 40 PRINT " " + 50 FOR j = 0 TO 8 + 60 PRINT j + 0.5, GET(2, j, 1), GET(4, j, 1), GET(2, j, 2), GET(4, j, 2) + 70 NEXT j + END +----------------------------------User print----------------------------------- + + Error in Cl concentration Error in Na concentration + ------------------------- ------------------------- + Distance 20-cell 60-cell 20-cell 60-cell + + 5.0000e-01 4.3817e-06 9.0009e-08 5.0636e-04 3.9397e-05 + 1.5000e+00 1.7304e-05 1.0407e-06 5.1077e-04 5.5286e-05 + 2.5000e+00 3.5613e-05 3.2028e-06 9.0486e-05 1.4725e-05 + 3.5000e+00 4.9599e-05 5.2170e-06 -3.7312e-05 -3.8884e-06 + 4.5000e+00 5.0063e-05 5.6394e-06 -1.9794e-05 -2.5770e-06 + 5.5000e+00 3.8208e-05 4.4562e-06 -4.0684e-06 -5.0254e-07 + 6.5000e+00 2.2627e-05 2.7007e-06 -4.8926e-07 -4.8938e-08 + 7.5000e+00 1.0547e-05 1.2850e-06 -3.9174e-08 -2.7009e-09 + 8.5000e+00 3.8231e-06 4.5302e-07 -2.2318e-09 -9.0081e-11 + +No memory leaks diff --git a/Sun/examples/ex12a.sel b/Sun/examples/ex12a.sel new file mode 100644 index 00000000..2a0be12f --- /dev/null +++ b/Sun/examples/ex12a.sel @@ -0,0 +1,169 @@ + dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic + 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 + 19.5 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + 0.5 1.686181418415e+01 1.686181419284e+01 7.138185798940e+00 2.011377529332e+01 4.381717721817e-06 5.063555346726e-04 + 1.5 6.421492325960e+00 6.421492401967e+00 1.757850758482e+01 1.294968671951e+01 1.730376465525e-05 5.107739267532e-04 + 2.5 1.759908541854e+00 1.759908596887e+00 2.224009139342e+01 7.342808261321e+00 3.561257289983e-05 9.048612448212e-05 + 3.5 3.571924631562e-01 3.571924817826e-01 2.364280751302e+01 3.623408283684e+00 4.959925523712e-05 -3.731213350966e-05 + 4.5 5.490209781370e-02 5.490210180416e-02 2.394509789597e+01 1.538555967129e+00 5.006313596727e-05 -1.979378199416e-05 + 5.5 6.484238380348e-03 6.484238983030e-03 2.399351576028e+01 5.556625533113e-01 3.820767165714e-05 -4.068366980646e-06 + 6.5 5.926340095484e-04 5.926340766447e-04 2.399940736578e+01 1.684990632469e-01 2.262672987200e-05 -4.892608394194e-07 + 7.5 4.190926756604e-05 4.190927316640e-05 2.399995809078e+01 4.224784404205e-02 1.054699173423e-05 -3.917411153365e-08 + 8.5 2.276345750780e-06 2.276346101865e-06 2.399999772376e+01 8.664946370896e-03 3.823149392506e-06 -2.231772077916e-09 + 9.5 1.396593677778e-07 1.396593921606e-07 2.399999986046e+01 2.055609847093e-03 + 10.5 1.138869021831e-06 1.138869196840e-06 2.399999886124e+01 4.374443607427e-03 + 11.5 2.090811414205e-05 2.090811693112e-05 2.399997909197e+01 2.044715368548e-02 + 12.5 2.951795282278e-04 2.951795617161e-04 2.399970482043e+01 7.995922685941e-02 + 13.5 3.221164570742e-03 3.221164872772e-03 2.399677883485e+01 2.567109777341e-01 + 14.5 2.715473190226e-02 2.715473392142e-02 2.397284526515e+01 6.850286499844e-01 + 15.5 1.753541123879e-01 1.753541220807e-01 2.382464587576e+01 1.533872870596e+00 + 16.5 8.525032220200e-01 8.525032534626e-01 2.314749674271e+01 2.902126148041e+00 + 17.5 3.032149931402e+00 3.032149994216e+00 2.096785000078e+01 4.663139220104e+00 + 18.5 7.550952821146e+00 7.550952899109e+00 1.644904709714e+01 6.385483516941e+00 + 19.5 1.235834674495e+01 1.235834684370e+01 1.164165315611e+01 7.468268986482e+00 + dist_x temp + -99 2.400000000000e+01 + -99 0.000000000000e+00 + -99 2.400000000000e+01 + -99 2.400000000000e+01 + dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic + 0.166667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 0.833333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 1.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 1.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 2.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 2.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 3.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 3.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 4.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 4.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 5.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 5.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 6.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 6.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 7.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 7.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 8.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 8.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 9.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 9.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 10.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 10.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 11.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 11.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 12.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 12.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 13.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 13.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 14.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 14.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 15.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 15.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 16.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 16.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 17.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 17.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 18.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 18.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 19.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 19.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 + 19.8333 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 + 0.166667 2.173421305916e+01 2.173421306343e+01 2.265786933713e+00 2.269804666237e+01 + 0.5 1.732877230198e+01 1.732877231885e+01 6.671227673618e+00 2.011806700231e+01 9.000873062853e-08 3.939740866218e-05 + 0.833333 1.328083118787e+01 1.328083122259e+01 1.071916876673e+01 1.760855984610e+01 + 1.16667 9.764783869793e+00 9.764783923632e+00 1.423521606399e+01 1.521226338251e+01 + 1.5 6.876979954453e+00 6.876980022636e+00 1.712301996456e+01 1.296594983180e+01 1.040652364160e-06 5.528630608450e-05 + 1.83333 4.633445178532e+00 4.633445251920e+00 1.936655473578e+01 1.089878644688e+01 + 2.16667 2.983957613764e+00 2.983957682799e+00 2.101604230602e+01 9.031332911172e+00 + 2.5 1.835670035272e+00 1.835670093239e+00 2.216432989702e+01 7.375218041863e+00 3.202792358406e-06 1.472462813043e-05 + 2.83333 1.078309641703e+00 1.078309685856e+00 2.292169030595e+01 5.933464823536e+00 + 3.16667 6.047271172834e-01 6.047271481610e-01 2.339527284513e+01 4.701369002513e+00 + 3.5 3.237687663205e-01 3.237687863260e-01 2.367623120832e+01 3.667790505378e+00 5.217033543007e-06 -3.888438053093e-06 + 3.83333 1.655091653734e-01 1.655091774636e-01 2.383449081836e+01 2.816693047508e+00 + 4.16667 8.080184009388e-02 8.080184694439e-02 2.391919814987e+01 2.128765884991e+00 + 4.5 3.768529738011e-02 3.768530103391e-02 2.396231469660e+01 1.582979737206e+00 5.639365889894e-06 -2.576981223905e-06 + 4.83333 1.679748179371e-02 1.679748363383e-02 2.398320251464e+01 1.157961028529e+00 + 5.16667 7.158658672534e-03 7.158659549847e-03 2.399284133922e+01 8.331081560779e-01 + 5.5 2.918406916536e-03 2.918407313331e-03 2.399708159183e+01 5.894139758477e-01 4.456249120743e-06 -5.025353109470e-07 + 5.83333 1.138704483513e-03 1.138704654056e-03 2.399886129476e+01 4.099947290008e-01 + 6.16667 4.254614091980e-04 4.254614789566e-04 2.399957453813e+01 2.803535790356e-01 + 6.5 1.523110828875e-04 1.523111100786e-04 2.399984768864e+01 1.884251292313e-01 2.700663887612e-06 -4.893787285338e-08 + 6.83333 5.227158932778e-05 5.227159943954e-05 2.399994772825e+01 1.244558376472e-01 + 7.16667 1.720693829075e-05 1.720694188206e-05 2.399998279298e+01 8.077556918093e-02 + 7.5 5.436060808742e-06 5.436062028079e-06 2.399999456390e+01 5.150981286307e-02 1.285022913218e-06 -2.700900395322e-09 + 7.83333 1.649087567417e-06 1.649087963540e-06 2.399999835090e+01 3.227276557119e-02 + 8.16667 4.806328011003e-07 4.806329243359e-07 2.399999951938e+01 1.987075437176e-02 + 8.5 1.346545980534e-07 1.346546347973e-07 2.399999986537e+01 1.203507596490e-02 4.530197984976e-07 -9.008061084852e-11 + 8.83333 3.628418612942e-08 3.628419663780e-08 2.399999996375e+01 7.194421703709e-03 + 9.16667 9.420115605087e-09 9.420118494085e-09 2.399999999061e+01 4.290208467916e-03 + 9.5 2.409789753518e-09 2.409790536015e-09 2.399999999763e+01 2.633460429579e-03 + 9.83333 8.318493065839e-10 8.318495907164e-10 2.399999999921e+01 1.799170182453e-03 + 10.1667 1.239138622414e-09 1.239139029450e-09 2.399999999880e+01 1.552911248870e-03 + 10.5 4.450121249069e-09 4.450122620282e-09 2.399999999559e+01 1.804410616828e-03 + 10.8333 1.697307773631e-08 1.697308267056e-08 2.399999998306e+01 2.583364148394e-03 + 11.1667 6.262520065472e-08 6.262521780825e-08 2.399999993741e+01 4.033590225456e-03 + 11.5 2.221760110271e-07 2.221760682136e-07 2.399999977785e+01 6.422343300949e-03 + 11.8333 7.572168365738e-07 7.572170191795e-07 2.399999924281e+01 1.016200278611e-02 + 12.1667 2.477714073998e-06 2.477714631994e-06 2.399999752230e+01 1.584124624556e-02 + 12.5 7.778925375184e-06 7.778927005412e-06 2.399999222108e+01 2.426212581439e-02 + 12.8333 2.341776426203e-05 2.341776881132e-05 2.399997658222e+01 3.647820852624e-02 + 13.1667 6.755207229881e-05 6.755208441218e-05 2.399993244787e+01 5.382725013175e-02 + 13.5 1.865949099352e-04 1.865949406769e-04 2.399981340498e+01 7.795002257855e-02 + 13.8333 4.931967003130e-04 4.931967745830e-04 2.399950680310e+01 1.107853267574e-01 + 14.1667 1.246472753669e-03 1.246472924261e-03 2.399875352688e+01 1.545304347559e-01 + 14.5 3.009977094510e-03 3.009977466523e-03 2.399699002225e+01 2.115568175130e-01 + 14.8333 6.939537438586e-03 6.939538207639e-03 2.399306046140e+01 2.842735712027e-01 + 15.1667 1.526331935379e-02 1.526332085840e-02 2.398473667861e+01 3.749358095681e-01 + 15.5 3.200217915009e-02 3.200218193090e-02 2.396799781737e+01 4.854024361712e-01 + 15.8333 6.391193399667e-02 6.391193884267e-02 2.393608806026e+01 6.168566584837e-01 + 16.1667 1.214834631133e-01 1.214834710604e-01 2.387851652783e+01 7.695123116931e-01 + 16.5 2.196089759550e-01 2.196089881955e-01 2.378039101048e+01 9.423379783552e-01 + 16.8333 3.772704376914e-01 3.772704553669e-01 2.362272954311e+01 1.132837159798e+00 + 17.1667 6.154714589941e-01 6.154714828922e-01 2.338452851541e+01 1.336924520486e+00 + 17.5 9.528239860304e-01 9.528240162733e-01 2.304717598190e+01 1.548934044811e+00 + 17.8333 1.398887571630e+00 1.398887607499e+00 2.260111239061e+01 1.761784203671e+00 + 18.1667 1.946511170344e+00 1.946511210371e+00 2.205348878777e+01 1.967308461518e+00 + 18.5 2.565669345631e+00 2.565669387970e+00 2.143433061028e+01 2.156738468785e+00 + 18.8333 3.201925616708e+00 3.201925659659e+00 2.079807433877e+01 2.321305007457e+00 + 19.1667 3.781994216092e+00 3.781994258530e+00 2.021800574010e+01 2.452901809002e+00 + 19.5 4.226690935644e+00 4.226690977196e+00 1.977330902162e+01 2.544743405451e+00 + 19.8333 4.468507319433e+00 4.468507360365e+00 1.953149263856e+01 2.591943163049e+00 + dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic + -99 25.000 0.0000e+00 0.0000e+00 0.0000e+00 diff --git a/Sun/examples/ex13a.log b/Sun/examples/ex13a.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex13a.out b/Sun/examples/ex13a.out new file mode 100644 index 00000000..77218db9 --- /dev/null +++ b/Sun/examples/ex13a.out @@ -0,0 +1,310 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13a + Output file: ex13a.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 13A.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + Implicit definition of first-order exchange model. + SOLUTION 0 # 1 mmol/l NaCl + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + Na 1.0 # Na has Retardation = 2 + Cl 1.0 # Cl has Retardation = 1, stagnant exchange + N(5) 1.0 # NO3 is conservative + END +----- +TITLE +----- + + Example 13A.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + Implicit definition of first-order exchange model. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.500e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.551e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.000e-03 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 + H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +Cl 1.000e-03 + Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 +Na 1.000e-03 + Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 + NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 +O(0) 4.374e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.62 -6.04 1.58 NaCl + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1-41 # Column with KNO3 + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + EXCHANGE 1-41 + equilibrate 1 + X 1.e-3 + EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX + K+ + X- = KX + log_k 0.0 + gamma 3.5 0.015 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.70 -3.66 -2.96 O2 + +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using exchange 1. Exchange assemblage after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 13.605 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 + NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 +N(0) 1.994e-19 + N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 +N(3) 2.291e-16 + NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.74 -19.00 -3.26 N2 + NH3(g) -66.79 -65.02 1.77 NH3 + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + TRANSPORT + cells 20 + shifts 5 + flow_direction forward + timest 3600 + bcond flux flux + diffc 0.0 + length 0.1 + disp 0.015 + stagnant 1 6.8e-6 0.3 0.1 + PRINT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. + reset false + END + SOLUTION 0 # Original solution reenters + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + TRANSPORT + shifts 10 + punch_frequency 10 + punch_cells 1-20 + SELECTED_OUTPUT + file ex13a.sel + reset false + solution + distance true + USER_PUNCH + heading Cl_mmol Na_mmol + 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 + END +No memory leaks diff --git a/Sun/examples/ex13a.sel b/Sun/examples/ex13a.sel new file mode 100644 index 00000000..68d5fffe --- /dev/null +++ b/Sun/examples/ex13a.sel @@ -0,0 +1,42 @@ + soln dist_x Cl_mmol Na_mmol + 0 -99 0.0000e+00 0.0000e+00 + 1 0.05 9.6495e-01 8.8504e-01 + 2 0.15 9.1812e-01 6.9360e-01 + 3 0.25 8.4451e-01 4.3288e-01 + 4 0.35 7.1652e-01 1.9734e-01 + 5 0.45 4.9952e-01 6.0705e-02 + 6 0.55 2.4048e-01 1.1785e-02 + 7 0.65 7.2812e-02 1.4039e-03 + 8 0.75 1.3132e-02 9.9324e-05 + 9 0.85 1.2882e-03 3.8318e-06 + 10 0.95 5.2940e-05 6.2140e-08 + 11 1.05 0.0000e+00 0.0000e+00 + 12 1.15 0.0000e+00 0.0000e+00 + 13 1.25 0.0000e+00 0.0000e+00 + 14 1.35 0.0000e+00 0.0000e+00 + 15 1.45 0.0000e+00 0.0000e+00 + 16 1.55 0.0000e+00 0.0000e+00 + 17 1.65 0.0000e+00 0.0000e+00 + 18 1.75 0.0000e+00 0.0000e+00 + 19 1.85 0.0000e+00 0.0000e+00 + 20 1.95 0.0000e+00 0.0000e+00 + 1 0.05 7.5889e-03 2.0250e-02 + 2 0.15 1.7993e-02 5.0943e-02 + 3 0.25 3.3135e-02 1.0209e-01 + 4 0.35 5.3591e-02 1.7480e-01 + 5 0.45 8.0158e-02 2.5484e-01 + 6 0.55 1.1396e-01 3.1308e-01 + 7 0.65 1.5767e-01 3.2277e-01 + 8 0.75 2.1666e-01 2.7968e-01 + 9 0.85 2.9573e-01 2.0468e-01 + 10 0.95 3.8769e-01 1.2726e-01 + 11 1.05 4.6467e-01 6.7581e-02 + 12 1.15 4.9243e-01 3.0745e-02 + 13 1.25 4.5811e-01 1.1988e-02 + 14 1.35 3.7620e-01 3.9981e-03 + 15 1.45 2.7323e-01 1.1366e-03 + 16 1.55 1.7416e-01 2.7440e-04 + 17 1.65 9.6074e-02 5.6038e-05 + 18 1.75 4.5211e-02 9.6477e-06 + 19 1.85 1.7934e-02 1.3954e-06 + 20 1.95 6.4869e-03 1.7678e-07 diff --git a/Sun/examples/ex13b.log b/Sun/examples/ex13b.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex13b.out b/Sun/examples/ex13b.out new file mode 100644 index 00000000..f705879b --- /dev/null +++ b/Sun/examples/ex13b.out @@ -0,0 +1,430 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13b + Output file: ex13b.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 13B.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + Explicit definition of first-order exchange factors. + SOLUTION 0 # 1 mmol/l NaCl + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + Na 1.0 # Na has Retardation = 2 + Cl 1.0 # Cl has Retardation = 1, stagnant exchange + N(5) 1.0 # NO3 is conservative + END +----- +TITLE +----- + + Example 13B.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + Explicit definition of first-order exchange factors. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.500e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.551e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.000e-03 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 + H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +Cl 1.000e-03 + Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 +Na 1.000e-03 + Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 + NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 +O(0) 4.374e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.62 -6.04 1.58 NaCl + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1-41 # Column with KNO3 + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + EXCHANGE 1-41 + equilibrate 1 + X 1.e-3 + EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX + K+ + X- = KX + log_k 0.0 + gamma 3.5 0.015 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.70 -3.66 -2.96 O2 + +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using exchange 1. Exchange assemblage after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 13.605 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 + NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 +N(0) 1.994e-19 + N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 +N(3) 2.291e-16 + NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.74 -19.00 -3.26 N2 + NH3(g) -66.79 -65.02 1.77 NH3 + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + MIX 1 + 1 .93038 + 22 .06962 + MIX 2 + 2 .93038 + 23 .06962 + MIX 3 + 3 .93038 + 24 .06962 + MIX 4 + 4 .93038 + 25 .06962 + MIX 5 + 5 .93038 + 26 .06962 + MIX 6 + 6 .93038 + 27 .06962 + MIX 7 + 7 .93038 + 28 .06962 + MIX 8 + 8 .93038 + 29 .06962 + MIX 9 + 9 .93038 + 30 .06962 + MIX 10 + 10 .93038 + 31 .06962 + MIX 11 + 11 .93038 + 32 .06962 + MIX 12 + 12 .93038 + 33 .06962 + MIX 13 + 13 .93038 + 34 .06962 + MIX 14 + 14 .93038 + 35 .06962 + MIX 15 + 15 .93038 + 36 .06962 + MIX 16 + 16 .93038 + 37 .06962 + MIX 17 + 17 .93038 + 38 .06962 + MIX 18 + 18 .93038 + 39 .06962 + MIX 19 + 19 .93038 + 40 .06962 + MIX 20 + 20 .93038 + 41 .06962 + MIX 22 + 1 .20886 + 22 .79114 + MIX 23 + 2 .20886 + 23 .79114 + MIX 24 + 3 .20886 + 24 .79114 + MIX 25 + 4 .20886 + 25 .79114 + MIX 26 + 5 .20886 + 26 .79114 + MIX 27 + 6 .20886 + 27 .79114 + MIX 28 + 7 .20886 + 28 .79114 + MIX 29 + 8 .20886 + 29 .79114 + MIX 30 + 9 .20886 + 30 .79114 + MIX 31 + 10 .20886 + 31 .79114 + MIX 32 + 11 .20886 + 32 .79114 + MIX 33 + 12 .20886 + 33 .79114 + MIX 34 + 13 .20886 + 34 .79114 + MIX 35 + 14 .20886 + 35 .79114 + MIX 36 + 15 .20886 + 36 .79114 + MIX 37 + 16 .20886 + 37 .79114 + MIX 38 + 17 .20886 + 38 .79114 + MIX 39 + 18 .20886 + 39 .79114 + MIX 40 + 19 .20886 + 40 .79114 + MIX 41 + 20 .20886 + 41 .79114 + TRANSPORT + cells 20 + shifts 5 + flow_direction forward + timest 3600 + bcond flux flux + diffc 0.0 + length 0.1 + disp 0.015 + stagnant 1 + PRINT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. + reset false + END + SOLUTION 0 # Original solution reenters + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + TRANSPORT + shifts 10 + punch_frequency 10 + punch_cells 1-20 + SELECTED_OUTPUT + file ex13b.sel + reset false + distance true + solution + USER_PUNCH + heading Cl_mmol Na_mmol + 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 + END +No memory leaks diff --git a/Sun/examples/ex13b.sel b/Sun/examples/ex13b.sel new file mode 100644 index 00000000..21837b16 --- /dev/null +++ b/Sun/examples/ex13b.sel @@ -0,0 +1,42 @@ + soln dist_x Cl_mmol Na_mmol + 0 -99 0.0000e+00 0.0000e+00 + 1 0.05 9.6495e-01 8.8504e-01 + 2 0.15 9.1812e-01 6.9360e-01 + 3 0.25 8.4451e-01 4.3288e-01 + 4 0.35 7.1652e-01 1.9734e-01 + 5 0.45 4.9952e-01 6.0705e-02 + 6 0.55 2.4048e-01 1.1785e-02 + 7 0.65 7.2813e-02 1.4039e-03 + 8 0.75 1.3132e-02 9.9324e-05 + 9 0.85 1.2882e-03 3.8318e-06 + 10 0.95 5.2941e-05 6.2140e-08 + 11 1.05 0.0000e+00 0.0000e+00 + 12 1.15 0.0000e+00 0.0000e+00 + 13 1.25 0.0000e+00 0.0000e+00 + 14 1.35 0.0000e+00 0.0000e+00 + 15 1.45 0.0000e+00 0.0000e+00 + 16 1.55 0.0000e+00 0.0000e+00 + 17 1.65 0.0000e+00 0.0000e+00 + 18 1.75 0.0000e+00 0.0000e+00 + 19 1.85 0.0000e+00 0.0000e+00 + 20 1.95 0.0000e+00 0.0000e+00 + 1 0.05 7.5889e-03 2.0249e-02 + 2 0.15 1.7993e-02 5.0943e-02 + 3 0.25 3.3135e-02 1.0209e-01 + 4 0.35 5.3590e-02 1.7480e-01 + 5 0.45 8.0158e-02 2.5484e-01 + 6 0.55 1.1395e-01 3.1308e-01 + 7 0.65 1.5766e-01 3.2277e-01 + 8 0.75 2.1666e-01 2.7969e-01 + 9 0.85 2.9573e-01 2.0468e-01 + 10 0.95 3.8768e-01 1.2727e-01 + 11 1.05 4.6467e-01 6.7581e-02 + 12 1.15 4.9243e-01 3.0745e-02 + 13 1.25 4.5811e-01 1.1988e-02 + 14 1.35 3.7620e-01 3.9981e-03 + 15 1.45 2.7323e-01 1.1366e-03 + 16 1.55 1.7416e-01 2.7440e-04 + 17 1.65 9.6075e-02 5.6039e-05 + 18 1.75 4.5211e-02 9.6477e-06 + 19 1.85 1.7934e-02 1.3954e-06 + 20 1.95 6.4870e-03 1.7678e-07 diff --git a/Sun/examples/ex13c.log b/Sun/examples/ex13c.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex13c.out b/Sun/examples/ex13c.out new file mode 100644 index 00000000..d073ce4e --- /dev/null +++ b/Sun/examples/ex13c.out @@ -0,0 +1,751 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13c + Output file: ex13c.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 13C.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + 5 layer stagnant zone with finite differences. + SOLUTION 0 # 1 mmol/l NaCl + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + Na 1.0 # Na has Retardation = 2 + Cl 1.0 # Cl has Retardation = 1, stagnant exchange + N(5) 1.0 # NO3 is conservative + END +----- +TITLE +----- + + Example 13C.--1 mmol/l NaCl/NO3 enters column with stagnant zones. + 5 layer stagnant zone with finite differences. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.500e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.551e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.000e-03 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 + H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +Cl 1.000e-03 + Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 +Na 1.000e-03 + Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 + NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 +O(0) 4.374e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -7.62 -6.04 1.58 NaCl + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1-121 # Column with KNO3 + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + EXCHANGE 1-121 + equilibrate 1 + X 1.e-3 + EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX + K+ + X- = KX + log_k 0.0 + gamma 3.5 0.015 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N(5) 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.605 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -0.70 -3.66 -2.96 O2 + +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using exchange 1. Exchange assemblage after simulation 2. + +-----------------------------Exchange composition------------------------------ + +X 1.000e-03 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + KX 1.000e-03 1.000e-03 1.000e+00 -0.016 + NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + K 1.000e-03 1.000e-03 + N 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 13.605 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.351e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.351e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 + H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +K 1.000e-03 + K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 + KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 + NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 +N(0) 1.994e-19 + N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 +N(3) 2.291e-16 + NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 +N(5) 1.000e-03 + NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 +O(0) 4.375e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -15.74 -19.00 -3.26 N2 + NH3(g) -66.79 -65.02 1.77 NH3 + O2(g) -0.70 -3.66 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + MIX 1 + 1 0.90712 + 22 0.09288 + MIX 22 + 1 0.57098 + 22 0.21656 + 42 0.21246 + MIX 42 + 22 0.35027 + 42 0.45270 + 62 0.19703 + MIX 62 + 42 0.38368 + 62 0.44579 + 82 0.17053 + MIX 82 + 62 0.46286 + 82 0.42143 + 102 0.11571 + MIX 102 + 82 0.81000 + 102 0.19000 + MIX 2 + 2 0.90712 + 23 0.09288 + MIX 23 + 2 0.57098 + 23 0.21656 + 43 0.21246 + MIX 43 + 23 0.35027 + 43 0.45270 + 63 0.19703 + MIX 63 + 43 0.38368 + 63 0.44579 + 83 0.17053 + MIX 83 + 63 0.46286 + 83 0.42143 + 103 0.11571 + MIX 103 + 83 0.81000 + 103 0.19000 + MIX 3 + 3 0.90712 + 24 0.09288 + MIX 24 + 3 0.57098 + 24 0.21656 + 44 0.21246 + MIX 44 + 24 0.35027 + 44 0.45270 + 64 0.19703 + MIX 64 + 44 0.38368 + 64 0.44579 + 84 0.17053 + MIX 84 + 64 0.46286 + 84 0.42143 + 104 0.11571 + MIX 104 + 84 0.81000 + 104 0.19000 + MIX 4 + 4 0.90712 + 25 0.09288 + MIX 25 + 4 0.57098 + 25 0.21656 + 45 0.21246 + MIX 45 + 25 0.35027 + 45 0.45270 + 65 0.19703 + MIX 65 + 45 0.38368 + 65 0.44579 + 85 0.17053 + MIX 85 + 65 0.46286 + 85 0.42143 + 105 0.11571 + MIX 105 + 85 0.81000 + 105 0.19000 + MIX 5 + 5 0.90712 + 26 0.09288 + MIX 26 + 5 0.57098 + 26 0.21656 + 46 0.21246 + MIX 46 + 26 0.35027 + 46 0.45270 + 66 0.19703 + MIX 66 + 46 0.38368 + 66 0.44579 + 86 0.17053 + MIX 86 + 66 0.46286 + 86 0.42143 + 106 0.11571 + MIX 106 + 86 0.81000 + 106 0.19000 + MIX 6 + 6 0.90712 + 27 0.09288 + MIX 27 + 6 0.57098 + 27 0.21656 + 47 0.21246 + MIX 47 + 27 0.35027 + 47 0.45270 + 67 0.19703 + MIX 67 + 47 0.38368 + 67 0.44579 + 87 0.17053 + MIX 87 + 67 0.46286 + 87 0.42143 + 107 0.11571 + MIX 107 + 87 0.81000 + 107 0.19000 + MIX 7 + 7 0.90712 + 28 0.09288 + MIX 28 + 7 0.57098 + 28 0.21656 + 48 0.21246 + MIX 48 + 28 0.35027 + 48 0.45270 + 68 0.19703 + MIX 68 + 48 0.38368 + 68 0.44579 + 88 0.17053 + MIX 88 + 68 0.46286 + 88 0.42143 + 108 0.11571 + MIX 108 + 88 0.81000 + 108 0.19000 + MIX 8 + 8 0.90712 + 29 0.09288 + MIX 29 + 8 0.57098 + 29 0.21656 + 49 0.21246 + MIX 49 + 29 0.35027 + 49 0.45270 + 69 0.19703 + MIX 69 + 49 0.38368 + 69 0.44579 + 89 0.17053 + MIX 89 + 69 0.46286 + 89 0.42143 + 109 0.11571 + MIX 109 + 89 0.81000 + 109 0.19000 + MIX 9 + 9 0.90712 + 30 0.09288 + MIX 30 + 9 0.57098 + 30 0.21656 + 50 0.21246 + MIX 50 + 30 0.35027 + 50 0.45270 + 70 0.19703 + MIX 70 + 50 0.38368 + 70 0.44579 + 90 0.17053 + MIX 90 + 70 0.46286 + 90 0.42143 + 110 0.11571 + MIX 110 + 90 0.81000 + 110 0.19000 + MIX 10 + 10 0.90712 + 31 0.09288 + MIX 31 + 10 0.57098 + 31 0.21656 + 51 0.21246 + MIX 51 + 31 0.35027 + 51 0.45270 + 71 0.19703 + MIX 71 + 51 0.38368 + 71 0.44579 + 91 0.17053 + MIX 91 + 71 0.46286 + 91 0.42143 + 111 0.11571 + MIX 111 + 91 0.81000 + 111 0.19000 + MIX 11 + 11 0.90712 + 32 0.09288 + MIX 32 + 11 0.57098 + 32 0.21656 + 52 0.21246 + MIX 52 + 32 0.35027 + 52 0.45270 + 72 0.19703 + MIX 72 + 52 0.38368 + 72 0.44579 + 92 0.17053 + MIX 92 + 72 0.46286 + 92 0.42143 + 112 0.11571 + MIX 112 + 92 0.81000 + 112 0.19000 + MIX 12 + 12 0.90712 + 33 0.09288 + MIX 33 + 12 0.57098 + 33 0.21656 + 53 0.21246 + MIX 53 + 33 0.35027 + 53 0.45270 + 73 0.19703 + MIX 73 + 53 0.38368 + 73 0.44579 + 93 0.17053 + MIX 93 + 73 0.46286 + 93 0.42143 + 113 0.11571 + MIX 113 + 93 0.81000 + 113 0.19000 + MIX 13 + 13 0.90712 + 34 0.09288 + MIX 34 + 13 0.57098 + 34 0.21656 + 54 0.21246 + MIX 54 + 34 0.35027 + 54 0.45270 + 74 0.19703 + MIX 74 + 54 0.38368 + 74 0.44579 + 94 0.17053 + MIX 94 + 74 0.46286 + 94 0.42143 + 114 0.11571 + MIX 114 + 94 0.81000 + 114 0.19000 + MIX 14 + 14 0.90712 + 35 0.09288 + MIX 35 + 14 0.57098 + 35 0.21656 + 55 0.21246 + MIX 55 + 35 0.35027 + 55 0.45270 + 75 0.19703 + MIX 75 + 55 0.38368 + 75 0.44579 + 95 0.17053 + MIX 95 + 75 0.46286 + 95 0.42143 + 115 0.11571 + MIX 115 + 95 0.81000 + 115 0.19000 + MIX 15 + 15 0.90712 + 36 0.09288 + MIX 36 + 15 0.57098 + 36 0.21656 + 56 0.21246 + MIX 56 + 36 0.35027 + 56 0.45270 + 76 0.19703 + MIX 76 + 56 0.38368 + 76 0.44579 + 96 0.17053 + MIX 96 + 76 0.46286 + 96 0.42143 + 116 0.11571 + MIX 116 + 96 0.81000 + 116 0.19000 + MIX 16 + 16 0.90712 + 37 0.09288 + MIX 37 + 16 0.57098 + 37 0.21656 + 57 0.21246 + MIX 57 + 37 0.35027 + 57 0.45270 + 77 0.19703 + MIX 77 + 57 0.38368 + 77 0.44579 + 97 0.17053 + MIX 97 + 77 0.46286 + 97 0.42143 + 117 0.11571 + MIX 117 + 97 0.81000 + 117 0.19000 + MIX 17 + 17 0.90712 + 38 0.09288 + MIX 38 + 17 0.57098 + 38 0.21656 + 58 0.21246 + MIX 58 + 38 0.35027 + 58 0.45270 + 78 0.19703 + MIX 78 + 58 0.38368 + 78 0.44579 + 98 0.17053 + MIX 98 + 78 0.46286 + 98 0.42143 + 118 0.11571 + MIX 118 + 98 0.81000 + 118 0.19000 + MIX 18 + 18 0.90712 + 39 0.09288 + MIX 39 + 18 0.57098 + 39 0.21656 + 59 0.21246 + MIX 59 + 39 0.35027 + 59 0.45270 + 79 0.19703 + MIX 79 + 59 0.38368 + 79 0.44579 + 99 0.17053 + MIX 99 + 79 0.46286 + 99 0.42143 + 119 0.11571 + MIX 119 + 99 0.81000 + 119 0.19000 + MIX 19 + 19 0.90712 + 40 0.09288 + MIX 40 + 19 0.57098 + 40 0.21656 + 60 0.21246 + MIX 60 + 40 0.35027 + 60 0.45270 + 80 0.19703 + MIX 80 + 60 0.38368 + 80 0.44579 + 100 0.17053 + MIX 100 + 80 0.46286 + 100 0.42143 + 120 0.11571 + MIX 120 + 100 0.81000 + 120 0.19000 + MIX 20 + 20 0.90712 + 41 0.09288 + MIX 41 + 20 0.57098 + 41 0.21656 + 61 0.21246 + MIX 61 + 41 0.35027 + 61 0.45270 + 81 0.19703 + MIX 81 + 61 0.38368 + 81 0.44579 + 101 0.17053 + MIX 101 + 81 0.46286 + 101 0.42143 + 121 0.11571 + MIX 121 + 101 0.81000 + 121 0.19000 + TRANSPORT + cells 20 + shifts 5 + flow_direction forward + timest 3600 + tempr 3.0 + bcond flux flux + diffc 0.0 + length 0.10 + disp 0.015 + stagnant 5 + PRINT +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. + reset false + END + SOLUTION 0 # Original solution reenters + units mmol/l + pH 7.0 + pe 13.0 O2(g) -0.7 + K 1.0 + N(5) 1.0 + TRANSPORT + shifts 10 + punch_frequency 10 + punch_cells 1-20 + SELECTED_OUTPUT + file ex13c.sel + reset false + solution + distance true + USER_PUNCH + heading Cl_mmol Na_mmol + 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 + END +No memory leaks diff --git a/Sun/examples/ex13c.sel b/Sun/examples/ex13c.sel new file mode 100644 index 00000000..7969e528 --- /dev/null +++ b/Sun/examples/ex13c.sel @@ -0,0 +1,42 @@ + soln dist_x Cl_mmol Na_mmol + 0 -99 0.0000e+00 0.0000e+00 + 1 0.05 9.7683e-01 8.8829e-01 + 2 0.15 9.4255e-01 6.9066e-01 + 3 0.25 8.7253e-01 4.2503e-01 + 4 0.35 7.2600e-01 1.9091e-01 + 5 0.45 4.8246e-01 5.8021e-02 + 6 0.55 2.2239e-01 1.1177e-02 + 7 0.65 6.5489e-02 1.3256e-03 + 8 0.75 1.1639e-02 9.3569e-05 + 9 0.85 1.1350e-03 3.6065e-06 + 10 0.95 4.6646e-05 5.8485e-08 + 11 1.05 0.0000e+00 0.0000e+00 + 12 1.15 0.0000e+00 0.0000e+00 + 13 1.25 0.0000e+00 0.0000e+00 + 14 1.35 0.0000e+00 0.0000e+00 + 15 1.45 0.0000e+00 0.0000e+00 + 16 1.55 0.0000e+00 0.0000e+00 + 17 1.65 0.0000e+00 0.0000e+00 + 18 1.75 0.0000e+00 0.0000e+00 + 19 1.85 0.0000e+00 0.0000e+00 + 20 1.95 0.0000e+00 0.0000e+00 + 1 0.05 4.7101e-03 1.6916e-02 + 2 0.15 1.0234e-02 4.9729e-02 + 3 0.25 1.8109e-02 1.0883e-01 + 4 0.35 2.9565e-02 1.9194e-01 + 5 0.45 4.7408e-02 2.7841e-01 + 6 0.55 7.7191e-02 3.3492e-01 + 7 0.65 1.2832e-01 3.3632e-01 + 8 0.75 2.1109e-01 2.8375e-01 + 9 0.85 3.2572e-01 2.0251e-01 + 10 0.95 4.4908e-01 1.2304e-01 + 11 1.05 5.3819e-01 6.3977e-02 + 12 1.15 5.5716e-01 2.8554e-02 + 13 1.25 5.0158e-01 1.0943e-02 + 14 1.35 3.9581e-01 3.5935e-03 + 15 1.45 2.7424e-01 1.0078e-03 + 16 1.55 1.6586e-01 2.4047e-04 + 17 1.65 8.6688e-02 4.8621e-05 + 18 1.75 3.8743e-02 8.3007e-06 + 19 1.85 1.4669e-02 1.1922e-06 + 20 1.95 5.0940e-03 1.5016e-07 diff --git a/Sun/examples/ex14.log b/Sun/examples/ex14.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex14.out b/Sun/examples/ex14.out new file mode 100644 index 00000000..bf8f9286 --- /dev/null +++ b/Sun/examples/ex14.out @@ -0,0 +1,3000 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex14 + Output file: ex14.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/wateq4f.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 14.--Transport with equilibrium_phases, exchange, and surface reactions + *********** + PLEASE NOTE: This problem requires database file wateq4f.dat! + Arsenic data of Archer and Nordstrom (2002) included in + wateq4f.dat (PHREEQC Version 2.8). + Results differ from WRIR 99-4259 because of revised data. + *********** + SURFACE_SPECIES + Hfo_wOH + Mg+2 = Hfo_wOMg+ + H+ + log_k -15. + Hfo_wOH + Ca+2 = Hfo_wOCa+ + H+ + log_k -15. + SOLUTION 1 Brine + pH 5.713 + pe 4.0 O2(g) -0.7 + temp 25. + units mol/kgw + Ca .4655 + Mg .1609 + Na 5.402 + Cl 6.642 charge + C .00396 + S .004725 + As .05 umol/kgw + END +----- +TITLE +----- + + Example 14.--Transport with equilibrium_phases, exchange, and surface reactions +*********** +PLEASE NOTE: This problem requires database file wateq4f.dat! + Arsenic data of Archer and Nordstrom (2002) included in + wateq4f.dat (PHREEQC Version 2.8). + Results differ from WRIR 99-4259 because of revised data. +*********** + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Brine + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 5.000e-08 5.000e-08 + C 3.960e-03 3.960e-03 + Ca 4.655e-01 4.655e-01 + Cl 6.642e+00 6.642e+00 Charge balance + Mg 1.609e-01 1.609e-01 + Na 5.402e+00 5.402e+00 + S 4.725e-03 4.725e-03 + +----------------------------Description of solution---------------------------- + + pH = 5.713 + pe = 14.945 Equilibrium with O2(g) + Activity of water = 0.785 + Ionic strength = 7.269e+00 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.333e-03 + Total CO2 (mol/kg) = 3.960e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.964e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 11 + Total H = 1.110158e+02 + Total O = 5.553645e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.755e-06 1.936e-06 -5.560 -5.713 -0.153 + OH- 7.396e-10 4.056e-09 -9.131 -8.392 0.739 + H2O 5.551e+01 7.846e-01 1.744 -0.105 0.000 +As(3) 2.742e-33 + H3AsO3 2.741e-33 1.462e-32 -32.562 -31.835 0.727 + H2AsO3- 9.743e-37 5.343e-36 -36.011 -35.272 0.739 + H4AsO3+ 2.557e-39 1.402e-38 -38.592 -37.853 0.739 + HAsO3-2 0.000e+00 0.000e+00 -47.216 -44.259 2.956 + AsO3-3 0.000e+00 0.000e+00 -60.898 -54.246 6.652 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -302.180 -301.440 0.739 + As3S4(HS)2- 0.000e+00 0.000e+00 -897.970 -897.231 0.739 +As(5) 5.000e-08 + H2AsO4- 4.997e-08 2.740e-07 -7.301 -6.562 0.739 + H3AsO4 1.986e-11 1.059e-10 -10.702 -9.975 0.727 + HAsO4-2 1.082e-11 9.791e-09 -10.966 -8.009 2.956 + AsO4-3 2.522e-21 1.132e-14 -20.598 -13.946 6.652 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.861 -143.135 0.727 +C(4) 3.960e-03 + HCO3- 1.045e-03 6.049e-04 -2.981 -3.218 -0.238 + CaHCO3+ 1.002e-03 5.494e-03 -2.999 -2.260 0.739 + MgHCO3+ 6.754e-04 3.704e-03 -3.170 -2.431 0.739 + CO2 6.296e-04 3.357e-03 -3.201 -2.474 0.727 + NaHCO3 6.026e-04 3.213e-03 -3.220 -2.493 0.727 + CaCO3 3.278e-06 1.748e-05 -5.484 -4.758 0.727 + MgCO3 1.372e-06 7.316e-06 -5.863 -5.136 0.727 + NaCO3- 4.698e-07 2.577e-06 -6.328 -5.589 0.739 + CO3-2 1.307e-07 1.465e-08 -6.884 -7.834 -0.950 +Ca 4.655e-01 + Ca+2 4.629e-01 7.121e-01 -0.335 -0.147 0.187 + CaSO4 1.606e-03 8.565e-03 -2.794 -2.067 0.727 + CaHCO3+ 1.002e-03 5.494e-03 -2.999 -2.260 0.739 + CaCO3 3.278e-06 1.748e-05 -5.484 -4.758 0.727 + CaHSO4+ 1.772e-08 9.716e-08 -7.752 -7.012 0.739 + CaOH+ 8.731e-09 4.788e-08 -8.059 -7.320 0.739 +Cl 6.642e+00 + Cl- 6.642e+00 3.947e+00 0.822 0.596 -0.226 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -45.192 -44.465 0.727 +Mg 1.609e-01 + Mg+2 1.588e-01 5.233e-01 -0.799 -0.281 0.518 + MgSO4 1.387e-03 7.395e-03 -2.858 -2.131 0.727 + MgHCO3+ 6.754e-04 3.704e-03 -3.170 -2.431 0.739 + MgCO3 1.372e-06 7.316e-06 -5.863 -5.136 0.727 + MgOH+ 1.404e-07 7.698e-07 -6.853 -6.114 0.739 +Na 5.402e+00 + Na+ 5.401e+00 9.445e+00 0.732 0.975 0.243 + NaHCO3 6.026e-04 3.213e-03 -3.220 -2.493 0.727 + NaSO4- 5.203e-04 2.854e-03 -3.284 -2.545 0.739 + NaCO3- 4.698e-07 2.577e-06 -6.328 -5.589 0.739 +O(0) 8.206e-05 + O2 4.103e-05 2.188e-04 -4.387 -3.660 0.727 +S(-2) 0.000e+00 + H2S 0.000e+00 0.000e+00 -140.569 -139.842 0.727 + HS- 0.000e+00 0.000e+00 -141.810 -141.070 0.739 + S5-2 0.000e+00 0.000e+00 -144.480 -144.952 -0.473 + S4-2 0.000e+00 0.000e+00 -144.629 -145.186 -0.558 + S6-2 0.000e+00 0.000e+00 -144.828 -145.238 -0.410 + S3-2 0.000e+00 0.000e+00 -147.960 -148.639 -0.680 + S2-2 0.000e+00 0.000e+00 -149.072 -149.885 -0.813 + S-2 0.000e+00 0.000e+00 -151.232 -148.275 2.956 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -302.180 -301.440 0.739 + As3S4(HS)2- 0.000e+00 0.000e+00 -897.970 -897.231 0.739 +S(6) 4.725e-03 + CaSO4 1.606e-03 8.565e-03 -2.794 -2.067 0.727 + MgSO4 1.387e-03 7.395e-03 -2.858 -2.131 0.727 + SO4-2 1.211e-03 6.028e-05 -2.917 -4.220 -1.303 + NaSO4- 5.203e-04 2.854e-03 -3.284 -2.545 0.739 + CaHSO4+ 1.772e-08 9.716e-08 -7.752 -7.012 0.739 + HSO4- 2.069e-09 1.135e-08 -8.684 -7.945 0.739 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.01 -4.37 -4.36 CaSO4 + Aragonite 0.35 -7.98 -8.34 CaCO3 + Arsenolite -61.97 -63.35 -1.38 As2O3 + Artinite -7.10 2.50 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -27.86 -19.63 8.23 As2O5 + As2S3(am) -458.49 -503.39 -44.90 As2S3 + As_native -80.96 -93.49 -12.53 As + Brucite -5.91 10.93 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -9.85 -28.76 -18.91 Ca3(AsO4)2:4H2O + Calcite 0.50 -7.98 -8.48 CaCO3 + CH4(g) -140.27 -143.13 -2.86 CH4 + Claudetite -62.01 -63.35 -1.34 As2O3 + CO2(g) -1.01 -2.47 -1.47 CO2 + Dolomite 0.99 -16.10 -17.09 CaMg(CO3)2 + Dolomite(d) 0.44 -16.10 -16.54 CaMg(CO3)2 + Epsomite -3.10 -5.24 -2.14 MgSO4:7H2O + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -41.32 -44.47 -3.15 H2 + H2O(g) -1.62 -0.11 1.51 H2O + H2S(g) -138.84 -139.84 -1.00 H2S + Halite -0.01 1.57 1.58 NaCl + Huntite -2.36 -32.33 -29.97 CaMg3(CO3)4 + Hydromagnesite -13.19 -21.95 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.09 -8.12 -8.03 MgCO3 + Mirabilite -2.21 -3.32 -1.11 Na2SO4:10H2O + Nahcolite -1.70 -2.24 -0.55 NaHCO3 + Natron -5.63 -6.94 -1.31 Na2CO3:10H2O + Nesquehonite -2.81 -8.43 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -457.09 -503.39 -46.30 As2S3 + Portlandite -11.73 11.07 22.80 Ca(OH)2 + Realgar -179.02 -198.96 -19.94 AsS + Sulfur -103.36 -118.39 -15.03 S + Thenardite -2.09 -2.27 -0.18 Na2SO4 + Thermonatrite -6.11 -5.99 0.12 Na2CO3:H2O + Trona -7.54 -8.34 -0.80 NaHCO3:Na2CO3:2H2O + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + USE solution 1 + EQUILIBRIUM_PHASES 1 + Dolomite 0.0 1.6 + Calcite 0.0 0.1 + SAVE solution 1 + SELECTED_OUTPUT + file ex14.sel + reset false + step + USER_PUNCH + heading m_Ca m_Mg m_Na umol_As pH + 10 PUNCH TOT("Ca"), TOT("Mg"), TOT("Na"), TOT("As")*1e6, -LA("H+") + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Brine +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e-01 1.020e-01 1.982e-03 + Dolomite 0.00 -17.09 -17.09 1.600e+00 1.599e+00 -7.679e-04 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 5.000e-08 5.000e-08 + C 3.514e-03 3.514e-03 + Ca 4.643e-01 4.643e-01 + Cl 6.642e+00 6.642e+00 + Mg 1.617e-01 1.617e-01 + Na 5.402e+00 5.402e+00 + S 4.725e-03 4.725e-03 + +----------------------------Description of solution---------------------------- + + pH = 5.350 Charge balance + pe = 15.308 Adjusted to redox equilibrium + Activity of water = 0.785 + Ionic strength = 7.269e+00 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.441e-03 + Total CO2 (mol/kg) = 3.514e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 4.107e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 4 + Total H = 1.110158e+02 + Total O = 5.553511e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.361e-06 4.471e-06 -5.196 -5.350 -0.153 + OH- 3.204e-10 1.757e-09 -9.494 -8.755 0.739 + H2O 5.551e+01 7.846e-01 1.744 -0.105 0.000 +As(3) 6.327e-33 + H3AsO3 6.326e-33 3.373e-32 -32.199 -31.472 0.727 + H2AsO3- 9.740e-37 5.341e-36 -36.011 -35.272 0.739 + H4AsO3+ 1.363e-38 7.471e-38 -37.866 -37.127 0.739 + HAsO3-2 0.000e+00 0.000e+00 -47.579 -44.623 2.956 + AsO3-3 0.000e+00 0.000e+00 -61.625 -54.973 6.652 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -300.727 -299.988 0.739 + As3S4(HS)2- 0.000e+00 0.000e+00 -892.885 -892.146 0.739 +As(5) 5.000e-08 + H2AsO4- 4.995e-08 2.739e-07 -7.301 -6.562 0.739 + H3AsO4 4.583e-11 2.443e-10 -10.339 -9.612 0.727 + HAsO4-2 4.687e-12 4.238e-09 -11.329 -8.373 2.956 + AsO4-3 4.733e-22 2.122e-15 -21.325 -14.673 6.652 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.632 -142.905 0.727 +C(4) 3.514e-03 + CO2 1.068e-03 5.694e-03 -2.971 -2.245 0.727 + HCO3- 7.680e-04 4.444e-04 -3.115 -3.352 -0.238 + CaHCO3+ 7.345e-04 4.028e-03 -3.134 -2.395 0.739 + MgHCO3+ 4.991e-04 2.737e-03 -3.302 -2.563 0.739 + NaHCO3 4.428e-04 2.361e-03 -3.354 -2.627 0.727 + CaCO3 1.041e-06 5.550e-06 -5.983 -5.256 0.727 + MgCO3 4.392e-07 2.341e-06 -6.357 -5.631 0.727 + NaCO3- 1.495e-07 8.199e-07 -6.825 -6.086 0.739 + CO3-2 4.158e-08 4.662e-09 -7.381 -8.331 -0.950 +Ca 4.643e-01 + Ca+2 4.619e-01 7.106e-01 -0.335 -0.148 0.187 + CaSO4 1.601e-03 8.538e-03 -2.796 -2.069 0.727 + CaHCO3+ 7.345e-04 4.028e-03 -3.134 -2.395 0.739 + CaCO3 1.041e-06 5.550e-06 -5.983 -5.256 0.727 + CaHSO4+ 4.078e-08 2.236e-07 -7.390 -6.650 0.739 + CaOH+ 3.774e-09 2.069e-08 -8.423 -7.684 0.739 +Cl 6.642e+00 + Cl- 6.642e+00 3.947e+00 0.822 0.596 -0.226 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -45.192 -44.465 0.727 +Mg 1.617e-01 + Mg+2 1.598e-01 5.263e-01 -0.796 -0.279 0.518 + MgSO4 1.394e-03 7.430e-03 -2.856 -2.129 0.727 + MgHCO3+ 4.991e-04 2.737e-03 -3.302 -2.563 0.739 + MgCO3 4.392e-07 2.341e-06 -6.357 -5.631 0.727 + MgOH+ 6.115e-08 3.353e-07 -7.214 -6.475 0.739 +Na 5.402e+00 + Na+ 5.401e+00 9.445e+00 0.732 0.975 0.243 + NaSO4- 5.199e-04 2.851e-03 -3.284 -2.545 0.739 + NaHCO3 4.428e-04 2.361e-03 -3.354 -2.627 0.727 + NaCO3- 1.495e-07 8.199e-07 -6.825 -6.086 0.739 +O(0) 8.206e-05 + O2 4.103e-05 2.188e-04 -4.387 -3.660 0.727 +S(-2) 0.000e+00 + H2S 0.000e+00 0.000e+00 -139.842 -139.115 0.727 + HS- 0.000e+00 0.000e+00 -141.447 -140.707 0.739 + S5-2 0.000e+00 0.000e+00 -144.480 -144.953 -0.473 + S4-2 0.000e+00 0.000e+00 -144.629 -145.187 -0.558 + S6-2 0.000e+00 0.000e+00 -144.829 -145.239 -0.410 + S3-2 0.000e+00 0.000e+00 -147.960 -148.640 -0.680 + S2-2 0.000e+00 0.000e+00 -149.073 -149.886 -0.813 + S-2 0.000e+00 0.000e+00 -151.232 -148.276 2.956 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -300.727 -299.988 0.739 + As3S4(HS)2- 0.000e+00 0.000e+00 -892.885 -892.146 0.739 +S(6) 4.725e-03 + CaSO4 1.601e-03 8.538e-03 -2.796 -2.069 0.727 + MgSO4 1.394e-03 7.430e-03 -2.856 -2.129 0.727 + SO4-2 1.210e-03 6.022e-05 -2.917 -4.220 -1.303 + NaSO4- 5.199e-04 2.851e-03 -3.284 -2.545 0.739 + CaHSO4+ 4.078e-08 2.236e-07 -7.390 -6.650 0.739 + HSO4- 4.774e-09 2.618e-08 -8.321 -7.582 0.739 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.01 -4.37 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Arsenolite -61.25 -62.63 -1.38 As2O3 + Artinite -8.32 1.28 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -27.14 -18.91 8.23 As2O5 + As2S3(am) -455.58 -500.48 -44.90 As2S3 + As_native -80.60 -93.13 -12.53 As + Brucite -6.63 10.21 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -11.31 -30.21 -18.91 Ca3(AsO4)2:4H2O + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -140.04 -142.90 -2.86 CH4 + Claudetite -61.29 -62.63 -1.34 As2O3 + CO2(g) -0.78 -2.24 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -3.10 -5.24 -2.14 MgSO4:7H2O + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -41.32 -44.47 -3.15 H2 + H2O(g) -1.62 -0.11 1.51 H2O + H2S(g) -138.12 -139.12 -1.00 H2S + Halite -0.01 1.57 1.58 NaCl + Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 + Hydromagnesite -15.89 -24.65 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.58 -8.61 -8.03 MgCO3 + Mirabilite -2.21 -3.32 -1.11 Na2SO4:10H2O + Nahcolite -1.83 -2.38 -0.55 NaHCO3 + Natron -6.12 -7.43 -1.31 Na2CO3:10H2O + Nesquehonite -3.31 -8.93 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -454.18 -500.48 -46.30 As2S3 + Portlandite -12.46 10.34 22.80 Ca(OH)2 + Realgar -177.93 -197.87 -19.94 AsS + Sulfur -102.63 -117.66 -15.03 S + Thenardite -2.09 -2.27 -0.18 Na2SO4 + Thermonatrite -6.61 -6.49 0.12 Na2CO3:H2O + Trona -8.17 -8.97 -0.80 NaHCO3:Na2CO3:2H2O + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + PRINT + selected_output false + EXCHANGE 1 + equilibrate with solution 1 + X 1.0 + SURFACE 1 + equilibrate solution 1 + Hfo_w 0.07 600. 30. + END +------------------------------------------------------- +Beginning of initial exchange-composition calculations. +------------------------------------------------------- + +Exchange 1. + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + NaX 9.355e-01 9.355e-01 9.355e-01 0.000 + CaX2 2.199e-02 4.398e-02 4.398e-02 0.000 + MgX2 1.028e-02 2.055e-02 2.055e-02 0.000 + HX 4.428e-06 4.428e-06 4.428e-06 0.000 + +------------------------------------------------------ +Beginning of initial surface-composition calculations. +------------------------------------------------------ + +Surface 1. + +Hfo + 6.234e-02 Surface charge, eq + 3.342e-01 sigma, C/m**2 + 4.729e-02 psi, V + -1.841e+00 -F*psi/RT + 1.587e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH2+ 6.388e-02 0.913 6.388e-02 -1.195 + Hfo_wOH 4.617e-03 0.066 4.616e-03 -2.336 + Hfo_wSO4- 6.015e-04 0.009 6.015e-04 -3.221 + Hfo_wHAsO4- 5.089e-04 0.007 5.089e-04 -3.293 + Hfo_wH2AsO4 2.279e-04 0.003 2.279e-04 -3.642 + Hfo_wOHAsO4-3 9.316e-05 0.001 9.316e-05 -4.031 + Hfo_wOHSO4-2 6.805e-05 0.001 6.805e-05 -4.167 + Hfo_wO- 7.643e-06 0.000 7.643e-06 -5.117 + Hfo_wOCa+ 1.165e-13 0.000 1.165e-13 -12.934 + Hfo_wOMg+ 8.626e-14 0.000 8.626e-14 -13.064 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + SOLUTION 0 20 x precipitation + pH 4.6 + pe 4.0 O2(g) -0.7 + temp 25. + units mmol/kgw + Ca .191625 + Mg .035797 + Na .122668 + Cl .133704 + C .01096 + S .235153 charge + EQUILIBRIUM_PHASES 0 + Dolomite 0.0 1.6 + Calcite 0.0 0.1 + CO2(g) -1.5 10. + SAVE solution 0 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. 20 x precipitation + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.096e-05 1.096e-05 + Ca 1.916e-04 1.916e-04 + Cl 1.337e-04 1.337e-04 + Mg 3.580e-05 3.580e-05 + Na 1.227e-04 1.227e-04 + S 2.351e-04 2.351e-04 Charge balance + +----------------------------Description of solution---------------------------- + + pH = 4.600 + pe = 16.005 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.035e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -2.630e-05 + Total CO2 (mol/kg) = 1.096e-05 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.119e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 9 + Total H = 1.110125e+02 + Total O = 5.550762e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.600e-05 2.512e-05 -4.585 -4.600 -0.015 + OH- 4.132e-10 3.985e-10 -9.384 -9.400 -0.016 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -145.418 -145.418 0.000 +C(4) 1.096e-05 + CO2 1.076e-05 1.076e-05 -4.968 -4.968 0.000 + HCO3- 1.975e-07 1.906e-07 -6.704 -6.720 -0.015 + CaHCO3+ 4.049e-10 3.905e-10 -9.393 -9.408 -0.016 + MgHCO3+ 6.905e-11 6.660e-11 -10.161 -10.177 -0.016 + NaHCO3 1.267e-11 1.267e-11 -10.897 -10.897 0.000 + CO3-2 4.105e-13 3.559e-13 -12.387 -12.449 -0.062 + CaCO3 9.575e-14 9.577e-14 -13.019 -13.019 0.000 + MgCO3 1.014e-14 1.014e-14 -13.994 -13.994 0.000 + NaCO3- 8.122e-16 7.833e-16 -15.090 -15.106 -0.016 +Ca 1.916e-04 + Ca+2 1.853e-04 1.606e-04 -3.732 -3.794 -0.062 + CaSO4 6.296e-06 6.297e-06 -5.201 -5.201 0.000 + CaHSO4+ 9.608e-10 9.267e-10 -9.017 -9.033 -0.016 + CaHCO3+ 4.049e-10 3.905e-10 -9.393 -9.408 -0.016 + CaOH+ 1.100e-12 1.061e-12 -11.958 -11.974 -0.016 + CaCO3 9.575e-14 9.577e-14 -13.019 -13.019 0.000 +Cl 1.337e-04 + Cl- 1.337e-04 1.289e-04 -3.874 -3.890 -0.016 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 +Mg 3.580e-05 + Mg+2 3.442e-05 2.986e-05 -4.463 -4.525 -0.062 + MgSO4 1.375e-06 1.375e-06 -5.862 -5.862 0.000 + MgHCO3+ 6.905e-11 6.660e-11 -10.161 -10.177 -0.016 + MgOH+ 4.475e-12 4.316e-12 -11.349 -11.365 -0.016 + MgCO3 1.014e-14 1.014e-14 -13.994 -13.994 0.000 +Na 1.227e-04 + Na+ 1.225e-04 1.182e-04 -3.912 -3.927 -0.016 + NaSO4- 1.207e-07 1.164e-07 -6.918 -6.934 -0.016 + NaHCO3 1.267e-11 1.267e-11 -10.897 -10.897 0.000 + NaCO3- 8.122e-16 7.833e-16 -15.090 -15.106 -0.016 +O(0) 4.374e-04 + O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 +S(-2) 0.000e+00 + H2S 0.000e+00 0.000e+00 -137.103 -137.103 0.000 + HS- 0.000e+00 0.000e+00 -139.429 -139.444 -0.016 + S5-2 0.000e+00 0.000e+00 -144.381 -144.439 -0.058 + S4-2 0.000e+00 0.000e+00 -144.614 -144.673 -0.059 + S6-2 0.000e+00 0.000e+00 -144.668 -144.725 -0.057 + S-2 0.000e+00 0.000e+00 -147.700 -147.762 -0.063 + S3-2 0.000e+00 0.000e+00 -148.066 -148.126 -0.060 + S2-2 0.000e+00 0.000e+00 -149.311 -149.372 -0.061 +S(6) 2.351e-04 + SO4-2 2.268e-04 1.965e-04 -3.644 -3.707 -0.062 + CaSO4 6.296e-06 6.297e-06 -5.201 -5.201 0.000 + MgSO4 1.375e-06 1.375e-06 -5.862 -5.862 0.000 + HSO4- 4.975e-07 4.798e-07 -6.303 -6.319 -0.016 + NaSO4- 1.207e-07 1.164e-07 -6.918 -6.934 -0.016 + CaHSO4+ 9.608e-10 9.267e-10 -9.017 -9.033 -0.016 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.14 -7.50 -4.36 CaSO4 + Aragonite -7.91 -16.24 -8.34 CaCO3 + Artinite -21.90 -12.30 9.60 MgCO3:Mg(OH)2:3H2O + Brucite -12.16 4.68 16.84 Mg(OH)2 + Calcite -7.76 -16.24 -8.48 CaCO3 + CH4(g) -142.56 -145.42 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Dolomite -16.13 -33.22 -17.09 CaMg(CO3)2 + Dolomite(d) -16.68 -33.22 -16.54 CaMg(CO3)2 + Epsomite -6.09 -8.23 -2.14 MgSO4:7H2O + Gypsum -2.92 -7.50 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -136.11 -137.10 -1.00 H2S + Halite -9.40 -7.82 1.58 NaCl + Huntite -37.20 -67.16 -29.97 CaMg3(CO3)4 + Hydromagnesite -54.46 -63.22 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -8.94 -16.97 -8.03 MgCO3 + Mirabilite -10.45 -11.56 -1.11 Na2SO4:10H2O + Nahcolite -10.10 -10.65 -0.55 NaHCO3 + Natron -18.99 -20.30 -1.31 Na2CO3:10H2O + Nesquehonite -11.35 -16.97 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Portlandite -17.39 5.41 22.80 Ca(OH)2 + Sulfur -100.73 -115.75 -15.03 S + Thenardite -11.38 -11.56 -0.18 Na2SO4 + Thermonatrite -20.43 -20.30 0.12 Na2CO3:H2O + Trona -30.16 -30.95 -0.80 NaHCO3:Na2CO3:2H2O + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 0. 20 x precipitation +Using pure phase assemblage 0. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e-01 9.966e-02 -3.443e-04 + CO2(g) -1.50 -19.65 -18.15 1.000e+01 9.996e+00 -4.067e-03 + Dolomite 0.00 -17.09 -17.09 1.600e+00 1.599e+00 -1.349e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 7.120e-03 7.119e-03 + Ca 1.885e-03 1.885e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.385e-03 1.384e-03 + Na 1.227e-04 1.227e-04 + S 2.351e-04 2.351e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.047 Charge balance + pe = 13.558 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.629e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.057e-03 + Total CO2 (mol/kg) = 7.120e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.173e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 16 + Total H = 1.110125e+02 + Total O = 5.552487e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.234e-07 1.115e-07 -6.909 -6.953 -0.044 + H+ 9.814e-08 8.977e-08 -7.008 -7.047 -0.039 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.421 -143.420 0.001 +C(4) 7.120e-03 + HCO3- 5.883e-03 5.333e-03 -2.230 -2.273 -0.043 + CO2 1.074e-03 1.077e-03 -2.969 -2.968 0.001 + CaHCO3+ 8.950e-05 8.087e-05 -4.048 -4.092 -0.044 + MgHCO3+ 6.082e-05 5.496e-05 -4.216 -4.260 -0.044 + CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 + CO3-2 4.124e-06 2.786e-06 -5.385 -5.555 -0.170 + MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 + NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 + NaCO3- 6.351e-09 5.738e-09 -8.197 -8.241 -0.044 +Ca 1.885e-03 + Ca+2 1.761e-03 1.189e-03 -2.754 -2.925 -0.171 + CaHCO3+ 8.950e-05 8.087e-05 -4.048 -4.092 -0.044 + CaSO4 2.881e-05 2.887e-05 -4.540 -4.539 0.001 + CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 + CaOH+ 2.432e-09 2.198e-09 -8.614 -8.658 -0.044 + CaHSO4+ 1.681e-11 1.518e-11 -10.775 -10.819 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.385e-03 + Mg+2 1.296e-03 8.806e-04 -2.887 -3.055 -0.168 + MgHCO3+ 6.082e-05 5.496e-05 -4.216 -4.260 -0.044 + MgSO4 2.507e-05 2.513e-05 -4.601 -4.600 0.001 + MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 + MgOH+ 3.941e-08 3.561e-08 -7.404 -7.448 -0.044 +Na 1.227e-04 + Na+ 1.223e-04 1.106e-04 -3.913 -3.956 -0.044 + NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 + NaSO4- 7.467e-08 6.747e-08 -7.127 -7.171 -0.044 + NaCO3- 6.351e-09 5.738e-09 -8.197 -8.241 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.057 -142.101 -0.044 + H2S 0.000e+00 0.000e+00 -142.207 -142.206 0.001 + S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 + S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 + S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 + S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 + S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 + S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 +S(6) 2.351e-04 + SO4-2 1.811e-04 1.217e-04 -3.742 -3.915 -0.173 + CaSO4 2.881e-05 2.887e-05 -4.540 -4.539 0.001 + MgSO4 2.507e-05 2.513e-05 -4.601 -4.600 0.001 + NaSO4- 7.467e-08 6.747e-08 -7.127 -7.171 -0.044 + HSO4- 1.176e-09 1.062e-09 -8.930 -8.974 -0.044 + CaHSO4+ 1.681e-11 1.518e-11 -10.775 -10.819 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.48 -6.84 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Artinite -7.17 2.43 9.60 MgCO3:Mg(OH)2:3H2O + Brucite -5.80 11.04 16.84 Mg(OH)2 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -140.56 -143.42 -2.86 CH4 + CO2(g) -1.50 -2.97 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.83 -6.97 -2.14 MgSO4:7H2O + Gypsum -2.26 -6.84 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.21 -142.21 -1.00 H2S + Halite -9.46 -7.87 1.58 NaCl + Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.64 -23.40 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.58 -8.61 -8.03 MgCO3 + Mirabilite -10.71 -11.83 -1.11 Na2SO4:10H2O + Nahcolite -5.68 -6.23 -0.55 NaHCO3 + Natron -12.16 -13.47 -1.31 Na2CO3:10H2O + Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Portlandite -11.63 11.17 22.80 Ca(OH)2 + Sulfur -105.83 -120.86 -15.03 S + Thenardite -11.65 -11.83 -0.18 Na2SO4 + Thermonatrite -13.59 -13.47 0.12 Na2CO3:H2O + Trona -18.90 -19.70 -0.80 NaHCO3:Na2CO3:2H2O + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 5. +------------------------------------ + + PRINT + selected_output true + ADVECTION + cells 1 + shifts 200 + print_frequency 20 + END +------------------------------------ +Beginning of advection calculations. +------------------------------------ + +Beginning of advection time step 1, cumulative pore volumes 1.000000. +Beginning of advection time step 2, cumulative pore volumes 2.000000. +Beginning of advection time step 3, cumulative pore volumes 3.000000. +Beginning of advection time step 4, cumulative pore volumes 4.000000. +Beginning of advection time step 5, cumulative pore volumes 5.000000. +Beginning of advection time step 6, cumulative pore volumes 6.000000. +Beginning of advection time step 7, cumulative pore volumes 7.000000. +Beginning of advection time step 8, cumulative pore volumes 8.000000. +Beginning of advection time step 9, cumulative pore volumes 9.000000. +Beginning of advection time step 10, cumulative pore volumes 10.000000. +Beginning of advection time step 11, cumulative pore volumes 11.000000. +Beginning of advection time step 12, cumulative pore volumes 12.000000. +Beginning of advection time step 13, cumulative pore volumes 13.000000. +Beginning of advection time step 14, cumulative pore volumes 14.000000. +Beginning of advection time step 15, cumulative pore volumes 15.000000. +Beginning of advection time step 16, cumulative pore volumes 16.000000. +Beginning of advection time step 17, cumulative pore volumes 17.000000. +Beginning of advection time step 18, cumulative pore volumes 18.000000. +Beginning of advection time step 19, cumulative pore volumes 19.000000. +Beginning of advection time step 20, cumulative pore volumes 20.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 5.212e-02 5.085e-02 -1.272e-03 + Dolomite 0.00 -17.09 -17.09 1.576e+00 1.575e+00 -1.774e-04 + +------------------------------Surface composition------------------------------ + +Hfo + -2.907e-03 Surface charge, eq + -1.559e-02 sigma, C/m**2 + -5.497e-02 psi, V + 2.140e+00 -F*psi/RT + 8.498e+00 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.310e-02 0.759 5.310e-02 -1.275 + Hfo_wO- 8.255e-03 0.118 8.256e-03 -2.083 + Hfo_wOH2+ 7.823e-03 0.112 7.824e-03 -2.107 + Hfo_wOHAsO4-3 8.244e-04 0.012 8.245e-04 -3.084 + Hfo_wOHSO4-2 6.801e-07 0.000 6.802e-07 -6.167 + Hfo_wHAsO4- 4.008e-07 0.000 4.008e-07 -6.397 + Hfo_wSO4- 5.024e-08 0.000 5.024e-08 -7.299 + Hfo_wH2AsO4 1.911e-09 0.000 1.911e-09 -8.719 + Hfo_wOCa+ 4.391e-12 0.000 4.391e-12 -11.357 + Hfo_wOMg+ 3.252e-12 0.000 3.252e-12 -11.488 + Hfo_wH2AsO3 4.273e-34 0.000 4.274e-34 -33.369 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + NaX 6.110e-01 6.110e-01 6.110e-01 -0.000 + CaX2 1.325e-01 2.651e-01 2.651e-01 -0.000 + MgX2 6.194e-02 1.239e-01 1.239e-01 -0.000 + HX 6.196e-07 6.196e-07 6.196e-07 -0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.542e-07 1.542e-07 + C 8.747e-03 8.746e-03 + Ca 1.972e-05 1.972e-05 + Cl 1.337e-04 1.337e-04 + Mg 1.279e-05 1.279e-05 + Na 9.850e-03 9.850e-03 + S 2.350e-04 2.350e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.051 Charge balance + pe = 11.554 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.065e-02 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 9.399e-03 + Total CO2 (mol/kg) = 8.747e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -8.721e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.44 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.552976e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.251e-05 1.125e-05 -4.903 -4.949 -0.046 + H+ 9.756e-10 8.892e-10 -9.011 -9.051 -0.040 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +As(3) 5.893e-38 + H3AsO3 3.122e-38 3.130e-38 -37.506 -37.504 0.001 + H2AsO3- 2.771e-38 2.492e-38 -37.557 -37.603 -0.046 + HAsO3-2 0.000e+00 0.000e+00 -43.068 -43.252 -0.184 + H4AsO3+ 0.000e+00 0.000e+00 -46.814 -46.860 -0.046 + AsO3-3 0.000e+00 0.000e+00 -49.487 -49.901 -0.414 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -316.500 -316.546 -0.046 + As3S4(HS)2- 0.000e+00 0.000e+00 -949.494 -949.540 -0.046 +As(5) 1.542e-07 + HAsO4-2 1.521e-07 9.955e-08 -6.818 -7.002 -0.184 + H2AsO4- 1.423e-09 1.280e-09 -8.847 -8.893 -0.046 + AsO4-3 6.505e-10 2.506e-10 -9.187 -9.601 -0.414 + H3AsO4 2.265e-16 2.270e-16 -15.645 -15.644 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -145.291 -145.290 0.001 +C(4) 8.747e-03 + HCO3- 8.041e-03 7.259e-03 -2.095 -2.139 -0.044 + CO3-2 5.765e-04 3.828e-04 -3.239 -3.417 -0.178 + NaCO3- 6.950e-05 6.252e-05 -4.158 -4.204 -0.046 + NaHCO3 3.571e-05 3.580e-05 -4.447 -4.446 0.001 + CO2 1.448e-05 1.452e-05 -4.839 -4.838 0.001 + CaCO3 5.536e-06 5.550e-06 -5.257 -5.256 0.001 + MgCO3 2.336e-06 2.341e-06 -5.632 -5.631 0.001 + CaHCO3+ 8.907e-07 8.011e-07 -6.050 -6.096 -0.046 + MgHCO3+ 6.052e-07 5.444e-07 -6.218 -6.264 -0.046 +Ca 1.972e-05 + Ca+2 1.304e-05 8.653e-06 -4.885 -5.063 -0.178 + CaCO3 5.536e-06 5.550e-06 -5.257 -5.256 0.001 + CaHCO3+ 8.907e-07 8.011e-07 -6.050 -6.096 -0.046 + CaSO4 2.584e-07 2.590e-07 -6.588 -6.587 0.001 + CaOH+ 1.795e-09 1.614e-09 -8.746 -8.792 -0.046 + CaHSO4+ 1.500e-15 1.349e-15 -14.824 -14.870 -0.046 +Cl 1.337e-04 + Cl- 1.337e-04 1.200e-04 -3.874 -3.921 -0.047 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.362 -44.361 0.001 +Mg 1.279e-05 + Mg+2 9.592e-06 6.409e-06 -5.018 -5.193 -0.175 + MgCO3 2.336e-06 2.341e-06 -5.632 -5.631 0.001 + MgHCO3+ 6.052e-07 5.444e-07 -6.218 -6.264 -0.046 + MgSO4 2.249e-07 2.254e-07 -6.648 -6.647 0.001 + MgOH+ 2.909e-08 2.616e-08 -7.536 -7.582 -0.046 +Na 9.850e-03 + Na+ 9.738e-03 8.769e-03 -2.012 -2.057 -0.045 + NaCO3- 6.950e-05 6.252e-05 -4.158 -4.204 -0.046 + NaHCO3 3.571e-05 3.580e-05 -4.447 -4.446 0.001 + NaSO4- 7.331e-06 6.594e-06 -5.135 -5.181 -0.046 +O(0) 4.375e-04 + O2 2.187e-04 2.193e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -143.968 -144.014 -0.046 + S5-2 0.000e+00 0.000e+00 -144.409 -144.559 -0.149 + S4-2 0.000e+00 0.000e+00 -144.635 -144.793 -0.157 + S6-2 0.000e+00 0.000e+00 -144.702 -144.845 -0.143 + H2S 0.000e+00 0.000e+00 -146.125 -146.124 0.001 + S-2 0.000e+00 0.000e+00 -147.697 -147.882 -0.184 + S3-2 0.000e+00 0.000e+00 -148.080 -148.246 -0.165 + S2-2 0.000e+00 0.000e+00 -149.319 -149.492 -0.172 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -316.500 -316.546 -0.046 + As3S4(HS)2- 0.000e+00 0.000e+00 -949.494 -949.540 -0.046 +S(6) 2.350e-04 + SO4-2 2.272e-04 1.500e-04 -3.644 -3.824 -0.180 + NaSO4- 7.331e-06 6.594e-06 -5.135 -5.181 -0.046 + CaSO4 2.584e-07 2.590e-07 -6.588 -6.587 0.001 + MgSO4 2.249e-07 2.254e-07 -6.648 -6.647 0.001 + HSO4- 1.442e-11 1.297e-11 -10.841 -10.887 -0.046 + CaHSO4+ 1.500e-15 1.349e-15 -14.824 -14.870 -0.046 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -4.53 -8.89 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Arsenolite -73.63 -75.01 -1.38 As2O3 + Artinite -5.30 4.30 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -39.52 -31.29 8.23 As2O5 + As2S3(am) -489.30 -534.20 -44.90 As2S3 + As_native -86.79 -99.32 -12.53 As + Brucite -3.93 12.91 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -15.49 -34.39 -18.91 Ca3(AsO4)2:4H2O + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -142.43 -145.29 -2.86 CH4 + Claudetite -73.67 -75.01 -1.34 As2O3 + CO2(g) -3.37 -4.84 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -6.88 -9.02 -2.14 MgSO4:7H2O + Gypsum -4.31 -8.89 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -145.13 -146.12 -1.00 H2S + Halite -7.56 -5.98 1.58 NaCl + Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 + Hydromagnesite -12.77 -21.53 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.58 -8.61 -8.03 MgCO3 + Mirabilite -6.83 -7.94 -1.11 Na2SO4:10H2O + Nahcolite -3.65 -4.20 -0.55 NaHCO3 + Natron -6.22 -7.53 -1.31 Na2CO3:10H2O + Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -487.90 -534.20 -46.30 As2S3 + Portlandite -9.76 13.04 22.80 Ca(OH)2 + Realgar -191.23 -211.17 -19.94 AsS + Sulfur -109.75 -124.77 -15.03 S + Thenardite -7.76 -7.94 -0.18 Na2SO4 + Thermonatrite -7.66 -7.53 0.12 Na2CO3:H2O + Trona -10.93 -11.73 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 21, cumulative pore volumes 21.000000. +Beginning of advection time step 22, cumulative pore volumes 22.000000. +Beginning of advection time step 23, cumulative pore volumes 23.000000. +Beginning of advection time step 24, cumulative pore volumes 24.000000. +Beginning of advection time step 25, cumulative pore volumes 25.000000. +Beginning of advection time step 26, cumulative pore volumes 26.000000. +Beginning of advection time step 27, cumulative pore volumes 27.000000. +Beginning of advection time step 28, cumulative pore volumes 28.000000. +Beginning of advection time step 29, cumulative pore volumes 29.000000. +Beginning of advection time step 30, cumulative pore volumes 30.000000. +Beginning of advection time step 31, cumulative pore volumes 31.000000. +Beginning of advection time step 32, cumulative pore volumes 32.000000. +Beginning of advection time step 33, cumulative pore volumes 33.000000. +Beginning of advection time step 34, cumulative pore volumes 34.000000. +Beginning of advection time step 35, cumulative pore volumes 35.000000. +Beginning of advection time step 36, cumulative pore volumes 36.000000. +Beginning of advection time step 37, cumulative pore volumes 37.000000. +Beginning of advection time step 38, cumulative pore volumes 38.000000. +Beginning of advection time step 39, cumulative pore volumes 39.000000. +Beginning of advection time step 40, cumulative pore volumes 40.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 2.832e-02 2.720e-02 -1.117e-03 + Dolomite -0.00 -17.09 -17.09 1.573e+00 1.573e+00 -5.221e-05 + +------------------------------Surface composition------------------------------ + +Hfo + -1.480e-03 Surface charge, eq + -7.936e-03 sigma, C/m**2 + -3.318e-02 psi, V + 1.291e+00 -F*psi/RT + 3.638e+00 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.308e-02 0.758 5.308e-02 -1.275 + Hfo_wOH2+ 8.547e-03 0.122 8.548e-03 -2.068 + Hfo_wO- 7.550e-03 0.108 7.551e-03 -2.122 + Hfo_wOHAsO4-3 8.229e-04 0.012 8.229e-04 -3.085 + Hfo_wOHSO4-2 3.772e-06 0.000 3.772e-06 -5.423 + Hfo_wHAsO4- 4.779e-07 0.000 4.779e-07 -6.321 + Hfo_wSO4- 3.045e-07 0.000 3.046e-07 -6.516 + Hfo_wH2AsO4 2.490e-09 0.000 2.490e-09 -8.604 + Hfo_wOCa+ 1.877e-12 0.000 1.877e-12 -11.727 + Hfo_wOMg+ 1.390e-12 0.000 1.390e-12 -11.857 + Hfo_wH2AsO3 5.569e-34 0.000 5.569e-34 -33.254 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + NaX 4.267e-01 4.267e-01 4.267e-01 -0.000 + CaX2 1.954e-01 3.907e-01 3.907e-01 -0.000 + MgX2 9.130e-02 1.826e-01 1.826e-01 -0.000 + HX 1.203e-06 1.203e-06 1.203e-06 -0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 3.060e-08 3.059e-08 + C 8.341e-03 8.341e-03 + Ca 4.111e-05 4.111e-05 + Cl 1.337e-04 1.337e-04 + Mg 2.852e-05 2.851e-05 + Na 8.966e-03 8.965e-03 + S 2.347e-04 2.347e-04 + +----------------------------Description of solution---------------------------- + + pH = 8.644 Charge balance + pe = 11.961 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.555e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 8.564e-03 + Total CO2 (mol/kg) = 8.341e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.232e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.34 + Iterations = 12 + Total H = 1.110124e+02 + Total O = 5.552854e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.877e-06 4.408e-06 -5.312 -5.356 -0.044 + H+ 2.481e-09 2.270e-09 -8.605 -8.644 -0.039 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +As(3) 5.480e-38 + H3AsO3 4.072e-38 4.081e-38 -37.390 -37.389 0.001 + H2AsO3- 1.408e-38 1.273e-38 -37.851 -37.895 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -43.776 -43.951 -0.176 + H4AsO3+ 0.000e+00 0.000e+00 -46.294 -46.338 -0.044 + AsO3-3 0.000e+00 0.000e+00 -50.612 -51.008 -0.395 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -315.151 -315.195 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -944.628 -944.672 -0.044 +As(5) 3.060e-08 + HAsO4-2 2.983e-08 1.991e-08 -7.525 -7.701 -0.176 + H2AsO4- 7.228e-10 6.533e-10 -9.141 -9.185 -0.044 + AsO4-3 4.875e-11 1.963e-11 -10.312 -10.707 -0.395 + H3AsO4 2.953e-16 2.959e-16 -15.530 -15.529 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -144.883 -144.882 0.001 +C(4) 8.341e-03 + HCO3- 8.013e-03 7.267e-03 -2.096 -2.139 -0.042 + CO3-2 2.219e-04 1.501e-04 -3.654 -3.824 -0.170 + CO2 3.702e-05 3.711e-05 -4.432 -4.431 0.001 + NaHCO3 3.284e-05 3.292e-05 -4.484 -4.483 0.001 + NaCO3- 2.491e-05 2.251e-05 -4.604 -4.648 -0.044 + CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 + MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 + CaHCO3+ 2.263e-06 2.045e-06 -5.645 -5.689 -0.044 + MgHCO3+ 1.538e-06 1.390e-06 -5.813 -5.857 -0.044 +Ca 4.111e-05 + Ca+2 3.264e-05 2.207e-05 -4.486 -4.656 -0.170 + CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 + CaHCO3+ 2.263e-06 2.045e-06 -5.645 -5.689 -0.044 + CaSO4 6.701e-07 6.716e-07 -6.174 -6.173 0.001 + CaOH+ 1.784e-09 1.613e-09 -8.749 -8.792 -0.044 + CaHSO4+ 9.883e-15 8.933e-15 -14.005 -14.049 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.207e-04 -3.874 -3.918 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.362 -44.361 0.001 +Mg 2.852e-05 + Mg+2 2.403e-05 1.635e-05 -4.619 -4.787 -0.167 + MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 + MgHCO3+ 1.538e-06 1.390e-06 -5.813 -5.857 -0.044 + MgSO4 5.832e-07 5.845e-07 -6.234 -6.233 0.001 + MgOH+ 2.891e-08 2.613e-08 -7.539 -7.583 -0.044 +Na 8.966e-03 + Na+ 8.901e-03 8.054e-03 -2.051 -2.094 -0.043 + NaHCO3 3.284e-05 3.292e-05 -4.484 -4.483 0.001 + NaCO3- 2.491e-05 2.251e-05 -4.604 -4.648 -0.044 + NaSO4- 6.812e-06 6.158e-06 -5.167 -5.211 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -143.556 -143.600 -0.044 + S5-2 0.000e+00 0.000e+00 -144.407 -144.551 -0.144 + S4-2 0.000e+00 0.000e+00 -144.634 -144.785 -0.151 + S6-2 0.000e+00 0.000e+00 -144.700 -144.837 -0.137 + H2S 0.000e+00 0.000e+00 -145.303 -145.302 0.001 + S-2 0.000e+00 0.000e+00 -147.699 -147.874 -0.176 + S3-2 0.000e+00 0.000e+00 -148.080 -148.238 -0.158 + S2-2 0.000e+00 0.000e+00 -149.319 -149.484 -0.165 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -315.151 -315.195 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -944.628 -944.672 -0.044 +S(6) 2.347e-04 + SO4-2 2.266e-04 1.525e-04 -3.645 -3.817 -0.172 + NaSO4- 6.812e-06 6.158e-06 -5.167 -5.211 -0.044 + CaSO4 6.701e-07 6.716e-07 -6.174 -6.173 0.001 + MgSO4 5.832e-07 5.845e-07 -6.234 -6.233 0.001 + HSO4- 3.725e-11 3.367e-11 -10.429 -10.473 -0.044 + CaHSO4+ 9.883e-15 8.933e-15 -14.005 -14.049 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -4.11 -8.47 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Arsenolite -73.40 -74.78 -1.38 As2O3 + Artinite -5.71 3.89 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -39.29 -31.06 8.23 As2O5 + As2S3(am) -486.61 -531.51 -44.90 As2S3 + As_native -86.67 -99.20 -12.53 As + Brucite -4.34 12.50 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -16.48 -35.38 -18.91 Ca3(AsO4)2:4H2O + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -142.02 -144.88 -2.86 CH4 + Claudetite -73.44 -74.78 -1.34 As2O3 + CO2(g) -2.96 -4.43 -1.47 CO2 + Dolomite -0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -6.46 -8.60 -2.14 MgSO4:7H2O + Gypsum -3.89 -8.47 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -144.31 -145.30 -1.00 H2S + Halite -7.59 -6.01 1.58 NaCl + Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 + Hydromagnesite -13.18 -21.94 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.58 -8.61 -8.03 MgCO3 + Mirabilite -6.89 -8.01 -1.11 Na2SO4:10H2O + Nahcolite -3.68 -4.23 -0.55 NaHCO3 + Natron -6.70 -8.01 -1.31 Na2CO3:10H2O + Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -485.21 -531.51 -46.30 As2S3 + Portlandite -10.17 12.63 22.80 Ca(OH)2 + Realgar -190.29 -210.24 -19.94 AsS + Sulfur -108.93 -123.95 -15.03 S + Thenardite -7.83 -8.00 -0.18 Na2SO4 + Thermonatrite -8.14 -8.01 0.12 Na2CO3:H2O + Trona -11.45 -12.24 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 41, cumulative pore volumes 41.000000. +Beginning of advection time step 42, cumulative pore volumes 42.000000. +Beginning of advection time step 43, cumulative pore volumes 43.000000. +Beginning of advection time step 44, cumulative pore volumes 44.000000. +Beginning of advection time step 45, cumulative pore volumes 45.000000. +Beginning of advection time step 46, cumulative pore volumes 46.000000. +Beginning of advection time step 47, cumulative pore volumes 47.000000. +Beginning of advection time step 48, cumulative pore volumes 48.000000. +Beginning of advection time step 49, cumulative pore volumes 49.000000. +Beginning of advection time step 50, cumulative pore volumes 50.000000. +Beginning of advection time step 51, cumulative pore volumes 51.000000. +Beginning of advection time step 52, cumulative pore volumes 52.000000. +Beginning of advection time step 53, cumulative pore volumes 53.000000. +Beginning of advection time step 54, cumulative pore volumes 54.000000. +Beginning of advection time step 55, cumulative pore volumes 55.000000. +Beginning of advection time step 56, cumulative pore volumes 56.000000. +Beginning of advection time step 57, cumulative pore volumes 57.000000. +Beginning of advection time step 58, cumulative pore volumes 58.000000. +Beginning of advection time step 59, cumulative pore volumes 59.000000. +Beginning of advection time step 60, cumulative pore volumes 60.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 7.030e-03 6.028e-03 -1.002e-03 + Dolomite 0.00 -17.09 -17.09 1.573e+00 1.573e+00 1.267e-05 + +------------------------------Surface composition------------------------------ + +Hfo + -2.886e-04 Surface charge, eq + -1.547e-03 sigma, C/m**2 + -7.102e-03 psi, V + 2.764e-01 -F*psi/RT + 1.318e+00 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.296e-02 0.757 5.296e-02 -1.276 + Hfo_wOH2+ 9.213e-03 0.132 9.213e-03 -2.036 + Hfo_wO- 6.974e-03 0.100 6.975e-03 -2.156 + Hfo_wOHAsO4-3 8.225e-04 0.012 8.226e-04 -3.085 + Hfo_wOHSO4-2 2.832e-05 0.000 2.833e-05 -4.548 + Hfo_wSO4- 2.470e-06 0.000 2.470e-06 -5.607 + Hfo_wHAsO4- 5.574e-07 0.000 5.574e-07 -6.254 + Hfo_wH2AsO4 3.138e-09 0.000 3.138e-09 -8.503 + Hfo_wOCa+ 6.903e-13 0.000 6.904e-13 -12.161 + Hfo_wOMg+ 5.113e-13 0.000 5.114e-13 -12.291 + Hfo_wH2AsO3 7.018e-34 0.000 7.018e-34 -33.154 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + NaX 2.571e-01 2.571e-01 2.571e-01 0.000 + CaX2 2.531e-01 5.063e-01 5.063e-01 0.000 + MgX2 1.183e-01 2.366e-01 2.366e-01 0.000 + HX 2.343e-06 2.343e-06 2.343e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 4.506e-09 4.505e-09 + C 8.097e-03 8.096e-03 + Ca 1.123e-04 1.123e-04 + Cl 1.337e-04 1.337e-04 + Mg 8.089e-05 8.089e-05 + Na 8.229e-03 8.229e-03 + S 2.318e-04 2.318e-04 + +----------------------------Description of solution---------------------------- + + pH = 8.170 Charge balance + pe = 12.436 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.032e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 8.078e-03 + Total CO2 (mol/kg) = 8.097e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.959e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.35 + Iterations = 11 + Total H = 1.110124e+02 + Total O = 5.552779e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.632e-06 1.479e-06 -5.787 -5.830 -0.043 + H+ 7.382e-09 6.767e-09 -8.132 -8.170 -0.038 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +As(3) 5.738e-38 + H3AsO3 5.143e-38 5.154e-38 -37.289 -37.288 0.001 + H2AsO3- 5.950e-39 5.392e-39 -38.225 -38.268 -0.043 + HAsO3-2 0.000e+00 0.000e+00 -44.627 -44.799 -0.171 + H4AsO3+ 0.000e+00 0.000e+00 -45.720 -45.762 -0.043 + AsO3-3 0.000e+00 0.000e+00 -51.944 -52.329 -0.385 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -313.638 -313.680 -0.043 + As3S4(HS)2- 0.000e+00 0.000e+00 -939.137 -939.180 -0.043 +As(5) 4.506e-09 + HAsO4-2 4.198e-09 2.830e-09 -8.377 -8.548 -0.171 + H2AsO4- 3.055e-10 2.768e-10 -9.515 -9.558 -0.043 + AsO4-3 2.274e-12 9.362e-13 -11.643 -12.029 -0.385 + H3AsO4 3.729e-16 3.737e-16 -15.428 -15.427 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -144.416 -144.415 0.001 +C(4) 8.097e-03 + HCO3- 7.859e-03 7.144e-03 -2.105 -2.146 -0.041 + CO2 1.085e-04 1.087e-04 -3.965 -3.964 0.001 + CO3-2 7.251e-05 4.951e-05 -4.140 -4.305 -0.166 + NaHCO3 2.977e-05 2.983e-05 -4.526 -4.525 0.001 + NaCO3- 7.555e-06 6.846e-06 -5.122 -5.165 -0.043 + CaHCO3+ 6.728e-06 6.097e-06 -5.172 -5.215 -0.043 + CaCO3 5.538e-06 5.550e-06 -5.257 -5.256 0.001 + MgHCO3+ 4.572e-06 4.143e-06 -5.340 -5.383 -0.043 + MgCO3 2.337e-06 2.341e-06 -5.631 -5.631 0.001 +Ca 1.123e-04 + Ca+2 9.805e-05 6.691e-05 -4.009 -4.175 -0.166 + CaHCO3+ 6.728e-06 6.097e-06 -5.172 -5.215 -0.043 + CaCO3 5.538e-06 5.550e-06 -5.257 -5.256 0.001 + CaSO4 2.008e-06 2.013e-06 -5.697 -5.696 0.001 + CaOH+ 1.810e-09 1.640e-09 -8.742 -8.785 -0.043 + CaHSO4+ 8.806e-14 7.979e-14 -13.055 -13.098 -0.043 +Cl 1.337e-04 + Cl- 1.337e-04 1.210e-04 -3.874 -3.917 -0.044 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 8.089e-05 + Mg+2 7.221e-05 4.956e-05 -4.141 -4.305 -0.163 + MgHCO3+ 4.572e-06 4.143e-06 -5.340 -5.383 -0.043 + MgCO3 2.337e-06 2.341e-06 -5.631 -5.631 0.001 + MgSO4 1.748e-06 1.752e-06 -5.757 -5.757 0.001 + MgOH+ 2.934e-08 2.658e-08 -7.533 -7.575 -0.043 +Na 8.229e-03 + Na+ 8.186e-03 7.425e-03 -2.087 -2.129 -0.042 + NaHCO3 2.977e-05 2.983e-05 -4.526 -4.525 0.001 + NaCO3- 7.555e-06 6.846e-06 -5.122 -5.165 -0.043 + NaSO4- 6.192e-06 5.611e-06 -5.208 -5.251 -0.043 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -143.088 -143.131 -0.043 + H2S 0.000e+00 0.000e+00 -144.359 -144.359 0.001 + S5-2 0.000e+00 0.000e+00 -144.415 -144.556 -0.141 + S4-2 0.000e+00 0.000e+00 -144.642 -144.790 -0.148 + S6-2 0.000e+00 0.000e+00 -144.707 -144.842 -0.135 + S-2 0.000e+00 0.000e+00 -147.708 -147.879 -0.171 + S3-2 0.000e+00 0.000e+00 -148.088 -148.243 -0.155 + S2-2 0.000e+00 0.000e+00 -149.328 -149.489 -0.161 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -313.638 -313.680 -0.043 + As3S4(HS)2- 0.000e+00 0.000e+00 -939.137 -939.180 -0.043 +S(6) 2.318e-04 + SO4-2 2.219e-04 1.508e-04 -3.654 -3.822 -0.168 + NaSO4- 6.192e-06 5.611e-06 -5.208 -5.251 -0.043 + CaSO4 2.008e-06 2.013e-06 -5.697 -5.696 0.001 + MgSO4 1.748e-06 1.752e-06 -5.757 -5.757 0.001 + HSO4- 1.095e-10 9.919e-11 -9.961 -10.004 -0.043 + CaHSO4+ 8.806e-14 7.979e-14 -13.055 -13.098 -0.043 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.64 -8.00 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Arsenolite -73.20 -74.58 -1.38 As2O3 + Artinite -6.18 3.42 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -39.08 -30.85 8.23 As2O5 + As2S3(am) -483.58 -528.48 -44.90 As2S3 + As_native -86.57 -99.10 -12.53 As + Brucite -4.81 12.03 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -17.68 -36.58 -18.91 Ca3(AsO4)2:4H2O + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -141.56 -144.42 -2.86 CH4 + Claudetite -73.24 -74.58 -1.34 As2O3 + CO2(g) -2.50 -3.96 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -5.99 -8.13 -2.14 MgSO4:7H2O + Gypsum -3.42 -8.00 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -143.36 -144.36 -1.00 H2S + Halite -7.63 -6.05 1.58 NaCl + Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 + Hydromagnesite -13.65 -22.41 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.58 -8.61 -8.03 MgCO3 + Mirabilite -6.97 -8.08 -1.11 Na2SO4:10H2O + Nahcolite -3.73 -4.28 -0.55 NaHCO3 + Natron -7.25 -8.57 -1.31 Na2CO3:10H2O + Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -482.18 -528.48 -46.30 As2S3 + Portlandite -10.64 12.16 22.80 Ca(OH)2 + Realgar -189.25 -209.19 -19.94 AsS + Sulfur -107.98 -123.01 -15.03 S + Thenardite -7.90 -8.08 -0.18 Na2SO4 + Thermonatrite -8.69 -8.56 0.12 Na2CO3:H2O + Trona -12.04 -12.84 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 61, cumulative pore volumes 61.000000. +Beginning of advection time step 62, cumulative pore volumes 62.000000. +Beginning of advection time step 63, cumulative pore volumes 63.000000. +Beginning of advection time step 64, cumulative pore volumes 64.000000. +Beginning of advection time step 65, cumulative pore volumes 65.000000. +Beginning of advection time step 66, cumulative pore volumes 66.000000. +Beginning of advection time step 67, cumulative pore volumes 67.000000. +Beginning of advection time step 68, cumulative pore volumes 68.000000. +Beginning of advection time step 69, cumulative pore volumes 69.000000. +Beginning of advection time step 70, cumulative pore volumes 70.000000. +Beginning of advection time step 71, cumulative pore volumes 71.000000. +Beginning of advection time step 72, cumulative pore volumes 72.000000. +Beginning of advection time step 73, cumulative pore volumes 73.000000. +Beginning of advection time step 74, cumulative pore volumes 74.000000. +Beginning of advection time step 75, cumulative pore volumes 75.000000. +Beginning of advection time step 76, cumulative pore volumes 76.000000. +Beginning of advection time step 77, cumulative pore volumes 77.000000. +Beginning of advection time step 78, cumulative pore volumes 78.000000. +Beginning of advection time step 79, cumulative pore volumes 79.000000. +Beginning of advection time step 80, cumulative pore volumes 80.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.568e+00 1.568e+00 -3.004e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 9.677e-04 Surface charge, eq + 5.188e-03 sigma, C/m**2 + 2.356e-02 psi, V + -9.170e-01 -F*psi/RT + 3.997e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.250e-02 0.750 5.251e-02 -1.280 + Hfo_wOH2+ 1.019e-02 0.146 1.019e-02 -1.992 + Hfo_wO- 6.199e-03 0.089 6.199e-03 -2.208 + Hfo_wOHAsO4-3 8.223e-04 0.012 8.224e-04 -3.085 + Hfo_wOHSO4-2 2.636e-04 0.004 2.636e-04 -3.579 + Hfo_wSO4- 2.564e-05 0.000 2.564e-05 -4.591 + Hfo_wHAsO4- 6.933e-07 0.000 6.933e-07 -6.159 + Hfo_wH2AsO4 4.353e-09 0.000 4.353e-09 -8.361 + Hfo_wOCa+ 2.176e-13 0.000 2.176e-13 -12.662 + Hfo_wOMg+ 1.711e-13 0.000 1.712e-13 -12.767 + Hfo_wH2AsO3 9.736e-34 0.000 9.737e-34 -33.012 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 2.972e-01 5.944e-01 5.944e-01 0.000 + MgX2 1.475e-01 2.950e-01 2.950e-01 0.000 + NaX 1.106e-01 1.106e-01 1.106e-01 0.000 + HX 4.756e-06 4.756e-06 4.756e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 5.470e-10 5.469e-10 + C 7.720e-03 7.720e-03 + Ca 4.118e-04 4.117e-04 + Cl 1.337e-04 1.337e-04 + Mg 3.198e-04 3.198e-04 + Na 6.400e-03 6.399e-03 + S 2.072e-04 2.072e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.604 Charge balance + pe = 13.001 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.663e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 7.379e-03 + Total CO2 (mol/kg) = 7.720e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.390e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.41 + Iterations = 13 + Total H = 1.110123e+02 + Total O = 5.552657e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.429e-07 4.020e-07 -6.354 -6.396 -0.042 + H+ 2.712e-08 2.490e-08 -7.567 -7.604 -0.037 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +As(3) 7.424e-38 + H3AsO3 7.198e-38 7.213e-38 -37.143 -37.142 0.001 + H2AsO3- 2.259e-39 2.051e-39 -38.646 -38.688 -0.042 + H4AsO3+ 0.000e+00 0.000e+00 -45.009 -45.051 -0.042 + HAsO3-2 0.000e+00 0.000e+00 -45.616 -45.784 -0.168 + AsO3-3 0.000e+00 0.000e+00 -53.502 -53.880 -0.378 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -311.923 -311.965 -0.042 + As3S4(HS)2- 0.000e+00 0.000e+00 -932.861 -932.903 -0.042 +As(5) 5.470e-10 + HAsO4-2 4.309e-10 2.926e-10 -9.366 -9.534 -0.168 + H2AsO4- 1.160e-10 1.053e-10 -9.936 -9.978 -0.042 + AsO4-3 6.288e-14 2.631e-14 -13.202 -13.580 -0.378 + H3AsO4 5.219e-16 5.230e-16 -15.282 -15.282 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.884 -143.883 0.001 +C(4) 7.720e-03 + HCO3- 7.261e-03 6.611e-03 -2.139 -2.180 -0.041 + CO2 3.694e-04 3.702e-04 -3.432 -3.432 0.001 + CaHCO3+ 2.398e-05 2.177e-05 -4.620 -4.662 -0.042 + NaHCO3 2.149e-05 2.153e-05 -4.668 -4.667 0.001 + CO3-2 1.812e-05 1.245e-05 -4.742 -4.905 -0.163 + MgHCO3+ 1.730e-05 1.571e-05 -4.762 -4.804 -0.042 + CaCO3 5.375e-06 5.385e-06 -5.270 -5.269 0.001 + MgCO3 2.408e-06 2.413e-06 -5.618 -5.617 0.001 + NaCO3- 1.479e-06 1.343e-06 -5.830 -5.872 -0.042 +Ca 4.118e-04 + Ca+2 3.757e-04 2.581e-04 -3.425 -3.588 -0.163 + CaHCO3+ 2.398e-05 2.177e-05 -4.620 -4.662 -0.042 + CaSO4 6.687e-06 6.700e-06 -5.175 -5.174 0.001 + CaCO3 5.375e-06 5.385e-06 -5.270 -5.269 0.001 + CaOH+ 1.895e-09 1.720e-09 -8.722 -8.764 -0.042 + CaHSO4+ 1.077e-12 9.772e-13 -11.968 -12.010 -0.042 +Cl 1.337e-04 + Cl- 1.337e-04 1.212e-04 -3.874 -3.917 -0.043 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 3.198e-04 + Mg+2 2.939e-04 2.030e-04 -3.532 -3.692 -0.161 + MgHCO3+ 1.730e-05 1.571e-05 -4.762 -4.804 -0.042 + MgSO4 6.180e-06 6.192e-06 -5.209 -5.208 0.001 + MgCO3 2.408e-06 2.413e-06 -5.618 -5.617 0.001 + MgOH+ 3.261e-08 2.960e-08 -7.487 -7.529 -0.042 +Na 6.400e-03 + Na+ 6.373e-03 5.791e-03 -2.196 -2.237 -0.042 + NaHCO3 2.149e-05 2.153e-05 -4.668 -4.667 0.001 + NaSO4- 4.160e-06 3.776e-06 -5.381 -5.423 -0.042 + NaCO3- 1.479e-06 1.343e-06 -5.830 -5.872 -0.042 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.587 -142.629 -0.042 + H2S 0.000e+00 0.000e+00 -143.292 -143.291 0.001 + S5-2 0.000e+00 0.000e+00 -144.481 -144.620 -0.139 + S4-2 0.000e+00 0.000e+00 -144.709 -144.854 -0.145 + S6-2 0.000e+00 0.000e+00 -144.773 -144.906 -0.133 + S-2 0.000e+00 0.000e+00 -147.775 -147.943 -0.168 + S3-2 0.000e+00 0.000e+00 -148.155 -148.307 -0.152 + S2-2 0.000e+00 0.000e+00 -149.395 -149.553 -0.158 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -311.923 -311.965 -0.042 + As3S4(HS)2- 0.000e+00 0.000e+00 -932.861 -932.903 -0.042 +S(6) 2.072e-04 + SO4-2 1.902e-04 1.301e-04 -3.721 -3.886 -0.165 + CaSO4 6.687e-06 6.700e-06 -5.175 -5.174 0.001 + MgSO4 6.180e-06 6.192e-06 -5.209 -5.208 0.001 + NaSO4- 4.160e-06 3.776e-06 -5.381 -5.423 -0.042 + HSO4- 3.469e-10 3.149e-10 -9.460 -9.502 -0.042 + CaHSO4+ 1.077e-12 9.772e-13 -11.968 -12.010 -0.042 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.11 -7.47 -4.36 CaSO4 + Aragonite -0.16 -8.49 -8.34 CaCO3 + Arsenolite -72.90 -74.28 -1.38 As2O3 + Artinite -6.68 2.92 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -38.79 -30.56 8.23 As2O5 + As2S3(am) -480.08 -524.98 -44.90 As2S3 + As_native -86.43 -98.96 -12.53 As + Brucite -5.32 11.52 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.02 -37.92 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.01 -8.49 -8.48 CaCO3 + CH4(g) -141.02 -143.88 -2.86 CH4 + Claudetite -72.94 -74.28 -1.34 As2O3 + CO2(g) -1.96 -3.43 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -5.44 -7.58 -2.14 MgSO4:7H2O + Gypsum -2.89 -7.47 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -142.29 -143.29 -1.00 H2S + Halite -7.74 -6.15 1.58 NaCl + Huntite -4.32 -34.28 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.11 -22.87 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.57 -8.60 -8.03 MgCO3 + Mirabilite -7.25 -8.36 -1.11 Na2SO4:10H2O + Nahcolite -3.87 -4.42 -0.55 NaHCO3 + Natron -8.07 -9.38 -1.31 Na2CO3:10H2O + Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -478.68 -524.98 -46.30 As2S3 + Portlandite -11.18 11.62 22.80 Ca(OH)2 + Realgar -188.04 -207.98 -19.94 AsS + Sulfur -106.91 -121.94 -15.03 S + Thenardite -8.18 -8.36 -0.18 Na2SO4 + Thermonatrite -9.50 -9.38 0.12 Na2CO3:H2O + Trona -13.00 -13.80 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 81, cumulative pore volumes 81.000000. +Beginning of advection time step 82, cumulative pore volumes 82.000000. +Beginning of advection time step 83, cumulative pore volumes 83.000000. +Beginning of advection time step 84, cumulative pore volumes 84.000000. +Beginning of advection time step 85, cumulative pore volumes 85.000000. +Beginning of advection time step 86, cumulative pore volumes 86.000000. +Beginning of advection time step 87, cumulative pore volumes 87.000000. +Beginning of advection time step 88, cumulative pore volumes 88.000000. +Beginning of advection time step 89, cumulative pore volumes 89.000000. +Beginning of advection time step 90, cumulative pore volumes 90.000000. +Beginning of advection time step 91, cumulative pore volumes 91.000000. +Beginning of advection time step 92, cumulative pore volumes 92.000000. +Beginning of advection time step 93, cumulative pore volumes 93.000000. +Beginning of advection time step 94, cumulative pore volumes 94.000000. +Beginning of advection time step 95, cumulative pore volumes 95.000000. +Beginning of advection time step 96, cumulative pore volumes 96.000000. +Beginning of advection time step 97, cumulative pore volumes 97.000000. +Beginning of advection time step 98, cumulative pore volumes 98.000000. +Beginning of advection time step 99, cumulative pore volumes 99.000000. +Beginning of advection time step 100, cumulative pore volumes 100.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 -5.456e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.005e-03 Surface charge, eq + 1.075e-02 sigma, C/m**2 + 4.415e-02 psi, V + -1.719e+00 -F*psi/RT + 1.793e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.116e-02 0.731 5.116e-02 -1.291 + Hfo_wOH2+ 1.176e-02 0.168 1.177e-02 -1.929 + Hfo_wO- 5.096e-03 0.073 5.097e-03 -2.293 + Hfo_wOHSO4-2 1.038e-03 0.015 1.038e-03 -2.984 + Hfo_wOHAsO4-3 8.220e-04 0.012 8.221e-04 -3.085 + Hfo_wSO4- 1.197e-04 0.002 1.197e-04 -3.922 + Hfo_wHAsO4- 9.734e-07 0.000 9.735e-07 -6.012 + Hfo_wH2AsO4 7.244e-09 0.000 7.244e-09 -8.140 + Hfo_wOCa+ 1.086e-13 0.000 1.086e-13 -12.964 + Hfo_wOMg+ 8.842e-14 0.000 8.843e-14 -13.053 + Hfo_wH2AsO3 1.620e-33 0.000 1.620e-33 -32.790 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.218e-01 6.437e-01 6.437e-01 0.000 + MgX2 1.654e-01 3.308e-01 3.308e-01 0.000 + NaX 2.548e-02 2.548e-02 2.548e-02 0.000 + HX 7.530e-06 7.530e-06 7.530e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.811e-10 1.810e-10 + C 7.229e-03 7.228e-03 + Ca 1.222e-03 1.222e-03 + Cl 1.337e-04 1.337e-04 + Mg 9.867e-04 9.866e-04 + Na 2.461e-03 2.461e-03 + S 1.889e-04 1.888e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.182 Charge balance + pe = 13.423 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.921e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.402e-03 + Total CO2 (mol/kg) = 7.229e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.426e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.26 + Iterations = 9 + Total H = 1.110123e+02 + Total O = 5.552502e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.678e-07 1.522e-07 -6.775 -6.818 -0.043 + H+ 7.172e-08 6.577e-08 -7.144 -7.182 -0.038 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.244e-37 + H3AsO3 1.229e-37 1.232e-37 -36.910 -36.909 0.001 + H2AsO3- 1.462e-39 1.326e-39 -38.835 -38.878 -0.043 + H4AsO3+ 0.000e+00 0.000e+00 -44.354 -44.396 -0.043 + HAsO3-2 0.000e+00 0.000e+00 -46.225 -46.396 -0.170 + AsO3-3 0.000e+00 0.000e+00 -54.530 -54.914 -0.383 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.604 -310.646 -0.043 + As3S4(HS)2- 0.000e+00 0.000e+00 -928.060 -928.103 -0.043 +As(5) 1.811e-10 + HAsO4-2 1.060e-10 7.159e-11 -9.975 -10.145 -0.170 + H2AsO4- 7.507e-11 6.806e-11 -10.125 -10.167 -0.043 + AsO4-3 5.890e-15 2.437e-15 -14.230 -14.613 -0.383 + H3AsO4 8.914e-16 8.932e-16 -15.050 -15.049 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.527 -143.526 0.001 +C(4) 7.229e-03 + HCO3- 6.259e-03 5.692e-03 -2.204 -2.245 -0.041 + CO2 8.402e-04 8.419e-04 -3.076 -3.075 0.001 + CaHCO3+ 6.233e-05 5.651e-05 -4.205 -4.248 -0.043 + MgHCO3+ 4.658e-05 4.223e-05 -4.332 -4.374 -0.043 + NaHCO3 7.110e-06 7.125e-06 -5.148 -5.147 0.001 + CO3-2 5.932e-06 4.058e-06 -5.227 -5.392 -0.165 + CaCO3 5.281e-06 5.292e-06 -5.277 -5.276 0.001 + MgCO3 2.450e-06 2.455e-06 -5.611 -5.610 0.001 + NaCO3- 1.856e-07 1.682e-07 -6.732 -6.774 -0.043 +Ca 1.222e-03 + Ca+2 1.138e-03 7.784e-04 -2.944 -3.109 -0.165 + CaHCO3+ 6.233e-05 5.651e-05 -4.205 -4.248 -0.043 + CaSO4 1.640e-05 1.644e-05 -4.785 -4.784 0.001 + CaCO3 5.281e-06 5.292e-06 -5.277 -5.276 0.001 + CaOH+ 2.166e-09 1.964e-09 -8.664 -8.707 -0.043 + CaHSO4+ 6.986e-12 6.334e-12 -11.156 -11.198 -0.043 +Cl 1.337e-04 + Cl- 1.337e-04 1.210e-04 -3.874 -3.917 -0.043 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.360 0.001 +Mg 9.867e-04 + Mg+2 9.219e-04 6.340e-04 -3.035 -3.198 -0.163 + MgHCO3+ 4.658e-05 4.223e-05 -4.332 -4.374 -0.043 + MgSO4 1.570e-05 1.573e-05 -4.804 -4.803 0.001 + MgCO3 2.450e-06 2.455e-06 -5.611 -5.610 0.001 + MgOH+ 3.860e-08 3.499e-08 -7.413 -7.456 -0.043 +Na 2.461e-03 + Na+ 2.453e-03 2.226e-03 -2.610 -2.652 -0.042 + NaHCO3 7.110e-06 7.125e-06 -5.148 -5.147 0.001 + NaSO4- 1.302e-06 1.181e-06 -5.885 -5.928 -0.043 + NaCO3- 1.856e-07 1.682e-07 -6.732 -6.774 -0.043 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.254 -142.297 -0.043 + H2S 0.000e+00 0.000e+00 -142.538 -142.537 0.001 + S5-2 0.000e+00 0.000e+00 -144.569 -144.710 -0.140 + S4-2 0.000e+00 0.000e+00 -144.797 -144.944 -0.147 + S6-2 0.000e+00 0.000e+00 -144.862 -144.996 -0.134 + S-2 0.000e+00 0.000e+00 -147.862 -148.033 -0.170 + S3-2 0.000e+00 0.000e+00 -148.243 -148.397 -0.154 + S2-2 0.000e+00 0.000e+00 -149.483 -149.643 -0.160 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.604 -310.646 -0.043 + As3S4(HS)2- 0.000e+00 0.000e+00 -928.060 -928.103 -0.043 +S(6) 1.889e-04 + SO4-2 1.554e-04 1.058e-04 -3.808 -3.975 -0.167 + CaSO4 1.640e-05 1.644e-05 -4.785 -4.784 0.001 + MgSO4 1.570e-05 1.573e-05 -4.804 -4.803 0.001 + NaSO4- 1.302e-06 1.181e-06 -5.885 -5.928 -0.043 + HSO4- 7.465e-10 6.768e-10 -9.127 -9.170 -0.043 + CaHSO4+ 6.986e-12 6.334e-12 -11.156 -11.198 -0.043 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.72 -7.08 -4.36 CaSO4 + Aragonite -0.16 -8.50 -8.34 CaCO3 + Arsenolite -72.44 -73.82 -1.38 As2O3 + Artinite -7.02 2.58 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -38.33 -30.10 8.23 As2O5 + As2S3(am) -477.35 -522.25 -44.90 As2S3 + As_native -86.19 -98.72 -12.53 As + Brucite -5.67 11.17 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.65 -38.55 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.02 -8.50 -8.48 CaCO3 + CH4(g) -140.67 -143.53 -2.86 CH4 + Claudetite -72.48 -73.82 -1.34 As2O3 + CO2(g) -1.61 -3.07 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -5.03 -7.17 -2.14 MgSO4:7H2O + Gypsum -2.50 -7.08 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.54 -142.54 -1.00 H2S + Halite -8.15 -6.57 1.58 NaCl + Huntite -4.30 -34.27 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.43 -23.19 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.56 -8.59 -8.03 MgCO3 + Mirabilite -8.17 -9.28 -1.11 Na2SO4:10H2O + Nahcolite -4.35 -4.90 -0.55 NaHCO3 + Natron -9.39 -10.70 -1.31 Na2CO3:10H2O + Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -475.95 -522.25 -46.30 As2S3 + Portlandite -11.55 11.25 22.80 Ca(OH)2 + Realgar -187.05 -206.99 -19.94 AsS + Sulfur -106.16 -121.19 -15.03 S + Thenardite -9.10 -9.28 -0.18 Na2SO4 + Thermonatrite -10.82 -10.70 0.12 Na2CO3:H2O + Trona -14.80 -15.59 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 101, cumulative pore volumes 101.000000. +Beginning of advection time step 102, cumulative pore volumes 102.000000. +Beginning of advection time step 103, cumulative pore volumes 103.000000. +Beginning of advection time step 104, cumulative pore volumes 104.000000. +Beginning of advection time step 105, cumulative pore volumes 105.000000. +Beginning of advection time step 106, cumulative pore volumes 106.000000. +Beginning of advection time step 107, cumulative pore volumes 107.000000. +Beginning of advection time step 108, cumulative pore volumes 108.000000. +Beginning of advection time step 109, cumulative pore volumes 109.000000. +Beginning of advection time step 110, cumulative pore volumes 110.000000. +Beginning of advection time step 111, cumulative pore volumes 111.000000. +Beginning of advection time step 112, cumulative pore volumes 112.000000. +Beginning of advection time step 113, cumulative pore volumes 113.000000. +Beginning of advection time step 114, cumulative pore volumes 114.000000. +Beginning of advection time step 115, cumulative pore volumes 115.000000. +Beginning of advection time step 116, cumulative pore volumes 116.000000. +Beginning of advection time step 117, cumulative pore volumes 117.000000. +Beginning of advection time step 118, cumulative pore volumes 118.000000. +Beginning of advection time step 119, cumulative pore volumes 119.000000. +Beginning of advection time step 120, cumulative pore volumes 120.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.153e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.333e-03 Surface charge, eq + 1.251e-02 sigma, C/m**2 + 4.866e-02 psi, V + -1.894e+00 -F*psi/RT + 1.505e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 5.018e-02 0.717 5.018e-02 -1.299 + Hfo_wOH2+ 1.268e-02 0.181 1.268e-02 -1.897 + Hfo_wO- 4.548e-03 0.065 4.548e-03 -2.342 + Hfo_wOHSO4-2 1.569e-03 0.022 1.569e-03 -2.804 + Hfo_wOHAsO4-3 8.218e-04 0.012 8.219e-04 -3.085 + Hfo_wSO4- 1.988e-04 0.003 1.988e-04 -3.702 + Hfo_wHAsO4- 1.176e-06 0.000 1.176e-06 -5.930 + Hfo_wH2AsO4 9.617e-09 0.000 9.618e-09 -8.017 + Hfo_wOCa+ 9.482e-14 0.000 9.482e-14 -13.023 + Hfo_wOMg+ 7.699e-14 0.000 7.699e-14 -13.114 + Hfo_wH2AsO3 2.151e-33 0.000 2.151e-33 -32.667 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.292e-01 6.584e-01 6.584e-01 0.000 + MgX2 1.687e-01 3.373e-01 3.373e-01 0.000 + NaX 4.301e-03 4.301e-03 4.301e-03 0.000 + HX 8.461e-06 8.461e-06 8.461e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.623e-10 1.623e-10 + C 7.117e-03 7.117e-03 + Ca 1.709e-03 1.709e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.376e-03 1.376e-03 + Na 4.854e-04 4.853e-04 + S 2.190e-04 2.189e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.065 Charge balance + pe = 13.540 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.464e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.091e-03 + Total CO2 (mol/kg) = 7.117e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.811e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.552481e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.285e-07 1.162e-07 -6.891 -6.935 -0.044 + H+ 9.412e-08 8.614e-08 -7.026 -7.065 -0.038 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.679e-37 + H3AsO3 1.664e-37 1.667e-37 -36.779 -36.778 0.001 + H2AsO3- 1.515e-39 1.370e-39 -38.819 -38.863 -0.044 + H4AsO3+ 0.000e+00 0.000e+00 -44.104 -44.148 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -46.324 -46.498 -0.175 + AsO3-3 0.000e+00 0.000e+00 -54.740 -55.134 -0.393 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.049 -310.093 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -926.164 -926.208 -0.044 +As(5) 1.623e-10 + HAsO4-2 8.450e-11 5.650e-11 -10.073 -10.248 -0.175 + H2AsO4- 7.779e-11 7.035e-11 -10.109 -10.153 -0.044 + AsO4-3 3.632e-15 1.468e-15 -14.440 -14.833 -0.393 + H3AsO4 1.206e-15 1.209e-15 -14.918 -14.918 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.435 -143.434 0.001 +C(4) 7.117e-03 + HCO3- 5.922e-03 5.373e-03 -2.228 -2.270 -0.042 + CO2 1.039e-03 1.041e-03 -2.984 -2.983 0.001 + CaHCO3+ 8.197e-05 7.412e-05 -4.086 -4.130 -0.044 + MgHCO3+ 6.106e-05 5.522e-05 -4.214 -4.258 -0.044 + CaCO3 5.289e-06 5.300e-06 -5.277 -5.276 0.001 + CO3-2 4.317e-06 2.925e-06 -5.365 -5.534 -0.169 + MgCO3 2.446e-06 2.452e-06 -5.612 -5.611 0.001 + NaHCO3 1.320e-06 1.323e-06 -5.879 -5.878 0.001 + NaCO3- 2.638e-08 2.385e-08 -7.579 -7.622 -0.044 +Ca 1.709e-03 + Ca+2 1.597e-03 1.082e-03 -2.797 -2.966 -0.169 + CaHCO3+ 8.197e-05 7.412e-05 -4.086 -4.130 -0.044 + CaSO4 2.473e-05 2.478e-05 -4.607 -4.606 0.001 + CaCO3 5.289e-06 5.300e-06 -5.277 -5.276 0.001 + CaOH+ 2.304e-09 2.083e-09 -8.638 -8.681 -0.044 + CaHSO4+ 1.383e-11 1.251e-11 -10.859 -10.903 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.207e-04 -3.874 -3.918 -0.044 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.376e-03 + Mg+2 1.289e-03 8.783e-04 -2.890 -3.056 -0.167 + MgHCO3+ 6.106e-05 5.522e-05 -4.214 -4.258 -0.044 + MgSO4 2.359e-05 2.364e-05 -4.627 -4.626 0.001 + MgCO3 2.446e-06 2.452e-06 -5.612 -5.611 0.001 + MgOH+ 4.093e-08 3.701e-08 -7.388 -7.432 -0.044 +Na 4.854e-04 + Na+ 4.837e-04 4.379e-04 -3.315 -3.359 -0.043 + NaHCO3 1.320e-06 1.323e-06 -5.879 -5.878 0.001 + NaSO4- 2.787e-07 2.520e-07 -6.555 -6.599 -0.044 + NaCO3- 2.638e-08 2.385e-08 -7.579 -7.622 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.100 -142.144 -0.044 + H2S 0.000e+00 0.000e+00 -142.268 -142.267 0.001 + S5-2 0.000e+00 0.000e+00 -144.531 -144.674 -0.143 + S4-2 0.000e+00 0.000e+00 -144.758 -144.908 -0.150 + S6-2 0.000e+00 0.000e+00 -144.823 -144.960 -0.137 + S-2 0.000e+00 0.000e+00 -147.822 -147.997 -0.175 + S3-2 0.000e+00 0.000e+00 -148.203 -148.361 -0.158 + S2-2 0.000e+00 0.000e+00 -149.443 -149.607 -0.164 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.049 -310.093 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -926.164 -926.208 -0.044 +S(6) 2.190e-04 + SO4-2 1.704e-04 1.148e-04 -3.769 -3.940 -0.171 + CaSO4 2.473e-05 2.478e-05 -4.607 -4.606 0.001 + MgSO4 2.359e-05 2.364e-05 -4.627 -4.626 0.001 + NaSO4- 2.787e-07 2.520e-07 -6.555 -6.599 -0.044 + HSO4- 1.064e-09 9.618e-10 -8.973 -9.017 -0.044 + CaHSO4+ 1.383e-11 1.251e-11 -10.859 -10.903 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.55 -6.91 -4.36 CaSO4 + Aragonite -0.16 -8.50 -8.34 CaCO3 + Arsenolite -72.18 -73.56 -1.38 As2O3 + Artinite -7.12 2.48 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -38.06 -29.83 8.23 As2O5 + As2S3(am) -476.28 -521.18 -44.90 As2S3 + As_native -86.06 -98.59 -12.53 As + Brucite -5.77 11.07 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.66 -38.56 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.02 -8.50 -8.48 CaCO3 + CH4(g) -140.57 -143.43 -2.86 CH4 + Claudetite -72.22 -73.56 -1.34 As2O3 + CO2(g) -1.51 -2.98 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.86 -7.00 -2.14 MgSO4:7H2O + Gypsum -2.33 -6.91 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.27 -142.27 -1.00 H2S + Halite -8.86 -7.28 1.58 NaCl + Huntite -4.30 -34.27 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.53 -23.29 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.56 -8.59 -8.03 MgCO3 + Mirabilite -9.54 -10.66 -1.11 Na2SO4:10H2O + Nahcolite -5.08 -5.63 -0.55 NaHCO3 + Natron -10.94 -12.25 -1.31 Na2CO3:10H2O + Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -474.88 -521.18 -46.30 As2S3 + Portlandite -11.64 11.16 22.80 Ca(OH)2 + Realgar -186.65 -206.59 -19.94 AsS + Sulfur -105.89 -120.92 -15.03 S + Thenardite -10.48 -10.66 -0.18 Na2SO4 + Thermonatrite -12.38 -12.25 0.12 Na2CO3:H2O + Trona -17.08 -17.88 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 121, cumulative pore volumes 121.000000. +Beginning of advection time step 122, cumulative pore volumes 122.000000. +Beginning of advection time step 123, cumulative pore volumes 123.000000. +Beginning of advection time step 124, cumulative pore volumes 124.000000. +Beginning of advection time step 125, cumulative pore volumes 125.000000. +Beginning of advection time step 126, cumulative pore volumes 126.000000. +Beginning of advection time step 127, cumulative pore volumes 127.000000. +Beginning of advection time step 128, cumulative pore volumes 128.000000. +Beginning of advection time step 129, cumulative pore volumes 129.000000. +Beginning of advection time step 130, cumulative pore volumes 130.000000. +Beginning of advection time step 131, cumulative pore volumes 131.000000. +Beginning of advection time step 132, cumulative pore volumes 132.000000. +Beginning of advection time step 133, cumulative pore volumes 133.000000. +Beginning of advection time step 134, cumulative pore volumes 134.000000. +Beginning of advection time step 135, cumulative pore volumes 135.000000. +Beginning of advection time step 136, cumulative pore volumes 136.000000. +Beginning of advection time step 137, cumulative pore volumes 137.000000. +Beginning of advection time step 138, cumulative pore volumes 138.000000. +Beginning of advection time step 139, cumulative pore volumes 139.000000. +Beginning of advection time step 140, cumulative pore volumes 140.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 2.132e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.378e-03 Surface charge, eq + 1.275e-02 sigma, C/m**2 + 4.912e-02 psi, V + -1.912e+00 -F*psi/RT + 1.478e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 4.994e-02 0.713 4.994e-02 -1.302 + Hfo_wOH2+ 1.289e-02 0.184 1.289e-02 -1.890 + Hfo_wO- 4.431e-03 0.063 4.431e-03 -2.353 + Hfo_wOHSO4-2 1.698e-03 0.024 1.698e-03 -2.770 + Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 + Hfo_wSO4- 2.198e-04 0.003 2.198e-04 -3.658 + Hfo_wHAsO4- 1.226e-06 0.000 1.226e-06 -5.911 + Hfo_wH2AsO4 1.025e-08 0.000 1.025e-08 -7.989 + Hfo_wOCa+ 9.387e-14 0.000 9.387e-14 -13.027 + Hfo_wOMg+ 7.538e-14 0.000 7.538e-14 -13.123 + Hfo_wH2AsO3 2.291e-33 0.000 2.292e-33 -32.640 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.314e-01 6.627e-01 6.627e-01 -0.000 + MgX2 1.679e-01 3.358e-01 3.358e-01 -0.000 + NaX 1.435e-03 1.435e-03 1.435e-03 -0.000 + HX 8.602e-06 8.602e-06 8.602e-06 -0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.640e-10 1.639e-10 + C 7.115e-03 7.115e-03 + Ca 1.806e-03 1.805e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.438e-03 1.438e-03 + Na 1.658e-04 1.658e-04 + S 2.323e-04 2.323e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.048 Charge balance + pe = 13.558 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.599e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.055e-03 + Total CO2 (mol/kg) = 7.115e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.682e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 10 + Total H = 1.110125e+02 + Total O = 5.552485e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.236e-07 1.117e-07 -6.908 -6.952 -0.044 + H+ 9.795e-08 8.960e-08 -7.009 -7.048 -0.039 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.797e-37 + H3AsO3 1.781e-37 1.785e-37 -36.749 -36.748 0.001 + H2AsO3- 1.561e-39 1.410e-39 -38.807 -38.851 -0.044 + H4AsO3+ 0.000e+00 0.000e+00 -44.057 -44.101 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -46.327 -46.503 -0.176 + AsO3-3 0.000e+00 0.000e+00 -54.759 -55.155 -0.396 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.927 -309.971 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.763 -925.807 -0.044 +As(5) 1.640e-10 + HAsO4-2 8.383e-11 5.591e-11 -10.077 -10.253 -0.176 + H2AsO4- 8.012e-11 7.240e-11 -10.096 -10.140 -0.044 + AsO4-3 3.475e-15 1.397e-15 -14.459 -14.855 -0.396 + H3AsO4 1.291e-15 1.294e-15 -14.889 -14.888 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.421 -143.420 0.001 +C(4) 7.115e-03 + HCO3- 5.882e-03 5.333e-03 -2.230 -2.273 -0.043 + CO2 1.072e-03 1.075e-03 -2.970 -2.969 0.001 + CaHCO3+ 8.579e-05 7.752e-05 -4.067 -4.111 -0.044 + MgHCO3+ 6.320e-05 5.711e-05 -4.199 -4.243 -0.044 + CaCO3 5.318e-06 5.330e-06 -5.274 -5.273 0.001 + CO3-2 4.130e-06 2.792e-06 -5.384 -5.554 -0.170 + MgCO3 2.433e-06 2.438e-06 -5.614 -5.613 0.001 + NaHCO3 4.474e-07 4.484e-07 -6.349 -6.348 0.001 + NaCO3- 8.600e-09 7.772e-09 -8.065 -8.109 -0.044 +Ca 1.806e-03 + Ca+2 1.687e-03 1.140e-03 -2.773 -2.943 -0.170 + CaHCO3+ 8.579e-05 7.752e-05 -4.067 -4.111 -0.044 + CaSO4 2.733e-05 2.739e-05 -4.563 -4.562 0.001 + CaCO3 5.318e-06 5.330e-06 -5.274 -5.273 0.001 + CaOH+ 2.336e-09 2.111e-09 -8.632 -8.676 -0.044 + CaHSO4+ 1.591e-11 1.437e-11 -10.798 -10.842 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.438e-03 + Mg+2 1.346e-03 9.152e-04 -2.871 -3.038 -0.168 + MgHCO3+ 6.320e-05 5.711e-05 -4.199 -4.243 -0.044 + MgSO4 2.578e-05 2.584e-05 -4.589 -4.588 0.001 + MgCO3 2.433e-06 2.438e-06 -5.614 -5.613 0.001 + MgOH+ 4.103e-08 3.708e-08 -7.387 -7.431 -0.044 +Na 1.658e-04 + Na+ 1.653e-04 1.495e-04 -3.782 -3.825 -0.043 + NaHCO3 4.474e-07 4.484e-07 -6.349 -6.348 0.001 + NaSO4- 9.987e-08 9.025e-08 -7.001 -7.045 -0.044 + NaCO3- 8.600e-09 7.772e-09 -8.065 -8.109 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.062 -142.106 -0.044 + H2S 0.000e+00 0.000e+00 -142.213 -142.212 0.001 + S5-2 0.000e+00 0.000e+00 -144.510 -144.654 -0.144 + S4-2 0.000e+00 0.000e+00 -144.737 -144.888 -0.151 + S6-2 0.000e+00 0.000e+00 -144.802 -144.940 -0.138 + S-2 0.000e+00 0.000e+00 -147.801 -147.977 -0.176 + S3-2 0.000e+00 0.000e+00 -148.182 -148.341 -0.159 + S2-2 0.000e+00 0.000e+00 -149.422 -149.587 -0.165 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.927 -309.971 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.763 -925.807 -0.044 +S(6) 2.323e-04 + SO4-2 1.791e-04 1.204e-04 -3.747 -3.919 -0.172 + CaSO4 2.733e-05 2.739e-05 -4.563 -4.562 0.001 + MgSO4 2.578e-05 2.584e-05 -4.589 -4.588 0.001 + NaSO4- 9.987e-08 9.025e-08 -7.001 -7.045 -0.044 + HSO4- 1.161e-09 1.049e-09 -8.935 -8.979 -0.044 + CaHSO4+ 1.591e-11 1.437e-11 -10.798 -10.842 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.50 -6.86 -4.36 CaSO4 + Aragonite -0.16 -8.50 -8.34 CaCO3 + Arsenolite -72.12 -73.50 -1.38 As2O3 + Artinite -7.14 2.46 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -38.00 -29.78 8.23 As2O5 + As2S3(am) -476.06 -520.96 -44.90 As2S3 + As_native -86.03 -98.56 -12.53 As + Brucite -5.78 11.06 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.63 -38.54 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.02 -8.50 -8.48 CaCO3 + CH4(g) -140.56 -143.42 -2.86 CH4 + Claudetite -72.16 -73.50 -1.34 As2O3 + CO2(g) -1.50 -2.97 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O + Gypsum -2.28 -6.86 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.22 -142.21 -1.00 H2S + Halite -9.33 -7.74 1.58 NaCl + Huntite -4.31 -34.28 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.55 -23.31 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.56 -8.59 -8.03 MgCO3 + Mirabilite -10.46 -11.57 -1.11 Na2SO4:10H2O + Nahcolite -5.55 -6.10 -0.55 NaHCO3 + Natron -11.89 -13.21 -1.31 Na2CO3:10H2O + Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -474.66 -520.96 -46.30 As2S3 + Portlandite -11.65 11.15 22.80 Ca(OH)2 + Realgar -186.56 -206.51 -19.94 AsS + Sulfur -105.84 -120.86 -15.03 S + Thenardite -11.39 -11.57 -0.18 Na2SO4 + Thermonatrite -13.33 -13.20 0.12 Na2CO3:H2O + Trona -18.51 -19.30 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 141, cumulative pore volumes 141.000000. +Beginning of advection time step 142, cumulative pore volumes 142.000000. +Beginning of advection time step 143, cumulative pore volumes 143.000000. +Beginning of advection time step 144, cumulative pore volumes 144.000000. +Beginning of advection time step 145, cumulative pore volumes 145.000000. +Beginning of advection time step 146, cumulative pore volumes 146.000000. +Beginning of advection time step 147, cumulative pore volumes 147.000000. +Beginning of advection time step 148, cumulative pore volumes 148.000000. +Beginning of advection time step 149, cumulative pore volumes 149.000000. +Beginning of advection time step 150, cumulative pore volumes 150.000000. +Beginning of advection time step 151, cumulative pore volumes 151.000000. +Beginning of advection time step 152, cumulative pore volumes 152.000000. +Beginning of advection time step 153, cumulative pore volumes 153.000000. +Beginning of advection time step 154, cumulative pore volumes 154.000000. +Beginning of advection time step 155, cumulative pore volumes 155.000000. +Beginning of advection time step 156, cumulative pore volumes 156.000000. +Beginning of advection time step 157, cumulative pore volumes 157.000000. +Beginning of advection time step 158, cumulative pore volumes 158.000000. +Beginning of advection time step 159, cumulative pore volumes 159.000000. +Beginning of advection time step 160, cumulative pore volumes 160.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.465e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.383e-03 Surface charge, eq + 1.278e-02 sigma, C/m**2 + 4.916e-02 psi, V + -1.914e+00 -F*psi/RT + 1.476e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 + Hfo_wOH2+ 1.292e-02 0.185 1.292e-02 -1.889 + Hfo_wO- 4.414e-03 0.063 4.415e-03 -2.355 + Hfo_wOHSO4-2 1.717e-03 0.025 1.717e-03 -2.765 + Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 + Hfo_wSO4- 2.229e-04 0.003 2.229e-04 -3.652 + Hfo_wHAsO4- 1.234e-06 0.000 1.234e-06 -5.909 + Hfo_wH2AsO4 1.034e-08 0.000 1.034e-08 -7.985 + Hfo_wOCa+ 9.423e-14 0.000 9.423e-14 -13.026 + Hfo_wOMg+ 7.486e-14 0.000 7.487e-14 -13.126 + Hfo_wH2AsO3 2.312e-33 0.000 2.313e-33 -32.636 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.327e-01 6.654e-01 6.654e-01 0.000 + MgX2 1.668e-01 3.335e-01 3.335e-01 0.000 + NaX 1.101e-03 1.101e-03 1.101e-03 0.000 + HX 8.612e-06 8.612e-06 8.612e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.645e-10 1.645e-10 + C 7.117e-03 7.116e-03 + Ca 1.825e-03 1.825e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.438e-03 1.438e-03 + Na 1.276e-04 1.276e-04 + S 2.347e-04 2.347e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.046 Charge balance + pe = 13.560 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.619e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.052e-03 + Total CO2 (mol/kg) = 7.117e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.135e-08 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110125e+02 + Total O = 5.552486e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.231e-07 1.112e-07 -6.910 -6.954 -0.044 + H+ 9.840e-08 9.000e-08 -7.007 -7.046 -0.039 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.814e-37 + H3AsO3 1.799e-37 1.802e-37 -36.745 -36.744 0.001 + H2AsO3- 1.569e-39 1.418e-39 -38.804 -38.848 -0.044 + H4AsO3+ 0.000e+00 0.000e+00 -44.051 -44.095 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -46.327 -46.503 -0.176 + AsO3-3 0.000e+00 0.000e+00 -54.761 -55.157 -0.396 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.909 -309.953 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.705 -925.749 -0.044 +As(5) 1.645e-10 + HAsO4-2 8.392e-11 5.595e-11 -10.076 -10.252 -0.176 + H2AsO4- 8.055e-11 7.279e-11 -10.094 -10.138 -0.044 + AsO4-3 3.465e-15 1.392e-15 -14.460 -14.856 -0.396 + H3AsO4 1.304e-15 1.307e-15 -14.885 -14.884 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 +C(4) 7.117e-03 + HCO3- 5.878e-03 5.330e-03 -2.231 -2.273 -0.043 + CO2 1.076e-03 1.079e-03 -2.968 -2.967 0.001 + CaHCO3+ 8.665e-05 7.829e-05 -4.062 -4.106 -0.044 + MgHCO3+ 6.315e-05 5.707e-05 -4.200 -4.244 -0.044 + CaCO3 5.347e-06 5.358e-06 -5.272 -5.271 0.001 + CO3-2 4.110e-06 2.777e-06 -5.386 -5.556 -0.170 + MgCO3 2.420e-06 2.425e-06 -5.616 -5.615 0.001 + NaHCO3 3.441e-07 3.449e-07 -6.463 -6.462 0.001 + NaCO3- 6.585e-09 5.951e-09 -8.181 -8.225 -0.044 +Ca 1.825e-03 + Ca+2 1.706e-03 1.152e-03 -2.768 -2.939 -0.171 + CaHCO3+ 8.665e-05 7.829e-05 -4.062 -4.106 -0.044 + CaSO4 2.787e-05 2.793e-05 -4.555 -4.554 0.001 + CaCO3 5.347e-06 5.358e-06 -5.272 -5.271 0.001 + CaOH+ 2.350e-09 2.123e-09 -8.629 -8.673 -0.044 + CaHSO4+ 1.630e-11 1.473e-11 -10.788 -10.832 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.438e-03 + Mg+2 1.347e-03 9.151e-04 -2.871 -3.039 -0.168 + MgHCO3+ 6.315e-05 5.707e-05 -4.200 -4.244 -0.044 + MgSO4 2.601e-05 2.607e-05 -4.585 -4.584 0.001 + MgCO3 2.420e-06 2.425e-06 -5.616 -5.615 0.001 + MgOH+ 4.085e-08 3.691e-08 -7.389 -7.433 -0.044 +Na 1.276e-04 + Na+ 1.272e-04 1.151e-04 -3.895 -3.939 -0.044 + NaHCO3 3.441e-07 3.449e-07 -6.463 -6.462 0.001 + NaSO4- 7.756e-08 7.009e-08 -7.110 -7.154 -0.044 + NaCO3- 6.585e-09 5.951e-09 -8.181 -8.225 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.056 -142.101 -0.044 + H2S 0.000e+00 0.000e+00 -142.206 -142.205 0.001 + S5-2 0.000e+00 0.000e+00 -144.506 -144.650 -0.144 + S4-2 0.000e+00 0.000e+00 -144.733 -144.884 -0.151 + S6-2 0.000e+00 0.000e+00 -144.798 -144.936 -0.138 + S-2 0.000e+00 0.000e+00 -147.797 -147.973 -0.176 + S3-2 0.000e+00 0.000e+00 -148.178 -148.337 -0.159 + S2-2 0.000e+00 0.000e+00 -149.418 -149.583 -0.165 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.909 -309.953 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.705 -925.749 -0.044 +S(6) 2.347e-04 + SO4-2 1.808e-04 1.215e-04 -3.743 -3.915 -0.172 + CaSO4 2.787e-05 2.793e-05 -4.555 -4.554 0.001 + MgSO4 2.601e-05 2.607e-05 -4.585 -4.584 0.001 + NaSO4- 7.756e-08 7.009e-08 -7.110 -7.154 -0.044 + HSO4- 1.177e-09 1.063e-09 -8.929 -8.973 -0.044 + CaHSO4+ 1.630e-11 1.473e-11 -10.788 -10.832 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.49 -6.85 -4.36 CaSO4 + Aragonite -0.16 -8.50 -8.34 CaCO3 + Arsenolite -72.11 -73.49 -1.38 As2O3 + Artinite -7.14 2.46 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -38.00 -29.77 8.23 As2O5 + As2S3(am) -476.03 -520.93 -44.90 As2S3 + As_native -86.03 -98.56 -12.53 As + Brucite -5.79 11.05 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.62 -38.53 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.02 -8.50 -8.48 CaCO3 + CH4(g) -140.56 -143.42 -2.86 CH4 + Claudetite -72.15 -73.49 -1.34 As2O3 + CO2(g) -1.50 -2.97 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.81 -6.95 -2.14 MgSO4:7H2O + Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.21 -142.20 -1.00 H2S + Halite -9.44 -7.86 1.58 NaCl + Huntite -4.31 -34.28 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.57 -23.33 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.57 -8.59 -8.03 MgCO3 + Mirabilite -10.68 -11.79 -1.11 Na2SO4:10H2O + Nahcolite -5.66 -6.21 -0.55 NaHCO3 + Natron -12.12 -13.44 -1.31 Na2CO3:10H2O + Nesquehonite -2.97 -8.60 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -474.63 -520.93 -46.30 As2S3 + Portlandite -11.65 11.15 22.80 Ca(OH)2 + Realgar -186.55 -206.50 -19.94 AsS + Sulfur -105.83 -120.85 -15.03 S + Thenardite -11.61 -11.79 -0.18 Na2SO4 + Thermonatrite -13.56 -13.43 0.12 Na2CO3:H2O + Trona -18.85 -19.65 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 161, cumulative pore volumes 161.000000. +Beginning of advection time step 162, cumulative pore volumes 162.000000. +Beginning of advection time step 163, cumulative pore volumes 163.000000. +Beginning of advection time step 164, cumulative pore volumes 164.000000. +Beginning of advection time step 165, cumulative pore volumes 165.000000. +Beginning of advection time step 166, cumulative pore volumes 166.000000. +Beginning of advection time step 167, cumulative pore volumes 167.000000. +Beginning of advection time step 168, cumulative pore volumes 168.000000. +Beginning of advection time step 169, cumulative pore volumes 169.000000. +Beginning of advection time step 170, cumulative pore volumes 170.000000. +Beginning of advection time step 171, cumulative pore volumes 171.000000. +Beginning of advection time step 172, cumulative pore volumes 172.000000. +Beginning of advection time step 173, cumulative pore volumes 173.000000. +Beginning of advection time step 174, cumulative pore volumes 174.000000. +Beginning of advection time step 175, cumulative pore volumes 175.000000. +Beginning of advection time step 176, cumulative pore volumes 176.000000. +Beginning of advection time step 177, cumulative pore volumes 177.000000. +Beginning of advection time step 178, cumulative pore volumes 178.000000. +Beginning of advection time step 179, cumulative pore volumes 179.000000. +Beginning of advection time step 180, cumulative pore volumes 180.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.206e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.384e-03 Surface charge, eq + 1.278e-02 sigma, C/m**2 + 4.916e-02 psi, V + -1.913e+00 -F*psi/RT + 1.476e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 + Hfo_wOH2+ 1.292e-02 0.185 1.293e-02 -1.889 + Hfo_wO- 4.413e-03 0.063 4.413e-03 -2.355 + Hfo_wOHSO4-2 1.719e-03 0.025 1.719e-03 -2.765 + Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 + Hfo_wSO4- 2.232e-04 0.003 2.232e-04 -3.651 + Hfo_wHAsO4- 1.235e-06 0.000 1.235e-06 -5.908 + Hfo_wH2AsO4 1.035e-08 0.000 1.035e-08 -7.985 + Hfo_wOCa+ 9.467e-14 0.000 9.468e-14 -13.024 + Hfo_wOMg+ 7.451e-14 0.000 7.452e-14 -13.128 + Hfo_wH2AsO3 2.314e-33 0.000 2.314e-33 -32.636 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.337e-01 6.675e-01 6.675e-01 -0.000 + MgX2 1.657e-01 3.315e-01 3.315e-01 -0.000 + NaX 1.062e-03 1.062e-03 1.062e-03 -0.000 + HX 8.606e-06 8.606e-06 8.606e-06 -0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.646e-10 1.646e-10 + C 7.117e-03 7.117e-03 + Ca 1.835e-03 1.834e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.432e-03 1.432e-03 + Na 1.233e-04 1.233e-04 + S 2.351e-04 2.351e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.046 Charge balance + pe = 13.560 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.623e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.053e-03 + Total CO2 (mol/kg) = 7.117e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.004e-09 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 10 + Total H = 1.110125e+02 + Total O = 5.552487e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.230e-07 1.112e-07 -6.910 -6.954 -0.044 + H+ 9.842e-08 9.002e-08 -7.007 -7.046 -0.039 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.816e-37 + H3AsO3 1.800e-37 1.804e-37 -36.745 -36.744 0.001 + H2AsO3- 1.570e-39 1.419e-39 -38.804 -38.848 -0.044 + H4AsO3+ 0.000e+00 0.000e+00 -44.050 -44.094 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -46.326 -46.502 -0.176 + AsO3-3 0.000e+00 0.000e+00 -54.761 -55.157 -0.396 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.700 -925.744 -0.044 +As(5) 1.646e-10 + HAsO4-2 8.397e-11 5.598e-11 -10.076 -10.252 -0.176 + H2AsO4- 8.061e-11 7.284e-11 -10.094 -10.138 -0.044 + AsO4-3 3.467e-15 1.392e-15 -14.460 -14.856 -0.396 + H3AsO4 1.305e-15 1.308e-15 -14.884 -14.883 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 +C(4) 7.117e-03 + HCO3- 5.878e-03 5.330e-03 -2.231 -2.273 -0.043 + CO2 1.077e-03 1.079e-03 -2.968 -2.967 0.001 + CaHCO3+ 8.707e-05 7.868e-05 -4.060 -4.104 -0.044 + MgHCO3+ 6.287e-05 5.681e-05 -4.202 -4.246 -0.044 + CaCO3 5.372e-06 5.384e-06 -5.270 -5.269 0.001 + CO3-2 4.109e-06 2.777e-06 -5.386 -5.556 -0.170 + MgCO3 2.408e-06 2.414e-06 -5.618 -5.617 0.001 + NaHCO3 3.323e-07 3.331e-07 -6.478 -6.477 0.001 + NaCO3- 6.359e-09 5.746e-09 -8.197 -8.241 -0.044 +Ca 1.835e-03 + Ca+2 1.714e-03 1.157e-03 -2.766 -2.937 -0.171 + CaHCO3+ 8.707e-05 7.868e-05 -4.060 -4.104 -0.044 + CaSO4 2.804e-05 2.810e-05 -4.552 -4.551 0.001 + CaCO3 5.372e-06 5.384e-06 -5.270 -5.269 0.001 + CaOH+ 2.361e-09 2.133e-09 -8.627 -8.671 -0.044 + CaHSO4+ 1.640e-11 1.482e-11 -10.785 -10.829 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.432e-03 + Mg+2 1.341e-03 9.110e-04 -2.873 -3.040 -0.168 + MgHCO3+ 6.287e-05 5.681e-05 -4.202 -4.246 -0.044 + MgSO4 2.593e-05 2.599e-05 -4.586 -4.585 0.001 + MgCO3 2.408e-06 2.414e-06 -5.618 -5.617 0.001 + MgOH+ 4.065e-08 3.673e-08 -7.391 -7.435 -0.044 +Na 1.233e-04 + Na+ 1.228e-04 1.111e-04 -3.911 -3.954 -0.044 + NaHCO3 3.323e-07 3.331e-07 -6.478 -6.477 0.001 + NaSO4- 7.500e-08 6.777e-08 -7.125 -7.169 -0.044 + NaCO3- 6.359e-09 5.746e-09 -8.197 -8.241 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.056 -142.100 -0.044 + H2S 0.000e+00 0.000e+00 -142.205 -142.204 0.001 + S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 + S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 + S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 + S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 + S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 + S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.700 -925.744 -0.044 +S(6) 2.351e-04 + SO4-2 1.810e-04 1.217e-04 -3.742 -3.915 -0.173 + CaSO4 2.804e-05 2.810e-05 -4.552 -4.551 0.001 + MgSO4 2.593e-05 2.599e-05 -4.586 -4.585 0.001 + NaSO4- 7.500e-08 6.777e-08 -7.125 -7.169 -0.044 + HSO4- 1.179e-09 1.065e-09 -8.929 -8.973 -0.044 + CaHSO4+ 1.640e-11 1.482e-11 -10.785 -10.829 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.49 -6.85 -4.36 CaSO4 + Aragonite -0.16 -8.49 -8.34 CaCO3 + Arsenolite -72.11 -73.49 -1.38 As2O3 + Artinite -7.15 2.45 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -37.99 -29.77 8.23 As2O5 + As2S3(am) -476.02 -520.92 -44.90 As2S3 + As_native -86.03 -98.56 -12.53 As + Brucite -5.79 11.05 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.62 -38.52 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.01 -8.49 -8.48 CaCO3 + CH4(g) -140.56 -143.42 -2.86 CH4 + Claudetite -72.15 -73.49 -1.34 As2O3 + CO2(g) -1.50 -2.97 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O + Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.21 -142.20 -1.00 H2S + Halite -9.45 -7.87 1.58 NaCl + Huntite -4.32 -34.28 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.58 -23.34 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.57 -8.60 -8.03 MgCO3 + Mirabilite -10.71 -11.82 -1.11 Na2SO4:10H2O + Nahcolite -5.68 -6.23 -0.55 NaHCO3 + Natron -12.15 -13.47 -1.31 Na2CO3:10H2O + Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -474.62 -520.92 -46.30 As2S3 + Portlandite -11.65 11.15 22.80 Ca(OH)2 + Realgar -186.55 -206.49 -19.94 AsS + Sulfur -105.83 -120.85 -15.03 S + Thenardite -11.64 -11.82 -0.18 Na2SO4 + Thermonatrite -13.59 -13.46 0.12 Na2CO3:H2O + Trona -18.90 -19.69 -0.80 NaHCO3:Na2CO3:2H2O + +Beginning of advection time step 181, cumulative pore volumes 181.000000. +Beginning of advection time step 182, cumulative pore volumes 182.000000. +Beginning of advection time step 183, cumulative pore volumes 183.000000. +Beginning of advection time step 184, cumulative pore volumes 184.000000. +Beginning of advection time step 185, cumulative pore volumes 185.000000. +Beginning of advection time step 186, cumulative pore volumes 186.000000. +Beginning of advection time step 187, cumulative pore volumes 187.000000. +Beginning of advection time step 188, cumulative pore volumes 188.000000. +Beginning of advection time step 189, cumulative pore volumes 189.000000. +Beginning of advection time step 190, cumulative pore volumes 190.000000. +Beginning of advection time step 191, cumulative pore volumes 191.000000. +Beginning of advection time step 192, cumulative pore volumes 192.000000. +Beginning of advection time step 193, cumulative pore volumes 193.000000. +Beginning of advection time step 194, cumulative pore volumes 194.000000. +Beginning of advection time step 195, cumulative pore volumes 195.000000. +Beginning of advection time step 196, cumulative pore volumes 196.000000. +Beginning of advection time step 197, cumulative pore volumes 197.000000. +Beginning of advection time step 198, cumulative pore volumes 198.000000. +Beginning of advection time step 199, cumulative pore volumes 199.000000. +Beginning of advection time step 200, cumulative pore volumes 200.000000. + +Cell 1. + +Using solution 1. Solution after simulation 4. +Using exchange 1. Exchange assemblage after simulation 5. +Using surface 1. Surface assemblage after simulation 5. +Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 + Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.046e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.383e-03 Surface charge, eq + 1.278e-02 sigma, C/m**2 + 4.915e-02 psi, V + -1.913e+00 -F*psi/RT + 1.476e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 1.800e+04 m**2 for 3.000e+01 g + + +Hfo_w + 7.000e-02 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 + Hfo_wOH2+ 1.292e-02 0.185 1.292e-02 -1.889 + Hfo_wO- 4.413e-03 0.063 4.414e-03 -2.355 + Hfo_wOHSO4-2 1.719e-03 0.025 1.719e-03 -2.765 + Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 + Hfo_wSO4- 2.231e-04 0.003 2.232e-04 -3.651 + Hfo_wHAsO4- 1.234e-06 0.000 1.234e-06 -5.909 + Hfo_wH2AsO4 1.035e-08 0.000 1.035e-08 -7.985 + Hfo_wOCa+ 9.507e-14 0.000 9.508e-14 -13.022 + Hfo_wOMg+ 7.422e-14 0.000 7.422e-14 -13.129 + Hfo_wH2AsO3 2.314e-33 0.000 2.314e-33 -32.636 + +-----------------------------Exchange composition------------------------------ + +X 1.000e+00 mol + + Equiv- Equivalent Log + Species Moles alents Fraction Gamma + + CaX2 3.346e-01 6.693e-01 6.693e-01 0.000 + MgX2 1.648e-01 3.297e-01 3.297e-01 0.000 + NaX 1.058e-03 1.058e-03 1.058e-03 0.000 + HX 8.599e-06 8.599e-06 8.599e-06 0.000 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + As 1.646e-10 1.646e-10 + C 7.117e-03 7.117e-03 + Ca 1.841e-03 1.841e-03 + Cl 1.337e-04 1.337e-04 + Mg 1.426e-03 1.426e-03 + Na 1.228e-04 1.228e-04 + S 2.351e-04 2.351e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.046 Charge balance + pe = 13.559 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.624e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.053e-03 + Total CO2 (mol/kg) = 7.117e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 1.225e-08 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 10 + Total H = 1.110125e+02 + Total O = 5.552487e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.231e-07 1.112e-07 -6.910 -6.954 -0.044 + H+ 9.839e-08 9.000e-08 -7.007 -7.046 -0.039 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +As(3) 1.815e-37 + H3AsO3 1.800e-37 1.804e-37 -36.745 -36.744 0.001 + H2AsO3- 1.570e-39 1.419e-39 -38.804 -38.848 -0.044 + H4AsO3+ 0.000e+00 0.000e+00 -44.051 -44.095 -0.044 + HAsO3-2 0.000e+00 0.000e+00 -46.326 -46.502 -0.176 + AsO3-3 0.000e+00 0.000e+00 -54.760 -55.157 -0.396 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.701 -925.745 -0.044 +As(5) 1.646e-10 + HAsO4-2 8.400e-11 5.600e-11 -10.076 -10.252 -0.176 + H2AsO4- 8.061e-11 7.284e-11 -10.094 -10.138 -0.044 + AsO4-3 3.469e-15 1.393e-15 -14.460 -14.856 -0.396 + H3AsO4 1.305e-15 1.308e-15 -14.884 -14.883 0.001 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 +C(4) 7.117e-03 + HCO3- 5.879e-03 5.330e-03 -2.231 -2.273 -0.043 + CO2 1.076e-03 1.079e-03 -2.968 -2.967 0.001 + CaHCO3+ 8.741e-05 7.898e-05 -4.058 -4.102 -0.044 + MgHCO3+ 6.260e-05 5.656e-05 -4.203 -4.247 -0.044 + CaCO3 5.394e-06 5.406e-06 -5.268 -5.267 0.001 + CO3-2 4.111e-06 2.778e-06 -5.386 -5.556 -0.170 + MgCO3 2.398e-06 2.404e-06 -5.620 -5.619 0.001 + NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 + NaCO3- 6.335e-09 5.724e-09 -8.198 -8.242 -0.044 +Ca 1.841e-03 + Ca+2 1.721e-03 1.162e-03 -2.764 -2.935 -0.171 + CaHCO3+ 8.741e-05 7.898e-05 -4.058 -4.102 -0.044 + CaSO4 2.815e-05 2.821e-05 -4.551 -4.550 0.001 + CaCO3 5.394e-06 5.406e-06 -5.268 -5.267 0.001 + CaOH+ 2.371e-09 2.142e-09 -8.625 -8.669 -0.044 + CaHSO4+ 1.646e-11 1.487e-11 -10.784 -10.828 -0.044 +Cl 1.337e-04 + Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 +Mg 1.426e-03 + Mg+2 1.335e-03 9.069e-04 -2.875 -3.042 -0.168 + MgHCO3+ 6.260e-05 5.656e-05 -4.203 -4.247 -0.044 + MgSO4 2.582e-05 2.587e-05 -4.588 -4.587 0.001 + MgCO3 2.398e-06 2.404e-06 -5.620 -5.619 0.001 + MgOH+ 4.049e-08 3.658e-08 -7.393 -7.437 -0.044 +Na 1.228e-04 + Na+ 1.224e-04 1.107e-04 -3.912 -3.956 -0.044 + NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 + NaSO4- 7.471e-08 6.751e-08 -7.127 -7.171 -0.044 + NaCO3- 6.335e-09 5.724e-09 -8.198 -8.242 -0.044 +O(0) 4.375e-04 + O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -142.056 -142.100 -0.044 + H2S 0.000e+00 0.000e+00 -142.205 -142.204 0.001 + S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 + S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 + S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 + S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 + S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 + S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 + AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 + As3S4(HS)2- 0.000e+00 0.000e+00 -925.701 -925.745 -0.044 +S(6) 2.351e-04 + SO4-2 1.811e-04 1.217e-04 -3.742 -3.915 -0.173 + CaSO4 2.815e-05 2.821e-05 -4.551 -4.550 0.001 + MgSO4 2.582e-05 2.587e-05 -4.588 -4.587 0.001 + NaSO4- 7.471e-08 6.751e-08 -7.127 -7.171 -0.044 + HSO4- 1.178e-09 1.065e-09 -8.929 -8.973 -0.044 + CaHSO4+ 1.646e-11 1.487e-11 -10.784 -10.828 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.49 -6.85 -4.36 CaSO4 + Aragonite -0.16 -8.49 -8.34 CaCO3 + Arsenolite -72.11 -73.49 -1.38 As2O3 + Artinite -7.15 2.45 9.60 MgCO3:Mg(OH)2:3H2O + As2O5(cr) -37.99 -29.77 8.23 As2O5 + As2S3(am) -476.02 -520.92 -44.90 As2S3 + As_native -86.03 -98.56 -12.53 As + Brucite -5.79 11.05 16.84 Mg(OH)2 + Ca3(AsO4)2:4w -19.61 -38.52 -18.91 Ca3(AsO4)2:4H2O + Calcite -0.01 -8.49 -8.48 CaCO3 + CH4(g) -140.56 -143.42 -2.86 CH4 + Claudetite -72.15 -73.49 -1.34 As2O3 + CO2(g) -1.50 -2.97 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 + Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O + Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O + H2(g) -41.21 -44.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -141.21 -142.20 -1.00 H2S + Halite -9.46 -7.87 1.58 NaCl + Huntite -4.32 -34.29 -29.97 CaMg3(CO3)4 + Hydromagnesite -14.58 -23.35 -8.76 Mg5(CO3)4(OH)2:4H2O + Magnesite -0.57 -8.60 -8.03 MgCO3 + Mirabilite -10.71 -11.83 -1.11 Na2SO4:10H2O + Nahcolite -5.68 -6.23 -0.55 NaHCO3 + Natron -12.16 -13.47 -1.31 Na2CO3:10H2O + Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O + O2(g) -0.70 -3.66 -2.96 O2 + Orpiment -474.62 -520.92 -46.30 As2S3 + Portlandite -11.64 11.16 22.80 Ca(OH)2 + Realgar -186.55 -206.49 -19.94 AsS + Sulfur -105.83 -120.85 -15.03 S + Thenardite -11.65 -11.83 -0.18 Na2SO4 + Thermonatrite -13.59 -13.47 0.12 Na2CO3:H2O + Trona -18.90 -19.70 -0.80 NaHCO3:Na2CO3:2H2O + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 6. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex14.sel b/Sun/examples/ex14.sel new file mode 100644 index 00000000..48a4e9ba --- /dev/null +++ b/Sun/examples/ex14.sel @@ -0,0 +1,202 @@ + step m_Ca m_Mg m_Na umol_As pH + 1 4.6428e-01 1.6167e-01 5.4020e+00 5.0000e-02 5.3496e+00 + 1 5.2071e-04 3.6797e-04 1.0345e-01 2.9703e-04 7.0358e+00 + 2 4.3418e-05 3.0073e-05 2.7681e-02 1.4274e-02 8.4251e+00 + 3 1.6723e-05 1.0553e-05 1.5102e-02 1.7369e-01 9.0861e+00 + 4 1.3810e-05 8.4300e-06 1.2580e-02 3.4749e-01 9.2687e+00 + 5 1.3241e-05 8.0170e-06 1.1705e-02 4.2057e-01 9.3189e+00 + 6 1.3253e-05 8.0279e-06 1.1293e-02 4.3148e-01 9.3249e+00 + 7 1.3481e-05 8.1962e-06 1.1055e-02 4.1548e-01 9.3142e+00 + 8 1.3805e-05 8.4346e-06 1.0889e-02 3.9004e-01 9.2967e+00 + 9 1.4178e-05 8.7091e-06 1.0758e-02 3.6247e-01 9.2767e+00 + 10 1.4581e-05 9.0053e-06 1.0645e-02 3.3557e-01 9.2558e+00 + 11 1.5006e-05 9.3176e-06 1.0542e-02 3.1029e-01 9.2348e+00 + 12 1.5449e-05 9.6438e-06 1.0447e-02 2.8686e-01 9.2138e+00 + 13 1.5911e-05 9.9834e-06 1.0358e-02 2.6525e-01 9.1929e+00 + 14 1.6392e-05 1.0337e-05 1.0274e-02 2.4534e-01 9.1722e+00 + 15 1.6892e-05 1.0704e-05 1.0195e-02 2.2698e-01 9.1517e+00 + 16 1.7412e-05 1.1087e-05 1.0119e-02 2.1004e-01 9.1314e+00 + 17 1.7954e-05 1.1485e-05 1.0047e-02 1.9440e-01 9.1111e+00 + 18 1.8519e-05 1.1901e-05 9.9787e-03 1.7994e-01 9.0910e+00 + 19 1.9109e-05 1.2335e-05 9.9131e-03 1.6656e-01 9.0710e+00 + 20 1.9725e-05 1.2787e-05 9.8504e-03 1.5418e-01 9.0510e+00 + 21 2.0368e-05 1.3260e-05 9.7904e-03 1.4270e-01 9.0311e+00 + 22 2.1041e-05 1.3755e-05 9.7328e-03 1.3206e-01 9.0112e+00 + 23 2.1745e-05 1.4273e-05 9.6775e-03 1.2220e-01 8.9913e+00 + 24 2.2482e-05 1.4815e-05 9.6243e-03 1.1304e-01 8.9714e+00 + 25 2.3254e-05 1.5383e-05 9.5731e-03 1.0454e-01 8.9515e+00 + 26 2.4064e-05 1.5978e-05 9.5238e-03 9.6657e-02 8.9316e+00 + 27 2.4914e-05 1.6603e-05 9.4761e-03 8.9334e-02 8.9116e+00 + 28 2.5807e-05 1.7260e-05 9.4301e-03 8.2534e-02 8.8916e+00 + 29 2.6745e-05 1.7950e-05 9.3855e-03 7.6219e-02 8.8715e+00 + 30 2.7732e-05 1.8675e-05 9.3423e-03 7.0356e-02 8.8514e+00 + 31 2.8770e-05 1.9439e-05 9.3004e-03 6.4912e-02 8.8312e+00 + 32 2.9863e-05 2.0243e-05 9.2597e-03 5.9857e-02 8.8109e+00 + 33 3.1015e-05 2.1090e-05 9.2200e-03 5.5166e-02 8.7905e+00 + 34 3.2230e-05 2.1983e-05 9.1814e-03 5.0812e-02 8.7699e+00 + 35 3.3513e-05 2.2926e-05 9.1436e-03 4.6773e-02 8.7493e+00 + 36 3.4867e-05 2.3922e-05 9.1067e-03 4.3028e-02 8.7285e+00 + 37 3.6299e-05 2.4975e-05 9.0705e-03 3.9555e-02 8.7076e+00 + 38 3.7813e-05 2.6089e-05 9.0350e-03 3.6337e-02 8.6865e+00 + 39 3.9416e-05 2.7267e-05 9.0000e-03 3.3356e-02 8.6653e+00 + 40 4.1113e-05 2.8516e-05 8.9656e-03 3.0597e-02 8.6439e+00 + 41 4.2913e-05 2.9840e-05 8.9315e-03 2.8043e-02 8.6224e+00 + 42 4.4823e-05 3.1244e-05 8.8978e-03 2.5682e-02 8.6006e+00 + 43 4.6851e-05 3.2736e-05 8.8643e-03 2.3500e-02 8.5787e+00 + 44 4.9006e-05 3.4321e-05 8.8310e-03 2.1485e-02 8.5565e+00 + 45 5.1298e-05 3.6006e-05 8.7977e-03 1.9626e-02 8.5342e+00 + 46 5.3738e-05 3.7800e-05 8.7644e-03 1.7911e-02 8.5116e+00 + 47 5.6337e-05 3.9712e-05 8.7309e-03 1.6331e-02 8.4889e+00 + 48 5.9107e-05 4.1749e-05 8.6973e-03 1.4877e-02 8.4658e+00 + 49 6.2064e-05 4.3924e-05 8.6633e-03 1.3539e-02 8.4426e+00 + 50 6.5221e-05 4.6246e-05 8.6288e-03 1.2309e-02 8.4191e+00 + 51 6.8596e-05 4.8728e-05 8.5938e-03 1.1181e-02 8.3954e+00 + 52 7.2206e-05 5.1383e-05 8.5581e-03 1.0146e-02 8.3714e+00 + 53 7.6071e-05 5.4225e-05 8.5216e-03 9.1972e-03 8.3471e+00 + 54 8.0212e-05 5.7271e-05 8.4840e-03 8.3294e-03 8.3226e+00 + 55 8.4653e-05 6.0537e-05 8.4454e-03 7.5361e-03 8.2978e+00 + 56 8.9419e-05 6.4042e-05 8.4055e-03 6.8118e-03 8.2727e+00 + 57 9.4538e-05 6.7807e-05 8.3641e-03 6.1514e-03 8.2473e+00 + 58 1.0004e-04 7.1853e-05 8.3211e-03 5.5498e-03 8.2217e+00 + 59 1.0596e-04 7.6206e-05 8.2762e-03 5.0027e-03 8.1958e+00 + 60 1.1233e-04 8.0892e-05 8.2293e-03 4.5057e-03 8.1696e+00 + 61 1.1919e-04 8.5939e-05 8.1800e-03 4.0548e-03 8.1431e+00 + 62 1.2659e-04 9.1378e-05 8.1283e-03 3.6464e-03 8.1164e+00 + 63 1.3456e-04 9.7244e-05 8.0737e-03 3.2769e-03 8.0893e+00 + 64 1.4317e-04 1.0357e-04 8.0161e-03 2.9432e-03 8.0621e+00 + 65 1.5246e-04 1.1040e-04 7.9550e-03 2.6421e-03 8.0345e+00 + 66 1.6249e-04 1.1778e-04 7.8904e-03 2.3710e-03 8.0067e+00 + 67 1.7301e-04 1.2608e-04 7.8205e-03 2.1257e-03 7.9786e+00 + 68 1.8432e-04 1.3516e-04 7.7465e-03 1.9049e-03 7.9501e+00 + 69 1.9654e-04 1.4497e-04 7.6681e-03 1.7071e-03 7.9214e+00 + 70 2.0974e-04 1.5559e-04 7.5847e-03 1.5302e-03 7.8925e+00 + 71 2.2397e-04 1.6707e-04 7.4960e-03 1.3724e-03 7.8636e+00 + 72 2.3933e-04 1.7947e-04 7.4015e-03 1.2317e-03 7.8345e+00 + 73 2.5587e-04 1.9285e-04 7.3009e-03 1.1064e-03 7.8054e+00 + 74 2.7370e-04 2.0729e-04 7.1938e-03 9.9507e-04 7.7763e+00 + 75 2.9288e-04 2.2286e-04 7.0799e-03 8.9618e-04 7.7472e+00 + 76 3.1349e-04 2.3961e-04 6.9590e-03 8.0843e-04 7.7182e+00 + 77 3.3561e-04 2.5763e-04 6.8306e-03 7.3066e-04 7.6893e+00 + 78 3.5933e-04 2.7696e-04 6.6948e-03 6.6179e-04 7.6606e+00 + 79 3.8469e-04 2.9767e-04 6.5512e-03 6.0086e-04 7.6321e+00 + 80 4.1177e-04 3.1980e-04 6.3998e-03 5.4698e-04 7.6039e+00 + 81 4.4060e-04 3.4340e-04 6.2406e-03 4.9938e-04 7.5760e+00 + 82 4.7122e-04 3.6849e-04 6.0737e-03 4.5735e-04 7.5485e+00 + 83 5.0365e-04 3.9509e-04 5.8993e-03 4.2027e-04 7.5215e+00 + 84 5.3788e-04 4.2320e-04 5.7176e-03 3.8756e-04 7.4950e+00 + 85 5.7386e-04 4.5277e-04 5.5290e-03 3.5874e-04 7.4691e+00 + 86 6.1156e-04 4.8377e-04 5.3342e-03 3.3335e-04 7.4438e+00 + 87 6.5087e-04 5.1613e-04 5.1337e-03 3.1101e-04 7.4193e+00 + 88 6.9168e-04 5.4973e-04 4.9284e-03 2.9135e-04 7.3955e+00 + 89 7.3384e-04 5.8447e-04 4.7190e-03 2.7407e-04 7.3726e+00 + 90 7.7716e-04 6.2017e-04 4.5066e-03 2.5890e-04 7.3505e+00 + 91 8.2146e-04 6.5669e-04 4.2923e-03 2.4559e-04 7.3293e+00 + 92 8.6649e-04 6.9381e-04 4.0771e-03 2.3392e-04 7.3090e+00 + 93 9.1201e-04 7.3133e-04 3.8623e-03 2.2372e-04 7.2897e+00 + 94 9.5775e-04 7.6903e-04 3.6490e-03 2.1480e-04 7.2714e+00 + 95 1.0035e-03 8.0669e-04 3.4384e-03 2.0702e-04 7.2541e+00 + 96 1.0489e-03 8.4407e-04 3.2315e-03 2.0024e-04 7.2377e+00 + 97 1.0937e-03 8.8096e-04 3.0295e-03 1.9436e-04 7.2223e+00 + 98 1.1377e-03 9.1715e-04 2.8333e-03 1.8926e-04 7.2079e+00 + 99 1.1807e-03 9.5246e-04 2.6436e-03 1.8485e-04 7.1945e+00 + 100 1.2224e-03 9.8670e-04 2.4613e-03 1.8105e-04 7.1819e+00 + 101 1.2628e-03 1.0197e-03 2.2869e-03 1.7780e-04 7.1703e+00 + 102 1.3015e-03 1.0514e-03 2.1208e-03 1.7501e-04 7.1595e+00 + 103 1.3386e-03 1.0817e-03 1.9634e-03 1.7264e-04 7.1495e+00 + 104 1.3740e-03 1.1105e-03 1.8148e-03 1.7063e-04 7.1403e+00 + 105 1.4074e-03 1.1377e-03 1.6752e-03 1.6893e-04 7.1318e+00 + 106 1.4391e-03 1.1633e-03 1.5444e-03 1.6752e-04 7.1239e+00 + 107 1.4689e-03 1.1874e-03 1.4225e-03 1.6634e-04 7.1168e+00 + 108 1.4968e-03 1.2099e-03 1.3090e-03 1.6537e-04 7.1102e+00 + 109 1.5229e-03 1.2309e-03 1.2038e-03 1.6458e-04 7.1042e+00 + 110 1.5472e-03 1.2503e-03 1.1066e-03 1.6394e-04 7.0987e+00 + 111 1.5699e-03 1.2683e-03 1.0170e-03 1.6344e-04 7.0937e+00 + 112 1.5909e-03 1.2849e-03 9.3458e-04 1.6305e-04 7.0891e+00 + 113 1.6103e-03 1.3002e-03 8.5895e-04 1.6275e-04 7.0850e+00 + 114 1.6282e-03 1.3143e-03 7.8970e-04 1.6254e-04 7.0812e+00 + 115 1.6448e-03 1.3271e-03 7.2642e-04 1.6239e-04 7.0777e+00 + 116 1.6600e-03 1.3389e-03 6.6867e-04 1.6229e-04 7.0746e+00 + 117 1.6740e-03 1.3496e-03 6.1608e-04 1.6225e-04 7.0718e+00 + 118 1.6868e-03 1.3594e-03 5.6824e-04 1.6224e-04 7.0692e+00 + 119 1.6986e-03 1.3682e-03 5.2478e-04 1.6226e-04 7.0669e+00 + 120 1.7093e-03 1.3763e-03 4.8535e-04 1.6230e-04 7.0648e+00 + 121 1.7192e-03 1.3836e-03 4.4962e-04 1.6236e-04 7.0629e+00 + 122 1.7282e-03 1.3901e-03 4.1726e-04 1.6244e-04 7.0612e+00 + 123 1.7365e-03 1.3960e-03 3.8800e-04 1.6252e-04 7.0596e+00 + 124 1.7441e-03 1.4014e-03 3.6155e-04 1.6262e-04 7.0582e+00 + 125 1.7509e-03 1.4062e-03 3.3765e-04 1.6272e-04 7.0569e+00 + 126 1.7572e-03 1.4105e-03 3.1609e-04 1.6282e-04 7.0558e+00 + 127 1.7630e-03 1.4143e-03 2.9664e-04 1.6292e-04 7.0547e+00 + 128 1.7683e-03 1.4178e-03 2.7910e-04 1.6302e-04 7.0538e+00 + 129 1.7731e-03 1.4208e-03 2.6330e-04 1.6312e-04 7.0529e+00 + 130 1.7774e-03 1.4236e-03 2.4907e-04 1.6321e-04 7.0522e+00 + 131 1.7815e-03 1.4260e-03 2.3626e-04 1.6331e-04 7.0515e+00 + 132 1.7851e-03 1.4281e-03 2.2472e-04 1.6339e-04 7.0509e+00 + 133 1.7885e-03 1.4300e-03 2.1435e-04 1.6348e-04 7.0503e+00 + 134 1.7916e-03 1.4317e-03 2.0502e-04 1.6356e-04 7.0498e+00 + 135 1.7944e-03 1.4331e-03 1.9662e-04 1.6364e-04 7.0494e+00 + 136 1.7970e-03 1.4344e-03 1.8908e-04 1.6371e-04 7.0490e+00 + 137 1.7994e-03 1.4355e-03 1.8230e-04 1.6377e-04 7.0486e+00 + 138 1.8016e-03 1.4364e-03 1.7621e-04 1.6384e-04 7.0483e+00 + 139 1.8036e-03 1.4372e-03 1.7073e-04 1.6390e-04 7.0480e+00 + 140 1.8055e-03 1.4379e-03 1.6582e-04 1.6395e-04 7.0477e+00 + 141 1.8072e-03 1.4385e-03 1.6140e-04 1.6400e-04 7.0475e+00 + 142 1.8088e-03 1.4390e-03 1.5743e-04 1.6405e-04 7.0473e+00 + 143 1.8103e-03 1.4394e-03 1.5387e-04 1.6409e-04 7.0471e+00 + 144 1.8117e-03 1.4397e-03 1.5068e-04 1.6413e-04 7.0469e+00 + 145 1.8130e-03 1.4399e-03 1.4780e-04 1.6417e-04 7.0467e+00 + 146 1.8142e-03 1.4401e-03 1.4523e-04 1.6421e-04 7.0466e+00 + 147 1.8153e-03 1.4402e-03 1.4291e-04 1.6424e-04 7.0465e+00 + 148 1.8164e-03 1.4402e-03 1.4084e-04 1.6427e-04 7.0464e+00 + 149 1.8174e-03 1.4402e-03 1.3897e-04 1.6429e-04 7.0463e+00 + 150 1.8183e-03 1.4402e-03 1.3730e-04 1.6432e-04 7.0462e+00 + 151 1.8192e-03 1.4401e-03 1.3580e-04 1.6434e-04 7.0461e+00 + 152 1.8200e-03 1.4400e-03 1.3445e-04 1.6436e-04 7.0461e+00 + 153 1.8208e-03 1.4399e-03 1.3325e-04 1.6438e-04 7.0460e+00 + 154 1.8216e-03 1.4397e-03 1.3216e-04 1.6440e-04 7.0459e+00 + 155 1.8223e-03 1.4396e-03 1.3119e-04 1.6441e-04 7.0459e+00 + 156 1.8230e-03 1.4394e-03 1.3032e-04 1.6443e-04 7.0459e+00 + 157 1.8236e-03 1.4391e-03 1.2953e-04 1.6444e-04 7.0458e+00 + 158 1.8243e-03 1.4389e-03 1.2883e-04 1.6446e-04 7.0458e+00 + 159 1.8249e-03 1.4386e-03 1.2820e-04 1.6447e-04 7.0458e+00 + 160 1.8255e-03 1.4384e-03 1.2763e-04 1.6448e-04 7.0457e+00 + 161 1.8260e-03 1.4381e-03 1.2713e-04 1.6449e-04 7.0457e+00 + 162 1.8266e-03 1.4378e-03 1.2667e-04 1.6450e-04 7.0457e+00 + 163 1.8271e-03 1.4375e-03 1.2626e-04 1.6451e-04 7.0457e+00 + 164 1.8276e-03 1.4372e-03 1.2590e-04 1.6451e-04 7.0457e+00 + 165 1.8281e-03 1.4369e-03 1.2557e-04 1.6452e-04 7.0457e+00 + 166 1.8286e-03 1.4366e-03 1.2527e-04 1.6453e-04 7.0457e+00 + 167 1.8291e-03 1.4363e-03 1.2501e-04 1.6453e-04 7.0456e+00 + 168 1.8296e-03 1.4360e-03 1.2477e-04 1.6454e-04 7.0456e+00 + 169 1.8300e-03 1.4356e-03 1.2456e-04 1.6454e-04 7.0456e+00 + 170 1.8305e-03 1.4353e-03 1.2437e-04 1.6455e-04 7.0456e+00 + 171 1.8309e-03 1.4350e-03 1.2420e-04 1.6455e-04 7.0456e+00 + 172 1.8313e-03 1.4347e-03 1.2404e-04 1.6456e-04 7.0456e+00 + 173 1.8318e-03 1.4343e-03 1.2390e-04 1.6456e-04 7.0456e+00 + 174 1.8322e-03 1.4340e-03 1.2378e-04 1.6456e-04 7.0456e+00 + 175 1.8326e-03 1.4337e-03 1.2367e-04 1.6457e-04 7.0456e+00 + 176 1.8330e-03 1.4333e-03 1.2357e-04 1.6457e-04 7.0456e+00 + 177 1.8334e-03 1.4330e-03 1.2348e-04 1.6457e-04 7.0456e+00 + 178 1.8338e-03 1.4327e-03 1.2340e-04 1.6458e-04 7.0456e+00 + 179 1.8342e-03 1.4323e-03 1.2333e-04 1.6458e-04 7.0457e+00 + 180 1.8346e-03 1.4320e-03 1.2326e-04 1.6458e-04 7.0457e+00 + 181 1.8349e-03 1.4317e-03 1.2321e-04 1.6458e-04 7.0457e+00 + 182 1.8353e-03 1.4313e-03 1.2315e-04 1.6459e-04 7.0457e+00 + 183 1.8357e-03 1.4310e-03 1.2311e-04 1.6459e-04 7.0457e+00 + 184 1.8360e-03 1.4307e-03 1.2306e-04 1.6459e-04 7.0457e+00 + 185 1.8364e-03 1.4304e-03 1.2303e-04 1.6459e-04 7.0457e+00 + 186 1.8368e-03 1.4300e-03 1.2299e-04 1.6460e-04 7.0457e+00 + 187 1.8371e-03 1.4297e-03 1.2296e-04 1.6460e-04 7.0457e+00 + 188 1.8375e-03 1.4294e-03 1.2294e-04 1.6460e-04 7.0457e+00 + 189 1.8378e-03 1.4291e-03 1.2291e-04 1.6460e-04 7.0457e+00 + 190 1.8382e-03 1.4287e-03 1.2289e-04 1.6460e-04 7.0457e+00 + 191 1.8385e-03 1.4284e-03 1.2287e-04 1.6460e-04 7.0457e+00 + 192 1.8388e-03 1.4281e-03 1.2285e-04 1.6461e-04 7.0457e+00 + 193 1.8392e-03 1.4278e-03 1.2284e-04 1.6461e-04 7.0457e+00 + 194 1.8395e-03 1.4275e-03 1.2282e-04 1.6461e-04 7.0457e+00 + 195 1.8398e-03 1.4272e-03 1.2281e-04 1.6461e-04 7.0457e+00 + 196 1.8402e-03 1.4269e-03 1.2280e-04 1.6461e-04 7.0458e+00 + 197 1.8405e-03 1.4266e-03 1.2279e-04 1.6461e-04 7.0458e+00 + 198 1.8408e-03 1.4263e-03 1.2278e-04 1.6462e-04 7.0458e+00 + 199 1.8411e-03 1.4260e-03 1.2277e-04 1.6462e-04 7.0458e+00 + 200 1.8415e-03 1.4257e-03 1.2276e-04 1.6462e-04 7.0458e+00 diff --git a/Sun/examples/ex15.log b/Sun/examples/ex15.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex15.out b/Sun/examples/ex15.out new file mode 100644 index 00000000..fd32cad1 --- /dev/null +++ b/Sun/examples/ex15.out @@ -0,0 +1,2299 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex15 + Output file: ex15.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex15.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 15.--1D Transport: Kinetic Biodegradation, Cell Growth, and Sorption + *********** + PLEASE NOTE: This problem requires database file ex15.dat!! + *********** + SOLUTION 0 Pulse solution with NTA and cobalt + units umol/L + pH 6 + C .49 + O(0) 62.5 + Nta 5.23 + Co 5.23 + Na 1000 + Cl 1000 + END +----- +TITLE +----- + + Example 15.--1D Transport: Kinetic Biodegradation, Cell Growth, and Sorption +*********** +PLEASE NOTE: This problem requires database file ex15.dat!! +*********** + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. Pulse solution with NTA and cobalt + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.900e-07 4.900e-07 + Cl 1.000e-03 1.000e-03 + Co 5.230e-06 5.230e-06 + Na 1.000e-03 1.000e-03 + Nta 5.230e-06 5.230e-06 + O(0) 6.250e-05 6.250e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.005e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.539e-05 + Total CO2 (mol/kg) = 4.900e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.954e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 + Iterations = 6 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + O(-2)/O(0) 14.3937 0.8515 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 + OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 4.900e-07 + CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 + HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 5.230e-06 + CoNta- 4.793e-06 4.793e-06 -5.319 -5.319 -0.000 + Co+2 4.370e-07 4.370e-07 -6.360 -6.360 -0.000 + CoOH+ 8.719e-11 8.719e-11 -10.060 -10.060 -0.000 + CoOHNta-2 3.024e-11 3.024e-11 -10.519 -10.519 -0.000 + CoNta2-4 6.618e-14 6.618e-14 -13.179 -13.179 -0.000 + Co(OH)2 5.501e-18 5.501e-18 -17.260 -17.260 0.000 + Co(OH)3- 1.382e-20 1.382e-20 -19.860 -19.860 -0.000 +H(0) 1.416e-23 + H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 5.230e-06 + CoNta- 4.793e-06 4.793e-06 -5.319 -5.319 -0.000 + HNta-2 4.366e-07 4.366e-07 -6.360 -6.360 -0.000 + H2Nta- 4.366e-10 4.366e-10 -9.360 -9.360 -0.000 + CoOHNta-2 3.024e-11 3.024e-11 -10.519 -10.519 -0.000 + Nta-3 2.188e-11 2.188e-11 -10.660 -10.660 -0.000 + CoNta2-4 6.618e-14 6.618e-14 -13.179 -13.179 -0.000 + H3Nta 1.738e-14 1.738e-14 -13.760 -13.760 0.000 +O(0) 6.250e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1-10 Background solution initially filling column # 1-20 + units umol/L + pH 6 + C .49 + O(0) 62.5 + Na 1000 + Cl 1000 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Background solution initially filling column + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.900e-07 4.900e-07 + Cl 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + O(0) 6.250e-05 6.250e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.414e-07 + Total CO2 (mol/kg) = 4.900e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 4 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + O(-2)/O(0) 14.3937 0.8515 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 + OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 4.900e-07 + CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 + HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +H(0) 1.416e-23 + H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +O(0) 6.250e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + RATES Rate expressions for the four kinetic reactions + HNTA-2 + start + 10 Ks = 7.64e-7 + 20 Ka = 6.25e-6 + 30 qm = 1.407e-3/3600 + 40 f1 = MOL("HNta-2")/(Ks + MOL("HNta-2")) + 50 f2 = MOL("O2")/(Ka + MOL("O2")) + 60 rate = -qm * KIN("Biomass") * f1 * f2 + 70 moles = rate * TIME + 80 PUT(rate, 1) # save the rate for use in Biomass rate calculation + 90 SAVE moles + end + Biomass + start + 10 Y = 65.14 + 20 b = 0.00208/3600 + 30 rate = GET(1) # uses rate calculated in HTNA-2 rate calculation + 40 rate = -Y*rate -b*M + 50 moles = -rate * TIME + 60 if (M + moles) < 0 then moles = -M + 70 SAVE moles + end + Co_sorption + start + 10 km = 1/3600 + 20 kd = 5.07e-3 + 30 solids = 3.75e3 + 40 rate = -km*(MOL("Co+2") - (M/solids)/kd) + 50 moles = rate * TIME + 60 if (M - moles) < 0 then moles = M + 70 SAVE moles + end + CoNta_sorption + start + 10 km = 1/3600 + 20 kd = 5.33e-4 + 30 solids = 3.75e3 + 40 rate = -km*(MOL("CoNta-") - (M/solids)/kd) + 50 moles = rate * TIME + 60 if (M - moles) < 0 then moles = M + 70 SAVE moles + end + KINETICS 1-10 Four kinetic reactions for all cells # 1-20 + HNTA-2 + formula C -3.12 H -1.968 O -4.848 N -0.424 Nta 1. + Biomass + formula H 0.0 + m 1.36e-4 + Co_sorption + formula CoCl2 + m 0.0 + tol 1e-11 + CoNta_sorption + formula NaCoNta + m 0.0 + tol 1e-11 + SELECTED_OUTPUT + file ex15.sel + molalities Nta-3 CoNta- HNta-2 Co+2 + USER_PUNCH + heading hours Co_sorb CoNta_sorb Biomass + start + 10 punch TOTAL_TIME/3600 + 1800/3600 # TOTAL_TIME/3600 + 900/3600 + 20 punch KIN("Co_sorption")/3.75e3 + 30 punch KIN("CoNta_sorption")/3.75e3 + 40 punch KIN("Biomass") + end + TRANSPORT First 20 hours have NTA and cobalt in infilling solution + cells 10 # 20 + length 1 # 0.5 + shifts 20 # 40 + time_step 3600 # 1800 + flow_direction forward + boundary_conditions flux flux + dispersivity .05 + correct_disp true + diffusion_coefficient 0.0e-9 + punch_cells 10 # 20 + punch_frequency 1 # 2 + print_cells 10 # 20 + print_frequency 5 # 10 + END +WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 10. +WARNING: Dispersivities were read for 1 cells. Last value is used till cell 10. +------------------------------------ +Beginning of transport calculations. +------------------------------------ + +------------------------------- +Equilibrating initial solutions +------------------------------- + +Using solution 10. Background solution initially filling column + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.900e-07 4.900e-07 + Cl 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.000 Charge balance + pe = 14.394 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.414e-07 + Total CO2 (mol/kg) = 4.900e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 + OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 4.900e-07 + CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 + HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +O(0) 6.250e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 1. + +Transport step 1. Mixrun 1. + +Transport step 2. + +Transport step 2. Mixrun 1. + +Transport step 3. + +Transport step 3. Mixrun 1. + +Transport step 4. + +Transport step 4. Mixrun 1. + +Transport step 5. + +Transport step 5. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 3. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 3. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 18000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 9.570e-14 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass -2.804e-07 1.346e-04 H 0 + Co_sorption 2.317e-14 2.317e-14 CoCl2 1 + CoNta_sorption 5.391e-19 5.391e-19 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.900e-07 4.900e-07 + Cl 1.000e-03 1.000e-03 + Co 2.318e-14 2.318e-14 + N 4.652e-13 4.652e-13 + Na 1.000e-03 1.000e-03 + Nta 8.316e-13 8.316e-13 + +----------------------------Description of solution---------------------------- + + pH = 6.000 Charge balance + pe = 14.394 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.414e-07 + Total CO2 (mol/kg) = 4.900e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 + OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 4.900e-07 + CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 + HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 2.318e-14 + Co+2 2.317e-14 2.317e-14 -13.635 -13.635 -0.000 + CoOH+ 4.623e-18 4.623e-18 -17.335 -17.335 -0.000 + CoNta- 4.836e-19 4.836e-19 -18.316 -18.316 -0.000 + CoOHNta-2 3.051e-24 3.051e-24 -23.516 -23.516 -0.000 + Co(OH)2 2.917e-25 2.917e-25 -24.535 -24.535 0.000 + Co(OH)3- 7.327e-28 7.327e-28 -27.135 -27.135 -0.000 + CoNta2-4 1.270e-32 1.270e-32 -31.896 -31.896 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +N 4.652e-13 + NH4+ 4.649e-13 4.649e-13 -12.333 -12.333 -0.000 + NH3 2.330e-16 2.330e-16 -15.633 -15.633 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 8.316e-13 + HNta-2 8.308e-13 8.308e-13 -12.081 -12.081 -0.000 + H2Nta- 8.308e-16 8.308e-16 -15.081 -15.081 -0.000 + Nta-3 4.164e-17 4.164e-17 -16.381 -16.381 -0.000 + CoNta- 4.836e-19 4.836e-19 -18.316 -18.316 -0.000 + H3Nta 3.307e-20 3.307e-20 -19.481 -19.481 0.000 + CoOHNta-2 3.051e-24 3.051e-24 -23.516 -23.516 -0.000 + CoNta2-4 1.270e-32 1.270e-32 -31.896 -31.896 -0.000 +O(0) 6.250e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 6. + +Transport step 6. Mixrun 1. + +Transport step 7. + +Transport step 7. Mixrun 1. + +Transport step 8. + +Transport step 8. Mixrun 1. + +Transport step 9. + +Transport step 9. Mixrun 1. + +Transport step 10. + +Transport step 10. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 3. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 3. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 36000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 2.135e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 1.110e-06 1.356e-04 H 0 + Co_sorption 1.871e-09 3.691e-09 CoCl2 1 + CoNta_sorption 7.149e-09 9.228e-09 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.541e-06 1.541e-06 + Cl 9.992e-04 9.992e-04 + Co 9.656e-09 9.656e-09 + N 1.429e-07 1.429e-07 + Na 9.967e-04 9.967e-04 + Nta 1.196e-07 1.196e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.237 Charge balance + pe = 14.155 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.989e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.439e-06 + Total CO2 (mol/kg) = 1.541e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.646e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.13 + Iterations = 25 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 5.796e-07 5.796e-07 -6.237 -6.237 -0.000 + OH- 1.725e-08 1.725e-08 -7.763 -7.763 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 1.541e-06 + CO2 8.705e-07 8.705e-07 -6.060 -6.060 0.000 + HCO3- 6.709e-07 6.709e-07 -6.173 -6.173 -0.000 + CO3-2 5.414e-11 5.414e-11 -10.266 -10.266 -0.000 +Cl 9.992e-04 + Cl- 9.992e-04 9.992e-04 -3.000 -3.000 -0.000 +Co 9.656e-09 + CoNta- 8.000e-09 8.000e-09 -8.097 -8.097 -0.000 + Co+2 1.655e-09 1.655e-09 -8.781 -8.781 -0.000 + CoOH+ 5.698e-13 5.698e-13 -12.244 -12.244 -0.000 + CoOHNta-2 8.710e-14 8.710e-14 -13.060 -13.060 -0.000 + CoNta2-4 4.869e-17 4.869e-17 -16.313 -16.313 -0.000 + Co(OH)2 6.203e-20 6.203e-20 -19.207 -19.207 0.000 + Co(OH)3- 2.688e-22 2.688e-22 -21.571 -21.571 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.934 -43.934 0.000 +N 1.429e-07 + NH4+ 1.428e-07 1.428e-07 -6.845 -6.845 -0.000 + NH3 1.235e-10 1.235e-10 -9.908 -9.908 0.000 +Na 9.967e-04 + Na+ 9.967e-04 9.967e-04 -3.001 -3.001 -0.000 +Nta 1.196e-07 + HNta-2 1.115e-07 1.115e-07 -6.953 -6.953 -0.000 + CoNta- 8.000e-09 8.000e-09 -8.097 -8.097 -0.000 + H2Nta- 6.464e-11 6.464e-11 -10.190 -10.190 -0.000 + Nta-3 9.645e-12 9.645e-12 -11.016 -11.016 -0.000 + CoOHNta-2 8.710e-14 8.710e-14 -13.060 -13.060 -0.000 + H3Nta 1.491e-15 1.491e-15 -14.826 -14.826 0.000 + CoNta2-4 4.869e-17 4.869e-17 -16.313 -16.313 -0.000 +O(0) 6.141e-05 + O2 3.071e-05 3.071e-05 -4.513 -4.513 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 11. + +Transport step 11. Mixrun 1. + +Transport step 12. + +Transport step 12. Mixrun 1. + +Transport step 13. + +Transport step 13. Mixrun 1. + +Transport step 14. + +Transport step 14. Mixrun 1. + +Transport step 15. + +Transport step 15. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 3. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 3. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 54000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 4.019e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 2.318e-06 1.453e-04 H 0 + Co_sorption 1.090e-08 3.661e-08 CoCl2 1 + CoNta_sorption 9.432e-08 2.656e-07 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.330e-06 2.330e-06 + Cl 9.985e-04 9.985e-04 + Co 1.862e-07 1.862e-07 + N 2.500e-07 2.500e-07 + Na 9.958e-04 9.958e-04 + Nta 4.001e-07 4.001e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.448 Charge balance + pe = 13.942 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.987e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 6.603e-06 + Total CO2 (mol/kg) = 2.330e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.954e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 + Iterations = 21 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.564e-07 3.564e-07 -6.448 -6.448 -0.000 + OH- 2.806e-08 2.806e-08 -7.552 -7.552 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.330e-06 + HCO3- 1.296e-06 1.296e-06 -5.887 -5.887 -0.000 + CO2 1.034e-06 1.034e-06 -5.985 -5.985 0.000 + CO3-2 1.700e-10 1.700e-10 -9.769 -9.769 -0.000 +Cl 9.985e-04 + Cl- 9.985e-04 9.985e-04 -3.001 -3.001 -0.000 +Co 1.862e-07 + CoNta- 1.751e-07 1.751e-07 -6.757 -6.757 -0.000 + Co+2 1.105e-08 1.105e-08 -7.957 -7.957 -0.000 + CoOH+ 6.187e-12 6.187e-12 -11.209 -11.209 -0.000 + CoOHNta-2 3.100e-12 3.100e-12 -11.509 -11.509 -0.000 + CoNta2-4 3.494e-15 3.494e-15 -14.457 -14.457 -0.000 + Co(OH)2 1.095e-18 1.095e-18 -17.960 -17.960 0.000 + Co(OH)3- 7.718e-21 7.718e-21 -20.112 -20.112 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.931 -43.931 0.000 +N 2.500e-07 + NH4+ 2.497e-07 2.497e-07 -6.603 -6.603 -0.000 + NH3 3.511e-10 3.511e-10 -9.455 -9.455 0.000 +Na 9.958e-04 + Na+ 9.958e-04 9.958e-04 -3.002 -3.002 -0.000 +Nta 4.001e-07 + HNta-2 2.249e-07 2.249e-07 -6.648 -6.648 -0.000 + CoNta- 1.751e-07 1.751e-07 -6.757 -6.757 -0.000 + H2Nta- 8.014e-11 8.014e-11 -10.096 -10.096 -0.000 + Nta-3 3.162e-11 3.162e-11 -10.500 -10.500 -0.000 + CoOHNta-2 3.100e-12 3.100e-12 -11.509 -11.509 -0.000 + CoNta2-4 3.494e-15 3.494e-15 -14.457 -14.457 -0.000 + H3Nta 1.137e-15 1.137e-15 -14.944 -14.944 0.000 +O(0) 6.059e-05 + O2 3.030e-05 3.030e-05 -4.519 -4.519 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 16. + +Transport step 16. Mixrun 1. + +Transport step 17. + +Transport step 17. Mixrun 1. + +Transport step 18. + +Transport step 18. Mixrun 1. + +Transport step 19. + +Transport step 19. Mixrun 1. + +Transport step 20. + +Transport step 20. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 3. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 3. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 72000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 4.950e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 2.897e-06 1.588e-04 H 0 + Co_sorption 2.585e-08 1.347e-07 CoCl2 1 + CoNta_sorption 2.379e-07 1.169e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.638e-06 2.638e-06 + Cl 9.982e-04 9.982e-04 + Co 7.184e-07 7.184e-07 + N 2.918e-07 2.918e-07 + Na 9.965e-04 9.965e-04 + Nta 9.571e-07 9.571e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.540 Charge balance + pe = 13.850 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.994e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.227e-06 + Total CO2 (mol/kg) = 2.638e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.954e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 + Iterations = 51 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.887e-07 2.887e-07 -6.540 -6.540 -0.000 + OH- 3.464e-08 3.464e-08 -7.460 -7.460 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.638e-06 + HCO3- 1.602e-06 1.602e-06 -5.795 -5.795 -0.000 + CO2 1.035e-06 1.035e-06 -5.985 -5.985 0.000 + CO3-2 2.596e-10 2.596e-10 -9.586 -9.586 -0.000 +Cl 9.982e-04 + Cl- 9.982e-04 9.982e-04 -3.001 -3.001 -0.000 +Co 7.184e-07 + CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 + Co+2 2.952e-08 2.952e-08 -7.530 -7.530 -0.000 + CoOH+ 2.040e-11 2.040e-11 -10.690 -10.690 -0.000 + CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 + CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 + Co(OH)2 4.459e-18 4.459e-18 -17.351 -17.351 0.000 + Co(OH)3- 3.880e-20 3.880e-20 -19.411 -19.411 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 +N 2.918e-07 + NH4+ 2.913e-07 2.913e-07 -6.536 -6.536 -0.000 + NH3 5.058e-10 5.058e-10 -9.296 -9.296 0.000 +Na 9.965e-04 + Na+ 9.965e-04 9.965e-04 -3.002 -3.002 -0.000 +Nta 9.571e-07 + CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 + HNta-2 2.682e-07 2.682e-07 -6.572 -6.572 -0.000 + H2Nta- 7.742e-11 7.742e-11 -10.111 -10.111 -0.000 + Nta-3 4.656e-11 4.656e-11 -10.332 -10.332 -0.000 + CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 + CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 + H3Nta 8.897e-16 8.897e-16 -15.051 -15.051 0.000 +O(0) 6.027e-05 + O2 3.014e-05 3.014e-05 -4.521 -4.521 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + PRINT + selected_output false + SOLUTION 0 New infilling solution, same as background solution + units umol/L + pH 6 + C .49 + O(0) 62.5 + Na 1000 + Cl 1000 + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 0. New infilling solution, same as background solution + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.900e-07 4.900e-07 + Cl 1.000e-03 1.000e-03 + Na 1.000e-03 1.000e-03 + O(0) 6.250e-05 6.250e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.414e-07 + Total CO2 (mol/kg) = 4.900e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 4 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + O(-2)/O(0) 14.3937 0.8515 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 + OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 4.900e-07 + CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 + HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +H(0) 1.416e-23 + H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +O(0) 6.250e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 5. +------------------------------------ + + PRINT + selected_output true + TRANSPORT Last 55 hours with background infilling solution + shifts 55 # 110 + END +------------------------------------ +Column data retained from former run +------------------------------------ + +------------------------------------ +Beginning of transport calculations. +------------------------------------ + +------------------------------- +Equilibrating initial solutions +------------------------------- + +Using solution 10. Solution after simulation 3. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.638e-06 2.638e-06 + Cl 9.982e-04 9.982e-04 + Co 7.184e-07 7.184e-07 + N 2.918e-07 2.918e-07 + Na 9.965e-04 9.965e-04 + Nta 9.571e-07 9.571e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.540 Charge balance + pe = 13.850 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.994e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.227e-06 + Total CO2 (mol/kg) = 2.638e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.954e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.887e-07 2.887e-07 -6.540 -6.540 -0.000 + OH- 3.464e-08 3.464e-08 -7.460 -7.460 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.638e-06 + HCO3- 1.602e-06 1.602e-06 -5.795 -5.795 -0.000 + CO2 1.035e-06 1.035e-06 -5.985 -5.985 0.000 + CO3-2 2.596e-10 2.596e-10 -9.586 -9.586 -0.000 +Cl 9.982e-04 + Cl- 9.982e-04 9.982e-04 -3.001 -3.001 -0.000 +Co 7.184e-07 + CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 + Co+2 2.952e-08 2.952e-08 -7.530 -7.530 -0.000 + CoOH+ 2.040e-11 2.040e-11 -10.690 -10.690 -0.000 + CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 + CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 + Co(OH)2 4.459e-18 4.459e-18 -17.351 -17.351 0.000 + Co(OH)3- 3.880e-20 3.880e-20 -19.411 -19.411 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 +N 2.918e-07 + NH4+ 2.913e-07 2.913e-07 -6.536 -6.536 -0.000 + NH3 5.058e-10 5.058e-10 -9.296 -9.296 0.000 +Na 9.965e-04 + Na+ 9.965e-04 9.965e-04 -3.002 -3.002 -0.000 +Nta 9.571e-07 + CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 + HNta-2 2.682e-07 2.682e-07 -6.572 -6.572 -0.000 + H2Nta- 7.742e-11 7.742e-11 -10.111 -10.111 -0.000 + Nta-3 4.656e-11 4.656e-11 -10.332 -10.332 -0.000 + CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 + CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 + H3Nta 8.897e-16 8.897e-16 -15.051 -15.051 0.000 +O(0) 6.027e-05 + O2 3.014e-05 3.014e-05 -4.521 -4.521 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 1. + +Transport step 1. Mixrun 1. + +Transport step 2. + +Transport step 2. Mixrun 1. + +Transport step 3. + +Transport step 3. Mixrun 1. + +Transport step 4. + +Transport step 4. Mixrun 1. + +Transport step 5. + +Transport step 5. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 90000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 5.582e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 3.276e-06 1.744e-04 H 0 + Co_sorption 4.161e-08 3.117e-07 CoCl2 1 + CoNta_sorption 3.270e-07 2.663e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.855e-06 2.855e-06 + Cl 9.981e-04 9.981e-04 + Co 1.525e-06 1.525e-06 + N 3.213e-07 3.213e-07 + Na 9.973e-04 9.973e-04 + Nta 1.754e-06 1.754e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.593 Charge balance + pe = 13.797 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.000e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.229e-05 + Total CO2 (mol/kg) = 2.855e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.954e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 + Iterations = 49 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.555e-07 2.555e-07 -6.593 -6.593 -0.000 + OH- 3.914e-08 3.914e-08 -7.407 -7.407 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.855e-06 + HCO3- 1.816e-06 1.816e-06 -5.741 -5.741 -0.000 + CO2 1.039e-06 1.039e-06 -5.984 -5.984 0.000 + CO3-2 3.324e-10 3.324e-10 -9.478 -9.478 -0.000 +Cl 9.981e-04 + Cl- 9.981e-04 9.981e-04 -3.001 -3.001 -0.000 +Co 1.525e-06 + CoNta- 1.472e-06 1.472e-06 -5.832 -5.832 -0.000 + Co+2 5.314e-08 5.314e-08 -7.275 -7.275 -0.000 + CoOH+ 4.150e-11 4.150e-11 -10.382 -10.382 -0.000 + CoOHNta-2 3.634e-11 3.634e-11 -10.440 -10.440 -0.000 + CoNta2-4 5.131e-14 5.131e-14 -13.290 -13.290 -0.000 + Co(OH)2 1.025e-17 1.025e-17 -16.989 -16.989 0.000 + Co(OH)3- 1.008e-19 1.008e-19 -18.997 -18.997 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.929 -43.929 0.000 +N 3.213e-07 + NH4+ 3.207e-07 3.207e-07 -6.494 -6.494 -0.000 + NH3 6.291e-10 6.291e-10 -9.201 -9.201 0.000 +Na 9.973e-04 + Na+ 9.973e-04 9.973e-04 -3.001 -3.001 -0.000 +Nta 1.754e-06 + CoNta- 1.472e-06 1.472e-06 -5.832 -5.832 -0.000 + HNta-2 2.817e-07 2.817e-07 -6.550 -6.550 -0.000 + H2Nta- 7.197e-11 7.197e-11 -10.143 -10.143 -0.000 + Nta-3 5.526e-11 5.526e-11 -10.258 -10.258 -0.000 + CoOHNta-2 3.634e-11 3.634e-11 -10.440 -10.440 -0.000 + CoNta2-4 5.131e-14 5.131e-14 -13.290 -13.290 -0.000 + H3Nta 7.320e-16 7.320e-16 -15.136 -15.136 0.000 +O(0) 6.005e-05 + O2 3.002e-05 3.002e-05 -4.523 -4.523 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 6. + +Transport step 6. Mixrun 1. + +Transport step 7. + +Transport step 7. Mixrun 1. + +Transport step 8. + +Transport step 8. Mixrun 1. + +Transport step 9. + +Transport step 9. Mixrun 1. + +Transport step 10. + +Transport step 10. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 108000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 5.493e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 3.184e-06 1.911e-04 H 0 + Co_sorption 5.379e-08 5.596e-07 CoCl2 1 + CoNta_sorption 3.109e-07 4.300e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.617e-06 2.617e-06 + Cl 9.984e-04 9.984e-04 + Co 2.356e-06 2.356e-06 + N 2.891e-07 2.891e-07 + Na 1.002e-03 1.002e-03 + Nta 2.524e-06 2.524e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.680 Charge balance + pe = 13.710 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.003e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.418e-05 + Total CO2 (mol/kg) = 2.617e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -4.697e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 47 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.092e-07 2.092e-07 -6.680 -6.680 -0.000 + OH- 4.781e-08 4.781e-08 -7.321 -7.321 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.617e-06 + HCO3- 1.782e-06 1.782e-06 -5.749 -5.749 -0.000 + CO2 8.346e-07 8.346e-07 -6.079 -6.079 0.000 + CO3-2 3.985e-10 3.985e-10 -9.400 -9.400 -0.000 +Cl 9.984e-04 + Cl- 9.984e-04 9.984e-04 -3.001 -3.001 -0.000 +Co 2.356e-06 + CoNta- 2.278e-06 2.278e-06 -5.642 -5.642 -0.000 + Co+2 7.711e-08 7.711e-08 -7.113 -7.113 -0.000 + CoOH+ 7.356e-11 7.356e-11 -10.133 -10.133 -0.000 + CoOHNta-2 6.872e-11 6.872e-11 -10.163 -10.163 -0.000 + CoNta2-4 8.474e-14 8.474e-14 -13.072 -13.072 -0.000 + Co(OH)2 2.219e-17 2.219e-17 -16.654 -16.654 0.000 + Co(OH)3- 2.664e-19 2.664e-19 -18.574 -18.574 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 +N 2.891e-07 + NH4+ 2.884e-07 2.884e-07 -6.540 -6.540 -0.000 + NH3 6.910e-10 6.910e-10 -9.161 -9.161 0.000 +Na 1.002e-03 + Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 +Nta 2.524e-06 + CoNta- 2.278e-06 2.278e-06 -5.642 -5.642 -0.000 + HNta-2 2.460e-07 2.460e-07 -6.609 -6.609 -0.000 + CoOHNta-2 6.872e-11 6.872e-11 -10.163 -10.163 -0.000 + Nta-3 5.895e-11 5.895e-11 -10.230 -10.230 -0.000 + H2Nta- 5.146e-11 5.146e-11 -10.289 -10.289 -0.000 + CoNta2-4 8.474e-14 8.474e-14 -13.072 -13.072 -0.000 + H3Nta 4.285e-16 4.285e-16 -15.368 -15.368 0.000 +O(0) 6.029e-05 + O2 3.015e-05 3.015e-05 -4.521 -4.521 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 11. + +Transport step 11. Mixrun 1. + +Transport step 12. + +Transport step 12. Mixrun 1. + +Transport step 13. + +Transport step 13. Mixrun 1. + +Transport step 14. + +Transport step 14. Mixrun 1. + +Transport step 15. + +Transport step 15. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 126000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 5.701e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 3.286e-06 2.072e-04 H 0 + Co_sorption 6.691e-08 8.668e-07 CoCl2 1 + CoNta_sorption 1.292e-07 5.375e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.207e-06 2.207e-06 + Cl 9.987e-04 9.987e-04 + Co 2.833e-06 2.833e-06 + N 2.334e-07 2.334e-07 + Na 1.004e-03 1.004e-03 + Nta 2.963e-06 2.963e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.644 Charge balance + pe = 13.747 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.004e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.435e-05 + Total CO2 (mol/kg) = 2.207e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.384e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 18 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.271e-07 2.271e-07 -6.644 -6.644 -0.000 + OH- 4.403e-08 4.403e-08 -7.356 -7.356 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 2.207e-06 + HCO3- 1.463e-06 1.463e-06 -5.835 -5.835 -0.000 + CO2 7.440e-07 7.440e-07 -6.128 -6.128 0.000 + CO3-2 3.013e-10 3.013e-10 -9.521 -9.521 -0.000 +Cl 9.987e-04 + Cl- 9.987e-04 9.987e-04 -3.001 -3.001 -0.000 +Co 2.833e-06 + CoNta- 2.728e-06 2.728e-06 -5.564 -5.564 -0.000 + Co+2 1.049e-07 1.049e-07 -6.979 -6.979 -0.000 + CoOH+ 9.212e-11 9.212e-11 -10.036 -10.036 -0.000 + CoOHNta-2 7.577e-11 7.577e-11 -10.120 -10.120 -0.000 + CoNta2-4 8.932e-14 8.932e-14 -13.049 -13.049 -0.000 + Co(OH)2 2.559e-17 2.559e-17 -16.592 -16.592 0.000 + Co(OH)3- 2.830e-19 2.830e-19 -18.548 -18.548 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.931 -43.931 0.000 +N 2.334e-07 + NH4+ 2.329e-07 2.329e-07 -6.633 -6.633 -0.000 + NH3 5.139e-10 5.139e-10 -9.289 -9.289 0.000 +Na 1.004e-03 + Na+ 1.004e-03 1.004e-03 -2.998 -2.998 -0.000 +Nta 2.963e-06 + CoNta- 2.728e-06 2.728e-06 -5.564 -5.564 -0.000 + HNta-2 2.352e-07 2.352e-07 -6.629 -6.629 -0.000 + CoOHNta-2 7.577e-11 7.577e-11 -10.120 -10.120 -0.000 + H2Nta- 5.342e-11 5.342e-11 -10.272 -10.272 -0.000 + Nta-3 5.190e-11 5.190e-11 -10.285 -10.285 -0.000 + CoNta2-4 8.932e-14 8.932e-14 -13.049 -13.049 -0.000 + H3Nta 4.830e-16 4.830e-16 -15.316 -15.316 0.000 +O(0) 6.072e-05 + O2 3.036e-05 3.036e-05 -4.518 -4.518 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 16. + +Transport step 16. Mixrun 1. + +Transport step 17. + +Transport step 17. Mixrun 1. + +Transport step 18. + +Transport step 18. Mixrun 1. + +Transport step 19. + +Transport step 19. Mixrun 1. + +Transport step 20. + +Transport step 20. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 144000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 5.782e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 3.305e-06 2.237e-04 H 0 + Co_sorption 7.697e-08 1.234e-06 CoCl2 1 + CoNta_sorption -1.235e-07 5.251e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.847e-06 1.847e-06 + Cl 9.990e-04 9.990e-04 + Co 2.681e-06 2.681e-06 + N 1.845e-07 1.845e-07 + Na 1.003e-03 1.003e-03 + Nta 2.767e-06 2.767e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.540 Charge balance + pe = 13.851 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.004e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.265e-05 + Total CO2 (mol/kg) = 1.847e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 19 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.881e-07 2.881e-07 -6.540 -6.540 -0.000 + OH- 3.471e-08 3.471e-08 -7.460 -7.460 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 1.847e-06 + HCO3- 1.123e-06 1.123e-06 -5.950 -5.950 -0.000 + CO2 7.243e-07 7.243e-07 -6.140 -6.140 0.000 + CO3-2 1.823e-10 1.823e-10 -9.739 -9.739 -0.000 +Cl 9.990e-04 + Cl- 9.990e-04 9.990e-04 -3.000 -3.000 -0.000 +Co 2.681e-06 + CoNta- 2.547e-06 2.547e-06 -5.594 -5.594 -0.000 + Co+2 1.332e-07 1.332e-07 -6.875 -6.875 -0.000 + CoOH+ 9.225e-11 9.225e-11 -10.035 -10.035 -0.000 + CoOHNta-2 5.579e-11 5.579e-11 -10.253 -10.253 -0.000 + CoNta2-4 6.133e-14 6.133e-14 -13.212 -13.212 -0.000 + Co(OH)2 2.020e-17 2.020e-17 -16.695 -16.695 0.000 + Co(OH)3- 1.761e-19 1.761e-19 -18.754 -18.754 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.933 -43.933 0.000 +N 1.845e-07 + NH4+ 1.841e-07 1.841e-07 -6.735 -6.735 -0.000 + NH3 3.203e-10 3.203e-10 -9.494 -9.494 0.000 +Na 1.003e-03 + Na+ 1.003e-03 1.003e-03 -2.999 -2.999 -0.000 +Nta 2.767e-06 + CoNta- 2.547e-06 2.547e-06 -5.594 -5.594 -0.000 + HNta-2 2.193e-07 2.193e-07 -6.659 -6.659 -0.000 + H2Nta- 6.319e-11 6.319e-11 -10.199 -10.199 -0.000 + CoOHNta-2 5.579e-11 5.579e-11 -10.253 -10.253 -0.000 + Nta-3 3.816e-11 3.816e-11 -10.418 -10.418 -0.000 + CoNta2-4 6.133e-14 6.133e-14 -13.212 -13.212 -0.000 + H3Nta 7.247e-16 7.247e-16 -15.140 -15.140 0.000 +O(0) 6.109e-05 + O2 3.055e-05 3.055e-05 -4.515 -4.515 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 21. + +Transport step 21. Mixrun 1. + +Transport step 22. + +Transport step 22. Mixrun 1. + +Transport step 23. + +Transport step 23. Mixrun 1. + +Transport step 24. + +Transport step 24. Mixrun 1. + +Transport step 25. + +Transport step 25. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 162000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 5.421e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 3.036e-06 2.396e-04 H 0 + Co_sorption 7.935e-08 1.630e-06 CoCl2 1 + CoNta_sorption -2.766e-07 4.115e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.473e-06 1.473e-06 + Cl 9.994e-04 9.994e-04 + Co 2.065e-06 2.065e-06 + N 1.336e-07 1.336e-07 + Na 1.002e-03 1.002e-03 + Nta 2.097e-06 2.097e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.412 Charge balance + pe = 13.980 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.003e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.478e-06 + Total CO2 (mol/kg) = 1.473e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 50 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.871e-07 3.871e-07 -6.412 -6.412 -0.000 + OH- 2.584e-08 2.584e-08 -7.588 -7.588 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 1.473e-06 + HCO3- 7.893e-07 7.893e-07 -6.103 -6.103 -0.000 + CO2 6.840e-07 6.840e-07 -6.165 -6.165 0.000 + CO3-2 9.539e-11 9.539e-11 -10.021 -10.021 -0.000 +Cl 9.994e-04 + Cl- 9.994e-04 9.994e-04 -3.000 -3.000 -0.000 +Co 2.065e-06 + CoNta- 1.909e-06 1.909e-06 -5.719 -5.719 -0.000 + Co+2 1.565e-07 1.565e-07 -6.806 -6.806 -0.000 + CoOH+ 8.067e-11 8.067e-11 -10.093 -10.093 -0.000 + CoOHNta-2 3.111e-11 3.111e-11 -10.507 -10.507 -0.000 + CoNta2-4 2.931e-14 2.931e-14 -13.533 -13.533 -0.000 + Co(OH)2 1.315e-17 1.315e-17 -16.881 -16.881 0.000 + Co(OH)3- 8.534e-20 8.534e-20 -19.069 -19.069 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.934 -43.934 0.000 +N 1.336e-07 + NH4+ 1.335e-07 1.335e-07 -6.875 -6.875 -0.000 + NH3 1.728e-10 1.728e-10 -9.762 -9.762 0.000 +Na 1.002e-03 + Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 +Nta 2.097e-06 + CoNta- 1.909e-06 1.909e-06 -5.719 -5.719 -0.000 + HNta-2 1.879e-07 1.879e-07 -6.726 -6.726 -0.000 + H2Nta- 7.274e-11 7.274e-11 -10.138 -10.138 -0.000 + CoOHNta-2 3.111e-11 3.111e-11 -10.507 -10.507 -0.000 + Nta-3 2.434e-11 2.434e-11 -10.614 -10.614 -0.000 + CoNta2-4 2.931e-14 2.931e-14 -13.533 -13.533 -0.000 + H3Nta 1.121e-15 1.121e-15 -14.950 -14.950 0.000 +O(0) 6.148e-05 + O2 3.074e-05 3.074e-05 -4.512 -4.512 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 26. + +Transport step 26. Mixrun 1. + +Transport step 27. + +Transport step 27. Mixrun 1. + +Transport step 28. + +Transport step 28. Mixrun 1. + +Transport step 29. + +Transport step 29. Mixrun 1. + +Transport step 30. + +Transport step 30. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 180000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 4.557e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 2.444e-06 2.531e-04 H 0 + Co_sorption 7.182e-08 2.008e-06 CoCl2 1 + CoNta_sorption -2.844e-07 2.658e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.132e-06 1.132e-06 + Cl 9.997e-04 9.997e-04 + Co 1.349e-06 1.349e-06 + N 8.723e-08 8.723e-08 + Na 1.002e-03 1.002e-03 + Nta 1.324e-06 1.324e-06 + +----------------------------Description of solution---------------------------- + + pH = 6.278 Charge balance + pe = 14.115 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.002e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 6.102e-06 + Total CO2 (mol/kg) = 1.132e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 50 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 5.273e-07 5.273e-07 -6.278 -6.278 -0.000 + OH- 1.896e-08 1.896e-08 -7.722 -7.722 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 1.132e-06 + CO2 6.128e-07 6.128e-07 -6.213 -6.213 0.000 + HCO3- 5.191e-07 5.191e-07 -6.285 -6.285 -0.000 + CO3-2 4.605e-11 4.605e-11 -10.337 -10.337 -0.000 +Cl 9.997e-04 + Cl- 9.997e-04 9.997e-04 -3.000 -3.000 -0.000 +Co 1.349e-06 + CoNta- 1.179e-06 1.179e-06 -5.929 -5.929 -0.000 + Co+2 1.705e-07 1.705e-07 -6.768 -6.768 -0.000 + CoOH+ 6.450e-11 6.450e-11 -10.190 -10.190 -0.000 + CoOHNta-2 1.411e-11 1.411e-11 -10.851 -10.851 -0.000 + CoNta2-4 1.026e-14 1.026e-14 -13.989 -13.989 -0.000 + Co(OH)2 7.719e-18 7.719e-18 -17.112 -17.112 0.000 + Co(OH)3- 3.677e-20 3.677e-20 -19.435 -19.435 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.935 -43.935 0.000 +N 8.723e-08 + NH4+ 8.715e-08 8.715e-08 -7.060 -7.060 -0.000 + NH3 8.284e-11 8.284e-11 -10.082 -10.082 0.000 +Na 1.002e-03 + Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 +Nta 1.324e-06 + CoNta- 1.179e-06 1.179e-06 -5.929 -5.929 -0.000 + HNta-2 1.452e-07 1.452e-07 -6.838 -6.838 -0.000 + H2Nta- 7.654e-11 7.654e-11 -10.116 -10.116 -0.000 + CoOHNta-2 1.411e-11 1.411e-11 -10.851 -10.851 -0.000 + Nta-3 1.380e-11 1.380e-11 -10.860 -10.860 -0.000 + CoNta2-4 1.026e-14 1.026e-14 -13.989 -13.989 -0.000 + H3Nta 1.607e-15 1.607e-15 -14.794 -14.794 0.000 +O(0) 6.184e-05 + O2 3.092e-05 3.092e-05 -4.510 -4.510 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 31. + +Transport step 31. Mixrun 1. + +Transport step 32. + +Transport step 32. Mixrun 1. + +Transport step 33. + +Transport step 33. Mixrun 1. + +Transport step 34. + +Transport step 34. Mixrun 1. + +Transport step 35. + +Transport step 35. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 198000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 3.282e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 1.593e-06 2.629e-04 H 0 + Co_sorption 5.514e-08 2.320e-06 CoCl2 1 + CoNta_sorption -2.069e-07 1.451e-06 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 8.578e-07 8.578e-07 + Cl 1.000e-03 1.000e-03 + Co 7.877e-07 7.877e-07 + N 4.998e-08 4.998e-08 + Na 1.001e-03 1.001e-03 + Nta 7.128e-07 7.128e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.162 Charge balance + pe = 14.231 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.002e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.419e-06 + Total CO2 (mol/kg) = 8.578e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 20 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.892e-07 6.892e-07 -6.162 -6.162 -0.000 + OH- 1.451e-08 1.451e-08 -7.838 -7.838 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 8.578e-07 + CO2 5.205e-07 5.205e-07 -6.284 -6.284 0.000 + HCO3- 3.373e-07 3.373e-07 -6.472 -6.472 -0.000 + CO3-2 2.289e-11 2.289e-11 -10.640 -10.640 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 7.877e-07 + CoNta- 6.150e-07 6.150e-07 -6.211 -6.211 -0.000 + Co+2 1.727e-07 1.727e-07 -6.763 -6.763 -0.000 + CoOH+ 4.999e-11 4.999e-11 -10.301 -10.301 -0.000 + CoOHNta-2 5.630e-12 5.630e-12 -11.249 -11.249 -0.000 + CoNta2-4 2.757e-15 2.757e-15 -14.560 -14.560 -0.000 + Co(OH)2 4.577e-18 4.577e-18 -17.339 -17.339 0.000 + Co(OH)3- 1.668e-20 1.668e-20 -19.778 -19.778 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.936 -43.936 0.000 +N 4.998e-08 + NH4+ 4.995e-08 4.995e-08 -7.301 -7.301 -0.000 + NH3 3.632e-11 3.632e-11 -10.440 -10.440 0.000 +Na 1.001e-03 + Na+ 1.001e-03 1.001e-03 -3.000 -3.000 -0.000 +Nta 7.128e-07 + CoNta- 6.150e-07 6.150e-07 -6.211 -6.211 -0.000 + HNta-2 9.771e-08 9.771e-08 -7.010 -7.010 -0.000 + H2Nta- 6.734e-11 6.734e-11 -10.172 -10.172 -0.000 + Nta-3 7.106e-12 7.106e-12 -11.148 -11.148 -0.000 + CoOHNta-2 5.630e-12 5.630e-12 -11.249 -11.249 -0.000 + CoNta2-4 2.757e-15 2.757e-15 -14.560 -14.560 -0.000 + H3Nta 1.848e-15 1.848e-15 -14.733 -14.733 0.000 +O(0) 6.212e-05 + O2 3.106e-05 3.106e-05 -4.508 -4.508 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 36. + +Transport step 36. Mixrun 1. + +Transport step 37. + +Transport step 37. Mixrun 1. + +Transport step 38. + +Transport step 38. Mixrun 1. + +Transport step 39. + +Transport step 39. Mixrun 1. + +Transport step 40. + +Transport step 40. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 216000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 1.946e-08 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 7.109e-07 2.681e-04 H 0 + Co_sorption 3.544e-08 2.536e-06 CoCl2 1 + CoNta_sorption -1.186e-07 6.881e-07 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 6.715e-07 6.715e-07 + Cl 1.000e-03 1.000e-03 + Co 4.456e-07 4.456e-07 + N 2.467e-08 2.467e-08 + Na 1.000e-03 1.000e-03 + Nta 3.350e-07 3.350e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.081 Charge balance + pe = 14.313 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.709e-06 + Total CO2 (mol/kg) = 6.715e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 8.307e-07 8.307e-07 -6.081 -6.081 -0.000 + OH- 1.204e-08 1.204e-08 -7.919 -7.919 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 6.715e-07 + CO2 4.367e-07 4.367e-07 -6.360 -6.360 0.000 + HCO3- 2.348e-07 2.348e-07 -6.629 -6.629 -0.000 + CO3-2 1.322e-11 1.322e-11 -10.879 -10.879 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 4.456e-07 + CoNta- 2.794e-07 2.794e-07 -6.554 -6.554 -0.000 + Co+2 1.662e-07 1.662e-07 -6.779 -6.779 -0.000 + CoOH+ 3.992e-11 3.992e-11 -10.399 -10.399 -0.000 + CoOHNta-2 2.122e-12 2.122e-12 -11.673 -11.673 -0.000 + CoNta2-4 5.911e-16 5.911e-16 -15.228 -15.228 -0.000 + Co(OH)2 3.032e-18 3.032e-18 -17.518 -17.518 0.000 + Co(OH)3- 9.168e-21 9.168e-21 -20.038 -20.038 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +N 2.467e-08 + NH4+ 2.465e-08 2.465e-08 -7.608 -7.608 -0.000 + NH3 1.487e-11 1.487e-11 -10.828 -10.828 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 3.350e-07 + CoNta- 2.794e-07 2.794e-07 -6.554 -6.554 -0.000 + HNta-2 5.558e-08 5.558e-08 -7.255 -7.255 -0.000 + H2Nta- 4.618e-11 4.618e-11 -10.336 -10.336 -0.000 + Nta-3 3.353e-12 3.353e-12 -11.475 -11.475 -0.000 + CoOHNta-2 2.122e-12 2.122e-12 -11.673 -11.673 -0.000 + H3Nta 1.527e-15 1.527e-15 -14.816 -14.816 0.000 + CoNta2-4 5.911e-16 5.911e-16 -15.228 -15.228 -0.000 +O(0) 6.232e-05 + O2 3.116e-05 3.116e-05 -4.506 -4.506 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 41. + +Transport step 41. Mixrun 1. + +Transport step 42. + +Transport step 42. Mixrun 1. + +Transport step 43. + +Transport step 43. Mixrun 1. + +Transport step 44. + +Transport step 44. Mixrun 1. + +Transport step 45. + +Transport step 45. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 234000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 9.475e-09 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass 5.654e-08 2.696e-04 H 0 + Co_sorption 2.003e-08 2.664e-06 CoCl2 1 + CoNta_sorption -5.697e-08 2.930e-07 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.676e-07 5.676e-07 + Cl 1.000e-03 1.000e-03 + Co 2.732e-07 2.732e-07 + N 1.054e-08 1.054e-08 + Na 1.000e-03 1.000e-03 + Nta 1.416e-07 1.416e-07 + +----------------------------Description of solution---------------------------- + + pH = 6.035 Charge balance + pe = 14.359 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.065e-07 + Total CO2 (mol/kg) = 5.676e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 23 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.228e-07 9.228e-07 -6.035 -6.035 -0.000 + OH- 1.084e-08 1.084e-08 -7.965 -7.965 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 5.676e-07 + CO2 3.825e-07 3.825e-07 -6.417 -6.417 0.000 + HCO3- 1.851e-07 1.851e-07 -6.733 -6.733 -0.000 + CO3-2 9.383e-12 9.383e-12 -11.028 -11.028 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 2.732e-07 + Co+2 1.583e-07 1.583e-07 -6.801 -6.801 -0.000 + CoNta- 1.149e-07 1.149e-07 -6.940 -6.940 -0.000 + CoOH+ 3.422e-11 3.422e-11 -10.466 -10.466 -0.000 + CoOHNta-2 7.856e-13 7.856e-13 -12.105 -12.105 -0.000 + CoNta2-4 1.050e-16 1.050e-16 -15.979 -15.979 -0.000 + Co(OH)2 2.339e-18 2.339e-18 -17.631 -17.631 0.000 + Co(OH)3- 6.368e-21 6.368e-21 -20.196 -20.196 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +N 1.054e-08 + NH4+ 1.054e-08 1.054e-08 -7.977 -7.977 -0.000 + NH3 5.723e-12 5.723e-12 -11.242 -11.242 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 1.416e-07 + CoNta- 1.149e-07 1.149e-07 -6.940 -6.940 -0.000 + HNta-2 2.667e-08 2.667e-08 -7.574 -7.574 -0.000 + H2Nta- 2.461e-11 2.461e-11 -10.609 -10.609 -0.000 + Nta-3 1.449e-12 1.449e-12 -11.839 -11.839 -0.000 + CoOHNta-2 7.856e-13 7.856e-13 -12.105 -12.105 -0.000 + H3Nta 9.043e-16 9.043e-16 -15.044 -15.044 0.000 + CoNta2-4 1.050e-16 1.050e-16 -15.979 -15.979 -0.000 +O(0) 6.242e-05 + O2 3.121e-05 3.121e-05 -4.506 -4.506 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 46. + +Transport step 46. Mixrun 1. + +Transport step 47. + +Transport step 47. Mixrun 1. + +Transport step 48. + +Transport step 48. Mixrun 1. + +Transport step 49. + +Transport step 49. Mixrun 1. + +Transport step 50. + +Transport step 50. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 252000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 3.947e-09 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass -3.021e-07 2.687e-04 H 0 + Co_sorption 1.119e-08 2.735e-06 CoCl2 1 + CoNta_sorption -2.428e-08 1.158e-07 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.197e-07 5.197e-07 + Cl 1.000e-03 1.000e-03 + Co 1.976e-07 1.976e-07 + N 4.028e-09 4.028e-09 + Na 1.000e-03 1.000e-03 + Nta 5.550e-08 5.550e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.014 Charge balance + pe = 14.380 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.997e-07 + Total CO2 (mol/kg) = 5.197e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 23 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.693e-07 9.693e-07 -6.014 -6.014 -0.000 + OH- 1.032e-08 1.032e-08 -7.986 -7.986 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 5.197e-07 + CO2 3.557e-07 3.557e-07 -6.449 -6.449 0.000 + HCO3- 1.639e-07 1.639e-07 -6.785 -6.785 -0.000 + CO3-2 7.911e-12 7.911e-12 -11.102 -11.102 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 1.976e-07 + Co+2 1.533e-07 1.533e-07 -6.815 -6.815 -0.000 + CoNta- 4.433e-08 4.433e-08 -7.353 -7.353 -0.000 + CoOH+ 3.155e-11 3.155e-11 -10.501 -10.501 -0.000 + CoOHNta-2 2.886e-13 2.886e-13 -12.540 -12.540 -0.000 + CoNta2-4 1.614e-17 1.614e-17 -16.792 -16.792 -0.000 + Co(OH)2 2.054e-18 2.054e-18 -17.687 -17.687 0.000 + Co(OH)3- 5.322e-21 5.322e-21 -20.274 -20.274 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +N 4.028e-09 + NH4+ 4.026e-09 4.026e-09 -8.395 -8.395 -0.000 + NH3 2.082e-12 2.082e-12 -11.682 -11.682 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 5.550e-08 + CoNta- 4.433e-08 4.433e-08 -7.353 -7.353 -0.000 + HNta-2 1.116e-08 1.116e-08 -7.952 -7.952 -0.000 + H2Nta- 1.082e-11 1.082e-11 -10.966 -10.966 -0.000 + Nta-3 5.770e-13 5.770e-13 -12.239 -12.239 -0.000 + CoOHNta-2 2.886e-13 2.886e-13 -12.540 -12.540 -0.000 + H3Nta 4.174e-16 4.174e-16 -15.379 -15.379 0.000 + CoNta2-4 1.614e-17 1.614e-17 -16.792 -16.792 -0.000 +O(0) 6.247e-05 + O2 3.124e-05 3.124e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +Transport step 51. + +Transport step 51. Mixrun 1. + +Transport step 52. + +Transport step 52. Mixrun 1. + +Transport step 53. + +Transport step 53. Mixrun 1. + +Transport step 54. + +Transport step 54. Mixrun 1. + +Transport step 55. + +Transport step 55. Mixrun 1. + +Using mix 10. +Using kinetics 10. Kinetics defined in simulation 3. + +Mixture 10. + + 6.000e-02 Solution 9 Solution after simulation 5. + 0.000e+00 Solution 11 Background solution initially filling column + 9.400e-01 Solution 10 Solution after simulation 5. + +Kinetics 10. Kinetics defined in simulation 3. + + Time: 270000 seconds + Time step: 3600 seconds + + Rate name Delta Moles Total Moles Reactant Coefficient + + HNTA-2 1.487e-09 1.000e+00 C -3.12 + H -1.968 + O -4.848 + N -0.424 + Nta 1 + Biomass -4.583e-07 2.667e-04 H 0 + Co_sorption 6.974e-09 2.777e-06 CoCl2 1 + CoNta_sorption -9.586e-09 4.346e-08 NaCoNta 1 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.005e-07 5.005e-07 + Cl 1.000e-03 1.000e-03 + Co 1.677e-07 1.677e-07 + N 1.429e-09 1.429e-09 + Na 1.000e-03 1.000e-03 + Nta 2.065e-08 2.065e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.005 Charge balance + pe = 14.389 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.001e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.359e-07 + Total CO2 (mol/kg) = 5.005e-07 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.387e-07 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 + Iterations = 23 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.888e-07 9.888e-07 -6.005 -6.005 -0.000 + OH- 1.011e-08 1.011e-08 -7.995 -7.995 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C 5.005e-07 + CO2 3.448e-07 3.448e-07 -6.462 -6.462 0.000 + HCO3- 1.558e-07 1.558e-07 -6.808 -6.808 -0.000 + CO3-2 7.368e-12 7.368e-12 -11.133 -11.133 -0.000 +Cl 1.000e-03 + Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Co 1.677e-07 + Co+2 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 + CoNta- 1.638e-08 1.638e-08 -7.786 -7.786 -0.000 + CoOH+ 3.053e-11 3.053e-11 -10.515 -10.515 -0.000 + CoOHNta-2 1.045e-13 1.045e-13 -12.981 -12.981 -0.000 + CoNta2-4 2.232e-18 2.232e-18 -17.651 -17.651 -0.000 + Co(OH)2 1.948e-18 1.948e-18 -17.710 -17.710 0.000 + Co(OH)3- 4.948e-21 4.948e-21 -20.306 -20.306 -0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 +N 1.429e-09 + NH4+ 1.429e-09 1.429e-09 -8.845 -8.845 -0.000 + NH3 7.241e-13 7.241e-13 -12.140 -12.140 0.000 +Na 1.000e-03 + Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 +Nta 2.065e-08 + CoNta- 1.638e-08 1.638e-08 -7.786 -7.786 -0.000 + HNta-2 4.262e-09 4.262e-09 -8.370 -8.370 -0.000 + H2Nta- 4.214e-12 4.214e-12 -11.375 -11.375 -0.000 + Nta-3 2.160e-13 2.160e-13 -12.666 -12.666 -0.000 + CoOHNta-2 1.045e-13 1.045e-13 -12.981 -12.981 -0.000 + H3Nta 1.659e-16 1.659e-16 -15.780 -15.780 0.000 + CoNta2-4 2.232e-18 2.232e-18 -17.651 -17.651 -0.000 +O(0) 6.249e-05 + O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 6. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex15.sel b/Sun/examples/ex15.sel new file mode 100644 index 00000000..ecf04dff --- /dev/null +++ b/Sun/examples/ex15.sel @@ -0,0 +1,78 @@ + sim state soln dist_x time step pH pe m_Nta-3 m_CoNta- m_HNta-2 m_Co+2 hours Co_sorb CoNta_sorb Biomass + 1 transp 10 9.5 0 0 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 5.0000e-01 0.0000e+00 0.0000e+00 0.0000e+00 + 1 transp 10 9.5 3600 1 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 1.5000e+00 0.0000e+00 0.0000e+00 1.3572e-04 + 1 transp 10 9.5 7200 2 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 2.5000e+00 0.0000e+00 0.0000e+00 1.3544e-04 + 1 transp 10 9.5 10800 3 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.5000e+00 0.0000e+00 0.0000e+00 1.3515e-04 + 1 transp 10 9.5 14400 4 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 4.5000e+00 0.0000e+00 0.0000e+00 1.3487e-04 + 1 transp 10 9.5 18000 5 6 14.3937 4.1637e-17 4.8355e-19 8.3076e-13 2.3172e-14 5.5000e+00 6.1781e-18 1.4377e-22 1.3459e-04 + 1 transp 10 9.5 21600 6 6.00019 14.3935 5.3587e-15 7.6672e-15 1.0687e-10 2.8548e-12 6.5000e+00 1.0994e-15 2.6066e-18 1.3431e-04 + 1 transp 10 9.5 25200 7 6.00441 14.3893 1.1039e-13 3.4338e-12 2.1803e-09 6.2065e-11 7.5000e+00 2.2731e-14 9.7754e-16 1.3406e-04 + 1 transp 10 9.5 28800 8 6.03587 14.3576 8.7248e-13 1.8088e-10 1.6028e-08 4.1366e-10 8.5000e+00 1.5703e-13 4.8045e-14 1.3399e-04 + 1 transp 10 9.5 32400 9 6.12883 14.264 3.7779e-12 1.9561e-09 5.6030e-08 1.0331e-09 9.5000e+00 4.8525e-13 5.5433e-13 1.3445e-04 + 1 transp 10 9.5 36000 10 6.2369 14.1549 9.6448e-12 8.0004e-09 1.1153e-07 1.6551e-09 1.0500e+01 9.8421e-13 2.4608e-12 1.3556e-04 + 1 transp 10 9.5 39600 11 6.30614 14.0851 1.5152e-11 2.0272e-08 1.4940e-07 2.6695e-09 1.1500e+01 1.7623e-12 6.7849e-12 1.3707e-04 + 1 transp 10 9.5 43200 12 6.35376 14.0371 1.9799e-11 4.1065e-08 1.7494e-07 4.1384e-09 1.2500e+01 2.9364e-12 1.4662e-11 1.3886e-04 + 1 transp 10 9.5 46800 13 6.3909 13.9998 2.3996e-11 7.2616e-08 1.9464e-07 6.0380e-09 1.3500e+01 4.6059e-12 2.7261e-11 1.4085e-04 + 1 transp 10 9.5 50400 14 6.4217 13.9688 2.7923e-11 1.1683e-07 2.1099e-07 8.3484e-09 1.4500e+01 6.8561e-12 4.5675e-11 1.4301e-04 + 1 transp 10 9.5 54000 15 6.44804 13.9423 3.1619e-11 1.7515e-07 2.2486e-07 1.1052e-08 1.5500e+01 9.7615e-12 7.0827e-11 1.4533e-04 + 1 transp 10 9.5 57600 16 6.47097 13.9193 3.5087e-11 2.4844e-07 2.3669e-07 1.4128e-08 1.6500e+01 1.3385e-11 1.0340e-10 1.4778e-04 + 1 transp 10 9.5 61200 17 6.49117 13.8989 3.8321e-11 3.3699e-07 2.4675e-07 1.7546e-08 1.7500e+01 1.7779e-11 1.4381e-10 1.5036e-04 + 1 transp 10 9.5 64800 18 6.50914 13.8808 4.1316e-11 4.4051e-07 2.5526e-07 2.1274e-08 1.8500e+01 2.2982e-11 1.9215e-10 1.5306e-04 + 1 transp 10 9.5 68400 19 6.52519 13.8647 4.4065e-11 5.5820e-07 2.6236e-07 2.5276e-08 1.9500e+01 2.9022e-11 2.4826e-10 1.5586e-04 + 1 transp 10 9.5 72000 20 6.53959 13.8502 4.6562e-11 6.8880e-07 2.6819e-07 2.9517e-08 2.0500e+01 3.5915e-11 3.1170e-10 1.5876e-04 + 2 transp 10 9.5 72000 0 6.53959 13.8502 4.6562e-11 6.8880e-07 2.6819e-07 2.9517e-08 2.0500e+01 0.0000e+00 0.0000e+00 0.0000e+00 + 2 transp 10 9.5 75600 1 6.55254 13.8371 4.8804e-11 8.3068e-07 2.7284e-07 3.3961e-08 2.1500e+01 4.3669e-11 3.8179e-10 1.6174e-04 + 2 transp 10 9.5 79200 2 6.56419 13.8254 5.0791e-11 9.8198e-07 2.7644e-07 3.8576e-08 2.2500e+01 5.2280e-11 4.5769e-10 1.6481e-04 + 2 transp 10 9.5 82800 3 6.57469 13.8148 5.2526e-11 1.1406e-06 2.7905e-07 4.3329e-08 2.3500e+01 6.1739e-11 5.3842e-10 1.6796e-04 + 2 transp 10 9.5 86400 4 6.58413 13.8053 5.4012e-11 1.3046e-06 2.8077e-07 4.8193e-08 2.4500e+01 7.2027e-11 6.2293e-10 1.7117e-04 + 2 transp 10 9.5 90000 5 6.59263 13.7967 5.5256e-11 1.4717e-06 2.8168e-07 5.3142e-08 2.5500e+01 8.3123e-11 7.1013e-10 1.7444e-04 + 2 transp 10 9.5 93600 6 6.60028 13.789 5.6269e-11 1.6400e-06 2.8183e-07 5.8153e-08 2.6500e+01 9.4998e-11 7.9893e-10 1.7778e-04 + 2 transp 10 9.5 97200 7 6.60754 13.7817 5.7056e-11 1.8075e-06 2.8103e-07 6.3208e-08 2.7500e+01 1.0762e-10 8.8826e-10 1.8116e-04 + 2 transp 10 9.5 100800 8 6.61795 13.7713 5.7637e-11 1.9718e-06 2.7717e-07 6.8258e-08 2.8500e+01 1.2096e-10 9.7697e-10 1.8457e-04 + 2 transp 10 9.5 104400 9 6.64212 13.7473 5.8212e-11 2.1299e-06 2.6478e-07 7.3002e-08 2.9500e+01 1.3490e-10 1.0636e-09 1.8791e-04 + 2 transp 10 9.5 108000 10 6.6795 13.7103 5.8949e-11 2.2783e-06 2.4602e-07 7.7114e-08 3.0500e+01 1.4924e-10 1.1465e-09 1.9109e-04 + 2 transp 10 9.5 111600 11 6.69156 13.6985 5.8746e-11 2.4117e-06 2.3846e-07 8.1911e-08 3.1500e+01 1.6415e-10 1.2236e-09 1.9424e-04 + 2 transp 10 9.5 115200 12 6.68638 13.7039 5.7684e-11 2.5260e-06 2.3696e-07 8.7374e-08 3.2500e+01 1.7978e-10 1.2925e-09 1.9741e-04 + 2 transp 10 9.5 118800 13 6.67462 13.7157 5.6097e-11 2.6183e-06 2.3676e-07 9.3127e-08 3.3500e+01 1.9616e-10 1.3514e-09 2.0062e-04 + 2 transp 10 9.5 122400 14 6.66009 13.7304 5.4144e-11 2.6860e-06 2.3630e-07 9.8982e-08 3.4500e+01 2.1330e-10 1.3987e-09 2.0387e-04 + 2 transp 10 9.5 126000 15 6.64373 13.7469 5.1900e-11 2.7276e-06 2.3520e-07 1.0486e-07 3.5500e+01 2.3114e-10 1.4332e-09 2.0716e-04 + 2 transp 10 9.5 129600 16 6.62579 13.7649 4.9419e-11 2.7424e-06 2.3341e-07 1.1072e-07 3.6500e+01 2.4964e-10 1.4540e-09 2.1047e-04 + 2 transp 10 9.5 133200 17 6.60638 13.7845 4.6754e-11 2.7304e-06 2.3091e-07 1.1652e-07 3.7500e+01 2.6875e-10 1.4608e-09 2.1379e-04 + 2 transp 10 9.5 136800 18 6.58562 13.8054 4.3956e-11 2.6927e-06 2.2772e-07 1.2223e-07 3.8500e+01 2.8841e-10 1.4537e-09 2.1712e-04 + 2 transp 10 9.5 140400 19 6.56361 13.8275 4.1075e-11 2.6309e-06 2.2386e-07 1.2780e-07 3.9500e+01 3.0854e-10 1.4333e-09 2.2044e-04 + 2 transp 10 9.5 144000 20 6.54047 13.8508 3.8158e-11 2.5474e-06 2.1934e-07 1.3320e-07 4.0500e+01 3.2906e-10 1.4004e-09 2.2375e-04 + 2 transp 10 9.5 147600 21 6.51631 13.8751 3.5247e-11 2.4449e-06 2.1419e-07 1.3841e-07 4.1500e+01 3.4990e-10 1.3562e-09 2.2702e-04 + 2 transp 10 9.5 151200 22 6.49127 13.9003 3.2379e-11 2.3266e-06 2.0845e-07 1.4337e-07 4.2500e+01 3.7097e-10 1.3021e-09 2.3026e-04 + 2 transp 10 9.5 154800 23 6.46547 13.9262 2.9588e-11 2.1956e-06 2.0213e-07 1.4806e-07 4.3500e+01 3.9217e-10 1.2398e-09 2.3344e-04 + 2 transp 10 9.5 158400 24 6.43907 13.9527 2.6899e-11 2.0552e-06 1.9529e-07 1.5245e-07 4.4500e+01 4.1340e-10 1.1710e-09 2.3656e-04 + 2 transp 10 9.5 162000 25 6.41223 13.9797 2.4336e-11 1.9087e-06 1.8794e-07 1.5649e-07 4.5500e+01 4.3456e-10 1.0972e-09 2.3959e-04 + 2 transp 10 9.5 165600 26 6.38512 14.0069 2.1913e-11 1.7589e-06 1.8013e-07 1.6016e-07 4.6500e+01 4.5554e-10 1.0202e-09 2.4253e-04 + 2 transp 10 9.5 169200 27 6.35794 14.0343 1.9643e-11 1.6088e-06 1.7189e-07 1.6342e-07 4.7500e+01 4.7623e-10 9.4150e-10 2.4537e-04 + 2 transp 10 9.5 172800 28 6.33089 14.0614 1.7532e-11 1.4607e-06 1.6329e-07 1.6624e-07 4.8500e+01 4.9652e-10 8.6254e-10 2.4809e-04 + 2 transp 10 9.5 176400 29 6.30416 14.0883 1.5584e-11 1.3168e-06 1.5436e-07 1.6859e-07 4.9500e+01 5.1630e-10 7.8460e-10 2.5068e-04 + 2 transp 10 9.5 180000 30 6.27797 14.1146 1.3798e-11 1.1788e-06 1.4516e-07 1.7047e-07 5.0500e+01 5.3545e-10 7.0877e-10 2.5312e-04 + 2 transp 10 9.5 183600 31 6.25252 14.1402 1.2170e-11 1.0482e-06 1.3576e-07 1.7185e-07 5.1500e+01 5.5388e-10 6.3597e-10 2.5541e-04 + 2 transp 10 9.5 187200 32 6.228 14.1648 1.0695e-11 9.2591e-07 1.2623e-07 1.7274e-07 5.2500e+01 5.7148e-10 5.6693e-10 2.5754e-04 + 2 transp 10 9.5 190800 33 6.20459 14.1883 9.3648e-12 8.1273e-07 1.1666e-07 1.7316e-07 5.3500e+01 5.8818e-10 5.0219e-10 2.5949e-04 + 2 transp 10 9.5 194400 34 6.18244 14.2105 8.1717e-12 7.0904e-07 1.0712e-07 1.7312e-07 5.4500e+01 6.0391e-10 4.4212e-10 2.6127e-04 + 2 transp 10 9.5 198000 35 6.16167 14.2314 7.1059e-12 6.1497e-07 9.7713e-08 1.7268e-07 5.5500e+01 6.1861e-10 3.8695e-10 2.6286e-04 + 2 transp 10 9.5 201600 36 6.14237 14.2508 6.1578e-12 5.3042e-07 8.8524e-08 1.7187e-07 5.6500e+01 6.3226e-10 3.3676e-10 2.6427e-04 + 2 transp 10 9.5 205200 37 6.12459 14.2686 5.3178e-12 4.5509e-07 7.9641e-08 1.7075e-07 5.7500e+01 6.4483e-10 2.9149e-10 2.6550e-04 + 2 transp 10 9.5 208800 38 6.10837 14.2849 4.5763e-12 3.8853e-07 7.1145e-08 1.6940e-07 5.8500e+01 6.5634e-10 2.5101e-10 2.6655e-04 + 2 transp 10 9.5 212400 39 6.09369 14.2996 3.9244e-12 3.3017e-07 6.3107e-08 1.6787e-07 5.9500e+01 6.6679e-10 2.1511e-10 2.6742e-04 + 2 transp 10 9.5 216000 40 6.08053 14.3129 3.3534e-12 2.7937e-07 5.5584e-08 1.6623e-07 6.0500e+01 6.7624e-10 1.8349e-10 2.6813e-04 + 2 transp 10 9.5 219600 41 6.06883 14.3246 2.8552e-12 2.3545e-07 4.8619e-08 1.6454e-07 6.1500e+01 6.8474e-10 1.5585e-10 2.6869e-04 + 2 transp 10 9.5 223200 42 6.05851 14.335 2.4224e-12 1.9772e-07 4.2241e-08 1.6286e-07 6.2500e+01 6.9233e-10 1.3184e-10 2.6910e-04 + 2 transp 10 9.5 226800 43 6.04948 14.3441 2.0479e-12 1.6548e-07 3.6461e-08 1.6123e-07 6.3500e+01 6.9911e-10 1.1112e-10 2.6938e-04 + 2 transp 10 9.5 230400 44 6.04163 14.3519 1.7253e-12 1.3809e-07 3.1277e-08 1.5969e-07 6.4500e+01 7.0513e-10 9.3326e-11 2.6955e-04 + 2 transp 10 9.5 234000 45 6.03487 14.3587 1.4485e-12 1.1491e-07 2.6672e-08 1.5827e-07 6.5500e+01 7.1047e-10 7.8132e-11 2.6960e-04 + 2 transp 10 9.5 237600 46 6.02908 14.3645 1.2122e-12 9.5378e-08 2.2620e-08 1.5699e-07 6.6500e+01 7.1521e-10 6.5220e-11 2.6957e-04 + 2 transp 10 9.5 241200 47 6.02415 14.3695 1.0113e-12 7.8988e-08 1.9086e-08 1.5585e-07 6.7500e+01 7.1941e-10 5.4292e-11 2.6945e-04 + 2 transp 10 9.5 244800 48 6.01999 14.3737 8.4110e-13 6.5277e-08 1.6027e-08 1.5485e-07 6.8500e+01 7.2315e-10 4.5082e-11 2.6926e-04 + 2 transp 10 9.5 248400 49 6.01648 14.3772 6.9760e-13 5.3842e-08 1.3400e-08 1.5400e-07 6.9500e+01 7.2648e-10 3.7348e-11 2.6901e-04 + 2 transp 10 9.5 252000 50 6.01355 14.3801 5.7705e-13 4.4330e-08 1.1160e-08 1.5328e-07 7.0500e+01 7.2947e-10 3.0873e-11 2.6870e-04 + 2 transp 10 9.5 255600 51 6.01111 14.3826 4.7615e-13 3.6437e-08 9.2604e-09 1.5268e-07 7.1500e+01 7.3215e-10 2.5469e-11 2.6836e-04 + 2 transp 10 9.5 259200 52 6.00908 14.3846 3.9198e-13 2.9901e-08 7.6592e-09 1.5220e-07 7.2500e+01 7.3458e-10 2.0972e-11 2.6798e-04 + 2 transp 10 9.5 262800 53 6.00741 14.3863 3.2200e-13 2.4501e-08 6.3161e-09 1.5182e-07 7.3500e+01 7.3678e-10 1.7238e-11 2.6756e-04 + 2 transp 10 9.5 266400 54 6.00603 14.3877 2.6398e-13 2.0046e-08 5.1944e-09 1.5152e-07 7.4500e+01 7.3880e-10 1.4145e-11 2.6713e-04 + 2 transp 10 9.5 270000 55 6.0049 14.3888 2.1600e-13 1.6379e-08 4.2615e-09 1.5130e-07 7.5500e+01 7.4066e-10 1.1589e-11 2.6667e-04 diff --git a/Sun/examples/ex16.log b/Sun/examples/ex16.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex16.out b/Sun/examples/ex16.out new file mode 100644 index 00000000..afb2e8ae --- /dev/null +++ b/Sun/examples/ex16.out @@ -0,0 +1,435 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex16 + Output file: ex16.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 16.--Inverse modeling of Sierra springs + SOLUTION_SPREAD + units mmol/L + Number pH Si Ca Mg Na K Alkalinity S(6) Cl + 1 6.2 0.273 0.078 0.029 0.134 0.028 0.328 0.01 0.014 + 2 6.8 0.41 0.26 0.071 0.259 0.04 0.895 0.025 0.03 + INVERSE_MODELING 1 + solutions 1 2 + uncertainty 0.025 + range + phases + Halite + Gypsum + Kaolinite precip + Ca-montmorillonite precip + CO2(g) + Calcite + Chalcedony precip + Biotite dissolve + Plagioclase dissolve + balances + Ca 0.05 0.025 + PHASES + Biotite + KMg3AlSi3O10(OH)2 + 6H+ + 4H2O = K+ + 3Mg+2 + Al(OH)4- + 3H4SiO4 + log_k 0.0 # No log_k, Inverse modeling only + Plagioclase + Na0.62Ca0.38Al1.38Si2.62O8 + 5.52 H+ + 2.48H2O = 0.62Na+ + 0.38Ca+2 + 1.38Al+3 + 2.62H4SiO4 + log_k 0.0 # No log_k, inverse modeling only + END +----- +TITLE +----- + + Example 16.--Inverse modeling of Sierra springs + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Alkalinity 3.280e-04 3.280e-04 + Ca 7.800e-05 7.800e-05 + Cl 1.400e-05 1.400e-05 + K 2.800e-05 2.800e-05 + Mg 2.900e-05 2.900e-05 + Na 1.340e-04 1.340e-04 + S(6) 1.000e-05 1.000e-05 + Si 2.730e-04 2.730e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.200 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 4.851e-04 + Mass of water (kg) = 1.000e+00 + Total carbon (mol/kg) = 7.825e-04 + Total CO2 (mol/kg) = 7.825e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 1.400e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 1.90 + Iterations = 7 + Total H = 1.110139e+02 + Total O = 5.550924e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.464e-07 6.310e-07 -6.189 -6.200 -0.011 + OH- 1.627e-08 1.587e-08 -7.789 -7.800 -0.011 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(4) 7.825e-04 + CO2 4.540e-04 4.540e-04 -3.343 -3.343 0.000 + HCO3- 3.281e-04 3.200e-04 -3.484 -3.495 -0.011 + CaHCO3+ 2.940e-07 2.868e-07 -6.532 -6.542 -0.011 + MgHCO3+ 1.003e-07 9.783e-08 -6.999 -7.010 -0.011 + CO3-2 2.628e-08 2.379e-08 -7.580 -7.624 -0.043 + NaHCO3 2.351e-08 2.352e-08 -7.629 -7.629 0.000 + CaCO3 2.806e-09 2.807e-09 -8.552 -8.552 0.000 + MgCO3 5.929e-10 5.930e-10 -9.227 -9.227 0.000 + NaCO3- 5.935e-11 5.788e-11 -10.227 -10.237 -0.011 +Ca 7.800e-05 + Ca+2 7.758e-05 7.023e-05 -4.110 -4.153 -0.043 + CaHCO3+ 2.940e-07 2.868e-07 -6.532 -6.542 -0.011 + CaSO4 1.244e-07 1.245e-07 -6.905 -6.905 0.000 + CaCO3 2.806e-09 2.807e-09 -8.552 -8.552 0.000 + CaOH+ 1.894e-11 1.847e-11 -10.723 -10.733 -0.011 + CaHSO4+ 4.717e-13 4.600e-13 -12.326 -12.337 -0.011 +Cl 1.400e-05 + Cl- 1.400e-05 1.365e-05 -4.854 -4.865 -0.011 +H(0) 5.636e-24 + H2 2.818e-24 2.818e-24 -23.550 -23.550 0.000 +K 2.800e-05 + K+ 2.800e-05 2.730e-05 -4.553 -4.564 -0.011 + KSO4- 1.747e-09 1.704e-09 -8.758 -8.769 -0.011 + KOH 1.500e-13 1.500e-13 -12.824 -12.824 0.000 +Mg 2.900e-05 + Mg+2 2.885e-05 2.612e-05 -4.540 -4.583 -0.043 + MgHCO3+ 1.003e-07 9.783e-08 -6.999 -7.010 -0.011 + MgSO4 5.438e-08 5.439e-08 -7.265 -7.264 0.000 + MgCO3 5.929e-10 5.930e-10 -9.227 -9.227 0.000 + MgOH+ 1.541e-10 1.503e-10 -9.812 -9.823 -0.011 +Na 1.340e-04 + Na+ 1.340e-04 1.307e-04 -3.873 -3.884 -0.011 + NaHCO3 2.351e-08 2.352e-08 -7.629 -7.629 0.000 + NaSO4- 5.964e-09 5.816e-09 -8.224 -8.235 -0.011 + NaCO3- 5.935e-11 5.788e-11 -10.227 -10.237 -0.011 + NaOH 1.368e-12 1.368e-12 -11.864 -11.864 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -45.280 -45.280 0.000 +S(6) 1.000e-05 + SO4-2 9.813e-06 8.882e-06 -5.008 -5.052 -0.043 + CaSO4 1.244e-07 1.245e-07 -6.905 -6.905 0.000 + MgSO4 5.438e-08 5.439e-08 -7.265 -7.264 0.000 + NaSO4- 5.964e-09 5.816e-09 -8.224 -8.235 -0.011 + KSO4- 1.747e-09 1.704e-09 -8.758 -8.769 -0.011 + HSO4- 5.587e-10 5.448e-10 -9.253 -9.264 -0.011 + CaHSO4+ 4.717e-13 4.600e-13 -12.326 -12.337 -0.011 +Si 2.730e-04 + H4SiO4 2.729e-04 2.730e-04 -3.564 -3.564 0.000 + H3SiO4- 6.541e-08 6.379e-08 -7.184 -7.195 -0.011 + H2SiO4-2 7.604e-15 6.877e-15 -14.119 -14.163 -0.044 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -4.84 -9.20 -4.36 CaSO4 + Aragonite -3.44 -11.78 -8.34 CaCO3 + Calcite -3.30 -11.78 -8.48 CaCO3 + Chalcedony -0.01 -3.56 -3.55 SiO2 + Chrysotile -15.88 16.32 32.20 Mg3Si2O5(OH)4 + CO2(g) -1.87 -3.34 -1.47 CO2 + Dolomite -6.89 -23.98 -17.09 CaMg(CO3)2 + Gypsum -4.62 -9.20 -4.58 CaSO4:2H2O + H2(g) -20.40 -23.55 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -10.33 -8.75 1.58 NaCl + O2(g) -42.32 -45.28 -2.96 O2 + Quartz 0.42 -3.56 -3.98 SiO2 + Sepiolite -10.82 4.94 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -13.72 4.94 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -0.85 -3.56 -2.71 SiO2 + Talc -12.20 9.20 21.40 Mg3Si4O10(OH)2 + +Initial solution 2. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Alkalinity 8.951e-04 8.951e-04 + Ca 2.600e-04 2.600e-04 + Cl 3.000e-05 3.000e-05 + K 4.000e-05 4.000e-05 + Mg 7.101e-05 7.101e-05 + Na 2.590e-04 2.590e-04 + S(6) 2.500e-05 2.500e-05 + Si 4.100e-04 4.100e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.800 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.313e-03 + Mass of water (kg) = 1.000e+00 + Total carbon (mol/kg) = 1.199e-03 + Total CO2 (mol/kg) = 1.199e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.400e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.73 + Iterations = 6 + Total H = 1.110150e+02 + Total O = 5.551125e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.647e-07 1.585e-07 -6.783 -6.800 -0.017 + OH- 6.579e-08 6.316e-08 -7.182 -7.200 -0.018 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(4) 1.199e-03 + HCO3- 8.907e-04 8.559e-04 -3.050 -3.068 -0.017 + CO2 3.049e-04 3.050e-04 -3.516 -3.516 0.000 + CaHCO3+ 2.485e-06 2.387e-06 -5.605 -5.622 -0.017 + MgHCO3+ 6.235e-07 5.987e-07 -6.205 -6.223 -0.018 + CO3-2 2.971e-07 2.533e-07 -6.527 -6.596 -0.069 + NaHCO3 1.196e-07 1.197e-07 -6.922 -6.922 0.000 + CaCO3 9.299e-08 9.302e-08 -7.032 -7.031 0.000 + MgCO3 1.444e-08 1.445e-08 -7.840 -7.840 0.000 + NaCO3- 1.221e-09 1.173e-09 -8.913 -8.931 -0.018 +Ca 2.600e-04 + Ca+2 2.566e-04 2.186e-04 -3.591 -3.660 -0.069 + CaHCO3+ 2.485e-06 2.387e-06 -5.605 -5.622 -0.017 + CaSO4 8.841e-07 8.843e-07 -6.054 -6.053 0.000 + CaCO3 9.299e-08 9.302e-08 -7.032 -7.031 0.000 + CaOH+ 2.384e-10 2.289e-10 -9.623 -9.640 -0.018 + CaHSO4+ 8.551e-13 8.211e-13 -12.068 -12.086 -0.018 +Cl 3.000e-05 + Cl- 3.000e-05 2.880e-05 -4.523 -4.541 -0.018 +H(0) 3.555e-25 + H2 1.778e-25 1.778e-25 -24.750 -24.750 0.000 +K 4.000e-05 + K+ 4.000e-05 3.840e-05 -4.398 -4.416 -0.018 + KSO4- 5.696e-09 5.470e-09 -8.244 -8.262 -0.018 + KOH 8.398e-13 8.401e-13 -12.076 -12.076 0.000 +Mg 7.101e-05 + Mg+2 7.008e-05 5.978e-05 -4.154 -4.223 -0.069 + MgHCO3+ 6.235e-07 5.987e-07 -6.205 -6.223 -0.018 + MgSO4 2.840e-07 2.841e-07 -6.547 -6.547 0.000 + MgCO3 1.444e-08 1.445e-08 -7.840 -7.840 0.000 + MgOH+ 1.426e-09 1.370e-09 -8.846 -8.863 -0.018 +Na 2.590e-04 + Na+ 2.589e-04 2.486e-04 -3.587 -3.604 -0.018 + NaHCO3 1.196e-07 1.197e-07 -6.922 -6.922 0.000 + NaSO4- 2.631e-08 2.526e-08 -7.580 -7.598 -0.018 + NaCO3- 1.221e-09 1.173e-09 -8.913 -8.931 -0.018 + NaOH 1.036e-11 1.036e-11 -10.985 -10.984 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.880 -42.880 0.000 +S(6) 2.500e-05 + SO4-2 2.380e-05 2.027e-05 -4.623 -4.693 -0.070 + CaSO4 8.841e-07 8.843e-07 -6.054 -6.053 0.000 + MgSO4 2.840e-07 2.841e-07 -6.547 -6.547 0.000 + NaSO4- 2.631e-08 2.526e-08 -7.580 -7.598 -0.018 + KSO4- 5.696e-09 5.470e-09 -8.244 -8.262 -0.018 + HSO4- 3.253e-10 3.124e-10 -9.488 -9.505 -0.018 + CaHSO4+ 8.551e-13 8.211e-13 -12.068 -12.086 -0.018 +Si 4.100e-04 + H4SiO4 4.096e-04 4.098e-04 -3.388 -3.387 0.000 + H3SiO4- 3.970e-07 3.812e-07 -6.401 -6.419 -0.018 + H2SiO4-2 1.924e-13 1.636e-13 -12.716 -12.786 -0.070 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.99 -8.35 -4.36 CaSO4 + Aragonite -1.92 -10.26 -8.34 CaCO3 + Calcite -1.78 -10.26 -8.48 CaCO3 + Chalcedony 0.16 -3.39 -3.55 SiO2 + Chrysotile -10.85 21.35 32.20 Mg3Si2O5(OH)4 + CO2(g) -2.05 -3.52 -1.47 CO2 + Dolomite -3.99 -21.08 -17.09 CaMg(CO3)2 + Gypsum -3.77 -8.35 -4.58 CaSO4:2H2O + H2(g) -21.60 -24.75 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -9.73 -8.14 1.58 NaCl + O2(g) -39.92 -42.88 -2.96 O2 + Quartz 0.59 -3.39 -3.98 SiO2 + Sepiolite -7.17 8.59 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -10.07 8.59 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -0.68 -3.39 -2.71 SiO2 + Talc -6.82 14.58 21.40 Mg3Si4O10(OH)2 + +------------------------------------------- +Beginning of inverse modeling calculations. +------------------------------------------- + + +Solution 1: + + Input Delta Input+Delta + pH 6.200e+00 + 1.246e-02 = 6.212e+00 + Al 0.000e+00 + 0.000e+00 = 0.000e+00 + Alkalinity 3.280e-04 + 5.500e-06 = 3.335e-04 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 7.825e-04 + 0.000e+00 = 7.825e-04 + Ca 7.800e-05 + -3.900e-06 = 7.410e-05 + Cl 1.400e-05 + 0.000e+00 = 1.400e-05 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 2.800e-05 + -7.000e-07 = 2.730e-05 + Mg 2.900e-05 + 0.000e+00 = 2.900e-05 + Na 1.340e-04 + 0.000e+00 = 1.340e-04 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 1.000e-05 + 0.000e+00 = 1.000e-05 + Si 2.730e-04 + 0.000e+00 = 2.730e-04 + +Solution 2: + + Input Delta Input+Delta + pH 6.800e+00 + -3.407e-03 = 6.797e+00 + Al 0.000e+00 + 0.000e+00 = 0.000e+00 + Alkalinity 8.951e-04 + -1.796e-06 = 8.933e-04 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 1.199e-03 + 0.000e+00 = 1.199e-03 + Ca 2.600e-04 + 6.501e-06 = 2.665e-04 + Cl 3.000e-05 + 0.000e+00 = 3.000e-05 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 4.000e-05 + 1.000e-06 = 4.100e-05 + Mg 7.101e-05 + -8.979e-07 = 7.011e-05 + Na 2.590e-04 + 0.000e+00 = 2.590e-04 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 2.500e-05 + 0.000e+00 = 2.500e-05 + Si 4.100e-04 + 0.000e+00 = 4.100e-04 + +Solution fractions: Minimum Maximum + Solution 1 1.000e+00 1.000e+00 1.000e+00 + Solution 2 1.000e+00 1.000e+00 1.000e+00 + +Phase mole transfers: Minimum Maximum + Halite 1.600e-05 1.490e-05 1.710e-05 NaCl + Gypsum 1.500e-05 1.413e-05 1.588e-05 CaSO4:2H2O + Kaolinite -3.392e-05 -5.587e-05 -1.224e-05 Al2Si2O5(OH)4 +Ca-Montmorillon -8.090e-05 -1.100e-04 -5.154e-05 Ca0.165Al2.33Si3.67O10(OH)2 + CO2(g) 2.928e-04 2.363e-04 3.563e-04 CO2 + Calcite 1.240e-04 1.007e-04 1.309e-04 CaCO3 + Biotite 1.370e-05 1.317e-05 1.370e-05 KMg3AlSi3O10(OH)2 + Plagioclase 1.758e-04 1.582e-04 1.935e-04 Na0.62Ca0.38Al1.38Si2.62O8 + +Redox mole transfers: + +Sum of residuals (epsilons in documentation): 5.574e+00 +Sum of delta/uncertainty limit: 5.574e+00 +Maximum fractional error in element concentration: 5.000e-02 + +Model contains minimum number of phases. +=============================================================================== + + +Solution 1: + + Input Delta Input+Delta + pH 6.200e+00 + 1.246e-02 = 6.212e+00 + Al 0.000e+00 + 0.000e+00 = 0.000e+00 + Alkalinity 3.280e-04 + 5.500e-06 = 3.335e-04 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 7.825e-04 + 0.000e+00 = 7.825e-04 + Ca 7.800e-05 + -3.900e-06 = 7.410e-05 + Cl 1.400e-05 + 0.000e+00 = 1.400e-05 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 2.800e-05 + -7.000e-07 = 2.730e-05 + Mg 2.900e-05 + 0.000e+00 = 2.900e-05 + Na 1.340e-04 + 0.000e+00 = 1.340e-04 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 1.000e-05 + 0.000e+00 = 1.000e-05 + Si 2.730e-04 + 0.000e+00 = 2.730e-04 + +Solution 2: + + Input Delta Input+Delta + pH 6.800e+00 + -3.407e-03 = 6.797e+00 + Al 0.000e+00 + 0.000e+00 = 0.000e+00 + Alkalinity 8.951e-04 + -1.796e-06 = 8.933e-04 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 1.199e-03 + 0.000e+00 = 1.199e-03 + Ca 2.600e-04 + 6.501e-06 = 2.665e-04 + Cl 3.000e-05 + 0.000e+00 = 3.000e-05 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 4.000e-05 + 1.000e-06 = 4.100e-05 + Mg 7.101e-05 + -8.980e-07 = 7.011e-05 + Na 2.590e-04 + 0.000e+00 = 2.590e-04 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 2.500e-05 + 0.000e+00 = 2.500e-05 + Si 4.100e-04 + 0.000e+00 = 4.100e-04 + +Solution fractions: Minimum Maximum + Solution 1 1.000e+00 1.000e+00 1.000e+00 + Solution 2 1.000e+00 1.000e+00 1.000e+00 + +Phase mole transfers: Minimum Maximum + Halite 1.600e-05 1.490e-05 1.710e-05 NaCl + Gypsum 1.500e-05 1.413e-05 1.588e-05 CaSO4:2H2O + Kaolinite -1.282e-04 -1.403e-04 -1.159e-04 Al2Si2O5(OH)4 + CO2(g) 3.061e-04 2.490e-04 3.703e-04 CO2 + Calcite 1.106e-04 8.680e-05 1.182e-04 CaCO3 + Chalcedony -1.084e-04 -1.473e-04 -6.906e-05 SiO2 + Biotite 1.370e-05 1.317e-05 1.370e-05 KMg3AlSi3O10(OH)2 + Plagioclase 1.758e-04 1.582e-04 1.935e-04 Na0.62Ca0.38Al1.38Si2.62O8 + +Redox mole transfers: + +Sum of residuals (epsilons in documentation): 5.574e+00 +Sum of delta/uncertainty limit: 5.574e+00 +Maximum fractional error in element concentration: 5.000e-02 + +Model contains minimum number of phases. +=============================================================================== + + +Summary of inverse modeling: + + Number of models found: 2 + Number of minimal models found: 2 + Number of infeasible sets of phases saved: 20 + Number of calls to cl1: 62 +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex17.log b/Sun/examples/ex17.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex17.out b/Sun/examples/ex17.out new file mode 100644 index 00000000..857c94be --- /dev/null +++ b/Sun/examples/ex17.out @@ -0,0 +1,349 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex17 + Output file: ex17.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 17.--Inverse modeling of Black Sea water evaporation + SOLUTION 1 Black Sea water + units mg/L + density 1.014 + pH 8.0 # estimated + Ca 233 + Mg 679 + Na 5820 + K 193 + S(6) 1460 + Cl 10340 + Br 35 + C 1 CO2(g) -3.5 + SOLUTION 2 Composition during halite precipitation + units mg/L + density 1.271 + pH 5.0 # estimated + Ca 0.0 + Mg 50500 + Na 55200 + K 15800 + S(6) 76200 + Cl 187900 + Br 2670 + C 1 CO2(g) -3.5 + INVERSE_MODELING + solutions 1 2 + uncertainties .025 + range + balances + Br + K + Mg + phases + H2O(g) pre + Calcite pre + CO2(g) pre + Gypsum pre + Halite pre + END +----- +TITLE +----- + + Example 17.--Inverse modeling of Black Sea water evaporation + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Black Sea water + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Br 4.401e-04 4.401e-04 + C 8.284e-04 8.284e-04 Equilibrium with CO2(g) + Ca 5.841e-03 5.841e-03 + Cl 2.930e-01 2.930e-01 + K 4.959e-03 4.959e-03 + Mg 2.806e-02 2.806e-02 + Na 2.544e-01 2.544e-01 + S(6) 1.527e-02 1.527e-02 + +----------------------------Description of solution---------------------------- + + pH = 8.000 + pe = 4.000 + Activity of water = 0.990 + Ionic strength = 3.540e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.625e-04 + Total CO2 (mol/kg) = 8.284e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.240e-03 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.36 + Iterations = 5 + Total H = 1.110132e+02 + Total O = 5.556978e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.500e-06 9.909e-07 -5.824 -6.004 -0.180 + H+ 1.288e-08 1.000e-08 -7.890 -8.000 -0.110 + H2O 5.551e+01 9.899e-01 1.744 -0.004 0.000 +Br 4.401e-04 + Br- 4.401e-04 2.835e-04 -3.356 -3.547 -0.191 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -76.604 -76.569 0.035 +C(4) 8.284e-04 + HCO3- 6.657e-04 4.740e-04 -3.177 -3.324 -0.147 + MgHCO3+ 5.725e-05 4.187e-05 -4.242 -4.378 -0.136 + NaHCO3 4.444e-05 4.822e-05 -4.352 -4.317 0.035 + MgCO3 1.476e-05 1.601e-05 -4.831 -4.796 0.035 + CaHCO3+ 1.247e-05 8.879e-06 -4.904 -5.052 -0.147 + NaCO3- 1.024e-05 7.488e-06 -4.990 -5.126 -0.136 + CO2 9.923e-06 1.077e-05 -5.003 -4.968 0.035 + CO3-2 8.646e-06 2.223e-06 -5.063 -5.653 -0.590 + CaCO3 5.053e-06 5.483e-06 -5.296 -5.261 0.035 +Ca 5.841e-03 + Ca+2 5.267e-03 1.468e-03 -2.278 -2.833 -0.555 + CaSO4 5.563e-04 6.035e-04 -3.255 -3.219 0.035 + CaHCO3+ 1.247e-05 8.879e-06 -4.904 -5.052 -0.147 + CaCO3 5.053e-06 5.483e-06 -5.296 -5.261 0.035 + CaOH+ 3.298e-08 2.412e-08 -7.482 -7.618 -0.136 + CaHSO4+ 4.835e-11 3.536e-11 -10.316 -10.452 -0.136 +Cl 2.930e-01 + Cl- 2.930e-01 1.960e-01 -0.533 -0.708 -0.175 +H(0) 1.305e-27 + H2 6.525e-28 7.079e-28 -27.185 -27.150 0.035 +K 4.959e-03 + K+ 4.895e-03 3.274e-03 -2.310 -2.485 -0.175 + KSO4- 6.480e-05 4.739e-05 -4.188 -4.324 -0.136 + KOH 1.036e-09 1.124e-09 -8.985 -8.949 0.035 +Mg 2.806e-02 + Mg+2 2.463e-02 7.549e-03 -1.609 -2.122 -0.514 + MgSO4 3.360e-03 3.646e-03 -2.474 -2.438 0.035 + MgHCO3+ 5.725e-05 4.187e-05 -4.242 -4.378 -0.136 + MgCO3 1.476e-05 1.601e-05 -4.831 -4.796 0.035 + MgOH+ 3.710e-06 2.713e-06 -5.431 -5.567 -0.136 +Na 2.544e-01 + Na+ 2.518e-01 1.809e-01 -0.599 -0.743 -0.144 + NaSO4- 2.554e-03 1.868e-03 -2.593 -2.729 -0.136 + NaHCO3 4.444e-05 4.822e-05 -4.352 -4.317 0.035 + NaCO3- 1.024e-05 7.488e-06 -4.990 -5.126 -0.136 + NaOH 1.090e-07 1.183e-07 -6.962 -6.927 0.035 +O(0) 1.502e-38 + O2 7.512e-39 8.150e-39 -38.124 -38.089 0.035 +S(6) 1.527e-02 + SO4-2 8.735e-03 2.060e-03 -2.059 -2.686 -0.627 + MgSO4 3.360e-03 3.646e-03 -2.474 -2.438 0.035 + NaSO4- 2.554e-03 1.868e-03 -2.593 -2.729 -0.136 + CaSO4 5.563e-04 6.035e-04 -3.255 -3.219 0.035 + KSO4- 6.480e-05 4.739e-05 -4.188 -4.324 -0.136 + HSO4- 2.739e-09 2.003e-09 -8.562 -8.698 -0.136 + CaHSO4+ 4.835e-11 3.536e-11 -10.316 -10.452 -0.136 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -1.16 -5.52 -4.36 CaSO4 + Aragonite -0.15 -8.49 -8.34 CaCO3 + Calcite -0.01 -8.49 -8.48 CaCO3 + CH4(g) -73.71 -76.57 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Dolomite 0.83 -16.26 -17.09 CaMg(CO3)2 + Gypsum -0.95 -5.53 -4.58 CaSO4:2H2O + H2(g) -24.00 -27.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -3.03 -1.45 1.58 NaCl + O2(g) -35.13 -38.09 -2.96 O2 + +Initial solution 2. Composition during halite precipitation + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Br 3.785e-02 3.785e-02 + C 7.019e-06 7.019e-06 Equilibrium with CO2(g) + Cl 6.004e+00 6.004e+00 + K 4.578e-01 4.578e-01 + Mg 2.353e+00 2.353e+00 + Na 2.720e+00 2.720e+00 + S(6) 8.986e-01 8.986e-01 + +----------------------------Description of solution---------------------------- + + pH = 5.000 + pe = 4.000 + Activity of water = 0.802 + Ionic strength = 7.827e+00 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -9.195e-06 + Total CO2 (mol/kg) = 7.019e-06 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 4.491e-02 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.36 + Iterations = 10 + Total H = 1.110125e+02 + Total O = 5.910064e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.425e-05 1.000e-05 -4.846 -5.000 -0.154 + OH- 1.749e-09 8.029e-10 -8.757 -9.095 -0.338 + H2O 5.551e+01 8.021e-01 1.744 -0.096 0.000 +Br 3.785e-02 + Br- 3.785e-02 1.580e-02 -1.422 -1.801 -0.379 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -53.169 -52.386 0.783 +C(4) 7.019e-06 + MgHCO3+ 4.391e-06 2.905e-05 -5.357 -4.537 0.821 + CO2 1.776e-06 1.077e-05 -5.751 -4.968 0.783 + HCO3- 6.660e-07 3.841e-07 -6.177 -6.416 -0.239 + NaHCO3 1.847e-07 1.120e-06 -6.734 -5.951 0.783 + MgCO3 1.833e-09 1.111e-08 -8.737 -7.954 0.783 + NaCO3- 2.628e-11 1.739e-10 -10.580 -9.760 0.821 + CO3-2 1.629e-11 1.801e-12 -10.788 -11.744 -0.956 +Cl 6.004e+00 + Cl- 6.004e+00 3.612e+00 0.778 0.558 -0.221 +H(0) 2.335e-22 + H2 1.168e-22 7.079e-22 -21.933 -21.150 0.783 +K 4.578e-01 + K+ 4.568e-01 2.748e-01 -0.340 -0.561 -0.221 + KSO4- 9.513e-04 6.294e-03 -3.022 -2.201 0.821 + KOH 1.261e-11 7.643e-11 -10.899 -10.117 0.783 +Mg 2.353e+00 + Mg+2 1.538e+00 6.465e+00 0.187 0.811 0.624 + MgSO4 8.148e-01 4.940e+00 -0.089 0.694 0.783 + MgHCO3+ 4.391e-06 2.905e-05 -5.357 -4.537 0.821 + MgOH+ 2.845e-07 1.883e-06 -6.546 -5.725 0.821 + MgCO3 1.833e-09 1.111e-08 -8.737 -7.954 0.783 +Na 2.720e+00 + Na+ 2.707e+00 5.184e+00 0.433 0.715 0.282 + NaSO4- 1.280e-02 8.469e-02 -1.893 -1.072 0.821 + NaHCO3 1.847e-07 1.120e-06 -6.734 -5.951 0.783 + NaOH 4.531e-10 2.747e-09 -9.344 -8.561 0.783 + NaCO3- 2.628e-11 1.739e-10 -10.580 -9.760 0.821 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -51.054 -50.272 0.783 +S(6) 8.986e-01 + MgSO4 8.148e-01 4.940e+00 -0.089 0.694 0.783 + SO4-2 7.004e-02 3.259e-03 -1.155 -2.487 -1.332 + NaSO4- 1.280e-02 8.469e-02 -1.893 -1.072 0.821 + KSO4- 9.513e-04 6.294e-03 -3.022 -2.201 0.821 + HSO4- 4.789e-07 3.169e-06 -6.320 -5.499 0.821 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + CH4(g) -49.53 -52.39 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + H2(g) -18.00 -21.15 -3.15 H2 + H2O(g) -1.61 -0.10 1.51 H2O + Halite -0.31 1.27 1.58 NaCl + O2(g) -47.31 -50.27 -2.96 O2 + +------------------------------------------- +Beginning of inverse modeling calculations. +------------------------------------------- + + +Solution 1: Black Sea water + + Input Delta Input+Delta + pH 8.000e+00 + 0.000e+00 = 8.000e+00 + Alkalinity 8.625e-04 + 0.000e+00 = 8.625e-04 + Br 4.401e-04 + 0.000e+00 = 4.401e-04 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 8.284e-04 + 0.000e+00 = 8.284e-04 + Ca 5.841e-03 + 0.000e+00 = 5.841e-03 + Cl 2.930e-01 + 7.845e-04 = 2.938e-01 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 4.959e-03 + 1.034e-04 = 5.063e-03 + Mg 2.806e-02 + -7.016e-04 = 2.736e-02 + Na 2.544e-01 + 0.000e+00 = 2.544e-01 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 1.527e-02 + 7.768e-05 = 1.535e-02 + +Solution 2: Composition during halite precipitation + + Input Delta Input+Delta + pH 5.000e+00 + 5.711e-14 = 5.000e+00 + Alkalinity -9.195e-06 + 0.000e+00 = -9.195e-06 + Br 3.785e-02 + 9.440e-04 = 3.880e-02 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 7.019e-06 + 0.000e+00 = 7.019e-06 + Ca 0.000e+00 + 0.000e+00 = 0.000e+00 + Cl 6.004e+00 + 1.501e-01 = 6.154e+00 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 4.578e-01 + -1.144e-02 = 4.463e-01 + Mg 2.353e+00 + 5.883e-02 = 2.412e+00 + Na 2.720e+00 + -4.500e-02 = 2.675e+00 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 8.986e-01 + -2.247e-02 = 8.761e-01 + +Solution fractions: Minimum Maximum + Solution 1 8.815e+01 8.780e+01 8.815e+01 + Solution 2 1.000e+00 1.000e+00 1.000e+00 + +Phase mole transfers: Minimum Maximum + H2O(g) -4.837e+03 -4.817e+03 -4.817e+03 H2O + Calcite -3.802e-02 -3.897e-02 -3.692e-02 CaCO3 + CO2(g) -3.500e-02 -3.615e-02 -3.371e-02 CO2 + Gypsum -4.769e-01 -4.907e-01 -4.612e-01 CaSO4:2H2O + Halite -1.975e+01 -2.033e+01 -1.901e+01 NaCl + +Redox mole transfers: + +Sum of residuals (epsilons in documentation): 1.947e+02 +Sum of delta/uncertainty limit: 7.804e+00 +Maximum fractional error in element concentration: 2.500e-02 + +Model contains minimum number of phases. +=============================================================================== + + +Summary of inverse modeling: + + Number of models found: 1 + Number of minimal models found: 1 + Number of infeasible sets of phases saved: 6 + Number of calls to cl1: 22 +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex18.log b/Sun/examples/ex18.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex18.out b/Sun/examples/ex18.out new file mode 100644 index 00000000..106cdf99 --- /dev/null +++ b/Sun/examples/ex18.out @@ -0,0 +1,550 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex18 + Output file: ex18.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 18.--Inverse modeling of Madison aquifer + SOLUTION 1 Recharge number 3 + units mmol/kgw + temp 9.9 + pe 0. + pH 7.55 + Ca 1.2 + Mg 1.01 + Na 0.02 + K 0.02 + Fe(2) 0.001 + Cl 0.02 + S(6) 0.16 + S(-2) 0 + C(4) 4.30 + isotope 13C -7.0 1.4 + isotope 34S 9.7 0.9 + SOLUTION 2 Mysse + units mmol/kgw + temp 63. + pH 6.61 + pe 0. + redox S(6)/S(-2) + Ca 11.28 + Mg 4.54 + Na 31.89 + K 2.54 + Fe(2) 0.0004 + Cl 17.85 + S(6) 19.86 + S(-2) 0.26 + C(4) 6.87 + isotope 13C -2.3 0.2 + isotope 34S(6) 16.3 1.5 + isotope 34S(-2) -22.1 7 + INVERSE_MODELING 1 + solutions 1 2 + uncertainty 0.05 + range + isotopes + 13C + 34S + balances + Fe(2) 1.0 + ph 0.1 + phases + Dolomite dis 13C 3.0 2 + Calcite pre 13C -1.5 1 + Anhydrite dis 34S 13.5 2 + CH2O dis 13C -25.0 5 + Goethite + Pyrite pre 34S -22. 2 + CaX2 pre + Ca.75Mg.25X2 pre + MgX2 pre + NaX + Halite + Sylvite + PHASES + Sylvite + KCl = K+ + Cl- + log_k 0.0 + CH2O + CH2O + H2O = CO2 + 4H+ + 4e- + log_k 0.0 + EXCHANGE_SPECIES + 0.75Ca+2 + 0.25Mg+2 + 2X- = Ca.75Mg.25X2 + log_k 0.0 + END +----- +TITLE +----- + + Example 18.--Inverse modeling of Madison aquifer + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Recharge number 3 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C(4) 4.300e-03 4.300e-03 + Ca 1.200e-03 1.200e-03 + Cl 2.000e-05 2.000e-05 + Fe(2) 1.000e-06 1.000e-06 + K 2.000e-05 2.000e-05 + Mg 1.010e-03 1.010e-03 + Na 2.000e-05 2.000e-05 + S(6) 1.600e-04 1.600e-04 + +----------------------------Description of solution---------------------------- + + pH = 7.550 + pe = 0.000 + Activity of water = 1.000 + Ionic strength = 6.543e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.016e-03 + Total CO2 (mol/kg) = 4.300e-03 + Temperature (deg C) = 9.900 + Electrical balance (eq) = 1.061e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 1.24 + Iterations = 8 + Total H = 1.110164e+02 + Total O = 5.551946e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.120e-07 1.029e-07 -6.951 -6.988 -0.037 + H+ 3.038e-08 2.818e-08 -7.517 -7.550 -0.033 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(4) 4.300e-03 + HCO3- 3.929e-03 3.623e-03 -2.406 -2.441 -0.035 + CO2 2.970e-04 2.974e-04 -3.527 -3.527 0.001 + MgHCO3+ 3.098e-05 2.850e-05 -4.509 -4.545 -0.036 + CaHCO3+ 3.027e-05 2.792e-05 -4.519 -4.554 -0.035 + CO3-2 5.765e-06 4.168e-06 -5.239 -5.380 -0.141 + CaCO3 4.727e-06 4.734e-06 -5.325 -5.325 0.001 + MgCO3 2.208e-06 2.211e-06 -5.656 -5.655 0.001 + FeHCO3+ 2.086e-07 1.919e-07 -6.681 -6.717 -0.036 + FeCO3 5.289e-08 5.297e-08 -7.277 -7.276 0.001 + NaHCO3 3.737e-08 3.742e-08 -7.428 -7.427 0.001 + NaCO3- 6.948e-10 6.391e-10 -9.158 -9.194 -0.036 +Ca 1.200e-03 + Ca+2 1.151e-03 8.317e-04 -2.939 -3.080 -0.141 + CaHCO3+ 3.027e-05 2.792e-05 -4.519 -4.554 -0.035 + CaSO4 1.393e-05 1.395e-05 -4.856 -4.855 0.001 + CaCO3 4.727e-06 4.734e-06 -5.325 -5.325 0.001 + CaOH+ 5.323e-09 4.897e-09 -8.274 -8.310 -0.036 + CaHSO4+ 2.136e-12 1.965e-12 -11.670 -11.707 -0.036 +Cl 2.000e-05 + Cl- 2.000e-05 1.838e-05 -4.699 -4.736 -0.037 + FeCl+ 1.461e-11 1.344e-11 -10.835 -10.872 -0.036 +Fe(2) 1.000e-06 + Fe+2 7.296e-07 5.298e-07 -6.137 -6.276 -0.139 + FeHCO3+ 2.086e-07 1.919e-07 -6.681 -6.717 -0.036 + FeCO3 5.289e-08 5.297e-08 -7.277 -7.276 0.001 + FeSO4 6.861e-09 6.871e-09 -8.164 -8.163 0.001 + FeOH+ 1.969e-09 1.811e-09 -8.706 -8.742 -0.036 + FeCl+ 1.461e-11 1.344e-11 -10.835 -10.872 -0.036 + FeHSO4+ 1.361e-15 1.252e-15 -14.866 -14.903 -0.036 +H(0) 1.316e-18 + H2 6.579e-19 6.588e-19 -18.182 -18.181 0.001 +K 2.000e-05 + K+ 1.999e-05 1.837e-05 -4.699 -4.736 -0.037 + KSO4- 1.037e-08 9.538e-09 -7.984 -8.021 -0.036 + KOH 2.256e-12 2.260e-12 -11.647 -11.646 0.001 +Mg 1.010e-03 + Mg+2 9.662e-04 7.011e-04 -3.015 -3.154 -0.139 + MgHCO3+ 3.098e-05 2.850e-05 -4.509 -4.545 -0.036 + MgSO4 1.063e-05 1.064e-05 -4.974 -4.973 0.001 + MgCO3 2.208e-06 2.211e-06 -5.656 -5.655 0.001 + MgOH+ 2.335e-08 2.148e-08 -7.632 -7.668 -0.036 +Na 2.000e-05 + Na+ 1.995e-05 1.837e-05 -4.700 -4.736 -0.036 + NaHCO3 3.737e-08 3.742e-08 -7.428 -7.427 0.001 + NaSO4- 8.826e-09 8.119e-09 -8.054 -8.090 -0.036 + NaCO3- 6.948e-10 6.391e-10 -9.158 -9.194 -0.036 + NaOH 4.299e-12 4.306e-12 -11.367 -11.366 0.001 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -61.151 -61.151 0.001 +S(6) 1.600e-04 + SO4-2 1.354e-04 9.754e-05 -3.868 -4.011 -0.142 + CaSO4 1.393e-05 1.395e-05 -4.856 -4.855 0.001 + MgSO4 1.063e-05 1.064e-05 -4.974 -4.973 0.001 + KSO4- 1.037e-08 9.538e-09 -7.984 -8.021 -0.036 + NaSO4- 8.826e-09 8.119e-09 -8.054 -8.090 -0.036 + FeSO4 6.861e-09 6.871e-09 -8.164 -8.163 0.001 + HSO4- 2.136e-10 1.965e-10 -9.670 -9.707 -0.036 + CaHSO4+ 2.136e-12 1.965e-12 -11.670 -11.707 -0.036 + FeHSO4+ 1.361e-15 1.252e-15 -14.866 -14.903 -0.036 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.76 -7.09 -4.34 CaSO4 + Aragonite -0.21 -8.46 -8.25 CaCO3 + Calcite -0.05 -8.46 -8.41 CaCO3 + CH2O -33.73 -33.73 0.00 CH2O + CO2(g) -2.26 -3.53 -1.27 CO2 + Dolomite -0.27 -16.99 -16.72 CaMg(CO3)2 + Gypsum -2.50 -7.09 -4.59 CaSO4:2H2O + H2(g) -15.10 -18.18 -3.08 H2 + H2O(g) -1.92 -0.00 1.92 H2O + Halite -11.02 -9.47 1.55 NaCl + Melanterite -7.88 -10.29 -2.41 FeSO4:7H2O + O2(g) -58.26 -61.15 -2.89 O2 + Siderite -0.86 -11.66 -10.79 FeCO3 + Sylvite -9.47 -9.47 0.00 KCl + +Initial solution 2. Mysse + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C(4) 6.870e-03 6.870e-03 + Ca 1.128e-02 1.128e-02 + Cl 1.785e-02 1.785e-02 + Fe(2) 4.000e-07 4.000e-07 + K 2.540e-03 2.540e-03 + Mg 4.540e-03 4.540e-03 + Na 3.189e-02 3.189e-02 + S(-2) 2.600e-04 2.600e-04 + S(6) 1.986e-02 1.986e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.610 + pe = 0.000 + Activity of water = 0.999 + Ionic strength = 7.256e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.258e-03 + Total CO2 (mol/kg) = 6.870e-03 + Temperature (deg C) = 63.000 + Electrical balance (eq) = 3.242e-03 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 3.20 + Iterations = 8 + Total H = 1.110179e+02 + Total O = 5.560448e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + S(-2)/S(6) -3.6487 -0.2434 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.726e-07 4.419e-07 -6.242 -6.355 -0.112 + H+ 2.963e-07 2.455e-07 -6.528 -6.610 -0.082 + H2O 5.551e+01 9.985e-01 1.744 -0.001 0.000 +C(4) 6.870e-03 + HCO3- 4.711e-03 3.746e-03 -2.327 -2.426 -0.100 + CO2 1.784e-03 1.814e-03 -2.749 -2.741 0.007 + CaHCO3+ 2.347e-04 1.867e-04 -3.629 -3.729 -0.100 + MgHCO3+ 6.578e-05 5.169e-05 -4.182 -4.287 -0.105 + NaHCO3 5.046e-05 5.131e-05 -4.297 -4.290 0.007 + CaCO3 1.560e-05 1.586e-05 -4.807 -4.800 0.007 + NaCO3- 3.512e-06 2.760e-06 -5.454 -5.559 -0.105 + CO3-2 2.780e-06 1.112e-06 -5.556 -5.954 -0.398 + MgCO3 1.642e-06 1.670e-06 -5.784 -5.777 0.007 + FeHCO3+ 1.177e-08 9.248e-09 -7.929 -8.034 -0.105 + FeCO3 6.474e-10 6.583e-10 -9.189 -9.182 0.007 +Ca 1.128e-02 + Ca+2 7.217e-03 2.899e-03 -2.142 -2.538 -0.396 + CaSO4 3.813e-03 3.877e-03 -2.419 -2.411 0.007 + CaHCO3+ 2.347e-04 1.867e-04 -3.629 -3.729 -0.100 + CaCO3 1.560e-05 1.586e-05 -4.807 -4.800 0.007 + CaHSO4+ 1.322e-08 1.039e-08 -7.879 -7.983 -0.105 + CaOH+ 2.491e-09 1.957e-09 -8.604 -8.708 -0.105 +Cl 1.785e-02 + Cl- 1.785e-02 1.381e-02 -1.748 -1.860 -0.111 + FeCl+ 5.988e-10 4.706e-10 -9.223 -9.327 -0.105 +Fe(2) 4.000e-07 + Fe(HS)2 2.830e-07 2.878e-07 -6.548 -6.541 0.007 + Fe+2 5.978e-08 2.468e-08 -7.223 -7.608 -0.384 + FeSO4 3.911e-08 3.977e-08 -7.408 -7.400 0.007 + FeHCO3+ 1.177e-08 9.248e-09 -7.929 -8.034 -0.105 + Fe(HS)3- 4.561e-09 3.585e-09 -8.341 -8.446 -0.105 + FeCO3 6.474e-10 6.583e-10 -9.189 -9.182 0.007 + FeCl+ 5.988e-10 4.706e-10 -9.223 -9.327 -0.105 + FeOH+ 5.014e-10 3.940e-10 -9.300 -9.404 -0.105 + FeHSO4+ 1.125e-13 8.843e-14 -12.949 -13.053 -0.105 +H(0) 1.190e-09 + H2 5.948e-10 6.048e-10 -9.226 -9.218 0.007 +K 2.540e-03 + K+ 2.394e-03 1.852e-03 -2.621 -2.732 -0.111 + KSO4- 1.459e-04 1.146e-04 -3.836 -3.941 -0.105 + KOH 2.569e-11 2.613e-11 -10.590 -10.583 0.007 +Mg 4.540e-03 + MgSO4 2.360e-03 2.399e-03 -2.627 -2.620 0.007 + Mg+2 2.113e-03 8.783e-04 -2.675 -3.056 -0.381 + MgHCO3+ 6.578e-05 5.169e-05 -4.182 -4.287 -0.105 + MgCO3 1.642e-06 1.670e-06 -5.784 -5.777 0.007 + MgOH+ 3.463e-07 2.721e-07 -6.461 -6.565 -0.105 +Na 3.189e-02 + Na+ 3.090e-02 2.435e-02 -1.510 -1.613 -0.103 + NaSO4- 9.408e-04 7.393e-04 -3.027 -3.131 -0.105 + NaHCO3 5.046e-05 5.131e-05 -4.297 -4.290 0.007 + NaCO3- 3.512e-06 2.760e-06 -5.454 -5.559 -0.105 + NaOH 6.437e-10 6.545e-10 -9.191 -9.184 0.007 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -63.075 -63.067 0.007 +S(-2) 2.600e-04 + HS- 1.482e-04 1.144e-04 -3.829 -3.942 -0.112 + H2S 1.112e-04 1.131e-04 -3.954 -3.947 0.007 + Fe(HS)2 2.830e-07 2.878e-07 -6.548 -6.541 0.007 + Fe(HS)3- 4.561e-09 3.585e-09 -8.341 -8.446 -0.105 + S-2 1.449e-09 5.662e-10 -8.839 -9.247 -0.408 +S(6) 1.986e-02 + SO4-2 1.260e-02 4.892e-03 -1.900 -2.311 -0.411 + CaSO4 3.813e-03 3.877e-03 -2.419 -2.411 0.007 + MgSO4 2.360e-03 2.399e-03 -2.627 -2.620 0.007 + NaSO4- 9.408e-04 7.393e-04 -3.027 -3.131 -0.105 + KSO4- 1.459e-04 1.146e-04 -3.836 -3.941 -0.105 + HSO4- 3.792e-07 2.980e-07 -6.421 -6.526 -0.105 + FeSO4 3.911e-08 3.977e-08 -7.408 -7.400 0.007 + CaHSO4+ 1.322e-08 1.039e-08 -7.879 -7.983 -0.105 + FeHSO4+ 1.125e-13 8.843e-14 -12.949 -13.053 -0.105 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.14 -4.85 -4.71 CaSO4 + Aragonite 0.18 -8.49 -8.67 CaCO3 + Calcite 0.30 -8.49 -8.79 CaCO3 + CH2O -14.59 -14.59 0.00 CH2O + CO2(g) -0.94 -2.74 -1.80 CO2 + Dolomite 0.37 -17.50 -17.87 CaMg(CO3)2 + FeS(ppt) -1.02 -4.94 -3.92 FeS + Gypsum -0.18 -4.85 -4.67 CaSO4:2H2O + H2(g) -5.92 -9.22 -3.30 H2 + H2O(g) -0.64 -0.00 0.64 H2O + H2S(g) -2.57 -3.95 -1.38 H2S + Halite -5.13 -3.47 1.66 NaCl + Mackinawite -0.29 -4.94 -4.65 FeS + Melanterite -8.07 -9.92 -1.85 FeSO4:7H2O + O2(g) -59.95 -63.07 -3.11 O2 + Pyrite 7.97 -9.57 -17.54 FeS2 + Siderite -2.47 -13.56 -11.10 FeCO3 + Sulfur -2.12 1.98 4.09 S + Sylvite -4.59 -4.59 0.00 KCl + +------------------------------------------- +Beginning of inverse modeling calculations. +------------------------------------------- + + +Solution 1: Recharge number 3 + + Input Delta Input+Delta + pH 7.550e+00 + 0.000e+00 = 7.550e+00 + Alkalinity 4.016e-03 + 0.000e+00 = 4.016e-03 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 4.300e-03 + 0.000e+00 = 4.300e-03 + Ca 1.200e-03 + -5.306e-05 = 1.147e-03 + Cl 2.000e-05 + 0.000e+00 = 2.000e-05 + Fe(2) 1.000e-06 + 0.000e+00 = 1.000e-06 + Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 2.000e-05 + 0.000e+00 = 2.000e-05 + Mg 1.010e-03 + 0.000e+00 = 1.010e-03 + Na 2.000e-05 + 0.000e+00 = 2.000e-05 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 1.600e-04 + 0.000e+00 = 1.600e-04 + X 0.000e+00 + 0.000e+00 = 0.000e+00 + 13C(-4) -7 + 0 = -7 + 13C(4) -7 + 0 = -7 + 34S(-2) 9.7 + 0 = 9.7 + 34S(6) 9.7 + 0 = 9.7 + +Solution 2: Mysse + + Input Delta Input+Delta + pH 6.610e+00 + 0.000e+00 = 6.610e+00 + Alkalinity 5.258e-03 + 0.000e+00 = 5.258e-03 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 6.870e-03 + 0.000e+00 = 6.870e-03 + Ca 1.128e-02 + 0.000e+00 = 1.128e-02 + Cl 1.785e-02 + 0.000e+00 = 1.785e-02 + Fe(2) 4.000e-07 + 0.000e+00 = 4.000e-07 + Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 + H(0) 1.190e-09 + 0.000e+00 = 1.190e-09 + K 2.540e-03 + 0.000e+00 = 2.540e-03 + Mg 4.540e-03 + 0.000e+00 = 4.540e-03 + Na 3.189e-02 + -1.256e-03 = 3.063e-02 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 2.600e-04 + 0.000e+00 = 2.600e-04 + S(6) 1.986e-02 + 9.930e-04 = 2.085e-02 + X 0.000e+00 + 0.000e+00 = 0.000e+00 + 13C(-4) -2.3 + 0 = -2.3 + 13C(4) -2.3 + 0 = -2.3 + 34S(-2) -22.1 + 0 = -22.1 + 34S(6) 16.3 + 0 = 16.3 + +Isotopic composition of phases: + 13C Dolomite 3 + 0 = 3 + 13C Calcite -1.5 + 0 = -1.5 + 34S Anhydrite 13.5 + -0.65116 = 12.8488 + 13C CH2O -25 + 3.56577 = -21.4342 + 34S Pyrite -22 + 2 = -20 + +Solution fractions: Minimum Maximum + Solution 1 1.000e+00 9.999e-01 1.000e+00 + Solution 2 1.000e+00 1.000e+00 1.000e+00 + +Phase mole transfers: Minimum Maximum + Dolomite 1.118e-02 1.022e-02 1.193e-02 CaMg(CO3)2 + Calcite -2.393e-02 -2.567e-02 -2.144e-02 CaCO3 + Anhydrite 2.288e-02 2.076e-02 2.348e-02 CaSO4 + CH2O 4.138e-03 3.003e-03 5.273e-03 CH2O + Goethite 9.642e-04 6.533e-04 1.275e-03 FeOOH + Pyrite -9.648e-04 -1.274e-03 -6.553e-04 FeS2 + MgX2 -7.652e-03 -8.576e-03 -6.972e-03 MgX2 + NaX 1.530e-02 1.394e-02 1.715e-02 NaX + Halite 1.531e-02 1.429e-02 1.633e-02 NaCl + Sylvite 2.520e-03 2.392e-03 2.648e-03 KCl + +Redox mole transfers: + Fe(3) 9.642e-04 + H(0) -1.190e-09 + S(-2) -2.190e-03 + +Sum of residuals (epsilons in documentation): 2.684e+00 +Sum of delta/uncertainty limit: 4.711e+00 +Maximum fractional error in element concentration: 5.000e-02 + +Model contains minimum number of phases. +=============================================================================== + + +Solution 1: Recharge number 3 + + Input Delta Input+Delta + pH 7.550e+00 + 0.000e+00 = 7.550e+00 + Alkalinity 4.016e-03 + 1.061e-04 = 4.122e-03 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 4.300e-03 + 1.136e-04 = 4.414e-03 + Ca 1.200e-03 + 0.000e+00 = 1.200e-03 + Cl 2.000e-05 + 0.000e+00 = 2.000e-05 + Fe(2) 1.000e-06 + 0.000e+00 = 1.000e-06 + Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 + H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + K 2.000e-05 + 0.000e+00 = 2.000e-05 + Mg 1.010e-03 + 0.000e+00 = 1.010e-03 + Na 2.000e-05 + 0.000e+00 = 2.000e-05 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(6) 1.600e-04 + 0.000e+00 = 1.600e-04 + X 0.000e+00 + 0.000e+00 = 0.000e+00 + 13C(-4) -7 + 0 = -7 + 13C(4) -7 + 0 = -7 + 34S(-2) 9.7 + 0 = 9.7 + 34S(6) 9.7 + 0 = 9.7 + +Solution 2: Mysse + + Input Delta Input+Delta + pH 6.610e+00 + 5.872e-02 = 6.669e+00 + Alkalinity 5.258e-03 + 0.000e+00 = 5.258e-03 + C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 + C(4) 6.870e-03 + -2.581e-04 = 6.612e-03 + Ca 1.128e-02 + 0.000e+00 = 1.128e-02 + Cl 1.785e-02 + 0.000e+00 = 1.785e-02 + Fe(2) 4.000e-07 + 0.000e+00 = 4.000e-07 + Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 + H(0) 1.190e-09 + 0.000e+00 = 1.190e-09 + K 2.540e-03 + 0.000e+00 = 2.540e-03 + Mg 4.540e-03 + 0.000e+00 = 4.540e-03 + Na 3.189e-02 + -1.256e-03 = 3.063e-02 + O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 + S(-2) 2.600e-04 + 0.000e+00 = 2.600e-04 + S(6) 1.986e-02 + 9.930e-04 = 2.085e-02 + X 0.000e+00 + 0.000e+00 = 0.000e+00 + 13C(-4) -2.3 + 0 = -2.3 + 13C(4) -2.3 + 0 = -2.3 + 34S(-2) -22.1 + 0 = -22.1 + 34S(6) 16.3 + 0 = 16.3 + +Isotopic composition of phases: + 13C Dolomite 3 + 2 = 5 + 13C Calcite -1.5 + -1 = -2.5 + 34S Anhydrite 13.5 + -0.119926 = 13.3801 + 13C CH2O -25 + 5 = -20 + 34S Pyrite -22 + 2 = -20 + +Solution fractions: Minimum Maximum + Solution 1 1.000e+00 1.000e+00 1.000e+00 + Solution 2 1.000e+00 1.000e+00 1.000e+00 + +Phase mole transfers: Minimum Maximum + Dolomite 5.443e-03 4.995e-03 5.838e-03 CaMg(CO3)2 + Calcite -1.214e-02 -1.333e-02 -1.098e-02 CaCO3 + Anhydrite 2.252e-02 2.076e-02 2.297e-02 CaSO4 + CH2O 3.455e-03 3.003e-03 4.297e-03 CH2O + Goethite 7.821e-04 6.533e-04 1.015e-03 FeOOH + Pyrite -7.827e-04 -1.014e-03 -6.553e-04 FeS2 + Ca.75Mg.25X2 -7.652e-03 -8.576e-03 -6.972e-03 Ca.75Mg.25X2 + NaX 1.530e-02 1.394e-02 1.715e-02 NaX + Halite 1.531e-02 1.429e-02 1.633e-02 NaCl + Sylvite 2.520e-03 2.392e-03 2.648e-03 KCl + +Redox mole transfers: + Fe(3) 7.821e-04 + H(0) -1.190e-09 + S(-2) -1.825e-03 + +Sum of residuals (epsilons in documentation): 4.207e+00 +Sum of delta/uncertainty limit: 8.243e+00 +Maximum fractional error in element concentration: 5.000e-02 + +Model contains minimum number of phases. +=============================================================================== + + +Summary of inverse modeling: + + Number of models found: 2 + Number of minimal models found: 2 + Number of infeasible sets of phases saved: 28 + Number of calls to cl1: 80 +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex2.log b/Sun/examples/ex2.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex2.out b/Sun/examples/ex2.out new file mode 100644 index 00000000..5f57d4e9 --- /dev/null +++ b/Sun/examples/ex2.out @@ -0,0 +1,4037 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex2 + Output file: ex2.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 2.--Temperature dependence of solubility + of gypsum and anhydrite + SOLUTION 1 Pure water + pH 7.0 + temp 25.0 + EQUILIBRIUM_PHASES 1 + Gypsum 0.0 1.0 + Anhydrite 0.0 1.0 + REACTION_TEMPERATURE 1 + 25.0 75.0 in 51 steps + SELECTED_OUTPUT + file ex2.sel + temperature + si anhydrite gypsum + END +----- +TITLE +----- + + Example 2.--Temperature dependence of solubility + of gypsum and anhydrite + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Pure water + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Pure water + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.082e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 + H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 +H(0) 1.416e-25 + H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 0.00 1.51 H2O + O2(g) -39.12 -42.08 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.22 -4.58 -4.36 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.849e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.564e-02 1.508e-02 + S 1.564e-02 1.508e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.067 Charge balance + pe = 10.686 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.178e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -9.881e-11 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070728e+02 + Total O = 5.359671e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.417e-07 1.167e-07 -6.849 -6.933 -0.084 + H+ 9.957e-08 8.575e-08 -7.002 -7.067 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.564e-02 + Ca+2 1.045e-02 5.176e-03 -1.981 -2.286 -0.305 + CaSO4 5.191e-03 5.242e-03 -2.285 -2.281 0.004 + CaOH+ 1.204e-08 1.001e-08 -7.919 -7.999 -0.080 + CaHSO4+ 3.166e-09 2.633e-09 -8.499 -8.580 -0.080 +H(0) 4.375e-39 + H2 2.187e-39 2.209e-39 -38.660 -38.656 0.004 +O(0) 1.691e-15 + O2 8.457e-16 8.539e-16 -15.073 -15.069 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -117.650 -117.734 -0.084 + H2S 0.000e+00 0.000e+00 -117.863 -117.859 0.004 + S-2 0.000e+00 0.000e+00 -123.274 -123.585 -0.312 +S(6) 1.564e-02 + SO4-2 1.045e-02 5.075e-03 -1.981 -2.295 -0.313 + CaSO4 5.191e-03 5.242e-03 -2.285 -2.281 0.004 + HSO4- 5.088e-08 4.231e-08 -7.293 -7.374 -0.080 + CaHSO4+ 3.166e-09 2.633e-09 -8.499 -8.580 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.22 -4.58 -4.36 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -35.51 -38.66 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -116.86 -117.86 -1.00 H2S + O2(g) -12.11 -15.07 -2.96 O2 + Sulfur -87.24 -82.35 4.88 S + +Reaction step 2. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.22 -4.58 -4.37 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.849e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.569e-02 1.514e-02 + S 1.569e-02 1.514e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.053 Charge balance + pe = 10.617 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.182e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 26.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.070730e+02 + Total O = 5.359703e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.482e-07 1.220e-07 -6.829 -6.914 -0.084 + H+ 1.027e-07 8.845e-08 -6.988 -7.053 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.569e-02 + Ca+2 1.046e-02 5.174e-03 -1.981 -2.286 -0.306 + CaSO4 5.236e-03 5.287e-03 -2.281 -2.277 0.004 + CaOH+ 1.167e-08 9.704e-09 -7.933 -8.013 -0.080 + CaHSO4+ 3.337e-09 2.774e-09 -8.477 -8.557 -0.080 +H(0) 6.343e-39 + H2 3.172e-39 3.202e-39 -38.499 -38.495 0.004 +O(0) 1.687e-15 + O2 8.436e-16 8.517e-16 -15.074 -15.070 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -117.121 -117.205 -0.084 + H2S 0.000e+00 0.000e+00 -117.334 -117.330 0.004 + S-2 0.000e+00 0.000e+00 -122.728 -123.041 -0.312 +S(6) 1.569e-02 + SO4-2 1.046e-02 5.073e-03 -1.981 -2.295 -0.314 + CaSO4 5.236e-03 5.287e-03 -2.281 -2.277 0.004 + HSO4- 5.364e-08 4.459e-08 -7.270 -7.351 -0.080 + CaHSO4+ 3.337e-09 2.774e-09 -8.477 -8.557 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.22 -4.58 -4.37 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -35.34 -38.49 -3.15 H2 + H2O(g) -1.48 -0.00 1.48 H2O + H2S(g) -116.32 -117.33 -1.01 H2S + O2(g) -12.11 -15.07 -2.96 O2 + Sulfur -86.85 -81.99 4.86 S + +Reaction step 3. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.21 -4.58 -4.37 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.848e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.574e-02 1.519e-02 + S 1.574e-02 1.519e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.040 Charge balance + pe = 10.572 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.186e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 27.000 + Electrical balance (eq) = -1.001e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 20 + Total H = 1.070732e+02 + Total O = 5.359733e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.548e-07 1.274e-07 -6.810 -6.895 -0.085 + H+ 1.060e-07 9.122e-08 -6.975 -7.040 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.574e-02 + Ca+2 1.047e-02 5.172e-03 -1.980 -2.286 -0.306 + CaSO4 5.279e-03 5.330e-03 -2.277 -2.273 0.004 + CaOH+ 1.132e-08 9.405e-09 -7.946 -8.027 -0.080 + CaHSO4+ 3.516e-09 2.922e-09 -8.454 -8.534 -0.080 +H(0) 8.213e-39 + H2 4.107e-39 4.146e-39 -38.387 -38.382 0.004 +O(0) 2.100e-15 + O2 1.050e-15 1.060e-15 -14.979 -14.975 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -116.788 -116.873 -0.085 + H2S 0.000e+00 0.000e+00 -117.001 -116.997 0.004 + S-2 0.000e+00 0.000e+00 -122.379 -122.692 -0.313 +S(6) 1.574e-02 + SO4-2 1.047e-02 5.071e-03 -1.980 -2.295 -0.315 + CaSO4 5.279e-03 5.330e-03 -2.277 -2.273 0.004 + HSO4- 5.655e-08 4.699e-08 -7.248 -7.328 -0.080 + CaHSO4+ 3.516e-09 2.922e-09 -8.454 -8.534 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.21 -4.58 -4.37 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -35.22 -38.38 -3.16 H2 + H2O(g) -1.46 -0.00 1.46 H2O + H2S(g) -115.98 -117.00 -1.02 H2S + O2(g) -12.01 -14.97 -2.97 O2 + Sulfur -86.61 -81.77 4.84 S + +Reaction step 4. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.21 -4.58 -4.37 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.848e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.579e-02 1.523e-02 + S 1.579e-02 1.523e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.027 Charge balance + pe = 10.479 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.189e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 28.000 + Electrical balance (eq) = -9.955e-11 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 22 + Total H = 1.070734e+02 + Total O = 5.359762e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.617e-07 1.330e-07 -6.791 -6.876 -0.085 + H+ 1.093e-07 9.404e-08 -6.961 -7.027 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.579e-02 + Ca+2 1.047e-02 5.168e-03 -1.980 -2.287 -0.307 + CaSO4 5.321e-03 5.373e-03 -2.274 -2.270 0.004 + CaOH+ 1.097e-08 9.117e-09 -7.960 -8.040 -0.081 + CaHSO4+ 3.703e-09 3.076e-09 -8.431 -8.512 -0.081 +H(0) 1.325e-38 + H2 6.624e-39 6.688e-39 -38.179 -38.175 0.004 +O(0) 1.677e-15 + O2 8.383e-16 8.464e-16 -15.077 -15.072 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -116.073 -116.158 -0.085 + H2S 0.000e+00 0.000e+00 -116.285 -116.281 0.004 + S-2 0.000e+00 0.000e+00 -121.647 -121.961 -0.314 +S(6) 1.579e-02 + SO4-2 1.047e-02 5.067e-03 -1.980 -2.295 -0.315 + CaSO4 5.321e-03 5.373e-03 -2.274 -2.270 0.004 + HSO4- 5.959e-08 4.950e-08 -7.225 -7.305 -0.081 + CaHSO4+ 3.703e-09 3.076e-09 -8.431 -8.512 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.21 -4.58 -4.37 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -35.01 -38.17 -3.16 H2 + H2O(g) -1.43 -0.00 1.43 H2O + H2S(g) -115.25 -116.28 -1.03 H2S + O2(g) -12.10 -15.07 -2.97 O2 + Sulfur -86.08 -81.27 4.81 S + +Reaction step 5. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.20 -4.58 -4.38 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.847e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.584e-02 1.528e-02 + S 1.584e-02 1.528e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.014 Charge balance + pe = 10.411 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.191e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 29.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.070735e+02 + Total O = 5.359788e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.688e-07 1.388e-07 -6.773 -6.858 -0.085 + H+ 1.127e-07 9.693e-08 -6.948 -7.014 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.584e-02 + Ca+2 1.048e-02 5.164e-03 -1.980 -2.287 -0.307 + CaSO4 5.361e-03 5.413e-03 -2.271 -2.267 0.004 + CaOH+ 1.064e-08 8.838e-09 -7.973 -8.054 -0.081 + CaHSO4+ 3.899e-09 3.238e-09 -8.409 -8.490 -0.081 +H(0) 1.909e-38 + H2 9.547e-39 9.639e-39 -38.020 -38.016 0.004 +O(0) 1.668e-15 + O2 8.339e-16 8.420e-16 -15.079 -15.075 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -115.552 -115.637 -0.085 + H2S 0.000e+00 0.000e+00 -115.764 -115.759 0.004 + S-2 0.000e+00 0.000e+00 -121.110 -121.424 -0.314 +S(6) 1.584e-02 + SO4-2 1.048e-02 5.063e-03 -1.980 -2.296 -0.316 + CaSO4 5.361e-03 5.413e-03 -2.271 -2.267 0.004 + HSO4- 6.279e-08 5.214e-08 -7.202 -7.283 -0.081 + CaHSO4+ 3.899e-09 3.238e-09 -8.409 -8.490 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.20 -4.58 -4.38 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -34.85 -38.02 -3.17 H2 + H2O(g) -1.41 -0.00 1.41 H2O + H2S(g) -114.72 -115.76 -1.04 H2S + O2(g) -12.10 -15.07 -2.98 O2 + Sulfur -85.70 -80.91 4.79 S + +Reaction step 6. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.20 -4.58 -4.39 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.847e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.588e-02 1.532e-02 + S 1.588e-02 1.532e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.001 Charge balance + pe = 10.344 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.193e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 30.000 + Electrical balance (eq) = -9.775e-11 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.070737e+02 + Total O = 5.359813e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.762e-07 1.448e-07 -6.754 -6.839 -0.085 + H+ 1.161e-07 9.988e-08 -6.935 -7.001 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.588e-02 + Ca+2 1.048e-02 5.160e-03 -1.980 -2.287 -0.308 + CaSO4 5.400e-03 5.453e-03 -2.268 -2.263 0.004 + CaOH+ 1.032e-08 8.569e-09 -7.986 -8.067 -0.081 + CaHSO4+ 4.103e-09 3.406e-09 -8.387 -8.468 -0.081 +H(0) 2.734e-38 + H2 1.367e-38 1.380e-38 -37.864 -37.860 0.004 +O(0) 1.673e-15 + O2 8.364e-16 8.445e-16 -15.078 -15.073 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -115.042 -115.128 -0.085 + H2S 0.000e+00 0.000e+00 -115.253 -115.249 0.004 + S-2 0.000e+00 0.000e+00 -120.584 -120.899 -0.315 +S(6) 1.588e-02 + SO4-2 1.048e-02 5.059e-03 -1.980 -2.296 -0.316 + CaSO4 5.400e-03 5.453e-03 -2.268 -2.263 0.004 + HSO4- 6.614e-08 5.491e-08 -7.180 -7.260 -0.081 + CaHSO4+ 4.103e-09 3.406e-09 -8.387 -8.468 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.20 -4.58 -4.39 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -34.69 -37.86 -3.17 H2 + H2O(g) -1.38 -0.00 1.38 H2O + H2S(g) -114.20 -115.25 -1.05 H2S + O2(g) -12.09 -15.07 -2.98 O2 + Sulfur -85.33 -80.56 4.77 S + +Reaction step 7. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.19 -4.58 -4.39 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.592e-02 1.536e-02 + S 1.592e-02 1.536e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.988 Charge balance + pe = 10.277 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.194e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 31.000 + Electrical balance (eq) = -1.014e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.070739e+02 + Total O = 5.359836e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.837e-07 1.510e-07 -6.736 -6.821 -0.085 + H+ 1.197e-07 1.029e-07 -6.922 -6.988 -0.066 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.592e-02 + Ca+2 1.049e-02 5.154e-03 -1.979 -2.288 -0.308 + CaSO4 5.438e-03 5.491e-03 -2.265 -2.260 0.004 + CaOH+ 1.001e-08 8.310e-09 -7.999 -8.080 -0.081 + CaHSO4+ 4.317e-09 3.582e-09 -8.365 -8.446 -0.081 +H(0) 3.917e-38 + H2 1.959e-38 1.978e-38 -37.708 -37.704 0.004 +O(0) 1.668e-15 + O2 8.342e-16 8.423e-16 -15.079 -15.075 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -114.531 -114.617 -0.085 + H2S 0.000e+00 0.000e+00 -114.740 -114.736 0.004 + S-2 0.000e+00 0.000e+00 -120.057 -120.372 -0.315 +S(6) 1.592e-02 + SO4-2 1.048e-02 5.053e-03 -1.979 -2.296 -0.317 + CaSO4 5.438e-03 5.491e-03 -2.265 -2.260 0.004 + HSO4- 6.966e-08 5.780e-08 -7.157 -7.238 -0.081 + CaHSO4+ 4.317e-09 3.582e-09 -8.365 -8.446 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.19 -4.58 -4.39 CaSO4 + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -34.53 -37.70 -3.18 H2 + H2O(g) -1.36 -0.00 1.36 H2O + H2S(g) -113.67 -114.74 -1.06 H2S + O2(g) -12.09 -15.07 -2.99 O2 + Sulfur -84.95 -80.21 4.74 S + +Reaction step 8. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.19 -4.59 -4.40 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.596e-02 1.539e-02 + S 1.596e-02 1.539e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.975 Charge balance + pe = 10.210 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.194e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 32.000 + Electrical balance (eq) = -1.029e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070740e+02 + Total O = 5.359858e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.916e-07 1.573e-07 -6.718 -6.803 -0.085 + H+ 1.233e-07 1.060e-07 -6.909 -6.975 -0.066 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.596e-02 + Ca+2 1.049e-02 5.148e-03 -1.979 -2.288 -0.309 + CaSO4 5.474e-03 5.527e-03 -2.262 -2.258 0.004 + CaOH+ 9.715e-09 8.059e-09 -8.013 -8.094 -0.081 + CaHSO4+ 4.540e-09 3.766e-09 -8.343 -8.424 -0.081 +H(0) 5.596e-38 + H2 2.798e-38 2.825e-38 -37.553 -37.549 0.004 +O(0) 1.666e-15 + O2 8.330e-16 8.410e-16 -15.079 -15.075 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -114.024 -114.110 -0.085 + H2S 0.000e+00 0.000e+00 -114.232 -114.228 0.004 + S-2 0.000e+00 0.000e+00 -119.534 -119.850 -0.316 +S(6) 1.596e-02 + SO4-2 1.049e-02 5.047e-03 -1.979 -2.297 -0.318 + CaSO4 5.474e-03 5.527e-03 -2.262 -2.258 0.004 + HSO4- 7.334e-08 6.084e-08 -7.135 -7.216 -0.081 + CaHSO4+ 4.540e-09 3.766e-09 -8.343 -8.424 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.19 -4.59 -4.40 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -34.37 -37.55 -3.18 H2 + H2O(g) -1.33 -0.00 1.33 H2O + H2S(g) -113.15 -114.23 -1.07 H2S + O2(g) -12.08 -15.08 -2.99 O2 + Sulfur -84.58 -79.86 4.72 S + +Reaction step 9. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.18 -4.59 -4.40 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.599e-02 1.543e-02 + S 1.599e-02 1.543e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.962 Charge balance + pe = 10.149 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.194e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 33.000 + Electrical balance (eq) = -9.966e-11 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.070741e+02 + Total O = 5.359877e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.996e-07 1.639e-07 -6.700 -6.785 -0.086 + H+ 1.270e-07 1.091e-07 -6.896 -6.962 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.599e-02 + Ca+2 1.049e-02 5.142e-03 -1.979 -2.289 -0.309 + CaSO4 5.508e-03 5.562e-03 -2.259 -2.255 0.004 + CaOH+ 9.427e-09 7.818e-09 -8.026 -8.107 -0.081 + CaHSO4+ 4.772e-09 3.957e-09 -8.321 -8.403 -0.081 +H(0) 7.777e-38 + H2 3.888e-38 3.926e-38 -37.410 -37.406 0.004 +O(0) 1.749e-15 + O2 8.746e-16 8.831e-16 -15.058 -15.054 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -113.565 -113.650 -0.086 + H2S 0.000e+00 0.000e+00 -113.771 -113.767 0.004 + S-2 0.000e+00 0.000e+00 -119.058 -119.374 -0.316 +S(6) 1.599e-02 + SO4-2 1.048e-02 5.041e-03 -1.979 -2.297 -0.318 + CaSO4 5.508e-03 5.562e-03 -2.259 -2.255 0.004 + HSO4- 7.720e-08 6.402e-08 -7.112 -7.194 -0.081 + CaHSO4+ 4.772e-09 3.957e-09 -8.321 -8.403 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.18 -4.59 -4.40 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -34.22 -37.41 -3.18 H2 + H2O(g) -1.31 -0.00 1.31 H2O + H2S(g) -112.68 -113.77 -1.08 H2S + O2(g) -12.06 -15.05 -3.00 O2 + Sulfur -84.24 -79.54 4.70 S + +Reaction step 10. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.18 -4.59 -4.41 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.602e-02 1.546e-02 + S 1.602e-02 1.546e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.950 Charge balance + pe = 10.078 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.193e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 34.000 + Electrical balance (eq) = -1.005e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.070743e+02 + Total O = 5.359895e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.079e-07 1.707e-07 -6.682 -6.768 -0.086 + H+ 1.307e-07 1.123e-07 -6.884 -6.950 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.602e-02 + Ca+2 1.048e-02 5.134e-03 -1.980 -2.290 -0.310 + CaSO4 5.541e-03 5.595e-03 -2.256 -2.252 0.004 + CaOH+ 9.149e-09 7.585e-09 -8.039 -8.120 -0.081 + CaHSO4+ 5.015e-09 4.157e-09 -8.300 -8.381 -0.081 +H(0) 1.129e-37 + H2 5.647e-38 5.701e-38 -37.248 -37.244 0.004 +O(0) 1.675e-15 + O2 8.373e-16 8.454e-16 -15.077 -15.073 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -113.028 -113.114 -0.086 + H2S 0.000e+00 0.000e+00 -113.233 -113.229 0.004 + S-2 0.000e+00 0.000e+00 -118.505 -118.822 -0.317 +S(6) 1.602e-02 + SO4-2 1.048e-02 5.034e-03 -1.980 -2.298 -0.319 + CaSO4 5.541e-03 5.595e-03 -2.256 -2.252 0.004 + HSO4- 8.124e-08 6.734e-08 -7.090 -7.172 -0.081 + CaHSO4+ 5.015e-09 4.157e-09 -8.300 -8.381 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.18 -4.59 -4.41 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -34.06 -37.24 -3.19 H2 + H2O(g) -1.28 -0.00 1.28 H2O + H2S(g) -112.13 -113.23 -1.10 H2S + O2(g) -12.07 -15.07 -3.00 O2 + Sulfur -83.85 -79.17 4.68 S + +Reaction step 11. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.17 -4.59 -4.42 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.605e-02 1.548e-02 + S 1.605e-02 1.548e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.937 Charge balance + pe = 10.013 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.191e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 35.000 + Electrical balance (eq) = -1.043e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 20 + Total H = 1.070744e+02 + Total O = 5.359911e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.165e-07 1.776e-07 -6.665 -6.750 -0.086 + H+ 1.345e-07 1.155e-07 -6.871 -6.937 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.605e-02 + Ca+2 1.048e-02 5.126e-03 -1.980 -2.290 -0.310 + CaSO4 5.573e-03 5.627e-03 -2.254 -2.250 0.004 + CaOH+ 8.881e-09 7.360e-09 -8.052 -8.133 -0.082 + CaHSO4+ 5.267e-09 4.365e-09 -8.278 -8.360 -0.082 +H(0) 1.600e-37 + H2 8.002e-38 8.080e-38 -37.097 -37.093 0.004 +O(0) 1.676e-15 + O2 8.378e-16 8.459e-16 -15.077 -15.073 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -112.533 -112.619 -0.086 + H2S 0.000e+00 0.000e+00 -112.737 -112.733 0.004 + S-2 0.000e+00 0.000e+00 -117.994 -118.312 -0.317 +S(6) 1.605e-02 + SO4-2 1.048e-02 5.026e-03 -1.980 -2.299 -0.319 + CaSO4 5.573e-03 5.627e-03 -2.254 -2.250 0.004 + HSO4- 8.546e-08 7.082e-08 -7.068 -7.150 -0.082 + CaHSO4+ 5.267e-09 4.365e-09 -8.278 -8.360 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.17 -4.59 -4.42 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -33.90 -37.09 -3.19 H2 + H2O(g) -1.26 -0.00 1.26 H2O + H2S(g) -111.63 -112.73 -1.11 H2S + O2(g) -12.07 -15.07 -3.00 O2 + Sulfur -83.49 -78.83 4.66 S + +Reaction step 12. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.17 -4.59 -4.42 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.608e-02 1.551e-02 + S 1.608e-02 1.551e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.925 Charge balance + pe = 9.946 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.189e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 36.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.070745e+02 + Total O = 5.359925e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.253e-07 1.848e-07 -6.647 -6.733 -0.086 + H+ 1.384e-07 1.189e-07 -6.859 -6.925 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.608e-02 + Ca+2 1.047e-02 5.118e-03 -1.980 -2.291 -0.311 + CaSO4 5.603e-03 5.657e-03 -2.252 -2.247 0.004 + CaOH+ 8.622e-09 7.143e-09 -8.064 -8.146 -0.082 + CaHSO4+ 5.530e-09 4.582e-09 -8.257 -8.339 -0.082 +H(0) 2.285e-37 + H2 1.143e-37 1.154e-37 -36.942 -36.938 0.004 +O(0) 1.644e-15 + O2 8.221e-16 8.301e-16 -15.085 -15.081 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -112.024 -112.110 -0.086 + H2S 0.000e+00 0.000e+00 -112.227 -112.223 0.004 + S-2 0.000e+00 0.000e+00 -117.470 -117.788 -0.318 +S(6) 1.608e-02 + SO4-2 1.047e-02 5.018e-03 -1.980 -2.300 -0.320 + CaSO4 5.603e-03 5.657e-03 -2.252 -2.247 0.004 + HSO4- 8.988e-08 7.446e-08 -7.046 -7.128 -0.082 + CaHSO4+ 5.530e-09 4.582e-09 -8.257 -8.339 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.17 -4.59 -4.42 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -33.74 -36.94 -3.20 H2 + H2O(g) -1.24 -0.00 1.24 H2O + H2S(g) -111.11 -112.22 -1.12 H2S + O2(g) -12.07 -15.08 -3.01 O2 + Sulfur -83.11 -78.48 4.63 S + +Reaction step 13. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.16 -4.59 -4.43 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.610e-02 1.553e-02 + S 1.610e-02 1.553e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.913 Charge balance + pe = 9.884 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.186e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 37.000 + Electrical balance (eq) = -1.048e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 22 + Total H = 1.070745e+02 + Total O = 5.359938e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.344e-07 1.922e-07 -6.630 -6.716 -0.086 + H+ 1.423e-07 1.222e-07 -6.847 -6.913 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.610e-02 + Ca+2 1.047e-02 5.109e-03 -1.980 -2.292 -0.311 + CaSO4 5.632e-03 5.686e-03 -2.249 -2.245 0.004 + CaOH+ 8.373e-09 6.934e-09 -8.077 -8.159 -0.082 + CaHSO4+ 5.804e-09 4.807e-09 -8.236 -8.318 -0.082 +H(0) 3.186e-37 + H2 1.593e-37 1.609e-37 -36.798 -36.794 0.004 +O(0) 1.684e-15 + O2 8.422e-16 8.504e-16 -15.075 -15.070 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -111.557 -111.643 -0.086 + H2S 0.000e+00 0.000e+00 -111.757 -111.753 0.004 + S-2 0.000e+00 0.000e+00 -116.986 -117.305 -0.318 +S(6) 1.610e-02 + SO4-2 1.047e-02 5.009e-03 -1.980 -2.300 -0.320 + CaSO4 5.632e-03 5.686e-03 -2.249 -2.245 0.004 + HSO4- 9.450e-08 7.827e-08 -7.025 -7.106 -0.082 + CaHSO4+ 5.804e-09 4.807e-09 -8.236 -8.318 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.16 -4.59 -4.43 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -33.59 -36.79 -3.20 H2 + H2O(g) -1.21 -0.00 1.21 H2O + H2S(g) -110.63 -111.75 -1.13 H2S + O2(g) -12.06 -15.07 -3.01 O2 + Sulfur -82.77 -78.16 4.61 S + +Reaction step 14. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.15 -4.59 -4.44 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.612e-02 1.554e-02 + S 1.612e-02 1.554e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.901 Charge balance + pe = 9.865 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.183e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 38.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070746e+02 + Total O = 5.359949e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.438e-07 1.999e-07 -6.613 -6.699 -0.086 + H+ 1.464e-07 1.256e-07 -6.835 -6.901 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.612e-02 + Ca+2 1.046e-02 5.099e-03 -1.981 -2.293 -0.312 + CaSO4 5.659e-03 5.714e-03 -2.247 -2.243 0.004 + CaOH+ 8.132e-09 6.733e-09 -8.090 -8.172 -0.082 + CaHSO4+ 6.089e-09 5.042e-09 -8.215 -8.297 -0.082 +H(0) 3.638e-37 + H2 1.819e-37 1.837e-37 -36.740 -36.736 0.004 +O(0) 2.562e-15 + O2 1.281e-15 1.293e-15 -14.893 -14.888 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -111.435 -111.521 -0.086 + H2S 0.000e+00 0.000e+00 -111.634 -111.630 0.004 + S-2 0.000e+00 0.000e+00 -116.849 -117.168 -0.319 +S(6) 1.612e-02 + SO4-2 1.046e-02 4.999e-03 -1.981 -2.301 -0.321 + CaSO4 5.659e-03 5.714e-03 -2.247 -2.243 0.004 + HSO4- 9.933e-08 8.224e-08 -7.003 -7.085 -0.082 + CaHSO4+ 6.089e-09 5.042e-09 -8.215 -8.297 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.15 -4.59 -4.44 CaSO4 + Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O + H2(g) -33.53 -36.74 -3.20 H2 + H2O(g) -1.19 -0.00 1.19 H2O + H2S(g) -110.49 -111.63 -1.14 H2S + O2(g) -11.87 -14.89 -3.02 O2 + Sulfur -82.69 -78.10 4.59 S + +Reaction step 15. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.15 -4.60 -4.45 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.613e-02 1.556e-02 + S 1.613e-02 1.556e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.889 Charge balance + pe = 9.755 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.179e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 39.000 + Electrical balance (eq) = -1.056e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070747e+02 + Total O = 5.359958e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.534e-07 2.077e-07 -6.596 -6.683 -0.086 + H+ 1.504e-07 1.291e-07 -6.823 -6.889 -0.066 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.613e-02 + Ca+2 1.045e-02 5.089e-03 -1.981 -2.293 -0.312 + CaSO4 5.684e-03 5.739e-03 -2.245 -2.241 0.004 + CaOH+ 7.899e-09 6.538e-09 -8.102 -8.185 -0.082 + CaHSO4+ 6.386e-09 5.286e-09 -8.195 -8.277 -0.082 +H(0) 6.313e-37 + H2 3.156e-37 3.187e-37 -36.501 -36.497 0.004 +O(0) 1.680e-15 + O2 8.399e-16 8.480e-16 -15.076 -15.072 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -110.586 -110.673 -0.086 + H2S 0.000e+00 0.000e+00 -110.783 -110.779 0.004 + S-2 0.000e+00 0.000e+00 -115.984 -116.304 -0.319 +S(6) 1.613e-02 + SO4-2 1.045e-02 4.989e-03 -1.981 -2.302 -0.321 + CaSO4 5.684e-03 5.739e-03 -2.245 -2.241 0.004 + HSO4- 1.044e-07 8.640e-08 -6.981 -7.064 -0.082 + CaHSO4+ 6.386e-09 5.286e-09 -8.195 -8.277 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.15 -4.60 -4.45 CaSO4 + Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O + H2(g) -33.29 -36.50 -3.21 H2 + H2O(g) -1.16 -0.00 1.16 H2O + H2S(g) -109.63 -110.78 -1.15 H2S + O2(g) -12.05 -15.07 -3.02 O2 + Sulfur -82.06 -77.49 4.57 S + +Reaction step 16. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.14 -4.60 -4.46 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.614e-02 1.557e-02 + S 1.614e-02 1.557e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.877 Charge balance + pe = 9.692 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.174e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 40.000 + Electrical balance (eq) = -1.037e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070747e+02 + Total O = 5.359965e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.634e-07 2.158e-07 -6.579 -6.666 -0.086 + H+ 1.546e-07 1.326e-07 -6.811 -6.877 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.614e-02 + Ca+2 1.044e-02 5.078e-03 -1.981 -2.294 -0.313 + CaSO4 5.708e-03 5.764e-03 -2.243 -2.239 0.004 + CaOH+ 7.675e-09 6.351e-09 -8.115 -8.197 -0.082 + CaHSO4+ 6.694e-09 5.539e-09 -8.174 -8.257 -0.082 +H(0) 8.826e-37 + H2 4.413e-37 4.456e-37 -36.355 -36.351 0.004 +O(0) 1.689e-15 + O2 8.445e-16 8.527e-16 -15.073 -15.069 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -110.112 -110.198 -0.086 + H2S 0.000e+00 0.000e+00 -110.307 -110.303 0.004 + S-2 0.000e+00 0.000e+00 -115.494 -115.814 -0.320 +S(6) 1.614e-02 + SO4-2 1.044e-02 4.979e-03 -1.981 -2.303 -0.321 + CaSO4 5.708e-03 5.764e-03 -2.243 -2.239 0.004 + HSO4- 1.097e-07 9.073e-08 -6.960 -7.042 -0.082 + CaHSO4+ 6.694e-09 5.539e-09 -8.174 -8.257 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.14 -4.60 -4.46 CaSO4 + Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O + H2(g) -33.14 -36.35 -3.21 H2 + H2O(g) -1.14 -0.00 1.14 H2O + H2S(g) -109.15 -110.30 -1.16 H2S + O2(g) -12.04 -15.07 -3.02 O2 + Sulfur -81.71 -77.16 4.55 S + +Reaction step 17. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.13 -4.60 -4.47 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.615e-02 1.558e-02 + S 1.615e-02 1.558e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.866 Charge balance + pe = 9.629 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.169e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 41.000 + Electrical balance (eq) = -1.043e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070748e+02 + Total O = 5.359970e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.736e-07 2.241e-07 -6.563 -6.649 -0.087 + H+ 1.588e-07 1.362e-07 -6.799 -6.866 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.615e-02 + Ca+2 1.042e-02 5.066e-03 -1.982 -2.295 -0.313 + CaSO4 5.731e-03 5.786e-03 -2.242 -2.238 0.004 + CaOH+ 7.458e-09 6.170e-09 -8.127 -8.210 -0.082 + CaHSO4+ 7.014e-09 5.802e-09 -8.154 -8.236 -0.082 +H(0) 1.237e-36 + H2 6.185e-37 6.244e-37 -36.209 -36.205 0.004 +O(0) 1.683e-15 + O2 8.416e-16 8.497e-16 -15.075 -15.071 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -109.633 -109.719 -0.087 + H2S 0.000e+00 0.000e+00 -109.826 -109.822 0.004 + S-2 0.000e+00 0.000e+00 -115.000 -115.320 -0.320 +S(6) 1.615e-02 + SO4-2 1.042e-02 4.967e-03 -1.982 -2.304 -0.322 + CaSO4 5.731e-03 5.786e-03 -2.242 -2.238 0.004 + HSO4- 1.152e-07 9.526e-08 -6.939 -7.021 -0.082 + CaHSO4+ 7.014e-09 5.802e-09 -8.154 -8.236 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.13 -4.60 -4.47 CaSO4 + Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O + H2(g) -32.99 -36.20 -3.22 H2 + H2O(g) -1.12 -0.00 1.12 H2O + H2S(g) -108.65 -109.82 -1.17 H2S + O2(g) -12.04 -15.07 -3.03 O2 + Sulfur -81.36 -76.83 4.53 S + +Reaction step 18. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.13 -4.60 -4.47 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.616e-02 1.559e-02 + S 1.616e-02 1.559e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.854 Charge balance + pe = 9.564 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.164e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 42.000 + Electrical balance (eq) = -1.067e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070748e+02 + Total O = 5.359974e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.842e-07 2.327e-07 -6.546 -6.633 -0.087 + H+ 1.631e-07 1.398e-07 -6.788 -6.854 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.616e-02 + Ca+2 1.041e-02 5.054e-03 -1.983 -2.296 -0.314 + CaSO4 5.752e-03 5.808e-03 -2.240 -2.236 0.004 + CaHSO4+ 7.346e-09 6.075e-09 -8.134 -8.216 -0.082 + CaOH+ 7.249e-09 5.995e-09 -8.140 -8.222 -0.082 +H(0) 1.736e-36 + H2 8.682e-37 8.766e-37 -36.061 -36.057 0.004 +O(0) 1.664e-15 + O2 8.322e-16 8.402e-16 -15.080 -15.076 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -109.150 -109.237 -0.087 + H2S 0.000e+00 0.000e+00 -109.341 -109.337 0.004 + S-2 0.000e+00 0.000e+00 -114.502 -114.822 -0.321 +S(6) 1.616e-02 + SO4-2 1.041e-02 4.956e-03 -1.983 -2.305 -0.322 + CaSO4 5.752e-03 5.808e-03 -2.240 -2.236 0.004 + HSO4- 1.209e-07 9.998e-08 -6.918 -7.000 -0.082 + CaHSO4+ 7.346e-09 6.075e-09 -8.134 -8.216 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.13 -4.60 -4.47 CaSO4 + Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O + H2(g) -32.84 -36.06 -3.22 H2 + H2O(g) -1.09 -0.00 1.09 H2O + H2S(g) -108.16 -109.34 -1.18 H2S + O2(g) -12.04 -15.08 -3.03 O2 + Sulfur -81.01 -76.50 4.51 S + +Reaction step 19. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.12 -4.60 -4.48 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.616e-02 1.559e-02 + S 1.616e-02 1.559e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.843 Charge balance + pe = 9.503 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.157e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 43.000 + Electrical balance (eq) = -1.056e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070748e+02 + Total O = 5.359977e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.950e-07 2.416e-07 -6.530 -6.617 -0.087 + H+ 1.674e-07 1.435e-07 -6.776 -6.843 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.616e-02 + Ca+2 1.039e-02 5.042e-03 -1.983 -2.297 -0.314 + CaSO4 5.772e-03 5.827e-03 -2.239 -2.235 0.004 + CaHSO4+ 7.691e-09 6.359e-09 -8.114 -8.197 -0.083 + CaOH+ 7.048e-09 5.827e-09 -8.152 -8.235 -0.083 +H(0) 2.404e-36 + H2 1.202e-36 1.213e-36 -35.920 -35.916 0.004 +O(0) 1.686e-15 + O2 8.429e-16 8.510e-16 -15.074 -15.070 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -108.692 -108.778 -0.087 + H2S 0.000e+00 0.000e+00 -108.881 -108.877 0.004 + S-2 0.000e+00 0.000e+00 -114.027 -114.348 -0.321 +S(6) 1.616e-02 + SO4-2 1.039e-02 4.944e-03 -1.983 -2.306 -0.323 + CaSO4 5.772e-03 5.827e-03 -2.239 -2.235 0.004 + HSO4- 1.269e-07 1.049e-07 -6.897 -6.979 -0.083 + CaHSO4+ 7.691e-09 6.359e-09 -8.114 -8.197 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.12 -4.60 -4.48 CaSO4 + Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O + H2(g) -32.69 -35.92 -3.22 H2 + H2O(g) -1.07 -0.00 1.07 H2O + H2S(g) -107.69 -108.88 -1.19 H2S + O2(g) -12.03 -15.07 -3.04 O2 + Sulfur -80.67 -76.18 4.49 S + +Reaction step 20. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.11 -4.61 -4.49 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.617e-02 1.559e-02 + S 1.617e-02 1.559e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.832 Charge balance + pe = 9.445 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.150e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 44.000 + Electrical balance (eq) = -1.062e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070748e+02 + Total O = 5.359977e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.062e-07 2.506e-07 -6.514 -6.601 -0.087 + H+ 1.718e-07 1.473e-07 -6.765 -6.832 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.617e-02 + Ca+2 1.038e-02 5.028e-03 -1.984 -2.299 -0.315 + CaSO4 5.790e-03 5.845e-03 -2.237 -2.233 0.004 + CaHSO4+ 8.049e-09 6.653e-09 -8.094 -8.177 -0.083 + CaOH+ 6.853e-09 5.665e-09 -8.164 -8.247 -0.083 +H(0) 3.282e-36 + H2 1.641e-36 1.657e-36 -35.785 -35.781 0.004 +O(0) 1.748e-15 + O2 8.739e-16 8.823e-16 -15.059 -15.054 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -108.256 -108.343 -0.087 + H2S 0.000e+00 0.000e+00 -108.443 -108.439 0.004 + S-2 0.000e+00 0.000e+00 -113.577 -113.898 -0.321 +S(6) 1.617e-02 + SO4-2 1.038e-02 4.931e-03 -1.984 -2.307 -0.323 + CaSO4 5.790e-03 5.845e-03 -2.237 -2.233 0.004 + HSO4- 1.331e-07 1.100e-07 -6.876 -6.958 -0.083 + CaHSO4+ 8.049e-09 6.653e-09 -8.094 -8.177 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.11 -4.61 -4.49 CaSO4 + Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O + H2(g) -32.55 -35.78 -3.23 H2 + H2O(g) -1.05 -0.00 1.05 H2O + H2S(g) -107.24 -108.44 -1.20 H2S + O2(g) -12.01 -15.05 -3.04 O2 + Sulfur -80.35 -75.89 4.46 S + +Reaction step 21. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.11 -4.61 -4.50 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.616e-02 1.559e-02 + S 1.616e-02 1.559e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.821 Charge balance + pe = 9.379 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.143e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 45.000 + Electrical balance (eq) = -1.068e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070748e+02 + Total O = 5.359976e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.177e-07 2.600e-07 -6.498 -6.585 -0.087 + H+ 1.762e-07 1.510e-07 -6.754 -6.821 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.616e-02 + Ca+2 1.036e-02 5.015e-03 -1.985 -2.300 -0.315 + CaSO4 5.806e-03 5.862e-03 -2.236 -2.232 0.004 + CaHSO4+ 8.419e-09 6.957e-09 -8.075 -8.158 -0.083 + CaOH+ 6.666e-09 5.508e-09 -8.176 -8.259 -0.083 +H(0) 4.641e-36 + H2 2.320e-36 2.343e-36 -35.634 -35.630 0.004 +O(0) 1.682e-15 + O2 8.410e-16 8.491e-16 -15.075 -15.071 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -107.759 -107.846 -0.087 + H2S 0.000e+00 0.000e+00 -107.944 -107.940 0.004 + S-2 0.000e+00 0.000e+00 -113.064 -113.386 -0.322 +S(6) 1.616e-02 + SO4-2 1.036e-02 4.918e-03 -1.985 -2.308 -0.323 + CaSO4 5.806e-03 5.862e-03 -2.236 -2.232 0.004 + HSO4- 1.396e-07 1.154e-07 -6.855 -6.938 -0.083 + CaHSO4+ 8.419e-09 6.957e-09 -8.075 -8.158 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.11 -4.61 -4.50 CaSO4 + Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O + H2(g) -32.40 -35.63 -3.23 H2 + H2O(g) -1.03 -0.00 1.03 H2O + H2S(g) -106.73 -107.94 -1.21 H2S + O2(g) -12.03 -15.07 -3.04 O2 + Sulfur -79.98 -75.54 4.44 S + +Reaction step 22. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.10 -4.61 -4.51 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.616e-02 1.559e-02 + S 1.616e-02 1.559e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.810 Charge balance + pe = 9.316 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.135e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 46.000 + Electrical balance (eq) = -1.073e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070748e+02 + Total O = 5.359973e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.296e-07 2.696e-07 -6.482 -6.569 -0.087 + H+ 1.807e-07 1.549e-07 -6.743 -6.810 -0.067 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +Ca 1.616e-02 + Ca+2 1.034e-02 5.001e-03 -1.986 -2.301 -0.315 + CaSO4 5.821e-03 5.877e-03 -2.235 -2.231 0.004 + CaHSO4+ 8.804e-09 7.273e-09 -8.055 -8.138 -0.083 + CaOH+ 6.484e-09 5.357e-09 -8.188 -8.271 -0.083 +H(0) 6.456e-36 + H2 3.228e-36 3.259e-36 -35.491 -35.487 0.004 +O(0) 1.666e-15 + O2 8.330e-16 8.410e-16 -15.079 -15.075 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -107.291 -107.378 -0.087 + H2S 0.000e+00 0.000e+00 -107.473 -107.469 0.004 + S-2 0.000e+00 0.000e+00 -112.580 -112.902 -0.322 +S(6) 1.616e-02 + SO4-2 1.034e-02 4.904e-03 -1.986 -2.309 -0.324 + CaSO4 5.821e-03 5.877e-03 -2.235 -2.231 0.004 + HSO4- 1.464e-07 1.210e-07 -6.834 -6.917 -0.083 + CaHSO4+ 8.804e-09 7.273e-09 -8.055 -8.138 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.10 -4.61 -4.51 CaSO4 + Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O + H2(g) -32.25 -35.49 -3.23 H2 + H2O(g) -1.00 -0.00 1.00 H2O + H2S(g) -106.25 -107.47 -1.22 H2S + O2(g) -12.03 -15.08 -3.05 O2 + Sulfur -79.64 -75.22 4.42 S + +Reaction step 23. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.09 -4.61 -4.52 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.615e-02 1.558e-02 + S 1.615e-02 1.558e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.799 Charge balance + pe = 9.255 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.127e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 47.000 + Electrical balance (eq) = -1.079e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.070747e+02 + Total O = 5.359969e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.417e-07 2.795e-07 -6.466 -6.554 -0.087 + H+ 1.852e-07 1.587e-07 -6.732 -6.799 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.615e-02 + Ca+2 1.032e-02 4.986e-03 -1.986 -2.302 -0.316 + CaSO4 5.835e-03 5.891e-03 -2.234 -2.230 0.004 + CaHSO4+ 9.202e-09 7.600e-09 -8.036 -8.119 -0.083 + CaOH+ 6.310e-09 5.211e-09 -8.200 -8.283 -0.083 +H(0) 8.884e-36 + H2 4.442e-36 4.485e-36 -35.352 -35.348 0.004 +O(0) 1.679e-15 + O2 8.396e-16 8.477e-16 -15.076 -15.072 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -106.840 -106.927 -0.087 + H2S 0.000e+00 0.000e+00 -107.020 -107.016 0.004 + S-2 0.000e+00 0.000e+00 -112.114 -112.436 -0.323 +S(6) 1.615e-02 + SO4-2 1.032e-02 4.890e-03 -1.986 -2.311 -0.324 + CaSO4 5.835e-03 5.891e-03 -2.234 -2.230 0.004 + HSO4- 1.535e-07 1.268e-07 -6.814 -6.897 -0.083 + CaHSO4+ 9.202e-09 7.600e-09 -8.036 -8.119 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.09 -4.61 -4.52 CaSO4 + Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O + H2(g) -32.11 -35.35 -3.24 H2 + H2O(g) -0.98 -0.00 0.98 H2O + H2S(g) -105.79 -107.02 -1.23 H2S + O2(g) -12.02 -15.07 -3.05 O2 + Sulfur -79.31 -74.91 4.40 S + +Reaction step 24. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.08 -4.62 -4.53 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.614e-02 1.557e-02 + S 1.614e-02 1.557e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.789 Charge balance + pe = 9.192 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.118e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 48.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070747e+02 + Total O = 5.359963e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.543e-07 2.897e-07 -6.451 -6.538 -0.087 + H+ 1.898e-07 1.626e-07 -6.722 -6.789 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.614e-02 + Ca+2 1.029e-02 4.971e-03 -1.987 -2.304 -0.316 + CaSO4 5.847e-03 5.903e-03 -2.233 -2.229 0.004 + CaHSO4+ 9.614e-09 7.938e-09 -8.017 -8.100 -0.083 + CaOH+ 6.141e-09 5.070e-09 -8.212 -8.295 -0.083 +H(0) 1.237e-35 + H2 6.183e-36 6.242e-36 -35.209 -35.205 0.004 +O(0) 1.648e-15 + O2 8.239e-16 8.317e-16 -15.084 -15.080 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -106.369 -106.456 -0.087 + H2S 0.000e+00 0.000e+00 -106.546 -106.542 0.004 + S-2 0.000e+00 0.000e+00 -111.627 -111.950 -0.323 +S(6) 1.614e-02 + SO4-2 1.029e-02 4.875e-03 -1.987 -2.312 -0.325 + CaSO4 5.847e-03 5.903e-03 -2.233 -2.229 0.004 + HSO4- 1.609e-07 1.328e-07 -6.794 -6.877 -0.083 + CaHSO4+ 9.614e-09 7.938e-09 -8.017 -8.100 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.08 -4.62 -4.53 CaSO4 + Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O + H2(g) -31.96 -35.20 -3.24 H2 + H2O(g) -0.96 -0.00 0.96 H2O + H2S(g) -105.31 -106.54 -1.24 H2S + O2(g) -12.02 -15.08 -3.06 O2 + Sulfur -78.96 -74.58 4.38 S + +Reaction step 25. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.08 -4.62 -4.54 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.844e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.613e-02 1.556e-02 + S 1.613e-02 1.556e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.778 Charge balance + pe = 9.142 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.108e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 49.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070747e+02 + Total O = 5.359956e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.672e-07 3.002e-07 -6.435 -6.523 -0.087 + H+ 1.945e-07 1.666e-07 -6.711 -6.778 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.613e-02 + Ca+2 1.027e-02 4.956e-03 -1.988 -2.305 -0.317 + CaSO4 5.858e-03 5.914e-03 -2.232 -2.228 0.004 + CaHSO4+ 1.004e-08 8.288e-09 -7.998 -8.082 -0.083 + CaOH+ 5.978e-09 4.935e-09 -8.223 -8.307 -0.083 +H(0) 1.623e-35 + H2 8.115e-36 8.192e-36 -35.091 -35.087 0.004 +O(0) 1.812e-15 + O2 9.060e-16 9.146e-16 -15.043 -15.039 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -106.000 -106.087 -0.087 + H2S 0.000e+00 0.000e+00 -106.175 -106.171 0.004 + S-2 0.000e+00 0.000e+00 -111.243 -111.566 -0.323 +S(6) 1.613e-02 + SO4-2 1.027e-02 4.860e-03 -1.988 -2.313 -0.325 + CaSO4 5.858e-03 5.914e-03 -2.232 -2.228 0.004 + HSO4- 1.685e-07 1.391e-07 -6.773 -6.857 -0.083 + CaHSO4+ 1.004e-08 8.288e-09 -7.998 -8.082 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.08 -4.62 -4.54 CaSO4 + Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O + H2(g) -31.84 -35.09 -3.25 H2 + H2O(g) -0.94 -0.00 0.94 H2O + H2S(g) -104.92 -106.17 -1.25 H2S + O2(g) -11.98 -15.04 -3.06 O2 + Sulfur -78.69 -74.33 4.36 S + +Reaction step 26. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.07 -4.62 -4.55 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.611e-02 1.554e-02 + S 1.611e-02 1.554e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.768 Charge balance + pe = 9.071 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.098e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 50.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070746e+02 + Total O = 5.359947e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.805e-07 3.110e-07 -6.420 -6.507 -0.088 + H+ 1.992e-07 1.706e-07 -6.701 -6.768 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.611e-02 + Ca+2 1.025e-02 4.940e-03 -1.989 -2.306 -0.317 + CaSO4 5.867e-03 5.923e-03 -2.232 -2.227 0.004 + CaHSO4+ 1.048e-08 8.650e-09 -7.980 -8.063 -0.083 + CaOH+ 5.820e-09 4.804e-09 -8.235 -8.318 -0.083 +H(0) 2.343e-35 + H2 1.172e-35 1.183e-35 -34.931 -34.927 0.004 +O(0) 1.639e-15 + O2 8.196e-16 8.274e-16 -15.086 -15.082 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -105.464 -105.552 -0.088 + H2S 0.000e+00 0.000e+00 -105.636 -105.632 0.004 + S-2 0.000e+00 0.000e+00 -110.692 -111.015 -0.324 +S(6) 1.611e-02 + SO4-2 1.025e-02 4.845e-03 -1.989 -2.315 -0.325 + CaSO4 5.867e-03 5.923e-03 -2.232 -2.227 0.004 + HSO4- 1.765e-07 1.457e-07 -6.753 -6.837 -0.083 + CaHSO4+ 1.048e-08 8.650e-09 -7.980 -8.063 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.07 -4.62 -4.55 CaSO4 + Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O + H2(g) -31.68 -34.93 -3.25 H2 + H2O(g) -0.91 -0.00 0.91 H2O + H2S(g) -104.38 -105.63 -1.26 H2S + O2(g) -12.02 -15.08 -3.06 O2 + Sulfur -78.30 -73.96 4.34 S + +Reaction step 27. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.06 -4.62 -4.56 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.609e-02 1.552e-02 + S 1.609e-02 1.552e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.758 Charge balance + pe = 9.012 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.088e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 51.000 + Electrical balance (eq) = -1.081e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.070745e+02 + Total O = 5.359936e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.941e-07 3.221e-07 -6.404 -6.492 -0.088 + H+ 2.039e-07 1.746e-07 -6.691 -6.758 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.609e-02 + Ca+2 1.022e-02 4.923e-03 -1.991 -2.308 -0.317 + CaSO4 5.875e-03 5.930e-03 -2.231 -2.227 0.004 + CaHSO4+ 1.094e-08 9.025e-09 -7.961 -8.045 -0.083 + CaOH+ 5.668e-09 4.677e-09 -8.247 -8.330 -0.083 +H(0) 3.183e-35 + H2 1.592e-35 1.607e-35 -34.798 -34.794 0.004 +O(0) 1.669e-15 + O2 8.347e-16 8.426e-16 -15.078 -15.074 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -105.034 -105.122 -0.088 + H2S 0.000e+00 0.000e+00 -105.204 -105.200 0.004 + S-2 0.000e+00 0.000e+00 -110.247 -110.570 -0.324 +S(6) 1.609e-02 + SO4-2 1.022e-02 4.829e-03 -1.991 -2.316 -0.326 + CaSO4 5.875e-03 5.930e-03 -2.231 -2.227 0.004 + HSO4- 1.848e-07 1.525e-07 -6.733 -6.817 -0.083 + CaHSO4+ 1.094e-08 9.025e-09 -7.961 -8.045 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.06 -4.62 -4.56 CaSO4 + Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O + H2(g) -31.54 -34.79 -3.25 H2 + H2O(g) -0.89 -0.00 0.89 H2O + H2S(g) -103.93 -105.20 -1.27 H2S + O2(g) -12.01 -15.07 -3.07 O2 + Sulfur -77.98 -73.66 4.32 S + +Reaction step 28. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.05 -4.63 -4.58 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.63 -4.63 1.000e+00 1.984e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.607e-02 1.550e-02 + S 1.607e-02 1.550e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.748 Charge balance + pe = 8.953 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.077e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 52.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070744e+02 + Total O = 5.359924e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.081e-07 3.335e-07 -6.389 -6.477 -0.088 + H+ 2.087e-07 1.787e-07 -6.680 -6.748 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.607e-02 + Ca+2 1.019e-02 4.906e-03 -1.992 -2.309 -0.318 + CaSO4 5.881e-03 5.937e-03 -2.231 -2.226 0.004 + CaHSO4+ 1.141e-08 9.411e-09 -7.943 -8.026 -0.084 + CaOH+ 5.521e-09 4.555e-09 -8.258 -8.342 -0.084 +H(0) 4.352e-35 + H2 2.176e-35 2.196e-35 -34.662 -34.658 0.004 +O(0) 1.672e-15 + O2 8.358e-16 8.437e-16 -15.078 -15.074 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -104.592 -104.680 -0.088 + H2S 0.000e+00 0.000e+00 -104.759 -104.755 0.004 + S-2 0.000e+00 0.000e+00 -109.789 -110.114 -0.324 +S(6) 1.607e-02 + SO4-2 1.019e-02 4.813e-03 -1.992 -2.318 -0.326 + CaSO4 5.881e-03 5.937e-03 -2.231 -2.226 0.004 + HSO4- 1.934e-07 1.596e-07 -6.714 -6.797 -0.084 + CaHSO4+ 1.141e-08 9.411e-09 -7.943 -8.026 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.05 -4.63 -4.58 CaSO4 + Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O + H2(g) -31.40 -34.66 -3.26 H2 + H2O(g) -0.87 -0.00 0.87 H2O + H2S(g) -103.48 -104.76 -1.28 H2S + O2(g) -12.00 -15.07 -3.07 O2 + Sulfur -77.66 -73.35 4.30 S + +Reaction step 29. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.04 -4.63 -4.59 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.63 -4.63 1.000e+00 1.985e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.605e-02 1.548e-02 + S 1.605e-02 1.548e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.738 Charge balance + pe = 8.891 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.066e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 53.000 + Electrical balance (eq) = 1.076e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 24 + Total H = 1.070744e+02 + Total O = 5.359910e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.225e-07 3.452e-07 -6.374 -6.462 -0.088 + H+ 2.136e-07 1.828e-07 -6.670 -6.738 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.605e-02 + Ca+2 1.016e-02 4.889e-03 -1.993 -2.311 -0.318 + CaSO4 5.886e-03 5.942e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.189e-08 9.811e-09 -7.925 -8.008 -0.084 + CaOH+ 5.379e-09 4.437e-09 -8.269 -8.353 -0.084 +H(0) 5.999e-35 + H2 3.000e-35 3.028e-35 -34.523 -34.519 0.004 +O(0) 1.640e-15 + O2 8.200e-16 8.278e-16 -15.086 -15.082 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -104.136 -104.224 -0.088 + H2S 0.000e+00 0.000e+00 -104.300 -104.296 0.004 + S-2 0.000e+00 0.000e+00 -109.318 -109.642 -0.325 +S(6) 1.605e-02 + SO4-2 1.016e-02 4.796e-03 -1.993 -2.319 -0.326 + CaSO4 5.886e-03 5.942e-03 -2.230 -2.226 0.004 + HSO4- 2.024e-07 1.669e-07 -6.694 -6.778 -0.084 + CaHSO4+ 1.189e-08 9.811e-09 -7.925 -8.008 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.04 -4.63 -4.59 CaSO4 + Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O + H2(g) -31.26 -34.52 -3.26 H2 + H2O(g) -0.85 -0.00 0.85 H2O + H2S(g) -103.01 -104.30 -1.28 H2S + O2(g) -12.01 -15.08 -3.08 O2 + Sulfur -77.32 -73.04 4.28 S + +Reaction step 30. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.03 -4.63 -4.60 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.63 -4.63 1.000e+00 1.985e+00 9.845e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.602e-02 1.546e-02 + S 1.602e-02 1.546e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.728 Charge balance + pe = 8.834 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.054e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 54.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.070743e+02 + Total O = 5.359895e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.374e-07 3.573e-07 -6.359 -6.447 -0.088 + H+ 2.184e-07 1.869e-07 -6.661 -6.728 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.602e-02 + Ca+2 1.013e-02 4.871e-03 -1.994 -2.312 -0.318 + CaSO4 5.890e-03 5.945e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.240e-08 1.022e-08 -7.907 -7.990 -0.084 + CaOH+ 5.242e-09 4.323e-09 -8.280 -8.364 -0.084 +H(0) 8.078e-35 + H2 4.039e-35 4.077e-35 -34.394 -34.390 0.004 +O(0) 1.680e-15 + O2 8.401e-16 8.480e-16 -15.076 -15.072 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -103.720 -103.807 -0.088 + H2S 0.000e+00 0.000e+00 -103.881 -103.877 0.004 + S-2 0.000e+00 0.000e+00 -108.886 -109.211 -0.325 +S(6) 1.602e-02 + SO4-2 1.013e-02 4.779e-03 -1.994 -2.321 -0.327 + CaSO4 5.890e-03 5.945e-03 -2.230 -2.226 0.004 + HSO4- 2.117e-07 1.746e-07 -6.674 -6.758 -0.084 + CaHSO4+ 1.240e-08 1.022e-08 -7.907 -7.990 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.03 -4.63 -4.60 CaSO4 + Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O + H2(g) -31.13 -34.39 -3.26 H2 + H2O(g) -0.83 -0.00 0.83 H2O + H2S(g) -102.58 -103.88 -1.29 H2S + O2(g) -11.99 -15.07 -3.08 O2 + Sulfur -77.02 -72.75 4.26 S + +Reaction step 31. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.03 -4.64 -4.61 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.600e-02 1.543e-02 + S 1.600e-02 1.543e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.719 Charge balance + pe = 8.773 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.042e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 55.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.070741e+02 + Total O = 5.359879e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.526e-07 3.697e-07 -6.344 -6.432 -0.088 + H+ 2.233e-07 1.911e-07 -6.651 -6.719 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.600e-02 + Ca+2 1.010e-02 4.853e-03 -1.995 -2.314 -0.318 + CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.292e-08 1.065e-08 -7.889 -7.973 -0.084 + CaOH+ 5.110e-09 4.213e-09 -8.292 -8.375 -0.084 +H(0) 1.113e-34 + H2 5.565e-35 5.617e-35 -34.255 -34.250 0.004 +O(0) 1.638e-15 + O2 8.188e-16 8.264e-16 -15.087 -15.083 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -103.263 -103.351 -0.088 + H2S 0.000e+00 0.000e+00 -103.421 -103.417 0.004 + S-2 0.000e+00 0.000e+00 -108.414 -108.739 -0.325 +S(6) 1.600e-02 + SO4-2 1.010e-02 4.761e-03 -1.995 -2.322 -0.327 + CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 + HSO4- 2.214e-07 1.825e-07 -6.655 -6.739 -0.084 + CaHSO4+ 1.292e-08 1.065e-08 -7.889 -7.973 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.03 -4.64 -4.61 CaSO4 + Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O + H2(g) -30.98 -34.25 -3.27 H2 + H2O(g) -0.81 -0.00 0.80 H2O + H2S(g) -102.11 -103.42 -1.30 H2S + O2(g) -12.00 -15.08 -3.08 O2 + Sulfur -76.68 -72.43 4.25 S + +Reaction step 32. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.02 -4.64 -4.62 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.597e-02 1.540e-02 + S 1.597e-02 1.540e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.709 Charge balance + pe = 8.716 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.029e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 56.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 20 + Total H = 1.070740e+02 + Total O = 5.359861e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.683e-07 3.824e-07 -6.330 -6.417 -0.088 + H+ 2.283e-07 1.953e-07 -6.642 -6.709 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.597e-02 + Ca+2 1.007e-02 4.835e-03 -1.997 -2.316 -0.319 + CaSO4 5.893e-03 5.948e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.345e-08 1.109e-08 -7.871 -7.955 -0.084 + CaOH+ 4.982e-09 4.106e-09 -8.303 -8.387 -0.084 +H(0) 1.497e-34 + H2 7.485e-35 7.554e-35 -34.126 -34.122 0.004 +O(0) 1.669e-15 + O2 8.344e-16 8.422e-16 -15.079 -15.075 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -102.848 -102.936 -0.088 + H2S 0.000e+00 0.000e+00 -103.003 -102.999 0.004 + S-2 0.000e+00 0.000e+00 -107.984 -108.309 -0.325 +S(6) 1.597e-02 + SO4-2 1.007e-02 4.743e-03 -1.997 -2.324 -0.327 + CaSO4 5.893e-03 5.948e-03 -2.230 -2.226 0.004 + HSO4- 2.314e-07 1.907e-07 -6.636 -6.720 -0.084 + CaHSO4+ 1.345e-08 1.109e-08 -7.871 -7.955 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.02 -4.64 -4.62 CaSO4 + Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O + H2(g) -30.85 -34.12 -3.27 H2 + H2O(g) -0.78 -0.00 0.78 H2O + H2S(g) -101.69 -103.00 -1.31 H2S + O2(g) -11.99 -15.07 -3.09 O2 + Sulfur -76.38 -72.15 4.23 S + +Reaction step 33. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite -0.01 -4.64 -4.63 1.000e+00 -1.000e+00 + Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.593e-02 1.537e-02 + S 1.593e-02 1.537e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.700 Charge balance + pe = 8.659 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.016e-02 + Mass of water (kg) = 9.645e-01 + Total alkalinity (eq/kg) = 1.122e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 57.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 23 + Total H = 1.070739e+02 + Total O = 5.359842e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.844e-07 3.955e-07 -6.315 -6.403 -0.088 + H+ 2.333e-07 1.995e-07 -6.632 -6.700 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.593e-02 + Ca+2 1.004e-02 4.816e-03 -1.998 -2.317 -0.319 + CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.400e-08 1.154e-08 -7.854 -7.938 -0.084 + CaOH+ 4.858e-09 4.004e-09 -8.314 -8.398 -0.084 +H(0) 2.017e-34 + H2 1.009e-34 1.018e-34 -33.996 -33.992 0.004 +O(0) 1.688e-15 + O2 8.441e-16 8.519e-16 -15.074 -15.070 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -102.429 -102.517 -0.088 + H2S 0.000e+00 0.000e+00 -102.581 -102.577 0.004 + S-2 0.000e+00 0.000e+00 -107.549 -107.875 -0.326 +S(6) 1.593e-02 + SO4-2 1.004e-02 4.725e-03 -1.998 -2.326 -0.327 + CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 + HSO4- 2.418e-07 1.993e-07 -6.616 -6.700 -0.084 + CaHSO4+ 1.400e-08 1.154e-08 -7.854 -7.938 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.01 -4.64 -4.63 CaSO4 + Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O + H2(g) -30.72 -33.99 -3.27 H2 + H2O(g) -0.76 -0.00 0.76 H2O + H2S(g) -101.26 -102.58 -1.32 H2S + O2(g) -11.98 -15.07 -3.09 O2 + Sulfur -76.07 -71.86 4.21 S + +Reaction step 34. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.65 -4.65 1.000e+00 1.984e+00 9.835e-01 + Gypsum -0.00 -4.65 -4.65 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.588e-02 1.646e-02 + S 1.588e-02 1.646e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.691 Charge balance + pe = 8.590 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.000e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 58.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.150124e+02 + Total O = 5.757204e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.008e-07 4.089e-07 -6.300 -6.388 -0.088 + H+ 2.383e-07 2.038e-07 -6.623 -6.691 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.588e-02 + Ca+2 1.000e-02 4.794e-03 -2.000 -2.319 -0.319 + CaSO4 5.884e-03 5.939e-03 -2.230 -2.226 0.004 + CaHSO4+ 1.456e-08 1.200e-08 -7.837 -7.921 -0.084 + CaOH+ 4.735e-09 3.902e-09 -8.325 -8.409 -0.084 +H(0) 2.861e-34 + H2 1.431e-34 1.444e-34 -33.844 -33.840 0.004 +O(0) 1.535e-15 + O2 7.677e-16 7.749e-16 -15.115 -15.111 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -101.920 -102.008 -0.088 + H2S 0.000e+00 0.000e+00 -102.070 -102.066 0.004 + S-2 0.000e+00 0.000e+00 -107.026 -107.352 -0.326 +S(6) 1.588e-02 + SO4-2 9.999e-03 4.704e-03 -2.000 -2.328 -0.327 + CaSO4 5.884e-03 5.939e-03 -2.230 -2.226 0.004 + HSO4- 2.526e-07 2.081e-07 -6.598 -6.682 -0.084 + CaHSO4+ 1.456e-08 1.200e-08 -7.837 -7.921 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.65 -4.65 CaSO4 + Gypsum -0.00 -4.65 -4.65 CaSO4:2H2O + H2(g) -30.56 -33.84 -3.28 H2 + H2O(g) -0.74 -0.00 0.74 H2O + H2S(g) -100.74 -102.07 -1.33 H2S + O2(g) -12.02 -15.11 -3.09 O2 + Sulfur -75.69 -71.50 4.19 S + +Reaction step 35. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.66 -4.66 1.000e+00 1.984e+00 9.839e-01 + Gypsum -0.01 -4.66 -4.65 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.558e-02 1.614e-02 + S 1.558e-02 1.614e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.681 Charge balance + pe = 8.533 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.929e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 59.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.757079e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.158e-07 4.215e-07 -6.288 -6.375 -0.088 + H+ 2.438e-07 2.087e-07 -6.613 -6.681 -0.068 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.558e-02 + Ca+2 9.822e-03 4.724e-03 -2.008 -2.326 -0.318 + CaSO4 5.760e-03 5.812e-03 -2.240 -2.236 0.004 + CaHSO4+ 1.485e-08 1.225e-08 -7.828 -7.912 -0.084 + CaOH+ 4.554e-09 3.756e-09 -8.342 -8.425 -0.084 +H(0) 3.871e-34 + H2 1.935e-34 1.953e-34 -33.713 -33.709 0.004 +O(0) 1.530e-15 + O2 7.652e-16 7.721e-16 -15.116 -15.112 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -101.498 -101.585 -0.088 + H2S 0.000e+00 0.000e+00 -101.643 -101.639 0.004 + S-2 0.000e+00 0.000e+00 -106.590 -106.915 -0.324 +S(6) 1.558e-02 + SO4-2 9.822e-03 4.637e-03 -2.008 -2.334 -0.326 + CaSO4 5.760e-03 5.812e-03 -2.240 -2.236 0.004 + HSO4- 2.615e-07 2.157e-07 -6.582 -6.666 -0.084 + CaHSO4+ 1.485e-08 1.225e-08 -7.828 -7.912 -0.084 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.66 -4.66 CaSO4 + Gypsum -0.01 -4.66 -4.65 CaSO4:2H2O + H2(g) -30.43 -33.71 -3.28 H2 + H2O(g) -0.72 -0.00 0.72 H2O + H2S(g) -100.30 -101.64 -1.34 H2S + O2(g) -12.01 -15.11 -3.10 O2 + Sulfur -75.38 -71.21 4.17 S + +Reaction step 36. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.67 -4.67 1.000e+00 1.984e+00 9.842e-01 + Gypsum -0.02 -4.67 -4.65 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.528e-02 1.583e-02 + S 1.528e-02 1.583e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.670 Charge balance + pe = 8.477 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.858e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 60.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756954e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.310e-07 4.344e-07 -6.275 -6.362 -0.087 + H+ 2.494e-07 2.136e-07 -6.603 -6.670 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.528e-02 + Ca+2 9.645e-03 4.654e-03 -2.016 -2.332 -0.316 + CaSO4 5.636e-03 5.686e-03 -2.249 -2.245 0.004 + CaHSO4+ 1.515e-08 1.250e-08 -7.820 -7.903 -0.083 + CaOH+ 4.379e-09 3.615e-09 -8.359 -8.442 -0.083 +H(0) 5.203e-34 + H2 2.602e-34 2.625e-34 -33.585 -33.581 0.004 +O(0) 1.539e-15 + O2 7.696e-16 7.765e-16 -15.114 -15.110 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -101.086 -101.173 -0.087 + H2S 0.000e+00 0.000e+00 -101.226 -101.222 0.004 + S-2 0.000e+00 0.000e+00 -106.166 -106.489 -0.323 +S(6) 1.528e-02 + SO4-2 9.644e-03 4.570e-03 -2.016 -2.340 -0.324 + CaSO4 5.636e-03 5.686e-03 -2.249 -2.245 0.004 + HSO4- 2.707e-07 2.234e-07 -6.568 -6.651 -0.083 + CaHSO4+ 1.515e-08 1.250e-08 -7.820 -7.903 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.67 -4.67 CaSO4 + Gypsum -0.02 -4.67 -4.65 CaSO4:2H2O + H2(g) -30.30 -33.58 -3.29 H2 + H2O(g) -0.70 -0.00 0.70 H2O + H2S(g) -99.87 -101.22 -1.35 H2S + O2(g) -12.01 -15.11 -3.10 O2 + Sulfur -75.08 -70.93 4.15 S + +Reaction step 37. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.69 -4.69 1.000e+00 1.984e+00 9.845e-01 + Gypsum -0.03 -4.69 -4.66 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.498e-02 1.552e-02 + S 1.498e-02 1.552e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.660 Charge balance + pe = 8.422 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.787e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 61.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756829e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.465e-07 4.476e-07 -6.262 -6.349 -0.087 + H+ 2.551e-07 2.186e-07 -6.593 -6.660 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.498e-02 + Ca+2 9.468e-03 4.584e-03 -2.024 -2.339 -0.315 + CaSO4 5.511e-03 5.559e-03 -2.259 -2.255 0.004 + CaHSO4+ 1.544e-08 1.275e-08 -7.811 -7.894 -0.083 + CaOH+ 4.211e-09 3.479e-09 -8.376 -8.459 -0.083 +H(0) 6.963e-34 + H2 3.482e-34 3.512e-34 -33.458 -33.454 0.004 +O(0) 1.557e-15 + O2 7.783e-16 7.851e-16 -15.109 -15.105 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -100.681 -100.768 -0.087 + H2S 0.000e+00 0.000e+00 -100.816 -100.812 0.004 + S-2 0.000e+00 0.000e+00 -105.748 -106.070 -0.321 +S(6) 1.498e-02 + SO4-2 9.467e-03 4.503e-03 -2.024 -2.347 -0.323 + CaSO4 5.511e-03 5.559e-03 -2.259 -2.255 0.004 + HSO4- 2.801e-07 2.314e-07 -6.553 -6.636 -0.083 + CaHSO4+ 1.544e-08 1.275e-08 -7.811 -7.894 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.69 -4.69 CaSO4 + Gypsum -0.03 -4.69 -4.66 CaSO4:2H2O + H2(g) -30.17 -33.45 -3.29 H2 + H2O(g) -0.68 -0.00 0.68 H2O + H2S(g) -99.45 -100.81 -1.36 H2S + O2(g) -12.00 -15.11 -3.11 O2 + Sulfur -74.78 -70.65 4.13 S + +Reaction step 38. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.70 -4.70 1.000e+00 1.985e+00 9.848e-01 + Gypsum -0.04 -4.70 -4.66 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.468e-02 1.521e-02 + S 1.468e-02 1.521e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.650 Charge balance + pe = 8.365 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.717e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 62.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756704e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.623e-07 4.611e-07 -6.250 -6.336 -0.086 + H+ 2.608e-07 2.236e-07 -6.584 -6.650 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.468e-02 + Ca+2 9.291e-03 4.514e-03 -2.032 -2.345 -0.314 + CaSO4 5.386e-03 5.433e-03 -2.269 -2.265 0.004 + CaHSO4+ 1.572e-08 1.300e-08 -7.803 -7.886 -0.083 + CaOH+ 4.049e-09 3.349e-09 -8.393 -8.475 -0.083 +H(0) 9.437e-34 + H2 4.719e-34 4.759e-34 -33.326 -33.322 0.004 +O(0) 1.529e-15 + O2 7.646e-16 7.712e-16 -15.117 -15.113 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -100.254 -100.340 -0.086 + H2S 0.000e+00 0.000e+00 -100.384 -100.380 0.004 + S-2 0.000e+00 0.000e+00 -105.309 -105.628 -0.320 +S(6) 1.468e-02 + SO4-2 9.291e-03 4.435e-03 -2.032 -2.353 -0.321 + CaSO4 5.386e-03 5.433e-03 -2.269 -2.265 0.004 + HSO4- 2.897e-07 2.396e-07 -6.538 -6.621 -0.083 + CaHSO4+ 1.572e-08 1.300e-08 -7.803 -7.886 -0.083 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.70 -4.70 CaSO4 + Gypsum -0.04 -4.70 -4.66 CaSO4:2H2O + H2(g) -30.03 -33.32 -3.29 H2 + H2O(g) -0.66 -0.00 0.66 H2O + H2S(g) -99.01 -100.38 -1.37 H2S + O2(g) -12.00 -15.11 -3.11 O2 + Sulfur -74.46 -70.35 4.11 S + +Reaction step 39. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.71 -4.71 1.000e+00 1.985e+00 9.851e-01 + Gypsum -0.05 -4.71 -4.67 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.438e-02 1.490e-02 + S 1.438e-02 1.490e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.641 Charge balance + pe = 8.221 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.646e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 63.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756580e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.784e-07 4.748e-07 -6.238 -6.324 -0.086 + H+ 2.666e-07 2.287e-07 -6.574 -6.641 -0.067 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.438e-02 + Ca+2 9.116e-03 4.444e-03 -2.040 -2.352 -0.312 + CaSO4 5.262e-03 5.307e-03 -2.279 -2.275 0.004 + CaHSO4+ 1.600e-08 1.325e-08 -7.796 -7.878 -0.082 + CaOH+ 3.894e-09 3.223e-09 -8.410 -8.492 -0.082 +H(0) 1.894e-33 + H2 9.471e-34 9.551e-34 -33.024 -33.020 0.004 +O(0) 6.826e-16 + O2 3.413e-16 3.442e-16 -15.467 -15.463 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -99.144 -99.230 -0.086 + H2S 0.000e+00 0.000e+00 -99.269 -99.265 0.004 + S-2 0.000e+00 0.000e+00 -104.186 -104.504 -0.318 +S(6) 1.438e-02 + SO4-2 9.115e-03 4.368e-03 -2.040 -2.360 -0.319 + CaSO4 5.262e-03 5.307e-03 -2.279 -2.275 0.004 + HSO4- 2.995e-07 2.479e-07 -6.524 -6.606 -0.082 + CaHSO4+ 1.600e-08 1.325e-08 -7.796 -7.878 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.71 -4.71 CaSO4 + Gypsum -0.05 -4.71 -4.67 CaSO4:2H2O + H2(g) -29.72 -33.02 -3.30 H2 + H2O(g) -0.64 -0.00 0.64 H2O + H2S(g) -97.89 -99.27 -1.38 H2S + O2(g) -12.35 -15.46 -3.11 O2 + Sulfur -73.64 -69.54 4.09 S + +Reaction step 40. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.73 -4.73 1.000e+00 1.985e+00 9.854e-01 + Gypsum -0.06 -4.73 -4.67 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.408e-02 1.459e-02 + S 1.408e-02 1.459e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.631 Charge balance + pe = 8.254 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.576e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 64.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756456e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.948e-07 4.888e-07 -6.226 -6.311 -0.085 + H+ 2.725e-07 2.339e-07 -6.565 -6.631 -0.066 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.408e-02 + Ca+2 8.941e-03 4.374e-03 -2.049 -2.359 -0.310 + CaSO4 5.138e-03 5.181e-03 -2.289 -2.286 0.004 + CaHSO4+ 1.628e-08 1.349e-08 -7.788 -7.870 -0.082 + CaOH+ 3.744e-09 3.102e-09 -8.427 -8.508 -0.082 +H(0) 1.693e-33 + H2 8.466e-34 8.536e-34 -33.072 -33.069 0.004 +O(0) 1.531e-15 + O2 7.655e-16 7.718e-16 -15.116 -15.112 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -99.439 -99.524 -0.085 + H2S 0.000e+00 0.000e+00 -99.559 -99.555 0.004 + S-2 0.000e+00 0.000e+00 -104.469 -104.785 -0.316 +S(6) 1.408e-02 + SO4-2 8.941e-03 4.301e-03 -2.049 -2.366 -0.318 + CaSO4 5.138e-03 5.181e-03 -2.289 -2.286 0.004 + HSO4- 3.096e-07 2.565e-07 -6.509 -6.591 -0.082 + CaHSO4+ 1.628e-08 1.349e-08 -7.788 -7.870 -0.082 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.73 -4.73 CaSO4 + Gypsum -0.06 -4.73 -4.67 CaSO4:2H2O + H2(g) -29.77 -33.07 -3.30 H2 + H2O(g) -0.62 -0.00 0.62 H2O + H2S(g) -98.17 -99.56 -1.38 H2S + O2(g) -12.00 -15.11 -3.12 O2 + Sulfur -73.86 -69.79 4.08 S + +Reaction step 41. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.74 -4.74 1.000e+00 1.986e+00 9.857e-01 + Gypsum -0.07 -4.74 -4.67 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.378e-02 1.428e-02 + S 1.378e-02 1.428e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.621 Charge balance + pe = 8.199 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.507e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 65.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756333e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.114e-07 5.030e-07 -6.214 -6.298 -0.085 + H+ 2.785e-07 2.392e-07 -6.555 -6.621 -0.066 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.378e-02 + Ca+2 8.767e-03 4.305e-03 -2.057 -2.366 -0.309 + CaSO4 5.015e-03 5.056e-03 -2.300 -2.296 0.004 + CaHSO4+ 1.656e-08 1.373e-08 -7.781 -7.862 -0.081 + CaOH+ 3.600e-09 2.986e-09 -8.444 -8.525 -0.081 +H(0) 2.266e-33 + H2 1.133e-33 1.142e-33 -32.946 -32.942 0.004 +O(0) 1.527e-15 + O2 7.634e-16 7.696e-16 -15.117 -15.114 0.004 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -99.033 -99.117 -0.085 + H2S 0.000e+00 0.000e+00 -99.147 -99.144 0.004 + S-2 0.000e+00 0.000e+00 -104.050 -104.365 -0.315 +S(6) 1.378e-02 + SO4-2 8.767e-03 4.234e-03 -2.057 -2.373 -0.316 + CaSO4 5.015e-03 5.056e-03 -2.300 -2.296 0.004 + HSO4- 3.199e-07 2.653e-07 -6.495 -6.576 -0.081 + CaHSO4+ 1.656e-08 1.373e-08 -7.781 -7.862 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.74 -4.74 CaSO4 + Gypsum -0.07 -4.74 -4.67 CaSO4:2H2O + H2(g) -29.64 -32.94 -3.30 H2 + H2O(g) -0.60 -0.00 0.60 H2O + H2S(g) -97.75 -99.14 -1.39 H2S + O2(g) -11.99 -15.11 -3.12 O2 + Sulfur -73.56 -69.50 4.06 S + +Reaction step 42. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.75 -4.75 1.000e+00 1.986e+00 9.860e-01 + Gypsum -0.08 -4.75 -4.68 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.349e-02 1.397e-02 + S 1.349e-02 1.397e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.612 Charge balance + pe = 8.055 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.438e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 66.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.756211e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.283e-07 5.176e-07 -6.202 -6.286 -0.084 + H+ 2.845e-07 2.445e-07 -6.546 -6.612 -0.066 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.349e-02 + Ca+2 8.594e-03 4.236e-03 -2.066 -2.373 -0.307 + CaSO4 4.893e-03 4.931e-03 -2.310 -2.307 0.003 + CaHSO4+ 1.683e-08 1.397e-08 -7.774 -7.855 -0.081 + CaOH+ 3.462e-09 2.874e-09 -8.461 -8.541 -0.081 +H(0) 4.558e-33 + H2 2.279e-33 2.297e-33 -32.642 -32.639 0.003 +O(0) 6.716e-16 + O2 3.358e-16 3.384e-16 -15.474 -15.471 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -97.918 -98.002 -0.084 + H2S 0.000e+00 0.000e+00 -98.027 -98.024 0.003 + S-2 0.000e+00 0.000e+00 -102.923 -103.236 -0.313 +S(6) 1.349e-02 + SO4-2 8.594e-03 4.167e-03 -2.066 -2.380 -0.314 + CaSO4 4.893e-03 4.931e-03 -2.310 -2.307 0.003 + HSO4- 3.304e-07 2.743e-07 -6.481 -6.562 -0.081 + CaHSO4+ 1.683e-08 1.397e-08 -7.774 -7.855 -0.081 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.75 -4.75 CaSO4 + Gypsum -0.08 -4.75 -4.68 CaSO4:2H2O + H2(g) -29.33 -32.64 -3.31 H2 + H2O(g) -0.58 -0.00 0.58 H2O + H2S(g) -96.62 -98.02 -1.40 H2S + O2(g) -12.35 -15.47 -3.12 O2 + Sulfur -72.73 -68.69 4.04 S + +Reaction step 43. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.77 -4.77 1.000e+00 1.986e+00 9.863e-01 + Gypsum -0.09 -4.77 -4.68 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.319e-02 1.367e-02 + S 1.319e-02 1.367e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.602 Charge balance + pe = 8.092 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.369e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 67.000 + Electrical balance (eq) = -1.080e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.756089e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.456e-07 5.324e-07 -6.190 -6.274 -0.084 + H+ 2.905e-07 2.499e-07 -6.537 -6.602 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.319e-02 + Ca+2 8.423e-03 4.167e-03 -2.075 -2.380 -0.306 + CaSO4 4.771e-03 4.808e-03 -2.321 -2.318 0.003 + CaHSO4+ 1.709e-08 1.420e-08 -7.767 -7.848 -0.080 + CaOH+ 3.329e-09 2.766e-09 -8.478 -8.558 -0.080 +H(0) 3.979e-33 + H2 1.990e-33 2.005e-33 -32.701 -32.698 0.003 +O(0) 1.562e-15 + O2 7.812e-16 7.873e-16 -15.107 -15.104 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -98.253 -98.336 -0.084 + H2S 0.000e+00 0.000e+00 -98.356 -98.353 0.003 + S-2 0.000e+00 0.000e+00 -103.246 -103.557 -0.311 +S(6) 1.319e-02 + SO4-2 8.422e-03 4.101e-03 -2.075 -2.387 -0.313 + CaSO4 4.771e-03 4.808e-03 -2.321 -2.318 0.003 + HSO4- 3.412e-07 2.835e-07 -6.467 -6.547 -0.080 + CaHSO4+ 1.709e-08 1.420e-08 -7.767 -7.848 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.77 -4.77 CaSO4 + Gypsum -0.09 -4.77 -4.68 CaSO4:2H2O + H2(g) -29.39 -32.70 -3.31 H2 + H2O(g) -0.56 -0.00 0.56 H2O + H2S(g) -96.94 -98.35 -1.41 H2S + O2(g) -11.98 -15.10 -3.13 O2 + Sulfur -72.99 -68.96 4.02 S + +Reaction step 44. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.78 -4.78 1.000e+00 1.987e+00 9.866e-01 + Gypsum -0.10 -4.78 -4.69 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.290e-02 1.337e-02 + S 1.290e-02 1.337e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.593 Charge balance + pe = 8.038 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.301e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 68.000 + Electrical balance (eq) = -1.073e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.755969e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.631e-07 5.475e-07 -6.178 -6.262 -0.083 + H+ 2.966e-07 2.553e-07 -6.528 -6.593 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.290e-02 + Ca+2 8.252e-03 4.098e-03 -2.083 -2.387 -0.304 + CaSO4 4.650e-03 4.685e-03 -2.333 -2.329 0.003 + CaHSO4+ 1.735e-08 1.443e-08 -7.761 -7.841 -0.080 + CaOH+ 3.201e-09 2.663e-09 -8.495 -8.575 -0.080 +H(0) 5.280e-33 + H2 2.640e-33 2.660e-33 -32.578 -32.575 0.003 +O(0) 1.569e-15 + O2 7.846e-16 7.906e-16 -15.105 -15.102 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -97.860 -97.943 -0.083 + H2S 0.000e+00 0.000e+00 -97.958 -97.955 0.003 + S-2 0.000e+00 0.000e+00 -102.841 -103.150 -0.309 +S(6) 1.290e-02 + SO4-2 8.252e-03 4.034e-03 -2.083 -2.394 -0.311 + CaSO4 4.650e-03 4.685e-03 -2.333 -2.329 0.003 + HSO4- 3.522e-07 2.929e-07 -6.453 -6.533 -0.080 + CaHSO4+ 1.735e-08 1.443e-08 -7.761 -7.841 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.78 -4.78 CaSO4 + Gypsum -0.10 -4.78 -4.69 CaSO4:2H2O + H2(g) -29.26 -32.58 -3.31 H2 + H2O(g) -0.54 -0.00 0.54 H2O + H2S(g) -96.54 -97.95 -1.42 H2S + O2(g) -11.97 -15.10 -3.13 O2 + Sulfur -72.70 -68.69 4.00 S + +Reaction step 45. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.80 -4.80 1.000e+00 1.987e+00 9.869e-01 + Gypsum -0.11 -4.80 -4.69 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.261e-02 1.307e-02 + S 1.261e-02 1.307e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.584 Charge balance + pe = 7.985 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.233e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 69.000 + Electrical balance (eq) = -1.068e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.755849e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.808e-07 5.628e-07 -6.167 -6.250 -0.083 + H+ 3.028e-07 2.608e-07 -6.519 -6.584 -0.065 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +Ca 1.261e-02 + Ca+2 8.083e-03 4.029e-03 -2.092 -2.395 -0.302 + CaSO4 4.530e-03 4.564e-03 -2.344 -2.341 0.003 + CaHSO4+ 1.760e-08 1.466e-08 -7.754 -7.834 -0.080 + CaOH+ 3.078e-09 2.563e-09 -8.512 -8.591 -0.080 +H(0) 6.996e-33 + H2 3.498e-33 3.524e-33 -32.456 -32.453 0.003 +O(0) 1.575e-15 + O2 7.874e-16 7.932e-16 -15.104 -15.101 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -97.469 -97.552 -0.083 + H2S 0.000e+00 0.000e+00 -97.562 -97.558 0.003 + S-2 0.000e+00 0.000e+00 -102.438 -102.746 -0.308 +S(6) 1.261e-02 + SO4-2 8.083e-03 3.968e-03 -2.092 -2.401 -0.309 + CaSO4 4.530e-03 4.564e-03 -2.344 -2.341 0.003 + HSO4- 3.634e-07 3.026e-07 -6.440 -6.519 -0.080 + CaHSO4+ 1.760e-08 1.466e-08 -7.754 -7.834 -0.080 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.80 -4.80 CaSO4 + Gypsum -0.11 -4.80 -4.69 CaSO4:2H2O + H2(g) -29.14 -32.45 -3.32 H2 + H2O(g) -0.52 -0.00 0.52 H2O + H2S(g) -96.13 -97.56 -1.43 H2S + O2(g) -11.97 -15.10 -3.13 O2 + Sulfur -72.41 -68.42 3.99 S + +Reaction step 46. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.81 -4.81 1.000e+00 1.987e+00 9.872e-01 + Gypsum -0.12 -4.81 -4.69 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.233e-02 1.277e-02 + S 1.233e-02 1.277e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.574 Charge balance + pe = 7.930 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.166e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 70.000 + Electrical balance (eq) = -1.062e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.755730e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.989e-07 5.785e-07 -6.156 -6.238 -0.082 + H+ 3.091e-07 2.664e-07 -6.510 -6.574 -0.065 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.233e-02 + Ca+2 7.916e-03 3.961e-03 -2.101 -2.402 -0.301 + CaSO4 4.411e-03 4.444e-03 -2.355 -2.352 0.003 + CaHSO4+ 1.785e-08 1.488e-08 -7.748 -7.827 -0.079 + CaOH+ 2.959e-09 2.467e-09 -8.529 -8.608 -0.079 +H(0) 9.312e-33 + H2 4.656e-33 4.690e-33 -32.332 -32.329 0.003 +O(0) 1.561e-15 + O2 7.805e-16 7.862e-16 -15.108 -15.104 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -97.070 -97.152 -0.082 + H2S 0.000e+00 0.000e+00 -97.157 -97.154 0.003 + S-2 0.000e+00 0.000e+00 -102.027 -102.333 -0.306 +S(6) 1.233e-02 + SO4-2 7.916e-03 3.902e-03 -2.102 -2.409 -0.307 + CaSO4 4.411e-03 4.444e-03 -2.355 -2.352 0.003 + HSO4- 3.748e-07 3.125e-07 -6.426 -6.505 -0.079 + CaHSO4+ 1.785e-08 1.488e-08 -7.748 -7.827 -0.079 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.81 -4.81 CaSO4 + Gypsum -0.12 -4.81 -4.69 CaSO4:2H2O + H2(g) -29.01 -32.33 -3.32 H2 + H2O(g) -0.50 -0.00 0.50 H2O + H2S(g) -95.72 -97.15 -1.44 H2S + O2(g) -11.97 -15.10 -3.14 O2 + Sulfur -72.11 -68.14 3.97 S + +Reaction step 47. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.83 -4.83 1.000e+00 1.988e+00 9.875e-01 + Gypsum -0.13 -4.83 -4.70 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.204e-02 1.248e-02 + S 1.204e-02 1.248e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.565 Charge balance + pe = 7.877 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.100e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 71.000 + Electrical balance (eq) = -1.058e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.755613e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.173e-07 5.944e-07 -6.144 -6.226 -0.082 + H+ 3.154e-07 2.720e-07 -6.501 -6.565 -0.064 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.204e-02 + Ca+2 7.750e-03 3.893e-03 -2.111 -2.410 -0.299 + CaSO4 4.294e-03 4.325e-03 -2.367 -2.364 0.003 + CaHSO4+ 1.809e-08 1.510e-08 -7.742 -7.821 -0.079 + CaOH+ 2.846e-09 2.375e-09 -8.546 -8.624 -0.079 +H(0) 1.231e-32 + H2 6.154e-33 6.198e-33 -32.211 -32.208 0.003 +O(0) 1.564e-15 + O2 7.818e-16 7.874e-16 -15.107 -15.104 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -96.683 -96.764 -0.082 + H2S 0.000e+00 0.000e+00 -96.764 -96.761 0.003 + S-2 0.000e+00 0.000e+00 -101.628 -101.932 -0.304 +S(6) 1.204e-02 + SO4-2 7.750e-03 3.837e-03 -2.111 -2.416 -0.305 + CaSO4 4.294e-03 4.325e-03 -2.367 -2.364 0.003 + HSO4- 3.865e-07 3.225e-07 -6.413 -6.491 -0.079 + CaHSO4+ 1.809e-08 1.510e-08 -7.742 -7.821 -0.079 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.83 -4.83 CaSO4 + Gypsum -0.13 -4.83 -4.70 CaSO4:2H2O + H2(g) -28.89 -32.21 -3.32 H2 + H2O(g) -0.48 -0.00 0.48 H2O + H2S(g) -95.32 -96.76 -1.44 H2S + O2(g) -11.96 -15.10 -3.14 O2 + Sulfur -71.83 -67.88 3.95 S + +Reaction step 48. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.84 -4.84 1.000e+00 1.988e+00 9.878e-01 + Gypsum -0.14 -4.84 -4.70 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.176e-02 1.219e-02 + S 1.176e-02 1.219e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.556 Charge balance + pe = 7.824 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.034e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 72.000 + Electrical balance (eq) = -1.056e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.150124e+02 + Total O = 5.755497e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.359e-07 6.106e-07 -6.133 -6.214 -0.081 + H+ 3.218e-07 2.777e-07 -6.492 -6.556 -0.064 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.176e-02 + Ca+2 7.586e-03 3.826e-03 -2.120 -2.417 -0.297 + CaSO4 4.178e-03 4.207e-03 -2.379 -2.376 0.003 + CaHSO4+ 1.833e-08 1.531e-08 -7.737 -7.815 -0.078 + CaOH+ 2.736e-09 2.286e-09 -8.563 -8.641 -0.078 +H(0) 1.624e-32 + H2 8.122e-33 8.179e-33 -32.090 -32.087 0.003 +O(0) 1.566e-15 + O2 7.832e-16 7.887e-16 -15.106 -15.103 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -96.298 -96.379 -0.081 + H2S 0.000e+00 0.000e+00 -96.373 -96.370 0.003 + S-2 0.000e+00 0.000e+00 -101.231 -101.533 -0.302 +S(6) 1.176e-02 + SO4-2 7.585e-03 3.772e-03 -2.120 -2.423 -0.303 + CaSO4 4.178e-03 4.207e-03 -2.379 -2.376 0.003 + HSO4- 3.984e-07 3.328e-07 -6.400 -6.478 -0.078 + CaHSO4+ 1.833e-08 1.531e-08 -7.737 -7.815 -0.078 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.84 -4.84 CaSO4 + Gypsum -0.14 -4.84 -4.70 CaSO4:2H2O + H2(g) -28.76 -32.09 -3.33 H2 + H2O(g) -0.46 -0.00 0.46 H2O + H2S(g) -94.92 -96.37 -1.45 H2S + O2(g) -11.96 -15.10 -3.14 O2 + Sulfur -71.54 -67.61 3.93 S + +Reaction step 49. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.86 -4.86 1.000e+00 1.988e+00 9.881e-01 + Gypsum -0.15 -4.86 -4.71 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.149e-02 1.190e-02 + S 1.149e-02 1.190e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.547 Charge balance + pe = 7.769 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.969e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 73.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.755382e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.548e-07 6.271e-07 -6.122 -6.203 -0.081 + H+ 3.282e-07 2.835e-07 -6.484 -6.547 -0.064 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.149e-02 + Ca+2 7.423e-03 3.759e-03 -2.129 -2.425 -0.295 + CaSO4 4.063e-03 4.091e-03 -2.391 -2.388 0.003 + CaHSO4+ 1.856e-08 1.552e-08 -7.731 -7.809 -0.078 + CaOH+ 2.631e-09 2.200e-09 -8.580 -8.658 -0.078 +H(0) 2.169e-32 + H2 1.084e-32 1.092e-32 -31.965 -31.962 0.003 +O(0) 1.528e-15 + O2 7.641e-16 7.694e-16 -15.117 -15.114 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -95.892 -95.973 -0.081 + H2S 0.000e+00 0.000e+00 -95.962 -95.959 0.003 + S-2 0.000e+00 0.000e+00 -100.813 -101.114 -0.300 +S(6) 1.149e-02 + SO4-2 7.423e-03 3.707e-03 -2.129 -2.431 -0.302 + CaSO4 4.063e-03 4.091e-03 -2.391 -2.388 0.003 + HSO4- 4.106e-07 3.434e-07 -6.387 -6.464 -0.078 + CaHSO4+ 1.856e-08 1.552e-08 -7.731 -7.809 -0.078 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.86 -4.86 CaSO4 + Gypsum -0.15 -4.86 -4.71 CaSO4:2H2O + H2(g) -28.63 -31.96 -3.33 H2 + H2O(g) -0.44 -0.00 0.44 H2O + H2S(g) -94.50 -95.96 -1.46 H2S + O2(g) -11.97 -15.11 -3.15 O2 + Sulfur -71.24 -67.33 3.92 S + +Reaction step 50. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.87 -4.87 1.000e+00 1.988e+00 9.884e-01 + Gypsum -0.16 -4.87 -4.71 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.121e-02 1.162e-02 + S 1.121e-02 1.162e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.539 Charge balance + pe = 7.717 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.905e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 74.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.755268e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.741e-07 6.439e-07 -6.111 -6.191 -0.080 + H+ 3.347e-07 2.893e-07 -6.475 -6.539 -0.063 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.121e-02 + Ca+2 7.263e-03 3.693e-03 -2.139 -2.433 -0.294 + CaSO4 3.950e-03 3.976e-03 -2.403 -2.401 0.003 + CaHSO4+ 1.878e-08 1.572e-08 -7.726 -7.803 -0.077 + CaOH+ 2.530e-09 2.118e-09 -8.597 -8.674 -0.077 +H(0) 2.852e-32 + H2 1.426e-32 1.436e-32 -31.846 -31.843 0.003 +O(0) 1.531e-15 + O2 7.657e-16 7.709e-16 -15.116 -15.113 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -95.513 -95.593 -0.080 + H2S 0.000e+00 0.000e+00 -95.576 -95.573 0.003 + S-2 0.000e+00 0.000e+00 -100.421 -100.720 -0.299 +S(6) 1.121e-02 + SO4-2 7.262e-03 3.642e-03 -2.139 -2.439 -0.300 + CaSO4 3.950e-03 3.976e-03 -2.403 -2.401 0.003 + HSO4- 4.230e-07 3.541e-07 -6.374 -6.451 -0.077 + CaHSO4+ 1.878e-08 1.572e-08 -7.726 -7.803 -0.077 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.87 -4.87 CaSO4 + Gypsum -0.16 -4.87 -4.71 CaSO4:2H2O + H2(g) -28.51 -31.84 -3.33 H2 + H2O(g) -0.42 -0.00 0.42 H2O + H2S(g) -94.10 -95.57 -1.47 H2S + O2(g) -11.96 -15.11 -3.15 O2 + Sulfur -70.96 -67.06 3.90 S + +Reaction step 51. + +Using solution 1. Pure water +Using pure phase assemblage 1. +Using temperature 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Anhydrite 0.00 -4.89 -4.89 1.000e+00 1.989e+00 9.887e-01 + Gypsum -0.17 -4.89 -4.72 1.000e+00 -1.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Ca 1.094e-02 1.134e-02 + S 1.094e-02 1.134e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.530 Charge balance + pe = 7.664 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.841e-02 + Mass of water (kg) = 1.036e+00 + Total alkalinity (eq/kg) = 1.044e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 75.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 17 + Total H = 1.150124e+02 + Total O = 5.755156e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.935e-07 6.609e-07 -6.100 -6.180 -0.079 + H+ 3.412e-07 2.952e-07 -6.467 -6.530 -0.063 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Ca 1.094e-02 + Ca+2 7.104e-03 3.627e-03 -2.149 -2.440 -0.292 + CaSO4 3.838e-03 3.863e-03 -2.416 -2.413 0.003 + CaHSO4+ 1.900e-08 1.592e-08 -7.721 -7.798 -0.077 + CaOH+ 2.432e-09 2.039e-09 -8.614 -8.691 -0.077 +H(0) 3.754e-32 + H2 1.877e-32 1.889e-32 -31.727 -31.724 0.003 +O(0) 1.528e-15 + O2 7.641e-16 7.691e-16 -15.117 -15.114 0.003 +S(-2) 0.000e+00 + HS- 0.000e+00 0.000e+00 -95.131 -95.211 -0.079 + H2S 0.000e+00 0.000e+00 -95.188 -95.185 0.003 + S-2 0.000e+00 0.000e+00 -100.028 -100.325 -0.297 +S(6) 1.094e-02 + SO4-2 7.103e-03 3.579e-03 -2.149 -2.446 -0.298 + CaSO4 3.838e-03 3.863e-03 -2.416 -2.413 0.003 + HSO4- 4.356e-07 3.651e-07 -6.361 -6.438 -0.077 + CaHSO4+ 1.900e-08 1.592e-08 -7.721 -7.798 -0.077 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite 0.00 -4.89 -4.89 CaSO4 + Gypsum -0.17 -4.89 -4.72 CaSO4:2H2O + H2(g) -28.39 -31.72 -3.34 H2 + H2O(g) -0.40 -0.00 0.40 H2O + H2S(g) -93.71 -95.19 -1.48 H2S + O2(g) -11.96 -15.11 -3.15 O2 + Sulfur -70.68 -66.80 3.88 S + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex2.sel b/Sun/examples/ex2.sel new file mode 100644 index 00000000..6c7eed43 --- /dev/null +++ b/Sun/examples/ex2.sel @@ -0,0 +1,53 @@ + sim state soln dist_x time step pH pe temp si_anhydrite si_gypsum + 1 i_soln 1 -99 -99 -99 7 4 25.000 -999.9990 -999.9990 + 1 react 1 -99 0 1 7.06676 10.6862 25.000 -0.2197 0.0000 + 1 react 1 -99 0 2 7.05329 10.6168 26.000 -0.2157 0.0000 + 1 react 1 -99 0 3 7.03993 10.5719 27.000 -0.2115 0.0000 + 1 react 1 -99 0 4 7.02667 10.4793 28.000 -0.2071 0.0000 + 1 react 1 -99 0 5 7.01353 10.4109 29.000 -0.2025 0.0000 + 1 react 1 -99 0 6 7.00051 10.3439 30.000 -0.1977 0.0000 + 1 react 1 -99 0 7 6.9876 10.2766 31.000 -0.1928 0.0000 + 1 react 1 -99 0 8 6.97482 10.2099 32.000 -0.1877 0.0000 + 1 react 1 -99 0 9 6.96217 10.149 33.000 -0.1824 0.0000 + 1 react 1 -99 0 10 6.94965 10.0785 34.000 -0.1769 0.0000 + 1 react 1 -99 0 11 6.93726 10.0131 35.000 -0.1713 0.0000 + 1 react 1 -99 0 12 6.925 9.94603 36.000 -0.1655 0.0000 + 1 react 1 -99 0 13 6.91288 9.88397 37.000 -0.1595 0.0000 + 1 react 1 -99 0 14 6.90089 9.86516 38.000 -0.1533 0.0000 + 1 react 1 -99 0 15 6.88905 9.75536 39.000 -0.1470 0.0000 + 1 react 1 -99 0 16 6.87734 9.69233 40.000 -0.1406 0.0000 + 1 react 1 -99 0 17 6.86578 9.62865 41.000 -0.1340 0.0000 + 1 react 1 -99 0 18 6.85435 9.56448 42.000 -0.1272 0.0000 + 1 react 1 -99 0 19 6.84307 9.50323 43.000 -0.1203 0.0000 + 1 react 1 -99 0 20 6.83193 9.44484 44.000 -0.1132 0.0000 + 1 react 1 -99 0 21 6.82093 9.37869 45.000 -0.1060 0.0000 + 1 react 1 -99 0 22 6.81008 9.31598 46.000 -0.0986 0.0000 + 1 react 1 -99 0 23 6.79936 9.25548 47.000 -0.0911 0.0000 + 1 react 1 -99 0 24 6.78879 9.19236 48.000 -0.0835 0.0000 + 1 react 1 -99 0 25 6.77836 9.14193 49.000 -0.0757 0.0000 + 1 react 1 -99 0 26 6.76807 9.07059 50.000 -0.0678 0.0000 + 1 react 1 -99 0 27 6.75793 9.01241 51.000 -0.0597 0.0000 + 1 react 1 -99 0 28 6.74792 8.95269 52.000 -0.0515 0.0000 + 1 react 1 -99 0 29 6.73806 8.89104 53.000 -0.0432 0.0000 + 1 react 1 -99 0 30 6.72833 8.83437 54.000 -0.0347 0.0000 + 1 react 1 -99 0 31 6.71874 8.77256 55.000 -0.0261 0.0000 + 1 react 1 -99 0 32 6.7093 8.71589 56.000 -0.0174 0.0000 + 1 react 1 -99 0 33 6.69999 8.65867 57.000 -0.0085 0.0000 + 1 react 1 -99 0 34 6.69076 8.59025 58.000 0.0000 -0.0004 + 1 react 1 -99 0 35 6.68054 8.53312 59.000 0.0000 -0.0095 + 1 react 1 -99 0 36 6.67043 8.4773 60.000 0.0000 -0.0187 + 1 react 1 -99 0 37 6.66041 8.42236 61.000 0.0000 -0.0280 + 1 react 1 -99 0 38 6.65049 8.36458 62.000 0.0000 -0.0375 + 1 react 1 -99 0 39 6.64066 8.22145 63.000 0.0000 -0.0471 + 1 react 1 -99 0 40 6.63093 8.25388 64.000 0.0000 -0.0567 + 1 react 1 -99 0 41 6.62129 8.1986 65.000 0.0000 -0.0665 + 1 react 1 -99 0 42 6.61175 8.05474 66.000 0.0000 -0.0764 + 1 react 1 -99 0 43 6.6023 8.09202 67.000 0.0000 -0.0864 + 1 react 1 -99 0 44 6.59294 8.03836 68.000 0.0000 -0.0966 + 1 react 1 -99 0 45 6.58367 7.98491 69.000 0.0000 -0.1068 + 1 react 1 -99 0 46 6.57449 7.93039 70.000 0.0000 -0.1171 + 1 react 1 -99 0 47 6.5654 7.87729 71.000 0.0000 -0.1276 + 1 react 1 -99 0 48 6.55641 7.82446 72.000 0.0000 -0.1381 + 1 react 1 -99 0 49 6.5475 7.76904 73.000 0.0000 -0.1488 + 1 react 1 -99 0 50 6.53867 7.71679 74.000 0.0000 -0.1595 + 1 react 1 -99 0 51 6.52994 7.66434 75.000 0.0000 -0.1704 diff --git a/Sun/examples/ex3.log b/Sun/examples/ex3.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex3.out b/Sun/examples/ex3.out new file mode 100644 index 00000000..c04b11b6 --- /dev/null +++ b/Sun/examples/ex3.out @@ -0,0 +1,789 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex3 + Output file: ex3.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 3, part A.--Calcite equilibrium at log Pco2 = -2.0 and 25C. + SOLUTION 1 Pure water + pH 7.0 + temp 25.0 + EQUILIBRIUM_PHASES + CO2(g) -2.0 + Calcite 0.0 + SAVE solution 1 + END +----- +TITLE +----- + + Example 3, part A.--Calcite equilibrium at log Pco2 = -2.0 and 25C. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Pure water + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Pure water + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.082e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 + H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 +H(0) 1.416e-25 + H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 0.00 1.51 H2O + O2(g) -39.12 -42.08 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Pure water +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.998e+00 -1.646e-03 + CO2(g) -2.00 -20.15 -18.15 1.000e+01 9.998e+00 -1.976e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 3.622e-03 3.622e-03 + Ca 1.646e-03 1.646e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.297 Charge balance + pe = -0.987 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.826e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.291e-03 + Total CO2 (mol/kg) = 3.622e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.110124e+02 + Total O = 5.551511e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.137e-07 1.982e-07 -6.670 -6.703 -0.033 + H+ 5.403e-08 5.050e-08 -7.267 -7.297 -0.029 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 2.799e-30 + CH4 2.799e-30 2.802e-30 -29.553 -29.552 0.000 +C(4) 3.622e-03 + HCO3- 3.224e-03 2.998e-03 -2.492 -2.523 -0.032 + CO2 3.401e-04 3.405e-04 -3.468 -3.468 0.000 + CaHCO3+ 4.894e-05 4.551e-05 -4.310 -4.342 -0.032 + CaCO3 5.559e-06 5.565e-06 -5.255 -5.255 0.000 + CO3-2 3.721e-06 2.784e-06 -5.429 -5.555 -0.126 +Ca 1.646e-03 + Ca+2 1.591e-03 1.190e-03 -2.798 -2.925 -0.126 + CaHCO3+ 4.894e-05 4.551e-05 -4.310 -4.342 -0.032 + CaCO3 5.559e-06 5.565e-06 -5.255 -5.255 0.000 + CaOH+ 4.212e-09 3.910e-09 -8.376 -8.408 -0.032 +H(0) 3.403e-16 + H2 1.701e-16 1.703e-16 -15.769 -15.769 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -60.843 -60.843 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -26.69 -29.55 -2.86 CH4 + CO2(g) -2.00 -3.47 -1.47 CO2 + H2(g) -12.62 -15.77 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -57.88 -60.84 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + TITLE Example 3, part B.--Definition of seawater. + SOLUTION 2 Seawater + units ppm + pH 8.22 + pe 8.451 + density 1.023 + temp 25.0 + Ca 412.3 + Mg 1291.8 + Na 10768.0 + K 399.1 + Si 4.28 + Cl 19353.0 + Alkalinity 141.682 as HCO3 + S(6) 2712.0 + END +----- +TITLE +----- + + Example 3, part B.--Definition of seawater. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 2. Seawater + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Alkalinity 2.406e-03 2.406e-03 + Ca 1.066e-02 1.066e-02 + Cl 5.657e-01 5.657e-01 + K 1.058e-02 1.058e-02 + Mg 5.507e-02 5.507e-02 + Na 4.854e-01 4.854e-01 + S(6) 2.926e-02 2.926e-02 + Si 7.382e-05 7.382e-05 + +----------------------------Description of solution---------------------------- + + pH = 8.220 + pe = 8.451 + Activity of water = 0.981 + Ionic strength = 6.748e-01 + Mass of water (kg) = 1.000e+00 + Total carbon (mol/kg) = 2.180e-03 + Total CO2 (mol/kg) = 2.180e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.967e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.07 + Iterations = 7 + Total H = 1.110147e+02 + Total O = 5.563008e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.674e-06 1.629e-06 -5.573 -5.788 -0.215 + H+ 7.981e-09 6.026e-09 -8.098 -8.220 -0.122 + H2O 5.551e+01 9.806e-01 1.744 -0.009 0.000 +C(4) 2.180e-03 + HCO3- 1.514e-03 1.023e-03 -2.820 -2.990 -0.170 + MgHCO3+ 2.196e-04 1.640e-04 -3.658 -3.785 -0.127 + NaHCO3 1.668e-04 1.948e-04 -3.778 -3.710 0.067 + MgCO3 8.914e-05 1.041e-04 -4.050 -3.982 0.067 + NaCO3- 6.719e-05 5.020e-05 -4.173 -4.299 -0.127 + CaHCO3+ 4.598e-05 3.106e-05 -4.337 -4.508 -0.170 + CO3-2 3.821e-05 7.960e-06 -4.418 -5.099 -0.681 + CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 + CO2 1.210e-05 1.413e-05 -4.917 -4.850 0.067 +Ca 1.066e-02 + Ca+2 9.504e-03 2.380e-03 -2.022 -2.623 -0.601 + CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 + CaHCO3+ 4.598e-05 3.106e-05 -4.337 -4.508 -0.170 + CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 + CaOH+ 8.604e-08 6.429e-08 -7.065 -7.192 -0.127 + CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 +Cl 5.657e-01 + Cl- 5.657e-01 3.528e-01 -0.247 -0.452 -0.205 +H(0) 5.515e-37 + H2 2.757e-37 3.221e-37 -36.559 -36.492 0.067 +K 1.058e-02 + K+ 1.041e-02 6.495e-03 -1.982 -2.187 -0.205 + KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 + KOH 3.137e-09 3.665e-09 -8.503 -8.436 0.067 +Mg 5.507e-02 + Mg+2 4.742e-02 1.371e-02 -1.324 -1.863 -0.539 + MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 + MgHCO3+ 2.196e-04 1.640e-04 -3.658 -3.785 -0.127 + MgCO3 8.914e-05 1.041e-04 -4.050 -3.982 0.067 + MgOH+ 1.084e-05 8.100e-06 -4.965 -5.092 -0.127 +Na 4.854e-01 + Na+ 4.791e-01 3.387e-01 -0.320 -0.470 -0.151 + NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 + NaHCO3 1.668e-04 1.948e-04 -3.778 -3.710 0.067 + NaCO3- 6.719e-05 5.020e-05 -4.173 -4.299 -0.127 + NaOH 3.117e-07 3.641e-07 -6.506 -6.439 0.067 +O(0) 6.614e-20 + O2 3.307e-20 3.863e-20 -19.481 -19.413 0.067 +S(6) 2.926e-02 + SO4-2 1.463e-02 2.664e-03 -1.835 -2.574 -0.740 + MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 + NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 + CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 + KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 + HSO4- 2.089e-09 1.561e-09 -8.680 -8.807 -0.127 + CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 +Si 7.382e-05 + H4SiO4 7.110e-05 8.306e-05 -4.148 -4.081 0.067 + H3SiO4- 2.720e-06 2.032e-06 -5.565 -5.692 -0.127 + H2SiO4-2 7.362e-11 2.294e-11 -10.133 -10.639 -0.506 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.84 -5.20 -4.36 CaSO4 + Aragonite 0.61 -7.72 -8.34 CaCO3 + Calcite 0.76 -7.72 -8.48 CaCO3 + Chalcedony -0.51 -4.06 -3.55 SiO2 + Chrysotile 3.36 35.56 32.20 Mg3Si2O5(OH)4 + CO2(g) -3.38 -4.85 -1.47 CO2 + Dolomite 2.41 -14.68 -17.09 CaMg(CO3)2 + Gypsum -0.63 -5.21 -4.58 CaSO4:2H2O + H2(g) -33.34 -36.49 -3.15 H2 + H2O(g) -1.52 -0.01 1.51 H2O + Halite -2.50 -0.92 1.58 NaCl + O2(g) -16.45 -19.41 -2.96 O2 + Quartz -0.08 -4.06 -3.98 SiO2 + Sepiolite 1.16 16.92 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -1.74 16.92 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -1.35 -4.06 -2.71 SiO2 + Talc 6.04 27.44 21.40 Mg3Si4O10(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + TITLE Example 3, part C.--Mix 70% ground water, 30% seawater. + MIX 1 + 1 0.7 + 2 0.3 + SAVE solution 3 + END +----- +TITLE +----- + + Example 3, part C.--Mix 70% ground water, 30% seawater. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using mix 1. + +Mixture 1. + + 7.000e-01 Solution 1 Solution after simulation 1. + 3.000e-01 Solution 2 Seawater + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 3.189e-03 3.189e-03 + Ca 4.350e-03 4.350e-03 + Cl 1.697e-01 1.697e-01 + K 3.173e-03 3.173e-03 + Mg 1.652e-02 1.652e-02 + Na 1.456e-01 1.456e-01 + S 8.777e-03 8.777e-03 + Si 2.215e-05 2.215e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.351 Charge balance + pe = -1.717 Adjusted to redox equilibrium + Activity of water = 0.994 + Ionic strength = 2.087e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.026e-03 + Total CO2 (mol/kg) = 3.189e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.390e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 + Iterations = 13 + Total H = 1.110131e+02 + Total O = 5.554960e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.170e-07 2.231e-07 -6.499 -6.651 -0.153 + H+ 5.603e-08 4.460e-08 -7.252 -7.351 -0.099 + H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 +C(-4) 4.007e-25 + CH4 4.007e-25 4.204e-25 -24.397 -24.376 0.021 +C(4) 3.189e-03 + HCO3- 2.662e-03 1.980e-03 -2.575 -2.703 -0.129 + CO2 1.904e-04 1.998e-04 -3.720 -3.699 0.021 + MgHCO3+ 1.545e-04 1.151e-04 -3.811 -3.939 -0.128 + NaHCO3 1.137e-04 1.192e-04 -3.944 -3.924 0.021 + CaHCO3+ 4.245e-05 3.158e-05 -4.372 -4.501 -0.129 + MgCO3 9.408e-06 9.871e-06 -5.027 -5.006 0.021 + CO3-2 6.803e-06 2.082e-06 -5.167 -5.682 -0.514 + NaCO3- 5.572e-06 4.151e-06 -5.254 -5.382 -0.128 + CaCO3 4.166e-06 4.371e-06 -5.380 -5.359 0.021 +Ca 4.350e-03 + Ca+2 3.928e-03 1.250e-03 -2.406 -2.903 -0.497 + CaSO4 3.753e-04 3.938e-04 -3.426 -3.405 0.021 + CaHCO3+ 4.245e-05 3.158e-05 -4.372 -4.501 -0.129 + CaCO3 4.166e-06 4.371e-06 -5.380 -5.359 0.021 + CaOH+ 6.204e-09 4.622e-09 -8.207 -8.335 -0.128 + CaHSO4+ 1.381e-10 1.029e-10 -9.860 -9.988 -0.128 +Cl 1.697e-01 + Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 +H(0) 7.279e-15 + H2 3.640e-15 3.819e-15 -14.439 -14.418 0.021 +K 3.173e-03 + K+ 3.140e-03 2.226e-03 -2.503 -2.652 -0.149 + KSO4- 3.316e-05 2.470e-05 -4.479 -4.607 -0.128 + KOH 1.639e-10 1.720e-10 -9.785 -9.764 0.021 +Mg 1.652e-02 + Mg+2 1.460e-02 4.968e-03 -1.836 -2.304 -0.468 + MgSO4 1.753e-03 1.839e-03 -2.756 -2.735 0.021 + MgHCO3+ 1.545e-04 1.151e-04 -3.811 -3.939 -0.128 + MgCO3 9.408e-06 9.871e-06 -5.027 -5.006 0.021 + MgOH+ 5.396e-07 4.020e-07 -6.268 -6.396 -0.128 +Na 1.456e-01 + Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 + NaSO4- 1.138e-03 8.476e-04 -2.944 -3.072 -0.128 + NaHCO3 1.137e-04 1.192e-04 -3.944 -3.924 0.021 + NaCO3- 5.572e-06 4.151e-06 -5.254 -5.382 -0.128 + NaOH 1.503e-08 1.577e-08 -7.823 -7.802 0.021 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -63.570 -63.549 0.021 +S(-2) 4.890e-22 + HS- 3.876e-22 2.728e-22 -21.412 -21.564 -0.153 + H2S 1.014e-22 1.064e-22 -21.994 -21.973 0.021 + S-2 2.513e-27 7.386e-28 -26.600 -27.132 -0.532 +S(6) 8.777e-03 + SO4-2 5.478e-03 1.579e-03 -2.261 -2.802 -0.540 + MgSO4 1.753e-03 1.839e-03 -2.756 -2.735 0.021 + NaSO4- 1.138e-03 8.476e-04 -2.944 -3.072 -0.128 + CaSO4 3.753e-04 3.938e-04 -3.426 -3.405 0.021 + KSO4- 3.316e-05 2.470e-05 -4.479 -4.607 -0.128 + HSO4- 9.193e-09 6.849e-09 -8.037 -8.164 -0.128 + CaHSO4+ 1.381e-10 1.029e-10 -9.860 -9.988 -0.128 +Si 2.215e-05 + H4SiO4 2.204e-05 2.313e-05 -4.657 -4.636 0.021 + H3SiO4- 1.026e-07 7.646e-08 -6.989 -7.117 -0.128 + H2SiO4-2 3.784e-13 1.166e-13 -12.422 -12.933 -0.511 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -1.34 -5.70 -4.36 CaSO4 + Aragonite -0.25 -8.58 -8.34 CaCO3 + Calcite -0.10 -8.58 -8.48 CaCO3 + CH4(g) -21.52 -24.38 -2.86 CH4 + Chalcedony -1.08 -4.63 -3.55 SiO2 + Chrysotile -4.28 27.92 32.20 Mg3Si2O5(OH)4 + CO2(g) -2.23 -3.70 -1.47 CO2 + Dolomite 0.52 -16.57 -17.09 CaMg(CO3)2 + Gypsum -1.13 -5.71 -4.58 CaSO4:2H2O + H2(g) -11.27 -14.42 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -20.98 -21.97 -1.00 H2S + Halite -3.47 -1.89 1.58 NaCl + O2(g) -60.59 -63.55 -2.96 O2 + Quartz -0.65 -4.63 -3.98 SiO2 + Sepiolite -4.87 10.89 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -7.77 10.89 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -1.92 -4.63 -2.71 SiO2 + Sulfur -15.59 -10.71 4.88 S + Talc -2.74 18.66 21.40 Mg3Si4O10(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + TITLE Example 3, part D.--Equilibrate mixture with calcite and dolomite. + EQUILIBRIUM_PHASES 1 + Calcite 0.0 + Dolomite 0.0 + USE solution 3 + END +----- +TITLE +----- + + Example 3, part D.--Equilibrate mixture with calcite and dolomite. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 3. Solution after simulation 3. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.984e+00 -1.571e-02 + Dolomite 0.00 -17.09 -17.09 1.000e+01 1.001e+01 7.935e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 3.029e-03 3.029e-03 + Ca 1.213e-02 1.212e-02 + Cl 1.697e-01 1.697e-01 + K 3.173e-03 3.173e-03 + Mg 8.585e-03 8.585e-03 + Na 1.456e-01 1.456e-01 + S 8.777e-03 8.777e-03 + Si 2.215e-05 2.215e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.056 Charge balance + pe = -1.421 Adjusted to redox equilibrium + Activity of water = 0.994 + Ionic strength = 2.087e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.704e-03 + Total CO2 (mol/kg) = 3.029e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.390e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 + Iterations = 5 + Total H = 1.110131e+02 + Total O = 5.554912e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.609e-07 1.132e-07 -6.793 -6.946 -0.153 + H+ 1.104e-07 8.788e-08 -6.957 -7.056 -0.099 + H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 +C(-4) 6.977e-25 + CH4 6.977e-25 7.320e-25 -24.156 -24.135 0.021 +C(4) 3.029e-03 + HCO3- 2.397e-03 1.783e-03 -2.620 -2.749 -0.129 + CO2 3.377e-04 3.543e-04 -3.471 -3.451 0.021 + CaHCO3+ 1.065e-04 7.920e-05 -3.973 -4.101 -0.129 + NaHCO3 1.023e-04 1.073e-04 -3.990 -3.969 0.021 + MgHCO3+ 7.221e-05 5.380e-05 -4.141 -4.269 -0.128 + CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 + CO3-2 3.109e-06 9.513e-07 -5.507 -6.022 -0.514 + NaCO3- 2.546e-06 1.897e-06 -5.594 -5.722 -0.128 + MgCO3 2.232e-06 2.341e-06 -5.651 -5.631 0.021 +Ca 1.213e-02 + Ca+2 1.095e-02 3.482e-03 -1.961 -2.458 -0.497 + CaSO4 1.067e-03 1.119e-03 -2.972 -2.951 0.021 + CaHCO3+ 1.065e-04 7.920e-05 -3.973 -4.101 -0.129 + CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 + CaOH+ 8.774e-09 6.537e-09 -8.057 -8.185 -0.128 + CaHSO4+ 7.734e-10 5.762e-10 -9.112 -9.239 -0.128 +Cl 1.697e-01 + Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 +H(0) 7.246e-15 + H2 3.623e-15 3.801e-15 -14.441 -14.420 0.021 +K 3.173e-03 + K+ 3.140e-03 2.225e-03 -2.503 -2.653 -0.149 + KSO4- 3.381e-05 2.519e-05 -4.471 -4.599 -0.128 + KOH 8.319e-11 8.729e-11 -10.080 -10.059 0.021 +Mg 8.585e-03 + Mg+2 7.582e-03 2.579e-03 -2.120 -2.588 -0.468 + MgSO4 9.283e-04 9.740e-04 -3.032 -3.011 0.021 + MgHCO3+ 7.221e-05 5.380e-05 -4.141 -4.269 -0.128 + MgCO3 2.232e-06 2.341e-06 -5.651 -5.631 0.021 + MgOH+ 1.422e-07 1.059e-07 -6.847 -6.975 -0.128 +Na 1.456e-01 + Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 + NaSO4- 1.160e-03 8.644e-04 -2.935 -3.063 -0.128 + NaHCO3 1.023e-04 1.073e-04 -3.990 -3.969 0.021 + NaCO3- 2.546e-06 1.897e-06 -5.594 -5.722 -0.128 + NaOH 7.627e-09 8.002e-09 -8.118 -8.097 0.021 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -63.566 -63.545 0.021 +S(-2) 1.159e-21 + HS- 7.648e-22 5.382e-22 -21.116 -21.269 -0.153 + H2S 3.941e-22 4.136e-22 -21.404 -21.383 0.021 + S-2 2.517e-27 7.397e-28 -26.599 -27.131 -0.532 +S(6) 8.777e-03 + SO4-2 5.588e-03 1.611e-03 -2.253 -2.793 -0.540 + NaSO4- 1.160e-03 8.644e-04 -2.935 -3.063 -0.128 + CaSO4 1.067e-03 1.119e-03 -2.972 -2.951 0.021 + MgSO4 9.283e-04 9.740e-04 -3.032 -3.011 0.021 + KSO4- 3.381e-05 2.519e-05 -4.471 -4.599 -0.128 + HSO4- 1.847e-08 1.376e-08 -7.733 -7.861 -0.128 + CaHSO4+ 7.734e-10 5.762e-10 -9.112 -9.239 -0.128 +Si 2.215e-05 + H4SiO4 2.210e-05 2.318e-05 -4.656 -4.635 0.021 + H3SiO4- 5.221e-08 3.890e-08 -7.282 -7.410 -0.128 + H2SiO4-2 9.772e-14 3.011e-14 -13.010 -13.521 -0.511 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.89 -5.25 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -21.28 -24.14 -2.86 CH4 + Chalcedony -1.08 -4.63 -3.55 SiO2 + Chrysotile -6.90 25.30 32.20 Mg3Si2O5(OH)4 + CO2(g) -1.98 -3.45 -1.47 CO2 + Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 + Gypsum -0.68 -5.26 -4.58 CaSO4:2H2O + H2(g) -11.27 -14.42 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -20.39 -21.38 -1.00 H2S + Halite -3.47 -1.89 1.58 NaCl + O2(g) -60.58 -63.54 -2.96 O2 + Quartz -0.65 -4.63 -3.98 SiO2 + Sepiolite -6.62 9.14 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -9.52 9.14 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -1.92 -4.63 -2.71 SiO2 + Sulfur -15.00 -10.11 4.88 S + Talc -5.36 16.04 21.40 Mg3Si4O10(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 5. +------------------------------------ + + TITLE Example 3, part E.--Equilibrate mixture with calcite only. + EQUILIBRIUM_PHASES 2 + Calcite 0.0 + USE solution 3 + END +----- +TITLE +----- + + Example 3, part E.--Equilibrate mixture with calcite only. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 3. Solution after simulation 3. +Using pure phase assemblage 2. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 1.000e+01 -3.992e-05 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 3.229e-03 3.229e-03 + Ca 4.390e-03 4.390e-03 + Cl 1.697e-01 1.697e-01 + K 3.173e-03 3.173e-03 + Mg 1.652e-02 1.652e-02 + Na 1.456e-01 1.456e-01 + S 8.777e-03 8.777e-03 + Si 2.215e-05 2.215e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.442 Charge balance + pe = -1.861 Adjusted to redox equilibrium + Activity of water = 0.994 + Ionic strength = 2.088e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.106e-03 + Total CO2 (mol/kg) = 3.229e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.390e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 + Iterations = 6 + Total H = 1.110131e+02 + Total O = 5.554972e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.915e-07 2.755e-07 -6.407 -6.560 -0.153 + H+ 4.537e-08 3.612e-08 -7.343 -7.442 -0.099 + H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 +C(-4) 8.842e-25 + CH4 8.842e-25 9.278e-25 -24.053 -24.033 0.021 +C(4) 3.229e-03 + HCO3- 2.721e-03 2.024e-03 -2.565 -2.694 -0.129 + MgHCO3+ 1.579e-04 1.176e-04 -3.802 -3.930 -0.128 + CO2 1.576e-04 1.653e-04 -3.803 -3.782 0.021 + NaHCO3 1.161e-04 1.219e-04 -3.935 -3.914 0.021 + CaHCO3+ 4.376e-05 3.255e-05 -4.359 -4.487 -0.129 + MgCO3 1.187e-05 1.245e-05 -4.926 -4.905 0.021 + CO3-2 8.587e-06 2.628e-06 -5.066 -5.580 -0.514 + NaCO3- 7.033e-06 5.240e-06 -5.153 -5.281 -0.128 + CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 +Ca 4.390e-03 + Ca+2 3.963e-03 1.261e-03 -2.402 -2.899 -0.497 + CaSO4 3.784e-04 3.971e-04 -3.422 -3.401 0.021 + CaHCO3+ 4.376e-05 3.255e-05 -4.359 -4.487 -0.129 + CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 + CaOH+ 7.728e-09 5.758e-09 -8.112 -8.240 -0.128 + CaHSO4+ 1.128e-10 8.402e-11 -9.948 -10.076 -0.128 +Cl 1.697e-01 + Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 +H(0) 9.302e-15 + H2 4.651e-15 4.880e-15 -14.332 -14.312 0.021 +K 3.173e-03 + K+ 3.140e-03 2.226e-03 -2.503 -2.652 -0.149 + KSO4- 3.314e-05 2.469e-05 -4.480 -4.607 -0.128 + KOH 2.025e-10 2.124e-10 -9.694 -9.673 0.021 +Mg 1.652e-02 + Mg+2 1.460e-02 4.966e-03 -1.836 -2.304 -0.468 + MgSO4 1.752e-03 1.838e-03 -2.757 -2.736 0.021 + MgHCO3+ 1.579e-04 1.176e-04 -3.802 -3.930 -0.128 + MgCO3 1.187e-05 1.245e-05 -4.926 -4.905 0.021 + MgOH+ 6.661e-07 4.963e-07 -6.176 -6.304 -0.128 +Na 1.456e-01 + Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 + NaSO4- 1.137e-03 8.472e-04 -2.944 -3.072 -0.128 + NaHCO3 1.161e-04 1.219e-04 -3.935 -3.914 0.021 + NaCO3- 7.033e-06 5.240e-06 -5.153 -5.281 -0.128 + NaOH 1.856e-08 1.947e-08 -7.731 -7.711 0.021 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -63.783 -63.762 0.021 +S(-2) 1.014e-21 + HS- 8.367e-22 5.888e-22 -21.077 -21.230 -0.153 + H2S 1.772e-22 1.860e-22 -21.751 -21.731 0.021 + S-2 6.701e-27 1.969e-27 -26.174 -26.706 -0.532 +S(6) 8.777e-03 + SO4-2 5.477e-03 1.579e-03 -2.261 -2.802 -0.540 + MgSO4 1.752e-03 1.838e-03 -2.757 -2.736 0.021 + NaSO4- 1.137e-03 8.472e-04 -2.944 -3.072 -0.128 + CaSO4 3.784e-04 3.971e-04 -3.422 -3.401 0.021 + KSO4- 3.314e-05 2.469e-05 -4.480 -4.607 -0.128 + HSO4- 7.441e-09 5.544e-09 -8.128 -8.256 -0.128 + CaHSO4+ 1.128e-10 8.402e-11 -9.948 -10.076 -0.128 +Si 2.215e-05 + H4SiO4 2.202e-05 2.311e-05 -4.657 -4.636 0.021 + H3SiO4- 1.266e-07 9.432e-08 -6.898 -7.025 -0.128 + H2SiO4-2 5.766e-13 1.776e-13 -12.239 -12.750 -0.511 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -1.34 -5.70 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -21.17 -24.03 -2.86 CH4 + Chalcedony -1.08 -4.63 -3.55 SiO2 + Chrysotile -3.73 28.47 32.20 Mg3Si2O5(OH)4 + CO2(g) -2.31 -3.78 -1.47 CO2 + Dolomite 0.73 -16.36 -17.09 CaMg(CO3)2 + Gypsum -1.13 -5.71 -4.58 CaSO4:2H2O + H2(g) -11.16 -14.31 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -20.73 -21.73 -1.00 H2S + Halite -3.47 -1.89 1.58 NaCl + O2(g) -60.80 -63.76 -2.96 O2 + Quartz -0.65 -4.63 -3.98 SiO2 + Sepiolite -4.51 11.25 15.76 Mg2Si3O7.5OH:3H2O + Sepiolite(d) -7.41 11.25 18.66 Mg2Si3O7.5OH:3H2O + SiO2(a) -1.92 -4.63 -2.71 SiO2 + Sulfur -15.45 -10.57 4.88 S + Talc -2.19 19.21 21.40 Mg3Si4O10(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 6. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex4.log b/Sun/examples/ex4.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex4.out b/Sun/examples/ex4.out new file mode 100644 index 00000000..146247a6 --- /dev/null +++ b/Sun/examples/ex4.out @@ -0,0 +1,478 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex4 + Output file: ex4.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 4a.--Rain water evaporation + SOLUTION 1 Precipitation from Central Oklahoma + units mg/L + pH 4.5 # estimated + temp 25.0 + Ca .384 + Mg .043 + Na .141 + K .036 + Cl .236 + C(4) .1 CO2(g) -3.5 + S(6) 1.3 + N(-3) .208 + N(5) .237 + REACTION 1 + H2O -1.0 + 52.73 moles + SAVE solution 2 + END +----- +TITLE +----- + + Example 4a.--Rain water evaporation + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. Precipitation from Central Oklahoma + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C(4) 1.092e-05 1.092e-05 Equilibrium with CO2(g) + Ca 9.581e-06 9.581e-06 + Cl 6.657e-06 6.657e-06 + K 9.207e-07 9.207e-07 + Mg 1.769e-06 1.769e-06 + N(-3) 1.485e-05 1.485e-05 + N(5) 1.692e-05 1.692e-05 + Na 6.133e-06 6.133e-06 + S(6) 1.353e-05 1.353e-05 + +----------------------------Description of solution---------------------------- + + pH = 4.500 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 8.838e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.185e-05 + Total CO2 (mol/kg) = 1.092e-05 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.581e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 20.29 + Iterations = 3 + Total H = 1.110125e+02 + Total O = 5.550634e+01 + +---------------------------------Redox couples--------------------------------- + + Redox couple pe Eh (volts) + + N(-3)/N(5) 9.2667 0.5482 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.196e-05 3.162e-05 -4.495 -4.500 -0.005 + OH- 3.200e-10 3.166e-10 -9.495 -9.500 -0.005 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(4) 1.092e-05 + CO2 1.077e-05 1.077e-05 -4.968 -4.968 0.000 + HCO3- 1.531e-07 1.514e-07 -6.815 -6.820 -0.005 + CaHCO3+ 1.787e-11 1.768e-11 -10.748 -10.753 -0.005 + MgHCO3+ 3.025e-12 2.992e-12 -11.519 -11.524 -0.005 + NaHCO3 5.166e-13 5.166e-13 -12.287 -12.287 0.000 + CO3-2 2.345e-13 2.246e-13 -12.630 -12.649 -0.019 + CaCO3 3.452e-15 3.452e-15 -14.462 -14.462 0.000 + MgCO3 3.619e-16 3.619e-16 -15.441 -15.441 0.000 + NaCO3- 2.565e-17 2.537e-17 -16.591 -16.596 -0.005 +Ca 9.581e-06 + Ca+2 9.557e-06 9.151e-06 -5.020 -5.039 -0.019 + CaSO4 2.353e-08 2.353e-08 -7.628 -7.628 0.000 + CaHCO3+ 1.787e-11 1.768e-11 -10.748 -10.753 -0.005 + CaHSO4+ 4.408e-12 4.360e-12 -11.356 -11.361 -0.005 + CaOH+ 4.855e-14 4.803e-14 -13.314 -13.319 -0.005 + CaCO3 3.452e-15 3.452e-15 -14.462 -14.462 0.000 +Cl 6.657e-06 + Cl- 6.657e-06 6.585e-06 -5.177 -5.181 -0.005 +H(0) 1.416e-20 + H2 7.079e-21 7.079e-21 -20.150 -20.150 0.000 +K 9.207e-07 + K+ 9.206e-07 9.106e-07 -6.036 -6.041 -0.005 + KSO4- 8.337e-11 8.247e-11 -10.079 -10.084 -0.005 + KOH 9.984e-17 9.985e-17 -16.001 -16.001 0.000 +Mg 1.769e-06 + Mg+2 1.764e-06 1.689e-06 -5.754 -5.772 -0.019 + MgSO4 5.103e-09 5.103e-09 -8.292 -8.292 0.000 + MgHCO3+ 3.025e-12 2.992e-12 -11.519 -11.524 -0.005 + MgOH+ 1.960e-13 1.939e-13 -12.708 -12.712 -0.005 + MgCO3 3.619e-16 3.619e-16 -15.441 -15.441 0.000 +N(-3) 1.485e-05 + NH4+ 1.485e-05 1.469e-05 -4.828 -4.833 -0.005 + NH4SO4- 2.465e-09 2.438e-09 -8.608 -8.613 -0.005 + NH3 2.646e-10 2.647e-10 -9.577 -9.577 0.000 +N(5) 1.692e-05 + NO3- 1.692e-05 1.674e-05 -4.772 -4.776 -0.005 +Na 6.133e-06 + Na+ 6.133e-06 6.066e-06 -5.212 -5.217 -0.005 + NaSO4- 3.962e-10 3.919e-10 -9.402 -9.407 -0.005 + NaHCO3 5.166e-13 5.166e-13 -12.287 -12.287 0.000 + NaOH 1.267e-15 1.267e-15 -14.897 -14.897 0.000 + NaCO3- 2.565e-17 2.537e-17 -16.591 -16.596 -0.005 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -52.080 -52.080 0.000 +S(6) 1.353e-05 + SO4-2 1.346e-05 1.289e-05 -4.871 -4.890 -0.019 + HSO4- 4.006e-08 3.963e-08 -7.397 -7.402 -0.005 + CaSO4 2.353e-08 2.353e-08 -7.628 -7.628 0.000 + MgSO4 5.103e-09 5.103e-09 -8.292 -8.292 0.000 + NH4SO4- 2.465e-09 2.438e-09 -8.608 -8.613 -0.005 + NaSO4- 3.962e-10 3.919e-10 -9.402 -9.407 -0.005 + KSO4- 8.337e-11 8.247e-11 -10.079 -10.084 -0.005 + CaHSO4+ 4.408e-12 4.360e-12 -11.356 -11.361 -0.005 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -5.57 -9.93 -4.36 CaSO4 + Aragonite -9.35 -17.69 -8.34 CaCO3 + Calcite -9.21 -17.69 -8.48 CaCO3 + CO2(g) -3.50 -4.97 -1.47 CO2 + Dolomite -19.02 -36.11 -17.09 CaMg(CO3)2 + Gypsum -5.35 -9.93 -4.58 CaSO4:2H2O + H2(g) -17.00 -20.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -11.98 -10.40 1.58 NaCl + NH3(g) -11.35 -9.58 1.77 NH3 + O2(g) -49.12 -52.08 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Precipitation from Central Oklahoma +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 5.273e+01 moles of the following reaction have been added: + + Relative + Reactant moles + + H2O -1.00 + + Relative + Element moles + H -2.00 + O -1.00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.183e-04 1.092e-05 + Ca 1.916e-04 9.581e-06 + Cl 1.331e-04 6.657e-06 + K 1.841e-05 9.207e-07 + Mg 3.536e-05 1.769e-06 + N 6.352e-04 3.177e-05 + Na 1.226e-04 6.133e-06 + S 2.706e-04 1.353e-05 + +----------------------------Description of solution---------------------------- + + pH = 3.148 Charge balance + pe = 16.530 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.528e-03 + Mass of water (kg) = 5.002e-02 + Total alkalinity (eq/kg) = -7.555e-04 + Total CO2 (mol/kg) = 2.183e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.581e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 24.31 + Iterations = 20 + Total H = 5.552525e+00 + Total O = 2.776344e+00 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 7.406e-04 7.108e-04 -3.130 -3.148 -0.018 + OH- 1.472e-11 1.408e-11 -10.832 -10.851 -0.019 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -136.693 -136.693 0.000 +C(4) 2.183e-04 + CO2 2.182e-04 2.182e-04 -3.661 -3.661 0.000 + HCO3- 1.425e-07 1.366e-07 -6.846 -6.865 -0.019 + CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 + MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 + NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 + CO3-2 1.070e-14 9.010e-15 -13.971 -14.045 -0.074 + CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 + MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 + NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 +Ca 1.916e-04 + Ca+2 1.851e-04 1.559e-04 -3.733 -3.807 -0.075 + CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 + CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 + CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 + CaOH+ 3.801e-14 3.639e-14 -13.420 -13.439 -0.019 + CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 +Cl 1.331e-04 + Cl- 1.331e-04 1.274e-04 -3.876 -3.895 -0.019 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.506 -42.506 0.000 +K 1.841e-05 + K+ 1.838e-05 1.759e-05 -4.736 -4.755 -0.019 + KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 + KOH 8.579e-17 8.582e-17 -16.067 -16.066 0.000 +Mg 3.536e-05 + Mg+2 3.396e-05 2.864e-05 -4.469 -4.543 -0.074 + MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 + MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 + MgOH+ 1.528e-13 1.463e-13 -12.816 -12.835 -0.019 + MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -48.438 -48.457 -0.019 + NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 + NH3 0.000e+00 0.000e+00 -54.553 -54.553 0.000 +N(0) 4.751e-04 + N2 2.375e-04 2.376e-04 -3.624 -3.624 0.000 +N(3) 2.623e-15 + NO2- 2.623e-15 2.510e-15 -14.581 -14.600 -0.019 +N(5) 1.601e-04 + NO3- 1.601e-04 1.532e-04 -3.796 -3.815 -0.019 +Na 1.226e-04 + Na+ 1.225e-04 1.173e-04 -3.912 -3.931 -0.019 + NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 + NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 + NaOH 1.090e-15 1.090e-15 -14.963 -14.962 0.000 + NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 +O(0) 8.553e-08 + O2 4.277e-08 4.278e-08 -7.369 -7.369 0.000 +S(-2) 0.000e+00 + H2S 0.000e+00 0.000e+00 -126.809 -126.809 0.000 + HS- 0.000e+00 0.000e+00 -130.583 -130.602 -0.019 + S-2 0.000e+00 0.000e+00 -140.297 -140.372 -0.075 +S(6) 2.706e-04 + SO4-2 2.475e-04 2.083e-04 -3.606 -3.681 -0.075 + HSO4- 1.503e-05 1.439e-05 -4.823 -4.842 -0.019 + CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 + MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 + NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 + CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 + KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 + NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.13 -7.49 -4.36 CaSO4 + Aragonite -9.52 -17.85 -8.34 CaCO3 + Calcite -9.37 -17.85 -8.48 CaCO3 + CH4(g) -133.83 -136.69 -2.86 CH4 + CO2(g) -2.19 -3.66 -1.47 CO2 + Dolomite -19.35 -36.44 -17.09 CaMg(CO3)2 + Gypsum -2.91 -7.49 -4.58 CaSO4:2H2O + H2(g) -39.36 -42.51 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -125.81 -126.81 -1.00 H2S + Halite -9.41 -7.83 1.58 NaCl + N2(g) -0.36 -3.62 -3.26 N2 + NH3(g) -56.32 -54.55 1.77 NH3 + O2(g) -4.41 -7.37 -2.96 O2 + Sulfur -92.34 -87.45 4.88 S + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + TITLE Example 4b.--Factor of 20 more solution + MIX + 2 20. + SAVE solution 3 + END +----- +TITLE +----- + + Example 4b.--Factor of 20 more solution + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using mix 1. + +Mixture 1. + + 2.000e+01 Solution 2 Solution after simulation 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.183e-04 2.184e-04 + Ca 1.916e-04 1.916e-04 + Cl 1.331e-04 1.331e-04 + K 1.841e-05 1.841e-05 + Mg 3.536e-05 3.537e-05 + N 6.352e-04 6.354e-04 + Na 1.226e-04 1.227e-04 + S 2.706e-04 2.707e-04 + +----------------------------Description of solution---------------------------- + + pH = 3.148 Charge balance + pe = 16.530 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.528e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -7.555e-04 + Total CO2 (mol/kg) = 2.183e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 5.162e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 24.31 + Iterations = 0 + Total H = 1.110505e+02 + Total O = 5.552687e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 7.406e-04 7.108e-04 -3.130 -3.148 -0.018 + OH- 1.472e-11 1.408e-11 -10.832 -10.851 -0.019 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(-4) 0.000e+00 + CH4 0.000e+00 0.000e+00 -136.693 -136.693 0.000 +C(4) 2.183e-04 + CO2 2.182e-04 2.182e-04 -3.661 -3.661 0.000 + HCO3- 1.425e-07 1.366e-07 -6.846 -6.865 -0.019 + CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 + MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 + NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 + CO3-2 1.070e-14 9.010e-15 -13.971 -14.045 -0.074 + CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 + MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 + NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 +Ca 1.916e-04 + Ca+2 1.851e-04 1.559e-04 -3.733 -3.807 -0.075 + CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 + CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 + CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 + CaOH+ 3.801e-14 3.639e-14 -13.420 -13.439 -0.019 + CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 +Cl 1.331e-04 + Cl- 1.331e-04 1.274e-04 -3.876 -3.895 -0.019 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.506 -42.506 0.000 +K 1.841e-05 + K+ 1.838e-05 1.759e-05 -4.736 -4.755 -0.019 + KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 + KOH 8.579e-17 8.582e-17 -16.067 -16.066 0.000 +Mg 3.536e-05 + Mg+2 3.396e-05 2.864e-05 -4.469 -4.543 -0.074 + MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 + MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 + MgOH+ 1.528e-13 1.463e-13 -12.816 -12.835 -0.019 + MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -48.438 -48.457 -0.019 + NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 + NH3 0.000e+00 0.000e+00 -54.553 -54.553 0.000 +N(0) 4.751e-04 + N2 2.375e-04 2.376e-04 -3.624 -3.624 0.000 +N(3) 2.623e-15 + NO2- 2.623e-15 2.510e-15 -14.581 -14.600 -0.019 +N(5) 1.601e-04 + NO3- 1.601e-04 1.532e-04 -3.796 -3.815 -0.019 +Na 1.226e-04 + Na+ 1.225e-04 1.173e-04 -3.912 -3.931 -0.019 + NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 + NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 + NaOH 1.090e-15 1.090e-15 -14.963 -14.962 0.000 + NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 +O(0) 8.553e-08 + O2 4.277e-08 4.278e-08 -7.369 -7.369 0.000 +S(-2) 0.000e+00 + H2S 0.000e+00 0.000e+00 -126.809 -126.809 0.000 + HS- 0.000e+00 0.000e+00 -130.583 -130.602 -0.019 + S-2 0.000e+00 0.000e+00 -140.297 -140.372 -0.075 +S(6) 2.706e-04 + SO4-2 2.475e-04 2.083e-04 -3.606 -3.681 -0.075 + HSO4- 1.503e-05 1.439e-05 -4.823 -4.842 -0.019 + CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 + MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 + NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 + CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 + KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 + NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -3.13 -7.49 -4.36 CaSO4 + Aragonite -9.52 -17.85 -8.34 CaCO3 + Calcite -9.37 -17.85 -8.48 CaCO3 + CH4(g) -133.83 -136.69 -2.86 CH4 + CO2(g) -2.19 -3.66 -1.47 CO2 + Dolomite -19.35 -36.44 -17.09 CaMg(CO3)2 + Gypsum -2.91 -7.49 -4.58 CaSO4:2H2O + H2(g) -39.36 -42.51 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -125.81 -126.81 -1.00 H2S + Halite -9.41 -7.83 1.58 NaCl + N2(g) -0.36 -3.62 -3.26 N2 + NH3(g) -56.32 -54.55 1.77 NH3 + O2(g) -4.41 -7.37 -2.96 O2 + Sulfur -92.34 -87.45 4.88 S + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex5.log b/Sun/examples/ex5.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex5.out b/Sun/examples/ex5.out new file mode 100644 index 00000000..d335bbe5 --- /dev/null +++ b/Sun/examples/ex5.out @@ -0,0 +1,942 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex5 + Output file: ex5.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 5.--Add oxygen, equilibrate with pyrite, calcite, and goethite. + SOLUTION 1 PURE WATER + pH 7.0 + temp 25.0 + EQUILIBRIUM_PHASES 1 + Pyrite 0.0 + Goethite 0.0 + Calcite 0.0 + CO2(g) -3.5 + Gypsum 0.0 0.0 + REACTION 1 + O2 1.0 + NaCl 0.5 + 0.0 0.001 0.005 0.01 0.05 + SELECTED_OUTPUT + file ex5.sel + totals Cl + si Gypsum + equilibrium_phases pyrite goethite calcite CO2(g) gypsum + END +----- +TITLE +----- + + Example 5.--Add oxygen, equilibrate with pyrite, calcite, and goethite. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. PURE WATER + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Pure water + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.082e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 + H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 +H(0) 1.416e-25 + H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 0.00 1.51 H2O + O2(g) -39.12 -42.08 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 0.000e+00 moles of the following reaction have been added: + + Relative + Reactant moles + + O2 1.00 + NaCl 0.50 + + Relative + Element moles + Cl 0.50 + Na 0.50 + O 2.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 1.000e+01 -4.934e-04 + CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 -4.870e-04 + Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 1.105e-08 + Gypsum -6.13 -10.71 -4.58 0.000e+00 0.000e+00 + Pyrite 0.00 -85.78 -85.78 1.000e+01 1.000e+01 -3.154e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 9.804e-04 9.804e-04 + Ca 4.934e-04 4.934e-04 + Fe 2.049e-08 2.049e-08 + S 6.308e-08 6.308e-08 + +----------------------------Description of solution---------------------------- + + pH = 8.279 Charge balance + pe = -4.943 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.463e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.867e-04 + Total CO2 (mol/kg) = 9.803e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.550867e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.987e-06 1.903e-06 -5.702 -5.720 -0.019 + H+ 5.476e-09 5.260e-09 -8.262 -8.279 -0.018 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +C(-4) 5.403e-08 + CH4 5.403e-08 5.405e-08 -7.267 -7.267 0.000 +C(4) 9.803e-04 + HCO3- 9.494e-04 9.104e-04 -3.023 -3.041 -0.018 + CO2 1.076e-05 1.077e-05 -4.968 -4.968 0.000 + CO3-2 9.603e-06 8.117e-06 -5.018 -5.091 -0.073 + CaCO3 5.563e-06 5.565e-06 -5.255 -5.255 0.000 + CaHCO3+ 4.943e-06 4.740e-06 -5.306 -5.324 -0.018 + FeCO3 2.600e-09 2.601e-09 -8.585 -8.585 0.000 + FeHCO3+ 1.269e-09 1.216e-09 -8.896 -8.915 -0.019 +Ca 4.934e-04 + Ca+2 4.829e-04 4.081e-04 -3.316 -3.389 -0.073 + CaCO3 5.563e-06 5.565e-06 -5.255 -5.255 0.000 + CaHCO3+ 4.943e-06 4.740e-06 -5.306 -5.324 -0.018 + CaOH+ 1.344e-08 1.288e-08 -7.872 -7.890 -0.019 + CaSO4 3.896e-09 3.897e-09 -8.409 -8.409 0.000 + CaHSO4+ 1.253e-16 1.201e-16 -15.902 -15.920 -0.019 +Fe(2) 2.049e-08 + Fe+2 1.578e-08 1.336e-08 -7.802 -7.874 -0.072 + FeCO3 2.600e-09 2.601e-09 -8.585 -8.585 0.000 + FeHCO3+ 1.269e-09 1.216e-09 -8.896 -8.915 -0.019 + FeOH+ 8.381e-10 8.031e-10 -9.077 -9.095 -0.019 + FeSO4 1.137e-13 1.137e-13 -12.944 -12.944 0.000 + Fe(HS)2 6.287e-17 6.289e-17 -16.202 -16.201 0.000 + FeHSO4+ 4.102e-21 3.931e-21 -20.387 -20.406 -0.019 + Fe(HS)3- 1.643e-23 1.574e-23 -22.784 -22.803 -0.019 +Fe(3) 3.369e-14 + Fe(OH)3 2.753e-14 2.754e-14 -13.560 -13.560 0.000 + Fe(OH)4- 4.984e-15 4.776e-15 -14.302 -14.321 -0.019 + Fe(OH)2+ 1.174e-15 1.124e-15 -14.931 -14.949 -0.019 + FeOH+2 2.119e-20 1.786e-20 -19.674 -19.748 -0.074 + Fe+3 2.091e-26 1.455e-26 -25.680 -25.837 -0.158 + FeSO4+ 7.970e-30 7.637e-30 -29.099 -29.117 -0.019 + Fe(SO4)2- 8.346e-36 7.997e-36 -35.079 -35.097 -0.019 + FeHSO4+2 1.276e-37 1.076e-37 -36.894 -36.968 -0.074 + Fe2(OH)2+4 1.700e-38 8.587e-39 -37.769 -38.066 -0.297 + Fe3(OH)4+5 0.000e+00 0.000e+00 -50.232 -50.695 -0.464 +H(0) 3.009e-10 + H2 1.505e-10 1.505e-10 -9.823 -9.822 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -72.735 -72.735 0.000 +S(-2) 2.505e-09 + HS- 2.399e-09 2.298e-09 -8.620 -8.639 -0.019 + H2S 1.057e-10 1.057e-10 -9.976 -9.976 0.000 + S-2 6.249e-14 5.278e-14 -13.204 -13.278 -0.073 + Fe(HS)2 6.287e-17 6.289e-17 -16.202 -16.201 0.000 + Fe(HS)3- 1.643e-23 1.574e-23 -22.784 -22.803 -0.019 +S(6) 6.057e-08 + SO4-2 5.668e-08 4.786e-08 -7.247 -7.320 -0.073 + CaSO4 3.896e-09 3.897e-09 -8.409 -8.409 0.000 + FeSO4 1.137e-13 1.137e-13 -12.944 -12.944 0.000 + HSO4- 2.554e-14 2.448e-14 -13.593 -13.611 -0.019 + CaHSO4+ 1.253e-16 1.201e-16 -15.902 -15.920 -0.019 + FeHSO4+ 4.102e-21 3.931e-21 -20.387 -20.406 -0.019 + FeSO4+ 7.970e-30 7.637e-30 -29.099 -29.117 -0.019 + Fe(SO4)2- 8.346e-36 7.997e-36 -35.079 -35.097 -0.019 + FeHSO4+2 1.276e-37 1.076e-37 -36.894 -36.968 -0.074 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -6.35 -10.71 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -4.41 -7.27 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 + FeS(ppt) -4.32 -8.23 -3.92 FeS + Goethite 0.00 -1.00 -1.00 FeOOH + Gypsum -6.13 -10.71 -4.58 CaSO4:2H2O + H2(g) -6.67 -9.82 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -8.98 -9.98 -1.00 H2S + Hematite 2.01 -2.00 -4.01 Fe2O3 + Mackinawite -3.59 -8.23 -4.65 FeS + Melanterite -12.99 -15.19 -2.21 FeSO4:7H2O + O2(g) -69.78 -72.74 -2.96 O2 + Pyrite 0.00 -18.48 -18.48 FeS2 + Siderite -2.07 -12.96 -10.89 FeCO3 + Sulfur -8.19 -3.30 4.88 S + +Reaction step 2. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 1.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + O2 1.00 + NaCl 0.50 + + Relative + Element moles + Cl 0.50 + Na 0.50 + O 2.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.999e+00 -9.277e-04 + CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 1.418e-04 + Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 2.667e-04 + Gypsum -2.02 -6.60 -4.58 0.000e+00 0.000e+00 + Pyrite 0.00 -85.78 -85.78 1.000e+01 1.000e+01 -2.667e-04 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 7.859e-04 7.859e-04 + Ca 9.277e-04 9.277e-04 + Cl 5.000e-04 5.000e-04 + Fe 9.939e-09 9.939e-09 + Na 5.000e-04 5.000e-04 + S 5.333e-04 5.333e-04 + +----------------------------Description of solution---------------------------- + + pH = 8.171 Charge balance + pe = -4.287 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.591e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 7.887e-04 + Total CO2 (mol/kg) = 7.859e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 24 + Total H = 1.110122e+02 + Total O = 5.551018e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.585e-06 1.484e-06 -5.800 -5.829 -0.029 + H+ 7.160e-09 6.745e-09 -8.145 -8.171 -0.026 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 2.240e-12 + CH4 2.240e-12 2.242e-12 -11.650 -11.649 0.000 +C(4) 7.859e-04 + HCO3- 7.565e-04 7.099e-04 -3.121 -3.149 -0.028 + CO2 1.076e-05 1.077e-05 -4.968 -4.968 0.000 + CaHCO3+ 6.477e-06 6.078e-06 -5.189 -5.216 -0.028 + CO3-2 6.364e-06 4.936e-06 -5.196 -5.307 -0.110 + CaCO3 5.560e-06 5.565e-06 -5.255 -5.255 0.000 + NaHCO3 1.865e-07 1.867e-07 -6.729 -6.729 0.000 + NaCO3- 4.587e-08 4.298e-08 -7.338 -7.367 -0.028 + FeCO3 7.363e-10 7.369e-10 -9.133 -9.133 0.000 + FeHCO3+ 4.715e-10 4.418e-10 -9.327 -9.355 -0.028 +Ca 9.277e-04 + Ca+2 8.657e-04 6.711e-04 -3.063 -3.173 -0.111 + CaSO4 4.996e-05 5.000e-05 -4.301 -4.301 0.000 + CaHCO3+ 6.477e-06 6.078e-06 -5.189 -5.216 -0.028 + CaCO3 5.560e-06 5.565e-06 -5.255 -5.255 0.000 + CaOH+ 1.762e-08 1.651e-08 -7.754 -7.782 -0.028 + CaHSO4+ 2.108e-12 1.976e-12 -11.676 -11.704 -0.028 +Cl 5.000e-04 + Cl- 5.000e-04 4.682e-04 -3.301 -3.330 -0.029 + FeCl+ 4.293e-12 4.023e-12 -11.367 -11.396 -0.028 + FeCl+2 5.629e-28 4.339e-28 -27.250 -27.363 -0.113 + FeCl2+ 9.686e-31 9.076e-31 -30.014 -30.042 -0.028 + FeCl3 4.246e-35 4.250e-35 -34.372 -34.372 0.000 +Fe(2) 9.939e-09 + Fe+2 8.002e-09 6.223e-09 -8.097 -8.206 -0.109 + FeCO3 7.363e-10 7.369e-10 -9.133 -9.133 0.000 + FeHCO3+ 4.715e-10 4.418e-10 -9.327 -9.355 -0.028 + FeSO4 4.129e-10 4.132e-10 -9.384 -9.384 0.000 + FeOH+ 3.114e-10 2.918e-10 -9.507 -9.535 -0.028 + FeCl+ 4.293e-12 4.023e-12 -11.367 -11.396 -0.028 + FeHSO4+ 1.955e-17 1.832e-17 -16.709 -16.737 -0.028 + Fe(HS)2 5.043e-18 5.047e-18 -17.297 -17.297 0.000 + Fe(HS)3- 5.596e-25 5.243e-25 -24.252 -24.280 -0.028 +Fe(3) 3.303e-14 + Fe(OH)3 2.752e-14 2.754e-14 -13.560 -13.560 0.000 + Fe(OH)4- 3.974e-15 3.724e-15 -14.401 -14.429 -0.028 + Fe(OH)2+ 1.539e-15 1.442e-15 -14.813 -14.841 -0.028 + FeOH+2 3.810e-20 2.937e-20 -19.419 -19.532 -0.113 + FeSO4+ 1.341e-25 1.256e-25 -24.873 -24.901 -0.028 + Fe+3 5.252e-26 3.069e-26 -25.280 -25.513 -0.233 + Fe(SO4)2- 1.095e-27 1.026e-27 -26.960 -26.989 -0.028 + FeCl+2 5.629e-28 4.339e-28 -27.250 -27.363 -0.113 + FeCl2+ 9.686e-31 9.076e-31 -30.014 -30.042 -0.028 + FeHSO4+2 2.943e-33 2.269e-33 -32.531 -32.644 -0.113 + FeCl3 4.246e-35 4.250e-35 -34.372 -34.372 0.000 + Fe2(OH)2+4 6.575e-38 2.322e-38 -37.182 -37.634 -0.452 + Fe3(OH)4+5 0.000e+00 0.000e+00 -49.449 -50.155 -0.706 +H(0) 2.414e-11 + H2 1.207e-11 1.208e-11 -10.918 -10.918 0.000 +Na 5.000e-04 + Na+ 4.988e-04 4.677e-04 -3.302 -3.330 -0.028 + NaSO4- 9.340e-07 8.752e-07 -6.030 -6.058 -0.028 + NaHCO3 1.865e-07 1.867e-07 -6.729 -6.729 0.000 + NaCO3- 4.587e-08 4.298e-08 -7.338 -7.367 -0.028 + NaOH 4.577e-10 4.581e-10 -9.339 -9.339 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -70.545 -70.544 0.000 +S(-2) 1.075e-09 + HS- 1.019e-09 9.540e-10 -8.992 -9.020 -0.029 + H2S 5.621e-11 5.626e-11 -10.250 -10.250 0.000 + S-2 2.207e-14 1.708e-14 -13.656 -13.767 -0.111 + Fe(HS)2 5.043e-18 5.047e-18 -17.297 -17.297 0.000 + Fe(HS)3- 5.596e-25 5.243e-25 -24.252 -24.280 -0.028 +S(6) 5.333e-04 + SO4-2 4.824e-04 3.734e-04 -3.317 -3.428 -0.111 + CaSO4 4.996e-05 5.000e-05 -4.301 -4.301 0.000 + NaSO4- 9.340e-07 8.752e-07 -6.030 -6.058 -0.028 + FeSO4 4.129e-10 4.132e-10 -9.384 -9.384 0.000 + HSO4- 2.613e-10 2.449e-10 -9.583 -9.611 -0.028 + CaHSO4+ 2.108e-12 1.976e-12 -11.676 -11.704 -0.028 + FeHSO4+ 1.955e-17 1.832e-17 -16.709 -16.737 -0.028 + FeSO4+ 1.341e-25 1.256e-25 -24.873 -24.901 -0.028 + Fe(SO4)2- 1.095e-27 1.026e-27 -26.960 -26.989 -0.028 + FeHSO4+2 2.943e-33 2.269e-33 -32.531 -32.644 -0.113 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -2.24 -6.60 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -8.79 -11.65 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 + FeS(ppt) -5.14 -9.06 -3.92 FeS + Goethite -0.00 -1.00 -1.00 FeOOH + Gypsum -2.02 -6.60 -4.58 CaSO4:2H2O + H2(g) -7.77 -10.92 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -9.25 -10.25 -1.00 H2S + Halite -8.24 -6.66 1.58 NaCl + Hematite 2.01 -2.00 -4.01 Fe2O3 + Mackinawite -4.41 -9.06 -4.65 FeS + Melanterite -9.42 -11.63 -2.21 FeSO4:7H2O + O2(g) -67.58 -70.54 -2.96 O2 + Pyrite -0.00 -18.48 -18.48 FeS2 + Siderite -2.62 -13.51 -10.89 FeCO3 + Sulfur -7.36 -2.48 4.88 S + +Reaction step 3. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 5.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + O2 1.00 + NaCl 0.50 + + Relative + Element moles + Cl 0.50 + Na 0.50 + O 2.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.997e+00 -2.937e-03 + CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 2.395e-03 + Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 1.333e-03 + Gypsum -1.06 -5.64 -4.58 0.000e+00 0.000e+00 + Pyrite 0.00 -85.78 -85.78 1.000e+01 9.999e+00 -1.333e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.424e-04 5.424e-04 + Ca 2.937e-03 2.937e-03 + Cl 2.500e-03 2.500e-03 + Fe 2.124e-08 2.124e-08 + Na 2.500e-03 2.500e-03 + S 2.667e-03 2.667e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.982 Charge balance + pe = -3.970 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.210e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.415e-04 + Total CO2 (mol/kg) = 5.424e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 25 + Total H = 1.110111e+02 + Total O = 5.551757e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.077e-06 9.604e-07 -5.968 -6.018 -0.050 + H+ 1.149e-08 1.042e-08 -7.940 -7.982 -0.042 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 2.129e-13 + CH4 2.129e-13 2.135e-13 -12.672 -12.671 0.001 +C(4) 5.424e-04 + HCO3- 5.118e-04 4.594e-04 -3.291 -3.338 -0.047 + CO2 1.074e-05 1.077e-05 -4.969 -4.968 0.001 + CaHCO3+ 1.046e-05 9.392e-06 -4.980 -5.027 -0.047 + CaCO3 5.549e-06 5.565e-06 -5.256 -5.255 0.001 + CO3-2 3.184e-06 2.067e-06 -5.497 -5.685 -0.188 + NaHCO3 5.724e-07 5.740e-07 -6.242 -6.241 0.001 + NaCO3- 9.566e-08 8.553e-08 -7.019 -7.068 -0.049 + FeHCO3+ 5.691e-10 5.088e-10 -9.245 -9.293 -0.049 + FeCO3 5.477e-10 5.493e-10 -9.261 -9.260 0.001 +Ca 2.937e-03 + Ca+2 2.469e-03 1.602e-03 -2.607 -2.795 -0.188 + CaSO4 4.520e-04 4.532e-04 -3.345 -3.344 0.001 + CaHCO3+ 1.046e-05 9.392e-06 -4.980 -5.027 -0.047 + CaCO3 5.549e-06 5.565e-06 -5.256 -5.255 0.001 + CaOH+ 2.854e-08 2.551e-08 -7.545 -7.593 -0.049 + CaHSO4+ 3.095e-11 2.767e-11 -10.509 -10.558 -0.049 +Cl 2.500e-03 + Cl- 2.500e-03 2.230e-03 -2.602 -2.652 -0.050 + FeCl+ 3.814e-11 3.410e-11 -10.419 -10.467 -0.049 + FeCl+2 1.194e-26 7.627e-27 -25.923 -26.118 -0.194 + FeCl2+ 8.499e-29 7.599e-29 -28.071 -28.119 -0.049 + FeCl3 1.690e-32 1.695e-32 -31.772 -31.771 0.001 +Fe(2) 2.124e-08 + Fe+2 1.693e-08 1.108e-08 -7.771 -7.956 -0.184 + FeSO4 2.784e-09 2.792e-09 -8.555 -8.554 0.001 + FeHCO3+ 5.691e-10 5.088e-10 -9.245 -9.293 -0.049 + FeCO3 5.477e-10 5.493e-10 -9.261 -9.260 0.001 + FeOH+ 3.758e-10 3.360e-10 -9.425 -9.474 -0.049 + FeCl+ 3.814e-11 3.410e-11 -10.419 -10.467 -0.049 + FeHSO4+ 2.139e-16 1.913e-16 -15.670 -15.718 -0.049 + Fe(HS)2 2.796e-18 2.804e-18 -17.553 -17.552 0.001 + Fe(HS)3- 1.820e-25 1.627e-25 -24.740 -24.789 -0.049 +Fe(3) 3.265e-14 + Fe(OH)3 2.746e-14 2.754e-14 -13.561 -13.560 0.001 + Fe(OH)4- 2.695e-15 2.409e-15 -14.569 -14.618 -0.049 + Fe(OH)2+ 2.492e-15 2.228e-15 -14.603 -14.652 -0.049 + FeOH+2 1.098e-19 7.014e-20 -18.960 -19.154 -0.194 + FeSO4+ 1.968e-24 1.760e-24 -23.706 -23.755 -0.049 + Fe+3 2.720e-25 1.132e-25 -24.566 -24.946 -0.381 + Fe(SO4)2- 6.105e-26 5.458e-26 -25.214 -25.263 -0.049 + FeCl+2 1.194e-26 7.627e-27 -25.923 -26.118 -0.194 + FeCl2+ 8.499e-29 7.599e-29 -28.071 -28.119 -0.049 + FeHSO4+2 7.686e-32 4.911e-32 -31.114 -31.309 -0.194 + FeCl3 1.690e-32 1.695e-32 -31.772 -31.771 0.001 + Fe2(OH)2+4 7.941e-37 1.324e-37 -36.100 -36.878 -0.778 + Fe3(OH)4+5 0.000e+00 0.000e+00 -47.995 -49.210 -1.216 +H(0) 1.338e-11 + H2 6.691e-12 6.710e-12 -11.174 -11.173 0.001 +Na 2.500e-03 + Na+ 2.482e-03 2.222e-03 -2.605 -2.653 -0.048 + NaSO4- 1.766e-05 1.579e-05 -4.753 -4.802 -0.049 + NaHCO3 5.724e-07 5.740e-07 -6.242 -6.241 0.001 + NaCO3- 9.566e-08 8.553e-08 -7.019 -7.068 -0.049 + NaOH 1.404e-09 1.408e-09 -8.853 -8.851 0.001 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -70.035 -70.034 0.001 +S(-2) 6.460e-10 + HS- 5.976e-10 5.329e-10 -9.224 -9.273 -0.050 + H2S 4.843e-11 4.856e-11 -10.315 -10.314 0.001 + S-2 9.562e-15 6.176e-15 -14.019 -14.209 -0.190 + Fe(HS)2 2.796e-18 2.804e-18 -17.553 -17.552 0.001 + Fe(HS)3- 1.820e-25 1.627e-25 -24.740 -24.789 -0.049 +S(6) 2.667e-03 + SO4-2 2.197e-03 1.418e-03 -2.658 -2.848 -0.190 + CaSO4 4.520e-04 4.532e-04 -3.345 -3.344 0.001 + NaSO4- 1.766e-05 1.579e-05 -4.753 -4.802 -0.049 + FeSO4 2.784e-09 2.792e-09 -8.555 -8.554 0.001 + HSO4- 1.606e-09 1.436e-09 -8.794 -8.843 -0.049 + CaHSO4+ 3.095e-11 2.767e-11 -10.509 -10.558 -0.049 + FeHSO4+ 2.139e-16 1.913e-16 -15.670 -15.718 -0.049 + FeSO4+ 1.968e-24 1.760e-24 -23.706 -23.755 -0.049 + Fe(SO4)2- 6.105e-26 5.458e-26 -25.214 -25.263 -0.049 + FeHSO4+2 7.686e-32 4.911e-32 -31.114 -31.309 -0.194 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -1.28 -5.64 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -9.81 -12.67 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 + FeS(ppt) -5.33 -9.25 -3.92 FeS + Goethite -0.00 -1.00 -1.00 FeOOH + Gypsum -1.06 -5.64 -4.58 CaSO4:2H2O + H2(g) -8.02 -11.17 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -9.32 -10.31 -1.00 H2S + Halite -6.89 -5.30 1.58 NaCl + Hematite 2.01 -2.00 -4.01 Fe2O3 + Mackinawite -4.60 -9.25 -4.65 FeS + Melanterite -8.60 -10.80 -2.21 FeSO4:7H2O + O2(g) -67.07 -70.03 -2.96 O2 + Pyrite -0.00 -18.48 -18.48 FeS2 + Siderite -2.75 -13.64 -10.89 FeCO3 + Sulfur -7.17 -2.29 4.88 S + +Reaction step 4. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 1.000e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + O2 1.00 + NaCl 0.50 + + Relative + Element moles + Cl 0.50 + Na 0.50 + O 2.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.994e+00 -5.559e-03 + CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.001e+01 5.105e-03 + Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 2.667e-03 + Gypsum -0.65 -5.23 -4.58 0.000e+00 0.000e+00 + Pyrite -0.00 -85.78 -85.78 1.000e+01 9.997e+00 -2.667e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.540e-04 4.540e-04 + Ca 5.560e-03 5.559e-03 + Cl 5.000e-03 5.000e-03 + Fe 3.429e-08 3.429e-08 + Na 5.000e-03 5.000e-03 + S 5.333e-03 5.333e-03 + +----------------------------Description of solution---------------------------- + + pH = 7.884 Charge balance + pe = -3.817 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.218e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.522e-04 + Total CO2 (mol/kg) = 4.540e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 25 + Total H = 1.110098e+02 + Total O = 5.552735e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 8.898e-07 7.665e-07 -6.051 -6.115 -0.065 + H+ 1.474e-08 1.306e-08 -7.832 -7.884 -0.053 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +C(-4) 7.696e-14 + CH4 7.696e-14 7.735e-14 -13.114 -13.112 0.002 +C(4) 4.540e-04 + HCO3- 4.210e-04 3.666e-04 -3.376 -3.436 -0.060 + CaHCO3+ 1.351e-05 1.177e-05 -4.869 -4.929 -0.060 + CO2 1.071e-05 1.077e-05 -4.970 -4.968 0.002 + CaCO3 5.536e-06 5.565e-06 -5.257 -5.255 0.002 + CO3-2 2.289e-06 1.317e-06 -5.640 -5.880 -0.240 + NaHCO3 8.791e-07 8.836e-07 -6.056 -6.054 0.002 + NaCO3- 1.214e-07 1.051e-07 -6.916 -6.978 -0.063 + FeHCO3+ 6.487e-10 5.616e-10 -9.188 -9.251 -0.063 + FeCO3 4.814e-10 4.839e-10 -9.317 -9.315 0.002 +Ca 5.560e-03 + Ca+2 4.373e-03 2.515e-03 -2.359 -2.599 -0.240 + CaSO4 1.168e-03 1.174e-03 -2.933 -2.930 0.002 + CaHCO3+ 1.351e-05 1.177e-05 -4.869 -4.929 -0.060 + CaCO3 5.536e-06 5.565e-06 -5.257 -5.255 0.002 + CaOH+ 3.692e-08 3.196e-08 -7.433 -7.495 -0.063 + CaHSO4+ 1.037e-10 8.977e-11 -9.984 -10.047 -0.063 +Cl 5.000e-03 + Cl- 5.000e-03 4.311e-03 -2.301 -2.365 -0.064 + FeCl+ 1.053e-10 9.114e-11 -9.978 -10.040 -0.063 + FeCl+2 5.162e-26 2.899e-26 -25.287 -25.538 -0.251 + FeCl2+ 6.449e-28 5.583e-28 -27.191 -27.253 -0.063 + FeCl3 2.394e-31 2.406e-31 -30.621 -30.619 0.002 +Fe(2) 3.429e-08 + Fe+2 2.629e-08 1.532e-08 -7.580 -7.815 -0.235 + FeSO4 6.337e-09 6.369e-09 -8.198 -8.196 0.002 + FeHCO3+ 6.487e-10 5.616e-10 -9.188 -9.251 -0.063 + FeCO3 4.814e-10 4.839e-10 -9.317 -9.315 0.002 + FeOH+ 4.284e-10 3.708e-10 -9.368 -9.431 -0.063 + FeCl+ 1.053e-10 9.114e-11 -9.978 -10.040 -0.063 + FeHSO4+ 6.314e-16 5.466e-16 -15.200 -15.262 -0.063 + Fe(HS)2 2.164e-18 2.175e-18 -17.665 -17.663 0.002 + Fe(HS)3- 1.092e-25 9.454e-26 -24.962 -25.024 -0.063 +Fe(3) 3.284e-14 + Fe(OH)3 2.739e-14 2.753e-14 -13.562 -13.560 0.002 + Fe(OH)2+ 3.224e-15 2.791e-15 -14.492 -14.554 -0.063 + Fe(OH)4- 2.221e-15 1.923e-15 -14.653 -14.716 -0.063 + FeOH+2 1.960e-19 1.101e-19 -18.708 -18.958 -0.251 + FeSO4+ 6.596e-24 5.710e-24 -23.181 -23.243 -0.063 + Fe+3 6.635e-25 2.227e-25 -24.178 -24.652 -0.474 + Fe(SO4)2- 3.374e-25 2.921e-25 -24.472 -24.534 -0.063 + FeCl+2 5.162e-26 2.899e-26 -25.287 -25.538 -0.251 + FeCl2+ 6.449e-28 5.583e-28 -27.191 -27.253 -0.063 + FeHSO4+2 3.555e-31 1.996e-31 -30.449 -30.700 -0.251 + FeCl3 2.394e-31 2.406e-31 -30.621 -30.619 0.002 + Fe2(OH)2+4 3.279e-36 3.263e-37 -35.484 -36.486 -1.002 + Fe3(OH)4+5 0.000e+00 0.000e+00 -47.155 -48.721 -1.566 +H(0) 1.036e-11 + H2 5.179e-12 5.205e-12 -11.286 -11.284 0.002 +Na 5.000e-03 + Na+ 4.941e-03 4.286e-03 -2.306 -2.368 -0.062 + NaSO4- 5.802e-05 5.023e-05 -4.236 -4.299 -0.063 + NaHCO3 8.791e-07 8.836e-07 -6.056 -6.054 0.002 + NaCO3- 1.214e-07 1.051e-07 -6.916 -6.978 -0.063 + NaOH 2.157e-09 2.168e-09 -8.666 -8.664 0.002 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -69.815 -69.813 0.002 +S(-2) 5.087e-10 + HS- 4.634e-10 3.992e-10 -9.334 -9.399 -0.065 + H2S 4.533e-11 4.557e-11 -10.344 -10.341 0.002 + S-2 6.474e-15 3.693e-15 -14.189 -14.433 -0.244 + Fe(HS)2 2.164e-18 2.175e-18 -17.665 -17.663 0.002 + Fe(HS)3- 1.092e-25 9.454e-26 -24.962 -25.024 -0.063 +S(6) 5.333e-03 + SO4-2 4.108e-03 2.338e-03 -2.386 -2.631 -0.245 + CaSO4 1.168e-03 1.174e-03 -2.933 -2.930 0.002 + NaSO4- 5.802e-05 5.023e-05 -4.236 -4.299 -0.063 + FeSO4 6.337e-09 6.369e-09 -8.198 -8.196 0.002 + HSO4- 3.429e-09 2.968e-09 -8.465 -8.527 -0.063 + CaHSO4+ 1.037e-10 8.977e-11 -9.984 -10.047 -0.063 + FeHSO4+ 6.314e-16 5.466e-16 -15.200 -15.262 -0.063 + FeSO4+ 6.596e-24 5.710e-24 -23.181 -23.243 -0.063 + Fe(SO4)2- 3.374e-25 2.921e-25 -24.472 -24.534 -0.063 + FeHSO4+2 3.555e-31 1.996e-31 -30.449 -30.700 -0.251 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.87 -5.23 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -10.25 -13.11 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 + FeS(ppt) -5.41 -9.33 -3.92 FeS + Goethite -0.00 -1.00 -1.00 FeOOH + Gypsum -0.65 -5.23 -4.58 CaSO4:2H2O + H2(g) -8.13 -11.28 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -9.34 -10.34 -1.00 H2S + Halite -6.32 -4.73 1.58 NaCl + Hematite 2.01 -2.00 -4.01 Fe2O3 + Mackinawite -4.68 -9.33 -4.65 FeS + Melanterite -8.24 -10.45 -2.21 FeSO4:7H2O + O2(g) -66.85 -69.81 -2.96 O2 + Pyrite -0.00 -18.48 -18.48 FeS2 + Siderite -2.81 -13.70 -10.89 FeCO3 + Sulfur -7.09 -2.21 4.88 S + +Reaction step 5. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 1. + + 5.000e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + O2 1.00 + NaCl 0.50 + + Relative + Element moles + Cl 0.50 + Na 0.50 + O 2.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.973e+00 -2.684e-02 + CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.003e+01 2.649e-02 + Goethite 0.00 12.02 12.02 1.000e+01 1.001e+01 1.333e-02 + Gypsum 0.00 -4.58 -4.58 0.000e+00 9.002e-03 9.002e-03 + Pyrite -0.00 -85.78 -85.78 1.000e+01 9.987e+00 -1.333e-02 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 3.526e-04 3.524e-04 + Ca 1.785e-02 1.784e-02 + Cl 2.501e-02 2.500e-02 + Fe 8.735e-08 8.732e-08 + Na 2.501e-02 2.500e-02 + S 1.767e-02 1.766e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.719 Charge balance + pe = -3.565 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 7.432e-02 + Mass of water (kg) = 9.996e-01 + Total alkalinity (eq/kg) = 3.499e-04 + Total CO2 (mol/kg) = 3.526e-04 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -4.778e-11 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 25 + Total H = 1.109631e+02 + Total O = 5.555309e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.681e-07 5.237e-07 -6.175 -6.281 -0.106 + H+ 2.279e-08 1.909e-08 -7.642 -7.719 -0.077 + H2O 5.551e+01 9.986e-01 1.744 -0.001 0.000 +C(-4) 1.534e-14 + CH4 1.534e-14 1.561e-14 -13.814 -13.807 0.007 +C(4) 3.526e-04 + HCO3- 3.108e-04 2.505e-04 -3.508 -3.601 -0.094 + CaHCO3+ 2.134e-05 1.720e-05 -4.671 -4.764 -0.094 + CO2 1.058e-05 1.077e-05 -4.975 -4.968 0.007 + CaCO3 5.470e-06 5.565e-06 -5.262 -5.255 0.007 + NaHCO3 2.706e-06 2.752e-06 -5.568 -5.560 0.007 + CO3-2 1.458e-06 6.155e-07 -5.836 -6.211 -0.374 + NaCO3- 2.804e-07 2.239e-07 -6.552 -6.650 -0.098 + FeHCO3+ 8.424e-10 6.727e-10 -9.074 -9.172 -0.098 + FeCO3 3.897e-10 3.964e-10 -9.409 -9.402 0.007 +Ca 1.785e-02 + Ca+2 1.266e-02 5.382e-03 -1.898 -2.269 -0.371 + CaSO4 5.162e-03 5.251e-03 -2.287 -2.280 0.007 + CaHCO3+ 2.134e-05 1.720e-05 -4.671 -4.764 -0.094 + CaCO3 5.470e-06 5.565e-06 -5.262 -5.255 0.007 + CaOH+ 5.853e-08 4.673e-08 -7.233 -7.330 -0.098 + CaHSO4+ 7.355e-10 5.872e-10 -9.133 -9.231 -0.098 +Cl 2.501e-02 + Cl- 2.501e-02 1.966e-02 -1.602 -1.706 -0.105 + FeCl+ 9.125e-10 7.286e-10 -9.040 -9.138 -0.098 + FeCl+2 1.019e-24 4.140e-25 -23.992 -24.383 -0.391 + FeCl2+ 4.553e-26 3.635e-26 -25.342 -25.439 -0.098 + FeCl3 7.025e-29 7.146e-29 -28.153 -28.146 0.007 +Fe(2) 8.735e-08 + Fe+2 6.170e-08 2.685e-08 -7.210 -7.571 -0.361 + FeSO4 2.295e-08 2.335e-08 -7.639 -7.632 0.007 + FeCl+ 9.125e-10 7.286e-10 -9.040 -9.138 -0.098 + FeHCO3+ 8.424e-10 6.727e-10 -9.074 -9.172 -0.098 + FeOH+ 5.563e-10 4.442e-10 -9.255 -9.352 -0.098 + FeCO3 3.897e-10 3.964e-10 -9.409 -9.402 0.007 + FeHSO4+ 3.669e-15 2.930e-15 -14.435 -14.533 -0.098 + Fe(HS)2 1.432e-18 1.457e-18 -17.844 -17.837 0.007 + Fe(HS)3- 4.903e-26 3.915e-26 -25.310 -25.407 -0.098 +Fe(3) 3.379e-14 + Fe(OH)3 2.704e-14 2.750e-14 -13.568 -13.561 0.007 + Fe(OH)2+ 5.111e-15 4.081e-15 -14.291 -14.389 -0.098 + Fe(OH)4- 1.644e-15 1.312e-15 -14.784 -14.882 -0.098 + FeOH+2 5.796e-19 2.356e-19 -18.237 -18.628 -0.391 + FeSO4+ 4.683e-23 3.739e-23 -22.329 -22.427 -0.098 + Fe(SO4)2- 5.010e-24 4.000e-24 -23.300 -23.398 -0.098 + Fe+3 3.432e-24 6.974e-25 -23.464 -24.156 -0.692 + FeCl+2 1.019e-24 4.140e-25 -23.992 -24.383 -0.391 + FeCl2+ 4.553e-26 3.635e-26 -25.342 -25.439 -0.098 + FeCl3 7.025e-29 7.146e-29 -28.153 -28.146 0.007 + FeHSO4+2 4.703e-30 1.911e-30 -29.328 -29.719 -0.391 + Fe2(OH)2+4 5.473e-35 1.494e-36 -34.262 -35.826 -1.564 + Fe3(OH)4+5 0.000e+00 0.000e+00 -45.451 -47.895 -2.444 +H(0) 6.856e-12 + H2 3.428e-12 3.487e-12 -11.465 -11.458 0.007 +Na 2.501e-02 + Na+ 2.441e-02 1.954e-02 -1.612 -1.709 -0.097 + NaSO4- 5.997e-04 4.788e-04 -3.222 -3.320 -0.098 + NaHCO3 2.706e-06 2.752e-06 -5.568 -5.560 0.007 + NaCO3- 2.804e-07 2.239e-07 -6.552 -6.650 -0.098 + NaOH 6.639e-09 6.753e-09 -8.178 -8.170 0.007 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -69.474 -69.466 0.007 +S(-2) 3.552e-10 + HS- 3.148e-10 2.467e-10 -9.502 -9.608 -0.106 + H2S 4.048e-11 4.118e-11 -10.393 -10.385 0.007 + S-2 3.777e-15 1.561e-15 -14.423 -14.807 -0.384 + Fe(HS)2 1.432e-18 1.457e-18 -17.844 -17.837 0.007 + Fe(HS)3- 4.903e-26 3.915e-26 -25.310 -25.407 -0.098 +S(6) 1.767e-02 + SO4-2 1.191e-02 4.890e-03 -1.924 -2.311 -0.387 + CaSO4 5.162e-03 5.251e-03 -2.287 -2.280 0.007 + NaSO4- 5.997e-04 4.788e-04 -3.222 -3.320 -0.098 + FeSO4 2.295e-08 2.335e-08 -7.639 -7.632 0.007 + HSO4- 1.137e-08 9.075e-09 -7.944 -8.042 -0.098 + CaHSO4+ 7.355e-10 5.872e-10 -9.133 -9.231 -0.098 + FeHSO4+ 3.669e-15 2.930e-15 -14.435 -14.533 -0.098 + FeSO4+ 4.683e-23 3.739e-23 -22.329 -22.427 -0.098 + Fe(SO4)2- 5.010e-24 4.000e-24 -23.300 -23.398 -0.098 + FeHSO4+2 4.703e-30 1.911e-30 -29.328 -29.719 -0.391 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Anhydrite -0.22 -4.58 -4.36 CaSO4 + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -10.95 -13.81 -2.86 CH4 + CO2(g) -3.50 -4.97 -1.47 CO2 + Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 + FeS(ppt) -5.54 -9.46 -3.92 FeS + Goethite 0.00 -1.00 -1.00 FeOOH + Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O + H2(g) -8.31 -11.46 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + H2S(g) -9.39 -10.39 -1.00 H2S + Halite -5.00 -3.42 1.58 NaCl + Hematite 2.01 -2.00 -4.01 Fe2O3 + Mackinawite -4.81 -9.46 -4.65 FeS + Melanterite -7.68 -9.89 -2.21 FeSO4:7H2O + O2(g) -66.51 -69.47 -2.96 O2 + Pyrite -0.00 -18.48 -18.48 FeS2 + Siderite -2.89 -13.78 -10.89 FeCO3 + Sulfur -6.96 -2.08 4.88 S + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex5.sel b/Sun/examples/ex5.sel new file mode 100644 index 00000000..a017da32 --- /dev/null +++ b/Sun/examples/ex5.sel @@ -0,0 +1,7 @@ + sim state soln dist_x time step pH pe Cl pyrite d_pyrite goethite d_goethite calcite d_calcite CO2(g) d_CO2(g) gypsum d_gypsum si_Gypsum + 1 i_soln 1 -99 -99 -99 7 4 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -999.9990 + 1 react 1 -99 0 1 8.27904 -4.94284 0.0000e+00 1.0000e+01 -3.1538e-08 1.0000e+01 1.1047e-08 9.9995e+00 -4.9340e-04 9.9995e+00 -4.8697e-04 0.0000e+00 0.0000e+00 -6.1283 + 1 react 1 -99 0 2 8.17103 -4.28707 5.0000e-04 9.9997e+00 -2.6667e-04 1.0000e+01 2.6666e-04 9.9991e+00 -9.2766e-04 1.0000e+01 1.4180e-04 0.0000e+00 0.0000e+00 -2.0202 + 1 react 1 -99 0 3 7.98207 -3.97043 2.5000e-03 9.9987e+00 -1.3333e-03 1.0001e+01 1.3333e-03 9.9971e+00 -2.9374e-03 1.0002e+01 2.3951e-03 0.0000e+00 0.0000e+00 -1.0629 + 1 react 1 -99 0 4 7.88418 -3.81741 5.0001e-03 9.9973e+00 -2.6667e-03 1.0003e+01 2.6666e-03 9.9944e+00 -5.5594e-03 1.0005e+01 5.1054e-03 0.0000e+00 0.0000e+00 -0.6499 + 1 react 1 -99 0 5 7.71922 -3.56545 2.5011e-02 9.9867e+00 -1.3333e-02 1.0013e+01 1.3333e-02 9.9732e+00 -2.6841e-02 1.0026e+01 2.6489e-02 9.0018e-03 9.0018e-03 0.0000 diff --git a/Sun/examples/ex6.log b/Sun/examples/ex6.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex6.out b/Sun/examples/ex6.out new file mode 100644 index 00000000..49aa2d56 --- /dev/null +++ b/Sun/examples/ex6.out @@ -0,0 +1,3053 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex6 + Output file: ex6.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 6A.--React to phase boundaries. + SOLUTION 1 PURE WATER + pH 7.0 charge + temp 25.0 + PHASES + Gibbsite + Al(OH)3 + 3 H+ = Al+3 + 3 H2O + log_k 8.049 + delta_h -22.792 kcal + Kaolinite + Al2Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 2 Al+3 + log_k 5.708 + delta_h -35.306 kcal + K-mica + KAl3Si3O10(OH)2 + 10 H+ = 3 Al+3 + 3 H4SiO4 + K+ + log_k 12.970 + delta_h -59.377 kcal + K-feldspar + KAlSi3O8 + 4 H2O + 4 H+ = Al+3 + 3 H4SiO4 + K+ + log_k 0.875 + delta_h -12.467 kcal + SELECTED_OUTPUT + file ex6A-B.sel + activities K+ H+ H4SiO4 + si Gibbsite Kaolinite K-mica K-feldspar + equilibrium_phases Gibbsite Kaolinite K-mica K-feldspar + END +----- +TITLE +----- + + Example 6A.--React to phase boundaries. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. PURE WATER + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Pure water + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.121e-18 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.121e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 2 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.001e-07 1.001e-07 -7.000 -7.000 -0.000 + H+ 1.001e-07 1.001e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +H(0) 1.417e-25 + H2 7.087e-26 7.087e-26 -25.150 -25.150 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.081 -42.081 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -39.12 -42.08 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + TITLE Example 6A1.--Find amount of K-feldspar dissolved to + reach gibbsite saturation. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 KAlSi3O8 10.0 + Kaolinite 0.0 0.0 + K-mica 0.0 0.0 + K-feldspar 0.0 0.0 + END +----- +TITLE +----- + + Example 6A1.--Find amount of K-feldspar dissolved to + reach gibbsite saturation. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.671e-08 + K-feldspar -14.68 -13.81 0.88 0.000e+00 0.000e+00 + K-mica -10.68 2.29 12.97 0.000e+00 0.000e+00 + Kaolinite -3.80 1.90 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 2.671e-08 2.671e-08 + K 2.671e-08 2.671e-08 + Si 8.013e-08 8.013e-08 + +----------------------------Description of solution---------------------------- + + pH = 7.006 Charge balance + pe = 11.468 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.262e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.068e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.300e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.016e-07 1.015e-07 -6.993 -6.993 -0.000 + H+ 9.865e-08 9.861e-08 -7.006 -7.006 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 2.671e-08 + Al(OH)4- 2.455e-08 2.454e-08 -7.610 -7.610 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 8.597e-10 8.594e-10 -9.066 -9.066 -0.000 + AlOH+2 1.083e-11 1.081e-11 -10.965 -10.966 -0.001 + Al+3 1.077e-13 1.073e-13 -12.968 -12.969 -0.002 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.099 -40.099 0.000 +K 2.671e-08 + K+ 2.671e-08 2.670e-08 -7.573 -7.574 -0.000 + KOH 9.388e-16 9.388e-16 -15.027 -15.027 0.000 +O(0) 1.314e-12 + O2 6.572e-13 6.572e-13 -12.182 -12.182 0.000 +Si 8.013e-08 + H4SiO4 8.001e-08 8.001e-08 -7.097 -7.097 0.000 + H3SiO4- 1.197e-10 1.196e-10 -9.922 -9.922 -0.000 + H2SiO4-2 8.267e-17 8.253e-17 -16.083 -16.083 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -3.55 -7.10 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -36.95 -40.10 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -14.68 -13.81 0.88 KAlSi3O8 + K-mica -10.68 2.29 12.97 KAl3Si3O10(OH)2 + Kaolinite -3.80 1.90 5.71 Al2Si2O5(OH)4 + O2(g) -9.22 -12.18 -2.96 O2 + Quartz -3.12 -7.10 -3.98 SiO2 + SiO2(a) -4.39 -7.10 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + TITLE Example 6A2.--Find amount of K-feldspar dissolved to + reach kaolinite saturation. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 0.0 + Kaolinite 0.0 KAlSi3O8 10.0 + K-mica 0.0 0.0 + K-feldspar 0.0 0.0 + END +----- +TITLE +----- + + Example 6A2.--Find amount of K-feldspar dissolved to + reach kaolinite saturation. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.00 8.05 8.05 0.000e+00 1.782e-06 1.782e-06 + K-feldspar -5.86 -4.99 0.88 0.000e+00 0.000e+00 + K-mica -1.86 11.11 12.97 0.000e+00 0.000e+00 + Kaolinite -0.00 5.71 5.71 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.179e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 3.968e-07 3.968e-07 + K 2.179e-06 2.179e-06 + Si 6.536e-06 6.536e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.212 Charge balance + pe = 9.894 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.185e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.369e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.876e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550623e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.636e-06 1.633e-06 -5.786 -5.787 -0.001 + H+ 6.141e-09 6.131e-09 -8.212 -8.212 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 3.968e-07 + Al(OH)4- 3.955e-07 3.948e-07 -6.403 -6.404 -0.001 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 5.352e-11 5.343e-11 -10.271 -10.272 -0.001 + AlOH+2 4.208e-14 4.179e-14 -13.376 -13.379 -0.003 + Al+3 2.620e-17 2.579e-17 -16.582 -16.588 -0.007 +H(0) 8.674e-40 + H2 4.337e-40 4.337e-40 -39.363 -39.363 0.000 +K 2.179e-06 + K+ 2.179e-06 2.175e-06 -5.662 -5.663 -0.001 + KOH 1.230e-12 1.230e-12 -11.910 -11.910 0.000 +O(0) 4.433e-14 + O2 2.216e-14 2.216e-14 -13.654 -13.654 0.000 +Si 6.536e-06 + H4SiO4 6.383e-06 6.383e-06 -5.195 -5.195 0.000 + H3SiO4- 1.538e-07 1.535e-07 -6.813 -6.814 -0.001 + H2SiO4-2 1.715e-12 1.703e-12 -11.766 -11.769 -0.003 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -1.64 -5.20 -3.55 SiO2 + Gibbsite -0.00 8.05 8.05 Al(OH)3 + H2(g) -36.21 -39.36 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -5.86 -4.99 0.88 KAlSi3O8 + K-mica -1.86 11.11 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -10.69 -13.65 -2.96 O2 + Quartz -1.21 -5.20 -3.98 SiO2 + SiO2(a) -2.48 -5.20 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + TITLE Example 6A3.--Find amount of K-feldspar dissolved to + reach K-mica saturation. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 0.0 + Kaolinite 0.0 0.0 + K-mica 0.0 KAlSi3O8 10.0 + K-feldspar 0.0 0.0 + END +----- +TITLE +----- + + Example 6A3.--Find amount of K-feldspar dissolved to + reach K-mica saturation. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.73 7.32 8.05 0.000e+00 0.000e+00 + K-feldspar -2.55 -1.67 0.88 0.000e+00 0.000e+00 + K-mica -0.00 12.97 12.97 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.001e-05 + Kaolinite 0.00 5.71 5.71 0.000e+00 9.715e-06 9.715e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.851e-07 5.851e-07 + K 2.001e-05 2.001e-05 + Si 4.062e-05 4.061e-05 + +----------------------------Description of solution---------------------------- + + pH = 9.109 Charge balance + pe = 9.063 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.002e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.177e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.710e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550629e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.293e-05 1.286e-05 -4.888 -4.891 -0.002 + H+ 7.822e-10 7.782e-10 -9.107 -9.109 -0.002 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.851e-07 + Al(OH)4- 5.849e-07 5.818e-07 -6.233 -6.235 -0.002 + Al(OH)3 2.402e-10 2.402e-10 -9.619 -9.619 0.000 + Al(OH)2+ 1.275e-12 1.269e-12 -11.894 -11.897 -0.002 + AlOH+2 1.286e-16 1.260e-16 -15.891 -15.900 -0.009 + Al+3 1.034e-20 9.870e-21 -19.985 -20.006 -0.020 +H(0) 6.411e-40 + H2 3.206e-40 3.206e-40 -39.494 -39.494 0.000 +K 2.001e-05 + K+ 2.001e-05 1.991e-05 -4.699 -4.701 -0.002 + KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 +O(0) 8.113e-14 + O2 4.057e-14 4.057e-14 -13.392 -13.392 0.000 +Si 4.062e-05 + H4SiO4 3.412e-05 3.412e-05 -4.467 -4.467 0.000 + H3SiO4- 6.498e-06 6.464e-06 -5.187 -5.189 -0.002 + H2SiO4-2 5.770e-10 5.651e-10 -9.239 -9.248 -0.009 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.48 7.32 10.80 Al(OH)3 + Chalcedony -0.92 -4.47 -3.55 SiO2 + Gibbsite -0.73 7.32 8.05 Al(OH)3 + H2(g) -36.34 -39.49 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -2.55 -1.67 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -10.43 -13.39 -2.96 O2 + Quartz -0.49 -4.47 -3.98 SiO2 + SiO2(a) -1.76 -4.47 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 5. +------------------------------------ + + TITLE Example 6A4.--Find amount of K-feldspar dissolved to + reach K-feldspar saturation. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 0.0 + Kaolinite 0.0 0.0 + K-mica 0.0 0.0 + K-feldspar 0.0 KAlSi3O8 10.0 + END +----- +TITLE +----- + + Example 6A4.--Find amount of K-feldspar dissolved to + reach K-feldspar saturation. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 + K-feldspar -0.00 0.87 0.88 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -1.909e-04 + K-mica -0.00 12.97 12.97 0.000e+00 6.361e-05 6.361e-05 + Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.990e-08 5.989e-08 + K 1.273e-04 1.273e-04 + Si 3.818e-04 3.818e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.389 Charge balance + pe = 8.719 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.273e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.275e-04 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.063e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.110123e+02 + Total O = 5.550698e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 + H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.990e-08 + Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 + Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 + Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 + AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 + Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 +H(0) 8.588e-40 + H2 4.294e-40 4.294e-40 -39.367 -39.367 0.000 +K 1.273e-04 + K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 + KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 +O(0) 4.521e-14 + O2 2.261e-14 2.261e-14 -13.646 -13.646 0.000 +Si 3.818e-04 + H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 + H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 + H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 + Chalcedony -0.00 -3.55 -3.55 SiO2 + Gibbsite -2.00 6.05 8.05 Al(OH)3 + H2(g) -36.22 -39.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -0.00 0.87 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 + O2(g) -10.69 -13.65 -2.96 O2 + Quartz 0.43 -3.55 -3.98 SiO2 + SiO2(a) -0.84 -3.55 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 6. +------------------------------------ + + TITLE Example 6A5.--Find point with kaolinite present, + but no gibbsite. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 KAlSi3O8 10.0 + Kaolinite 0.0 1.0 + END +----- +TITLE +----- + + Example 6A5.--Find point with kaolinite present, + but no gibbsite. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -3.023e-06 + Kaolinite -0.00 5.71 5.71 1.000e+00 1.000e+00 1.237e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.493e-07 5.493e-07 + K 3.023e-06 3.023e-06 + Si 6.596e-06 6.596e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.354 Charge balance + pe = 9.786 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.028e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.671e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.021e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550623e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.267e-06 2.262e-06 -5.645 -5.646 -0.001 + H+ 4.435e-09 4.426e-09 -8.353 -8.354 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.493e-07 + Al(OH)4- 5.480e-07 5.469e-07 -6.261 -6.262 -0.001 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 3.865e-11 3.857e-11 -10.413 -10.414 -0.001 + AlOH+2 2.196e-14 2.178e-14 -13.658 -13.662 -0.004 + Al+3 9.882e-18 9.704e-18 -17.005 -17.013 -0.008 +H(0) 7.444e-40 + H2 3.722e-40 3.722e-40 -39.429 -39.429 0.000 +K 3.023e-06 + K+ 3.023e-06 3.017e-06 -5.520 -5.520 -0.001 + KOH 2.364e-12 2.364e-12 -11.626 -11.626 0.000 +O(0) 6.019e-14 + O2 3.009e-14 3.009e-14 -13.522 -13.522 0.000 +Si 6.596e-06 + H4SiO4 6.383e-06 6.383e-06 -5.195 -5.195 0.000 + H3SiO4- 2.131e-07 2.127e-07 -6.671 -6.672 -0.001 + H2SiO4-2 3.295e-12 3.269e-12 -11.482 -11.486 -0.004 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -1.64 -5.20 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -36.28 -39.43 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -5.58 -4.70 0.88 KAlSi3O8 + K-mica -1.57 11.40 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -10.56 -13.52 -2.96 O2 + Quartz -1.21 -5.20 -3.98 SiO2 + SiO2(a) -2.48 -5.20 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 7. +------------------------------------ + + TITLE Example 6A6.--Find point with K-mica present, + but no kaolinite + USE solution 1 + EQUILIBRIUM_PHASES 1 + Kaolinite 0.0 KAlSi3O8 10.0 + K-mica 0.0 1.0 + END +----- +TITLE +----- + + Example 6A6.--Find point with K-mica present, + but no kaolinite + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + K-mica 0.00 12.97 12.97 1.000e+00 1.000e+00 1.079e-05 + Kaolinite 0.00 5.71 5.71 + KAlSi3O8 is reactant 1.000e+01 1.000e+01 -3.268e-05 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 3.263e-07 3.263e-07 + K 2.190e-05 2.190e-05 + Si 6.569e-05 6.569e-05 + +----------------------------Description of solution---------------------------- + + pH = 9.070 Charge balance + pe = 8.836 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.190e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.288e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.154e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550635e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.183e-05 1.176e-05 -4.927 -4.930 -0.002 + H+ 8.558e-10 8.512e-10 -9.068 -9.070 -0.002 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 3.263e-07 + Al(OH)4- 3.262e-07 3.244e-07 -6.487 -6.489 -0.002 + Al(OH)3 1.465e-10 1.465e-10 -9.834 -9.834 0.000 + Al(OH)2+ 8.509e-13 8.463e-13 -12.070 -12.072 -0.002 + AlOH+2 9.393e-17 9.191e-17 -16.027 -16.037 -0.009 + Al+3 8.269e-21 7.876e-21 -20.083 -20.104 -0.021 +H(0) 2.179e-39 + H2 1.089e-39 1.089e-39 -38.963 -38.963 0.000 +K 2.190e-05 + K+ 2.190e-05 2.178e-05 -4.660 -4.662 -0.002 + KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 +O(0) 7.024e-15 + O2 3.512e-15 3.512e-15 -14.454 -14.454 0.000 +Si 6.569e-05 + H4SiO4 5.595e-05 5.595e-05 -4.252 -4.252 0.000 + H3SiO4- 9.745e-06 9.692e-06 -5.011 -5.014 -0.002 + H2SiO4-2 7.916e-10 7.745e-10 -9.101 -9.111 -0.009 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.69 7.11 10.80 Al(OH)3 + Chalcedony -0.70 -4.25 -3.55 SiO2 + Gibbsite -0.94 7.11 8.05 Al(OH)3 + H2(g) -35.81 -38.96 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -2.12 -1.24 0.88 KAlSi3O8 + K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -11.49 -14.45 -2.96 O2 + Quartz -0.27 -4.25 -3.98 SiO2 + SiO2(a) -1.54 -4.25 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 8. +------------------------------------ + + TITLE Example 6B.--Path between phase boundaries. + USE solution 1 + EQUILIBRIUM_PHASES 1 + Kaolinite 0.0 0.0 + Gibbsite 0.0 0.0 + K-mica 0.0 0.0 + K-feldspar 0.0 0.0 + REACTION 1 + K-feldspar 1.0 + 0.04 0.08 0.16 0.32 0.64 1.0 2.0 4.0 + 8.0 16.0 32.0 64.0 100 200 umol + END +----- +TITLE +----- + + Example 6B.--Path between phase boundaries. + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 4.000e-08 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.00 8.05 8.05 0.000e+00 1.187e-08 1.187e-08 + K-feldspar -13.96 -13.08 0.88 0.000e+00 0.000e+00 + K-mica -9.95 3.02 12.97 0.000e+00 0.000e+00 + Kaolinite -3.45 2.25 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 2.813e-08 2.813e-08 + K 4.000e-08 4.000e-08 + Si 1.200e-07 1.200e-07 + +----------------------------Description of solution---------------------------- + + pH = 7.031 Charge balance + pe = 11.457 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.339e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.244e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.761e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.077e-07 1.076e-07 -6.968 -6.968 -0.000 + H+ 9.306e-08 9.302e-08 -7.031 -7.031 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 2.813e-08 + Al(OH)4- 2.603e-08 2.602e-08 -7.585 -7.585 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 8.110e-10 8.107e-10 -9.091 -9.091 -0.000 + AlOH+2 9.638e-12 9.621e-12 -11.016 -11.017 -0.001 + Al+3 9.044e-14 9.009e-14 -13.044 -13.045 -0.002 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.127 -40.127 0.000 +K 4.000e-08 + K+ 4.000e-08 3.998e-08 -7.398 -7.398 -0.000 + KOH 1.490e-15 1.490e-15 -14.827 -14.827 0.000 +O(0) 1.494e-12 + O2 7.470e-13 7.470e-13 -12.127 -12.127 0.000 +Si 1.200e-07 + H4SiO4 1.198e-07 1.198e-07 -6.922 -6.922 0.000 + H3SiO4- 1.900e-10 1.899e-10 -9.721 -9.721 -0.000 + H2SiO4-2 1.391e-16 1.389e-16 -15.857 -15.857 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -3.37 -6.92 -3.55 SiO2 + Gibbsite -0.00 8.05 8.05 Al(OH)3 + H2(g) -36.98 -40.13 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -13.96 -13.08 0.88 KAlSi3O8 + K-mica -9.95 3.02 12.97 KAl3Si3O10(OH)2 + Kaolinite -3.45 2.25 5.71 Al2Si2O5(OH)4 + O2(g) -9.17 -12.13 -2.96 O2 + Quartz -2.94 -6.92 -3.98 SiO2 + SiO2(a) -4.21 -6.92 -2.71 SiO2 + +Reaction step 2. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 8.000e-08 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.00 8.05 8.05 0.000e+00 4.713e-08 4.713e-08 + K-feldspar -12.68 -11.80 0.88 0.000e+00 0.000e+00 + K-mica -8.68 4.29 12.97 0.000e+00 0.000e+00 + Kaolinite -2.85 2.86 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 3.287e-08 3.287e-08 + K 8.000e-08 8.000e-08 + Si 2.400e-07 2.400e-07 + +----------------------------Description of solution---------------------------- + + pH = 7.106 Charge balance + pe = 11.288 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.591e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.786e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.120e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.278e-07 1.277e-07 -6.894 -6.894 -0.000 + H+ 7.842e-08 7.838e-08 -7.106 -7.106 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 3.287e-08 + Al(OH)4- 3.089e-08 3.088e-08 -7.510 -7.510 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 6.834e-10 6.831e-10 -9.165 -9.166 -0.000 + AlOH+2 6.845e-12 6.832e-12 -11.165 -11.165 -0.001 + Al+3 5.414e-14 5.391e-14 -13.267 -13.268 -0.002 +H(0) 2.308e-40 + H2 1.154e-40 1.154e-40 -39.938 -39.938 0.000 +K 8.000e-08 + K+ 8.000e-08 7.996e-08 -7.097 -7.097 -0.000 + KOH 3.537e-15 3.537e-15 -14.451 -14.451 0.000 +O(0) 6.262e-13 + O2 3.131e-13 3.131e-13 -12.504 -12.504 0.000 +Si 2.400e-07 + H4SiO4 2.395e-07 2.395e-07 -6.621 -6.621 0.000 + H3SiO4- 4.508e-10 4.506e-10 -9.346 -9.346 -0.000 + H2SiO4-2 3.918e-16 3.911e-16 -15.407 -15.408 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -3.07 -6.62 -3.55 SiO2 + Gibbsite -0.00 8.05 8.05 Al(OH)3 + H2(g) -36.79 -39.94 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -12.68 -11.80 0.88 KAlSi3O8 + K-mica -8.68 4.29 12.97 KAl3Si3O10(OH)2 + Kaolinite -2.85 2.86 5.71 Al2Si2O5(OH)4 + O2(g) -9.54 -12.50 -2.96 O2 + Quartz -2.64 -6.62 -3.98 SiO2 + SiO2(a) -3.91 -6.62 -2.71 SiO2 + +Reaction step 3. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 1.600e-07 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 0.000e+00 1.160e-07 1.160e-07 + K-feldspar -11.34 -10.47 0.88 0.000e+00 0.000e+00 + K-mica -7.34 5.63 12.97 0.000e+00 0.000e+00 + Kaolinite -2.25 3.46 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 4.398e-08 4.398e-08 + K 1.600e-07 1.600e-07 + Si 4.800e-07 4.800e-07 + +----------------------------Description of solution---------------------------- + + pH = 7.241 Charge balance + pe = 11.241 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.179e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.919e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.323e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.745e-07 1.744e-07 -6.758 -6.758 -0.000 + H+ 5.743e-08 5.740e-08 -7.241 -7.241 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 4.398e-08 + Al(OH)4- 4.219e-08 4.217e-08 -7.375 -7.375 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 5.005e-10 5.002e-10 -9.301 -9.301 -0.000 + AlOH+2 3.671e-12 3.663e-12 -11.435 -11.436 -0.001 + Al+3 2.127e-14 2.117e-14 -13.672 -13.674 -0.002 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.113 -40.113 0.000 +K 1.600e-07 + K+ 1.600e-07 1.599e-07 -6.796 -6.796 -0.000 + KOH 9.661e-15 9.661e-15 -14.015 -14.015 0.000 +O(0) 1.405e-12 + O2 7.025e-13 7.025e-13 -12.153 -12.153 0.000 +Si 4.800e-07 + H4SiO4 4.788e-07 4.788e-07 -6.320 -6.320 0.000 + H3SiO4- 1.231e-09 1.230e-09 -8.910 -8.910 -0.000 + H2SiO4-2 1.461e-15 1.458e-15 -14.835 -14.836 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -2.77 -6.32 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -36.96 -40.11 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -11.34 -10.47 0.88 KAlSi3O8 + K-mica -7.34 5.63 12.97 KAl3Si3O10(OH)2 + Kaolinite -2.25 3.46 5.71 Al2Si2O5(OH)4 + O2(g) -9.19 -12.15 -2.96 O2 + Quartz -2.34 -6.32 -3.98 SiO2 + SiO2(a) -3.61 -6.32 -2.71 SiO2 + +Reaction step 4. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 3.200e-07 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.00 8.05 8.05 0.000e+00 2.499e-07 2.499e-07 + K-feldspar -9.93 -9.05 0.88 0.000e+00 0.000e+00 + K-mica -5.93 7.04 12.97 0.000e+00 0.000e+00 + Kaolinite -1.65 4.06 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 7.007e-08 7.007e-08 + K 3.200e-07 3.200e-07 + Si 9.600e-07 9.600e-07 + +----------------------------Description of solution---------------------------- + + pH = 7.451 Charge balance + pe = 11.188 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 3.557e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.302e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.281e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.832e-07 2.830e-07 -6.548 -6.548 -0.000 + H+ 3.539e-08 3.537e-08 -7.451 -7.451 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 7.007e-08 + Al(OH)4- 6.848e-08 6.843e-08 -7.164 -7.165 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 3.085e-10 3.082e-10 -9.511 -9.511 -0.000 + AlOH+2 1.395e-12 1.391e-12 -11.855 -11.857 -0.001 + Al+3 4.984e-15 4.953e-15 -14.302 -14.305 -0.003 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.429 -40.429 0.000 +K 3.200e-07 + K+ 3.200e-07 3.198e-07 -6.495 -6.495 -0.000 + KOH 3.135e-14 3.135e-14 -13.504 -13.504 0.000 +O(0) 6.000e-12 + O2 3.000e-12 3.000e-12 -11.523 -11.523 0.000 +Si 9.600e-07 + H4SiO4 9.560e-07 9.560e-07 -6.020 -6.020 0.000 + H3SiO4- 3.988e-09 3.986e-09 -8.399 -8.400 -0.000 + H2SiO4-2 7.687e-15 7.665e-15 -14.114 -14.115 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -2.47 -6.02 -3.55 SiO2 + Gibbsite -0.00 8.05 8.05 Al(OH)3 + H2(g) -37.28 -40.43 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -9.93 -9.05 0.88 KAlSi3O8 + K-mica -5.93 7.04 12.97 KAl3Si3O10(OH)2 + Kaolinite -1.65 4.06 5.71 Al2Si2O5(OH)4 + O2(g) -8.56 -11.52 -2.96 O2 + Quartz -2.04 -6.02 -3.98 SiO2 + SiO2(a) -3.31 -6.02 -2.71 SiO2 + +Reaction step 5. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 6.400e-07 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 0.000e+00 5.130e-07 5.130e-07 + K-feldspar -8.47 -7.59 0.88 0.000e+00 0.000e+00 + K-mica -4.46 8.51 12.97 0.000e+00 0.000e+00 + Kaolinite -1.05 4.66 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.270e-07 1.270e-07 + K 6.400e-07 6.400e-07 + Si 1.920e-06 1.920e-06 + +----------------------------Description of solution---------------------------- + + pH = 7.715 Charge balance + pe = 10.994 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 6.595e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.021e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.096e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 5.193e-07 5.189e-07 -6.285 -6.285 -0.000 + H+ 1.931e-08 1.929e-08 -7.714 -7.715 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.270e-07 + Al(OH)4- 1.256e-07 1.254e-07 -6.901 -6.902 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 1.683e-10 1.681e-10 -9.774 -9.774 -0.000 + AlOH+2 4.155e-13 4.139e-13 -12.381 -12.383 -0.002 + Al+3 8.109e-16 8.040e-16 -15.091 -15.095 -0.004 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.567 -40.567 0.000 +K 6.400e-07 + K+ 6.400e-07 6.394e-07 -6.194 -6.194 -0.000 + KOH 1.149e-13 1.149e-13 -12.940 -12.940 0.000 +O(0) 1.135e-11 + O2 5.673e-12 5.673e-12 -11.246 -11.246 0.000 +Si 1.920e-06 + H4SiO4 1.905e-06 1.905e-06 -5.720 -5.720 0.000 + H3SiO4- 1.458e-08 1.456e-08 -7.836 -7.837 -0.000 + H2SiO4-2 5.153e-14 5.134e-14 -13.288 -13.290 -0.002 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -2.17 -5.72 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -37.42 -40.57 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -8.47 -7.59 0.88 KAlSi3O8 + K-mica -4.46 8.51 12.97 KAl3Si3O10(OH)2 + Kaolinite -1.05 4.66 5.71 Al2Si2O5(OH)4 + O2(g) -8.29 -11.25 -2.96 O2 + Quartz -1.74 -5.72 -3.98 SiO2 + SiO2(a) -3.01 -5.72 -2.71 SiO2 + +Reaction step 6. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 1.000e-06 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 0.000e+00 8.081e-07 8.081e-07 + K-feldspar -7.51 -6.64 0.88 0.000e+00 0.000e+00 + K-mica -3.51 9.46 12.97 0.000e+00 0.000e+00 + Kaolinite -0.67 5.04 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.919e-07 1.919e-07 + K 1.000e-06 1.000e-06 + Si 3.000e-06 3.000e-06 + +----------------------------Description of solution---------------------------- + + pH = 7.896 Charge balance + pe = 10.790 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.013e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.576e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.467e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 11 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.879e-07 7.870e-07 -6.104 -6.104 -0.001 + H+ 1.274e-08 1.272e-08 -7.895 -7.896 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.919e-07 + Al(OH)4- 1.905e-07 1.903e-07 -6.720 -6.721 -0.001 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 1.110e-10 1.109e-10 -9.955 -9.955 -0.001 + AlOH+2 1.808e-13 1.799e-13 -12.743 -12.745 -0.002 + Al+3 2.328e-16 2.304e-16 -15.633 -15.638 -0.005 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.520 -40.520 0.000 +K 1.000e-06 + K+ 1.000e-06 9.988e-07 -6.000 -6.001 -0.001 + KOH 2.723e-13 2.723e-13 -12.565 -12.565 0.000 +O(0) 9.161e-12 + O2 4.580e-12 4.580e-12 -11.339 -11.339 0.000 +Si 3.000e-06 + H4SiO4 2.966e-06 2.966e-06 -5.528 -5.528 0.000 + H3SiO4- 3.442e-08 3.438e-08 -7.463 -7.464 -0.001 + H2SiO4-2 1.847e-13 1.838e-13 -12.734 -12.736 -0.002 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -1.98 -5.53 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -37.37 -40.52 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -7.51 -6.64 0.88 KAlSi3O8 + K-mica -3.51 9.46 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.67 5.04 5.71 Al2Si2O5(OH)4 + O2(g) -8.38 -11.34 -2.96 O2 + Quartz -1.55 -5.53 -3.98 SiO2 + SiO2(a) -2.82 -5.53 -2.71 SiO2 + +Reaction step 7. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 2.000e-06 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 0.000e+00 1.633e-06 1.633e-06 + K-feldspar -6.04 -5.17 0.88 0.000e+00 0.000e+00 + K-mica -2.04 10.93 12.97 0.000e+00 0.000e+00 + Kaolinite -0.07 5.64 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 3.666e-07 3.666e-07 + K 2.000e-06 2.000e-06 + Si 6.000e-06 6.000e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.178 Charge balance + pe = 10.498 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.007e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.100e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.114e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 12 + Total H = 1.110124e+02 + Total O = 5.550623e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.511e-06 1.508e-06 -5.821 -5.822 -0.001 + H+ 6.648e-09 6.637e-09 -8.177 -8.178 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 3.666e-07 + Al(OH)4- 3.653e-07 3.647e-07 -6.437 -6.438 -0.001 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 5.794e-11 5.784e-11 -10.237 -10.238 -0.001 + AlOH+2 4.931e-14 4.898e-14 -13.307 -13.310 -0.003 + Al+3 3.322e-17 3.273e-17 -16.479 -16.485 -0.006 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -40.501 -40.501 0.000 +K 2.000e-06 + K+ 2.000e-06 1.997e-06 -5.699 -5.700 -0.001 + KOH 1.043e-12 1.043e-12 -11.982 -11.982 0.000 +O(0) 8.387e-12 + O2 4.194e-12 4.194e-12 -11.377 -11.377 0.000 +Si 6.000e-06 + H4SiO4 5.869e-06 5.869e-06 -5.231 -5.231 0.000 + H3SiO4- 1.306e-07 1.304e-07 -6.884 -6.885 -0.001 + H2SiO4-2 1.345e-12 1.336e-12 -11.871 -11.874 -0.003 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -1.68 -5.23 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -37.35 -40.50 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -6.04 -5.17 0.88 KAlSi3O8 + K-mica -2.04 10.93 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.07 5.64 5.71 Al2Si2O5(OH)4 + O2(g) -8.42 -11.38 -2.96 O2 + Quartz -1.25 -5.23 -3.98 SiO2 + SiO2(a) -2.52 -5.23 -2.71 SiO2 + +Reaction step 8. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 4.000e-06 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.11 7.94 8.05 0.000e+00 0.000e+00 + K-feldspar -5.11 -4.23 0.88 0.000e+00 0.000e+00 + K-mica -1.32 11.65 12.97 0.000e+00 0.000e+00 + Kaolinite -0.00 5.71 5.71 0.000e+00 1.712e-06 1.712e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.761e-07 5.761e-07 + K 4.000e-06 4.000e-06 + Si 8.576e-06 8.576e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.484 Charge balance + pe = 9.390 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.003e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.728e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.241e-17 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 12 + Total H = 1.110124e+02 + Total O = 5.550623e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.059e-06 3.051e-06 -5.514 -5.516 -0.001 + H+ 3.288e-09 3.281e-09 -8.483 -8.484 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.761e-07 + Al(OH)4- 5.751e-07 5.737e-07 -6.240 -6.241 -0.001 + Al(OH)3 9.987e-10 9.987e-10 -9.001 -9.001 0.000 + Al(OH)2+ 2.229e-11 2.224e-11 -10.652 -10.653 -0.001 + AlOH+2 9.396e-15 9.309e-15 -14.027 -14.031 -0.004 + Al+3 3.140e-18 3.074e-18 -17.503 -17.512 -0.009 +H(0) 2.529e-39 + H2 1.264e-39 1.264e-39 -38.898 -38.898 0.000 +K 4.000e-06 + K+ 4.000e-06 3.991e-06 -5.398 -5.399 -0.001 + KOH 4.218e-12 4.218e-12 -11.375 -11.375 0.000 +O(0) 5.215e-15 + O2 2.607e-15 2.607e-15 -14.584 -14.584 0.000 +Si 8.576e-06 + H4SiO4 8.206e-06 8.206e-06 -5.086 -5.086 0.000 + H3SiO4- 3.697e-07 3.688e-07 -6.432 -6.433 -0.001 + H2SiO4-2 7.719e-12 7.647e-12 -11.112 -11.116 -0.004 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.86 7.94 10.80 Al(OH)3 + Chalcedony -1.53 -5.09 -3.55 SiO2 + Gibbsite -0.11 7.94 8.05 Al(OH)3 + H2(g) -35.75 -38.90 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -5.11 -4.23 0.88 KAlSi3O8 + K-mica -1.32 11.65 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -11.62 -14.58 -2.96 O2 + Quartz -1.11 -5.09 -3.98 SiO2 + SiO2(a) -2.37 -5.09 -2.71 SiO2 + +Reaction step 9. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 8.000e-06 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.38 7.67 8.05 0.000e+00 0.000e+00 + K-feldspar -3.97 -3.10 0.88 0.000e+00 0.000e+00 + K-mica -0.73 12.24 12.97 0.000e+00 0.000e+00 + Kaolinite -0.00 5.71 5.71 0.000e+00 3.695e-06 3.695e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 6.110e-07 6.110e-07 + K 8.000e-06 8.000e-06 + Si 1.661e-05 1.661e-05 + +----------------------------Description of solution---------------------------- + + pH = 8.779 Charge balance + pe = 9.506 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.002e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.833e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.133e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550625e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.035e-06 6.015e-06 -5.219 -5.221 -0.001 + H+ 1.670e-09 1.664e-09 -8.777 -8.779 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 6.110e-07 + Al(OH)4- 6.105e-07 6.084e-07 -6.214 -6.216 -0.001 + Al(OH)3 5.373e-10 5.373e-10 -9.270 -9.270 0.000 + Al(OH)2+ 6.089e-12 6.069e-12 -11.215 -11.217 -0.001 + AlOH+2 1.306e-15 1.289e-15 -14.884 -14.890 -0.006 + Al+3 2.224e-19 2.159e-19 -18.653 -18.666 -0.013 +H(0) 3.823e-40 + H2 1.911e-40 1.911e-40 -39.719 -39.719 0.000 +K 8.000e-06 + K+ 8.000e-06 7.974e-06 -5.097 -5.098 -0.001 + KOH 1.661e-11 1.661e-11 -10.780 -10.780 0.000 +O(0) 2.282e-13 + O2 1.141e-13 1.141e-13 -12.943 -12.943 0.000 +Si 1.661e-05 + H4SiO4 1.525e-05 1.525e-05 -4.817 -4.817 0.000 + H3SiO4- 1.356e-06 1.352e-06 -5.868 -5.869 -0.001 + H2SiO4-2 5.598e-11 5.524e-11 -10.252 -10.258 -0.006 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.13 7.67 10.80 Al(OH)3 + Chalcedony -1.27 -4.82 -3.55 SiO2 + Gibbsite -0.38 7.67 8.05 Al(OH)3 + H2(g) -36.57 -39.72 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -3.97 -3.10 0.88 KAlSi3O8 + K-mica -0.73 12.24 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -9.98 -12.94 -2.96 O2 + Quartz -0.84 -4.82 -3.98 SiO2 + SiO2(a) -2.10 -4.82 -2.71 SiO2 + +Reaction step 10. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 1.600e-05 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.64 7.41 8.05 0.000e+00 0.000e+00 + K-feldspar -2.89 -2.01 0.88 0.000e+00 0.000e+00 + K-mica -0.17 12.80 12.97 0.000e+00 0.000e+00 + Kaolinite 0.00 5.71 5.71 0.000e+00 7.701e-06 7.701e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.987e-07 5.987e-07 + K 1.600e-05 1.600e-05 + Si 3.260e-05 3.260e-05 + +----------------------------Description of solution---------------------------- + + pH = 9.035 Charge balance + pe = 8.801 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.600e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.780e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.512e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550628e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.089e-05 1.084e-05 -4.963 -4.965 -0.002 + H+ 9.275e-10 9.232e-10 -9.033 -9.035 -0.002 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.987e-07 + Al(OH)4- 5.984e-07 5.956e-07 -6.223 -6.225 -0.002 + Al(OH)3 2.918e-10 2.918e-10 -9.535 -9.535 0.000 + Al(OH)2+ 1.837e-12 1.828e-12 -11.736 -11.738 -0.002 + AlOH+2 2.194e-16 2.153e-16 -15.659 -15.667 -0.008 + Al+3 2.087e-20 2.001e-20 -19.681 -19.699 -0.018 +H(0) 3.011e-39 + H2 1.505e-39 1.505e-39 -38.822 -38.822 0.000 +K 1.600e-05 + K+ 1.600e-05 1.593e-05 -4.796 -4.798 -0.002 + KOH 5.981e-11 5.981e-11 -10.223 -10.223 0.000 +O(0) 3.679e-15 + O2 1.840e-15 1.840e-15 -14.735 -14.735 0.000 +Si 3.260e-05 + H4SiO4 2.809e-05 2.809e-05 -4.551 -4.551 0.000 + H3SiO4- 4.508e-06 4.487e-06 -5.346 -5.348 -0.002 + H2SiO4-2 3.368e-10 3.306e-10 -9.473 -9.481 -0.008 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.39 7.41 10.80 Al(OH)3 + Chalcedony -1.00 -4.55 -3.55 SiO2 + Gibbsite -0.64 7.41 8.05 Al(OH)3 + H2(g) -35.67 -38.82 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -2.89 -2.01 0.88 KAlSi3O8 + K-mica -0.17 12.80 12.97 KAl3Si3O10(OH)2 + Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -11.78 -14.74 -2.96 O2 + Quartz -0.57 -4.55 -3.98 SiO2 + SiO2(a) -1.84 -4.55 -2.71 SiO2 + +Reaction step 11. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 3.200e-05 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.93 7.12 8.05 0.000e+00 0.000e+00 + K-feldspar -2.14 -1.26 0.88 0.000e+00 0.000e+00 + K-mica -0.00 12.97 12.97 0.000e+00 1.020e-05 1.020e-05 + Kaolinite 0.00 5.71 5.71 0.000e+00 5.270e-07 5.270e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 3.349e-07 3.349e-07 + K 2.180e-05 2.180e-05 + Si 6.434e-05 6.433e-05 + +----------------------------Description of solution---------------------------- + + pH = 9.072 Charge balance + pe = 8.977 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.180e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.280e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 2.694e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 13 + Total H = 1.110124e+02 + Total O = 5.550635e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.188e-05 1.182e-05 -4.925 -4.928 -0.002 + H+ 8.519e-10 8.473e-10 -9.070 -9.072 -0.002 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 3.349e-07 + Al(OH)4- 3.348e-07 3.330e-07 -6.475 -6.478 -0.002 + Al(OH)3 1.497e-10 1.497e-10 -9.825 -9.825 0.000 + Al(OH)2+ 8.654e-13 8.607e-13 -12.063 -12.065 -0.002 + AlOH+2 9.510e-17 9.305e-17 -16.022 -16.031 -0.009 + Al+3 8.332e-21 7.937e-21 -20.079 -20.100 -0.021 +H(0) 1.127e-39 + H2 5.637e-40 5.637e-40 -39.249 -39.249 0.000 +K 2.180e-05 + K+ 2.180e-05 2.168e-05 -4.662 -4.664 -0.002 + KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 +O(0) 2.624e-14 + O2 1.312e-14 1.312e-14 -13.882 -13.882 0.000 +Si 6.434e-05 + H4SiO4 5.475e-05 5.475e-05 -4.262 -4.262 0.000 + H3SiO4- 9.581e-06 9.529e-06 -5.019 -5.021 -0.002 + H2SiO4-2 7.819e-10 7.650e-10 -9.107 -9.116 -0.009 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.68 7.12 10.80 Al(OH)3 + Chalcedony -0.71 -4.26 -3.55 SiO2 + Gibbsite -0.93 7.12 8.05 Al(OH)3 + H2(g) -36.10 -39.25 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -2.14 -1.26 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -10.92 -13.88 -2.96 O2 + Quartz -0.28 -4.26 -3.98 SiO2 + SiO2(a) -1.55 -4.26 -2.71 SiO2 + +Reaction step 12. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 6.400e-05 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -1.35 6.69 8.05 0.000e+00 0.000e+00 + K-feldspar -1.29 -0.42 0.88 0.000e+00 0.000e+00 + K-mica 0.00 12.97 12.97 0.000e+00 2.127e-05 2.127e-05 + Kaolinite -0.30 5.41 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.812e-07 1.812e-07 + K 4.273e-05 4.273e-05 + Si 1.282e-04 1.282e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.225 Charge balance + pe = 8.690 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 4.273e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.327e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.000e-13 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 21 + Total H = 1.110124e+02 + Total O = 5.550647e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.694e-05 1.681e-05 -4.771 -4.774 -0.003 + H+ 5.999e-10 5.954e-10 -9.222 -9.225 -0.003 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.812e-07 + Al(OH)4- 1.812e-07 1.798e-07 -6.742 -6.745 -0.003 + Al(OH)3 5.680e-11 5.680e-11 -10.246 -10.246 0.000 + Al(OH)2+ 2.313e-13 2.295e-13 -12.636 -12.639 -0.003 + AlOH+2 1.797e-17 1.744e-17 -16.745 -16.759 -0.013 + Al+3 1.118e-21 1.045e-21 -20.951 -20.981 -0.029 +H(0) 2.093e-39 + H2 1.046e-39 1.046e-39 -38.980 -38.980 0.000 +K 4.273e-05 + K+ 4.273e-05 4.240e-05 -4.369 -4.373 -0.003 + KOH 2.469e-10 2.469e-10 -9.607 -9.607 0.000 +O(0) 7.616e-15 + O2 3.808e-15 3.808e-15 -14.419 -14.419 0.000 +Si 1.282e-04 + H4SiO4 1.026e-04 1.026e-04 -3.989 -3.989 0.000 + H3SiO4- 2.560e-05 2.540e-05 -4.592 -4.595 -0.003 + H2SiO4-2 2.992e-09 2.902e-09 -8.524 -8.537 -0.013 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.11 6.69 10.80 Al(OH)3 + Chalcedony -0.44 -3.99 -3.55 SiO2 + Gibbsite -1.35 6.69 8.05 Al(OH)3 + H2(g) -35.83 -38.98 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -1.29 -0.42 0.88 KAlSi3O8 + K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.30 5.41 5.71 Al2Si2O5(OH)4 + O2(g) -11.46 -14.42 -2.96 O2 + Quartz -0.01 -3.99 -3.98 SiO2 + SiO2(a) -1.28 -3.99 -2.71 SiO2 + +Reaction step 13. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 1.000e-04 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -1.62 6.43 8.05 0.000e+00 0.000e+00 + K-feldspar -0.76 0.11 0.88 0.000e+00 0.000e+00 + K-mica 0.00 12.97 12.97 0.000e+00 3.329e-05 3.329e-05 + Kaolinite -0.48 5.23 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.179e-07 1.179e-07 + K 6.671e-05 6.671e-05 + Si 2.001e-04 2.001e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.305 Charge balance + pe = 8.570 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 6.671e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 6.706e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.012e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.550662e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.038e-05 2.019e-05 -4.691 -4.695 -0.004 + H+ 5.006e-10 4.959e-10 -9.301 -9.305 -0.004 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.179e-07 + Al(OH)4- 1.179e-07 1.167e-07 -6.929 -6.933 -0.004 + Al(OH)3 3.072e-11 3.072e-11 -10.513 -10.513 0.000 + Al(OH)2+ 1.044e-13 1.034e-13 -12.981 -12.985 -0.004 + AlOH+2 6.796e-18 6.543e-18 -17.168 -17.184 -0.016 + Al+3 3.554e-22 3.267e-22 -21.449 -21.486 -0.037 +H(0) 2.521e-39 + H2 1.260e-39 1.260e-39 -38.899 -38.899 0.000 +K 6.671e-05 + K+ 6.671e-05 6.608e-05 -4.176 -4.180 -0.004 + KOH 4.620e-10 4.620e-10 -9.335 -9.335 0.000 +O(0) 5.248e-15 + O2 2.624e-15 2.624e-15 -14.581 -14.581 0.000 +Si 2.001e-04 + H4SiO4 1.539e-04 1.539e-04 -3.813 -3.813 0.000 + H3SiO4- 4.620e-05 4.576e-05 -4.335 -4.339 -0.004 + H2SiO4-2 6.519e-09 6.277e-09 -8.186 -8.202 -0.016 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.37 6.43 10.80 Al(OH)3 + Chalcedony -0.26 -3.81 -3.55 SiO2 + Gibbsite -1.62 6.43 8.05 Al(OH)3 + H2(g) -35.75 -38.90 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -0.76 0.11 0.88 KAlSi3O8 + K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.48 5.23 5.71 Al2Si2O5(OH)4 + O2(g) -11.62 -14.58 -2.96 O2 + Quartz 0.17 -3.81 -3.98 SiO2 + SiO2(a) -1.10 -3.81 -2.71 SiO2 + +Reaction step 14. + +Using solution 1. PURE WATER +Using pure phase assemblage 1. +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 8. + + 2.000e-04 moles of the following reaction have been added: + + Relative + Reactant moles + + K-feldspar 1.00 + + Relative + Element moles + Al 1.00 + K 1.00 + O 8.00 + Si 3.00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 + K-feldspar 0.00 0.88 0.88 0.000e+00 9.120e-06 9.120e-06 + K-mica -0.00 12.97 12.97 0.000e+00 6.361e-05 6.361e-05 + Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.990e-08 5.989e-08 + K 1.273e-04 1.273e-04 + Si 3.818e-04 3.818e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.389 Charge balance + pe = 8.947 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.273e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.275e-04 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.728e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 15 + Total H = 1.110123e+02 + Total O = 5.550698e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 + H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.990e-08 + Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 + Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 + Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 + AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 + Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 +H(0) 3.013e-40 + H2 1.507e-40 1.507e-40 -39.822 -39.822 0.000 +K 1.273e-04 + K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 + KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 +O(0) 3.673e-13 + O2 1.836e-13 1.836e-13 -12.736 -12.736 0.000 +Si 3.818e-04 + H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 + H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 + H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 + Chalcedony -0.00 -3.55 -3.55 SiO2 + Gibbsite -2.00 6.05 8.05 Al(OH)3 + H2(g) -36.67 -39.82 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar 0.00 0.88 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 + O2(g) -9.78 -12.74 -2.96 O2 + Quartz 0.43 -3.55 -3.98 SiO2 + SiO2(a) -0.84 -3.55 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 9. +------------------------------------ + + TITLE Example 6C.--kinetic calculation + SOLUTION 1 + units mol/kgw + Al 1.e-13 + K 1.e-13 + Si 3.e-13 + EQUILIBRIUM_PHASES 1 + Gibbsite 0.0 0.0 + Kaolinite 0.0 0.0 + K-mica 0.0 0.0 + KINETICS 1 + K-feldspar + parms 1.36e-11 + m0 2.16 + m 1.94 + step_divide 1e-6 + steps 1e2 1e3 1e4 1e5 1e6 1e7 1e8 + INCREMENTAL_REACTIONS true + RATES + K-feldspar + start + 10 REM store the initial amount of K-feldspar + 20 IF EXISTS(1) = 0 THEN PUT(M, 1) + 30 REM calculate moles of reaction + 40 SR_kfld = SR("K-feldspar") + 50 moles = PARM(1) * (M/M0)^0.67 * (1 - SR_kfld) * TIME + 60 REM The following is for printout of phase transitions + 80 REM Start Gibbsite + 90 if ABS(SI("Gibbsite")) > 1e-3 THEN GOTO 150 + 100 i = 2 + 110 GOSUB 1500 + 150 REM Start Gibbsite -> Kaolinite + 160 if ABS(SI("Kaolinite")) > 1e-3 THEN GOTO 200 + 170 i = 3 + 180 GOSUB 1500 + 200 REM End Gibbsite -> Kaolinite + 210 if ABS(SI("Kaolinite")) > 1e-3 OR EQUI("Gibbsite") > 0 THEN GOTO 250 + 220 i = 4 + 230 GOSUB 1500 + 250 REM Start Kaolinite -> K-mica + 260 if ABS(SI("K-mica")) > 1e-3 THEN GOTO 300 + 270 i = 5 + 280 GOSUB 1500 + 300 REM End Kaolinite -> K-mica + 310 if ABS(SI("K-mica")) > 1e-3 OR EQUI("Kaolinite") > 0 THEN GOTO 350 + 320 i = 6 + 330 GOSUB 1500 + 350 REM Start K-mica -> K-feldspar + 360 if ABS(SI("K-feldspar")) > 1e-3 THEN GOTO 1000 + 370 i = 7 + 380 GOSUB 1500 + 1000 SAVE moles + 1010 END + 1500 REM subroutine to store data + 1510 if GET(i) >= M THEN RETURN + 1520 PUT(M, i) + 1530 PUT(TOTAL_TIME, i, 1) + 1540 PUT(LA("K+")-LA("H+"), i, 2) + 1550 PUT(LA("H4SiO4"), i, 3) + 1560 RETURN + end + USER_PRINT + 10 DATA "A: Gibbsite ", "B: Gibbsite -> Kaolinite ", "C: Gibbsite -> Kaolinite ", "D: Kaolinite -> K-mica ", "E: Kaolinite -> K-mica ", "F: K-mica -> K-feldspar" + 20 PRINT " Transition Time K-feldspar LA(K/H) LA(H4SiO4)" + 30 PRINT " reacted" + 40 PRINT " (moles)" + 50 FOR i = 2 TO 7 + 60 READ s$ + 70 IF EXISTS(i) THEN PRINT s$, GET(i,1), GET(1) - GET(i), GET(i,2), GET(i,3) + 80 NEXT i + SELECTED_OUTPUT + file ex6C.sel + reset false + USER_PUNCH + heading pH+log[K] log[H4SiO4] + 10 PUNCH LA("K+")-LA("H+") LA("H4SiO4") + END +----- +TITLE +----- + + Example 6C.--kinetic calculation + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.000e-13 1.000e-13 + K 1.000e-13 1.000e-13 + Si 3.000e-13 3.000e-13 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.086e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 3 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.001e-07 1.001e-07 -6.999 -7.000 -0.000 + H+ 1.000e-07 1.000e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.000e-13 + Al(OH)4- 9.178e-14 9.175e-14 -13.037 -13.037 -0.000 + Al(OH)3 4.868e-15 4.868e-15 -14.313 -14.313 0.000 + Al(OH)2+ 3.305e-15 3.304e-15 -14.481 -14.481 -0.000 + AlOH+2 4.222e-17 4.215e-17 -16.375 -16.375 -0.001 + Al+3 4.258e-19 4.244e-19 -18.371 -18.372 -0.001 +H(0) 1.416e-25 + H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 +K 1.000e-13 + K+ 1.000e-13 9.996e-14 -13.000 -13.000 -0.000 + KOH 3.466e-21 3.466e-21 -20.460 -20.460 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 +Si 3.000e-13 + H4SiO4 2.996e-13 2.996e-13 -12.524 -12.524 0.000 + H3SiO4- 4.419e-16 4.417e-16 -15.355 -15.355 -0.000 + H2SiO4-2 3.009e-22 3.005e-22 -21.522 -21.522 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -8.17 2.63 10.80 Al(OH)3 + Chalcedony -8.97 -12.52 -3.55 SiO2 + Gibbsite -5.42 2.63 8.05 Al(OH)3 + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -41.82 -40.94 0.88 KAlSi3O8 + K-mica -48.66 -35.69 12.97 KAl3Si3O10(OH)2 + Kaolinite -25.50 -19.79 5.71 Al2Si2O5(OH)4 + O2(g) -39.12 -42.08 -2.96 O2 + Quartz -8.54 -12.52 -3.98 SiO2 + SiO2(a) -9.81 -12.52 -2.71 SiO2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 100 seconds (Incremented time: 100 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.266e-09 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -1.32 6.73 8.05 0.000e+00 0.000e+00 + K-mica -19.94 -6.97 12.97 0.000e+00 0.000e+00 + Kaolinite -9.09 -3.38 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.266e-09 1.266e-09 + K 1.266e-09 1.266e-09 + Si 3.797e-09 3.797e-09 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 11.049 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.013e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.171e-09 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 35 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.002e-07 1.002e-07 -6.999 -6.999 -0.000 + H+ 9.997e-08 9.993e-08 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.266e-09 + Al(OH)4- 1.162e-09 1.161e-09 -8.935 -8.935 -0.000 + Al(OH)3 6.157e-11 6.157e-11 -10.211 -10.211 0.000 + Al(OH)2+ 4.178e-11 4.176e-11 -10.379 -10.379 -0.000 + AlOH+2 5.332e-13 5.324e-13 -12.273 -12.274 -0.001 + Al+3 5.375e-15 5.356e-15 -14.270 -14.271 -0.001 +H(0) 1.128e-39 + H2 5.642e-40 5.642e-40 -39.249 -39.249 0.000 +K 1.266e-09 + K+ 1.266e-09 1.265e-09 -8.898 -8.898 -0.000 + KOH 4.390e-17 4.390e-17 -16.358 -16.358 0.000 +O(0) 2.619e-14 + O2 1.309e-14 1.309e-14 -13.883 -13.883 0.000 +Si 3.797e-09 + H4SiO4 3.791e-09 3.791e-09 -8.421 -8.421 0.000 + H3SiO4- 5.596e-12 5.594e-12 -11.252 -11.252 -0.000 + H2SiO4-2 3.814e-18 3.808e-18 -17.419 -17.419 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.07 6.73 10.80 Al(OH)3 + Chalcedony -4.87 -8.42 -3.55 SiO2 + Gibbsite -1.32 6.73 8.05 Al(OH)3 + H2(g) -36.10 -39.25 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -21.31 -20.43 0.88 KAlSi3O8 + K-mica -19.94 -6.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -9.09 -3.38 5.71 Al2Si2O5(OH)4 + O2(g) -10.92 -13.88 -2.96 O2 + Quartz -4.44 -8.42 -3.98 SiO2 + SiO2(a) -5.71 -8.42 -2.71 SiO2 + +Reaction step 2. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 1000 seconds (Incremented time: 1100 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.266e-08 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.28 7.77 8.05 0.000e+00 0.000e+00 + K-mica -12.66 0.31 12.97 0.000e+00 0.000e+00 + Kaolinite -4.93 0.78 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 1.392e-08 1.392e-08 + K 1.392e-08 1.392e-08 + Si 4.176e-08 4.176e-08 + +----------------------------Description of solution---------------------------- + + pH = 7.003 Charge balance + pe = 11.058 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.137e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.579e-08 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 7 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.009e-07 1.009e-07 -6.996 -6.996 -0.000 + H+ 9.928e-08 9.924e-08 -7.003 -7.003 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 1.392e-08 + Al(OH)4- 1.279e-08 1.278e-08 -7.893 -7.893 -0.000 + Al(OH)3 6.731e-10 6.731e-10 -9.172 -9.172 0.000 + Al(OH)2+ 4.535e-10 4.533e-10 -9.343 -9.344 -0.000 + AlOH+2 5.749e-12 5.740e-12 -11.240 -11.241 -0.001 + Al+3 5.755e-14 5.734e-14 -13.240 -13.242 -0.002 +H(0) 1.070e-39 + H2 5.349e-40 5.349e-40 -39.272 -39.272 0.000 +K 1.392e-08 + K+ 1.392e-08 1.392e-08 -7.856 -7.856 -0.000 + KOH 4.862e-16 4.862e-16 -15.313 -15.313 0.000 +O(0) 2.914e-14 + O2 1.457e-14 1.457e-14 -13.837 -13.837 0.000 +Si 4.176e-08 + H4SiO4 4.170e-08 4.170e-08 -7.380 -7.380 0.000 + H3SiO4- 6.199e-11 6.196e-11 -10.208 -10.208 -0.000 + H2SiO4-2 4.254e-17 4.247e-17 -16.371 -16.372 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.03 7.77 10.80 Al(OH)3 + Chalcedony -3.83 -7.38 -3.55 SiO2 + Gibbsite -0.28 7.77 8.05 Al(OH)3 + H2(g) -36.12 -39.27 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -16.10 -15.22 0.88 KAlSi3O8 + K-mica -12.66 0.31 12.97 KAl3Si3O10(OH)2 + Kaolinite -4.93 0.78 5.71 Al2Si2O5(OH)4 + O2(g) -10.88 -13.84 -2.96 O2 + Quartz -3.40 -7.38 -3.98 SiO2 + SiO2(a) -4.67 -7.38 -2.71 SiO2 + +Reaction step 3. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 10000 seconds (Incremented time: 11100 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.266e-07 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) +A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 0.000e+00 9.936e-08 9.936e-08 + K-mica -7.59 5.38 12.97 0.000e+00 0.000e+00 + Kaolinite -2.36 3.35 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 4.111e-08 4.111e-08 + K 1.405e-07 1.405e-07 + Si 4.214e-07 4.214e-07 + +----------------------------Description of solution---------------------------- + + pH = 7.210 Charge balance + pe = 10.821 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 2.027e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.639e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 + Iterations = 8 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.625e-07 1.624e-07 -6.789 -6.789 -0.000 + H+ 6.167e-08 6.164e-08 -7.210 -7.210 -0.000 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 4.111e-08 + Al(OH)4- 3.929e-08 3.927e-08 -7.406 -7.406 -0.000 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 5.374e-10 5.372e-10 -9.270 -9.270 -0.000 + AlOH+2 4.233e-12 4.224e-12 -11.373 -11.374 -0.001 + Al+3 2.634e-14 2.621e-14 -13.579 -13.582 -0.002 +H(0) 1.226e-39 + H2 6.128e-40 6.128e-40 -39.213 -39.213 0.000 +K 1.405e-07 + K+ 1.405e-07 1.404e-07 -6.852 -6.853 -0.000 + KOH 7.899e-15 7.899e-15 -14.102 -14.102 0.000 +O(0) 2.220e-14 + O2 1.110e-14 1.110e-14 -13.955 -13.955 0.000 +Si 4.214e-07 + H4SiO4 4.204e-07 4.204e-07 -6.376 -6.376 0.000 + H3SiO4- 1.006e-09 1.006e-09 -8.997 -8.997 -0.000 + H2SiO4-2 1.112e-15 1.110e-15 -14.954 -14.955 -0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -2.82 -6.38 -3.55 SiO2 + Gibbsite -0.00 8.05 8.05 Al(OH)3 + H2(g) -36.06 -39.21 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -11.60 -10.72 0.88 KAlSi3O8 + K-mica -7.59 5.38 12.97 KAl3Si3O10(OH)2 + Kaolinite -2.36 3.35 5.71 Al2Si2O5(OH)4 + O2(g) -10.99 -13.95 -2.96 O2 + Quartz -2.40 -6.38 -3.98 SiO2 + SiO2(a) -3.66 -6.38 -2.71 SiO2 + +Reaction step 4. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 100000 seconds (Incremented time: 111100 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.266e-06 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) +A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite 0.00 8.05 8.05 9.936e-08 1.142e-06 1.043e-06 + K-mica -2.79 10.18 12.97 0.000e+00 0.000e+00 + Kaolinite -0.37 5.33 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 2.640e-07 2.640e-07 + K 1.406e-06 1.406e-06 + Si 4.218e-06 4.218e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.035 Charge balance + pe = 10.027 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.415e-06 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.198e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 65 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.086e-06 1.085e-06 -5.964 -5.965 -0.001 + H+ 9.240e-09 9.228e-09 -8.034 -8.035 -0.001 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 2.640e-07 + Al(OH)4- 2.626e-07 2.623e-07 -6.581 -6.581 -0.001 + Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 + Al(OH)2+ 8.053e-11 8.042e-11 -10.094 -10.095 -0.001 + AlOH+2 9.521e-14 9.468e-14 -13.021 -13.024 -0.002 + Al+3 8.906e-17 8.796e-17 -16.050 -16.056 -0.005 +H(0) 1.066e-39 + H2 5.332e-40 5.332e-40 -39.273 -39.273 0.000 +K 1.406e-06 + K+ 1.406e-06 1.404e-06 -5.852 -5.853 -0.001 + KOH 5.276e-13 5.276e-13 -12.278 -12.278 0.000 +O(0) 2.932e-14 + O2 1.466e-14 1.466e-14 -13.834 -13.834 0.000 +Si 4.218e-06 + H4SiO4 4.152e-06 4.152e-06 -5.382 -5.382 0.000 + H3SiO4- 6.643e-08 6.634e-08 -7.178 -7.178 -0.001 + H2SiO4-2 4.918e-13 4.890e-13 -12.308 -12.311 -0.002 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 + Chalcedony -1.83 -5.38 -3.55 SiO2 + Gibbsite 0.00 8.05 8.05 Al(OH)3 + H2(g) -36.12 -39.27 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -6.79 -5.91 0.88 KAlSi3O8 + K-mica -2.79 10.18 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.37 5.33 5.71 Al2Si2O5(OH)4 + O2(g) -10.87 -13.83 -2.96 O2 + Quartz -1.40 -5.38 -3.98 SiO2 + SiO2(a) -2.67 -5.38 -2.71 SiO2 + +Reaction step 5. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 1e+06 seconds (Incremented time: 1.1111e+06 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.265e-05 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) +A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 +B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 +C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -0.59 7.45 8.05 1.142e-06 -1.142e-06 + K-mica -0.27 12.70 12.97 0.000e+00 0.000e+00 + Kaolinite 0.00 5.71 5.71 0.000e+00 6.727e-06 6.727e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 6.045e-07 6.045e-07 + K 1.406e-05 1.406e-05 + Si 2.872e-05 2.872e-05 + +----------------------------Description of solution---------------------------- + + pH = 8.990 Charge balance + pe = 9.170 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.406e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.587e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 467 + Total H = 1.110124e+02 + Total O = 5.550627e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 9.825e-06 9.782e-06 -5.008 -5.010 -0.002 + H+ 1.028e-09 1.023e-09 -8.988 -8.990 -0.002 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 6.045e-07 + Al(OH)4- 6.042e-07 6.015e-07 -6.219 -6.221 -0.002 + Al(OH)3 3.266e-10 3.266e-10 -9.486 -9.486 0.000 + Al(OH)2+ 2.279e-12 2.269e-12 -11.642 -11.644 -0.002 + AlOH+2 3.015e-16 2.963e-16 -15.521 -15.528 -0.008 + Al+3 3.174e-20 3.052e-20 -19.498 -19.515 -0.017 +H(0) 6.790e-40 + H2 3.395e-40 3.395e-40 -39.469 -39.469 0.000 +K 1.406e-05 + K+ 1.406e-05 1.400e-05 -4.852 -4.854 -0.002 + KOH 4.742e-11 4.742e-11 -10.324 -10.324 0.000 +O(0) 7.232e-14 + O2 3.616e-14 3.616e-14 -13.442 -13.442 0.000 +Si 2.872e-05 + H4SiO4 2.509e-05 2.509e-05 -4.600 -4.600 0.000 + H3SiO4- 3.631e-06 3.615e-06 -5.440 -5.442 -0.002 + H2SiO4-2 2.445e-10 2.403e-10 -9.612 -9.619 -0.008 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -3.35 7.45 10.80 Al(OH)3 + Chalcedony -1.05 -4.60 -3.55 SiO2 + Gibbsite -0.59 7.45 8.05 Al(OH)3 + H2(g) -36.32 -39.47 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -3.09 -2.21 0.88 KAlSi3O8 + K-mica -0.27 12.70 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 + O2(g) -10.48 -13.44 -2.96 O2 + Quartz -0.62 -4.60 -3.98 SiO2 + SiO2(a) -1.89 -4.60 -2.71 SiO2 + +Reaction step 6. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 1e+07 seconds (Incremented time: 1.11111e+07 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -1.126e-04 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) +A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 +B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 +C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 +D: Kaolinite -> K-mica 1.5869e+06 2.0070e-05 4.4080e+00 -4.4659e+00 +E: Kaolinite -> K-mica 2.5972e+06 3.2791e-05 4.4103e+00 -4.2509e+00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -1.76 6.29 8.05 0.000e+00 0.000e+00 + K-mica -0.00 12.97 12.97 0.000e+00 4.218e-05 4.218e-05 + Kaolinite -0.57 5.14 5.71 6.727e-06 -6.727e-06 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 9.274e-08 9.274e-08 + K 8.444e-05 8.444e-05 + Si 2.533e-04 2.533e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.339 Charge balance + pe = -4.518 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.445e-05 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.472e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.113e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 3145 + Total H = 1.110123e+02 + Total O = 5.550672e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.211e-05 2.187e-05 -4.655 -4.660 -0.005 + H+ 4.625e-10 4.577e-10 -9.335 -9.339 -0.005 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 9.274e-08 + Al(OH)4- 9.272e-08 9.174e-08 -7.033 -7.037 -0.005 + Al(OH)3 2.228e-11 2.228e-11 -10.652 -10.652 0.000 + Al(OH)2+ 6.994e-14 6.920e-14 -13.155 -13.160 -0.005 + AlOH+2 4.217e-18 4.041e-18 -17.375 -17.393 -0.018 + Al+3 2.046e-22 1.862e-22 -21.689 -21.730 -0.041 +H(0) 3.219e-13 + H2 1.610e-13 1.610e-13 -12.793 -12.793 0.000 +K 8.444e-05 + K+ 8.444e-05 8.355e-05 -4.073 -4.078 -0.005 + KOH 6.329e-10 6.329e-10 -9.199 -9.199 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -66.794 -66.794 0.000 +Si 2.533e-04 + H4SiO4 1.911e-04 1.911e-04 -3.719 -3.719 0.000 + H3SiO4- 6.222e-05 6.157e-05 -4.206 -4.211 -0.005 + H2SiO4-2 9.548e-09 9.150e-09 -8.020 -8.039 -0.018 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.51 6.29 10.80 Al(OH)3 + Chalcedony -0.17 -3.72 -3.55 SiO2 + Gibbsite -1.76 6.29 8.05 Al(OH)3 + H2(g) -9.64 -12.79 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -0.48 0.39 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.57 5.14 5.71 Al2Si2O5(OH)4 + O2(g) -63.83 -66.79 -2.96 O2 + Quartz 0.26 -3.72 -3.98 SiO2 + SiO2(a) -1.01 -3.72 -2.71 SiO2 + +Reaction step 7. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 9. + +Kinetics 1. Kinetics defined in simulation 9. + + Time step: 1e+08 seconds (Incremented time: 1.11111e+08 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + K-feldspar -6.426e-05 1.940e+00 K-feldspar 1 + +----------------------------------User print----------------------------------- + + Transition Time K-feldspar LA(K/H) LA(H4SiO4) + reacted + (moles) +A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 +B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 +C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 +D: Kaolinite -> K-mica 1.5869e+06 2.0070e-05 4.4080e+00 -4.4659e+00 +E: Kaolinite -> K-mica 2.5972e+06 3.2791e-05 4.4103e+00 -4.2509e+00 +F: K-mica -> K-feldspar 4.7840e+07 1.9072e-04 5.4879e+00 -3.5540e+00 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 + K-mica 0.00 12.97 12.97 4.218e-05 6.361e-05 2.143e-05 + Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Al 5.990e-08 5.989e-08 + K 1.273e-04 1.273e-04 + Si 3.818e-04 3.818e-04 + +----------------------------Description of solution---------------------------- + + pH = 9.389 Charge balance + pe = -4.454 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.273e-04 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.275e-04 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.114e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 1788 + Total H = 1.110123e+02 + Total O = 5.550698e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 + H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 + H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 +Al 5.990e-08 + Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 + Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 + Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 + AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 + Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 +H(0) 1.911e-13 + H2 9.553e-14 9.553e-14 -13.020 -13.020 0.000 +K 1.273e-04 + K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 + KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -66.340 -66.340 0.000 +Si 3.818e-04 + H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 + H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 + H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 + Chalcedony -0.00 -3.55 -3.55 SiO2 + Gibbsite -2.00 6.05 8.05 Al(OH)3 + H2(g) -9.87 -13.02 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + K-feldspar -0.00 0.87 0.88 KAlSi3O8 + K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 + Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 + O2(g) -63.38 -66.34 -2.96 O2 + Quartz 0.43 -3.55 -3.98 SiO2 + SiO2(a) -0.84 -3.55 -2.71 SiO2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 10. +------------------------------------- + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex6A-B.sel b/Sun/examples/ex6A-B.sel new file mode 100644 index 00000000..a623a401 --- /dev/null +++ b/Sun/examples/ex6A-B.sel @@ -0,0 +1,22 @@ + sim state soln dist_x time step pH pe la_K+ la_H+ la_H4SiO4 Gibbsite d_Gibbsite Kaolinite d_Kaolinite K-mica d_K-mica K-feldspar d_K-feldspar si_Gibbsite si_Kaolinite si_K-mica si_K-feldspar + 1 i_soln 1 -99 -99 -99 6.99977 4 -1.0000e+03 -6.9998e+00 -1.0000e+03 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -999.9990 -999.9990 -999.9990 -999.9990 + 2 react 1 -99 0 1 7.00609 11.4683 -7.5735e+00 -7.0061e+00 -7.0969e+00 1.0000e+01 -2.6709e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -3.8037 -10.6810 -14.6840 + 3 react 1 -99 0 1 8.2125 9.89391 -5.6625e+00 -8.2125e+00 -5.1950e+00 1.7820e-06 1.7820e-06 1.0000e+01 -2.1788e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -0.0000 -1.8580 -5.8610 + 4 react 1 -99 0 1 9.10891 9.06313 -4.7009e+00 -9.1089e+00 -4.4670e+00 0.0000e+00 0.0000e+00 9.7149e-06 9.7149e-06 1.0000e+01 -2.0015e-05 0.0000e+00 0.0000e+00 -0.7280 0.0000 -0.0000 -2.5471 + 5 react 1 -99 0 1 9.3893 8.71926 -3.9009e+00 -9.3893e+00 -3.5536e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.3607e-05 6.3607e-05 9.9998e+00 -1.9088e-04 -2.0015 -0.7202 -0.0000 -0.0000 + 6 react 1 -99 0 1 8.35402 9.7856 -5.5204e+00 -8.3540e+00 -5.1950e+00 1.0000e+01 -3.0232e-06 1.0000e+00 1.2370e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.0000 -1.5744 -5.5774 + 7 react 1 -99 0 1 9.06998 8.8364 -4.6620e+00 -9.0700e+00 -4.2522e+00 0.0000e+00 0.0000e+00 1.0000e+01 -3.2683e-05 1.0000e+00 1.0785e-05 0.0000e+00 0.0000e+00 -0.9428 0.0000 0.0000 -2.1175 + 8 react 1 -99 0 1 7.03143 11.4569 -7.3981e+00 -7.0314e+00 -6.9215e+00 1.1865e-08 1.1865e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -3.4530 -9.9542 -13.9572 + 8 react 1 -99 0 2 7.10578 11.2881 -7.0971e+00 -7.1058e+00 -6.6206e+00 4.7135e-08 4.7135e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -2.8512 -8.6762 -12.6792 + 8 react 1 -99 0 3 7.24112 11.2405 -6.7961e+00 -7.2411e+00 -6.3199e+00 1.1602e-07 1.1602e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -2.2497 -7.3376 -11.3406 + 8 react 1 -99 0 4 7.45138 11.1879 -6.4952e+00 -7.4514e+00 -6.0195e+00 2.4993e-07 2.4993e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -1.6491 -5.9254 -9.9284 + 8 react 1 -99 0 5 7.71458 10.9939 -6.1942e+00 -7.7146e+00 -5.7200e+00 5.1299e-07 5.1299e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -1.0500 -4.4627 -8.4657 + 8 react 1 -99 0 6 7.89551 10.7897 -6.0005e+00 -7.8955e+00 -5.5279e+00 8.0811e-07 8.0811e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.6658 -3.5117 -7.5147 + 8 react 1 -99 0 7 8.17803 10.4976 -5.6997e+00 -8.1780e+00 -5.2314e+00 1.6334e-06 1.6334e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.0728 -2.0389 -6.0419 + 8 react 1 -99 0 8 8.48402 9.39003 -5.3990e+00 -8.4840e+00 -5.0858e+00 0.0000e+00 0.0000e+00 1.7119e-06 1.7119e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.1092 -0.0000 -1.3229 -5.1076 + 8 react 1 -99 0 9 8.77878 9.50556 -5.0983e+00 -8.7788e+00 -4.8166e+00 0.0000e+00 0.0000e+00 3.6945e-06 3.6945e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.3784 -0.0000 -0.7276 -3.9737 + 8 react 1 -99 0 10 9.0347 8.80148 -4.7979e+00 -9.0347e+00 -4.5514e+00 0.0000e+00 0.0000e+00 7.7006e-06 7.7006e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.6436 0.0000 -0.1712 -2.8871 + 8 react 1 -99 0 11 9.07198 8.97748 -4.6640e+00 -9.0720e+00 -4.2616e+00 0.0000e+00 0.0000e+00 5.2701e-07 5.2701e-07 1.0204e-05 1.0204e-05 0.0000e+00 0.0000e+00 -0.9334 0.0000 -0.0000 -2.1362 + 8 react 1 -99 0 12 9.2252 8.68998 -4.3726e+00 -9.2252e+00 -3.9889e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 2.1273e-05 2.1273e-05 0.0000e+00 0.0000e+00 -1.3543 -0.2964 0.0000 -1.2945 + 8 react 1 -99 0 13 9.30457 8.57016 -4.1800e+00 -9.3046e+00 -3.8127e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.3294e-05 3.3294e-05 0.0000e+00 0.0000e+00 -1.6212 -0.4777 0.0000 -0.7607 + 8 react 1 -99 0 14 9.3893 8.9467 -3.9009e+00 -9.3893e+00 -3.5536e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.3607e-05 6.3607e-05 9.1200e-06 9.1200e-06 -2.0015 -0.7202 -0.0000 0.0000 diff --git a/Sun/examples/ex6C.sel b/Sun/examples/ex6C.sel new file mode 100644 index 00000000..efc12a6c --- /dev/null +++ b/Sun/examples/ex6C.sel @@ -0,0 +1,9 @@ + pH+log[K] log[H4SiO4] + -6.0002e+00 -1.2524e+01 + -1.8975e+00 -8.4212e+00 + -8.5316e-01 -7.3798e+00 + 3.5755e-01 -6.3763e+00 + 2.1823e+00 -5.3818e+00 + 4.1360e+00 -4.6005e+00 + 5.2614e+00 -3.7187e+00 + 5.4884e+00 -3.5536e+00 diff --git a/Sun/examples/ex7.log b/Sun/examples/ex7.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex7.out b/Sun/examples/ex7.out new file mode 100644 index 00000000..8e79de41 --- /dev/null +++ b/Sun/examples/ex7.out @@ -0,0 +1,2819 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex7 + Output file: ex7.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 7.--Organic decomposition with fixed-pressure and + fixed-volume gas phases + SOLUTION 1 + EQUILIBRIUM_PHASES 1 + Calcite + CO2(g) -1.5 + SAVE solution 1 + SELECTED_OUTPUT + reset false + file ex7.sel + simulation true + state true + reaction true + si CO2(g) CH4(g) N2(g) NH3(g) + gases CO2(g) CH4(g) N2(g) NH3(g) + END +----- +TITLE +----- + + Example 7.--Organic decomposition with fixed-pressure and + fixed-volume gas phases + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Pure water + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 4.000 + Activity of water = 1.000 + Ionic strength = 1.001e-07 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.082e-10 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.082e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 0 + Total H = 1.110124e+02 + Total O = 5.550622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 + H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 + H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 +H(0) 1.416e-25 + H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -22.00 -25.15 -3.15 H2 + H2O(g) -1.51 0.00 1.51 H2O + O2(g) -39.12 -42.08 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Calcite 0.00 -8.48 -8.48 1.000e+01 9.997e+00 -2.502e-03 + CO2(g) -1.50 -19.65 -18.15 1.000e+01 9.996e+00 -3.568e-03 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 6.071e-03 6.071e-03 + Ca 2.502e-03 2.502e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.971 Charge balance + pe = -0.653 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.282e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.004e-03 + Total CO2 (mol/kg) = 6.071e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 16 + Total H = 1.110124e+02 + Total O = 5.552086e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.159e-07 1.070e-07 -6.936 -6.971 -0.035 + OH- 1.025e-07 9.358e-08 -6.989 -7.029 -0.040 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 7.589e-30 + CH4 7.589e-30 7.602e-30 -29.120 -29.119 0.001 +C(4) 6.071e-03 + HCO3- 4.883e-03 4.476e-03 -2.311 -2.349 -0.038 + CO2 1.075e-03 1.077e-03 -2.969 -2.968 0.001 + CaHCO3+ 1.052e-04 9.640e-05 -3.978 -4.016 -0.038 + CaCO3 5.556e-06 5.565e-06 -5.255 -5.255 0.001 + CO3-2 2.778e-06 1.962e-06 -5.556 -5.707 -0.151 +Ca 2.502e-03 + Ca+2 2.391e-03 1.688e-03 -2.621 -2.773 -0.151 + CaHCO3+ 1.052e-04 9.640e-05 -3.978 -4.016 -0.038 + CaCO3 5.556e-06 5.565e-06 -5.255 -5.255 0.001 + CaOH+ 2.864e-09 2.619e-09 -8.543 -8.582 -0.039 +H(0) 3.273e-16 + H2 1.636e-16 1.639e-16 -15.786 -15.785 0.001 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -60.810 -60.809 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite 0.00 -8.48 -8.48 CaCO3 + CH4(g) -26.26 -29.12 -2.86 CH4 + CO2(g) -1.50 -2.97 -1.47 CO2 + H2(g) -12.64 -15.79 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -57.85 -60.81 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + USE solution 1 + GAS_PHASE 1 Fixed-pressure gas phase + fixed_pressure + pressure 1.1 + CO2(g) 0.0 + CH4(g) 0.0 + N2(g) 0.0 + NH3(g) 0.0 + REACTION 1 + CH2O(NH3)0.07 1.0 + 1. 2. 3. 4. 8. 16. 32 64. 125. 250. 500. 1000. mmol + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 1.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 7.071e-03 7.071e-03 + Ca 2.502e-03 2.502e-03 + N 7.000e-05 7.000e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.831 Charge balance + pe = -3.723 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.353e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.074e-03 + Total CO2 (mol/kg) = 6.571e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.110146e+02 + Total O = 5.552186e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.597e-07 1.474e-07 -6.797 -6.831 -0.035 + OH- 7.440e-08 6.789e-08 -7.128 -7.168 -0.040 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 5.001e-04 + CH4 5.001e-04 5.009e-04 -3.301 -3.300 0.001 +C(4) 6.571e-03 + HCO3- 4.955e-03 4.541e-03 -2.305 -2.343 -0.038 + CO2 1.503e-03 1.505e-03 -2.823 -2.822 0.001 + CaHCO3+ 1.066e-04 9.766e-05 -3.972 -4.010 -0.038 + CaCO3 4.083e-06 4.090e-06 -5.389 -5.388 0.001 + CO3-2 2.048e-06 1.445e-06 -5.689 -5.840 -0.152 +Ca 2.502e-03 + Ca+2 2.392e-03 1.686e-03 -2.621 -2.773 -0.152 + CaHCO3+ 1.066e-04 9.766e-05 -3.972 -4.010 -0.038 + CaCO3 4.083e-06 4.090e-06 -5.389 -5.388 0.001 + CaOH+ 2.076e-09 1.897e-09 -8.683 -8.722 -0.039 +H(0) 8.575e-10 + H2 4.287e-10 4.295e-10 -9.368 -9.367 0.001 +N(-3) 6.986e-05 + NH4+ 6.962e-05 6.338e-05 -4.157 -4.198 -0.041 + NH3 2.446e-07 2.450e-07 -6.612 -6.611 0.001 +N(0) 1.394e-07 + N2 6.970e-08 6.981e-08 -7.157 -7.156 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.351 -62.391 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.704 -84.744 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.647 -73.646 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.28 -8.61 -8.34 CaCO3 + Calcite -0.13 -8.61 -8.48 CaCO3 + CH4(g) -0.44 -3.30 -2.86 CH4 + CO2(g) -1.35 -2.82 -1.47 CO2 + H2(g) -6.22 -9.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.90 -7.16 -3.26 N2 + NH3(g) -8.38 -6.61 1.77 NH3 + O2(g) -70.69 -73.65 -2.96 O2 + +Reaction step 2. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 2.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 8.071e-03 8.071e-03 + Ca 2.502e-03 2.502e-03 + N 1.400e-04 1.400e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.728 Charge balance + pe = -3.644 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.422e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.144e-03 + Total CO2 (mol/kg) = 7.071e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 20 + Total H = 1.110169e+02 + Total O = 5.552286e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.026e-07 1.869e-07 -6.693 -6.728 -0.035 + OH- 5.871e-08 5.355e-08 -7.231 -7.271 -0.040 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 1.000e-03 + CH4 1.000e-03 1.002e-03 -3.000 -2.999 0.001 +C(4) 7.071e-03 + HCO3- 5.026e-03 4.604e-03 -2.299 -2.337 -0.038 + CO2 1.932e-03 1.935e-03 -2.714 -2.713 0.001 + CaHCO3+ 1.079e-04 9.886e-05 -3.967 -4.005 -0.038 + CaCO3 3.261e-06 3.266e-06 -5.487 -5.486 0.001 + CO3-2 1.640e-06 1.155e-06 -5.785 -5.937 -0.152 +Ca 2.502e-03 + Ca+2 2.391e-03 1.683e-03 -2.621 -2.774 -0.153 + CaHCO3+ 1.079e-04 9.886e-05 -3.967 -4.005 -0.038 + CaCO3 3.261e-06 3.266e-06 -5.487 -5.486 0.001 + CaOH+ 1.635e-09 1.494e-09 -8.786 -8.826 -0.039 +H(0) 9.576e-10 + H2 4.788e-10 4.796e-10 -9.320 -9.319 0.001 +N(-3) 1.398e-04 + NH4+ 1.394e-04 1.268e-04 -3.856 -3.897 -0.041 + NH3 3.860e-07 3.867e-07 -6.413 -6.413 0.001 +N(0) 2.493e-07 + N2 1.247e-07 1.249e-07 -6.904 -6.904 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.399 -62.440 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.800 -84.841 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.743 -73.742 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.38 -8.71 -8.34 CaCO3 + Calcite -0.23 -8.71 -8.48 CaCO3 + CH4(g) -0.14 -3.00 -2.86 CH4 + CO2(g) -1.25 -2.71 -1.47 CO2 + H2(g) -6.17 -9.32 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.64 -6.90 -3.26 N2 + NH3(g) -8.18 -6.41 1.77 NH3 + O2(g) -70.78 -73.74 -2.96 O2 + +Reaction step 3. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 3.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 1.91e-03 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) 0.01 1.030e+00 0.000e+00 8.036e-05 8.036e-05 +CO2(g) -1.16 6.932e-02 0.000e+00 5.406e-06 5.406e-06 +N2(g) -3.50 3.151e-04 0.000e+00 2.458e-08 2.458e-08 +NH3(g) -8.09 8.187e-09 0.000e+00 6.386e-13 6.386e-13 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 8.985e-03 8.985e-03 + Ca 2.502e-03 2.502e-03 + N 2.100e-04 2.100e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.648 Charge balance + pe = -3.572 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.491e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.214e-03 + Total CO2 (mol/kg) = 7.565e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 23 + Total H = 1.110187e+02 + Total O = 5.552385e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.438e-07 2.249e-07 -6.613 -6.648 -0.035 + OH- 4.882e-08 4.451e-08 -7.311 -7.352 -0.040 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 1.420e-03 + CH4 1.420e-03 1.422e-03 -2.848 -2.847 0.001 +C(4) 7.565e-03 + HCO3- 5.096e-03 4.667e-03 -2.293 -2.331 -0.038 + CO2 2.356e-03 2.360e-03 -2.628 -2.627 0.001 + CaHCO3+ 1.092e-04 1.000e-04 -3.962 -4.000 -0.038 + CaCO3 2.742e-06 2.747e-06 -5.562 -5.561 0.001 + CO3-2 1.384e-06 9.733e-07 -5.859 -6.012 -0.153 +Ca 2.502e-03 + Ca+2 2.390e-03 1.680e-03 -2.622 -2.775 -0.153 + CaHCO3+ 1.092e-04 1.000e-04 -3.962 -4.000 -0.038 + CaCO3 2.742e-06 2.747e-06 -5.562 -5.561 0.001 + CaOH+ 1.357e-09 1.240e-09 -8.867 -8.907 -0.039 +H(0) 9.947e-10 + H2 4.974e-10 4.982e-10 -9.303 -9.303 0.001 +N(-3) 2.096e-04 + NH4+ 2.091e-04 1.902e-04 -3.680 -3.721 -0.041 + NH3 4.813e-07 4.821e-07 -6.318 -6.317 0.001 +N(0) 3.457e-07 + N2 1.729e-07 1.732e-07 -6.762 -6.762 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.433 -62.474 -0.041 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.851 -84.891 -0.041 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.776 -73.775 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.45 -8.79 -8.34 CaCO3 + Calcite -0.31 -8.79 -8.48 CaCO3 + CH4(g) 0.01 -2.85 -2.86 CH4 + CO2(g) -1.16 -2.63 -1.47 CO2 + H2(g) -6.15 -9.30 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.50 -6.76 -3.26 N2 + NH3(g) -8.09 -6.32 1.77 NH3 + O2(g) -70.81 -73.77 -2.96 O2 + +Reaction step 4. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 4.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 1.43e-02 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) 0.01 1.019e+00 0.000e+00 5.966e-04 5.966e-04 +CO2(g) -1.09 8.074e-02 0.000e+00 4.728e-05 4.728e-05 +N2(g) -3.32 4.773e-04 0.000e+00 2.795e-07 2.795e-07 +NH3(g) -8.02 9.476e-09 0.000e+00 5.549e-12 5.549e-12 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 9.427e-03 9.427e-03 + Ca 2.502e-03 2.502e-03 + N 2.795e-04 2.794e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.588 Charge balance + pe = -3.502 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.558e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 5.283e-03 + Total CO2 (mol/kg) = 8.023e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 23 + Total H = 1.110189e+02 + Total O = 5.552477e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.803e-07 2.585e-07 -6.552 -6.588 -0.035 + OH- 4.248e-08 3.872e-08 -7.372 -7.412 -0.040 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 1.404e-03 + CH4 1.404e-03 1.406e-03 -2.853 -2.852 0.001 +C(4) 8.023e-03 + HCO3- 5.165e-03 4.728e-03 -2.287 -2.325 -0.038 + CO2 2.744e-03 2.749e-03 -2.562 -2.561 0.001 + CaHCO3+ 1.105e-04 1.012e-04 -3.957 -3.995 -0.038 + CaCO3 2.412e-06 2.417e-06 -5.618 -5.617 0.001 + CO3-2 1.221e-06 8.579e-07 -5.913 -6.067 -0.153 +Ca 2.502e-03 + Ca+2 2.389e-03 1.677e-03 -2.622 -2.775 -0.154 + CaHCO3+ 1.105e-04 1.012e-04 -3.957 -3.995 -0.038 + CaCO3 2.412e-06 2.417e-06 -5.618 -5.617 0.001 + CaOH+ 1.179e-09 1.076e-09 -8.928 -8.968 -0.040 +H(0) 9.548e-10 + H2 4.774e-10 4.782e-10 -9.321 -9.320 0.001 +N(-3) 2.789e-04 + NH4+ 2.784e-04 2.531e-04 -3.555 -3.597 -0.041 + NH3 5.570e-07 5.580e-07 -6.254 -6.253 0.001 +N(0) 5.237e-07 + N2 2.619e-07 2.623e-07 -6.582 -6.581 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.377 -62.418 -0.041 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.777 -84.817 -0.041 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.740 -73.739 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.51 -8.84 -8.34 CaCO3 + Calcite -0.36 -8.84 -8.48 CaCO3 + CH4(g) 0.01 -2.85 -2.86 CH4 + CO2(g) -1.09 -2.56 -1.47 CO2 + H2(g) -6.17 -9.32 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.32 -6.58 -3.26 N2 + NH3(g) -8.02 -6.25 1.77 NH3 + O2(g) -70.78 -73.74 -2.96 O2 + +Reaction step 5. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 8.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 6.67e-02 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.01 9.758e-01 0.000e+00 2.659e-03 2.659e-03 +CO2(g) -0.91 1.230e-01 0.000e+00 3.351e-04 3.351e-04 +N2(g) -2.90 1.257e-03 0.000e+00 3.425e-06 3.425e-06 +NH3(g) -7.89 1.292e-08 0.000e+00 3.520e-11 3.520e-11 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.108e-02 1.108e-02 + Ca 2.502e-03 2.502e-03 + N 5.532e-04 5.532e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.426 Charge balance + pe = -3.316 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.823e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 5.556e-03 + Total CO2 (mol/kg) = 9.733e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.074e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.110195e+02 + Total O = 5.552819e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 4.068e-07 3.747e-07 -6.391 -6.426 -0.036 + OH- 2.935e-08 2.671e-08 -7.532 -7.573 -0.041 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 1.344e-03 + CH4 1.344e-03 1.347e-03 -2.871 -2.871 0.001 +C(4) 9.733e-03 + HCO3- 5.435e-03 4.969e-03 -2.265 -2.304 -0.039 + CO2 4.180e-03 4.187e-03 -2.379 -2.378 0.001 + CaHCO3+ 1.155e-04 1.056e-04 -3.938 -3.977 -0.039 + CaCO3 1.736e-06 1.740e-06 -5.760 -5.760 0.001 + CO3-2 8.902e-07 6.219e-07 -6.051 -6.206 -0.156 +Ca 2.502e-03 + Ca+2 2.385e-03 1.665e-03 -2.623 -2.779 -0.156 + CaHCO3+ 1.155e-04 1.056e-04 -3.938 -3.977 -0.039 + CaCO3 1.736e-06 1.740e-06 -5.760 -5.760 0.001 + CaOH+ 8.088e-10 7.373e-10 -9.092 -9.132 -0.040 +H(0) 8.501e-10 + H2 4.251e-10 4.258e-10 -9.372 -9.371 0.001 +N(-3) 5.518e-04 + NH4+ 5.510e-04 5.003e-04 -3.259 -3.301 -0.042 + NH3 7.594e-07 7.608e-07 -6.120 -6.119 0.001 +N(0) 1.379e-06 + N2 6.895e-07 6.907e-07 -6.161 -6.161 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.252 -62.293 -0.041 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.601 -84.642 -0.041 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.639 -73.639 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.65 -8.98 -8.34 CaCO3 + Calcite -0.51 -8.98 -8.48 CaCO3 + CH4(g) -0.01 -2.87 -2.86 CH4 + CO2(g) -0.91 -2.38 -1.47 CO2 + H2(g) -6.22 -9.37 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.90 -6.16 -3.26 N2 + NH3(g) -7.89 -6.12 1.77 NH3 + O2(g) -70.68 -73.64 -2.96 O2 + +Reaction step 6. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 1.600e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 1.83e-01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.04 9.042e-01 0.000e+00 6.775e-03 6.775e-03 +CO2(g) -0.72 1.925e-01 0.000e+00 1.442e-03 1.442e-03 +N2(g) -2.47 3.359e-03 0.000e+00 2.517e-05 2.517e-05 +NH3(g) -7.76 1.735e-08 0.000e+00 1.300e-10 1.300e-10 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.385e-02 1.385e-02 + Ca 2.502e-03 2.502e-03 + N 1.070e-03 1.070e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.269 Charge balance + pe = -3.131 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.320e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.070e-03 + Total CO2 (mol/kg) = 1.261e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 20 + Total H = 1.110207e+02 + Total O = 5.553398e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 5.850e-07 5.377e-07 -6.233 -6.269 -0.037 + OH- 2.050e-08 1.861e-08 -7.688 -7.730 -0.042 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +C(-4) 1.246e-03 + CH4 1.246e-03 1.248e-03 -2.905 -2.904 0.001 +C(4) 1.261e-02 + CO2 6.541e-03 6.553e-03 -2.184 -2.184 0.001 + HCO3- 5.941e-03 5.419e-03 -2.226 -2.266 -0.040 + CaHCO3+ 1.246e-04 1.136e-04 -3.905 -3.945 -0.040 + CaCO3 1.302e-06 1.304e-06 -5.885 -5.885 0.001 + CO3-2 6.830e-07 4.726e-07 -6.166 -6.326 -0.160 +Ca 2.502e-03 + Ca+2 2.376e-03 1.643e-03 -2.624 -2.784 -0.160 + CaHCO3+ 1.246e-04 1.136e-04 -3.905 -3.945 -0.040 + CaCO3 1.302e-06 1.304e-06 -5.885 -5.885 0.001 + CaOH+ 5.575e-10 5.070e-10 -9.254 -9.295 -0.041 +H(0) 7.456e-10 + H2 3.728e-10 3.735e-10 -9.429 -9.428 0.001 +N(-3) 1.066e-03 + NH4+ 1.065e-03 9.641e-04 -2.973 -3.016 -0.043 + NH3 1.020e-06 1.022e-06 -5.991 -5.991 0.001 +N(0) 3.685e-06 + N2 1.842e-06 1.846e-06 -5.735 -5.734 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -62.109 -62.151 -0.043 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.401 -84.444 -0.043 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.526 -73.525 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.77 -9.11 -8.34 CaCO3 + Calcite -0.63 -9.11 -8.48 CaCO3 + CH4(g) -0.04 -2.90 -2.86 CH4 + CO2(g) -0.72 -2.18 -1.47 CO2 + H2(g) -6.28 -9.43 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.47 -5.73 -3.26 N2 + NH3(g) -7.76 -5.99 1.77 NH3 + O2(g) -70.56 -73.52 -2.96 O2 + +Reaction step 7. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 3.200e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 4.56e-01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.09 8.051e-01 0.000e+00 1.502e-02 1.502e-02 +CO2(g) -0.54 2.859e-01 0.000e+00 5.333e-03 5.333e-03 +N2(g) -2.05 8.992e-03 0.000e+00 1.677e-04 1.677e-04 +NH3(g) -7.63 2.343e-08 0.000e+00 4.372e-10 4.372e-10 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.772e-02 1.772e-02 + Ca 2.502e-03 2.502e-03 + N 1.905e-03 1.905e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.152 Charge balance + pe = -2.985 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.121e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 6.899e-03 + Total CO2 (mol/kg) = 1.661e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.110231e+02 + Total O = 5.554219e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 7.692e-07 7.048e-07 -6.114 -6.152 -0.038 + OH- 1.571e-08 1.420e-08 -7.804 -7.848 -0.044 + H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 +C(-4) 1.109e-03 + CH4 1.109e-03 1.111e-03 -2.955 -2.954 0.001 +C(4) 1.661e-02 + CO2 9.712e-03 9.733e-03 -2.013 -2.012 0.001 + HCO3- 6.756e-03 6.139e-03 -2.170 -2.212 -0.042 + CaHCO3+ 1.387e-04 1.261e-04 -3.858 -3.899 -0.042 + CaCO3 1.102e-06 1.104e-06 -5.958 -5.957 0.001 + CO3-2 5.992e-07 4.085e-07 -6.222 -6.389 -0.166 +Ca 2.502e-03 + Ca+2 2.362e-03 1.609e-03 -2.627 -2.793 -0.167 + CaHCO3+ 1.387e-04 1.261e-04 -3.858 -3.899 -0.042 + CaCO3 1.102e-06 1.104e-06 -5.958 -5.957 0.001 + CaOH+ 4.182e-10 3.788e-10 -9.379 -9.422 -0.043 +H(0) 6.560e-10 + H2 3.280e-10 3.287e-10 -9.484 -9.483 0.001 +N(-3) 1.895e-03 + NH4+ 1.893e-03 1.707e-03 -2.723 -2.768 -0.045 + NH3 1.377e-06 1.380e-06 -5.861 -5.860 0.001 +N(0) 9.862e-06 + N2 4.931e-06 4.941e-06 -5.307 -5.306 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.927 -61.972 -0.044 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -84.164 -84.209 -0.044 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.415 -73.414 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.85 -9.18 -8.34 CaCO3 + Calcite -0.70 -9.18 -8.48 CaCO3 + CH4(g) -0.09 -2.95 -2.86 CH4 + CO2(g) -0.54 -2.01 -1.47 CO2 + H2(g) -6.33 -9.48 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.05 -5.31 -3.26 N2 + NH3(g) -7.63 -5.86 1.77 NH3 + O2(g) -70.45 -73.41 -2.96 O2 + +Reaction step 8. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 6.400e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 1.10e+00 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.15 7.052e-01 0.000e+00 3.167e-02 3.167e-02 +CO2(g) -0.42 3.760e-01 0.000e+00 1.689e-02 1.689e-02 +N2(g) -1.73 1.883e-02 0.000e+00 8.456e-04 8.456e-04 +NH3(g) -7.54 2.911e-08 0.000e+00 1.307e-09 1.307e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.151e-02 2.151e-02 + Ca 2.502e-03 2.502e-03 + N 2.789e-03 2.789e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.083 Charge balance + pe = -2.895 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 9.965e-03 + Mass of water (kg) = 9.999e-01 + Total alkalinity (eq/kg) = 7.773e-03 + Total CO2 (mol/kg) = 2.054e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.110272e+02 + Total O = 5.555108e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.035e-07 8.254e-07 -6.044 -6.083 -0.039 + OH- 1.346e-08 1.212e-08 -7.871 -7.916 -0.046 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +C(-4) 9.712e-04 + CH4 9.712e-04 9.734e-04 -3.013 -3.012 0.001 +C(4) 2.054e-02 + CO2 1.277e-02 1.280e-02 -1.894 -1.893 0.001 + HCO3- 7.616e-03 6.895e-03 -2.118 -2.161 -0.043 + CaHCO3+ 1.532e-04 1.387e-04 -3.815 -3.858 -0.043 + CaCO3 1.035e-06 1.037e-06 -5.985 -5.984 0.001 + CO3-2 5.831e-07 3.917e-07 -6.234 -6.407 -0.173 +Ca 2.502e-03 + Ca+2 2.348e-03 1.576e-03 -2.629 -2.802 -0.173 + CaHCO3+ 1.532e-04 1.387e-04 -3.815 -3.858 -0.043 + CaCO3 1.035e-06 1.037e-06 -5.985 -5.984 0.001 + CaOH+ 3.511e-10 3.168e-10 -9.455 -9.499 -0.045 +H(0) 5.924e-10 + H2 2.962e-10 2.969e-10 -9.528 -9.527 0.001 +N(-3) 2.768e-03 + NH4+ 2.767e-03 2.483e-03 -2.558 -2.605 -0.047 + NH3 1.710e-06 1.714e-06 -5.767 -5.766 0.001 +N(0) 2.065e-05 + N2 1.032e-05 1.035e-05 -4.986 -4.985 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.767 -61.814 -0.046 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.960 -84.006 -0.046 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.327 -73.326 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.87 -9.21 -8.34 CaCO3 + Calcite -0.73 -9.21 -8.48 CaCO3 + CH4(g) -0.15 -3.01 -2.86 CH4 + CO2(g) -0.42 -1.89 -1.47 CO2 + H2(g) -6.38 -9.53 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.73 -4.99 -3.26 N2 + NH3(g) -7.54 -5.77 1.77 NH3 + O2(g) -70.37 -73.33 -2.96 O2 + +Reaction step 9. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 1.250e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 2.44e+00 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.20 6.377e-01 0.000e+00 6.367e-02 6.367e-02 +CO2(g) -0.36 4.352e-01 0.000e+00 4.345e-02 4.345e-02 +N2(g) -1.57 2.715e-02 0.000e+00 2.711e-03 2.711e-03 +NH3(g) -7.50 3.187e-08 0.000e+00 3.182e-09 3.182e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.396e-02 2.396e-02 + Ca 2.502e-03 2.502e-03 + N 3.328e-03 3.328e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.048 Charge balance + pe = -2.846 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 1.048e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.302e-03 + Total CO2 (mol/kg) = 2.308e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.107e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 19 + Total H = 1.110340e+02 + Total O = 5.555897e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.825e-07 8.960e-07 -6.008 -6.048 -0.040 + OH- 1.243e-08 1.117e-08 -7.905 -7.952 -0.047 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +C(-4) 8.781e-04 + CH4 8.781e-04 8.802e-04 -3.056 -3.055 0.001 +C(4) 2.308e-02 + CO2 1.478e-02 1.482e-02 -1.830 -1.829 0.001 + HCO3- 8.137e-03 7.351e-03 -2.090 -2.134 -0.044 + CaHCO3+ 1.616e-04 1.460e-04 -3.791 -3.836 -0.044 + CaCO3 1.004e-06 1.006e-06 -5.998 -5.997 0.001 + CO3-2 5.776e-07 3.847e-07 -6.238 -6.415 -0.177 +Ca 2.502e-03 + Ca+2 2.339e-03 1.557e-03 -2.631 -2.808 -0.177 + CaHCO3+ 1.616e-04 1.460e-04 -3.791 -3.836 -0.044 + CaCO3 1.004e-06 1.006e-06 -5.998 -5.997 0.001 + CaOH+ 3.202e-10 2.883e-10 -9.495 -9.540 -0.046 +H(0) 5.569e-10 + H2 2.784e-10 2.791e-10 -9.555 -9.554 0.001 +N(-3) 3.298e-03 + NH4+ 3.296e-03 2.951e-03 -2.482 -2.530 -0.048 + NH3 1.872e-06 1.877e-06 -5.728 -5.727 0.001 +N(0) 2.977e-05 + N2 1.489e-05 1.492e-05 -4.827 -4.826 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.682 -61.730 -0.047 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.848 -83.896 -0.047 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.273 -73.272 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.89 -9.22 -8.34 CaCO3 + Calcite -0.74 -9.22 -8.48 CaCO3 + CH4(g) -0.20 -3.06 -2.86 CH4 + CO2(g) -0.36 -1.83 -1.47 CO2 + H2(g) -6.40 -9.55 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.57 -4.83 -3.26 N2 + NH3(g) -7.50 -5.73 1.77 NH3 + O2(g) -70.31 -73.27 -2.96 O2 + +Reaction step 10. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 2.500e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 5.29e+00 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.22 5.988e-01 0.000e+00 1.294e-01 1.294e-01 +CO2(g) -0.33 4.690e-01 0.000e+00 1.013e-01 1.013e-01 +N2(g) -1.49 3.216e-02 0.000e+00 6.949e-03 6.949e-03 +NH3(g) -7.48 3.294e-08 0.000e+00 7.117e-09 7.117e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.532e-02 2.532e-02 + Ca 2.502e-03 2.502e-03 + N 3.602e-03 3.602e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.029 Charge balance + pe = -2.819 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 1.074e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.570e-03 + Total CO2 (mol/kg) = 2.450e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 23 + Total H = 1.110473e+02 + Total O = 5.556816e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.028e-06 9.364e-07 -5.988 -6.029 -0.040 + OH- 1.191e-08 1.069e-08 -7.924 -7.971 -0.047 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +C(-4) 8.246e-04 + CH4 8.246e-04 8.266e-04 -3.084 -3.083 0.001 +C(4) 2.450e-02 + CO2 1.593e-02 1.597e-02 -1.798 -1.797 0.001 + HCO3- 8.400e-03 7.581e-03 -2.076 -2.120 -0.045 + CaHCO3+ 1.659e-04 1.497e-04 -3.780 -3.825 -0.045 + CaCO3 9.846e-07 9.870e-07 -6.007 -6.006 0.001 + CO3-2 5.724e-07 3.797e-07 -6.242 -6.421 -0.178 +Ca 2.502e-03 + Ca+2 2.335e-03 1.548e-03 -2.632 -2.810 -0.179 + CaHCO3+ 1.659e-04 1.497e-04 -3.780 -3.825 -0.045 + CaCO3 9.846e-07 9.870e-07 -6.007 -6.006 0.001 + CaOH+ 3.049e-10 2.741e-10 -9.516 -9.562 -0.046 +H(0) 5.380e-10 + H2 2.690e-10 2.697e-10 -9.570 -9.569 0.001 +N(-3) 3.566e-03 + NH4+ 3.564e-03 3.187e-03 -2.448 -2.497 -0.049 + NH3 1.935e-06 1.939e-06 -5.713 -5.712 0.001 +N(0) 3.526e-05 + N2 1.763e-05 1.767e-05 -4.754 -4.753 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.642 -61.690 -0.048 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.793 -83.841 -0.048 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.243 -73.242 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.89 -9.23 -8.34 CaCO3 + Calcite -0.75 -9.23 -8.48 CaCO3 + CH4(g) -0.22 -3.08 -2.86 CH4 + CO2(g) -0.33 -1.80 -1.47 CO2 + H2(g) -6.42 -9.57 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.49 -4.75 -3.26 N2 + NH3(g) -7.48 -5.71 1.77 NH3 + O2(g) -70.28 -73.24 -2.96 O2 + +Reaction step 11. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 5.000e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 1.10e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.24 5.791e-01 0.000e+00 2.609e-01 2.609e-01 +CO2(g) -0.31 4.862e-01 0.000e+00 2.191e-01 2.191e-01 +N2(g) -1.46 3.469e-02 0.000e+00 1.563e-02 1.563e-02 +NH3(g) -7.48 3.333e-08 0.000e+00 1.502e-08 1.502e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.600e-02 2.601e-02 + Ca 2.501e-03 2.502e-03 + N 3.730e-03 3.731e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.019 Charge balance + pe = -2.806 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 1.086e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 8.694e-03 + Total CO2 (mol/kg) = 2.520e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.094e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 23 + Total H = 1.110737e+02 + Total O = 5.558262e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.051e-06 9.573e-07 -5.978 -6.019 -0.041 + OH- 1.166e-08 1.045e-08 -7.933 -7.981 -0.047 + H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 +C(-4) 7.973e-04 + CH4 7.973e-04 7.993e-04 -3.098 -3.097 0.001 +C(4) 2.520e-02 + CO2 1.651e-02 1.655e-02 -1.782 -1.781 0.001 + HCO3- 8.522e-03 7.687e-03 -2.069 -2.114 -0.045 + CaHCO3+ 1.678e-04 1.513e-04 -3.775 -3.820 -0.045 + CaCO3 9.737e-07 9.761e-07 -6.012 -6.011 0.001 + CO3-2 5.689e-07 3.766e-07 -6.245 -6.424 -0.179 +Ca 2.501e-03 + Ca+2 2.333e-03 1.543e-03 -2.632 -2.812 -0.179 + CaHCO3+ 1.678e-04 1.513e-04 -3.775 -3.820 -0.045 + CaCO3 9.737e-07 9.761e-07 -6.012 -6.011 0.001 + CaOH+ 2.975e-10 2.673e-10 -9.527 -9.573 -0.046 +H(0) 5.287e-10 + H2 2.643e-10 2.650e-10 -9.578 -9.577 0.001 +N(-3) 3.691e-03 + NH4+ 3.690e-03 3.297e-03 -2.433 -2.482 -0.049 + NH3 1.958e-06 1.962e-06 -5.708 -5.707 0.001 +N(0) 3.804e-05 + N2 1.902e-05 1.907e-05 -4.721 -4.720 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.623 -61.671 -0.048 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.767 -83.815 -0.048 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.228 -73.227 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.90 -9.24 -8.34 CaCO3 + Calcite -0.76 -9.24 -8.48 CaCO3 + CH4(g) -0.24 -3.10 -2.86 CH4 + CO2(g) -0.31 -1.78 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.46 -4.72 -3.26 N2 + NH3(g) -7.48 -5.71 1.77 NH3 + O2(g) -70.27 -73.23 -2.96 O2 + +Reaction step 12. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed-pressure gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 2. + + 1.000e+00 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1000 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.24 5.692e-01 0.000e+00 5.241e-01 5.241e-01 +CO2(g) -0.31 4.949e-01 0.000e+00 4.557e-01 4.557e-01 +N2(g) -1.44 3.595e-02 0.000e+00 3.310e-02 3.310e-02 +NH3(g) -7.48 3.349e-08 0.000e+00 3.083e-08 3.083e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.634e-02 2.636e-02 + Ca 2.500e-03 2.502e-03 + N 3.791e-03 3.794e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.014 Charge balance + pe = -2.799 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 1.091e-02 + Mass of water (kg) = 1.001e+00 + Total alkalinity (eq/kg) = 8.752e-03 + Total CO2 (mol/kg) = 2.556e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.077e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 24 + Total H = 1.111262e+02 + Total O = 5.560955e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.063e-06 9.680e-07 -5.973 -6.014 -0.041 + OH- 1.153e-08 1.034e-08 -7.938 -7.986 -0.047 + H2O 5.551e+01 9.994e-01 1.744 -0.000 0.000 +C(-4) 7.837e-04 + CH4 7.837e-04 7.857e-04 -3.106 -3.105 0.001 +C(4) 2.556e-02 + CO2 1.681e-02 1.685e-02 -1.775 -1.773 0.001 + HCO3- 8.579e-03 7.737e-03 -2.067 -2.111 -0.045 + CaHCO3+ 1.686e-04 1.520e-04 -3.773 -3.818 -0.045 + CaCO3 9.674e-07 9.698e-07 -6.014 -6.013 0.001 + CO3-2 5.667e-07 3.748e-07 -6.247 -6.426 -0.180 +Ca 2.500e-03 + Ca+2 2.331e-03 1.540e-03 -2.633 -2.812 -0.180 + CaHCO3+ 1.686e-04 1.520e-04 -3.773 -3.818 -0.045 + CaCO3 9.674e-07 9.698e-07 -6.014 -6.013 0.001 + CaOH+ 2.937e-10 2.639e-10 -9.532 -9.579 -0.047 +H(0) 5.241e-10 + H2 2.621e-10 2.627e-10 -9.582 -9.581 0.001 +N(-3) 3.752e-03 + NH4+ 3.750e-03 3.350e-03 -2.426 -2.475 -0.049 + NH3 1.967e-06 1.972e-06 -5.706 -5.705 0.001 +N(0) 3.942e-05 + N2 1.971e-05 1.976e-05 -4.705 -4.704 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.614 -61.663 -0.048 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.754 -83.802 -0.048 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.221 -73.219 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.90 -9.24 -8.34 CaCO3 + Calcite -0.76 -9.24 -8.48 CaCO3 + CH4(g) -0.24 -3.10 -2.86 CH4 + CO2(g) -0.31 -1.77 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.44 -4.70 -3.26 N2 + NH3(g) -7.48 -5.71 1.77 NH3 + O2(g) -70.26 -73.22 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + USE solution 1 + USE reaction 1 + GAS_PHASE 1 Fixed volume gas phase + fixed_volume + volume 22.5 + CO2(g) 0.0 + CH4(g) 0.0 + N2(g) 0.0 + NH3(g) 0.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 1.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0024 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -3.24 5.712e-04 0.000e+00 5.253e-04 5.253e-04 +CO2(g) -2.76 1.756e-03 0.000e+00 1.615e-03 1.615e-03 +N2(g) -4.42 3.775e-05 0.000e+00 3.472e-05 3.472e-05 +NH3(g) -9.17 6.759e-10 0.000e+00 6.216e-10 6.216e-10 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.930e-03 4.930e-03 + Ca 2.502e-03 2.502e-03 + N 5.596e-07 5.596e-07 + +----------------------------Description of solution---------------------------- + + pH = 8.204 Charge balance + pe = -4.921 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.093e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.005e-03 + Total CO2 (mol/kg) = 4.930e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110125e+02 + Total O = 5.551863e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.754e-06 1.603e-06 -5.756 -5.795 -0.039 + H+ 6.760e-09 6.246e-09 -8.170 -8.204 -0.034 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 7.871e-07 + CH4 7.871e-07 7.884e-07 -6.104 -6.103 0.001 +C(4) 4.930e-03 + HCO3- 4.640e-03 4.258e-03 -2.334 -2.371 -0.037 + CaHCO3+ 9.719e-05 8.918e-05 -4.012 -4.050 -0.037 + CaCO3 8.803e-05 8.818e-05 -4.055 -4.055 0.001 + CO2 5.969e-05 5.979e-05 -4.224 -4.223 0.001 + CO3-2 4.508e-05 3.197e-05 -4.346 -4.495 -0.149 +Ca 2.502e-03 + Ca+2 2.317e-03 1.642e-03 -2.635 -2.785 -0.150 + CaHCO3+ 9.719e-05 8.918e-05 -4.012 -4.050 -0.037 + CaCO3 8.803e-05 8.818e-05 -4.055 -4.055 0.001 + CaOH+ 4.766e-08 4.362e-08 -7.322 -7.360 -0.038 +H(0) 3.826e-10 + H2 1.913e-10 1.916e-10 -9.718 -9.718 0.001 +N(-3) 5.182e-07 + NH4+ 4.784e-07 4.362e-07 -6.320 -6.360 -0.040 + NH3 3.974e-08 3.980e-08 -7.401 -7.400 0.001 +N(0) 4.143e-08 + N2 2.071e-08 2.075e-08 -7.684 -7.683 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.716 -60.756 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -82.719 -82.758 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -72.946 -72.945 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 1.06 -7.28 -8.34 CaCO3 + Calcite 1.20 -7.28 -8.48 CaCO3 + CH4(g) -3.24 -6.10 -2.86 CH4 + CO2(g) -2.76 -4.22 -1.47 CO2 + H2(g) -6.57 -9.72 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.42 -7.68 -3.26 N2 + NH3(g) -9.17 -7.40 1.77 NH3 + O2(g) -69.98 -72.94 -2.96 O2 + +Reaction step 2. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 2.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0034 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -2.94 1.142e-03 0.000e+00 1.051e-03 1.051e-03 +CO2(g) -2.65 2.226e-03 0.000e+00 2.047e-03 2.047e-03 +N2(g) -4.12 7.549e-05 0.000e+00 6.942e-05 6.942e-05 +NH3(g) -8.95 1.134e-09 0.000e+00 1.043e-09 1.043e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 4.973e-03 4.973e-03 + Ca 2.502e-03 2.502e-03 + N 1.156e-06 1.156e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.106 Charge balance + pe = -4.847 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.132e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.005e-03 + Total CO2 (mol/kg) = 4.972e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110127e+02 + Total O = 5.551877e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.399e-06 1.278e-06 -5.854 -5.893 -0.039 + H+ 8.478e-09 7.832e-09 -8.072 -8.106 -0.034 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 1.574e-06 + CH4 1.574e-06 1.577e-06 -5.803 -5.802 0.001 +C(4) 4.972e-03 + HCO3- 4.690e-03 4.303e-03 -2.329 -2.366 -0.037 + CaHCO3+ 9.880e-05 9.064e-05 -4.005 -4.043 -0.037 + CO2 7.565e-05 7.577e-05 -4.121 -4.120 0.001 + CaCO3 7.135e-05 7.146e-05 -4.147 -4.146 0.001 + CO3-2 3.636e-05 2.576e-05 -4.439 -4.589 -0.150 +Ca 2.502e-03 + Ca+2 2.332e-03 1.651e-03 -2.632 -2.782 -0.150 + CaHCO3+ 9.880e-05 9.064e-05 -4.005 -4.043 -0.037 + CaCO3 7.135e-05 7.146e-05 -4.147 -4.146 0.001 + CaOH+ 3.823e-08 3.498e-08 -7.418 -7.456 -0.039 +H(0) 4.288e-10 + H2 2.144e-10 2.148e-10 -9.669 -9.668 0.001 +N(-3) 1.074e-06 + NH4+ 1.007e-06 9.178e-07 -5.997 -6.037 -0.040 + NH3 6.667e-08 6.678e-08 -7.176 -7.175 0.001 +N(0) 8.283e-08 + N2 4.142e-08 4.148e-08 -7.383 -7.382 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.738 -60.778 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -82.790 -82.830 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.045 -73.044 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.96 -7.37 -8.34 CaCO3 + Calcite 1.11 -7.37 -8.48 CaCO3 + CH4(g) -2.94 -5.80 -2.86 CH4 + CO2(g) -2.65 -4.12 -1.47 CO2 + H2(g) -6.52 -9.67 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.12 -7.38 -3.26 N2 + NH3(g) -8.95 -7.18 1.77 NH3 + O2(g) -70.08 -73.04 -2.96 O2 + +Reaction step 3. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 3.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0045 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -2.77 1.713e-03 0.000e+00 1.576e-03 1.576e-03 +CO2(g) -2.57 2.703e-03 0.000e+00 2.486e-03 2.486e-03 +N2(g) -3.95 1.132e-04 0.000e+00 1.041e-04 1.041e-04 +NH3(g) -8.82 1.503e-09 0.000e+00 1.382e-09 1.382e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.009e-03 5.009e-03 + Ca 2.502e-03 2.502e-03 + N 1.822e-06 1.822e-06 + +----------------------------Description of solution---------------------------- + + pH = 8.025 Charge balance + pe = -4.777 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.159e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.006e-03 + Total CO2 (mol/kg) = 5.006e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.101e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 8 + Total H = 1.110128e+02 + Total O = 5.551889e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.160e-06 1.060e-06 -5.936 -5.975 -0.039 + H+ 1.023e-08 9.445e-09 -7.990 -8.025 -0.034 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 2.361e-06 + CH4 2.361e-06 2.365e-06 -5.627 -5.626 0.001 +C(4) 5.006e-03 + HCO3- 4.724e-03 4.334e-03 -2.326 -2.363 -0.037 + CaHCO3+ 9.991e-05 9.166e-05 -4.000 -4.038 -0.037 + CO2 9.189e-05 9.204e-05 -4.037 -4.036 0.001 + CaCO3 5.983e-05 5.992e-05 -4.223 -4.222 0.001 + CO3-2 3.039e-05 2.152e-05 -4.517 -4.667 -0.150 +Ca 2.502e-03 + Ca+2 2.342e-03 1.658e-03 -2.630 -2.781 -0.150 + CaHCO3+ 9.991e-05 9.166e-05 -4.000 -4.038 -0.037 + CaCO3 5.983e-05 5.992e-05 -4.223 -4.222 0.001 + CaOH+ 3.183e-08 2.912e-08 -7.497 -7.536 -0.039 +H(0) 4.521e-10 + H2 2.260e-10 2.264e-10 -9.646 -9.645 0.001 +N(-3) 1.698e-06 + NH4+ 1.609e-06 1.467e-06 -5.793 -5.834 -0.040 + NH3 8.836e-08 8.851e-08 -7.054 -7.053 0.001 +N(0) 1.242e-07 + N2 6.210e-08 6.220e-08 -7.207 -7.206 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.766 -60.806 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -82.841 -82.881 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.091 -73.090 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.89 -7.45 -8.34 CaCO3 + Calcite 1.03 -7.45 -8.48 CaCO3 + CH4(g) -2.77 -5.63 -2.86 CH4 + CO2(g) -2.57 -4.04 -1.47 CO2 + H2(g) -6.50 -9.65 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.95 -7.21 -3.26 N2 + NH3(g) -8.82 -7.05 1.77 NH3 + O2(g) -70.13 -73.09 -2.96 O2 + +Reaction step 4. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 4.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0056 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -2.64 2.285e-03 0.000e+00 2.101e-03 2.101e-03 +CO2(g) -2.50 3.186e-03 0.000e+00 2.930e-03 2.930e-03 +N2(g) -3.82 1.508e-04 0.000e+00 1.387e-04 1.387e-04 +NH3(g) -8.74 1.817e-09 0.000e+00 1.671e-09 1.671e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.040e-03 5.039e-03 + Ca 2.502e-03 2.502e-03 + N 2.554e-06 2.554e-06 + +----------------------------Description of solution---------------------------- + + pH = 7.956 Charge balance + pe = -4.715 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.179e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.007e-03 + Total CO2 (mol/kg) = 5.036e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.089e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 8 + Total H = 1.110129e+02 + Total O = 5.551900e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 9.896e-07 9.039e-07 -6.005 -6.044 -0.039 + H+ 1.199e-08 1.107e-08 -7.921 -7.956 -0.035 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 3.148e-06 + CH4 3.148e-06 3.154e-06 -5.502 -5.501 0.001 +C(4) 5.036e-03 + HCO3- 4.750e-03 4.357e-03 -2.323 -2.361 -0.038 + CO2 1.083e-04 1.085e-04 -3.965 -3.965 0.001 + CaHCO3+ 1.007e-04 9.240e-05 -3.997 -4.034 -0.038 + CaCO3 5.144e-05 5.153e-05 -4.289 -4.288 0.001 + CO3-2 2.607e-05 1.845e-05 -4.584 -4.734 -0.150 +Ca 2.502e-03 + Ca+2 2.350e-03 1.662e-03 -2.629 -2.779 -0.150 + CaHCO3+ 1.007e-04 9.240e-05 -3.997 -4.034 -0.038 + CaCO3 5.144e-05 5.153e-05 -4.289 -4.288 0.001 + CaOH+ 2.723e-08 2.491e-08 -7.565 -7.604 -0.039 +H(0) 4.662e-10 + H2 2.331e-10 2.335e-10 -9.632 -9.632 0.001 +N(-3) 2.389e-06 + NH4+ 2.282e-06 2.079e-06 -5.642 -5.682 -0.040 + NH3 1.068e-07 1.070e-07 -6.971 -6.971 0.001 +N(0) 1.655e-07 + N2 8.276e-08 8.289e-08 -7.082 -7.081 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.793 -60.833 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -82.881 -82.921 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.117 -73.117 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.82 -7.51 -8.34 CaCO3 + Calcite 0.97 -7.51 -8.48 CaCO3 + CH4(g) -2.64 -5.50 -2.86 CH4 + CO2(g) -2.50 -3.96 -1.47 CO2 + H2(g) -6.48 -9.63 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.82 -7.08 -3.26 N2 + NH3(g) -8.74 -6.97 1.77 NH3 + O2(g) -70.16 -73.12 -2.96 O2 + +Reaction step 5. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 8.000e-03 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0100 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -2.34 4.569e-03 0.000e+00 4.202e-03 4.202e-03 +CO2(g) -2.29 5.141e-03 0.000e+00 4.728e-03 4.728e-03 +N2(g) -3.52 3.012e-04 0.000e+00 2.770e-04 2.770e-04 +NH3(g) -8.56 2.783e-09 0.000e+00 2.559e-09 2.559e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.141e-03 5.141e-03 + Ca 2.502e-03 2.502e-03 + N 6.067e-06 6.067e-06 + +----------------------------Description of solution---------------------------- + + pH = 7.753 Charge balance + pe = -4.524 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.225e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.010e-03 + Total CO2 (mol/kg) = 5.135e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.182e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 8 + Total H = 1.110133e+02 + Total O = 5.551940e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 6.208e-07 5.669e-07 -6.207 -6.246 -0.039 + H+ 1.912e-08 1.766e-08 -7.718 -7.753 -0.035 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 6.296e-06 + CH4 6.296e-06 6.307e-06 -5.201 -5.200 0.001 +C(4) 5.135e-03 + HCO3- 4.808e-03 4.409e-03 -2.318 -2.356 -0.038 + CO2 1.748e-04 1.750e-04 -3.758 -3.757 0.001 + CaHCO3+ 1.026e-04 9.408e-05 -3.989 -4.027 -0.038 + CaCO3 3.285e-05 3.290e-05 -4.483 -4.483 0.001 + CO3-2 1.656e-05 1.171e-05 -4.781 -4.931 -0.150 +Ca 2.502e-03 + Ca+2 2.367e-03 1.673e-03 -2.626 -2.777 -0.151 + CaHCO3+ 1.026e-04 9.408e-05 -3.989 -4.027 -0.038 + CaCO3 3.285e-05 3.290e-05 -4.483 -4.483 0.001 + CaOH+ 1.719e-08 1.572e-08 -7.765 -7.804 -0.039 +H(0) 4.919e-10 + H2 2.459e-10 2.464e-10 -9.609 -9.608 0.001 +N(-3) 5.737e-06 + NH4+ 5.573e-06 5.077e-06 -5.254 -5.294 -0.040 + NH3 1.636e-07 1.639e-07 -6.786 -6.785 0.001 +N(0) 3.305e-07 + N2 1.652e-07 1.655e-07 -6.782 -6.781 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.880 -60.920 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -82.992 -83.032 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.164 -73.163 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.63 -7.71 -8.34 CaCO3 + Calcite 0.77 -7.71 -8.48 CaCO3 + CH4(g) -2.34 -5.20 -2.86 CH4 + CO2(g) -2.29 -3.76 -1.47 CO2 + H2(g) -6.46 -9.61 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.52 -6.78 -3.26 N2 + NH3(g) -8.56 -6.79 1.77 NH3 + O2(g) -70.20 -73.16 -2.96 O2 + +Reaction step 6. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 1.600e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0188 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -2.04 9.136e-03 0.000e+00 8.402e-03 8.402e-03 +CO2(g) -2.04 9.088e-03 0.000e+00 8.358e-03 8.358e-03 +N2(g) -3.22 6.006e-04 0.000e+00 5.523e-04 5.523e-04 +NH3(g) -8.39 4.116e-09 0.000e+00 3.786e-09 3.786e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.311e-03 5.311e-03 + Ca 2.502e-03 2.502e-03 + N 1.533e-05 1.533e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.510 Charge balance + pe = -4.288 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.265e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.019e-03 + Total CO2 (mol/kg) = 5.299e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 8 + Total H = 1.110142e+02 + Total O = 5.552014e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 3.548e-07 3.239e-07 -6.450 -6.490 -0.040 + H+ 3.347e-08 3.090e-08 -7.475 -7.510 -0.035 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 1.259e-05 + CH4 1.259e-05 1.261e-05 -4.900 -4.899 0.001 +C(4) 5.299e-03 + HCO3- 4.857e-03 4.453e-03 -2.314 -2.351 -0.038 + CO2 3.089e-04 3.094e-04 -3.510 -3.509 0.001 + CaHCO3+ 1.041e-04 9.544e-05 -3.983 -4.020 -0.038 + CaCO3 1.904e-05 1.907e-05 -4.720 -4.720 0.001 + CO3-2 9.566e-06 6.759e-06 -5.019 -5.170 -0.151 +Ca 2.502e-03 + Ca+2 2.379e-03 1.680e-03 -2.624 -2.775 -0.151 + CaHCO3+ 1.041e-04 9.544e-05 -3.983 -4.020 -0.038 + CaCO3 1.904e-05 1.907e-05 -4.720 -4.720 0.001 + CaOH+ 9.866e-09 9.021e-09 -8.006 -8.045 -0.039 +H(0) 5.073e-10 + H2 2.536e-10 2.541e-10 -9.596 -9.595 0.001 +N(-3) 1.467e-05 + NH4+ 1.443e-05 1.314e-05 -4.841 -4.881 -0.041 + NH3 2.420e-07 2.424e-07 -6.616 -6.615 0.001 +N(0) 6.590e-07 + N2 3.295e-07 3.301e-07 -6.482 -6.481 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -60.993 -61.033 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.118 -83.158 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.191 -73.190 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.39 -7.94 -8.34 CaCO3 + Calcite 0.53 -7.94 -8.48 CaCO3 + CH4(g) -2.04 -4.90 -2.86 CH4 + CO2(g) -2.04 -3.51 -1.47 CO2 + H2(g) -6.45 -9.60 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.22 -6.48 -3.26 N2 + NH3(g) -8.39 -6.62 1.77 NH3 + O2(g) -70.23 -73.19 -2.96 O2 + +Reaction step 7. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 3.200e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0365 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -1.74 1.827e-02 0.000e+00 1.680e-02 1.680e-02 +CO2(g) -1.77 1.701e-02 0.000e+00 1.564e-02 1.564e-02 +N2(g) -2.92 1.196e-03 0.000e+00 1.100e-03 1.100e-03 +NH3(g) -8.23 5.955e-09 0.000e+00 5.476e-09 5.476e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 5.630e-03 5.630e-03 + Ca 2.502e-03 2.502e-03 + N 4.035e-05 4.035e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.242 Charge balance + pe = -4.023 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.308e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.043e-03 + Total CO2 (mol/kg) = 5.605e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110160e+02 + Total O = 5.552158e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.915e-07 1.748e-07 -6.718 -6.757 -0.040 + H+ 6.203e-08 5.726e-08 -7.207 -7.242 -0.035 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 2.517e-05 + CH4 2.517e-05 2.522e-05 -4.599 -4.598 0.001 +C(4) 5.605e-03 + HCO3- 4.906e-03 4.497e-03 -2.309 -2.347 -0.038 + CO2 5.780e-04 5.790e-04 -3.238 -3.237 0.001 + CaHCO3+ 1.054e-04 9.659e-05 -3.977 -4.015 -0.038 + CaCO3 1.040e-05 1.042e-05 -4.983 -4.982 0.001 + CO3-2 5.218e-06 3.683e-06 -5.283 -5.434 -0.151 +Ca 2.502e-03 + Ca+2 2.386e-03 1.683e-03 -2.622 -2.774 -0.152 + CaHCO3+ 1.054e-04 9.659e-05 -3.977 -4.015 -0.038 + CaCO3 1.040e-05 1.042e-05 -4.983 -4.982 0.001 + CaOH+ 5.337e-09 4.879e-09 -8.273 -8.312 -0.039 +H(0) 5.158e-10 + H2 2.579e-10 2.583e-10 -9.589 -9.588 0.001 +N(-3) 3.904e-05 + NH4+ 3.869e-05 3.523e-05 -4.412 -4.453 -0.041 + NH3 3.501e-07 3.506e-07 -6.456 -6.455 0.001 +N(0) 1.312e-06 + N2 6.561e-07 6.572e-07 -6.183 -6.182 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.122 -61.162 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.254 -83.295 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.205 -73.204 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite 0.13 -8.21 -8.34 CaCO3 + Calcite 0.27 -8.21 -8.48 CaCO3 + CH4(g) -1.74 -4.60 -2.86 CH4 + CO2(g) -1.77 -3.24 -1.47 CO2 + H2(g) -6.44 -9.59 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.92 -6.18 -3.26 N2 + NH3(g) -8.23 -6.46 1.77 NH3 + O2(g) -70.24 -73.20 -2.96 O2 + +Reaction step 8. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 6.400e-02 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.0718 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -1.44 3.653e-02 0.000e+00 3.359e-02 3.359e-02 +CO2(g) -1.48 3.285e-02 0.000e+00 3.021e-02 3.021e-02 +N2(g) -2.62 2.377e-03 0.000e+00 2.186e-03 2.186e-03 +NH3(g) -8.07 8.504e-09 0.000e+00 7.820e-09 7.820e-09 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 6.268e-03 6.268e-03 + Ca 2.502e-03 2.502e-03 + N 1.082e-04 1.082e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.963 Charge balance + pe = -3.746 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.383e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.110e-03 + Total CO2 (mol/kg) = 6.217e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 12 + Total H = 1.110195e+02 + Total O = 5.552443e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.180e-07 1.089e-07 -6.928 -6.963 -0.035 + OH- 1.008e-07 9.192e-08 -6.997 -7.037 -0.040 + H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 +C(-4) 5.033e-05 + CH4 5.033e-05 5.042e-05 -4.298 -4.297 0.001 +C(4) 6.217e-03 + HCO3- 4.985e-03 4.568e-03 -2.302 -2.340 -0.038 + CO2 1.117e-03 1.118e-03 -2.952 -2.951 0.001 + CaHCO3+ 1.071e-04 9.809e-05 -3.970 -4.008 -0.038 + CaCO3 5.553e-06 5.563e-06 -5.255 -5.255 0.001 + CO3-2 2.791e-06 1.967e-06 -5.554 -5.706 -0.152 +Ca 2.502e-03 + Ca+2 2.389e-03 1.683e-03 -2.622 -2.774 -0.152 + CaHCO3+ 1.071e-04 9.809e-05 -3.970 -4.008 -0.038 + CaCO3 5.553e-06 5.563e-06 -5.255 -5.255 0.001 + CaOH+ 2.807e-09 2.565e-09 -8.552 -8.591 -0.039 +H(0) 5.202e-10 + H2 2.601e-10 2.605e-10 -9.585 -9.584 0.001 +N(-3) 1.056e-04 + NH4+ 1.051e-04 9.568e-05 -3.978 -4.019 -0.041 + NH3 4.999e-07 5.007e-07 -6.301 -6.300 0.001 +N(0) 2.608e-06 + N2 1.304e-06 1.306e-06 -5.885 -5.884 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.258 -61.298 -0.040 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.394 -83.434 -0.040 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.213 -73.212 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.14 -8.48 -8.34 CaCO3 + Calcite -0.00 -8.48 -8.48 CaCO3 + CH4(g) -1.44 -4.30 -2.86 CH4 + CO2(g) -1.48 -2.95 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.62 -5.88 -3.26 N2 + NH3(g) -8.07 -6.30 1.77 NH3 + O2(g) -70.25 -73.21 -2.96 O2 + +Reaction step 9. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 1.250e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.1390 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -1.15 7.131e-02 0.000e+00 6.558e-02 6.558e-02 +CO2(g) -1.20 6.304e-02 0.000e+00 5.798e-02 5.798e-02 +N2(g) -2.34 4.605e-03 0.000e+00 4.235e-03 4.235e-03 +NH3(g) -7.92 1.191e-08 0.000e+00 1.096e-08 1.096e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 7.514e-03 7.514e-03 + Ca 2.502e-03 2.502e-03 + N 2.794e-04 2.794e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.694 Charge balance + pe = -3.478 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.551e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.278e-03 + Total CO2 (mol/kg) = 7.416e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 18 + Total H = 1.110264e+02 + Total O = 5.552991e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.192e-07 2.021e-07 -6.659 -6.694 -0.035 + OH- 5.433e-08 4.952e-08 -7.265 -7.305 -0.040 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 9.827e-05 + CH4 9.827e-05 9.844e-05 -4.008 -4.007 0.001 +C(4) 7.416e-03 + HCO3- 5.158e-03 4.722e-03 -2.288 -2.326 -0.038 + CO2 2.143e-03 2.146e-03 -2.669 -2.668 0.001 + CaHCO3+ 1.103e-04 1.010e-04 -3.957 -3.996 -0.038 + CaCO3 3.080e-06 3.086e-06 -5.511 -5.511 0.001 + CO3-2 1.560e-06 1.096e-06 -5.807 -5.960 -0.153 +Ca 2.502e-03 + Ca+2 2.388e-03 1.677e-03 -2.622 -2.776 -0.154 + CaHCO3+ 1.103e-04 1.010e-04 -3.957 -3.996 -0.038 + CaCO3 3.080e-06 3.086e-06 -5.511 -5.511 0.001 + CaOH+ 1.508e-09 1.376e-09 -8.822 -8.861 -0.040 +H(0) 5.224e-10 + H2 2.612e-10 2.617e-10 -9.583 -9.582 0.001 +N(-3) 2.744e-04 + NH4+ 2.737e-04 2.488e-04 -3.563 -3.604 -0.041 + NH3 7.003e-07 7.015e-07 -6.155 -6.154 0.001 +N(0) 5.053e-06 + N2 2.526e-06 2.531e-06 -5.597 -5.597 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.385 -61.426 -0.041 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.523 -83.564 -0.041 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.216 -73.216 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.40 -8.74 -8.34 CaCO3 + Calcite -0.26 -8.74 -8.48 CaCO3 + CH4(g) -1.15 -4.01 -2.86 CH4 + CO2(g) -1.20 -2.67 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.34 -5.60 -3.26 N2 + NH3(g) -7.92 -6.15 1.77 NH3 + O2(g) -70.26 -73.22 -2.96 O2 + +Reaction step 10. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 2.500e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.2765 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.85 1.426e-01 0.000e+00 1.311e-01 1.311e-01 +CO2(g) -0.90 1.249e-01 0.000e+00 1.148e-01 1.148e-01 +N2(g) -2.04 9.123e-03 0.000e+00 8.390e-03 8.390e-03 +NH3(g) -7.77 1.683e-08 0.000e+00 1.547e-08 1.547e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.015e-02 1.015e-02 + Ca 2.502e-03 2.502e-03 + N 7.205e-04 7.206e-04 + +----------------------------Description of solution---------------------------- + + pH = 6.432 Charge balance + pe = -3.216 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 7.974e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.714e-03 + Total CO2 (mol/kg) = 9.953e-03 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.110405e+02 + Total O = 5.554122e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 4.021e-07 3.702e-07 -6.396 -6.432 -0.036 + OH- 2.973e-08 2.704e-08 -7.527 -7.568 -0.041 + H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 +C(-4) 1.964e-04 + CH4 1.964e-04 1.968e-04 -3.707 -3.706 0.001 +C(4) 9.953e-03 + HCO3- 5.589e-03 5.106e-03 -2.253 -2.292 -0.039 + CO2 4.243e-03 4.251e-03 -2.372 -2.372 0.001 + CaHCO3+ 1.182e-04 1.080e-04 -3.927 -3.967 -0.039 + CaCO3 1.798e-06 1.802e-06 -5.745 -5.744 0.001 + CO3-2 9.288e-07 6.469e-07 -6.032 -6.189 -0.157 +Ca 2.502e-03 + Ca+2 2.382e-03 1.658e-03 -2.623 -2.780 -0.157 + CaHCO3+ 1.182e-04 1.080e-04 -3.927 -3.967 -0.039 + CaCO3 1.798e-06 1.802e-06 -5.745 -5.744 0.001 + CaOH+ 8.158e-10 7.431e-10 -9.088 -9.129 -0.041 +H(0) 5.236e-10 + H2 2.618e-10 2.623e-10 -9.582 -9.581 0.001 +N(-3) 7.105e-04 + NH4+ 7.095e-04 6.436e-04 -3.149 -3.191 -0.042 + NH3 9.890e-07 9.908e-07 -6.005 -6.004 0.001 +N(0) 1.001e-05 + N2 5.004e-06 5.013e-06 -5.301 -5.300 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.500 -61.542 -0.042 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.639 -83.681 -0.042 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.219 -73.218 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.63 -8.97 -8.34 CaCO3 + Calcite -0.49 -8.97 -8.48 CaCO3 + CH4(g) -0.85 -3.71 -2.86 CH4 + CO2(g) -0.90 -2.37 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.04 -5.30 -3.26 N2 + NH3(g) -7.77 -6.00 1.77 NH3 + O2(g) -70.26 -73.22 -2.96 O2 + +Reaction step 11. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 5.000e-01 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 0.5515 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.55 2.850e-01 0.000e+00 2.621e-01 2.621e-01 +CO2(g) -0.60 2.484e-01 0.000e+00 2.284e-01 2.284e-01 +N2(g) -1.74 1.809e-02 0.000e+00 1.663e-02 1.663e-02 +NH3(g) -7.62 2.373e-08 0.000e+00 2.183e-08 2.183e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 1.554e-02 1.555e-02 + Ca 2.501e-03 2.502e-03 + N 1.731e-03 1.732e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.201 Charge balance + pe = -2.986 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 8.940e-03 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 6.713e-03 + Total CO2 (mol/kg) = 1.515e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 10 + Total H = 1.110691e+02 + Total O = 5.556400e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.859e-07 6.290e-07 -6.164 -6.201 -0.038 + OH- 1.758e-08 1.591e-08 -7.755 -7.798 -0.043 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +C(-4) 3.926e-04 + CH4 3.926e-04 3.934e-04 -3.406 -3.405 0.001 +C(4) 1.515e-02 + CO2 8.439e-03 8.457e-03 -2.074 -2.073 0.001 + HCO3- 6.573e-03 5.978e-03 -2.182 -2.223 -0.041 + CaHCO3+ 1.355e-04 1.233e-04 -3.868 -3.909 -0.041 + CaCO3 1.208e-06 1.210e-06 -5.918 -5.917 0.001 + CO3-2 6.516e-07 4.457e-07 -6.186 -6.351 -0.165 +Ca 2.501e-03 + Ca+2 2.364e-03 1.616e-03 -2.626 -2.792 -0.165 + CaHCO3+ 1.355e-04 1.233e-04 -3.868 -3.909 -0.041 + CaCO3 1.208e-06 1.210e-06 -5.918 -5.917 0.001 + CaOH+ 4.702e-10 4.262e-10 -9.328 -9.370 -0.043 +H(0) 5.241e-10 + H2 2.620e-10 2.626e-10 -9.582 -9.581 0.001 +N(-3) 1.711e-03 + NH4+ 1.710e-03 1.543e-03 -2.767 -2.812 -0.045 + NH3 1.395e-06 1.398e-06 -5.856 -5.855 0.001 +N(0) 1.984e-05 + N2 9.920e-06 9.940e-06 -5.004 -5.003 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.580 -61.624 -0.044 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.719 -83.764 -0.044 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.220 -73.219 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.81 -9.14 -8.34 CaCO3 + Calcite -0.66 -9.14 -8.48 CaCO3 + CH4(g) -0.55 -3.41 -2.86 CH4 + CO2(g) -0.60 -2.07 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.74 -5.00 -3.26 N2 + NH3(g) -7.62 -5.85 1.77 NH3 + O2(g) -70.26 -73.22 -2.96 O2 + +Reaction step 12. + +Using solution 1. Solution after simulation 1. +Using gas phase 1. Fixed volume gas phase +Using reaction 1. + +Reaction 1. Irreversible reaction defined in simulation 3. + + 1.000e+00 moles of the following reaction have been added: + + Relative + Reactant moles + + CH2O(NH3)0.07 1.00 + + Relative + Element moles + C 1.00 + H 2.21 + N 0.07 + O 1.00 + +-----------------------------------Gas phase----------------------------------- + + +Total pressure: 1.1013 atmospheres + Gas volume: 2.25e+01 liters + + Moles in gas + ---------------------------------- +Component log P P Initial Final Delta +CH4(g) -0.24 5.698e-01 0.000e+00 5.241e-01 5.241e-01 +CO2(g) -0.31 4.954e-01 0.000e+00 4.556e-01 4.556e-01 +N2(g) -1.44 3.599e-02 0.000e+00 3.310e-02 3.310e-02 +NH3(g) -7.47 3.351e-08 0.000e+00 3.081e-08 3.081e-08 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + C 2.636e-02 2.638e-02 + Ca 2.500e-03 2.502e-03 + N 3.796e-03 3.799e-03 + +----------------------------Description of solution---------------------------- + + pH = 6.014 Charge balance + pe = -2.799 Adjusted to redox equilibrium + Activity of water = 0.999 + Ionic strength = 1.092e-02 + Mass of water (kg) = 1.001e+00 + Total alkalinity (eq/kg) = 8.756e-03 + Total CO2 (mol/kg) = 2.558e-02 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.075e-10 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 13 + Total H = 1.111262e+02 + Total O = 5.560960e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.064e-06 9.687e-07 -5.973 -6.014 -0.041 + OH- 1.152e-08 1.033e-08 -7.938 -7.986 -0.048 + H2O 5.551e+01 9.994e-01 1.744 -0.000 0.000 +C(-4) 7.846e-04 + CH4 7.846e-04 7.866e-04 -3.105 -3.104 0.001 +C(4) 2.558e-02 + CO2 1.683e-02 1.687e-02 -1.774 -1.773 0.001 + HCO3- 8.584e-03 7.741e-03 -2.066 -2.111 -0.045 + CaHCO3+ 1.687e-04 1.521e-04 -3.773 -3.818 -0.045 + CaCO3 9.672e-07 9.696e-07 -6.014 -6.013 0.001 + CO3-2 5.667e-07 3.748e-07 -6.247 -6.426 -0.180 +Ca 2.500e-03 + Ca+2 2.330e-03 1.540e-03 -2.633 -2.812 -0.180 + CaHCO3+ 1.687e-04 1.521e-04 -3.773 -3.818 -0.045 + CaCO3 9.672e-07 9.696e-07 -6.014 -6.013 0.001 + CaOH+ 2.935e-10 2.637e-10 -9.532 -9.579 -0.047 +H(0) 5.241e-10 + H2 2.621e-10 2.627e-10 -9.582 -9.581 0.001 +N(-3) 3.756e-03 + NH4+ 3.754e-03 3.354e-03 -2.425 -2.474 -0.049 + NH3 1.968e-06 1.973e-06 -5.706 -5.705 0.001 +N(0) 3.946e-05 + N2 1.973e-05 1.978e-05 -4.705 -4.704 0.001 +N(3) 0.000e+00 + NO2- 0.000e+00 0.000e+00 -61.615 -61.663 -0.048 +N(5) 0.000e+00 + NO3- 0.000e+00 0.000e+00 -83.754 -83.802 -0.048 +O(0) 0.000e+00 + O2 0.000e+00 0.000e+00 -73.221 -73.219 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Aragonite -0.90 -9.24 -8.34 CaCO3 + Calcite -0.76 -9.24 -8.48 CaCO3 + CH4(g) -0.24 -3.10 -2.86 CH4 + CO2(g) -0.31 -1.77 -1.47 CO2 + H2(g) -6.43 -9.58 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -1.44 -4.70 -3.26 N2 + NH3(g) -7.47 -5.70 1.77 NH3 + O2(g) -70.26 -73.22 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex7.sel b/Sun/examples/ex7.sel new file mode 100644 index 00000000..e4582478 --- /dev/null +++ b/Sun/examples/ex7.sel @@ -0,0 +1,27 @@ + sim state reaction si_CO2(g) si_CH4(g) si_N2(g) si_NH3(g) pressure total mol volume g_CO2(g) g_CH4(g) g_N2(g) g_NH3(g) + 1 i_soln -99 -999.9990 -999.9990 -999.9990 -999.9990 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 + 1 react -99 -1.5000 -26.2591 -999.9990 -999.9990 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 + 2 react 1.0000e-03 -1.3544 -0.4402 -3.8961 -8.3809 1.1000e+00 1.0000e-25 2.2242e-24 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 + 2 react 2.0000e-03 -1.2453 -0.1392 -3.6436 -8.1826 1.1000e+00 1.0000e-25 2.2242e-24 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 + 2 react 3.0000e-03 -1.1592 0.0130 -3.5015 -8.0869 1.1000e+00 8.5793e-05 1.9082e-03 5.4061e-06 8.0362e-05 2.4578e-08 6.3856e-13 + 2 react 4.0000e-03 -1.0929 0.0081 -3.3212 -8.0234 1.1000e+00 6.4416e-04 1.4327e-02 4.7279e-05 5.9660e-04 2.7953e-07 5.5492e-12 + 2 react 8.0000e-03 -0.9101 -0.0107 -2.9007 -7.8887 1.1000e+00 2.9972e-03 6.6664e-02 3.3511e-04 2.6587e-03 3.4247e-06 3.5204e-11 + 2 react 1.6000e-02 -0.7156 -0.0438 -2.4738 -7.7606 1.1000e+00 8.2421e-03 1.8332e-01 1.4423e-03 6.7746e-03 2.5169e-05 1.3002e-10 + 2 react 3.2000e-02 -0.5438 -0.0941 -2.0462 -7.6302 1.1000e+00 2.0521e-02 4.5644e-01 5.3332e-03 1.5021e-02 1.6775e-04 4.3718e-10 + 2 react 6.4000e-02 -0.4248 -0.1517 -1.7252 -7.5359 1.1000e+00 4.9404e-02 1.0988e+00 1.6888e-02 3.1671e-02 8.4558e-04 1.3075e-09 + 2 react 1.2500e-01 -0.3613 -0.1954 -1.5662 -7.4966 1.1000e+00 1.0982e-01 2.4427e+00 4.3447e-02 6.3666e-02 2.7111e-03 3.1820e-09 + 2 react 2.5000e-01 -0.3288 -0.2227 -1.4927 -7.4823 1.1000e+00 2.3770e-01 5.2868e+00 1.0135e-01 1.2940e-01 6.9491e-03 7.1171e-09 + 2 react 5.0000e-01 -0.3131 -0.2373 -1.4597 -7.4772 1.1000e+00 4.9570e-01 1.1025e+01 2.1912e-01 2.6094e-01 1.5635e-02 1.5019e-08 + 2 react 1.0000e+00 -0.3055 -0.2448 -1.4443 -7.4751 1.1000e+00 1.0128e+00 2.2527e+01 4.5565e-01 5.2406e-01 3.3103e-02 3.0832e-08 + 3 react 1.0000e-03 -2.7554 -3.2432 -4.4230 -9.1701 2.3652e-03 2.1751e-03 2.2500e+01 1.6151e-03 5.2527e-04 3.4720e-05 6.2162e-10 + 3 react 2.0000e-03 -2.6525 -2.9422 -4.1221 -8.9453 3.4435e-03 3.1668e-03 2.2500e+01 2.0468e-03 1.0505e-03 6.9421e-05 1.0430e-09 + 3 react 3.0000e-03 -2.5681 -2.7661 -3.9462 -8.8230 4.5301e-03 4.1661e-03 2.2500e+01 2.4862e-03 1.5758e-03 1.0409e-04 1.3823e-09 + 3 react 4.0000e-03 -2.4967 -2.6412 -3.8215 -8.7406 5.6217e-03 5.1699e-03 2.2500e+01 2.9303e-03 2.1010e-03 1.3872e-04 1.6713e-09 + 3 react 8.0000e-03 -2.2889 -2.3402 -3.5212 -8.5555 1.0011e-02 9.2068e-03 2.2500e+01 4.7283e-03 4.2016e-03 2.7697e-04 2.5595e-09 + 3 react 1.6000e-02 -2.0415 -2.0392 -3.2214 -8.3855 1.8825e-02 1.7312e-02 2.2500e+01 8.3576e-03 8.4019e-03 5.5233e-04 3.7856e-09 + 3 react 3.2000e-02 -1.7694 -1.7383 -2.9223 -8.2251 3.6471e-02 3.3540e-02 2.2500e+01 1.5640e-02 1.6800e-02 1.0998e-03 5.4762e-09 + 3 react 6.4000e-02 -1.4834 -1.4374 -2.6240 -8.0704 7.1755e-02 6.5989e-02 2.2500e+01 3.0213e-02 3.3590e-02 2.1859e-03 7.8205e-09 + 3 react 1.2500e-01 -1.2004 -1.1468 -2.3367 -7.9240 1.3896e-01 1.2779e-01 2.2500e+01 5.7976e-02 6.5580e-02 4.2353e-03 1.0956e-08 + 3 react 2.5000e-01 -0.9036 -0.8460 -2.0399 -7.7740 2.7653e-01 2.5431e-01 2.2500e+01 1.1482e-01 1.3110e-01 8.3897e-03 1.5474e-08 + 3 react 5.0000e-01 -0.6049 -0.5452 -1.7426 -7.6246 5.5147e-01 5.0716e-01 2.2500e+01 2.2843e-01 2.6209e-01 1.6634e-02 2.1827e-08 + 3 react 1.0000e+00 -0.3050 -0.2442 -1.4438 -7.4749 1.1013e+00 1.0128e+00 2.2500e+01 4.5563e-01 5.2406e-01 3.3101e-02 3.0813e-08 diff --git a/Sun/examples/ex8.log b/Sun/examples/ex8.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex8.out b/Sun/examples/ex8.out new file mode 100644 index 00000000..5afdec15 --- /dev/null +++ b/Sun/examples/ex8.out @@ -0,0 +1,3612 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex8 + Output file: ex8.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 8.--Sorption of zinc on hydrous + iron oxides. + SURFACE_SPECIES + Hfo_sOH + H+ = Hfo_sOH2+ + log_k 7.18 + Hfo_sOH = Hfo_sO- + H+ + log_k -8.82 + Hfo_sOH + Zn+2 = Hfo_sOZn+ + H+ + log_k 0.66 + Hfo_wOH + H+ = Hfo_wOH2+ + log_k 7.18 + Hfo_wOH = Hfo_wO- + H+ + log_k -8.82 + Hfo_wOH + Zn+2 = Hfo_wOZn+ + H+ + log_k -2.32 + SURFACE 1 + Hfo_sOH 5e-6 600. 0.09 + Hfo_wOH 2e-4 + SOLUTION 1 + units mmol/kgw + pH 8.0 + Zn 0.0001 + Na 100. charge + N(5) 100. + SOLUTION 2 + units mmol/kgw + pH 8.0 + Zn 0.1 + Na 100. charge + N(5) 100. + USE solution none + PHASES + Fix_H+ + H+ = H+ + log_k 0.0 + END +----- +TITLE +----- + + Example 8.--Sorption of zinc on hydrous + iron oxides. + +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N(5) 1.000e-01 1.000e-01 + Na 1.000e-01 1.000e-01 Charge balance + Zn 1.000e-07 1.000e-07 + +----------------------------Description of solution---------------------------- + + pH = 8.000 + pe = 4.000 + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.361e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.936e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 9 + Total H = 1.110124e+02 + Total O = 5.580622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 + H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 1.384e-27 + H2 6.918e-28 7.079e-28 -27.160 -27.150 0.010 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 1.000e-01 + Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 + NaOH 5.038e-08 5.155e-08 -7.298 -7.288 0.010 +O(0) 1.615e-38 + O2 8.073e-39 8.261e-39 -38.093 -38.083 0.010 +Zn 1.000e-07 + Zn+2 9.102e-08 3.428e-08 -7.041 -7.465 -0.424 + ZnOH+ 4.793e-09 3.746e-09 -8.319 -8.426 -0.107 + Zn(OH)2 4.189e-09 4.286e-09 -8.378 -8.368 0.010 + Zn(OH)3- 1.729e-12 1.351e-12 -11.762 -11.869 -0.107 + Zn(OH)4-2 5.721e-17 2.134e-17 -16.243 -16.671 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -8.00 -8.00 0.00 H+ + H2(g) -24.00 -27.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -35.12 -38.08 -2.96 O2 + Zn(OH)2(e) -2.97 8.53 11.50 Zn(OH)2 + +Initial solution 2. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N(5) 1.000e-01 1.000e-01 + Na 9.981e-02 9.981e-02 Charge balance + Zn 1.000e-04 1.000e-04 + +----------------------------Description of solution---------------------------- + + pH = 8.000 + pe = 4.000 + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.452e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 7.433e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 9 + Total H = 1.110124e+02 + Total O = 5.580623e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 + H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 1.384e-27 + H2 6.918e-28 7.079e-28 -27.160 -27.150 0.010 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.981e-02 + Na+ 9.981e-02 7.814e-02 -1.001 -1.107 -0.106 + NaOH 5.028e-08 5.145e-08 -7.299 -7.289 0.010 +O(0) 1.615e-38 + O2 8.073e-39 8.261e-39 -38.093 -38.083 0.010 +Zn 1.000e-04 + Zn+2 9.102e-05 3.427e-05 -4.041 -4.465 -0.424 + ZnOH+ 4.792e-06 3.745e-06 -5.319 -5.427 -0.107 + Zn(OH)2 4.187e-06 4.285e-06 -5.378 -5.368 0.010 + Zn(OH)3- 1.728e-09 1.350e-09 -8.762 -8.870 -0.107 + Zn(OH)4-2 5.721e-14 2.133e-14 -13.243 -13.671 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -8.00 -8.00 0.00 H+ + H2(g) -24.00 -27.15 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + O2(g) -35.12 -38.08 -2.96 O2 + Zn(OH)2(e) 0.03 11.53 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SELECTED_OUTPUT + file ex8.sel + molalities Zn+2 Hfo_wOZn+ Hfo_sOZn+ + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.00 -5.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.273e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 1.123e-04 Surface charge, eq + 2.007e-01 sigma, C/m**2 + 1.228e-01 psi, V + -4.778e+00 -F*psi/RT + 8.410e-03 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH2+ 2.778e-06 0.556 2.778e-06 -5.556 + Hfo_sOH 2.182e-06 0.436 2.182e-06 -5.661 + Hfo_sO- 3.928e-08 0.008 3.928e-08 -7.406 + Hfo_sOZn+ 3.150e-10 0.000 3.150e-10 -9.502 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH2+ 1.111e-04 0.556 1.111e-04 -3.954 + Hfo_wOH 8.730e-05 0.437 8.730e-05 -4.059 + Hfo_wO- 1.571e-06 0.008 1.571e-06 -5.804 + Hfo_wOZn+ 1.319e-11 0.000 1.319e-11 -10.880 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.987e-02 9.987e-02 + Zn 9.967e-08 9.967e-08 + +----------------------------Description of solution---------------------------- + + pH = 5.000 Charge balance + pe = 15.095 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.994e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.211e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.123e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.06 + Iterations = 17 + Total H = 1.110122e+02 + Total O = 5.580609e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.211e-05 1.000e-05 -4.917 -5.000 -0.083 + OH- 1.309e-09 9.977e-10 -8.883 -9.001 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.349 -43.339 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -52.670 -52.798 -0.128 + NH3 0.000e+00 0.000e+00 -57.052 -57.042 0.010 +N(0) 1.543e-06 + N2 7.717e-07 7.897e-07 -6.113 -6.103 0.010 +N(3) 2.412e-13 + NO2- 2.412e-13 1.818e-13 -12.618 -12.740 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.987e-02 + Na+ 9.987e-02 7.819e-02 -1.001 -1.107 -0.106 + NaOH 5.032e-11 5.149e-11 -10.298 -10.288 0.010 +O(0) 3.859e-06 + O2 1.929e-06 1.974e-06 -5.715 -5.705 0.010 +Zn 9.967e-08 + Zn+2 9.967e-08 3.754e-08 -7.001 -7.425 -0.424 + ZnOH+ 5.250e-12 4.103e-12 -11.280 -11.387 -0.107 + Zn(OH)2 4.588e-15 4.695e-15 -14.338 -14.328 0.010 + Zn(OH)3- 1.893e-21 1.479e-21 -20.723 -20.830 -0.107 + Zn(OH)4-2 6.265e-29 2.337e-29 -28.203 -28.631 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.00 -5.00 0.00 H+ + H2(g) -40.19 -43.34 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.84 -6.10 -3.26 N2 + NH3(g) -58.81 -57.04 1.77 NH3 + O2(g) -2.74 -5.70 -2.96 O2 + Zn(OH)2(e) -8.93 2.57 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.25 -5.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.060e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 9.671e-05 Surface charge, eq + 1.728e-01 sigma, C/m**2 + 1.152e-01 psi, V + -4.485e+00 -F*psi/RT + 1.127e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 2.520e-06 0.504 2.520e-06 -5.599 + Hfo_sOH2+ 2.419e-06 0.484 2.419e-06 -5.616 + Hfo_sO- 6.017e-08 0.012 6.017e-08 -7.221 + Hfo_sOZn+ 8.622e-10 0.000 8.622e-10 -9.064 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.008e-04 0.504 1.008e-04 -3.996 + Hfo_wOH2+ 9.676e-05 0.484 9.676e-05 -4.014 + Hfo_wO- 2.407e-06 0.012 2.407e-06 -5.618 + Hfo_wOZn+ 3.612e-11 0.000 3.612e-11 -10.442 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.990e-02 9.990e-02 + Zn 9.910e-08 9.910e-08 + +----------------------------Description of solution---------------------------- + + pH = 5.250 Charge balance + pe = 14.809 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.995e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.809e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -9.671e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 17 + Total H = 1.110122e+02 + Total O = 5.580611e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.812e-06 5.623e-06 -5.167 -5.250 -0.083 + OH- 2.329e-09 1.774e-09 -8.633 -8.751 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.278 -43.268 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -52.884 -53.012 -0.128 + NH3 0.000e+00 0.000e+00 -57.017 -57.007 0.010 +N(0) 1.111e-06 + N2 5.554e-07 5.683e-07 -6.255 -6.245 0.010 +N(3) 2.843e-13 + NO2- 2.843e-13 2.143e-13 -12.546 -12.669 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.990e-02 + Na+ 9.990e-02 7.821e-02 -1.000 -1.107 -0.106 + NaOH 8.949e-11 9.158e-11 -10.048 -10.038 0.010 +O(0) 2.777e-06 + O2 1.388e-06 1.421e-06 -5.857 -5.847 0.010 +Zn 9.910e-08 + Zn+2 9.909e-08 3.733e-08 -7.004 -7.428 -0.424 + ZnOH+ 9.281e-12 7.254e-12 -11.032 -11.139 -0.107 + Zn(OH)2 1.442e-14 1.476e-14 -13.841 -13.831 0.010 + Zn(OH)3- 1.058e-20 8.272e-21 -19.975 -20.082 -0.107 + Zn(OH)4-2 6.228e-28 2.323e-28 -27.206 -27.634 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.25 -5.25 0.00 H+ + H2(g) -40.12 -43.27 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.99 -6.25 -3.26 N2 + NH3(g) -58.78 -57.01 1.77 NH3 + O2(g) -2.89 -5.85 -2.96 O2 + Zn(OH)2(e) -8.43 3.07 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 4. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.50 -5.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 8.815e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 8.217e-05 Surface charge, eq + 1.468e-01 sigma, C/m**2 + 1.071e-01 psi, V + -4.168e+00 -F*psi/RT + 1.549e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 2.820e-06 0.564 2.820e-06 -5.550 + Hfo_sOH2+ 2.090e-06 0.418 2.090e-06 -5.680 + Hfo_sO- 8.716e-08 0.017 8.716e-08 -7.060 + Hfo_sOZn+ 2.320e-09 0.000 2.320e-09 -8.635 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.129e-04 0.564 1.129e-04 -3.947 + Hfo_wOH2+ 8.365e-05 0.418 8.365e-05 -4.078 + Hfo_wO- 3.488e-06 0.017 3.488e-06 -5.457 + Hfo_wOZn+ 9.722e-11 0.000 9.722e-11 -10.012 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.991e-02 9.991e-02 + Zn 9.758e-08 9.758e-08 + +----------------------------Description of solution---------------------------- + + pH = 5.500 Charge balance + pe = 14.523 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.996e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.826e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -8.217e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.04 + Iterations = 16 + Total H = 1.110123e+02 + Total O = 5.580613e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.830e-06 3.162e-06 -5.417 -5.500 -0.083 + OH- 4.141e-09 3.155e-09 -8.383 -8.501 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.206 -43.196 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.099 -53.227 -0.128 + NH3 0.000e+00 0.000e+00 -56.981 -56.971 0.010 +N(0) 7.994e-07 + N2 3.997e-07 4.090e-07 -6.398 -6.388 0.010 +N(3) 3.351e-13 + NO2- 3.351e-13 2.526e-13 -12.475 -12.598 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.991e-02 + Na+ 9.991e-02 7.822e-02 -1.000 -1.107 -0.106 + NaOH 1.592e-10 1.629e-10 -9.798 -9.788 0.010 +O(0) 1.998e-06 + O2 9.992e-07 1.023e-06 -6.000 -5.990 0.010 +Zn 9.758e-08 + Zn+2 9.757e-08 3.675e-08 -7.011 -7.435 -0.424 + ZnOH+ 1.625e-11 1.270e-11 -10.789 -10.896 -0.107 + Zn(OH)2 4.491e-14 4.595e-14 -13.348 -13.338 0.010 + Zn(OH)3- 5.860e-20 4.580e-20 -19.232 -19.339 -0.107 + Zn(OH)4-2 6.133e-27 2.288e-27 -26.212 -26.641 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.50 -5.50 0.00 H+ + H2(g) -40.05 -43.20 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.13 -6.39 -3.26 N2 + NH3(g) -58.74 -56.97 1.77 NH3 + O2(g) -3.03 -5.99 -2.96 O2 + Zn(OH)2(e) -7.94 3.56 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 5. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.75 -5.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 7.298e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 6.891e-05 Surface charge, eq + 1.231e-01 sigma, C/m**2 + 9.836e-02 psi, V + -3.829e+00 -F*psi/RT + 2.174e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.075e-06 0.615 3.075e-06 -5.512 + Hfo_sOH2+ 1.799e-06 0.360 1.799e-06 -5.745 + Hfo_sO- 1.204e-07 0.024 1.204e-07 -6.919 + Hfo_sOZn+ 6.061e-09 0.001 6.061e-09 -8.217 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.231e-04 0.616 1.231e-04 -3.910 + Hfo_wOH2+ 7.205e-05 0.360 7.205e-05 -4.142 + Hfo_wO- 4.821e-06 0.024 4.821e-06 -5.317 + Hfo_wOZn+ 2.542e-10 0.000 2.542e-10 -9.595 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.993e-02 9.993e-02 + Zn 9.368e-08 9.368e-08 + +----------------------------Description of solution---------------------------- + + pH = 5.750 Charge balance + pe = 14.237 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.997e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -2.146e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.891e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 + Iterations = 15 + Total H = 1.110123e+02 + Total O = 5.580615e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.154e-06 1.778e-06 -5.667 -5.750 -0.083 + OH- 7.364e-09 5.610e-09 -8.133 -8.251 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.135 -43.125 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.313 -53.441 -0.128 + NH3 0.000e+00 0.000e+00 -56.945 -56.935 0.010 +N(0) 5.753e-07 + N2 2.877e-07 2.944e-07 -6.541 -6.531 0.010 +N(3) 3.950e-13 + NO2- 3.950e-13 2.977e-13 -12.403 -12.526 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.993e-02 + Na+ 9.993e-02 7.824e-02 -1.000 -1.107 -0.106 + NaOH 2.831e-10 2.897e-10 -9.548 -9.538 0.010 +O(0) 1.438e-06 + O2 7.191e-07 7.359e-07 -6.143 -6.133 0.010 +Zn 9.368e-08 + Zn+2 9.366e-08 3.528e-08 -7.028 -7.452 -0.424 + ZnOH+ 2.774e-11 2.168e-11 -10.557 -10.664 -0.107 + Zn(OH)2 1.363e-13 1.395e-13 -12.865 -12.855 0.010 + Zn(OH)3- 3.163e-19 2.472e-19 -18.500 -18.607 -0.107 + Zn(OH)4-2 5.887e-26 2.196e-26 -25.230 -25.658 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.75 -5.75 0.00 H+ + H2(g) -39.97 -43.12 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.27 -6.53 -3.26 N2 + NH3(g) -58.71 -56.94 1.77 NH3 + O2(g) -3.17 -6.13 -2.96 O2 + Zn(OH)2(e) -7.46 4.04 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 6. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.00 -6.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 5.997e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 5.703e-05 Surface charge, eq + 1.019e-01 sigma, C/m**2 + 8.913e-02 psi, V + -3.469e+00 -F*psi/RT + 3.114e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.280e-06 0.656 3.280e-06 -5.484 + Hfo_sOH2+ 1.546e-06 0.309 1.546e-06 -5.811 + Hfo_sO- 1.594e-07 0.032 1.594e-07 -6.797 + Hfo_sOZn+ 1.486e-08 0.003 1.486e-08 -7.828 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.316e-04 0.658 1.316e-04 -3.881 + Hfo_wOH2+ 6.202e-05 0.310 6.202e-05 -4.207 + Hfo_wO- 6.395e-06 0.032 6.395e-06 -5.194 + Hfo_wOZn+ 6.241e-10 0.000 6.241e-10 -9.205 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.994e-02 9.994e-02 + Zn 8.452e-08 8.452e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.000 Charge balance + pe = 13.952 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.997e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.198e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.703e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 + Iterations = 15 + Total H = 1.110123e+02 + Total O = 5.580616e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.211e-06 1.000e-06 -5.917 -6.000 -0.083 + OH- 1.310e-08 9.977e-09 -7.883 -8.001 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.063 -43.053 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.527 -53.655 -0.128 + NH3 0.000e+00 0.000e+00 -56.909 -56.899 0.010 +N(0) 4.140e-07 + N2 2.070e-07 2.118e-07 -6.684 -6.674 0.010 +N(3) 4.656e-13 + NO2- 4.656e-13 3.509e-13 -12.332 -12.455 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.994e-02 + Na+ 9.994e-02 7.824e-02 -1.000 -1.107 -0.106 + NaOH 5.035e-10 5.152e-10 -9.298 -9.288 0.010 +O(0) 1.035e-06 + O2 5.176e-07 5.296e-07 -6.286 -6.276 0.010 +Zn 8.452e-08 + Zn+2 8.448e-08 3.182e-08 -7.073 -7.497 -0.424 + ZnOH+ 4.449e-11 3.477e-11 -10.352 -10.459 -0.107 + Zn(OH)2 3.888e-13 3.979e-13 -12.410 -12.400 0.010 + Zn(OH)3- 1.604e-18 1.254e-18 -17.795 -17.902 -0.107 + Zn(OH)4-2 5.310e-25 1.981e-25 -24.275 -24.703 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.00 -6.00 0.00 H+ + H2(g) -39.90 -43.05 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.41 -6.67 -3.26 N2 + NH3(g) -58.67 -56.90 1.77 NH3 + O2(g) -3.32 -6.28 -2.96 O2 + Zn(OH)2(e) -7.00 4.50 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 7. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.25 -6.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 4.875e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 4.650e-05 Surface charge, eq + 8.309e-02 sigma, C/m**2 + 7.940e-02 psi, V + -3.091e+00 -F*psi/RT + 4.547e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.435e-06 0.687 3.435e-06 -5.464 + Hfo_sOH2+ 1.330e-06 0.266 1.330e-06 -5.876 + Hfo_sO- 2.033e-07 0.041 2.033e-07 -6.692 + Hfo_sOZn+ 3.190e-08 0.006 3.190e-08 -7.496 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.383e-04 0.691 1.383e-04 -3.859 + Hfo_wOH2+ 5.352e-05 0.268 5.352e-05 -4.271 + Hfo_wO- 8.186e-06 0.041 8.186e-06 -5.087 + Hfo_wOZn+ 1.345e-09 0.000 1.345e-09 -8.871 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.995e-02 9.995e-02 + Zn 6.676e-08 6.676e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.250 Charge balance + pe = 13.666 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.998e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.569e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -4.650e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 14 + Total H = 1.110123e+02 + Total O = 5.580617e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.812e-07 5.623e-07 -6.167 -6.250 -0.083 + OH- 2.329e-08 1.774e-08 -7.633 -7.751 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.992 -42.982 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.742 -53.869 -0.128 + NH3 0.000e+00 0.000e+00 -56.874 -56.864 0.010 +N(0) 2.980e-07 + N2 1.490e-07 1.525e-07 -6.827 -6.817 0.010 +N(3) 5.488e-13 + NO2- 5.488e-13 4.137e-13 -12.261 -12.383 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.995e-02 + Na+ 9.995e-02 7.825e-02 -1.000 -1.106 -0.106 + NaOH 8.954e-10 9.163e-10 -9.048 -9.038 0.010 +O(0) 7.449e-07 + O2 3.725e-07 3.811e-07 -6.429 -6.419 0.010 +Zn 6.676e-08 + Zn+2 6.670e-08 2.512e-08 -7.176 -7.600 -0.424 + ZnOH+ 6.247e-11 4.882e-11 -10.204 -10.311 -0.107 + Zn(OH)2 9.707e-13 9.933e-13 -12.013 -12.003 0.010 + Zn(OH)3- 7.123e-18 5.567e-18 -17.147 -17.254 -0.107 + Zn(OH)4-2 4.192e-24 1.564e-24 -23.378 -23.806 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.25 -6.25 0.00 H+ + H2(g) -39.83 -42.98 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.56 -6.82 -3.26 N2 + NH3(g) -58.63 -56.86 1.77 NH3 + O2(g) -3.46 -6.42 -2.96 O2 + Zn(OH)2(e) -6.60 4.90 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 8. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.50 -6.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 3.904e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 3.724e-05 Surface charge, eq + 6.654e-02 sigma, C/m**2 + 6.920e-02 psi, V + -2.694e+00 -F*psi/RT + 6.764e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.546e-06 0.709 3.546e-06 -5.450 + Hfo_sOH2+ 1.148e-06 0.230 1.148e-06 -5.940 + Hfo_sO- 2.509e-07 0.050 2.509e-07 -6.600 + Hfo_sOZn+ 5.526e-08 0.011 5.526e-08 -7.258 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.434e-04 0.717 1.434e-04 -3.843 + Hfo_wOH2+ 4.643e-05 0.232 4.643e-05 -4.333 + Hfo_wO- 1.015e-05 0.051 1.015e-05 -4.994 + Hfo_wOZn+ 2.341e-09 0.000 2.341e-09 -8.631 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.996e-02 9.996e-02 + Zn 4.239e-08 4.239e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.500 Charge balance + pe = 13.380 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.998e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.400e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.724e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580618e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.831e-07 3.162e-07 -6.417 -6.500 -0.083 + OH- 4.141e-08 3.155e-08 -7.383 -7.501 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.921 -42.911 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.956 -54.084 -0.128 + NH3 0.000e+00 0.000e+00 -56.838 -56.828 0.010 +N(0) 2.145e-07 + N2 1.072e-07 1.097e-07 -6.970 -6.960 0.010 +N(3) 6.470e-13 + NO2- 6.470e-13 4.876e-13 -12.189 -12.312 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.996e-02 + Na+ 9.996e-02 7.826e-02 -1.000 -1.106 -0.106 + NaOH 1.592e-09 1.630e-09 -8.798 -8.788 0.010 +O(0) 5.361e-07 + O2 2.681e-07 2.743e-07 -6.572 -6.562 0.010 +Zn 4.239e-08 + Zn+2 4.232e-08 1.594e-08 -7.373 -7.797 -0.424 + ZnOH+ 7.049e-11 5.509e-11 -10.152 -10.259 -0.107 + Zn(OH)2 1.948e-12 1.993e-12 -11.710 -11.700 0.010 + Zn(OH)3- 2.542e-17 1.986e-17 -16.595 -16.702 -0.107 + Zn(OH)4-2 2.660e-23 9.922e-24 -22.575 -23.003 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.50 -6.50 0.00 H+ + H2(g) -39.76 -42.91 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.70 -6.96 -3.26 N2 + NH3(g) -58.60 -56.83 1.77 NH3 + O2(g) -3.60 -6.56 -2.96 O2 + Zn(OH)2(e) -6.30 5.20 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 9. +------------------------------------ + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.75 -6.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 3.063e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.913e-05 Surface charge, eq + 5.205e-02 sigma, C/m**2 + 5.854e-02 psi, V + -2.278e+00 -F*psi/RT + 1.024e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.624e-06 0.725 3.624e-06 -5.441 + Hfo_sOH2+ 9.992e-07 0.200 9.992e-07 -6.000 + Hfo_sO- 3.011e-07 0.060 3.011e-07 -6.521 + Hfo_sOZn+ 7.566e-08 0.015 7.566e-08 -7.121 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.472e-04 0.736 1.472e-04 -3.832 + Hfo_wOH2+ 4.058e-05 0.203 4.058e-05 -4.392 + Hfo_wO- 1.223e-05 0.061 1.223e-05 -4.913 + Hfo_wOZn+ 3.218e-09 0.000 3.218e-09 -8.492 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.997e-02 9.997e-02 + Zn 2.112e-08 2.112e-08 + +----------------------------Description of solution---------------------------- + + pH = 6.750 Charge balance + pe = 13.095 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.999e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.389e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.913e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580619e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.154e-07 1.778e-07 -6.667 -6.750 -0.083 + OH- 7.364e-08 5.610e-08 -7.133 -7.251 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.849 -42.839 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.170 -54.298 -0.128 + NH3 0.000e+00 0.000e+00 -56.802 -56.792 0.010 +N(0) 1.543e-07 + N2 7.717e-08 7.897e-08 -7.113 -7.103 0.010 +N(3) 7.626e-13 + NO2- 7.626e-13 5.748e-13 -12.118 -12.240 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.997e-02 + Na+ 9.997e-02 7.827e-02 -1.000 -1.106 -0.106 + NaOH 2.832e-09 2.898e-09 -8.548 -8.538 0.010 +O(0) 3.858e-07 + O2 1.929e-07 1.974e-07 -6.715 -6.705 0.010 +Zn 2.112e-08 + Zn+2 2.105e-08 7.929e-09 -7.677 -8.101 -0.424 + ZnOH+ 6.235e-11 4.872e-11 -10.205 -10.312 -0.107 + Zn(OH)2 3.064e-12 3.135e-12 -11.514 -11.504 0.010 + Zn(OH)3- 7.110e-17 5.556e-17 -16.148 -16.255 -0.107 + Zn(OH)4-2 1.323e-22 4.935e-23 -21.878 -22.307 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.75 -6.75 0.00 H+ + H2(g) -39.69 -42.84 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.84 -7.10 -3.26 N2 + NH3(g) -58.56 -56.79 1.77 NH3 + O2(g) -3.74 -6.70 -2.96 O2 + Zn(OH)2(e) -6.10 5.40 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 10. +------------------------------------- + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.00 -7.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 2.330e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.203e-05 Surface charge, eq + 3.936e-02 sigma, C/m**2 + 4.744e-02 psi, V + -1.847e+00 -F*psi/RT + 1.578e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.681e-06 0.736 3.681e-06 -5.434 + Hfo_sOH2+ 8.789e-07 0.176 8.789e-07 -6.056 + Hfo_sO- 3.531e-07 0.071 3.531e-07 -6.452 + Hfo_sOZn+ 8.747e-08 0.017 8.747e-08 -7.058 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.498e-04 0.749 1.498e-04 -3.824 + Hfo_wOH2+ 3.578e-05 0.179 3.578e-05 -4.446 + Hfo_wO- 1.437e-05 0.072 1.437e-05 -4.842 + Hfo_wOZn+ 3.729e-09 0.000 3.729e-09 -8.428 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.998e-02 9.998e-02 + Zn 8.799e-09 8.799e-09 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 12.809 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.999e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.491e-08 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.203e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580619e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-07 9.977e-08 -6.883 -7.001 -0.118 + H+ 1.211e-07 1.000e-07 -6.917 -7.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.778 -42.768 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.384 -54.512 -0.128 + NH3 0.000e+00 0.000e+00 -56.767 -56.757 0.010 +N(0) 1.111e-07 + N2 5.554e-08 5.683e-08 -7.255 -7.245 0.010 +N(3) 8.990e-13 + NO2- 8.990e-13 6.775e-13 -12.046 -12.169 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.998e-02 + Na+ 9.998e-02 7.827e-02 -1.000 -1.106 -0.106 + NaOH 5.037e-09 5.154e-09 -8.298 -8.288 0.010 +O(0) 2.777e-07 + O2 1.388e-07 1.421e-07 -6.857 -6.847 0.010 +Zn 8.799e-09 + Zn+2 8.749e-09 3.295e-09 -8.058 -8.482 -0.424 + ZnOH+ 4.608e-11 3.601e-11 -10.336 -10.444 -0.107 + Zn(OH)2 4.027e-12 4.121e-12 -11.395 -11.385 0.010 + Zn(OH)3- 1.662e-16 1.299e-16 -15.779 -15.887 -0.107 + Zn(OH)4-2 5.499e-22 2.051e-22 -21.260 -21.688 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.00 -7.00 0.00 H+ + H2(g) -39.62 -42.77 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.99 -7.25 -3.26 N2 + NH3(g) -58.53 -56.76 1.77 NH3 + O2(g) -3.89 -6.85 -2.96 O2 + Zn(OH)2(e) -5.99 5.51 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 11. +------------------------------------- + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.25 -7.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.683e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 1.576e-05 Surface charge, eq + 2.816e-02 sigma, C/m**2 + 3.596e-02 psi, V + -1.400e+00 -F*psi/RT + 2.467e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.720e-06 0.744 3.720e-06 -5.429 + Hfo_sOH2+ 7.810e-07 0.156 7.810e-07 -6.107 + Hfo_sO- 4.060e-07 0.081 4.060e-07 -6.392 + Hfo_sOZn+ 9.271e-08 0.019 9.271e-08 -7.033 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.516e-04 0.758 1.516e-04 -3.819 + Hfo_wOH2+ 3.183e-05 0.159 3.183e-05 -4.497 + Hfo_wO- 1.655e-05 0.083 1.655e-05 -4.781 + Hfo_wOZn+ 3.956e-09 0.000 3.956e-09 -8.403 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.998e-02 9.998e-02 + Zn 3.336e-09 3.336e-09 + +----------------------------Description of solution---------------------------- + + pH = 7.250 Charge balance + pe = 12.523 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 9.999e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.738e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.576e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580620e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.329e-07 1.774e-07 -6.633 -6.751 -0.118 + H+ 6.812e-08 5.623e-08 -7.167 -7.250 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.706 -42.696 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.599 -54.727 -0.128 + NH3 0.000e+00 0.000e+00 -56.731 -56.721 0.010 +N(0) 7.994e-08 + N2 3.997e-08 4.090e-08 -7.398 -7.388 0.010 +N(3) 1.060e-12 + NO2- 1.060e-12 7.987e-13 -11.975 -12.098 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.998e-02 + Na+ 9.998e-02 7.828e-02 -1.000 -1.106 -0.106 + NaOH 8.957e-09 9.166e-09 -8.048 -8.038 0.010 +O(0) 1.998e-07 + O2 9.992e-08 1.022e-07 -7.000 -6.990 0.010 +Zn 3.336e-09 + Zn+2 3.300e-09 1.243e-09 -8.481 -8.906 -0.424 + ZnOH+ 3.091e-11 2.415e-11 -10.510 -10.617 -0.107 + Zn(OH)2 4.803e-12 4.915e-12 -11.319 -11.309 0.010 + Zn(OH)3- 3.524e-16 2.754e-16 -15.453 -15.560 -0.107 + Zn(OH)4-2 2.074e-21 7.736e-22 -20.683 -21.111 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.25 -7.25 0.00 H+ + H2(g) -39.55 -42.70 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.13 -7.39 -3.26 N2 + NH3(g) -58.49 -56.72 1.77 NH3 + O2(g) -4.03 -6.99 -2.96 O2 + Zn(OH)2(e) -5.91 5.59 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 12. +------------------------------------- + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.50 -7.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.097e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 1.014e-05 Surface charge, eq + 1.812e-02 sigma, C/m**2 + 2.417e-02 psi, V + -9.409e-01 -F*psi/RT + 3.903e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.746e-06 0.749 3.746e-06 -5.426 + Hfo_sOH2+ 6.998e-07 0.140 6.998e-07 -6.155 + Hfo_sO- 4.594e-07 0.092 4.594e-07 -6.338 + Hfo_sOZn+ 9.474e-08 0.019 9.474e-08 -7.023 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.527e-04 0.764 1.527e-04 -3.816 + Hfo_wOH2+ 2.853e-05 0.143 2.853e-05 -4.545 + Hfo_wO- 1.873e-05 0.094 1.873e-05 -4.727 + Hfo_wOZn+ 4.045e-09 0.000 4.045e-09 -8.393 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.999e-02 9.999e-02 + Zn 1.216e-09 1.216e-09 + +----------------------------Description of solution---------------------------- + + pH = 7.500 Charge balance + pe = 12.237 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.918e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.014e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580621e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.141e-07 3.155e-07 -6.383 -6.501 -0.118 + H+ 3.831e-08 3.162e-08 -7.417 -7.500 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.635 -42.625 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.813 -54.941 -0.128 + NH3 0.000e+00 0.000e+00 -56.695 -56.685 0.010 +N(0) 5.753e-08 + N2 2.876e-08 2.943e-08 -7.541 -7.531 0.010 +N(3) 1.249e-12 + NO2- 1.249e-12 9.414e-13 -11.903 -12.026 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.999e-02 + Na+ 9.999e-02 7.828e-02 -1.000 -1.106 -0.106 + NaOH 1.593e-08 1.630e-08 -7.798 -7.788 0.010 +O(0) 1.438e-07 + O2 7.191e-08 7.359e-08 -7.143 -7.133 0.010 +Zn 1.216e-09 + Zn+2 1.190e-09 4.483e-10 -8.924 -9.348 -0.424 + ZnOH+ 1.982e-11 1.549e-11 -10.703 -10.810 -0.107 + Zn(OH)2 5.478e-12 5.606e-12 -11.261 -11.251 0.010 + Zn(OH)3- 7.149e-16 5.587e-16 -15.146 -15.253 -0.107 + Zn(OH)4-2 7.481e-21 2.790e-21 -20.126 -20.554 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.50 -7.50 0.00 H+ + H2(g) -39.47 -42.62 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.27 -7.53 -3.26 N2 + NH3(g) -58.46 -56.69 1.77 NH3 + O2(g) -4.17 -7.13 -2.96 O2 + Zn(OH)2(e) -5.85 5.65 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 13. +------------------------------------- + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.75 -7.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 5.425e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 4.965e-06 Surface charge, eq + 8.872e-03 sigma, C/m**2 + 1.217e-02 psi, V + -4.735e-01 -F*psi/RT + 6.228e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.760e-06 0.752 3.760e-06 -5.425 + Hfo_sOH2+ 6.303e-07 0.126 6.303e-07 -6.200 + Hfo_sO- 5.139e-07 0.103 5.139e-07 -6.289 + Hfo_sOZn+ 9.548e-08 0.019 9.548e-08 -7.020 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.533e-04 0.767 1.533e-04 -3.814 + Hfo_wOH2+ 2.570e-05 0.129 2.570e-05 -4.590 + Hfo_wO- 2.096e-05 0.105 2.096e-05 -4.679 + Hfo_wOZn+ 4.077e-09 0.000 4.077e-09 -8.390 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 1.000e-01 1.000e-01 + Zn 4.397e-10 4.397e-10 + +----------------------------Description of solution---------------------------- + + pH = 7.750 Charge balance + pe = 11.952 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 7.432e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -4.965e-06 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580621e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.364e-07 5.610e-07 -6.133 -6.251 -0.118 + H+ 2.154e-08 1.778e-08 -7.667 -7.750 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.563 -42.553 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -55.027 -55.155 -0.128 + NH3 0.000e+00 0.000e+00 -56.659 -56.649 0.010 +N(0) 4.140e-08 + N2 2.070e-08 2.118e-08 -7.684 -7.674 0.010 +N(3) 1.472e-12 + NO2- 1.472e-12 1.110e-12 -11.832 -11.955 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 1.000e-01 + Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 + NaOH 2.833e-08 2.899e-08 -7.548 -7.538 0.010 +O(0) 1.035e-07 + O2 5.175e-08 5.296e-08 -7.286 -7.276 0.010 +Zn 4.397e-10 + Zn+2 4.211e-10 1.586e-10 -9.376 -9.800 -0.424 + ZnOH+ 1.247e-11 9.747e-12 -10.904 -11.011 -0.107 + Zn(OH)2 6.129e-12 6.272e-12 -11.213 -11.203 0.010 + Zn(OH)3- 1.422e-15 1.112e-15 -14.847 -14.954 -0.107 + Zn(OH)4-2 2.647e-20 9.873e-21 -19.577 -20.006 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.75 -7.75 0.00 H+ + H2(g) -39.40 -42.55 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.41 -7.67 -3.26 N2 + NH3(g) -58.42 -56.65 1.77 NH3 + O2(g) -4.32 -7.28 -2.96 O2 + Zn(OH)2(e) -5.80 5.70 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 14. +------------------------------------- + + USE solution 1 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -8.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 1. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -8.00 -8.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -1.388e-07 + +------------------------------Surface composition------------------------------ + +Hfo + 1.788e-08 Surface charge, eq + 3.195e-05 sigma, C/m**2 + 4.422e-05 psi, V + -1.721e-03 -F*psi/RT + 9.983e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 3.765e-06 0.753 3.765e-06 -5.424 + Hfo_sO- 5.708e-07 0.114 5.708e-07 -6.244 + Hfo_sOH2+ 5.688e-07 0.114 5.688e-07 -6.245 + Hfo_sOZn+ 9.575e-08 0.019 9.575e-08 -7.019 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.535e-04 0.768 1.535e-04 -3.814 + Hfo_wO- 2.328e-05 0.116 2.328e-05 -4.633 + Hfo_wOH2+ 2.320e-05 0.116 2.320e-05 -4.635 + Hfo_wOZn+ 4.089e-09 0.000 4.089e-09 -8.388 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 1.000e-01 1.000e-01 + Zn 1.626e-10 1.626e-10 + +----------------------------Description of solution---------------------------- + + pH = 8.000 Charge balance + pe = 11.666 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.348e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.788e-08 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 14 + Total H = 1.110124e+02 + Total O = 5.580622e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 + H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.492 -42.482 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -55.242 -55.369 -0.128 + NH3 0.000e+00 0.000e+00 -56.624 -56.614 0.010 +N(0) 2.980e-08 + N2 1.490e-08 1.525e-08 -7.827 -7.817 0.010 +N(3) 1.736e-12 + NO2- 1.736e-12 1.308e-12 -11.761 -11.883 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 1.000e-01 + Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 + NaOH 5.038e-08 5.155e-08 -7.298 -7.288 0.010 +O(0) 7.449e-08 + O2 3.725e-08 3.811e-08 -7.429 -7.419 0.010 +Zn 1.626e-10 + Zn+2 1.480e-10 5.574e-11 -9.830 -10.254 -0.424 + ZnOH+ 7.794e-12 6.091e-12 -11.108 -11.215 -0.107 + Zn(OH)2 6.811e-12 6.969e-12 -11.167 -11.157 0.010 + Zn(OH)3- 2.811e-15 2.196e-15 -14.551 -14.658 -0.107 + Zn(OH)4-2 9.302e-20 3.469e-20 -19.031 -19.460 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -8.00 -8.00 0.00 H+ + H2(g) -39.33 -42.48 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.56 -7.82 -3.26 N2 + NH3(g) -58.38 -56.61 1.77 NH3 + O2(g) -4.46 -7.42 -2.96 O2 + Zn(OH)2(e) -5.76 5.74 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 15. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.00 -5.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.399e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 1.124e-04 Surface charge, eq + 2.008e-01 sigma, C/m**2 + 1.228e-01 psi, V + -4.779e+00 -F*psi/RT + 8.404e-03 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH2+ 2.613e-06 0.523 2.613e-06 -5.583 + Hfo_sOH 2.054e-06 0.411 2.054e-06 -5.687 + Hfo_sOZn+ 2.962e-07 0.059 2.962e-07 -6.528 + Hfo_sO- 3.700e-08 0.007 3.700e-08 -7.432 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH2+ 1.111e-04 0.555 1.111e-04 -3.954 + Hfo_wOH 8.733e-05 0.437 8.733e-05 -4.059 + Hfo_wO- 1.573e-06 0.008 1.573e-06 -5.803 + Hfo_wOZn+ 1.319e-08 0.000 1.319e-08 -7.880 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.967e-02 9.967e-02 + Zn 9.969e-05 9.969e-05 + +----------------------------Description of solution---------------------------- + + pH = 5.000 Charge balance + pe = 15.095 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.211e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.124e-04 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.06 + Iterations = 21 + Total H = 1.110122e+02 + Total O = 5.580609e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.211e-05 1.000e-05 -4.917 -5.000 -0.083 + OH- 1.310e-09 9.977e-10 -8.883 -9.001 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.349 -43.339 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -52.670 -52.798 -0.128 + NH3 0.000e+00 0.000e+00 -57.052 -57.042 0.010 +N(0) 1.543e-06 + N2 7.716e-07 7.896e-07 -6.113 -6.103 0.010 +N(3) 2.412e-13 + NO2- 2.412e-13 1.818e-13 -12.618 -12.741 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.967e-02 + Na+ 9.967e-02 7.803e-02 -1.001 -1.108 -0.106 + NaOH 5.021e-11 5.138e-11 -10.299 -10.289 0.010 +O(0) 3.858e-06 + O2 1.929e-06 1.974e-06 -5.715 -5.705 0.010 +Zn 9.969e-05 + Zn+2 9.969e-05 3.754e-05 -4.001 -4.426 -0.424 + ZnOH+ 5.249e-09 4.102e-09 -8.280 -8.387 -0.107 + Zn(OH)2 4.587e-12 4.694e-12 -11.338 -11.328 0.010 + Zn(OH)3- 1.893e-18 1.479e-18 -17.723 -17.830 -0.107 + Zn(OH)4-2 6.266e-26 2.337e-26 -25.203 -25.631 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.00 -5.00 0.00 H+ + H2(g) -40.19 -43.34 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.84 -6.10 -3.26 N2 + NH3(g) -58.81 -57.04 1.77 NH3 + O2(g) -2.74 -5.70 -2.96 O2 + Zn(OH)2(e) -5.93 5.57 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 16. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.25 -5.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.178e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 9.693e-05 Surface charge, eq + 1.732e-01 sigma, C/m**2 + 1.153e-01 psi, V + -4.489e+00 -F*psi/RT + 1.124e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 2.154e-06 0.431 2.154e-06 -5.667 + Hfo_sOH2+ 2.060e-06 0.412 2.060e-06 -5.686 + Hfo_sOZn+ 7.349e-07 0.147 7.349e-07 -6.134 + Hfo_sO- 5.159e-08 0.010 5.159e-08 -7.287 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.010e-04 0.505 1.010e-04 -3.996 + Hfo_wOH2+ 9.657e-05 0.483 9.657e-05 -4.015 + Hfo_wO- 2.419e-06 0.012 2.419e-06 -5.616 + Hfo_wOZn+ 3.608e-08 0.000 3.608e-08 -7.443 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.970e-02 9.970e-02 + Zn 9.923e-05 9.923e-05 + +----------------------------Description of solution---------------------------- + + pH = 5.250 Charge balance + pe = 14.809 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -6.800e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -9.693e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 + Iterations = 21 + Total H = 1.110122e+02 + Total O = 5.580611e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.812e-06 5.623e-06 -5.167 -5.250 -0.083 + OH- 2.329e-09 1.774e-09 -8.633 -8.751 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.278 -43.268 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -52.884 -53.012 -0.128 + NH3 0.000e+00 0.000e+00 -57.017 -57.007 0.010 +N(0) 1.111e-06 + N2 5.553e-07 5.683e-07 -6.255 -6.245 0.010 +N(3) 2.843e-13 + NO2- 2.843e-13 2.142e-13 -12.546 -12.669 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.970e-02 + Na+ 9.970e-02 7.805e-02 -1.001 -1.108 -0.106 + NaOH 8.931e-11 9.139e-11 -10.049 -10.039 0.010 +O(0) 2.777e-06 + O2 1.388e-06 1.421e-06 -5.858 -5.848 0.010 +Zn 9.923e-05 + Zn+2 9.922e-05 3.736e-05 -4.003 -4.428 -0.424 + ZnOH+ 9.291e-09 7.261e-09 -8.032 -8.139 -0.107 + Zn(OH)2 1.444e-11 1.477e-11 -10.841 -10.831 0.010 + Zn(OH)3- 1.060e-17 8.280e-18 -16.975 -17.082 -0.107 + Zn(OH)4-2 6.236e-25 2.326e-25 -24.205 -24.633 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.25 -5.25 0.00 H+ + H2(g) -40.12 -43.27 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -2.99 -6.25 -3.26 N2 + NH3(g) -58.78 -57.01 1.77 NH3 + O2(g) -2.89 -5.85 -2.96 O2 + Zn(OH)2(e) -5.43 6.07 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 17. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.50 -5.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 9.839e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 8.263e-05 Surface charge, eq + 1.476e-01 sigma, C/m**2 + 1.073e-01 psi, V + -4.178e+00 -F*psi/RT + 1.533e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOH 1.934e-06 0.387 1.934e-06 -5.714 + Hfo_sOZn+ 1.587e-06 0.317 1.587e-06 -5.800 + Hfo_sOH2+ 1.419e-06 0.284 1.419e-06 -5.848 + Hfo_sO- 6.036e-08 0.012 6.036e-08 -7.219 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.132e-04 0.566 1.132e-04 -3.946 + Hfo_wOH2+ 8.312e-05 0.416 8.312e-05 -4.080 + Hfo_wO- 3.535e-06 0.018 3.535e-06 -5.452 + Hfo_wOZn+ 9.730e-08 0.000 9.730e-08 -7.012 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.972e-02 9.972e-02 + Zn 9.832e-05 9.832e-05 + +----------------------------Description of solution---------------------------- + + pH = 5.500 Charge balance + pe = 14.523 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -3.810e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -8.263e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.04 + Iterations = 21 + Total H = 1.110123e+02 + Total O = 5.580613e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.831e-06 3.162e-06 -5.417 -5.500 -0.083 + OH- 4.141e-09 3.155e-09 -8.383 -8.501 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.206 -43.196 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.099 -53.227 -0.128 + NH3 0.000e+00 0.000e+00 -56.981 -56.971 0.010 +N(0) 7.994e-07 + N2 3.997e-07 4.090e-07 -6.398 -6.388 0.010 +N(3) 3.351e-13 + NO2- 3.351e-13 2.525e-13 -12.475 -12.598 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.972e-02 + Na+ 9.972e-02 7.806e-02 -1.001 -1.108 -0.106 + NaOH 1.588e-10 1.625e-10 -9.799 -9.789 0.010 +O(0) 1.998e-06 + O2 9.991e-07 1.022e-06 -6.000 -5.990 0.010 +Zn 9.832e-05 + Zn+2 9.830e-05 3.702e-05 -4.007 -4.432 -0.424 + ZnOH+ 1.637e-08 1.279e-08 -7.786 -7.893 -0.107 + Zn(OH)2 4.523e-11 4.628e-11 -10.345 -10.335 0.010 + Zn(OH)3- 5.903e-17 4.613e-17 -16.229 -16.336 -0.107 + Zn(OH)4-2 6.178e-24 2.304e-24 -23.209 -23.638 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.50 -5.50 0.00 H+ + H2(g) -40.05 -43.20 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.13 -6.39 -3.26 N2 + NH3(g) -58.74 -56.97 1.77 NH3 + O2(g) -3.03 -5.99 -2.96 O2 + Zn(OH)2(e) -4.93 6.57 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 18. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -5.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -5.75 -5.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 8.089e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 6.973e-05 Surface charge, eq + 1.246e-01 sigma, C/m**2 + 9.892e-02 psi, V + -3.850e+00 -F*psi/RT + 2.127e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 2.766e-06 0.553 2.766e-06 -5.558 + Hfo_sOH 1.385e-06 0.277 1.385e-06 -5.858 + Hfo_sOH2+ 7.933e-07 0.159 7.933e-07 -6.101 + Hfo_sO- 5.543e-08 0.011 5.543e-08 -7.256 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.239e-04 0.619 1.239e-04 -3.907 + Hfo_wOH2+ 7.092e-05 0.355 7.092e-05 -4.149 + Hfo_wO- 4.955e-06 0.025 4.955e-06 -5.305 + Hfo_wOZn+ 2.589e-07 0.001 2.589e-07 -6.587 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.973e-02 9.973e-02 + Zn 9.698e-05 9.698e-05 + +----------------------------Description of solution---------------------------- + + pH = 5.750 Charge balance + pe = 14.237 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -2.117e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -6.973e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 + Iterations = 21 + Total H = 1.110123e+02 + Total O = 5.580615e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.154e-06 1.778e-06 -5.667 -5.750 -0.083 + OH- 7.365e-09 5.610e-09 -8.133 -8.251 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.135 -43.125 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.313 -53.441 -0.128 + NH3 0.000e+00 0.000e+00 -56.945 -56.935 0.010 +N(0) 5.754e-07 + N2 2.877e-07 2.944e-07 -6.541 -6.531 0.010 +N(3) 3.950e-13 + NO2- 3.950e-13 2.977e-13 -12.403 -12.526 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.973e-02 + Na+ 9.973e-02 7.808e-02 -1.001 -1.107 -0.106 + NaOH 2.825e-10 2.891e-10 -9.549 -9.539 0.010 +O(0) 1.438e-06 + O2 7.190e-07 7.358e-07 -6.143 -6.133 0.010 +Zn 9.698e-05 + Zn+2 9.695e-05 3.651e-05 -4.013 -4.438 -0.424 + ZnOH+ 2.871e-08 2.243e-08 -7.542 -7.649 -0.107 + Zn(OH)2 1.411e-10 1.443e-10 -9.851 -9.841 0.010 + Zn(OH)3- 3.274e-16 2.558e-16 -15.485 -15.592 -0.107 + Zn(OH)4-2 6.093e-23 2.272e-23 -22.215 -22.644 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -5.75 -5.75 0.00 H+ + H2(g) -39.97 -43.12 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.27 -6.53 -3.26 N2 + NH3(g) -58.71 -56.94 1.77 NH3 + O2(g) -3.17 -6.13 -2.96 O2 + Zn(OH)2(e) -4.44 7.06 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 19. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.00 -6.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 6.529e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 5.823e-05 Surface charge, eq + 1.041e-01 sigma, C/m**2 + 9.012e-02 psi, V + -3.508e+00 -F*psi/RT + 2.996e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 3.830e-06 0.766 3.830e-06 -5.417 + Hfo_sOH 7.781e-07 0.156 7.781e-07 -6.109 + Hfo_sOH2+ 3.529e-07 0.071 3.529e-07 -6.452 + Hfo_sO- 3.930e-08 0.008 3.930e-08 -7.406 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.325e-04 0.663 1.325e-04 -3.878 + Hfo_wOH2+ 6.010e-05 0.301 6.010e-05 -4.221 + Hfo_wO- 6.694e-06 0.033 6.694e-06 -5.174 + Hfo_wOZn+ 6.830e-07 0.003 6.830e-07 -6.166 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.975e-02 9.975e-02 + Zn 9.549e-05 9.549e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.000 Charge balance + pe = 13.952 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.147e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -5.823e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 + Iterations = 21 + Total H = 1.110123e+02 + Total O = 5.580617e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.211e-06 1.000e-06 -5.917 -6.000 -0.083 + OH- 1.310e-08 9.977e-09 -7.883 -8.001 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -43.063 -43.053 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.527 -53.655 -0.128 + NH3 0.000e+00 0.000e+00 -56.909 -56.899 0.010 +N(0) 4.143e-07 + N2 2.072e-07 2.120e-07 -6.684 -6.674 0.010 +N(3) 4.657e-13 + NO2- 4.657e-13 3.510e-13 -12.332 -12.455 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.975e-02 + Na+ 9.975e-02 7.809e-02 -1.001 -1.107 -0.106 + NaOH 5.025e-10 5.142e-10 -9.299 -9.289 0.010 +O(0) 1.035e-06 + O2 5.173e-07 5.294e-07 -6.286 -6.276 0.010 +Zn 9.549e-05 + Zn+2 9.544e-05 3.594e-05 -4.020 -4.444 -0.424 + ZnOH+ 5.025e-08 3.927e-08 -7.299 -7.406 -0.107 + Zn(OH)2 4.391e-10 4.493e-10 -9.357 -9.347 0.010 + Zn(OH)3- 1.812e-15 1.416e-15 -14.742 -14.849 -0.107 + Zn(OH)4-2 5.998e-22 2.237e-22 -21.222 -21.650 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.00 -6.00 0.00 H+ + H2(g) -39.90 -43.05 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.41 -6.67 -3.26 N2 + NH3(g) -58.67 -56.90 1.77 NH3 + O2(g) -3.32 -6.28 -2.96 O2 + Zn(OH)2(e) -3.95 7.55 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 20. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.25 -6.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 5.100e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 4.813e-05 Surface charge, eq + 8.601e-02 sigma, C/m**2 + 8.101e-02 psi, V + -3.153e+00 -F*psi/RT + 4.272e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.478e-06 0.896 4.478e-06 -5.349 + Hfo_sOH 3.657e-07 0.073 3.657e-07 -6.437 + Hfo_sOH2+ 1.330e-07 0.027 1.330e-07 -6.876 + Hfo_sO- 2.304e-08 0.005 2.304e-08 -7.637 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.389e-04 0.695 1.389e-04 -3.857 + Hfo_wOH2+ 5.052e-05 0.253 5.052e-05 -4.297 + Hfo_wO- 8.755e-06 0.044 8.755e-06 -5.058 + Hfo_wOZn+ 1.781e-06 0.009 1.781e-06 -5.749 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.976e-02 9.976e-02 + Zn 9.374e-05 9.374e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.250 Charge balance + pe = 13.666 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -5.666e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -4.813e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.580618e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.812e-07 5.623e-07 -6.167 -6.250 -0.083 + OH- 2.329e-08 1.774e-08 -7.633 -7.751 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.992 -42.982 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.742 -53.869 -0.128 + NH3 0.000e+00 0.000e+00 -56.874 -56.864 0.010 +N(0) 2.980e-07 + N2 1.490e-07 1.525e-07 -6.827 -6.817 0.010 +N(3) 5.489e-13 + NO2- 5.489e-13 4.136e-13 -12.261 -12.383 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.976e-02 + Na+ 9.976e-02 7.810e-02 -1.001 -1.107 -0.106 + NaOH 8.936e-10 9.145e-10 -9.049 -9.039 0.010 +O(0) 7.449e-07 + O2 3.724e-07 3.811e-07 -6.429 -6.419 0.010 +Zn 9.374e-05 + Zn+2 9.365e-05 3.526e-05 -4.028 -4.453 -0.424 + ZnOH+ 8.769e-08 6.853e-08 -7.057 -7.164 -0.107 + Zn(OH)2 1.363e-09 1.394e-09 -8.866 -8.856 0.010 + Zn(OH)3- 1.000e-14 7.814e-15 -14.000 -14.107 -0.107 + Zn(OH)4-2 5.886e-21 2.195e-21 -20.230 -20.659 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.25 -6.25 0.00 H+ + H2(g) -39.83 -42.98 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.56 -6.82 -3.26 N2 + NH3(g) -58.63 -56.86 1.77 NH3 + O2(g) -3.46 -6.42 -2.96 O2 + Zn(OH)2(e) -3.46 8.04 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 21. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.50 -6.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 3.598e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 3.959e-05 Surface charge, eq + 7.074e-02 sigma, C/m**2 + 7.194e-02 psi, V + -2.800e+00 -F*psi/RT + 6.079e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.781e-06 0.956 4.781e-06 -5.320 + Hfo_sOH 1.595e-07 0.032 1.595e-07 -6.797 + Hfo_sOH2+ 4.642e-08 0.009 4.642e-08 -7.333 + Hfo_sO- 1.256e-08 0.003 1.256e-08 -7.901 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.427e-04 0.714 1.427e-04 -3.845 + Hfo_wOH2+ 4.153e-05 0.208 4.153e-05 -4.382 + Hfo_wO- 1.124e-05 0.056 1.124e-05 -4.949 + Hfo_wOZn+ 4.480e-06 0.022 4.480e-06 -5.349 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.978e-02 9.978e-02 + Zn 9.074e-05 9.074e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.500 Charge balance + pe = 13.380 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = -1.809e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.959e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.580620e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.831e-07 3.162e-07 -6.417 -6.500 -0.083 + OH- 4.141e-08 3.155e-08 -7.383 -7.501 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.921 -42.911 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -53.956 -54.084 -0.128 + NH3 0.000e+00 0.000e+00 -56.838 -56.828 0.010 +N(0) 2.144e-07 + N2 1.072e-07 1.097e-07 -6.970 -6.960 0.010 +N(3) 6.470e-13 + NO2- 6.470e-13 4.876e-13 -12.189 -12.312 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.978e-02 + Na+ 9.978e-02 7.811e-02 -1.001 -1.107 -0.106 + NaOH 1.589e-09 1.626e-09 -8.799 -8.789 0.010 +O(0) 5.361e-07 + O2 2.680e-07 2.743e-07 -6.572 -6.562 0.010 +Zn 9.074e-05 + Zn+2 9.058e-05 3.411e-05 -4.043 -4.467 -0.424 + ZnOH+ 1.508e-07 1.179e-07 -6.822 -6.929 -0.107 + Zn(OH)2 4.168e-09 4.265e-09 -8.380 -8.370 0.010 + Zn(OH)3- 5.439e-14 4.250e-14 -13.264 -13.372 -0.107 + Zn(OH)4-2 5.693e-20 2.123e-20 -19.245 -19.673 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.50 -6.50 0.00 H+ + H2(g) -39.76 -42.91 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.70 -6.96 -3.26 N2 + NH3(g) -58.60 -56.83 1.77 NH3 + O2(g) -3.60 -6.56 -2.96 O2 + Zn(OH)2(e) -2.97 8.53 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 22. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -6.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -6.75 -6.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 1.709e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 3.290e-05 Surface charge, eq + 5.878e-02 sigma, C/m**2 + 6.370e-02 psi, V + -2.480e+00 -F*psi/RT + 8.378e-02 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.905e-06 0.981 4.905e-06 -5.309 + Hfo_sOH 7.153e-08 0.014 7.153e-08 -7.146 + Hfo_sOH2+ 1.613e-08 0.003 1.613e-08 -7.792 + Hfo_sO- 7.267e-09 0.001 7.267e-09 -8.139 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.430e-04 0.715 1.430e-04 -3.845 + Hfo_wOH2+ 3.224e-05 0.161 3.224e-05 -4.492 + Hfo_wO- 1.452e-05 0.073 1.452e-05 -4.838 + Hfo_wOZn+ 1.027e-05 0.051 1.027e-05 -4.989 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.980e-02 9.980e-02 + Zn 8.483e-05 8.483e-05 + +----------------------------Description of solution---------------------------- + + pH = 6.750 Charge balance + pe = 13.095 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.361e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -3.290e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.580621e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 2.154e-07 1.778e-07 -6.667 -6.750 -0.083 + OH- 7.365e-08 5.610e-08 -7.133 -7.251 -0.118 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.849 -42.839 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.170 -54.298 -0.128 + NH3 0.000e+00 0.000e+00 -56.802 -56.792 0.010 +N(0) 1.544e-07 + N2 7.718e-08 7.898e-08 -7.113 -7.102 0.010 +N(3) 7.627e-13 + NO2- 7.627e-13 5.748e-13 -12.118 -12.240 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.980e-02 + Na+ 9.980e-02 7.813e-02 -1.001 -1.107 -0.106 + NaOH 2.827e-09 2.893e-09 -8.549 -8.539 0.010 +O(0) 3.858e-07 + O2 1.929e-07 1.974e-07 -6.715 -6.705 0.010 +Zn 8.483e-05 + Zn+2 8.457e-05 3.184e-05 -4.073 -4.497 -0.424 + ZnOH+ 2.504e-07 1.957e-07 -6.601 -6.708 -0.107 + Zn(OH)2 1.230e-08 1.259e-08 -7.910 -7.900 0.010 + Zn(OH)3- 2.856e-13 2.231e-13 -12.544 -12.651 -0.107 + Zn(OH)4-2 5.315e-19 1.982e-19 -18.274 -18.703 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -6.75 -6.75 0.00 H+ + H2(g) -39.69 -42.84 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.84 -7.10 -3.26 N2 + NH3(g) -58.56 -56.79 1.77 NH3 + O2(g) -3.74 -6.70 -2.96 O2 + Zn(OH)2(e) -2.50 9.00 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 23. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.00 -7.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -7.621e-06 + +------------------------------Surface composition------------------------------ + +Hfo + 2.821e-05 Surface charge, eq + 5.040e-02 sigma, C/m**2 + 5.718e-02 psi, V + -2.226e+00 -F*psi/RT + 1.080e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.953e-06 0.991 4.953e-06 -5.305 + Hfo_sOH 3.573e-08 0.007 3.573e-08 -7.447 + Hfo_sOH2+ 5.840e-09 0.001 5.840e-09 -8.234 + Hfo_sO- 5.008e-09 0.001 5.008e-09 -8.300 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.380e-04 0.690 1.380e-04 -3.860 + Hfo_wOH2+ 2.256e-05 0.113 2.256e-05 -4.647 + Hfo_wOZn+ 2.004e-05 0.100 2.004e-05 -4.698 + Hfo_wO- 1.935e-05 0.097 1.935e-05 -4.713 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.982e-02 9.982e-02 + Zn 7.501e-05 7.501e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.000 Charge balance + pe = 12.809 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.001e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.762e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.821e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 22 + Total H = 1.110125e+02 + Total O = 5.580624e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-07 9.977e-08 -6.883 -7.001 -0.118 + H+ 1.211e-07 1.000e-07 -6.917 -7.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.778 -42.768 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.384 -54.512 -0.128 + NH3 0.000e+00 0.000e+00 -56.766 -56.756 0.010 +N(0) 1.112e-07 + N2 5.561e-08 5.691e-08 -7.255 -7.245 0.010 +N(3) 8.992e-13 + NO2- 8.992e-13 6.777e-13 -12.046 -12.169 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.982e-02 + Na+ 9.982e-02 7.815e-02 -1.001 -1.107 -0.106 + NaOH 5.028e-09 5.146e-09 -8.299 -8.289 0.010 +O(0) 2.775e-07 + O2 1.388e-07 1.420e-07 -6.858 -6.848 0.010 +Zn 7.501e-05 + Zn+2 7.458e-05 2.808e-05 -4.127 -4.552 -0.424 + ZnOH+ 3.927e-07 3.069e-07 -6.406 -6.513 -0.107 + Zn(OH)2 3.432e-08 3.512e-08 -7.465 -7.454 0.010 + Zn(OH)3- 1.416e-12 1.107e-12 -11.849 -11.956 -0.107 + Zn(OH)4-2 4.688e-18 1.748e-18 -17.329 -17.757 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.00 -7.00 0.00 H+ + H2(g) -39.62 -42.77 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -3.98 -7.24 -3.26 N2 + NH3(g) -58.53 -56.76 1.77 NH3 + O2(g) -3.89 -6.85 -2.96 O2 + Zn(OH)2(e) -2.05 9.45 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 24. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.25 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.25 -7.25 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -3.628e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.514e-05 Surface charge, eq + 4.492e-02 sigma, C/m**2 + 5.252e-02 psi, V + -2.044e+00 -F*psi/RT + 1.295e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.973e-06 0.995 4.973e-06 -5.303 + Hfo_sOH 2.031e-08 0.004 2.031e-08 -7.692 + Hfo_sO- 4.222e-09 0.001 4.222e-09 -8.375 + Hfo_sOH2+ 2.238e-09 0.000 2.238e-09 -8.650 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.270e-04 0.635 1.270e-04 -3.896 + Hfo_wOZn+ 3.257e-05 0.163 3.257e-05 -4.487 + Hfo_wO- 2.640e-05 0.132 2.640e-05 -4.578 + Hfo_wOH2+ 1.400e-05 0.070 1.400e-05 -4.854 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.985e-02 9.985e-02 + Zn 6.245e-05 6.245e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.250 Charge balance + pe = 12.523 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.321e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.514e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 22 + Total H = 1.110125e+02 + Total O = 5.580627e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 2.329e-07 1.774e-07 -6.633 -6.751 -0.118 + H+ 6.812e-08 5.623e-08 -7.167 -7.250 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.706 -42.696 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.596 -54.724 -0.128 + NH3 0.000e+00 0.000e+00 -56.729 -56.719 0.010 +N(0) 8.046e-08 + N2 4.023e-08 4.117e-08 -7.395 -7.385 0.010 +N(3) 1.061e-12 + NO2- 1.061e-12 7.997e-13 -11.974 -12.097 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 +Na 9.985e-02 + Na+ 9.985e-02 7.817e-02 -1.001 -1.107 -0.106 + NaOH 8.944e-09 9.153e-09 -8.048 -8.038 0.010 +O(0) 1.993e-07 + O2 9.966e-08 1.020e-07 -7.001 -6.991 0.010 +Zn 6.245e-05 + Zn+2 6.179e-05 2.327e-05 -4.209 -4.633 -0.424 + ZnOH+ 5.786e-07 4.521e-07 -6.238 -6.345 -0.107 + Zn(OH)2 8.990e-08 9.200e-08 -7.046 -7.036 0.010 + Zn(OH)3- 6.598e-12 5.156e-12 -11.181 -11.288 -0.107 + Zn(OH)4-2 3.883e-17 1.448e-17 -16.411 -16.839 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.25 -7.25 0.00 H+ + H2(g) -39.55 -42.70 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.13 -7.39 -3.26 N2 + NH3(g) -58.49 -56.72 1.77 NH3 + O2(g) -4.03 -6.99 -2.96 O2 + Zn(OH)2(e) -1.64 9.86 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 25. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.5 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.50 -7.50 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -6.533e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.290e-05 Surface charge, eq + 4.091e-02 sigma, C/m**2 + 4.889e-02 psi, V + -1.903e+00 -F*psi/RT + 1.491e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.982e-06 0.996 4.982e-06 -5.303 + Hfo_sOH 1.269e-08 0.003 1.269e-08 -7.897 + Hfo_sO- 4.073e-09 0.001 4.073e-09 -8.390 + Hfo_sOH2+ 9.054e-10 0.000 9.054e-10 -9.043 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 1.109e-04 0.554 1.109e-04 -3.955 + Hfo_wOZn+ 4.560e-05 0.228 4.560e-05 -4.341 + Hfo_wO- 3.560e-05 0.178 3.560e-05 -4.449 + Hfo_wOH2+ 7.913e-06 0.040 7.913e-06 -5.102 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.988e-02 9.988e-02 + Zn 4.942e-05 4.942e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.500 Charge balance + pe = 12.237 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.643e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.290e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 24 + Total H = 1.110126e+02 + Total O = 5.580630e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 4.141e-07 3.155e-07 -6.383 -6.501 -0.118 + H+ 3.831e-08 3.162e-08 -7.417 -7.500 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.635 -42.625 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -54.813 -54.941 -0.128 + NH3 0.000e+00 0.000e+00 -56.695 -56.685 0.010 +N(0) 5.753e-08 + N2 2.876e-08 2.943e-08 -7.541 -7.531 0.010 +N(3) 1.249e-12 + NO2- 1.249e-12 9.414e-13 -11.903 -12.026 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.988e-02 + Na+ 9.988e-02 7.819e-02 -1.001 -1.107 -0.106 + NaOH 1.591e-08 1.628e-08 -7.798 -7.788 0.010 +O(0) 1.438e-07 + O2 7.191e-08 7.359e-08 -7.143 -7.133 0.010 +Zn 4.942e-05 + Zn+2 4.839e-05 1.822e-05 -4.315 -4.739 -0.424 + ZnOH+ 8.058e-07 6.297e-07 -6.094 -6.201 -0.107 + Zn(OH)2 2.227e-07 2.278e-07 -6.652 -6.642 0.010 + Zn(OH)3- 2.906e-11 2.271e-11 -10.537 -10.644 -0.107 + Zn(OH)4-2 3.041e-16 1.134e-16 -15.517 -15.945 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.50 -7.50 0.00 H+ + H2(g) -39.47 -42.62 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.27 -7.53 -3.26 N2 + NH3(g) -58.46 -56.69 1.77 NH3 + O2(g) -4.17 -7.13 -2.96 O2 + Zn(OH)2(e) -1.24 10.26 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 26. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -7.75 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -7.75 -7.75 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -9.246e-05 + +------------------------------Surface composition------------------------------ + +Hfo + 2.082e-05 Surface charge, eq + 3.720e-02 sigma, C/m**2 + 4.536e-02 psi, V + -1.765e+00 -F*psi/RT + 1.711e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.987e-06 0.997 4.987e-06 -5.302 + Hfo_sOH 8.383e-09 0.002 8.383e-09 -8.077 + Hfo_sO- 4.170e-09 0.001 4.170e-09 -8.380 + Hfo_sOH2+ 3.861e-10 0.000 3.861e-10 -9.413 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 9.232e-05 0.462 9.232e-05 -4.035 + Hfo_wOZn+ 5.751e-05 0.288 5.751e-05 -4.240 + Hfo_wO- 4.592e-05 0.230 4.592e-05 -4.338 + Hfo_wOH2+ 4.251e-06 0.021 4.251e-06 -5.371 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.991e-02 9.991e-02 + Zn 3.750e-05 3.750e-05 + +----------------------------Description of solution---------------------------- + + pH = 7.750 Charge balance + pe = 11.952 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.853e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -2.082e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 23 + Total H = 1.110126e+02 + Total O = 5.580632e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 7.364e-07 5.610e-07 -6.133 -6.251 -0.118 + H+ 2.154e-08 1.778e-08 -7.667 -7.750 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.563 -42.553 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -55.027 -55.155 -0.128 + NH3 0.000e+00 0.000e+00 -56.659 -56.649 0.010 +N(0) 4.145e-08 + N2 2.072e-08 2.121e-08 -7.684 -7.674 0.010 +N(3) 1.473e-12 + NO2- 1.473e-12 1.110e-12 -11.832 -11.955 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.991e-02 + Na+ 9.991e-02 7.821e-02 -1.000 -1.107 -0.106 + NaOH 2.830e-08 2.896e-08 -7.548 -7.538 0.010 +O(0) 1.035e-07 + O2 5.173e-08 5.294e-08 -7.286 -7.276 0.010 +Zn 3.750e-05 + Zn+2 3.592e-05 1.353e-05 -4.445 -4.869 -0.424 + ZnOH+ 1.064e-06 8.312e-07 -5.973 -6.080 -0.107 + Zn(OH)2 5.227e-07 5.349e-07 -6.282 -6.272 0.010 + Zn(OH)3- 1.213e-10 9.479e-11 -9.916 -10.023 -0.107 + Zn(OH)4-2 2.258e-15 8.419e-16 -14.646 -15.075 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -7.75 -7.75 0.00 H+ + H2(g) -39.40 -42.55 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.41 -7.67 -3.26 N2 + NH3(g) -58.42 -56.65 1.77 NH3 + O2(g) -4.32 -7.28 -2.96 O2 + Zn(OH)2(e) -0.87 10.63 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 27. +------------------------------------- + + USE solution 2 + USE surface 1 + EQUILIBRIUM_PHASES 1 + Fix_H+ -8.0 NaOH 10.0 + END +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +Using solution 2. +Using surface 1. +Using pure phase assemblage 1. + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + Fix_H+ -8.00 -8.00 0.00 + NaOH is reactant 1.000e+01 1.000e+01 -1.167e-04 + +------------------------------Surface composition------------------------------ + +Hfo + 1.856e-05 Surface charge, eq + 3.316e-02 sigma, C/m**2 + 4.130e-02 psi, V + -1.607e+00 -F*psi/RT + 2.004e-01 exp(-F*psi/RT) + 6.000e+02 specific area, m**2/g + 5.400e+01 m**2 for 9.000e-02 g + + +Hfo_s + 5.000e-06 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_sOZn+ 4.990e-06 0.998 4.990e-06 -5.302 + Hfo_sOH 5.756e-09 0.001 5.756e-09 -8.240 + Hfo_sO- 4.347e-09 0.001 4.347e-09 -8.362 + Hfo_sOH2+ 1.746e-10 0.000 1.746e-10 -9.758 + +Hfo_w + 2.000e-04 moles + Mole Log + Species Moles Fraction Molality Molality + + Hfo_wOH 7.426e-05 0.371 7.426e-05 -4.129 + Hfo_wOZn+ 6.740e-05 0.337 6.740e-05 -4.171 + Hfo_wO- 5.608e-05 0.280 5.608e-05 -4.251 + Hfo_wOH2+ 2.252e-06 0.011 2.252e-06 -5.647 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + N 1.000e-01 1.000e-01 + Na 9.993e-02 9.993e-02 + Zn 2.761e-05 2.761e-05 + +----------------------------Description of solution---------------------------- + + pH = 8.000 Charge balance + pe = 11.666 Adjusted to redox equilibrium + Activity of water = 0.997 + Ionic strength = 1.000e-01 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 4.985e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.856e-05 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 + Iterations = 25 + Total H = 1.110127e+02 + Total O = 5.580635e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 + H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 + H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -42.492 -42.482 0.010 +N(-3) 0.000e+00 + NH4+ 0.000e+00 0.000e+00 -55.242 -55.369 -0.128 + NH3 0.000e+00 0.000e+00 -56.624 -56.614 0.010 +N(0) 2.980e-08 + N2 1.490e-08 1.525e-08 -7.827 -7.817 0.010 +N(3) 1.736e-12 + NO2- 1.736e-12 1.308e-12 -11.761 -11.883 -0.123 +N(5) 1.000e-01 + NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 +Na 9.993e-02 + Na+ 9.993e-02 7.823e-02 -1.000 -1.107 -0.106 + NaOH 5.034e-08 5.151e-08 -7.298 -7.288 0.010 +O(0) 7.449e-08 + O2 3.725e-08 3.811e-08 -7.429 -7.419 0.010 +Zn 2.761e-05 + Zn+2 2.513e-05 9.463e-06 -4.600 -5.024 -0.424 + ZnOH+ 1.323e-06 1.034e-06 -5.878 -5.985 -0.107 + Zn(OH)2 1.156e-06 1.183e-06 -5.937 -5.927 0.010 + Zn(OH)3- 4.772e-10 3.729e-10 -9.321 -9.428 -0.107 + Zn(OH)4-2 1.579e-14 5.890e-15 -13.802 -14.230 -0.428 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Fix_H+ -8.00 -8.00 0.00 H+ + H2(g) -39.33 -42.48 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + N2(g) -4.56 -7.82 -3.26 N2 + NH3(g) -58.38 -56.61 1.77 NH3 + O2(g) -4.46 -7.42 -2.96 O2 + Zn(OH)2(e) -0.53 10.97 11.50 Zn(OH)2 + +------------------ +End of simulation. +------------------ + +------------------------------------- +Reading input data for simulation 28. +------------------------------------- + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex8.sel b/Sun/examples/ex8.sel new file mode 100644 index 00000000..7bbafc65 --- /dev/null +++ b/Sun/examples/ex8.sel @@ -0,0 +1,27 @@ + sim state soln dist_x time step pH pe m_Zn+2 m_Hfo_wOZn+ m_Hfo_sOZn+ + 2 react 1 -99 0 1 5 15.0946 9.9667e-08 1.3194e-11 3.1498e-10 + 3 react 1 -99 0 1 5.25 14.8089 9.9093e-08 3.6118e-11 8.6216e-10 + 4 react 1 -99 0 1 5.5 14.5232 9.7567e-08 9.7221e-11 2.3200e-09 + 5 react 1 -99 0 1 5.75 14.2374 9.3657e-08 2.5418e-10 6.0611e-09 + 6 react 1 -99 0 1 6 13.9517 8.4476e-08 6.2406e-10 1.4855e-08 + 7 react 1 -99 0 1 6.25 13.666 6.6695e-08 1.3446e-09 3.1897e-08 + 8 react 1 -99 0 1 6.5 13.3803 4.2322e-08 2.3406e-09 5.5265e-08 + 9 react 1 -99 0 1 6.75 13.0946 2.1052e-08 3.2179e-09 7.5665e-08 + 10 react 1 -99 0 1 7 12.8089 8.7494e-09 3.7289e-09 8.7472e-08 + 11 react 1 -99 0 1 7.25 12.5232 3.3000e-09 3.9564e-09 9.2708e-08 + 12 react 1 -99 0 1 7.5 12.2374 1.1903e-09 4.0447e-09 9.4740e-08 + 13 react 1 -99 0 1 7.75 11.9517 4.2114e-10 4.0771e-09 9.5483e-08 + 14 react 1 -99 0 1 8 11.666 1.4799e-10 4.0887e-09 9.5749e-08 + 15 react 2 -99 0 1 5 15.0946 9.9686e-05 1.3187e-08 2.9620e-07 + 16 react 2 -99 0 1 5.25 14.8089 9.9220e-05 3.6081e-08 7.3494e-07 + 17 react 2 -99 0 1 5.5 14.5231 9.8300e-05 9.7297e-08 1.5866e-06 + 18 react 2 -99 0 1 5.75 14.2374 9.6947e-05 2.5891e-07 2.7658e-06 + 19 react 2 -99 0 1 6 13.9517 9.5437e-05 6.8302e-07 3.8297e-06 + 20 react 2 -99 0 1 6.25 13.666 9.3651e-05 1.7815e-06 4.4782e-06 + 21 react 2 -99 0 1 6.5 13.3803 9.0584e-05 4.4798e-06 4.7815e-06 + 22 react 2 -99 0 1 6.75 13.0946 8.4566e-05 1.0266e-05 4.9051e-06 + 23 react 2 -99 0 1 7 12.8088 7.4581e-05 2.0039e-05 4.9534e-06 + 24 react 2 -99 0 1 7.25 12.5229 6.1786e-05 3.2572e-05 4.9732e-06 + 25 react 2 -99 0 1 7.5 12.2374 4.8388e-05 4.5601e-05 4.9823e-06 + 26 react 2 -99 0 1 7.75 11.9517 3.5918e-05 5.7508e-05 4.9871e-06 + 27 react 2 -99 0 1 8 11.666 2.5127e-05 6.7404e-05 4.9897e-06 diff --git a/Sun/examples/ex9.log b/Sun/examples/ex9.log new file mode 100644 index 00000000..e69de29b diff --git a/Sun/examples/ex9.out b/Sun/examples/ex9.out new file mode 100644 index 00000000..e865b680 --- /dev/null +++ b/Sun/examples/ex9.out @@ -0,0 +1,1284 @@ + Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex9 + Output file: ex9.out +Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat + +------------------ +Reading data base. +------------------ + + SOLUTION_MASTER_SPECIES + SOLUTION_SPECIES + PHASES + EXCHANGE_MASTER_SPECIES + EXCHANGE_SPECIES + SURFACE_MASTER_SPECIES + SURFACE_SPECIES + RATES + END +------------------------------------ +Reading input data for simulation 1. +------------------------------------ + + TITLE Example 9.--Kinetically controlled oxidation of ferrous + iron. Decoupled valence states of iron. + SOLUTION_MASTER_SPECIES + Fe_di Fe_di+2 0.0 Fe_di 55.847 + Fe_tri Fe_tri+3 0.0 Fe_tri 55.847 + SOLUTION_SPECIES + Fe_di+2 = Fe_di+2 + log_k 0.0 + Fe_tri+3 = Fe_tri+3 + log_k 0.0 + Fe_di+2 + H2O = Fe_diOH+ + H+ + log_k -9.5 + delta_h 13.20 kcal + Fe_di+2 + Cl- = Fe_diCl+ + log_k 0.14 + Fe_di+2 + CO3-2 = Fe_diCO3 + log_k 4.38 + Fe_di+2 + HCO3- = Fe_diHCO3+ + log_k 2.0 + Fe_di+2 + SO4-2 = Fe_diSO4 + log_k 2.25 + delta_h 3.230 kcal + Fe_di+2 + HSO4- = Fe_diHSO4+ + log_k 1.08 + Fe_di+2 + 2HS- = Fe_di(HS)2 + log_k 8.95 + Fe_di+2 + 3HS- = Fe_di(HS)3- + log_k 10.987 + Fe_di+2 + HPO4-2 = Fe_diHPO4 + log_k 3.6 + Fe_di+2 + H2PO4- = Fe_diH2PO4+ + log_k 2.7 + Fe_di+2 + F- = Fe_diF+ + log_k 1.0 + Fe_tri+3 + H2O = Fe_triOH+2 + H+ + log_k -2.19 + delta_h 10.4 kcal + Fe_tri+3 + 2 H2O = Fe_tri(OH)2+ + 2 H+ + log_k -5.67 + delta_h 17.1 kcal + Fe_tri+3 + 3 H2O = Fe_tri(OH)3 + 3 H+ + log_k -12.56 + delta_h 24.8 kcal + Fe_tri+3 + 4 H2O = Fe_tri(OH)4- + 4 H+ + log_k -21.6 + delta_h 31.9 kcal + 2 Fe_tri+3 + 2 H2O = Fe_tri2(OH)2+4 + 2 H+ + log_k -2.95 + delta_h 13.5 kcal + 3 Fe_tri+3 + 4 H2O = Fe_tri3(OH)4+5 + 4 H+ + log_k -6.3 + delta_h 14.3 kcal + Fe_tri+3 + Cl- = Fe_triCl+2 + log_k 1.48 + delta_h 5.6 kcal + Fe_tri+3 + 2 Cl- = Fe_triCl2+ + log_k 2.13 + Fe_tri+3 + 3 Cl- = Fe_triCl3 + log_k 1.13 + Fe_tri+3 + SO4-2 = Fe_triSO4+ + log_k 4.04 + delta_h 3.91 kcal + Fe_tri+3 + HSO4- = Fe_triHSO4+2 + log_k 2.48 + Fe_tri+3 + 2 SO4-2 = Fe_tri(SO4)2- + log_k 5.38 + delta_h 4.60 kcal + Fe_tri+3 + HPO4-2 = Fe_triHPO4+ + log_k 5.43 + delta_h 5.76 kcal + Fe_tri+3 + H2PO4- = Fe_triH2PO4+2 + log_k 5.43 + Fe_tri+3 + F- = Fe_triF+2 + log_k 6.2 + delta_h 2.7 kcal + Fe_tri+3 + 2 F- = Fe_triF2+ + log_k 10.8 + delta_h 4.8 kcal + Fe_tri+3 + 3 F- = Fe_triF3 + log_k 14.0 + delta_h 5.4 kcal + PHASES + Goethite + Fe_triOOH + 3 H+ = Fe_tri+3 + 2 H2O + log_k -1.0 + END +----- +TITLE +----- + + Example 9.--Kinetically controlled oxidation of ferrous + iron. Decoupled valence states of iron. + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 2. +------------------------------------ + + SOLUTION 1 + pH 7.0 + pe 10.0 O2(g) -0.67 + Fe_di 0.1 + Na 10. + Cl 10. charge + EQUILIBRIUM_PHASES 1 + O2(g) -0.67 + RATES + Fe_di_ox + start + 10 Fe_di = TOT("Fe_di") + 20 if (Fe_di <= 0) then goto 200 + 30 p_o2 = 10^(SI("O2(g)")) + 40 moles = (2.91e-9 + 1.33e12 * (ACT("OH-"))^2 * p_o2) * Fe_di * TIME + 200 SAVE moles + end + KINETICS 1 + Fe_di_ox + formula Fe_di -1.0 Fe_tri 1.0 + steps 100 400 3100 10800 21600 5.04e4 8.64e4 1.728e5 1.728e5 1.728e5 1.728e5 + INCREMENTAL_REACTIONS true + SELECTED_OUTPUT + file ex9.sel + reset false + USER_PUNCH + headings Days Fe(2) Fe(3) pH si_goethite + 10 PUNCH SIM_TIME/3600/24 TOT("Fe_di")*1e6, TOT("Fe_tri")*1e6, -LA("H+"), SI("Goethite") + END +------------------------------------------- +Beginning of initial solution calculations. +------------------------------------------- + +Initial solution 1. + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 Charge balance + Fe_di 1.000e-04 1.000e-04 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 7.000 + pe = 13.613 Equilibrium with O2(g) + Activity of water = 1.000 + Ionic strength = 1.030e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.308e-07 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = -1.740e-18 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 + Iterations = 9 + Total H = 1.110124e+02 + Total O = 5.550668e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + OH- 1.113e-07 1.001e-07 -6.953 -7.000 -0.046 + H+ 1.096e-07 1.000e-07 -6.960 -7.000 -0.040 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 9.149e-07 8.242e-07 -6.039 -6.084 -0.045 +Fe_di 1.000e-04 + Fe_di+2 9.886e-05 6.510e-05 -4.005 -4.186 -0.181 + Fe_diCl+ 9.149e-07 8.242e-07 -6.039 -6.084 -0.045 + Fe_diOH+ 2.285e-07 2.058e-07 -6.641 -6.687 -0.045 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 5.943e-10 5.957e-10 -9.226 -9.225 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +----------------------------------------- +Beginning of batch-reaction calculations. +----------------------------------------- + +Reaction step 1. + +WARNING: Element Fe_tri has negative moles in solution, -5.977583e-06. + Erroneous mole balance occurs as moles are added to produce zero moles. + Usually caused by KINETICS, REACTION, or diffuse layer calculation. + May be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer. +WARNING: Element Fe_tri has negative moles in solution, -1.366855e-06. + Erroneous mole balance occurs as moles are added to produce zero moles. + Usually caused by KINETICS, REACTION, or diffuse layer calculation. + May be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer. +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 100 seconds (Incremented time: 100 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.058e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -2.645e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.894e-05 9.894e-05 + Fe_tri 1.058e-06 1.058e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 6.048 Charge balance + pe = 14.565 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.030e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.289e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.530e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 206 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.821e-07 8.962e-07 -6.008 -6.048 -0.040 + OH- 1.242e-08 1.117e-08 -7.906 -7.952 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 9.071e-07 8.172e-07 -6.042 -6.088 -0.045 + Fe_triCl+2 1.330e-13 8.757e-14 -12.876 -13.058 -0.181 + Fe_triCl2+ 3.982e-15 3.587e-15 -14.400 -14.445 -0.045 + Fe_triCl3 3.282e-18 3.290e-18 -17.484 -17.483 0.001 +Fe_di 9.894e-05 + Fe_di+2 9.801e-05 6.455e-05 -4.009 -4.190 -0.181 + Fe_diCl+ 9.071e-07 8.172e-07 -6.042 -6.088 -0.045 + Fe_diOH+ 2.527e-08 2.277e-08 -7.597 -7.643 -0.045 +Fe_tri 1.058e-06 + Fe_tri(OH)2+ 9.336e-07 8.410e-07 -6.030 -6.075 -0.045 + Fe_tri(OH)3 1.206e-07 1.209e-07 -6.919 -6.918 0.001 + Fe_triOH+2 3.457e-09 2.277e-09 -8.461 -8.643 -0.181 + Fe_tri(OH)4- 1.365e-10 1.229e-10 -9.865 -9.910 -0.045 + Fe_tri+3 8.092e-13 3.162e-13 -12.092 -12.500 -0.408 + Fe_triCl+2 1.330e-13 8.757e-14 -12.876 -13.058 -0.181 + Fe_triCl2+ 3.982e-15 3.587e-15 -14.400 -14.445 -0.045 + Fe_tri2(OH)2+4 7.418e-16 1.396e-16 -15.130 -15.855 -0.726 + Fe_triCl3 3.282e-18 3.290e-18 -17.484 -17.483 0.001 + Fe_tri3(OH)4+5 3.336e-19 2.452e-20 -18.477 -19.610 -1.134 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 6.631e-11 6.647e-11 -10.178 -10.177 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.64 5.64 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 2. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 400 seconds (Incremented time: 500 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -7.364e-07 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -1.841e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.821e-05 9.821e-05 + Fe_tri 1.794e-06 1.794e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 5.810 Charge balance + pe = 14.803 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.030e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.025e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 8.635e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 25 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.699e-06 1.550e-06 -5.770 -5.810 -0.040 + OH- 7.183e-09 6.457e-09 -8.144 -8.190 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 9.005e-07 8.112e-07 -6.046 -6.091 -0.045 + Fe_triCl+2 7.069e-13 4.656e-13 -12.151 -12.332 -0.181 + Fe_triCl2+ 2.117e-14 1.907e-14 -13.674 -13.720 -0.045 + Fe_triCl3 1.745e-17 1.749e-17 -16.758 -16.757 0.001 +Fe_di 9.821e-05 + Fe_di+2 9.729e-05 6.408e-05 -4.012 -4.193 -0.181 + Fe_diCl+ 9.005e-07 8.112e-07 -6.046 -6.091 -0.045 + Fe_diOH+ 1.451e-08 1.307e-08 -7.838 -7.884 -0.045 +Fe_tri 1.794e-06 + Fe_tri(OH)2+ 1.660e-06 1.495e-06 -5.780 -5.825 -0.045 + Fe_tri(OH)3 1.239e-07 1.242e-07 -6.907 -6.906 0.001 + Fe_triOH+2 1.063e-08 7.000e-09 -7.974 -8.155 -0.181 + Fe_tri(OH)4- 8.110e-11 7.306e-11 -10.091 -10.136 -0.045 + Fe_tri+3 4.302e-12 1.681e-12 -11.366 -11.774 -0.408 + Fe_triCl+2 7.069e-13 4.656e-13 -12.151 -12.332 -0.181 + Fe_triCl2+ 2.117e-14 1.907e-14 -13.674 -13.720 -0.045 + Fe_tri2(OH)2+4 7.010e-15 1.319e-15 -14.154 -14.880 -0.726 + Fe_triCl3 1.745e-17 1.749e-17 -16.758 -16.757 0.001 + Fe_tri3(OH)4+5 5.604e-18 4.120e-19 -17.252 -18.385 -1.134 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 3.834e-11 3.843e-11 -10.416 -10.415 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.65 5.65 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 3. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 3100 seconds (Incremented time: 3600 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.614e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.036e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.659e-05 9.659e-05 + Fe_tri 3.408e-06 3.408e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 5.525 Charge balance + pe = 15.088 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.029e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 3.639e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 9.240e-16 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 65 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 3.274e-06 2.988e-06 -5.485 -5.525 -0.040 + OH- 3.726e-09 3.349e-09 -8.429 -8.475 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 8.857e-07 7.979e-07 -6.053 -6.098 -0.045 + Fe_triCl+2 5.132e-12 3.380e-12 -11.290 -11.471 -0.181 + Fe_triCl2+ 1.537e-13 1.385e-13 -12.813 -12.859 -0.045 + Fe_triCl3 1.267e-16 1.270e-16 -15.897 -15.896 0.001 +Fe_di 9.659e-05 + Fe_di+2 9.570e-05 6.303e-05 -4.019 -4.200 -0.181 + Fe_diCl+ 8.857e-07 7.979e-07 -6.053 -6.098 -0.045 + Fe_diOH+ 7.403e-09 6.669e-09 -8.131 -8.176 -0.045 +Fe_tri 3.408e-06 + Fe_tri(OH)2+ 3.242e-06 2.921e-06 -5.489 -5.534 -0.045 + Fe_tri(OH)3 1.256e-07 1.259e-07 -6.901 -6.900 0.001 + Fe_triOH+2 4.003e-08 2.636e-08 -7.398 -7.579 -0.181 + Fe_tri(OH)4- 4.265e-11 3.842e-11 -10.370 -10.415 -0.045 + Fe_tri+3 3.123e-11 1.220e-11 -10.505 -10.913 -0.408 + Fe_triCl+2 5.132e-12 3.380e-12 -11.290 -11.471 -0.181 + Fe_triCl2+ 1.537e-13 1.385e-13 -12.813 -12.859 -0.045 + Fe_tri2(OH)2+4 9.943e-14 1.871e-14 -13.002 -13.728 -0.725 + Fe_tri3(OH)4+5 1.553e-16 1.142e-17 -15.809 -16.942 -1.134 + Fe_triCl3 1.267e-16 1.270e-16 -15.897 -15.896 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 1.989e-11 1.994e-11 -10.701 -10.700 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 4. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 10800 seconds (Incremented time: 14400 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.953e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.883e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.464e-05 9.464e-05 + Fe_tri 5.361e-06 5.361e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 5.327 Charge balance + pe = 15.286 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.029e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 5.592e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.873e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 24 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 5.163e-06 4.711e-06 -5.287 -5.327 -0.040 + OH- 2.363e-09 2.124e-09 -8.627 -8.673 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 8.679e-07 7.819e-07 -6.062 -6.107 -0.045 + Fe_triCl+2 2.021e-11 1.331e-11 -10.694 -10.876 -0.181 + Fe_triCl2+ 6.053e-13 5.453e-13 -12.218 -12.263 -0.045 + Fe_triCl3 4.990e-16 5.001e-16 -15.302 -15.301 0.001 +Fe_di 9.464e-05 + Fe_di+2 9.377e-05 6.176e-05 -4.028 -4.209 -0.181 + Fe_diCl+ 8.679e-07 7.819e-07 -6.062 -6.107 -0.045 + Fe_diOH+ 4.600e-09 4.144e-09 -8.337 -8.383 -0.045 +Fe_tri 5.361e-06 + Fe_tri(OH)2+ 5.135e-06 4.626e-06 -5.289 -5.335 -0.045 + Fe_tri(OH)3 1.261e-07 1.264e-07 -6.899 -6.898 0.001 + Fe_triOH+2 9.996e-08 6.584e-08 -7.000 -7.182 -0.181 + Fe_tri+3 1.230e-10 4.806e-11 -9.910 -10.318 -0.408 + Fe_tri(OH)4- 2.716e-11 2.447e-11 -10.566 -10.611 -0.045 + Fe_triCl+2 2.021e-11 1.331e-11 -10.694 -10.876 -0.181 + Fe_tri2(OH)2+4 6.200e-13 1.167e-13 -12.208 -12.933 -0.725 + Fe_triCl2+ 6.053e-13 5.453e-13 -12.218 -12.263 -0.045 + Fe_tri3(OH)4+5 1.533e-15 1.128e-16 -14.814 -15.948 -1.133 + Fe_triCl3 4.990e-16 5.001e-16 -15.302 -15.301 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 1.261e-11 1.264e-11 -10.899 -10.898 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 5. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 21600 seconds (Incremented time: 36000 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.875e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.688e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.276e-05 9.276e-05 + Fe_tri 7.236e-06 7.236e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 5.197 Charge balance + pe = 15.415 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.029e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 7.467e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.886e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 6.954e-06 6.346e-06 -5.158 -5.197 -0.040 + OH- 1.754e-09 1.577e-09 -8.756 -8.802 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 8.507e-07 7.664e-07 -6.070 -6.116 -0.045 + Fe_triCl+2 4.947e-11 3.258e-11 -10.306 -10.487 -0.181 + Fe_triCl2+ 1.482e-12 1.335e-12 -11.829 -11.875 -0.045 + Fe_triCl3 1.221e-15 1.224e-15 -14.913 -14.912 0.001 +Fe_di 9.276e-05 + Fe_di+2 9.191e-05 6.054e-05 -4.037 -4.218 -0.181 + Fe_diCl+ 8.507e-07 7.664e-07 -6.070 -6.116 -0.045 + Fe_diOH+ 3.347e-09 3.016e-09 -8.475 -8.521 -0.045 +Fe_tri 7.236e-06 + Fe_tri(OH)2+ 6.928e-06 6.241e-06 -5.159 -5.205 -0.045 + Fe_triOH+2 1.817e-07 1.196e-07 -6.741 -6.922 -0.181 + Fe_tri(OH)3 1.263e-07 1.266e-07 -6.898 -6.897 0.001 + Fe_tri+3 3.010e-10 1.176e-10 -9.521 -9.929 -0.408 + Fe_triCl+2 4.947e-11 3.258e-11 -10.306 -10.487 -0.181 + Fe_tri(OH)4- 2.020e-11 1.819e-11 -10.695 -10.740 -0.045 + Fe_tri2(OH)2+4 2.047e-12 3.853e-13 -11.689 -12.414 -0.725 + Fe_triCl2+ 1.482e-12 1.335e-12 -11.829 -11.875 -0.045 + Fe_tri3(OH)4+5 6.830e-15 5.024e-16 -14.166 -15.299 -1.133 + Fe_triCl3 1.221e-15 1.224e-15 -14.913 -14.912 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 + NaOH 9.365e-12 9.387e-12 -11.029 -11.027 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 6. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 50400 seconds (Incremented time: 86400 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -2.406e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -6.016e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 9.036e-05 9.036e-05 + Fe_tri 9.642e-06 9.642e-06 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 5.075 Charge balance + pe = 15.538 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.029e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 9.873e-06 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.884e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 22 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 9.220e-06 8.414e-06 -5.035 -5.075 -0.040 + OH- 1.323e-09 1.189e-09 -8.878 -8.925 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 8.287e-07 7.466e-07 -6.082 -6.127 -0.045 + Fe_triCl+2 1.154e-10 7.603e-11 -9.938 -10.119 -0.181 + Fe_triCl2+ 3.457e-12 3.115e-12 -11.461 -11.507 -0.045 + Fe_triCl3 2.850e-15 2.857e-15 -14.545 -14.544 0.001 +Fe_di 9.036e-05 + Fe_di+2 8.953e-05 5.897e-05 -4.048 -4.229 -0.181 + Fe_diCl+ 8.287e-07 7.466e-07 -6.082 -6.127 -0.045 + Fe_diOH+ 2.459e-09 2.216e-09 -8.609 -8.655 -0.045 +Fe_tri 9.642e-06 + Fe_tri(OH)2+ 9.195e-06 8.284e-06 -5.036 -5.082 -0.045 + Fe_triOH+2 3.197e-07 2.106e-07 -6.495 -6.677 -0.181 + Fe_tri(OH)3 1.265e-07 1.268e-07 -6.898 -6.897 0.001 + Fe_tri+3 7.023e-10 2.745e-10 -9.153 -9.561 -0.408 + Fe_triCl+2 1.154e-10 7.603e-11 -9.938 -10.119 -0.181 + Fe_tri(OH)4- 1.525e-11 1.374e-11 -10.817 -10.862 -0.045 + Fe_tri2(OH)2+4 6.340e-12 1.193e-12 -11.198 -11.923 -0.725 + Fe_triCl2+ 3.457e-12 3.115e-12 -11.461 -11.507 -0.045 + Fe_tri3(OH)4+5 2.807e-14 2.065e-15 -13.552 -14.685 -1.133 + Fe_triCl3 2.850e-15 2.857e-15 -14.545 -14.544 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 7.063e-12 7.080e-12 -11.151 -11.150 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 7. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 86400 seconds (Incremented time: 172800 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -2.462e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -6.156e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 8.790e-05 8.790e-05 + Fe_tri 1.210e-05 1.210e-05 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 4.979 Charge balance + pe = 15.634 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.029e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.233e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.894e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 21 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.150e-05 1.050e-05 -4.939 -4.979 -0.040 + OH- 1.061e-09 9.534e-10 -8.974 -9.021 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 8.062e-07 7.263e-07 -6.094 -6.139 -0.045 + Fe_triCl+2 2.242e-10 1.477e-10 -9.649 -9.831 -0.181 + Fe_triCl2+ 6.716e-12 6.050e-12 -11.173 -11.218 -0.045 + Fe_triCl3 5.536e-15 5.549e-15 -14.257 -14.256 0.001 +Fe_di 8.790e-05 + Fe_di+2 8.709e-05 5.737e-05 -4.060 -4.241 -0.181 + Fe_diCl+ 8.062e-07 7.263e-07 -6.094 -6.139 -0.045 + Fe_diOH+ 1.918e-09 1.728e-09 -8.717 -8.763 -0.045 +Fe_tri 1.210e-05 + Fe_tri(OH)2+ 1.148e-05 1.034e-05 -4.940 -4.985 -0.045 + Fe_triOH+2 4.978e-07 3.279e-07 -6.303 -6.484 -0.181 + Fe_tri(OH)3 1.266e-07 1.269e-07 -6.898 -6.897 0.001 + Fe_tri+3 1.364e-09 5.332e-10 -8.865 -9.273 -0.408 + Fe_triCl+2 2.242e-10 1.477e-10 -9.649 -9.831 -0.181 + Fe_tri2(OH)2+4 1.537e-11 2.894e-12 -10.813 -11.539 -0.725 + Fe_tri(OH)4- 1.223e-11 1.102e-11 -10.912 -10.958 -0.045 + Fe_triCl2+ 6.716e-12 6.050e-12 -11.173 -11.218 -0.045 + Fe_tri3(OH)4+5 8.494e-14 6.251e-15 -13.071 -14.204 -1.133 + Fe_triCl3 5.536e-15 5.549e-15 -14.257 -14.256 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 5.662e-12 5.676e-12 -11.247 -11.246 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 8. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 172800 seconds (Incremented time: 345600 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -3.088e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -7.722e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 8.481e-05 8.481e-05 + Fe_tri 1.519e-05 1.519e-05 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 4.884 Charge balance + pe = 15.729 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.028e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.542e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 6.894e-15 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 21 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.431e-05 1.306e-05 -4.844 -4.884 -0.040 + OH- 8.523e-10 7.662e-10 -9.069 -9.116 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 7.779e-07 7.008e-07 -6.109 -6.154 -0.045 + Fe_triCl+2 4.323e-10 2.848e-10 -9.364 -9.546 -0.181 + Fe_triCl2+ 1.295e-11 1.167e-11 -10.888 -10.933 -0.045 + Fe_triCl3 1.068e-14 1.070e-14 -13.972 -13.971 0.001 +Fe_di 8.481e-05 + Fe_di+2 8.403e-05 5.535e-05 -4.076 -4.257 -0.181 + Fe_diCl+ 7.779e-07 7.008e-07 -6.109 -6.154 -0.045 + Fe_diOH+ 1.487e-09 1.340e-09 -8.828 -8.873 -0.045 +Fe_tri 1.519e-05 + Fe_tri(OH)2+ 1.429e-05 1.288e-05 -4.845 -4.890 -0.045 + Fe_triOH+2 7.712e-07 5.080e-07 -6.113 -6.294 -0.181 + Fe_tri(OH)3 1.266e-07 1.269e-07 -6.897 -6.896 0.001 + Fe_tri+3 2.630e-09 1.028e-09 -8.580 -8.988 -0.408 + Fe_triCl+2 4.323e-10 2.848e-10 -9.364 -9.546 -0.181 + Fe_tri2(OH)2+4 3.689e-11 6.947e-12 -10.433 -11.158 -0.725 + Fe_triCl2+ 1.295e-11 1.167e-11 -10.888 -10.933 -0.045 + Fe_tri(OH)4- 9.835e-12 8.861e-12 -11.007 -11.053 -0.045 + Fe_tri3(OH)4+5 2.539e-13 1.869e-14 -12.595 -13.728 -1.133 + Fe_triCl3 1.068e-14 1.070e-14 -13.972 -13.971 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 4.550e-12 4.561e-12 -11.342 -11.341 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 9. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 172800 seconds (Incremented time: 518400 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -2.157e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -5.393e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 8.265e-05 8.265e-05 + Fe_tri 1.735e-05 1.735e-05 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 4.829 Charge balance + pe = 15.784 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.028e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.758e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 5.287e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 18 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.624e-05 1.482e-05 -4.789 -4.829 -0.040 + OH- 7.509e-10 6.751e-10 -9.124 -9.171 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 7.581e-07 6.830e-07 -6.120 -6.166 -0.045 + Fe_triCl+2 6.322e-10 4.164e-10 -9.199 -9.380 -0.181 + Fe_triCl2+ 1.894e-11 1.706e-11 -10.723 -10.768 -0.045 + Fe_triCl3 1.561e-14 1.565e-14 -13.807 -13.806 0.001 +Fe_di 8.265e-05 + Fe_di+2 8.189e-05 5.395e-05 -4.087 -4.268 -0.181 + Fe_diCl+ 7.581e-07 6.830e-07 -6.120 -6.166 -0.045 + Fe_diOH+ 1.277e-09 1.150e-09 -8.894 -8.939 -0.045 +Fe_tri 1.735e-05 + Fe_tri(OH)2+ 1.622e-05 1.462e-05 -4.790 -4.835 -0.045 + Fe_triOH+2 9.937e-07 6.546e-07 -6.003 -6.184 -0.181 + Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 + Fe_tri+3 3.845e-09 1.503e-09 -8.415 -8.823 -0.408 + Fe_triCl+2 6.322e-10 4.164e-10 -9.199 -9.380 -0.181 + Fe_tri2(OH)2+4 6.124e-11 1.153e-11 -10.213 -10.938 -0.725 + Fe_triCl2+ 1.894e-11 1.706e-11 -10.723 -10.768 -0.045 + Fe_tri(OH)4- 8.668e-12 7.809e-12 -11.062 -11.107 -0.045 + Fe_tri3(OH)4+5 4.783e-13 3.522e-14 -12.320 -13.453 -1.133 + Fe_triCl3 1.561e-14 1.565e-14 -13.807 -13.806 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 4.009e-12 4.019e-12 -11.397 -11.396 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 10. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 172800 seconds (Incremented time: 691200 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.711e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.279e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 8.094e-05 8.094e-05 + Fe_tri 1.906e-05 1.906e-05 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 4.790 Charge balance + pe = 15.822 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.028e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 1.929e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 5.594e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 18 + Total H = 1.110124e+02 + Total O = 5.550669e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.776e-05 1.621e-05 -4.751 -4.790 -0.040 + OH- 6.869e-10 6.175e-10 -9.163 -9.209 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 7.425e-07 6.689e-07 -6.129 -6.175 -0.045 + Fe_triCl+2 8.261e-10 5.442e-10 -9.083 -9.264 -0.181 + Fe_triCl2+ 2.475e-11 2.230e-11 -10.606 -10.652 -0.045 + Fe_triCl3 2.040e-14 2.045e-14 -13.690 -13.689 0.001 +Fe_di 8.094e-05 + Fe_di+2 8.020e-05 5.283e-05 -4.096 -4.277 -0.181 + Fe_diCl+ 7.425e-07 6.689e-07 -6.129 -6.175 -0.045 + Fe_diOH+ 1.144e-09 1.031e-09 -8.942 -8.987 -0.045 +Fe_tri 1.906e-05 + Fe_tri(OH)2+ 1.774e-05 1.598e-05 -4.751 -4.796 -0.045 + Fe_triOH+2 1.188e-06 7.825e-07 -5.925 -6.107 -0.181 + Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 + Fe_tri+3 5.025e-09 1.965e-09 -8.299 -8.707 -0.408 + Fe_triCl+2 8.261e-10 5.442e-10 -9.083 -9.264 -0.181 + Fe_tri2(OH)2+4 8.749e-11 1.648e-11 -10.058 -10.783 -0.725 + Fe_triCl2+ 2.475e-11 2.230e-11 -10.606 -10.652 -0.045 + Fe_tri(OH)4- 7.930e-12 7.145e-12 -11.101 -11.146 -0.045 + Fe_tri3(OH)4+5 7.472e-13 5.503e-14 -12.127 -13.259 -1.133 + Fe_triCl3 2.040e-14 2.045e-14 -13.690 -13.689 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 3.667e-12 3.676e-12 -11.436 -11.435 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +Reaction step 11. + +Using solution 1. +Using pure phase assemblage 1. +Using kinetics 1. Kinetics defined in simulation 2. + +Kinetics 1. Kinetics defined in simulation 2. + + Time step: 172800 seconds (Incremented time: 864000 seconds) + + Rate name Delta Moles Total Moles Reactant Coefficient + + Fe_di_ox -1.441e-06 1.000e+00 Fe_di -1 + Fe_tri 1 + +-------------------------------Phase assemblage-------------------------------- + + Moles in assemblage + Phase SI log IAP log KT Initial Final Delta + + O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -3.603e-07 + +-----------------------------Solution composition------------------------------ + + Elements Molality Moles + + Cl 1.020e-02 1.020e-02 + Fe_di 7.950e-05 7.950e-05 + Fe_tri 2.050e-05 2.050e-05 + Na 1.000e-02 1.000e-02 + +----------------------------Description of solution---------------------------- + + pH = 4.760 Charge balance + pe = 15.852 Adjusted to redox equilibrium + Activity of water = 1.000 + Ionic strength = 1.028e-02 + Mass of water (kg) = 1.000e+00 + Total alkalinity (eq/kg) = 2.073e-05 + Total carbon (mol/kg) = 0.000e+00 + Total CO2 (mol/kg) = 0.000e+00 + Temperature (deg C) = 25.000 + Electrical balance (eq) = 5.638e-14 + Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 + Iterations = 18 + Total H = 1.110124e+02 + Total O = 5.550670e+01 + +----------------------------Distribution of species---------------------------- + + Log Log Log + Species Molality Activity Molality Activity Gamma + + H+ 1.902e-05 1.736e-05 -4.721 -4.760 -0.040 + OH- 6.413e-10 5.765e-10 -9.193 -9.239 -0.046 + H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 +Cl 1.020e-02 + Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 + Fe_diCl+ 7.293e-07 6.570e-07 -6.137 -6.182 -0.045 + Fe_triCl+2 1.015e-09 6.689e-10 -8.993 -9.175 -0.181 + Fe_triCl2+ 3.042e-11 2.740e-11 -10.517 -10.562 -0.045 + Fe_triCl3 2.508e-14 2.513e-14 -13.601 -13.600 0.001 +Fe_di 7.950e-05 + Fe_di+2 7.877e-05 5.189e-05 -4.104 -4.285 -0.181 + Fe_diCl+ 7.293e-07 6.570e-07 -6.137 -6.182 -0.045 + Fe_diOH+ 1.049e-09 9.450e-10 -8.979 -9.025 -0.045 +Fe_tri 2.050e-05 + Fe_tri(OH)2+ 1.900e-05 1.712e-05 -4.721 -4.766 -0.045 + Fe_triOH+2 1.363e-06 8.979e-07 -5.866 -6.047 -0.181 + Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 + Fe_tri+3 6.176e-09 2.415e-09 -8.209 -8.617 -0.408 + Fe_triCl+2 1.015e-09 6.689e-10 -8.993 -9.175 -0.181 + Fe_tri2(OH)2+4 1.152e-10 2.170e-11 -9.939 -10.664 -0.725 + Fe_triCl2+ 3.042e-11 2.740e-11 -10.517 -10.562 -0.045 + Fe_tri(OH)4- 7.405e-12 6.671e-12 -11.130 -11.176 -0.045 + Fe_tri3(OH)4+5 1.054e-12 7.762e-14 -11.977 -13.110 -1.133 + Fe_triCl3 2.508e-14 2.513e-14 -13.601 -13.600 0.001 +H(0) 0.000e+00 + H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 +Na 1.000e-02 + Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 + NaOH 3.424e-12 3.432e-12 -11.465 -11.464 0.001 +O(0) 4.677e-04 + O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 + +------------------------------Saturation indices------------------------------- + + Phase SI log IAP log KT + + Goethite 6.66 5.66 -1.00 Fe_triOOH + H2(g) -41.23 -44.38 -3.15 H2 + H2O(g) -1.51 -0.00 1.51 H2O + Halite -5.66 -4.08 1.58 NaCl + O2(g) -0.67 -3.63 -2.96 O2 + +------------------ +End of simulation. +------------------ + +------------------------------------ +Reading input data for simulation 3. +------------------------------------ + +----------- +End of run. +----------- + +No memory leaks diff --git a/Sun/examples/ex9.sel b/Sun/examples/ex9.sel new file mode 100644 index 00000000..98dc3b1e --- /dev/null +++ b/Sun/examples/ex9.sel @@ -0,0 +1,13 @@ + Days Fe(2) Fe(3) pH si_goethite + 0.0000e+00 1.0000e+02 0.0000e+00 7.0000e+00 -9.9990e+01 + 1.1574e-03 9.8942e+01 1.0578e+00 6.0476e+00 6.6424e+00 + 5.7870e-03 9.8206e+01 1.7942e+00 5.8097e+00 6.6543e+00 + 4.1667e-02 9.6592e+01 3.4082e+00 5.5247e+00 6.6602e+00 + 1.6667e-01 9.4639e+01 5.3610e+00 5.3268e+00 6.6620e+00 + 4.1667e-01 9.2764e+01 7.2360e+00 5.1975e+00 6.6627e+00 + 1.0000e+00 9.0358e+01 9.6422e+00 5.0750e+00 6.6632e+00 + 2.0000e+00 8.7896e+01 1.2104e+01 4.9790e+00 6.6635e+00 + 4.0000e+00 8.4808e+01 1.5192e+01 4.8840e+00 6.6638e+00 + 6.0000e+00 8.2651e+01 1.7349e+01 4.8290e+00 6.6639e+00 + 8.0000e+00 8.0939e+01 1.9061e+01 4.7903e+00 6.6640e+00 + 1.0000e+01 7.9498e+01 2.0502e+01 4.7605e+00 6.6640e+00 diff --git a/SurfCharge.cxx b/SurfCharge.cxx new file mode 100644 index 00000000..1a0cf559 --- /dev/null +++ b/SurfCharge.cxx @@ -0,0 +1,493 @@ +// SurfCharge.cxx: implementation of the cxxSurfCharge class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "SurfCharge.h" +#define EXTERNAL extern +#include "global.h" +#include "output.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSurfCharge::cxxSurfCharge() + // + // default constructor for cxxSurfCharge + // +{ + name = NULL; + specific_area = 0.0; + grams = 0.0; + charge_balance = 0.0; + mass_water = 0.0; + la_psi = 0.0; + diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; +} + +cxxSurfCharge::cxxSurfCharge(struct surface_charge *surf_charge_ptr) + // + // constructor for cxxSurfCharge from struct surface_charge + // +: +diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) +{ + name = surf_charge_ptr->name; + specific_area = surf_charge_ptr->specific_area; + grams = surf_charge_ptr->grams; + charge_balance = surf_charge_ptr->charge_balance; + mass_water = surf_charge_ptr->mass_water; + la_psi = surf_charge_ptr->la_psi; +} + +cxxSurfCharge::~cxxSurfCharge() +{ +} + +struct master *cxxSurfCharge::get_psi_master() +{ + struct master *master_ptr = NULL; + std::string str = this->name; + + str.append("_psi"); + master_ptr = master_bsearch(str.c_str()); + if (master_ptr == NULL) { + std::ostringstream error_oss; + error_oss << "Surface charge psi_master not found." << this->name << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); + } + return(master_ptr); +} + +struct surface_charge *cxxSurfCharge::cxxSurfCharge2surface_charge(std::list& el) + // + // Builds surface_charge structure from of cxxSurfCharge + // +{ + struct surface_charge *surf_charge_ptr = (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); + if (surf_charge_ptr == NULL) malloc_error(); + + int i = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + surf_charge_ptr[i].name = it->name; + surf_charge_ptr[i].specific_area = it->specific_area; + surf_charge_ptr[i].grams = it->grams; + surf_charge_ptr[i].charge_balance = it->charge_balance; + surf_charge_ptr[i].mass_water = it->mass_water; + surf_charge_ptr[i].la_psi = it->la_psi; + surf_charge_ptr[i].diffuse_layer_totals = it->diffuse_layer_totals.elt_list(); + surf_charge_ptr[i].psi_master = it->get_psi_master(); + surf_charge_ptr[i].count_g = 0; + surf_charge_ptr[i].g = NULL; + i++; + } + return(surf_charge_ptr); +} + +void cxxSurfCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surf_Charge element and attributes + + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "specific_area=\"" << this->specific_area << "\"" << std::endl; + s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; + s_oss << indent0 << "mass_water=\"" << this->mass_water << "\"" << std::endl; + s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl; + + // totals + s_oss << indent0; + s_oss << "diffuse_layer_totals.dump_xml(s_oss, indent + 1); + +} + +void cxxSurfCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surf_Charge element and attributes + + s_oss << indent0 << "-name " << this->name << std::endl; + s_oss << indent0 << "-specific_area " << this->specific_area << std::endl; + s_oss << indent0 << "-grams " << this->grams << std::endl; + s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; + s_oss << indent0 << "-mass_water " << this->mass_water << std::endl; + s_oss << indent0 << "-la_psi " << this->la_psi << std::endl; + + // totals + s_oss << indent0; + s_oss << "-diffuse_layer_totals" << std::endl; + this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); + +} + +void cxxSurfCharge::read_raw(CParser& parser) +{ + std::string str; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("specific_area"); // 1 + vopts.push_back("grams"); // 2 + vopts.push_back("charge_balance"); // 3 + vopts.push_back("mass_water"); // 4 + vopts.push_back("la_psi"); // 5 + vopts.push_back("diffuse_layer_totals"); // 6 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + bool specific_area_defined(false); + bool grams_defined(false); + bool charge_balance_defined(false); + bool mass_water_defined(false); + bool la_psi_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Surface for more processing + //parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); + } else { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + break; + + case 1: // specific_area + if (!(parser.get_iss() >> this->specific_area)) + { + this->specific_area = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for specific_area.", CParser::OT_CONTINUE); + } + specific_area_defined = true; + break; + + case 2: // grams + if (!(parser.get_iss() >> this->grams)) + { + this->grams = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for grams.", CParser::OT_CONTINUE); + } + grams_defined = true; + break; + + + case 3: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; + + case 4: // mass_water + if (!(parser.get_iss() >> this->mass_water)) + { + this->mass_water = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass_water.", CParser::OT_CONTINUE); + } + mass_water_defined = true; + break; + + + case 5: // la_psi + if (!(parser.get_iss() >> this->la_psi)) + { + this->la_psi = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE); + } + la_psi_defined = true; + break; + + + case 6: // diffuse_layer_totals + if ( this->diffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for SurfCharge diffuse_layer_totals.", CParser::OT_CONTINUE); + } + opt_save = 6; + break; + + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (name_defined == false) { + parser.incr_input_error(); + parser.error_msg("Name not defined for SurfCharge input.", CParser::OT_CONTINUE); + } + if (specific_area_defined == false) { + parser.incr_input_error(); + parser.error_msg("Specific_area not defined for SurfCharge input.", CParser::OT_CONTINUE); + } + if (grams_defined == false) { + parser.incr_input_error(); + parser.error_msg("Grams not defined for SurfCharge input.", CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for SurfCharge input.", CParser::OT_CONTINUE); + } + if (mass_water_defined == false) { + parser.incr_input_error(); + parser.error_msg("Mass_water not defined for SurfCharge input.", CParser::OT_CONTINUE); + } + if (la_psi_defined == false) { + parser.incr_input_error(); + parser.error_msg("La_psi not defined for SurfCharge input.", CParser::OT_CONTINUE); + } +} + +#ifdef SKIP +cxxSurfCharge& cxxSurfCharge::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxSurfCharge numkey; + + // Read surf_charge number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxSurfCharge& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SURF_CHARGE keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.surf_charge_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in surf_charge.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif + diff --git a/SurfCharge.h b/SurfCharge.h new file mode 100644 index 00000000..63022761 --- /dev/null +++ b/SurfCharge.h @@ -0,0 +1,50 @@ +#if !defined(SURFCHARGE_H_INCLUDED) +#define SURFCHARGE_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxSurfCharge +{ + +public: + + cxxSurfCharge(); + cxxSurfCharge(struct surface_charge *); + ~cxxSurfCharge(); + + + struct master *get_psi_master(); + + static struct surface_charge *cxxSurfCharge2surface_charge(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + char * name; + double specific_area; + double grams; + double charge_balance; + double mass_water; + double la_psi; + //std::map g; + //char * psi_master_name; + cxxNameDouble diffuse_layer_totals; + +public: + +}; + +#endif // !defined(SURFCHARGE_H_INCLUDED) diff --git a/SurfComp.cxx b/SurfComp.cxx new file mode 100644 index 00000000..e7cb0c55 --- /dev/null +++ b/SurfComp.cxx @@ -0,0 +1,537 @@ +// SurfComp.cxx: implementation of the cxxSurfComp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "SurfComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include "output.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSurfComp::cxxSurfComp() + // + // default constructor for cxxSurfComp + // +{ + formula = NULL; + moles = 0.0; + totals.type = cxxNameDouble::ND_ELT_MOLES; + la = 0.0; + charge_number = -99; + charge_balance = 0; + phase_name = NULL; + phase_proportion = 0.0; + rate_name = NULL; +} + +cxxSurfComp::cxxSurfComp(struct surface_comp *surf_comp_ptr) + // + // constructor for cxxSurfComp from struct surface_comp + // +: +totals(surf_comp_ptr->totals) +{ + formula = surf_comp_ptr->formula; + moles = surf_comp_ptr->moles; + la = surf_comp_ptr->la; + charge_number = surf_comp_ptr->charge; + charge_balance = surf_comp_ptr->cb; + phase_name = surf_comp_ptr->phase_name; + phase_proportion = surf_comp_ptr->phase_proportion; + rate_name = surf_comp_ptr->rate_name; +} + +cxxSurfComp::~cxxSurfComp() +{ +} + +struct master *cxxSurfComp::get_master() +{ + struct master *master_ptr = NULL; + //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { + for (cxxNameDouble::iterator it = this->totals.begin(); it != this->totals.end(); it++) { + /* Find master species */ + char *eltName = it->first; + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); + return(NULL); + } + if (elt_ptr->master->type != SURF) continue; + master_ptr = elt_ptr->master; + break; + } + if (master_ptr == NULL) { + std::ostringstream error_oss; + error_oss << "Surface formula does not contain an surface master species, " << this->formula << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); + } + return(master_ptr); +} + +struct surface_comp *cxxSurfComp::cxxSurfComp2surface_comp(std::list& el) + // + // Builds surface_comp structure from of cxxSurfComp + // +{ + struct surface_comp *surf_comp_ptr = (struct surface_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); + if (surf_comp_ptr == NULL) malloc_error(); + + int i = 0; + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + surf_comp_ptr[i].formula = it->formula; + surf_comp_ptr[i].moles = it->moles; + surf_comp_ptr[i].master = it->get_master(); + surf_comp_ptr[i].totals = it->totals.elt_list(); + surf_comp_ptr[i].la = it->la; + surf_comp_ptr[i].charge = it->charge_number; + surf_comp_ptr[i].cb = it->charge_balance; + surf_comp_ptr[i].phase_name = it->phase_name; + surf_comp_ptr[i].phase_proportion = it->phase_proportion; + surf_comp_ptr[i].rate_name = it->rate_name; + surf_comp_ptr[i].master = it->get_master(); + i++; + } + return(surf_comp_ptr); +} + +void cxxSurfComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surf_Comp element and attributes + + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) { + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) { + s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); + +} + +void cxxSurfComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surf_Comp element and attributes + + s_oss << indent0 << "-formula " << this->formula << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-la " << this->la << std::endl; + s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; + s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; + if (this->phase_name != NULL) { + s_oss << indent0 << "-phase_name " << this->phase_name << std::endl; + } + if (this->rate_name != NULL) { + s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; + } + s_oss << indent0 << "-phase_proportion " << this->phase_proportion << std::endl; + + // totals + s_oss << indent0; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 1); + +} + +void cxxSurfComp::read_raw(CParser& parser) +{ + std::string str; + + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(10); + vopts.push_back("formula"); // 0 + vopts.push_back("moles"); // 1 + vopts.push_back("la"); // 2 + vopts.push_back("charge_number"); // 3 + vopts.push_back("charge_balance"); // 4 + vopts.push_back("phase_name"); // 5 + vopts.push_back("rate_name"); // 6 + vopts.push_back("phase_proportion"); // 7 + vopts.push_back("totals"); // 8 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool formula_defined(false); + bool moles_defined(false); + bool la_defined(false); + bool charge_number_defined(false); + bool charge_balance_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Surface for more processing + //parser.error_msg("Unknown input in SURF_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // formula + if (!(parser.get_iss() >> str)) + { + this->formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); + } else { + this->formula = string_hsave(str.c_str()); + } + formula_defined = true; + break; + + case 1: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); + } + moles_defined = true; + break; + + case 2: // la + if (!(parser.get_iss() >> this->la)) + { + this->la = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la.", CParser::OT_CONTINUE); + } + la_defined = true; + break; + + case 3: // charge_number + if (!(parser.get_iss() >> this->charge_number)) + { + this->charge_number = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for charge_number.", CParser::OT_CONTINUE); + } + charge_number_defined = true; + break; + + case 4: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; + + case 5: // phase_name + if (!(parser.get_iss() >> str)) + { + this->phase_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); + } else { + this->phase_name = string_hsave(str.c_str()); + } + break; + + case 6: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); + } else { + this->rate_name = string_hsave(str.c_str()); + } + break; + + case 7: // phase_proportion + if (!(parser.get_iss() >> this->phase_proportion)) + { + this->phase_proportion = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for phase_proportion.", CParser::OT_CONTINUE); + } + break; + + case 8: // totals + if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for SurfComp totals.", CParser::OT_CONTINUE); + } + opt_save = 8; + break; + + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (formula_defined == false) { + parser.incr_input_error(); + parser.error_msg("Formula not defined for SurfComp input.", CParser::OT_CONTINUE); + } + if (moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Moles not defined for SurfComp input.", CParser::OT_CONTINUE); + } + if (la_defined == false) { + parser.incr_input_error(); + parser.error_msg("La not defined for SurfComp input.", CParser::OT_CONTINUE); + } + if (charge_number_defined == false) { + parser.incr_input_error(); + parser.error_msg("Charge_number not defined for SurfComp input.", CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for SurfComp input.", CParser::OT_CONTINUE); + } +} + +#ifdef SKIP +cxxSurfComp& cxxSurfComp::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxSurfComp numkey; + + // Read surf_comp number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxSurfComp& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SURF_COMP keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.surf_comp_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in surf_comp.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif + diff --git a/SurfComp.h b/SurfComp.h new file mode 100644 index 00000000..c025dc95 --- /dev/null +++ b/SurfComp.h @@ -0,0 +1,52 @@ +#if !defined(SURFCOMP_H_INCLUDED) +#define SURFCOMP_H_INCLUDED + +#include "NameDouble.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxSurfComp +{ + +public: + + cxxSurfComp(); + cxxSurfComp(struct surface_comp *); + ~cxxSurfComp(); + + + struct master *get_master(); + char *get_phase_name()const {return this->phase_name;} + char *get_rate_name()const {return this->rate_name;} + + static struct surface_comp *cxxSurfComp2surface_comp(std::list& el); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + char * formula; + double moles; + cxxNameDouble totals; + double la; + int charge_number; + double charge_balance; + char *phase_name; + double phase_proportion; + char *rate_name; + +public: + +}; + +#endif // !defined(SURFCOMP_H_INCLUDED) diff --git a/Surface.cxx b/Surface.cxx new file mode 100644 index 00000000..f4e1a971 --- /dev/null +++ b/Surface.cxx @@ -0,0 +1,557 @@ +// Surface.cxx: implementation of the cxxSurface class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Surface.h" +#include "SurfComp.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSurface::cxxSurface() + // + // default constructor for cxxSurface + // +: cxxNumKeyword() +{ + diffuse_layer = false; + edl = false; + only_counter_ions = false; + donnan = false; + thickness = 0.0; +} + +cxxSurface::cxxSurface(struct surface *surface_ptr) + // + // constructor for cxxSurface from struct surface + // +: +cxxNumKeyword() + +{ + int i; + + this->set_description(surface_ptr->description); + n_user = surface_ptr->n_user; + n_user_end = surface_ptr->n_user_end; + diffuse_layer = (surface_ptr->diffuse_layer == TRUE); + edl = (surface_ptr->edl == TRUE); + only_counter_ions = (surface_ptr->only_counter_ions == TRUE); + donnan = (surface_ptr->donnan == TRUE); + thickness = surface_ptr->thickness; + // Surface components + for (i = 0; i < surface_ptr->count_comps; i++) { + cxxSurfComp ec(&(surface_ptr->comps[i])); + surfComps.push_back(ec); + } + // Surface charge + for (i = 0; i < surface_ptr->count_charge; i++) { + cxxSurfCharge ec(&(surface_ptr->charge[i])); + surfCharges.push_back(ec); + } +} + +cxxSurface::~cxxSurface() +{ +} + +bool cxxSurface::get_related_phases() +{ + for (std::list::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + if (it->get_phase_name() == NULL) continue; + return(true); + } + return(false); +} + +bool cxxSurface::get_related_rate() +{ + for (std::list::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + if (it->get_rate_name() == NULL) continue; + return(true); + } + return(false); +} + +struct surface *cxxSurface::cxxSurface2surface() + // + // Builds a surface structure from instance of cxxSurface + // +{ + struct surface *surface_ptr = surface_alloc(); + + surface_ptr->description = this->get_description(); + surface_ptr->n_user = this->n_user; + surface_ptr->n_user_end = this->n_user_end; + surface_ptr->new_def = FALSE; + surface_ptr->diffuse_layer = this->diffuse_layer; + surface_ptr->edl = this->edl; + surface_ptr->only_counter_ions = this->only_counter_ions; + surface_ptr->donnan = this->donnan; + surface_ptr->thickness = this->thickness; + surface_ptr->debye_units = 1.0; + surface_ptr->solution_equilibria = FALSE; + surface_ptr->n_solution = -2; + surface_ptr->related_phases = (int) this->get_related_phases(); + surface_ptr->related_rate = (int) this->get_related_rate(); + surface_ptr->transport = FALSE; + + // Surface comps + surface_ptr->count_comps = this->surfComps.size(); + surface_ptr->comps = (struct surface_comp *) free_check_null(surface_ptr->comps); + surface_ptr->comps = cxxSurfComp::cxxSurfComp2surface_comp(this->surfComps); + + // Surface charge + surface_ptr->count_charge = this->surfCharges.size(); + surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); + surface_ptr->charge = cxxSurfCharge::cxxSurfCharge2surface_charge(this->surfCharges); + + return(surface_ptr); +} + +void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surface element and attributes + s_oss << indent0; + s_oss << "diffuse_layer << "\"" << std::endl; + + s_oss << indent1; + s_oss << "edl=\"" << this->edl << "\"" << std::endl; + + s_oss << indent1; + s_oss << "only_counter_ions=\"" << this->only_counter_ions << "\"" << std::endl; + + s_oss << indent1; + s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; + + s_oss << indent1; + s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; + + // surface component structures + s_oss << indent1; + s_oss << "::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + } + // surface charge structures + s_oss << indent1; + s_oss << "::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} + +void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Surface element and attributes + s_oss << indent0; + s_oss << "SURFACE_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; + + s_oss << indent1; + s_oss << "-edl " << this->edl << std::endl; + + s_oss << indent1; + s_oss << "-only_counter_ions " << this->only_counter_ions << std::endl; + + s_oss << indent1; + s_oss << "-donnan " << this->donnan << std::endl; + + s_oss << indent1; + s_oss << "-thickness " << this->thickness << std::endl; + + // surfComps structures + for (std::list::const_iterator it = surfComps.begin(); it != surfComps.end(); ++it) { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } + // surface charge structures + { + for (std::list::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) { + s_oss << indent1; + s_oss << "-charge_component " << std::endl; + it->dump_raw(s_oss, indent + 2); + } + } + + return; +} + +void cxxSurface::read_raw(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("diffuse_layer"); // 0 + vopts.push_back("edl"); // 1 + vopts.push_back("only_counter_ions"); // 2 + vopts.push_back("donnan"); // 3 + vopts.push_back("thickness"); // 4 + vopts.push_back("component"); // 5 + vopts.push_back("charge_component"); // 6 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read surface number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool diffuse_layer_defined(false); + bool edl_defined(false); + bool only_counter_ions_defined(false); + bool donnan_defined(false); + bool thickness_defined(false); + + for (;;) + { + int opt; + if (useLastLine == false) { + opt = parser.get_option(vopts, next_char); + } else { + opt = parser.getOptionFromLastLine(vopts, next_char); + } + 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 SURF_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // diffuse_layer + if (!(parser.get_iss() >> this->diffuse_layer)) + { + this->diffuse_layer = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for diffuse_layer.", CParser::OT_CONTINUE); + } + diffuse_layer_defined = true; + useLastLine = false; + break; + + case 1: // edl + if (!(parser.get_iss() >> this->edl)) + { + this->edl = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for edl.", CParser::OT_CONTINUE); + } + edl_defined = true; + useLastLine = false; + break; + + case 2: // only_counter_ions + if (!(parser.get_iss() >> this->only_counter_ions)) + { + this->only_counter_ions = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for only_counter_ions.", CParser::OT_CONTINUE); + } + only_counter_ions_defined = true; + useLastLine = false; + break; + + case 3: // donnan + if (!(parser.get_iss() >> this->donnan)) + { + this->donnan = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for donnan.", CParser::OT_CONTINUE); + } + donnan_defined = true; + useLastLine = false; + break; + + case 4: // thickness + if (!(parser.get_iss() >> this->thickness)) + { + this->thickness = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for thickness.", CParser::OT_CONTINUE); + } + thickness_defined = true; + useLastLine = false; + break; + + case 5: // component + { + cxxSurfComp ec; + ec.read_raw(parser); + this->surfComps.push_back(ec); + } + useLastLine = true; + break; + + case 6: // charge_component + { + cxxSurfCharge ec; + ec.read_raw(parser); + this->surfCharges.push_back(ec); + } + useLastLine = true; + break; + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (diffuse_layer_defined == false) { + parser.incr_input_error(); + parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (edl_defined == false) { + parser.incr_input_error(); + parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (only_counter_ions_defined == false) { + parser.incr_input_error(); + parser.error_msg("Only_counter_ions not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (donnan_defined == false) { + parser.incr_input_error(); + parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (thickness_defined == false) { + parser.incr_input_error(); + parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } +} +#ifdef SKIP +cxxSurface& cxxSurface::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + cxxSurface numkey; + + // Read surface number and description + numkey.read_number_description(parser); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + //cxxSurface& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SURFACE keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = cxxPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.surface_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + cxxIsotope isotope; + if (isotope.read(parser) == cxxIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in surface.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxConc conc; + if (conc.read(parser, sol) == cxxConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif diff --git a/Surface.h b/Surface.h new file mode 100644 index 00000000..03652f56 --- /dev/null +++ b/Surface.h @@ -0,0 +1,56 @@ +#if !defined(SURFACE_H_INCLUDED) +#define SURFACE_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" +#include "SurfComp.h" +#include "SurfCharge.h" + +class cxxSurface : public cxxNumKeyword +{ + +public: + cxxSurface(); + cxxSurface(struct surface *); + ~cxxSurface(); + + struct surface *cxxSurface2surface(); + + struct surf_comp *cxxSurfComp2surf_comp(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + + bool get_related_phases(void); + + bool get_related_rate(void); + + +protected: + std::list surfComps; + std::list surfCharges; + bool diffuse_layer; + bool edl; + bool only_counter_ions; + bool donnan; + double thickness; + //double debye_units; + //int transport; + +public: + //static std::map& map; + +}; + +#endif // !defined(SURFACE_H_INCLUDED) diff --git a/Utils.cxx b/Utils.cxx new file mode 100644 index 00000000..81efd109 --- /dev/null +++ b/Utils.cxx @@ -0,0 +1,79 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include // ::tolower +#include // ::tolower +#include //std::transform +#include // std::cout std::cerr + +#include "Utils.h" +#include "Parser.h" +#include "output.h" +//////////////////////////////////////////////////////////////////////////// +int Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 = ::tolower(*str1++)) == (c2 = *str2++)) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} + +//////////////////////////////////////////////////////////////////////////// +int Utilities::strcmp_nocase(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 = ::tolower(*str1++)) == (c2 = ::tolower(*str2++))) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} + +//////////////////////////////////////////////////////////////////////////// +void Utilities::str_tolower(std::string& str) +//////////////////////////////////////////////////////////////////////////// +{ + std::transform(str.begin(), str.end(), str.begin(), tolower); +} + + + +//////////////////////////////////////////////////////////////////////////// +bool Utilities::replace(const char* str1, const char* str2, std::string& str) +//////////////////////////////////////////////////////////////////////////// +{ + std::string::size_type n = str.find(str1, 0); + if (n == std::string::npos) return false; + + str.replace(n, ::strlen(str1), str2); + return true; +} +//////////////////////////////////////////////////////////////////////////// +void Utilities::squeeze_white(std::string& s_l) +//////////////////////////////////////////////////////////////////////////// +{ + std::string str; + std::string::iterator beg = s_l.begin(); + std::string::iterator end = s_l.end(); + CParser::copy_token(str, beg, end); + s_l = str; +} +#ifdef SKIP +//////////////////////////////////////////////////////////////////////////// +void Utilities::error_msg (const std::string& err_str, const int stop) +//////////////////////////////////////////////////////////////////////////// +{ + //std::cerr << err_str << std::endl; + output_message(OUTPUT_ERROR, err_str, stop, "", args); +} +#endif diff --git a/Utils.h b/Utils.h new file mode 100644 index 00000000..0c1bba6c --- /dev/null +++ b/Utils.h @@ -0,0 +1,31 @@ +#if !defined(UTILITIES_H_INCLUDED) +#define UTILITIES_H_INCLUDED + +#include + +namespace Utilities { + + const char INDENT[] = " "; + + enum STATUS_TYPE { + OK = 0, + ERROR = 1 + }; + + STATUS_TYPE parse_couple(std::string& token); + + int strcmp_nocase(const char *str1, const char *str2); + + int strcmp_nocase_arg1(const char *str1, const char *str2); + + void str_tolower(std::string& str); + + bool replace(const char* str1, const char* str2, std::string& str); + + void squeeze_white(std::string& s_l); + + void error_msg(const std::string&, const int stopflag); + +} + +#endif // UTILITIES_H_INCLUDED diff --git a/advection.cpp b/advection.cpp new file mode 100644 index 00000000..9453c372 --- /dev/null +++ b/advection.cpp @@ -0,0 +1,103 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: advection.c 78 2005-02-01 22:47:12Z dlpark $"; + +/* ---------------------------------------------------------------------- */ +int advection(void) +/* ---------------------------------------------------------------------- */ +{ + int i, n; + LDBLE kin_time; + if (svnid == NULL) fprintf(stderr," "); +/* + * Calculate advection + */ + state = ADVECTION; +/* mass_water_switch = TRUE; */ +/* + * Check existence of all solutions + */ + for (i = 0; i <= count_ad_cells; i++) { + if (solution_bsearch(i, &n, TRUE) == NULL) { + input_error++; + sprintf(error_string, "Solution %d is needed for advection, but is not defined.", i); + error_msg(error_string, CONTINUE); + } + } +/* + * Check kinetics logic + */ + kin_time = advection_kin_time; + if (kin_time <= 0.0) { + for (i = 1; i <= count_ad_cells; i++) { + if (kinetics_bsearch(i, &n) != NULL) { + input_error++; + sprintf(error_string, "KINETIC reaction(s) defined, but time_step is not defined in ADVECTION keyword."); + error_msg(error_string, CONTINUE); + break; + } + } + } +/* + * Quit on error + */ + if (input_error > 0) { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Equilibrate solutions with phases, exchangers, surfaces + */ + last_model.force_prep = TRUE; + rate_sim_time_start = 0; + for (advection_step = 1; advection_step <= count_ad_shifts; advection_step++) { + output_msg(OUTPUT_LOG, "\nBeginning of advection time step %d, cumulative pore volumes %f.\n", advection_step, (double) (((LDBLE) advection_step) / ((LDBLE) count_ad_cells))); + if (pr.use == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE, "Beginning of advection time step %d, cumulative pore volumes %f.\n", + advection_step, (double) (((LDBLE) advection_step) / ((LDBLE) count_ad_cells))); + } +/* + * Advect + */ + for (i = count_ad_cells; i > 0; i--) { + solution_duplicate(i - 1, i); + } +/* + * Equilibrate and (or) mix + */ + for (i = 1; i <= count_ad_cells; i++) { + + cell_no = i; + set_advection(i, TRUE, TRUE, i); + run_reactions(i, kin_time, TRUE, 1.0); + if (advection_kin_time_defined == TRUE) { + rate_sim_time = rate_sim_time_start + kin_time; + } + output_msg(OUTPUT_LOG, "\nCell %d.\n\n", i); + if (pr.use == TRUE && pr.all == TRUE && + advection_step % print_ad_modulus == 0 && + advection_print[i-1] == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nCell %d.\n\n", i); + } + if (advection_step % punch_ad_modulus == 0 && + advection_punch[i-1] == TRUE ) { + punch_all(); + } + if (advection_step % print_ad_modulus == 0 && + advection_print[i-1] == TRUE ) { + print_all(); + } + if (i > 1) solution_duplicate(-2, i-1); + saver(); + } + solution_duplicate(-2, count_ad_cells); + rate_sim_time_start += kin_time; + } + initial_total_time += rate_sim_time_start; + /* free_model_allocs(); */ + mass_water_switch = FALSE; + return(OK); +} diff --git a/basic.cpp b/basic.cpp new file mode 100644 index 00000000..5b567552 --- /dev/null +++ b/basic.cpp @@ -0,0 +1,4400 @@ +/* Output from p2c, the Pascal-to-C translator */ +/* From input file "basic.p" */ + + +static char const svnid[] = "$Id: basic.c 247 2005-04-14 13:47:35Z dlpark $"; + +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +int n_user_punch_index; +#ifdef PHREEQ98 +void GridChar(char* s, char* a); +extern int colnr, rownr; +#endif + +#include "p2c.h" + +static int sget_logical_line(char **ptr, int *l, char *return_line); + +#define checking true +#define varnamelen 20 +#define maxdims 4 + +typedef Char varnamestring[varnamelen + 1]; +typedef Char string255[256]; + +#define tokvar 0 +#define toknum 1 +#define tokstr 2 +#define toksnerr 3 +#define tokplus 4 +#define tokminus 5 +#define toktimes 6 +#define tokdiv 7 +#define tokup 8 +#define toklp 9 +#define tokrp 10 +#define tokcomma 11 +#define toksemi 12 +#define tokcolon 13 +#define tokeq 14 +#define toklt 15 +#define tokgt 16 +#define tokle 17 +#define tokge 18 +#define tokne 19 +#define tokand 20 +#define tokor 21 +#define tokxor 22 +#define tokmod 23 +#define toknot 24 +#define toksqr 25 +#define toksqrt 26 +#define toksin 27 +#define tokcos 28 +#define toktan 29 +#define tokarctan 30 +#define toklog 31 +#define tokexp 32 +#define tokabs 33 +#define toksgn 34 +#define tokstr_ 35 +#define tokval 36 +#define tokchr_ 37 +#define tokasc 38 +#define toklen 39 +#define tokmid_ 40 +#define tokpeek 41 +#define tokrem 42 +#define toklet 43 +#define tokprint 44 +#define tokinput 45 +#define tokgoto 46 +#define tokif 47 +#define tokend 48 +#define tokstop 49 +#define tokfor 50 +#define toknext 51 +#define tokwhile 52 +#define tokwend 53 +#define tokgosub 54 +#define tokreturn 55 +#define tokread 56 +#define tokdata 57 +#define tokrestore 58 +#define tokgotoxy 59 +#define tokon 60 +#define tokdim 61 +#define tokpoke 62 +#define toklist 63 +#define tokrun 64 +#define toknew 65 +#define tokload 66 +#define tokmerge 67 +#define toksave 68 +#define tokbye 69 +#define tokdel 70 +#define tokrenum 71 +#define tokthen 72 +#define tokelse 73 +#define tokto 74 +#define tokstep 75 +#define toktc 76 +#define tokm0 77 +#define tokm 78 +#define tokparm 79 +#define tokact 80 +#define tokmol 81 +#define tokla 82 +#define toklm 83 +#define toksr 84 +#define toksi 85 +#define toktot 86 +#define toktk 87 +#define toktime 88 +#define toklog10 89 +#define toksim_time 90 +#define tokequi 91 +#define tokgas 92 +#define tokpunch 93 +#define tokkin 94 +#define toks_s 95 +#define tokmu 96 +#define tokalk 97 +#define tokrxn 98 +#define tokdist 99 +#define tokmisc1 100 +#define tokmisc2 101 +#define tokedl 102 +#define tokstep_no 103 +#define toksim_no 104 +#define toktotal_time 105 +#define tokput 106 +#define tokget 107 +#define tokcharge_balance 109 +#define tokpercent_error 110 +#ifdef PHREEQ98 +#define tokgraph_x 111 +#define tokgraph_y 112 +#define tokgraph_sy 113 +#endif +#define tokcell_no 114 +#define tokexists 115 +#define toksurf 116 +#define toklk_species 117 +#define toklk_named 118 +#define toklk_phase 119 +#define toksum_species 120 +#define toksum_gas 121 +#define toksum_s_s 122 +#define tokcalc_value 123 +#define tokdescription 124 +#define toksys 125 +#define tokinstr 126 +#define tokltrim 127 +#define tokrtrim 128 +#define toktrim 129 +#define tokpad 130 + +typedef LDBLE numarray[]; +typedef Char *strarray[]; + +#define forloop 0 +#define whileloop 1 +#define gosubloop 2 + +typedef struct tokenrec { + struct tokenrec *next; + int kind; + union { + struct varrec *vp; + LDBLE num; + Char *sp; + Char snch; + } UU; +} tokenrec; + +typedef struct linerec { + long num, num2; + tokenrec *txt; + struct linerec *next; +} linerec; + +typedef struct varrec { + varnamestring name; + struct varrec *next; + long dims[maxdims]; + char numdims; + boolean stringvar; + union { + struct { + LDBLE *arr; + LDBLE *val, rv; + } U0; + struct { + Char **sarr; + Char **sval, *sv; + } U1; + } UU; +} varrec; + +typedef struct valrec { + boolean stringval; + union { + LDBLE val; + Char *sval; + } UU; +} valrec; + +typedef struct looprec { + struct looprec *next; + linerec *homeline; + tokenrec *hometok; + int kind; + union { + struct { + varrec *vp; + LDBLE max, step; + } U0; + } UU; +} looprec; + + +Static Char *inbuf; +Static linerec *linebase; +Static varrec *varbase; +Static looprec *loopbase; +Static long curline; +Static linerec *stmtline, *dataline; +Static tokenrec *stmttok, *datatok, *buf; +Static boolean exitflag; + +Static int free_dim_stringvar(struct varrec *varbase); +extern long EXCP_LINE; +Static void parseinput(tokenrec **buf); +Static void exec(void); +Static void disposetokens(tokenrec **tok); + +/*$if not checking$ + $range off$ +$end$*/ +static HashTable *command_hash_table; +static const struct key command[] = { + {"and", tokand}, + {"or", tokor}, + {"xor", tokxor}, + {"not", toknot}, + {"mod", tokmod}, + {"sqr", toksqr}, + {"sqrt", toksqrt}, + {"sin", toksin}, + {"cos", tokcos}, + {"tan", toktan}, + {"arctan", tokarctan}, + {"log", toklog}, + {"exp", tokexp}, + {"abs", tokabs}, + {"sgn", toksgn}, + {"str$", tokstr_}, + {"val", tokval}, + {"chr$", tokchr_}, + {"asc", tokasc}, + {"len", toklen}, + {"mid$", tokmid_}, + {"peek", tokpeek}, + {"let", toklet}, + {"print", tokprint}, + {"punch", tokpunch}, +#ifdef PHREEQ98 + {"graph_x", tokgraph_x}, + {"graph_y", tokgraph_y}, + {"graph_sy", tokgraph_sy}, +#endif + {"input", tokinput}, + {"goto", tokgoto}, + {"go to", tokgoto}, + {"if", tokif}, + {"end", tokend}, + {"stop", tokstop}, + {"for", tokfor}, + {"next", toknext}, + {"while", tokwhile}, + {"wend", tokwend}, + {"gosub", tokgosub}, + {"return", tokreturn}, + {"read", tokread}, + {"data", tokdata}, + {"restore", tokrestore}, + {"gotoxy", tokgotoxy}, + {"on", tokon}, + {"dim", tokdim}, + {"poke", tokpoke}, + {"list", toklist}, + {"run", tokrun}, + {"new", toknew}, + {"load", tokload}, + {"merge", tokmerge}, + {"save", toksave}, + {"bye", tokbye}, + {"quit", tokbye}, + {"del", tokdel}, + {"renum", tokrenum}, + {"then", tokthen}, + {"else", tokelse}, + {"to", tokto}, + {"step", tokstep}, + {"tc", toktc}, + {"tk", toktk}, + {"time", toktime}, + {"sim_time", toksim_time}, + {"total_time", toktotal_time}, + {"m0", tokm0}, + {"m", tokm}, + {"parm", tokparm}, + {"act", tokact}, + {"edl", tokedl}, + {"surf", toksurf}, + {"equi", tokequi}, + {"kin", tokkin}, + {"gas", tokgas}, + {"s_s", toks_s}, + {"misc1", tokmisc1}, + {"misc2", tokmisc2}, + {"mu", tokmu}, + {"alk", tokalk}, + {"lk_species", toklk_species}, + {"lk_named", toklk_named}, + {"lk_phase", toklk_phase}, + {"sum_species", toksum_species}, + {"sum_gas", toksum_gas}, + {"sum_s_s", toksum_s_s}, + {"calc_value", tokcalc_value}, + {"description", tokdescription}, + {"sys", toksys}, + {"instr", tokinstr}, + {"ltrim", tokltrim}, + {"rtrim", tokrtrim}, + {"trim", toktrim}, + {"pad", tokpad}, + {"rxn", tokrxn}, + {"dist", tokdist}, + {"mol", tokmol}, + {"la", tokla}, + {"lm", toklm}, + {"sr", toksr}, + {"si", toksi}, + {"step_no", tokstep_no}, + {"cell_no", tokcell_no}, + {"sim_no", toksim_no}, + {"tot", toktot}, + {"log10", toklog10}, + {"charge_balance", tokcharge_balance}, + {"percent_error", tokpercent_error}, + {"put", tokput}, + {"get", tokget}, + {"exists", tokexists}, + {"rem", tokrem} +}; +static int NCMDS = (sizeof(command) / sizeof(struct key)); + +/* ---------------------------------------------------------------------- */ +void cmd_initialize(void) +/* ---------------------------------------------------------------------- */ +{ + ENTRY item, *found_item; + int i; +/* + * create hash table + */ + hcreate_multi((unsigned) 2*NCMDS, &command_hash_table); +/* + * fill with commands + */ + for (i = 0; i < NCMDS; i++) { + item.key = command[i].name; + item.data = (void *) &command[i]; + found_item = hsearch_multi(command_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in basic commands initialization."); + error_msg(error_string, STOP); + } + } + return; +} +/* ---------------------------------------------------------------------- */ +void cmd_free(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * destroy hash table + */ + hdestroy_multi(command_hash_table); + command_hash_table = NULL; + return; +} + +#ifdef SKIP +int main(int argc, Char *argv[]) +{ /*main*/ + char commands[] = "10a=1\n20a=a*2;30print a;40quit;run"; + basic_main(commands); + return 0; +} +#endif +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main*/ + int l; + char *ptr; + if (svnid == NULL) fprintf(stderr," "); + + PASCAL_MAIN(0, NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do { + TRY(try2); + ptr = commands; + do { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) { +#ifdef SKIP + printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); +#endif + sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); + error_msg(error_string, CONTINUE); + } else { + putchar('\n'); + } + ENDTRY(try2); + } while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + return(P_escapecode); +} +int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main*/ + int l, i; + char *ptr; + PASCAL_MAIN(0,NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do { + TRY(try2); + i = 0; + ptr = commands; + do { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) { + i++; + if (i == 1) { + strcpy(inbuf, "renum"); + } else if (i == 2) { + strcpy(inbuf, "list"); + } else if (i == 3) { + strcpy(inbuf, "new"); + } else if (i == 4) { + strcpy(inbuf, "bye"); + } + } + parseinput(&buf); + if (curline == 0) { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) { +#ifdef SKIP + printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); +#endif + sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); + error_msg(error_string, CONTINUE); + } else { + putchar('\n'); + } + ENDTRY(try2); + } while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + + return(P_escapecode); +} +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) +{ /*main*/ + int l; + char *ptr; + PASCAL_MAIN(0,NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if ( inbuf == NULL) malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + linebase = (linerec *) lnbase; + varbase = (varrec *) vbase; + loopbase = (looprec *) lpbase; + do { + TRY(try2); + do { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) { +#ifdef SKIP + printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); +#endif + sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); + error_msg(error_string, CONTINUE); + } else { + putchar('\n'); + } + ENDTRY(try2); + } while (!(exitflag || P_eof())); + + /* exit(EXIT_SUCCESS); */ + free(inbuf); + return(P_escapecode); +} +int basic_main(char *commands) +{ /*main*/ + int l; + char *ptr; +#ifdef SKIP + PASCAL_MAIN(argc, argv); +#endif + PASCAL_MAIN(0,NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; +#ifdef SKIP + printf("Chipmunk BASIC 1.0\n\n"); +#endif + exitflag = false; + ptr = commands; + do { + TRY(try2); + do { +#ifdef SKIP + putchar('>'); +#endif + if (sget_logical_line(&ptr, &l, inbuf) == EOF) { + strcpy(inbuf, "bye"); + } +#ifdef SKIP + gets(inbuf); +#endif + parseinput(&buf); + if (curline == 0) { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) { +#ifdef SKIP + printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); +#endif + sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); + error_msg(error_string, CONTINUE); + } else { + putchar('\n'); + } + ENDTRY(try2); + } while (!(exitflag || P_eof())); + return 1; +/* exit(EXIT_SUCCESS); */ +} + + + + + + + +/* End. */ +/* ---------------------------------------------------------------------- */ +int sget_logical_line(char **ptr, int *l, char *return_line) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads file fp until end of line, ";", or eof + * stores characters in line_save + * reallocs line_save and line if more space is needed + * + * returns: + * EOF on empty line on end of file or + * OK otherwise + * *l returns length of line + */ + int i; + char c; + i = 0; + if (**ptr == '\0') return (EOF); + for (;;) { + c = **ptr; + if (c == '\0') break; + (*ptr)++; + if (c == ';' || c == '\n') break; + return_line[i++] = c; + } + return_line[i] = '\0'; + *l = i; + return(1); +} +Static void restoredata(void) +{ + dataline = NULL; + datatok = NULL; +} + + + +Static void clearloops(void) +{ + looprec *l; + + while (loopbase != NULL) { + l = loopbase->next; + free(loopbase); + loopbase = l; + } +} + + + +#ifdef SKIP +Static long arraysize(varrec *v) +{ + long i, j, FORLIM; + + if (v->stringvar) + j = 4; + else + j = 8; + FORLIM = v->numdims; + for (i = 0; i < FORLIM; i++) + j *= v->dims[i]; + return j; +} +#endif + +Static void clearvar(varrec *v) +{ + if (v->numdims != 0) { + if (v->stringvar == 0) { + free(v->UU.U0.arr); + v->UU.U0.arr = NULL; + } else { + free_dim_stringvar(v); + } + } else if (v->stringvar && v->UU.U1.sv != NULL) { + free(v->UU.U1.sv); + } + v->numdims = 0; + if (v->stringvar) { + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } else { + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } +} + + +Static void clearvars(void) +{ + varrec *v; + + v = varbase; + while (v != NULL) { + clearvar(v); + v = v->next; + } +} + +Static Char *numtostr(Char *Result, LDBLE n) +{ + /*string255 s;*/ + char *s; + long i; + + s = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (s == NULL) malloc_error(); + s[max_line - 1] = '\0'; +/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ + if (ceil(n) == floor(n)) { + if (punch.high_precision == FALSE) { + sprintf(s, "%12g", (double) n); + } else { + sprintf(s, "%19g", (double) n); + } + } else { + if (punch.high_precision == FALSE) { + sprintf(s, "%12.4e", (double) n); + } else { + sprintf(s, "%20.12e", (double) n); + } + } + i = strlen(s) + 1; + s[i - 1] = '\0'; +/* p2c: basic.p, line 237: + * Note: Modification of string length may translate incorrectly [146] */ + strcpy(Result, s); + free_check_null(s); + return (Result); +/* } else { + if (punch.high_precision == FALSE) sprintf(s, "%30.10f", n); + else sprintf(s, "%30.12f", n); + i = strlen(s) + 1; + do { + i--; + } while (s[i - 1] == '0'); + if (s[i - 1] == '.') + i--; + s[i] = '\0'; + * p2c: basic.p, line 248: + * Note: Modification of string length may translate incorrectly [146] * + return strcpy(Result, strltrim(s)); + } */ +} + +#define toklength 20 + + +typedef long chset[9]; + + + + + +Static void parse(Char *inbuf, tokenrec **buf) +{ + long i, j, begin, len, m; + Char token[toklength + 1]; + tokenrec *t, *tptr; + varrec *v; + Char ch; + ENTRY item, *found_item; + char *ptr; + + tptr = NULL; + *buf = NULL; + i = 1; + do { + ch = ' '; + while (i <= (int) strlen(inbuf) && (ch == ' ' || ch == '\t')) { + ch = inbuf[i - 1]; + i++; + } + if (ch != ' ') { + t = (tokenrec *) PHRQ_malloc(sizeof(tokenrec)); + if ( t == NULL) malloc_error(); + if (tptr == NULL) + *buf = t; + else + tptr->next = t; + tptr = t; + t->next = NULL; + switch (ch) { + + case '"': + case '\'': + t->kind = tokstr; + j = 0; + len = strlen(inbuf); + begin = i; + while (i <= len && inbuf[i - 1] != ch) { + ++j; + ++i; + } + m = 256; + if (j + 1 > m) m = j + 1; + t->UU.sp = (char *) PHRQ_malloc(m); + if (t->UU.sp == NULL) malloc_error(); + strncpy(t->UU.sp, inbuf + begin - 1, j); + t->UU.sp[j] = '\0'; +/* p2c: basic.p, line 415: + * Note: Modification of string length may translate incorrectly [146] */ + i++; + break; + + case '+': + t->kind = tokplus; + break; + + case '-': + t->kind = tokminus; + break; + + case '*': + t->kind = toktimes; + break; + + case '/': + t->kind = tokdiv; + break; + + case '^': + t->kind = tokup; + break; + + case '(': + case '[': + t->kind = toklp; + break; + + case ')': + case ']': + t->kind = tokrp; + break; + + case ',': + t->kind = tokcomma; + break; + + case ';': + t->kind = toksemi; + break; + + case ':': + t->kind = tokcolon; + break; + + case '?': + t->kind = tokprint; + break; + + case '=': + t->kind = tokeq; + break; + + case '<': + if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '=') { + t->kind = tokle; + i++; + } else if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '>') { + t->kind = tokne; + i++; + } else + t->kind = toklt; + break; + + case '>': + if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '=') { + t->kind = tokge; + i++; + } else + t->kind = tokgt; + break; + + default: + if (isalpha((int) ch)) { + i--; + j = 0; + token[toklength] = '\0'; + while (i <= (int) strlen(inbuf) && + (inbuf[i - 1] == '$' || inbuf[i - 1] == '_' || + isalnum((int) inbuf[i - 1]))) { + if (j < toklength) { + j++; + token[j - 1] = inbuf[i - 1]; + } + i++; + } + token[j] = '\0'; +/* p2c: basic.p, line 309: + * Note: Modification of string length may translate incorrectly [146] */ +#define INT +#ifdef INT +/* + * Search hash list + */ + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(command_hash_table, item, FIND); + if (found_item != NULL) { + t->kind = ((struct key *) (found_item->data))->keycount; + if (t->kind == tokrem) { + m = strlen(inbuf) + 1; + if (m < 256) m = 256; + t->UU.sp = (char *) PHRQ_malloc(m); + if ( t->UU.sp == NULL) malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int)(strlen(inbuf) - i + 1), inbuf + i - 1); + i = strlen(inbuf) + 1; + } +#endif +#ifdef LONG + if (!strcmp(token, "and")) + t->kind = tokand; + else if (!strcmp(token, "or")) + t->kind = tokor; + else if (!strcmp(token, "xor")) + t->kind = tokxor; + else if (!strcmp(token, "not")) + t->kind = toknot; + else if (!strcmp(token, "mod")) + t->kind = tokmod; + else if (!strcmp(token, "sqr")) + t->kind = toksqr; + else if (!strcmp(token, "sqrt")) + t->kind = toksqrt; + else if (!strcmp(token, "sin")) + t->kind = toksin; + else if (!strcmp(token, "cos")) + t->kind = tokcos; + else if (!strcmp(token, "tan")) + t->kind = toktan; + else if (!strcmp(token, "arctan")) + t->kind = tokarctan; + else if (!strcmp(token, "log")) + t->kind = toklog; + else if (!strcmp(token, "exp")) + t->kind = tokexp; + else if (!strcmp(token, "abs")) + t->kind = tokabs; + else if (!strcmp(token, "sgn")) + t->kind = toksgn; + else if (!strcmp(token, "str$")) + t->kind = tokstr_; + else if (!strcmp(token, "val")) + t->kind = tokval; + else if (!strcmp(token, "chr$")) + t->kind = tokchr_; + else if (!strcmp(token, "asc")) + t->kind = tokasc; + else if (!strcmp(token, "len")) + t->kind = toklen; + else if (!strcmp(token, "mid$")) + t->kind = tokmid_; + else if (!strcmp(token, "peek")) + t->kind = tokpeek; + else if (!strcmp(token, "let")) + t->kind = toklet; + else if (!strcmp(token, "print")) + t->kind = tokprint; + else if (!strcmp(token, "punch")) + t->kind = tokpunch; +#ifdef PHREEQ98 + else if (!strcmp(token, "graph_x")) + t->kind = tokgraph_x; + else if (!strcmp(token, "graph_y")) + t->kind = tokgraph_y; + else if (!strcmp(token, "graph_sy")) + t->kind = tokgraph_sy; +#endif + else if (!strcmp(token, "input")) + t->kind = tokinput; + else if (!strcmp(token, "goto")) + t->kind = tokgoto; + else if (!strcmp(token, "go to")) + t->kind = tokgoto; + else if (!strcmp(token, "if")) + t->kind = tokif; + else if (!strcmp(token, "end")) + t->kind = tokend; + else if (!strcmp(token, "stop")) + t->kind = tokstop; + else if (!strcmp(token, "for")) + t->kind = tokfor; + else if (!strcmp(token, "next")) + t->kind = toknext; + else if (!strcmp(token, "while")) + t->kind = tokwhile; + else if (!strcmp(token, "wend")) + t->kind = tokwend; + else if (!strcmp(token, "gosub")) + t->kind = tokgosub; + else if (!strcmp(token, "return")) + t->kind = tokreturn; + else if (!strcmp(token, "read")) + t->kind = tokread; + else if (!strcmp(token, "data")) + t->kind = tokdata; + else if (!strcmp(token, "restore")) + t->kind = tokrestore; + else if (!strcmp(token, "gotoxy")) + t->kind = tokgotoxy; + else if (!strcmp(token, "on")) + t->kind = tokon; + else if (!strcmp(token, "dim")) + t->kind = tokdim; + else if (!strcmp(token, "poke")) + t->kind = tokpoke; + else if (!strcmp(token, "list")) + t->kind = toklist; + else if (!strcmp(token, "run")) + t->kind = tokrun; + else if (!strcmp(token, "new")) + t->kind = toknew; + else if (!strcmp(token, "load")) + t->kind = tokload; + else if (!strcmp(token, "merge")) + t->kind = tokmerge; + else if (!strcmp(token, "save")) + t->kind = toksave; + else if (!strcmp(token, "bye")) + t->kind = tokbye; + else if (!strcmp(token, "quit")) + t->kind = tokbye; + else if (!strcmp(token, "del")) + t->kind = tokdel; + else if (!strcmp(token, "renum")) + t->kind = tokrenum; + else if (!strcmp(token, "then")) + t->kind = tokthen; + else if (!strcmp(token, "else")) + t->kind = tokelse; + else if (!strcmp(token, "to")) + t->kind = tokto; + else if (!strcmp(token, "step")) + t->kind = tokstep; +/* + * dlp: added functions + */ + else if (!strcmp(token, "tc")) + t->kind = toktc; + else if (!strcmp(token, "tk")) + t->kind = toktk; + else if (!strcmp(token, "time")) + t->kind = toktime; + else if (!strcmp(token, "sim_time")) + t->kind = toksim_time; + else if (!strcmp(token, "total_time")) + t->kind = toktotal_time; + else if (!strcmp(token, "m0")) + t->kind = tokm0; + else if (!strcmp(token, "m")) + t->kind = tokm; + else if (!strcmp(token, "parm")) + t->kind = tokparm; + else if (!strcmp(token, "act")) + t->kind = tokact; + else if (!strcmp(token, "edl")) + t->kind = tokedl; + else if (!strcmp(token, "surf")) + t->kind = toksurf; + else if (!strcmp(token, "equi")) + t->kind = tokequi; + else if (!strcmp(token, "kin")) + t->kind = tokkin; + else if (!strcmp(token, "gas")) + t->kind = tokgas; + else if (!strcmp(token, "s_s")) + t->kind = toks_s; + else if (!strcmp(token, "misc1")) + t->kind = tokmisc1; + else if (!strcmp(token, "misc2")) + t->kind = tokmisc2; + else if (!strcmp(token, "mu")) + t->kind = tokmu; + else if (!strcmp(token, "alk")) + t->kind = tokalk; + else if (!strcmp(token, "lk_species")) + t->kind = toklk_species; + else if (!strcmp(token, "lk_named")) + t->kind = toklk_named; + else if (!strcmp(token, "lk_phase")) + t->kind = toklk_phase; + else if (!strcmp(token, "sum_species")) + t->kind = toksum_species; + else if (!strcmp(token, "sum_gas")) + t->kind = toksum_gas; + else if (!strcmp(token, "sum_s_s")) + t->kind = toksum_s_s; + else if (!strcmp(token, "calc_value")) + t->kind = tokcalc_value; + else if (!strcmp(token, "description")) + t->kind = tokdescription; + else if (!strcmp(token, "sys")) + t->kind = toksys; + else if (!strcmp(token, "instr")) + t->kind = tokinstr; + else if (!strcmp(token, "ltrim")) + t->kind = tokltrim; + else if (!strcmp(token, "rtrim")) + t->kind = tokrtrim; + else if (!strcmp(token, "trim")) + t->kind = toktrim; + else if (!strcmp(token, "pad")) + t->kind = tokpad; + else if (!strcmp(token, "rxn")) + t->kind = tokrxn; + else if (!strcmp(token, "dist")) + t->kind = tokdist; + else if (!strcmp(token, "mol")) + t->kind = tokmol; + else if (!strcmp(token, "la")) + t->kind = tokla; + else if (!strcmp(token, "lm")) + t->kind = toklm; + else if (!strcmp(token, "sr")) + t->kind = toksr; + else if (!strcmp(token, "step_no")) + t->kind = tokstep_no; + else if (!strcmp(token, "cell_no")) + t->kind = tokcell_no; + else if (!strcmp(token, "sim_no")) + t->kind = toksim_no; + else if (!strcmp(token, "si")) + t->kind = toksi; + else if (!strcmp(token, "tot")) + t->kind = toktot; + else if (!strcmp(token, "log10")) + t->kind = toklog10; + else if (!strcmp(token, "put")) + t->kind = tokput; + else if (!strcmp(token, "get")) + t->kind = tokget; + else if (!strcmp(token, "exists")) + t->kind = tokexists; + else if (!strcmp(token, "charge_balance")) + t->kind = tokcharge_balance; + else if (!strcmp(token, "percent_error")) + t->kind = tokpercent_error; + else if (!strcmp(token, "rem")) { + t->kind = tokrem; + m = strlen(inbuf) + 1; + if (m < 256) m = 256; + t->UU.sp = (char *) PHRQ_malloc(m)); + if ( t->UU.sp == NULL) malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int)(strlen(inbuf) - i + 1), inbuf + i - 1); + i = strlen(inbuf) + 1; +#endif + } else { + t->kind = tokvar; + v = varbase; + while (v != NULL && strcmp(v->name, token)) + v = v->next; + if (v == NULL) { + v = (varrec *) PHRQ_malloc(sizeof(varrec)); + if ( v == NULL) malloc_error(); + v->UU.U0.arr = NULL; + v->next = varbase; + varbase = v; + strcpy(v->name, token); + v->numdims = 0; + if (token[strlen(token) - 1] == '$') { + v->stringvar = true; + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } else { + v->stringvar = false; + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } + } + t->UU.vp = v; + } + } else if (isdigit((int) ch) || ch == '.') { + t->kind = toknum; + i--; + t->UU.num = strtod(&inbuf[i-1], &ptr); + if (&inbuf[i-1] == ptr) { + /* + Note: the following causes an infinite loop: + X = ..9 + */ + t->kind = toksnerr; + t->UU.snch = ch; + i++; + break; + } + i += (int) (ptr - &inbuf[i-1]); + } else { + t->kind = toksnerr; + t->UU.snch = ch; + } + break; + } + } + } while (i <= (int) strlen(inbuf)); +} + +#undef toklength + + + +Static void listtokens(FILE *f, tokenrec *buf) +{ + boolean ltr; + Char STR1[256]; + char *string; + ltr = false; + while (buf != NULL) { + if ((buf->kind >= (long)toknot && buf->kind <= (long)tokrenum) || + buf->kind == (long)toknum || buf->kind == (long)tokvar || + buf->kind >= (long)toktc) { + if (ltr) + /*putc(' ', f);*/ + output_msg(OUTPUT_BASIC, " "); + ltr = (boolean) (buf->kind != toknot); + } else + ltr = false; + switch (buf->kind) { + + case tokvar: + /*fputs(buf->UU.vp->name, f);*/ + output_msg(OUTPUT_BASIC, "%s", buf->UU.vp->name); + break; + + case toknum: + /*fputs(numtostr(STR1, buf->UU.num), f);*/ + string = numtostr(STR1, buf->UU.num); + string_trim(string); + output_msg(OUTPUT_BASIC, "%s", string); + break; + + case tokstr: + output_msg(OUTPUT_BASIC, "\"%s\"", buf->UU.sp); + break; + + case toksnerr: + output_msg(OUTPUT_BASIC, "{%c}", buf->UU.snch); + break; + + case tokplus: + /*putc('+', f);*/ + output_msg(OUTPUT_BASIC, "+"); + break; + + case tokminus: + /*putc('-', f);*/ + output_msg(OUTPUT_BASIC, "-"); + break; + + case toktimes: + /*putc('*', f);*/ + output_msg(OUTPUT_BASIC, "*"); + break; + + case tokdiv: + /*putc('/', f);*/ + output_msg(OUTPUT_BASIC, "/"); + break; + + case tokup: + /*putc('^', f);*/ + output_msg(OUTPUT_BASIC, "^"); + break; + + case toklp: + /*putc('(', f);*/ + output_msg(OUTPUT_BASIC, "("); + break; + + case tokrp: + /*putc(')', f);*/ + output_msg(OUTPUT_BASIC, ")"); + break; + + case tokcomma: + /*putc(',', f);*/ + output_msg(OUTPUT_BASIC, ","); + break; + + case toksemi: + /*putc(';', f);*/ + output_msg(OUTPUT_BASIC, ";"); + break; + + case tokcolon: + output_msg(OUTPUT_BASIC, " : "); + break; + + case tokeq: + output_msg(OUTPUT_BASIC, " = "); + break; + + case toklt: + output_msg(OUTPUT_BASIC, " < "); + break; + + case tokgt: + output_msg(OUTPUT_BASIC, " > "); + break; + + case tokle: + output_msg(OUTPUT_BASIC, " <= "); + break; + + case tokge: + output_msg(OUTPUT_BASIC, " >= "); + break; + + case tokne: + output_msg(OUTPUT_BASIC, " <> "); + break; + + case tokand: + output_msg(OUTPUT_BASIC, " AND "); + break; + + case tokor: + output_msg(OUTPUT_BASIC, " OR "); + break; + + case tokxor: + output_msg(OUTPUT_BASIC, " XOR "); + break; + + case tokmod: + output_msg(OUTPUT_BASIC, " MOD "); + break; + + case toknot: + output_msg(OUTPUT_BASIC, "NOT "); + break; + + case toksqr: + output_msg(OUTPUT_BASIC, "SQR"); + break; + + case toksqrt: + output_msg(OUTPUT_BASIC, "SQRT"); + break; + + case toksin: + output_msg(OUTPUT_BASIC, "SIN"); + break; + + case tokcos: + output_msg(OUTPUT_BASIC, "COS"); + break; + + case toktan: + output_msg(OUTPUT_BASIC, "TAN"); + break; + + case tokarctan: + output_msg(OUTPUT_BASIC, "ARCTAN"); + break; + + case toklog: + output_msg(OUTPUT_BASIC, "LOG"); + break; + + case tokexp: + output_msg(OUTPUT_BASIC, "EXP"); + break; + + case tokabs: + output_msg(OUTPUT_BASIC, "ABS"); + break; + + case toksgn: + output_msg(OUTPUT_BASIC, "SGN"); + break; + + case tokstr_: + output_msg(OUTPUT_BASIC, "STR$"); + break; + + case tokval: + output_msg(OUTPUT_BASIC, "VAL"); + break; + + case tokchr_: + output_msg(OUTPUT_BASIC, "CHR$"); + break; + + case tokasc: + output_msg(OUTPUT_BASIC, "ASC"); + break; + + case toklen: + output_msg(OUTPUT_BASIC, "LEN"); + break; + + case tokmid_: + output_msg(OUTPUT_BASIC, "MID$"); + break; + + case tokpeek: + output_msg(OUTPUT_BASIC, "PEEK"); + break; + + case tokrem: + output_msg(OUTPUT_BASIC, "REM%s", buf->UU.sp); + break; + + case toklet: + output_msg(OUTPUT_BASIC, "LET"); + break; + + case tokprint: + output_msg(OUTPUT_BASIC, "PRINT"); + break; + + case tokinput: + output_msg(OUTPUT_BASIC, "INPUT"); + break; + + case tokgoto: + output_msg(OUTPUT_BASIC, "GOTO"); + break; + + case tokif: + output_msg(OUTPUT_BASIC, "IF"); + break; + + case tokend: + output_msg(OUTPUT_BASIC, "END"); + break; + + case tokstop: + output_msg(OUTPUT_BASIC, "STOP"); + break; + + case tokfor: + output_msg(OUTPUT_BASIC, "FOR"); + break; + + case toknext: + output_msg(OUTPUT_BASIC, "NEXT"); + break; + + case tokwhile: + output_msg(OUTPUT_BASIC, "WHILE"); + break; + + case tokwend: + output_msg(OUTPUT_BASIC, "WEND"); + break; + + case tokgosub: + output_msg(OUTPUT_BASIC, "GOSUB"); + break; + + case tokreturn: + output_msg(OUTPUT_BASIC, "RETURN"); + break; + + case tokread: + output_msg(OUTPUT_BASIC, "READ"); + break; + + case tokdata: + output_msg(OUTPUT_BASIC, "DATA"); + break; + + case tokrestore: + output_msg(OUTPUT_BASIC, "RESTORE"); + break; + + case tokgotoxy: + output_msg(OUTPUT_BASIC, "GOTOXY"); + break; + + case tokon: + output_msg(OUTPUT_BASIC, "ON"); + break; + + case tokdim: + output_msg(OUTPUT_BASIC, "DIM"); + break; + + case tokpoke: + output_msg(OUTPUT_BASIC, "POKE"); + break; + + case toklist: + output_msg(OUTPUT_BASIC, "LIST"); + break; + + case tokrun: + output_msg(OUTPUT_BASIC, "RUN"); + break; + + case toknew: + output_msg(OUTPUT_BASIC, "NEW"); + break; + + case tokload: + output_msg(OUTPUT_BASIC, "LOAD"); + break; + + case tokmerge: + output_msg(OUTPUT_BASIC, "MERGE"); + break; + + case toksave: + output_msg(OUTPUT_BASIC, "SAVE"); + break; + + case tokbye: + output_msg(OUTPUT_BASIC, "BYE"); + break; + + case tokdel: + output_msg(OUTPUT_BASIC, "DEL"); + break; + + case tokrenum: + output_msg(OUTPUT_BASIC, "RENUM"); + break; + + case tokthen: + output_msg(OUTPUT_BASIC, " THEN "); + break; + + case tokelse: + output_msg(OUTPUT_BASIC, " ELSE "); + break; + + case tokto: + output_msg(OUTPUT_BASIC, " TO "); + break; + + case tokstep: + output_msg(OUTPUT_BASIC, " STEP "); + break; + + case toktc: + output_msg(OUTPUT_BASIC, "TC"); + break; + + case tokm0: + output_msg(OUTPUT_BASIC, "M0"); + break; + + case tokm: + output_msg(OUTPUT_BASIC, "M"); + break; + + case tokparm: + output_msg(OUTPUT_BASIC, "PARM"); + break; + + case tokact: + output_msg(OUTPUT_BASIC, "ACT"); + break; + + case tokmol: + output_msg(OUTPUT_BASIC, "MOL"); + break; + + case tokla: + output_msg(OUTPUT_BASIC, "LA"); + break; + + case toklm: + output_msg(OUTPUT_BASIC, "LM"); + break; + + case toksr: + output_msg(OUTPUT_BASIC, "SR"); + break; + + case toksi: + output_msg(OUTPUT_BASIC, "SI"); + break; + + case toktot: + output_msg(OUTPUT_BASIC, "TOT"); + break; + + case toktk: + output_msg(OUTPUT_BASIC, "TK"); + break; + + case toktime: + output_msg(OUTPUT_BASIC, "TIME"); + break; + + case toklog10: + output_msg(OUTPUT_BASIC, "LOG10"); + break; + + case toksim_time: + output_msg(OUTPUT_BASIC, "SIM_TIME"); + break; + + case tokequi: + output_msg(OUTPUT_BASIC, "EQUI"); + break; + + case tokgas: + output_msg(OUTPUT_BASIC, "GAS"); + break; + + case tokpunch: + output_msg(OUTPUT_BASIC, "PUNCH"); + break; + + case tokkin: + output_msg(OUTPUT_BASIC, "KIN"); + break; + + case toks_s: + output_msg(OUTPUT_BASIC, "S_S"); + break; + + case tokmu: + output_msg(OUTPUT_BASIC, "MU"); + break; + + case tokalk: + output_msg(OUTPUT_BASIC, "ALK"); + break; + + case toklk_species: + output_msg(OUTPUT_BASIC, "LK_SPECIES"); + break; + + case toklk_named: + output_msg(OUTPUT_BASIC, "LK_NAMED"); + break; + + case toklk_phase: + output_msg(OUTPUT_BASIC, "LK_PHASE"); + break; + + case toksum_species: + output_msg(OUTPUT_BASIC, "SUM_SPECIES"); + break; + + case toksum_gas: + output_msg(OUTPUT_BASIC, "SUM_GAS"); + break; + + case toksum_s_s: + output_msg(OUTPUT_BASIC, "SUM_s_s"); + break; + + case tokcalc_value: + output_msg(OUTPUT_BASIC, "CALC_VALUE"); + break; + + case tokdescription: + output_msg(OUTPUT_BASIC, "DESCRIPTION"); + break; + + case toksys: + output_msg(OUTPUT_BASIC, "SYS"); + break; + + case tokinstr: + output_msg(OUTPUT_BASIC, "INSTR"); + break; + + case tokltrim: + output_msg(OUTPUT_BASIC, "LTRIM"); + break; + + case tokrtrim: + output_msg(OUTPUT_BASIC, "RTRIM"); + break; + + case toktrim: + output_msg(OUTPUT_BASIC, "TRIM"); + break; + + case tokpad: + output_msg(OUTPUT_BASIC, "PAD"); + break; + + case tokrxn: + output_msg(OUTPUT_BASIC, "RXN"); + break; + + case tokdist: + output_msg(OUTPUT_BASIC, "DIST"); + break; + + case tokmisc1: + output_msg(OUTPUT_BASIC, "MISC1"); + break; + + case tokmisc2: + output_msg(OUTPUT_BASIC, "MISC2"); + break; + + case tokedl: + output_msg(OUTPUT_BASIC, "EDL"); + break; + + case toksurf: + output_msg(OUTPUT_BASIC, "SURF"); + break; + + case tokstep_no: + output_msg(OUTPUT_BASIC, "STEP_NO"); + break; + + case toksim_no: + output_msg(OUTPUT_BASIC, "SIM_NO"); + break; + + case toktotal_time: + output_msg(OUTPUT_BASIC, "TOTAL_TIME"); + break; + + case tokput: + output_msg(OUTPUT_BASIC, "PUT"); + break; + + case tokget: + output_msg(OUTPUT_BASIC, "GET"); + break; + + case tokcharge_balance: + output_msg(OUTPUT_BASIC, "CHARGE_BALANCE"); + break; + + case tokpercent_error: + output_msg(OUTPUT_BASIC, "PERCENT_ERROR"); + break; + +#ifdef PHREEQ98 + case tokgraph_x: + output_msg(OUTPUT_BASIC, "GRAPH_X"); + break; + + case tokgraph_y: + output_msg(OUTPUT_BASIC, "GRAPH_Y"); + break; + + case tokgraph_sy: + output_msg(OUTPUT_BASIC, "GRAPH_SY"); + break; +#endif + + case tokcell_no: + output_msg(OUTPUT_BASIC, "CELL_NO"); + break; + + case tokexists: + output_msg(OUTPUT_BASIC, "EXISTS"); + break; + + } + buf = buf->next; + } +} + + + +Static void disposetokens(tokenrec **tok) +{ + tokenrec *tok1; + + while (*tok != NULL) { + tok1 = (*tok)->next; + if ((*tok)->kind == (long)tokrem || (*tok)->kind == (long)tokstr) { + (*tok)->UU.sp = (char*) free_check_null((*tok)->UU.sp); + } + *tok = (struct tokenrec *)free_check_null(*tok); + *tok = tok1; + } +} + + + +Static void parseinput(tokenrec **buf) +{ + linerec *l, *l0, *l1; + + while (replace("\t"," ",inbuf)); + while (replace("\r"," ",inbuf)); + string_trim(inbuf); + curline = 0; + while (*inbuf != '\0' && isdigit((int) inbuf[0])) { + curline = curline * 10 + inbuf[0] - 48; +#ifdef SKIP + strcpy(inbuf, inbuf + 1); +#endif + memmove(inbuf, inbuf + 1, strlen(inbuf)); + } + parse(inbuf, buf); + if (curline == 0) + return; + l = linebase; + l0 = NULL; + while (l != NULL && l->num < curline) { + l0 = l; + l = l->next; + } + if (l != NULL && l->num == curline) { + l1 = l; + l = l->next; + if (l0 == NULL) + linebase = l; + else + l0->next = l; + disposetokens(&l1->txt); + free(l1); + } + if (*buf != NULL) { + l1 = (linerec *) PHRQ_malloc(sizeof(linerec)); + if ( l1 == NULL) malloc_error(); + l1->next = l; + if (l0 == NULL) + linebase = l1; + else + l0->next = l1; + l1->num = curline; + l1->txt = *buf; + } + clearloops(); + restoredata(); +} + +Static void errormsg(Char *s) +{ +#ifdef SKIP + printf("\007%s", s); +#endif + error_msg(s, CONTINUE); + _Escape(42); +} + + +Static void snerr(void) +{ + errormsg("Syntax error"); +} + + +Static void tmerr(void) +{ + errormsg("Type mismatch error"); +} + + +Static void badsubscr(void) +{ + errormsg("Bad subscript"); +} + + +/* Local variables for exec: */ +struct LOC_exec { + boolean gotoflag, elseflag; + tokenrec *t; +} ; + +Local valrec factor(struct LOC_exec *LINK); +Local valrec expr(struct LOC_exec *LINK); +Local Char *stringfactor(Char *Result, struct LOC_exec *LINK); + +Local LDBLE realfactor(struct LOC_exec *LINK) +{ + valrec n; + + n = factor(LINK); + if (n.stringval) + tmerr(); + return (n.UU.val); +} + +Local Char *strfactor(struct LOC_exec *LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(); + return (n.UU.sval); +} + +Local Char *stringfactor(Char *Result, struct LOC_exec *LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(); + strcpy(Result, n.UU.sval); + free(n.UU.sval); + return Result; +} + +Local long intfactor(struct LOC_exec *LINK) +{ + return ((long)floor(realfactor(LINK) + 0.5)); +} + +Local LDBLE realexpr(struct LOC_exec *LINK) +{ + valrec n; + + n = expr(LINK); + if (n.stringval) + tmerr(); + return (n.UU.val); +} + +Local Char *strexpr(struct LOC_exec *LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(); + return (n.UU.sval); +} + +Local Char *stringexpr(Char *Result, struct LOC_exec *LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(); + strcpy(Result, n.UU.sval); + free(n.UU.sval); + return Result; +} + +Local long intexpr(struct LOC_exec *LINK) +{ + return ((long)floor(realexpr(LINK) + 0.5)); +} + + +Local void require(int k, struct LOC_exec *LINK) +{ + if (LINK->t == NULL || LINK->t->kind != k) + snerr(); + LINK->t = LINK->t->next; +} + + +Local void skipparen(struct LOC_exec *LINK) +{ + do { + if (LINK->t == NULL) + snerr(); + if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) + goto _L1; + if (LINK->t->kind == toklp) { + LINK->t = LINK->t->next; + skipparen(LINK); + } + LINK->t = LINK->t->next; + } while (true); +_L1: ; +} + + +Local varrec *findvar(struct LOC_exec *LINK) +{ + varrec *v; + long i, j, k; + tokenrec *tok; + long FORLIM; + + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != toklp) { + if (v->numdims != 0) + badsubscr(); + return v; + } + if (v->numdims == 0) { + tok = LINK->t; + i = 0; + j = 1; + do { + if (i >= maxdims) + badsubscr(); + LINK->t = LINK->t->next; + skipparen(LINK); + j *= 11; + i++; + v->dims[i - 1] = 11; + } while (LINK->t->kind != tokrp); + v->numdims = (char) i; + if (v->stringvar) { + v->UU.U1.sarr = (Char **) PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) malloc_error(); + for (k = 0; k < j; k++) + v->UU.U1.sarr[k] = NULL; + } else { + v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); + if ( v->UU.U0.arr == NULL) malloc_error(); + for (k = 0; k < j; k++) + v->UU.U0.arr[k] = 0.0; + } + LINK->t = tok; + } + k = 0; + LINK->t = LINK->t->next; + FORLIM = v->numdims; + for (i = 1; i <= FORLIM; i++) { + j = intexpr(LINK); + if ((unsigned long)j >= (unsigned long) v->dims[i - 1]) + badsubscr(); + k = k * v->dims[i - 1] + j; + if (i < v->numdims) + require(tokcomma, LINK); + } + require(tokrp, LINK); + if (v->stringvar) + v->UU.U1.sval = &v->UU.U1.sarr[k]; + else + v->UU.U0.val = &v->UU.U0.arr[k]; + return v; +} + + +#ifdef SKIP +Local long inot(long i, struct LOC_exec *LINK) +{ + return (-i - 1); +} + +Local long ixor(long a, long b, struct LOC_exec *LINK) +{ + return ((a & (~b)) | ((~a) & b)); +} +#endif + +Local valrec factor(struct LOC_exec *LINK) +{ + varrec *v; + tokenrec *facttok; + valrec n; + long i, j, m; + tokenrec *tok, *tok1; + Char *s; + LDBLE dummy; + int i_rate; + union { + long i; + Char *c; + } trick; + struct save_values s_v, *s_v_ptr; + int k; + LDBLE TEMP; + Char *STR1, *STR2; + char *elt_name, *surface_name, *mytemplate, *name; + struct varrec *count_varrec=NULL, *names_varrec=NULL, *types_varrec=NULL, *moles_varrec=NULL; + char **names_arg, **types_arg; + LDBLE *moles_arg; + int arg_num; + LDBLE count_species; + char *ptr, *string1, *string2; + + STR1 = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (STR1 == NULL) malloc_error(); + STR2 = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (STR2 == NULL) malloc_error(); + + if (LINK->t == NULL) + snerr(); + facttok = LINK->t; + LINK->t = LINK->t->next; + n.stringval = false; + s_v.count_subscripts = 0; + s_v.subscripts = (int*) PHRQ_malloc(sizeof(int)); + switch (facttok->kind) { + + case toknum: + n.UU.val = facttok->UU.num; + break; + + case tokstr: + n.stringval = true; + m = strlen(facttok->UU.sp) + 1; + if (m < 256) m = 256; + n.UU.sval = (char *) PHRQ_malloc(m); + if (n.UU.sval == NULL) malloc_error(); + strcpy(n.UU.sval, facttok->UU.sp); + break; + + case tokvar: + LINK->t = facttok; + v = findvar(LINK); + n.stringval = v->stringvar; + if (n.stringval) { + if (*v->UU.U1.sval != NULL) { + m = strlen(*v->UU.U1.sval) + 1; + if (m < 256) m = 256; + } else { + m = 256; + } + n.UU.sval = (char *) PHRQ_malloc(m); + if (n.UU.sval == NULL) malloc_error(); + if (*v->UU.U1.sval != NULL) { + strcpy(n.UU.sval, *v->UU.U1.sval); + } + + } else + n.UU.val = *v->UU.U0.val; + break; + + case toklp: + n = expr(LINK); + require(tokrp, LINK); + break; + + case tokminus: + n.UU.val = -realfactor(LINK); + break; + + case tokplus: + n.UU.val = realfactor(LINK); + break; + + case toknot: + n.UU.val = ~intfactor(LINK); + break; + + case toksqr: + TEMP = realfactor(LINK); + n.UU.val = TEMP * TEMP; + break; + + case toksqrt: + n.UU.val = sqrt(realfactor(LINK)); + break; + + case toktc: + n.UU.val = tc_x; + break; + + case toktk: + n.UU.val = tc_x+273.16; + break; + + case toktime: + n.UU.val = rate_time; + break; + + case toksim_time: + if (use.kinetics_in == FALSE) { + if (state == PHAST) { + n.UU.val = rate_sim_time; + } else if (state == TRANSPORT) { + n.UU.val = transport_step * timest; + } else if (state == ADVECTION) { + if (advection_kin_time_defined == TRUE) { + n.UU.val = advection_step * advection_kin_time; + } else { + n.UU.val = advection_step; + } + } else { + n.UU.val = 0; + } + } else { + n.UU.val = rate_sim_time; + } + break; + + case toktotal_time: + if (use.kinetics_in == FALSE) { + if (state == PHAST) { + n.UU.val = rate_sim_time_end; + } else if (state == TRANSPORT) { + n.UU.val = initial_total_time + transport_step * timest; + } else if (state == ADVECTION) { + n.UU.val = initial_total_time + advection_step * advection_kin_time; + } else { + n.UU.val = 0; + } + } else { + n.UU.val = initial_total_time + rate_sim_time; + } + break; + + case tokm0: + n.UU.val = rate_m0; + break; + + case tokm: + n.UU.val = rate_m; + break; + + case tokparm: + i_rate = intfactor(LINK); + if ( i_rate > count_rate_p) { + errormsg("Parameter subscript out of range."); + } + n.UU.val = rate_p[i_rate - 1]; + break; + + case tokact: + n.UU.val = activity(stringfactor(STR1, LINK)); + break; + + case tokedl: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } else { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = diff_layer_total(elt_name, surface_name); + break; + + case toksurf: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } else { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = surf_total(elt_name, surface_name); + break; + + case tokequi: + n.UU.val = equi_phase(stringfactor(STR1, LINK)); + break; + + case tokkin: + n.UU.val = kinetics_moles(stringfactor(STR1, LINK)); + break; + + case tokgas: + n.UU.val = find_gas_comp(stringfactor(STR1, LINK)); + break; + + case toks_s: + n.UU.val = find_s_s_comp(stringfactor(STR1, LINK)); + break; + + case tokmisc1: + n.UU.val = find_misc1(stringfactor(STR1, LINK)); + break; + + case tokmisc2: + n.UU.val = find_misc2(stringfactor(STR1, LINK)); + break; + + case tokmu: + n.UU.val = mu_x; + break; + + case tokalk: + n.UU.val = total_alkalinity/mass_water_aq_x; + break; + + case toklk_species: + n.UU.val = calc_logk_s(stringfactor(STR1, LINK)); + break; + + case toklk_named: + n.UU.val = calc_logk_n(stringfactor(STR1, LINK)); + break; + + case toklk_phase: + n.UU.val = calc_logk_p(stringfactor(STR1, LINK)); + break; + + case toksum_species: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } else { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = sum_match_species(mytemplate, elt_name); + break; + + case toksum_gas: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } else { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = sum_match_gases(mytemplate, elt_name); + break; + + case toksum_s_s: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } else { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = sum_match_s_s(mytemplate, elt_name); + break; + + case tokcalc_value: + require(toklp, LINK); + name = stringfactor(STR1, LINK); + require(tokrp, LINK); + n.UU.val = get_calculate_value(name); + break; + + case tokdescription: + n.stringval = true; + n.UU.sval = string_duplicate(use.solution_ptr->description); + while (replace("\t"," ",n.UU.sval)); + break; + + case tokinstr: + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + string2 = stringfactor(STR2, LINK); + require(tokrp, LINK); + ptr = strstr(string1, string2); + if (ptr == NULL) { + n.UU.val = 0; + } else { + n.UU.val = ((LDBLE) (ptr - string1)) + 1; + } + break; + + case tokltrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + string_trim_left(string1); + n.UU.sval = string_duplicate(string1); + break; + + case tokrtrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + string_trim_right(string1); + n.UU.sval = string_duplicate(string1); + break; + + case toktrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + string_trim(string1); + n.UU.sval = string_duplicate(string1); + break; + + case tokpad: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + require(tokrp, LINK); + n.UU.sval = string_pad(string1, i); + break; + + case toksys: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (count_varrec->stringvar != 0) snerr(); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (names_varrec->stringvar != 1) snerr(); + + /* return number of types of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + types_varrec = LINK->t->UU.vp; + if (types_varrec->stringvar != 1) snerr(); + + /* return number of moles of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (moles_varrec->stringvar != 0) snerr(); + LINK->t = LINK->t->next; + arg_num = 4; + } else { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) { + free_dim_stringvar(names_varrec); + free_dim_stringvar(types_varrec); + free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + /* + n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); + */ + n.UU.val = system_total(elt_name, &count_species, &(names_arg), &(types_arg), &(moles_arg)); + + /* + * fill in varrec structure + */ + if (arg_num > 1) { + *count_varrec->UU.U0.val = count_species; + names_varrec->UU.U1.sarr = names_arg; + types_varrec->UU.U1.sarr = types_arg; + moles_varrec->UU.U0.arr = moles_arg; + + for (i = 0; i < maxdims; i++) { + names_varrec->dims[i] = 0; + types_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + types_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + names_varrec->numdims = 1; + types_varrec->numdims = 1; + moles_varrec->numdims = 1; + } else { + for (i = 0; i < count_species + 1; i++) { + free_check_null(names_arg[i]); + free_check_null(types_arg[i]); + } + free_check_null(names_arg); + free_check_null(types_arg); + free_check_null(moles_arg); + } + break; + case tokrxn: + if (state == REACTION) { + n.UU.val = step_x; + } else { + n.UU.val = 0.0; + } + break; + + case tokdist: + if (state == PHAST) { + n.UU.val = 0; + } else if (state == TRANSPORT) { + n.UU.val = cell_data[cell-1].mid_cell_x; + } else if (state == ADVECTION) { + n.UU.val = (LDBLE) use.n_solution_user; + } else { + n.UU.val = 0; + } + break; + + case tokmol: + n.UU.val = molality(stringfactor(STR1, LINK)); + break; + + case tokla: + n.UU.val = log_activity(stringfactor(STR1, LINK)); + break; + + case toklm: + n.UU.val = log_molality(stringfactor(STR1, LINK)); + break; + + case toksr: + n.UU.val = saturation_ratio(stringfactor(STR1, LINK)); + break; + + case tokstep_no: + if (state == PHAST) { + n.UU.val = 0; + } else if (state == TRANSPORT) { + n.UU.val = transport_step; + } else if (state == ADVECTION) { + n.UU.val = advection_step; + } else if (state == REACTION) { + n.UU.val = reaction_step; + } else { + n.UU.val = 0; + } + break; + + case tokcell_no: + if (state == TRANSPORT) { + n.UU.val = cell_no; + } else if (state == PHAST) { + n.UU.val = cell_no; + } else if (state == ADVECTION) { + n.UU.val = cell_no; + } else if (state < REACTION) { + n.UU.val = use.solution_ptr->n_user; + } else { + if (use.mix_in == TRUE) { + n.UU.val = use.n_mix_user; + } else { + n.UU.val = use.n_solution_user; + } + } + break; + + case toksim_no: + n.UU.val = simulation; + break; + + case tokget: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) { + i = intexpr(LINK); + s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); + if (s_v.subscripts == NULL) malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) { + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + j = intexpr(LINK); + s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); + if (s_v.subscripts == NULL) malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } else { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) { + n.UU.val = 0; + } else { + n.UU.val = s_v_ptr->value; + } + break; + + case tokexists: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) { + i = intexpr(LINK); + s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); + if (s_v.subscripts == NULL) malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) { + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + j = intexpr(LINK); + s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); + if (s_v.subscripts == NULL) malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } else { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) { + n.UU.val = 0; + } else { + n.UU.val = 1; + } + break; + + case tokcharge_balance: + n.UU.val = cb_x; + break; + + case tokpercent_error: + n.UU.val = 100*cb_x/total_ions_x; + break; + + case toksi: + saturation_index(stringfactor(STR1, LINK), &dummy, &n.UU.val); + break; + + case toktot: + n.UU.val = total(stringfactor(STR1, LINK)); + break; + + case toklog10: + n.UU.val = log10(realfactor(LINK)); + break; + + case toksin: + n.UU.val = sin(realfactor(LINK)); + break; + + case tokcos: + n.UU.val = cos(realfactor(LINK)); + break; + + case toktan: + n.UU.val = realfactor(LINK); + n.UU.val = sin(n.UU.val) / cos(n.UU.val); + break; + + case tokarctan: + n.UU.val = atan(realfactor(LINK)); + break; + + case toklog: + n.UU.val = log(realfactor(LINK)); + break; + + case tokexp: + n.UU.val = exp(realfactor(LINK)); + break; + + case tokabs: + n.UU.val = fabs(realfactor(LINK)); + break; + + case toksgn: + n.UU.val = realfactor(LINK); + n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); + break; + + case tokstr_: + n.stringval = true; + n.UU.sval = (char *) PHRQ_malloc(256); + if (n.UU.sval == NULL) malloc_error(); + numtostr(n.UU.sval, realfactor(LINK)); + break; + + case tokval: + s = strfactor(LINK); + tok1 = LINK->t; + parse(s, &LINK->t); + tok = LINK->t; + if (tok == NULL) + n.UU.val = 0.0; + else + n = expr(LINK); + disposetokens(&tok); + LINK->t = tok1; + free(s); + break; + + case tokchr_: + n.stringval = true; + n.UU.sval = (char *) PHRQ_malloc(256); + if (n.UU.sval == NULL) malloc_error(); + strcpy(n.UU.sval, " "); + n.UU.sval[0] = (Char)intfactor(LINK); + break; + + case tokasc: + s = strfactor(LINK); + if (*s == '\0') + n.UU.val = 0.0; + else + n.UU.val = s[0]; + free(s); + break; + + case tokmid_: + n.stringval = true; + require(toklp, LINK); + n.UU.sval = strexpr(LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + if (i < 1) + i = 1; + /*j = 255;*/ + j = strlen(n.UU.sval); + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + j = intexpr(LINK); + } + if (j > (int) strlen(n.UU.sval) - i + 1) + j = strlen(n.UU.sval) - i + 1; + if (i > (int) strlen(n.UU.sval)) + *n.UU.sval = '\0'; + else { + STR1 = (char *) PHRQ_realloc(STR1, j + 1); + if (STR1 == NULL) malloc_error(); + sprintf(STR1, "%.*s", (int)j, n.UU.sval + i - 1); + strcpy(n.UU.sval, STR1); + } + require(tokrp, LINK); + break; + + case toklen: + s = strfactor(LINK); + n.UU.val = strlen(s); + free(s); + break; + + case tokpeek: +/* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ + trick.i = intfactor(LINK); + n.UU.val = *trick.c; +/* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ + break; + + default: + snerr(); + break; + } + s_v.subscripts = (int*) free_check_null(s_v.subscripts); + free_check_null(STR1); + free_check_null(STR2); + return n; +} + +Local valrec upexpr(struct LOC_exec *LINK) +{ + valrec n, n2; + + n = factor(LINK); + while (LINK->t != NULL && LINK->t->kind == tokup) { + if (n.stringval) + tmerr(); + LINK->t = LINK->t->next; + n2 = upexpr(LINK); + if (n2.stringval) + tmerr(); + if (n.UU.val >= 0) { + if (n.UU.val >0) { + n.UU.val = exp(n2.UU.val * log(n.UU.val)); + } + continue; + } + if (n2.UU.val != (long)n2.UU.val) + n.UU.val = log(n.UU.val); + n.UU.val = exp(n2.UU.val * log(-n.UU.val)); + if (((long)n2.UU.val) & 1) + n.UU.val = -n.UU.val; + } + return n; +} + +Local valrec term(struct LOC_exec *LINK) +{ + valrec n, n2; + int k; + + n = upexpr(LINK); + while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & ((1L << ((long)toktimes)) | + (1L << ((long)tokdiv)) | (1L << ((long)tokmod)))) != 0) { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = upexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(); + if (k == tokmod) { + /* n.UU.val = (long)floor(n.UU.val + 0.5) % (long)floor(n2.UU.val + 0.5); */ + if (n.UU.val != 0) { + n.UU.val = fabs(n.UU.val)/n.UU.val * fmod(fabs(n.UU.val) + 1e-14, n2.UU.val); + } else { + n.UU.val = 0; + } +/* p2c: basic.p, line 1078: + * Note: Using % for possibly-negative arguments [317] */ + } else if (k == toktimes) + n.UU.val *= n2.UU.val; + else + if (n2.UU.val != 0) { + n.UU.val /= n2.UU.val; + } else { + error_msg("Zero divide in Basic. Value set to zero.", CONTINUE); + n.UU.val = 0; + } + } + return n; +} + +Local valrec sexpr(struct LOC_exec *LINK) +{ + valrec n, n2; + int k, m; + + n = term(LINK); + while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)tokplus)) | (1L << ((long)tokminus)))) != 0) { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = term(LINK); + if (n.stringval != n2.stringval) + tmerr(); + if (k == tokplus) { + if (n.stringval) { + m = strlen(n.UU.sval) + strlen(n2.UU.sval) + 1; + if (m < 256) m = 256; + + n.UU.sval = (char *) PHRQ_realloc(n.UU.sval, m); + if (n.UU.sval == NULL) malloc_error(); + strcat(n.UU.sval, n2.UU.sval); + free(n2.UU.sval); + } else + n.UU.val += n2.UU.val; + } else { + if (n.stringval) + tmerr(); + else + n.UU.val -= n2.UU.val; + } + } + return n; +} + +Local valrec relexpr(struct LOC_exec *LINK) +{ + valrec n, n2; + boolean f; + int k; + + n = sexpr(LINK); + while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)tokne + 1)) - (1L << ((long)tokeq)))) != 0) { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = sexpr(LINK); + if (n.stringval != n2.stringval) + tmerr(); + if (n.stringval) { + f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)tokeq)) | + (1L << ((long)tokge)) | (1L << ((long)tokle)))) != 0) || + (strcmp(n.UU.sval, n2.UU.sval) < 0 && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)toklt)) | + (1L << ((long)tokle)) | (1L << ((long)tokne)))) != 0) || + (strcmp(n.UU.sval, n2.UU.sval) > 0 && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)tokgt)) | + (1L << ((long)tokge)) | (1L << ((long)tokne)))) != 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+1.00 seconds, 5000 tries on line 1518 [251] */ + free(n.UU.sval); + free(n2.UU.sval); + } else + f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)tokeq)) | + (1L << ((long)tokge)) | (1L << ((long)tokle)))) != 0) || + (n.UU.val < n2.UU.val && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)toklt)) | + (1L << ((long)tokle)) | (1L << ((long)tokne)))) != 0) || + (n.UU.val > n2.UU.val && (unsigned long)k < 32 && + ((1L << ((long)k)) & ((1L << ((long)tokgt)) | + (1L << ((long)tokge)) | (1L << ((long)tokne)))) != 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+2.00 seconds, 5000 tries on line 1532 [251] */ + n.stringval = false; + n.UU.val = f; + } + return n; +} + +Local valrec andexpr(struct LOC_exec *LINK) +{ + valrec n, n2; + + n = relexpr(LINK); + while (LINK->t != NULL && LINK->t->kind == tokand) { + LINK->t = LINK->t->next; + n2 = relexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(); + n.UU.val = ((long)n.UU.val) & ((long)n2.UU.val); + } + return n; +} + +Local valrec expr(struct LOC_exec *LINK) +{ + valrec n, n2; + int k; + + n = andexpr(LINK); + while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)tokor)) | (1L << ((long)tokxor)))) != 0) { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = andexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(); + if (k == tokor) + n.UU.val = ((long)n.UU.val) | ((long)n2.UU.val); + else + n.UU.val = ((long)n.UU.val) ^ ((long)n2.UU.val); + } + return n; +} + + +Local void checkextra(struct LOC_exec *LINK) +{ + if (LINK->t != NULL) + errormsg("Extra information on line"); +} + + +Local boolean iseos(struct LOC_exec *LINK) +{ + return ( (boolean) (LINK->t == NULL || LINK->t->kind == (long)tokelse || + LINK->t->kind == (long)tokcolon) ); +} + + +Local void skiptoeos(struct LOC_exec *LINK) +{ + while (!iseos(LINK)) + LINK->t = LINK->t->next; +} + + +#ifdef SKIP +/* LINK not used */ +Local linerec *findline(long n, struct LOC_exec *LINK) +#endif +Local linerec *findline(long n) +{ + linerec *l; + + l = linebase; + while (l != NULL && l->num != n) + l = l->next; + return l; +} + + +#ifdef SKIP +Local linerec *mustfindline(long n, struct LOC_exec *LINK) +#endif +Local linerec *mustfindline(long n) +{ + linerec *l; + +#ifdef SKIP + l = findline(n, LINK); +#endif + l = findline(n); + if (l == NULL) + errormsg("Undefined line"); + return l; +} + + +Local void cmdend(struct LOC_exec *LINK) +{ + stmtline = NULL; + LINK->t = NULL; +} + + +Local void cmdnew(struct LOC_exec *LINK) +{ + void *p; + int i, k; + + cmdend(LINK); + clearloops(); + restoredata(); + while (linebase != NULL) { + p = linebase->next; + disposetokens(&linebase->txt); + free(linebase); + linebase = (struct linerec *) p; + } + while (varbase != NULL) { + p = varbase->next; + if (varbase->stringvar) { + if (varbase->numdims > 0) { + k = 1; + for (i = 0; i < varbase->numdims; i++) { + k = k*(varbase->dims[i]); + } + for (i = 0; i < k; i++) { + free_check_null(varbase->UU.U1.sarr[i]); + } + free_check_null(varbase->UU.U1.sarr); + } else if (*varbase->UU.U1.sval != NULL) { + *varbase->UU.U1.sval = (char*) free_check_null(*varbase->UU.U1.sval); + } + + } else { + free_check_null(varbase->UU.U0.arr); + varbase->UU.U0.arr = NULL; + } + free(varbase); + varbase = (struct varrec *) p; + } +} + + +Local void cmdlist(struct LOC_exec *LINK) +{ + linerec *l; + long n1, n2; + + do { + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) { + n1 = (long)LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) { + n2 = (long)LINK->t->UU.num; + LINK->t = LINK->t->next; + } else + n2 = LONG_MAX; + } + l = linebase; + while (l != NULL && l->num <= n2) { + if (l->num >= n1) { + /* printf("%ld ", l->num); */ + /* listtokens(stdout, l->txt); */ + /* putchar('\n'); */ + output_msg(OUTPUT_MESSAGE, "%ld ", l->num); + listtokens(NULL, l->txt); + output_msg(OUTPUT_MESSAGE, "\n"); + } + l = l->next; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } while (!iseos(LINK)); +} + + +Local void cmdload(boolean merging, Char *name, struct LOC_exec *LINK) +{ + FILE *f; + tokenrec *buf; + Char STR1[256]; + Char *TEMP; + + f = NULL; + if (!merging) + cmdnew(LINK); + if (f != NULL) { + sprintf(STR1, "%s.TEXT", name); + f = freopen(STR1, "r", f); + } else { + sprintf(STR1, "%s.TEXT", name); + f = fopen(STR1, "r"); + } + if (f == NULL) + _EscIO(FileNotFound); + while (fgets(inbuf, 256, f) != NULL) { + TEMP = strchr(inbuf, '\n'); + if (TEMP != NULL) + *TEMP = 0; + parseinput(&buf); + if (curline == 0) { + printf("Bad line in file\n"); + disposetokens(&buf); + } + } + if (f != NULL) + fclose(f); + f = NULL; + if (f != NULL) + fclose(f); +} + + +Local void cmdrun(struct LOC_exec *LINK) +{ + linerec *l; + long i; + /*string255 s;*/ + char *s; + + s = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (s == NULL) malloc_error(); + + l = linebase; + if (!iseos(LINK)) { + if (LINK->t->kind == toknum) +#ifdef SKIP + l = mustfindline(intexpr(LINK), LINK); +#endif + l = mustfindline(intexpr(LINK)); + else { + stringexpr(s, LINK); + i = 0; + if (!iseos(LINK)) { + require(tokcomma, LINK); + i = intexpr(LINK); + } + checkextra(LINK); + cmdload(false, s, LINK); + if (i == 0) + l = linebase; + else +#ifdef SKIP + l = mustfindline(i, LINK); +#endif + l = mustfindline(i); + } + } + stmtline = l; + LINK->gotoflag = true; + clearvars(); + clearloops(); + restoredata(); + free_check_null(s); + return; +} + +#ifdef SKIP +Local void cmdsave(struct LOC_exec *LINK) +{ + FILE *f; + linerec *l; + Char STR1[256], STR2[256]; + + f = NULL; + if (f != NULL) { + sprintf(STR2, "%s.TEXT", stringexpr(STR1, LINK)); + f = freopen(STR2, "w", f); + } else { + sprintf(STR2, "%s.TEXT", stringexpr(STR1, LINK)); + f = fopen(STR2, "w"); + } + if (f == NULL) + _EscIO(FileNotFound); + l = linebase; + while (l != NULL) { + /* fprintf(f, "%ld ", l->num);*/ + listtokens(f, l->txt); + putc('\n', f); + l = l->next; + } + if (f != NULL) + fclose(f); + f = NULL; + if (f != NULL) + fclose(f); +} +#endif + +/* replace basic save command with transport of rate back to calc_kinetic_rate */ +Local void cmdsave(struct LOC_exec *LINK) +{ +#ifdef SKIP + boolean semiflag; +#endif + valrec n; + while (!iseos(LINK)) { +#ifdef SKIP + semiflag = false; +#endif + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { +#ifdef SKIP + semiflag = true; +#endif + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) { + snerr(); + } else { + rate_moles = n.UU.val; + } + } +} +Local void cmdput(struct LOC_exec *LINK) +{ + int j; + struct save_values s_v; + + s_v.count_subscripts = 0; + s_v.subscripts = (int*) PHRQ_malloc(sizeof(int)); + + /* get parentheses */ + require(toklp, LINK); + + /* get first argumen */ + s_v.value = realexpr(LINK); + + for (;;) { + if (LINK->t != NULL && LINK->t->kind == tokcomma) { + LINK->t = LINK->t->next; + j = intexpr(LINK); + s_v.count_subscripts++; + s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) s_v.count_subscripts * sizeof(int)); + if (s_v.subscripts == NULL) malloc_error(); + s_v.subscripts[s_v.count_subscripts - 1] = j; + } else { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + + save_values_store(&s_v); + s_v.subscripts = (int*) free_check_null(s_v.subscripts); +} +#ifdef SKIP +/* LINK not used */ +Local void cmdbye(struct LOC_exec *LINK) +#endif +Local void cmdbye(void) +{ + exitflag = true; +} + +Local void cmddel(struct LOC_exec *LINK) +{ + linerec *l, *l0, *l1; + long n1, n2; + + do { + if (iseos(LINK)) + snerr(); + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) { + n1 = (long)LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) { + n2 = (long)LINK->t->UU.num; + LINK->t = LINK->t->next; + } else + n2 = LONG_MAX; + } + l = linebase; + l0 = NULL; + while (l != NULL && l->num <= n2) { + l1 = l->next; + if (l->num >= n1) { + if (l == stmtline) { + cmdend(LINK); + clearloops(); + restoredata(); + } + if (l0 == NULL) + linebase = l->next; + else + l0->next = l->next; + disposetokens(&l->txt); + free(l); + } else + l0 = l; + l = l1; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } while (!iseos(LINK)); +} + + +Local void cmdrenum(struct LOC_exec *LINK) +{ + linerec *l, *l1; + tokenrec *tok; + long lnum, step; + + lnum = 10; + step = 10; + if (!iseos(LINK)) { + lnum = intexpr(LINK); + if (!iseos(LINK)) { + require(tokcomma, LINK); + step = intexpr(LINK); + } + } + l = linebase; + if (l == NULL) + return; + while (l != NULL) { + l->num2 = lnum; + lnum += step; + l = l->next; + } + l = linebase; + do { + tok = l->txt; + do { + if (tok->kind == (long)tokdel || tok->kind == (long)tokrestore || + tok->kind == (long)toklist || tok->kind == (long)tokrun || + tok->kind == (long)tokelse || tok->kind == (long)tokthen || + tok->kind == (long)tokgosub || tok->kind == (long)tokgoto) { + while (tok->next != NULL && tok->next->kind == toknum) { + tok = tok->next; + lnum = (long)floor(tok->UU.num + 0.5); + l1 = linebase; + while (l1 != NULL && l1->num != lnum) + l1 = l1->next; + if (l1 == NULL) + printf("Undefined line %ld in line %ld\n", lnum, l->num2); + else + tok->UU.num = l1->num2; + if (tok->next != NULL && tok->next->kind == tokcomma) + tok = tok->next; + } + } + tok = tok->next; + } while (tok != NULL); + l = l->next; + } while (l != NULL); + l = linebase; + while (l != NULL) { + l->num = l->num2; + l = l->next; + } +} + + +Local void cmdprint(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + Char STR1[256]; + + semiflag = false; + while (!iseos(LINK)) { + semiflag = false; + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) { +/* fputs(n.UU.sval, stdout); */ + output_msg(OUTPUT_MESSAGE, "%s ", n.UU.sval); + free(n.UU.sval); + } else +/* printf("%s ", numtostr(STR1, n.UU.val)); */ + output_msg(OUTPUT_MESSAGE, "%s ", numtostr(STR1, n.UU.val)); + } + if (!semiflag) +/* putchar('\n');*/ + output_msg(OUTPUT_MESSAGE, "\n"); +} + +Local void cmdpunch(struct LOC_exec *LINK) +{ +#ifdef SKIP + boolean semiflag; +#endif + valrec n; + /* Char STR1[256]; */ + +#ifdef SKIP + semiflag = false; +#endif + while (!iseos(LINK)) { +#ifdef SKIP + semiflag = false; +#endif + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { +#ifdef SKIP + semiflag = true; +#endif + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) { +/* fputs(n.UU.sval, stdout); */ + if (punch.high_precision == FALSE) { + if (strlen(n.UU.sval) <= 12) { + fpunchf_user(n_user_punch_index, "%12.12s\t", n.UU.sval); + } else { + fpunchf_user(n_user_punch_index, "%s\t", n.UU.sval); + } + } else { + if (strlen(n.UU.sval) <= 20) { + fpunchf_user(n_user_punch_index, "%20.20s\t", n.UU.sval); + } else { + fpunchf_user(n_user_punch_index, "%s\t", n.UU.sval); + } + } + free(n.UU.sval); + } else + if (punch.high_precision == FALSE) { + fpunchf_user(n_user_punch_index, "%12.4e\t", n.UU.val); + } else { + fpunchf_user(n_user_punch_index, "%20.12e\t", n.UU.val); + } + ++n_user_punch_index; + } +} + +#ifdef PHREEQ98 +Local void cmdgraph_x(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + Char STR1[256]; + semiflag = false; + while (!iseos(LINK)) { + semiflag = false; + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) rownr++; + if (n.stringval) { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "x"); + Free(n.UU.sval); + } else + GridChar(numtostr(STR1, n.UU.val), "x"); + colnr++; + } +} + +Local void cmdgraph_y(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + Char STR1[256]; + semiflag = false; + while (!iseos(LINK)) { + semiflag = false; + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "y"); + Free(n.UU.sval); + } else + GridChar(numtostr(STR1, n.UU.val), "y"); + colnr++; + } +} + +Local void cmdgraph_sy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + Char STR1[256]; + semiflag = false; + while (!iseos(LINK)) { + semiflag = false; + if ((unsigned long)LINK->t->kind < 32 && + ((1L << ((long)LINK->t->kind)) & + ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "s"); + Free(n.UU.sval); + } else + GridChar(numtostr(STR1, n.UU.val), "s"); + colnr++; + } +} +#endif + +#ifdef SKIP +Local void cmdinput(struct LOC_exec *LINK) +{ + varrec *v; + /* string255 s; */ + char *s; + tokenrec *tok, *tok0, *tok1; + boolean strflag; + + /* + s = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (s == NULL) malloc_error(); + */ + /* need to free s if this subroutine is used */ + + if (LINK->t != NULL && LINK->t->kind == tokstr) { + fputs(LINK->t->UU.sp, stdout); + LINK->t = LINK->t->next; + require(toksemi, LINK); + } else + printf("? "); + tok = LINK->t; + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(); + strflag = LINK->t->UU.vp->stringvar; + do { + if (LINK->t != NULL && LINK->t->kind == tokvar) { + if (LINK->t->UU.vp->stringvar != strflag) + snerr(); + } + LINK->t = LINK->t->next; + } while (!iseos(LINK)); + LINK->t = tok; + if (strflag) { + do { + gets(s); + v = findvar(LINK); + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = (char *) PHRQ_malloc(256); + if (*v->UU.U1.sval == NULL) malloc_error(); + strcpy(*v->UU.U1.sval, s); + if (!iseos(LINK)) { + require(tokcomma, LINK); + printf("?? "); + } + } while (!iseos(LINK)); + return; + } + gets(s); + parse(s, &tok); + tok0 = tok; + do { + v = findvar(LINK); + while (tok == NULL) { + printf("?? "); + gets(s); + disposetokens(&tok0); + parse(s, &tok); + tok0 = tok; + } + tok1 = LINK->t; + LINK->t = tok; + *v->UU.U0.val = realexpr(LINK); + if (LINK->t != NULL) { + if (LINK->t->kind == tokcomma) + LINK->t = LINK->t->next; + else + snerr(); + } + tok = LINK->t; + LINK->t = tok1; + if (!iseos(LINK)) + require(tokcomma, LINK); + } while (!iseos(LINK)); + disposetokens(&tok0); +} +#endif + +Local void cmdlet(boolean implied, struct LOC_exec *LINK) +{ + varrec *v; + Char *old, *mynew; + LDBLE d_value; + LDBLE *target; + char **starget; + target = NULL; + starget = NULL; + if (implied) + LINK->t = stmttok; + v = findvar(LINK); + if (v->stringvar) { + starget = v->UU.U1.sval; + } else { + target = v->UU.U0.val; + } + require(tokeq, LINK); + if (!v->stringvar) { + /* in case array is used on right hand side */ + d_value = realexpr(LINK); + v->UU.U0.val = target; + *v->UU.U0.val = d_value; + /* *v->UU.U0.val = realexpr(LINK); */ + return; + } + mynew = strexpr(LINK); + v->UU.U1.sval = starget; + old = *v->UU.U1.sval; + *v->UU.U1.sval = mynew; + if (old != NULL) + free(old); +} + + +Local void cmdgoto(struct LOC_exec *LINK) +{ +#ifdef SKIP + stmtline = mustfindline(intexpr(LINK), LINK); +#endif + stmtline = mustfindline(intexpr(LINK)); + LINK->t = NULL; + LINK->gotoflag = true; +} + + +Local void cmdif(struct LOC_exec *LINK) +{ + LDBLE n; + long i; + + n = realexpr(LINK); + require(tokthen, LINK); + if (n == 0) { + i = 0; + do { + if (LINK->t != NULL) { + if (LINK->t->kind == tokif) + i++; + if (LINK->t->kind == tokelse) + i--; + LINK->t = LINK->t->next; + } + } while (LINK->t != NULL && i >= 0); + } + if (LINK->t != NULL && LINK->t->kind == toknum) + cmdgoto(LINK); + else + LINK->elseflag = true; +} + + +Local void cmdelse(struct LOC_exec *LINK) +{ + LINK->t = NULL; +} + + +Local boolean skiploop(int up, int dn, struct LOC_exec *LINK) +{ + boolean Result; + long i; + linerec *saveline; + + saveline = stmtline; + i = 0; + do { + while (LINK->t == NULL) { + if (stmtline == NULL || stmtline->next == NULL) { + Result = false; + stmtline = saveline; + goto _L1; + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == up) + i++; + if (LINK->t->kind == dn) + i--; + LINK->t = LINK->t->next; + } while (i >= 0); + Result = true; +_L1: + return Result; +} + + +Local void cmdfor(struct LOC_exec *LINK) +{ + looprec *l, lr; + linerec *saveline; + long i, j; + + lr.UU.U0.vp = findvar(LINK); + if (lr.UU.U0.vp->stringvar) + snerr(); + require(tokeq, LINK); + *lr.UU.U0.vp->UU.U0.val = realexpr(LINK); + require(tokto, LINK); + lr.UU.U0.max = realexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokstep) { + LINK->t = LINK->t->next; + lr.UU.U0.step = realexpr(LINK); + } else + lr.UU.U0.step = 1.0; + lr.homeline = stmtline; + lr.hometok = LINK->t; + lr.kind = forloop; + lr.next = loopbase; + if ((lr.UU.U0.step >= 0 && *lr.UU.U0.vp->UU.U0.val > lr.UU.U0.max) || + (lr.UU.U0.step <= 0 && *lr.UU.U0.vp->UU.U0.val < lr.UU.U0.max)) { + saveline = stmtline; + i = 0; + j = 0; + do { + while (LINK->t == NULL) { + if (stmtline == NULL || stmtline->next == NULL) { + stmtline = saveline; + errormsg("FOR without NEXT"); + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == tokfor) { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j++; + else + i++; + } + if (LINK->t->kind == toknext) { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j--; + else + i--; + } + LINK->t = LINK->t->next; + } while (i >= 0 && j >= 0); + skiptoeos(LINK); + return; + } + l = (looprec *) PHRQ_malloc(sizeof(looprec)); + if (l == NULL) malloc_error(); + *l = lr; + loopbase = l; +} + + +Local void cmdnext(struct LOC_exec *LINK) +{ + varrec *v; + boolean found; + looprec *l, *WITH; + + if (!iseos(LINK)) + v = findvar(LINK); + else + v = NULL; + do { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("NEXT without FOR"); + found = (boolean) (loopbase->kind == forloop && + (v == NULL || loopbase->UU.U0.vp == v)); + if (!found) { + l = loopbase->next; + free(loopbase); + loopbase = l; + } + } while (!found); + WITH = loopbase; + *WITH->UU.U0.vp->UU.U0.val += WITH->UU.U0.step; + if ((WITH->UU.U0.step < 0 || *WITH->UU.U0.vp->UU.U0.val <= WITH->UU.U0.max) && + (WITH->UU.U0.step > 0 || *WITH->UU.U0.vp->UU.U0.val >= WITH->UU.U0.max)) { + stmtline = WITH->homeline; + LINK->t = WITH->hometok; + return; + } + l = loopbase->next; + free(loopbase); + loopbase = l; +} + + +Local void cmdwhile(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PHRQ_malloc(sizeof(looprec)); + if (l == NULL) malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = whileloop; + l->homeline = stmtline; + l->hometok = LINK->t; + if (iseos(LINK)) + return; + if (realexpr(LINK) != 0) + return; + if (!skiploop(tokwhile, tokwend, LINK)) + errormsg("WHILE without WEND"); + l = loopbase->next; + free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + +Local void cmdwend(struct LOC_exec *LINK) +{ + tokenrec *tok; + linerec *tokline; + looprec *l; + boolean found; + + do { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("WEND without WHILE"); + found = (boolean) (loopbase->kind == whileloop); + if (!found) { + l = loopbase->next; + free(loopbase); + loopbase = l; + } + } while (!found); + if (!iseos(LINK)) { + if (realexpr(LINK) != 0) + found = false; + } + tok = LINK->t; + tokline = stmtline; + if (found) { + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + if (!iseos(LINK)) { + if (realexpr(LINK) == 0) + found = false; + } + } + if (found) + return; + LINK->t = tok; + stmtline = tokline; + l = loopbase->next; + free(loopbase); + loopbase = l; +} + + +Local void cmdgosub(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PHRQ_malloc(sizeof(looprec)); + if (l == NULL) malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + cmdgoto(LINK); +} + + +Local void cmdreturn(struct LOC_exec *LINK) +{ + looprec *l; + boolean found; + + do { + if (loopbase == NULL) + errormsg("RETURN without GOSUB"); + found = (boolean) (loopbase->kind == gosubloop); + if (!found) { + l = loopbase->next; + free(loopbase); + loopbase = l; + } + } while (!found); + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + l = loopbase->next; + free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + +Local void cmdread(struct LOC_exec *LINK) +{ + varrec *v; + tokenrec *tok; + boolean found; + + do { + v = findvar(LINK); + tok = LINK->t; + LINK->t = datatok; + if (dataline == NULL) { + dataline = linebase; + LINK->t = dataline->txt; + } + if (LINK->t == NULL || LINK->t->kind != tokcomma) { + do { + while (LINK->t == NULL) { + if (dataline == NULL || dataline->next == NULL) + errormsg("Out of Data"); + dataline = dataline->next; + LINK->t = dataline->txt; + } + found = (boolean) (LINK->t->kind == tokdata); + LINK->t = LINK->t->next; + } while (!found || iseos(LINK)); + } else + LINK->t = LINK->t->next; + if (v->stringvar) { + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = (char *) free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = strexpr(LINK); + } else + *v->UU.U0.val = realexpr(LINK); + datatok = LINK->t; + LINK->t = tok; + if (!iseos(LINK)) + require(tokcomma, LINK); + } while (!iseos(LINK)); +} + + +Local void cmddata(struct LOC_exec *LINK) +{ + skiptoeos(LINK); +} + + +Local void cmdrestore(struct LOC_exec *LINK) +{ + if (iseos(LINK)) + restoredata(); + else { +#ifdef SKIP + dataline = mustfindline(intexpr(LINK), LINK); +#endif + dataline = mustfindline(intexpr(LINK)); + datatok = dataline->txt; + } +} + + +Local void cmdgotoxy(struct LOC_exec *LINK) +{ +#ifdef SKIP + long i; + + i = intexpr(LINK); +#endif + intexpr(LINK); + require(tokcomma, LINK); +} + + +Local void cmdon(struct LOC_exec *LINK) +{ + long i; + looprec *l; + + i = intexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokgosub) { + l = (looprec *) PHRQ_malloc(sizeof(looprec)); + if (l == NULL) malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + LINK->t = LINK->t->next; + } else + require(tokgoto, LINK); + if (i < 1) { + skiptoeos(LINK); + return; + } + while (i > 1 && !iseos(LINK)) { + require(toknum, LINK); + if (!iseos(LINK)) + require(tokcomma, LINK); + i--; + } + if (!iseos(LINK)) + cmdgoto(LINK); +} + + +Local void cmddim(struct LOC_exec *LINK) +{ + long i, j, k; + varrec *v; + boolean done; + + do { + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (v->numdims != 0) + errormsg("Array already dimensioned"); + j = 1; + i = 0; + require(toklp, LINK); + do { + k = intexpr(LINK) + 1; + if (k < 1) + badsubscr(); + if (i >= maxdims) + badsubscr(); + i++; + v->dims[i - 1] = k; + j *= k; + done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); + if (!done) + require(tokcomma, LINK); + } while (!done); + LINK->t = LINK->t->next; + v->numdims = (char) i; + if (v->stringvar) { + v->UU.U1.sarr = (Char **) PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) malloc_error(); + for (i = 0; i < j; i++) + v->UU.U1.sarr[i] = NULL; + } else { + v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); + if (v->UU.U0.arr == NULL) malloc_error(); + for (i = 0; i < j; i++) + v->UU.U0.arr[i] = 0.0; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } while (!iseos(LINK)); +} + + +Local void cmdpoke(struct LOC_exec *LINK) +{ + union { + long i; + Char *c; + } trick; + +/* p2c: basic.p, line 2073: Note: Range checking is OFF [216] */ + trick.i = intexpr(LINK); + require(tokcomma, LINK); + *trick.c = (Char)intexpr(LINK); +/* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ +} + + + + + + + + + +Static void exec(void) +{ + struct LOC_exec V; + Char *ioerrmsg; + Char STR1[256]; + + + TRY(try1); + do { + do { + V.gotoflag = false; + V.elseflag = false; + while (stmttok != NULL && stmttok->kind == tokcolon) + stmttok = stmttok->next; + V.t = stmttok; + if (V.t != NULL) { + V.t = V.t->next; + switch (stmttok->kind) { + + case tokrem: + /* blank case */ + break; + + case toklist: + cmdlist(&V); + break; + + case tokrun: + cmdrun(&V); + break; + + case toknew: + cmdnew(&V); + break; + + case tokload: + cmdload(false, stringexpr(STR1, &V), &V); + break; + + case tokmerge: + cmdload(true, stringexpr(STR1, &V), &V); + break; + + case toksave: + cmdsave(&V); + break; + + case tokbye: +#ifdef SKIP + cmdbye(&V); +#endif + cmdbye(); + break; + + case tokdel: + cmddel(&V); + break; + + case tokrenum: + cmdrenum(&V); + break; + + case toklet: + cmdlet(false, &V); + break; + + case tokvar: + cmdlet(true, &V); + break; + + case tokprint: + cmdprint(&V); + break; + + case tokpunch: + cmdpunch(&V); + break; + + case tokput: + cmdput(&V); + break; + +#ifdef PHREEQ98 + case tokgraph_x: + cmdgraph_x(&V); + break; + + case tokgraph_y: + cmdgraph_y(&V); + break; + + case tokgraph_sy: + cmdgraph_sy(&V); + break; +#endif + + case tokinput: + error_msg("Basic command INPUT is not a legal command in PHREEQC.", STOP); +#ifdef SKIP + cmdinput(&V); +#endif + break; + + case tokgoto: + cmdgoto(&V); + break; + + case tokif: + cmdif(&V); + break; + + case tokelse: + cmdelse(&V); + break; + + case tokend: + cmdend(&V); + break; + + case tokstop: + P_escapecode = -20; + goto _Ltry1; + + case tokfor: + cmdfor(&V); + break; + + case toknext: + cmdnext(&V); + break; + + case tokwhile: + cmdwhile(&V); + break; + + case tokwend: + cmdwend(&V); + break; + + case tokgosub: + cmdgosub(&V); + break; + + case tokreturn: + cmdreturn(&V); + break; + + case tokread: + cmdread(&V); + break; + + case tokdata: + cmddata(&V); + break; + + case tokrestore: + cmdrestore(&V); + break; + + case tokgotoxy: + cmdgotoxy(&V); + break; + + case tokon: + cmdon(&V); + break; + + case tokdim: + cmddim(&V); + break; + + case tokpoke: + cmdpoke(&V); + break; + + default: + errormsg("Illegal command"); + break; + } + } + if (!V.elseflag && !iseos(&V)) + checkextra(&V); + stmttok = V.t; + } while (V.t != NULL); + if (stmtline != NULL) { + if (!V.gotoflag) + stmtline = stmtline->next; + if (stmtline != NULL) + stmttok = stmtline->txt; + } + } while (stmtline != NULL); + RECOVER2(try1,_Ltry1); + if (P_escapecode == -20) + error_msg("Break", CONTINUE); +#ifdef SKIP + printf("Break"); +#endif + else if (P_escapecode != 42) { + switch (P_escapecode) { + + case -4: +#ifdef SKIP + printf("\007Integer overflow"); +#endif + error_msg("Integer overflow", CONTINUE); + break; + + case -5: +#ifdef SKIP + printf("\007Divide by zero"); +#endif + error_msg("Divide by zero", CONTINUE); + break; + + case -6: +#ifdef SKIP + printf("\007Real math overflow"); +#endif + error_msg("Real math overflow", CONTINUE); + break; + + case -7: +#ifdef SKIP + printf("\007Real math underflow"); +#endif + error_msg("Real math underflow", CONTINUE); + break; + + case -8: + case -19: + case -18: + case -17: + case -16: + case -15: +#ifdef SKIP + printf("\007Value range error"); +#endif + error_msg("Value range error", CONTINUE); + break; + + case -10: + ioerrmsg = (char *) PHRQ_malloc(256); + if (ioerrmsg == NULL) malloc_error(); + sprintf(ioerrmsg, "I/O Error %d", (int)P_ioresult); +#ifdef SKIP + printf("\007%s", ioerrmsg); +#endif + error_msg(ioerrmsg, CONTINUE); + free(ioerrmsg); + break; + + default: + if (EXCP_LINE != -1) { + sprintf(error_string, "%12ld\n", EXCP_LINE); + error_msg(error_string, CONTINUE); + } +#ifdef SKIP + printf("%12ld\n", EXCP_LINE); +#endif + _Escape(P_escapecode); + break; + } + } + if (stmtline != NULL) { + sprintf(error_string, " in line %ld", stmtline->num); + error_msg(error_string, CONTINUE); + } +#ifdef SKIP + printf(" in %ld", stmtline->num); + putchar('\n'); +#endif + ENDTRY(try1); +} /*exec*/ + +int free_dim_stringvar(struct varrec *varbase) +{ + int i, k; + if (varbase->numdims > 0) { + k = 1; + for (i = 0; i < varbase->numdims; i++) { + k = k*(varbase->dims[i]); + } + for (i = 0; i < k; i++) { + free_check_null(varbase->UU.U1.sarr[i]); + } + varbase->UU.U1.sarr = (char **) free_check_null(varbase->UU.U1.sarr); + } + return(OK); +} diff --git a/basicsubs.cpp b/basicsubs.cpp new file mode 100644 index 00000000..cf129578 --- /dev/null +++ b/basicsubs.cpp @@ -0,0 +1,1774 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: basicsubs.c 338 2005-06-15 14:10:45Z dlpark $"; + +struct system_species { + char * name; + char *type; + LDBLE moles; +}; +struct system_species *sys; +int count_sys, max_sys; +LDBLE sys_tot; + +/* ---------------------------------------------------------------------- */ +LDBLE activity (char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE a; + if (svnid == NULL) fprintf(stderr," "); + + s_ptr = s_search(species_name); + if (s_ptr == s_h2o) { + a = pow(10., s_h2o->la); + } else if (s_ptr == s_eminus) { + a = pow(10.,s_eminus->la); + } else if (s_ptr == NULL || s_ptr->in == FALSE) { + a = 1e-99; + } else { + a = pow(10., s_ptr->lm + s_ptr->lg); + } + return(a); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_logk_n(char *name) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH]; + int i; + LDBLE lk; + struct logk *logk_ptr; + LDBLE logk[8]; + struct name_coef add_logk; + + for (i = 0; i < 8; i++) { + logk[i] = 0.0; + } + strcpy(token, name); + logk_ptr = logk_search(token); + if (logk_ptr != NULL) { + add_logk.name = token; + add_logk.coef = 1.0; + add_other_logk(logk, 1, &add_logk); + lk = k_calc(logk, tk_x); + return(lk); + } + return(-999.99); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_logk_p(char *name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + LDBLE lk; + LDBLE logk[8]; + + strcpy(token, name); + phase_ptr = phase_bsearch(token, &j, FALSE); + if (phase_ptr != NULL) { + for (i = 0; i < 8; i++) { + logk[i] = 0.0; + } + select_log_k_expression(phase_ptr->logk, logk); + add_other_logk(logk, phase_ptr->count_add_logk, phase_ptr->add_logk); + lk = k_calc(logk, tk_x); + return(lk); + } + return(-999.99); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_logk_s(char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + char token[MAX_LENGTH]; + struct species *s_ptr; + LDBLE lk, logk[8]; + + strcpy(token, name); + s_ptr = s_search(token); + if (s_ptr != NULL) { + for (i = 0; i < 8; i++) { + logk[i] = 0.0; + } + select_log_k_expression(s_ptr->logk, logk); + add_other_logk(logk, s_ptr->count_add_logk, s_ptr->add_logk); + lk = k_calc(logk, tk_x); + return(lk); + } + return(-999.99); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_surface_charge(char *surface_name) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr; + int i, j, k; + LDBLE charge; + struct rxn_token_temp *token_ptr; + struct master *master_ptr; + + /* + * Go through species, sum charge + */ + charge = 0; + for (k = 0; k < count_s_x; k++) { + if (s_x[k]->type != SURF) continue; + /* + * Match surface_name + */ + count_trxn=0; + trxn_add (s_x[k]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ + for (i=1; i < count_trxn; i++) { + token_ptr = &(trxn.token[i]); + if (token_ptr->s->type != SURF) continue; + master_ptr = trxn.token[i].s->primary; + strcpy(token, master_ptr->elt->name); + replace ("_", " ", token); + ptr = token; + copy_token(token1, &ptr, &j); + if (strcmp(surface_name, token1) == 0) { + charge += s_x[k]->moles *s_x[k]->z; + } + } + } + return(charge); +} +/* ---------------------------------------------------------------------- */ +LDBLE diff_layer_total(char *total_name, char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in LDBLE layer + */ + int i, j, k, count_g; + struct surface_charge *surface_charge_ptr1; + char name[MAX_LENGTH], token[MAX_LENGTH]; + char surface_name_local[MAX_LENGTH]; + char *ptr; + + LDBLE mass_water_surface; + LDBLE molality, moles_excess, moles_surface, charge; + + if (use.surface_ptr == NULL || (diffuse_layer_x == FALSE && + strcmp_nocase("psi", total_name) != 0 && + strcmp_nocase("charge", total_name) != 0 && + strcmp_nocase("sigma", total_name) != 0 ) + ) return(0); + +/* + * Find surface... + */ + i = 0; + for (j =0; j < count_unknowns; j++) { + if (use.surface_ptr->edl == TRUE) { + if (x[j]->type != SURFACE_CB) continue; + strcpy(name, x[j]->master[0]->elt->name); + replace ("_psi", "", name); + } else { + if (x[j]->type != SURFACE) continue; + strcpy(token, x[j]->master[0]->elt->name); + replace ("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + } + if (surface_name != NULL) { + if (strcmp(name, surface_name) == 0) break; + } else { + break; + } + } + if (j >= count_unknowns) return(0); + strcpy(surface_name_local, name); + /* + * Psi, charge, sigma + */ + if (strcmp_nocase("psi", total_name) == 0) { + if (use.surface_ptr->edl == TRUE) { + return((LDBLE) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ)); + } else { + return(0); + } + } else if (strcmp_nocase("charge", total_name) == 0) { + if (use.surface_ptr->edl == TRUE && diffuse_layer_x == FALSE) { + return((LDBLE) (x[j]->f)); + } else { + return(calc_surface_charge(surface_name_local)); + } + } else if (strcmp_nocase("sigma", total_name) == 0) { + if (use.surface_ptr->edl == TRUE) { + if (diffuse_layer_x == TRUE) { + charge = calc_surface_charge(surface_name_local); + } else { + charge = x[j]->f; + } + if ((x[j]->surface_charge->specific_area * x[j]->surface_charge->grams) > 0) { + return((LDBLE) (charge * F_C_MOL / (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams))); + } else { + return(0); + } + } else { + return(0); + } + } else if (strcmp_nocase("water", total_name) == 0) { + if (diffuse_layer_x == TRUE) { + return(x[j]->surface_charge->mass_water); + } else { + return(0); + } + } +/* + * find total moles of each element in diffuse layer... + */ + surface_charge_ptr1 = x[j]->surface_charge; + mass_water_surface = surface_charge_ptr1->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { + if (s_x[j]->type > HPLUS) continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + + moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; + moles_surface = mass_water_surface * molality + moles_excess; +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Return totals + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + return((LDBLE) elt_list[j].coef); + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE equi_phase (char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + if (use.pp_assemblage_in == FALSE || use.pp_assemblage_ptr == NULL) return(0); + for( j = 0; j < count_unknowns; j++) { + if (x[j]->type != PP) continue; + if (strcmp_nocase(x[j]->pure_phase->name, phase_name) == 0) { + break; + } + } +/* + * Print pure phase assemblage data + */ + if (j == count_unknowns) { + /* if not an unknown */ + for (i=0; i < use.pp_assemblage_ptr->count_comps; i++) { + if (strcmp_nocase(use.pp_assemblage_ptr->pure_phases[i].name,phase_name) == 0) { + return(use.pp_assemblage_ptr->pure_phases[i].moles); + } + } + } else { + /* if an unknown */ + if (x[j]->moles < 0.0) x[j]->moles = 0.0; + return(x[j]->moles); + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE find_gas_comp (char *gas_comp_name) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (use.gas_phase_in == FALSE || use.gas_phase_ptr == NULL) return(0); + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + if (strcmp_nocase(use.gas_phase_ptr->comps[i].name, gas_comp_name) == 0) { + return(use.gas_phase_ptr->comps[i].phase->moles_x); + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE find_misc1 (char *s_s_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0.0); + for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, s_s_name) == 0) { + if (use.s_s_assemblage_ptr->s_s[j].miscibility == TRUE) { + return(use.s_s_assemblage_ptr->s_s[j].xb1); + } else { + return(1.0); + } + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE find_misc2 (char *s_s_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0.0); + for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, s_s_name) == 0) { + if (use.s_s_assemblage_ptr->s_s[j].miscibility == TRUE) { + return(use.s_s_assemblage_ptr->s_s[j].xb2); + } else { + return(1.0); + } + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE find_s_s_comp (char *s_s_comp_name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); + for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].comps[i].name, s_s_comp_name) == 0) { + if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { + return(use.s_s_assemblage_ptr->s_s[j].comps[i].moles); + } else { + return(0.0); + } + } + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE get_calculate_value(char *name) +/* ---------------------------------------------------------------------- */ +/* + * Gets value from a calclate_value structure + * arguments: name + * return: LDBLE of value + */ +{ + struct calculate_value *calculate_value_ptr; + calculate_value_ptr = calculate_value_search(name); + if (calculate_value_ptr == NULL) { + sprintf(error_string, "CALC_VALUE Basic function, %s not found.", name); + error_msg(error_string, CONTINUE); + input_error++; + return(MISSING); + } + if (name == NULL) { + sprintf(error_string, "Definition for calculated value not found, %s", name); + input_error++; + error_msg(error_string, CONTINUE); + return (MISSING); + } + if (calculate_value_ptr->calculated == FALSE) { + sprintf(error_string, "Calculated value used before it has been calculated, %s.\nCalculated values are evalutated in the order in which they were defined.", name); + input_error++; + error_msg(error_string, CONTINUE); + return (MISSING); + } + return(calculate_value_ptr->value); +} +/* ---------------------------------------------------------------------- */ +LDBLE kinetics_moles (char *kinetics_name) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (use.kinetics_in == FALSE || use.kinetics_ptr == NULL) return(0); + for (i = 0; i < use.kinetics_ptr->count_comps; i++) { + if (strcmp_nocase(use.kinetics_ptr->comps[i].rate_name, kinetics_name) == 0) { + return (use.kinetics_ptr->comps[i].m); + } + } + + sprintf(error_string, "No data for rate %s in KINETICS keyword.", kinetics_name); + warning_msg(error_string); + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE log_activity (char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE la; + + s_ptr = s_search(species_name); + + if (s_ptr == s_eminus) { + la = s_eminus->la; + } else if (s_ptr == NULL || s_ptr->in == FALSE) { + la = -99.99; + } else if (s_ptr == s_h2o) { + la = s_h2o->la; + } else { + la = s_ptr->lm + s_ptr->lg; + } + return(la); +} +/* ---------------------------------------------------------------------- */ +LDBLE log_molality (char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE lm; + + s_ptr = s_search(species_name); + + if (s_ptr == s_eminus) { + lm = -99.99; + } else if (s_ptr == NULL || s_ptr->in == FALSE) { + lm = -99.99; + } else if (s_ptr == s_h2o) { + lm = log10(s_ptr->moles / mass_water_aq_x); + } else { + lm = s_ptr->lm; + } + return(lm); +} +/* ---------------------------------------------------------------------- */ +LDBLE molality (char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE m; + + s_ptr = s_search(species_name); + if (s_ptr == NULL || s_ptr == s_eminus || s_ptr->in == FALSE) { + m = 1e-99; + } else { + /* m = pow(10., s_ptr->lm); */ + m = s_ptr->moles/mass_water_aq_x; + } + return(m); +} +/* ---------------------------------------------------------------------- */ +LDBLE saturation_ratio (char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + int l; + LDBLE si, iap; + + iap = 0.0; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) { + sprintf(error_string, "Mineral %s, not found.", phase_name); + warning_msg(error_string); + return(1e-99); + } else if (phase_ptr->in != FALSE) { + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = iap - phase_ptr->lk; + return(pow(10.0, si)); + } + return(0.0); + +} +/* ---------------------------------------------------------------------- */ +int saturation_index (char *phase_name, LDBLE *iap, LDBLE *si) +/* ---------------------------------------------------------------------- */ +{ + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + int l; + + *si = -99.99; + *iap = 0.0; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) { + sprintf(error_string, "Mineral %s, not found.", phase_name); + warning_msg(error_string); + *si = -99; + } else if (phase_ptr->in != FALSE) { + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + *iap += rxn_ptr->s->la * rxn_ptr->coef; + } + *si = *iap - phase_ptr->lk; + } else { + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE sum_match_gases (char *mytemplate, char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + if (use.gas_phase_in == FALSE || use.gas_phase_ptr == NULL) return(0); + tot = 0; + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + if (match_elts_in_species(use.gas_phase_ptr->comps[i].phase->formula,mytemplate) == TRUE) { + if (name == NULL) { + tot += use.gas_phase_ptr->comps[i].phase->moles_x; + } else { + for (next_elt = use.gas_phase_ptr->comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { + if (strcmp(next_elt->elt->name, name) == 0) { + tot += next_elt->coef * use.gas_phase_ptr->comps[i].phase->moles_x; + break; + } + } + } + } + } + return(tot); +} +/* ---------------------------------------------------------------------- */ +LDBLE sum_match_species (char *mytemplate, char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + count_elts = 0; + paren_count = 0; + tot = 0; + for (i = 0; i < count_s_x; i++) { + if (match_elts_in_species(s_x[i]->name, mytemplate) == TRUE) { + if (name == NULL) { + tot += s_x[i]->moles; + } else { + for (next_elt = s_x[i]->next_elt; next_elt->elt != NULL; next_elt++) { + if (strcmp(next_elt->elt->name, name) == 0) { + tot += next_elt->coef * s_x[i]->moles; + break; + } + } + } + } + } + return(tot); +} +/* ---------------------------------------------------------------------- */ +LDBLE sum_match_s_s (char *mytemplate, char *name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE tot; + struct elt_list *next_elt; + + if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); + tot = 0; + for (j=0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, mytemplate) == 0) { + if (use.s_s_assemblage_ptr->s_s[j].s_s_in == FALSE) { + tot = 0; + break; + } + for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (name == NULL) { + tot += use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + } else { + for (next_elt = use.s_s_assemblage_ptr->s_s[j].comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { + if (strcmp(next_elt->elt->name, name) == 0) { + tot += next_elt->coef * use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + break; + } + } + } + } + break; + } + } + return(tot); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +LDBLE sum_match_s_s (char *template, char *name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE tot; + struct elt_list *next_elt; + + if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); + tot = 0; + for (j=0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (match_elts_in_species(use.s_s_assemblage_ptr->s_s[j].comps[i].phase->formula,template) == TRUE) { + if (name == NULL) { + tot += use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + } else { + for (next_elt = use.s_s_assemblage_ptr->s_s[j].comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { + if (strcmp(next_elt->elt->name, name) == 0) { + tot += next_elt->coef * use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + break; + } + } + } + } + } + } + return(tot); +} +#endif +/* ---------------------------------------------------------------------- */ +int match_elts_in_species (char *name, char *mytemplate) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, i1, l, case_no, match; + char c, c1; + char *ptr, *ptr1, *replace_name, *name_ptr; + LDBLE d; + char element[MAX_LENGTH]; + char token[MAX_LENGTH], equal_list[MAX_LENGTH], elt_name[MAX_LENGTH]; + char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH]; + char str[2]; + + strcpy(token, name); + squeeze_white(token); + while (replace("(+","(",token)); + while (replace("++++++","+6",token)); + while (replace("+++++","+5",token)); + while (replace("++++","+4",token)); + while (replace("+++","+3",token)); + while (replace("++","+2",token)); + while (replace("------","-6",token)); + while (replace("-----","-5",token)); + while (replace("----","-4",token)); + while (replace("---","-3",token)); + while (replace("--","-2",token)); + + ptr = token; + count_match_tokens = 0; + while ( (c=*ptr) != '\0') { + c1=*(ptr+1); + str[0] = c; + str[1] = '\0'; +/* + * New element + */ + if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) { + /* + * Get new element and subscript + */ + if ( get_elt( &ptr, element, &l) == ERROR) { + return(ERROR); + } + match_tokens[count_match_tokens].name = string_hsave(element); + if ( get_num( &ptr , &d ) == ERROR) { + return(ERROR); + } + match_tokens[count_match_tokens++].coef = d; + } else { + match_tokens[count_match_tokens].name = string_hsave(str); + match_tokens[count_match_tokens++].coef = 1.0; + ptr += 1; + } + } + /* + * Replace elements with first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) { + replace("{","",equal_list); + replace("}","",equal_list); + while (replace(","," ",equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list from template + */ + if (copy_token(elt_name, &ptr1, &l) == EMPTY) { + sprintf(error_string, "Expecting a nonempty list of element names in isotope sum. %s", mytemplate); + error_msg(error_string, CONTINUE); + return(ERROR); + } + replace_name = string_hsave(elt_name); + /* + * Replace in species all equivalent names from template + */ + while (copy_token(elt_name, &ptr1, &l) != EMPTY) { + name_ptr = string_hsave (elt_name); + for (i = 0; i < count_match_tokens; i++) { + if (name_ptr == match_tokens[i].name) { + match_tokens[i].name = replace_name; + } + } + } + } + /* + * Combine contiguous elements + */ + i1 = 0; + for ( i = 1; i < count_match_tokens; i++) { + if ((isupper((int) (match_tokens[i].name[0])) != FALSE) && (match_tokens[i].name == match_tokens[i1].name)) { + match_tokens[i1].coef += match_tokens[i].coef; + } else { + i1++; + match_tokens[i1].name = match_tokens[i].name; + match_tokens[i1].coef = match_tokens[i].coef; + } + } + count_match_tokens = i1 + 1; + /* + * write out string + */ + token[0] = '\0'; + for (i = 0; i < count_match_tokens; i++) { + strcat(token, match_tokens[i].name); + if (match_tokens[i].coef != 1.0) { + sprintf(token1, "%g", (double) match_tokens[i].coef); + strcat(token, token1); + } + } + /* + * Write a template name using first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) { + strcpy(equal_list1, equal_list); + replace("{","",equal_list); + replace("}","",equal_list); + while (replace(","," ",equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list + */ + if (copy_token(elt_name, &ptr1, &l) == EMPTY) { + sprintf(error_string, "Expecting a nonempty list of element names in isotope sum. %s", mytemplate); + error_msg(error_string, CONTINUE); + return(ERROR); + } + replace_name = string_hsave(elt_name); + replace(equal_list1, replace_name, template1); + squeeze_white(template1); + ptr = template1; + } + /* + * Compare string + */ + /* Cases: 0 exact match + * 1 leading wild card + * 2 trailing wild card + * 3 leading and trailing wild card + */ + case_no = 0; + if (template1[0] == '*') case_no = 1; + l = strlen(template1); + if (template1[l - 1] == '*') { + if (case_no != 1) { + case_no = 2; + } else { + case_no = 3; + } + } + while (replace("*","",template1)); + match = FALSE; + switch (case_no) { + case 0: + /* exact match */ + if (strcmp(token, template1) == 0) match = TRUE; + break; + case 1: + /* leading wild card */ + if ((ptr = strstr(token, template1)) == NULL) { + match = FALSE; + } else { + if (strcmp(ptr, template1) == 0) match = TRUE; + } + break; + case 2: + /* trailing wild card */ + if (strstr(token, template1) == token) match = TRUE; + break; + case 3: + /* trailing wild card */ + if (strstr(token, template1) != NULL) match = TRUE; + break; + } + return (match); +} +/* ---------------------------------------------------------------------- */ +int extract_bracket(char **string, char *bracket_string) +/* ---------------------------------------------------------------------- */ +{ + char *ptr, *ptr1; + + if ((ptr = strstr(*string, "{")) == NULL) return(FALSE); + strcpy(bracket_string, ptr); + if ((ptr1 = strstr(bracket_string, "}")) == NULL) { + sprintf(error_string, "No matching bracket (}) in isotope template string %s", *string); + error_msg(error_string, CONTINUE); + input_error++; + return(FALSE); + } + ptr1[1] = '\0'; + *string = strstr(*string, "}"); + *string += 1; + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +LDBLE surf_total(char *total_name, char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in LDBLE layer + */ + int i, j, k; + char name[MAX_LENGTH], token[MAX_LENGTH]; + char surface_name_local[MAX_LENGTH]; + char *ptr; + + if (use.surface_ptr == NULL) return(0); + +/* + * Find surface... + */ + for (j =0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE) continue; + strcpy(token, x[j]->master[0]->elt->name); + replace ("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + if (surface_name != NULL) { + if (strcmp(name, surface_name) == 0) break; + } else { + break; + } + } + if (j >= count_unknowns) return(0); + strcpy(surface_name_local, name); +/* + * find total moles of each element in diffuse layer... + */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { + if (s_x[j]->type != SURF) continue; + for (i=0; s_x[j]->next_elt[i].elt != NULL; i++) { + strcpy(token, s_x[j]->next_elt[i].elt->name); + replace ("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + if (strcmp(name, surface_name_local) == 0) { +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, s_x[j]->moles); + break; + } + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Return totals + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + return((LDBLE) elt_list[j].coef); + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +LDBLE total (char *total_name) +/* ---------------------------------------------------------------------- */ +{ + struct master *master_ptr; + LDBLE t; + int i; + + if (strcmp_nocase(total_name,"water") == 0) { + return(mass_water_aq_x); + } + if (strcmp(total_name,"H") == 0) { + return(total_h_x/mass_water_aq_x); + } + if (strcmp(total_name,"O") == 0) { + return(total_o_x/mass_water_aq_x); + } + master_ptr = master_bsearch(total_name); + t = 0.0; + if (master_ptr == NULL) { + sprintf(error_string,"Can not find definition for master species, %s.", total_name); + warning_msg(error_string); +/* + * Primary master species + */ + } else if (master_ptr->primary == TRUE) { + /* + * Not a redox element + */ + if (master_ptr->s->secondary == NULL) { + t = master_ptr->total/mass_water_aq_x; + /* + * Redox element, need to sum totals of all redox states + */ + } else { + t = 0; + for (i = master_ptr->number + 1; master[i]->elt->primary == master_ptr; i++) { + t += master[i]->total/mass_water_aq_x; + } + } +/* + * Secondary master species + */ + } else { + t = master_ptr->total/mass_water_aq_x; + } + return(t); +} +/* ---------------------------------------------------------------------- */ +LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; + + sys_tot = 0; + count_sys = 0; + max_sys = 100; + space ((void **) ((void *) &sys), INIT, &max_sys, sizeof (struct system_species)); + if (strcmp_nocase(total_name,"elements") == 0) { + system_total_elements(); + } else if (strcmp_nocase(total_name,"phases") == 0) { + system_total_si(); + } else if (strcmp_nocase(total_name,"aq") == 0) { + system_total_aq(); + } else if (strcmp_nocase(total_name,"ex") == 0) { + system_total_ex(); + } else if (strcmp_nocase(total_name,"surf") == 0) { + system_total_surf(); + } else if (strcmp_nocase(total_name,"s_s") == 0) { + system_total_s_s(); + } else if (strcmp_nocase(total_name,"gas") == 0) { + system_total_gas(); + } else { + if (strstr(total_name,"(") == NULL) { + system_total_elt(total_name); + } else { + system_total_elt_secondary(total_name); + } + } + /* + * Sort system species + */ + if (count_sys > 1 ) { + qsort (sys, (size_t) count_sys, + (size_t) sizeof(struct system_species), system_species_compare); + } + /* + * malloc space + */ + *names = (char **) PHRQ_malloc((size_t) (count_sys+1) * sizeof (char *)); + if (names == NULL) malloc_error(); + *types = (char **) PHRQ_malloc((size_t) (count_sys+1) * sizeof (char *)); + if (types == NULL) malloc_error(); + *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys+1) * sizeof (LDBLE)); + if (moles == NULL) malloc_error(); + + (*names)[0] = NULL; + (*types)[0] = NULL; + (*moles)[0] = 0; + for(i = 0; i < count_sys; i++) { + /* output_msg(OUTPUT_MESSAGE, "%20s\t%10s\t%e\n", sys[i].name, sys[i].type, sys[i].moles); */ + (*names)[i + 1] = sys[i].name; + (*types)[i + 1] = sys[i].type; + (*moles)[i + 1] = sys[i].moles; + } + *count = (LDBLE) count_sys; + PHRQ_free(sys); + if (strcmp_nocase(total_name,"elements") == 0) { + sys_tot = 0;; + for (i = 0; i < count_sys; i++) { + if (strcmp(sys[i].type,"dis") == 0 && + strstr(sys[i].name,"(") == NULL && + strcmp(sys[i].name,"H") != 0 && + strcmp(sys[i].name,"O") != 0) { + sys_tot += sys[i].moles; + } + } + } + return(sys_tot); +} +/* ---------------------------------------------------------------------- */ +int system_total_elements(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE t; + char name[MAX_LENGTH]; + struct master *master_ptr; + + /* + * Include H and O + */ + sys[count_sys].name = string_duplicate("H"); + sys[count_sys].moles = total_h_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + sys[count_sys].name = string_duplicate("O"); + sys[count_sys].moles = total_o_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + /* + * Include H(1) and O(-2) + */ + sys[count_sys].name = string_duplicate("H(1)"); + sys[count_sys].moles = solution_sum_secondary("H(1)"); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + sys[count_sys].name = string_duplicate("O(-2)"); + sys[count_sys].moles = solution_sum_secondary("O(-2)"); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + + for (i = 0; i < count_master; i++) { + master_ptr=master[i]; + if (master_ptr->primary == TRUE && master_ptr->total_primary <= 0) continue; + if (master_ptr->in == FALSE && (master_ptr->primary == FALSE || master_ptr->total_primary == 0)) continue; + /* + * H and O + */ + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } + if (master_ptr->primary == TRUE) { + if (master_ptr->total_primary > 0) { + t = master_ptr->total_primary; + /* + * Not a redox element + */ + } else if (master_ptr->s->secondary == NULL) { + t = master_ptr->total; + /* + * Redox element, need to sum totals of all redox states + */ + } else { + t = 0; + for (j = master_ptr->number + 1; master[j]->elt->primary == master_ptr; j++) { + t += master[j]->total; + } + } + /* + * Secondary master species + */ + } else { + t = master_ptr->total; + } + strcpy(name, master[i]->elt->name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = t; + sys_tot += sys[count_sys].moles; + if (master[i]->s->type <= SOLID) { + sys[count_sys].type = string_duplicate("dis"); + } else if (master[i]->s->type == EX) { + sys[count_sys].type = string_duplicate("ex"); + } else if (master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) { + sys[count_sys].type = string_duplicate("surf"); + } + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_si(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE si, iap; + struct rxn_token *rxn_ptr; + char name[MAX_LENGTH]; + + for (i=0; i < count_phases; i++) { + if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; +/* + * Print saturation index + */ + iap = 0.0; + for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si=-phases[i]->lk + iap; + /* output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, si, iap, (LDBLE) phases[i]->lk, phases[i]->formula); */ + strcpy(name, phases[i]->name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = si; + if (si > sys_tot) sys_tot = si; + sys[count_sys].type = string_duplicate("phase"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_aq(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type != AQ) continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("aq"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_ex(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type != EX) continue; + if (s_x[i]->primary != NULL) continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("ex"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_surf(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type != SURF) continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("surf"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_gas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; + +/* + * find total in gas phase + */ + if (use.gas_phase_ptr == NULL) return(OK); + for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { + sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); + sys[count_sys].moles = use.gas_phase_ptr->comps[i].phase->moles_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_s_s(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, k; + +/* + * Solid solutions + */ + if (use.s_s_assemblage_ptr == NULL) return(OK); + for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { + sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); + sys[count_sys].moles = use.s_s_assemblage_ptr->s_s[k].comps[i].moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_elt(char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j, k, count_g; + LDBLE molality, moles_excess, moles_surface, mass_water_surface; + char name[MAX_LENGTH]; + +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) { + count_elts = 0; + paren_count = 0; + add_elt_list(s_x[i]->next_elt, s_x[i]->moles); + + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + if (s_x[i]->type == AQ) { + sys[count_sys].type = string_duplicate("aq"); + } else if (s_x[i]->type == EX) { + sys[count_sys].type = string_duplicate("ex"); + } else if (s_x[i]->type == SURF) { + sys[count_sys].type = string_duplicate("surf"); + } else if (s_x[i]->type == HPLUS) { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_h_x; */ + } else if (s_x[i]->type == H2O) { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_o_x; */ + } else { + error_msg("System_total", STOP); + } + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { + /* + * Find position of component in surface charge data + */ + i = -1; + for (k = 0; k < count_unknowns; k++) { + if (x[k]->type != SURFACE_CB) continue; + i++; + /* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + mass_water_surface = x[k]->surface_charge->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { + if (s_x[j]->type > HPLUS) continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + moles_excess = mass_water_aq_x * molality * x[k]->surface_charge->g[count_g].g; + moles_surface = mass_water_surface * molality + moles_excess; + /* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Print totals + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + strcpy(name, x[k]->master[0]->elt->name); + replace ("_psi", "", name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("diff"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } +/* + * find total moles in mineral phases + */ + if (use.pp_assemblage_in == TRUE && use.pp_assemblage_ptr != NULL) { + for( i = 0; i < count_unknowns; i++) { + if (x[i]->type != PP) continue; + if (x[i]->pure_phase->add_formula != NULL) continue; + count_elts = 0; + paren_count = 0; + add_elt_list(x[i]->pure_phase->phase->next_elt, x[i]->moles); + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(x[i]->pure_phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("equi"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } +/* + * Solid solutions + */ + if (use.s_s_assemblage_ptr != NULL) { + for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { + if (use.s_s_assemblage_ptr->s_s[k].s_s_in == TRUE) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { + count_elts = 0; + paren_count = 0; + add_elt_list(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->next_elt, use.s_s_assemblage_ptr->s_s[k].comps[i].moles); + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +/* + * find total in gas phase + */ + if (use.gas_phase_ptr != NULL) { + for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { + if (use.gas_phase_ptr->comps[i].phase->in == TRUE) { + count_elts = 0; + paren_count = 0; + add_elt_list(use.gas_phase_ptr->comps[i].phase->next_elt, use.gas_phase_ptr->comps[i].phase->moles_x); + + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_total_elt_secondary(char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j, k, l, count_g; + LDBLE molality, moles_excess, moles_surface, mass_water_surface, sum, coef; + char name[MAX_LENGTH]; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) { + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) { + add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); + } else { + add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* debug + output_msg(OUTPUT_MESSAGE, "%s\n", s_x[i]->name); + for ( j=0; j < count_elts; j++ ) { + output_msg(OUTPUT_MESSAGE, "\t%10s\t%g\n", elt_list[j].elt->name, elt_list[j].coef); + } + */ + /* + * Look for element + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + if (s_x[i]->type == AQ) { + sys[count_sys].type = string_duplicate("aq"); + } else if (s_x[i]->type == EX) { + sys[count_sys].type = string_duplicate("ex"); + } else if (s_x[i]->type == SURF) { + sys[count_sys].type = string_duplicate("surf"); + } else if (s_x[i]->type == HPLUS) { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_h_x; */ + } else if (s_x[i]->type == H2O) { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_o_x; */ + } else { + error_msg("System_total", STOP); + } + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { + /* + * Find position of component in surface charge data + */ + i = -1; + for (k = 0; k < count_unknowns; k++) { + if (x[k]->type != SURFACE_CB) continue; + i++; + /* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + mass_water_surface = x[k]->surface_charge->mass_water; + sum = 0; + for (j = 0; j < count_s_x; j++) { + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) { + add_elt_list(s_x[i]->next_secondary, 1); + } else { + add_elt_list(s_x[i]->next_sys_total, 1); + } + for ( l=0; l < count_elts; l++ ) { + if (strcmp(elt_list[l].elt->name, total_name) == 0) { + coef = elt_list[l].coef; + if (s_x[j]->type > H2O) continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + moles_excess = mass_water_aq_x * molality * x[k]->surface_charge->g[count_g].g; + moles_surface = mass_water_surface * molality + moles_excess; + sum += moles_surface * coef; + break; + } + } + if (l >= count_elts) continue; + strcpy(name, x[k]->master[0]->elt->name); + replace ("_psi", "", name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = sum; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("diff"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } +/* + * find total moles in mineral phases + */ + if (use.pp_assemblage_in == TRUE && use.pp_assemblage_ptr != NULL) { + for( i = 0; i < count_unknowns; i++) { + if (x[i]->type != PP) continue; + if (x[i]->pure_phase->add_formula != NULL) continue; + count_elts = 0; + paren_count = 0; + add_elt_list(x[i]->pure_phase->phase->next_sys_total, x[i]->moles); + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* debug + output_msg(OUTPUT_MESSAGE, "%s\n", x[i]->pure_phase->phase->name); + for ( j=0; j < count_elts; j++ ) { + output_msg(OUTPUT_MESSAGE, "\t%10s\t%g\n", elt_list[j].elt->name, elt_list[j].coef); + } + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(x[i]->pure_phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("equi"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } +/* + * Solid solutions + */ + if (use.s_s_assemblage_ptr != NULL) { + for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { + if (use.s_s_assemblage_ptr->s_s[k].s_s_in == TRUE) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { + count_elts = 0; + paren_count = 0; + add_elt_list(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->next_sys_total, use.s_s_assemblage_ptr->s_s[k].comps[i].moles); + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +/* + * find total in gas phase + */ + if (use.gas_phase_ptr != NULL) { + for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { + if (use.gas_phase_ptr->comps[i].phase->in == TRUE) { + count_elts = 0; + paren_count = 0; + add_elt_list(use.gas_phase_ptr->comps[i].phase->next_sys_total, use.gas_phase_ptr->comps[i].phase->moles_x); + + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE solution_sum_secondary(char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j; + LDBLE sum; +/* + * find total moles in aq, surface, and exchange + */ + sum = 0; + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type > H2O) continue; + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) { + add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); + } else { + add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for ( j=0; j < count_elts; j++ ) { + if (strcmp(elt_list[j].elt->name, total_name) == 0) { + sum += elt_list[j].coef; + break; + } + } + } + return(sum); +} +/* ---------------------------------------------------------------------- */ +int system_species_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct system_species *a, *b; + + a=(const struct system_species *) ptr1; + b=(const struct system_species *) ptr2; + if (a->moles < b->moles) return(1); + if (a->moles > b->moles) return(-1); + return(0); +} + +/* ---------------------------------------------------------------------- */ +int system_total_solids(struct exchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in solid phases + */ + int i, j; + + count_elts = 0; + paren_count = 0; +/* + * find total moles in exchanger + */ + if (exchange_ptr != NULL) { + for( i = 0; i < exchange_ptr->count_comps; i++) { + add_elt_list(exchange_ptr->comps[i].totals, 1.0); + } + } + if (surface_ptr != NULL) { + for( i = 0; i < surface_ptr->count_comps; i++) { + add_elt_list(surface_ptr->comps[i].totals, 1.0); + } + } + if (s_s_assemblage_ptr != NULL) { + for( i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { + for (j = 0; j < s_s_assemblage_ptr->s_s[i].count_comps; j++) { + add_elt_list(s_s_assemblage_ptr->s_s[i].comps[j].phase->next_elt, s_s_assemblage_ptr->s_s[i].comps[j].moles); + } + } + } + if (gas_phase_ptr != NULL) { + for( i = 0; i < gas_phase_ptr->count_comps; i++) { + add_elt_list(gas_phase_ptr->comps[i].phase->next_elt, gas_phase_ptr->comps[i].moles); + } + } + if (pp_assemblage_ptr != NULL) { + for( i = 0; i < pp_assemblage_ptr->count_comps; i++) { + add_elt_list(pp_assemblage_ptr->pure_phases[i].phase->next_elt, pp_assemblage_ptr->pure_phases[i].moles); + } + } + + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + return(OK); +} diff --git a/char_star.h b/char_star.h new file mode 100644 index 00000000..9d5b65f5 --- /dev/null +++ b/char_star.h @@ -0,0 +1,11 @@ +#if !defined(CHARSTAR_H_INCLUDED) +#define CHARSTAR_H_INCLUDED + +struct CHARSTAR_LESS : std::binary_function { +bool operator()(const char* _X, const char* _Y) const +{ + return ::strcmp( _X, _Y) < 0;} +}; + +#endif + diff --git a/cl1.cpp b/cl1.cpp new file mode 100644 index 00000000..93fc89e7 --- /dev/null +++ b/cl1.cpp @@ -0,0 +1,753 @@ +#include +#include +#include +#include + +/* must be defined here and in global.h */ +#if !defined(WIN32_MEMORY_DEBUG) +#define USE_PHRQ_ALLOC +#endif +#include "phqalloc.h" +#include "output.h" +#include "phrqtype.h" + +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q, + int *kode, LDBLE toler, + int *iter, LDBLE *x, LDBLE *res, LDBLE *error, + LDBLE *cu, int *iu, int *s, + int check); +static char const svnid[] = "$Id: cl1.c 248 2005-04-14 17:10:53Z dlpark $"; + +extern void *free_check_null(void *ptr); +extern void malloc_error(void); + +/* debug +#define DEBUG_CL1 +#define CHECK_ERRORS + */ + +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q, + int *kode, LDBLE toler, + int *iter, LDBLE *x, LDBLE *res, LDBLE *error, + LDBLE *cu, int *iu, int *s, int check) +{ + /* System generated locals */ + LDBLE *scratch; + union double_or_int {int ival; LDBLE dval;} *q2; + + /* Local variables */ + static int nklm; + static LDBLE xmin, xmax; + static int iout, i, j; + static LDBLE z; + static int maxit, n1, n2; + static LDBLE pivot; + static int ia, ii, kk, in, nk, js; + static LDBLE sn; + static int iphase, kforce; + static LDBLE zu, zv; + static LDBLE tpivot; + static int klm, jmn, nkl, jpn; + static LDBLE cuv, sum; + static int klm1; + int q_dim, cu_dim; + int kode_arg; + LDBLE *x_arg, *res_arg, check_toler; +#ifdef CHECK_ERRORS + extern char **col_name, **row_name; + extern int *row_back, *col_back; +#endif +/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ +/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ +/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ +/* AX=B */ +/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ +/* CX=D */ +/* AND M LINEAR INEQUALITY CONSTRAINTS */ +/* EX.LE.F. */ +/* DESCRIPTION OF PARAMETERS */ +/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ +/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ +/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ +/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ +/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ +/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ +/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ +/* AT LEAST N2D COLUMNS. */ +/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ +/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ +/* AND N+1 COLUMNS OF Q AS FOLLOWS */ +/* A B */ +/* Q = C D */ +/* E F */ +/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ +/* KODE A CODE USED ON ENTRY TO, AND EXIT */ +/* FROM, THE SUBROUTINE. */ +/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ +/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ +/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ +/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ +/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ +/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ +/* RES (SEE BELOW). */ +/* ON EXIT, KODE HAS ONE OF THE */ +/* FOLLOWING VALUES */ +/* 0- OPTIMAL SOLUTION FOUND, */ +/* 1- NO FEASIBLE SOLUTION TO THE */ +/* CONSTRAINTS, */ +/* 2- CALCULATIONS TERMINATED */ +/* PREMATURELY DUE TO ROUNDING ERRORS, */ +/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ +/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ +/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ +/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ +/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ +/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ +/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ +/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ +/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ +/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ +/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ +/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ +/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ +/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ +/* ON EXIT THIS ARRAY CONTAINS A */ +/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ +/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ +/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ +/* VARIABLES. THE VALUES -1, 0, OR 1 */ +/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ +/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ +/* OR .GE.0 RESPECTIVELY. */ +/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ +/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ +/* IN THE FIRST K COMPONENTS, D-CX IN THE */ +/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ +/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ +/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ +/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ +/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ +/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ +/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ +/* RESPECTIVELY. */ +/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ +/* ABSOLUTE VALUES OF THE RESIDUALS. */ +/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ +/* WORKSPACE. */ +/* DOUBLE PRECISION DBLE */ +/* REAL */ + +/* INITIALIZATION. */ + if (svnid == NULL) fprintf(stderr," "); + + + zv = 0; + kode_arg = *kode; + x_arg = NULL; + res_arg = NULL; + if (check == 1) { + /* + q_arg = PHRQ_malloc((size_t) (max_row_count * max_column_count * sizeof(LDBLE))); + if (q_arg == NULL) malloc_error(); + for (i = 0; i < max_row_count*max_column_count; i++) { + q_arg[i] = q[i]; + } + */ + x_arg = (double *) PHRQ_malloc((size_t) (n2d * sizeof(LDBLE))); + if (x_arg == NULL) malloc_error(); + for (i = 0; i < n2d; i++) { + x_arg[i] = x[i]; + } + res_arg = (double *) PHRQ_malloc((size_t) ((k + l + m) * sizeof(LDBLE))); + if (res_arg == NULL) malloc_error(); + for (i = 0; i < k + l + m; i++) { + res_arg[i] = res[i]; + } + } +/* Parameter adjustments */ + q_dim = n2d; + q2 = (union double_or_int *) q; + cu_dim = nklmd; + +/* Function Body */ + maxit = *iter; + n1 = n + 1; + n2 = n + 2; + nk = n + k; + nkl = nk + l; + klm = k + l + m; + klm1 = klm + 1; + nklm = n + klm; + kforce = 1; + *iter = 0; + js = 0; + ia = -1; +/* Make scratch space */ + scratch = (LDBLE *) PHRQ_malloc( (size_t) nklmd * sizeof(LDBLE)); + if (scratch == NULL) malloc_error(); + for (i=0; i < nklmd; i++) { + scratch[i] = 0.0; + } +/* SET UP LABELS IN Q. */ + for (j = 0; j < n; ++j) { + q2[ klm1 * q_dim + j ].ival = j + 1; + } +/* L10: */ + for (i = 0; i < klm; ++i) { + q2[ i * q_dim + n1 ].ival = n + i + 1; + if (q2[ i * q_dim + n ].dval < 0.) { + for (j = 0; j < n1; ++j) { + q2[ i * q_dim + j ].dval = -q2[ i * q_dim + j ].dval; + } + q2[ i * q_dim + n1 ].ival = -q2[ i * q_dim + n1 ].ival; +/* L20: */ + } + } +/* L30: */ +/* SET UP PHASE 1 COSTS. */ + iphase = 2; +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Set up phase 1 costs\n"); +#endif +/* Zero first row of cu and iu */ + memcpy( (void *) &(cu[0]), (void *) &(scratch[0]), + (size_t) nklm * sizeof(LDBLE) ); + for (j = 0; j < nklm; ++j) { + iu[ j ] = 0; + } +/* L40: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L40\n"); +#endif + if (l != 0) { + for (j = nk; j < nkl; ++j) { + cu[ j ] = 1.; + iu[ j ] = 1; + } +/* L50: */ + iphase = 1; + } + +/* Copy first row of cu and iu to second row */ + memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), + (size_t) nklm * sizeof(LDBLE) ); + memcpy( (void *) &(iu[cu_dim]), (void *) &(iu[0]), + (size_t) nklm * sizeof(int) ); + +/* L60: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L60\n"); +#endif + if (m != 0) { + for (j = nkl; j < nklm; ++j) { + cu[ cu_dim + j ] = 1.; + iu[ cu_dim + j ] = 1; + jmn = j - n; + if (q2[ jmn * q_dim + n1 ].ival < 0) { + iphase = 1; + } + } +/* L70: */ + } +/* L80: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L80\n"); +#endif + if (*kode != 0) { + for (j = 0; j < n; ++j) { + if ( x[j] < 0.) { +/* L90: */ + cu[ j ] = 1.; + iu[ j ] = 1; + } else if (x[j] > 0.) { + cu[ cu_dim + j ] = 1.; + iu[ cu_dim + j ] = 1; + } + } +/* L110: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L110\n"); +#endif + for (j = 0; j < k; ++j) { + jpn = j + n; + if ( res[j] < 0.) { +/* L120: */ + cu[ jpn ] = 1.; + iu[ jpn ] = 1; + if (q2[ j * q_dim + n1 ].ival > 0) { + iphase = 1; + } + } else if (res[j] > 0.) { +/* L130: */ + cu[ cu_dim + jpn ] = 1.; + iu[ cu_dim + jpn ] = 1; + if (q2[ j * q_dim + n1 ].ival < 0) { + iphase = 1; + } + } + } +/* L140: */ + } +/* L150: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L150\n"); +#endif + if (iphase == 2) { + goto L500; + } +/* COMPUTE THE MARGINAL COSTS. */ +L160: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L160\n"); +#endif + for (j = js; j < n1; ++j) { + sum = 0.; + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + if (ii < 0) { + z = cu[ cu_dim - ii - 1 ]; + } else { + z = cu[ ii - 1 ]; + } + sum += q2[ i * q_dim + j ].dval * z; + } + q2[ klm * q_dim + j ].dval = sum; + } + for (j = js; j < n; ++j) { + ii = q2[ klm1 * q_dim + j].ival; + if (ii < 0) { + z = cu[ cu_dim - ii - 1 ]; + } else { + z = cu[ ii - 1 ]; + } + q2[ klm * q_dim + j ].dval -= z; + } +/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ +L240: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L240, xmax %e\n", xmax); +#endif + xmax = 0.; + if (js >= n) { + goto L490; /* test for optimality */ + } + for (j = js; j < n; ++j) { + zu = q2[ klm * q_dim + j ].dval; + ii = q2[ klm1 * q_dim + j ].ival; + if (ii > 0) { + zv = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; + } else { + ii = -ii; + zv = zu; + zu = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; + } +/* L260 */ + if (kforce == 1 && ii > n) { + continue; + } + if (iu[ ii - 1 ] != 1 && zu > xmax){ + xmax = zu; + in = j; + } +/* L270 */ + if (iu[ cu_dim + ii - 1 ] != 1 && zv > xmax ) { + xmax = zv; + in = j; + } + } +/* L280 */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L280 xmax %e, toler %e\n", xmax, toler); +#endif + if (xmax <= toler) { +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "xmax before optimality test %e\n",xmax); +#endif + goto L490; /* test for optimality */ + } + if (q2[ klm * q_dim + in ].dval != xmax) { + for (i = 0; i < klm1; ++i) { + q2[ i * q_dim + in ].dval = -q2[ i * q_dim + in ].dval; + } + q2[ klm1 * q_dim + in ].ival = -q2[ klm1 * q_dim + in ].ival; +/* L290: */ + q2[ klm * q_dim + in ].dval = xmax; + } +/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ + if (iphase != 1 && ia != -1) { + xmax = 0.; +/* find maximum absolute value in column "in" */ + for (i = 0; i <= ia; ++i) { + z = fabs(q2[ i * q_dim + in ].dval); + if (z > xmax) { + xmax = z; + iout = i; + } + } +/* L310: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L310, xmax %e\n", xmax); +#endif +/* switch row ia with row iout, use memcpy */ + if (xmax > toler) { + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ iout * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ iout * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(LDBLE) ); +/* L320: */ +/* set pivot to row ia, column in */ + iout = ia; + --ia; + pivot = q2[ iout * q_dim + in ].dval; + goto L420; /* Gauss Jordan */ + } + } +/* L330: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L330, xmax %e\n", xmax); +#endif + kk = -1; +/* divide column n1 by positive value in column "in" greater than toler */ + for (i = 0; i < klm; ++i) { + z = q2[ i * q_dim + in ].dval; + if (z > toler) { + ++kk; + res[kk] = q2[ i * q_dim + n ].dval / z; + s[kk] = i; + } + } +/* L340: */ +#ifdef DEBUG_CL1 + if (kk < 0) { + output_msg(OUTPUT_MESSAGE, "kode = 2 in loop 340.\n"); + } +#endif +L350: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L350, xmax %e\n", xmax); +#endif + if (kk < 0) { +/* no positive value found in L340 or bypass intermediate verticies */ + *kode = 2; + goto L590; + } +/* L360: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L360, xmax %e\n", xmax); +#endif +/* find minimum residual */ + xmin = res[ 0 ]; + iout = s[ 0 ]; + j = 0; + if (kk != 0) { + for (i = 1; i <= kk; ++i) { + if (res[i] < xmin) { + j = i; + xmin = res[i]; + iout = s[i]; + } + } +/* L370: */ +/* put kk in position j */ + res[j] = res[kk]; + s[j] = s[kk]; + } +/* L380: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L380 iout %d, xmin %e, xmax %e\n", iout, xmin, xmax); +#endif + --kk; + pivot = q2[ iout * q_dim + in ].dval; + ii = q2[ iout * q_dim + n1 ].ival; + if (iphase != 1) { + if (ii < 0) { +/* L390: */ + if (iu[ - ii - 1 ] == 1) { + goto L420; + } + } else { + if (iu[ cu_dim + ii - 1 ] == 1) { + goto L420; + } + } + } +/* L400: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L400\n"); +#endif + ii = abs(ii); + cuv = cu[ ii - 1 ] + cu[ cu_dim + ii - 1]; + if (q2[ klm * q_dim + in ].dval - pivot * cuv > toler) { + +/* BYPASS INTERMEDIATE VERTICES. */ + for (j = js; j < n1; ++j) { + z = q2[ iout * q_dim + j ].dval; + q2[ klm * q_dim + j ].dval -= z * cuv; + q2[ iout * q_dim + j ].dval = -z; + } +/* L410: */ + q2[ iout * q_dim + n1 ].ival = -q2[ iout * q_dim + n1 ].ival; + goto L350; + } +/* GAUSS-JORDAN ELIMINATION. */ +L420: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Gauss Jordon %d\n", *iter); +#endif + if (*iter >= maxit) { + *kode = 3; + goto L590; + } +/* L430: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L430\n"); +#endif + ++(*iter); + for (j = js; j < n1; ++j) { + if (j != in) { + q2[ iout * q_dim + j ].dval /= pivot; + } + } +/* L440: */ + for (j = js; j < n1; ++j) { + if (j != in) { + z = -q2[ iout * q_dim + j ].dval; + for (i = 0; i < klm1; ++i) { + if (i != iout) { + q2[ i * q_dim + j ].dval += z * q2[ i * q_dim + in ].dval; + } + } +/* L450: */ + } + } +/* L460: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L460\n"); +#endif + tpivot = -pivot; + for (i = 0; i < klm1; ++i) { + if (i != iout) { + q2[ i * q_dim + in ].dval /= tpivot; + } + } +/* L470: */ + q2[ iout * q_dim + in ].dval = 1. / pivot; + ii = q2[ iout * q_dim + n1 ].ival; + q2[ iout * q_dim + n1 ].ival = q2[ klm1 * q_dim + in ].ival; + q2[ klm1 * q_dim + in ].ival = ii; + ii = abs(ii); + if (iu[ ii - 1 ] == 0 || iu[ cu_dim + ii - 1 ] == 0) { + goto L240; + } +/* switch column */ + for (i = 0; i < klm1; ++i) { + z = q2[ i * q_dim + in ].dval; + q2[ i * q_dim + in ].dval = q2[ i * q_dim + js ].dval; + q2[ i * q_dim + js ].dval = z; + } + i = q2[ klm1 * q_dim + in ].ival; + q2[ klm1 * q_dim + in ].ival = q2[ klm1 * q_dim + js ].ival; + q2[ klm1 * q_dim + js ].ival = i; +/* L480: */ + ++js; + goto L240; +/* TEST FOR OPTIMALITY. */ +L490: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L490\n"); +#endif + if (kforce == 0) { + if (iphase == 1) { + if (q2[ klm * q_dim + n ].dval <= toler) { + goto L500; + } +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE,"q2[klm1-1, n1-1] > *toler. %e\n",q2[ ( klm1 - 1 ) * q_dim + n1 - 1 ].dval); +#endif + *kode = 1; + goto L590; + } + *kode = 0; + goto L590; + } + if (iphase != 1 || q2[ klm * q_dim + n ].dval > toler) { + kforce = 0; + goto L240; + } +/* SET UP PHASE 2 COSTS. */ +L500: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Set up phase 2 costs %d\n", *iter); +#endif + iphase = 2; + for (j = 0; j < nklm; ++j) { + cu[ j ] = 0.; + } +/* L510: */ + for (j = n; j < nk; ++j) { + cu[ j ] = 1.; + } + memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), + (size_t) nklm * sizeof(LDBLE) ); +/* L520: */ + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + if (ii <= 0) { + if (iu[ cu_dim - ii - 1 ] == 0) { + continue; + } + cu[ cu_dim - ii - 1 ] = 0.; + } else { +/* L530: */ + if (iu[ ii - 1 ] == 0) { + continue; + } + cu[ ii - 1 ] = 0.; + } +/* L540: */ + ++ia; +/* switch row */ + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ i * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ i * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(LDBLE) ); +/* L550: */ + } +/* L560: */ + goto L160; + + +/* PREPARE OUTPUT. */ +L590: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L590\n"); +#endif + sum = 0.; + for (j = 0; j < n; ++j) { + x[j] = 0.; + } +/* L600: */ + for (i = 0; i < klm; ++i) { + res[i] = 0.; + } +/* L610: */ + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + sn = 1.; + if (ii < 0) { + ii = -ii; + sn = -1.; + } + if (ii <= n) { +/* L620: */ + x[ii - 1] = sn * q2[ i * q_dim + n ].dval; + } else { +/* L630: */ + res[ii - n - 1] = sn * q2[ i * q_dim + n ].dval; + if (ii >= n1 && ii <= nk ) { +/* * DBLE(Q(I,N1)) */ + sum += q2[ i * q_dim + n ].dval; + } + } + } +/* L640: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L640\n"); +#endif + *error = sum; + scratch = (double *) free_check_null (scratch); + /* + * Check calculation + */ + if ((check == 1) && (*kode == 0)) { + check_toler = 10.*toler; + /* + * Check optimization constraints + */ + if (kode_arg == 1) { + for (i = 0; i < k; i++) { + if (res_arg[i] < 0.0) { + if (res[i] > check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: optimization constraint not satisfied row %d, res %s, constraint %f.\n", row_name[row_back[i]], res[i], res_arg[i]); +#endif + *kode = 1; + } + } else if (res_arg[i] > 0.0) { + if (res[i] < -check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: optimization constraint not satisfied row %s, res %e, constraint %f.\n", row_name[row_back[i]], res[i], res_arg[i]); +#endif + *kode = 1; + } + } + } + } + /* + * Check equalities + */ + for (i = k; i < k + l; i++) { + if (fabs(res[i]) > check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: equality constraint not satisfied row %s, res %e, tolerance %e.\n", row_name[row_back[i]], res[i], check_toler); +#endif + *kode = 1; + } + } + /* + * Check inequalities + */ + for (i = k + l; i < k + l + m; i++) { + if (res[i] < -check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: inequality constraint not satisfied row %s, res %e, tolerance %e.\n", row_name[row_back[i]], res[i], check_toler); +#endif + *kode = 1; + } + } + /* + * Check dissolution/precipitation constraints + */ + if (kode_arg == 1) { + for (i = 0; i < n; i++) { + if (x_arg[i] < 0.0) { + if (x[i] > check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", col_name[col_back[i]], x[i], x_arg[i]); +#endif + *kode = 1; + } + } else if (x_arg[i] > 0.0) { + if (x[i] < -check_toler) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", col_name[col_back[i]], x[i], x_arg[i]); +#endif + *kode = 1; + } + } + } + } + if (*kode == 1) { + output_msg(OUTPUT_MESSAGE, "\n\tCL1: Roundoff errors in optimization.\n\t Try using -multiple_precision in INVERSE_MODELING\n"); + } + } + if (check == 1) { + x_arg = (double *) free_check_null(x_arg); + res_arg = (double *) free_check_null(res_arg); + } + return 0; +} diff --git a/cl1mp.cpp b/cl1mp.cpp new file mode 100644 index 00000000..ca15c0bb --- /dev/null +++ b/cl1mp.cpp @@ -0,0 +1,974 @@ +#include +#include +#include +#include +#include + +/* must be defined here and in global.h */ +#if !defined(WIN32_MEMORY_DEBUG) +#define USE_PHRQ_ALLOC +#endif +#include "phqalloc.h" +#include "output.h" +#include "phrqtype.h" + +extern int max_row_count, max_column_count; +static char const svnid[] = "$Id: cl1mp.c 78 2005-02-01 22:47:12Z dlpark $"; + +int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error, + LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg); +extern void *free_check_null(void *ptr); +extern void malloc_error(void); + +/* debug +#define DEBUG_CL1 +#define CHECK_ERRORS + */ + + +int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q_arg, + int *kode_arg, LDBLE toler_arg, + int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error_arg, + LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg) +{ + /* System generated locals */ + union double_or_int {int ival; mpf_t dval;} *q2; + + /* Local variables */ + static int nklm; + static int iout, i, j; + static int maxit, n1, n2; + static int ia, ii, kk, in, nk, js; + static int iphase, kforce; + static int klm, jmn, nkl, jpn; + static int klm1; + static int *kode; + int q_dim, cu_dim; + int iswitch; + mpf_t *q; + mpf_t *x; + mpf_t *res; + mpf_t error; + mpf_t *cu; + mpf_t dummy, dummy1, sum, z, zu, zv, xmax, minus_one, toler, check_toler; + /*mpf_t *scratch;*/ + mpf_t pivot, xmin, cuv, tpivot, sn; + mpf_t zero; + int censor; + mpf_t censor_tol; +/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ +/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ +/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ +/* AX=B */ +/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ +/* CX=D */ +/* AND M LINEAR INEQUALITY CONSTRAINTS */ +/* EX.LE.F. */ +/* DESCRIPTION OF PARAMETERS */ +/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ +/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ +/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ +/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ +/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ +/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ +/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ +/* AT LEAST N2D COLUMNS. */ +/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ +/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ +/* AND N+1 COLUMNS OF Q AS FOLLOWS */ +/* A B */ +/* Q = C D */ +/* E F */ +/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ +/* KODE A CODE USED ON ENTRY TO, AND EXIT */ +/* FROM, THE SUBROUTINE. */ +/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ +/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ +/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ +/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ +/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ +/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ +/* RES (SEE BELOW). */ +/* ON EXIT, KODE HAS ONE OF THE */ +/* FOLLOWING VALUES */ +/* 0- OPTIMAL SOLUTION FOUND, */ +/* 1- NO FEASIBLE SOLUTION TO THE */ +/* CONSTRAINTS, */ +/* 2- CALCULATIONS TERMINATED */ +/* PREMATURELY DUE TO ROUNDING ERRORS, */ +/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ +/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ +/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ +/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ +/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ +/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ +/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ +/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ +/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ +/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ +/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ +/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ +/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ +/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ +/* ON EXIT THIS ARRAY CONTAINS A */ +/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ +/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ +/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ +/* VARIABLES. THE VALUES -1, 0, OR 1 */ +/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ +/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ +/* OR .GE.0 RESPECTIVELY. */ +/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ +/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ +/* IN THE FIRST K COMPONENTS, D-CX IN THE */ +/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ +/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ +/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ +/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ +/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ +/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ +/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ +/* RESPECTIVELY. */ +/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ +/* ABSOLUTE VALUES OF THE RESIDUALS. */ +/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ +/* WORKSPACE. */ +/* DOUBLE PRECISION DBLE */ +/* REAL */ + +/* INITIALIZATION. */ + if (svnid == NULL) fprintf(stderr," "); + /* + * mp variables + */ + censor = 1; + if (censor_arg == 0.0) censor = 0; + mpf_set_default_prec(96); + mpf_init(zero); + mpf_init(dummy); + mpf_init(dummy1); + mpf_init_set_d(censor_tol, censor_arg); + q = (mpf_t *) PHRQ_malloc((size_t) (max_row_count * max_column_count * sizeof(mpf_t))); + if (q == NULL) malloc_error(); + for (i = 0; i < max_row_count*max_column_count; i++) { + mpf_init_set_d(q[i], q_arg[i]); + if (censor == 1) { + if (mpf_cmp(q[ i ], zero) != 0) { + mpf_abs(dummy1, q[ i ]); + if (mpf_cmp(dummy1, censor_tol) <= 0) { + mpf_set_si(q[ i ], 0); + } + } + } + } + x = (mpf_t *) PHRQ_malloc((size_t) (n2d * sizeof(mpf_t))); + if (x == NULL) malloc_error(); + for (i = 0; i < n2d; i++) { + mpf_init_set_d (x[i], x_arg[i]); + } + res = (mpf_t *) PHRQ_malloc((size_t) ((k + l + m) * sizeof(mpf_t))); + if (res == NULL) malloc_error(); + for (i = 0; i < k + l + m; i++) { + mpf_init_set_d (res[i], res_arg[i]); + } + cu = (mpf_t *) PHRQ_malloc((size_t) (2*nklmd * sizeof(mpf_t))); + if (cu == NULL) malloc_error(); + for (i = 0; i < 2*nklmd; i++) { + mpf_init_set_d (cu[i], cu_arg[i]); + } + kode = (int *) PHRQ_malloc(sizeof(int)); + if (kode == NULL) malloc_error(); + *kode = *kode_arg; + mpf_init(sum); + mpf_init(error); + mpf_init(z); + mpf_init(zu); + mpf_init(zv); + mpf_init(xmax); + mpf_init_set_si(minus_one, -1); + mpf_init_set_d(toler, toler_arg); + mpf_init_set_d(check_toler, toler_arg); + mpf_init(pivot); + mpf_init(xmin); + mpf_init(cuv); + mpf_init(tpivot); + mpf_init(sn); +/* Parameter adjustments */ + q_dim = n2d; + q2 = (union double_or_int *) q; + cu_dim = nklmd; + +/* Function Body */ + maxit = *iter; + n1 = n + 1; + n2 = n + 2; + nk = n + k; + nkl = nk + l; + klm = k + l + m; + klm1 = klm + 1; + nklm = n + klm; + kforce = 1; + *iter = 0; + js = 0; + ia = -1; +/* Make scratch space */ +/* + scratch = (LDBLE *) PHRQ_malloc( (size_t) nklmd * sizeof(LDBLE)); + if (scratch == NULL) malloc_error(); + for (i=0; i < nklmd; i++) { + scratch[i] = 0.0; + } +*/ +/* + scratch = (mpf_t *) PHRQ_malloc( (size_t) nklmd * sizeof(mpf_t)); + if (scratch == NULL) malloc_error(); + for (i=0; i < nklmd; i++) { + mpf_init(scratch[i]); + } +*/ +/* SET UP LABELS IN Q. */ + for (j = 0; j < n; ++j) { + q2[ klm1 * q_dim + j ].ival = j + 1; + } +/* L10: */ + for (i = 0; i < klm; ++i) { + q2[ i * q_dim + n1 ].ival = n + i + 1; + if (mpf_cmp_d(q2[ i * q_dim + n ].dval, 0.0) < 0) { + for (j = 0; j < n1; ++j) { + /* q2[ i * q_dim + j ].dval = -q2[ i * q_dim + j ].dval; */ + mpf_neg(q2[ i * q_dim + j ].dval, q2[ i * q_dim + j ].dval); + } + q2[ i * q_dim + n1 ].ival = -q2[ i * q_dim + n1 ].ival; +/* L20: */ + } + } +/* L30: */ +/* SET UP PHASE 1 COSTS. */ + iphase = 2; +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Set up phase 1 costs\n"); +#endif +/* Zero first row of cu and iu */ + /*memcpy( (void *) &(cu[0]), (void *) &(scratch[0]), (size_t) nklm * sizeof(mpf_t) );*/ + for (j = 0; j < nklm; ++j) { + mpf_set_si(cu[j], 0); + iu[ j ] = 0; + } +/* L40: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L40\n"); +#endif + if (l != 0) { + for (j = nk; j < nkl; ++j) { + mpf_set_si(cu[j], 1); + /*cu[ j ] = 1.;*/ + iu[ j ] = 1; + } +/* L50: */ + iphase = 1; + } + +/* Copy first row of cu and iu to second row */ + /*memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(mpf_t) );*/ + for (i = 0; i < nklm; i++) { + mpf_set(cu[cu_dim + i], cu[i]); + } + memcpy( (void *) &(iu[cu_dim]), (void *) &(iu[0]), (size_t) nklm * sizeof(int) ); +/* L60: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L60\n"); +#endif + if (m != 0) { + for (j = nkl; j < nklm; ++j) { + /* cu[ cu_dim + j ] = 1.;*/ + mpf_set_si(cu[cu_dim + j], 1); + iu[ cu_dim + j ] = 1; + jmn = j - n; + if (q2[ jmn * q_dim + n1 ].ival < 0) { + iphase = 1; + } + } +/* L70: */ + } +/* L80: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L80\n"); +#endif + if (*kode != 0) { + for (j = 0; j < n; ++j) { + /* if ( x[j] < 0.) { */ + if (mpf_cmp_si(x[j], 0) < 0) { +/* L90: */ + /* cu[ j ] = 1.;*/ + mpf_set_si(cu[j], 1); + iu[ j ] = 1; + /* } else if (x[j] > 0.) {*/ + } else if (mpf_cmp_si(x[j], 0) > 0) { + /* cu[ cu_dim + j ] = 1.; */ + mpf_set_si(cu[cu_dim + j], 1); + iu[ cu_dim + j ] = 1; + } + } +/* L110: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L110\n"); +#endif + for (j = 0; j < k; ++j) { + jpn = j + n; + /* if (res[j] < 0.) { */ + if (mpf_cmp_si(res[j], 0) < 0) { +/* L120: */ + /* cu[ jpn ] = 1.;*/ + mpf_set_si(cu[jpn], 1); + iu[ jpn ] = 1; + if (q2[ j * q_dim + n1 ].ival > 0) { + iphase = 1; + } + /* } else if (res[j] > 0.) { */ + } else if (mpf_cmp_si(res[j], 0) > 0) { +/* L130: */ + /* cu[ cu_dim + jpn ] = 1.;*/ + mpf_set_si(cu[cu_dim + jpn], 1); + iu[ cu_dim + jpn ] = 1; + if (q2[ j * q_dim + n1 ].ival < 0) { + iphase = 1; + } + } + } +/* L140: */ + } +/* L150: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L150\n"); +#endif + if (iphase == 2) { + goto L500; + } +/* COMPUTE THE MARGINAL COSTS. */ +L160: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L160\n"); +#endif + for (j = js; j < n1; ++j) { + mpf_set_si(sum, 0); + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + if (ii < 0) { + /* z = cu[ cu_dim - ii - 1 ];*/ + mpf_set(z, cu[ cu_dim - ii - 1 ]); + } else { + /*z = cu[ ii - 1 ];*/ + mpf_set(z, cu[ ii - 1 ]); + } + /*sum += q2[ i * q_dim + j ].dval * z;*/ + mpf_mul(dummy, q2[ i * q_dim + j ].dval, z); + mpf_add(sum, sum, dummy); + } + /*q2[ klm * q_dim + j ].dval = sum;*/ + mpf_set(q2[ klm * q_dim + j ].dval, sum); + } + for (j = js; j < n; ++j) { + ii = q2[ klm1 * q_dim + j].ival; + if (ii < 0) { + /*z = cu[ cu_dim - ii - 1 ];*/ + mpf_set(z, cu[ cu_dim - ii - 1 ]); + } else { + /*z = cu[ ii - 1 ];*/ + mpf_set(z, cu[ ii - 1 ]); + } + /*q2[ klm * q_dim + j ].dval -= z;*/ + mpf_sub(q2[ klm * q_dim + j ].dval, q2[ klm * q_dim + j ].dval, z); + } +/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ +L240: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L240, xmax %e\n", mpf_get_d(xmax)); +#endif + /*xmax = 0.;*/ + mpf_set_si(xmax, 0); + if (js >= n) { + goto L490; /* test for optimality */ + } + for (j = js; j < n; ++j) { + /*zu = q2[ klm * q_dim + j ].dval;*/ + mpf_set(zu, q2[ klm * q_dim + j ].dval); + ii = q2[ klm1 * q_dim + j ].ival; + if (ii > 0) { + /*zv = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ];*/ + mpf_mul(dummy, cu[ cu_dim + ii - 1 ], minus_one); + mpf_sub(dummy, dummy, cu[ ii - 1 ]); + mpf_sub(zv, dummy, zu); + } else { + ii = -ii; + /* zv = zu; */ + mpf_set(zv, zu); + /* zu = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; */ + mpf_mul(dummy, cu[ cu_dim + ii - 1 ], minus_one); + mpf_sub(dummy, dummy, cu[ ii - 1 ]); + mpf_sub(zu, dummy, zu); + } +/* L260 */ + if (kforce == 1 && ii > n) { + continue; + } + /*if (iu[ ii - 1 ] != 1 && zu > xmax){*/ + if ((iu[ ii - 1 ] != 1) && (mpf_cmp(zu, xmax) > 0)) { + /*xmax = zu;*/ + mpf_set(xmax, zu); + in = j; + } +/* L270 */ + /*if (iu[ cu_dim + ii - 1 ] != 1 && zv > xmax ) {*/ + if ((iu[ cu_dim + ii - 1 ] != 1) && (mpf_cmp(zv, xmax) > 0)) { + /*xmax = zv;*/ + mpf_set(xmax, zv); + in = j; + } + } +/* L280 */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L280 xmax %e, toler %e\n", mpf_get_d(xmax), mpf_get_d(toler)); +#endif + /*if (xmax <= toler) {*/ + if (mpf_cmp(xmax, toler) <= 0) { +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "xmax before optimality test %e\n", mpf_get_d(xmax)); +#endif + goto L490; /* test for optimality */ + } + /*if (q2[ klm * q_dim + in ].dval != xmax) {*/ + if (mpf_cmp(q2[ klm * q_dim + in ].dval,xmax) != 0) { + for (i = 0; i < klm1; ++i) { + /*q2[ i * q_dim + in ].dval = -q2[ i * q_dim + in ].dval;*/ + mpf_neg(q2[ i * q_dim + in ].dval, q2[ i * q_dim + in ].dval); + } + q2[ klm1 * q_dim + in ].ival = -q2[ klm1 * q_dim + in ].ival; +/* L290: */ + /*q2[ klm * q_dim + in ].dval = xmax;*/ + mpf_set(q2[ klm * q_dim + in ].dval, xmax); + } +/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ + if (iphase != 1 && ia != -1) { + /*xmax = 0.;*/ + mpf_set_si(xmax, 0); +/* find maximum absolute value in column "in" */ + for (i = 0; i <= ia; ++i) { + /*z = fabs(q2[ i * q_dim + in ].dval);*/ + mpf_abs(z, q2[ i * q_dim + in ].dval); + /*if (z > xmax) {*/ + if (mpf_cmp(z, xmax) > 0) { + /*xmax = z;*/ + mpf_set(xmax, z); + iout = i; + } + } +/* L310: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L310, xmax %e\n", mpf_get_d(xmax)); +#endif +/* switch row ia with row iout, use memcpy */ + /*if (xmax > toler) {*/ + if (mpf_cmp(xmax, toler) > 0) { + /* + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(mpf_t) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ iout * q_dim]), + (size_t) n2 * sizeof(mpf_t) ); + memcpy( (void *) &(q2[ iout * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(mpf_t) ); + */ + for (i = 0; i < n1; i++) { + mpf_set(dummy, q2[ ia * q_dim + i].dval); + mpf_set(q2[ ia * q_dim + i].dval, q2[ iout * q_dim + i].dval); + mpf_set(q2[ iout * q_dim + i].dval, dummy); + } + j = q2[ ia * q_dim + n1].ival; + q2[ ia * q_dim + n1].ival = q2[ iout * q_dim + n1].ival; + q2[ iout * q_dim + n1].ival = j; + +/* L320: */ +/* set pivot to row ia, column in */ + iout = ia; + --ia; + /*pivot = q2[ iout * q_dim + in ].dval;*/ + mpf_set(pivot, q2[ iout * q_dim + in ].dval); + goto L420; /* Gauss Jordan */ + } + } +/* L330: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L330, xmax %e\n", mpf_get_d(xmax)); +#endif + kk = -1; +/* divide column n1 by positive value in column "in" greater than toler */ + for (i = 0; i < klm; ++i) { + /*z = q2[ i * q_dim + in ].dval;*/ + mpf_set(z, q2[ i * q_dim + in ].dval); + /*if (z > toler) {*/ + if (mpf_cmp(z, toler) > 0) { + ++kk; + /*res[kk] = q2[ i * q_dim + n ].dval / z;*/ + mpf_div(res[kk], q2[ i * q_dim + n ].dval, z); + s[kk] = i; + } + } +/* L340: */ + if (kk < 0) { + output_msg(OUTPUT_MESSAGE, "kode = 2 in loop 340.\n"); + } +L350: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L350, xmax %e\n", mpf_get_d(xmax)); +#endif + if (kk < 0) { +/* no positive value found in L340 or bypass intermediate verticies */ + *kode = 2; + goto L590; + } +/* L360: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L360, xmax %e\n", mpf_get_d(xmax)); +#endif +/* find minimum residual */ + /*xmin = res[ 0 ];*/ + mpf_set(xmin, res[0]); + iout = s[ 0 ]; + j = 0; + if (kk != 0) { + for (i = 1; i <= kk; ++i) { + /*if (res[i] < xmin) {*/ + if (mpf_cmp(res[i], xmin) < 0) { + j = i; + /*xmin = res[i];*/ + mpf_set(xmin, res[i]); + iout = s[i]; + } + } +/* L370: */ +/* put kk in position j */ + /*res[j] = res[kk];*/ + mpf_set(res[j], res[kk]); + s[j] = s[kk]; + } +/* L380: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L380 iout %d, xmin %e, xmax %e\n", iout, mpf_get_d(xmin), mpf_get_d(xmax)); +#endif + --kk; + /*pivot = q2[ iout * q_dim + in ].dval;*/ + mpf_set(pivot, q2[ iout * q_dim + in ].dval); + ii = q2[ iout * q_dim + n1 ].ival; + if (iphase != 1) { + if (ii < 0) { +/* L390: */ + if (iu[ - ii - 1 ] == 1) { + goto L420; + } + } else { + if (iu[ cu_dim + ii - 1 ] == 1) { + goto L420; + } + } + } +/* L400: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L400\n"); +#endif + ii = abs(ii); + /*cuv = cu[ ii - 1 ] + cu[ cu_dim + ii - 1];*/ + mpf_add(cuv, cu[ ii - 1 ], cu[ cu_dim + ii - 1]); + /*if (q2[ klm * q_dim + in ].dval - pivot * cuv > toler) {*/ + mpf_mul(dummy, pivot, cuv); + mpf_sub(dummy, q2[ klm * q_dim + in ].dval, dummy); + if (mpf_cmp(dummy, toler) > 0) { +/* BYPASS INTERMEDIATE VERTICES. */ + for (j = js; j < n1; ++j) { + /*z = q2[ iout * q_dim + j ].dval;*/ + mpf_set(z, q2[ iout * q_dim + j ].dval); + /*q2[ klm * q_dim + j ].dval -= z * cuv;*/ + mpf_mul(dummy1, z, cuv); + mpf_sub(q2[ klm * q_dim + j ].dval, q2[ klm * q_dim + j ].dval, dummy1); + + if (censor == 1) { + if (mpf_cmp(q2[ klm * q_dim + j ].dval, zero) != 0) { + mpf_abs(dummy1, q2[ klm * q_dim + j ].dval); + if (mpf_cmp(dummy1, censor_tol) <= 0) { + mpf_set_si(q2[ klm * q_dim + j ].dval, 0); + } + } + } + + /*q2[ iout * q_dim + j ].dval = -z;*/ + mpf_neg(q2[ iout * q_dim + j ].dval, z); + } +/* L410: */ + q2[ iout * q_dim + n1 ].ival = -q2[ iout * q_dim + n1 ].ival; + goto L350; + } +/* GAUSS-JORDAN ELIMINATION. */ +L420: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Gauss Jordon %d\n", *iter); +#endif + if (*iter >= maxit) { + *kode = 3; + goto L590; + } +/* L430: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L430\n"); +#endif + ++(*iter); + for (j = js; j < n1; ++j) { + if (j != in) { + /*q2[ iout * q_dim + j ].dval /= pivot;*/ + mpf_div(q2[ iout * q_dim + j ].dval, q2[ iout * q_dim + j ].dval, pivot); + } + } +/* L440: */ + for (j = js; j < n1; ++j) { + if (j != in) { + /*z = -q2[ iout * q_dim + j ].dval;*/ + mpf_neg(z, q2[ iout * q_dim + j ].dval); + for (i = 0; i < klm1; ++i) { + if (i != iout) { + /*q2[ i * q_dim + j ].dval += z * q2[ i * q_dim + in ].dval;*/ + mpf_mul(dummy, z, q2[ i * q_dim + in ].dval); + mpf_add(q2[ i * q_dim + j ].dval, q2[ i * q_dim + j ].dval, dummy); + + if (censor == 1) { + if (mpf_cmp(q2[ i * q_dim + j ].dval, zero) != 0) { + mpf_abs(dummy1, q2[ i * q_dim + j ].dval); + if (mpf_cmp(dummy1, censor_tol) <= 0) { + mpf_set_si(q2[ i * q_dim + j ].dval, 0); + } + } + } + } + } +/* L450: */ + } + } +/* L460: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L460\n"); +#endif + /*tpivot = -pivot;*/ + mpf_neg(tpivot, pivot); + for (i = 0; i < klm1; ++i) { + if (i != iout) { + /*q2[ i * q_dim + in ].dval /= tpivot;*/ + mpf_div(q2[ i * q_dim + in ].dval, q2[ i * q_dim + in ].dval, tpivot); + } + } +/* L470: */ + /*q2[ iout * q_dim + in ].dval = 1. / pivot;*/ + mpf_set_si(dummy, 1); + mpf_div(q2[ iout * q_dim + in ].dval, dummy, pivot); + ii = q2[ iout * q_dim + n1 ].ival; + q2[ iout * q_dim + n1 ].ival = q2[ klm1 * q_dim + in ].ival; + q2[ klm1 * q_dim + in ].ival = ii; + ii = abs(ii); + if (iu[ ii - 1 ] == 0 || iu[ cu_dim + ii - 1 ] == 0) { + goto L240; + } +/* switch column */ + for (i = 0; i < klm1; ++i) { + /*z = q2[ i * q_dim + in ].dval;*/ + mpf_set(z, q2[ i * q_dim + in ].dval); + /*q2[ i * q_dim + in ].dval = q2[ i * q_dim + js ].dval;*/ + mpf_set(q2[ i * q_dim + in ].dval, q2[ i * q_dim + js ].dval); + /*q2[ i * q_dim + js ].dval = z;*/ + mpf_set(q2[ i * q_dim + js ].dval, z); + } + i = q2[ klm1 * q_dim + in ].ival; + q2[ klm1 * q_dim + in ].ival = q2[ klm1 * q_dim + js ].ival; + q2[ klm1 * q_dim + js ].ival = i; +/* L480: */ + ++js; + goto L240; +/* TEST FOR OPTIMALITY. */ +L490: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L490\n"); +#endif + if (kforce == 0) { + if (iphase == 1) { + /*if (q2[ klm * q_dim + n ].dval <= toler) {*/ + if (mpf_cmp(q2[ klm * q_dim + n ].dval, toler) <= 0) { + goto L500; + } +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE,"q2[klm1-1, n1-1] > *toler. %e\n", mpf_get_d(q2[ ( klm1 - 1 ) * q_dim + n1 - 1 ].dval)); +#endif + *kode = 1; + goto L590; + } + *kode = 0; + goto L590; + } + /*if (iphase != 1 || q2[ klm * q_dim + n ].dval > toler) {*/ + if ((iphase != 1) || (mpf_cmp(q2[ klm * q_dim + n ].dval, toler) > 0)) { + kforce = 0; + goto L240; + } +/* SET UP PHASE 2 COSTS. */ +L500: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "Set up phase 2 costs %d\n", *iter); +#endif + iphase = 2; + for (j = 0; j < nklm; ++j) { + /*cu[ j ] = 0.;*/ + mpf_set_si(cu[j], 0); + } +/* L510: */ + for (j = n; j < nk; ++j) { + /*cu[ j ] = 1.;*/ + mpf_set_si(cu[j], 1); + } + /* + memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(LDBLE) ); + */ + for (i = 0; i < nklm; i++) { + mpf_set(cu[cu_dim + i], cu[i]); + } + +/* L520: */ + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + if (ii <= 0) { + if (iu[ cu_dim - ii - 1 ] == 0) { + continue; + } + /*cu[ cu_dim - ii - 1 ] = 0.;*/ + mpf_set_si(cu[ cu_dim - ii - 1 ], 0); + } else { +/* L530: */ + if (iu[ ii - 1 ] == 0) { + continue; + } + /*cu[ ii - 1 ] = 0.;*/ + mpf_set_si(cu[ ii - 1 ], 0); + } +/* L540: */ + ++ia; +/* switch row */ + /* + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ i * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ i * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(LDBLE) ); + */ + for (iswitch = 0; iswitch < n1; iswitch++) { + mpf_set(dummy, q2[ ia * q_dim + iswitch].dval); + mpf_set(q2[ ia * q_dim + iswitch].dval, q2[ i * q_dim + iswitch].dval); + mpf_set(q2[ i * q_dim + iswitch].dval, dummy); + } + iswitch = q2[ ia * q_dim + n1].ival; + q2[ ia * q_dim + n1].ival = q2[ i * q_dim + n1].ival; + q2[ i * q_dim + n1].ival = iswitch; +/* L550: */ + } +/* L560: */ + goto L160; + + +/* PREPARE OUTPUT. */ +L590: +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L590\n"); +#endif + /*sum = 0.;*/ + mpf_set_si(sum, 0); + for (j = 0; j < n; ++j) { + /*x[j] = 0.;*/ + mpf_set_si(x[j], 0); + } +/* L600: */ + for (i = 0; i < klm; ++i) { + /*res[i] = 0.;*/ + mpf_set_si(res[i], 0); + } +/* L610: */ + for (i = 0; i < klm; ++i) { + ii = q2[ i * q_dim + n1 ].ival; + /*sn = 1.;*/ + mpf_set_si(sn, 1); + if (ii < 0) { + ii = -ii; + /*sn = -1.;*/ + mpf_set_si(sn, -1); + } + if (ii <= n) { +/* L620: */ + /*x[ii - 1] = sn * q2[ i * q_dim + n ].dval;*/ + mpf_mul(x[ii - 1], sn, q2[ i * q_dim + n ].dval); + } else { +/* L630: */ + /*res[ii - n - 1] = sn * q2[ i * q_dim + n ].dval;*/ + mpf_mul(res[ii - n - 1], sn, q2[ i * q_dim + n ].dval); + if (ii >= n1 && ii <= nk ) { +/* * DBLE(Q(I,N1)) */ + /*sum += q2[ i * q_dim + n ].dval;*/ + mpf_add(sum, sum, q2[ i * q_dim + n ].dval); + } + } + } +/* L640: */ +#ifdef DEBUG_CL1 + output_msg(OUTPUT_MESSAGE, "L640\n"); +#endif + /* + * Check calculation + */ + mpf_set_si(dummy, 100); + mpf_mul(check_toler, toler, dummy); + if (check && *kode == 0) { + /* + * Check optimization constraints + */ + if (*kode_arg == 1) { + for (i = 0; i < k; i++) { + if (res_arg[i] < 0.0) { + mpf_sub(dummy, res[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy,dummy1) > 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", i, mpf_get_d(res[i]), res_arg[i]); +#endif + *kode = 1; + } + } else if (res_arg[i] > 0.0) { + mpf_add(dummy, res[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy,dummy1) < 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", i, mpf_get_d(res[i]), res_arg[i]); +#endif + *kode = 1; + } + } + } + } + /* + * Check equalities + */ + for (i = k; i < k + l; i++) { + mpf_abs(dummy, res[i]); + if (mpf_cmp(dummy, check_toler) > 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: equality constraint not satisfied row %d, res %e, tolerance %e.\n", i, mpf_get_d(res[i]), mpf_get_d(check_toler)); +#endif + + *kode = 1; + } + } + /* + * Check inequalities + */ + for (i = k + l; i < k + l + m; i++) { + mpf_neg(dummy, check_toler); + if (mpf_cmp(res[i], dummy) < 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: inequality constraint not satisfied row %d, res %e, tolerance %e.\n", i, mpf_get_d(res[i]), mpf_get_d(check_toler)); +#endif + *kode = 1; + } + } + /* + * Check dissolution/precipitation constraints + */ + if (*kode_arg == 1) { + for (i = 0; i < n; i++) { + if (x_arg[i] < 0.0) { + mpf_sub(dummy, x[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy,dummy1) > 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", i, mpf_get_d(x[i]), x_arg[i]); +#endif + *kode = 1; + } + } else if (x_arg[i] > 0.0) { + mpf_add(dummy, x[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy,dummy1) < 0) { +#ifdef CHECK_ERRORS + output_msg(OUTPUT_MESSAGE, "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", i, mpf_get_d(x[i]), x_arg[i]); +#endif + *kode = 1; + } + } + } + } + if (*kode == 1) { + output_msg(OUTPUT_MESSAGE, "\n\tCL1MP: Roundoff errors in optimization.\n\t Deleting model.\n"); + } + } + /* + * set return variables + */ + /**error = sum;*/ + mpf_set(error, sum); + *error_arg = mpf_get_d(error); + *kode_arg = *kode; + for (i = 0; i < n2d; i++) { + x_arg[i] = mpf_get_d (x[i]); + } + for (i = 0; i < k + l + m; i++) { + res_arg[i] = mpf_get_d (res[i]); + } + + /*scratch = free_check_null (scratch);*/ + + for (i = 0; i < max_row_count*max_column_count; i++) { + mpf_clear(q[i]); + } + q = (mpf_t *) free_check_null(q); + for (i = 0; i < n2d; i++) { + mpf_clear (x[i]); + } + x = (mpf_t *) free_check_null(x); + for (i = 0; i < k + l + m; i++) { + mpf_clear (res[i]); + } + res = (mpf_t *) free_check_null(res); + for (i = 0; i < 2*nklmd; i++) { + mpf_clear (cu[i]); + } + cu = (mpf_t *) free_check_null(cu); + mpf_clear(dummy); + mpf_clear(dummy1); + mpf_clear(sum); + mpf_clear(error); + mpf_clear(z); + mpf_clear(zu); + mpf_clear(zv); + mpf_clear(xmax); + mpf_clear(minus_one); + mpf_clear(toler); + mpf_clear(check_toler); + mpf_clear(pivot); + mpf_clear(xmin); + mpf_clear(cuv); + mpf_clear(tpivot); + mpf_clear(sn); + mpf_clear(censor_tol); + kode = (int *) free_check_null(kode); + return 0; +} diff --git a/classes/Conc.cxx b/classes/Conc.cxx new file mode 100644 index 00000000..fae825a6 --- /dev/null +++ b/classes/Conc.cxx @@ -0,0 +1,188 @@ +#include "Conc.h" +#include "Solution.h" +#include "Utilities.h" +#include + +CConc::CConc(void) +: description("") +, moles(0.0) +, input_conc(0.0) +, units("") +, equation_name("") +, phase_si(0.0) +, n_pe(-1) +, as("") +, gfw(0.0) + //, skip(0); + //, phase(NULL) +{ +} + +CConc::~CConc(void) +{ +} + +#ifdef SKIP +CConc::STATUS_TYPE CConc::read(CParser& parser, CSolution& solution) +{ + // std::string& str = parser.line(); + std::string str = parser.line(); + + // defaults set in ctor + + // Remove space between "kg" and "solution" or "water" in units + Utilities::replace("Kg", "kg", str); + Utilities::replace("KG", "kg", str); + while (Utilities::replace("kg ", "kg", str)); + + std::istream::pos_type ptr = 0; + + // + // Read master species list for mass balance equation + // + std::string token; + std::string token1; + int count_redox_states = 0; + CParser::TOKEN_TYPE j; + while ( ((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER ) || + ( token[0] == '[' ) || + ( Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0 ) || + ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) ) + { + ++count_redox_states; + Utilities::replace("(+", "(", token); + if (count_redox_states > 1) token1 += " "; + token1 += token; + } + if (count_redox_states == 0) { + parser.incr_input_error(); + parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE); + return CConc::ERROR; + } + description = token1; + + // Determine if reading alkalinity, allow equivalents for units + Utilities::str_tolower(token1); + bool alk = false; + if (token1.find("alk") == 0) { + alk = true; + } + + // Read concentration + if (!(std::istringstream(token) >> this->input_conc)) { + std::ostringstream err; + err << "Concentration data error for " << token1 << " in solution input."; + parser.error_msg(err, CParser::OT_CONTINUE); + return CConc::ERROR; + } + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + + // Read optional data + token1 = token; + + // Check for units info + if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) { + if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) { + this->units = token1; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + } else { + return CConc::ERROR; + } + } + + // Check for "as" followed by formula to be used for gfw + token1 = token; + Utilities::str_tolower(token1); + if (token1.compare("as") == 0) + { + parser.copy_token(token, ptr); + this->as = token; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + } + // Check for "gfw" followed by gram formula weight + else if (token1.compare("gfw") == 0) + { + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { + parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); + return CConc::ERROR; + } else { + parser.get_iss() >> this->gfw; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + } + } + + // Check for redox couple for pe + if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { + this->n_pe = CPe_Data::store(solution.pe, token); + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + } else if (token.find("/") != std::string::npos) { + if (parser.parse_couple(token) == CParser::OK) { + this->n_pe = CPe_Data::store(solution.pe, token); + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + } else { + return CConc::ERROR; + } + } + + // Must have phase + this->equation_name = token; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; + + // Check for saturation index + if (!(std::istringstream(token) >> this->phase_si)) + { + parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); + return CConc::ERROR; + } + return CConc::OK; +} +#endif + +void CConc::dump_xml(const CSolution& solution, std::ostream& os, unsigned int indent)const +{ + unsigned int i; + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->description << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->input_conc << "\n"; + + if (!this->units.empty()) { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->units << "\n"; + } + + if ( !this->as.empty() ) { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->as << "\n"; + } + else if (this->gfw > 0.0) { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->gfw << "\n"; + } + ////if (this->n_pe > 0) { + solution.pe[this->n_pe].dump_xml(os, indent + 1); + ////} + + if (!this->equation_name.empty()) { + if (Utilities::strcmp_nocase_arg1(this->equation_name.c_str(), "charge") == 0) + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + } + else + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->equation_name << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->phase_si << "\n"; + } + } + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "\n"; +} diff --git a/classes/Conc.h b/classes/Conc.h new file mode 100644 index 00000000..4b867d2f --- /dev/null +++ b/classes/Conc.h @@ -0,0 +1,60 @@ +#if !defined(CONC_H_INCLUDED) +#define CONC_H_INCLUDED + +#include "Parser.h" +#include "Utilities.h" + +#include + +// forward declarations +class CSolution; // reqd for read and dump_xml + +class CConc +{ +public: + CConc(void); + ~CConc(void); + + enum STATUS_TYPE { + ERROR = 0, + OK = 1 + }; + +public: + + STATUS_TYPE read(CParser& parser, CSolution& sol); + + void dump_xml(const CSolution& solution, std::ostream& os, unsigned int indent = 0)const; + + double get_input_conc()const {return this->input_conc;} + void set_input_conc(double input_conc) {this->input_conc = input_conc;} + + std::string get_equation_name()const {return this->equation_name;} + void set_equation_name(std::string equation_name) {this->equation_name = equation_name;} + + std::string get_description()const {return this->description;} + void set_description(std::string description) {this->description = description;} + + std::string get_units()const {return this->units;} + void set_units(std::string units) {this->units = units;} + + int get_n_pe()const {return this->n_pe;} + void set_n_pe(int n_pe) {this->n_pe = n_pe;} + + bool operator<(const CConc& conc)const { return (this->description < conc.description); } + +private: + std::string description; + // int m_skip; + double moles; + double input_conc; + std::string units; + std::string equation_name; + // struct phase *m_phase; + double phase_si; + int n_pe; + std::string as; + double gfw; +}; + +#endif // CONC_H_INCLUDED diff --git a/classes/Isotope.cxx b/classes/Isotope.cxx new file mode 100644 index 00000000..5654e1df --- /dev/null +++ b/classes/Isotope.cxx @@ -0,0 +1,100 @@ +#include "Isotope.h" +#include "Utilities.h" +#include + +CIsotope::CIsotope(void) +: isotope_number(0.0) +, ratio_uncertainty_defined(false) +{ +} + +CIsotope::~CIsotope(void) +{ +} + +std::string CIsotope::get_name()const +{ + std::ostringstream oss; + oss << this->isotope_number << this->elt_name; + return oss.str(); +} +#ifdef SKIP +CIsotope::STATUS CIsotope::read(CParser& parser) +{ + if ( !(parser.get_iss() >> this->isotope_number) ) { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected isotope name to" + " begin with an isotopic number.", CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + + // read and save element name + std::istringstream::int_type c = parser.get_iss().peek(); + if ( c == std::char_traits::eof() || !(::isupper(c)) ) { + parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + parser.incr_input_error(); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + if ( !(parser.get_iss() >> this->elt_name) ) { + // should never get here + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + assert(!this->elt_name.empty() && ::isupper(this->elt_name[0])); + + // read and store isotope ratio + if ( !(parser.get_iss() >> this->ratio) ) { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected numeric value for isotope ratio.", CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + + // read and store isotope ratio + this->ratio_uncertainty_defined = false; + if ( !(parser.get_iss() >> this->ratio_uncertainty)) { + if ( !parser.get_iss().eof() ) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for uncertainty in isotope ratio.", CParser::OT_CONTINUE); + return ERROR; + } + } else { + this->ratio_uncertainty_defined = true; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + return OK; +} +#endif +#ifdef SKIP +void CIsotope::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "ratio << "\""; + if ( this->ratio_uncertainty_defined /* Utilities::isnan(this->ratio_uncertainty) */ ) { + os << "/>\n"; + } + else { + os << ">\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->ratio_uncertainty << "\n"; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "\n"; + } +} +#endif +bool CIsotope::operator<(const CIsotope& isotope)const +{ + int i = Utilities::strcmp_nocase(this->elt_name.c_str(), isotope.elt_name.c_str()); + if (i != 0) return (i < 0); + return ( this->isotope_number < isotope.isotope_number ); +} + diff --git a/classes/Isotope.h b/classes/Isotope.h new file mode 100644 index 00000000..9ded5525 --- /dev/null +++ b/classes/Isotope.h @@ -0,0 +1,40 @@ +#if !defined(ISOTOPE_H_INCLUDED) +#define ISOTOPE_H_INCLUDED + +#include "Parser.h" +#include // std::ostream +#include // std::string + +class CIsotope +{ +public: + CIsotope(void); + ~CIsotope(void); + + enum STATUS { + ERROR = 0, + OK = 1 + }; + + CIsotope::STATUS read(CParser& parser); + + void dump_xml(std::ostream& os, unsigned int indent)const; + + std::string get_name()const ; + + double get_ratio()const { return this->ratio; } + + double get_ratio_uncertainty()const { return this->ratio_uncertainty; } + + bool get_ratio_uncertainty_defined()const { return this->ratio_uncertainty_defined; } + + bool operator<(const CIsotope& conc)const; + +private: + double isotope_number; + std::string elt_name; + double ratio; + double ratio_uncertainty; + bool ratio_uncertainty_defined; +}; +#endif // ISOTOPE_H_INCLUDED diff --git a/classes/Makefile b/classes/Makefile new file mode 100644 index 00000000..04119bc6 --- /dev/null +++ b/classes/Makefile @@ -0,0 +1,35 @@ +.SUFFIXES : .o .cxx + +.cxx.o : + $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $< + +CXX = g++ +CPPFLAGS = -I/z/srv2rcolkr/home/charlton/cppunit-robocomp/include +CXXFLAGS = -Wall +LDFLAGS = -lcppunit -L/z/srv2rcolkr/home/charlton/cppunit-robocomp/lib -static + + +COMMON_OBJS = Conc.o\ + Isotope.o\ + NumKeyword.o\ + Parser.o\ + Pe_Data.o\ + Solution.o\ + Utilities.o + +TEST_OBJS = TestCIsotope.o\ + TestCSolution.o\ + TestCParser.o\ + test.o + +all: phreeqcxx test + + +phreeqcxx : ${COMMON_OBJS} main.o + ${CXX} -o $@ ${COMMON_OBJS} main.o + +test : ${COMMON_OBJS} ${TEST_OBJS} + ${CXX} -o $@ ${COMMON_OBJS} ${TEST_OBJS} ${LDFLAGS} + +clean : + rm -f ${COMMON_OBJS} main.o ${TEST_OBJS} diff --git a/classes/NumKeyword.cxx b/classes/NumKeyword.cxx new file mode 100644 index 00000000..8590b95f --- /dev/null +++ b/classes/NumKeyword.cxx @@ -0,0 +1,119 @@ +// NumKeyword.cxx: implementation of the CNumKeyword class. +// +////////////////////////////////////////////////////////////////////// + +#include "NumKeyword.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CNumKeyword::CNumKeyword() +{ +} + +CNumKeyword::~CNumKeyword() +{ +} + +void CNumKeyword::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->n_user << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->n_user_end << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << " "; + os << "" << this->description << "" << "\n"; +} + +void CNumKeyword::read_number_description(CParser& parser) +{ + // skip keyword + std::string keyword; + std::istream::pos_type ptr; + parser.copy_token(keyword, ptr); + + std::istream::pos_type ptr1 = ptr; + std::string::size_type pos; + std::string token; + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) + { + this->n_user = 1; + this->n_user_end = 1; + } + else if ( (pos = token.find_first_of("-")) != std::string::npos ) + { + token.replace(pos, 1, " "); + std::istringstream iss(token); + if (!(iss >> this->n_user >> this->n_user_end)) + { + std::ostringstream err_oss; + if (parser.next_keyword() >= 0) + { + err_oss << "Reading number range for " << keyword << "."; + } + else + { + err_oss << "Reading number range for keyword."; + } + parser.error_msg(err_oss, CParser::OT_CONTINUE); + parser.incr_input_error(); + } + ptr1 = ptr; + } + else + { + std::istringstream iss(token); + iss >> this->n_user; + this->n_user_end = this->n_user; + ptr1 = ptr; + } + + // reset get position + parser.get_iss().seekg(ptr1); + + // skip whitespace + while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore(); + + // copy description + std::getline(parser.get_iss(), this->description); +} + +void CNumKeyword::read_number_description(std::istream& is) +{ + // KEYWORD [[1[-20]] [This is the description]] + + // eat keyword + std::string token; + is >> token; + + // skip whitespace + while (::isspace(is.peek())) is.ignore(); + + if (::isdigit(is.peek())) + { + is >> this->n_user; + char ch = is.peek(); + if (ch == '-') + { + is >> ch; // eat '-' + is >> this->n_user_end; + } + else + { + this->n_user_end = this->n_user; + } + } + else + { + this->n_user = this->n_user_end = 1; + } + + while (::isspace(is.peek())) is.ignore(); + + std::getline(is, this->description); +} diff --git a/classes/NumKeyword.h b/classes/NumKeyword.h new file mode 100644 index 00000000..0b885426 --- /dev/null +++ b/classes/NumKeyword.h @@ -0,0 +1,34 @@ +#if !defined(NUMKEYWORD_H_INCLUDED) +#define NUMKEYWORD_H_INCLUDED + +#include "Parser.h" +#include // std::ostream +#include // std::string + +class CNumKeyword +{ +public: + CNumKeyword(); + virtual ~CNumKeyword(); + + int get_n_user()const { return this->n_user; } + void set_n_user(int user) { this->n_user = user; } + + int get_n_user_end()const { return this->n_user_end; } + void set_n_user_end(int user_end) { this->n_user_end = user_end; } + + bool operator<(const CNumKeyword& key)const { return (this->n_user < key.n_user); } + + virtual void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void read_number_description(CParser& parser); + +protected: + int n_user; + int n_user_end; + std::string description; + +private: + void read_number_description(std::istream& is); +}; +#endif // !defined(NUMKEYWORD_H_INCLUDED) diff --git a/classes/Parser.cxx b/classes/Parser.cxx new file mode 100644 index 00000000..3316162d --- /dev/null +++ b/classes/Parser.cxx @@ -0,0 +1,836 @@ +// Parser.cpp: implementation of the CParser class. +// +////////////////////////////////////////////////////////////////////// + +#include "Parser.h" +#include "utilities.h" +#include // std::transform +#include // std::map +#include // assert +#include // std::cout std::cerr + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CParser::CParser(std::istream& input) +: m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::CParser(std::istream& input, std::ostream& output) +: m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) +: m_input_stream(input), m_output_stream(output), m_error_stream(error) +, m_input_error(0), m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); +} + +CParser::~CParser() +{ +} + +CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print) +{ + LINE_TYPE i; + + // Get line + do { + i = get_line(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + + if (true) // pr.echo_input == TRUE + { + if ((print && i != LT_EOF) || i == LT_KEYWORD) + { + get_output() << "\t" << m_line_save << "\n"; + } + } + + } while (i == LT_EMPTY && allow_empty == false); + + // Check eof + if (i == LT_EOF && allow_eof == false) + { + std::ostringstream msg; + msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; + error_msg(msg, OT_STOP); + } + + // Check keyword + if (i == LT_KEYWORD && allow_keyword == false) + { + std::ostringstream msg; + msg << "Expected data for " << str << ", but got a keyword ending data block."; + error_msg(msg, OT_CONTINUE); + incr_input_error(); + } + return i; +} + +CParser::LINE_TYPE CParser::get_line() +{ + CParser::LINE_TYPE return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + // + // Eliminate all characters after # sign as a comment + // + + // + // Get line, check for eof + // + if (get_logical_line() == LT_EOF) + { + if (!m_input_stream.eof()) + { + error_msg("Reading input file.", OT_CONTINUE); + error_msg("istream::get() returned an error.", OT_STOP); + } + else + { + //{{MOD + m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + //}}MOD + m_next_keyword = KT_EOF; + return LT_EOF; + } + } + + // + // Get long lines + // + bool empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + } + + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' && ::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + return return_value; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +CParser::LINE_TYPE CParser::get_logical_line() +{ + int j; + unsigned int pos; + char c; + + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + + while ((j = m_input_stream.get()) != std::char_traits::eof()) { + c = (char) j; + if (c == '#') { + // ignore all chars after # until newline + do { + c = (char) j; + if (c == '\n') { + break; + } + m_line_save += c; + } while ((j = m_input_stream.get()) != std::char_traits::eof()); + } + if (c == ';') break; + if (c == '\n') { + break; + } + if (c == '\\') { + pos = m_line_save.size(); + m_line_save += c; + while ((j = m_input_stream.get()) != std::char_traits::eof()) { + c = (char) j; + if (c == '\\') { + pos = m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') { + // remove '\\' + for (; pos < m_line_save.size(); pos++) { + m_line_save[pos] = m_line_save[pos+1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) break; + } + } else { + m_line_save += c; + } + } + if (j == std::char_traits::eof() && m_line_save.size() == 0) { + return(LT_EOF); + } + return(LT_OK); +} + + +//bool CParser::check_key(const std::string::iterator ptr) +bool CParser::check_key(std::string::iterator begin, std::string::iterator end) +{ + static std::map s_keyword_map; + if (s_keyword_map.size() == 0) + { + s_keyword_map.insert(std::map::value_type("solution", KT_SOLUTION)); + s_keyword_map.insert(std::map::value_type("end", KT_END)); + } + + std::string lowercase; + copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); + + m_next_keyword = KT_NONE; + std::map::iterator map_iter = s_keyword_map.find(lowercase); + if (map_iter == s_keyword_map.end()) + return false; + m_next_keyword = (*map_iter).second; + return true; +} + +CParser::STATUS_TYPE CParser::check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, + const std::string& default_units, bool print) +{ +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity true if alkalinity, false if any other total, + * check_compatibility true check alk and default units, false otherwise + * default_units character string of default units (check /L, /kg, etc) + * print true print warning messages + * Output: + * tot_units standard form for unit + */ + using utilities::str_tolower; + using utilities::replace; + using utilities::squeeze_white; + + static const char *units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + + std::string::size_type end; + if ((end = tot_units.find("/l")) != std::string::npos) { + tot_units.resize(end + 2); + } + if ((end = tot_units.find("/kgs")) != std::string::npos) { + tot_units.resize(end + 4); + } + if ((end = tot_units.find("/kgw")) != std::string::npos) { + tot_units.resize(end + 4); + } + + // + // Check if unit in list + // + bool found = false; + for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) { + if (tot_units.compare(units[i]) == 0) { + found = true; + break; + } + } + if (!found) { + if (print) { + std::ostringstream err; + err << "Unknown unit, " << tot_units; + error_msg(err, OT_CONTINUE); + } + return ERROR; + } + + // + // Check if units are compatible with default_units + // + if (check_compatibility == false) return OK; + + // + // Special cases for alkalinity + // + if (alkalinity == true && tot_units.find("Mol") != std::string::npos) { + if (print) { + warning_msg("Alkalinity given in moles, assumed to be equivalents."); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == false && tot_units.find("eq") != std::string::npos) { + if (print) { + error_msg("Only alkalinity can be entered in equivalents.", OT_CONTINUE); + } + return ERROR; + } + + // + // See if default_units are compatible with tot_units + // + if (default_units.find("/l") != std::string::npos && tot_units.find("/l") != std::string::npos) return OK; + if (default_units.find("/kgs") != std::string::npos && tot_units.find("/kgs") != std::string::npos) return OK; + if (default_units.find("/kgw") != std::string::npos && tot_units.find("/kgw") != std::string::npos) return OK; + + std::string str = default_units; + replace("kgs", "kg solution", str); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", str); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", str); + replace("Mol", "mol", str); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); + + if (print) { + std::ostringstream err; + err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; + error_msg(err, OT_CONTINUE); + } + return ERROR; +} + +CParser::TOKEN_TYPE CParser::token_type(const std::string& token) +{ + if (!token.empty()) { + if (::isupper(token[0])) { + return CParser::TT_UPPER; + } else if (::islower(token[0])) { + return CParser::TT_LOWER; + } else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') { + return CParser::TT_DIGIT; + } else { + assert(!::isspace(token[0])); + return CParser::TT_UNKNOWN; + } + } + else { + return CParser::TT_EMPTY; + } +} + +CParser::TOKEN_TYPE CParser::peek_token() +{ + std::istringstream::pos_type pos = m_line_iss.tellg(); + std::string token; + m_line_iss >> token; + m_line_iss.seekg(pos); + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end) +{ + if (begin != end) + { + std::string::iterator b = begin; + for (; b < end && ::isspace(*b); ++b); + + begin = b; + for (; begin < end && !::isspace(*begin); ++begin); + + token.assign(b, begin); + } + else + { + token.resize(0); + } + + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream& is) +{ + is >> token; + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream::pos_type& pos) +{ + m_line_iss.seekg(pos); + // m_line_iss >> token; + if( !(m_line_iss >> token)) { + token.erase(token.begin(), token.end()); // token.clear(); + } + pos = m_line_iss.tellg(); + return token_type(token); +} + +CParser::FIND_TYPE CParser::find_option(const std::string& item, int *n, const std::vector& list, bool exact) +{ + std::string token(item); + std::transform(token.begin(), token.end(), token.begin(), tolower); + for (unsigned int i = 0; i < list.size(); i++) + { + if (exact == true) + { + if (list[i].compare(token) == 0) + { + *n = i; + return FT_OK; + } + } + else + { + if(list[i].find(token) == 0) + { + *n = i; + return FT_OK; + } + } + } + + *n = -1; + return FT_ERROR; +} + +// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) +// OPTION_TYPE CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +int CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; + + // char option[MAX_LENGTH]; + std::string option; + + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, false); + if (lt == LT_EOF) + { + j = OPTION_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPTION_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); + + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; + + j = OPTION_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPTION_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int CParser::get_option(const std::vector& opt_list, std::istream::pos_type& next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, false); + if (lt == LT_EOF) + { + j = OPTION_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPTION_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + error_msg("Unknown option.", OT_CONTINUE); + error_msg(m_line_save.c_str(), OT_CONTINUE); + incr_input_error(); + j = OPTION_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPTION_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) +{ + m_error_stream << "ERROR: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "ERROR: " << err_str << "\n"; + m_output_stream.flush(); + + if (ot == OT_STOP) + { + exit(1); + } + return 0; +} + +int CParser::warning_msg(const char *err_str) +{ + m_error_stream << "WARNING: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "WARNING: " << err_str << "\n"; + m_output_stream.flush(); + + return 0; +} + +CParser::STATUS_TYPE CParser::get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element) +{ + element.erase(element.begin(), element.end()); // element.clear(); + + if (begin == end) { + error_msg("Empty string in get_elt. Expected an element name.", OT_CONTINUE); + return ERROR; + } + + // + // Load name into char array element + // + char c = *begin; + ++begin; + element.insert(element.end(), c); // element.push_back(c); + if (c == '[') { + while ( (c = *begin) != ']' ) { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if ( (c = *begin) == ']' ) { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + break; + } else if (begin == end) { + error_msg("No ending bracket (]) for element name", OT_CONTINUE); + incr_input_error(); + return ERROR; + } + } + while (::islower(c = *begin) || c == '_') { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) break; + } + } else { + while (::islower(c = *begin) || c == '_') { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) break; + } + } + return OK; +} + +CParser::STATUS_TYPE CParser::parse_couple(std::string& token) +{ + // Parse couple puts redox couples in standard form + // "+" is removed and couples are rewritten in sort + // order. + + if (utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) { + utilities::str_tolower(token); + return OK; + } + + while ( utilities::replace("+", "", token) ); + + std::string::iterator ptr = token.begin(); + std::string elt1; + get_elt(ptr, token.end(), elt1); + + if (*ptr != '(') { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " << + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return ERROR; + } + + int paren_count = 1; + std::string paren1 = "("; + while ( ptr != token.end() ) { + ++ptr; + if (*ptr == '/' || ptr == token.end()) { + std::ostringstream err_msg; + err_msg << "End of line or ""/"" encountered before end of parentheses, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return ERROR; + } + paren1.insert(paren1.end(), *ptr); // element.push_back(c); + if (*ptr == '(') ++paren_count; + if (*ptr == ')') --paren_count; + if (paren_count == 0) break; + } + + ++ptr; + if (ptr == token.end() || *ptr != '/') { + std::ostringstream err_msg; + err_msg << " ""/"" must follow parentheses " << + "ending first half of redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return ERROR; + } + ++ptr; + std::string elt2; + get_elt(ptr, token.end(), elt2); + if (elt1.compare(elt2) != 0) { + std::ostringstream err_msg; + err_msg << "Redox couple must be two redox states " << + "of the same element, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return ERROR; + } + if (*ptr != '(') { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return ERROR; + } + std::string paren2 = "("; + paren_count = 1; + + while ( ptr != token.end() ) { + ++ptr; + if (*ptr == '/' || ptr == token.end()) { + std::ostringstream err_msg; + err_msg << "End of line or ""/"" encountered before end of parentheses, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return ERROR; + } + paren2.insert(paren2.end(), *ptr); // element.push_back(c); + if (*ptr == '(') ++paren_count; + if (*ptr == ')') --paren_count; + if (paren_count == 0) break; + } + if (paren1.compare(paren2) < 0) { + token = elt1 + paren1 + std::string("/") + elt2 + paren2; + } else if (paren1.compare(paren2) > 0) { + token = elt2 + paren2 + std::string("/") + elt1 + paren1; + } else { + std::ostringstream err_msg; + err_msg << "Both parts of redox couple are the same, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return ERROR; + } + return OK; +} diff --git a/classes/Parser.h b/classes/Parser.h new file mode 100644 index 00000000..71281780 --- /dev/null +++ b/classes/Parser.h @@ -0,0 +1,196 @@ +#if !defined(PARSER_H_INCLUDED) +#define PARSER_H_INCLUDED + +#include // std::string +#include // std::vector +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream + +class CParser +{ +public: + CParser(std::istream& input); + CParser(std::istream& input, std::ostream& output); + CParser(std::istream& input, std::ostream& output, std::ostream& error); + + virtual ~CParser(); + + enum LINE_TYPE { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; + + enum TOKEN_TYPE { + TT_EMPTY = 2, + TT_UPPER = 4, + TT_LOWER = 5, + TT_DIGIT = 6, + TT_UNKNOWN = 7 + }; + + enum FIND_TYPE { + FT_OK = 0, + FT_ERROR = 1 + }; + + enum KEY_TYPE { + KT_NONE = -1, + KT_END = 0, + KT_EOF = 1, + KT_SOLUTION = 4 + }; + + enum OPTION_TYPE { + OPTION_DEFAULT = -4, + OPTION_ERROR = -3, + OPTION_KEYWORD = -2, + OPTION_EOF = -1 + }; + + enum ONERROR_TYPE { + OT_CONTINUE = 0, + OT_STOP = 1, + }; + + enum STATUS_TYPE { + ERROR = 0, + OK = 1 + }; + + /** + Function gets a new line and checks for empty, eof, and keywords. + + Arguments: + string Input, character string used in printing error message + allow_empty Input, True or false, if a blank line is accepable + if false, another line is read + allow_eof Input, True or false, if EOF is acceptable + allow_keyword Input, True or false, if a keyword is acceptable + + Returns: + LT_EMPTY if empty line read and allow_empty == true + LT_KEYWORD if line begins with keyword + LT_EOF if eof and allow_eof == true + LT_OK otherwise + LT_OPTION if line begins with -[alpha] + + Terminates if EOF and allow_eof == false. + */ + LINE_TYPE check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print); + + /** + Read a line from input file put in "line". + Copy of input line is stored in "line_save". + Characters after # are discarded in line but retained in "line_save" + + Arguments: + None + Returns: + LT_EMPTY, + LT_EOF, + LT_KEYWORD, + LT_OK, + LT_OPTION + */ + LINE_TYPE get_line(); + + // bool check_key(const std::string::iterator ptr); + bool check_key(std::string::iterator begin, std::string::iterator end); + + STATUS_TYPE check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, + const std::string& default_units, bool print); + + + KEY_TYPE next_keyword()const { return m_next_keyword; } + int get_option(const std::vector& opt_list, std::string::iterator& next_char); + int get_option(const std::vector& opt_list, std::istream::pos_type& next_pos); + + + std::string& line() {return m_line;} + std::istringstream& get_iss() {return m_line_iss;} + int incr_input_error() {return ++m_input_error;} + std::ostream& get_output() {return m_output_stream;} + int get_input_error() {return m_input_error;} + + + /** + Copies from begin to token until first space is encountered. + + Arguments: + token output, the token + begin input, begin iterator + end input, end iterator + + Returns: + TT_EMPTY + TT_UPPER + TT_LOWER + TT_DIGIT + TT_UNKNOWN + */ + static TOKEN_TYPE copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end); + static TOKEN_TYPE token_type(const std::string& token); + static TOKEN_TYPE copy_token(std::string& token, std::istream& is); + TOKEN_TYPE copy_token(std::string& token, std::istream::pos_type& pos); + CParser::TOKEN_TYPE peek_token(); + + /** + Function reads an element name out of the equation string. + An element name is composed of a capital letter followed by any number + of lower case characters. + + Arguments: + begin input, points to position in the equation to begin + output, points to next character of equation after + element name. + end input, points to last position in the equation + element input pointer to place to return element character string + */ + STATUS_TYPE get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element); + + + /** + Compares a string value to match beginning letters of a list of options + + Arguments: + item entry: pointer to string to compare + n exit: item in list that was matched + list entry: pointer to list of character values, assumed to + be lower case + count_list entry: number of character values in list + + Returns: + OK item matched + ERROR item not matched + n -1 item not matched + i position of match in list + */ + static FIND_TYPE find_option(const std::string& item, int *n, const std::vector& list, bool exact); + + + int error_msg(const std::ostringstream& err_str, ONERROR_TYPE stop) {return error_msg(err_str.str().c_str(), stop);} + int error_msg(const char *err_str, ONERROR_TYPE stop); + int warning_msg(const char *err_str); + + + STATUS_TYPE parse_couple(std::string& token); + +protected: + LINE_TYPE get_logical_line(); + +private: + std::istream& m_input_stream; + std::ostream& m_output_stream; + std::ostream& m_error_stream; + int m_input_error; + KEY_TYPE m_next_keyword; + std::string m_line; + std::string m_line_save; + std::istringstream m_line_iss; +}; + +#endif // PARSER_H_INCLUDED diff --git a/classes/Pe_Data.cxx b/classes/Pe_Data.cxx new file mode 100644 index 00000000..1109971d --- /dev/null +++ b/classes/Pe_Data.cxx @@ -0,0 +1,45 @@ +#include "Pe_Data.h" +#include "Utilities.h" +#include // std::ostream + +CPe_Data::CPe_Data() +: name("") +{ +} + +CPe_Data::CPe_Data(const std::string& name) +: name(name) +{ +} + +CPe_Data::~CPe_Data() +{ +} + +int CPe_Data::store(std::vector& vec_pe_data, const std::string& token) +{ + unsigned int i = 0; + unsigned int size = vec_pe_data.size(); + for (; i < size; ++i) { + if (vec_pe_data[i].name.compare(token) == 0) + return i; + } + vec_pe_data.push_back(token); + return i; +} + +std::vector CPe_Data::alloc() +{ + std::vector vec; + vec.push_back(CPe_Data("pe")); + // TODO: see pe_data_alloc + return vec; +} + +void CPe_Data::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "" << this->name << "\n"; +} + diff --git a/classes/Pe_Data.h b/classes/Pe_Data.h new file mode 100644 index 00000000..263709ea --- /dev/null +++ b/classes/Pe_Data.h @@ -0,0 +1,27 @@ +#if !defined(PE_DATA_H_INCLUDED) +#define PE_DATA_H_INCLUDED + +#include +#include + +class CPe_Data +{ +public: + CPe_Data(); + CPe_Data(const std::string& name); + + ~CPe_Data(); + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + std::string get_name()const {return this->name;}; + void set_name(std::string name) {this->name = name;}; + + static int store(std::vector& vec, const std::string& token); + static std::vector CPe_Data::alloc(); + +private: + std::string name; +}; + +#endif // PE_DATA_H_INCLUDED diff --git a/classes/Solution.cxx b/classes/Solution.cxx new file mode 100644 index 00000000..429168d6 --- /dev/null +++ b/classes/Solution.cxx @@ -0,0 +1,312 @@ +// Solution.cxx: implementation of the CSolutionxx class. +// +////////////////////////////////////////////////////////////////////// + +#include "Solution.h" + +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +//static std::map ss_map; +//std::map& CSolution::s_map = ss_map; + +CSolution::CSolution() +: CNumKeyword() +, units("mMol/kgw") +, pe(CPe_Data::alloc()) +{ + ph = 7.0; + tc = 25.0; + density = 1.0; + + solution_pe = 4.0; + mu = 1e-7; + ah2o = 1.0; + mass_water = 1.0; + default_pe = -1; +} + +CSolution::~CSolution() +{ +} +#ifdef SKIP +CSolution& CSolution::read(CParser& parser) +{ + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); + + CSolution numkey; + + // Read solution number and description + numkey.read_number_description(parser); + + // Malloc space for solution data + //// g_solution_map[numkey.n_user()] = numkey; + s_map[numkey.n_user()] = numkey; + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; + + CSolution& sol = s_map[numkey.n_user()]; + int default_pe = 0; + + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { + opt = 9; + } + } + + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; + + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; + + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; + + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { + sol.units = token; + } else { + parser.incr_input_error(); + } + break; + + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; + if (parser.parse_couple(token) == CParser::OK) { + default_pe = CPe_Data::store(sol.pe, token); + } else { + parser.incr_input_error(); + } + break; + + case 6: // ph + { + CConc conc; + if (conc.read(parser, sol) == CConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; + + case 7: // pe + { + CConc conc; + if (conc.read(parser, sol) == CConc::ERROR) { + parser.incr_input_error(); + break; + } + sol.solution_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; + + case 9: // isotope + { + CIsotope isotope; + if (isotope.read(parser) == CIsotope::OK) { + sol.add(isotope); + } + } + break; + + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) { + sol.mass_water = 1.0; + } else if (j != CParser::TT_DIGIT) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); + } else { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + CConc conc; + if (conc.read(parser, sol) == CConc::ERROR) { + parser.incr_input_error(); + } else { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; + } +#ifdef SKIP + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); +#endif + + // + // fix up default units and default pe + // + std::string token1; + std::vector::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) { + (*iter).set_units(sol.units); + } else { + bool alk = false; + if (token.find("alk") == 0) alk = true; + token1 = (*iter).get_units(); + if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { + parser.incr_input_error(); + } else { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; +} +#endif +void CSolution::dump_xml(std::ostream& os, unsigned int indent)const +{ + unsigned int i; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "\n"; + + CNumKeyword::dump_xml(os, indent); + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_tc() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_ph() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_solution_pe() << "" << "\n"; + + assert(this->pe.size() > 0); + assert(this->default_pe >= 0); + assert(this->pe.size() > (unsigned int) this->default_pe); + this->pe[this->default_pe].dump_xml(os, indent + 1); + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_units() << "" << "\n"; + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_density() << "" << "\n"; + + // foreach conc + if (!this->totals.empty()) + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + + std::vector::const_iterator iter = this->totals.begin(); + for(; iter != this->totals.end(); ++iter) + { + (*iter).dump_xml(*this, os, indent + 2); + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + } + + // foreach isotope + if (!this->isotopes.empty()) + { + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + + std::list::const_iterator iter = this->isotopes.begin(); + for(; iter != this->isotopes.end(); ++iter) + { + (*iter).dump_xml(os, indent + 2); + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "\n"; + } + + for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; + os << "" << this->get_mass_water() << "" << "\n"; + + for(i = 0; i < indent; ++i) os << Utilities::INDENT; + os << "" << "\n"; +} + + + + + + + + + + + + + + + diff --git a/classes/Solution.h b/classes/Solution.h new file mode 100644 index 00000000..012977b9 --- /dev/null +++ b/classes/Solution.h @@ -0,0 +1,72 @@ +#if !defined(SOLUTION_H_INCLUDED) +#define SOLUTION_H_INCLUDED + +#include "NumKeyword.h" +#include "Parser.h" +#include "Conc.h" +#include "Isotope.h" +#include "Pe_Data.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + + +class CSolution : public CNumKeyword +{ +public: + CSolution(); + ~CSolution(); + + static CSolution& read(CParser& parser); + + void add(CConc conc) { this->totals.push_back(conc); } + void add(CIsotope isotope) { this->isotopes.push_back(isotope); } + + double get_ph()const {return this->ph;} + void set_ph(double pH) {this->ph = pH;} + + double get_solution_pe()const {return this->solution_pe;} + void set_solution_pe(double solution_pe) {this->solution_pe = solution_pe;} + + double get_tc()const {return this->tc;} + void set_tc(double tc) {this->tc = tc;} + + double get_density()const {return this->density;} + void set_density(double density) {this->density = density;} + + std::string get_units()const {return this->units;} + void set_units(std::string units) {this->units = units;} + + std::string get_redox()const {return this->pe[this->default_pe].get_name();} + + long double get_mass_water()const {return this->mass_water;}; + void set_mass_water(long double mass_water) {this->mass_water = mass_water;}; + + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + +protected: + friend class CConc; // for this->pe access + double ph; + double tc; + double solution_pe; + double mu; + double ah2o; + double density; + long double mass_water; + std::string units; + + + std::vector totals; /// std::set m_totals; ////std::list m_totals; + std::vector pe; + int default_pe; + + std::list isotopes; + +public: + static std::map& map; + +}; + +#endif // !defined(SOLUTION_H_INCLUDED) diff --git a/classes/TestCIsotope.cxx b/classes/TestCIsotope.cxx new file mode 100644 index 00000000..27f0828e --- /dev/null +++ b/classes/TestCIsotope.cxx @@ -0,0 +1,164 @@ +#include "TestCIsotope.h" +#include "Parser.h" +#include "utilities.h" + +TestCIsotope::TestCIsotope() +{ +} + +TestCIsotope::~TestCIsotope() +{ +} + +void TestCIsotope::test_read_1() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("-isotope"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected isotope name to begin with an isotopic number.\n") == 0); +} + +void TestCIsotope::test_read_2() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("-isotope C"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected isotope name to begin with an isotopic number.\n") == 0); +} + +void TestCIsotope::test_read_3() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expecting element name.\nERROR: isotope 13\n") == 0); +} + +void TestCIsotope::test_read_4() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13C"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for isotope ratio.\n") == 0); +} + +void TestCIsotope::test_read_5() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13C -"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for isotope ratio.\n") == 0); +} + +void TestCIsotope::test_read_6() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13C -12."); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::OK); + CPPUNIT_ASSERT(oss_err.str().empty()); + + CPPUNIT_ASSERT(iso.get_name().compare("13C") == 0); + CPPUNIT_ASSERT(iso.get_ratio() == -12.0); + CPPUNIT_ASSERT(!iso.get_ratio_uncertainty_defined()); +} + +void TestCIsotope::test_read_7() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13C -12. a"); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for uncertainty in isotope ratio.\n") == 0); +} + +void TestCIsotope::test_read_8() +{ + CIsotope iso; + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream::pos_type next_pos; + std::vector opt_list; + + std::istringstream iss_in("isotope 13C -12. 1."); + + CParser parser(iss_in, oss_out, oss_err); + opt_list.push_back("isotope"); + + CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); + CPPUNIT_ASSERT(iso.read(parser) == CIsotope::OK); + CPPUNIT_ASSERT(oss_err.str().empty()); + + CPPUNIT_ASSERT(iso.get_name().compare("13C") == 0); + CPPUNIT_ASSERT(iso.get_ratio() == -12.0); + CPPUNIT_ASSERT(iso.get_ratio_uncertainty() == 1.0); + CPPUNIT_ASSERT(iso.get_ratio_uncertainty_defined()); +} diff --git a/classes/TestCIsotope.h b/classes/TestCIsotope.h new file mode 100644 index 00000000..97cdaebc --- /dev/null +++ b/classes/TestCIsotope.h @@ -0,0 +1,39 @@ +#if !defined(TESTCISOTOPE_H_INCLUDED) +#define TESTCISOTOPE_H_INCLUDED + +#include "Isotope.h" +#include +#include + + +class TestCIsotope : + public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( TestCIsotope ); + CPPUNIT_TEST( test_read_1 ); + CPPUNIT_TEST( test_read_2 ); + CPPUNIT_TEST( test_read_3 ); + CPPUNIT_TEST( test_read_4 ); + CPPUNIT_TEST( test_read_5 ); + CPPUNIT_TEST( test_read_6 ); + CPPUNIT_TEST( test_read_7 ); + CPPUNIT_TEST( test_read_8 ); + CPPUNIT_TEST_SUITE_END(); + +public: + TestCIsotope(void); + ~TestCIsotope(void); + +public: + // read + void test_read_1(); + void test_read_2(); + void test_read_3(); + void test_read_4(); + void test_read_5(); + void test_read_6(); + void test_read_7(); + void test_read_8(); +}; + +#endif // TESTCISOTOPE_H_INCLUDED diff --git a/classes/TestCParser.cxx b/classes/TestCParser.cxx new file mode 100644 index 00000000..4c3de473 --- /dev/null +++ b/classes/TestCParser.cxx @@ -0,0 +1,192 @@ +#include "TestCParser.h" +#include "Parser.h" + +TestCParser::TestCParser(void) +{ +} + +TestCParser::~TestCParser(void) +{ +} + +void TestCParser::testEmptyInput() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in(""); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); +} + +void TestCParser::testCommentOnlyInput() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("#this is a comment"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); +} + +void TestCParser::testLineContinuation() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("Line \\\n1"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); + CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); + CPPUNIT_ASSERT(parser.line().compare("") == 0); +} + +void TestCParser::testMultipleLineContinuation() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("Line \\\n\\\n\\\n\\\n1"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); + CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); + CPPUNIT_ASSERT(parser.line().compare("") == 0); +} + +void TestCParser::testLogicalLineSeparator() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("Line 1;Line 2"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); + CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); + CPPUNIT_ASSERT(parser.line().compare("Line 2") == 0); + + CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); + CPPUNIT_ASSERT(parser.line().compare("") == 0); +} + +void TestCParser::test_check_line_1() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("SOLUTION"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_KEYWORD); + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); + CPPUNIT_ASSERT(oss_out.str().compare("\tSOLUTION\n") == 0); +} + +void TestCParser::test_check_line_2() +{ + std::ostringstream oss_out; + std::ostringstream oss_err; + std::istringstream iss_in("NOT_A_KEYWORD"); + + CParser parser(iss_in, oss_out, oss_err); + + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_OK); + CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); +} + +void TestCParser::test_get_elt_1() +{ + std::istringstream iss_in; + std::ostringstream oss_out; + std::ostringstream oss_err; + + std::string token(""); + CParser parser(iss_in, oss_out, oss_err); + std::string::iterator begin = token.begin(); + std::string element; + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); + CPPUNIT_ASSERT(element.empty()); +} + +void TestCParser::test_get_elt_2() +{ + std::istringstream iss_in; + std::ostringstream oss_out; + std::ostringstream oss_err; + + std::string token("Ca"); + CParser parser(iss_in, oss_out, oss_err); + std::string::iterator begin = token.begin(); + std::string element; + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); + CPPUNIT_ASSERT(element.compare("Ca") == 0); + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); +} + +void TestCParser::test_get_elt_3() +{ + std::istringstream iss_in; + std::ostringstream oss_out; + std::ostringstream oss_err; + + std::string token("CaCO3"); + CParser parser(iss_in, oss_out, oss_err); + std::string::iterator begin = token.begin(); + std::string element; + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); + CPPUNIT_ASSERT(element.compare("Ca") == 0); + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); + CPPUNIT_ASSERT(element.compare("C") == 0); + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); + CPPUNIT_ASSERT(element.compare("O") == 0); +} + +void TestCParser::test_get_elt_4() +{ + std::istringstream iss_in; + std::ostringstream oss_out; + std::ostringstream oss_err; + + std::string token("[18O]"); + CParser parser(iss_in, oss_out, oss_err); + std::string::iterator begin = token.begin(); + std::string element; + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); + CPPUNIT_ASSERT(element.compare("[18O]") == 0); + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); +} + +void TestCParser::test_get_elt_5() +{ + std::istringstream iss_in; + std::ostringstream oss_out; + std::ostringstream oss_err; + + std::string token("[18O"); + CParser parser(iss_in, oss_out, oss_err); + std::string::iterator begin = token.begin(); + std::string element; + + CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); + CPPUNIT_ASSERT(oss_err.str().compare("ERROR: No ending bracket (]) for element name\n") == 0); +} diff --git a/classes/TestCParser.h b/classes/TestCParser.h new file mode 100644 index 00000000..315f0428 --- /dev/null +++ b/classes/TestCParser.h @@ -0,0 +1,48 @@ +#if !defined(TESTCPARSER_H_INCLUDED) +#define TESTCPARSER_H_INCLUDED + +#include +#include + +class TestCParser : + public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( TestCParser ); + CPPUNIT_TEST( testEmptyInput ); + CPPUNIT_TEST( testCommentOnlyInput ); + CPPUNIT_TEST( testLineContinuation ); + CPPUNIT_TEST( testMultipleLineContinuation ); + CPPUNIT_TEST( testLogicalLineSeparator ); + CPPUNIT_TEST( test_check_line_1 ); + CPPUNIT_TEST( test_check_line_2 ); + CPPUNIT_TEST( test_get_elt_1 ); + CPPUNIT_TEST( test_get_elt_2 ); + CPPUNIT_TEST( test_get_elt_3 ); + CPPUNIT_TEST( test_get_elt_4 ); + CPPUNIT_TEST( test_get_elt_5 ); + CPPUNIT_TEST_SUITE_END(); + +public: + TestCParser(void); + ~TestCParser(void); + +public: + void testEmptyInput(); + void testCommentOnlyInput(); + void testLineContinuation(); + void testMultipleLineContinuation(); + void testLogicalLineSeparator(); + + // check_line + void test_check_line_1(); + void test_check_line_2(); + + // get_elt + void test_get_elt_1(); + void test_get_elt_2(); + void test_get_elt_3(); + void test_get_elt_4(); + void test_get_elt_5(); + +}; +#endif // TESTCPARSER_H_INCLUDED diff --git a/classes/TestCSolution.cxx b/classes/TestCSolution.cxx new file mode 100644 index 00000000..cd30e0a8 --- /dev/null +++ b/classes/TestCSolution.cxx @@ -0,0 +1,124 @@ +#include "TestCSolution.h" +#include "Solution.h" +#include "Parser.h" +#include "utilities.h" +#include // std::cout std::cerr + +TestCSolution::TestCSolution() +{ +} + +TestCSolution::~TestCSolution() +{ +} + +CParser::LINE_TYPE read_input(CParser& parser) +{ + CParser::LINE_TYPE i; + while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) return CParser::LT_EOF; + } + + for (;;) { + switch(parser.next_keyword()) + { + case CParser::KT_END: + case CParser::KT_EOF: + case CParser::KT_NONE: + goto END_OF_SIMULATION_INPUT; + break; + + case CParser::KT_SOLUTION: + CSolution::read(parser); + break; + + default: + break; + } + } + +END_OF_SIMULATION_INPUT: + return CParser::LT_OK; +} + +void TestCSolution::test_read_ex1() +{ + CPPUNIT_ASSERT(CSolution::s_map.find(1) == CSolution::s_map.end()); + std::string input = + "SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979)\n" + " units ppm\n" + " pH 8.22\n" + " pe 8.451\n" + " density 1.023\n" + " temp 25.0\n" + " redox O(0)/O(-2)\n" + " Ca 412.3\n" + " Mg 1291.8\n" + " Na 10768.0\n" + " K 399.1\n" + " Fe 0.002\n" + " Mn 0.0002 pe\n" + " Si 4.28\n" + " Cl 19353.0\n" + " Alkalinity 141.682 as HCO3\n" + " S(6) 2712.0\n" + " N(5) 0.29 gfw 62.0\n" + " N(-3) 0.03 as NH4\n" + " U 3.3 ppb N(5)/N(-3)\n" + " O(0) 1.0 O2(g) -0.7\n" + ; + + // setup parser + std::istringstream iss_in(input); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + for (int simulation = 1; ; ++simulation) { + if (read_input(parser) == CParser::LT_EOF) break; + } + CPPUNIT_ASSERT(parser.get_input_error() == 0); + CPPUNIT_ASSERT(CSolution::s_map.size() == 1); + CPPUNIT_ASSERT(CSolution::s_map.find(1) != CSolution::s_map.end()); + + CPPUNIT_ASSERT(CSolution::s_map[1].get_units().compare("mg/kgs") == 0); + CPPUNIT_ASSERT_DOUBLES_EQUAL(8.22, CSolution::s_map[1].get_ph(), 0.005); + CPPUNIT_ASSERT_DOUBLES_EQUAL(8.451, CSolution::s_map[1].get_solution_pe(), 0.0005); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.023, CSolution::s_map[1].get_density(), 0.0005); + CPPUNIT_ASSERT_DOUBLES_EQUAL(25.0, CSolution::s_map[1].get_tc(), 0.5); + CPPUNIT_ASSERT(CSolution::s_map[1].get_redox().compare("O(-2)/O(0)") == 0); + + // empty map for subsequent tests + CSolution::s_map.erase(CSolution::s_map.begin(), CSolution::s_map.end()); +} + +void TestCSolution::test_read_ex7() +{ + CPPUNIT_ASSERT(CSolution::s_map.find(1) == CSolution::s_map.end()); + std::string input = + "SOLUTION 1\n" + ; + + // setup parser + std::istringstream iss_in(input); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + for (int simulation = 1; ; ++simulation) { + if (read_input(parser) == CParser::LT_EOF) break; + } + CPPUNIT_ASSERT(parser.get_input_error() == 0); + CPPUNIT_ASSERT(CSolution::s_map.size() == 1); + CPPUNIT_ASSERT(CSolution::s_map.find(1) != CSolution::s_map.end()); + + CPPUNIT_ASSERT(CSolution::s_map[1].get_units().compare("mMol/kgw") == 0); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(7.0, CSolution::s_map[1].get_ph(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, CSolution::s_map[1].get_solution_pe(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, CSolution::s_map[1].get_density(), 0.05); + CPPUNIT_ASSERT_DOUBLES_EQUAL(25.0, CSolution::s_map[1].get_tc(), 0.5); + CPPUNIT_ASSERT(CSolution::s_map[1].get_redox().compare("pe") == 0); + + // empty map for subsequent tests + CSolution::s_map.erase(CSolution::s_map.begin(), CSolution::s_map.end()); +} diff --git a/classes/TestCSolution.h b/classes/TestCSolution.h new file mode 100644 index 00000000..8bb8f3cb --- /dev/null +++ b/classes/TestCSolution.h @@ -0,0 +1,24 @@ +#if !defined(TESTCSOLUTION_H_INCLUDED) +#define TESTCSOLUTION_H_INCLUDED + +#include +#include + +class TestCSolution : + public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( TestCSolution ); + CPPUNIT_TEST( test_read_ex1 ); + CPPUNIT_TEST( test_read_ex7 ); + CPPUNIT_TEST_SUITE_END(); + +public: + TestCSolution(void); + ~TestCSolution(void); + +public: + void test_read_ex1(); + void test_read_ex7(); + +}; +#endif // TESTCSOLUTION_H_INCLUDED diff --git a/classes/main.cxx b/classes/main.cxx new file mode 100644 index 00000000..81acf510 --- /dev/null +++ b/classes/main.cxx @@ -0,0 +1,83 @@ +#include // std::cout std::cerr +#include // std::string +#include // std::vector +#include // std::map + +#include "Parser.h" +#include "Solution.h" + +CParser::LINE_TYPE read_input(CParser& parser) +{ + CParser::LINE_TYPE i; + while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) return CParser::LT_EOF; + } + + for (;;) { + switch(parser.next_keyword()) + { + case CParser::KT_END: + case CParser::KT_EOF: + case CParser::KT_NONE: + goto END_OF_SIMULATION_INPUT; + break; + + case CParser::KT_SOLUTION: + CSolution::read(parser); + break; + + default: + break; + } + } + +END_OF_SIMULATION_INPUT: + return CParser::LT_OK; +} + +int main(void) +{ + std::string input = + "SOLUTION 25 Test solution number 25\n" + " temp 25.0 \n" + " pH 7.0 charge \n" + " pe 4.5 \n" + " redox O(-2)/O(0) \n" + " units ppm \n" + " density 1.02 \n" + " Ca 80. \n" + " S(6) 96. as SO4 \n" + " S(-2) 1. as S \n" + " N(5) N(3) 14. as N \n" + " O(0) 8.0 \n" + " C 61.0 as HCO3 CO2(g) -3.5 \n" + " Fe 55. ug/kgs as Fe S(6)/S(-2) Pyrite \n" + " -isotope 13C -12. 1. # permil PDB \n" + " -isotope 34S 15. 1.5 # permil CDT \n" + " -water 0.5 # kg \n" + ; + + // setup parser + std::istringstream iss_in(input); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + for (int simulation = 1; ; ++simulation) { + if (read_input(parser) == CParser::LT_EOF) break; + } + + // dump solutions as xml string + std::ostringstream oss_tmp; + std::map::const_iterator it = CSolution::s_map.begin(); + for (; it != CSolution::s_map.end(); ++it) + { + (*it).second.dump_xml(oss_tmp); + } + oss_tmp << "\n"; + + // output xml string + std::cout << oss_tmp.str(); + + return 0; +} diff --git a/classes/test.cxx b/classes/test.cxx new file mode 100644 index 00000000..9046a76f --- /dev/null +++ b/classes/test.cxx @@ -0,0 +1,23 @@ +#include +#include + +#include "TestCParser.h" +#include "TestCIsotope.h" +#include "TestCSolution.h" + +int main(int argc, char **argv) +{ + CppUnit::TextUi::TestRunner runner; + + runner.addTest(TestCParser::suite()); + runner.addTest(TestCIsotope::suite()); + runner.addTest(TestCSolution::suite()); + + runner.setOutputter( + CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout) + ); + + bool wasSucessful = runner.run("", false); + return wasSucessful; +} + diff --git a/classes/utilities.cxx b/classes/utilities.cxx new file mode 100644 index 00000000..0a13b46d --- /dev/null +++ b/classes/utilities.cxx @@ -0,0 +1,68 @@ +#include // ::tolower +#include // ::tolower +#include //std::transform + +#include "utilities.h" +#include "Parser.h" + +//////////////////////////////////////////////////////////////////////////// +int utilities::strcmp_nocase_arg1(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 = ::tolower(*str1++)) == (c2 = *str2++)) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} + +//////////////////////////////////////////////////////////////////////////// +int utilities::strcmp_nocase(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 = ::tolower(*str1++)) == (c2 = ::tolower(*str2++))) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} + +//////////////////////////////////////////////////////////////////////////// +void utilities::str_tolower(std::string& str) +//////////////////////////////////////////////////////////////////////////// +{ + std::transform(str.begin(), str.end(), str.begin(), tolower); +} + + + +//////////////////////////////////////////////////////////////////////////// +bool utilities::replace(const char* str1, const char* str2, std::string& str) +//////////////////////////////////////////////////////////////////////////// +{ + std::string::size_type n = str.find(str1, 0); + if (n == std::string::npos) return false; + + str.replace(n, ::strlen(str1), str2); + return true; +} + +//////////////////////////////////////////////////////////////////////////// +void utilities::squeeze_white(std::string& s_l) +//////////////////////////////////////////////////////////////////////////// +{ + std::string str; + std::string::iterator beg = s_l.begin(); + std::string::iterator end = s_l.end(); + CParser::copy_token(str, beg, end); + s_l = str; +} + diff --git a/classes/utilities.h b/classes/utilities.h new file mode 100644 index 00000000..f4580d9d --- /dev/null +++ b/classes/utilities.h @@ -0,0 +1,28 @@ +#if !defined(UTILITIES_H_INCLUDED) +#define UTILITIES_H_INCLUDED + +#include + +namespace utilities { + + const char INDENT[] = " "; + + enum STATUS_TYPE { + OK = 0, + ERROR = 1 + }; + + STATUS_TYPE parse_couple(std::string& token); + + int strcmp_nocase(const char *str1, const char *str2); + + int strcmp_nocase_arg1(const char *str1, const char *str2); + + void str_tolower(std::string& str); + + bool replace(const char* str1, const char* str2, std::string& str); + + void squeeze_white(std::string& s_l); +} + +#endif // UTILITIES_H_INCLUDED diff --git a/cpp.dsw b/cpp.dsw new file mode 100644 index 00000000..fd89dcc2 --- /dev/null +++ b/cpp.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "cpp"=.\cpp.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/cvdense.cpp b/cvdense.cpp new file mode 100644 index 00000000..62538545 --- /dev/null +++ b/cvdense.cpp @@ -0,0 +1,473 @@ +/******************************************************************* + * * + * File : cvdense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for the CVODE dense linear * + * solver, CVDENSE. * + * * + *******************************************************************/ + + +#include +#include +#include +#include "cvdense.h" +#include "cvode.h" +#include "dense.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "sundialsmath.h" +#include "output.h" +#include "phqalloc.h" +/* WARNING don't include any headers below here */ +#define malloc PHRQ_malloc + +static char const svnid[] = "$Id: cvdense.c 78 2005-02-01 22:47:12Z dlpark $"; + +/* Error Messages */ + +#define CVDENSE "CVDense/CVReInitDense-- " + +#define MSG_CVMEM_NULL CVDENSE "CVode Memory is NULL.\n\n" + +#define MSG_MEM_FAIL CVDENSE "A memory request failed.\n\n" + +#define MSG_WRONG_NVEC CVDENSE "Incompatible NVECTOR implementation.\n\n" + +/* Other Constants */ + +#define MIN_INC_MULT RCONST(1000.0) +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) +#define TWO RCONST(2.0) + + +/****************************************************************** + * * + * Types : CVDenseMemRec, CVDenseMem * + *----------------------------------------------------------------* + * The type CVDenseMem is pointer to a CVDenseMemRec. This * + * structure contains CVDense solver-specific data. * + * * + ******************************************************************/ + +typedef struct { + + CVDenseJacFn d_jac; /* jac = Jacobian routine to be called */ + + DenseMat d_M; /* M = I - gamma J, gamma = h / l1 */ + + integertype *d_pivots; /* pivots = pivot array for PM = LU */ + + DenseMat d_savedJ; /* savedJ = old Jacobian */ + + long int d_nstlj; /* nstlj = nst at last Jacobian eval. */ + + long int d_nje; /* nje = no. of calls to jac */ + + void *d_J_data; /* J_data is passed to jac */ + +} CVDenseMemRec, *CVDenseMem; + + +/* CVDENSE linit, lsetup, lsolve, lfree, and DQJac routines */ + +static int CVDenseInit(CVodeMem cv_mem); + +static int CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + +static int CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, + N_Vector fcur); + +static void CVDenseFree(CVodeMem cv_mem); + +static void CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype t, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + +/*************** CVDenseDQJac **************************************** + + This routine generates a dense difference quotient approximation to + the Jacobian of f(t,y). It assumes that a dense matrix of type + DenseMat is stored column-wise, and that elements within each column + are contiguous. The address of the jth column of J is obtained via + the macro DENSE_COL and an N_Vector with the jth column as the + component array is created using N_VMake and N_VSetData. Finally, the + actual computation of the jth column of the Jacobian is done with a + call to N_VLinearSum. + +**********************************************************************/ + +static void CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype tn, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3) +{ + realtype fnorm, minInc, inc, inc_inv, yjsaved, srur; + realtype *y_data, *ewt_data; + N_Vector ftemp, jthCol; + M_Env machEnv; + integertype j; + + if (svnid == NULL) fprintf(stderr," "); + machEnv = y->menv; /* Get machine environment */ + + ftemp = vtemp1; /* Rename work vector for use as f vector value */ + + /* Obtain pointers to the data for ewt, y */ + ewt_data = N_VGetData(ewt); + y_data = N_VGetData(y); + + /* Set minimum increment based on uround and norm of f */ + srur = RSqrt(uround); + fnorm = N_VWrmsNorm(fy, ewt); + minInc = (fnorm != ZERO) ? + (MIN_INC_MULT * ABS(h) * uround * N * fnorm) : ONE; + + jthCol = N_VMake(N, y_data, machEnv); /* j loop overwrites this data address */ + + /* This is the only for loop for 0..N-1 in CVODE */ + for (j = 0; j < N; j++) { + + /* Generate the jth col of J(tn,y) */ + + N_VSetData(DENSE_COL(J,j), jthCol); + yjsaved = y_data[j]; + inc = MAX(srur*ABS(yjsaved), minInc/ewt_data[j]); + y_data[j] += inc; + f(N, tn, y, ftemp, f_data); + inc_inv = ONE/inc; + N_VLinearSum(inc_inv, ftemp, -inc_inv, fy, jthCol); + y_data[j] = yjsaved; + } + + N_VDispose(jthCol); + + /* Increment counter nfe = *nfePtr */ + *nfePtr += N; +} + + +/* Readability Replacements */ + +#define N (cv_mem->cv_N) +#define lmm (cv_mem->cv_lmm) +#define f (cv_mem->cv_f) +#define f_data (cv_mem->cv_f_data) +#define uround (cv_mem->cv_uround) +#define nst (cv_mem->cv_nst) +#define tn (cv_mem->cv_tn) +#define h (cv_mem->cv_h) +#define gamma (cv_mem->cv_gamma) +#define gammap (cv_mem->cv_gammap) +#define gamrat (cv_mem->cv_gamrat) +#define ewt (cv_mem->cv_ewt) +#define nfe (cv_mem->cv_nfe) +#define errfp (cv_mem->cv_errfp) +#define iopt (cv_mem->cv_iopt) +#define linit (cv_mem->cv_linit) +#define lsetup (cv_mem->cv_lsetup) +#define lsolve (cv_mem->cv_lsolve) +#define lfree (cv_mem->cv_lfree) +#define lmem (cv_mem->cv_lmem) +#define setupNonNull (cv_mem->cv_setupNonNull) +#define machenv (cv_mem->cv_machenv) + +#define jac (cvdense_mem->d_jac) +#define M (cvdense_mem->d_M) +#define pivots (cvdense_mem->d_pivots) +#define savedJ (cvdense_mem->d_savedJ) +#define nstlj (cvdense_mem->d_nstlj) +#define nje (cvdense_mem->d_nje) +#define J_data (cvdense_mem->d_J_data) + + +/*************** CVDense ********************************************* + + This routine initializes the memory record and sets various function + fields specific to the dense linear solver module. CVDense first + calls the existing lfree routine if this is not NULL. Then it sets + the cv_linit, cv_lsetup, cv_lsolve, cv_lfree fields in (*cvode_mem) + to be CVDenseInit, CVDenseSetup, CVDenseSolve, and CVDenseFree, + respectively. It allocates memory for a structure of type + CVDenseMemRec and sets the cv_lmem field in (*cvode_mem) to the + address of this structure. It sets setupNonNull in (*cvode_mem) to + TRUE, the d_J_data field in CVDenseMemRec to be the input + parameter jac_data, and the d_jac field to be: + (1) the input parameter djac if djac != NULL or + (2) CVDenseDQJac if djac == NULL. + Finally, it allocates memory for M, savedJ, and pivots. + The return value is SUCCESS = 0, or LMEM_FAIL = -1. + + NOTE: The dense linear solver assumes a serial implementation + of the NVECTOR package. Therefore, CVDense will first + test for compatible a compatible N_Vector internal + representation by checking (1) the machine environment + ID tag and (2) that the functions N_VMake, N_VDispose, + N_VGetData, and N_VSetData are implemented. + +**********************************************************************/ + +int CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) +{ + CVodeMem cv_mem; + CVDenseMem cvdense_mem; + + /* Return immediately if cvode_mem is NULL */ + cv_mem = (CVodeMem) cvode_mem; + if (cv_mem == NULL) { /* CVode reports this error */ + output_msg(OUTPUT_CVODE, MSG_CVMEM_NULL); + return(LMEM_FAIL); + } + + /* Test if the NVECTOR package is compatible with the DENSE solver */ + if ((strcmp(machenv->tag,"serial")) || + machenv->ops->nvmake == NULL || + machenv->ops->nvdispose == NULL || + machenv->ops->nvgetdata == NULL || + machenv->ops->nvsetdata == NULL) { + output_msg(OUTPUT_CVODE, MSG_WRONG_NVEC); + return(LMEM_FAIL); + } + + if (lfree !=NULL) lfree(cv_mem); + + /* Set four main function fields in cv_mem */ + linit = CVDenseInit; + lsetup = CVDenseSetup; + lsolve = CVDenseSolve; + lfree = CVDenseFree; + + /* Get memory for CVDenseMemRec */ + lmem = cvdense_mem = (CVDenseMem) malloc(sizeof(CVDenseMemRec)); + if (cvdense_mem == NULL) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + return(LMEM_FAIL); + } + + /* Set Jacobian routine field, J_data, and setupNonNull */ + if (djac == NULL) { + jac = CVDenseDQJac; + } else { + jac = djac; + } + J_data = jac_data; + setupNonNull = TRUE; + + /* Allocate memory for M, savedJ, and pivot array */ + + M = DenseAllocMat(N); + if (M == NULL) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + return(LMEM_FAIL); + } + savedJ = DenseAllocMat(N); + if (savedJ == NULL) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + DenseFreeMat(M); + return(LMEM_FAIL); + } + pivots = DenseAllocPiv(N); + if (pivots == NULL) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + DenseFreeMat(M); + DenseFreeMat(savedJ); + return(LMEM_FAIL); + } + + return(SUCCESS); +} + +/*************** CVReInitDense**************************************** + + This routine resets the link between the main CVODE module and the + dense linear solver module CVDENSE. No memory freeing or allocation + operations are done, as the existing linear solver memory is assumed + sufficient. All other initializations are the same as in CVDense. + The return value is SUCCESS = 0, or LMEM_FAIL = -1. + +**********************************************************************/ + +int CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) +{ + CVodeMem cv_mem; + CVDenseMem cvdense_mem; + + /* Return immediately if cvode_mem is NULL */ + cv_mem = (CVodeMem) cvode_mem; + if (cv_mem == NULL) { /* CVode reports this error */ + output_msg(OUTPUT_CVODE, MSG_CVMEM_NULL); + return(LMEM_FAIL); + } + + /* Test if the NVECTOR package is compatible with the DENSE solver */ + if ((strcmp(machenv->tag,"serial")) || + machenv->ops->nvmake == NULL || + machenv->ops->nvdispose == NULL || + machenv->ops->nvgetdata == NULL || + machenv->ops->nvsetdata == NULL) { + output_msg(OUTPUT_CVODE, MSG_WRONG_NVEC); + return(LMEM_FAIL); + } + + cvdense_mem = (CVDenseMem) lmem; /* Use existing linear solver memory pointer */ + + /* Set four main function fields in cv_mem */ + linit = CVDenseInit; + lsetup = CVDenseSetup; + lsolve = CVDenseSolve; + lfree = CVDenseFree; + + /* Set Jacobian routine field, J_data, and setupNonNull */ + if (djac == NULL) { + jac = CVDenseDQJac; + } else { + jac = djac; + } + J_data = jac_data; + setupNonNull = TRUE; + + return(SUCCESS); +} + +/*************** CVDenseInit ***************************************** + + This routine does remaining initializations specific to the dense + linear solver. + +**********************************************************************/ + +static int CVDenseInit(CVodeMem cv_mem) +{ + CVDenseMem cvdense_mem; + cvdense_mem = (CVDenseMem) lmem; + + /* Initialize nje and nstlj, and set workspace lengths */ + + nje = 0; + if (iopt != NULL) { + iopt[DENSE_NJE] = nje; + iopt[DENSE_LRW] = 2*N*N; + iopt[DENSE_LIW] = N; + } + nstlj = 0; + + return(LINIT_OK); +} + +/*************** CVDenseSetup **************************************** + + This routine does the setup operations for the dense linear solver. + It makes a decision whether or not to call the Jacobian evaluation + routine based on various state variables, and if not it uses the + saved copy. In any case, it constructs the Newton matrix + M = I - gamma*J, updates counters, and calls the dense LU + factorization routine. + +**********************************************************************/ + +static int CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, booleantype *jcurPtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) +{ + booleantype jbad, jok; + realtype dgamma; + integertype ier; + CVDenseMem cvdense_mem; + + cvdense_mem = (CVDenseMem) lmem; + + /* Use nst, gamma/gammap, and convfail to set J eval. flag jok */ + + dgamma = ABS((gamma/gammap) - ONE); + jbad = (nst == 0) || (nst > nstlj + CVD_MSBJ) || + ((convfail == FAIL_BAD_J) && (dgamma < CVD_DGMAX)) || + (convfail == FAIL_OTHER); + jok = !jbad; + + if (jok) { + /* If jok = TRUE, use saved copy of J */ + *jcurPtr = FALSE; + DenseCopy(savedJ, M); + } else { + /* If jok = FALSE, call jac routine for new J value */ + nje++; + if (iopt != NULL) iopt[DENSE_NJE] = nje; + nstlj = nst; + *jcurPtr = TRUE; + DenseZero(M); + jac(N, M, f, f_data, tn, ypred, fpred, ewt, h, + uround, J_data, &nfe, vtemp1, vtemp2, vtemp3); + DenseCopy(M, savedJ); + } + + /* Scale and add I to get M = I - gamma*J */ + DenseScale(-gamma, M); + DenseAddI(M); + + /* Do LU factorization of M */ + ier = DenseFactor(M, pivots); + + /* Return 0 if the LU was complete; otherwise return 1 */ + if (ier > 0) return(1); + return(0); +} + +/*************** CVDenseSolve **************************************** + + This routine handles the solve operation for the dense linear solver + by calling the dense backsolve routine. The returned value is 0. + +**********************************************************************/ + +static int CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, + N_Vector fcur) +{ + CVDenseMem cvdense_mem; + realtype *bd; + + cvdense_mem = (CVDenseMem) lmem; + + bd = N_VGetData(b); + DenseBacksolve(M, pivots, bd); + N_VSetData(bd, b); + + /* If BDF, scale the correction to account for change in gamma */ + if ((lmm == BDF) && (gamrat != ONE)) { + N_VScale(TWO/(ONE + gamrat), b, b); + } + + return(0); +} + +/*************** CVDenseFree ***************************************** + + This routine frees memory specific to the dense linear solver. + +**********************************************************************/ + +static void CVDenseFree(CVodeMem cv_mem) +{ + CVDenseMem cvdense_mem; + + cvdense_mem = (CVDenseMem) lmem; + + DenseFreeMat(M); + DenseFreeMat(savedJ); + DenseFreePiv(pivots); + free(cvdense_mem); +} diff --git a/cvdense.h b/cvdense.h new file mode 100644 index 00000000..af4931c0 --- /dev/null +++ b/cvdense.h @@ -0,0 +1,224 @@ +/******************************************************************* + * * + * File : cvdense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for the CVODE dense linear solver, * + * CVDENSE. * + * * + * Note: The type integertype must be large enough to store the * + * value of the linear system size N. * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidcvdense[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef _cvdense_h +#define _cvdense_h + + +#include +#include "cvode.h" +#include "sundialstypes.h" +#include "dense.h" +#include "nvector.h" + + +/****************************************************************** + * * + * CVDENSE solver statistics indices * + *----------------------------------------------------------------* + * The following enumeration gives a symbolic name to each * + * CVDENSE statistic. The symbolic names are used as indices into * + * the iopt and ropt arrays passed to CVodeMalloc. * + * The CVDENSE statistics are: * + * * + * iopt[DENSE_NJE] : number of Jacobian evaluations, i.e. of * + * calls made to the dense Jacobian routine * + * (default or user-supplied). * + * * + * iopt[DENSE_LRW] : size (in realtype words) of real workspace * + * matrices and vectors used by this solver. * + * * + * iopt[DENSE_LIW] : size (in integertype words) of integer * + * workspace vectors used by this solver. * + * * + ******************************************************************/ + +enum { DENSE_NJE=CVODE_IOPT_SIZE, DENSE_LRW, DENSE_LIW }; + + +/****************************************************************** + * * + * CVDENSE solver constants * + *----------------------------------------------------------------* + * CVD_MSBJ : maximum number of steps between dense Jacobian * + * evaluations * + * * + * CVD_DGMAX : maximum change in gamma between dense Jacobian * + * evaluations * + * * + ******************************************************************/ + +#define CVD_MSBJ 50 + +#define CVD_DGMAX RCONST(0.2) + + +/****************************************************************** + * * + * Type : CVDenseJacFn * + *----------------------------------------------------------------* + * A dense Jacobian approximation function Jac must have the * + * prototype given below. Its parameters are: * + * * + * N is the length of all vector arguments. * + * * + * J is the dense matrix (of type DenseMat) that will be loaded * + * by a CVDenseJacFn with an approximation to the Jacobian matrix * + * J = (df_i/dy_j) at the point (t,y). * + * J is preset to zero, so only the nonzero elements need to be * + * loaded. Two efficient ways to load J are: * + * * + * (1) (with macros - no explicit data structure references) * + * for (j=0; j < N; j++) { * + * col_j = DENSE_COL(J,j); * + * for (i=0; i < N; i++) { * + * generate J_ij = the (i,j)th Jacobian element * + * col_j[i] = J_ij; * + * } * + * } * + * * + * (2) (without macros - explicit data structure references) * + * for (j=0; j < N; j++) { * + * col_j = (J->data)[j]; * + * for (i=0; i < N; i++) { * + * generate J_ij = the (i,j)th Jacobian element * + * col_j[i] = J_ij; * + * } * + * } * + * * + * The DENSE_ELEM(A,i,j) macro is appropriate for use in small * + * problems in which efficiency of access is NOT a major concern. * + * * + * f is the right hand side function for the ODE problem. * + * * + * f_data is a pointer to user data to be passed to f, the same * + * as the F_data parameter passed to CVodeMalloc. * + * * + * t is the current value of the independent variable. * + * * + * y is the current value of the dependent variable vector, * + * namely the predicted value of y(t). * + * * + * fy is the vector f(t,y). * + * * + * ewt is the error weight vector. * + * * + * h is a tentative step size in t. * + * * + * uround is the machine unit roundoff. * + * * + * jac_data is a pointer to user data - the same as the jac_data * + * parameter passed to CVDense. * + * * + * nfePtr is a pointer to the memory location containing the * + * CVODE problem data nfe = number of calls to f. The Jacobian * + * routine should update this counter by adding on the number * + * of f calls made in order to approximate the Jacobian, if any. * + * For example, if the routine calls f a total of N times, then * + * the update is *nfePtr += N. * + * * + * vtemp1, vtemp2, and vtemp3 are pointers to memory allocated * + * for vectors of length N which can be used by a CVDenseJacFn * + * as temporary storage or work space. * + * * + ******************************************************************/ + +typedef void (*CVDenseJacFn)(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype t, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + +/****************************************************************** + * * + * Function : CVDense * + *----------------------------------------------------------------* + * A call to the CVDense function links the main CVODE integrator * + * with the CVDENSE linear solver. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * djac is the dense Jacobian approximation routine to be used. * + * A user-supplied djac routine must be of type * + * CVDenseJacFn. Pass NULL for djac to use the default * + * difference quotient routine CVDenseDQJac supplied * + * with this solver. * + * * + * jac_data is a pointer to user data which is passed to the * + * djac routine every time it is called. * + * * + * The return values of CVDense are: * + * SUCCESS = 0 if successful * + * LMEM_FAIL = -1 if there was a memory allocation failure * + * * + * NOTE: The dense linear solver assumes a serial implementation * + * of the NVECTOR package. Therefore, CVDense will first * + * test for a compatible N_Vector internal representation * + * by checking (1) the machine environment ID tag and * + * (2) that the functions N_VMake, N_VDispose, N_VGetData, * + * and N_VSetData are implemented. * + * * + ******************************************************************/ + +int CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); + + +/****************************************************************** + * * + * Function : CVReInitDense * + *----------------------------------------------------------------* + * A call to the CVReInitDense function resets the link between * + * the main CVODE integrator and the CVDENSE linear solver. * + * After solving one problem using CVDENSE, call CVReInit and then* + * CVReInitDense to solve another problem of the same size, if * + * there is a change in the CVDense parameters djac or jac_data. * + * If there is no change in parameters, it is not necessary to * + * call either CVReInitDense or CVDense for the new problem. * + * * + * All arguments to CVReInitDense have the same names and meanings* + * as those of CVDense. The cvode_mem argument must be identical * + * to its value in the previous CVDense call. * + * * + * The return values of CVReInitDense are: * + * SUCCESS = 0 if successful, or * + * LMEM_FAIL = -1 if the cvode_mem argument is NULL * + * * + * NOTE: CVReInitDense performs the same compatibility tests as * + * CVDense. * + * * + ******************************************************************/ + +int CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); + + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/cvode.cpp b/cvode.cpp new file mode 100644 index 00000000..b5c07e94 --- /dev/null +++ b/cvode.cpp @@ -0,0 +1,3330 @@ +/*#define DEBUG_CVODE*/ +extern char *error_string; +/******************************************************************* + * * + * File : cvode.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, * + * and Dan Shumaker @ LLNL * + * Version of : 24 July 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for the main CVODE integrator. * + * It is independent of the CVODE linear solver in use. * + * * + *******************************************************************/ + + +/************************************************************/ +/******************* BEGIN Imports **************************/ +/************************************************************/ + +#include +#include +#include "cvode.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "sundialsmath.h" +#include "output.h" +#define KINETICS_EXTERNAL +#include "kinetics.h" +#include "phqalloc.h" +/* WARNING don't include any headers below here */ +#define malloc PHRQ_malloc +static char const svnid[] = "$Id: cvode.c 663 2005-11-16 00:46:04Z dlpark $"; + +/************************************************************/ +/******************** END Imports ***************************/ +/************************************************************/ + + +/***************************************************************/ +/*********************** BEGIN Macros **************************/ +/***************************************************************/ + +/* Macro: loop */ + +#define loop for(;;) + +/***************************************************************/ +/************************ END Macros ***************************/ +/***************************************************************/ + + + +/************************************************************/ +/************** BEGIN CVODE Private Constants ***************/ +/************************************************************/ + +#define FOURTH RCONST(0.25) /* real 0.25 */ +#define THREE RCONST(3.0) /* real 3.0 */ +#define FOUR RCONST(4.0) /* real 4.0 */ +#define HUN RCONST(100.0) /* real 100.0 */ +#define TINY RCONST(1.0e-10) /* small number */ +#define HALF RCONST(0.5) /* real 0.5 */ +#define ZERO RCONST(0.0) /* real 0.0 */ +#define ONE RCONST(1.0) /* real 1.0 */ +#define TWO RCONST(2.0) /* real 2.0 */ +#define TWELVE RCONST(12.0) /* real 12.0 */ + +/***************************************************************/ +/************** BEGIN Default Constants ************************/ +/***************************************************************/ + +#define HMIN_DEFAULT ZERO /* hmin default value */ +#define HMAX_INV_DEFAULT ZERO /* hmax_inv default value */ +#define MXHNIL_DEFAULT 10 /* mxhnil default value */ +#define MXSTEP_DEFAULT 50 /* mxstep default value */ + + +/***************************************************************/ +/*************** END Default Constants *************************/ +/***************************************************************/ + + +/***************************************************************/ +/************ BEGIN Routine-Specific Constants *****************/ +/***************************************************************/ + +/* CVodeDky */ + +#define FUZZ_FACTOR RCONST(100.0) + +/* CVHin */ + +#define HLB_FACTOR RCONST(100.0) +#define HUB_FACTOR RCONST(0.1) +#define H_BIAS HALF +#define MAX_ITERS 4 + +/* CVSet */ + +#define CORTES RCONST(0.1) + +/* CVStep return values */ + +#define SUCCESS_STEP 0 +#define REP_ERR_FAIL -1 +#define REP_CONV_FAIL -2 +#define SETUP_FAILED -3 +#define SOLVE_FAILED -4 + +/* CVStep control constants */ + +#define PREDICT_AGAIN -5 +#define DO_ERROR_TEST 1 + +/* CVStep */ + +#define THRESH RCONST(1.5) +#define ETAMX1 RCONST(10000.0) +#define ETAMX2 RCONST(10.0) +#define ETAMX3 RCONST(10.0) +#define ETAMXF RCONST(0.2) +#define ETAMIN RCONST(0.1) +#define ETACF RCONST(0.25) +#define ADDON RCONST(0.000001) +#define BIAS1 RCONST(6.0) +#define BIAS2 RCONST(6.0) +#define BIAS3 RCONST(10.0) +#define ONEPSM RCONST(1.000001) + +#define SMALL_NST 10 /* nst > SMALL_NST => use ETAMX3 */ +#define MXNCF 10 /* max no. of convergence failures during */ + /* one step try */ +#define MXNEF 7 /* max no. of error test failures during */ + /* one step try */ +#define MXNEF1 3 /* max no. of error test failures before */ + /* forcing a reduction of order */ +#define SMALL_NEF 2 /* if an error failure occurs and */ + /* SMALL_NEF <= nef <= MXNEF1, then */ + /* reset eta = MIN(eta, ETAMXF) */ +#define LONG_WAIT 10 /* number of steps to wait before */ + /* considering an order change when */ + /* q==1 and MXNEF1 error test failures */ + /* have occurred */ + +/* CVnls return values */ + +#define SOLVED 0 +#define CONV_FAIL -1 +#define SETUP_FAIL_UNREC -2 +#define SOLVE_FAIL_UNREC -3 + +/* CVnls input flags */ + +#define FIRST_CALL 0 +#define PREV_CONV_FAIL -1 +#define PREV_ERR_FAIL -2 + +/* CVnls other constants */ + +#define FUNC_MAXCOR 3 /* maximum no. of corrector iterations */ + /* for iter == FUNCTIONAL */ +#define NEWT_MAXCOR 3 /* maximum no. of corrector iterations */ + /* for iter == NEWTON */ + +#define CRDOWN RCONST(0.3) /* constant used in the estimation of the */ + /* convergence rate (crate) of the */ + /* iterates for the nonlinear equation */ +#define DGMAX RCONST(0.3) /* iter == NEWTON, |gamma/gammap-1| > DGMAX */ + /* => call lsetup */ + +#define RDIV TWO /* declare divergence if ratio del/delp > RDIV */ +#define MSBP 20 /* max no. of steps between lsetup calls */ + +#define TRY_AGAIN 99 /* control constant for CVnlsNewton - should be */ + /* distinct from CVnls return values */ + + +/***************************************************************/ +/*************** END Routine-Specific Constants ***************/ +/***************************************************************/ + + +/***************************************************************/ +/***************** BEGIN Error Messages ************************/ +/***************************************************************/ + +/* CVodeMalloc/CVReInit Error Messages */ + +#define CVM "CVodeMalloc/CVReInit-- " + +#define MSG_Y0_NULL CVM "y0=NULL illegal.\n\n" + +#define MSG_BAD_N CVM "N=%ld < 1 illegal.\n\n" + +#define MSG_BAD_LMM_1 CVM "lmm=%d illegal.\n" +#define MSG_BAD_LMM_2 "The legal values are ADAMS=%d and BDF=%d.\n\n" +#define MSG_BAD_LMM MSG_BAD_LMM_1 MSG_BAD_LMM_2 + +#define MSG_BAD_ITER_1 CVM "iter=%d illegal.\n" +#define MSG_BAD_ITER_2 "The legal values are FUNCTIONAL=%d " +#define MSG_BAD_ITER_3 "and NEWTON=%d.\n\n" +#define MSG_BAD_ITER MSG_BAD_ITER_1 MSG_BAD_ITER_2 MSG_BAD_ITER_3 + +#define MSG_BAD_ITOL_1 CVM "itol=%d illegal.\n" +#define MSG_BAD_ITOL_2 "The legal values are SS=%d and SV=%d.\n\n" +#define MSG_BAD_ITOL MSG_BAD_ITOL_1 MSG_BAD_ITOL_2 + +#define MSG_F_NULL CVM "f=NULL illegal.\n\n" + +#define MSG_RELTOL_NULL CVM "reltol=NULL illegal.\n\n" + +#define MSG_BAD_RELTOL CVM "*reltol=%g < 0 illegal.\n\n" + +#define MSG_ABSTOL_NULL CVM "abstol=NULL illegal.\n\n" + +#define MSG_BAD_ABSTOL CVM "Some abstol component < 0.0 illegal.\n\n" + +#define MSG_BAD_OPTIN_1 CVM "optIn=%d illegal.\n" +#define MSG_BAD_OPTIN_2 "The legal values are FALSE=%d and TRUE=%d.\n\n" +#define MSG_BAD_OPTIN MSG_BAD_OPTIN_1 MSG_BAD_OPTIN_2 + +#define MSG_BAD_OPT CVM "optIn=TRUE, but iopt=ropt=NULL.\n\n" + +#define MSG_MEM_FAIL CVM "A memory request failed.\n\n" + +#define MSG_BAD_EWT CVM "Some initial ewt component = 0.0 illegal.\n\n" + +#define MSG_REI_NO_MEM "CVReInit-- cvode_mem = NULL illegal.\n\n" + +#define MSG_REI_MAXORD1 "CVReInit-- Illegal attempt to increase " +#define MSG_REI_MAXORD2 "maximum method order from %d to %d.\n\n" +#define MSG_REI_MAXORD MSG_REI_MAXORD1 MSG_REI_MAXORD2 + + +/* CVode error messages */ + +#define CVODE "CVode-- " + +#define NO_MEM "cvode_mem=NULL illegal.\n\n" + +#define MSG_CVODE_NO_MEM CVODE NO_MEM + +#define MSG_LINIT_NULL CVODE "The linear solver's init routine is NULL.\n\n" + +#define MSG_LSETUP_NULL CVODE "The linear solver's setup routine is NULL.\n\n" + +#define MSG_LSOLVE_NULL CVODE "The linear solver's solve routine is NULL.\n\n" + +#define MSG_LFREE_NULL CVODE "The linear solver's free routine is NULL.\n\n" + +#define MSG_LINIT_FAIL CVODE "The linear solver's init routine failed.\n\n" + +#define MSG_YOUT_NULL CVODE "yout=NULL illegal.\n\n" + +#define MSG_T_NULL CVODE "t=NULL illegal.\n\n" + +#define MSG_BAD_ITASK_1 CVODE "itask=%d illegal.\nThe legal values are" +#define MSG_BAD_ITASK_2 " NORMAL=%d and ONE_STEP=%d.\n\n" +#define MSG_BAD_ITASK MSG_BAD_ITASK_1 MSG_BAD_ITASK_2 + +#define MSG_BAD_HMIN_HMAX_1 CVODE "Inconsistent step size limits:\n" +#define MSG_BAD_HMIN_HMAX_2 "ropt[HMIN]=%g > ropt[HMAX]=%g.\n\n" +#define MSG_BAD_HMIN_HMAX MSG_BAD_HMIN_HMAX_1 MSG_BAD_HMIN_HMAX_2 + +#define MSG_BAD_H0 CVODE "h0=%g and tout-t0=%g inconsistent.\n\n" + +#define MSG_BAD_TOUT_1 CVODE "Trouble interpolating at tout = %g.\n" +#define MSG_BAD_TOUT_2 "tout too far back in direction of integration.\n\n" +#define MSG_BAD_TOUT MSG_BAD_TOUT_1 MSG_BAD_TOUT_2 + +#define MSG_MAX_STEPS_1 CVODE "At t=%g, mxstep=%d steps taken on " +#define MSG_MAX_STEPS_2 "this call before\nreaching tout=%g.\n\n" +#define MSG_MAX_STEPS MSG_MAX_STEPS_1 MSG_MAX_STEPS_2 + +#define MSG_EWT_NOW_BAD_1 CVODE "At t=%g, " +#define MSG_EWT_NOW_BAD_2 "some ewt component has become <= 0.0.\n\n" +#define MSG_EWT_NOW_BAD MSG_EWT_NOW_BAD_1 MSG_EWT_NOW_BAD_2 + +#define MSG_TOO_MUCH_ACC CVODE "At t=%g, too much accuracy requested.\n\n" + +#define MSG_HNIL_1 CVODE "Warning.. internal t=%g and step size h=%g\n" +#define MSG_HNIL_2 "are such that t + h == t on the next step.\n" +#define MSG_HNIL_3 "The solver will continue anyway.\n\n" +#define MSG_HNIL MSG_HNIL_1 MSG_HNIL_2 MSG_HNIL_3 + +#define MSG_HNIL_DONE_1 CVODE "The above warning has been issued %d times " +#define MSG_HNIL_DONE_2 "and will not be\nissued again for this problem.\n\n" +#define MSG_HNIL_DONE MSG_HNIL_DONE_1 MSG_HNIL_DONE_2 + +#define MSG_ERR_FAILS_1 CVODE "At t=%g and step size h=%g, the error test\n" +#define MSG_ERR_FAILS_2 "failed repeatedly or with |h| = hmin.\n\n" +#define MSG_ERR_FAILS MSG_ERR_FAILS_1 MSG_ERR_FAILS_2 + +#define MSG_CONV_FAILS_1 CVODE "At t=%g and step size h=%g, the corrector\n" +#define MSG_CONV_FAILS_2 "convergence failed repeatedly or " +#define MSG_CONV_FAILS_3 "with |h| = hmin.\n\n" +#define MSG_CONV_FAILS MSG_CONV_FAILS_1 MSG_CONV_FAILS_2 MSG_CONV_FAILS_3 + +#define MSG_SETUP_FAILED_1 CVODE "At t=%g, the setup routine failed in an " +#define MSG_SETUP_FAILED_2 "unrecoverable manner.\n\n" +#define MSG_SETUP_FAILED MSG_SETUP_FAILED_1 MSG_SETUP_FAILED_2 + +#define MSG_SOLVE_FAILED_1 CVODE "At t=%g, the solve routine failed in an " +#define MSG_SOLVE_FAILED_2 "unrecoverable manner.\n\n" +#define MSG_SOLVE_FAILED MSG_SOLVE_FAILED_1 MSG_SOLVE_FAILED_2 + +#define MSG_TOO_CLOSE_1 CVODE "tout=%g too close to t0=%g to start" +#define MSG_TOO_CLOSE_2 " integration.\n\n" +#define MSG_TOO_CLOSE MSG_TOO_CLOSE_1 MSG_TOO_CLOSE_2 + + +/* CVodeDky Error Messages */ + +#define DKY "CVodeDky-- " + +#define MSG_DKY_NO_MEM DKY NO_MEM + +#define MSG_BAD_K DKY "k=%d illegal.\n\n" + +#define MSG_BAD_T_1 DKY "t=%g illegal.\n" +#define MSG_BAD_T_2 "t not in interval tcur-hu=%g to tcur=%g.\n\n" +#define MSG_BAD_T MSG_BAD_T_1 MSG_BAD_T_2 + +#define MSG_BAD_DKY DKY "dky=NULL illegal.\n\n" + +/***************************************************************/ +/****************** END Error Messages *************************/ +/***************************************************************/ + + +/************************************************************/ +/*************** END CVODE Private Constants ****************/ +/************************************************************/ + + +/**************************************************************/ +/********* BEGIN Private Helper Functions Prototypes **********/ +/**************************************************************/ + +static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq, int maxord, + M_Env machEnv); +static void CVFreeVectors(CVodeMem cv_mem, int maxord); + +static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur); +static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur); +static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur); + +static booleantype CVHin(CVodeMem cv_mem, realtype tout); +static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist); +static realtype CVYddNorm(CVodeMem cv_mem, realtype hg); + +static int CVStep(CVodeMem cv_mem); + +static int CVsldet(CVodeMem cv_mem); + +static void CVAdjustParams(CVodeMem cv_mem); +static void CVAdjustOrder(CVodeMem cv_mem, int deltaq); +static void CVAdjustAdams(CVodeMem cv_mem, int deltaq); +static void CVAdjustBDF(CVodeMem cv_mem, int deltaq); +static void CVIncreaseBDF(CVodeMem cv_mem); +static void CVDecreaseBDF(CVodeMem cv_mem); + +static void CVRescale(CVodeMem cv_mem); + +static void CVPredict(CVodeMem cv_mem); + +static void CVSet(CVodeMem cv_mem); +static void CVSetAdams(CVodeMem cv_mem); +static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]); +static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], + realtype hsum); +static realtype CVAltSum(int iend, realtype a[], int k); +static void CVSetBDF(CVodeMem cv_mem); +static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, + realtype alpha0_hat, realtype xi_inv, realtype xistar_inv); + +static int CVnls(CVodeMem cv_mem, int nflag); +static int CVnlsFunctional(CVodeMem cv_mem); +static int CVnlsNewton(CVodeMem cv_mem, int nflag); +static int CVNewtonIteration(CVodeMem cv_mem); + +static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, + int *ncfPtr); + +static void CVRestore(CVodeMem cv_mem, realtype saved_t); + +static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, + realtype saved_t, int *nefPtr, realtype *dsmPtr); + +static void CVCompleteStep(CVodeMem cv_mem); + +static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm); +static void CVSetEta(CVodeMem cv_mem); +static realtype CVComputeEtaqm1(CVodeMem cv_mem); +static realtype CVComputeEtaqp1(CVodeMem cv_mem); +static void CVChooseEta(CVodeMem cv_mem); +static void CVBDFStab(CVodeMem cv_mem); + +static int CVHandleFailure(CVodeMem cv_mem,int kflag); + + +/**************************************************************/ +/********** END Private Helper Functions Prototypes ***********/ +/**************************************************************/ + + +/**************************************************************/ +/**************** BEGIN Readability Constants *****************/ +/**************************************************************/ + + +#define uround (cv_mem->cv_uround) +#define zn (cv_mem->cv_zn) +#define ewt (cv_mem->cv_ewt) +#define y (cv_mem->cv_y) +#define acor (cv_mem->cv_acor) +#define tempv (cv_mem->cv_tempv) +#define ftemp (cv_mem->cv_ftemp) +#define q (cv_mem->cv_q) +#define qprime (cv_mem->cv_qprime) +#define qwait (cv_mem->cv_qwait) +#define L (cv_mem->cv_L) +#define h (cv_mem->cv_h) +#define hprime (cv_mem->cv_hprime) +#define eta (cv_mem-> cv_eta) +#define etaqm1 (cv_mem-> cv_etaqm1) +#define etaq (cv_mem-> cv_etaq) +#define etaqp1 (cv_mem-> cv_etaqp1) +#define nscon (cv_mem->cv_nscon) +#define ssdat (cv_mem->cv_ssdat) +#define hscale (cv_mem->cv_hscale) +#define tn (cv_mem->cv_tn) +#define tau (cv_mem->cv_tau) +#define tq (cv_mem->cv_tq) +#define l (cv_mem->cv_l) +#define rl1 (cv_mem->cv_rl1) +#define gamma (cv_mem->cv_gamma) +#define gammap (cv_mem->cv_gammap) +#define gamrat (cv_mem->cv_gamrat) +#define crate (cv_mem->cv_crate) +#define acnrm (cv_mem->cv_acnrm) +#define mnewt (cv_mem->cv_mnewt) +#define qmax (cv_mem->cv_qmax) +#define mxstep (cv_mem->cv_mxstep) +#define maxcor (cv_mem->cv_maxcor) +#define mxhnil (cv_mem->cv_mxhnil) +#define hmin (cv_mem->cv_hmin) +#define hmax_inv (cv_mem->cv_hmax_inv) +#define etamax (cv_mem->cv_etamax) +#define nst (cv_mem->cv_nst) +#define nfe (cv_mem->cv_nfe) +#define ncfn (cv_mem->cv_ncfn) +#define netf (cv_mem->cv_netf) +#define nni (cv_mem-> cv_nni) +#define nsetups (cv_mem->cv_nsetups) +#define nhnil (cv_mem->cv_nhnil) +#define lrw (cv_mem->cv_lrw) +#define liw (cv_mem->cv_liw) +#define linit (cv_mem->cv_linit) +#define lsetup (cv_mem->cv_lsetup) +#define lsolve (cv_mem->cv_lsolve) +#define lfree (cv_mem->cv_lfree) +#define lmem (cv_mem->cv_lmem) +#define qu (cv_mem->cv_qu) +#define nstlp (cv_mem->cv_nstlp) +#define hu (cv_mem->cv_hu) +#define saved_tq5 (cv_mem->cv_saved_tq5) +#define jcur (cv_mem->cv_jcur) +#define tolsf (cv_mem->cv_tolsf) +#define setupNonNull (cv_mem->cv_setupNonNull) +#define machenv (cv_mem->cv_machenv) +#define sldeton (cv_mem->cv_sldeton) + +/**************************************************************/ +/***************** END Readability Constants ******************/ +/**************************************************************/ + + +/***************************************************************/ +/************* BEGIN CVODE Implementation **********************/ +/***************************************************************/ + + +/***************************************************************/ +/********* BEGIN Exported Functions Implementation *************/ +/***************************************************************/ + + +/******************** CVodeMalloc ******************************* + + CVodeMalloc allocates and initializes memory for a problem. All + problem specification inputs are checked for errors. If any + error occurs during initialization, it is reported to the file + whose file pointer is errfp and NULL is returned. Otherwise, the + pointer to successfully initialized problem memory is returned. + +*****************************************************************/ + +void *CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, + realtype *reltol, void *abstol, + void *f_data, FILE *errfp, booleantype optIn, + long int iopt[], realtype ropt[], M_Env machEnv) +{ + booleantype allocOK, ioptExists, roptExists, neg_abstol, ewtsetOK; + int maxord; + CVodeMem cv_mem; + FILE *fp; + int i,k; + + if (svnid == NULL) fprintf(stderr," "); + /* Check for legal input parameters */ + + fp = (errfp == NULL) ? stdout : errfp; + + if (y0==NULL) { + output_msg(OUTPUT_CVODE, MSG_Y0_NULL); + return(NULL); + } + + if (N <= 0) { + output_msg(OUTPUT_CVODE, MSG_BAD_N, N); + return(NULL); + } + + if ((lmm != ADAMS) && (lmm != BDF)) { + output_msg(OUTPUT_CVODE, MSG_BAD_LMM, lmm, ADAMS, BDF); + return(NULL); + } + + if ((iter != FUNCTIONAL) && (iter != NEWTON)) { + output_msg(OUTPUT_CVODE, MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON); + return(NULL); + } + + if ((itol != SS) && (itol != SV)) { + output_msg(OUTPUT_CVODE, MSG_BAD_ITOL, itol, SS, SV); + return(NULL); + } + + if (f == NULL) { + output_msg(OUTPUT_CVODE, MSG_F_NULL); + return(NULL); + } + + if (reltol == NULL) { + output_msg(OUTPUT_CVODE, MSG_RELTOL_NULL); + return(NULL); + } + + if (*reltol < ZERO) { + output_msg(OUTPUT_CVODE, MSG_BAD_RELTOL, (double) *reltol); + return(NULL); + } + + if (abstol == NULL) { + output_msg(OUTPUT_CVODE, MSG_ABSTOL_NULL); + return(NULL); + } + + if (itol == SS) { + neg_abstol = (*((realtype *)abstol) < ZERO); + } else { + neg_abstol = (N_VMin((N_Vector)abstol) < ZERO); + } + if (neg_abstol) { + output_msg(OUTPUT_CVODE, MSG_BAD_ABSTOL); + return(NULL); + } + + if ((optIn != FALSE) && (optIn != TRUE)) { + output_msg(OUTPUT_CVODE, MSG_BAD_OPTIN, optIn, FALSE, TRUE); + return(NULL); + } + + if ((optIn) && (iopt == NULL) && (ropt == NULL)) { + output_msg(OUTPUT_CVODE, MSG_BAD_OPT); + return(NULL); + } + + ioptExists = (iopt != NULL); + roptExists = (ropt != NULL); + + /* Compute maxord */ + + maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; + + if (optIn && ioptExists) { + if (iopt[MAXORD] > 0) maxord = MIN(maxord, iopt[MAXORD]); + } + + cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); + if (cv_mem == NULL) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + return(NULL); + } + + /* Allocate the vectors */ + + allocOK = CVAllocVectors(cv_mem, N, maxord, machEnv); + if (!allocOK) { + output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); + free(cv_mem); + return(NULL); + } + + /* Copy tolerances into memory, and set the ewt vector */ + + cv_mem->cv_itol = itol; + cv_mem->cv_reltol = reltol; + cv_mem->cv_abstol = abstol; + ewtsetOK = CVEwtSet(cv_mem, y0); + if (!ewtsetOK) { + output_msg(OUTPUT_CVODE, MSG_BAD_EWT); + CVFreeVectors(cv_mem, maxord); + free(cv_mem); + return(NULL); + } + + /* All error checking is complete at this point */ + + /* Copy the remaining input parameters into CVODE memory */ + + cv_mem->cv_N = N; + cv_mem->cv_f = f; + cv_mem->cv_f_data = f_data; + cv_mem->cv_lmm = lmm; + cv_mem->cv_iter = iter; + cv_mem->cv_optIn = optIn; + cv_mem->cv_iopt = iopt; + cv_mem->cv_ropt = ropt; + cv_mem->cv_errfp = fp; + tn = t0; + machenv = machEnv; + + /* Set step parameters */ + + q = 1; + L = 2; + qwait = L; + qmax = maxord; + etamax = ETAMX1; + + /* Set uround */ + + uround = UnitRoundoff(); + + /* Set the linear solver addresses to NULL. + (We check != NULL later, in CVode, if using NEWTON.) */ + + linit = NULL; + lsetup = NULL; + lsolve = NULL; + lfree = NULL; + lmem = NULL; + + /* Initialize zn[0] in the history array */ + + N_VScale(ONE, y0, zn[0]); + + /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ + + hmax_inv = HMAX_INV_DEFAULT; + hmin = HMIN_DEFAULT; + if (optIn && roptExists) { + if (ropt[HMIN] > ZERO) hmin = ropt[HMIN]; + } + + mxhnil = MXHNIL_DEFAULT; + mxstep = MXSTEP_DEFAULT; + if (optIn && ioptExists) { + if (iopt[MXHNIL] != 0) mxhnil = iopt[MXHNIL]; + if (iopt[MXSTEP] > 0) mxstep = iopt[MXSTEP]; + } + + if ((!optIn) && roptExists) ropt[H0] = ZERO; + + /* Set maxcor */ + + maxcor = (iter==NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; + + /* Initialize all the counters */ + + nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; + + /* Initialize all other variables corresponding to optional outputs */ + + qu = 0; + hu = ZERO; + tolsf = ONE; + + /* Initialize optional output locations in iopt, ropt */ + /* and Stablilty Limit Detection data. */ + + nscon = 0; + sldeton = FALSE; + if (ioptExists) { + iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; + iopt[NCFN] = iopt[NETF] = 0; + iopt[QU] = qu; + iopt[QCUR] = 0; + iopt[LENRW] = lrw; + iopt[LENIW] = liw; + if(optIn && iopt[SLDET] && (lmm == BDF)) { + sldeton = TRUE; + iopt[NOR] = 0; + for (i = 1; i <= 5; i++) { + for (k = 1; k <= 3; k++) ssdat[i-1][k-1] = ZERO;} + } + } + + if (roptExists) { + ropt[HU] = hu; + ropt[HCUR] = ZERO; + ropt[TCUR] = t0; + ropt[TOLSF] = tolsf; + } + + + /* Problem has been successfully initialized */ + + return((void *)cv_mem); +} + + +/******************** CVReInit ********************************** + + CVReInit re-initializes CVODE's memory for a problem, assuming + it has already been allocated in a prior CVodeMalloc call. + All problem specification inputs are checked for errors. + The problem size N is assumed to be unchanged since the call to + CVodeMalloc, and the maximum order maxord must not be larger. + If any error occurs during initialization, it is reported to the + file whose file pointer is errfp. + The return value is SUCCESS = 0 if no errors occurred, or + a negative value otherwise. + +*****************************************************************/ + +int CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, + realtype *reltol, void *abstol, + void *f_data, FILE *errfp, booleantype optIn, + long int iopt[], realtype ropt[], M_Env machEnv) +{ + booleantype ioptExists, roptExists, neg_abstol, ewtsetOK; + int maxord, i,k; + CVodeMem cv_mem; + FILE *fp; + + /* Check for legal input parameters */ + + fp = (errfp == NULL) ? stdout : errfp; + + if (cvode_mem == NULL) { + output_msg(OUTPUT_CVODE, MSG_REI_NO_MEM); + return(CVREI_NO_MEM); + } + cv_mem = (CVodeMem) cvode_mem; + + if (y0 == NULL) { + output_msg(OUTPUT_CVODE, MSG_Y0_NULL); + return(CVREI_ILL_INPUT); + } + + if ((lmm != ADAMS) && (lmm != BDF)) { + output_msg(OUTPUT_CVODE, MSG_BAD_LMM, lmm, ADAMS, BDF); + return(CVREI_ILL_INPUT); + } + + if ((iter != FUNCTIONAL) && (iter != NEWTON)) { + output_msg(OUTPUT_CVODE, MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON); + return(CVREI_ILL_INPUT); + } + + if ((itol != SS) && (itol != SV)) { + output_msg(OUTPUT_CVODE, MSG_BAD_ITOL, itol, SS, SV); + return(CVREI_ILL_INPUT); + } + + if (f == NULL) { + output_msg(OUTPUT_CVODE, MSG_F_NULL); + return(CVREI_ILL_INPUT); + } + + if (reltol == NULL) { + output_msg(OUTPUT_CVODE, MSG_RELTOL_NULL); + return(CVREI_ILL_INPUT); + } + + if (*reltol < ZERO) { + output_msg(OUTPUT_CVODE, MSG_BAD_RELTOL,(double) *reltol); + return(CVREI_ILL_INPUT); + } + + if (abstol == NULL) { + output_msg(OUTPUT_CVODE, MSG_ABSTOL_NULL); + return(CVREI_ILL_INPUT); + } + + if (itol == SS) { + neg_abstol = (*((realtype *)abstol) < ZERO); + } else { + neg_abstol = (N_VMin((N_Vector)abstol) < ZERO); + } + if (neg_abstol) { + output_msg(OUTPUT_CVODE, MSG_BAD_ABSTOL); + return(CVREI_ILL_INPUT); + } + + if ((optIn != FALSE) && (optIn != TRUE)) { + output_msg(OUTPUT_CVODE, MSG_BAD_OPTIN, optIn, FALSE, TRUE); + return(CVREI_ILL_INPUT); + } + + if ((optIn) && (iopt == NULL) && (ropt == NULL)) { + output_msg(OUTPUT_CVODE, MSG_BAD_OPT); + return(CVREI_ILL_INPUT); + } + + ioptExists = (iopt != NULL); + roptExists = (ropt != NULL); + + /* Compute new maxord and check against old value */ + + maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; + if (optIn && ioptExists) + { if (iopt[MAXORD] > 0) maxord = MIN(maxord, iopt[MAXORD]); } + if (maxord > qmax) { + output_msg(OUTPUT_CVODE, MSG_REI_MAXORD, qmax, maxord); + return(CVREI_ILL_INPUT); + } + + /* Copy tolerances into memory, and set the ewt vector */ + + cv_mem->cv_itol = itol; + cv_mem->cv_reltol = reltol; + cv_mem->cv_abstol = abstol; + ewtsetOK = CVEwtSet(cv_mem, y0); + if (!ewtsetOK) { + output_msg(OUTPUT_CVODE, MSG_BAD_EWT); + return(CVREI_ILL_INPUT); + } + + /* All error checking is complete at this point */ + + /* Copy the remaining input parameters into CVODE memory */ + + cv_mem->cv_f = f; + cv_mem->cv_f_data = f_data; + cv_mem->cv_lmm = lmm; + cv_mem->cv_iter = iter; + cv_mem->cv_optIn = optIn; + cv_mem->cv_iopt = iopt; + cv_mem->cv_ropt = ropt; + cv_mem->cv_errfp = fp; + tn = t0; + machenv = machEnv; + + /* Set step parameters */ + + q = 1; + L = 2; + qwait = L; + qmax = maxord; + etamax = ETAMX1; + + /* Set uround */ + + uround = UnitRoundoff(); + + /* Initialize zn[0] in the history array */ + + N_VScale(ONE, y0, zn[0]); + + /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ + + hmax_inv = HMAX_INV_DEFAULT; + hmin = HMIN_DEFAULT; + if (optIn && roptExists) { + if (ropt[HMIN] > ZERO) hmin = ropt[HMIN]; + } + + mxhnil = MXHNIL_DEFAULT; + mxstep = MXSTEP_DEFAULT; + if (optIn && ioptExists) { + if (iopt[MXHNIL] != 0) mxhnil = iopt[MXHNIL]; + if (iopt[MXSTEP] > 0) mxstep = iopt[MXSTEP]; + } + + if ((!optIn) && roptExists) ropt[H0] = ZERO; + + /* Set maxcor */ + + maxcor = (iter==NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; + + /* Initialize all the counters */ + + nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; + + /* Initialize all other vars corresponding to optional outputs */ + + qu = 0; + hu = ZERO; + tolsf = ONE; + + /* Initialize optional output locations in iopt, ropt */ + /* and Stablilty Limit Detection data. */ + + nscon = 0; + sldeton = FALSE; + if (ioptExists) { + iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; + iopt[NCFN] = iopt[NETF] = 0; + iopt[QU] = qu; + iopt[QCUR] = 0; + iopt[LENRW] = lrw; + iopt[LENIW] = liw; + if(optIn && iopt[SLDET] && (lmm == BDF)) { + sldeton = TRUE; + iopt[NOR] = 0; + for (i = 1; i <= 5; i++) { + for (k = 1; k <= 3; k++) ssdat[i-1][k-1] = ZERO;} + } + } + + if (roptExists) { + ropt[HU] = hu; + ropt[HCUR] = ZERO; + ropt[TCUR] = t0; + ropt[TOLSF] = tolsf; + } + + /* Problem has been successfully re-initialized */ + + return(SUCCESS); +} + + +/**************************************************************/ +/************** BEGIN More Readability Constants **************/ +/**************************************************************/ + +#define N (cv_mem->cv_N) +#define f (cv_mem->cv_f) +#define f_data (cv_mem->cv_f_data) +#define lmm (cv_mem->cv_lmm) +#define iter (cv_mem->cv_iter) +#define itol (cv_mem->cv_itol) +#define reltol (cv_mem->cv_reltol) +#define abstol (cv_mem->cv_abstol) +#define optIn (cv_mem->cv_optIn) +#define iopt (cv_mem->cv_iopt) +#define ropt (cv_mem->cv_ropt) +#define errfp (cv_mem->cv_errfp) + +/**************************************************************/ +/*************** END More Readability Constants ***************/ +/**************************************************************/ + + +/********************* CVode **************************************** + + This routine is the main driver of the CVODE package. + + It integrates over a time interval defined by the user, by calling + CVStep to do internal time steps. + + The first time that CVode is called for a successfully initialized + problem, it computes a tentative initial step size h. + + CVode supports two modes, specified by itask: NORMAL and ONE_STEP. + In the NORMAL mode, the solver steps until it reaches or passes tout + and then interpolates to obtain y(tout). + In the ONE_STEP mode, it takes one internal step and returns. + +********************************************************************/ + +int CVode(void *cvode_mem, realtype tout, N_Vector yout, + realtype *t, int itask) +{ + int nstloc, kflag, istate, next_q, ier; + realtype rh, next_h; + booleantype hOK, ewtsetOK; + CVodeMem cv_mem; + realtype t0; + + /* Check for legal inputs in all cases */ + + cv_mem = (CVodeMem) cvode_mem; + if (cvode_mem == NULL) { + output_msg(OUTPUT_CVODE, MSG_CVODE_NO_MEM); + return(CVODE_NO_MEM); + } + + if ((y = yout) == NULL) { + output_msg(OUTPUT_CVODE, MSG_YOUT_NULL); + return(ILL_INPUT); + } + + if (t == NULL) { + output_msg(OUTPUT_CVODE, MSG_T_NULL); + return(ILL_INPUT); + } + t0 = tn; + *t = tn; + + if ((itask != NORMAL) && (itask != ONE_STEP)) { + output_msg(OUTPUT_CVODE, MSG_BAD_ITASK, itask, NORMAL, ONE_STEP); + return(ILL_INPUT); + } + + /* Set hmax_inv from ropt[HMAX] and test for hmin > hmax */ + + if (optIn && ropt != NULL) { + if (ropt[HMAX] > ZERO) hmax_inv = ONE/ropt[HMAX]; + if (hmin*hmax_inv > ONE) { + output_msg(OUTPUT_CVODE, MSG_BAD_HMIN_HMAX, (double) hmin, (double) ropt[HMAX]); + return(ILL_INPUT); + } + } + + /* On first call, check solver functions and call linit function */ + + if (nst == 0) { + if (iter == NEWTON) { + if (linit == NULL) { + output_msg(OUTPUT_CVODE, MSG_LINIT_NULL); + return(ILL_INPUT); + } + if (lsetup == NULL) { + output_msg(OUTPUT_CVODE, MSG_LSETUP_NULL); + return(ILL_INPUT); + } + if (lsolve == NULL) { + output_msg(OUTPUT_CVODE, MSG_LSOLVE_NULL); + return(ILL_INPUT); + } + if (lfree == NULL) { + output_msg(OUTPUT_CVODE, MSG_LFREE_NULL); + return(ILL_INPUT); + } + ier = linit(cv_mem); + if (ier != LINIT_OK) { + output_msg(OUTPUT_CVODE, MSG_LINIT_FAIL); + return(ILL_INPUT); + } + } + + /* On the first call, call f at (t0,y0), set zn[1] = y'(t0), + set initial h (from H0 or CVHin), and scale zn[1] by h */ + cvode_rate_sim_time = cvode_rate_sim_time_start + tn; + cvode_step_fraction = 0; + + f(N, tn, zn[0], zn[1], f_data); + nfe = 1; + h = ZERO; + if (ropt != NULL) h = ropt[H0]; + if ( (h != ZERO) && ((tout-tn)*h < ZERO) ) { + output_msg(OUTPUT_CVODE, MSG_BAD_H0, (double) h, (double) (tout-tn)); + return(ILL_INPUT); + } + if (h == ZERO) { + hOK = CVHin(cv_mem, tout); + if (!hOK) { + output_msg(OUTPUT_CVODE, MSG_TOO_CLOSE, (double) tout, (double) tn); + return(ILL_INPUT); + } + } + rh = ABS(h)*hmax_inv; + if (rh > ONE) h /= rh; + if (ABS(h) < hmin) h *= hmin/ABS(h); + hscale = h; + N_VScale(h, zn[1], zn[1]); + + } /* end of first call block */ + + /* If not the first call, check if tout already reached */ + + if ( (itask == NORMAL) && (nst > 0) && ((tn-tout)*h >= ZERO) ) { + *t = tout; + ier = CVodeDky(cv_mem, tout, 0, yout); + if (ier != OKAY) { /* ier must be == BAD_T */ + output_msg(OUTPUT_CVODE, MSG_BAD_TOUT, (double) tout); + return(ILL_INPUT); + } + return(SUCCESS); + } + + /* Looping point for internal steps */ + + nstloc = 0; + loop { + + next_h = h; + next_q = q; + + /* Reset and check ewt */ + + if (nst > 0) { + ewtsetOK = CVEwtSet(cv_mem, zn[0]); + if (!ewtsetOK) { + output_msg(OUTPUT_CVODE, MSG_EWT_NOW_BAD, (double) tn); + istate = ILL_INPUT; + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + } + + /* Check for too many steps */ + + if (nstloc >= mxstep) { + /* output_msg(OUTPUT_CVODE, MSG_MAX_STEPS, tn, mxstep, tout); */ + istate = TOO_MUCH_WORK; + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + + /* Check for too much accuracy requested */ + + if ((tolsf = uround * N_VWrmsNorm(zn[0], ewt)) > ONE) { + output_msg(OUTPUT_CVODE, MSG_TOO_MUCH_ACC, (double) tn); + istate = TOO_MUCH_ACC; + *t = tn; + N_VScale(ONE, zn[0], yout); + tolsf *= TWO; + break; + } + + /* Check for h below roundoff level in tn */ + + if (tn + h == tn) { + nhnil++; + if (nhnil <= mxhnil) output_msg(OUTPUT_CVODE, MSG_HNIL, (double) tn, (double) h); + if (nhnil == mxhnil) output_msg(OUTPUT_CVODE, MSG_HNIL_DONE, mxhnil); + } + + /* Call CVStep to take a step */ + + kflag = CVStep(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After CVStep, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After CVStep, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After CVStep, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After CVStep, zn OK\n"); + } +#endif + /* Process failed step cases, and exit loop */ + + if (kflag != SUCCESS_STEP) { + istate = CVHandleFailure(cv_mem, kflag); + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + + nstloc++; + + /* Check if in one-step mode, and if so copy y and exit loop */ + + if (itask == ONE_STEP) { + istate = SUCCESS; + *t = tn; + N_VScale(ONE, zn[0], yout); + next_q = qprime; + next_h = hprime; + break; + } + cvode_rate_sim_time = cvode_rate_sim_time_start + tn; + cvode_step_fraction = (tn - t0)/(tout - t0); + /* + output_msg(OUTPUT_CVODE, "ODE: tn %e, t0 %e, tout %e, step_frac %e\n", (double) tn, (double) t0, (double) tout, (double) cvode_step_fraction); + */ + /* Check if tout reached, and if so interpolate and exit loop */ + + if ((tn-tout)*h >= ZERO) { + /* + output_msg(OUTPUT_CVODE, "*tn %e, t0 %e, tout %e, h %e\n", tn, t0, tout,h); + */ + cvode_rate_sim_time = cvode_rate_sim_time_start + tout; + cvode_step_fraction = 1.0; + istate = SUCCESS; + *t = tout; + (void) CVodeDky(cv_mem, tout, 0, yout); + next_q = qprime; + next_h = hprime; + break; + } + } + + /* End of step loop; load optional outputs and return */ + + if (iopt != NULL) { + iopt[NST] = nst; + iopt[NFE] = nfe; + iopt[NSETUPS] = nsetups; + iopt[NNI] = nni; + iopt[NCFN] = ncfn; + iopt[NETF] = netf; + iopt[QU] = q; + iopt[QCUR] = next_q; + } + + if (ropt != NULL) { + ropt[HU] = h; + ropt[HCUR] = next_h; + ropt[TCUR] = tn; + ropt[TOLSF] = tolsf; + } +#ifdef DEBUG_CVODE + /* + * check interpolation + */ + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"End of cvode, Interpolated y Fail\n"); + return(-1); + } else { + output_msg(OUTPUT_CVODE,"End of cvode, Interpolated y OK\n"); + } +#endif + return(istate); +} + +/*************** CVodeDky ******************************************** + + This routine computes the k-th derivative of the interpolating + polynomial at the time t and stores the result in the vector dky. + The formula is: + q + dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] , + j=k + where c(j,k) = j*(j-1)*...*(j-k+1), q is the current order, and + zn[j] is the j-th column of the Nordsieck history array. + + This function is called by CVode with k = 0 and t = tout, but + may also be called directly by the user. + +**********************************************************************/ + +int CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky) +{ + realtype s, c, r; + realtype tfuzz, tp, tn1; + int i, j; + CVodeMem cv_mem; + + cv_mem = (CVodeMem) cvode_mem; + + /* Check all inputs for legality */ + + if (cvode_mem == NULL) { + output_msg(OUTPUT_CVODE, MSG_DKY_NO_MEM); + return(DKY_NO_MEM); + } + + if (dky == NULL) { + output_msg(OUTPUT_CVODE, MSG_BAD_DKY); + return(BAD_DKY); + } + + if ((k < 0) || (k > q)) { + output_msg(OUTPUT_CVODE, MSG_BAD_K, k); + return(BAD_K); + } + + tfuzz = FUZZ_FACTOR * uround * (ABS(tn) + ABS(hu)); + if (hu < ZERO) tfuzz = -tfuzz; + tp = tn - hu - tfuzz; + tn1 = tn + tfuzz; + if ((t-tp)*(t-tn1) > ZERO) { + output_msg(OUTPUT_CVODE, MSG_BAD_T, (double) t, (double) (tn-hu), (double) tn); + return(BAD_T); + } + + /* Sum the differentiated interpolating polynomial */ + + s = (t - tn) / h; + for (j=q; j >= k; j--) { + c = ONE; + for (i=j; i >= j-k+1; i--) c *= i; + if (j == q) { + N_VScale(c, zn[q], dky); + } else { + N_VLinearSum(c, zn[j], s, dky, dky); + } + } + if (k == 0) return(OKAY); + r = RPowerI(h,-k); + N_VScale(r, dky, dky); + return(OKAY); +} + +/********************* CVodeFree ********************************** + + This routine frees the problem memory allocated by CVodeMalloc. + Such memory includes all the vectors allocated by CVAllocVectors, + and the memory lmem for the linear solver (deallocated by a call + to lfree). + +*******************************************************************/ + +void CVodeFree(void *cvode_mem) +{ + CVodeMem cv_mem; + + cv_mem = (CVodeMem) cvode_mem; + + if (cvode_mem == NULL) return; + + CVFreeVectors(cv_mem, qmax); + if (iter == NEWTON) lfree(cv_mem); + free(cv_mem); +} + + +/***************************************************************/ +/********** END Exported Functions Implementation **************/ +/***************************************************************/ + + +/*******************************************************************/ +/******** BEGIN Private Helper Functions Implementation ************/ +/*******************************************************************/ + +/****************** CVAllocVectors *********************************** + + This routine allocates the CVODE vectors ewt, acor, tempv, ftemp, and + zn[0], ..., zn[maxord]. The length of the vectors is the input + parameter neq and the maximum order (needed to allocate zn) is the + input parameter maxord. If all memory allocations are successful, + CVAllocVectors returns TRUE. Otherwise all allocated memory is freed + and CVAllocVectors returns FALSE. + This routine also sets the optional outputs lrw and liw, which are + (respectively) the lengths of the real and integer work spaces + allocated here. + +**********************************************************************/ + +static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq, + int maxord, M_Env machEnv) +{ + int i, j; + + /* Allocate ewt, acor, tempv, ftemp */ + + ewt = N_VNew(neq, machEnv); + if (ewt == NULL) return(FALSE); + acor = N_VNew(neq, machEnv); + if (acor == NULL) { + N_VFree(ewt); + return(FALSE); + } + tempv = N_VNew(neq, machEnv); + if (tempv == NULL) { + N_VFree(ewt); + N_VFree(acor); + return(FALSE); + } + ftemp = N_VNew(neq, machEnv); + if (ftemp == NULL) { + N_VFree(tempv); + N_VFree(ewt); + N_VFree(acor); + return(FALSE); + } + + /* Allocate zn[0] ... zn[maxord] */ + + for (j=0; j <= maxord; j++) { + zn[j] = N_VNew(neq, machEnv); + if (zn[j] == NULL) { + N_VFree(ewt); + N_VFree(acor); + N_VFree(tempv); + N_VFree(ftemp); + for (i=0; i < j; i++) N_VFree(zn[i]); + return(FALSE); + } + } + + /* Set solver workspace lengths */ + + lrw = (maxord + 5)*neq; + liw = 0; + + return(TRUE); +} + +/***************** CVFreeVectors ********************************* + + This routine frees the CVODE vectors allocated in CVAllocVectors. + +******************************************************************/ + +static void CVFreeVectors(CVodeMem cv_mem, int maxord) +{ + int j; + + N_VFree(ewt); + N_VFree(acor); + N_VFree(tempv); + N_VFree(ftemp); + for(j=0; j <= maxord; j++) N_VFree(zn[j]); +} + +/*********************** CVEwtSet ************************************** + + This routine is responsible for setting the error weight vector ewt, + according to tol_type, as follows: + + (1) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + *abstol), i=0,...,neq-1 + if tol_type = SS + (2) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + abstol[i]), i=0,...,neq-1 + if tol_type = SV + + CVEwtSet returns TRUE if ewt is successfully set as above to a + positive vector and FALSE otherwise. In the latter case, ewt is + considered undefined after the FALSE return from CVEwtSet. + + All the real work is done in the routines CVEwtSetSS, CVEwtSetSV. + +***********************************************************************/ + +static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur) +{ + switch(itol) { + case SS: return(CVEwtSetSS(cv_mem, ycur)); + case SV: return(CVEwtSetSV(cv_mem, ycur)); + } + return(-99); +} + +/*********************** CVEwtSetSS ********************************* + + This routine sets ewt as decribed above in the case tol_type = SS. + It tests for non-positive components before inverting. CVEwtSetSS + returns TRUE if ewt is successfully set to a positive vector + and FALSE otherwise. In the latter case, ewt is considered + undefined after the FALSE return from CVEwtSetSS. + +********************************************************************/ + +static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur) +{ + realtype rtoli, atoli; + + rtoli = *reltol; + atoli = *((realtype *)abstol); + N_VAbs(ycur, tempv); + N_VScale(rtoli, tempv, tempv); + N_VAddConst(tempv, atoli, tempv); + if (N_VMin(tempv) <= ZERO) return(FALSE); + N_VInv(tempv, ewt); + return(TRUE); +} + +/*********************** CVEwtSetSV ********************************* + + This routine sets ewt as decribed above in the case tol_type = SV. + It tests for non-positive components before inverting. CVEwtSetSV + returns TRUE if ewt is successfully set to a positive vector + and FALSE otherwise. In the latter case, ewt is considered + undefined after the FALSE return from CVEwtSetSV. + +********************************************************************/ + +static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur) +{ + realtype rtoli; + rtoli = *reltol; + N_VAbs(ycur, tempv); + N_VLinearSum(rtoli, tempv, ONE, (N_Vector) abstol, tempv); + if (N_VMin(tempv) <= ZERO) return(FALSE); + N_VInv(tempv, ewt); + return(TRUE); +} + +/******************* CVHin *************************************** + + This routine computes a tentative initial step size h0. + If tout is too close to tn (= t0), then CVHin returns FALSE and + h remains uninitialized. Otherwise, CVHin sets h to the chosen + value h0 and returns TRUE. + + The algorithm used seeks to find h0 as a solution of + (WRMS norm of (h0^2 ydd / 2)) = 1, + where ydd = estimated second derivative of y. + +*****************************************************************/ + +static booleantype CVHin(CVodeMem cv_mem, realtype tout) +{ + int sign, count; + realtype tdiff, tdist, tround, hlb, hub; + realtype hg, hgs, hnew, hrat, h0, yddnrm; + + /* Test for tout too close to tn */ + + if ((tdiff = tout-tn) == ZERO) return(FALSE); + + sign = (tdiff > ZERO) ? 1 : -1; + tdist = ABS(tdiff); + tround = uround * MAX(ABS(tn), ABS(tout)); + if (tdist < TWO*tround) return(FALSE); + + /* Set lower and upper bounds on h0, and take geometric mean + Exit with this value if the bounds cross each other */ + + hlb = HLB_FACTOR * tround; + hub = CVUpperBoundH0(cv_mem, tdist); + hg = RSqrt(hlb*hub); + if (hub < hlb) { + if (sign == -1) hg = -hg; + h = hg; + return(TRUE); + } + + /* Loop up to MAX_ITERS times to find h0. + Stop if new and previous values differ by a factor < 2. + Stop if hnew/hg > 2 after one iteration, as this probably means + that the ydd value is bad because of cancellation error. */ + + count = 0; + loop { + hgs = hg*sign; + yddnrm = CVYddNorm(cv_mem, hgs); + if (cvode_error == TRUE) { + hg /= 2.; +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE, "halving step in CVHin\n"); +#endif + continue; + } + + hnew = (yddnrm*hub*hub > TWO) ? RSqrt(TWO/yddnrm) : RSqrt(hg*hub); + count++; + if (count >= MAX_ITERS) break; + hrat = hnew/hg; + if ((hrat > HALF) && (hrat < TWO)) break; + if ((count >= 2) && (hrat > TWO)) { + hnew = hg; + break; + } + hg = hnew; + } + + /* Apply bounds, bias factor, and attach sign */ + + h0 = H_BIAS*hnew; + if (h0 < hlb) h0 = hlb; + if (h0 > hub) h0 = hub; + if (sign == -1) h0 = -h0; + h = h0; + return(TRUE); +} + +/******************** CVUpperBoundH0 ****************************** + + This routine sets an upper bound on abs(h0) based on + tdist = abs(tout - t0) and the values of y[i]/y'[i]. + +******************************************************************/ + +static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist) +{ + realtype atoli, hub_inv, hub; + booleantype vectorAtol; + N_Vector temp1, temp2; + + atoli = 0; + vectorAtol = (itol == SV); + if (!vectorAtol) atoli = *((realtype *) abstol); + temp1 = tempv; + temp2 = acor; + N_VAbs(zn[0], temp1); + N_VAbs(zn[1], temp2); + if (vectorAtol) { + N_VLinearSum(HUB_FACTOR, temp1, ONE, (N_Vector)abstol, temp1); + } else { + N_VScale(HUB_FACTOR, temp1, temp1); + N_VAddConst(temp1, atoli, temp1); + } + N_VDiv(temp2, temp1, temp1); + hub_inv = N_VMaxNorm(temp1); + hub = HUB_FACTOR*tdist; + if (hub*hub_inv > ONE) hub = ONE/hub_inv; + return(hub); +} + +/****************** CVYddNorm ************************************* + + This routine computes an estimate of the second derivative of y + using a difference quotient, and returns its WRMS norm. + +******************************************************************/ + +static realtype CVYddNorm(CVodeMem cv_mem, realtype hg) +{ + realtype yddnrm; + + N_VLinearSum(hg, zn[1], ONE, zn[0], y); + f(N, tn+hg, y, tempv, f_data); +#ifdef DEBUG_CVODE + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"CVYddNorm error\n"); + } +#endif + nfe++; + N_VLinearSum(ONE, tempv, -ONE, zn[1], tempv); + N_VScale(ONE/hg, tempv, tempv); + + yddnrm = N_VWrmsNorm(tempv, ewt); + return(yddnrm); +} + +/********************* CVStep ************************************** + + This routine performs one internal cvode step, from tn to tn + h. + It calls other routines to do all the work. + + The main operations done here are as follows: + * preliminary adjustments if a new step size was chosen; + * prediction of the Nordsieck history array zn at tn + h; + * setting of multistep method coefficients and test quantities; + * solution of the nonlinear system; + * testing the local error; + * updating zn and other state data if successful; + * resetting stepsize and order for the next step. + * if SLDET is on, check for stability, reduce order if necessary. + On a failure in the nonlinear system solution or error test, the + step may be reattempted, depending on the nature of the failure. + +********************************************************************/ + +static int CVStep(CVodeMem cv_mem) +{ + realtype saved_t, dsm; + int ncf, nef, nflag; + booleantype passed; + + int kflag; + + saved_t = tn; + ncf = nef = 0; + nflag = FIRST_CALL; + + + if ((nst > 0) && (hprime != h)) CVAdjustParams(cv_mem); + + /* Looping point for attempts to take a step */ + loop { + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"Before predict, y Fail, time %e\n", tn); +#endif + } else { + cvode_prev_good_time = cvode_last_good_time; + N_VScale(1.0, cvode_last_good_y, cvode_prev_good_y); + cvode_last_good_time = tn; + N_VScale(1.0, y, cvode_last_good_y); +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"Before predict, y OK, time %e\n", tn); +#endif + } +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"Before predict, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"Before predict, zn OK\n"); + } + saved_t = tn; +#endif + CVPredict(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After predict, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After predict, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After predict, zn Fail\n"); + + } else { + output_msg(OUTPUT_CVODE,"After predict, zn OK\n"); + } +#endif + CVSet(cv_mem); + + nflag = CVnls(cv_mem, nflag); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After CVnls, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After CVnls, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After CVnls, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After CVnls, zn OK\n"); + } +#endif + kflag = CVHandleNFlag(cv_mem, &nflag, saved_t, &ncf); + if (kflag == PREDICT_AGAIN) continue; + if (kflag != DO_ERROR_TEST) return(kflag); + /* Return if nonlinear solve failed and recovery not possible. */ +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"Before error test, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"Before error test, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"Before error test, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"Before error test, zn OK\n"); + } +#endif + passed = CVDoErrorTest(cv_mem, &nflag, &kflag, saved_t, &nef, &dsm); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After error test, y Fail, passed %d\n", passed); + } else { + output_msg(OUTPUT_CVODE,"After error test, y OK, passed %d\n", passed); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After error test, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After error test, zn OK\n"); + } +#endif + /* Return if error test failed and recovery not possible. */ + if ((!passed) && (kflag == REP_ERR_FAIL)) return(kflag); + if (passed) break; + /* Retry step if error test failed, nflag == PREV_ERR_FAIL */ + } +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE, "Finished step in CVStep\n"); +#endif + /* Nonlinear system solve and error test were both successful. + Update data, and consider change of step and/or order. */ + + + CVCompleteStep(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After complete step, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After complete step, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After complete step, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After complete step, zn OK\n"); + } +#endif + CVPrepareNextStep(cv_mem, dsm); + + /* If Stablilty Limit Detection is turned on, call stability limit + detection routine for possible order reduction. */ + + if (sldeton) CVBDFStab(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After cvbfdstab, y Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After cvbfdstab, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"After cvbfdstab, zn Fail\n"); + } else { + output_msg(OUTPUT_CVODE,"After cvbfdstab, zn OK\n"); + } +#endif + etamax = (nst <= SMALL_NST) ? ETAMX2 : ETAMX3; + + /* Finally, we rescale the acor array to be the + estimated local error vector. */ + + N_VScale(ONE/tq[2], acor, acor); + return(SUCCESS_STEP); + +} + + +/********************* CVAdjustParams ******************************** + + This routine is called when a change in step size was decided upon, + and it handles the required adjustments to the history array zn. + If there is to be a change in order, we call CVAdjustOrder and reset + q, L = q+1, and qwait. Then in any case, we call CVRescale, which + resets h and rescales the Nordsieck array. + +**********************************************************************/ + +static void CVAdjustParams(CVodeMem cv_mem) +{ + if (qprime != q) { + CVAdjustOrder(cv_mem, qprime-q); + q = qprime; + L = q+1; + qwait = L; + } + CVRescale(cv_mem); +} + +/********************* CVAdjustOrder ***************************** + + This routine is a high level routine which handles an order + change by an amount deltaq (= +1 or -1). If a decrease in order + is requested and q==2, then the routine returns immediately. + Otherwise CVAdjustAdams or CVAdjustBDF is called to handle the + order change (depending on the value of lmm). + +******************************************************************/ + +static void CVAdjustOrder(CVodeMem cv_mem, int deltaq) +{ + if ((q==2) && (deltaq != 1)) return; + + switch(lmm){ + case ADAMS: CVAdjustAdams(cv_mem, deltaq); + break; + case BDF: CVAdjustBDF(cv_mem, deltaq); + break; + } +} + +/*************** CVAdjustAdams *********************************** + + This routine adjusts the history array on a change of order q by + deltaq, in the case that lmm == ADAMS. + +*****************************************************************/ + +static void CVAdjustAdams(CVodeMem cv_mem, int deltaq) +{ + int i, j; + realtype xi, hsum; + + /* On an order increase, set new column of zn to zero and return */ + + if (deltaq==1) { + N_VConst(ZERO, zn[L]); + return; + } + + /* On an order decrease, each zn[j] is adjusted by a multiple + of zn[q]. The coefficients in the adjustment are the + coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_j), + integrated, where xi_j = [t_n - t_(n-j)]/h. */ + + for (i=0; i <= qmax; i++) l[i] = ZERO; + l[1] = ONE; + hsum = ZERO; + for (j=1; j <= q-2; j++) { + hsum += tau[j]; + xi = hsum / hscale; + for (i=j+1; i >= 1; i--) l[i] = l[i]*xi + l[i-1]; + } + + for (j=1; j <= q-2; j++) l[j+1] = q * (l[j] / (j+1)); + + for (j=2; j < q; j++) + N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); +} + +/********************** CVAdjustBDF ******************************* + + This is a high level routine which handles adjustments to the + history array on a change of order by deltaq in the case that + lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and + CVDecreaseBDF if deltaq = -1 to do the actual work. + +******************************************************************/ + +static void CVAdjustBDF(CVodeMem cv_mem, int deltaq) +{ + switch(deltaq) { + case 1 : CVIncreaseBDF(cv_mem); + return; + case -1: CVDecreaseBDF(cv_mem); + return; + } +} + +/******************** CVIncreaseBDF ********************************** + + This routine adjusts the history array on an increase in the + order q in the case that lmm == BDF. + A new column zn[q+1] is set equal to a multiple of the saved + vector (= acor) in zn[qmax]. Then each zn[j] is adjusted by + a multiple of zn[q+1]. The coefficients in the adjustment are the + coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-1)), + where xi_j = [t_n - t_(n-j)]/h. + +*********************************************************************/ + +static void CVIncreaseBDF(CVodeMem cv_mem) +{ + realtype alpha0, alpha1, prod, xi, xiold, hsum, A1; + int i, j; + + for (i=0; i <= qmax; i++) l[i] = ZERO; + l[2] = alpha1 = prod = xiold = ONE; + alpha0 = -ONE; + hsum = hscale; + if (q > 1) { + for (j=1; j < q; j++) { + hsum += tau[j+1]; + xi = hsum / hscale; + prod *= xi; + alpha0 -= ONE / (j+1); + alpha1 += ONE / xi; + for (i=j+2; i >= 2; i--) l[i] = l[i]*xiold + l[i-1]; + xiold = xi; + } + } + A1 = (-alpha0 - alpha1) / prod; + N_VScale(A1, zn[qmax], zn[L]); + for (j=2; j <= q; j++) { + N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); + } +} + +/********************* CVDecreaseBDF ****************************** + + This routine adjusts the history array on a decrease in the + order q in the case that lmm == BDF. + Each zn[j] is adjusted by a multiple of zn[q]. The coefficients + in the adjustment are the coefficients of the polynomial + x*x*(x+xi_1)*...*(x+xi_(q-2)), where xi_j = [t_n - t_(n-j)]/h. + +******************************************************************/ + +static void CVDecreaseBDF(CVodeMem cv_mem) +{ + realtype hsum, xi; + int i, j; + + for (i=0; i <= qmax; i++) l[i] = ZERO; + l[2] = ONE; + hsum = ZERO; + for(j=1; j <= q-2; j++) { + hsum += tau[j]; + xi = hsum /hscale; + for (i=j+2; i >= 2; i--) l[i] = l[i]*xi + l[i-1]; + } + + for(j=2; j < q; j++) + N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); +} + +/**************** CVRescale *********************************** + + This routine rescales the Nordsieck array by multiplying the + jth column zn[j] by eta^j, j = 1, ..., q. Then the value of + h is rescaled by eta, and hscale is reset to h. + +***************************************************************/ + +static void CVRescale(CVodeMem cv_mem) +{ + int j; + realtype factor; + + factor = eta; + for (j=1; j <= q; j++) { + N_VScale(factor, zn[j], zn[j]); + factor *= eta; + } + h = hscale * eta; + hscale = h; + nscon = 0; +} + +/********************* CVPredict ************************************* + + This routine advances tn by the tentative step size h, and computes + the predicted array z_n(0), which is overwritten on zn. The + prediction of zn is done by repeated additions. + +*********************************************************************/ + +static void CVPredict(CVodeMem cv_mem) +{ + int j, k; + + tn += h; + for (k = 1; k <= q; k++) + for (j = q; j >= k; j--) + N_VLinearSum(ONE, zn[j-1], ONE, zn[j], zn[j-1]); +} + +/************************** CVSet ********************************* + + This routine is a high level routine which calls CVSetAdams or + CVSetBDF to set the polynomial l, the test quantity array tq, + and the related variables rl1, gamma, and gamrat. + +******************************************************************/ + +static void CVSet(CVodeMem cv_mem) +{ + switch(lmm) { + case ADAMS: CVSetAdams(cv_mem); + break; + case BDF : CVSetBDF(cv_mem); + break; + } + rl1 = ONE / l[1]; + gamma = h * rl1; + if (nst == 0) gammap = gamma; + gamrat = (nst > 0) ? gamma / gammap : ONE; /* protect x / x != 1.0 */ +} + +/******************** CVSetAdams ********************************* + + This routine handles the computation of l and tq for the + case lmm == ADAMS. + + The components of the array l are the coefficients of a + polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by + q-1 + (d/dx) Lambda(x) = c * PRODUCT (1 + x / xi_i) , where + i=1 + Lambda(-1) = 0, Lambda(0) = 1, and c is a normalization factor. + Here xi_i = [t_n - t_(n-i)] / h. + + The array tq is set to test quantities used in the convergence + test, the error test, and the selection of h at a new order. + +*****************************************************************/ + +static void CVSetAdams(CVodeMem cv_mem) +{ + realtype m[L_MAX], M[3], hsum; + + if (q == 1) { + l[0] = l[1] = tq[1] = tq[5] = ONE; + tq[2] = TWO; + tq[3] = TWELVE; + tq[4] = CORTES * tq[2]; /* = 0.1 * tq[2] */ + return; + } + + hsum = CVAdamsStart(cv_mem, m); + + M[0] = CVAltSum(q-1, m, 1); + M[1] = CVAltSum(q-1, m, 2); + + CVAdamsFinish(cv_mem, m, M, hsum); +} + +/****************** CVAdamsStart ******************************** + + This routine generates in m[] the coefficients of the product + polynomial needed for the Adams l and tq coefficients for q > 1. + +******************************************************************/ + +static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]) +{ + realtype hsum, xi_inv, sum; + int i, j; + + hsum = h; + m[0] = ONE; + for (i=1; i <= q; i++) m[i] = ZERO; + for (j=1; j < q; j++) { + if ((j==q-1) && (qwait == 1)) { + sum = CVAltSum(q-2, m, 2); + tq[1] = m[q-2] / (q * sum); + } + xi_inv = h / hsum; + for (i=j; i >= 1; i--) m[i] += m[i-1] * xi_inv; + hsum += tau[j]; + /* The m[i] are coefficients of product(1 to j) (1 + x/xi_i) */ + } + return(hsum); +} + +/****************** CVAdamsFinish ******************************* + + This routine completes the calculation of the Adams l and tq. + +******************************************************************/ + +static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], + realtype hsum) +{ + int i; + realtype M0_inv, xi, xi_inv; + + M0_inv = ONE / M[0]; + + l[0] = ONE; + for (i=1; i <= q; i++) l[i] = M0_inv * (m[i-1] / i); + xi = hsum / h; + xi_inv = ONE / xi; + + tq[2] = xi * M[0] / M[1]; + tq[5] = xi / l[q]; + + if (qwait == 1) { + for (i=q; i >= 1; i--) m[i] += m[i-1] * xi_inv; + M[2] = CVAltSum(q, m, 2); + tq[3] = L * M[0] / M[2]; + } + + tq[4] = CORTES * tq[2]; +} + +/****************** CVAltSum ************************************** + + CVAltSum returns the value of the alternating sum + sum (i= 0 ... iend) [ (-1)^i * (a[i] / (i + k)) ]. + If iend < 0 then CVAltSum returns 0. + This operation is needed to compute the integral, from -1 to 0, + of a polynomial x^(k-1) M(x) given the coefficients of M(x). + +******************************************************************/ + +static realtype CVAltSum(int iend, realtype a[], int k) +{ + int i, sign; + realtype sum; + + if (iend < 0) return(ZERO); + + sum = ZERO; + sign = 1; + for (i=0; i <= iend; i++) { + sum += sign * (a[i] / (i+k)); + sign = -sign; + } + return(sum); +} + +/***************** CVSetBDF ************************************** + + This routine computes the coefficients l and tq in the case + lmm == BDF. CVSetBDF calls CVSetTqBDF to set the test + quantity array tq. + + The components of the array l are the coefficients of a + polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by + q-1 + Lambda(x) = (1 + x / xi*_q) * PRODUCT (1 + x / xi_i) , where + i=1 + xi_i = [t_n - t_(n-i)] / h. + + The array tq is set to test quantities used in the convergence + test, the error test, and the selection of h at a new order. + + +*****************************************************************/ + +static void CVSetBDF(CVodeMem cv_mem) +{ + realtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum; + int i,j; + + l[0] = l[1] = xi_inv = xistar_inv = ONE; + for (i=2; i <= q; i++) l[i] = ZERO; + alpha0 = alpha0_hat = -ONE; + hsum = h; + if (q > 1) { + for (j=2; j < q; j++) { + hsum += tau[j-1]; + xi_inv = h / hsum; + alpha0 -= ONE / j; + for(i=j; i >= 1; i--) l[i] += l[i-1]*xi_inv; + /* The l[i] are coefficients of product(1 to j) (1 + x/xi_i) */ + } + + /* j = q */ + alpha0 -= ONE / q; + xistar_inv = -l[1] - alpha0; + hsum += tau[q-1]; + xi_inv = h / hsum; + alpha0_hat = -l[1] - xi_inv; + for (i=q; i >= 1; i--) l[i] += l[i-1]*xistar_inv; + } + + CVSetTqBDF(cv_mem, hsum, alpha0, alpha0_hat, xi_inv, xistar_inv); +} + +/****************** CVSetTqBDF ************************************ + + This routine sets the test quantity array tq when lmm == BDF. + +******************************************************************/ + +static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, + realtype alpha0_hat, realtype xi_inv, realtype xistar_inv) +{ + realtype A1, A2, A3, A4, A5, A6; + realtype C, CPrime, CPrimePrime; + + A1 = ONE - alpha0_hat + alpha0; + A2 = ONE + q * A1; + tq[2] = ABS(alpha0 * (A2 / A1)); + tq[5] = ABS((A2) / (l[q] * xi_inv/xistar_inv)); + if (qwait == 1) { + C = xistar_inv / l[q]; + A3 = alpha0 + ONE / q; + A4 = alpha0_hat + xi_inv; + CPrime = A3 / (ONE - A4 + A3); + tq[1] = ABS(CPrime / C); + hsum += tau[q]; + xi_inv = h / hsum; + A5 = alpha0 - (ONE / (q+1)); + A6 = alpha0_hat - xi_inv; + CPrimePrime = A2 / (ONE - A6 + A5); + tq[3] = ABS(CPrimePrime * xi_inv * (q+2) * A5); + } + tq[4] = CORTES * tq[2]; +} + +/****************** CVnls ***************************************** + + This routine attempts to solve the nonlinear system associated + with a single implicit step of the linear multistep method. + Depending on iter, it calls CVnlsFunctional or CVnlsNewton + to do the work. + +******************************************************************/ + +static int CVnls(CVodeMem cv_mem, int nflag) +{ + switch(iter) { + case FUNCTIONAL : return(CVnlsFunctional(cv_mem)); + case NEWTON : return(CVnlsNewton(cv_mem, nflag)); + } + return(-99); +} + +/***************** CVnlsFunctional ******************************** + + This routine attempts to solve the nonlinear system using + functional iteration (no matrices involved). + +******************************************************************/ + +static int CVnlsFunctional(CVodeMem cv_mem) +{ + int m; + realtype del, delp, dcon; + + /* Initialize counter and evaluate f at predicted y */ + + delp = 0; + crate = ONE; + m = 0; + f(N, tn, zn[0], tempv, f_data); + nfe++; + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsFunctional, Fail at beginning\n"); +#endif + return(CONV_FAIL); + } else { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsFunctional, OK at beginning\n"); +#endif + } + N_VConst(ZERO, acor); + + /* Loop until convergence; accumulate corrections in acor */ + + loop { + /* Correct y directly from the last f value */ + N_VLinearSum(h, tempv, -ONE, zn[1], tempv); + N_VScale(rl1, tempv, tempv); + N_VLinearSum(ONE, zn[0], ONE, tempv, y); + /* Get WRMS norm of current correction to use in convergence test */ + N_VLinearSum(ONE, tempv, -ONE, acor, acor); + del = N_VWrmsNorm(acor, ewt); + N_VScale(ONE, tempv, acor); + + /* Test for convergence. If m > 0, an estimate of the convergence + rate constant is stored in crate, and used in the test. */ + if (m > 0) crate = MAX(CRDOWN * crate, del / delp); + dcon = del * MIN(ONE, crate) / tq[4]; + if (dcon <= ONE) { + acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt); + return(SOLVED); /* Convergence achieved */ + } + + /* Stop at maxcor iterations or if iter. seems to be diverging */ + m++; + if ((m==maxcor) || ((m >= 2) && (del > RDIV * delp))) + return(CONV_FAIL); + /* Save norm of correction, evaluate f, and loop again */ + delp = del; + f(N, tn, y, tempv, f_data); + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsFunctional, Fail at end\n"); +#endif + return(CONV_FAIL); + } else { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsFunctional, OK at end\n"); +#endif + } + nfe++; + } +} + +/*********************** CVnlsNewton ********************************** + + This routine handles the Newton iteration. It calls lsetup if + indicated, calls CVNewtonIteration to perform the iteration, and + retries a failed attempt at Newton iteration if that is indicated. + See return values at top of this file. + +**********************************************************************/ + +static int CVnlsNewton(CVodeMem cv_mem, int nflag) +{ + N_Vector vtemp1, vtemp2, vtemp3; + int convfail, ier; + booleantype callSetup; + + vtemp1 = acor; /* rename acor as vtemp1 for readability */ + vtemp2 = y; /* rename y as vtemp2 for readability */ + vtemp3 = tempv; /* rename tempv as vtemp3 for readability */ + + /* Set flag convfail, input to lsetup for its evaluation decision */ + convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) ? + NO_FAILURES : FAIL_OTHER; + + /* Decide whether or not to call setup routine (if one exists) */ + if (setupNonNull) { + callSetup = (nflag == PREV_CONV_FAIL) || (nflag == PREV_ERR_FAIL) || + (nst == 0) || (nst >= nstlp + MSBP) || (ABS(gamrat-ONE) > DGMAX); + } else { + crate = ONE; + callSetup = FALSE; + } + + /* Looping point for the solution of the nonlinear system. + Evaluate f at the predicted y, call lsetup if indicated, and + call CVNewtonIteration for the Newton iteration itself. */ + + loop { + + f(N, tn, zn[0], ftemp, f_data); + + nfe++; + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsNewton, start of loop, time %e\n", tn); +#endif + return (CONV_FAIL); + } else { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsNewton, OK, start of loop, time %e\n", tn); +#endif + } + + if (callSetup) { + ier = lsetup(cv_mem, convfail, zn[0], ftemp, &jcur, + vtemp1, vtemp2, vtemp3); + nsetups++; + callSetup = FALSE; + gamrat = crate = ONE; + gammap = gamma; + nstlp = nst; + /* Return if lsetup failed */ + if (ier < 0) return(SETUP_FAIL_UNREC); + if (ier > 0) return(CONV_FAIL); + } + + /* Set acor to zero and load prediction into y vector */ + N_VConst(ZERO, acor); + N_VScale(ONE, zn[0], y); + + /* Do the Newton iteration */ + ier = CVNewtonIteration(cv_mem); + + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"After CVNewtonIteration, Fail, ier %d\n", ier); +#endif + return(CONV_FAIL); + } else { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"After CVNewtonIteration, OK, ier %d\n", ier); +#endif + } + /* If there is a convergence failure and the Jacobian-related + data appears not to be current, loop again with a call to lsetup + in which convfail=FAIL_BAD_J. Otherwise return. */ + if (ier != TRY_AGAIN) return(ier); + callSetup = TRUE; + convfail = FAIL_BAD_J; + } +} + +/********************** CVNewtonIteration **************************** + + This routine performs the Newton iteration. If the iteration succeeds, + it returns the value SOLVED. If not, it may signal the CVnlsNewton + routine to call lsetup again and reattempt the iteration, by + returning the value TRY_AGAIN. (In this case, CVnlsNewton must set + convfail to FAIL_BAD_J before calling setup again). + Otherwise, this routine returns one of the appropriate values + SOLVE_FAIL_UNREC or CONV_FAIL back to CVnlsNewton. + +*********************************************************************/ + +static int CVNewtonIteration(CVodeMem cv_mem) +{ + int m, ret; + realtype del, delp, dcon; + N_Vector b; + + + mnewt = m = 0; + delp = 0; + + /* Looping point for Newton iteration */ + loop { + + /* Evaluate the residual of the nonlinear system*/ + N_VLinearSum(rl1, zn[1], ONE, acor, tempv); + N_VLinearSum(gamma, ftemp, -ONE, tempv, tempv); + + /* Call the lsolve function */ + b = tempv; + ret = lsolve(cv_mem, b, y, ftemp); + nni++; + + if (ret < 0) return(SOLVE_FAIL_UNREC); + + /* If lsolve had a recoverable failure and Jacobian data is + not current, signal to try the solution again */ + if (ret > 0) { + if ((!jcur) && (setupNonNull)) return(TRY_AGAIN); + return(CONV_FAIL); + } + /* Get WRMS norm of correction; add correction to acor and y */ + del = N_VWrmsNorm(b, ewt); + N_VLinearSum(ONE, acor, ONE, b, acor); + N_VLinearSum(ONE, zn[0], ONE, acor, y); + + /* Test for convergence. If m > 0, an estimate of the convergence + rate constant is stored in crate, and used in the test. */ + if (m > 0) { + crate = MAX(CRDOWN * crate, del/delp); + } + dcon = del * MIN(ONE, crate) / tq[4]; + +#ifdef DEBUG_CVODE + /* added before SOLVED */ + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE,"CVnlsNewton, Fail at SOLVED\n"); + return(CONV_FAIL); + } else { + output_msg(OUTPUT_CVODE,"CVnlsNewton, OK at SOLVED\n"); + } +#endif + if (dcon <= ONE) { + acnrm = (m==0) ? del : N_VWrmsNorm(acor, ewt); + jcur = FALSE; + return(SOLVED); /* Nonlinear system was solved successfully */ + } + + mnewt = ++m; + + /* Stop at maxcor iterations or if iter. seems to be diverging. + If still not converged and Jacobian data is not current, + signal to try the solution again */ + if ((m == maxcor) || ((m >= 2) && (del > RDIV*delp))) { + if ((!jcur) && (setupNonNull)) return(TRY_AGAIN); + return(CONV_FAIL); + } + + /* Save norm of correction, evaluate f, and loop again */ + delp = del; + f(N, tn, y, ftemp, f_data); + + if (cvode_error == TRUE) { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsNewton, Fail at end\n"); +#endif + return(CONV_FAIL); + } else { +#ifdef DEBUG_CVODE + output_msg(OUTPUT_CVODE,"CVnlsNewton, OK at end\n"); +#endif + } + nfe++; + } +} + +/********************** CVHandleNFlag ******************************* + + This routine takes action on the return value nflag = *nflagPtr + returned by CVnls, as follows: + + If CVnls succeeded in solving the nonlinear system, then + CVHandleNFlag returns the constant DO_ERROR_TEST, which tells CVStep + to perform the error test. + + If the nonlinear system was not solved successfully, then ncfn and + ncf = *ncfPtr are incremented and Nordsieck array zn is restored. + + If the solution of the nonlinear system failed due to an + unrecoverable failure by setup, we return the value SETUP_FAILED. + + If it failed due to an unrecoverable failure in solve, then we return + the value SOLVE_FAILED. + + Otherwise, a recoverable failure occurred when solving the + nonlinear system (CVnls returned nflag == CONV_FAIL). + In this case, we return the value REP_CONV_FAIL if ncf is now + equal to MXNCF or |h| = hmin. + If not, we set *nflagPtr = PREV_CONV_FAIL and return the value + PREDICT_AGAIN, telling CVStep to reattempt the step. + +*********************************************************************/ + +static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, + int *ncfPtr) +{ + int nflag; + + nflag = *nflagPtr; + + if (nflag == SOLVED) return(DO_ERROR_TEST); + + /* The nonlinear soln. failed; increment ncfn and restore zn */ + ncfn++; + CVRestore(cv_mem, saved_t); + + /* Return if lsetup or lsolve failed unrecoverably */ + if (nflag == SETUP_FAIL_UNREC) return(SETUP_FAILED); + if (nflag == SOLVE_FAIL_UNREC) return(SOLVE_FAILED); + + /* At this point, nflag == CONV_FAIL; increment ncf */ + + (*ncfPtr)++; + etamax = ONE; + /* If we had MXNCF failures or |h| = hmin, return REP_CONV_FAIL */ + if ((ABS(h) <= hmin*ONEPSM) || (*ncfPtr == MXNCF)) + return(REP_CONV_FAIL); + + /* Reduce step size; return to reattempt the step */ + eta = MAX(ETACF, hmin / ABS(h)); + *nflagPtr = PREV_CONV_FAIL; + CVRescale(cv_mem); + return(PREDICT_AGAIN); +} + +/********************** CVRestore ************************************ + + This routine restores the value of tn to saved_t and undoes the + prediction. After execution of CVRestore, the Nordsieck array zn has + the same values as before the call to CVPredict. + +********************************************************************/ + +static void CVRestore(CVodeMem cv_mem, realtype saved_t) +{ + int j, k; + + tn = saved_t; + for (k = 1; k <= q; k++) + for (j = q; j >= k; j--) + N_VLinearSum(ONE, zn[j-1], -ONE, zn[j], zn[j-1]); +} + +/******************* CVDoErrorTest ******************************** + + This routine performs the local error test. + The weighted local error norm dsm is loaded into *dsmPtr, and + the test dsm ?<= 1 is made. + + If the test passes, CVDoErrorTest returns TRUE. + + If the test fails, we undo the step just taken (call CVRestore), + set *nflagPtr to PREV_ERR_FAIL, and return FALSE. + + If MXNEF error test failures have occurred or if ABS(h) = hmin, + we set *kflagPtr = REP_ERR_FAIL. (Otherwise *kflagPtr has the + value last returned by CVHandleNflag.) + + If more than MXNEF1 error test failures have occurred, an order + reduction is forced. + +******************************************************************/ + +static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, + realtype saved_t, int *nefPtr, realtype *dsmPtr) +{ + realtype dsm; + + dsm = acnrm / tq[2]; + + /* If est. local error norm dsm passes test, return TRUE */ + *dsmPtr = dsm; + if (dsm <= ONE) return(TRUE); + + /* Test failed; increment counters, set nflag, and restore zn array */ + (*nefPtr)++; + netf++; + *nflagPtr = PREV_ERR_FAIL; + CVRestore(cv_mem, saved_t); + + /* At MXNEF failures or |h| = hmin, return with kflag = REP_ERR_FAIL */ + if ((ABS(h) <= hmin*ONEPSM) || (*nefPtr == MXNEF)) { + *kflagPtr = REP_ERR_FAIL; + return(FALSE); + } + + /* Set etamax = 1 to prevent step size increase at end of this step */ + etamax = ONE; + + /* Set h ratio eta from dsm, rescale, and return for retry of step */ + if (*nefPtr <= MXNEF1) { + eta = ONE / (RPowerR(BIAS2*dsm,ONE/L) + ADDON); + eta = MAX(ETAMIN, MAX(eta, hmin / ABS(h))); + if (*nefPtr >= SMALL_NEF) eta = MIN(eta, ETAMXF); + CVRescale(cv_mem); + return(FALSE); + } + + /* After MXNEF1 failures, force an order reduction and retry step */ + if (q > 1) { + eta = MAX(ETAMIN, hmin / ABS(h)); + CVAdjustOrder(cv_mem,-1); + L = q; + q--; + qwait = L; + CVRescale(cv_mem); + return(FALSE); + } + + /* If already at order 1, restart: reload zn from scratch */ + eta = MAX(ETAMIN, hmin / ABS(h)); + h *= eta; + hscale = h; + qwait = LONG_WAIT; + nscon = 0; + f(N, tn, zn[0], tempv, f_data); + if (cvode_error == TRUE) { + output_msg(OUTPUT_CVODE, "CVDoErrorTest"); + /*exit(8);*/ + error_msg("CVDoErrorTest", 1 /* STOP */); + } + nfe++; + N_VScale(h, tempv, zn[1]); + return(FALSE); +} + +/*************** CVCompleteStep ********************************** + + This routine performs various update operations when the solution + to the nonlinear system has passed the local error test. + We increment the step counter nst, record the values hu and qu, + update the tau array, and apply the corrections to the zn array. + The tau[i] are the last q values of h, with tau[1] the most recent. + The counter qwait is decremented, and if qwait == 1 (and q < qmax) + we save acor and tq[5] for a possible order increase. + +******************************************************************/ + +static void CVCompleteStep(CVodeMem cv_mem) +{ + int i, j; + + nst++; + nscon++; + hu = h; + qu = q; + + for (i=q; i >= 2; i--) tau[i] = tau[i-1]; + if ((q==1) && (nst > 1)) tau[2] = tau[1]; + tau[1] = h; + + for (j=0; j <= q; j++) + N_VLinearSum(l[j], acor, ONE, zn[j], zn[j]); + qwait--; + if ((qwait == 1) && (q != qmax)) { + N_VScale(ONE, acor, zn[qmax]); + saved_tq5 = tq[5]; + } +} + +/************* CVPrepareNextStep ********************************** + + This routine handles the setting of stepsize and order for the + next step -- hprime and qprime. Along with hprime, it sets the + ratio eta = hprime/h. It also updates other state variables + related to a change of step size or order. + +******************************************************************/ + + static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm) +{ + /* If etamax = 1, defer step size or order changes */ + if (etamax == ONE) { + qwait = MAX(qwait, 2); + qprime = q; + hprime = h; + eta = ONE; + return; + } + + /* etaq is the ratio of new to old h at the current order */ + etaq = ONE /(RPowerR(BIAS2*dsm,ONE/L) + ADDON); + + /* If no order change, adjust eta and acor in CVSetEta and return */ + if (qwait != 0) { + eta = etaq; + qprime = q; + CVSetEta(cv_mem); + return; + } + + /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are + the ratios of new to old h at orders q-1 and q+1, respectively. + CVChooseEta selects the largest; CVSetEta adjusts eta and acor */ + qwait = 2; + etaqm1 = CVComputeEtaqm1(cv_mem); + etaqp1 = CVComputeEtaqp1(cv_mem); + CVChooseEta(cv_mem); + CVSetEta(cv_mem); +} + +/***************** CVSetEta *************************************** + + This routine adjusts the value of eta according to the various + heuristic limits and the optional input hmax. It also resets + etamax to be the estimated local error vector. + +*******************************************************************/ + +static void CVSetEta(CVodeMem cv_mem) +{ + + /* If eta below the threshhold THRESH, reject a change of step size */ + if (eta < THRESH) { + eta = ONE; + hprime = h; + } else { + /* Limit eta by etamax and hmax, then set hprime */ + eta = MIN(eta, etamax); + eta /= MAX(ONE, ABS(h)*hmax_inv*eta); + hprime = h * eta; + if (qprime < q) nscon = 0; + } + + /* Reset etamax for the next step size change, and scale acor */ +} + +/*************** CVComputeEtaqm1 ********************************** + + This routine computes and returns the value of etaqm1 for a + possible decrease in order by 1. + +******************************************************************/ + +static realtype CVComputeEtaqm1(CVodeMem cv_mem) +{ + realtype ddn; + + etaqm1 = ZERO; + if (q > 1) { + ddn = N_VWrmsNorm(zn[q], ewt) / tq[1]; + etaqm1 = ONE/(RPowerR(BIAS1*ddn, ONE/q) + ADDON); + } + return(etaqm1); +} + +/*************** CVComputeEtaqp1 ********************************** + + This routine computes and returns the value of etaqp1 for a + possible increase in order by 1. + +******************************************************************/ + +static realtype CVComputeEtaqp1(CVodeMem cv_mem) +{ + realtype dup, cquot; + + etaqp1 = ZERO; + if (q != qmax) { + cquot = (tq[5] / saved_tq5) * RPowerI(h/tau[2], L); + N_VLinearSum(-cquot, zn[qmax], ONE, acor, tempv); + dup = N_VWrmsNorm(tempv, ewt) /tq[3]; + etaqp1 = ONE / (RPowerR(BIAS3*dup, ONE/(L+1)) + ADDON); + } + return(etaqp1); +} + +/******************* CVChooseEta ********************************** + + Given etaqm1, etaq, etaqp1 (the values of eta for qprime = + q - 1, q, or q + 1, respectively), this routine chooses the + maximum eta value, sets eta to that value, and sets qprime to the + corresponding value of q. If there is a tie, the preference + order is to (1) keep the same order, then (2) decrease the order, + and finally (3) increase the order. If the maximum eta value + is below the threshhold THRESH, the order is kept unchanged and + eta is set to 1. + +******************************************************************/ + +static void CVChooseEta(CVodeMem cv_mem) +{ + realtype etam; + + etam = MAX(etaqm1, MAX(etaq, etaqp1)); + + if (etam < THRESH) { + eta = ONE; + qprime = q; + return; + } + + if (etam == etaq) { + eta = etaq; + qprime = q; + } else if (etam == etaqm1) { + eta = etaqm1; + qprime = q - 1; + } else { + eta = etaqp1; + qprime = q + 1; + if (lmm == BDF) N_VScale(ONE, acor, zn[qmax]); + } +} + +/****************** CVHandleFailure ****************************** + + This routine prints error messages for all cases of failure by + CVStep. It returns to CVode the value that CVode is to return to + the user. + +*****************************************************************/ + +static int CVHandleFailure(CVodeMem cv_mem, int kflag) +{ + char error_string_long[1000]; + /* Set vector of absolute weighted local errors */ + N_VProd(acor, ewt, tempv); + N_VAbs(tempv, tempv); + + /* Depending on kflag, print error message and return error flag */ + switch (kflag) { + case REP_ERR_FAIL: + sprintf(error_string_long, MSG_ERR_FAILS, (double) tn, (double) h); + warning_msg(error_string_long); + return(ERR_FAILURE); + case REP_CONV_FAIL: + sprintf(error_string_long, MSG_CONV_FAILS, (double) tn, (double) h); + warning_msg(error_string_long); + return(CONV_FAILURE); + case SETUP_FAILED: + sprintf(error_string_long, MSG_SETUP_FAILED, (double) tn); + warning_msg(error_string_long); + return(SETUP_FAILURE); + case SOLVE_FAILED: + sprintf(error_string_long, MSG_SOLVE_FAILED, (double) tn); + warning_msg(error_string_long); + return(SOLVE_FAILURE); + } + return(-99); +} + +/****************** CVBDFStab *********************************** + This routine handles the BDF Stability Limit Detection Algorithm + STALD. It is called if lmm = BDF and the SLDET option is on. + If the order is 3 or more, the required norm data is saved. + If a decision to reduce order has not already been made, and + enough data has been saved, CVsldet is called. If it signals + a stability limit violation, the order is reduced, and the step + size is reset accordingly. + +*****************************************************************/ + +void CVBDFStab(CVodeMem cv_mem) +{ + int i,k, ldflag, factorial; + realtype sq, sqm1, sqm2; + + /* If order is 3 or greater, then save scaled derivative data, + push old data down in i, then add current values to top. */ + + if (q >= 3) { + for (k = 1; k <= 3; k++) + { for (i = 5; i >= 2; i--) ssdat[i][k] = ssdat[i-1][k]; } + factorial = 1; + for (i = 1; i <= q-1; i++) factorial *= i; + sq = factorial*q*(q+1)*acnrm/tq[5]; + sqm1 = factorial*q*N_VWrmsNorm(zn[q], ewt); + sqm2 = factorial*N_VWrmsNorm(zn[q-1], ewt); + ssdat[1][1] = sqm2*sqm2; + ssdat[1][2] = sqm1*sqm1; + ssdat[1][3] = sq*sq; + } + + if (qprime >= q) { + + /* If order is 3 or greater, and enough ssdat has been saved, + nscon >= q+5, then call stability limit detection routine. */ + + if ( (q >= 3) && (nscon >= q+5) ) { + ldflag = CVsldet(cv_mem); + if (ldflag > 3) { + /* A stability limit violation is indicated by + a return flag of 4, 5, or 6. + Reduce new order. */ + qprime = q-1; + eta = etaqm1; + eta = MIN(eta,etamax); + eta = eta/MAX(ONE,ABS(h)*hmax_inv*eta); + hprime = h*eta; + iopt[NOR] =iopt[NOR] + 1; + /* output_msg(OUTPUT_CVODE, + " Order reduced to %d by CVBDFStab at nst = %d,\n h = %e hnew = %e\n", + qprime,nst,h,h*eta); */ + } + } + } + else { + /* Otherwise, let order increase happen, and + reset stability limit counter, nscon. */ + nscon = 0; + } +} + +/********************* CVsldet ************************************ + This routine detects stability limitation using stored scaled + derivatives data. CVsldet returns the magnitude of the + dominate characteristic root, rr. The presents of a stability + limit is indicated by rr > "something a little less then 1.0", + and a positive kflag. This routine should only be called if + order is greater than or equal to 3, and data has been collected + for 5 time steps. + + Returned values: + kflag = 1 -> Found stable characteristic root, normal matrix case + kflag = 2 -> Found stable characteristic root, quartic solution + kflag = 3 -> Found stable characteristic root, quartic solution, + with Newton correction + kflag = 4 -> Found stability violation, normal matrix case + kflag = 5 -> Found stability violation, quartic solution + kflag = 6 -> Found stability violation, quartic solution, + with Newton correction + + kflag < 0 -> No stability limitation, + or could not compute limitation. + + kflag = -1 -> Min/max ratio of ssdat too small. + kflag = -2 -> For normal matrix case, vmax > vrrt2*vrrt2 + kflag = -3 -> For normal matrix case, The three ratios + are inconsistent. + kflag = -4 -> Small coefficient prevents elimination of quartics. + kflag = -5 -> R value from quartics not consistent. + kflag = -6 -> No corrected root passes test on qk values + kflag = -7 -> Trouble solving for sigsq. + kflag = -8 -> Trouble solving for B, or R via B. + kflag = -9 -> R via sigsq[k] disagrees with R from data. + +********************************************************************/ + +static int CVsldet(CVodeMem cv_mem) +{ + integertype i, k, j, it, kmin, kflag = 0; + realtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4]; + realtype drr[4], rrc[4],sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; + realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; + realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; + realtype small, tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; + realtype rsa, rsb, rsc, rsd, rse, rd1a, rd1b, rd1c, rd1d; + realtype rd2a, rd2b, rd2c, rd3a, rd3b, cest1, corr1; + realtype ratp, ratm, qfac1, qfac2, bb, rrb; + + /* The following are cutoffs and tolerances used by this routine */ + + rrcut = 0.98; + vrrtol = 1.0e-4; + vrrt2 = 5.0e-4; + sqtol = 1.0e-3; + rrtol = 1.0e-2; + + rr = ZERO; + + /* Index k corresponds to the degree of the interpolating polynomial. */ + /* k = 1 -> q-1 */ + /* k = 2 -> q */ + /* k = 3 -> q+1 */ + + /* Index i is a backward-in-time index, i = 1 -> current time, */ + /* i = 2 -> previous step, etc */ + + /* get maxima, minima, and variances, and form quartic coefficients */ + + for (k=1; k<=3; k++) { + smink = ssdat[1][k]; + smaxk = ZERO; + + for (i=1; i<=5; i++) { + smink = MIN(smink,ssdat[i][k]); + smaxk = MAX(smaxk,ssdat[i][k]); + } + + if (smink < TINY*smaxk) { + kflag = -1; + return(kflag); + } + smax[k] = smaxk; + ssmax[k] = smaxk*smaxk; + + sumrat = ZERO; + sumrsq = ZERO; + for (i=1; i<=4; i++) { + rat[i][k] = ssdat[i][k]/ssdat[i+1][k]; + sumrat = sumrat + rat[i][k]; + sumrsq = sumrsq + rat[i][k]*rat[i][k]; + } + rav[k] = FOURTH*sumrat; + vrat[k] = ABS(FOURTH*sumrsq - rav[k]*rav[k]); + + qc[5][k] = ssdat[1][k]*ssdat[3][k] - ssdat[2][k]*ssdat[2][k]; + qc[4][k] = ssdat[2][k]*ssdat[3][k] - ssdat[1][k]*ssdat[4][k]; + qc[3][k] = ZERO; + qc[2][k] = ssdat[2][k]*ssdat[5][k] - ssdat[3][k]*ssdat[4][k]; + qc[1][k] = ssdat[4][k]*ssdat[4][k] - ssdat[3][k]*ssdat[5][k]; + + for (i=1; i<=5; i++) { + qco[i][k] = qc[i][k]; + } + } /* End of k loop */ + + /* Isolate normal or nearly-normal matrix case. Three quartic will + have common or nearly-common roots in this case. + Return a kflag = 1 if this procedure works. If three root + differ more than vrrt2, return error kflag = -3. */ + + vmin = MIN(vrat[1],MIN(vrat[2],vrat[3])); + vmax = MAX(vrat[1],MAX(vrat[2],vrat[3])); + + if(vmin < vrrtol*vrrtol) { + if (vmax > vrrt2*vrrt2) { + kflag = -2; + return(kflag); + } else { + rr = (rav[1] + rav[2] + rav[3])/THREE; + + drrmax = ZERO; + for(k = 1;k<=3;k++) { + adrr = ABS(rav[k] - rr); + drrmax = MAX(drrmax, adrr); + } + if (drrmax > vrrt2) { + kflag = -3; + } + + kflag = 1; + + /* can compute charactistic root, drop to next section */ + + } + } else { + + /* use the quartics to get rr. */ + + if (ABS(qco[1][1]) < TINY*ssmax[1]) { + small = qco[1][1]; + kflag = -4; + return(kflag); + } + + tem = qco[1][2]/qco[1][1]; + for(i=2; i<=5; i++) { + qco[i][2] = qco[i][2] - tem*qco[i][1]; + } + + qco[1][2] = ZERO; + tem = qco[1][3]/qco[1][1]; + for(i=2; i<=5; i++) { + qco[i][3] = qco[i][3] - tem*qco[i][1]; + } + qco[1][3] = ZERO; + + if (ABS(qco[2][2]) < TINY*ssmax[2]) { + small = qco[2][2]; + kflag = -4; + return(kflag); + } + + tem = qco[2][3]/qco[2][2]; + for(i=3; i<=5; i++) { + qco[i][3] = qco[i][3] - tem*qco[i][2]; + } + + if (ABS(qco[4][3]) < TINY*ssmax[3]) { + small = qco[4][3]; + kflag = -4; + return(kflag); + } + + rr = -qco[5][3]/qco[4][3]; + + if (rr < TINY || rr > HUN) { + kflag = -5; + return(kflag); + } + + for(k=1; k<=3; k++) { + qkr[k] = qc[5][k] + rr*(qc[4][k] + rr*rr*(qc[2][k] + rr*qc[1][k])); + } + + sqmax = ZERO; + for(k=1; k<=3; k++) { + saqk = ABS(qkr[k])/ssmax[k]; + if (saqk > sqmax) sqmax = saqk; + } + sqmin = sqmax; + if (sqmax < sqtol) { + kflag = 2; + + /* can compute charactistic root, drop to "given rr,etc" */ + + } else { + + /* do Newton corrections to improve rr. */ + + for(it=1; it<=3; it++) { + for(k=1; k<=3; k++) { + qp = qc[4][k] + rr*rr*(THREE*qc[2][k] + rr*FOUR*qc[1][k]); + drr[k] = ZERO; + if (ABS(qp) > TINY*ssmax[k]) drr[k] = -qkr[k]/qp; + rrc[k] = rr + drr[k]; + } + + for(k=1; k<=3; k++) { + s = rrc[k]; + sqmaxk = ZERO; + for(j=1; j<=3; j++) { + qjk[j][k] = qc[5][j] + s*(qc[4][j] + + s*s*(qc[2][j] + s*qc[1][j])); + saqj = ABS(qjk[j][k])/ssmax[j]; + if (saqj > sqmaxk) sqmaxk = saqj; + } + sqmx[k] = sqmaxk; + } + + sqmin = sqmx[1]; kmin = 1; + for(k=2; k<=3; k++) { + if (sqmx[k] < sqmin) { + kmin = k; + sqmin = sqmx[k]; + } + } + rr = rrc[kmin]; + + if (sqmin < sqtol) { + kflag = 3; + /* can compute charactistic root */ + /* break out of Newton correction loop and drop to "given rr,etc" */ + break; + } else { + for(j=1; j<=3; j++) { + qkr[j] = qjk[j][kmin]; + } + } + } /* end of Newton correction loop */ + + if (sqmin > sqtol) { + kflag = -6; + return(kflag); + } + } /* end of if (sqmax < sqtol) else */ + } /* end of if(vmin < vrrtol*vrrtol) else, quartics to get rr. */ + + /* given rr, find sigsq[k] and verify rr. */ + /* All positive kflag drop to this section */ + + for(k=1; k<=3; k++) { + rsa = ssdat[1][k]; + rsb = ssdat[2][k]*rr; + rsc = ssdat[3][k]*rr*rr; + rsd = ssdat[4][k]*rr*rr*rr; + rse = ssdat[5][k]*rr*rr*rr*rr; + rd1a = rsa - rsb; + rd1b = rsb - rsc; + rd1c = rsc - rsd; + rd1d = rsd - rse; + rd2a = rd1a - rd1b; + rd2b = rd1b - rd1c; + rd2c = rd1c - rd1d; + rd3a = rd2a - rd2b; + rd3b = rd2b - rd2c; + + if (ABS(rd1b) < TINY*smax[k]) { + kflag = -7; + return(kflag); + } + + cest1 = -rd3a/rd1b; + if (cest1 < TINY || cest1 > FOUR) { + kflag = -7; + return(kflag); + } + corr1 = (rd2b/cest1)/(rr*rr); + sigsq[k] = ssdat[3][k] + corr1; + } + + if (sigsq[2] < TINY) { + kflag = -8; + return(kflag); + } + + ratp = sigsq[3]/sigsq[2]; + ratm = sigsq[1]/sigsq[2]; + qfac1 = FOURTH*(q*q - ONE); + qfac2 = TWO/(q - ONE); + bb = ratp*ratm - ONE - qfac1*ratp; + tem = ONE - qfac2*bb; + + if (ABS(tem) < TINY) { + kflag = -8; + return(kflag); + } + + rrb = ONE/tem; + + if (ABS(rrb - rr) > rrtol) { + kflag = -9; + return(kflag); + } + + /* Check to see if rr is above cutoff rrcut */ + if (rr > rrcut) { + if (kflag == 1) kflag = 4; + if (kflag == 2) kflag = 5; + if (kflag == 3) kflag = 6; + } + + /* All positive kflag returned at this point */ + + return(kflag); + +} + + +/*******************************************************************/ +/********* END Private Helper Functions Implementation *************/ +/*******************************************************************/ + + +/***************************************************************/ +/************** END CVODE Implementation ***********************/ +/***************************************************************/ diff --git a/cvode.h b/cvode.h new file mode 100644 index 00000000..0a81b5bd --- /dev/null +++ b/cvode.h @@ -0,0 +1,882 @@ +/******************************************************************* + * * + * File : cvode.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban * + * and Dan Shumaker @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the interface file for the main CVODE integrator. * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidcvode[] = "$Id$"; +#endif + + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef _cvode_h +#define _cvode_h + + +#include +#include "sundialstypes.h" +#include "nvector.h" + +/****************************************************************** + * * + * CVODE is used to solve numerically the ordinary initial value * + * problem : * + * * + * y' = f(t,y), * + * y(t0) = y0, * + * * + * where t0, y0 in R^N, and f: R x R^N -> R^N are given. * + * * + ******************************************************************/ + + +/****************************************************************** + * * + * Enumerations for inputs to CVodeMalloc, CVReInit, and CVode. * + *----------------------------------------------------------------* + * Symbolic constants for the lmm, iter, and itol input * + * parameters to CVodeMalloc and CVReInit, as well as the input * + * parameter itask to CVode, are given below. * + * * + * lmm : The user of the CVODE package specifies whether to use * + * the ADAMS or BDF (backward differentiation formula) * + * linear multistep method. The BDF method is recommended * + * for stiff problems, and the ADAMS method is recommended * + * for nonstiff problems. * + * * + * iter : At each internal time step, a nonlinear equation must * + * be solved. The user can specify either FUNCTIONAL * + * iteration, which does not require linear algebra, or a * + * NEWTON iteration, which requires the solution of linear * + * systems. In the NEWTON case, the user also specifies a * + * CVODE linear solver. NEWTON is recommended in case of * + * stiff problems. * + * * + * itol : This parameter specifies the relative and absolute * + * tolerance types to be used. The SS tolerance type means * + * a scalar relative and absolute tolerance, while the SV * + * tolerance type means a scalar relative tolerance and a * + * vector absolute tolerance (a potentially different * + * absolute tolerance for each vector component). * + * * + * itask : The itask input parameter to CVode indicates the job * + * of the solver for the next user step. The NORMAL * + * itask is to have the solver take internal steps until * + * it has reached or just passed the user specified tout * + * parameter. The solver then interpolates in order to * + * return an approximate value of y(tout). The ONE_STEP * + * option tells the solver to just take one internal step * + * and return the solution at the point reached by that * + * step. * + * * + ******************************************************************/ + +enum { ADAMS, BDF }; /* lmm */ + +enum { FUNCTIONAL, NEWTON }; /* iter */ + +enum { SS, SV }; /* itol */ + +enum { NORMAL, ONE_STEP }; /* itask */ + + +/****************************************************************** + * * + * Type : RhsFn * + *----------------------------------------------------------------* + * The f function which defines the right hand side of the ODE * + * system y' = f(t,y) must have type RhsFn. * + * f takes as input the problem size N, the independent variable * + * value t, and the dependent variable vector y. It stores the * + * result of f(t,y) in the vector ydot. The y and ydot arguments * + * are of type N_Vector. * + * (Allocation of memory for ydot is handled within CVODE.) * + * The f_data parameter is the same as the f_data * + * parameter passed by the user to the CVodeMalloc routine. This * + * user-supplied pointer is passed to the user's f function * + * every time it is called. * + * A RhsFn f does not have a return value. * + * * + ******************************************************************/ + +typedef void (*RhsFn)(integertype N, realtype t, N_Vector y, + N_Vector ydot, void *f_data); + + +/****************************************************************** + * * + * Function : CVodeMalloc * + *----------------------------------------------------------------* + * CVodeMalloc allocates and initializes memory for a problem to * + * to be solved by CVODE. * + * * + * N is the number of equations in the ODE system. * + * * + * f is the right hand side function in y' = f(t,y). * + * * + * t0 is the initial value of t. * + * * + * y0 is the initial condition vector y(t0). * + * * + * lmm is the type of linear multistep method to be used. * + * The legal values are ADAMS and BDF (see previous * + * description). * + * * + * iter is the type of iteration used to solve the nonlinear * + * system that arises during each internal time step. * + * The legal values are FUNCTIONAL and NEWTON. * + * * + * itol is the type of tolerances to be used. * + * The legal values are: * + * SS (scalar relative and absolute tolerances), * + * SV (scalar relative tolerance and vector * + * absolute tolerance). * + * * + * reltol is a pointer to the relative tolerance scalar. * + * * + * abstol is a pointer to the absolute tolerance scalar or * + * an N_Vector of absolute tolerances. * + * * + * The parameters itol, reltol, and abstol define a vector of * + * error weights, ewt, with components * + * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (if itol = SS), or * + * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (if itol = SV). * + * This vector is used in all error and convergence tests, which * + * use a weighted RMS norm on all error-like vectors v: * + * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ). * + * * + * f_data is a pointer to user data that will be passed to the * + * user's f function every time f is called. * + * * + * errfp is the file pointer for an error file where all CVODE * + * warning and error messages will be written. This * + * parameter can be stdout (standard output), stderr * + * (standard error), a file pointer (corresponding to * + * a user error file opened for writing) returned by * + * fopen, or NULL. If the user passes NULL, then all * + * messages will be written to standard output. * + * * + * optIn is a flag indicating whether there are any optional * + * inputs from the user in the arrays iopt and ropt. * + * Pass FALSE to indicate no optional inputs and TRUE * + * to indicate that optional inputs are present. * + * * + * iopt is the user-allocated array (of size OPT_SIZE given * + * later) that will hold optional integer inputs and * + * outputs. The user can pass NULL if he/she does not * + * wish to use optional integer inputs or outputs. * + * If optIn is TRUE, the user should preset to 0 those * + * locations for which default values are to be used. * + * * + * ropt is the user-allocated array (of size OPT_SIZE given * + * later) that will hold optional real inputs and * + * outputs. The user can pass NULL if he/she does not * + * wish to use optional real inputs or outputs. * + * If optIn is TRUE, the user should preset to 0.0 the * + * locations for which default values are to be used. * + * * + * machEnv is a pointer to machine environment-specific * + * information. * + * * + * Note: The tolerance values may be changed in between calls to * + * CVode for the same problem. These values refer to * + * (*reltol) and either (*abstol), for a scalar absolute * + * tolerance, or the components of abstol, for a vector * + * absolute tolerance. * + * * + * If successful, CVodeMalloc returns a pointer to initialized * + * problem memory. This pointer should be passed to CVode. If * + * an initialization error occurs, CVodeMalloc prints an error * + * message to the file specified by errfp and returns NULL. * + * * + ******************************************************************/ + + +void *CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, realtype *reltol, + void *abstol, void *f_data, FILE *errfp, + booleantype optIn, long int iopt[], realtype ropt[], + M_Env machEnv); + + +/****************************************************************** + * * + * Function : CVReInit * + *----------------------------------------------------------------* + * CVReInit re-initializes CVode for the solution of a problem, * + * where a prior call to CVodeMalloc has been made with the same * + * problem size N. CVReInit performs the same input checking * + * and initializations that CVodeMalloc does (except for N). * + * But it does no memory allocation, assuming that the existing * + * internal memory is sufficient for the new problem. * + * * + * The use of CVReInit requires that the maximum method order, * + * maxord, is no larger for the new problem than for the problem * + * specified in the last call to CVodeMalloc. This condition is * + * automatically fulfilled if the multistep method parameter lmm * + * is unchanged (or changed from ADAMS to BDF) and the default * + * value for maxord is specified. * + * * + * If iter = NEWTON, then following the call to CVReInit, a call * + * to the linear solver specification routine is necessary if a * + * different linear solver is chosen, but may not be otherwise. * + * If the same linear solver is chosen, and there are no changes * + * in the input parameters to the specification routine, then no * + * call to that routine is needed. * + * If there are changes in parameters, but they do not increase * + * the linear solver memory size, then a call to the corresponding* + * CVReInit routine must made to communicate the new * + * parameters; in that case the linear solver memory is reused. * + * If the parameter changes do increase the linear solver memory * + * size, then the main linear solver specification routine must be* + * called. See the linear solver documentation for full details. * + * * + * The first argument to CVReInit is: * + * * + * cvode_mem = pointer to CVODE memory returned by CVodeMalloc. * + * * + * All the remaining arguments to CVReInit have names and * + * meanings identical to those of CVodeMalloc. Note that the * + * problem size N is not passed as an argument to CVReInit, * + * as that is assumed to be unchanged since the CVodeMalloc call. * + * * + * The return value of CVReInit is equal to SUCCESS = 0 if there * + * were no errors; otherwise it is a negative int equal to: * + * CVREI_NO_MEM indicating cvode_mem was NULL, or * + * CVREI_ILL_INPUT indicating an input argument was illegal * + * (including an attempt to increase maxord). * + * In case of an error return, an error message is also printed. * + * * + * Note: the reported workspace sizes iopt[LENRW] and iopt[LENIW] * + * are left unchanged from the values computed by CVodeMalloc, and* + * so may be larger than would be computed for the new problem. * + ******************************************************************/ + +int CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, realtype *reltol, + void *abstol, void *f_data, FILE *errfp, + booleantype optIn, long int iopt[], + realtype ropt[], M_Env machEnv); + + +/* CVReInit return values: */ + +/* SUCCESS = 0 (Defined under CVode return values, but listed + here also for completeness) */ +enum {CVREI_NO_MEM = -1, CVREI_ILL_INPUT = -2}; + + +/****************************************************************** + * * + * Function : CVode * + *----------------------------------------------------------------* + * CVode integrates the ODE over an interval in t. * + * If itask is NORMAL, then the solver integrates from its * + * current internal t value to a point at or beyond tout, then * + * interpolates to t = tout and returns y(tout) in the user- * + * allocated vector yout. If itask is ONE_STEP, then the solver * + * takes one internal time step and returns in yout the value of * + * y at the new internal time. In this case, tout is used only * + * during the first call to CVode to determine the direction of * + * integration and the rough scale of the problem. In either * + * case, the time reached by the solver is placed in (*t). The * + * user is responsible for allocating the memory for this value. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * tout is the next time at which a computed solution is desired * + * * + * yout is the computed solution vector. In NORMAL mode with no * + * errors, yout=y(tout). * + * * + * t is a pointer to a real location. CVode sets (*t) to the * + * time reached by the solver and returns yout=y(*t). * + * * + * itask is either NORMAL or ONE_STEP mode. These two modes have * + * been described above. * + * * + * The return values for CVode are defined later in this file. * + * Here is a brief description of each return value: * + * * + * SUCCESS : CVode succeeded. * + * * + * CVODE_NO_MEM : The cvode_mem argument was NULL. * + * * + * ILL_INPUT : One of the inputs to CVode is illegal. This * + * includes the situation when a component of the * + * error weight vectors becomes < 0 during * + * internal time-stepping. The ILL_INPUT flag * + * will also be returned if the linear solver * + * routine CV--- (called by the user after * + * calling CVodeMalloc) failed to set one of the * + * linear solver-related fields in cvode_mem or * + * if the linear solver's init routine failed. In * + * any case, the user should see the printed * + * error message for more details. * + * * + * TOO_MUCH_WORK : The solver took mxstep internal steps but * + * could not reach tout. The default value for * + * mxstep is MXSTEP_DEFAULT = 500. * + * * + * TOO_MUCH_ACC : The solver could not satisfy the accuracy * + * demanded by the user for some internal step. * + * * + * ERR_FAILURE : Error test failures occurred too many times * + * (= MXNEF = 7) during one internal time step or * + * occurred with |h| = hmin. * + * * + * CONV_FAILURE : Convergence test failures occurred too many * + * times (= MXNCF = 10) during one internal time * + * step or occurred with |h| = hmin. * + * * + * SETUP_FAILURE : The linear solver's setup routine failed in an * + * unrecoverable manner. * + * * + * SOLVE_FAILURE : The linear solver's solve routine failed in an * + * unrecoverable manner. * + * * + ******************************************************************/ + + +int CVode(void *cvode_mem, realtype tout, N_Vector yout, + realtype *t, int itask); + + +/* CVode return values */ + +enum { SUCCESS=0, CVODE_NO_MEM=-1, ILL_INPUT=-2, TOO_MUCH_WORK=-3, + TOO_MUCH_ACC=-4, ERR_FAILURE=-5, CONV_FAILURE=-6, + SETUP_FAILURE=-7, SOLVE_FAILURE=-8 }; + + +/****************************************************************** + * * + * Function : CVodeDky * + *----------------------------------------------------------------* + * CVodeDky computes the kth derivative of the y function at * + * time t, where tn-hu <= t <= tn, tn denotes the current * + * internal time reached, and hu is the last internal step size * + * successfully used by the solver. The user may request * + * k=0, 1, ..., qu, where qu is the current order. The * + * derivative vector is returned in dky. This vector must be * + * allocated by the caller. It is only legal to call this * + * function after a successful return from CVode. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * t is the time at which the kth derivative of y is evaluated. * + * The legal range for t is [tn-hu,tn] as described above. * + * * + * k is the order of the derivative of y to be computed. The * + * legal range for k is [0,qu] as described above. * + * * + * dky is the output derivative vector [(D_k)y](t). * + * * + * The return values for CVodeDky are defined later in this file. * + * Here is a brief description of each return value: * + * * + * OKAY : CVodeDky succeeded. * + * * + * BAD_K : k is not in the range 0, 1, ..., qu. * + * * + * BAD_T : t is not in the interval [tn-hu,tn]. * + * * + * BAD_DKY : The dky argument was NULL. * + * * + * DKY_NO_MEM : The cvode_mem argument was NULL. * + * * + ******************************************************************/ + + +int CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky); + + +/* CVodeDky return values */ + +enum { OKAY=0, BAD_K=-1, BAD_T=-2, BAD_DKY=-3, DKY_NO_MEM=-4 }; + + +/****************************************************************** + * * + * Function : CVodeFree * + *----------------------------------------------------------------* + * CVodeFree frees the problem memory cvode_mem allocated by * + * CVodeMalloc. Its only argument is the pointer cvode_mem * + * returned by CVodeMalloc. * + * * + ******************************************************************/ + +void CVodeFree(void *cvode_mem); + + +/****************************************************************** + * * + * Optional Inputs and Outputs * + *----------------------------------------------------------------* + * The user should declare two arrays for optional input and * + * output, an iopt array for optional integer input and output * + * and an ropt array for optional real input and output. The * + * size of both these arrays should be OPT_SIZE. * + * So the user's declaration should look like: * + * * + * long int iopt[OPT_SIZE]; * + * realtype ropt[OPT_SIZE]; * + * * + * The enumerations below the OPT_SIZE definition * + * are indices into the iopt and ropt arrays. Here is a brief * + * description of the contents of these positions: * + * * + * iopt[MAXORD] : maximum lmm order to be used by the solver. * + * Optional input. (Default = 12 for ADAMS, 5 for * + * BDF). * + * * + * iopt[MXSTEP] : maximum number of internal steps to be taken by * + * the solver in its attempt to reach tout. * + * Optional input. (Default = 500). * + * * + * iopt[MXHNIL] : maximum number of warning messages issued by the* + * solver that t + h = t on the next internal step.* + * A value of -1 means no such messages are issued.* + * Optional input. (Default = 10). * + * * + * iopt[NST] : cumulative number of internal steps taken by * + * the solver (total so far). Optional output. * + * * + * iopt[NFE] : number of calls to the user's f function. * + * Optional output. * + * * + * iopt[NSETUPS] : number of calls made to the linear solver's * + * setup routine. Optional output. * + * * + * iopt[NNI] : number of NEWTON iterations performed. * + * Optional output. * + * * + * iopt[NCFN] : number of nonlinear convergence failures * + * that have occurred. Optional output. * + * * + * iopt[NETF] : number of local error test failures that * + * have occurred. Optional output. * + * * + * iopt[QU] : order used during the last internal step. * + * Optional output. * + * * + * iopt[QCUR] : order to be used on the next internal step. * + * Optional output. * + * * + * iopt[LENRW] : size of required CVODE internal real work * + * space, in realtype words. Optional output. * + * * + * iopt[LENIW] : size of required CVODE internal integer work * + * space, in integertype words. Optional output. * + * * + * iopt[SLDET] : Flag to turn on/off stability limit detection * + * (1 = on, 0 = off). When BDF is used and order * + * is 3 or greater, CVsldet is call to detect * + * stability limit. If limit is detected, the * + * order is reduced. Optional input. * + * * + * iopt[NOR] : Number of order reductions due to * + * stability limit detection. * + * Optional output. * + * * + * ropt[H0] : initial step size. Optional input. * + * * + * ropt[HMAX] : maximum absolute value of step size allowed. * + * Optional input. (Default is infinity). * + * Note: If optIn = TRUE, the value of ropt[HMAX] * + * is examined on every call to CVode, and so can * + * be changed between calls. * + * * + * ropt[HMIN] : minimum absolute value of step size allowed. * + * Optional input. (Default is 0.0). * + * * + * ropt[HU] : step size for the last internal step. * + * Optional output. * + * * + * ropt[HCUR] : step size to be attempted on the next internal * + * step. Optional output. * + * * + * ropt[TCUR] : current internal time reached by the solver. * + * Optional output. * + * * + * ropt[TOLSF] : a suggested factor by which the user's * + * tolerances should be scaled when too much * + * accuracy has been requested for some internal * + * step. Optional output. * + * * + ******************************************************************/ + +/* iopt, ropt array sizes */ + +#define OPT_SIZE 40 + + +/* iopt and ropt offsets * + * The constants CVODE_IOPT_SIZE and CVODE_ROPT_SIZE are equal to * + * the number of integer and real optional inputs and outputs * + * actually accessed in cvode.c. The locations beyond these * + * values are used by the linear solvers. */ + +#define CVODE_IOPT_SIZE 15 +#define CVODE_ROPT_SIZE 7 + +/* iopt indices */ +enum { MAXORD, MXSTEP, MXHNIL, + NST, NFE, NSETUPS, NNI, NCFN, NETF, QU, QCUR, + LENRW, LENIW, SLDET, NOR}; + +/* ropt indices */ + +enum { H0, HMAX, HMIN, + HU, HCUR, TCUR, TOLSF }; + + +/* Basic CVODE constants */ + +#define ADAMS_Q_MAX 12 /* max value of q for lmm == ADAMS */ +#define BDF_Q_MAX 5 /* max value of q for lmm == BDF */ +#define Q_MAX ADAMS_Q_MAX /* max value of q for either lmm */ +#define L_MAX (Q_MAX+1) /* max value of L for either lmm */ +#define NUM_TESTS 5 /* number of error test quantities */ + + +/****************************************************************** + * * + * Types : struct CVodeMemRec, CVodeMem * + *----------------------------------------------------------------* + * The type CVodeMem is type pointer to struct CVodeMemRec. This * + * structure contains fields to keep track of problem state. * + * * + ******************************************************************/ + +typedef struct CVodeMemRec { + + realtype cv_uround; /* machine unit roundoff */ + + /* Problem Specification Data */ + + integertype cv_N; /* ODE system size */ + RhsFn cv_f; /* y' = f(t,y(t)) */ + void *cv_f_data; /* user pointer passed to f */ + int cv_lmm; /* lmm = ADAMS or BDF */ + int cv_iter; /* iter = FUNCTIONAL or NEWTON */ + int cv_itol; /* itol = SS or SV */ + realtype *cv_reltol; /* ptr to relative tolerance */ + void *cv_abstol; /* ptr to absolute tolerance */ + + /* Nordsieck History Array */ + + N_Vector cv_zn[L_MAX]; /* Nordsieck array, of size N x (q+1). */ + /* zn[j] is a vector of length N (j=0,...,q) */ + /* zn[j] = [1/factorial(j)] * h^j * (jth */ + /* derivative of the interpolating polynomial */ + + /* Vectors of length N */ + + N_Vector cv_ewt; /* error weight vector */ + N_Vector cv_y; /* y is used as temporary storage by the solver */ + /* The memory is provided by the user to CVode */ + /* where the vector is named yout. */ + N_Vector cv_acor; /* In the context of the solution of the */ + /* nonlinear equation, acor = y_n(m) - y_n(0). */ + /* On return, this vector is scaled to give */ + /* the estimated local error in y. */ + N_Vector cv_tempv; /* temporary storage vector */ + N_Vector cv_ftemp; /* temporary storage vector */ + + /* Step Data */ + + int cv_q; /* current order */ + int cv_qprime; /* order to be used on the next step */ + /* = q-1, q, or q+1 */ + int cv_qwait; /* number of internal steps to wait before */ + /* considering a change in q */ + int cv_L; /* L = q + 1 */ + + realtype cv_h; /* current step size */ + realtype cv_hprime; /* step size to be used on the next step */ + realtype cv_eta; /* eta = hprime / h */ + realtype cv_hscale; /* value of h used in zn */ + realtype cv_tn; /* current internal value of t */ + + realtype cv_tau[L_MAX+1]; /* array of previous q+1 successful step */ + /* sizes indexed from 1 to q+1 */ + realtype cv_tq[NUM_TESTS+1]; /* array of test quantities indexed from */ + /* 1 to NUM_TESTS(=5) */ + realtype cv_l[L_MAX]; /* coefficients of l(x) (degree q poly) */ + + realtype cv_rl1; /* 1 / l[1] */ + realtype cv_gamma; /* gamma = h * rl1 */ + realtype cv_gammap; /* gamma at the last setup call */ + realtype cv_gamrat; /* gamma / gammap */ + + realtype cv_crate; /* estimated corrector convergence rate */ + realtype cv_acnrm; /* | acor | wrms */ + int cv_mnewt; /* Newton iteration counter */ + + /* Limits */ + + int cv_qmax; /* q <= qmax */ + int cv_mxstep; /* maximum number of internal steps for one user call */ + int cv_maxcor; /* maximum number of corrector iterations for the */ + /* solution of the nonlinear equation */ + int cv_mxhnil; /* maximum number of warning messages issued to the */ + /* user that t + h == t for the next internal step */ + + realtype cv_hmin; /* |h| >= hmin */ + realtype cv_hmax_inv; /* |h| <= 1/hmax_inv */ + realtype cv_etamax; /* eta <= etamax */ + + /* Counters */ + + long int cv_nst; /* number of internal steps taken */ + long int cv_nfe; /* number of f calls */ + long int cv_ncfn; /* number of corrector convergence failures */ + long int cv_netf; /* number of error test failures */ + long int cv_nni; /* number of Newton iterations performed */ + long int cv_nsetups; /* number of setup calls */ + int cv_nhnil; /* number of messages issued to the user that */ + /* t + h == t for the next iternal step */ + long int cv_lrw; /* number of realtype words in CVODE work vectors */ + long int cv_liw; /* no. of integertype words in CVODE work vectors */ + long int cv_nscon; /* counter for STALD method */ + + realtype cv_etaqm1; /* ratio of new to old h for order q-1 */ + realtype cv_etaq; /* ratio of new to old h for order q */ + realtype cv_etaqp1; /* ratio of new to old h for order q+1 */ + realtype cv_ssdat[6][4]; /* scaled data array for STALD */ + + /* Linear Solver Data */ + + /* Linear Solver functions to be called */ + + int (*cv_linit)(struct CVodeMemRec *cv_mem); + + int (*cv_lsetup)(struct CVodeMemRec *cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + int (*cv_lsolve)(struct CVodeMemRec *cv_mem, N_Vector b, N_Vector ycur, + N_Vector fcur); + + void (*cv_lfree)(struct CVodeMemRec *cv_mem); + + /* Linear Solver specific memory */ + + void *cv_lmem; + + /* Saved Values */ + + int cv_qu; /* last successful q value used */ + long int cv_nstlp; /* step number of last setup call */ + realtype cv_hu; /* last successful h value used */ + realtype cv_saved_tq5; /* saved value of tq[5] */ + booleantype cv_jcur; /* Is the Jacobian info used by */ + /* linear solver current? */ + realtype cv_tolsf; /* tolerance scale factor */ + booleantype cv_setupNonNull; /* Does setup do something? */ + + /* Arrays for Optional Input and Optional Output */ + + booleantype cv_optIn; /* boolean input optIn */ + long int *cv_iopt; /* long int optional input, output */ + realtype *cv_ropt; /* real optional input, output */ + + /* Error File */ + + FILE *cv_errfp; /* CVODE error messages are sent to errfp */ + + /* Pointer to Machine Environment-Specific Information */ + + M_Env cv_machenv; + + /* Stability Limit Detection control flag */ + + booleantype cv_sldeton; /* Is Stability Limit Detection on */ + +} *CVodeMem; + + +/****************************************************************** + * * + * Communication between user and a CVODE Linear Solver * + *----------------------------------------------------------------* + * Return values of the linear solver specification routine. * + * The values of these are given in the enum statement below. * + * SUCCESS : The routine was successful. * + * * + * LMEM_FAIL : A memory allocation failed. * + * * + * LIN_ILL_INPUT: Some input was illegal (see message). * + * * + ******************************************************************/ + +/* SUCCESS = 0 (Defined under CVode return values, but listed + here also for completeness) */ +enum {LMEM_FAIL = -1, LIN_ILL_INPUT = -2}; + + +/****************************************************************** + * * + * Communication between cvode.c and a CVODE Linear Solver * + *----------------------------------------------------------------* + * (1) cv_linit return values * + * * + * LINIT_OK : The cv_linit routine succeeded. * + * * + * LINIT_ERR : The cv_linit routine failed. Each linear solver * + * init routine should print an appropriate error * + * message to (cv_mem->errfp). * + * * + * (2) convfail (input to cv_lsetup) * + * * + * NO_FAILURES : Either this is the first cv_setup call for this * + * step, or the local error test failed on the * + * previous attempt at this step (but the Newton * + * iteration converged). * + * * + * FAIL_BAD_J : This value is passed to cv_lsetup if * + * * + * (1) The previous Newton corrector iteration * + * did not converge and the linear solver's * + * setup routine indicated that its Jacobian- * + * related data is not current. * + * or * + * (2) During the previous Newton corrector * + * iteration, the linear solver's solve routine * + * failed in a recoverable manner and the * + * linear solver's setup routine indicated that * + * its Jacobian-related data is not current. * + * * + * FAIL_OTHER : During the current internal step try, the * + * previous Newton iteration failed to converge * + * even though the linear solver was using current * + * Jacobian-related data. * + * * + * (3) Parameter documentation, as well as a brief description * + * of purpose, for each CVODE linear solver routine to be * + * called in cvode.c is given below the constant declarations * + * that follow. * + * * + ******************************************************************/ + +/* cv_linit return values */ + +#define LINIT_OK 0 +#define LINIT_ERR -1 + +/* Constants for convfail (input to cv_lsetup) */ + +#define NO_FAILURES 0 +#define FAIL_BAD_J 1 +#define FAIL_OTHER 2 + + +/******************************************************************* + * * + * int (*cv_linit)(CVodeMem cv_mem); * + *-----------------------------------------------------------------* + * The purpose of cv_linit is to complete initializations for * + * specific linear solver, such as counters and statistics. * + * An LInitFn should return LINIT_OK (= 0) if it has successfully * + * initialized the CVODE linear solver and LINIT_ERR (= -1) * + * otherwise. These constants are defined above. If an error does * + * occur, an appropriate message should be sent to (cv_mem->errfp).* + * * + *******************************************************************/ + +/******************************************************************* + * * + * int (*cv_lsetup)(CVodeMem cv_mem, int convfail, N_Vector ypred, * + * N_Vector fpred, booleantype *jcurPtr, * + * N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); * + *-----------------------------------------------------------------* + * The job of cv_lsetup is to prepare the linear solver for * + * subsequent calls to cv_lsolve. It may re-compute Jacobian- * + * related data is it deems necessary. Its parameters are as * + * follows: * + * * + * cv_mem - problem memory pointer of type CVodeMem. See the big * + * typedef earlier in this file. * + * * + * convfail - a flag to indicate any problem that occurred during * + * the solution of the nonlinear equation on the * + * current time step for which the linear solver is * + * being used. This flag can be used to help decide * + * whether the Jacobian data kept by a CVODE linear * + * solver needs to be updated or not. * + * Its possible values have been documented above. * + * * + * ypred - the predicted y vector for the current CVODE internal * + * step. * + * * + * fpred - f(tn, ypred). * + * * + * jcurPtr - a pointer to a boolean to be filled in by cv_lsetup. * + * The function should set *jcurPtr=TRUE if its Jacobian * + * data is current after the call and should set * + * *jcurPtr=FALSE if its Jacobian data is not current. * + * Note: If cv_lsetup calls for re-evaluation of * + * Jacobian data (based on convfail and CVODE state * + * data), it should return *jcurPtr=TRUE unconditionally;* + * otherwise an infinite loop can result. * + * * + * vtemp1 - temporary N_Vector provided for use by cv_lsetup. * + * * + * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * + * * + * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * + * * + * The cv_lsetup routine should return 0 if successful, * + * a positive value for a recoverable error, and a negative value * + * for an unrecoverable error. * + * * + *******************************************************************/ + +/******************************************************************* + * * + * int (*cv_lsolve)(CVodeMem cv_mem, N_Vector b, N_Vector ycur, * + * N_Vector fcur); * + *-----------------------------------------------------------------* + * cv_lsolve must solve the linear equation P x = b, where * + * P is some approximation to (I - gamma J), J = (df/dy)(tn,ycur) * + * and the RHS vector b is input. The N-vector ycur contains * + * the solver's current approximation to y(tn) and the vector * + * fcur contains the N-vector f(tn,ycur). The solution is to be * + * returned in the vector b. cv_lsolve returns a positive value * + * for a recoverable error and a negative value for an * + * unrecoverable error. Success is indicated by a 0 return value. * + * * + *******************************************************************/ + +/******************************************************************* + * * + * void (*cv_lfree)(CVodeMem cv_mem); * + *-----------------------------------------------------------------* + * cv_lfree should free up any memory allocated by the linear * + * solver. This routine is called once a problem has been * + * completed and the linear solver is no longer needed. * + * * + *******************************************************************/ + + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/dense.cpp b/dense.cpp new file mode 100644 index 00000000..a0648504 --- /dev/null +++ b/dense.cpp @@ -0,0 +1,114 @@ +/******************************************************************* + * * + * File : dense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package. * + * * + *******************************************************************/ + +#include +#include +#include "sundialstypes.h" +#include "sundialsmath.h" +#include "dense.h" +#include "smalldense.h" +#include "output.h" +#include "phqalloc.h" +/* WARNING don't include any headers below here */ +#define malloc PHRQ_malloc +static char const svnid[] = "$Id: dense.c 78 2005-02-01 22:47:12Z dlpark $"; + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) + + +/* Implementation */ + + +DenseMat DenseAllocMat(integertype N) +{ + DenseMat A; + + if (svnid == NULL) fprintf(stderr," "); + if (N <= 0) return(NULL); + + A = (DenseMat) malloc(sizeof *A); + if (A==NULL) return (NULL); + + A->data = denalloc(N); + if (A->data == NULL) { + free(A); + return(NULL); + } + + A->size = N; + + return(A); +} + + +integertype *DenseAllocPiv(integertype N) +{ + if (N <= 0) return(NULL); + + return((integertype *) malloc(N * sizeof(integertype))); +} + + +integertype DenseFactor(DenseMat A, integertype *p) +{ + return(gefa(A->data, A->size, p)); +} + + +void DenseBacksolve(DenseMat A, integertype *p, realtype *b) +{ + gesl(A->data, A->size, p, b); +} + + +void DenseZero(DenseMat A) +{ + denzero(A->data, A->size); +} + +void DenseCopy(DenseMat A, DenseMat B) +{ + dencopy(A->data, B->data, A->size); +} + +void DenseScale(realtype c, DenseMat A) +{ + denscale(c, A->data, A->size); +} + +void DenseAddI(DenseMat A) +{ + denaddI(A->data, A->size); +} + +void DenseFreeMat(DenseMat A) +{ + denfree(A->data); + free(A); +} + +void DenseFreePiv(integertype *p) +{ + free(p); +} + +void DensePrint(DenseMat A) +{ + denprint(A->data, A->size); +} + diff --git a/dense.h b/dense.h new file mode 100644 index 00000000..c2c019c1 --- /dev/null +++ b/dense.h @@ -0,0 +1,298 @@ +/******************************************************************* + * * + * File : dense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic DENSE linear solver * + * package. The routines listed in this file all use type * + * DenseMat, defined below, for matrices. These routines in turn * + * call routines in the smalldense.h/smalldense.c module, which * + * use the type realtype** for matrices. This separation allows * + * for possible modifications in which matrices of type DenseMat * + * may not be stored contiguously, while small matrices can still * + * be treated with the routines in smalldense. * + * * + * Routines that work with the type DenseMat begin with "Dense". * + * The DenseAllocMat function allocates a dense matrix for use in * + * the other DenseMat routines listed in this file. Matrix * + * storage details are given in the documentation for the type * + * DenseMat. The DenseAllocPiv function allocates memory for * + * pivot information. The storage allocated by DenseAllocMat and * + * DenseAllocPiv is deallocated by the routines DenseFreeMat and * + * DenseFreePiv, respectively. The DenseFactor and DenseBacksolve * + * routines perform the actual solution of a dense linear system. * + * * + * Routines that work with realtype** begin with "den" (except for * + * the factor and solve routines which are called gefa and gesl, * + * respectively). The underlying matrix storage is described in * + * the documentation for denalloc in smalldense.h * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svniddense[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif +#ifndef _dense_h +#define _dense_h + + +#include "sundialstypes.h" +#include "smalldense.h" + + +/****************************************************************** + * * + * Type: DenseMat * + *----------------------------------------------------------------* + * The type DenseMat is defined to be a pointer to a structure * + * with a size and a data field. The size field indicates the * + * number of columns (== number of rows) of a dense matrix, while * + * the data field is a two dimensional array used for component * + * storage. The elements of a dense matrix are stored columnwise * + * (i.e columns are stored one on top of the other in memory). If * + * A is of type DenseMat, then the (i,j)th element of A (with * + * 0 <= i,j <= size-1) is given by the expression (A->data)[j][i] * + * or by the expression (A->data)[0][j*n+i]. The macros below * + * allow a user to access efficiently individual matrix * + * elements without writing out explicit data structure * + * references and without knowing too much about the underlying * + * element storage. The only storage assumption needed is that * + * elements are stored columnwise and that a pointer to the jth * + * column of elements can be obtained via the DENSE_COL macro. * + * Users should use these macros whenever possible. * + * * + ******************************************************************/ + +typedef struct _DenseMat { + integertype size; + realtype **data; +} *DenseMat; + + +/* DenseMat accessor macros */ + + +/****************************************************************** + * * + * Macro : DENSE_ELEM * + * Usage : DENSE_ELEM(A,i,j) = a_ij; OR * + * a_ij = DENSE_ELEM(A,i,j); * + *----------------------------------------------------------------* + * DENSE_ELEM(A,i,j) references the (i,j)th element of the N by N * + * DenseMat A, 0 <= i,j <= N-1. * + * * + ******************************************************************/ + +#define DENSE_ELEM(A,i,j) ((A->data)[j][i]) + + +/****************************************************************** + * * + * Macro : DENSE_COL * + * Usage : col_j = DENSE_COL(A,j); * + *----------------------------------------------------------------* + * DENSE_COL(A,j) references the jth column of the N by N * + * DenseMat A, 0 <= j <= N-1. The type of the expression * + * DENSE_COL(A,j) is realtype *. After the assignment in the usage* + * above, col_j may be treated as an array indexed from 0 to N-1. * + * The (i,j)th element of A is referenced by col_j[i]. * + * * + ******************************************************************/ + +#define DENSE_COL(A,j) ((A->data)[j]) + + +/* Functions that use the DenseMat representation for a dense matrix */ + + +/****************************************************************** + * * + * Function : DenseAllocMat * + * Usage : A = DenseAllocMat(N); * + * if (A == NULL) ... memory request failed * + *----------------------------------------------------------------* + * DenseAllocMat allocates memory for an N by N dense matrix and * + * returns the storage allocated (type DenseMat). DenseAllocMat * + * returns NULL if the request for matrix storage cannot be * + * satisfied. See the above documentation for the type DenseMat * + * for matrix storage details. * + * * + ******************************************************************/ + +DenseMat DenseAllocMat(integertype N); + + +/****************************************************************** + * * + * Function : DenseAllocPiv * + * Usage : p = DenseAllocPiv(N); * + * if (p == NULL) ... memory request failed * + *----------------------------------------------------------------* + * DenseAllocPiv allocates memory for pivot information to be * + * filled in by the DenseFactor routine during the factorization * + * of an N by N dense matrix. The underlying type for pivot * + * information is an array of N integers and this routine returns * + * the pointer to the memory it allocates. If the request for * + * pivot storage cannot be satisfied, DenseAllocPiv returns NULL. * + * * + ******************************************************************/ + +integertype *DenseAllocPiv(integertype N); + + +/****************************************************************** + * * + * Function : DenseFactor * + * Usage : ier = DenseFactor(A, p); * + * if (ier != 0) ... A is singular * + *----------------------------------------------------------------* + * DenseFactor performs the LU factorization of the N by N dense * + * matrix A. This is done using standard Gaussian elimination * + * with partial pivoting. * + * * + * A successful LU factorization leaves the matrix A and the * + * pivot array p with the following information: * + * * + * (1) p[k] contains the row number of the pivot element chosen * + * at the beginning of elimination step k, k=0, 1, ..., N-1. * + * * + * (2) If the unique LU factorization of A is given by PA = LU, * + * where P is a permutation matrix, L is a lower triangular * + * matrix with all 1's on the diagonal, and U is an upper * + * triangular matrix, then the upper triangular part of A * + * (including its diagonal) contains U and the strictly lower * + * triangular part of A contains the multipliers, I-L. * + * * + * DenseFactor returns 0 if successful. Otherwise it encountered * + * a zero diagonal element during the factorization. In this case * + * it returns the column index (numbered from one) at which * + * it encountered the zero. * + * * + ******************************************************************/ + +integertype DenseFactor(DenseMat A, integertype *p); + + +/****************************************************************** + * * + * Function : DenseBacksolve * + * Usage : DenseBacksolve(A, p, b); * + *----------------------------------------------------------------* + * DenseBacksolve solves the N-dimensional system A x = b using * + * the LU factorization in A and the pivot information in p * + * computed in DenseFactor. The solution x is returned in b. This * + * routine cannot fail if the corresponding call to DenseFactor * + * did not fail. * + * * + ******************************************************************/ + +void DenseBacksolve(DenseMat A, integertype *p, realtype *b); + + +/****************************************************************** + * * + * Function : DenseZero * + * Usage : DenseZero(A); * + *----------------------------------------------------------------* + * DenseZero sets all the elements of the N by N matrix A to 0.0. * + * * + ******************************************************************/ + +void DenseZero(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseCopy * + * Usage : DenseCopy(A, B); * + *----------------------------------------------------------------* + * DenseCopy copies the contents of the N by N matrix A into the * + * N by N matrix B. * + * * + ******************************************************************/ + +void DenseCopy(DenseMat A, DenseMat B); + + +/****************************************************************** + * * + * Function: DenseScale * + * Usage : DenseScale(c, A); * + *----------------------------------------------------------------* + * DenseScale scales the elements of the N by N matrix A by the * + * constant c and stores the result back in A. * + * * + ******************************************************************/ + +void DenseScale(realtype c, DenseMat A); + + +/****************************************************************** + * * + * Function : DenseAddI * + * Usage : DenseAddI(A); * + *----------------------------------------------------------------* + * DenseAddI adds the identity matrix to A and stores the result * + * back in A. * + * * + ******************************************************************/ + +void DenseAddI(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseFreeMat * + * Usage : DenseFreeMat(A); * + *----------------------------------------------------------------* + * DenseFreeMat frees the memory allocated by DenseAllocMat for * + * the N by N matrix A. * + * * + ******************************************************************/ + +void DenseFreeMat(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseFreePiv * + * Usage : DenseFreePiv(p); * + *----------------------------------------------------------------* + * DenseFreePiv frees the memory allocated by DenseAllocPiv for * + * the pivot information array p. * + * * + ******************************************************************/ + +void DenseFreePiv(integertype *p); + + +/****************************************************************** + * * + * Function : DensePrint * + * Usage : DensePrint(A); * + *----------------------------------------------------------------* + * This routine prints the N by N dense matrix A to standard * + * output as it would normally appear on paper. It is intended * + * as a debugging tool with small values of N. The elements are * + * printed using the %g option. A blank line is printed before * + * and after the matrix. * + * * + ******************************************************************/ + +void DensePrint(DenseMat A); + + +#endif +#ifdef __cplusplus +} +#endif diff --git a/distribution.checklist b/distribution.checklist new file mode 100644 index 00000000..86f3bb93 --- /dev/null +++ b/distribution.checklist @@ -0,0 +1,85 @@ +(1) Copy distribution.checklist to checklist.VERSION + +(2) XXX Update version and date in main.c + +(3) XXX Update doc/README.TXT + XXX uname -r + XXX gcc -v + +(4) Update src/revisions + when all_dist is run by make, src/revisions is copied + to doc/RELEASE.TXT + + ( ../doc/phreeqc.txt now static, only RELEASE.TXT + has history 2/2/05) + +(5) Update Makefile and distribution.mk + set VERSION number + set VER_DATE + add any new files to distribution + database files + source files + output files + doc files + +(6) svn status ~/programs/phreeqc -q + svn ci ~/programs/phreeqc + svn update + +(7) remake everything + make clean_all + make output_files (also remakes programs) + +(8) svn status ~/programs/phreeqc -q + should be clean + otherwise commit and restart checklist at item 5 + +(9) make all_dist REVISION=xxx + ls phreeqc_export +Linux/ phreeqc-2.12-577.Linux.tar.gz phreeqc-2.12-577.source.tar.gz Source/ + +(10) test Unix distributions + make test_dist + or + make linux_test, sun_test, source_test + +(11) Scott is making batch windows + +(12) make web + install windows version + copy README.TXT to ~/programs/phreeqc/win + + cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc + cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT + cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT + cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT + cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT + cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt + cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT + +(13) check for latest version of Phreeqc For Windows. + +(14) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/index.html + phreeqci version, date, size + windows batch phreeqc version size + Linux batch phreeqc version size + Generic batch phreeqc version size + phreeqc for windows version, date, size + +(15) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqci/index.html + PhreeqcI version, date, size + +(16) send mail to Brian Marshal + +(17) PHAST + unpack release version in packages + Update table in /z/linarcolkr/home/www/projects/GWC_coupled/phast/index.html + copy release notes + from ~/packages/phast-x.x/doc/RELEASE.TXT + to /z/linarcolkr/home/www/projects/GWC_coupled/phast/RELEASE.TXT + copy readme + from ~/packages/phast-x.x/README + to /z/linarcolkr/home/www/projects/GWC_coupled/phast/README + +(18) Update status.fm + diff --git a/distribution.mk b/distribution.mk new file mode 100644 index 00000000..b1603ed1 --- /dev/null +++ b/distribution.mk @@ -0,0 +1,368 @@ +# Locations to save compressed tar file for distribution +EXPORT=$(TOPDIR)/src/phreeqc_export +EXPORT_DIR=$(EXPORT) +WIN_DIR=$(TOPDIR)/win +DIST_DIR=$(EXPORT_DIR) +DEBUG_DIR=phreeqc_debug +DEBUG_EXE=$(SRC)/$(PROGRAM) +VERSION=2.12 +VER_DATE:=November 10, 2005 +VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") +V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") +GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") +KERNEL_VER:=$(shell uname -r) +ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) +TEXTCP=textcp DOS +SUN_DIR=$(TOPDIR)/src/Sun +UNIX2DOS=unix2dos +CCFLAGS_DBG=-Wall -ansi -g +# list of files for distribution +FILES= \ + src/Makefile \ + src/advection.c \ + src/basic.c \ + src/basicsubs.c \ + src/cl1.c \ + src/cl1mp.c \ + src/cvdense.c \ + src/cvode.c \ + src/dense.c \ + src/dw.c \ + src/input.c \ + src/integrate.c \ + src/inverse.c \ + src/isotopes.c \ + src/kinetics.c \ + src/main.c \ + src/mainsubs.c \ + src/model.c \ + src/nvector.c \ + src/nvector_serial.c \ + src/output.c \ + src/p2clib.c \ + src/parse.c \ + src/phqalloc.c \ + src/phreeqc_files.c \ + src/phreeqc_files.c \ + src/pitzer.c \ + src/pitzer_structures.c \ + src/prep.c \ + src/print.c \ + src/read.c \ + src/readtr.c \ + src/smalldense.c \ + src/spread.c \ + src/step.c \ + src/structures.c \ + src/sundialsmath.c \ + src/tally.c \ + src/tidy.c \ + src/transport.c \ + src/utilities.c \ + src/cvdense.h \ + src/cvode.h \ + src/dense.h \ + src/global.h \ + src/input.h \ + src/kinetics.h \ + src/nvector.h \ + src/nvector_serial.h \ + src/output.h \ + src/p2c.h \ + src/phqalloc.h \ + src/phrqproto.h \ + src/phrqtype.h \ + src/pitzer.h \ + src/smalldense.h \ + src/sundialsmath.h \ + src/sundialstypes.h \ + database/llnl.dat \ + database/minteq.dat \ + database/minteq.v4.dat \ + database/phreeqc.dat \ + database/wateq4f.dat \ + database/iso.dat \ + database/pitzer.dat \ + examples/ex1 examples/ex1.out \ + examples/ex2 examples/ex2.out examples/ex2.sel \ + examples/ex3 examples/ex3.out \ + examples/ex4 examples/ex4.out \ + examples/ex5 examples/ex5.out examples/ex5.sel \ + examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ + examples/ex7 examples/ex7.out examples/ex7.sel \ + examples/ex8 examples/ex8.out examples/ex8.sel \ + examples/ex9 examples/ex9.out examples/ex9.sel \ + examples/ex10 examples/ex10.out examples/ex10.sel \ + examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ + examples/ex12 examples/ex12.out examples/ex12.sel \ + examples/ex12a examples/ex12a.out examples/ex12a.sel \ + examples/ex13a examples/ex13a.out examples/ex13a.sel \ + examples/ex13b examples/ex13b.out examples/ex13b.sel \ + examples/ex13c examples/ex13c.out examples/ex13c.sel \ + examples/ex14 examples/ex14.out examples/ex14.sel \ + examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ + examples/ex16 examples/ex16.out \ + examples/ex17 examples/ex17.out \ + examples/ex18 examples/ex18.out \ + doc/NOTICE.TXT \ + doc/README.TXT \ + doc/RELEASE.TXT \ + doc/manual.pdf \ + doc/wrir02-4172.pdf \ + doc/phreeqc.txt \ + bin/phreeqc.orig \ + test/test.sh \ + test/clean.sh \ + test/check.sh + +SED_ARGS= \ + -e "s/@VERSION@/$(VERSION)/" \ + -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ + -e "s/VERSION_DATE/$(VERSION)/" \ + -e "s^@GCC_VER@^$(GCC_VER)^" \ + -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ + -e "s/@REVISION@/$(REVISION)/" + +remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files + +output_files: linux_output_files # sun_output_files + +# make sure program is compiles, run examples and mytest +linux_output_files: all + cd ../examples; make >& make.out + cd ../mytest; make >& make.out + +clean_linux_output_files: + cd ../examples; make clean + cd ../mytest; make clean + +sun_output_files: phreeqc.sun + ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" + +phreeqc.sun: + ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" + +clean_sun_output_files: + cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean + +all_dist: clean_dist linux source # win # sun + +test_dist: linux_test source_test # sun_test + +# +#Linux +# +linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist + +source: source_export source_clean source_sed_files source_dist + +linux_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Linux + svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux + +linux_clean: + rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o + +linux_sed_list= \ + "$(EXPORT_DIR)/Linux/doc/README.TXT \ + $(EXPORT_DIR)/Linux/src/main.c" + +linux_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/doc/RELEASE.TXT + for FILE in "$(linux_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + +linux_compile: + make -C $(EXPORT_DIR)/Linux/src + +linux_output: + cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out + +linux_dist: + cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) + cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz + cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) + +source_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Source + svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source + +source_clean: + rm -f $(EXPORT_DIR/Source/bin/$(PROGRAM) $(EXPORT_DIR/Source/src/*.o + +source_sed_list= \ + "$(EXPORT_DIR)/Source/doc/README.TXT \ + $(EXPORT_DIR)/Source/src/main.c" + +source_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/doc/RELEASE.TXT + for FILE in "$(source_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + +source_dist: + cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar + cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz + cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) + +linux_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh + rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh + +source_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source + cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k + cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh + +# +#Sun +# +sun: sun_export sun_clean sun_sed_files sun_compile sun_output sun_dist + +sun_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Sun + svn export .. $(EXPORT_DIR)/Sun + +sun_clean: + rm -f $(EXPORT_DIR)/Sun/bin/$(PROGRAM) $(EXPORT_DIR)/Sun/src/*.o + +sun_sed_list= \ + "$(EXPORT_DIR)/Sun/doc/README.TXT \ + $(EXPORT_DIR)/Sun/src/main.c" + +sun_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Sun/src/revisions > $(EXPORT_DIR)/Sun/doc/RELEASE.TXT + for FILE in "$(sun_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + +sun_compile: + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/src" + +sun_output: + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples clean" + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples" > $(EXPORT_DIR)/Sun/examples/make.out 2>> $(EXPORT_DIR)/Sun/examples/make.out + +sun_dist: + cd $(EXPORT_DIR)/Sun; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Sun; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Sun; tar -rf $(PROGRAM).tar bin/$(PROGRAM) + cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Sun; tar -czf $(PROGRAM).Sun.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).Sun.tar.gz $(DIST_DIR)/$(ROOTNAME).Sun.tar.gz + cd $(EXPORT_DIR)/Sun; echo $(ROOTNAME).Sun.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) + +sun_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Sun + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Sun.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Sun + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./test.sh" + rm -f $(DIST_DIR)/phreeqc-$(VERSION).Sun/bin/phreeqc + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/src; make -k" + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./clean.sh; ./test.sh" + +clean_dist: + rm -rf $(EXPORT_DIR) + +clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files + +# +#Win +# +win: win_export win_sed_files win_dist + +win_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Win + svn export .. $(EXPORT_DIR)/Win + +win_sed_list= \ + "$(EXPORT_DIR)/Win/src/main.c" + +win_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/doc/RELEASE.TXT + $(UNIX2DOS) $(EXPORT_DIR)/Win/doc/RELEASE.TXT + sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/doc/README.TXT + $(UNIX2DOS) $(EXPORT_DIR)/Win/doc/README.TXT + for FILE in "$(win_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; \ + mv t $$FILE; \ + $(UNIX2DOS) $$FILE; \ + done + +win_dist: + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar +# Translate cr/lf + cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ + if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ + else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done + cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +# remove example output + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel +# remove bin directory + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin +# remove test directory files + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat +# copy bat file + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat + cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz + cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(PROGRAM).Windows.tar.gz . + cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); mv $(PROGRAM).Windows.tar.gz $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz + @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) + +win_echo_files: + @echo $(FILES) + +debug: + echo DEBUG_EXE $(DEBUG_EXE) + echo SRC $(SRC) + echo CURDIR $(CURDIR) + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(SRC)/Makefile SRC=$(SRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) + +debug_nomp: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(TOPDIR)/src/Makefile SRC=$(TOPDIR)/src CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) + +web: + cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc + cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT + cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT + cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT + cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT + cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt + cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT + + diff --git a/dw.cpp b/dw.cpp new file mode 100644 index 00000000..662551a8 --- /dev/null +++ b/dw.cpp @@ -0,0 +1,349 @@ +#define EXTERNAL extern +#include "global.h" +#include "phrqproto.h" +#include "output.h" +#define PITZER_EXTERNAL extern +#include "pitzer.h" + +static int BB (double T); +static double PS (double T); +static double VLEST (double T); +static int DFIND (double *DOUT, double P, double D, double T); +static int QQ (double T, double D); +static double BASE (double D); + +/* COMMON /QQQQ/ */ +static double Q0,Q5; +/* COMMON /ACONST/ */ +static double GASCON=0.461522e0, TZ=647.073e0, AA=1.e0; +static double Z, DZ, Y; +/* COMMON /ELLCON/ */ +static double G1=11.e0,G2=44.333333333333e0,GF=3.5e0; +static double B1, B2, B1T, B2T, B1TT, B2TT; + +/* ---------------------------------------------------------------------- */ +int DW (double T) +/* ---------------------------------------------------------------------- */ +/* +C +C SUBROUTINE TO CALCULATE THE DENSITY OF WATER AS A FUNCTION OF +C TEMPERATURE. T IS IN KELVIN, P IS IN PASCALS, DW0 IS IN G/CM^3 +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + double FP = 9.869232667e0, P, DGSS, D; + + BB (T); + P=1.0e0/FP; + if (T > 373.149e0) P=PS(T); + DGSS=P/T/.4e0; + if (T < TZ) { + DGSS=1.0e0/(VLEST(T)); + } + DFIND (&D,P,DGSS,T); + DW0=D; + VP=P*FP; + return OK; +} + +/* ---------------------------------------------------------------------- */ +static int BB (double T) +/* ---------------------------------------------------------------------- */ +/* + +C +C THIS SUBROUTINE CALCULATES THE B'S NEEDED FOR FUNCTION DW. +C THE B'S CALCULATED HERE ARE IN CM3/G. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + double V[11]; + int I; + /* COMMON /BCONST/ */ + double P[11]={0, 0.7478629e0, -.3540782e0, 0.e0, 0e0, .007159876e0, 0.e0, + -.003528426e0, 0., 0., 0.}; + double Q[11]={0, 1.1278334e0,0.e0,-.5944001e0,-5.010996e0,0.e0,.63684256e0, + 0., 0., 0., 0.}; + + V[1]=1.0; + for (I = 2; I <= 10; I++) { + V[I]=V[I-1]*TZ/T; + } + B1=P[1]+P[2]*log(1.e0/V[2]); + B2=Q[1]; + B1T=P[2]*V[2]/TZ; + B2T=0.e0; + B1TT=0.e0; + B2TT=0.e0; + for (I = 3; I <= 10; I++) { + B1=B1+P[I]*V[I-1]; + B2=B2+Q[I]*V[I-1]; + B1T=B1T-(I-2)*P[I]*V[I-1]/T; + B2T=B2T-(I-2)*Q[I]*V[I-1]/T; + B1TT=B1TT+P[I]*(I-2)*(I-2)*V[I-1]/T/T; + B2TT=B2TT+Q[I]*(I-2)*(I-2)*V[I-1]/T/T; + } + B1TT=B1TT-B1T/T; + B2TT=B2TT-B2T/T; + return OK; +} +/* ---------------------------------------------------------------------- */ +static double PS (double T) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES AN APPROXIMATION TO THE VAPOR PRESSURE, P +C AS A FUNCTION OF THE INPUT TEMPERATURE. THE VAPOR PRESSURE +C CALCULATED AGREES WITH THE VAPOR PRESSURE PREDICTED BY THE SURFACE +C TO WITHIN .02% TO WITHIN A DEGREE OR SO OF THE CRITICAL TEMPERATUR +C AND CAN SERVE AS AN INITIAL GUESS FOR FURTHER REFINEMENT BY +C IMPOSING THE CONDITION THAT GL=GV. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + double A[9]={0, -7.8889166e0,2.5514255e0,-6.716169e0, + 33.239495e0,-105.38479e0,174.35319e0,-148.39348e0, + 48.631602e0}; + double PL, V, W, B, Z, Q; + int I; + if(T <= 314.e0) { + PL=6.3573118e0-8858.843e0/T+607.56335e0*pow(T,-.6e0); + return (.1e0*exp(PL)); + } + V=T/647.25e0; + W=fabs(1.e0-V); + B=0.e0; + for (I = 1; I <= 8; I++) { + Z=I; + B=B+A[I]*pow(W,((Z+1.e0)/2.e0)); + } + Q=B/V; + return (22.093e0*exp(Q)); +} +/* ---------------------------------------------------------------------- */ +static double VLEST (double T) +/* ---------------------------------------------------------------------- */ +/* +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + double A=-1.59259e1,B=6.57886e-2,C=-1.12666e-4,D=7.33191e-8, + E=1.60229e3,F=2.88572e0,G=650.0e0; + + return (A+B*T+C*T*T+D*T*T*T+E/T+F/(G-T)); +} +/* ---------------------------------------------------------------------- */ +static int DFIND (double *DOUT, double P, double D, double T) +/* ---------------------------------------------------------------------- */ +/* +C +C ROUTINE TO FIND DENSITY CORRESPONDING TO INPUT PRESSURE P(MPA), AN +C TEMPERATURE T(K), USING INITIAL GUESS DENSITY D(G/CM3). THE OUTPUT +C DENSITY IS IN G/CM3. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + int L; + double DD, RT, PP_dfind, DPD, DPDX, DP, X; + /* double DD, RT, PP, DPD, DPDX, DP, X; */ + + DD=D; + RT=GASCON*T; + if(DD <= 0.e0) DD=1.e-8; + if(DD > 1.9e0) DD=1.9e0; + L=0; + for (L=1; L <= 30; L++) { + if(DD <= 0.e0) DD=1.e-8; + if(DD > 1.9e0) DD=1.9e0; + QQ(T,DD); + PP_dfind = RT*DD*BASE(DD)+Q0; + DPD=RT*(Z+Y*DZ)+Q5; + /* +C +C THE FOLLOWING 3 LINES CHECK FOR NEGATIVE DP/DRHO, AND IF SO ASSUME +C GUESS TO BE IN 2-PHASE REGION, AND CORRECT GUESS ACCORDINGLY. +C + */ + if(DPD <= 0.e0) { + if(D >= .2967e0) DD=DD*1.02e0; + if(D < .2967e0) DD=DD*.98e0; + if(L <= 10) continue; + } else { +/* 13 */ + DPDX=DPD*1.1e0; + if(DPDX < 0.1e0) DPDX=0.1e0; + DP=fabs(1.e0-PP_dfind/P); + if(DP < 1.e-8) break; + if(D > .3e0 && DP < 1.e-7) break; + if(D > .7e0 && DP < 1.e-6) break; + X=(P-PP_dfind)/DPDX; + if(fabs(X) > .1e0) X=X*.1e0/fabs(X); + DD=DD+X; + if(DD < 0.e0) DD=1.e-8; + } + } + if (L > 30) error_msg("In subroutine DFIND", STOP); +/* 20 CONTINUE */ + *DOUT=DD; + return OK; +} +/* ---------------------------------------------------------------------- */ +static int QQ (double T, double D) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS ROUTINE CALCULATES, FOR A GIVEN T(K) AND D(G/CM3), THE RESIDUL +C CONTRIBUTIONS TO: PRESSURE (Q), DP/DRHO (Q5) +C THIS SUBROUTINE IS USED IN DENSITY OF WATER CALCULATION. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + /* COMMON /NCONST/ */ + double G[41]={0,-.53062968529023e3,.22744901424408e4,.78779333020687e3 + ,-.69830527374994e2,.17863832875422e5,-.39514731563338e5 + ,.33803884280753e5,-.13855050202703e5,-.25637436613260e6 + ,.48212575981415e6,-.34183016969660e6, .12223156417448e6 + ,.11797433655832e7,-.21734810110373e7, .10829952168620e7 + ,-.25441998064049e6,-.31377774947767e7,.52911910757704e7 + ,-.13802577177877e7,-.25109914369001e6, .46561826115608e7 + ,-.72752773275387e7,.41774246148294e6,.14016358244614e7 + ,-.31555231392127e7,.47929666384584e7,.40912664781209e6 + ,-.13626369388386e7, .69625220862664e6,-.10834900096447e7 + ,-.22722827401688e6,.38365486000660e6,.68833257944332e4 + ,.21757245522644e5,-.26627944829770e4,-.70730418082074e5 + ,-.225e0,-1.68e0,.055e0,-93.0e0}; + /*int II[41]={0,4*0,4*1,4*2,4*3,4*4,4*5,4*6,4*8,2*2,0,4,3*2,4};*/ + int II[41]={0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4, 5,5,5,5, 6,6,6,6, 8,8,8,8, 2,2, 0,4, 2,2,2,4}; + /*int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,3*4,0,2,0,0};*/ + int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,4,4,4,0,2,0,0}; + int NC=36; + /* COMMON /ADDCON/ */ + double ATZ[5]={0,64.e1,64.e1,641.6e0,27.e1},ADZ[5]={0,.319e0,.319e0,.319e0,1.55e0}, + AAT[5]={0,2.e4,2.e4,4.e4,25.e0}, AAD[5]={0,34.e0,4.e1,3.e1,1.05e3}; + double *QZT; + double QR[12],QT[11] /*, QZT[10]*/; + /*EQUIVALENCE (QT(2),QZT(1))*/ + + double E, Q10, Q20, V, QP, DDZ, DEL, EX1, DEX, ATT, TX, + TAU, EX2, TEX, QM, FCT, Q5T; + int I, K, L, J, KM; + QZT = &(QT[1]); + QR[1]=0.e0; + Q5=0.e0; + Q0=0.e0; + E=exp(-AA*D); + Q10=D*D*E; + Q20=1.e0-E; + QR[2]=Q10; + V=TZ/T; + QT[1]=T/TZ; + /*DO 4 I=2,10*/ + for (I = 2; I <= 10; I++) { + QR[I+1]=QR[I]*Q20; + /* 4 QT[I]=QT[I-1]*V*/ + QT[I]=QT[I-1]*V; + } + /* DO 10 I=1,NC */ + for (I = 1; I <= NC; I++) { + K=II[I]+1; + L=JJ[I]; + QP=G[I]*AA*QR[K+1]*QZT[L]; + Q0=Q0+QP; + /*10 Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP*/ + Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP; + } + QP=0.e0; + /* DO 20 J=37,40 */ + for (J=37; J <= 40; J++) { + if(fabs(G[J]) < 1.0e-20) continue; + K=II[J]; + KM=JJ[J]; + DDZ = ADZ[J-36]; + DEL = D/DDZ - 1.e0; + if(fabs(DEL) < 1.e-10) DEL=1.e-10; + EX1 = -AAD[J-36]*pow(DEL,K); + if (EX1 <= -88.028e0) { + DEX=0.e0; + } else { + DEX=exp(EX1)*pow(DEL,KM); + } + ATT = AAT[J-36]; + TX = ATZ[J-36]; + TAU = T/TX-1.e0; + EX2 = -ATT*TAU*TAU; + if (EX2 <= -88.028e0) { + TEX=0.e0; + } else { + TEX = exp(EX2); + } + Q10 = DEX*TEX; + QM = KM/DEL - K*AAD[J-36]*pow(DEL,(K-1)); + FCT=QM*D*D*Q10/DDZ; + Q5T = FCT*(2.e0/D+QM/DDZ)-pow((D/DDZ),2)*Q10*(KM/DEL/DEL+ + K*(K-1)*AAD[J-36]*pow(DEL,(K-2))); + Q5 = Q5 + Q5T*G[J]; + QP = QP + G[J]*FCT; + /* 20 CONTINUE */ + } + Q0=Q0+QP; + return OK; +} +/* ---------------------------------------------------------------------- */ +static double BASE (double D) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES THE Z (=PBASE/(DRT)) NEEDED FOR FUNCTION +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + double X, Z0, DZ0; +/* +C +C G1,G2 AND GF ARE THE ALPHA, BETA AND GAMMA FOR DENSITY OF WATER +C CALCULATIONS. B1 AND B2 ARE THE 'EXCLUDED VOLUME' AND '2ND VIRIAL +C SUPPLIED BY THE SUBROUTINE BB(T), WHICH ALSO SUPPLIES THE 1ST AND +C 2ND DERIVATIVES WITH RESPECT TO T (B1T,B2T,B1TT,B2TT). +C +*/ + Y=.25e0*B1*D; + X=1.e0-Y; + Z0=(1.e0+G1*Y+G2*Y*Y)/pow(X,3); + Z=Z0+4.e0*Y*(B2/B1-GF); + DZ0=(G1+2.e0*G2*Y)/pow(X,3) + 3.e0*(1.e0+G1*Y+G2*Y*Y)/pow(X,4); + DZ=DZ0+4.e0*(B2/B1-GF); + return(Z); +} +/* ---------------------------------------------------------------------- */ +double DC (double T) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES THE RELATIVE DIELECTRIC CONSTANT AS A +C FUNCTION OF TEMPERATURE, ASSUMING ONE ATMOSPHERE PRESSURE +C ACCORDING TO D. J. BRADLEY AND K. S. PITZER, (1979) +C +*/ +{ + double D1000, C, B; + double U[10]={0, 3.4279e2, -5.0866e-3, 9.4690e-7, -2.0525e0, 3.1159e3, + -1.8289e2, -8.0325e3, 4.2142e6, 2.1417e0}; + D1000=U[1]*exp(U[2]*T+U[3]*T*T); + C=U[4]+U[5]/(U[6]+T); + B=U[7]+U[8]/T+U[9]*T; + return (D1000+C*log((B+VP*1.01325e0)/(B+1000.0e0))); +} diff --git a/ex1 b/ex1 new file mode 100644 index 00000000..8021fa1a --- /dev/null +++ b/ex1 @@ -0,0 +1,77 @@ +PRINT + -status false +TITLE Example 1.--Add uranium and speciate seawater. +SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979) + units ppm + pH 8.22 + pe 8.451 + density 1.023 + temp 25.0 + redox O(0)/O(-2) + Ca 412.3 + Mg 1291.8 + Na 10768.0 + K 399.1 + Fe 0.002 + Mn 0.0002 pe + Si 4.28 + Cl 19353.0 + Alkalinity 141.682 as HCO3 + S(6) 2712.0 + N(5) 0.29 gfw 62.0 + N(-3) 0.03 as NH4 + U 3.3 ppb N(5)/N(-3) + O(0) 1.0 O2(g) -0.7 + 12C 1 .1 +SOLUTION_MASTER_SPECIES + U U+4 0.0 238.0290 238.0290 + U(4) U+4 0.0 238.0290 + U(5) UO2+ 0.0 238.0290 + U(6) UO2+2 0.0 238.0290 +SOLUTION_SPECIES + #primary master species for U + #is also secondary master species for U(4) + U+4 = U+4 + log_k 0.0 + U+4 + 4 H2O = U(OH)4 + 4 H+ + log_k -8.538 + delta_h 24.760 kcal + U+4 + 5 H2O = U(OH)5- + 5 H+ + log_k -13.147 + delta_h 27.580 kcal + #secondary master species for U(5) + U+4 + 2 H2O = UO2+ + 4 H+ + e- + log_k -6.432 + delta_h 31.130 kcal + #secondary master species for U(6) + U+4 + 2 H2O = UO2+2 + 4 H+ + 2 e- + log_k -9.217 + delta_h 34.430 kcal + UO2+2 + H2O = UO2OH+ + H+ + log_k -5.782 + delta_h 11.015 kcal + 2UO2+2 + 2H2O = (UO2)2(OH)2+2 + 2H+ + log_k -5.626 + delta_h -36.04 kcal + 3UO2+2 + 5H2O = (UO2)3(OH)5+ + 5H+ + log_k -15.641 + delta_h -44.27 kcal + UO2+2 + CO3-2 = UO2CO3 + log_k 10.064 + delta_h 0.84 kcal + UO2+2 + 2CO3-2 = UO2(CO3)2-2 + log_k 16.977 + delta_h 3.48 kcal + UO2+2 + 3CO3-2 = UO2(CO3)3-4 + log_k 21.397 + delta_h -8.78 kcal +PHASES + Uraninite + UO2 + 4 H+ = U+4 + 2 H2O + log_k -3.490 + delta_h -18.630 kcal +END +USE solution 1 +REACTION_TEMPERATURE + 30 +END \ No newline at end of file diff --git a/global.h b/global.h new file mode 100644 index 00000000..9fb1f7f9 --- /dev/null +++ b/global.h @@ -0,0 +1,1638 @@ + +#ifdef PHREEQC_IDENT +static char const svnidglobal[] = "$Id$"; +#endif +#ifndef _INC_GLOBAL_H +#define _INC_GLOBAL_H + +#define NO_DOS +/* #define PHREEQ98 */ /* PHREEQ98: code for graphical user interface */ +#ifdef PHREEQ98 +/*#define fprintf fprintf98*/ +#endif +/* + * uncomment following line, to use default DOS file name for + * output file + */ +/*#define DOS*/ +/* + * BUG FIX FOR DGs + */ +#ifndef __OPEN_NAMESPACE__ +#define __OPEN_NAMESPACE__ +#endif +/* ---------------------------------------------------------------------- + * INCLUDE FILES + * ---------------------------------------------------------------------- */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" + +/* must be defined here and in cl.c */ +/* #include */ +#ifndef NAN +# define NAN -99999999 +#endif +#define MISSING -9999.999 +/* search.h -- declarations for POSIX/SVID-compatible search functions */ + + /* HSEARCH(3C) */ + typedef struct entry { char *key; void *data; } ENTRY; + typedef enum { FIND, ENTER } ACTION; + + /* TSEARCH(3C) */ + typedef enum { preorder, postorder, endorder, leaf } VISIT; + +/* ---------------------------------------------------------------------- + * DEFINITIONS + * ---------------------------------------------------------------------- */ +#define F_C_MOL 96493.5 /* C/mol or joule/volt-eq*/ +#define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ +#define F_KCAL_V_EQ 23.0623 /* kcal/volt-eq */ +#define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ +#define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ +#define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ +#define EPSILON 78.5 /* dialectric constant, dimensionless */ +#define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ +#define JOULES_PER_CALORIE 4.1840 + +typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; + +#define TRUE 1 +#define FALSE 0 +#define OK 1 +#define ERROR 0 +#define STOP 1 +#define CONTINUE 0 + +#define DISP 2 +#define STAG 3 +#define NOMIX 4 + +#define CONVERGED 2 +#define MASS_BALANCE 3 +/* +#define OSCILLATE 4 +#define H2O_LIMITS 5 + */ +#define REWRITE 2 +#define INIT -1 + +/* check_line values, plus EMPTY, EOF, OK */ +#define KEYWORD 3 + +/* copy_token values */ +#define EMPTY 2 +#define UPPER 4 +#define LOWER 5 +#define DIGIT 6 +#define UNKNOWN 7 +#define OPTION 8 + +/* species types */ +#define AQ 0 +#define HPLUS 1 +#define H2O 2 +#define EMINUS 3 +#define SOLID 4 +#define EX 5 +#define SURF 6 +#define SURF_PSI 7 + +/* unknown types */ +#define MB 10 +#define ALK 11 +#define CB 12 +#define SOLUTION_PHASE_BOUNDARY 13 +#define MU 14 +#define AH2O 15 +#define MH 16 +#define MH2O 17 +#define PP 18 +#define EXCH 19 +#define SURFACE 20 +#define SURFACE_CB 21 +#define GAS_MOLES 23 +#define S_S_MOLES 24 +#define PITZER_GAMMA 25 +/* state */ +#define INITIALIZE 0 +#define INITIAL_SOLUTION 1 +#define INITIAL_EXCHANGE 2 +#define INITIAL_SURFACE 3 +#define INITIAL_GAS_PHASE 4 +#define REACTION 5 +#define INVERSE 6 +#define ADVECTION 7 +#define TRANSPORT 8 +#define PHAST 9 + +/* constaints in mass balance */ +#define EITHER 0 +#define DISSOLVE 1 +#define PRECIPITATE -1 + +/* gas phase type */ +#define PRESSURE 1 +#define VOLUME 2 + +#define MAX_PP_ASSEMBLAGE 10 /* default estimate of the number of phase assemblages */ +#define MAX_ADD_EQUATIONS 20 /* maximum number of equations added together to reduce eqn to + master species */ +#define MAX_ELEMENTS 50 /* default estimate of the number of elements */ +#define MAX_LENGTH 200 /* maximum number of characters component name */ +#define MAX_LINE 80 /* estimate of maximum line length */ +#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ +#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +#define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ +#define MAX_MASTER 50 /* default estimate of the number of master species */ +#define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in + an equation */ +#define MAX_PHASES 500 /* initial guess of number of phases defined */ +#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ +#define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ +#define MAX_STRINGS 3000 +#define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ +#define MAX_SUM_MB 500 /* list used to calculate mass balance sums */ +#define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ +#define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ +#define TOL 1e-9 /* tolerance for comparisons of double numbers */ +#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +#define MIN_TOTAL 1e-25 +#define MIN_RELATED_SURFACE MIN_TOTAL*100 +#define MIN_RELATED_LOG_ACTIVITY -30 +/* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ +struct model { + int force_prep; + LDBLE temperature; + int count_exchange; + struct master **exchange; + + int count_kinetics; + struct kinetics *kinetics; + + int count_gas_phase; + struct phase **gas_phase; + + int count_s_s_assemblage; + char **s_s_assemblage; + + int count_pp_assemblage; + struct phase **pp_assemblage; + char **add_formula; + LDBLE *si; + + int diffuse_layer; + int count_surface_comp; + struct master **surface_comp; + int count_surface_charge; + struct master **surface_charge; +}; +EXTERNAL struct model last_model; +EXTERNAL int same_model; +EXTERNAL int same_temperature; + +struct name_master { + char *name; + struct master *master; +}; +struct name_species { + char *name; + struct species *s; +}; +struct name_phase { + char *name; + struct phase *phase; +}; +struct punch { + int in; + int new_def; + struct name_master *totals; + int count_totals; + struct name_species *molalities; + int count_molalities; + struct name_species *activities; + int count_activities; + struct name_phase *pure_phases; + int count_pure_phases; + struct name_phase *si; + int count_si; + struct name_phase *gases; + int count_gases; + struct name_phase *s_s; + int count_s_s; + struct name_phase *kinetics; + int count_kinetics; + struct name_master *isotopes; + int count_isotopes; + struct name_master *calculate_values; + int count_calculate_values; + int inverse; + int sim; + int state; + int soln; + int dist; + int time; + int step; + int rxn; + int temp; + int ph; + int pe; + int alk; + int mu; + int water; + int high_precision; + int user_punch; + int charge_balance; + int percent_error; +}; +EXTERNAL struct punch punch; +/* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ +struct temperature { + int n_user; + int n_user_end; + char *description; + LDBLE *t; + int count_t; +}; +EXTERNAL struct temperature *temperature; +EXTERNAL int count_temperature; +/* ---------------------------------------------------------------------- + * Surface + * ---------------------------------------------------------------------- */ +struct surface { + int n_user; + int n_user_end; + int new_def; + int diffuse_layer; + int edl; + int only_counter_ions; + int donnan; + LDBLE thickness; + LDBLE debye_units; + char *description; + int solution_equilibria; + int n_solution; + int count_comps; + struct surface_comp *comps; + int count_charge; + struct surface_charge *charge; + int related_phases; + int related_rate; + int transport; +}; +struct surface_comp { + char *formula; + LDBLE moles; + struct master *master; + struct elt_list *totals; + LDBLE la; + int charge; + LDBLE cb; + char *phase_name; + LDBLE phase_proportion; + char *rate_name; +}; +struct surface_charge { + char *name; + LDBLE specific_area; + LDBLE grams; + LDBLE charge_balance; + LDBLE mass_water; + struct elt_list *diffuse_layer_totals; + int count_g; + struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ + struct master *psi_master; + LDBLE la_psi; +}; +struct surface_diff_layer { + LDBLE charge; + LDBLE g; + LDBLE dg; + LDBLE psi_to_z; +}; +EXTERNAL struct surface *surface; +EXTERNAL struct surface *dbg_surface; +EXTERNAL int count_surface; +EXTERNAL int max_surface; +EXTERNAL struct charge_group { + LDBLE z; + LDBLE eq; +} *charge_group; +/* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ +struct exchange { + int n_user; + int n_user_end; + int new_def; + char *description; + int solution_equilibria; + int n_solution; + int count_comps; + struct exch_comp *comps; + int related_phases; + int related_rate; + int pitzer_exchange_gammas; +}; +struct exch_comp { + char *formula; + LDBLE formula_z; + struct elt_list *formula_totals; + LDBLE moles; + struct master *master; + struct elt_list *totals; + LDBLE la; + LDBLE charge_balance; + char *phase_name; + LDBLE phase_proportion; + char *rate_name; +}; +EXTERNAL struct exchange *exchange; +EXTERNAL struct exchange *dbg_exchange; +EXTERNAL int count_exchange; +EXTERNAL int max_exchange; +/* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ +struct kinetics { + int n_user; + int n_user_end; + char *description; + int count_comps; + struct kinetics_comp *comps; + int count_steps; + LDBLE *steps; + LDBLE step_divide; + /*char *units;*/ + struct elt_list *totals; + int rk; + int bad_step_max; + int use_cvode; +}; +struct kinetics_comp { + char *rate_name; +#ifdef SKIP + char *formula; +#endif + struct name_coef *list; + int count_list; +/* struct phase *phase; */ + LDBLE tol; + LDBLE m; + LDBLE initial_moles; + LDBLE m0; + LDBLE moles; + int count_c_params; + char **c_params; + int count_d_params; + LDBLE *d_params; +}; +EXTERNAL struct kinetics *kinetics; +EXTERNAL struct kinetics *dbg_kinetics; +EXTERNAL int count_kinetics; +EXTERNAL int max_kinetics; + +struct save_values { + LDBLE value; + int count_subscripts; + int *subscripts; +}; +EXTERNAL int count_save_values; +EXTERNAL struct save_values *save_values; + +#ifdef SKIP +struct kin_exch { + char *exch_name; + char *phase_name; + LDBLE phase_proportion; +}; +EXTERNAL struct kin_exch *kin_exch; +EXTERNAL int count_kin_exch; +struct kin_surf { + char *surf_name; + char *phase_name; + LDBLE phase_proportion; +}; +EXTERNAL struct kin_surf *kin_surf; +EXTERNAL int count_kin_surf; +#endif +/*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ +struct save { + int solution; + int n_solution_user; + int n_solution_user_end; + int mix; + int n_mix_user; + int n_mix_user_end; + int irrev; + int n_irrev_user; + int n_irrev_user_end; + int pp_assemblage; + int n_pp_assemblage_user; + int n_pp_assemblage_user_end; + int exchange; + int n_exchange_user; + int n_exchange_user_end; + int kinetics; + int n_kinetics_user; + int n_kinetics_user_end; + int surface; + int n_surface_user; + int n_surface_user_end; + int gas_phase; + int n_gas_phase_user; + int n_gas_phase_user_end; + int s_s_assemblage; + int n_s_s_assemblage_user; + int n_s_s_assemblage_user_end; +}; +EXTERNAL struct save save; +/*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ +struct use { + int solution_in; + int n_solution_user; + int n_solution; + struct solution *solution_ptr; + + int pp_assemblage_in; + int n_pp_assemblage_user; + int n_pp_assemblage; + struct pp_assemblage *pp_assemblage_ptr; + + int mix_in; + int n_mix_user; + int n_mix; + struct mix *mix_ptr; + int n_mix_user_orig; + + int irrev_in; + int n_irrev_user; + int n_irrev; + struct irrev *irrev_ptr; + + int exchange_in; + int n_exchange_user; + int n_exchange; + struct exchange *exchange_ptr; + + int kinetics_in; + int n_kinetics_user; + int n_kinetics; + struct kinetics *kinetics_ptr; + + int surface_in; + int n_surface_user; + int n_surface; + struct surface *surface_ptr; + + int temperature_in; + int n_temperature_user; + int n_temperature; + struct temperature *temperature_ptr; + + int inverse_in; + int n_inverse_user; + int n_inverse; + struct inverse *inverse_ptr; + + int gas_phase_in; + int n_gas_phase_user; + int n_gas_phase; + struct gas_phase *gas_phase_ptr; + + int s_s_assemblage_in; + int n_s_s_assemblage_user; + int n_s_s_assemblage; + struct s_s_assemblage *s_s_assemblage_ptr; + + int trans_in; + int advect_in; +}; +EXTERNAL struct use use; +EXTERNAL struct use *dbg_use; +/*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ +struct copier { + int count; + int max; + int *n_user; + int *start; + int *end; +}; +EXTERNAL struct copier copy_solution; +EXTERNAL struct copier copy_pp_assemblage; +EXTERNAL struct copier copy_exchange; +EXTERNAL struct copier copy_surface; +EXTERNAL struct copier copy_s_s_assemblage; +EXTERNAL struct copier copy_gas_phase; +EXTERNAL struct copier copy_kinetics; +EXTERNAL struct copier copy_mix; +EXTERNAL struct copier copy_irrev; +EXTERNAL struct copier copy_temperature; + + +/*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ +struct inverse { + int n_user; + char *description; + int new_def; + int minimal; + int range; + int mp; + LDBLE mp_censor; + LDBLE range_max; + LDBLE tolerance; + LDBLE mp_tolerance; + int count_uncertainties; + LDBLE *uncertainties; + int count_ph_uncertainties; + LDBLE *ph_uncertainties; +#ifdef SKIP + LDBLE *alk_uncertainties; +#endif + LDBLE water_uncertainty; + int mineral_water; + int carbon; + LDBLE *dalk_dph; + LDBLE *dalk_dc; + int count_solns; + int *solns; + int count_force_solns; + int *force_solns; + int count_elts; + struct inv_elts *elts; + int count_phases; + struct inv_phases *phases; + int count_master_list; + struct master **master_list; + int count_redox_rxns; + int count_isotopes; + struct inv_isotope *isotopes; + int count_i_u; + struct inv_isotope *i_u; + int count_isotope_unknowns; + struct isotope *isotope_unknowns; +}; +struct inv_elts { + char *name; + struct master *master; + int row; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_isotope { + char *isotope_name; + LDBLE isotope_number; + char *elt_name; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_phases { + char *name; + struct phase *phase; + int column; + int constraint; + int force; + int count_isotopes; + struct isotope *isotopes; +}; +EXTERNAL struct inverse *inverse; +EXTERNAL int count_inverse; + +/*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ +struct mix { + int n_user; + int n_user_end; + char *description; + int count_comps; + struct mix_comp *comps; +}; +struct mix_comp { + int n_solution; + LDBLE fraction; +}; +EXTERNAL struct mix *mix; +EXTERNAL struct mix *dbg_mix; +EXTERNAL int count_mix; +/*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ +struct irrev { + int n_user; + int n_user_end; + char *description; + struct name_coef *list; + struct elt_list *elts; + LDBLE *steps; + char *units; + int count_steps; + int count_list; +}; +struct name_coef { + char *name; + LDBLE coef; +}; +EXTERNAL struct irrev *irrev; +EXTERNAL struct irrev *dbg_irrev; +EXTERNAL int count_irrev; +/*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ +struct gas_phase { + int n_user; + int n_user_end; + char *description; + int new_def; + int solution_equilibria; + int n_solution; + int type; + LDBLE total_p; + LDBLE total_moles; + LDBLE volume; + LDBLE temperature; + int count_comps; + struct gas_comp *comps; +}; +struct gas_comp { + struct phase *phase; + char *name; + LDBLE p_read; + LDBLE moles; + LDBLE initial_moles; +}; +EXTERNAL int count_gas_phase; +EXTERNAL int max_gas_phase; +EXTERNAL struct gas_phase *gas_phase; +/*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ +struct s_s_assemblage { + int n_user; + int n_user_end; + char *description; + int new_def; +/* int type; */ +/* int solution_equilibria; */ +/* int n_solution; */ + int count_s_s; + struct s_s *s_s; +}; +struct s_s { + char *name; + struct s_s_comp *comps; + int count_comps; + LDBLE total_moles; + LDBLE dn; + LDBLE a0, a1; + LDBLE ag0, ag1; + int s_s_in; + int miscibility; + int spinodal; + LDBLE tk, xb1, xb2; + int input_case; + LDBLE p[4]; +}; +struct s_s_comp { + char *name; + struct phase *phase; + LDBLE initial_moles; + LDBLE moles; + LDBLE init_moles; + LDBLE delta; + LDBLE fraction_x; + LDBLE log10_lambda; + LDBLE log10_fraction_x; + LDBLE dn, dnc, dnb; +}; +EXTERNAL int count_s_s_assemblage; +EXTERNAL int max_s_s_assemblage; +EXTERNAL struct s_s_assemblage *s_s_assemblage; +/*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ +struct pp_assemblage { + int n_user; + int n_user_end; + char *description; + int new_def; + struct elt_list *next_elt; + int count_comps; + struct pure_phase *pure_phases; +}; +struct pure_phase { + struct phase *phase; + char *name; + char *add_formula; + LDBLE si; + LDBLE moles; + LDBLE delta; + LDBLE initial_moles; + int dissolve_only; +}; +EXTERNAL int count_pp_assemblage; +EXTERNAL int max_pp_assemblage; +EXTERNAL struct pp_assemblage *pp_assemblage; +EXTERNAL struct pp_assemblage *dbg_pp_assemblage; +/*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ +struct species_list { + struct species *master_s; + struct species *s; + LDBLE coef; +}; +EXTERNAL int count_species_list; +EXTERNAL int max_species_list; +EXTERNAL struct species_list *species_list; +/*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ +struct list0 { + LDBLE *target; + LDBLE coef; +}; +EXTERNAL int count_sum_jacob0; /* number of elements in sum_jacob0 */ +EXTERNAL int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ +EXTERNAL struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + +struct list1 { + LDBLE *source; + LDBLE *target; +}; +EXTERNAL int count_sum_mb1; /* number of elements in sum_mb1 */ +EXTERNAL int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ +EXTERNAL struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ +EXTERNAL int count_sum_jacob1; /* number of elements in sum_jacob1 */ +EXTERNAL int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ +EXTERNAL struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ +struct list2 { + LDBLE *source; + LDBLE *target; + LDBLE coef; +}; +EXTERNAL int count_sum_mb2; /* number of elements in sum_mb2 */ +EXTERNAL int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ +EXTERNAL struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ +EXTERNAL int count_sum_jacob2; /* number of elements in sum_jacob2 */ +EXTERNAL int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ +EXTERNAL struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ +EXTERNAL int count_sum_delta; /* number of elements in sum_delta */ +EXTERNAL int max_sum_delta; /* calculated maximum number of elements in sum_delta */ +EXTERNAL struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ +/*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ +struct solution { + int new_def; + int n_user; + int n_user_end; + char *description; + LDBLE tc; + LDBLE ph; + LDBLE solution_pe; + LDBLE mu; + LDBLE ah2o; + LDBLE density; + LDBLE total_h; + LDBLE total_o; + LDBLE cb; + LDBLE mass_water; + LDBLE total_alkalinity; + /*LDBLE total_co2;*/ + char *units; + struct pe_data *pe; + int default_pe; + struct conc *totals; + struct master_activity *master_activity; + int count_master_activity; + int count_isotopes; + struct isotope *isotopes; + struct master_activity *species_gamma; + int count_species_gamma; +}; +struct master_activity { + char *description; + LDBLE la; +}; +struct conc { + char *description; + /*int skip;*/ + LDBLE moles; + LDBLE input_conc; + char *units; + char *equation_name; + struct phase *phase; + LDBLE phase_si; + int n_pe; + char *as; + LDBLE gfw; +}; +struct pe_data { + char *name; + struct reaction *rxn; +}; +struct isotope { + LDBLE isotope_number; + char *elt_name; + char *isotope_name; + LDBLE total; + LDBLE ratio; + LDBLE ratio_uncertainty; + LDBLE x_ratio_uncertainty; + struct master *master; + struct master *primary; + LDBLE coef; /* coefficient of element in phase */ +}; +EXTERNAL struct solution **solution; +EXTERNAL struct solution **dbg_solution; +EXTERNAL int count_solution; +EXTERNAL int max_solution; +struct iso { + char *name; + LDBLE value; + LDBLE uncertainty; +}; +#ifdef MAINSUBS +struct iso iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} +}; +int count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct iso)); +#else +extern struct iso iso_defaults[]; +extern int count_iso_defaults; +#endif +/*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ +EXTERNAL char *title_x; +EXTERNAL int new_x; +EXTERNAL char *description_x; +EXTERNAL LDBLE tc_x; +EXTERNAL LDBLE tk_x; +EXTERNAL LDBLE ph_x; +EXTERNAL LDBLE solution_pe_x; +EXTERNAL LDBLE mu_x; +EXTERNAL LDBLE ah2o_x; +EXTERNAL LDBLE density_x; +EXTERNAL LDBLE total_h_x; +EXTERNAL LDBLE total_o_x; +EXTERNAL LDBLE cb_x; +EXTERNAL LDBLE total_ions_x; +EXTERNAL LDBLE mass_water_aq_x; +EXTERNAL LDBLE mass_water_surfaces_x; +EXTERNAL LDBLE mass_water_bulk_x; +EXTERNAL char *units_x; +EXTERNAL struct pe_data *pe_x; +EXTERNAL int count_isotopes_x; +EXTERNAL struct isotope *isotopes_x; +EXTERNAL int default_pe_x; +EXTERNAL int diffuse_layer_x; +EXTERNAL LDBLE total_carbon; +EXTERNAL LDBLE total_co2; +EXTERNAL LDBLE total_alkalinity; +EXTERNAL LDBLE gfw_water; +EXTERNAL LDBLE step_x; +EXTERNAL LDBLE kin_time_x; +/*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ +EXTERNAL int count_cells; +EXTERNAL int count_shifts; +EXTERNAL int ishift; +EXTERNAL int bcon_first; +EXTERNAL int bcon_last; +EXTERNAL int correct_disp; +EXTERNAL LDBLE tempr; +EXTERNAL LDBLE timest; +EXTERNAL int simul_tr; +EXTERNAL LDBLE diffc; +EXTERNAL LDBLE heat_diffc; +EXTERNAL int cell; +/* !!!!! EXTERNAL int count_stag; */ +EXTERNAL struct stag_data { + int count_stag; + LDBLE exch_f; + LDBLE th_m; + LDBLE th_im; +} *stag_data; +EXTERNAL int print_modulus; +EXTERNAL int punch_modulus; +EXTERNAL int dump_in; +EXTERNAL int dump_modulus; +EXTERNAL int transport_warnings; +EXTERNAL struct cell_data { + LDBLE length; + LDBLE mid_cell_x; + LDBLE disp; + LDBLE temp; + int punch; + int print; +} *cell_data; +EXTERNAL int cell_no; +/*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ +EXTERNAL int count_ad_cells; +EXTERNAL int count_ad_shifts; +EXTERNAL int print_ad_modulus; +EXTERNAL int punch_ad_modulus; +EXTERNAL int *advection_punch, *advection_print; +EXTERNAL LDBLE advection_kin_time; +EXTERNAL LDBLE advection_kin_time_defined; +EXTERNAL int advection_warnings; + +/*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ +struct key { + char *name; + int keycount; +}; +#ifdef MAINSUBS + /* list of valid keywords */ +struct key keyword[] = { + {"eof", 0}, + {"end", 0}, + {"solution_species", 0}, + {"solution_master_species", 0}, + {"solution", 0}, + {"phases", 0}, + {"pure_phases", 0}, + {"reaction", 0}, + {"mix", 0}, + {"use", 0}, + {"save", 0}, + {"exchange_species", 0}, + {"exchange_master_species", 0}, + {"exchange", 0}, + {"surface_species", 0}, + {"surface_master_species", 0}, + {"surface", 0}, + {"reaction_temperature", 0}, + {"inverse_modeling", 0}, + {"gas_phase", 0}, + {"transport", 0}, + {"debug", 0}, + {"selected_output", 0}, + {"select_output", 0}, + {"knobs", 0}, + {"print", 0}, + {"equilibrium_phases", 0}, + {"equilibria", 0}, + {"equilibrium", 0}, + {"pure", 0}, + {"title", 0}, + {"comment", 0}, + {"advection", 0}, + {"kinetics", 0}, + {"incremental_reactions", 0}, + {"incremental", 0}, + {"rates", 0}, + {"solution_s", 0}, + {"user_print", 0}, + {"user_punch", 0}, + {"solid_solutions", 0}, + {"solid_solution", 0}, + {"solution_spread", 0}, + {"spread_solution", 0}, + {"selected_out", 0}, + {"select_out", 0}, + {"user_graph", 0}, + {"llnl_aqueous_model_parameters", 0}, + {"llnl_aqueous_model", 0}, + {"database", 0}, + {"named_analytical_expression", 0}, + {"named_analytical_expressions", 0}, + {"named_expressions", 0}, + {"named_log_k", 0}, + {"isotopes", 0}, + {"calculate_values", 0}, + {"isotope_ratios", 0}, + {"isotope_alphas", 0}, + {"copy", 0}, + {"pitzer", 0}, + {"solution_raw", 0}, + {"exchange_raw", 0}, + {"surface_raw", 0}, + {"equilibrium_phases_raw", 0}, + {"kinetics_raw", 0}, + {"solid_solutions_raw", 0}, + {"gas_phase_raw", 0}, + {"reaction_raw", 0}, + {"mix_raw", 0}, + {"reaction_temperature_raw", 0} +}; +int NKEYS = (sizeof(keyword) / sizeof(struct key)); /* Number of valid keywords */ +#else + extern struct key keyword[]; + extern int NKEYS; +#endif +EXTERNAL struct key *keyword_hash; +EXTERNAL int new_model, new_exchange, new_pp_assemblage, new_surface, new_reaction, new_temperature, + new_mix, new_solution, new_gas_phase, new_inverse, new_punch, new_s_s_assemblage, + new_kinetics, new_copy, new_pitzer; +/*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ +struct element { + char *name; /* element name */ +/* int in; */ + struct master *master; + struct master *primary; + LDBLE gfw; +}; +EXTERNAL struct element **elements; +EXTERNAL int count_elements; +EXTERNAL int max_elements; +EXTERNAL struct element *element_h_one; + +/*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ +struct elt_list { /* list of name and number of elements in an equation */ + struct element *elt; /* pointer to element structure */ + LDBLE coef; /* number of element e's in eqn */ +}; +EXTERNAL struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order*/ +EXTERNAL int count_elts; /* number of elements in elt_list = position of next */ +EXTERNAL int max_elts; +/*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ +struct reaction { + LDBLE logk[8]; + struct rxn_token *token; +}; +struct rxn_token { + struct species *s; + LDBLE coef; +}; +/*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ +struct species { /* all data pertinent to an aqueous species */ + char *name; /* name of species */ + char *mole_balance; /* formula for mole balance */ + int in; /* species used in model if TRUE */ + int number; + struct master *primary; /* points to master species list, NULL if not primary master */ + struct master *secondary; /* points to master species list, NULL if not secondary master */ + LDBLE gfw; /* gram formula wt of species */ + LDBLE z; /* charge of species */ + LDBLE equiv; /* equivalents in exchange species */ + LDBLE alk; /* alkalinity of species, used for cec in exchange */ + LDBLE carbon; /* stoichiometric coefficient of carbon in species */ + LDBLE co2; /* stoichiometric coefficient of C(4) in species */ + LDBLE h; /* stoichiometric coefficient of H in species */ + LDBLE o; /* stoichiometric coefficient of O in species */ + LDBLE dha, dhb; /* WATEQ Debye Huckel a and b-dot */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + struct name_coef *add_logk; + LDBLE lg; /* log10 activity coefficient, gamma */ + LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */ + LDBLE lm; /* log10 molality */ + LDBLE la; /* log10 activity */ + LDBLE dg; /* gamma term for jacobian */ + LDBLE dg_total_g; + LDBLE moles; /* moles in solution; moles/mass_water = molality */ + int type; /* flag indicating presence in model and types of equations */ + int gflag; /* flag for preferred activity coef eqn */ + int exch_gflag; /* flag for preferred activity coef eqn */ + struct elt_list *next_elt; /* pointer to next element */ + struct elt_list *next_secondary; + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ + LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ + struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each + surface */ +}; +struct logk { /* Named log K's */ + char *name; /* name of species */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE log_k[8]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ +}; +EXTERNAL struct logk **logk; +EXTERNAL int count_logk; +EXTERNAL int max_logk; +struct species_diff_layer { + struct surface_charge *charge; + int count_g; + LDBLE g_moles; + LDBLE dg_g_moles; /* g_moles*dgterm */ + LDBLE dx_moles; + LDBLE dh2o_moles; /* moles*g*Ws/Waq */ + LDBLE drelated_moles; /* for related phase */ +}; +EXTERNAL char *moles_per_kilogram_string; +EXTERNAL char *pe_string; + +EXTERNAL struct species **s; +EXTERNAL int count_s; +EXTERNAL int max_s; + +EXTERNAL struct species **s_x; +EXTERNAL int count_s_x; +EXTERNAL int max_s_x; + +EXTERNAL struct species *s_h2o; +EXTERNAL struct species *s_hplus ; +EXTERNAL struct species *s_h3oplus ; +EXTERNAL struct species *s_eminus; +EXTERNAL struct species *s_co3; +EXTERNAL struct species *s_h2; +EXTERNAL struct species *s_o2; +/*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ +struct phase { /* all data pertinent to a pure solid phase */ + char *name; /* name of species */ + char *formula; /* chemical formula */ + int in; /* species used in model if TRUE */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + struct name_coef *add_logk; + LDBLE moles_x; + LDBLE p_soln_x; + LDBLE fraction_x; + LDBLE log10_lambda, log10_fraction_x; + LDBLE dn, dnb, dnc; + LDBLE gn, gntot; + LDBLE gn_n, gntot_n; + + int type; /* flag indicating presence in model and types of equations */ + struct elt_list *next_elt; /* pointer to list of elements in phase */ + /* struct elt_list *next_secondary; */ + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + int in_system; +}; +EXTERNAL struct phase **phases; +EXTERNAL int count_phases; +EXTERNAL int max_phases; +/*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ +struct master { /* list of name and number of elements in an equation */ + int in; /* TRUE if in model, FALSE if out, REWRITE if other mb eq */ + int number; /* sequence number in list of masters */ + int last_model; /* saved to determine if model has changed */ + int type; /* AQ or EX */ + int primary; /* TRUE if master species is primary */ + LDBLE coef; /* coefficient of element in master species */ + LDBLE total; /* total concentration for element or valence state */ + LDBLE isotope_ratio; + LDBLE isotope_ratio_uncertainty; + int isotope; + LDBLE total_primary; +/* LDBLE la; */ /* initial guess of master species log activity */ + struct element *elt; /* element structure */ + LDBLE alk; /* alkalinity of species */ + LDBLE gfw; /* default gfw for species */ + char *gfw_formula; /* formula from which to calcuate gfw */ + struct unknown *unknown; /* pointer to unknown structure */ + struct species *s; /* pointer to species structure */ + struct reaction *rxn_primary; /* reaction writes master species in terms of primary + master species */ + struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary + master species */ + struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points + to location */ + int minor_isotope; +}; +EXTERNAL struct master **master; /* structure array of master species */ +EXTERNAL int count_master; +EXTERNAL int max_master; +/*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ +struct unknown { + int type; + LDBLE moles; + LDBLE ln_moles; + LDBLE f; + LDBLE sum; + LDBLE delta; + LDBLE la; + int number; + char *description; + struct master **master; + struct phase *phase; + LDBLE si; + struct gas_phase *gas_phase; + struct conc *total; + struct species *s; + struct exch_comp *exch_comp; + struct pure_phase *pure_phase; + struct s_s *s_s; + struct s_s_comp *s_s_comp; + int s_s_comp_number; + int s_s_in; + struct surface_comp *surface_comp; + LDBLE related_moles; + struct unknown *potential_unknown; + struct unknown *phase_unknown; + struct surface_charge *surface_charge; + LDBLE mass_water; + int dissolve_only; +}; +EXTERNAL struct unknown **x; +EXTERNAL int count_unknowns; +EXTERNAL int max_unknowns; + +EXTERNAL struct unknown *ah2o_unknown; +EXTERNAL struct unknown *alkalinity_unknown; +EXTERNAL struct unknown *carbon_unknown; +EXTERNAL struct unknown *charge_balance_unknown; +EXTERNAL struct unknown *exchange_unknown; +EXTERNAL struct unknown *mass_hydrogen_unknown; +EXTERNAL struct unknown *mass_oxygen_unknown; +EXTERNAL struct unknown *mb_unknown; +EXTERNAL struct unknown *mu_unknown; +EXTERNAL struct unknown *pe_unknown; +EXTERNAL struct unknown *ph_unknown; +EXTERNAL struct unknown *pure_phase_unknown; +EXTERNAL struct unknown *solution_phase_boundary_unknown; +EXTERNAL struct unknown *surface_unknown; +EXTERNAL struct unknown *gas_unknown; +EXTERNAL struct unknown *s_s_unknown; +/*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ +struct reaction_temp { + LDBLE logk[8]; + struct rxn_token_temp *token; +}; +struct rxn_token_temp { /* data for equations, aq. species or minerals */ + char *name; /* pointer to a species name (formula) */ + LDBLE z; /* charge on species */ + struct species *s; + struct unknown *unknown; + LDBLE coef; /* coefficient of species name */ +}; +EXTERNAL struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ +EXTERNAL int count_trxn; /* number of reactants in trxn = position of next */ +EXTERNAL int max_trxn; +struct unknown_list { + struct unknown *unknown; + LDBLE *source; + LDBLE *gamma_source; +/* int row; */ +/* int col; */ + LDBLE coef; +}; +EXTERNAL struct unknown_list *mb_unknowns; +EXTERNAL int count_mb_unknowns; +EXTERNAL int max_mb_unknowns; +/* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ +struct prints { + int all; + int initial_solutions; + int initial_exchangers; + int reactions; + int gas_phase; + int s_s_assemblage; + int pp_assemblage; + int surface; + int exchange; + int kinetics; + int totals; + int eh; + int species; + int saturation_indices; + int irrev; + int mix; + int reaction; + int use; + int logfile; + int punch; + int status; + int inverse; + int dump; + int user_print; + int headings; + int user_graph; + int echo_input; + int warnings; + int initial_isotopes; + int isotope_ratios; + int isotope_alphas; + int hdf; + int alkalinity; +}; +EXTERNAL struct prints pr; +EXTERNAL int status_on; +EXTERNAL int count_warnings; + +/* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ +struct rate { + char *name; + char *commands; + int new_def; + void *linebase; + void *varbase; + void *loopbase; +}; +EXTERNAL struct rate *rates; +EXTERNAL int count_rates; +EXTERNAL LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; +EXTERNAL int count_rate_p; +/* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ +EXTERNAL struct rate *user_print; +EXTERNAL struct rate *user_punch; +EXTERNAL char **user_punch_headings; +EXTERNAL int user_punch_count_headings; +#ifdef PHREEQ98 +EXTERNAL struct rate *user_graph; +EXTERNAL char **user_graph_headings; +EXTERNAL int user_graph_count_headings; +#endif + +/* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ +EXTERNAL char error_string[10*MAX_LENGTH]; +EXTERNAL int simulation; +EXTERNAL int state; +EXTERNAL int reaction_step; +EXTERNAL int transport_step; +EXTERNAL int transport_start; +EXTERNAL int advection_step; +EXTERNAL int stop_program; +EXTERNAL int incremental_reactions; + +EXTERNAL int count_strings; +EXTERNAL int max_strings; + +EXTERNAL LDBLE *array; +EXTERNAL LDBLE *delta; +EXTERNAL LDBLE *residual; + +EXTERNAL int input_error; +EXTERNAL int next_keyword; +EXTERNAL int parse_error; +EXTERNAL int paren_count; +EXTERNAL int iterations; +EXTERNAL int gamma_iterations; +EXTERNAL int run_reactions_iterations; + +EXTERNAL int max_line; +EXTERNAL char *line; +EXTERNAL char *line_save; + +EXTERNAL LDBLE LOG_10; + +EXTERNAL int debug_model; +EXTERNAL int debug_prep; +EXTERNAL int debug_set; +EXTERNAL int debug_diffuse_layer; +EXTERNAL int debug_inverse; + +EXTERNAL LDBLE inv_tol_default; +EXTERNAL int itmax; +EXTERNAL LDBLE ineq_tol; +EXTERNAL LDBLE convergence_tolerance; +EXTERNAL LDBLE step_size; +EXTERNAL LDBLE pe_step_size; +EXTERNAL LDBLE step_size_now; +EXTERNAL LDBLE pe_step_size_now; +EXTERNAL LDBLE pp_scale; +EXTERNAL LDBLE pp_column_scale; +EXTERNAL int diagonal_scale; /* 0 not used, 1 used */ +EXTERNAL int mass_water_switch; +EXTERNAL int delay_mass_water; +EXTERNAL LDBLE censor; +EXTERNAL int aqueous_only; +EXTERNAL int negative_concentrations; + +EXTERNAL int count_total_steps; +EXTERNAL int phast; +EXTERNAL LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; +EXTERNAL int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, llnl_count_co2_coefs; + +EXTERNAL char *selected_output_file_name; +EXTERNAL char *dump_file_name; +struct spread_row { + int count; + int empty, string, number; + char **char_vector; + LDBLE *d_vector; + int *type_vector; +}; +struct defaults { + LDBLE temp; + LDBLE density; + char *units; + char *redox; + LDBLE ph; + LDBLE pe; + LDBLE water; + int count_iso; + struct iso *iso; +}; +struct spread_sheet { + struct spread_row *heading; + struct spread_row *units; + int count_rows; + struct spread_row **rows; + struct defaults defaults; +}; +#ifdef PHREEQCI_GUI +EXTERNAL struct spread_sheet g_spread_sheet; +#endif + +/* ---------------------------------------------------------------------- */ +/* + * Hash definitions + */ +/* +** Constants +*/ + +# define SegmentSize 256 +# define SegmentSizeShift 8 /* log2(SegmentSize) */ +# define DirectorySize 256 +# define DirectorySizeShift 8 /* log2(DirectorySize) */ +# define Prime1 37 +# define Prime2 1048583 +# define DefaultMaxLoadFactor 5 + + +typedef struct Element + { + /* + ** The user only sees the first two fields, + ** as we pretend to pass back only a pointer to ENTRY. + ** {S}he doesn't know what else is in here. + */ + char *Key; + char *Data; + struct Element *Next; /* secret from user */ + } Element,*Segment; + +typedef struct + { + short p; /* Next bucket to be split */ + short maxp; /* upper bound on p during expansion */ + long KeyCount; /* current # keys */ + short SegmentCount; /* current # segments */ + short MinLoadFactor; + short MaxLoadFactor; + Segment *Directory[DirectorySize]; + } HashTable; + +typedef unsigned long Address; + +EXTERNAL HashTable *strings_hash_table; +EXTERNAL HashTable *elements_hash_table; +EXTERNAL HashTable *species_hash_table; +EXTERNAL HashTable *phases_hash_table; +EXTERNAL HashTable *keyword_hash_table; +EXTERNAL HashTable *logk_hash_table; +EXTERNAL HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ + +EXTERNAL struct name_coef match_tokens[50]; +EXTERNAL int count_match_tokens; +struct master_isotope { + char *name; + struct master *master; + struct element *elt; + char *units; + LDBLE standard; + LDBLE ratio; + LDBLE moles; + int total_is_major; + int minor_isotope; +}; +EXTERNAL int count_master_isotope; +EXTERNAL struct master_isotope **master_isotope; +EXTERNAL int max_master_isotope; +EXTERNAL int initial_solution_isotopes; + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPT_1 -5 + +struct calculate_value { + char *name; + LDBLE value; + char *commands; + int new_def; + int calculated; + void *linebase; + void *varbase; + void *loopbase; +}; +EXTERNAL int count_calculate_value; +EXTERNAL struct calculate_value **calculate_value; +EXTERNAL int max_calculate_value; +EXTERNAL HashTable *calculate_value_hash_table; + +struct isotope_ratio { + char *name; + char *isotope_name; + LDBLE ratio; + LDBLE converted_ratio; +}; +EXTERNAL int count_isotope_ratio; +EXTERNAL struct isotope_ratio **isotope_ratio; +EXTERNAL int max_isotope_ratio; +EXTERNAL HashTable *isotope_ratio_hash_table; +struct isotope_alpha { + char *name; + char *named_logk; + LDBLE value; +}; +EXTERNAL int count_isotope_alpha; +EXTERNAL struct isotope_alpha **isotope_alpha; +EXTERNAL int max_isotope_alpha; +EXTERNAL HashTable *isotope_alpha_hash_table; + +EXTERNAL int phreeqc_mpi_myself; + +enum entity_type { Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, Kinetics, Mix, Temperature, UnKnown }; + +EXTERNAL int first_read_input; +EXTERNAL char *user_database; +EXTERNAL int pitzer_model; +EXTERNAL int full_pitzer, always_full_pitzer, ICON, IC; +EXTERNAL double COSMOT; +EXTERNAL double AW; + +EXTERNAL jmp_buf mark; + +#if defined(WIN32) +#include +#endif + +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif + +#endif /* _INC_GLOBAL_H */ diff --git a/input.cpp b/input.cpp new file mode 100644 index 00000000..812a92ba --- /dev/null +++ b/input.cpp @@ -0,0 +1,249 @@ +#define EXTERNAL extern +#include +#include "global.h" +#include "input.h" +#include "output.h" +#include "phrqproto.h" +#include "phqalloc.h" + +static char const svnid[] = "$Id: input.c 78 2005-02-01 22:47:12Z dlpark $"; + +int check_line_return; + +static struct read_callback s_read_callback; + + +/* ---------------------------------------------------------------------- */ +int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database) +/* ---------------------------------------------------------------------- */ +{ + if (svnid == NULL) fprintf(stderr," "); + s_read_callback.callback = pfn; + s_read_callback.cookie = cookie; + s_read_callback.database = database; + return OK; +} +/* ---------------------------------------------------------------------- */ +int reading_database(void) +/* ---------------------------------------------------------------------- */ +{ + return s_read_callback.database; +} +/* ---------------------------------------------------------------------- */ +int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) +/* ---------------------------------------------------------------------- */ +{ + assert(s_read_callback.callback != NULL); + if (s_read_callback.callback == NULL) return EOF; + if (reading_database()) print = FALSE; + return check_line_impl(s_read_callback.callback, s_read_callback.cookie, string, allow_empty, allow_eof, allow_keyword, print); +} +/* ---------------------------------------------------------------------- */ +int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function gets a new line and checks for empty, eof, and keywords. + * + * Arguments: + * string Input, character string used in printing error message + * allow_empty Input, True or false, if a blank line is accepable + * if false, another line is read + * allow_eof Input, True or false, if EOF is acceptable + * allow_keyword Input, True or false, if a keyword is acceptable + * + * Returns: + * EMPTY if empty line read and allow_empty == true + * KEYWORD if line begins with keyword + * EOF if eof and allow_eof == true + * OK otherwise + * OPTION if line begins with -[alpha] + * + * Terminates if EOF and allow_eof == false. + */ + int i; + + +/* Get line */ + do { + i = get_line(pfn, cookie); + if ((print == TRUE && i != EOF) || i == KEYWORD) { + output_msg(OUTPUT_CHECKLINE,"\t%s\n",line_save); + } + } while ( i == EMPTY && allow_empty == FALSE ); +/* Check eof */ + if ( i == EOF && allow_eof == FALSE ) { + sprintf(error_string,"Unexpected eof while reading %s\nExecution terminated.\n",string); + error_msg(error_string, STOP); + } +/* Check keyword */ + if (i == KEYWORD && allow_keyword == FALSE ) { + sprintf(error_string, "Expected data for %s, but got a keyword ending data block.", string); + error_msg(error_string, CONTINUE); + input_error++; + } + check_line_return = i; + return (i); +} +/* ---------------------------------------------------------------------- */ +int get_line(PFN_READ_CALLBACK pfn, void *cookie) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line from input file put in "line". + * Copy of input line is stored in "line_save". + * Characters after # are discarded in line but retained in "line_save" + * + * Arguments: + * fp is file name + * Returns: + * EMPTY, + * EOF, + * KEYWORD, + * OK, + * OPTION + */ + int i, j, return_value, empty, l; + char *ptr; + char token[MAX_LENGTH]; + + return_value = EMPTY; + while (return_value == EMPTY) { +/* + * Eliminate all characters after # sign as a comment + */ + i=-1; + empty=TRUE; +/* + * Get line, check for eof + */ + if (get_logical_line(pfn, cookie, &l) == EOF) { + next_keyword=0; + return (EOF); + } +/* + * Get long lines + */ + j = l; + ptr = strchr (line_save, '#'); + if (ptr != NULL) { + j = ptr - line_save; + } + strncpy(line, line_save, (unsigned) j); + line[j] = '\0'; + for (i = 0; i < j; i++) { + if (! isspace((int) line[i]) ) { + empty = FALSE; + break; + } + } +/* + * New line character encountered + */ + + if (empty == TRUE) { + return_value=EMPTY; + } else { + return_value=OK; + } + } +/* + * Determine return_value + */ + if (return_value == OK) { + if ( check_key(line) == TRUE) { + return_value=KEYWORD; + } else { + ptr = line; + copy_token(token, &ptr, &i); + if (token[0] == '-' && isalpha((int) token[1])) { + return_value = OPTION; + } + } + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads file fp until end of line, ";", or eof + * stores characters in line_save + * reallocs line_save and line if more space is needed + * + * returns: + * EOF on empty line on end of file or + * OK otherwise + * *l returns length of line + */ + int i, j; + int pos; + char c; + i = 0; + if (!pfn) return EOF; + while ((j = pfn(cookie)) != EOF) { + c = (char) j; + if (c == '#') { + /* ignore all chars after # until newline */ + do { + c = (char) j; + if (c == '\n') { + break; + } + add_char_to_line(&i, c); + } while ((j = pfn(cookie)) != EOF); + } + if (c == ';') break; + if (c == '\n') { + break; + } + if (c == '\\') { + pos = i; + add_char_to_line(&i, c); + while ((j = pfn(cookie)) != EOF) { + c = (char) j; + if (c == '\\') { + pos = i; + add_char_to_line(&i, c); + continue; + } + if (c == '\n') { + /* remove '\\' */ + for (; pos < i; pos++) { + line_save[pos] = line_save[pos+1]; + } + i--; + break; + } + add_char_to_line(&i, c); + if (!isspace(j)) break; + } + } else { + add_char_to_line(&i, c); + } + } + if (j == EOF && i == 0) { + *l = 0; + line_save[i] = '\0'; + return(EOF); + } + line_save[i] = '\0'; + *l = i; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_char_to_line(int *i, char c) +/* ---------------------------------------------------------------------- */ +{ + if ( *i + 20 >= max_line) { + max_line *= 2; + line_save = (char *) PHRQ_realloc(line_save, (size_t) max_line * sizeof(char)); + if (line_save == NULL) malloc_error(); + line = (char *) PHRQ_realloc(line, (size_t) max_line * sizeof(char)); + if (line == NULL) malloc_error(); + } + line_save[*i] = c; + *i += 1; + return(OK); +} diff --git a/input.h b/input.h new file mode 100644 index 00000000..ed35503f --- /dev/null +++ b/input.h @@ -0,0 +1,24 @@ +#ifndef _INC_INPUT_H +#define _INC_INPUT_H + +#ifdef PHREEQC_IDENT +static char const svnidinput[] = "$Id$"; +#endif +typedef int (*PFN_READ_CALLBACK)(void *cookie); + +struct read_callback { + PFN_READ_CALLBACK callback; + void *cookie; + int database; +}; + +int add_char_to_line(int *i, char c); +int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); +int get_line(PFN_READ_CALLBACK pfn, void *cookie); +int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); +int read_database(PFN_READ_CALLBACK pfn, void *cookie); +int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); +int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); + + +#endif /* _INC_INPUT_H */ diff --git a/integrate.cpp b/integrate.cpp new file mode 100644 index 00000000..86245c73 --- /dev/null +++ b/integrate.cpp @@ -0,0 +1,851 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: integrate.c 78 2005-02-01 22:47:12Z dlpark $"; + +#define MAX_QUAD 20 +#define K_POLY 5 +static LDBLE g_function(LDBLE x_value); +static LDBLE midpnt (LDBLE x1, LDBLE x2, int n); +static void polint(LDBLE *xa, LDBLE *ya, int n, LDBLE xv, LDBLE *yv, LDBLE *dy); +static LDBLE qromb_midpnt (LDBLE x1, LDBLE x2); +static LDBLE z, xd, alpha, G_TOL; +static struct surface_charge *surface_charge_ptr; + +/*static LDBLE calc_psi_avg(char *name);*/ +static LDBLE calc_psi_avg(LDBLE surf_chrg_eq); + +/* ---------------------------------------------------------------------- */ +int calc_all_g( void ) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int converge, converge1; + int count_g, count_charge; + LDBLE new_g, xd1; + LDBLE epsilon; + + if (svnid == NULL) fprintf(stderr," "); + if (use.surface_ptr == NULL) return(OK); +/* + * calculate g for each surface + */ +#ifdef SKIP + if (punch.high_precision == FALSE) { + epsilon = 1e-8; + G_TOL = 1e-9; + } else { + epsilon = 1.e-12; + G_TOL = 1e-10; + } +#endif + epsilon = convergence_tolerance; + if (convergence_tolerance >= 1e-8) { + G_TOL = 1e-9; + } else { + G_TOL = 1e-10; + } + + converge = TRUE; + count_charge = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + if (debug_diffuse_layer == TRUE) output_msg(OUTPUT_MESSAGE, "Calc_all_g, X[%d]\n", j); + surface_charge_ptr = x[j]->surface_charge; + count_g = 1; + x[j]->surface_charge->g[0].charge = 0.0; + x[j]->surface_charge->g[0].g = 0.0; + x[j]->surface_charge->g[0].dg = 0.0; + xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); + /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + /* 1000 J/kJ and 1000 L/m**3 */ + alpha = sqrt( EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); +/* + * calculate g for given surface for each species + */ + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type > HPLUS) continue; + for (k=0; k < count_g; k++) { + if (equal(x[j]->surface_charge->g[k].charge, s_x[i]->z, G_TOL) == TRUE) { + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + break; + } + } + if (k < count_g) continue; + + if (x[j]->surface_charge->grams > 0.0) { + z = s_x[i]->z; + if ((use.surface_ptr->only_counter_ions == FALSE) || + (((x[j]->master[0]->s->la > 0) && (z < 0)) || ((x[j]->master[0]->s->la < 0) && (z > 0)))) { + if (xd > 0.1) { + new_g = qromb_midpnt( 1.0, xd); + } else if (xd > 0.01) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, xd); + } else if (xd > 0.001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, xd); + } else if (xd > 0.0001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, xd); + } else if (xd > 0.00001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, .0001); + new_g += qromb_midpnt( 0.0001, xd); + } else if (xd > 0.000001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, .0001); + new_g += qromb_midpnt( 0.0001, .00001); + new_g += qromb_midpnt( 0.00001, xd); + } else if (xd > 0.0000001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, .0001); + new_g += qromb_midpnt( 0.0001, .00001); + new_g += qromb_midpnt( 0.00001, .000001); + new_g += qromb_midpnt( 0.000001, xd); + } else if (xd > 0.00000001) { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, .0001); + new_g += qromb_midpnt( 0.0001, .00001); + new_g += qromb_midpnt( 0.00001, .000001); + new_g += qromb_midpnt( 0.000001, .0000001); + new_g += qromb_midpnt( 0.0000001, xd); + } else { + new_g = qromb_midpnt( 1.0, 0.1); + new_g += qromb_midpnt( 0.1, 0.01); + new_g += qromb_midpnt( 0.01, .001); + new_g += qromb_midpnt( 0.001, .0001); + new_g += qromb_midpnt( 0.0001, .00001); + new_g += qromb_midpnt( 0.00001, .000001); + new_g += qromb_midpnt( 0.000001, .0000001); + new_g += qromb_midpnt( 0.0000001, .00000001); + new_g += qromb_midpnt( 0.00000001, xd); + } + } else { + new_g = 0; + } + } else { + new_g = 0.0; + } + if ((use.surface_ptr->only_counter_ions == TRUE) && new_g < 0) new_g = 0; + x[j]->surface_charge->g[count_g].charge = s_x[i]->z; + converge1 = TRUE; + if (fabs(new_g) >= 1.) { + if (fabs((new_g - x[j]->surface_charge->g[count_g].g)/new_g) > epsilon) { + converge1 = FALSE; + } + } else { + if (fabs(new_g - x[j]->surface_charge->g[count_g].g) > epsilon) { + converge1 = FALSE; + } + } + if (converge1 == FALSE) { + converge = FALSE; + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[count_g].charge, + (double) x[j]->surface_charge->g[count_g].g, + (double) new_g, + (double) (new_g - x[j]->surface_charge->g[count_g].g) ); + } + } + x[j]->surface_charge->g[count_g].g = new_g; + if (new_g == 0) { + x[j]->surface_charge->g[count_g].dg = 0; + } else { + if (x[j]->surface_charge->grams > 0.0) { + x[j]->surface_charge->g[count_g].dg = surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha * g_function(xd) / F_C_MOL; + x[j]->surface_charge->g[count_g].dg *= -2. / + (exp(x[j]->master[0]->s->la * LOG_10) * + exp(x[j]->master[0]->s->la * LOG_10)); + if ((xd - 1) < 0.0) { + x[j]->surface_charge->g[count_g].dg *= -1.0; + } + if (fabs(x[j]->surface_charge->g[count_g].dg) < 1e-8) { + xd1 = exp(-2 * 1e-3 * LOG_10); + + + new_g = qromb_midpnt( 1.0, xd1); + x[j]->surface_charge->g[count_g].dg = new_g/.001; + } + } else { + x[j]->surface_charge->g[count_g].dg = 0.0; + } + } + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = count_g; + count_g++; + + } + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nSurface component %d: charge,\tg,\tdg/dlny,\txd\n", count_charge); + for (i = 0; i < count_g; i++) { + output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg, + (double) xd); + } + } + count_charge++; + } + return (converge); +} +/* ---------------------------------------------------------------------- */ +LDBLE g_function(LDBLE x_value) +/* ---------------------------------------------------------------------- */ +{ + LDBLE sum, return_value, sum1; + int i, j; + LDBLE ln_x_value; + + if (equal(x_value, 1.0, G_TOL*100) == TRUE) return(0.0); + sum = 0.0; + ln_x_value = log(x_value); + for (j = 0; j < use.surface_ptr->charge[0].count_g; j++) { + use.surface_ptr->charge[0].g[j].psi_to_z = + exp(ln_x_value * use.surface_ptr->charge[0].g[j].charge) - 1.0; + } + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { + for(j = 0; j < use.surface_ptr->charge[0].count_g; j++) { + if(use.surface_ptr->charge[0].g[j].charge == s_x[i]->z) { + sum += s_x[i]->moles * use.surface_ptr->charge[0].g[j].psi_to_z; + break; + } + } + } + } + if (sum < 0.0) { + sum = 0.0; + sum1 = 0.0; + output_msg(OUTPUT_MESSAGE, "Species\tmoles\tX**z-1\tsum\tsum charge\n"); + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { + sum += s_x[i]->moles * (pow(x_value, s_x[i]->z) - 1.0); + sum1 += s_x[i]->moles * s_x[i]->z; + output_msg(OUTPUT_MESSAGE, "%s\t%e\t%e\t%e\t%e\n", s_x[i]->name, (double) s_x[i]->moles, (double) (pow(x_value, (double) s_x[i]->z) - 1.0), (double) sum, (double) sum1); + } + } + sprintf(error_string, "Negative sum in g_function, %e\t%e.", (double) sum, (double) x_value); + error_msg(error_string, CONTINUE); + sprintf(error_string, "Solutions must be charge balanced, charge imbalance is %e\n", (double) sum1); + error_msg(error_string, STOP); + } + + return_value = ( exp (ln_x_value * z) - 1) / sqrt((x_value * x_value * mass_water_aq_x * sum )); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +void polint(LDBLE *xa, LDBLE *ya, int n, LDBLE xv, LDBLE *yv, LDBLE *dy) +/* ---------------------------------------------------------------------- */ +{ + int i, m, ns; + LDBLE den, dif, dift, ho, hp, w; + LDBLE *c, *d; + + ns = 1; + dif = fabs(xv-xa[1]); +/* + * Malloc work space + */ + c = (double *) PHRQ_malloc((size_t) (n + 1) * sizeof (LDBLE) ); + if (c == NULL) malloc_error(); + d = (double *) PHRQ_malloc((size_t) (n + 1) * sizeof (LDBLE) ); + if (d == NULL) malloc_error(); + + + + for (i=1; i <= n; i++) { + dift = fabs(xv-xa[i]); + if ( dift < dif ) { + ns = i; + dif = dift; + } + c[i] = ya[i]; + d[i] = ya[i]; + } + + *yv = ya[ns--]; + for (m = 1; m < n; m++) { + for (i=1; i <= n - m; i++) { + ho = xa[i] - xv; + hp = xa[i+m] - xv; + w = c[i+1] - d[i]; + if ( (den=ho-hp) == 0.0) { + error_msg("In subroutine polint.", STOP); + } + den = w/den; + d[i] = hp*den; + c[i] = ho*den; + } + if (2 * ns < (n-m) ) { + *dy = c[ns+1]; + } else { + *dy = d[ns--]; + } + *yv += *dy; + +/* *yv += (*dy = (2 * ns < (n-m) ? c[ns+1] : d[ns--])); */ + } + c = (double *) free_check_null(c); + d = (double *) free_check_null(d); + return; +} +/* ---------------------------------------------------------------------- */ +LDBLE midpnt (LDBLE x1, LDBLE x2, int n) +/* ---------------------------------------------------------------------- */ +{ + LDBLE xv, tnm, sum, del, ddel; + static LDBLE sv; + int it, j; + + if (n == 1) { + sv = (x2-x1) * g_function(0.5 * (x1 + x2)); + return(sv); + } else { + for (it=1, j=1; jgrams * surface_charge_ptr->specific_area * + alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + if ((x2 - 1) < 0.0) sv[j] *= -1.0; + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "Iterations in qromb_midpnt: %d\n", j); + } + return(sv[j]); + } + + if (j >= K_POLY - 1) { + polint( &h[j - K_POLY], &sv[j - K_POLY], K_POLY, 0.0, &ss, &dss); + if (fabs(dss) <= G_TOL * fabs(ss) || fabs(dss) < G_TOL) { + ss *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * + alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + if ((x2 - 1) < 0.0) ss *= -1.0; + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "Iterations in qromb_midpnt: %d\n", j); + } + return(ss); + } + } + + } + sprintf(error_string, "\nToo many iterations integrating diffuse layer.\n"); + error_msg(error_string, STOP); + return(-999.9); +} +/* ---------------------------------------------------------------------- */ +int calc_init_g(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge; + + if (use.surface_ptr == NULL) return(OK); + +/* + * calculate g for each surface + */ + count_charge = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + surface_charge_ptr = x[j]->surface_charge; + count_g = 0; + if (x[j]->surface_charge->g != NULL) { + count_g = x[j]->surface_charge->count_g; + } + if( count_g == 0 ) { + x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_malloc((size_t) sizeof(struct surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) malloc_error(); + x[j]->surface_charge->g[0].charge = 0.0; + x[j]->surface_charge->g[0].g = 0.0; + x[j]->surface_charge->g[0].dg = 0.0; + xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); + /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + /* second 1000 is liters/m**3 */ + alpha = sqrt( EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); + } +/* + * calculate g for given surface for each species + */ + count_g = 1; + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type > HPLUS) continue; + for (k=0; k < count_g; k++) { + if (equal(x[j]->surface_charge->g[k].charge, s_x[i]->z, G_TOL) == TRUE) { + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + break; + } + } + if (k >= count_g) { + + /* malloc space to save g for charge */ + x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_realloc(x[j]->surface_charge->g, + (size_t) (count_g + 1) * + sizeof(struct surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) malloc_error(); + + /* save g for charge */ + x[j]->surface_charge->g[count_g].charge = s_x[i]->z; + if (x[j]->surface_charge->grams > 0.0) { + x[j]->surface_charge->g[count_g].g = 2 * alpha * sqrt(mu_x) * (pow(xd, s_x[i]->z / 2.0) - 1) *surface_charge_ptr->grams * surface_charge_ptr->specific_area / F_C_MOL; + x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; + if ((use.surface_ptr->only_counter_ions == TRUE) && + x[j]->surface_charge->g[count_g].g < 0) { + x[j]->surface_charge->g[count_g].g = 0; + x[j]->surface_charge->g[count_g].dg = 0; + } + } else { + x[j]->surface_charge->g[count_g].g = 0.0; + x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; + } + /* save g for species */ + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = count_g; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + count_g++; + } + } + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nSurface component %d: charge,\tg,\tdg\n", count_charge); + for (i = 0; i < count_g; i++) { + output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, (double) x[j]->surface_charge->g[i].g, (double) x[j]->surface_charge->g[i].dg ); + } + } + count_charge++; + x[j]->surface_charge->count_g = count_g; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int initial_surface_water(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * In initial surface calculation, need to calculate + * mass of water in diffuse layer. + * diffuse layer water + aqueous solution water = bulk water. + * Ionic strength is fixed, so diffuse-layer water will not change + */ + int i; +/*#define DEBYE*/ +#ifdef DEBYE + LDBLE debye_length; + LDBLE volume_diffuse_layer; +#endif + LDBLE mass_water_surface; +/* + * Debye length = 1/k = sqrt[eta*eta_zero*R*T/(2*F**2*mu_x*1000)], Dzombak and Morel, p 36 + * + * 1000 converts kJ to J; 1000 converts Liters to meter**3; debye_length is in meters. + */ +#ifdef DEBYE + debye_length = (EPSILON * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) + / (2. * F_C_MOL * F_C_MOL * mu_x * 1000.); + debye_length = sqrt(debye_length); +#endif +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + mass_water_surfaces_x = 0.0; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != SURFACE_CB) continue; +#ifdef DEBYE + /* 1000 converts volume from m**3 to Liters */ + volume_diffuse_layer = x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams * debye_length * 1000; + + /* Assume mol/L = mol/kgw */ + mass_water_surface = volume_diffuse_layer; +#else + /* make constant thickness of, default 1e-8 m (100 Angstroms) */ + mass_water_surface = x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams * use.surface_ptr->thickness * 1000; +#endif + x[i]->surface_charge->mass_water = mass_water_surface; + mass_water_surfaces_x += mass_water_surface; + } + mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) +/* ---------------------------------------------------------------------- */ +{ + int i, j, count_g; + LDBLE mass_water_surface; + LDBLE molality, moles_excess, moles_surface; + + if (use.surface_ptr == NULL) return(OK); +/* + * Find position of component in list of components + */ + i = 0; + + for (j =0; j < use.surface_ptr->count_charge; j++) { + if (&(use.surface_ptr->charge[j]) == surface_charge_ptr1) { + i = j; + break; + } + } + if (j >= use.surface_ptr->count_charge) { + sprintf(error_string, "In sum_diffuse_layer, component not found, %s.", surface_charge_ptr1->name); + error_msg(error_string, STOP); + } +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + count_elts = 0; + paren_count = 0; + mass_water_surface = surface_charge_ptr1->mass_water; + for (j = 0; j < count_s_x; j++) { + if (s_x[j]->type > HPLUS) continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; +#ifdef SKIP + moles_excess = mass_water_bulk_x * +/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ + surface_charge_ptr1->g[count_g].g * molality; +#endif + moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; + + moles_surface = mass_water_surface * molality + moles_excess; +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + add_elt_list(s_h2o->next_elt, mass_water_surface / gfw_water); + + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int calc_all_donnan(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge, converge; + char name[MAX_LENGTH]; + LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; + LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif; + + if (use.surface_ptr == NULL) return(OK); + f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); +/* + * calculate g for each surface... + */ + converge = TRUE; + count_charge = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + surface_charge_ptr = x[j]->surface_charge; + + if (debug_diffuse_layer == TRUE) output_msg(OUTPUT_MESSAGE, "Calc_all_g, X[%d]\n", j); +/* + * sum eq of each charge number in solution... + */ + count_g = x[j]->surface_charge->count_g; + for (i = 0; i < count_g; i++) { + charge_group[i].eq = 0.0; + } + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type > HPLUS) continue; + for (k = 0; k < count_g; k++) { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { + charge_group[k].eq += s_x[i]->z * s_x[i]->moles; + break; + } + } + } + /* find surface charge from potential... */ + A_surf = x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; + f_psi = x[j]->master[0]->s->la * LOG_10; + surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; + /* also for the derivative... */ + dif = 1e-5; + f_psi2 = f_psi + dif; + surf_chrg_eq2 = A_surf * f_sinh * sinh(f_psi2) / F_C_MOL; + + + /* find psi_avg that matches surface charge... */ + psi_avg = calc_psi_avg(surf_chrg_eq); + psi_avg2 = calc_psi_avg(surf_chrg_eq2); + + /* fill in g's */ + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + + for (k = 0; k < count_g; k++) { + x[j]->surface_charge->g[k].charge = charge_group[k].z; + + new_g = exp(-charge_group[k].z * psi_avg) - 1; + if (new_g <= - ratio_aq) new_g = G_TOL; + new_g2 = exp(-charge_group[k].z * psi_avg2) - 1; + if (new_g2 <= - ratio_aq) new_g2 = G_TOL; + + if (fabs(new_g) >= 1) { + if (fabs((new_g - x[j]->surface_charge->g[k].g) / new_g) > convergence_tolerance) { + converge = FALSE; + } + } else { + if (fabs(new_g - x[j]->surface_charge->g[k].g) > convergence_tolerance) { + converge = FALSE; + } + } + x[j]->surface_charge->g[k].g = new_g; + if (new_g != 0) { + x[j]->surface_charge->g[k].dg = (new_g2 - new_g) / dif; + } else { + x[j]->surface_charge->g[k].dg = -charge_group[k].z; + } + /* save g for species */ + for (i = 0; i < count_s_x; i++) { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + } + } + } + if (debug_diffuse_layer == TRUE) { + strcpy(name, x[j]->master[0]->elt->name); + replace ("_psi", "", name); +/* surf_chrg_eq = calc_surface_charge(name); + */ + output_msg(OUTPUT_MESSAGE, "\nDonnan all on %s (%d): charge, \tg, \tdg, Psi_surface = %8f V. \n", name, count_charge, + x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ); + for (i = 0; i < count_g; i++) { + output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg); + } + } + count_charge++; + } + return (converge); +} +/* ---------------------------------------------------------------------- */ +int calc_init_donnan(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge; + char name[MAX_LENGTH]; + LDBLE f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; + + if (use.surface_ptr == NULL) return(OK); + f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); +/* + * sum eq of each charge number in solution... + */ + charge_group = (struct charge_group *) free_check_null(charge_group); + charge_group = (struct charge_group *) PHRQ_malloc((size_t) sizeof(struct charge_group)); + if (charge_group == NULL) malloc_error(); + charge_group[0].z = 0.0; + charge_group[0].eq = 0.0; + + count_g = 1; + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->type > HPLUS) continue; + for (k = 0; k < count_g; k++) { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { + charge_group[k].eq += s_x[i]->z * s_x[i]->moles; + break; + } + } + if (k >= count_g) { + charge_group = (struct charge_group *) PHRQ_realloc(charge_group, (size_t) (count_g + 1) * + sizeof(struct charge_group)); + if (charge_group == NULL) malloc_error(); + charge_group[count_g].z = s_x[i]->z; + charge_group[count_g].eq = s_x[i]->z * s_x[i]->moles; + + count_g++; + } + } +/* + * calculate g for each surface... + */ + count_charge = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + surface_charge_ptr = x[j]->surface_charge; + + x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_malloc((size_t) count_g * sizeof(struct surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) malloc_error(); + x[j]->surface_charge->count_g = count_g; + + /* find surface charge from potential... */ + A_surf = x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; + f_psi = x[j]->master[0]->s->la * LOG_10; + surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; + + /* find psi_avg that matches surface charge... */ + psi_avg = calc_psi_avg(surf_chrg_eq); + + /* fill in g's */ + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + + for (k = 0; k < count_g; k++) { + x[j]->surface_charge->g[k].charge = charge_group[k].z; + x[j]->surface_charge->g[k].g = exp(-charge_group[k].z * psi_avg) - 1; + if (x[j]->surface_charge->g[k].g != 0) { + x[j]->surface_charge->g[k].dg = - A_surf * f_sinh * cosh(f_psi) / + (charge_group[k].eq * F_C_MOL); + } else { + x[j]->surface_charge->g[k].dg = -charge_group[k].z; + } + /* save g for species */ + for (i = 0; i < count_s_x; i++) { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + } + } + } + if (debug_diffuse_layer == TRUE) { + strcpy(name, x[j]->master[0]->elt->name); + replace ("_psi", "", name); +/* surf_chrg_eq = calc_surface_charge(name); + */ + output_msg(OUTPUT_MESSAGE, "\nDonnan init on %s : charge, \tg, \tdg, Psi_surface = %8f V. \n", name, + x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ); + for (i = 0; i < count_g; i++) { + output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, (double) x[j]->surface_charge->g[i].g, (double) x[j]->surface_charge->g[i].dg ); + } + } + count_charge++; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_psi_avg(LDBLE surf_chrg_eq) +/* ---------------------------------------------------------------------- */ +{ +/* + * calculate the average (F * Psi / RT) that lets the DL charge counter the surface charge + */ + int i, iter, count_g; + LDBLE fd, fd1, p, temp, ratio_aq; +/* LDBLE dif; + */ + count_g = surface_charge_ptr->count_g; + if (convergence_tolerance >= 1e-8) { + G_TOL = 1e-9; + } else { + G_TOL = 1e-10; + } + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + p = 0; + if (surf_chrg_eq == 0) { + return(0.0); + } else if (surf_chrg_eq < 0) { + p = -0.5 * log(-surf_chrg_eq * ratio_aq / mu_x + 1); + } else if (surf_chrg_eq > 0) { + p = 0.5 * log(surf_chrg_eq * ratio_aq / mu_x + 1); + } +/* + * Optimize p in SS{s_x[i]->moles * z_i * g(p)} = -surf_chrg_eq + * g(p) = exp(-p * z_i) - 1 + */ + iter = 0; + do { + fd = surf_chrg_eq; + fd1 = 0.0; + for (i = 1; i < count_g; i++) { + temp = exp(-charge_group[i].z * p); + if (temp > 1 - ratio_aq) { + fd += charge_group[i].eq * (temp - 1); + fd1 -= charge_group[i].z * charge_group[i].eq * temp; + } + } +/* fd1 = surf_chrg_eq * ratio_aq; + dif = 1e-5; + p += dif; + for (i = 1; i < count_g; i++) { + temp = exp(-charge_group[i].z * p); + fd1 += charge_group[i].eq * temp; + } + fd /= -(fd1 - fd) / dif; + p -= dif; + p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); + */ + fd /= -fd1; + p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); + if (fabs(p) < G_TOL) p = 0.0; + iter++; + if (iter > 50) { + sprintf(error_string, "\nToo many iterations for surface in subroutine calc_psi_avg.\n"); + error_msg(error_string, STOP); + } + } while (fabs(fd) > G_TOL && p != 0.0); + if (debug_diffuse_layer == TRUE) + output_msg(OUTPUT_MESSAGE, "iter in calc_psi_avg = %d. g(+1) = %8f. surface charge = %8f.\n", + iter, (double) (exp(-p) - 1), (double) surf_chrg_eq); + + return(p); +} diff --git a/inverse.cpp b/inverse.cpp new file mode 100644 index 00000000..a1227358 --- /dev/null +++ b/inverse.cpp @@ -0,0 +1,3014 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: inverse.c 588 2005-10-11 20:29:31Z dlpark $"; + +#define MAX_MODELS 20 +#define MIN_TOTAL_INVERSE 1e-14 + +#ifdef INVERSE_CL1MP +/* cl1mp.c */ +extern int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error, + LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg); +#endif + +/* variables local to module */ + +int max_row_count, max_column_count; +static int carbon; +char **col_name, **row_name; +static int count_rows, count_optimize; +static int col_phases, col_redox, col_epsilon, col_ph, col_water, col_isotopes, col_phase_isotopes; +static int row_mb, row_fract, row_charge, row_carbon, row_isotopes, row_epsilon, row_isotope_epsilon, row_water; +static LDBLE *zero, *array1, *res, *delta1, *delta2, *delta3, *cu, *delta_save; +static LDBLE *min_delta, *max_delta; +static int *iu, *is; +static int klmd, nklmd, n2d, kode, iter; +static LDBLE toler, error, max_pct, scaled_error; +static struct master *master_alk; +int *row_back, *col_back; + +static unsigned long *good, *bad, *minimal; +static int max_good, max_bad, max_minimal; +static int count_good, count_bad, count_minimal, count_calls; +static unsigned long soln_bits, phase_bits, current_bits, temp_bits; + +/* subroutines */ + +static int bit_print(unsigned long bits, int l); +static int carbon_derivs(struct inverse *inv_ptr); +static int check_isotopes(struct inverse *inv_ptr); +static int check_solns(struct inverse *inv_ptr); +static int count_isotope_unknowns(struct inverse *inv_ptr, struct isotope **isotope_unknowns); +static int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); +static int post_mortem(void); +static unsigned long get_bits(unsigned long bits, int position, int number); +static unsigned long minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits); +static int next_set_phases(struct inverse *inv_ptr, + int first_of_model_size, + int model_size); +static int phase_isotope_inequalities(struct inverse *inv_ptr); +static int print_model(struct inverse *inv_ptr); +static int punch_model_heading(struct inverse *inv_ptr); +static int punch_model(struct inverse *inv_ptr); +static int range(struct inverse *inv_ptr, unsigned long cur_bits); +static int save_bad(unsigned long bits); +static int save_good(unsigned long bits); +static int save_minimal(unsigned long bits); +static unsigned long set_bit(unsigned long bits, int position, int value); +static int setup_inverse(struct inverse *inv_ptr); +static int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *soln_ptr_orig, + int n_user_new, + LDBLE d_alk, + LDBLE ph_factor, + LDBLE alk_factor); +static int shrink(struct inverse *inv_ptr, LDBLE *array_in, LDBLE *array_out, + int *k, int *l, int *m, int *n, + unsigned long cur_bits, + LDBLE *delta_l, int *col_back_l, int *row_back_l); +static int solve_inverse(struct inverse *inv_ptr); +static int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); +static int subset_bad(unsigned long bits); +static int subset_minimal(unsigned long bits); +static int superset_minimal(unsigned long bits); +static int write_optimize_names(struct inverse *inv_ptr); + +#ifdef SKIP +#define SCALE_EPSILON .0009765625 +#define SCALE_WATER .0009765625 +#define SCALE_ALL 16 +#endif +#define SCALE_EPSILON .0009765625 +#define SCALE_WATER 1. +#define SCALE_ALL 1. + +/* ---------------------------------------------------------------------- */ +int inverse_models(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of inverse models, make calculations + * for any marked "new". + */ + int n, print1; + + if (svnid == NULL) fprintf(stderr," "); + array1 = NULL; + zero = NULL; + res = NULL; + delta1 = NULL; + delta2 = NULL; + delta3 = NULL; + delta_save = NULL; + cu = NULL; + iu = NULL; + is = NULL; + col_name = NULL; + row_name = NULL; + min_delta = NULL; + max_delta = NULL; + good = NULL; + bad = NULL; + minimal = NULL; + + print1 = TRUE; + state = INVERSE; + diffuse_layer_x = FALSE; + for (n=0; n < count_inverse; n++) { + if (inverse[n].new_def == TRUE) { +/* + * Fill in stucture "use". + */ + use.inverse_in = TRUE; + use.inverse_ptr = &inverse[n]; + use.n_inverse_user = inverse[n].n_user; +/* + * Initial prints + */ + sprintf(error_string,"Beginning of inverse modeling %d calculations.", inverse[n].n_user); + dup_print(error_string, TRUE); + + if (inverse[n].mp == TRUE) { + output_msg(OUTPUT_MESSAGE, "Using Cl1MP multiprecision optimization routine.\n"); + + } else { + output_msg(OUTPUT_MESSAGE, "Using Cl1 standard precision optimization routine.\n"); + } + status(0, NULL); + +/* + * Setup and solve + */ + count_calls = 0; + setup_inverse(&(inverse[n])); + punch_model_heading(&inverse[n]); + solve_inverse(&(inverse[n])); + if (inverse[n].count_isotope_unknowns > 0 ) { + inverse[n].isotope_unknowns = (struct isotope *) free_check_null(inverse[n].isotope_unknowns); + } + inverse[n].new_def = FALSE; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_inverse(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in array for an inverse problem + */ + int i, j, k, i_alk, i_carb; + int max; + int count_rows_t; + int column, row; + int temp, temppun; + LDBLE isotope_number; + LDBLE f, coef, cb, conc; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + struct solution *solution_ptr; + struct reaction *rxn_ptr; + struct master *master_ptr; +/* + * Determine array sizes, row and column positions + */ + toler = inv_ptr->tolerance; + if (inv_ptr->mp == TRUE) { + toler = inv_ptr->mp_tolerance; + } +/* + * Alkalinity derivatives with pH and carbon + */ + carbon = 1; + temp = pr.status; + pr.status = FALSE; + temppun = punch.in; + punch.in = FALSE; + carbon_derivs(inv_ptr); + pr.status = temp; + punch.in = temppun; + state = INVERSE; +/* + * tidy isotopes if necessary + */ + inv_ptr->count_isotope_unknowns = 0; + if (inv_ptr->count_isotopes > 0) { + inv_ptr->count_isotope_unknowns = count_isotope_unknowns(inv_ptr, &inv_ptr->isotope_unknowns); + if (input_error > 0) { + error_msg("Stopping because of input errors.", STOP); + } + check_isotopes(inv_ptr); + if (input_error > 0) { + error_msg("Stopping because of input errors.", STOP); + } + } + +/* + * count unknowns + */ + max_column_count = inv_ptr->count_elts * inv_ptr->count_solns + /* epsilons */ + inv_ptr->count_solns + /* solutions */ + inv_ptr->count_phases + /* phases */ + inv_ptr->count_redox_rxns + /* redox reactions */ + carbon * inv_ptr->count_solns + /* pH */ + 1 + /* water */ + inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* isotopes in solution*/ + inv_ptr->count_isotopes * inv_ptr->count_phases + /* isotopes in phases */ + 1 + 1; /* rhs, ineq */ + count_unknowns = max_column_count - 2; + col_phases = inv_ptr->count_solns; + col_redox = col_phases + inv_ptr->count_phases; + col_epsilon = col_redox + inv_ptr->count_redox_rxns; + col_ph = col_epsilon + inv_ptr->count_elts * inv_ptr->count_solns; + col_water = col_ph + carbon * inv_ptr->count_solns; + col_isotopes = col_water + 1; + col_phase_isotopes = col_isotopes + inv_ptr->count_isotope_unknowns * inv_ptr->count_solns; + max_row_count = + inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ + carbon * inv_ptr->count_solns + /* optimize ph */ + 1 + /* optimize water */ + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ + inv_ptr->count_isotopes * inv_ptr->count_phases + /* optimize phase isotopes */ + inv_ptr->count_elts + /* mass balances */ + 1 + 1 + /* fractions, init and final */ + inv_ptr->count_solns + /* charge balances */ + carbon * inv_ptr->count_solns + /* dAlk = dC + dph */ + inv_ptr->count_isotopes + /* isotopes */ + 2 * inv_ptr->count_solns * inv_ptr->count_elts + /* epsilon constraints */ + 2 * carbon * inv_ptr->count_solns + /* epsilon on ph */ + 2 + /* epsilon for water */ + 2 * inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* epsilon for isotopes */ + 2 * inv_ptr->count_isotopes * inv_ptr->count_phases + /* epsilon for isotopes in phases */ + 2; /* work space */ + + row_mb =inv_ptr->count_solns * inv_ptr->count_elts + + carbon * inv_ptr->count_solns + 1 + + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + + inv_ptr->count_isotopes * inv_ptr->count_phases; + row_fract = row_mb + inv_ptr->count_elts; + row_charge = row_fract + 2; + row_carbon = row_charge + inv_ptr->count_solns; + row_isotopes = row_carbon + carbon * inv_ptr->count_solns; + row_epsilon = row_isotopes + inv_ptr->count_isotopes; +/* The next three are not right, some rows of epsilon are deleted */ +/* + row_ph_epsilon = row_epsilon + 2 * inv_ptr->count_solns * inv_ptr->count_elts; + row_water_epsilon = row_ph + 2 * carbon * inv_ptr->count_solns; + row_isotope_epsilon + row_isotope_phase_epsilon + */ +/* + * Malloc space for arrays + */ + array = (LDBLE *) free_check_null(array); + array = (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * sizeof(LDBLE)); + if (array == NULL) malloc_error(); + + array1 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * sizeof(LDBLE)); + if (array1 == NULL) malloc_error(); + + col_name = (char **) PHRQ_malloc((size_t) max_column_count * sizeof(char *)); + if (col_name == NULL) malloc_error(); + + row_name = (char **) PHRQ_malloc((size_t) max_row_count * sizeof(char *)); + if (row_name == NULL) malloc_error(); + + delta = (LDBLE *) free_check_null (delta); + delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (delta == NULL) malloc_error(); + + delta1 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (delta1 == NULL) malloc_error(); + + delta2 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (delta2 == NULL) malloc_error(); + + delta3 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (delta3 == NULL) malloc_error(); + + delta_save = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (delta_save == NULL) malloc_error(); + + min_delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (min_delta == NULL) malloc_error(); + + max_delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (max_delta == NULL) malloc_error(); + + res = (LDBLE *) PHRQ_malloc((size_t) max_row_count*sizeof(LDBLE)); + if (res == NULL) malloc_error(); + + if (max_column_count < max_row_count) { + max = max_row_count; + } else { + max = max_column_count; + } + zero = (LDBLE *) PHRQ_malloc((size_t) max * sizeof(LDBLE)); + if (zero == NULL) malloc_error(); +/* + * Define zero and zero array, delta + */ + for (i = 0; i < max; i++) zero[i] = 0.0; + + memcpy((void *) &(delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + for (i = 0; i < max_row_count; i++) { + memcpy((void *) &(array[i*max_column_count]), (void *) &(zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * begin filling array + */ + count_rows = 0; +/* + * optimization + */ + count_optimize = inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ + carbon * inv_ptr->count_solns + /* optimize ph */ + 1 + /* optimize water */ + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ + inv_ptr->count_isotopes * inv_ptr->count_phases; /* optimize phase isotopes */ + + for (i = 0; i < count_optimize; i++) { + row_name[count_rows] = string_hsave("optimize"); + count_rows++; + } + write_optimize_names(inv_ptr); +/* + * equalities + */ + +/* + * Mass_balance: solution data + */ + + /* initialize master species */ + for (i = 0; i < count_master; i++) { + master[i]->in = -1; + if (strstr(master[i]->elt->name, "Alk") == master[i]->elt->name) { + master_alk = master[i]; + } + } + /* mark master species included in model, write row names*/ + count_rows_t = count_rows; + i_alk = -1; + i_carb = -1; + for (i = 0; i < inv_ptr->count_elts; i++) { + master_ptr = inv_ptr->elts[i].master; + if (master_ptr == master_alk) i_alk = i; + if (strcmp(master_ptr->elt->name,"C(4)") == 0) i_carb = i; + inv_ptr->elts[i].master->in = count_rows_t; + row_name[count_rows_t] = inv_ptr->elts[i].master->elt->name; + count_rows_t++; + } + /* put concentrations in array */ + for (i=0; i < inv_ptr->count_solns; i++) { + xsolution_zero(); + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + if (solution_ptr == NULL) { + sprintf(error_string, "Solution number %d not found.", + inv_ptr->solns[i]); + error_msg(error_string, STOP); + } + /* write master species concentrations */ + for (j=0; solution_ptr->totals[j].description != NULL; j++) { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + master_ptr->total += solution_ptr->totals[j].moles; + /* List elements not included in model */ + if (master_ptr->in < 0) { + sprintf(error_string, "%s is included in solution %d, but is not included as a mass-balance constraint.", + solution_ptr->totals[j].description, + inv_ptr->solns[i]); + warning_msg(error_string); + } + } + master_alk->total = solution_ptr->total_alkalinity; + f = 1.0; + if (i == (inv_ptr->count_solns - 1)) { + f = -1.0; + } + column = i; + sprintf(token, "soln %d", i); + col_name[column] = string_hsave(token); + for(j=0; j < count_master; j++) { + if (master[j]->in >= 0) { + array[master[j]->in * max_column_count + i] = f * master[j]->total; + if (master[j]->s == s_eminus) { + array[master[j]->in * max_column_count + i] = 0.0; + } + } + } + /* calculate charge balance for elements in model */ + cb = 0; + for(j=0; j < count_master; j++) { + if (master[j]->in >= 0) { + if (master[j]->s == s_eminus) { + coef = 0.0; + } else if (master[j] == master_alk) { + coef = -1.0; + } else { + coef = master[j]->s->z + master[j]->s->alk; + } + cb += coef * master[j]->total; + } + } + if (fabs(cb) < toler) cb = 0.0; + array[(row_charge + i) * max_column_count + i] = cb; + } + +/* mass_balance: phase data */ + + for (i = 0; i < inv_ptr->count_phases; i++) { + phase_ptr = inv_ptr->phases[i].phase; + rxn_ptr = phase_ptr->rxn_s; + column = col_phases + i; + col_name[column] = phase_ptr->name; + for (j = 1; rxn_ptr->token[j].s != NULL; j++) { + if (rxn_ptr->token[j].s->secondary != NULL) { + master_ptr = rxn_ptr->token[j].s->secondary; + } else { + master_ptr = rxn_ptr->token[j].s->primary; + } + if (master_ptr == NULL) { + sprintf(error_string, "Setup_inverse, reaction for phase, %s.", phase_ptr->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) continue; + if (master_ptr->s == s_h2o) { + row = row_fract; +/* turn off h2o from minerals in water mass balance */ + if (inv_ptr->mineral_water != TRUE) continue; + + } else { + row = master_ptr->in; + } + /* e- has coef of 0 for some reason */ + coef = master_ptr->coef; + if (coef <= 0) coef = 1.0; + array[row*max_column_count + column] = rxn_ptr->token[j].coef * coef; + } + row = master_alk->in; /* include alkalinity for phase */ + array[row * max_column_count + column] = calc_alk(rxn_ptr); + } + +/* mass balance: redox reaction data */ + + k = 0; + for (i = 0; i < inv_ptr->count_elts; i++) { + if (inv_ptr->elts[i].master->s->primary == NULL) { + coef = inv_ptr->elts[i].master->coef ; + rxn_ptr = inv_ptr->elts[i].master->rxn_primary; + column = col_redox + k; + col_name[column] = inv_ptr->elts[i].master->elt->name; + k++; + for (j = 0; rxn_ptr->token[j].s != NULL; j++) { + if (rxn_ptr->token[j].s->secondary != NULL) { + master_ptr = rxn_ptr->token[j].s->secondary; + } else { + master_ptr = rxn_ptr->token[j].s->primary; + } + if (master_ptr == NULL) { + sprintf(error_string, "Subroutine setup_inverse, element not found, %s.", rxn_ptr->token[j].s->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) continue; + if (master_ptr->s == s_h2o) { + row = row_fract; +/* turn off h2o from minerals in water mass balance */ + if (inv_ptr->mineral_water != TRUE) continue; + } else { + row = master_ptr->in; + } + array[row*max_column_count + column] = rxn_ptr->token[j].coef; + /* if coefficient of element is not 1.0 in master species */ + if (j != 0) array[row*max_column_count + column] /= coef; + } + row = master_alk->in; /* include alkalinity for redox reaction */ + array[row * max_column_count + column] = ( calc_alk(rxn_ptr) - inv_ptr->elts[i].master->s->alk ) / coef; + } + } + +/* mass-balance: epsilons */ + + column = col_epsilon; + for (i = 0; i < inv_ptr->count_elts; i++) { + row = inv_ptr->elts[i].master->in; + for (j = 0; j < inv_ptr->count_solns; j++) { + if (j < (inv_ptr->count_solns - 1)) { + array[row * max_column_count + column] = 1.0; + } else { + array[row * max_column_count + column] = -1.0; + } + if (inv_ptr->elts[i].master->s == s_eminus) { + array[row * max_column_count + column] = 0.0; + } + sprintf(token, "%s %d", row_name[row], j); + col_name[column] = string_hsave(token); + column++; + } + } + count_rows += inv_ptr->count_elts; + +/* put names in col_name for ph */ + + for (i = 0; i < inv_ptr->count_solns; i++) { + sprintf(token, "ph %d", i); + col_name[column] = string_hsave(token); + column++; + } +/* put names in col_name for water */ + + sprintf(token, "water"); + col_name[column] = string_hsave(token); + column++; + +/* put names of isotopes in col_name */ + for (i = 0; i < inv_ptr->count_solns; i++) { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { + sprintf(token, "%d%s %d", + (int) inv_ptr->isotope_unknowns[j].isotope_number, + inv_ptr->isotope_unknowns[j].elt_name, i); + col_name[column] = string_hsave(token); + column++; + } + } + +/* put phase isotopes in col_name */ + + if (inv_ptr->count_isotopes > 0) { + /* isotopes of phases phases */ + for (i = 0; i < inv_ptr->count_phases; i++) { + for (j = 0; j < inv_ptr->count_isotopes; j++) { + sprintf(token, "%d%s %s", + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name, + inv_ptr->phases[i].phase->name); + col_name[column] = string_hsave(token); + column++; + } + } + } +/* + * Initial solution mixing fractions or water mass balance + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + if (i < inv_ptr->count_solns - 1) { + array[count_rows * max_column_count + i] = 1.0 / gfw_water * solution_ptr->mass_water; + } else { + array[count_rows * max_column_count + inv_ptr->count_solns - 1] = - 1.0 / gfw_water * solution_ptr->mass_water; + } + } + /* coefficient for water uncertainty */ + if (inv_ptr->water_uncertainty > 0 ) { + array[count_rows * max_column_count + col_water] = 1.0; + } + row_name[count_rows] = string_hsave("H2O"); + row_water = count_rows; + count_rows++; + +/* + * Final solution fraction equals 1.0 + */ + + array[count_rows * max_column_count + inv_ptr->count_solns - 1] = 1.0 ; + array[count_rows * max_column_count + count_unknowns] = 1.0; + row_name[count_rows] = string_hsave("fract, final"); + count_rows++; + +/* + * Charge balance: + */ + + for (i = 0; i < inv_ptr->count_solns; i++) { +/* solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); */ +/* array[count_rows * max_column_count + i] = solution_ptr->cb; */ + for (j = 0; j < inv_ptr->count_elts; j++) { + column = col_epsilon + j * inv_ptr->count_solns + i; + coef = inv_ptr->elts[j].master->s->z + inv_ptr->elts[j].master->s->alk; + if (inv_ptr->elts[j].master == master_alk) { + coef = -1.0; + } + array[count_rows * max_column_count + column] = coef; + if (inv_ptr->elts[j].master->s == s_eminus) { + array[count_rows * max_column_count + column] = 0.0; + } + } + sprintf(token, "%s %d", "charge", i); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * dC = (dC/dph)*dph + (dC/dAlk)*dAlk for each solution + */ +/* + * dAlk = (dAlk/dC)*dC + (dAlk/dpH)*dpH for each solution + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + if (inv_ptr->dalk_dph[i] != 0 || inv_ptr->dalk_dc[i] != 0) { + column = col_ph + i; + array[count_rows * max_column_count + column] = inv_ptr->dalk_dph[i]; + column = col_epsilon + i_alk * inv_ptr->count_solns + i; + array[count_rows * max_column_count + column] = -1.0; + column = col_epsilon + i_carb * inv_ptr->count_solns + i; + array[count_rows * max_column_count + column] = inv_ptr->dalk_dc[i]; + } + sprintf(token, "%s %d", "dAlk", i); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * Isotope mass balances + */ + if (input_error > 0) { + error_msg("Stopping because of input errors.", STOP); + } + if (inv_ptr->count_isotopes != 0) { + for (j = 0; j < inv_ptr->count_isotopes; j++) { + isotope_balance_equation(inv_ptr, count_rows, j); + sprintf(token,"%d%s", (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities + */ + row_epsilon = count_rows; + for (i = 0; i < inv_ptr->count_solns; i++) { + for (j = 0; j < inv_ptr->count_elts; j++) { + if (inv_ptr->elts[j].master->s == s_eminus) continue; + column = col_epsilon + j*inv_ptr->count_solns + i; + +/* calculate magnitude of bound */ + + coef = inv_ptr->elts[j].uncertainties[i]; + if (coef <= 0.0) { + coef = -coef; + } else { + coef = array[inv_ptr->elts[j].master->in * max_column_count + i] * coef; + coef = fabs(coef); + } + + if (coef < toler) coef = 0; + +/* zero column if uncertainty is zero */ + if (coef == 0.0) { + for(k = 0; k < count_rows; k++) { + array[k * max_column_count + column] = 0.0; + } + continue; + } + +/* this statement probably obviates some of the following logic. */ +/* coef += toler; */ + +/* scale epsilon optimization equation */ + + if (coef < toler) { + array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/toler; + } else { + array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; + } + +/* set upper limit of change in positive direction */ + if (coef < toler) { + coef = toler; + f = 10; + } else { + f = 1.0; + } + array[count_rows * max_column_count + column] = 1.0 * f; + array[count_rows * max_column_count + i] = -coef * f; + sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + conc = array[inv_ptr->elts[j].master->in * max_column_count + i]; + + /* if concentration is zero, only positive direction allowed */ + if (conc == 0.0) { + delta[column] = 1.0; + continue; + } + /* if uncertainty is less than tolerance, set uncertainty to toler */ + if (coef <= toler) { +/* f = 10 * toler / coef; */ + coef = toler; + f = 10; + } else { + f = 1.0; + } + /* if uncertainty is greater than concentration, + maximum negative is equal to concentrations, + except alkalinity */ + if (coef > fabs(conc) && + (strstr(inv_ptr->elts[j].master->elt->name,"Alkalinity") != inv_ptr->elts[j].master->elt->name)) coef = fabs(conc) + toler; + + array[count_rows * max_column_count + i] = -coef * f ; + array[count_rows * max_column_count + column] = -1.0 * f; + sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities for pH + */ + /* row_ph_epsilon = count_rows; */ + if (inv_ptr->carbon == TRUE) { + for (i = 0; i < inv_ptr->count_solns; i++) { + column = col_ph + i; + coef = inv_ptr->ph_uncertainties[i]; + +/* scale epsilon in optimization equation */ + + array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; + +/* set upper limit of change in positive direction */ + + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%s %s", "pH", "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%s %s", "pH", "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities for water + */ + column = col_water; + coef = inv_ptr->water_uncertainty; + /* row_water_epsilon = count_rows; */ + if (coef > 0.0) { +/* set upper limit of change in positive direction */ + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + count_unknowns] = coef; + sprintf(token, "%s %s", "water", "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + count_unknowns] = coef; + sprintf(token, "%s %s", "water", "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * inequalities for isotopes + */ + row_isotope_epsilon = count_rows; + if (inv_ptr->count_isotopes > 0) { + for (i = 0; i < inv_ptr->count_solns; i++) { + solution_ptr = solution_bsearch(inv_ptr->solns[i], &k, TRUE); + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { + column = col_isotopes + (i * inv_ptr->count_isotope_unknowns) + j; + master_ptr = inv_ptr->isotope_unknowns[j].master; + isotope_number = inv_ptr->isotope_unknowns[j].isotope_number; + for (k = 0; k < solution_ptr->count_isotopes; k++) { + if (solution_ptr->isotopes[k].master == master_ptr && + solution_ptr->isotopes[k].isotope_number == isotope_number) { + coef = solution_ptr->isotopes[k].x_ratio_uncertainty; + +/* scale epsilon in optimization equation */ + + array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; + +/* set upper limit of change in positive direction */ + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%d%s %s", + (int) solution_ptr->isotopes[k].isotope_number, + solution_ptr->isotopes[k].elt_name, + "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%d%s %s", + (int) solution_ptr->isotopes[k].isotope_number, + solution_ptr->isotopes[k].elt_name, + "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + break; + } + } + } + } + } +/* + * inequalities for isotopes in phases + */ + /* row_isotope_phase_epsilon = count_rows; */ + phase_isotope_inequalities(inv_ptr); + if (input_error > 0) { + error_msg("Stopping because of input errors.", STOP); + } +/* + * Set non-negativity constraints + */ + + for (i = 0; i < inv_ptr->count_phases; i++) { + if (inv_ptr->phases[i].constraint == PRECIPITATE) { + delta[col_phases + i] = -1.0; + } else if (inv_ptr->phases[i].constraint == DISSOLVE) { + delta[col_phases + i] = 1.0; + } + } + for (i = 0; i < (inv_ptr->count_solns - 1); i++) { + delta[i] = 1.0; + } +/* + * Scale water equation + */ + for (i = 0; i < max_column_count; i++) { + array[row_water * max_column_count + i] *= SCALE_WATER; + } +/* + * Arrays are complete + */ + if (debug_inverse == TRUE ) { + for (i = 0; i < count_unknowns; i++) { + output_msg(OUTPUT_MESSAGE, "%d\t%s\n", i, col_name[i]); + } + for (i = 0; i < count_rows; i++) { + k = 0; + output_msg(OUTPUT_MESSAGE,"%d\t%s\n", i, row_name[i]); + for (j=0; j < count_unknowns + 1; j++) { + if (k > 7) { + output_msg(OUTPUT_MESSAGE,"\n"); + k = 0; + } + output_msg(OUTPUT_MESSAGE,"%11.2e", (double) array[i*max_column_count + j]); + k++; + } + if (k != 0) { + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE, "row_mb %d\n", row_mb); + output_msg(OUTPUT_MESSAGE, "row_fract %d\n", row_fract); + output_msg(OUTPUT_MESSAGE, "row_charge %d\n", row_charge); + output_msg(OUTPUT_MESSAGE, "row_carbon %d\n", row_carbon); + output_msg(OUTPUT_MESSAGE, "row_isotopes %d\n", row_isotopes); + output_msg(OUTPUT_MESSAGE, "row_epsilon %d\n", row_epsilon); + + output_msg(OUTPUT_MESSAGE, "col_phases %d\n", col_phases); + output_msg(OUTPUT_MESSAGE, "col_redox %d\n", col_redox); + output_msg(OUTPUT_MESSAGE, "col_epsilon %d\n", col_epsilon); + output_msg(OUTPUT_MESSAGE, "col_ph %d\n", col_ph); + output_msg(OUTPUT_MESSAGE, "col_water %d\n", col_water); + output_msg(OUTPUT_MESSAGE, "col_isotopes %d\n", col_isotopes); + output_msg(OUTPUT_MESSAGE, "col_phase_isotopes %d\n", col_phase_isotopes); + output_msg(OUTPUT_MESSAGE, "count_unknowns %d\n", count_unknowns); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solve_inverse(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Exhaustively search for mass-balance models with two options + * -minimal on or off + * -range on or off + * + */ + int i, j, n; + int quit, print, first; + int first_of_model_size, model_size; + unsigned long minimal_bits, good_bits; + char token[MAX_LENGTH]; + + n = count_unknowns; /* columns in A, C, E */ + klmd = max_row_count - 2; + nklmd = n + klmd; + n2d = n + 2; + + max_good = MAX_MODELS; + max_bad = MAX_MODELS; + max_minimal = MAX_MODELS; + + good = (unsigned long *) PHRQ_malloc( (size_t) max_good * sizeof(unsigned long)); + if (good == NULL) malloc_error(); + count_good = 0; + + bad = (unsigned long *) PHRQ_malloc( (size_t) max_bad * sizeof(unsigned long)); + if (bad == NULL) malloc_error(); + count_bad = 0; + + minimal = (unsigned long *) PHRQ_malloc( (size_t) max_minimal * sizeof(unsigned long)); + if (minimal == NULL) malloc_error(); + count_minimal = 0; + + col_back = (int *) PHRQ_malloc((size_t) max_column_count * sizeof(int)); + if (col_back == NULL) malloc_error(); + + row_back = (int *) PHRQ_malloc((size_t) max_row_count * sizeof(int)); + if (row_back == NULL) malloc_error(); + +/* + * Allocate space for arrays + */ + cu = (LDBLE *) PHRQ_malloc((size_t) 2*nklmd*sizeof(LDBLE)); + if (cu == NULL) malloc_error(); + iu = (int *) PHRQ_malloc((size_t) 2*nklmd*sizeof(int)); + if (iu == NULL) malloc_error(); + is = (int *) PHRQ_malloc((size_t) klmd*sizeof(int)); + if (is == NULL) malloc_error(); + + for(i = 0; i < 79; i++) token[i] = '='; + token[79] = '\0'; +/* + * Set solutions, largest bit is final solution, smallest bit is initial solution 1 + * Set phases, largest bit is last phase, smallest bit is first phase + * Set current bits to complete list. + */ + soln_bits = 0; + if (inv_ptr->count_solns + inv_ptr->count_phases > 32) { + error_msg("For inverse modeling, sum of initial solutions and phases must be <= 32.\n\tFor all reasonable calculations, the sum should be much less than 32.", STOP); + } + for (i = inv_ptr->count_solns ; i > 0; i--) { + temp_bits = 1 << (i - 1); + soln_bits += temp_bits; + } + if (check_solns(inv_ptr) == ERROR) { + error_msg("Calculations terminating.", STOP); + } +/* + * solutions are in highest bits, phases are in lower bits; + */ +/* + * All combinations of solutions + */ + first = TRUE; + for ( ; get_bits(soln_bits, inv_ptr->count_solns - 2, inv_ptr->count_solns - 1) > 0; soln_bits--) { +/* + * Loop through all models of of descending size + */ + for (model_size = inv_ptr->count_phases; model_size >= 0; model_size--) { + first_of_model_size = TRUE; + quit = TRUE; + while ( next_set_phases(inv_ptr, first_of_model_size, model_size) == TRUE) { + first_of_model_size = FALSE; + current_bits = (soln_bits << inv_ptr->count_phases) + phase_bits; + + if (subset_bad(current_bits) == TRUE || subset_minimal(current_bits) == TRUE) continue; + quit = FALSE; +/* + * Switch for finding minimal models only + */ + if (inv_ptr->minimal == TRUE && superset_minimal(current_bits) == TRUE) continue; +/* + * Solve for minimum epsilons, continue if no solution found. + */ + if (solve_with_mask(inv_ptr, current_bits) == ERROR) { + save_bad(current_bits); + if (first == TRUE) { + post_mortem(); + quit = TRUE; + break; + } else { + continue; + } + } + first = FALSE; +/* + * Model has been found, set bits + */ + good_bits = current_bits; + for(i = 0; i < inv_ptr->count_phases; i++) { + if (equal(delta1[i + inv_ptr->count_solns], 0.0, TOL) == TRUE) { + good_bits = set_bit(good_bits, i, 0); + } + } + for(i = 0; i < inv_ptr->count_solns; i++) { + if (equal(delta1[i], 0.0, TOL) == TRUE) { + good_bits = set_bit(good_bits, i + inv_ptr->count_phases, 0); + } + } +/* + * Determine if model is new + */ + for (j = 0; j < count_good; j++) { + if ( good_bits == good[j]) break; + } +/* + * Calculate ranges and print model only if NOT looking for minimal models + */ + print = FALSE; + if ( j >= count_good && inv_ptr->minimal == FALSE) { + print = TRUE; + save_good(good_bits); + if (inv_ptr->range == TRUE) { + range(inv_ptr, good_bits); + } + print_model(inv_ptr); + punch_model(inv_ptr); + } +/* + * If superset of a minimal model continue + */ + minimal_bits = good_bits; + if (superset_minimal(minimal_bits) == TRUE) { + if (print == TRUE) { + if (pr.inverse == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE,"%s\n\n", token); + } + } + continue; + } +/* + * If not superset of minimal model, find minimal model + */ + minimal_bits = minimal_solve(inv_ptr, minimal_bits); + if (minimal_bits == good_bits && print == TRUE) { + if (pr.inverse == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nModel contains minimum number of phases.\n"); + } + } + if (print == TRUE) { + if (pr.inverse == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE,"%s\n\n", token); + } + } + for (j = 0; j < count_good; j++) { + if ( minimal_bits == good[j]) break; + } + if (j >= count_good) { + save_good(minimal_bits); + if (inv_ptr->range == TRUE) { + range(inv_ptr, minimal_bits); + } + print_model(inv_ptr); + if (pr.inverse == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nModel contains minimum number of phases.\n"); + output_msg(OUTPUT_MESSAGE,"%s\n\n", token); + } + punch_model(inv_ptr); + } + save_minimal(minimal_bits); + } + if (quit == TRUE) break; + } + } +/* + * Summary print + */ + if (pr.inverse == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nSummary of inverse modeling:\n\n"); + output_msg(OUTPUT_MESSAGE,"\tNumber of models found: %d\n", count_good); + output_msg(OUTPUT_MESSAGE,"\tNumber of minimal models found: %d\n", count_minimal); + output_msg(OUTPUT_MESSAGE,"\tNumber of infeasible sets of phases saved: %d\n", count_bad); + output_msg(OUTPUT_MESSAGE,"\tNumber of calls to cl1: %d\n", count_calls); + } + array = (LDBLE *) free_check_null(array); + delta = (LDBLE *) free_check_null(delta); + array1 = (LDBLE *) free_check_null(array1); + zero = (LDBLE *) free_check_null(zero); + res = (LDBLE *) free_check_null(res); + delta1 = (LDBLE *) free_check_null(delta1); + delta2 = (LDBLE *) free_check_null(delta2); + delta3 = (LDBLE *) free_check_null(delta3); + delta_save = (LDBLE *) free_check_null(delta_save); + cu = (LDBLE *) free_check_null(cu); + iu = (int *) free_check_null(iu); + is = (int *) free_check_null(is); + col_name = (char **) free_check_null(col_name); + row_name = (char **) free_check_null(row_name); + col_back = (int *) free_check_null(col_back); + row_back = (int *) free_check_null(row_back); + min_delta = (LDBLE *) free_check_null(min_delta); + max_delta = (LDBLE *) free_check_null(max_delta); + good = (unsigned long *) free_check_null(good); + bad = (unsigned long *) free_check_null(bad); + minimal = (unsigned long *) free_check_null(minimal); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +unsigned long minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Starting with phases indicated in minimal bits, sequentially + * remove phases to find minimal solution + */ + int i; + unsigned long temp_bits_l; + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "Beginning minimal solve: \n"); + bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); + } + for (i = 0; i < inv_ptr->count_phases + inv_ptr->count_solns - 1; i++) { + if (get_bits(minimal_bits, i, 1) == 0) continue; + temp_bits_l = 1 << i; /* 0's and one 1 */ + temp_bits_l = ~temp_bits_l; /* 1's and one 0 */ + minimal_bits = minimal_bits & temp_bits_l; + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "Solving for minimal\n"); + bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); + } + +/* + * minimal_bits can not be superset of a minimal model, but + * could be subset of one of the sets of minerals with no feasible solution + * If it is a subset, then replace mineral and go on to next + */ + if ( subset_bad(minimal_bits) == TRUE) { + /* put bit back */ + minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ + continue; + } + if (solve_with_mask (inv_ptr, minimal_bits) == ERROR) { + save_bad(minimal_bits); + /* put bit back */ + minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ + } + + } + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE,"\n\nMINIMAL MODEL\n\n"); + bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); + } + solve_with_mask (inv_ptr, minimal_bits); + return(minimal_bits); +} + +/* ---------------------------------------------------------------------- */ +int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Uses cur_bits to zero out columns of the array and then solves. + */ + int i, k, l, m, n; + +/* + * Calculate dimensions + */ + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; + + + + memcpy( (void *) &(res[0]), (void *) &(zero[0]), (size_t) max_row_count * sizeof(LDBLE)); + memcpy( (void *) &(delta2[0]), (void *) &(delta[0]), (size_t) max_column_count * sizeof(LDBLE)); + memcpy( (void *) &(delta_save[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + + shrink(inv_ptr, array, array1, + &k, &l, &m, &n, + cur_bits, + delta2, col_back, row_back); + /* + * Save delta constraints + */ + for (i=0; i < n; i++) { + delta_save[col_back[i]] = delta2[i]; + } + + + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nColumns\n"); + for (i = 0; i < n; i++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i, col_name[col_back[i]]); + } + + output_msg(OUTPUT_MESSAGE, "\nRows\n"); + for (i = 0; i < k + l + m; i++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i, row_name[row_back[i]]); + } + + output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); + array_print(array1, k + l + m, n + 1, max_column_count); + + output_msg(OUTPUT_MESSAGE, "\nInput delta vector:\n"); + for (i=0; i < n; i++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, col_name[col_back[i]], (double) delta2[i]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + + for (i=0; i < k + l + m; i++) { + if (res[i] == 0) continue; + output_msg(OUTPUT_MESSAGE, "\nInput res is non zero:\n"); + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, row_name[row_back[i]], (double) res[i]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + } +/* + * Call CL1 + */ + + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "k, l, m, n, max_col, max_row\t%d\t%d\t%d\t%d\t%d\t%d\n", + k, l, m, n, max_column_count, max_row_count); + } + + kode = 1; + iter = 1000; + count_calls++; + +#ifdef INVERSE_CL1MP + if(inv_ptr->mp == TRUE) { + cl1mp(k, l, m, n, + nklmd, n2d, array1, + &kode, inv_ptr->mp_tolerance, &iter, + delta2, res, &error, cu, iu, is, TRUE, inv_ptr->mp_censor); + } else { + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, + delta2, res, &error, cu, iu, is, TRUE); + } +#else + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, + delta2, res, &error, cu, iu, is, TRUE); +#endif + if (kode == 3) { + sprintf(error_string, "Exceeded maximum iterations in inverse modeling: %d.\n" + "Recompile program with larger limit.", iter); + error_msg(error_string, STOP); + } + memcpy( (void *) &(delta1[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + for(i = 0; i < n; i++) { + delta1[col_back[i]] = delta2[i]; + } + +/* + * Debug, write results + */ + + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error); + output_msg(OUTPUT_MESSAGE, "\nsolution vector:\n"); + for (i=0; i < n; i++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, col_name[col_back[i]], (double) delta2[i]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + + output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); + for (i=0; i < (k + l + m); i++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, row_name[row_back[i]], (double) res[i]); + } + } + + if (kode != 0) { + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +unsigned long get_bits(unsigned long bits, int position, int number) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns number of bits from position and below. + * position begins at 0. + */ + return( (bits >> (position + 1 - number)) & ~(~0 << number)); +} +/* ---------------------------------------------------------------------- */ +int save_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of minimal models + */ + minimal[count_minimal] = bits; + count_minimal++; + if (count_minimal >= max_minimal) { + max_minimal *= 2; + minimal = (unsigned long *) PHRQ_realloc(minimal, (size_t) max_minimal * sizeof (unsigned long)); + if (minimal == NULL) malloc_error(); + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int save_good(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of good models, not necessarily minimal + */ + good[count_good] = bits; + count_good++; + if (count_good >= max_good) { + max_good *= 2; + good = (unsigned long *) PHRQ_realloc(good, (size_t) max_good * sizeof (unsigned long)); + if (good == NULL) malloc_error(); + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int save_bad(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of sets of phases with no feasible solution + */ + bad[count_bad] = bits; + count_bad++; + if (count_bad >= max_bad) { + max_bad *= 2; + bad = (unsigned long *) PHRQ_realloc(bad, (size_t) max_bad * sizeof (unsigned long)); + if (bad == NULL) malloc_error(); + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int superset_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a superset of any of the minimal models + */ + int i; + unsigned long temp_bits_l; + for (i=0; i < count_minimal; i++) { + temp_bits_l = bits | minimal[i]; + if (temp_bits_l == bits) { + return(TRUE); + } + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +int subset_bad(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a superset of any of the bad models + */ + int i; + unsigned long temp_bits_l; + for (i=0; i < count_bad; i++) { + temp_bits_l = bits | bad[i]; + if (temp_bits_l == bad[i]) { + return(TRUE); + } + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +int subset_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a subset of any of the minimal models + */ + int i; + unsigned long temp_bits_l; + for (i=0; i < count_minimal; i++) { + temp_bits_l = bits | minimal[i]; + if (temp_bits_l == minimal[i]) { + return(TRUE); + } + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +int bit_print(unsigned long bits, int l) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints l bits of an unsigned long + */ + int i; + + for (i = l - 1; i >= 0; i--) { + output_msg(OUTPUT_MESSAGE,"%lu ", get_bits(bits, i, 1)); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_model(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model + */ + int i, j, k; + int column; + int print_msg; + struct solution *solution_ptr; + struct master *master_ptr; + struct isotope *isotope_ptr; + LDBLE d1, d2, d3, d4; + char token[MAX_LENGTH]; +/* + * Update screen + */ + status(count_good, NULL); +/* + * print solution data, epsilons, and revised data + */ + if (pr.inverse == FALSE || pr.all == FALSE) return(OK); + max_pct = 0; + scaled_error = 0; + for (i = 0; i < inv_ptr->count_solns; i++) { + if (equal(delta1[i], 0.0, toler) == TRUE) continue; + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + xsolution_zero(); + for (j=0; solution_ptr->totals[j].description != NULL; j++) { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + master_ptr->total = solution_ptr->totals[j].moles; + } + + output_msg(OUTPUT_MESSAGE,"\nSolution %d: %s\n", inv_ptr->solns[i], solution_ptr->description); + output_msg(OUTPUT_MESSAGE,"\n%15.15s %12.12s %12.12s %12.12s\n", + " ", "Input", "Delta", "Input+Delta"); + master_alk->total = solution_ptr->total_alkalinity; + if (inv_ptr->carbon == TRUE) { + d1 = solution_ptr->ph; + d2 = delta1[col_ph + i] / delta1[i]; + d3 = d1 + d2; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + output_msg(OUTPUT_MESSAGE,"%15.15s %12.3e +%12.3e =%12.3e\n", + "pH", (double) d1, (double) d2, (double) d3); + if (inv_ptr->ph_uncertainties[i] > 0) { + scaled_error += fabs(d2) / inv_ptr->ph_uncertainties[i]; +/* debug + output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / inv_ptr->ph_uncertainties[i], fabs(d2), inv_ptr->ph_uncertainties[i]); + */ + } else if (d2 != 0.0) { + error_msg("Computing delta pH/uncertainty", CONTINUE); + } + } + for (j = 0; j < inv_ptr->count_elts; j++) { + if (inv_ptr->elts[j].master->s == s_eminus) continue; + d1 = inv_ptr->elts[j].master->total; + d2 = delta1[col_epsilon + j * inv_ptr->count_solns + i] / delta1[i]; + d3 = d1 + d2; + + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + + output_msg(OUTPUT_MESSAGE,"%15.15s %12.3e +%12.3e =%12.3e\n", + inv_ptr->elts[j].master->elt->name, (double) d1, (double) d2, (double) d3); + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE ) { + d3 = fabs(d2/d1); + if (d3 > max_pct) max_pct = d3; + } + d4 = 0; + if (inv_ptr->elts[j].uncertainties[i] > 0) { + d4 = fabs(inv_ptr->elts[j].uncertainties[i] * d1); + } else if (inv_ptr->elts[j].uncertainties[i] < 0) { + d4 = -inv_ptr->elts[j].uncertainties[i]; + } + if (d4 > 0) { + scaled_error += fabs(d2) / d4; +/* debug + output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / d4, fabs(d2), d4); + */ + } else if (d2 != 0.0) { + error_msg("Computing delta element/uncertainty", CONTINUE); + } + } + if (inv_ptr->count_isotopes > 0) { + /* adjustments to solution isotope composition */ + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { + for (k = 0; k < solution_ptr->count_isotopes; k++) { + if (inv_ptr->isotope_unknowns[j].elt_name != + solution_ptr->isotopes[k].elt_name || + inv_ptr->isotope_unknowns[j].isotope_number != + solution_ptr->isotopes[k].isotope_number) continue; + d1 = solution_ptr->isotopes[k].ratio; + d2 = delta1[col_isotopes + i * inv_ptr->count_isotope_unknowns + j] / delta1[i]; + d3 = d1 + d2; + + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + sprintf(token, "%d%s", + (int) inv_ptr->isotope_unknowns[j].isotope_number, + inv_ptr->isotope_unknowns[j].elt_name); + output_msg(OUTPUT_MESSAGE,"%15.15s %12g +%12g =%12g\n", token, + (double) d1, (double) d2, (double) d3); +/* + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE ) { + d3 = fabs(d2/d1); + if (d3 > max_pct) max_pct = d3; + } + */ + if (solution_ptr->isotopes[k].x_ratio_uncertainty > 0) { + scaled_error += fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty; +/* debug + output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty , fabs(d2), solution_ptr->isotopes[k].x_ratio_uncertainty); + */ + } else if (d2 != 0.0) { + error_msg("Computing delta solution isotope/uncertainty", CONTINUE); + } + } + } + } + } + +/* + * Adjustments to phases + */ + print_msg = FALSE; + if (inv_ptr->count_isotopes > 0) { + output_msg(OUTPUT_MESSAGE,"\nIsotopic composition of phases:\n"); + for (i = 0; i < inv_ptr->count_phases; i++) { + if (inv_ptr->phases[i].count_isotopes == 0) continue; + j = col_phases + i; + if (equal(delta1[j], 0.0, toler) == TRUE && + equal(min_delta[j], 0.0, toler) == TRUE && + equal(max_delta[j], 0.0, toler) == TRUE ) continue; + isotope_ptr = inv_ptr->phases[i].isotopes; + for (j = 0; j < inv_ptr->count_isotopes; j++) { + for (k = 0; k < inv_ptr->phases[i].count_isotopes; k++) { + if (inv_ptr->isotopes[j].elt_name != + isotope_ptr[k].elt_name || + inv_ptr->isotopes[j].isotope_number != + isotope_ptr[k].isotope_number) continue; + d1 = isotope_ptr[k].ratio; + column = col_phase_isotopes + i * inv_ptr->count_isotopes + j; + if (delta1[col_phases + i] != 0.0) { + d2 = delta1[column] / delta1[col_phases + i]; + } else { + continue; + } + d3 = d1 + d2; + if (equal(d1, 0.0, 1e-7) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, 1e-7) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, 1e-7) == TRUE) d3 = 0.0; + sprintf(token, "%d%s %s", + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name, + inv_ptr->phases[i].phase->name); + output_msg(OUTPUT_MESSAGE,"%15.15s %12g +%12g =%12g", token, + (double) d1, (double) d2, (double) d3); + if (fabs(d2) > (isotope_ptr[k].ratio_uncertainty + toler)) { + output_msg(OUTPUT_MESSAGE," **"); + print_msg = TRUE; + } + output_msg(OUTPUT_MESSAGE,"\n"); + if (isotope_ptr[k].ratio_uncertainty > 0) { + scaled_error += fabs(d2) / isotope_ptr[k].ratio_uncertainty; +/* debug + output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / isotope_ptr[k].ratio_uncertainty, fabs(d2), isotope_ptr[k].ratio_uncertainty); + */ + } else if (d2 != 0.0) { + error_msg("Computing delta phase isotope/uncertainty", CONTINUE); + } + } + } + } + } + if (print_msg == TRUE) { + output_msg(OUTPUT_MESSAGE,"\n**\tWARNING: The adjustment to at least one isotopic" + "\n\tcomposition of a phase exceeded the specified uncertainty" + "\n\tfor the phase. If the phase is not constrained to dissolve" + "\n\tor precipitate, then the isotopic composition of the phase" + "\n\tis also unconstrained.\n"); + } + output_msg(OUTPUT_MESSAGE,"\n%-20.20s %7s %12.12s %12.12s\n", "Solution fractions:", " ", "Minimum","Maximum"); + for (i = 0; i < inv_ptr->count_solns; i++) { + d1 = delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + output_msg(OUTPUT_MESSAGE, "%11s%4d %12.3e %12.3e %12.3e\n", "Solution", + inv_ptr->solns[i], (double) d1, (double) d2, (double) d3); + } + + output_msg(OUTPUT_MESSAGE,"\n%-25.25s %2s %12.12s %12.12s\n", + "Phase mole transfers:", " ", "Minimum","Maximum"); + for (i = col_phases; i < col_redox; i++) { + if (equal(delta1[i], 0.0, toler) == TRUE && + equal(min_delta[i], 0.0, toler) == TRUE && + equal(max_delta[i], 0.0, toler) == TRUE ) continue; + d1 = delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + output_msg(OUTPUT_MESSAGE, "%15.15s %12.3e %12.3e %12.3e %s\n", col_name[i], (double) d1, + (double) d2, (double) d3, inv_ptr->phases[i - col_phases].phase->formula); + } + + output_msg(OUTPUT_MESSAGE,"\n%-25.25s\n", "Redox mole transfers:"); + for (i = col_redox; i < col_epsilon; i++) { + if (equal(delta1[i], 0.0, toler) == TRUE) continue; + output_msg(OUTPUT_MESSAGE, "%15.15s %12.3e\n", col_name[i], (double) delta1[i]); + } + + output_msg(OUTPUT_MESSAGE,"\nSum of residuals (epsilons in documentation): %12.3e\n", ((double) error/SCALE_EPSILON)); + output_msg(OUTPUT_MESSAGE, "Sum of delta/uncertainty limit: %12.3e\n", (double) scaled_error); + output_msg(OUTPUT_MESSAGE, "Maximum fractional error in element concentration: %12.3e\n", (double) max_pct); +/* + * Flush buffer after each model + */ + output_fflush(OUTPUT_MESSAGE); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_model_heading(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model headings to selected output file + */ + int i; + char token[MAX_LENGTH]; + if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) return(OK); +/* + * Print sum of residuals and maximum fractional error + */ + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH,"%12s\t%12s\t%12s\t","Sum_resid", "Sum_Delta/U","MaxFracErr"); + } else { + output_msg(OUTPUT_PUNCH,"%20s\t%20s\t%20s\t","Sum_resid", "Sum_Delta/U","MaxFracErr"); + } +/* + * Print solution numbers + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + sprintf(token, "Soln %d", inv_ptr->solns[i]); + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH,"%12s\t%12s\t%12s\t", token, "min", "max"); + } else { + output_msg(OUTPUT_PUNCH,"%20s\t%20s\t%20s\t", token, "min","max"); + } + } +/* + * Print phase names + */ + for (i = col_phases; i < col_redox; i++) { + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH, "%12s\t%12s\t%12s\t", col_name[i], " min", " max"); + } else { + output_msg(OUTPUT_PUNCH, "%20s\t%20s\t%20s\t", col_name[i], " min", " max"); + } + } + output_msg(OUTPUT_PUNCH, "\n"); +/* + * Flush buffer after each model + */ + output_fflush(OUTPUT_PUNCH); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_model(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model to selected output file + */ + int i; + LDBLE d1, d2, d3; + if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) return(OK); +/* + * write residual info + */ + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH,"%12.4e\t", ((double) error/SCALE_EPSILON)); + output_msg(OUTPUT_PUNCH,"%12.4e\t", (double) scaled_error); + output_msg(OUTPUT_PUNCH,"%12.4e\t", (double) max_pct); + } else { + output_msg(OUTPUT_PUNCH,"%20.12e\t", ((double) error/SCALE_EPSILON)); + output_msg(OUTPUT_PUNCH,"%20.12e\t", (double) scaled_error); + output_msg(OUTPUT_PUNCH,"%20.12e\t", (double) max_pct); + } +/* + * write solution fractions + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + d1 = delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH, "%12.4e\t%12.4e\t%12.4e\t", (double) d1, (double) d2, (double) d3); + } else { + output_msg(OUTPUT_PUNCH, "%20.12e\t%20.12e\t%20.12e\t", (double) d1, (double) d2, (double) d3); + } + } +/* + * write phase transfers + */ + for (i = col_phases; i < col_redox; i++) { + d1 = delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; + if (punch.high_precision == FALSE) { + output_msg(OUTPUT_PUNCH, "%12.4e\t%12.4e\t%12.4e\t", (double) d1, (double) d2, (double) d3); + } else { + output_msg(OUTPUT_PUNCH, "%20.12e\t%20.12e\t%20.12e\t", (double) d1, (double) d2, (double) d3); + } + } + output_msg(OUTPUT_PUNCH, "\n"); +/* + * Flush buffer after each model + */ + output_fflush(OUTPUT_PUNCH); + return(OK); +} +/* ---------------------------------------------------------------------- */ +unsigned long set_bit(unsigned long bits, int position, int value) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets a single bit + */ + unsigned long temp_bits_l; + + temp_bits_l = 1 << position; + if (value == 0) { + temp_bits_l = ~temp_bits_l; + temp_bits_l = bits & temp_bits_l; + } else { + temp_bits_l = bits | temp_bits_l; + } + return(temp_bits_l); +} +/* ---------------------------------------------------------------------- */ +int next_set_phases(struct inverse *inv_ptr, + int first_of_model_size, + int model_size) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + unsigned long temp_bits_l; + static int min_position[32], max_position[32], now[32]; + +/* + * min_ and max_position are arrays, logically with length + * of model_size, that contain minimum and maximum + * phase numbers that can be in that model position. + * + * now contains a list of phase numbers to mark as in for this + * model + */ + +/* + * Initialize for a given model_size + */ + if (first_of_model_size == TRUE) { + for (i = 0; i < model_size; i++) { + min_position[i] = i; + now[i] = i; + max_position[i] = inv_ptr->count_phases - model_size + i; + } + } else { +/* + * Determine next combination of phases for fixed model_size + */ + for (i = (model_size - 1); i >= 0; i--) { + if (now[i] < max_position[i]) { + now[i]++; + if (i < (model_size - 1) ) { + k = now[i]; + for (j = (i + 1); j < model_size; j++) { + k++; + now[j] = k; + } + } + break; + } + } + if (i < 0) return(FALSE); + } +/* + * Set bits which switch in phases + */ + temp_bits_l = 0; + for (j = 0; j < model_size; j++) { + temp_bits_l += (1 << now[j]); + } + phase_bits = temp_bits_l; + return(TRUE); +} + +/* ---------------------------------------------------------------------- */ +int range(struct inverse *inv_ptr, unsigned long cur_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes the model from cur_bits and sequentially determines the + * minimum and maximum values for each solution fraction and + * each phase mass transfer. + */ + int i, j; + int k, l, m, n; + int f; + unsigned long bits; + LDBLE error2; +/* + * Include forced solutions and phases in range calculation + */ + for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) { + if (i < inv_ptr->count_phases) { + if (inv_ptr->phases[i].force == TRUE) { + cur_bits = set_bit(cur_bits, i , 1); + } + } else { + if (inv_ptr->force_solns[i - inv_ptr->count_phases] == TRUE) { + cur_bits = set_bit(cur_bits, i, 1); + } + } + } + + memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); +/* + * Switch bits so that phases are high and solutions are low + */ + bits = get_bits(cur_bits, inv_ptr->count_phases + inv_ptr->count_solns - 1, inv_ptr->count_solns); + bits += (get_bits(cur_bits, inv_ptr->count_phases - 1, inv_ptr->count_phases) << inv_ptr->count_solns); +/* + * Do range calculation + */ + for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) { + if (inv_ptr->count_solns == i + 1) { + min_delta[i] = 1.0; + max_delta[i] = 1.0; + continue; + } + if (get_bits(bits, i, 1) == 0) continue; +/* + * Calculate min and max + */ + for (f = -1; f < 2; f += 2) { + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; /* number of variables */ +/* + * Copy equations + */ + memcpy((void *) &(array1[0]), (void *) &(array[0]), + (size_t) max_column_count * max_row_count * sizeof(LDBLE)); + memcpy((void *) &(delta2[0]), (void *) &(delta[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(delta3[0]), (void *) &(zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(delta_save[0]), (void *) &(zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(res[0]), (void *) &(zero[0]), + (size_t) max_row_count * sizeof(LDBLE)); + +/* + * Change optimization + */ + for (j = 0; j < k; j++) { + memcpy((void *) &(array1[j * max_column_count]), (void *) &(zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } + array1[i] = 1.0; + if (f < 1) { + array1[n] = -fabs(inv_ptr->range_max); + } else { + array1[n] = fabs(inv_ptr->range_max); + } + shrink(inv_ptr, array1, array1, + &k, &l, &m, &n, + cur_bits, + delta2, col_back, row_back); + /* + * Save delta constraints + */ + for (j=0; j < n; j++) { + delta_save[col_back[j]] = delta2[j]; + } + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nInput delta:\n\n"); + for (j = 0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d %s\t%g\n", j, col_name[col_back[j]], (double) delta2[j]); + } + output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); + array_print(array1, k + l + m, + n + 1, max_column_count); + } + kode = 1; + iter = 200; + count_calls++; +#ifdef INVERSE_CL1MP + if(inv_ptr->mp == TRUE) { + cl1mp(k, l, m, n, + nklmd, n2d, array1, + &kode, inv_ptr->mp_tolerance, &iter, + delta2, res, &error2, cu, iu, is, TRUE, inv_ptr->mp_censor); + } else { + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, + delta2, res, &error2, cu, iu, is, TRUE); + } +#else + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, + delta2, res, &error2, cu, iu, is, TRUE); +#endif + if (kode != 0) { + output_msg(OUTPUT_MESSAGE, "Error in subroutine range. Kode = %d\n", kode); + } + + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error2); + output_msg(OUTPUT_MESSAGE, "k, l, m, n: %d\t%d\t%d\t%d\n", k, l, m, n); + output_msg(OUTPUT_MESSAGE, "\nsolution vector %s\n", col_name[i]); + for (j = 0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], (double) delta2[j]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + + output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); + for (j = 0; j < (k + l + m); j++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n", j, row_name[row_back[j]], (double) res[j]); + } + } + for(j = 0; j < n; j++) { + if (col_back[j] == i) break; + } + if (f < 0) { + min_delta[i] = delta2[j]; + } else { + max_delta[i] = delta2[j]; + } + for(j = 0; j < n; j++) { + delta3[col_back[j]] = delta2[j]; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int shrink(struct inverse *inv_ptr, LDBLE *array_in, LDBLE *array_out, + int *k, int *l, int *m, int *n, + unsigned long cur_bits, + LDBLE *delta_l, int *col_back_l, int *row_back_l) +/* ---------------------------------------------------------------------- */ +{ +/* + * Shrink eliminates any rows that are all zeros and any columns + * that are not in cur_bits, result is put in array_out + * + * k, l, m, n return the new sizes of the array. + * delta is remapped to retain any non-negativity constraints + * Col_back maps columns that remain back to original columns + * Row_back maps rows that remain back to original rows + */ + int i, j, row; + int k1, l1, m1; + int cur_col, column; + int nonzero; +/* + * Copy array_in to array_out + */ + if (array_in != array_out) { + for (i = 0; i < (*k + *l + *m); i++) { + memcpy(&(array_out[i * max_column_count]), &(array_in[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + } + } +/* + * Determine columns to eliminate + */ + for (i = 0; i < (*n + 1); i++) col_back_l[i] = i; + +/* + * Drop phases not in model + */ + for (i = 0; i < inv_ptr->count_phases; i++) { + if (get_bits(cur_bits, i, 1) == 0) { + col_back_l[col_phases + i] = -1; + /* drop isotopes */ + if (inv_ptr->count_isotopes > 0 ) { + for (j =0; j < inv_ptr->count_isotopes; j++) { + column = col_phase_isotopes + i * inv_ptr->count_isotopes + j; + col_back_l[column] = -1; + } + } + } + } +/* + * Drop solutions not in model + */ + for (i = 0; i < (inv_ptr->count_solns - 1) ; i++) { + if (get_bits(cur_bits, inv_ptr->count_phases + i, 1) == 0) { + col_back_l[i] = -1; + /* drop all epsilons for the solution */ + for(j = 0; j < inv_ptr->count_elts; j++) { + column = col_epsilon + j * inv_ptr->count_solns + i; + col_back_l[column] = -1; + } + /* drop pH for the solution */ + if (inv_ptr->carbon == TRUE) { + column = col_ph + i; + col_back_l[column] = -1; + } + /* drop isotopes */ + if (inv_ptr->count_isotopes > 0) { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { + column = col_isotopes + i * inv_ptr->count_isotope_unknowns + j; + col_back_l[column] = -1; + } + } + } + } + +/* + * Drop epsilons not used + */ + for (i = col_epsilon; i < *n; i++) { + if (col_back_l[i] < 0) continue; + for (j = 0; j < (*k + *l + *m); j++) { + if (array_out[j * max_column_count + i] != 0) break; + } + if (j == (*k + *l + *m)) { + col_back_l[i] = -1; + } + } +/* + * rewrite array_out + */ + cur_col = 0; + for (i = 0; i < (*n + 1); i++) { + if (col_back_l[i] < 0) continue; + if (cur_col == col_back_l[i]) { + cur_col++; + continue; + } + for (j=0; j < (*k + *l + *m); j++) { + array_out[j * max_column_count + cur_col] = array_out[j * max_column_count + i]; + } + col_back_l[cur_col] = col_back_l[i]; + delta_l[cur_col] = delta_l[i]; + cur_col++; + } + *n = cur_col - 1; +/* + * Eliminate unnecessary optimization eqns + */ + row = 0; + k1 = 0; + for(i=0; i < *k; i++) { + if (memcmp(&(array_out[i*max_column_count]), &(zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) { + continue; + } +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + k1++; + } + +/* + * Eliminate unnecessary equality eqns + */ + l1 = 0; + for (i = *k; i < (*k + *l); i++) { + nonzero = FALSE; + for (j = 0; j < *n; j++) { + if (equal(array_out[i * max_column_count + j], 0.0, toler) == FALSE) { + nonzero = TRUE; + break; + } + } + if (nonzero == FALSE) continue; +/* + if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) { + continue; + } + */ +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + l1++; + } +/* + * Eliminate unnecessary inequality eqns + */ + m1 = 0; + for (i = (*k + *l); i < (*k + *l + *m); i++) { + nonzero = FALSE; + for (j = 0; j < *n; j++) { + if (equal(array_out[i * max_column_count + j], 0.0, toler) == FALSE) { + nonzero = TRUE; + break; + } + } + if (nonzero == FALSE) continue; +/* + if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) { + continue; + } + */ +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + m1++; + } + + *k = k1; + *l = l1; + *m = m1; +/* + * Scale all inequality rows + */ + + for (i = *k + *l; i < *k + *l + *m; i++) { + for (j = 0; j < *n + 1; j++) { + array_out[i*max_column_count + j] *= SCALE_ALL; + } + } + + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int check_solns(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check_solns checks that each solution can be charge balanced within + * the given constraints. If not, it is an error and the program will + * terminate. + */ + int i, j; + int k, l, m, n; + int return_value; + unsigned long bits; + LDBLE error2; + + memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + +/* + * Switch bits so that phases are high and solutions are low + */ + return_value = OK; + for (i = 0; i < inv_ptr->count_solns; i++) { + bits = 0; + bits += 1 << (inv_ptr->count_phases + i); +/* + * Check for feasibility of charge balance with given uncertainties + */ + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; /* number of variables */ +/* debug + output_msg(OUTPUT_MESSAGE, "\nColumns\n"); + for (j = 0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, col_name[j]); + } + + output_msg(OUTPUT_MESSAGE, "\nRows\n"); + for (j = 0; j < k + l + m; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, row_name[j]); + } + + output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); + array_print(array, k + l + m, + n + 1, max_column_count); + */ +/* + * Copy equations + */ + memcpy((void *) &(array1[0]), (void *) &(array[0]), + (size_t) max_column_count * max_row_count * sizeof(LDBLE)); + memcpy((void *) &(delta2[0]), (void *) &(delta[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(res[0]), (void *) &(zero[0]), + (size_t) max_row_count * sizeof(LDBLE)); + +/* + * Keep optimization + */ +/* + * Zero out mass balance rows and fraction rows + */ + for (j = row_mb; j < row_charge; j++) { + memcpy((void *) &(array1[j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * Set fraction of solution to 1.0 + */ + array1[(row_charge - 1) * max_column_count + i] = 1.0; + array1[(row_charge - 1) * max_column_count + n] = 1.0; + +/* + * Zero out charge balance rows for other solutions + */ + for (j = 0; j < inv_ptr->count_solns; j++) { + if ( j == i ) continue; + memcpy((void *) &(array1[(row_charge + j) * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + } + +/* + * Zero out isotope mole balance + */ + for (j = row_isotopes; j < row_epsilon; j++) { + memcpy((void *) &(array1[ j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + } + +/* + * Zero out isotope uncertainties + */ + for (j = row_isotope_epsilon; j < count_rows; j++) { + memcpy((void *) &(array1[ j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * Can't Zero out epsilon constraint rows for other solutions because not sure which + * are which + */ + + shrink(inv_ptr, array1, array1, + &k, &l, &m, &n, + bits, + delta2, col_back, row_back); +/* Debug + + output_msg(OUTPUT_MESSAGE, "\nColumns\n"); + for (j = 0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, col_name[col_back[j]]); + } + + output_msg(OUTPUT_MESSAGE, "\nRows\n"); + for (j = 0; j < k + l + m; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, row_name[row_back[j]]); + } + + output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); + array_print(array1, k + l + m, + n + 1, max_column_count); + + output_msg(OUTPUT_MESSAGE, "\nInput delta vector:\n"); + for (j=0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + */ + + kode = 1; + iter = 200; + count_calls++; + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, + delta2, res, &error2, cu, iu, is, TRUE); + + if (kode != 0) { + sprintf(error_string, "Not possible to balance solution %d with input uncertainties.", inv_ptr->solns[i]); + error_msg(error_string, CONTINUE); + return_value = ERROR; + } + +/* Debug + output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, error); + output_msg(OUTPUT_MESSAGE, "k, l, m, n: %d\t%d\t%d\t%d\n", k, l, m, n); + + output_msg(OUTPUT_MESSAGE, "\nsolution vector %s\n", col_name[i]); + for (j = 0; j < n; j++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j]); + output_msg(OUTPUT_MESSAGE, "\n"); + } + + output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); + for (j = 0; j < (k + l + m); j++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n", j, row_name[row_back[j]], res[j]); + } + */ + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int post_mortem(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Post_mortem simply identifies which equality and inequality of the + * array have not been satisfied. + * + */ + int i, j; + LDBLE sum; +/* + * Check equalities + */ + output_msg(OUTPUT_MESSAGE, "\nPost_mortem examination of inverse modeling:\n\n"); + for (i = row_mb; i < row_epsilon; i++) { + sum = 0; + for (j = 0; j < count_unknowns; j++) { + sum += delta1[j] * array[i * max_column_count + j]; + } + + if ( equal(sum, array[(i * max_column_count) + count_unknowns], toler) == FALSE) { + output_msg(OUTPUT_MESSAGE, "\tERROR: equality not satisfied for %s, %e.\n", row_name[i], sum - array[(i * max_column_count) + count_unknowns]); + } + } +/* + * Check inequalities + */ + for (i = row_epsilon; i < count_rows; i++) { + sum = 0; + for (j = 0; j < count_unknowns; j++) { + sum += delta1[j] * array[i * max_column_count + j]; + } + + if ( sum > array[(i * max_column_count) + count_unknowns] + toler) { + output_msg(OUTPUT_MESSAGE, "\tERROR: inequality not satisfied for %s, %e\n", row_name[i], sum - array[(i * max_column_count) + count_unknowns]); + } + } +/* + * Check dissolution/precipitation constraints + */ + for (i = 0; i < count_unknowns; i++) { + if (delta_save[i] > 0.5 && delta1[i] < -toler) { + output_msg(OUTPUT_MESSAGE, "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", i, col_name[i], delta1[i]); + } else if (delta_save[i] < -0.5 && delta1[i] > toler) { + output_msg(OUTPUT_MESSAGE, "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", i, col_name[i], delta1[i]); + } + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int carbon_derivs(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, n, temp; + LDBLE c_uncertainty, d_carbon, alk_plus, alk_minus; + struct solution *solution_ptr_orig, *solution_ptr; + + inv_ptr->dalk_dph = (LDBLE *) free_check_null(inv_ptr->dalk_dph); + inv_ptr->dalk_dph = (LDBLE *) PHRQ_malloc( (size_t) inv_ptr->count_solns * sizeof(LDBLE) ); + if (inv_ptr->dalk_dph == NULL) malloc_error(); + + inv_ptr->dalk_dc = (LDBLE *) free_check_null(inv_ptr->dalk_dc); + inv_ptr->dalk_dc = (LDBLE *) PHRQ_malloc( (size_t) inv_ptr->count_solns * sizeof(LDBLE) ); + if (inv_ptr->dalk_dc == NULL) malloc_error(); + + for (i = 0; i < inv_ptr->count_solns; i++) { + solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &n, TRUE); + if (solution_ptr_orig == NULL) { + sprintf(error_string, "Solution %d for inverse " + "modeling not found.", inv_ptr->solns[i]); + error_msg(error_string, STOP); + } +/* + * Find carbon uncertainty + */ + c_uncertainty = 0; + d_carbon = 0; + for (j = 0; j < inv_ptr->count_elts; j++) { + if (inv_ptr->elts[j].master == s_co3->secondary) { + c_uncertainty = inv_ptr->elts[j].uncertainties[i]; + break; + } + } + if (c_uncertainty < 0.0) { + d_carbon = -c_uncertainty; + } else if (c_uncertainty > 0.0) { + for (k = 0; solution_ptr_orig->totals[k].description != NULL; k++) { + if (strcmp(solution_ptr_orig->totals[k].description, "C(4)") == 0) { + d_carbon = solution_ptr_orig->totals[k].moles / + solution_ptr_orig->mass_water * c_uncertainty; + break; + } + + } + } + +/* + * Make four copies of solution + * Modify ph and carbon in solutions + */ + set_ph_c(inv_ptr, i, solution_ptr_orig, -5, 0.0, 1.0, 0.0); + set_ph_c(inv_ptr, i, solution_ptr_orig, -4, 0.0, -1.0, 0.0); + if (c_uncertainty != 0) { + set_ph_c(inv_ptr, i, solution_ptr_orig, -3, d_carbon, 0.0, 1.0); + set_ph_c(inv_ptr, i, solution_ptr_orig, -2, d_carbon, 0.0, -1.0); + } +/* */ + temp = pr.all; + pr.all = FALSE; + initial_solutions(FALSE); + pr.all = temp; +/* + * dAlk/dpH + */ + solution_ptr = solution_bsearch(-5, &n, TRUE); + alk_plus = solution_ptr->total_alkalinity; + solution_ptr = solution_bsearch(-4, &n, TRUE); + alk_minus = solution_ptr->total_alkalinity; + inv_ptr->dalk_dph[i] = (alk_plus - alk_minus) / + (2.0 * inv_ptr->ph_uncertainties[i]); +/* + * dAlk/dC + */ + if (d_carbon != 0) { + solution_ptr = solution_bsearch(-3, &n, TRUE); + alk_plus = solution_ptr->total_alkalinity; + solution_ptr = solution_bsearch(-2, &n, TRUE); + alk_minus = solution_ptr->total_alkalinity; + inv_ptr->dalk_dc[i] = (alk_plus - alk_minus) / (2.0 * d_carbon); + } else { + inv_ptr->dalk_dc[i] = 0.0; + } + if (debug_inverse == TRUE) { + output_msg(OUTPUT_MESSAGE, "dAlk/dph = %e\tdAlk/dC = %e\n", + (double) inv_ptr->dalk_dph[i], (double) inv_ptr->dalk_dc[i]); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *solution_ptr_orig, + int n_user_new, + LDBLE d_carbon, + LDBLE ph_factor, + LDBLE c_factor) +/* ---------------------------------------------------------------------- */ +{ + int j, n_user_orig; + struct solution *solution_ptr; + struct conc *conc_ptr; + + n_user_orig = inv_ptr->solns[i]; + solution_duplicate(n_user_orig, n_user_new); + solution_ptr = solution_bsearch(n_user_new, &j, TRUE); + solution_ptr->new_def = TRUE; + solution_ptr->n_user_end = n_user_new; + solution_ptr->ph += inv_ptr->ph_uncertainties[i] * ph_factor; + for (j = 0; solution_ptr->totals[j].description != NULL; j++) { + conc_ptr = &solution_ptr->totals[j]; + conc_ptr->input_conc = conc_ptr->moles / + solution_ptr_orig->mass_water; + conc_ptr->units = string_hsave("Mol/kgw"); + if (strcmp(conc_ptr->description, "C(4)") == 0) { + conc_ptr->input_conc += d_carbon * c_factor; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int isotope_balance_equation(struct inverse *inv_ptr, int row, int n) +/* ---------------------------------------------------------------------- */ +/* + * routine fills in an isotope balance equation + * + * row is the row in array that needs to be filled + * n is the isotope number in inv_ptr + */ +{ + int i, j, k; + LDBLE isotope_number; + int column; + LDBLE f; + struct master *primary_ptr; + struct solution *solution_ptr; + struct isotope *isotope_ptr; +/* + * Determine primary master species and isotope number for + * isotope mass-balance equation + */ + column = 0; + primary_ptr = master_bsearch_primary(inv_ptr->isotopes[n].elt_name); + isotope_number = inv_ptr->isotopes[n].isotope_number; + /* isotope element must be defined */ + if (primary_ptr == NULL) { + sprintf(error_string, "In isotope calculation: element not defined: %s.", + inv_ptr->isotopes[n].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + + /* isotope element must be primary */ + if (primary_ptr->primary != TRUE) { + sprintf(error_string, "Isotope mass-balance may only be used" + " for total element concentrations.\n" + "Secondary species not allowed: %s.", + inv_ptr->isotopes[n].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + +/* + * Fill in terms for each solution + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + if (i == (inv_ptr->count_solns - 1)) { + f = -1.0; + } else { + f = 1.0; + } + + /* mixing fraction term */ + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + isotope_ptr = solution_ptr->isotopes; + for (j = 0; j < solution_ptr->count_isotopes; j++) { + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) { + array[row * max_column_count + i] += f * isotope_ptr[j].total * isotope_ptr[j].ratio; + } + } + + /* epsilon of total moles of element valence * ratio */ + for (j = 0; j < solution_ptr->count_isotopes; j++) { + + /* What to do with H and O, skip for now ??? */ + if (primary_ptr == s_hplus->primary || + primary_ptr == s_h2o->primary) continue; + + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) { + + /* find column of master for solution i*/ + for (k = 0; k < inv_ptr->count_elts; k++) { + if (isotope_ptr[j].master == inv_ptr->elts[k].master) break; + } + column = col_epsilon + (k * inv_ptr->count_solns) + i; + array[row * max_column_count + column] += f * isotope_ptr[j].ratio; + } + } + + /* epsilon of ratio * total of element valence */ + for (j = 0; j < solution_ptr->count_isotopes; j++) { + + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) { + + /* find column of epsilon for ratio of valence */ + for (k = 0; k < inv_ptr->count_isotope_unknowns; k++) { + if (isotope_ptr[j].master == inv_ptr->isotope_unknowns[k].master && + isotope_ptr[j].isotope_number == inv_ptr->isotope_unknowns[k].isotope_number) { + column = col_isotopes + (i * inv_ptr->count_isotope_unknowns) + k; + } + } + array[row * max_column_count + column] += f * isotope_ptr[j].total; + } + } + } +/* + * Fill in terms for each phase + */ + for (i = 0; i < inv_ptr->count_phases; i++) { + if (inv_ptr->phases[i].count_isotopes <= 0) continue; + isotope_ptr = inv_ptr->phases[i].isotopes; + for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) { + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) { + /* term for alpha phase unknowns */ + column = col_phases + i; + array[row * max_column_count + column] = isotope_ptr[j].ratio * isotope_ptr[j].coef; + /* term for phase isotope uncertainty unknown */ + column = col_phase_isotopes + i * inv_ptr->count_isotopes + n; + array[row * max_column_count + column] = isotope_ptr[j].coef; + break; + } + } + + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int count_isotope_unknowns(struct inverse *inv_ptr, struct isotope **isotope_unknowns) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through elements for which isotope balances are requested + * and make a array of isotope structures + * return total number of isotope unknowns and structure array + */ + int i, k; + LDBLE isotope_number; + struct master *primary_ptr; + int count_isotopes; + struct isotope *isotopes; + + if (inv_ptr->count_isotopes == 0) { + *isotope_unknowns = NULL; + return(0); + } + isotopes = (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); + if (isotopes == NULL) malloc_error(); + count_isotopes = 0; + + for (i = 0; i < inv_ptr->count_isotopes; i++) { + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + if (primary_ptr == NULL) { + sprintf(error_string, "Element not found for isotope calculation: %s.", + inv_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (primary_ptr->primary != TRUE) { + sprintf(error_string, "Isotope mass-balance may only be used" + " for total element concentrations.\n" + "Secondary species not allowed: %s.", + inv_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + + /* nonredox element */ + if (primary_ptr->s->secondary == NULL) { + isotopes = (struct isotope *) PHRQ_realloc(isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); + if (isotopes == NULL) malloc_error(); + isotopes[count_isotopes].primary = primary_ptr; + isotopes[count_isotopes].master = primary_ptr; + isotopes[count_isotopes].isotope_number = isotope_number; + isotopes[count_isotopes].elt_name = primary_ptr->elt->name; + count_isotopes++; + + /* redox element */ + } else { + + /* find master */ + for (k = 0; k < count_master; k++) { + if (master[k] == primary_ptr) break; + } + + /* sum all secondary for master */ + k++; + for ( ; k < count_master; k++) { + if (master[k]->elt->primary != primary_ptr) break; + isotopes = (struct isotope *) PHRQ_realloc(isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); + if (isotopes == NULL) malloc_error(); + isotopes[count_isotopes].primary = primary_ptr; + isotopes[count_isotopes].master = master[k]; + isotopes[count_isotopes].isotope_number = isotope_number; + isotopes[count_isotopes].elt_name = master[k]->elt->name; + count_isotopes++; + } + } + } + *isotope_unknowns = isotopes; + return (count_isotopes); +} +/* ---------------------------------------------------------------------- */ +int check_isotopes(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through elements for which isotope balances are requested + * and make sure each solution has isotope ratios defined + */ + int i, ii, j, k, l; + int err, found_isotope; + LDBLE isotope_number; + struct master *master_ptr, *primary_ptr; + struct solution *solution_ptr; + struct phase *phase_ptr; + char token[MAX_LENGTH]; + +/* + * Check solutions for necessary isotope data + */ + for (j = 0; j < inv_ptr->count_solns; j++) { + solution_ptr = solution_bsearch(inv_ptr->solns[j], &i, TRUE); + xsolution_zero(); + add_solution (solution_ptr, 1.0, 1.0); +/* + * Go through inverse isotopes and make sure isotope data for each solution + * inv_ptr->isotopes has elements; inv_ptr->i_u has redox states and uncertainties + */ + for (i = 0; i < inv_ptr->count_isotopes; i++) { + err = FALSE; + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + found_isotope = FALSE; + for (k = 0; k < solution_ptr->count_isotopes; k++) { + if (solution_ptr->isotopes[k].primary == primary_ptr && + solution_ptr->isotopes[k].isotope_number == isotope_number) { + found_isotope = TRUE; + break; + } + } + if (found_isotope == TRUE) continue; + + /* did not find isotope, which is ok if element not in solution */ + if (primary_ptr == s_h2o->primary || primary_ptr == s_hplus->primary) { + err = TRUE; + } else if (primary_ptr->total > 0) { + err = TRUE; + } + if (err == TRUE) { + sprintf(error_string, + "In solution %d, isotope ratio(s) are needed for element: %g%s.", + solution_ptr->n_user, (double) isotope_number, primary_ptr->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } +/* + * Go through solution isotopes and set uncertainties + */ + for (k = 0; k < solution_ptr->count_isotopes; k++) { + solution_ptr->isotopes[k].x_ratio_uncertainty = NAN; +/* + * Search for secondary or primary master in inverse uncertainties + */ + ii = -1; + for (i = 0; i < inv_ptr->count_i_u; i++) { + master_ptr = master_bsearch(inv_ptr->i_u[i].elt_name); + if (master_ptr == solution_ptr->isotopes[k].master) { + ii = i; + break; + } + if (master_ptr == solution_ptr->isotopes[k].primary) { + ii = i; + } + } + /* solution isotope data not being used in inverse */ + if (ii == -1) continue; + + i = ii; + /* use inverse-defined uncertainties first */ + if (j < inv_ptr->i_u[i].count_uncertainties && inv_ptr->i_u[i].uncertainties[j] != NAN) { + solution_ptr->isotopes[k].x_ratio_uncertainty = inv_ptr->i_u[i].uncertainties[j]; + + /* use solution-defined uncertainties second */ + } else if (solution_ptr->isotopes[k].ratio_uncertainty != NAN) { + solution_ptr->isotopes[k].x_ratio_uncertainty = solution_ptr->isotopes[k].ratio_uncertainty; + /* use isotope defaults third */ + } else { + sprintf(token,"%g%s", (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name); + for (l = 0; l < count_iso_defaults; l++) { + if (strcmp(token, iso_defaults[l].name) == 0) { + solution_ptr->isotopes[k].x_ratio_uncertainty = iso_defaults[l].uncertainty; + sprintf(error_string, "Solution %d, element %g%s: default isotope ratio uncertainty is used, %g.", solution_ptr->n_user, (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name, (double) solution_ptr->isotopes[k].x_ratio_uncertainty); + warning_msg(error_string); + break; + } + } + } + if (solution_ptr->isotopes[k].x_ratio_uncertainty == NAN) { + sprintf(error_string, + "In solution %d, isotope ratio uncertainty is needed for element: %g%s.", solution_ptr->n_user, (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } +/* + * Check phases for necessary isotope data + */ + for (j = 0; j < inv_ptr->count_phases; j++) { + for (i = 0; i < inv_ptr->count_isotopes; i++) { + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + found_isotope = FALSE; + for (k = 0; k < inv_ptr->phases[j].count_isotopes; k++) { + if (inv_ptr->phases[j].isotopes[k].primary == primary_ptr && + inv_ptr->phases[j].isotopes[k].isotope_number == isotope_number) { + found_isotope = TRUE; + break; + } + } + if (found_isotope == TRUE) continue; + + /* did not find isotope, which is ok if element not in solution */ + phase_ptr = inv_ptr->phases[j].phase; + k = 0; + while (phase_ptr->next_elt[k].elt != NULL) { + if (phase_ptr->next_elt[k].elt->primary == primary_ptr) { + if (s_hplus->primary == primary_ptr || + s_h2o->primary == primary_ptr) { + k++; + continue; + } else { + sprintf(error_string, + "In phase %s, isotope ratio(s) are needed for element: %g%s.", + phase_ptr->name, (double) isotope_number, primary_ptr->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + } + k++; + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int phase_isotope_inequalities(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int column; + char token[MAX_LENGTH]; + if (inv_ptr->count_isotopes <= 0 ) return OK; + for (i = 0; i < inv_ptr->count_phases; i++) { + if (inv_ptr->phases[i].count_isotopes <= 0) continue; + + for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) { + /* find index number */ + for (k = 0; k < inv_ptr->count_isotopes; k++) { + if (inv_ptr->phases[i].isotopes[j].elt_name == inv_ptr->isotopes[k].elt_name && + inv_ptr->phases[i].isotopes[j].isotope_number == inv_ptr->isotopes[k].isotope_number) { + break; + } + } + if (k >= inv_ptr->count_isotopes) break; + column = col_phase_isotopes + i * inv_ptr->count_isotopes + k; +/* + * zero column if uncertainty is zero + */ + if (inv_ptr->phases[i].isotopes[j].ratio_uncertainty == 0) { + for (k = 0; k < count_rows; k++) { + array[k * max_column_count + column] = 0.0; + } + continue; + } + +/* + * optimization + */ + array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON / inv_ptr->phases[i].isotopes[j].ratio_uncertainty; +/* + * two inequalities to account for absolute value + */ + /* for phases constrained to precipitate */ + if (inv_ptr->phases[i].constraint == PRECIPITATE) { + array[count_rows * max_column_count + col_phases + i] = + inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = 1.0; + sprintf(token, "%s %s", + inv_ptr->phases[i].phase->name, + "iso pos"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + array[count_rows * max_column_count + col_phases + i] = + inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = -1.0; + sprintf(token, "%s %s", + inv_ptr->phases[i].phase->name, + "iso neg"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + /* for phases constrained to dissolve */ + } else if (inv_ptr->phases[i].constraint == DISSOLVE) { + array[count_rows * max_column_count + col_phases + i] = + -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = -1.0; + sprintf(token, "%s %s", + inv_ptr->phases[i].phase->name, + "iso pos"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + array[count_rows * max_column_count + col_phases + i] = + -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = 1.0; + sprintf(token, "%s %s", + inv_ptr->phases[i].phase->name, + "iso neg"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + /* Error if phase is not constrained*/ + } else { + sprintf(error_string, + "In isotope calculations, all phases containing isotopes must be" + " constrained.\nPhase %s is not constrained.\n", + inv_ptr->phases[i].phase->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int write_optimize_names(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, row; + char token[MAX_LENGTH]; + row = 0; +/* + * epsilons for analytical data + */ + for (j = 0; j < inv_ptr->count_elts; j++) { + for (i = 0; i < inv_ptr->count_solns; i++) { + sprintf(token,"%s %s %d","optimize", + inv_ptr->elts[j].master->elt->name, + inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * pH + */ + if (carbon > 0) { + for (i = 0; i < inv_ptr->count_solns; i++) { + sprintf(token,"%s %s %d","optimize", + "pH", + inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * water + */ + sprintf(token,"%s %s","optimize", "water"); + row_name[row] = string_hsave(token); + row++; +/* + * solution isotopes + */ + for (i = 0; i < inv_ptr->count_solns; i++) { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { + sprintf(token,"%s %d%s %d","optimize", + (int) inv_ptr->isotope_unknowns[j].isotope_number, + inv_ptr->isotope_unknowns[j].elt_name, + inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * phase isotopes + */ + + for (i = 0; i < inv_ptr->count_phases; i++) { + for (j = 0; j < inv_ptr->count_isotopes; j++) { + sprintf(token,"%s %s %d%s","optimize", + inv_ptr->phases[i].phase->name, + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name); + row_name[row] = string_hsave(token); + row++; + } + } + return OK; +} diff --git a/isotopes.cpp b/isotopes.cpp new file mode 100644 index 00000000..885b19bc --- /dev/null +++ b/isotopes.cpp @@ -0,0 +1,1540 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: isotopes.c 402 2005-07-25 23:26:07Z dlpark $"; + +static int calculate_value_init(struct calculate_value *calculate_value_ptr); +static int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); +static int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); +static int master_isotope_init(struct master_isotope *master_isotope_ptr); + +/* ---------------------------------------------------------------------- */ +int read_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species information for isotopes + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + + int j, l; + struct master_isotope *master_isotope_ptr, *master_isotope_ptr_major; + char token[MAX_LENGTH]; + struct element *elt_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "isotope", /* 0 */ + "total_is_major" /* 1 */ + }; + int count_opt_list = 2; + if (svnid == NULL) fprintf(stderr," "); + + master_isotope_ptr = NULL; + elt_ptr = NULL; +/* + * Read name followed by options + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* isotope */ + if (elt_ptr == NULL) { + sprintf(error_string, "The element of which this isotope is a minor isotope has not been defined, %s. ISOTOPES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + /* + * Save an isotope + */ + master_isotope_ptr = NULL; + j = copy_token(token, &next_char, &l); + master_isotope_ptr = master_isotope_store(token, TRUE); + master_isotope_ptr->elt = elt_ptr; + master_isotope_ptr->minor_isotope = TRUE; + master_isotope_ptr->total_is_major = FALSE; + /* + * Read units + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting units for isotopic values, %s. ISOTOPES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + master_isotope_ptr->units = string_hsave(token); + /* + * Read standard + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting isotope ratio of standard, %s. ISOTOPES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + sscanf(token,SCANFORMAT, &(master_isotope_ptr->standard)); + opt_save = OPTION_DEFAULT; + break; + case 1: /* total_is_major_isotope */ +#ifdef SKIP + if (elt_ptr == NULL) { + sprintf(error_string, "The element of which this isotope is a minor isotope has not been defined, %s. ISOTOPES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + master_isotope_ptr_major->total_is_major = get_true_false(next_char, TRUE); +#endif + sprintf(error_string, "Obsolete identifier. The total of the element must be the sum of all isotopes. ISOTOPES data block.\n%s", line); + warning_msg(error_string); + break; + case OPTION_DEFAULT: +/* + * Read and element name + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting an element name for isotope definition, %s. ISOTOPES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + elt_ptr = element_store(token); + master_isotope_ptr = master_isotope_store(token, TRUE); + master_isotope_ptr_major = master_isotope_ptr; + master_isotope_ptr->elt = elt_ptr; + master_isotope_ptr->minor_isotope = FALSE; + master_isotope_ptr->total_is_major = FALSE; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_calculate_values (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate calculate_value + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, length, line_length, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct calculate_value *calculate_value_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; +/* + * Read advection number (not currently used) + */ + n = -1; + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + calculate_value_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in CALCULATE_VALUE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPT_1; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read calculate_value name */ +/* + * Read calculate_value name + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting a name for calculate_value definition, %s. CALCULATE_VALUES data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + calculate_value_ptr = calculate_value_store(token, TRUE); + calculate_value_ptr->new_def = TRUE; + calculate_value_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); + if (calculate_value_ptr->commands == NULL) malloc_error(); + calculate_value_ptr->commands[0] = '\0'; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + opt_save = OPT_1; + break; + + case OPT_1: /* read command */ + length = strlen(calculate_value_ptr->commands); + line_length = strlen(line); + calculate_value_ptr->commands = (char *) PHRQ_realloc(calculate_value_ptr->commands, (size_t) (length + line_length + 2) * sizeof(char)); + if (calculate_value_ptr->commands == NULL) malloc_error(); + calculate_value_ptr->commands[length] = ';'; + calculate_value_ptr->commands[length + 1] = '\0'; + strcat((calculate_value_ptr->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* output_msg(OUTPUT_MESSAGE, "%s", calculate_value[0].commands); + */ return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_isotope_ratios (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads isotope_ratio info, ratios are calculated with + * Basic programs read in CALCULATE_VALUE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct isotope_ratio *isotope_ratio_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "no_options" /* 0 */ + }; + int count_opt_list = 0; +/* + * Read number (not currently used) + */ + n = -1; + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + isotope_ratio_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ISOTOPE_RATIOS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* read isotope_ratio name */ +/* + * Read isotope_ratio name + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting a name for isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_ratio_ptr = isotope_ratio_store(token, TRUE); + /* + * Read isotope + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting a name of isotope for an isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_ratio_ptr->isotope_name = string_hsave(token); + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_isotope_alphas (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads isotope_alpha info, ratios are calculated with + * Basic programs read in CALCULATE_VALUE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct isotope_alpha *isotope_alpha_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "no_options" /* 0 */ + }; + int count_opt_list = 0; +/* + * Read number (not currently used) + */ + n = -1; + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + isotope_alpha_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ISOTOPE_ALPHAS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* read isotope_alpha name */ +/* + * Read isotope_alpha name + */ + if (copy_token(token, &next_char, &l) == EMPTY) { + sprintf(error_string, "Expecting a name for isotope_alpha definition, %s. ISOTOPE_ALPHAS data block.", line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_alpha_ptr = isotope_alpha_store(token, TRUE); + isotope_alpha_ptr->name = string_hsave(token); + if (copy_token(token, &next_char, &l) != EMPTY) { + isotope_alpha_ptr->named_logk = string_hsave(token); + } + + + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int add_isotopes(struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + char *ptr; + struct master_isotope *master_isotope_ptr; + LDBLE total_moles; + /* + * zero out isotopes + */ + for (i = 0; i < count_master_isotope; i++) { + master_isotope[i]->moles = 0; + } + master_isotope_ptr = master_isotope_search("H"); + if (master_isotope_ptr != NULL) { + total_moles = total_h_x; + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); + } + master_isotope_ptr = master_isotope_search("O"); + if (master_isotope_ptr != NULL) { + total_moles = total_o_x; + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { + ptr=solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) continue; + if (master_isotope_ptr->minor_isotope == FALSE) { + total_moles = total(master_isotope_ptr->name); + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); + } + } + /* + * Set isotopes flag + */ + initial_solution_isotopes = FALSE; + for (i= 0; i < count_master_isotope; i++) { + if (master_isotope[i]->minor_isotope == TRUE && master_isotope[i]->moles > 0) { + initial_solution_isotopes = TRUE; + } + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int calculate_isotope_moles(struct element *elt_ptr, struct solution *solution_ptr, LDBLE total_moles) +/* ---------------------------------------------------------------------- */ +{ + int i, j, iter; + int count_isotopes, total_is_major; + char *ptr; + struct master_isotope *master_isotope_ptr, *master_isotope_ptr1; + struct master_isotope list[MAX_ELTS]; + LDBLE m_major, tot; +#ifdef SKIP + struct elt_list *iso_elt_list; + struct master *master_ptr; +#endif + /* + * Get total concentration of elt_ptr + */ + if (total_moles <= 0) { + sprintf(error_string, "Can not calculate molality of isotopes, molality of element is zero, %s", elt_ptr->name); + warning_msg(error_string); + return(ERROR); + } + m_major = total_moles; + /* + * Make a list of isotopes + */ + count_isotopes = 0; + total_is_major = FALSE; + master_isotope_ptr = master_isotope_search("H"); + if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) { + memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); + list[count_isotopes].ratio = 1.0; + if (list[count_isotopes].minor_isotope == FALSE) { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + master_isotope_ptr = master_isotope_search("O"); + if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) { + memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); + list[count_isotopes].ratio = 1.0; + if (list[count_isotopes].minor_isotope == FALSE) { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { + ptr=solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) continue; + if (master_isotope_ptr->elt != elt_ptr) continue; + memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); + if (list[count_isotopes].minor_isotope == FALSE) { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + /* + * Loop to calculate isotope molalities + */ + for (iter = 0; iter < itmax; iter++) { + tot = 0; + for (i = 0; i < count_isotopes; i++) { + if (list[i].minor_isotope == FALSE) { + list[i].moles = m_major; + tot += m_major; + continue; + } + if (strcmp_nocase(list[i].units, "permil") == 0) { + from_permil(&(list[i]), m_major); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pct") == 0) { + from_pct(&(list[i]), total_moles); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pmc") == 0) { + from_pct(&(list[i]), total_moles); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "tu") == 0) { + from_tu(&(list[i])); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pci/l") == 0) { + from_pcil(&(list[i])); + tot += list[i].moles; + continue; + } + sprintf(error_string, "Isotope units not recognized, %s",list[i].units); + input_error++; + error_msg(error_string, CONTINUE); + } + if (total_is_major == TRUE) break; + if (fabs(total_moles - tot) < convergence_tolerance*total_moles) { + break; + } else { + m_major = m_major*total_moles/tot; + } + } + if (iter >= itmax) { + error_msg("Failed to converge in CALCULATE_ISOTOPE_MOLES.", STOP); + } + /* + * Update master_isotope + */ + for (j = 0; j < count_master_isotope; j++) { + for (i = 0; i < count_isotopes; i++) { + if (list[i].name== master_isotope[j]->name) { + memcpy(master_isotope[j], &(list[i]), sizeof(struct master_isotope)); + } + } + } + /* + * Update solution + */ + master_isotope_ptr1 = master_isotope_search("H"); + if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) { + total_h_x = m_major; + } + master_isotope_ptr1 = master_isotope_search("O"); + if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) { + total_o_x = m_major; + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { + ptr=solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) continue; + if (master_isotope_ptr->elt != elt_ptr) continue; + solution_ptr->totals[i].moles = master_isotope_ptr->moles; + solution_ptr->totals[i].input_conc = master_isotope_ptr->moles; + } + +#ifdef SKIP + /* + * make elt list + */ + iso_elt_list = PHRQ_malloc((size_t) (count_isotopes + 1)*sizeof(struct elt_list)); + if (iso_elt_list == NULL) malloc_error(); + for (i = 0; i < count_isotopes; i++) { + master_ptr = master_bsearch(list[i].name); + if (master_ptr == NULL) { + sprintf(error_string, "Did not find element in CALCULATE_ISOTOPES, %s.", list[i].name); + error_msg(error_string, STOP); + } + iso_elt_list[i].elt = master_ptr->elt; + iso_elt_list[i].coef = list[i].moles; + } + iso_elt_list[i].elt = NULL; +#endif + return(OK); +} +/* ---------------------------------------------------------------------- */ +int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total) +/* ---------------------------------------------------------------------- */ +{ + LDBLE r; + + r = (master_isotope_ptr->ratio/1000. + 1.0)*master_isotope_ptr->standard; + master_isotope_ptr->moles = major_total * r; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int from_pct(struct master_isotope *master_isotope_ptr, LDBLE total_moles) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = master_isotope_ptr->ratio/100*master_isotope_ptr->standard*total_moles; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int from_tu(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = master_isotope_ptr->ratio*master_isotope_ptr->standard*mass_water_aq_x/gfw_water; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int from_pcil(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = master_isotope_ptr->ratio*master_isotope_ptr->standard*mass_water_aq_x/gfw_water; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_initial_solution_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + + if (pr.initial_isotopes == FALSE || pr.all == FALSE) return(OK); + if (state != INITIAL_SOLUTION) return(OK); + if (initial_solution_isotopes == FALSE) return(OK); +/* + * Print heading + */ + print_centered("Isotopes"); + output_msg(OUTPUT_MESSAGE,"%10s\t%12s\t%12s\t%12s\t%12s\n\n", "Isotope","Molality","Moles","Ratio", "Units"); + for (i = 0; i < count_master_isotope; i++) { + if (master_isotope[i]->minor_isotope == FALSE) { + print_isotope = FALSE; + for (j = 0; j < count_master_isotope; j++) { + if ((master_isotope[j]->elt == master_isotope[i]->elt) && + (master_isotope[j]->minor_isotope == TRUE) && + (master_isotope[j]->moles > 0)) { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) continue; + /* + * Print isotope values + */ + output_msg(OUTPUT_MESSAGE,"%10s\t%12.5e\t%12.5e\n", master_isotope[i]->name, (double) (master_isotope[i]->moles/mass_water_aq_x), (double) master_isotope[i]->moles); + for (j = 0; j < count_master_isotope; j++) { + if (i == j) continue; + if ((master_isotope[j]->elt == master_isotope[i]->elt) && + (master_isotope[j]->minor_isotope == TRUE)) { + output_msg(OUTPUT_MESSAGE,"%10s\t%12.5e\t%12.5e\t%12.5e\t%12s\n", master_isotope[j]->name, (double) (master_isotope[j]->moles/mass_water_aq_x), (double) master_isotope[j]->moles, (double) master_isotope[j]->ratio, master_isotope[j]->units); + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch isotope ratios relative to standards + */ + int i; + LDBLE iso; + struct isotope_ratio *isotope_ratio_ptr; + struct master_isotope *master_isotope_ptr; + + if (punch.in == FALSE || punch.isotopes == FALSE) return(OK); + if (punch.count_isotopes == 0) return(OK); + for (i = 0; i < punch.count_isotopes; i++) { + iso = MISSING; + if (state == INITIAL_SOLUTION) { + isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + if (isotope_ratio_ptr != NULL) { + master_isotope_ptr = master_isotope_search(isotope_ratio_ptr->isotope_name); + if (master_isotope_ptr != NULL && master_isotope_ptr->minor_isotope == TRUE) { + iso = master_isotope_ptr->ratio; + } + } + } else { + isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + if (isotope_ratio_ptr != NULL) { + iso = isotope_ratio_ptr->converted_ratio; + } + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("I_%s",punch.isotopes[i].name),"%12.4e\t", iso); + } else { + fpunchf(sformatf("I_%s",punch.isotopes[i].name),"%20.12e\t", iso); + } + + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch calculate values + */ + int i; + LDBLE result; + struct calculate_value *calculate_value_ptr; + + if (punch.in == FALSE || punch.calculate_values == FALSE) return(OK); + if (punch.count_calculate_values == 0) return(OK); + for (i = 0; i < punch.count_calculate_values; i++) { + result = MISSING; + calculate_value_ptr = calculate_value_search(punch.calculate_values[i].name); + if (calculate_value_ptr != NULL) { + result = calculate_value_ptr->value; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("V_%s",punch.calculate_values[i].name),"%12.4e\t", result); + } else { + fpunchf(sformatf("V_%s",punch.calculate_values[i].name),"%20.12e\t", result); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_isotope_ratios(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + struct master *master_ptr; + struct master_isotope *master_isotope_ptr; + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + + + if (pr.isotope_ratios == FALSE || pr.all == FALSE) return(OK); + if (state == INITIAL_SOLUTION) return(OK); +/* + * Print heading + */ + print_isotope = FALSE; + for (i = 0; i < count_master_isotope; i++) { + if (master_isotope[i]->minor_isotope == FALSE) continue; + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) continue; + if (master_ptr->total > 0 || master_ptr->s->moles > 0) { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) return(OK); + + print_centered("Isotope Ratios"); + output_msg(OUTPUT_MESSAGE,"%25s\t%12s\t%15s\n\n", "Isotope Ratio","Ratio","Input Units"); + + for (j = 0; j < count_isotope_ratio; j++) { + if (isotope_ratio[j]->ratio == MISSING) continue; + isotope_ratio_ptr = isotope_ratio[j]; + master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name); + /* + * Print isotope ratio + */ + strcpy(token, isotope_ratio[j]->name); + while(replace("_"," ",token) == TRUE); + output_msg(OUTPUT_MESSAGE," %-20s\t%12.5e\t%15.5g %-10s\n", token, (double) isotope_ratio[j]->ratio, (double) isotope_ratio[j]->converted_ratio, master_isotope_ptr->units); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_isotope_alphas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + struct master *master_ptr; + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + LDBLE log_alpha; + + if (pr.isotope_alphas == FALSE || pr.all == FALSE) return(OK); + if (state == INITIAL_SOLUTION) return(OK); +/* + * Print heading + */ + print_isotope = FALSE; + for (i = 0; i < count_master_isotope; i++) { + if (master_isotope[i]->minor_isotope == FALSE) continue; + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) continue; + if (master_ptr->total > 0 || master_ptr->s->moles > 0) { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) return(OK); + + print_centered("Isotope Alphas"); + output_msg(OUTPUT_MESSAGE,"%75s\n", "1000ln(Alpha)"); + output_msg(OUTPUT_MESSAGE,"%79s\n", "----------------------"); + output_msg(OUTPUT_MESSAGE,"%-37s%14s%14s%12.1f C\n\n", " Isotope Ratio", "Solution alpha", "Solution", (double) tc_x); + + for (j = 0; j < count_isotope_alpha; j++) { + if (isotope_alpha[j]->value == MISSING) continue; + isotope_alpha_ptr = isotope_alpha[j]; + /* + * Print isotope ratio + */ + strcpy(token, isotope_alpha[j]->name); + while(replace("_"," ",token) == TRUE); + if (isotope_alpha[j]->named_logk != NULL) { + if (isotope_alpha[j]->value <=0) { + log_alpha = -999.999; + } else { + log_alpha = 1000*log(isotope_alpha[j]->value); + } + output_msg(OUTPUT_MESSAGE,"%-37s%14.5g%14.5g%14.5g\n", token, (double) isotope_alpha[j]->value, (double) log_alpha, (double) (1000*calc_logk_n(isotope_alpha[j]->named_logk)*LOG_10)); + } else { + output_msg(OUTPUT_MESSAGE,"%-37s%14.5g%14.5g\n", token, (double) isotope_alpha[j]->value, (double) (1000*log(isotope_alpha[j]->value))); + } + + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ + int j; + struct calculate_value *calculate_value_ptr; + struct isotope_ratio *isotope_ratio_ptr; + struct isotope_alpha *isotope_alpha_ptr; + struct master_isotope *master_isotope_ptr; + char command[] = "run"; + + + /* + * initialize ratios as missing + */ + for (j = 0; j < count_calculate_value; j++) { + calculate_value[j]->calculated = FALSE; + calculate_value[j]->value = MISSING; + } + + for (j = 0; j < count_calculate_value; j++) { + calculate_value_ptr = calculate_value[j]; + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) { + if (basic_compile(calculate_value[j]->commands, &calculate_value[j]->linebase, &calculate_value[j]->varbase, &calculate_value[j]->loopbase) != 0) { + sprintf (error_string, "Fatal Basic error in CALCULATE_VALUES %s.", calculate_value[j]->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run(command, calculate_value[j]->linebase, calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) { + sprintf (error_string, "Fatal Basic error in calculate_value %s.", calculate_value[j]->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) { + sprintf(error_string, "Calculated value not SAVE'd for %s.", calculate_value[j]->name); + error_msg(error_string, STOP); + } else { + calculate_value[j]->calculated = TRUE; + calculate_value[j]->value = rate_moles; + } + } + for (j = 0; j < count_isotope_ratio; j++) { + isotope_ratio_ptr = isotope_ratio[j]; + master_isotope_ptr = master_isotope_search(isotope_ratio_ptr->isotope_name); + calculate_value_ptr = calculate_value_search(isotope_ratio_ptr->name); + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->value == MISSING) { + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + } else { + isotope_ratio_ptr->ratio = calculate_value_ptr->value; + isotope_ratio_ptr->converted_ratio = convert_isotope(master_isotope_ptr, calculate_value_ptr->value); + } + } + for (j = 0; j < count_isotope_alpha; j++) { + isotope_alpha_ptr = isotope_alpha[j]; + calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->value == MISSING) { + isotope_alpha_ptr->value = MISSING; + } else { + isotope_alpha_ptr->value = calculate_value_ptr->value; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio) +/* ---------------------------------------------------------------------- */ +{ + char *units; + units = master_isotope_ptr->units; + + if (strcmp_nocase(units, "permil") == 0) { + return( (ratio/master_isotope_ptr->standard - 1) * 1000); + } + if (strcmp_nocase(units, "pct") == 0) { + return(ratio/master_isotope_ptr->standard*100.); + } + if (strcmp_nocase(units, "pmc") == 0) { + return(ratio/master_isotope_ptr->standard*100.); + } + if (strcmp_nocase(units, "tu") == 0) { + return(ratio/master_isotope_ptr->standard); + } + if (strcmp_nocase(units, "pci/l") == 0) { + return(ratio/master_isotope_ptr->standard); + } + sprintf(error_string, "Did not recognize isotope units in convert_isotope, %s", units); + error_msg(error_string, STOP); + return (-99.0); +} +/* + * Utility routines for master_isotope + */ + +/* ---------------------------------------------------------------------- */ +struct master_isotope *master_isotope_store (char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for master_isotope. + * + * Pointer to a master_isotope structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old master_isotope structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old master_isotope structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "master_isotope". + * replace_if_found input, TRUE means reinitialize master_isotope structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to master_isotope structure "master_isotope" where "name" can be found. + */ + int n; + struct master_isotope *master_isotope_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + + item.key = name; + item.data = NULL; + found_item = hsearch_multi(master_isotope_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + return (master_isotope_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + master_isotope_init(master_isotope_ptr); + } else { + n = count_master_isotope++; + /* make sure there is space in s */ + if (count_master_isotope >= max_master_isotope) { + space ((void **) ((void *) &master_isotope), count_master_isotope, &max_master_isotope, sizeof(struct master_isotope *)); + } + /* Make new master_isotope structure */ + master_isotope[n] = master_isotope_alloc(); + master_isotope_ptr = master_isotope[n]; + } + /* set name and z in pointer in master_isotope structure */ + master_isotope_ptr->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = master_isotope_ptr->name; + item.data = (void *) master_isotope_ptr; + found_item = hsearch_multi(master_isotope_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in master_isotope_store."); + error_msg(error_string, CONTINUE); + } + + return (master_isotope_ptr); +} +/* ---------------------------------------------------------------------- */ +struct master_isotope *master_isotope_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a master_isotope structure, initializes + * arguments: void + * return: pointer to a master_isotope structure + */ +{ + struct master_isotope *master_isotope_ptr; + master_isotope_ptr=(struct master_isotope *) PHRQ_malloc(sizeof(struct master_isotope)); + if (master_isotope_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + master_isotope_init(master_isotope_ptr); + + return(master_isotope_ptr); +} +/* ---------------------------------------------------------------------- */ +static int master_isotope_init(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a master_isotope structure + */ +{ +/* + * set pointers in structure to NULL + */ + master_isotope_ptr->name=NULL; + master_isotope_ptr->units=NULL; + master_isotope_ptr->standard=0; + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct master_isotope *master_isotope_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for master_isotope. + * + * Arguments: + * name input, character string to be found in "master_isotope". + * + * Returns: + * pointer to master_isotope structure "master_isotope" where "name" can be found. + * or NULL if not found. + */ + struct master_isotope *master_isotope_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + item.key = name; + item.data = NULL; + found_item = hsearch_multi(master_isotope_hash_table, item, FIND); + + if (found_item != NULL) { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + return (master_isotope_ptr); + } + return(NULL); +} +/* + * Utility routines for calculate_value + */ + +/* ---------------------------------------------------------------------- */ +struct calculate_value *calculate_value_store (char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for calculate_value. + * + * Pointer to a calculate_value structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old calculate_value structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old calculate_value structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "calculate_value". + * replace_if_found input, TRUE means reinitialize calculate_value structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to calculate_value structure "calculate_value" where "name" can be found. + */ + int n; + struct calculate_value *calculate_value_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(calculate_value_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + return (calculate_value_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + calculate_value_free(calculate_value_ptr); + calculate_value_init(calculate_value_ptr); + } else { + n = count_calculate_value++; + /* make sure there is space in s */ + if (count_calculate_value >= max_calculate_value) { + space ((void **) ((void *) &calculate_value), count_calculate_value, &max_calculate_value, sizeof(struct calculate_value *)); + } + /* Make new calculate_value structure */ + calculate_value[n] = calculate_value_alloc(); + calculate_value_ptr = calculate_value[n]; + } + /* set name and z in pointer in calculate_value structure */ + calculate_value_ptr->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) calculate_value_ptr; + found_item = hsearch_multi(calculate_value_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in calculate_value_store."); + error_msg(error_string, CONTINUE); + } + + return (calculate_value_ptr); +} +/* ---------------------------------------------------------------------- */ +struct calculate_value *calculate_value_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a calculate_value structure, initializes + * arguments: void + * return: pointer to a calculate_value structure + */ +{ + struct calculate_value *calculate_value_ptr; + calculate_value_ptr=(struct calculate_value *) PHRQ_malloc(sizeof(struct calculate_value)); + if (calculate_value_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + calculate_value_init(calculate_value_ptr); + + return(calculate_value_ptr); +} +/* ---------------------------------------------------------------------- */ +static int calculate_value_init(struct calculate_value *calculate_value_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a calculate_value structure + */ +{ +/* + * set pointers in structure to NULL + */ + calculate_value_ptr->name=NULL; + calculate_value_ptr->commands=NULL; + calculate_value_ptr->linebase=NULL; + calculate_value_ptr->varbase=NULL; + calculate_value_ptr->loopbase=NULL; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct calculate_value *calculate_value_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for calculate_value. + * + * Arguments: + * name input, character string to be found in "calculate_value". + * + * Returns: + * pointer to calculate_value structure "calculate_value" where "name" can be found. + * or NULL if not found. + */ + struct calculate_value *calculate_value_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(calculate_value_hash_table, item, FIND); + + if (found_item != NULL) { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + return (calculate_value_ptr); + } + return(NULL); +} +/* ---------------------------------------------------------------------- */ +int calculate_value_free(struct calculate_value *calculate_value_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within calculate_value[i], does not free calculate_value structure + * Input: i, number of calculate_value + * Return: OK + */ + char cmd[] = "new; quit"; + + if (calculate_value_ptr == NULL) return(ERROR); + calculate_value_ptr->commands = (char *) free_check_null(calculate_value_ptr->commands); + basic_run(cmd, calculate_value_ptr->linebase, calculate_value_ptr->varbase, calculate_value_ptr->loopbase); + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + return(OK); +} +/* + * Utility routines for isotope_ratio + */ + +/* ---------------------------------------------------------------------- */ +struct isotope_ratio *isotope_ratio_store (char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_ratio. + * + * Pointer to a isotope_ratio structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old isotope_ratio structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old isotope_ratio structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "isotope_ratio". + * replace_if_found input, TRUE means reinitialize isotope_ratio structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. + */ + int n; + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + return (isotope_ratio_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + isotope_ratio_init(isotope_ratio_ptr); + } else { + n = count_isotope_ratio++; + /* make sure there is space in s */ + if (count_isotope_ratio >= max_isotope_ratio) { + space ((void **) ((void *) &isotope_ratio), count_isotope_ratio, &max_isotope_ratio, sizeof(struct isotope_ratio *)); + } + /* Make new isotope_ratio structure */ + isotope_ratio[n] = isotope_ratio_alloc(); + isotope_ratio_ptr = isotope_ratio[n]; + } + /* set name and z in pointer in isotope_ratio structure */ + isotope_ratio_ptr->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) isotope_ratio_ptr; + found_item = hsearch_multi(isotope_ratio_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in isotope_ratio_store."); + error_msg(error_string, CONTINUE); + } + + return (isotope_ratio_ptr); +} +/* ---------------------------------------------------------------------- */ +struct isotope_ratio *isotope_ratio_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a isotope_ratio structure, initializes + * arguments: void + * return: pointer to a isotope_ratio structure + */ +{ + struct isotope_ratio *isotope_ratio_ptr; + isotope_ratio_ptr=(struct isotope_ratio *) PHRQ_malloc(sizeof(struct isotope_ratio)); + if (isotope_ratio_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + isotope_ratio_init(isotope_ratio_ptr); + + return(isotope_ratio_ptr); +} +/* ---------------------------------------------------------------------- */ +static int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a isotope_ratio structure + */ +{ +/* + * set pointers in structure to NULL + */ + isotope_ratio_ptr->name=NULL; + isotope_ratio_ptr->isotope_name=NULL; + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct isotope_ratio *isotope_ratio_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_ratio. + * + * Arguments: + * name input, character string to be found in "isotope_ratio". + * + * Returns: + * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. + * or NULL if not found. + */ + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); + + if (found_item != NULL) { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + return (isotope_ratio_ptr); + } + return(NULL); +} +/* + * Utility routines for isotope_alpha + */ + +/* ---------------------------------------------------------------------- */ +struct isotope_alpha *isotope_alpha_store (char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_alpha. + * + * Pointer to a isotope_alpha structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old isotope_alpha structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old isotope_alpha structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "isotope_alpha". + * replace_if_found input, TRUE means reinitialize isotope_alpha structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. + */ + int n; + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + return (isotope_alpha_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + isotope_alpha_init(isotope_alpha_ptr); + } else { + n = count_isotope_alpha++; + /* make sure there is space in s */ + if (count_isotope_alpha >= max_isotope_alpha) { + space ((void **) ((void *) &isotope_alpha), count_isotope_alpha, &max_isotope_alpha, sizeof(struct isotope_alpha *)); + } + /* Make new isotope_alpha structure */ + isotope_alpha[n] = isotope_alpha_alloc(); + isotope_alpha_ptr = isotope_alpha[n]; + } + /* set name and z in pointer in isotope_alpha structure */ + isotope_alpha_ptr->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) isotope_alpha_ptr; + found_item = hsearch_multi(isotope_alpha_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in isotope_alpha_store."); + error_msg(error_string, CONTINUE); + } + + return (isotope_alpha_ptr); +} +/* ---------------------------------------------------------------------- */ +struct isotope_alpha *isotope_alpha_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a isotope_alpha structure, initializes + * arguments: void + * return: pointer to a isotope_alpha structure + */ +{ + struct isotope_alpha *isotope_alpha_ptr; + isotope_alpha_ptr=(struct isotope_alpha *) PHRQ_malloc(sizeof(struct isotope_alpha)); + if (isotope_alpha_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + isotope_alpha_init(isotope_alpha_ptr); + + return(isotope_alpha_ptr); +} +/* ---------------------------------------------------------------------- */ +static int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a isotope_alpha structure + */ +{ +/* + * set pointers in structure to NULL + */ + isotope_alpha_ptr->name=NULL; + isotope_alpha_ptr->named_logk=NULL; + isotope_alpha_ptr->value = MISSING; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct isotope_alpha *isotope_alpha_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_alpha. + * + * Arguments: + * name input, character string to be found in "isotope_alpha". + * + * Returns: + * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. + * or NULL if not found. + */ + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); + + if (found_item != NULL) { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + return (isotope_alpha_ptr); + } + return(NULL); +} diff --git a/kinetics.cpp b/kinetics.cpp new file mode 100644 index 00000000..0f5c751a --- /dev/null +++ b/kinetics.cpp @@ -0,0 +1,2288 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +#include "sundialstypes.h" /* definitions of types realtype and */ + /* integertype, and the constant FALSE */ +#include "cvode.h" /* prototypes for CVodeMalloc, CVode, and */ + /* CVodeFree, constants OPT_SIZE, BDF, NEWTON, */ + /* SV, SUCCESS, NST,NFE,NSETUPS, NNI, NCFN, NETF */ +#include "cvdense.h" /* prototype for CVDense, constant DENSE_NJE */ +#include "nvector_serial.h" /* definitions of type N_Vector and macro */ + /* NV_Ith_S, prototypes for N_VNew, N_VFree */ +#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM*/ +#define KINETICS_EXTERNAL extern +#include "kinetics.h" +/* These macros are defined in order to write code which exactly matches + the mathematical problem description given above. + + Ith(v,i) references the ith component of the vector v, where i is in + the range [1..NEQ] and NEQ is defined below. The Ith macro is defined + using the N_VIth macro in nvector.h. N_VIth numbers the components of + a vector starting from 0. + + IJth(A,i,j) references the (i,j)th element of the dense matrix A, where + i and j are in the range [1..NEQ]. The IJth macro is defined using the + DENSE_ELEM macro in dense.h. DENSE_ELEM numbers rows and columns of a + dense matrix starting from 0. */ + +#define Ith(v,i) NV_Ith_S(v,i-1) /* Ith numbers components 1..NEQ */ +#define IJth(A,i,j) DENSE_ELEM(A,i-1,j-1) /* IJth numbers rows,cols 1..NEQ */ + +static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); + +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + +static char const svnid[] = "$Id: kinetics.c 738 2006-01-26 17:22:32Z dlpark $"; +static int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); +static int calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step); +static int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction); +static int set_reaction(int i, int use_mix, int use_kinetics); +static int set_transport(int i, int use_mix, int use_kinetics, int nsaver); +static int store_get_equi_reactants(int k, int kin_end); + +#define MAX_DIVIDE 2 +#define KINETICS_TOL 1e-8; + +LDBLE *m_original; +LDBLE *m_temp; + +extern LDBLE min_value; +extern int count_total_steps; + +/* ---------------------------------------------------------------------- */ +int calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * determine rates and + * a list of elements and amounts in + * the reaction. + */ + int i, j, return_value; + LDBLE coef; +/* char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; + */ char command[] = "run"; + struct rate *rate_ptr; +/* LDBLE t1, t2; */ + if (svnid == NULL) fprintf(stderr," "); +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + return_value = OK; + count_elts = 0; + paren_count = 0; + + rate_time = time_step; + +/* t1 = clock(); */ + for (i=0; i < kinetics_ptr->count_comps; i++) { + coef = 0.0; +/* + * Send command to basic interpreter + */ + rate_ptr = rate_search (kinetics_ptr->comps[i].rate_name, &j); + if (rate_ptr == NULL) { + sprintf(error_string,"Rate not found for %s",kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } else { + rate_moles = NAN; + rate_m = kinetics_ptr->comps[i].m; + rate_m0 = kinetics_ptr->comps[i].m0; + rate_p = kinetics_ptr->comps[i].d_params; + count_rate_p = kinetics_ptr->comps[i].count_d_params; + if (rate_ptr->new_def == TRUE) { + if (basic_compile(rates[j].commands, &rates[j].linebase, &rates[j].varbase, &rates[j].loopbase) != 0) { + sprintf (error_string, "Fatal Basic error in rate %s.",kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + + rate_ptr->new_def = FALSE; + } + if (basic_run(command, rates[j].linebase, rates[j].varbase, rates[j].loopbase) != 0) { + sprintf (error_string, "Fatal Basic error in rate %s.",kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) { + sprintf(error_string, "Moles of reaction not SAVE'd for %s.",kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } else { + + coef = rate_moles; + } + } +/* + * Accumulate moles of reaction for component + */ + kinetics_ptr->comps[i].moles += coef; + if (coef == 0.0) continue; + } +/* t2=clock(); + printf("secs in reac %e, t2 %e\n", t2-t1, t1); + */ + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * using extrapolated values, which were + * stored in moles in run_kinetics + */ + int i, j, k; + LDBLE coef; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; + struct master *master_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + kinetics_ptr->totals = (struct elt_list *) free_check_null(kinetics_ptr->totals); + count_elts = 0; + paren_count = 0; + for (i=0; i < kinetics_ptr->count_comps; i++) { + if (kinetics_ptr->comps[i].moles > m_temp[i]) { + kinetics_ptr->comps[i].moles = m_temp[i]; + kinetics_ptr->comps[i].m = 0; + } + coef = kinetics_ptr->comps[i].moles; + if (coef == 0.0) continue; +/* + * Reactant is a pure phase, copy formula into token + */ + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { + phase_ptr = NULL; + strcpy(token, kinetics_ptr->comps[i].list[j].name); + phase_ptr = phase_bsearch(token, &k, FALSE); + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, coef * kinetics_ptr->comps[i].list[j].coef); + } else { + ptr = kinetics_ptr->comps[i].list[j].name; + get_elts_in_species (&ptr, coef * kinetics_ptr->comps[i].list[j].coef); + } + } +#ifdef SKIP + phase_ptr = NULL; + if (kinetics_ptr->comps[i].count_list == 1) { + strcpy(token, kinetics_ptr->comps[i].list[0].name); + phase_ptr = phase_bsearch(token, &j, FALSE); + } + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, coef * kinetics_ptr->comps[i].list[0].coef); + } else { + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { + ptr = kinetics_ptr->comps[i].list[j].name; + get_elts_in_species (&ptr, coef * kinetics_ptr->comps[i].list[j].coef); + } + } +#endif + if (use.exchange_ptr != NULL && use.exchange_ptr->related_rate == TRUE) { + for (j = 0; j < use.exchange_ptr->count_comps; j++) { + if (use.exchange_ptr->comps[j].rate_name != NULL) { + if (strcmp_nocase(kinetics_ptr->comps[i].rate_name, use.exchange_ptr->comps[j].rate_name) == 0) { + /* found kinetics component */ + add_elt_list(use.exchange_ptr->comps[j].formula_totals, -coef * use.exchange_ptr->comps[j].phase_proportion); + } + } + } + } + if (use.surface_ptr != NULL && use.surface_ptr->related_rate == TRUE) { + for (j = 0; j < use.surface_ptr->count_comps; j++) { + if (use.surface_ptr->comps[j].rate_name != NULL) { + if (strcmp_nocase(kinetics_ptr->comps[i].rate_name, use.surface_ptr->comps[j].rate_name) == 0) { + /* found kinetics component */ + ptr = use.surface_ptr->comps[j].formula; +/* Surface = 0 when m becomes low ... + */ + if (0.9 * use.surface_ptr->comps[j].phase_proportion * (kinetics_ptr->comps[i].m) < MIN_RELATED_SURFACE) { + master_ptr = master_bsearch(ptr); + master_ptr->total = 0.0; + } else { + get_elts_in_species (&ptr, -coef * use.surface_ptr->comps[j].phase_proportion); + } + } + } + } + } + } + kinetics_ptr->totals = elt_list_save(); + /* + output_msg(OUTPUT_MESSAGE, "Calc_final_kinetic_reaction \n"); + elt_list_print(kinetics_ptr->totals); + */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Runge-Kutta-Fehlberg method; 6 evaluations of the derivative + * give O(h^5) global error and error estimate + * calc_kinetic_reaction(.., ..) calculates moles of intermediate derivatives; + * these are calc'd for the whole step h. + * calc_final_kinetic reaction(..) translates moles to PHREEQC reaction. + */ + int j, k, m, save_old; + int bad, step_bad, step_ok; + int n_reactions; + LDBLE h, h_old, h_sum; + LDBLE *rk_moles; + LDBLE error, error_max, safety, moles_max, moles_reduction; + struct kinetics *kinetics_ptr; + int equal_rate, zero_rate; + + struct pp_assemblage *pp_assemblage_save = NULL; + struct s_s_assemblage *s_s_assemblage_save = NULL; + +#ifdef SKIP + struct gas_phase *gas_phase_save = NULL; + struct solution *solution_save = NULL; + struct exchange *exchange_save = NULL; + struct surface *surface_save = NULL; +#endif + + static LDBLE b31 = 3./40., b32 = 9./40., + b51 = -11./54., b53 = -70./27., b54 = 35./27., + b61 = 1631./55296., b62 = 175./512., b63 = 575./13824., b64 = 44275./110592., b65 = 253./4096., + c1 = 37./378., c3 = 250./621., c4 = 125./594., c6 = 512./1771., + dc5 = -277./14336.; + LDBLE dc1 = c1 - 2825./27648., dc3 = c3 - 18575./48384., + dc4 = c4 - 13525./55296., dc6 = c6 - 0.25; +/* + * Save kinetics i and solution i, if necessary + */ + save_old = -2 - (count_cells + 1); + kinetics_duplicate(i, save_old); + if (nsaver != i) { + solution_duplicate(i, save_old); + } + +/* + * Malloc some space + */ + if (kinetics_bsearch(i, &m) == NULL) return(OK); + n_reactions = kinetics[m].count_comps; + rk_moles = (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); + if (rk_moles == NULL) malloc_error(); + + /*if (use_mix != NOMIX) last_model.force_prep = TRUE;*/ + set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); + run_reactions_iterations += iterations; + saver(); + + if (state == TRANSPORT || state == PHAST) { + set_transport(i, NOMIX, TRUE, i); + } else if (state == ADVECTION) { + set_advection(i, NOMIX, TRUE, i); + } else if (state == REACTION) { + set_reaction(i, NOMIX, TRUE); + } + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_save == NULL) malloc_error(); + } + if (use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); + if (s_s_assemblage_save == NULL) malloc_error(); + } + + kinetics_ptr = kinetics_bsearch(i, &m); + + step_bad = step_ok = 0; + bad = FALSE; + h_sum = 0.; + h = h_old = kin_time; + moles_max = 0.1; + moles_reduction = 1.0; + safety = 0.7; + if (kinetics_ptr->rk < 1) { + kinetics_ptr->rk = 1; + } else if (kinetics_ptr->rk > 3 && kinetics_ptr->rk < 6) { + kinetics_ptr->rk = 6; + } else if (kinetics_ptr->rk > 6) { + kinetics_ptr->rk = 6; + } + if (kinetics_ptr->rk == 6) equal_rate = FALSE; else equal_rate = TRUE; +/* + * if step_divide > 1, initial timestep is divided + * if < 1, step_divide indicates maximal reaction... + */ + if (kinetics_ptr->step_divide > 1.0) { + h = h_old = kin_time / kinetics_ptr->step_divide; + equal_rate = FALSE; + } else if (kinetics_ptr->step_divide < 1.0) { + moles_max = kinetics_ptr->step_divide; + } + + rate_sim_time = rate_sim_time_start + h_sum; + + status(0, NULL); + while (h_sum < kin_time) { + + if (step_bad > kinetics_ptr->bad_step_max) { + sprintf(error_string,"Bad RK steps > %d. Please decrease (time)step or increase -bad_step_max.", + kinetics_ptr->bad_step_max); + error_msg(error_string, STOP); + } + + MOLES_TOO_LARGE: + if (moles_reduction > 1.0) { + h_old = h; + h = safety * h / (1.0 + moles_reduction); + moles_reduction = 1.0; + equal_rate = FALSE; + bad = TRUE; + } +/* + * find k1 + */ + if (bad == TRUE) { + for (j=0; j < n_reactions; j++) { + rk_moles[j] *= (h / h_old); + kinetics_ptr->comps[j].moles = rk_moles[j] * 0.2; + kinetics_ptr->comps[j].m = m_temp[j]; + } + bad = FALSE; + } else { +/* + * define pointers for calc_kinetic_, they are lost after saver()... + */ + if (state == TRANSPORT || state == PHAST) { + set_transport(i, NOMIX, TRUE, i); + } else if (state == ADVECTION) { + set_advection(i, NOMIX, TRUE, i); + } else if (state == REACTION) { + set_reaction(i, NOMIX, TRUE); + } + /* + * Moles of minerals and solid solutions may change to make positive + * concentrations. Reactions may take out more than is present in + * solution. + */ + if (pp_assemblage_save != NULL) { + pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); + } + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = 0.; + m_temp[j] = kinetics_ptr->comps[j].m; + } + + rate_sim_time = rate_sim_time_start + h_sum; + calc_kinetic_reaction(kinetics_ptr, h); + + /* store k1 in rk_moles ... */ + for (j=0; j < n_reactions; j++) { + if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { + moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k2 ... */ + rk_moles[j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles *= 0.2; + } + if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; + } +/* + * Quit rk with rk = 1 and equal rates ... + */ + if (kinetics_ptr->rk == 1 && equal_rate) { + zero_rate = TRUE; + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = rk_moles[j]; + if (fabs (kinetics_ptr->comps[j].moles) > MIN_TOTAL) zero_rate = FALSE; + } + + if (zero_rate == FALSE) { + calc_final_kinetic_reaction(kinetics_ptr); + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + calc_kinetic_reaction(kinetics_ptr, h); + for (j=0; j < n_reactions; j++) { + if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { + equal_rate = FALSE; + break; + } + } + } + if (zero_rate || equal_rate) { + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + } + goto EQUAL_RATE_OUT; + } else { + kinetics_ptr->rk = 3; + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = 0.2 * rk_moles[j]; + } + } + } +/* + * Continue with rk ... + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + +/* + * find k2 + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.2 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + + /* store k2 in rk_moles */ + k = n_reactions; + for (j=0; j < n_reactions; j++) { + if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { + moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k3 */ + rk_moles[k+j] = kinetics_ptr->comps[j].moles; + + kinetics_ptr->comps[j].moles = b31 * rk_moles[j] + + b32 * rk_moles[k+j]; +/* + * check for equal_rate ... + */ + if (equal_rate && fabs( rk_moles[j] - rk_moles[k + j]) > kinetics_ptr->comps[j].tol) { + equal_rate = FALSE; + } + } + if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 2 and equal rates ... + */ + if (kinetics_ptr->rk == 2 && equal_rate) { + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] + 0.7 * rk_moles[k + j]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j=0; j < n_reactions; j++) { + if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { + equal_rate = FALSE; + break; + } + } + if (equal_rate) kinetics_ptr->rk = 1; + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k3 + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.3 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + + /* store k3 in rk_moles */ + k = 2 * n_reactions; + for (j=0; j < n_reactions; j++) { + if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { + moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k4 ... */ + rk_moles[k+j] = kinetics_ptr->comps[j].moles; + + kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] + - 0.9 * rk_moles[ n_reactions + j ] + + 1.2 * rk_moles[k+j]; +/* + * check for equal_rate ... + */ + if (equal_rate && fabs ( rk_moles[j] - rk_moles[k+j]) > kinetics_ptr->comps[j].tol) + equal_rate = FALSE; + } + if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 3 and equal rates ... + */ + if (kinetics_ptr->rk == 3 && equal_rate) { + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = 0.5 * rk_moles[j] + - 1.5 * rk_moles[n_reactions + j] + + 2 * rk_moles[k + j]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j=0; j < n_reactions; j++) { + if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { + equal_rate = FALSE; + break; + } + } + if (equal_rate) kinetics_ptr->rk = 1; + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k4 + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.6 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + + /* store k4 in rk_moles */ + k = 3 * n_reactions; + for (j=0; j < n_reactions; j++) { + if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { + moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + + /* define reaction for calculating k5 */ + rk_moles[k+j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = b51 * rk_moles[j] + + 2.5 * rk_moles[ n_reactions + j ] + + b53 * rk_moles[ 2*n_reactions + j ] + + b54 * rk_moles[ k + j ]; + } + if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k5 + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + + /* store k5 in rk_moles */ + k = 4 * n_reactions; + for (j=0; j < n_reactions; j++) { + if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { + moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + + /* define reaction for calculating k6 */ + rk_moles[k+j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = b61 * rk_moles[j] + + b62 * rk_moles[ n_reactions + j ] + + b63 * rk_moles[ 2*n_reactions + j ] + + b64 * rk_moles[ 3*n_reactions + j ] + + b65 * rk_moles[ k + j ]; + } + if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k6 + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.875 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + + /* store k6 in rk_moles */ + k = 5 * n_reactions; + for (j=0; j < n_reactions; j++) { + rk_moles[k+j] = kinetics_ptr->comps[j].moles; + } + +/* + * Evaluate error + */ + error_max = 0.; + for (j=0; j < n_reactions; j++) { + error = fabs ( dc1 * rk_moles[j] + + dc3 * rk_moles[ 2*n_reactions + j ] + + dc4 * rk_moles[ 3*n_reactions + j ] + + dc5 * rk_moles[ 4*n_reactions + j ] + + dc6 * rk_moles[ 5*n_reactions + j ] ); + + /* tol is in moles/l */ + error /= kinetics_ptr->comps[j].tol; + if (error > error_max) error_max = error; + } + +/* + * repeat with smaller step + */ +/* printf("timest %g ; error_max %g\n", h, error_max); */ + if (error_max > 1) { + h_old = h; + if (step_ok == 0) + h = h * safety / error_max; + else h = h * safety * pow(error_max, -0.25); + bad = TRUE; + step_bad ++; + } else { +/* + * OK, calculate result + */ + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = c1 * rk_moles[j] + + c3 * rk_moles[ 2*n_reactions + j ] + + c4 * rk_moles[ 3*n_reactions + j ] + + c6 * rk_moles[ 5*n_reactions + j ]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j=0; j < n_reactions; j++) { + kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j=0; j < n_reactions; j++) { + if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { + equal_rate = FALSE; + break; + } + } + if (equal_rate && kinetics_ptr->rk < 6) kinetics_ptr->rk = 1; + + saver(); + + step_ok ++; + h_sum += h; + /* Free space */ + + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + } +/* + * and increase step size ... + */ + if (h_sum < kin_time) { + if (error_max > 0.000577) { + h = h * safety * pow(error_max, -0.2); + } else { + h *= 4; + } + if (h > (kin_time - h_sum)) h = (kin_time - h_sum); + } + } +#if !defined(PHREEQCI_GUI) +#ifndef PHREEQ98 + if (pr.status == TRUE && status_on == TRUE) { + char str[MAX_LENGTH]; + backspace_screen(37); + sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, step_ok, (int) (100*h_sum/kin_time)); + output_msg(OUTPUT_SCREEN, "%-37s", str); + } +#endif +#endif + } + + EQUAL_RATE_OUT: + +/* + * Run one more time to get distribution of species + */ + if (state >= REACTION || nsaver != i) { + set_and_run_wrapper(i, NOMIX, FALSE, nsaver, 0.); + run_reactions_iterations += iterations; + } + /* reset for printing */ + if (use_mix == DISP) { + use.mix_ptr = &mix[count_mix - count_cells + i - 1]; + use.mix_in = TRUE; + use.n_mix_user = i; + } else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) { + use.mix_ptr = mix_search (i, &use.n_mix, FALSE); + if (use.mix_ptr != NULL) { + use.mix_in = TRUE; + use.n_mix_user = i; + } + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) { + solution_duplicate(save_old, i); + } + rk_moles = (LDBLE *) free_check_null(rk_moles); + +#ifdef SKIP + if (state != TRANSPORT) { +#ifdef DOS + output_msg(OUTPUT_SCREEN, "\n"); +#else + output_msg(OUTPUT_SCREEN, "\n%-80s", " "); +#endif + } +#endif + rate_sim_time = rate_sim_time_start + kin_time; + use.kinetics_in = TRUE; + + /* Free space */ + + if (pp_assemblage_save != NULL) { + pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ + int j, converge, max_try; + int old_diag, old_itmax; + LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; + LDBLE small_pe_step, small_step; + struct pp_assemblage *pp_assemblage_save = NULL; + struct s_s_assemblage *s_s_assemblage_save = NULL; + struct kinetics *kinetics_save = NULL; + + /* 0 -- normal */ + /* 1 -- try smaller step size, more iterations */ + /* 2 -- try diagonal scaling */ + /* 3 -- try smaller tolerance */ + /* 4 -- try alternate scaling */ + small_pe_step = 5.; + small_step = 10.; + converge = FALSE; + + old_diag = diagonal_scale; + old_itmax = itmax; + old_tol = ineq_tol; + old_step = step_size; + old_pe = pe_step_size; + old_min_value = min_value; + old_pp_column_scale = pp_column_scale; + + if (state == TRANSPORT || state == PHAST) { + set_transport(i, use_mix, use_kinetics, i); + } else if (state == ADVECTION) { + set_advection(i, use_mix, use_kinetics, i); + } else if (state == REACTION) { + set_reaction(i, use_mix, use_kinetics); + } + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_save == NULL) malloc_error(); + pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); + } + if (use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); + if (s_s_assemblage_save == NULL) malloc_error(); + s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); + } + if (use.kinetics_ptr != NULL) { + kinetics_save = (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); + if (kinetics_save == NULL) malloc_error(); + kinetics_copy(use.kinetics_ptr, kinetics_save, use.kinetics_ptr->n_user); + } + + if (pitzer_model == TRUE) { + diagonal_scale = TRUE; + always_full_pitzer = FALSE; + max_try = 2; + } else { + max_try = 11; + } + for (j = 0; j < max_try; j++) { + if (j == 1) { + always_full_pitzer = TRUE; + if (pe_step_size <= small_pe_step && step_size <= small_step) continue; + itmax *= 2; + step_size = small_step; + pe_step_size = small_pe_step; + sprintf(error_string, "Trying smaller step size, pe step size %g, %g ... \n", (double) step_size, (double) pe_step_size); + warning_msg(error_string); + } else if (j == 2) { + itmax *= 2; + if (diagonal_scale == TRUE) { + diagonal_scale = FALSE; + } else { + diagonal_scale = TRUE; + } + sprintf(error_string, "Trying diagonal scaling ...\n"); + warning_msg(error_string); + } else if (j == 3) { + itmax *= 2; + ineq_tol /= 10.; + sprintf(error_string, "Trying reduced tolerance %g ...\n", (double) ineq_tol); + warning_msg(error_string); + } else if (j == 4) { + itmax *= 2; + ineq_tol *= 10.; + sprintf(error_string, "Trying increased tolerance %g ...\n", (double) ineq_tol); + warning_msg(error_string); + } else if (j == 5) { + itmax *= 2; + if (diagonal_scale == TRUE) { + diagonal_scale = FALSE; + } else { + diagonal_scale = TRUE; + } + ineq_tol /= 10.; + sprintf(error_string, "Trying diagonal scaling and reduced tolerance %g ...\n", (double) ineq_tol); + warning_msg(error_string); + } else if (j == 6) { + itmax *= 2; + pp_column_scale = 1e-10; + sprintf(error_string, "Trying scaling pure_phase columns %g ...\n", (double) pp_column_scale); + warning_msg(error_string); + } else if (j == 7) { + itmax *= 2; + pp_column_scale = 1e-10; + if (diagonal_scale == TRUE) { + diagonal_scale = FALSE; + } else { + diagonal_scale = TRUE; + } + sprintf(error_string, "Trying scaling pure_phase columns and diagonal scale %g ...\n", (double) pp_column_scale); + warning_msg(error_string); + } else if (j == 8) { + itmax *= 2; + min_value *= 10; + sprintf(error_string, "Trying increased scaling %g ...\n", (double) min_value); + warning_msg(error_string); + } else if (j == 9) { + aqueous_only = 5; + sprintf(error_string, "Skipping optimize equations for first %d iterations ...\n", aqueous_only); + warning_msg(error_string); + } else if (j == 10) { + negative_concentrations = TRUE; + sprintf(error_string, "Adding inequality to make concentrations greater than zero.\n"); + warning_msg(error_string); + } + if (j > 0) { + if (pp_assemblage_save != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); + } + if (kinetics_save != NULL) { + kinetics_free(use.kinetics_ptr); + kinetics_copy(kinetics_save, use.kinetics_ptr, kinetics_save->n_user); + } + } + + converge = set_and_run(i, use_mix, use_kinetics, nsaver, step_fraction); + /* reset values */ + diagonal_scale = old_diag; + itmax = old_itmax; + ineq_tol = old_tol; + step_size = old_step; + pe_step_size = old_pe; + min_value = old_min_value; + pp_column_scale = old_pp_column_scale; + aqueous_only = 0; + negative_concentrations = FALSE; + if (converge == TRUE) { + break; + } else if (converge == MASS_BALANCE) { + break; + } + warning_msg("Numerical method failed with this set of convergence parameters.\n"); + } + if (converge == FALSE && use.kinetics_ptr != NULL && use.kinetics_ptr->use_cvode == TRUE) { + sprintf(error_string, "Numerical method failed on all parameter combinations, retrying integration"); + /*output_msg(OUTPUT_MESSAGE, "Numerical method failed on all parameter combinations, retrying integration\n"); */ + warning_msg(error_string); + converge = MASS_BALANCE; + } + if (converge == FALSE) { +/* + * write to error.inp what failed to converge. + */ + if( output_open(OUTPUT_DUMP, "error.inp") != OK) { + sprintf(error_string, "Can't open file, %s.", "error.inp"); + error_msg(error_string, CONTINUE); + input_error++; + } else { + if (use.irrev_in == TRUE) { + dump_reaction(use.n_mix_user); + } + if (use.kinetics_ptr != NULL) { + dump_kinetics(use.kinetics_ptr->n_user); + } + output_msg(OUTPUT_DUMP, "END\n"); + if (use.solution_ptr != NULL) { + dump_solution(use.n_solution_user); + } else if (use.mix_ptr != NULL) { + dump_mix(use.n_mix_user); + } + if (use.pp_assemblage_in == TRUE) { + dump_pp_assemblage(use.n_pp_assemblage_user); + } + if (use.exchange_in == TRUE) { + dump_exchange(use.n_exchange_user); + } + if (use.surface_in == TRUE) { + dump_surface(use.n_surface_user); + } + if (use.gas_phase_in == TRUE) { + dump_gas_phase(use.n_gas_phase_user); + } + if (use.s_s_assemblage_in == TRUE) { + dump_s_s_assemblage(use.n_s_s_assemblage_user); + } + output_msg(OUTPUT_DUMP, "END\n"); + } + /* if (state == TRANSPORT && dump_modulus == 0) dump(); */ + check_residuals(); + pr.all = TRUE; + pr.gas_phase = use.gas_phase_in; + pr.pp_assemblage = use.pp_assemblage_in; + pr.s_s_assemblage = use.s_s_assemblage_in; + pr.surface = use.surface_in; + pr.exchange = use.exchange_in; + pr.totals = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = use.irrev_in; + pr.mix = use.mix_in; + pr.reaction = TRUE; + pr.use = TRUE; + sum_species(); + print_all(); + sprintf(error_string, "Numerical method failed on all combinations of convergence parameters"); + error_msg(error_string, STOP); + } + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); + } + if (kinetics_save != NULL) { + kinetics_free(kinetics_save); + kinetics_save = (struct kinetics *) free_check_null(kinetics_save); + } + if (converge == MASS_BALANCE) { + return(MASS_BALANCE); + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + * step_fraction--fraction of irreversible reaction to add + */ + int n, n1, n2, converge; + if (state == TRANSPORT || state == PHAST) { + set_transport(i, use_mix, use_kinetics, nsaver); + } else if (state == ADVECTION) { + set_advection(i, use_mix, use_kinetics, nsaver); + } else if (state == REACTION) { + set_reaction(i, use_mix, use_kinetics); + } + cell = i; +/* + * Take step + */ + if (state >= REACTION) { + if (step(step_fraction) == MASS_BALANCE) { + return(MASS_BALANCE); + } +/* + * Always use solution, exchange, and surface -1 + */ + use.solution_ptr = solution_bsearch(-1, &n, TRUE); + + /* new */ + if (use.exchange_ptr != NULL) { + use.exchange_ptr = exchange_bsearch(-1, &n1); + } + if (use.surface_ptr != NULL) { + use.surface_ptr = surface_bsearch(-1, &n2); + } + } + /* end new */ +#ifdef SKIP +/* a quick one ...*/ + if (state == TRANSPORT /*&& ishift == 0*/ && + (cell == 1 || cell == count_cells)) last_model.force_prep = TRUE; +#endif + if (use.surface_ptr != NULL ) { + diffuse_layer_x = use.surface_ptr->diffuse_layer; + } + if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { + converge = surface_model(); + } else { + prep(); +#ifdef SKIP + k_temp(solution[n]->tc); +#endif + k_temp(use.solution_ptr->tc); + set(FALSE); + converge = model(); + } + sum_species(); + return(converge); +} +/* ---------------------------------------------------------------------- */ +int set_transport(int i, int use_mix, int use_kinetics, int nsaver) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + */ + int n; + + cell = i; + reaction_step = 1; +#ifdef SKIP + if (pr.use == TRUE && pr.all == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nCell %d\n", i); + } +#endif +/* + * Find mixture or solution + */ + + use.mix_ptr = NULL; + use.mix_in = FALSE; + if (use_mix == DISP) { + use.mix_ptr = &mix[count_mix - count_cells + i - 1]; + use.mix_in = TRUE; + use.n_mix_user = i; + use.n_mix_user_orig = i; + } else if (use_mix == STAG) { + use.mix_ptr = mix_search (i, &use.n_mix, FALSE); + if (use.mix_ptr != NULL) { + use.mix_in = TRUE; + use.n_mix_user = i; + use.n_mix_user_orig = i; + } else { + use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); + if (use.solution_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", use.n_solution_user); + error_msg(error_string, STOP); + } + use.n_solution_user = i; + use.solution_in = TRUE; + } + } else { + use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); + if (use.solution_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", use.n_solution_user); + error_msg(error_string, STOP); + } + use.n_solution_user = i; + use.solution_in = TRUE; + } + save.solution = TRUE; + save.n_solution_user = nsaver; + save.n_solution_user_end = nsaver; +/* + * Find pure phase assemblage + */ + + use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); + if (use.pp_assemblage_ptr != NULL) { + use.pp_assemblage_in = TRUE; + use.n_pp_assemblage_user = i; + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } else { + use.pp_assemblage_in = FALSE; + save.pp_assemblage = FALSE; + } +/* + * Find irreversible reaction + */ + use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); + if (use.irrev_ptr != NULL) { + use.irrev_in = TRUE; + use.n_irrev_user = i; + } else { + use.irrev_in = FALSE; + } +/* + * Find exchange + */ + use.exchange_ptr = exchange_bsearch(i, &use.n_exchange); + if (use.exchange_ptr != NULL) { + use.exchange_in = TRUE; + use.n_exchange_user = i; + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } else { + use.exchange_in = FALSE; + save.exchange = FALSE; + } + +/* + * Find surface + */ + use.surface_ptr = surface_bsearch(i, &use.n_surface); + if (use.surface_ptr != NULL) { + use.surface_in = TRUE; + use.n_surface_user = i; + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } else { + use.surface_in = FALSE; + save.surface = FALSE; + } +/* + * Find temperature; temp retardation is done in step + */ + use.temperature_ptr = temperature_bsearch(i, &use.n_temperature); + if (use.temperature_ptr != NULL) { + use.temperature_in = TRUE; + use.n_temperature_user = i; + } else { + use.temperature_in = FALSE; + } +/* + * Find gas + */ + use.gas_phase_ptr = gas_phase_bsearch(i, &use.n_gas_phase); + if (use.gas_phase_ptr != NULL) { + use.gas_phase_in = TRUE; + use.n_gas_phase_user = i; + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } else { + use.gas_phase_in = FALSE; + save.gas_phase = FALSE; + } +/* + * Find s_s_assemblage + */ + use.s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &use.n_s_s_assemblage); + if (use.s_s_assemblage_ptr != NULL) { + use.s_s_assemblage_in = TRUE; + use.n_s_s_assemblage_user = i; + save.s_s_assemblage = TRUE; + save.n_s_s_assemblage_user = i; + save.n_s_s_assemblage_user_end = i; + } else { + use.s_s_assemblage_in = FALSE; + save.s_s_assemblage = FALSE; + } +/* + * Find kinetics + */ + if (use_kinetics == TRUE && (use.kinetics_ptr = kinetics_bsearch(i, &n)) != NULL) { + use.n_kinetics_user = i; + use.n_kinetics = n; + use.kinetics_in = TRUE; + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } else { + use.kinetics_ptr = NULL; + use.kinetics_in = FALSE; + save.kinetics = FALSE; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_reaction(int i, int use_mix, int use_kinetics) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + */ +/* + * Find mixture or solution + */ + use.mix_ptr = NULL; + use.solution_ptr = NULL; + if (use_mix == TRUE && use.mix_in == TRUE) { + use.mix_ptr = mix_bsearch (i, &use.n_mix); + if (use.mix_ptr == NULL) { + sprintf(error_string, "MIX %d not found.", i); + error_msg(error_string, STOP); + } + } else { + use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); + if (use.solution_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find pure phase assemblage + */ + if (use.pp_assemblage_in == TRUE) { + use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); + if (use.pp_assemblage_ptr == NULL) { + sprintf(error_string, "PP_ASSEMBLAGE %d not found.", i); + error_msg(error_string, STOP); + } + } + +/* + * Find irreversible reaction + */ + if (use.irrev_in == TRUE) { + use.irrev_ptr = irrev_bsearch (i, &use.n_irrev); + if (use.irrev_ptr == NULL) { + sprintf(error_string, "REACTION %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find exchange + */ + if (use.exchange_in == TRUE) { + use.exchange_ptr = exchange_bsearch (i, &use.n_exchange); + if (use.exchange_ptr == NULL) { + sprintf(error_string, "EXCHANGE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find surface + */ + if (use.surface_in == TRUE) { + use.surface_ptr = surface_bsearch (i, &use.n_surface); + if (use.surface_ptr == NULL) { + sprintf(error_string, "SURFACE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find temperature; temp retardation is done in step + */ + if (use.temperature_in == TRUE) { + use.temperature_ptr = temperature_bsearch (i, &use.n_temperature); + if (use.temperature_ptr == NULL) { + sprintf(error_string, "TEMPERATURE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find gas + */ + if (use.gas_phase_in == TRUE) { + use.gas_phase_ptr = gas_phase_bsearch (i, &use.n_gas_phase); + if (use.gas_phase_ptr == NULL) { + sprintf(error_string, "GAS_PHASE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find s_s_assemblage + */ + if (use.s_s_assemblage_in == TRUE) { + use.s_s_assemblage_ptr = s_s_assemblage_bsearch (i, &use.n_s_s_assemblage); + if (use.s_s_assemblage_ptr == NULL) { + sprintf(error_string, "Solid-solution Assemblage %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find kinetics + */ + if (use_kinetics == TRUE && use.kinetics_in == TRUE) { + use.kinetics_ptr = kinetics_bsearch (i, &use.n_kinetics); + if (use.kinetics_ptr == NULL) { + sprintf(error_string, "KINETICS %d not found.", i); + error_msg(error_string, STOP); + } + } else { + use.kinetics_ptr = NULL; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Kinetics calculations + * Rates and moles of each reaction are calculated in calc_kinetic_reaction + * Total number of moles in reaction is stored in kinetics[i].totals + */ + + int j, n, converge, iter; + int pr_all_save; + int nsaver; + struct kinetics *kinetics_ptr; + struct pp_assemblage *pp_assemblage_ptr; + struct s_s_assemblage *s_s_assemblage_ptr; + + int save_old, m, n_reactions /*, nok, nbad */; + + /* CVODE definitions */ + realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; + long int iopt[OPT_SIZE]; + int flag; +/* + * Set nsaver + */ + run_reactions_iterations = 0; + kin_time_x = kin_time; + nsaver = i; + if (state == TRANSPORT || state == PHAST) { + if (use_mix == DISP) { + nsaver = -2; + } else if (use_mix == STAG) { + nsaver = -2-i; + } + } if (state == ADVECTION) { + nsaver = -2; + } +/* + * Check that reaction exists for this cell .. + */ + if (kin_time <= 0 || + (state == REACTION && use.kinetics_in == FALSE) || + (state == TRANSPORT && kinetics_bsearch(i, &n) == NULL) || + (state == PHAST && kinetics_bsearch(i, &n) == NULL) || + (state == ADVECTION && kinetics_bsearch(i, &n) == NULL)) { + converge = set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); + if (converge == MASS_BALANCE) error_msg("Negative concentration in system. Stopping calculation.",STOP); + run_reactions_iterations += iterations; + } else { +/* + * Save moles of kinetic reactants for printout... + */ + kinetics_ptr = kinetics_bsearch(i, &n); + + m_temp = (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * sizeof(LDBLE)); + if (m_temp == NULL) malloc_error(); + + m_original = (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * sizeof(LDBLE)); + if (m_original == NULL) malloc_error(); + + for (j = 0; j < kinetics_ptr->count_comps; j++) { + m_original[j] = kinetics_ptr->comps[j].m; + m_temp[j] = kinetics_ptr->comps[j].m; + } +/* + * Start the loop for timestepping ... + * Use either Runge-Kutta-Fehlberg, or final result extrapolation + */ + pr_all_save = pr.all; + pr.all = FALSE; +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * (if (incremental_reactions == FALSE || reaction_step == 1) + */ + store_get_equi_reactants(i, FALSE); + if (kinetics_ptr->use_cvode == FALSE) { + rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); + } else { + save_old = -2 - (count_cells + 1); + if (nsaver != i) { + solution_duplicate(i, save_old); + } + for (j = 0; j < OPT_SIZE; j++) { + iopt[j] = 0; + ropt[j] = 0; + } + +/* + * Do mix first + */ + kinetics_ptr = kinetics_bsearch(i, &m); + n_reactions = kinetics_ptr->count_comps; + cvode_n_user = i; + cvode_kinetics_ptr = (void *) kinetics_ptr; + cvode_n_reactions = n_reactions; + cvode_rate_sim_time_start = rate_sim_time_start; + cvode_rate_sim_time = rate_sim_time; + + converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); + if (converge == MASS_BALANCE) error_msg("Negative concentration in system. Stopping calculation.",STOP); + saver(); + pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); + s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &n); + if (pp_assemblage_ptr != NULL) { + cvode_pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); + if (cvode_pp_assemblage_save == NULL) malloc_error(); + pp_assemblage_copy(pp_assemblage_ptr, cvode_pp_assemblage_save, pp_assemblage_ptr->n_user); + } + if (s_s_assemblage_ptr != NULL) { + cvode_s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); + if (cvode_s_s_assemblage_save == NULL) malloc_error(); + s_s_assemblage_copy(s_s_assemblage_ptr, cvode_s_s_assemblage_save, s_s_assemblage_ptr->n_user); + } + + /* allocate space for CVODE */ + kinetics_machEnv = M_EnvInit_Serial(n_reactions); + kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (kinetics_y == NULL) malloc_error(); + cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_last_good_y == NULL) malloc_error(); + cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_prev_good_y == NULL) malloc_error(); + kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); + if (kinetics_abstol == NULL) malloc_error(); + +/* + * Set y to 0.0 + */ + for (j = 0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = 0.0; + Ith(kinetics_y,j+1) = 0.0; + Ith(kinetics_abstol,j+1) = kinetics_ptr->comps[j].tol; + /*Ith(abstol,j+1) = 1e-8; */ + /* m_temp[j] = kinetics_ptr->comps[j].m; */ + } + reltol = 0.0; + + /* Call CVodeMalloc to initialize CVODE: + + NEQ is the problem size = number of equations + f is the user's right hand side function in y'=f(t,y) + T0 is the initial time + y is the initial dependent variable vector + BDF specifies the Backward Differentiation Formula + NEWTON specifies a Newton iteration + SV specifies scalar relative and vector absolute tolerances + &reltol is a pointer to the scalar relative tolerance + abstol is the absolute tolerance vector + FALSE indicates there are no optional inputs in iopt and ropt + iopt is an array used to communicate optional integer input and output + ropt is an array used to communicate optional real input and output + + A pointer to CVODE problem memory is returned and stored in cvode_mem. */ + /* Don't know what this does */ + /* + iopt[SLDET] = TRUE; + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); + */ + kinetics_cvode_mem = CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, &reltol, kinetics_abstol, NULL, NULL, TRUE, iopt, ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + + flag = CVDense(kinetics_cvode_mem, Jac, NULL); + if (flag != SUCCESS) { + error_msg("CVDense failed.", STOP); + } + t = 0; + tout = kin_time; + /*ropt[HMAX] = tout/10.;*/ + /*ropt[HMIN] = 1e-17;*/ + flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); + rate_sim_time = rate_sim_time_start + t; + /* + printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", + t, Ith(y,1), Ith(y,2), Ith(y,3)); + */ + iter = 0; + sum_t = 0; + RESTART: + while (flag != SUCCESS) { + sum_t += cvode_last_good_time; + cvode_last_good_time = 0; + if (++iter >= 200) { + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + error_msg("Repeated restart of integration.", STOP); + } + tout1 = tout - sum_t; + t = 0; + N_VScale(1.0, cvode_last_good_y, kinetics_y); + for (j = 0; j < OPT_SIZE; j++) { + iopt[j] = 0; + ropt[j] = 0; + } + CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + kinetics_cvode_mem = CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, &reltol, kinetics_abstol, NULL, NULL, FALSE, iopt, ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + + flag = CVDense(kinetics_cvode_mem, Jac, NULL); + if (flag != SUCCESS) { + error_msg("CVDense failed.", STOP); + } + flag = CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); + /* + sprintf(error_string, "CVode failed, flag=%d.\n", flag); + error_msg(error_string, STOP); + */ + } + + + /* + odeint(&ystart[-1], n_reactions, 0, kin_time, kinetics_ptr->comps[0].tol, kin_time/kinetics_ptr->step_divide, 0.0, &nok, &nbad, i, nsaver ); + */ + for (j = 0; j < n_reactions; j++) { + kinetics_ptr->comps[j].moles = Ith(kinetics_y,j+1); + kinetics_ptr->comps[j].m = m_original[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 0) { + kinetics_ptr->comps[j].moles = m_original[j]; + kinetics_ptr->comps[j].m = 0.0; + } + /* output_msg(OUTPUT_MESSAGE,"%d y[%d] %g\n", i, j, ystart[j]); */ + } + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, i); + } + if (use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(cvode_s_s_assemblage_save, use.s_s_assemblage_ptr, i); + } + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) { + /*error_msg("FAIL 2 after successful integration in CVode", CONTINUE);*/ + warning_msg("FAIL 2 after successful integration in CVode"); + flag = -1; + goto RESTART; + } + for (j = 0; j < kinetics_ptr->count_comps; j++) { + kinetics_ptr->comps[j].m = m_original[j] - kinetics_ptr->comps[j].moles; + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) { + solution_duplicate(save_old, i); + } + free_cvode(); + } + + store_get_equi_reactants(i, TRUE); + pr.all = pr_all_save; + + kinetics_ptr = kinetics_bsearch(i, &n); + for (j = 0; j < kinetics_ptr->count_comps; j++) { + kinetics_ptr->comps[j].moles = m_original[j] - kinetics_ptr->comps[j].m; +/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0; + */ } + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + } + iterations = run_reactions_iterations; + if (cvode_pp_assemblage_save != NULL) { + pp_assemblage_free(cvode_pp_assemblage_save); + cvode_pp_assemblage_save = (struct pp_assemblage *) free_check_null(cvode_pp_assemblage_save); + } + if (cvode_s_s_assemblage_save != NULL) { + s_s_assemblage_free(cvode_s_s_assemblage_save); + cvode_s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(cvode_s_s_assemblage_save); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int free_cvode(void) +/* ---------------------------------------------------------------------- */ +{ + if (kinetics_y != NULL) N_VFree(kinetics_y); /* Free vector */ + kinetics_y = NULL; + if (cvode_last_good_y != NULL) N_VFree(cvode_last_good_y); /* Free vector */ + cvode_last_good_y = NULL; + if (cvode_prev_good_y != NULL) N_VFree(cvode_prev_good_y); /* Free vector */ + cvode_prev_good_y = NULL; + if (kinetics_abstol != NULL) N_VFree(kinetics_abstol); /* Free vector */ + kinetics_abstol = NULL; + if (kinetics_cvode_mem != NULL) CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + kinetics_cvode_mem = NULL; + if (kinetics_machEnv != NULL) M_EnvFree_Serial(kinetics_machEnv); /* Free the machine environment memory */ + kinetics_machEnv = NULL; + if (cvode_pp_assemblage_save != NULL) { + pp_assemblage_free(cvode_pp_assemblage_save); + cvode_pp_assemblage_save = (struct pp_assemblage *) free_check_null(cvode_pp_assemblage_save); + } + if (cvode_s_s_assemblage_save != NULL) { + s_s_assemblage_free(cvode_s_s_assemblage_save); + cvode_s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(cvode_s_s_assemblage_save); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_advection(int i, int use_mix, int use_kinetics, int nsaver) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + state == ADVECTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + */ + int n; + + cell = i; + reaction_step = 1; +/* + * Find mixture or solution + */ + + use.mix_ptr = NULL; + use.mix_in = FALSE; + if (use_mix == TRUE && + (use.mix_ptr = mix_search (i, &use.n_mix, FALSE)) != NULL) { + use.mix_in = TRUE; + use.n_mix_user = i; + use.n_mix_user_orig = i; + use.n_solution_user = i; + } else { + use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); + if (use.solution_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", use.n_solution_user); + error_msg(error_string, STOP); + } + use.n_solution_user = i; + use.solution_in = TRUE; + } + save.solution = TRUE; + save.n_solution_user = nsaver; + save.n_solution_user_end = nsaver; +/* + * Find pure phase assemblage + */ + + use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); + if (use.pp_assemblage_ptr != NULL) { + use.pp_assemblage_in = TRUE; + use.n_pp_assemblage_user = i; + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } else { + use.pp_assemblage_in = FALSE; + save.pp_assemblage = FALSE; + } +/* + * Find irreversible reaction + */ + use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); + if (use.irrev_ptr != NULL) { + use.irrev_in = TRUE; + use.n_irrev_user = i; + } else { + use.irrev_in = FALSE; + } +/* + * Find exchange + */ + use.exchange_ptr = exchange_bsearch(i, &use.n_exchange); + if (use.exchange_ptr != NULL) { + use.exchange_in = TRUE; + use.n_exchange_user = i; + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } else { + use.exchange_in = FALSE; + save.exchange = FALSE; + } + +/* + * Find surface + */ + use.surface_ptr = surface_bsearch(i, &use.n_surface); + if (use.surface_ptr != NULL) { + use.surface_in = TRUE; + use.n_surface_user = i; + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } else { + use.surface_in = FALSE; + save.surface = FALSE; + } +/* + * Find temperature; temp retardation is done in step + */ + use.temperature_ptr = temperature_bsearch(i, &use.n_temperature); + if (use.temperature_ptr != NULL) { + use.temperature_in = TRUE; + use.n_temperature_user = i; + } else { + use.temperature_in = FALSE; + } +/* + * Find gas + */ + use.gas_phase_ptr = gas_phase_bsearch(i, &use.n_gas_phase); + if (use.gas_phase_ptr != NULL) { + use.gas_phase_in = TRUE; + use.n_gas_phase_user = i; + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } else { + use.gas_phase_in = FALSE; + save.gas_phase = FALSE; + } +/* + * Find s_s_assemblage + */ + use.s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &use.n_s_s_assemblage); + if (use.s_s_assemblage_ptr != NULL) { + use.s_s_assemblage_in = TRUE; + use.n_s_s_assemblage_user = i; + save.s_s_assemblage = TRUE; + save.n_s_s_assemblage_user = i; + save.n_s_s_assemblage_user_end = i; + } else { + use.s_s_assemblage_in = FALSE; + save.s_s_assemblage = FALSE; + } +/* + * Find kinetics + */ + if (use_kinetics == TRUE && (use.kinetics_ptr = kinetics_bsearch(i, &n)) != NULL) { + use.n_kinetics_user = i; + use.n_kinetics = n; + use.kinetics_in = TRUE; + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } else { + use.kinetics_ptr = NULL; + use.kinetics_in = FALSE; + save.kinetics = FALSE; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_get_equi_reactants(int l, int kin_end) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + static int count_pp, count_pg, count_s_s; + static LDBLE *x0_moles; + + if (use.pp_assemblage_in == TRUE) { + use.pp_assemblage_ptr = pp_assemblage_bsearch (l, &use.n_pp_assemblage); + } else use.pp_assemblage_ptr = NULL; + if (use.gas_phase_in == TRUE) { + use.gas_phase_ptr = gas_phase_bsearch(l, &use.n_gas_phase); + } else use.gas_phase_ptr = NULL; + if (use.s_s_assemblage_in == TRUE) { + use.s_s_assemblage_ptr = s_s_assemblage_bsearch(l, &use.n_s_s_assemblage); + } else use.s_s_assemblage_ptr = NULL; + + if (kin_end == FALSE) { + count_pp = count_s_s = count_pg = 0; + if (use.pp_assemblage_ptr != NULL) count_pp = use.pp_assemblage_ptr->count_comps; + if (use.gas_phase_ptr != NULL) count_pg = use.gas_phase_ptr->count_comps; + if (use.s_s_assemblage_ptr != NULL) { + for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + count_s_s++; + } + } + } + k = count_pp + count_s_s + count_pg; + x0_moles = NULL; + if (k == 0) return(OK); + x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE)); + if (x0_moles == NULL) malloc_error(); + + k = -1; + for (j = 0; j < count_pp; j++) { + x0_moles[++k] = use.pp_assemblage_ptr->pure_phases[j].moles; + } + for (j = 0; j < count_pg; j++) { + x0_moles[++k] = use.gas_phase_ptr->comps[j].moles; + } + if (count_s_s != 0) { + for(j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + x0_moles[++k] = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + } +/*!!!! also miscibility gap comps ?? + */ + } + } + } else { + k = -1; + for (j = 0; j < count_pp; j++) { + use.pp_assemblage_ptr->pure_phases[j].moles = x0_moles[++k]; + use.pp_assemblage_ptr->pure_phases[j].delta = 0.0; + } + for (j = 0; j < count_pg; j++) { + use.gas_phase_ptr->comps[j].moles = x0_moles[++k]; + } + if (count_s_s != 0) { + for(j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles = x0_moles[++k]; + } +/*!!!! also miscibility gap comps ?? + */ + } + } +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * if (incremental_reactions == FALSE || reaction_step == count_total_steps) + */ + x0_moles = (LDBLE *) free_check_null(x0_moles); + } + return(OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +static void derivs (LDBLE x, LDBLE y[], LDBLE dydx[], int n_reactions, int n_user, struct kinetics *kinetics_ptr, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +#endif +static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data) +{ + int i, n_reactions, n_user; + LDBLE step_fraction; + struct kinetics *kinetics_ptr; + + cvode_error = FALSE; + n_reactions = cvode_n_reactions; + n_user = cvode_n_user; + kinetics_ptr = (struct kinetics *) cvode_kinetics_ptr; + step_fraction = cvode_step_fraction; + rate_sim_time = cvode_rate_sim_time; + + for (i = 0; i < n_reactions; i++) { + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_ptr->comps[i].moles = Ith(y,i + 1); + kinetics_ptr->comps[i].m = m_original[i] - Ith(y,i + 1); + if (kinetics_ptr->comps[i].m < 0) { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); + } + if (use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(cvode_s_s_assemblage_save, use.s_s_assemblage_ptr, n_user); + } + + if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) { + run_reactions_iterations += iterations; + cvode_error = TRUE; + /* + error_msg("Mass balance error in f", CONTINUE); + */ + return; + } + if (cvode_test == TRUE) { + return; + } + run_reactions_iterations += iterations; + for (i = 0; i < n_reactions; i++) { + kinetics_ptr->comps[i].moles = 0.0; + } + calc_kinetic_reaction(kinetics_ptr, 1.0); + for (i = 0; i < n_reactions; i++) { + /* + dydx[i + 1] = kinetics_ptr->comps[i].moles; + */ + Ith(ydot,i + 1) = kinetics_ptr->comps[i].moles; + } + return; +} + +/* +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); +*/ +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +void jacobn (LDBLE x, LDBLE y[], LDBLE dfdx[], LDBLE **dfdy, int n_reactions, int n_user, struct kinetics *kinetics_ptr, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +#endif +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) +{ + int count_cvode_errors; + int i, j, n_reactions, n_user; + LDBLE *initial_rates, del; + struct kinetics *kinetics_ptr; + LDBLE step_fraction; + + cvode_error = FALSE; + n_reactions = cvode_n_reactions; + n_user = cvode_n_user; + kinetics_ptr = (struct kinetics *) cvode_kinetics_ptr; + step_fraction = cvode_step_fraction; + rate_sim_time = cvode_rate_sim_time; + + initial_rates = (LDBLE *) PHRQ_malloc((size_t) n_reactions * sizeof(LDBLE)); + if (initial_rates == NULL) malloc_error(); + + for (i = 0; i < n_reactions; i++) { + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_ptr->comps[i].moles = Ith(y, i + 1); + kinetics_ptr->comps[i].m = m_original[i] - Ith(y, i + 1); + if (kinetics_ptr->comps[i].m < 0) { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) {*/ + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); + } + if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) { + run_reactions_iterations += iterations; + cvode_error = TRUE; + /* + error_msg("Mass balance error in jacobian", CONTINUE); + */ + initial_rates = (LDBLE *) free_check_null(initial_rates); + return; + } + run_reactions_iterations += iterations; + for (i = 0; i < n_reactions; i++) kinetics_ptr->comps[i].moles = 0.0; + calc_kinetic_reaction(kinetics_ptr, 1.0); + for (i = 0; i < n_reactions; i++) { + initial_rates[i] = kinetics_ptr->comps[i].moles; + } + for (i = 0; i < n_reactions; i++) { + /* calculate reaction up to current time */ + del = 1e-12; + cvode_error = TRUE; + count_cvode_errors = 0; + while (cvode_error == TRUE) { + del /= 10.; + for (j = 0; j < n_reactions; j++) { + /* + kinetics_ptr->comps[j].moles = y[j + 1]; + kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; + */ + kinetics_ptr->comps[j].moles = Ith(y, j+1); + kinetics_ptr->comps[j].m = m_original[j] - Ith(y,j + 1); + if (kinetics_ptr->comps[i].m < 0) { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + + /* Add small amount of ith reaction */ + kinetics_ptr->comps[i].m -= del; + if (kinetics_ptr->comps[i].m < 0) { + kinetics_ptr->comps[i].m = 0; + } + kinetics_ptr->comps[i].moles += del; + calc_final_kinetic_reaction(kinetics_ptr); + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); + } +#ifdef SKIP + if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { + run_reactions_iterations += iterations; + /* + error_msg("Mass balance error in jacobian 2", CONTINUE); + */ + cvode_error = TRUE; + initial_rates = (LDBLE *) free_check_null(initial_rates); + return; + } +#endif + if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { + count_cvode_errors++; + cvode_error = TRUE; + if (count_cvode_errors > 30) { + initial_rates = (LDBLE *) free_check_null(initial_rates); + return; + } + run_reactions_iterations += iterations; + continue; + } + cvode_error = FALSE; + run_reactions_iterations += iterations; + /*kinetics_ptr->comps[i].moles -= del;*/ + for (j = 0; j < n_reactions; j++) kinetics_ptr->comps[j].moles = 0.0; + calc_kinetic_reaction(kinetics_ptr, 1.0); + + /* calculate new rates for df/dy[i] */ + /* dfdx[i + 1] = 0.0; */ + for (j = 0; j < n_reactions; j++) { + IJth(J,j+1,i+1) = (kinetics_ptr->comps[j].moles - initial_rates[j])/del; + } + } + } + for (i = 0; i < n_reactions; i++) { + kinetics_ptr->comps[i].moles = 0; + } + initial_rates = (LDBLE *) free_check_null(initial_rates); + return; +} + +void cvode_init(void) +{ + cvode_kinetics_ptr = NULL; + cvode_test = 0; + cvode_error = 0; + cvode_n_user = -99; + cvode_n_reactions = -99; + cvode_step_fraction = 0.0; + cvode_rate_sim_time = 0.0; + cvode_rate_sim_time_start = 0.0; + cvode_last_good_time = 0.0; + cvode_prev_good_time = 0.0; + cvode_last_good_y = NULL; + cvode_prev_good_y = NULL; + kinetics_machEnv = NULL; + kinetics_y = kinetics_abstol = NULL; + kinetics_cvode_mem = NULL; + cvode_pp_assemblage_save = NULL; + cvode_s_s_assemblage_save = NULL; + return; +} diff --git a/kinetics.h b/kinetics.h new file mode 100644 index 00000000..60df9d12 --- /dev/null +++ b/kinetics.h @@ -0,0 +1,21 @@ +#ifdef PHREEQC_IDENT +static char const svnidkinetics[] = "$Id$"; +#endif +KINETICS_EXTERNAL void *cvode_kinetics_ptr; +KINETICS_EXTERNAL int cvode_test; +KINETICS_EXTERNAL int cvode_error; +KINETICS_EXTERNAL int cvode_n_user; +KINETICS_EXTERNAL int cvode_n_reactions; +KINETICS_EXTERNAL realtype cvode_step_fraction; +KINETICS_EXTERNAL realtype cvode_rate_sim_time; +KINETICS_EXTERNAL realtype cvode_rate_sim_time_start; +KINETICS_EXTERNAL realtype cvode_last_good_time; +KINETICS_EXTERNAL realtype cvode_prev_good_time; +KINETICS_EXTERNAL N_Vector cvode_last_good_y; +KINETICS_EXTERNAL N_Vector cvode_prev_good_y; +KINETICS_EXTERNAL M_Env kinetics_machEnv; +KINETICS_EXTERNAL N_Vector kinetics_y, kinetics_abstol; +KINETICS_EXTERNAL void *kinetics_cvode_mem; +KINETICS_EXTERNAL struct pp_assemblage *cvode_pp_assemblage_save; +KINETICS_EXTERNAL struct s_s_assemblage *cvode_s_s_assemblage_save; + diff --git a/main.cpp b/main.cpp new file mode 100644 index 00000000..073e5d25 --- /dev/null +++ b/main.cpp @@ -0,0 +1,140 @@ +#define EXTERNAL +#include "global.h" +#include "output.h" +#include "phrqproto.h" +#include "input.h" + +/*#define PHREEQC_XML*/ +#ifdef PHREEQC_XML +#include "SAXPhreeqc.h" +extern void SAX_cleanup(void); +#endif + +static char const svnid[] = "$Id: main.c 715 2006-01-18 01:26:29Z dlpark $"; + +#ifdef DOS +static int write_banner(void); +#endif + +/* ---------------------------------------------------------------------- + * MAIN + * ---------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + int errors; + void *db_cookie = NULL; + void *input_cookie = NULL; + if (svnid == NULL) fprintf(stderr," "); + phast = FALSE; +/* + * Add callbacks for error_msg and warning_msg + */ + if (add_output_callback(phreeqc_handler, NULL) != OK) { + fprintf(stderr, "ERROR: %s\n", "NULL pointer returned from malloc or realloc."); + fprintf(stderr, "ERROR: %s\n", "Program terminating."); + return -1; + } + +/* + * Open input/output files + */ + errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); + if (errors != 0) { + clean_up(); + return errors; + } +#ifdef DOS + write_banner(); +#endif + +/* + * Initialize arrays + */ + errors = do_initialize(); + if (errors != 0) { + clean_up(); + return errors; + } + +/* + * Load database into memory + */ + errors = read_database(getc_callback, db_cookie); + if (errors != 0) { + clean_up(); + return errors; + } + +/* + * Read input data for simulation + */ + errors = run_simulations(getc_callback, input_cookie); + if (errors != 0) { + clean_up(); + return errors; + } + + +/* + * Display successful status + */ + errors = do_status(); + if (errors != 0) { + clean_up(); + return errors; + } +#ifdef PHREEQC_XML +{ + int n; + SAX_StartSystem(); + for (n = 0; n < count_solution; ++n) + { + SAX_AddSolution(solution[n]); + } + SAX_EndSystem(); + SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); + } +#endif + + clean_up(); + close_input_files(); + close_output_files(); +#ifdef PHREEQC_XML + SAX_cleanup(); +#endif + return 0; +} +/* ---------------------------------------------------------------------- */ +int write_banner(void) +/* ---------------------------------------------------------------------- */ +{ + char buffer[80]; + int len, indent; + output_msg(OUTPUT_SCREEN, " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); + output_msg(OUTPUT_SCREEN, " º º\n"); + + /* version */ + len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, " º º\n"); + output_msg(OUTPUT_SCREEN, " º A hydrogeochemical transport model º\n"); + output_msg(OUTPUT_SCREEN, " º º\n"); + output_msg(OUTPUT_SCREEN, " º by º\n"); + output_msg(OUTPUT_SCREEN, " º D.L. Parkhurst and C.A.J. Appelo º\n"); + output_msg(OUTPUT_SCREEN, " º º\n"); + + + /* date */ + len = sprintf(buffer, "%s", "@VER_DATE@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); + +return 0; +} diff --git a/mainsubs.cpp b/mainsubs.cpp new file mode 100644 index 00000000..8c1d6df2 --- /dev/null +++ b/mainsubs.cpp @@ -0,0 +1,2486 @@ +#define EXTERNAL extern +#define MAINSUBS +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +#include "input.h" + +extern void test_classes(void); +#define PHREEQC_XML +#ifdef PHREEQC_XML +#include "SAXPhreeqc.h" +extern void SAX_cleanup(void); +#endif + +static char const svnid[] = "$Id: mainsubs.c 715 2006-01-18 01:26:29Z dlpark $"; + +#if defined(WINDOWS) || defined(_WINDOWS) +#include +#endif + +static int copy_use (int i); +static int set_use(void); +static int xexchange_save(int n_user); +static int xgas_save(int n_user); +static int xpp_assemblage_save(int n_user); +static int xs_s_assemblage_save(int n_user); +static int xsurface_save(int n_user); + +#ifdef PHREEQ98 +extern int phreeq98_debug; +extern int AddSeries, connect_simulations; +#endif +/* ---------------------------------------------------------------------- */ +void initialize(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialize global variables + */ + ENTRY item, *found_item; + int i; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + if (svnid == NULL) fprintf(stderr," "); + + moles_per_kilogram_string = string_duplicate("Mol/kgw"); + pe_string = string_duplicate("pe"); + + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + itmax=100; +#ifdef USE_LONG_LDBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow(10, -LDBL_DIG); +#else + ineq_tol = pow(10, -DBL_DIG); +#endif + convergence_tolerance = 1e-8; +#ifdef USE_LONG_LDBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow(10, -LDBL_DIG+5); +#else + inv_tol_default = pow(10, -DBL_DIG+5); +#endif + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + /* mass_water_switch = TRUE; */ + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; + negative_concentrations = FALSE; + + LOG_10 = log(10.0); + /* Use space for all memory allocation */ + max_solution=MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; + + count_solution = 0; + count_pp_assemblage = 0; + count_exchange = 0; + count_surface = 0; + count_gas_phase = 0; + count_kinetics = 0; + count_s_s_assemblage = 0; + + count_elements = 0; + count_irrev = 0; + count_master = 0; + count_mix = 0; + count_phases=0; + count_s = 0; + count_temperature = 0; + count_logk = 0; + count_master_isotope = 0; +/* + * Initialize advection + */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + advection_punch = (int *) PHRQ_malloc(sizeof(int)); + if (advection_punch == NULL) malloc_error(); + advection_punch[0] = TRUE; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = (int *) PHRQ_malloc(sizeof(int)); + if (advection_print == NULL) malloc_error(); + advection_print[0] = TRUE; + advection_warnings = TRUE; +/* + * Initialize transport + */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; +/* !!!! count_stag = 0; */ + + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; +/* + * Allocate space + */ + space ((void **) ((void *) &pp_assemblage), INIT, &max_pp_assemblage, sizeof(struct pp_assemblage)); + + space ((void **) ((void *) &exchange), INIT, &max_exchange, sizeof(struct exchange)); + + space ((void **) ((void *) &surface), INIT, &max_surface, sizeof(struct surface)); + + space ((void **) ((void *) &gas_phase), INIT, &max_gas_phase, sizeof(struct gas_phase)); + + space ((void **) ((void *) &kinetics), INIT, &max_kinetics, sizeof(struct kinetics)); + + space ((void **) ((void *) &s_s_assemblage), INIT, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + + space ((void **) ((void *) &cell_data), INIT, &count_cells, + sizeof(struct cell_data)); + + space ((void **) ((void *) &elements), INIT, &max_elements, sizeof(struct element *)); + + space ((void **) ((void *) &elt_list), INIT, &max_elts, sizeof(struct elt_list)); + + + inverse = (struct inverse *) PHRQ_malloc( (size_t) sizeof (struct inverse) ); + if (inverse == NULL) malloc_error(); + count_inverse = 0; + + irrev = (struct irrev *) PHRQ_malloc( (size_t) sizeof (struct irrev) ); + if (irrev == NULL) malloc_error(); + + space ((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + + space ((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); + + space ((void **) ((void *) &master), INIT, &max_master, sizeof(struct master *)); + + space ((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, sizeof(struct unknown_list)); + + mix = (struct mix *) PHRQ_malloc((size_t) sizeof(struct mix)); + if (mix == NULL) malloc_error(); + count_mix = 0; +/* !!!! */ + stag_data = (struct stag_data *) PHRQ_calloc (1, sizeof(struct stag_data)); + if (stag_data == NULL) malloc_error(); + stag_data->count_stag = 0; + stag_data->exch_f = 0; + stag_data->th_m = 0; + stag_data->th_im = 0; + + space ((void **) ((void *) &phases), INIT, &max_phases, sizeof(struct phase *)); + + space ((void **) &trxn.token, INIT, &max_trxn, + sizeof(struct rxn_token_temp)); + + space ((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); + + space ((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); + + space ((void **) ((void *) &master_isotope), INIT, &max_master_isotope, sizeof(struct master_isotope *)); + + solution = (struct solution **) PHRQ_malloc((size_t) MAX_SOLUTION * sizeof(struct solution *)); + if (solution == NULL) malloc_error(); + + temperature = (struct temperature *) PHRQ_malloc((size_t) sizeof (struct temperature)); + if (temperature == NULL) malloc_error(); + + title_x = NULL; + pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; +/* SRC ADDED */ + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; +/* SRC ADDED */ + isotopes_x = (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); + if (isotopes_x == NULL) malloc_error(); + x = NULL; + max_unknowns = 0; + + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + + hcreate_multi((unsigned) max_logk, &logk_hash_table); + hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); +/* + * Create hash table for strings + */ + hcreate_multi((unsigned) max_strings, &strings_hash_table); + hcreate_multi((unsigned) max_elements, &elements_hash_table); + hcreate_multi((unsigned) max_s, &species_hash_table); + hcreate_multi((unsigned) max_phases, &phases_hash_table); + hcreate_multi((unsigned) 2*NKEYS, &keyword_hash_table); +/* + * Initialize use pointers + */ + use.solution_in = FALSE; + use.pp_assemblage_in = FALSE; + use.mix_in = FALSE; + use.irrev_in = FALSE; +/* + * Initialize punch + */ + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.totals == NULL) malloc_error(); + punch.count_molalities = 0; + punch.molalities = (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.molalities == NULL) malloc_error(); + punch.count_activities = 0; + punch.activities = (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.activities == NULL) malloc_error(); + punch.count_pure_phases = 0; + punch.pure_phases = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.pure_phases == NULL) malloc_error(); + punch.count_si = 0; + punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.si == NULL) malloc_error(); + punch.count_gases = 0; + punch.gases = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.gases == NULL) malloc_error(); + punch.count_s_s = 0; + punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.s_s == NULL) malloc_error(); + + punch.count_kinetics = 0; + punch.kinetics = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.kinetics == NULL) malloc_error(); + + punch.count_isotopes = 0; + punch.isotopes = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.isotopes == NULL) malloc_error(); + + punch.count_calculate_values = 0; + punch.calculate_values = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.calculate_values == NULL) malloc_error(); + + count_save_values = 0; + save_values = (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); + if (save_values == NULL) malloc_error(); + + punch.inverse = TRUE; + + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; +/* + * last model + */ + last_model.exchange = NULL; + last_model.gas_phase = NULL; + last_model.s_s_assemblage = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; + last_model.surface_charge = NULL; +/* + * Update hash table + */ + keyword_hash = (struct key *) PHRQ_malloc((size_t) NKEYS * sizeof(struct key)); + if (keyword_hash == NULL) malloc_error(); + for (i = 0; i < NKEYS; i++) { + keyword_hash[i].name = string_hsave(keyword[i].name); + keyword_hash[i].keycount = i; + item.key = keyword_hash[i].name; + item.data = (void *) &keyword_hash[i]; + found_item = hsearch_multi(keyword_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in keyword initialization."); + error_msg(error_string, STOP); + } + } +/* + * rates + */ + rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); + if (rates == NULL) malloc_error(); + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_p = NULL; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + +/* + * user_print, user_punch + */ + user_print = (struct rate *) PHRQ_malloc((size_t) sizeof (struct rate)); + if (user_print == NULL) malloc_error(); + user_print->commands = NULL; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof (struct rate)); + if (user_punch == NULL) malloc_error(); + user_punch->commands = NULL; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + user_punch_headings = (char **) PHRQ_malloc(sizeof(char *)); + if (user_punch_headings == NULL) malloc_error(); + user_punch_count_headings = 0; +#ifdef PHREEQ98 +/* + * user_graph + */ + user_graph = PHRQ_malloc((size_t) sizeof (struct rate)); + if (user_graph == NULL) malloc_error(); + user_graph->commands = NULL; + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); + if (user_graph_headings == NULL) malloc_error(); + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_temp == NULL) malloc_error(); + llnl_count_temp = 0; + llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_adh == NULL) malloc_error(); + llnl_count_adh = 0; + llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdh == NULL) malloc_error(); + llnl_count_bdh = 0; + llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdot == NULL) malloc_error(); + llnl_count_bdot = 0; + llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_co2_coefs == NULL) malloc_error(); + llnl_count_co2_coefs = 0; +/* + * + */ + cmd_initialize(); +#if defined(WINDOWS) || defined(_WINDOWS) + /* SRC pr.status = FALSE; */ +#endif + /* Initialize print here, not in global.h */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + if (phast == TRUE) { + pr.status = FALSE; + } else { + pr.status = TRUE; + } + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + + species_list = NULL; + + user_database = NULL; + first_read_input = TRUE; + selected_output_file_name = NULL; + dump_file_name = NULL; + +#ifdef PHREEQCI_GUI + g_spread_sheet.heading = NULL; + g_spread_sheet.units = NULL; + g_spread_sheet.count_rows = 0; + g_spread_sheet.rows = NULL; + g_spread_sheet.defaults.units = NULL; + g_spread_sheet.defaults.count_iso = 0; + g_spread_sheet.defaults.iso = NULL; +#endif + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + space ((void **) ((void *) &calculate_value), INIT, &max_calculate_value, sizeof(struct calculate_value *)); + hcreate_multi((unsigned) max_calculate_value, &calculate_value_hash_table); + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + space ((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, sizeof(struct isotope_ratio *)); + hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + space ((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, sizeof(struct isotope_alpha *)); + hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); + + /* + * define constant named log_k + */ + strcpy(token, "XconstantX"); + logk_ptr = logk_store(token, TRUE); + read_log_k_only("1.0", &logk_ptr->log_k[0]); + + phreeqc_mpi_myself = 0; + + copier_init(©_solution); + copier_init(©_pp_assemblage); + copier_init(©_exchange); + copier_init(©_surface); + copier_init(©_s_s_assemblage); + copier_init(©_gas_phase); + copier_init(©_kinetics); + copier_init(©_mix); + copier_init(©_irrev); + copier_init(©_temperature); + + set_forward_output_to_log(FALSE); + simulation = 0; + /* + * cvode + */ + cvode_init(); + /* + * Pitzer + */ + pitzer_init(); + /* + * to facilitate debuging + */ + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; + dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + return; +} +/* ---------------------------------------------------------------------- */ +static int set_use(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Structure "use" has list of solution, ex, surf, pp_assemblage, + * gas_phase and solid solution to use in current calculations, + * also mix, irrev, and temp. + * This routine searches for the user numbers in each list + * (solution, ex, ...) and sets a pointer in structure use + */ + +/* + * Initial solution case + */ + use.pp_assemblage_ptr = NULL; + use.mix_ptr = NULL; + use.irrev_ptr = NULL; + use.exchange_ptr = NULL; + use.kinetics_ptr = NULL; + use.surface_ptr = NULL; + use.temperature_ptr = NULL; + use.gas_phase_ptr = NULL; + use.s_s_assemblage_ptr = NULL; + + if (state < REACTION) { + return(OK); + } +/* + * Reaction case + */ + if (use.pp_assemblage_in == FALSE && + use.irrev_in == FALSE && + use.mix_in == FALSE && + use.exchange_in == FALSE && + use.kinetics_in == FALSE && + use.surface_in == FALSE && + use.temperature_in == FALSE && + use.gas_phase_in == FALSE && + use.s_s_assemblage_in == FALSE) { + return (FALSE); + } + if (use.solution_in == FALSE && use.mix_in == FALSE) return(FALSE); +/* + * Find solution + */ + if (use.solution_in == TRUE) { + use.solution_ptr = solution_bsearch (use.n_solution_user, &use.n_solution, FALSE); + if (use.solution_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", use.n_solution_user); + error_msg(error_string, STOP); + } + } +/* + * Find mixture + */ + if (use.mix_in == TRUE) { + use.mix_ptr = mix_bsearch(use.n_mix_user, &use.n_mix); + use.n_mix_user_orig = use.n_mix_user; + if (use.mix_ptr == NULL) { + sprintf(error_string, "Mixture %d not found.", use.n_mix_user); + error_msg(error_string, STOP); + } + } else { + use.mix_ptr = NULL; + } +/* + * Find pure phase assemblage + */ + if (use.pp_assemblage_in == TRUE) { + use.pp_assemblage_ptr = pp_assemblage_bsearch (use.n_pp_assemblage_user, &use.n_pp_assemblage); + if (use.pp_assemblage_ptr == NULL) { + sprintf(error_string, "Pure phase assemblage %d not found.", use.n_pp_assemblage_user); + error_msg(error_string, STOP); + } + } else { + use.pp_assemblage_ptr = NULL; + } +/* + * Find irrev reaction + */ + if (use.irrev_in == TRUE) { + use.irrev_ptr = irrev_bsearch(use.n_irrev_user, &use.n_irrev); + if (use.irrev_ptr == NULL) { + sprintf(error_string, "Irreversible reaction %d not found.", use.n_irrev_user); + error_msg(error_string, STOP); + } + } else { + use.irrev_ptr = NULL; + } +/* + * Find exchange + */ + if (use.exchange_in == TRUE) { + use.exchange_ptr = exchange_bsearch(use.n_exchange_user, &use.n_exchange); + if (use.exchange_ptr == NULL) { + sprintf(error_string, "Exchange %d not found.", use.n_exchange_user); + error_msg(error_string, STOP); + } + } else { + use.exchange_ptr = NULL; + } +/* + * Find kinetics + */ + if (use.kinetics_in == TRUE) { + use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &use.n_kinetics); + if (use.kinetics_ptr == NULL) { + sprintf(error_string, "Kinetics %d not found.", use.n_kinetics_user); + error_msg(error_string, STOP); + } + } else { + use.kinetics_ptr = NULL; + } +/* + * Find surface + */ + diffuse_layer_x = FALSE; + if (use.surface_in == TRUE) { + use.surface_ptr = surface_bsearch(use.n_surface_user, &use.n_surface); + if (use.surface_ptr == NULL) { + sprintf(error_string, "Surface %d not found.", use.n_surface_user); + error_msg(error_string, STOP); + } + } else { + use.surface_ptr = NULL; + } +/* + * Find temperature + */ + if (use.temperature_in == TRUE) { + use.temperature_ptr = temperature_bsearch(use.n_temperature_user, &use.n_temperature); + if (use.temperature_ptr == NULL) { + sprintf(error_string, "Temperature %d not found.", use.n_temperature_user); + error_msg(error_string, STOP); + } + } else { + use.temperature_ptr = NULL; + } +/* + * Find gas + */ + if (use.gas_phase_in == TRUE) { + use.gas_phase_ptr = gas_phase_bsearch(use.n_gas_phase_user, &use.n_gas_phase); + if (use.gas_phase_ptr == NULL) { + sprintf(error_string, "Gas_phase %d not found.", use.n_gas_phase_user); + error_msg(error_string, STOP); + } + } else { + use.gas_phase_ptr = NULL; + } +/* + * Find s_s_assemblage + */ + if (use.s_s_assemblage_in == TRUE) { + use.s_s_assemblage_ptr = s_s_assemblage_bsearch(use.n_s_s_assemblage_user, &use.n_s_s_assemblage); + if (use.s_s_assemblage_ptr == NULL) { + sprintf(error_string, "s_s_assemblage %d not found.", use.n_s_s_assemblage_user); + error_msg(error_string, STOP); + } + } else { + use.s_s_assemblage_ptr = NULL; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_solutions(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of solutions, make initial solution calculations + * for any marked "new". + */ + int i, converge, converge1; + int n, last, n_user, print1; + char token[2*MAX_LENGTH]; + + state = INITIAL_SOLUTION; + set_use(); + print1 = TRUE; + diffuse_layer_x = FALSE; + for (n=0; n < count_solution; n++) { + initial_solution_isotopes = FALSE; + if (solution[n] != NULL && solution[n]->new_def == TRUE) { + if (print1 == TRUE && print == TRUE) { + dup_print("Beginning of initial solution calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) { + sprintf(token, "Initial solution %d.\t%.350s", solution[n]->n_user, solution[n]->description); + dup_print(token, FALSE); + } + use.solution_ptr = solution[n]; + prep(); + k_temp(solution[n]->tc); + set(TRUE); + converge = model(); + converge1 = check_residuals(); + sum_species(); + add_isotopes(solution[n]); + punch_all(); + print_all(); + /* free_model_allocs(); */ + if (converge == ERROR || converge1 == ERROR) { + error_msg("Model failed to converge for initial solution.", STOP); + } + n_user = solution[n]->n_user; + last = solution[n]->n_user_end; + /* copy isotope data */ + if (solution[n]->count_isotopes > 0) { + count_isotopes_x = solution[n]->count_isotopes; + isotopes_x = (struct isotope *) PHRQ_realloc(isotopes_x, (size_t) count_isotopes_x * sizeof(struct isotope)); + if (isotopes_x == NULL) malloc_error(); + memcpy(isotopes_x, solution[n]->isotopes, (size_t) count_isotopes_x * sizeof(struct isotope)); + } else { + count_isotopes_x = 0; + } + xsolution_save(n_user); + for (i = n_user + 1; i <= last; i++) { + solution_duplicate(n_user, i); + } + } + } + initial_solution_isotopes = FALSE; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_exchangers(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of exchangers, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i, converge, converge1; + int n, last, n_user, print1; + char token[2*MAX_LENGTH]; + + state = INITIAL_EXCHANGE; + set_use(); + print1 = TRUE; + diffuse_layer_x = FALSE; + for (n=0; n < count_exchange; n++) { + if (exchange[n].new_def != TRUE) continue; + n_user = exchange[n].n_user; + last = exchange[n].n_user_end; + exchange[n].n_user_end = n_user; + if (exchange[n].solution_equilibria == TRUE) { + if (print1 == TRUE && print == TRUE) { + dup_print("Beginning of initial exchange" + "-composition calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) { + sprintf(token, "Exchange %d.\t%.350s", + exchange[n].n_user, + exchange[n].description); + dup_print(token, FALSE); + } + use.exchange_ptr = &(exchange[n]); + use.solution_ptr = solution_bsearch(exchange[n].n_solution, &i, TRUE); + if (use.solution_ptr == NULL) { + error_msg("Solution not found for initial exchange calculation", STOP); + } +#ifdef PHREEQC_XML +{ + // int n; + //SAX_StartSystem(); + //SAX_AddSolution(use.solution_ptr); + //SAX_EndSystem(); + //SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); + //SAX_cleanup(); + } +#endif + prep(); + k_temp(use.solution_ptr->tc); + set(TRUE); + converge = model(); + converge1 = check_residuals(); + sum_species(); + species_list_sort(); + print_exchange(); + xexchange_save(n_user); + punch_all(); + /* free_model_allocs(); */ + if (converge == ERROR || converge1 == ERROR) { + error_msg("Model failed to converge for initial exchange calculation.", STOP); + } + } + for (i = n_user + 1; i <= last; i++) { + exchange_duplicate(n_user, i); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_gas_phases(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of gas_phases, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i, converge, converge1; + int n, last, n_user, print1; + char token[2*MAX_LENGTH]; + struct gas_comp *gas_comp_ptr; + struct phase *phase_ptr; + struct rxn_token *rxn_ptr; + LDBLE lp; + + state = INITIAL_GAS_PHASE; + set_use(); + print1 = TRUE; + diffuse_layer_x = FALSE; + for (n=0; n < count_gas_phase; n++) { + if (gas_phase[n].new_def != TRUE) continue; + n_user = gas_phase[n].n_user; + last = gas_phase[n].n_user_end; + gas_phase[n].n_user_end = n_user; + if (gas_phase[n].solution_equilibria == TRUE) { + if (print1 == TRUE && print == TRUE) { + dup_print("Beginning of initial gas_phase" + "-composition calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) { + sprintf(token, "Gas_Phase %d.\t%.350s", + gas_phase[n].n_user, + gas_phase[n].description); + dup_print(token, FALSE); + } + use.solution_ptr = solution_bsearch(gas_phase[n].n_solution, &i, TRUE); + prep(); + k_temp(use.solution_ptr->tc); + set(TRUE); + converge = model(); + converge1 = check_residuals(); + if (converge == ERROR || converge1 == ERROR) { + /* free_model_allocs(); */ + error_msg("Model failed to converge for initial gas phase calculation.", STOP); + } + use.gas_phase_ptr = &(gas_phase[n]); + use.gas_phase_ptr->total_p = 0; + use.gas_phase_ptr->total_moles = 0; + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); + phase_ptr = gas_comp_ptr->phase; + if (phase_ptr->in == TRUE) { + lp=-phase_ptr->lk; + for (rxn_ptr=phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + gas_comp_ptr->phase->p_soln_x = exp(lp * LOG_10); + use.gas_phase_ptr->total_p += gas_comp_ptr->phase->p_soln_x; + gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * + use.gas_phase_ptr->volume / (R_LITER_ATM * tk_x); + gas_comp_ptr->moles = gas_comp_ptr->phase->moles_x; + use.gas_phase_ptr->total_moles += gas_comp_ptr->moles; + } else { + gas_comp_ptr->phase->moles_x = 0; + } + } + print_gas_phase(); + xgas_save(n_user); + punch_all(); + /* free_model_allocs(); */ + } + for (i = n_user + 1; i <= last; i++) { + gas_phase_duplicate(n_user, i); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_surfaces(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of surfaces, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i; + int n, last, n_user, print1; + char token[2*MAX_LENGTH]; + + state = INITIAL_SURFACE; + set_use(); + print1 = TRUE; + for (n=0; n < count_surface; n++) { + if (surface[n].new_def != TRUE) continue; + n_user = surface[n].n_user; + last = surface[n].n_user_end; + surface[n].n_user_end = n_user; + if (surface[n].solution_equilibria == TRUE) { + if (print1 == TRUE && print == TRUE) { + dup_print("Beginning of initial surface-composition calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) { + sprintf(token, "Surface %d.\t%.350s", + surface[n].n_user, + surface[n].description); + dup_print(token, FALSE); + } + use.surface_ptr = &(surface[n]); + diffuse_layer_x = use.surface_ptr->diffuse_layer; + use.solution_ptr = solution_bsearch(surface[n].n_solution, &i, TRUE); + if (use.solution_ptr == NULL) { + error_msg("Solution not found for initial surface calculation", STOP); + } +#ifdef SKIP + if (diffuse_layer_x == TRUE) { + converge = surface_model(); + } else { + prep(); + k_temp(use.solution_ptr->tc); + set(TRUE); + converge = model(); + } + converge1 = check_residuals(); + sum_species(); +#endif + set_and_run_wrapper(-1, FALSE, FALSE, -1, 0.0); + species_list_sort(); + print_surface(); + punch_all(); +#ifdef SKIP + if (converge == ERROR || converge1 == ERROR) { + /* free_model_allocs(); */ + error_msg("Model failed to converge for initial surface calculation.", STOP); + } +#endif + xsurface_save(n_user); + /* free_model_allocs(); */ + } + for (i = n_user + 1; i <= last; i++) { + surface_duplicate(n_user, i); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make all reaction calculation which could include: + * equilibrium with a pure-phase assemblage, + * equilibrium with an exchanger, + * equilibrium with an surface, + * equilibrium with a gas phase, + * equilibrium with a solid solution assemblage, + * kinetics, + * change of temperature, + * mixture, + * or irreversible reaction. + */ + int count_steps, use_mix, m; + char token[2*MAX_LENGTH]; + struct save save_data; + LDBLE kin_time; + struct kinetics *kinetics_ptr; + + state = REACTION; + /* last_model.force_prep = TRUE; */ + if (set_use() == FALSE) return(OK); +/* + * Find maximum number of steps + */ + dup_print ("Beginning of batch-reaction calculations.", TRUE); + count_steps = 1; + if (use.irrev_in == TRUE && use.irrev_ptr != NULL) { + if (abs(use.irrev_ptr->count_steps) > count_steps) + count_steps = abs(use.irrev_ptr->count_steps); + } + if (use.kinetics_in == TRUE && use.kinetics_ptr != NULL) { + if (abs(use.kinetics_ptr->count_steps) > count_steps) + count_steps = abs(use.kinetics_ptr->count_steps); + } + if (use.temperature_in == TRUE && use.temperature_ptr != NULL) { + if (abs(use.temperature_ptr->count_t) > count_steps) + count_steps = abs(use.temperature_ptr->count_t); + } + count_total_steps = count_steps; +/* + * save data for saving solutions + */ + memcpy(&save_data, &save, sizeof(struct save)); + /* + *Copy everything to -2 + */ + copy_use(-2); + rate_sim_time_start = 0; + rate_sim_time = 0; + for (reaction_step=1; reaction_step <= count_steps; reaction_step++) { + sprintf(token,"Reaction step %d.", reaction_step); + if (reaction_step > 1 && incremental_reactions == FALSE) { + copy_use(-2); + } + set_initial_moles(-2); + dup_print(token, FALSE); +/* + * Determine time step for kinetics + */ + kin_time = 0.0; + if ( use.kinetics_in == TRUE) { + kinetics_ptr = kinetics_bsearch(-2, &m); + if (incremental_reactions == FALSE) { + if (kinetics_ptr->count_steps > 0) { + if (reaction_step > kinetics_ptr->count_steps) { + kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } else { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } else if (kinetics_ptr->count_steps < 0) { + if (reaction_step > -kinetics_ptr->count_steps) { + kin_time = kinetics_ptr->steps[0]; + } else { + kin_time = reaction_step * kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); + } + } + } else { + /* incremental reactions */ + if (kinetics_ptr->count_steps > 0) { + if (reaction_step > kinetics_ptr->count_steps) { + kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } else { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } else if (kinetics_ptr->count_steps < 0) { + if (reaction_step > -kinetics_ptr->count_steps) { + kin_time = 0; + } else { + kin_time = kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + } + if (incremental_reactions == FALSE || + (incremental_reactions == TRUE && reaction_step == 1)) { + use_mix = TRUE; + } else { + use_mix = FALSE; + } +/* + * Run reaction step + */ + run_reactions(-2, kin_time, use_mix, 1.0); + if (incremental_reactions == TRUE) { + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start; + } else { + rate_sim_time = kin_time; + } + if (state != ADVECTION) { + punch_all(); + print_all(); + } + /* saves back into -2 */ + if (reaction_step < count_steps) { + saver(); + } + } +/* + * save end of reaction + */ + memcpy(&save, &save_data, sizeof(struct save)); + if (use.kinetics_in == TRUE) { + kinetics_duplicate(-2, use.n_kinetics_user); + } + saver(); + + /* free_model_allocs(); */ + /* last_model.force_prep = TRUE; */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int saver(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save results of calcuations (data in variables with _x, + * in unknown structure x, in master, or s) into structure + * arrays. Structure "save" has info on whether to save + * data for each entity (solution, ex, surf, pp, gas, or s_s). + * Initial calculation may be saved into multiple "n_user" + * slots. + */ + int i, n; + char token[MAX_LENGTH]; + + if (save.solution == TRUE) { + sprintf(token, "Solution after simulation %d.", simulation); + description_x = (char *) free_check_null(description_x); + description_x = string_duplicate(token); + n = save.n_solution_user; + xsolution_save(n); + for(i = save.n_solution_user + 1; i <= save.n_solution_user_end; i++) { + solution_duplicate(n, i); + } + } + if (save.pp_assemblage == TRUE) { + n = save.n_pp_assemblage_user; + xpp_assemblage_save(n); + for(i = save.n_pp_assemblage_user + 1; i <= save.n_pp_assemblage_user_end; i++) { + pp_assemblage_duplicate(n, i); + } + } + if (save.exchange == TRUE) { + n = save.n_exchange_user; + xexchange_save(n); + for(i = save.n_exchange_user + 1; i <= save.n_exchange_user_end; i++) { + exchange_duplicate(n, i); + } + } + if (save.surface == TRUE) { + n = save.n_surface_user; + xsurface_save(n); + for(i = save.n_surface_user + 1; i <= save.n_surface_user_end; i++) { + surface_duplicate(n, i); + } + } + if (save.gas_phase == TRUE) { + n = save.n_gas_phase_user; + xgas_save(n); + for(i = save.n_gas_phase_user + 1; i <= save.n_gas_phase_user_end; i++) { + gas_phase_duplicate(n, i); + } + } + if (save.s_s_assemblage == TRUE) { + n = save.n_s_s_assemblage_user; + xs_s_assemblage_save(n); + for(i = save.n_s_s_assemblage_user + 1; i <= save.n_s_s_assemblage_user_end; i++) { + s_s_assemblage_duplicate(n, i); + } + } + if (save.kinetics == TRUE && use.kinetics_in == TRUE && use.kinetics_ptr != NULL) { + n = use.kinetics_ptr->n_user; + for(i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) { + kinetics_duplicate(n, i); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int xexchange_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save exchanger assemblage into structure exchange with user + * number n_user. + */ + int i, j, n; + char token[MAX_LENGTH]; + int count_comps; + struct exchange temp_exchange, *exchange_ptr; + LDBLE charge; + if (use.exchange_ptr == NULL) return(OK); +/* + * Store data for structure exchange + */ + memcpy(&temp_exchange, use.exchange_ptr, sizeof(struct exchange)); + temp_exchange.n_user = n_user; + temp_exchange.n_user_end = n_user; + temp_exchange.new_def = FALSE; + sprintf(token, "Exchange assemblage after simulation %d.", simulation); + temp_exchange.description = string_duplicate(token); + temp_exchange.solution_equilibria = FALSE; + temp_exchange.n_solution = -2; + temp_exchange.count_comps = 0; +/* + * Count exchange components and allocate space + */ + count_comps = 0; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == EXCH) count_comps++; + } + temp_exchange.comps = (struct exch_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct exch_comp)); + if (temp_exchange.comps == NULL) malloc_error(); + temp_exchange.count_comps = count_comps; +/* + * Write exch_comp structure for each exchange component + */ + count_comps = 0; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == EXCH) { + memcpy(&temp_exchange.comps[count_comps], x[i]->exch_comp, sizeof(struct exch_comp)); + temp_exchange.comps[count_comps].master = x[i]->master[0]; + temp_exchange.comps[count_comps].la = x[i]->master[0]->s->la; + temp_exchange.comps[count_comps].formula_totals = elt_list_dup(x[i]->exch_comp->formula_totals); + temp_exchange.comps[count_comps].moles = 0.; +/* + * Save element concentrations on exchanger + */ + count_elts = 0; + paren_count = 0; + charge = 0.0; + for (j=0; j < count_species_list; j++) { + if (species_list[j].master_s == x[i]->master[0]->s) { + add_elt_list(species_list[j].s->next_elt, species_list[j].s->moles); + charge += species_list[j].s->moles * species_list[j].s->z; + } + } +/* + * Keep exchanger related to phase even if none currently in solution + */ + if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) { + add_elt_list(x[i]->master[0]->s->next_elt, 1e-20); + } +/* + * Store list + */ + temp_exchange.comps[count_comps].charge_balance = charge; + temp_exchange.comps[count_comps].totals = elt_list_save(); +/* debug + output_msg(OUTPUT_MESSAGE, "Exchange charge_balance: %e\n", charge); + */ + /* update unknown pointer */ + x[i]->exch_comp = &(temp_exchange.comps[count_comps]); + count_comps++; + } + } +/* + * Finish up + */ + exchange_ptr = exchange_bsearch(n_user, &n); + if (exchange_ptr == NULL) { + n = count_exchange++; + space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); + } else { + exchange_free(&exchange[n]); + } + memcpy(&exchange[n], &temp_exchange, sizeof(struct exchange)); + /* sort only if necessary */ + if (n == count_exchange - 1 && count_exchange > 1) { + if (exchange[n].n_user < exchange[n-1].n_user) { + qsort (exchange, + (size_t) count_exchange, + (size_t) sizeof (struct exchange), + exchange_compare); + } + } + use.exchange_ptr = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int xgas_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save gas composition into structure gas_phase with user + * number n_user. + */ + int count_comps, n, i; + struct gas_phase temp_gas_phase, *gas_phase_ptr; + char token[MAX_LENGTH]; + + if (use.gas_phase_ptr == NULL) return(OK); +/* + * Count gases + */ + count_comps = use.gas_phase_ptr->count_comps; +/* + * Malloc space and copy + */ + temp_gas_phase.comps = (struct gas_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct gas_comp)); + if (temp_gas_phase.comps == NULL) malloc_error(); + memcpy( (void *) temp_gas_phase.comps, (void *) use.gas_phase_ptr->comps, (size_t) count_comps * sizeof(struct gas_comp) ); +/* + * Store in gas_phase + */ + + temp_gas_phase.n_user = n_user; + temp_gas_phase.n_user_end = n_user; + sprintf(token, "Gas phase after simulation %d.", simulation); + temp_gas_phase.description = string_duplicate(token); + temp_gas_phase.new_def = FALSE; + temp_gas_phase.solution_equilibria = FALSE; + temp_gas_phase.n_solution = -99; + temp_gas_phase.type = use.gas_phase_ptr->type; + temp_gas_phase.total_p = use.gas_phase_ptr->total_p; + temp_gas_phase.total_moles = use.gas_phase_ptr->total_moles; + temp_gas_phase.volume = use.gas_phase_ptr->volume; + temp_gas_phase.temperature = use.gas_phase_ptr->temperature; + temp_gas_phase.count_comps = count_comps; +/* + * Update amounts + */ + for (i = 0; i < count_comps; i++) { + temp_gas_phase.comps[i].moles = use.gas_phase_ptr->comps[i].phase->moles_x; + } +/* + * Finish up + */ + gas_phase_ptr = gas_phase_bsearch(n_user, &n); + if (gas_phase_ptr == NULL) { + n = count_gas_phase++; + space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); + } else { + gas_phase_free(&gas_phase[n]); + } + memcpy(&gas_phase[n], &temp_gas_phase, sizeof(struct gas_phase)); + + /* update unknown pointer */ + if (gas_unknown != NULL) { + gas_unknown->gas_phase = &(gas_phase[n]); + } + /* sort only if necessary */ + if (n == count_gas_phase - 1 && count_gas_phase > 1) { + if (gas_phase[n].n_user < gas_phase[n-1].n_user) { + qsort (gas_phase, + (size_t) count_gas_phase, + (size_t) sizeof (struct gas_phase), + gas_phase_compare); + } + } + use.gas_phase_ptr = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int xs_s_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save s_s_assemblage composition into structure s_s_assemblage with user + * number n_user. + */ + int i, j, n; + int count_comps, count_s_s; + struct s_s_assemblage temp_s_s_assemblage, *s_s_assemblage_ptr; + char token[MAX_LENGTH]; + + if (use.s_s_assemblage_ptr == NULL) return(OK); +/* + * Set s_s_assemblage + */ + temp_s_s_assemblage.n_user = n_user; + temp_s_s_assemblage.n_user_end = n_user; + sprintf(token, "Solid solution assemblage after simulation %d.", simulation); + temp_s_s_assemblage.description = string_duplicate(token); + temp_s_s_assemblage.new_def = FALSE; +#ifdef SKIP + temp_s_s_assemblage.type = use.s_s_assemblage_ptr->type; + temp_s_s_assemblage.solution_equilibria = FALSE; + temp_s_s_assemblage.n_solution = -99; +#endif + count_s_s = use.s_s_assemblage_ptr->count_s_s; + temp_s_s_assemblage.count_s_s = count_s_s; +/* + * Malloc space for solid solutions + */ + /* s_s_assemblage->s_s */ + temp_s_s_assemblage.s_s = (struct s_s *) PHRQ_malloc( (size_t) count_s_s * sizeof(struct s_s)); + if (temp_s_s_assemblage.s_s == NULL) malloc_error(); + for (i = 0; i < count_s_s; i++) { + memcpy(&(temp_s_s_assemblage.s_s[i]), &(use.s_s_assemblage_ptr->s_s[i]), sizeof(struct s_s)); + /* + * Malloc space for solid soution components + */ + count_comps = use.s_s_assemblage_ptr->s_s[i].count_comps; + temp_s_s_assemblage.s_s[i].comps = (struct s_s_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct s_s_comp)); + if (temp_s_s_assemblage.s_s[i].comps == NULL) malloc_error(); + memcpy( (void *) temp_s_s_assemblage.s_s[i].comps, (void *) use.s_s_assemblage_ptr->s_s[i].comps, (size_t) count_comps * sizeof(struct s_s_comp) ); + + /* set initial moles for quick setup*/ + for (j = 0; j < count_comps; j++) { + temp_s_s_assemblage.s_s[i].comps[j].initial_moles = temp_s_s_assemblage.s_s[i].comps[j].moles; + } + } +/* + * Finish up + */ + s_s_assemblage_ptr = s_s_assemblage_bsearch(n_user, &n); + if (s_s_assemblage_ptr == NULL) { + space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + n = count_s_s_assemblage++; + } else { + s_s_assemblage_free(&s_s_assemblage[n]); + } + memcpy(&s_s_assemblage[n], &temp_s_s_assemblage, sizeof(struct s_s_assemblage)); + /* sort only if necessary */ + if (n == count_s_s_assemblage - 1 && count_s_s_assemblage > 1) { + if (s_s_assemblage[n].n_user < s_s_assemblage[n-1].n_user) { + qsort (s_s_assemblage, + (size_t) count_s_s_assemblage, + (size_t) sizeof (struct s_s_assemblage), + s_s_assemblage_compare); + } + } + use.s_s_assemblage_ptr = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int xpp_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save pure_phase assemblage into structure pp_assemblage with user + * number n_user. + */ + int count_comps, n, j, i; + struct pp_assemblage temp_pp_assemblage, *pp_assemblage_ptr; + char token[MAX_LENGTH]; + + if (use.pp_assemblage_ptr == NULL) return(OK); +/* + * Count pure phases + */ + count_comps = use.pp_assemblage_ptr->count_comps; + + temp_pp_assemblage.n_user = n_user; + temp_pp_assemblage.n_user_end = n_user; + sprintf(token, "Pure-phase assemblage after simulation %d.", simulation); + temp_pp_assemblage.description = string_duplicate(token); + temp_pp_assemblage.new_def = FALSE; + temp_pp_assemblage.count_comps = count_comps; + temp_pp_assemblage.next_elt = elt_list_dup(use.pp_assemblage_ptr->next_elt); +/* + * Malloc space and copy pure phase data + */ + temp_pp_assemblage.pure_phases = (struct pure_phase *) PHRQ_malloc( (size_t) count_comps * sizeof(struct pure_phase)); + if (temp_pp_assemblage.pure_phases == NULL) malloc_error(); + memcpy( (void *) temp_pp_assemblage.pure_phases, (void *) use.pp_assemblage_ptr->pure_phases, (size_t) count_comps * sizeof(struct pure_phase) ); +/* + * Update amounts + */ + i = 0; + for (j=0; j < count_unknowns; j++) { + if (x[j]->type != PP) continue; + temp_pp_assemblage.pure_phases[i].moles = x[j]->moles; + temp_pp_assemblage.pure_phases[i].delta = 0.0; + + /* update unknown ptr, old may be freed later */ + x[j]->pure_phase = &(temp_pp_assemblage.pure_phases[i]); + i++; + } +/* + * Finish up + */ + pp_assemblage_ptr = pp_assemblage_bsearch(n_user, &n); + if (pp_assemblage_ptr == NULL) { + space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); + n = count_pp_assemblage++; + } else { + pp_assemblage_free(&pp_assemblage[n]); + } + memcpy(&pp_assemblage[n], &temp_pp_assemblage, sizeof(struct pp_assemblage)); + /* sort only if necessary */ + if (n == count_pp_assemblage - 1 && count_pp_assemblage > 1) { + if (pp_assemblage[n].n_user < pp_assemblage[n-1].n_user) { + qsort (pp_assemblage, + (size_t) count_pp_assemblage, + (size_t) sizeof (struct pp_assemblage), + pp_assemblage_compare); + } + } + use.pp_assemblage_ptr = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int xsolution_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save solution composition into structure solution with user number + * n_user. + * + * input: n_user is user solution number of target + */ + int i, j, n; + int count_mass_balance, count_master_activity; + int max_mass_balance, max_master_activity; + struct solution *solution_ptr; + struct master *master_i_ptr, *master_ptr; +/* + * Malloc space for solution data + */ + solution_ptr = solution_alloc(); + + max_mass_balance=MAX_MASS_BALANCE; + max_master_activity=MAX_MASS_BALANCE; + + solution_ptr->n_user = n_user; + solution_ptr->n_user_end = n_user; + solution_ptr->new_def = FALSE; + solution_ptr->description = string_duplicate(description_x); + solution_ptr->tc = tc_x; + solution_ptr->ph = ph_x; + solution_ptr->solution_pe = solution_pe_x; + solution_ptr->mu = mu_x; + solution_ptr->ah2o = ah2o_x; + solution_ptr->density = density_x; + solution_ptr->total_h = total_h_x; + solution_ptr->total_o = total_o_x; + solution_ptr->cb = cb_x; /* cb_x does not include surface charge sfter sum_species */ + /* does include surface charge after step */ + + solution_ptr->mass_water = mass_water_aq_x; + solution_ptr->total_alkalinity = total_alkalinity; + /*solution_ptr->total_co2 = total_co2;*/ + solution_ptr->units = moles_per_kilogram_string; +/* + * Copy pe data + */ + + pe_data_free(solution_ptr->pe); + /*solution_ptr->pe = pe_data_dup(pe_x); */ + solution_ptr->pe = pe_data_alloc(); + solution_ptr->default_pe = 0; + /* + * Add in minor isotopes if initial solution calculation + */ + if (initial_solution_isotopes == TRUE) { + for (i = 0; i < count_master_isotope; i++) { + if (master_isotope[i]->moles > 0) { + master_i_ptr = master_bsearch(master_isotope[i]->name); + master_ptr = master_isotope[i]->elt->master; + if (master_isotope[i]->minor_isotope == TRUE) { + master_i_ptr->total = master_isotope[i]->moles; + if (master_ptr->total > 0) { + master_i_ptr->s->la = master_ptr->s->la + log10(master_i_ptr->total / master_ptr->total); + } else { + master_i_ptr->s->la = master_ptr->s->la; + } + } else if (master_isotope[i]->minor_isotope == FALSE && master_ptr->s != s_hplus && master_ptr->s != s_h2o) { + if (master_ptr->s->secondary != NULL) { + master_ptr->s->secondary->total = master_isotope[i]->moles; + } else { + master_ptr->s->primary->total = master_isotope[i]->moles; + } + } + } + } + } +/* + * Copy totals data + */ + count_mass_balance = 0; + count_master_activity = 0; + for (i=0; i < count_master; i++) { + if (master[i]->s->type == EX || + master[i]->s->type == SURF || + master[i]->s->type == SURF_PSI) continue; + if (strcmp(master[i]->elt->name,"H") == 0 || + strcmp(master[i]->elt->name,"H(1)") == 0 || + strcmp(master[i]->elt->name,"O") == 0 || + strcmp(master[i]->elt->name,"O(-2)") == 0) continue; +/* + * Save list of log activities + */ + if (master[i]->in != FALSE) { + count_master_activity++; + } + } + solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(solution_ptr->master_activity, (size_t) (count_master_activity + 1)*sizeof(struct master_activity)); + solution_ptr->count_master_activity = count_master_activity; + count_master_activity = 0; + for (i=0; i < count_master; i++) { + if (master[i]->s->type == EX || + master[i]->s->type == SURF || + master[i]->s->type == SURF_PSI) continue; + if (strcmp(master[i]->elt->name,"H") == 0 || + strcmp(master[i]->elt->name,"H(1)") == 0 || + strcmp(master[i]->elt->name,"O") == 0 || + strcmp(master[i]->elt->name,"O(-2)") == 0) continue; +/* + * Save list of log activities + */ + if (master[i]->in != FALSE) { + solution_ptr->master_activity[count_master_activity].description = master[i]->elt->name; + solution_ptr->master_activity[count_master_activity++].la = master[i]->s->la; + /* + if (count_master_activity + 2 >= max_master_activity) { + space ((void *) &(solution_ptr->master_activity), count_master_activity + 2, + &max_master_activity, sizeof (struct master_activity)); + } + */ + } + if (master[i]->total <= MIN_TOTAL) { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + continue; + } +/* if (master[i]->total <= 0.0) continue; */ +/* + * Save list of concentrations + */ + solution_ptr->totals[count_mass_balance].description = master[i]->elt->name; + solution_ptr->totals[count_mass_balance].input_conc = master[i]->total; + solution_ptr->totals[count_mass_balance].moles = master[i]->total; + solution_ptr->totals[count_mass_balance].units = solution_ptr->units; + solution_ptr->totals[count_mass_balance].equation_name = NULL; + solution_ptr->totals[count_mass_balance].n_pe = 0; + solution_ptr->totals[count_mass_balance].phase = NULL; + solution_ptr->totals[count_mass_balance].phase_si = 0.0; + solution_ptr->totals[count_mass_balance].as = NULL; + solution_ptr->totals[count_mass_balance].gfw = 0.0; + count_mass_balance++; +/* + * Make space + */ + if (count_mass_balance + 2 >= max_mass_balance) { + space ((void **) &(solution_ptr->totals), count_mass_balance + 2, + &max_mass_balance, sizeof (struct conc)); + } + } + if (pitzer_model == TRUE) { + i = 0; + for (j = 0; j < count_s; j++) { + if (s[j]->lg != 0.0) i++; + } + solution_ptr->species_gamma = (struct master_activity *) PHRQ_realloc(solution_ptr->species_gamma, (size_t) (i * sizeof(struct master_activity))); + i = 0; + for (j= 0; j < count_s; j++) { + if (s[j]->lg != 0.0) { + solution_ptr->species_gamma[i].la = s[j]->lg; + solution_ptr->species_gamma[i].description = s[j]->name; + i++; + } + } + solution_ptr->count_species_gamma = i; + } else { + solution_ptr->species_gamma = NULL; + solution_ptr->count_species_gamma = 0; + } +/* + * Mark end of totals + */ + solution_ptr->totals[count_mass_balance].description = NULL; + count_mass_balance++; + solution_ptr->master_activity[count_master_activity].description = NULL; + count_master_activity++; + solution_ptr->totals = (struct conc *) PHRQ_realloc(solution_ptr->totals, (size_t) count_mass_balance * sizeof(struct conc)); + if (solution_ptr->totals == NULL) malloc_error(); + solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(solution_ptr->master_activity, (size_t) count_master_activity * sizeof(struct master_activity)); + if (solution_ptr->master_activity == NULL) malloc_error(); + solution_ptr->count_master_activity = count_master_activity; +/* + * Save isotope data + */ + if (count_isotopes_x > 0 ) { + solution_ptr->count_isotopes = count_isotopes_x; + solution_ptr->isotopes = (struct isotope *) PHRQ_realloc(solution_ptr->isotopes, (size_t) count_isotopes_x * sizeof(struct isotope)); + if (solution_ptr->isotopes == NULL) malloc_error(); + memcpy(solution_ptr->isotopes, isotopes_x, (size_t) count_isotopes_x * sizeof(struct isotope)); + for (i = 0; i < count_isotopes_x; i++) { + solution_ptr->isotopes[i].total = solution_ptr->isotopes[i].master->total; + if (solution_ptr->isotopes[i].master == s_hplus->secondary) { + solution_ptr->isotopes[i].total = 2 * mass_water_aq_x / gfw_water; + } + if (solution_ptr->isotopes[i].master == s_h2o->secondary) { + solution_ptr->isotopes[i].total = mass_water_aq_x / gfw_water; + } + } + } else { + solution_ptr->count_isotopes = 0; + solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); + solution_ptr->isotopes = NULL; + } +/* + * Save solution in solution + */ + if (solution_bsearch (n_user, &n, FALSE) != NULL) { + solution_free(solution[n]); + } else { + n = count_solution++; + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); + } + } + solution[n] = solution_ptr; + /* sort only if necessary */ + if (count_solution > 1 && (solution[count_solution -1]->n_user < solution[count_solution - 2]->n_user)) { + solution_sort(); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int xsurface_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save surface data into structure surface with user + * number n_user. + */ + int i, j, n, last_charge; + int count_comps, count_charge; + char token[MAX_LENGTH]; + struct surface temp_surface, *surface_ptr; + LDBLE charge; + + if (use.surface_ptr == NULL) return(OK); +/* + * Store data for structure surface + */ + memcpy(&temp_surface, use.surface_ptr, sizeof(struct surface)); + temp_surface.n_user = n_user; + temp_surface.n_user_end = n_user; + temp_surface.new_def = FALSE; + temp_surface.diffuse_layer = diffuse_layer_x; + sprintf(token, "Surface assemblage after simulation %d.", simulation); + temp_surface.description = string_duplicate(token); + temp_surface.solution_equilibria = FALSE; + temp_surface.n_solution = -10; +/* + * Allocate space to pointer comps + */ + + count_comps = use.surface_ptr->count_comps; + count_charge = use.surface_ptr->count_charge; + temp_surface.count_comps = count_comps; + temp_surface.comps = (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct surface_comp)); + if (temp_surface.comps == NULL) malloc_error(); + if (temp_surface.edl == FALSE) { + temp_surface.charge = NULL; + temp_surface.count_charge = 0; + } else { + temp_surface.count_charge = count_charge; + temp_surface.charge = (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * sizeof (struct surface_charge)); + if (temp_surface.charge == NULL) malloc_error(); + } +/* + * Write surface_comp structure for each surf component into comps_ptr + */ + count_comps = 0; + count_charge = 0; + /* + * Initial entry of surface sites is random + * Charge balance numbering follows the initial entry + * Surface sites are then sorted alphabetically + * Now when we save, the site order differs from the charge order + * last_charge sets up logic to renumber charge balance equations. + */ + last_charge = -1; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == SURFACE) { + memcpy(&temp_surface.comps[count_comps], x[i]->surface_comp, sizeof(struct surface_comp)); + + temp_surface.comps[count_comps].master = x[i]->master[0]; + temp_surface.comps[count_comps].la = x[i]->master[0]->s->la; + /* temp_surface.comps[count_comps].formula = NULL; */ + temp_surface.comps[count_comps].moles = 0.; + if (x[i]->surface_comp->charge == last_charge) { + temp_surface.comps[count_comps].charge = count_charge - 1; + } else { + temp_surface.comps[count_comps].charge = count_charge; + } + last_charge = x[i]->surface_comp->charge; +/* + * Save element concentrations on surface + */ + count_elts = 0; + paren_count = 0; + charge = 0.0; + for (j=0; j < count_species_list; j++) { + if (species_list[j].master_s == x[i]->master[0]->s) { + add_elt_list(species_list[j].s->next_elt, species_list[j].s->moles); + charge += species_list[j].s->moles * + species_list[j].s->z; + } + } + temp_surface.comps[count_comps].totals = elt_list_save(); + temp_surface.comps[count_comps].cb = charge; + + /* update unknown pointer */ + x[i]->surface_comp = &(temp_surface.comps[count_comps]); + count_comps++; + } else if (x[i]->type == SURFACE_CB) { + memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, sizeof(struct surface_charge)); + temp_surface.charge[count_charge].charge_balance = x[i]->f; + temp_surface.charge[count_charge].mass_water = x[i]->surface_charge->mass_water; + temp_surface.charge[count_charge].diffuse_layer_totals = NULL; + temp_surface.charge[count_charge].count_g = 0; + temp_surface.charge[count_charge].g = NULL; +/* + * Added code to save g + */ +/* + if (x[i]->surface_charge->count_g > 0) { + temp_surface.charge[count_charge].count_g = x[i]->surface_charge->count_g; + temp_surface.charge[count_charge].g = (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]->surface_charge->count_g * sizeof(struct surface_diff_layer)); + if (temp_surface.charge[count_charge].g == NULL) malloc_error(); + memcpy(temp_surface.charge[count_charge].g, x[i]->surface_charge->g, (size_t) x[i]->surface_charge->count_g * sizeof(struct surface_diff_layer)); + } +*/ + temp_surface.charge[count_charge].psi_master = x[i]->master[0]; + temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; +/* + * Store moles from diffuse_layer + */ + if (diffuse_layer_x == TRUE) { + sum_diffuse_layer(x[i]->surface_charge); + temp_surface.charge[count_charge].diffuse_layer_totals = elt_list_save(); + } + + /* update unknown pointer */ + x[i]->surface_charge = &(temp_surface.charge[count_charge]); + x[i]->surface_comp = x[i - 1]->surface_comp; + + count_charge++; + } + } +/* + * Finish up + */ + surface_ptr = surface_bsearch(n_user, &n); + if (surface_ptr == NULL) { + n = count_surface++; + space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); + } else { + surface_free(&surface[n]); + } + memcpy(&surface[n], &temp_surface, sizeof(struct surface)); + if (n == count_surface - 1 && count_surface > 1) { + if (surface[n].n_user < surface[n-1].n_user) { + qsort (surface, + (size_t) count_surface, + (size_t) sizeof (struct surface), + surface_compare); + } + } + use.surface_ptr = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +FILE *file_open (char *query, char *default_name, const char *status, int batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH], answer[MAX_LENGTH]; + FILE *new_file; + int l; + + for (;;) { +/* + * Get file name + */ + strcpy(name, default_name); + if (batch == FALSE) { + output_msg(OUTPUT_SCREEN,"%s\n", query); + if (default_name[0] != '\0') { + output_msg(OUTPUT_SCREEN,"Default: %s\n", default_name); + } + fgets(name, MAX_LENGTH, stdin); + l = strlen(name); + name[l-1]='\0'; + if (name[0] == '\0') { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + if (status[0] == 'r') { + if ((new_file = fopen(name, "r")) == NULL) { + sprintf(error_string, "Can't open file, %s.", name); + output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); + output_fflush(OUTPUT_SCREEN); + batch = FALSE; + continue; + } + break; +/* + * Open file to write, no check + */ + } else if (status[0] == 'w') { + if ((new_file = fopen(name, "w")) == NULL) { + sprintf(error_string, "Error opening file, %s.", name); + output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); + output_fflush(OUTPUT_SCREEN); + batch = FALSE; + continue; + } + break; +/* + * Open file to write, check for existence + */ + } else if (status[0] == 'c') { + for (;;) { + if ((new_file = fopen(name, "r")) != NULL) { + fclose(new_file); + output_msg(OUTPUT_SCREEN,"Warning: File already exists, %s.\n" + "Enter new file name or to overwrite:", name); + fgets(answer, MAX_LENGTH, stdin); + l = strlen(answer); + answer[l-1]='\0'; + if (answer != '\0') { + strcpy(name, answer); + continue; + } + } + break; + } + if ((new_file = fopen(name, "w")) == NULL) { + sprintf(error_string, "Error opening file, %s.", name) ; + output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); + output_fflush(OUTPUT_SCREEN); + batch = FALSE; + continue; + } + break; + } + } + strncpy(default_name, name, MAX_LENGTH); + return(new_file); +} +/* ---------------------------------------------------------------------- */ +int copy_use (int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find mixture + */ + if (use.mix_in == TRUE) { + mix_duplicate(use.n_mix_user, i); + } +/* + * Find solution + */ + if (use.solution_in == TRUE) { + solution_duplicate(use.n_solution_user, i); + } +/* + * Always save solution to i, mixing or not + */ + save.solution = TRUE; + save.n_solution_user = i; + save.n_solution_user_end = i; +/* + * Find pure phase assemblage + */ + if (use.pp_assemblage_in == TRUE) { + pp_assemblage_duplicate(use.n_pp_assemblage_user, i); + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } else { + save.pp_assemblage = FALSE; + } +/* + * Find irrev reaction + */ + if (use.irrev_in == TRUE) { + irrev_duplicate(use.n_irrev_user, i); + save.irrev = TRUE; + save.n_irrev_user = i; + save.n_irrev_user_end = i; + } else { + save.irrev = FALSE; + } +/* + * Find exchange + */ + if (use.exchange_in == TRUE) { + exchange_duplicate(use.n_exchange_user, i); + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } else { + save.exchange = FALSE; + } +/* + * Find kinetics + */ + if (use.kinetics_in == TRUE) { + kinetics_duplicate(use.n_kinetics_user, i); + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } else { + save.kinetics = FALSE; + } +/* + * Find surface + */ + diffuse_layer_x = FALSE; + if (use.surface_in == TRUE) { + surface_duplicate(use.n_surface_user, i); + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } else { + save.surface = FALSE; + } +/* + * Find temperature + */ + if (use.temperature_in == TRUE) { + temperature_duplicate(use.n_temperature_user, i); + } +/* + * Find gas + */ + if (use.gas_phase_in == TRUE) { + gas_phase_duplicate(use.n_gas_phase_user, i); + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } else { + save.gas_phase = FALSE; + } +/* + * Find solid solution + */ + if (use.s_s_assemblage_in == TRUE) { + s_s_assemblage_duplicate(use.n_s_s_assemblage_user, i); + save.s_s_assemblage = TRUE; + save.n_s_s_assemblage_user = i; + save.n_s_s_assemblage_user_end = i; + } else { + save.s_s_assemblage = FALSE; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int step_save_exch(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save solution composition into structure solution with user number + * n_user. + * + * input: n_user is user solution number of target + */ + int i, j, k, n; + int found; + struct exchange *exchange_ptr; +/* + * Malloc space for solution data + */ + if (use.exchange_ptr == NULL) return(OK); + exchange_duplicate(use.exchange_ptr->n_user, n_user); + exchange_ptr = exchange_bsearch(n_user, &n); + for (i=0; i < count_master; i++) { + if (master[i]->s->type != EX) continue; + found = FALSE; + for (j = 0; j < exchange_ptr->count_comps; j++) { + for (k = 0; exchange_ptr->comps[j].totals[k].elt != NULL; k++ ) { + if(exchange_ptr->comps[j].totals[k].elt == master[i]->elt) { + if (found == FALSE) { + found = TRUE; + if (master[i]->total <= MIN_TOTAL) { + exchange_ptr->comps[j].totals[k].coef = MIN_TOTAL; + } else { + exchange_ptr->comps[j].totals[k].coef = master[i]->total; + } + break; + } else { + exchange_ptr->comps[j].totals[k].coef = 0; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int step_save_surf(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save surface for intermediate calculation + * Amt of surface may have changed due to reaction or surface related + * to kinetic reactant. + * + * input: n_user is user solution number of target + */ + int i, j, k, n, m; + struct surface *surface_ptr; +/* + * Malloc space for solution data + */ + if (use.surface_ptr == NULL) return(OK); + surface_duplicate(use.surface_ptr->n_user, n_user); + surface_ptr = surface_bsearch(n_user, &n); + for (i=0; i < count_master; i++) { + if (master[i]->s->type != SURF) continue; + for (j = 0; j < surface_ptr->count_comps; j++) { + for (k = 0; surface_ptr->comps[j].totals[k].elt != NULL; k++ ) { + if(surface_ptr->comps[j].totals[k].elt == master[i]->elt) { + if (master[i]->total <= MIN_TOTAL) { + surface_ptr->comps[j].totals[k].coef = MIN_TOTAL; + } else { + surface_ptr->comps[j].totals[k].coef = master[i]->total; + } + break; + } + } + } + } + /* + * Update grams + */ + if (surface_ptr->edl == TRUE && surface_ptr->related_rate == TRUE && use.kinetics_ptr != NULL) { + for (j = 0; j < surface_ptr->count_comps; j++) { + if (surface_ptr->comps[j].rate_name != NULL) { + for (m = 0; m < use.kinetics_ptr->count_comps; m++) { + if (strcmp_nocase(use.kinetics_ptr->comps[m].rate_name, surface_ptr->comps[j].rate_name) != 0) continue; + surface_ptr->charge[surface_ptr->comps[j].charge].grams = use.kinetics_ptr->comps[m].m; + break; + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int copy_entities(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, n, return_value; + return_value = OK; + if (copy_solution.count > 0) { + for (j = 0; j < copy_solution.count; j++) { + if (solution_bsearch(copy_solution.n_user[j], &n, FALSE) != NULL) { + for (i = copy_solution.start[j]; i <= copy_solution.end[j]; i++) { + if (i == copy_solution.n_user[j]) continue; + solution_duplicate(copy_solution.n_user[j], i); + } + } else { + warning_msg("SOLUTION to copy not found."); + return_value = ERROR; + } + } + } + if (copy_pp_assemblage.count > 0) { + for (j = 0; j < copy_pp_assemblage.count; j++) { + if (pp_assemblage_bsearch(copy_pp_assemblage.n_user[j], &n) != NULL) { + for (i = copy_pp_assemblage.start[j]; i <= copy_pp_assemblage.end[j]; i++) { + if (i == copy_pp_assemblage.n_user[j]) continue; + pp_assemblage_duplicate(copy_pp_assemblage.n_user[j], i); + } + } else { + warning_msg("EQUILIBRIUM_PHASES to copy not found."); + return_value = ERROR; + } + } + } + if (copy_irrev.count > 0) { + for (j = 0; j < copy_irrev.count; j++) { + if (irrev_bsearch(copy_irrev.n_user[j], &n) != NULL) { + for (i = copy_irrev.start[j]; i <= copy_irrev.end[j]; i++) { + if (i == copy_irrev.n_user[j]) continue; + irrev_duplicate(copy_irrev.n_user[j], i); + } + } else { + warning_msg("REACTION to copy not found."); + return_value = ERROR; + } + } + } + if (copy_mix.count > 0) { + for (j = 0; j < copy_mix.count; j++) { + if (mix_bsearch(copy_mix.n_user[j], &n) != NULL) { + for (i = copy_mix.start[j]; i <= copy_mix.end[j]; i++) { + if (i == copy_mix.n_user[j]) continue; + mix_duplicate(copy_mix.n_user[j], i); + } + } else { + warning_msg("MIX to copy not found."); + return_value = ERROR; + } + } + } + if (copy_exchange.count > 0) { + for (j = 0; j < copy_exchange.count; j++) { + if (exchange_bsearch(copy_exchange.n_user[j], &n) != NULL) { + for (i = copy_exchange.start[j]; i <= copy_exchange.end[j]; i++) { + if (i == copy_exchange.n_user[j]) continue; + exchange_duplicate(copy_exchange.n_user[j], i); + } + } else { + warning_msg("EXCHANGE to copy not found."); + return_value = ERROR; + } + } + } + if (copy_surface.count > 0) { + for (j = 0; j < copy_surface.count; j++) { + if (surface_bsearch(copy_surface.n_user[j], &n) != NULL) { + for (i = copy_surface.start[j]; i <= copy_surface.end[j]; i++) { + if (i == copy_surface.n_user[j]) continue; + surface_duplicate(copy_surface.n_user[j], i); + } + } else { + warning_msg("SURFACE to copy not found."); + return_value = ERROR; + } + } + } + if (copy_temperature.count > 0) { + for (j = 0; j < copy_temperature.count; j++) { + if (temperature_bsearch(copy_temperature.n_user[j], &n) != NULL) { + for (i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++) { + if (i == copy_temperature.n_user[j]) continue; + temperature_duplicate(copy_temperature.n_user[j], i); + } + } else { + warning_msg("TEMPERATURE to copy not found."); + return_value = ERROR; + } + } + } + if (copy_gas_phase.count > 0) { + for (j = 0; j < copy_gas_phase.count; j++) { + if (gas_phase_bsearch(copy_gas_phase.n_user[j], &n) != NULL) { + for (i = copy_gas_phase.start[j]; i <= copy_gas_phase.end[j]; i++) { + if (i == copy_gas_phase.n_user[j]) continue; + gas_phase_duplicate(copy_gas_phase.n_user[j], i); + } + } else { + warning_msg("GAS_PHASE to copy not found."); + return_value = ERROR; + } + } + } + if (copy_kinetics.count > 0) { + for (j = 0; j < copy_kinetics.count; j++) { + if (kinetics_bsearch(copy_kinetics.n_user[j], &n) != NULL) { + for (i = copy_kinetics.start[j]; i <= copy_kinetics.end[j]; i++) { + if (i == copy_kinetics.n_user[j]) continue; + kinetics_duplicate(copy_kinetics.n_user[j], i); + } + } else { + warning_msg("KINETICS to copy not found."); + return_value = ERROR; + } + } + } + if (copy_s_s_assemblage.count > 0) { + for (j = 0; j < copy_s_s_assemblage.count; j++) { + if (s_s_assemblage_bsearch(copy_s_s_assemblage.n_user[j], &n) != NULL) { + for (i = copy_s_s_assemblage.start[j]; i <= copy_s_s_assemblage.end[j]; i++) { + if (i == copy_s_s_assemblage.n_user[j]) continue; + s_s_assemblage_duplicate(copy_s_s_assemblage.n_user[j], i); + } + } else { + warning_msg("SOLID_SOLUTIONS to copy not found."); + return_value = ERROR; + } + } + } + copy_solution.count = 0; + copy_pp_assemblage.count = 0; + copy_exchange.count = 0; + copy_surface.count = 0; + copy_s_s_assemblage.count = 0; + copy_gas_phase.count = 0; + copy_kinetics.count = 0; + copy_mix.count = 0; + copy_irrev.count = 0; + copy_temperature.count = 0; + new_copy = FALSE; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_database(PFN_READ_CALLBACK pfn, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + int errors; + simulation = 0; + +/* + * Prepare error handling + */ + errors = setjmp(mark); + if (errors != 0) { + return errors; + } + + set_read_callback(pfn, cookie, TRUE); + dup_print("Reading data base.", TRUE); + read_input(); + tidy_model(); + status(0, NULL); + return 0; +} +/* ---------------------------------------------------------------------- */ +int run_simulations(PFN_READ_CALLBACK pfn, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + int errors; + char token[MAX_LENGTH]; + +/* + * Prepare error handling + */ + errors = setjmp(mark); + if (errors != 0) { + return errors; + } + + set_read_callback(pfn, cookie, FALSE); + +/* + * Read input data for simulation + */ + for (simulation = 1; ; simulation++) { + +#ifdef PHREEQ98 + AddSeries = !connect_simulations; +#endif + sprintf(token, "Reading input data for simulation %d.", simulation); + + output_msg(OUTPUT_GUI_ERROR, "\nSimulation %d\n", simulation); + + dup_print(token, TRUE); + if (read_input() == EOF) break; + + if (title_x != NULL) { + sprintf(token, "TITLE"); + dup_print(token, TRUE); + if (pr.headings == TRUE) output_msg(OUTPUT_MESSAGE,"%s\n\n", title_x); + } + tidy_model(); + test_classes(); + +#ifdef PHREEQ98 + if (!phreeq98_debug) { +#endif + +/* + * Calculate distribution of species for initial solutions + */ + if (new_solution) initial_solutions(TRUE); +/* + * Calculate distribution for exchangers + */ + if (new_exchange) initial_exchangers(TRUE); +/* + * Calculate distribution for surfaces + */ + if (new_surface) initial_surfaces(TRUE); +/* + * Calculate initial gas composition + */ + if (new_gas_phase) initial_gas_phases(TRUE); +/* + * Calculate reactions + */ + reactions(); +/* + * Calculate inverse models + */ + inverse_models(); +/* + * Calculate advection + */ + if (use.advect_in == TRUE) { + dup_print ("Beginning of advection calculations.", TRUE); + advection(); + } +/* + * Calculate transport + */ + if (use.trans_in == TRUE) { + dup_print ("Beginning of transport calculations.", TRUE); + transport(); + } +/* + * Copy + */ + if (new_copy) copy_entities(); +/* + * End of simulation + */ + dup_print( "End of simulation.", TRUE); +#ifdef PHREEQ98 + } /* if (!phreeq98_debug) */ +#endif + #ifdef SKIP + +{ + int n; + SAX_StartSystem(); + for (n = 0; n < count_solution; ++n) + { + SAX_AddSolution(solution[n]); + } + SAX_EndSystem(); + SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); + } + #endif + + } + + + return 0; +} +/* ---------------------------------------------------------------------- */ +int do_initialize(void) +/* ---------------------------------------------------------------------- */ +{ + int errors; +/* + * Prepare error handling + */ + errors = setjmp(mark); + if (errors != 0) { + return errors; + } + + state = INITIALIZE; + initialize(); + + return 0; +} +/* ---------------------------------------------------------------------- */ +int do_status(void) +/* ---------------------------------------------------------------------- */ +{ + int errors; +/* + * Prepare error handling + */ + errors = setjmp(mark); + if (errors != 0) { + return errors; + } + + if (pr.status == TRUE) { +#if defined(PHREEQCI_GUI) + state = -1; + status(0, "\r\nDone."); +#else + status(0, "\nDone."); +#endif + output_msg(OUTPUT_SCREEN,"\n"); + output_msg(OUTPUT_SEND_MESSAGE,"\r\n"); + } + dup_print ("End of run.", TRUE); + output_msg(OUTPUT_SCREEN,"\nEnd of Run.\n"); + output_msg(OUTPUT_SEND_MESSAGE,"\r\nEnd of Run.\r\n"); + + return 0; +} diff --git a/model.cpp b/model.cpp new file mode 100644 index 00000000..6c0d19b4 --- /dev/null +++ b/model.cpp @@ -0,0 +1,3102 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: model.c 632 2005-11-08 17:59:00Z dlpark $"; + +static LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); +static LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); +static LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); + +#ifdef SKIP +static int adjust_step_size(void); +#endif + +/*#define SLNQ*/ + +#ifdef SLNQ +static int add_trivial_eqns(int rows, int cols, LDBLE *matrix); +extern int slnq (int n, LDBLE *a, LDBLE *delta, int ncols, int print); +#endif + +static int calc_gas_pressures(void); +static int calc_s_s_fractions(void); +static int gammas (LDBLE mu); +static int initial_guesses(void); +static int revise_guesses(void); +static int s_s_binary(struct s_s *s_s_ptr); +static int s_s_ideal(struct s_s *s_s_ptr); + +static int remove_unstable_phases; +static int gas_in; + +LDBLE min_value = 1e-10; + + +/* ---------------------------------------------------------------------- */ +int model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * model is called after the equations have been set up by prep + * and initial guesses have been made in set. + * + * Here is the outline of the calculation sequence: + * residuals--residuals are calculated, if small we are done + * sum_jacobian--jacobian is calculated + * ineq--inequality solver is called + * reset--estimates of unknowns revised, if changes are small solution + * has been found, usually convergence is found in residuals. + * gammas--new activity coefficients + * molalities--calculate molalities + * mb_sums--calculate mass-balance sums + * mb_gases--decide if gas_phase exists + * mb_s_s--decide if solid_solutions exists + * switch_bases--check to see if new basis species is needed + * reprep--rewrite equations with new basis species if needed + * revise_guesses--revise unknowns to get initial mole balance + * check_residuals--check convergence one last time + * sum_species--calculate sums of elements from species concentrations + * + * An additional pass through may be needed if unstable phases still exist + * in the phase assemblage. + */ + int kode, return_kode; + int r; + int count_infeasible, count_basis_change; + int debug_model_save; + int mass_water_switch_save; + if (svnid == NULL) fprintf(stderr," "); + +/* debug_model = TRUE; */ +/* debug_prep = TRUE; */ +/* debug_set = TRUE; */ + /* mass_water_switch == TRUE, mass of water is constant */ + if (pitzer_model == TRUE) return model_pz(); + mass_water_switch_save = mass_water_switch; + if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) { + mass_water_switch = TRUE; + } + debug_model_save = debug_model; + pe_step_size_now = pe_step_size; + step_size_now = step_size; + status(0, NULL); + iterations=0; + count_basis_change = count_infeasible = 0; + stop_program = FALSE; + remove_unstable_phases = FALSE; + for (; ; ) { + mb_gases(); + mb_s_s(); + kode = 1; + while ( ( r = residuals() ) != CONVERGED || remove_unstable_phases == TRUE) { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill*/, 0) == WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + iterations++; + if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { + set_forward_output_to_log(TRUE); + debug_model = TRUE; + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nIteration %d\tStep_size = %f\n", + iterations, (double) step_size_now); + output_msg(OUTPUT_MESSAGE,"\t\tPe_step_size = %f\n\n", (double) pe_step_size_now); + } +/* + * Iterations exceeded + */ + if (iterations > itmax ) { + sprintf(error_string,"Maximum iterations exceeded, %d\n",itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } +/* + * Calculate jacobian + */ + jacobian_sums(); +/* + * Full matrix with pure phases + */ + if ( r == OK || remove_unstable_phases == TRUE) { + return_kode = ineq(kode); + if ( return_kode != OK ) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "Ineq had infeasible solution, " + "kode %d, iteration %d\n", + return_kode, iterations); + } + output_msg(OUTPUT_LOG, "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, iterations); + count_infeasible++; + } + if ( return_kode == 2 ) { + ineq(0); + } + reset(); + } + gammas(mu_x); + if (molalities(FALSE) == ERROR) { + revise_guesses(); +/* adjust_step_size(); */ + } + if(use.surface_ptr != NULL && + use.surface_ptr->diffuse_layer == TRUE && + use.surface_ptr->related_phases == TRUE) + initial_surface_water(); + mb_sums(); + mb_gases(); + mb_s_s(); +/* + * Switch bases if necessary + */ + + if (switch_bases() == TRUE ) { + count_basis_change++; + reprep(); + gammas(mu_x); + molalities(TRUE); + if(use.surface_ptr != NULL && + use.surface_ptr->diffuse_layer == TRUE && + use.surface_ptr->related_phases == TRUE) + initial_surface_water(); + revise_guesses(); + mb_sums(); + mb_gases(); + mb_s_s(); + } +/* debug + species_list_sort(); + sum_species(); + print_species(); + print_exchange(); + print_surface(); + */ + if (stop_program == TRUE) { + break; + } + } +/* + * Check for stop_program + */ + + if (stop_program == TRUE) { + break; + } + if (check_residuals() == ERROR) { + stop_program = TRUE; + break; + } + if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE && + mass_water_switch == TRUE) { + output_msg(OUTPUT_LOG,"\nChanging water switch to FALSE. Iteration %d.\n", iterations); + mass_water_switch = FALSE; + continue; + } + if (remove_unstable_phases == FALSE) break; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nRemoving unstable phases. Iteration %d.\n", iterations); + } + output_msg(OUTPUT_LOG,"\nRemoving unstable phases. Iteration %d.\n", iterations); + } + output_msg(OUTPUT_LOG,"\nNumber of infeasible solutions: %d\n",count_infeasible); + output_msg(OUTPUT_LOG,"Number of basis changes: %d\n\n",count_basis_change); + output_msg(OUTPUT_LOG,"Number of iterations: %d\n\n", iterations); + debug_model = debug_model_save; + set_forward_output_to_log(FALSE); + if (stop_program == TRUE) { + return(ERROR); + } + return(OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int adjust_step_size(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Step sizes are cut down if overflow occurs in molalities + */ + pe_step_size_now -= (pe_step_size_now - 1.0) / 2.0; + step_size_now -= (step_size_now - 1.) / 2.0; + if (pe_step_size_now < 1.5) pe_step_size_now = 1.5; + if (step_size_now < 1.5) step_size_now = 1.5; + output_msg(OUTPUT_LOG,"\tNew step sizes: %f\t%f\t%d\n", + step_size_now, pe_step_size_now, iterations); + return(OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int check_residuals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks for convergence of all equations, prints any nonconvergence + * Sets variable remove_unstable_phases if a phase is present, + * but undersaturated (i.e. aragonite in calcite-saturated solution). + */ + int i, return_value; + LDBLE epsilon; +#ifdef SKIP + if (punch.high_precision == FALSE) + epsilon = 1e-8; + else + epsilon = 1.e-12; +#endif + epsilon = convergence_tolerance; + + return_value = OK; + if (stop_program == TRUE) { + warning_msg("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:"); + /*error_msg("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:", CONTINUE);*/ + } + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == MB || x[i]->type == ALK) { + if ( fabs(residual[i]) >= epsilon*x[i]->moles && x[i]->moles > MIN_TOTAL /* || stop_program == TRUE */) { +#ifdef SKIP + if ( fabs(residual[i]) >= epsilon*x[i]->moles /* || stop_program == TRUE */) { +#endif + sprintf(error_string,"%20s has not converged. Total: %e\tCalculated: " + "%e\tResidual: %e\n", x[i]->description, (double) x[i]->moles, + (double) x[i]->f, (double) residual[i]); + error_msg(error_string, CONTINUE); + if (x[i]->type == ALK) { + error_msg("Is non-carbonate alkalinity " + "greater than total alkalinity?\n", CONTINUE); + } + return_value = ERROR; + } + } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { + if (fabs (residual[i]) >= epsilon /* || stop_program == TRUE */) { + sprintf(error_string,"%20s solution phase boundary has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == CB) { + if (fabs (residual[i]) >= epsilon * mu_x *mass_water_aq_x /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Charge balance has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == MU && pitzer_model == FALSE) { + if (fabs (residual[i]) >= epsilon * mu_x * mass_water_aq_x /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Ionic strength has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == AH2O && pitzer_model == FALSE) { + if (fabs (residual[i]) >= epsilon /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Activity of water has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == MH && pitzer_model == FALSE) { +#define COMBINE + /*#define COMBINE_CHARGE*/ +#ifdef COMBINE +#ifndef COMBINE_CHARGE + if (fabs(residual[i]) > epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles)) +#else + if (fabs(residual[i]) > epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles + charge_balance_unknown->moles)) +#endif +#else + if (fabs (residual[i]) >= epsilon * x[i]->moles /* || stop_program == TRUE */) +#endif + { + sprintf(error_string,"%20s Mass of hydrogen has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == MH2O) { + if (mass_water_switch == TRUE) continue; + if (fabs (residual[i]) >= 0.01 * epsilon * x[i]->moles /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Mass of oxygen has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == PP) { + if (x[i]->pure_phase->add_formula == NULL) { + if (x[i]->dissolve_only == TRUE) { + if ((residual[i] > epsilon && x[i]->moles > 0.0) || ((residual[i] < -epsilon && (x[i]->pure_phase->initial_moles - x[i]->moles) > 0))) { + output_msg(OUTPUT_LOG,"%20s Dissolve_only pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); + } + } else { + if ((residual[i] >= epsilon && x[i]->moles > 0.0) /* || stop_program == TRUE */) { + remove_unstable_phases = TRUE; + output_msg(OUTPUT_LOG,"%20s Pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); + } else if (residual[i] <= -epsilon ) { + sprintf(error_string,"%20s Pure phase has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + } else { + if ((fabs(residual[i]) >= epsilon && x[i]->moles > 0.0) /* || stop_program == TRUE */) { + output_msg(OUTPUT_LOG,"%s, Pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); + sprintf(error_string,"%s, Pure phase with add formula has not converged.\n\t SI may be a local minimum." + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + warning_msg(error_string); + } + } + } else if (x[i]->type == EXCH) { + if (/* stop_program == TRUE || */ + (x[i]->moles <= MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) || + (x[i]->moles > MIN_RELATED_SURFACE && (fabs(residual[i]) > epsilon * x[i]->moles))) { + sprintf(error_string,"%20s Exchanger mass balance has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == SURFACE) { + if (/* stop_program == TRUE || */ + (x[i]->moles <= MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) || + (x[i]->moles > MIN_RELATED_SURFACE && (fabs(residual[i]) > epsilon * x[i]->moles))) { + sprintf(error_string,"%20s Surface mass balance has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == SURFACE_CB) { + if ((x[i]->surface_charge->grams > MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Surface charge/potential has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == GAS_MOLES) { + if (gas_in == FALSE) continue; + if (residual[i] >= epsilon || residual[i] <= -epsilon /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Total moles in gas phase has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } else if (x[i]->type == PITZER_GAMMA) { + if (fabs(residual[i]) > epsilon ) { + sprintf(error_string,"%20s log gamma not converged.\tResidual: %e\n", x[i]->description, (double) residual[i]); + } + } else if (x[i]->type == S_S_MOLES) { + if (x[i]->s_s_in == FALSE) continue; + if (residual[i] >= epsilon || residual[i] <= -epsilon /* || stop_program == TRUE */) { + sprintf(error_string,"%20s Total moles in solid solution has not converged. " + "\tResidual: %e\n", x[i]->description, (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + } + if (remove_unstable_phases == TRUE) { + output_msg(OUTPUT_LOG, "%20sRemoving unstable phases, iteration %d."," ", iterations); + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int gammas (LDBLE mu) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates gammas and [moles * d(ln gamma)/d mu] for all aqueous + * species. + */ + int i, j; + int ifirst, ilast; + LDBLE f, a_llnl, b_llnl, bdot_llnl, log_g_co2, dln_g_co2, c2_llnl; + LDBLE s1, s2, s3; + LDBLE c1, c2, a, b; + LDBLE muhalf; + /* Initialize */ + if (pitzer_model == TRUE) return gammas_pz(); + a_llnl = b_llnl = bdot_llnl = log_g_co2 = dln_g_co2 = c2_llnl = 0; +/* + * compute temperature dependence of a and b for debye-huckel + */ + s1=374.11-tc_x; + s2=pow(s1,1.0/3.0); + s3=1.0+0.1342489*s2-3.946263e-03*s1; + s3=s3/(3.1975-0.3151548*s2-1.203374e-03*s1+7.48908e-13*(s1*s1*s1*s1)); + s3=sqrt(s3); + if (tk_x >= 373.15) { + c1=5321.0/tk_x+233.76-tk_x*(tk_x*(8.292e-07*tk_x-1.417e-03)+0.9297); + } else { + /* replaced by wateq4f expression + c1=87.74-tc_x*(tc_x*(1.41e-06*tc_x-9.398e-04)+0.4008); + */ + c1 = 2727.586+0.6224107*tk_x-466.9151*log(tk_x)-52000.87/tk_x; + } + c1=sqrt(c1*tk_x); + /* replaced by wateq4f expressions + a=1824600.0*s3/(c1 * c1 * c1); + b=50.29*s3/c1; + */ + a = 1824827.7 * s3 / (c1 * c1 * c1); + b = 50.2905 * s3 / c1; + /* + * LLNL temperature dependence + */ + if (llnl_count_temp > 0) { + ifirst = 0; + ilast = llnl_count_temp; + if (tc_x < llnl_temp[0] || tc_x > llnl_temp[llnl_count_temp - 1]) { + error_msg("Temperature out of range of LLNL_AQUEOUS_MODEL parameters", STOP); + } + for (i = 0; i < llnl_count_temp; i++) { + if (tc_x >= llnl_temp[i]) ifirst = i; + if (tc_x <= llnl_temp[i]) { + ilast = i; + break; + } + } + if (ilast == ifirst) { + f = 1; + } else { + f = (tc_x - llnl_temp[ifirst])/(llnl_temp[ilast] - llnl_temp[ifirst]); + } + a_llnl = (1 - f)*llnl_adh[ifirst] + f*llnl_adh[ilast]; + b_llnl = (1 - f)*llnl_bdh[ifirst] + f*llnl_bdh[ilast]; + bdot_llnl = (1 - f)*llnl_bdot[ifirst] + f*llnl_bdot[ilast]; + /* + * CO2 activity coefficient + */ + log_g_co2 = (llnl_co2_coefs[0] + llnl_co2_coefs[1]*tk_x + llnl_co2_coefs[2]/tk_x)*mu - + (llnl_co2_coefs[3] + llnl_co2_coefs[4]*tk_x)*(mu/(mu+1)); + log_g_co2 /= LOG_10; + dln_g_co2 = (llnl_co2_coefs[0] + llnl_co2_coefs[1]*tk_x + llnl_co2_coefs[2]/tk_x) - + (llnl_co2_coefs[3] + llnl_co2_coefs[4]*tk_x)*(1/((mu+1)*(mu+1))); + } + +/* + * constants for equations + */ + muhalf = sqrt(mu); + c1=(-a)*LOG_10*(1.0/(2*muhalf*(muhalf+1.0)*(muhalf+1.0))-0.3); + c2=-a/(2*muhalf); + if (llnl_count_temp > 0) { + c2_llnl = -a_llnl/(2*muhalf); + } + +/* + * Calculate activity coefficients + */ + for (i=0; i < count_s_x; i++) { + switch (s_x[i]->gflag) { + case 0: /* uncharged */ + s_x[i]->lg = s_x[i]->dhb * mu; + s_x[i]->dg = s_x[i]->dhb * LOG_10 * s_x[i]->moles; + break; + case 1: /* Davies */ + s_x[i]->lg = - s_x[i]->z * s_x[i]->z * a * + ( muhalf / (1.0 + muhalf) - 0.3 * mu); + s_x[i]->dg = c1 * s_x[i]->z * s_x[i]->z * s_x[i]->moles; + break; + case 2: /* Extended D-H, WATEQ D-H */ + s_x[i]->lg = -a * muhalf * s_x[i]->z * s_x[i]->z / + (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu; + s_x[i]->dg = (c2 * s_x[i]->z * s_x[i]->z / + ((1.0 + s_x[i]->dha * b * muhalf)*(1.0 + s_x[i]->dha * b * muhalf)) + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; +/* if (mu_x < 1e-6) s_x[i]->dg = 0.0; */ + break; + case 3: /* Always 1.0 */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + break; + case 4: /* Exchange */ +/* + * Find CEC + * z contains valence of cation for exchange species, alk contains cec + */ +/* !!!!! */ + for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { + if (s_x[i]->rxn_x->token[j].s->type == EX) { + s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->exch_gflag == 1 && s_x[i]->alk > 0) { + /* Davies */ + s_x[i]->lg = - s_x[i]->equiv * s_x[i]->equiv * a * + ( muhalf / (1.0 + muhalf) - 0.3 * mu) + + log10(fabs(s_x[i]->equiv)/s_x[i]->alk); + s_x[i]->dg = c1 * s_x[i]->equiv * s_x[i]->equiv * s_x[i]->moles; + } else if (s_x[i]->exch_gflag == 2 && s_x[i]->alk > 0) { + /* Extended D-H, WATEQ D-H */ + s_x[i]->lg = -a * muhalf * s_x[i]->equiv * s_x[i]->equiv / + (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu + + log10(fabs(s_x[i]->equiv)/s_x[i]->alk); + s_x[i]->dg = (c2 * s_x[i]->equiv * s_x[i]->equiv / + ((1.0 + s_x[i]->dha * b * muhalf)*(1.0 + s_x[i]->dha * b * muhalf)) + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; + } else if (s_x[i]->exch_gflag == 7 && s_x[i]->alk > 0) { + if (llnl_count_temp >0 ) { + s_x[i]->lg = -a_llnl * muhalf * s_x[i]->equiv * s_x[i]->equiv / (1.0 + s_x[i]->dha * b_llnl * muhalf) + bdot_llnl * mu + log10(fabs(s_x[i]->equiv)/s_x[i]->alk); + s_x[i]->dg = (c2_llnl * s_x[i]->equiv * s_x[i]->equiv / ((1.0 + s_x[i]->dha * b_llnl * muhalf)*(1.0 + s_x[i]->dha * b_llnl * muhalf)) + bdot_llnl) * LOG_10 * s_x[i]->moles; + } else { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); + } + } else { +/* + * Master species is a dummy variable with meaningless activity and mass + */ + if (s_x[i]->primary != NULL) { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } else { + if (s_x[i]->alk <= 0) { + s_x[i]->lg = 0.0; + } else { + s_x[i]->lg = log10(fabs(s_x[i]->equiv)/s_x[i]->alk); + } + s_x[i]->dg = 0.0; + } + } + break; + case 5: /* Always 1.0 */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + break; + case 6: /* Surface */ +/* + * Find moles of sites. + * s_x[i]->equiv is stoichiometric coefficient of sites in species + */ + for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { + if (s_x[i]->rxn_x->token[j].s->type == SURF) { + s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->alk > 0) { + s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); + s_x[i]->dg = 0.0; + } else { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + break; + case 7: /* LLNL */ + if (llnl_count_temp >0 ) { + if (s_x[i]->z == 0) { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } else { + s_x[i]->lg = -a_llnl * muhalf * s_x[i]->z * s_x[i]->z / + (1.0 + s_x[i]->dha * b_llnl * muhalf) + bdot_llnl * mu; + s_x[i]->dg = (c2_llnl * s_x[i]->z * s_x[i]->z / ((1.0 + s_x[i]->dha * b_llnl * muhalf)*(1.0 + s_x[i]->dha * b_llnl * muhalf)) + bdot_llnl) * LOG_10 * s_x[i]->moles; + break; + } + } else { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); + } + break; + case 8: /* LLNL CO2*/ + if (llnl_count_temp > 0) { + s_x[i]->lg = log_g_co2; + s_x[i]->dg = dln_g_co2 * s_x[i]->moles; + } else { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); + } + break; + case 9: /* activity water */ + s_x[i]->lg = log10(exp( s_h2o->la * LOG_10) * gfw_water); + s_x[i]->dg = 0.0; + break; + } +/* + if (mu_unknown != NULL) { + if (fabs(residual[mu_unknown->number]) > 0.1 && + fabs(residual[mu_unknown->number])/mu_x > 0.5) { + s_x[i]->dg = 0.0; + } + } + */ + } + return(OK); +} +/* ------------------------------------------------------------------------------- */ +int ineq(int in_kode) +/* ------------------------------------------------------------------------------- */ +{ +/* + * Sets up equations and inequalities for Cl1. + * Scales columns if necessary. + * Eliminates equations that are not necessary because + * gas_phase, s_s, or phase equation is not needed + * Mallocs space + * Calls Cl1 + * Rescales results if necessary + */ + int i, j; + int return_code; + int *back; + int count_rows; + int count_optimize, count_equal; + extern int max_row_count, max_column_count; + int k, l, m, n; + int klmd, nklmd, n2d; + int iter; + LDBLE error; + LDBLE *ineq_array, *res, *cu; + LDBLE *zero, *delta1; + int *iu, *is; + LDBLE *normal; + LDBLE max; + int kode; +#ifdef SKIP + LDBLE *save_row; +#endif + LDBLE min; +#ifdef SLNQ + LDBLE *slnq_array; + LDBLE *slnq_delta1; +#endif +/* Debug + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "\narray:\n\n"); + array_print(array, count_unknowns, count_unknowns + 1, count_unknowns + 1); + } + */ +/* + * Special case for removing unstable phases + */ + if ( remove_unstable_phases == TRUE ) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nSolution vector for removing unstable phases:\n"); + } + for (i=0; i< count_unknowns; i++) { + if (x[i]->type == PP && residual[i] > 0e-8 && x[i]->moles > 0 && + x[i]->pure_phase->add_formula == NULL && x[i]->dissolve_only == FALSE) { +/* + * Set mass transfer to all of phase + */ + delta[i] = x[i]->moles; + } else { + delta[i] = 0.0; + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, + x[i]->description, (double) delta[i]); + } + } + remove_unstable_phases = FALSE; + return(OK); + } +/* + * Pitzer model does not have activity of water or mu + */ + if (pitzer_model == TRUE) { + for (i=0; i < count_unknowns; i++) { + if ( (x[i]->type == AH2O && full_pitzer == FALSE) || + x[i]->type == MH || + x[i]->type == MU || + (x[i]->type == PITZER_GAMMA && full_pitzer == FALSE)) { + for (j=0; jtype == MB || x[i]->type == ALK || x[i]->type == EXCH || x[i]->type == SURFACE || x[i]->type == SURFACE_CB) { +/* !!!! */ if ( x[i]->moles <= MIN_RELATED_SURFACE && (x[i]->type == EXCH || x[i]->type == SURFACE)) continue; + for (j = 0; j < count_unknowns; j++) { + if (x[i]->type == SURFACE && x[j]->type == SURFACE_CB ) continue; + + if (fabs(array[j *(count_unknowns + 1) + i]) > max) { + max = fabs(array[j * (count_unknowns + 1) + i]); + if (max > min_value) break; + } + } + if (diagonal_scale == TRUE) { + if (fabs(array[i *(count_unknowns + 1) + i]) < min_value) { + max = fabs(array[i * (count_unknowns + 1) + i]); + } + } + + if (max == 0) { + array[i *(count_unknowns + 1) + i] = 1e-5*x[i]->moles; + max = fabs(1e-5*x[i]->moles); + } + } + + if (x[i]->type == MH && pitzer_model == FALSE) { + /* make absolute value of diagonal at least 1e-12 */ + + min = 1e-12; + min = MIN_TOTAL; + array[x[i]->number * (count_unknowns + 1) + x[i]->number] += min; + if (fabs(array[x[i]->number * (count_unknowns + 1) + x[i]->number]) < min) + array[x[i]->number * (count_unknowns + 1) + x[i]->number] = min; + max = 0.0; + + for (j=0; jtype != MB && + x[j]->type != SURFACE && + x[j]->type != SURFACE_CB && + x[j]->type != EXCH && + x[j]->type != MH && + x[j]->type != MH2O) continue; + if (fabs(array[j * (count_unknowns + 1) + i]) > max) { + max = fabs(array[j * (count_unknowns + 1) + i]); + if (max > min_value) break; + } + } + } + + if (max > 0.0 && max < min_value) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "Scaling column for %s, max= %e\n", + x[i]->description, (double) max); + } + for (j=0; j < count_unknowns; j++) { + array[j * (count_unknowns + 1) + i] *= min_value / max ; + } + normal[i] = min_value / max; + } + } + +/* + * Allocate arrays for inequality solver + */ + max_row_count = 2*count_unknowns + 2; + max_column_count = count_unknowns + 2; + ineq_array = (LDBLE *) PHRQ_malloc((size_t) max_row_count * max_column_count * + sizeof(LDBLE)); + if (ineq_array == NULL) malloc_error(); + + back = (int *) PHRQ_malloc((size_t) max_row_count * sizeof(int)); + if (back == NULL) malloc_error(); + + zero = (LDBLE *) PHRQ_malloc((size_t) max_row_count*sizeof(LDBLE)); + if (zero == NULL) malloc_error(); + for (i=0; itype == PP ) { + /* not in model, ignore */ + if (x[i]->pure_phase->phase->in == FALSE) continue; + /* Undersaturated and no mass, ignore */ + if (x[i]->f > 0e-8 && x[i]->moles <= 0 && x[i]->pure_phase->add_formula == NULL) { + continue; + } else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { + continue; + } else { + /* Copy in saturation index equation (has mass or supersaturated) */ + memcpy((void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + if (x[i]->pure_phase->add_formula == NULL && x[i]->dissolve_only == FALSE) { + res[count_rows] = 1.0; + } +/* + * If infeasible solution on first attempt, remove constraints on IAP + */ +#ifdef SKIP +#endif + if (pp_scale != 1){ + for (j = 0; j < count_unknowns +1; j++) { + ineq_array[count_rows * max_column_count + j] *= pp_scale; + } + } + + + if (in_kode != 1) { + res[count_rows] = 0.0; + } + count_rows++; + } + } else if (x[i]->type == ALK || + x[i]->type == SOLUTION_PHASE_BOUNDARY ) { +/* + * Alkalinity and solution phase boundary + */ + memcpy((void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + count_rows++; +/* + * Gas phase + */ + } else if (x[i]->type == GAS_MOLES && gas_in == TRUE) { + memcpy((void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + + res[count_rows] = 1.0; + if (in_kode != 1) { + res[count_rows] = 0.0; + } + count_rows++; +/* + * Solid solution + */ + } else if (x[i]->type == S_S_MOLES && x[i]->s_s_in == TRUE) { + memcpy((void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + res[count_rows] = 1.0; + if (in_kode != 1) { + res[count_rows] = 0.0; + } + count_rows++; + } + } + count_optimize = count_rows; +/* + * Copy equality equations into ineq_array + */ + for (i=0; i< count_unknowns; i++) { + if (x[i]->type != SOLUTION_PHASE_BOUNDARY && + x[i]->type != ALK && + x[i]->type != GAS_MOLES && + x[i]->type != S_S_MOLES && + x[i]->type != PP ) { + if(x[i]->type == MH && pitzer_model == TRUE) continue; + if(mass_water_switch == TRUE && x[i] == mass_oxygen_unknown) continue; +/* + * Mass balance, CB, MU, AH2O, MH, MH2O, others + */ + if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) continue; + if (x[i]->type == SURFACE && + x[i]->phase_unknown == NULL && + x[i]->moles <= MIN_RELATED_SURFACE) continue; + if (x[i]->type == SURFACE_CB && + /* x[i-1]->phase_unknown == NULL && */ + /* x[i-1]->moles <= MIN_RELATED_SURFACE) continue; */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) continue; + if (x[i]->type == SURFACE && + x[i]->phase_unknown != NULL && +/* x[i]->phase_unknown->f > 0e-8 && */ + x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && + x[i]->phase_unknown->pure_phase->add_formula == NULL) continue; + if (x[i]->type == SURFACE_CB && + x[i-1]->phase_unknown != NULL && +/* x[i-1]->phase_unknown->f > 0e-8 && */ +/* x[i-1]->phase_unknown->moles <= MIN_RELATED_SURFACE && */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + x[i-1]->phase_unknown->pure_phase->add_formula == NULL) continue; + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + if(mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown) { + k = mass_oxygen_unknown->number; + for (j = 0; j < count_unknowns; j++) { + ineq_array[count_rows * max_column_count + j] -= 2*array[k * (count_unknowns + 1) + j]; + } + } + count_rows++; + } else if (x[i]->type == PITZER_GAMMA) { + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + } + } + count_equal = count_rows - count_optimize; +/* + * Copy inequality constraints into ineq + */ + if (pure_phase_unknown != NULL) { + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == PP) { + /* not in model, ignore */ + if (x[i]->pure_phase->phase->in == FALSE) continue; + /* No moles and undersaturated, ignore */ + if (x[i]->moles <= 0.0 && x[i]->f > 0e-8 && + x[i]->pure_phase->add_formula == NULL) { + continue; + /* No moles of pure phase present, must precipitate */ + } else if (x[i]->moles <= 0.0 ) { + delta1[i] = -1.0; + } else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { + continue; + } else { + + /* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */ + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(zero[ 0 ]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[count_rows*max_column_count + i] = 1.0; + ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->moles; + back[count_rows] = i; + count_rows++; + } + /* Pure phase is present and dissolve_only, force ppt to be <= amount of dissolved so far */ + if (x[i]->dissolve_only == TRUE) { + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), (void *) &(zero[ 0 ]), (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[count_rows*max_column_count + i] = -1.0; + ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->pure_phase->initial_moles - x[i]->moles; + back[count_rows] = i; + count_rows++; + } + } + } + } +/* + * Add inequality for mass of oxygen greater than zero + */ +#ifdef SKIP +#endif + if (pitzer_model) { + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == MH2O) { + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type < PP) { + ineq_array[count_rows*max_column_count + j] = 0.0; + } else { + /*ineq_array[count_rows*max_column_count + j] = -ineq_array[count_rows*max_column_count + j]; */ + } + } + ineq_array[count_rows*max_column_count + count_unknowns] = 0.5*x[i]->moles; + count_rows++; + } + } + } + + +/* + * Hydrogen mass balance is good + */ +/* + * No moles and undersaturated, mass transfer must be zero + */ + if (pure_phase_unknown != NULL) { + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == PP) { + if ((x[i]->moles <= 0.0 && x[i]->f > 0e-8 && + x[i]->pure_phase->add_formula == NULL) || x[i]->pure_phase->phase->in == FALSE) { + for (j=0; jdissolve_only == TRUE) { + if (x[i]->f < 0e-8 && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { + for (j=0; jrelated_phases == TRUE || use.exchange_ptr->related_rate == TRUE )) { + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == EXCH && x[i]->moles <= 0) { + for (j=0; jrelated_phases == TRUE || use.surface_ptr->related_rate == TRUE ) ) { + for (i=0; i < count_unknowns; i++) { + if ((x[i]->type == SURFACE && + x[i]->phase_unknown != NULL && +/* x[i]->phase_unknown->f > 0e-8 && */ + x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && + x[i]->phase_unknown->pure_phase->add_formula == NULL) || + (x[i]->type == SURFACE_CB && + x[i-1]->phase_unknown != NULL && +/* x[i-1]->phase_unknown->f > 0e-8 && */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + x[i-1]->phase_unknown->pure_phase->add_formula == NULL)) { + for (j=0; jtype == SURFACE && + x[i]->phase_unknown == NULL && + x[i]->moles <= MIN_RELATED_SURFACE) || + (x[i]->type == SURFACE_CB && + x[i-1]->phase_unknown == NULL && + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE)) { + for (j=0; j= zero + */ + if (gas_in == TRUE) { + i = gas_unknown->number; + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(zero[ 0 ]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[count_rows*max_column_count + i] = -1.0; + ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->moles; + back[count_rows] = i; + count_rows++; + } else if (use.gas_phase_ptr != NULL && gas_in == FALSE) { +/* + * Moles of gas small and sum p < ptotal + */ + i = gas_unknown->number; + for (j=0; j= zero + */ + + if (s_s_unknown != NULL) { + for (i = s_s_unknown->number; i < count_unknowns; i++) { + if (x[i]->type != S_S_MOLES) break; + if (x[i]->phase->in == TRUE && x[i]->s_s_in == TRUE) { + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(zero[ 0 ]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[count_rows*max_column_count + i] = 1.0; + ineq_array[count_rows*max_column_count + count_unknowns ] = 0.99*x[i]->moles - MIN_TOTAL; + back[count_rows] = i; + count_rows++; + } else { + for (j=0; jtype == MB && x[i]->moles < 0.0 ) { + memcpy( (void *) &(ineq_array[count_rows*max_column_count]), + (void *) &(array[i*(count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back[count_rows] = i; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type < PP) { + ineq_array[count_rows*max_column_count + j] = 0.0; + } + } + count_rows++; + } + } + } +/* + * Zero column for mass of water + */ + if(mass_oxygen_unknown != NULL && mass_water_switch == TRUE) { + k = mass_oxygen_unknown->number; + for (j = 0; j < count_rows + 1; j++) { + ineq_array[j * max_column_count + k] = 0; + } + } +/* + * Scale column for pure phases + */ + for (i=0; i < count_unknowns; i++) { + if ( (x[i]->type == PP || x[i]->type == S_S_MOLES) && pp_column_scale != 1.0) { + for (j = 0; j < count_rows; j++) { + ineq_array[j* max_column_count + i] *= pp_column_scale; + } + normal[i] = pp_column_scale; + } + + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); + array_print(ineq_array, count_rows, count_unknowns + 1, max_column_count); + } +/* + * Calculate dimensions + */ + k = count_optimize; /* rows in A */ + l = count_equal; /* rows in C */ + m = count_rows - l - k; /* rows in E */ + if (m < 0) m = 0; + + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "k, l, m\t%d\t%d\t%d\n",k, l, m); + } + + n = count_unknowns; /* columns in A, C, E */ + klmd = max_row_count - 2; + nklmd = n+klmd; + n2d = n + 2; +/* + * Retain constraints on mineral mass transfers, even if infeasible on + * first attempt. + */ + kode = 1; + + if (in_kode == 2) { + kode = 1; + } + iter = 200; +/* + * Allocate space for arrays + */ + cu = (LDBLE *) PHRQ_malloc((size_t) 2*nklmd*sizeof(LDBLE)); + if (cu == NULL) malloc_error(); + iu = (int *) PHRQ_malloc((size_t) 2*nklmd*sizeof(int)); + if (iu == NULL) malloc_error(); + is = (int *) PHRQ_malloc((size_t) klmd*sizeof(int)); + if (is == NULL) malloc_error(); +#ifdef SLNQ + slnq_array = (LDBLE *) PHRQ_malloc((size_t) count_unknowns*(count_unknowns+1)*sizeof(LDBLE)); + if (slnq_array == NULL) malloc_error(); + for (i = 0; i < k+l; i++) { + for (j = 0; j <= count_unknowns; j++) { + slnq_array[i*(count_unknowns + 1) + j] = ineq_array[i*max_column_count + j]; + } + } + slnq_delta1 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); + if (slnq_delta1 == NULL) malloc_error(); + memcpy( (void *) &(slnq_delta1[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); +#endif +/* + * Call CL1 + */ + cl1(k, l, m, n, + nklmd, n2d, ineq_array, + &kode, ineq_tol, &iter, + delta1, res, &error, cu, iu, is, FALSE); + +/* Set return_kode */ + if ( kode == 1) { + return_code = ERROR; + } else if (kode == 2) { + return_code = 2; + } else { + return_code = OK; + } +#ifdef SLNQ +/* if (kode > 0 && ((k + l) == count_unknowns)) { */ + if (kode > 0 && ((k + l) <= count_unknowns)) { + if (add_trivial_eqns(k+l, count_unknowns, slnq_array) == TRUE) { + if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Calling SLNQ, iteration %d\n", iterations); + output_msg(OUTPUT_LOG, "Calling SLNQ, iteration %d\n", iterations); + if (slnq(count_unknowns, slnq_array, slnq_delta1, count_unknowns+1, debug_model) == OK) { + memcpy( (void *) &(delta1[0]), (void *) &(slnq_delta1[0]), + (size_t) count_unknowns * sizeof(LDBLE)); + if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Using SLNQ results.\n"); + output_msg(OUTPUT_LOG, "Using SLNQ results.\n"); + return_code = OK; + } else { + if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Could not use SLNQ results.\n"); + output_msg(OUTPUT_LOG, "Could not use SLNQ results.\n"); + } + } else { + output_msg(OUTPUT_LOG, "Could not call SLNQ, row %d, unknowns %d, iteration %d\n", k+l, count_unknowns, iterations); + } + } else if (kode > 0) { + output_msg(OUTPUT_LOG, "Could not call SLNQ, row %d, unknowns %d\n", k+l, count_unknowns); + } +#endif +/* Copy delta1 into delta and scale */ + + memcpy( (void *) &(delta[0]), (void *) &(delta1[0]), + (size_t) count_unknowns * sizeof(LDBLE)); + for (i = 0; i < count_unknowns; i++) delta[i] *= normal[i]; +/* + * Rescale columns of array + */ + for (i = 0; i < count_unknowns; i++) { + if (normal[i] != 1.0) { + for (j=0; j < count_unknowns; j++) { + array[j * (count_unknowns + 1) + i] /= normal[i]; + } + } + } + +/* + * Debug, write results of ineq + */ + + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error); + output_msg(OUTPUT_MESSAGE, "\nsolution vector:\n"); + for (i=0; i < count_unknowns; i++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e",i, x[i]->description, (double) delta[i]); + if (x[i]->type == PP) { + output_msg(OUTPUT_MESSAGE, " -SI %10.2e Moles %10.2e", (double) x[i]->f, (double) x[i]->moles); + if (x[i]->f < 0e-8 || x[i]->moles > 0.0) { + output_msg(OUTPUT_MESSAGE, " **"); + } + } + output_msg(OUTPUT_MESSAGE, "\n"); + } + + output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); + for (i=0; i < count_rows; i++) { + output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, x[back[i]]->description, (double) res[i]); + } + } + normal = (LDBLE *) free_check_null(normal); + ineq_array = (LDBLE *) free_check_null(ineq_array); + back = (int *) free_check_null(back); + zero = (LDBLE *) free_check_null(zero); + res = (LDBLE *) free_check_null(res); + delta1 = (LDBLE *) free_check_null(delta1); + cu = (LDBLE *) free_check_null(cu); + iu = (int *) free_check_null(iu); + is = (int *) free_check_null(is); +#ifdef SLNQ + slnq_array = free_check_null(slnq_array); + slnq_delta1 = free_check_null(slnq_delta1); +#endif + return(return_code); +} +/* ---------------------------------------------------------------------- */ +int jacobian_sums (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fills in jacobian array, uses arrays sum_jacob0, sum_jacob1, and + * sum_jacob2. + */ + int i, j, k; + LDBLE sinh_constant; +/* + * Clear array, note residuals are in array[i, count_unknowns+1] + */ + for (i=0; i < count_unknowns; i++) { + array[i]=0.0; + } + for (i=1; i < count_unknowns; i++) { + memcpy ( (void *) &(array[i*(count_unknowns + 1)]), (void *) &(array[0]), + (size_t) count_unknowns * sizeof(LDBLE)); + } +/* + * Add constant terms + */ + for (k=0; k < count_sum_jacob0; k++) { + *sum_jacob0[k].target += sum_jacob0[k].coef; + } +/* + * Add terms with coefficients of 1.0 + */ + for (k=0; k < count_sum_jacob1; k++) { + *sum_jacob1[k].target += *sum_jacob1[k].source; + } +/* + * Add terms with coefficients != 1.0 + */ + for (k=0; k < count_sum_jacob2; k++) { + *sum_jacob2[k].target += *sum_jacob2[k].source * sum_jacob2[k].coef; + } +/* + * Make final adustments to jacobian array + */ +/* + * Ionic strength + */ + if (mu_unknown != NULL) { + for (i=0; inumber*(count_unknowns+1)+i] *= 0.5; + } + array[mu_unknown->number*(count_unknowns+1)+mu_unknown->number] -= mass_water_aq_x; + } +/* + * Mass of oxygen + */ + if (mass_oxygen_unknown != NULL && mu_unknown != NULL) { + array[mu_unknown->number*(count_unknowns+1)+mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x; + } +/* + * Activity of water + */ + if (ah2o_unknown != NULL) { + for (i=0; inumber*(count_unknowns+1)+i] *= -0.017; + } + array[ah2o_unknown->number*(count_unknowns+1)+ah2o_unknown->number] -= mass_water_aq_x*exp(s_h2o->la * LOG_10); + } + if (mass_oxygen_unknown != NULL && ah2o_unknown != NULL) { + array[ah2o_unknown->number*(count_unknowns+1)+mass_oxygen_unknown->number] -= + (exp(s_h2o->la * LOG_10) - 1) * mass_water_aq_x; + } +/* + * Surface charge balance + */ + if (surface_unknown != NULL && diffuse_layer_x == FALSE) { + sinh_constant = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*tk_x*1000); + for (i=0; itype == SURFACE_CB && x[i]->surface_charge->grams > 0 ) { + for (j=0; j < count_unknowns; j++) { + array[x[i]->number * (count_unknowns + 1) + j] *= + F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams); + } + array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= + sinh_constant * sqrt(mu_x) * cosh(x[i]->master[0]->s->la * LOG_10); + if (mu_unknown != NULL) { + array[x[i]->number * (count_unknowns + 1) + mu_unknown->number] -= + 0.5 * sinh_constant / sqrt(mu_x) * sinh(x[i]->master[0]->s->la * LOG_10); + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_sums (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates sums of species for calculation of mass balances, charge + * balance. Also calculates saturation indices for solution_phase_boundaries + * and pure_phases. After this routine total calcium calculated from all + * calcium species in solution is stored in x[i]->f. Also calculates + * x[i]->sum for some types of unknowns. Uses arrays sum_mb1 and + * sum_mb1, which are generated in prep and reprep. + */ + int k; +/* + * Clear functions in unknowns + */ + for (k=0; k < count_unknowns; k++) { + x[k]->f=0.0; + x[k]->sum=0.0; + } +/* + * Add terms with coefficients of 1.0 + */ + for (k=0; k < count_sum_mb1; k++) { + *sum_mb1[k].target += *sum_mb1[k].source; +/* { k += 1; k -= 1;} */ + } +/* + * Add terms with coefficients != 1.0 + */ + for (k=0; k < count_sum_mb2; k++) { + *sum_mb2[k].target += *sum_mb2[k].source * sum_mb2[k].coef; +/* { k += 1; k -= 1;} */ + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_gases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Determines whether gas_phase equation is needed + */ + gas_in = FALSE; + if (gas_unknown == NULL || use.gas_phase_ptr == NULL) return(OK); + if (use.gas_phase_ptr->type == PRESSURE) { + if (gas_unknown->f > use.gas_phase_ptr->total_p + 1e-7 || + gas_unknown->moles > MIN_TOTAL) { + gas_in = TRUE; + } + } else { + gas_in = FALSE; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_s_s(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE lp, log10_iap, total_moles; + LDBLE iapc, iapb, kc, kb, lc, lb, xcaq, xbaq, xb, xc; + LDBLE sigmapi_aq, sigmapi_solid; + LDBLE total_p; + struct s_s *s_s_ptr; + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; +/* + * Determines whether solid solution equation is needed + */ + if (s_s_unknown == NULL || use.s_s_assemblage_ptr == NULL) return(OK); + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + s_s_ptr = &(use.s_s_assemblage_ptr->s_s[i]); + total_moles = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) { + total_moles += s_s_ptr->comps[j].moles; + } + if (total_moles > 1e-13) { + s_s_ptr->s_s_in = TRUE; + } else if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) { + /* + * Calculate IAPc and IAPb + */ + if (s_s_ptr->comps[0].phase->rxn_x != NULL) { + log10_iap = 0; + for (rxn_ptr = s_s_ptr->comps[0].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapc = exp(log10_iap * LOG_10); + } else { + iapc = 1e-99; + } + if (s_s_ptr->comps[1].phase->rxn_x != NULL) { + log10_iap = 0; + for (rxn_ptr = s_s_ptr->comps[1].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapb = exp(log10_iap * LOG_10); + } else { + iapb = 1e-99; + } + /* + * Calculate sigma pi, aq + */ + sigmapi_aq = iapc + iapb; + /* + * Calculate xc,aq and xb, aq + */ + xcaq = iapc/(iapb + iapc); + xbaq = iapb/(iapb + iapc); + /* + * Get Kc and Kb + */ + kc = exp(s_s_ptr->comps[0].phase->lk*LOG_10); + kb = exp(s_s_ptr->comps[1].phase->lk*LOG_10); + /* + * Solve for xb + */ + xb = s_s_root(s_s_ptr->a0, s_s_ptr->a1, kc, kb, xcaq, xbaq); + /* + * Calculate lambdac and lambdab + */ + xc = 1 - xb; + lc = exp((s_s_ptr->a0 - s_s_ptr->a1*(-4*xb + 3))*xb*xb); + lb = exp((s_s_ptr->a0 + s_s_ptr->a1*(4*xb - 3))*xc*xc); + /* + * Calculate sigma pi, solid + */ + sigmapi_solid = xb*lb*kb + xc*lc*kc; + /* + * If Sigma pi, solid < sigma pi, aq, then use eqns + */ + if (sigmapi_solid < sigmapi_aq) { + s_s_ptr->s_s_in = TRUE; + } else { + s_s_ptr->s_s_in = FALSE; + } + } else { + /* + * Calculate total mole fraction from solution activities + */ + total_p = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) { + phase_ptr = s_s_ptr->comps[j].phase; + if (phase_ptr->in == TRUE) { + lp=-phase_ptr->lk; + for (rxn_ptr = s_s_ptr->comps[j].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + total_p += exp(lp * LOG_10); + } + } + if (total_p > 1.0) { + s_s_ptr->s_s_in = TRUE; + } else { + s_s_ptr->s_s_in= FALSE; + } + } + } + for (i = s_s_unknown->number; i < count_unknowns; i++) { + if (x[i]->type != S_S_MOLES) break; + x[i]->s_s_in = x[i]->s_s->s_s_in; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int molalities (int allow_overflow) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates la for master species + * Calculates lm and moles from lk, lg, and la's of master species + * Adjusts lm of h2 and o2. + */ + int i, j, count_g; + LDBLE total_g; + struct rxn_token *rxn_ptr; +/* + * la for master species + */ + for (i=0; i < count_master; i++) { + if (master[i]->in == REWRITE) { + master[i]->s->la = master[i]->s->lm + master[i]->s->lg; + } + } + if (diffuse_layer_x == TRUE) { + s_h2o->tot_g_moles = s_h2o->moles; + s_h2o->tot_dh2o_moles = 0.0; + } + for (i=0; i < count_s_x; i++) { + if (s_x[i]->type > HPLUS && s_x[i]->type != EX && s_x[i]->type != SURF) continue; +/* + * lm and moles for all aqueous species + */ + s_x[i]->lm=s_x[i]->lk - s_x[i]->lg; + for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef; + } + if (s_x[i]->type == EX ) { + s_x[i]->moles = exp(s_x[i]->lm * LOG_10); + } else if (s_x[i]->type == SURF ) { + s_x[i]->moles = exp(s_x[i]->lm * LOG_10); /* formerly * mass water */ + + } else { + s_x[i]->moles = under (s_x[i]->lm) * mass_water_aq_x; + if (s_x[i]->moles/mass_water_aq_x > 30) { + output_msg(OUTPUT_LOG,"Overflow: %s\t%e\t%e\t%d\n", s_x[i]->name, (double) (s_x[i]->moles/mass_water_aq_x), (double) s_x[i]->lm, iterations); + + if (iterations >= 0 && allow_overflow == FALSE) { + return(ERROR); + } + } + + } +/* + * other terms for diffuse layer model + */ + if (use.surface_ptr != NULL && diffuse_layer_x == TRUE && s_x[i]->type <= HPLUS) { + total_g = 0.0; + s_x[i]->tot_dh2o_moles = 0.0; + for (j = 0; j < use.surface_ptr->count_charge; j++) { + count_g = s_x[i]->diff_layer[j].count_g; +#ifdef SKIP +/* + * original formulation incorrectly mixes concentrations of surface relative + * to moles_water_aq_x and concentrations of diffuse layer in terms + * of moles_water_bulk_x. Moles_water_bulk_x is wrong anyway because + * an individual surface sees only moles_water_aq_x + moles_water_surface + * (not sum of all surfaces) + */ + s_x[i]->diff_layer[j].g_moles = s_x[i]->moles * + (s_x[i]->diff_layer[j].charge->g[count_g].g * + mass_water_bulk_x / mass_water_aq_x + + s_x[i]->diff_layer[j].charge->mass_water / + mass_water_aq_x); + + /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ + s_x[i]->diff_layer[j].dx_moles = s_x[i]->moles * + s_x[i]->diff_layer[j].charge->g[count_g].dg * + mass_water_bulk_x / mass_water_aq_x; + + total_g += s_x[i]->diff_layer[j].charge->g[count_g].g * + mass_water_bulk_x / mass_water_aq_x + + s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; + + s_x[i]->diff_layer[j].dh2o_moles = - s_x[i]->moles * + (s_x[i]->diff_layer[j].charge->g[count_g].g + 1) * + s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; + + s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; + + /* surface related to phase */ + + s_x[i]->diff_layer[j].drelated_moles = s_x[i]->moles * (s_x[i]->diff_layer[j].charge->g[count_g].g + 1) * use.surface_ptr->charge[j].specific_area * use.surface_ptr->thickness / mass_water_aq_x; +#endif +/* + * partially corrected formulation assumes mass of water in diffuse layer + * is insignificant. Excess is calculated on the basis of moles_water_aq_x + * instead of moles_water_bulk. + */ + /* revised eq. 61 */ + s_x[i]->diff_layer[j].g_moles = s_x[i]->moles * + (s_x[i]->diff_layer[j].charge->g[count_g].g + + s_x[i]->diff_layer[j].charge->mass_water / + mass_water_aq_x); + if (s_x[i]->moles > 1e-30) { + s_x[i]->diff_layer[j].dg_g_moles = s_x[i]->dg * s_x[i]->diff_layer[j].g_moles / s_x[i]->moles; + } + + /* + * first term of 63 is summed for all surfaces in + * s_x[i]->tot_g_moles. This sum is then used in + * the jacobian for species i + */ + total_g += s_x[i]->diff_layer[j].charge->g[count_g].g + s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; + + /* revised eq. 63, second term */ + /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ + s_x[i]->diff_layer[j].dx_moles = s_x[i]->moles * s_x[i]->diff_layer[j].charge->g[count_g].dg; + + /* revised eq. 63, third term */ + s_x[i]->diff_layer[j].dh2o_moles = - s_x[i]->moles * s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; + s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; + + /* surface related to phase */ + s_x[i]->diff_layer[j].drelated_moles = s_x[i]->moles * + use.surface_ptr->charge[j].specific_area * + use.surface_ptr->thickness / mass_water_aq_x; + } + s_x[i]->tot_g_moles = s_x[i]->moles * (1 + total_g); + + /* note that dg is for cb, act water, mu eqns */ + /* dg_total_g for mole balance eqns */ + /* dg_g_moles for surface cb */ + + if (s_x[i]->moles > 1e-30) { + s_x[i]->dg_total_g = s_x[i]->dg * s_x[i]->tot_g_moles / s_x[i]->moles; + } else { + s_x[i]->dg_total_g = 0.0; + } +#ifdef SKIP +#endif + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "%s\t%e\t%e\n", s_x[i]->name, (double) s_x[i]->moles, (double) s_x[i]->tot_g_moles); + output_msg(OUTPUT_MESSAGE, "\tg\n"); + for (j=0; j < use.surface_ptr->count_charge; j++) { + count_g = s_x[i]->diff_layer[j].count_g; + output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].charge->g[count_g].g); + } + output_msg(OUTPUT_MESSAGE, "\n\tg_moles\n"); + for (j=0; j < use.surface_ptr->count_charge; j++) { + output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].g_moles); + } + output_msg(OUTPUT_MESSAGE, "\n\tdg\n"); + for (j=0; j < use.surface_ptr->count_charge; j++) { + count_g = s_x[i]->diff_layer[j].count_g; + output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].charge->g[count_g].dg); + } + output_msg(OUTPUT_MESSAGE, "\n\tdx_moles\n"); + for (j=0; j < use.surface_ptr->count_charge; j++) { + output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].dx_moles); + } + output_msg(OUTPUT_MESSAGE, "\n\tdh2o_moles\t%e\n", (double) s_x[i]->tot_dh2o_moles); + for (j=0; j < use.surface_ptr->count_charge; j++) { + output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].dh2o_moles); + } + output_msg(OUTPUT_MESSAGE, "\n"); + } + } + } + if (use.gas_phase_ptr != NULL) calc_gas_pressures(); + if (use.s_s_assemblage_ptr != NULL) calc_s_s_fractions(); + + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int calc_gas_pressures(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE lp; + struct rxn_token *rxn_ptr; + struct gas_comp *gas_comp_ptr; + struct phase *phase_ptr; +/* + * moles and partial pressures for gases + */ + if (use.gas_phase_ptr == NULL) return(OK); + if (use.gas_phase_ptr->type == VOLUME) { + use.gas_phase_ptr->total_p = 0; + use.gas_phase_ptr->total_moles = 0; + } + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); + phase_ptr = use.gas_phase_ptr->comps[i].phase; + if (phase_ptr->in == TRUE) { + lp=-phase_ptr->lk; + for (rxn_ptr=phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + gas_comp_ptr->phase->p_soln_x = exp(lp * LOG_10); + if (use.gas_phase_ptr->type == PRESSURE) { + gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * + gas_unknown->moles / gas_unknown->gas_phase->total_p; + gas_comp_ptr->phase->fraction_x = gas_comp_ptr->phase->moles_x / gas_unknown->moles; + } else { + gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * + use.gas_phase_ptr->volume / (R_LITER_ATM * tk_x); + use.gas_phase_ptr->total_p += gas_comp_ptr->phase->p_soln_x; + use.gas_phase_ptr->total_moles += gas_comp_ptr->phase->moles_x; + } + } else { + gas_comp_ptr->phase->moles_x = 0; + gas_comp_ptr->phase->fraction_x = 0; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int calc_s_s_fractions(void) +/* ---------------------------------------------------------------------- */ +{ + int i, k; + LDBLE moles, n_tot; + struct s_s *s_s_ptr; + +/* + * moles and lambdas for solid solutions + */ + if (s_s_unknown == NULL) return(OK); +/* + * Calculate mole fractions and log lambda and derivative factors + */ + if (use.s_s_assemblage_ptr == NULL) return(OK); + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + s_s_ptr = &(use.s_s_assemblage_ptr->s_s[i]); + n_tot = 0; + for (k = 0; k < s_s_ptr->count_comps; k++) { + moles = s_s_ptr->comps[k].moles; + if (s_s_ptr->comps[k].moles < 0) { + moles = MIN_TOTAL; + s_s_ptr->comps[k].initial_moles = moles; + } + n_tot += moles; + } + s_s_ptr->total_moles = n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) { + moles = s_s_ptr->comps[k].moles; + if (s_s_ptr->comps[k].moles < 0) { + moles = MIN_TOTAL; + } + s_s_ptr->comps[k].fraction_x = moles / n_tot; + s_s_ptr->comps[k].log10_fraction_x = log10(moles / n_tot); + + /* all mb and jacobian items must be in x or phase to be static between models */ + s_s_ptr->comps[k].phase->log10_fraction_x = s_s_ptr->comps[k].log10_fraction_x; + } + if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0) { + s_s_binary(s_s_ptr); + } else { + s_s_ideal(s_s_ptr); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_binary(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, a0, a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE xb1, xc1; +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = s_s_ptr->total_moles; + + nc = s_s_ptr->comps[0].moles; + xc = nc/n_tot; + nb = s_s_ptr->comps[1].moles; + xb = nb/n_tot; +/* + * In miscibility gap + */ + a0 = s_s_ptr->a0; + a1 = s_s_ptr->a1; + if (s_s_ptr->miscibility == TRUE && xb > s_s_ptr->xb1 && xb < s_s_ptr->xb2) { + xb1 = s_s_ptr->xb1; + xc1 = 1.0 - xb1; + s_s_ptr->comps[0].fraction_x = xc1; + s_s_ptr->comps[0].log10_fraction_x = log10(xc1); + s_s_ptr->comps[0].phase->log10_fraction_x = s_s_ptr->comps[0].log10_fraction_x; + + s_s_ptr->comps[1].fraction_x = xb1; + s_s_ptr->comps[1].log10_fraction_x = log10(xb1); + s_s_ptr->comps[1].phase->log10_fraction_x = s_s_ptr->comps[1].log10_fraction_x; + + s_s_ptr->comps[0].log10_lambda = xb1*xb1*(a0 - a1*(3 -4*xb1))/LOG_10; + s_s_ptr->comps[0].phase->log10_lambda = s_s_ptr->comps[0].log10_lambda; + + s_s_ptr->comps[1].log10_lambda = xc1*xc1*(a0 + a1*(4*xb1 - 1))/LOG_10; + s_s_ptr->comps[1].phase->log10_lambda = s_s_ptr->comps[1].log10_lambda; + + s_s_ptr->comps[0].dnb = 0; + s_s_ptr->comps[0].dnc = 0; + s_s_ptr->comps[1].dnb = 0; + s_s_ptr->comps[1].dnc = 0; + s_s_ptr->comps[0].phase->dnb = 0; + s_s_ptr->comps[0].phase->dnc = 0; + s_s_ptr->comps[1].phase->dnb = 0; + s_s_ptr->comps[1].phase->dnc = 0; + } else { +/* + * Not in miscibility gap + */ + s_s_ptr->comps[0].fraction_x = xc; + s_s_ptr->comps[0].log10_fraction_x = log10(xc); + s_s_ptr->comps[0].phase->log10_fraction_x = s_s_ptr->comps[0].log10_fraction_x; + + s_s_ptr->comps[1].fraction_x = xb; + s_s_ptr->comps[1].log10_fraction_x = log10(xb); + s_s_ptr->comps[1].phase->log10_fraction_x = s_s_ptr->comps[1].log10_fraction_x; + + s_s_ptr->comps[0].log10_lambda = xb*xb*(a0 - a1*(3 -4*xb))/LOG_10; + s_s_ptr->comps[0].phase->log10_lambda = s_s_ptr->comps[0].log10_lambda; + + s_s_ptr->comps[1].log10_lambda = xc*xc*(a0 + a1*(4*xb - 1))/LOG_10; + s_s_ptr->comps[1].phase->log10_lambda = s_s_ptr->comps[1].log10_lambda; + + xc2 = xc*xc; + xc3 = xc2*xc; + xb2 = xb*xb; + xb3 = xb2*xb; + xb4 = xb3*xb; +#ifdef SKIP + /* first component */ + dnb = -2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 - 4*a1*xc*xb4 - 8*a1*xb3*xc2 - + 4*a1*xb2*xc3 - 2*a0*xc*xb2 - 8*a1*xc*xb3 + 6*a1*xc*xb2 + 1; + s_s_ptr->comps[0].phase->dnb = dnb/n_tot; + dnc = 2*a0*xb3 + 2*a0*xc*xb2 + 8*a1*xb4 + 8*a1*xc*xb3 - 2*a1*xb3 - 6*a1*xc*xb2; + s_s_ptr->comps[0].phase->dnc = - xb/nc + dnc/n_tot; + + /* second component */ + dnb = 2*a0*xb*xc2 + 2*a0*xc3 + 8*a1*xb2*xc2 + 8*a1*xb*xc3 - 2*a1*xb*xc2 -6*a1*xc3; + s_s_ptr->comps[1].phase->dnb = -xc/nb + dnb/n_tot; + dnc = -2*a0*xc*xb2 - 8*a1*xc*xb3 + 2*a1*xc*xb2 - 2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 + 1; + s_s_ptr->comps[1].phase->dnc = dnc/n_tot; +#endif + /* used derivation that did not substitute x2 = 1-x1 */ + + /* first component, df1/dn1*/ + dnc = 2*a0*xb2 + 12*a1*xc*xb2 + 6*a1*xb2; + s_s_ptr->comps[0].phase->dnc = - xb/nc + dnc/n_tot; + + + /* first component, df1/dn2*/ + dnb = 1 - 2*a0*xb + 2*a0*xb2 + 8*a1*xc*xb - 12*a1*xc*xb2 - 2*a1*xb + 2*a1*xb2; + s_s_ptr->comps[0].phase->dnb = dnb/n_tot; + + /* second component, df2/dn1 */ + dnc = 1 -2*a0*xc +2*a0*xc2 - 8*a1*xb*xc + 12*a1*xb*xc2 + 2*a1*xc - 2*a1*xc2; + s_s_ptr->comps[1].phase->dnc = dnc/n_tot; + + /* second component, df2/dn2 */ + dnb = 2*a0*xc2 + 12*a1*xb*xc2 - 6*a1*xc2; + s_s_ptr->comps[1].phase->dnb = -xc/nb + dnb/n_tot; + + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_ideal(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + int k, j; + LDBLE n_tot, n_tot1; + +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = s_s_ptr->total_moles; + +/* + * Ideal solid solution + */ + s_s_ptr->dn = 1.0 / n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) { + n_tot1 = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) { + if (j != k) { + n_tot1 += s_s_ptr->comps[j].moles; + } + } + s_s_ptr->comps[k].log10_lambda = 0; + s_s_ptr->comps[k].phase->log10_lambda = 0; + + s_s_ptr->comps[k].dnb = -(n_tot1)/(s_s_ptr->comps[k].moles*n_tot); + s_s_ptr->comps[k].phase->dnb = s_s_ptr->comps[k].dnb; + + s_s_ptr->comps[k].dn = s_s_ptr->dn; + s_s_ptr->comps[k].phase->dn = s_s_ptr->dn; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int reset(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks deltas (changes to unknowns) to make sure they are reasonable + * Scales deltas if necessary + * Updates unknowns with deltas + */ + + int i, j; + int converge; + LDBLE up, down; + LDBLE d; + LDBLE factor, f0; + LDBLE sum_deltas; + LDBLE step_up; +#ifdef SKIP + LDBLE epsilon; +#endif + LDBLE mu_calc; + LDBLE old_moles; +/*appt char name[MAX_LENGTH]; LDBLE surf_chrg_eq; + */ +/* + * Calculate interphase mass transfers + */ +#ifdef SKIP + if (punch.high_precision == FALSE) + epsilon = 1e-9; + else + epsilon = 1.e-12; +#endif + step_up = log(step_size_now); + factor = 1.; + + if ( pure_phase_unknown != NULL || s_s_unknown != NULL) { +/* + * Don't take out more mineral than is present + */ + for (i=0; itype == PP || x[i]->type == S_S_MOLES) { + if (/* delta[i] > 0.0 && */ x[i]->moles > 0.0 && delta[i] > x[i]->moles ) { + f0 = delta[i] / x[i]->moles; + if (f0 > factor) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s, Removing more than total mineral.\t%f\n", + x[i]->description, (double) f0); + } + factor=f0; + } + } else if ( delta[i] > 0.0 && x[i]->moles <= 0.0 ) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "%-10.10s\tDelta: %e\tMass: %e " + "Dissolving mineral with 0.0 mass.\n ", + x[i]->description, (double) delta[i], (double) x[i]->moles); + } + delta[i] = 0.0 ; + } else if (delta[i] < 0.0 && x[i]->moles > 0.0 && delta[i] < -100.0 ) { + f0 = -delta[i] / 100.0 ; + if (f0 > factor) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s, Precipitating too much mineral.\t%f\n", x[i]->description, (double) f0); + } + factor=f0; + } + } + } + } + } +/* + * Calculate change in element concentrations due to pure phases and gases + */ + if (pure_phase_unknown != NULL || gas_unknown != NULL || s_s_unknown != NULL) { + for(i=0; i < count_unknowns; i++) { + x[i]->delta = 0.0; + } + + for (i=0; i < count_sum_delta; i++) { + *sum_delta[i].target += *sum_delta[i].source * sum_delta[i].coef; + } + +/* + * Apply factor from minerals to deltas + */ + + + for(i=0; i < count_unknowns; i++) { + x[i]->delta /= factor; + if (x[i]->type == PP || x[i]->type == S_S_MOLES) delta[i] /= factor; + } + + } + + +/* + * Calc factor for mass balance equations for aqueous unknowns + */ + factor=1.0; + sum_deltas=0.0; + for (i=0; i < count_unknowns; i++) { + sum_deltas += fabs(delta[i]); + up = step_up; + down = up; + if (x[i]->type <= SOLUTION_PHASE_BOUNDARY) { + up = step_up; + down = 1.3 * up; + } else if (x[i]->type == MU) { + up = 100 * mu_x; +#ifdef SKIP + if (up > 0.1) { + up = 2 * mu_x; + up = 0.1; + } +#endif +#ifdef SKIP + down = 0.7 * mu_x; + if (down < 0.1) down = 0.1; +#endif + down = mu_x; + } else if (x[i]->type == AH2O) { + down = up; + } else if (x[i]->type == MH) { + up = log(pe_step_size_now); + down = 1.3*up; + } else if (x[i]->type == MH2O) { + /* ln gH2O + delta; ln(gH2O*delta); */ + /* + up = log(10.); + down = log(4.); + */ + up = log(1.3); + down = log(1.2); + + } else if (x[i]->type == PP) { + continue; + } else if (x[i]->type == GAS_MOLES) { + up = 1000. * x[i]->moles; + if (up <= 0.0) up = 1e-1; + if (up >= 1.0) up = 1.; + down = x[i]->moles; + } else if (x[i]->type == S_S_MOLES) { + continue; + } else if (x[i]->type == EXCH) { + up = step_up; + down = 1.3 * up; + } else if (x[i]->type == SURFACE) { + up = step_up; + down = 1.3 * up; + } else if (x[i]->type == SURFACE_CB) { + up = step_up; + down = 1.3 * up; + } + + if (delta[i] > 0.0) { + f0=delta[i]/up; + if (f0 > factor) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s\t%f\n",x[i]->description, (double) f0); + } + factor=f0; + } + } else { + f0=delta[i]/(-down); + if (f0 > factor) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s\t%f\n",x[i]->description, (double) f0); + } + factor=f0; + } + } + } + + /*converge=TRUE;*/ + + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nSum of deltas: %12.6f\n", (double) sum_deltas); + output_msg(OUTPUT_MESSAGE,"Factor: %12.4e\n", (double) factor); + } + factor = 1.0/factor; + + for (i=0; itype != PP && x[i]->type != S_S_MOLES) delta[i] *= factor; + } +/* + * Solution mass balances: MB, ALK, CB, SOLUTION_PHASE_BOUNDARY + */ + for (i=0; i < count_unknowns ; i++) { + if (x[i]->type == MB || x[i]->type == ALK || x[i]->type == EXCH || x[i]->type == SURFACE) { + /*if ( fabs(delta[i]) >= epsilon ) converge = FALSE;*/ + d = delta[i] / LOG_10; + /* surface */ + if (x[i]->type == SURFACE) { + old_moles = x[i]->moles; + if (x[i]->phase_unknown != NULL) { + x[i]->moles = x[i]->surface_comp->phase_proportion * + (x[i]->phase_unknown->moles - + delta[x[i]->phase_unknown->number]); + if (x[i]->phase_unknown->moles - delta[x[i]->phase_unknown->number] <= MIN_RELATED_SURFACE) { + x[i]->moles = 0.0; + if (fabs(x[i]->f) > MIN_RELATED_SURFACE) { + x[i]->master[0]->s->la -= 5.; + } + } + if (old_moles <= 0 && x[i]->moles > 0) { + x[i]->master[0]->s->la = log10(x[i]->moles) - 5.; + } + } + } + /* exch */ + if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) { + x[i]->moles = 0.0; + if (fabs(x[i]->f) > MIN_RELATED_SURFACE) { + x[i]->master[0]->s->la -= 5.; + } + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e " + "%-8s%10.2e\n", x[i]->description, + "old la", (double) x[i]->master[0]->s->la, + "new la", (double) x[i]->master[0]->s->la + (double) d, + "delta", (double) delta[i], "delta/c", (double) d); + } + x[i]->master[0]->s->la += d; + if (x[i]->master[0]->s->la < (double) (DBL_MIN_10_EXP+10)) x[i]->master[0]->s->la = (double) (DBL_MIN_10_EXP+10); + +/* + * Surface charge balance + */ + + } else if ( x[i]->type == SURFACE_CB ) { + d = delta[i] / LOG_10; + if (x[i]->phase_unknown != NULL) { + x[i]->surface_charge->grams = /* !!!! x[i]->surface_comp->phase_proportion * */ + (x[i]->phase_unknown->moles - + delta[x[i]->phase_unknown->number]); + if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { + x[i]->surface_charge->grams = 0.0; + } + } + if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { + x[i]->surface_charge->grams = 0.0; + } +#ifdef SKIP + else if (fabs(delta[i]) > epsilon) { + converge=FALSE; + } +#endif + x[i]->related_moles = x[i]->surface_charge->grams; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", + x[i]->description, "old f*psi", (double) x[i]->master[0]->s->la, "new f*psi", (double) x[i]->master[0]->s->la + (double) d,"delta", (double) d); + } + + x[i]->master[0]->s->la += d; + + /* recalculte g's for component */ + if (diffuse_layer_x == TRUE) { + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "\ncharge, old g, new g, dg*delta," + " dg, delta\n"); + } + for (j = 0; j < x[i]->surface_charge->count_g; j++) { + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE, "%12f\t%12.4e\t%12.4e\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[i]->surface_charge->g[j].charge, + (double) x[i]->surface_charge->g[j].g, + (double) x[i]->surface_charge->g[j].g + + (double) (x[i]->surface_charge->g[j].dg * delta[i]), + (double) (x[i]->surface_charge->g[j].dg * delta[i]), + (double) x[i]->surface_charge->g[j].dg, + (double) delta[i]); + } +/*appt*/ if (use.surface_ptr->donnan != TRUE) { + x[i]->surface_charge->g[j].g += x[i]->surface_charge->g[j].dg * delta[i]; + } + } +/*appt*/ if (use.surface_ptr->donnan == TRUE) { + calc_all_donnan(); + } + } + +/* Solution phase boundary */ + } else if ( x[i]->type == SOLUTION_PHASE_BOUNDARY ) { + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + d = delta[i] / LOG_10; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); + } + x[i]->master[0]->s->la += d; +/* Charge balance */ + } else if ( x[i]->type == CB ) { + /*if (fabs(delta[i]) > epsilon * mu_x * mass_water_aq_x ) converge=FALSE;*/ + d = delta[i] / LOG_10; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); + } + x[i]->master[0]->s->la += d; +/* Ionic strength */ + } else if (x[i]->type == MU) { + + /*if (fabs(delta[i]) > epsilon * mu_x ) converge=FALSE;*/ + mu_calc = 0.5*mu_unknown->f/mass_water_aq_x; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"Calculated mu: %e\n", (double) mu_calc); + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", + x[i]->description, "old mu", (double) mu_x, "new mu", + (double) (mu_x + delta[i]), + "delta", (double) delta[i]); + } + d = mu_x + delta[i]; + if (d < 1e-7) { + delta[i] = sqrt(mu_calc * mu_x) - mu_x; + mu_x = sqrt(mu_calc * mu_x); + } else { + mu_x += delta[i]; + } + if (mu_x <= 1e-8) { + mu_x = 1e-8; + } +/* Activity of water */ + } else if (x[i]->type == AH2O) { + /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue;*/ + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + d = delta[i] / LOG_10; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); + } + s_h2o->la += d; + if (pitzer_model == FALSE) { + if (s_h2o->la < -1.0) { + d = -1.0 - s_h2o->la; + delta[i] = d * LOG_10; + s_h2o->la = -1.0; + } + } +/* pe */ + } else if (x[i]->type == MH) { + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + d = delta[i] / LOG_10; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old pe", (double) x[i]->master[0]->s->la, "new pe", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); + } + s_eminus->la += d; +/* Mass of water */ + } else if (x[i]->type == MH2O) { + if (mass_water_switch == TRUE) continue; + /*if (fabs(delta[i]) > epsilon * mass_water_aq_x) converge=FALSE;*/ + /* ln(gh2o) + delta, log(gh2o) + d, gh2o * 10**d */ + d = exp(delta[i]); + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old MH2O", (double) mass_water_aq_x, "new MH2O", (double) (mass_water_aq_x * d), "delta", (double) delta[i], "10**d/c", (double) d); + } + mass_water_aq_x *= d; + mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; + if (debug_model == TRUE && diffuse_layer_x == TRUE) { + output_msg(OUTPUT_MESSAGE,"mass_water bulk: %e\taq: %e\tsurfaces: %e\n", + (double) mass_water_bulk_x, (double) mass_water_aq_x, (double) mass_water_surfaces_x); + } + x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; + + if (mass_water_aq_x < 1e-10) { + sprintf(error_string, "Mass of water is less than 1e-10 kilogram.\n" + "The aqueous phase may not be stable relative to given masses of minerals."); + warning_msg(error_string); + stop_program = TRUE; + return(TRUE); + } +/* Pure phases */ + } else if (x[i]->type == PP) { + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mass", (double) x[i]->moles, + "new mass", (double) (x[i]->moles - delta[i]), "delta", (double) delta[i]); + } + x[i]->moles -= delta[i]; +/* if (fabs(x[i]->moles) < MIN_RELATED_SURFACE) x[i]->moles = 0.0; */ + } else if (x[i]->type == GAS_MOLES) { + + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + /*if (gas_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE;*/ + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mol", (double) x[i]->moles, + "new mol", (double) (x[i]->moles + delta[i]), + "delta", (double) delta[i]); + } + x[i]->moles += delta[i]; + if (x[i]->moles < MIN_TOTAL) x[i]->moles = MIN_TOTAL; + } else if (x[i]->type == S_S_MOLES) { + + /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ + /*if (x[i]->s_s_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE;*/ + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mol", (double) x[i]->moles, + "new mol", (double) (x[i]->moles - delta[i]), + "delta", (double) delta[i]); + } + x[i]->moles -= delta[i]; + if (x[i]->moles < MIN_TOTAL) x[i]->moles = MIN_TOTAL; + x[i]->s_s_comp->moles = x[i]->moles; +/* Pitzer gamma */ + } else if ( x[i]->type == PITZER_GAMMA ) { + if (full_pitzer == FALSE) continue; + d = delta[i]; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old lg", (double) x[i]->s->lg, "new lg", (double) (x[i]->s->lg + d), "delta", (double) delta[i], "delta", (double) d); + } + x[i]->s->lg += d; + } + } +/* + * Reset total molalities in mass balance equations + */ + if (pure_phase_unknown != NULL || gas_unknown != NULL || s_s_unknown != NULL) { + for (i=0; itype == MB || x[i]->type == MH || + x[i]->type == MH2O || + x[i]->type == CB || x[i]->type == EXCH || + x[i]->type == SURFACE ) { + /*if (fabs(x[i]->delta) > epsilon*x[i]->moles) converge = FALSE;*/ + if (x[i]->type == SURFACE) x[i]->delta = 0.0; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mole", (double) x[i]->moles, + "new mole", (double) (x[i]->moles + x[i]->delta), + "delta", (double) x[i]->delta); + } + x[i]->moles += x[i]->delta; + } + } + } + converge = FALSE; + return(converge); +} +/* ---------------------------------------------------------------------- */ +int residuals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates residuals for all equations + */ + int i; + int converge; + + LDBLE toler; + LDBLE sum_residual; + LDBLE sinh_constant; + + sum_residual = 0.0; + +/* + * Calculate residuals + */ + converge = TRUE; +#ifdef SKIP + if (punch.high_precision == FALSE) + toler = 1e-8; + else + toler = 1.e-12; +#endif + toler = convergence_tolerance; + + for (i=0; i < count_unknowns; i++) { + if (x[i]->type == MB ) { + residual[i] = x[i]->moles - x[i]->f; + if (fabs(residual[i]) > toler * x[i]->moles && x[i]->moles > MIN_TOTAL ) { + /* + fprintf(stderr,"Residuals %d: %s %d %e\n", iterations, x[i]->description, i, residual[i]); + */ + converge = FALSE; + } + } else if (x[i]->type == ALK) { + residual[i] = x[i]->moles - x[i]->f; + if (fabs(residual[i]) > toler * x[i]->moles ) converge = FALSE; + } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { + residual[i] = x[i]->f * LOG_10; + if (fabs(residual[i]) > toler ) converge = FALSE; + } else if (x[i]->type == CB) { + residual[i] = - x[i]->f; + if (ph_unknown == charge_balance_unknown) { + residual[i] += x[i]->moles; + } + if (fabs(residual[i]) >= toler * mu_x * mass_water_aq_x ) converge = FALSE; + } else if (x[i]->type == MU && pitzer_model == FALSE) { + residual[i] = mass_water_aq_x * mu_x - 0.5*x[i]->f; + if (fabs(residual[i]) > toler*mu_x * mass_water_aq_x ) converge = FALSE; + } else if (x[i]->type == AH2O /*&& pitzer_model == FALSE*/) { + /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue;*/ + residual[i] = mass_water_aq_x*exp(s_h2o->la * LOG_10) - mass_water_aq_x + 0.017 * x[i]->f; + if (pitzer_model) { + residual[i] = pow(10.0,s_h2o->la) - AW; + if (full_pitzer == FALSE) { + residual[i] = 0.0; + } + } + if (fabs(residual[i]) > toler ) converge = FALSE; + } else if (x[i]->type == MH && pitzer_model == FALSE) { +#ifdef COMBINE + residual[i] = x[i]->moles - x[i]->f; +#else + residual[i] = (x[i]->moles - 2*s_h2o->moles) - x[i]->f; + x[i]->f += 2 * s_h2o->moles; +#endif + if (mass_water_switch == TRUE) { + residual[i] -= 2 * (mass_oxygen_unknown->moles - mass_oxygen_unknown->f); + } +#ifdef COMBINE +#ifndef COMBINE_CHARGE + if (fabs(residual[i]) > toler*(x[i]->moles + 2 * mass_oxygen_unknown->moles)) converge = FALSE; +#else + if (fabs(residual[i]) > toler*(x[i]->moles + 2 * mass_oxygen_unknown->moles + charge_balance_unknown->moles)) converge = FALSE; +#endif +#else + if (fabs(residual[i]) > toler*x[i]->moles ) converge = FALSE; +#endif + } else if (x[i]->type == MH2O) { + if (mass_water_switch == TRUE) continue; +#ifdef COMBINE + residual[i] = x[i]->moles - x[i]->f; +#else + residual[i] = (x[i]->moles - s_h2o->moles) - x[i]->f; + x[i]->f += s_h2o->moles; +#endif + if (fabs(residual[i]) > 0.01 * toler*x[i]->moles ) converge = FALSE; + } else if (x[i]->type == PP) { + residual[i] = x[i]->f * LOG_10; + if (x[i]->pure_phase->add_formula == NULL) { + if (x[i]->dissolve_only == TRUE) { + if ((residual[i] > toler && x[i]->moles > 0.0) || (residual[i] < -toler && (x[i]->pure_phase->initial_moles - x[i]->moles) > 0)) { + converge = FALSE; + } + } else { + if (residual[i] < -toler || iterations < 1) converge = FALSE; + } + } else { + /* if (x[i]->moles > 0.0 && fabs(residual[i]) > toler) converge = FALSE;*/ + if (residual[i] < -toler || iterations < 1) { + converge = FALSE; + } + } + } else if (x[i]->type == GAS_MOLES) { + residual[i] = x[i]->gas_phase->total_p - x[i]->f; + if (fabs(residual[i]) > toler && gas_in == TRUE) converge = FALSE; + } else if (x[i]->type == S_S_MOLES) { + residual[i] = x[i]->f * LOG_10; + if (fabs(residual[i]) > toler && x[i]->s_s_in == TRUE) converge = FALSE; + } else if (x[i]->type == EXCH) { + residual[i] = x[i]->moles - x[i]->f; + if (x[i]->moles <= MIN_RELATED_SURFACE) { + if (fabs(residual[i]) > toler) converge = FALSE; + } else if (fabs(residual[i]) > toler * x[i]->moles ) { + converge = FALSE; + } + } else if (x[i]->type == SURFACE) { + residual[i] = x[i]->moles - x[i]->f; + if (x[i]->moles <= MIN_RELATED_SURFACE) { + if ( fabs(residual[i]) > toler ) converge = FALSE; + } else if (fabs(residual[i]) > toler * x[i]->moles ) { + converge = FALSE; + } + } else if (x[i]->type == PITZER_GAMMA) { + if (full_pitzer == FALSE) continue; + residual[i] = x[i]->s->lg - x[i]->s->lg_pitzer; + if (fabs(residual[i]) > toler ) { + /* + fprintf(stderr,"Residuals %d: %s %d %e\n", iterations, x[i]->description, i, residual[i]); + */ + converge = FALSE; + } + } else if (x[i]->type == SURFACE_CB) { + /*sinh_constant = 0.1174;*/ + sinh_constant = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*tk_x*1000); +/* if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { */ + if (x[i]->surface_charge->grams == 0) { + residual[i] = 0.0; + } else if (diffuse_layer_x == TRUE) { + residual[i] = - x[i]->f; + } else { +/* + * sinh_constant is (8 e e0 R T 1000)**1/2 + * = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*t_x*1000) + * ~ 0.1174 at 25C + */ + residual[i] = sinh_constant * sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10) - + x[i]->f * F_C_MOL / + (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams); + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"Charge/Potential\n"); + if (x[i]->surface_charge->grams > 0) { + output_msg(OUTPUT_MESSAGE,"\tSum of surface charge %e eq\n", + (double) (x[i]->f /* F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams)*/)); + } else { + output_msg(OUTPUT_MESSAGE,"\tResidual %e\n", (double) x[i]->f ); + } + output_msg(OUTPUT_MESSAGE,"\t grams %g\n", (double) x[i]->surface_charge->grams); + output_msg(OUTPUT_MESSAGE,"\tCharge from potential %e eq\n", + (double) (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams / F_C_MOL * + sinh_constant * sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10))); + output_msg(OUTPUT_MESSAGE,"\t FPsi/2RT %e\n", + (double) (x[i]->master[0]->s->la * LOG_10)); + output_msg(OUTPUT_MESSAGE,"\t Sinh(FPsi/2RT) %e\n", + sinh(x[i]->master[0]->s->la * LOG_10)); + output_msg(OUTPUT_MESSAGE,"\t Cosh(FPsi/2RT) %e\n", + cosh(x[i]->master[0]->s->la * LOG_10)); + output_msg(OUTPUT_MESSAGE,"\t Sqrt(mu_x) %e\n", + sqrt(mu_x)); + } + if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE && fabs(residual[i]) > toler ) converge = FALSE; + } +/* + * Store residuals in array + */ + array[(i+1)*(count_unknowns+1)-1] = residual[i]; + sum_residual += fabs(residual[i]); + } +/* + * Return + */ + if (pitzer_model == TRUE && iterations < 1) return(OK); + if (converge == TRUE ) { + return (CONVERGED); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set(int initial) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets initial guesses for unknowns if initial == TRUE + * Revises guesses whether initial is true or not + */ + int i; + struct solution *solution_ptr; +/* + * Set initial log concentrations to zero + */ + if (pitzer_model == TRUE) return(set_pz(initial)); + iterations = -1; + solution_ptr = use.solution_ptr; + for (i=0; i < count_s_x; i++) { + s_x[i]->lm = LOG_ZERO_MOLALITY; + s_x[i]->lg = 0.0; + } +/* + * Set master species activities + */ + + tc_x=solution_ptr->tc; + tk_x=tc_x+273.15; +/* + * H+, e-, H2O + */ + mass_water_aq_x = solution_ptr->mass_water; + mu_x = solution_ptr->mu; + s_h2o->moles = mass_water_aq_x/gfw_water; + s_h2o->la = log10(solution_ptr->ah2o); + s_hplus->la = - solution_ptr->ph; + s_hplus->lm = s_hplus->la; + s_hplus->moles = exp(s_hplus->lm * LOG_10)*mass_water_aq_x; + s_eminus->la= - solution_ptr->solution_pe; + if (initial == TRUE) initial_guesses(); + if (diffuse_layer_x == TRUE) initial_surface_water(); + revise_guesses(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make initial guesses for activities of master species and + * ionic strength + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.solution_ptr; + mu_x = s_hplus->moles + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + mu_x /= mass_water_aq_x; + s_h2o->la=0.0; + for ( i=0; i < count_unknowns; i++ ) { + if (x[i] == ph_unknown || x[i] == pe_unknown ) continue; + if (x[i]->type < CB) { + mu_x += x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * + x[i]->master[0]->s->z; + x[i]->master[0]->s->la = log10(x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == CB) { + x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { + x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == EXCH) { + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + x[i]->master[0]->s->la = log10(x[i]->moles); + } + } else if (x[i]->type == SURFACE) { + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); + } + } else if (x[i]->type == SURFACE_CB) { + x[i]->master[0]->s->la = 0.0; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int revise_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Revise la's of master species + */ + int i; + int iter, max_iter, repeat, fail; + LDBLE weight, f; +/*appt char name[MAX_LENGTH]; LDBLE surf_chrg_eq; + */ + max_iter = 10; + gammas(mu_x); + iter = 0; + repeat = TRUE; + fail = FALSE;; + while ( repeat == TRUE ) { + iter++; + if (debug_set == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nBeginning set iteration %d.\n", iter); + } + if (iter == max_iter + 1) { + output_msg(OUTPUT_LOG, "Did not converge in set, iteration %d.\n", iterations); + fail = TRUE; + } + if (iter > 2*max_iter) { + output_msg(OUTPUT_LOG, "Did not converge with relaxed criteria in set.\n"); + return(OK); + } + molalities(TRUE); + mb_sums(); + if (state < REACTION) { + sum_species(); + } else { + for (i = 0; i < count_unknowns; i++) { + x[i]->sum = x[i]->f; + } + } +/* debug + if (debug_set == TRUE) { + pr.species = TRUE; + pr.all = TRUE; + print_species(); + } + */ + repeat=FALSE; + for ( i=0; i < count_unknowns; i++ ) { + if (x[i] == ph_unknown || x[i] == pe_unknown) continue; + if (x[i]->type == MB || +/* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || + x[i]->type == SURFACE ) { + + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\t%5s at beginning of set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + if (fabs(x[i]->moles) < 1e-30) x[i]->moles = 0; + f = fabs(x[i]->sum); + if (f == 0 && x[i]->moles == 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + continue; + } else if (f == 0) { + repeat = TRUE; + x[i]->master[0]->s->la += 5; +/*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { + continue; + } else if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + repeat = TRUE; + x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); + } + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t%5s not converged in set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + } + } else if (x[i]->type == ALK) { + f = total_co2; + if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { + continue; + } + if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { + repeat = TRUE; + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + x[i]->master[0]->s->la += weight * + log10(fabs(x[i]->moles / x[i]->sum)); + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"%s not converged in set. %e\t%e\t%e\n", x[i]->description, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + } + } + } + } + output_msg(OUTPUT_LOG,"Iterations in revise_guesses: %d\n", iter); + mu_x = mu_unknown->f * 0.5 / mass_water_aq_x; + if (mu_x <= 1e-8) { + mu_x = 1e-8; + } + gammas(mu_x); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int sum_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates total alk, total carbon, total co2, electrical balance, + * total hydrogen, and total oxygen. + * + * Sorts species for summing and printing based on valence state and + * concentrations. + * + * Sums total valence states and stores in master[i]->total. + */ + int i, j; + struct master *master_ptr; +/* + * Set global variables + */ + ph_x = -s_hplus->la; + solution_pe_x = -s_eminus->la; + ah2o_x = exp(s_h2o->la * LOG_10); + density_x = 1.0; + if (s_o2 != NULL) s_o2->moles = under(s_o2->lm) * mass_water_aq_x; + if (s_h2 != NULL) s_h2->moles = under(s_h2->lm) * mass_water_aq_x; + +/* + * Calculate sums + */ + total_alkalinity = 0.0; + total_carbon = 0.0; + total_co2 = 0.0; + cb_x = 0.0; + total_ions_x = 0.0; + total_o_x = 0.0; + total_h_x = 0.0; + for (i=0; i < count_s_x; i++) { + if (s_x[i]->type == EX ) continue; + if (s_x[i]->type == SURF ) continue; + cb_x += s_x[i]->z * s_x[i]->moles; + total_ions_x += fabs(s_x[i]->z * s_x[i]->moles); + total_alkalinity += s_x[i]->alk * s_x[i]->moles; + total_carbon += s_x[i]->carbon * s_x[i]->moles; + total_co2 += s_x[i]->co2 * s_x[i]->moles; + total_h_x += s_x[i]->h * s_x[i]->moles; + total_o_x += s_x[i]->o * s_x[i]->moles; + } +/* + * Sum valence states, put in master->total + */ + for (i=0; i < count_master; i++) { + master[i]->total=0.0; + master[i]->total_primary = 0.0; + } + for (i=0; i < count_species_list; i++) { + if (species_list[i].master_s->secondary != NULL) { + master_ptr = species_list[i].master_s->secondary; + } else { + master_ptr = species_list[i].master_s->primary; + } + master_ptr->total += species_list[i].s->moles * species_list[i].coef; + } +/* + * Calculate mass-balance sums + */ + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == MB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || + x[i]->type == SURFACE || + ( x[i]->type == CB && x[i] != ph_unknown && x[i] != pe_unknown ) ) { + x[i]->sum = 0.0; + for (j = 0; x[i]->master[j] != NULL; j++) { + x[i]->sum += x[i]->master[j]->total; + } + } else if (x[i]->type == ALK) { + x[i]->sum = total_co2; + } + } +/* + * Calculate total element concentrations + */ + for (i = 0; i < count_master; i++) { + master[i]->elt->primary->total_primary += + master[i]->total; + } + /* + * Calculate isotope ratios + */ + calculate_values(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Use extra iterative loop to converge on g_factors + */ + int i, g_iterations, debug_diffuse_layer_save, debug_model_save; + +/* + * Allocate space for g factors for diffuse layer in surface complexation + */ + debug_diffuse_layer_save = debug_diffuse_layer; + debug_model_save = debug_model; + if (last_model.force_prep == TRUE) { + same_model = FALSE; + } else { + same_model = check_same_model(); + } + if (diffuse_layer_x == TRUE && same_model == FALSE) { + for (i=0; i < count_s; i++) { + s[i]->diff_layer = (struct species_diff_layer *) free_check_null(s[i]->diff_layer); + s[i]->diff_layer = (struct species_diff_layer *) PHRQ_malloc((size_t) use.surface_ptr->count_charge * sizeof (struct species_diff_layer)); + if (s[i]->diff_layer == NULL) malloc_error(); + } + } + prep(); + k_temp(tc_x); + if (use.surface_ptr->donnan == TRUE) { + initial_surface_water(); + calc_init_donnan(); + } else { + calc_init_g(); + } + if (state >= REACTION && use.surface_ptr->new_def == FALSE) { + set(FALSE); + } else { + set(TRUE); + } + if (model() == ERROR) return(ERROR); + g_iterations = 0; + if (use.surface_ptr->donnan == TRUE) { + do { + g_iterations++; + k_temp(tc_x); + gammas(mu_x); + molalities(TRUE); + mb_sums(); + if (model() == ERROR) return(ERROR); + if (use.surface_ptr->related_phases != TRUE && use.surface_ptr->related_rate != TRUE) initial_surface_water(); + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "Surface_model (Donnan approximation): %d g_iterations, %d model iterations\n", + g_iterations, iterations); + } + } while (calc_all_donnan() == FALSE && g_iterations < itmax); + } else { + do { + g_iterations++; + if (g_iterations > itmax - 10) { + debug_model = TRUE; + debug_diffuse_layer = TRUE; + } + k_temp(tc_x); + gammas(mu_x); + molalities(TRUE); + mb_sums(); + if (model() == ERROR) return(ERROR); + if (use.surface_ptr->related_phases != TRUE && use.surface_ptr->related_rate != TRUE) initial_surface_water(); + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "Surface_model (full integration): %d g_iterations, %d iterations\n", + g_iterations, iterations); + } + } while (calc_all_g() == FALSE && g_iterations < itmax); + } + if (g_iterations >= itmax) { + error_msg("Did not converge on g (diffuse layer excess)", STOP); + } +/* + print_all(); + */ + debug_diffuse_layer = debug_diffuse_layer_save; + debug_model = debug_model_save; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int free_model_allocs(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * free space allocated in model + */ + int i; + if (x != NULL) { + for (i = 0; i < max_unknowns; i++) { + unknown_free(x[i]); + } + } + x = (struct unknown **) free_check_null(x); + max_unknowns = 0; + array = (LDBLE *) free_check_null(array); + delta = (LDBLE *) free_check_null(delta); + residual = (LDBLE *) free_check_null(residual); + s_x = (struct species **) free_check_null(s_x); + sum_mb1 = (struct list1*) free_check_null(sum_mb1); + sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); + sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); + sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); + sum_delta = (struct list2 *) free_check_null(sum_delta); + charge_group = (struct charge_group *) free_check_null(charge_group); + return(OK); +} +#ifdef SLNQ +/* ---------------------------------------------------------------------- */ +int add_trivial_eqns(int rows, int cols, LDBLE *matrix) +/* ---------------------------------------------------------------------- */ +{ + int r, i, j; + r = rows; + if (rows == cols) return(OK); + if (rows > cols) return(ERROR); + for (i = 0; i < cols; i++) { + for (j = 0; j < rows; j++) { + if (matrix[j*(cols+1) + i] != 0.0) break; + } + if (j < rows) continue; + for (j = 0; j < cols+1; j++) matrix[r*(cols+1) + j] = 0.0; + matrix[r*(cols+1) + i] = 1.0; + r++; + } + if (r == cols) return(OK); + return(ERROR); +} +#endif +#define ZERO_TOL 1.0e-30 +/* ---------------------------------------------------------------------- */ +LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE x0, y0, x1, y1, xb, miny; + +/* + * Bracket answer + */ + x0 = 0.0; + x1 = 0.0; + y0 = s_s_f( x0, a0, a1, kc, kb, xcaq, xbaq); + miny = fabs(y0); + for (i = 1; i <= 10; i++) { + x1 = (LDBLE) i / 10; + y1 = s_s_f( x1, a0, a1, kc, kb, xcaq, xbaq); + if (fabs(y1) < miny) { + miny = fabs(y1); + } + if (y0*y1 < 0) { + break; + } else { + x0 = x1; + y0 = y1; + } + } +/* + * Interval halve + */ + if (i > 10) { + xb = 0.0; + } else { + xb = s_s_halve(a0, a1, x0, x1, kc, kb, xcaq, xbaq); + } + return(xb); +} +/* ---------------------------------------------------------------------- */ +LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE x, y0, dx, y; + + y0 = s_s_f( x0, a0, a1, kc, kb, xcaq, xbaq); + dx = (x1 - x0); +/* + * Loop for interval halving + */ + for (i = 0; i < 100; i++) { + dx *= 0.5; + x = x0 + dx; + y = s_s_f( x, a0, a1, kc, kb, xcaq, xbaq); + if (dx < 1e-8 || y == 0) { + break; + } +#ifdef SKIP + if (y0*y < 0) { + x1 = x; + } else { + x0 = x; + y0 = y; + } +#endif + if (y0*y >= 0) { + x0 = x; + y0 = y; + } + } + return(x0 + dx); +} +/* ---------------------------------------------------------------------- */ +LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ +/* + * Need root of this function to determine xb + */ + LDBLE lb, lc, f, xc, r; + xc = 1 - xb; + if (xb == 0) xb = 1e-20; + if (xc == 0) xc = 1e-20; + lc = exp((a0-a1*(-4*xb + 3))*xb*xb); + lb = exp((a0+a1*(4*xb - 3))*xc*xc); + r = lc*kc/(lb*kb); + f = xcaq*(xb/r + xc) + xbaq*(xb + r*xc) - 1; + return(f); +} + + + diff --git a/nvector.cpp b/nvector.cpp new file mode 100644 index 00000000..331479d8 --- /dev/null +++ b/nvector.cpp @@ -0,0 +1,193 @@ +/******************************************************************* + * * + * File : nvector.c * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic NVECTOR * + * package. It contains the implementation of the N_Vector * + * kernels listed in nvector.h. * + * * + *******************************************************************/ + +#include "nvector.h" /* generic M_Env and N_Vector */ +#include "output.h" +static char const svnid[] = "$Id: nvector.c 78 2005-02-01 22:47:12Z dlpark $"; + +N_Vector N_VNew(integertype n, M_Env machEnv) +{ + N_Vector v_new; + v_new = machEnv->ops->nvnew(n, machEnv); + return(v_new); +} + +N_Vector_S N_VNew_S(integertype ns, integertype n, M_Env machEnv) +{ + N_Vector_S vs_new; + vs_new = machEnv->ops->nvnewS(ns, n, machEnv); + return(vs_new); +} + +void N_VFree(N_Vector v) +{ + v->menv->ops->nvfree(v); +} + +void N_VFree_S(integertype ns, N_Vector_S vs) +{ + (*vs)->menv->ops->nvfreeS(ns, vs); +} + +N_Vector N_VMake(integertype n, realtype *v_data, M_Env machEnv) +{ + N_Vector v_new; + v_new = machEnv->ops->nvmake(n, v_data, machEnv); + return(v_new); +} + +void N_VDispose(N_Vector v) +{ + v->menv->ops->nvdispose(v); +} + +realtype *N_VGetData(N_Vector v) +{ + realtype *data; + data = v->menv->ops->nvgetdata(v); + return(data); +} + +void N_VSetData(realtype *v_data, N_Vector v) +{ + v->menv->ops->nvsetdata(v_data, v); +} + +void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) +{ + z->menv->ops->nvlinearsum(a, x, b, y, z); +} + +void N_VConst(realtype c, N_Vector z) +{ + z->menv->ops->nvconst(c, z); +} + +void N_VProd(N_Vector x, N_Vector y, N_Vector z) +{ + z->menv->ops->nvprod(x, y, z); +} + +void N_VDiv(N_Vector x, N_Vector y, N_Vector z) +{ + z->menv->ops->nvdiv(x, y, z); +} + +void N_VScale(realtype c, N_Vector x, N_Vector z) +{ + z->menv->ops->nvscale(c, x, z); +} + +void N_VAbs(N_Vector x, N_Vector z) +{ + z->menv->ops->nvabs(x, z); +} + +void N_VInv(N_Vector x, N_Vector z) +{ + z->menv->ops->nvinv(x, z); +} + +void N_VAddConst(N_Vector x, realtype b, N_Vector z) +{ + z->menv->ops->nvaddconst(x, b, z); +} + +realtype N_VDotProd(N_Vector x, N_Vector y) +{ + realtype prod; + prod = y->menv->ops->nvdotprod(x, y); + return(prod); +} + +realtype N_VMaxNorm(N_Vector x) +{ + realtype norm; + norm = x->menv->ops->nvmaxnorm(x); + return(norm); +} + +realtype N_VWrmsNorm(N_Vector x, N_Vector w) +{ + realtype norm; + norm = x->menv->ops->nvwrmsnorm(x, w); + return(norm); +} + +realtype N_VMin(N_Vector x) +{ + realtype minval; + minval = x->menv->ops->nvmin(x); + return(minval); +} + +realtype N_VWL2Norm(N_Vector x, N_Vector w) +{ + realtype norm; + norm = x->menv->ops->nvwl2norm(x, w); + return(norm); +} + +realtype N_VL1Norm(N_Vector x) +{ + realtype norm; + norm = x->menv->ops->nvl1norm(x); + return(norm); +} + +void N_VOneMask(N_Vector x) +{ + x->menv->ops->nvonemask(x); +} + +void N_VCompare(realtype c, N_Vector x, N_Vector z) +{ + z->menv->ops->nvcompare(c, x, z); +} + +booleantype N_VInvTest(N_Vector x, N_Vector z) +{ + booleantype flag; + flag = z->menv->ops->nvinvtest(x, z); + return(flag); +} + +booleantype N_VConstrProdPos(N_Vector c, N_Vector x) +{ + booleantype flag; + flag = x->menv->ops->nvconstrprodpos(c, x); + return(flag); +} + +booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m) +{ + booleantype flag; + flag = x->menv->ops->nvconstrmask(c, x, m); + return(flag); +} + +realtype N_VMinQuotient(N_Vector num, N_Vector denom) +{ + realtype quotient; + quotient = num->menv->ops->nvminquotient(num, denom); + return(quotient); +} + +void N_VPrint(N_Vector x) +{ + x->menv->ops->nvprint(x); +} diff --git a/nvector.h b/nvector.h new file mode 100644 index 00000000..9be6345d --- /dev/null +++ b/nvector.h @@ -0,0 +1,441 @@ +/******************************************************************* + * * + * File : nvector.h * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic NVECTOR package. * + * It defines the N_Vector and M_Env structures: * + * M_Env has an implementation-dependent 'content' field * + * which contains the data needed to generate a new * + * nvector in that implementation and an 'ops' filed * + * which is a structure listing operations acting on * + * such nvectors. * + * N_Vector has an implementation-dependent 'content' field * + * which contains the description and actual data of * + * the nvector and a 'menv' field which points to the * + * M_Env structure used in creating the nvector. * + * * + * Part I of this file contains type declarations for the * + * the following structures: _generic_M_Env, _generic_N_Vector, * + * and _generic_N_Vector_Ops, as well as references to pointers * + * to such structures (M_Env and N_Vector). * + * * + * Part II of this file contains the prototypes for the vector * + * kernels which operate on N_Vector. * + * * + * A particular implementation of an NVECTOR package must then * + * specify the 'content' fields of M_Env and N_Vector, define * + * the propotypes for kernel operations on those N_Vectors * + * (NOTE: kernel routine names must be unique to that * + * implementation), and finally provide an initialization * + * routine (which generates an M_Env with that particular * + * 'content' field and links the defined vector kernel routines * + * into the 'ops' field). * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidnvector[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef included_nvector_h +#define included_nvector_h + +#include "sundialstypes.h" /* definition of types */ + +/**************************************************************** + * Generic definitions of machine environment and N_Vector * + ****************************************************************/ + +/* Forward reference for pointer to N_Vector_Ops object */ +typedef struct _generic_N_Vector_Ops *N_Vector_Ops; + +/* Forward reference for pointer to M_Env object */ +typedef struct _generic_M_Env *M_Env; + +/* Forward reference for pointer to N_Vector object */ +typedef struct _generic_N_Vector *N_Vector; + +/* Define array of N_Vectors */ +typedef N_Vector *N_Vector_S; + +/* Structure containing function pointers to vector operations */ +struct _generic_N_Vector_Ops { + N_Vector (*nvnew)(integertype, M_Env); + N_Vector_S (*nvnewS)(integertype, integertype, M_Env); + void (*nvfree)(N_Vector); + void (*nvfreeS)(integertype, N_Vector_S); + N_Vector (*nvmake)(integertype, realtype *, M_Env); + void (*nvdispose)(N_Vector); + realtype* (*nvgetdata)(N_Vector); + void (*nvsetdata)(realtype *, N_Vector); + void (*nvlinearsum)(realtype, N_Vector, realtype, N_Vector, N_Vector); + void (*nvconst)(realtype, N_Vector); + void (*nvprod)(N_Vector, N_Vector, N_Vector); + void (*nvdiv)(N_Vector, N_Vector, N_Vector); + void (*nvscale)(realtype, N_Vector, N_Vector); + void (*nvabs)(N_Vector, N_Vector); + void (*nvinv)(N_Vector, N_Vector); + void (*nvaddconst)(N_Vector, realtype, N_Vector); + realtype (*nvdotprod)(N_Vector, N_Vector); + realtype (*nvmaxnorm)(N_Vector); + realtype (*nvwrmsnorm)(N_Vector, N_Vector); + realtype (*nvmin)(N_Vector); + realtype (*nvwl2norm)(N_Vector, N_Vector); + realtype (*nvl1norm)(N_Vector); + void (*nvonemask)(N_Vector); + void (*nvcompare)(realtype, N_Vector, N_Vector); + booleantype (*nvinvtest)(N_Vector, N_Vector); + booleantype (*nvconstrprodpos)(N_Vector, N_Vector); + booleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); + realtype (*nvminquotient)(N_Vector, N_Vector); + void (*nvprint)(N_Vector); +}; + +/* A machine environment is a structure with an implementation + dependent 'content' representation (used to generate a new vector + in that implementation), a set of operations defined in the above + structure, and an ID tag */ +struct _generic_M_Env { + void *content; + struct _generic_N_Vector_Ops *ops; + char tag[8]; +}; + +/* A vector is a structure with an implementation dependent content + representation and a pointer to the machine environment + corresponding to that implementation */ +struct _generic_N_Vector { + void *content; + struct _generic_M_Env *menv; +}; + +/**************************************************************** + * Functions exported by nvector * + ****************************************************************/ + +/*--------------------------------------------------------------* + * Function : N_VNew * + * Usage : v = N_VNew(n, machEnv); * + *--------------------------------------------------------------* + * Returns a new N_Vector of length n. The parameter machEnv * + * is a pointer to machine environment-specific information. * + * If there is not enough memory for a new N_Vector, then * + * N_VNew returns NULL. * + *--------------------------------------------------------------*/ + +N_Vector N_VNew(integertype n, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VNew_S * + * Usage : v = N_VNew_S(ns, n, machEnv); * + *--------------------------------------------------------------* + * Returns an array of ns new N_Vectors of length n. The * + * parameter machEnv is a pointer to machine environment * + * specific information. * + * If there is not enough memory for a new array of N_Vectors * + * or for one of the components, then N_VNew_S returns NULL. * + *--------------------------------------------------------------*/ + +N_Vector_S N_VNew_S(integertype ns, integertype n, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VFree * + * Usage : N_VFree(v); * + *--------------------------------------------------------------* + * Frees the N_Vector v. It is illegal to use v after the call * + * N_VFree(v). * + *--------------------------------------------------------------*/ + +void N_VFree(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VFree_S * + * Usage : N_VFree_S(ns, vs); * + *--------------------------------------------------------------* + * Frees the array of ns N_Vectors vs. * + * It is illegal to use vs after the call N_VFree_S(Ns,vs). * + *--------------------------------------------------------------*/ + +void N_VFree_S(integertype ns, N_Vector_S vs); + +/*--------------------------------------------------------------* + * Function : N_VMake * + * Usage : v = N_VMake(n, v_data, machEnv); * + *--------------------------------------------------------------* + * Creates an N_Vector with component array data allocated by * + * the user. * + *--------------------------------------------------------------*/ + +N_Vector N_VMake(integertype n, realtype *v_data, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VDispose * + * Usage : N_VDispose(v); * + *--------------------------------------------------------------* + * Destroys an N_Vector with component array data allocated by * + * the user. * + *--------------------------------------------------------------*/ + +void N_VDispose(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VGetData * + * Usage : v_data = N_VGetData(v); * + *--------------------------------------------------------------* + * Extracts the data component array from the N_Vector v. * + * Note: this routine is used in the solver-specific interfaces * + * to the dense and banded linear solvers, as well as the * + * interfaces to the banded preconditioners provided with * + * SUNDIALS. It needs not be implemented by a user * + * defined NVECTOR module, if these linear solvers are not* + * used. * + *--------------------------------------------------------------*/ + +realtype *N_VGetData(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VSetData * + * Usage : N_VSetData(v_data, v); * + *--------------------------------------------------------------* + * Attaches the data component array v_data to the N_Vector v. * + * Note: this routine is used in the solver-specific interfaces * + * to the dense and banded linear solvers, as well as the * + * interfaces to the banded preconditioners provided with * + * SUNDIALS. It needs not be implemented by a user * + * defined NVECTOR module, if these linear solvers are not* + * used. * + *--------------------------------------------------------------*/ + +void N_VSetData(realtype *v_data, N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VLinearSum * + * Operation : z = a x + b y * + *--------------------------------------------------------------*/ + +void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, + N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VConst * + * Operation : z[i] = c for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + +void N_VConst(realtype c, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VProd * + * Operation : z[i] = x[i] * y[i] for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + +void N_VProd(N_Vector x, N_Vector y, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VDiv * + * Operation : z[i] = x[i] / y[i] for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + +void N_VDiv(N_Vector x, N_Vector y, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VScale * + * Operation : z = c x * + *--------------------------------------------------------------*/ + +void N_VScale(realtype c, N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VAbs * + * Operation : z[i] = |x[i]|, for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + +void N_VAbs(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VInv * + * Operation : z[i] = 1.0 / x[i] for i = 0, 1, ..., N-1 * + *--------------------------------------------------------------* + * This routine does not check for division by 0. It should be * + * called only with an N_Vector x which is guaranteed to have * + * all non-zero components. * + *--------------------------------------------------------------*/ + +void N_VInv(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VAddConst * + * Operation : z[i] = x[i] + b for i = 0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + +void N_VAddConst(N_Vector x, realtype b, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VDotProd * + * Usage : dotprod = N_VDotProd(x, y); * + *--------------------------------------------------------------* + * Returns the value of the ordinary dot product of x and y: * + * -> sum (i=0 to N-1) {x[i] * y[i]} * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VDotProd(N_Vector x, N_Vector y); + +/*--------------------------------------------------------------* + * Function : N_VMaxNorm * + * Usage : maxnorm = N_VMaxNorm(x); * + *--------------------------------------------------------------* + * Returns the maximum norm of x: * + * -> max (i=0 to N-1) |x[i]| * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VMaxNorm(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VWrmsNorm * + * Usage : wrmsnorm = N_VWrmsNorm(x, w); * + *--------------------------------------------------------------* + * Returns the weighted root mean square norm of x with * + * weight vector w: * + * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) / N] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VWrmsNorm(N_Vector x, N_Vector w); + +/*--------------------------------------------------------------* + * Function : N_VMin * + * Usage : min = N_VMin(x); * + *--------------------------------------------------------------* + * Returns the smallest element of x: * + * -> min (i=0 to N-1) x[i] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VMin(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VWL2Norm * + * Usage : wl2norm = N_VWL2Norm(x, w); * + *--------------------------------------------------------------* + * Returns the weighted Euclidean L2 norm of x with * + * weight vector w: * + * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) ] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VWL2Norm(N_Vector x, N_Vector w); + +/*--------------------------------------------------------------* + * Function : N_VL1Norm * + * Usage : l1norm = N_VL1Norm(x); * + *--------------------------------------------------------------* + * Returns the L1 norm of x: * + * -> sum (i=0 to N-1) {ABS(x[i])} * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + +realtype N_VL1Norm(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VOneMask * + * Operation : x[i] = 1.0 if |x[i]| != 0. i = 0, 1, ..., N-1 * + * 0.0 otherwise * + *--------------------------------------------------------------*/ + +void N_VOneMask(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VCompare * + * Operation : z[i] = 1.0 if |x[i]| >= c i = 0, 1, ..., N-1 * + * 0.0 otherwise * + *--------------------------------------------------------------*/ + +void N_VCompare(realtype c, N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VInvTest * + * Operation : z[i] = 1.0 / x[i] with a test for x[i]==0.0 * + * before inverting x[i]. * + *--------------------------------------------------------------* + * This routine returns TRUE if all components of x are * + * non-zero (successful inversion) and returns FALSE * + * otherwise. * + *--------------------------------------------------------------*/ + +booleantype N_VInvTest(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VConstrProdPos * + * Usage : booltest = N_VConstrProdPos(c,x); * + *--------------------------------------------------------------* + * Returns a boolean equal to * + * FALSE if some c[i] != 0.0 and x[i]*c[i] <= 0.0, or * + * TRUE otherwise. * + * * + * This routine is used for constraint checking. * + *--------------------------------------------------------------*/ + +booleantype N_VConstrProdPos(N_Vector c, N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VConstrMask * + * Operation : m[i] = 1.0 if constraint test fails for x[i] * + * m[i] = 0.0 if constraint test passes for x[i] * + * where the constraint tests are as follows: * + * If c[i] = 2.0, then x[i] must be > 0.0. * + * If c[i] = 1.0, then x[i] must be >= 0.0. * + * If c[i] = -1.0, then x[i] must be <= 0.0. * + * If c[i] = -2.0, then x[i] must be < 0.0. * + *--------------------------------------------------------------* + * This routine returns a boolean FALSE if any element failed * + * the constraint test, TRUE if all passed. It also sets a * + * mask vector m, with elements equal to 1.0 where the * + * corresponding constraint test failed, and equal to 0.0 * + * where the constraint test passed. * + * This routine is specialized in that it is used only for * + * constraint checking. * + *--------------------------------------------------------------*/ + +booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); + +/*--------------------------------------------------------------* + * Function : N_VMinQuotient * + * Operation : minq = min ( num[i]/denom[i]) over all i such * + * that denom[i] != 0. * + *--------------------------------------------------------------* + * This routine returns the minimum of the quotients obtained * + * by term-wise dividing num[i] by denom[i]. A zero element * + * in denom will be skipped. If no such quotients are found, * + * then the large value 1.e99 is returned. * + *--------------------------------------------------------------*/ + +realtype N_VMinQuotient(N_Vector num, N_Vector denom); + +/*--------------------------------------------------------------* + * Function : N_VPrint * + * Usage : N_VPrint(x); * + *--------------------------------------------------------------* + * Prints the N_Vector x to stdout. * + * This routine is provided as an aid in debugging code which * + * uses this vector package. * + *--------------------------------------------------------------*/ + +void N_VPrint(N_Vector x); + + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/nvector_serial.cpp b/nvector_serial.cpp new file mode 100644 index 00000000..cef66fd6 --- /dev/null +++ b/nvector_serial.cpp @@ -0,0 +1,869 @@ +/******************************************************************* + * * + * File : nvector_serial.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * + * Radu Serban, and Allan G. Taylor, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a serial implementation * + * of the NVECTOR package. It contains the implementation of * + * the serial machine environment intialization and free * + * routines (and of the Fortran callable interfaces to them) * + * and of the N_Vector kernels listed in nvector_serial.h. * + * * + *******************************************************************/ + +#include +#include +#include +#include "nvector_serial.h" +#include "sundialstypes.h" +#include "sundialsmath.h" +#include "output.h" +#include "phqalloc.h" +/* WARNING don't include any headers below here */ +#define malloc PHRQ_malloc +static char const svnid[] = "$Id: nvector_serial.c 663 2005-11-16 00:46:04Z dlpark $"; + +#define ZERO RCONST(0.0) +#define HALF RCONST(0.5) +#define ONE RCONST(1.0) +#define ONEPT5 RCONST(1.5) + + +/* Private Helper Prototypes */ +/* z=x */ +static void VCopy_Serial(N_Vector x, N_Vector z); +/* z=x+y */ +static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z); +/* z=x-y */ +static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z); +/* z=-x */ +static void VNeg_Serial(N_Vector x, N_Vector z); +/* z=c(x+y) */ +static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); +/* z=c(x-y) */ +static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); +/* z=ax+y */ +static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); +/* z=ax-y */ +static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); +/* y <- ax+y */ +static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y); +/* x <- ax */ +static void VScaleBy_Serial(realtype a, N_Vector x); + +/********************* Exported Functions ************************/ + +/* Serial implementation of the machine environment + initialization routine */ + +M_Env M_EnvInit_Serial(integertype vec_length) +{ + M_Env me; + + if (svnid == NULL) fprintf(stderr," "); + /* Create machine environment structure */ + me = (M_Env) malloc(sizeof *me); + if (me == NULL) return(NULL); + + /* Create serial content of machine environment structure */ + me->content = (M_EnvSerialContent) malloc(sizeof(struct _M_EnvSerialContent)); + if (me->content == NULL) { + free(me); + return(NULL); + } + + /* Load serial content of machine environment structure */ + ME_CONTENT_S(me)->length = vec_length; + + /* Attach vector operations */ + me->ops = (N_Vector_Ops) malloc(sizeof(struct _generic_N_Vector_Ops)); + if (me->ops == NULL) { + free(me->content); + free(me); + return(NULL); + } + + me->ops->nvnew = N_VNew_Serial; + me->ops->nvnewS = N_VNew_S_Serial; + me->ops->nvfree = N_VFree_Serial; + me->ops->nvfreeS = N_VFree_S_Serial; + me->ops->nvmake = N_VMake_Serial; + me->ops->nvdispose = N_VDispose_Serial; + me->ops->nvgetdata = N_VGetData_Serial; + me->ops->nvsetdata = N_VSetData_Serial; + me->ops->nvlinearsum = N_VLinearSum_Serial; + me->ops->nvconst = N_VConst_Serial; + me->ops->nvprod = N_VProd_Serial; + me->ops->nvdiv = N_VDiv_Serial; + me->ops->nvscale = N_VScale_Serial; + me->ops->nvabs = N_VAbs_Serial; + me->ops->nvinv = N_VInv_Serial; + me->ops->nvaddconst = N_VAddConst_Serial; + me->ops->nvdotprod = N_VDotProd_Serial; + me->ops->nvmaxnorm = N_VMaxNorm_Serial; + me->ops->nvwrmsnorm = N_VWrmsNorm_Serial; + me->ops->nvmin = N_VMin_Serial; + me->ops->nvwl2norm = N_VWL2Norm_Serial; + me->ops->nvl1norm = N_VL1Norm_Serial; + me->ops->nvonemask = N_VOneMask_Serial; + me->ops->nvcompare = N_VCompare_Serial; + me->ops->nvinvtest = N_VInvTest_Serial; + me->ops->nvconstrprodpos = N_VConstrProdPos_Serial; + me->ops->nvconstrmask = N_VConstrMask_Serial; + me->ops->nvminquotient = N_VMinQuotient_Serial; + me->ops->nvprint = N_VPrint_Serial; + + /* Attach ID tag */ + strcpy(me->tag, ID_TAG_S); + + return(me); + +} + +/* Serial implementation of the machine environment + free routine */ + +void M_EnvFree_Serial(M_Env machEnv) +{ + if (machEnv == NULL) return; + + free(machEnv->content); + free(machEnv->ops); + free(machEnv); +} + +/***************************************************************************/ + +/* BEGIN implementation of vector operations */ + +N_Vector N_VNew_Serial(integertype n, M_Env machEnv) +{ + N_Vector v; + integertype length; + + if (n <= 0) return(NULL); + + if (machEnv == NULL) return(NULL); + + v = (N_Vector) malloc(sizeof *v); + if (v == NULL) return(NULL); + + v->content = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); + if (v->content == NULL) { + free(v); + return(NULL); + } + + length = ME_CONTENT_S(machEnv)->length; + + NV_CONTENT_S(v)->data = (realtype *) malloc(length * sizeof(realtype)); + if(NV_CONTENT_S(v)->data == NULL) { + free(v->content); + free(v); + return(NULL); + } + + NV_CONTENT_S(v)->length = length; + + v->menv = machEnv; + + return(v); +} + + +N_Vector_S N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv) +{ + N_Vector_S vs; + integertype is, j; + + + if (ns <= 0 || n <= 0) return(NULL); + + if (machEnv == NULL) return(NULL); + + vs = (N_Vector_S) malloc(ns * sizeof(N_Vector *)); + if (vs == NULL) return(NULL); + + for (is=0; iscontent = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); + if (v->content == NULL) { + free(v); + return(NULL); + } + + length = ME_CONTENT_S(machEnv)->length; + + NV_CONTENT_S(v)->data = v_data; + + NV_CONTENT_S(v)->length = length; + + v->menv = machEnv; + + return(v); +} + +void N_VDispose_Serial(N_Vector v) +{ + free(NV_CONTENT_S(v)); + free(v); +} + +realtype *N_VGetData_Serial(N_Vector v) +{ + realtype *v_data; + v_data = NV_CONTENT_S(v)->data; + return(v_data); +} + +void N_VSetData_Serial(realtype *v_data, N_Vector v) +{ + NV_CONTENT_S(v)->data = v_data; +} + +void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype c, *xd, *yd, *zd; + N_Vector v1, v2; + booleantype test; + + if ((b == ONE) && (z == y)) { /* BLAS usage: axpy y <- ax+y */ + Vaxpy_Serial(a,x,y); + return; + } + + if ((a == ONE) && (z == x)) { /* BLAS usage: axpy x <- by+x */ + Vaxpy_Serial(b,y,x); + return; + } + + /* Case: a == b == 1.0 */ + + if ((a == ONE) && (b == ONE)) { + VSum_Serial(x, y, z); + return; + } + + /* Cases: (1) a == 1.0, b = -1.0, (2) a == -1.0, b == 1.0 */ + + /*if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) {*/ + test = ((a == ONE) && (b == -ONE)); + if (test || ((a == -ONE) && (b == ONE))) { + v1 = test ? y : x; + v2 = test ? x : y; + VDiff_Serial(v2, v1, z); + return; + } + + /* Cases: (1) a == 1.0, b == other or 0.0, (2) a == other or 0.0, b == 1.0 */ + /* if a or b is 0.0, then user should have called N_VScale */ + + /*if ((test = (a == ONE)) || (b == ONE)) {*/ + test = (a == ONE); + if (test || (b == ONE)) { + c = test ? b : a; + v1 = test ? y : x; + v2 = test ? x : y; + VLin1_Serial(c, v1, v2, z); + return; + } + + /* Cases: (1) a == -1.0, b != 1.0, (2) a != 1.0, b == -1.0 */ + + /*if ((test = (a == -ONE)) || (b == -ONE)) {*/ + test = (a == -ONE); + if (test || (b == -ONE)) { + c = test ? b : a; + v1 = test ? y : x; + v2 = test ? x : y; + VLin2_Serial(c, v1, v2, z); + return; + } + + /* Case: a == b */ + /* catches case both a and b are 0.0 - user should have called N_VConst */ + + if (a == b) { + VScaleSum_Serial(a, x, y, z); + return; + } + + /* Case: a == -b */ + + if (a == -b) { + VScaleDiff_Serial(a, x, y, z); + return; + } + + /* Do all cases not handled above: + (1) a == other, b == 0.0 - user should have called N_VScale + (2) a == 0.0, b == other - user should have called N_VScale + (3) a,b == other, a !=b, a != -b */ + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = a * (*xd++) + b * (*yd++); +} + + +void N_VConst_Serial(realtype c, N_Vector z) +{ + integertype i, N; + realtype *zd; + + N = NV_LENGTH_S(z); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = c; +} + + +void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = (*xd++) * (*yd++); +} + + +void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = (*xd++) / (*yd++); +} + + +void N_VScale_Serial(realtype c, N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + if (z == x) { /* BLAS usage: scale x <- cx */ + VScaleBy_Serial(c, x); + return; + } + + if (c == ONE) { + VCopy_Serial(x, z); + } else if (c == -ONE) { + VNeg_Serial(x, z); + } else { + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + for (i=0; i < N; i++) + *zd++ = c * (*xd++); + } +} + + +void N_VAbs_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++, xd++, zd++) + *zd = ABS(*xd); +} + + +void N_VInv_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = ONE / (*xd++); +} + + +void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) + *zd++ = (*xd++) + b; +} + + +realtype N_VDotProd_Serial(N_Vector x, N_Vector y) +{ + integertype i, N; + realtype sum = ZERO, *xd, *yd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + + for (i=0; i < N; i++) + sum += (*xd++) * (*yd++); + + return(sum); +} + + +realtype N_VMaxNorm_Serial(N_Vector x) +{ + integertype i, N; + realtype max = ZERO, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i=0; i < N; i++, xd++) { + if (ABS(*xd) > max) max = ABS(*xd); + } + + return(max); +} + + +realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w) +{ + integertype i, N; + realtype sum = ZERO, prodi, *xd, *wd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + wd = NV_DATA_S(w); + + for (i=0; i < N; i++) { + prodi = (*xd++) * (*wd++); + sum += prodi * prodi; + } + + return(RSqrt(sum / N)); +} + + +realtype N_VMin_Serial(N_Vector x) +{ + integertype i, N; + realtype min, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + min = xd[0]; + + xd++; + for (i=1; i < N; i++, xd++) { + if ((*xd) < min) min = *xd; + } + + return(min); +} + + +realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w) +{ + integertype i, N; + realtype sum = ZERO, prodi, *xd, *wd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + wd = NV_DATA_S(w); + + for (i=0; i < N; i++) { + prodi = (*xd++) * (*wd++); + sum += prodi * prodi; + } + + return(RSqrt(sum)); +} + + +realtype N_VL1Norm_Serial(N_Vector x) +{ + integertype i, N; + realtype sum = ZERO, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i=0; i= c) ? ONE : ZERO; + } +} + + +booleantype N_VInvTest_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i=0; i < N; i++) { + if (*xd == ZERO) return(FALSE); + *zd++ = ONE / (*xd++); + } + + return(TRUE); +} + + +booleantype N_VConstrProdPos_Serial(N_Vector c, N_Vector x) +{ + integertype i, N; + realtype *xd, *cd; + booleantype test; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + cd = NV_DATA_S(c); + + test = TRUE; + + for (i=0; i < N; i++, xd++,cd++) { + if (*cd != ZERO) { + if ((*xd)*(*cd) <= ZERO) { + test = FALSE; + break; + } + } + } + return(test); +} + + +booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) +{ + integertype i, N; + booleantype test; + realtype *cd, *xd, *md; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + cd = NV_DATA_S(c); + md = NV_DATA_S(m); + + test = TRUE; + + for (i=0; i ONEPT5 || (*cd) < -ONEPT5) { + if ( (*xd)*(*cd) <= ZERO) {test = FALSE; *md = ONE; } + continue; + } + if ( (*cd) > HALF || (*cd) < -HALF) { + if ( (*xd)*(*cd) < ZERO ) {test = FALSE; *md = ONE; } + } + } + return(test); +} + + +realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom) +{ + booleantype notEvenOnce; + integertype i, N; + realtype *nd, *dd, min; + + N = NV_LENGTH_S(num); + nd = NV_DATA_S(num); + dd = NV_DATA_S(denom); + min = 0; + + notEvenOnce = TRUE; + + for (i=0; i since these macros expand to calls to * + * malloc and free. * + * * + * When looping over the components of an N_Vector v, it is * + * more efficient to first obtain the component array via * + * v_data=NV_DATA_S(v) and then access v_data[i] within the * + * loop than it is to use NV_Ith_S(v,i) within the loop. * + * * + * NV_MAKE_S and NV_DISPOSE_S are similar to N_VNew_Serial and * + * N_VFree_Serial, while NVS_MAKE_S and NVS_DISPOSE_S are * + * similar to N_VNew_S_Serial and N_VFree_S_Serial. The * + * difference is one of responsibility for component memory * + * allocation and deallocation. N_VNew_Serial allocates memory * + * for the N_Vector components and N_VFree_Serial frees the * + * component memory allocated by N_VNew_Serial. For NV_MAKE_S * + * and NV_DISPOSE_S, the component memory is allocated and * + * freed by the user of this package. Similar remarks hold for * + * NVS_MAKE_S, NVS_DISPOSE_S and N_VNew_S_Serial, * + * N_VFree_S_Serial. * + * * + ****************************************************************/ + +#define NV_MAKE_S(v, v_data, machenv) \ + v = (N_Vector) malloc(sizeof(*v)); \ + v->content = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); \ + v->content->data = v_data; \ + v->content->length = machenv->content->v_len; \ + v->menv = machenv + +#define NV_DISPOSE_S(v) \ + free((N_VectorSerialContent)(v->content)); \ + free(v) + +#define NVS_MAKE_S(vs, vs_data, s_len, machenv) \ + vs = (N_Vector_S) malloc(s_len*sizeof(N_Vector *)); \ + for ((int)is=0; iscontent) ) + +#define NV_CONTENT_S(v) ( (N_VectorSerialContent)(v->content) ) + +#define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) + +#define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) + +#define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) + + +/**************************************************************** + * PART III: * + * Functions exported by nvector_serial * + ****************************************************************/ + +/*--------------------------------------------------------------* + * Routine : M_EnvInit_Serial * + *--------------------------------------------------------------* + * This function sets the content field of the machine * + * environment for the serial implementation to a structure of * + * type _MEnvSerialContent and attaches the vector operations * + * defined for this implementation. * + * * + * If successful, M_EnvInit_Serial returns a pointer of type * + * M_Env. This pointer should in turn be passed in any user * + * calls to N_VNew, or uses of the macros NV_MAKE_S and * + * NVS_MAKE_S. * + * * + *--------------------------------------------------------------* + * * + * vec_length is the length of the vector. * + * * + *--------------------------------------------------------------*/ + +M_Env M_EnvInit_Serial(integertype vec_length); + +/*--------------------------------------------------------------* + * Function M_EnvFree_Serial * + *--------------------------------------------------------------* + * Function to free the block of machine-dependent environment * + * information created by M_EnvInit_Serial. * + * Its only argument is the pointer machenv returned by * + * M_EnvInit_Serial. * + * * + *--------------------------------------------------------------*/ + +void M_EnvFree_Serial(M_Env machenv); + +/*--------------------------------------------------------------* + * Serial implementations of the vector operations * + * * + * For a complete description of each of the following routines * + * see the header file nvector.h * + *--------------------------------------------------------------*/ + +N_Vector N_VNew_Serial(integertype n, M_Env machEnv); +N_Vector_S N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv); +void N_VFree_Serial(N_Vector v); +void N_VFree_S_Serial(integertype ns, N_Vector_S vs); +N_Vector N_VMake_Serial(integertype n, realtype *v_data, M_Env machEnv); +void N_VDispose_Serial(N_Vector v); +realtype *N_VGetData_Serial(N_Vector v); +void N_VSetData_Serial(realtype *v_data, N_Vector v); +void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); +void N_VConst_Serial(realtype c, N_Vector z); +void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); +void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); +void N_VScale_Serial(realtype c, N_Vector x, N_Vector z); +void N_VAbs_Serial(N_Vector x, N_Vector z); +void N_VInv_Serial(N_Vector x, N_Vector z); +void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z); +realtype N_VDotProd_Serial(N_Vector x, N_Vector y); +realtype N_VMaxNorm_Serial(N_Vector x); +realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); +realtype N_VMin_Serial(N_Vector x); +realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); +realtype N_VL1Norm_Serial(N_Vector x); +void N_VOneMask_Serial(N_Vector x); +void N_VCompare_Serial(realtype c, N_Vector x, N_Vector z); +booleantype N_VInvTest_Serial(N_Vector x, N_Vector z); +booleantype N_VConstrProdPos_Serial(N_Vector c, N_Vector x); +booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); +realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); +void N_VPrint_Serial(N_Vector x); + + + +#endif +#ifdef __cplusplus +} +#endif diff --git a/output.cpp b/output.cpp new file mode 100644 index 00000000..51ecd413 --- /dev/null +++ b/output.cpp @@ -0,0 +1,182 @@ +#define EXTERNAL extern +#include +#include "global.h" +#include "output.h" +#include "phrqproto.h" +#include "phqalloc.h" +static char const svnid[] = "$Id: output.c 663 2005-11-16 00:46:04Z dlpark $"; + +#define MAX_CALLBACKS 10 +static struct output_callback output_callbacks[MAX_CALLBACKS]; +static size_t count_output_callback = 0; +static int forward_output_to_log = 0; + +/* ---------------------------------------------------------------------- */ +int add_output_callback(PFN_OUTPUT_CALLBACK pfn, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + if (svnid == NULL) fprintf(stderr," "); + if (pfn) { + if (count_output_callback >= MAX_CALLBACKS - 1) { + sprintf(error_string, "Too many callbacks.\nSee %s\n", __FILE__); + fprintf(stderr, "%s", error_string); + error_msg(error_string, STOP); + return ERROR; + } + output_callbacks[count_output_callback].callback = pfn; + output_callbacks[count_output_callback].cookie = cookie; + ++count_output_callback; + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int output_message(const int type, const char *err_str, const int stop, const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + extern jmp_buf mark; + size_t i; + + for (i = 0; i < count_output_callback; ++i) { + (output_callbacks[i].callback)(ACTION_OUTPUT, type, err_str, stop, output_callbacks[i].cookie, format, args); + } + + if (stop == STOP) { + longjmp(mark, input_error); + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int clean_up_output_callbacks(void) +/* ---------------------------------------------------------------------- */ +{ + count_output_callback = 0; + return OK; +} + +/* ---------------------------------------------------------------------- */ +int error_msg (const char *err_str, const int stop, ...) +/* ---------------------------------------------------------------------- */ +{ + va_list args; + int return_value; + + if (input_error <= 0) input_error = 1; + va_start(args, stop); + return_value = output_message(OUTPUT_ERROR, err_str, stop, "", args); + va_end(args); + return(return_value); +} + +/* ---------------------------------------------------------------------- */ +int warning_msg (const char *err_str, ...) +/* ---------------------------------------------------------------------- */ +{ + va_list args; + int return_value; + + va_start(args, err_str); + return_value = output_message(OUTPUT_WARNING, err_str, CONTINUE, "", args); + count_warnings++; + va_end(args); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int output_msg (const int type, const char* format, ...) +/* ---------------------------------------------------------------------- */ +{ + int return_value; + va_list args; + + va_start(args, format); + return_value = output_message(type, NULL, CONTINUE, format, args); + va_end(args); + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +void set_forward_output_to_log(int value) +/* ---------------------------------------------------------------------- */ +{ + forward_output_to_log = value; +} +/* ---------------------------------------------------------------------- */ +int get_forward_output_to_log(void) +/* ---------------------------------------------------------------------- */ +{ + return forward_output_to_log; +} +/* ---------------------------------------------------------------------- */ +int output_fflush(const int type, ...) +/* ---------------------------------------------------------------------- */ +{ + size_t i; + int check; + va_list args; + + check = OK; + va_start(args, type); + for (i = 0; i < count_output_callback; ++i) { + check = (output_callbacks[i].callback)(ACTION_FLUSH, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); + if (check != OK) break; + } + va_end(args); + if (check != OK) return(ERROR); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int output_rewind(const int type, ...) +/* ---------------------------------------------------------------------- */ +{ + size_t i; + int check; + va_list args; + + check = OK; + va_start(args, type); + for (i = 0; i < count_output_callback; ++i) { + check = (output_callbacks[i].callback)(ACTION_REWIND, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); + if (check != OK) break; + } + va_end(args); + if (check != OK) return(ERROR); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int output_close(const int type, ...) +/* ---------------------------------------------------------------------- */ +{ + size_t i; + int check; + va_list args; + + check = OK; + va_start(args, type); + for (i = 0; i < count_output_callback; ++i) { + check = (output_callbacks[i].callback)(ACTION_CLOSE, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); + if (check != OK) break; + } + va_end(args); + if (check != OK) return(ERROR); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int output_open(const int type, const char *file_name, ...) +/* ---------------------------------------------------------------------- */ +{ + size_t i; + int check; + va_list args; + assert(file_name && strlen(file_name)); + + check = OK; + va_start(args, file_name); + for (i = 0; i < count_output_callback; ++i) { + check = (output_callbacks[i].callback)(ACTION_OPEN, type, file_name, CONTINUE, output_callbacks[i].cookie, NULL, args); + if (check != OK) break; + } + va_end(args); + if (check != OK) return(ERROR); + return(OK); +} diff --git a/output.h b/output.h new file mode 100644 index 00000000..4ad59e67 --- /dev/null +++ b/output.h @@ -0,0 +1,57 @@ +#ifndef _INC_MESSAGE_H +#define _INC_MESSAGE_H + +#include +#ifdef PHREEQC_IDENT +static char const svnidoutput[] = "$Id$"; +#endif + +typedef int (*PFN_OUTPUT_CALLBACK)(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *, va_list args); + +struct output_callback { + PFN_OUTPUT_CALLBACK callback; + void *cookie; +}; + +int add_output_callback(PFN_OUTPUT_CALLBACK pfn, void *cookie); +int clean_up_output_callbacks(void); +int output_msg (const int type, const char* format, ...); +int warning_msg (const char *err_str, ...); +int error_msg (const char *err_str, const int stop, ...); +int phreeqc_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *, va_list args); +void set_forward_output_to_log(int value); +int get_forward_output_to_log(void); + +/* + * Functions for output callbacks + */ +int output_open(const int type, const char *file_name, ...); +int output_fflush(const int type, ...); +int output_rewind(const int type, ...); +int output_close(const int type, ...); + +typedef enum { + OUTPUT_ERROR, + OUTPUT_WARNING, + OUTPUT_MESSAGE, + OUTPUT_PUNCH, + OUTPUT_SCREEN, + OUTPUT_LOG, + OUTPUT_CHECKLINE, + OUTPUT_GUI_ERROR, + OUTPUT_BASIC, + OUTPUT_CVODE, + OUTPUT_DUMP, + OUTPUT_STDERR, + OUTPUT_SEND_MESSAGE +} output_type; + +typedef enum { + ACTION_OPEN, + ACTION_OUTPUT, + ACTION_CLOSE, + ACTION_REWIND, + ACTION_FLUSH +} action_type; + +#endif /* _INC_MESSAGE_H */ diff --git a/p2c.h b/p2c.h new file mode 100644 index 00000000..725328dd --- /dev/null +++ b/p2c.h @@ -0,0 +1,543 @@ +#ifndef P2C_H +#define P2C_H + +#ifdef PHREEQC_IDENT +static char const svnidp2c[] = "$Id$"; +#endif + +/* Header file for code generated by "p2c", the Pascal-to-C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + + +#include + + + +/* If the following heuristic fails, compile -DBSD=0 for non-BSD systems, + or -DBSD=1 for BSD systems. */ + +#ifdef M_XENIX +# define BSD 0 +#endif + +#ifdef vms +# define BSD 0 +# ifndef __STDC__ +# define __STDC__ 1 +# endif +#endif + +#ifdef __TURBOC__ +# define MSDOS 1 +#endif + +#ifdef MSDOS +# define BSD 0 +#endif + +#ifdef FILE /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */ +# ifndef BSD /* (a convenient, but horrible kludge!) */ +# define BSD 1 +# endif +#endif + +#ifdef BSD +# if !BSD +# undef BSD +# endif +#endif + + +#if (defined(__STDC__) && !defined(M_XENIX)) || defined(__TURBOC__) +# include +# include +# define HAS_STDLIB +# if defined(vms) || defined(__TURBOC__) +# define __ID__(a)a +# endif +#else +# ifndef BSD +# ifndef __TURBOC__ +# include +# endif +# endif +# ifdef hpux +# ifdef _INCLUDE__STDC__ +# include +# include +# endif +# endif +# include +# if !defined(MSDOS) || defined(__TURBOC__) +# define __ID__(a)a +# endif +#endif + +#ifdef __ID__ +# define __CAT__(a,b)__ID__(a)b +#else +# define __CAT__(a,b)a##b +#endif + + +#ifdef BSD +# include +# define memcpy(a,b,n) (bcopy(b,a,n),a) +# define memcmp(a,b,n) bcmp(a,b,n) +# define strchr(s,c) index(s,c) +# define strrchr(s,c) rindex(s,c) +#else +# include +#endif + +#include +#include +#include +#include + + +#ifndef NO_LACK +#ifdef vms + +#define LACK_LABS +#define LACK_MEMMOVE +#define LACK_MEMCPY + +#else + +#define LACK_LABS /* Undefine these if your library has these */ +#ifdef SKIP +#define LACK_MEMMOVE +#endif + +#endif +#endif + + +typedef struct __p2c_jmp_buf { + struct __p2c_jmp_buf *next; + jmp_buf jbuf; +} __p2c_jmp_buf; + + +/* Warning: The following will not work if setjmp is used simultaneously. + This also violates the ANSI restriction about using vars after longjmp, + but a typical implementation of longjmp will get it right anyway. */ + +#ifndef FAKE_TRY +# define TRY(x) do { __p2c_jmp_buf __try_jb; \ + __try_jb.next = __top_jb; \ + if (!setjmp((__top_jb = &__try_jb)->jbuf)) { +# define RECOVER(x) __top_jb = __try_jb.next; } else { +#ifdef SKIP +# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ + if (0) { L: __top_jb = __try_jb.next; } +#endif +# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ + { L: __top_jb = __try_jb.next; } +# define ENDTRY(x) } } while (0) +#else +# define TRY(x) if (1) { +# define RECOVER(x) } else do { +# define RECOVER2(x,L) } else do { L: ; +# define ENDTRY(x) } while (0) +#endif + + + +#ifdef M_XENIX /* avoid compiler bug */ +# define INT_MAX (32767) +# define INT_MIN (-32768) +#endif + + +/* The following definitions work only on twos-complement machines */ +#ifndef INT_MAX +# define INT_MAX ((int)(((unsigned int) -1) >> 1)) +# define INT_MIN (~INT_MAX) +#endif + +#ifndef INT_MAX +# define INT_MAX ((int)(((unsigned int) -1) >> 1)) +# define INT_MIN (~INT_MAX) +#endif + +#ifndef LONG_MAX +# define LONG_MAX ((long)(((unsigned long) -1) >> 1)) +# define LONG_MIN (~LONG_MAX) +#endif + +#ifndef SEEK_SET +# define SEEK_SET 0 +# define SEEK_CUR 1 +# define SEEK_END 2 +#endif + +#ifndef EXIT_SUCCESS +# ifdef vms +# define EXIT_SUCCESS 1 +# define EXIT_FAILURE (02000000000L) +# else +# define EXIT_SUCCESS 0 +# define EXIT_FAILURE 1 +# endif +#endif + + +#define SETBITS 32 + +#ifdef SKIP +#if defined(__STDC__) || defined(__TURBOC__) +# if !defined(vms) && !defined(M_LINT) +# define Signed signed +# else +# define Signed +# endif +# define Void void /* Void f() = procedure */ +# ifndef Const +# define Const const +# endif +# ifndef Volatile +# define Volatile volatile +# endif +# ifdef M_LINT +# define P2PP(x) () +# define PV() () +typedef char *Anyptr; +# else +# define P2PP(x) x /* function prototype */ +# define PV() (void) /* null function prototype */ +typedef void *Anyptr; +# endif +#else +# define Signed +# define Void void +# ifndef Const +# define Const +# endif +# ifndef Volatile +# define Volatile +# endif +# define P2PP(x) () +# define PV() () +typedef char *Anyptr; +#endif +#endif + + +#define Signed +#define Void void +#ifndef Const +# define Const +#endif +#ifndef Volatile +# define Volatile +#endif +#define P2PP(x) () +#define PV() () +typedef char *Anyptr; + + +#ifdef __GNUC__ +# define Inline inline +#else +# define Inline +#endif + +#define Register register /* Register variables */ +#define Char char /* Characters (not bytes) */ + +#ifndef Static +# define Static static /* Private global funcs and vars */ +#endif + +#ifndef Local +# define Local static /* Nested functions */ +#endif + +typedef Signed char schar; +/*typedef unsigned char uchar;*/ +typedef unsigned char boolean; + +#ifndef true +# define true 1 +# define false 0 +#endif + +#ifndef TRUE +# define TRUE 1 +# define FALSE 0 +#endif + + +typedef struct { + Anyptr proc, link; +} _PROCEDURE; + +#ifndef _FNSIZE +# define _FNSIZE 120 +#endif + + +/*extern Void PASCAL_MAIN P2PP( (int, Char **) );*/ +extern Void PASCAL_MAIN (int, Char **) ; +/* +extern Char **P_argv; +extern int P_argc; +*/ +extern int P_escapecode; +extern int P_ioresult; +extern __p2c_jmp_buf *__top_jb; + + +#ifdef P2C_H_PROTO /* if you have Ansi C but non-prototyped header files */ +extern Char *strcat P2PP( (Char *, Const Char *) ); +extern Char *strchr P2PP( (Const Char *, int) ); +extern int strcmp P2PP( (Const Char *, Const Char *) ); +extern Char *strcpy P2PP( (Char *, Const Char *) ); +extern size_t strlen P2PP( (Const Char *) ); +extern Char *strncat P2PP( (Char *, Const Char *, size_t) ); +extern int strncmp P2PP( (Const Char *, Const Char *, size_t) ); +extern Char *strncpy P2PP( (Char *, Const Char *, size_t) ); +extern Char *strrchr P2PP( (Const Char *, int) ); + +extern Anyptr memchr P2PP( (Const Anyptr, int, size_t) ); +extern Anyptr memmove P2PP( (Anyptr, Const Anyptr, size_t) ); +extern Anyptr memset P2PP( (Anyptr, int, size_t) ); +#ifndef memcpy +extern Anyptr memcpy P2PP( (Anyptr, Const Anyptr, size_t) ); +extern int memcmp P2PP( (Const Anyptr, Const Anyptr, size_t) ); +#endif + +extern int atoi P2PP( (Const Char *) ); +extern LDBLE atof P2PP( (Const Char *) ); +extern long atol P2PP( (Const Char *) ); +extern LDBLE strtod P2PP( (Const Char *, Char **) ); +extern long strtol P2PP( (Const Char *, Char **, int) ); +#endif /*P2C_H_PROTO*/ + +/* force stdlib for DEC */ +#define HAS_STDLIB +#ifndef HAS_STDLIB +extern Anyptr malloc P2PP( (size_t) ); +extern Void free P2PP( (Anyptr) ); +#endif + +extern int _OutMem PV(); +extern int _CaseCheck PV(); +extern int _NilCheck PV(); +/*extern int _Escape P2PP( (int) );*/ +extern int _Escape(int); +/*extern int _EscIO P2PP( (int) );*/ +extern int _EscIO (int); +extern long ipow P2PP( (long, long) ); +extern Char *strsub P2PP( (Char *, Char *, int, int) ); +extern Char *strltrim P2PP( (Char *) ); +extern Char *strrtrim P2PP( (Char *) ); +extern Char *strrpt P2PP( (Char *, Char *, int) ); +extern Char *strpad P2PP( (Char *, Char *, int, int) ); +extern int strpos2 P2PP( (Char *, Char *, int) ); +extern long memavail PV(); +extern int P_peek P2PP( (FILE *) ); +extern int P_eof P2PP( (FILE *) ); +extern int P_eoln P2PP( (FILE *) ); +extern Void P_readpaoc P2PP( (FILE *, Char *, int) ); +extern Void P_readlnpaoc P2PP( (FILE *, Char *, int) ); +extern long P_maxpos P2PP( (FILE *) ); +extern Char *P_trimname P2PP( (Char *, int) ); +extern long *P_setunion P2PP( (long *, long *, long *) ); +extern long *P_setint P2PP( (long *, long *, long *) ); +extern long *P_setdiff P2PP( (long *, long *, long *) ); +extern long *P_setxor P2PP( (long *, long *, long *) ); +extern int P_inset P2PP( (unsigned, long *) ); +extern int P_setequal P2PP( (long *, long *) ); +extern int P_subset P2PP( (long *, long *) ); +extern long *P_addset P2PP( (long *, unsigned) ); +extern long *P_addsetr P2PP( (long *, unsigned, unsigned) ); +extern long *P_remset P2PP( (long *, unsigned) ); +extern long *P_setcpy P2PP( (long *, long *) ); +extern long *P_expset P2PP( (long *, long) ); +extern long P_packset P2PP( (long *) ); +extern int P_getcmdline P2PP( (int, int, Char *) ); +extern Void TimeStamp P2PP( (int *, int *, int *, + int *, int *, int *) ); +extern Void P_sun_argv P2PP( (char *, int, int) ); + + +/* I/O error handling */ +#define _CHKIO(cond,ior,val,def) ((cond) ? P_ioresult=0,(val) \ + : P_ioresult=(ior),(def)) +#define _SETIO(cond,ior) (P_ioresult = (cond) ? 0 : (ior)) + +/* Following defines are suitable for the HP Pascal operating system */ +#define FileNotFound 10 +#define FileNotOpen 13 +#define FileWriteError 38 +#define BadInputFormat 14 +#define EndOfFile 30 + +#define FILENOTFOUND 10 +#define FILENOTOPEN 13 +#define FILEWRITEERROR 38 +#define BADINPUTFORMAT 14 +#define ENDOFFILE 30 + +/* Creating temporary files */ +#if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE) +# define tmpfile() (fopen(tmpnam(NULL), "w+")) +#endif + +/* File buffers */ +#define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS); \ + sc type __CAT__(f,_BUFFER) +#define FILEBUFNC(f,type) int __CAT__(f,_BFLAGS); \ + type __CAT__(f,_BUFFER) + +#define RESETBUF(f,type) (__CAT__(f,_BFLAGS) = 1) +#define SETUPBUF(f,type) (__CAT__(f,_BFLAGS) = 0) + +#define GETFBUF(f,type) (*((__CAT__(f,_BFLAGS) == 1 && \ + ((__CAT__(f,_BFLAGS) = 2), \ + fread(&__CAT__(f,_BUFFER), \ + sizeof(type),1,(f)))),\ + &__CAT__(f,_BUFFER))) +#define AGETFBUF(f,type) ((__CAT__(f,_BFLAGS) == 1 && \ + ((__CAT__(f,_BFLAGS) = 2), \ + fread(__CAT__(f,_BUFFER), \ + sizeof(type),1,(f)))),\ + __CAT__(f,_BUFFER)) + +#define PUTFBUF(f,type,v) (GETFBUF(f,type) = (v)) +#define CPUTFBUF(f,v) (PUTFBUF(f,char,v)) +#define APUTFBUF(f,type,v) (memcpy(AGETFBUF(f,type), (v), \ + sizeof(__CAT__(f,_BUFFER)))) + +#define GET(f,type) (__CAT__(f,_BFLAGS) == 1 ? \ + fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) : \ + (__CAT__(f,_BFLAGS) = 1)) + +#define PUT(f,type) (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)), \ + (__CAT__(f,_BFLAGS) = 0)) +#define CPUT(f) (PUT(f,char)) + +#define BUFEOF(f) (__CAT__(f,_BFLAGS) != 2 && P_eof(f)) +#define BUFFPOS(f) (ftell(f) - (__CAT__(f,_BFLAGS) == 2)) + +#ifdef SKIP +typedef struct { + FILE *f; + FILEBUFNC(f,Char); + Char name[_FNSIZE]; +} _TEXT; +#endif + +/* Memory allocation */ +#ifdef __GCC__ +# define Malloc(n) (PHRQ_malloc(n) ?: (Anyptr)_OutMem()) +#else +extern Anyptr __MallocTemp__; +# define Malloc(n) ((__MallocTemp__ = PHRQ_malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem()) +#endif +#define FreeR(p) (free((Anyptr)(p))) /* used if arg is an rvalue */ +#define Free(p) (free((Anyptr)(p)), (p)=NULL) + +/* sign extension */ +#define SEXT(x,n) ((x) | -(((x) & (1L<<((n)-1))) << 1)) + +/* packed arrays */ /* BEWARE: these are untested! */ +#define P_getbits_UB(a,i,n,L) ((int)((a)[(i)>>(L)-(n)] >> \ + (((~(i))&((1<<(L)-(n))-1)) << (n)) & \ + (1<<(1<<(n)))-1)) + +#define P_getbits_SB(a,i,n,L) ((int)((a)[(i)>>(L)-(n)] << \ + (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\ + (n)) >> (16-(1<<(n)))))) + +#define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |= \ + (x) << (((~(i))&((1<<(L)-(n))-1)) << (n))) + +#define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |= \ + ((x) & (1<<(1<<(n)))-1) << \ + (((~(i))&((1<<(L)-(n))-1)) << (n))) + +#define P_clrbits_B(a,i,n,L) ((a)[(i)>>(L)-(n)] &= \ + ~( ((1<<(1<<(n)))-1) << \ + (((~(i))&((1<<(L)-(n))-1)) << (n))) ) + +/* small packed arrays */ +#define P_getbits_US(v,i,n) ((int)((v) >> ((i)<<(n)) & (1<<(1<<(n)))-1)) +#define P_getbits_SS(v,i,n) ((int)((long)(v) << (SETBITS - (((i)+1) << (n))) >> (SETBITS-(1<<(n))))) +#define P_putbits_US(v,i,x,n) ((v) |= (x) << ((i) << (n))) +#define P_putbits_SS(v,i,x,n) ((v) |= ((x) & (1<<(1<<(n)))-1) << ((i)<<(n))) +#define P_clrbits_S(v,i,n) ((v) &= ~( ((1<<(1<<(n)))-1) << ((i)<<(n)) )) + +#define P_max(a,b) ((a) > (b) ? (a) : (b)) +#define P_min(a,b) ((a) < (b) ? (a) : (b)) + + +/* Fix ANSI-isms */ + +#ifdef LACK_LABS +# ifndef labs +# define labs my_labs + extern long my_labs P2PP( (long) ); +# endif +#endif + +#ifdef LACK_MEMMOVE +# ifndef memmove +# define memmove my_memmove + extern Anyptr my_memmove P2PP( (Anyptr, Const Anyptr, size_t) ); +# endif +#endif + +#ifdef LACK_MEMCPY +# ifndef memcpy +# define memcpy my_memcpy + extern Anyptr my_memcpy P2PP( (Anyptr, Const Anyptr, size_t) ); +# endif +# ifndef memcmp +# define memcmp my_memcmp + extern int my_memcmp P2PP( (Const Anyptr, Const Anyptr, size_t) ); +# endif +# ifndef memset +# define memset my_memset + extern Anyptr my_memset P2PP( (Anyptr, int, size_t) ); +# endif +#endif + +/* Fix toupper/tolower on Suns and other stupid BSD systems */ +#ifdef toupper +# undef toupper +# undef tolower +# define toupper(c) my_toupper(c) +# define tolower(c) my_tolower(c) +#endif + +#ifndef _toupper +# if 'A' == 65 && 'a' == 97 +# define _toupper(c) ((c)-'a'+'A') +# define _tolower(c) ((c)-'A'+'a') +# else +# ifdef toupper +# undef toupper /* hope these are shadowing real functions, */ +# undef tolower /* because my_toupper calls _toupper! */ +# endif +# define _toupper(c) toupper(c) +# define _tolower(c) tolower(c) +# endif +#endif + + +#endif /* P2C_H */ + + + +/* End. */ + + diff --git a/p2clib.cpp b/p2clib.cpp new file mode 100644 index 00000000..88b662b8 --- /dev/null +++ b/p2clib.cpp @@ -0,0 +1,936 @@ + +/* Run-time library for use with "p2c", the Pascal to C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + +static char const svnid[] = "$Id: p2clib.c 663 2005-11-16 00:46:04Z dlpark $"; + +#include "p2c.h" +#include "output.h" +#define STOP 1 +#define CONTINUE 0 + +#define NO_TIME +#ifndef NO_TIME +# include +#endif +#include + +#define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ + + + + +static int P_argc; +static char **P_argv; +static char *_ShowEscape(char *buf, int code, int ior, char *prefix); + +int P_escapecode; +int P_ioresult; + +long EXCP_LINE; /* Used by Pascal workstation system */ + +Anyptr __MallocTemp__; + +__p2c_jmp_buf *__top_jb; + +void PASCAL_MAIN(int argc, char **argv) +{ + if (svnid == NULL) fprintf(stderr," "); + P_argc = argc; + P_argv = argv; + __top_jb = NULL; + P_escapecode = 0; + P_ioresult = 0; +#ifdef LOCAL_INIT + LOCAL_INIT(); +#endif +} + + + + + +/* In case your system lacks these... */ + +long my_labs(long x) +{ + return((x > 0) ? x : -x); +} + + +/* #define __STDC__ */ /* PHREEQ98 */ + +Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n) +{ + register char *dd = (char *)d, *ss = (char *)s; + if (dd < ss || (unsigned int) (dd - ss) >= n) { + memcpy(dd, ss, n); + } else if (n > 0) { + dd += n; + ss += n; + while (n-- > 0) + *--dd = *--ss; + } + return d; +} + + +Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n) + +{ + register char *ss = (char *)s, *dd = (char *)d; + while (n-- > 0) + *dd++ = *ss++; + return d; +} + +int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) +{ + register char *a = (char *)s1, *b = (char *)s2; + register int i; + while (n-- > 0) + if ((i = (*a++) - (*b++)) != 0) + return i; + return 0; +} + +Anyptr my_memset(Anyptr d, int c, size_t n) +{ + register char *dd = (char *)d; + while (n-- > 0) + *dd++ = (char) c; + return d; +} + +int my_toupper(int c) +{ + if (islower(c)) + return _toupper(c); + else + return c; +} + + +int my_tolower(int c) + +{ + if (isupper(c)) + return _tolower(c); + else + return c; +} + + + + +long ipow(long a, long b) +{ + long v; + + if (a == 0 || a == 1) + return a; + if (a == -1) + return (b & 1) ? -1 : 1; + if (b < 0) + return 0; + if (a == 2) + return 1L << b; + v = (b & 1) ? a : 1; + while ((b >>= 1) > 0) { + a *= a; + if (b & 1) + v *= a; + } + return v; +} + + + + +/* Common string functions: */ + +/* Store in "ret" the substring of length "len" starting from "pos" (1-based). + Store a shorter or null string if out-of-range. Return "ret". */ +char *strsub(register char *ret, register char *s, register int pos, register int len) +{ + register char *s2; + + if (--pos < 0 || len <= 0) { + *ret = 0; + return ret; + } + while (pos > 0) { + if (!*s++) { + *ret = 0; + return ret; + } + pos--; + } + s2 = ret; + while (--len >= 0) { + if (!(*s2++ = *s++)) + return ret; + } + *s2 = 0; + return ret; +} + + +/* Return the index of the first occurrence of "pat" as a substring of "s", + starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ + +int strpos2(char *s, register char *pat, register int pos) +{ + register char *cp, ch; + register int slen; + + if (--pos < 0) + return 0; + slen = strlen(s) - pos; + cp = s + pos; + if (!(ch = *pat++)) + return 0; + pos = strlen(pat); + slen -= pos; + while (--slen >= 0) { + if (*cp++ == ch && !strncmp(cp, pat, pos)) + return cp - s; + } + return 0; +} + + +/* Case-insensitive version of strcmp. */ +int strcicmp(register char *s1, register char *s2) +{ + register unsigned char c1, c2; + + while (*s1) { + if (*s1++ != *s2++) { + if (!s2[-1]) + return 1; + c1 = (unsigned char) toupper(s1[-1]); + c2 = (unsigned char) toupper(s2[-1]); + if (c1 != c2) + return c1 - c2; + } + } + if (*s2) + return -1; + return 0; +} + + + + +/* HP and Turbo Pascal string functions: */ + +/* Trim blanks at left end of string. */ +char *strltrim(register char *s) +{ + while (Isspace((int) *s++)) ; + return s - 1; +} + + +/* Trim blanks at right end of string. */ +char *strrtrim(register char *s) +{ + register char *s2 = s; + + if (!*s) + return s; + while (*++s2) ; + while (s2 > s && Isspace((int) *--s2)) + *s2 = 0; + return s; +} + + +/* Store in "ret" "num" copies of string "s". Return "ret". */ +#ifdef SKIP +char *strrpt(ret, s, num) +char *ret; +register char *s; +register int num; +{ + register char *s2 = ret; + register char *s1; + + while (--num >= 0) { + s1 = s; + while ((*s2++ = *s1++)) ; + s2--; + } + return ret; +} +#endif + +/* Store in "ret" string "s" with enough pad chars added to reach "size". */ + +#ifdef SKIP +char *strpad +(ret, s, padchar, num) +char *ret; +register char *s; +register int padchar, num; +{ + register char *d = ret; + + if (s == d) { + while (*d++) ; + } else { + while ((*d++ = *s++)) ; + } + num -= (--d - ret); + while (--num >= 0) + *d++ = (char) padchar; + *d = 0; + return ret; +} +#endif + +/* Copy the substring of length "len" from index "spos" of "s" (1-based) + to index "dpos" of "d", lengthening "d" if necessary. Length and + indices must be in-range. */ +void strmove(register int len, register char *s, register int spos, register char *d, register int dpos) +{ + s += spos - 1; + d += dpos - 1; + while (*d && --len >= 0) + *d++ = *s++; + if (len > 0) { + while (--len >= 0) + *d++ = *s++; + *d = 0; + } +} + + +/* Delete the substring of length "len" at index "pos" from "s". + Delete less if out-of-range. */ +#ifdef SKIP +void strdelete(s, pos, len) +register char *s; +register int pos, len; +{ + register int slen; + + if (--pos < 0) + return; + slen = strlen(s) - pos; + if (slen <= 0) + return; + s += pos; + if (slen <= len) { + *s = 0; + return; + } + while ((*s = s[len])) s++; +} +#endif + +/* Insert string "src" at index "pos" of "dst". */ +void strinsert(register char *src, register char *dst, register int pos) +{ + register int slen, dlen; + + if (--pos < 0) + return; + dlen = strlen(dst); + dst += dlen; + dlen -= pos; + if (dlen <= 0) { + strcpy(dst, src); + return; + } + slen = strlen(src); + do { + dst[slen] = *dst; + --dst; + } while (--dlen >= 0); + dst++; + while (--slen >= 0) + *dst++ = *src++; +} + + + + +/* File functions */ + +/* Peek at next character of input stream; return EOF at end-of-file. */ +int P_peek(FILE *f) +{ + int ch; + + ch = getc(f); + if (ch == EOF) + return EOF; + ungetc(ch, f); + return (ch == '\n') ? ' ' : ch; +} + + +/* Check if at end of file, using Pascal "eof" semantics. End-of-file for + stdin is broken; remove the special case for it to be broken in a + different way. */ +/*int P_eof(FILE *f)*/ +int P_eof(void) +{ +#ifdef SKIP + register int ch; + if (feof(f)) + return 1; + if (f == stdin) + return 0; /* not safe to look-ahead on the keyboard! */ + ch = getc(f); + if (ch == EOF) + return 1; + ungetc(ch, f); +#endif + return 0; +} + + +/* Check if at end of line (or end of entire file). */ +int P_eoln(FILE *f) +{ + register int ch; + + ch = getc(f); + if (ch == EOF) + return 1; + ungetc(ch, f); + return (ch == '\n'); +} + + +/* Read a packed array of characters from a file. */ +Void P_readpaoc(FILE *f, char *s, int len) +{ + int ch; + + for (;;) { + if (len <= 0) + return; + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + *s++ = (char) ch; + --len; + } + while (--len >= 0) + *s++ = ' '; + if (ch != EOF) + ungetc(ch, f); +} +Void P_readlnpaoc(FILE *f, char *s, int len) +{ + int ch; + + for (;;) { + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + if (len > 0) { + *s++ = (char) ch; + --len; + } + } + while (--len >= 0) + *s++ = ' '; +} + + +/* Compute maximum legal "seek" index in file (0-based). */ +long P_maxpos(FILE *f) +{ + long savepos = ftell(f); + long val; + + if (fseek(f, 0L, SEEK_END)) + return -1; + val = ftell(f); + if (fseek(f, savepos, SEEK_SET)) + return -1; + return val; +} + + +/* Use packed array of char for a file name. */ +Char *P_trimname(register Char *fn, register int len) +{ + static Char fnbuf[256]; + register Char *cp = fnbuf; + + while (--len >= 0 && *fn && !isspace((int) *fn)) + *cp++ = *fn++; + *cp = 0; + return fnbuf; +} + + + + +/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. + We fix memory size as 10Meg as a reasonable compromise. */ + +long memavail(void) +{ + return 10000000; /* worry about this later! */ +} + +long maxavail(void) +{ + return memavail(); +} + + + + +/* Sets are stored as an array of longs. S[0] is the size of the set; + S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum + I such that S[I] is nonzero. S[0] is zero for an empty set. Within + each long, bits are packed from lsb to msb. The first bit of the + set is the element with ordinal value 0. (Thus, for a "set of 5..99", + the lowest five bits of the first long are unused and always zero.) */ + +/* (Sets with 32 or fewer elements are normally stored as plain longs.) */ +long *P_setunion(register long *d, register long *s1, register long *s2) /* d := s1 + s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) { + *d++ = *s1++ | *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + *dbase = d - dbase - 1; + return dbase; +} + +long *P_setint(register long *d, register long *s1, register long *s2) /* d := s1 * s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & *s2++; + while (--d > dbase && !*d) ; + *dbase = d - dbase; + return dbase; +} + +long *P_setdiff(register long *d, register long *s1, register long *s2) /* d := s1 - s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & ~*s2++; + if (sz1 >= 0) { + while (sz1-- >= 0) + *d++ = *s1++; + } + while (--d > dbase && !*d) ; + *dbase = d - dbase; + return dbase; +} + +long *P_setxor(register long *d, register long *s1, register long *s2) /* d := s1 / s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) { + *d++ = *s1++ ^ *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + while (--d > dbase && !*d) ; + *dbase = d - dbase; + return dbase; +} + +int P_inset(register unsigned val, register long *s) /* val IN s */ +{ + register int bit; + bit = val % SETBITS; + val /= SETBITS; + if ((long) val < (*s++ && ((1L< size) { + s += size; + while ((long) val > size) + *++s = 0, size++; + *sbase = size; + } else + s += val; + *s |= 1L< (int)v2) + return sbase; + b1 = v1 % SETBITS; + v1 /= SETBITS; + b2 = v2 % SETBITS; + v2 /= SETBITS; + size = *s; + v1++; + if ((int) ++v2 > size) { + while ((int) v2 > size) + s[++size] = 0; + s[v2] = 0; + *s = v2; + } + s += v1; + if (v1 == v2) { + *s |= (~((-2L)<<(b2-b1))) << b1; + } else { + *s++ |= (-1L) << b1; + while (++v1 < v2) + *s++ = -1; + *s |= ~((-2L) << b2); + } + return sbase; +} + +long *P_remset(register long *s, register unsigned val) /* s := s - [val] */ +{ + register int bit; + bit = val % SETBITS; + val /= SETBITS; + if ((long) ++val <= *s) { + if (!(s[val] &= ~(1L<= 0) { + if (*s1++ != *s2++) + return 0; + } + return 1; +} + +int P_subset(register long *s1, register long *s2) /* s1 <= s2 */ +{ + register int sz1 = *s1++, sz2 = *s2++; + if (sz1 > sz2) + return 0; + while (--sz1 >= 0) { + if (*s1++ & ~*s2++) + return 0; + } + return 1; +} + +long *P_setcpy(register long *d, register long *s) /* d := s */ +{ + register long *save_d = d; + +#ifdef SETCPY_MEMCPY + memcpy(d, s, (*s + 1) * sizeof(long)); +#else + register int i = *s + 1; + while (--i >= 0) + *d++ = *s++; +#endif + return save_d; +} + + +/* s is a "smallset", i.e., a 32-bit or less set stored + directly in a long. */ +long *P_expset(register long *d, register long s) /* d := s */ +{ + if (s) { + d[1] = s; + *d = 1; + } else + *d = 0; + return d; +} + +long P_packset(register long *s) /* convert s to a small-set */ +{ + if (*s++) + return *s; + else + return 0; +} + + + + + +/* Oregon Software Pascal extensions, courtesy of William Bader */ +int P_getcmdline(int l, int h, Char *line) +{ + int i, len; + char *s; + + h = h - l + 1; + len = 0; + for(i = 1; i < P_argc; i++) { + s = P_argv[i]; + while (*s) { + if (len >= h) return len; + line[len++] = *s++; + } + if (len >= h) return len; + line[len++] = ' '; + } + return len; +} + +#ifndef NO_TIME +Void TimeStamp(Day, Month, Year, Hour, Min, Sec) +int *Day, *Month, *Year, *Hour, *Min, *Sec; +{ + struct tm *tm; + long clock; + + time(&clock); + tm = localtime(&clock); + *Day = tm->tm_mday; + *Month = tm->tm_mon + 1; /* Jan = 0 */ + *Year = tm->tm_year; + if (*Year < 1900) + *Year += 1900; /* year since 1900 */ + *Hour = tm->tm_hour; + *Min = tm->tm_min; + *Sec = tm->tm_sec; +} + +Void VAXdate(s) +char *s; +{ + long clock; + char *c; + int i; + static int where[] = {8, 9, 0, 4, 5, 6, 0, 20, 21, 22, 23}; + + time(&clock); + c = ctime(&clock); + for (i = 0; i < 11; i++) + s[i] = my_toupper(c[where[i]]); + s[2] = '-'; + s[6] = '-'; +} + +Void VAXtime(s) +char *s; +{ + long clock; + char *c; + int i; + + time(&clock); + c = ctime(&clock); + for (i = 0; i < 8; i++) + s[i] = c[i+11]; + s[8] = '.'; + s[9] = '0'; + s[10] = '0'; +} +#endif + + + + +/* SUN Berkeley Pascal extensions */ +Void P_sun_argv(register char *s, register int len, register int n) +{ + register char *cp; + + if (n < P_argc) + cp = P_argv[n]; + else + cp = ""; + while (*cp && --len >= 0) + *s++ = *cp++; + while (--len >= 0) + *s++ = ' '; +} + + + + +int _OutMem(void) +{ + return _Escape(-2); +} + +int _CaseCheck(void) +{ + return _Escape(-9); +} + +int _NilCheck(void) +{ + return _Escape(-3); +} + + + + + +/* The following is suitable for the HP Pascal operating system. + It might want to be revised when emulating another system. */ + +#ifdef SKIP +static char *_ShowEscape(buf, code, ior, prefix) +char *buf, *prefix; +int code, ior; +#endif +static char *_ShowEscape(char *buf, int code, int ior, char *prefix) +{ + char *bufp; + + if (prefix && *prefix) { + strcpy(buf, prefix); + strcat(buf, ": "); + bufp = buf + strlen(buf); + } else { + bufp = buf; + } + if (code == -10) { + sprintf(bufp, "Pascal system I/O error %d", ior); + switch (ior) { + case 3: + strcat(buf, " (illegal I/O request)"); + break; + case 7: + strcat(buf, " (bad file name)"); + break; + case FileNotFound: /*10*/ + strcat(buf, " (file not found)"); + break; + case FileNotOpen: /*13*/ + strcat(buf, " (file not open)"); + break; + case BadInputFormat: /*14*/ + strcat(buf, " (bad input format)"); + break; + case 24: + strcat(buf, " (not open for reading)"); + break; + case 25: + strcat(buf, " (not open for writing)"); + break; + case 26: + strcat(buf, " (not open for direct access)"); + break; + case 28: + strcat(buf, " (string subscript out of range)"); + break; + case EndOfFile: /*30*/ + strcat(buf, " (end-of-file)"); + break; + case FileWriteError: /*38*/ + strcat(buf, " (file write error)"); + break; + } + } else { + sprintf(bufp, "Pascal system error %d", code); + switch (code) { + case -2: + strcat(buf, " (out of memory)"); + break; + case -3: + strcat(buf, " (reference to NIL pointer)"); + break; + case -4: + strcat(buf, " (integer overflow)"); + break; + case -5: + strcat(buf, " (divide by zero)"); + break; + case -6: + strcat(buf, " (real math overflow)"); + break; + case -8: + strcat(buf, " (value range error)"); + break; + case -9: + strcat(buf, " (CASE value range error)"); + break; + case -12: + strcat(buf, " (bus error)"); + break; + case -20: + strcat(buf, " (stopped by user)"); + break; + } + } + return buf; +} +int _Escape(int code) +{ + char buf[100]; + char token[200]; + + P_escapecode = code; + if (__top_jb) { + __p2c_jmp_buf *jb = __top_jb; + __top_jb = jb->next; + longjmp(jb->jbuf, 1); + } + if (code == 0) + /* exit(EXIT_SUCCESS); */ + error_msg("Exit success in Basic", STOP); + if (code == -1) { + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", _ShowEscape(buf, P_escapecode, P_ioresult, "")); + error_msg(token, STOP); + exit(EXIT_FAILURE); + } + /* fprintf(stderr, "%s\n", _ShowEscape(buf, P_escapecode, P_ioresult, "")); */ + /* exit(EXIT_FAILURE); */ + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", _ShowEscape(buf, P_escapecode, P_ioresult, "")); + error_msg(token, STOP); + return(1); +} +int _EscIO(int code) +{ + P_ioresult = code; + return _Escape(-10); +} + + + + +/* End. */ diff --git a/parse.cpp b/parse.cpp new file mode 100644 index 00000000..27d39c58 --- /dev/null +++ b/parse.cpp @@ -0,0 +1,904 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: parse.c 392 2005-07-19 16:05:07Z dlpark $"; + +static int get_coef(LDBLE *coef, char **eqnaddr); +static int get_secondary (char **t_ptr, char *element, int *i); +static int get_species (char **ptr); + +/* ---------------------------------------------------------------------- */ +int parse_eq(char *eqn, struct elt_list **elt_ptr, int association) +/* ---------------------------------------------------------------------- */ +/* + * function to break equation up into component species + * returns species name, coefficient, and charge in global variable "rxn_list". + * Also returns pointer to elt_list structure array with list of elements + * and coefficients in species. + * rxn_list global variable, output with contiguous rxn_list structures, + * which is the reaction. Target species is first in + * list, coefficient is -1.0. + * + * Argurments: + * *eqn input, pointer to equation to be parsed. + * **elt_ptr output, pointer to contiguous elt_list structures, + * which is list of elements and coefficients in the + * target species. + * association input, TRUE or FALSE if reaction is an association reaction + */ +{ + int i; + LDBLE coef, z; + char c; + char *ptr, *char_ptr; + if (svnid == NULL) fprintf(stderr," "); + + paren_count = 0; +/* + * Remove white space + */ + squeeze_white(eqn); +/* + * Check for illegal characters + */ + for (i = 0; (c=eqn[i]) != '\0'; i++) { + if( islegit(c) == FALSE ){ + sprintf(error_string,"Character is not allowed,\ + %c (octal: %o).",c,c); + error_msg(error_string, CONTINUE); + return(ERROR); + } + } + +/* + * Find coefficients, name, and charge for each species for lhs + */ + count_trxn=0; + ptr=eqn; + c = ptr[0]; + for (;;) { + if (c == '=') break; + if (c == '\0'){ + sprintf(error_string,"Equation has no equal sign.\n\t%s",eqn); + error_msg(error_string, CONTINUE); + return(ERROR); + } + if ( get_species (&ptr) == ERROR ){ + return(ERROR); + } + c = ptr[0]; + if ( association == FALSE ) { + trxn.token[count_trxn].coef *= -1.0; + } + count_trxn++; + } +/* + * Get coefficient, name, and charge of species for dissociation reaction + */ + ptr++; + if ( association == TRUE ) { + if ( get_species (&ptr) == ERROR ){ + return(ERROR); + } + trxn.token[count_trxn].coef *= -1.0; + /* Swap species into first structure position */ + char_ptr=trxn.token[0].name; + coef=trxn.token[0].coef; + z=trxn.token[0].z; + trxn.token[0].name=trxn.token[count_trxn].name; + trxn.token[0].coef=trxn.token[count_trxn].coef; + trxn.token[0].z=trxn.token[count_trxn].z; + trxn.token[count_trxn].name=char_ptr; + trxn.token[count_trxn].coef=coef; + trxn.token[count_trxn].z=z; + count_trxn++; + } +/* + * Get reaction species from rhs of equation + */ + c = ptr[0]; + for (;;) { + if (c == '\0') break; + if ( get_species (&ptr) == ERROR ){ + return(ERROR); + } + c = ptr[0]; + if ( association == TRUE ) { + trxn.token[count_trxn].coef *= -1.0; + } + count_trxn++; + } +/* + * Sort list of reaction species + */ + trxn_sort(); +/* + * Get elements in species or mineral formula + */ + count_elts=0; + char_ptr=trxn.token[0].name; + if ( get_elts_in_species( &char_ptr , trxn.token[0].coef ) == ERROR ) { + return(ERROR); + } +/* + * Sort elements in reaction and combine + */ + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + if (elt_list_combine () == ERROR) return(ERROR); +/* + * Malloc space and store element data for return + */ + *elt_ptr=(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1)*sizeof(struct elt_list)); + if (*elt_ptr == NULL ) malloc_error(); + for ( i=0; i < count_elts; i++ ) { + (*elt_ptr)[i].elt=elt_list[i].elt; + (*elt_ptr)[i].coef=-elt_list[i].coef; + } + (*elt_ptr)[count_elts].elt=NULL; +/* + * Debugging print of parsed equation + trxn_print(); + */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int check_eqn ( int association ) +/* ---------------------------------------------------------------------- */ +/* + * Check that equation is balanced reaction. Uses array "trxn.token" and + * assumes "count_trxn" is set to number of species in reaction. + * Charge and elements are checked. + * + * Arguments: + * + * association input, TRUE or FALSE if reaction is an association reaction. + */ +{ + int i; + int oops=0; + char *t_ptr; + LDBLE sumcharge; + + paren_count=0; + count_elts=0; +/* + * Check that coefficient of first species is -1.0 + */ + if ( equal(trxn.token[0].coef,-1.0,TOL) == FALSE ) { + if (association == TRUE) { + sprintf(error_string, "Coefficient of first species on rhs is not equal to 1.0."); + error_msg(error_string, CONTINUE); + } else { + sprintf(error_string, "Coefficient of mineral (first on lhs) is not equal to 1.0."); + error_msg(error_string, CONTINUE); + } + return(ERROR); + } +/* + * Go through all species in the reaction; sum the charge and store elements + */ + sumcharge=0.0; + for (i=0; i < count_trxn; i++) { + sumcharge += ( trxn.token[i].coef)*(trxn.token[i].z); + t_ptr=trxn.token[i].name; + if ( get_elts_in_species(&t_ptr, trxn.token[i].coef ) == ERROR ) { + return(ERROR); + } + } +/* + * Sort elements in reaction and combine + */ + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + if (elt_list_combine() == ERROR) return(ERROR); +/* + * Check charge + */ + if ( equal(sumcharge, 0.0, TOL) == FALSE) { + sprintf(error_string, "Equation is not charge balanced."); + error_msg(error_string, CONTINUE); + oops++; + } +/* + * Check mass balance + */ + for ( i=0; i < count_elts; i++) { + if ( (equal(elt_list[i].coef,0.0,TOL) == FALSE) && + strncmp( (elt_list[i].elt)->name , "e" , MAX_LENGTH) != 0) { + sprintf(error_string, "Equation does not balance for element, %s.", (elt_list[i].elt)->name); + error_msg(error_string, CONTINUE); + oops++; + } + } + if (oops == 0) { + return(OK); + } else { + return(ERROR); + } +} +/* ---------------------------------------------------------------------- */ +int get_charge(char *charge, LDBLE *z) +/* ---------------------------------------------------------------------- */ +/* + * Function takes character string and calculates the charge on + * the species. Charge can be in two forms: (1) string of "+" or "-" + * or (2) + or - followed by an integer. Charge is reduced to form (2) + * and stored in the pointer location *charge. + * + * Arguments: + * *charge input, string containing charge + * output, string containing charge of the form + or - + * followed by an integer, if integer greater than 1. + * *z output, value of charge. + * + * Returns: + * ERROR, + * OK. + */ +{ + int i; + char *ptr; + char c,c1; +/* + * Charge is zero + */ + if((c=charge[0]) == '\0'){ + *z=0.0; + return(OK); + } +/* + * Error check for + or - at start of string + */ + if(c != '+' && c != '-'){ + sprintf(error_string,"Character string for charge does not start with + or -,\t%s.", charge); + error_msg(error_string, CONTINUE); + return(ERROR); + } +/* + * Count string of +'s or -'s + */ + i=0; + while (c == (c1=charge[i++]) ); + i--; + if (c1 == '\0') { + if (c == '-') i=-i; + } else { +/* + * + or - followed by a number + */ + errno=0; + i=strtol(charge,&ptr,0); +#ifdef SKIP + if (errno == ERANGE) { + sprintf(error_string, "Error in character string for charge, %s.", charge); + error_msg(error_string, CONTINUE); + return(ERROR); + } +#endif +/* + * Truncate fractional part of charge if all zeros + */ + if (*ptr != '\0') { + if ( *ptr == '.') { + while (*(++ptr) != '\0') { + if (*ptr != '0') { + *z = strtod(charge, &ptr); + return(OK); +#ifdef SKIP + sprintf(error_string, "Charge must be an integer, %s.", charge); + error_msg(error_string, CONTINUE); + return(ERROR); +#endif + } + } +/* + * Non-numeric characters + */ + } else { + sprintf(error_string, "Error in character string for charge, %s.", charge); + error_msg(error_string, CONTINUE); + return(ERROR); + } + } + } +/* + * Charge is zero, must have had +0 or -0 in eqn + */ + if (i == 0) { + charge[0]='\0'; + } +/* + * Charge is +1 or -1, single + or - + */ + if (abs(i) == 1) { + charge[0]=c; + charge[1]='\0'; + } +/* + * Abs(z)>1, set charge to + or - plus integer + */ + if (abs(i)>1) { + if (sprintf(charge,"%-+d",i) == EOF){ + sprintf(error_string, "Error converting charge to character string, %s.", charge); + error_msg(error_string, CONTINUE); + return(ERROR); + } + } + *z=i; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_coef(LDBLE *coef, char **eqnaddr) +/* ---------------------------------------------------------------------- */ +/* + * Function reads through eqn and determines the coefficient of the next + * species. + * + * Arguments: + * *coef output, coefficient of next species. + * + * **eqnaddr input, pointer to a position in eqn to start parsing + * output, pointer to next position after coefficient + * + * Returns: + * ERROR, + * OK. + */ +{ + int i; + char c,c1; + char *ptr, *ptr1, *rest; + char token[MAX_LENGTH];; + + rest=*eqnaddr; + ptr=*eqnaddr; /* address of a position in eqn */ + c=*ptr; /* character in eqn */ + *coef=0.0; +/* + * No leading sign or number + */ + if (isalpha((int) c) || + (c == '(') || + (c == ')') || + (c == '[') || + (c == ']') + ) { + *coef=1.0; + return(OK); + } +/* + * Leading +, no digits + */ + c1=*(ptr+1); + if (c == '+' && + ( isalpha((int) c1) || + (c1 == '(') || + (c1 == ')') || + (c1 == '[') || + (c1 == ']') ) ) { + *eqnaddr=++ptr; + *coef=1.0; + return(OK); + } +/* + * Leading -, no digits + */ + if (c == '-' && + ( isalpha((int) c1) || + (c1 == '(') || + (c1 == ')') || + (c1 == '[') || + (c1 == ']') + ) ) { + *eqnaddr=++ptr; + *coef=-1.0; + return(OK); + } + i=0; +/* + * Has number coefficient + */ + if (isdigit((int) c) || c == '+' || c == '-' || c =='.') { + while (isdigit((int) c) || c == '+' || c == '-' || c =='.') { + token[i++]=c; + if (i >= MAX_LENGTH) { + sprintf(error_string, "Coefficient has more than MAX_LENGTH characters."); + error_msg(error_string, CONTINUE); + return(ERROR); + } + c=*(++ptr); + } + token[i]='\0'; + *eqnaddr=ptr; + errno = 0; + *coef=strtod(token,&ptr1); + if ((errno == ERANGE) || + (*ptr1 != '\0') ) { + sprintf(error_string, "Error converting coefficient in get_coef, %s.", token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + return(OK); + } +/* + * None of the above, unknown construct + */ + sprintf(error_string, "Illegal equation construct detected in get_coef.\n\t%s.", rest); + error_msg(error_string, CONTINUE); + return(ERROR); +} +/* ---------------------------------------------------------------------- */ +int get_elt (char **t_ptr, char *element, int *i) +/* ---------------------------------------------------------------------- */ +/* + * Function reads an element name out of the equation string. + * An element name is composed of a capital letter followed by any number + * of lower case characters. + * + * Arguments: + * **t_ptr input, points to position in the equation to begin + * output, points to next character of equation after + * element name. + * *element input pointer to place to return element character string + */ +{ + char c; + + c=*(*t_ptr)++; + if (c == '\0') { + sprintf(error_string, "Empty string in get_elt. Expected an element name."); + error_msg(error_string, CONTINUE); + return(ERROR); + } +/* + * Load name into char array element + */ + element[0]=c; + *i=1; + if (c == '[') { + while ((c=(**t_ptr)) != ']') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + if ((c=(**t_ptr)) == ']') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + break; + } else if (**t_ptr == '\0') { + error_msg("No ending bracket (]) for element name", CONTINUE); + input_error++; + break; + } + } + while (islower((int) (c=(**t_ptr))) || c == '_') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } + } else { + while (islower((int) (c=(**t_ptr))) || c == '_') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } + } + element[*i]='\0'; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_elts_in_species (char **t_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, count, l; + char c, c1; + LDBLE d; + char element[MAX_LENGTH]; + + while ( ( (c=**t_ptr) != '+') && + (c != '-') && (c != '\0') ) { + /* close parenthesis */ + if (c == ')') { + paren_count--; + if (paren_count < 0) { + sprintf(error_string,"Too many right parentheses."); + error_msg(error_string, CONTINUE); + return(ERROR); + } + (*t_ptr)++; + return(OK); + } + c1=*((*t_ptr)+1); + /* beginning of element name */ + if (isupper((int) c) || + (c == 'e' && c1 == '-') + || (c == '[') + ) { +/* + * Get new element and subscript + */ + if ( get_elt( t_ptr, element, &l) == ERROR) { + return(ERROR); + } + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_store ( element ); + if ( get_num( t_ptr , &d ) == ERROR) { + return(ERROR); + } + elt_list[count_elts].coef = d*coef; + count_elts++; +/* + * Expand working space for elements if necessary + */ + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + continue; + } +/* + * Open parentheses + */ + if (c=='(') { + count=count_elts; + if (c1 == ')') { + sprintf(error_string, "Empty parentheses."); + warning_msg(error_string); + } + paren_count++; + (*t_ptr)++; + if ( get_elts_in_species(t_ptr, coef ) == ERROR ) { + return(ERROR); + } + if (get_num (t_ptr, &d) == ERROR ) { + return(ERROR); + } + for (i=count; i < count_elts; i++) { + elt_list[i].coef *= d; + } + continue; + } +/* + * Colon + */ + if (c==':') { + count=count_elts; + (*t_ptr)++; + if (get_num (t_ptr, &d) == ERROR ) { + return(ERROR); + } + if ( get_elts_in_species(t_ptr, coef ) == ERROR ) { + return(ERROR); + } + for (i=count; i < count_elts; i++) { + elt_list[i].coef *= d; + } + continue; + } +/* + * Not beginning of element and not opening paren + */ + sprintf(error_string, "Parsing error in get_elts_in_species, unexpected character, %c.", c); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + if (paren_count != 0) { + sprintf(error_string,"Unbalanced parentheses."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +static int get_secondary (char **t_ptr, char *element, int *i) +/* ---------------------------------------------------------------------- */ +/* + * Function reads an element name out of the equation string. + * An element name is composed of a capital letter followed by any number + * of lower case characters. + * + * Arguments: + * **t_ptr input, points to position in the equation to begin + * output, points to next character of equation after + * element name. + * *element input pointer to place to return element character string + */ +{ + int j; + char c; + char *ptr; + + c=*(*t_ptr)++; + if (c == '\0') { + sprintf(error_string, "Empty string in get_elt. Expected an element name."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Load name into char array element + */ + element[0]=c; + *i=1; + if (c == '[') { + while ((c=(**t_ptr)) != ']') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + if ((c=(**t_ptr)) == ']') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + c=(**t_ptr); + break; + } else if ((c=(**t_ptr)) == '\0') { + error_msg("Did not find ending bracket (])", CONTINUE); + input_error++; + return(ERROR); + } + } + while (islower((int) (c=(**t_ptr))) || c == '_') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } + } else { + while (islower((int) (c=(**t_ptr))) || c == '_') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } + } +/* + * Check if secondary master species element + */ + j = *i; + ptr = *t_ptr; + if (c == '(') { + /* copy parenthesis */ + element[*i]=c; + (*i)++; + (*t_ptr)++; + /* copy number */ + for (;;) { + c = **t_ptr; + if (isdigit((int) c) || c == '-' || c == '.') { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } else if (c == '+') { + (*t_ptr)++; + } else { + break; + } + } + /* go back to before parenthesis */ + if (c != ')' ) { + *i = j; + *t_ptr = ptr; + /* put in closing parenthesis */ + } else { + element[*i]=c; + (*i)++; + (*t_ptr)++; + } + } + element[*i]='\0'; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_secondary_in_species (char **t_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, count, l; + char c, c1; + LDBLE d; + char element[MAX_LENGTH]; + + while ( ( (c=**t_ptr) != '+') && + (c != '-') && (c != '\0') ) { + /* close parenthesis */ + if (c == ')') { + paren_count--; + if (paren_count < 0) { + sprintf(error_string,"Too many right parentheses."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } + (*t_ptr)++; + return(OK); + } + c1=*((*t_ptr)+1); + /* beginning of element name */ + if (isupper((int) c) || + c == '[' || + (c == 'e' && c1 == '-') ) { +/* + * Get new element and subscript + */ + if ( get_secondary( t_ptr, element, &l) == ERROR) { + return(ERROR); + } + elt_list[count_elts].elt = element_store ( element ); + if ( get_num( t_ptr , &d ) == ERROR) { + return(ERROR); + } + elt_list[count_elts].coef = d*coef; + count_elts++; +/* + * Expand working space for elements if necessary + */ + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + continue; + } +/* + * Open parentheses + */ + if (c=='(') { + count=count_elts; + if (c1 == ')') { + sprintf(error_string, "Empty parentheses."); + warning_msg(error_string); + } + paren_count++; + (*t_ptr)++; + if ( get_secondary_in_species(t_ptr, coef ) == ERROR ) { + return(ERROR); + } + if (get_num (t_ptr, &d) == ERROR ) { + return(ERROR); + } + for (i=count; i < count_elts; i++) { + elt_list[i].coef *= d; + } + continue; + } +/* + * Colon + */ + if (c==':') { + count=count_elts; + (*t_ptr)++; + if (get_num (t_ptr, &d) == ERROR ) { + return(ERROR); + } + if ( get_secondary_in_species(t_ptr, coef ) == ERROR ) { + return(ERROR); + } + for (i=count; i < count_elts; i++) { + elt_list[i].coef *= d; + } + continue; + } +/* + * Not beginning of element and not opening paren + */ + sprintf(error_string, "Parsing error in get_secondary_in_species, unexpected character, %c.", c); + error_msg(error_string, CONTINUE); + return (ERROR); + } + if (paren_count != 0) { + sprintf(error_string,"Unbalanced parentheses."); + error_msg(error_string, CONTINUE); + return(ERROR); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int get_num (char **t_ptr, LDBLE *num) +/* ---------------------------------------------------------------------- */ +/* + * Function reads through a string looking for leading numeric field + * if no numeric field is found, the number is set to 1.0. + * + * Arguments: + * + * **t_ptr input, points to a position in a character string from which + * a number is to be extracted. + * output, points to next position to be parsed. + * *num address where the number is to be stored. + * + * Returns: + * ERROR, + * OK. + */ +{ + int i, decimal; + char c; + char *ptr1; + char token[MAX_LENGTH]; + + *num=1.0; + i=0; + c=**t_ptr; + decimal=0; + if (isdigit((int) c) || (c == '.') ){ + while (isdigit((int) c) || (c == '.') ) { + if (c == '.') decimal++; + if (decimal > 1) break; + token[i++]=c; + /* check number length */ + if (i >= MAX_LENGTH ) { + sprintf(error_string, "Number was greater than MAX_LENGTH characters."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } + c=*(++(*t_ptr)); + } + token[i]='\0'; + errno=0; + *num=strtod(token,&ptr1); + if ( errno == ERANGE ) { + sprintf(error_string,"Converting number in get_num, %s.", token); + input_error++; + error_msg(error_string, CONTINUE); + return(ERROR); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_species (char **ptr) +/* ---------------------------------------------------------------------- */ +{ +/* Function reads next species out of the equation, including optional + * preceding coefficient and optional trailing charge. Data are + * store in trxn.token[count]. + * + * Arguments: + * **ptr input, points to the position in the equation to pick up the species. + * output, points to the next character after the species charge. + * + */ + char string[MAX_LENGTH]; + int l; + + if (count_trxn + 1 >= max_trxn) { + space ((void **) &(trxn.token), count_trxn+1, &max_trxn, + sizeof(struct rxn_token_temp)); + } + /* coefficient */ + if ( get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR ) { + return(ERROR); + } + /* name and charge */ + if ( get_token( ptr, string, &trxn.token[count_trxn].z, &l) == ERROR ) { + return(ERROR); + } + trxn.token[count_trxn].name = string_hsave ( string ); + return(OK); +} diff --git a/phast.xsd b/phast.xsd new file mode 100644 index 00000000..e2b59f7d --- /dev/null +++ b/phast.xsd @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phqalloc.cpp b/phqalloc.cpp new file mode 100644 index 00000000..30b6b0f2 --- /dev/null +++ b/phqalloc.cpp @@ -0,0 +1,246 @@ +#define EXTERNAL extern +#include "global.h" +#include "output.h" +/*#include */ +#include +#include +#include +static char const svnid[] = "$Id: phqalloc.c 78 2005-02-01 22:47:12Z dlpark $"; + +#if defined(PHREEQCI_GUI) +#define _CRTDBG_MAP_ALLOC +#include +#endif + +typedef struct PHRQMemHeader { + struct PHRQMemHeader *pNext; /* memory allocated just after this one */ + struct PHRQMemHeader *pPrev; /* memory allocated just prior to this one */ +#if !defined(NDEBUG) + size_t size; /* memory request + sizeof(PHRQMemHeader) */ + char *szFileName; /* file name */ + int nLine; /* line number */ + int dummy; /* alignment */ +#endif +} PHRQMemHeader; + +/* + * This pointer points to the last allocated block + * Note: s_pTail->pNext should always be NULL + */ +static PHRQMemHeader *s_pTail = NULL; + + +/* ---------------------------------------------------------------------- */ +#if !defined(NDEBUG) +void *PHRQ_malloc( size_t size, const char *szFileName, int nLine) +#else +void *PHRQ_malloc( size_t size) +#endif +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + if (svnid == NULL) fprintf(stderr," "); + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader*)malloc(sizeof(PHRQMemHeader) + size); + + if (p == NULL) return NULL; + +#if !defined(NDEBUG) + memset(p, 0, sizeof(PHRQMemHeader) + size); +#endif + p->pNext = NULL; + + if ( (p->pPrev = s_pTail) != NULL ) { + s_pTail->pNext = p; + } + +#if !defined(NDEBUG) + p->size = sizeof(PHRQMemHeader) + size; + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + s_pTail = p; + p++; + return ((void *)(p)); +} + +/* ---------------------------------------------------------------------- */ +void PHRQ_free( void *ptr ) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + if (ptr == NULL) return; + + p = (PHRQMemHeader *)ptr - 1; + + if (p->pNext != NULL) { + p->pNext->pPrev = p->pPrev; + } else { + /* Handle special case when (p == s_pTail) */ + assert(s_pTail != NULL); + assert(p == s_pTail); + s_pTail = p->pPrev; + } + + if (p->pPrev) { + p->pPrev->pNext = p->pNext; + } + +#if !defined(NDEBUG) + free(p->szFileName); +#endif + + free(p); +} + +/* ---------------------------------------------------------------------- */ +void PHRQ_free_all( void ) +/* ---------------------------------------------------------------------- */ +{ + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + if (s_pTail == NULL) { +#if !defined(NDEBUG) + output_msg(OUTPUT_MESSAGE, "No memory leaks\n"); +#endif + return; + } + while (s_pTail->pPrev != NULL) + { + s_pTail = s_pTail->pPrev; +#if !defined(NDEBUG) + output_msg(OUTPUT_MESSAGE, "%s(%d) %p: freed in PHRQ_free_all\n", + s_pTail->pNext->szFileName, s_pTail->pNext->nLine, (void *) (s_pTail->pNext + 1)); + free(s_pTail->pNext->szFileName); +#endif + free(s_pTail->pNext); + } + +#if !defined(NDEBUG) + output_msg(OUTPUT_MESSAGE, "%s(%d) %p: freed in PHRQ_free_all\n", + s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail+1)); + if (phast == TRUE) { + output_msg(OUTPUT_STDERR, "%s(%d) %p: freed in PHRQ_free_all, %d\n", + s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail+1), phreeqc_mpi_myself); + } + free(s_pTail->szFileName); +#endif + free(s_pTail); + s_pTail = NULL; +} + +/* ---------------------------------------------------------------------- */ +void *PHRQ_calloc( size_t num, + size_t size +#if !defined(NDEBUG) + , + const char *szFileName, + int nLine +#endif + ) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader*)malloc(sizeof(PHRQMemHeader) + size * num); + + if (p == NULL) return NULL; + + p->pNext = NULL; + + if ( (p->pPrev = s_pTail) != NULL ) { + s_pTail->pNext = p; + } + +#if !defined(NDEBUG) + p->size = sizeof(PHRQMemHeader) + size * num; + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + s_pTail = p; + p++; + return memset(p, 0, size * num); +} + +/* ---------------------------------------------------------------------- */ +void *PHRQ_realloc( void *ptr, + size_t size +#if !defined(NDEBUG) + , + const char *szFileName, + int nLine +#endif + ) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + size_t new_size; + +#if !defined(NDEBUG) + size_t old_size; +#endif + + if (ptr == NULL) + { + return PHRQ_malloc(size +#if !defined(NDEBUG) + , + szFileName, + nLine +#endif + ); + } + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader*)ptr - 1; + + new_size = sizeof(PHRQMemHeader) + size; + +#if defined(NDEBUG) + p = (PHRQMemHeader*)realloc(p, new_size); +#else + old_size = p->size; + p = (PHRQMemHeader*)realloc(p, new_size); + if (p != NULL) { + p->size = new_size; + if (new_size > old_size) { + memset((char*)p + old_size, 0, new_size - old_size); + } + } +#endif + + if (p == NULL) return NULL; + + if (p->pPrev != NULL) { + p->pPrev->pNext = p; + } + + if (p->pNext != NULL) { + p->pNext->pPrev = p; + } else { + s_pTail = p; + } + +#if !defined(NDEBUG) + free(p->szFileName); + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + p++; + return ((void *)(p)); +} + diff --git a/phqalloc.h b/phqalloc.h new file mode 100644 index 00000000..6d06a4b2 --- /dev/null +++ b/phqalloc.h @@ -0,0 +1,46 @@ +#if !defined (INCLUDE_PHRQALLOC_H) +#define INCLUDE_PHRQALLOC_H + +#if !defined(WIN32_MEMORY_DEBUG) +#define USE_PHRQ_ALLOC +#endif + +#if defined (USE_PHRQ_ALLOC) + +#ifdef PHREEQC_IDENT +static char const svnidphqalloc[] = "$Id$"; +#endif + +#if !defined(NDEBUG) +extern void *PHRQ_malloc(size_t, const char *, int); +extern void *PHRQ_calloc(size_t, size_t, const char *, int); +extern void *PHRQ_realloc(void *, size_t, const char *, int); +#else +extern void *PHRQ_malloc(size_t); +extern void *PHRQ_calloc(size_t, size_t); +extern void *PHRQ_realloc(void *, size_t); +#endif + +extern void PHRQ_free(void *); +extern void PHRQ_free_all(void); + +#if !defined(NDEBUG) +#define PHRQ_malloc(s) PHRQ_malloc(s, __FILE__, __LINE__) +#define PHRQ_calloc(c, s) PHRQ_calloc(c, s, __FILE__, __LINE__) +#define PHRQ_realloc(p, s) PHRQ_realloc(p, s, __FILE__, __LINE__) +#endif + +#define free(p) PHRQ_free(p) + +#else /* defined (USE_PHRQ_ALLOC) */ + +#define PHRQ_malloc malloc +#define PHRQ_realloc realloc +#define PHRQ_calloc calloc +#define PHRQ_free free + +#define PHRQ_free_all() do{}while(0) /* NO-OP */ + +#endif /* defined (USE_PHRQ_ALLOC) */ + +#endif /* !defined (INCLUDE_PHRQALLOC_H) */ diff --git a/phreeqc.dat b/phreeqc.dat new file mode 100644 index 00000000..befd93da --- /dev/null +++ b/phreeqc.dat @@ -0,0 +1,1556 @@ +SOLUTION_MASTER_SPECIES +# +#element species alk gfw_formula element_gfw +# +H H+ -1. H 1.008 +H(0) H2 0.0 H +H(1) H+ -1. 0.0 +E e- 0.0 0.0 0.0 +O H2O 0.0 O 16.00 +O(0) O2 0.0 O +O(-2) H2O 0.0 0.0 +Ca Ca+2 0.0 Ca 40.08 +Mg Mg+2 0.0 Mg 24.312 +Na Na+ 0.0 Na 22.9898 +K K+ 0.0 K 39.102 +Fe Fe+2 0.0 Fe 55.847 +Fe(+2) Fe+2 0.0 Fe +Fe(+3) Fe+3 -2.0 Fe +Mn Mn+2 0.0 Mn 54.938 +Mn(+2) Mn+2 0.0 Mn +Mn(+3) Mn+3 0.0 Mn +Al Al+3 0.0 Al 26.9815 +Ba Ba+2 0.0 Ba 137.34 +Sr Sr+2 0.0 Sr 87.62 +Si H4SiO4 0.0 SiO2 28.0843 +Cl Cl- 0.0 Cl 35.453 +C CO3-2 2.0 HCO3 12.0111 +C(+4) CO3-2 2.0 HCO3 +C(-4) CH4 0.0 CH4 +Alkalinity CO3-2 1.0 Ca0.5(CO3)0.5 50.05 +S SO4-2 0.0 SO4 32.064 +S(6) SO4-2 0.0 SO4 +S(-2) HS- 1.0 S +N NO3- 0.0 N 14.0067 +N(+5) NO3- 0.0 N +N(+3) NO2- 0.0 N +N(0) N2 0.0 N +N(-3) NH4+ 0.0 N +B H3BO3 0.0 B 10.81 +P PO4-3 2.0 P 30.9738 +F F- 0.0 F 18.9984 +Li Li+ 0.0 Li 6.939 +Br Br- 0.0 Br 79.904 +Zn Zn+2 0.0 Zn 65.37 +Cd Cd+2 0.0 Cd 112.4 +Pb Pb+2 0.0 Pb 207.19 +Cu Cu+2 0.0 Cu 63.546 +Cu(+2) Cu+2 0.0 Cu +Cu(+1) Cu+1 0.0 Cu + +SOLUTION_SPECIES + +H+ = H+ + log_k 0.000 + -gamma 9.0000 0.0000 + +e- = e- + log_k 0.000 + +H2O = H2O + log_k 0.000 + +Ca+2 = Ca+2 + log_k 0.000 + -gamma 5.0000 0.1650 + +Mg+2 = Mg+2 + log_k 0.000 + -gamma 5.5000 0.2000 + +Na+ = Na+ + log_k 0.000 + -gamma 4.0000 0.0750 + +K+ = K+ + log_k 0.000 + -gamma 3.5000 0.0150 + +Fe+2 = Fe+2 + log_k 0.000 + -gamma 6.0000 0.0000 + +Mn+2 = Mn+2 + log_k 0.000 + -gamma 6.0000 0.0000 + +Al+3 = Al+3 + log_k 0.000 + -gamma 9.0000 0.0000 + +Ba+2 = Ba+2 + log_k 0.000 + -gamma 5.0000 0.0000 + +Sr+2 = Sr+2 + log_k 0.000 + -gamma 5.2600 0.1210 + +H4SiO4 = H4SiO4 + log_k 0.000 + +Cl- = Cl- + log_k 0.000 + -gamma 3.5000 0.0150 + +CO3-2 = CO3-2 + log_k 0.000 + -gamma 5.4000 0.0000 + +SO4-2 = SO4-2 + log_k 0.000 + -gamma 5.0000 -0.0400 + +NO3- = NO3- + log_k 0.000 + -gamma 3.0000 0.0000 + +H3BO3 = H3BO3 + log_k 0.000 + +PO4-3 = PO4-3 + log_k 0.000 + -gamma 4.0000 0.0000 + +F- = F- + log_k 0.000 + -gamma 3.5000 0.0000 + +Li+ = Li+ + log_k 0.000 + -gamma 6.0000 0.0000 + +Br- = Br- + log_k 0.000 + -gamma 3.0000 0.0000 + +Zn+2 = Zn+2 + log_k 0.000 + -gamma 5.0000 0.0000 + +Cd+2 = Cd+2 + log_k 0.000 + +Pb+2 = Pb+2 + log_k 0.000 + +Cu+2 = Cu+2 + log_k 0.000 + -gamma 6.0000 0.0000 + +H2O = OH- + H+ + log_k -14.000 + delta_h 13.362 kcal + -analytic -283.971 -0.05069842 13323.0 102.24447 -1119669.0 + -gamma 3.5000 0.0000 + +2 H2O = O2 + 4 H+ + 4 e- + log_k -86.08 + delta_h 134.79 kcal + +2 H+ + 2 e- = H2 + log_k -3.15 + delta_h -1.759 kcal + +CO3-2 + H+ = HCO3- + log_k 10.329 + delta_h -3.561 kcal + -analytic 107.8871 0.03252849 -5151.79 -38.92561 563713.9 + -gamma 5.4000 0.0000 + +CO3-2 + 2 H+ = CO2 + H2O + log_k 16.681 + delta_h -5.738 kcal + -analytic 464.1965 0.09344813 -26986.16 -165.75951 2248628.9 + +CO3-2 + 10 H+ + 8 e- = CH4 + 3 H2O + log_k 41.071 + delta_h -61.039 kcal + +SO4-2 + H+ = HSO4- + log_k 1.988 + delta_h 3.85 kcal + -analytic -56.889 0.006473 2307.9 19.8858 0.0 + +HS- = S-2 + H+ + log_k -12.918 + delta_h 12.1 kcal + -gamma 5.0000 0.0000 + +SO4-2 + 9 H+ + 8 e- = HS- + 4 H2O + log_k 33.65 + delta_h -60.140 kcal + -gamma 3.5000 0.0000 + +HS- + H+ = H2S + log_k 6.994 + delta_h -5.300 kcal + -analytical -11.17 0.02386 3279.0 + + +NO3- + 2 H+ + 2 e- = NO2- + H2O + log_k 28.570 + delta_h -43.760 kcal + -gamma 3.0000 0.0000 + +2 NO3- + 12 H+ + 10 e- = N2 + 6 H2O + log_k 207.080 + delta_h -312.130 kcal + +NH4+ = NH3 + H+ + log_k -9.252 + delta_h 12.48 kcal + -analytic 0.6322 -0.001225 -2835.76 + +NO3- + 10 H+ + 8 e- = NH4+ + 3 H2O + log_k 119.077 + delta_h -187.055 kcal + -gamma 2.5000 0.0000 + +NH4+ + SO4-2 = NH4SO4- + log_k 1.11 + +H3BO3 = H2BO3- + H+ + log_k -9.240 + delta_h 3.224 kcal +# -analytical 24.3919 0.012078 -1343.9 -13.2258 + +H3BO3 + F- = BF(OH)3- + log_k -0.400 + delta_h 1.850 kcal + +H3BO3 + 2 F- + H+ = BF2(OH)2- + H2O + log_k 7.63 + delta_h 1.618 kcal + +H3BO3 + 2 H+ + 3 F- = BF3OH- + 2 H2O + log_k 13.67 + delta_h -1.614 kcal + +H3BO3 + 3 H+ + 4 F- = BF4- + 3 H2O + log_k 20.28 + delta_h -1.846 kcal + +PO4-3 + H+ = HPO4-2 + log_k 12.346 + delta_h -3.530 kcal + -gamma 4.0000 0.0000 + +PO4-3 + 2 H+ = H2PO4- + log_k 19.553 + delta_h -4.520 kcal + -gamma 4.5000 0.0000 + +H+ + F- = HF + log_k 3.18 + delta_h 3.18 kcal + -analytic -2.033 0.012645 429.01 + +H+ + 2 F- = HF2- + log_k 3.760 + delta_h 4.550 kcal + +Ca+2 + H2O = CaOH+ + H+ + log_k -12.780 + +Ca+2 + CO3-2 = CaCO3 + log_k 3.224 + delta_h 3.545 kcal + -analytic -1228.732 -0.299440 35512.75 485.818 + +Ca+2 + CO3-2 + H+ = CaHCO3+ + log_k 11.435 + delta_h -0.871 kcal + -analytic 1317.0071 0.34546894 -39916.84 -517.70761 563713.9 + -gamma 5.4000 0.0000 + +Ca+2 + SO4-2 = CaSO4 + log_k 2.300 + delta_h 1.650 kcal + +Ca+2 + HSO4- = CaHSO4+ + log_k 1.08 + +Ca+2 + PO4-3 = CaPO4- + log_k 6.459 + delta_h 3.100 kcal + +Ca+2 + HPO4-2 = CaHPO4 + log_k 2.739 + delta_h 3.3 kcal + +Ca+2 + H2PO4- = CaH2PO4+ + log_k 1.408 + delta_h 3.4 kcal + +Ca+2 + F- = CaF+ + log_k 0.940 + delta_h 4.120 kcal + +Mg+2 + H2O = MgOH+ + H+ + log_k -11.440 + delta_h 15.952 kcal + +Mg+2 + CO3-2 = MgCO3 + log_k 2.98 + delta_h 2.713 kcal + -analytic 0.9910 0.00667 + +Mg+2 + H+ + CO3-2 = MgHCO3+ + log_k 11.399 + delta_h -2.771 kcal + -analytic 48.6721 0.03252849 -2614.335 -18.00263 563713.9 + +Mg+2 + SO4-2 = MgSO4 + log_k 2.370 + delta_h 4.550 kcal + +Mg+2 + PO4-3 = MgPO4- + log_k 6.589 + delta_h 3.100 kcal + +Mg+2 + HPO4-2 = MgHPO4 + log_k 2.87 + delta_h 3.3 kcal + +Mg+2 + H2PO4- = MgH2PO4+ + log_k 1.513 + delta_h 3.4 kcal + +Mg+2 + F- = MgF+ + log_k 1.820 + delta_h 3.200 kcal + +Na+ + H2O = NaOH + H+ + log_k -14.180 + +Na+ + CO3-2 = NaCO3- + log_k 1.270 + delta_h 8.910 kcal + +Na+ + HCO3- = NaHCO3 + log_k -0.25 + +Na+ + SO4-2 = NaSO4- + log_k 0.700 + delta_h 1.120 kcal + +Na+ + HPO4-2 = NaHPO4- + log_k 0.29 + +Na+ + F- = NaF + log_k -0.240 + +K+ + H2O = KOH + H+ + log_k -14.460 + +K+ + SO4-2 = KSO4- + log_k 0.850 + delta_h 2.250 kcal + -analytical 3.106 0.0 -673.6 + + +K+ + HPO4-2 = KHPO4- + log_k 0.29 + +Fe+2 + H2O = FeOH+ + H+ + log_k -9.500 + delta_h 13.200 kcal + +Fe+2 + Cl- = FeCl+ + log_k 0.140 + +Fe+2 + CO3-2 = FeCO3 + log_k 4.380 + +Fe+2 + HCO3- = FeHCO3+ + log_k 2.0 + +Fe+2 + SO4-2 = FeSO4 + log_k 2.250 + delta_h 3.230 kcal + +Fe+2 + HSO4- = FeHSO4+ + log_k 1.08 + +Fe+2 + 2HS- = Fe(HS)2 + log_k 8.95 + +Fe+2 + 3HS- = Fe(HS)3- + log_k 10.987 + +Fe+2 + HPO4-2 = FeHPO4 + log_k 3.6 + +Fe+2 + H2PO4- = FeH2PO4+ + log_k 2.7 + +Fe+2 + F- = FeF+ + log_k 1.000 + +Fe+2 = Fe+3 + e- + log_k -13.020 + delta_h 9.680 kcal + -gamma 9.0000 0.0000 + +Fe+3 + H2O = FeOH+2 + H+ + log_k -2.19 + delta_h 10.4 kcal + +Fe+3 + 2 H2O = Fe(OH)2+ + 2 H+ + log_k -5.67 + delta_h 17.1 kcal + +Fe+3 + 3 H2O = Fe(OH)3 + 3 H+ + log_k -12.56 + delta_h 24.8 kcal + +Fe+3 + 4 H2O = Fe(OH)4- + 4 H+ + log_k -21.6 + delta_h 31.9 kcal + +2 Fe+3 + 2 H2O = Fe2(OH)2+4 + 2 H+ + log_k -2.95 + delta_h 13.5 kcal + +3 Fe+3 + 4 H2O = Fe3(OH)4+5 + 4 H+ + log_k -6.3 + delta_h 14.3 kcal + +Fe+3 + Cl- = FeCl+2 + log_k 1.48 + delta_h 5.6 kcal + +Fe+3 + 2 Cl- = FeCl2+ + log_k 2.13 + +Fe+3 + 3 Cl- = FeCl3 + log_k 1.13 + +Fe+3 + SO4-2 = FeSO4+ + log_k 4.04 + delta_h 3.91 kcal + +Fe+3 + HSO4- = FeHSO4+2 + log_k 2.48 + +Fe+3 + 2 SO4-2 = Fe(SO4)2- + log_k 5.38 + delta_h 4.60 kcal + +Fe+3 + HPO4-2 = FeHPO4+ + log_k 5.43 + delta_h 5.76 kcal + +Fe+3 + H2PO4- = FeH2PO4+2 + log_k 5.43 + +Fe+3 + F- = FeF+2 + log_k 6.2 + delta_h 2.7 kcal + +Fe+3 + 2 F- = FeF2+ + log_k 10.8 + delta_h 4.8 kcal + +Fe+3 + 3 F- = FeF3 + log_k 14.0 + delta_h 5.4 kcal + +Mn+2 + H2O = MnOH+ + H+ + log_k -10.590 + delta_h 14.400 kcal + +Mn+2 + Cl- = MnCl+ + log_k 0.610 + +Mn+2 + 2 Cl- = MnCl2 + log_k 0.250 + +Mn+2 + 3 Cl- = MnCl3- + log_k -0.310 + +Mn+2 + CO3-2 = MnCO3 + log_k 4.900 + +Mn+2 + HCO3- = MnHCO3+ + log_k 1.95 + +Mn+2 + SO4-2 = MnSO4 + log_k 2.250 + delta_h 3.370 kcal + +Mn+2 + 2 NO3- = Mn(NO3)2 + log_k 0.600 + delta_h -0.396 kcal + +Mn+2 + F- = MnF+ + log_k 0.840 + +Mn+2 = Mn+3 + e- + log_k -25.510 + delta_h 25.800 kcal + +Al+3 + H2O = AlOH+2 + H+ + log_k -5.00 + delta_h 11.49 kcal + -analytic -38.253 0.0 -656.27 14.327 + +Al+3 + 2 H2O = Al(OH)2+ + 2 H+ + log_k -10.1 + delta_h 26.90 kcal + -analytic 88.500 0.0 -9391.6 -27.121 + +Al+3 + 3 H2O = Al(OH)3 + 3 H+ + log_k -16.9 + delta_h 39.89 kcal + -analytic 226.374 0.0 -18247.8 -73.597 + +Al+3 + 4 H2O = Al(OH)4- + 4 H+ + log_k -22.7 + delta_h 42.30 kcal + -analytic 51.578 0.0 -11168.9 -14.865 + +Al+3 + SO4-2 = AlSO4+ + log_k 3.5 + delta_h 2.29 kcal + +Al+3 + 2SO4-2 = Al(SO4)2- + log_k 5.0 + delta_h 3.11 kcal + +Al+3 + HSO4- = AlHSO4+2 + log_k 0.46 + +Al+3 + F- = AlF+2 + log_k 7.000 + delta_h 1.060 kcal + +Al+3 + 2 F- = AlF2+ + log_k 12.700 + delta_h 1.980 kcal + +Al+3 + 3 F- = AlF3 + log_k 16.800 + delta_h 2.160 kcal + +Al+3 + 4 F- = AlF4- + log_k 19.400 + delta_h 2.200 kcal + +Al+3 + 5 F- = AlF5-2 + log_k 20.600 + delta_h 1.840 kcal + +Al+3 + 6 F- = AlF6-3 + log_k 20.600 + delta_h -1.670 kcal + +H4SiO4 = H3SiO4- + H+ + log_k -9.83 + delta_h 6.12 kcal + -analytic -302.3724 -0.050698 15669.69 108.18466 -1119669.0 + +H4SiO4 = H2SiO4-2 + 2 H+ + log_k -23.0 + delta_h 17.6 kcal + -analytic -294.0184 -0.072650 11204.49 108.18466 -1119669.0 + +H4SiO4 + 4 H+ + 6 F- = SiF6-2 + 4 H2O + log_k 30.180 + delta_h -16.260 kcal + +Ba+2 + H2O = BaOH+ + H+ + log_k -13.470 + +Ba+2 + CO3-2 = BaCO3 + log_k 2.71 + delta_h 3.55 kcal + -analytic 0.113 0.008721 + +Ba+2 + HCO3- = BaHCO3+ + log_k 0.982 + delta_h 5.56 kcal + -analytical -3.0938 0.013669 0.0 0.0 0.0 + +Ba+2 + SO4-2 = BaSO4 + log_k 2.700 + +Sr+2 + H2O = SrOH+ + H+ + log_k -13.290 + -gamma 5.0000 0.0000 + +Sr+2 + CO3-2 + H+ = SrHCO3+ + log_k 11.509 + delta_h 2.489 kcal + -analytic 104.6391 0.04739549 -5151.79 -38.92561 563713.9 + -gamma 5.4000 0.0000 + +Sr+2 + CO3-2 = SrCO3 + log_k 2.81 + delta_h 5.22 kcal + -analytic -1.019 0.012826 + +Sr+2 + SO4-2 = SrSO4 + log_k 2.290 + delta_h 2.080 kcal + +Li+ + H2O = LiOH + H+ + log_k -13.640 + +Li+ + SO4-2 = LiSO4- + log_k 0.640 + +Cu+2 + e- = Cu+ + log_k 2.720 + delta_h 1.650 kcal + -gamma 2.5000 0.0000 + +Cu+2 + H2O = CuOH+ + H+ + log_k -8.000 + -gamma 4.0000 0.0000 + +Cu+2 + 2 H2O = Cu(OH)2 + 2 H+ + log_k -13.680 + +Cu+2 + 3 H2O = Cu(OH)3- + 3 H+ + log_k -26.900 + +Cu+2 + 4 H2O = Cu(OH)4-2 + 4 H+ + log_k -39.600 + +Cu+2 + SO4-2 = CuSO4 + log_k 2.310 + delta_h 1.220 kcal + +Zn+2 + H2O = ZnOH+ + H+ + log_k -8.96 + delta_h 13.4 kcal + +Zn+2 + 2 H2O = Zn(OH)2 + 2 H+ + log_k -16.900 + +Zn+2 + 3 H2O = Zn(OH)3- + 3 H+ + log_k -28.400 + +Zn+2 + 4 H2O = Zn(OH)4-2 + 4 H+ + log_k -41.200 + +Zn+2 + Cl- = ZnCl+ + log_k 0.43 + delta_h 7.79 kcal + +Zn+2 + 2 Cl- = ZnCl2 + log_k 0.45 + delta_h 8.5 kcal + +Zn+2 + 3Cl- = ZnCl3- + log_k 0.5 + delta_h 9.56 kcal + +Zn+2 + 4Cl- = ZnCl4-2 + log_k 0.2 + delta_h 10.96 kcal + +Zn+2 + CO3-2 = ZnCO3 + log_k 5.3 + +Zn+2 + 2CO3-2 = Zn(CO3)2-2 + log_k 9.63 + +Zn+2 + HCO3- = ZnHCO3+ + log_k 2.1 + +Zn+2 + SO4-2 = ZnSO4 + log_k 2.37 + delta_h 1.36 kcal + +Zn+2 + 2SO4-2 = Zn(SO4)2-2 + log_k 3.28 + +Cd+2 + H2O = CdOH+ + H+ + log_k -10.080 + delta_h 13.1 kcal + +Cd+2 + 2 H2O = Cd(OH)2 + 2 H+ + log_k -20.350 + +Cd+2 + 3 H2O = Cd(OH)3- + 3 H+ + log_k -33.300 + +Cd+2 + 4 H2O = Cd(OH)4-2 + 4 H+ + log_k -47.350 + +Cd+2 + Cl- = CdCl+ + log_k 1.980 + delta_h 0.59 kcal + +Cd+2 + 2 Cl- = CdCl2 + log_k 2.600 + delta_h 1.24 kcal + +Cd+2 + 3 Cl- = CdCl3- + log_k 2.400 + delta_h 3.9 kcal + +Cd+2 + CO3-2 = CdCO3 + log_k 2.9 + +Cd+2 + 2CO3-2 = Cd(CO3)2-2 + log_k 6.4 + +Cd+2 + HCO3- = CdHCO3+ + log_k 1.5 + +Cd+2 + SO4-2 = CdSO4 + log_k 2.460 + delta_h 1.08 kcal + +Cd+2 + 2SO4-2 = Cd(SO4)2-2 + log_k 3.5 + +Pb+2 + H2O = PbOH+ + H+ + log_k -7.710 + +Pb+2 + 2 H2O = Pb(OH)2 + 2 H+ + log_k -17.120 + +Pb+2 + 3 H2O = Pb(OH)3- + 3 H+ + log_k -28.060 + +Pb+2 + 4 H2O = Pb(OH)4-2 + 4 H+ + log_k -39.700 + +2 Pb+2 + H2O = Pb2OH+3 + H+ + log_k -6.360 + +Pb+2 + Cl- = PbCl+ + log_k 1.600 + delta_h 4.38 kcal + +Pb+2 + 2 Cl- = PbCl2 + log_k 1.800 + delta_h 1.08 kcal + +Pb+2 + 3 Cl- = PbCl3- + log_k 1.700 + delta_h 2.17 kcal + +Pb+2 + 4 Cl- = PbCl4-2 + log_k 1.380 + delta_h 3.53 kcal + +Pb+2 + CO3-2 = PbCO3 + log_k 7.240 + +Pb+2 + 2 CO3-2 = Pb(CO3)2-2 + log_k 10.640 + +Pb+2 + HCO3- = PbHCO3+ + log_k 2.9 + +Pb+2 + SO4-2 = PbSO4 + log_k 2.750 + +Pb+2 + 2 SO4-2 = Pb(SO4)2-2 + log_k 3.470 + +Pb+2 + NO3- = PbNO3+ + log_k 1.170 + +PHASES + +Calcite + CaCO3 = CO3-2 + Ca+2 + log_k -8.480 + delta_h -2.297 kcal + -analytic -171.9065 -0.077993 2839.319 71.595 + +Aragonite + CaCO3 = CO3-2 + Ca+2 + log_k -8.336 + delta_h -2.589 kcal + -analytic -171.9773 -0.077993 2903.293 71.595 + +Dolomite + CaMg(CO3)2 = Ca+2 + Mg+2 + 2 CO3-2 + log_k -17.090 + delta_h -9.436 kcal + +Siderite + FeCO3 = Fe+2 + CO3-2 + log_k -10.890 + delta_h -2.480 kcal + +Rhodochrosite + MnCO3 = Mn+2 + CO3-2 + log_k -11.130 + delta_h -1.430 kcal + +Strontianite + SrCO3 = Sr+2 + CO3-2 + log_k -9.271 + delta_h -0.400 kcal + -analytic 155.0305 0.0 -7239.594 -56.58638 + +Witherite + BaCO3 = Ba+2 + CO3-2 + log_k -8.562 + delta_h 0.703 kcal + -analytic 607.642 0.121098 -20011.25 -236.4948 + +Gypsum + CaSO4:2H2O = Ca+2 + SO4-2 + 2 H2O + log_k -4.580 + delta_h -0.109 kcal + -analytic 68.2401 0.0 -3221.51 -25.0627 + +Anhydrite + CaSO4 = Ca+2 + SO4-2 + log_k -4.360 + delta_h -1.710 kcal + -analytic 197.52 0.0 -8669.8 -69.835 + +Celestite + SrSO4 = Sr+2 + SO4-2 + log_k -6.630 + delta_h -1.037 kcal + -analytic -14805.9622 -2.4660924 756968.533 5436.3588 -40553604.0 + +Barite + BaSO4 = Ba+2 + SO4-2 + log_k -9.970 + delta_h 6.350 kcal + -analytic 136.035 0.0 -7680.41 -48.595 + +Hydroxyapatite + Ca5(PO4)3OH + 4 H+ = H2O + 3 HPO4-2 + 5 Ca+2 + log_k -3.421 + delta_h -36.155 kcal + +Fluorite + CaF2 = Ca+2 + 2 F- + log_k -10.600 + delta_h 4.690 kcal + -analytic 66.348 0.0 -4298.2 -25.271 + +SiO2(a) + SiO2 + 2 H2O = H4SiO4 + log_k -2.710 + delta_h 3.340 kcal + -analytic -0.26 0.0 -731.0 + +Chalcedony + SiO2 + 2 H2O = H4SiO4 + log_k -3.550 + delta_h 4.720 kcal + -analytic -0.09 0.0 -1032.0 + +Quartz + SiO2 + 2 H2O = H4SiO4 + log_k -3.980 + delta_h 5.990 kcal + -analytic 0.41 0.0 -1309.0 + +Gibbsite + Al(OH)3 + 3 H+ = Al+3 + 3 H2O + log_k 8.110 + delta_h -22.800 kcal + +Al(OH)3(a) + Al(OH)3 + 3 H+ = Al+3 + 3 H2O + log_k 10.800 + delta_h -26.500 kcal + +Kaolinite + Al2Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 2 Al+3 + log_k 7.435 + delta_h -35.300 kcal + +Albite + NaAlSi3O8 + 8 H2O = Na+ + Al(OH)4- + 3 H4SiO4 + log_k -18.002 + delta_h 25.896 kcal + +Anorthite + CaAl2Si2O8 + 8 H2O = Ca+2 + 2 Al(OH)4- + 2 H4SiO4 + log_k -19.714 + delta_h 11.580 kcal + +K-feldspar + KAlSi3O8 + 8 H2O = K+ + Al(OH)4- + 3 H4SiO4 + log_k -20.573 + delta_h 30.820 kcal + +K-mica + KAl3Si3O10(OH)2 + 10 H+ = K+ + 3 Al+3 + 3 H4SiO4 + log_k 12.703 + delta_h -59.376 kcal + +Chlorite(14A) + Mg5Al2Si3O10(OH)8 + 16H+ = 5Mg+2 + 2Al+3 + 3H4SiO4 + 6H2O + log_k 68.38 + delta_h -151.494 kcal + +Ca-Montmorillonite + Ca0.165Al2.33Si3.67O10(OH)2 + 12 H2O = 0.165Ca+2 + 2.33 Al(OH)4- + 3.67 H4SiO4 + 2 H+ + log_k -45.027 + delta_h 58.373 kcal + +Talc + Mg3Si4O10(OH)2 + 4 H2O + 6 H+ = 3 Mg+2 + 4 H4SiO4 + log_k 21.399 + delta_h -46.352 kcal + +Illite + K0.6Mg0.25Al2.3Si3.5O10(OH)2 + 11.2H2O = 0.6K+ + 0.25Mg+2 + 2.3Al(OH)4- + 3.5H4SiO4 + 1.2H+ + log_k -40.267 + delta_h 54.684 kcal + +Chrysotile + Mg3Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 3 Mg+2 + log_k 32.200 + delta_h -46.800 kcal + -analytic 13.248 0.0 10217.1 -6.1894 + +Sepiolite + Mg2Si3O7.5OH:3H2O + 4 H+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + log_k 15.760 + delta_h -10.700 kcal + +Sepiolite(d) + Mg2Si3O7.5OH:3H2O + 4 H+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + log_k 18.660 + +Hematite + Fe2O3 + 6 H+ = 2 Fe+3 + 3 H2O + log_k -4.008 + delta_h -30.845 kcal + +Goethite + FeOOH + 3 H+ = Fe+3 + 2 H2O + log_k -1.000 + delta_h -14.48 kcal + +Fe(OH)3(a) + Fe(OH)3 + 3 H+ = Fe+3 + 3 H2O + log_k 4.891 + +Pyrite + FeS2 + 2 H+ + 2 e- = Fe+2 + 2 HS- + log_k -18.479 + delta_h 11.300 kcal + +FeS(ppt) + FeS + H+ = Fe+2 + HS- + log_k -3.915 + +Mackinawite + FeS + H+ = Fe+2 + HS- + log_k -4.648 + +Sulfur + S + 2H+ + 2e- = H2S + log_k 4.882 + delta_h -9.5 kcal + +Vivianite + Fe3(PO4)2:8H2O = 3 Fe+2 + 2 PO4-3 + 8 H2O + log_k -36.000 + +Pyrolusite + MnO2 + 4 H+ + 2 e- = Mn+2 + 2 H2O + log_k 41.380 + delta_h -65.110 kcal + +Hausmannite + Mn3O4 + 8 H+ + 2 e- = 3 Mn+2 + 4 H2O + log_k 61.030 + delta_h -100.640 kcal + +Manganite + MnOOH + 3 H+ + e- = Mn+2 + 2 H2O + log_k 25.340 + +Pyrochroite + Mn(OH)2 + 2 H+ = Mn+2 + 2 H2O + log_k 15.200 + +Halite + NaCl = Na+ + Cl- + log_k 1.582 + delta_h 0.918 kcal + +CO2(g) + CO2 = CO2 + log_k -1.468 + delta_h -4.776 kcal + -analytic 108.3865 0.01985076 -6919.53 -40.45154 669365.0 + +O2(g) + O2 = O2 + log_k -2.960 + delta_h -1.844 kcal + +H2(g) + H2 = H2 + log_k -3.150 + delta_h -1.759 kcal + +H2O(g) + H2O = H2O + log_k 1.51 + delta_h -44.03 kJ +# Stumm and Morgan, from NBS and Robie, Hemmingway, and Fischer (1978) + +N2(g) + N2 = N2 + log_k -3.260 + delta_h -1.358 kcal + +H2S(g) + H2S = H2S + log_k -0.997 + delta_h -4.570 kcal + +CH4(g) + CH4 = CH4 + log_k -2.860 + delta_h -3.373 kcal + +NH3(g) + NH3 = NH3 + log_k 1.770 + delta_h -8.170 kcal + +Melanterite + FeSO4:7H2O = 7 H2O + Fe+2 + SO4-2 + log_k -2.209 + delta_h 4.910 kcal + -analytic 1.447 -0.004153 0.0 0.0 -214949.0 + +Alunite + KAl3(SO4)2(OH)6 + 6 H+ = K+ + 3 Al+3 + 2 SO4-2 + 6H2O + log_k -1.400 + delta_h -50.250 kcal + +Jarosite-K + KFe3(SO4)2(OH)6 + 6 H+ = 3 Fe+3 + 6 H2O + K+ + 2 SO4-2 + log_k -9.210 + delta_h -31.280 kcal + +Zn(OH)2(e) + Zn(OH)2 + 2 H+ = Zn+2 + 2 H2O + log_k 11.50 + +Smithsonite + ZnCO3 = Zn+2 + CO3-2 + log_k -10.000 + delta_h -4.36 kcal + +Sphalerite + ZnS + H+ = Zn+2 + HS- + log_k -11.618 + delta_h 8.250 kcal + +Willemite 289 + Zn2SiO4 + 4H+ = 2Zn+2 + H4SiO4 + log_k 15.33 + delta_h -33.37 kcal + +Cd(OH)2 + Cd(OH)2 + 2 H+ = Cd+2 + 2 H2O + log_k 13.650 + +Otavite 315 + CdCO3 = Cd+2 + CO3-2 + log_k -12.1 + delta_h -0.019 kcal + +CdSiO3 328 + CdSiO3 + H2O + 2H+ = Cd+2 + H4SiO4 + log_k 9.06 + delta_h -16.63 kcal + +CdSO4 329 + CdSO4 = Cd+2 + SO4-2 + log_k -0.1 + delta_h -14.74 kcal + +Cerrusite 365 + PbCO3 = Pb+2 + CO3-2 + log_k -13.13 + delta_h 4.86 kcal + +Anglesite 384 + PbSO4 = Pb+2 + SO4-2 + log_k -7.79 + delta_h 2.15 kcal + +Pb(OH)2 389 + Pb(OH)2 + 2H+ = Pb+2 + 2H2O + log_k 8.15 + delta_h -13.99 kcal + +EXCHANGE_MASTER_SPECIES + X X- +EXCHANGE_SPECIES + X- = X- + log_k 0.0 + + Na+ + X- = NaX + log_k 0.0 + -gamma 4.0 0.075 + + K+ + X- = KX + log_k 0.7 + -gamma 3.5 0.015 + delta_h -4.3 # Jardine & Sparks, 1984 + + Li+ + X- = LiX + log_k -0.08 + -gamma 6.0 0.0 + delta_h 1.4 # Merriam & Thomas, 1956 + + NH4+ + X- = NH4X + log_k 0.6 + -gamma 2.5 0.0 + delta_h -2.4 # Laudelout et al., 1968 + + Ca+2 + 2X- = CaX2 + log_k 0.8 + -gamma 5.0 0.165 + delta_h 7.2 # Van Bladel & Gheyl, 1980 + + Mg+2 + 2X- = MgX2 + log_k 0.6 + -gamma 5.5 0.2 + delta_h 7.4 # Laudelout et al., 1968 + + Sr+2 + 2X- = SrX2 + log_k 0.91 + -gamma 5.26 0.121 + delta_h 5.5 # Laudelout et al., 1968 + + Ba+2 + 2X- = BaX2 + log_k 0.91 + -gamma 5.0 0.0 + delta_h 4.5 # Laudelout et al., 1968 + + Mn+2 + 2X- = MnX2 + log_k 0.52 + -gamma 6.0 0.0 + + Fe+2 + 2X- = FeX2 + log_k 0.44 + -gamma 6.0 0.0 + + Cu+2 + 2X- = CuX2 + log_k 0.6 + -gamma 6.0 0.0 + + Zn+2 + 2X- = ZnX2 + log_k 0.8 + -gamma 5.0 0.0 + + Cd+2 + 2X- = CdX2 + log_k 0.8 + + Pb+2 + 2X- = PbX2 + log_k 1.05 + + Al+3 + 3X- = AlX3 + log_k 0.41 + -gamma 9.0 0.0 + + AlOH+2 + 2X- = AlOHX2 + log_k 0.89 + -gamma 0.0 0.0 +SURFACE_MASTER_SPECIES + Hfo_s Hfo_sOH + Hfo_w Hfo_wOH +SURFACE_SPECIES +# All surface data from +# Dzombak and Morel, 1990 +# +# +# Acid-base data from table 5.7 +# +# strong binding site--Hfo_s, + + Hfo_sOH = Hfo_sOH + log_k 0.0 + + Hfo_sOH + H+ = Hfo_sOH2+ + log_k 7.29 # = pKa1,int + + Hfo_sOH = Hfo_sO- + H+ + log_k -8.93 # = -pKa2,int + +# weak binding site--Hfo_w + + Hfo_wOH = Hfo_wOH + log_k 0.0 + + Hfo_wOH + H+ = Hfo_wOH2+ + log_k 7.29 # = pKa1,int + + Hfo_wOH = Hfo_wO- + H+ + log_k -8.93 # = -pKa2,int + +############################################### +# CATIONS # +############################################### +# +# Cations from table 10.1 or 10.5 +# +# Calcium + Hfo_sOH + Ca+2 = Hfo_sOHCa+2 + log_k 4.97 + + Hfo_wOH + Ca+2 = Hfo_wOCa+ + H+ + log_k -5.85 +# Strontium + Hfo_sOH + Sr+2 = Hfo_sOHSr+2 + log_k 5.01 + + Hfo_wOH + Sr+2 = Hfo_wOSr+ + H+ + log_k -6.58 + + Hfo_wOH + Sr+2 + H2O = Hfo_wOSrOH + 2H+ + log_k -17.60 +# Barium + Hfo_sOH + Ba+2 = Hfo_sOHBa+2 + log_k 5.46 + + Hfo_wOH + Ba+2 = Hfo_wOBa+ + H+ + log_k -7.2 # table 10.5 +# +# Cations from table 10.2 +# +# Cadmium + Hfo_sOH + Cd+2 = Hfo_sOCd+ + H+ + log_k 0.47 + + Hfo_wOH + Cd+2 = Hfo_wOCd+ + H+ + log_k -2.91 +# Zinc + Hfo_sOH + Zn+2 = Hfo_sOZn+ + H+ + log_k 0.99 + + Hfo_wOH + Zn+2 = Hfo_wOZn+ + H+ + log_k -1.99 +# Copper + Hfo_sOH + Cu+2 = Hfo_sOCu+ + H+ + log_k 2.89 + + Hfo_wOH + Cu+2 = Hfo_wOCu+ + H+ + log_k 0.6 # table 10.5 +# Lead + Hfo_sOH + Pb+2 = Hfo_sOPb+ + H+ + log_k 4.65 + + Hfo_wOH + Pb+2 = Hfo_wOPb+ + H+ + log_k 0.3 # table 10.5 +# +# Derived constants table 10.5 +# +# Magnesium + Hfo_wOH + Mg+2 = Hfo_wOMg+ + H+ + log_k -4.6 +# Manganese + Hfo_sOH + Mn+2 = Hfo_sOMn+ + H+ + log_k -0.4 # table 10.5 + + Hfo_wOH + Mn+2 = Hfo_wOMn+ + H+ + log_k -3.5 # table 10.5 +# Iron +# Hfo_sOH + Fe+2 = Hfo_sOFe+ + H+ +# log_k 0.7 # LFER using table 10.5 + +# Hfo_wOH + Fe+2 = Hfo_wOFe+ + H+ +# log_k -2.5 # LFER using table 10.5 + +# Iron, strong site: Appelo, Van der Weiden, Tournassat & Charlet, subm. + Hfo_sOH + Fe+2 = Hfo_sOFe+ + H+ + log_k -0.95 +# Iron, weak site: Liger et al., GCA 63, 2939, re-optimized for D&M + Hfo_wOH + Fe+2 = Hfo_wOFe+ + H+ + log_k -2.98 + + Hfo_wOH + Fe+2 + H2O = Hfo_wOFeOH + 2H+ + log_k -11.55 + +############################################### +# ANIONS # +############################################### +# +# Anions from table 10.6 +# +# Phosphate + Hfo_wOH + PO4-3 + 3H+ = Hfo_wH2PO4 + H2O + log_k 31.29 + + Hfo_wOH + PO4-3 + 2H+ = Hfo_wHPO4- + H2O + log_k 25.39 + + Hfo_wOH + PO4-3 + H+ = Hfo_wPO4-2 + H2O + log_k 17.72 +# +# Anions from table 10.7 +# +# Borate + Hfo_wOH + H3BO3 = Hfo_wH2BO3 + H2O + log_k 0.62 +# +# Anions from table 10.8 +# +# Sulfate + Hfo_wOH + SO4-2 + H+ = Hfo_wSO4- + H2O + log_k 7.78 + + Hfo_wOH + SO4-2 = Hfo_wOHSO4-2 + log_k 0.79 +# +# Derived constants table 10.10 +# + Hfo_wOH + F- + H+ = Hfo_wF + H2O + log_k 8.7 + + Hfo_wOH + F- = Hfo_wOHF- + log_k 1.6 +# +# Carbonate: Van Geen et al., 1994 reoptimized for HFO +# 0.15 g HFO/L has 0.344 mM sites == 2 g of Van Geen's Goethite/L +# +# Hfo_wOH + CO3-2 + H+ = Hfo_wCO3- + H2O +# log_k 12.56 +# +# Hfo_wOH + CO3-2 + 2H+= Hfo_wHCO3 + H2O +# log_k 20.62 + +# 9/19/96 +# Added analytical expression for H2S, NH3, KSO4. +# Added species CaHSO4+. +# Added delta H for Goethite. + +RATES + +########### +#K-feldspar +########### +# +# Sverdrup, H.U., 1990, The kinetics of base cation release due to +# chemical weathering: Lund University Press, Lund, 246 p. +# +# Example of KINETICS data block for K-feldspar rate: +# KINETICS 1 +# K-feldspar +# -m0 2.16 # 10% K-fsp, 0.1 mm cubes +# -m 1.94 +# -parms 1.36e4 0.1 + +K-feldspar + -start + 1 rem specific rate from Sverdrup, 1990, in kmol/m2/s + 2 rem parm(1) = 10 * (A/V, 1/dm) (recalc's sp. rate to mol/kgw) + 3 rem parm(2) = corrects for field rate relative to lab rate + 4 rem temp corr: from p. 162. E (kJ/mol) / R / 2.303 = H in H*(1/T-1/298) + + 10 dif_temp = 1/TK - 1/298 + 20 pk_H = 12.5 + 3134 * dif_temp + 30 pk_w = 15.3 + 1838 * dif_temp + 40 pk_OH = 14.2 + 3134 * dif_temp + 50 pk_CO2 = 14.6 + 1677 * dif_temp + #60 pk_org = 13.9 + 1254 * dif_temp # rate increase with DOC + 70 rate = 10^-pk_H * ACT("H+")^0.5 + 10^-pk_w + 10^-pk_OH * ACT("OH-")^0.3 + 71 rate = rate + 10^-pk_CO2 * (10^SI("CO2(g)"))^0.6 + #72 rate = rate + 10^-pk_org * TOT("Doc")^0.4 + 80 moles = parm(1) * parm(2) * rate * (1 - SR("K-feldspar")) * time + 81 rem decrease rate on precipitation + 90 if SR("K-feldspar") > 1 then moles = moles * 0.1 + 100 save moles + -end + +########### +#Albite +########### +# +# Sverdrup, H.U., 1990, The kinetics of base cation release due to +# chemical weathering: Lund University Press, Lund, 246 p. +# +# Example of KINETICS data block for Albite rate: +# KINETICS 1 +# Albite +# -m0 0.43 # 2% Albite, 0.1 mm cubes +# -parms 2.72e3 0.1 + +Albite + -start + 1 rem specific rate from Sverdrup, 1990, in kmol/m2/s + 2 rem parm(1) = 10 * (A/V, 1/dm) (recalc's sp. rate to mol/kgw) + 3 rem parm(2) = corrects for field rate relative to lab rate + 4 rem temp corr: from p. 162. E (kJ/mol) / R / 2.303 = H in H*(1/T-1/298) + + 10 dif_temp = 1/TK - 1/298 + 20 pk_H = 12.5 + 3359 * dif_temp + 30 pk_w = 14.8 + 2648 * dif_temp + 40 pk_OH = 13.7 + 3359 * dif_temp + #41 rem ^12.9 in Sverdrup, but larger than for oligoclase... + 50 pk_CO2 = 14.0 + 1677 * dif_temp + #60 pk_org = 12.5 + 1254 * dif_temp # ...rate increase for DOC + 70 rate = 10^-pk_H * ACT("H+")^0.5 + 10^-pk_w + 10^-pk_OH * ACT("OH-")^0.3 + 71 rate = rate + 10^-pk_CO2 * (10^SI("CO2(g)"))^0.6 + #72 rate = rate + 10^-pk_org * TOT("Doc")^0.4 + 80 moles = parm(1) * parm(2) * rate * (1 - SR("Albite")) * time + 81 rem decrease rate on precipitation + 90 if SR("Albite") > 1 then moles = moles * 0.1 + 100 save moles + -end + +######## +#Calcite +######## +# +# Plummer, L.N., Wigley, T.M.L., and Parkhurst, D.L., 1978, +# American Journal of Science, v. 278, p. 179-216. +# +# Example of KINETICS data block for calcite rate: +# +# KINETICS 1 +# Calcite +# -tol 1e-8 +# -m0 3.e-3 +# -m 3.e-3 +# -parms 5.0 0.6 +Calcite + -start + 1 REM Modified from Plummer and others, 1978 + 2 REM M = current moles of calcite + 3 REM M0 = initial moles of calcite + 4 REM parm(1) = Area/Volume, cm^2/L (or cm^2 per cell) + 5 REM parm(2) = exponent for M/M0 for surface area correction + 10 REM rate = 0 if no calcite and undersaturated + 20 si_cc = SI("Calcite") + 30 if (M <= 0 and si_cc < 0) then goto 300 + 40 k1 = 10^(0.198 - 444.0 / TK ) + 50 k2 = 10^(2.84 - 2177.0 / TK ) + 60 if TC <= 25 then k3 = 10^(-5.86 - 317.0 / TK ) + 70 if TC > 25 then k3 = 10^(-1.1 - 1737.0 / TK ) + 80 REM surface area calculation + 90 t = 1 + 100 if M0 > 0 then t = M/M0 + 110 if t = 0 then t = 1 + 120 area = PARM(1) * (t)^PARM(2) + 130 rf = k1 * ACT("H+") + k2 * ACT("CO2") + k3 * ACT("H2O") + 140 REM 1e-3 converts mmol to mol + 150 rate = area * 1e-3 * rf * (1 - 10^(2/3*si_cc)) + 160 moles = rate * TIME + 170 REM do not dissolve more calcite than present + 180 if (moles > M) then moles = M + 190 if (moles >= 0) then goto 300 + 200 REM do not precipitate more Ca or C(4) than present + 210 temp = TOT("Ca") + 220 mc = TOT("C(4)") + 230 if mc < temp then temp = mc + 240 if -moles > temp then moles = -temp + 300 SAVE moles + -end + +####### +#Pyrite +####### +# +# Williamson, M.A. and Rimstidt, J.D., 1994, +# Geochimica et Cosmochimica Acta, v. 58, p. 5443-5454. +# +# Example of KINETICS data block for pyrite rate: +# KINETICS 1 +# Pyrite +# -tol 1e-8 +# -m0 5.e-4 +# -m 5.e-4 +# -parms 2.0 0.67 .5 -0.11 +Pyrite + -start + 1 rem Williamson and Rimstidt, 1994 + 2 rem parm(1) = log10(A/V, 1/dm) parm(2) = exp for (m/m0) + 3 rem parm(3) = exp for O2 parm(4) = exp for H+ + + 10 if (m <= 0) then goto 200 + 20 if (si("Pyrite") >= 0) then goto 200 + 20 rate = -10.19 + parm(1) + parm(3)*lm("O2") + parm(4)*lm("H+") + parm(2)*log10(m/m0) + 30 moles = 10^rate * time + 40 if (moles > m) then moles = m + 200 save moles + -end + +########## +#Organic_C +########## +# +# Example of KINETICS data block for Organic_C rate: +# KINETICS 1 +# Organic_C +# -tol 1e-8 +# # m in mol/kgw +# -m0 5e-3 +# -m 5e-3 +Organic_C + -start + 1 rem Additive Monod kinetics + 2 rem Electron acceptors: O2, NO3, and SO4 + + 10 if (m <= 0) then goto 200 + 20 mO2 = mol("O2") + 30 mNO3 = tot("N(5)") + 40 mSO4 = tot("S(6)") + 50 rate = 1.57e-9*mO2/(2.94e-4 + mO2) + 1.67e-11*mNO3/(1.55e-4 + mNO3) + 60 rate = rate + 1.e-13*mSO4/(1.e-4 + mSO4) + 70 moles = rate * m * (m/m0) * time + 80 if (moles > m) then moles = m + 200 save moles + -end + +########### +#Pyrolusite +########### +# +# Postma, D. and Appelo, C.A.J., 2000, GCA 64, in press +# +# Example of KINETICS data block for Pyrolusite +# KINETICS 1-12 +# Pyrolusite +# -tol 1.e-7 +# -m0 0.1 +# -m 0.1 +Pyrolusite + -start + 5 if (m <= 0.0) then goto 200 + 7 sr_pl = sr("Pyrolusite") + 9 if abs(1 - sr_pl) < 0.1 then goto 200 + 10 if (sr_pl > 1.0) then goto 100 + #20 rem initially 1 mol Fe+2 = 0.5 mol pyrolusite. k*A/V = 1/time (3 cells) + #22 rem time (3 cells) = 1.432e4. 1/time = 6.98e-5 + 30 Fe_t = tot("Fe(2)") + 32 if Fe_t < 1.e-8 then goto 200 + 40 moles = 6.98e-5 * Fe_t * (m/m0)^0.67 * time * (1 - sr_pl) + 50 if moles > Fe_t / 2 then moles = Fe_t / 2 + 70 if moles > m then moles = m + 90 goto 200 + 100 Mn_t = tot("Mn") + 110 moles = 2e-3 * 6.98e-5 * (1-sr_pl) * time + 120 if moles <= -Mn_t then moles = -Mn_t + 200 save moles + -end +END diff --git a/phreeqc.rev b/phreeqc.rev new file mode 100644 index 00000000..8dc8253f --- /dev/null +++ b/phreeqc.rev @@ -0,0 +1,4579 @@ + +RCS file: RCS/README.TXT,v +Working file: README.TXT +head: 1.17 +branch: +locks: strict +access list: +symbolic names: +keyword substitution: kv +total revisions: 17 +============================================================================= + +RCS file: RCS/NOTICE.TXT,v +Working file: NOTICE.TXT +head: 1.1 +branch: +locks: strict +access list: +symbolic names: +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: RCS/RELEASE.TXT,v +Working file: RELEASE.TXT +head: 1.16 +branch: +locks: strict + dlpark: 1.16 +access list: +symbolic names: +keyword substitution: kv +total revisions: 16 +============================================================================= + +RCS file: src/RCS/Makefile,v +Working file: src/Makefile +head: 1.35 +branch: +locks: strict +access list: +symbolic names: + C_260: 1.33 + C_259: 1.33 + C_258: 1.33 + C_257: 1.31 + C_256: 1.31 + C_255: 1.31 + C_254: 1.30 + C_253: 1.26 + C_252: 1.25 + C_251: 1.25 + C_250: 1.25 + C_249: 1.24 + C_248: 1.24 + C_247: 1.24 + C_246: 1.24 + C_245: 1.24 + C_244: 1.24 + C_243: 1.24 + C_242: 1.23 + C_241: 1.22 + C_240: 1.22 + C_239: 1.22 + C_238: 1.22 + C_237: 1.22 + C_236: 1.22 + C_235: 1.22 + C_234: 1.22 + C_233: 1.22 + C_232: 1.22 + C_231: 1.22 + C_230: 1.22 + C_229: 1.22 + C_227: 1.22 + C_226: 1.22 + C_225: 1.22 + C_224: 1.22 + C_222: 1.21 + C_221: 1.21 + C_220: 1.21 + C_219: 1.21 + C_218: 1.21 + RC1: 1.20 + C_216: 1.20 + C_215: 1.20 + C_214: 1.20 + C_213: 1.20 + C_212: 1.20 + C_206: 1.18 + C_205_3: 1.15 + C_205_2: 1.15 + C_205_1: 1.15 + C_205: 1.15 + C_204_2: 1.14 + C_204_1: 1.14 + C_204: 1.14 + C_202: 1.10 + C_201: 1.5 + C_200: 1.5 +keyword substitution: kv +total revisions: 35 +============================================================================= + +RCS file: src/RCS/advection.c,v +Working file: src/advection.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.5 + C_246: 2.5 + C_245: 2.5 + C_244: 2.5 + C_243: 2.5 + C_242: 2.4 + C_241: 2.4 + C_240: 2.4 + C_239: 2.4 + C_238: 2.3 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/basic.c,v +Working file: src/basic.c +head: 2.44 +branch: +locks: strict + dlpark: 2.44 +access list: +symbolic names: + C_260: 2.44 + C_259: 2.44 + C_258: 2.44 + C_257: 2.44 + C_256: 2.43 + C_255: 2.43 + C_254: 2.43 + C_253: 2.42 + C_252: 2.42 + C_251: 2.42 + C_250: 2.42 + C_249: 2.41 + C_248: 2.41 + C_247: 2.41 + C_246: 2.41 + C_245: 2.41 + C_244: 2.41 + C_243: 2.41 + C_242: 2.39 + C_241: 2.39 + C_240: 2.39 + C_239: 2.39 + C_238: 2.38 + C_237: 2.37 + C_236: 2.37 + C_235: 2.37 + C_234: 2.37 + C_233: 2.36 + C_232: 2.34 + C_231: 2.33 + C_230: 2.30 + C_229: 2.30 + C_227: 2.30 + C_226: 2.30 + C_225: 2.30 + C_224: 2.30 + C_222: 2.30 + C_221: 2.20 + C_220: 2.20 + C_219: 2.19 + C_218: 2.19 + RC1: 2.19 + C_216: 2.19 + C_215: 2.18 + C_214: 2.17 + C_213: 2.17 + C_212: 2.16 + C_206: 2.16 + C_205_3: 2.14 + C_205_2: 2.14 + C_205_1: 2.13 + C_205: 2.11 + C_204_2: 2.11 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.10 + C_202_1: 2.10 + C_202: 2.6 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 45 +============================================================================= + +RCS file: src/RCS/basicsubs.c,v +Working file: src/basicsubs.c +head: 2.18 +branch: +locks: strict + dlpark: 2.18 +access list: +symbolic names: + C_260: 2.18 + C_259: 2.18 + C_258: 2.18 + C_257: 2.18 + C_256: 2.17 + C_255: 2.17 + C_254: 2.17 + C_253: 2.16 + C_252: 2.16 + C_251: 2.15 + C_250: 2.15 + C_249: 2.14 + C_248: 2.14 + C_247: 2.14 + C_246: 2.14 + C_245: 2.14 + C_244: 2.14 + C_243: 2.14 + C_242: 2.13 + C_241: 2.13 + C_240: 2.13 + C_239: 2.13 + C_238: 2.12 + C_237: 2.12 + C_236: 2.12 + C_235: 2.12 + C_234: 2.12 + C_233: 2.11 + C_232: 2.9 + C_231: 2.9 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.6 + C_222: 2.6 + C_221: 2.6 + C_220: 2.6 + C_219: 2.6 + C_218: 2.6 + RC1: 2.6 + C_216: 2.6 + C_215: 2.6 + C_214: 2.5 + C_213: 2.4 + C_212: 2.3 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.1 + C_205_1: 2.1 +keyword substitution: kv +total revisions: 18 +============================================================================= + +RCS file: src/RCS/cl1.c,v +Working file: src/cl1.c +head: 2.7 +branch: +locks: strict + dlpark: 2.7 +access list: +symbolic names: + C_260: 2.7 + C_259: 2.7 + C_258: 2.7 + C_257: 2.6 + C_256: 2.5 + C_255: 2.5 + C_254: 2.5 + C_253: 2.5 + C_252: 2.5 + C_251: 2.5 + C_250: 2.5 + C_249: 2.4 + C_248: 2.4 + C_247: 2.4 + C_246: 2.4 + C_245: 2.4 + C_244: 2.4 + C_243: 2.4 + C_242: 2.3 + C_241: 2.3 + C_240: 2.3 + C_239: 2.2 + C_238: 2.1 + C_237: 2.1 + C_236: 2.1 + C_235: 2.1 + C_234: 2.1 + C_233: 2.1 + C_232: 2.1 + C_231: 2.1 + C_230: 2.1 + C_229: 2.1 + C_227: 2.1 + C_226: 2.1 + C_225: 2.1 + C_224: 2.1 + C_222: 2.1 + C_221: 2.1 + C_220: 2.1 + C_219: 2.1 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: src/RCS/cvdense.c,v +Working file: src/cvdense.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 + C_225: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/cvode.c,v +Working file: src/cvode.c +head: 1.10 +branch: +locks: strict +access list: +symbolic names: + C_260: 1.10 + C_259: 1.9 + C_258: 1.9 + C_257: 1.9 + C_256: 1.8 + C_255: 1.8 + C_254: 1.8 + C_253: 1.8 + C_252: 1.8 + C_251: 1.8 + C_250: 1.7 + C_249: 1.6 + C_248: 1.6 + C_247: 1.6 + C_246: 1.6 + C_245: 1.6 + C_244: 1.6 + C_243: 1.6 + C_242: 1.4 + C_241: 1.4 + C_240: 1.4 + C_239: 1.4 + C_238: 1.2 + C_237: 1.2 + C_236: 1.2 + C_235: 1.2 + C_234: 1.2 + C_233: 1.2 + C_232: 1.2 + C_231: 1.2 + C_230: 1.2 + C_229: 1.2 + C_227: 1.2 + C_226: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: src/RCS/dense.c,v +Working file: src/dense.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/input.c,v +Working file: src/input.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.1 + C_254: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/integrate.c,v +Working file: src/integrate.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.4 + C_237: 2.4 + C_236: 2.4 + C_235: 2.4 + C_234: 2.4 + C_233: 2.4 + C_232: 2.4 + C_231: 2.4 + C_230: 2.4 + C_229: 2.4 + C_227: 2.4 + C_226: 2.4 + C_225: 2.4 + C_224: 2.3 + C_222: 2.3 + C_221: 2.3 + C_220: 2.3 + C_219: 2.3 + C_218: 2.3 + RC1: 2.3 + C_216: 2.3 + C_215: 2.3 + C_214: 2.3 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/inverse.c,v +Working file: src/inverse.c +head: 2.10 +branch: +locks: strict + dlpark: 2.10 +access list: +symbolic names: + C_260: 2.10 + C_259: 2.10 + C_258: 2.10 + C_257: 2.10 + C_256: 2.9 + C_255: 2.9 + C_254: 2.9 + C_253: 2.8 + C_252: 2.8 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.4 + C_241: 2.4 + C_240: 2.4 + C_239: 2.4 + C_238: 2.3 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.1 + C_206: 2.1 + C_205_3: 2.1 + C_205_2: 2.1 + C_205_1: 2.1 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: src/RCS/isotopes.c,v +Working file: src/isotopes.c +head: 2.12 +branch: +locks: strict + dlpark: 2.12 +access list: +symbolic names: + C_260: 2.12 + C_259: 2.12 + C_258: 2.12 + C_257: 2.12 + C_256: 2.11 + C_255: 2.11 + C_254: 2.11 + C_253: 2.11 + C_252: 2.11 + C_251: 2.11 + C_250: 2.10 + C_249: 2.9 + C_248: 2.9 + C_247: 2.9 + C_246: 2.9 + C_245: 2.9 + C_244: 2.9 + C_243: 2.9 + C_242: 2.8 + C_241: 2.8 + C_240: 2.8 + C_239: 2.8 + C_238: 2.7 + C_237: 2.7 + C_236: 2.7 + C_235: 2.7 + C_234: 2.7 + C_233: 2.7 + C_232: 2.7 + C_231: 2.7 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.7 + C_222: 2.7 + C_221: 2.7 + C_220: 2.7 + C_219: 2.7 + C_218: 2.7 + RC1: 2.7 + C_216: 2.7 + C_215: 2.7 + C_214: 2.7 + C_213: 2.7 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.2 + C_205_2: 2.1 + C_205_1: 2.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: src/RCS/kinetics.c,v +Working file: src/kinetics.c +head: 2.36 +branch: +locks: strict + dlpark: 2.36 +access list: +symbolic names: + C_260: 2.36 + C_259: 2.36 + C_258: 2.36 + C_257: 2.33 + C_256: 2.32 + C_255: 2.31 + C_254: 2.31 + C_253: 2.30 + C_252: 2.30 + C_251: 2.29 + C_250: 2.29 + C_249: 2.28 + C_248: 2.28 + C_247: 2.26 + C_246: 2.26 + C_245: 2.26 + C_244: 2.26 + C_243: 2.26 + C_242: 2.24 + C_241: 2.24 + C_240: 2.24 + C_239: 2.23 + C_238: 2.22 + C_237: 2.22 + C_236: 2.22 + C_235: 2.22 + C_234: 2.21 + C_233: 2.21 + C_232: 2.21 + C_231: 2.21 + C_230: 2.21 + C_229: 2.21 + C_227: 2.21 + C_226: 2.20 + C_225: 2.19 + C_224: 2.19 + C_222: 2.19 + C_221: 2.19 + C_220: 2.19 + C_219: 2.18 + C_218: 2.17 + RC1: 2.17 + C_216: 2.17 + C_215: 2.17 + C_214: 2.17 + C_213: 2.17 + C_212: 2.16 + C_206: 2.16 + C_205_3: 2.16 + C_205_2: 2.16 + C_205_1: 2.15 + C_205: 2.11 + C_204_2: 2.7 + C_204_1: 2.7 + C_204: 2.7 + C_202_2: 2.6 + C_202_1: 2.6 + C_202: 2.4 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 37 +============================================================================= + +RCS file: src/RCS/main.c,v +Working file: src/main.c +head: 2.35 +branch: +locks: strict +access list: +symbolic names: + C_260: 2.35 + C_259: 2.34 + C_258: 2.34 + C_257: 2.34 + C_256: 2.33 + C_255: 2.33 + C_254: 2.32 + C_253: 2.31 + C_252: 2.30 + C_251: 2.30 + C_250: 2.30 + C_249: 2.29 + C_248: 2.29 + C_247: 2.29 + C_246: 2.29 + C_245: 2.29 + C_244: 2.28 + C_243: 2.28 + C_242: 2.26 + C_241: 2.25 + C_240: 2.25 + C_239: 2.25 + C_238: 2.25 + C_237: 2.24 + C_236: 2.24 + C_235: 2.24 + C_234: 2.23 + C_233: 2.23 + C_232: 2.23 + C_231: 2.23 + C_230: 2.23 + C_229: 2.23 + C_227: 2.23 + C_226: 2.23 + C_225: 2.23 + C_224: 2.23 + C_222: 2.22 + C_221: 2.22 + C_220: 2.22 + C_219: 2.22 + C_218: 2.20 + RC1: 2.19 + C_216: 2.19 + C_215: 2.18 + C_214: 2.18 + C_213: 2.18 + C_212: 2.14 + C_206: 2.14 + C_205_3: 2.13 + C_205_2: 2.13 + C_205_1: 2.13 + C_205: 2.13 + C_204_2: 2.12 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.9 + C_202_1: 2.6 + C_202: 2.4 + C_201: 2.2 + C_200: 2.1 +keyword substitution: kv +total revisions: 36 +============================================================================= + +RCS file: src/RCS/mainsubs.c,v +Working file: src/mainsubs.c +head: 2.38 +branch: +locks: strict + dlpark: 2.38 +access list: +symbolic names: + C_260: 2.38 + C_259: 2.38 + C_258: 2.38 + C_257: 2.36 + C_256: 2.35 + C_255: 2.35 + C_254: 2.34 + C_253: 2.33 + C_252: 2.33 + C_251: 2.32 + C_250: 2.32 + C_249: 2.31 + C_248: 2.31 + C_247: 2.30 + C_246: 2.30 + C_245: 2.30 + C_244: 2.30 + C_243: 2.30 + C_242: 2.28 + C_241: 2.28 + C_240: 2.28 + C_239: 2.27 + C_238: 2.25 + C_237: 2.24 + C_236: 2.24 + C_235: 2.24 + C_234: 2.23 + C_233: 2.23 + C_232: 2.23 + C_231: 2.23 + C_230: 2.23 + C_229: 2.23 + C_227: 2.22 + C_226: 2.22 + C_225: 2.22 + C_224: 2.22 + C_222: 2.22 + C_221: 2.22 + C_220: 2.22 + C_219: 2.22 + C_218: 2.21 + RC1: 2.21 + C_216: 2.21 + C_215: 2.21 + C_214: 2.20 + C_213: 2.20 + C_212: 2.17 + C_206: 2.15 + C_205_3: 2.14 + C_205_2: 2.13 + C_205_1: 2.12 + C_205: 2.11 + C_204_2: 2.10 + C_204_1: 2.10 + C_204: 2.10 + C_202_2: 2.6 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 39 +============================================================================= + +RCS file: src/RCS/model.c,v +Working file: src/model.c +head: 2.27 +branch: +locks: strict + dlpark: 2.27 +access list: +symbolic names: + C_260: 2.27 + C_259: 2.27 + C_258: 2.27 + C_257: 2.26 + C_256: 2.25 + C_255: 2.25 + C_254: 2.25 + C_253: 2.24 + C_252: 2.24 + C_251: 2.24 + C_250: 2.24 + C_249: 2.23 + C_248: 2.23 + C_247: 2.22 + C_246: 2.22 + C_245: 2.22 + C_244: 2.22 + C_243: 2.22 + C_242: 2.20 + C_241: 2.19 + C_240: 2.19 + C_239: 2.19 + C_238: 2.17 + C_237: 2.17 + C_236: 2.17 + C_235: 2.17 + C_234: 2.17 + C_233: 2.16 + C_232: 2.15 + C_231: 2.15 + C_230: 2.14 + C_229: 2.14 + C_227: 2.14 + C_226: 2.14 + C_225: 2.14 + C_224: 2.14 + C_222: 2.14 + C_221: 2.14 + C_220: 2.14 + C_219: 2.14 + C_218: 2.14 + RC1: 2.13 + C_216: 2.13 + C_215: 2.13 + C_214: 2.12 + C_213: 2.12 + C_212: 2.11 + C_206: 2.11 + C_205_3: 2.11 + C_205_2: 2.11 + C_205_1: 2.10 + C_205: 2.8 + C_204_2: 2.6 + C_204_1: 2.6 + C_204: 2.6 + C_202_2: 2.5 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 28 +============================================================================= + +RCS file: src/RCS/nvector.c,v +Working file: src/nvector.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/nvector_serial.c,v +Working file: src/nvector_serial.c +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_260: 1.5 + C_259: 1.5 + C_258: 1.5 + C_257: 1.5 + C_256: 1.4 + C_255: 1.4 + C_254: 1.4 + C_253: 1.4 + C_252: 1.4 + C_251: 1.4 + C_250: 1.4 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: src/RCS/output.c,v +Working file: src/output.c +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_260: 1.2 + C_259: 1.2 + C_258: 1.2 + C_257: 1.1 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: src/RCS/p2clib.c,v +Working file: src/p2clib.c +head: 2.6 +branch: +locks: strict + dlpark: 2.6 +access list: +symbolic names: + C_260: 2.6 + C_259: 2.6 + C_258: 2.6 + C_257: 2.6 + C_256: 2.5 + C_255: 2.5 + C_254: 2.5 + C_253: 2.5 + C_252: 2.5 + C_251: 2.5 + C_250: 2.5 + C_249: 2.5 + C_248: 2.5 + C_247: 2.5 + C_246: 2.5 + C_245: 2.5 + C_244: 2.5 + C_243: 2.5 + C_242: 2.3 + C_241: 2.3 + C_240: 2.3 + C_239: 2.3 + C_238: 2.3 + C_237: 2.3 + C_236: 2.3 + C_235: 2.3 + C_234: 2.3 + C_233: 2.3 + C_232: 2.3 + C_231: 2.3 + C_230: 2.3 + C_229: 2.3 + C_227: 2.3 + C_226: 2.3 + C_225: 2.3 + C_224: 2.3 + C_222: 2.3 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.1 + C_206: 2.1 + C_205_3: 2.1 + C_205_2: 2.1 + C_205_1: 2.1 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: src/RCS/parse.c,v +Working file: src/parse.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.4 + C_237: 2.4 + C_236: 2.4 + C_235: 2.4 + C_234: 2.4 + C_233: 2.4 + C_232: 2.4 + C_231: 2.4 + C_230: 2.4 + C_229: 2.4 + C_227: 2.4 + C_226: 2.4 + C_225: 2.4 + C_224: 2.4 + C_222: 2.4 + C_221: 2.4 + C_220: 2.4 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.4 + C_212: 2.3 + C_206: 2.3 + C_205_3: 2.3 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/phqalloc.c,v +Working file: src/phqalloc.c +head: 2.9 +branch: +locks: strict + dlpark: 2.9 +access list: +symbolic names: + C_260: 2.9 + C_259: 2.9 + C_258: 2.9 + C_257: 2.9 + C_256: 2.8 + C_255: 2.8 + C_254: 2.8 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.7 + C_248: 2.7 + C_247: 2.7 + C_246: 2.7 + C_245: 2.7 + C_244: 2.7 + C_243: 2.7 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.5 + C_237: 2.5 + C_236: 2.5 + C_235: 2.5 + C_234: 2.5 + C_233: 2.5 + C_232: 2.5 + C_231: 2.5 + C_230: 2.5 + C_229: 2.5 + C_227: 2.5 + C_226: 2.5 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.5 + C_218: 2.5 + RC1: 2.5 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.4 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.2 + C_204_1: 2.2 + C_204: 2.2 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: src/RCS/phreeqc_files.c,v +Working file: src/phreeqc_files.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.3 + C_257: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/prep.c,v +Working file: src/prep.c +head: 2.15 +branch: +locks: strict + dlpark: 2.15 +access list: +symbolic names: + C_260: 2.15 + C_259: 2.15 + C_258: 2.15 + C_257: 2.15 + C_256: 2.14 + C_255: 2.14 + C_254: 2.14 + C_253: 2.14 + C_252: 2.14 + C_251: 2.14 + C_250: 2.14 + C_249: 2.13 + C_248: 2.13 + C_247: 2.13 + C_246: 2.13 + C_245: 2.13 + C_244: 2.13 + C_243: 2.13 + C_242: 2.11 + C_241: 2.11 + C_240: 2.11 + C_239: 2.11 + C_238: 2.10 + C_237: 2.9 + C_236: 2.9 + C_235: 2.9 + C_234: 2.9 + C_233: 2.9 + C_232: 2.8 + C_231: 2.8 + C_230: 2.8 + C_229: 2.8 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.6 + C_222: 2.6 + C_221: 2.6 + C_220: 2.6 + C_219: 2.5 + C_218: 2.5 + RC1: 2.5 + C_216: 2.5 + C_215: 2.5 + C_214: 2.5 + C_213: 2.5 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.4 + C_205_2: 2.4 + C_205_1: 2.3 + C_205: 2.3 + C_204_2: 2.3 + C_204_1: 2.3 + C_204: 2.3 + C_202_2: 2.3 + C_202_1: 2.3 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 16 +============================================================================= + +RCS file: src/RCS/print.c,v +Working file: src/print.c +head: 2.38 +branch: +locks: strict + dlpark: 2.38 +access list: +symbolic names: + C_260: 2.38 + C_259: 2.38 + C_258: 2.38 + C_257: 2.38 + C_256: 2.37 + C_255: 2.36 + C_254: 2.35 + C_253: 2.34 + C_252: 2.34 + C_251: 2.32 + C_250: 2.32 + C_249: 2.31 + C_248: 2.31 + C_247: 2.31 + C_246: 2.31 + C_245: 2.31 + C_244: 2.31 + C_243: 2.31 + C_242: 2.30 + C_241: 2.30 + C_240: 2.30 + C_239: 2.30 + C_238: 2.29 + C_237: 2.29 + C_236: 2.29 + C_235: 2.28 + C_234: 2.27 + C_233: 2.27 + C_232: 2.27 + C_231: 2.27 + C_230: 2.27 + C_229: 2.27 + C_227: 2.27 + C_226: 2.27 + C_225: 2.26 + C_224: 2.26 + C_222: 2.26 + C_221: 2.25 + C_220: 2.25 + C_219: 2.24 + C_218: 2.24 + RC1: 2.24 + C_216: 2.24 + C_215: 2.24 + C_214: 2.21 + C_213: 2.20 + C_212: 2.15 + C_206: 2.15 + C_205_3: 2.11 + C_205_2: 2.10 + C_205_1: 2.9 + C_205: 2.8 + C_204_2: 2.7 + C_204_1: 2.7 + C_204: 2.7 + C_202_2: 2.5 + C_202_1: 2.4 + C_202: 2.4 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 39 +============================================================================= + +RCS file: src/RCS/read.c,v +Working file: src/read.c +head: 2.43 +branch: +locks: strict + dlpark: 2.43 +access list: +symbolic names: + C_260: 2.43 + C_259: 2.43 + C_258: 2.43 + C_257: 2.43 + C_256: 2.42 + C_255: 2.41 + C_254: 2.41 + C_253: 2.39 + C_252: 2.39 + C_251: 2.39 + C_250: 2.39 + C_249: 2.38 + C_248: 2.38 + C_247: 2.38 + C_246: 2.38 + C_245: 2.38 + C_244: 2.38 + C_243: 2.38 + C_242: 2.36 + C_241: 2.36 + C_240: 2.36 + C_239: 2.36 + C_238: 2.35 + C_237: 2.33 + C_236: 2.33 + C_235: 2.32 + C_234: 2.31 + C_233: 2.31 + C_232: 2.31 + C_231: 2.31 + C_230: 2.31 + C_229: 2.31 + C_227: 2.30 + C_226: 2.29 + C_225: 2.29 + C_224: 2.29 + C_222: 2.29 + C_221: 2.29 + C_220: 2.29 + C_219: 2.29 + C_218: 2.29 + RC1: 2.29 + C_216: 2.29 + C_215: 2.28 + C_214: 2.27 + C_213: 2.27 + C_212: 2.23 + C_206: 2.21 + C_205_3: 2.20 + C_205_2: 2.19 + C_205_1: 2.18 + C_205: 2.17 + C_204_2: 2.12 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.8 + C_202_1: 2.6 + C_202: 2.2 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 44 +============================================================================= + +RCS file: src/RCS/readtr.c,v +Working file: src/readtr.c +head: 2.13 +branch: +locks: strict + dlpark: 2.13 +access list: +symbolic names: + C_260: 2.13 + C_259: 2.13 + C_258: 2.12 + C_257: 2.12 + C_256: 2.11 + C_255: 2.10 + C_254: 2.10 + C_253: 2.9 + C_252: 2.9 + C_251: 2.9 + C_250: 2.9 + C_249: 2.8 + C_248: 2.8 + C_247: 2.8 + C_246: 2.8 + C_245: 2.8 + C_244: 2.8 + C_243: 2.8 + C_242: 2.6 + C_241: 2.6 + C_240: 2.6 + C_239: 2.6 + C_238: 2.5 + C_237: 2.5 + C_236: 2.5 + C_235: 2.5 + C_234: 2.5 + C_233: 2.5 + C_232: 2.5 + C_231: 2.5 + C_230: 2.5 + C_229: 2.5 + C_227: 2.5 + C_226: 2.5 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.3 + C_214: 2.3 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/smalldense.c,v +Working file: src/smalldense.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/spread.c,v +Working file: src/spread.c +head: 2.17 +branch: +locks: strict + dlpark: 2.17 +access list: +symbolic names: + C_260: 2.17 + C_259: 2.17 + C_258: 2.16 + C_257: 2.16 + C_256: 2.15 + C_255: 2.15 + C_254: 2.15 + C_253: 2.15 + C_252: 2.15 + C_251: 2.15 + C_250: 2.15 + C_249: 2.14 + C_248: 2.14 + C_247: 2.14 + C_246: 2.14 + C_245: 2.14 + C_244: 2.14 + C_243: 2.14 + C_242: 2.13 + C_241: 2.13 + C_240: 2.13 + C_239: 2.13 + C_238: 2.12 + C_237: 2.12 + C_236: 2.12 + C_235: 2.12 + C_234: 2.12 + C_233: 2.12 + C_232: 2.12 + C_231: 2.12 + C_230: 2.11 + C_229: 2.11 + C_227: 2.11 + C_226: 2.11 + C_225: 2.11 + C_224: 2.11 + C_222: 2.11 + C_221: 2.11 + C_220: 2.11 + C_219: 2.11 + C_218: 2.11 + RC1: 2.11 + C_216: 2.11 + C_215: 2.11 + C_214: 2.11 + C_213: 2.11 + C_212: 2.10 + C_206: 2.10 + C_205_3: 2.10 + C_205_2: 2.10 + C_205_1: 2.9 + C_205: 2.8 + C_204_2: 2.8 + C_204_1: 2.7 + C_204: 2.6 + C_202_2: 2.3 + C_202_1: 2.2 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 18 +============================================================================= + +RCS file: src/RCS/step.c,v +Working file: src/step.c +head: 2.13 +branch: +locks: strict + dlpark: 2.13 +access list: +symbolic names: + C_260: 2.13 + C_259: 2.13 + C_258: 2.13 + C_257: 2.13 + C_256: 2.12 + C_255: 2.12 + C_254: 2.12 + C_253: 2.12 + C_252: 2.12 + C_251: 2.12 + C_250: 2.12 + C_249: 2.11 + C_248: 2.11 + C_247: 2.11 + C_246: 2.11 + C_245: 2.11 + C_244: 2.11 + C_243: 2.11 + C_242: 2.10 + C_241: 2.10 + C_240: 2.10 + C_239: 2.10 + C_238: 2.9 + C_237: 2.7 + C_236: 2.7 + C_235: 2.7 + C_234: 2.7 + C_233: 2.7 + C_232: 2.7 + C_231: 2.7 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.6 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/structures.c,v +Working file: src/structures.c +head: 2.35 +branch: +locks: strict + dlpark: 2.35 +access list: +symbolic names: + C_260: 2.35 + C_259: 2.35 + C_258: 2.34 + C_257: 2.33 + C_256: 2.32 + C_255: 2.32 + C_254: 2.31 + C_253: 2.29 + C_252: 2.29 + C_251: 2.29 + C_250: 2.29 + C_249: 2.28 + C_248: 2.28 + C_247: 2.28 + C_246: 2.28 + C_245: 2.28 + C_244: 2.28 + C_243: 2.28 + C_242: 2.26 + C_241: 2.25 + C_240: 2.25 + C_239: 2.24 + C_238: 2.23 + C_237: 2.22 + C_236: 2.22 + C_235: 2.22 + C_234: 2.21 + C_233: 2.21 + C_232: 2.20 + C_231: 2.20 + C_230: 2.20 + C_229: 2.20 + C_227: 2.19 + C_226: 2.19 + C_225: 2.19 + C_224: 2.19 + C_222: 2.19 + C_221: 2.19 + C_220: 2.19 + C_219: 2.19 + C_218: 2.18 + RC1: 2.18 + C_216: 2.18 + C_215: 2.18 + C_214: 2.17 + C_213: 2.17 + C_212: 2.15 + C_206: 2.14 + C_205_3: 2.13 + C_205_2: 2.13 + C_205_1: 2.12 + C_205: 2.11 + C_204_2: 2.10 + C_204_1: 2.10 + C_204: 2.10 + C_202_2: 2.6 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 36 +============================================================================= + +RCS file: src/RCS/sundialsmath.c,v +Working file: src/sundialsmath.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/tally.c,v +Working file: src/tally.c +head: 1.14 +branch: +locks: strict + dlpark: 1.14 +access list: +symbolic names: + C_260: 1.14 + C_259: 1.14 + C_258: 1.14 + C_257: 1.14 + C_256: 1.13 + C_255: 1.13 + C_254: 1.13 + C_253: 1.13 + C_252: 1.13 + C_251: 1.12 + C_250: 1.12 + C_249: 1.11 + C_248: 1.11 + C_247: 1.11 + C_246: 1.10 + C_245: 1.10 + C_244: 1.9 + C_243: 1.8 + C_242: 1.6 + C_241: 1.5 + C_240: 1.4 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/tidy.c,v +Working file: src/tidy.c +head: 2.30 +branch: +locks: strict +access list: +symbolic names: + C_260: 2.30 + C_259: 2.29 + C_258: 2.29 + C_257: 2.29 + C_256: 2.28 + C_255: 2.28 + C_254: 2.28 + C_253: 2.27 + C_252: 2.27 + C_251: 2.27 + C_250: 2.27 + C_249: 2.26 + C_248: 2.26 + C_247: 2.26 + C_246: 2.26 + C_245: 2.26 + C_244: 2.26 + C_243: 2.26 + C_242: 2.24 + C_241: 2.23 + C_240: 2.23 + C_239: 2.22 + C_238: 2.21 + C_237: 2.19 + C_236: 2.19 + C_235: 2.19 + C_234: 2.19 + C_233: 2.19 + C_232: 2.17 + C_231: 2.17 + C_230: 2.17 + C_229: 2.16 + C_227: 2.16 + C_226: 2.16 + C_225: 2.16 + C_224: 2.16 + C_222: 2.16 + C_221: 2.16 + C_220: 2.15 + C_219: 2.15 + C_218: 2.15 + RC1: 2.15 + C_216: 2.15 + C_215: 2.15 + C_214: 2.15 + C_213: 2.15 + C_212: 2.10 + C_206: 2.9 + C_205_3: 2.9 + C_205_2: 2.8 + C_205_1: 2.7 + C_205: 2.6 + C_204_2: 2.5 + C_204_1: 2.4 + C_204: 2.3 + C_202_2: 2.2 + C_202_1: 2.2 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 31 +============================================================================= + +RCS file: src/RCS/transport.c,v +Working file: src/transport.c +head: 2.14 +branch: +locks: strict + dlpark: 2.14 +access list: +symbolic names: + C_260: 2.14 + C_259: 2.14 + C_258: 2.14 + C_257: 2.14 + C_256: 2.13 + C_255: 2.13 + C_254: 2.13 + C_253: 2.13 + C_252: 2.13 + C_251: 2.13 + C_250: 2.13 + C_249: 2.12 + C_248: 2.12 + C_247: 2.12 + C_246: 2.12 + C_245: 2.12 + C_244: 2.12 + C_243: 2.12 + C_242: 2.10 + C_241: 2.10 + C_240: 2.10 + C_239: 2.10 + C_238: 2.9 + C_237: 2.8 + C_236: 2.8 + C_235: 2.8 + C_234: 2.8 + C_233: 2.8 + C_232: 2.8 + C_231: 2.8 + C_230: 2.8 + C_229: 2.8 + C_227: 2.8 + C_226: 2.8 + C_225: 2.8 + C_224: 2.8 + C_222: 2.8 + C_221: 2.8 + C_220: 2.7 + C_219: 2.7 + C_218: 2.7 + RC1: 2.6 + C_216: 2.5 + C_215: 2.5 + C_214: 2.5 + C_213: 2.5 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.4 + C_205_2: 2.4 + C_205_1: 2.4 + C_205: 2.3 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 15 +============================================================================= + +RCS file: src/RCS/utilities.c,v +Working file: src/utilities.c +head: 2.30 +branch: +locks: strict + dlpark: 2.30 +access list: +symbolic names: + C_260: 2.30 + C_259: 2.30 + C_258: 2.30 + C_257: 2.30 + C_256: 2.29 + C_255: 2.29 + C_254: 2.29 + C_253: 2.28 + C_252: 2.28 + C_251: 2.28 + C_250: 2.28 + C_249: 2.27 + C_248: 2.27 + C_247: 2.27 + C_246: 2.27 + C_245: 2.27 + C_244: 2.27 + C_243: 2.27 + C_242: 2.25 + C_241: 2.24 + C_240: 2.24 + C_239: 2.24 + C_238: 2.23 + C_237: 2.22 + C_236: 2.22 + C_235: 2.21 + C_234: 2.21 + C_233: 2.21 + C_232: 2.19 + C_231: 2.18 + C_230: 2.18 + C_229: 2.16 + C_227: 2.15 + C_226: 2.15 + C_225: 2.15 + C_224: 2.15 + C_222: 2.15 + C_221: 2.15 + C_220: 2.14 + C_219: 2.13 + C_218: 2.13 + RC1: 2.13 + C_216: 2.13 + C_215: 2.13 + C_214: 2.11 + C_213: 2.11 + C_212: 2.9 + C_206: 2.9 + C_205_3: 2.8 + C_205_2: 2.8 + C_205_1: 2.7 + C_205: 2.6 + C_204_2: 2.5 + C_204_1: 2.5 + C_204: 2.5 + C_202_2: 2.4 + C_202_1: 2.4 + C_202: 2.3 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 31 +============================================================================= + +RCS file: src/RCS/cvdense.h,v +Working file: src/cvdense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/cvode.h,v +Working file: src/cvode.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/dense.h,v +Working file: src/dense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/global.h,v +Working file: src/global.h +head: 2.47 +branch: +locks: strict + dlpark: 2.47 +access list: +symbolic names: + C_260: 2.47 + C_259: 2.47 + C_258: 2.46 + C_257: 2.44 + C_256: 2.44 + C_255: 2.44 + C_254: 2.43 + C_253: 2.42 + C_252: 2.42 + C_251: 2.42 + C_250: 2.42 + C_249: 2.41 + C_248: 2.41 + C_247: 2.40 + C_246: 2.40 + C_245: 2.40 + C_244: 2.39 + C_243: 2.39 + C_242: 2.36 + C_241: 2.35 + C_240: 2.35 + C_239: 2.34 + C_238: 2.33 + C_237: 2.32 + C_236: 2.32 + C_235: 2.32 + C_234: 2.31 + C_233: 2.31 + C_232: 2.30 + C_231: 2.30 + C_230: 2.30 + C_229: 2.30 + C_227: 2.29 + C_226: 2.28 + C_225: 2.28 + C_224: 2.28 + C_222: 2.28 + C_221: 2.28 + C_220: 2.28 + C_219: 2.27 + C_218: 2.27 + RC1: 2.27 + C_216: 2.27 + C_215: 2.26 + C_214: 2.25 + C_213: 2.24 + C_212: 2.19 + C_206: 2.18 + C_205_3: 2.17 + C_205_2: 2.16 + C_205_1: 2.15 + C_205: 2.13 + C_204_2: 2.11 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.7 + C_202_1: 2.5 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 48 +============================================================================= + +RCS file: src/RCS/input.h,v +Working file: src/input.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/kinetics.h,v +Working file: src/kinetics.h +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_260: 1.2 + C_259: 1.2 + C_258: 1.2 + C_257: 1.2 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: src/RCS/nvector.h,v +Working file: src/nvector.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/nvector_serial.h,v +Working file: src/nvector_serial.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/output.h,v +Working file: src/output.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/p2c.h,v +Working file: src/p2c.h +head: 2.2 +branch: +locks: strict + dlpark: 2.2 +access list: +symbolic names: + C_260: 2.2 + C_259: 2.2 + C_258: 2.2 + C_257: 2.2 + C_256: 2.2 + C_255: 2.2 + C_254: 2.2 + C_253: 2.2 + C_252: 2.2 + C_251: 2.2 + C_250: 2.2 + C_249: 2.2 + C_248: 2.2 + C_247: 2.2 + C_246: 2.2 + C_245: 2.2 + C_244: 2.2 + C_243: 2.2 + C_242: 2.2 + C_241: 2.2 + C_240: 2.2 + C_239: 2.2 + C_238: 2.1 + C_237: 2.1 + C_236: 2.1 + C_235: 2.1 + C_234: 2.1 + C_233: 2.1 + C_232: 2.1 + C_231: 2.1 + C_230: 2.1 + C_229: 2.1 + C_227: 2.1 + C_226: 2.1 + C_225: 2.1 + C_224: 2.1 + C_222: 2.1 + C_221: 2.1 + C_220: 2.1 + C_219: 2.1 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/phqalloc.h,v +Working file: src/phqalloc.h +head: 2.3 +branch: +locks: strict + dlpark: 2.3 +access list: +symbolic names: + C_260: 2.3 + C_259: 2.3 + C_258: 2.3 + C_257: 2.2 + C_256: 2.2 + C_255: 2.2 + C_254: 2.2 + C_253: 2.2 + C_252: 2.2 + C_251: 2.2 + C_250: 2.2 + C_249: 2.2 + C_248: 2.2 + C_247: 2.2 + C_246: 2.2 + C_245: 2.2 + C_244: 2.2 + C_243: 2.2 + C_242: 2.2 + C_241: 2.2 + C_240: 2.2 + C_239: 2.2 + C_238: 2.2 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/phrqproto.h,v +Working file: src/phrqproto.h +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_260: 1.6 + C_259: 1.6 + C_258: 1.6 + C_257: 1.6 + C_256: 1.5 + C_255: 1.5 + C_254: 1.4 + C_253: 1.2 + C_252: 1.2 + C_251: 1.1 + C_250: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: src/RCS/phrqtype.h,v +Working file: src/phrqtype.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/smalldense.h,v +Working file: src/smalldense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/sundialsmath.h,v +Working file: src/sundialsmath.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/sundialstypes.h,v +Working file: src/sundialstypes.h +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.4 + C_255: 1.4 + C_254: 1.4 + C_253: 1.4 + C_252: 1.4 + C_251: 1.4 + C_250: 1.4 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.3 + C_241: 1.3 + C_240: 1.3 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: database/RCS/llnl.dat,v +Working file: database/llnl.dat +head: 1.14 +branch: +locks: strict +access list: +symbolic names: + C_210: 1.14 + C_209: 1.14 + C_224: 1.12 + C_207: 1.12 + C_206: 1.11 + C_205: 1.11 + C_204: 1.10 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: database/RCS/minteq.dat,v +Working file: database/minteq.dat +head: 2.1 +branch: +locks: strict +access list: +symbolic names: + C_210: 2.1 + C_209: 2.1 + C_224: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: database/RCS/phreeqc.dat,v +Working file: database/phreeqc.dat +head: 2.3 +branch: +locks: strict + dlpark: 2.3 +access list: +symbolic names: + C_210: 2.3 + C_209: 2.3 + C_224: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: database/RCS/wateq4f.dat,v +Working file: database/wateq4f.dat +head: 2.6 +branch: +locks: strict + dlpark: 2.6 +access list: +symbolic names: + C_210: 2.6 + C_209: 2.6 + C_224: 2.4 + C_207: 2.2 + C_206: 2.2 + C_205: 2.2 + C_204: 2.2 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: database/RCS/iso.dat,v +Working file: database/iso.dat +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_210: 1.4 + C_209: 1.4 + C_224: 1.4 + C_207: 1.4 + C_206: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex1,v +Working file: examples/ex1 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex1.out,v +Working file: examples/ex1.out +head: 1.7 +branch: +locks: strict + dlpark: 1.7 +access list: +symbolic names: + C_212: 1.7 + C_211: 1.5 + C_210: 1.5 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: examples/RCS/ex2,v +Working file: examples/ex2 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex2.out,v +Working file: examples/ex2.out +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex2.sel,v +Working file: examples/ex2.sel +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex3,v +Working file: examples/ex3 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex3.out,v +Working file: examples/ex3.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex4,v +Working file: examples/ex4 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex4.out,v +Working file: examples/ex4.out +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_212: 1.6 + C_211: 1.4 + C_210: 1.4 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: examples/RCS/ex5,v +Working file: examples/ex5 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex5.out,v +Working file: examples/ex5.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex5.sel,v +Working file: examples/ex5.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex6,v +Working file: examples/ex6 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex6.out,v +Working file: examples/ex6.out +head: 1.13 +branch: +locks: strict + dlpark: 1.13 +access list: +symbolic names: + C_212: 1.13 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.9 + C_206: 1.7 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 13 +============================================================================= + +RCS file: examples/RCS/ex6A-B.sel,v +Working file: examples/ex6A-B.sel +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex6C.sel,v +Working file: examples/ex6C.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex7,v +Working file: examples/ex7 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex7.out,v +Working file: examples/ex7.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex7.sel,v +Working file: examples/ex7.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex8,v +Working file: examples/ex8 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex8.out,v +Working file: examples/ex8.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex8.sel,v +Working file: examples/ex8.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex9,v +Working file: examples/ex9 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex9.out,v +Working file: examples/ex9.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.5 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex9.sel,v +Working file: examples/ex9.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex10,v +Working file: examples/ex10 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex10.out,v +Working file: examples/ex10.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex10.sel,v +Working file: examples/ex10.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex11,v +Working file: examples/ex11 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.1 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex11.out,v +Working file: examples/ex11.out +head: 1.13 +branch: +locks: strict + dlpark: 1.13 +access list: +symbolic names: + C_212: 1.13 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 13 +============================================================================= + +RCS file: examples/RCS/ex11adv.sel,v +Working file: examples/ex11adv.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex11trn.sel,v +Working file: examples/ex11trn.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex12,v +Working file: examples/ex12 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex12.out,v +Working file: examples/ex12.out +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_212: 1.3 + C_211: 1.1 + C_210: 1.1 + C_224: 1.1 + C_208: 1.1 + C_207: 1.1 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: examples/RCS/ex12.sel,v +Working file: examples/ex12.sel +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.9 + C_206: 1.7 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex13a,v +Working file: examples/ex13a +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13a.out,v +Working file: examples/ex13a.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13a.sel,v +Working file: examples/ex13a.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13b,v +Working file: examples/ex13b +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13b.out,v +Working file: examples/ex13b.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13b.sel,v +Working file: examples/ex13b.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13c,v +Working file: examples/ex13c +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13c.out,v +Working file: examples/ex13c.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13c.sel,v +Working file: examples/ex13c.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex14,v +Working file: examples/ex14 +head: 2.2 +branch: +locks: strict + dlpark: 2.2 +access list: +symbolic names: + C_212: 2.2 + C_211: 2.2 + C_210: 2.2 + C_224: 2.2 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.1 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: examples/RCS/ex14.out,v +Working file: examples/ex14.out +head: 1.15 +branch: +locks: strict + dlpark: 1.15 +access list: +symbolic names: + C_212: 1.15 + C_211: 1.13 + C_210: 1.12 + C_224: 1.11 + C_208: 1.9 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 15 +============================================================================= + +RCS file: examples/RCS/ex14.sel,v +Working file: examples/ex14.sel +head: 1.8 +branch: +locks: strict + dlpark: 1.8 +access list: +symbolic names: + C_212: 1.8 + C_211: 1.7 + C_210: 1.7 + C_224: 1.6 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: examples/RCS/ex15,v +Working file: examples/ex15 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex15.dat,v +Working file: examples/ex15.dat +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex15.out,v +Working file: examples/ex15.out +head: 1.8 +branch: +locks: strict + dlpark: 1.8 +access list: +symbolic names: + C_212: 1.8 + C_211: 1.6 + C_210: 1.6 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: examples/RCS/ex15.sel,v +Working file: examples/ex15.sel +head: 1.7 +branch: +locks: strict + dlpark: 1.7 +access list: +symbolic names: + C_212: 1.7 + C_211: 1.7 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.5 + C_205: 1.4 + C_204: 1.4 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: examples/RCS/ex16,v +Working file: examples/ex16 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex16.out,v +Working file: examples/ex16.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex17,v +Working file: examples/ex17 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex17.out,v +Working file: examples/ex17.out +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex18,v +Working file: examples/ex18 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex18.out,v +Working file: examples/ex18.out +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_212: 1.6 + C_211: 1.4 + C_210: 1.4 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: doc/RCS/manual.pdf,v +Working file: doc/manual.pdf +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_211: 1.1 + C_210: 1.1 + C_224: 1.1 + C_208: 1.1 + C_207: 1.1 + C_206: 1.1 + C_205: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: doc/RCS/phreeqc.txt,v +Working file: doc/phreeqc.txt +head: 1.11 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.8 + C_207: 1.8 + C_206: 1.7 + C_205: 1.6 + C_204_2: 1.5 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: bin/RCS/phreeqc.orig,v +Working file: bin/phreeqc.orig +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_209: 1.4 + C_208: 1.4 + C_224: 1.4 + C_206: 1.4 + C_205: 1.4 + C_202: 1.4 + C_201: 1.4 + C_200: 1.4 + C_1: 1.4 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: test/RCS/test.sh,v +Working file: test/test.sh +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_211: 1.2 + C_210: 1.2 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: test/RCS/clean.sh,v +Working file: test/clean.sh +head: 1.2 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.2 + C_210: 1.2 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: test/RCS/check.sh,v +Working file: test/check.sh +head: 1.3 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.3 + C_210: 1.3 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 +keyword substitution: kv +total revisions: 3 +============================================================================= diff --git a/phreeqc_files.cpp b/phreeqc_files.cpp new file mode 100644 index 00000000..4d4990df --- /dev/null +++ b/phreeqc_files.cpp @@ -0,0 +1,524 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +#include "input.h" + +/* following line defines path for default data base file */ +const char *default_data_base = "phreeqc.dat"; + +static FILE *input_file = NULL; +static FILE *database_file = NULL; +static FILE *output = NULL; /* OUTPUT_MESSAGE */ +static FILE *log_file = NULL; /* OUTPUT_LOG */ +static FILE *punch_file = NULL; /* OUTPUT_PUNCH */ +static FILE *error_file = NULL; /* OUTPUT_ERROR */ +static FILE *dump_file = NULL; /* OUTPUT_DUMP */ + +static int fileop_handler(const int type, int (*PFN)(FILE*)); +static int open_handler(const int type, const char *file_name); +static int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); +static int rewind_wrapper(FILE* file_ptr); + +static char const svnid[] = "$Id: phreeqc_files.c 78 2005-02-01 22:47:12Z dlpark $"; + +/* ---------------------------------------------------------------------- */ +int phreeqc_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + int i; + + switch (action) { + case ACTION_OPEN: + return open_handler(type, err_str); + break; + case ACTION_OUTPUT: + return output_handler(type, err_str, stop, cookie, format, args); + break; + case ACTION_FLUSH: + return fileop_handler(type, fflush); + break; + case ACTION_REWIND: + return fileop_handler(type, rewind_wrapper); + break; + case ACTION_CLOSE: + + i = fileop_handler(type, fclose); + switch (type) { + case OUTPUT_ERROR: + error_file = NULL; + break; + + case OUTPUT_WARNING: + break; + + case OUTPUT_MESSAGE: + output = NULL; + break; + + case OUTPUT_PUNCH: + punch_file = NULL; + break; + + case OUTPUT_SCREEN: + break; + + case OUTPUT_LOG: + log_file = NULL; + break; + + case OUTPUT_STDERR: + break; + + case OUTPUT_DUMP: + dump_file = NULL; + break; + } + + + return(i); + break; + } + return ERROR; +} +/* ---------------------------------------------------------------------- */ +int close_input_files(void) +/* ---------------------------------------------------------------------- */ +{ + int i = 0; + i |= fclose(database_file); + i |= fclose(input_file); + input_file = database_file = NULL; + return (i); +} +/* ---------------------------------------------------------------------- */ +int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log) +/* ---------------------------------------------------------------------- */ +{ + int l; + char token[2*MAX_LENGTH], default_name[2*MAX_LENGTH]; + char query[2*MAX_LENGTH]; + char in_file[2*MAX_LENGTH], out_file[2*MAX_LENGTH]; + char *env_ptr; + char *ptr; + int errors; + ENTRY item, *found_item; + +/* + * Prepare error handling + */ + errors = setjmp(mark); + if (errors != 0) { + return errors; + } + +/* + * Prep for get_line + */ + max_line = MAX_LINE; + space ((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + space ((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); + hcreate_multi(5, &strings_hash_table); + hcreate_multi(2, &keyword_hash_table); + +/* + * Initialize hash table + */ + keyword_hash = (struct key *) PHRQ_malloc(sizeof(struct key)); + if (keyword_hash == NULL) { + malloc_error(); + } else { + keyword_hash->name = string_hsave("database"); + keyword_hash->keycount = 0; + item.key = keyword_hash->name; + item.data = keyword_hash; + found_item = hsearch_multi(keyword_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in keyword initialization."); + error_msg(error_string, STOP); + } + } + + +/* + * Open file for screen output + */ + if (argc > 4) { + error_file = fopen(argv[4], "w"); + if (error_file == NULL) { + error_file = stderr; + sprintf(error_string, "Error opening file, %s.", argv[4]); + warning_msg(error_string); + } + } else { + error_file = stderr; + } + +/* + * Open user-input file + */ + strcpy(query,"Name of input file?"); + if (argc <= 1) { + default_name[0]='\0'; + input_file = file_open(query, default_name, "r", FALSE); + } else { + strcpy(default_name, argv[1]); + input_file = file_open(query, default_name, "r", TRUE); + } + output_msg(OUTPUT_SCREEN, "Input file: %s\n\n", default_name); + output_msg(OUTPUT_SEND_MESSAGE, "Input file: %s\r\n\r\n", default_name); + strcpy(in_file, default_name); +/* + * Open file for output + */ + strcpy(query,"Name of output file?"); +#ifdef DOS + replace("."," ",default_name); +#endif + ptr = default_name; + copy_token(token, &ptr, &l); + strcat(token,".out"); + if (argc <= 1) { + output = file_open(query, token, "w", FALSE); + } else if (argc == 2) { + output = file_open(query, token, "w", TRUE); + } else if (argc >= 3) { + strcpy(token, argv[2]); + output = file_open(query, token, "w", TRUE); + } + output_msg(OUTPUT_SCREEN, "Output file: %s\n\n", token); + output_msg(OUTPUT_SEND_MESSAGE, "Output file: %s\r\n\r\n", token); + strcpy(out_file, token); +/* + * Open file for errors + */ + if (log == TRUE) { + if ((log_file = fopen("phreeqc.log","w")) == NULL) { + error_msg ("Can't open log file, phreeqc.log.", STOP); + } + } + /* + * Read input file for DATABASE keyword + */ + if (get_line(getc_callback, input_file) == KEYWORD) { + ptr = line; + copy_token(token, &ptr, &l); + if (strcmp_nocase(token, "database") == 0) { + user_database = string_duplicate(ptr); + if (string_trim(user_database) == EMPTY) { + warning_msg("DATABASE file name is missing; default database will be used."); + user_database = (char *) free_check_null(user_database); + } + } + } + fclose(input_file); + if ((input_file = fopen(in_file,"r")) == NULL) {; + error_msg ("Can't reopen input file.", STOP); + } +/* + * Open data base + */ + strcpy(query,"Name of database file?"); + env_ptr = getenv("PHREEQC_DATABASE"); + if (user_database != NULL) { + strcpy(token, user_database); + } else if (env_ptr != NULL) { + strcpy(token, env_ptr); + } else { + strcpy(token, default_data_base); + } + if (argc <= 1) { + database_file = file_open(query, token, "r", FALSE); + } else if (argc < 4) { + database_file = file_open(query, token, "r", TRUE); + } else if (argc >= 4) { + if (user_database == NULL) { + strcpy(token, argv[3]); + } else { +#ifndef PHREEQCI_GUI + warning_msg("Database file from DATABASE keyword is used; command line argument ignored."); +#endif + } + database_file = file_open(query, token, "r", TRUE); + } + output_msg(OUTPUT_SCREEN, "Database file: %s\n\n", token); + output_msg(OUTPUT_SEND_MESSAGE, "Database file: %s\r\n\r\n", token); + + + output_msg(OUTPUT_MESSAGE, " Input file: %s\n", in_file); + output_msg(OUTPUT_MESSAGE, " Output file: %s\n", out_file); + output_msg(OUTPUT_MESSAGE, "Database file: %s\n\n", token); + + +/* + * local cleanup + */ + user_database = (char *) free_check_null(user_database); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + hdestroy_multi(keyword_hash_table); + keyword_hash = (struct key *) free_check_null(keyword_hash); + keyword_hash_table = NULL; + + free_hash_strings(strings_hash_table); + hdestroy_multi(strings_hash_table); + strings_hash_table = NULL; + + *db_cookie = database_file; + *input_cookie = input_file; + + return 0; +} +/* ---------------------------------------------------------------------- */ +int getc_callback(void* cookie) +/* ---------------------------------------------------------------------- */ +{ + int i; + assert(cookie); + i = getc((FILE*)cookie); +#ifdef PHREEQ98 + if (i == '\n') ++inputlinenr; +#endif + return i; +} + +/* ---------------------------------------------------------------------- */ +static int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + int flush; + FILE *save_output = NULL; + + flush = TRUE; + + if (get_forward_output_to_log()) { + save_output = output; + output = log_file; + } + + switch (type) { + + case OUTPUT_ERROR: + if (status_on == TRUE) { + if (error_file != NULL) { + fprintf(error_file, "\n"); + } +#ifndef DOS + status_on = FALSE; +#endif + } + if (error_file != NULL) { + fprintf(error_file, "ERROR: %s\n", err_str); + if (flush) fflush(error_file); + } + if (output != NULL) { + fprintf(output, "ERROR: %s\n", err_str); + if (flush) fflush(output); + } + if (stop == STOP) { + if (error_file != NULL) { + fprintf(error_file, "Stopping.\n"); + fflush(error_file); + } + if (output != NULL) { + fprintf(output, "Stopping.\n"); + fflush(output); + } + } + break; + + case OUTPUT_WARNING: + if (pr.logfile == TRUE && log_file != NULL) { + fprintf(log_file,"WARNING: %s\n", err_str); + if (flush) fflush(log_file); + } + if (state == TRANSPORT && transport_warnings == FALSE) return(OK); + if (state == ADVECTION && advection_warnings == FALSE) return(OK); + if (pr.warnings >= 0) { + if (count_warnings > pr.warnings) return(OK); + } + if (status_on == TRUE) { + if (error_file != NULL) { + fprintf(error_file,"\n"); + } +#ifndef DOS + status_on = FALSE; +#endif + } + if (error_file != NULL) { + fprintf(error_file,"WARNING: %s\n", err_str); + if (flush) fflush(error_file); + } + if (output != NULL) { + fprintf(output,"WARNING: %s\n", err_str); + if (flush) fflush(output); + } + break; + case OUTPUT_CHECKLINE: + if (pr.echo_input == TRUE) { + if (output != NULL) { + vfprintf(output, format, args); + if (flush) fflush(output); + } + } + break; + case OUTPUT_MESSAGE: + case OUTPUT_BASIC: + if (output != NULL) { + vfprintf(output, format, args); + if (flush) fflush(output); + } + break; + case OUTPUT_PUNCH: + if (punch_file != NULL) { + if (pr.punch == TRUE && punch.in == TRUE) { + vfprintf(punch_file, format, args); + if (flush) fflush(punch_file); + } + } + break; + case OUTPUT_LOG: + if (pr.logfile == TRUE && log_file != NULL) { + vfprintf(log_file, format, args); + if (flush) fflush(log_file); + } + break; + case OUTPUT_SCREEN: + if (error_file != NULL) { + vfprintf(error_file, format, args); + if (flush) fflush(error_file); + } + break; + case OUTPUT_STDERR: + case OUTPUT_CVODE: + if (stderr != NULL) { + vfprintf(stderr, format, args); + fflush(stderr); + } + break; + case OUTPUT_DUMP: + if (dump_file != NULL) { + vfprintf(dump_file, format, args); + if (flush) fflush(dump_file); + } + break; + } + + if (get_forward_output_to_log()) { + output = save_output; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int close_output_files(void) +/* ---------------------------------------------------------------------- */ +{ + int ret = 0; + + if (output != NULL) ret |= fclose(output); + if (log_file != NULL) ret |= fclose(log_file); + if (punch_file != NULL) ret |= fclose(punch_file); + if (dump_file != NULL) ret |= fclose(dump_file); + if (error_file != NULL) ret |= fclose(error_file); + error_file = NULL; + output = log_file = punch_file = dump_file = NULL; + return ret; +} +/* ---------------------------------------------------------------------- */ +static int open_handler(const int type, const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + switch (type) { + + case OUTPUT_PUNCH: + if (punch_file != NULL) { + fclose(punch_file); + punch_file = NULL; + } + if( (punch_file = fopen(file_name, "w")) == NULL) { + return ERROR; + } else { + free_check_null(selected_output_file_name); + selected_output_file_name = string_duplicate(file_name); + } + break; + + case OUTPUT_DUMP: + if (dump_file != NULL) { + fclose(dump_file); + dump_file = NULL; + } + if( (dump_file = fopen(file_name, "w")) == NULL) { + return ERROR; + } else { + free_check_null(dump_file_name); + dump_file_name = string_duplicate(file_name); + } + break; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int fileop_handler(const int type, int (*PFN)(FILE*)) +/* ---------------------------------------------------------------------- */ +{ + FILE *save_output = NULL; + + int forward = get_forward_output_to_log(); + if (forward) { + save_output = output; + output = log_file; + } + + switch (type) { + case OUTPUT_ERROR: + if (error_file) PFN(error_file); + break; + + case OUTPUT_WARNING: + if (error_file) PFN(error_file); + if (output) PFN(output); + break; + + case OUTPUT_MESSAGE: + case OUTPUT_CHECKLINE: + case OUTPUT_BASIC: + if (output) PFN(output); + break; + + case OUTPUT_PUNCH: + if (punch_file) PFN(punch_file); + break; + + case OUTPUT_SCREEN: + if (error_file) PFN(error_file); + break; + + case OUTPUT_LOG: + if (log_file) PFN(log_file); + break; + + case OUTPUT_CVODE: + case OUTPUT_STDERR: + if (stderr) PFN(stderr); + break; + + case OUTPUT_DUMP: + if (dump_file) PFN(dump_file); + break; + } + + if (forward) { + output = save_output; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int rewind_wrapper(FILE* file_ptr) +/* ---------------------------------------------------------------------- */ +{ + rewind(file_ptr); + return(OK); +} diff --git a/phrqproto.h b/phrqproto.h new file mode 100644 index 00000000..f83016db --- /dev/null +++ b/phrqproto.h @@ -0,0 +1,515 @@ +#ifdef PHREEQC_IDENT +static char const svnidphrqproto[] = "$Id$"; +#endif +/* advection.c */ +int advection(void); +/* basic.c */ +LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles); +int basic_main(char *commands); +void cmd_initialize(void); +void cmd_free(void); +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +/* basicsubs.c */ +LDBLE activity (char *species_name); +LDBLE calc_logk_n(char *name); +LDBLE calc_logk_p(char *name); +LDBLE calc_logk_s(char *name); +LDBLE calc_surface_charge(char *surface_name); +LDBLE diff_layer_total(char *total_name, char *surface_name); +LDBLE equi_phase (char *phase_name); +LDBLE find_gas_comp (char *gas_comp_name); +LDBLE find_misc1 (char *s_s_name); +LDBLE find_misc2 (char *s_s_name); +LDBLE find_s_s_comp (char *s_s_comp_name); +LDBLE get_calculate_value(char *name); +LDBLE kinetics_moles (char *kinetics_name); +LDBLE log_activity (char *species_name); +LDBLE log_molality (char *species_name); +LDBLE molality (char *species_name); +LDBLE saturation_ratio (char *phase_name); +int saturation_index (char *phase_name, LDBLE *iap, LDBLE *si); +LDBLE solution_sum_secondary(char *total_name); +LDBLE sum_match_gases (char *stemplate, char *name); +LDBLE sum_match_species (char *stemplate, char *name); +LDBLE sum_match_s_s (char *stemplate, char *name); +int match_elts_in_species (char *name, char *stemplate); +int extract_bracket(char **string, char *bracket_string); +LDBLE surf_total(char *total_name, char *surface_name); +int system_species_compare(const void *ptr1, const void *ptr2); +LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles); +int system_total_elements(void); +int system_total_si(void); +int system_total_aq(void); +int system_total_ex(void); +int system_total_surf(void); +int system_total_gas(void); +int system_total_s_s(void); +int system_total_elt(char *total_name); +int system_total_elt_secondary(char *total_name); +LDBLE total (char *total_name); + +/* cl1.c */ +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE *q, + int *kode, LDBLE toler, + int *iter, LDBLE *x, LDBLE *res, LDBLE *error, + LDBLE *cu, int *iu, int *s, + int check); + +/* default.c */ +int close_input_files(void); +int close_output_files(void); +int getc_callback(void* cookie); +int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); + +/* integrate.c */ +int calc_all_g(void); +int calc_init_g(void); +int initial_surface_water(void); +int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); +int calc_all_donnan(void); +int calc_init_donnan(void); + +/* inverse.c */ +int inverse_models(void); + +/* isotopes.c */ +int add_isotopes(struct solution *solution_ptr); +int calculate_values(void); +int calculate_isotope_moles(struct element *elt_ptr, struct solution *solution_ptr, LDBLE total_moles); +LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); +int from_pcil(struct master_isotope *master_isotope_ptr); +int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_tu(struct master_isotope *master_isotope_ptr); +struct calculate_value *calculate_value_alloc(void); +int calculate_value_free(struct calculate_value *calculate_value_ptr); +struct calculate_value *calculate_value_search (char *name); +struct calculate_value *calculate_value_store (char *name, int replace_if_found); +struct isotope_alpha *isotope_alpha_alloc(void); +struct isotope_alpha *isotope_alpha_search (char *name); +struct isotope_alpha *isotope_alpha_store (char *name, int replace_if_found); +struct isotope_ratio *isotope_ratio_alloc(void); +struct isotope_ratio *isotope_ratio_search (char *name); +struct isotope_ratio *isotope_ratio_store (char *name, int replace_if_found); +struct master_isotope *master_isotope_store (char *name, int replace_if_found); +struct master_isotope *master_isotope_alloc(void); +struct master_isotope *master_isotope_search (char *name); +int print_initial_solution_isotopes(void); +int print_isotope_ratios(void); +int print_isotope_alphas(void); +int punch_isotopes(void); +int punch_calculate_values(void); +int read_calculate_values (void); +int read_isotopes(void); +int read_isotope_ratios (void); +int read_isotope_alphas (void); + +/* kinetics.c */ + +void cvode_init(void); +int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); +int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); +int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); +int set_advection(int i, int use_mix, int use_kinetics, int nsaver); +int free_cvode(void); + +/* main.c */ +int main(int argc, char *argv[]); + +/* mainsubs.c */ +FILE *file_open (char *query, char *default_name, const char *status, int batch); +int copy_entities(void); +void initialize(void); +int initial_exchangers(int print); +int initial_gas_phases(int print); +int initial_solutions(int print); +int step_save_exch(int n_user); +int step_save_surf(int n_user); +int initial_surfaces(int print); +int k_temp(LDBLE tempc); +int reactions(void); +int saver(void); +int xsolution_save(int k_user); +int do_initialize(void); +int do_status(void); + +/* model.c */ +int check_residuals(void); +int free_model_allocs(void); +int ineq(int kode); +int model(void); +int jacobian_sums (void); +int mb_gases(void); +int mb_s_s(void); +int mb_sums (void); +int molalities (int allow_overflow); +int reset(void); +int residuals(void); +int set(int initial); +int sum_species(void); +int surface_model(void); + +/* p2clib.c */ + +/* parse.c */ +int check_eqn ( int association ); +int get_charge(char *charge, LDBLE *z); +int get_elt (char **t_ptr, char *element, int *i); +int get_elts_in_species (char **t_ptr, LDBLE coef); +int get_num (char **t_ptr, LDBLE *num); +int get_secondary_in_species (char **t_ptr, LDBLE coef); +int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + +/* pitzer.c */ +int gammas_pz(void); +int model_pz(void); +int pitzer (void); +int pitzer_clean_up(void); +int pitzer_init (void); +int pitzer_tidy (void); +int read_pitzer (void); +int set_pz(int initial); + +/* prep.c */ +int check_same_model(void); +int k_temp(LDBLE tc); +LDBLE k_calc(LDBLE *logk, LDBLE tempk); +int prep(void); +int reprep (void); +int rewrite_master_to_secondary(struct master *master_ptr1, struct master *master_ptr2); +int switch_bases(void); +int write_phase_sys_total (int n); + +/* print.c */ +int fpunchf(const char* name, const char* format, ...); +int fpunchf_user(int user_index, const char* format, ...); +char *sformatf(const char* format, ...); +int array_print(LDBLE *array_l, int row_count, int column_count, int max_column_count); +int print_all(void); +int print_exchange(void); +int print_gas_phase(void); +int print_master_reactions(void); +int print_reaction(struct reaction *rxn_ptr); +int print_species(void); +int print_surface(void); +int punch_all(void); + +/* read.c */ +int read_input(void); +int read_conc(int n, int count_mass_balance, char *str); +int *read_list_ints_range (char **ptr, int *count_ints, int positive, int *int_list ); +int read_log_k_only (char *ptr, LDBLE *log_k); +int read_number_description (char *ptr, int *n_user, int *n_user_end, + char **description); +int check_key (char *str); +int check_units (char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print); +int find_option(char *item, int *n, const char **list, int count_list, int exact); +int get_option (const char **opt_list, int count_opt_list, char **next_char); +int get_true_false(char *string, int default_value); + +/* readtr.c */ +int read_transport (void); +int dump(void); +int dump_exchange(int k); +int dump_gas_phase(int k); +int dump_kinetics (int k); +int dump_mix (int k); +int dump_pp_assemblage(int k); +int dump_reaction (int k); +int dump_s_s_assemblage (int k); +int dump_solution (int k); +int dump_surface(int k); + +/* spread.c */ +int read_solution_spread(void); + +/* step.c */ +int step(LDBLE step_fraction); +int xsolution_zero (void); +int add_exchange (struct exchange *exchange_ptr); +int add_gas_phase (struct gas_phase *gas_phase_ptr); +int add_kinetics (struct kinetics *kinetics_ptr); +int add_mix (struct mix *mix_ptr); +int add_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr); +int add_reaction (struct irrev *irrev_ptr, int step_number, LDBLE step_fraction); +int add_s_s_assemblage (struct s_s_assemblage *s_s_assemblage_ptr); +int add_solution (struct solution *solution_ptr, LDBLE extensive, + LDBLE intensive); +int add_surface (struct surface *surface_ptr); +int add_temperature(struct temperature *temperature_ptr, int step_number); + +/* structures.c */ +int clean_up(void); +int copier_add(struct copier *copier_ptr, int n_user, int start, int end); +int copier_free(struct copier *copier_ptr); +int copier_init(struct copier *copier_ptr); +int copy_entities(void); +int element_compare(const void *ptr1, const void *ptr2); +struct element *element_store (char *element); +int elt_list_combine(void); +int elt_list_compare(const void *ptr1, const void *ptr2); +struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); +int elt_list_print(struct elt_list *elt_list_ptr); +struct elt_list *elt_list_save(void); + +struct exchange *exchange_alloc (void); +struct exchange *exchange_bsearch (int k, int *n); +int exchange_comp_compare(const void *ptr1, const void *ptr2); +int exchange_copy(struct exchange *exchange_old_ptr, struct exchange *exchange_new_ptr, int n_user_new); +int exchange_compare (const void *ptr1, const void *ptr2); +int exchange_copy_to_last(int n, int n_user); +int exchange_delete(int n_user_old); +int exchange_duplicate(int n_user_old, int n_user_new); +int exchange_init (struct exchange *exchange_ptr, int n_user, int n_user_end, char *description); +int exchange_free (struct exchange *exchange_ptr); +int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); +struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new); +struct exchange *exchange_search(int n_user, int *n, int print); +int exchange_sort(void); + +int gas_comp_compare(const void *ptr1, const void *ptr2); +struct gas_phase *gas_phase_alloc (void); +struct gas_phase *gas_phase_bsearch (int k, int *n); +int gas_phase_compare (const void *ptr1, const void *ptr2); +int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new); +int gas_phase_copy_to_last(int n, int n_user); +int gas_phase_delete(int n_user_old); +int gas_phase_duplicate(int n_user_old, int n_user_new); +int gas_phase_init (struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description); +int gas_phase_free (struct gas_phase *gas_phase_ptr); +int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new); +struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, int n_user_new); +struct gas_phase *gas_phase_search (int n_user, int *n); +int gas_phase_sort(void); + +enum entity_type get_entity_enum (char *name); + +struct inverse *inverse_alloc(void); +int inverse_delete (int i); +int inverse_isotope_compare (const void *ptr1, const void *ptr2); +struct inverse *inverse_search (int n_user, int *n); +int inverse_sort(void); + +struct irrev *irrev_bsearch (int k, int *n); +int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, int n_user_new); +int irrev_duplicate(int n_user_old, int n_user_new); +int irrev_free (struct irrev *irrev_ptr); +struct irrev *irrev_search(int n_user, int *n); + +struct kinetics *kinetics_alloc (void); +struct kinetics *kinetics_bsearch (int k, int *n); +int kinetics_delete(int n_user_old); +int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr); +int kinetics_compare (const void *ptr1, const void *ptr2); +int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new); +int kinetics_copy_to_last(int n, int n_user); +int kinetics_duplicate(int n_user_old, int n_user_new); +int kinetics_init (struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description); +int kinetics_free (struct kinetics *kinetics_ptr); +int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); +struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new); +struct kinetics *kinetics_search(int n_user, int *n, int print); +int kinetics_sort(void); + +struct logk *logk_alloc(void); +struct logk *logk_store (char *name, int replace_if_found); +struct logk *logk_search (char *name); + +struct master *master_alloc(void); +int master_compare (const void *ptr1, const void *ptr2); +int master_delete(char *ptr); +struct master *master_bsearch (const char *ptr); +struct master *master_bsearch_primary (char *ptr); +struct master *master_search (char *ptr, int *n); + +struct mix *mix_bsearch (int k, int *n); +int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new); +int mix_duplicate(int n_user_old, int n_user_new); +int mix_free (struct mix *mix_ptr); +struct mix *mix_search(int n_user, int *n, int print); +int mix_sort(void); + +struct pe_data *pe_data_alloc(void); +struct pe_data *pe_data_dup (struct pe_data *pe_ptr_old); +int pe_data_free (struct pe_data *pe_data_ptr); +int pe_data_store (struct pe_data **pe, const char *token); + +struct phase *phase_bsearch (char *ptr, int *j, int print); +int phase_compare(const void *ptr1, const void *ptr2); +int phase_delete(int i); +struct phase *phase_store (char *name); + +struct pp_assemblage *pp_assemblage_alloc (void); +struct pp_assemblage *pp_assemblage_bsearch (int k, int *n); +int pp_assemblage_compare(const void *ptr1, const void *ptr2); +int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new); +int pp_assemblage_copy_to_last(int n, int n_user); +int pp_assemblage_delete(int n_user_old); +int pp_assemblage_duplicate(int n_user_old, int n_user_new); +int pp_assemblage_free (struct pp_assemblage *pp_assemblage_ptr); +int pp_assemblage_init (struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description); +int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, int n_user_new); +struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, int n_user_new); +struct pp_assemblage *pp_assemblage_search (int n_user, int *n); +int pp_assemblage_sort(void); + +int pure_phase_compare (const void *ptr1, const void *ptr2); + +struct rate *rate_bsearch (char *ptr, int *j); +int rate_free(struct rate *rate_ptr); +struct rate *rate_search (char *name, int *n); +int rate_sort(void); + +struct reaction *rxn_alloc(int ntokens); +struct reaction *rxn_dup(struct reaction *rxn_ptr_old); +LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); +int rxn_free(struct reaction *rxn_ptr); + +int s_compare (const void *ptr1, const void *ptr2); +int s_delete (int i); +struct species *s_search (char *name); +struct species *s_store (char *name, LDBLE z, int replace_if_found); + +struct s_s_assemblage *s_s_assemblage_alloc (void); +struct s_s_assemblage *s_s_assemblage_bsearch (int k, int *n); +int s_s_assemblage_compare (const void *ptr1, const void *ptr2); + +int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, + struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new); +int s_s_assemblage_copy_to_last(int n, int n_user); +int s_s_assemblage_duplicate(int n_user_old, int n_user_new); +int s_s_assemblage_delete(int n_user_old); +int s_s_assemblage_free (struct s_s_assemblage *s_s_assemblage_ptr); +int s_s_assemblage_init (struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description); +int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, int n_user_new); +struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage *s_s_assemblage_old_ptr, int n_user_new); +struct s_s_assemblage *s_s_assemblage_search (int n_user, int *n); +int s_s_assemblage_sort(void); +int s_s_compare (const void *ptr1, const void *ptr2); + +struct save_values *save_values_bsearch (struct save_values *k, int *n); +int save_values_compare(const void *ptr1, const void *ptr2); +int save_values_sort(void); +int save_values_store(struct save_values *s_v); + +int conc_compare(const void *ptr1, const void *ptr2); +int conc_init (struct conc *conc_ptr); +int isotope_compare (const void *ptr1, const void *ptr2); +struct solution *solution_alloc(void); +struct solution *solution_bsearch (int k, int *n, int print); +int solution_copy_to_last(int n, int n_user_new); +int solution_duplicate(int n_user_old, int n_user_new); +int solution_delete(int n_user_old); +int solution_free (struct solution *solution_ptr); +int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); +struct solution *solution_replicate(struct solution *solution_old_ptr, int n_user_new); +int solution_sort(void); + +int species_list_compare_alk (const void *ptr1, const void *ptr2); +int species_list_compare_master (const void *ptr1, const void *ptr2); +int species_list_sort(void); + +struct surface *surface_alloc (void); +struct surface *surface_bsearch (int k, int *n); +int surface_comp_compare(const void *ptr1, const void *ptr2); +int surface_compare (const void *ptr1, const void *ptr2); +int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new); +int surface_copy_to_last(int n, int n_user); +int surface_delete(int n_user_old); +int surface_duplicate(int n_user_old, int n_user_new); +int surface_free(struct surface *surface_ptr); +int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description); +int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); +struct surface *surface_replicate(struct surface *surface_old_ptr, int n_user_new); +struct surface *surface_search(int n_user, int *n, int print); +int surface_sort(void); + +int system_duplicate (int i, int save_old); + +struct temperature *temperature_bsearch (int k, int *n); +int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new); +int temperature_duplicate(int n_user_old, int n_user_new); +int temperature_free (struct temperature *temperature_ptr); +struct temperature *temperature_search(int n_user, int *n); +int temperature_sort(void); + +int trxn_add (struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_combine (void); +int trxn_copy (struct reaction *rxn_ptr); +LDBLE trxn_find_coef(const char *str, int start); +int trxn_print (void); +int trxn_reverse_k (void); +int trxn_sort( void ); +int trxn_swap (const char *token); + +struct unknown *unknown_alloc(void); +int unknown_delete(int i); +int unknown_free(struct unknown *unknown_ptr); + +/* tally.c */ +void add_all_components_tally(void); +int build_tally_table(void); +int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); +int diff_tally_table(void); +int extend_tally_table(void); +int free_tally_table(void); +int fill_tally_table(int *n_user, int index_conservative, int n_buffer); +int get_tally_table_rows_columns(int *rows, int *columns); +int get_tally_table_column_heading(int column, int *type, char *string); +int get_tally_table_row_heading(int column, char *string); +int store_tally_table(double *array, int row_dim, int col_dim, double fill_factor); +int zero_tally_table(void); + +/* tidy.c */ +int add_other_logk(LDBLE *source_k, int count_add_logk, struct name_coef *add_logk); +int select_log_k_expression(LDBLE *source_k, LDBLE *target_k); +int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); +int tidy_punch(void); +int tidy_model(void); + +/* transport.c */ +int transport(void); +int set_initial_moles(int i); + +/* utilities.c */ +int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); +int backspace_screen (int spaces); +LDBLE calc_alk(struct reaction *rxn_ptr); +int compute_gfw(const char *string, LDBLE *gfw); +int copy_token (char *token_ptr, char **ptr, int *length); +int dup_print(const char *ptr, int emphasis); +int equal (LDBLE a, LDBLE b, LDBLE eps); +void *free_check_null(void *ptr); +void free_hash_strings(HashTable *Table); +int get_token(char **eqnaddr, char *string, LDBLE *z, int *l); +int hcreate_multi(unsigned Count, HashTable **HashTable_ptr); +void hdestroy_multi(HashTable *HashTable_ptr); +ENTRY * hsearch_multi(HashTable *Table, ENTRY item, ACTION action); +int islegit(const char c); +void malloc_error (void); +int parse_couple(char *token); +int print_centered(const char *string); +int replace(const char *str1, const char *str2, char *str); +void space (void **ptr, int i, int *max, int struct_size); +void squeeze_white(char *s_l); +int status (int count, const char *str); +void str_tolower(char *str); +void str_toupper(char *str); +int strcmp_nocase(const char *str1, const char *str2); +int strcmp_nocase_arg1(const char *str1, const char *str2); +char * string_duplicate (const char *token); +char *string_hsave (const char *str); +char *string_pad (char *str, int i); +int string_trim (char *str); +int string_trim_right (char *str); +int string_trim_left (char *str); +LDBLE under (LDBLE xval); +int get_elts_in_species (char **t_ptr, LDBLE coef); diff --git a/phrqtype.h b/phrqtype.h new file mode 100644 index 00000000..01ff322c --- /dev/null +++ b/phrqtype.h @@ -0,0 +1,19 @@ +/* + * The following implements long double + * Many machines long double = double so there is no advantage + * Check float.h include file for number of digits (LDBL_DIG) + * Need to define here and in cl1.c + */ +#ifdef PHREEQC_IDENT +static char const svnidphrqtype[] = "$Id$"; +#endif + +/*#define USE_LONG_DOUBLE*/ +#ifdef USE_LONG_DOUBLE + #define LDBLE long double + #define SCANFORMAT "%Lf" +#else + #define LDBLE double + #define SCANFORMAT "%lf" +#endif + diff --git a/pitzer.cpp b/pitzer.cpp new file mode 100644 index 00000000..ddc59250 --- /dev/null +++ b/pitzer.cpp @@ -0,0 +1,1587 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +#define PITZER +#define PITZER_EXTERNAL +#include "pitzer.h" + +static char const svnid[] = "$Id: pitzer.c 248 2005-04-14 17:10:53Z dlpark $"; +/* variables */ +static double A0; +struct species **spec, **cations, **anions, **neutrals; +static int count_cations, count_anions, count_neutrals; +static int MAXCATIONS, FIRSTANION, MAXNEUTRAL; +struct pitz_param *mcb0, *mcb1, *mcc0; +static int *IPRSNT; +static double *M, *LGAMMA; +static double BK[23], DK[23]; + +/* routines */ +static int calc_pitz_param (struct pitz_param *pz_ptr, double TK, double TR); +static int check_gammas_pz(void); +static int ISPEC(char * name); +/*static int DH_AB (double TK, double *A, double *B);*/ +static double G (double Y); +static double GP (double Y); +#ifdef SKIP +static double ETHETAP (double ZJ, double ZK, double I); +static double ETHETA (double ZJ, double ZK, double I); +#endif +static int ETHETAS (double ZJ, double ZK, double I, double *etheta, double *ethetap); +static int BDK (double X); +static int initial_guesses(void); +static int revise_guesses(void); +static int remove_unstable_phases; + + +/* ---------------------------------------------------------------------- */ +int pitzer_init (void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Initialization for pitzer + */ + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + space ((void **) ((void *) &pitz_params), INIT, &max_pitz_param, sizeof(struct pitz_param *)); + + max_theta_param = 100; + count_theta_param = 0; + space ((void **) ((void *) &theta_params), INIT, &max_theta_param, sizeof(struct theta_param *)); + + ICON = TRUE; + OTEMP=0.0; + for (i = 0; i < 23; i++) { + BK[i] = 0.0; + DK[i] = 0.0; + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int pitzer_tidy (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make lists of species for cations, anions, neutral + */ + char * string1, *string2; + int i, j, order; + double z0, z1; + struct pitz_param *pzp_ptr; + struct theta_param *theta_param_ptr; + /* + * allocate pointers to species structures + */ + if (spec != NULL) spec = (struct species **) free_check_null(spec); + spec = (struct species **) PHRQ_malloc((size_t) (3*count_s*sizeof(struct species *))); + if (spec == NULL) malloc_error(); + for (i = 0; i < 3*count_s; i++) spec[i] = NULL; + cations = spec; + neutrals = &(spec[count_s]); + anions = &(spec[2*count_s]); + MAXCATIONS = count_s; + FIRSTANION = 2*count_s; + MAXNEUTRAL = count_s; + count_cations = 0; + count_anions = 0; + count_neutrals = 0; + if (itmax < 200) itmax = 200; + /* + * allocate other arrays for Pitzer + */ + if (IPRSNT != NULL) IPRSNT = (int *) free_check_null(IPRSNT); + IPRSNT = (int *) PHRQ_malloc((size_t) (3*count_s*sizeof(int))); + if (IPRSNT == NULL) malloc_error(); + if (M != NULL) M = (double *) free_check_null(M); + M = (double *) PHRQ_malloc((size_t) (3*count_s*sizeof(double))); + if (M == NULL) malloc_error(); + if (LGAMMA != NULL) LGAMMA = (double *) free_check_null(LGAMMA); + LGAMMA = (double *) PHRQ_malloc((size_t) (3*count_s*sizeof(double))); + if (LGAMMA == NULL) malloc_error(); + + + for (i = 0; i < count_s; i++) { + if (s[i] == s_eminus) continue; + if (s[i] == s_h2o) continue; + if (s[i]->z < -.001) { + anions[count_anions++] = s[i]; + } else if (s[i]->z > .001) { + cations[count_cations++] = s[i]; + } else { + neutrals[count_neutrals++] = s[i]; + } + } + /* + * Add etheta to parameter list in case theta not defined for + * cation-cation or anion-anion pair + * Remove old TYPE_ETHETA definitions + */ + j = 0; + for (i = 0; i < count_pitz_param; i++) { + if (pitz_params[i]->type == TYPE_ETHETA) { + pitz_params[i] = (struct pitz_param *) free_check_null(pitz_params[i]); + } else { + pitz_params[j++] = pitz_params[i]; + } + } + count_pitz_param = j; + for (i = 0; i < count_cations - 1; i++) { + for (j = i+1; j < count_cations; j++) { + sprintf(line,"%s %s 1", spec[i]->name, spec[j]->name); + pzp_ptr = pitz_param_read(line, 2); + pzp_ptr->type = TYPE_ETHETA; + if (count_pitz_param >= max_pitz_param) { + space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); + } + pitz_params[count_pitz_param++] = pzp_ptr; + + } + } + for (i = 2*count_s; i < 2*count_s + count_anions - 1; i++) { + for (j = i+1; j < 2*count_s + count_anions; j++) { + sprintf(line,"%s %s 1", spec[i]->name, spec[j]->name); + pzp_ptr = pitz_param_read(line, 2); + pzp_ptr->type = TYPE_ETHETA; + if (count_pitz_param >= max_pitz_param) { + space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); + } + pitz_params[count_pitz_param] = pzp_ptr; + count_pitz_param++; + } + } + /* + * put species numbers in pitz_params + */ + for (i = 0; i < count_pitz_param; i++) { + for (j = 0; j < 3; j++) { + if (pitz_params[i]->species[j] == NULL) continue; + pitz_params[i]->ispec[j] = ISPEC(pitz_params[i]->species[j]); + if ((j < 2 && pitz_params[i]->ispec[j] == -1) || + (j == 3 && (pitz_params[i]->type == TYPE_PSI || pitz_params[i]->type == TYPE_ZETA) && pitz_params[i]->ispec[j] == -1)) { + input_error++; + sprintf(error_string, "Species for Pitzer parameter not defined in SOLUTION_SPECIES, %s", pitz_params[i]->species[j]); + error_msg(error_string, CONTINUE); + return(ERROR); + } + } + } + /* + * McGinnis data + */ + string1 = string_hsave("K+"); + string2 = string_hsave("Cl-"); + IC = ISPEC(string2); + for (i = 0; i < count_pitz_param; i++) { + if (pitz_params[i]->species[0] == string1 && + pitz_params[i]->species[1] == string2) { + switch (pitz_params[i]->type) { + case TYPE_B0: + mcb0 = pitz_params[i]; + break; + case TYPE_B1: + mcb1 = pitz_params[i]; + break; + case TYPE_C0: + mcc0 = pitz_params[i]; + break; + case TYPE_B2: + case TYPE_THETA: + case TYPE_LAMDA: + case TYPE_ZETA: + case TYPE_PSI: + case TYPE_ETHETA: + case TYPE_Other: + break; + } + } + } + /* + * Set alpha values + */ + for (i = 0; i < count_pitz_param; i++) { + z0 = fabs(spec[pitz_params[i]->ispec[0]]->z); + z1 = fabs(spec[pitz_params[i]->ispec[1]]->z); + if (equal(z0, 1.0, 1e-8) || equal(z1, 1.0, 1e-8)) { + order = 1; + } else if (equal(z0,2.0, 1e-8) && equal(z1, 2.0, 1e-8)) { + order = 2; + } else { + order = 3; + } + if (pitz_params[i]->type == TYPE_B1) { + switch (order) { + case 1: + case 3: + pitz_params[i]->alpha = 2.0; + break; + case 2: + pitz_params[i]->alpha = 1.4; + break; + } + } else if (pitz_params[i]->type == TYPE_B2) { + switch (order) { + case 1: + pitz_params[i]->alpha = 12.0; + break; + case 2: + pitz_params[i]->alpha = 12.0; + break; + case 3: + pitz_params[i]->alpha = 50.0; + break; + } + } + } + /* + * Add thetas pointer to etheta pitzer parameters + */ + + if (count_theta_param > 0 ) { + for (i = 0; i < count_theta_param; i++) { + theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); + } + } + count_theta_param = 0; + for (i = 0; i < count_pitz_param; i++) { + if (pitz_params[i]->type == TYPE_ETHETA) { + z0 = spec[pitz_params[i]->ispec[0]]->z; + z1 = spec[pitz_params[i]->ispec[1]]->z; + theta_param_ptr = theta_param_search(z0, z1); + if (theta_param_ptr == NULL) { + if (count_theta_param >= max_theta_param) { + space ((void **) ((void *) &theta_params), count_theta_param, &max_theta_param, sizeof(struct theta_param *)); + } + theta_params[count_theta_param] = theta_param_alloc(); + theta_param_init(theta_params[count_theta_param]); + theta_params[count_theta_param]->zj = z0; + theta_params[count_theta_param]->zk = z1; + theta_param_ptr = theta_params[count_theta_param]; + count_theta_param++; + } + pitz_params[i]->thetas = theta_param_ptr; + } + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int ISPEC(char * name) +/* ---------------------------------------------------------------------- */ +/* + * Find species number in spec for character string species name + */ +{ + int i; + for (i = 0; i < 3*count_s; i++) { + if (spec[i] == NULL) continue; + if (name == spec[i]->name) { + return(i); + } + } + return (-1); +} +/* ---------------------------------------------------------------------- */ +int read_pitzer (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads advection information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read advection parameters: + * number of cells; + * number of shifts; + */ + int n, j; + struct pitz_param *pzp_ptr; + pitz_param_type pzp_type; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "b0", /* 0 */ + "b1", /* 1 */ + "b2", /* 2 */ + "c0", /* 3 */ + "theta", /* 4 */ + "lamda", /* 5 */ + "zeta", /* 6 */ + "psi", /* 7 */ + "macinnes", /* 8 */ + "macinnis", /* 9 */ + "mac" /* 10 */ + }; + int count_opt_list = 11; +/* + * Read lines + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + n = -1; + pzp_type = TYPE_Other; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + pzp_ptr = pitz_param_read(line, n); + if (pzp_ptr != NULL) { + pzp_ptr->type = pzp_type; + j = pitz_param_search(pzp_ptr); + if (j < 0) { + if (count_pitz_param >= max_pitz_param) { + space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); + } + + pitz_params[count_pitz_param] = pzp_ptr; + count_pitz_param++; + } else { + pitz_params[j] = (struct pitz_param *) free_check_null(pitz_params[j]); + pitz_params[j] = pzp_ptr; + } + } + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in PITZER keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* b0 */ + pzp_type = TYPE_B0; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 1: /* b1 */ + pzp_type = TYPE_B1; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 2: /* b2 */ + pzp_type = TYPE_B2; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 3: /* c0 */ + pzp_type = TYPE_C0; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 4: /* theta */ + pzp_type = TYPE_THETA; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 5: /* lambda */ + pzp_type = TYPE_LAMDA; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 6: /* zeta */ + pzp_type = TYPE_ZETA; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 7: /* psi */ + pzp_type = TYPE_PSI; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 8: /* macinnes */ + case 9: /* macinnis */ + case 10: /* mac */ + opt_save = OPTION_ERROR; + ICON = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + if (count_pitz_param > 0) pitzer_model = TRUE; + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int PTEMP (double TK) +/* ---------------------------------------------------------------------- */ +{ +/* +C +C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER +C +*/ + double DC0; + int i; + double TR=298.15; + + if (fabs(TK-OTEMP) < 0.01e0) return OK; + OTEMP=TK; +/* +C Set DW0 +*/ + DW(TK); + for (i = 0; i < count_pitz_param; i++) { + calc_pitz_param(pitz_params[i], TK, TR); + } + DC0=DC(TK); + if (fabs(TK-TR) < 0.01e0) { + A0=0.392e0; + } else { + DC0=DC(TK); + A0=1.400684e6*sqrt(DW0/(pow((DC0*TK),3.0e0))); + /*A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0*/ + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int calc_pitz_param (struct pitz_param *pz_ptr, double TK, double TR) +/* ---------------------------------------------------------------------- */ +{ + double param; + /* + */ + + if (fabs(TK-TR) < 0.01) { + param = pz_ptr->a[0]; + } else { + param = (pz_ptr->a[0] + + pz_ptr->a[1]*(1.e0/TK-1.e0/TR) + + pz_ptr->a[2]*log(TK/TR) + + pz_ptr->a[3]*(TK - TR) + + pz_ptr->a[4]*(TK*TK - TR*TR)); + } + pz_ptr->p = param; + switch (pz_ptr->type) { + case TYPE_B0: + pz_ptr->U.b0 = param; + break; + case TYPE_B1: + pz_ptr->U.b1 = param; + break; + case TYPE_B2: + pz_ptr->U.b2 = param; + break; + case TYPE_C0: + pz_ptr->U.c0 = param; + break; + case TYPE_THETA: + pz_ptr->U.theta = param; + break; + case TYPE_LAMDA: + pz_ptr->U.lamda = param; + break; + case TYPE_ZETA: + pz_ptr->U.zeta = param; + break; + case TYPE_ETHETA: + break; + case TYPE_PSI: + pz_ptr->U.psi = param; + break; + case TYPE_Other: + error_msg("Should not be TYPE_Other in function calc_pitz_param", STOP); + break; + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int pitzer (void) +/* ---------------------------------------------------------------------- */ +{ + int i, i0, i1, i2; + double param, alpha, z0, z1, z2; + double etheta, ethetap; + double dummy; + /* + double CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, + BMXPHI, PHIPHI, AW, A, B; + */ + double CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, B; + double I, TK; + int LNEUT; + /* + C + C INITIALIZE + C + */ + CONV = 1.0/log(10.0); + XI=0.0e0; + XX=0.0e0; + OSUM=0.0e0; + LNEUT=FALSE; + /*n + I = *I_X; + TK = *TK_X; + */ + I = mu_x; + TK = tk_x; + /* DH_AB(TK, &A, &B); */ + /* + C + C TRANSFER DATA FROM TO M + C + */ + for (i = 0; i < 3*count_s; i++) { + IPRSNT[i] = FALSE; + M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) { + if (spec[i]->type == EX || + spec[i]->type == SURF || + spec[i]->type == SURF_PSI) continue; + M[i] = under(spec[i]->lm); + if (M[i] > MIN_TOTAL) IPRSNT[i] = TRUE; + } + } + if (ICON == TRUE) { + IPRSNT[IC] = TRUE; + } +#ifdef SKIP + for (i = count_s; i < count_s + count_neutrals; i++) { + if (M[i] > MIN_TOTAL) LNEUT = TRUE; + } +#endif + /* + ICON = 0; + M[1] = 1.40070736; + M[4] = 2.52131086E-05; + M[140] = 4.59985435E-09; + */ + +/* +C +C COMPUTE PITZER COEFFICIENTS' TEMPERATURE DEPENDENCE +C +*/ + PTEMP(TK); + for (i = 0; i < 2*count_s + count_anions; i++) { + LGAMMA[i] = 0.0; + if (IPRSNT[i] == TRUE) { + XX=XX+M[i]*fabs(spec[i]->z); + XI=XI+M[i]*spec[i]->z*spec[i]->z; + OSUM=OSUM+M[i]; + } + } + I=XI/2.0e0; +/* +C +C EQUATION (8) +C +*/ + BIGZ=XX; + DI=sqrt(I); +/* +C +C CALCULATE F & GAMCLM +C +*/ + B = 1.2; + F=-A0*(DI/(1.0e0+B*DI)+2.0e0*log(1.0e0+B*DI)/B); + XXX=2.0e0*DI; + XXX=(1.0e0-(1.0e0+XXX-XXX*XXX*0.5e0)*exp(-XXX))/(XXX*XXX); + /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I;*/ + /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I;*/ + GAMCLM=F+I*2.0e0*(mcb0->p + mcb1->p*XXX) + 1.5e0*mcc0->p*I*I; + CSUM=0.0e0; + OSMOT=-(A0)*pow(I,1.5e0)/(1.0e0+B*DI); +/* + * Calculate ethetas + */ + for (i = 0; i < count_theta_param; i++) { + z0 = theta_params[i]->zj; + z1 = theta_params[i]->zk; + ETHETAS(z0, z1, I, ðeta, ðetap); + theta_params[i]->etheta = etheta; + theta_params[i]->ethetap = ethetap; + } +/* + * Sums for F, LGAMMA, and OSMOT + */ + dummy = LGAMMA[1]; + for (i = 0; i < count_pitz_param; i++) { + i0 = pitz_params[i]->ispec[0]; + i1 = pitz_params[i]->ispec[1]; + if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) continue; + z0 = spec[i0]->z; + z1 = spec[i1]->z; + param = pitz_params[i]->p; + alpha = pitz_params[i]->alpha; + switch (pitz_params[i]->type) { + case TYPE_B0: + LGAMMA[i0] += M[i1]*2.0*param; + LGAMMA[i1] += M[i0]*2.0*param; + OSMOT += M[i0]*M[i1]*param; + break; + case TYPE_B1: + F += M[i0]*M[i1]*param*GP(alpha*DI)/I; + LGAMMA[i0] += M[i1]*2.0*param*G(alpha*DI); + LGAMMA[i1] += M[i0]*2.0*param*G(alpha*DI); + OSMOT += M[i0]*M[i1]*param*exp(-alpha*DI); + break; + case TYPE_B2: + F += M[i0]*M[i1]*param*GP(alpha*DI)/I; + LGAMMA[i0] += M[i1]*2.0*param*G(alpha*DI); + LGAMMA[i1] += M[i0]*2.0*param*G(alpha*DI); + OSMOT += M[i0]*M[i1]*param*exp(-alpha*DI); + break; + case TYPE_C0: + CSUM += M[i0]*M[i1]*pitz_params[i]->p/(2.0e0*sqrt(fabs(z0*z1))); + LGAMMA[i0] += M[i1]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); + LGAMMA[i1] += M[i0]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); + OSMOT += M[i0]*M[i1]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); + break; + case TYPE_THETA: + LGAMMA[i0] += 2.0*M[i1]*(param /*+ ETHETA(z0, z1, I) */ ); + LGAMMA[i1] += 2.0*M[i0]*(param /*+ ETHETA(z0, z1, I) */ ); + OSMOT += M[i0]*M[i1]*param; + break; + case TYPE_ETHETA: + /* + ETHETAS(z0, z1, I, ðeta, ðetap); + */ + etheta = pitz_params[i]->thetas->etheta; + ethetap = pitz_params[i]->thetas->ethetap; + F += M[i0]*M[i1]*ethetap; + LGAMMA[i0] += 2.0*M[i1]*etheta; + LGAMMA[i1] += 2.0*M[i0]*etheta; + OSMOT += M[i0]*M[i1]*(etheta + I*ethetap); + /* + F += M[i0]*M[i1]*ETHETAP(z0, z1, I); + LGAMMA[i0] += 2.0*M[i1]*(ETHETA(z0, z1, I) ); + LGAMMA[i1] += 2.0*M[i0]*(ETHETA(z0, z1, I) ); + OSMOT += M[i0]*M[i1]*(ETHETA(z0, z1, I) + I*ETHETAP(z0, z1, I) ); + */ + break; + case TYPE_PSI: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) continue; + z2 = spec[i2]->z; + LGAMMA[i0] += M[i1]*M[i2]*param; + LGAMMA[i1] += M[i0]*M[i2]*param; + LGAMMA[i2] += M[i0]*M[i1]*param; + OSMOT += M[i0]*M[i1]*M[i2]*param; + break; + case TYPE_LAMDA: + LGAMMA[i0] += 2.0*M[i1]*param; + LGAMMA[i1] += 2.0*M[i0]*param; + OSMOT += M[i0]*M[i1]*param; + break; + case TYPE_ZETA: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) continue; + LGAMMA[i0] += M[i1]*M[i2]*param; + LGAMMA[i1] += M[i0]*M[i2]*param; + LGAMMA[i2] += M[i0]*M[i1]*param; + OSMOT += M[i0]*M[i1]*M[i2]*param; + break; + case TYPE_Other: + error_msg("TYPE_Other in pitz_param list.", STOP); + break; + } + } + + /* + * Add F and CSUM terms to LGAMMA + */ + + for (i = 0; i < count_cations; i++) { + z0 = spec[i]->z; + LGAMMA[i] += z0*z0*F+fabs(z0)*CSUM; + } + for (i = 2*count_s; i < 2*count_s + count_anions; i++) { + z0 = spec[i]->z; + LGAMMA[i] += z0*z0*F+fabs(z0)*CSUM; + } +/* +C +C CONVERT TO MACINNES CONVENTION +C +*/ + if (ICON == TRUE) { + PHIMAC=LGAMMA[IC]-GAMCLM; +/* +C +C CORRECTED ERROR IN PHIMAC, NOVEMBER, 1989 +C +*/ + for (i = 0; i < 2*count_s + count_anions; i++) { + if (IPRSNT[i] == TRUE) { + LGAMMA[i]=LGAMMA[i]+spec[i]->z*PHIMAC; + } + } + } + + COSMOT = 1.0e0 + 2.0e0*OSMOT/OSUM; +/* +C +C CALCULATE THE ACTIVITY OF WATER +C +*/ + AW=exp(-OSUM*COSMOT/55.50837e0); + if (AW > 1.0) AW = 1.0; + /*s_h2o->la=log10(AW);*/ + mu_x = I; + for (i = 0; i < 2*count_s + count_anions; i++) { + if (IPRSNT[i] == FALSE) continue; + /*spec[i]->lg=LGAMMA[i]*CONV;*/ + spec[i]->lg_pitzer=LGAMMA[i]*CONV; + /* + output_msg(OUTPUT_MESSAGE, "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg); + */ + } + /* + output_msg(OUTPUT_MESSAGE, "OSUM: %e\n", OSUM); + output_msg(OUTPUT_MESSAGE, "OSMOT: %e\n", OSMOT); + output_msg(OUTPUT_MESSAGE, "COSMOT: %e\n", COSMOT); + output_msg(OUTPUT_MESSAGE, "F: %e\n", F); + output_msg(OUTPUT_MESSAGE, "AW: %e\n", AW); + */ + /* + *I_X = I; + *COSMOT_X = COSMOT; + */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +double JAY (double X) +/* ---------------------------------------------------------------------- */ +/* +C +C FUNCTION TO CALCULATE JAY AND JPRIME +C +C J0 AND J1, USED IN CALCULATION OF ETHETA AND ETHEAP +C +*/ +{ + double JAY; + BDK (X); + JAY=X/4.0e0-1.0e0+0.5e0*(BK[0]-BK[2]); + return JAY; +} +/* ---------------------------------------------------------------------- */ +double JPRIME (double Y) +/* ---------------------------------------------------------------------- */ +{ + double DZ; + BDK (Y); + if (Y > 1.0e0) { + DZ=-4.0e0*pow(Y,-1.1e0)/9.0e0; + } else { + DZ=0.8e0*pow(Y,-0.8e0); + } + return (Y*(.25e0+DZ*(DK[0]-DK[2])/2.0e0)); +} + + +/* ---------------------------------------------------------------------- */ +int BDK (double X) +/* ---------------------------------------------------------------------- */ +/* +C +C NUMERICAL APPROXIMATION TO THE INTEGRALS IN THE EXPRESSIONS FOR J0 +C AND J1. CHEBYSHEV APPROXIMATION IS USED. THE CONSTANTS 'AK' ARE +C DEFINED IN BLOCK COMMON. +C +*/ +/* +C +C AK IS USED TO CALCULATE HIGHER ORDER ELECTROSTATIC TERMS IN +C SUBROUTINE PITZER +C +*/ +{ + double AKX[42] = { + 1.925154014814667e0, -.060076477753119e0, -.029779077456514e0, + -.007299499690937e0, 0.000388260636404e0, 0.000636874599598e0, + 0.000036583601823e0, -.000045036975204e0, -.000004537895710e0, + 0.000002937706971e0, 0.000000396566462e0, -.000000202099617e0, + -.000000025267769e0, 0.000000013522610e0, 0.000000001229405e0, + -.000000000821969e0, -.000000000050847e0, 0.000000000046333e0, + 0.000000000001943e0, -.000000000002563e0, -.000000000010991e0, + 0.628023320520852e0, 0.462762985338493e0, 0.150044637187895e0, + -.028796057604906e0, -.036552745910311e0, -.001668087945272e0, + 0.006519840398744e0, 0.001130378079086e0, -.000887171310131e0, + -.000242107641309e0, 0.000087294451594e0, 0.000034682122751e0, + -.000004583768938e0, -.000003548684306e0, -.000000250453880e0, + 0.000000216991779e0, 0.000000080779570e0, 0.000000004558555e0, + -.000000006944757e0, -.000000002849257e0, 0.000000000237816e0}; +/* + DOUBLE PRECISION AK, BK, DK + COMMON / MX8 / AK(0:20,2),BK(0:22),DK(0:22) +*/ + double *AK; + double Z; + int II; + int i; + + if (X <= 1.0e0) { + II=1; + Z=4.0e0*pow(X,0.2e0)-2.0e0; + AK = &AKX[0]; + } else { + II=2; + Z=40.0e0*pow(X,-1.0e-1)/9.0e0-22.0e0/9.0e0; + AK = &AKX[21]; + } + for (i = 20; i >= 0; i--) { + BK[i]=Z*BK[i+1]-BK[i+2]+AK[i]; + DK[i]=BK[i+1]+Z*DK[i+1]-DK[i+2]; + } + return OK; +} +/* ---------------------------------------------------------------------- */ +double G (double Y) +/* ---------------------------------------------------------------------- */ +{ + return (2.0e0*(1.0e0-(1.0e0+Y)*exp(-Y))/(Y*Y)); +} +/* ---------------------------------------------------------------------- */ +double GP (double Y) +/* ---------------------------------------------------------------------- */ +{ + return (-2.0e0*(1.0e0-(1.0e0+Y+Y*Y/2.0e0)*exp(-Y))/(Y*Y)); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +double ETHETA (double ZJ, double ZK, double I) +/* ---------------------------------------------------------------------- */ +{ + double XCON, ZZ; + double XJK, XJJ, XKK; + + if (ZJ == ZK) return(0.0); + XCON=6.0e0*A0*sqrt(I); + ZZ=ZJ*ZK; +/* +C +C NEXT 3 ARE EQUATION (A1) +C +*/ + XJK=XCON*ZZ; + XJJ=XCON*ZJ*ZJ; + XKK=XCON*ZK*ZK; +/* +C +C EQUATION (A2) +C +*/ + + return (ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I)); +} +/* ---------------------------------------------------------------------- */ +double ETHETAP (double ZJ, double ZK, double I) +/* ---------------------------------------------------------------------- */ +{ + double XCON, ZZ, ETHETA, ETHETAP; + double XJK, XJJ, XKK; + + if (ZJ == ZK) return(0.0); + XCON=6.0e0*A0*sqrt(I); + ZZ=ZJ*ZK; +/* +C +C NEXT 3 ARE EQUATION (A1) +C +*/ + XJK=XCON*ZZ; + XJJ=XCON*ZJ*ZJ; + XKK=XCON*ZK*ZK; +/* +C +C EQUATION (A3) +C +*/ + ETHETA=ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I); + ETHETAP=ZZ*(JPRIME(XJK)-JPRIME(XJJ)/2.0e0-JPRIME(XKK)/2.0e0)/(8.0e0*I*I) - ETHETA/I; + return (ETHETAP); +} +#endif +/* ---------------------------------------------------------------------- */ +int ETHETAS (double ZJ, double ZK, double I, double *etheta, double *ethetap) +/* ---------------------------------------------------------------------- */ +{ + double XCON, ZZ; + double XJK, XJJ, XKK; + + *etheta = 0.0; + *ethetap = 0.0; + if (ZJ == ZK) return(OK); + XCON=6.0e0*A0*sqrt(I); + ZZ=ZJ*ZK; +/* +C +C NEXT 3 ARE EQUATION (A1) +C +*/ + XJK=XCON*ZZ; + XJJ=XCON*ZJ*ZJ; + XKK=XCON*ZK*ZK; +/* +C +C EQUATION (A3) +C +*/ + *etheta=ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I); + *ethetap=ZZ*(JPRIME(XJK)-JPRIME(XJJ)/2.0e0-JPRIME(XKK)/2.0e0)/(8.0e0*I*I) - *etheta/I; + return (OK); +} +/* ---------------------------------------------------------------------- */ +int pitzer_clean_up(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all allocated memory, except strings + */ + int i; + + if (svnid == NULL) fprintf(stderr," "); + for (i = 0; i < count_pitz_param; i++) { + pitz_params[i] = (struct pitz_param *) free_check_null(pitz_params[i]); + } + pitz_params = (struct pitz_param **) free_check_null(pitz_params); + for (i = 0; i < count_theta_param; i++) { + theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); + } + theta_params = (struct theta_param **) free_check_null(theta_params); + LGAMMA = (double *) free_check_null(LGAMMA); + IPRSNT = (int *) free_check_null(IPRSNT); + spec = (struct species **) free_check_null(spec); + M = (double *) free_check_null(M); + + return OK; +} + +/* ---------------------------------------------------------------------- */ +int set_pz(int initial) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets initial guesses for unknowns if initial == TRUE + * Revises guesses whether initial is true or not + */ + int i; + struct solution *solution_ptr; +/* + * Set initial log concentrations to zero + */ + iterations = -1; + solution_ptr = use.solution_ptr; + for (i=0; i < count_s_x; i++) { + s_x[i]->lm = LOG_ZERO_MOLALITY; + /*s_x[i]->lg = 0.0;*/ + s_x[i]->lg_pitzer = 0.0; + } +/* + * Set master species activities + */ + + tc_x=solution_ptr->tc; + tk_x=tc_x+273.15; +/* + * H+, e-, H2O + */ + mass_water_aq_x = solution_ptr->mass_water; + mu_x = solution_ptr->mu; + s_h2o->moles = mass_water_aq_x/gfw_water; + s_h2o->la = log10(solution_ptr->ah2o); + AW = pow(10.0, s_h2o->la); + s_hplus->la = - solution_ptr->ph; + s_hplus->lm = s_hplus->la; + s_hplus->moles = exp(s_hplus->lm * LOG_10)*mass_water_aq_x; + s_eminus->la= - solution_ptr->solution_pe; + if (initial == TRUE) initial_guesses(); + if (diffuse_layer_x == TRUE) initial_surface_water(); + revise_guesses(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int initial_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make initial guesses for activities of master species and + * ionic strength + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.solution_ptr; + mu_x = s_hplus->moles + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + mu_x /= mass_water_aq_x; + s_h2o->la=0.0; + for ( i=0; i < count_unknowns; i++ ) { + if (x[i] == ph_unknown || x[i] == pe_unknown ) continue; + if (x[i]->type < CB) { + mu_x += x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * + x[i]->master[0]->s->z; + x[i]->master[0]->s->la = log10(x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == CB) { + x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { + x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); + } else if (x[i]->type == EXCH) { + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + x[i]->master[0]->s->la = log10(x[i]->moles); + } + } else if (x[i]->type == SURFACE) { + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); + } + } else if (x[i]->type == SURFACE_CB) { + x[i]->master[0]->s->la = 0.0; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int revise_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Revise molalities species + */ + int i; + int iter, max_iter, repeat, fail; + LDBLE weight, f; + + max_iter = 10; + /* gammas(mu_x);*/ + iter = 0; + repeat = TRUE; + fail = FALSE;; + while ( repeat == TRUE ) { + iter++; + if (debug_set == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nBeginning set iteration %d.\n", iter); + } + if (iter == max_iter + 1) { + output_msg(OUTPUT_LOG, "Did not converge in set, iteration %d.\n", iterations); + fail = TRUE; + } + if (iter > 2*max_iter) { + output_msg(OUTPUT_LOG, "Did not converge with relaxed criteria in set.\n"); + return(OK); + } + molalities(TRUE); + /*pitzer();*/ + /*s_h2o->la = 0.0;*/ + /*molalities(TRUE);*/ + mb_sums(); + if (state < REACTION) { + sum_species(); + } else { + for (i = 0; i < count_unknowns; i++) { + x[i]->sum = x[i]->f; + } + } + /*n + if (debug_set == TRUE) { + pr.species = TRUE; + pr.all = TRUE; + print_species(); + } + */ + repeat=FALSE; + for ( i=0; i < count_unknowns; i++ ) { + if (x[i] == ph_unknown || x[i] == pe_unknown) continue; + if (x[i]->type == MB || +/* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || + x[i]->type == SURFACE ) { + + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\t%5s at beginning of set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + if (fabs(x[i]->moles) < 1e-30) x[i]->moles = 0; + f = fabs(x[i]->sum); + if (f == 0 && x[i]->moles == 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + continue; + } else if (f == 0) { + repeat = TRUE; + x[i]->master[0]->s->la += 5; +/*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { + continue; + } else if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + if (x[i]->moles <= 0) { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } else { + repeat = TRUE; + x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); + } + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t%5s not converged in set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + } + } else if (x[i]->type == ALK) { + f = total_co2; + if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { + continue; + } + if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { + repeat = TRUE; + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + x[i]->master[0]->s->la += weight * + log10(fabs(x[i]->moles / x[i]->sum)); + if ( debug_set == TRUE ) { + output_msg(OUTPUT_MESSAGE,"%s not converged in set. %e\t%e\t%e\n", x[i]->description, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); + } + } + } + } + } + output_msg(OUTPUT_LOG,"Iterations in revise_guesses: %d\n", iter); + /*mu_x = mu_unknown->f * 0.5 / mass_water_aq_x;*/ + if (mu_x <= 1e-8) { + mu_x = 1e-8; + } + /*gammas(mu_x);*/ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int jacobian_pz(void) +/* ---------------------------------------------------------------------- */ +{ + double *base; + double d, d1, d2; + int i, j; + + if (full_pitzer == TRUE) { + molalities(TRUE); + pitzer(); + residuals(); + } + base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + if (base == NULL) malloc_error(); + for (i = 0; i < count_unknowns; i++) { + base[i] = residual[i]; + } + d = 0.0001; + d1 = d*log(10.0); + d2 = 0; + for (i = 0; i < count_unknowns; i++) { + switch (x[i]->type) { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case AH2O: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case PITZER_GAMMA: + x[i]->s->lg += d; + d2 = d; + break; + case MH2O: + mass_water_aq_x *= (1.0 + d); + x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; + d2 = log(1.0 + d); + break; + case MU: + case MH: + case PP: + case S_S_MOLES: + continue; + break; + } + molalities(TRUE); + if (full_pitzer == TRUE) pitzer(); + mb_sums(); + residuals(); + for (j = 0; j < count_unknowns; j++) { + array[j*(count_unknowns + 1) + i] = -(residual[j] - base[j])/d2; + } + switch (x[i]->type) { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case AH2O: + x[i]->master[0]->s->la -= d; + break; + case PITZER_GAMMA: + x[i]->s->lg -= d; + break; + case MH2O: + mass_water_aq_x /= (1 + d); + x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; + break; + } + } + molalities(TRUE); + if (full_pitzer == TRUE) pitzer(); + mb_sums(); + residuals(); + free_check_null(base); + return OK; +} +/* ---------------------------------------------------------------------- */ +int model_pz(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * model is called after the equations have been set up by prep + * and initial guesses have been made in set. + * + * Here is the outline of the calculation sequence: + * residuals--residuals are calculated, if small we are done + * sum_jacobian--jacobian is calculated + * ineq--inequality solver is called + * reset--estimates of unknowns revised, if changes are small solution + * has been found, usually convergence is found in residuals. + * gammas--new activity coefficients + * molalities--calculate molalities + * mb_sums--calculate mass-balance sums + * mb_gases--decide if gas_phase exists + * mb_s_s--decide if solid_solutions exists + * switch_bases--check to see if new basis species is needed + * reprep--rewrite equations with new basis species if needed + * revise_guesses--revise unknowns to get initial mole balance + * check_residuals--check convergence one last time + * sum_species--calculate sums of elements from species concentrations + * + * An additional pass through may be needed if unstable phases still exist + * in the phase assemblage. + */ + int kode, return_kode; + int r; + int count_infeasible, count_basis_change; + int debug_model_save; + int mass_water_switch_save; + if (svnid == NULL) fprintf(stderr," "); + +/* debug_model = TRUE; */ +/* debug_prep = TRUE; */ +/* debug_set = TRUE; */ + /* mass_water_switch == TRUE, mass of water is constant */ + mass_water_switch_save = mass_water_switch; + if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) { + mass_water_switch = TRUE; + } + debug_model_save = debug_model; + pe_step_size_now = pe_step_size; + step_size_now = step_size; + status(0, NULL); + iterations=0; + gamma_iterations = 0; + count_basis_change = count_infeasible = 0; + stop_program = FALSE; + remove_unstable_phases = FALSE; + if (always_full_pitzer == TRUE) { + full_pitzer = TRUE; + } else { + full_pitzer = FALSE; + } + for (; ; ) { + mb_gases(); + mb_s_s(); + kode = 1; + while ( ( r = residuals() ) != CONVERGED || remove_unstable_phases == TRUE) { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill*/, 0) == WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + iterations++; + if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { + set_forward_output_to_log(TRUE); + debug_model = TRUE; + } + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nIteration %d\tStep_size = %f\n", + iterations, (double) step_size_now); + output_msg(OUTPUT_MESSAGE,"\t\tPe_step_size = %f\n\n", (double) pe_step_size_now); + } + /* + * Iterations exceeded + */ + if (iterations > itmax ) { + sprintf(error_string,"Maximum iterations exceeded, %d\n",itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + /* + * Calculate jacobian + */ + gammas_pz(); + jacobian_sums(); + jacobian_pz(); + /* + * Full matrix with pure phases + */ + if ( r == OK || remove_unstable_phases == TRUE) { + return_kode = ineq(kode); + if ( return_kode != OK ) { + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE, "Ineq had infeasible solution, " + "kode %d, iteration %d\n", + return_kode, iterations); + } + output_msg(OUTPUT_LOG, "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, iterations); + count_infeasible++; + } + if ( return_kode == 2 ) { + ineq(0); + } + reset(); + } + gammas_pz(); + if (full_pitzer == TRUE) pitzer(); + if (always_full_pitzer == TRUE) { + full_pitzer = TRUE; + } else { + full_pitzer = FALSE; + } + molalities(TRUE); + if(use.surface_ptr != NULL && + use.surface_ptr->diffuse_layer == TRUE && + use.surface_ptr->related_phases == TRUE) + initial_surface_water(); + mb_sums(); + mb_gases(); + mb_s_s(); + /* debug + species_list_sort(); + sum_species(); + print_species(); + print_exchange(); + print_surface(); + */ + if (stop_program == TRUE) { + break; + } + } +/* + * Check for stop_program + */ + + if (stop_program == TRUE) { + break; + } + if (check_residuals() == ERROR) { + stop_program = TRUE; + break; + } + if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE && + mass_water_switch == TRUE) { + output_msg(OUTPUT_LOG,"\nChanging water switch to FALSE. Iteration %d.\n", iterations); + mass_water_switch = FALSE; + continue; + } + gamma_iterations++; + if (gamma_iterations > itmax ) { + sprintf(error_string,"Maximum gamma iterations exceeded, %d\n", itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + if (check_gammas_pz() != TRUE) { + full_pitzer = TRUE; + continue; + } + if (remove_unstable_phases == FALSE) break; + if (debug_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nRemoving unstable phases. Iteration %d.\n", iterations); + } + output_msg(OUTPUT_LOG,"\nRemoving unstable phases. Iteration %d.\n", iterations); + } + output_msg(OUTPUT_LOG,"\nNumber of infeasible solutions: %d\n",count_infeasible); + output_msg(OUTPUT_LOG,"Number of basis changes: %d\n\n",count_basis_change); + output_msg(OUTPUT_LOG,"Number of iterations: %d\n\n", iterations); + debug_model = debug_model_save; + set_forward_output_to_log(FALSE); + if (stop_program == TRUE) { + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int check_gammas_pz(void) +/* ---------------------------------------------------------------------- */ +{ + double old_aw, old_mu, tol; + int converge, i; + + old_mu = mu_x; + old_aw = s_h2o->la; + pitzer(); + molalities(TRUE); + mb_sums(); + converge = TRUE; + tol = convergence_tolerance*10.; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != PITZER_GAMMA) continue; + if (fabs(x[i]->s->lg - x[i]->s->lg_pitzer) > tol) { + converge = FALSE; + } + } + if (fabs(old_mu - mu_x) > tol) converge = FALSE; + if ((pow(10.0,s_h2o->la) - AW) > tol) converge = FALSE; + return converge; +} +/* ---------------------------------------------------------------------- */ +int gammas_pz () +/* ---------------------------------------------------------------------- */ +{ +/* + * Need exchange gammas for pitzer + */ + int i, j; + double coef; + /* Initialize */ +/* + * Calculate activity coefficients + */ + for (i=0; i < count_s_x; i++) { + switch (s_x[i]->gflag) { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + break; + case 4: /* Exchange */ + /* Now calculated in next loop */ + break; + case 5: /* Always 1.0 */ + break; + case 6: /* Surface */ +/* + * Find moles of sites. + * s_x[i]->equiv is stoichiometric coefficient of sites in species + */ + for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { + if (s_x[i]->rxn_x->token[j].s->type == SURF) { + s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->alk > 0) { + s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); + s_x[i]->dg = 0.0; + } else { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + break; + case 7: /* LLNL */ + break; + case 8: /* LLNL CO2*/ + break; + case 9: /* activity water */ + s_x[i]->lg = log10(exp( s_h2o->la * LOG_10) * gfw_water); + s_x[i]->dg = 0.0; + break; + } +/* + if (mu_unknown != NULL) { + if (fabs(residual[mu_unknown->number]) > 0.1 && + fabs(residual[mu_unknown->number])/mu_x > 0.5) { + s_x[i]->dg = 0.0; + } + } + */ + } + /* + * calculate exchange gammas + */ + + if (use.exchange_ptr != NULL) { + for (i=0; i < count_s_x; i++) { + switch (s_x[i]->gflag) { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + case 5: /* Always 1.0 */ + case 6: /* Surface */ + case 7: /* LLNL */ + case 8: /* LLNL CO2*/ + case 9: /* activity water */ + break; + case 4: /* Exchange */ + + /* + * Find CEC + * z contains valence of cation for exchange species, alk contains cec + */ + /* !!!!! */ + for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { + if (s_x[i]->rxn_x->token[j].s->type == EX) { + s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + /* + * Master species is a dummy variable with meaningless activity and mass + */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + if (s_x[i]->primary != NULL) { + break; + } + /* + * All other species + */ + + /* modific 29 july 2005... */ + if (s_x[i]->equiv != 0 && s_x[i]->alk > 0) { + s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + } + if (use.exchange_ptr->pitzer_exchange_gammas == TRUE) { + /* Assume equal gamma's of solute and exchangeable species... */ + for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { + if (s_x[i]->rxn_x->token[j].s->type == EX) continue; + coef = s_x[i]->rxn_x->token[j].coef; + s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg; + s_x[i]->dg += coef * s_x[i]->rxn_x->token[j].s->dg; + } + } + } + } + } +/* ...end modific 29 july 2005 */ + + return(OK); +} diff --git a/pitzer.h b/pitzer.h new file mode 100644 index 00000000..46c50843 --- /dev/null +++ b/pitzer.h @@ -0,0 +1,50 @@ +typedef enum { TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, TYPE_PSI, TYPE_ETHETA, TYPE_Other } pitz_param_type; + + +PITZER_EXTERNAL double VP, DW0; + +struct pitz_param { + char * species[3]; + int ispec[3]; + pitz_param_type type; + double p; + union {double b0; + double b1; + double b2; + double c0; + double theta; + double lamda; + double zeta; + double psi;} U; + double a[5]; + double alpha; + struct theta_param *thetas; +}; + +PITZER_EXTERNAL struct pitz_param **pitz_params; +PITZER_EXTERNAL int count_pitz_param, max_pitz_param; + + + +/* routines define in pitzer_structures.c */ +PITZER_EXTERNAL struct pitz_param *pitz_param_read (char *string, int n); +PITZER_EXTERNAL int pitz_param_search(struct pitz_param *pzp_ptr); +PITZER_EXTERNAL struct theta_param *theta_param_search(double zj, double zk); +PITZER_EXTERNAL struct theta_param *theta_param_alloc (void); +PITZER_EXTERNAL int theta_param_init (struct theta_param *theta_param_ptr); + + + +/* defined in DW */ +PITZER_EXTERNAL int DW (double T); +PITZER_EXTERNAL double DC (double T); + +struct theta_param { + double zj; + double zk; + double etheta; + double ethetap; +}; +PITZER_EXTERNAL struct theta_param **theta_params; +PITZER_EXTERNAL int count_theta_param, max_theta_param; +PITZER_EXTERNAL double OTEMP; diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp new file mode 100644 index 00000000..e42d13d1 --- /dev/null +++ b/pitzer_structures.cpp @@ -0,0 +1,195 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +#define PITZER_EXTERNAL extern +#include "pitzer.h" + +static char const svnid[] = "$Id: structures.c 269 2005-04-27 19:54:25Z dlpark $"; + + +static struct pitz_param *pitz_param_alloc (void); +static int pitz_param_init (struct pitz_param *pitz_param_ptr); +static struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); +static int pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr); + + +/* ********************************************************************** + * + * Routines related to structure "pitz_param" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pitz_param *pitz_param_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct pitz_param *pitz_param_ptr; + pitz_param_ptr = (struct pitz_param *) PHRQ_malloc(sizeof (struct pitz_param)); + if (pitz_param_ptr == NULL) malloc_error(); + return ( pitz_param_ptr ); +} +/* ---------------------------------------------------------------------- */ +int pitz_param_init (struct pitz_param *pitz_param_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Frees all data associated with pitz_param structure. + */ + + if (pitz_param_ptr == NULL) return(ERROR); + pitz_param_ptr->species[0] = NULL; + pitz_param_ptr->species[1] = NULL; + pitz_param_ptr->species[2] = NULL; + pitz_param_ptr->ispec[0] = -1; + pitz_param_ptr->ispec[1] = -1; + pitz_param_ptr->ispec[2] = -1; + pitz_param_ptr->type = TYPE_Other; + pitz_param_ptr->p = 0.0; + pitz_param_ptr->U.b0 = 0.0; + for (i = 0; i < 5; i++) { + pitz_param_ptr->a[i] = 0.0; + } + pitz_param_ptr->alpha = 0.0; + pitz_param_ptr->thetas = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct pitz_param *pitz_param_read (char *string, int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read pitzer parameter info from string + * n is number of species (character values) + * + */ + int l, i, j, k; + char *ptr; + char token[2*MAX_LENGTH]; + struct pitz_param pzp, *pzp_ptr; + + if (n != 2 && n != 3) return (NULL); + if (string == NULL) return (NULL); + + pitz_param_init(&pzp); + ptr = string; + if (copy_token(token, &ptr, &l) == EMPTY) return(NULL); + ptr = string; + for (i = 0; i < n; i++) { + if (copy_token(token, &ptr, &l) == EMPTY) return(NULL); + pzp.species[i] = string_hsave(token); + } + k = 0; + for (i = 0; i < 5; i++) { + if (copy_token(token, &ptr, &l) == EMPTY) break; + j=sscanf(token,"%le", &pzp.a[i]); + if (j <= 0) break; + k++; + } + if (k <= 0) return(NULL); + pzp_ptr = pitz_param_duplicate(&pzp); + return ( pzp_ptr); +} +/* ---------------------------------------------------------------------- */ +struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space and makes duplicate copy of pitz_param structure + */ + struct pitz_param *new_ptr; + + new_ptr = pitz_param_alloc(); + pitz_param_init(new_ptr); +/* + * Copy data + */ + pitz_param_copy(old_ptr, new_ptr); + return(new_ptr); +} +/* ---------------------------------------------------------------------- */ +int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies pitz_param data from old_ptr to new location, new_ptr. + * Space for the new_ptr structure must already be malloced. + */ +/* + * Store data for structure pitz_param + */ + memcpy(new_ptr, old_ptr, sizeof(struct pitz_param)); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pitz_param_search(struct pitz_param *pzp_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search of pitz_params for same type and species + * Returns -1 if not found, index number in pitz_params if found + */ + int i; + if (pzp_ptr == NULL) return -1; + if (pzp_ptr->type == TYPE_Other) return -1; + for (i = 0; i < count_pitz_param; i++) { + if (pitz_params[i]->type == pzp_ptr->type && + pitz_params[i]->species[0] == pzp_ptr->species[0] && + pitz_params[i]->species[1] == pzp_ptr->species[1] && + pitz_params[i]->species[2] == pzp_ptr->species[2] ) { + break; + } + } + if (i >= count_pitz_param) { + return -1; + } + return i; +} +/* ********************************************************************** + * + * Routines related to structure "theta_parm" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct theta_param *theta_param_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct theta_param *theta_param_ptr; + theta_param_ptr = (struct theta_param *) PHRQ_malloc(sizeof (struct theta_param)); + if (theta_param_ptr == NULL) malloc_error(); + return ( theta_param_ptr ); +} +/* ---------------------------------------------------------------------- */ +int theta_param_init (struct theta_param *theta_param_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data associated with theta_param structure. + */ + + if (theta_param_ptr == NULL) return(ERROR); + theta_param_ptr->zj = 0; + theta_param_ptr->zk = 0; + theta_param_ptr->etheta = 0; + theta_param_ptr->ethetap = 0; + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct theta_param *theta_param_search(double zj, double zk) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search of theta_params for same charge + * Returns NULL if not found, index number in theta_params if found + */ + int i; + for (i = 0; i < count_theta_param; i++) { + if ((theta_params[i]->zj == zj && theta_params[i]->zk == zk) || + (theta_params[i]->zj == zk && theta_params[i]->zk == zj)) { + return theta_params[i]; + } + } + return NULL; +} diff --git a/prep.cpp b/prep.cpp new file mode 100644 index 00000000..880aa76d --- /dev/null +++ b/prep.cpp @@ -0,0 +1,4055 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: prep.c 655 2005-11-14 23:06:29Z dlpark $"; + +static int add_potential_factor(void); +static int add_surface_charge_balance(void); +static int build_gas_phase(void); +static int build_jacobian_sums (int k); +static int build_mb_sums(void); +static int build_min_exch(void); +static int build_model(void); +static int build_pure_phases(void); +static int build_s_s_assemblage(void); +static int build_solution_phase_boundaries(void); +static int build_species_list(int n); +static int build_min_surface(void); +static int change_hydrogen_in_elt_list(LDBLE charge); +static int clear (void); +static int convert_units(struct solution *solution_ptr); +static struct unknown *find_surface_charge_unknown(char *str_ptr); +static struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr); +static int inout(void); +static int is_special(struct species *spec); +static int mb_for_species_aq(int n); +static int mb_for_species_ex(int n); +static int mb_for_species_surf(int n); +static int quick_setup (void); +static int resetup_master (void); +static int save_model(void); +static int setup_exchange (void); +static int setup_gas_phase(void); +static int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); +static int setup_pure_phases(void); +static int setup_related_surface (void); +static int setup_s_s_assemblage(void); +static int setup_solution (void); +static int setup_surface (void); +static int setup_unknowns (void); +static int store_dn (int k, LDBLE *source, int row, LDBLE coef_in, LDBLE *gamma_source); +static int store_jacob(LDBLE *source, LDBLE *target, LDBLE coef); +static int store_jacob0(int row, int column, LDBLE coef); +int store_mb(LDBLE *source, LDBLE *target, LDBLE coef); +static int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE *LDBLE_ptr, LDBLE coef, LDBLE *gamma_ptr); +static int store_sum_deltas(LDBLE *source, LDBLE *target, LDBLE coef); +static int tidy_redox (void); +static struct master **unknown_alloc_master(void); +static int write_mb_eqn_x (void); +static int write_mb_for_species_list (int n); +static int write_mass_action_eqn_x (int stop); + +/* ---------------------------------------------------------------------- */ +int prep(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input is model defined by the structure use. + * Most of routine is skipped if model, as defined by master.total + * plus use.pure_phases, is same as previous calculation. + * Routine sets up struct unknown for each unknown. + * Determines elements, species, and phases that are in the model. + * Calculates mass-action equations for each species and phase. + * Routine builds a set of lists for calculating mass balance and + * for building jacobian. + */ + struct solution *solution_ptr; + if (svnid == NULL) fprintf(stderr," "); + + if (state >= REACTION) { + same_model = check_same_model(); + } else { + same_model = FALSE; + last_model.force_prep = TRUE; + } + /*same_model = FALSE;*/ +/* + * Initialize s, master, and unknown pointers + */ + solution_ptr = use.solution_ptr; + if (solution_ptr == NULL) { + error_msg("Solution needed for calculation not found, stopping.", STOP); + } + description_x = (char *) free_check_null(description_x); + description_x = string_duplicate(solution_ptr->description); +/* + * Allocate space for unknowns + * Must allocate all necessary space before pointers to + * X are set. + */ + + if (same_model == FALSE) { + clear(); + setup_unknowns(); +/* + * Set unknown pointers, unknown types, validity checks + */ + if (state == INITIAL_SOLUTION) convert_units(solution_ptr); + setup_solution(); + setup_exchange(); + setup_surface(); + setup_pure_phases(); + setup_gas_phase(); + setup_s_s_assemblage(); + setup_related_surface(); + tidy_redox(); + if (input_error > 0) { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Allocate space for array + */ +/* + array = (LDBLE *) PHRQ_malloc( (size_t) (count_unknowns+1) * count_unknowns * sizeof( LDBLE )); + if (array == NULL) malloc_error(); + delta = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); + if (delta == NULL) malloc_error(); + residual = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); + if (residual == NULL) malloc_error(); +*/ + array = (LDBLE *) PHRQ_malloc( (size_t) (max_unknowns+1) * max_unknowns * sizeof( LDBLE )); + if (array == NULL) malloc_error(); + delta = (LDBLE *) PHRQ_malloc( (size_t) max_unknowns * sizeof( LDBLE )); + if (delta == NULL) malloc_error(); + residual = (LDBLE *) PHRQ_malloc( (size_t) max_unknowns * sizeof( LDBLE )); + if (residual == NULL) malloc_error(); +/* + * Build lists to fill Jacobian array and species list + */ + build_model(); + } else { +/* + * If model is same, just update masses, don't rebuild unknowns and lists + */ + quick_setup(); + } + if (input_error > 0) { + error_msg("Program stopping due to input errors.", STOP); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int quick_setup (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine is used if model is the same as previous model + * Assumes moles of elements, exchangers, surfaces, gases, and solid solutions have + * been accumulated in array master, usually by subroutine step. + * Updates essential information for the model. + */ + int i, j, k, l; + + for (i = 0; i < count_master; i++) { + if (master[i]->s->type == SURF_PSI) continue; + if (master[i]->s == s_eminus || + master[i]->s == s_hplus || + master[i]->s == s_h2o || + master[i]->s == s_h2 || + master[i]->s == s_o2) continue; + if(master[i]->total > 0) { + if (master[i]->s->secondary != NULL) { + master[i]->s->secondary->unknown->moles = master[i]->total; + } else { + master[i]->unknown->moles = master[i]->total; + } + } + } +/* + * Reaction: pH for charge balance + */ + ph_unknown->moles = use.solution_ptr->cb; +/* + * Reaction: pe for total hydrogen + */ + if (mass_hydrogen_unknown != NULL) { +#define COMBINE + /*#define COMBINE_CHARGE*/ +#ifdef COMBINE +#ifndef COMBINE_CHARGE + mass_hydrogen_unknown->moles = use.solution_ptr->total_h - 2 * use.solution_ptr->total_o; +#else + mass_hydrogen_unknown->moles = use.solution_ptr->total_h - 2 * use.solution_ptr->total_o - use.solution_ptr->cb; +#endif +#else + mass_hydrogen_unknown->moles = use.solution_ptr->total_h; +#endif + } +/* + * Reaction H2O for total oxygen + */ + if (mass_oxygen_unknown != NULL) { + mass_oxygen_unknown->moles = use.solution_ptr->total_o; + } + +/* + * pp_assemblage + */ + j = 0; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == PP) { + x[i]->moles = use.pp_assemblage_ptr->pure_phases[j].moles; + x[i]->dissolve_only = use.pp_assemblage_ptr->pure_phases[j].dissolve_only; + use.pp_assemblage_ptr->pure_phases[j].delta = 0.0; + x[i]->pure_phase = &(use.pp_assemblage_ptr->pure_phases[j]); + j++; + } + } +/* + * gas phase + */ + if (gas_unknown != NULL) { + gas_unknown->moles = 0.0; + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + gas_unknown->moles += use.gas_phase_ptr->comps[i].moles; + } + if (gas_unknown->moles <= 0) gas_unknown->moles = MIN_TOTAL; + gas_unknown->ln_moles = log(gas_unknown->moles); + gas_unknown->gas_phase = use.gas_phase_ptr; + } +/* + * s_s_assemblage + */ + if (s_s_unknown != NULL) { + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == S_S_MOLES) break; + } + for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (k = 0; k < use.s_s_assemblage_ptr->s_s[j].count_comps; k++) { + x[i]->s_s = &(use.s_s_assemblage_ptr->s_s[j]); + x[i]->s_s_comp = &(use.s_s_assemblage_ptr->s_s[j].comps[k]); + x[i]->s_s_comp_number = j; + x[i]->moles = x[i]->s_s_comp->moles; + if (x[i]->moles <= 0) { + x[i]->moles = MIN_TOTAL; + x[i]->s_s_comp->moles = MIN_TOTAL; + } + x[i]->s_s_comp->initial_moles = x[i]->moles; + x[i]->ln_moles = log(x[i]->moles); + + x[i]->phase->dn = x[i]->s_s_comp->dn; + x[i]->phase->dnb = x[i]->s_s_comp->dnb; + x[i]->phase->dnc = x[i]->s_s_comp->dnc; + x[i]->phase->log10_fraction_x = x[i]->s_s_comp->log10_fraction_x; + x[i]->phase->log10_lambda = x[i]->s_s_comp->log10_lambda; + i++; + } + } + } +/* + * exchange + */ + if (use.exchange_ptr != NULL) { + k = 0; + for (i = 0 ; i < count_unknowns; i++) { + if (x[i]->type == EXCH) { + x[i]->exch_comp = &(use.exchange_ptr->comps[k++]); + if (x[i]->exch_comp->rate_name != NULL) { + for (l = 0; x[i]->exch_comp->totals[l].elt != NULL; l++) { + if (x[i]->exch_comp->totals[l].elt->master->type != EX) continue; + if (strcmp_nocase(x[i]->description, x[i]->exch_comp->totals[l].elt->name) == 0) { + x[i]->moles = x[i]->exch_comp->totals[l].coef; +/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + break; + } + } + } + +#ifdef SKIP + if (count_kin_exch > 0) { + for (l = 0; x[i]->exch_comp->totals[l].elt != NULL; l++) { + if (x[i]->exch_comp->totals[l].elt->master->type != EX) continue; + if (strcmp_nocase(x[i]->description, x[i]->exch_comp->totals[l].elt->name) == 0) { + x[i]->moles = x[i]->exch_comp->totals[l].coef; +/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + } + } + } +#endif + } + } + } +/* + * surface + */ + if (use.surface_ptr != NULL) { + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == SURFACE) { + break; + } + } + j = 0; + k = 0; + for ( ; i < count_unknowns; i++) { + if (x[i]->type == SURFACE_CB) { + x[i]->surface_charge = &(use.surface_ptr->charge[j]); + x[i]->related_moles = x[i]->surface_charge->grams; + x[i]->mass_water = use.surface_ptr->charge[j++].mass_water; + x[i]->surface_comp = x[i-1]->surface_comp; + /* moles picked up from master->total */ + } else if (x[i]->type == SURFACE) { + x[i]->surface_comp = &(use.surface_ptr->comps[k++]); + /* moles picked up from master->total + except for surfaces related to kinetic minerals ... */ + if (x[i]->surface_comp->rate_name != NULL) { + for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; l++) { + if (x[i]->surface_comp->totals[l].elt->master->type != SURF) continue; + if (strcmp_nocase(x[i]->description, x[i]->surface_comp->totals[l].elt->name) == 0) { + x[i]->moles = x[i]->surface_comp->totals[l].coef; + /* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + } + } + } +/* !!!! */ +#ifdef SKIP + if (count_kin_surf > 0) { + for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; l++) { + if (x[i]->surface_comp->totals[l].elt->master->type != SURF) continue; + + if (strcmp_nocase(x[i]->description, x[i]->surface_comp->totals[l].elt->name) == 0) { + x[i]->moles = x[i]->surface_comp->totals[l].coef; +/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + } + } + } +#endif + } else { + break; + } + + } + } + save_model(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * sum of partial pressures equation and + * mass balance equations for elements contained in gases + */ + int i, j; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + struct gas_comp *gas_comp_ptr; + struct phase *phase_ptr; + struct unknown *unknown_ptr; + LDBLE coef, coef_elt; + + if (gas_unknown == NULL) return(OK); + for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { +/* + * Determine elements in gas component + */ + count_elts = 0; + paren_count = 0; + gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); + phase_ptr = gas_comp_ptr->phase; + if (phase_ptr->rxn_x == NULL) continue; + add_elt_list(phase_ptr->next_elt, 1.0); +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif +/* + * Build mass balance sums for each element in gas + */ + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\tMass balance summations %s.\n\n", + gas_comp_ptr->phase->name); + } + + /* All elements in gas */ + for (j = 0; j < count_elts; j++) { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name,"H") == 0) { + unknown_ptr = mass_hydrogen_unknown; + } else if (strcmp(elt_list[j].elt->name,"O") == 0) { + unknown_ptr = mass_oxygen_unknown; + } else { + if (elt_list[j].elt->primary->in == TRUE) { + unknown_ptr = elt_list[j].elt->primary->unknown; + } else if (elt_list[j].elt->primary->s->secondary != NULL) { + unknown_ptr = elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr != NULL) { + coef = elt_list[j].coef; + store_mb(&(gas_comp_ptr->phase->moles_x), &(unknown_ptr->f), coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\n", + unknown_ptr->description, + (double) coef); + } + } + } + if (use.gas_phase_ptr->type == PRESSURE) { + /* Total pressure of gases */ + store_mb(&(gas_comp_ptr->phase->p_soln_x), &(gas_unknown->f), 1.0); + } +/* + * Build jacobian sums for mass balance equations + */ + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\tJacobian summations %s.\n\n", + phase_ptr->name); + } + for (j = 0; j < count_elts; j++) { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name,"H") == 0) { + unknown_ptr = mass_hydrogen_unknown; + } else if (strcmp(elt_list[j].elt->name,"O") == 0) { + unknown_ptr = mass_oxygen_unknown; + } else { + if (elt_list[j].elt->primary->in == TRUE) { + unknown_ptr = elt_list[j].elt->primary->unknown; + } else if (elt_list[j].elt->primary->s->secondary != NULL) { + unknown_ptr = elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr == NULL) { +#ifdef SKIP + error_msg("NULL pointer in subroutine build_gas_phase.", STOP); +#endif + continue; + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\t%s.\n", + unknown_ptr->description); + } + row = unknown_ptr->number * (count_unknowns + 1); + coef_elt = elt_list[j].coef; + for (rxn_ptr = phase_ptr->rxn_x->token+1; + rxn_ptr->s != NULL; rxn_ptr++) { + + if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if (master_ptr == NULL) { + sprintf(error_string, "Element needed for gas component, %s, is not in model.", phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); + } + if (master_ptr->unknown == NULL) { +#ifdef SKIP + input_error++; +#endif + continue; + } + if (master_ptr->in == FALSE ) { + sprintf(error_string, "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + col = master_ptr->unknown->number; + coef = coef_elt * rxn_ptr->coef; + store_jacob (&(gas_comp_ptr->phase->moles_x), &(array[row + col]), coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, row/(count_unknowns+1), col); + } + } + if (use.gas_phase_ptr->type == PRESSURE) { + /* derivative wrt total moles of gas */ + store_jacob (&(gas_comp_ptr->phase->fraction_x), &(array[row + gas_unknown->number]), coef_elt); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n","gas moles", (double) elt_list[j].coef, row/(count_unknowns+1), gas_unknown->number); + } + } + } +/* + * Build jacobian sums for sum of partial pressures equation + */ + if (use.gas_phase_ptr->type != PRESSURE) continue; + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\tPartial pressure eqn %s.\n\n", + phase_ptr->name); + } + unknown_ptr = gas_unknown; + row = unknown_ptr->number * (count_unknowns + 1); + for (rxn_ptr = phase_ptr->rxn_x->token+1; + rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); + } + if (master_ptr->unknown == NULL) { +#ifdef SKIP + input_error++; +#endif + continue; + } + if (master_ptr->in == FALSE ) { + sprintf(error_string, "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + col = master_ptr->unknown->number; + coef = rxn_ptr->coef; + store_jacob (&(gas_comp_ptr->phase->p_soln_x), &(array[row + col]), coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, + row/(count_unknowns+1), col); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_s_s_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * mass action equation for component + * mass balance equations for elements contained in solid solutions + */ + int i, j, k, l, stop; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + struct s_s *s_s_ptr, *s_s_ptr_old; + char token[MAX_LENGTH]; + char *ptr; + + if (s_s_unknown == NULL) return(OK); + s_s_ptr_old = NULL; + col = 0; + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != S_S_MOLES) continue; + s_s_ptr = x[i]->s_s; + if (s_s_ptr != s_s_ptr_old) { + col = x[i]->number; + s_s_ptr_old = s_s_ptr; + } +/* + * Calculate function value (inverse saturation index) + */ + if (x[i]->phase->rxn_x == NULL) continue; + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + /* include mole fraction */ + store_mb(&(x[i]->phase->log10_fraction_x), &(x[i]->f), 1.0); + + /* include activity coeficient */ + store_mb(&(x[i]->phase->log10_lambda), &(x[i]->f), 1.0); +/* + * Put coefficients into mass action equations + */ + /* first IAP terms */ + for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s->secondary != NULL && + rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); + } + + if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) { +/* + * For binary solid solution + */ + /* next dnc terms */ + row = x[i]->number * (count_unknowns + 1); + if (x[i]->s_s_comp_number == 0) { + col = x[i]->number; + } else { + col = x[i]->number -1; + } + store_jacob (&(x[i]->phase->dnc), &(array[row + col]), -1); + + /* next dnb terms */ + col++; + store_jacob (&(x[i]->phase->dnb), &(array[row + col]), -1); + } else { +/* + * For ideal solid solution + */ + row = x[i]->number * (count_unknowns + 1); + for (j = 0; j < s_s_ptr->count_comps; j++) { + if (j != x[i]->s_s_comp_number) { +/* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ + store_jacob (&(x[i]->phase->dn), &(array[row + col + j]), -1.0); + } else { + store_jacob (&(x[i]->phase->dnb), &(array[row + col + j]), -1.0); + } + } + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + strcpy(token, x[i]->phase->formula); + ptr = token; + get_elts_in_species (&ptr, 1.0); +/* + * Go through elements in phase + */ +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (j = 0; j < count_elts; j++) { + + if (strcmp(elt_list[j].elt->name, "H") == 0 && mass_hydrogen_unknown != NULL) { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, elt_list[j].coef); + + } else if (strcmp(elt_list[j].elt->name, "O") == 0 && mass_oxygen_unknown != NULL) { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, elt_list[j].coef); + + } else { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) { + if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { + sprintf(error_string, "Element in phase, %s, is not in model.", x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } else if (master_ptr->in == TRUE ) { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } else if (master_ptr->in == REWRITE ) { + stop = FALSE; + for (k=0; k < count_unknowns; k++) { + if (x[k]->type != MB) continue; + for (l = 0; x[k]->master[l] != NULL; l++) { + if (x[k]->master[l] == master_ptr) { + store_jacob0(x[k]->master[0]->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &x[k]->master[0]->unknown->delta, + elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) break; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_jacobian_sums (int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function builds lists sum_jacob1 and sum_jacob2 that describe how to sum molalities + * to form jacobian. + */ + int i, j, kk; + int count_g; + LDBLE coef; + LDBLE *source, *target; + + if (debug_prep == TRUE) output_msg(OUTPUT_MESSAGE,"\n\tJacobian summations.\n"); +/* + * Calculate jacobian coefficients for each mass balance equation + */ + for (i = 0; i < count_mb_unknowns; i++) { +#ifdef SKIP + /* switch for mu term */ + if (diffuse_layer_x == TRUE && ((mb_unknowns[i].unknown == charge_balance_unknown) || + (mb_unknowns[i].unknown == ah2o_unknown) || + (mb_unknowns[i].unknown == mu_unknown))) { + use_tot_g = 1; + } else if (diffuse_layer_x == TRUE && mb_unknowns[i].unknown->type == SURFACE_CB) { + use_tot_g = 2; + } else { + use_tot_g = 0; + } +#endif +/* + * Store d(moles) for a mass balance equation + */ + /* initial solution only */ + if (mb_unknowns[i].unknown->type == SOLUTION_PHASE_BOUNDARY) { + continue; + } + coef = mb_unknowns[i].coef; + if (debug_prep == TRUE) output_msg(OUTPUT_MESSAGE,"\n\tMass balance eq: %s\t%f\n", + mb_unknowns[i].unknown->description, (double) coef); + store_dn(k, mb_unknowns[i].source, mb_unknowns[i].unknown->number, coef, mb_unknowns[i].gamma_source); +/* + * Add extra terms for change in dg/dx in diffuse layer model + */ + if (s[k]->type >= H2O || diffuse_layer_x == FALSE) { + continue; + } else if ( (mb_unknowns[i].unknown->type == MB || + mb_unknowns[i].unknown->type == MH || + mb_unknowns[i].unknown->type == MH2O) && state >= REACTION) { + if (mass_oxygen_unknown != NULL) { + /* term for water, sum of all surfaces */ + source = &s[k]->tot_dh2o_moles; + target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", "sum[dn(i,s)/dlnwater]", (double) coef, + mb_unknowns[i].unknown->number, mass_oxygen_unknown->number); + } + } + + /* terms for psi, one for each surface */ + count_g = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + source = &s[k]->diff_layer[count_g].dx_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + + x[j]->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + "dg/dlny", (double) coef, + mb_unknowns[i].unknown->number, + x[j]->number); + } + count_g++; + if (count_g >= use.surface_ptr->count_charge) break; + } + + /* terms for related phases */ + count_g = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + + /* has related phase */ + if (x[j-1]->surface_comp->phase_name == NULL) continue; + + /* now find the related phase */ + for (kk = count_unknowns - 1; kk >= 0; kk--) { + if (x[kk]->type != PP) continue; + if (x[kk]->phase->name == x[j-1]->surface_comp->phase_name) break; + } + + if (kk >= 0) { + source = &s[k]->diff_layer[count_g].drelated_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + + x[kk]->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + "dphase", (double) coef, + mb_unknowns[i].unknown->number, + x[kk]->number); + } + } + count_g++; + if (count_g >= use.surface_ptr->count_charge) break; + } + + } else if (mb_unknowns[i].unknown->type == SURFACE_CB) { + count_g = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + if (mb_unknowns[i].unknown->number == x[j]->number) { + source = &s[k]->diff_layer[count_g].dx_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + + x[j]->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + "dg/dlny", (double) coef, + mb_unknowns[i].unknown->number, + x[j]->number); + } + + /* term for related phase */ + /* has related phase */ + if (x[j-1]->surface_comp->phase_name != NULL) { + + /* now find the related phase */ + for (kk = count_unknowns - 1; kk >= 0; kk--) { + if (x[kk]->type != PP) continue; + if (x[kk]->phase->name == x[j-1]->surface_comp->phase_name) break; + } + if (kk >= 0) { + source = &s[k]->diff_layer[count_g].drelated_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + + x[kk]->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + "dphase", (double) coef, + mb_unknowns[i].unknown->number, + x[kk]->number); + } + } + } + + if (mass_oxygen_unknown != NULL) { + /* term for water, for same surfaces */ + source = &s[k]->diff_layer[count_g].dh2o_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + mass_oxygen_unknown->number]); + store_jacob(source, target, coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + "dn(i,s)/dlnwater", (double) coef, + mb_unknowns[i].unknown->number, + mass_oxygen_unknown->number); + } + } + break; + } + count_g++; + if (count_g >= use.surface_ptr->count_charge) break; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_mb_sums(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function builds lists sum_mb1 and sum_mb2 that describe how to sum molalities + * to calculate mass balance sums, including activity of water, ionic strength, + * charge balance, and alkalinity. + */ + int i; + LDBLE *target; +/* + * Make space for lists + */ + if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) { + space ((void **) ((void *) &sum_mb1), count_sum_mb1 + count_mb_unknowns, + &max_sum_mb1, sizeof(struct list1)); + } + if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) { + space ((void **) ((void *) &sum_mb2), count_sum_mb2 + count_mb_unknowns, + &max_sum_mb2, sizeof(struct list2)); + } + + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\n\tMass balance summations.\n\n"); + } + for (i = 0; i < count_mb_unknowns; i++) { + target = &(mb_unknowns[i].unknown->f); + store_mb(mb_unknowns[i].source, target, mb_unknowns[i].coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\n", + mb_unknowns[i].unknown->description, + (double) mb_unknowns[i].coef); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Guts of prep. Determines species in model, rewrites equations, + * builds lists for mass balance and jacobian sums. + */ + int i, j, j0, k; + LDBLE coef_e; + + if (s_hplus == NULL || s_eminus == NULL || s_h2o == NULL) { + error_msg("Data base is missing H+, H2O, or e- species.", CONTINUE); + input_error++; + } +/* + * Make space for lists of pointers to species in the model + */ + + max_s_x = MAX_S; + space ((void **) ((void *) &s_x), INIT, &max_s_x, sizeof(struct species *)); + + max_sum_mb1=MAX_SUM_MB; + count_sum_mb1=0; + space ((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, sizeof(struct list1)); + + max_sum_mb2=MAX_SUM_MB; + count_sum_mb2=0; + space ((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, sizeof(struct list2)); + + max_sum_jacob0=MAX_SUM_JACOB0; + count_sum_jacob0=0; + space ((void **) ((void *) &sum_jacob0), INIT, &max_sum_jacob0, + sizeof(struct list0)); + + max_sum_jacob1=MAX_SUM_JACOB1; + count_sum_jacob1=0; + space ((void **) ((void *) &sum_jacob1), INIT, &max_sum_jacob1, + sizeof(struct list1)); + + max_sum_jacob2=MAX_SUM_JACOB2; + count_sum_jacob2=0; + space ((void **) ((void *) &sum_jacob2), INIT, &max_sum_jacob2, + sizeof(struct list2)); + + + max_sum_delta=MAX_SUM_JACOB0; + count_sum_delta=0; + space ((void **) ((void *) &sum_delta), INIT, &max_sum_delta, + sizeof(struct list2)); + + max_species_list = 5 * MAX_S; + count_species_list = 0; + species_list = (struct species_list *) free_check_null(species_list); + space ((void **) ((void *) &species_list), INIT, &max_species_list, + sizeof (struct species_list)); + +/* + * Pick species in the model, determine reaction for model, build jacobian + */ + count_s_x=0; + compute_gfw("H2O", &gfw_water); + gfw_water *= 0.001; + for (i=0; i < count_s; i++) { + if (s[i]->type > H2O && s[i]->type != EX && s[i]->type != SURF) continue; + s[i]->in=FALSE; + count_trxn=0; + trxn_add (s[i]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ +/* + * Check if species is in model + */ + s[i]->in = inout(); + if (s[i]->in == TRUE) { + /* for isotopes, activity of water is for 1H and 16O */ + if (s[i]->gflag == 9 ) { + gfw_water = 18.0/1000.0; + } + if (pitzer_model == FALSE) s[i]->lg = 0.0; + if (count_s_x + 1 >= max_s_x) { + space ((void **) ((void *) &s_x), count_s_x + 1, + &max_s_x, + sizeof (struct species *)); + } + s_x[count_s_x++] = s[i]; +/* + * Write mass action equation for current model + */ + write_mass_action_eqn_x(STOP); + if (s[i]->type == SURF) { + add_potential_factor(); + } + rxn_free(s[i]->rxn_x); + s[i]->rxn_x = rxn_alloc(count_trxn+1); + trxn_copy (s[i]->rxn_x); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\nSpecies: %s\n", s[i]->name); + trxn_print(); + } +/* + * Determine mass balance equations, build sums for mass balance, build sums for jacobian + */ + count_trxn=0; + trxn_add (s[i]->rxn_s, 1.0, FALSE); + if (s[i]->next_secondary == NULL) { + write_mb_eqn_x(); + } else { + count_elts = 0; + add_elt_list(s[i]->next_secondary, 1.0); + } + if (s[i]->type == SURF) { + add_potential_factor(); + add_surface_charge_balance(); + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"%s\n", trxn.token[0].s->name); + for (j = 0; j < count_elts; j++) { + output_msg(OUTPUT_MESSAGE,"\t%s\t%f\n", elt_list[j].elt->name, (double) elt_list[j].coef); + } + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\nSpecies: %s\n", s[i]->name); + trxn_print(); + } + if (s[i]->type < EMINUS) { + mb_for_species_aq(i); + } else if (s[i]->type == EX) { + mb_for_species_ex(i); + } else if (s[i]->type == SURF) { + mb_for_species_surf(i); + } +#ifdef COMBINE + build_mb_sums(); +#else + if (s[i] != s_h2o) { + build_mb_sums(); + } +#endif + if (!pitzer_model) build_jacobian_sums(i); +/* + * Build list of species for summing and printing + */ + if (s[i]->next_secondary == NULL) { + write_mb_for_species_list(i); + } else { + count_elts = 0; + add_elt_list(s[i]->next_secondary, 1.0); + } + build_species_list(i); + } + } + if (diffuse_layer_x == TRUE && pitzer_model == TRUE) { + error_msg("-diffuse_layer option not available for Pizer model", STOP); + } +/* + * Sum diffuse layer water into hydrogen and oxygen mass balances + */ + if (diffuse_layer_x == TRUE && state >= REACTION) { + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == SURFACE_CB) { +#ifndef COMBINE + store_mb(&(x[i]->mass_water), + &(mass_hydrogen_unknown->f), + 2 / gfw_water); +#endif + if (mass_oxygen_unknown != NULL) { + store_mb(&(x[i]->mass_water), + &(mass_oxygen_unknown->f), + 1 / gfw_water); + } + } + } + } +/* + * For Pizer model add lg unknown for each aqueous species + */ + + if (pitzer_model == TRUE) { + j0 = count_unknowns; + j = count_unknowns + count_s_x; + k = j0; + for (i = j0; i < j; i++) { + if (s_x[i - j0]->type == EX) continue; + if (s_x[i - j0]->type == SURF) continue; + x[k]->number = k; + x[k]->type = PITZER_GAMMA; + x[k]->s = s_x[i - j0]; + x[k]->description = s_x[i - j0]->name; + k++; + count_unknowns++; + } + } +/* + * Rewrite phases to current master species + */ + for (i=0; i < count_phases; i++) { + count_trxn=0; + trxn_add(phases[i]->rxn_s, 1.0, FALSE); + trxn_reverse_k(); + phases[i]->in = inout(); + if (phases[i]->in == TRUE) { +/* + * Replace e- in original equation with default redox reaction + */ + coef_e=trxn_find_coef ("e-", 1); + if ( equal(coef_e,0.0,TOL) == FALSE ) { + trxn_add( pe_x[default_pe_x].rxn, coef_e, TRUE); + } +/* + * Rewrite reaction to current master species + */ + write_mass_action_eqn_x(STOP); + trxn_reverse_k(); + rxn_free(phases[i]->rxn_x); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\nPhase: %s\n", phases[i]->name); + trxn_print(); + } + phases[i]->rxn_x = rxn_alloc(count_trxn+1); + trxn_copy (phases[i]->rxn_x); + write_phase_sys_total(i); + } + } + build_solution_phase_boundaries(); + build_pure_phases(); + build_min_exch(); + build_min_surface(); + build_gas_phase(); + build_s_s_assemblage(); +/* + * Sort species list, by master only + */ + qsort (&species_list[0], (size_t) count_species_list, + (size_t) sizeof(struct species_list), species_list_compare_master); +/* + * Print size information to logfile + */ +/* + output_msg(OUTPUT_LOG, "\nMemory used:\n"); + output_msg(OUTPUT_LOG, "count_s: %d\tmax_s: %d\t\tbytes: %d\n", count_s, max_s, (int) (max_s * sizeof(struct species))); + output_msg(OUTPUT_LOG, "count_s_x: %d\tmax_s_x: %d\t\tbytes: %d\n", count_s_x, max_s_x, (int) (max_s_x * sizeof(struct species *))); + output_msg(OUTPUT_LOG, "count_sum_mb1: %d\tmax_sum_mb1: %d\t\tbytes: %d\n", count_sum_mb1, max_sum_mb1, (int) (max_sum_mb1 * sizeof(struct list1))); + output_msg(OUTPUT_LOG, "count_sum_mb2: %d\tmax_sum_mb2: %d\t\tbytes: %d\n", count_sum_mb2, max_sum_mb2, (int) (max_sum_mb2 * sizeof(struct list2))); + output_msg(OUTPUT_LOG, "count_sum_jacob0: %d\tmax_sum_jacob0: %d\t\tbytes: %d\n", count_sum_jacob0, max_sum_jacob0, (int) (max_sum_jacob0 * sizeof(struct list0))); + output_msg(OUTPUT_LOG, "count_sum_jacob1: %d\tmax_sum_jacob1: %d\t\tbytes: %d\n", count_sum_jacob1, max_sum_jacob1, (int) (max_sum_jacob1 * sizeof(struct list1))); + output_msg(OUTPUT_LOG_LOG, "count_sum_jacob2: %d\tmax_sum_jacob2: %d\t\tbytes: %d\n", count_sum_jacob2, max_sum_jacob2, (int) (max_sum_jacob2 * sizeof(struct list2))); + output_msg(OUTPUT_LOG_LOG, "count_sum_delta: %d\tmax_sum_delta: %d\t\tbytes: %d\n", count_sum_delta, max_sum_delta, (int) (max_sum_delta * sizeof(struct list2))); + output_msg(OUTPUT_LOG, "count_unknowns: %d\n", count_unknowns); + output_msg(OUTPUT_LOG_LOG, "\n"); + */ +/* + * Save model description + */ + /* if (state >= REACTION) save_model(); */ + save_model(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Includes calculation of inverse saturation index in sum_mb. + * Puts coefficients in iap and mass balance equations for each phase. + */ + int i; + int stop, j, k, l; + char token[MAX_LENGTH]; + char *ptr; + struct master *master_ptr; + struct rxn_token *rxn_ptr; +/* + * Build into sums the logic to calculate inverse saturation indices for + * pure phases + */ + if (pure_phase_unknown == NULL) return(OK); +/* + * Calculate inverse saturation index + */ + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) continue; + if (pure_phase_unknown == NULL) pure_phase_unknown = x[i]; + + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + store_mb(&(x[i]->si), &(x[i]->f), 1.0); + + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + } + for (i = 0; i < count_unknowns; i++) { +/* + * rxn_x is null if an element in phase is not in solution + */ + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) continue; +/* + * Put coefficients into IAP equations + */ + for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s->secondary != NULL && + rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + if (x[i]->pure_phase->add_formula != NULL) { + strcpy(token, x[i]->pure_phase->add_formula); + ptr = token; + get_elts_in_species (&ptr, 1.0); + } else { + strcpy(token, x[i]->phase->formula); + ptr = token; + get_elts_in_species (&ptr, 1.0); + } +/* + * Go through elements in phase + */ + +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (j = 0; j < count_elts; j++) { + + if (strcmp(elt_list[j].elt->name, "H") == 0 && mass_hydrogen_unknown != NULL) { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, elt_list[j].coef); + + } else if (strcmp(elt_list[j].elt->name, "O") == 0 && mass_oxygen_unknown != NULL) { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, elt_list[j].coef); + + } else { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) { + if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { + sprintf(error_string, "Element in phase, %s, is not in model.", x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } else if (master_ptr->in == TRUE ) { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } else if (master_ptr->in == REWRITE ) { + stop = FALSE; + for (k=0; k < count_unknowns; k++) { + if (x[k]->type != MB) continue; + for (l = 0; x[k]->master[l] != NULL; l++) { + if (x[k]->master[l] == master_ptr) { + store_jacob0(x[k]->master[0]->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &x[k]->master[0]->unknown->delta, + elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) break; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_solution_phase_boundaries(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + struct rxn_token *rxn_ptr; +/* + * Build into sums the logic to calculate inverse saturation indices for + * solution phase boundaries + */ + if (solution_phase_boundary_unknown == NULL) return(OK); +/* + * Calculate inverse saturation index + */ + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != SOLUTION_PHASE_BOUNDARY) continue; + + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + store_mb(&(x[i]->si), &(x[i]->f), 1.0); + if (x[i]->phase->in != TRUE) { + sprintf(error_string, "Solution does not contain all elements for phase-boundary mineral, %s.", x[i]->phase->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + } + if (input_error > 0) return(ERROR); +/* + * Put coefficients into array + */ + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != SOLUTION_PHASE_BOUNDARY) continue; + for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s->secondary != NULL && + rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if (master_ptr->unknown == NULL) continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_species_list(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Builds a list that includes an entry for each master species in each + * secondary reaction. Used for summing species of each element and + * printing results. + */ + int j; + struct master *master_ptr; +/* + * Check space and store reaction token name and pointer to species + */ + if (count_species_list + count_elts >= max_species_list) { + space ((void **) ((void *) &species_list), count_species_list + count_elts, + &max_species_list, sizeof (struct species_list)); + } +/* + * Treat species made only with H+, e-, and H2O specially + */ + if ( is_special(s[n]) == TRUE ) { + species_list[count_species_list].master_s = s_hplus; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = 0.0; + count_species_list++; + return(OK); + } +/* + * Treat exchange species specially + */ + if (s[n]->type == EX) { + if (s[n]->primary != NULL) return(OK); /* master species has zero molality */ + for (j = 0; j < count_elts; j++) { + if ( elt_list[j].elt->master->s->type != EX ) continue; + master_ptr = elt_list[j].elt->master; + species_list[count_species_list].master_s = elt_list[j].elt->master->s; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return(OK); + } +/* + * Treat surface species specially + */ + if (s[n]->type == SURF_PSI) return(OK); + if (s[n]->type == SURF) { + for (j=0; j < count_elts; j++) { + if ( elt_list[j].elt->master->s->type != SURF ) continue; + master_ptr = elt_list[j].elt->master; + species_list[count_species_list].master_s = elt_list[j].elt->master->s; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return(OK); + } +/* + * Other aqueous species + */ + for (j=0; j < count_elts; j++) { + if ( is_special(elt_list[j].elt->master->s) == TRUE ) continue; + if (elt_list[j].elt->master->s->secondary != NULL) { + master_ptr = elt_list[j].elt->master->s->secondary; + } else { + master_ptr = elt_list[j].elt->master->s->primary; + } + species_list[count_species_list].master_s = master_ptr->s; + species_list[count_species_list].s = s[n]; +/* + * Find coefficient for element represented by master species + */ + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int clear (void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Resets information for setting up a new model + */ + struct solution *solution_ptr; +/* + * Clear species solution-dependent data + */ + solution_ptr = use.solution_ptr; + + for (i=0; i < count_s; i++) { + s[i]->in=FALSE; + } +/* + * Set pe structure + */ + pe_data_free(pe_x); + pe_x = pe_data_dup(solution_ptr->pe); + default_pe_x = solution_ptr->default_pe; +/* + * Clear master species solution-dependent data + */ + for (i=0; i < count_master; i++) { + master[i]->in=FALSE; + master[i]->unknown=NULL; + master[i]->pe_rxn = &(pe_x[solution_ptr->default_pe].rxn); +/* + * copy primary reaction to secondary reaction + */ + rxn_free (master[i]->rxn_secondary); + master[i]->rxn_secondary = rxn_dup (master[i]->rxn_primary); + } + + if (state == INITIAL_SOLUTION) { + s_h2o->secondary->in=TRUE; + s_hplus->secondary->in=TRUE; + } else { + s_h2o->primary->in=TRUE; + s_hplus->primary->in=TRUE; + } + s_eminus->primary->in=TRUE; +/* + * Set all unknown pointers to NULL + */ + mb_unknown = NULL; + ah2o_unknown = NULL; + mass_hydrogen_unknown = NULL; + mass_oxygen_unknown = NULL; + mu_unknown = NULL; + alkalinity_unknown = NULL; + carbon_unknown = NULL; + ph_unknown = NULL; + pe_unknown = NULL; + charge_balance_unknown = NULL; + solution_phase_boundary_unknown = NULL; + pure_phase_unknown = NULL; + exchange_unknown = NULL; + surface_unknown = NULL; + gas_unknown = NULL; + s_s_unknown = NULL; +/* + * Free arrays used in model + */ + free_model_allocs(); + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int convert_units(struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Converts solution concentrations to moles/kg water + * Uses totals.input conc to calculate totals.moles. + */ + int i, l; + LDBLE sum_solutes; + char c; + struct master *master_ptr; + struct conc *tot_ptr; + char token[MAX_LENGTH]; + char *ptr; +/* + * Convert units + */ + sum_solutes= exp(-solution_ptr->ph * LOG_10); + for ( i=0; solution_ptr->totals[i].description != NULL; i++) { + master_ptr = master_bsearch (solution_ptr->totals[i].description); + if (master_ptr != NULL) { + if (master_ptr->minor_isotope == TRUE) continue; + } + tot_ptr=&(solution_ptr->totals[i]); + tot_ptr->moles = 0.0; + if (strcmp(tot_ptr->description,"H(1)") == 0 || + strcmp(tot_ptr->description,"E" ) == 0 ) { + continue; + } + if (tot_ptr->input_conc <= 0) continue; +/* + * Get gfw + */ + /* use given gfw if gfw > 0.0 */ + /* use formula give with "as" */ + if (tot_ptr->gfw <= 0.0) { + if ( tot_ptr->as != NULL ) { + /* use given chemical formula to calculate gfw */ + if (compute_gfw(tot_ptr->as, &(tot_ptr->gfw) ) == ERROR ) { + sprintf(error_string, "Could not compute gfw, %s.", tot_ptr->as); + error_msg(error_string, CONTINUE); + input_error++; + } + if (strcmp (tot_ptr->description,"Alkalinity") == 0 && + strcmp (tot_ptr->as, "CaCO3") == 0) { + tot_ptr->gfw /= 2.; + sprintf(error_string, "Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.", (double) tot_ptr->gfw); + warning_msg(error_string); + } + /* use gfw of master species */ + } else { + ptr = tot_ptr->description; + copy_token(token, &ptr, &l); + master_ptr = master_bsearch (token); + if (master_ptr != NULL) { + /* use gfw for element redox state*/ + tot_ptr->gfw = master_ptr->gfw; + } else { + sprintf(error_string, "Could not find gfw, %s.", tot_ptr->description); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } + } +/* + * Convert liters to kg solution + */ + tot_ptr->moles=tot_ptr->input_conc; + if (strstr (solution_ptr->units, "/l") != NULL ) { + tot_ptr->moles *= 1.0/(solution_ptr->density); + } +/* + * Convert milli or micro + */ + c=tot_ptr->units[0]; + if (c == 'm') { + tot_ptr->moles *= 1e-3; + } else if ( c == 'u' ) { + tot_ptr->moles *= 1e-6; + } +/* + * Sum grams of solute, convert from moles necessary + */ + if (strstr (tot_ptr->units, "g/kgs") != NULL || + strstr (tot_ptr->units,"g/l") != NULL ) { + sum_solutes += tot_ptr->moles; + } else if (strstr (tot_ptr->units, "Mol/kgs") != NULL || + strstr (tot_ptr->units, "Mol/l") != NULL || + strstr (tot_ptr->units, "eq/l") != NULL ) { + sum_solutes += (tot_ptr->moles)*(tot_ptr->gfw); + } +/* + * Convert grams to moles, if necessary + */ + if ( strstr (tot_ptr->units, "g/") != NULL && tot_ptr->gfw != 0.0) { + tot_ptr->moles /= tot_ptr->gfw; + } + } +/* + * Convert /kgs to /kgw + */ + if (strstr( solution_ptr->units, "kgs") != NULL || + strstr( solution_ptr->units, "/l") != NULL ) { + mass_water_aq_x = 1.0 - 1e-3*sum_solutes; + for ( i=0; solution_ptr->totals[i].description != NULL; i++) { + solution_ptr->totals[i].moles /= mass_water_aq_x; + } + } +/* + * Scale by mass of water in solution + */ + mass_water_aq_x = solution_ptr->mass_water; + for ( i=0; solution_ptr->totals[i].description != NULL; i++) { + solution_ptr->totals[i].moles *= mass_water_aq_x; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input: ptr contains a list of one or more master species names + * Output: space is allocated and a list of master species pointers is + * returned. + */ + int j, l, count_list; + char token[MAX_LENGTH]; + struct master **master_ptr_list; + struct master *master_ptr0; +/* + * Make list of master species pointers + */ + count_list = 0; + master_ptr_list = unknown_alloc_master(); + master_ptr0=master_ptr; + if (master_ptr0 == master_ptr->s->primary) { +/* + * First in list is primary species + */ + for (j = 0; j < count_master; j++) { + if (master[j] == master_ptr0) break; + } + j++; +/* + * Element has only one valence + */ + if ( j >= count_master || master[j]->elt->primary != master_ptr0) { + master_ptr_list[count_list++] = master_ptr0; +/* + * Element has multiple valences + */ + } else { + if (master_ptr0->s->secondary == NULL) { + sprintf(error_string, "Master species for valence states of element %s are not correct.\n\tPossibly related to master species for %s.", master_ptr0->elt->name, master[j]->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + } + master_ptr_list[count_list++] = master_ptr0->s->secondary; + while (j < count_master && master[j]->elt->primary == master_ptr0) { + if (master[j]->s->primary == NULL) { + master_ptr_list = (struct master **) PHRQ_realloc((void *) master_ptr_list, (size_t) (count_list + 2) * sizeof(struct master *)); + if (master_ptr_list == NULL) malloc_error(); + master_ptr_list[count_list++] = master[j]; + } + j++; + } + } + } else { +/* + * First in list is secondary species, Include all valences from input + */ + master_ptr_list[count_list++]=master_ptr0; + while (copy_token(token,&ptr, &l) != EMPTY) { + master_ptr = master_bsearch(token); + if (master_ptr != NULL) { + master_ptr_list = (struct master **) PHRQ_realloc((void *) master_ptr_list, (size_t) (count_list + 2) * sizeof(struct master *)); + if (master_ptr_list == NULL) malloc_error(); + master_ptr_list[count_list++] = master_ptr; + } + } + } + master_ptr_list[count_list] = NULL; + return (master_ptr_list); +} +/* ---------------------------------------------------------------------- */ +int inout(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct rxn_token_temp *token_ptr; +/* + * Routine goes through trxn to determine if each master species is + * in this model. + * Assumes equation is written in terms of primary and secondary species + * Checks to see if in is TRUE or REWRITE for each species + * Returns TRUE if in model + * FALSE if not + */ + for (i=1; i < count_trxn; i++) { + token_ptr = &(trxn.token[i]); + /* Check primary master species in */ + if (token_ptr->s->primary != NULL && (token_ptr->s->primary->in == TRUE) ) continue; + /* Check secondary master species */ + if ( (token_ptr->s->secondary != NULL) && (token_ptr->s->secondary->in != FALSE) ) { + continue; + } + /* Must be primary master species that is out */ + return(FALSE); + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int is_special(struct species *spec) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks to see if a species is composed of only H, O, and e- + * Returns TRUE if true + * FALSE if not + */ + int special; + struct rxn_token *token_ptr; + + special = TRUE; + for ( token_ptr = spec->rxn_s->token + 1; token_ptr->s != NULL; token_ptr++) { + if (token_ptr->s != s_hplus && + token_ptr->s != s_h2o && + token_ptr->s != s_eminus ) { + special = FALSE; + break; + } + } + return(special); +} +/* ---------------------------------------------------------------------- */ +int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE *LDBLE_ptr, LDBLE coef, LDBLE *gamma_ptr) +/* ---------------------------------------------------------------------- */ +/* + * Takes an unknown pointer and a coefficient and puts in + * list of mb_unknowns + */ +{ + if (equal(coef, 0.0, TOL) == TRUE) return(OK); + if ( (count_mb_unknowns + 1) >= max_mb_unknowns) { + space ((void **) ((void *) &mb_unknowns), count_mb_unknowns + 1, &max_mb_unknowns, + sizeof(struct unknown_list)); + } + mb_unknowns[count_mb_unknowns].unknown = unknown_ptr; + mb_unknowns[count_mb_unknowns].source = LDBLE_ptr; + mb_unknowns[count_mb_unknowns].gamma_source = gamma_ptr; + mb_unknowns[count_mb_unknowns].coef = coef; + count_mb_unknowns++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_for_species_aq(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i, j; + struct master *master_ptr; + + count_mb_unknowns = 0; +/* + * e- does not appear in any mass balances + */ + if (s[n]->type == EMINUS) return(OK); +/* + * Do not include diffuse layer in cb, alk, ah2o, mu + */ + if (charge_balance_unknown != NULL && s[n]->type < H2O) { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); + } + if (alkalinity_unknown != NULL && s[n]->type < H2O ) { + store_mb_unknowns(alkalinity_unknown, &s[n]->moles, s[n]->alk, &s[n]->dg); + } + if (ah2o_unknown != NULL && s[n]->type < H2O ) { + store_mb_unknowns(ah2o_unknown, &s[n]->moles, 1.0, &s[n]->dg); + } + if (mu_unknown != NULL && s[n]->type < H2O ) { + store_mb_unknowns(mu_unknown, &s[n]->moles, s[n]->z * s[n]->z, &s[n]->dg); + } +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (mass_hydrogen_unknown != NULL ) { + if (diffuse_layer_x == TRUE && state >= REACTION) { +#ifdef COMBINE +#ifndef COMBINE_CHARGE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h - 2 *s[n]->o, &s[n]->dg_total_g); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h - 2 *s[n]->o - s[n]->z, &s[n]->dg_total_g); +#endif +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h, &s[n]->dg_total_g ); +#endif + } else { +#ifdef COMBINE +#ifndef COMBINE_CHARGE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2* s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2* s[n]->o - s[n]->z, &s[n]->dg); +#endif +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg); +#endif + } + } + if (mass_oxygen_unknown != NULL ) { + if (diffuse_layer_x == TRUE && state >= REACTION) { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->tot_g_moles, s[n]->o, &s[n]->dg_total_g ); + } else { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); + } + } +/* + * Sum diffuse layer charge into (surface + DL) charge balance + */ + if (use.surface_ptr != NULL && s[n]->type < H2O && diffuse_layer_x == TRUE) { + j = 0; + for(i = 0; i < count_unknowns; i++) { + if (x[i]->type == SURFACE_CB) { + store_mb_unknowns(x[i], &s[n]->diff_layer[j].g_moles, s[n]->z, &s[n]->diff_layer[j].dg_g_moles); + j++; + } + } + } +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) { + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) { + if (master_ptr->s->secondary != NULL) { + master_ptr = master_ptr->s->secondary; + } + } + if (master_ptr->unknown == ph_unknown ) { + continue; + } else if (master_ptr->unknown == pe_unknown ) { + continue; + } else if (master_ptr->unknown == charge_balance_unknown ) { + continue; + } else if (master_ptr->unknown == alkalinity_unknown ) { + continue; + } else if (master_ptr->unknown->type == SOLUTION_PHASE_BOUNDARY ) { + continue; + } + if (diffuse_layer_x == TRUE && state >= REACTION) { + store_mb_unknowns(master_ptr->unknown, + &s[n]->tot_g_moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg_total_g ); + } else { + store_mb_unknowns(master_ptr->unknown, + &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_for_species_ex(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert exchange species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i; + struct master *master_ptr; + count_mb_unknowns = 0; +/* + * Master species for exchange do not appear in any mass balances + */ + if (s[n]->type == EX && s[n]->primary != NULL) return(OK); +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (charge_balance_unknown != NULL) { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); + } + if (mass_hydrogen_unknown != NULL ) { +#ifdef COMBINE +#ifndef COMBINE_CHARGE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2 * s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2 * s[n]->o - s[n]->z, &s[n]->dg); +#endif +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg ); +#endif + } + if (mass_oxygen_unknown != NULL ) { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); + } +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) { + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) { + if (master_ptr->s->secondary != NULL) { + master_ptr = master_ptr->s->secondary; + } + } +/* + * Special for ph_unknown, pe_unknown, and alkalinity_unknown + */ + if (master_ptr->unknown == ph_unknown ) { + continue; + } else if (master_ptr->unknown == pe_unknown ) { + continue; + } else if (master_ptr->unknown == alkalinity_unknown ) { + continue; + } +/* + * EX, sum exchange species only into EXCH mass balance in initial calculation + * into all mass balances in reaction calculation + */ + if ( state >= REACTION || master_ptr->s->type == EX) { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mb_for_species_surf(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i; + struct master *master_ptr; + + count_mb_unknowns = 0; +/* + * Include in charge balance, if diffuse_layer_x == FALSE + */ + if (charge_balance_unknown != NULL && diffuse_layer_x == FALSE) { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); + } +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (mass_hydrogen_unknown != NULL ) { +#ifdef COMBINE +#ifndef COMBINE_CHARGE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2*s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2*s[n]->o -s[n]->z, &s[n]->dg); + +#endif +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg ); +#endif + } + if (mass_oxygen_unknown != NULL ) { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); + } +/* + * Other mass balances + */ +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) { +/* Skip H+, e-, and H2O */ + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) { + if (master_ptr->s->secondary != NULL) { + master_ptr = master_ptr->s->secondary; + } + } +/* + * SURF_PSI, sum surface species in (surface + DL) charge balance + */ + if (master_ptr->s->type == SURF_PSI) { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->z, &s[n]->dg ); + continue; + } +/* + * Special for ph_unknown, pe_unknown, and alkalinity_unknown + */ + if (master_ptr->unknown == ph_unknown ) { + continue; + } else if (master_ptr->unknown == pe_unknown ) { + continue; + } else if (master_ptr->unknown == alkalinity_unknown ) { + continue; + } +/* + * SURF, sum surface species only into SURFACE mass balance in initial calculation + * into all mass balances in reaction calculation + */ + if ( state >= REACTION || master_ptr->s->type == SURF) { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int reprep (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * If a basis species has been switched, makes new model. + * Unknowns are not changed, but mass-action equations are + * rewritten and lists for mass balance and jacobian are regenerated + */ + int i; +/* + * Initialize s, master, and unknown pointers + */ + for (i=0; i < count_master; i++) { + if (master[i]->in == FALSE) continue; + rxn_free (master[i]->rxn_secondary); + master[i]->rxn_secondary = rxn_dup (master[i]->rxn_primary); + } + resetup_master(); +/* + * Set unknown pointers, unknown types, validity checks + */ + tidy_redox(); + if (input_error > 0) { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Free arrays built in build_model + */ + s_x = (struct species **) free_check_null(s_x); + sum_mb1 = (struct list1 *) free_check_null(sum_mb1); + sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); + sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); + sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); + sum_delta = (struct list2 *) free_check_null(sum_delta); +/* + * Build model again + */ + build_model(); + same_model = FALSE; + k_temp(tc_x); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int resetup_master (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * For basis switch, rewrite equations for master species + * Set master_ptr->rxn_secondary, + * master_ptr->pe_rxn, + * and special cases for alkalinity, carbon, and pH. + */ + int i, j; + struct master *master_ptr, *master_ptr0; + + for (i = 0; i < count_unknowns; i++ ) { + if (x[i]->type != MB) continue; + master_ptr0=x[i]->master[0]; + for (j = 0; (master_ptr = x[i]->master[j]) != NULL; j++) { +/* + * Set flags + */ + if (j == 0) { + if (master_ptr->s->primary == NULL) { + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_dup(master_ptr->s->rxn_s); + } + } else { + if (master_ptr0->s->primary == NULL) { + rewrite_master_to_secondary(master_ptr, master_ptr0); + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_alloc(count_trxn+1); + trxn_copy (master_ptr->rxn_secondary); + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int write_mass_action_eqn_x (int stop) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reduce mass-action equation to the master species that are in the model + */ + LDBLE coef_e; + int count, repeat; + int i, count_rxn_orig; +/* + * Rewrite any secondary master species flagged REWRITE + * Replace pe if necessary + */ + count = 0; + repeat = TRUE; + while (repeat == TRUE) { + count++; + if (count > MAX_ADD_EQUATIONS) { + sprintf(error_string, "Could not reduce equation " + "to primary and secondary species that are " + "in the model\n\t Species: %s.", + trxn.token[0].s->name); + if (stop == STOP) { + input_error++; + error_msg(error_string, CONTINUE); + } else { + warning_msg(error_string); + } + return(ERROR); + } + repeat = FALSE; + count_rxn_orig=count_trxn; + for (i=1; i < count_rxn_orig; i++) { + if (trxn.token[i].s->secondary == NULL) continue; + if (trxn.token[i].s->secondary->in == REWRITE ) { + repeat=TRUE; + coef_e=rxn_find_coef (trxn.token[i].s->secondary->rxn_secondary, + "e-"); + trxn_add(trxn.token[i].s->secondary->rxn_secondary, + trxn.token[i].coef, FALSE); + if ( equal(coef_e,0.0,TOL) == FALSE ) { + trxn_add( *(trxn.token[i].s->secondary->pe_rxn), + trxn.token[i].coef*coef_e, FALSE); + } + } + } + trxn_combine(); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_potential_factor(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add the potential factor to surface mass-action equations. + * Factor is essentially the activity coefficient, representing + * the work required to bring charged ions to the surface + */ + int i; + char token[MAX_LENGTH]; + LDBLE sum_z; + struct master *master_ptr; + struct unknown *unknown_ptr; + + if (use.surface_ptr->edl == FALSE) return(OK); + sum_z = 0.0; + master_ptr = NULL; +/* + * Find sum of charge of aqueous species and surface master species + */ + for (i=1; i < count_trxn; i++) { + if (trxn.token[i].s->type == AQ || trxn.token[i].s == s_hplus || + trxn.token[i].s == s_eminus) { + sum_z += trxn.token[i].s->z * trxn.token[i].coef; + } + if (trxn.token[i].s->type == SURF) { + master_ptr = trxn.token[i].s->primary; + } + } +/* + * Find potential unknown for surface species + */ + if (master_ptr == NULL) { + sprintf(error_string,"Did not find a surface species in equation defining %s", trxn.token[0].name); + error_msg(error_string, CONTINUE); + sprintf(error_string,"One of the following must be defined with SURFACE_SPECIES:"); + error_msg(error_string, CONTINUE); + for (i=1; i < count_trxn; i++) { + sprintf(error_string," %s", trxn.token[i].name); + error_msg(error_string, CONTINUE); + } + input_error++; + return(ERROR); + } + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token); + if (unknown_ptr == NULL) { + sprintf(error_string, "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ +/* + * Make sure there is space + */ + if (count_trxn + 1 >= max_trxn) { + space ((void **) &(trxn.token), count_trxn+1, &max_trxn, + sizeof(struct rxn_token_temp)); + } +/* + * Include psi in mass action equation + */ + if (master_ptr != NULL) { + trxn.token[count_trxn].name = master_ptr->s->name; + trxn.token[count_trxn].s = master_ptr->s; + trxn.token[count_trxn].coef = -2.0 * sum_z; + count_trxn++; + } else { + output_msg(OUTPUT_MESSAGE, "How did this happen in add potential factor?\n"); + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_surface_charge_balance(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add the potential factor to surface mass-action equations. + * Factor is essentially the activity coefficient, representing + * the work required to bring charged ions to the surface + */ + int i; + char *ptr; + char token[MAX_LENGTH]; + + struct master *master_ptr; + struct unknown *unknown_ptr; + + if (use.surface_ptr->edl == FALSE) return(OK); + master_ptr = NULL; +/* + * Find master species + */ + for (i=0; i < count_elts; i++) { + if (elt_list[i].elt->primary->s->type == SURF) { + master_ptr = elt_list[i].elt->primary; + break; + } + } + if (i >= count_elts) { + sprintf(error_string, "No surface master species found for surface species."); + error_msg(error_string, STOP); + } +/* + * Find potential unknown for surface species + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token); + if (unknown_ptr == NULL) { + sprintf(error_string, "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ +/* + * Include charge balance in list for mass-balance equations + */ + ptr = master_ptr->elt->name; + get_secondary_in_species(&ptr, 1.0); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int rewrite_master_to_secondary(struct master *master_ptr1, struct master *master_ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for secondary master species in terms of another secondary master species + * Store result in rxn_secondary of master_ptr. + */ + LDBLE coef1, coef2; + struct master *master_ptr_p1, *master_ptr_p2; +/* + * Check that the two master species have the same primary master species + */ + master_ptr_p1 = master_ptr1->elt->primary; + master_ptr_p2 = master_ptr2->elt->primary; + if (master_ptr_p1 != master_ptr_p2 || + master_ptr_p1 == NULL ) { + sprintf(error_string, "All redox states must be for the same element. %s\t%s.", + master_ptr1->elt->name, master_ptr2->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find coefficient of primary master in reaction + */ + coef1=rxn_find_coef(master_ptr1->rxn_primary, master_ptr_p1->s->name); + coef2=rxn_find_coef(master_ptr2->rxn_primary, master_ptr_p1->s->name); + if ( equal(coef1,0.0,TOL) == TRUE || equal(coef2,0.0,TOL) == TRUE ) { + sprintf(error_string, "One of these equations does not contain master species for element, %s or %s.", + master_ptr1->s->name, master_ptr2->s->name); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Rewrite equation to secondary master species + */ + count_trxn=0; + trxn_add(master_ptr1->rxn_primary, 1.0, FALSE); + trxn_add(master_ptr2->rxn_primary, -coef1/coef2, TRUE); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_exchange (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for exchanger in unknowns structures + */ + int i, j; + struct master *master_ptr; + struct master **master_ptr_list; + + if (use.exchange_ptr == NULL) return(OK); + + for (j = 0; j < use.exchange_ptr->count_comps; j++) { + for (i = 0; use.exchange_ptr->comps[j].totals[i].elt != NULL; i++ ) { +/* + * Find master species + */ + master_ptr = use.exchange_ptr->comps[j].totals[i].elt->master; + if (master_ptr == NULL) { + sprintf(error_string, "Master species not in data " + "base for %s, skipping element.", + use.exchange_ptr->comps[j].totals[i].elt->name); + input_error++; + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != EX) continue; +/* + * Check for data already given + */ + if (master_ptr->in != FALSE ) { + x[master_ptr->unknown->number]->moles += use.exchange_ptr->comps[j].totals[i].coef; + + } else { +/* + * Set flags + */ + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; +/* + * Set unknown data + */ + x[count_unknowns]->type = EXCH; + x[count_unknowns]->exch_comp = &(use.exchange_ptr->comps[j]); + x[count_unknowns]->description = use.exchange_ptr->comps[j].totals[i].elt->name; + x[count_unknowns]->moles = use.exchange_ptr->comps[j].totals[i].coef; + x[count_unknowns]->master = master_ptr_list; + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + count_unknowns++; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for gas phase unknown (sum of partial pressures) + * in unknown structure + */ + int i; + if (use.gas_phase_ptr == NULL) return(OK); +/* + * One for total moles in gas + */ + x[count_unknowns]->type = GAS_MOLES; + x[count_unknowns]->description = string_hsave("gas moles"); + x[count_unknowns]->moles = 0.0; + for (i=0; i < use.gas_phase_ptr->count_comps; i++) { + x[count_unknowns]->moles += use.gas_phase_ptr->comps[i].moles; + } + if (x[count_unknowns]->moles <= 0) x[count_unknowns]->moles = MIN_TOTAL; + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + x[count_unknowns]->gas_phase = use.gas_phase_ptr; + gas_unknown = x[count_unknowns]; + count_unknowns++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_s_s_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for solid solution unknowns (sum of partial pressures) + * in unknown structure + */ + int i, j; + if (use.s_s_assemblage_ptr == NULL) return(OK); +/* + * One for each component in each solid solution + */ + s_s_unknown = NULL; + for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + x[count_unknowns]->type = S_S_MOLES; + x[count_unknowns]->description = string_hsave(use.s_s_assemblage_ptr->s_s[j].comps[i].name); + x[count_unknowns]->moles = 0.0; + if (use.s_s_assemblage_ptr->s_s[j].comps[i].moles <= 0) { + use.s_s_assemblage_ptr->s_s[j].comps[i].moles = MIN_TOTAL; + } + x[count_unknowns]->moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles = x[count_unknowns]->moles; + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + x[count_unknowns]->s_s = &(use.s_s_assemblage_ptr->s_s[j]); + x[count_unknowns]->s_s_comp = &(use.s_s_assemblage_ptr->s_s[j].comps[i]); + x[count_unknowns]->s_s_comp_number = i; + x[count_unknowns]->phase = use.s_s_assemblage_ptr->s_s[j].comps[i].phase; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->phase->dn = use.s_s_assemblage_ptr->s_s[j].comps[i].dn; + x[count_unknowns]->phase->dnb = use.s_s_assemblage_ptr->s_s[j].comps[i].dnb; + x[count_unknowns]->phase->dnc = use.s_s_assemblage_ptr->s_s[j].comps[i].dnc; + x[count_unknowns]->phase->log10_fraction_x = use.s_s_assemblage_ptr->s_s[j].comps[i].log10_fraction_x; + x[count_unknowns]->phase->log10_lambda = use.s_s_assemblage_ptr->s_s[j].comps[i].log10_lambda; + if (s_s_unknown == NULL) s_s_unknown = x[count_unknowns]; + count_unknowns++; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_surface (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for surface assemblage in unknown structure + */ + int i, j, k; + struct master *master_ptr; + struct master **master_ptr_list; + struct unknown *unknown_ptr; + char token[MAX_LENGTH]; + char *name1, *name2; + if (use.surface_ptr == NULL) return(OK); + + for (i = 0; i < use.surface_ptr->count_comps; i++ ) { +/* + * Find master species for each surface, setup unknown structure + */ + for (j = 0; use.surface_ptr->comps[i].totals[j].elt != NULL; j++) { + master_ptr = use.surface_ptr->comps[i].totals[j].elt->master; + if (master_ptr == NULL) { + sprintf(error_string, "Master species not in data base for %s, skipping element.", use.surface_ptr->comps[i].totals[j].elt->name); + warning_msg(error_string); + continue; + } + if (master_ptr->type != SURF) continue; +/* + * Check that data not already given + */ if (master_ptr->in != FALSE ) { + sprintf(error_string, "Analytical data entered twice for %s.", master_ptr->s->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } +/* + * Set flags + */ + use.surface_ptr->comps[i].master = master_ptr; + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; +/* + * Setup mass balance unknown + */ + x[count_unknowns]->type = SURFACE; + x[count_unknowns]->description = use.surface_ptr->comps[i].totals[j].elt->name; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->surface_comp = &(use.surface_ptr->comps[i]); + x[count_unknowns]->master = master_ptr_list; + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + x[count_unknowns]->moles = use.surface_ptr->comps[i].totals[j].coef; + if (surface_unknown == NULL) surface_unknown = x[count_unknowns]; + x[count_unknowns]->potential_unknown = NULL; + count_unknowns++; + if (use.surface_ptr->edl == FALSE) continue; +/* + * Setup surface-potential unknown + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token); + if (unknown_ptr != NULL) { + x[count_unknowns - 1]->potential_unknown = unknown_ptr; + } else { +/* + * Find master species + */ + replace ("_CB", "_psi", token); + master_ptr = master_bsearch (token); + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; +/* + * Find surface charge structure + */ + x[count_unknowns]->type = SURFACE_CB; + k = use.surface_ptr->comps[i].charge; + x[count_unknowns]->surface_charge = &use.surface_ptr->charge[k]; + x[count_unknowns]->related_moles = x[count_unknowns]->surface_charge->grams; + x[count_unknowns]->mass_water = use.surface_ptr->charge[k].mass_water; + replace("_psi","_CB",token); + x[count_unknowns]->description = string_hsave(token); + x[count_unknowns]->master = master_ptr_list; + use.surface_ptr->charge[k].psi_master = x[count_unknowns]->master[0]; + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + x[count_unknowns]->moles = 0.0; + x[count_unknowns - 1]->potential_unknown = x[count_unknowns]; + x[count_unknowns]->surface_comp = x[count_unknowns - 1]->surface_comp; + count_unknowns++; + } + } + } +/* + * check related phases + */ + if (use.surface_ptr->related_phases == TRUE) { + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != SURFACE_CB) continue; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE) continue; + if (x[j]->potential_unknown != x[i]) continue; + if (x[j]->surface_comp->phase_name != x[i]->surface_comp->phase_name) { + if (x[i]->surface_comp->phase_name == NULL) { + name1 = string_hsave("None"); + } else { + name1 = x[i]->surface_comp->phase_name; + } + if (x[j]->surface_comp->phase_name == NULL) { + name2 = string_hsave("None"); + } else { + name2 = x[j]->surface_comp->phase_name; + } + input_error++; + sprintf(error_string,"All surface sites for a single component must be related to the same phase.\n\tSite: %s is related to %s, Site: %s is related to %s", + x[i]->surface_comp->master->s->name, name1, + x[j]->surface_comp->master->s->name, name2); + + error_msg(error_string, CONTINUE); + } + } + } + } +/* + * check related kinetics + */ + if (use.surface_ptr->related_rate == TRUE) { + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type != SURFACE_CB) continue; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE) continue; + if (x[j]->potential_unknown != x[i]) continue; + if (x[j]->surface_comp->rate_name != x[i]->surface_comp->rate_name) { + if (x[i]->surface_comp->rate_name == NULL) { + name1 = string_hsave("None"); + } else { + name1 = x[i]->surface_comp->rate_name; + } + if (x[j]->surface_comp->rate_name == NULL) { + name2 = string_hsave("None"); + } else { + name2 = x[j]->surface_comp->rate_name; + } + input_error++; + sprintf(error_string,"All surface sites for a single component must be related to the same kinetic reaction.\n\tSite: %s is related to %s, Site: %s is related to %s", + x[i]->surface_comp->master->s->name, name1, + x[j]->surface_comp->master->s->name, name2); + + error_msg(error_string, CONTINUE); + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct unknown *find_surface_charge_unknown(char *str_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes name for the potential unknown and returns in str_ptr + * Returns NULL if this unknown not in unknown list else + * returns a pointer to the potential unknown + */ + int i; + char *ptr; + char token[MAX_LENGTH]; + + replace ("_", " ", str_ptr); + ptr = str_ptr; + copy_token(token, &ptr, &i); + strcat(token, "_CB"); + strcpy(str_ptr, token); + for (i = 0; i < count_unknowns; i++) { + if ( strcmp(token, x[i]->description) == 0 ) { + return(x[i]); + } + } + return(NULL); +} + +/* ---------------------------------------------------------------------- */ +int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn) +/* ---------------------------------------------------------------------- */ +{ +/* + * Rewrites rxn_secondary for all redox states in list + * First, in = TRUE; others, in = REWRITE + */ + int j; + struct master *master_ptr, *master_ptr0; +/* + * Set master_ptr->in, master_ptr->rxn + */ + master_ptr0 = master_ptr_list[0]; + for (j = 0; (master_ptr = master_ptr_list[j]) != NULL; j++) { +/* + * Check that data not already given + */ + if (master_ptr->s == s_h2o) { + sprintf(error_string, "Can not enter concentration data for O(-2),\n\tdissolved oxygen is O(0),\n\tfor mass of water, use -water identifier."); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + + if (master_ptr->in != FALSE ) { + if (master_ptr->s != s_eminus && master_ptr->s != s_hplus) { + sprintf(error_string, "Analytical data entered twice for %s.", master_ptr->s->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } +/* + * Set flags + */ + if (j == 0) { + master_ptr->in = TRUE; + if (master_ptr->s->primary == NULL) { + rxn_free (master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_dup (master_ptr->s->rxn_s); +/* debug + trxn_print (); + */ + } + } else { + master_ptr->in = REWRITE; + if (master_ptr0->s->primary == NULL) { + rewrite_master_to_secondary(master_ptr, master_ptr0); + rxn_free (master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_alloc(count_trxn+1); + trxn_copy (master_ptr->rxn_secondary); +/* debug + trxn_print (); + */ + } + } + master_ptr->pe_rxn = pe_rxn; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Fills in data for pure_phase assemglage in unknown structure + */ + + if (use.pp_assemblage_ptr == NULL) return(OK); +/* + * Setup unknowns + */ + for (i=0; i < use.pp_assemblage_ptr->count_comps; i++) { + x[count_unknowns]->type = PP; + x[count_unknowns]->description = use.pp_assemblage_ptr->pure_phases[i].name; + x[count_unknowns]->moles = use.pp_assemblage_ptr->pure_phases[i].moles; + x[count_unknowns]->phase = use.pp_assemblage_ptr->pure_phases[i].phase; + x[count_unknowns]->si = use.pp_assemblage_ptr->pure_phases[i].si; + x[count_unknowns]->delta = use.pp_assemblage_ptr->pure_phases[i].delta; + x[count_unknowns]->pure_phase = &(use.pp_assemblage_ptr->pure_phases[i]); + x[count_unknowns]->dissolve_only = use.pp_assemblage_ptr->pure_phases[i].dissolve_only; + if (pure_phase_unknown == NULL) pure_phase_unknown = x[count_unknowns]; + count_unknowns++; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_solution (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fills in data in unknown structure for the solution + */ + int l, i, j; + struct master *master_ptr; + struct solution *solution_ptr; + char *ptr; + char token[MAX_LENGTH]; + struct master_isotope *master_isotope_ptr; + + solution_ptr = use.solution_ptr; + count_unknowns = 0; + for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { + /*solution_ptr->totals[i].skip = FALSE;*/ + ptr=solution_ptr->totals[i].description; + copy_token(token, &ptr, &l); + master_ptr = master_bsearch(token); + /* + * Treat minor isotopes as special in initial solution calculation + */ + if ((state == INITIAL_SOLUTION) && (master_ptr != NULL) && (master_ptr->minor_isotope == TRUE) && (initial_solution_isotopes == FALSE)) { + master_isotope_ptr = master_isotope_search(token); + if (master_isotope_ptr != NULL) { + master_isotope_ptr->ratio = solution_ptr->totals[i].input_conc; + } + /*solution_ptr->totals[i].skip = TRUE;*/ + continue; + } +/* + * Check that total not <= zero + */ + if (solution_ptr->totals[i].input_conc <= 0.0) { + if (strcmp(token,"H(1)") != 0 && + strcmp(token,"E") != 0 ) { + /*solution_ptr->totals[i].skip = TRUE;*/ + continue; + } + } +/* + * Find master species + */ + master_ptr = master_bsearch(token); + if (master_ptr == NULL) { + /*solution_ptr->totals[i].skip = TRUE;*/ + sprintf(error_string,"Master species not in data base for %s, skipping element.", solution_ptr->totals[i].description); + warning_msg(error_string); + continue; + } + if (master_ptr->type != AQ) { + /*solution_ptr->totals[i].skip = TRUE;*/ + sprintf(error_string, "Only aqueous concentrations are allowed in solution data, ignoring %s.", solution_ptr->totals[i].description); + warning_msg(error_string); + continue; + } +/* + * Store list of master species pointers, set master[i].in and master[i].rxn for list + */ + x[count_unknowns]->master = get_list_master_ptrs(ptr, master_ptr); + setup_master_rxn(x[count_unknowns]->master, &(pe_x[solution_ptr->totals[i].n_pe].rxn)); +/* + * Set default unknown data + */ + x[count_unknowns]->type = MB; + x[count_unknowns]->description = solution_ptr->totals[i].description; + x[count_unknowns]->total = &(solution_ptr->totals[i]); + for (j=0; x[count_unknowns]->master[j] != NULL; j++) { + x[count_unknowns]->master[j]->unknown = x[count_unknowns]; + } + x[count_unknowns]->moles = solution_ptr->totals[i].moles; +/* + * Set pointers + */ + ptr=solution_ptr->totals[i].description; + copy_token(token, &ptr, &l); + str_tolower(token); + if (strstr( token,"alk") != NULL) { + if (alkalinity_unknown == NULL) { + x[count_unknowns]->type = ALK; + alkalinity_unknown=x[count_unknowns]; + } else { + error_msg("Alkalinity entered more than once.", CONTINUE); + input_error++; + } + } else if (strcmp(token,"c") == 0 || strcmp(token,"c(4)") == 0 ) { + if (carbon_unknown == NULL) { + carbon_unknown=x[count_unknowns]; + } else { + error_msg("Carbon entered more than once.", CONTINUE); + input_error++; + } + } else if (strcmp(token,"h(1)") == 0 ) { + if (ph_unknown == NULL) { + ph_unknown=x[count_unknowns]; + } else { + error_msg("pH entered more than once.", CONTINUE); + input_error++; + } + } else if (strcmp(token,"e") == 0 ) { + if (pe_unknown == NULL) { + pe_unknown=x[count_unknowns]; + } else { + error_msg("pe entered more than once.", CONTINUE); + input_error++; + } + } +/* + * Charge balance unknown + */ + if (solution_ptr->totals[i].equation_name != NULL ) { + ptr = solution_ptr->totals[i].equation_name; + copy_token(token, &ptr, &l); + str_tolower(token); + if (strstr(token,"charge") != NULL) { + if (charge_balance_unknown == NULL) { + charge_balance_unknown=x[count_unknowns]; + x[count_unknowns]->type = CB; + if (charge_balance_unknown == ph_unknown ) { + x[count_unknowns]->moles = solution_ptr->cb; + } + } else { + error_msg("Charge balance specified for more" + " than one species.", CONTINUE); + input_error++; + } + } else { +/* + * Solution phase boundaries + */ + solution_ptr->totals[i].phase= + phase_bsearch(solution_ptr->totals[i].equation_name, &l, FALSE); + if (solution_ptr->totals[i].phase == NULL) { + sprintf(error_string, "Expected a mineral name, %s.", solution_ptr->totals[i].equation_name); + error_msg(error_string, CONTINUE); + input_error++; + } + x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; + x[count_unknowns]->phase=solution_ptr->totals[i].phase; + x[count_unknowns]->si=solution_ptr->totals[i].phase_si; + if (solution_phase_boundary_unknown == NULL) { + solution_phase_boundary_unknown = x[count_unknowns]; + } + } + } + count_unknowns++; + } +/* + * Set mb_unknown + */ + if (count_unknowns > 0) mb_unknown=x[0]; +/* + * Special for alkalinity + */ + if (alkalinity_unknown != NULL) { + if (carbon_unknown != NULL) { +/* + * pH adjusted to obtain given alkalinity + */ + if (ph_unknown == NULL) { + output_msg(OUTPUT_MESSAGE,"\npH will be adjusted to obtain desired alkalinity.\n\n"); + ph_unknown = alkalinity_unknown; + master_ptr=master_bsearch("H(1)"); + alkalinity_unknown->master[0] = master_ptr; + master_ptr->in = TRUE; + master_ptr->unknown = ph_unknown; + ph_unknown->master[0] = master_ptr; + ph_unknown->description = string_hsave( "H(1)" ); + } else { + error_msg("pH adjustment is needed for alkalinity but" + " charge balance or a phase boundary was also specified.", CONTINUE); + input_error++; + } +/* + * Carbonate ion adjusted to obtain given alkalintiy + */ + } else { + if (alkalinity_unknown->master[0]->s->secondary != NULL) { + alkalinity_unknown->master[0]->s->secondary->in=TRUE; + alkalinity_unknown->master[0]->s->secondary->unknown=alkalinity_unknown; + } else { + error_msg("Error in definition of Alkalinity in SOLUTION_MASTER_SPECIES and SOLUTION_SPECIES.\n\tAlkalinity master species should be same as master species for C(4).", CONTINUE); + input_error++; + } + } + } + if (pitzer_model == FALSE) { + /* + * Ionic strength + */ + mu_unknown=x[count_unknowns]; + x[count_unknowns]->description= string_hsave( "Mu" ); + x[count_unknowns]->type=MU; + x[count_unknowns]->number=count_unknowns; + x[count_unknowns]->moles = 0.0; + mu_unknown = x[count_unknowns]; + count_unknowns++; + } + /* + * Activity of water + */ + ah2o_unknown=x[count_unknowns]; + ah2o_unknown->description= string_hsave( "A(H2O)" ); + ah2o_unknown->type=AH2O; + ah2o_unknown->number=count_unknowns; + ah2o_unknown->master = unknown_alloc_master(); + ah2o_unknown->master[0] = master_bsearch ("O"); + ah2o_unknown->master[0]->unknown = ah2o_unknown; + ah2o_unknown->moles = 0.0; + count_unknowns++; + + if (state >= REACTION) { +/* + + * Reaction: pH for charge balance + */ + ph_unknown = x[count_unknowns]; + ph_unknown->description = string_hsave( "pH" ); + ph_unknown->type = CB; + ph_unknown->moles = solution_ptr->cb; + ph_unknown->number = count_unknowns; + ph_unknown->master = unknown_alloc_master(); + ph_unknown->master[0] = s_hplus->primary; + ph_unknown->master[0]->unknown = ph_unknown; + charge_balance_unknown = ph_unknown; + count_unknowns++; +/* + * Reaction: pe for total hydrogen + */ + pe_unknown = x[count_unknowns]; + mass_hydrogen_unknown = x[count_unknowns]; + mass_hydrogen_unknown->description = string_hsave( "Hydrogen" ); + mass_hydrogen_unknown->type = MH; +#ifdef COMBINE +#ifndef COMBINE_CHARGE + mass_hydrogen_unknown->moles = solution_ptr->total_h - 2*solution_ptr->total_o ; +#else + mass_hydrogen_unknown->moles = solution_ptr->total_h - 2*solution_ptr->total_o - solution_ptr->cb ; +#endif +#else + mass_hydrogen_unknown->moles = solution_ptr->total_h; +#endif + mass_hydrogen_unknown->number = count_unknowns; + mass_hydrogen_unknown->master = unknown_alloc_master(); + mass_hydrogen_unknown->master[0] = s_eminus->primary; + mass_hydrogen_unknown->master[0]->unknown = mass_hydrogen_unknown; + count_unknowns++; +/* + * Reaction H2O for total oxygen + */ + mass_oxygen_unknown = x[count_unknowns]; + mass_oxygen_unknown->description = string_hsave( "Oxygen" ); + mass_oxygen_unknown->type = MH2O; + mass_oxygen_unknown->moles = solution_ptr->total_o; + mass_oxygen_unknown->number = count_unknowns; + mass_oxygen_unknown->master = unknown_alloc_master(); + mass_oxygen_unknown->master[0] = s_h2o->primary; + count_unknowns++; + } +/* + * Validity tests + */ + if ( (ph_unknown != NULL) && + (ph_unknown == charge_balance_unknown) && + (alkalinity_unknown != NULL) ) { + error_msg("pH adustment can not attain charge balance" + " when alkalinity is fixed.", CONTINUE); + input_error++; + } + if ( (alkalinity_unknown != NULL) && + (alkalinity_unknown->type == CB || + alkalinity_unknown->type == SOLUTION_PHASE_BOUNDARY)) { + error_msg("Alkalinity can not be used with charge balance" + " or solution phase boundary constraints.", CONTINUE); + input_error++; + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct master **unknown_alloc_master(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space for a list of 2 master pointers + */ + struct master **master_ptr; + + master_ptr = (struct master **) PHRQ_malloc( 2 * sizeof(struct master *) ); + if (master_ptr == NULL) malloc_error(); + master_ptr[0] = NULL; + master_ptr[1] = NULL; + return(master_ptr); +} +/* ---------------------------------------------------------------------- */ +int setup_unknowns (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Counts unknowns and allocates space for unknown structures + */ + int i, j; + struct solution *solution_ptr; + + solution_ptr = use.solution_ptr; +/* + * Calculate maximum number of unknowns + */ + max_unknowns = 0; +/* + * Count mass balance in solution + */ + for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) max_unknowns++; +/* + * Add 5 for ionic strength, activity of water, charge balance, total H, total O + */ + max_unknowns += 5; +/* + * Count pure phases + */ + if (use.pp_assemblage_ptr != NULL) { + max_unknowns += use.pp_assemblage_ptr->count_comps; +/* + for (i = 0; use.pp_assemblage_ptr->pure_phases[i].name != NULL; i++ ) { + max_unknowns++; + } + */ + } +/* + * Count exchange + */ + if (use.exchange_ptr != NULL) { + for (j = 0; j < use.exchange_ptr->count_comps; j++) { + for (i = 0; use.exchange_ptr->comps[j].totals[i].elt != NULL; i++) { + if (use.exchange_ptr->comps[j].totals[i].elt->master == NULL) { + sprintf(error_string, "Master species missing for element %s", use.exchange_ptr->comps[j].totals[i].elt->name); + error_msg(error_string, STOP); + } + if (use.exchange_ptr->comps[j].totals[i].elt->master->type == EX) { + max_unknowns++; + } + } + } + } +/* + * Count surfaces + */ + if (use.surface_ptr != NULL) { + max_unknowns += use.surface_ptr->count_comps + use.surface_ptr->count_charge; + } +/* + * Count gas components + */ + if (use.gas_phase_ptr != NULL) { + max_unknowns++; + } +/* + * Count solid solutions + */ + if (use.s_s_assemblage_ptr != NULL) { + /* max_unknowns += 2 * use.s_s_assemblage_ptr->count_s_s;*/ + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + max_unknowns += use.s_s_assemblage_ptr->s_s[i].count_comps; + } + } + +/* + * One for luck + */ + max_unknowns++; + if (pitzer_model == TRUE) { + max_unknowns += count_s; + } +/* + * Allocate space for pointer array and structures + */ + + space ((void **) ((void *) &x), INIT, &max_unknowns, sizeof(struct unknown *)); + for (i = 0; i < max_unknowns; i++) { + x[i] = (struct unknown *) unknown_alloc (); + x[i]->number = i; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_dn (int k, LDBLE *source, int row, LDBLE coef_in, LDBLE *gamma_source) +/* ---------------------------------------------------------------------- */ +{ +/* + * Stores the terms for d moles of species k in solution into row, multiplied + * by coef_in + */ + int col; + LDBLE coef; + struct rxn_token *rxn_ptr; + struct master *master_ptr; + + if (equal(coef_in, 0.0, TOL) == TRUE) { + return(OK); + } +/* Gamma term for d molality of species */ +/* Note dg includes molality as a factor */ + + row = row * (count_unknowns + 1); + if (s[k]->type != SURF && s[k] != s_h2o ) { + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n","Activity coefficient", (double) (-1.0 * coef_in), row/(count_unknowns + 1), mu_unknown->number); + } + /* mu term */ + if (gamma_source != NULL) { + store_jacob(gamma_source, &array[row + mu_unknown->number], -1.0 * coef_in); +#ifdef SKIP + if (use_tot_g == 0) { + store_jacob(&(s[k]->dg_total_g), &array[row + mu_unknown->number], -1.0 * coef_in); + } else if (use_tot_g == 1) { + store_jacob(&(s[k]->dg), &array[row + mu_unknown->number], -1.0 * coef_in); + } +#endif + } + } +/* + * Mass of water factor + */ + if (mass_oxygen_unknown != NULL && s[k]->type != EX && s[k]->type != SURF) { + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", + mass_oxygen_unknown->master[0]->s->name, (double) coef_in, + row/(count_unknowns+1), + mass_oxygen_unknown->number); + } + store_jacob(source, &(array[row + mass_oxygen_unknown->number]), coef_in); + } + if ( s[k] == s_h2o ) return(OK); + for ( rxn_ptr = s[k]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { + master_ptr=rxn_ptr->s->secondary; + } else { + master_ptr=rxn_ptr->s->primary; + } + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); + } + if (master_ptr->unknown == NULL) continue; + col = master_ptr->unknown->number; + coef = coef_in * rxn_ptr->coef; + store_jacob (source, &(array[row + col]), coef); + if ( debug_prep == TRUE ) { + output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, + row/(count_unknowns+1), col); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_jacob(LDBLE *source, LDBLE *target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds a new item to either sum_jacob1 or sum_jacob2 + * If coef is 1.0, adds to sum_jacob1, which does not require a multiply + * Otherwise, adds to sum_jacob2, which allows multiply by coef + */ + if (equal(coef, 1.0, TOL) == TRUE) { + if (debug_prep == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t\tjacob1 %d\n", count_sum_jacob1); + } + sum_jacob1[count_sum_jacob1].source = source; + sum_jacob1[count_sum_jacob1++].target = target; + /* Check space */ + if (count_sum_jacob1 >= max_sum_jacob1) { + space ((void **) ((void *) &sum_jacob1), count_sum_jacob1, + &max_sum_jacob1, + sizeof(struct list1)); + } + } else { + if (debug_prep == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t\tjacob2 %d\n", count_sum_jacob2); + } + sum_jacob2[count_sum_jacob2].source = source; + sum_jacob2[count_sum_jacob2].target = target; + sum_jacob2[count_sum_jacob2++].coef=coef; + /* Check space */ + if (count_sum_jacob2 >= max_sum_jacob2) { + space ((void **) ((void *) &sum_jacob2), count_sum_jacob2, &max_sum_jacob2, + sizeof(struct list2)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_jacob0(int row, int column, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Stores in list a constant coef which will be added into jacobian array + */ + sum_jacob0[count_sum_jacob0].target = &(array[row*(count_unknowns+1) + column]); + sum_jacob0[count_sum_jacob0++].coef=coef; + /* Check space */ + if (count_sum_jacob0 >= max_sum_jacob0) { + space ((void **) ((void *) &sum_jacob0), count_sum_jacob0, + &max_sum_jacob0, + sizeof(struct list0)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_mb(LDBLE *source, LDBLE *target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds item to list sum_mb1 or sum_mb2 + * If coef is 1.0, adds to sum_mb1, which does not require a multiply + * else, adds to sum_mb2, which will multiply by coef + */ + if (equal(coef, 1.0, TOL) == TRUE ) { + sum_mb1[count_sum_mb1].source = source; + sum_mb1[count_sum_mb1++].target = target; + if (count_sum_mb1 >= max_sum_mb1) { + space ((void **) ((void *) &sum_mb1), count_sum_mb1 + count_trxn + 4, + &max_sum_mb1, sizeof(struct list1)); + } + } else { + sum_mb2[count_sum_mb2].source = source; + sum_mb2[count_sum_mb2].coef = coef; + sum_mb2[count_sum_mb2++].target = target; + if (count_sum_mb2 >= max_sum_mb2) { + space ((void **) ((void *) &sum_mb2), count_sum_mb2, + &max_sum_mb2, sizeof(struct list2)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_sum_deltas(LDBLE *source, LDBLE *target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * List sum_delta is summed to determine the change in the mass of + * each element due to mass transfers of minerals, changes show up + * in x[i]->delta. These may be multiplied by a factor under some + * situations where the entire calculated step is not taken + */ + sum_delta[count_sum_delta].source = source; + sum_delta[count_sum_delta].target = target; + sum_delta[count_sum_delta++].coef=coef; + /* Check space */ + if (count_sum_delta >= max_sum_delta) { + space ((void **) ((void *) &sum_delta), count_sum_delta, &max_sum_delta, + sizeof(struct list2)); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int switch_bases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check if activity of first master species is predominant among activities of + * secondary master species included in mass balance. + */ + int i, j; + int first; + int return_value; + LDBLE la, la1; + struct master *master_ptr; + + return_value = FALSE; + for (i=0; i < count_unknowns; i++) { + if (x[i]->type != MB) continue; + first = 0; + la = x[i]->master[0]->s->la; + for (j=1; x[i]->master[j] != NULL; j++) { + la1 = x[i]->master[j]->s->lm + x[i]->master[j]->s->lg; + if (first == 0 && la1 > la + 10.) { + la = la1; + first = j; + } else if (first != 0 && la1 > la ) { + la = la1; + first = j; + } + } + if (first != 0) { + master_ptr = x[i]->master[0]; + x[i]->master[0] = x[i]->master[first]; + x[i]->master[0]->in = TRUE; + x[i]->master[first] = master_ptr; + x[i]->master[first]->in = REWRITE; + output_msg(OUTPUT_LOG,"Switching bases to %s.\tIteration %d\n", + x[i]->master[0]->s->name, iterations); + return_value = TRUE; + } + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int tidy_redox (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write pe redox reactions (rxn in struct pe_data) in terms of master species + * defined in analytical data + * + */ + int i, j, l; + char *ptr; + char token[MAX_LENGTH], tok1[MAX_LENGTH], tok2[MAX_LENGTH]; + struct pe_data *pe_data_ptr; + struct master *master_ptr1, *master_ptr2; +/* + * Keep valences of oxygen and hydrogen in model, if not already in + */ + for (i=0; i < count_master; i++) { + if (master[i]->primary == TRUE && + (master[i]->s == s_hplus || + master[i]->s == s_h2o ) ) { + j = i+1; + while (j < count_master && master[j]->elt->primary == master[i]) { + if (master[j]->in == FALSE && + master[j]->s != master[i]->s) { + master[j]->in = REWRITE; + master[j]->pe_rxn = master[i]->pe_rxn; + } + j++; + } + } + } +/* + * Writes equations for e- for each redox couple used in solution n + */ + for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) { + if (strcmp_nocase_arg1(pe_data_ptr->name,"pe") == 0 ) { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); + } else { + strcpy(token, pe_data_ptr->name); + replace ("/"," ",token); + ptr=token; +/* + * Get redox states and elements from redox couple + */ + copy_token (tok1, &ptr, &l); + copy_token (tok2, &ptr, &l); +/* + * Find master species + */ + master_ptr1 = master_bsearch(tok1); + master_ptr2 = master_bsearch(tok2); + if (master_ptr1 != NULL && master_ptr2 != NULL ) { + rewrite_master_to_secondary (master_ptr1, master_ptr2); +/* + * Rewrite equation to e- + */ + trxn_swap ("e-"); + } else { + sprintf(error_string, "Can not find master species for redox couple, %s.", pe_data_ptr->name); + error_msg(error_string, STOP); + } + if (inout() == FALSE) { + sprintf(error_string, "Analytical data missing for redox couple, %s\n\t Using pe instead.", pe_data_ptr->name ); + warning_msg(error_string); + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); + pe_data_ptr->name = pe_x[0].name; + } else { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_alloc(count_trxn+1); + trxn_copy (pe_data_ptr->rxn); + } + } + } +/* + * Rewrite equations to master species that are "in" the model + */ + for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) { + count_trxn=0; + trxn_add(pe_data_ptr->rxn, 1.0, FALSE); + if (write_mass_action_eqn_x(CONTINUE) == FALSE) { + sprintf(error_string, "Could not rewrite redox " + "couple equation for %s\n\t Possibly missing data for one " + "of the redox states.", pe_data_ptr->name); + warning_msg(error_string); + sprintf(error_string, "Using pe instead of %s.", pe_data_ptr->name); + warning_msg(error_string); + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup (pe_x[0].rxn); + pe_data_ptr->name = pe_x[0].name; + } else { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_alloc(count_trxn+1); + trxn_copy (pe_data_ptr->rxn); + } + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int write_mb_eqn_x (void) +/* ---------------------------------------------------------------------- */ +{ + int count, repeat; + int i, count_rxn_orig; + int j, k; + char *ptr; + struct master *master_ptr; +/* + * Rewrite any secondary master species flagged REWRITE + * Don't add in any pe reactions + */ + count = 0; + repeat = TRUE; + while (repeat == TRUE) { + count++; + if (count > MAX_ADD_EQUATIONS) { + sprintf(error_string, "Could not reduce equation " + "to primary and secondary species that are " + "in the model, %s.", trxn.token[0].s->name); + error_msg(error_string, CONTINUE); + return(ERROR); + } + repeat = FALSE; + count_rxn_orig=count_trxn; + for (i=1; i < count_rxn_orig; i++) { + if (trxn.token[i].s->secondary == NULL) continue; + if (trxn.token[i].s->secondary->in == REWRITE ) { + repeat=TRUE; + trxn_add(trxn.token[i].s->secondary->rxn_secondary, + trxn.token[i].coef, FALSE); + } + } + trxn_combine(); + } +/* + * + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) { + j = count_elts; + ptr = trxn.token[i].s->name; + get_elts_in_species(&ptr, trxn.token[i].coef); + for (k = j; k < count_elts; k++) { + if (trxn.token[i].s->secondary != NULL) { + master_ptr = trxn.token[i].s->secondary->elt->primary; + } else { + master_ptr = trxn.token[i].s->primary; + } + if (elt_list[k].elt == master_ptr->elt) { + elt_list[k].coef = 0.0; + break; + } + } + if (trxn.token[i].s->secondary == NULL) { + ptr = trxn.token[i].s->primary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } else { + ptr = trxn.token[i].s->secondary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int write_mb_for_species_list (int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets up data to add to species_list + * Original secondary redox states are retained + */ + int i; + char *ptr; +/* + * Start with secondary reaction + */ + count_trxn=0; + trxn_add (s[n]->rxn_s, 1.0, FALSE); +/* + * Copy to elt_list + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) { + if (trxn.token[i].s->secondary == NULL) { + ptr = trxn.token[i].s->primary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } else { + ptr = trxn.token[i].s->secondary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } + } + for (i = 0; i < count_elts; i++) { + if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_h_one; + elt_list[count_elts].coef = elt_list[i].coef*2; + count_elts++; + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } + s[n]->next_sys_total = (struct elt_list *) free_check_null(s[n]->next_sys_total); + s[n]->next_sys_total = elt_list_save(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int write_phase_sys_total (int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets up data to add to species_list + * Original secondary redox states are retained + */ + int i; + char *ptr; +/* + * Start with secondary reaction + */ + count_trxn=0; + trxn_add (phases[n]->rxn_s, 1.0, FALSE); +/* + * Copy to elt_list + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) { + if (trxn.token[i].s->secondary == NULL) { + ptr = trxn.token[i].s->primary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } else { + ptr = trxn.token[i].s->secondary->elt->name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + } + } + for (i = 0; i < count_elts; i++) { + if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_h_one; + elt_list[count_elts].coef = elt_list[i].coef*2; + count_elts++; + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } + phases[n]->next_sys_total = (struct elt_list *) free_check_null(phases[n]->next_sys_total); + phases[n]->next_sys_total = elt_list_save(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int k_temp(LDBLE tempc) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates log k's for all species and pure_phases + */ + int i; + LDBLE tempk; + + if (same_model == TRUE && same_temperature == TRUE) return(OK); + + tempk=tempc+273.15; +/* + * Calculate log k for all aqueous species + */ + for (i=0; i < count_s_x; i++) { + s_x[i]->lk = k_calc(s_x[i]->rxn_x->logk, tempk); + } +/* + * Calculate log k for all pure phases + */ + for (i=0; i < count_phases; i++) { + if (phases[i]->in == TRUE) { + phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk); + } + } +/* + * Calculate miscibility gaps for solid solutions + */ + if (use.s_s_assemblage_ptr != NULL ) { + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + if (fabs(tempk - use.s_s_assemblage_ptr->s_s[i].tk) > 0.01) { + s_s_prep(tempk, &(use.s_s_assemblage_ptr->s_s[i]), FALSE); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE k_calc(LDBLE *logk, LDBLE tempk) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates log k at specified temperature + * + * Input: + * *logk is pointer to logkt0, deltah, and analytical expression data + * tempk is temperature in degrees K. + * + * Returns calculated log k. + */ + return(logk[0] + - logk[1]*(298.15-tempk)/(298.15*tempk*LOG_10*R_KJ_DEG_MOL) + + logk[2] + + logk[3]*tempk + + logk[4]/tempk + + logk[5]*log10(tempk) + + logk[6]/(tempk*tempk) ); +} +/* ---------------------------------------------------------------------- */ +static int save_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * save temperature + */ + last_model.temperature = tc_x; +/* + * mark master species + */ + for (i = 0; i < count_master; i++) { + master[i]->last_model = FALSE; + if (master[i]->total > 0) { + if (master[i]->primary == TRUE) { + master[i]->last_model = TRUE; + } else { + /* mark primary master */ + master[i]->s->secondary->elt->primary->last_model = TRUE; + } + } + } +/* + * save list of phase pointers for gas phase + */ + last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); + if (use.gas_phase_ptr != NULL) { + last_model.count_gas_phase = use.gas_phase_ptr->count_comps; + last_model.gas_phase = (struct phase **) PHRQ_malloc((size_t) use.gas_phase_ptr->count_comps * sizeof(struct phase *)); + if (last_model.gas_phase == NULL) malloc_error(); + for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { + last_model.gas_phase[i] = use.gas_phase_ptr->comps[i].phase; + } + } else { + last_model.count_gas_phase = 0; + last_model.gas_phase = NULL; + } +/* + * save list of names of solid solutions + */ + last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); + if (use.s_s_assemblage_ptr != NULL) { + last_model.count_s_s_assemblage = use.s_s_assemblage_ptr->count_s_s; + last_model.s_s_assemblage = (char **) PHRQ_malloc((size_t) use.s_s_assemblage_ptr->count_s_s * sizeof(char *)); + if (last_model.s_s_assemblage == NULL) malloc_error(); + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + last_model.s_s_assemblage[i] = use.s_s_assemblage_ptr->s_s[i].name; + } + } else { + last_model.count_s_s_assemblage = 0; + last_model.s_s_assemblage = NULL; + } +/* + * save list of phase pointers for pp_assemblage + */ + last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.add_formula = (char **) free_check_null(last_model.add_formula); + last_model.si = (double *) free_check_null(last_model.si); + if (use.pp_assemblage_ptr != NULL) { + last_model.count_pp_assemblage = use.pp_assemblage_ptr->count_comps; + last_model.pp_assemblage = (struct phase **) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(struct phase *)); + if (last_model.pp_assemblage == NULL) malloc_error(); + last_model.add_formula = (char **) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(char *)); + if (last_model.add_formula == NULL) malloc_error(); + last_model.si = (double *) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(LDBLE)); + if (last_model.si == NULL) malloc_error(); + for (i = 0; i < use.pp_assemblage_ptr->count_comps; i++) { + last_model.pp_assemblage[i] = use.pp_assemblage_ptr->pure_phases[i].phase; + last_model.add_formula[i] = use.pp_assemblage_ptr->pure_phases[i].add_formula; + last_model.si[i] = use.pp_assemblage_ptr->pure_phases[i].si; + } + } else { + last_model.count_pp_assemblage = 0; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int check_same_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Force new model to be built in prep + */ + if (last_model.force_prep == TRUE) { + last_model.force_prep = FALSE; + same_temperature = FALSE; + return(FALSE); + } +/* + * Check temperature + */ + if (fabs(tc_x - last_model.temperature) < 0.05) { + same_temperature = TRUE; + } else { + same_temperature = FALSE; + } +/* + * Check master species + */ + for (i = 0; i < count_master; i++) { +/* + output_msg(OUTPUT_MESSAGE,"%s\t%e\t%d\n", master[i]->elt->name, + master[i]->total, master[i]->last_model); + */ + if (master[i]->s == s_hplus || master[i]->s == s_h2o) continue; + if (master[i]->total > MIN_TOTAL && master[i]->last_model == TRUE) continue; + if (master[i]->total <= MIN_TOTAL && master[i]->last_model == FALSE) continue; + return(FALSE); + } +/* + * Check gas_phase + */ + if (use.gas_phase_ptr != NULL) { + if (last_model.count_gas_phase != use.gas_phase_ptr->count_comps) return(FALSE); + for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { + if(last_model.gas_phase[i] != use.gas_phase_ptr->comps[i].phase) { + return(FALSE); + } + } + } else { + if(last_model.gas_phase != NULL) return(FALSE); + } +/* + * Check solid solutions + */ + if (use.s_s_assemblage_ptr != NULL) { + if (last_model.count_s_s_assemblage != use.s_s_assemblage_ptr->count_s_s) return(FALSE); + for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { + if(last_model.s_s_assemblage[i] != use.s_s_assemblage_ptr->s_s[i].name) { + return(FALSE); + } + } + } else { + if(last_model.s_s_assemblage != NULL) return(FALSE); + } +/* + * Check pure_phases + */ + if (use.pp_assemblage_ptr != NULL) { + if (last_model.count_pp_assemblage != use.pp_assemblage_ptr->count_comps) return(FALSE); + for (i = 0; i < use.pp_assemblage_ptr->count_comps; i++) { + if(last_model.pp_assemblage[i] != use.pp_assemblage_ptr->pure_phases[i].phase) { + return(FALSE); + } + if(last_model.add_formula[i] != use.pp_assemblage_ptr->pure_phases[i].add_formula) { + return(FALSE); + } + if(last_model.si[i] != use.pp_assemblage_ptr->pure_phases[i].si) { + return(FALSE); + } + } + } else { + if(last_model.pp_assemblage != NULL) return(FALSE); + } +/* + * Model is the same + */ + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int build_min_exch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Defines proportionality factor between mineral and exchanger to + * jacob0 + */ + int i, j, k, n, jj; + int row; + struct exch_comp *comp_ptr; + struct master *master_ptr; + struct unknown *unknown_ptr; + LDBLE coef; + + if (use.exchange_ptr == NULL) return(OK); + if (exchange_bsearch(use.exchange_ptr->n_user, &n) == NULL) { + input_error++; + sprintf(error_string,"Exchange %d not found.", use.exchange_ptr->n_user); + error_msg(error_string, CONTINUE); + } + if (exchange[n].related_phases == FALSE) return(OK); + for (i=0; i=0; j--) { + if (x[j]->type != EXCH) continue; + if (x[j]->master[0] == exchange[n].comps[i].master) break; + } + for (k=count_unknowns-1; k>=0; k--) { + if (x[k]->type != PP) continue; + if (x[k]->phase->name == exchange[n].comps[i].phase_name) break; + } + if (j == -1 ) { + input_error++; + sprintf(error_string,"Did not find unknown for master exchange species %s", exchange[n].comps[i].master->s->name); + error_msg(error_string, CONTINUE); + } + if (j == -1 || k == -1) continue; +/* + * Build jacobian + */ + comp_ptr = &exchange[n].comps[i]; + + /* charge balance */ + store_jacob0(charge_balance_unknown->number, x[k]->number, comp_ptr->formula_z * comp_ptr->phase_proportion); + store_sum_deltas(&delta[k], &charge_balance_unknown->delta, -comp_ptr->formula_z * comp_ptr->phase_proportion); + + + /* mole balance balance */ + for (jj = 0; comp_ptr->formula_totals[jj].elt != NULL; jj++) { + master_ptr = comp_ptr->formula_totals[jj].elt->primary; + if (master_ptr->in == FALSE) { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL) { + input_error++; + sprintf(error_string,"Did not find unknown for exchange related to mineral %s", exchange[n].comps[i].phase_name); + error_msg(error_string, STOP); + } + if (master_ptr->s->type == EX) { + if (equal(x[j]->moles, x[k]->moles * comp_ptr->formula_totals[jj].coef * comp_ptr->phase_proportion, 1.e-8) == FALSE) { + input_error++; + sprintf(error_string,"Number of sites in exchanger %s (=%e) not consistent with moles calculated from phase %s (%e).", master_ptr->s->name, (double) x[j]->moles, comp_ptr->phase_name, (double) (x[k]->moles * comp_ptr->formula_totals[jj].coef * comp_ptr->phase_proportion)); + error_msg(error_string, CONTINUE); + } + } + coef = comp_ptr->formula_totals[jj].coef; + if (master_ptr->s == s_hplus) { + row = mass_hydrogen_unknown->number; + unknown_ptr = mass_hydrogen_unknown; +#ifdef COMBINE +#ifndef COMBINE_CHARGE + coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o; +#else + coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o - x[j]->master[0]->s->z ; +#endif +#endif + } else if (master_ptr->s == s_h2o) { + row = mass_oxygen_unknown->number; + unknown_ptr = mass_oxygen_unknown; + } else { + row = master_ptr->unknown->number; + unknown_ptr = master_ptr->unknown; + } + store_jacob0(row, x[k]->number, coef * comp_ptr->phase_proportion); + store_sum_deltas(&delta[k], &unknown_ptr->delta, -coef * comp_ptr->phase_proportion); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_min_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Defines proportionality factor between mineral and surface to + * jacob0 + */ + int i, j, k, n, jj, row; + struct elt_list *next_elt; + struct surface_comp *comp_ptr; + struct unknown *unknown_ptr; + struct master *master_ptr; + LDBLE coef; + + if (use.surface_ptr == NULL) return(OK); + if (surface_bsearch(use.surface_ptr->n_user, &n) == NULL) { + input_error++; + sprintf(error_string,"Surface %d not found.", use.surface_ptr->n_user); + error_msg(error_string, CONTINUE); + } + if (surface[n].related_phases == FALSE) return(OK); + for (i=0; i=0; j--) { + if (x[j]->type != SURFACE) continue; + if (x[j]->master[0] == surface[n].comps[i].master) break; + } + for (k=count_unknowns-1; k>=0; k--) { + if (x[k]->type != PP) continue; + if (x[k]->phase->name == surface[n].comps[i].phase_name) break; + } + if (j == -1 ) { + input_error++; + sprintf(error_string,"Did not find unknown for master surface species %s", surface[n].comps[i].master->s->name); + error_msg(error_string, CONTINUE); + } + if (j == -1 || k == -1) continue; + + next_elt = x[j]->master[0]->s->next_elt; + comp_ptr = x[j]->surface_comp; + + /* update grams == moles in this case */ + if(j < count_unknowns - 1 && x[j+1]->type == SURFACE_CB) { +#ifdef SKIP +/* Major error, can't use "use." because it changes every time + have to use only things allocated in prep.c Now put + grams into unknown structure. */ +/* + store_sum_deltas(&delta[k], &(use.surface_ptr->charge[comp_ptr->charge].grams), -1.0); + */ +#endif + store_sum_deltas(&delta[k], &(x[j+1]->related_moles), -1.0); + } + /* mole balance balance */ + for (jj = 0; next_elt[jj].elt != NULL; jj++) { + master_ptr = next_elt[jj].elt->primary; + if (master_ptr->in == FALSE) { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL) { + input_error++; + sprintf(error_string,"Did not find unknown for surface related to mineral %s", surface[n].comps[i].phase_name); + error_msg(error_string, STOP); + } + if (master_ptr->s->type == SURF) { + if (equal(x[j]->moles, x[k]->moles * next_elt[jj].coef * comp_ptr->phase_proportion, 1.e-8) == FALSE) { + input_error++; + sprintf(error_string,"Number of sites in surface %s (=%e) not consistent with moles of phase %s (=%e).\n%s", master_ptr->s->name, (double) x[j]->moles, comp_ptr->phase_name, (double) (x[k]->moles * next_elt[jj].coef * comp_ptr->phase_proportion), "\tHas equilibrium_phase assemblage been redefined?\n"); + error_msg(error_string, CONTINUE); + } + } + coef = next_elt[jj].coef; + if (master_ptr->s == s_hplus) { + row = mass_hydrogen_unknown->number; + unknown_ptr = mass_hydrogen_unknown; +#ifdef COMBINE +#ifndef COMBINE_CHARGE + coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o; +#else + coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o - x[j]->master[0]->s->z; +#endif +#endif + } else if (master_ptr->s == s_h2o) { + row = mass_oxygen_unknown->number; + unknown_ptr = mass_oxygen_unknown; + } else { + row = master_ptr->unknown->number; + unknown_ptr = master_ptr->unknown; + } + store_jacob0(row, x[k]->number, coef * comp_ptr->phase_proportion); + store_sum_deltas(&delta[k], &unknown_ptr->delta, -coef * comp_ptr->phase_proportion); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int setup_related_surface (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for surface assemblage in unknown structure + */ + int i, k; + struct surface_comp *comp_ptr; + + if (use.surface_ptr == NULL) return(OK); + if (use.surface_ptr->related_phases == FALSE) return(OK); + + for (i = 0; i < count_unknowns; i++) { + if (x[i]->type == SURFACE && x[i]->surface_comp->phase_name != NULL) { + for (k=count_unknowns-1; k>=0; k--) { + if (x[k]->type != PP) continue; + if (x[k]->phase->name == x[i]->surface_comp->phase_name) break; + } + if (k == -1) continue; + + comp_ptr = x[i]->surface_comp; + x[i]->phase_unknown = x[k]; +/* !!!!! */ + x[i]->moles = x[k]->moles * comp_ptr->phase_proportion; + + } else if (x[i]->type == SURFACE_CB && x[i-1]->surface_comp->phase_name != NULL) { + for (k=count_unknowns-1; k>=0; k--) { + if (x[k]->type != PP) continue; + if (x[k]->phase->name == x[i]->surface_comp->phase_name) break; + } + if (k == -1) continue; + + comp_ptr = x[i]->surface_comp; + x[i]->phase_unknown = x[k]; +/* !!!! Added for security, not checked... */ + x[i]->related_moles = x[k]->moles * comp_ptr->phase_proportion; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int change_hydrogen_in_elt_list(LDBLE charge) +/* ---------------------------------------------------------------------- */ +{ + int j; + int found_h, found_o; + LDBLE coef_h, coef_o, coef; + found_h = -1; + found_o = -1; + coef_h = 0.0; + coef_o = 0.0; + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + for (j = 0; j < count_elts; j++) { + if (strcmp(elt_list[j].elt->name,"H") == 0) { + found_h = j; + coef_h = elt_list[j].coef; + } else if (strcmp(elt_list[j].elt->name,"O") == 0) { + found_o = j; + coef_o = elt_list[j].coef; + } + } + coef = coef_h-2*coef_o - charge; + if (found_h < 0 && found_o < 0) return(OK); + if (found_h >= 0 && found_o < 0) return(OK); + if (found_h < 0 && found_o >= 0) { + elt_list[count_elts].elt = s_hplus->primary->elt; + elt_list[count_elts].coef = coef; + count_elts++; + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + return(OK); + } + elt_list[found_h].coef = coef; + return(OK); +} diff --git a/print.cpp b/print.cpp new file mode 100644 index 00000000..223c3e72 --- /dev/null +++ b/print.cpp @@ -0,0 +1,2259 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +#define PITZER_EXTERNAL extern +#include "pitzer.h" +#include + +static char const svnid[] = "$Id: print.c 701 2005-12-22 15:20:59Z dlpark $"; + +static int print_alkalinity(void); +static int print_diffuse_layer(struct surface_charge *surface_charge_ptr); +static int print_eh(void); +static int print_irrev(void); +static int print_kinetics(void); +static int print_mix(void); +static int print_pp_assemblage(void); +static int print_s_s_assemblage(void); +static int print_saturation_indices(void); +static int print_totals(void); +static int print_using(void); +static int print_user_print(void); +static int punch_gas_phase(void); +static int punch_identifiers(void); +static int punch_kinetics(void); +static int punch_molalities(void); +static int punch_activities(void); +static int punch_pp_assemblage(void); +static int punch_s_s_assemblage(void); +static int punch_saturation_indices(void); +static int punch_totals(void); +static int punch_user_punch(void); + +#ifdef PHREEQ98 +static int punch_user_graph(void); +extern int colnr, rownr; +extern int graph_initial_solutions; +extern int prev_advection_step, prev_transport_step; /*, prev_reaction_step*/ +/* extern int shifts_as_points; */ +extern int chart_type; +extern int AddSeries; +extern int FirstCallToUSER_GRAPH; +#endif + +#if defined(SWIG_SHARED_OBJ) +extern void EndRow(void); +extern void AddSelectedOutput(const char* name, const char* format, va_list argptr); +#endif + +/* ---------------------------------------------------------------------- */ +int array_print(LDBLE *array_l, int row_count, int column_count, int max_column_count) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + if (svnid == NULL) fprintf(stderr," "); + + + for (i=0; i < row_count; i++) { + k = 0; + output_msg(OUTPUT_MESSAGE,"%d\n", i); + for (j=0; j < column_count; j++) { + if (k > 7) { + output_msg(OUTPUT_MESSAGE,"\n"); + k = 0; + } + output_msg(OUTPUT_MESSAGE,"%11.2e", (double) array_l[i*max_column_count + j]); + k++; + } + if (k != 0) { + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_all(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print each block of results in sequence to file output + * also print selected output to punch_file + * Each routine is controlled by a variable in structure print. + * print.all == FALSE will turn off all prints. + */ +/* + * Makes sorted list including all species for each valence state + */ + if (pr.all == FALSE) return(OK); + if(pr.surface == TRUE || + pr.exchange == TRUE || + pr.species == TRUE ) { + species_list_sort(); + } +/* + * Print results + */ + s_h2o->lm = s_h2o->la; + print_using(); + print_mix(); + print_irrev(); + print_kinetics(); + print_user_print(); + print_gas_phase(); + print_pp_assemblage(); + print_s_s_assemblage(); + print_surface(); + print_exchange(); + print_initial_solution_isotopes(); + print_isotope_ratios(); + print_isotope_alphas(); + print_totals(); + print_eh(); + print_species(); + print_alkalinity(); + print_saturation_indices(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_all(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + +#ifndef PHREEQ98 /* if not PHREEQ98 use the standard declaration */ + if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) return(OK); +/* + * Punch results + */ + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); + } else if (use.kinetics_in != FALSE) { + use.kinetics_ptr = kinetics_bsearch(-2, &i); + } +#else /* if PHREEQ98 execute punch_user_graph first, that is, before punch.in and pr.punch is checked */ + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); + } else if (use.kinetics_in != FALSE) { + use.kinetics_ptr = kinetics_bsearch(-2, &i); + } + if (pr.user_graph == TRUE) punch_user_graph(); + + if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) return(OK); +#endif + punch_identifiers(); + punch_totals(); + punch_molalities(); + punch_activities(); + punch_pp_assemblage(); + punch_saturation_indices(); + punch_gas_phase(); + punch_kinetics(); + punch_s_s_assemblage(); + punch_isotopes(); + punch_calculate_values(); + punch_user_punch(); +/* + * new line for punch_file + */ + fpunchf(NULL, "\n"); + +#if defined(SWIG_SHARED_OBJ) + EndRow(); +#endif + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_diffuse_layer(struct surface_charge *surface_charge_ptr1) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints total moles of each element in diffuse layer + * Remove comment to print total moles of each species + */ + int i, j, count_g; + LDBLE mass_water_surface; + LDBLE molality, moles_excess, moles_surface; + + if (use.surface_ptr == NULL) return(OK); +/* + * Find position of component in surface charge data + */ + i = 0; + for (j = 0; j < count_unknowns; j++) { + if (x[j]->type != SURFACE_CB) continue; + if (x[j]->surface_charge == surface_charge_ptr1) { + break; + } + i++; + } + if (j >= count_unknowns) { + sprintf(error_string, "In print_diffuse_layer: component not found, %s.", surface_charge_ptr1->name); + error_msg(error_string, STOP); + } +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + + output_msg(OUTPUT_MESSAGE,"\tKg water in diffuse layer: %e\n", + (double) surface_charge_ptr1->mass_water); + + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE,"\n\t\tDistribution of species in diffuse layer\n\n"); + output_msg(OUTPUT_MESSAGE,"\n\tSpecies \t Moles \tMoles excess\t g\n"); + } + mass_water_surface = surface_charge_ptr1->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { + if (s_x[j]->type > HPLUS) continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; +#ifdef SKIP + moles_excess = mass_water_bulk_x * +/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ + surface_charge_ptr1->g[count_g].g * molality; +#endif + moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; + moles_surface = mass_water_surface * molality + moles_excess; + if (debug_diffuse_layer == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", s_x[j]->name, + moles_surface, moles_excess, s_x[j]->diff_layer[i].charge->g[count_g].g); + } +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } +/* + strcpy(token, s_h2o->name); + ptr = &(token[0]); + get_elts_in_species (&ptr, mass_water_surface / gfw_water); + */ + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Print totals + */ + if (use.surface_ptr->donnan == FALSE) { + output_msg(OUTPUT_MESSAGE,"\n\tTotal moles in diffuse layer (excluding water)\n\n"); + } else { + output_msg(OUTPUT_MESSAGE,"\n\tTotal moles in diffuse layer (excluding water), Donnan calculation \n\n"); + } + output_msg(OUTPUT_MESSAGE,"\tElement \t Moles\n"); + for ( j=0; j < count_elts; j++ ) { + output_msg(OUTPUT_MESSAGE, "\t%-14s\t%12.4e\n", + elt_list[j].elt->name, + (double) elt_list[j].coef); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_eh(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints eh calculated from redox couples + * Only calculates eh if two redox states of an element have mass balance + * equations. + */ + int i, j, k, first; + LDBLE pe, eh; + struct master *master_ptr0, *master_ptr1; + char token[MAX_LENGTH]; + + if (pr.eh == FALSE || pr.all == FALSE) return(OK); + + tk_x=tc_x+273.15; + + first = TRUE; + for (i=0; i < count_master; i++) { + if (master[i]->in != TRUE ) continue; + if (master[i]->primary == TRUE) continue; +/* + * Secondary master species has mass balance equation + */ + master_ptr0 = master[i]->elt->primary; + for (k = i + 1; k < count_master; k++) { + if (master[k]->in != TRUE) continue; + master_ptr1 = master[k]->elt->primary; + if ( master_ptr1 != master_ptr0) break; +/* + * Another secondary master species of same element has mass balance equation + * Rewrite equations to calculate pe + */ + rewrite_master_to_secondary ( master[k], master[i] ); + trxn_swap ("e-"); +/* debug + trxn_print(); + */ +/* + * Calculate pe, eh + */ + pe = -k_calc(trxn.logk, tk_x); + for (j = 1; j < count_trxn; j++) { + pe -= trxn.token[j].s->la * trxn.token[j].coef; + } + eh = ( (LOG_10 * R_KJ_DEG_MOL * tk_x) / F_KJ_V_EQ ) * pe; +/* + * Print heading + */ + if (first == TRUE) { + print_centered("Redox couples"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s\n\n","Redox couple","pe","Eh (volts)"); + first = FALSE; + } +/* + * Print result + */ + strcpy(token,master[i]->elt->name); + strcat(token,"/"); + strcat(token,master[k]->elt->name); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.4f%12.4f\n", token, (double) pe, (double) eh); + } + } + if (first == FALSE) output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_exchange(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print moles of each exchange species + */ + int i; + struct exchange *exchange_ptr; + char *name, *name1; + struct master *master_ptr; + LDBLE dum, dum2; +/* + * Print exchange data + */ + exchange_ptr = use.exchange_ptr; + if (exchange_ptr == NULL || pr.exchange == FALSE || pr.all == FALSE) return(OK); + + if (state >= REACTION) { + print_centered("Exchange composition"); + } +/* + * Print list of species + */ + + s_h2o->lm = s_h2o->la; + name = s_hplus->secondary->elt->name; + for (i=0; i < count_species_list; i++) { +/* + * Get name of master species + */ + if (species_list[i].s->type != EX) continue; + if (species_list[i].master_s->secondary != NULL ) { + master_ptr = species_list[i].master_s->secondary; + name1=species_list[i].master_s->secondary->elt->name; + } else { + master_ptr = species_list[i].master_s->primary; + name1=species_list[i].master_s->primary->elt->name; + } +/* + * Check if new master species, print total molality + */ + if (name1 != name) { + name = name1; + output_msg(OUTPUT_MESSAGE,"%-14s%12.3e mol", name, (double) master_ptr->unknown->moles); + if (master_ptr->unknown->exch_comp->phase_name != NULL) { + output_msg(OUTPUT_MESSAGE, "\t[%g (mol %s)/(mol %s)]", + (double) master_ptr->unknown->exch_comp->phase_proportion, + master_ptr->unknown->exch_comp->formula, + master_ptr->unknown->exch_comp->phase_name); + } else + if (master_ptr->unknown->exch_comp->rate_name != NULL) { + output_msg(OUTPUT_MESSAGE, "\t[%g (mol %s)/(mol kinetic reactant %s)]", + (double) master_ptr->unknown->exch_comp->phase_proportion, + master_ptr->unknown->exch_comp->formula, + master_ptr->unknown->exch_comp->rate_name); + } + output_msg(OUTPUT_MESSAGE, "\n\n"); + /* Heading for species */ + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%10s\n"," "," ","Equiv- ", + "Equivalent","Log "); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%10s\n\n","Species","Moles ","alents ", + "Fraction", "Gamma"); + } +/* + * Print species data + */ +/* !!!!! */ + if (master_ptr->total > 1.0e-10) { + if (species_list[i].s->equiv != 0.0) { + dum = fabs(species_list[i].s->equiv)/master_ptr->total; + } else { + if (species_list[i].master_s->z == 0) { + dum = 1 / master_ptr->total; + } else { + dum = 1; + } + } + if (species_list[i].master_s->z != 0.0) { + dum2 = fabs(species_list[i].master_s->z); + } else { + dum2 =1; + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%12.3e%10.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) (species_list[i].s->moles * dum2 * species_list[i].s->equiv), + (double) (species_list[i].s->moles * dum /* / dum2 */), + (double) (species_list[i].s->lg - log10(dum)) ); + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints gas phase composition if present + */ + int j; + LDBLE lp, moles, initial_moles, delta_moles; + struct rxn_token *rxn_ptr; + + if (pr.gas_phase == FALSE || pr.all == FALSE) return(OK); + if (use.gas_phase_ptr == NULL) return(OK); + if (use.gas_phase_ptr->type == PRESSURE) { + if (gas_unknown == NULL) return(OK); + if (gas_unknown->moles < 1e-12) return(OK); + use.gas_phase_ptr->total_moles = gas_unknown->moles; + use.gas_phase_ptr->volume = use.gas_phase_ptr->total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; + } +/* + * Print heading + */ + print_centered("Gas phase"); + output_msg(OUTPUT_MESSAGE,"\n"); + output_msg(OUTPUT_MESSAGE, "Total pressure: %8.4f atmospheres\n", (double) use.gas_phase_ptr->total_p); + output_msg(OUTPUT_MESSAGE, " Gas volume: %10.2e liters\n", (double) use.gas_phase_ptr->volume); + + output_msg(OUTPUT_MESSAGE, "\n%66s\n%75s\n", "Moles in gas", "----------------------------------"); + output_msg(OUTPUT_MESSAGE,"%-15s%12s%12s%12s%12s%12s\n","Component","log P", "P", "Initial", "Final", + "Delta"); + + for( j = 0; j < use.gas_phase_ptr->count_comps; j++) { +/* + * Calculate partial pressure + */ + if (use.gas_phase_ptr->comps[j].phase->in == TRUE) { + lp=-use.gas_phase_ptr->comps[j].phase->lk; + for (rxn_ptr = use.gas_phase_ptr->comps[j].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + moles = use.gas_phase_ptr->comps[j].phase->moles_x; + } else { + lp = -99.99; + moles = 0; + use.gas_phase_ptr->comps[j].phase->p_soln_x = 0; + } +/* + * Print gas composition + */ + if (state != TRANSPORT && state != PHAST) { + initial_moles = use.gas_phase_ptr->comps[j].moles; + delta_moles = use.gas_phase_ptr->comps[j].phase->moles_x - + use.gas_phase_ptr->comps[j].moles; + } else { + initial_moles = use.gas_phase_ptr->comps[j].initial_moles; + delta_moles = use.gas_phase_ptr->comps[j].initial_moles - + use.gas_phase_ptr->comps[j].moles; + } + if (moles <= MIN_TOTAL) moles = 0.0; + if (fabs(delta_moles) <= MIN_TOTAL) delta_moles = 0.0; + output_msg(OUTPUT_MESSAGE,"%-15s%12.2f%12.3e%12.3e%12.3e%12.3e\n", + use.gas_phase_ptr->comps[j].phase->name, + (double) lp, + (double) use.gas_phase_ptr->comps[j].phase->p_soln_x, + (double) initial_moles, + (double) moles, + (double) delta_moles); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_s_s_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Prints solid solution composition if present + */ + int i, j; + LDBLE delta_moles; + LDBLE nb, nc, xb, xb1, xb2, xb1moles, xb2moles; + struct s_s *s_s_ptr; + + if (pr.s_s_assemblage == FALSE || pr.all == FALSE) return(OK); + if (use.s_s_assemblage_ptr == NULL) return(OK); + /* + * Print heading + */ + print_centered("Solid solutions"); + output_msg(OUTPUT_MESSAGE,"\n"); + output_msg(OUTPUT_MESSAGE, "\t%-15s %15s %11s %11s %11s\n", "Solid solution", "Component", "Moles", + "Delta moles", "Mole fract"); + /* + * Print solid solutions + */ + for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { + /* solid solution name, moles */ + output_msg(OUTPUT_MESSAGE,"\t%-15s %15s %11.2e\n", use.s_s_assemblage_ptr->s_s[j].name," ", + (double) use.s_s_assemblage_ptr->s_s[j].total_moles); + /* component name, moles, delta moles, mole fraction */ + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (state != TRANSPORT && state != PHAST) { + delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].delta; + } else { + delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].init_moles; + } + output_msg(OUTPUT_MESSAGE, "\t%15s %15s %11.2e %11.2e %11.2e\n", " ", + use.s_s_assemblage_ptr->s_s[j].comps[i].name, + (double) use.s_s_assemblage_ptr->s_s[j].comps[i].moles, + (double) delta_moles, + (double) (use.s_s_assemblage_ptr->s_s[j].comps[i].moles/ + use.s_s_assemblage_ptr->s_s[j].total_moles)); + } + s_s_ptr = &(use.s_s_assemblage_ptr->s_s[j]); + if(s_s_ptr->miscibility == TRUE) { + nc = s_s_ptr->comps[0].moles; + nb = s_s_ptr->comps[1].moles; + xb = nb/(nb + nc); + xb1 = s_s_ptr->xb1; + xb2 = s_s_ptr->xb2; + + if (xb > xb1 && xb < xb2) { + xb2moles = (xb1 - 1)/xb1*nb + nc; + xb2moles = xb2moles / ((xb1 - 1)/xb1*xb2 + (1 - xb2)); + xb1moles = (nb - xb2moles*xb2)/xb1; + output_msg(OUTPUT_MESSAGE, "\n\t%15s Solid solution is in miscibility gap\n", " "); + output_msg(OUTPUT_MESSAGE, "\t%15s End members in pct of %s\n\n", " ", s_s_ptr->comps[1].name); + output_msg(OUTPUT_MESSAGE, "\t%15s %11g pct %11.2e\n", " ", (double) xb1, (double) xb1moles); + output_msg(OUTPUT_MESSAGE, "\t%15s %11g pct %11.2e\n", " ", (double) xb2, (double) xb2moles); + } + } + } else { + /* solid solution name, moles */ + output_msg(OUTPUT_MESSAGE,"\t%-15s %15s %11.2e\n", use.s_s_assemblage_ptr->s_s[j].name," ", + (double) 0.0); + /* component name, moles, delta moles, mole fraction */ + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (state != TRANSPORT && state != PHAST) { + delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].delta; + } else { + delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - + use.s_s_assemblage_ptr->s_s[j].comps[i].init_moles; + } + output_msg(OUTPUT_MESSAGE, "\t%15s %15s %11.2e %11.2e %11.2e\n", " ", + use.s_s_assemblage_ptr->s_s[j].comps[i].name, + (double) 0, + (double) delta_moles, + (double) 0 ); + } + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int print_irrev(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints irreversible reaction as defined and as + * relative moles of each element and total amount + * of reaction + */ + int i; + struct irrev *irrev_ptr; + + if (pr.use == FALSE || pr.all == FALSE) return(OK); + if (state < REACTION || use.irrev_in == FALSE) return(OK); + if (state == TRANSPORT && transport_step == 0) return(OK); + irrev_ptr = use.irrev_ptr; +/* + * Print amount of reaction + */ + output_msg(OUTPUT_MESSAGE,"Reaction %d.\t%s\n\n", use.n_irrev_user, irrev_ptr->description); + output_msg(OUTPUT_MESSAGE,"\t%11.3e moles of the following reaction have been added:\n\n", (double) step_x); +/* + * Print reaction + */ + output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", " ", "Relative"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n\n", "Reactant", "moles"); + for (i = 0; i < irrev_ptr->count_list; i++) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%10.2f\n", irrev_ptr->list[i].name, (double) irrev_ptr->list[i].coef); + } + output_msg(OUTPUT_MESSAGE,"\n"); +/* + * Debug + */ + + output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", " ", "Relative"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", "Element", "moles"); + for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%10.2f\n", irrev_ptr->elts[i].elt->name, (double) irrev_ptr->elts[i].coef); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int print_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + int i, j; + LDBLE sim_time; + struct kinetics *kinetics_ptr; + if (pr.kinetics == FALSE || pr.all == FALSE) return(OK); + if (state < REACTION) return(OK); + kinetics_ptr = NULL; + if (use.kinetics_in == TRUE) { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); + } else { + kinetics_ptr = kinetics_bsearch(-2, &i); + } + } + if (kinetics_ptr == NULL) return(OK); +/* + * determine time step + */ + if (state == TRANSPORT || state == PHAST) { + kin_time_x = timest; + } else if (state == ADVECTION) { + kin_time_x =advection_kin_time; + } + sim_time = 0.; + if (incremental_reactions == TRUE) { + if (kinetics_ptr->count_steps > 0) { + for (i = 0; i < reaction_step; i++) { + if (i < kinetics_ptr->count_steps) { + sim_time += kinetics_ptr->steps[i]; + } else { + sim_time += kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } + } + } else if (kinetics_ptr->count_steps < 0) { + if (reaction_step > -kinetics_ptr->count_steps) { + sim_time = kinetics_ptr->steps[0]; + } else { + sim_time = reaction_step * kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); + } + } + } +/* + * Print amount of reaction + */ + if (phast == FALSE) { + output_msg(OUTPUT_MESSAGE,"Kinetics %d.\t%s\n\n", use.n_kinetics_user, kinetics_ptr->description); + } else { + output_msg(OUTPUT_MESSAGE,"Kinetics.\n\n"); + } +/* + * Print reaction + */ + if (state == TRANSPORT) { + output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n",(double) (initial_total_time + transport_step * timest)); + output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); + } else if (state == ADVECTION) { + output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n",(double) (initial_total_time + advection_step * advection_kin_time)); + output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); + } else if (state == PHAST) { + output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n", (double) rate_sim_time_end); + output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); + } else if (state == REACTION) { + if (incremental_reactions == FALSE) { + output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); + } else { + output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds (Incremented time: %g seconds)\n\n", (double) kin_time_x, (double) sim_time); + } + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s %-15s%12s\n\n", "Rate name", "Delta Moles","Total Moles","Reactant","Coefficient"); + for (i = 0; i < kinetics_ptr->count_comps; i++) { + if (state != TRANSPORT && state != PHAST) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", + kinetics_ptr->comps[i].rate_name, + (double) -kinetics_ptr->comps[i].moles, + (double) kinetics_ptr->comps[i].m); + } else { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", + kinetics_ptr->comps[i].rate_name, + (double) (kinetics_ptr->comps[i].m - kinetics_ptr->comps[i].initial_moles), + (double) kinetics_ptr->comps[i].m); + } + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { + if (j == 0) { + output_msg(OUTPUT_MESSAGE," %-15s%12g\n", kinetics_ptr->comps[i].list[j].name, + (double) kinetics_ptr->comps[i].list[j].coef); + } else { + output_msg(OUTPUT_MESSAGE,"\t%39s %-15s%12g\n"," ", kinetics_ptr->comps[i].list[j].name, + (double) kinetics_ptr->comps[i].list[j].coef); + } + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_master_reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Debugging print routine to test primary and secondary reactions + */ + int i; + struct rxn_token *next_token; + + for ( i=0; i < count_master; i++) { + output_msg(OUTPUT_MESSAGE,"%s\t%s\n\tPrimary reaction\n",master[i]->elt->name, master[i]->s->name); + next_token=master[i]->rxn_primary->token; + for (; next_token->s != NULL; next_token++) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); + } + output_msg(OUTPUT_MESSAGE,"\n\tSecondary reaction:\n"); + if (master[i]->rxn_secondary != NULL) { + next_token=master[i]->rxn_secondary->token; + for (; next_token->s != NULL; next_token++) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); + } + } + output_msg(OUTPUT_MESSAGE,"\n\tRedox reaction:\n"); + if (*(master[i]->pe_rxn) != NULL) { + next_token=(*(master[i]->pe_rxn))->token; + for (; next_token->s != NULL; next_token++) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int print_mix(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints definition of mixing, solution number and multiplier + */ + int i, n; + struct mix *mix_ptr; + struct solution *solution_ptr; + + if (pr.use == FALSE || pr.all == FALSE) return(OK); + if (use.mix_in == FALSE || state < REACTION) return(OK); + if (state == TRANSPORT) { + mix_ptr = mix_bsearch(use.n_mix_user, &i); + } else { + mix_ptr = mix_bsearch(use.n_mix_user_orig, &i); + } + if (mix_ptr == NULL) { + mix_ptr = use.mix_ptr; + } +/* + * Print mixture data + */ + if (mix_ptr == NULL) { + return(OK); + + } + if (state == TRANSPORT) { + output_msg(OUTPUT_MESSAGE,"Mixture %d.\t%s\n\n", use.n_mix_user, mix_ptr->description); + } else { + output_msg(OUTPUT_MESSAGE,"Mixture %d.\t%s\n\n", mix_ptr->n_user, mix_ptr->description); + } + for (i = 0; i < mix_ptr->count_comps; i++) { + solution_ptr = solution_bsearch (mix_ptr->comps[i].n_solution, &n, TRUE); + if (solution_ptr == NULL) { + input_error++; + return(ERROR); + } + output_msg(OUTPUT_MESSAGE,"\t%11.3e Solution %d\t%-55s\n", (double) mix_ptr->comps[i].fraction, + mix_ptr->comps[i].n_solution, solution[n]->description); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_reaction(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Debugging print of individual chemical reactions for + * species or phases + */ + int j; + struct rxn_token *next_token; + + if (pr.use == FALSE || pr.all == FALSE) return(OK); + + output_msg(OUTPUT_MESSAGE,"%s\t\n",rxn_ptr->token[0].s->name); + output_msg(OUTPUT_MESSAGE,"\n\tlog k:\n"); + for (j=0;j<7;j++) { + output_msg(OUTPUT_MESSAGE,"\t%f",(double) rxn_ptr->logk[j]); + } + output_msg(OUTPUT_MESSAGE,"\n\nReaction:\n"); + for (next_token=rxn_ptr->token; next_token->s != NULL; next_token++) { + output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_saturation_indices(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices of all applicable pure_phases + */ + int i; + LDBLE si, iap; + LDBLE lk; + LDBLE la_eminus; + struct rxn_token *rxn_ptr; + + if (pr.saturation_indices == FALSE || pr.all == FALSE) return(OK); + if (state == INITIAL_SOLUTION) { + iap = 0; + for (rxn_ptr = pe_x[default_pe_x].rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->coef*rxn_ptr->s->la; + /* fprintf(output,"\t%s\t%f\t%f\n", rxn_ptr->s->name, rxn_ptr->coef, rxn_ptr->s->la ); */ + } + lk = k_calc(pe_x[default_pe_x].rxn->logk, tk_x); + la_eminus = lk + iap; + /* fprintf(output,"\t%s\t%f\n", "pe", si ); */ + } else { + la_eminus = s_eminus->la; + } +/* + * Print heading + */ + print_centered("Saturation indices"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%7s%8s%8s\n\n","Phase","SI","log IAP", "log KT"); + + for (i=0; i < count_phases; i++) { + if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; +/* + * Print saturation index + */ +#ifdef SKIP + iap = 0.0; + for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + /* fprintf(output,"\t%s\t%f\t%e\n", rxn_ptr->s->name, rxn_ptr->s->la, rxn_ptr->coef); */ + } + si=-phases[i]->lk + iap; + output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, (double) si, (double) iap, (double) phases[i]->lk, phases[i]->formula); + si1 = si; +#endif + + /* pe_value_x = pe_x[default_pe_x].rxn;*/ + lk = k_calc(phases[i]->rxn->logk, tk_x); + iap = 0.0; + for (rxn_ptr = phases[i]->rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + /* iap += rxn_ptr->s->la * rxn_ptr->coef; */ + if (rxn_ptr->s != s_eminus) { + iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; + } else { + iap += la_eminus * rxn_ptr->coef; + } + /* output_msg(OUTPUT_MESSAGE,"\t%s\t%f\t%e\t%e\t%e\n", rxn_ptr->s->name, rxn_ptr->s->la, rxn_ptr->coef, rxn_ptr->s->lm, rxn_ptr->s->lg ); */ + } + si=-lk + iap; + output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, (double) si, (double) iap, (double) lk, phases[i]->formula); + +#ifdef SKIP + if (fabs(si1-si) > convergence_tolerance) { + sprintf(error_string, "SI1 != SI, %s SI1 %e, SI %e, diff %e\n", phases[i]->name, si1, si, si1 - si); + error_msg(error_string, CONTINUE); + } +#endif + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices and masses of pure_phases in pp_assemblage + */ + int j, k; + LDBLE si, iap, lk; + char token[MAX_LENGTH]; + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + + if (pr.pp_assemblage == FALSE || pr.all == FALSE) return(OK); + if (pure_phase_unknown == NULL) return(OK); +/* + * Print heading + */ + print_centered("Phase assemblage"); + output_msg(OUTPUT_MESSAGE, "%74s\n", "Moles in assemblage"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%7s%8s%8s","Phase","SI","log IAP", "log KT"); + output_msg(OUTPUT_MESSAGE,"%12s%12s%12s", " Initial", " Final", " Delta"); + output_msg(OUTPUT_MESSAGE,"\n\n"); + + for( j = 0; j < count_unknowns; j++) { + if (x[j]->type != PP) continue; +/* + * Print saturation index + */ + iap = 0.0; + phase_ptr=x[j]->phase; + if (x[j]->phase->rxn_x == NULL || phase_ptr->in == FALSE) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%23s", x[j]->phase->name, "Element not present."); + } else { + phase_ptr=x[j]->phase; + lk = k_calc(phase_ptr->rxn->logk, tk_x); + for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + if (rxn_ptr->s != s_eminus) { + iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; + } else { + iap += s_eminus->la * rxn_ptr->coef; + } + } + si=-lk + iap; + /* + for (rxn_ptr = x[j]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = -x[j]->phase->lk + iap; + output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) x[j]->phase->lk); + */ + output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) lk); + } +/* + * Print pure phase assemblage data + */ + if (x[j]->moles < 0.0) x[j]->moles = 0.0; + if (state != TRANSPORT && state != PHAST) { + sprintf(token, " %11.3e %11.3e %11.3e", + (double) (x[j]->pure_phase->moles + x[j]->pure_phase->delta), + (double) x[j]->moles, + (double) (x[j]->moles - x[j]->pure_phase->moles - x[j]->pure_phase->delta)); + } else { + sprintf(token, " %11.3e %11.3e %11.3e", + (double) x[j]->pure_phase->initial_moles, + (double) x[j]->moles, + (double) (x[j]->moles - x[j]->pure_phase->initial_moles)); + } + if (x[j]->moles <= 0.0) { + for (k=0; k < 11; k++) { + token[12+k] = ' '; + } + } + if (x[j]->pure_phase->add_formula == NULL) { + output_msg(OUTPUT_MESSAGE, "%36s\n", token); + } else { + output_msg(OUTPUT_MESSAGE,"\n\t\t%-15s%-15s%36s\n",x[j]->pure_phase->add_formula," is reactant", token); + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of solution, uses array species_list for + * order of aqueous species. + */ + int i; + char *name, *name1; + struct master *master_ptr; + LDBLE min; + LDBLE lm; + + if (pr.species == FALSE || pr.all == FALSE) return(OK); + min = -1000; + print_centered("Distribution of species"); +/* + * Heading for species + */ + if (pitzer_model == TRUE) { + if (ICON == TRUE) { + output_msg(OUTPUT_MESSAGE,"%67s%11s\n","MacInnes","MacInnes"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," ","MacInnes","Log ","Log ","Log "); + } else { + output_msg(OUTPUT_MESSAGE,"%67s%11s\n","Unscaled","Unscaled"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," ","Unscaled","Log ","Log ","Log "); + } + } else { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," "," ","Log ","Log ","Log "); + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n\n","Species","Molality","Activity", + "Molality","Activity","Gamma"); +/* + * Print list of species + */ + s_h2o->lm = s_h2o->la; + name = s_hplus->secondary->elt->name; + for (i=0; i < count_species_list; i++) { +/* + * Get name of master species + */ + if (species_list[i].s->type == EX) continue; + if (species_list[i].s->type == SURF) continue; + if (species_list[i].master_s->secondary != NULL ) { + master_ptr = species_list[i].master_s->secondary; + name1=species_list[i].master_s->secondary->elt->name; + } else { + master_ptr = species_list[i].master_s->primary; + name1=species_list[i].master_s->primary->elt->name; + } +/* + * Check if new master species, print total molality + */ + if (name1 != name) { + name = name1; + output_msg(OUTPUT_MESSAGE,"%-14s%12.3e\n",name, (double) (master_ptr->total/mass_water_aq_x)); + min = censor*master_ptr->total/mass_water_aq_x; + if (min > 0) { + min = log10(min); + } else { + min = -1000.; + } + } +/* + * Print species data + */ + if (species_list[i].s->lm > min) { + if (species_list[i].s == s_h2o) { + lm = log10(s_h2o->moles / mass_water_aq_x); + } else { + lm = species_list[i].s->lm; + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%10.3f%10.3f%10.3f\n", + species_list[i].s->name, + (double) ((species_list[i].s->moles)/mass_water_aq_x), + (double) under(species_list[i].s->lm + species_list[i].s->lg), + (double) lm, + (double) (species_list[i].s->lm+species_list[i].s->lg), + (double) species_list[i].s->lg ); + } + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of surface, including charge and potential, + * grams and specific area, moles of each species on surface sites, + * and description of diffuse layer if applicable. + */ + int i, j, k; + struct surface *surface_ptr; + char name[MAX_LENGTH], token[MAX_LENGTH]; + struct master *master_ptr; + LDBLE molfrac, charge; + char *ptr; +/* + * Print surface speciation + */ + surface_ptr = use.surface_ptr; + if (surface_ptr == NULL || pr.surface == FALSE || pr.all == FALSE) return(OK); + + if (state >= REACTION) { + print_centered("Surface composition"); + } +/* + * Print list of species + */ + + s_h2o->lm = s_h2o->la; + for (j =0; j < count_unknowns; j++) { + if (use.surface_ptr->edl == TRUE) { + if (x[j]->type != SURFACE_CB) continue; + strcpy(name, x[j]->master[0]->elt->name); + replace ("_psi", "", name); + } else { + if (x[j]->type != SURFACE) continue; + strcpy(token, x[j]->master[0]->elt->name); + replace ("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + } + output_msg(OUTPUT_MESSAGE,"%-14s\n",name); +/* + * Description of surface + */ + if (diffuse_layer_x == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t%11.3e Surface + diffuse layer charge, eq\n", (double) x[j]->f ); + } + if (use.surface_ptr->edl == TRUE && diffuse_layer_x == FALSE) { + charge = x[j]->f; + } else { + charge = calc_surface_charge(name); + } + output_msg(OUTPUT_MESSAGE,"\t%11.3e Surface charge, eq\n", (double) charge); + if (x[j]->type == SURFACE_CB) { + if ((x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) > 0) { + output_msg(OUTPUT_MESSAGE,"\t%11.3e sigma, C/m**2\n", + (double) (charge * F_C_MOL / + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams))); + } else { + output_msg(OUTPUT_MESSAGE,"\tundefined sigma, C/m**2\n"); + } + output_msg(OUTPUT_MESSAGE,"\t%11.3e psi, V\n", + (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ)); + output_msg(OUTPUT_MESSAGE,"\t%11.3e -F*psi/RT\n", + (double) (x[j]->master[0]->s->la * (-2) * LOG_10)); + output_msg(OUTPUT_MESSAGE,"\t%11.3e exp(-F*psi/RT)\n", + exp(x[j]->master[0]->s->la * (-2) * LOG_10)); + if (x[j]->surface_comp->phase_name != NULL) { + output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->phase_name); + output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->phase_name); + } else if (x[j]->surface_comp->rate_name != NULL) { + output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->rate_name); + output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->rate_name); + } else { + output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/g\n", + (double) x[j]->surface_charge->specific_area); + output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e g\n\n", + (double) (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams), + (double) x[j]->surface_charge->grams); + } + if (diffuse_layer_x == TRUE) print_diffuse_layer(x[j]->surface_charge); + output_msg(OUTPUT_MESSAGE,"\n"); +/* + * Heading for species + */ + for (k = j - 1; k < count_unknowns; k++) { + if (x[k]->type != SURFACE) continue; + if (x[j] != x[k]->potential_unknown) continue; + master_ptr = x[k]->master[0]; + output_msg(OUTPUT_MESSAGE,"%-14s\n",x[k]->master[0]->elt->name); + output_msg(OUTPUT_MESSAGE,"\t%11.3e moles", (double) x[k]->moles); + if (x[k]->surface_comp->phase_name != NULL) { + output_msg(OUTPUT_MESSAGE,"\t[%g mol/(mol %s)]\n", (double) x[k]->surface_comp->phase_proportion, x[k]->surface_comp->phase_name); + } else + if (x[k]->surface_comp->rate_name != NULL) { + output_msg(OUTPUT_MESSAGE,"\t[%g mol/(mol kinetic reactant %s)]\n", (double) x[k]->surface_comp->phase_proportion, x[k]->surface_comp->rate_name); + } else { + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n"," "," ","Mole", + " ", "Log"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n\n","Species", + "Moles", "Fraction", "Molality", "Molality"); + for (i=0; i < count_species_list; i++) { + if (species_list[i].master_s != master_ptr->s) continue; +/* + * Print species data + */ + if (x[k]->moles >= MIN_RELATED_SURFACE) { + molfrac = (LDBLE) (species_list[i].s->moles) / x[k]->moles * species_list[i].s->equiv; + } else { + molfrac = 0.0; + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3f%12.3e%12.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) molfrac, + (double) (species_list[i].s->moles/mass_water_aq_x), + log10(species_list[i].s->moles/mass_water_aq_x)); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + } else { + k = j; + master_ptr = x[k]->master[0]; + output_msg(OUTPUT_MESSAGE,"%-14s\n",x[k]->master[0]->elt->name); + output_msg(OUTPUT_MESSAGE,"\t%11.3e moles\n", (double) x[k]->moles); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n"," "," ","Mole", + " ", "Log"); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n\n","Species", + "Moles", "Fraction", "Molality", "Molality"); + for (i=0; i < count_species_list; i++) { + if (species_list[i].master_s != master_ptr->s) continue; +/* + * Print species data + */ + if (x[k]->moles >= MIN_RELATED_SURFACE) { + molfrac = (double) (species_list[i].s->moles) / x[k]->moles * species_list[i].s->equiv; + } else { + molfrac = 0.0; + } + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3f%12.3e%12.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) molfrac, + (double) (species_list[i].s->moles/mass_water_aq_x), + log10(species_list[i].s->moles/mass_water_aq_x)); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_totals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print total concentrations of elements, molality and moles. + */ + int i, pure_water; + + if (pr.totals == FALSE || pr.all == FALSE) return(OK); + print_centered("Solution composition"); + pure_water = TRUE; + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s\n\n","Elements","Molality","Moles"); + for (i = 0; i < count_unknowns; i++) { + if (x[i] == alkalinity_unknown) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e\n", x[i]->total->description, + (double) (x[i]->f/mass_water_aq_x), (double) x[i]->f); + pure_water = FALSE; + } + if (x[i] == ph_unknown) continue; + if (x[i] == pe_unknown) continue; + if (x[i] == charge_balance_unknown ) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", x[i]->description, + (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); + output_msg(OUTPUT_MESSAGE," Charge balance\n"); + pure_water = FALSE; + continue; + } + if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", x[i]->description, + (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); + output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", x[i]->phase->name); + pure_water = FALSE; + continue; + } + if (x[i]->type == MB) { + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e\n", x[i]->description, + (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); + pure_water = FALSE; + } + } + + if (pure_water == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t%-15s\n","Pure water"); + } +/* + * Description of solution + */ + output_msg(OUTPUT_MESSAGE,"\n"); + print_centered("Description of solution"); +/* + * pH + */ + output_msg(OUTPUT_MESSAGE,"%45s%7.3f ","pH = ",(double) (-(s_hplus->la))); + if (ph_unknown == NULL) { + output_msg(OUTPUT_MESSAGE,"\n"); + } else if (ph_unknown == charge_balance_unknown) { + output_msg(OUTPUT_MESSAGE," Charge balance\n"); + } else if (ph_unknown->type == SOLUTION_PHASE_BOUNDARY) { + output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", ph_unknown->phase->name); + } else if (ph_unknown->type == ALK) { + output_msg(OUTPUT_MESSAGE," Adjust alkalinity\n"); + } +/* + * pe + */ + output_msg(OUTPUT_MESSAGE,"%45s%7.3f ","pe = ",(double) (-(s_eminus->la))); + if (pe_unknown == NULL) { + output_msg(OUTPUT_MESSAGE,"\n"); + } else if (pe_unknown == charge_balance_unknown) { + output_msg(OUTPUT_MESSAGE," Charge balance\n"); + } else if (pe_unknown->type == SOLUTION_PHASE_BOUNDARY) { + output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", pe_unknown->phase->name); + } else if (pe_unknown->type == MH) { + output_msg(OUTPUT_MESSAGE," Adjusted to redox equilibrium\n"); + } +/* + * Others + */ + output_msg(OUTPUT_MESSAGE,"%45s%7.3f\n","Activity of water = ",exp( s_h2o->la * LOG_10)); + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Ionic strength = ", (double) mu_x); + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Mass of water (kg) = ", (double) mass_water_aq_x); + if (alkalinity_unknown == NULL) { + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total alkalinity (eq/kg) = ", (double) (total_alkalinity/mass_water_aq_x)); + } + if (carbon_unknown == NULL) { + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total carbon (mol/kg) = ", (double) (total_carbon/mass_water_aq_x)); + } + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total CO2 (mol/kg) = ", (double) (total_co2/mass_water_aq_x)); + output_msg(OUTPUT_MESSAGE,"%45s%7.3f\n","Temperature (deg C) = ", (double) tc_x); + output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Electrical balance (eq) = ", (double) cb_x); + output_msg(OUTPUT_MESSAGE,"%45s%6.2f\n","Percent error, 100*(Cat-|An|)/(Cat+|An|) = ", (double) (100*cb_x/total_ions_x)); + output_msg(OUTPUT_MESSAGE,"%45s%3d\n","Iterations = ",iterations); + if (pitzer_model == TRUE) { + output_msg(OUTPUT_MESSAGE,"%45s%3d\n","Gamma iterations = ",gamma_iterations); + output_msg(OUTPUT_MESSAGE,"%45s%9.5f\n","Osmotic coefficient = ", COSMOT); + output_msg(OUTPUT_MESSAGE,"%45s%9.5f\n","Density of water = ", DW0); + } + output_msg(OUTPUT_MESSAGE,"%45s%e\n","Total H = ", (double) total_h_x); + output_msg(OUTPUT_MESSAGE,"%45s%e\n","Total O = ", (double) total_o_x); + output_msg(OUTPUT_MESSAGE,"\n"); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_user_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print with user defined BASIC print routine + */ + int i; + struct kinetics *kinetics_ptr; + + char command[] = "run"; + + if (pr.user_print == FALSE || pr.all == FALSE) return(OK); + if (user_print->commands == NULL) return(OK); + kinetics_ptr = NULL; + if (use.kinetics_in == TRUE) { + kinetics_ptr = use.kinetics_ptr; + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); + } else { + use.kinetics_ptr = kinetics_bsearch(-2, &i); + } + } + print_centered("User print"); + if (user_print->new_def == TRUE) { + /* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */ + if (basic_compile(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase) != 0) { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + user_print->new_def = FALSE; + } + if (basic_run(command, user_print->linebase, user_print->varbase, user_print->loopbase) != 0) { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + output_msg(OUTPUT_MESSAGE,"\n"); + if (use.kinetics_in == TRUE) { + use.kinetics_ptr = kinetics_ptr; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_using(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print entities used in calculation + */ + struct mix *mix_ptr; + struct solution *solution_ptr; + struct exchange *exchange_ptr; + struct surface *surface_ptr; + struct pp_assemblage *pp_assemblage_ptr; + struct s_s_assemblage *s_s_assemblage_ptr; + struct gas_phase *gas_phase_ptr; + struct temperature *temperature_ptr; + struct irrev *irrev_ptr; + struct kinetics *kinetics_ptr; + int n; + + if (pr.use == FALSE || pr.all == FALSE) return(OK); + if (state < REACTION || phast == TRUE) return(OK); +/* + * Mixture or Solution + */ + if (use.mix_in == TRUE) { + if (state == TRANSPORT) { + mix_ptr = mix_bsearch(use.n_mix_user, &n); + } else { + mix_ptr = mix_bsearch(use.n_mix_user_orig, &n); + } + if (mix_ptr == NULL) { + mix_ptr = use.mix_ptr; + } + if (mix_ptr != NULL) { + if (state == TRANSPORT) { + output_msg(OUTPUT_MESSAGE,"Using mix %d.\t%s\n", use.n_mix_user, mix_ptr->description); + } else { + output_msg(OUTPUT_MESSAGE,"Using mix %d.\t%s\n", use.n_mix_user_orig, mix_ptr->description); + } + + } + } else { + solution_ptr = solution_bsearch (use.n_solution_user, &n, TRUE); + output_msg(OUTPUT_MESSAGE,"Using solution %d.\t%s\n", use.n_solution_user, solution_ptr->description); + } +/* + * Exchange and surface + */ + if (use.exchange_in == TRUE) { + exchange_ptr = exchange_bsearch(use.n_exchange_user, &n); + output_msg(OUTPUT_MESSAGE,"Using exchange %d.\t%s\n", use.n_exchange_user, exchange_ptr->description); + } + if (use.surface_in == TRUE) { + surface_ptr = surface_bsearch(use.n_surface_user, &n); + output_msg(OUTPUT_MESSAGE,"Using surface %d.\t%s\n", use.n_surface_user, surface_ptr->description); + } + if (use.pp_assemblage_in == TRUE) { + pp_assemblage_ptr = pp_assemblage_bsearch(use.n_pp_assemblage_user, &n); + output_msg(OUTPUT_MESSAGE,"Using pure phase assemblage %d.\t%s\n", use.n_pp_assemblage_user, + pp_assemblage_ptr->description); + } + if (use.s_s_assemblage_in == TRUE) { + s_s_assemblage_ptr = s_s_assemblage_bsearch(use.n_s_s_assemblage_user, &n); + output_msg(OUTPUT_MESSAGE,"Using solid solution assemblage %d.\t%s\n", use.n_s_s_assemblage_user, + s_s_assemblage_ptr->description); + } + if (use.gas_phase_in == TRUE) { + gas_phase_ptr = gas_phase_bsearch(use.n_gas_phase_user, &n); + output_msg(OUTPUT_MESSAGE,"Using gas phase %d.\t%s\n", use.n_gas_phase_user, gas_phase_ptr->description); + } + if (use.temperature_in == TRUE) { + temperature_ptr = temperature_bsearch(use.n_temperature_user, &n); + output_msg(OUTPUT_MESSAGE,"Using temperature %d.\t%s\n", use.n_temperature_user, temperature_ptr->description); + } + if (use.irrev_in == TRUE) { + if (state != TRANSPORT || transport_step > 0) { + irrev_ptr = irrev_bsearch(use.n_irrev_user, &n); + output_msg(OUTPUT_MESSAGE,"Using reaction %d.\t%s\n", use.n_irrev_user, irrev_ptr->description); + } + } + if (use.kinetics_in == TRUE) { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &n); + } else { + kinetics_ptr = kinetics_bsearch(-2, &n); + } + output_msg(OUTPUT_MESSAGE,"Using kinetics %d.\t%s\n", use.n_kinetics_user, kinetics_ptr->description); + } + output_msg(OUTPUT_MESSAGE,"\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints selected gas phase data + */ + int i, j; + LDBLE p, total_moles, volume; + LDBLE moles; + + if (punch.count_gases <= 0) return(OK); + p = 0.0; + total_moles = 0.0; + volume = 0.0; + if (gas_unknown != NULL && use.gas_phase_ptr != NULL){ + if (use.gas_phase_ptr->type == PRESSURE) { + use.gas_phase_ptr->total_moles = gas_unknown->moles; + use.gas_phase_ptr->volume = use.gas_phase_ptr->total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; + } + p = use.gas_phase_ptr->total_p; + total_moles = use.gas_phase_ptr->total_moles; + volume = total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; + } + if (punch.high_precision == FALSE) { + fpunchf("pressure", "%12.4e\t", p); + fpunchf("total mol", "%12.4e\t",total_moles); + fpunchf("volume", "%12.4e\t",volume); + } else { + fpunchf("pressure", "%20.12e\t", p); + fpunchf("total mol", "%20.12e\t",total_moles); + fpunchf("volume", "%20.12e\t",volume); + } + for (i = 0; i < punch.count_gases; i++) { + moles = 0.0; + if (use.gas_phase_ptr != NULL && punch.gases[i].phase != NULL) { + for( j = 0; j < use.gas_phase_ptr->count_comps; j++) { + + if (use.gas_phase_ptr->comps[j].phase != punch.gases[i].phase) continue; + moles = use.gas_phase_ptr->comps[j].phase->moles_x; + if ( moles <= MIN_TOTAL ) moles = 0.0; + break; + } + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("g_%s", punch.gases[i].name),"%12.4e\t", moles); + } else { + fpunchf(sformatf("g_%s", punch.gases[i].name),"%20.12e\t", moles); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_s_s_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints solid solution composition if present + */ + int i, j, k; + int found; + LDBLE moles; + +/* + * Print solid solutions + */ + for (k = 0; k < punch.count_s_s; k++) { + found = FALSE; + if (use.s_s_assemblage_ptr != NULL) { + for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { + for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { + if (strcmp_nocase(punch.s_s[k].name, use.s_s_assemblage_ptr->s_s[j].comps[i].name) == 0) { + if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { + moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; + } else { + moles = 0; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", + (double) moles); + } else { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", + (double) moles); + } + found = TRUE; + break; + } + } + if (found == TRUE) break; + } + } + if (found == FALSE) { + if (punch.high_precision == FALSE) { + fpunchf(sformatf("s_%s", punch.s_s[k].name),"%12.4e\t", 0.0); + } else { + fpunchf(sformatf("s_%s", punch.s_s[k].name),"%20.12e\t", 0.0); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_totals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print total concentrations of elements, molality and moles. + */ + int j; + LDBLE molality; + + for (j = 0; j < punch.count_totals; j++) { + if (punch.totals[j].master == NULL) { + molality =0.0; + } else if (punch.totals[j].master->primary == TRUE) { + molality = punch.totals[j].master->total_primary / mass_water_aq_x; + } else { + molality = punch.totals[j].master->total / mass_water_aq_x; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),"%12.4e\t", molality); + } else { + fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),"%20.12e\t", molality); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_molalities(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print concentrations of species (aq, ex, surf) + */ + int j; + LDBLE molality; + + for (j = 0; j < punch.count_molalities; j++) { + molality = 0.0; + if (punch.molalities[j].s != NULL && punch.molalities[j].s->in == TRUE) { + molality = punch.molalities[j].s->moles / mass_water_aq_x; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),"%12.4e\t", molality); + } else { + fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),"%20.12e\t", molality); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_activities(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print concentrations of species (aq, ex, surf) + */ + int j; + LDBLE la; + + for (j = 0; j < punch.count_activities; j++) { + la = -999.999; + if (punch.activities[j].s != NULL && punch.activities[j].s->in == TRUE) { + la = punch.activities[j].s->lm + punch.activities[j].s->lg; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("la_%s", punch.activities[j].name),"%12.4e\t", la); + } else { + fpunchf(sformatf("la_%s", punch.activities[j].name),"%20.12e\t", la); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints masses of selected pure_phases in pp_assemblage + */ + int i, j; + LDBLE moles, delta_moles; + + for (i = 0; i < punch.count_pure_phases; i++) { + delta_moles = 0; + moles = 0.0; + if (punch.pure_phases[i].phase != NULL) { + for( j = 0; j < count_unknowns; j++) { + if (x == NULL || x[j]->type != PP) continue; +/* + * Print pure phase assemblage data + */ + if (punch.pure_phases[i].phase != x[j]->pure_phase->phase) continue; + if (state != TRANSPORT && state != PHAST) { + moles = x[j]->moles; + delta_moles = x[j]->moles - x[j]->pure_phase->moles - x[j]->pure_phase->delta; + } else { + moles = x[j]->moles; + delta_moles = x[j]->moles - x[j]->pure_phase->initial_moles; + } + break; + } + } + if (punch.high_precision == FALSE) { + fpunchf(punch.pure_phases[i].name,"%12.4e\t", moles); + fpunchf(sformatf("d_%s", punch.pure_phases[i].name),"%12.4e\t", delta_moles); + } else { + fpunchf(punch.pure_phases[i].name,"%20.12e\t", moles); + fpunchf(sformatf("d_%s", punch.pure_phases[i].name),"%20.12e\t", delta_moles); + } + } + return(OK); +} +#define PHAST_NULL(x) (phast ? NULL : x) +/* ---------------------------------------------------------------------- */ +int punch_identifiers(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints series of integers to identify simulation number, + * state of calculations, reaction or transport step number, + * and temp, ph, pe, and mass of water for each line + * of selected output. + */ + const char *sformat; + const char *dformat; + const char *gformat; + int i, l; + char token[MAX_LENGTH]; + if (punch.in == FALSE) return(OK); + if (punch.high_precision == FALSE) { + l = 12; + sformat = "%12s\t"; + dformat = "%12d\t"; + gformat = "%12g\t"; + } else { + l = 20; + sformat = "%20s\t"; + dformat = "%20d\t"; + gformat = "%20g\t"; + } + +/* + * simulation or simul_tr + */ + + if (punch.sim == TRUE) { + if (state != TRANSPORT && state != PHAST) { + fpunchf(PHAST_NULL("sim"), dformat, simulation); + } else { + fpunchf(PHAST_NULL("sim"), dformat, simul_tr); + } + } + if (punch.state == TRUE) { + switch (state) { + case 0: + strcpy(token,"init"); + break; + case 1: + strcpy(token,"i_soln"); + break; + case 2: + strcpy(token,"i_exch"); + break; + case 3: + strcpy(token,"i_surf"); + break; + case 4: + strcpy(token,"i_gas"); + break; + case 5: + strcpy(token,"react"); + break; + case 6: + strcpy(token,"inverse"); + break; + case 7: + strcpy(token,"advect"); + break; + case 8: + strcpy(token,"transp"); + break; + } + fpunchf(PHAST_NULL("state"), sformat, token); + + } +/* + * solution number or cell number and time + */ + if (punch.soln == TRUE) { + if (state == TRANSPORT || state == PHAST) { + fpunchf(PHAST_NULL("soln"), dformat, cell); + } else if (state == ADVECTION) { + fpunchf(PHAST_NULL("soln"), dformat, use.n_solution_user); + } else if (state < REACTION) { + fpunchf(PHAST_NULL("soln"), dformat, use.solution_ptr->n_user); + } else { + if (use.mix_in == TRUE) { + if (state != TRANSPORT) { + fpunchf(PHAST_NULL("soln"),dformat, use.n_mix_user_orig); + } else { + fpunchf(PHAST_NULL("soln"),dformat, use.n_mix_user); + } + + } else { + fpunchf(PHAST_NULL("soln"), dformat, use.n_solution_user); + } + } + } + if (punch.dist == TRUE) { + if (state == ADVECTION) { + fpunchf(PHAST_NULL("dist_x"), dformat, use.n_solution_user); + } else if (state == TRANSPORT) { + fpunchf(PHAST_NULL("dist_x"), gformat, cell_data[cell-1 ].mid_cell_x); + } else { + fpunchf(PHAST_NULL("dist_x"), dformat, -99); + } + } + if (punch.time == TRUE) { + if (state == REACTION && incremental_reactions == TRUE && use.kinetics_ptr != NULL) { + if (use.kinetics_ptr->count_steps > 0) { + kin_time_x = 0.; + for (i = 0; i < reaction_step; i++) { + if (i < use.kinetics_ptr->count_steps) { + kin_time_x += use.kinetics_ptr->steps[i]; + } else { + kin_time_x += use.kinetics_ptr->steps[use.kinetics_ptr->count_steps - 1]; + } + } + } else if (use.kinetics_ptr->count_steps < 0) { + if (reaction_step > -use.kinetics_ptr->count_steps) { + kin_time_x = use.kinetics_ptr->steps[0]; + } else { + kin_time_x = reaction_step * use.kinetics_ptr->steps[0] / ( (LDBLE) (-use.kinetics_ptr->count_steps)); + } + } + } + if (state == REACTION) { + fpunchf(PHAST_NULL("time"), gformat, kin_time_x); + } else if (state == TRANSPORT || state == PHAST ) { + fpunchf(PHAST_NULL("time"), gformat, initial_total_time + rate_sim_time); + } else if (state == ADVECTION) { + if (advection_kin_time_defined == TRUE) { + fpunchf(PHAST_NULL("time"), gformat, initial_total_time + rate_sim_time); + } else { + fpunchf(PHAST_NULL("time"), dformat, advection_step); + } + } else { + fpunchf(PHAST_NULL("time"), dformat, -99); + } + } + +/* + * reaction or transport step + */ + if (punch.step == TRUE) { + if (state == REACTION) { + fpunchf(PHAST_NULL("step"), dformat, reaction_step); + } else if (state == ADVECTION) { + fpunchf(PHAST_NULL("step"), dformat, advection_step); + } else if (state == TRANSPORT) { + fpunchf(PHAST_NULL("step"), dformat, transport_step); + } else { + fpunchf(PHAST_NULL("step"), dformat, -99); + } + } + if (punch.ph == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("pH","%12g\t", (double) (-s_hplus->la)); + } else { + fpunchf("pH","%20.12e\t", (double) (-s_hplus->la)); + } + } + if (punch.pe == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("pe","%12g\t", (double) (-s_eminus->la)); + } else { + fpunchf("pe","%20.12e\t", (double) (-s_eminus->la)); + } + } + if (punch.rxn == TRUE) { + if (state >= REACTION && use.irrev_in == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("reaction","%12.4e\t", step_x); + } else { + fpunchf("reaction","%20.12e\t", step_x); + } + } else { + if (punch.high_precision == FALSE) { + fpunchf("reaction","%12d\t", -99); + } else { + fpunchf("reaction","%20d\t", -99); + } + } + } + if (punch.temp == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("temp(C)","%12.3f\t", tc_x); + } else { + fpunchf("temp(C)","%20.12e\t", tc_x); + } + } + if (punch.alk == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("Alk(eq/kgw)","%12g\t", (double) (total_alkalinity/mass_water_aq_x)); + } else { + fpunchf("Alk(eq/kgw)","%20.12e\t", (double) (total_alkalinity/mass_water_aq_x)); + } + } + if (punch.mu == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("mu","%12g\t", (double) mu_x); + } else { + fpunchf("mu","%20.12e\t", (double) mu_x); + } + } + if (punch.water == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("mass_H2O","%12g\t", (double) mass_water_aq_x); + } else { + fpunchf("mass_H2O","%20.12e\t", (double) mass_water_aq_x); + } + } + if (punch.charge_balance == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("charge(eq)","%12g\t", (double) cb_x); + } else { + fpunchf("charge(eq)","%20.12e\t", (double) cb_x); + } + } + if (punch.percent_error == TRUE) { + if (punch.high_precision == FALSE) { + fpunchf("pct_err","%12g\t", (double) (100*cb_x/total_ions_x)); + } else { + fpunchf("pct_err","%20.12e\t", (double) (100*cb_x/total_ions_x)); + } + } + + return(OK); +} +#undef PHAST_NULL +/* ---------------------------------------------------------------------- */ +int punch_saturation_indices(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices of selected phases + */ + int i; + LDBLE si, iap; + struct rxn_token *rxn_ptr; + + for (i=0; i < punch.count_si; i++) { + if (punch.si[i].phase == NULL || punch.si[i].phase->in == FALSE) { + si = -999.999; + } else { +/* + * Print saturation index + */ + iap = 0.0; + for (rxn_ptr = punch.si[i].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si=-punch.si[i].phase->lk + iap; + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("si_%s", punch.si[i].name),"%12.4f\t", si); + } else { + fpunchf(sformatf("si_%s", punch.si[i].name),"%20.12e\t", si); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int punch_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + int i, j; + struct kinetics *kinetics_ptr; + LDBLE moles, delta_moles; + + kinetics_ptr = NULL; + if (use.kinetics_in == TRUE) { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) { + kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); + } else { + kinetics_ptr = kinetics_bsearch(-2, &i); + } + } + for (i = 0; i < punch.count_kinetics; i++) { + moles = 0.0; + delta_moles = 0.0; + if (kinetics_ptr != NULL) { + for (j = 0; j < kinetics_ptr->count_comps; j++) { + if (strcmp_nocase(punch.kinetics[i].name, kinetics_ptr->comps[j].rate_name) == 0) { + if (state != TRANSPORT && state != PHAST) { + moles = kinetics_ptr->comps[j].m; + delta_moles = -kinetics_ptr->comps[j].moles; + } else { + moles = kinetics_ptr->comps[j].m; + delta_moles = kinetics_ptr->comps[j].m - kinetics_ptr->comps[j].initial_moles; + } + break; + } + } + } + if (punch.high_precision == FALSE) { + fpunchf(sformatf("k_%s", punch.kinetics[i].name),"%12.4e\t", moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name),"%12.4e\t", -delta_moles); + } else { + fpunchf(sformatf("k_%s", punch.kinetics[i].name),"%20.12e\t", moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name),"%20.12e\t", -delta_moles); + } + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int punch_user_punch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch with user defined BASIC print routine + */ + char command[] = "run"; + + extern int n_user_punch_index; + n_user_punch_index = 0; + if (punch.user_punch == FALSE) return(OK); + if (user_punch->commands == NULL) return(OK); + if (user_punch->new_def == TRUE) { + if (basic_compile(user_punch->commands, &user_punch->linebase, &user_punch->varbase, &user_punch->loopbase) != 0) { + error_msg("Fatal Basic error in USER_PUNCH.", STOP); + } + user_punch->new_def = FALSE; + } + if (basic_run(command, user_punch->linebase, user_punch->varbase, user_punch->loopbase) != 0) { + error_msg("Fatal Basic error in USER_PUNCH.", STOP); + } + return(OK); +} + +#ifdef PHREEQ98 +/* ---------------------------------------------------------------------- */ +int punch_user_graph(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Graph with user defined BASIC print routine + */ + char command[] = "run"; + + colnr = 0; +/* //if (pr.user_graph == FALSE || pr.all == FALSE) return(OK); */ +/* //if (punch.user_punch == FALSE) return(OK); */ +/* //if (punch.in == FALSE) return(OK); */ + if (user_graph->commands == NULL) return(OK); + if (((state == INITIAL_SOLUTION) || (state == INITIAL_EXCHANGE) || (state == INITIAL_SURFACE) || (state == INITIAL_GAS_PHASE)) && (graph_initial_solutions == FALSE)) return(OK); + if (FirstCallToUSER_GRAPH) AddSeries = TRUE; + if (state == REACTION) { + /*if (reaction_step == 1) AddSeries = TRUE; + else AddSeries = FALSE; */ + if (reaction_step > 1) AddSeries = FALSE; + } + if (state == ADVECTION) { + if (advection_step == 0 && graph_initial_solutions == FALSE) return(OK); + if (((chart_type == 1) && (advection_step == punch_ad_modulus)) || + ((chart_type == 0) && (advection_step != prev_advection_step))) AddSeries = TRUE; + else AddSeries = FALSE; + } + if (state == TRANSPORT) { + if (transport_step == 0 && graph_initial_solutions == FALSE) return(OK); + if (((chart_type == 1) && (transport_step == punch_modulus)) || + ((chart_type == 0) && (transport_step != prev_transport_step))) AddSeries = TRUE; + else AddSeries = FALSE; + } + if (user_graph->new_def == TRUE) { + if (basic_compile(user_graph->commands, &user_graph->linebase, &user_graph->varbase, &user_graph->loopbase) != 0) { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + user_graph->new_def = FALSE; + } + if (basic_run(command, user_graph->linebase, user_graph->varbase, user_graph->loopbase) != 0) { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + if (state == ADVECTION) prev_advection_step = advection_step; + if (state == TRANSPORT) prev_transport_step = transport_step; + /*if (state == REACTION) prev_reaction_step = reaction_step;*/ + + FirstCallToUSER_GRAPH = FALSE; + + return(OK); +} +#endif + +#if defined(HDF5_CREATE) +extern void HDFWriteHyperSlabV(const char* name, const char* format, va_list argptr); +#endif + +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern int Merge_fpunchf(const int length, const char* format, va_list argptr); +#endif + +int output_message(const int type, const char *err_str, const int stop, const char *format, va_list args); + +int fpunchf(const char* name, const char* format, ...) +{ + int retval = 0; + va_list args; + + va_start(args, format); + retval = output_message(OUTPUT_PUNCH, name, CONTINUE, format, args); + va_end(args); + + return retval; +} +int fpunchf_user(int user_index, const char* format, ...) +{ + static int s_warning = 0; + int retval = 0; + va_list args; + static char buffer[80]; + char* name; + + if (user_index < user_punch_count_headings) { + name = user_punch_headings[user_index]; + } + else { + if (s_warning == 0) { + sprintf(error_string, "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + warning_msg(error_string); + s_warning = 1; + } + sprintf(buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); + name = buffer; + } + + va_start(args, format); + retval = output_message(OUTPUT_PUNCH, name, CONTINUE, format, args); + va_end(args); + + return retval; +} +#ifdef SAVE +int fpunchf(const char* name, const char* format, ...) +{ + int retval = 0; + va_list args; + static char big_buffer[200]; + +#if defined(HDF5_CREATE) + if (pr.hdf == TRUE) { + va_start(args, format); + HDFWriteHyperSlabV(name, format, args); + va_end(args); + } +#endif + if (pr.punch == TRUE && punch.in == TRUE) { + va_start(args, format); + retval = output_message(OUTPUT_PUNCH, NULL, CONTINUE, format, args); + va_end(args); +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + va_start(args, format); + retval = vsprintf(big_buffer, format, args); + Merge_fpunchf(retval, format, args); + va_end(args); +#endif +#if defined(SWIG_SHARED_OBJ) + va_start(args, format); + AddSelectedOutput(name, format, args); + va_end(args); +#endif + } + return retval; +} +int fpunchf_user(int user_index, const char* format, ...) +{ + extern int warning_msg(const char* err_str); + static int s_warning = 0; + int retval = 0; + va_list args; + static char buffer[80]; + char* name; + + if (user_index < user_punch_count_headings) { + name = user_punch_headings[user_index]; + } + else { + if (s_warning == 0) { + sprintf(error_string, "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + warning_msg(error_string); + s_warning = 1; + } + sprintf(buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); + name = buffer; + } + +#if defined(HDF5_CREATE) + if (pr.hdf == TRUE) { + va_start(args, format); + HDFWriteHyperSlabV(name, format, args); + va_end(args); + } +#endif + + if (punch.in == TRUE && pr.punch == TRUE) { + va_start(args, format); + retval = output_message(OUTPUT_PUNCH, NULL, CONTINUE, format, args); + va_end(args); +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + va_start(args, format); + Merge_fpunchf(retval, format, args); + va_end(args); +#endif +#if defined(SWIG_SHARED_OBJ) + va_start(args, format); + AddSelectedOutput(name, format, args); + va_end(args); +#endif + } + return retval; +} +#endif + +char *sformatf(const char* format, ...) +{ +#if defined(HDF5_CREATE) || defined SWIG_SHARED_OBJ + static char scratch[240]; + va_list args; + + va_start(args, format); + if (vsprintf(scratch, format, args) > 239) { + error_msg("buffer overwrite in sformatf", STOP); + } + va_end(args); + return scratch; +#else + return NULL; +#endif +} + +/* ---------------------------------------------------------------------- */ +int print_alkalinity(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of solution, uses array species_list for + * order of aqueous species. + */ + int i, j; + struct species_list *alk_list; + int count_alk_list; + double min; + + if (pr.alkalinity == FALSE || pr.all == FALSE) return(OK); + print_centered("Distribution of alkalinity"); + alk_list = (struct species_list *) PHRQ_malloc((size_t) (count_s_x *sizeof(struct species_list))); + if (alk_list == NULL) malloc_error(); + j = 0; + for (i = 0; i < count_s_x; i++) { + if (s_x[i]->alk == 0.0) continue; + alk_list[j].master_s = s_hplus; + alk_list[j].s = s_x[i]; + alk_list[j].coef = s_x[i]->alk; + j++; + } + count_alk_list = j; + min = fabs(censor*total_alkalinity/mass_water_aq_x); + if (count_alk_list > 0) { + output_msg(OUTPUT_MESSAGE,"\t%26s%11.3e\n\n","Total alkalinity (eq/kgw) = ", (double) (total_alkalinity/mass_water_aq_x)); + output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s\n\n","Species","Alkalinity","Molality", "Alk/Mol"); + qsort (&alk_list[0], (size_t) count_alk_list, + (size_t) sizeof(struct species_list), species_list_compare_alk); + for (i = 0; i < count_alk_list; i++) { + if (fabs(alk_list[i].s->alk*(alk_list[i].s->moles)/mass_water_aq_x) < min) continue; + output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%10.2f\n", + alk_list[i].s->name, + (double) (alk_list[i].s->alk*(alk_list[i].s->moles)/mass_water_aq_x), + (double) ((alk_list[i].s->moles)/mass_water_aq_x), + (double) (alk_list[i].s->alk)); + } + } + + output_msg(OUTPUT_MESSAGE,"\n"); + alk_list = (struct species_list *) free_check_null(alk_list); + return(OK); +} diff --git a/read.cpp b/read.cpp new file mode 100644 index 00000000..949ce156 --- /dev/null +++ b/read.cpp @@ -0,0 +1,7904 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" +extern int read_solution_raw (void); +extern int read_exchange_raw (void); +extern int read_surface_raw (void); +extern int read_equilibrium_phases_raw (void); +extern int read_kinetics_raw (void); +extern int read_solid_solutions_raw (void); +extern int read_gas_phase_raw (void); +extern int read_reaction_raw (void); +extern int read_mix_raw (void); +extern int read_temperature_raw (void); +static char const svnid[] = "$Id: read.c 715 2006-01-18 01:26:29Z dlpark $"; + +#if defined(SWIG_SHARED_OBJ) +#define STATIC +#else +#define STATIC static +#endif +STATIC int read_advection (void); +STATIC int read_analytical_expression_only (char *ptr, LDBLE *log_k); +STATIC int read_copy (void); +STATIC int read_debug (void); +STATIC int read_delta_h_only (char *ptr, LDBLE *delta_h, DELTA_H_UNIT *units); +STATIC int read_llnl_aqueous_model_parameters(void); +STATIC int read_exchange(void); +STATIC int read_exchange_master_species (void); +STATIC int read_exchange_species (void); +STATIC int read_gas_phase(void); +STATIC int read_incremental_reactions(void); +STATIC int read_inverse(void); +STATIC int read_inv_balances (struct inverse *inverse_ptr, char *next_char); +STATIC int read_inv_isotopes (struct inverse *inverse_ptr, char *ptr); +STATIC int read_inv_phases (struct inverse *inverse_ptr, char *next_char); +STATIC int read_kinetics (void); +STATIC int read_line_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc); +STATIC int read_lines_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc, const char **opt_list, int count_opt_list, int *opt); +STATIC LDBLE *read_list_doubles(char **ptr, int *count_doubles ); +STATIC int *read_list_ints (char **ptr, int *count_ints, int positive ); +STATIC int *read_list_t_f (char **ptr, int *count_ints ); +STATIC int read_master_species (void); +STATIC int read_mix (void); +STATIC int read_named_logk(void); +STATIC int read_phases(void); +STATIC int read_print (void); +STATIC int read_pure_phases(void); +STATIC int read_rates (void); +STATIC int read_reaction (void); +STATIC int read_reaction_reactants(struct irrev *irrev_ptr); +STATIC int read_reaction_steps(struct irrev *irrev_ptr); +STATIC int read_solid_solutions(void); +STATIC int read_temperature (void); +STATIC int read_reaction_temps(struct temperature *temperature_ptr); +STATIC int read_save(void); +STATIC int read_selected_output (void); +STATIC int read_solution(void); +STATIC int read_species (void); +STATIC int read_surf(void); +STATIC int read_surface_master_species (void); +STATIC int read_surface_species (void); +STATIC int read_use(void); +STATIC int read_title (void); +STATIC int read_user_print (void); +STATIC int read_user_punch (void); +#ifdef PHREEQ98 +STATIC int read_user_graph (void); +extern int connect_simulations, graph_initial_solutions; +/*extern*/ int shifts_as_points; +extern int chart_type; +extern int ShowChart; +extern int RowOffset, ColumnOffset; +#endif + +extern int reading_database(void); +extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, + int print); + +#ifdef PHREEQ98 +extern int copy_title(char *token_ptr, char **ptr, int *length); +extern int OpenCSVFile(char file_name[MAX_LENGTH]); +void GridHeadings(char* s, int i); +void SetAxisTitles(char* s, int i); +void SetAxisScale(char* a, int c, char* v, int l); +void SetChartTitle(char* s); +#endif + +static LDBLE dummy; + +/* ---------------------------------------------------------------------- */ +int read_input(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l; + char *ptr; + char token[2*MAX_LENGTH]; + if (svnid == NULL) fprintf(stderr," "); + + parse_error = 0; + input_error = 0; + next_keyword = 0; + count_warnings = 0; +/* + * Initialize keyword flags + */ + for (i=0; i < NKEYS; i++) { + keyword[i].keycount=0; + } +/* + * Initialize use and save pointers + */ + use.solution_in = FALSE; + use.solution_ptr = NULL; + use.pp_assemblage_in = FALSE; + use.pp_assemblage_ptr = NULL; + use.mix_in = FALSE; + use.mix_ptr = NULL; + use.irrev_in = FALSE; + use.irrev_ptr = NULL; + use.kinetics_in = FALSE; + use.kinetics_ptr = NULL; + use.exchange_in = FALSE; + use.exchange_ptr = NULL; + use.surface_in = FALSE; + use.surface_ptr = NULL; + use.temperature_in = FALSE; + use.temperature_ptr = NULL; + use.gas_phase_in = FALSE; + use.gas_phase_ptr = NULL; + use.s_s_assemblage_in = FALSE; + use.s_s_assemblage_ptr = NULL; + use.trans_in = FALSE; + use.advect_in = FALSE; + + save.solution = FALSE; + save.mix = FALSE; + save.irrev = FALSE; + save.pp_assemblage = FALSE; + save.exchange = FALSE; + save.surface = FALSE; + save.gas_phase = FALSE; + save.s_s_assemblage = FALSE; + title_x = (char *) free_check_null(title_x); + + while ( (i = check_line("Subroutine Read", FALSE, TRUE, TRUE, TRUE)) != KEYWORD) { + /* empty, eof, keyword, print */ + + if ( i == EOF) return(EOF); + sprintf(error_string, "Unknown input, no keyword has been specified."); + warning_msg(error_string); + } +/* + 0 "eof" + 1 "end" + 2 "species" + 3 "master" + 4 "solution" + 5 "phases" + 6 "pure_phases" + 7 "reaction" + 8 "mix" + 9 "use" + 10 "save" + 11 "exchange_species" + 12 "master_exchange_species" + 13 "exchange" + 14 "surface_species" + 15 "master_surface_species" + 16 "surface" + 17 "reacton_temperature" + 18 "inverse_modeling" + 19 "gas_phase" + 20 "transport" + 21 "debug" + 22 "selected_output" + 23 "select_output" + 24 "knobs" + 25 "print" + 26 "equilibrium_phases" + 27 "equilibria" + 28 "equilibrium" + 29 "pure" + 30 "title" + 31 "comment" + 32 "advection" + 33 "kinetics" + 34 "incremental_reactions" + 35 "incremental" + 36 "rates" + 37 "solution_s" + 38 "user_print" + 39 "user_punch" + 40 "solid_solutions" + 41 "solid_solution" + 42 "solution_spread" + 43 "spread_solution" + 44 "selected_out" + 45 "select_out" + 46 "user_graph" + 47 "llnl_aqueous_model_parameters" + 48 "llnl_aqueous_model" + 49 "database" + 50 "named_analytical_expression" + 51 "named_analytical_expressions" + 52 "named_expressions" + 53 "named_log_k" + 54 "isotopes" + 55 "calculate_values" + 56 "isotopes_ratios", + 57 "isotopes_alphas" + 58 "copy" + 59 "pitzer" + 60 "solution_raw" + 61 "exchange_raw" + 62 "surface_raw" + 63 "equilibrium_phases_raw" + 64 "kinetics_raw" + 65 "solid_solutions_raw" + 66 "gas_phase_raw" + 67 "reaction_raw" + 68 "mix_raw" + 69 "reaction_temperature_raw" + */ + for (;;) { + if (next_keyword >= 0) { + /* keyword[next_keyword].keycount++;*/ + if (next_keyword != 49 && !reading_database()) first_read_input = FALSE; + } + switch(next_keyword) { + case -1: /* Have not read line with keyword */ + sprintf(error_string, "Unknown input, no keyword has been specified."); + warning_msg(error_string); + while ((j = check_line ("No keyword", FALSE, TRUE, TRUE, TRUE)) != KEYWORD + && j != EOF ) { + warning_msg(error_string); + } + break; + case 0: /* End encountered */ + case 1: /* EOF encountered */ + goto END_OF_SIMULATION_INPUT; + case 2: /* Read aqueous model */ + keyword[2].keycount++; + read_species(); + break; + case 3: /* Read master species */ + keyword[3].keycount++; + read_master_species(); + break; + case 4: /* Read solution data */ + keyword[4].keycount++; + read_solution(); + solution_sort(); + break; + case 5: + keyword[5].keycount++; + read_phases(); + break; + case 6: + case 26: + case 27: + case 28: + case 29: + keyword[6].keycount++; + keyword[26].keycount++; + keyword[27].keycount++; + keyword[28].keycount++; + keyword[29].keycount++; + read_pure_phases(); + break; + case 7: + keyword[7].keycount++; + read_reaction(); + break; + case 8: + keyword[8].keycount++; + read_mix(); + break; + case 9: + keyword[9].keycount++; + read_use(); + break; + case 10: + keyword[10].keycount++; + read_save(); + break; + case 11: + keyword[11].keycount++; + read_exchange_species(); + break; + case 12: + keyword[12].keycount++; + read_exchange_master_species(); + break; + case 13: + keyword[13].keycount++; + read_exchange(); + break; + case 14: + keyword[14].keycount++; + read_surface_species(); + break; + case 15: + keyword[15].keycount++; + read_surface_master_species(); + break; + case 16: + keyword[16].keycount++; + read_surf(); + break; + case 17: + keyword[17].keycount++; + read_temperature(); + break; + case 18: + keyword[18].keycount++; + read_inverse(); + break; + case 19: + keyword[19].keycount++; + read_gas_phase(); + break; + case 20: + keyword[20].keycount++; + read_transport(); + break; + case 21: + case 24: + keyword[21].keycount++; + keyword[24].keycount++; + read_debug(); + break; + case 22: + case 23: + case 44: + case 45: + keyword[22].keycount++; + keyword[23].keycount++; + keyword[44].keycount++; + keyword[45].keycount++; + read_selected_output(); + break; + case 25: + keyword[25].keycount++; + read_print(); + break; + case 30: + case 31: + keyword[30].keycount++; + keyword[31].keycount++; + read_title(); + break; + case 32: + keyword[32].keycount++; + read_advection(); + break; + case 33: + keyword[33].keycount++; + read_kinetics(); + break; + case 34: + case 35: + keyword[34].keycount++; + keyword[35].keycount++; + read_incremental_reactions(); + break; + case 36: + keyword[36].keycount++; + read_rates(); + break; + case 37: + case 42: + case 43: + keyword[37].keycount++; + keyword[42].keycount++; + keyword[43].keycount++; + read_solution_spread(); +#ifdef SKIP + solution_sort(); +#endif + break; + case 38: + keyword[38].keycount++; + read_user_print(); + break; + case 39: + keyword[39].keycount++; + read_user_punch(); + break; + case 40: + case 41: + keyword[40].keycount++; + keyword[41].keycount++; + read_solid_solutions(); + break; + case 46: + keyword[46].keycount++; +#ifdef PHREEQ98 + read_user_graph(); +# else + for (;;) { + j=check_line ("Reading user_graph", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD ) { + break; + } + } +#endif + break; + case 47: + case 48: + keyword[47].keycount++; + keyword[48].keycount++; + read_llnl_aqueous_model_parameters(); + break; + case 49: + keyword[49].keycount++; + if (reading_database()) { + /* warning_msg("DATABASE is ignored in the database file."); */ + } else if (first_read_input == FALSE) { + error_msg("DATABASE must be the first keyword in the input file.", CONTINUE); + input_error++; + } else { + ptr = line; + copy_token(token, &ptr, &l); + user_database = string_duplicate(ptr); + if (string_trim(user_database) == EMPTY) { + error_msg("DATABASE file name is missing.", CONTINUE); + input_error++; + user_database = (char *) free_check_null(user_database); + } + first_read_input = FALSE; + } + j=check_line ("Reading after DATABASE", FALSE, TRUE, TRUE, TRUE); + break; + case 50: + case 51: + case 52: + case 53: + keyword[50].keycount++; + keyword[51].keycount++; + keyword[52].keycount++; + keyword[53].keycount++; + read_named_logk(); + break; + case 54: + keyword[54].keycount++; + read_isotopes(); + break; + case 55: + keyword[55].keycount++; + read_calculate_values(); + break; + case 56: + keyword[56].keycount++; + read_isotope_ratios(); + break; + case 57: + keyword[57].keycount++; + read_isotope_alphas(); + break; + case 58: + keyword[58].keycount++; + read_copy(); + break; + case 59: + keyword[59].keycount++; + read_pitzer(); + break; + case 60: + keyword[60].keycount++; + read_solution_raw(); + break; + case 61: + keyword[61].keycount++; + read_exchange_raw(); + break; + case 62: + keyword[62].keycount++; + read_surface_raw(); + break; + case 63: + keyword[63].keycount++; + read_equilibrium_phases_raw(); + break; + case 64: + keyword[64].keycount++; + read_kinetics_raw(); + break; + case 65: + keyword[65].keycount++; + read_solid_solutions_raw(); + break; + case 66: + keyword[66].keycount++; + read_gas_phase_raw(); + break; + case 67: + keyword[67].keycount++; + read_reaction_raw(); + break; + case 68: + keyword[68].keycount++; + read_mix_raw(); + break; + case 69: + keyword[69].keycount++; + read_temperature_raw(); + break; + } + } + END_OF_SIMULATION_INPUT: + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_conc(int n, int count_mass_balance, char *str) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + int alk; + int count_redox_states; + + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; +/* + * Set defaults + */ + /* + solution[n]->totals[count_mass_balance].equation_name = NULL; + solution[n]->totals[count_mass_balance].phase = NULL; + solution[n]->totals[count_mass_balance].phase_si = 0.0; + solution[n]->totals[count_mass_balance].units=NULL; + solution[n]->totals[count_mass_balance].n_pe=-1; + solution[n]->totals[count_mass_balance].as=NULL; + solution[n]->totals[count_mass_balance].gfw= 0.0; + */ + conc_init(&(solution[n]->totals[count_mass_balance])); + +/* + * Remove space between "kg" and "solution" or "water" in units + */ + replace("Kg","kg",str); + replace("KG","kg",str); + while (replace("kg ","kg",str) == TRUE); + ptr=str; +/* + * Read master species list for mass balance equation + */ + token1[0]='\0'; + count_redox_states=0; + while ( ((j = copy_token(token, &ptr, &l)) == UPPER ) || + ( token[0] == '[' ) || + ( strcmp_nocase_arg1(token,"ph") == 0 ) || + ( strcmp_nocase_arg1(token,"pe") == 0 ) ) { + count_redox_states++; + replace("(+","(",token); + if (count_redox_states > 1) strcat(token1," "); + strcat(token1,token); + } + if (count_redox_states == 0) { + input_error++; + error_msg ("No element or master species given for concentration input.", CONTINUE); + return(ERROR); + } + solution[n]->totals[count_mass_balance].description = string_hsave (token1); +/* + * Determine if reading alkalinity, allow equivalents for units + */ + str_tolower(token1); + if (strstr(token1,"alk") == token1) { + alk=TRUE; + } else { + alk=FALSE; + } +/* + * Read concentration + */ + + j=sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].input_conc)); + if (j == 0 ) { + sprintf(error_string,"Concentration data error for %s in solution input.", token1); + error_msg(error_string, CONTINUE); + return(ERROR); + } + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); +/* + * Read optional data + */ + strcpy(token1,token); +/* + * Check for units info + */ + if (check_units (token1, alk, FALSE, solution[n]->units, FALSE) == OK) { + if (check_units (token1, alk, FALSE, solution[n]->units, TRUE) == OK) { + solution[n]->totals[count_mass_balance].units = + string_hsave( token1 ); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); + } else { + return(ERROR); + } + } +/* + * Check for "as" followed by formula to be used for gfw + */ + strcpy(token1,token); + str_tolower(token1); + if ( strcmp(token1,"as") == 0 ) { + copy_token(token, &ptr, &l); + solution[n]->totals[count_mass_balance].as = string_hsave(token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); +/* + * Check for "gfw" followed by gram formula weight + */ + } else if (strcmp(token1,"gfw") == 0 ) { + if (copy_token(token, &ptr, &l) != DIGIT) { + error_msg("Expecting gram formula weight.", CONTINUE); + return(ERROR); + } else { + sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].gfw)); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); + } + } +/* + * Check for redox couple for pe + */ + if ( strcmp_nocase_arg1(token,"pe") == 0 ) { + solution[n]->totals[count_mass_balance].n_pe = pe_data_store (&(solution[n]->pe), token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); + } else if ( strstr(token,"/") != NULL) { + if (parse_couple(token) == OK ) { + solution[n]->totals[count_mass_balance].n_pe = + pe_data_store (&(solution[n]->pe), token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); + } else { + return(ERROR); + } + } +/* + * Must have phase + */ + solution[n]->totals[count_mass_balance].equation_name = string_hsave(token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); +/* + * Check for saturation index + */ + j=sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].phase_si)); + if (j != 1 ) { + error_msg("Expected saturation index.", CONTINUE); + return(ERROR); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int read_exchange_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for exchange species, parse equations + */ + int i; + int association; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; + + struct species *s_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + LDBLE exchange_coef; + LDBLE offset; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "mb", /* 2 */ + "mass_balance", /* 3 */ + "log_k", /* 4 */ + "logk", /* 5 */ + "delta_h", /* 6 */ + "deltah", /* 7 */ + "analytical_expression", /* 8 */ + "a_e", /* 9 */ + "ae", /* 10 */ + "mole_balance", /* 11 */ + "gamma", /* 12 */ + "davies", /* 13 */ + "offset", /* 14 */ + "llnl_gamma", /* 15 */ + "add_logk", /* 16 */ + "add_log_k", /* 17 */ + "add_constant" /* 18 */ + }; + int count_opt_list = 19; + + association=TRUE; + s_ptr = NULL; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EXCHANGE_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* mb */ + case 3: /* mass_balance */ + case 11: /* mole_balance */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count =0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = elt_list_save(); +/* debug + for (i = 0; i < count_elts; i++) { + output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 4: /* log_k */ + case 5: /* logk */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 6: /* delta_h */ + case 7: /* deltah */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 8: /* analytical_expression */ + case 9: /* a_e */ + case 10: /* ae */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[2])); + opt_save = OPTION_DEFAULT; + break; + case 12: /* gamma data */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 2; + i = sscanf(next_char,SCANFORMAT SCANFORMAT, &s_ptr->dha, &s_ptr->dhb ); + if (i < 2) { + sprintf(error_string, "Expecting 2 activity-" + "coefficient parameters, a and b."); + warning_msg(error_string); + } + if (s_ptr->dha == 0 && s_ptr->dhb == 0) { + s_ptr->dhb = 99.9; + s_ptr->exch_gflag = 1; + } + opt_save = OPTION_DEFAULT; + break; + case 13: /* davies eqn */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 1; + s_ptr->dha = 0; + s_ptr->dhb = 99.9; + opt_save = OPTION_DEFAULT; + break; + case 14: /* offset */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (sscanf(next_char, SCANFORMAT, &offset) != 1) { + error_msg("No offset for log K given", STOP); + } + s_ptr->logk[0] += offset; + opt_save = OPTION_DEFAULT; + break; + case 15: /* llnl_gamma */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 7; /* llnl D-H */ + i = sscanf(next_char,SCANFORMAT, &s_ptr->dha); + if (i < 1) { + sprintf(error_string, "Expecting activity-coefficient parameter, a."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 16: /* add_logk */ + case 17: /* add_log_k */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) { + input_error++; + sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 18: /* add_constant */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + input_error++; + sprintf(error_string, "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get exchange species information and parse equation + */ + s_ptr = NULL; + if ( parse_eq(line, &next_elt, association ) == ERROR) { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = s_store(trxn.token[0].name, trxn.token[0].z, TRUE); + for (i=1; inext_elt=next_elt; + for ( ; next_elt->elt != NULL; next_elt++) { + if ( strcmp (next_elt->elt->name,"C") == 0 ) { + trxn.token[0].s->carbon = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"H") == 0 ) { + trxn.token[0].s->h = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"O") == 0 ) { + trxn.token[0].s->o = next_elt->coef; + } + } +/* + * Find valence of cation from coefficients of reaction components + * Changed to be coefficient of exchanger + */ + exchange_coef = 0.0; + for (i=1; itype == EX) { + exchange_coef = trxn.token[i].coef; + } + } + trxn.token[0].s->equiv = exchange_coef; +/* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); +/* + * Copy reaction to reaction for species + */ + token_ptr=trxn.token[0].s->rxn->token; + for (i=0; itype = EX; + s_ptr=trxn.token[0].s; +/* + * Set gamma data + */ + s_ptr->gflag = 4; + s_ptr->exch_gflag = 3; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + opt_save = OPTION_DEFAULT; +/* + * Save as a phase for inverse modeling only + */ + phase_ptr = phase_store(s_ptr->name); + if (phase_ptr == NULL) { + input_error++; + sprintf(error_string, "Copying exchange to phases."); + error_msg(error_string, CONTINUE); + } + phase_ptr->formula=s_ptr->name; + phase_ptr->check_equation = FALSE; + phase_ptr->type = EX; + phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt); + phase_ptr->rxn = rxn_dup(s_ptr->rxn); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_exchange(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads exchange data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, l, n, count_comps; + int n_user, n_user_end; + LDBLE conc; + char *ptr; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + struct exchange *exchange_ptr; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "equilibrate", /* 0 */ + "equil", /* 1 */ + "pitzer_exchange_gammas", /* 2 */ + "exchange_gammas", /* 3 */ + "gammas" /* 4 */ + }; + int count_opt_list = 5; +/* + * kin_exch is for exchangers, related to kinetically reacting minerals + * they are defined if "sites" is followed by mineral name: + * Z Manganite ('equi' or 'kine') 0.25 + * ^Name ^equi or kinetic mineral ^switch ^prop.factor + */ +/* + * Read exchange number and description + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Find space for exchange data + */ + exchange_ptr = exchange_search(n_user, &n, FALSE); + if (exchange_ptr != NULL) { + exchange_free(exchange_ptr); + } else { + n = count_exchange++; + space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); + } +/* + * Default values + */ + exchange_init(&(exchange[n]), n_user, n_user_end, description); + free_check_null(description); + if (use.exchange_in == FALSE) { + use.exchange_in = TRUE; + use.n_exchange_user = n_user; + } +/* + * Read exchange data + */ + count_comps = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EXCHANGE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* equilibrate */ + case 1: + /* + * Read solution to equilibrate with + */ + for (;;) { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) { + sscanf(token, "%d", &exchange[n].n_solution); + exchange[n].new_def = TRUE; + exchange[n].solution_equilibria = TRUE; + break; + } + if (i == EMPTY) { + error_msg("Expected a solution number with which to equilibrate exchanger.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case 2: /* pitzer_exchange_gammas */ + case 3: /* exchange_gammas */ + case 4: /* gammas */ + exchange[n].pitzer_exchange_gammas = get_true_false(next_char, TRUE); + break; + case OPTION_DEFAULT: + exchange[n].comps = (struct exch_comp *) PHRQ_realloc(exchange[n].comps, (size_t) (count_comps + 1) * sizeof (struct exch_comp)); + if (exchange[n].comps == NULL) malloc_error(); + exchange[n].comps[count_comps].formula = NULL; + exchange[n].comps[count_comps].formula_totals = NULL; + exchange[n].comps[count_comps].phase_name = NULL; + exchange[n].comps[count_comps].phase_proportion = 0.0; + exchange[n].comps[count_comps].rate_name = NULL; + ptr=line; + i = copy_token(token, &ptr, &l); + /* + * Species formula is stored in token + */ + if (i != UPPER && token[0] != '[') { + error_msg("Expected exchanger name to begin with a capital letter.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + exchange[n].comps[count_comps].formula = string_hsave(token); + i = copy_token(token1, &ptr, &l); + if (i == DIGIT) { + /* + * Read exchange concentration + */ + + /* exchanger conc. is read directly .. */ + if ( sscanf(token1, SCANFORMAT, &conc) < 1) { + error_msg("Expected concentration of exchanger.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + j = copy_token(token1, &ptr, &l); + if( j == UPPER || j == LOWER) { + exchange[n].comps[count_comps].rate_name = string_hsave(token1); + if (copy_token(token1, &ptr, &l) != DIGIT) { + error_msg("Expected a coefficient to relate exchange to kinetic reaction.\n", CONTINUE); + input_error++; + break; + } + sscanf(token1, SCANFORMAT, &exchange[n].comps[count_comps].phase_proportion); + exchange[n].related_rate = TRUE; + } + /* + * Read equilibrium phase name or kinetics rate name + */ + } else if (i != EMPTY) { + + /* exchanger conc. is related to mineral or kinetics */ + exchange[n].comps[count_comps].phase_name = string_hsave(token1); + j = copy_token(token1, &ptr, &l); + if (j == DIGIT) { + exchange[n].related_phases = TRUE; + } else { + if (token1[0] == 'K' || token1[0] == 'k') { + exchange[n].comps[count_comps].rate_name = exchange[n].comps[count_comps].phase_name; + exchange[n].comps[count_comps].phase_name = NULL; + exchange[n].related_rate = TRUE; + } else if (token1[0] == 'E' || token1[0] == 'e') { + exchange[n].related_phases = TRUE; + } else { + error_msg("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate exchange to mineral or kinetic reaction.\n", CONTINUE); + input_error++; + break; + } + j = copy_token(token1, &ptr, &l); + } + + + if (j != DIGIT) { + error_msg("Expected a coefficient to relate exchanger to mineral or kinetic reaction.\n", CONTINUE); + input_error++; + break; + } + sscanf(token1, SCANFORMAT, &exchange[n].comps[count_comps].phase_proportion); + /* real conc must be defined in tidy_model */ + conc = 1.0; + } else { + error_msg("Expected concentration of exchanger, mineral name, or kinetic reaction name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + /* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + ptr = token; + get_elts_in_species(&ptr, conc); + /* + * save formula for adjusting number of exchange sites + */ + ptr = token; + get_token(&ptr, token1, &exchange[n].comps[count_comps].formula_z, &l); + exchange[n].comps[count_comps].formula_totals = elt_list_save(); + /* + * Save elt_list + */ + exchange[n].comps[count_comps].moles = conc; + exchange[n].comps[count_comps].totals = elt_list_save(); + exchange[n].comps[count_comps].charge_balance = 0.0; + count_comps++; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + exchange[n].count_comps = count_comps; + return(return_value); +} + +/* ---------------------------------------------------------------------- */ +int read_exchange_master_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species data from data file or input file + */ + int j, l; + char *ptr, *ptr1; + LDBLE z; + struct element *elts_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + for (;;) { + j=check_line ("Exchange species equation", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD ) { + break; + } +/* + * Get element name with valence, allocate space, store + */ + ptr=line; +/* + * Get element name and save pointer to character string + */ + if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { + parse_error++; + error_msg("Reading element for master species.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + /* + if (token[0] == '[') { + ptr1 = token; + get_elt(&ptr, element, &l); + strcpy(token, element); + } + */ + replace ("(+", "(", token); +/* + * Delete master if it exists + */ + master_delete(token); +/* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master >= max_master) { + space ((void **) ((void *) &master), count_master+1, &max_master, sizeof(struct master *)); + } + master[count_master] = master_alloc(); +/* + * Set type to EX + */ + master[count_master]->type = EX; +/* + * Save element name + */ + master[count_master]->elt = element_store ( token ); +/* + * Save pointer to species data for master species + */ + if ( ( copy_token(token, &ptr, &l) != UPPER ) && + token[0] != '[' && + ( strcmp_nocase_arg1(token, "e-") != 0 ) ) { + parse_error++; + error_msg("Reading master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + s_ptr=s_search (token); + if (s_ptr != NULL) { + master[count_master]->s = s_ptr; + } else { + ptr1=token; + get_token(&ptr1, token1, &z, &l); + master[count_master]->s = s_store(token1, z, FALSE); + } +/* + * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES + */ + master[count_master]->primary=TRUE; + if ( strcmp(master[count_master]->elt->name,"E") != 0 ) { + elts_ptr = element_store(master[count_master]->elt->name); + elts_ptr->gfw = 0.0; + } + + count_master++; + if (count_master >= max_master) { + space ((void **) ((void *) &master), count_master, &max_master, + sizeof(struct master *)); + } + } + return (j); +} +/* ---------------------------------------------------------------------- */ +int read_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads gas phase data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int count_comps; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + struct gas_phase *gas_phase_ptr; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "pressure", /* 0 */ + "volume", /* 1 */ + "temp", /* 2 */ + "temperature", /* 3 */ + "fixed_pressure", /* 4 */ + "fixed_volume", /* 5 */ + "equilibrium", /* 6 */ + "equilibrate", /* 7 */ + "equil" /* 8 */ + }; + int count_opt_list = 9; +/* + * Read gas_phase number + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Find old gas_phase or alloc space for new gas_phase + */ + gas_phase_ptr = gas_phase_search(n_user, &n); + if (gas_phase_ptr != NULL) { + gas_phase_free(gas_phase_ptr); + } else { + n=count_gas_phase; + count_gas_phase++; + space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); + } +/* + * Initialize + */ + gas_phase_init(&(gas_phase[n]), n_user, n_user_end, description); + free_check_null(description); +/* + * Set use data to first read + */ + if (use.gas_phase_in == FALSE) { + use.gas_phase_in = TRUE; + use.n_gas_phase_user = n_user; + } +/* + * Read phases + */ + count_comps = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in GAS_PHASE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* pressure */ + sscanf( next_char,SCANFORMAT, &dummy); + gas_phase[n].total_p = (LDBLE) dummy; + break; + case 1: /* Volume */ + sscanf( next_char,SCANFORMAT, &(gas_phase[n].volume) ); + break; + case 2: /* Temperature */ + case 3: + j = sscanf( next_char,SCANFORMAT, &(gas_phase[n].temperature) ); + if (j == 1) { + gas_phase[n].temperature += 273.15; + } + break; + case 4: /* fixed_pressure */ + gas_phase[n].type = PRESSURE; + break; + case 5: /* fixed_volume */ + gas_phase[n].type = VOLUME; + break; + case 6: /* equilibrate */ + case 7: /* equilibrium */ + case 8: /* equil */ +/* + * Read solution to equilibrate with + */ + for (;;) { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) { + sscanf(token, "%d", &gas_phase[n].n_solution); + gas_phase[n].new_def = TRUE; + gas_phase[n].solution_equilibria = TRUE; + break; + } + if (i == EMPTY) { + error_msg("Expected a solution number with which to equilibrate gas phase.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case OPTION_DEFAULT: +/* + * Make space, set default + */ + gas_phase[n].comps = (struct gas_comp *) PHRQ_realloc(gas_phase[n].comps, (size_t) (count_comps + 1) * sizeof(struct gas_comp)); + if (gas_phase[n].comps == NULL) malloc_error(); + gas_phase[n].comps[count_comps].p_read = 0.0; + gas_phase[n].comps[count_comps].moles = 0.0; + count_comps++; +/* + * Read name + */ + ptr = line; + copy_token(token, &ptr, &l); + gas_phase[n].comps[count_comps - 1].name = string_hsave(token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { + gas_phase[n].comps[count_comps - 1].p_read = NAN; + break; + } +/* + * Read initial partial pressure of gas + */ + + j=sscanf( token,SCANFORMAT, &(gas_phase[n].comps[count_comps - 1].p_read) ); + if (j != 1 ) { + error_msg("Expected partial pressure of gas in gas phase.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* + * Sort components by name (lowercase) + */ + gas_phase[n].count_comps = count_comps; + qsort (gas_phase[n].comps, + (size_t) count_comps, + (size_t) sizeof(struct gas_comp), + gas_comp_compare); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_inverse(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads data for mass_balance calculations + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int n, j; + int n_user, n_user_end; + char *ptr; + char *description; + LDBLE range_max, inv_tol, water_uncertainty; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "solutions", /* 0 */ + "uncertainty", /* 1 */ + "uncertainties", /* 2 */ + "balances", /* 3 */ + "phase_data", /* 4 */ + "range", /* 5 */ + "minimal", /* 6 */ + "minimum", /* 7 */ + "balance", /* 8 */ + "bal", /* 9 */ + "sol", /* 10 */ + "phases", /* 11 */ + "ranges", /* 12 */ + "tolerance", /* 13 */ + "u_water", /* 14 */ + "uncertainty_water", /* 15 */ + "force", /* 16 */ + "force_solution", /* 17 */ + "force_solutions", /* 18 */ + "isotopes", /* 19 */ + "mineral_water", /* 20 */ + "phase", /* 21 */ + "multiple_precision", /* 22 */ + "mp_tolerance", /* 23 */ + "censor_mp" /* 24 */ + }; + int count_opt_list = 25; + + ptr=line; +/* + * Read solution number and description + */ + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Malloc space for solution data + */ + if (inverse_search(n_user, &n) != NULL) { + inverse_delete(n); + } + inverse_alloc(); + n = count_inverse - 1; +/* + * Initialize structure and use + */ + inverse[n].new_def = TRUE; + inverse[n].n_user = n_user; + inverse[n].range = FALSE; + inverse[n].range_max = 1000.; + inverse[n].tolerance = 1e-10; + inverse[n].minimal = FALSE; + inverse[n].description = description; + inverse[n].count_uncertainties = 1; + inverse[n].uncertainties[0] = 0.05; + inverse[n].count_ph_uncertainties = 1; + inverse[n].ph_uncertainties[0] = 0.05; + inverse[n].water_uncertainty = 0.0; + inverse[n].mineral_water = TRUE; + inverse[n].mp = FALSE; + inverse[n].mp_tolerance = 1e-12; + inverse[n].mp_censor = 1e-20; +/* + * Read data for inverse modeling + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + opt_save = opt; + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in INVERSE_MODELING keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* solutions */ + case 10: /* solution */ + inverse[n].solns = read_list_ints(&next_char, &inverse[n].count_solns, TRUE); + opt_save = OPTION_ERROR; + break; + case 1: /* uncertainty */ + case 2: /* uncertainties */ + inverse[n].uncertainties = (double *) free_check_null (inverse[n].uncertainties); + inverse[n].uncertainties = read_list_doubles(&next_char, &inverse[n].count_uncertainties); + opt_save = OPTION_ERROR; + break; + case 3: /* balances */ + case 8: /* balance */ + case 9: /* bal */ + read_inv_balances( &(inverse[n]), next_char ); + break; + case 4: /* phase_data */ + case 11: /* phases */ + case 21: /* phase */ + read_inv_phases( &(inverse[n]), next_char ); + break; + case 5: /* range */ + case 12: /* ranges */ + inverse[n].range = TRUE; + j = sscanf( next_char, SCANFORMAT, &range_max ) ; + if (j == 1 ) { + inverse[n].range_max = range_max; + } + opt_save = OPTION_ERROR; + break; + case 6: /* minimal */ + case 7: /* minimum */ + inverse[n].minimal = TRUE; + opt_save = OPTION_ERROR; + break; + case 13: /* tolerance */ + j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; + if (j == 1 ) { + inverse[n].tolerance = inv_tol; + } + opt_save = OPTION_ERROR; + break; + case 14: /* u_water */ + case 15: /* uncertainty_water */ + j = sscanf( next_char, SCANFORMAT, &water_uncertainty ) ; + if (j == 1 ) { + inverse[n].water_uncertainty = water_uncertainty; + } + opt_save = OPTION_ERROR; + break; + case 16: /* force */ + case 17: /* force_solution */ + case 18: /* force_solutions */ + inverse[n].force_solns = (int *) free_check_null (inverse[n].force_solns); + inverse[n].force_solns = read_list_t_f(&next_char, + &inverse[n].count_force_solns); + opt_save = OPTION_ERROR; + break; + case 19: /* isotope values */ + read_inv_isotopes( &(inverse[n]), next_char ); + break; + case 20: /* mineral_water */ + inverse[n].mineral_water = get_true_false(next_char, TRUE); + break; + case 22: /* multiple_precision */ + inverse[n].mp = get_true_false(next_char, TRUE); + break; + case 23: /* mp_tolerance */ + j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; + if (j == 1 ) { + inverse[n].mp_tolerance = fabs(inv_tol); + } + break; + case 24: /* censor_mp */ + j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; + if (j == 1 ) { + inverse[n].mp_censor = fabs(inv_tol); + } + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* + * Default: soln 1 -> soln 2 + */ + if (inverse[n].count_solns == 0) { + inverse[n].solns = (int *) PHRQ_malloc( 2 * sizeof( int ) ); + if (inverse[n].solns == NULL) malloc_error(); + inverse[n].solns[0] = 1; + inverse[n].solns[1] = 2; + inverse[n].count_solns = 2; + } +/* + * Sort isotopes + */ + if (inverse[n].count_isotopes > 0) { + qsort (inverse[n].isotopes, + (size_t) inverse[n].count_isotopes, + (size_t) sizeof(struct inv_isotope), + inverse_isotope_compare); + } + + if (inverse[n].count_i_u > 0) { + qsort (inverse[n].i_u, + (size_t) inverse[n].count_i_u, + (size_t) sizeof(struct inv_isotope), + inverse_isotope_compare); + } + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_inv_balances (struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int j, l, count; + char token[MAX_LENGTH]; +/* + * Read element name + */ + j = copy_token(token, &ptr, &l); + if (j == EMPTY) { + return(OK); + } else if (j == LOWER && strcmp_nocase_arg1(token,"ph") != 0) { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } else if (strcmp_nocase_arg1(token, "ph") != 0) { + inverse_ptr->elts = (struct inv_elts *) PHRQ_realloc(inverse_ptr->elts, (size_t) (inverse_ptr->count_elts + 1) * sizeof( struct inv_elts)); + if (inverse_ptr->elts == NULL) malloc_error(); + replace("(+","(",token); + inverse_ptr->elts[inverse_ptr->count_elts].name = string_hsave(token); +/* + * Read element uncertainties + */ + inverse_ptr->elts[inverse_ptr->count_elts].uncertainties = read_list_doubles(&ptr, &count); + inverse_ptr->elts[inverse_ptr->count_elts].count_uncertainties = count; + inverse_ptr->count_elts++; + } else if (strcmp_nocase_arg1(token, "ph") == 0) { + inverse_ptr->ph_uncertainties = (double *) free_check_null (inverse_ptr->ph_uncertainties); + inverse_ptr->ph_uncertainties = read_list_doubles(&ptr, &count); + inverse_ptr->count_ph_uncertainties = count; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_inv_isotopes (struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, l1, l2, count; + LDBLE isotope_number; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr1, *ptr2, *redox_name, *element_name; +/* + * Read element name + */ + ptr1 = ptr; + j = copy_token(token, &ptr1, &l); +/* + * ptr1 is start of uncertainties + */ + if (j == EMPTY) { + return(OK); + } else if (j != DIGIT) { + error_msg("Expecting isotope to begin with isotope number.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Read isotope name + */ + ptr2 = token; + get_num(&ptr2, &isotope_number); + if (ptr2[0] == '\0' || isupper((int) ptr2[0]) == FALSE) { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + + /* redox state name with parentheses */ + redox_name = string_hsave(ptr2); + + copy_token(token, &ptr2, &l1); + replace("("," ",token); + ptr2 = token; + + /* element name, without parentheses */ + copy_token(token1, &ptr2, &l2); + element_name = string_hsave(token1); + +/* + * add element name to inv_ptr->isotopes + */ + for (i = 0; i < inverse_ptr->count_isotopes; i++) { + if (element_name == inverse_ptr->isotopes[i].elt_name) break; + } + if (i == inverse_ptr->count_isotopes) { + inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->isotopes, (size_t) (inverse_ptr->count_isotopes + 1) * sizeof( struct inv_isotope)); + if (inverse_ptr->isotopes == NULL) malloc_error(); + inverse_ptr->isotopes[inverse_ptr->count_isotopes].isotope_number = isotope_number; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].elt_name = element_name; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties == NULL) malloc_error(); + inverse_ptr->count_isotopes++; + } +/* + * add redox state name to inv_ptr->i_u + */ + inverse_ptr->i_u = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->i_u, (size_t) (inverse_ptr->count_i_u + 1) * sizeof( struct inv_isotope)); + if (inverse_ptr->i_u == NULL) malloc_error(); + inverse_ptr->i_u[inverse_ptr->count_i_u].elt_name = redox_name; + inverse_ptr->i_u[inverse_ptr->count_i_u].isotope_number = isotope_number; +/* + * Read isotope uncertainties + */ + inverse_ptr->i_u[inverse_ptr->count_i_u].uncertainties = read_list_doubles(&ptr1, &count); + inverse_ptr->i_u[inverse_ptr->count_i_u].count_uncertainties = count; + inverse_ptr->count_i_u++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_inv_phases (struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + int count_isotopes; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr1; + struct isotope *isotopes; +/* + * Read phase name + */ + j = copy_token(token, &ptr, &l); + if (j == EMPTY) return(OK); + inverse_ptr->phases = (struct inv_phases *) PHRQ_realloc(inverse_ptr->phases, (size_t) (inverse_ptr->count_phases + 1) * sizeof( struct inv_phases)); + if (inverse_ptr->phases == NULL) malloc_error(); + inverse_ptr->phases[inverse_ptr->count_phases].name = string_hsave(token); +/* + * Read constraint, force, and isotopes + */ + inverse_ptr->phases[inverse_ptr->count_phases].constraint = EITHER; + inverse_ptr->phases[inverse_ptr->count_phases].force = FALSE; + count_isotopes = 0; + isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); + if (isotopes == NULL) malloc_error(); + + for (;;) { + j = copy_token(token, &ptr, &l); + if (j == EMPTY) break; + strcpy(token1, token); + str_tolower(token1); + if (token1[0] == 'p' ) { + inverse_ptr->phases[inverse_ptr->count_phases].constraint = PRECIPITATE; + } else if (token1[0] == 'd' ) { + inverse_ptr->phases[inverse_ptr->count_phases].constraint = DISSOLVE; + } else if (token[0] == 'f' ) { + inverse_ptr->phases[inverse_ptr->count_phases].force = TRUE; + } else if (j == DIGIT) { +/* + * read isotope data + */ + isotopes = (struct isotope *) PHRQ_realloc( isotopes , (size_t) (count_isotopes + 1) * sizeof (struct isotope)); + if (isotopes == NULL) malloc_error(); + ptr1 = token; + + /* isotope number */ + get_num(&ptr1, &(isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { + sprintf(error_string, "Expecting element name: %s.", ptr1); + error_msg(error_string, CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + + /* element name */ + isotopes[count_isotopes].elt_name = string_hsave(ptr1); + + /* ratio */ + j = copy_token(token, &ptr, &l); + if (j != DIGIT ) { + error_msg("Expecting isotope ratio for phase.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio)); + + /* read and store isotope ratio uncertainty */ + if (copy_token(token, &ptr, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio_uncertainty)); + + count_isotopes++; + } else { + sprintf(error_string, "Unknown option for inverse modeling phase."); + warning_msg(error_string); + } + } + if (count_isotopes > 0) { + inverse_ptr->phases[inverse_ptr->count_phases].isotopes = isotopes; + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = count_isotopes; + } else { + inverse_ptr->phases[inverse_ptr->count_phases].isotopes = NULL; + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = 0; + isotopes = (struct isotope *) free_check_null(isotopes); + } + inverse_ptr->count_phases++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_kinetics (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads kinetics data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read kinetics + */ + int i, j, k, l, count_comps, count_steps, count_list; + char *ptr; + char *description; + char token[MAX_LENGTH]; + int n; + int n_user, n_user_end; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + LDBLE step, coef; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "tol", /* 0 */ + "m", /* 1 */ + "m0", /* 2 */ + "parms", /* 3 */ + "formula", /* 4 */ + "steps", /* 5 */ + "step_divide", /* 6 */ + "parameters", /* 7 */ + "runge-kutta", /* 8 */ + "runge_kutta", /* 9 */ + "rk", /* 10 */ + "bad_step_max", /* 11 */ + "cvode" /* 12 */ + }; + int count_opt_list = 13; + +/* + * Read kinetics number + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + +/* + * Find space for kinetics data + */ + kinetics_ptr = kinetics_search(n_user, &n, FALSE); + if (kinetics_ptr != NULL) { + kinetics_free(kinetics_ptr); + } else { + space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); + n = count_kinetics++; + } +/* + * Set use data to first read + */ + if (use.kinetics_in == FALSE) { + use.kinetics_in = TRUE; + use.n_kinetics_user = n_user; + } +/* + * Initialize + */ + kinetics_init(&(kinetics[n]), n_user, n_user_end, description); + free_check_null(description); + kinetics_ptr = &kinetics[n]; + + count_steps = 0; +/* + * Read kinetics data + */ + return_value = UNKNOWN; + kinetics_comp_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: /* allocate space, read new name */ + count_comps = kinetics_ptr->count_comps++; + kinetics_ptr->comps = (struct kinetics_comp *) PHRQ_realloc(kinetics_ptr->comps, (size_t) (count_comps + 1) * sizeof(struct kinetics_comp)); + if (kinetics_ptr->comps == NULL) malloc_error(); + kinetics_ptr->comps[count_comps].moles = 0; + ptr = line; + copy_token (token, &ptr, &l); + kinetics_ptr->comps[count_comps].rate_name = string_hsave(token); +#ifdef SKIP + kinetics_ptr->comps[count_comps].formula = kinetics_ptr->comps[count_comps].rate_name; +#endif + kinetics_ptr->comps[count_comps].tol = 1e-8; + kinetics_ptr->comps[count_comps].m0 = -1.0; + kinetics_ptr->comps[count_comps].m = -1.0; + kinetics_ptr->comps[count_comps].count_c_params = 0; + + kinetics_comp_ptr = &kinetics_ptr->comps[count_comps]; + kinetics_comp_ptr->d_params = (double *) PHRQ_malloc(sizeof(LDBLE)); + if (kinetics_comp_ptr->d_params == NULL) malloc_error(); + kinetics_comp_ptr->count_d_params = 0; + + kinetics_comp_ptr->c_params = (char **) PHRQ_malloc(sizeof(char *)); + if (kinetics_comp_ptr->c_params == NULL) malloc_error(); + kinetics_comp_ptr->count_c_params = 0; + + kinetics_comp_ptr->count_list = 0; + kinetics_comp_ptr->list = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (kinetics_comp_ptr->list == NULL) malloc_error(); + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in KINETICS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* tolerance */ + if (kinetics_comp_ptr == NULL) { + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } else { + if (copy_token (token, &next_char, &l) == DIGIT) { + kinetics_comp_ptr->tol = strtod(token, &ptr); + } else { + sprintf(error_string, "Expecting numerical value for tolerance."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 1: /* m */ + if (kinetics_comp_ptr == NULL) { + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } else { + if (copy_token (token, &next_char, &l) == DIGIT) { + kinetics_comp_ptr->m = strtod(token, &ptr); + } else { + sprintf(error_string, "Expecting numerical value for moles of reactant."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 2: /* m0 */ + if (kinetics_comp_ptr == NULL) { + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } else { + if (copy_token (token, &next_char, &l) == DIGIT) { + kinetics_comp_ptr->m0 = strtod(token, &ptr); + } else { + sprintf(error_string, "Expecting numerical value for initial moles of reactant."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 3: /* parms */ + case 7: /* parameters */ + if (kinetics_comp_ptr == NULL) { + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } else { + while ((j = copy_token (token, &next_char, &l)) != EMPTY) { + /* + * Store a LDBLE parameter + */ + if (j == DIGIT) { + kinetics_comp_ptr->d_params = (double *) PHRQ_realloc(kinetics_comp_ptr->d_params, (size_t) (kinetics_comp_ptr->count_d_params + 1) * sizeof(LDBLE)); + if (kinetics_comp_ptr->d_params == NULL) malloc_error(); + kinetics_comp_ptr->d_params[kinetics_comp_ptr->count_d_params] = strtod(token, &ptr); + kinetics_comp_ptr->count_d_params++; + } else { + /* + * Store a character parameter + */ + kinetics_comp_ptr->c_params = (char **) PHRQ_realloc(kinetics_comp_ptr->c_params, (size_t) (kinetics_comp_ptr->count_c_params + 1) * sizeof(char *)); + if (kinetics_comp_ptr->c_params == NULL) malloc_error(); + kinetics_comp_ptr->c_params[kinetics_comp_ptr->count_c_params] = string_hsave(token); + kinetics_comp_ptr->count_c_params++; + } + } + } + break; + case 4: /* formula */ + if (kinetics_comp_ptr == NULL) { + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } else { + /* + * Store reactant name, default coefficient + */ + ptr = next_char; + while (copy_token (token, &ptr, &l) != EMPTY) { + if ( isalpha((int) token[0]) || (token[0] == '(' ) || (token[0] == '[' )) { + count_list = kinetics_comp_ptr->count_list++; + kinetics_comp_ptr->list = (struct name_coef *) PHRQ_realloc(kinetics_comp_ptr->list, + (size_t) (count_list + 1) * sizeof(struct name_coef)); + if (kinetics_comp_ptr->list == NULL) malloc_error(); + kinetics_comp_ptr->list[count_list].name = string_hsave(token); + kinetics_comp_ptr->list[count_list].coef = 1.0; + } else { + /* + * Store relative coefficient + */ + j = sscanf(token, SCANFORMAT, &coef); + if (j == 1 ) { + count_list = kinetics_comp_ptr->count_list - 1; + kinetics_comp_ptr->list[count_list].coef = coef; + } else { + error_msg("Reading relative coefficient of reactant.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + } + } + break; + case 5: /* steps */ + /* + * Read one or more kinetics time increments + */ + while ( (j = copy_token (token, &next_char, &l)) == DIGIT ) { + /* Read next step increment(s) */ +/* multiple, equal timesteps 15 aug. 2005 */ + if (replace("*"," ",token) == TRUE) { + if (sscanf(token,"%d" SCANFORMAT, &k, &step) == 2) { + for (i = 0; i < k; i++) { + count_steps++; + kinetics_ptr->steps = (double *) PHRQ_realloc(kinetics_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) malloc_error(); + kinetics_ptr->steps[kinetics_ptr->count_steps] = step; + kinetics_ptr->count_steps = count_steps; + } + } else { + input_error++; + error_msg("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", CONTINUE); + } + } else { + step = strtod(token, &ptr); + count_steps++; + kinetics_ptr->steps = (double *) PHRQ_realloc(kinetics_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) malloc_error(); + kinetics_ptr->steps[kinetics_ptr->count_steps] = step; + kinetics_ptr->count_steps = count_steps; + } + } + if (j == EMPTY) break; + /* + * Read number of increments + */ + if (kinetics_ptr->count_steps != 1) { + error_msg("To define equal time increments, only one total time should be defined.", CONTINUE); + input_error++; + break; + } + do { + j = sscanf(token, "%d", &i); + if (j == 1 && i > 0 ) { + kinetics_ptr->count_steps = -i; + break; + } else if (j == 1 && i <= 0 ) { + error_msg("Expecting positive number for number of equal " + "time increments for kinetics.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } while ( copy_token (token, &next_char, &l) != EMPTY ); + break; + case 6: /* step_divide */ + if (copy_token (token, &next_char, &l) == DIGIT) { + sscanf(token, SCANFORMAT, &kinetics_ptr->step_divide); + } else { + sprintf(error_string, "Expecting numerical value for step_divide."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 8: /* runge-kutta */ + case 9: /* runge_kutta */ + case 10: /* rk */ + j = copy_token (token, &next_char, &l); + if ( j == DIGIT) { + kinetics_ptr->rk = (int)strtod(token, &ptr); + } else if (j == EMPTY) { + } else { + sprintf(error_string, "Expecting order for Runge-Kutta method."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 11: /* bad_step_max */ + j = copy_token (token, &next_char, &l); + if ( j == DIGIT) { + kinetics_ptr->bad_step_max = (int)strtod(token, &ptr); + } else if (j == EMPTY) { + } else { + sprintf(error_string, "Expecting maximal bad steps number."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 12: /* cvode */ + kinetics[n].use_cvode = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + +/* + * Default reactant + */ + for (i = 0; i < kinetics[n].count_comps; i++) { + if (kinetics[n].comps[i].count_list == 0) { + kinetics[n].comps[i].list[0].name = kinetics_ptr->comps[i].rate_name; + kinetics[n].comps[i].list[0].coef = 1; + kinetics[n].comps[i].count_list = 1; + } + } +/* + * Default 1 sec + */ + if (kinetics[n].count_steps == 0) { + kinetics[n].count_steps = 1; + kinetics[n].steps[0] = 1.0; + } +/* + * set defaults for moles + */ + for (i = 0; i < kinetics[n].count_comps; i++) { + if (kinetics[n].comps[i].m0 < 0) { + if (kinetics[n].comps[i].m < 0) { + kinetics[n].comps[i].m0 = 1; + } else { + kinetics[n].comps[i].m0 = kinetics[n].comps[i].m; + } + } + if (kinetics[n].comps[i].m < 0) { + kinetics[n].comps[i].m = kinetics[n].comps[i].m0; + } + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +LDBLE *read_list_doubles(char **ptr, int *count_doubles ) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of LDBLE numbers until end of line is reached or + * a LDBLE can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-LDBLE token or end of line + * + * count_doubles exit: number of LDBLEs read + * + * Returns: + * pointer to a list of count_doubles LDBLEs. + */ + + LDBLE *LDBLE_list; + char token[MAX_LENGTH]; + LDBLE value; + char *ptr_save; + int l; + + LDBLE_list = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (LDBLE_list == NULL) malloc_error(); + *count_doubles = 0; + + ptr_save = *ptr; + while ( copy_token(token, ptr, &l) != EMPTY) { + if (sscanf(token,SCANFORMAT, &value) == 1) { + *count_doubles = *count_doubles + 1; + LDBLE_list = (LDBLE *) PHRQ_realloc(LDBLE_list, (size_t) (*count_doubles) * sizeof (LDBLE)); + if (LDBLE_list == NULL) malloc_error(); + LDBLE_list[ (*count_doubles) - 1] = value; + ptr_save = *ptr; + } else { + *ptr = ptr_save; + break; + } + } + return(LDBLE_list); +} +/* ---------------------------------------------------------------------- */ +int *read_list_ints (char **ptr, int *count_ints, int positive ) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of int numbers until end of line is reached or + * an int can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints exit: number of LDBLEs read + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints. + */ + int *int_list; + char token[MAX_LENGTH]; + int value; + int l; + char *ptr_save; + + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) malloc_error(); + *count_ints = 0; + + ptr_save = *ptr; + while ( copy_token(token, ptr, &l) != EMPTY) { + if (sscanf(token,"%d", &value) == 1) { + (*count_ints)++; + int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); + if (int_list == NULL) malloc_error(); + int_list[(*count_ints) - 1] = value; + if (value <= 0 && positive == TRUE) { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + ptr_save = *ptr; + } else { + *ptr = ptr_save; + break; + } + } + return(int_list); +} +/* ---------------------------------------------------------------------- */ +int *read_list_ints_range (char **ptr, int *count_ints, int positive, int *int_list ) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of int numbers until end of line is reached or + * an int can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints entry: number of ints already in list + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints + */ + char token[MAX_LENGTH]; + int value, value1, value2; + int i, l; + char *ptr_save; + + if (int_list == NULL) { + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) malloc_error(); + *count_ints = 0; + } + ptr_save = *ptr; + while ( copy_token(token, ptr, &l) != EMPTY) { + if (sscanf(token,"%d", &value) == 1) { + /* Read an integer */ + (*count_ints)++; + int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); + if (int_list == NULL) malloc_error(); + int_list[(*count_ints) - 1] = value; + if (value <= 0 && positive == TRUE) { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + /* Read range of integers */ + if (replace("-"," ",token) == TRUE) { + if (sscanf(token, "%d %d", &value1, &value2) != 2) { + error_msg("Expected an integer range n-m.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } else if (value2 < value1) { + error_msg("Expected an integer range n-m, with n <= m.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } else if (value2 <= 0 && positive == TRUE) { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } else { + for (i = value1 + 1; i <= value2; i++) { + (*count_ints)++; + int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); + if (int_list == NULL) malloc_error(); + int_list[(*count_ints) - 1] = i; + } + } + } + ptr_save = *ptr; + } else { + *ptr = ptr_save; + break; + } + } + return(int_list); +} +/* ---------------------------------------------------------------------- */ +int *read_list_t_f (char **ptr, int *count_ints ) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of true and false until end of line is reached or + * until non- t or f is found + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints exit: number of LDBLEs read + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints. + */ + int *int_list; + char token[MAX_LENGTH]; + int value; + int l; + + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) malloc_error(); + *count_ints = 0; + + while ( copy_token(token, ptr, &l) != EMPTY) { + str_tolower(token); + if (token[0] == 't') { + value = TRUE; + } else if (token[0] == 'f') { + value = FALSE; + } else { + error_msg("Expected TRUE or FALSE.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + (*count_ints)++; + int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); + if (int_list == NULL) malloc_error(); + int_list[(*count_ints) - 1] = value; + } + return(int_list); +} +/* ---------------------------------------------------------------------- */ +int read_log_k_only (char *ptr, LDBLE *log_k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read log k + */ + *log_k = 0.0; + replace("="," ",ptr); + if (sscanf(ptr,SCANFORMAT, log_k) < 1) { + input_error++; + error_msg("Expecting log k.", CONTINUE); + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_delta_h_only (char *ptr, LDBLE *delta_h, DELTA_H_UNIT *units) +/* ---------------------------------------------------------------------- */ +{ + int j, l, kilo, joul; + char token[MAX_LENGTH]; +/* + * Read delta H + */ + *delta_h = 0.0; + replace("="," ",ptr); + j = copy_token(token, &ptr, &l); + if (j == EMPTY) { + input_error++; + error_msg("Expecting numeric value for delta H.", CONTINUE); + return(ERROR); + } + if (sscanf(token,SCANFORMAT, delta_h) < 1) { + input_error++; + error_msg("Expecting numeric value for delta H.", CONTINUE); + return(ERROR); + } +/* + * Read delta H units + */ + j = copy_token(token, &ptr, &l); + *units = kjoules; + kilo = TRUE; + joul = TRUE; + if (j == EMPTY) { + return(OK); + } if (j == UPPER || j == LOWER) { + str_tolower(token); + if(strstr(token,"k") != token) { + /* convert to kilo */ + kilo = FALSE; + *delta_h /= 1000.; + } + if(strstr(token,"c") != NULL) { + /* convert to joules */ + *delta_h *= JOULES_PER_CALORIE; + joul = FALSE; + } + } + if (kilo == TRUE && joul == TRUE) { + *units = kjoules; + } else if (kilo == FALSE && joul == TRUE) { + *units = joules; + } else if (kilo == TRUE && joul == FALSE) { + *units = kcal; + } else if (kilo == FALSE && joul == FALSE) { + *units = cal; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_analytical_expression_only (char *ptr, LDBLE *log_k) +/* ---------------------------------------------------------------------- */ +{ + int j; +/* + * Read analytical expression + */ + for (j = 0; j < 5; j++) { + log_k[j] = 0.0; + } + j=sscanf(ptr,SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &(log_k[0]), &(log_k[1]), &(log_k[2]), &(log_k[3]), + &(log_k[4])); + if (j < 1) { + input_error++; + error_msg("Expecting numeric values for analytical expression.", CONTINUE); + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_incremental_reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Define flow only + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int j, l; + char *ptr; + char token[MAX_LENGTH]; + + ptr = line; + /* read keyword */ + copy_token(token, &ptr, &l); + + /* read true or false */ + incremental_reactions = get_true_false(ptr, TRUE); +/* + * find next keyword + */ + while ( (j = check_line("Subroutine Read", FALSE, TRUE, TRUE, FALSE)) != KEYWORD) { + /* empty, eof, keyword, print */ + if ( j == EOF) return(EOF); + sprintf(error_string,"Unknown input: %s", line); + error_msg(error_string, CONTINUE); + input_error++; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_master_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species data from data file or input file + */ + int j, i, l; + char *ptr, *ptr1; + LDBLE z; + struct element *elts_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + elts_ptr = NULL; + for (;;) { + j=check_line ("Master species", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD ) { + break; + } +/* + * Get element name with valence, allocate space, store + */ + ptr=line; +/* + * Get element name and save pointer to character string + */ + if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { + parse_error++; + error_msg ("Reading element for master species.", CONTINUE); + error_msg (line_save, CONTINUE); + continue; + } + /* + if (token[0] == '[') { + ptr1 = token; + get_elt(&ptr, element, &l); + strcpy(token, element); + } + */ + replace ("(+", "(", token); +/* + * Delete master if it exists + */ + master_delete(token); +/* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master >= max_master) { + space ((void **) ((void *) &master), count_master+1, &max_master, sizeof(struct master *)); + } + master[count_master] = master_alloc(); +/* + * Set type to AQ + */ + master[count_master]->type = AQ; +/* + * Save element name + */ + master[count_master]->elt = element_store ( token ); +/* + * Save pointer to species data for master species + */ + if ( ( copy_token(token, &ptr, &l) != UPPER ) && + token[0] != '[' && + ( strcmp_nocase_arg1(token, "e-") != 0 ) ) { + parse_error++; + error_msg("Reading master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + + s_ptr=s_search (token); + if (s_ptr != NULL) { + master[count_master]->s = s_ptr; + } else { + ptr1=token; + get_token(&ptr1, token1, &z, &l); + master[count_master]->s = s_store(token1, z, FALSE); + } + +/* + * Read alkalinity for species + */ + copy_token(token, &ptr, &l); + i = sscanf(token,SCANFORMAT, &master[count_master]->alk); + if (i != 1) { + input_error++; + if (elts_ptr != NULL) { + sprintf(error_string, "Expected alkalinity for master species, %s, in master species input.", elts_ptr->name); + } else { + sprintf(error_string, "Expected alkalinity for master species in master species input."); + } + error_msg(error_string, CONTINUE); + continue; + } +/* + * Read default gfw for species + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) { + sscanf(token,SCANFORMAT, &master[count_master]->gfw); + } else if (i == UPPER) { + master[count_master]->gfw_formula = string_hsave(token); + } else { + input_error++; + if (elts_ptr != NULL) { + sprintf(error_string, "Expected gram formula weight for master species, %s, in master species input.", elts_ptr->name); + } else { + sprintf(error_string, "Expected gram formula weight for master species in master species input."); + } + error_msg(error_string, CONTINUE); + continue; + } +/* + * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES + */ + if ( strchr(master[count_master]->elt->name,'(') == NULL ) { + master[count_master]->primary=TRUE; + /* Read gram formula weight for primary */ + if ( strcmp(master[count_master]->elt->name,"E") != 0 ) { + elts_ptr = master[count_master]->elt; + i = copy_token(token, &ptr, &l); + if (i == DIGIT) { + sscanf(token,SCANFORMAT, &elts_ptr->gfw); + } else { + input_error++; + if (elts_ptr != NULL) { + sprintf(error_string,"Expected gram formula weight for element, %s.", elts_ptr->name); + } else { + sprintf(error_string,"Expected gram formula weight for element."); + } + + error_msg(error_string, CONTINUE); + continue; + } + } + } else { + master[count_master]->primary=FALSE; + } + count_master++; + if (count_master >= max_master) { + space ((void **) ((void *) &master), count_master, &max_master, + sizeof(struct master *)); + } + + } + return (j); +} +/* ---------------------------------------------------------------------- */ +int read_mix (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads mixing fractions + */ + int n, n_user, n_user_end; + int return_value; + int count_comps; + int n_solution; + LDBLE fraction; + int j, i, l; + char *ptr; + char token[MAX_LENGTH]; + char *description; + struct mix *mix_ptr; +/* + * Read mix number + */ + ptr = line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Update list of mixtures + */ + mix_ptr = mix_search(n_user, &n, FALSE); + if (mix_ptr != NULL) { + mix_free (&mix[n]); + } else { + n = count_mix++; + mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix)); + if (mix == NULL) malloc_error(); + } +/* + * Set use data to first read + */ + if (use.mix_in == FALSE) { + use.mix_in = TRUE; + use.n_mix_user = n_user; + } +/* + * Defaults + */ + mix[n].description = description; + mix[n].n_user = n_user; + mix[n].n_user_end = n_user_end; + mix[n].comps = NULL; + count_comps = 0; +/* + * Read mixture data + */ + for (;;) { + return_value = check_line("Mixture data",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) { + break; + } + ptr=line; +/* + * Read n_user + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) { + sscanf(token,"%d ", &n_solution); + } else { + input_error++; + error_msg("Expected a solution number in mix input.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Read fraction for solution + */ + copy_token(token, &ptr, &l); + j = sscanf(token, SCANFORMAT, &fraction); + if (j != 1 ) { + input_error++; + error_msg("Expected a mixing fraction.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Malloc space + */ + count_comps++; + if (mix[n].comps == NULL) { + mix[n].comps = (struct mix_comp *) PHRQ_malloc( (size_t) sizeof (struct mix_comp)); + } else { + mix[n].comps = (struct mix_comp *) PHRQ_realloc(mix[n].comps, + (size_t) count_comps * sizeof (struct mix_comp)); + } + if (mix[n].comps == NULL) malloc_error(); +/* + * Save data + */ + mix[n].comps[count_comps - 1].n_solution = n_solution; + mix[n].comps[count_comps - 1].fraction = fraction; + } + if (count_comps <= 0) { + input_error++; + error_msg("Must define at least one solution number and mixing fraction for MIX input.", CONTINUE); + } + mix[n].count_comps = count_comps; + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_number_description (char *ptr, int *n_user, + int *n_user_end, char **description) +/* ---------------------------------------------------------------------- */ +{ + int l, n; + char token[MAX_LENGTH]; + char *ptr1; +/* + * Read user number + */ + copy_token(token, &ptr, &l); + ptr1 = ptr; + if (copy_token (token, &ptr, &l) != DIGIT) { +/* + sprintf(error_string, "No number given with %s keyword, " + "%s 1 assumed.", str, str); + warning_msg(error_string); + */ + *n_user=1; + *n_user_end = 1; + } else if (strstr(token,"-") != NULL) { + replace("-"," ",token); + n = sscanf(token,"%d%d", n_user, n_user_end); + if (n != 2) { + if (next_keyword >= 0) { + sprintf(error_string, "Reading number range for %s.", + keyword[next_keyword].name); + } else { + sprintf(error_string, "Reading number range for keyword."); + } + error_msg(error_string, CONTINUE); + input_error++; + } + ptr1 = ptr; + } else { + sscanf(token,"%d", n_user); + *n_user_end = *n_user; + ptr1 = ptr; + } +/* + * Read description + */ + for ( ; isspace((int) ptr1[0]) ;ptr1++ ); + *description = string_duplicate ( ptr1 ); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_phases (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for phases, parse equations + */ + int j, i, l; + int association; + char *ptr; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "log_k", /* 2 */ + "logk", /* 3 */ + "delta_h", /* 4 */ + "deltah", /* 5 */ + "analytical_expression", /* 6 */ + "a_e", /* 7 */ + "ae", /* 8 */ + "add_logk", /* 9 */ + "add_log_k", /* 10 */ + "add_constant" /* 11 */ + }; + int count_opt_list = 12; + + association=FALSE; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + phase_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in PHASES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (phase_ptr == NULL) break; + phase_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (phase_ptr == NULL) break; + phase_ptr->check_equation = TRUE; + break; + case 2: /* log_k */ + case 3: /* logk */ + if (phase_ptr == NULL) break; + read_log_k_only(next_char, &phase_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 4: /* delta_h */ + case 5: /* deltah */ + if (phase_ptr == NULL) break; + read_delta_h_only(next_char, &phase_ptr->logk[1], &phase_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 6: /* analytical_expression */ + case 7: /* a_e */ + case 8: /* ae */ + if (phase_ptr == NULL) break; + read_analytical_expression_only(next_char, &(phase_ptr->logk[2])); + opt_save = OPTION_DEFAULT; + break; + case 9: /* add_logk */ + case 10: /* add_log_k */ + if (phase_ptr == NULL) break; + if (phase_ptr->count_add_logk == 0) { + phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (phase_ptr->add_logk == NULL) malloc_error(); + } else { + phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, (size_t) ((phase_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (phase_ptr->add_logk == NULL) malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) { + input_error++; + sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + phase_ptr->add_logk[phase_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char,SCANFORMAT, &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); + if (i <= 0) { + phase_ptr->add_logk[phase_ptr->count_add_logk].coef = 1; + } + phase_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 11: /* add_constant */ + if (phase_ptr == NULL) break; + if (phase_ptr->count_add_logk == 0) { + phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (phase_ptr->add_logk == NULL) malloc_error(); + } else { + phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, (size_t) ((phase_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (phase_ptr->add_logk == NULL) malloc_error(); + } + i = sscanf(next_char,SCANFORMAT, &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); + if (i <= 0) { + input_error++; + sprintf(error_string, "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + phase_ptr->add_logk[phase_ptr->count_add_logk].name = string_hsave("XconstantX"); + /* read coef */ + phase_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get element name and save pointer to character string + */ + phase_ptr = NULL; + ptr=line; + copy_token(token, &ptr, &l); +/* + * Get and parse equation + */ + j=check_line ("Phase equation", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD ) { + return_value = j; + break; + } + if ( parse_eq(line, &next_elt, association ) == ERROR) { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } + phase_ptr = phase_store (token); +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + phase_ptr->formula = string_hsave(trxn.token[0].name ); + for (i=1; inext_elt=next_elt; +/* + * Malloc space for phase reaction + */ + phase_ptr->rxn = rxn_alloc (count_trxn+1); +/* + * Copy reaction to reaction for phase, first token (token[0]) is not used + * except to check that coef of phase formula = 1.0 + */ + token_ptr=phase_ptr->rxn->token; + /* token_ptr[0].coef=0; */ + token_ptr[0].coef=trxn.token[0].coef; + token_ptr[0].s=trxn.token[1].s; + for (i=1; itype = SOLID; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads pure phase data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int j, n, l, return_value; + int count_pure_phases; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + + ptr=line; +/* + * Read pp_assemblage number + */ + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Find pp_assemblage or realloc space for pp_assemblage + */ + + if (pp_assemblage_search(n_user, &n) != NULL) { + pp_assemblage_free (&pp_assemblage[n]); + } else { + n=count_pp_assemblage++; + space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); + } +/* + * Set use data to first read + */ + if (use.pp_assemblage_in == FALSE) { + use.pp_assemblage_in = TRUE; + use.n_pp_assemblage_user = n_user; + } + + pp_assemblage_init(&(pp_assemblage[n]), n_user, n_user_end, description); + free_check_null(description); +/* + * Read phases + */ + count_pure_phases = 0; + for (;;) { + return_value = check_line("Pure phase data",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) { + break; + } +/* + * Make space, set default + */ + count_pure_phases++; + pp_assemblage[n].pure_phases = (struct pure_phase *) PHRQ_realloc(pp_assemblage[n].pure_phases, (size_t) (count_pure_phases) * sizeof(struct pure_phase)); + if (pp_assemblage[n].pure_phases == NULL) malloc_error(); + pp_assemblage[n].pure_phases[count_pure_phases-1].si = 0.0; + pp_assemblage[n].pure_phases[count_pure_phases-1].add_formula = NULL; + pp_assemblage[n].pure_phases[count_pure_phases-1].moles = 10.0; + pp_assemblage[n].pure_phases[count_pure_phases-1].dissolve_only = FALSE; + pp_assemblage[n].pure_phases[count_pure_phases-1].delta = 0.0; +/* + * Read name + */ + ptr = line; + copy_token(token, &ptr, &l); + pp_assemblage[n].pure_phases[count_pure_phases-1].name = string_hsave(token); + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; +/* + * Read saturation index + */ + j=sscanf(token,SCANFORMAT, &dummy); + pp_assemblage[n].pure_phases[count_pure_phases-1].si = (LDBLE) dummy; + if (j != 1 ) { + error_msg("Expected saturation index.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } +/* + * Adding a reaction to the phase boundary + */ + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; + if ( j == UPPER || j == LOWER) { + pp_assemblage[n].pure_phases[count_pure_phases-1].add_formula = string_hsave(token); + j = copy_token(token, &ptr, &l); + } +/* + * Read amount + */ + if ( j == EMPTY) continue; + j=sscanf(token,SCANFORMAT, &dummy); + pp_assemblage[n].pure_phases[count_pure_phases-1].moles = (LDBLE) dummy; + if (j != 1 ) { + error_msg("Expected amount of mineral.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; + str_tolower(token); + if (strstr(token,"d") == token) { + pp_assemblage[n].pure_phases[count_pure_phases-1].dissolve_only = TRUE; + } else { + error_msg("Unexpected data at end of equilibrium-phase definition.", CONTINUE); + input_error++; + continue; + } + } + pp_assemblage[n].count_comps = count_pure_phases; +/* + * Sort phases by name (lowercase) + */ + qsort (pp_assemblage[n].pure_phases, + (size_t) count_pure_phases, + (size_t) sizeof(struct pure_phase), + pure_phase_compare); + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_reaction (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads reaction data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read reaction + */ + int l; + char *ptr; + char *description; + char token[MAX_LENGTH]; + int n, return_value; + int n_user, n_user_end; + struct irrev *irrev_ptr; +/* + * Read reaction number + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + +/* + * Read reaction or realloc space for irrev reaction + */ + irrev_ptr = irrev_search(n_user, &n); + if (irrev_ptr != NULL) { + irrev_free(&irrev[n]); + } else { + n = count_irrev++; + irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev)); + if (irrev == NULL) malloc_error(); + } +/* + * Set use data to first read + */ + if (use.irrev_in == FALSE) { + use.irrev_in = TRUE; + use.n_irrev_user = n_user; + } +/* + * Defaults + */ + irrev[n].n_user = n_user; + irrev[n].n_user_end = n_user_end; + irrev[n].description = description; + irrev[n].steps = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (irrev[n].steps == NULL) malloc_error(); + irrev[n].list = (struct name_coef *) PHRQ_malloc((size_t) sizeof(struct name_coef)); + if (irrev[n].list == NULL) malloc_error(); + irrev[n].count_steps = 0; + irrev[n].count_list = 0; + irrev[n].units = string_hsave("Mol"); + irrev[n].elts = NULL; +/* + * Read reaction data + */ + for (;;) { +/* + * Read line + */ + return_value = check_line("Pure phase data",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) { + break; + } + ptr = line; + copy_token(token, &ptr, &l); + if (isalpha((int) token[0]) || (token[0] == '(') || (token[0] == '[') ) { +/* + * Read reactant information + */ + read_reaction_reactants(&(irrev[n])); + } else { +/* + * Read steps information + */ + read_reaction_steps(&(irrev[n])); + } + } +/* + * Default 1 mol of reaction + */ + if (irrev[n].count_steps == 0) { + irrev[n].count_steps = 1; + irrev[n].steps[0] = 1.0; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_reaction_reactants(struct irrev *irrev_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read reactants, may be a chemical formula or a pure_phase name + * followed by relative reaction coefficient, default 1.0. + * + */ + int j, l; + int count_list; + char token[MAX_LENGTH]; + LDBLE coef; + char *ptr; +/* + * Read one or more reactants + */ + ptr = line; + while (copy_token (token, &ptr, &l) != EMPTY) { +/* + * Store reactant name, default coefficient + */ + if ( isalpha((int) token[0]) || (token[0] == '(' ) || (token[0] == '[') ) { + irrev_ptr->count_list++; + count_list = irrev_ptr->count_list - 1; + irrev_ptr->list = (struct name_coef *) PHRQ_realloc(irrev_ptr->list, (size_t) (count_list + 1) * sizeof(struct name_coef)); + if (irrev_ptr->list == NULL) malloc_error(); + irrev_ptr->list[count_list].name = string_hsave(token); + irrev_ptr->list[count_list].coef = 1.0; +/* + * Store relative coefficient + */ + } else { + j = sscanf(token, SCANFORMAT, &coef); + if (j == 1 ) { + count_list = irrev_ptr->count_list - 1; + irrev_ptr->list[count_list].coef = coef; + } else { + error_msg("Reading relative coefficient of reactant.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_reaction_steps(struct irrev *irrev_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read amount(s) of irrev reactions in one of three forms: + * + * 6 millimoles in 6 steps or + * + * 1 2 3 4 5 6 millimoles or + * + * 6*1 millimoles + * INCREMENTAL_REACTIONS + */ + int i, j, l, n; + int count_steps; + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + LDBLE step, value; + + ptr = line; + count_steps = irrev_ptr->count_steps; +/* + * Read one or more reaction increments + */ + for (;;) { + if ( copy_token (token, &ptr, &l) == EMPTY ) { + return(OK); + } +/* + * Read next step increment + */ +/* begin modif 29 july 2005... */ + if (replace("*"," ",token) == TRUE) { + if (sscanf(token,"%d" SCANFORMAT, &n, &value) == 2) { + for (i = 0; i < n; i++) { + count_steps++; + irrev_ptr->steps = (double *) PHRQ_realloc(irrev_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); + if (irrev_ptr->steps == NULL) malloc_error(); + irrev_ptr->steps[irrev_ptr->count_steps] = value; + irrev_ptr->count_steps = count_steps; + } + } else { + input_error++; + error_msg("Format error in multiple, equal REACTION steps.\nCorrect is (for example): 0.2 4*0.1 2*0.5 0.3\n", CONTINUE); + } + } else { + j = sscanf(token, SCANFORMAT, &step); + if (j == 1 ) { + count_steps++; + irrev_ptr->steps = (double *) PHRQ_realloc(irrev_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); + if (irrev_ptr->steps == NULL) malloc_error(); + irrev_ptr->steps[irrev_ptr->count_steps] = step; + irrev_ptr->count_steps = count_steps; + } else { + break; + } + } +/* ...end modif 29 july 2005 */ + } +/* + * Read units + */ + strcpy(token1, token); + strcat(token1,"/l"); + if (check_units(token1, FALSE, FALSE, NULL, FALSE) == OK) { + replace("/l", "", token1); + if (strstr(token1, "Mol") == NULL) { + sprintf(error_string, "Units of steps not in moles, %s.", token); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } else { + irrev_ptr->units = string_hsave(token1); + } + if ( copy_token (token, &ptr, &l) == EMPTY ) { + return(OK); + } + } +/* + * Read number of equal increments, store as negative integer + */ + if (count_steps != 1) { + error_msg("To define equal increments, only one reaction increment should be defined.", CONTINUE); + input_error++; + return(ERROR); + } + do { + j = sscanf(token, "%d", &i); + if (j == 1 && i > 0 ) { + irrev_ptr->count_steps = -i; + return(OK); + } else if (j == 1 && i <= 0 ) { + break; + } + } while ( copy_token (token, &ptr, &l) != EMPTY ); + + error_msg("Expecting positive number for number of equal " + "increments to add.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); +} +/* ---------------------------------------------------------------------- */ +int read_save (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, mix, irreversible reaction, and pure phases to use + * in reaction calculation + */ + int i, l, n, n_user, n_user_end; + char *ptr; + char token[MAX_LENGTH]; +/* + * Read "save" + */ + ptr = line; + copy_token (token, &ptr, &l); +/* + * Read keyword + */ + copy_token (token, &ptr, &l); + check_key (token); + switch (next_keyword) { + case -1: /* Have not read line with keyword */ + case 0: /* End encountered */ + case 1: /* EOF encountered */ + case 2: /* Read aqueous model */ + case 3: /* Read master species */ + case 5: /* Phases */ + case 7: /* Reaction */ + case 8: /* Mix */ + case 9: /* Use */ + case 10: /* Save */ + case 11: + case 12: + case 14: + case 15: + case 17: + case 18: + case 21: + case 22: + case 23: + case 24: + case 25: + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 38: + case 39: + input_error++; + error_msg("Expecting keyword solution, equilibrium_phases, exchange, surface, kinetics, gas_phase, or solid_solutions.", CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of save",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(ERROR); + } +/* + * Read number + */ + for (;;) { + i = copy_token (token, &ptr, &l); + if (i == DIGIT) { + replace("-"," ",token); + n = sscanf(token,"%d%d",&n_user, &n_user_end); + if (n == 1) { + n_user_end = n_user; + } + if (n_user < 0) { + error_msg("Number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + break; + } else if ( i == EMPTY ) { + sprintf(error_string, "No number given, 1 assumed."); + warning_msg(error_string); + n_user = 1; + n_user_end = 1; + break; + } } + switch (next_keyword) { + case 4: /* Solution */ + save.solution = TRUE; + save.n_solution_user = n_user; + save.n_solution_user_end = n_user_end; + break; + case 6: /* Pure phases */ + case 26: + case 27: + case 28: + case 29: + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = n_user; + save.n_pp_assemblage_user_end = n_user_end; + break; + case 13: /* exchange */ + save.exchange = TRUE; + save.n_exchange_user = n_user; + save.n_exchange_user_end = n_user_end; + break; + case 16: /* surface */ + save.surface = TRUE; + save.n_surface_user = n_user; + save.n_surface_user_end = n_user_end; + break; + case 19: /* gas_phase */ + save.gas_phase = TRUE; + save.n_gas_phase_user = n_user; + save.n_gas_phase_user_end = n_user_end; + break; + case 40: /* solid_solutions */ + case 41: /* solid_solution */ + save.s_s_assemblage = TRUE; + save.n_s_s_assemblage_user = n_user; + save.n_s_s_assemblage_user_end = n_user_end; + break; + } + check_line("End of save",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_selected_output (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for to output to flat file + */ + int value; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "file", /* 0 */ + "totals", /* 1 */ + "molalities", /* 2 */ + "activities", /* 3 */ + "pure_phases", /* 4 */ + "si", /* 5 */ + "saturation_indices", /* 6 */ + "gases", /* 7 */ + "equilibrium_phases", /* 8 */ + "equilibria", /* 9 */ + "equilibrium", /* 10 */ + "pure", /* 11 */ + "inverse", /* 12 */ + "kinetic_reactants", /* 13 */ + "kinetics", /* 14 */ + "solid_solutions", /* 15 */ + "inverse_modeling", /* 16 */ + "reset", /* 17 */ + "simulation", /* 18 */ + "sim", /* 19 */ + "state", /* 20 */ + "solution", /* 21 */ + "soln", /* 22 */ + "distance", /* 23 */ + "dist", /* 24 */ + "time", /* 25 */ + "step", /* 26 */ + "reaction", /* 27 */ + "rxn", /* 28 */ + "temperature", /* 29 */ + "temp", /* 30 */ + "ph", /* 31 */ + "pe", /* 32 */ + "alkalinity", /* 33 */ + "alk", /* 34 */ + "ionic_strength", /* 35 */ + "mu", /* 36 */ + "water", /* 37 */ + "high_precision", /* 38 */ + "user_punch", /* 39 */ + "mol", /* 40 */ + "kin", /* 41 */ + "charge_balance", /* 42 */ + "percent_error", /* 43 */ + "selected_out", /* 44 */ + "selected_output", /* 45 */ + "isotopes", /* 46 */ + "calculate_values" /* 47 */ + }; + int count_opt_list = 48; + + int i, l; + char file_name[MAX_LENGTH], token[MAX_LENGTH]; + static int have_punch_name = FALSE; + + punch.in = TRUE; + punch.new_def = TRUE; + punch.count_totals = 0; + punch.count_molalities = 0; + punch.count_activities = 0; + punch.count_pure_phases = 0; + punch.count_si = 0; + punch.count_gases = 0; + punch.count_kinetics = 0; + punch.count_s_s = 0; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + opt_save = opt; + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* file name */ + /* copy_token(file_name, &next_char, &l); */ + string_trim(next_char); + strcpy(file_name, next_char); + have_punch_name = TRUE; + if (output_open(OUTPUT_PUNCH, file_name) != OK) { + sprintf(error_string, "Can't open file, %s.", file_name); + input_error++; + error_msg(error_string, CONTINUE); + } + opt_save = OPTION_ERROR; + break; + case 1: /* totals */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + if (i != UPPER && token[0] != '[') { + sprintf(error_string, "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } else { + punch.count_totals++; + punch.totals = (struct name_master *) PHRQ_realloc(punch.totals, (size_t) punch.count_totals * sizeof(struct name_master)); + if (punch.totals == NULL) malloc_error(); + punch.totals[punch.count_totals - 1].name = string_hsave(token); + } + } + break; + case 2: /* molalities */ + case 40: /* mol */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) { + sprintf(error_string, "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } else { + punch.count_molalities++; + punch.molalities = (struct name_species *) PHRQ_realloc(punch.molalities, (size_t) punch.count_molalities * sizeof(struct name_species)); + if (punch.molalities == NULL) malloc_error(); + punch.molalities[punch.count_molalities - 1].name = + string_hsave(token); + } + } + break; + case 3: /* activities */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) { + sprintf(error_string, "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } else { + punch.count_activities++; + punch.activities = (struct name_species *) PHRQ_realloc(punch.activities, (size_t) punch.count_activities * sizeof(struct name_species)); + if (punch.activities == NULL) malloc_error(); + punch.activities[punch.count_activities - 1].name = + string_hsave(token); + } + } + break; + case 4: /* pure_phases */ + case 8: /* equilibrium_phases */ + case 9: /* equilibria */ + case 10: /* equilibrium */ + case 11: /* pure */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_pure_phases++; + punch.pure_phases = (struct name_phase *) PHRQ_realloc(punch.pure_phases, (size_t) punch.count_pure_phases * sizeof(struct name_phase)); + if (punch.pure_phases == NULL) malloc_error(); + punch.pure_phases[punch.count_pure_phases - 1].name = string_hsave(token); + } + break; + case 5: /* si */ + case 6: /* saturation_index */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_si++; + punch.si = (struct name_phase *) PHRQ_realloc(punch.si, (size_t) punch.count_si * sizeof(struct name_phase)); + if (punch.si == NULL) malloc_error(); + punch.si[punch.count_si - 1].name = string_hsave(token); + } + break; + case 7: /* gases */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_gases++; + punch.gases = (struct name_phase *) PHRQ_realloc(punch.gases, (size_t) punch.count_gases * sizeof(struct name_phase)); + if (punch.gases == NULL) malloc_error(); + punch.gases[punch.count_gases - 1].name = string_hsave(token); + } + break; + case 12: /* inverse */ + case 16: /* inverse_modeling */ + punch.inverse = get_true_false(next_char, TRUE); + break; + case 13: /* kinetic_reactants */ + case 14: /* kinetics */ + case 41: /* kin */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_kinetics++; + punch.kinetics = (struct name_phase *) PHRQ_realloc(punch.kinetics, (size_t) punch.count_kinetics * sizeof(struct name_phase)); + if (punch.kinetics == NULL) malloc_error(); + punch.kinetics[punch.count_kinetics - 1].name = string_hsave(token); + } + break; + case 15: /* solid_solutions */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_s_s++; + punch.s_s = (struct name_phase *) PHRQ_realloc(punch.s_s, (size_t) punch.count_s_s * sizeof(struct name_phase)); + if (punch.s_s == NULL) malloc_error(); + punch.s_s[punch.count_s_s - 1].name = string_hsave(token); + } + break; + case 46: /* isotopes */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + if (i != UPPER && token[0] != '[') { + sprintf(error_string, "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } else { + punch.count_isotopes++; + punch.isotopes = (struct name_master *) PHRQ_realloc(punch.isotopes, (size_t) punch.count_isotopes * sizeof(struct name_master)); + if (punch.isotopes == NULL) malloc_error(); + punch.isotopes[punch.count_isotopes - 1].name = string_hsave(token); + } + } + break; + case 47: /* calculate_values */ + while( (i = copy_token(token, &next_char, &l)) != EMPTY) { + punch.count_calculate_values++; + punch.calculate_values = (struct name_master *) PHRQ_realloc(punch.calculate_values, (size_t) punch.count_calculate_values * sizeof(struct name_master)); + if (punch.calculate_values == NULL) malloc_error(); + punch.calculate_values[punch.count_calculate_values - 1].name = string_hsave(token); + } + break; + case 17: /* reset */ + value = get_true_false(next_char, TRUE); + punch.sim = value; + punch.state = value; + punch.soln = value; + punch.dist = value; + punch.time = value; + punch.step = value; + punch.rxn = value; + punch.temp = value; + punch.ph = value; + punch.pe = value; + punch.alk = value; + punch.mu = value; + punch.water = value; + punch.charge_balance = value; + punch.percent_error = value; + break; + case 18: /* simulation */ + case 19: /* sim */ + punch.sim = get_true_false(next_char, TRUE); + break; + case 20: /* state */ + punch.state = get_true_false(next_char, TRUE); + break; + case 21: /* solution */ + case 22: /* soln */ + punch.soln = get_true_false(next_char, TRUE); + break; + case 23: /* distance */ + case 24: /* dist */ + punch.dist = get_true_false(next_char, TRUE); + break; + case 25: /* time */ + punch.time = get_true_false(next_char, TRUE); + break; + case 26: /* step */ + punch.step = get_true_false(next_char, TRUE); + break; + case 27: /* reaction */ + case 28: /* rxn */ + punch.rxn = get_true_false(next_char, TRUE); + break; + case 29: /* temperature */ + case 30: /* temp */ + punch.temp = get_true_false(next_char, TRUE); + break; + case 31: /* ph */ + punch.ph = get_true_false(next_char, TRUE); + break; + case 32: /* pe */ + punch.pe = get_true_false(next_char, TRUE); + break; + case 33: /* alkalinity */ + case 34: /* alk */ + punch.alk = get_true_false(next_char, TRUE); + break; + case 35: /* ionic strength */ + case 36: /* mu */ + punch.mu = get_true_false(next_char, TRUE); + break; + case 37: /* water */ + punch.water = get_true_false(next_char, TRUE); + break; + case 38: /* high_precision */ + punch.high_precision = get_true_false(next_char, TRUE); + if (punch.high_precision == TRUE && convergence_tolerance > 1e-12) { + convergence_tolerance = 1e-12; + } + break; + case 39: /* user_punch */ + punch.user_punch = get_true_false(next_char, TRUE); + break; + case 42: /* charge_balance */ + punch.charge_balance = get_true_false(next_char, TRUE); + break; + case 43: /* percent_error */ + punch.percent_error = get_true_false(next_char, TRUE); + break; + case 44: /* selected_out */ + case 45: /* selected_output */ + pr.punch = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + if (!have_punch_name) { + if (output_open(OUTPUT_PUNCH, "selected.out") != OK) { + sprintf(error_string, "Can't open file, %s.", "selected.out"); + input_error++; + error_msg(error_string, CONTINUE); + } + } + + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int n_user, n_user_end; + int default_pe, alk; + int count_isotopes; + int max_mass_balance, count_mass_balance; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water" /* 10 */ + + }; + int count_opt_list = 11; +/* + * Read solution number and description + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Malloc space for solution data + */ + if (solution_bsearch(n_user, &n, FALSE) != NULL) { + solution_free(solution[n]); + } else { + n=count_solution++; + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); + } + } + solution[n] = solution_alloc(); + + solution[n]->n_user = n_user; + solution[n]->n_user_end = n_user_end; + if (use.solution_in == FALSE) { + use.solution_in = TRUE; + use.n_solution_user = n_user; + } + max_mass_balance=MAX_MASS_BALANCE; +/* + * Set default ph, temp, density, pe, units + */ + solution[n]->description = description; + solution[n]->tc=25.0; + solution[n]->ph=7.0; + solution[n]->density=1.0; + solution[n]->solution_pe = 4.0; + solution[n]->mass_water=1.0; + solution[n]->ah2o = 1.0; + solution[n]->mu = 1e-7; + solution[n]->cb = 0.0; + default_pe = 0; + solution[n]->units = string_hsave( "mMol/kgw" ); + solution[n]->totals[0].description=NULL; + count_mass_balance=0; + count_isotopes = 0; +/* + * Read concentration data + */ + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + ptr = next_char; + if (copy_token(token, &ptr, &l) == DIGIT) { + opt = 9; + } + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* temperature */ + case 1: + if (sscanf(next_char,SCANFORMAT, &(solution[n]->tc)) != 1) { + solution[n]->tc = 25; + } + break; + case 2: /* density */ + case 3: + sscanf(next_char,SCANFORMAT, &(solution[n]->density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (check_units (token, FALSE, FALSE, solution[n]->units, TRUE) == OK) { + solution[n]->units = string_hsave(token); + } else { + input_error++; + } + break; + case 5: /* redox */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (parse_couple(token) == OK) { + default_pe = pe_data_store (&(solution[n]->pe), token); + } else { + input_error++; + } + break; + case 6: /* ph */ + if ( read_conc(n, count_mass_balance, line) == ERROR ) { + input_error++; + break; + } + solution[n]->ph = solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { + break; + } + solution[n]->totals[count_mass_balance].description = string_hsave("H(1)"); + count_mass_balance++; + break; + case 7: /* pe */ + if ( read_conc(n, count_mass_balance, line) == ERROR ) { + input_error++; + break; + } + solution[n]->solution_pe = solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { + break; + } + solution[n]->totals[count_mass_balance].description = string_hsave("E"); + count_mass_balance++; + break; + case 9: /* isotope */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + solution[n]->isotopes = (struct isotope *) PHRQ_realloc(solution[n]->isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); + if (solution[n]->isotopes == NULL) malloc_error(); + + /* read and save element name */ + ptr1 = token; + get_num(&ptr1, &(solution[n]->isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + solution[n]->isotopes[count_isotopes].elt_name = string_hsave(ptr1); + + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio)); + + solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; + + /* read and store isotope ratio uncertainty */ + if ((j = copy_token(token, &next_char, &l)) != EMPTY) { + if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio_uncertainty)); + } + count_isotopes++; + break; + case 10: /* water */ + j = copy_token (token, &next_char, &l); + if (j == EMPTY) { + solution[n]->mass_water=1.0; + } else if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } else { + sscanf(token, SCANFORMAT, &dummy); + solution[n]->mass_water = (LDBLE) dummy; + } + break; + case OPTION_DEFAULT: +/* + * Read concentration + */ + if ( read_conc(n, count_mass_balance, line) == ERROR ) { + input_error++; + break; + } + count_mass_balance++; + break; + } + if (count_mass_balance + 1 >= max_mass_balance) { + space ((void **) &(solution[n]->totals), count_mass_balance + 1, + &max_mass_balance, sizeof (struct conc)); + } + if (return_value == EOF || return_value == KEYWORD) break; + } +#ifdef SKIP +/* + * Sort totals by description + */ + qsort (solution[n]->totals, + (size_t) count_mass_balance, + (size_t) sizeof(struct conc), + conc_compare); +#endif +/* + * fix up default units and default pe + */ + for (i=0; i < count_mass_balance; i++) { + strcpy(token, solution[n]->totals[i].description); + str_tolower(token); + if (solution[n]->totals[i].units == NULL) { + solution[n]->totals[i].units = solution[n]->units; + } else { + alk = FALSE; + if (strstr(token, "alk") == token) alk = TRUE; + strcpy(token1, solution[n]->totals[i].units); + if (check_units (token1, alk, TRUE, solution[n]->units, TRUE) == ERROR ) { + input_error++; + } else { + solution[n]->totals[i].units = string_hsave(token1); + } + } + if (solution[n]->totals[i].n_pe < 0) { + solution[n]->totals[i].n_pe = default_pe; + } + } + solution[n]->default_pe = default_pe; +/* + * Mark end of solution + */ + solution[n]->totals[count_mass_balance].description = NULL; + solution[n]->count_isotopes = count_isotopes; +#ifdef SKIP + if (count_isotopes > 0) { + qsort (solution[n]->isotopes, + (size_t) count_isotopes, + (size_t) sizeof(struct isotope), + isotope_compare); + } else { + solution[n]->isotopes = free_check_null(solution[n]->isotopes); + } +#endif + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for aqueous species, parse equations + */ + int i; + int association; + struct species *s_ptr; + struct elt_list *next_elt; + char *ptr, token[MAX_LENGTH]; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "gamma", /* 2 */ + "mb", /* 3 */ + "mass_balance", /* 4 */ + "log_k", /* 5 */ + "logk", /* 6 */ + "delta_h", /* 7 */ + "deltah", /* 8 */ + "analytical_expression", /* 9 */ + "a_e", /* 10 */ + "ae", /* 11 */ + "mole_balance", /* 12 */ + "llnl_gamma", /* 13 */ + "co2_llnl_gamma", /* 14 */ + "activity_water", /* 15 */ + "add_logk", /* 16 */ + "add_log_k", /* 17 */ + "add_constant" /* 18 */ + }; + int count_opt_list = 19; + + association=TRUE; + s_ptr = NULL; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* gamma data */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 2; /* Wateq D-H */ + i = sscanf(next_char,SCANFORMAT SCANFORMAT, &s_ptr->dha, &s_ptr->dhb ); + if (i < 2) { + sprintf(error_string, "Expecting 2 activity-" + "coefficient parameters, a and b."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 3: /* mb */ + case 4: /* mass_balance */ + case 12: /* mole_balance */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count =0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = elt_list_save(); +/* debug + for (i = 0; i < count_elts; i++) { + output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 5: /* log_k */ + case 6: /* logk */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 7: /* delta_h */ + case 8: /* deltah */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 9: /* analytical_expression */ + case 10: /* a_e */ + case 11: /* ae */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[2])); + opt_save = OPTION_DEFAULT; + break; + case 13: /* llnl_gamma */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 7; /* llnl D-H */ + i = sscanf(next_char,SCANFORMAT, &s_ptr->dha); + if (i < 1) { + sprintf(error_string, "Expecting activity-coefficient parameter, a."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 14: /* co2_llnl_gamma */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 8; /* llnl CO2 D-H */ + opt_save = OPTION_DEFAULT; + break; + case 15: /* activity water */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 9; /* activity_water/55.5 for HDO, D2O, H2[O18], etc */ + opt_save = OPTION_DEFAULT; + break; + case 16: /* add_logk */ + case 17: /* add_log_k */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) { + input_error++; + sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 18: /* add_constant */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + input_error++; + sprintf(error_string, "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get space for species information and parse equation + */ + s_ptr = NULL; + if ( parse_eq(line, &next_elt, association ) == ERROR) { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = s_store( trxn.token[0].name, trxn.token[0].z, TRUE); + for (i=1; inext_elt=next_elt; + trxn.token[0].s->next_secondary = NULL; + for ( ; next_elt->elt != NULL; next_elt++) { + if ( strcmp (next_elt->elt->name,"C") == 0 ) { + trxn.token[0].s->carbon = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"H") == 0 ) { + trxn.token[0].s->h = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"O") == 0 ) { + trxn.token[0].s->o = next_elt->coef; + } + } +/* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); +/* + * Copy reaction to reaction for species + */ + trxn_copy(trxn.token[0].s->rxn); + s_ptr=trxn.token[0].s; +/* + * Default gamma data + */ + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + if (equal (s_ptr->z, 0.0, TOL) == TRUE) { + s_ptr->gflag = 0; /* Uncharged */ + s_ptr->dhb = 0.1; + } else { + s_ptr->gflag = 1; /* Davies */ + } +/* + * Set type for species + */ + if ( strcmp(trxn.token[0].s->name, "H+" ) == 0) { + s_hplus = trxn.token[0].s; + s_hplus->type = HPLUS; + } else if ( strcmp(trxn.token[0].s->name, "H3O+" ) == 0) { + s_h3oplus = trxn.token[0].s; + s_h3oplus->type = HPLUS; + } else if ( strcmp(trxn.token[0].s->name, "e-" ) == 0) { + s_eminus = trxn.token[0].s; + s_eminus->type = EMINUS; + s_eminus->gflag = 3; /* Always 1 */ + } else if ( strcmp(trxn.token[0].s->name, "H2O" ) == 0) { + s_h2o = trxn.token[0].s; + s_h2o->type = H2O; + s_h2o->gflag = 3; /* Always 1 */ + } else if ( strstr(trxn.token[0].s->name, "(s)" ) != NULL) { + trxn.token[0].s->type = SOLID; + } else if ( strcmp(trxn.token[0].s->name, "H2" ) == 0 ) { + trxn.token[0].s->type = AQ; + s_h2 = trxn.token[0].s; + } else if ( strcmp(trxn.token[0].s->name, "O2" ) == 0 ) { + trxn.token[0].s->type = AQ; + s_o2 = trxn.token[0].s; + } else { + trxn.token[0].s->type = AQ; + } + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_use (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, mix, irreversible reaction, and pure phases to use + * in reaction calculation + */ + int i, l, n_user, return_value; + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH];; +/* + * Read "use" + */ + ptr = line; + copy_token (token, &ptr, &l); +/* + * Read keyword + */ + copy_token (token, &ptr, &l); + check_key (token); + switch (next_keyword) { + case -1: /* Have not read line with keyword */ + case 0: /* End encountered */ + case 1: /* EOF encountered */ + case 2: /* Read aqueous model */ + case 3: /* Read master species */ + case 5: + case 9: + case 10: + case 11: + case 12: + case 14: + case 15: + case 18: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 30: + case 31: + case 32: + case 34: + case 35: + case 38: + case 39: + input_error++; + error_msg("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions.", CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of use",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(ERROR); + } +/* + * Read number + */ + strcpy(token1, token); + for (;;) { + i = copy_token (token, &ptr, &l); + if (i == DIGIT) { + sscanf(token,"%d",&n_user); + if (n_user < 0) { + error_msg("Number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + if (strstr(token,"-") != NULL) { + sprintf(error_string, "USE does not accept a range of numbers, %s.", token); + warning_msg(error_string); + sprintf(error_string, "Only %s %d will be used in the batch-reaction calculation.", token1, n_user); + warning_msg(error_string); + sprintf(error_string, "NOTE--USE is not needed for ADVECTION and TRANSPORT calculations."); + warning_msg(error_string); + + } + break; + } else if ( i == EMPTY ) { + sprintf(error_string, "No number given, 1 assumed."); + warning_msg(error_string); + n_user=1; + break; + } else if (token[0] == 'N' || token[0] == 'n') { + n_user = -2; + break; + } + } + switch (next_keyword) { + case 4: /* Solution */ + use.n_solution_user = n_user; + if (n_user >= 0 ) { + use.solution_in = TRUE; + } else { + use.solution_in = FALSE; + } + break; + case 6: /* Pure phases */ + case 26: + case 27: + case 28: + case 29: + use.n_pp_assemblage_user = n_user; + if (n_user >= 0 ) { + use.pp_assemblage_in = TRUE; + } else { + use.pp_assemblage_in = FALSE; + } + break; + case 7: /* Reaction */ + use.n_irrev_user = n_user; + if (n_user >= 0 ) { + use.irrev_in = TRUE; + } else { + use.irrev_in = FALSE; + } + break; + case 8: /* Mix */ + use.n_mix_user = n_user; + if (n_user >= 0 ) { + use.mix_in = TRUE; + } else { + use.mix_in = FALSE; + } + break; + case 13: /* Ex */ + use.n_exchange_user = n_user; + if (n_user >= 0 ) { + use.exchange_in = TRUE; + } else { + use.exchange_in = FALSE; + } + break; + case 16: /* Surface */ + use.n_surface_user = n_user; + if (n_user >= 0 ) { + use.surface_in = TRUE; + } else { + use.surface_in = FALSE; + } + break; + case 17: /* Temperature */ + use.n_temperature_user = n_user; + if (n_user >= 0 ) { + use.temperature_in = TRUE; + } else { + use.temperature_in = FALSE; + } + break; + case 19: /* Gas */ + use.n_gas_phase_user = n_user; + if (n_user >= 0 ) { + use.gas_phase_in = TRUE; + } else { + use.gas_phase_in = FALSE; + } + break; + case 33: /* Kinetics */ + use.n_kinetics_user = n_user; + if (n_user >= 0 ) { + use.kinetics_in = TRUE; + } else { + use.kinetics_in = FALSE; + } + break; + case 40: /* solid_solutions */ + case 41: /* solid_solution */ + use.n_s_s_assemblage_user = n_user; + if (n_user >= 0 ) { + use.s_s_assemblage_in = TRUE; + } else { + use.s_s_assemblage_in = FALSE; + } + break; + } + return_value = check_line("End of use",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_surface_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for surface species, parse equations + */ + int i; + int association; + char token[MAX_LENGTH]; + char *ptr; + LDBLE offset; + + struct species *s_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "mb", /* 2 */ + "mass_balance", /* 3 */ + "log_k", /* 4 */ + "logk", /* 5 */ + "delta_h", /* 6 */ + "deltah", /* 7 */ + "analytical_expression", /* 8 */ + "a_e", /* 9 */ + "ae", /* 10 */ + "mole_balance", /* 11 */ + "offset", /* 12 */ + "add_logk", /* 13 */ + "add_log_k", /* 14 */ + "add_constant" /* 15 */ + }; + int count_opt_list = 16; + + association=TRUE; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + s_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SURFACE_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* mb */ + case 3: /* mass_balance */ + case 11: /* mole_balance */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count =0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = elt_list_save(); +/* debug + for (i = 0; i < count_elts; i++) { + output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 4: /* log_k */ + case 5: /* logk */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 6: /* delta_h */ + case 7: /* deltah */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 8: /* analytical_expression */ + case 9: /* a_e */ + case 10: /* ae */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[2])); + opt_save = OPTION_DEFAULT; + break; + case 12: /* offset */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (sscanf(next_char, SCANFORMAT, &offset) != 1) { + error_msg("No offset for log K given", STOP); + } + s_ptr->logk[0] += offset; + opt_save = OPTION_DEFAULT; + break; + case 13: /* add_logk */ + case 14: /* add_log_k */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) { + input_error++; + sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 15: /* add_constant */ + if (s_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + } else { + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); + if (s_ptr->add_logk == NULL) malloc_error(); + } + i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) { + input_error++; + sprintf(error_string, "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get surface species information and parse equation + */ + s_ptr = NULL; + if ( parse_eq(line, &next_elt, association ) == ERROR) { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = s_store(trxn.token[0].name, trxn.token[0].z, TRUE); + for (i=1; inext_elt=next_elt; + for ( ; next_elt->elt != NULL; next_elt++) { + if ( strcmp (next_elt->elt->name,"C") == 0 ) { + trxn.token[0].s->carbon = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"H") == 0 ) { + trxn.token[0].s->h = next_elt->coef; + } + if ( strcmp (next_elt->elt->name,"O") == 0 ) { + trxn.token[0].s->o = next_elt->coef; + } + } +/* + * Find coefficient of surface in rxn, store in equiv + */ + trxn.token[0].s->equiv = 0.0; + for (i=1; itype == SURF) { + trxn.token[0].s->equiv = trxn.token[i].coef; + } + } + if (trxn.token[0].s->equiv == 0.0) trxn.token[0].s->equiv = 1.0; +/* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); +/* + * Copy reaction to reaction for species + */ + token_ptr=trxn.token[0].s->rxn->token; + for (i=0; itype = SURF; + s_ptr=trxn.token[0].s; +/* + * Read gamma data + */ + s_ptr->gflag = 6; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_surf(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads surface data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int count_comps, count_charge; + int n_user, n_user_end; + LDBLE conc, area, grams /*, thickness , factor */; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH], name[MAX_LENGTH]; + struct surface *surface_ptr; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "equilibrate", /* 0 */ + "equil", /* 1 */ + "diff", /* 2 */ + "diffuse_layer", /* 3 */ + "no_edl", /* 4 */ + "no_electrostatic", /* 5 */ + "only_counter_ions", /* 6 */ + "donnan", /* 7 */ + "transport" /* 8 */ + }; + int count_opt_list = 9; +/* + * kin_surf is for Surfaces, related to kinetically reacting minerals + * they are defined if "sites" is followed by mineral name: + * Surf_wOH Manganite [equilibrium_phases or kinetics] 0.25 4000 + * ^Name mineral ^switch ^prop.factor ^m2/mol + */ +/* + * Read surface number and description + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Find space for surface data + */ + surface_ptr = surface_search(n_user, &n, FALSE); + if (surface_ptr != NULL) { + surface_free(&surface[n]); + } else { + n = count_surface++; + space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); + } +/* + * Initialize + */ + surface_init(&(surface[n]), n_user, n_user_end, description); + free_check_null(description); + + if (use.surface_in == FALSE) { + use.surface_in = TRUE; + use.n_surface_user = n_user; + } +/* + * Read surface data + */ + count_charge = 0; + count_comps = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SURFACE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* equilibrate */ + case 1: + for (;;) { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) { + sscanf(token, "%d", &surface[n].n_solution); + surface[n].solution_equilibria = TRUE; + break; + } + if (i == EMPTY) { + error_msg("Expected a solution number with which to equilibrate surface.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case 2: /* diffuse_layer */ + case 3: + surface[n].thickness = 1e-8; + surface[n].diffuse_layer = TRUE; + for (;;) { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) { + sscanf(token, SCANFORMAT, &surface[n].thickness); + break; + } else if (i != EMPTY) { + if (token[0] == 'D' || token[0] == 'd') { + surface[n].debye_units = 1.0; + j = copy_token(token1, &ptr, &l); + if (j == DIGIT) { + sscanf(token1, SCANFORMAT, &surface[n].debye_units); + break; + } else if (j != EMPTY) { + error_msg("Expected number of Debye units (1/k) for calculating diffuse layer thickness.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } else break; + } else { + error_msg("Expected D or d for Donnan calculations.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } else break; + } + break; + case 4: /* no electrostatic */ + case 5: + surface[n].edl = FALSE; + break; + case 6: + surface[n].only_counter_ions = TRUE; + break; + case 7: /* donnan for DL conc's */ + surface[n].donnan = TRUE; + break; + case 8: /* transport */ + surface[n].transport = TRUE; + break; + case OPTION_DEFAULT: +/* + * Read surface component + */ + ptr=line; + i = copy_token(token, &ptr, &l); + if (i != UPPER && token[0] != '[' ) { + error_msg("Expected surface name to begin with a capital letter.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } +/* + * Realloc space for new surface component + */ + surface[n].comps = (struct surface_comp *) PHRQ_realloc( surface[n].comps, (size_t) (count_comps + 1) * sizeof (struct surface_comp)); + if (surface[n].comps == NULL) malloc_error(); + surface[n].comps[count_comps].formula = string_hsave(token); + surface[n].comps[count_comps].moles = 0; + surface[n].comps[count_comps].cb = 0; + surface[n].comps[count_comps].phase_name = NULL; + surface[n].comps[count_comps].rate_name = NULL; + i = copy_token(token1, &ptr, &l); + if (i == DIGIT) { +/* + * Read surface concentration + */ + /* surface concentration is read directly */ + if ( sscanf(token1, SCANFORMAT, &conc) < 1) { + error_msg("Expected number of surface sites in moles.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } +#ifdef PHREEQCI_GUI + surface[n].comps[count_comps].moles = conc; +#endif +/* + * Read equilibrium phase name or kinetics rate name + */ + } else if (i != EMPTY) { + + /* surface conc. is related to mineral or kinetics */ + surface[n].comps[count_comps].phase_name = string_hsave(token1); + j = copy_token(token1, &ptr, &l); + + /* read optional 'equilibrium_phases' or 'kinetics' */ + if (j == DIGIT) { + surface[n].related_phases = TRUE; + } else { + if (token1[0] == 'K' || token1[0] == 'k') { + surface[n].comps[count_comps].rate_name = surface[n].comps[count_comps].phase_name; + surface[n].comps[count_comps].phase_name = NULL; + surface[n].related_rate = TRUE; + } else if (token1[0] == 'E' || token1[0] == 'e') { + surface[n].related_phases = TRUE; + surface[n].comps[count_comps].rate_name = NULL; + } else { + error_msg("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate surface to mineral or kinetic reaction.\n", CONTINUE); + input_error++; + break; + } + j = copy_token(token1, &ptr, &l); + } + + /* read proportion */ + if (j != DIGIT) { + error_msg("Expected a coefficient to relate surface to mineral or kinetic reaction.\n", CONTINUE); + input_error++; + break; + } + sscanf(token1, SCANFORMAT, &surface[n].comps[count_comps].phase_proportion); + /* real conc must be defined in tidy_model */ + conc = 1.0; + } else { + error_msg("Expected concentration of surface, mineral name, or kinetic reaction name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } +/* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + ptr1 = token; + get_elts_in_species(&ptr1, conc); + surface[n].comps[count_comps].totals = elt_list_save(); +/* + * Search for charge structure + */ + ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name,'_'); + if (ptr1 != NULL) ptr1[0] = '\0'; + for (i = 0; i < count_charge; i++) { + if (strcmp(surface[n].charge[i].name, name) == 0) break; + } + if (i >= count_charge) { + surface[n].charge = (struct surface_charge *) PHRQ_realloc(surface[n].charge, (size_t) ( count_charge + 1) * sizeof(struct surface_charge)); + if (surface[n].charge == NULL) malloc_error(); + i = count_charge; + surface[n].charge[i].name = string_hsave(name); + if (surface[n].comps[count_comps].phase_name == NULL && surface[n].comps[count_comps].rate_name == NULL) { + surface[n].charge[i].specific_area = 600.0; + surface[n].charge[i].grams = 0.0; + } else { + surface[n].charge[i].specific_area = 0.0; + surface[n].charge[i].grams = 1.0; + } + surface[n].charge[i].mass_water = 0.0; + surface[n].charge[i].charge_balance = 0.0; + surface[n].charge[i].diffuse_layer_totals = NULL; + surface[n].charge[i].count_g = 0; + surface[n].charge[i].g = NULL; + surface[n].charge[i].psi_master = NULL; + count_charge++; + } + surface[n].comps[count_comps].charge = i; + count_comps++; +/* + * Read surface area (m2/g) + */ + copy_token(token1, &ptr, &l); + if (sscanf(token1, SCANFORMAT, &area) == 1) { + surface[n].charge[i].specific_area = area; + } else { + break; + } +/* + * Read grams of solid (g) + */ + copy_token(token1, &ptr, &l); + if (sscanf(token1, SCANFORMAT, &grams) == 1 ) { + surface[n].charge[i].grams = grams; + } + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + surface[n].count_comps = count_comps; + surface[n].count_charge = count_charge; +/* + * Make sure surface area is defined + */ + if (surface[n].edl == TRUE) { + for (i = 0; i < count_charge; i++) { + if (surface[n].charge[i].grams * surface[n].charge[i].specific_area <= 0) { + sprintf(error_string, "Surface area not defined for %s.\n", surface[n].charge[i].name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } else { + if (surface[n].diffuse_layer == TRUE) { + sprintf(error_string, "Diffuse_layer and no_edl are mutually exclusive options.\n"); + error_msg(error_string, CONTINUE); + input_error++; + } + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_surface_master_species (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species data from data file or input file + */ + int i, l, n, return_value; + char *ptr, *ptr1; + LDBLE z; + struct master *master_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + for (;;) { + return_value = check_line ("Surface species equation", FALSE, TRUE, TRUE, TRUE); + if (return_value == EOF || return_value == KEYWORD ) break; +/* + * Get "element" name with valence, allocate space, store + */ + ptr=line; +/* + * Get element name and save pointer to character string + */ + if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { + parse_error++; + error_msg ("Reading element for master species.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + /* + if (token[0] == '[') { + ptr1 = token; + get_elt(&ptr, element, &l); + strcpy(token, element); + } + */ + replace ("(+", "(", token); +/* + * Delete master if it exists + */ + master_delete(token); +/* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master + 2 >= max_master) { + space ((void **) ((void *) &master), count_master+2, &max_master, sizeof(struct master *)); + } +/* + * Save values in master and species structure for surface sites + */ + master[count_master] = master_alloc(); + master[count_master]->type = SURF; + master[count_master]->elt = element_store ( token ); + + if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { + parse_error++; + error_msg("Reading surface master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + s_ptr=s_search (token); + if (s_ptr != NULL) { + master[count_master]->s = s_ptr; + } else { + ptr1=token; + get_token(&ptr1, token1, &z, &l); + master[count_master]->s = s_store(token1, z, FALSE); + } + master[count_master]->primary=TRUE; + strcpy(token,master[count_master]->elt->name); + count_master++; +/* + * Save values in master and species structure for surface psi + */ + strcpy(token1, token); + replace ("_", " ", token1); + ptr1 = token1; + copy_token(token, &ptr1, &l); + strcat(token,"_psi"); + master_ptr=master_search (token, &n); + if (master_ptr == NULL) { + master[count_master] = master_alloc(); + master[count_master]->type = SURF_PSI; + master[count_master]->elt = element_store ( token ); + s_ptr=s_search (token); + if (s_ptr != NULL) { + master[count_master]->s = s_ptr; + } else { + master[count_master]->s = s_store(token, 0.0, FALSE); + } + count_elts = 0; + paren_count = 0; + ptr = token; + get_elts_in_species(&ptr, 1.0); + master[count_master]->s->next_elt = elt_list_save(); + + master[count_master]->s->type=SURF_PSI; + master[count_master]->primary=TRUE; + master[count_master]->s->rxn = rxn_alloc(3); +/* + * Define reaction for psi + */ + for( i = 0; i < 8; i++) { + master[count_master]->s->rxn->logk[i] = 0.0; + } + master[count_master]->s->rxn->token[0].s = master[count_master]->s; + master[count_master]->s->rxn->token[0].coef = -1.0; + master[count_master]->s->rxn->token[1].s = master[count_master]->s; + master[count_master]->s->rxn->token[1].coef = 1.0; + master[count_master]->s->rxn->token[2].s = NULL; + count_master++; + } + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int read_temperature (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads temperature data for reaction steps + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + char *description; + int n, return_value; + int n_user, n_user_end; + struct temperature *temperature_ptr; +/* + * Read reaction number + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Read allocate space for temperature + */ + temperature_ptr = temperature_search(n_user, &n); + if (temperature_ptr != NULL) { + temperature_free(&temperature[n]); + } else { + n = count_temperature++; + temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature)); + if (temperature == NULL) malloc_error(); + } +/* + * Set use data to first read + */ + if (use.temperature_in == FALSE) { + use.temperature_in = TRUE; + use.n_temperature_user = n_user; + } +/* + * Defaults + */ + temperature[n].n_user = n_user; + temperature[n].n_user_end = n_user_end; + temperature[n].description = description; + temperature[n].t = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (temperature[n].t == NULL) malloc_error(); + temperature[n].t[0] = 25.0; + temperature[n].count_t = 0; +/* + * Read temperature data + */ + for (;;) { + return_value = check_line("reaction_temperature",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; +/* + * Read steps information + */ + read_reaction_temps(&(temperature[n])); + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_reaction_temps(struct temperature *temperature_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read temperature one of two forms: + * + * (1) 25.0 30. 40. 50. 60. + * + * (2) 25.0 100.0 in 4 steps # (25 50 75 100) + * + */ + int i, j, l; + int count_t; + char *ptr; + char token[MAX_LENGTH]; + LDBLE step; + + ptr = line; + count_t = temperature_ptr->count_t; +/* + * Read one or more reaction increments + */ + for (;;) { + if ( copy_token (token, &ptr, &l) == EMPTY ) { + return(OK); + } +/* + * Read next step increment + */ + j = sscanf(token, SCANFORMAT, &step); + if (j == 1 ) { + count_t++; + temperature_ptr->t = (LDBLE *) PHRQ_realloc(temperature_ptr->t, (size_t) count_t * sizeof(LDBLE)); + if (temperature_ptr->t == NULL) malloc_error(); + temperature_ptr->t[temperature_ptr->count_t] = step; + temperature_ptr->count_t = count_t; + } else { + break; + } + } +/* + * Read number of equal increments, store as negative integer + */ + if (count_t != 2) { + error_msg("To define equal increments, exactly two temperatures should be defined.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + do { + j = sscanf(token, "%d", &i); + if (j == 1 && i > 0 ) { + temperature_ptr->count_t = -i; + return(OK); + } else if (j == 1 && i <= 0 ) { + break; + } + } while ( copy_token (token, &ptr, &l) != EMPTY ); + + error_msg("Expecting positive number for calculation of " + "temperature increments.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); +} +/* ---------------------------------------------------------------------- */ +int read_title (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads title for simulation + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr, *ptr1; + int l, title_x_length, line_length; + int return_value; + char token[MAX_LENGTH]; +/* + * Read anything after keyword + */ + ptr=line; + copy_token(token, &ptr, &l); + ptr1 = ptr; + title_x = (char *) free_check_null(title_x); + if (copy_token(token, &ptr, &l) != EMPTY) { + title_x = string_duplicate(ptr1); + } else { + title_x = (char *) PHRQ_malloc(sizeof(char)); + if (title_x == NULL) malloc_error(); + title_x[0] = '\0'; + } + +/* + * Read additonal lines + */ + for (;;) { + return_value = check_line("title",TRUE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD ) break; +/* + * append line to title_x + */ + title_x_length = strlen(title_x); + line_length = strlen(line); + title_x = (char *) PHRQ_realloc(title_x, (size_t) (title_x_length + line_length + 2) * sizeof(char)); + if (title_x == NULL) malloc_error(); + if (title_x_length > 0) { + title_x[title_x_length] = '\n'; + title_x[title_x_length+1] = '\0'; + } + strcat(title_x, line); + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_advection (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads advection information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read advection parameters: + * number of cells; + * number of shifts; + */ + char *ptr; + char *description; + int n_user, n_user_end, i; + + int count_punch, count_print; + int *punch_temp, *print_temp; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "cells", /* 0 */ + "shifts", /* 1 */ + "print", /* 2 */ + "selected_output", /* 3 */ + "punch", /* 4 */ + "print_cells", /* 5 */ + "selected_cells", /* 6 */ + "time_step", /* 7 */ + "timest", /* 8 */ + "output", /* 9 */ + "output_frequency", /* 10 */ + "selected_output_frequency",/* 11 */ + "punch_frequency", /* 12 */ + "print_frequency", /* 13 */ + "punch_cells", /* 14 */ + "initial_time", /* 15 */ + "warning", /* 16 */ + "warnings" /* 17 */ + }; + int count_opt_list = 18; +/* + * Read advection number (not currently used) + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); +/* + * Set use data + */ + use.advect_in = TRUE; + count_ad_cells = 0; + count_ad_shifts = 0; + print_ad_modulus = 1; + punch_ad_modulus = 1; + count_punch = 0; + count_print = 0; + punch_temp = (int *) PHRQ_malloc(sizeof(int)); + if (punch_temp == NULL) malloc_error(); + print_temp = (int *) PHRQ_malloc(sizeof(int)); + if (print_temp == NULL) malloc_error(); +/* + * Read lines + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ADVECTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* cells */ + sscanf(next_char, "%d", &count_ad_cells); + opt_save = OPTION_DEFAULT; + break; + case 1: /* shifts */ + sscanf(next_char, "%d", &count_ad_shifts); + opt_save = OPTION_DEFAULT; + break; + case 2: /* print */ + case 5: /* print_cells */ + print_temp = read_list_ints_range (&next_char, &count_print, TRUE, print_temp); +#ifdef SKIP + while (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &l); + print_temp = PHRQ_realloc(print_temp, (size_t) (count_print + 1) * sizeof(int)); + if (print_temp == NULL) malloc_error(); + print_temp[count_print] = l; + count_print++; + } +#endif + opt_save = 2; + break; + case 3: /* selected_output */ + case 11: /* selected_output_frequency */ + case 12: /* punch_frequency */ + sscanf(next_char, "%d", &punch_ad_modulus); + opt_save = OPTION_DEFAULT; + break; + case 4: /* punch */ + case 14: /* punch_cells */ + case 6: /* selected_cells */ + punch_temp = read_list_ints_range (&next_char, &count_punch, TRUE, punch_temp); +#ifdef SKIP + while (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &l); + punch_temp = PHRQ_realloc(punch_temp, (size_t) (count_punch + 1) * sizeof(int)); + if (punch_temp == NULL) malloc_error(); + punch_temp[count_punch] = l; + count_punch++; + } +#endif + opt_save = 4; + break; + case 7: /* time_step */ + case 8: /* timest */ + sscanf(next_char, SCANFORMAT, &advection_kin_time); + advection_kin_time_defined = TRUE; + opt_save = OPTION_DEFAULT; + break; + case 9: /* output */ + case 10: /* output_frequency */ + case 13: /* print_frequency */ + sscanf(next_char, "%d", &print_ad_modulus); + opt_save = OPTION_DEFAULT; + break; + case 15: /* initial_time */ + sscanf(next_char, SCANFORMAT, &initial_total_time); + opt_save = OPTION_DEFAULT; + break; + case 16: /* warning */ + case 17: /* warnings */ + advection_warnings = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* + * Fill in data for punch + */ + advection_punch = (int *) PHRQ_realloc(advection_punch, (size_t) (count_ad_cells + 1) * sizeof(int)); + if (advection_punch == NULL) malloc_error(); + if (count_punch != 0) { + for (i=0; i count_ad_cells || punch_temp[i] < 1) { + sprintf(error_string,"Cell number for punch is out of range, %d. Request ignored.", punch_temp[i]); + warning_msg(error_string); + } else { + advection_punch[punch_temp[i]-1] = TRUE; + } + } + } else { + for (i=0; i count_ad_cells || print_temp[i] < 1) { + sprintf(error_string,"Cell number for print is out of range, %d. Request ignored.", print_temp[i]); + warning_msg(error_string); + } else { + advection_print[print_temp[i]-1] = TRUE; + } + } + } else { + for (i=0; idata))->keycount; + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int check_units (char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print) +/* ---------------------------------------------------------------------- */ +{ +#define NUNITS (sizeof(units) / sizeof(char *)) +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity TRUE if alkalinity, FALSE if any other total, + * check_compatibility TRUE check alk and default units, FALSE otherwise + * default_units character string of default units (check /L, /kg, etc) + * print TRUE print warning messages + * Output: + * tot_units standard form for unit + */ + int i, found; + char *end; + char string[MAX_LENGTH]; + const char *units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white (tot_units); + str_tolower(tot_units); + replace ("milli", "m", tot_units); + replace ("micro", "u", tot_units); + replace ("grams", "g", tot_units); + replace ("gram", "g", tot_units); + replace ("moles", "Mol", tot_units); + replace ("mole", "Mol", tot_units); + replace ("mol", "Mol", tot_units); + replace ("liter", "l", tot_units); + replace ("kgh", "kgw", tot_units); + replace ("ppt", "g/kgs", tot_units); + replace ("ppm", "mg/kgs",tot_units); + replace ("ppb", "ug/kgs",tot_units); + replace ("equivalents","eq", tot_units); + replace ("equivalent", "eq", tot_units); + replace ("equiv", "eq", tot_units); + + if ( (end=strstr(tot_units,"/l")) != NULL) { + *(end+2)='\0'; + } + if ( (end=strstr(tot_units,"/kgs")) != NULL) { + *(end+4)='\0'; + } + if ( (end=strstr(tot_units,"/kgw")) != NULL) { + *(end+4)='\0'; + } +/* + * Check if unit in list + */ + found = FALSE; + for (i=0; i < (int) NUNITS; i++) { + if (strcmp(tot_units, units[i]) == 0) { + found=TRUE; + break; + } + } + if (found == FALSE) { + if (print == TRUE) { + sprintf(error_string, "Unknown unit, %s.", tot_units); + error_msg(error_string, CONTINUE); + } + return (ERROR); + } + +/* + * Check if units are compatible with default_units + */ + if (check_compatibility == FALSE) return (OK); +/* + * Special cases for alkalinity + */ + if (alkalinity == TRUE && strstr(tot_units,"Mol") != NULL) { + if (print == TRUE) { + sprintf(error_string, "Alkalinity given in moles, assumed to be equivalents."); + warning_msg(error_string); + } + replace("Mol","eq",tot_units); + } + if (alkalinity == FALSE && strstr(tot_units,"eq") != NULL) { + if (print == TRUE) { + error_msg("Only alkalinity can be entered in equivalents.", CONTINUE); + } + return (ERROR); + } +/* + * See if default_units are compatible with tot_units + */ + if ( strstr(default_units,"/l") && strstr(tot_units,"/l")) return (OK); + if ( strstr(default_units,"/kgs") && strstr(tot_units,"/kgs")) return (OK); + if ( strstr(default_units,"/kgw") && strstr(tot_units,"/kgw")) return (OK); + + strcpy( string, default_units); + replace ("kgs","kg solution",string); + replace ("kgs","kg solution",tot_units); + replace ("kgw","kg water",string); + replace ("kgw","kg water",tot_units); + replace ("/l","/L",string); + replace ("Mol","mol",string); + replace ("/l","/L",tot_units); + replace ("Mol","mol",tot_units); + if (print == TRUE) { + sprintf(error_string, "Units for master species, %s, are not compatible with default units, %s.", tot_units, string); + error_msg(error_string, CONTINUE); + } + return (ERROR); +} +/* ---------------------------------------------------------------------- */ +int find_option(char *item, int *n, const char **list, int count_list, int exact) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares a string value to match beginning letters of a list of options + * + * Arguments: + * item entry: pointer to string to compare + * n exit: item in list that was matched + * list entry: pointer to list of character values, assumed to + * be lower case + * count_list entry: number of character values in list + * + * Returns: + * OK item matched + * ERROR item not matched + * n -1 item not matched + * i position of match in list + */ + int i; + char token[MAX_LENGTH]; + + strcpy(token, item); + str_tolower(token); + for (i=0; i < count_list; i++) { + if (exact == TRUE) { + if (strcmp(list[i], token) == 0) { + *n = i; + return(OK); + } + } else { + if (strstr(list[i], token) == list[i]) { + *n = i; + return(OK); + } + } + } + *n = -1; + return(ERROR); +} +/* ---------------------------------------------------------------------- */ +int get_true_false(char *string, int default_value) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns true unless string starts with "F" or "f" + */ + int l; + char token[MAX_LENGTH]; + char *ptr; + + ptr = string; + + if (copy_token(token, &ptr, &l) == EMPTY) { + return(default_value); + } else { + if (token[0] == 'F' || token[0] == 'f') { + return(FALSE); + } + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int get_option (const char **opt_list, int count_opt_list, char **next_char) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line and check for options + */ + int j; + int opt_l, opt; + char *opt_ptr; + char option[MAX_LENGTH]; +/* + * Read line + */ + j = check_line ("get_option", FALSE, TRUE, TRUE, FALSE); + if (j == EOF) { + j = OPTION_EOF; + } else if (j == KEYWORD ) { + j = OPTION_KEYWORD; + } else if (j == OPTION) { + opt_ptr = line; + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[1]), &opt, opt_list, count_opt_list, FALSE) == OK) { + j = opt; + replace(option, opt_list[j], line_save); + replace(option, opt_list[j], line); + opt_ptr = line; + copy_token(option, &opt_ptr, &opt_l); + *next_char = opt_ptr; + if (pr.echo_input == TRUE) { + if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); + } + } else { + if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); + error_msg("Unknown option.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + j = OPTION_ERROR; + *next_char = line; + } + } else { + opt_ptr = line; + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[0]), &opt, opt_list, count_opt_list, TRUE) == OK) { + j = opt; + *next_char = opt_ptr; + } else { + j = OPTION_DEFAULT; + *next_char = line; + } + if (pr.echo_input == TRUE) { + if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); + } + } + return (j); +} +/* ---------------------------------------------------------------------- */ +int read_rates (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, length, line_length, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct rate *rate_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; +/* + * Read advection number (not currently used) + */ + n = -1; + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + rate_ptr = NULL; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in RATES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPT_1; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read rate name */ + ptr = line; + copy_token(token, &ptr, &l); + rate_ptr = rate_search(token, &n); + if (rate_ptr == NULL) { + rates = (struct rate *) PHRQ_realloc(rates, (size_t) (count_rates + 1) * sizeof (struct rate)); + if (rates == NULL) malloc_error(); + rate_ptr = &rates[count_rates]; + count_rates++; + } else { + rate_free(rate_ptr); + } + rate_ptr->new_def = TRUE; + rate_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); + if (rate_ptr->commands == NULL) malloc_error(); + rate_ptr->commands[0] = '\0'; + rate_ptr->name = string_hsave(token); + rate_ptr->linebase = NULL; + rate_ptr->varbase = NULL; + rate_ptr->loopbase = NULL; + opt_save = OPT_1; + break; + case OPT_1: /* read command */ + if (rate_ptr == NULL) { + input_error++; + sprintf(error_string, "No rate name has been defined."); + error_msg(error_string, CONTINUE); + opt_save = OPT_1; + break; + } + length = strlen(rate_ptr->commands); + line_length = strlen(line); + rate_ptr->commands = (char *) PHRQ_realloc(rate_ptr->commands, (size_t) (length + line_length + 2) * sizeof(char)); + if (rate_ptr->commands == NULL) malloc_error(); + rate_ptr->commands[length] = ';'; + rate_ptr->commands[length + 1] = '\0'; + strcat((rate_ptr->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* output_msg(OUTPUT_MESSAGE, "%s", rates[0].commands); + */ return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_user_print (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int length, line_length; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in RATES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read first command */ + rate_free(user_print); + user_print->new_def = TRUE; + user_print->commands = (char *) PHRQ_malloc(sizeof(char)); + if (user_print->commands == NULL) malloc_error(); + user_print->commands[0] = '\0'; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + user_print->name = string_hsave("user defined Basic print routine"); + case OPT_1: /* read command */ + length = strlen(user_print->commands); + line_length = strlen(line); + user_print->commands = (char *) PHRQ_realloc(user_print->commands, (size_t) (length + line_length + 2) * sizeof(char)); + if (user_print->commands == NULL) malloc_error(); + user_print->commands[length] = ';'; + user_print->commands[length + 1] = '\0'; + strcat((user_print->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* output_msg(OUTPUT_MESSAGE, "%s", rates[0].commands); + */ return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_user_punch (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int l, length, line_length; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end", /* 1 */ + "heading", /* 2 */ + "headings" /* 3 */ + }; + int count_opt_list = 4; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + user_punch_count_headings = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in RATES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading*/ + while (copy_token(token, &next_char, &l) != EMPTY) { + user_punch_headings = (char **) PHRQ_realloc(user_punch_headings, (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + if (user_punch_headings == NULL) malloc_error(); + user_punch_headings[user_punch_count_headings] = string_hsave(token); + user_punch_count_headings++; + } + break; + case OPTION_DEFAULT: /* read first command */ + rate_free(user_punch); + user_punch->new_def = TRUE; + user_punch->commands = (char *) PHRQ_malloc(sizeof(char)); + if (user_punch->commands == NULL) malloc_error(); + user_punch->commands[0] = '\0'; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + user_punch->name = string_hsave("user defined Basic punch routine"); + case OPT_1: /* read command */ + length = strlen(user_punch->commands); + line_length = strlen(line); + user_punch->commands = (char *) PHRQ_realloc(user_punch->commands, (size_t) (length + line_length + 2) * sizeof(char)); + if (user_punch->commands == NULL) malloc_error(); + user_punch->commands[length] = ';'; + user_punch->commands[length + 1] = '\0'; + strcat((user_punch->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return(return_value); +} +#ifdef PHREEQ98 +/* ---------------------------------------------------------------------- */ +int read_user_graph (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int l, length, line_length; + int return_value, opt, opt_save; + char file_name[MAX_LENGTH]; + char token[MAX_LENGTH]; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end", /* 1 */ + "heading", /* 2 */ + "headings", /* 3 */ + "chart_title", /* 4 */ + "axis_titles", /* 5 */ + "axis_scale", /* 6 */ + "initial_solutions", /* 7 */ + "plot_concentration_vs",/* 8 */ + "shifts_as_points", /* 9 */ + "grid_offset", /* 10 */ + "connect_simulations", /* 11 */ + "plot_csv_file" /* 12 */ + + }; + int count_opt_list = 13; + int i; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + user_graph_count_headings = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading*/ + while (copy_token(token, &next_char, &l) != EMPTY) { + user_graph_headings = PHRQ_realloc(user_graph_headings, (size_t) (user_graph_count_headings + 1) * sizeof(char *)); + if (user_graph_headings == NULL) malloc_error(); + user_graph_headings[user_graph_count_headings] = string_hsave(token); + user_graph_count_headings++; + } + break; +/*Modifications of read_user_punch to change the chart's appearance */ + case 4: /* chart title */ + copy_title(token, &next_char, &l); + SetChartTitle(token); + break; + case 5: { /* axis titles */ + i = 0; + while (copy_title(token, &next_char, &l) != EMPTY) { + SetAxisTitles(token, i); + i++; + } + } + break; + case 6: { /* axis scales */ + char* axis = ""; + int j = 0; + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "x") == token) { + axis = "x"; + } else if (strstr(token, "y") == token) { + axis = "y"; + } else if (strstr(token, "s") == token) { + axis = "s"; + } else { + input_error++; + error_msg("Expected axis type.", CONTINUE); + } + while ((j < 4) && (i = copy_token(token, &next_char, &l)) != EMPTY) { + str_tolower(token); + if ((i == DIGIT) || (strstr(token, "auto") == token)) { + SetAxisScale(axis, j, token, FALSE); + } else { + input_error++; + error_msg("Expected numerical value or 'auto'.", CONTINUE); + } + j++; /* counter for categories */ + } + if (j == 4) SetAxisScale(axis, j, 0, get_true_false(next_char, FALSE)); + } + break; + case 7: + graph_initial_solutions = get_true_false(next_char, TRUE); + break; + case 8: + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "x") == token) { + chart_type = 0; + } else if (strstr(token, "t") == token) { + chart_type = 1; + } else { + input_error++; + error_msg("Expected simulation type.", CONTINUE); + } + break; + case 9: + shifts_as_points = get_true_false(next_char, TRUE); + if (shifts_as_points == TRUE) chart_type = 0; + else chart_type = 1; + break; + case 10: { + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) sscanf(token, "%d", &RowOffset); + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) sscanf(token, "%d", &ColumnOffset); + } + break; + case 11: + connect_simulations = get_true_false(next_char, TRUE); + break; + case 12: + string_trim(next_char); + strcpy(file_name, next_char); + if (!OpenCSVFile(file_name)) { + sprintf(error_string, "Can't open file, %s.", file_name); + input_error++; + error_msg(error_string, CONTINUE); + } + break; + /* End of modifications */ + case OPTION_DEFAULT: /* read first command */ + rate_free(user_graph); + user_graph->new_def = TRUE; + user_graph->commands = PHRQ_malloc(sizeof(char)); + if (user_graph->commands == NULL) malloc_error(); + user_graph->commands[0] = '\0'; + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + user_graph->name = string_hsave("user defined Basic punch routine"); + case OPT_1: /* read command */ + length = strlen(user_graph->commands); + line_length = strlen(line); + user_graph->commands = PHRQ_realloc(user_graph->commands, (size_t) (length + line_length + 2) * sizeof(char)); + if (user_graph->commands == NULL) malloc_error(); + user_graph->commands[length] = ';'; + user_graph->commands[length + 1] = '\0'; + strcat((user_graph->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + for (i = 0; i < user_graph_count_headings; i++) + GridHeadings(user_graph_headings[i], i); + return(return_value); +} +#endif +/* ---------------------------------------------------------------------- */ +int read_solid_solutions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solid solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int count_s_s, number_s_s, count_comps; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "component", /* 0 */ + "comp", /* 1 */ + "parms", /* 2 */ + "gugg_nondimensional", /* 3 */ + "gugg_kj", /* 4 */ + "activity_coefficients", /* 5 */ + "distribution_coefficients", /* 6 */ + "miscibility_gap", /* 7 */ + "spinodal_gap", /* 8 */ + "critical_point", /* 9 */ + "alyotropic_point", /* 10 */ + "temp", /* 11 */ + "tempk", /* 12 */ + "tempc", /* 13 */ + "thompson", /* 14 */ + "margules", /* 15 */ + "comp1", /* 16 */ + "comp2" /* 17 */ + }; + int count_opt_list = 18; +/* + * Read s_s_assemblage number + */ + number_s_s = 0; + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); +/* + * Find old s_s_assemblage or alloc space for new s_s_assemblage + */ + if (s_s_assemblage_search(n_user, &n) != NULL) { + s_s_assemblage_free(&s_s_assemblage[n]); + } else { + n=count_s_s_assemblage; + space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + count_s_s_assemblage++; + } +/* + * Initialize + */ + s_s_assemblage_init(&(s_s_assemblage[n]), n_user, n_user_end, description); + free_check_null(description); +/* + * Set use data to first read + */ + if (use.s_s_assemblage_in == FALSE) { + use.s_s_assemblage_in = TRUE; + use.n_s_s_assemblage_user = n_user; + } +/* + * Read solid solutions + */ + count_s_s = 0; + count_comps = 0; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLID_SOLUTIONS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + +/* + * New component + */ + case 0: /* component */ + case 1: /* comp */ + count_comps=s_s_assemblage[n].s_s[number_s_s].count_comps++; + s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps+1) * sizeof(struct s_s_comp)); + if ( s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); + s_s_assemblage[n].s_s[number_s_s].comps[count_comps].initial_moles = 0; + s_s_assemblage[n].s_s[number_s_s].comps[count_comps].delta = 0; + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + s_s_assemblage[n].s_s[number_s_s].comps[count_comps].name = string_hsave(token); + /* + * Read moles of component + */ + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { + s_s_assemblage[n].s_s[number_s_s].comps[count_comps].moles = NAN; + } else { + j=sscanf( token,SCANFORMAT, &dummy); + s_s_assemblage[n].s_s[number_s_s].comps[count_comps].moles = (LDBLE) dummy; + if (j != 1 ) { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; + case 2: /* parms */ + case 3: /* gugg_nondimensional */ + /* + * Read parameters + */ + + ptr = next_char; + if (copy_token(token, &ptr, &l) != EMPTY) { + sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[0]) ); + } + if (copy_token(token, &ptr, &l) != EMPTY) { + sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[1]) ); + } + s_s_assemblage[n].s_s[number_s_s].input_case = 0; + break; + case 4: /* gugg_kj */ + ptr = next_char; + if (copy_token(token, &ptr, &l) != EMPTY) { + sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[0]) ); + } + if (copy_token(token, &ptr, &l) != EMPTY) { + sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[1]) ); + } + s_s_assemblage[n].s_s[number_s_s].input_case = 7; + break; + case 5: /* activity coefficients */ + ptr = next_char; + j = 0; + for (i = 0; i < 4; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 4) { + sprintf(error_string, "Expected 4 parameters to calculate a0 and a1 from two activity coefficients, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 1; + break; + case 6: /* distribution coefficients */ + ptr = next_char; + j = 0; + for (i = 0; i < 4; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 4) { + sprintf(error_string, "Expected 4 parameters to calculate a0 and a1 from two distribution coefficients, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 2; + break; + case 7: /* miscibility_gap */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected 2 miscibility gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 3; + break; + case 8: /* spinodal_gap */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected 2 spinodal gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 4; + break; + case 9: /* critical point */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected fraction of component 2 and critical temperature to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 5; + break; + case 10: /* alyotropic point */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected fraction of component 2 and sigma pi at alyotropic point to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 6; + break; + case 12: /* tempk */ + ptr = next_char; + j = 0; + if (copy_token(token, &ptr, &l) != EMPTY) { + j = sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].tk) ); + } + if (j != 1) { + sprintf(error_string, "Expected temperature (Kelvin) for parameters, assemblage %d, solid solution %s, using 298.15 K", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + warning_msg(error_string); + s_s_assemblage[n].s_s[number_s_s].tk = 298.15; + } + break; + case 11: /* temp */ + case 13: /* tempc */ + ptr = next_char; + j = 0; + if (copy_token(token, &ptr, &l) != EMPTY) { + j = sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].tk) ); + } + if (j != 1) { + sprintf(error_string, "Expected temperature (Celcius) for parameters, assemblage %d, solid solution %s, using 25 C", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + warning_msg(error_string); + s_s_assemblage[n].s_s[number_s_s].tk = 25.; + } + s_s_assemblage[n].s_s[number_s_s].tk += 273.15; + break; + case 14: /* Thompson and Waldbaum */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected Wg2 and Wg1 Thompson-Waldbaum parameters to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 8; + break; + case 15: /* Margules */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) { + if (copy_token(token, &ptr, &l) != EMPTY) { + j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); + } + } + if (j != 2) { + sprintf(error_string, "Expected alpha2 and alpha3 Margules parameters to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + s_s_assemblage[n].s_s[number_s_s].input_case = 9; + break; + case 16: /* comp1 */ + if (count_comps < 2) { + s_s_assemblage[n].s_s[number_s_s].count_comps = 2; + count_comps = 2; + s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps) * sizeof(struct s_s_comp)); + if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); + } + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + s_s_assemblage[n].s_s[number_s_s].comps[0].name = string_hsave(token); + /* + * Read moles of component + */ + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { + s_s_assemblage[n].s_s[number_s_s].comps[0].moles = NAN; + } else { + j=sscanf( token,SCANFORMAT, &dummy); + s_s_assemblage[n].s_s[number_s_s].comps[0].moles = (LDBLE) dummy; + if (j != 1 ) { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; + case 17: /* comp2 */ + if (count_comps < 2) { + s_s_assemblage[n].s_s[number_s_s].count_comps = 2; + count_comps = 2; + s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps) * sizeof(struct s_s_comp)); + if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); + } + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + s_s_assemblage[n].s_s[number_s_s].comps[1].name = string_hsave(token); + /* + * Read moles of component + */ + if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { + s_s_assemblage[n].s_s[number_s_s].comps[1].moles = NAN; + } else { + j=sscanf( token,SCANFORMAT, &dummy); + s_s_assemblage[n].s_s[number_s_s].comps[1].moles = (LDBLE) dummy; + if (j != 1 ) { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; +/* + * New solid solution + */ + case OPTION_DEFAULT: + number_s_s = count_s_s++; + /* + * Make space, set default + */ + + /* realloc space for one s_s */ + s_s_assemblage[n].s_s = (struct s_s *) PHRQ_realloc(s_s_assemblage[n].s_s, (size_t) (count_s_s + 1) * sizeof(struct s_s)); + if (s_s_assemblage[n].s_s == NULL) malloc_error(); + + /* malloc space for one component */ + s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_malloc((size_t) sizeof(struct s_s_comp)); + if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); + count_comps = 0; + s_s_assemblage[n].s_s[number_s_s].count_comps = 0; + s_s_assemblage[n].s_s[number_s_s].input_case = 0; + s_s_assemblage[n].s_s[number_s_s].miscibility = FALSE; + s_s_assemblage[n].s_s[number_s_s].p[0] = 0.0; + s_s_assemblage[n].s_s[number_s_s].p[1] = 0.0; + s_s_assemblage[n].s_s[number_s_s].tk = 298.15; + /* + * Read solid solution name + */ + ptr = line; + copy_token(token, &ptr, &l); + s_s_assemblage[n].s_s[number_s_s].name = string_hsave(token); + s_s_assemblage[n].s_s[number_s_s].total_moles = NAN; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + for (i = 0; i < s_s_assemblage[n].count_s_s; i++) { + if (s_s_assemblage[n].s_s[i].p[0] != 0.0 || + s_s_assemblage[n].s_s[i].p[1] != 0.0) { + if (s_s_assemblage[n].s_s[number_s_s].count_comps != 2) { + sprintf(error_string, "Solid solution, %s, is nonideal. Must define exactly two components (-comp1 and -comp2).", s_s_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } +/* + * Sort components by name (lowercase) + */ + + s_s_assemblage[n].count_s_s = count_s_s; + qsort (s_s_assemblage[n].s_s, + (size_t) count_s_s, + (size_t) sizeof(struct s_s), + s_s_compare); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_llnl_aqueous_model_parameters(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads aqueous model parameters + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + extern int check_line_return; /* input.c */ + int i, count_alloc; + char token[MAX_LENGTH]; + + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temperatures", /* 0 */ + "temperature", /* 1 */ + "temp", /* 2 */ + "adh", /* 3 */ + "debye_huckel_a", /* 4 */ + "dh_a", /* 5 */ + "bdh", /* 6 */ + "debye_huckel_b", /* 7 */ + "dh_b", /* 8 */ + "bdot", /* 9 */ + "b_dot", /* 10 */ + "c_co2", /* 11 */ + "co2_coefs" /* 12 */ + }; + int count_opt_list = 13; +/* + * Initialize + */ +/* + * Read aqueous model parameters + */ + return_value = UNKNOWN; + opt = get_option(opt_list, count_opt_list, &next_char); + for (;;) { + next_char = line; + if (opt >= 0) { + copy_token(token, &next_char , &i); + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in LLNL_AQUEOUS_MODEL_PARAMETERS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + +/* + * New component + */ + case 0: /* temperatures */ + case 1: /* temperature */ + case 2: /* temp */ + count_alloc = 1; + llnl_count_temp = 0; + i = read_lines_doubles(next_char, &(llnl_temp), &(llnl_count_temp), &(count_alloc), opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_temp = read_list_doubles(&ptr, &count); + llnl_count_temp = count; + */ + break; + case 3: /* adh */ + case 4: /* debye_huckel_a */ + case 5: /* dh_a */ + count_alloc = 1; + llnl_count_adh = 0; + i = read_lines_doubles(next_char, &(llnl_adh), &(llnl_count_adh), &(count_alloc), opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_adh = read_list_doubles(&ptr, &count); + llnl_count_adh = count; + */ + break; + case 6: /* bdh */ + case 7: /* debye_huckel_b */ + case 8: /* dh_b */ + count_alloc = 1; + llnl_count_bdh = 0; + i = read_lines_doubles(next_char, &(llnl_bdh), &(llnl_count_bdh), &(count_alloc), opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_bdh = read_list_doubles(&ptr, &count); + llnl_count_bdh = count; + */ + break; + case 9: /* bdot */ + case 10: /* b_dot */ + count_alloc = 1; + llnl_count_bdot = 0; + i = read_lines_doubles(next_char, &(llnl_bdot), &(llnl_count_bdot), &(count_alloc), opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_bdot = read_list_doubles(&ptr, &count); + llnl_count_bdot = count; + */ + break; + case 11: /* c_co2 */ + case 12: /* co2_coefs */ + count_alloc = 1; + llnl_count_co2_coefs = 0; + i = read_lines_doubles(next_char, &(llnl_co2_coefs), &(llnl_count_co2_coefs), &(count_alloc), opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_co2_coefs = read_list_doubles(&ptr, &count); + llnl_count_co2_coefs = count; + */ + break; + } + return_value = check_line_return; + if (return_value == EOF || return_value == KEYWORD) break; + } + /* check consistency */ + if ((llnl_count_temp <= 0) || + (llnl_count_temp != llnl_count_adh) || + (llnl_count_temp != llnl_count_bdh) || + (llnl_count_temp != llnl_count_bdot) ) { + error_msg("Must define equal number (>0) of temperatures, dh_a, dh_b, and bdot parameters\nin LLNL_AQUEOUS_MODEL", CONTINUE); + input_error++; + } + if (llnl_count_co2_coefs != 5) { + error_msg("Must define 5 CO2 activity coefficient parameters in LLNL_AQUEOUS_MODEL", CONTINUE); + input_error++; + } + for (i = 1; i < llnl_count_temp; i++) { + if (llnl_temp[i-1] > llnl_temp[i]) { + error_msg("Temperatures must be in ascending order in LLNL_AQUEOUS_MODEL", CONTINUE); + input_error++; + } + } + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_lines_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc, const char **opt_list, int count_opt_list, int *opt) +/* ---------------------------------------------------------------------- */ + + { +/* + * Reads LDBLEs on line starting at next_char + * and on succeeding lines. Appends to d. + * Stops at KEYWORD, OPTION, and EOF + * + * Input Arguments: + * next_char points to line to read from + * d points to array of LDBLEs, must be malloced + * count_d number of elements in array + * count_alloc number of elements malloced + * + * Output Arguments: + * d points to array of LDBLEs, may have been + * realloced + * count_d updated number of elements in array + * count_alloc updated of elements malloced + * + * Returns: + * KEYWORD + * OPTION + * EOF + * ERROR if any errors reading LDBLEs + */ + + if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) { + return(ERROR); + } + for(;;) { + *opt = get_option(opt_list, count_opt_list, &next_char); + if (*opt == OPTION_KEYWORD || *opt == OPTION_EOF || *opt ==OPTION_ERROR) { + break; + } else if (*opt >= 0) { + break; + } + next_char = line; + if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) { + return(ERROR); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int read_line_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, n; + LDBLE value; + char token[MAX_LENGTH]; + + for (;;) { + j = copy_token(token, &next_char, &l); + if(j == EMPTY) { + break; + } + if (j != DIGIT) { + return(ERROR); + } + if (replace("*"," ",token) == TRUE) { + if (sscanf(token,"%d" SCANFORMAT, &n, &value) != 2) { + return(ERROR); + } + } else { + sscanf(token,SCANFORMAT, &value); + n = 1; + } + for (;;) { + if ((*count_d) + n > (*count_alloc)) { + *count_alloc *= 2; + *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); + if (*d == NULL ) malloc_error(); + } else { + break; + } + } + for (i = 0; i < n; i++) { + (*d)[(*count_d) + i] = value; + } + *count_d += n; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int next_keyword_or_option(const char **opt_list, int count_opt_list) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads to next keyword or option or eof + * + * Returns: + * KEYWORD + * OPTION + * EOF + */ + int opt; + char *next_char; + + for(;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_EOF) { /* end of file */ + break; + } else if (opt == OPTION_KEYWORD) { /* keyword */ + break; + } else if (opt >= 0 && opt < count_opt_list) { + break; + } else { + error_msg("Expected a keyword or option.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + return(opt); +} +/* ---------------------------------------------------------------------- */ +int read_named_logk(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads K's that can be used to calculate K's for species + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + + int j, l; + int i, empty; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "log_k", /* 0 */ + "logk", /* 1 */ + "delta_h", /* 2 */ + "deltah", /* 3 */ + "analytical_expression", /* 4 */ + "a_e", /* 5 */ + "ae", /* 6 */ + "ln_alpha1000" /* 7 */ + }; + int count_opt_list = 8; + logk_ptr = NULL; +/* + * Read name followed by options + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* log_k */ + case 1: /* logk */ + if (logk_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &logk_ptr->log_k[0]); + opt_save = OPTION_DEFAULT; + break; + case 2: /* delta_h */ + case 3: /* deltah */ + if (logk_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &logk_ptr->log_k[1], &logk_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 4: /* analytical_expression */ + case 5: /* a_e */ + case 6: /* ae */ + if (logk_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(logk_ptr->log_k[2])); + opt_save = OPTION_DEFAULT; + break; + case 7: /* ln_alpha1000 */ + if (logk_ptr == NULL) { + sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + empty = TRUE; + for (i = 2; i < 7; i++) { + if (logk_ptr->log_k[i] != 0.0) { + empty = FALSE; + logk_ptr->log_k[i] = 0.0; + } + } + if (empty == FALSE) { + sprintf(error_string, "Analytical expression previously defined for %s in NAMED_EXPRESSIONS\nAnalytical expression will be overwritten.", logk_ptr->name); + warning_msg(error_string); + } + read_analytical_expression_only(next_char, &(logk_ptr->log_k[2])); + for (i = 2; i < 7; i++) { + logk_ptr->log_k[i] /= 1000.*LOG_10; + } + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get space for logk information + */ + logk_ptr = NULL; + j = copy_token(token, &next_char, &l); + + logk_ptr = logk_store(token, TRUE); +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_copy (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, + * equilibrium_phases, + * exchange, + * surface, + * solid_solution, + * gas_phase, + * kinetics, + * mix, + * reaction, + * reaction_temperature + * + */ + int i, l, n, n_user, n_user_start, n_user_end, return_value; + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH];; +/* + * Read "copy" + */ + ptr = line; + copy_token (token, &ptr, &l); +/* + * Read keyword + */ + copy_token (token, &ptr, &l); + check_key (token); + switch (next_keyword) { + case -1: /* Have not read line with keyword */ + case 0: /* End encountered */ + case 1: /* EOF encountered */ + case 2: /* Read aqueous model */ + case 3: /* Read master species */ + case 5: + case 9: + case 10: + case 11: + case 12: + case 14: + case 15: + case 18: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 30: + case 31: + case 32: + case 34: + case 35: + case 38: + case 39: + input_error++; + error_msg("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions.", CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of use",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(ERROR); + } +/* + * Read source index + */ + strcpy(token1, token); + i = copy_token (token, &ptr, &l); + if (i == DIGIT) { + sscanf(token,"%d",&n_user); + if (n_user < 0) { + error_msg("Source index number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + if (strstr(token,"-") != NULL) { + error_msg("COPY does not accept a range of numbers for source index", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + } else { + error_msg("Source index number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Read target index or range of indices + */ + i = copy_token (token, &ptr, &l); + if (i == DIGIT) { + replace("-"," ",token); + n = sscanf(token,"%d%d",&n_user_start, &n_user_end); + if (n == 1) { + n_user_end = n_user_start; + } + if (n_user_start < 0) { + error_msg("Target index number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + } else { + error_msg("Target index number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + + switch (next_keyword) { + case 4: /* Solution */ + copier_add(©_solution, n_user, n_user_start, n_user_end); + break; + case 6: /* Pure phases */ + case 26: + case 27: + case 28: + case 29: + copier_add(©_pp_assemblage, n_user, n_user_start, n_user_end); + break; + case 7: /* Reaction */ + copier_add(©_irrev, n_user, n_user_start, n_user_end); + break; + case 8: /* Mix */ + copier_add(©_mix, n_user, n_user_start, n_user_end); + break; + case 13: /* Ex */ + copier_add(©_exchange, n_user, n_user_start, n_user_end); + break; + case 16: /* Surface */ + copier_add(©_surface, n_user, n_user_start, n_user_end); + break; + case 17: /* Temperature */ + copier_add(©_temperature, n_user, n_user_start, n_user_end); + break; + case 19: /* Gas */ + copier_add(©_gas_phase, n_user, n_user_start, n_user_end); + break; + case 33: /* Kinetics */ + copier_add(©_kinetics, n_user, n_user_start, n_user_end); + break; + case 40: /* solid_solutions */ + case 41: /* solid_solution */ + copier_add(©_s_s_assemblage, n_user, n_user_start, n_user_end); + break; + } + return_value = check_line("End of COPY",FALSE,TRUE,TRUE,TRUE); + /* empty, eof, keyword, print */ + return(return_value); +} diff --git a/readtr.cpp b/readtr.cpp new file mode 100644 index 00000000..c29afb06 --- /dev/null +++ b/readtr.cpp @@ -0,0 +1,1121 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: readtr.c 430 2005-08-22 22:53:26Z dlpark $"; + +static int read_line_LDBLEs(char *next_char, LDBLE **d, int *count_d, int *count_alloc); + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPTION_DEFAULT2 -5 + +/* ---------------------------------------------------------------------- */ +int read_transport (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads advection and column information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int i, j, l; + int old_cells, max; + int count_length, count_disp, count_punch, count_print; + int count_length_alloc, count_disp_alloc; + char token[MAX_LENGTH]; + char *description; + int n_user, n_user_end; + LDBLE *length, *disp; + int *punch_temp, *print_temp; + int return_value, opt, opt_save; + char *next_char, *next_char_save; + char file_name[MAX_LENGTH]; + + const char *opt_list[] = { + "cells", /* 0 */ + "shifts", /* 1 */ + "print", /* 2 */ + "selected_output", /* 3 */ + "bcond", /* 4 */ + "timest", /* 5 */ + "diffc", /* 6 */ + "tempr", /* 7 */ + "length", /* 8 */ + "disp", /* 9 */ + "punch", /* 10 */ + "stagnant", /* 11 */ + "bc", /* 12 */ + "boundary_conditions", /* 13 */ + "time_step", /* 14 */ + "temp_retardation_factor", /* 15 */ + "diffusion_coefficient", /* 16 */ + "dispersivity", /* 17 */ + "direction", /* 18 */ + "temperature_retardation_factor", /* 19 */ + "print_cells", /* 20 */ + "selected_cells", /* 21 */ + "flow_direction", /* 22 */ + "flow", /* 23 */ + "lengths", /* 24 */ + "dispersivities", /* 25 */ + "dump", /* 26 */ + "output", /* 27 */ + "output_frequency", /* 28 */ + "selected_output_frequency",/* 29 */ + "punch_cells", /* 30 */ + "dump_frequency", /* 31 */ + "dump_restart", /* 32 */ + "punch_frequency", /* 33 */ + "print_frequency", /* 34 */ + "correct_disp", /* 35 */ + "initial_time", /* 36 */ + "warning", /* 37 */ + "warnings", /* 38 */ + "thermal_diffusion" /* 39 */ + }; + int count_opt_list = 40; + if (svnid == NULL) fprintf(stderr," "); + + + strcpy(file_name, "phreeqc.dmp"); +/* + * Initialize + */ + simul_tr++; + if (simul_tr == 1) { + correct_disp = FALSE; + old_cells = 0; + } else { + old_cells = count_cells; + } + count_length = count_disp = count_punch = count_print = 0; + length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (length == NULL) malloc_error(); + disp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (disp == NULL) malloc_error(); + punch_temp = (int *) PHRQ_malloc(sizeof(int)); + if (punch_temp == NULL) malloc_error(); + print_temp = (int *) PHRQ_malloc(sizeof(int)); + if (print_temp == NULL) malloc_error(); + count_length_alloc = count_disp_alloc = 1; + transport_start = 1; +/* + * Read transport number (not currently used) + */ + ptr=line; + read_number_description (ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); +/* + * Set use data to last read + */ + use.trans_in = TRUE; + +/* + * Read lines + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) { + opt = opt_save; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + case OPTION_DEFAULT: + input_error++; + error_msg("Unknown input in TRANSPORT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* cells */ + sscanf(next_char, "%d", &count_cells); + opt_save = OPTION_DEFAULT; + break; + case 1: /* shifts */ + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &count_shifts); + } else { + warning_msg("Expected the number of shifts. One shift is assumed."); + count_shifts = 1; + } + j = copy_token(token, &next_char, &l); + if (j != EMPTY) { + if (j == DIGIT) { + sscanf(token, "%d", &ishift); + } else { + input_error++; + error_msg("Expected shift direction, -1, 0, 1. Use -direction instead.", CONTINUE); + ishift = 1; + } + } + opt_save = OPTION_DEFAULT; + break; + case 2: /* print */ + case 20: /* print_cells */ + print_temp = read_list_ints_range (&next_char, &count_print, TRUE, print_temp); +#ifdef SKIP + while (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &l); + print_temp = PHRQ_realloc(print_temp, (size_t) (count_print + 1) * sizeof(LDBLE)); + if (print_temp == NULL) malloc_error(); + print_temp[count_print] = l; + count_print++; + } +#endif + opt_save = 2; + break; + case 3: /* selected_output */ + case 29: /* selected_output_frequency */ + case 33: /* punch_frequency */ + sscanf(next_char, "%d", &punch_modulus); + opt_save = OPTION_DEFAULT; + break; + case 4: /* bcond */ + case 12: /* bc */ + case 13: /* boundary_conditions */ + /* first cell boundary condition */ + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) { + sscanf(token, "%d", &bcon_first); + if (bcon_first < 1 || bcon_first > 3) { + input_error++; + error_msg("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", CONTINUE); + } + } else if (i == EMPTY) { + bcon_first = 3; + } else if (strstr(token, "co") == token) { + bcon_first = 1; + } else if (strstr(token, "cl") == token) { + bcon_first = 2; + } else if (strstr(token, "f") == token) { + bcon_first = 3; + } else { + input_error++; + error_msg("Expected boundary condition to be 'constant', 'closed', or 'flux'.", CONTINUE); + } + + /* last cell boundary condition */ + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) { + sscanf(token, "%d", &bcon_last); + if (bcon_last < 1 || bcon_last > 3) { + input_error++; + error_msg("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", CONTINUE); + } + } else if (i == EMPTY) { + bcon_last = 3; + } else if (strstr(token, "co") == token) { + bcon_last = 1; + } else if (strstr(token, "cl") == token) { + bcon_last = 2; + } else if (strstr(token, "f") == token) { + bcon_last = 3; + } else { + input_error++; + error_msg("Expected boundary condition to be 'constant', 'closed', or 'flux'.", CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; + case 5: /* timest */ + case 14: /* time_step */ + sscanf(next_char, SCANFORMAT, ×t); + opt_save = OPTION_DEFAULT; + break; + case 6: /* diffc */ + case 16: /* diffusion_coefficient */ + sscanf(next_char, SCANFORMAT, &diffc); + opt_save = OPTION_DEFAULT; + break; + case 7: /* tempr */ + case 15: /* temp_retardation_factor */ + case 19: /* temperature_retardation_factor */ + case 39: /* thermal_diffusion */ + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, SCANFORMAT, &tempr); + } + if (tempr < 1) { + tempr = 1; + warning_msg("Temperature retardation factor < 1 is not possible.\n" + "Temperature retardation factor = 1 assumed."); + } + j = copy_token(token, &next_char, &l); + if (j == DIGIT) { + sscanf(token, SCANFORMAT, &heat_diffc); + } + opt_save = OPTION_DEFAULT; + break; + case 8: /* length */ + case 24: /* lengths */ + if (read_line_LDBLEs(next_char, &length, &count_length, &count_length_alloc) == ERROR) { + input_error++; + error_msg("Reading lengths in TRANSPORT keyword.\n", CONTINUE); + } + opt_save = 8; + break; + case 9: /* disp */ + case 17: /* dispersivity */ + case 25: /* dispersivities */ + if (read_line_LDBLEs(next_char, &disp, &count_disp, &count_disp_alloc) == ERROR) { + input_error++; + error_msg("Reading dispersivities in TRANSPORT keyword.\n", CONTINUE); + } + opt_save = 9; + break; + case 10: /* punch */ + case 21: /* selected_cells */ + case 30: /* punch_cells */ + punch_temp = read_list_ints_range (&next_char, &count_punch, TRUE, punch_temp); +#ifdef SKIP + while (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &l); + punch_temp = PHRQ_realloc(punch_temp, (size_t) (count_punch + 1) * sizeof(LDBLE)); + if (punch_temp == NULL) malloc_error(); + punch_temp[count_punch] = l; + count_punch++; + } +#endif + opt_save = 10; + break; + case 11: /* stagnant */ +/* !!!!! sscanf(next_char, "%d", &count_stag); + */ + if (copy_token(token, &next_char, &l) != EMPTY) { + + /* exchange factor */ + if (sscanf(token, "%d", &(stag_data->count_stag)) != 1) { + input_error++; + sprintf(error_string,"Expecting number of stagnant layers."); + error_msg(error_string, CONTINUE); + break; + } + + /* exchange factor */ + j = copy_token(token, &next_char, &l); + if (j != EMPTY) { + if (sscanf(token, SCANFORMAT, &(stag_data->exch_f)) != 1) { + input_error++; + sprintf(error_string,"Expecting exchange factor for stagnant layers."); + error_msg(error_string, CONTINUE); + break; + } + copy_token(token, &next_char, &l); + if (sscanf(token, SCANFORMAT, &(stag_data->th_m)) != 1) { + input_error++; + sprintf(error_string,"Expecting porosity in the mobile zone."); + error_msg(error_string, CONTINUE); + break; + } + copy_token(token, &next_char, &l); + if (sscanf(token, SCANFORMAT, &(stag_data->th_im)) != 1) { + input_error++; + sprintf(error_string,"Expecting porosity in the immobile zone."); + error_msg(error_string, CONTINUE); + break; + } + } + } + opt_save = OPTION_DEFAULT; + break; + case 18: /* direction */ + case 22: /* flow_direction */ + case 23: /* flow */ + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "f") == token) { + ishift = 1; + } else if (strstr(token, "b") == token) { + ishift = -1; + } else if (strstr(token, "d") == token) { + ishift = 0; + } else if (strstr(token, "n") == token) { + ishift = 0; + } else { + input_error++; + error_msg("Expected flow direction to be 'forward', 'back', or 'no_flow'.", CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; + case 26: /* dump */ + dump_in = TRUE; + next_char_save = next_char; + if (copy_token(file_name, &next_char, &l) == EMPTY) { + strcpy(file_name, "phreeqc.dmp"); + } else { + string_trim(next_char_save); + strcpy(file_name, next_char_save); + } +#ifdef SKIP + + /* Can not define dump_modulus an transport_start here */ + + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &dump_modulus); + } + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &transport_start); + } +#endif + opt_save = OPTION_DEFAULT; + break; + case 27: /* output */ + case 28: /* output_frequency */ + case 34: /* print_frequency */ + sscanf(next_char, "%d", &print_modulus); + opt_save = OPTION_DEFAULT; + break; + case 31: /* dump_frequency */ + dump_in = TRUE; + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &dump_modulus); + } else { + warning_msg("Expected integer value for dump_frequency."); + dump_modulus = 0; + } + opt_save = OPTION_DEFAULT; + break; + case 32: /* dump_restart */ + dump_in = TRUE; + if (copy_token(token, &next_char, &l) == DIGIT) { + sscanf(token, "%d", &transport_start); + } else { + warning_msg("Expected shift number to start calculations, 1 will be used."); + transport_start = 1; + } + opt_save = OPTION_DEFAULT; + break; + case 35: /* correct_dispersion */ + correct_disp = get_true_false(next_char, TRUE); + opt_save = OPTION_DEFAULT; + break; + case 36: /* initial_time */ + sscanf(next_char, SCANFORMAT, &initial_total_time); + opt_save = OPTION_DEFAULT; + break; + case 37: /* warning */ + case 38: /* warnings */ + transport_warnings = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* + * Determine number of cells + */ + max = count_cells; + if (count_length > max) max = count_length; + if (count_disp > max) max = count_disp; + if (max > count_cells) { + if (max == count_length) { + sprintf(token,"Number of cells is increased to number of 'lengths' %d.", count_length); + warning_msg(token); + } else { + sprintf(token,"Number of cells is increased to number of dispersivities %d.", count_disp); + warning_msg(token); + } + } +/* + * Allocate space for cell_data + */ + cell_data = (struct cell_data *)PHRQ_realloc(cell_data, (size_t)(max * (1 + stag_data->count_stag) + 1)*sizeof(struct cell_data)); + if (cell_data == NULL) malloc_error(); +/* + * Fill in data for lengths + */ + if (count_length == 0) { + if (old_cells < max) { + sprintf(error_string,"No cell-lengths were read; length = 1 m assumed."); + warning_msg(error_string); + for (i = 0; i < max; i++) cell_data[i].length = 1.0; + } + } else { + for (i = 0; i < count_length; i++) { + cell_data[i].length = length[i]; + } + if (max > count_length) { + sprintf(error_string,"Cell-lengths were read for %d cells. Last value is used till cell %d.", count_length, max); + warning_msg(error_string); + for (i = count_length - 1; i < max; i++) { + cell_data[i].length = length[count_length - 1]; + } + } + } + cell_data[0].mid_cell_x = cell_data[0].length / 2; + for (i = 1; i < max; i++) { + cell_data[i].mid_cell_x = cell_data[i-1].mid_cell_x + + (cell_data[i-1].length + cell_data[i].length)/2; + } + cell_data[max].mid_cell_x = cell_data[max-1].mid_cell_x + cell_data[max-1].length; +/* + * Fill in data for dispersivities + */ + if (count_disp == 0) { + if (old_cells < max) { + sprintf(error_string,"No dispersivities were read; disp = 0 assumed."); + warning_msg(error_string); + for (i = 0; i < max; i++) cell_data[i].disp = 0.0; + } + } else { + for (i = 0; i < count_disp; i++) { + cell_data[i].disp = disp[i]; + } + if (max > count_disp) { + sprintf(error_string,"Dispersivities were read for %d cells. Last value is used till cell %d.", count_disp, max); + warning_msg(error_string); + for (i = count_disp - 1; i < max; i++) { + cell_data[i].disp = disp[count_disp - 1]; + } + } + } + + count_cells = max; + +/* + * Account for stagnant cells + */ + if (stag_data->count_stag > 0) { + max = count_cells * (1 + stag_data->count_stag) + 1; + for (i = 0; i < count_cells; i++) { + for (l = 1; l <= stag_data->count_stag; l++) { + cell_data [ i+1+l*count_cells ] .mid_cell_x = cell_data[i].mid_cell_x; + } + } + } +/* + * Fill in data for punch + */ + if (count_punch != 0) { + for (i=0; i max || punch_temp[i] < 1) { + sprintf(error_string,"Cell number for punch is out of range, %d. Request ignored.", punch_temp[i]); + warning_msg(error_string); + } else { + cell_data[punch_temp[i]-1].punch = TRUE; + } + } + } else if (simul_tr == 1) { + for (i=0; i max || print_temp[i] < 1) { + sprintf(error_string,"Cell number for print is out of range, %d. Request ignored.", print_temp[i]); + warning_msg(error_string); + } else { + cell_data[print_temp[i]-1].print = TRUE; + } + } + } else if (simul_tr == 1) { + for (i=0; i count_shifts) { + input_error++; + sprintf(error_string,"Starting shift for transport, %d, is greater than number of shifts, %d.", transport_start, count_shifts); + error_msg(error_string, CONTINUE); + } + } +/* + * Check boundary conditions + */ + if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) { + warning_msg("Boundary condition = 'closed' not possible with advective transport.\n\t Boundary condition = 'flux' assumed."); + if (bcon_first == 2) bcon_first =3; + if (bcon_last == 2) bcon_last =3; + } +/* + * Retain data from previous run + */ + if (simul_tr > 1) { + if ((count_length == 0) && (count_disp == 0)) { + dup_print("Column data retained from former run", TRUE); + } + } +/* + * Check heat_diffc + */ + if (heat_diffc < 0) { + heat_diffc = diffc; + } else if (stag_data->count_stag == 1) { + if (stag_data->exch_f > 0) { + if (diffc <= 0 && heat_diffc > 0) { + input_error++; + sprintf(error_string,"Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } else if (heat_diffc > diffc) { + sprintf(error_string,"Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", (double) diffc); + warning_msg(error_string); + } + } else { + if (heat_diffc > diffc) { + input_error++; + sprintf(error_string,"Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } + } + } else if (stag_data->count_stag > 1 && heat_diffc > diffc) { + input_error++; + sprintf(error_string,"Only one stagant layer permitted (-stag) when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } + +/* + * free storage for length, disp, punch + */ + length = (LDBLE *) free_check_null(length); + disp = (LDBLE *) free_check_null(disp); + punch_temp = (int *) free_check_null(punch_temp); + print_temp = (int *) free_check_null(print_temp); + + if (dump_in == TRUE) { + if(output_open(OUTPUT_DUMP, file_name) != OK) { + sprintf(error_string, "Can't open file, %s.", file_name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int read_line_LDBLEs(char *next_char, LDBLE **d, int *count_d, int *count_alloc) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, n; + LDBLE value; + char token[MAX_LENGTH]; + + for (;;) { + j = copy_token(token, &next_char, &l); + if(j == EMPTY) { + break; + } + if (j != DIGIT) { + return(ERROR); + } + if (replace("*"," ",token) == TRUE) { + if (sscanf(token,"%d" SCANFORMAT, &n, &value) != 2) { + return(ERROR); + } + } else { + sscanf(token,SCANFORMAT, &value); + n = 1; + } + for (;;) { + if ((*count_d) + n > (*count_alloc)) { + *count_alloc *= 2; + *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); + if (*d == NULL ) malloc_error(); + } else { + break; + } + } + for (i = 0; i < n; i++) { + (*d)[(*count_d) + i] = value; + } + *count_d += n; + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int dump(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * dumps solution compositions to file + */ + + int i, j, k, l; + + if (dump_in == FALSE || pr.dump == FALSE) return(OK); + output_rewind(OUTPUT_DUMP); + output_msg(OUTPUT_DUMP, "# Dumpfile\n# Transport simulation %d. Shift %d.\n#\n", simul_tr, transport_step); + + for (k = 0; k <= 1 + (1 + stag_data->count_stag) * count_cells; k++) { + dump_reaction(k); + dump_kinetics(k); + output_msg(OUTPUT_DUMP, "END\n"); + dump_solution(k); + dump_pp_assemblage(k); + dump_exchange(k); + dump_surface(k); + dump_gas_phase(k); + dump_s_s_assemblage(k); + output_msg(OUTPUT_DUMP, "END\n"); + } + + output_msg(OUTPUT_DUMP, "KNOBS\n"); + output_msg(OUTPUT_DUMP, "\t-iter%15d\n", itmax); + output_msg(OUTPUT_DUMP, "\t-tol %15.3e\n", (double) ineq_tol); + output_msg(OUTPUT_DUMP, "\t-step%15.3e\n", (double) step_size); + output_msg(OUTPUT_DUMP, "\t-pe_s%15.3e\n", (double) pe_step_size); + output_msg(OUTPUT_DUMP, "\t-diag "); + if (diagonal_scale == TRUE) output_msg(OUTPUT_DUMP, "true\n"); + else output_msg(OUTPUT_DUMP, "false\n"); + + output_msg(OUTPUT_DUMP, "SELECTED_OUTPUT\n"); + output_msg(OUTPUT_DUMP, "\t-file %-15s\n", "sel_o$$$.prn"); + if (punch.count_totals != 0) { + output_msg(OUTPUT_DUMP, "\t-tot "); + for (i = 0; i < punch.count_totals; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.totals[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_molalities != 0) { + output_msg(OUTPUT_DUMP, "\t-mol "); + for (i = 0; i < punch.count_molalities; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.molalities[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_activities != 0) { + output_msg(OUTPUT_DUMP, "\t-act "); + for (i = 0; i < punch.count_activities; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.activities[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_pure_phases != 0) { + output_msg(OUTPUT_DUMP, "\t-equ "); + for (i = 0; i < punch.count_pure_phases; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.pure_phases[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_si != 0) { + output_msg(OUTPUT_DUMP, "\t-si "); + for (i = 0; i < punch.count_si; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.si[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_gases != 0) { + output_msg(OUTPUT_DUMP, "\t-gas "); + for (i = 0; i < punch.count_gases; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.gases[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_s_s != 0) { + output_msg(OUTPUT_DUMP, "\t-solid_solutions "); + for (i = 0; i < punch.count_s_s; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.s_s[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + if (punch.count_kinetics != 0) { + output_msg(OUTPUT_DUMP, "\t-kin "); + for (i = 0; i < punch.count_kinetics; i++) { + output_msg(OUTPUT_DUMP, " %s", punch.kinetics[i].name); + } + output_msg(OUTPUT_DUMP, "\n"); + } + output_msg(OUTPUT_DUMP, "TRANSPORT\n"); + output_msg(OUTPUT_DUMP, "\t-cells %6d\n", count_cells); + output_msg(OUTPUT_DUMP, "\t-shifts%6d%6d\n", count_shifts, ishift); + output_msg(OUTPUT_DUMP, "\t-output_frequency %6d\n", print_modulus); + output_msg(OUTPUT_DUMP, "\t-selected_output_frequency %6d\n", punch_modulus); + output_msg(OUTPUT_DUMP, "\t-bcon %6d%6d\n", bcon_first, bcon_last); + output_msg(OUTPUT_DUMP, "\t-timest %13.5e\n", (double) timest); + output_msg(OUTPUT_DUMP, "\t-diffc %13.5e\n", (double) diffc); + output_msg(OUTPUT_DUMP, "\t-tempr %13.5e\n", (double) tempr); + if (correct_disp == TRUE) { + output_msg(OUTPUT_DUMP, "\t-correct_disp %s\n", "True"); + } else { + output_msg(OUTPUT_DUMP, "\t-correct_disp %s\n", "False"); + } + output_msg(OUTPUT_DUMP, "\t-length\n"); + for (i = 0; i < count_cells; i++) { + output_msg(OUTPUT_DUMP, "%12.3e", (double) cell_data[i].length); + if (i > 0 && (i % 8 ) == 0) output_msg(OUTPUT_DUMP, "\n"); + } + output_msg(OUTPUT_DUMP, "\n"); + output_msg(OUTPUT_DUMP, "\t-disp\n"); + for (i = 0; i < count_cells; i++) { + output_msg(OUTPUT_DUMP, "%12.3e", (double) cell_data[i].disp); + if (i > 0 && (i % 8 ) == 0) output_msg(OUTPUT_DUMP, "\n"); + } + output_msg(OUTPUT_DUMP, "\n"); + output_msg(OUTPUT_DUMP, "\t-punch_cells"); + if (stag_data->count_stag > 0) j = 1 + (1 + stag_data->count_stag) * count_cells; + else j = count_cells; + l = 0; + for (i = 0; i < j; i++) { + if (cell_data[i].punch != TRUE) continue; + output_msg(OUTPUT_DUMP, " %d", i+1); + l++; + if ((l % 20) == 0) output_msg(OUTPUT_DUMP, "\n"); + } + output_msg(OUTPUT_DUMP, "\n"); + output_msg(OUTPUT_DUMP, "\t-print_cells"); + if (stag_data->count_stag > 0) j = 1 + (1 + stag_data->count_stag) * count_cells; + else j = count_cells; + l = 0; + for (i = 0; i < j; i++) { + if (cell_data[i].print != TRUE) continue; + output_msg(OUTPUT_DUMP, " %d", i+1); + l++; + if ((l % 20) == 0) output_msg(OUTPUT_DUMP, "\n"); + } + output_msg(OUTPUT_DUMP, "\n"); + output_msg(OUTPUT_DUMP, "\t-dump $$$.dmp\n"); + output_msg(OUTPUT_DUMP, "\t-dump_frequency %d\n", dump_modulus); + output_msg(OUTPUT_DUMP, "\t-dump_restart %d\n", transport_step + 1); + + output_msg(OUTPUT_DUMP, "END\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_exchange(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print moles of each exchange species + */ + int i, j, n; + struct exchange *exchange_ptr; + + exchange_ptr = exchange_bsearch(k, &n); + if ( exchange_ptr == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "EXCHANGE %d\n", k); +#ifdef SKIP + for (i = 0; i < exchange[n].count_comps; i++) { + output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].formula); + if (exchange[n].comps[i].phase_name != NULL) { + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", + exchange[n].comps[i].phase_name, + exchange[n].comps[i].phase_proportion); + } else { + for (j = 0; exchange[n].comps[i].totals[j].elt != NULL; j++) { + if (strcmp(exchange_ptr->comps[i].totals[j].elt->name, exchange[n].comps[i].formula) == NULL) { + output_msg(OUTPUT_DUMP, "%15.6e\n", exchange[n].comps[i].totals[j].coef); + } + } + } + } +#endif + for (i = 0; i < exchange[n].count_comps; i++) { + if (exchange[n].comps[i].phase_name != NULL) { + output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].formula); + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", + exchange[n].comps[i].phase_name, + (double) exchange[n].comps[i].phase_proportion); + } else { + for (j = 0; exchange[n].comps[i].totals[j].elt != NULL; j++) { +/* if (exchange_ptr->comps[i].totals[j].elt->master->type != EX) continue; */ + output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].totals[j].elt->name); + output_msg(OUTPUT_DUMP, "%15.6e", (double) exchange[n].comps[i].totals[j].coef); + + if (exchange[n].comps[i].rate_name != NULL) { + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", exchange[n].comps[i].rate_name, (double) exchange[n].comps[i].phase_proportion); + } +#ifdef SKIP + for (l = 0; l < count_kin_exch; l++) { + if (strcmp_nocase(kin_exch[l].exch_name, exchange[n].comps[i].totals[j].elt->name) != 0) continue; + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", kin_exch[l].phase_name, kin_exch[l].phase_proportion); + } +#endif + output_msg(OUTPUT_DUMP, "\n"); + } + } + } + output_msg(OUTPUT_DUMP, "\t-equil %d\n", k); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_pp_assemblage(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices and masses of pure_phases in pp_assemblage + */ + int j, n; + + if (pp_assemblage_search(k, &n) == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "EQUILIBRIUM_PHASES %d\n", k); + for (j = 0; j < pp_assemblage[n].count_comps; j++) { + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", + pp_assemblage[n].pure_phases[j].name, + (double) pp_assemblage[n].pure_phases[j].si); + + if (pp_assemblage[n].pure_phases[j].add_formula == NULL) { + output_msg(OUTPUT_DUMP, "%15.6e", + (double) pp_assemblage[n].pure_phases[j].moles); + } else { + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", + pp_assemblage[n].pure_phases[j].add_formula, + (double) pp_assemblage[n].pure_phases[j].moles); + } + output_msg(OUTPUT_DUMP, "\n"); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_reaction (int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps reaction data + */ + int i; + struct irrev *irrev_ptr; + + if ((irrev_ptr = irrev_search(k, &i)) == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "REACTION %d\n", k); + for (i = 0; i < irrev_ptr->count_list; i++) { + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", + irrev_ptr->list[i].name, + (double) irrev_ptr->list[i].coef); + } + if (irrev_ptr->count_steps >= 1) { + for (i = 0; i < irrev_ptr->count_steps; i++) + output_msg(OUTPUT_DUMP, "%15.6e", (double) irrev_ptr->steps[i]); + } else { + output_msg(OUTPUT_DUMP, "\t%15.6e in %d step", + (double) irrev_ptr->steps[0], + - irrev_ptr->count_steps); + } + output_msg(OUTPUT_DUMP, "\n"); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_surface(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print moles of each surface master species + */ + int i, j, l, n; + struct surface *surface_ptr; + + if ((surface_ptr = surface_bsearch(k, &n)) == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "SURFACE %d\n", k); + for (i = 0; i < surface[n].count_comps; i++) { + for (j = 0; surface[n].comps[i].totals[j].elt != NULL; j++) { + if (surface_ptr->comps[i].totals[j].elt->master->type != SURF) continue; + output_msg(OUTPUT_DUMP, "\t%-13s", surface[n].comps[i].totals[j].elt->name); + + if (surface[n].comps[i].phase_name != NULL) { + output_msg(OUTPUT_DUMP, "\t%-13s equi %13.5e", + surface[n].comps[i].phase_name, + (double) surface[n].comps[i].phase_proportion); + } else if (surface[n].comps[i].rate_name != NULL) { + output_msg(OUTPUT_DUMP, "\t%-13s kine %13.5e", + surface[n].comps[i].rate_name, + (double) surface[n].comps[i].phase_proportion); + } else { + output_msg(OUTPUT_DUMP, "\t%13.5e", (double) surface[n].comps[i].totals[j].coef); +#ifdef SKIP + for (l = 0; l < count_kin_surf; l++) { + if (strcmp_nocase(kin_surf[l].surf_name, surface[n].comps[i].totals[j].elt->name) != 0) continue; + output_msg(OUTPUT_DUMP, "\t%-13s %13.5e", kin_surf[l].phase_name, kin_surf[l].phase_proportion); + } +#endif + } + if (surface[n].edl == TRUE) { + l = surface[n].comps[i].charge; + output_msg(OUTPUT_DUMP, " %13.5e", (double) surface[n].charge[l].specific_area); + if (surface[n].comps[i].phase_name == NULL && surface[n].comps[i].rate_name == NULL) { + output_msg(OUTPUT_DUMP, " %13.5e\n", (double) surface[n].charge[l].grams); + } else output_msg(OUTPUT_DUMP, "\n"); + } else output_msg(OUTPUT_DUMP, "\n"); + } + } + if (surface[n].diffuse_layer == TRUE) { + output_msg(OUTPUT_DUMP, "\t-diffuse\t%13.5e\n", (double) surface[n].thickness); + } else if (surface[n].edl == FALSE) { + output_msg(OUTPUT_DUMP, "\t-no_edl\n"); + } + + + output_msg(OUTPUT_DUMP, "\t-equil %d\n", k); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_gas_phase(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps gas phase data + */ + int i, n; + LDBLE lp; + struct rxn_token *rxn_ptr; + struct gas_phase *gas_phase_ptr; + + if ((gas_phase_ptr = gas_phase_bsearch(k, &n)) == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "GAS_PHASE %d\n", k); + output_msg(OUTPUT_DUMP, "\t-pressure%15.6e\n", (double) gas_phase[n].total_p); + output_msg(OUTPUT_DUMP, "\t-volume%15.6e\n", (double) gas_phase[n].volume); + output_msg(OUTPUT_DUMP, "\t-temperature%15.6e\n", (double) gas_phase[n].temperature); + for (i = 0; i < gas_phase[n].count_comps; i++) { +/* + * Calculate partial pressure + */ + lp=-gas_phase_ptr->comps[i].phase->lk; + if (use.gas_phase_ptr->comps[i].phase->rxn_x != NULL) { + for (rxn_ptr = use.gas_phase_ptr->comps[i].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + } else { + lp = -99.9; + } + output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", + gas_phase[n].comps[i].name, + (double) lp); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_s_s_assemblage(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps solid solution data + */ + int i, j, n; + struct s_s_assemblage *s_s_assemblage_ptr; + + s_s_assemblage_ptr = s_s_assemblage_bsearch(k, &n); + if (s_s_assemblage_ptr == NULL) return(OK); + + output_msg(OUTPUT_DUMP, "SOLID_SOLUTIONS %d\n", k); + for (i = 0; i < s_s_assemblage[n].count_s_s; i++) { + output_msg(OUTPUT_DUMP, "\t%-15s\n", s_s_assemblage[n].s_s[i].name); + for (j = 0; j < s_s_assemblage[n].s_s[i].count_comps; j++) { + output_msg(OUTPUT_DUMP, "\t\t-comp\t%-15s%15.6e\n", + s_s_assemblage[n].s_s[i].comps[j].name, + (double) s_s_assemblage[n].s_s[i].comps[j].moles); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_kinetics (int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps kinetics data + */ + int i, j, n; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + + if ((kinetics_ptr = kinetics_search(k, &n, FALSE)) == NULL) return(OK); + output_msg(OUTPUT_DUMP, "KINETICS %d\n", k); + for (i = 0; i < kinetics[n].count_comps; i++) { + output_msg(OUTPUT_DUMP, "%-15s\n", kinetics_ptr->comps[i].rate_name); + + kinetics_comp_ptr = &kinetics_ptr->comps[i]; + output_msg(OUTPUT_DUMP, "\t-formula "); + for (j = 0; j < kinetics_comp_ptr->count_list; j++) { + output_msg(OUTPUT_DUMP, " %s %12.3e", kinetics_comp_ptr->list[j].name, (double) kinetics_comp_ptr->list[j].coef); + } + output_msg(OUTPUT_DUMP, "\n"); + + output_msg(OUTPUT_DUMP, "\t-tol %15.2e\n", (double) kinetics_ptr->comps[i].tol); + output_msg(OUTPUT_DUMP, "\t-m0 %15.6e\n", (double) kinetics_ptr->comps[i].m0); + output_msg(OUTPUT_DUMP, "\t-m %15.6e\n", (double) kinetics_ptr->comps[i].m); + + if (kinetics_comp_ptr->count_d_params != 0) { + output_msg(OUTPUT_DUMP, "\t-parm"); + for (j = 0; j < kinetics_comp_ptr->count_d_params; j++) { + output_msg(OUTPUT_DUMP, "%15.6e", (double) kinetics_comp_ptr->d_params[j]); + } + output_msg(OUTPUT_DUMP, "\n"); + } + +/* not dumped: kinetics_comp_ptr->count_c_params = 0 */ + } + output_msg(OUTPUT_DUMP, "\t-step_divide %15.6e\n", (double) kinetics[n].step_divide); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_solution (int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps solution data + */ + int i, j; + struct solution *solution_ptr; + + solution_ptr = solution_bsearch(k, &j, TRUE); + if (solution_ptr != NULL) { + output_msg(OUTPUT_DUMP, "SOLUTION %d\n", k); + output_msg(OUTPUT_DUMP, "\tunits mol/kgw\n"); + output_msg(OUTPUT_DUMP, "\ttemp %5.1f\n", (double) solution_ptr->tc); + output_msg(OUTPUT_DUMP, "\tpH %9.5f\n", (double) solution_ptr->ph); + output_msg(OUTPUT_DUMP, "\tpe %9.5f\n", (double) solution_ptr->solution_pe); + output_msg(OUTPUT_DUMP, "\twater %9.5f\n", (double) solution_ptr->mass_water); + for (i = 0; solution_ptr->totals[i].description != NULL; i++) { + /* + * write out totals... + */ + output_msg(OUTPUT_DUMP, "\t%-6s", solution_ptr->totals[i].description); + output_msg(OUTPUT_DUMP, " %13.5e\n", (double) (solution_ptr->totals[i].moles/solution_ptr->mass_water)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int dump_mix (int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Dumps solution data + */ + int j; + struct mix *mix_ptr; + + mix_ptr = mix_bsearch(k, &j); + if (mix_ptr == NULL) return(ERROR); + for (j = 0; j < mix_ptr->count_comps; j++) { + dump_solution(mix_ptr->comps[j].n_solution); + } + output_msg(OUTPUT_DUMP, "MIX %d\n", k); + for (j = 0; j < mix_ptr->count_comps; j++) { + output_msg(OUTPUT_DUMP, "\t5%d\t%13.5e\n", mix_ptr->comps[j].n_solution, (double) mix_ptr->comps[j].fraction); + } + return(OK); +} diff --git a/revisions b/revisions new file mode 100644 index 00000000..821702ef --- /dev/null +++ b/revisions @@ -0,0 +1,1401 @@ +------------------------------------------------------------ +Features not documented in WRIR 99-4259. +------------------------------------------------------------ + + svn 675: + Added PRINT option to print the species that contribute + to alkalinity. Alkalinity distribution is printed in + the output file following the distribution of species. + Default at program startup is false. + + PRINT + -alkalinity true + +------------------------------------------------------------ +Version 2.12: +------------------------------------------------------------ + +* Made aqueous activity coefficients the default activity + coefficients for exchange species when using the + Pitzer formulation. New option in EXCHANGE is + -pitzer_exchange_gammas T/F, default is true; + defining "false" sets exchange activity coefficients + to 1.0. Option has no effect for ion-association + model (non-Pitzer). + + +* Added multiplier format to REACTION steps and KINETICS steps, + which simplifies definition of multiple equal reaction increments. + + This definition: + + INCREMENTAL_REACTIONS true + REACTION + H2O 1 + -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles + + is equivalent to this definition: + + INCREMENTAL_REACTIONS true + REACTION + H2O 1 + -36 -4 -4 -4 -.25 -.25 -0.19 -0.1 -0.1 -0.1 + -0.1 -0.05 -0.05 -0.05 moles + + + +* Added Pitzer activity formulation. Use pitzer.dat database + to invoke the Pitzer model. Should have same capabilities + as ion-association model except explicit diffuse layer + calculation is not implemented with the Pitzer model. + New keyword is PITZER with following options: + + PITZER + -MacInnes T/F # uses MacInnes assumption or unscaled for + # individual activities and activity coefficients + -B0 + Na+ Cl- 0.0765 -777.03 -4.4706 0.008946 -3.3158E-6 + -B1 + Na+ Cl- 0.2664 0 0 6.1608E-5 1.0715E-6 + -B2 + Mg+2 SO4-2 -37.23 0 0 -0.253 + -C0 + Na+ Cl- 0.00127 33.317 0.09421 -4.655E-5 + -THETA + K+ Na+ -0.012 + -LAMDA + Na+ CO2 0.1 + -ZETA + H+ Cl- B(OH)3 -0.0102 + -PSI + Na+ K+ Cl- -0.0018 + + A five-term expression for temperature dependence is available + for all Pitzer parameter values: + P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3/(TK-TR) + + A4*(TK*TK - TR*TR), + where TK is Kelvin and TR is 298.15. + +* Cl1mp is a new multiple precision version of routine cl1, + a simplex-based optimization routine. Cl1mp was develeped + by using the Gnu Multiple Precision package (gmp). + Calculations are carried out to about 30 significant + digits. Cl1mp may help in some situations where roundoff + errors are a problem, but it is still possible that roundoff + errors will cause cl1mp to fail to find a solution to an + optimization problem. The mp version has the following + options in INVERSE_MODELING: + + -multiple_precision T/F--causes the mp version + to be used in inverse modeling calculations. + -mp_tolerance 1e-12--tolerance for mp version of + cl1. As in cl1, numbers less than the + tolerance are considered to be zero. + 1e-12 is the default. + -censor_mp 1e-20--as calculations occur in the + linear equation array, elements less + than this value are set to zero. Default + is 1e-20. A value of 0.0 causes no + censoring to occur. + +------------------------------------------------------------ +Version 2.11: +------------------------------------------------------------ + +* A new database, minteq.v4.dat, has been translated from + version 4.02 of MINTEQA2 and is included in all + distributions. The database minteq.dat from earlier + version of MINTEQA2 has been slightly revised and is + also included. + +------------------------------------------------------------ +Version 2.10: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.9: +------------------------------------------------------------ +* Added new keyword COPY that allows a data entity + to be copied from one index to a new index + or to a range of indicies. Format is + + COPY keyword index index_start[-index_end] + + where keyword may be SOLUTION + EQUILIBRIUM_PHASES + EXCHANGE + GAS_PHASE + KINETICS + MIX + REACTION + REACTION_TEMPERATURE + SOLID_SOLUTION + SURFACE + +* Added new Basic functions + b$ = PAD(a$, 20) pads a$ to a total of 20 characters + with spaces and stores result in b$. PAD returns + a copy of a$ if a$ is more than 20 characters. + i = INSTR(a$, b$) sets i to the character position of + string b$ in a$, 0 in not found. + b$ = LTRIM(a$) trims white space from beginning of + string a$ and stores result in b$. + b$ = RTRIM(a$) trims white space from end of string + a$ and stores result in b$. + b$ = TRIM(a$) trims white space from beginning and + end of string a$ and stores result in b$. + + +* Added new Basic function SYS that calculates the to + total amount of an element in all phases (solution, + equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase). KINETIC reactions are not included. + The function has two forms: (1) one element name as an + argument (variable names are user specified) + + 10 t = SYS("As") + + the function will return the total arsenic in the system. + (2) 5 argumens + + 10 t = SYS("As", count_species, names$, types$, moles) + + will return the total arsenic in the system to tot; count_species-- + the number of species that contain arsenic, including + solution, equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase species; names$--a character array that has the + name of each species; type$--a character array that specifies the + type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. + Diff refers to the amount of the element in the diffuse layer of + a surface when the explicit diffuse layer calculation is used; + moles--an array containing the number of moles of the element in + the species. The sum of moles(i) is equal to tot. + + SYS has several special arguments for the form + SYS("arg", count, names$, types$, values) + arg is one of the options listed below. + count is a single numeric value and is the number of elements + in the following arrays. + name$ is an array of string values. + type$ is an array of string values. + values is an array of numeric values. + + Values of arg: + + elt_name returns total number of moles of element in system. + count is the number of species for the element in + the system, including aqueous, exchange, surface, + equilibrium_phase, solid solution component, and + gas phase "species". + Arrays are filled for each "species"; values are moles. + "elements" returns total number of moles of dissolved elements other + than H and O. + count is number of elements, valence states, + exchangers, and surfaces. + Arrays are filled for each element and valence state, + type is "dis"; exchanger, type is "ex", + and surface, type is "surf". Values are moles. + "phases" returns maximum saturation index of all phases. + count is number of phases in system. + Arrays are filled for each phase; values are + saturation indexes. + "aq" returns sum of moles of all aqueous species. + count is number of aqueous species in system. + Arrays are filled with each aqueous species; + values are moles. + "ex" returns sum of moles of all exchange species. + count is number of exchange species in system. + Arrays are filled with each exchange species; + values are moles. + "surf" returns sum of moles of all surface species. + count is number of surface species in system. + Arrays are filled with each surface species; + values are moles. + "s_s" returns sum of moles of all solid solution components. + count is number of solid solution components in system. + Arrays are filled with each solid solution component; + values are moles. + "gas" returns sum of moles of all gas components. + count is number of gas components in system. + Arrays are filled with each gas component; + values are moles. + +* Added new Basic function, DESCRIPTION, that has the value + defined for the description field of the SOLUTION keyword line. + +* Added alternative ordinary differential equation solver + called CVODE, a set of C routines from the Lawrence + Livermore National Labs. CVODE is part of the SUNDIALS + package. CVODE is used in place of the Runge Kutta method + when "-cvode true" is used within a KINETICS data block. + + KINETICS + -cvode true + +------------------------------------------------------------ +Version 2.8: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.7: +------------------------------------------------------------ +Changed format of selected output file: + Removed quotations surrounding strings in headings. + Removed quotations surrounding strings in state variable. + All fields are 12 or 20 places depending on + -high_precision. + Headings are not truncated even if longer than + specified precision. + For isotopes, missing value is -9999.9 + Selected output is updated each simulation. + If a species or phase is defined + subsequent to the simulation where SELECTED_OUTPUT + was defined it will appear in the selected output + file in the simulation in which it is defined and + in subsequent simulations. + +Added strings for each file, which can be extracted from the + executable file with the "ident" command. + +Fixed null pointer for isotope_ratios if Basic routine + was undefined. + +Fixed problem in C++ if structure name is same as member name. + logk member of logk structure was renamed to log_k. + +Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, + SOLUTION_SPECIES, and SURFACE_SPECIES. + + -add_constant -0.301 + + log K is augmented by the specified constant. + + +Theory and implementation of isotopes in PHREEQC is documented in: + +Thorstenson, D.C., and Parkhurst, D.L., 2002, Calculation of +individual isotope equilibrium constants for implementation in +geochemical models: U.S. Geological Survey Water-Resources +Investigations Report 02-4172, 129 p. + +Added KEYWORDS: + +ISOTOPES + Element + -isotope isotope_name units standard_ratio + -total_is_major T/F (OPTION IS DISABLED!!) + +CALCULATE_VALUES + Name + -start + Basic statements, must have SAVE + -end + +ISOTOPE_RATIOS (for printing) + Name=Calculate_values_name Isotope_name + +ISOTOPE_ALPHAS (for printing) + Name=Calculate_values_name Named_logk=named_expression_name + +Basic functions: + calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES + lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS + lk_phase("name") log10(K) of definition in PHASES + lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES + sum_gas("template","element") Sum of element in gases with specified template + template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases + sum_species("template","element") Sum of element in aqueous, exchange, and surface species with + specified template + sum_s_s("s_s_name","element") Sum of element in a specified solid solution + +PRINT keyword: + -initial_isotopes T/F + -isotope_ratios T/F + -isotope_alphas T/F + -censor_species 1e-8 # omit species from Distribution of Species if less than + # relative minimum of an element or element redox state + # total concentration + +SELECTED_OUTPUT keyword: + -calculate_values name1 name2 ... + -isotopes minor_isotope1 minor_isotope2 .... + +Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic + interpreter. LK_SPECIES("CaHCO3+") returns the + log k for the association reaction for the ion pair + CaHCO3+ at the current temperature. The log K is + for the reaction as defined in the database or + input file. Similarly, + LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the + value for the log K at the current temperature using + expressions defined in NAMED_LOG_K data block; + LK_PHASE("Calcite") returns the value of log K + for calcite at the current temperature for the + dissociation reaction defined in the database or + input file. Values are "log10" values. +Example for Basic program: + 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") + 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") + 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 + +NAMED_EXPRESSION--New keyword data block. + + This data block was implemented to facilitate isotopic + calculations. It allows analytical expressions that + are functions of temperature to be defined. The purpose + is to separate the fractionation factors from the log + K, so that the fractionation factor or its temperature + dependence can be easily modified. The named expression + can be added to a log K for a species or phase by the + -add_logk identifier in SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data + block. Log K, Delta H, and analytical expressions for a + log K can be defined with identifiers -log_k, -delta_h, + and -analytical_expression as described in SOLUTION_SPECIES + in WRIR 99-4259. Fractionation factors are often defined + as 1000*ln(alpha). The identifier -ln_alpha1000 can be used + to enter data in this form. The analytical expression is the + same as defined in SOLUTION_SPECIES, but the result of the + expression is converted to log10(alpha) by dividing by + 1000*ln(10) before it is summed into log K values. + +NAMED_EXPRESSIONS + Log_K_calcite # CaCO3 + 2H3O+ = Ca+2 + 3H2O + CO2 + log_k 8.201 + delta_h -8.035 kcal + -analytic 292.29 0.015455 -24146.841 -94.16451 2248628.9 + + Log_alpha_18O_CO2(aq)/Calcite + -ln_alpha1000 3.8498 0.0 10.611e3 0.0 -1.8034e6 + + Log_alpha_13C_CO2(aq)/Calcite + -ln_alpha1000 2.72 0.0 0.0 0.0 -1.1877e6 + +------------------------------------------------------------ +Added identifier -add_logk to SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, and PHASES data + block. + + Allows a named expression to be added to the definition + of the log K for a species or phase. In the following + example, the log K for the phase Ca[14C][18O]3 is summed from + four parts, one defined with the log_k identifier and the + other three parts from expressions defined in NAMED_EXPRESSIONS. + The named expression is multiplied by the coefficient at the + end of the line before it is summed into the log K. A missing + coefficient is 1.0 by default. + +PHASES + Ca[13C][18O]3 + Ca[13C][18O]3 + 3CO2 + 2H3O+ = Ca+2 + 3H2O + 3CO[18O] + [13C]O2 + log_k 0.903089986991 # 3*log10(2) + -add_logk Log_K_calcite 1.0 + -add_logk Log_alpha_13C_CO2(aq)/Calcite 1.0 + -add_logk Log_alpha_18O_CO2(aq)/Calcite 3.0 + + +SOLUTION keyword: + At present, can only define isotopes in the units defined in ISOTOPES. + +------------------------------------------------------------ +Version 2.6: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.5: +------------------------------------------------------------ +Added the capability to use square brackets to define an + "element" name. The brackets act like quotation marks + in that any character string can be used within the + brackets as an element name. For example, [Fe3], [13C], + and [N5] are now legal "element" names. All element + names without brackets must begin with a capital letter, + followed by zero or more lower case letters and underscores. + +Added identifier -activity_water for a species in SOLUTION_SPECIES + data block. This identifier has been added for future updates + that will allow isotopic calculations. It is intended to be + used only for isotopic variations of H2O, like D2O or + H2[O18]. It forces the activity coefficient for the + species to be activity(water)/55.5. This effectively sets + the activity of the species to the mole fraction in + solution. + +Added identifier -bad_step_max to KINETICS data block. + An integer following -bad_step_max gives the maximum number + of times a rate integration may fail before execution of the + program is terminated. Default is 500. + +------------------------------------------------------------ +Version 2.4: +------------------------------------------------------------ + +------------------------------------------------------------ +Added identifier -warnings to PRINT keyword. + + An integer following -warnings gives the maximum number + of warnings to print into the output file. A negative + number allows all warnings to be printed. + + Example: -warnings 20 + +------------------------------------------------------------ +Changed the results of the function CELL_NO in Basic programs. + + Function cell_no in Basic now prints a number equivalent + to -solution in SELECTED_OUTPUT data block. It gives the + solution number for initial solution calculations and the + solution being used in batch reaction calculations. + Result is the same as previous versions for ADVECTION or + TRANSPORT calculations. + +------------------------------------------------------------ +Version 2.3: +------------------------------------------------------------ +DATABASE--New keyword data block + + It must be the first keyword in the input file. + The character string following the keyword is + the pathname for the database file to be used + in the calculation. The file that is specified + takes precedence over any default database + name, including environmental variable + PHREEQC_DATABASE and command line arguments. + +LLNL_AQUEOUS_MODEL_PARAMETERS--New keyword data block + + Added new keyword to make aqueous model similar to + EQ3/6 and Geochemists Workbench when using + llnl.dat as the database file. Values + of Debye-Huckel a and b and bdot (ionic strength + coefficient) are read at fixed temperatures. + Linear interpolation occurs between temperatures. + + New options for SOLUTION_SPECIES are + -llnl_gamma a , where a is the ion-size parameter. + -co2_llnl_gamma , indicates the temperature dependent + function for the bdot term given in + -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS + will be used. Applies to uncharged + species only. + +LLNL_AQUEOUS_MODEL_PARAMETERS +-temperatures + 0.0100 25.0000 60.0000 100.0000 + 150.0000 200.0000 250.0000 300.0000 +#debye huckel a (adh) +-dh_a + 0.4939 0.5114 0.5465 0.5995 + 0.6855 0.7994 0.9593 1.2180 +#debye huckel b (bdh) +-dh_b + 0.3253 0.3288 0.3346 0.3421 + 0.3525 0.3639 0.3766 0.3925 +-bdot + 0.0394 0.0410 0.0438 0.0460 + 0.0470 0.0470 0.0340 0.0000 +#cco2 (coefficients for the Drummond (1981) polynomial) +-co2_coefs + -1.0312 0.0012806 + 255.9 0.4445 + -0.001606 + +------------------------------------------------------------ +Added function SURF to Basic. + + SURF("element", "surface") gives the amount of element + sorbed on "surface". "surface" should be the surface + name, not the surface-site name (that is, no underscore). + +------------------------------------------------------------ +Allow decimals in definition of secondary master species. + + Some redox states do not average to integers, + for convenience in identifying them, decimal numbers + may be used within the parentheses that define the + redox state, example S(0.3) could be used in the + MASTER_SPECIES data block for the valence state of + aqueous species S6-2. + +------------------------------------------------------------ +Eliminate echo of input file in PRINT data block. + + -echo_input T/F turns echoing on and off. + Default is true, initial value is true. + +------------------------------------------------------------ +Added option for an equilibrium-phase to dissolve only. + "dis" is added at the end of a line defining an equilibrium- + phase. No data fields may be omitted. Should not + be used when adding an alternative reaction. + Example: + EQUILIBRIUM_PHASES + Dolomite 0.0 0.001 dis + +------------------------------------------------------------ +Version 2.2: +------------------------------------------------------------ +Added function EDL to Basic. + EDL("element", "surface") gives the amount of + element in the diffuse layer for "surface", not + including sorbed species. "surface" should be + the surface name, not the surface-site name + (that is, no underscore). + + Special values for "element" include: + "charge" - gives surface charge, equivalents. + "sigma" - surface charge density, C/m**2. + "psi" - potential at the surface, Volts. + "water" - mass of water in the diffuse layer, kg. + +------------------------------------------------------------ +End of Features not documented in WRIR 99-4259. +------------------------------------------------------------ + +------------------------------------------------------------ +Revisions and bug fixes +------------------------------------------------------------ + svn 675: + Added PRINT option to print the species that contribute + to alkalinity. Alkalinity distribution is printed in + the output file following the distribution of species. + Default at program startup is false. + + PRINT + -alkalinity true + + svn 655: + IAP and log K printed in Phase assemblage data + block were calculated from reactions rewritten to + new master species. Now the original data base + reaction is used to calculate IAP and log K. + Also fixed check that ensured all elements of + phase in are in solution before SI is calculated. + + svn 631: + Fixed bug with alternate formula for equilibrium phase, + nothing happened if all other equations were satisfied + at beginning of reaction calculation. + + svn 603: + Link gmp library statically. + + svn 601: + Fixed statement on multiprecision. + + svn 581: + Fixed bug in PhreeqcI that did not reinitialize + Chebyschev parameters leading to incorrect results + with Pitzer activity coefficients. Results were + correct on first run, but erroneous on subsequent + runs. + + Added statement to identify multiprecision or + standard solver for inverse modeling. + + svn 578: + + Distribution changes. Fixed names in README file. + Modified Makefile to use specified version. Split + Linux and source distribution procedure. + +Version 2.12 Date: Wed September 28, 2005 + + Executables and output files for Sun operating systems + are no longer provided. + + Limited log activities of master species to be greater + than the smallest machine precision exponential number. + Avoids a matherr exception and allows trial of additional + parameter sets to attempt to solve the system of + equations. + + Made aqueous activity coefficients the default activity + coefficients for exchange species when using the + Pitzer formulation. New option in EXCHANGE is + -pitzer_exchange_gammas T/F, default is true; + defining "false" sets exchange activity coefficients + to 1.0. Option has no effect for ion-association + model (non-Pitzer). + + Edited phreeqc.dat to add -gamma expression for + CdX2 and PbX2. + + Replaced O2(g) log K in phreeqc.dat and wateq4f.dat + with data from llnl.dat, which appears to be better. + + Added multiplier format to REACTION increments, which + simplifies definition of multiple equal reaction increments. + + REACTION + H2O 1 + -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles + + Added Pitzer activity formulation. Use pizer.dat database + to invoke the Pitzer model. Should have same capabilities + as ion-association model except explicit diffuse layer + calculation is not implemented with the Pitzer model. + + + Fixed bug in surface sites related to mineral and exchange + sites related to mineral. Did not have complete logic to + handle redox valence states in formula for species. + + Modified to remove non standard usage of va_list. + + Removed exchange master species from SYS("ex",..) + list of species. This species is fictive and should + not be included in the list. + + Changed -redox in SOLUTION so that if one of the + redox states of a couple is not defined, then + redox defaults to pe. + + Fixed buffer overrun in PhreeqcI with SOLUTION_SPREAD, + caused segmenatation fault with lines greater than + 500 characters. + + Added bigger string for some error messages to avoid + access violation in cvode. + + Changed output_msg to warning_msg for combinations + of convergence parameters so that message would + be controlled by -warnings identifier. + + Carriage returns are now stripped from Basic program + statements. Switching files from Windows to Unix sometimes + leaves extra carriage returns at the ends of lines, which + caused a syntax error for some Basic commands. + + Two bugs were fixed in inverse modeling. (1) Potential + models are now checked for all equality and inequality + constraints. Previously some constraints were not checked. + (2) One loop of cl1 did not include the last row when + checking for the pivot element. Also printing of headers + was slightly modified for inverse modeling. + + A new multiple precision version of cl1 was develeped by + using the Gnu Multiple Precision package (gmp). Calculations + are carried out to about 30 significant digits. The mp + version may help in some situations where roundoff errors are + a problem, but it is still possible that roundoff errors will + cause cl1mp to fail to find a solution to the optimization + problem. The mp version has the following options in + INVERSE_MODELING: + -multiple_precision T/F--causes the mp version + to be used in inverse modeling calculations. + -mp_tolerance 1e-12--tolerance for mp version of + cl1. As in cl1, numbers less than the + tolerance are considered to be zero. + 1e-12 is the default. + -censor_mp 1e-20--as calculations occur in the + linear equation array, elements less + than this value are set to zero. Default + is 1e-20. A value of 0.0 causes no + censoring to occur. + +Version 2.11 Date: Mon February 7, 2005 + + Fixed error in selected output file with mixing reaction. + MIX number was written to two columns, should be one. + + Fixed memory leak with PAD function. + + New database minteq.v4.dat has been translated from version + 4.02 of MINTEQA2. An older version of the MINTEQA2 database is + retained in file minteq.dat. + + Switched version control to subversion. Simplified, + reorganized makefiles. + + Fixed bug with PRINT; -warnings n. Use of this option + generally eliminated all warning messages instead of + all messages after the nth. Default number of warning + messages printed in now 100 per simulation. + + Fixed memory leaks in cvode that caused phreeqci to crash. + Now uses PHRQ_malloc in case of other memory leaks. Also + fixed potential memory error with PAD Basic function. + + Saturation index phases that included water had wrong + value if distribution of species, exchange, or surface + not written also. + + Fixed error message in cvode, if max iterations exceeded + the error caused a segmentation fault. + + Made printing of parameter combination message a warning + message so that it could be turned off. + +Version 2.10 Date: Tue November 2, 2004 + + Rearranged i/o for PHREEQC and reorganized driver + subroutine. The object of these changes is to make + the program more functional as a module for other + programs (PHAST) and eventually to produce a callable + C and Fortran module. + + Fixed a problem with surface related to a phase, when + phase was not part of system (for example, Fe(OH)3a when + there is no iron in system. + + Added convergence parameter set that requires mineral + transfers to produce positive concentrations in the + event that negative concentrations have been produced in + the prior Newton-Raphson iteration. (Fluorite example). + + Fixed bug with kinetics formulas; did not account for + stoichiometric coefficient correctly when using + phase names. Generalized to allow multiple phase + names in the -formula definition. + +Version 2.9 Date: Wed September 15, 2004 + + In inverse modeling, program terminates if sum of initial + solutions and phases is > 32. + + Fixed bug with isotopes. Log activity estimate after initial + solution calculation was inf under some conditions. An initial + surface calculation failed when using D. + + Changed saturation index print out to use reaction and log K + defined in PHASES definition. Previously, reaction could be + rewritten to predominant redox species. + + Fixed incorrect print of elapsed time for kinetics in advection. + + Added phrqproto.h prototype file and phrqtype.h for + switching compilation to long double. + + Fixed incorrect printout of kinetics delta moles with + advection. + + Added convergence parameter set that skips mineral + equations for first 5 iterations. + + Added entity_exists for module. + + Tried to fix bug with mix index incorrect (-2) for + mixing with kinetics. + + Added new keyword COPY that allows a data entity + to be copied from one index to a new index + or to a range of indicies. Format is + + COPY keyword index index_start[-index_end] + + where keyword is one of the following: + SOLUTION + EQUILIBRIUM_PHASES + EXCHANGE + GAS_PHASE + KINETICS + MIX + REACTION + REACTION_TEMPERATURE + SOLID_SOLUTION + SURFACE + + Numerical method had a bug with ionic strength, if + mass of water was not approximately 1. Routine + revise_guesses did not divide by the mass of + water. Also changed check in routine molalities + to check by molality, not moles. + + Fixed a null pointer when surface was related to a + mineral and mineral was not in database. + + Added new Basic functions + i = INSTR(a$, b$) sets i to the character position of + string b$ in a$, 0 in not found. + b$ = LTRIM(a$) trims white space from beginning of + string a$ and stores result in b$. + b$ = RTRIM(a$) trims white space from end of string + a$ and stores result in b$. + b$ = LTRIM(a$) trims white space from beginning and + end of string a$ and stores result in b$. + + Added new Basic function SYS that calculates the to + total amount of an element in all phases (solution, + equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase). KINETIC reactions are not included. + The function has two forms: (1) one element name as an + argument (variable names are user specified) + + 10 t = SYS("As") + + the function will return the total arsenic in the system. + (2) 5 argumens + + 10 t = SYS("As", count_species, names$, types$, moles) + + will return the total arsenic in the system to tot; count_species-- + the number of species that contain arsenic, including + solution, equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase species; names$--a character array that has the + name of each species; type$--a character array that specifies the + type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. + Diff refers to the amount of the element in the diffuse layer of + a surface when the explicit diffuse layer calculation is used; + moles--an array containing the number of moles of the element in + the species. The sum of moles(i) is equal to tot. + + SYS has several special arguments for the form + SYS("arg", count, names$, types$, values) + arg is one of the options listed below. + count is a single numeric value and is the number of elements + in the following arrays. + name$ is an array of string values. + type$ is an array of string values. + values is an array of numeric values. + + Values of arg: + + elt_name returns total number of moles of element in system. + count is the number of species for the element in + the system, including aqueous, exchange, surface, + equilibrium_phase, solid solution component, and + gas phase "species". + Arrays are filled for each "species"; values are moles. + "elements" returns total number of moles of all elements, + valence states, exchangers, and surfaces. + count is number of elements, valence states, + exchangers, and surfaces. + Arrays are filled for each element, valence state, + exchanger, and surface; values are moles. + "phases" returns maximum saturation index of all phases. + count is number of phases in system. + Arrays are filled for each phase; values are + saturation indexes. + "aq" returns sum of moles of all aqueous species. + count is number of aqueous species in system. + Arrays are filled with each aqueous species; + values are moles. + "ex" returns sum of moles of all exchange species. + count is number of exchange species in system. + Arrays are filled with each exchange species; + values are moles. + "surf" returns sum of moles of all surface species. + count is number of surface species in system. + Arrays are filled with each surface species; + values are moles. + "surf" returns sum of moles of all solid solution components. + count is number of solid solution components in system. + Arrays are filled with each solid solution component; + values are moles. + "gas" returns sum of moles of all gas components. + count is number of gas components in system. + Arrays are filled with each gas component; + values are moles. + + Added new Basic function, DESCRIPTION, that has the value + defined for the description field of the SOLUTION keyword line. + + Added alternative ordinary differential equation solver + called CVODE, a set of C routines from the Lawrence + Livermore National Labs. CVODE is part of the SUNDIALS + package. CVODE is used in place of the Runge Kutta method + when "-cvode true" is used within a KINETICS data block. + + KINETICS + -cvode true + + Fixed error in SOLUTION_SPREAD, defining -redox + did not set the default redox for the solutions + that were defined; pe was always used as default. + + Modified code to allocate space differently for + pp_assemblage, exchange, surface, gas_phase, + kinetics, and s_s_assemblage. Enough space is allocated + at beginning of distribute_initial_conditions. + May speed up phast initialization and make better + use of available memory. + + Changed gfw of water to 18 if isotopes of water are + included. Solvent is [1H]2[16O]. + + Fixed a bug in surface integration where order of ions + in the list of g's was incorrect. + + Pyrite rate was not 0 if supersaturated in phreeqc.dat + and wateq4f.dat + + Segmentation error if a surface species was not + defined with an equation that contained another surface + species. In this case, the surface master species + had been redefined to be an aqueous species (SOLUTION_SPECIES). + +Version 2.8 Date: Tue April 15, 2003 + + Updated arsenic data in wateq4f.dat to be consistent with + Archer and Nordstrom (2002). + + Revised Basic interpreter to allow lines of any length + and character strings of any length. + + Renumbering basic statement that included the function + SURF in PhreeqcI caused SURF to be omitted and generated + a syntax error. SURF and other functions had not been + implemented in PhreeqcI. + + Fixed a bug in the Basic Interpreter. If elements of + a dimensioned variable (character or number) were used on + both sides of an equation, the result was erroneously + stored in the last element of the variable used on the + right-hand side instead of the element specified on the + left-hand side. + + Using comma in some fields caused an infinite loop. + + Fixed bug with SOLUTION_SPREAD, Phreeqc was not + calculating solution numbers for solution_spread + solutions without solution numbers. + + Fixed bug with stagnant zone calculations. If solutions + not defined for stagnant cells, PhreeqcI crashed. + + Added new state for calculations, PHAST. Previously + phast used the state TRANSPORT, which caused some + erroneous results with temperature when TRANSPORT was + used in the PHREEQC part of the calculation. + + Trying to define dump file in TRANSPORT caused a file + opening error. Fixed logic so now can open a file + and the name can include blanks. + +Version 2.7 Date: Fri February 14, 2003 + + Initialized gfw in elements structure. + + Fixed bug where "time" would be wrong for initial + solution calculation. Needed to initialize + rate variables for PhreeqcI. + + Added print of simulation number to error file for + phreeqci + + Limited printing of cell numbers to output file in advection + calculations. Cell numbers only printed if results + for cell are going to be printed. + + PhreeqcI captured status messages for kinetics, which + made a very large error file in some cases and + a long wait to view the output file in PhreeqcI. + Now PhreeqcI does not capture these intermediate + status messages. + + Removed old code related to redirecting error file + + + Corrected error in transport where wrong time step was used + for integration. + + Changes to speed up transport algorithm. + + Allow file names with spaces in selected_output file name and + dump_file name. + + Modifications to work with RC1 phast log file. + + Allow any characters in square brackets for element name. + - and + and perhaps others caused problems before. + + Fixed log molality of water in species printout, was + equal to log activity of water. Also fixed + basic function for LM. + + Changed solid solution prints to print 0 if solid solution + is not present. + + Fixed bug if no rate name was defined before options + in RATES. + + Fixed warning on Mac compilation in fpunchf. + + Fixed bug if isotopes were used but H and O isotopes + were not defined. + + Fixed bug where special initial solution calculations + were done at later calculation stages. + Needed to set initial_solution_isotopes = FALSE; + + Fixed problem in C++ if structure name is same as member name. + logk member of logk structure was renamed to log_k. + + Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, + SOLUTION_SPECIES, and SURFACE_SPECIES. + + -add_constant -0.301 + + log K is augmented by the specified constant. + + + Added punch_isotopes and punch_calculate_values to allow + printing isotope ratios and any CALCULATE_VALUES result. + + Added KEYWORDS: + + ISOTOPES + Element + -isotope isotope_name units standard_ratio + -total_is_major T/F (OPTION IS DISABLED!!) + + CALCULATE_VALUES + Name + -start + Basic statements, must have SAVE + -end + + ISOTOPE_RATIOS (for printing) + Name=Calculate_values_name Isotope_name + + ISOTOPE_ALPHAS (for printing) + Name=Calculate_values_name Named_logk=named_expression_name + + Basic functions: + calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES + lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS + lk_phase("name") log10(K) of definition in PHASES + lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES + sum_gas("template","element") Sum of element in gases with specified template + template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases + sum_species("template","element") Sum of element in aqueous, exchange, and surface species with + specified template + sum_s_s("s_s_name","element") Sum of element in a specified solid solution + + PRINT keyword: + -initial_isotopes T/F + -isotope_ratios T/F + -isotope_alphas T/F + -censor_species 1e-8 # Omits print of species if less than relative criterion + + SELECTED_OUTPUT keyword: + -calculate_values name1 name2 ... + -isotopes minor_isotope1 minor_isotope2 .... + + Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic + interpreter. LK_SPECIES("CaHCO3+") returns the + log k for the association reaction for the ion pair + CaHCO3+ at the current temperature. The log K is + for the reaction as defined in the database or + input file. Similarly, + LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the + value for the log K at the current temperature using + expressions defined in NAMED_LOG_K data block; + LK_PHASE("Calcite") returns the value of log K + for calcite at the current temperature for the + dissociation reaction defined in the database or + input file. Values are "log10" values. + Example for Basic program: + + 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") + 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") + 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 + + Added NAMED_EXPRESSIONS data block. This data block was + implemented to facilitate isotopic calculations. + It allows analytical expressions that are functions + of temperature to be defined. The purpose is to + separate the fractionation factors from the log K, + so that the fractionation factor or its temperature + dependence can be easily modified. The named + expression can be added to a log K for a species + or phase by the -add_logk identifier in SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data + block. + +Version 2.6 Date: Mon April 22, 2002 + + PhreeqcI released. + + All selected_output is routed through a single routine. + + Allow "_" inside square brackets, [A_bcd]. + + Fixed bug match_elts_in_species, check for "e-" was wrong. + + Modified minteq.dat to put CuS4S5-3, Cu(S4)2-3 in + in Cu(1) mole balance equations instead of + Cu(2). Before the change, the program would + not converge if Cu(2) were defined in an + initial solution. + + Made revisions hopefully to improve SOLID_SOLUTIONS + convergence with small numbers of moles of + solids. + + Made changes related to dump file and PhreeqcI. + + Iterations now sums iterations in all kinetics calculations + + Fixed bug with LA("H2O"), which was returning natural log + of activity of water. + + +Version 2.5 Date: Mon October 1, 2001 + In llnl.dat, fixed sign errors in RRE (rare earth elements) + for some redox reactions and removed some redundant + species, generally ReeO2- was retained and Ree(OH)4- + was removed. + + Added the capability to use square brackets to define an + "element" name. The brackets act like quotation marks + in that any character string can be used within the + brackets as an element name. This was introduced to + simplify expansion of the model to isotopic species. + [13C], [14C], and [18O] are legal element names. + + Added identifier -activity_water for a species in + SOLUTION_SPECIES data block. This identifier has been + added for future updates that will allow isotopic + calculations. It is intended to be used only for + isotopic variations of H2O, like D2O or H2[O18]. It + forces the activity coefficient for the species to be + activity(water)/55.5. This effectively sets the activity + of the species to the mole fraction in solution. + + Fixed bug in checking solid solutions for presence or + absence of elements in the system. Programming + error caused segmentation fault if an error + was detected under certain conditions. + + Changed return value of MOL to be molality of water + if argument is "H2O". Also changed return value + of LA to be activity of water if argument is + "H2O". + + Diffuse layer calculation was incorrect if aqueous phase did not + have 1 kilogram of water. Eq. 74 of manual has molality, + but code used moles. The code was corrected by adding + the mass of water to the formulation. + + Stagnant zones with first-order exchange approximation (1 stagnant + cell, exchange factor, and porosities defined) did not work + correctly if mobile and immobile cells did not have equal + volumes of water. The mixing factors were revised to account + for the masses of water in the stagnant and mobile zones. + + A fatal error was erroneously detected if the database file + had a DATABASE data block. DATABASE data block is + now ignored while reading the database file. + + Added identifier -bad_step_max to KINETICS data block. + An integer following -bad_step_max gives the maximum number + of times a rate integration may fail before execution of the + program is terminated. Default is 500. + +Version 2.4.2: Date: Fri June 15, 2001 + Fixed spreadsheet bug. Program was not ignoring columns + that could not be identified as either element + names or allowed data (ph, pe, number, description, + etc). Also, the program failed if a spreadsheet solution + number was negative. + +Version 2.4.1: Date: Mon June 4, 2001 + Fixed spreadsheet bugs with isotopes. + +Version 2.4: Date: Fri June 1, 2001 + + Added structure for spreadsheet for use by PhreeqcI. + + Isotope value initialized incorrectly if only an -uncertainty was + defined in SOLUTION_SPREAD. + + Fixed segmentation violation when primary and secondary master + species were defined improperly. + + Corrected enthalpies of reaction in llnl.dat. Previous release had + erroneously had enthalpies of formation in -delta_H + parameter; the values should be enthalpies of reaction. + Enthalpies of reaction were calculated from the + enthalpies of formation and these values are now included + in the -delta_H parameter. This change will have very + little impact on calculations because the analytical + expression has precedence over -delta_H in calculating + temperature dependence of log K, and nearly all species + and minerals have an analytical expression or lack both + an analytical expression and an enthalpy of reaction. + + Corrected bugs in punch of solid solution components that caused + both selected output and output file errors: moles + were incorrect in selected output, and total moles and + mole fraction were incorrect in output file. + + Added surface complexation constants for Fe+2; two complexes for + weak sites and one complex for strong sites. phreeqc.dat + and wateq4f.dat modified. + + Comment for units of parameters for calcite rate equation was + wrong. Rate equation now uses cm^2/L for area parameter. + Previously the correct units would have been 1/decimeter. + phreeqc.dat and wateq4f.dat modified. + + Fixed a bug when rates were equal within tolerance, but negative + concentrations occurred because of small initial + concentrations. + + Added -warnings to PRINT keyword for specification of maximum + number of warnings to print. Negative number allows + all warnings to be printed. + + Function CELL_NO in Basic now prints a number equivalent to + -solution in SELECTED_OUTPUT data block. This does not + change printing for ADVECTION or TRANSPORT calculations. + + Kinetics time is halved for advective part of reaction in + transport; time incorrectly accounted for before. + + -punch_ identifiers printed -1 instead of the correct solution + number for batch-reaction calculations. + + -high_precision is no longer reset to false with every + SELECTED_OUTPUT data block. + + SELECTED_OUTPUT file name stored for use by PhreeqcI. + + Alkalinity for NH3 corrected to 1.0 in llnl.dat. + + Fixed bug with USER_PRINT of kinetics. Did not find correct + kinetics information in some cases. + + Fixed bug in default values for SOLUTION_SPREAD. Cannot use phase + name and SI for pH or pe, and bug did not allow PHREEQC + to run. Now PHREEQC runs, but warns that this is not + allowed. + +Version 2.3: Date: Tue January 2, 2001 + + Added new keyword DATABASE. It must be the first keyword in + the input file. The character string following the + keyword is the pathname for the database file to + be used in the calculation. The file that is + specified takes precedence over any default + database name, including environmental variable + PHREEQC_DATABASE and command line arguments. + + Fixed bug in SOLUTION_SPREAD. If first heading in + the spread-sheet input was an identifier--pH, + pe, units, etc--then the headings were interpreted + as an identifier and bad things happened. + + Added new keyword to make aqueous model similar to + LLNL and Geochemists Workbench when using + llnl.dat as the database file. Values + of Debye-Huckel a and b and bdot (ionic strength + coefficient) are read at fixed temperatures. + Linear interpolation occurs between temperatures. + + New options for SOLUTION_SPECIES are + -llnl_gamma a , where a is the ion-size parameter. + -co2_llnl_gamma , indicates the temperature dependent + function for the bdot term given in + -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS + will be used. Applies to uncharged + species only. + +LLNL_AQUEOUS_MODEL_PARAMETERS +-temperatures + 0.0100 25.0000 60.0000 100.0000 + 150.0000 200.0000 250.0000 300.0000 +#debye huckel a (adh) +-dh_a + 0.4939 0.5114 0.5465 0.5995 + 0.6855 0.7994 0.9593 1.2180 +#debye huckel b (bdh) +-dh_b + 0.3253 0.3288 0.3346 0.3421 + 0.3525 0.3639 0.3766 0.3925 +-bdot + 0.0394 0.0410 0.0438 0.0460 + 0.0470 0.0470 0.0340 0.0000 +#cco2 (coefficients for the Drummond (1981) polynomial) +-co2_coefs + -1.0312 0.0012806 + 255.9 0.4445 + -0.001606 + + + Fixed bug in basic interpreter. A number like "..524" would + cause an infinite loop. + + Added function SURF to Basic. + SURF("element", "surface") gives the amount of + element sorbed on "surface". "surface" + should be the surface name, not the + surface-site name (that is, no underscore). + + Fixed option to "runge_kutta" from "runge-kutta" to match + documentation for KINETICS. + + Fixed UO2+2 and Mn+2 reaction stoichiometry for Hfo surface complexation + in wateq4f.dat. + + Added option for an equilibrium-phase to dissolve only. + "dis" is added at the end of a line defining an equilibrium- + phase. No data fields may be omitted. Should not + be used when adding an alternative reaction. + Example: + EQUILIBRIUM_PHASES + Dolomite 0.0 0.001 dis + R-K integration failed when only the final rate generated + negative concentrations. + Allow decimals in definition of secondary master species, for + example S(0.3). + Fixed bug if description was more than about 85 characters; + now allows about 400 characters. + Fixed bug for surface/exchange sites related to phases. Was + checking internal copies of surfaces/exchange with negative + numbers. + Fixed bug in quick prep that did not set the correct pointer + for gas phases. + Fixed segmentation fault that occurred if all elements for + phase-boundary mineral were not in the solution. + Only applied to a phase used to define concentration + in an initial solution calculation. + Added option to eliminate echo of input file in PRINT + data block. -echo_input T/F turns echoing on + and off. Default is on. + + +Release 2.2: Date: Wed March 1, 2000 + + Fixed bug in MIX if no solutions are defined. + Changed printout for surface. + Only gives net surface charge for diffuse layer + calculation. + Prints correct value for the surface charge and + surface charge density for diffuse-layer + calculation. + + Added function EDL to Basic. + EDL("element", "surface") gives the amount of + element in the diffuse layer for "surface". + not including sorbed species. "surface" should + be the surface name, not the surface-site name + (that is, no underscore). + + Special values for "element" include: + "charge" - gives surface charge, equivalents. + "sigma" - surface charge density, C/m**2. + "psi" - potential at the surface, Volts. + "water" - mass of water in the diffuse layer, kg. + Changed distribution to be more consistent with other USGS + water-resources applications. + +Release 2.1: Date: Wed January 19, 2000 + + Added additional #ifdef's for PhreeqcI. + Fixed problem with formats for USER_PUNCH and + others with Microsoft C++ 3 digit + exponents. + +Initial Release 2.0: Date: Wed December 15, 1999 + +Version: C_54 = Version 2.0 + diff --git a/smalldense.cpp b/smalldense.cpp new file mode 100644 index 00000000..4116703f --- /dev/null +++ b/smalldense.cpp @@ -0,0 +1,243 @@ +/******************************************************************* + * * + * File : smalldense.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package, intended for small dense matrices. * + * * + *******************************************************************/ + +#include +#include +#include "smalldense.h" +#include "sundialstypes.h" +#include "sundialsmath.h" +#include "output.h" +#include "phqalloc.h" +/* WARNING don't include any headers below here */ +#define malloc PHRQ_malloc +static char const svnid[] = "$Id: smalldense.c 663 2005-11-16 00:46:04Z dlpark $"; + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) + + +/* Implementation */ + + +realtype **denalloc(integertype n) +{ + integertype j; + realtype **a; + + if (n <= 0) return(NULL); + + a = (realtype **) malloc(n * sizeof(realtype *)); + if (a == NULL) return(NULL); + + a[0] = (realtype *) malloc(n * n * sizeof(realtype)); + if (a[0] == NULL) { + free(a); + return(NULL); + } + + for (j=1; j < n; j++) a[j] = a[0] + j * n; + + return(a); +} + +integertype *denallocpiv(integertype n) +{ + if (n <= 0) return(NULL); + + return((integertype *) malloc(n * sizeof(integertype))); +} + +integertype gefa(realtype **a, integertype n, integertype *p) +{ + integertype i, j, k, l; + realtype *col_j, *col_k, *diag_k; + realtype temp, mult, a_kj; + booleantype swap; + + /* k = elimination step number */ + + for (k=0; k < n-1; k++, p++) { + + col_k = a[k]; + diag_k = col_k + k; + + /* find l = pivot row number */ + + l=k; + for (i=k+1; i < n; i++) + if (ABS(col_k[i]) > ABS(col_k[l])) l=i; + *p = l; + + /* check for zero pivot element */ + + if (col_k[l] == ZERO) return(k+1); + + /* swap a(l,k) and a(k,k) if necessary */ + + /*if ( (swap = (l != k) )) {*/ + swap = (l != k); + if (swap) { + temp = col_k[l]; + col_k[l] = *diag_k; + *diag_k = temp; + } + + /* Scale the elements below the diagonal in */ + /* column k by -1.0 / a(k,k). After the above swap, */ + /* a(k,k) holds the pivot element. This scaling */ + /* stores the pivot row multipliers -a(i,k)/a(k,k) */ + /* in a(i,k), i=k+1, ..., n-1. */ + + mult = -ONE / (*diag_k); + for(i=k+1; i < n; i++) + col_k[i] *= mult; + + /* row_i = row_i - [a(i,k)/a(k,k)] row_k, i=k+1, ..., n-1 */ + /* row k is the pivot row after swapping with row l. */ + /* The computation is done one column at a time, */ + /* column j=k+1, ..., n-1. */ + + for (j=k+1; j < n; j++) { + + col_j = a[j]; + a_kj = col_j[l]; + + /* Swap the elements a(k,j) and a(k,l) if l!=k. */ + + if (swap) { + col_j[l] = col_j[k]; + col_j[k] = a_kj; + } + + /* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */ + /* a_kj = a(k,j), col_k[i] = - a(i,k)/a(k,k) */ + + if (a_kj != ZERO) { + for (i=k+1; i < n; i++) + col_j[i] += a_kj * col_k[i]; + } + } + } + + /* set the last pivot row to be n-1 and check for a zero pivot */ + + *p = n-1; + if (a[n-1][n-1] == ZERO) return(n); + + /* return 0 to indicate success */ + + return(0); +} + +void gesl(realtype **a, integertype n, integertype *p, realtype *b) +{ + integertype k, l, i; + realtype mult, *col_k; + + /* Solve Ly = Pb, store solution y in b */ + + for (k=0; k < n-1; k++) { + l = p[k]; + mult = b[l]; + if (l != k) { + b[l] = b[k]; + b[k] = mult; + } + col_k = a[k]; + for (i=k+1; i < n; i++) + b[i] += mult*col_k[i]; + } + + /* Solve Ux = y, store solution x in b */ + + for (k=n-1; k >= 0; k--) { + col_k = a[k]; + b[k] /= col_k[k]; + mult = -b[k]; + for (i=0; i < k; i++) + b[i] += mult*col_k[i]; + } +} + +void denzero(realtype **a, integertype n) +{ + integertype i, j; + realtype *col_j; + + for (j=0; j < n; j++) { + col_j = a[j]; + for (i=0; i < n; i++) + col_j[i] = ZERO; + } +} + +void dencopy(realtype **a, realtype **b, integertype n) +{ + integertype i, j; + realtype *a_col_j, *b_col_j; + + for (j=0; j < n; j++) { + a_col_j = a[j]; + b_col_j = b[j]; + for (i=0; i < n; i++) + b_col_j[i] = a_col_j[i]; + } + +} + +void denscale(realtype c, realtype **a, integertype n) +{ + integertype i, j; + realtype *col_j; + + for (j=0; j < n; j++) { + col_j = a[j]; + for (i=0; i < n; i++) + col_j[i] *= c; + } +} + +void denaddI(realtype **a, integertype n) +{ + integertype i; + + for (i=0; i < n; i++) a[i][i] += ONE; +} + +void denfreepiv(integertype *p) +{ + free(p); +} + +void denfree(realtype **a) +{ + free(a[0]); + free(a); +} + +void denprint(realtype **a, integertype n) +{ + integertype i, j; + + printf("\n"); + for (i=0; i < n; i++) { + for (j=0; j < n; j++) { + printf("%10g", (double) a[j][i]); + } + printf("\n"); + } + printf("\n"); +} diff --git a/smalldense.h b/smalldense.h new file mode 100644 index 00000000..bffcc85c --- /dev/null +++ b/smalldense.h @@ -0,0 +1,224 @@ +/******************************************************************* + * * + * File : smalldense.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic DENSE linear solver * + * package, intended for small dense matrices. These routines * + * use the type realtype** for dense matrix arguments. * + * * + * These routines begin with "den" (except for the factor and * + * solve routines which are called gefa and gesl, respectively). * + * The underlying matrix storage is described in the * + * documentation for denalloc. * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidsmalldense[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef _smalldense_h +#define _smalldense_h + +#include "sundialstypes.h" + + +/****************************************************************** + * * + * Function : denalloc * + * Usage : realtype **a; * + * a = denalloc(n); * + * if (a == NULL) ... memory request failed * + *----------------------------------------------------------------* + * denalloc(n) allocates storage for an n by n dense matrix. It * + * returns a pointer to the newly allocated storage if * + * successful. If the memory request cannot be satisfied, then * + * denalloc returns NULL. The underlying type of the dense matrix * + * returned is realtype **. If we allocate a dense matrix * + * realtype **a by a = denalloc(n), then a[j][i] references the * + * (i,j)th element of the matrix a, 0 <= i,j <= n-1, and a[j] is * + * a pointer to the first element in the jth column of a. * + * The location a[0] contains a pointer to n^2 contiguous * + * locations which contain the elements of a. * + * * + ******************************************************************/ + +realtype **denalloc(integertype n); + + +/****************************************************************** + * * + * Function : denallocpiv * + * Usage : integertype *pivot; * + * pivot = denallocpiv(n); * + * if (pivot == NULL) ... memory request failed * + *----------------------------------------------------------------* + * denallocpiv(n) allocates an array of n integertype. It returns * + * a pointer to the first element in the array if successful. * + * It returns NULL if the memory request could not be satisfied. * + * * + ******************************************************************/ + +integertype *denallocpiv(integertype n); + + +/****************************************************************** + * * + * Function : gefa * + * Usage : integertype ier; * + * ier = gefa(a,n,p); * + * if (ier > 0) ... zero element encountered during * + * the factorization * + *----------------------------------------------------------------* + * gefa(a,n,p) factors the n by n dense matrix a. It overwrites * + * the elements of a with its LU factors and keeps track of the * + * pivot rows chosen in the pivot array p. * + * * + * A successful LU factorization leaves the matrix a and the * + * pivot array p with the following information: * + * * + * (1) p[k] contains the row number of the pivot element chosen * + * at the beginning of elimination step k, k=0, 1, ..., n-1. * + * * + * (2) If the unique LU factorization of a is given by Pa = LU, * + * where P is a permutation matrix, L is a lower triangular * + * matrix with all 1's on the diagonal, and U is an upper * + * triangular matrix, then the upper triangular part of a * + * (including its diagonal) contains U and the strictly lower * + * triangular part of a contains the multipliers, I-L. * + * * + * gefa returns 0 if successful. Otherwise it encountered a zero * + * diagonal element during the factorization. In this case it * + * returns the column index (numbered from one) at which it * + * encountered the zero. * + * * + ******************************************************************/ + +integertype gefa(realtype **a, integertype n, integertype *p); + + +/****************************************************************** + * * + * Function : gesl * + * Usage : realtype *b; * + * ier = gefa(a,n,p); * + * if (ier == 0) gesl(a,n,p,b); * + *----------------------------------------------------------------* + * gesl(a,n,p,b) solves the n by n linear system ax = b. It * + * assumes that a has been LU factored and the pivot array p has * + * been set by a successful call to gefa(a,n,p). The solution x * + * is written into the b array. * + * * + ******************************************************************/ + +void gesl(realtype **a, integertype n, integertype *p, realtype *b); + + +/****************************************************************** + * * + * Function : denzero * + * Usage : denzero(a,n); * + *----------------------------------------------------------------* + * denzero(a,n) sets all the elements of the n by n dense matrix * + * a to be 0.0. * + * * + ******************************************************************/ + +void denzero(realtype **a, integertype n); + + +/****************************************************************** + * * + * Function : dencopy * + * Usage : dencopy(a,b,n); * + *----------------------------------------------------------------* + * dencopy(a,b,n) copies the n by n dense matrix a into the * + * n by n dense matrix b. * + * * + ******************************************************************/ + +void dencopy(realtype **a, realtype **b, integertype n); + + +/****************************************************************** + * * + * Function : denscale * + * Usage : denscale(c,a,n); * + *----------------------------------------------------------------* + * denscale(c,a,n) scales every element in the n by n dense * + * matrix a by c. * + * * + ******************************************************************/ + +void denscale(realtype c, realtype **a, integertype n); + + +/****************************************************************** + * * + * Function : denaddI * + * Usage : denaddI(a,n); * + *----------------------------------------------------------------* + * denaddI(a,n) increments the n by n dense matrix a by the * + * identity matrix. * + * * + ******************************************************************/ + +void denaddI(realtype **a, integertype n); + + +/****************************************************************** + * * + * Function : denfreepiv * + * Usage : denfreepiv(p); * + *----------------------------------------------------------------* + * denfreepiv(p) frees the pivot array p allocated by * + * denallocpiv. * + * * + ******************************************************************/ + +void denfreepiv(integertype *p); + + +/****************************************************************** + * * + * Function : denfree * + * Usage : denfree(a); * + *----------------------------------------------------------------* + * denfree(a) frees the dense matrix a allocated by denalloc. * + * * + ******************************************************************/ + +void denfree(realtype **a); + + +/****************************************************************** + * * + * Function : denprint * + * Usage : denprint(a,n); * + *----------------------------------------------------------------* + * denprint(a,n) prints the n by n dense matrix a to standard * + * output as it would normally appear on paper. It is intended as * + * a debugging tool with small values of n. The elements are * + * printed using the %g option. A blank line is printed before * + * and after the matrix. * + * * + ******************************************************************/ + +void denprint(realtype **a, integertype n); + + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/spread.cpp b/spread.cpp new file mode 100644 index 00000000..61fdc15c --- /dev/null +++ b/spread.cpp @@ -0,0 +1,1069 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: spread.c 187 2005-03-16 19:54:17Z charlton $"; + +#define STATIC static + +#define STRING 11 +#define NUMBER 12 +#define MIXED 13 +#define EOL 14 + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPT_1 -5 + +static int copy_token_tab(char *token_ptr, char **ptr, int *length); +static int get_option_string (const char **opt_list, int count_opt_list, char **next_char); +static int spread_row_free(struct spread_row *spread_row_ptr); +static int spread_row_to_solution(struct spread_row *heading, struct spread_row *units, struct spread_row *data, struct defaults defaults); +static struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI +static void add_row(struct spread_row *spread_row_ptr); +static void copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr); +void free_spread(void); +static struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + +/* ---------------------------------------------------------------------- */ +int read_solution_spread(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + struct spread_row *heading, *row_ptr, *units; + int i, j, l, j1, num, count; + int strings, numbers; + int spread_lines; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr; + struct defaults defaults = { + 25, + 1, + "mmol/kgw", + "pe", + 7, + 4, + 1, + 1, + iso_defaults, + }; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "isotope_uncertainty", /* 11 */ + "uncertainty", /* 12 */ + "uncertainties" /* 13 */ + }; + int count_opt_list = 14; + if (svnid == NULL) fprintf(stderr," "); + + heading = NULL; + units = NULL; + defaults.count_iso = count_iso_defaults; + defaults.iso = (struct iso *) PHRQ_malloc((size_t) defaults.count_iso * sizeof(struct iso)); + if (defaults.iso == NULL) malloc_error(); + memcpy(defaults.iso, iso_defaults, (size_t) defaults.count_iso * sizeof(struct iso)); + return_value = UNKNOWN; + spread_lines = 0; +/* + * Loop on solutions + */ + for (;;) { + opt = get_option(opt_list, count_opt_list, &next_char); + if (spread_lines == 0 && opt != OPTION_DEFAULT) { + row_ptr = string_to_spread_row(line); + count = 0; + ptr = line; + numbers = 0; + strings = 0; + while ( ((j = copy_token(token, &ptr, &l)) != EMPTY)) { + count++; + if (j == UPPER || j == LOWER) strings++; + if (j == DIGIT) numbers++; + } +#ifdef SKIP + for (i = 0; i < row_ptr->count; i++) { + if (row_ptr->type_vector[i] == STRING) { + strings++; + } else if (row_ptr->type_vector[i] == NUMBER) { + numbers++; + } + } +#endif + /* + * Is 2nd token all number + */ + ptr = line; + copy_token(token, &ptr, &l); + j = copy_token(token, &ptr, &l); + num = FALSE; + if (j == DIGIT) { + strtod(token, &ptr); + j1 = copy_token(token1, &ptr, &l); + if (j1 != EMPTY) { + num = FALSE; + } else { + num = TRUE; + } + } + + /* + * Starts with hyphen + */ + ptr = line; + copy_token(token, &ptr, &l); + if (token[0] == '-') { + opt = opt; + } else { + switch (opt) { + case 0: /* temp */ + case 1: /* temperature */ + case 2: /* dens */ + case 3: /* density */ + case 10: /* water */ + if (count == 2 && num == TRUE) { + opt = opt; + } else { + opt = OPTION_DEFAULT; + } + break; + case 6: /* ph */ + case 7: /* pe */ + if ((count == 2 || count == 3 || count == 4) && num == TRUE) { + opt = opt; + } else { + opt = OPTION_DEFAULT; + } + break; + case 5: /* redox */ + case 4: /* units */ + case 8: /* unit */ + if (count == 2) { + opt = opt; + } else { + opt = OPTION_DEFAULT; + } + break; + case 9: /* isotope */ + if (row_ptr->count > 4) { + opt = OPTION_DEFAULT; + } else { + opt = opt; + } + break; + case 11: /* isotope_uncertainty */ + case 12: /* uncertainty */ + case 13: /* uncertainties */ + if (row_ptr->count > 3) { + opt = OPTION_DEFAULT; + } else { + opt = opt; + } + break; + } + } + spread_row_free(row_ptr); + } + if (opt == OPTION_DEFAULT) { + if (spread_lines == 0) { + opt = 100; + } + spread_lines++; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* solution definition */ + row_ptr = string_to_spread_row(line); + if (spread_lines == 2) { + numbers = 0; + strings = 0; + for (i = 0; i < heading->count; i++) { + if (row_ptr->type_vector[i] == STRING) { + strings++; + } else if (row_ptr->type_vector[i] == NUMBER) { + numbers++; + } +#ifdef SKIP + if (row_ptr->type_vector[i] == STRING && + (strcmp_nocase(heading->char_vector[i],"units") != 0) && + (strcmp_nocase(heading->char_vector[i],"unit") != 0) && + (strcmp_nocase(heading->char_vector[i],"description") != 0) && + (strcmp_nocase(heading->char_vector[i],"desc") != 0) && + (strcmp_nocase(heading->char_vector[i],"descriptor") != 0) && + (strcmp_nocase(heading->char_vector[i],"redox") != 0) ) { + break; + } +#endif + } +#ifdef SKIP + if (i < heading->count) { + units = row_ptr; + break; + } +#endif + if (numbers == 0) { + units = row_ptr; + break; + } + } + spread_row_to_solution(heading, units, row_ptr, defaults); +#ifdef PHREEQCI_GUI + add_row(row_ptr); +#endif + spread_row_free(row_ptr); + break; + case 0: /* temperature */ + case 1: + sscanf(next_char,SCANFORMAT, &(defaults.temp)); + break; + case 2: /* density */ + case 3: + sscanf(next_char,SCANFORMAT, &(defaults.density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (check_units (token, FALSE, FALSE, NULL, TRUE) == OK) { + defaults.units = string_hsave(token); + } else { + input_error++; + } + break; + case 5: /* redox */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (parse_couple(token) == OK) { + defaults.redox = string_hsave(token); + } else { + input_error++; + } + break; + case 6: /* ph */ + copy_token (token, &next_char, &l); + sscanf(token,SCANFORMAT, &(defaults.ph)); + if (copy_token (token, &next_char, &l) != EMPTY) { + warning_msg("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD."); + } + break; + case 7: /* pe */ + copy_token (token, &next_char, &l); + sscanf(token,SCANFORMAT, &(defaults.pe)); + if (copy_token (token, &next_char, &l) != EMPTY) { + warning_msg("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD."); + } + break; + case 11: /* isotope_uncertainty */ + case 12: /* uncertainty */ + case 13: /* uncertainties */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + for (i = 0; i < defaults.count_iso; i++) { + if (strcmp(token, defaults.iso[i].name) == 0) { + break; + } + } + if (i == defaults.count_iso) { + defaults.iso = (struct iso *) PHRQ_realloc(defaults.iso, (size_t) (i+1) * sizeof(struct iso)); + if (defaults.iso == NULL) malloc_error(); + defaults.iso[i].name = string_duplicate(token); + defaults.iso[i].value = NAN; + defaults.iso[i].uncertainty = NAN; + defaults.count_iso++; + } + + /* read and store isotope ratio uncertainty */ + if ( (j = copy_token(token, &next_char, &l)) != EMPTY) { + if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } else { + sscanf(token, SCANFORMAT, &(defaults.iso[i].uncertainty)); + } + } else { + defaults.iso[i].uncertainty = NAN; + } + break; + case 10: /* water */ + j = copy_token (token, &next_char, &l); + if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } else { + sscanf(token, SCANFORMAT, &(defaults.water)); + } + break; + case 9: /* isotope */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + for (i = 0; i < defaults.count_iso; i++) { + if (strcmp(token, defaults.iso[i].name) == 0) { + break; + } + } + if (i == defaults.count_iso) { + defaults.iso = (struct iso *) PHRQ_realloc(defaults.iso, (size_t) (i+1) * sizeof(struct iso)); + if (defaults.iso == NULL) malloc_error(); + defaults.iso[i].name = string_duplicate(token); + defaults.iso[i].value = NAN; + defaults.iso[i].uncertainty = NAN; + defaults.count_iso++; + } + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for default isotope ratio."); + error_msg(error_string, CONTINUE); + break; + } + sscanf(token, SCANFORMAT, &(defaults.iso[i].value)); + /* read and store isotope ratio uncertainty */ + if ( (j = copy_token(token, &next_char, &l)) != EMPTY) { + if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } else { + sscanf(token, SCANFORMAT, &(defaults.iso[i].uncertainty)); + } + } + break; + case 100: /* read headings */ + heading = string_to_spread_row(line); + for (i = 0; i < heading->count; i++) { + while(replace(" ", "", heading->char_vector[i]) == TRUE); + while(replace(",", "_", heading->char_vector[i]) == TRUE); + } + + break; + } + if (return_value == EOF || return_value == KEYWORD) break; + } +#ifdef PHREEQCI_GUI + if (heading) g_spread_sheet.heading = copy_row(heading); + if (units) g_spread_sheet.units = copy_row(units); + copy_defaults(&g_spread_sheet.defaults, &defaults); +#endif + spread_row_free(heading); + spread_row_free(units); + /* free non-default iso names */ + for (i = count_iso_defaults; i < defaults.count_iso; i++) { + defaults.iso[i].name = (char *) free_check_null(defaults.iso[i].name); + } + defaults.iso = (struct iso *) free_check_null(defaults.iso); + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int spread_row_to_solution(struct spread_row *heading, struct spread_row *units, + struct spread_row *data, struct defaults defaults) +/* ---------------------------------------------------------------------- */ +{ + int i, j, n, l, next_keyword_save; + int n_user, n_user_end; + int default_pe, alk; + int count_isotopes; + int max_mass_balance, count_mass_balance; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char string[2*MAX_LENGTH]; + LDBLE dummy; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "description", /* 11 */ + "desc", /* 12 */ + "descriptor" /* 13 */ + + }; + int count_opt_list = 14; + +/* + * look for solution number + */ + n_user = -1; + n_user_end = -1; + description = string_duplicate(""); + for (i = 0; i < heading->count; i++) { + if (strcmp_nocase(heading->char_vector[i], "number") == 0) { + break; + } + } + if (i == heading->count || data->type_vector[i] == EMPTY || data->count <= i) { + n_user = -1; +#ifdef SKIP + for (i = 0; i < count_solution; i++) { + if (n_user <= solution[i]->n_user) { + n_user = solution[i]->n_user + 1; + } + } +#endif + } else if (data->type_vector[i] == STRING) { + input_error++; + sprintf(error_string,"Expected solution number or number range in 'number' column, found: %s.", data->char_vector[i]); + error_msg(error_string, CONTINUE); + } else { + strcpy(string, "solution_s "); + strcat(string, data->char_vector[i]); + ptr = string; + description = (char *) free_check_null(description); + next_keyword_save = next_keyword; + next_keyword = 42; + read_number_description (ptr, &n_user, &n_user_end, &description); + next_keyword = next_keyword_save; + } +/* + * set up solution + */ + + if (n_user >= 0 && solution_bsearch(n_user, &n, FALSE) != NULL) { + solution_free(solution[n]); + } else { + n=count_solution++; + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); + } + } + solution[n] = solution_alloc(); + + solution[n]->n_user = n_user; + solution[n]->n_user_end = n_user_end; + if (use.solution_in == FALSE) { + use.solution_in = TRUE; + use.n_solution_user = n_user; + } + max_mass_balance=MAX_MASS_BALANCE; +/* + * Set default ph, temp, density, pe, units + */ + solution[n]->description = description; + solution[n]->tc=defaults.temp; + solution[n]->ph=defaults.ph; + solution[n]->density=defaults.density; + solution[n]->solution_pe = defaults.pe; + solution[n]->mass_water=defaults.water; + solution[n]->ah2o = 1.0; + solution[n]->mu = 1e-7; + solution[n]->cb = 0.0; + default_pe = 0; + solution[n]->units = defaults.units; + solution[n]->totals[0].description=NULL; + count_mass_balance=0; + count_isotopes = 0; + default_pe = pe_data_store (&(solution[n]->pe), defaults.redox); +/* + * Read concentration data + */ + return_value = UNKNOWN; + for (i = 0; i < heading->count; i++) { + if (strcmp_nocase(heading->char_vector[i], "number") == 0) continue; + if (strcmp_nocase(heading->char_vector[i], "uncertainty") == 0) continue; + if (strcmp_nocase(heading->char_vector[i], "uncertainties") == 0) continue; + if (strcmp_nocase(heading->char_vector[i], "isotope_uncertainty") == 0) continue; + /* + * Copy in element name + */ + if (heading->type_vector[i] == EMPTY) continue; + strcpy(string, heading->char_vector[i]); + strcat(string, " "); + /* + * Copy in concentration data + */ + if (i >= data->count || data->type_vector[i] == EMPTY) continue; + strcat(string, data->char_vector[i]); + strcat(string, " "); + /* + * Copy in concentration data + */ + if (units != NULL && i < units->count && units->type_vector[i] != EMPTY) { + strcat(string, units->char_vector[i]); + } +/* + * Parse string just like read_solution input + */ + next_char = string; + opt = get_option_string(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT && heading->type_vector[i] == NUMBER) { + opt = 9; + } + switch (opt) { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* temperature */ + case 1: + sscanf(next_char,SCANFORMAT, &(solution[n]->tc)); + break; + case 2: /* density */ + case 3: + sscanf(next_char,SCANFORMAT, &(solution[n]->density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (check_units (token, FALSE, FALSE, solution[n]->units, TRUE) == OK) { + solution[n]->units = string_hsave(token); + } else { + input_error++; + } + break; + case 5: /* redox */ + if (copy_token (token, &next_char, &l) == EMPTY) break; + if (parse_couple(token) == OK) { + default_pe = pe_data_store (&(solution[n]->pe), token); + } else { + input_error++; + } + break; + case 6: /* ph */ + next_char = string; + if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { + input_error++; + break; + } + solution[n]->ph = solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { + break; + } + solution[n]->totals[count_mass_balance].description = string_hsave("H(1)"); + count_mass_balance++; + break; + case 7: /* pe */ + next_char = string; + if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { + input_error++; + break; + } + solution[n]->solution_pe = solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { + break; + } + solution[n]->totals[count_mass_balance].description = string_hsave("E"); + count_mass_balance++; + break; + case 9: /* isotope */ + next_char = string; + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + solution[n]->isotopes = (struct isotope *) PHRQ_realloc(solution[n]->isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); + if (solution[n]->isotopes == NULL) malloc_error(); + /* read and save element name */ + ptr1 = token; + get_num(&ptr1, &(solution[n]->isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return(ERROR); + } + solution[n]->isotopes[count_isotopes].elt_name = string_hsave(ptr1); + + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio)); + + /* read and store isotope ratio uncertainty */ + /* first choice is next column */ + if ((i + 1) < heading->count && + (strcmp_nocase(heading->char_vector[i+1], "uncertainty") == 0 || + strcmp_nocase(heading->char_vector[i+1], "isotope_uncertainty") == 0 || + strcmp_nocase(heading->char_vector[i+1], "uncertainties") == 0) && + (i + 1) < data->count && + data->type_vector[i+1] == NUMBER) { + solution[n]->isotopes[count_isotopes].ratio_uncertainty = data->d_vector[i+1]; + } else { + next_char = string; + copy_token (token, &next_char, &l); + for (j = 0; j < defaults.count_iso; j++) { + if (strcmp(token, defaults.iso[j].name) == 0) { + solution[n]->isotopes[count_isotopes].ratio_uncertainty = defaults.iso[j].uncertainty; + break; + } + } + if (j == defaults.count_iso) { + solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; + } + } + count_isotopes++; + break; + case 10: /* water */ + j = copy_token (token, &next_char, &l); + if (j == EMPTY) { + solution[n]->mass_water=1.0; + } else if (j != DIGIT) { + input_error++; + sprintf(error_string, "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } else { + sscanf(token, SCANFORMAT, &dummy); + solution[n]->mass_water = (LDBLE) dummy; + } + break; + case 11: /* description */ + case 12: /* desc */ + case 13: /* descriptor */ + solution[n]->description = (char *) free_check_null(solution[n]->description); + solution[n]->description = string_duplicate(next_char); + break; + case OPTION_DEFAULT: +/* + * Read concentration + */ + next_char = string; + if (copy_token (token, &next_char, &l) == LOWER) continue; + next_char = string; + if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { +#ifdef SKIP + input_error++; + break; +#endif + } + count_mass_balance++; + break; + } + if (count_mass_balance + 1 >= max_mass_balance) { + space ((void **) &(solution[n]->totals), count_mass_balance + 1, + &max_mass_balance, sizeof (struct conc)); + } + if (return_value == EOF || return_value == KEYWORD) break; + } +/* + * Sort totals by description + */ + qsort (solution[n]->totals, + (size_t) count_mass_balance, + (size_t) sizeof(struct conc), + conc_compare); +/* + * fix up default units and default pe + */ + for (i=0; i < count_mass_balance; i++) { + strcpy(token, solution[n]->totals[i].description); + str_tolower(token); + if (solution[n]->totals[i].units == NULL) { + solution[n]->totals[i].units = solution[n]->units; + } else { + alk = FALSE; + if (strstr(token, "alk") == token) alk = TRUE; + strcpy(token1, solution[n]->totals[i].units); + if (check_units (token1, alk, TRUE, solution[n]->units, TRUE) == ERROR ) { + input_error++; + } else { + solution[n]->totals[i].units = string_hsave(token1); + } + } + if (solution[n]->totals[i].n_pe < 0) { + solution[n]->totals[i].n_pe = default_pe; + } + } + solution[n]->default_pe = default_pe; +/* + * Mark end of solution + */ + solution[n]->totals[count_mass_balance].description = NULL; + solution[n]->count_isotopes = count_isotopes; + if (count_isotopes > 0) { + qsort (solution[n]->isotopes, + (size_t) count_isotopes, + (size_t) sizeof(struct isotope), + isotope_compare); + } else { + solution[n]->isotopes = (struct isotope *) free_check_null(solution[n]->isotopes); + } + return(return_value); +} + +/* ---------------------------------------------------------------------- */ +struct spread_row *string_to_spread_row(char *string) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + int length = 10; + char token[MAX_LENGTH]; + char *ptr; + struct spread_row *spread_row_ptr; +/* + * Allocate space + */ + spread_row_ptr = (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); + if (spread_row_ptr == NULL) malloc_error(); + spread_row_ptr->char_vector = (char **) PHRQ_malloc((size_t) length * sizeof(char *)); + if (spread_row_ptr->char_vector == NULL) malloc_error(); + spread_row_ptr->d_vector = (LDBLE *) PHRQ_malloc((size_t) length * sizeof(LDBLE)); + if (spread_row_ptr->d_vector == NULL) malloc_error(); + spread_row_ptr->type_vector = (int *) PHRQ_malloc((size_t) length * sizeof(int)); + if (spread_row_ptr->type_vector == NULL) malloc_error(); + spread_row_ptr->count = 0; + spread_row_ptr->empty = 0; + spread_row_ptr->string = 0; + spread_row_ptr->number = 0; + ptr = string; +/* + * Split by tabs, reallocate space + */ + for (;;) { + if (spread_row_ptr->count + 1 > length) { + length *= 2; + + spread_row_ptr->char_vector = (char **) PHRQ_realloc(spread_row_ptr->char_vector, (size_t) length * sizeof(char *)); + if (spread_row_ptr->char_vector == NULL) malloc_error(); + + spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, (size_t) length * sizeof(LDBLE)); + if (spread_row_ptr->d_vector == NULL) malloc_error(); + + spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, (size_t) length * sizeof(int)); + if (spread_row_ptr->type_vector == NULL) malloc_error(); + } + j = copy_token_tab(token, &ptr, &l); + if (j == EOL) break; + spread_row_ptr->char_vector[spread_row_ptr->count] = string_duplicate(token); + spread_row_ptr->d_vector[spread_row_ptr->count] = NAN; + if (j == EMPTY || l == 0) { + spread_row_ptr->empty++; + spread_row_ptr->type_vector[spread_row_ptr->count] = EMPTY; + } else if (j == UPPER || j == LOWER) { + spread_row_ptr->string++; + spread_row_ptr->type_vector[spread_row_ptr->count] = STRING; + } else if (j == DIGIT) { + spread_row_ptr->number++; + spread_row_ptr->d_vector[spread_row_ptr->count] = strtod(token, NULL); + spread_row_ptr->type_vector[spread_row_ptr->count] = NUMBER; + } + spread_row_ptr->count++; + } +/* + * Clean up and return + */ + if (spread_row_ptr->count == 0) { + spread_row_ptr->char_vector = (char **) free_check_null(spread_row_ptr->char_vector); + spread_row_ptr->d_vector = (LDBLE *) free_check_null(spread_row_ptr->d_vector); + spread_row_ptr->type_vector = (int *) free_check_null(spread_row_ptr->type_vector); + } else { + spread_row_ptr->char_vector = (char **) PHRQ_realloc(spread_row_ptr->char_vector, (size_t) spread_row_ptr->count * sizeof(char *)); + if (spread_row_ptr->char_vector == NULL) malloc_error(); + spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, (size_t) spread_row_ptr->count * sizeof(LDBLE)); + if (spread_row_ptr->d_vector == NULL) malloc_error(); + spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, (size_t) spread_row_ptr->count * sizeof(int)); + if (spread_row_ptr->type_vector == NULL) malloc_error(); + + } + return (spread_row_ptr); +} +/* ---------------------------------------------------------------------- */ +int spread_row_free(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (spread_row_ptr == NULL) return(OK); + for (i = 0; i< spread_row_ptr->count; i++) { + spread_row_ptr->char_vector[i] = (char *) free_check_null(spread_row_ptr->char_vector[i]); + } + + spread_row_ptr->char_vector = (char **) free_check_null(spread_row_ptr->char_vector); + spread_row_ptr->d_vector = (double *) free_check_null(spread_row_ptr->d_vector); + spread_row_ptr->type_vector = (int *) free_check_null(spread_row_ptr->type_vector); + spread_row_ptr = (struct spread_row *) free_check_null(spread_row_ptr); + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int copy_token_tab(char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first tab is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * EOL, + * UNKNOWN. + */ + int i, j, return_value; + char c; +/* + * Strip leading spaces + */ + while ( (c=**ptr) == ' ' ) (*ptr)++; +/* + * Check what we have + */ + if ( isupper((int) c) ) { + return_value=UPPER; + } else if ( islower((int) c) ) { + return_value=LOWER; + } else if ( isdigit((int) c) || c=='.' || c=='-') { + return_value=DIGIT; + } else if ( c == '\0') { + return_value=EOL; + return(return_value); + } else if ( c == '\t') { + return_value=EMPTY; + } else { + return_value=UNKNOWN; + } +/* + * Begin copying to token + */ + i=0; +#ifdef SKIP + while ( (c=**ptr) != '\t' && + c != '\0' ) { + token_ptr[i]=c; + (*ptr)++; + i++; + } +#endif + for (;;) { + c=**ptr; + if (c == '\t') { + (*ptr)++; + break; + } else if (c =='\0') { + break; + } else { + token_ptr[i]=c; + (*ptr)++; + i++; + } + } + token_ptr[i]='\0'; + *length=i; +/* + * Strip trailing spaces + */ + for (j = i-1; j >= 0; j--) { + if (j != ' ') break; + } + if (j != i-1) { + token_ptr[j+1]='\0'; + *length=j+1; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +static int get_option_string (const char **opt_list, int count_opt_list, char **next_char) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line and check for options + */ + int j; + int opt_l, opt; + char *opt_ptr; + char option[MAX_LENGTH]; + + opt_ptr = *next_char; + if (opt_ptr[0] == '-') { + opt_ptr++; + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[1]), &opt, opt_list, count_opt_list, FALSE) == OK) { + j = opt; + *next_char = opt_ptr; + } else { + error_msg("Unknown option.", CONTINUE); + error_msg(*next_char, CONTINUE); + input_error++; + j = OPTION_ERROR; + } + } else { + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[0]), &opt, opt_list, count_opt_list, TRUE) == OK) { + j = opt; + *next_char = opt_ptr; + } else { + j = OPTION_DEFAULT; + } + } + return (j); +} +#ifdef PHREEQCI_GUI +/* ---------------------------------------------------------------------- */ +void free_spread(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + spread_row_free(g_spread_sheet.heading); + spread_row_free(g_spread_sheet.units); + for (i = 0; i < g_spread_sheet.count_rows; i++) + { + spread_row_free(g_spread_sheet.rows[i]); + } + g_spread_sheet.rows = free_check_null(g_spread_sheet.rows); + + for (i = 0; i < g_spread_sheet.defaults.count_iso; i++) + { + g_spread_sheet.defaults.iso[i].name = free_check_null(g_spread_sheet.defaults.iso[i].name); + } + g_spread_sheet.defaults.iso = free_check_null(g_spread_sheet.defaults.iso); + + g_spread_sheet.defaults.redox = free_check_null(g_spread_sheet.defaults.redox); + g_spread_sheet.defaults.units = free_check_null(g_spread_sheet.defaults.units); +} +/* ---------------------------------------------------------------------- */ +void add_row(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + g_spread_sheet.rows = (struct spread_row **) PHRQ_realloc(g_spread_sheet.rows, sizeof(struct spread_row*) * (g_spread_sheet.count_rows + 1)); + if (g_spread_sheet.rows == NULL) + { + malloc_error(); + } + else + { + g_spread_sheet.rows[g_spread_sheet.count_rows++] = copy_row(spread_row_ptr); + } +} +/* ---------------------------------------------------------------------- */ +struct spread_row *copy_row(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct spread_row *new_spread_row_ptr; +/* + * Allocate space + */ + new_spread_row_ptr = (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); + if (new_spread_row_ptr == NULL) malloc_error(); + new_spread_row_ptr->char_vector = (char **) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(char *)); + if (new_spread_row_ptr->char_vector == NULL) malloc_error(); + new_spread_row_ptr->d_vector = (LDBLE *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(LDBLE)); + if (new_spread_row_ptr->d_vector == NULL) malloc_error(); + new_spread_row_ptr->type_vector = (int *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(int)); + if (new_spread_row_ptr->type_vector == NULL) malloc_error(); + + for (i = 0; i < spread_row_ptr->count; i++) + { + new_spread_row_ptr->char_vector[i] = string_duplicate(spread_row_ptr->char_vector[i]); + new_spread_row_ptr->d_vector[i] = spread_row_ptr->d_vector[i]; + new_spread_row_ptr->type_vector[i] = spread_row_ptr->type_vector[i]; + } + new_spread_row_ptr->count = spread_row_ptr->count; + new_spread_row_ptr->empty = spread_row_ptr->empty; + new_spread_row_ptr->number = spread_row_ptr->number; + new_spread_row_ptr->string = spread_row_ptr->string; + + return new_spread_row_ptr; +} +/* ---------------------------------------------------------------------- */ +void copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + dest_ptr->count_iso = src_ptr->count_iso; + dest_ptr->density = src_ptr->density; + dest_ptr->iso = (struct iso*)PHRQ_malloc(sizeof(struct iso) * src_ptr->count_iso); + if (dest_ptr->iso == NULL) + { + malloc_error(); + } + else + { + for (i = 0; i < src_ptr->count_iso; i++) + { + dest_ptr->iso[i] = src_ptr->iso[i]; + dest_ptr->iso[i].name = string_duplicate(src_ptr->iso[i].name); + } + } + + dest_ptr->pe = src_ptr->pe; + dest_ptr->ph = src_ptr->ph; + dest_ptr->redox = string_duplicate(src_ptr->redox); + dest_ptr->temp = src_ptr->temp; + dest_ptr->units = string_duplicate(src_ptr->units); + dest_ptr->water = src_ptr->water; +} + +#endif diff --git a/step.cpp b/step.cpp new file mode 100644 index 00000000..1f60ae1d --- /dev/null +++ b/step.cpp @@ -0,0 +1,1028 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: step.c 406 2005-07-27 15:39:12Z dlpark $"; + +static int check_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr); +static int gas_phase_check (struct gas_phase *gas_phase_ptr); +static int pp_assemblage_check (struct pp_assemblage *pp_assemblage_ptr); +static int reaction_calc(struct irrev *irrev_ptr); +static int solution_check (void); +static int s_s_assemblage_check (struct s_s_assemblage *s_s_assemblage_ptr); + +/* ---------------------------------------------------------------------- */ +int step(LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * zero global solution, add solution or mixture, add exchange, + * add surface, add gas phase, add solid solutions, + * set temperature, and add reaction. + * Ensure all elements + * included in any of these are present in small amounts. + * Save result as n_user -1. + */ + LDBLE difftemp; + int step_number; + struct pp_assemblage *pp_assemblage_save = NULL; + struct s_s_assemblage *s_s_assemblage_save = NULL; + + if (svnid == NULL) fprintf(stderr," "); + +/* + * Zero out global solution data + */ + + xsolution_zero(); +/* + * Set reaction to zero + */ + step_x = 0.0; + step_number = reaction_step; +/* + * Mixing or solution + */ + if (use.mix_ptr != NULL) { + add_mix(use.mix_ptr); + } else if ( use.solution_ptr != NULL ) { + add_solution(use.solution_ptr, 1.0, 1.0); + } else { + input_error++; + error_msg("Neither mixing nor an initial solution have " + "been defined in reaction step.", STOP); + } +/* + * Reaction + */ + if(use.irrev_ptr != NULL) { + add_reaction(use.irrev_ptr, step_number, step_fraction); + } +/* + * Kinetics + */ + if(use.kinetics_ptr != NULL) { + add_kinetics(use.kinetics_ptr); + /* + master_ptr =master_bsearch("S(6)"); + output_msg(OUTPUT_MESSAGE,"Added kinetics, S(6) %e\n", master_ptr->total); + master_ptr =master_bsearch("S"); + output_msg(OUTPUT_MESSAGE,"Added kinetics, S %e\n", master_ptr->total); + */ + } +/* + * Exchange + */ + if (use.exchange_ptr != NULL) { + add_exchange(use.exchange_ptr); + } +/* + * Surface + */ + if (use.surface_ptr != NULL) { + add_surface(use.surface_ptr); + } +/* + * Gases + */ + if(use.gas_phase_ptr != NULL) { + add_gas_phase(use.gas_phase_ptr); + } +/* + * Temperature + */ + if(use.temperature_ptr != NULL) { + add_temperature(use.temperature_ptr, step_number); + } + if ((state == TRANSPORT) && (transport_step != 0) && + (cell > 0) && (cell != count_cells+1)) { + difftemp = tc_x - cell_data[cell-1].temp; + cell_data[cell-1].temp += difftemp/tempr; + tc_x = cell_data[cell-1].temp; + } +/* + * Pure phases and solid solutions are added to avoid + * zero or negative concentrations + */ +/* + * Pure phases + */ + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_save == NULL) malloc_error(); + pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); + add_pp_assemblage (use.pp_assemblage_ptr); + } +/* + * Solid solutions + */ + if(use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); + if (s_s_assemblage_save == NULL) malloc_error(); + s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); + add_s_s_assemblage(use.s_s_assemblage_ptr); + } +/* + * Check that elements are available for gas components, + * pure phases, and solid solutions + */ + if(use.gas_phase_ptr != NULL) { + gas_phase_check(use.gas_phase_ptr); + } + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_check (use.pp_assemblage_ptr); + } + if(use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_check(use.s_s_assemblage_ptr); + } +/* + * Check that element moles are >= zero + */ + if (solution_check() == MASS_BALANCE) { + /* reset moles and deltas */ + if (use.pp_assemblage_ptr != NULL) { + pp_assemblage_free(use.pp_assemblage_ptr); + pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, use.pp_assemblage_ptr->n_user); + pp_assemblage_free(pp_assemblage_save); + pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); + } + if (use.s_s_assemblage_ptr != NULL) { + s_s_assemblage_free(use.s_s_assemblage_ptr); + s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, use.s_s_assemblage_ptr->n_user); + s_s_assemblage_free(s_s_assemblage_save); + s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); + } + return(MASS_BALANCE); + } +/* + * Copy global into solution n_user = -1 + */ + xsolution_save(-1); + step_save_surf(-1); + step_save_exch(-1); +/* + * Clean up temporary space + */ + if (pp_assemblage_save != NULL) { + pp_assemblage_free(pp_assemblage_save); + pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); + } + if (s_s_assemblage_save != NULL) { + s_s_assemblage_free(s_s_assemblage_save); + s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int xsolution_zero (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Zero out _x variables, master->totals, and species->la + */ + int i; +/* + * Zero totals in master structures + */ + new_x = FALSE; + + tc_x = 0.0; + ph_x = 0.0; + solution_pe_x = 0.0; + mu_x = 0.0; + ah2o_x = 0.0; + density_x = 0.0; + total_h_x = 0.0; + total_o_x = 0.0; + cb_x = 0.0; + mass_water_aq_x = 0.0; + units_x = moles_per_kilogram_string; + + for (i=0; i < count_master; i++) { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + master[i]->s->la = 0.0; + } + if (pitzer_model == TRUE) { + for (i=0; i < count_s; i++) { + s[i]->lg = 0.0; + } + } +/* + * Copy pe data (not sure this will be used + */ +/* + pe_data_free (pe_x); + pe_x = pe_data_alloc(); + */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_solution (struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate solution data in master->totals and _x variables. + * + * extensive is multiplication factor for solution + * intensive is fraction of all multiplication factors for all solutions + */ + int i; + struct master *master_ptr; + struct species *species_ptr; +/* + * Add solution to global variables + */ + tc_x += solution_ptr->tc * intensive; + ph_x += solution_ptr->ph * intensive; + solution_pe_x += solution_ptr->solution_pe * intensive; + mu_x += solution_ptr->mu * intensive; + ah2o_x += solution_ptr->ah2o * intensive; + density_x += solution_ptr->density * intensive; + + total_h_x += solution_ptr->total_h * extensive; + total_o_x += solution_ptr->total_o * extensive; + cb_x += solution_ptr->cb * extensive; + mass_water_aq_x += solution_ptr->mass_water * extensive; +/* + * Copy totals data into primary master species + */ + for (i=0; solution_ptr->totals[i].description != NULL; i++) { + master_ptr = master_bsearch_primary(solution_ptr->totals[i].description); + master_ptr->total += solution_ptr->totals[i].moles * extensive; + } +/* + * Accumulate initial guesses for activities + */ + /*for (i=0; solution_ptr->master_activity[i].description != NULL; i++) {*/ + for (i=0; i < solution_ptr->count_master_activity; i++) { + if (solution_ptr->master_activity[i].description != NULL) { + master_ptr = master_bsearch(solution_ptr->master_activity[i].description); + if (master_ptr != NULL) { + master_ptr->s->la += solution_ptr->master_activity[i].la * intensive; + } + } + } +/* + * Accumulate initial guesses for log gamma + */ + if (pitzer_model == TRUE) { + for (i=0; i < solution_ptr->count_species_gamma ; i++) { + species_ptr = s_search(solution_ptr->species_gamma[i].description); + if (species_ptr != NULL) { + species_ptr->lg += solution_ptr->species_gamma[i].la * intensive; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_exchange (struct exchange *exchange_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate exchange data in master->totals and _x variables. + */ + int i, j; + struct master *master_ptr; + + if (exchange_ptr == NULL) return(OK); +/* + * Add element concentrations on exchanger to master species totals + */ + for (i = 0; i < exchange_ptr->count_comps; i++) { + for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) { + master_ptr = exchange_ptr->comps[i].totals[j].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += exchange_ptr->comps[i].totals[j].coef; + } else if (master_ptr->s == s_h2o) { + total_o_x += exchange_ptr->comps[i].totals[j].coef; + } else { + master_ptr->total += exchange_ptr->comps[i].totals[j].coef; + } + } + } + if (exchange_ptr->new_def == TRUE) { + for (i = 0; i < count_master; i++) { + if (master[i]->type == EX && master[i]->total > 0) { + master[i]->s->la = log10(0.1 * master[i]->total); + } + } + } else { + for (i = 0; i < exchange_ptr->count_comps; i++) { + exchange_ptr->comps[i].master->s->la = exchange_ptr->comps[i].la; + cb_x += exchange_ptr->comps[i].charge_balance; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_surface (struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate surface data in master->totals and _x variables. + */ + int i, j; + struct master *master_ptr; + + if (surface_ptr == NULL) return(OK); +/* + * Add element concentrations on surface to master species totals + */ + diffuse_layer_x = surface_ptr->diffuse_layer; + for (i = 0; i < surface_ptr->count_comps; i++) { + if(surface_ptr->edl == FALSE) { + cb_x += surface_ptr->comps[i].cb; + } + if (surface_ptr->new_def == FALSE) { + surface_ptr->comps[i].master->s->la = surface_ptr->comps[i].la; + } +/* + * Add surface and specifically sorbed elements + */ + for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) { + master_ptr = surface_ptr->comps[i].totals[j].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += surface_ptr->comps[i].totals[j].coef; + } else if (master_ptr->s == s_h2o) { + total_o_x += surface_ptr->comps[i].totals[j].coef; + } else { + master_ptr->total += surface_ptr->comps[i].totals[j].coef; + } + } + } + if (surface_ptr->edl == FALSE) return(OK); + for (i = 0; i < surface_ptr->count_charge; i++) { + if (surface_ptr->edl == TRUE) { + cb_x += surface_ptr->charge[i].charge_balance; + } + if (surface_ptr->new_def == FALSE) { + surface_ptr->charge[i].psi_master->s->la = surface_ptr->charge[i].la_psi; + } +/* + * Add diffuse layer elements (including water in Debye layer) + */ + if (surface_ptr->diffuse_layer == TRUE && surface_ptr->new_def == FALSE) { + for (j = 0; surface_ptr->charge[i].diffuse_layer_totals[j].elt != NULL; j++) { + master_ptr = surface_ptr->charge[i].diffuse_layer_totals[j].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } else if (master_ptr->s == s_h2o) { + total_o_x += surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } else { + master_ptr->total += surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_mix (struct mix *mix_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * calls add_solution to accumulate all data in master->totals + * and other variables. + */ + int i; + int n; + LDBLE sum_fractions, intensive, extensive; + struct solution *solution_ptr; + int count_positive; + LDBLE sum_positive; + + if (mix_ptr == NULL) return(OK); + if (mix_ptr->count_comps <= 0) return(OK); + sum_fractions = 0.0; + sum_positive = 0.0; + count_positive = 0; + for (i = 0; i < mix_ptr->count_comps; i++) { + sum_fractions += mix_ptr->comps[i].fraction; + if (mix_ptr->comps[i].fraction > 0) { + sum_positive += mix_ptr->comps[i].fraction; + count_positive++; + } + } + for (i = 0; i < mix_ptr->count_comps; i++) { + solution_ptr = solution_bsearch (mix_ptr->comps[i].n_solution, &n, TRUE); + if (solution_ptr == NULL) { + input_error++; + continue; + } + extensive = mix_ptr->comps[i].fraction; + intensive = extensive / sum_fractions; + if (count_positive < mix_ptr->count_comps) { + if (mix_ptr->comps[i].fraction > 0) { + intensive = extensive / sum_positive; + } else { + intensive = 0; + } + } + add_solution(solution_ptr, extensive, intensive); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add a small amount of each phase if necessary to insure + * all elements exist in solution. + */ + int i, j; + LDBLE amount_to_add, total; + char token[MAX_LENGTH]; + char *ptr; + struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) return(OK); +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + pure_phase_ptr = pp_assemblage_ptr->pure_phases; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { + count_elts = 0; + paren_count = 0; + amount_to_add = 0.0; + pure_phase_ptr[j].delta = 0.0; + if (pure_phase_ptr[j].add_formula != NULL) { + strcpy(token, pure_phase_ptr[j].add_formula); + ptr = &(token[0]); + get_elts_in_species (&ptr, 1.0); + } else { + strcpy(token, pure_phase_ptr[j].phase->formula); + add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); + } + if (pure_phase_ptr[j].moles > 0.0) { + for (i = 0; i < count_elts; i++) { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } else if (master_ptr->total > MIN_TOTAL) { + continue; + } else { + total = (-master_ptr->total + 1e-10) / elt_list[i].coef; + if (amount_to_add < total) { + amount_to_add = total; + } + } + } + if (pure_phase_ptr[j].moles < amount_to_add) { + amount_to_add = pure_phase_ptr[j].moles; + } + } + if (amount_to_add > 0.0) { + pure_phase_ptr[j].moles -= amount_to_add; + pure_phase_ptr[j].delta = amount_to_add; +/* + * Add reaction to totals + */ + for (i = 0; i < count_elts; i++) { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += elt_list[i].coef * amount_to_add; + } else if (master_ptr->s == s_h2o) { + total_o_x += elt_list[i].coef * amount_to_add; + } else { + master_ptr->total += elt_list[i].coef * amount_to_add; + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int check_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check list of all elements in pure_phase assemblage to see + * if all are in model. Return true if all are present, + * Return false if one or more is missing. + */ + int j; + struct master *master_ptr; + for (j = 0; pp_assemblage_ptr->next_elt[j].elt != NULL; j++) { + master_ptr = pp_assemblage_ptr->next_elt[j].elt->primary; + if (master_ptr->s == s_h2o || master_ptr->s == s_hplus) continue; + if (master_ptr->total > MIN_TOTAL) continue; + return(FALSE); + } + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int add_reaction (struct irrev *irrev_ptr, int step_number, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add irreversible reaction + */ + int i; + char c; + struct master *master_ptr; +/* + * Calculate and save reaction + */ +/* !!!!! with kinetics reaction, coeff's may change + * and reaction_calc must be called .... + */ + if (irrev_ptr->elts == NULL ) { + if (reaction_calc(irrev_ptr) == ERROR) { + return(ERROR); + } + } +/* + * Step size + */ + if (incremental_reactions == FALSE) { + if (irrev_ptr->count_steps > 0) { + if (step_number > irrev_ptr->count_steps) { + step_x = irrev_ptr->steps[irrev_ptr->count_steps - 1]; + } else { + step_x = irrev_ptr->steps[step_number - 1]; + } + } else if (irrev_ptr->count_steps < 0) { + if (step_number > -irrev_ptr->count_steps) { + step_x = irrev_ptr->steps[0]; + } else { + step_x = irrev_ptr->steps[0] * + ( (LDBLE) step_number ) / ( (LDBLE) (-irrev_ptr->count_steps)); + } + } else { + step_x = 0.0; + } + } else { + /* Incremental reactions */ + if (irrev_ptr->count_steps > 0) { + if (step_number > irrev_ptr->count_steps) { + step_x = irrev_ptr->steps[irrev_ptr->count_steps - 1]; + } else { + step_x = irrev_ptr->steps[step_number - 1]; + } + } else if (irrev_ptr->count_steps < 0) { + if (step_number > -irrev_ptr->count_steps) { + step_x = 0; + } else { + step_x = irrev_ptr->steps[0] / ( (LDBLE) (-irrev_ptr->count_steps)); + } + } else { + step_x = 0.0; + } + } +/* + * Convert units + */ + c = irrev_ptr->units[0]; + if (c == 'm') { + step_x *= 1e-3; + } else if (c == 'u') { + step_x *= 1e-6; + } else if (c == 'n') { + step_x *= 1e-9; + } +/* + * Add reaction to totals + */ + for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) { + master_ptr = irrev_ptr->elts[i].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += irrev_ptr->elts[i].coef * step_x * step_fraction; + } else if (master_ptr->s == s_h2o) { + total_o_x += irrev_ptr->elts[i].coef * step_x * step_fraction; + } else { + master_ptr->total += irrev_ptr->elts[i].coef * step_x * step_fraction; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int reaction_calc(struct irrev *irrev_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through irreversible reaction initially to + * determine a list of elements and amounts in + * the reaction. + */ + int i, j, return_value; + LDBLE coef; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + return_value = OK; + count_elts = 0; + paren_count = 0; + + for (i=0; i < irrev_ptr->count_list; i++) { + coef = irrev_ptr->list[i].coef; + strcpy(token, irrev_ptr->list[i].name); + phase_ptr = phase_bsearch(token, &j, FALSE); +/* + * Reactant is a pure phase, copy formula into token + */ + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, coef); + } else { + ptr = &(token[0]); + get_elts_in_species (&ptr, coef); + } + } +/* + * Check that all elements are in database + */ + for (i = 0; i < count_elts; i++) { + if (elt_list[i].elt->master == NULL) { + sprintf(error_string, "Element or phase not defined in database, %s.", elt_list[i].elt->name); + error_msg(error_string, CONTINUE); + input_error++; + return_value = ERROR; + } + } + irrev_ptr->elts = elt_list_save(); + + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int add_temperature (struct temperature *temperature_ptr, int step_number) +/* ---------------------------------------------------------------------- */ +{ +/* + * Determine temperature of reaction step, if reaction_temperature + * information is present. + */ + int denom; + LDBLE tc_temp; +/* + * Find temperature + */ + if (temperature_ptr == NULL) return(ERROR); + if (temperature_ptr->count_t > 0) { + if (step_number > temperature_ptr->count_t) { + tc_temp = temperature_ptr->t[temperature_ptr->count_t - 1]; + } else { + tc_temp = temperature_ptr->t[step_number - 1]; + } + } else if (temperature_ptr->count_t < 0) { + if (step_number > -temperature_ptr->count_t) { + tc_temp = temperature_ptr->t[1]; + } else { + if (-temperature_ptr->count_t <= 1) { + denom = 1; + } else { + denom = -temperature_ptr->count_t - 1; + } + tc_temp = temperature_ptr->t[0] + (temperature_ptr->t[1] - temperature_ptr->t[0]) * + ( (LDBLE) (step_number - 1) ) / ( (LDBLE) denom ); + } + } else { + tc_temp = 25.0; + } + tc_x = tc_temp; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_gas_phase (struct gas_phase *gas_phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate gas data in master->totals and _x variables. + */ + int i; + + struct gas_comp *gas_comp_ptr; + struct master *master_ptr; + + if (gas_phase_ptr == NULL) return(OK); + gas_comp_ptr = gas_phase_ptr->comps; +/* + * calculate reaction + */ + count_elts = 0; + paren_count = 0; + for (i = 0; i < gas_phase_ptr->count_comps; i++) { + add_elt_list(gas_comp_ptr[i].phase->next_elt, gas_comp_ptr[i].moles); + } +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } +/* + * Add gas elements to totals + */ + for (i = 0; i < count_elts; i++) { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += elt_list[i].coef; + } else if (master_ptr->s == s_h2o) { + total_o_x += elt_list[i].coef; + } else { + master_ptr->total += elt_list[i].coef; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_s_s_assemblage (struct s_s_assemblage *s_s_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate solid_solution data in master->totals and _x variables. + */ + int i, j, k; + LDBLE amount_to_add, total; + struct s_s *s_s_ptr; + struct master *master_ptr; + char token[MAX_LENGTH]; + char *ptr; + + if (s_s_assemblage_ptr == NULL) return(OK); + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { + count_elts = 0; + paren_count = 0; + s_s_ptr = &(s_s_assemblage_ptr->s_s[i]); + for (j = 0; j < s_s_ptr->count_comps; j++) { + amount_to_add = 0.0; + s_s_ptr->comps[j].delta = 0.0; + if (s_s_ptr->comps[j].moles > 0.0) { + strcpy(token, s_s_ptr->comps[j].phase->formula); + ptr = &(token[0]); + get_elts_in_species (&ptr, 1.0); + for (k = 0; k < count_elts; k++) { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } else if (master_ptr->total > MIN_TOTAL) { + continue; + } else { + total = (-master_ptr->total + 1e-10) / elt_list[k].coef; + if (amount_to_add < total) { + amount_to_add = total; + } + } + } + } + if (s_s_ptr->comps[j].moles < amount_to_add) { + amount_to_add = s_s_ptr->comps[j].moles; + } + if (amount_to_add > 0.0) { + s_s_ptr->comps[j].moles -= amount_to_add; + s_s_ptr->comps[j].delta = amount_to_add; +/* + * Add reaction to totals + */ + for (k = 0; k < count_elts; k++) { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) { + total_h_x += elt_list[k].coef * amount_to_add; + } else if (master_ptr->s == s_h2o) { + total_o_x += elt_list[k].coef * amount_to_add; + } else { + master_ptr->total += elt_list[k].coef * amount_to_add; + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_kinetics (struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add kinetic reaction + */ + int i; + struct master *master_ptr; +/* + * Add reaction to totals + */ + if (kinetics_ptr->totals == NULL) return(OK); + for (i = 0; kinetics_ptr->totals[i].elt != NULL; i++) { + master_ptr = kinetics_ptr->totals[i].elt->primary; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Element %s in kinetic reaction not found in database.", kinetics_ptr->totals[i].elt->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) { + total_h_x += kinetics_ptr->totals[i].coef; + } else if (master_ptr->s == s_h2o) { + total_o_x += kinetics_ptr->totals[i].coef; + } else { + master_ptr->total += kinetics_ptr->totals[i].coef; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_check (struct gas_phase *gas_phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i, j; + + struct gas_comp *gas_comp_ptr; + struct master *master_ptr; + + if (gas_phase_ptr == NULL) return(OK); + gas_comp_ptr = gas_phase_ptr->comps; +/* + * Check that all elements are in solution for phases with zero mass + */ + for (i = 0; i < gas_phase_ptr->count_comps; i++) { + count_elts = 0; + paren_count = 0; + if (gas_comp_ptr[i].moles <= 0.0) { + add_elt_list(gas_comp_ptr[i].phase->next_elt, 1.0); + for (j = 0; j < count_elts; j++) { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } else if (master_ptr->total > MIN_TOTAL) { + continue; + } else { + if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { + sprintf(error_string, "Element %s is contained in gas %s (which has 0.0 mass),\nbut is not in solution or other phases.", elt_list[j].elt->name, gas_comp_ptr[i].phase->name); + warning_msg(error_string); + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_check (struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i, j, k; + char token[MAX_LENGTH]; + char *ptr; + struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) return(OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + pure_phase_ptr = pp_assemblage_ptr->pure_phases; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { + count_elts = 0; + paren_count = 0; + if (pure_phase_ptr[j].moles <= 0.0) { + pure_phase_ptr[j].delta = 0.0; + if (pure_phase_ptr[j].add_formula != NULL) { + strcpy(token, pure_phase_ptr[j].add_formula); + ptr = &(token[0]); + get_elts_in_species (&ptr, 1.0); + } else { + strcpy(token, pure_phase_ptr[j].phase->formula); + add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); + } + for (i = 0; i < count_elts; i++) { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } else if (master_ptr->total > MIN_TOTAL) { + continue; + } else { + if (state != ADVECTION && state != TRANSPORT && state != PHAST) { + sprintf(error_string, "Element %s is contained in %s (which has 0.0 mass)," + "\t\nbut is not in solution or other phases.", elt_list[i].elt->name, pure_phase_ptr[j].phase->name); + warning_msg(error_string); + } +/* + * Make la's of all master species for the element small, so SI will be small + * and no mass transfer will be calculated + */ + for (k = 0; k < count_master; k++) { + if (master[k]->elt->primary == master_ptr) { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_check (struct s_s_assemblage *s_s_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i, j, k, l; + struct master *master_ptr; + + if (s_s_assemblage_ptr == NULL) return(OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { + for (j = 0; j < s_s_assemblage_ptr->s_s[i].count_comps; j++) { + count_elts = 0; + paren_count = 0; + if (s_s_assemblage_ptr->s_s[i].comps[j].moles <= 0.0) { + add_elt_list(s_s_assemblage_ptr->s_s[i].comps[j].phase->next_elt, 1.0); + for (l = 0; l < count_elts; l++) { + master_ptr = elt_list[l].elt->primary; + if (master_ptr->s == s_hplus) { + continue; + } else if (master_ptr->s == s_h2o) { + continue; + } else if (master_ptr->total > MIN_TOTAL) { + continue; + } else { + if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { + sprintf(error_string, "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.", elt_list[l].elt->name, s_s_assemblage_ptr->s_s[i].comps[j].phase->name); + warning_msg(error_string); + } + } + /* + * Make la's of all master species for the element small, + * so SI will be small + * and no mass transfer will be calculated + */ + for (k = 0; k < count_master; k++) { + if (master[k]->elt->primary == master_ptr) { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solution_check (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i; + struct master *master_ptr; + +/* + * Check that all elements are in solution for phases with zero mass + */ + for (i =0; i < count_master; i++) { + master_ptr = master[i]; + if (master_ptr->total >= 0.0) continue; + if (master_ptr->total > -MIN_TOTAL) { + master_ptr->total = 0; + continue; + } + if (master_ptr->s == s_eminus || master_ptr->s == s_h2o || master_ptr->s == s_hplus || master_ptr->s == s_h3oplus) { + master_ptr->total = 0; + continue; + } + sprintf(error_string, "Element %s has negative moles in solution, %e. \n\tErroneous mole balance occurs as moles are added to produce zero moles.\n\tUsually caused by KINETICS, REACTION, or diffuse layer calculation.\n\tMay be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer.", master_ptr->elt->name, (double) master_ptr->total); + warning_msg(error_string); + return(MASS_BALANCE); + } + return(OK); +} diff --git a/structures.cpp b/structures.cpp new file mode 100644 index 00000000..eab00142 --- /dev/null +++ b/structures.cpp @@ -0,0 +1,6059 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: structures.c 715 2006-01-18 01:26:29Z dlpark $"; + +static int exchange_compare_int(const void *ptr1, const void *ptr2); +static int gas_phase_compare_int(const void *ptr1, const void *ptr2); + +static int inverse_compare(const void *ptr1, const void *ptr2); +static int inverse_free (struct inverse *inverse_ptr); + +static int irrev_compare (const void *ptr1, const void *ptr2); +static int irrev_compare_int(const void *ptr1, const void *ptr2); +static int irrev_sort(void); + +static int kinetics_compare_int(const void *ptr1, const void *ptr2); + +static int logk_init(struct logk *logk_ptr); + +static int master_compare_string (const void *ptr1, const void *ptr2); +static int master_free(struct master *master_ptr); + +#if defined(PHREEQCI_GUI) +int mix_compare (const void *ptr1, const void *ptr2); +#else +static int mix_compare (const void *ptr1, const void *ptr2); +#endif +static int mix_compare_int(const void *ptr1, const void *ptr2); + +static struct phase *phase_alloc(void); +static int phase_compare_string (const void *ptr1, const void *ptr2); +static int phase_free(struct phase *phase_ptr); +static int phase_init(struct phase *phase_ptr); + +static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); + +static int rate_compare (const void *ptr1, const void *ptr2); +static int rate_compare_string (const void *ptr1, const void *ptr2); + +static struct species *s_alloc(void); +static int s_free (struct species *s_ptr); +static int s_init(struct species *s_ptr); + +static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); + +static int solution_compare(const void *ptr1, const void *ptr2); +static int solution_compare_int(const void *ptr1, const void *ptr2); +static struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); + +static int species_list_compare (const void *ptr1, const void *ptr2); + +static int surface_compare_int(const void *ptr1, const void *ptr2); + +static int temperature_compare (const void *ptr1, const void *ptr2); +static int temperature_compare_int(const void *ptr1, const void *ptr2); + +static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); +static int trxn_multiply (LDBLE coef); + +#ifdef PHREEQCI_GUI +extern void free_spread(void); +#endif +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern void MergeFinalize(void); +#endif + +/* ---------------------------------------------------------------------- */ +int clean_up(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all allocated memory, except strings + */ + int i, j; + if (svnid == NULL) fprintf(stderr," "); + + description_x = (char *) free_check_null(description_x); + isotopes_x = (struct isotope *) free_check_null(isotopes_x); + moles_per_kilogram_string = (char *) free_check_null(moles_per_kilogram_string); + pe_string = (char *) free_check_null(pe_string); +/* model */ + last_model.exchange = (struct master **) free_check_null(last_model.exchange); + last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); + last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); + last_model.add_formula = (char **) free_check_null(last_model.add_formula); + last_model.si = (double *) free_check_null(last_model.si); + last_model.surface_comp = (struct master **) free_check_null(last_model.surface_comp); + last_model.surface_charge = (struct master **) free_check_null(last_model.surface_charge); + + /* model */ + free_model_allocs(); + +/* species */ + + for (j=0; jname, element_ptr2->name)); */ + return(strcmp(element_ptr1->name, element_ptr2->name)); + +} +/* ---------------------------------------------------------------------- */ +struct element *element_store (char *element) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "element" in the hash table for elements. + * + * If found, pointer to the appropriate element structure is returned. + * + * If the string is not found, a new entry is made at the end of + * the elements array (position count_elements) and count_elements is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * + * Arguments: + * element input, character string to be located or stored. + * + * Returns: + * The address of an elt structure that contains the element data. + */ + int n; + struct element *elts_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + item.key = element; + item.data = NULL; + found_item = hsearch_multi(elements_hash_table, item, FIND); + if (found_item != NULL) { + elts_ptr = (struct element *) (found_item->data); + return (elts_ptr); + } +/* + * Save new elt structure and return pointer to it + */ + /* make sure there is space in elements */ + elements[count_elements] = (struct element *) PHRQ_malloc((size_t) sizeof(struct element)); + if (elements[count_elements] == NULL) malloc_error(); + /* set name pointer in elements structure */ + elements[count_elements]->name=string_hsave( element ); + /* set return value */ + elements[count_elements]->master = NULL; + elements[count_elements]->primary = NULL; + elements[count_elements]->gfw = 0.0; + n = count_elements++; + if (count_elements >= max_elements) { + space ((void **) ((void *) &elements), count_elements, &max_elements, sizeof(struct element *)); + } +/* + * Update hash table + */ + item.key = elements[n]->name; + item.data = (void *) elements[n]; + found_item = hsearch_multi(elements_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in element_store."); + error_msg(error_string, CONTINUE); + } + return (elements[n]); +} +/* ********************************************************************** + * + * Routines related to structure "elt_list" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int elt_list_combine(void) +/* ---------------------------------------------------------------------- */ +/* + * Function goes through the list of elements pointed to by elt_list + * and combines the coefficients of elements that are the same. + * Assumes elt_list has been sorted by element name. + */ +{ + int i, j; + + if (count_elts < 1 ) { + output_msg(OUTPUT_MESSAGE, "elt_list_combine: How did this happen?\n"); + return(ERROR); + } + if (count_elts == 1 ) { + return(OK); + } + j=0; + for ( i=1; i < count_elts; i++) { + if ( elt_list[i].elt == elt_list[j].elt ) { + elt_list[j].coef += elt_list[i].coef; + } else { + j++; + if ( i != j ) { + elt_list[j].elt=elt_list[i].elt; + elt_list[j].coef=elt_list[i].coef; + } + } + } + count_elts=j+1; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int elt_list_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct elt_list *a, *b; + + a=(const struct elt_list *) ptr1; + b=(const struct elt_list *) ptr2; + return( strncmp( a->elt->name, b->elt->name, MAX_LENGTH)); +} +/* ---------------------------------------------------------------------- */ +struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates the elt_list structure pointed to by elt_list_ptr_old. + */ + int i, count_totals; + struct elt_list *elt_list_ptr_new; +/* + * Count totals data and copy + */ + if (elt_list_ptr_old == NULL) return (NULL); + for (i = 0; elt_list_ptr_old[i].elt != NULL; i++); + count_totals = i; +/* + * Malloc space and store element data + */ + elt_list_ptr_new = (struct elt_list *) PHRQ_malloc( (size_t) (count_totals + 1) + * sizeof(struct elt_list)); + if (elt_list_ptr_new == NULL ) malloc_error(); + memcpy(elt_list_ptr_new, elt_list_ptr_old, + (size_t) (count_totals + 1) * sizeof(struct elt_list)); + return (elt_list_ptr_new); +} +/* ---------------------------------------------------------------------- */ +int elt_list_print(struct elt_list *elt_list_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates the elt_list structure pointed to by elt_list_ptr_old. + */ + int i; +/* + * Debug print for element list + */ + if (elt_list_ptr == NULL) return (ERROR); + output_msg(OUTPUT_MESSAGE, "Elt_list\n"); + for (i = 0; elt_list_ptr[i].elt != NULL; i++) { + output_msg(OUTPUT_MESSAGE, "\t%s\t%e\n", elt_list_ptr[i].elt->name, (double) elt_list_ptr[i].coef); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int elt_list_print0(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates the elt_list structure pointed to by elt_list_ptr_old. + */ + int i; +/* + * Debug print for element list + */ + output_msg(OUTPUT_STDERR, "Elt_list\n"); + for (i = 0; i < count_elts; i++) { + output_msg(OUTPUT_STDERR, "\t%s\t%e\n", elt_list[i].elt->name, (double) elt_list[i].coef); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +struct elt_list *elt_list_save(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes data from work space elt_list, allocates a new elt_list structure, + * copies data from work space to new structure, and returns pointer to + * new structure. + */ + int j; + struct elt_list *elt_list_ptr; +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } +/* + * Malloc space and store element data + */ + elt_list_ptr=(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1)*sizeof(struct elt_list)); + if (elt_list_ptr == NULL ) malloc_error(); + for ( j=0; j < count_elts; j++ ) { + elt_list_ptr[j].elt=elt_list[j].elt; + elt_list_ptr[j].coef=elt_list[j].coef; + } + elt_list_ptr[count_elts].elt=NULL; + return (elt_list_ptr); +} +/* ********************************************************************** + * + * Routines related to structure "exchange" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct exchange *exchange_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct exchange *exchange_ptr; + exchange_ptr = (struct exchange *) PHRQ_malloc(sizeof (struct exchange)); + if (exchange_ptr == NULL) malloc_error(); + exchange_ptr->description = NULL; + exchange_ptr->count_comps = 0; + exchange_ptr->comps = NULL; + return ( exchange_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct exchange *exchange_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search exchange to find if user exchange number k exists. + * Exchange is assumed to be in sort order by user number. + */ + void *void_ptr; + if (count_exchange == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) exchange, + (size_t) count_exchange, + (size_t) sizeof(struct exchange), + exchange_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct exchange *) void_ptr - exchange); + return ( (struct exchange *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int exchange_comp_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct exch_comp *exch_comp_ptr1, *exch_comp_ptr2; + exch_comp_ptr1 = (const struct exch_comp *) ptr1; + exch_comp_ptr2 = (const struct exch_comp *) ptr2; + return(strcmp_nocase(exch_comp_ptr1->master->elt->name, exch_comp_ptr2->master->elt->name)); +} +/* ---------------------------------------------------------------------- */ +int exchange_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct exchange *exchange_ptr1, *exchange_ptr2; + exchange_ptr1 = (const struct exchange *) ptr1; + exchange_ptr2 = (const struct exchange *) ptr2; + if (exchange_ptr1->n_user > exchange_ptr2->n_user) return(1); + if (exchange_ptr1->n_user < exchange_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int exchange_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare exchange user numbers + */ + const int *nptr1; + const struct exchange *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct exchange *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int exchange_copy(struct exchange *exchange_old_ptr, + struct exchange *exchange_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies exchange data from exchange_old_ptr to new location, exchange_new_ptr. + * Space for the exchange_new_ptr structure must already be malloced. + * Space for exchange components is malloced here. + */ + int count_comps, i; + char token[MAX_LENGTH]; +/* + * Store data for structure exchange + */ + memcpy(exchange_new_ptr, exchange_old_ptr, sizeof(struct exchange)); + exchange_new_ptr->n_user = n_user_new; + exchange_new_ptr->n_user_end = n_user_new; + count_comps = exchange_old_ptr->count_comps; + exchange_new_ptr->new_def = exchange_old_ptr->new_def; + exchange_new_ptr->solution_equilibria = FALSE; + exchange_new_ptr->n_solution = -2; + exchange_new_ptr->count_comps = count_comps; + sprintf(token, "Exchanger defined in simulation %d.", simulation); + exchange_new_ptr->description = string_duplicate(token); +/* + * Count exchange components and allocate space + */ + exchange_new_ptr->comps = (struct exch_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct exch_comp)); + if (exchange_new_ptr->comps == NULL) malloc_error(); +/* + * Write exch_comp structure for each exchange component + */ + memcpy(exchange_new_ptr->comps, exchange_old_ptr->comps, + (size_t) (count_comps) * sizeof (struct exch_comp)); + for ( i = 0; i < count_comps; i++) { + exchange_new_ptr->comps[i].totals = elt_list_dup(exchange_old_ptr->comps[i].totals); + exchange_new_ptr->comps[i].formula_totals = elt_list_dup(exchange_old_ptr->comps[i].formula_totals); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an exchange definition from position n to position count_exchange. + * New exchange structure is given user number n_user. + */ + space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); + exchange_copy(&exchange[n], &exchange[count_exchange], n_user); + count_exchange++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array exchange. + */ +{ + int i; + int n_old; + struct exchange *exchange_ptr_old; +/* + * Find n_user_old in structure array + */ + exchange_ptr_old = exchange_bsearch(n_user_old, &n_old); + if (exchange_ptr_old != NULL) { + /* + * Delete exchange + */ + exchange_free(&exchange[n_old]); + + for(i = n_old + 1; i < count_exchange; i++) { + memcpy( (void *) &exchange[i - 1], (void *) &exchange[i], + (size_t) sizeof (struct exchange) ); + } + count_exchange--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies exchange[n_user_old] to old n_user_new space if + * found or to exchange[count_exchange] if not found. + * Exchange array may not be in sort order after the copy. + */ + int sort; + int n_old, n_new; + struct exchange *exchange_ptr_old, *exchange_ptr_new; +/* + * Find n_user_old in structure array exchange + */ + if (n_user_old == n_user_new) return(OK); + exchange_ptr_old = exchange_bsearch(n_user_old, &n_old); + if (exchange_ptr_old == NULL) { + sprintf(error_string, "Exchange %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array exchange or make new space + */ + sort = FALSE; + exchange_ptr_new = exchange_bsearch(n_user_new, &n_new); + if (exchange_ptr_new != NULL) { + exchange_free(exchange_ptr_new); + } else { + space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); + if (n_user_new < exchange[count_exchange-1].n_user) sort = TRUE; + n_new = count_exchange++; + } +/* + * Copy data + */ + exchange_copy(&exchange[n_old], &exchange[n_new], n_user_new); + if (sort == TRUE) exchange_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_free (struct exchange *exchange_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data associated with exchange structure. + */ + int i; + if (exchange_ptr == NULL) return(ERROR); +/* + * Free space allocated for exchange structure + */ + exchange_ptr->description = (char *) free_check_null (exchange_ptr->description); + for (i=0; i < exchange_ptr->count_comps; i++) { + exchange_ptr->comps[i].totals = (struct elt_list *) free_check_null (exchange_ptr->comps[i].totals); + exchange_ptr->comps[i].formula_totals = (struct elt_list *) free_check_null (exchange_ptr->comps[i].formula_totals); + } + exchange_ptr->comps = (struct exch_comp *) free_check_null (exchange_ptr->comps); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_init (struct exchange *exchange_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data associated with exchange structure. + */ + + if (exchange_ptr == NULL) return(ERROR); + exchange_ptr->n_user = n_user; + exchange_ptr->n_user_end = n_user_end; + exchange_ptr->new_def = TRUE; + exchange_ptr->description = string_duplicate(description); + exchange_ptr->solution_equilibria = FALSE; + exchange_ptr->n_solution = 0; + exchange_ptr->count_comps = 0; + exchange_ptr->comps = (struct exch_comp *) PHRQ_malloc(sizeof (struct exch_comp)); + if (exchange_ptr->comps == NULL) malloc_error(); + exchange_ptr->related_phases = FALSE; + exchange_ptr->related_rate = FALSE; + exchange_ptr->pitzer_exchange_gammas = TRUE; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int exchange_ptr_to_user(struct exchange *exchange_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies exchange_old_ptr to old n_user_new space if + * found or to exchange[count_exchange] if not found. + * Exchange array may not be in sort order after the copy. + */ + int sort; + int n_new; + struct exchange *exchange_ptr_new; +/* + * Find n_user_old in structure array exchange + */ + if (exchange_ptr_old == NULL) { + sprintf(error_string, "Exchange ptr is NULL"); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array exchange or make new space + */ + sort = FALSE; + exchange_ptr_new = exchange_bsearch(n_user_new, &n_new); + if (exchange_ptr_new == exchange_ptr_old) return(OK); + if (exchange_ptr_new != NULL) { + exchange_free(exchange_ptr_new); + } else { + space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); + if (n_user_new < exchange[count_exchange-1].n_user) sort = TRUE; + n_new = count_exchange++; + } +/* + * Copy data + */ + exchange_copy(exchange_ptr_old, &exchange[n_new], n_user_new); + if (sort == TRUE) exchange_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct exchange *exchange_ptr; + exchange_ptr = exchange_alloc(); + exchange_copy(exchange_old_ptr, exchange_ptr, n_user_new); + return (exchange_ptr); +} +/* ---------------------------------------------------------------------- */ +struct exchange *exchange_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search for user number n_user. + * Returns pointer to exchange structure and position number, n, + * in exchange array if found. + * Returns NULL if not found. + */ + int i; + for (i = 0; i < count_exchange; i++) { + if (n_user == exchange[i].n_user) { + break; + } + } + if (i >= count_exchange) { + if ( print == TRUE) { + sprintf(error_string, "Exchange %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return(NULL); + } + *n = i; + return(&exchange[i]); +} +/* ---------------------------------------------------------------------- */ +int exchange_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of exchange structures + */ + if (count_exchange > 0) { + qsort (exchange, (size_t) count_exchange, (size_t) sizeof(struct exchange), + exchange_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "gas" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int gas_comp_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct gas_comp *gas_comp_ptr1, *gas_comp_ptr2; + gas_comp_ptr1 = (const struct gas_comp *) ptr1; + gas_comp_ptr2 = (const struct gas_comp *) ptr2; + return(strcmp_nocase(gas_comp_ptr1->name, gas_comp_ptr2->name)); + +} +/* ---------------------------------------------------------------------- */ +struct gas_phase *gas_phase_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct gas_phase *gas_phase_ptr; + gas_phase_ptr = (struct gas_phase *) PHRQ_malloc(sizeof (struct gas_phase)); + if (gas_phase_ptr == NULL) malloc_error(); + gas_phase_ptr->description = NULL; + gas_phase_ptr->count_comps = 0; + gas_phase_ptr->comps = NULL; + return ( gas_phase_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct gas_phase *gas_phase_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search gas_phase to find if user gas_phase number k exists. + * Assumes array gas_phase is in sort order. + */ + void *void_ptr; + if (count_gas_phase == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) gas_phase, + (size_t) count_gas_phase, + (size_t) sizeof(struct gas_phase), + gas_phase_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct gas_phase *) void_ptr - gas_phase); + return ( (struct gas_phase *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct gas_phase *gas_phase_ptr1, *gas_phase_ptr2; + gas_phase_ptr1 = (const struct gas_phase *) ptr1; + gas_phase_ptr2 = (const struct gas_phase *) ptr2; + if (gas_phase_ptr1->n_user > gas_phase_ptr2->n_user) return(1); + if (gas_phase_ptr1->n_user < gas_phase_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int gas_phase_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare gas phase user numbers + */ + const int *nptr1; + const struct gas_phase *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct gas_phase *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies gas_phase structure from gas_phase_old_ptr to new location gas_phase_new_ptr. + * Space for a gas_phase structure must already be malloced + * Space for gas_phase components is alloced here. + */ + int count_comps; + char token[MAX_LENGTH]; +/* + * Store data for structure gas + */ + memcpy(gas_phase_new_ptr, gas_phase_old_ptr, (size_t) sizeof(struct gas_phase)); + count_comps = gas_phase_old_ptr->count_comps; + gas_phase_new_ptr->n_user = n_user_new; + gas_phase_new_ptr->n_user_end = n_user_new; + gas_phase_new_ptr->new_def = FALSE; + sprintf(token, "Gas defined in simulation %d.", simulation); + gas_phase_new_ptr->description = string_duplicate(token); +/* + * Allocate space for gas components + */ + gas_phase_new_ptr->comps = (struct gas_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct gas_comp)); + if (gas_phase_new_ptr->comps == NULL) malloc_error(); +/* + * Write gas_comp structure for each gas component + */ + memcpy(gas_phase_new_ptr->comps, gas_phase_old_ptr->comps, + (size_t) (count_comps) * sizeof (struct gas_comp)); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an gas_phase definition to position count_gas_phase. + */ + space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); + gas_phase_copy(&gas_phase[n], &gas_phase[count_gas_phase], n_user); + count_gas_phase++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array gas_phase. + */ +{ + int i; + int n_old; + struct gas_phase *gas_phase_ptr_old; +/* + * Find n_user_old in structure array + */ + gas_phase_ptr_old = gas_phase_bsearch(n_user_old, &n_old); + if (gas_phase_ptr_old != NULL) { + /* + * Delete gas_phase + */ + gas_phase_free(&gas_phase[n_old]); + + for(i = n_old + 1; i < count_gas_phase; i++) { + memcpy( (void *) &gas_phase[i - 1], (void *) &gas_phase[i], + (size_t) sizeof (struct gas_phase) ); + } + count_gas_phase--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies gas_phase[n_user_old] to old n_user_new space if + * found or to gas_phase[count_gas_phase] if not found. + * Gas_Phase array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct gas_phase *gas_phase_ptr_old, *gas_phase_ptr_new; +/* + * Find n_user_old in structure array gas_phase + */ + if (n_user_old == n_user_new) return(OK); + gas_phase_ptr_old = gas_phase_bsearch(n_user_old, &n_old); + if (gas_phase_ptr_old == NULL) { + sprintf(error_string, "Gas_Phase %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array gas_phase or make new space + */ + sort = FALSE; + gas_phase_ptr_new = gas_phase_bsearch(n_user_new, &n_new); + if (gas_phase_ptr_new != NULL) { + gas_phase_free (&gas_phase[n_new]); +#ifdef SKIP + gas_phase[n_new].comps = free_check_null (gas_phase[n_new].comps); +#endif + } else { + space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); + if (n_user_new < gas_phase[count_gas_phase-1].n_user) sort = TRUE; + n_new = count_gas_phase++; + } +/* + * Copy data + */ + gas_phase_copy(&gas_phase[n_old], &gas_phase[n_new], n_user_new); + if (sort == TRUE) gas_phase_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_free (struct gas_phase *gas_phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space associated with gas_phase_ptr. + */ + if (gas_phase_ptr == NULL) return(ERROR); +/* + * Free space allocated for gas_phase structure + */ + gas_phase_ptr->description = (char *) free_check_null (gas_phase_ptr->description); + gas_phase_ptr->comps = (struct gas_comp *) free_check_null (gas_phase_ptr->comps); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_init (struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space associated with gas_phase_ptr. + */ + if (gas_phase_ptr == NULL) return(ERROR); + gas_phase_ptr->n_user = n_user; + gas_phase_ptr->n_user_end = n_user_end; + gas_phase_ptr->description = string_duplicate(description); + gas_phase_ptr->new_def = TRUE; + gas_phase_ptr->solution_equilibria = FALSE; + gas_phase_ptr->n_solution = 0; + gas_phase_ptr->type = PRESSURE; + gas_phase_ptr->total_p = 1.0; + gas_phase_ptr->total_moles = 0.0; + gas_phase_ptr->volume = 1.0; + gas_phase_ptr->temperature = 298.15; + gas_phase_ptr->count_comps = 0; + gas_phase_ptr->comps = (struct gas_comp *) PHRQ_malloc((size_t) sizeof(struct gas_comp)); + if (gas_phase_ptr->comps == NULL) malloc_error(); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies gas_phase_ptr_old to old n_user_new space if + * found or to gas_phase[count_gas_phase] if not found. + * Gas_Phase array may not be in sort order after the copy. + */ + int n_new, sort; + struct gas_phase *gas_phase_ptr_new; +/* + * Find n_user_old in structure array gas_phase + */ + if (gas_phase_ptr_old == NULL) { + sprintf(error_string, "Gas_Phase pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array gas_phase or make new space + */ + sort = FALSE; + gas_phase_ptr_new = gas_phase_bsearch(n_user_new, &n_new); + if (gas_phase_ptr_new == gas_phase_ptr_old) return(OK); + if (gas_phase_ptr_new != NULL) { + gas_phase_free (&gas_phase[n_new]); +#ifdef SKIP + gas_phase[n_new].comps = free_check_null (gas_phase[n_new].comps); +#endif + } else { + space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); + if (n_user_new < gas_phase[count_gas_phase-1].n_user) sort = TRUE; + n_new = count_gas_phase++; + } +/* + * Copy data + */ + gas_phase_copy(gas_phase_ptr_old, &gas_phase[n_new], n_user_new); + if (sort == TRUE) gas_phase_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct gas_phase *gas_phase_ptr; + gas_phase_ptr = gas_phase_alloc(); + gas_phase_copy(gas_phase_old_ptr, gas_phase_ptr, n_user_new); + return (gas_phase_ptr); +} +/* ---------------------------------------------------------------------- */ +struct gas_phase *gas_phase_search (int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "gas_phase" for user number n_user + * + * Arguments: + * n_user input, user number + * n output, position in gas_phase + * + * Returns: + * if found, the address of the gas_phase element + * if not found, NULL + * + */ + int i; + for (i=0; i < count_gas_phase; i++) { + if ( gas_phase[i].n_user == n_user) { + *n = i; + return (&(gas_phase[i])); + } + } +/* + * Gas_phase not found + */ + return (NULL); +} +/* ---------------------------------------------------------------------- */ +int gas_phase_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of gas_phase structures + */ + if (count_gas_phase > 0) { + qsort (gas_phase, (size_t) count_gas_phase, (size_t) sizeof(struct gas_phase), + gas_phase_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "inverse" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct inverse *inverse_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space for a new inverse structure at position count_inverse. + * Initializes structure. + * arguments + * input: none + * output: pointer to an inverse structure + * return: OK + */ +{ + struct inverse *inverse_ptr; + + count_inverse++; + inverse = (struct inverse *) PHRQ_realloc(inverse, (size_t) count_inverse * sizeof(struct inverse)); + if (inverse == NULL) malloc_error(); + inverse_ptr = &(inverse[count_inverse-1]); +/* + * Initialize variables + */ + inverse_ptr->description = NULL; + inverse_ptr->count_uncertainties = 0; + inverse_ptr->count_solns = 0; + inverse_ptr->count_elts = 0; + inverse_ptr->count_isotopes = 0; + inverse_ptr->count_i_u = 0; + inverse_ptr->count_phases = 0; + inverse_ptr->count_force_solns = 0; +/* + * allocate space for pointers in structure to NULL + */ + + inverse_ptr->uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->uncertainties == NULL) malloc_error(); + + inverse_ptr->ph_uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->ph_uncertainties == NULL) malloc_error(); + +#ifdef SKIP + inverse_ptr->alk_uncertainties = PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->alk_uncertainties == NULL) malloc_error(); +#endif + + inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int)); + if (inverse_ptr->force_solns == NULL) malloc_error(); + + inverse_ptr->dalk_dph = NULL; + inverse_ptr->dalk_dc = NULL; + + + inverse_ptr->solns = NULL; + + inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); + if (inverse_ptr->elts == NULL) malloc_error(); + inverse_ptr->elts[0].name = NULL; + inverse_ptr->elts[0].uncertainties = NULL; + + inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); + if (inverse_ptr->isotopes == NULL) malloc_error(); + inverse_ptr->isotopes[0].isotope_name = NULL; + inverse_ptr->isotopes[0].isotope_number = 0; + inverse_ptr->isotopes[0].elt_name = NULL; + + inverse_ptr->i_u = (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); + if (inverse_ptr->i_u == NULL) malloc_error(); + inverse_ptr->i_u[0].isotope_name = NULL; + inverse_ptr->i_u[0].isotope_number = 0; + inverse_ptr->i_u[0].elt_name = NULL; + + inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); + if (inverse_ptr->phases == NULL) malloc_error(); + + return(inverse_ptr); +} +/* ---------------------------------------------------------------------- */ +int inverse_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare inverse values for n_user + */ + const struct inverse *nptr1; + const struct inverse *nptr2; + + nptr1= (const struct inverse *) ptr1; + nptr2= (const struct inverse *) ptr2; + if (nptr1->n_user > nptr2->n_user) return(1); + if (nptr1->n_user < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int inverse_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Deletes inverse i from list (i is not user number), + * Frees memory allocated to inverse struct + * Input: i, number of inverse struct to delete + * Return: OK + */ + int j; + + inverse_free ( &(inverse[i]) ); + for (j=i; j < (count_inverse - 1); j++) { + memcpy ( (void *) &(inverse[j]), (void *) &(inverse[j+1]), + (size_t) sizeof (struct inverse)); + } + count_inverse--; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int inverse_free (struct inverse *inverse_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all memory for an inverse structure. + */ + int i; + + inverse_ptr->description = (char *) free_check_null (inverse_ptr->description); +/* Free solns */ + inverse_ptr->solns = (int *) free_check_null (inverse_ptr->solns); + +/* Free uncertainties */ + inverse_ptr->uncertainties = (double *) free_check_null (inverse_ptr->uncertainties); + inverse_ptr->ph_uncertainties = (double *) free_check_null (inverse_ptr->ph_uncertainties); +#ifdef SKIP + inverse_ptr->alk_uncertainties = (double *) free_check_null (inverse_ptr->alk_uncertainties); +#endif + +/* Free force_solns */ + inverse_ptr->force_solns = (int *) free_check_null (inverse_ptr->force_solns); + +/* Free elts */ + for (i = 0; i < inverse_ptr->count_elts; i++) { + inverse_ptr->elts[i].uncertainties = (double *) free_check_null (inverse_ptr->elts[i].uncertainties); + }; + inverse_ptr->elts = (struct inv_elts *) free_check_null (inverse_ptr->elts); + +/* Free isotopes */ + for (i = 0; i < inverse_ptr->count_isotopes; i++) { + inverse_ptr->isotopes[i].uncertainties = (double *) free_check_null (inverse_ptr->isotopes[i].uncertainties); + }; + inverse_ptr->isotopes = (struct inv_isotope *) free_check_null (inverse_ptr->isotopes); + + for (i = 0; i < inverse_ptr->count_i_u; i++) { + inverse_ptr->i_u[i].uncertainties = (double *) free_check_null (inverse_ptr->i_u[i].uncertainties); + }; + inverse_ptr->i_u = (struct inv_isotope *) free_check_null (inverse_ptr->i_u); + +/* Free phases */ + for (i = 0; i < inverse_ptr->count_phases; i++) { + inverse_ptr->phases[i].isotopes = (struct isotope *) free_check_null(inverse_ptr->phases[i].isotopes); + } + inverse_ptr->phases = (struct inv_phases *) free_check_null (inverse_ptr->phases); + +/* Free carbon derivatives */ + inverse_ptr->dalk_dph = (LDBLE *) free_check_null(inverse_ptr->dalk_dph); + inverse_ptr->dalk_dc = (LDBLE *) free_check_null(inverse_ptr->dalk_dc); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int inverse_isotope_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct inv_isotope *iso_ptr1, *iso_ptr2; + + iso_ptr1 = (const struct inv_isotope *) ptr1; + iso_ptr2 = (const struct inv_isotope *) ptr2; + i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); + if (i != 0) return(i); + if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) { + return(-1); + } else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) { + return(1); + } + return(0); +} + +/* ---------------------------------------------------------------------- */ +struct inverse *inverse_search (int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "inverse" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in inverse + * + * Returns: + * if found, the address of the inverse element + * if not found, NULL + * + */ + int i; + for (i=0; i < count_inverse; i++) { + if ( inverse[i].n_user == n_user) { + *n = i; + return (&(inverse[i])); + } + } +/* + * An inverse structure with n_user was not found + */ + return (NULL); +} +/* ---------------------------------------------------------------------- */ +int inverse_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of inverse structures + */ + if (count_inverse > 0) { + qsort (inverse, (size_t) count_inverse, (size_t) sizeof(struct inverse), + inverse_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "irrev" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct irrev *irrev_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Search irrev to find if user irrev number k exists. + * Uses binary search, assumes array irrev is in sort order. + */ + void *void_ptr; + if (count_irrev == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) irrev, + (size_t) count_irrev, + (size_t) sizeof(struct irrev), + irrev_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct irrev *) void_ptr - irrev); + return ( (struct irrev *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int irrev_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct irrev *irrev_ptr1, *irrev_ptr2; + irrev_ptr1 = (const struct irrev *) ptr1; + irrev_ptr2 = (const struct irrev *) ptr2; + if (irrev_ptr1->n_user > irrev_ptr2->n_user) return(1); + if (irrev_ptr1->n_user < irrev_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int irrev_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare irrev user numbers + */ + const int *nptr1; + const struct irrev *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct irrev *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies irrev structure from irrev_old_ptr to new location irrev_new_ptr. + * Space for a irrev structure must already be malloced + * Space for irrev components is alloced here. + */ + int count_list, count_steps; + char token[MAX_LENGTH]; +/* + * Store data for structure gas + */ + memcpy(irrev_new_ptr, irrev_old_ptr, (size_t) sizeof(struct irrev)); + irrev_new_ptr->n_user = n_user_new; + irrev_new_ptr->n_user_end = n_user_new; + sprintf(token, "Reaction defined in simulation %d.", simulation); + irrev_new_ptr->description = string_duplicate(token); + count_list = irrev_old_ptr->count_list; + count_steps = irrev_old_ptr->count_steps; +/* + * Allocate space + */ + irrev_new_ptr->list = (struct name_coef *) PHRQ_malloc((size_t) (count_list) * sizeof (struct name_coef)); + if (irrev_new_ptr->list == NULL) malloc_error(); + memcpy(irrev_new_ptr->list, irrev_old_ptr->list, (size_t) (count_list) * sizeof (struct name_coef)); + if (count_steps < 0) count_steps = 1; + irrev_new_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps) * sizeof (LDBLE)); + if (irrev_new_ptr->steps == NULL) malloc_error(); + memcpy(irrev_new_ptr->steps, irrev_old_ptr->steps, (size_t) (count_steps) * sizeof (LDBLE)); + + if (irrev_old_ptr->elts != NULL) { + irrev_new_ptr->elts = elt_list_dup(irrev_old_ptr->elts); + } else { + irrev_new_ptr->elts = NULL; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int irrev_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Finds irrev structure with user number n_user_old, + * copies data to irrev structure with user number n_user_new. + * If n_user_new already exists, it is overwritten and sort order + * is maintained. + * If n_user_new does not exist, a new structure is allocated; sort + * order may not be preserved. + */ + int n_old, n_new, sort; + char token[MAX_LENGTH]; + int count_steps, count_list; + struct irrev *irrev_ptr_old, *irrev_ptr_new; +/* + * Find n_user_old in structure array irrev_assemblage or make new space + */ + if (n_user_old == n_user_new) return(OK); + irrev_ptr_old = irrev_bsearch(n_user_old, &n_old); + if (irrev_ptr_old == NULL) { + sprintf(error_string, "Irreversible reaction %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_old in structure array irrev or make new space + */ + sort = FALSE; + irrev_ptr_new = irrev_bsearch(n_user_new, &n_new); + if (irrev_ptr_new != NULL) { + irrev_free(irrev_ptr_new); + } else { + irrev = (struct irrev *) PHRQ_realloc( irrev, (size_t) (count_irrev + 1) * sizeof (struct irrev)); + if (irrev == NULL) malloc_error(); + if (n_user_new < irrev[count_irrev-1].n_user) sort = TRUE; + n_new = count_irrev++; + } +/* + * Store data for structure irrev + */ + count_steps = irrev[n_old].count_steps; + irrev[n_new].n_user = n_user_new; + irrev[n_new].n_user_end = n_user_new; + sprintf(token, "Irreversible reaction defined in simulation %d.", simulation); + irrev[n_new].description = string_duplicate(token); + irrev[n_new].units = irrev[n_old].units; + irrev[n_new].count_steps = count_steps; + count_list = irrev[n_old].count_list; + irrev[n_new].count_list = irrev[n_old].count_list; +/* + * Allocate space + */ + irrev[n_new].list = (struct name_coef *) PHRQ_malloc((size_t) (count_list) * sizeof (struct name_coef)); + if (irrev[n_new].list == NULL) malloc_error(); + memcpy(irrev[n_new].list, irrev[n_old].list, + (size_t) (count_list) * sizeof (struct name_coef)); + + if (count_steps < 0) count_steps = 1; + irrev[n_new].steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps) * sizeof (LDBLE)); + if (irrev[n_new].steps == NULL) malloc_error(); + memcpy(irrev[n_new].steps, irrev[n_old].steps, + (size_t) (count_steps) * sizeof (LDBLE)); + + if (irrev[n_old].elts != NULL) { + irrev[n_new].elts = elt_list_dup(irrev[n_old].elts); + } else { + irrev[n_new].elts = NULL; + } + if (sort == TRUE) irrev_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int irrev_free (struct irrev *irrev_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free memory pointed to by an irrev structure. + */ + if (irrev_ptr == NULL) return(ERROR); +/* + * Free space allocated for irrev structure + */ + irrev_ptr->description = (char *) free_check_null (irrev_ptr->description); + irrev_ptr->list = (struct name_coef *) free_check_null (irrev_ptr->list); + irrev_ptr->elts = (struct elt_list *) free_check_null (irrev_ptr->elts); + irrev_ptr->steps = (LDBLE *) free_check_null (irrev_ptr->steps); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct irrev *irrev_search(int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Linear search for irrev user number n_user. + * If found, n is position in irrev array and pointer to irrev structure + * is returned + * If not found, NULL is returned. + */ + int i; + for (i = 0; i < count_irrev; i++) { + if (n_user == irrev[i].n_user) { + break; + } + } + if (i >= count_irrev) { + *n = -999; + return(NULL); + } + *n = i; + return(&irrev[i]); +} +/* ---------------------------------------------------------------------- */ +int irrev_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of irrev structures + */ + if (count_irrev > 0) { + qsort (irrev, (size_t) count_irrev, (size_t) sizeof(struct irrev), + irrev_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "kinetics" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct kinetics *kinetics_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct kinetics *kinetics_ptr; + kinetics_ptr = (struct kinetics *) PHRQ_malloc(sizeof (struct kinetics)); + if (kinetics_ptr == NULL) malloc_error(); + kinetics_ptr->description = NULL; + kinetics_ptr->count_comps = 0; + kinetics_ptr->comps = NULL; + kinetics_ptr->count_steps = 0; + kinetics_ptr->steps = NULL; + /*kinetics_ptr->units = NULL;*/ + kinetics_ptr->totals = NULL; + return ( kinetics_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct kinetics *kinetics_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search kinetics to find if user kinetics number k exists. + * Kinetics is assumed to be in sort order by user number. + */ + void *void_ptr; + if (count_kinetics == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) kinetics, + (size_t) count_kinetics, + (size_t) sizeof(struct kinetics), + kinetics_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct kinetics *) void_ptr - kinetics); + return ( (struct kinetics *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int kinetics_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct kinetics *kinetics_ptr1, *kinetics_ptr2; + kinetics_ptr1 = (const struct kinetics *) ptr1; + kinetics_ptr2 = (const struct kinetics *) ptr2; + if (kinetics_ptr1->n_user > kinetics_ptr2->n_user) return(1); + if (kinetics_ptr1->n_user < kinetics_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int kinetics_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare kinetics user numbers + */ + const int *nptr1; + const struct kinetics *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct kinetics *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies kinetics data from kinetics_old_ptr to new location, kinetics_new_ptr. + * Space for the kinetics_new_ptr structure must already be malloced. + * Space for kinetics components is malloced here. + */ + char token[MAX_LENGTH]; + int count_steps, i; +/* + * copy old to new + */ + memcpy(kinetics_new_ptr, kinetics_old_ptr, sizeof (struct kinetics)); +/* + * Store data for structure kinetics + */ + kinetics_new_ptr->n_user = n_user_new; + kinetics_new_ptr->n_user_end = n_user_new; + sprintf(token, "Kinetics defined in simulation %d.", simulation); + kinetics_new_ptr->description = string_duplicate(token); + kinetics_new_ptr->totals = NULL; + kinetics_new_ptr->totals = elt_list_dup(kinetics_old_ptr->totals); +/* + * Copy time steps + */ + if (kinetics_new_ptr->count_steps > 0) { + count_steps = kinetics_new_ptr->count_steps; + } else if (kinetics_new_ptr->count_steps < 0) { + count_steps = 1; + } else { + count_steps = 0; + } + if (count_steps > 0) { + kinetics_new_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps * sizeof (LDBLE))); + if (kinetics_new_ptr->steps == NULL) malloc_error(); + memcpy(kinetics_new_ptr->steps, kinetics_old_ptr->steps, (size_t) count_steps * sizeof (LDBLE)); + } +/* + * Copy kinetic components + */ + if (kinetics_new_ptr->count_comps > 0) { + kinetics_new_ptr->comps = (struct kinetics_comp *) PHRQ_malloc((size_t) kinetics_old_ptr->count_comps * sizeof (struct kinetics_comp)); + if (kinetics_new_ptr->comps == NULL) malloc_error(); + } else { + kinetics_new_ptr->comps = NULL; + } + for (i = 0; i < kinetics_old_ptr->count_comps; i++) { + kinetics_comp_duplicate(&kinetics_new_ptr->comps[i], &kinetics_old_ptr->comps[i]); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies kinetics comp data from kinetics_comp_old_ptr to new location + * Space for the new structure must already be allocated + */ + memcpy(kinetics_comp_new_ptr, kinetics_comp_old_ptr, sizeof (struct kinetics_comp)); +/* + * Kinetics character parameters + */ + if (kinetics_comp_new_ptr->count_c_params > 0) { + kinetics_comp_new_ptr->c_params = (char **) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_c_params) * sizeof (char *)); + if (kinetics_comp_new_ptr->c_params == NULL) malloc_error(); + memcpy(kinetics_comp_new_ptr->c_params, kinetics_comp_old_ptr->c_params, (size_t) (kinetics_comp_old_ptr->count_c_params) * sizeof (char *)); + } else { + kinetics_comp_new_ptr->c_params = NULL; + } +/* + * Kinetics LDBLE parameters + */ + if (kinetics_comp_new_ptr->count_d_params > 0) { + kinetics_comp_new_ptr->d_params = (LDBLE *) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_d_params) * sizeof (LDBLE)); + if (kinetics_comp_new_ptr->d_params == NULL) malloc_error(); + memcpy(kinetics_comp_new_ptr->d_params, kinetics_comp_old_ptr->d_params, (size_t) (kinetics_comp_old_ptr->count_d_params) * sizeof (LDBLE)); + } else { + kinetics_comp_new_ptr->d_params = (LDBLE *) PHRQ_malloc((size_t) sizeof (LDBLE)); + } +/* + * Kinetics list of formulae + */ + if (kinetics_comp_new_ptr->count_list > 0) { + kinetics_comp_new_ptr->list = (struct name_coef *) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_list) * sizeof (struct name_coef)); + if (kinetics_comp_new_ptr->list == NULL) malloc_error(); + memcpy(kinetics_comp_new_ptr->list, kinetics_comp_old_ptr->list, (size_t) (kinetics_comp_old_ptr->count_list) * sizeof (struct name_coef)); + } else { + kinetics_comp_new_ptr->d_params = NULL; + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int kinetics_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an kinetics definition from position n to position count_kinetics. + * New kinetics structure is given user number n_user. + */ + space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); + kinetics_copy(&kinetics[n], &kinetics[count_kinetics], n_user); + count_kinetics++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array kinetics. + */ +{ + int i; + int n_old; + struct kinetics *kinetics_ptr_old; +/* + * Find n_user_old in structure array + */ + kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); + if (kinetics_ptr_old != NULL) { + /* + * Delete kinetics + */ + kinetics_free(&kinetics[n_old]); + + for(i = n_old + 1; i < count_kinetics; i++) { + memcpy( (void *) &kinetics[i - 1], (void *) &kinetics[i], + (size_t) sizeof (struct kinetics) ); + } + count_kinetics--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies kinetics[n_user_old] to old n_user_new space if + * found or to kinetics[count_kinetics] if not found. + * Kinetics array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct kinetics *kinetics_ptr_old, *kinetics_ptr_new; +/* + * Find n_user_old in structure array kinetics + */ + if (n_user_old == n_user_new) return(OK); + kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); + if (kinetics_ptr_old == NULL) { + sprintf(error_string, "Kinetics %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array kinetics or make new space + */ + sort = FALSE; + kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); + if (kinetics_ptr_new != NULL) { + kinetics_free(kinetics_ptr_new); + } else { + space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); + if (n_user_new < kinetics[count_kinetics-1].n_user) sort = TRUE; + n_new = count_kinetics++; + } +/* + * Copy data + */ + kinetics_copy(&kinetics[n_old], &kinetics[n_new], n_user_new); + if (sort == TRUE) kinetics_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_free (struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Frees all data associated with kinetics structure. + */ + if (kinetics_ptr == NULL) return(ERROR); +/* + * Free space allocated for kinetics structure + */ + for (i = 0; i < kinetics_ptr->count_comps; i++) { + kinetics_ptr->comps[i].c_params = (char **) free_check_null (kinetics_ptr->comps[i].c_params); + kinetics_ptr->comps[i].d_params = (LDBLE *) free_check_null (kinetics_ptr->comps[i].d_params); + kinetics_ptr->comps[i].list = (struct name_coef *) free_check_null (kinetics_ptr->comps[i].list); + } + kinetics_ptr->description = (char *) free_check_null (kinetics_ptr->description); + kinetics_ptr->steps = (LDBLE *) free_check_null (kinetics_ptr->steps); + kinetics_ptr->comps = (struct kinetics_comp *) free_check_null (kinetics_ptr->comps); + kinetics_ptr->totals = (struct elt_list *) free_check_null (kinetics_ptr->totals); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_init (struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ + if (kinetics_ptr == NULL) return(ERROR); + kinetics_ptr->n_user = n_user; + kinetics_ptr->n_user_end = n_user_end; + kinetics_ptr->description = string_duplicate(description); + kinetics_ptr->count_comps = 0; + kinetics_ptr->comps = (struct kinetics_comp *) PHRQ_malloc((size_t) sizeof(struct kinetics_comp)); + if (kinetics_ptr->comps == NULL) malloc_error(); + kinetics_ptr->count_steps = 0; + kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) malloc_error(); + kinetics_ptr->step_divide = 1.0; + /*kinetics_ptr->units = string_hsave("sec");*/ + kinetics_ptr->totals = NULL; + kinetics_ptr->rk = 3; + kinetics_ptr->bad_step_max = 500; + kinetics_ptr->use_cvode = FALSE; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies kinetics_ptr_old to old n_user_new space if + * found or to kinetics[count_kinetics] if not found. + * Kinetics array may not be in sort order after the copy. + */ + int n_new, sort; + struct kinetics *kinetics_ptr_new; +/* + * Find n_user_old in structure array kinetics + */ + if (kinetics_ptr_old == NULL) { + sprintf(error_string, "Kinetics pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array kinetics or make new space + */ + sort = FALSE; + kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); + if (kinetics_ptr_new == kinetics_ptr_old) return(OK); + if (kinetics_ptr_new != NULL) { + kinetics_free(kinetics_ptr_new); + } else { + space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); + if (n_user_new < kinetics[count_kinetics-1].n_user) sort = TRUE; + n_new = count_kinetics++; + } +/* + * Copy data + */ + kinetics_copy(kinetics_ptr_old, &kinetics[n_new], n_user_new); + if (sort == TRUE) kinetics_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct kinetics *kinetics_ptr; + kinetics_ptr = kinetics_alloc(); + kinetics_copy(kinetics_old_ptr, kinetics_ptr, n_user_new); + return (kinetics_ptr); +} +/* ---------------------------------------------------------------------- */ +struct kinetics *kinetics_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search for user number n_user. + * Returns pointer to kinetics structure and position number, n, + * in kinetics array if found. + * Returns NULL if not found. + */ + int i; + for (i = 0; i < count_kinetics; i++) { + if (n_user == kinetics[i].n_user) { + break; + } + } + if (i >= count_kinetics) { + if ( print == TRUE) { + sprintf(error_string, "Kinetics %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return(NULL); + } + *n = i; + return(&kinetics[i]); +} +/* ---------------------------------------------------------------------- */ +int kinetics_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of kinetics structures + */ + if (count_kinetics > 0) { + qsort (kinetics, (size_t) count_kinetics, (size_t) sizeof(struct kinetics), + kinetics_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "master" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct master *master_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a master structure and initializes the space. + * arguments: void + * return: pointer to a master structure + */ +{ + struct master *ptr; + ptr=(struct master *) PHRQ_malloc(sizeof(struct master)); + if (ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL + */ + ptr->in=FALSE; + ptr->type=0; + ptr->primary=FALSE; + ptr->coef=0.0; + ptr->total=0.0; + ptr->elt=NULL; + ptr->alk = 0.0; + ptr->gfw = 0.0; + ptr->gfw_formula=NULL; + ptr->unknown=NULL; + ptr->s=NULL; + ptr->rxn_primary=NULL; + ptr->rxn_secondary=NULL; + ptr->pe_rxn=NULL; + ptr->minor_isotope = FALSE; + + return(ptr); +} +/* ---------------------------------------------------------------------- */ +int master_delete(char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete master species: Free memory of master species structure, free + * the structure, and remove from array master. + * + * Input + * ptr character string with name of element or valence state + * Returns + * TRUE if master species was deleted. + * FALSE if master species was not found. + */ + int j, n; + + if (master_search(ptr, &n) == NULL) return(FALSE); + master_free (master[n]); + for (j=n; j < (count_master - 1); j++) { + master[j] = master[j+1]; + } + count_master--; + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int master_free(struct master *master_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free memory pointed to by master species pointer, master_ptr. + * Frees master_ptr itself. + */ + if (master_ptr == NULL) return(ERROR); + rxn_free (master_ptr->rxn_primary); + rxn_free (master_ptr->rxn_secondary); + master_ptr = (struct master *) free_check_null (master_ptr); + return(OK); +} + +/* ---------------------------------------------------------------------- */ +struct master *master_bsearch (const char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Uses binary search. Assumes master is in sort order. + * Find master species for string (*ptr) containing name of element or valence state. + * + * Input: ptr pointer to string containing element name + * + * Return: pointer to master structure containing name ptr or NULL. + */ + void *void_ptr; + if (count_master == 0) { + return(NULL); + } + void_ptr = bsearch ((const char *) ptr, + (char *) master, + (unsigned) count_master, + sizeof(struct master *), + master_compare_string); + if (void_ptr == NULL) { + return(NULL); + } else { + return (* (struct master **) void_ptr); + } +} +/* ---------------------------------------------------------------------- */ +int master_compare_string (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *string_ptr; + const struct master *master_ptr; + + string_ptr = (const char *) ptr1; + master_ptr = * (const struct master **) ptr2; + return(strcmp_nocase(string_ptr, master_ptr->elt->name)); +} +/* ---------------------------------------------------------------------- */ +int master_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct master *master_ptr1, *master_ptr2; + master_ptr1 = * (const struct master **) ptr1; + master_ptr2 = * (const struct master **) ptr2; + return(strcmp_nocase(master_ptr1->elt->name, master_ptr2->elt->name)); +} +/* ---------------------------------------------------------------------- */ +struct master *master_bsearch_primary (char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find primary master species for first element in the string, ptr. + * Uses binary search. Assumes master is in sort order. + */ + int l; + char *ptr1; + char elt[MAX_LENGTH]; + struct master *master_ptr_primary; +/* + * Find element name + */ + ptr1=ptr; + get_elt(&ptr1, elt, &l); +/* + * Search master species list + */ + master_ptr_primary=master_bsearch(elt); + if (master_ptr_primary == NULL ) { + input_error++; + sprintf(error_string, "Could not find primary master species for %s.", ptr); + error_msg(error_string, CONTINUE); + } + return(master_ptr_primary); +} +/* ---------------------------------------------------------------------- */ +struct master *master_search (char *ptr, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Linear search of master to find master species in string, ptr. + * Returns pointer if found. n contains position in array master. + * Returns NULL if not found. + */ + int i; + struct master *master_ptr; +/* + * Search master species list + */ + *n = -999; + for (i = 0; i < count_master; i++) { + if (strcmp(ptr, master[i]->elt->name) == 0) { + *n = i; + master_ptr = master[i]; + return(master_ptr); + } + } + return(NULL); +} +/* ********************************************************************** + * + * Routines related to structure "mix" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct mix *mix_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Search mix to find if user mix number k exists. + * Uses binary search, assumes array mix is in sort order. + */ + void *void_ptr; + if (count_mix == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) mix, + (size_t) count_mix, + (size_t) sizeof(struct mix), + mix_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct mix *) void_ptr - mix); + return ( (struct mix *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int mix_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct mix *mix_ptr1, *mix_ptr2; + mix_ptr1 = (const struct mix *) ptr1; + mix_ptr2 = (const struct mix *) ptr2; + if (mix_ptr1->n_user > mix_ptr2->n_user) return(1); + if (mix_ptr1->n_user < mix_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int mix_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare mix user numbers + */ + const int *nptr1; + const struct mix *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct mix *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies mix data from mix_old_ptr to new location, mix_new_ptr. + * Space for the mix_new_ptr structure must already be malloced. + * Space for mix components is malloced here. + */ + char token[MAX_LENGTH]; +/* + * Copy old to new + */ + memcpy(mix_new_ptr, mix_old_ptr, sizeof (struct mix)); +/* + * Store data for structure mix + */ + mix_new_ptr->n_user = n_user_new; + mix_new_ptr->n_user_end = n_user_new; + sprintf(token, "Mix defined in simulation %d.", simulation); + mix_new_ptr->description = string_duplicate(token); +/* + * Count mix components and allocate space + */ + mix_new_ptr->comps = (struct mix_comp *) PHRQ_malloc((size_t) (mix_old_ptr->count_comps) * sizeof (struct mix_comp)); + if (mix_new_ptr->comps == NULL) malloc_error(); + memcpy(mix_new_ptr->comps, mix_old_ptr->comps, + (size_t) (mix_old_ptr->count_comps) * sizeof (struct mix_comp)); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mix_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies mix[n_user_old] to old n_user_new space if + * found or to mix[count_mix] if not found. + * Mix array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + char token[MAX_LENGTH]; + int count_comps; + struct mix *mix_ptr_old, *mix_ptr_new; +/* + * Find n_user_old in structure array mix or make new space + */ + if (n_user_old == n_user_new) return(OK); + mix_ptr_old = mix_bsearch(n_user_old, &n_old); + if (mix_ptr_old == NULL) { + sprintf(error_string, "Mix %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_old in structure array mix or make new space + */ + sort = FALSE; + mix_ptr_new = mix_bsearch(n_user_new, &n_new); + if (mix_ptr_new != NULL) { + mix_free (&(mix[n_new])); + } else { + mix = (struct mix *) PHRQ_realloc( mix, (size_t) (count_mix + 1) *sizeof (struct mix)); + if (mix == NULL) malloc_error(); + if (n_user_new < mix[count_mix - 1].n_user) sort = TRUE; + n_new = count_mix++; + } +/* + * Store data for structure mix + */ + memcpy(&mix[n_new], &mix[n_old], sizeof(struct mix)); + count_comps = mix[n_old].count_comps; + mix[n_new].n_user = n_user_new; + mix[n_new].n_user_end = n_user_new; + sprintf(token, "Mix defined in simulation %d.", simulation); + mix[n_new].description = string_duplicate(token); +/* + * Count mix components and allocate space + */ + mix[n_new].comps = (struct mix_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct mix_comp)); + if (mix[n_new].comps == NULL) malloc_error(); +/* + * Write mix_comp structure for each mix component + */ + memcpy(mix[n_new].comps, mix[n_old].comps, + (size_t) (count_comps) * sizeof (struct mix_comp)); + if (sort == TRUE) mix_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int mix_free (struct mix *mix_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for mixture structure. + */ + if (mix_ptr == NULL) return(ERROR); + + mix_ptr->description = (char *) free_check_null (mix_ptr->description); + mix_ptr->comps = (struct mix_comp *) free_check_null (mix_ptr->comps); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct mix *mix_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Linear search of mix array for user number n_user. + * Returns pointer to mix structure if found, n is set to position in mix array. + * Returns NULL if not found. + */ + int i; + for (i = 0; i < count_mix; i++) { + if (n_user == mix[i].n_user) { + break; + } + } + if (i >= count_mix) { + if ( print == TRUE) { + sprintf(error_string, "Mix %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return(NULL); + } + *n = i; + return(&mix[i]); +} +/* ---------------------------------------------------------------------- */ +int mix_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of mix structures + */ + if (count_mix > 0) { + qsort (mix, (size_t) count_mix, (size_t) sizeof(struct mix), + mix_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "pe_data" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pe_data *pe_data_alloc(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocate and initialize an array of struct pe_data + */ + struct pe_data *pe_data_ptr; + char token[MAX_LENGTH]; + + pe_data_ptr = (struct pe_data *) PHRQ_malloc( (size_t) (2 * sizeof (struct pe_data))); + if (pe_data_ptr == NULL) malloc_error(); + pe_data_ptr[0].name = pe_string; + if (s_eminus != NULL && s_eminus->rxn != NULL) { + pe_data_ptr[0].rxn = rxn_dup(s_eminus->rxn); + } else { + pe_data_ptr[0].rxn = rxn_alloc(3); + if (pe_data_ptr[0].rxn == NULL) malloc_error(); + strcpy(token,"e-"); + s_eminus = s_store(token, -1.0, FALSE); + pe_data_ptr[0].rxn->token[0].s = s_eminus; + pe_data_ptr[0].rxn->token[0].coef = -1.0; + pe_data_ptr[0].rxn->token[1].s = s_eminus; + pe_data_ptr[0].rxn->token[1].coef = -1.0; + pe_data_ptr[0].rxn->token[2].s = NULL; + } + pe_data_ptr[1].name = NULL; + pe_data_ptr[1].rxn = NULL; + + return (pe_data_ptr); +} +/* ---------------------------------------------------------------------- */ +struct pe_data *pe_data_dup (struct pe_data *pe_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocate space and copy data from pe_ptr_old into the new space. + * Returns pointer to new space. + */ + int i, count_pe; + struct pe_data *pe_ptr_new; +/* + * Count pe data and copy into new structure + */ + if (pe_ptr_old == NULL) return(ERROR); + for (i = 0; pe_ptr_old[i].name != NULL; i++); + count_pe = i + 1; + pe_ptr_new = (struct pe_data *) PHRQ_malloc( (size_t) count_pe * sizeof(struct pe_data)); + if (pe_ptr_new == NULL) malloc_error(); + memcpy ( (void *) pe_ptr_new, (void *) pe_ptr_old, (size_t) count_pe * sizeof(struct pe_data) ); + for (i = 0; i < count_pe - 1; i++) { + pe_ptr_new[i].rxn = rxn_dup(pe_ptr_old[i].rxn); + } + pe_ptr_new[count_pe - 1].rxn = NULL; + return(pe_ptr_new); +} +/* ---------------------------------------------------------------------- */ +int pe_data_free (struct pe_data *pe_data_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data for pe_data_ptr, including pe_data_ptr. + */ + int i; + + if ( pe_data_ptr == NULL ) return(ERROR); + for (i=0; pe_data_ptr[i].name != NULL; i++) { + rxn_free(pe_data_ptr[i].rxn); + } + pe_data_ptr = (struct pe_data *) free_check_null (pe_data_ptr); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pe_data_store (struct pe_data **pe, const char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find pe name in current list of pe_data structures + * or allocate new pe_data structure + */ + int i; + struct pe_data *pe_data_ptr; +/* + * Search for pe in list + */ + pe_data_ptr = *pe; + for (i=0; pe_data_ptr[i].name != NULL; i++) { + if (strcmp (token, pe_data_ptr[i].name ) == 0 ) { + return (i); + } + } +/* + * Save new struct pe_data in array + */ + *pe = (struct pe_data *) PHRQ_realloc( (void *) *pe, (size_t) (i+2) * sizeof(struct pe_data)); + if (*pe == NULL) malloc_error(); + pe_data_ptr = *pe; + pe_data_ptr[i].name = string_hsave ( token ); + pe_data_ptr[i].rxn = NULL; + pe_data_ptr[i + 1].name = NULL; + return ( i ); +} + +/* ********************************************************************** + * + * Routines related to structure "phases" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct phase *phase_alloc(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space to a phase structure and initializes + * arguments: void + * return: pointer to new phase structure + */ + struct phase *phase_ptr; +/* + * Allocate space + */ + phase_ptr=(struct phase *) PHRQ_malloc(sizeof(struct phase)); + if (phase_ptr == NULL) malloc_error(); +/* + * Initialize space + */ + phase_init(phase_ptr); + return(phase_ptr); +} +/* ---------------------------------------------------------------------- */ +int phase_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares names of phases for sort + */ + const struct phase *phase_ptr1, *phase_ptr2; + phase_ptr1 = * (const struct phase **) ptr1; + phase_ptr2 = * (const struct phase **) ptr2; + return(strcmp_nocase(phase_ptr1->name, phase_ptr2->name)); +} +/* ---------------------------------------------------------------------- */ +int phase_compare_string (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *char_ptr; + const struct phase *phase_ptr; + char_ptr = (const char *) ptr1; + phase_ptr = * (const struct phase **) ptr2; + return(strcmp_nocase(char_ptr, phase_ptr->name)); +} +/* ---------------------------------------------------------------------- */ +int phase_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Deletes phase i from list, phases + * Frees memory allocated to phase[i] and renumbers phases to remove number i. + * Input: i, number of phase + * Return: OK + */ + int j; + + phase_free(phases[i]); + phases[i] = (struct phase *) free_check_null(phases[i]); + for (j=i; j < (count_phases - 1); j++) { + phases[j]=phases[j+1]; + } + count_phases--; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int phase_free(struct phase *phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within phase[i], does not free phase structure + * Input: i, number of phase + * Return: OK + */ + if (phase_ptr == NULL) return(ERROR); + phase_ptr->next_elt = (struct elt_list *) free_check_null (phase_ptr->next_elt); + phase_ptr->next_sys_total = (struct elt_list *) free_check_null (phase_ptr->next_sys_total); + rxn_free (phase_ptr->rxn); + rxn_free (phase_ptr->rxn_s); + rxn_free (phase_ptr->rxn_x); + phase_ptr->add_logk = (struct name_coef *) free_check_null (phase_ptr->add_logk); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct phase *phase_bsearch (char *ptr, int *j, int print) +/* ---------------------------------------------------------------------- */ +{ +/* Binary search the structure array "phases" for a name that is equal to + * ptr. Assumes array phases is in sort order. + * + * Arguments: + * name input, a character string to be located in phases. + * j index number in array phases. + * + * Returns: + * if found, pointer to phase structure. + * if not found, NULL + * + */ + void *void_ptr; + + void_ptr = NULL; + if (count_phases > 0) { + void_ptr = (void *) + bsearch ( (char *) ptr, + (char *) phases, + (size_t) count_phases, + (size_t) sizeof(struct phase *), + phase_compare_string); + } + if (void_ptr == NULL && print == TRUE) { + sprintf(error_string, "Could not find phase in list, %s.", ptr); + error_msg(error_string, CONTINUE); + } + + if (void_ptr == NULL) { + *j = -1; + return(NULL); + } + + *j = (int) ((struct phase **) void_ptr - phases); + return (* (struct phase **) void_ptr); +} +/* ---------------------------------------------------------------------- */ +static int phase_init(struct phase *phase_ptr) +/* ---------------------------------------------------------------------- */ +/* + * set pointers in phase structure to NULL + */ +{ + int i; + + phase_ptr->name=NULL; + phase_ptr->formula=NULL; + phase_ptr->in = FALSE; + phase_ptr->lk = 0.0; + for (i = 0; i < 8; i++) phase_ptr->logk[i]=0.0; + phase_ptr->type = SOLID; + phase_ptr->check_equation = TRUE; + phase_ptr->next_elt = NULL; + phase_ptr->next_sys_total = NULL; + phase_ptr->rxn = NULL; + phase_ptr->rxn_s = NULL; + phase_ptr->rxn_x = NULL; + phase_ptr->add_logk = NULL; + phase_ptr->count_add_logk = 0; + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct phase *phase_store (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for phases. + * + * If found, pointer to the appropriate phase structure is returned. + * + * If the string is not found, a new entry is made at the end of + * the phases array (position count_phases) and count_phases is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * + * Arguments: + * name input, character string to be located or stored. + * + * Returns: + * The address of a phase structure that contains the phase data. + * If phase existed, it is reinitialized. The structure returned + * contains only the name of the phase. + */ + int n; + struct phase *phase_ptr; + ENTRY item, *found_item; + char token[MAX_LENGTH]; + char *ptr; +/* + * Search list + */ + + strcpy(token, name); + str_tolower(token); + ptr = string_hsave(token); + + item.key = ptr; + item.data = NULL; + found_item = hsearch_multi(phases_hash_table, item, FIND); + if (found_item != NULL) { + phase_ptr = (struct phase *) (found_item->data); + phase_free (phase_ptr); + phase_init (phase_ptr); + phase_ptr->name = string_hsave( name ); + return (phase_ptr); + } +/* + * Make new phase structure and return pointer to it + */ + /* make sure there is space in phases */ + n = count_phases++; + if (count_phases >= max_phases) { + space ((void **) ((void *) &phases), count_phases, &max_phases, sizeof(struct phase *)); + } + phases[n]=phase_alloc(); + /* set name in phase structure */ + phases[n]->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = ptr; + item.data = (void *) phases[n]; + found_item = hsearch_multi(phases_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in phase_store."); + error_msg(error_string, CONTINUE); + } + + return (phases[n]); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +struct phase *phase_search (char *ptr, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Linear search of phases to find phase with name in ptr. + * Returns pointer if found. n contains position in array master. + * Returns NULL if not found. + */ + int i; + struct phase *phase_ptr; +/* + * Search phases list + */ + *n = -999; + for (i = 0; i < count_phases; i++) { + if (strcmp_nocase(ptr, phases[i]->name) == 0) { + *n = i; + phase_ptr = phases[i]; + return(phase_ptr); + } + } + return(NULL); +} +/* ---------------------------------------------------------------------- */ +struct phase *phase_store (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for phases. + * + * If found, pointer to the appropriate phase structure is returned. + * + * If the string is not found, a new entry is made at the end of + * the phases array (position count_phases) and count_phases is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * + * Arguments: + * name input, character string to be located or stored. + * + * Returns: + * The address of a phase structure that contains the phase data. + * If phase existed, it is reinitialized. The structure returned + * contains only the name of the phase. + */ + int n; + struct phase *phase_ptr; +/* + * Search list + */ + phase_ptr = phase_search(name, &n); + if (phase_ptr != NULL) { + phase_free (phase_ptr); + phase_init (phase_ptr); + phase_ptr->name = string_hsave( name ); + return (phase_ptr); + } +/* + * Make new phase structure and return pointer to it + */ + /* make sure there is space in phases */ + n = count_phases++; + if (count_phases >= max_phases) { + space ((void **) &phases, count_phases, &max_phases, sizeof(struct phase *)); + } + phases[n]=phase_alloc(); + /* set name in phase structure */ + phases[n]->name = string_hsave( name ); + return (phases[n]); +} +#endif +/* ********************************************************************** + * + * Routines related to structure "pp_assemblage" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pp_assemblage *pp_assemblage_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct pp_assemblage *pp_assemblage_ptr; + pp_assemblage_ptr = (struct pp_assemblage *) PHRQ_malloc(sizeof (struct pp_assemblage)); + if (pp_assemblage_ptr == NULL) malloc_error(); + pp_assemblage_ptr->description = NULL; + pp_assemblage_ptr->next_elt = NULL; + pp_assemblage_ptr->count_comps = 0; + pp_assemblage_ptr->pure_phases = NULL; + return ( pp_assemblage_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct pp_assemblage *pp_assemblage_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array pp_assemblage to find user number k. + * Assumes pp_assemblage is in sort order. + * + * Input: k, user number to find. + * + * Output: n, position in array pp_assemblage for user number k. + * + * Return: pointer to pp_assemblage structure for user number k, if found. + * NULL if not found. + */ + void *void_ptr; + if (count_pp_assemblage == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) pp_assemblage, + (size_t) count_pp_assemblage, + (size_t) sizeof(struct pp_assemblage), + pp_assemblage_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct pp_assemblage *) void_ptr - pp_assemblage); + return ( (struct pp_assemblage *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct pp_assemblage *pp_assemblage_ptr1, *pp_assemblage_ptr2; + pp_assemblage_ptr1 = (const struct pp_assemblage *) ptr1; + pp_assemblage_ptr2 = (const struct pp_assemblage *) ptr2; + if (pp_assemblage_ptr1->n_user > pp_assemblage_ptr2->n_user) return(1); + if (pp_assemblage_ptr1->n_user < pp_assemblage_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare pp_assemblage user numbers + */ + const int *nptr1; + const struct pp_assemblage *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct pp_assemblage *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies pp_assemblage data from pp_assemblage_old_ptr to pp_assemblage_new_ptr. + * Space for a pp_assemblage_new_ptr must already be malloced. + * Space for list of pure phases in assemblage is malloced here. + */ + int count_comps; + char token[MAX_LENGTH]; +/* + * Store data for structure pp_assemblage + */ + pp_assemblage_new_ptr->n_user = n_user_new; + pp_assemblage_new_ptr->n_user_end = n_user_new; + pp_assemblage_new_ptr->new_def = pp_assemblage_old_ptr->new_def; + sprintf(token, "Pp_Assemblage defined in simulation %d.", simulation); + pp_assemblage_new_ptr->description = string_duplicate(token); + pp_assemblage_new_ptr->next_elt = elt_list_dup(pp_assemblage_old_ptr->next_elt); +/* + * Count pure phases + */ + count_comps = pp_assemblage_old_ptr->count_comps; + pp_assemblage_new_ptr->count_comps = count_comps; +/* + * Malloc space and copy + */ + pp_assemblage_new_ptr->pure_phases = (struct pure_phase *) PHRQ_malloc( (size_t) count_comps * sizeof(struct pure_phase)); + if (pp_assemblage_new_ptr->pure_phases == NULL) malloc_error(); + + memcpy( (void *) pp_assemblage_new_ptr->pure_phases, + (void *) pp_assemblage_old_ptr->pure_phases, + (size_t) count_comps * sizeof(struct pure_phase) ); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an pp_assemblage definition from position n + * to position count_pp_assemblage. + */ + space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); + pp_assemblage_copy(&pp_assemblage[n], &pp_assemblage[count_pp_assemblage], n_user); + count_pp_assemblage++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies pp_assemblage[n_user_old] to old n_user_new space if + * found or to pp_assemblage[count_pp_assemblage] if not found. + * Pp_Assemblage array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct pp_assemblage *pp_assemblage_ptr_old, *pp_assemblage_ptr_new; +/* + * Find n_user_old in structure array pp_assemblage + */ + if (n_user_old == n_user_new) return(OK); + pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); + if (pp_assemblage_ptr_old == NULL) { + sprintf(error_string, "Pp_Assemblage %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array pp_assemblage or make new space + */ + sort = FALSE; + pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); + if (pp_assemblage_ptr_new != NULL) { + pp_assemblage_free(pp_assemblage_ptr_new); + } else { + space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); + if (n_user_new < pp_assemblage[count_pp_assemblage-1].n_user) sort = TRUE; + n_new = count_pp_assemblage++; + } +/* + * Copy data + */ + pp_assemblage_copy(&pp_assemblage[n_old], &pp_assemblage[n_new], n_user_new); + if (sort == TRUE) pp_assemblage_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array pp_assemblage. + */ +{ + int i; + int n_old; + struct pp_assemblage *pp_assemblage_ptr_old; +/* + * Find n_user_old in structure array + */ + pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); + if (pp_assemblage_ptr_old != NULL) { + /* + * Delete pp_assemblage + */ + pp_assemblage_free(&pp_assemblage[n_old]); + + for(i = n_old + 1; i < count_pp_assemblage; i++) { + memcpy( (void *) &pp_assemblage[i - 1], (void *) &pp_assemblage[i], + (size_t) sizeof (struct pp_assemblage) ); + } + count_pp_assemblage--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_free (struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for pp_assemblage structure + */ + if (pp_assemblage_ptr == NULL) return(ERROR); + + pp_assemblage_ptr->description = (char *) free_check_null (pp_assemblage_ptr->description); + pp_assemblage_ptr->next_elt = (struct elt_list *) free_check_null (pp_assemblage_ptr->next_elt); + pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null (pp_assemblage_ptr->pure_phases); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_init (struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides initial values for a new pp_assemblage + * arguments: + * n position in array pp_assemblage + * n_user user number for pp_assemblage + * return: OK + */ + pp_assemblage_ptr->n_user = n_user; + pp_assemblage_ptr->n_user_end = n_user_end; + pp_assemblage_ptr->new_def = TRUE; + pp_assemblage_ptr->description = string_duplicate(description); + + pp_assemblage_ptr->next_elt = NULL; + pp_assemblage_ptr->count_comps = 0; + pp_assemblage_ptr->pure_phases = (struct pure_phase *) PHRQ_malloc((size_t) sizeof(struct pure_phase)); + if (pp_assemblage_ptr->pure_phases == NULL) malloc_error(); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies pp_assemblage_ptr_old to old n_user_new space if + * found or to pp_assemblage[count_pp_assemblage] if not found. + * Pp_Assemblage array may not be in sort order after the copy. + */ + int n_new, sort; + struct pp_assemblage *pp_assemblage_ptr_new; +/* + * Find n_user_old in structure array pp_assemblage + */ + if (pp_assemblage_ptr_old == NULL) { + sprintf(error_string, "Pp_Assemblage pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array pp_assemblage or make new space + */ + sort = FALSE; + pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); + if (pp_assemblage_ptr_new == pp_assemblage_ptr_old) return(OK); + if (pp_assemblage_ptr_new != NULL) { + pp_assemblage_free(pp_assemblage_ptr_new); + } else { + space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); + if (n_user_new < pp_assemblage[count_pp_assemblage-1].n_user) sort = TRUE; + n_new = count_pp_assemblage++; + } +/* + * Copy data + */ + pp_assemblage_copy(pp_assemblage_ptr_old, &pp_assemblage[n_new], n_user_new); + if (sort == TRUE) pp_assemblage_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct pp_assemblage *pp_assemblage_ptr; + pp_assemblage_ptr = pp_assemblage_alloc(); + pp_assemblage_copy(pp_assemblage_old_ptr, pp_assemblage_ptr, n_user_new); + return (pp_assemblage_ptr); +} +/* ---------------------------------------------------------------------- */ +struct pp_assemblage *pp_assemblage_search (int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "pp_assemblage" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in pp_assemblage + * + * Returns: + * if found, the address of the pp_assemblage element + * if not found, NULL + */ + int i; + for (i=0; i < count_pp_assemblage; i++) { + if ( pp_assemblage[i].n_user == n_user) { + *n = i; + return (&(pp_assemblage[i])); + } + } +/* + * Pp_Assemblage not found + */ + return (NULL); +} +/* ---------------------------------------------------------------------- */ +int pp_assemblage_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of pp_assemblage structures + */ + if (count_pp_assemblage > 0) { + qsort (pp_assemblage, (size_t) count_pp_assemblage, (size_t) sizeof(struct pp_assemblage), + pp_assemblage_compare); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int pure_phase_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct pure_phase *pure_phase_ptr1, *pure_phase_ptr2; + pure_phase_ptr1 = (const struct pure_phase *) ptr1; + pure_phase_ptr2 = (const struct pure_phase *) ptr2; + return(strcmp_nocase(pure_phase_ptr1->name, pure_phase_ptr2->name)); + +} +/* ********************************************************************** + * + * Routines related to structure "rates" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct rate *rate_bsearch (char *ptr, int *j) +/* ---------------------------------------------------------------------- */ +{ +/* Binary search the structure array "rates" for a name that is equal to + * ptr. Assumes array rates is in sort order. + * + * Arguments: + * name input, a character string to be located in rates. + * j index number in array rates. + * + * Returns: + * if found, pointer to rate structure. + * if not found, NULL + * + */ + void *void_ptr; + + if (count_rates == 0) { + *j = -1; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) ptr, + (char *) rates, + (size_t) count_rates, + (size_t) sizeof(struct rate *), + rate_compare_string); + + if (void_ptr == NULL) { + *j = -1; + return(NULL); + } + + *j = (int) ((struct rate *) void_ptr - rates); + return ((struct rate *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int rate_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares names of rates for sort + */ + const struct rate *rate_ptr1, *rate_ptr2; + rate_ptr1 = * (const struct rate **) ptr1; + rate_ptr2 = * (const struct rate **) ptr2; + return(strcmp_nocase(rate_ptr1->name, rate_ptr2->name)); +} +/* ---------------------------------------------------------------------- */ +int rate_compare_string (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *char_ptr; + const struct rate *rate_ptr; + char_ptr = (const char *) ptr1; + rate_ptr = * (const struct rate **) ptr2; + return(strcmp_nocase(char_ptr, rate_ptr->name)); +} +/* ---------------------------------------------------------------------- */ +int rate_free(struct rate *rate_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within rate[i], does not free rate structure + * Input: i, number of rate + * Return: OK + */ + char cmd[] = "new; quit"; + + if (rate_ptr == NULL) return(ERROR); + rate_ptr->commands = (char *) free_check_null(rate_ptr->commands); + basic_run(cmd, rate_ptr->linebase, rate_ptr->varbase, rate_ptr->loopbase); + rate_ptr->linebase = NULL; + rate_ptr->varbase = NULL; + rate_ptr->loopbase = NULL; + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct rate *rate_search (char *name, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "rates" for name. + * + * Arguments: + * name input, name of rate + * n output, position in rates + * + * Returns: + * if found, the address of the pp_assemblage element + * if not found, NULL + */ + int i; + *n = -1; + for (i=0; i < count_rates; i++) { + if ( strcmp_nocase(rates[i].name, name) == 0) { + *n = i; + return (&(rates[i])); + } + } +/* + * rate name not found + */ + return (NULL); +} +/* ---------------------------------------------------------------------- */ +int rate_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of rate structures + */ + if (count_rates > 0) { + qsort (rates, (size_t) count_rates, (size_t) sizeof(struct rate), + rate_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "reaction", balanced chemical reactions + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct reaction *rxn_alloc(int ntokens) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Allocates space to a rxn structure + * input: ntokens, number of tokens in reaction + * return: pointer to a species structure + */ + struct reaction *rxn_ptr; +/* + * Malloc reaction structure + */ + rxn_ptr=(struct reaction *) PHRQ_malloc(sizeof(struct reaction)); + if (rxn_ptr == NULL) malloc_error(); +/* + * zero log k data + */ + for (i = 0; i < 7; i++) { + rxn_ptr->logk[i] = 0.0; + } +/* + * Malloc rxn_token structure + */ + rxn_ptr->token = (struct rxn_token *) PHRQ_malloc((size_t) ntokens*sizeof(struct rxn_token)); + if (rxn_ptr->token == NULL) malloc_error(); + return(rxn_ptr); +} +/* ---------------------------------------------------------------------- */ +struct reaction *rxn_dup(struct reaction *rxn_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * mallocs space for a reaction and copies the reaction + * input: rxn_ptr_old, pointer to a reaction structure to copy + * + * Return: rxn_ptr_new, pointer to duplicated structure to copy + */ + int i; + struct reaction *rxn_ptr_new; + + if (rxn_ptr_old == NULL) return(NULL); + for (i = 0; rxn_ptr_old->token[i].s != NULL; i++); + + rxn_ptr_new = rxn_alloc( i + 1); +/* + * Copy logk data + */ + memcpy (rxn_ptr_new->logk, rxn_ptr_old->logk, (size_t) 7 * sizeof (LDBLE)); +/* + * Copy tokens + */ + memcpy (rxn_ptr_new->token, rxn_ptr_old->token, (size_t) (i + 1) * sizeof (struct rxn_token)); + + return(rxn_ptr_new); +} +/* ---------------------------------------------------------------------- */ +LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Finds coefficient of token in reaction. + * input: r_ptr, pointer to a reaction structure + * str, string to find as reaction token + * + * Return: 0.0, if token not found + * coefficient of token, if found. + */ + struct rxn_token *r_token; + LDBLE coef; + + r_token=r_ptr->token + 1; + coef=0.0; + while (r_token->s != NULL) { + if (strcmp(r_token->s->name, str) == 0) { + coef=r_token->coef; + break; + } + r_token++; + } + return(coef); +} +/* ---------------------------------------------------------------------- */ +int rxn_free(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space allocated for a reaction structure + * input: rxn_ptr, pointer to reaction structure + * return: ERROR, if pointer is NULL + * OK, otherwise. + */ + if (rxn_ptr == NULL) return(ERROR); + rxn_ptr->token = (struct rxn_token *) free_check_null (rxn_ptr->token); + rxn_ptr = (struct reaction *) free_check_null (rxn_ptr); + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "species" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct species *s_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a species structure, initializes + * arguments: void + * return: pointer to a species structure + */ +{ + struct species *s_ptr; + s_ptr=(struct species *) PHRQ_malloc(sizeof(struct species)); + if (s_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + s_init(s_ptr); + + return(s_ptr); +} +/* ---------------------------------------------------------------------- */ +int s_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct species *s_ptr1, *s_ptr2; + s_ptr1 = * (const struct species **) ptr1; + s_ptr2 = * (const struct species **) ptr2; + return(strcmp(s_ptr1->name, s_ptr2->name)); + +} +/* ---------------------------------------------------------------------- */ +int s_delete (int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete species i: free memory and renumber array of pointers, s. + */ + int j; + + s_free (s[i]); + s[i] = (struct species *) free_check_null(s[i]); + for (j=i; j < (count_s - 1); j++) { + s[j]=s[j+1]; + } + count_s--; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_free (struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for species structure, s_ptr. Does not free s_ptr. + */ + if (s_ptr == NULL) return(ERROR); + s_ptr->next_elt = (struct elt_list *) free_check_null (s_ptr->next_elt); + s_ptr->next_secondary = (struct elt_list *) free_check_null (s_ptr->next_secondary); + s_ptr->next_sys_total = (struct elt_list *) free_check_null (s_ptr->next_sys_total); + s_ptr->add_logk = (struct name_coef *) free_check_null(s_ptr->add_logk); + rxn_free (s_ptr->rxn); + rxn_free (s_ptr->rxn_s); + rxn_free (s_ptr->rxn_x); + s_ptr->diff_layer = (struct species_diff_layer *) free_check_null (s_ptr->diff_layer); + return(OK); +} +/* ---------------------------------------------------------------------- */ +static int s_init(struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a species structure + */ +{ + int i; +/* + * set pointers in structure to NULL + */ + s_ptr->name=NULL; + s_ptr->mole_balance=NULL; + s_ptr->primary=NULL; + s_ptr->secondary=NULL; + s_ptr->next_elt=NULL; + s_ptr->next_secondary=NULL; + s_ptr->next_sys_total=NULL; + s_ptr->rxn=NULL; + s_ptr->rxn_s=NULL; + s_ptr->rxn_x=NULL; + s_ptr->diff_layer = NULL; +/* + * set varibles = 0 + */ + s_ptr->in = FALSE; + s_ptr->gfw = 0.0; + s_ptr->z = 0.0; + s_ptr->alk = 0.0; + s_ptr->carbon = 0.0; + s_ptr->co2 = 0.0; + s_ptr->h = 0.0; + s_ptr->o = 0.0; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + s_ptr->lk = 0.0; + for (i =0; i < 8; i++) { + s_ptr->logk[i] = 0.0; + } + s_ptr->count_add_logk = 0; + s_ptr->add_logk = NULL; + s_ptr->lg = 0.0; + s_ptr->lm = 0.0; + s_ptr->la = 0.0; + s_ptr->dg = 0.0; + s_ptr->moles = 0.0; + s_ptr->type = 0; + s_ptr->gflag = 0; + s_ptr->check_equation = TRUE; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct species *s_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for species. + * + * Arguments: + * name input, a character string to be located in species. + * i is obsolete. + * + * Returns: + * If found, pointer to the appropriate species structure is returned. + * else, NULL pointer is returned. + */ + struct species *s_ptr; + ENTRY item, *found_item; + + item.key = name; + item.data = NULL; + found_item = hsearch_multi(species_hash_table, item, FIND); + if (found_item != NULL) { + s_ptr = (struct species *) (found_item->data); + return (s_ptr); + } + return (NULL); +} +/* ---------------------------------------------------------------------- */ +struct species *s_store (char *name, LDBLE z, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for species. + * + * Pointer to a species structure is always returned. + * + * If the string is not found, a new entry is made at the end of + * the elements array (position count_elements) and count_elements is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old species structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old species structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "species". + * z input, charge on "name" + * replace_if_found input, TRUE means reinitialize species if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to species structure "s" where "name" can be found. + */ + int n; + struct species *s_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + item.key = name; + item.data = NULL; + found_item = hsearch_multi(species_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + s_ptr = (struct species *) (found_item->data); + return (s_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + s_ptr = (struct species *) (found_item->data); + s_free(s_ptr); + s_init(s_ptr); + } else { + n = count_s++; + /* make sure there is space in s */ + if (count_s >= max_s) { + space ((void **) ((void *) &s), count_s, &max_s, sizeof(struct species *)); + } + /* Make new species structure */ + s[n] = s_alloc(); + s_ptr = s[n]; + } + /* set name and z in pointer in species structure */ + s_ptr->name = string_hsave( name ); + s_ptr->z = z; +/* + * Update hash table + */ + item.key = s_ptr->name; + item.data = (void *) s_ptr; + found_item = hsearch_multi(species_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in species_store."); + error_msg(error_string, CONTINUE); + } + + return (s_ptr); +} +/* ********************************************************************** + * + * Routines related to structure "s_s_assemblage" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct s_s_assemblage *s_s_assemblage_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct s_s_assemblage *s_s_assemblage_ptr; + s_s_assemblage_ptr = (struct s_s_assemblage *) PHRQ_malloc(sizeof (struct s_s_assemblage)); + if (s_s_assemblage_ptr == NULL) malloc_error(); + s_s_assemblage_ptr->description = NULL; + s_s_assemblage_ptr->count_s_s = 0; + s_s_assemblage_ptr->s_s = NULL; + return ( s_s_assemblage_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct s_s_assemblage *s_s_assemblage_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array s_s_assemblage to find user number k. + * Assumes s_s_assemblage is in sort order. + * + * Input: k, user number to find. + * + * Output: n, position in array s_s_assemblage for user number k. + * + * Return: pointer to s_s_assemblage structure for user number k, if found. + * NULL if not found. + */ + void *void_ptr; + if (count_s_s_assemblage == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) s_s_assemblage, + (size_t) count_s_s_assemblage, + (size_t) sizeof(struct s_s_assemblage), + s_s_assemblage_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct s_s_assemblage *) void_ptr - s_s_assemblage); + return ( (struct s_s_assemblage *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct s_s_assemblage *s_s_assemblage_ptr1, *s_s_assemblage_ptr2; + s_s_assemblage_ptr1 = (const struct s_s_assemblage *) ptr1; + s_s_assemblage_ptr2 = (const struct s_s_assemblage *) ptr2; + if (s_s_assemblage_ptr1->n_user > s_s_assemblage_ptr2->n_user) return(1); + if (s_s_assemblage_ptr1->n_user < s_s_assemblage_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare s_s_assemblage user numbers + */ + const int *nptr1; + const struct s_s_assemblage *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct s_s_assemblage *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, + struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies s_s_assemblage data from s_s_assemblage_old_ptr to s_s_assemblage_new_ptr. + * Space for a s_s_assemblage_new_ptr must already be malloced. + * Space for list of pure phases in assemblage is malloced here. + */ + int i, count_comps, count_s_s; + char token[MAX_LENGTH]; +/* + * Store data for structure s_s_assemblage + */ + memcpy(s_s_assemblage_new_ptr, s_s_assemblage_old_ptr, sizeof(struct s_s_assemblage)); + s_s_assemblage_new_ptr->n_user = n_user_new; + s_s_assemblage_new_ptr->n_user_end = n_user_new; + sprintf(token, "S_S_Assemblage defined in simulation %d.", simulation); + s_s_assemblage_new_ptr->description = string_duplicate(token); + s_s_assemblage_new_ptr->new_def = FALSE; +/* + * Malloc space for s_s structures and fill + */ + count_s_s = s_s_assemblage_old_ptr->count_s_s; + s_s_assemblage_new_ptr->s_s = (struct s_s *) PHRQ_malloc( (size_t) count_s_s * sizeof(struct s_s)); + if (s_s_assemblage_new_ptr->s_s == NULL) malloc_error(); + memcpy( (void *) s_s_assemblage_new_ptr->s_s, + (void *) s_s_assemblage_old_ptr->s_s, + (size_t) count_s_s * sizeof(struct s_s) ); +/* + * Malloc space for components + */ + for (i = 0; i < count_s_s; i++) { + count_comps = s_s_assemblage_old_ptr->s_s[i].count_comps; + s_s_assemblage_new_ptr->s_s[i].comps = (struct s_s_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct s_s_comp)); + if (s_s_assemblage_new_ptr->s_s[i].comps == NULL) malloc_error(); + memcpy( (void *) s_s_assemblage_new_ptr->s_s[i].comps, + (void *) s_s_assemblage_old_ptr->s_s[i].comps, + (size_t) count_comps * sizeof(struct s_s_comp) ); + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an s_s_assemblage definition from position n + * to position count_s_s_assemblage. + */ + space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + s_s_assemblage_copy(&s_s_assemblage[n], &s_s_assemblage[count_s_s_assemblage], n_user); + count_s_s_assemblage++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies s_s_assemblage[n_user_old] to old n_user_new space if + * found or to s_s_assemblage[count_s_s_assemblage] if not found. + * S_S_Assemblage array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct s_s_assemblage *s_s_assemblage_ptr_old, *s_s_assemblage_ptr_new; +/* + * Find n_user_old in structure array s_s_assemblage + */ + if (n_user_old == n_user_new) return(OK); + s_s_assemblage_ptr_old = s_s_assemblage_bsearch(n_user_old, &n_old); + if (s_s_assemblage_ptr_old == NULL) { + sprintf(error_string, "S_S_Assemblage %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array s_s_assemblage or make new space + */ + sort = FALSE; + s_s_assemblage_ptr_new = s_s_assemblage_bsearch(n_user_new, &n_new); + if (s_s_assemblage_ptr_new != NULL) { + s_s_assemblage_free(s_s_assemblage_ptr_new); + } else { + space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + if (n_user_new < s_s_assemblage[count_s_s_assemblage-1].n_user) sort = TRUE; + n_new = count_s_s_assemblage++; + } +/* + * Copy data + */ + s_s_assemblage_copy(&s_s_assemblage[n_old], &s_s_assemblage[n_new], n_user_new); + if (sort == TRUE) s_s_assemblage_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array s_s_assemblage. + */ +{ + int i; + int n_old; + struct s_s_assemblage *s_s_assemblage_ptr_old; +/* + * Find n_user_old in structure array + */ + s_s_assemblage_ptr_old = s_s_assemblage_bsearch(n_user_old, &n_old); + if (s_s_assemblage_ptr_old != NULL) { + /* + * Delete s_s_assemblage + */ + s_s_assemblage_free(&s_s_assemblage[n_old]); + + for(i = n_old + 1; i < count_s_s_assemblage; i++) { + memcpy( (void *) &s_s_assemblage[i - 1], (void *) &s_s_assemblage[i], + (size_t) sizeof (struct s_s_assemblage) ); + } + count_s_s_assemblage--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_free (struct s_s_assemblage *s_s_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for s_s_assemblage structure + */ + int i; + + if (s_s_assemblage_ptr == NULL) return(ERROR); + s_s_assemblage_ptr->description = (char *) free_check_null (s_s_assemblage_ptr->description); + for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { + s_s_assemblage_ptr->s_s[i].comps = (struct s_s_comp *) free_check_null(s_s_assemblage_ptr->s_s[i].comps); + } + s_s_assemblage_ptr->s_s = (struct s_s *) free_check_null (s_s_assemblage_ptr->s_s); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_init (struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ + s_s_assemblage_ptr->n_user = n_user; + s_s_assemblage_ptr->n_user_end = n_user_end; + s_s_assemblage_ptr->description = string_duplicate(description); + s_s_assemblage_ptr->new_def = TRUE; + s_s_assemblage_ptr->count_s_s = 0; + s_s_assemblage_ptr->s_s = (struct s_s *) PHRQ_malloc((size_t) sizeof(struct s_s)); + if (s_s_assemblage_ptr->s_s == NULL) malloc_error(); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies s_s_assemblage_ptr_old to old n_user_new space if + * found or to s_s_assemblage[count_s_s_assemblage] if not found. + * S_S_Assemblage array may not be in sort order after the copy. + */ + int n_new, sort; + struct s_s_assemblage *s_s_assemblage_ptr_new; +/* + * Find n_user_old in structure array s_s_assemblage + */ + if (s_s_assemblage_ptr_old == NULL) { + sprintf(error_string, "S_S_Assemblage pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array s_s_assemblage or make new space + */ + sort = FALSE; + s_s_assemblage_ptr_new = s_s_assemblage_bsearch(n_user_new, &n_new); + if (s_s_assemblage_ptr_new == s_s_assemblage_ptr_old) return(OK); + if (s_s_assemblage_ptr_new != NULL) { + s_s_assemblage_free(s_s_assemblage_ptr_new); + } else { + space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); + if (n_user_new < s_s_assemblage[count_s_s_assemblage-1].n_user) sort = TRUE; + n_new = count_s_s_assemblage++; + } +/* + * Copy data + */ + s_s_assemblage_copy(s_s_assemblage_ptr_old, &s_s_assemblage[n_new], n_user_new); + if (sort == TRUE) s_s_assemblage_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage *s_s_assemblage_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct s_s_assemblage *s_s_assemblage_ptr; + s_s_assemblage_ptr = s_s_assemblage_alloc(); + s_s_assemblage_copy(s_s_assemblage_old_ptr, s_s_assemblage_ptr, n_user_new); + return (s_s_assemblage_ptr); +} +/* ---------------------------------------------------------------------- */ +struct s_s_assemblage *s_s_assemblage_search (int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "s_s_assemblage" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in s_s_assemblage + * + * Returns: + * if found, the address of the s_s_assemblage element + * if not found, NULL + */ + int i; + for (i=0; i < count_s_s_assemblage; i++) { + if ( s_s_assemblage[i].n_user == n_user) { + *n = i; + return (&(s_s_assemblage[i])); + } + } +/* + * S_S_Assemblage not found + */ + return (NULL); +} +/* ---------------------------------------------------------------------- */ +int s_s_assemblage_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of s_s_assemblage structures + */ + if (count_s_s_assemblage > 0) { + qsort (s_s_assemblage, (size_t) count_s_s_assemblage, (size_t) sizeof(struct s_s_assemblage), + s_s_assemblage_compare); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct s_s *s_s_ptr1, *s_s_ptr2; + s_s_ptr1 = (const struct s_s *) ptr1; + s_s_ptr2 = (const struct s_s *) ptr2; + return(strcmp_nocase(s_s_ptr1->name, s_s_ptr2->name)); + +} +/* ********************************************************************** + * + * Routines related to structure "save_values" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct save_values *save_values_bsearch (struct save_values *k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search save_values to find if one exists with given coefficients + * Save_Values is assumed to be in sort order by count_subscripts and + * values of subscripts + */ + void *void_ptr; + if (count_save_values == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) k, + (char *) save_values, + (size_t) count_save_values, + (size_t) sizeof(struct save_values), + save_values_compare); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct save_values *) void_ptr - save_values); + return ( (struct save_values *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int save_values_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct save_values *save_values_ptr1, *save_values_ptr2; + save_values_ptr1 = (const struct save_values *) ptr1; + save_values_ptr2 = (const struct save_values *) ptr2; + if (save_values_ptr1->count_subscripts < save_values_ptr2->count_subscripts) { + return(-1); + } else if (save_values_ptr1->count_subscripts > save_values_ptr2->count_subscripts) { + return(1); + } else { + for (i=0; i < save_values_ptr1->count_subscripts ;i++) { + if (save_values_ptr1->subscripts[i] < save_values_ptr2->subscripts[i]) { + return(-1); + } else if (save_values_ptr1->subscripts[i] > save_values_ptr2->subscripts[i]) { + return(1); + } + } + } + return(0); +} +/* ---------------------------------------------------------------------- */ +int save_values_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of save_values structures + */ + if (count_save_values > 0) { + qsort (save_values, (size_t) count_save_values, (size_t) sizeof(struct save_values), + save_values_compare); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int save_values_store(struct save_values *s_v) +/* ---------------------------------------------------------------------- */ +{ +/* + * Look for subscripts + */ + int n, i; + struct save_values *s_v_ptr; + + s_v_ptr = save_values_bsearch(s_v, &n); + if (s_v_ptr != NULL) { + s_v_ptr->value = s_v->value; + } else { + save_values = (struct save_values *) PHRQ_realloc(save_values, (size_t) (count_save_values + 1) * sizeof( struct save_values)); + if (save_values == NULL) malloc_error(); + save_values[count_save_values].value = s_v->value; + save_values[count_save_values].count_subscripts = s_v->count_subscripts; + i = s_v->count_subscripts; + if (i == 0) i = 1; + save_values[count_save_values].subscripts = (int *) PHRQ_malloc ((size_t) i * sizeof(int)); + if (save_values[count_save_values].subscripts == NULL) malloc_error(); + save_values[count_save_values].subscripts = (int *) memcpy(save_values[count_save_values].subscripts, s_v->subscripts, (size_t) i * sizeof(int)); + count_save_values++; + save_values_sort(); + } + + if (count_save_values > 0) { + qsort (save_values, (size_t) count_save_values, (size_t) sizeof(struct save_values), + save_values_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "solution" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int conc_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct conc *conc_ptr1, *conc_ptr2; + conc_ptr1 = (const struct conc *) ptr1; + conc_ptr2 = (const struct conc *) ptr2; + return(strcmp_nocase(conc_ptr1->description, conc_ptr2->description)); + +} +/* ---------------------------------------------------------------------- */ +int conc_init (struct conc *conc_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (conc_ptr == NULL) return(ERROR); + conc_ptr->equation_name = NULL; + conc_ptr->phase = NULL; + conc_ptr->phase_si = 0.0; + conc_ptr->units=NULL; + conc_ptr->n_pe=-1; + conc_ptr->as=NULL; + conc_ptr->gfw= 0.0; + return OK; +} +/* ---------------------------------------------------------------------- */ +int isotope_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct isotope *iso_ptr1, *iso_ptr2; + + iso_ptr1 = (const struct isotope *) ptr1; + iso_ptr2 = (const struct isotope *) ptr2; + i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); + if (i != 0) return(i); + if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) { + return(-1); + } else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) { + return(1); + } + return(0); +} +/* ---------------------------------------------------------------------- */ +struct solution *solution_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a solution structure + * arguments + * input: none + * return: pointer to a solution structure + */ +{ + int max_mass_balance; + struct solution *solution_ptr; + solution_ptr=(struct solution *) PHRQ_malloc(sizeof(struct solution)); + if (solution_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL + */ + solution_ptr->description=NULL; + solution_ptr->units=NULL; +/* + * Initial allocation of space for totals and activities + */ + max_mass_balance=MAX_MASS_BALANCE; + space ((void **) &(solution_ptr->totals), INIT, &max_mass_balance, sizeof (struct conc)); + max_mass_balance=MAX_MASS_BALANCE; + solution_ptr->totals[0].description = NULL; + space ((void **) &(solution_ptr->master_activity), INIT, &max_mass_balance, sizeof (struct master_activity)); + solution_ptr->master_activity[0].description = NULL; + solution_ptr->species_gamma = NULL; + solution_ptr->count_species_gamma = 0; +/* + * Initial allocation of space for pe's + */ + solution_ptr->pe = pe_data_alloc(); +/* + * Initial allocation of space for isotopes + */ + solution_ptr->isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); + if (solution_ptr->isotopes == NULL) malloc_error(); + solution_ptr->new_def=TRUE; + + return(solution_ptr); +} +/* ---------------------------------------------------------------------- */ +struct solution *solution_bsearch (int k, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of solution solution array to find user number k. + * Assumes array solution is in sort order. + * + * Input: k user number to find. + * print, TRUE print warning if solution not found. + * Output: n, position of solution ptr in solution array. + * Return: pointer to solution structure if found + * NULL if not found. + */ + void *void_ptr; + void_ptr = NULL; + if (count_solution > 0) { + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) solution, + (size_t) count_solution, + (size_t) sizeof(struct solution *), + solution_compare_int); + } + if (void_ptr == NULL && print == TRUE) { + sprintf(error_string, "Solution %d not found.", k); + error_msg(error_string, CONTINUE); + } + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + + *n = (int) ((struct solution **) void_ptr - solution); + return (* (struct solution **) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int solution_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare solution user numbers + */ + const struct solution *nptr1; + const struct solution *nptr2; + + nptr1= *(const struct solution **) ptr1; + nptr2= *(const struct solution **) ptr2; + if (nptr1->n_user > nptr2->n_user) return(1); + if (nptr1->n_user < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int solution_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare solution user number to an integer + */ + const int *nptr1; + const struct solution *nptr2; + + nptr1= (const int *) ptr1; + nptr2= *(const struct solution **) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +static struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies solution data to new structure. + * Space for new structure is malloced here. + * + * Input: solution_old_ptr, pointer to structure to be copied. + * n_user_new, user number to give to the new solution. + * + * Return: pointer to new solution structure. + */ + int i; + int count_totals, count_master_activity; + struct solution *solution_new_ptr; +/* + * malloc space for new solution structure + */ + solution_new_ptr = (struct solution *) PHRQ_malloc(sizeof(struct solution)); + if (solution_new_ptr == NULL) malloc_error(); +/* + * Copy solution data, but set pointers pe and totals to NULL + */ + memcpy ( (void *) solution_new_ptr, (void *) solution_old_ptr, (size_t) sizeof (struct solution)); + solution_new_ptr->n_user = n_user_new; + solution_new_ptr->n_user_end = n_user_new; + solution_new_ptr->description = string_duplicate(solution_old_ptr->description); +/* + * Count totals data and malloc space + */ + for (i = 0; solution_old_ptr->totals[i].description != NULL; i++); + count_totals = i + 1; + solution_new_ptr->totals = (struct conc *) PHRQ_malloc( (size_t) count_totals * sizeof(struct conc)); + if (solution_new_ptr->totals == NULL) malloc_error(); +/* + * Copy totals data + */ + memcpy ( (void *) solution_new_ptr->totals, (void *) solution_old_ptr->totals, (size_t) count_totals * sizeof (struct conc)); +/* + * Count master activity guesses and malloc space + */ + for (i = 0; solution_old_ptr->master_activity[i].description != NULL; i++); + count_master_activity = i + 1; + solution_new_ptr->master_activity = (struct master_activity *) PHRQ_malloc( (size_t) count_master_activity * sizeof(struct master_activity)); + if (solution_new_ptr->master_activity == NULL) malloc_error(); +/* + * Copy master activity guesses + */ + memcpy ( (void *) solution_new_ptr->master_activity, (void *) solution_old_ptr->master_activity, (size_t) count_master_activity * sizeof (struct master_activity)); +/* + * malloc space for species gammas + */ + if (solution_old_ptr->count_species_gamma > 0) { + solution_new_ptr->species_gamma = (struct master_activity *) PHRQ_malloc( (size_t) solution_old_ptr->count_species_gamma * sizeof(struct master_activity)); + if (solution_new_ptr->species_gamma == NULL) malloc_error(); + /* + * Copy species gammas + */ + memcpy ( (void *) solution_new_ptr->species_gamma, (void *) solution_old_ptr->species_gamma, (size_t) solution_old_ptr->count_species_gamma * sizeof (struct master_activity)); + solution_new_ptr->count_species_gamma = solution_old_ptr->count_species_gamma; + } else { + solution_new_ptr->species_gamma = NULL; + solution_new_ptr->count_species_gamma = 0; + } +/* + * Copy pe data + */ + solution_new_ptr->pe = pe_data_dup (solution_old_ptr->pe); +/* + * Malloc and copy isotope data + */ + if (solution_old_ptr->count_isotopes > 0) { + solution_new_ptr->count_isotopes = solution_old_ptr->count_isotopes; + solution_new_ptr->isotopes = (struct isotope *) PHRQ_malloc((size_t) solution_old_ptr->count_isotopes * sizeof(struct isotope)); + if (solution_new_ptr->isotopes == NULL) malloc_error(); + memcpy(solution_new_ptr->isotopes, solution_old_ptr->isotopes, (size_t) solution_old_ptr->count_isotopes * sizeof(struct isotope)); + } else { + solution_new_ptr->count_isotopes = 0; + solution_new_ptr->isotopes = NULL; + } +/* + * Return pointer to new structure + */ + return(solution_new_ptr); +} +/* ---------------------------------------------------------------------- */ +int solution_copy_to_last(int n, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies solution from pointer solution[n]. Makes new structure + * and saves pointer in solution[count_solution]. + */ + /* Make sure solution array is large enough */ + if (count_solution + 1 >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, + sizeof (struct solution *) ); + } + /* malloc space and copy solution */ + solution[count_solution] = solution_copy(solution[n], n_user_new); + count_solution++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solution_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees structure if it does + * Copies structure for solution[n_user_old] to new space + * Saves pointer in old position if it existed, no sort necessary + * Otherwise saves in count_solution position, sort may be necessary + * Solution array is in sort order on exit + */ + int n, n_old, n_new, sort; + struct solution *solution_old_ptr, *solution_new_ptr; +/* + * Find solution n_user_old + */ + if (n_user_old == n_user_new) return(OK); + solution_old_ptr = solution_bsearch(n_user_old, &n_old, TRUE); + if (solution_old_ptr == NULL) { + sprintf(error_string, "Solution %d not found.", n_user_old); + error_msg(error_string, STOP); + } +/* + * Check if solution n_user_new already exists + */ + solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); + if (solution_new_ptr != NULL) { + n = n_new; + solution_free(solution_new_ptr); + sort = FALSE; + } else { + n = count_solution; + count_solution++; + if (n_user_new > solution[n-1]->n_user) { + sort = FALSE; + } else { + sort = TRUE; + } + } + solution[n] = solution_copy(solution_old_ptr, n_user_new); +/* + * Make sure surface array is large enough + */ + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, + sizeof (struct solution *) ); + } +/* + * Sort solution if necessary + */ + if (sort == TRUE) solution_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solution_delete (int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete a solution structure: free memory and renumber solution. + */ + struct solution *solution_ptr; + int j, n; + solution_ptr = solution_bsearch(n_user, &n, FALSE); + if (solution_ptr != NULL) { + solution_free ( solution[n] ); + for (j=n; j < ( count_solution -1 ); j++) { + solution[j]=solution[j+1]; + } + count_solution--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solution_free (struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (solution_ptr == NULL) return(OK); +/* + * Free all memory unique to a solution structure, free solution_ptr too. + */ + solution_ptr->description = (char *) free_check_null (solution_ptr->description); +/* Free struct conc array */ + solution_ptr->totals = (struct conc *) free_check_null (solution_ptr->totals); + solution_ptr->master_activity = (struct master_activity *) free_check_null (solution_ptr->master_activity); + solution_ptr->species_gamma = (struct master_activity *) free_check_null (solution_ptr->species_gamma); + solution_ptr->count_species_gamma = 0; +/* Free struct pe_data array */ + pe_data_free (solution_ptr->pe); +/* Free isotope data */ + solution_ptr->isotopes = (struct isotope *) free_check_null (solution_ptr->isotopes); +/* Free struct solution */ + solution_ptr = (struct solution *) free_check_null (solution_ptr); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees structure if it does + * Copies structure for solution[n_user_old] to new space + * Saves pointer in old position if it existed, no sort necessary + * Otherwise saves in count_solution position, sort may be necessary + * Solution array is in sort order on exit + */ + int n, n_new, sort; + struct solution *solution_new_ptr; +/* + * Find solution n_user_old + */ + if (solution_old_ptr == NULL) { + sprintf(error_string, "Solution pointer is NULL."); + error_msg(error_string, STOP); + } +/* + * Check if solution n_user_new already exists + */ + solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); + if (solution_new_ptr == solution_old_ptr) return(OK); + if (solution_new_ptr != NULL) { + n = n_new; + solution_free(solution_new_ptr); + sort = FALSE; + } else { + n = count_solution; + count_solution++; + /* + * Make sure surface array is large enough + */ + if (count_solution >= max_solution) { + space ((void **) ((void *) &(solution)), count_solution, &max_solution, + sizeof (struct solution *) ); + } + if (n_user_new > solution[n-1]->n_user) { + sort = FALSE; + } else { + sort = TRUE; + } + } + solution[n] = solution_copy(solution_old_ptr, n_user_new); +/* + * Sort solution if necessary + */ + if (sort == TRUE) solution_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct solution *solution_replicate(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + return(solution_copy(solution_old_ptr, n_user_new)); +} +/* ---------------------------------------------------------------------- */ +int solution_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of pointers to solution structures, solution. + */ + if (count_solution > 0) { + qsort (solution, + (size_t) count_solution, + (size_t) sizeof(struct solution *), + solution_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "species_list" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +static int species_list_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int j; + char *name1, *name2; + const struct species_list *nptr1, *nptr2; + + nptr1= (const struct species_list *) ptr1; + nptr2= (const struct species_list *) ptr2; + +/* + * Put H+ first + */ + if (nptr1->master_s != nptr2->master_s) { + if (nptr1->master_s == s_hplus) return (-1); + if (nptr2->master_s == s_hplus) return (1); + } +/* + * Other element valence states + */ + if (nptr1->master_s->secondary != NULL) { + name1 = nptr1->master_s->secondary->elt->name; + } else { + name1 = nptr1->master_s->primary->elt->name; + } + if (nptr2->master_s->secondary != NULL) { + name2 = nptr2->master_s->secondary->elt->name; + } else { + name2 = nptr2->master_s->primary->elt->name; + } +/* + * Compare name of primary or secondary master species; log molality + */ + + j = strcmp( name1, name2 ); + +/* + * Different master species + */ + if (j != 0 ) return(j); + +/* + * Else, descending order by log molality + */ + if ( nptr1->s->lm > nptr2->s->lm) { + return (-1); + } else if ( nptr1->s->lm < nptr2->s->lm) { + return (1); + } else { + return (0); + } +} +/* ---------------------------------------------------------------------- */ +int species_list_compare_alk (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct species_list *nptr1, *nptr2; + double alk1, alk2; + + nptr1= (const struct species_list *) ptr1; + nptr2= (const struct species_list *) ptr2; +/* + * Else, descending order by log molality + */ + alk1 = fabs(under(nptr1->s->lm)*nptr1->s->alk); + alk2 = fabs(under(nptr2->s->lm)*nptr2->s->alk); + + if ( alk1 > alk2) { + return (-1); + } else if ( alk1 < alk2) { + return (1); + } else { + return (0); + } +} +/* ---------------------------------------------------------------------- */ +int species_list_compare_master (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + char *name1, *name2; + const struct species_list *nptr1, *nptr2; + + nptr1= (const struct species_list *) ptr1; + nptr2= (const struct species_list *) ptr2; + +/* + * Put H+ first + */ + if (nptr1->master_s != nptr2->master_s) { + if (nptr1->master_s == s_hplus) return (-1); + if (nptr2->master_s == s_hplus) return (1); + } +/* + * Other element valence states + */ + if (nptr1->master_s->secondary != NULL) { + name1 = nptr1->master_s->secondary->elt->name; + } else { + name1 = nptr1->master_s->primary->elt->name; + } + if (nptr2->master_s->secondary != NULL) { + name2 = nptr2->master_s->secondary->elt->name; + } else { + name2 = nptr2->master_s->primary->elt->name; + } +/* + * Compare name of primary or secondary master species; log molality + */ + + return(strcmp( name1, name2 )); +} +/* ---------------------------------------------------------------------- */ +int species_list_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort list using rules in species_list_compare + */ + if (count_species_list > 0) { + qsort (&species_list[0], (size_t) count_species_list, + (size_t) sizeof(struct species_list), species_list_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "surface" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct surface *surface_alloc (void) +/* ---------------------------------------------------------------------- */ +{ + struct surface *surface_ptr; + surface_ptr = (struct surface *) PHRQ_malloc(sizeof (struct surface)); + if (surface_ptr == NULL) malloc_error(); + surface_ptr->description = NULL; + surface_ptr->count_comps = 0; + surface_ptr->comps = NULL; + surface_ptr->count_charge = 0; + surface_ptr->charge = NULL; + return ( surface_ptr ); +} +/* ---------------------------------------------------------------------- */ +struct surface *surface_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array surface to find user number k. + * Assumes array surface is in sort order. + * + * Input: k, user number to find. + * Output: n, position in array surface of user number k. + * Return: pointer to surface structure if found, + * NULL if not found. + */ + void *void_ptr; + if (count_surface == 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) surface, + (size_t) count_surface, + (size_t) sizeof(struct surface), + surface_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct surface *) void_ptr - surface); + return ( (struct surface *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int surface_comp_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct surface_comp *surface_comp_ptr1, *surface_comp_ptr2; + surface_comp_ptr1 = (const struct surface_comp *) ptr1; + surface_comp_ptr2 = (const struct surface_comp *) ptr2; + return(strcmp_nocase(surface_comp_ptr1->master->elt->name, surface_comp_ptr2->master->elt->name)); +} +/* ---------------------------------------------------------------------- */ +int surface_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct surface *surface_ptr1, *surface_ptr2; + surface_ptr1 = (const struct surface *) ptr1; + surface_ptr2 = (const struct surface *) ptr2; + if (surface_ptr1->n_user > surface_ptr2->n_user) return(1); + if (surface_ptr1->n_user < surface_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int surface_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare surface user numbers to integer + */ + const int *nptr1; + const struct surface *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct surface *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies data from surface_old_ptr to surface_new_ptr. + * Space for a surface structure must already be malloced. + * User number of new surface structure is n_user. + */ + int count_comps, count_charge, i; + char token[MAX_LENGTH]; +/* + * Store data for structure surface + */ + memcpy(surface_new_ptr, surface_old_ptr, sizeof(struct surface)); + count_comps = surface_old_ptr->count_comps; + count_charge = surface_old_ptr->count_charge; + surface_new_ptr->n_user = n_user_new; + surface_new_ptr->n_user_end = n_user_new; + surface_new_ptr->new_def = surface_old_ptr->new_def; + sprintf(token, "Surface defined in simulation %d.", simulation); + surface_new_ptr->description = string_duplicate(token); + surface_new_ptr->solution_equilibria = FALSE; + surface_new_ptr->n_solution = -10; +/* + * Write surface_comp structure for each surface component + */ + surface_new_ptr->comps = (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct surface_comp)); + if (surface_new_ptr->comps == NULL) malloc_error(); + memcpy(surface_new_ptr->comps, surface_old_ptr->comps, + (size_t) (count_comps) * sizeof (struct surface_comp)); + for ( i = 0; i < count_comps; i++) { + surface_new_ptr->comps[i].totals = elt_list_dup(surface_old_ptr->comps[i].totals); + } +/* + * Write surface_charge structure for each surface + */ + if (surface_old_ptr->edl == TRUE) { + surface_new_ptr->charge = (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * sizeof (struct surface_charge)); + if (surface_new_ptr->charge == NULL) malloc_error(); + memcpy(surface_new_ptr->charge, surface_old_ptr->charge, + (size_t) (count_charge) * sizeof (struct surface_charge)); + for ( i = 0; i < count_charge; i++) { + surface_new_ptr->charge[i].diffuse_layer_totals = elt_list_dup(surface_old_ptr->charge[i].diffuse_layer_totals); + surface_new_ptr->charge[i].g = NULL; + } + } else { + surface_new_ptr->charge = NULL; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an surface definition to position count_surface. + */ + space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); + surface_copy(&surface[n], &surface[count_surface], n_user); + count_surface++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies surface[n_user_old] to old n_user_new space if + * found or to surface[count_surface] if not found. + * Surface array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct surface *surface_ptr_old, *surface_ptr_new; +/* + * Find n_user_old in structure array surface + */ + if (n_user_old == n_user_new) return(OK); + surface_ptr_old = surface_bsearch(n_user_old, &n_old); + if (surface_ptr_old == NULL) { + sprintf(error_string, "Surface %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array surface or make new space + */ + sort = FALSE; + surface_ptr_new = surface_bsearch(n_user_new, &n_new); + if (surface_ptr_new != NULL) { + surface_free(surface_ptr_new); + } else { + space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); + if (n_user_new < surface[count_surface-1].n_user) sort = TRUE; + n_new = count_surface++; + } +/* + * Copy data + */ + surface_copy(&surface[n_old], &surface[n_new], n_user_new); + if (sort == TRUE) surface_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array surface. + */ +{ + int i; + int n_old; + struct surface *surface_ptr_old; +/* + * Find n_user_old in structure array + */ + surface_ptr_old = surface_bsearch(n_user_old, &n_old); + if (surface_ptr_old != NULL) { + /* + * Delete surface + */ + surface_free(&surface[n_old]); + + for(i = n_old + 1; i < count_surface; i++) { + memcpy( (void *) &surface[i - 1], (void *) &surface[i], + (size_t) sizeof (struct surface) ); + } + count_surface--; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_free(struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all space related to surface_ptr, but not surface_ptr. + */ + int k; + + if (surface_ptr == NULL) return(ERROR); + surface_ptr->description = (char *) free_check_null(surface_ptr->description); +/* + * totals, then comps + */ + for (k = 0; k < surface_ptr->count_comps; k++) { + surface_ptr->comps[k].totals = (struct elt_list *) free_check_null(surface_ptr->comps[k].totals); + } + surface_ptr->comps = (struct surface_comp *) free_check_null (surface_ptr->comps); +/* + * diffuse_layer_totals and g, then charge + */ + if (surface_ptr->edl == TRUE) { + for (k = 0; k < surface_ptr->count_charge; k++) { + surface_ptr->charge[k].diffuse_layer_totals = (struct elt_list *) free_check_null(surface_ptr->charge[k].diffuse_layer_totals); + surface_ptr->charge[k].g = (struct surface_diff_layer *) free_check_null(surface_ptr->charge[k].g); + } + } + surface_ptr->charge = (struct surface_charge *) free_check_null (surface_ptr->charge); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ + + if (surface_ptr == NULL) return(ERROR); + + surface_ptr->n_user = n_user; + surface_ptr->n_user_end = n_user_end; + surface_ptr->description = string_duplicate(description); + surface_ptr->new_def = TRUE; + surface_ptr->diffuse_layer = FALSE; + surface_ptr->edl = TRUE; + surface_ptr->only_counter_ions = FALSE; + surface_ptr->donnan = FALSE; + surface_ptr->debye_units = 0.0; + surface_ptr->transport = FALSE; + surface_ptr->thickness = 1e-8; + surface_ptr->solution_equilibria = FALSE; + surface_ptr->n_solution = -999; +/* + * Malloc one surface_comp structure + */ + surface_ptr->count_comps = 0; + surface_ptr->comps = (struct surface_comp *) PHRQ_malloc( (size_t) sizeof (struct surface_comp)); + if (surface_ptr->comps == NULL) malloc_error(); + surface_ptr->comps[0].master = NULL; + surface_ptr->comps[0].totals = NULL; + surface_ptr->comps[0].phase_name = NULL; + surface_ptr->comps[0].rate_name = NULL; + surface_ptr->comps[0].charge = -1; + surface_ptr->comps[0].moles = 0; + surface_ptr->comps[0].cb = 0; +/* + * Malloc one charge structure + */ + surface_ptr->count_charge = 0; + surface_ptr->charge = (struct surface_charge *) PHRQ_malloc( (size_t) sizeof (struct surface_charge)); + if (surface_ptr->charge == NULL) malloc_error(); + + surface_ptr->related_phases = FALSE; + surface_ptr->related_rate = FALSE; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies surface_ptr_old to old n_user_new space if + * found or to surface[count_surface] if not found. + * Surface array may not be in sort order after the copy. + */ + int n_new, sort; + struct surface *surface_ptr_new; +/* + * Find n_user_old in structure array surface + */ + if (surface_ptr_old == NULL) { + sprintf(error_string, "Surface pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_new in structure array surface or make new space + */ + sort = FALSE; + surface_ptr_new = surface_bsearch(n_user_new, &n_new); + if (surface_ptr_new == surface_ptr_old) return(OK); + if (surface_ptr_new != NULL) { + surface_free(surface_ptr_new); + } else { + space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); + if (n_user_new < surface[count_surface-1].n_user) sort = TRUE; + n_new = count_surface++; + } +/* + * Copy data + */ + surface_copy(surface_ptr_old, &surface[n_new], n_user_new); + if (sort == TRUE) surface_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct surface *surface_replicate(struct surface *surface_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct surface *surface_ptr; + surface_ptr = surface_alloc(); + surface_copy(surface_old_ptr, surface_ptr, n_user_new); + return (surface_ptr); +} +/* ---------------------------------------------------------------------- */ +struct surface *surface_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "surface" for user number n_user. + * + * Arguments: + * n_user input, user number. + * n output, position in surface. + * + * Returns: + * if found, pointer to surface structure + * if not found, NULL + */ + int i; + for (i = 0; i < count_surface; i++) { + if (n_user == surface[i].n_user) { + break; + } + } + if (i >= count_surface) { + if ( print == TRUE) { + sprintf(error_string, "Surface %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return(NULL); + } + *n = i; + return(&surface[i]); +} +/* ---------------------------------------------------------------------- */ +int surface_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of surface structures + */ + if (count_surface > 0) { + qsort (surface, (size_t) count_surface, (size_t) sizeof(struct surface), + surface_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "temperature" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct temperature *temperature_bsearch (int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array temperature to find user number k. + * Assumes array temperature is in sort order. + * + * Input: k, user number to find. + * Output: n, position in array temperature of user number k. + * Return: pointer to temperature structure if found, + * NULL if not found. + */ + void *void_ptr; + if (count_temperature <= 0) { + *n = -999; + return(NULL); + } + void_ptr = (void *) + bsearch ( (char *) &k, + (char *) temperature, + (size_t) count_temperature, + (size_t) sizeof(struct temperature), + temperature_compare_int); + if (void_ptr == NULL) { + *n = -999; + return(NULL); + } + *n = (int) ((struct temperature *) void_ptr - temperature); + return ( (struct temperature *) void_ptr); +} +/* ---------------------------------------------------------------------- */ +int temperature_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct temperature *temperature_ptr1, *temperature_ptr2; + temperature_ptr1 = (const struct temperature *) ptr1; + temperature_ptr2 = (const struct temperature *) ptr2; + if (temperature_ptr1->n_user > temperature_ptr2->n_user) return(1); + if (temperature_ptr1->n_user < temperature_ptr2->n_user) return(-1); + return (0); + +} +/* ---------------------------------------------------------------------- */ +static int temperature_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare temperature user numbers + */ + const int *nptr1; + const struct temperature *nptr2; + + nptr1= (const int *) ptr1; + nptr2= (const struct temperature *) ptr2; + if (*nptr1 > nptr2->n_user) return(1); + if (*nptr1 < nptr2->n_user) return(-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies temperature data from temperature_old_ptr to new location, temperature_new_ptr. + * Space for the temperature_new_ptr structure must already be malloced. + * Space for temperature components is malloced here. + */ + int count; + char token[MAX_LENGTH]; +/* + * Copy old to new + */ + memcpy(temperature_new_ptr, temperature_old_ptr, sizeof (struct temperature)); +/* + * Store data for structure temperature + */ + temperature_new_ptr->n_user = n_user_new; + temperature_new_ptr->n_user_end = n_user_new; + sprintf(token, "Temperature defined in simulation %d.", simulation); + temperature_new_ptr->description = string_duplicate(token); +/* + * Count temperature components and allocate space + */ + if (temperature_old_ptr->count_t < 0) { + count = 2; + } else { + count = temperature_old_ptr->count_t; + } + temperature_new_ptr->t = (double *) PHRQ_malloc((size_t) (count) * sizeof (double)); + if (temperature_new_ptr->t == NULL) malloc_error(); + memcpy(temperature_new_ptr->t, temperature_old_ptr->t, + (size_t) (count * sizeof (double))); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int temperature_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies temperature[n_user_old] to old n_user_new space if + * found or to temperature[count_temperature] if not found. + * Temperature array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + char token[MAX_LENGTH]; + int count_t; + struct temperature *temperature_ptr_old, *temperature_ptr_new; +/* + * Find n_user_old in structure array temperature or make new space + */ + if (n_user_old == n_user_new) return(OK); + temperature_ptr_old = temperature_bsearch(n_user_old, &n_old); + if (temperature_ptr_old == NULL) { + sprintf(error_string, "Temperature %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return(ERROR); + } +/* + * Find n_user_old in structure array temperature or make new space + */ + sort = FALSE; + temperature_ptr_new = temperature_bsearch(n_user_new, &n_new); + if (temperature_ptr_new != NULL) { + temperature_free(&temperature[n_new]); + } else { + temperature = (struct temperature *) PHRQ_realloc( temperature, + (size_t) (count_temperature + 1) * + sizeof (struct temperature)); + if (temperature == NULL) malloc_error(); + if (n_user_new < temperature[count_temperature-1].n_user) sort = TRUE; + n_new = count_temperature++; + } +/* + * Store data for structure temperature + */ + count_t = temperature[n_old].count_t; + temperature[n_new].n_user = n_user_new; + temperature[n_new].n_user_end = n_user_new; + sprintf(token, "Temperature defined in simulation %d.", simulation); + temperature[n_new].description = string_duplicate(token); + temperature[n_new].count_t = count_t; + if (count_t < 0) count_t = 2; +/* + * Count temperature components and allocate space + */ + temperature[n_new].t = (LDBLE *) PHRQ_malloc((size_t) (count_t) * + sizeof (LDBLE)); + if (temperature[n_new].t == NULL) malloc_error(); +/* + * Write temperature_comp structure for each temperature component + */ + memcpy(temperature[n_new].t, temperature[n_old].t, + (size_t) (count_t) * sizeof (LDBLE)); + if (sort == TRUE) temperature_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int temperature_free (struct temperature *temperature_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for temperature structure, does not free temperature_ptr. + */ + if (temperature_ptr == NULL) return(ERROR); + + temperature_ptr->description = (char *) free_check_null (temperature_ptr->description); + temperature_ptr->t = (LDBLE *) free_check_null (temperature_ptr->t); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct temperature *temperature_search(int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "temperature" for user number n_user. + * + * Arguments: + * n_user input, user number. + * n output, position in temperature. + * + * Returns: + * if found, pointer to temperature structure + * if not found, NULL + */ + int i; + for (i = 0; i < count_temperature; i++) { + if (n_user == temperature[i].n_user) { + break; + } + } + if (i >= count_temperature) { + *n = -999; + return(NULL); + } + *n = i; + return(&temperature[i]); +} +/* ---------------------------------------------------------------------- */ +int temperature_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of temperature structures + */ + if (count_temperature > 0) { + qsort (temperature, (size_t) count_temperature, (size_t) sizeof(struct temperature), temperature_compare); + } + return(OK); +} +/* ********************************************************************** + * + * Routines related to structure "trxn" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int rxn_token_temp_compare (const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct rxn_token_temp *rxn_token_temp_ptr1, *rxn_token_temp_ptr2; + rxn_token_temp_ptr1 = (const struct rxn_token_temp *) ptr1; + rxn_token_temp_ptr2 = (const struct rxn_token_temp *) ptr2; + return(strcmp(rxn_token_temp_ptr1->name, rxn_token_temp_ptr2->name)); +} +/* ---------------------------------------------------------------------- */ +int trxn_add (struct reaction *r_ptr, LDBLE coef, int combine) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds reactions together. + * + * Global variable count_trxn determines which position in trxn is used. + * If count_trxn=0, then the equation effectively is copied into trxn. + * If count_trxn>0, then new equation is added to existing equation. + * + * Arguments: + * *r_ptr points to rxn structure to add. + * + * coef added equation is multiplied by coef. + * combine if TRUE, reaction is reaction is sorted and + * like terms combined. + */ + int i; + struct rxn_token *next_token; +/* + * Accumulate log k for reaction + */ + if (count_trxn == 0) { + memcpy( (void *) trxn.logk, (void *) r_ptr->logk, + (size_t) 7 * sizeof(LDBLE) ); + } else { + for (i=0; i < 7; i++) { + trxn.logk[i] += coef * (r_ptr->logk[i]); + } + } +/* + * Copy equation into work space + */ + next_token = r_ptr->token; + while (next_token->s != NULL) { + if (count_trxn + 1 >= max_trxn) { + space ((void **) &(trxn.token), count_trxn+1, &max_trxn, + sizeof(struct rxn_token_temp)); + } + trxn.token[count_trxn].name = next_token->s->name; + trxn.token[count_trxn].s = next_token->s; + trxn.token[count_trxn].coef = coef*next_token->coef; + count_trxn++; + next_token++; + } + if (combine == TRUE) trxn_combine(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int trxn_combine (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Combines coefficients of tokens that are equal in temporary + * reaction structure, trxn. + */ + int j, k; +/* + * Sort trxn species + */ + trxn_sort(); +/* + * Combine trxn tokens + */ + j=1; + for ( k=2; k < count_trxn; k++) { + if ( ( j > 0 ) && ( trxn.token[k].s == trxn.token[j].s) ) { + trxn.token[j].coef += trxn.token[k].coef; + if (equal(trxn.token[j].coef, 0.0, 1e-5)) j--; + } else { + j++; + if ( k != j ) { + trxn.token[j].name = trxn.token[k].name; + trxn.token[j].s = trxn.token[k].s; + trxn.token[j].coef = trxn.token[k].coef; + } + } + } + count_trxn=j+1; /* number excluding final NULL */ + return(OK); +} +/* ---------------------------------------------------------------------- */ +int trxn_copy (struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies trxn to a reaction structure. + * + * Input: rxn_ptr, pointer to reaction structure to copy trxn to. + * + */ + int i; +/* + * Copy logk data + */ + for (i=0; i<7; i++) { + rxn_ptr->logk[i]=trxn.logk[i]; + } +/* + * Copy tokens + */ + for (i=0; i < count_trxn; i++ ) { + rxn_ptr->token[i].s = trxn.token[i].s; + rxn_ptr->token[i].coef = trxn.token[i].coef; + } + rxn_ptr->token[count_trxn].s=NULL; + + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE trxn_find_coef(const char *str, int start) +/* ---------------------------------------------------------------------- */ +{ +/* + * Finds coefficient of specified token in trxn. + * Input: str, token name in reaction. + * + * Return: 0.0, if token not found. + * coefficient of token, if token found. + */ + int i; + LDBLE coef; + + coef=0.0; + for (i=start; iname, str) == 0) { + coef=trxn.token[i].coef; + break; + } + } + return(coef); +} +/* ---------------------------------------------------------------------- */ +int trxn_multiply (LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Multiplies temporary reaction, trxn, by a constant + * + * Arguments: + * input: coef multiplier. + */ + int i; +/* + * Multiply log k for reaction + */ + for (i=0; i < 7; i++) { + trxn.logk[i] *= coef; + } +/* + * Multiply coefficients of reaction + */ + for (i=0; i < count_trxn; i++ ){ + trxn.token[i].coef *= coef; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int trxn_print (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints trxn + */ + int i; +/* + * Print log k for reaction + */ + + output_msg(OUTPUT_MESSAGE,"log k data:\n"); + for (i=0; i < 7; i++) { + output_msg(OUTPUT_MESSAGE,"\t%f",(double) trxn.logk[i]); + } + output_msg(OUTPUT_MESSAGE,"\n"); + +/* + * Print stoichiometry + */ + for (i=0; i 0) { + qsort(&trxn.token[1], + (size_t) count_trxn-1, + (size_t) sizeof(struct rxn_token_temp), + rxn_token_temp_compare); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int trxn_swap (const char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Moves specified token to initial position in reaction. + * Input: token, token name to move to initial position. + * + * Return: ERROR, if token not found. + * OK, if token moved to initial position. + */ + int i, j; + LDBLE coef; +/* + * Locate token + */ + for (j=0; j < count_trxn; j++) { + if (strcmp(trxn.token[j].s->name,token) == 0 ) break; + } + if (j >= count_trxn ) { + input_error++; + sprintf(error_string,"Could not find token in equation, %s.", token); + error_msg(error_string, CONTINUE); + for (i=0; itype = 0; + unknown_ptr->moles = 0.0; + unknown_ptr->ln_moles = 0.0; + unknown_ptr->f = 0.0; + unknown_ptr->sum = 0.0; + unknown_ptr->delta = 0.0; + unknown_ptr->la = 0.0; + unknown_ptr->number = 0; + unknown_ptr->description=NULL; + unknown_ptr->master = NULL; + unknown_ptr->phase = NULL; + unknown_ptr->si = 0.0; + unknown_ptr->gas_phase=NULL; + unknown_ptr->total=NULL; + unknown_ptr->s=NULL; + unknown_ptr->exch_comp = NULL; + unknown_ptr->pure_phase = NULL; + unknown_ptr->s_s = NULL; + unknown_ptr->s_s_comp = NULL; + unknown_ptr->s_s_comp_number = 0; + unknown_ptr->s_s_in = FALSE; + unknown_ptr->surface_comp = NULL; + unknown_ptr->related_moles = 0.0; + unknown_ptr->potential_unknown = NULL; + unknown_ptr->phase_unknown = NULL; + unknown_ptr->surface_charge = NULL; + unknown_ptr->mass_water = 0.0; + unknown_ptr->dissolve_only = FALSE; + + return(unknown_ptr); +} +/* ---------------------------------------------------------------------- */ +int unknown_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete unknow from list x + */ + int j; + + unknown_free(x[i]); + for (j=i; j < (count_unknowns); j++) { + x[j] = x[j+1]; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int unknown_free(struct unknown *unknown_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space allocated to an unknown structure, frees unknown_ptr. + */ + if (unknown_ptr == NULL) return(ERROR); + unknown_ptr->master = (struct master **) free_check_null (unknown_ptr->master); + unknown_ptr = (struct unknown *) free_check_null (unknown_ptr); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int system_duplicate (int i, int save_old) +/* ---------------------------------------------------------------------- */ +{ + int n; + + if (solution_bsearch(i,&n, TRUE) != NULL) solution_duplicate(i, save_old); + if (pp_assemblage_bsearch(i,&n) != NULL) pp_assemblage_duplicate(i, save_old); + if (exchange_bsearch(i,&n) != NULL) exchange_duplicate(i, save_old); + if (surface_bsearch(i,&n) != NULL) surface_duplicate(i, save_old); + if (gas_phase_bsearch(i,&n) != NULL) gas_phase_duplicate(i, save_old); + if (kinetics_bsearch(i,&n) != NULL) kinetics_duplicate(i, save_old); + if (s_s_assemblage_bsearch(i,&n) != NULL) s_s_assemblage_duplicate(i, save_old); + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct logk *logk_store (char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for logk. + * + * Pointer to a logk structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old logk structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old logk structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "logk". + * replace_if_found input, TRUE means reinitialize logk structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to logk structure "logk" where "name" can be found. + */ + int n; + struct logk *logk_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + str_tolower(name); + item.key = name; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) { + logk_ptr = (struct logk *) (found_item->data); + return (logk_ptr); + } else if (found_item != NULL && replace_if_found == TRUE) { + logk_ptr = (struct logk *) (found_item->data); + logk_init(logk_ptr); + } else { + n = count_logk++; + /* make sure there is space in s */ + if (count_logk >= max_logk) { + space ((void **) ((void *) &logk), count_logk, &max_logk, sizeof(struct logk *)); + } + /* Make new logk structure */ + logk[n] = logk_alloc(); + logk_ptr = logk[n]; + } + /* set name and z in pointer in logk structure */ + logk_ptr->name = string_hsave( name ); +/* + * Update hash table + */ + item.key = logk_ptr->name; + item.data = (void *) logk_ptr; + found_item = hsearch_multi(logk_hash_table, item, ENTER); + if (found_item == NULL) { + sprintf(error_string, "Hash table error in logk_store."); + error_msg(error_string, CONTINUE); + } + + return (logk_ptr); +} +/* ---------------------------------------------------------------------- */ +struct logk *logk_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a logk structure, initializes + * arguments: void + * return: pointer to a logk structure + */ +{ + struct logk *logk_ptr; + logk_ptr=(struct logk *) PHRQ_malloc(sizeof(struct logk)); + if (logk_ptr == NULL) malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + logk_init(logk_ptr); + + return(logk_ptr); +} +/* ---------------------------------------------------------------------- */ +static int logk_init(struct logk *logk_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a logk structure + */ +{ + int i; +/* + * set pointers in structure to NULL + */ + logk_ptr->name=NULL; +/* + * set varibles = 0 + */ + logk_ptr->lk = 0.0; + for (i =0; i < 8; i++) { + logk_ptr->log_k[i] = 0.0; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +struct logk *logk_search (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for logk. + * + * Arguments: + * name input, character string to be found in "logk". + * + * Returns: + * pointer to logk structure "logk" where "name" can be found. + * or NULL if not found. + */ + struct logk *logk_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + str_tolower(name); + item.key = name; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + + if (found_item != NULL) { + logk_ptr = (struct logk *) (found_item->data); + return (logk_ptr); + } + return(NULL); +} +/* ---------------------------------------------------------------------- */ +int entity_exists (char *name, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, 0 Solution + * reaction, 1 Reaction + * exchange, 2 Exchange + * surface, 3 Surface + * gas_phase, 4 Gas_phase + * equilibrium_phases, 5 Pure_phase + * solid_solution, 6 Ss_phase + * kinetics, 7 Kinetics + * mix, 8 Mix + * reaction_temperature 9 Temperature + * unknown 10 UnKnown + */ + int i, return_value; + char *ptr; + char token[MAX_LENGTH]; + enum entity_type type; +/* + * Read keyword + */ + ptr = name; + copy_token (token, &ptr, &i); + type = get_entity_enum(token); + return_value = TRUE; + switch (type) { + case UnKnown: + warning_msg("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); + return_value = 2; + break; + case Solution: /* Solution */ + if (solution_bsearch (n_user, &i, FALSE) == NULL) { + return_value = FALSE; + } + break; + case Pure_phase: /* Pure phases */ + if(pp_assemblage_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Reaction: /* Reaction */ + if(irrev_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Mix: /* Mix */ + if(mix_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Exchange: /* Ex */ + if(exchange_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Surface: /* Surface */ + if(surface_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Temperature: /* Temperature */ + if(temperature_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Gas_phase: /* Gas */ + if(gas_phase_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Kinetics: /* Kinetics */ + if(kinetics_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + case Ss_phase: /* solid_solutions */ + if(s_s_assemblage_bsearch (n_user, &i) == NULL) { + return_value = FALSE; + } + break; + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +enum entity_type get_entity_enum (char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, 0 Solution + * reaction, 1 Reaction + * exchange, 2 Exchange + * surface, 3 Surface + * gas_phase, 4 Gas_phase + * equilibrium_phases, 5 Pure_phase + * solid_solution, 6 Ss_phase + * kinetics, 7 Kinetics + * mix, 8 Mix + * reaction_temperature 9 Temperature + * unknown 10 UnKnown + * + */ + int i; + char *ptr; + char token[MAX_LENGTH]; +/* + * Read keyword + */ + ptr = name; + copy_token (token, &ptr, &i); + check_key (token); + switch (next_keyword) { + case -1: /* Have not read line with keyword */ + case 0: /* End encountered */ + case 1: /* EOF encountered */ + case 2: /* Read aqueous model */ + case 3: /* Read master species */ + case 5: + case 9: + case 10: + case 11: + case 12: + case 14: + case 15: + case 18: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 30: + case 31: + case 32: + case 34: + case 35: + case 38: + case 39: + warning_msg("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); + return(UnKnown); + break; + case 4: /* Solution */ + return(Solution); + break; + case 6: /* Pure phases */ + case 26: + case 27: + case 28: + case 29: + return(Pure_phase); + break; + case 7: /* Reaction */ + return(Reaction); + break; + case 8: /* Mix */ + return(Mix); + break; + case 13: /* Ex */ + return(Exchange); + break; + case 16: /* Surface */ + return(Surface); + break; + case 17: /* Temperature */ + return(Temperature); + break; + case 19: /* Gas */ + return(Gas_phase); + break; + case 33: /* Kinetics */ + return(Kinetics); + break; + case 40: /* solid_solutions */ + case 41: /* solid_solution */ + return(Ss_phase); + break; + } + return(UnKnown); +} +/* + * copier routines + */ +/* ---------------------------------------------------------------------- */ +int copier_add(struct copier *copier_ptr, int n_user, int start, int end) +/* ---------------------------------------------------------------------- */ +/* + * add new set of copy instructions + */ +{ + + if (copier_ptr->count >= copier_ptr->max) { + copier_ptr->max = copier_ptr->count*2; + copier_ptr->n_user = (int *) PHRQ_realloc(copier_ptr->n_user, (size_t) (copier_ptr->max*sizeof(int))); + if (copier_ptr->n_user == NULL) malloc_error(); + copier_ptr->start = (int *) PHRQ_realloc(copier_ptr->start, (size_t) (copier_ptr->max*sizeof(int))); + if (copier_ptr->start == NULL) malloc_error(); + copier_ptr->end = (int *) PHRQ_realloc(copier_ptr->end, (size_t) (copier_ptr->max*sizeof(int))); + if (copier_ptr->end == NULL) malloc_error(); + } + copier_ptr->n_user[copier_ptr->count] = n_user; + copier_ptr->start[copier_ptr->count] = start; + copier_ptr->end[copier_ptr->count] = end; + copier_ptr->count++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int copier_free(struct copier *copier_ptr) +/* ---------------------------------------------------------------------- */ +/* + * initialize copier structure + */ +{ + + copier_ptr->n_user = (int *) free_check_null(copier_ptr->n_user); + copier_ptr->start = (int *) free_check_null(copier_ptr->start); + copier_ptr->end = (int *) free_check_null(copier_ptr->end); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int copier_init(struct copier *copier_ptr) +/* ---------------------------------------------------------------------- */ +/* + * initialize copier structure + */ +{ + + copier_ptr->count = 0; + copier_ptr->max = 10; + copier_ptr->n_user = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); + copier_ptr->start = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); + copier_ptr->end = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); + return(OK); +} diff --git a/sundialsmath.cpp b/sundialsmath.cpp new file mode 100644 index 00000000..2ec5ee28 --- /dev/null +++ b/sundialsmath.cpp @@ -0,0 +1,76 @@ +/******************************************************************* + * * + * File : sundialsmath.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a C math library. * + * * + *******************************************************************/ + + +#include +#include +#include "sundialsmath.h" +#include "sundialstypes.h" +#include "output.h" + +static char const svnid[] = "$Id: sundialsmath.c 78 2005-02-01 22:47:12Z dlpark $"; + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) +#define TWO RCONST(2.0) + + +realtype UnitRoundoff(void) +{ + realtype u; + volatile realtype one_plus_u; + + u = ONE; + one_plus_u = ONE + u; + while (one_plus_u != ONE) { + u /= TWO; + one_plus_u = ONE + u; + } + u *= TWO; + + return(u); +} + + +realtype RPowerI(realtype base, int exponent) +{ + int i, expt; + realtype prod; + + prod = ONE; + expt = ABS(exponent); + for(i=1; i <= expt; i++) prod *= base; + if (exponent < 0) prod = ONE/prod; + return(prod); +} + + +realtype RPowerR(realtype base, realtype exponent) +{ + + if (base <= ZERO) return(ZERO); + + /* return((realtype)pow((double)base,(double)exponent));*/ + return((realtype)pow(base,exponent)); +} + + +realtype RSqrt(realtype x) +{ + if (x <= ZERO) return(ZERO); + + /* return((realtype) sqrt((double) x));*/ + return((realtype) sqrt( x)); +} diff --git a/sundialsmath.h b/sundialsmath.h new file mode 100644 index 00000000..6c29aa28 --- /dev/null +++ b/sundialsmath.h @@ -0,0 +1,130 @@ +/******************************************************************* + * * + * File : sundialsmath.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a C math library. The routines * + * listed here work with the type realtype as defined in * + * sundialstypes.h. * + * To do single precision floating point arithmetic, set the type * + * realtype to be float. To do double precision arithmetic, set * + * the type realtype to be double. The default implementations * + * for RPowerR and RSqrt call standard math library functions * + * which do double precision arithmetic. If this is unacceptable * + * when realtype is float, then the user should re-implement * + * these two routines by calling single precision routines * + * available on his/her machine. * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidsundialsmath[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef _sundialsmath_h +#define _sundialsmath_h + +#include "sundialstypes.h" + + +/****************************************************************** + * * + * Macros : MIN, MAX, ABS, SQR * + *----------------------------------------------------------------* + * MIN(A, B) returns the minimum of A and B. * + * * + * MAX(A, B) returns the maximum of A and B. * + * * + * ABS(A) returns the absolute value of A. * + * * + * SQR(A) returns the square of A. * + * * + ******************************************************************/ +#ifndef MIN +#define MIN(A, B) ((A) < (B) ? (A) : (B)) +#endif + +#ifndef MAX +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#endif + +#ifndef ABS +#define ABS(A) ((A < 0) ? -(A) : (A)) +#endif + +#ifndef SQR +#define SQR(A) ((A) * (A)) +#endif + +/****************************************************************** + * * + * Function : UnitRoundoff * + * Usage : realtype uround; * + * uround = UnitRoundoff(); * + *----------------------------------------------------------------* + * UnitRoundoff returns the unit roundoff u for real floating * + * point arithmetic, where u is defined to be the smallest * + * positive real such that 1.0 + u != 1.0. * + * * + ******************************************************************/ + +realtype UnitRoundoff(void); + + +/****************************************************************** + * * + * Function : RPowerI * + * Usage : int exponent; * + * realtype base, ans; * + * ans = RPowerI(base,exponent); * + *----------------------------------------------------------------* + * RPowerI returns the value base^exponent, where base is a * + * realtype and exponent is an int. * + * * + ******************************************************************/ + +realtype RPowerI(realtype base, int exponent); + + +/****************************************************************** + * * + * Function : RPowerR * + * Usage : realtype base, exponent, ans; * + * ans = RPowerR(base,exponent); * + *----------------------------------------------------------------* + * RPowerR returns the value base^exponent, where both base and * + * exponent are realtype. If base < 0.0, then RPowerR returns 0.0 * + * * + ******************************************************************/ + +realtype RPowerR(realtype base, realtype exponent); + + +/****************************************************************** + * * + * Function : RSqrt * + * Usage : realtype sqrt_x; * + * sqrt_x = RSqrt(x); * + *----------------------------------------------------------------* + * RSqrt(x) returns the square root of x. If x < 0.0, then RSqrt * + * returns 0.0. * + * * + ******************************************************************/ + +realtype RSqrt(realtype x); + + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/sundialstypes.h b/sundialstypes.h new file mode 100644 index 00000000..a81ed34d --- /dev/null +++ b/sundialstypes.h @@ -0,0 +1,144 @@ +#include "phrqtype.h" +/******************************************************************* + * * + * File : sundialstypes.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This header file exports three types: realtype, integertype, * + * and booleantype, as well as the constants TRUE and FALSE. * + * * + * Users should #include "sundialstypes.h" in any file that * + * shhould be easily modifiable to work with different real or * + * integer types and use the exported names realtype and * + * integertype within such a file. * + * The types for realtype and integertype below have been set to * + * double and long int, respectively. A user should modify these * + * type declarations as he/she sees fit. For example, if a user * + * wants the work with type float because double precision * + * floating point arithmetic is too expensive on the user's * + * machine, then the definition below should be changed to: * + * * + * typedef float realtype; * + * * + * Similarly, if a user does not need to work with extremely large * + * integers (see the system header file for the limits * + * on type int and long int on your machine), then the user * + * should change the definition below to: * + * * + * typedef int integertype; * + * * + * The constants SUNDIALS_FLOAT, SUNDIALS_DOUBLE, SUNDIALS_INT, * + * SUNDIALS_LONG indicate the underlying types for realtype and * + * integertype. They should be set as follows: * + * * + * (1) #define SUNDIALS_FLOAT 1 * + * #define SUNDIALS_DOUBLE 0 (real is float) * + * * + * (2) #define SUNDIALS_FLOAT 0 * + * #define SUNDIALS_DOUBLE 1 (real is double) * + * * + * (3) #define SUNDIALS_INT 1 * + * #define SUNDIALS_LONG 0 (integer is int) * + * * + * (4) #define SUNDIALS_INT 0 * + * #define SUNDIALS_LONG 1 (integer is long int) * + * * + * Thus the legal types for realtype are float and double, while * + * the legal types for integertype are int and long int. * + * The macro RCONST gives a user a convenient way to define real * + * constants. To use the real constant 1.0, for example, the * + * user should write * + * * + * #define ONE RCONST(1.0) * + * * + * If realtype is double, then RCONST(1.0) expands to 1.0. * + * If realtype is float, then RCONST(1.0) expands to 1.0F. * + * There is never a need to explicitly cast 1.0 to (realtype). * + * * + *******************************************************************/ +#ifdef PHREEQC_IDENT +static char const svnidsundialstypes[] = "$Id$"; +#endif + +#ifdef __cplusplus /* wrapper to enable C++ usage */ +extern "C" { +#endif + +#ifndef _sundialstypes_h +#define _sundialstypes_h + + +/****************************************************************** + * * + * Types : realtype, integertype * + *----------------------------------------------------------------* + * The types realtype and integertype are currently set to double * + * and int, respectively. See the documentation at the top for * + * usage details and a description of associated constants and * + * macros. * + * * + ******************************************************************/ + +#ifdef USE_LONG_DOUBLE + typedef long double realtype; +#else + typedef double realtype; +#endif +typedef long int integertype; + +#define SUNDIALS_FLOAT 0 +#define SUNDIALS_DOUBLE 1 + +#define SUNDIALS_LONG 1 +#define SUNDIALS_INT 0 + +#if SUNDIALS_FLOAT + +#define RCONST(x) x##F + +#elif SUNDIALS_DOUBLE + +#define RCONST(x) x + +#endif + + +/****************************************************************** + * * + * Type : booleantype * + * Constants : FALSE, TRUE * + *----------------------------------------------------------------* + * ANSI C does not have a built-in boolean type. Below is the * + * definition for a new type booleantype. The advantage of using * + * the name booleantype (instead of int) is an increase in code * + * readability. * + * It allows the programmer to make a distinction between int and * + * boolean data. Variables of type booleantype are intended to * + * have only the two values FALSE and TRUE which are defined * + * below to be equal to 0 and 1, respectively. * + * * + ******************************************************************/ + +#ifndef booleantype +#define booleantype int +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#endif + +#ifdef __cplusplus +} +#endif diff --git a/tally.cpp b/tally.cpp new file mode 100644 index 00000000..2211863b --- /dev/null +++ b/tally.cpp @@ -0,0 +1,1006 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: tally.c 265 2005-04-25 13:57:00Z dlpark $"; +/* + * storage + */ +struct buffer { + char *name; + struct master *master; + LDBLE moles; + LDBLE gfw; +}; +struct buffer *buffer; +int count_component; +struct tally { + char *name; + enum entity_type type; + char *add_formula; + LDBLE moles; + struct elt_list *formula; + /* + * first total is initial + * second total is final + * third total is difference (final - initial) + */ + struct buffer *total[3]; +}; +struct tally *tally_table; +int count_tally_table_columns; +int count_tally_table_rows; + +static int elt_list_to_tally_table(struct buffer *buffer_ptr); + +/* + Calling sequence + +Initialization: +--------------- + +build_tally_table(); finds all elements (rows), + possible return values (columns), + allocates space +get_tally_table_rows_columns(int *rows, int *columns) + returns number of rows and columns in table +get_tally_table_row_heading(int row, char *string) + row is C row number + returns row descripter for row +get_tally_table_column_heading(int column, int *type, char *string) + column is C column number + returns column heading for column + +Each call to phreeqc: +--------------------- + +zero_tally_table(); initialize table to 0s +set_reaction_moles(n_user, moles) n_user is reservoir number + moles is number of moles of reaction to add + +int set_reaction_temperature(n_user, tc) + +fill_tally_table(int *n_user, int index_conservative, int n_buffer) + n_user is reservoir number + index_conservative is solution number + where conservative mixing is stored + slot is 0 for initial + + run phreeqc here. + +fill_tally_table(int *n_user, int index_conservative, int n_buffer) + n_user is reservoir number + index_conservative is solution number + where conservative mixing is stored + slot is 1 for final +store_tally_table(double *array, int row_dim, int col_dim, double fill_factor) + row_dim is Fortran dimension + col_dim is Fortran dimension + array is space from Fortran + stores conservative mixing (column 0) + stores reaction (column 1) + difference between slot 1 and slot 0 for + all other intities (columns 2-n) + +Finalization: +------------- +int free_tally_table(void); Frees space + +*/ + +/* ---------------------------------------------------------------------- */ +int get_all_components(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Counts components in any defined solution, gas_phase, exchanger, + * surface, or pure_phase_assemblage + * + * Returns n_comp, which is total, including H, O, elements, and Charge + * names contains character strings with names of components + */ + int i, j; +/* + * Accumulate all aqueous components + */ + add_all_components_tally(); +/* + * Count components, 2 for hydrogen, oxygen, + others, + */ + count_component = 0; + for (i = 0; i < count_master; i++) { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) { + count_component++; + } + } +/* + * Put information in buffer. + * Buffer contains an entry for every primary master + * species that can be used in the transport problem. + * Each entry in buffer is sent to HST for transort. + */ + buffer = (struct buffer *) PHRQ_malloc ((size_t) count_component * sizeof(struct buffer)); + j = 0; + for (i = 0; i < count_master; i++) { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) { + buffer[j].name = master[i]->elt->name; + buffer[j].master = master[i]; + buffer[j].gfw = master[i]->elt->gfw; + j++; + } + } +#ifdef SKIP + output_msg(OUTPUT_MESSAGE, "List of Components:\n"); + for (i = 0; i < count_component; i++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i+1, buffer[i].name); + /* + for (j=0; buffer[i].name[j] != '\0'; j++) { + names[i * length + j] = buffer[i].name[j]; + } + */ + } +#endif + /* + * Return value + */ + /**n_comp = count_component;*/ + count_tally_table_rows = count_component; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int store_tally_table(double *array, int row_dim, int col_dim, double fill_factor) +/* ---------------------------------------------------------------------- */ +{ + int i,j; + if (tally_table == NULL) { + input_error++; + error_msg("Tally table not defined, get_tally_table_rows_columns", CONTINUE); + return(ERROR); + } + if (count_tally_table_rows > row_dim) { + input_error++; + error_msg("Too many tally table rows for Fortran storage, store_tally_table", CONTINUE); + return(ERROR); + } + if (count_tally_table_columns > col_dim) { + input_error++; + error_msg("Too many tally table columns for Fortran storage, store_tally_table", CONTINUE); + return(ERROR); + } + /* + * store conservative mixing solution + */ + for (j = 0; j < count_tally_table_rows; j++) { + array[j] = tally_table[0].total[1][j].moles; + } + /* + * store reaction solution + */ + for (j = 0; j < count_tally_table_rows; j++) { + array[row_dim + j] = tally_table[1].total[1][j].moles; + } + /* + * Calculate deltas + */ + + diff_tally_table(); + + /* + * store deltas for all other columns + */ + for (i = 2; i < count_tally_table_columns; i++) { + for (j = 0; j < count_tally_table_rows; j++) { + array[i*row_dim + j] = tally_table[i].total[2][j].moles/fill_factor; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_tally_table_rows_columns(int *rows, int *columns) +/* ---------------------------------------------------------------------- */ +{ + *rows = 0; + *columns = 0; + if (tally_table == NULL) { + input_error++; + error_msg("tally table not defined, get_tally_table_rows_columns", CONTINUE); + return(ERROR); + } + *rows = count_tally_table_rows; + *columns = count_tally_table_columns; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_tally_table_row_heading(int row, char *string) +/* ---------------------------------------------------------------------- */ +{ + /* + * row is C row number + */ + strcpy(string, ""); + if (tally_table == NULL) { + input_error++; + error_msg("Tally table not defined, get_tally_table row_heading", CONTINUE); + return(ERROR); + } + if (row >= count_tally_table_rows) { + input_error++; + error_msg("Row exceeds tally table size, get_tally_table row_heading", CONTINUE); + return(ERROR); + } + strcpy(string, buffer[row].name); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int get_tally_table_column_heading(int column, int *type, char *string) +/* ---------------------------------------------------------------------- */ +{ + /* + * column is C column number + */ + *type = -1; + strcpy(string, ""); + if (tally_table == NULL) { + input_error++; + error_msg("tally table not defined, get_tally_table_column_heading", CONTINUE); + return(ERROR); + } + if (column >= count_tally_table_columns) { + input_error++; + error_msg("column exceeds tally table size, get_tally_table_column_heading", CONTINUE); + return(ERROR); + } + strcpy(string, tally_table[column].name); + *type = tally_table[column].type; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int free_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, k; + if (tally_table == NULL) return(OK); + for (i = 0; i < count_tally_table_columns; i++) { + if (tally_table[i].formula != NULL) (struct elt_list *) free_check_null(tally_table[i].formula); + for (k = 0; k < 3; k++) { + tally_table[i].total[k] = (struct buffer *) free_check_null(tally_table[i].total[k]); + } + } + tally_table = (struct tally *) free_check_null(tally_table); + buffer = (struct buffer *) free_check_null(buffer); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int zero_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + for (i = 0; i < count_tally_table_columns; i++) { + for (j = 0; j < count_tally_table_rows; j++) { + for (k = 0; k < 3; k++) { + tally_table[i].total[k][j].moles = 0; + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int diff_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + /* + output_msg(OUTPUT_MESSAGE,"Difference\n\n"); + */ + for (i = 0; i < count_tally_table_columns; i++) { + for (j = 0; j < count_tally_table_rows; j++) { + tally_table[i].total[2][j].moles = tally_table[i].total[1][j].moles - tally_table[i].total[0][j].moles; + } + + /* + output_msg(OUTPUT_MESSAGE, "Column %d\t%s\tType: %d\n", i, tally_table[i].name, tally_table[i].type); + for (j = 0; j < count_tally_table_rows; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\t%e\n", j, tally_table[i].total[2][j].name, (double) tally_table[i].total[2][j].moles); + } + */ + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + output_msg(OUTPUT_MESSAGE,"Tally_table\n\n"); + for (i = 0; i < count_tally_table_columns; i++) { + output_msg(OUTPUT_MESSAGE, "%s\tType: %d\n", tally_table[i].name, tally_table[i].type); + output_msg(OUTPUT_MESSAGE,"\n"); + output_msg(OUTPUT_MESSAGE, "\t%15s\t%15s\t%15s\n", "Initial", "Final", "Difference"); + for (j = 0; j < count_tally_table_rows; j++) { + output_msg(OUTPUT_MESSAGE,"%5s\t%15g\t%15g\t%15g\n", buffer[j].name, tally_table[i].total[0][j].moles, tally_table[i].total[1][j].moles, tally_table[i].total[2][j].moles); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int fill_tally_table(int *n_user, int index_conservative, int n_buffer) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. + */ + int i, j, k, n; + struct solution *solution_ptr; + struct irrev *irrev_ptr; + struct pp_assemblage *pp_assemblage_ptr; + struct exchange *exchange_ptr; + struct surface *surface_ptr; + struct s_s_assemblage *s_s_assemblage_ptr; + struct gas_phase *gas_phase_ptr; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + int found; + LDBLE moles; + char *ptr; + /* + * Cycle through tally table columns + */ + for (i = 0; i < count_tally_table_columns; i++) { + switch (tally_table[i].type) { + case Solution: +/* + * fill solution + */ + if (n_user[Solution] < 0 || n_buffer == 0) break; + if (i == 0) { + solution_ptr = solution_bsearch(index_conservative, &n, TRUE); + } else if (i == 1) { + solution_ptr = solution_bsearch(n_user[Solution], &n, TRUE); + } else { + solution_ptr = NULL; + error_msg("Solution is not in first two columns of tally_table", STOP); + } + if (solution_ptr == NULL) break; + xsolution_zero(); + add_solution(solution_ptr, 1.0, 1.0); + count_elts = 0; + paren_count = 0; + for (j=0; j < count_master; j++) { + if (master[j]->total > 0.0) { + ptr = master[j]->elt->primary->elt->name; + get_elts_in_species (&ptr, master[j]->total); + } + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Reaction: + /* + * fill reaction + */ + if (n_user[Reaction] < 0) break; + irrev_ptr = irrev_bsearch(n_user[Reaction], &n); + if (irrev_ptr == NULL) break; + count_elts = 0; + paren_count = 0; + if (n_buffer == 1) { + moles = irrev_ptr->steps[0]; + } else { + moles = 0.0; + } + add_elt_list(irrev_ptr->elts, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Pure_phase: + /* + * fill an equilibrium phase + */ + if (n_user[Pure_phase] < 0) break; + pp_assemblage_ptr = pp_assemblage_bsearch(n_user[Pure_phase], &n); + if (pp_assemblage_ptr == NULL) break; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { + if (pp_assemblage_ptr->pure_phases[j].name == tally_table[i].name) break; + if (strcmp_nocase(pp_assemblage_ptr->pure_phases[j].name, tally_table[i].name) == 0) break; + } + if (j >= pp_assemblage_ptr->count_comps) break; + count_elts = 0; + paren_count = 0; + moles = pp_assemblage_ptr->pure_phases[j].moles; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Exchange: + /* + * fill exchange + */ + if (n_user[Exchange] < 0) break; + exchange_ptr = exchange_bsearch(n_user[Exchange], &n); + if (exchange_ptr == NULL) break; + count_elts = 0; + paren_count = 0; + for (j = 0; j < exchange_ptr->count_comps; j++) { + add_elt_list(exchange_ptr->comps[j].totals, 1.0); + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Surface: + /* + * fill surface + */ + if (n_user[Surface] < 0) break; + surface_ptr = surface_bsearch(n_user[Surface], &n); + if (surface_ptr == NULL) break; + count_elts = 0; + paren_count = 0; + for (j = 0; j < surface_ptr->count_comps; j++) { + add_elt_list(surface_ptr->comps[j].totals, 1.0); + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Ss_phase: + /* + * fill an solid solution phase + */ + if (n_user[Ss_phase] < 0) break; + s_s_assemblage_ptr = s_s_assemblage_bsearch(n_user[Ss_phase], &n); + if (s_s_assemblage_ptr == NULL) break; + found = FALSE; + moles = 0.0; + for (j = 0; j < s_s_assemblage_ptr->count_s_s; j++) { + for (k = 0; k < s_s_assemblage_ptr->s_s[j].count_comps; k++) { + if (s_s_assemblage_ptr->s_s[j].comps[k].phase->name == tally_table[i].name) break; + if (strcmp_nocase(s_s_assemblage_ptr->s_s[j].comps[k].phase->name, tally_table[i].name) == 0) break; + } + if (k < s_s_assemblage_ptr->s_s[j].count_comps) { + moles = s_s_assemblage_ptr->s_s[j].comps[k].moles; + found = TRUE; + break; + } + } + if (found == FALSE) break; + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Gas_phase: + /* + * fill in gas phase + */ + if (n_user[Gas_phase] < 0) break; + gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); + if (gas_phase_ptr == NULL) break; + count_elts = 0; + paren_count = 0; + for (j = 0; j < gas_phase_ptr->count_comps; j++) { + add_elt_list(gas_phase_ptr->comps[j].phase->next_elt, gas_phase_ptr->comps[j].moles); + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Kinetics: + /* + * fill in kinetics + */ + if (n_user[Kinetics] < 0) break; + kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); + if (kinetics_ptr == NULL) break; + kinetics_comp_ptr = NULL; + for (j = 0; j < kinetics_ptr->count_comps; j++) { + kinetics_comp_ptr = &kinetics_ptr->comps[j]; + if (kinetics_comp_ptr->rate_name == tally_table[i].name) break; + if (strcmp_nocase(kinetics_comp_ptr->rate_name, tally_table[i].name) == 0) break; + } + if (j >= kinetics_ptr->count_comps) break; + moles = kinetics_comp_ptr->m; + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Mix: + break; + case Temperature: + break; + case UnKnown: + break; + } +#ifdef SKIP + output_msg(OUTPUT_MESSAGE, "Column %d\t%s\tType: %d\n", i, tally_table[i].name, tally_table[i].type); + for (j = 0; j < count_tally_table_rows; j++) { + output_msg(OUTPUT_MESSAGE, "\t%d\t%s\t%e\n", j, tally_table[i].total[n_buffer][j].name, (double) tally_table[i].total[n_buffer][j].moles); + } +#endif + } + + return(OK); +} + +/* ---------------------------------------------------------------------- */ +int elt_list_to_tally_table(struct buffer *buffer_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + for (i = 0; i < count_tally_table_rows; i++) { + buffer_ptr[i].moles=0.0; + } + /* + * copy element list amounts to buffer in tally table + * for column number + */ + + for ( j=0; j < count_elts; j++ ) { + if (elt_list[j].elt->primary->s == s_h2o) continue; + if (elt_list[j].elt->primary->s == s_hplus) continue; + if (elt_list[j].elt->primary->s == s_h3oplus) continue; + if (elt_list[j].elt->primary->type != AQ) continue; + for (i = 0; i < count_tally_table_rows; i++) { + if (elt_list[j].elt->primary == buffer_ptr[i].master->elt->primary) { + buffer_ptr[i].moles=elt_list[j].coef; + break; + } + } + if (i >= count_tally_table_rows) { + error_msg("Should not be here in elt_list_to_tally_table", STOP); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int build_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. Counts number of aqueous components + * to transport. Stores in global variable count_component. + * Also calculates a number greater than all user numbers and + * stores in global variable first_user_number. + */ + int i, j, k, l, n, p, save_print_use; + int count_tt_reaction, count_tt_exchange, count_tt_surface, count_tt_gas_phase; + int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; + struct pp_assemblage *pp_assemblage_ptr; + struct pure_phase *pure_phase_ptr; + struct s_s_assemblage *s_s_assemblage_ptr; + struct s_s *s_s_ptr; + struct s_s_comp *s_s_comp_ptr; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + struct phase *phase_ptr; + + + char token[MAX_LENGTH]; + char *ptr; + + if (svnid == NULL) fprintf(stderr," "); +/* + * make list of all elements in all entitites + * defines the number of rows in the table + */ + get_all_components(); + + save_print_use = pr.use; + pr.use = FALSE; +/* + * find nuber of columns + */ + count_tally_table_columns = 0; +/* + * add one for conservative mixing + */ + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Solution_conservative"); + tally_table[n].type = Solution; +/* + * add one for mixing plus reaction + */ + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Solution_reaction"); + tally_table[n].type = Solution; +/* + * add one for reactions + */ + if (count_irrev > 0) { + count_tt_reaction = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Reaction"); + tally_table[n].type = Reaction; + } else { + count_tt_reaction = 0; + } +/* + * add one for exchangers + */ + if (count_exchange > 0) { + count_tt_exchange = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Exchange"); + tally_table[n].type = Exchange; + } else { + count_tt_exchange = 0; + } +/* + * add one for surface + */ + if (count_surface > 0) { + count_tt_surface = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Surface"); + tally_table[n].type = Surface; + } else { + count_tt_surface = 0; + } +/* + * add one for gases + */ + if (count_gas_phase > 0) { + count_tt_gas_phase = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Gas_phase"); + tally_table[n].type = Gas_phase; + } else { + count_tt_gas_phase = 0; + } +/* + * Count pure phases + */ + count_tt_pure_phase = 0; + if (count_pp_assemblage > 0) { + /* + * Go through all pure phases in pure phase assemblages + */ + for (i = 0; i < count_pp_assemblage; i++) { + pp_assemblage_ptr = &pp_assemblage[i]; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { + pure_phase_ptr = &pp_assemblage_ptr->pure_phases[j]; + /* + * check if already in tally_table + */ + for (k = 1; k < count_tally_table_columns; k++) { + if (tally_table[k].type == Pure_phase && + tally_table[k].name == pure_phase_ptr->phase->name && + tally_table[k].add_formula == pure_phase_ptr->add_formula) break; + } + if (k < count_tally_table_columns) continue; + /* + * Add to table + */ + count_tt_pure_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = pure_phase_ptr->phase->name; + tally_table[n].type = Pure_phase; + tally_table[n].add_formula = pure_phase_ptr->add_formula; + count_elts = 0; + paren_count = 0; + if (pure_phase_ptr->add_formula != NULL) { + strcpy(token, pure_phase_ptr->add_formula); + ptr = &(token[0]); + get_elts_in_species (&ptr, 1.0); + } else { + strcpy(token, pure_phase_ptr->phase->formula); + add_elt_list(pure_phase_ptr->phase->next_elt, 1.0); + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +/* + * Add solid-solution pure phases + */ + count_tt_ss_phase = 0; + if (count_pp_assemblage > 0) { + /* + * Go through all components of all solid solutions in solid-solution assemblages + */ + for (i = 0; i < count_s_s_assemblage; i++) { + s_s_assemblage_ptr = &s_s_assemblage[i]; + for (j = 0; j < s_s_assemblage_ptr->count_s_s; j++) { + s_s_ptr = &s_s_assemblage_ptr->s_s[j]; + for (k = 0; k < s_s_ptr->count_comps; k++) { + s_s_comp_ptr = &s_s_ptr->comps[k]; + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) { + if (tally_table[l].type == Ss_phase && + tally_table[l].name == s_s_comp_ptr->phase->name) break; + } + if (l < count_tally_table_columns) continue; + /* + * Add to table + */ + count_tt_ss_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = s_s_comp_ptr->phase->name; + tally_table[n].type = Ss_phase; + count_elts = 0; + paren_count = 0; + strcpy(token, s_s_comp_ptr->phase->formula); + add_elt_list(s_s_comp_ptr->phase->next_elt, 1.0); + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } + } +/* + * Add kinetic reactants + */ + count_tt_kinetics = 0; + if (count_kinetics > 0) { + for (i = 0; i < count_kinetics; i++) { + kinetics_ptr = &kinetics[i]; + for (j = 0; j < kinetics_ptr->count_comps; j++) { + kinetics_comp_ptr = &kinetics_ptr->comps[j]; + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) { + if (tally_table[l].type == Kinetics && + tally_table[l].name == kinetics_comp_ptr->rate_name) break; + } + if (l < count_tally_table_columns) continue; + /* + * Add to table + */ + count_tt_kinetics++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = kinetics_comp_ptr->rate_name; + tally_table[n].type = Kinetics; + /* + * get formula for kinetic component + */ + count_elts = 0; + paren_count = 0; + phase_ptr = NULL; + if (kinetics_ptr->comps[j].count_list == 1) { + strcpy(token, kinetics_ptr->comps[j].list[0].name); + phase_ptr = phase_bsearch(token, &p, FALSE); + } + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, 1.0); + } else { + for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) { + ptr = kinetics_ptr->comps[j].list[k].name; + get_elts_in_species (&ptr, 1.0 * kinetics_ptr->comps[j].list[k].coef); + } + } + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +#ifdef SKIP + /* + * Debug print for table definition + */ + output_msg(OUTPUT_MESSAGE, "List of rows for tally table\n"); + for (i = 0; i < count_tally_table_rows; i++) { + output_msg(OUTPUT_MESSAGE, "\t%-s\n", buffer[i].name); + } + output_msg(OUTPUT_MESSAGE, "\nList of columns for tally table\n"); + for (i = 0; i < count_tally_table_columns; i++) { + output_msg(OUTPUT_MESSAGE, "\t%-20s\tType: %d\n", tally_table[i].name, tally_table[i].type); + if (tally_table[i].formula != NULL) { + for (j = 0; tally_table[i].formula[j].elt != NULL; j++) { + output_msg(OUTPUT_MESSAGE,"\t\t%-10s\t%f\n", tally_table[i].formula[j].elt->name, (double) tally_table[i].formula[j].coef); + } + } + } +#endif + pr.use = save_print_use; + return(OK); +} +/* ---------------------------------------------------------------------- */ +void add_all_components_tally(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. Counts number of aqueous components + * to transport. Stores in global variable count_component. + * Also calculates a number greater than all user numbers and + * stores in global variable first_user_number. + */ + int i, save_print_use; + + save_print_use = pr.use; + pr.use = FALSE; +/* + * Delete solutions less than -1 + */ + while (count_solution > 0 && solution[0]->n_user < -1) { + i = solution[0]->n_user; + solution_delete(i); + } +/* + * add all solutions + */ + xsolution_zero(); + for (i = 0; i < count_solution; i++) { + add_solution(solution[i], 1.0/solution[i]->mass_water, 1.0); + } +/* + * add all irrev reactions + */ + for (i = 0; i < count_irrev; i++) { + add_reaction(&irrev[i], 1, 1.0); + } +/* + * Add pure phases + */ + for (i = 0; i < count_pp_assemblage; i++) { + add_pp_assemblage(&pp_assemblage[i]); + } +/* + * Exchangers + */ + for (i = 0; i < count_exchange; i++) { + add_exchange(&exchange[i]); + } +/* + * Surfaces + */ + for (i = 0; i < count_surface; i++) { + add_surface(&surface[i]); + } +/* + * Gases + */ + for (i = 0; i < count_gas_phase; i++) { + add_gas_phase(&gas_phase[i]); + } +/* + * Add solid-solution pure phases + */ + for (i = 0; i < count_s_s_assemblage; i++) { + add_s_s_assemblage(&s_s_assemblage[i]); + } +/* + * Add elements in kinetic reactions + */ + for (i = 0; i < count_kinetics; i++) { + calc_dummy_kinetic_reaction_tally(&kinetics[i]); + add_kinetics(&kinetics[i]); + } +/* + * reset pr.use + */ + pr.use = save_print_use; + return; +} +/* ---------------------------------------------------------------------- */ +int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components and add positive amount of each reactant + */ + int i, j; + LDBLE coef; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + free_check_null(kinetics_ptr->totals); + count_elts = 0; + paren_count = 0; + for (i=0; i < kinetics_ptr->count_comps; i++) { + coef = 1.0; +/* + * Reactant is a pure phase, copy formula into token + */ + phase_ptr = NULL; + if (kinetics_ptr->comps[i].count_list == 1) { + strcpy(token, kinetics_ptr->comps[i].list[0].name); + phase_ptr = phase_bsearch(token, &j, FALSE); + } + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, coef); + } else { + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { + ptr = kinetics_ptr->comps[i].list[j].name; + get_elts_in_species (&ptr, coef); + } + } + + } + kinetics_ptr->totals = elt_list_save(); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int extend_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + /* + * adds another column to tally_table + * increments number of columns + */ + tally_table = (struct tally *)PHRQ_realloc((void *) tally_table, (size_t) (count_tally_table_columns + 1) * sizeof(struct tally)); + if (tally_table == NULL) malloc_error(); + for (i = 0; i < 3; i++) { + tally_table[count_tally_table_columns].total[i] = (struct buffer *)PHRQ_malloc( (size_t) (count_tally_table_rows) * sizeof( struct buffer )); + if (tally_table[count_tally_table_columns].total[i] == NULL) malloc_error(); + for (j = 0; j < count_tally_table_rows; j++) { + tally_table[count_tally_table_columns].total[i][j].name = buffer[j].name; + tally_table[count_tally_table_columns].total[i][j].master = buffer[j].master; + } + } + tally_table[count_tally_table_columns].name = NULL; + tally_table[count_tally_table_columns].type = UnKnown; + tally_table[count_tally_table_columns].add_formula = NULL; + tally_table[count_tally_table_columns].moles = 0.0; + tally_table[count_tally_table_columns].formula = NULL; + count_tally_table_columns++; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_reaction_moles(int n_user, LDBLE moles) +/* ---------------------------------------------------------------------- */ +{ + int n; + struct irrev *irrev_ptr; + + irrev_ptr = irrev_bsearch(n_user, &n); + if (irrev_ptr == NULL) return(ERROR); + irrev_ptr->steps[0] = moles; + irrev_ptr->count_steps = 1; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_reaction_temperature(int n_user, LDBLE tc) +/* ---------------------------------------------------------------------- */ +{ + int n; + struct temperature *temperature_ptr; + + temperature_ptr = temperature_bsearch(n_user, &n); + if (temperature_ptr == NULL) return(ERROR); + temperature_ptr->t[0] = tc; + temperature_ptr->count_t = 1; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_kinetics_time(int n_user, LDBLE step) +/* ---------------------------------------------------------------------- */ +{ + int n; + struct kinetics *kinetics_ptr; + + kinetics_ptr = kinetics_bsearch(n_user, &n); + if (kinetics_ptr == NULL) return(ERROR); + kinetics_ptr->steps[0] = step; + kinetics_ptr->count_steps = 1; + return(OK); +} + diff --git a/test.xml b/test.xml new file mode 100644 index 00000000..72bbd502 --- /dev/null +++ b/test.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + diff --git a/tidy.cpp b/tidy.cpp new file mode 100644 index 00000000..b76b509f --- /dev/null +++ b/tidy.cpp @@ -0,0 +1,3333 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: tidy.c 407 2005-07-27 22:06:36Z dlpark $"; + +static int check_species_input(void); +static LDBLE coef_in_master(struct master *master_ptr); +static int phase_rxn_to_trxn(struct phase *phase_ptr); +static int reset_last_model(void); +static int rewrite_eqn_to_primary(void); +static int rewrite_eqn_to_secondary(void); +static int species_rxn_to_trxn(struct species *s_ptr); +static int tidy_min_exchange(void); +static int tidy_kin_exchange(void); +static int tidy_gas_phase(void); +static int tidy_inverse(void); +static int tidy_isotopes (void); +static int tidy_isotope_ratios(void); +static int tidy_isotope_alphas(void); +static int tidy_kin_surface(void); +static int tidy_master_isotope (void); +static int tidy_min_surface(void); +static int tidy_phases(void); +static int tidy_pp_assemblage(void); +static int tidy_solutions(void); +static int tidy_s_s_assemblage(void); +static int tidy_species(void); +static int tidy_surface(void); + +static LDBLE a0, a1, kc, kb; +static int scan(LDBLE f(LDBLE x), LDBLE *xx0, LDBLE *xx1); +static LDBLE halve(LDBLE f(LDBLE x), LDBLE x0, LDBLE x1, LDBLE tol); +static LDBLE f_spinodal(LDBLE x); +static int solve_misc(LDBLE *xxc1, LDBLE *xxc2, LDBLE tol); +static int s_s_calc_a0_a1(struct s_s *s_s_ptr); +#define ZERO_TOL 1.0e-30 + +/* ---------------------------------------------------------------------- */ +int tidy_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + int n_user, last; + if (svnid == NULL) fprintf(stderr," "); + /* + * Determine if any new elements, species, phases have been read + */ + new_model = FALSE; + new_pp_assemblage = FALSE; + new_surface = FALSE; + new_exchange = FALSE; + new_reaction = FALSE; + new_temperature = FALSE; + new_mix = FALSE; + new_solution = FALSE; + new_gas_phase = FALSE; + new_inverse = FALSE; + new_punch = FALSE; + new_surface = FALSE; + new_s_s_assemblage = FALSE; + new_kinetics = FALSE; + new_pitzer = FALSE; + if (keyword[2].keycount > 0 || /*"species"*/ + keyword[3].keycount > 0 || /*"master"*/ + keyword[5].keycount > 0 || /*"phases"*/ + keyword[11].keycount > 0 || /*"exchange_species"*/ + keyword[12].keycount > 0 || /*"master_exchange_species"*/ + keyword[14].keycount > 0 || /*"surface_species"*/ + keyword[15].keycount > 0 || /*"master_surface_species"*/ + keyword[36].keycount > 0 || /*"rates"*/ + keyword[47].keycount > 0 || /*"llnl_aqueous_model_parameters"*/ + (keyword[49].keycount > 0 && simulation == 0) || /*"database"*/ + keyword[51].keycount > 0 || /*"named_analytical_expressions"*/ + keyword[54].keycount > 0 || /*"isotopes"*/ + keyword[55].keycount > 0 || /*"calculate_values"*/ + keyword[56].keycount > 0 || /*"isotopes_ratios",*/ + keyword[57].keycount > 0 || /*"isotopes_alphas"*/ + keyword[59].keycount > 0 ) { /*"pitzer"*/ + new_model = TRUE; + } + if (keyword[6].keycount > 0) new_pp_assemblage = TRUE; /*"pure_phases"*/ + if (keyword[16].keycount > 0) new_surface = TRUE; /*"surface"*/ + if (keyword[13].keycount > 0) new_exchange = TRUE; /*"exchange"*/ + if (keyword[7].keycount > 0) new_reaction = TRUE; /*"reaction"*/ + if (keyword[17].keycount > 0) new_temperature = TRUE; /*"reacton_temperature"*/ + if (keyword[8].keycount > 0) new_mix = TRUE; /*"mix"*/ + if (keyword[4].keycount > 0 || /*"solution"*/ + keyword[43].keycount > 0 ) { /*"spread_solution"*/ + new_solution = TRUE; + } + if (keyword[19].keycount > 0) new_gas_phase = TRUE; /*"gas_phase"*/ + if (keyword[18].keycount > 0) new_inverse = TRUE; /*"inverse_modeling"*/ + if (keyword[22].keycount > 0 || /*"selected_output"*/ + keyword[39].keycount > 0 ) { /*"user_punch"*/ + new_punch = TRUE; + } + if (keyword[40].keycount > 0) new_s_s_assemblage = TRUE;/*"solid_solutions"*/ + if (keyword[33].keycount > 0) new_kinetics = TRUE; /*"kinetics"*/ + if (keyword[58].keycount > 0) new_copy = TRUE; /*"copy"*/ + if (keyword[59].keycount > 0) new_pitzer = TRUE; /*"pitzer"*/ + + /* + 0 "eof" + 1 "end" + 2 "species" + 3 "master" + 4 "solution" + 5 "phases" + 6 "pure_phases" + 7 "reaction" + 8 "mix" + 9 "use" + 10 "save" + 11 "exchange_species" + 12 "master_exchange_species" + 13 "exchange" + 14 "surface_species" + 15 "master_surface_species" + 16 "surface" + 17 "reacton_temperature" + 18 "inverse_modeling" + 19 "gas_phase" + 20 "transport" + 21 "debug" + 22 "selected_output" + 23 "select_output" + 24 "knobs" + 25 "print" + 26 "equilibrium_phases" + 27 "equilibria" + 28 "equilibrium" + 29 "pure" + 30 "title" + 31 "comment" + 32 "advection" + 33 "kinetics" + 34 "incremental_reactions" + 35 "incremental" + 36 "rates" + 37 "solution_s" + 38 "user_print" + 39 "user_punch" + 40 "solid_solutions" + 41 "solid_solution" + 42 "solution_spread" + 43 "spread_solution" + 44 "selected_out" + 45 "select_out" + 46 "user_graph" + 47 "llnl_aqueous_model_parameters" + 48 "llnl_aqueous_model" + 49 "database" + 50 "named_analytical_expression" + 51 "named_analytical_expressions" + 52 "named_expressions" + 53 "named_log_k" + 54 "isotopes" + 55 "calculate_values" + 56 "isotopes_ratios", + 57 "isotopes_alphas" + 58 "copy" + 59 "pitzer" + */ + +/* + * Sort arrays + */ + +/* species */ + if (new_model == TRUE) { + qsort (s, + (size_t) count_s, + (size_t) sizeof (struct species *), + s_compare); + +/* master species */ + qsort (master, + (unsigned) count_master, + sizeof(struct master *), + master_compare); + +/* elements */ + qsort (elements, + (size_t) count_elements, + (size_t) sizeof (struct element *), + element_compare); +/* phases */ + qsort (phases, + (size_t) count_phases, + (size_t) sizeof (struct phase *), + phase_compare); + + } +/* pure_phases */ + if (new_pp_assemblage) pp_assemblage_sort(); + +/* solid solutions */ + if (new_s_s_assemblage) s_s_assemblage_sort(); + +/* exchangers */ + if (new_exchange) exchange_sort(); +/* surfaces */ + if (new_surface) surface_sort(); +#ifdef SKIP +/* mixtures */ + qsort (mix, + (size_t) count_mix, + (size_t) sizeof (struct mix), + mix_compare); +#endif + +/* mixtures */ +/* !!!!! + * In transport mode, with stagnant cells, cell number is 'n_mix_user' for + * both mix with stagnant cells and for dispersive mix. + * qsort(mix) then fails. Hence ... + */ + + if ((state != TRANSPORT) || (simul_tr < 2) || (stag_data->count_stag == 0)) { + mix_sort(); + } + +/* gas_phase */ + if (new_gas_phase) gas_phase_sort(); + +/* kinetics */ + if (new_kinetics) kinetics_sort(); +/* + * Check pointers, write reactions for species + */ + if (new_model) { + tidy_species(); + + tidy_phases(); + + tidy_master_isotope(); +/* + * calculate gfw of water, kg/mole + */ + compute_gfw("H2O", &gfw_water); + gfw_water *= 0.001; + } +/* + * tidy surface data + */ + if (new_model || new_surface) tidy_surface(); +/* + * tidy inverse data + */ + if (new_inverse) tidy_inverse(); +/* + * tidy gas phase data + */ + if (new_gas_phase) tidy_gas_phase(); +/* + * tidy pp_assemblage data + */ + if (new_model || new_pp_assemblage) tidy_pp_assemblage(); +/* + * tidy s_s_assemblage data + */ + if (new_model || new_s_s_assemblage) tidy_s_s_assemblage(); +/* + * tidy exchange data, after pp_assemblages + */ + if (new_exchange) tidy_min_exchange(); + if (new_exchange) tidy_kin_exchange(); +/* + * tidy surface data + */ + if (new_surface) tidy_min_surface(); + if (new_surface) tidy_kin_surface(); +/* + * tidy solution isotope data + */ + if (new_solution) tidy_isotopes(); + if (new_model) tidy_isotope_ratios(); + if (new_model) tidy_isotope_alphas(); +/* + * Duplicate reaction + */ + if (new_reaction) { + for ( i = 0; i < count_irrev; i++) { + if ( irrev[i].n_user_end > irrev[i].n_user ) { + n_user = irrev[i].n_user; + last = irrev[i].n_user_end; + irrev[i].n_user_end = irrev[i].n_user; + for (j = n_user + 1; j <= last; j++) { + irrev_duplicate(n_user, j); + } + } + } + } +/* + * Duplicate kinetics + */ + if (new_kinetics) { + for ( i = 0; i < count_kinetics; i++) { + if ( kinetics[i].n_user_end > kinetics[i].n_user ) { + n_user = kinetics[i].n_user; + last = kinetics[i].n_user_end; + kinetics[i].n_user_end = kinetics[i].n_user; + for (j = n_user + 1; j <= last; j++) { + kinetics_duplicate(n_user, j); + } + } + } + } +/* + * Duplicate temperature + */ + if (new_temperature) { + temperature_sort(); + for ( i = 0; i < count_temperature; i++) { + if ( temperature[i].n_user_end > temperature[i].n_user ) { + n_user = temperature[i].n_user; + last = temperature[i].n_user_end; + temperature[i].n_user_end = temperature[i].n_user; + for (j = n_user + 1; j <= last; j++) { + temperature_duplicate(n_user, j); + } + } + } + } +/* + * Tidy pitzer information + */ + if (pitzer_model && new_model) pitzer_tidy(); +/* + * Tidy punch information + */ + if (input_error == 0 && (new_punch || new_model)) tidy_punch(); +/* + * Tidy solution information + */ + if (new_solution) tidy_solutions(); + + /* if (new_model || new_exchange || new_pp_assemblage || new_surface || new_gas_phase || new_kinetics) reset_last_model(); */ + if (new_model) reset_last_model(); +/* + * make sure essential species are defined + */ + if (s_h2o == NULL) { + input_error++; + error_msg("H2O not defined.", STOP); + } + if (s_h2o->primary == NULL) { + input_error++; + error_msg("H2O, primary master species for O, not defined.", CONTINUE); + } + if (s_h2o->secondary == NULL) { + input_error++; + error_msg("H2O, secondary master species for O(-2), not defined.", CONTINUE); + } + if (s_hplus == NULL && s_h3oplus == NULL) { + input_error++; + error_msg("Neither H+ nor H3O+ are defined in solution_species.", STOP); + } else if (s_hplus == NULL && s_h3oplus != NULL) { + s_hplus = s_h3oplus; + s_h3oplus = NULL; + } else if (s_hplus != NULL && s_h3oplus == NULL) { + } else if (s_hplus != NULL && s_h3oplus != NULL) { + input_error++; + error_msg("Can not define both H+ and H3O+ in solution_species.", STOP); + } + if (s_hplus->primary == NULL) { + input_error++; + error_msg("H3O+, primary master species for H, not defined.", CONTINUE); + } + if (s_hplus->secondary == NULL) { + input_error++; + error_msg("H3O+, secondary master species for H(1), not defined.", CONTINUE); + } + if (s_eminus == NULL) { + input_error++; + error_msg("e- not defined in solution_species.", CONTINUE); + } + if (s_eminus->primary == NULL) { + input_error++; + error_msg("e-, primary master species for E-, not defined.", CONTINUE); + } + if (pitzer_model == FALSE) { + if (s_h2 == NULL) { + input_error++; + error_msg("H2(aq) not defined in solution_species.", CONTINUE); + } + if (s_o2 == NULL) { + input_error++; + error_msg("O2(aq) not defined in solution_species.", CONTINUE); + } + } + element_h_one = element_store ("H(1)"); + if (element_h_one == NULL) { + input_error++; + error_msg("H(1) not defined in solution_master_species.", CONTINUE); + } +/* + * Error check, program termination + */ + if (input_error > 0 || parse_error > 0 ) { + error_msg("Calculations terminating due to input errors.", STOP); + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int check_species_input(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check species data for completeness + */ + int i; + int return_value; + + return_value = OK; + for (i=0; i < count_s; i++) { + if (s[i]->next_elt == NULL) { + input_error++; + return_value = ERROR; + sprintf(error_string, "Elements in species have not been tabulated, %s.", s[i]->name); + error_msg(error_string, CONTINUE); + } + if (s[i]->rxn == NULL) { + input_error++; + return_value = ERROR; + sprintf(error_string, "Reaction for species has not been defined, %s.", s[i]->name); + error_msg(error_string, CONTINUE); + } else { + select_log_k_expression(s[i]->logk, s[i]->rxn->logk); + add_other_logk(s[i]->rxn->logk, s[i]->count_add_logk, s[i]->add_logk); + } + } + return(return_value); +} +/* ---------------------------------------------------------------------- */ +int select_log_k_expression(LDBLE *source_k, LDBLE *target_k) +/* ---------------------------------------------------------------------- */ +{ + int j, analytic; + + analytic = FALSE; + for (j=2; j < 7; j++) { + if (source_k[j] != 0.0) { + analytic = TRUE; + break; + } + } + if (analytic == TRUE) { + target_k[0] = 0.0; + target_k[1] = 0.0; + for (j=2; j < 7; j++) { + target_k[j] = source_k[j]; + } + } else { + target_k[0] = source_k[0]; + target_k[1] = source_k[1]; + for (j=2; j < 7; j++) { + target_k[j] = 0.0; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int add_other_logk(LDBLE *source_k, int count_add_logk, struct name_coef *add_logk) +/* ---------------------------------------------------------------------- */ +{ + int i, j, analytic; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + LDBLE coef; + ENTRY item, *found_item; + + if (count_add_logk == 0) return(OK); + for (i = 0; i < count_add_logk; i++) { + coef = add_logk[i].coef; + strcpy(token, add_logk[i].name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + if (found_item == NULL) { + input_error++; + sprintf(error_string,"Could not find named temperature expression, %s\n", token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + logk_ptr = (struct logk *) found_item->data; + analytic = FALSE; + for (j=2; j < 7; j++) { + if (logk_ptr->log_k[j] != 0.0) { + analytic = TRUE; + break; + } + } + if (analytic == TRUE) { + for (j=2; j < 7; j++) { + source_k[j] += logk_ptr->log_k[j]*coef; + } + } else { + source_k[0] += logk_ptr->log_k[0]*coef; + source_k[1] += logk_ptr->log_k[1]*coef; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE coef_in_master(struct master *master_ptr) +/* ---------------------------------------------------------------------- */ +{ + int l; + LDBLE coef; + char *ptr; + char elt_name[MAX_LENGTH]; + struct elt_list *next_elt; + + coef = 0.0; + ptr = master_ptr->elt->name; + get_elt(&ptr, elt_name, &l); + for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL; next_elt++) { + if ( strcmp(elt_name, next_elt->elt->name) == 0 ) { + coef= next_elt->coef; + break; + } + } + return(coef); +} +/* ---------------------------------------------------------------------- */ +int rewrite_eqn_to_secondary(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for species in terms of secondary species + * Result is in trxn. + */ + LDBLE coef; + int repeat, i, add_count; + struct rxn_token_temp *token_ptr; +/* + * + */ + add_count=0; + repeat=TRUE; +/* + * Reduce reaction equation to primary and secondary species + */ + while (repeat == TRUE) { + repeat = FALSE; + /* Check for too many iterations */ + if (++add_count > MAX_ADD_EQUATIONS) { + parse_error++; + sprintf(error_string, "Could not reduce equation to secondary master species, %s.", trxn.token[0].name); + error_msg(error_string, CONTINUE); + break; + } + + for (i=1; i < count_trxn; i++) { + token_ptr = &(trxn.token[i]); + if (token_ptr->s->secondary == NULL && + token_ptr->s->primary == NULL) { + coef=token_ptr->coef; + trxn_add(token_ptr->s->rxn, coef, TRUE); + repeat=TRUE; + break; + } + } + } + trxn_combine(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int rewrite_eqn_to_primary(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for secondary master species in terms of primary master species + * Store result in reaction structure for master species + * rewrite if necessary. + * + */ + int repeat, j, add_count; + +/* + * Check secondary master species + */ + repeat=TRUE; + add_count=0; +/* + * Check if reaction contains only primary master species + */ + while (repeat == TRUE) { + repeat=FALSE; +/* + * Check for too many iterations + */ + if (++add_count > MAX_ADD_EQUATIONS) { + parse_error++; + sprintf(error_string, "Could not reduce equation to primary master species, %s.", trxn.token[0].s->name); + error_msg(error_string, CONTINUE); + break; + } +/* + * Go through species in reaction for secondary master species, look for non-primary + * species as reactants, rewrite + */ + for (j=1; j < count_trxn; j++) { + if (trxn.token[j].s->primary == NULL) { + trxn_add(trxn.token[j].s->rxn, trxn.token[j].coef, TRUE); + repeat = TRUE; + break; + } + } + } + trxn_combine(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, n_user, last; + struct phase *phase_ptr; +/* + * Find all gases for each gas_phase in phase list + */ + for (i = 0; i < count_gas_phase; i++) { + if (gas_phase[i].new_def != TRUE) continue; + gas_phase[i].new_def = FALSE; + for (j=0; j < gas_phase[i].count_comps; j++) { + phase_ptr = phase_bsearch(gas_phase[i].comps[j].name, &k, FALSE); + if (phase_ptr == NULL) { + input_error++; + sprintf(error_string, "Gas not found in PHASES data base, %s.", gas_phase[i].comps[j].name); + error_msg(error_string, CONTINUE); + continue; + } else { + gas_phase[i].comps[j].phase = phase_ptr; + } +/* + * Fixed pressure + */ + if (gas_phase[i].type == PRESSURE) { + if (gas_phase[i].solution_equilibria == TRUE) { + input_error++; + sprintf(error_string, "Gas phase %d: can not use '-equilibrium' option with fixed pressure gas phase.", gas_phase[i].n_user); + error_msg(error_string, CONTINUE); + } + /* calculate moles */ + if (gas_phase[i].comps[j].p_read != NAN) { + gas_phase[i].comps[j].moles = gas_phase[i].comps[j].p_read * + gas_phase[i].volume/R_LITER_ATM/gas_phase[i].temperature; + } else { + input_error++; + sprintf(error_string, "Gas phase %d: partial pressure of gas component %s not defined.", gas_phase[i].n_user, gas_phase[i].comps[j].name); + error_msg(error_string, CONTINUE); + } + } else { +/* + * Fixed volume + */ + if (gas_phase[i].solution_equilibria == FALSE) { + if (gas_phase[i].comps[j].p_read != NAN) { + gas_phase[i].comps[j].moles = gas_phase[i].comps[j].p_read * gas_phase[i].volume/R_LITER_ATM/gas_phase[i].temperature; + } else { + input_error++; + sprintf(error_string, "Gas phase %d: moles of gas component %s not defined.", gas_phase[i].n_user, gas_phase[i].comps[j].name); + error_msg(error_string, CONTINUE); + } + } + } +/* + * Duplicate gas phase, only if not solution equilibria + */ + } + if (gas_phase[i].solution_equilibria == FALSE) { + n_user = gas_phase[i].n_user; + last = gas_phase[i].n_user_end; + gas_phase[i].n_user_end = gas_phase[i].n_user; + for (j = n_user + 1; j <= last; j++) { + gas_phase_duplicate(n_user, j); + } + } else { + gas_phase[i].new_def = TRUE; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_inverse(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * After all of data are read, fill in data for an inverse structure, + * including master species pointers, phase pointers, and uncertainties + * and a list of all elements from phases or -balance input. + */ + int i, j, k, l; + int count_in; + LDBLE value; + struct inv_elts *inv_elts; + struct master *master_ptr; + struct master *master_alk_ptr; + struct elt_list *elt_list_ptr; + master_alk_ptr = master_bsearch("Alkalinity"); + for (i = 0; i < count_inverse; i++) { + if (inverse[i].new_def != TRUE) continue; +/* + * Set default uncertainties for all solutions, if necessary + */ + if (inverse[i].count_uncertainties < inverse[i].count_solns) { + inverse[i].uncertainties = (LDBLE *)PHRQ_realloc(inverse[i].uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); + if (inverse[i].uncertainties == NULL) malloc_error(); + for (j = inverse[i].count_uncertainties; j < inverse[i].count_solns; j++) { + inverse[i].uncertainties[j] = inverse[i].uncertainties[inverse[i].count_uncertainties - 1]; + } + } +/* + * Set default ph uncertainties for all solutions, if necessary + */ + if (inverse[i].count_ph_uncertainties < inverse[i].count_solns) { + inverse[i].ph_uncertainties = (LDBLE *)PHRQ_realloc(inverse[i].ph_uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); + if ( inverse[i].ph_uncertainties == NULL) malloc_error(); + for (j = inverse[i].count_ph_uncertainties; j < inverse[i].count_solns; j++) { + inverse[i].ph_uncertainties[j] = inverse[i].ph_uncertainties[inverse[i].count_ph_uncertainties - 1]; + } + } +/* + * Set default force for all solutions + */ + if (inverse[i].count_force_solns < inverse[i].count_solns) { + inverse[i].force_solns = (int *) PHRQ_realloc(inverse[i].force_solns, (size_t) inverse[i].count_solns * sizeof (int)); + if (inverse[i].force_solns == NULL) malloc_error(); + for (j = inverse[i].count_force_solns; j < inverse[i].count_solns; j++) { + inverse[i].force_solns[j] = FALSE; + } + } +/* + * Find master species for element, set uncertainties + */ + for (j = 0; j < inverse[i].count_elts; j++) { + inverse[i].elts[j].master = master_bsearch_primary(inverse[i].elts[j].name); + if (inverse[i].elts[j].master == NULL) { + input_error++; + sprintf(error_string, "No master species for element, %s.", inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + inverse[i].elts[j].uncertainties = (double *) PHRQ_realloc(inverse[i].elts[j].uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); + if (inverse[i].elts[j].uncertainties == NULL) malloc_error(); + if (inverse[i].elts[j].count_uncertainties == 0) { +/* use default uncertainties for element */ + for (k=0; k < inverse[i].count_solns; k++) { + inverse[i].elts[j].uncertainties[k] = inverse[i].uncertainties[k]; + } + } else if (inverse[i].elts[j].count_uncertainties < inverse[i].count_solns) { +/* use input uncertainties, fill in any missing at end */ + value = inverse[i].elts[j].uncertainties[inverse[i].elts[j].count_uncertainties - 1]; + for (k=inverse[i].elts[j].count_uncertainties; k < inverse[i].count_solns; k++) { + inverse[i].elts[j].uncertainties[k] = value; + } + } + } +/* + * Find phase + */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < inverse[i].count_phases; j++) { + inverse[i].phases[j].phase = phase_bsearch(inverse[i].phases[j].name, &k, FALSE); + if (inverse[i].phases[j].phase == NULL) { + input_error++; + sprintf(error_string, "Could not find phase, %s.", inverse[i].phases[j].name); + error_msg(error_string, CONTINUE); + continue; + } +/* + * Find isotope elements + */ + if (inverse[i].phases[j].count_isotopes > 0) { + for (k = 0; k < inverse[i].phases[j].count_isotopes; k++) { + inverse[i].phases[j].isotopes[k].primary = NULL; + inverse[i].phases[j].isotopes[k].master = NULL; + master_ptr = master_bsearch(inverse[i].phases[j].isotopes[k].elt_name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Element not found for isotope calculation: %s.", + inverse[i].phases[j].isotopes[k].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary != TRUE) { + input_error++; + sprintf(error_string, "Isotope ratio may only be used" + " for total element in phase.\n" + "Secondary species not allowed: %s.", + master_ptr->elt->name); + error_msg(error_string, CONTINUE); + continue; + } + inverse[i].phases[j].isotopes[k].primary = master_ptr; + inverse[i].phases[j].isotopes[k].master = master_ptr; + /* find coefficient for element */ + for (elt_list_ptr=inverse[i].phases[j].phase->next_elt; + elt_list_ptr->elt != NULL; elt_list_ptr++) { + if (elt_list_ptr->elt == master_ptr->elt) { + inverse[i].phases[j].isotopes[k].coef = elt_list_ptr->coef; + break; + } + } + if (elt_list_ptr == NULL) { + input_error++; + sprintf(error_string, "Element, %s,for which isotope ratio was defined is not found in phase, %s", + master_ptr->elt->name, inverse[i].phases[j].phase->name); + error_msg(error_string, CONTINUE); + continue; + } + } + qsort (inverse[i].phases[j].isotopes, + (size_t) inverse[i].phases[j].count_isotopes, + (size_t) sizeof(struct isotope), + isotope_compare); + } + add_elt_list(inverse[i].phases[j].phase->next_elt, 1.0); + + } + if (input_error > 0) return(ERROR); +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } +/* + * Mark master species list + */ + for (j=0; j < count_master; j++) master[j]->in = FALSE; + for (j=0; j < count_elts; j++) { + elt_list[j].elt->master->in = TRUE; + } + /* Include all input elements */ + for (j = 0; j < inverse[i].count_elts; j++) { + inverse[i].elts[j].master->in = TRUE; + } + s_eminus->primary->in = TRUE; /* Include electrons */ + master_alk_ptr->in = TRUE; /* Include alkalinity */ +/* + * Unmark primary and mark secondary master species for redox elements + */ + count_in = 0; + inverse[i].count_redox_rxns = 0; + for (j=0; j < count_master; j++) { + /* skip all secondary master species in this loop */ + if (master[j]->primary == FALSE || master[j]->in == FALSE ) continue; + count_in++; + if (j+1 == count_master) continue; + /* if next master species is secondary, mark all + secondary master species until a primary is found */ + if (master[j+1]->primary == FALSE) { + master[j]->in = FALSE; + count_in--; + for (k=j+1; k < count_master; k++) { + if (master[k]->primary == FALSE) { + count_in++; + master[k]->in = TRUE; + if (master[k]->s->primary == NULL) { + inverse[i].count_redox_rxns++; + } + } else { + break; + } + } + } + } +/* + * Save list of master species in inv_elts structure + */ + inv_elts = (struct inv_elts *) PHRQ_malloc( (size_t) (count_in) * sizeof(struct inv_elts)); + if (inv_elts == NULL) malloc_error(); + count_in = 0; + for (j=0; j < count_master; j++) { + /* skip H(1) and O(-2) */ + if (master[j]->s == s_hplus || master[j]->s == s_h2o) continue; + if (master[j]->in == TRUE) { + /* set master */ + inv_elts[count_in].master = master[j]; + /* alloc uncertainties and set default */ + inv_elts[count_in].uncertainties = (double *) PHRQ_malloc((size_t) inverse[i].count_solns * sizeof(LDBLE)); + if (inv_elts[count_in].uncertainties == NULL) malloc_error(); + for(k=0; k < inverse[i].count_solns; k++) { + inv_elts[count_in].uncertainties[k] = inverse[i].uncertainties[k]; + } + count_in++; + } + } + if (s_co3->secondary->in == TRUE) { + inverse[i].carbon = TRUE; + } else { + inverse[i].carbon = FALSE; + } +/* + * copy in input uncertainties + */ + /* copy primary redox to all secondary redox */ + for (j=0; j < inverse[i].count_elts; j++) { + master_ptr = master_bsearch(inverse[i].elts[j].name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Element not found, %s.", inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary == FALSE || master_ptr->s->secondary == NULL) continue; + for (k=0; k < count_in; k++) { + if (master_ptr == inv_elts[k].master->elt->primary) { + for (l=0; l < inverse[i].count_solns; l++) { + inv_elts[k].uncertainties[l] = inverse[i].elts[j].uncertainties[l]; + } + } + } + inverse[i].elts[j].uncertainties = (double *) free_check_null(inverse[i].elts[j].uncertainties); + } + /* copy masters that are not primary redox */ + for (j=0; j < inverse[i].count_elts; j++) { + master_ptr = master_bsearch(inverse[i].elts[j].name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Element not found, %s.", inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL) continue; + for (k=0; k < count_in; k++) { + if (master_ptr == inv_elts[k].master) { + for(l=0; l < inverse[i].count_solns; l++) { + inv_elts[k].uncertainties[l] = inverse[i].elts[j].uncertainties[l]; + } + break; + } + } + inverse[i].elts[j].uncertainties = (double *) free_check_null(inverse[i].elts[j].uncertainties); + } +/* + * replace elts in inverse struct + */ + inverse[i].elts = (struct inv_elts *) free_check_null(inverse[i].elts); + inverse[i].elts = inv_elts; + inverse[i].count_elts = count_in; + for (j = 0; j < inverse[i].count_elts; j++) { +#ifdef SKIP +/* make another pointer alkalinity uncertainties */ + if (inverse[i].elts[j].master == master_alk_ptr) { + inverse[i].alk_uncertainties = free_check_null(inverse[i].alk_uncertainties); + inverse[i].alk_uncertainties = inverse[i].elts[j].uncertainties; + } +#endif +/* debug + output_msg(OUTPUT_MESSAGE, "\t%d\t%s", j, inverse[i].elts[j].master->elt->name); + for (k = 0; k < inverse[i].count_solns; k++) { + output_msg(OUTPUT_MESSAGE, "\t%f", inverse[i].elts[j].uncertainties[k]); + } + output_msg(OUTPUT_MESSAGE,"\n"); + */ + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_phases(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Rewrite all phases to secondary species + */ + for (i=0; i < count_phases; i++) { +/* + * Check equation + */ + if (phases[i]->check_equation == TRUE) { + phase_rxn_to_trxn(phases[i]); + if (check_eqn(FALSE) == ERROR) { + input_error++; + sprintf(error_string, "Equation for phase %s does not balance.", + phases[i]->name); + error_msg(error_string, CONTINUE); + } + } +/* + * Rewrite equation + */ + select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk); + add_other_logk(phases[i]->rxn->logk, phases[i]->count_add_logk, phases[i]->add_logk); + count_trxn=0; + trxn_add (phases[i]->rxn, 1.0, FALSE); + trxn_reverse_k(); + rewrite_eqn_to_secondary(); + trxn_reverse_k(); + rxn_free (phases[i]->rxn_s); + phases[i]->rxn_s = rxn_alloc(count_trxn+1); + trxn_copy (phases[i]->rxn_s); + /* debug + trxn_print(); + */ + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, l, n_user, first, last; + struct phase *phase_ptr; + LDBLE coef; + char *ptr; +/* + * Find pointers for pure phases + */ + for ( i = 0; i < count_pp_assemblage; i++) { + count_elts = 0; + paren_count = 0; + coef = 1.0; + pp_assemblage[i].new_def = FALSE; + for (j=0; j < pp_assemblage[i].count_comps; j++) { + phase_ptr = phase_bsearch(pp_assemblage[i].pure_phases[j].name, &k, FALSE); + if (phase_ptr == NULL) { + input_error++; + sprintf(error_string, "Phase not found in data base, %s.", pp_assemblage[i].pure_phases[j].name); + error_msg(error_string, CONTINUE); + continue; + } else { + pp_assemblage[i].pure_phases[j].phase = phase_ptr; + add_elt_list(phase_ptr->next_elt, coef); + + } + if (pp_assemblage[i].pure_phases[j].add_formula != NULL) { + first = count_elts; + phase_ptr = phase_bsearch(pp_assemblage[i].pure_phases[j].add_formula, &k, FALSE); + if (phase_ptr != NULL) { + pp_assemblage[i].pure_phases[j].add_formula = phase_ptr->formula; + } + ptr = pp_assemblage[i].pure_phases[j].add_formula; + get_elts_in_species(&ptr, coef); + /* check that all elements are in the database */ + for (l = first; l < count_elts; l++) { + if (elt_list[l].elt->master == NULL) { + input_error++; + sprintf(error_string, "Element \"%s\" in alternative phase for \"%s\" in EQUILIBRIUM_PHASES not found in database.", elt_list[l].elt->name, pp_assemblage[i].pure_phases[j].name); + error_msg(error_string, CONTINUE); + } + } + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine (); + } + pp_assemblage[i].next_elt = (struct elt_list *) free_check_null(pp_assemblage[i].next_elt); + pp_assemblage[i].next_elt = elt_list_save(); + +/* + * Store list with all elements in phases and add formulae + */ + +/* + * Duplicate pure phases if necessary + */ + if ( pp_assemblage[i].n_user_end > pp_assemblage[i].n_user ) { + n_user = pp_assemblage[i].n_user; + last = pp_assemblage[i].n_user_end; + pp_assemblage[i].n_user_end = pp_assemblage[i].n_user; + for (j = n_user + 1; j <= last; j++) { + pp_assemblage_duplicate(n_user, j); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_s_s_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, k1, n_user, last; + struct phase *phase_ptr; + struct s_s *s_s_ptr; + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, a0, a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE moles; +/* + * Find pointers for pure phases + */ + for ( i = 0; i < count_s_s_assemblage; i++) { + count_elts = 0; + paren_count = 0; + for (j=0; j < s_s_assemblage[i].count_s_s; j++) { + for (k=0; k < s_s_assemblage[i].s_s[j].count_comps; k++) { + phase_ptr = phase_bsearch(s_s_assemblage[i].s_s[j].comps[k].name, &k1, FALSE); + if (phase_ptr == NULL) { + input_error++; + sprintf(error_string, "Phase not found in data base, %s, assemblage %d.", s_s_assemblage[i].s_s[j].comps[k].name, s_s_assemblage[i].n_user); + error_msg(error_string, CONTINUE); + s_s_assemblage[i].s_s[j].comps[k].phase = NULL; + continue; + } else { + s_s_assemblage[i].s_s[j].comps[k].phase = phase_ptr; + s_s_assemblage[i].s_s[j].comps[k].phase->moles_x = 0; + s_s_assemblage[i].s_s[j].comps[k].phase->fraction_x = 0; + } + if (s_s_assemblage[i].s_s[j].comps[k].moles == NAN) { + input_error++; + sprintf(error_string, "Moles of solid solution component not defined, %s, assemblage %d.", s_s_assemblage[i].s_s[j].comps[k].name, s_s_assemblage[i].n_user); + error_msg(error_string, CONTINUE); + continue; + } + } + + if (s_s_assemblage[i].new_def == TRUE) { + /* + * Calculate a0 and a1 first + */ + s_s_calc_a0_a1(&(s_s_assemblage[i].s_s[j])); + s_s_ptr = &(s_s_assemblage[i].s_s[j]); + + n_tot = 0; + for (k = 0; k < s_s_ptr->count_comps; k++) { + moles = s_s_assemblage[i].s_s[j].comps[k].moles; + if (s_s_assemblage[i].s_s[j].comps[k].moles <= 0.0) { + moles = MIN_TOTAL; + s_s_assemblage[i].s_s[j].comps[k].initial_moles = moles; + } + n_tot += moles; + } + + for (k = 0; k < s_s_ptr->count_comps; k++) { + moles = s_s_assemblage[i].s_s[j].comps[k].moles; + if (s_s_assemblage[i].s_s[j].comps[k].moles <= 0.0) { + moles = MIN_TOTAL; + } + s_s_assemblage[i].s_s[j].comps[k].fraction_x = moles / n_tot; + s_s_assemblage[i].s_s[j].comps[k].log10_fraction_x = log10(moles / n_tot); + } + a0 = s_s_assemblage[i].s_s[j].a0; + a1 = s_s_assemblage[i].s_s[j].a1; + +/* + * Binary solid solution + */ + if (a0 != 0.0 || a1 != 0) { + s_s_assemblage[i].s_s[j].dn = 1.0 / n_tot; + nc = s_s_assemblage[i].s_s[j].comps[0].moles; + if (nc == 0) nc = MIN_TOTAL; + nb = s_s_assemblage[i].s_s[j].comps[1].moles; + if (nb == 0) nb = MIN_TOTAL; + xc = nc/n_tot; + xb = nb/n_tot; + + /* lambdas */ + s_s_assemblage[i].s_s[j].comps[0].log10_lambda = xb*xb*(a0 - a1*(3 -4*xb))/LOG_10; + s_s_assemblage[i].s_s[j].comps[1].log10_lambda = xc*xc*(a0 + a1*(4*xb - 1))/LOG_10; + + /* derivatives wrt nc and nb */ + xc2 = xc*xc; + xc3 = xc2*xc; + xb2 = xb*xb; + xb3 = xb2*xb; + xb4 = xb3*xb; + + /* component 1 */ + dnb = -2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 - 4*a1*xc*xb4 - 8*a1*xb3*xc2 - + 4*a1*xb2*xc3 - 2*a0*xc*xb2 - 8*a1*xc*xb3 + 6*a1*xc*xb2 + 1; + s_s_assemblage[i].s_s[j].comps[0].dnb = dnb/n_tot; + dnc = 2*a0*xb3 + 2*a0*xc*xb2 + 8*a1*xb4 + 8*a1*xc*xb3 - 2*a1*xb3 - 6*a1*xc*xb2; + s_s_assemblage[i].s_s[j].comps[0].dnc = - xb/nc + dnc/n_tot; + s_s_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; + + /* component 2*/ + dnb = 2*a0*xb*xc2 + 2*a0*xc3 + 8*a1*xb2*xc2 + 8*a1*xb*xc3 - 2*a1*xb*xc2 -6*a1*xc3; + s_s_assemblage[i].s_s[j].comps[1].dnb = -xc/nb + dnb/n_tot; + dnc = -2*a0*xc*xb2 - 8*a1*xc*xb3 + 2*a1*xc*xb2 - 2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 + 1; + s_s_assemblage[i].s_s[j].comps[1].dnc = dnc/n_tot; + s_s_prep(s_s_assemblage[i].s_s[j].tk, &(s_s_assemblage[i].s_s[j]), TRUE); + s_s_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; +/* + * Ideal solid solution + */ + } else { + s_s_assemblage[i].s_s[j].dn = 1.0 / n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) { + s_s_assemblage[i].s_s[j].comps[k].log10_lambda = 0; + moles = s_s_assemblage[i].s_s[j].comps[k].moles; + if (moles <= 0.0) moles = MIN_TOTAL; + s_s_assemblage[i].s_s[j].comps[k].dnb = (n_tot - moles)/(moles*n_tot); + s_s_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; + } + } + } + } + s_s_assemblage[i].new_def = FALSE; + +/* + * Duplicate s_s_assemblage if necessary + */ + n_user = s_s_assemblage[i].n_user; + last = s_s_assemblage[i].n_user_end; + s_s_assemblage[i].n_user_end = s_s_assemblage[i].n_user; + for (j = n_user + 1; j <= last; j++) { + s_s_assemblage_duplicate(n_user, j); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_punch(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l; + char token[MAX_LENGTH]; +/* + * tidy punch information + */ + if (punch.high_precision == FALSE) { + l = 12; + } else { + l = 20; + } + if (punch.in == TRUE && pr.punch == TRUE) { + /* totals */ + + for (i = 0; i < punch.count_totals; i++) { + punch.totals[i].master = master_bsearch(punch.totals[i].name); + } + + /* molalities */ + + for (i = 0; i < punch.count_molalities; i++) { + punch.molalities[i].s = s_search(punch.molalities[i].name); + } + + /* log activities */ + + for (i = 0; i < punch.count_activities; i++) { + punch.activities[i].s = s_search(punch.activities[i].name); + } + + /* equilibrium phases */ + + for (i = 0; i < punch.count_pure_phases; i++) { + punch.pure_phases[i].phase = phase_bsearch(punch.pure_phases[i].name, &j, FALSE); + } + + /* saturation indices */ + + for (i = 0; i < punch.count_si; i++) { + punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); + } + + /* gases */ + + for (i = 0; i < punch.count_gases; i++) { + punch.gases[i].phase = phase_bsearch(punch.gases[i].name, &j, FALSE); + } + } + if (punch.new_def == TRUE && punch.in == TRUE && pr.punch == TRUE) { + + /* constant stuff, sim, pH, etc. */ + + if (punch.sim == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "sim"); + } + if (punch.state == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "state"); + } + if (punch.soln == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "soln"); + } + if (punch.dist == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "dist_x"); + } + if (punch.time == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "time"); + } + if (punch.step == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "step"); + } + if (punch.ph == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "pH"); + } + if (punch.pe == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "pe"); + } + if (punch.rxn == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "reaction"); + } + if (punch.temp == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "temp"); + } + if (punch.alk == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "Alk"); + } + if (punch.mu == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "mu"); + } + if (punch.water == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "mass_H2O"); + } + if (punch.charge_balance == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "charge"); + } + if (punch.percent_error == TRUE) { + output_msg(OUTPUT_PUNCH, "%*s\t", l, "pct_err"); + } + /* totals */ + + for (i = 0; i < punch.count_totals; i++) { + output_msg(OUTPUT_PUNCH,"%*s\t", l, punch.totals[i].name); + if (punch.totals[i].master == NULL) { + sprintf(error_string, "Did not find master species," + " %s.", punch.totals[i].name); + warning_msg(error_string); + } + } + + /* molalities */ + + for (i = 0; i < punch.count_molalities; i++) { + strcpy(token,"m_"); + strcat(token, punch.molalities[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + if (punch.molalities[i].s == NULL) { + sprintf(error_string, "Did not find species," + " %s.", punch.molalities[i].name); + warning_msg(error_string); + } + } + + /* log activities */ + + for (i = 0; i < punch.count_activities; i++) { + strcpy(token,"la_"); + strcat(token, punch.activities[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + if (punch.activities[i].s == NULL) { + sprintf(error_string, "Did not find species, " + "%s.", punch.activities[i].name); + warning_msg(error_string); + } + } + + /* equilibrium phases */ + + for (i = 0; i < punch.count_pure_phases; i++) { + strcpy(token,"d_"); + strcat(token, punch.pure_phases[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t%*s\t", l, punch.pure_phases[i].name, l, token); + if (punch.pure_phases[i].phase == NULL) { + sprintf(error_string, "Did not find phase, " + "%s.", punch.pure_phases[i].name); + warning_msg(error_string); + } + } + + /* saturation indices */ + + for (i = 0; i < punch.count_si; i++) { + strcpy(token,"si_"); + strcat(token, punch.si[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + if (punch.si[i].phase == NULL) { + sprintf(error_string, "Did not find phase, " + "%s.", punch.si[i].name); + warning_msg(error_string); + } + } + + /* gases */ + + if (punch.count_gases > 0) { + output_msg(OUTPUT_PUNCH, "%*s\t%*s\t%*s\t", l, "pressure", l, "total mol", l, "volume"); + } + for (i = 0; i < punch.count_gases; i++) { + strcpy(token,"g_"); + strcat(token, punch.gases[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + if (punch.gases[i].phase == NULL) { + sprintf(error_string, "Did not find phase, " + "%s.", punch.gases[i].name); + warning_msg(error_string); + } + } + + /* kinetics */ + + for (i = 0; i < punch.count_kinetics; i++) { + strcpy(token,"k_"); + strcat(token, punch.kinetics[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + strcpy(token,"dk_"); + strcat(token, punch.kinetics[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + } + + /* solid solutions */ + + for (i = 0; i < punch.count_s_s; i++) { + strcpy(token,"s_"); + strcat(token, punch.s_s[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + } + + /* isotopes */ + + for (i = 0; i < punch.count_isotopes; i++) { + if (isotope_ratio_search(punch.isotopes[i].name) == NULL) { + sprintf(error_string, "Did not find isotope_ratio definition for " + "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", punch.isotopes[i].name, punch.isotopes[i].name); + warning_msg(error_string); + } + strcpy(token,"I_"); + strcat(token, punch.isotopes[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + } + + /* calculate_values */ + + for (i = 0; i < punch.count_calculate_values; i++) { + if (calculate_value_search(punch.calculate_values[i].name) == NULL) { + sprintf(error_string, "Did not find calculate_values definition for " + "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", punch.calculate_values[i].name, punch.calculate_values[i].name); + warning_msg(error_string); + } + strcpy(token,"V_"); + strcat(token, punch.calculate_values[i].name); + output_msg(OUTPUT_PUNCH,"%*s\t", l, token); + } + + /* user_punch */ + if (punch.user_punch == TRUE) { + for (i = 0; i < user_punch_count_headings; i++) { + output_msg(OUTPUT_PUNCH,"%*s\t", l, user_punch_headings[i]); + } + } + output_msg(OUTPUT_PUNCH,"\n"); + punch.new_def = FALSE; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_species(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + struct master *master_ptr; + char c, *ptr; +/* + * Make sure species pointers are ok + */ + if (check_species_input() == ERROR) { + error_msg("Calculations terminating due to input errors.", STOP); + } +/* + * Set secondary and primary pointers in species structures + */ + for (i=0; i < count_s; i++) { + s[i]->number = i; + s[i]->primary=NULL; + s[i]->secondary=NULL; + if (s[i]->check_equation == TRUE ) { + species_rxn_to_trxn(s[i]); + if (check_eqn(TRUE) == ERROR) { + input_error++; + sprintf(error_string, "Equation for species %s does not balance.", + s[i]->name); + error_msg(error_string, CONTINUE); + } + } + } + for (i=0; i < count_master; i++) { + ptr = master[i]->elt->name; + if (ptr[0] != '[') { + while ((c = (int) *(++ptr)) != '\0') { + if (isupper((int) c) ) { + input_error++; + sprintf(error_string, "Element or valence name in SOLUTION_MASTER_SPECIES should include only one element, %s.", master[i]->elt->name); + error_msg(error_string, CONTINUE); + break; + } + } + } + /* store sequence number in master structure */ + master[i]->number = i; + if (master[i]->primary == TRUE) { + master[i]->s->primary=master[i]; + } else { + master[i]->s->secondary=master[i]; + } + if (strcmp(master[i]->elt->name,"C") == 0) { + s_co3=master[i]->s; + } + if (master[i]->gfw_formula != NULL) { + if(compute_gfw(master[i]->gfw_formula, &master[i]->gfw) == ERROR){ + input_error++; + sprintf(error_string, "Calculating gfw for master species, %s, formula %s.", + master[i]->elt->name, master[i]->gfw_formula); + error_msg(error_string, CONTINUE); + } + } + } +/* + * Write equations for all master species in terms of primary + * master species, set coefficient of element in master species + */ + for (i=0; i < count_master; i++) { + count_trxn=0; + if ( master[i]->s->primary != NULL ) { + trxn_add(master[i]->s->rxn, 1.0, FALSE); + trxn_add(master[i]->s->rxn, -1.0, TRUE); + } else { + trxn_add(master[i]->s->rxn, 1.0, FALSE); + rewrite_eqn_to_primary(); + } + rxn_free(master[i]->rxn_primary); + master[i]->rxn_primary = rxn_alloc(count_trxn+1); + trxn_copy (master[i]->rxn_primary); + master[i]->coef = coef_in_master(master[i]); + } +/* + * Rewrite all species to secondary species + */ + for (i=0; i < count_s; i++) { + count_trxn=0; + if ( s[i]->primary != NULL || s[i]->secondary != NULL ) { + trxn_add (s[i]->rxn, 1.0, FALSE); + trxn_add (s[i]->rxn, -1.0, TRUE); + } else { + trxn_add (s[i]->rxn, 1.0, FALSE); + rewrite_eqn_to_secondary(); + } + rxn_free (s[i]->rxn_s); + s[i]->rxn_s = rxn_alloc(count_trxn+1); + trxn_copy (s[i]->rxn_s); + /* calculate alkalinity */ + s[i]->alk = calc_alk(s[i]->rxn_s); + /* set co2 coefficient */ + s[i]->co2 = 0.0; + for (j=1; j < count_trxn; j++) { + if (trxn.token[j].s == s_co3) { + s[i]->co2 = trxn.token[j].coef; + break; + } + } + } +/* + * Set pointer in element to master species + */ + for (i=0; i < count_elements; i++) { + elements[i]->master = master_bsearch(elements[i]->name); + if (elements[i]->master == NULL) { + input_error++; + sprintf(error_string, "No master species for element %s.", elements[i]->name); + error_msg(error_string, CONTINUE); + } + elements[i]->primary = master_bsearch_primary(elements[i]->name); + if (elements[i]->primary == NULL) { + input_error++; + sprintf(error_string, "No master species for element %s.", elements[i]->name); + error_msg(error_string, CONTINUE); + } + } +/* + * Make sure all primary master species for redox elements + * are also secondary master species + */ + for (i = 0; i < count_master; i++) { + if (master[i]->primary == FALSE) { + master_ptr = master[i]->s->secondary->elt->primary; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Every primary master species for a redox element\n" + "\tmust also be a secondary master species.\n" + "\tError in definitions related to %s .\n", + master[i]->s->name); + error_msg(error_string, CONTINUE); + + } else if (master_ptr->s->secondary == NULL) { + input_error++; + sprintf(error_string, "Every primary master species for a redox element\n" + "\tmust also be a secondary master species.\n" + "\t%s is the primary master species for element %s.\n" + "\tAnother entry in SOLUTION_MASTER_SPECIES is needed.\n" + "\tDefine species %s as a secondary master species for a valence state.\n" + "\tFor example: \n" + "\t%s(0)\t%s alk gfw", + master_ptr->s->name, master_ptr->elt->name, + master_ptr->s->name, master_ptr->elt->name, + master_ptr->s->name); + error_msg(error_string, CONTINUE); + } + } + } +/* + * Calculate H and O if alternate mass balance is given + */ + for (i = 0; i < count_s; i++) { + if (s[i]->next_secondary != NULL) { + s[i]->h = 0.0; + s[i]->o = 0.0; + for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) { + if (s[i]->next_secondary[j].elt->primary == NULL) continue; + if (s[i]->next_secondary[j].elt->primary->s == s_hplus) { + s[i]->h += s[i]->next_secondary[j].coef; + } else if (s[i]->next_secondary[j].elt->primary->s == s_h2o) { + s[i]->o += s[i]->next_secondary[j].coef; + } else if (s[i]->mole_balance != NULL) { + master_ptr = s[i]->next_secondary[j].elt->master; + if (master_ptr->primary == TRUE) { + if (master_ptr->s->secondary != NULL) { + master_ptr = master_ptr->s->secondary; + } + } + if (master_ptr->coef != 1) { + s[i]->next_secondary[j].coef /= master_ptr->coef; + } + } + } + if (s[i]->type == EX) { + for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) { + if (s[i]->next_secondary[j].elt->primary->s->type == EX) { + s[i]->equiv = s[i]->next_secondary[j].coef; + break; + } + } + } + } + } +#ifdef SKIP + for (i = 0; i < count_s; i++) { + if (match_elts_in_species(s[i]->name, "*{C,[13C]}{O,[18O]}3*") == TRUE) { + output_msg(OUTPUT_MESSAGE, "Match: %s\n", s[i]->name); + } + } +#endif + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * After all of data are read, fill in master species for surface comps + * Sort surface + */ + int i, j, k; + struct surface *surface_ptr; + struct master *master_ptr; + + for (k = 0; k < count_surface; k++) { + surface_ptr = &surface[k]; + for (i = 0; i < surface_ptr->count_comps; i++ ) { +/* + * Find master species for each surface, setup unknown structure + */ + for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) { + master_ptr = surface_ptr->comps[i].totals[j].elt->master; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Master species not in data base for %s, " + "skipping element.", surface_ptr->comps[i].totals[j].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) continue; +/* + * Set flags + */ + surface_ptr->comps[i].master = master_ptr; + break; + } + } +/* + * Sort components + */ + if (input_error == 0) { + qsort (surface[k].comps, + (size_t) surface_ptr->count_comps, + (size_t) sizeof(struct surface_comp), + surface_comp_compare); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_solutions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Define n_user for any solutions read by solution_spread that + * don't have n_user defined + */ + int i, l, n, last; + struct conc *tot_ptr; + char *ptr; + struct master *master_ptr; + char token[MAX_LENGTH]; + for (n=0; n < count_solution; n++) { + /* + * Check that elements are in database + */ + if (solution[n] != NULL && solution[n]->new_def == TRUE) { + /* + * Sort totals by description + */ + i = 0; + while(solution[n]->totals[i].description != NULL) i++; + qsort (solution[n]->totals, + (size_t) i, + (size_t) sizeof(struct conc), + conc_compare); + /* + * sort isotopes + */ + if (solution[n]->count_isotopes > 0) { + qsort (solution[n]->isotopes, + (size_t) solution[n]->count_isotopes, + (size_t) sizeof(struct isotope), + isotope_compare); + } else { + solution[n]->isotopes = (struct isotope *) free_check_null(solution[n]->isotopes); + } + for ( i=0; solution[n]->totals[i].description != NULL; i++) { + tot_ptr=&(solution[n]->totals[i]); + if (strcmp(tot_ptr->description,"H(1)") == 0 || + strcmp(tot_ptr->description,"E" ) == 0 ) { + tot_ptr->moles = 0.0; + continue; + } + ptr = tot_ptr->description; + copy_token(token, &ptr, &l); + master_ptr = master_bsearch (token); + if (master_ptr == NULL) { + sprintf(error_string, "Could not find element in database, %s.\n\tConcentration is set to zero.", tot_ptr->description); + warning_msg(error_string); + tot_ptr->input_conc = 0.0; + continue; + } + } + } + } + /* + * Calculate solution numbers + */ + for (n=0; n < count_solution; n++) { + if (solution[n] != NULL && solution[n]->new_def == TRUE && solution[n]->n_user < 0) { + last = 0; + for (i=0; i < count_solution; i++) { + if (solution[i]->n_user > last) last = solution[i]->n_user; + if (solution[i]->n_user_end > last) last = solution[i]->n_user_end; + } + if (save.solution == TRUE) { + if (save.n_solution_user > last) last = save.n_solution_user; + if (save.n_solution_user_end > last) last = save.n_solution_user_end; + } + for (i=0; i < count_solution; i++) { + if (solution[i]->new_def == TRUE && solution[i]->n_user < 0) { + solution[i]->n_user = ++last; + solution[i]->n_user_end = last; + if (use.solution_in == TRUE && use.n_solution_user == -1) { + use.n_solution_user = last; + } + } + } + break; + } + } + solution_sort(); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int species_rxn_to_trxn(struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copy reaction from reaction structure to + * temp reaction structure. + */ + int i; + + for (i = 0; s_ptr->rxn->token[i].s != NULL; i++) { + trxn.token[i].name = s_ptr->rxn->token[i].s->name; + trxn.token[i].z = s_ptr->rxn->token[i].s->z; + trxn.token[i].s = s_ptr->rxn->token[i].s; + trxn.token[i].unknown = NULL; + trxn.token[i].coef = s_ptr->rxn->token[i].coef; + count_trxn = i + 1; + if (count_trxn + 1 >= max_trxn) { + space ((void **) &(trxn.token), count_trxn+1, &max_trxn, + sizeof(struct rxn_token_temp)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int phase_rxn_to_trxn(struct phase *phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copy reaction from reaction structure to + * temp reaction structure. + */ + int i, l; + char *ptr; + char token[MAX_LENGTH]; + LDBLE z; + + trxn.token[0].name = phase_ptr->formula; + /* charge */ + ptr = phase_ptr->formula; + get_token ( &ptr, token, &z, &l); + trxn.token[0].z = z; + trxn.token[0].s = NULL; + trxn.token[0].unknown = NULL; + /*trxn.token[0].coef = -1.0;*/ + /* check for leading coefficient of 1.0 for phase did not work */ + trxn.token[0].coef = phase_ptr->rxn->token[0].coef; + for (i = 1; phase_ptr->rxn->token[i].s != NULL; i++) { + trxn.token[i].name = phase_ptr->rxn->token[i].s->name; + trxn.token[i].z = phase_ptr->rxn->token[i].s->z; + trxn.token[i].s = NULL; + trxn.token[i].unknown = NULL; + trxn.token[i].coef = phase_ptr->rxn->token[i].coef; + count_trxn = i + 1; + if (count_trxn + 1 >= max_trxn) { + space ((void **) &(trxn.token), count_trxn+1, &max_trxn, + sizeof(struct rxn_token_temp)); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_isotopes (void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Isotope ratios for each element or element valence state + */ + int i, j, k, l, n; + int count_isotopes, primary_number, count_primary; + LDBLE isotope_number; + struct master *master_ptr, *primary_ptr; + struct solution *solution_ptr; + struct isotope *new_isotopes; + struct isotope *primary_isotopes; + char token[MAX_LENGTH]; + + primary_number = 0; + primary_ptr = NULL; + for (n = 0; n < count_solution; n++) { + if (solution[n]->new_def != TRUE) continue; + if (solution[n]->count_isotopes == 0) continue; + solution_ptr = solution[n]; + primary_isotopes = (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); + if (primary_isotopes == NULL) malloc_error(); + count_primary = 0; + new_isotopes = (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); + if (new_isotopes == NULL) malloc_error(); + count_isotopes = 0; +/* + * Make list of primary master species for isotopes + */ + for (i = 0; i < solution_ptr->count_isotopes; i++) { + master_ptr = master_bsearch_primary(solution_ptr->isotopes[i].elt_name); + isotope_number = solution_ptr->isotopes[i].isotope_number; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "In isotope calculation: element not defined: %s.", + solution_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + for (j = 0; j < count_primary; j++) { + if (primary_isotopes[j].master == master_ptr && + primary_isotopes[j].isotope_number == isotope_number) break; + } + if (j == count_primary) { + primary_isotopes = (struct isotope *) PHRQ_realloc(primary_isotopes, (size_t) (count_primary + 1) * sizeof(struct isotope)); + if (primary_isotopes == NULL) malloc_error(); + primary_isotopes[count_primary].master = master_ptr; + primary_isotopes[count_primary].isotope_number = isotope_number; + count_primary++; + } + } + if (input_error > 0) return(ERROR); +/* + * Go through all redox states of the list of primary species and isotope number + */ + for (j = 0; j < count_primary; j++) { + + /* find index number of master species, set flag to FALSE */ + master_ptr = primary_isotopes[j].master; + isotope_number = primary_isotopes[j].isotope_number; + for (k = 0; k < count_master; k++) { + if (master[k] == master_ptr) { + primary_number = k; + primary_ptr = master[k]; + } + master[k]->isotope = FALSE; + } + + /* go through isotopes of solution and fill in master species */ + for (l = 0; l < solution_ptr->count_isotopes; l++) { + master_ptr = master_bsearch(solution_ptr->isotopes[l].elt_name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "In isotope calculation: element not defined: %s.", + solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + + /* only fill for pertinent isotope */ + if (master_ptr->elt->primary != primary_ptr) continue; + if (solution_ptr->isotopes[l].isotope_number != isotope_number) continue; + + /* for primary, fill in ratio for all secondary species */ + if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL ) { + for (k = primary_number + 1; k < count_master; k++) { + if (master[k]->elt->primary != primary_ptr) break; + master[k]->isotope_ratio = solution_ptr->isotopes[l].ratio; + master[k]->isotope_ratio_uncertainty = solution_ptr->isotopes[l].ratio_uncertainty; + if (master[k]->isotope == TRUE) { + sprintf(error_string, "In isotope calculation: redefinition of isotope ratio for %s.", solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + } + master[k]->isotope = TRUE; + } + + /* for secondary and non redox, set ratio */ + } else { + master_ptr->isotope_ratio = solution_ptr->isotopes[l].ratio; + master_ptr->isotope_ratio_uncertainty = solution_ptr->isotopes[l].ratio_uncertainty; + if (master_ptr->isotope == TRUE) { + sprintf(error_string, "In isotope calculation: redefinition of isotope ratio for %s.", solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + } + master_ptr->isotope = TRUE; + } + } +/* + * Write new isotope structure + */ + for (k = 0; k < count_master; k++) { + /* skip primary master species of redox elements */ + if (master[k]->primary == TRUE && + master[k]->s->secondary != NULL) continue; + if (master[k]->elt->primary == primary_ptr && master[k]->isotope == FALSE) { + input_error++; + sprintf(error_string, "Isotopic ratio not defined for element or valence state %g%s.", (double) isotope_number, master[k]->elt->name); + error_msg(error_string, CONTINUE); + } + if (master[k]->isotope == FALSE) continue; + new_isotopes = (struct isotope *) PHRQ_realloc(new_isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); + if (new_isotopes == NULL) malloc_error(); + new_isotopes[count_isotopes].master = master[k]; + new_isotopes[count_isotopes].primary = primary_ptr; + new_isotopes[count_isotopes].isotope_number = isotope_number; + new_isotopes[count_isotopes].elt_name = master[k]->elt->name; + new_isotopes[count_isotopes].total = 0; + new_isotopes[count_isotopes].ratio = master[k]->isotope_ratio; + new_isotopes[count_isotopes].ratio_uncertainty = master[k]->isotope_ratio_uncertainty; + sprintf(token,"%d%s", (int) isotope_number, master[k]->elt->name); + new_isotopes[count_isotopes].isotope_name = string_hsave(token); + count_isotopes++; + } + } + primary_isotopes = (struct isotope *) free_check_null(primary_isotopes); + solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); + solution_ptr->isotopes = new_isotopes; + solution_ptr->count_isotopes = count_isotopes; + qsort (solution_ptr->isotopes, + (size_t) count_isotopes, + (size_t) sizeof(struct isotope), + isotope_compare); + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_kin_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + int i, j, k, n; + struct kinetics *kinetics_ptr; + struct exch_comp *comp_ptr; + struct master *master_ptr; + char *ptr; + LDBLE conc; + + for (i=0; i < count_exchange; i++) { + if (exchange[i].new_def == FALSE) continue; + if (exchange[i].n_user < 0) continue; + for (j = 0; j < exchange[i].count_comps; j++) { + if (exchange[i].comps[j].rate_name == NULL) continue; + comp_ptr = &exchange[i].comps[j]; + comp_ptr->master = NULL; + n = exchange[i].n_user; + + /* First find exchange master species */ + + for (k=0; comp_ptr->totals[k].elt != NULL; k++) { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != EX) continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) { + input_error++; + sprintf(error_string, "Exchange formula does not contain an exchange master species, %s", comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find associated kinetic reaction ... */ + if ((kinetics_ptr=kinetics_bsearch(n, &k)) == NULL) { + input_error++; + sprintf(error_string, "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k=0; kcount_comps; k++) { + if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { + break; + } + } + if (k == kinetics_ptr->count_comps) { + input_error++; + sprintf(error_string,"Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", comp_ptr->rate_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + + /* use database name for phase */ + comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; + + /* make exchanger concentration proportional to mineral ... */ + conc=kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; + + count_elts = 0; + paren_count = 0; + ptr = comp_ptr->formula; + get_elts_in_species(&ptr, conc); + comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); +/* + * No check on availability of exchange elements + */ + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_min_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + int i, j, k, n, jj; + struct pp_assemblage *pp_a_ptr; + struct exch_comp *comp_ptr; + struct master *master_ptr; + char *ptr; + LDBLE conc; + + for (i=0; i < count_exchange; i++) { + if (exchange[i].new_def == FALSE) continue; + if (exchange[i].n_user < 0) continue; + for (j = 0; j < exchange[i].count_comps; j++) { + if (exchange[i].comps[j].phase_name == NULL) continue; + comp_ptr = &exchange[i].comps[j]; + comp_ptr->master = NULL; + n = exchange[i].n_user; + + /* First find exchange master species */ + + for (k=0; comp_ptr->totals[k].elt != NULL; k++) { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != EX) continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) { + input_error++; + sprintf(error_string, "Exchange formula does not contain an exchange master species, %s", comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the mineral on which exchanger depends... */ + if ((pp_a_ptr=pp_assemblage_bsearch(n, &k)) == NULL) { + input_error++; + sprintf(error_string, "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k=0; kcount_comps; k++) { + if (strcmp_nocase(comp_ptr->phase_name, pp_a_ptr->pure_phases[k].name) == 0) { + break; + } + } + if (k == pp_a_ptr->count_comps) { + input_error++; + sprintf(error_string,"Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", comp_ptr->phase_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + /* use database name for phase */ + comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; + /* make exchanger concentration proportional to mineral ... */ + conc=pp_a_ptr->pure_phases[k].moles * comp_ptr->phase_proportion; + count_elts = 0; + paren_count = 0; + ptr = comp_ptr->formula; + get_elts_in_species(&ptr, conc); + comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); +/* + * make sure exchange elements are in phase + */ + count_elts = 0; + paren_count = 0; + ptr = comp_ptr->formula; + get_elts_in_species(&ptr, -comp_ptr->phase_proportion); + ptr = pp_a_ptr->pure_phases[k].phase->formula; + get_elts_in_species(&ptr, 1.0); + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + for (jj = 0; jj < count_elts; jj++) { + if (elt_list[jj].elt->primary->s->type != EX && elt_list[jj].coef < 0) { + input_error++; + sprintf(error_string,"Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", comp_ptr->formula, (double) comp_ptr->phase_proportion, pp_a_ptr->pure_phases[k].phase->name, pp_a_ptr->pure_phases[k].phase->formula); + error_msg(error_string, CONTINUE); + break; + } + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_min_surface(void) +/* ---------------------------------------------------------------------- */ +/* + * If surface is related to mineral, surface amount is + * set in proportion + */ +{ + int i, j, k, n, jj; + struct pp_assemblage *pp_a_ptr; + struct surface_comp *comp_ptr; + struct master *master_ptr; + char *ptr; + LDBLE conc; + + for (i=0; i < count_surface; i++) { + if (surface[i].new_def == FALSE) continue; + if (surface[i].n_user < 0) continue; + for (j = 0; j < surface[i].count_comps; j++) { + if (surface[i].comps[j].phase_name == NULL) continue; + comp_ptr = &surface[i].comps[j]; + comp_ptr->master = NULL; + n = surface[i].n_user; + + /* First find surface master species */ + + for (k=0; comp_ptr->totals[k].elt != NULL; k++) { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) { + input_error++; + sprintf(error_string, "Surface formula does not contain a surface master species, %s", comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the mineral on which surface depends... */ + if ((pp_a_ptr=pp_assemblage_bsearch(n, &k)) == NULL) { + input_error++; + sprintf(error_string, "Equilibrium_phases %d must be defined to use surface related to mineral phase, %s", n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k=0; kcount_comps; k++) { + if (strcmp_nocase(comp_ptr->phase_name, pp_a_ptr->pure_phases[k].name) == 0) { + break; + } + } + if (k == pp_a_ptr->count_comps) { + input_error++; + sprintf(error_string,"Mineral, %s, related to surface, %s, not found in Equilibrium_Phases %d", comp_ptr->phase_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + if (pp_a_ptr->pure_phases[k].phase == NULL) { + input_error++; + sprintf(error_string,"Mineral, %s, related to surface, %s, not found in database.", pp_a_ptr->pure_phases[k].name, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + /* use database name for phase */ + comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; + /* make surface concentration proportional to mineral ... */ + conc=pp_a_ptr->pure_phases[k].moles * comp_ptr->phase_proportion; +/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ + ptr = comp_ptr->formula; + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, conc); + comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); + + /* area */ + surface[i].charge[comp_ptr->charge].grams = pp_a_ptr->pure_phases[k].moles; +/* + * make sure surface elements are in phase + */ + count_elts = 0; + paren_count = 0; + ptr = pp_a_ptr->pure_phases[k].phase->formula; + get_elts_in_species(&ptr, 1.0); + for (jj = 0; jj < surface[i].count_comps; jj++) { + if (comp_ptr->charge != surface[i].comps[jj].charge) continue; + if (surface[i].comps[jj].master->s->z != 0.0) { + input_error++; + sprintf(error_string, "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", surface[i].comps[jj].master->s->name); + error_msg(error_string, CONTINUE); + } + ptr = surface[i].comps[jj].master->s->name; + get_elts_in_species(&ptr, -surface[i].comps[jj].phase_proportion); + } + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); +/* Makes no sense: sorbed species need not be in mineral structure... */ +/* For example, if master species is SurfOH, then increasing the amount of surface + * adds SurfOH to the system, the OH must then come from phase, + * otherwise, O and H are not conserved + */ + for (jj = 0; jj < count_elts; jj++) { + if (elt_list[jj].elt->primary->s->type != SURF && elt_list[jj].coef < 0) { + input_error++; + sprintf(error_string,"Element %s in sum of surface sites,\n" + "\tincluding %s * %g mol sites/mol phase,\n" + "\texceeds stoichiometry in the related phase %s, %s.", + elt_list[jj].elt->name, + comp_ptr->master->s->name, + (double) comp_ptr->phase_proportion, + pp_a_ptr->pure_phases[k].phase->name, + pp_a_ptr->pure_phases[k].phase->formula); + error_msg(error_string, CONTINUE); + break; + } + } + + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_kin_surface(void) +/* ---------------------------------------------------------------------- */ +/* + * If surface is related to mineral, surface amount is + * set in proportion + */ +{ + int i, j, k, n, jj, l; + struct kinetics *kinetics_ptr; + struct surface_comp *comp_ptr; + struct master *master_ptr; + struct phase *phase_ptr; + char token[MAX_LENGTH]; + char *ptr; + LDBLE conc; + struct elt_list *elt_list_kinetics; + int count_elts_kinetics; + + n = -999; + comp_ptr = NULL; + for (i=0; i < count_surface; i++) { + if (surface[i].new_def == FALSE) continue; + if (surface[i].n_user < 0) continue; + for (j = 0; j < surface[i].count_comps; j++) { + if (surface[i].comps[j].rate_name == NULL) continue; + comp_ptr = &surface[i].comps[j]; + comp_ptr->master = NULL; + n = surface[i].n_user; + + /* First find surface master species */ + + for (k=0; comp_ptr->totals[k].elt != NULL; k++) { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) { + input_error++; + sprintf(error_string, "Surface formula does not contain a surface master species, %s", comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the kinetic reaction on which surface depends... */ + if ((kinetics_ptr=kinetics_bsearch(n, &k)) == NULL) { + input_error++; + sprintf(error_string, "Kinetics %d must be defined to use surface related to kinetic reaction, %s", n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k=0; kcount_comps; k++) { + if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { + break; + } + } + if (k == kinetics_ptr->count_comps) { + input_error++; + sprintf(error_string,"Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", comp_ptr->rate_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + + /* use database name for phase */ + comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; + + /* make surface concentration proportional to mineral ... */ + conc=kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; + +/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ + ptr = comp_ptr->formula; + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, conc); + comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); + + /* area */ + surface[i].charge[comp_ptr->charge].grams = kinetics_ptr->comps[k].m; + } +/* + * check on elements + */ + /* Go through each kinetic reaction, add all related surface compositions + * check for negative values + */ + if (surface[i].related_rate == FALSE) continue; + kinetics_ptr=kinetics_bsearch(n, &k); + for (k=0; k < kinetics_ptr->count_comps; k++) { + count_elts = 0; + paren_count = 0; + + /* added in kinetics formula */ + for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) { + phase_ptr = NULL; + strcpy(token, kinetics_ptr->comps[k].list[j].name); + phase_ptr = phase_bsearch(token, &jj, FALSE); + if (phase_ptr != NULL) { + add_elt_list(phase_ptr->next_elt, 1.0); + } else { + ptr = kinetics_ptr->comps[k].list[j].name; + get_elts_in_species (&ptr, kinetics_ptr->comps[k].list[j].coef); + } + } + /* save kinetics formula */ + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + elt_list_kinetics = elt_list_save(); + count_elts_kinetics = count_elts; + + /* get surface formulas */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < surface[i].count_comps; j++) { + comp_ptr = &surface[i].comps[j]; + if (comp_ptr->rate_name == NULL) continue; + if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { + ptr = comp_ptr->formula; + get_elts_in_species(&ptr, -1 * comp_ptr->phase_proportion); + } + } + if (count_elts > 0 ) { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) { + if (elt_list[j].elt->primary->s->type <= H2O) { + for (l = 0; l < count_elts_kinetics; l++) { + if (elt_list[j].elt == elt_list_kinetics[l].elt) { + break; + } + } + if (l == count_elts_kinetics) { + input_error++; + sprintf(error_string,"Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", comp_ptr->formula, (double) comp_ptr->phase_proportion, comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } else if (fabs(elt_list[j].coef) > fabs(elt_list_kinetics[l].coef)) { + input_error++; + sprintf(error_string,"Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", comp_ptr->formula, (double) comp_ptr->phase_proportion, comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } + } + } + elt_list_kinetics = (struct elt_list *) free_check_null(elt_list_kinetics); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, converged, divisions; + LDBLE r, rt, ag0, ag1, crit_pt; + LDBLE xc, tc; + LDBLE x, x0, x1, xsm1, xsm2, xb1, xb2; + LDBLE xc1, xc2; + LDBLE facb1, faca1, spim1, xblm1, acrae, acrael, xliapt, xliapm; + LDBLE xaly, xaly1, xaly2; + LDBLE faca, facb, spialy, facal, facbl; + LDBLE tol; + + if (pr.s_s_assemblage == FALSE) print = FALSE; + tol = 1e-6; + r = R_KJ_DEG_MOL; + rt = r * t; + a0 = s_s_ptr->ag0 / rt; + a1 = s_s_ptr->ag1 / rt; + s_s_ptr->a0 = a0; + s_s_ptr->a1 = a1; + ag0 = a0*rt; + ag1 = a1*rt; + kc = exp( k_calc(s_s_ptr->comps[0].phase->rxn->logk, t) * LOG_10); + kb = exp( k_calc(s_s_ptr->comps[1].phase->rxn->logk, t) * LOG_10); + crit_pt = fabs(a0) + fabs(a1); +/* + * Default, no miscibility or spinodal gaps + */ + s_s_ptr->miscibility = FALSE; + s_s_ptr->spinodal = FALSE; + xsm1 = 0.5; + xsm2 = 0.5; + xb1 = 0.5; + xb2 = 0.5; + xc1 = 0; + xc2 = 0; + + if (crit_pt >= tol) { +/* + * Miscibility gap information + */ + if (fabs(a1) < tol) { + xc = 0.5; + tc = ag0/(2*r); + } else { + xc = 0.5 + (pow((ag0*ag0 + 27*ag1*ag1), 0.5) - ag0) / (18*ag1); + tc = (12*ag1*xc - 6*ag1 + 2*ag0) * (xc - xc*xc)/r; + } + if (print == TRUE) { + sprintf(error_string,"Description of Solid Solution %s", s_s_ptr->name); + dup_print(error_string, TRUE); + } + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t Temperature: %g kelvin\n", (double) t); + output_msg(OUTPUT_MESSAGE,"\t A0 (dimensionless): %g\n", (double) a0); + output_msg(OUTPUT_MESSAGE,"\t A1 (dimensionless): %g\n", (double) a1); + output_msg(OUTPUT_MESSAGE,"\t A0 (kJ/mol): %g\n", (double) ag0); + output_msg(OUTPUT_MESSAGE,"\t A1 (kJ/mol): %g\n\n", (double) ag1); + } + if (xc < 0 || xc > 1) { + if (print == TRUE) output_msg(OUTPUT_MESSAGE,"No miscibility gap above 0 degrees kelvin.\n"); + } else { + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t Critical mole-fraction of component 2: %g\n", (double) xc); + output_msg(OUTPUT_MESSAGE,"\t Critical temperature: %g kelvin\n", (double) tc); + output_msg(OUTPUT_MESSAGE,"\n(The critical temperature calculation assumes that the Guggenheim model\ndefined at %g kelvin is valid at the critical temperature.)\n\n\n", (double) t); + } + } +/* + * Calculate miscibility and spinodal gaps + */ + if (tc >= t) { + + /* search for sign changes */ + x0 = 0; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) { + + /* find first spinodal pt */ + xsm1 = halve(f_spinodal, x0, x1, tol); + s_s_ptr->spinodal = TRUE; + + /* find second spinodal pt */ + x0 = x1; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) { + xsm2 = halve(f_spinodal, x0, x1, tol); + } else { + error_msg("Failed to find second spinodal point.", STOP); + } + } + } + } +/* + * Now find Miscibility gap + */ + if (s_s_ptr->spinodal == TRUE) { + if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\t Spinodal-gap mole fractions, component 2: %g\t%g\n", (double) xsm1, (double) xsm2); + converged = FALSE; + if (converged == FALSE) { + for (i = 1; i < 3; i++) { + divisions = (int) pow(10.,i); + for (j = 0; j < divisions; j++) { + for (k = divisions; k > 0; k--) { + xc1 = (LDBLE) j / divisions + 0.001; + xc2 = (LDBLE) k / divisions; + converged = solve_misc(&xc1, &xc2, tol); + if (converged == TRUE) break; + } + if (converged == TRUE) break; + } + if (converged == TRUE) break; + } + } + if (converged == FALSE) { + error_msg("Failed to find miscibility gap.", STOP); + } + s_s_ptr->miscibility = TRUE; + if (xc1 < xc2) { + xb1 = 1 - xc2; + xb2 = 1 - xc1; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + } else { + xb1 = 1 - xc1; + xb2 = 1 - xc2; + } + facb1 = kb*xb1*exp(xc1*xc1*(a0 + a1*(4*xb1 -1))); + faca1 = kc*xc1*exp(xb1*xb1*(a0 - a1*(3-4*xb1))); + spim1 = log10(faca1 + facb1); + xblm1 = 1./(1. + faca1/facb1); + acrae = facb1/faca1; + acrael = log10(acrae); + xliapt = log10(facb1); + xliapm = log10(faca1); + + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE, "\t Miscibility-gap fractions, component 2: %g\t%g\n", (double) xb1, (double) xb2); + output_msg(OUTPUT_MESSAGE, "\n\t\t\tEutectic Point Calculations\n\n"); + output_msg(OUTPUT_MESSAGE, "\t Aqueous activity ratio (comp2/comp1): %g\n", (double) acrae); + output_msg(OUTPUT_MESSAGE, "\t Log aqueous activity ratio (comp2/comp1): %g\n", (double) acrael); + output_msg(OUTPUT_MESSAGE, "\t Aqueous activity fraction of component 2: %g\n", (double) xblm1); + output_msg(OUTPUT_MESSAGE, "\t Log IAP (component 2): %g\n", (double) xliapt); + output_msg(OUTPUT_MESSAGE, "\t Log IAP (component 1): %g\n", (double) xliapm); + output_msg(OUTPUT_MESSAGE, "\t Log Sum Pi: %g\n", (double) spim1); + } + s_s_ptr->tk = t; + s_s_ptr->xb1 = xb1; + s_s_ptr->xb2 = xb2; + } +/* + * Alyotropic point calculation + */ + xaly = -1.0; + x = a0*a0 + 3*a1*a1 + 6*a1*log(kb/kc); + if (x > 0) { + if (fabs(x - a0*a0) >= tol) { + xaly1 = (-(a0 - 3*a1) + pow(x, 0.5)) / (6*a1); + xaly2 = (-(a0 - 3*a1) - pow(x, 0.5)) / (6*a1); + if (xaly1 >= 0 && xaly1 <= 1) { + xaly = xaly1; + } + if (xaly2 >= 0 && xaly2 <= 1) { + xaly = xaly2; + } + } else { + xaly = 0.5 + log(kb/kc) / (2*a0); + } + if (xaly > 0 && xaly < 1) { + faca = kc * (1 - xaly) * exp(xaly*xaly*(a0 - a1 * (3 - 4*xaly))); + facb = kb * xaly * exp((1 - xaly)*(1 - xaly)*(a0 + a1 * (4*xaly - 1.0))); + spialy = log10(faca + facb); + facal = log10(faca); + facbl = log10(facb); + if (xaly > xb1 && xaly < xb2) { + if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\nLocal minimum in the solidus curve coresponding to a maximum\nin the minimum stoichiometric saturation curve.\n\n"); + } else { + if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\n\t\t\tAlyotropic Point\n\n"); + } + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE,"\t Solid mole fraction of component 2: %g\n", (double) xaly); + output_msg(OUTPUT_MESSAGE,"\t Log IAP (component 2): %g\n", (double) facbl); + output_msg(OUTPUT_MESSAGE,"\t Log IAP (component 1): %g\n", (double) facal); + output_msg(OUTPUT_MESSAGE,"\t Log Sum Pi: %g\n", (double) spialy); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +static LDBLE halve(LDBLE f(LDBLE x), LDBLE x0, LDBLE x1, LDBLE tol) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE x, y, y0, dx; + + y0 = f(x0); + dx = (x1 - x0); +/* + * Loop for interval halving + */ + for (i = 0; i < 100; i++) { + dx *= 0.5; + x = x0 + dx; + y = f( x); + if (dx < tol || y == 0) { + break; + } +#ifdef SKIP + if (y0*y < 0) { + x1 = x; + } else { + x0 = x; + y0 = y; + } +#endif + if (y0*y >= 0) { + x0 = x; + y0 = y; + } + } + return(x0 + dx); +} +/* ---------------------------------------------------------------------- */ +static int scan(LDBLE f(LDBLE x), LDBLE *xx0, LDBLE *xx1) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE fx0, fx1, divisions; + LDBLE x0, x1, diff; + + x0 = *xx0; + x1 = *xx1; + diff = x1 - x0; + for (j = 0; j < 3; j++) { + fx0 = f(x0); + divisions = (int) pow(10, j); + for (i = 1; i < divisions; i++) { + x1 = *xx0 + diff * (LDBLE) i / divisions; + fx1 = f(x1); + if (fx0 * fx1 <= 0) { + *xx0 = x0; + *xx1 = x1; + return (TRUE); + } + x0 = x1; + fx0 = fx1; + } + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +static LDBLE f_spinodal(LDBLE x) +/* ---------------------------------------------------------------------- */ +{ + LDBLE fx; + fx = -12*a1*x*x*x + (18*a1 - 2*a0)*x*x + (2*a0 - 6*a1)*x - 1.0; + return(fx); +} +/* ---------------------------------------------------------------------- */ +int slnq (int n, LDBLE *a, LDBLE *delta, int ncols, int print) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, m; +/* debug + */ + int row; + + LDBLE b; +/* Debug +*/ + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nArray in slnq: \n\n"); + for (i=0; i < ncols - 1; i++) { + row=i*(n+1); + for (j=0; j < ncols; j++) { + output_msg(OUTPUT_MESSAGE,"%10.2e",(double) a[row+j]); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + output_msg(OUTPUT_MESSAGE,"\n"); + } + + if (n == 0) return(OK); +/* Trivial case */ + if (n == 1) { + if ( fabs(a[0]) < ZERO_TOL) goto slnq_error; + delta[0]=a[1]/a[0]; + return(OK); + } + +/* Reduction loop */ + for (i=0; i < n-1; i++) { + b=fabs(a[i*ncols + i]); + m=i; + +/* Find maximum value in column */ + for ( j=i+1; j < n; j++) { + if (fabs(a[j*ncols + i]) > b) { + b=fabs(a[j*ncols + i]); + m=j; + } + } + +/* Check for singularity */ + if ( b < ZERO_TOL ) goto slnq_error; + +/* Exchange rows if necessary */ + if (m != i) { + for ( j=i; j <= n; j++ ) { + b=a[i*ncols + j]; + a[i*ncols + j]=a[m*ncols + j]; + a[m*ncols + j]=b; + } + } + +/* Make a[i][i]=1.0 */ + for (j=n; j >= i; j--) { + a[i*ncols + j] /= a[i*ncols + i]; + } + +/* Reduction step */ + for (j=i+1; j < n; j++) { + if (a[j*ncols + i] == 0.0) continue; + b=-a[j*ncols + i]; + for (k=i+1; k <= n ; k++) { + a[j*ncols + k] += b*a[i*ncols + k]; + } + } + } + +/* Calculation of delta[n] */ + if (fabs(a[(n-1)*ncols + n-1]) > ZERO_TOL) { + delta[n-1]=a[(n-1)*ncols + n]/a[(n-1)*ncols + n - 1]; + } else { + output_msg(OUTPUT_MESSAGE,"Error: Divide by zero in slnq.\n"); + delta[n]=0.0; + goto slnq_error; + } + +/* Back substitution for other delta values */ + for (i=n-2; i>=0; i--) { + delta[i]=a[i*ncols + n]; + for (j = i+1; j < n; j++) { + delta[i] -= a[i*ncols + j]*delta[j]; + } + } + if (print == TRUE) { + output_msg(OUTPUT_MESSAGE,"\nResults from slnq: \n\n"); + for (i=0; i 1 || x1 < 0 || x2 > 1 || x2 < 0) { + d[0] *= 0.5; + d[1] *= 0.5; + } else { + repeat = FALSE; + } + }; + xc1 = x1; + xc2 = x2; + + if (fabs(xc1 - xc2) < .01) { + converged = FALSE; + break; + } + } + if (i == max_iter) converged = FALSE; + *xxc1 = xc1; + *xxc2 = xc2; + return(converged); +} +/* ---------------------------------------------------------------------- */ +static int s_s_calc_a0_a1(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, done; + LDBLE r, rt, *p; + LDBLE q1, q2, xbq1, xbq2, xb1, xb2, xc1, xc2; + LDBLE r1, r2, pa1, pb1, pa2, pb2, xsm1, xsm2; + LDBLE pn9, pn10, c5, c6, pl9, pl10, pj9, pj10; + LDBLE xc, tc; + LDBLE spialy, azero, phi1, phi2, test; + LDBLE dq1, dq2, denom, ratio, dr1, dr2, x21, x22, x61, x62; + LDBLE a0, a1, ag0, ag1; + LDBLE wg2, wg1, alpha2, alpha3; + LDBLE kc, kb; + LDBLE xaly, xcaly, alpha0, alpha1, fx, fx1; + LDBLE tol; + + tol = 1e-6; + rt = s_s_ptr->tk * R_KJ_DEG_MOL; + if (s_s_ptr->comps[0].phase == NULL || s_s_ptr->comps[1].phase == NULL) { + input_error++; + sprintf(error_string, "Two components were not defined for %s solid solution", s_s_ptr->name); + error_msg(error_string, CONTINUE); + return(ERROR); + } + kc = exp( k_calc(s_s_ptr->comps[0].phase->rxn->logk, s_s_ptr->tk) * LOG_10); + kb = exp( k_calc(s_s_ptr->comps[1].phase->rxn->logk, s_s_ptr->tk) * LOG_10); + + p = s_s_ptr->p; + + a0 = 0; + a1 = 0; + ag0 = 0; + ag1 = 0; + dq2 = 0; + switch (s_s_ptr->input_case) { + /* + * dimensionless a0 and a1 + */ + case 0: + a0 = p[0]; + a1 = p[1]; + ag0 = a0*rt; + ag1 = a1*rt; + break; + /* + * two activity coefficients + * q1, q2, xbq1, xbq2 + */ + case 1: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + done = FALSE; + if (fabs(1 - xbq1) > 0 && q1 > 0) { + dq1 = log(q1)/ ((1 - xbq1)*(1 - xbq1)); + if (xbq2 <= 0 || xbq2 > 1) { + a0 = dq1; + a1 = 0; + done = TRUE; + } + } + if (done == FALSE) { + if (fabs(xbq2) < 0 || q2 <= 0) { + input_error++; + sprintf(error_string, "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + done = TRUE; + } + } + if (done == FALSE) { + dq2 = log(q2) / (xbq2 * xbq2); + if (xbq1 < 0. || xbq2 > 1.) { + a0 = dq2; + a1 = 0; + done = TRUE; + } + } + if (done == FALSE) { + denom = 4 * (xbq1 - xbq2) + 2; + if (fabs(denom) >= tol) { + if (fabs(1 - xbq1) > 0 && q1 > 0) { + dq1 = log(q1)/ ((1 - xbq1)*(1 - xbq1)); + a0 = (dq1 * (3 - 4*xbq2) + dq2 * (4*xbq1 - 1)) / denom; + a1 = (dq1 - dq2) / denom; + done = TRUE; + } + } + } + if (done == FALSE) { + input_error++; + sprintf(error_string, "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + /* io = 1 */ + ag0 = a0*rt; + ag1 = a1*rt; + break; + /* + * two distribution coefficients + * q1, q2, xbq1, xbq2 + */ + case 2: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + ratio = kc/kb; + dr1 = log(q1/ratio); + x21 = 2*xbq1 - 1; + if (fabs(xbq1 - xbq2) < tol || xbq2 < 0) { + a0 = dr1 / x21; + a1 = 0; + } else { + dr2 = log(q2/ratio); + x22 = 2*xbq2 - 1; + if (xbq1 < 0.) { + a0 = dr2/x22; + a1 = 0; + } else { + x61 = 6*xbq1*xbq1 - 6*xbq1 + 1; + x62 = 6*xbq2*xbq2 - 6*xbq2 + 1; + if (fabs(x22*x61 - x21*x62) < tol) { + input_error++; + sprintf(error_string, "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + a0 = (x61*dr2 - x62*dr1) / (x22*x61 - x21*x62); + a1 = (x21*dr2 - x22*dr1) / (x21*x62 - x22*x61); + } + } + + /* io = 1 */ + ag0 = a0*rt; + ag1 = a1*rt; + break; + /* + * from miscibility gap fractions + * q1, q2 + */ + case 3: + q1 = p[0]; + q2 = p[1]; + xb1 = q1; + xb2 = q2; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + r1 = log(xb1/xb2); + r2 = log(xc1/xc2); + pa1 = xc2*xc2 - xc1*xc1; + pb1 = 3*(xc2*xc2 - xc1*xc1) - 4*(xc2*xc2*xc2 - xc1*xc1*xc1); + pa2 = xb2*xb2 - xb1*xb1; + pb2 = -(3*(xb2*xb2 - xb1*xb1) - 4*(xb2*xb2*xb2 - xb1*xb1*xb1)); + a0 = (r1 - pb1/pb2*r2) / (pa1 - pa2*pb1/pb2); + a1 = (r1 - pa1/pa2*r2) / (pb1 -pb2*pa1/pa2); + + /* io = 1 */ + ag0 = a0*rt; + ag1 = a1*rt; + break; + /* + * from spinodal gap fractions + * q1, q2 + */ + case 4: + q1 = p[0]; + q2 = p[1]; + xsm1 = q1; + xsm2 = q2; + pn9 = 1/xsm1; + pn10 = 1/xsm2; + c5 = 1 - xsm1; + c6 = 1 - xsm2; + pl9 = 6*c5 - 12*c5*c5; + pl10 = 6*c6 - 12*c6*c6; + pj9 = 2*c5; + pj10 = 2*c6; + a0 = (pn9 - pl9/pl10*pn10) / (pj9 - pl9/pl10*pj10); + a1 = (pn9 - pj9/pj10*pn10) / (pl9 - pj9/pj10*pl10); + + /* io = 1 */ + ag0 = a0*rt; + ag1 = a1*rt; + break; + /* + * from critical point + * q1, q2 + */ + case 5: + xc = p[0]; + tc = p[1]; + r = R_KJ_DEG_MOL; + ag1 = r*tc* (2*xc - 1) / (12*xc*xc*(1 - xc)*(1 - xc)); + ag0 = (r*tc / (xc*(1 - xc)) - (12*xc - 6)*ag1) / 2; + + /* io = 0 */ + a0 = ag0/rt; + a1 = ag1/rt; + break; + /* + * from alyotropic point + * q1, q2 + */ + case 6: + q1 = p[0]; + q2 = p[1]; + xaly = q1; + r = log(kb/kc); + alpha0 = 2*xaly - 1; + alpha1 = 6*xaly*(xaly - 1) + 1; + spialy = pow(10., q2); + a0 = -999.; + a1 = -999.; + if (fabs(alpha0) < tol) { + input_error++; + sprintf(error_string, "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + } else { + azero = 1; + if (fabs(alpha0) > tol) azero = r/alpha0; + xcaly = 1 - xaly; +/* + * Solve for a0 by Newton's method + */ + for (i = 0; i < 50; i++) { + phi1 = xcaly*xcaly*(azero + (r - azero*alpha0)*(4*xaly - 1)/alpha1); + phi2 = xaly*xaly*(azero + (3 - 4*xaly)*(azero*alpha0 - r)/alpha1); + phi1 = xaly*kb*exp(phi1); + phi2 = xcaly*kc*exp(phi2); + fx = phi1 + phi2 - spialy; + fx1 = xcaly*xcaly*(1 - alpha0*(4*xaly - 1)/alpha1)*phi1 + + xaly*xaly*(1 + alpha0*(3 - 4*xaly)/alpha1)*phi2; + if (fabs(fx1) < 1e-10) { + input_error++; + sprintf(error_string, "Could not find A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + break; + } + a0 = azero - fx/fx1; + test = fabs(a0 - azero) + fabs(fx); + azero = a0; + if (test < tol) break; + } + if (i == 50) { + input_error++; + sprintf(error_string, "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); + error_msg(error_string, CONTINUE); + } else { + a1 = (r - a0 *alpha0) / alpha1; + + /* io = 0 */ + ag0 = a0 * rt; + ag1 = a1 * rt; + } + + } + break; + /* + * dimensional (kJ/mol) Guggenheim parameters + * ag0, ag1 + */ + case 7: + ag0 = p[0]; + ag1 = p[1]; + a0 = ag0 / rt; + a1 = ag1 / rt; + break; + /* + * Waldbaum-Thompson + * wg2, wg1 + */ + case 8: + wg2 = p[0]; + wg1 = p[1]; + ag0 = (wg2 + wg1) / 2; + ag1 = (wg2 - wg1) / 2; + a0 = ag0 / rt; + a1 = ag1 / rt; + break; + /* + * Margules + * alpha2, alpha3 + */ + case 9: + alpha2 = p[0]; + alpha3 = p[1]; + a0 = alpha2 + 3*alpha3/4; + a1 = alpha3/4; + ag0 = a0 * rt; + ag1 = a1 * rt; + break; + } + + s_s_ptr->ag0 = ag0; + s_s_ptr->ag1 = ag1; + s_s_ptr->a0 = a0; + s_s_ptr->a1 = a1; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_master_isotope(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + + for (i = 0; i < count_master_isotope; i++) { + /* + * Mark master species list as minor isotope + */ + if (master_isotope[i]->minor_isotope == TRUE) { + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "Did not find master species for isotope, %s", master_isotope[i]->name); + error_msg(error_string,CONTINUE); + master_isotope[i]->master = NULL; + continue; + } else { + master_isotope[i]->master = master_ptr; + } + master_ptr->minor_isotope = TRUE; + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_isotope_ratios(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + struct master_isotope *master_isotope_ptr; + struct calculate_value *calculate_value_ptr; + + for (i = 0; i < count_isotope_ratio; i++) { + /* + * Mark master species list as minor isotope + */ + master_isotope_ptr = master_isotope_search(isotope_ratio[i]->isotope_name); + if (master_isotope_ptr == NULL) { + input_error++; + sprintf(error_string, "For ISOTOPE_RATIO %s, did not find ISOTOPE definition for this isotope, %s", isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); + error_msg(error_string,CONTINUE); + } + master_ptr = master_bsearch(isotope_ratio[i]->isotope_name); + if (master_ptr == NULL) { + input_error++; + sprintf(error_string, "For ISOTOPE_RATIO %s, did not find SOLUTION_MASTER_SPECIES for isotope, %s", isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); + error_msg(error_string,CONTINUE); + } + calculate_value_ptr = calculate_value_search(isotope_ratio[i]->name); + if (calculate_value_ptr == NULL) { + input_error++; + sprintf(error_string, "For ISOTOPE_RATIOS %s, did not find corresponding CALCULATE_VALUE definition", isotope_ratio[i]->name); + error_msg(error_string,CONTINUE); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int tidy_isotope_alphas(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct calculate_value *calculate_value_ptr; + struct logk *logk_ptr; + + for (i = 0; i < count_isotope_alpha; i++) { + /* + * Mark master species list as minor isotope + */ + calculate_value_ptr = calculate_value_search(isotope_alpha[i]->name); + if (calculate_value_ptr == NULL) { + input_error++; + sprintf(error_string, "For ISOTOPE_ALPHAS %s, did not find corresponding CALCULATE_VALUE definition", isotope_alpha[i]->name); + error_msg(error_string,CONTINUE); + } + if (isotope_alpha[i]->named_logk != NULL) { + logk_ptr = logk_search(isotope_alpha[i]->named_logk); + if (logk_ptr == NULL) { + input_error++; + sprintf(error_string, "For ISOTOPE_ALPHAS %s, did not find corresponding NAMED_EXPRESSION definition %s.", isotope_alpha[i]->name, isotope_alpha[i]->named_logk); + error_msg(error_string,CONTINUE); + } + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int reset_last_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialize model + */ + last_model.force_prep = TRUE; + last_model.count_exchange = 0; + last_model.exchange = (struct master **) free_check_null(last_model.exchange); + last_model.count_gas_phase = 0; + last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); + last_model.count_s_s_assemblage = 0; + last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); + last_model.count_pp_assemblage = 0; + last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.add_formula = (char **) free_check_null(last_model.add_formula); + last_model.si = (LDBLE *) free_check_null(last_model.si); + last_model.diffuse_layer = FALSE; + last_model.count_surface_comp = 0; + last_model.surface_comp = (struct master **) free_check_null(last_model.surface_comp); + last_model.count_surface_charge = 0; + last_model.surface_charge = (struct master **) free_check_null(last_model.surface_charge); + return(OK); +} diff --git a/transport.cpp b/transport.cpp new file mode 100644 index 00000000..4dba3182 --- /dev/null +++ b/transport.cpp @@ -0,0 +1,844 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: transport.c 78 2005-02-01 22:47:12Z dlpark $"; + +static int init_mix(void); +static int init_heat_mix(int nmix); +static int heat_mix(int heat_nmix); +static int mix_stag(int i, LDBLE stagkin_time, int punch, LDBLE step_fraction_kin); + + +LDBLE *heat_mix_array; +LDBLE *temp1, *temp2; +int heat_nmix; +LDBLE heat_mix_f_imm, heat_mix_f_m; + +/* ---------------------------------------------------------------------- */ +int transport(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, n; + int j_imm, n_m, n_imm; + LDBLE b, f, mix_f_m, mix_f_imm; + LDBLE water_m, water_imm; + int first_c, last_c, b_c; + int nmix; + int max_iter; + char token[MAX_LENGTH]; + LDBLE kin_time, stagkin_time, kin_time_save; + struct mix *mix_ptr; + int punch_boolean; + LDBLE step_fraction; + if (svnid == NULL) fprintf(stderr," "); + + state = TRANSPORT; +/* mass_water_switch = TRUE; */ +/* + * Check existence of solutions + */ + j = -1; + /* check column solutions */ + for (i = 1; i <= count_cells; i++) { + use.solution_ptr = solution_bsearch(i, &n, TRUE); + if (use.solution_ptr == NULL) { + input_error++; + sprintf(error_string, "Solution %d is needed for transport, but is not defined.", i); + error_msg(error_string, CONTINUE); + } else { + cell_data[i-1].temp = use.solution_ptr->tc; + } + } + + /* check solution 0 */ + if (ishift == 1) { + if (solution_bsearch(0, &n, TRUE) == NULL) { + input_error++; + sprintf(error_string, "Solution 0 is needed for transport, but is not defined."); + error_msg(error_string, CONTINUE); + } + } + + /* check solution count_cells */ + if (ishift == -1) { + if (solution_bsearch(count_cells+1, &n, TRUE) == NULL) { + input_error++; + sprintf(error_string, "Solution %d is needed for transport, but is not defined.", count_cells+1); + error_msg(error_string, CONTINUE); + } + } +/* + * Stop if error + */ + if (input_error > 0) { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Initialize temperature in stagnant cells ... + */ + for (n=1; n<=stag_data->count_stag; n++) { + for (i=1; i <= count_cells; i++) { + k = i+1+n*count_cells; + use.solution_ptr = solution_bsearch(k, &use.n_solution, FALSE); + if (use.solution_ptr != NULL) { + cell_data[k-1].temp = use.solution_ptr->tc; + } + } + } + + if (solution_bsearch(0, &n, FALSE) == NULL) solution_duplicate(1,0); + if (solution_bsearch(count_cells+1, &n, FALSE) == NULL) solution_duplicate(count_cells, count_cells+1); + +/* + * Initialize mixing factors, define kinetics times + */ + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { + mix_ptr = &mix[0]; + for (i = 0; i < count_mix; i++) mix_free(mix_ptr++); + count_mix = 2*count_cells; + mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof(struct mix)); + if (mix == NULL) malloc_error(); + memset(mix, 0, sizeof(struct mix) * count_mix); + } + nmix = init_mix(); + heat_nmix = init_heat_mix(nmix); + if (nmix < 2) stagkin_time = timest; else stagkin_time = timest/nmix; + if (ishift != 0 ) kin_time = timest/(1+nmix); else kin_time = stagkin_time; + kin_time_save = kin_time; + +/* Reaction defined for a shift... */ + step_fraction = 1.0/(1.0+nmix); + +/* + * Set boundary conditions, transport direction + */ + last_model.force_prep = TRUE; + if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) { + b_c = 1; + } else { + b_c = 0; + } + if (ishift >= 0) { + last_c = count_cells; + first_c = 1; + } else { + last_c = 1; + first_c = count_cells; + } +/* + * First equilibrate solutions + */ + dup_print("Equilibrating initial solutions", TRUE); + transport_step = 0; + for (i=1; i <= count_cells; i++) { + set_initial_moles(i); + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (cell_data[i-1].punch == TRUE) punch_all(); + if (cell_data[i-1].print == TRUE) print_all(); + saver(); + } +/* + * Also stagnant cells + */ + for (n=1; n<=stag_data->count_stag; n++) { + for (i=1; i <= count_cells; i++) { + k = i+1+n*count_cells; + cell_no = k; + if (solution_bsearch(k, &use.n_solution, FALSE) != 0 ) { + set_initial_moles(k); + set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); + if ((cell_data[k-1].punch == TRUE)) punch_all(); + if ((cell_data[k-1].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); + saver(); + } + } + } +/* + * Define stagnant/mobile mix structure, if not read explicitly. + * + * With count_stag = 1, mix factors are calculated from exchange factor à + * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. + * These variables are read under keyword TRANSPORT, after stagnant, in + * structure stag_data. + * MIX 'cell_no' in input file can be an alternative for the calculation here. + */ + + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { + + b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); + f = exp( - stag_data->exch_f * stagkin_time / (b * stag_data->th_im) ); + mix_f_imm = b - b * f; + mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; + + n = 0; + for (i=1; i <= count_cells; i++) { + j = i; + j_imm = j + (1 + count_cells); + if (solution_bsearch(j, &n_m, TRUE) == NULL) { + error_msg("Could not find mobile cell solution in TRANSPORT.", STOP); + } + if (solution_bsearch(j_imm, &n_imm, TRUE) == NULL) { + error_msg("Could not find immobile cell solution in TRANSPORT.", STOP); + } + water_m = solution[n_m]->mass_water; + water_imm = solution[n_imm]->mass_water; +/* + * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 + */ + mix[n].comps = (struct mix_comp *) PHRQ_malloc((size_t) 2*sizeof(struct mix_comp)); + if (mix[n].comps == NULL) malloc_error(); + mix[n].count_comps = 2; + mix[n].description = string_duplicate(" "); + mix[n].n_user = j; + mix[n].n_user_end = j; + mix[n].comps[0].n_solution = j; + mix[n].comps[0].fraction = 1 - mix_f_m; + mix[n].comps[1].n_solution = j_imm; + mix[n].comps[1].fraction = mix_f_m*water_m/water_imm; + n++; +/* + * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... + */ + mix[n].comps = (struct mix_comp *) PHRQ_malloc((size_t) 2*sizeof(struct mix_comp)); + if (mix[n].comps == NULL) malloc_error(); + mix[n].count_comps = 2; + mix[n].description = string_duplicate(" "); + mix[n].n_user = j_imm; + mix[n].n_user_end = j_imm; + mix[n].comps[0].n_solution = j_imm; + mix[n].comps[0].fraction = 1 - mix_f_imm; + mix[n].comps[1].n_solution = j; + mix[n].comps[1].fraction = mix_f_imm*water_imm/water_m; + n++; + } + + if (heat_nmix > 0) { +/* + * Assumption: D_e used for calculating exch_f in input file equals diffc + */ + f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; + f = exp( - f * stagkin_time / (b * stag_data->th_im) ); + heat_mix_f_imm = b - b * f; + heat_mix_f_m = heat_mix_f_imm * stag_data->th_im / stag_data->th_m; + } + } +/* + * Now transport + */ + max_iter = 0; + for (transport_step = transport_start; transport_step <= count_shifts; transport_step++) { + /* + * Set initial moles of phases + */ + for (i = 1; i <= count_cells; i++) { + set_initial_moles(i); + } + +/* + * Start diffusing if boundary cond = 1, (fixed c, or closed) + */ + if (b_c == 1) { + + /* For half of mixing steps */ + + for (j = 1; j <= floor(nmix/2); j++) { + rate_sim_time_start = (transport_step - 1) * timest + (j-1) * kin_time; + rate_sim_time = rate_sim_time_start + kin_time; + + sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); + dup_print(token, FALSE); + + if (heat_nmix > 0) { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i=1; i <= count_cells; i++) { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + saver(); + } + } + + /* Go through cells */ + + for (i = 1; i <= count_cells; i++) { + +#ifdef SKIP +/* this is somewhere lost; quickened in set_and_run ... */ + if (i == 1) { + last_model.force_prep = TRUE; + } +#endif + if (iterations > max_iter) max_iter = iterations; + sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, j, i, max_iter); + status(0, token); + + cell_no = i; + run_reactions(i, kin_time, DISP, step_fraction); + + /* punch and output file */ + if ((ishift == 0) && (j == nmix) && + ((stag_data->count_stag == 0) || + solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0)){ + if ((cell_data[i-1].punch == TRUE) && + (transport_step % punch_modulus == 0)) punch_all(); + if ((cell_data[i-1].print == TRUE) && + (transport_step % print_modulus == 0)) print_all(); + } + if (i > 1) solution_duplicate(-2, i-1); + saver(); + } + solution_duplicate(-2, count_cells); + + /* Stagnant zone mixing after completion of each + diffusive/dispersive step ... */ + + rate_sim_time_start = (transport_step - 1)*timest + (j-1)*stagkin_time; + rate_sim_time = rate_sim_time_start + stagkin_time; + + if (stag_data->count_stag > 0) { + if ((ishift == 0) && (j == nmix)) punch_boolean = TRUE; else punch_boolean = FALSE; + for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, step_fraction); + } + } + } +/* + * Advective transport + */ + if (ishift !=0) { + sprintf(token, "Transport step %3d.", transport_step); + dup_print(token, FALSE); + if (b_c == 1) { + rate_sim_time_start = (transport_step -1)*timest + (j-1)*kin_time; + } else { + rate_sim_time_start = (transport_step -1)*timest; + } + rate_sim_time = rate_sim_time_start + kin_time; + +/* halftime kinetics for resident water in first cell ... */ + if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) { + cell_no = first_c; + kin_time = kin_time_save / 2; + run_reactions(first_c, kin_time, NOMIX, 0.0); + saver(); + kin_time = kin_time_save; + } + + /* for each cell in column */ +/* Begin revision Dec 7, 1999 */ + for (i = last_c; i != (first_c-ishift); i-=ishift) { + solution_duplicate(i-ishift, i); + } +/* + * thermal diffusion when nmix = 0... + */ + if ((nmix == 0) && (heat_nmix > 0)) { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i=1; i <= count_cells; i++) { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + saver(); + } + } + + for (i = 1; i <= count_cells; i++) { + if (i == first_c && count_cells > 1) kin_time /= 2; + sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, 0, i, max_iter); + status(0, token); + cell_no = i; + run_reactions(i, kin_time, NOMIX, step_fraction); + if (iterations > max_iter) max_iter = iterations; +/* end revision Dec 7, 1999 */ + + if ((nmix == 0) && + ((stag_data->count_stag == 0) || + (solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0))) { + if ((cell_data[i-1].punch == TRUE) && + (transport_step % punch_modulus == 0)) punch_all(); + if ((cell_data[i-1].print == TRUE) && + (transport_step % print_modulus == 0)) print_all(); + } + if (i == first_c && count_cells > 1) kin_time = kin_time_save; + saver(); + + /* If nmix is zero, stagnant zone mixing after + advective step ... */ + + if ((nmix == 0) && (stag_data->count_stag > 0)) mix_stag(i, stagkin_time, TRUE, step_fraction); + } + } + +/* + * Further dispersive and diffusive transport + */ + if (b_c != 1) j = 1; + for (j = j; j <= nmix; j++) { + sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); + dup_print(token, FALSE); + rate_sim_time_start = (transport_step - 1)*timest + (j - 1) * kin_time; + if (ishift != 0) rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start + kin_time; + + if (heat_nmix > 0) { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i=1; i <= count_cells; i++) { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + saver(); + } + } + + /* for each cell in column */ + + for (i = 1; i <= count_cells; i++) { + if (iterations > max_iter) max_iter = iterations; + sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, j, i, max_iter); + status(0, token); + cell_no = i; + run_reactions(i, kin_time, DISP, step_fraction); + + if ((j == nmix) && + ((stag_data->count_stag == 0) || + (solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0))) { + if ((cell_data[i-1].punch == TRUE) && + (transport_step % punch_modulus == 0)) punch_all(); + if ((cell_data[i-1].print == TRUE) && + (transport_step % print_modulus == 0)) { + print_all(); + } + } + if (i > 1) solution_duplicate(-2, i-1); + saver(); + } + solution_duplicate(-2, count_cells); + /* Stagnant zone mixing after completion of each + diffusive/dispersive step ... */ + + rate_sim_time_start = (transport_step - 1)*timest + (j - 1) * stagkin_time; + rate_sim_time = rate_sim_time_start + stagkin_time; + + if (stag_data->count_stag > 0) { + if (j == nmix) punch_boolean = TRUE; else punch_boolean = FALSE; + for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, step_fraction); + } + } + if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) dump(); + } +#ifdef DOS + output_msg(OUTPUT_SCREEN, "\n"); +#else + output_msg(OUTPUT_SCREEN, "%s%-80s", "\n", " "); +#endif + /* free_model_allocs(); */ +/* + * free mix structures + */ + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { + mix_ptr = &mix[0]; + for (i = 0; i < count_mix; i++) mix_free(mix_ptr++); + count_mix =0; + } else { + if (nmix > 0) { + mix_ptr = &mix[count_mix - count_cells]; + for (i = count_mix - count_cells; i < count_mix; i++) { + mix_free(mix_ptr++); + } + count_mix -= count_cells; + mix = (struct mix *) PHRQ_realloc(mix, (size_t) (count_mix + 1)*sizeof(struct mix)); + if (mix == NULL) malloc_error(); + } + } + if (heat_nmix > 0) { + free_check_null(heat_mix_array); + free_check_null(temp1); + free_check_null(temp2); + } + + initial_total_time += rate_sim_time; + rate_sim_time = 0; + mass_water_switch = FALSE; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int init_mix(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE dav, lav, mixf, maxmix, corr_disp; + int i, n, nmix, count_comps, max_mix; + LDBLE *m; + + m = (LDBLE *) PHRQ_malloc((count_cells+1)*sizeof(LDBLE)); + if (m == NULL) malloc_error(); + +/* + * Define mixing factors among inner cells + */ + corr_disp = 1.; + if (correct_disp == TRUE && ishift != 0) { + if (bcon_first == 3) corr_disp += 1. / count_cells; + if (bcon_last == 3) corr_disp += 1. / count_cells; + } + maxmix = 0.0; + for (i=1; i < count_cells; i++) { + lav = (cell_data[i-1].length + cell_data[i].length)/2; + if (ishift != 0) { + dav = (cell_data[i-1].disp + cell_data[i].disp)/2; + } else { + dav = 0; + } + mixf = (diffc*timest/lav + dav) * corr_disp / lav; + + if (mixf > maxmix) maxmix = mixf; + m[i] = mixf; /* m[i] has mixf with lower cell */ + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) { + lav = cell_data[0].length; + if (ishift != 0) { + dav = cell_data[0].disp; + } else { + dav = 0; + } + mixf = (diffc*timest/lav + dav)/lav; + if (mixf > maxmix) maxmix = mixf; + m[0] = 2*mixf; + } else { + m[0] = 0; + } + if (bcon_last == 1) { + lav = cell_data[count_cells-1].length; + if (ishift != 0) { + dav = cell_data[count_cells-1].disp; + } else { + dav = 0; + } + mixf = (diffc*timest/lav + dav)/lav; + if (mixf > maxmix) maxmix = mixf; + m[count_cells] = 2*mixf; + } else { + m[count_cells] = 0; + } +/* + * Find number of mixes + */ + if (maxmix == 0) { + nmix = 0; + } else { + if ((bcon_first == 1) || (bcon_last == 1)) { + nmix = 1 + (int) floor(4.5 * maxmix); + } else { + nmix = 1 + (int) floor(3.0 * maxmix); + } + if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { + if (nmix < 2) nmix = 2; + } + for (i=0; i<=count_cells; i++) m[i] /= nmix; + } + /* + * Fill mix structure + */ + if (nmix != 0) { + mix = (struct mix *) PHRQ_realloc(mix, (size_t) (count_mix + count_cells)*sizeof(struct mix)); + if (mix == NULL) malloc_error(); + count_mix += count_cells; + for (n = count_mix-count_cells; ncount_stag + 1) + 1) { + max_mix = count_cells * (stag_data->count_stag + 1) + 1; + } + for (i=1; i<=count_cells; i++) { + dav = 0; + count_comps = 0; + mix[n].description = (char *) free_check_null(mix[n].description); + mix[n].description = string_duplicate(" "); +/* + * max_mix brings n_user outside range of active cells + * mix[n].n_user = mix[n].n_user_end = -999 has same effect + * but max_mix keeps mix in sort order in case mix_bsearch + * is used + */ + mix[n].n_user = max_mix + i ; + mix[n].n_user_end = max_mix + i ; + + mix[n].comps[count_comps].n_solution = i-1; + mix[n].comps[count_comps].fraction = m[i-1]; + dav += m[i-1]; + count_comps++; + mix[n].comps[count_comps].n_solution = i+1; + mix[n].comps[count_comps].fraction = m[i]; + dav += m[i]; + count_comps++; + mix[n].comps[count_comps].n_solution = i; + mix[n].comps[count_comps].fraction = 1.0 - dav; + + n++; + } + } + m = (LDBLE *) free_check_null(m); + return(nmix); +} +/* ---------------------------------------------------------------------- */ +int mix_stag(int i, LDBLE kin_time, int punch, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ + int n, k, l; + LDBLE t_imm; + struct solution *ptr_imm, *ptr_m; +#ifdef SKIP + char str[MAX_LENGTH]; +#endif +/* + * Kinetics in transport cell is done while transporting + */ + for (n=1; n<=stag_data->count_stag; n++) { + k = i+1+n*count_cells; + if ((ptr_imm = solution_bsearch(k, &use.n_solution, FALSE)) != NULL ) { + if (n == 1) { + if (heat_nmix > 0) { + ptr_m = solution_bsearch(i, &use.n_solution, FALSE); + t_imm = heat_mix_f_imm * ptr_m->tc + (1 - heat_mix_f_imm) * ptr_imm->tc; + ptr_m->tc = heat_mix_f_m * ptr_imm->tc + (1 - heat_mix_f_m) * ptr_m->tc; + cell_data[i-1].temp = ptr_m->tc; + cell_data[k-1].temp = ptr_imm->tc = t_imm; + /* equilibrate again ... */ + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + saver(); + cell_no = k; + set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); + saver(); + } +/* + * Mobile cell, kinetics already done ... + */ + cell_no = i; + set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); + if ((use.kinetics_ptr = kinetics_bsearch(i, &l)) != NULL) { + use.n_kinetics_user = i; + use.kinetics_in = TRUE; + } + if ((punch == TRUE) && + (cell_data[i-1].punch == TRUE) && + (transport_step % punch_modulus == 0)) punch_all(); + if ((punch == TRUE) && + (cell_data[i-1].print == TRUE) && + (transport_step % print_modulus == 0)) { + print_all(); + } + saver(); + } + cell_no = k; + run_reactions(k, kin_time, STAG, step_fraction); + if ((cell_data[k-1].punch == TRUE) && + (punch == TRUE) && + (transport_step % punch_modulus == 0)) punch_all(); + if ((cell_data[k-1].print == TRUE) && + (punch == TRUE) && + (transport_step % print_modulus == 0)) { + print_all(); + } + saver(); + } + } + for (n=1; n<=stag_data->count_stag; n++) { + k = i+1+n*count_cells; + if (solution_bsearch(k, &use.n_solution, FALSE) != 0 ) { + solution_duplicate(-2-k, k); + if (n == 1) solution_duplicate(-2, i); + } + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int init_heat_mix(int nmix) +/* ---------------------------------------------------------------------- */ +{ + LDBLE lav, mixf, maxmix, corr_disp; + int i, j, k, n; + int heat_nmix; + LDBLE t0; +/* + * Check for need to model thermal diffusion... + */ + if (heat_diffc <= diffc) return(0); + if (count_cells < 2) return(0); + + heat_nmix = 0; + t0 = solution_bsearch(0, &n, FALSE)->tc; + for (i = 0; i < count_cells; i++) { + if (fabs(cell_data[i].temp - t0) > 1.0) { + heat_nmix = 1; + break; + } + } + if (heat_nmix == 0) { + if (fabs(solution_bsearch(count_cells+1, &n, FALSE)->tc - t0) > 1.0) heat_nmix = 1; + for (n = 1; n <= stag_data->count_stag; n++) { + for (i = 1; i < count_cells; i++) { + k = i+1+n*count_cells; + if (solution_bsearch(k, &j, FALSE) != 0 ) { + if (fabs(cell_data[k-1].temp - t0) > 1.0) { + heat_nmix = 1; + break; + } + } + } + } + } + if (heat_nmix == 0) return(0); +/* + * Initialize arrays... + */ + heat_mix_array = (LDBLE *) PHRQ_malloc((count_cells+2)*sizeof(LDBLE)); + if (heat_mix_array == NULL) malloc_error(); + temp1 = (LDBLE *) PHRQ_malloc((count_cells + 2)*sizeof(LDBLE)); + if (temp1 == NULL) malloc_error(); + temp2 = (LDBLE *) PHRQ_malloc((count_cells + 2)*sizeof(LDBLE)); + if (temp2 == NULL) malloc_error(); +/* + * Define mixing factors among inner cells... + */ + corr_disp = 1.; + if (correct_disp == TRUE && ishift != 0) { + if (bcon_first == 3) corr_disp += 1. / count_cells; + if (bcon_last == 3) corr_disp += 1. / count_cells; + } + if (nmix > 0) corr_disp /= nmix; + maxmix = 0.0; + for (i=1; i < count_cells; i++) { + lav = (cell_data[i-1].length + cell_data[i].length)/2; + mixf = (heat_diffc - diffc) * timest * corr_disp / tempr / (lav *lav); + if (mixf > maxmix) maxmix = mixf; + heat_mix_array[i+1] = mixf; /* m[i] has mixf with lower cell */ + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) { + lav = cell_data[0].length; + mixf = (heat_diffc - diffc) * timest * corr_disp / tempr /(lav * lav); + if (2*mixf > maxmix) maxmix = 2*mixf; + heat_mix_array[1] = 2*mixf; + } else { + heat_mix_array[1] = 0; + } + if (bcon_last == 1) { + lav = cell_data[count_cells-1].length; + mixf = (heat_diffc - diffc) * timest * corr_disp / tempr /(lav * lav); + if (2*mixf > maxmix) maxmix = 2*mixf; + heat_mix_array[count_cells+1] = 2*mixf; + } else { + heat_mix_array[count_cells+1] = 0; + } +/* + * Find number of mixes + */ + if (maxmix == 0) { + heat_nmix = 0; + } else { + heat_nmix = 1 + (int) floor(3.0 * maxmix); + for (i=1; i <= count_cells + 1; i++) heat_mix_array[i] /= heat_nmix; + } + + return(heat_nmix); +} +/* ---------------------------------------------------------------------- */ +int heat_mix(int heat_nmix) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + for (i = 1; i <= count_cells; i++) temp1[i] = solution_bsearch(i, &j, FALSE)->tc; + temp1[0] = solution_bsearch(0, &j, FALSE)->tc; + temp1[count_cells+1] = solution_bsearch((count_cells+1), &j, FALSE)->tc; + + for (i = 1; i <= heat_nmix; i++) { + for (j = 1; j <= count_cells; j++) { + temp2[j] = heat_mix_array[j] * temp1[j-1] + + heat_mix_array[j+1] * temp1[j+1] + + (1 - heat_mix_array[j] - heat_mix_array[j+1]) * temp1[j]; + } + for (j = 1; j <= count_cells; j++) temp1[j] = temp2[j]; + } + + for (i = 1; i <= count_cells; i++) { + cell_data[i-1].temp = temp1[i]; + solution_bsearch(i, &j, FALSE)->tc = temp1[i]; + } + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int set_initial_moles(int i) +/* ---------------------------------------------------------------------- */ +{ + struct pp_assemblage *pp_assemblage_ptr; + struct gas_phase *gas_phase_ptr; + struct kinetics *kinetics_ptr; + struct s_s_assemblage *s_s_assemblage_ptr; + int j, k, n; + /* + * Pure phase assemblage + */ + pp_assemblage_ptr = pp_assemblage_bsearch (i, &n); + if (pp_assemblage_ptr != NULL) { + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { + pp_assemblage_ptr->pure_phases[j].initial_moles = pp_assemblage_ptr->pure_phases[j].moles; + if (pp_assemblage_ptr->pure_phases[j].initial_moles < 0) pp_assemblage_ptr->pure_phases[j].initial_moles = 0; + } + } + /* + * Gas phase + */ + gas_phase_ptr = gas_phase_bsearch (i, &n); + if (gas_phase_ptr != NULL) { + for (j = 0; j < gas_phase_ptr->count_comps; j++) { + gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; + } + } + /* + * Kinetics + */ + kinetics_ptr = kinetics_bsearch (i, &n); + if (kinetics_ptr != NULL) { + for (j = 0; j < kinetics_ptr->count_comps; j++) { + kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; + } + } + /* + * Solid solutions + */ + s_s_assemblage_ptr = s_s_assemblage_bsearch (i, &n); + if (s_s_assemblage_ptr != NULL) { + for (k = 0; k < s_s_assemblage_ptr->count_s_s; k++) { + for (j = 0; j < s_s_assemblage_ptr->s_s[k].count_comps; j++) { + s_s_assemblage_ptr->s_s[k].comps[j].init_moles = s_s_assemblage_ptr->s_s[k].comps[j].moles; + } + } + } + return(OK); +} diff --git a/utilities.cpp b/utilities.cpp new file mode 100644 index 00000000..40a6e640 --- /dev/null +++ b/utilities.cpp @@ -0,0 +1,1471 @@ +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "output.h" +#include "phrqproto.h" + +static char const svnid[] = "$Id: utilities.c 674 2005-11-21 15:01:22Z dlpark $"; + +#ifdef PHREEQ98 +extern int AutoLoadOutputFile, CreateToC; +extern int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; +extern int outputlinenr; +extern int stop_calculations; +void AddToCEntry(char* a, int l, int i); +void ApplicationProcessMessages(void); +/* void check_line_breaks(char *s); */ +char err_str98[80]; +int copy_title(char *token_ptr, char **ptr, int *length); +extern int clean_up_null(void); +#endif + +static int isamong(char c, const char *s_l); + +/* ---------------------------------------------------------------------- */ +int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ + struct elt_list *elt_list_ptr1; + if (svnid == NULL) fprintf(stderr," "); + + if (elt_list_ptr == NULL) return(OK); + + for (elt_list_ptr1=elt_list_ptr; elt_list_ptr1->elt != NULL; elt_list_ptr1++) { + if (count_elts >= max_elts) { + space ((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE calc_alk(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE return_value; + struct master *master_ptr; + + return_value = 0.0; + for ( i=1; rxn_ptr->token[i].s != NULL; i++) { + master_ptr = rxn_ptr->token[i].s->secondary; + if (master_ptr == NULL ) { + master_ptr = rxn_ptr->token[i].s->primary; + } + if (master_ptr == NULL ) { + sprintf(error_string, "Non-master species in secondary reaction, %s.", rxn_ptr->token[0].s->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + return_value += rxn_ptr->token[i].coef * master_ptr->alk; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int compute_gfw(const char *string, LDBLE *gfw) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input: string contains a chemical formula + * Output: gfw contains the calculated gfw + */ + int i; + char token[MAX_LENGTH]; + char *ptr; + + count_elts=0; + paren_count=0; + strcpy(token, string); + ptr = token; + if (get_elts_in_species (&ptr, 1.0) == ERROR) { + return(ERROR); + } + *gfw=0.0; + for (i=0; i < count_elts; i++) { + if (elt_list[i].elt->gfw <= 0.0) { + return(ERROR); + } + *gfw += elt_list[i].coef*(elt_list[i].elt)->gfw; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int copy_token (char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first space is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * UNKNOWN. + */ + int i, return_value; + char c; + +/* + * Read to end of whitespace + */ + while ( isspace((int) (c=**ptr)) ) (*ptr)++; +/* + * Check what we have + */ + if ( isupper((int) c) || c == '[') { + return_value=UPPER; + } else if ( islower((int) c) ) { + return_value=LOWER; + } else if ( isdigit((int) c) || c=='.' || c=='-') { + return_value=DIGIT; + } else if ( c == '\0') { + return_value=EMPTY; + } else { + return_value=UNKNOWN; + } +/* + * Begin copying to token + */ + i=0; + while ( ( ! isspace ((int) (c=**ptr)) ) && + /* c != ',' && */ + c != ';' && + c != '\0' ) { + token_ptr[i]=c; + (*ptr)++; + i++; + } + token_ptr[i]='\0'; + *length=i; +#ifdef PHREEQ98 + if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) { + sprintf(error_string, "Commas are not allowed as decimal separator: %s.", token_ptr); + error_msg(error_string, CONTINUE); + } +#endif + return(return_value); +} +#ifdef PHREEQ98 +/* ---------------------------------------------------------------------- */ +int copy_title(char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first space or comma is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * UNKNOWN. + */ + int i, return_value; + char c; + int Quote = FALSE; + +/* + * Read to end of whitespace + */ + while ( isspace((int) (c=**ptr)) || (c == ',') || (c == '"')) { + if (c == '"') Quote = TRUE; + (*ptr)++; + } +/* + * Check what we have + */ + if ( isupper((int) c) ) { + return_value=UPPER; + } else if ( islower((int) c) ) { + return_value=LOWER; + } else if ( isdigit((int) c) || c=='.' || c=='-') { + return_value=DIGIT; + } else if ( c == '\0') { + return_value=EMPTY; + } else { + return_value=UNKNOWN; + } +/* + * Begin copying to token + */ + i=0; + if (Quote == TRUE) { + while ( ( (int) (c=**ptr) != '"' ) && + c != '\0' ) { + token_ptr[i]=c; + (*ptr)++; + i++; + } + } else { + while ( ( ! isspace ((int) (c=**ptr)) ) && + c != ',' && + c != ';' && + c != '\0' ) { + token_ptr[i]=c; + (*ptr)++; + i++; + } + } + token_ptr[i]='\0'; + *length=i; + return(return_value); +} +#endif +/* ---------------------------------------------------------------------- */ +int dup_print(const char *ptr, int emphasis) +/* ---------------------------------------------------------------------- */ +{ +/* + * print character string to output and logfile + * if emphasis == TRUE the print is set off by + * a row of dashes before and after the character string. + * + */ + int l, i; + char *dash; + + if (pr.headings == FALSE) return(OK); +#ifdef PHREEQ98 + if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) { + if (strstr(ptr,"Reading") == ptr) AddToCEntry((char*)ptr, 1, outputlinenr); + else if (strstr(ptr,"Beginning") == ptr) AddToCEntry((char*)ptr, 2, outputlinenr); + else if ((strstr(ptr,"TITLE") != ptr) && (strstr(ptr,"End") != ptr)) AddToCEntry((char*)ptr, 3, outputlinenr); + } +#endif + l = strlen(ptr); + dash = (char *) PHRQ_malloc((size_t) (l+2) * sizeof(char)); + if (dash == NULL) malloc_error(); + if (emphasis == TRUE) { + for (i = 0; i < l; i++) dash[i] = '-'; + dash[i] = '\0'; + output_msg(OUTPUT_MESSAGE,"%s\n%s\n%s\n\n", dash, ptr, dash); + output_msg(OUTPUT_LOG,"%s\n%s\n%s\n\n", dash, ptr, dash); + } else { + output_msg(OUTPUT_MESSAGE,"%s\n\n", ptr); + output_msg(OUTPUT_LOG,"%s\n\n", ptr); + } + dash = (char*) free_check_null(dash); + + return(OK); +} +/* ---------------------------------------------------------------------- */ +int equal (LDBLE a, LDBLE b, LDBLE eps) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks equality between two LDBLE precision numbers + */ + if( fabs(a-b) <= eps ) return(TRUE); + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +void *free_check_null(void *ptr) +/* ---------------------------------------------------------------------- */ +{ + if (ptr != NULL) { + free(ptr); + } + return(NULL); +} +/* ---------------------------------------------------------------------- */ +int get_token(char **eqnaddr, char *string, LDBLE *z, int *l) +/* ---------------------------------------------------------------------- */ +/* + * Function finds next species in equation, coefficient has already + * been removed. Also determines charge on the species. + * + * Arguments: + * *eqnaddr input, pointer to position in eqn to start parsing + * output, pointer to a pointer to next position in eqn to start + * parsing. + * *string input pointer to place to store token + * *z charge on token + * *l length of token + * + * Returns: + * ERROR, + * OK. + */ +{ + int i, j; + int ltoken, lcharge; + char c; + char *ptr, *ptr1, *rest; + char charge[MAX_LENGTH]; + + rest=*eqnaddr; + ptr=*eqnaddr; + i=0; +/* + * Find end of token or begining of charge + */ + while ( ( (c=*ptr) != '+' ) && + (c != '-') && + (c != '=') && + (c != '\0') ) { + string[i++]=c; + if (c == '[') { + ptr++; + while ((c=*ptr) != ']') { + if (c == '\0') { + sprintf(error_string, "No final bracket \"]\" for element name, %s.", string); + error_msg(error_string, CONTINUE); + return(ERROR); + } + string[i++]=c; + if (i >= MAX_LENGTH ) { + output_msg(OUTPUT_MESSAGE, + "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", + MAX_LENGTH,string); + return(ERROR); + } + ptr++; + } + string[i++]=c; + } + + /* check for overflow of space */ + if (i >= MAX_LENGTH ) { + output_msg(OUTPUT_MESSAGE, + "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", + MAX_LENGTH,string); + return(ERROR); + } + ptr++; + } + string[i]='\0'; + ltoken=i; +/* + * Check for an empty string + */ + if(i == 0){ + sprintf(error_string, "NULL string detected in get_token, %s.",rest); + error_msg(error_string, CONTINUE); + return(ERROR); + } +/* + * End of token is = or \0, charge is zero + */ + if(c == '=' || c == '\0'){ + *eqnaddr=ptr; + lcharge=0; + *z=0.0; + } else { +/* + * Copy characters into charge until next species or end is detected + */ + j=0; + ptr1=ptr; + while( (isalpha((int) (c=*ptr1)) == FALSE) && + (c != '(') && + (c != ')') && + (c != ']') && + (c != '[') && + (c != '=') && + (c != '\0') ) { + charge[j++]=c; + /* error if no more space */ + if (j >= MAX_LENGTH ) { + error_msg("The charge on a species has exceeded MAX_LENGTH characters.", CONTINUE); + return(ERROR); + } + ptr1++; + } +/* + * Go back to last + or - if not end of side, + * everything before the last + or - in charge is part of the charge + */ + if( (c != '=') && (c != '\0') ) { + while( ((c=*ptr1) != '+') && (c != '-') ) { + j--; + ptr1--; + } + } + charge[j]='\0'; + lcharge=j; + *eqnaddr=ptr1; +/* + * Charge has been written, now need to check if charge has legal format + */ + if ( get_charge( charge, z) == OK ) { + strcat( string, charge); + } else { + return(ERROR); + } + } + *l=ltoken+lcharge; + return(OK); +} +/* ---------------------------------------------------------------------- */ +int isamong(char c, const char *s_l) +/* ---------------------------------------------------------------------- */ +/* + * Function checks if c is among the characters in the string s + * + * Arguments: + * c input, character to check + * *s string of characters + * + * Returns: + * TRUE if c is in set, + * FALSE if c in not in set. + */ +{ + int i; + + for (i=0; s_l[i] != '\0'; i++) { + if (c == s_l[i]) { + return(TRUE); + } + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +int islegit(const char c) +/* ---------------------------------------------------------------------- */ +/* + * Function checks for legal characters for chemical equations + * + * Argument: + * c input, character to check + * + * Returns: + * TRUE if c is in set, + * FALSE if c in not in set. + */ +{ + if( isalpha((int) c) || + isdigit((int) c) || + isamong(c,"+-=().:_[]") ){ + return(TRUE); + } + return(FALSE); +} +/* ---------------------------------------------------------------------- */ +void malloc_error (void) +/* ---------------------------------------------------------------------- */ +{ + error_msg("NULL pointer returned from malloc or realloc.", + CONTINUE); + error_msg("Program terminating.", STOP); + return; +} +/* ---------------------------------------------------------------------- */ +int parse_couple(char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Parse couple puts redox couples in standard form + * "+" is removed and couples are rewritten in sort + * order. + */ + int e1, e2, p1, p2; + char *ptr; + char elt1[MAX_LENGTH], elt2[MAX_LENGTH], paren1[MAX_LENGTH], paren2[MAX_LENGTH]; + + if (strcmp_nocase_arg1(token,"pe") == 0) { + str_tolower(token); + return(OK); + } + while (replace("+","",token) == TRUE); + ptr=token; + get_elt( &ptr, elt1, &e1); + if (*ptr != '(') { + sprintf(error_string, "Element name must be followed by " + "parentheses in redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return(ERROR); + } + paren_count=1; + paren1[0]='('; + p1=1; + while ( ptr != '\0') { + ptr++; + if (*ptr == '/' || *ptr == '\0') { + sprintf(error_string, "End of line or ""/"" encountered before end of parentheses, %s.", token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + paren1[p1++]=*ptr; + if (*ptr == '(') paren_count++; + if (*ptr == ')') paren_count--; + if (paren_count == 0) break; + } + paren1[p1]='\0'; + ptr++; + if (*ptr != '/') { + sprintf(error_string, " ""/"" must follow parentheses " + "ending first half of redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return(ERROR); + } + ptr++; + get_elt( &ptr, elt2, &e2); + if (strcmp(elt1,elt2) != 0) { + sprintf(error_string, "Redox couple must be two redox states " + "of the same element, %s.", token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + if (*ptr != '(') { + sprintf(error_string, "Element name must be followed by " + "parentheses in redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return(ERROR); + } + paren2[0]='('; + paren_count=1; + p2=1; + while ( *ptr != '\0') { + ptr++; + if (*ptr == '/' || *ptr == '\0') { + sprintf(error_string, "End of line or ""/"" encountered" + " before end of parentheses, %s.", token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + + paren2[p2++]=*ptr; + if (*ptr == '(') paren_count++; + if (*ptr == ')') paren_count--; + if (paren_count == 0) break; + } + paren2[p2]='\0'; + if (strcmp(paren1,paren2) < 0) { + strcpy(token,elt1); + strcat(token,paren1); + strcat(token,"/"); + strcat(token,elt2); + strcat(token,paren2); + } else if (strcmp(paren1,paren2) > 0) { + strcpy(token,elt2); + strcat(token,paren2); + strcat(token,"/"); + strcat(token,elt1); + strcat(token,paren1); + } else { + sprintf(error_string, "Both parts of redox couple are the same, %s.",token); + error_msg(error_string, CONTINUE); + return(ERROR); + } + return(OK); +} +/* ---------------------------------------------------------------------- */ +int print_centered(const char *string) +/* ---------------------------------------------------------------------- */ +{ + int i, l, l1, l2; + char token[MAX_LENGTH]; + +#ifdef PHREEQ98 + if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) AddToCEntry((char*)string, 4, outputlinenr); +#endif + l = strlen(string); + l1 = (79 - l)/2; + l2 = 79 -l -l1; + for (i=0; i < l1; i++) token[i]='-'; + token[i]='\0'; + strcat(token, string); + for (i=0; i < l2; i++) token[i + l1 + l]='-'; + token[79] = '\0'; + output_msg(OUTPUT_MESSAGE,"%s\n\n",token); + return(OK); +} +/* ---------------------------------------------------------------------- */ +int replace(const char *str1, const char *str2, char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function replaces str1 with str2 in str + * + * Arguments: + * str1 search str for str1 + * str2 replace str1 if str1 found in str + * str string to be searched + * + * Returns + * TRUE if string was replaced + * FALSE if string was not replaced + */ + int l, l1, l2; + char *ptr_start; + + ptr_start=strstr(str, str1); +/* + * Str1 not found, return + */ + if (ptr_start == NULL) return(FALSE); +/* + * Str1 found, replace Str1 with Str2 + */ + l=strlen(str); + l1=strlen(str1); + l2=strlen(str2); +/* + * Make gap in str long enough for str2 + */ +#ifdef SKIP + if (l2 < l1) { + for (ptr = (ptr_start + l1); ptr < ptr_start + l; ptr++) { + ptr1= ptr + l2 - l1; + *ptr1=*ptr; + if (*ptr == '\0') break; + } + } else { + for ( ptr = (str+l); ptr >= ptr_start + l1; ptr--) { + ptr1=ptr+l2-l1; + *ptr1=*ptr; + } + } +#endif + /* The plus one includes the terminating NULL */ + memmove(ptr_start + l2, ptr_start + l1, l - (ptr_start - str + l1) + 1); +/* + * Copy str2 into str + */ +#ifdef SKIP + ptr1=ptr_start; + for (ptr = (char *) str2; *ptr != '\0'; ptr++) { + *ptr1=*ptr; + ptr1++; + } +#endif + memcpy(ptr_start, str2, l2); + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +void space (void **ptr, int i, int *max, int struct_size) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine has 4 functions, allocate space, reallocate space, test to + * determine whether space is available, and free space. + * + * Arguments: + * ptr pointer to malloced space + * i value for test + * i = INIT, allocates space + * i >= 0 && i < max, space is available, return + * i >= max, reallocate space + * i = FREE, free space. + * max maximum value for i with available space + * struct size size of structure to be allocated + */ +/* + * Return if space exists + */ + if ( ( i >= 0 ) && ( i + 1 < *max ) ) { + return; + } +/* + * Realloc space + */ + if ( i+1 >= *max ) { + if (*max > 1000) { + *max += 1000; + } else { + *max *= 2; + } + if (i+1 > *max) *max = i + 1; + *ptr = PHRQ_realloc( *ptr, (size_t) (*max)*struct_size ); + if (*ptr == NULL ) malloc_error(); + return; + } +/* + * Allocate space + */ + if ( i == INIT ) { +/* free(*ptr); */ + *ptr=PHRQ_malloc((size_t) (*max)*struct_size); + if (*ptr == NULL ) malloc_error(); + return; + } +/* + * Free space + */ +/* + if ( i == FREE ) { + free(*ptr); + return; + } + */ +/* + * Error + */ + error_msg("Illegal argument to function space.", CONTINUE); + error_msg("Program terminating.", STOP); + return; +} +/* ---------------------------------------------------------------------- */ +void squeeze_white(char *s_l) +/* ---------------------------------------------------------------------- */ +/* + * Delete all white space from string s + * + * Argument: + * *s_l input, character string, possibly containing white space + * output, character string with all white space removed + * + * Return: void + */ +{ + int i, j; + + for (i = j = 0; s_l[i] != '\0'; i++){ + if (! isspace((int) s_l[i])) s_l[j++]=s_l[i]; + } + s_l[j]='\0'; +} +/* ---------------------------------------------------------------------- */ +void str_tolower(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Replaces string, str, with same string, lower case + */ + char *ptr; + ptr=str; + while (*ptr != '\0') { + *ptr= (char) tolower(*ptr); + ptr++; + } +} +/* ---------------------------------------------------------------------- */ +void str_toupper(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Replaces string, str, with same string, lower case + */ + char *ptr; + ptr=str; + while (*ptr != '\0') { + *ptr= (char) toupper(*ptr); + ptr++; + } +} +/* ---------------------------------------------------------------------- */ +int strcmp_nocase(const char *str1, const char *str2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare two strings disregarding case + */ + int c1, c2; + while ((c1 = tolower(*str1++)) == (c2 = tolower(*str2++))) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} +/* ---------------------------------------------------------------------- */ +int strcmp_nocase_arg1(const char *str1, const char *str2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare two strings disregarding case + */ + int c1, c2; + while ((c1 = tolower(*str1++)) == (c2 = *str2++)) { + if (c1 == '\0') return(0); + } + if (c1 < c2) return(-1); + return(1); +} +/* ---------------------------------------------------------------------- */ +char * string_duplicate (const char *token) +/* ---------------------------------------------------------------------- */ +{ + int l; + char *str; + + if (token == NULL) return NULL; + l = strlen(token); + str = (char *) PHRQ_malloc((size_t) (l +1) * sizeof(char) ); + if (str == NULL) malloc_error(); + strcpy (str, token); + return(str); +} +/* ---------------------------------------------------------------------- */ +char *string_hsave (const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save character string str + * + * Arguments: + * str input string to save. + * l input, length of str + * + * Returns: + * starting address of saved string (str) + */ + char *new_string; + ENTRY item, *found_item; + + new_string = string_duplicate(str); + item.key = new_string; + item.data = new_string; + found_item = hsearch_multi(strings_hash_table, item, ENTER); + if (found_item->key == new_string) { + count_strings++; + return(new_string); + } + new_string = (char*) free_check_null(new_string); + return(found_item->key); +} +/* ---------------------------------------------------------------------- */ +LDBLE under (LDBLE xval) +/* ---------------------------------------------------------------------- */ +{ +/* + * Exponentiate a number, x, but censor large and small numbers + * log values less than MIN_LM are set to 0 + * log values greater than MAX_LM are set to 10**MAX_LM + */ +/* if (xval < MIN_LM) { */ + if (xval < -40.) { + return(0.0); + } +/* if (xval > MAX_LM) { */ + if (xval > 3.) { + return ( 1.0e3 ); +/* return ( pow (10.0, MAX_LM));*/ + } +/* return (pow (10.0, xval)); */ + return (exp (xval * LOG_10)); +} +/* ---------------------------------------------------------------------- */ +int backspace_screen (int spaces) +/* ---------------------------------------------------------------------- */ +{ + int i; + char token[MAX_LENGTH]; + for (i = 0; i < spaces; i++) { + token[i] = '\b'; + } + token[i] = '\0'; + output_msg(OUTPUT_SCREEN,"%s",token); + return(OK); +} +#ifndef PHREEQCI_GUI +/* ---------------------------------------------------------------------- */ +int status (int count, const char *str) +/* ---------------------------------------------------------------------- */ +{ + static int spinner; + char sim_str[20]; + char state_str[45]; + char spin_str[2]; +/* char all[MAX_LENGTH]; */ +#ifdef PHREEQ98 + if (ProcessMessages) ApplicationProcessMessages(); + if (stop_calculations == TRUE) error_msg("Execution canceled by user.", STOP); +#endif + + if (pr.status == FALSE || phast == TRUE) return(OK); + sprintf(sim_str,"Simulation %d.", simulation); + sprintf(state_str," "); + sprintf(spin_str," "); + + if (state == INITIALIZE) { + output_msg(OUTPUT_SCREEN,"\n%-80s","Initializing..."); + + status_on = TRUE; + return(OK); + } +/* + * If str is defined print it + */ + if (str != NULL) { + if (status_on == TRUE) { + backspace_screen(80); + } else { + status_on = TRUE; + } +#ifdef DOS + backspace_screen(80); + /* if (state == TRANSPORT ) backspace_screen(80); */ + output_msg(OUTPUT_SCREEN, "%-79s", str); +#else + output_msg(OUTPUT_SCREEN, "%-80s", str); +#endif + } else if (state != TRANSPORT && state != PHAST ) { + if (state == INITIAL_SOLUTION) { + sprintf(state_str, "Initial solution %d.", use.solution_ptr->n_user); + } else if (state == INITIAL_EXCHANGE) { + sprintf(state_str, "Initial exchange %d.", use.exchange_ptr->n_user); + } else if (state == INITIAL_SURFACE) { + sprintf(state_str, "Initial surface %d.", use.surface_ptr->n_user); + } else if (state == INVERSE) { + sprintf(state_str, "Inverse %d. Models = %d.", + use.inverse_ptr->n_user, count); + } else if (state == REACTION) { + if (use.kinetics_in == TRUE) { + sprintf(state_str, "Kinetic step %d.", reaction_step); + } else { + sprintf(state_str, "Reaction step %d.", reaction_step); + } + } else if (state == ADVECTION || state == TRANSPORT) { + if (state == ADVECTION) { + sprintf(state_str, "Advection, shift %d.", advection_step); + } else if (state == TRANSPORT) { + sprintf(state_str, "Transport, shift %d.", transport_step); + } + spinner++; + if (spinner == 1) { + spin_str[0] = '/'; + } else if (spinner == 2) { + spin_str[0] = '-'; + } else { + spin_str[0] = '\\'; + spinner = 0; + } + } + if (status_on == TRUE) { + backspace_screen(80); + } else { + status_on = TRUE; + } + if (use.kinetics_in == TRUE) { +#ifdef DOS + backspace_screen(80); + output_msg(OUTPUT_SCREEN, "%-15s%-27s%37s", sim_str, state_str, " "); +#else + output_msg(OUTPUT_SCREEN, "%-15s%-27s%38s", sim_str, state_str, " "); +#endif + + } else { +#ifdef DOS + backspace_screen(80); + output_msg(OUTPUT_SCREEN, "%-15s%-27s%1s%36s", sim_str, state_str, spin_str, " "); +#else + output_msg(OUTPUT_SCREEN, "%-15s%-27s%1s%37s", sim_str, state_str, spin_str, " "); +#endif + } + } + return(OK); +} +#endif /*PHREEQCI_GUI*/ +/* +** Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson. +** Coded into C, with minor code improvements, and with hsearch(3) interface, +** by ejp@ausmelb.oz, Jul 26, 1988: 13:16; +** also, hcreate/hdestroy routines added to simulate hsearch(3). +** +** These routines simulate hsearch(3) and family, with the important +** difference that the hash table is dynamic - can grow indefinitely +** beyond its original size (as supplied to hcreate()). +** +** Performance appears to be comparable to that of hsearch(3). +** The 'source-code' options referred to in hsearch(3)'s 'man' page +** are not implemented; otherwise functionality is identical. +** +** Compilation controls: +** DEBUG controls some informative traces, mainly for debugging. +** HASH_STATISTICS causes HashAccesses and HashCollisions to be maintained; +** when combined with DEBUG, these are displayed by hdestroy(). +** +** Problems & fixes to ejp@ausmelb.oz. WARNING: relies on pre-processor +** concatenation property, in probably unnecessary code 'optimisation'. +** Esmond Pitt, Austec (Asia/Pacific) Ltd +** ...!uunet.UU.NET!munnari!ausmelb!ejp,ejp@ausmelb.oz +*/ + +# include + +/* +** Fast arithmetic, relying on powers of 2, +** and on pre-processor concatenation property +*/ + +/* rewrote to remove MUL and DIV */ +#ifdef SKIP +# define MUL(x,y) ((x) << (y/**/Shift)) +# define DIV(x,y) ((x) >> (y/**/Shift)) +#endif +# define MOD(x,y) ((x) & ((y)-1)) + +/* +** local data templates +*/ + + +/* +** external routines +*/ + +/* +extern char *calloc(); +extern int free(); + */ +/* +** Entry points +*/ + + +/* +** Internal routines +*/ + +static Address Hash_multi(HashTable *Table, char *Key); +static void ExpandTable_multi(HashTable *Table); + +/* +** Local data +*/ + +#ifdef HASH_STATISTICS +static long HashAccesses, HashCollisions; +#endif + +/* +** Code +*/ + +int hcreate_multi(unsigned Count, HashTable **HashTable_ptr) +{ + int i; + HashTable *Table; + /* + ** Adjust Count to be nearest higher power of 2, + ** minimum SegmentSize, then convert into segments. + */ + i = SegmentSize; + while (i < (int) Count) + i <<= 1; +/* Count = DIV(i,SegmentSize); */ + Count = ((i) >> (SegmentSizeShift)); + + Table = (HashTable*) PHRQ_calloc(sizeof(HashTable),1); + *HashTable_ptr = Table; + + if (Table == NULL) + return(0); + /* + ** resets are redundant - done by calloc(3) + ** + Table->SegmentCount = Table->p = Table->KeyCount = 0; + */ + /* + ** Allocate initial 'i' segments of buckets + */ + for (i = 0; i < (int) Count; i++) + { + Table->Directory[i] = (Segment*)PHRQ_calloc(sizeof(Segment),SegmentSize); + if (Table->Directory[i] == NULL) + { + hdestroy_multi(Table); + return(0); + } + Table->SegmentCount++; + } +/* Table->maxp = MUL(Count,SegmentSize); */ + Table->maxp = (short) ((Count) << (SegmentSizeShift)); + Table->MinLoadFactor = 1; + Table->MaxLoadFactor = DefaultMaxLoadFactor; +#ifdef DEBUG + output_msg(OUTPUT_STDERR, + "[hcreate] Table %x Count %d maxp %d SegmentCount %d\n", + Table, + Count, + Table->maxp, + Table->SegmentCount + ); +#endif +#ifdef HASH_STATISTICS + HashAccesses = HashCollisions = 0; +#endif + return(1); +} + +void hdestroy_multi(HashTable *Table) +{ + int i,j; + Segment *seg; + Element *p,*q; + + if (Table != NULL) + { + for (i = 0; i < Table->SegmentCount; i++) + { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) { + for (j = 0; j < SegmentSize; j++) { + p = seg[j]; + while (p != NULL) { + q = p->Next; + free((void*)p); + p = q; + } + } + free(Table->Directory[i]); + } + } + free(Table); + /* Table = NULL; */ +#if defined(HASH_STATISTICS) && defined(DEBUG) + output_msg(OUTPUT_STDERR, + "[hdestroy] Accesses %ld Collisions %ld\n", + HashAccesses, + HashCollisions + ); +#endif + } +} + +ENTRY * hsearch_multi(HashTable *Table, ENTRY item, ACTION action) +/* ACTION FIND/ENTER */ +{ + Address h; + Segment *CurrentSegment; + int SegmentIndex; + int SegmentDir; + Segment *p,q; + + assert(Table != NULL); /* Kinder really than return(NULL); */ +#ifdef HASH_STATISTICS + HashAccesses++; +#endif + h = Hash_multi(Table, item.key); +/* SegmentDir = DIV(h,SegmentSize); */ + SegmentDir = ((h) >> (SegmentSizeShift)); + SegmentIndex = MOD(h,SegmentSize); + /* + ** valid segment ensured by Hash() + */ + CurrentSegment = Table->Directory[SegmentDir]; + assert(CurrentSegment != NULL); /* bad failure if tripped */ + p = &CurrentSegment[SegmentIndex]; + q = *p; + /* + ** Follow collision chain + */ + while (q != NULL && strcmp(q->Key,item.key)) + { + p = &q->Next; + q = *p; +#ifdef HASH_STATISTICS + HashCollisions++; +#endif + } + if ( + q != NULL /* found */ + || + action == FIND /* not found, search only */ + || + (q = (Element*)PHRQ_calloc(sizeof(Element),1)) + == + NULL /* not found, no room */ + ) + return((ENTRY*)q); + *p = q; /* link into chain */ + /* + ** Initialize new element + */ + q->Key = item.key; + q->Data =(char*) item.data; + /* + ** cleared by calloc(3) + q->Next = NULL; + */ + /* + ** Table over-full? + */ +/* if (++Table->KeyCount / MUL(Table->SegmentCount,SegmentSize) > Table->MaxLoadFactor) */ + if (++Table->KeyCount / ((Table->SegmentCount) << (SegmentSizeShift)) > Table->MaxLoadFactor) + ExpandTable_multi(Table); /* doesn't affect q */ + return((ENTRY*)q); +} + +/* +** Internal routines +*/ + +static Address Hash_multi(HashTable *Table, char *Key) +{ + Address h,address; + register unsigned char *k = (unsigned char*)Key; + + h = 0; + /* + ** Convert string to integer + */ + while (*k) + h = h*Prime1 ^ (*k++ - ' '); + h %= Prime2; + address = MOD(h,Table->maxp); + if (address < (unsigned long) Table->p) + address = MOD(h,(Table->maxp << 1)); /* h % (2*Table->maxp) */ + return(address); +} + +void ExpandTable_multi(HashTable *Table) +{ + Address NewAddress; + int OldSegmentIndex,NewSegmentIndex; + int OldSegmentDir,NewSegmentDir; + Segment *OldSegment,*NewSegment; + Element *Current,**Previous,**LastOfNew; + +/* if (Table->maxp + Table->p < MUL(DirectorySize,SegmentSize)) */ + if (Table->maxp + Table->p < ((DirectorySize) << (SegmentSizeShift))) + { + /* + ** Locate the bucket to be split + */ +/* OldSegmentDir = DIV(Table->p,SegmentSize); */ + OldSegmentDir = ((Table->p) >> (SegmentSizeShift)); + OldSegment = Table->Directory[OldSegmentDir]; + OldSegmentIndex = MOD(Table->p,SegmentSize); + /* + ** Expand address space; if necessary create a new segment + */ + NewAddress = Table->maxp + Table->p; +/* NewSegmentDir = DIV(NewAddress,SegmentSize); */ + NewSegmentDir = ((NewAddress) >> (SegmentSizeShift)); + NewSegmentIndex = MOD(NewAddress,SegmentSize); + if (NewSegmentIndex == 0) + Table->Directory[NewSegmentDir] = (Segment*)PHRQ_calloc(sizeof(Segment),SegmentSize); + NewSegment = Table->Directory[NewSegmentDir]; + /* + ** Adjust state variables + */ + Table->p++; + if (Table->p == Table->maxp) + { + Table->maxp <<= 1; /* Table->maxp *= 2 */ + Table->p = 0; + } + Table->SegmentCount++; + /* + ** Relocate records to the new bucket + */ + Previous = &OldSegment[OldSegmentIndex]; + Current = *Previous; + LastOfNew = &NewSegment[NewSegmentIndex]; + *LastOfNew = NULL; + while (Current != NULL) + { + if (Hash_multi(Table, Current->Key) == NewAddress) + { + /* + ** Attach it to the end of the new chain + */ + *LastOfNew = Current; + /* + ** Remove it from old chain + */ + *Previous = Current->Next; + LastOfNew = &Current->Next; + Current = Current->Next; + *LastOfNew = NULL; + } + else + { + /* + ** leave it on the old chain + */ + Previous = &Current->Next; + Current = Current->Next; + } + } + } +} + + +void free_hash_strings(HashTable *Table) +{ + int i,j; + Segment *seg; + Element *p,*q; + + if (Table != NULL) + { + for (i = 0; i < Table->SegmentCount; i++) + { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) { + for (j = 0; j < SegmentSize; j++) { + p = seg[j]; + while (p != NULL) { + q = p->Next; + p->Data = (char*) free_check_null((void*)p->Data); + p = q; + } + } + } + } +#if defined(HASH_STATISTICS) && defined(DEBUG) + output_msg(OUTPUT_STDERR, + "[hdestroy] Accesses %ld Collisions %ld\n", + HashAccesses, + HashCollisions + ); +#endif + } +} +/* ---------------------------------------------------------------------- */ +int string_trim (char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from left and right of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, start, end, length; + char *ptr_start; + + l=strlen(str); + /* + * leading whitespace + */ + for (i = 0; i < l; i++) { + if (isspace((int) str[i])) continue; + break; + } + if (i == l) return(EMPTY); + start = i; + ptr_start = &(str[i]); + /* + * trailing whitespace + */ + for (i = l-1; i >= 0; i--) { + if (isspace((int) str[i])) continue; + break; + } + end = i; + if (start == 0 && end == l) return(FALSE); + length = end - start + 1; + memmove((void *) str, (void *) ptr_start, (size_t) length); + str[length] = '\0'; + + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int string_trim_right (char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from right of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, end, length; + + l=strlen(str); + for (i = l-1; i >= 0; i--) { + if (isspace((int) str[i])) continue; + break; + } + end = i; + length = end + 1; + str[length] = '\0'; + if (end == 0) return(EMPTY); + if (end == l) return(FALSE); + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +int string_trim_left (char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from left of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, start, end, length; + char *ptr_start; + + l=strlen(str); + /* + * leading whitespace + */ + for (i = 0; i < l; i++) { + if (isspace((int) str[i])) continue; + break; + } + if (i == l) return(EMPTY); + start = i; + ptr_start = &(str[i]); + end = l; + if (start == 0 && end == l) return(FALSE); + length = end - start + 1; + memmove((void *) str, (void *) ptr_start, (size_t) length); + str[length] = '\0'; + + return(TRUE); +} +/* ---------------------------------------------------------------------- */ +char *string_pad (char *str, int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function returns new string padded to width i + * or returns str if longer + * Arguments: + * str string to pad + * + * Returns + * new string of with i + */ + int j, l, max; + char *str_ptr; + + l=strlen(str); + max = l; + if (l < i) max = i; + str_ptr = (char *) PHRQ_malloc((size_t) ((max+1) * sizeof(char))); + if (str_ptr == NULL) malloc_error(); + strcpy(str_ptr, str); + if (i > l) { + for (j = l; j < i; j++) { + str_ptr[j] = ' '; + } + str_ptr[i] = '\0'; + } + return(str_ptr); +} From dff0e3454b4d731f4392f1abf5a74f1f96f88480 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 15:40:24 +0000 Subject: [PATCH 0002/1077] House cleaning for phreeqcpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@787 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cpp => ReadClass.cxx | 0 SAXPhreeqc.cpp => SAXPhreeqc.cxx | 0 Sun/examples/ex1.log | 0 Sun/examples/ex1.out | 325 - Sun/examples/ex10.log | 0 Sun/examples/ex10.out | 9431 ------------------------------ Sun/examples/ex10.sel | 701 --- Sun/examples/ex11.log | 0 Sun/examples/ex11.out | 2858 --------- Sun/examples/ex11adv.sel | 125 - Sun/examples/ex11trn.sel | 125 - Sun/examples/ex12.log | 0 Sun/examples/ex12.out | 99 - Sun/examples/ex12.sel | 44 - Sun/examples/ex12a.log | 0 Sun/examples/ex12a.out | 188 - Sun/examples/ex12a.sel | 169 - Sun/examples/ex13a.log | 0 Sun/examples/ex13a.out | 310 - Sun/examples/ex13a.sel | 42 - Sun/examples/ex13b.log | 0 Sun/examples/ex13b.out | 430 -- Sun/examples/ex13b.sel | 42 - Sun/examples/ex13c.log | 0 Sun/examples/ex13c.out | 751 --- Sun/examples/ex13c.sel | 42 - Sun/examples/ex14.log | 0 Sun/examples/ex14.out | 3000 ---------- Sun/examples/ex14.sel | 202 - Sun/examples/ex15.log | 0 Sun/examples/ex15.out | 2299 -------- Sun/examples/ex15.sel | 78 - Sun/examples/ex16.log | 0 Sun/examples/ex16.out | 435 -- Sun/examples/ex17.log | 0 Sun/examples/ex17.out | 349 -- Sun/examples/ex18.log | 0 Sun/examples/ex18.out | 550 -- Sun/examples/ex2.log | 0 Sun/examples/ex2.out | 4037 ------------- Sun/examples/ex2.sel | 53 - Sun/examples/ex3.log | 0 Sun/examples/ex3.out | 789 --- Sun/examples/ex4.log | 0 Sun/examples/ex4.out | 478 -- Sun/examples/ex5.log | 0 Sun/examples/ex5.out | 942 --- Sun/examples/ex5.sel | 7 - Sun/examples/ex6.log | 0 Sun/examples/ex6.out | 3053 ---------- Sun/examples/ex6A-B.sel | 22 - Sun/examples/ex6C.sel | 9 - Sun/examples/ex7.log | 0 Sun/examples/ex7.out | 2819 --------- Sun/examples/ex7.sel | 27 - Sun/examples/ex8.log | 0 Sun/examples/ex8.out | 3612 ------------ Sun/examples/ex8.sel | 27 - Sun/examples/ex9.log | 0 Sun/examples/ex9.out | 1284 ---- Sun/examples/ex9.sel | 13 - advection.cpp | 103 - basic.cpp | 4400 -------------- basicsubs.cpp | 1774 ------ cl1.cpp | 753 --- cl1mp.cpp | 974 --- cvdense.cpp | 473 -- cvode.cpp | 3330 ----------- dense.cpp | 114 - dense.h | 298 - dw.cpp | 349 -- global.h | 1638 ------ input.cpp | 249 - input.h | 24 - integrate.cpp | 851 --- inverse.cpp | 3014 ---------- isotopes.cpp | 1540 ----- kinetics.cpp | 2288 -------- main.cpp | 140 - mainsubs.cpp | 2486 -------- model.cpp | 3102 ---------- nvector.cpp | 193 - nvector.h | 441 -- nvector_serial.cpp | 869 --- nvector_serial.h | 325 - output.cpp | 182 - output.h | 57 - p2c.h | 543 -- p2clib.cpp | 936 --- parse.cpp | 904 --- phqalloc.cpp | 246 - phreeqc_files.cpp | 524 -- phrqproto.h | 515 -- phrqtype.h | 19 - pitzer.cpp | 1587 ----- pitzer.h | 50 - pitzer_structures.cpp | 195 - prep.cpp | 4055 ------------- print.cpp | 2259 ------- read.cpp | 7904 ------------------------- readtr.cpp | 1121 ---- smalldense.cpp | 243 - smalldense.h | 224 - spread.cpp | 1069 ---- step.cpp | 1028 ---- structures.cpp | 6059 ------------------- sundialsmath.cpp | 76 - sundialsmath.h | 130 - sundialstypes.h | 144 - tally.cpp | 1006 ---- tidy.cpp | 3333 ----------- transport.cpp | 844 --- utilities.cpp | 1471 ----- 113 files changed, 106219 deletions(-) rename ReadClass.cpp => ReadClass.cxx (100%) rename SAXPhreeqc.cpp => SAXPhreeqc.cxx (100%) delete mode 100644 Sun/examples/ex1.log delete mode 100644 Sun/examples/ex1.out delete mode 100644 Sun/examples/ex10.log delete mode 100644 Sun/examples/ex10.out delete mode 100644 Sun/examples/ex10.sel delete mode 100644 Sun/examples/ex11.log delete mode 100644 Sun/examples/ex11.out delete mode 100644 Sun/examples/ex11adv.sel delete mode 100644 Sun/examples/ex11trn.sel delete mode 100644 Sun/examples/ex12.log delete mode 100644 Sun/examples/ex12.out delete mode 100644 Sun/examples/ex12.sel delete mode 100644 Sun/examples/ex12a.log delete mode 100644 Sun/examples/ex12a.out delete mode 100644 Sun/examples/ex12a.sel delete mode 100644 Sun/examples/ex13a.log delete mode 100644 Sun/examples/ex13a.out delete mode 100644 Sun/examples/ex13a.sel delete mode 100644 Sun/examples/ex13b.log delete mode 100644 Sun/examples/ex13b.out delete mode 100644 Sun/examples/ex13b.sel delete mode 100644 Sun/examples/ex13c.log delete mode 100644 Sun/examples/ex13c.out delete mode 100644 Sun/examples/ex13c.sel delete mode 100644 Sun/examples/ex14.log delete mode 100644 Sun/examples/ex14.out delete mode 100644 Sun/examples/ex14.sel delete mode 100644 Sun/examples/ex15.log delete mode 100644 Sun/examples/ex15.out delete mode 100644 Sun/examples/ex15.sel delete mode 100644 Sun/examples/ex16.log delete mode 100644 Sun/examples/ex16.out delete mode 100644 Sun/examples/ex17.log delete mode 100644 Sun/examples/ex17.out delete mode 100644 Sun/examples/ex18.log delete mode 100644 Sun/examples/ex18.out delete mode 100644 Sun/examples/ex2.log delete mode 100644 Sun/examples/ex2.out delete mode 100644 Sun/examples/ex2.sel delete mode 100644 Sun/examples/ex3.log delete mode 100644 Sun/examples/ex3.out delete mode 100644 Sun/examples/ex4.log delete mode 100644 Sun/examples/ex4.out delete mode 100644 Sun/examples/ex5.log delete mode 100644 Sun/examples/ex5.out delete mode 100644 Sun/examples/ex5.sel delete mode 100644 Sun/examples/ex6.log delete mode 100644 Sun/examples/ex6.out delete mode 100644 Sun/examples/ex6A-B.sel delete mode 100644 Sun/examples/ex6C.sel delete mode 100644 Sun/examples/ex7.log delete mode 100644 Sun/examples/ex7.out delete mode 100644 Sun/examples/ex7.sel delete mode 100644 Sun/examples/ex8.log delete mode 100644 Sun/examples/ex8.out delete mode 100644 Sun/examples/ex8.sel delete mode 100644 Sun/examples/ex9.log delete mode 100644 Sun/examples/ex9.out delete mode 100644 Sun/examples/ex9.sel delete mode 100644 advection.cpp delete mode 100644 basic.cpp delete mode 100644 basicsubs.cpp delete mode 100644 cl1.cpp delete mode 100644 cl1mp.cpp delete mode 100644 cvdense.cpp delete mode 100644 cvode.cpp delete mode 100644 dense.cpp delete mode 100644 dense.h delete mode 100644 dw.cpp delete mode 100644 global.h delete mode 100644 input.cpp delete mode 100644 input.h delete mode 100644 integrate.cpp delete mode 100644 inverse.cpp delete mode 100644 isotopes.cpp delete mode 100644 kinetics.cpp delete mode 100644 main.cpp delete mode 100644 mainsubs.cpp delete mode 100644 model.cpp delete mode 100644 nvector.cpp delete mode 100644 nvector.h delete mode 100644 nvector_serial.cpp delete mode 100644 nvector_serial.h delete mode 100644 output.cpp delete mode 100644 output.h delete mode 100644 p2c.h delete mode 100644 p2clib.cpp delete mode 100644 parse.cpp delete mode 100644 phqalloc.cpp delete mode 100644 phreeqc_files.cpp delete mode 100644 phrqproto.h delete mode 100644 phrqtype.h delete mode 100644 pitzer.cpp delete mode 100644 pitzer.h delete mode 100644 pitzer_structures.cpp delete mode 100644 prep.cpp delete mode 100644 print.cpp delete mode 100644 read.cpp delete mode 100644 readtr.cpp delete mode 100644 smalldense.cpp delete mode 100644 smalldense.h delete mode 100644 spread.cpp delete mode 100644 step.cpp delete mode 100644 structures.cpp delete mode 100644 sundialsmath.cpp delete mode 100644 sundialsmath.h delete mode 100644 sundialstypes.h delete mode 100644 tally.cpp delete mode 100644 tidy.cpp delete mode 100644 transport.cpp delete mode 100644 utilities.cpp diff --git a/ReadClass.cpp b/ReadClass.cxx similarity index 100% rename from ReadClass.cpp rename to ReadClass.cxx diff --git a/SAXPhreeqc.cpp b/SAXPhreeqc.cxx similarity index 100% rename from SAXPhreeqc.cpp rename to SAXPhreeqc.cxx diff --git a/Sun/examples/ex1.log b/Sun/examples/ex1.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex1.out b/Sun/examples/ex1.out deleted file mode 100644 index 658d1320..00000000 --- a/Sun/examples/ex1.out +++ /dev/null @@ -1,325 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex1 - Output file: ex1.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 1.--Add uranium and speciate seawater. - SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979) - units ppm - pH 8.22 - pe 8.451 - density 1.023 - temp 25.0 - redox O(0)/O(-2) - Ca 412.3 - Mg 1291.8 - Na 10768.0 - K 399.1 - Fe 0.002 - Mn 0.0002 pe - Si 4.28 - Cl 19353.0 - Alkalinity 141.682 as HCO3 - S(6) 2712.0 - N(5) 0.29 gfw 62.0 - N(-3) 0.03 as NH4 - U 3.3 ppb N(5)/N(-3) - O(0) 1.0 O2(g) -0.7 - SOLUTION_MASTER_SPECIES - U U+4 0.0 238.0290 238.0290 - U(4) U+4 0.0 238.0290 - U(5) UO2+ 0.0 238.0290 - U(6) UO2+2 0.0 238.0290 - SOLUTION_SPECIES - U+4 = U+4 - log_k 0.0 - U+4 + 4 H2O = U(OH)4 + 4 H+ - log_k -8.538 - delta_h 24.760 kcal - U+4 + 5 H2O = U(OH)5- + 5 H+ - log_k -13.147 - delta_h 27.580 kcal - U+4 + 2 H2O = UO2+ + 4 H+ + e- - log_k -6.432 - delta_h 31.130 kcal - U+4 + 2 H2O = UO2+2 + 4 H+ + 2 e- - log_k -9.217 - delta_h 34.430 kcal - UO2+2 + H2O = UO2OH+ + H+ - log_k -5.782 - delta_h 11.015 kcal - 2UO2+2 + 2H2O = (UO2)2(OH)2+2 + 2H+ - log_k -5.626 - delta_h -36.04 kcal - 3UO2+2 + 5H2O = (UO2)3(OH)5+ + 5H+ - log_k -15.641 - delta_h -44.27 kcal - UO2+2 + CO3-2 = UO2CO3 - log_k 10.064 - delta_h 0.84 kcal - UO2+2 + 2CO3-2 = UO2(CO3)2-2 - log_k 16.977 - delta_h 3.48 kcal - UO2+2 + 3CO3-2 = UO2(CO3)3-4 - log_k 21.397 - delta_h -8.78 kcal - PHASES - Uraninite - UO2 + 4 H+ = U+4 + 2 H2O - log_k -3.490 - delta_h -18.630 kcal - END ------ -TITLE ------ - - Example 1.--Add uranium and speciate seawater. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. SEAWATER FROM NORDSTROM ET AL. (1979) - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Alkalinity 2.406e-03 2.406e-03 - Ca 1.066e-02 1.066e-02 - Cl 5.657e-01 5.657e-01 - Fe 3.711e-08 3.711e-08 - K 1.058e-02 1.058e-02 - Mg 5.507e-02 5.507e-02 - Mn 3.773e-09 3.773e-09 - N(-3) 1.724e-06 1.724e-06 - N(5) 4.847e-06 4.847e-06 - Na 4.854e-01 4.854e-01 - O(0) 3.746e-04 3.746e-04 Equilibrium with O2(g) - S(6) 2.926e-02 2.926e-02 - Si 7.382e-05 7.382e-05 - U 1.437e-08 1.437e-08 - -----------------------------Description of solution---------------------------- - - pH = 8.220 - pe = 8.451 - Activity of water = 0.981 - Ionic strength = 6.748e-01 - Mass of water (kg) = 1.000e+00 - Total carbon (mol/kg) = 2.180e-03 - Total CO2 (mol/kg) = 2.180e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.936e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.07 - Iterations = 7 - Total H = 1.110147e+02 - Total O = 5.563047e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - N(-3)/N(5) 4.6750 0.2766 - O(-2)/O(0) 12.3893 0.7329 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.674e-06 1.629e-06 -5.573 -5.788 -0.215 - H+ 7.981e-09 6.026e-09 -8.098 -8.220 -0.122 - H2O 5.551e+01 9.806e-01 1.744 -0.009 0.000 -C(4) 2.180e-03 - HCO3- 1.514e-03 1.023e-03 -2.820 -2.990 -0.170 - MgHCO3+ 2.195e-04 1.640e-04 -3.658 -3.785 -0.127 - NaHCO3 1.667e-04 1.948e-04 -3.778 -3.710 0.067 - MgCO3 8.913e-05 1.041e-04 -4.050 -3.982 0.067 - NaCO3- 6.718e-05 5.020e-05 -4.173 -4.299 -0.127 - CaHCO3+ 4.597e-05 3.106e-05 -4.337 -4.508 -0.170 - CO3-2 3.821e-05 7.959e-06 -4.418 -5.099 -0.681 - CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 - CO2 1.210e-05 1.413e-05 -4.917 -4.850 0.067 - UO2(CO3)3-4 1.255e-08 1.184e-10 -7.901 -9.927 -2.025 - UO2(CO3)2-2 1.814e-09 5.653e-10 -8.741 -9.248 -0.506 - MnCO3 2.696e-10 3.150e-10 -9.569 -9.502 0.067 - MnHCO3+ 6.077e-11 4.541e-11 -10.216 -10.343 -0.127 - UO2CO3 7.429e-12 8.678e-12 -11.129 -11.062 0.067 - FeCO3 1.952e-20 2.281e-20 -19.709 -19.642 0.067 - FeHCO3+ 1.635e-20 1.222e-20 -19.786 -19.913 -0.127 -Ca 1.066e-02 - Ca+2 9.504e-03 2.380e-03 -2.022 -2.623 -0.601 - CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 - CaHCO3+ 4.597e-05 3.106e-05 -4.337 -4.508 -0.170 - CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 - CaOH+ 8.604e-08 6.429e-08 -7.065 -7.192 -0.127 - CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 -Cl 5.657e-01 - Cl- 5.657e-01 3.528e-01 -0.247 -0.452 -0.205 - MnCl+ 9.582e-10 7.160e-10 -9.019 -9.145 -0.127 - MnCl2 9.439e-11 1.103e-10 -10.025 -9.958 0.067 - MnCl3- 1.434e-11 1.071e-11 -10.844 -10.970 -0.127 - FeCl+2 9.557e-19 2.978e-19 -18.020 -18.526 -0.506 - FeCl2+ 6.281e-19 4.693e-19 -18.202 -18.329 -0.127 - FeCl+ 7.786e-20 5.817e-20 -19.109 -19.235 -0.127 - FeCl3 1.417e-20 1.656e-20 -19.849 -19.781 0.067 -Fe(2) 6.909e-19 - Fe+2 5.205e-19 1.195e-19 -18.284 -18.923 -0.639 - FeCl+ 7.786e-20 5.817e-20 -19.109 -19.235 -0.127 - FeSO4 4.845e-20 5.660e-20 -19.315 -19.247 0.067 - FeCO3 1.952e-20 2.281e-20 -19.709 -19.642 0.067 - FeHCO3+ 1.635e-20 1.222e-20 -19.786 -19.913 -0.127 - FeOH+ 8.227e-21 6.147e-21 -20.085 -20.211 -0.127 - FeHSO4+ 3.000e-27 2.242e-27 -26.523 -26.649 -0.127 -Fe(3) 3.711e-08 - Fe(OH)3 2.841e-08 3.318e-08 -7.547 -7.479 0.067 - Fe(OH)4- 6.591e-09 4.924e-09 -8.181 -8.308 -0.127 - Fe(OH)2+ 2.118e-09 1.583e-09 -8.674 -8.801 -0.127 - FeOH+2 9.425e-14 2.937e-14 -13.026 -13.532 -0.506 - FeSO4+ 1.093e-18 8.167e-19 -17.961 -18.088 -0.127 - FeCl+2 9.557e-19 2.978e-19 -18.020 -18.526 -0.506 - FeCl2+ 6.281e-19 4.693e-19 -18.202 -18.329 -0.127 - Fe+3 3.509e-19 2.796e-20 -18.455 -19.554 -1.099 - Fe(SO4)2- 6.372e-20 4.761e-20 -19.196 -19.322 -0.127 - FeCl3 1.417e-20 1.656e-20 -19.849 -19.781 0.067 - Fe2(OH)2+4 2.462e-24 2.322e-26 -23.609 -25.634 -2.025 - FeHSO4+2 4.228e-26 1.318e-26 -25.374 -25.880 -0.506 - Fe3(OH)4+5 1.122e-29 7.679e-33 -28.950 -32.115 -3.165 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.436 -44.369 0.067 -K 1.058e-02 - K+ 1.042e-02 6.495e-03 -1.982 -2.187 -0.205 - KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 - KOH 3.137e-09 3.665e-09 -8.503 -8.436 0.067 -Mg 5.507e-02 - Mg+2 4.742e-02 1.371e-02 -1.324 -1.863 -0.539 - MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 - MgHCO3+ 2.195e-04 1.640e-04 -3.658 -3.785 -0.127 - MgCO3 8.913e-05 1.041e-04 -4.050 -3.982 0.067 - MgOH+ 1.084e-05 8.100e-06 -4.965 -5.092 -0.127 -Mn(2) 3.773e-09 - Mn+2 2.171e-09 4.982e-10 -8.663 -9.303 -0.639 - MnCl+ 9.582e-10 7.160e-10 -9.019 -9.145 -0.127 - MnCO3 2.696e-10 3.150e-10 -9.569 -9.502 0.067 - MnSO4 2.021e-10 2.360e-10 -9.695 -9.627 0.067 - MnCl2 9.439e-11 1.103e-10 -10.025 -9.958 0.067 - MnHCO3+ 6.077e-11 4.541e-11 -10.216 -10.343 -0.127 - MnCl3- 1.434e-11 1.071e-11 -10.844 -10.970 -0.127 - MnOH+ 2.789e-12 2.084e-12 -11.555 -11.681 -0.127 - Mn(NO3)2 1.375e-20 1.607e-20 -19.862 -19.794 0.067 -Mn(3) 5.993e-26 - Mn+3 5.993e-26 4.349e-27 -25.222 -26.362 -1.139 -N(-3) 1.724e-06 - NH4+ 1.609e-06 9.049e-07 -5.794 -6.043 -0.250 - NH3 7.326e-08 8.558e-08 -7.135 -7.068 0.067 - NH4SO4- 4.157e-08 3.106e-08 -7.381 -7.508 -0.127 -N(5) 4.847e-06 - NO3- 4.847e-06 2.846e-06 -5.314 -5.546 -0.231 - Mn(NO3)2 1.375e-20 1.607e-20 -19.862 -19.794 0.067 -Na 4.854e-01 - Na+ 4.791e-01 3.387e-01 -0.320 -0.470 -0.151 - NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 - NaHCO3 1.667e-04 1.948e-04 -3.778 -3.710 0.067 - NaCO3- 6.718e-05 5.020e-05 -4.173 -4.299 -0.127 - NaOH 3.117e-07 3.641e-07 -6.506 -6.439 0.067 -O(0) 3.746e-04 - O2 1.873e-04 2.188e-04 -3.727 -3.660 0.067 -S(6) 2.926e-02 - SO4-2 1.463e-02 2.664e-03 -1.835 -2.574 -0.740 - MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 - NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 - CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 - KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 - NH4SO4- 4.157e-08 3.106e-08 -7.381 -7.508 -0.127 - HSO4- 2.089e-09 1.561e-09 -8.680 -8.807 -0.127 - MnSO4 2.021e-10 2.360e-10 -9.695 -9.627 0.067 - CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 - FeSO4+ 1.093e-18 8.167e-19 -17.961 -18.088 -0.127 - Fe(SO4)2- 6.372e-20 4.761e-20 -19.196 -19.322 -0.127 - FeSO4 4.845e-20 5.660e-20 -19.315 -19.247 0.067 - FeHSO4+2 4.228e-26 1.318e-26 -25.374 -25.880 -0.506 - FeHSO4+ 3.000e-27 2.242e-27 -26.523 -26.649 -0.127 -Si 7.382e-05 - H4SiO4 7.110e-05 8.306e-05 -4.148 -4.081 0.067 - H3SiO4- 2.720e-06 2.032e-06 -5.565 -5.692 -0.127 - H2SiO4-2 7.362e-11 2.294e-11 -10.133 -10.639 -0.506 -U(4) 1.034e-21 - U(OH)5- 1.034e-21 7.725e-22 -20.985 -21.112 -0.127 - U(OH)4 1.652e-25 1.930e-25 -24.782 -24.715 0.067 - U+4 0.000e+00 0.000e+00 -46.997 -49.022 -2.025 -U(5) 1.622e-18 - UO2+ 1.622e-18 1.212e-18 -17.790 -17.916 -0.127 -U(6) 1.437e-08 - UO2(CO3)3-4 1.255e-08 1.184e-10 -7.901 -9.927 -2.025 - UO2(CO3)2-2 1.814e-09 5.653e-10 -8.741 -9.248 -0.506 - UO2CO3 7.429e-12 8.678e-12 -11.129 -11.062 0.067 - UO2OH+ 3.385e-14 2.530e-14 -13.470 -13.597 -0.127 - UO2+2 3.019e-16 9.409e-17 -15.520 -16.026 -0.506 - (UO2)2(OH)2+2 1.780e-21 5.547e-22 -20.750 -21.256 -0.506 - (UO2)3(OH)5+ 2.908e-23 2.173e-23 -22.536 -22.663 -0.127 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.84 -5.20 -4.36 CaSO4 - Aragonite 0.61 -7.72 -8.34 CaCO3 - Calcite 0.76 -7.72 -8.48 CaCO3 - Chalcedony -0.51 -4.06 -3.55 SiO2 - Chrysotile 3.36 35.56 32.20 Mg3Si2O5(OH)4 - CO2(g) -3.38 -4.85 -1.47 CO2 - Dolomite 2.41 -14.68 -17.09 CaMg(CO3)2 - Fe(OH)3(a) 0.19 5.08 4.89 Fe(OH)3 - Goethite 6.09 5.09 -1.00 FeOOH - Gypsum -0.63 -5.21 -4.58 CaSO4:2H2O - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.52 -0.01 1.51 H2O - Halite -2.50 -0.92 1.58 NaCl - Hausmannite 1.57 62.60 61.03 Mn3O4 - Hematite 14.20 10.19 -4.01 Fe2O3 - Jarosite-K -7.52 -16.73 -9.21 KFe3(SO4)2(OH)6 - Manganite 2.39 27.73 25.34 MnOOH - Melanterite -19.35 -21.56 -2.21 FeSO4:7H2O - NH3(g) -8.84 -7.07 1.77 NH3 - O2(g) -0.70 -3.66 -2.96 O2 - Pyrochroite -8.08 7.12 15.20 Mn(OH)2 - Pyrolusite 6.96 48.34 41.38 MnO2 - Quartz -0.08 -4.06 -3.98 SiO2 - Rhodochrosite -3.27 -14.40 -11.13 MnCO3 - Sepiolite 1.16 16.92 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -1.74 16.92 18.66 Mg2Si3O7.5OH:3H2O - Siderite -13.13 -24.02 -10.89 FeCO3 - SiO2(a) -1.35 -4.06 -2.71 SiO2 - Talc 6.04 27.44 21.40 Mg3Si4O10(OH)2 - Uraninite -12.67 -16.16 -3.49 UO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex10.log b/Sun/examples/ex10.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex10.out b/Sun/examples/ex10.out deleted file mode 100644 index 3b193583..00000000 --- a/Sun/examples/ex10.out +++ /dev/null @@ -1,9431 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex10 - Output file: ex10.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 10.--Solid solution of strontianite and aragonite. - PHASES - Strontianite - SrCO3 = CO3-2 + Sr+2 - log_k -9.271 - Aragonite - CaCO3 = CO3-2 + Ca+2 - log_k -8.336 - END ------ -TITLE ------ - - Example 10.--Solid solution of strontianite and aragonite. - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLID_SOLUTIONS 1 - Ca(x)Sr(1-x)CO3 - comp1 Aragonite 0 - comp2 Strontianite 0 - gugg_nondimensional 3.43 -1.82 - END ---------------------------------------------- -Description of Solid Solution Ca(x)Sr(1-x)CO3 ---------------------------------------------- - - Temperature: 298.15 kelvin - A0 (dimensionless): 3.43 - A1 (dimensionless): -1.82 - A0 (kJ/mol): 8.50307 - A1 (kJ/mol): -4.51183 - - Critical mole-fraction of component 2: 0.297625 - Critical temperature: 703.036 kelvin - -(The critical temperature calculation assumes that the Guggenheim model -defined at 298.15 kelvin is valid at the critical temperature.) - - - Spinodal-gap mole fractions, component 2: 0.0654427 0.619798 - Miscibility-gap fractions, component 2: 0.0048032 0.857863 - - Eutectic Point Calculations - - Aqueous activity ratio (comp2/comp1): 0.0981043 - Log aqueous activity ratio (comp2/comp1): -1.00831 - Aqueous activity fraction of component 2: 0.0893397 - Log IAP (component 2): -9.34631 - Log IAP (component 1): -8.338 - Log Sum Pi: -8.29736 - -Local minimum in the solidus curve coresponding to a maximum -in the minimum stoichiometric saturation curve. - - Solid mole fraction of component 2: 0.198353 - Log IAP (component 2): -8.91133 - Log IAP (component 1): -8.30479 - Log Sum Pi: -8.20877 ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - SOLUTION 1 - units mmol/kgw - pH 5.93 charge - Ca 3.932 - C 7.864 - EQUILIBRIUM_PHASES 1 - CO2(g) -0.01265 10 - Aragonite - SAVE solution 1 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 7.864e-03 7.864e-03 - Ca 3.932e-03 3.932e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.969 Charge balance - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.105e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 7.864e-03 - Total CO2 (mol/kg) = 7.864e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.985e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 9 - Total H = 1.110200e+02 - Total O = 5.552965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.039e-06 9.312e-07 -5.983 -6.031 -0.048 - H+ 1.181e-08 1.075e-08 -7.928 -7.969 -0.041 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -75.157 -75.156 0.001 -C(4) 7.864e-03 - HCO3- 7.325e-03 6.602e-03 -2.135 -2.180 -0.045 - CaHCO3+ 2.216e-04 1.997e-04 -3.654 -3.700 -0.045 - CO2 1.592e-04 1.596e-04 -3.798 -3.797 0.001 - CaCO3 1.145e-04 1.147e-04 -3.941 -3.940 0.001 - CO3-2 4.365e-05 2.881e-05 -4.360 -4.541 -0.181 -Ca 3.932e-03 - Ca+2 3.596e-03 2.371e-03 -2.444 -2.625 -0.181 - CaHCO3+ 2.216e-04 1.997e-04 -3.654 -3.700 -0.045 - CaCO3 1.145e-04 1.147e-04 -3.941 -3.940 0.001 - CaOH+ 4.077e-08 3.661e-08 -7.390 -7.436 -0.047 -H(0) 1.632e-27 - H2 8.158e-28 8.179e-28 -27.088 -27.087 0.001 -O(0) 1.243e-38 - O2 6.213e-39 6.229e-39 -38.207 -38.206 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 1.17 -7.17 -8.34 CaCO3 - Calcite 1.31 -7.17 -8.48 CaCO3 - CH4(g) -72.30 -75.16 -2.86 CH4 - CO2(g) -2.33 -3.80 -1.47 CO2 - H2(g) -23.94 -27.09 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -35.25 -38.21 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Aragonite 0.00 -8.34 -8.34 1.000e+01 9.993e+00 -6.605e-03 - CO2(g) -0.01 -18.16 -18.15 1.000e+01 9.961e+00 -3.944e-02 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.392e-02 5.391e-02 - Ca 1.054e-02 1.054e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.063 Charge balance - pe = 11.813 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 2.906e-02 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 2.108e-02 - Total CO2 (mol/kg) = 5.392e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.292e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 10 - Total H = 1.110200e+02 - Total O = 5.562835e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.885e-07 8.654e-07 -6.005 -6.063 -0.058 - OH- 1.366e-08 1.155e-08 -7.865 -7.937 -0.073 - H2O 5.551e+01 9.989e-01 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -120.096 -120.093 0.003 -C(4) 5.392e-02 - CO2 3.285e-02 3.307e-02 -1.483 -1.481 0.003 - HCO3- 1.979e-02 1.698e-02 -1.703 -1.770 -0.067 - CaHCO3+ 1.266e-03 1.086e-03 -2.897 -2.964 -0.067 - CaCO3 7.698e-06 7.750e-06 -5.114 -5.111 0.003 - CO3-2 1.700e-06 9.199e-07 -5.770 -6.036 -0.267 -Ca 1.054e-02 - Ca+2 9.265e-03 5.015e-03 -2.033 -2.300 -0.267 - CaHCO3+ 1.266e-03 1.086e-03 -2.897 -2.964 -0.067 - CaCO3 7.698e-06 7.750e-06 -5.114 -5.111 0.003 - CaOH+ 1.128e-09 9.606e-10 -8.948 -9.017 -0.070 -H(0) 2.496e-39 - H2 1.248e-39 1.257e-39 -38.904 -38.901 0.003 -O(0) 5.234e-15 - O2 2.617e-15 2.635e-15 -14.582 -14.579 0.003 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.00 -8.34 -8.34 CaCO3 - Calcite 0.14 -8.34 -8.48 CaCO3 - CH4(g) -117.23 -120.09 -2.86 CH4 - CO2(g) -0.01 -1.48 -1.47 CO2 - H2(g) -35.75 -38.90 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -11.62 -14.58 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - USE solution 1 - USE solid_solution 1 - REACTION 1 - SrCO3 1.0 - .005 in 500 steps - PRINT - reset false - user_print true - USER_PRINT - start - 10 sum = (S_S("Strontianite") + S_S("Aragonite")) - 20 if sum = 0 THEN GOTO 110 - 30 xb = S_S("Strontianite")/sum - 40 xc = S_S("Aragonite")/sum - 50 PRINT "Simulation number: ", SIM_NO - 60 PRINT "Reaction step number: ", STEP_NO - 70 PRINT "SrCO3 added: ", RXN - 80 PRINT "Log Sigma pi: ", LOG10 (ACT("CO3-2") * (ACT("Ca+2") + ACT("Sr+2"))) - 90 PRINT "XAragonite: ", xc - 100 PRINT "XStrontianite: ", xb - 110 PRINT "XCa: ", TOT("Ca")/(TOT("Ca") + TOT("Sr")) - 120 PRINT "XSr: ", TOT("Sr")/(TOT("Ca") + TOT("Sr")) - 130 PRINT "Misc 1: ", MISC1("Ca(x)Sr(1-x)CO3") - 140 PRINT "Misc 2: ", MISC2("Ca(x)Sr(1-x)CO3") - end - SELECTED_OUTPUT - file ex10.sel - reset false - reaction true - USER_PUNCH - heading lg_SigmaPi X_Arag X_Stront X_Ca_aq X_Sr_aq mol_Misc1 mol_Misc2 mol_Arag mol_Stront - start - 10 sum = (S_S("Strontianite") + S_S("Aragonite")) - 20 if sum = 0 THEN GOTO 60 - 30 xb = S_S("Strontianite")/(S_S("Strontianite") + S_S("Aragonite")) - 40 xc = S_S("Aragonite")/(S_S("Strontianite") + S_S("Aragonite")) - 50 REM Sigma Pi - 60 PUNCH LOG10(ACT("CO3-2") * (ACT("Ca+2") + ACT("Sr+2"))) - 70 PUNCH xc # Mole fraction aragonite - 80 PUNCH xb # Mole fraction strontianite - 90 PUNCH TOT("Ca")/(TOT("Ca") + TOT("Sr")) # Mole aqueous calcium - 100 PUNCH TOT("Sr")/(TOT("Ca") + TOT("Sr")) # Mole aqueous strontium - 110 x1 = MISC1("Ca(x)Sr(1-x)CO3") - 120 x2 = MISC2("Ca(x)Sr(1-x)CO3") - 130 if (xb < x1 OR xb > x2) THEN GOTO 250 - 140 nc = S_S("Aragonite") - 150 nb = S_S("Strontianite") - 160 mol2 = ((x1 - 1)/x1)*nb + nc - 170 mol2 = mol2 / ( ((x1 -1)/x1)*x2 + (1 - x2)) - 180 mol1 = (nb - mol2*x2)/x1 - 190 REM # Moles of misc. end members if in gap - 200 PUNCH mol1 - 210 PUNCH mol2 - 220 GOTO 300 - 250 REM # Moles of misc. end members if not in gap - 260 PUNCH 1e-10 - 270 PUNCH 1e-10 - 300 PUNCH S_S("Aragonite") # Moles aragonite - 310 PUNCH S_S("Strontianite") # Moles Strontianite - end - END -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 1 -SrCO3 added: 1.0000e-05 -Log Sigma pi: -8.3356e+00 -XAragonite: 9.9996e-01 -XStrontianite: 4.2096e-05 -XCa: 9.9905e-01 -XSr: 9.4867e-04 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 2 -SrCO3 added: 2.0000e-05 -Log Sigma pi: -8.3352e+00 -XAragonite: 9.9992e-01 -XStrontianite: 8.4301e-05 -XCa: 9.9810e-01 -XSr: 1.8967e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 3 -SrCO3 added: 3.0000e-05 -Log Sigma pi: -8.3348e+00 -XAragonite: 9.9987e-01 -XStrontianite: 1.2662e-04 -XCa: 9.9716e-01 -XSr: 2.8440e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 4 -SrCO3 added: 4.0000e-05 -Log Sigma pi: -8.3345e+00 -XAragonite: 9.9983e-01 -XStrontianite: 1.6904e-04 -XCa: 9.9621e-01 -XSr: 3.7906e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 5 -SrCO3 added: 5.0000e-05 -Log Sigma pi: -8.3341e+00 -XAragonite: 9.9979e-01 -XStrontianite: 2.1158e-04 -XCa: 9.9526e-01 -XSr: 4.7366e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 6 -SrCO3 added: 6.0000e-05 -Log Sigma pi: -8.3337e+00 -XAragonite: 9.9975e-01 -XStrontianite: 2.5422e-04 -XCa: 9.9432e-01 -XSr: 5.6819e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 7 -SrCO3 added: 7.0000e-05 -Log Sigma pi: -8.3333e+00 -XAragonite: 9.9970e-01 -XStrontianite: 2.9698e-04 -XCa: 9.9337e-01 -XSr: 6.6265e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 8 -SrCO3 added: 8.0000e-05 -Log Sigma pi: -8.3329e+00 -XAragonite: 9.9966e-01 -XStrontianite: 3.3985e-04 -XCa: 9.9243e-01 -XSr: 7.5705e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 9 -SrCO3 added: 9.0000e-05 -Log Sigma pi: -8.3325e+00 -XAragonite: 9.9962e-01 -XStrontianite: 3.8284e-04 -XCa: 9.9149e-01 -XSr: 8.5137e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 10 -SrCO3 added: 1.0000e-04 -Log Sigma pi: -8.3321e+00 -XAragonite: 9.9957e-01 -XStrontianite: 4.2593e-04 -XCa: 9.9054e-01 -XSr: 9.4563e-03 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 11 -SrCO3 added: 1.1000e-04 -Log Sigma pi: -8.3318e+00 -XAragonite: 9.9953e-01 -XStrontianite: 4.6914e-04 -XCa: 9.8960e-01 -XSr: 1.0398e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 12 -SrCO3 added: 1.2000e-04 -Log Sigma pi: -8.3314e+00 -XAragonite: 9.9949e-01 -XStrontianite: 5.1247e-04 -XCa: 9.8866e-01 -XSr: 1.1340e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 13 -SrCO3 added: 1.3000e-04 -Log Sigma pi: -8.3310e+00 -XAragonite: 9.9944e-01 -XStrontianite: 5.5591e-04 -XCa: 9.8772e-01 -XSr: 1.2280e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 14 -SrCO3 added: 1.4000e-04 -Log Sigma pi: -8.3306e+00 -XAragonite: 9.9940e-01 -XStrontianite: 5.9946e-04 -XCa: 9.8678e-01 -XSr: 1.3220e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 15 -SrCO3 added: 1.5000e-04 -Log Sigma pi: -8.3302e+00 -XAragonite: 9.9936e-01 -XStrontianite: 6.4313e-04 -XCa: 9.8584e-01 -XSr: 1.4159e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 16 -SrCO3 added: 1.6000e-04 -Log Sigma pi: -8.3298e+00 -XAragonite: 9.9931e-01 -XStrontianite: 6.8692e-04 -XCa: 9.8490e-01 -XSr: 1.5098e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 17 -SrCO3 added: 1.7000e-04 -Log Sigma pi: -8.3294e+00 -XAragonite: 9.9927e-01 -XStrontianite: 7.3082e-04 -XCa: 9.8396e-01 -XSr: 1.6036e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 18 -SrCO3 added: 1.8000e-04 -Log Sigma pi: -8.3290e+00 -XAragonite: 9.9923e-01 -XStrontianite: 7.7484e-04 -XCa: 9.8303e-01 -XSr: 1.6973e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 19 -SrCO3 added: 1.9000e-04 -Log Sigma pi: -8.3287e+00 -XAragonite: 9.9918e-01 -XStrontianite: 8.1897e-04 -XCa: 9.8209e-01 -XSr: 1.7909e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 20 -SrCO3 added: 2.0000e-04 -Log Sigma pi: -8.3283e+00 -XAragonite: 9.9914e-01 -XStrontianite: 8.6323e-04 -XCa: 9.8115e-01 -XSr: 1.8845e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 21 -SrCO3 added: 2.1000e-04 -Log Sigma pi: -8.3279e+00 -XAragonite: 9.9909e-01 -XStrontianite: 9.0760e-04 -XCa: 9.8022e-01 -XSr: 1.9780e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 22 -SrCO3 added: 2.2000e-04 -Log Sigma pi: -8.3275e+00 -XAragonite: 9.9905e-01 -XStrontianite: 9.5209e-04 -XCa: 9.7929e-01 -XSr: 2.0715e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 23 -SrCO3 added: 2.3000e-04 -Log Sigma pi: -8.3271e+00 -XAragonite: 9.9900e-01 -XStrontianite: 9.9670e-04 -XCa: 9.7835e-01 -XSr: 2.1649e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 24 -SrCO3 added: 2.4000e-04 -Log Sigma pi: -8.3267e+00 -XAragonite: 9.9896e-01 -XStrontianite: 1.0414e-03 -XCa: 9.7742e-01 -XSr: 2.2582e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 25 -SrCO3 added: 2.5000e-04 -Log Sigma pi: -8.3263e+00 -XAragonite: 9.9891e-01 -XStrontianite: 1.0863e-03 -XCa: 9.7649e-01 -XSr: 2.3514e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 26 -SrCO3 added: 2.6000e-04 -Log Sigma pi: -8.3259e+00 -XAragonite: 9.9887e-01 -XStrontianite: 1.1313e-03 -XCa: 9.7555e-01 -XSr: 2.4446e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 27 -SrCO3 added: 2.7000e-04 -Log Sigma pi: -8.3256e+00 -XAragonite: 9.9882e-01 -XStrontianite: 1.1764e-03 -XCa: 9.7462e-01 -XSr: 2.5377e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 28 -SrCO3 added: 2.8000e-04 -Log Sigma pi: -8.3252e+00 -XAragonite: 9.9878e-01 -XStrontianite: 1.2216e-03 -XCa: 9.7369e-01 -XSr: 2.6308e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 29 -SrCO3 added: 2.9000e-04 -Log Sigma pi: -8.3248e+00 -XAragonite: 9.9873e-01 -XStrontianite: 1.2669e-03 -XCa: 9.7276e-01 -XSr: 2.7238e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 30 -SrCO3 added: 3.0000e-04 -Log Sigma pi: -8.3244e+00 -XAragonite: 9.9869e-01 -XStrontianite: 1.3124e-03 -XCa: 9.7183e-01 -XSr: 2.8167e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 31 -SrCO3 added: 3.1000e-04 -Log Sigma pi: -8.3240e+00 -XAragonite: 9.9864e-01 -XStrontianite: 1.3580e-03 -XCa: 9.7090e-01 -XSr: 2.9095e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 32 -SrCO3 added: 3.2000e-04 -Log Sigma pi: -8.3236e+00 -XAragonite: 9.9860e-01 -XStrontianite: 1.4037e-03 -XCa: 9.6998e-01 -XSr: 3.0023e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 33 -SrCO3 added: 3.3000e-04 -Log Sigma pi: -8.3232e+00 -XAragonite: 9.9855e-01 -XStrontianite: 1.4495e-03 -XCa: 9.6905e-01 -XSr: 3.0950e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 34 -SrCO3 added: 3.4000e-04 -Log Sigma pi: -8.3228e+00 -XAragonite: 9.9850e-01 -XStrontianite: 1.4955e-03 -XCa: 9.6812e-01 -XSr: 3.1877e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 35 -SrCO3 added: 3.5000e-04 -Log Sigma pi: -8.3225e+00 -XAragonite: 9.9846e-01 -XStrontianite: 1.5416e-03 -XCa: 9.6720e-01 -XSr: 3.2802e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 36 -SrCO3 added: 3.6000e-04 -Log Sigma pi: -8.3221e+00 -XAragonite: 9.9841e-01 -XStrontianite: 1.5878e-03 -XCa: 9.6627e-01 -XSr: 3.3727e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 37 -SrCO3 added: 3.7000e-04 -Log Sigma pi: -8.3217e+00 -XAragonite: 9.9837e-01 -XStrontianite: 1.6341e-03 -XCa: 9.6535e-01 -XSr: 3.4652e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 38 -SrCO3 added: 3.8000e-04 -Log Sigma pi: -8.3213e+00 -XAragonite: 9.9832e-01 -XStrontianite: 1.6806e-03 -XCa: 9.6442e-01 -XSr: 3.5576e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 39 -SrCO3 added: 3.9000e-04 -Log Sigma pi: -8.3209e+00 -XAragonite: 9.9827e-01 -XStrontianite: 1.7272e-03 -XCa: 9.6350e-01 -XSr: 3.6499e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 40 -SrCO3 added: 4.0000e-04 -Log Sigma pi: -8.3205e+00 -XAragonite: 9.9823e-01 -XStrontianite: 1.7739e-03 -XCa: 9.6258e-01 -XSr: 3.7421e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 41 -SrCO3 added: 4.1000e-04 -Log Sigma pi: -8.3201e+00 -XAragonite: 9.9818e-01 -XStrontianite: 1.8208e-03 -XCa: 9.6166e-01 -XSr: 3.8343e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 42 -SrCO3 added: 4.2000e-04 -Log Sigma pi: -8.3197e+00 -XAragonite: 9.9813e-01 -XStrontianite: 1.8677e-03 -XCa: 9.6074e-01 -XSr: 3.9264e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 43 -SrCO3 added: 4.3000e-04 -Log Sigma pi: -8.3193e+00 -XAragonite: 9.9809e-01 -XStrontianite: 1.9149e-03 -XCa: 9.5982e-01 -XSr: 4.0184e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 44 -SrCO3 added: 4.4000e-04 -Log Sigma pi: -8.3190e+00 -XAragonite: 9.9804e-01 -XStrontianite: 1.9621e-03 -XCa: 9.5890e-01 -XSr: 4.1104e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 45 -SrCO3 added: 4.5000e-04 -Log Sigma pi: -8.3186e+00 -XAragonite: 9.9799e-01 -XStrontianite: 2.0095e-03 -XCa: 9.5798e-01 -XSr: 4.2023e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 46 -SrCO3 added: 4.6000e-04 -Log Sigma pi: -8.3182e+00 -XAragonite: 9.9794e-01 -XStrontianite: 2.0570e-03 -XCa: 9.5706e-01 -XSr: 4.2941e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 47 -SrCO3 added: 4.7000e-04 -Log Sigma pi: -8.3178e+00 -XAragonite: 9.9790e-01 -XStrontianite: 2.1046e-03 -XCa: 9.5614e-01 -XSr: 4.3859e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 48 -SrCO3 added: 4.8000e-04 -Log Sigma pi: -8.3174e+00 -XAragonite: 9.9785e-01 -XStrontianite: 2.1524e-03 -XCa: 9.5522e-01 -XSr: 4.4776e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 49 -SrCO3 added: 4.9000e-04 -Log Sigma pi: -8.3170e+00 -XAragonite: 9.9780e-01 -XStrontianite: 2.2003e-03 -XCa: 9.5431e-01 -XSr: 4.5692e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 50 -SrCO3 added: 5.0000e-04 -Log Sigma pi: -8.3166e+00 -XAragonite: 9.9775e-01 -XStrontianite: 2.2484e-03 -XCa: 9.5339e-01 -XSr: 4.6608e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 51 -SrCO3 added: 5.1000e-04 -Log Sigma pi: -8.3162e+00 -XAragonite: 9.9770e-01 -XStrontianite: 2.2966e-03 -XCa: 9.5248e-01 -XSr: 4.7523e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 52 -SrCO3 added: 5.2000e-04 -Log Sigma pi: -8.3159e+00 -XAragonite: 9.9766e-01 -XStrontianite: 2.3449e-03 -XCa: 9.5156e-01 -XSr: 4.8437e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 53 -SrCO3 added: 5.3000e-04 -Log Sigma pi: -8.3155e+00 -XAragonite: 9.9761e-01 -XStrontianite: 2.3933e-03 -XCa: 9.5065e-01 -XSr: 4.9351e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 54 -SrCO3 added: 5.4000e-04 -Log Sigma pi: -8.3151e+00 -XAragonite: 9.9756e-01 -XStrontianite: 2.4419e-03 -XCa: 9.4974e-01 -XSr: 5.0264e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 55 -SrCO3 added: 5.5000e-04 -Log Sigma pi: -8.3147e+00 -XAragonite: 9.9751e-01 -XStrontianite: 2.4907e-03 -XCa: 9.4882e-01 -XSr: 5.1176e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 56 -SrCO3 added: 5.6000e-04 -Log Sigma pi: -8.3143e+00 -XAragonite: 9.9746e-01 -XStrontianite: 2.5395e-03 -XCa: 9.4791e-01 -XSr: 5.2088e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 57 -SrCO3 added: 5.7000e-04 -Log Sigma pi: -8.3139e+00 -XAragonite: 9.9741e-01 -XStrontianite: 2.5885e-03 -XCa: 9.4700e-01 -XSr: 5.2999e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 58 -SrCO3 added: 5.8000e-04 -Log Sigma pi: -8.3135e+00 -XAragonite: 9.9736e-01 -XStrontianite: 2.6377e-03 -XCa: 9.4609e-01 -XSr: 5.3909e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 59 -SrCO3 added: 5.9000e-04 -Log Sigma pi: -8.3131e+00 -XAragonite: 9.9731e-01 -XStrontianite: 2.6870e-03 -XCa: 9.4518e-01 -XSr: 5.4819e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 60 -SrCO3 added: 6.0000e-04 -Log Sigma pi: -8.3127e+00 -XAragonite: 9.9726e-01 -XStrontianite: 2.7364e-03 -XCa: 9.4427e-01 -XSr: 5.5728e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 61 -SrCO3 added: 6.1000e-04 -Log Sigma pi: -8.3123e+00 -XAragonite: 9.9721e-01 -XStrontianite: 2.7860e-03 -XCa: 9.4336e-01 -XSr: 5.6636e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 62 -SrCO3 added: 6.2000e-04 -Log Sigma pi: -8.3120e+00 -XAragonite: 9.9716e-01 -XStrontianite: 2.8357e-03 -XCa: 9.4246e-01 -XSr: 5.7544e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 63 -SrCO3 added: 6.3000e-04 -Log Sigma pi: -8.3116e+00 -XAragonite: 9.9711e-01 -XStrontianite: 2.8856e-03 -XCa: 9.4155e-01 -XSr: 5.8451e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 64 -SrCO3 added: 6.4000e-04 -Log Sigma pi: -8.3112e+00 -XAragonite: 9.9706e-01 -XStrontianite: 2.9356e-03 -XCa: 9.4064e-01 -XSr: 5.9357e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 65 -SrCO3 added: 6.5000e-04 -Log Sigma pi: -8.3108e+00 -XAragonite: 9.9701e-01 -XStrontianite: 2.9857e-03 -XCa: 9.3974e-01 -XSr: 6.0263e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 66 -SrCO3 added: 6.6000e-04 -Log Sigma pi: -8.3104e+00 -XAragonite: 9.9696e-01 -XStrontianite: 3.0360e-03 -XCa: 9.3883e-01 -XSr: 6.1167e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 67 -SrCO3 added: 6.7000e-04 -Log Sigma pi: -8.3100e+00 -XAragonite: 9.9691e-01 -XStrontianite: 3.0864e-03 -XCa: 9.3793e-01 -XSr: 6.2072e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 68 -SrCO3 added: 6.8000e-04 -Log Sigma pi: -8.3096e+00 -XAragonite: 9.9686e-01 -XStrontianite: 3.1370e-03 -XCa: 9.3702e-01 -XSr: 6.2975e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 69 -SrCO3 added: 6.9000e-04 -Log Sigma pi: -8.3092e+00 -XAragonite: 9.9681e-01 -XStrontianite: 3.1878e-03 -XCa: 9.3612e-01 -XSr: 6.3878e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 70 -SrCO3 added: 7.0000e-04 -Log Sigma pi: -8.3088e+00 -XAragonite: 9.9676e-01 -XStrontianite: 3.2386e-03 -XCa: 9.3522e-01 -XSr: 6.4780e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 71 -SrCO3 added: 7.1000e-04 -Log Sigma pi: -8.3084e+00 -XAragonite: 9.9671e-01 -XStrontianite: 3.2897e-03 -XCa: 9.3432e-01 -XSr: 6.5682e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 72 -SrCO3 added: 7.2000e-04 -Log Sigma pi: -8.3081e+00 -XAragonite: 9.9666e-01 -XStrontianite: 3.3409e-03 -XCa: 9.3342e-01 -XSr: 6.6583e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 73 -SrCO3 added: 7.3000e-04 -Log Sigma pi: -8.3077e+00 -XAragonite: 9.9661e-01 -XStrontianite: 3.3922e-03 -XCa: 9.3252e-01 -XSr: 6.7483e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 74 -SrCO3 added: 7.4000e-04 -Log Sigma pi: -8.3073e+00 -XAragonite: 9.9656e-01 -XStrontianite: 3.4437e-03 -XCa: 9.3162e-01 -XSr: 6.8383e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 75 -SrCO3 added: 7.5000e-04 -Log Sigma pi: -8.3069e+00 -XAragonite: 9.9650e-01 -XStrontianite: 3.4953e-03 -XCa: 9.3072e-01 -XSr: 6.9282e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 76 -SrCO3 added: 7.6000e-04 -Log Sigma pi: -8.3065e+00 -XAragonite: 9.9645e-01 -XStrontianite: 3.5471e-03 -XCa: 9.2982e-01 -XSr: 7.0180e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 77 -SrCO3 added: 7.7000e-04 -Log Sigma pi: -8.3061e+00 -XAragonite: 9.9640e-01 -XStrontianite: 3.5990e-03 -XCa: 9.2892e-01 -XSr: 7.1077e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 78 -SrCO3 added: 7.8000e-04 -Log Sigma pi: -8.3057e+00 -XAragonite: 9.9635e-01 -XStrontianite: 3.6511e-03 -XCa: 9.2803e-01 -XSr: 7.1974e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 79 -SrCO3 added: 7.9000e-04 -Log Sigma pi: -8.3053e+00 -XAragonite: 9.9630e-01 -XStrontianite: 3.7034e-03 -XCa: 9.2713e-01 -XSr: 7.2870e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 80 -SrCO3 added: 8.0000e-04 -Log Sigma pi: -8.3049e+00 -XAragonite: 9.9624e-01 -XStrontianite: 3.7558e-03 -XCa: 9.2623e-01 -XSr: 7.3766e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 81 -SrCO3 added: 8.1000e-04 -Log Sigma pi: -8.3045e+00 -XAragonite: 9.9619e-01 -XStrontianite: 3.8083e-03 -XCa: 9.2534e-01 -XSr: 7.4661e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 82 -SrCO3 added: 8.2000e-04 -Log Sigma pi: -8.3042e+00 -XAragonite: 9.9614e-01 -XStrontianite: 3.8611e-03 -XCa: 9.2445e-01 -XSr: 7.5555e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 83 -SrCO3 added: 8.3000e-04 -Log Sigma pi: -8.3038e+00 -XAragonite: 9.9609e-01 -XStrontianite: 3.9139e-03 -XCa: 9.2355e-01 -XSr: 7.6448e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 84 -SrCO3 added: 8.4000e-04 -Log Sigma pi: -8.3034e+00 -XAragonite: 9.9603e-01 -XStrontianite: 3.9670e-03 -XCa: 9.2266e-01 -XSr: 7.7341e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 85 -SrCO3 added: 8.5000e-04 -Log Sigma pi: -8.3030e+00 -XAragonite: 9.9598e-01 -XStrontianite: 4.0202e-03 -XCa: 9.2177e-01 -XSr: 7.8233e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 86 -SrCO3 added: 8.6000e-04 -Log Sigma pi: -8.3026e+00 -XAragonite: 9.9593e-01 -XStrontianite: 4.0735e-03 -XCa: 9.2088e-01 -XSr: 7.9125e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 87 -SrCO3 added: 8.7000e-04 -Log Sigma pi: -8.3022e+00 -XAragonite: 9.9587e-01 -XStrontianite: 4.1270e-03 -XCa: 9.1998e-01 -XSr: 8.0016e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 88 -SrCO3 added: 8.8000e-04 -Log Sigma pi: -8.3018e+00 -XAragonite: 9.9582e-01 -XStrontianite: 4.1807e-03 -XCa: 9.1909e-01 -XSr: 8.0906e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 89 -SrCO3 added: 8.9000e-04 -Log Sigma pi: -8.3014e+00 -XAragonite: 9.9577e-01 -XStrontianite: 4.2346e-03 -XCa: 9.1820e-01 -XSr: 8.1795e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 90 -SrCO3 added: 9.0000e-04 -Log Sigma pi: -8.3010e+00 -XAragonite: 9.9571e-01 -XStrontianite: 4.2886e-03 -XCa: 9.1732e-01 -XSr: 8.2684e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 91 -SrCO3 added: 9.1000e-04 -Log Sigma pi: -8.3006e+00 -XAragonite: 9.9566e-01 -XStrontianite: 4.3427e-03 -XCa: 9.1643e-01 -XSr: 8.3572e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 92 -SrCO3 added: 9.2000e-04 -Log Sigma pi: -8.3002e+00 -XAragonite: 9.9560e-01 -XStrontianite: 4.3971e-03 -XCa: 9.1554e-01 -XSr: 8.4460e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 93 -SrCO3 added: 9.3000e-04 -Log Sigma pi: -8.2999e+00 -XAragonite: 9.9555e-01 -XStrontianite: 4.4516e-03 -XCa: 9.1465e-01 -XSr: 8.5347e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 94 -SrCO3 added: 9.4000e-04 -Log Sigma pi: -8.2995e+00 -XAragonite: 9.9549e-01 -XStrontianite: 4.5062e-03 -XCa: 9.1377e-01 -XSr: 8.6233e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 95 -SrCO3 added: 9.5000e-04 -Log Sigma pi: -8.2991e+00 -XAragonite: 9.9544e-01 -XStrontianite: 4.5611e-03 -XCa: 9.1288e-01 -XSr: 8.7118e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 96 -SrCO3 added: 9.6000e-04 -Log Sigma pi: -8.2987e+00 -XAragonite: 9.9538e-01 -XStrontianite: 4.6161e-03 -XCa: 9.1200e-01 -XSr: 8.8003e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 97 -SrCO3 added: 9.7000e-04 -Log Sigma pi: -8.2983e+00 -XAragonite: 9.9533e-01 -XStrontianite: 4.6713e-03 -XCa: 9.1111e-01 -XSr: 8.8887e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 98 -SrCO3 added: 9.8000e-04 -Log Sigma pi: -8.2979e+00 -XAragonite: 9.9527e-01 -XStrontianite: 4.7266e-03 -XCa: 9.1023e-01 -XSr: 8.9770e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 99 -SrCO3 added: 9.9000e-04 -Log Sigma pi: -8.2975e+00 -XAragonite: 9.9522e-01 -XStrontianite: 4.7821e-03 -XCa: 9.0935e-01 -XSr: 9.0653e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 100 -SrCO3 added: 1.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.8567e-01 -XStrontianite: 1.4329e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 101 -SrCO3 added: 1.0100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.7071e-01 -XStrontianite: 2.9286e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 102 -SrCO3 added: 1.0200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.5620e-01 -XStrontianite: 4.3796e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 103 -SrCO3 added: 1.0300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.4212e-01 -XStrontianite: 5.7879e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 104 -SrCO3 added: 1.0400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.2845e-01 -XStrontianite: 7.1552e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 105 -SrCO3 added: 1.0500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.1516e-01 -XStrontianite: 8.4835e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 106 -SrCO3 added: 1.0600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.0226e-01 -XStrontianite: 9.7743e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 107 -SrCO3 added: 1.0700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.8971e-01 -XStrontianite: 1.1029e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 108 -SrCO3 added: 1.0800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.7750e-01 -XStrontianite: 1.2250e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 109 -SrCO3 added: 1.0900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.6563e-01 -XStrontianite: 1.3437e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 110 -SrCO3 added: 1.1000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.5407e-01 -XStrontianite: 1.4593e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 111 -SrCO3 added: 1.1100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.4282e-01 -XStrontianite: 1.5718e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 112 -SrCO3 added: 1.1200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.3186e-01 -XStrontianite: 1.6814e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 113 -SrCO3 added: 1.1300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.2118e-01 -XStrontianite: 1.7882e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 114 -SrCO3 added: 1.1400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.1077e-01 -XStrontianite: 1.8923e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 115 -SrCO3 added: 1.1500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 8.0063e-01 -XStrontianite: 1.9937e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 116 -SrCO3 added: 1.1600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.9073e-01 -XStrontianite: 2.0927e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 117 -SrCO3 added: 1.1700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.8107e-01 -XStrontianite: 2.1893e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 118 -SrCO3 added: 1.1800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.7165e-01 -XStrontianite: 2.2835e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 119 -SrCO3 added: 1.1900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.6246e-01 -XStrontianite: 2.3754e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 120 -SrCO3 added: 1.2000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.5348e-01 -XStrontianite: 2.4652e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 121 -SrCO3 added: 1.2100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.4470e-01 -XStrontianite: 2.5530e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 122 -SrCO3 added: 1.2200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.3613e-01 -XStrontianite: 2.6387e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 123 -SrCO3 added: 1.2300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.2776e-01 -XStrontianite: 2.7224e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 124 -SrCO3 added: 1.2400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.1957e-01 -XStrontianite: 2.8043e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 125 -SrCO3 added: 1.2500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.1157e-01 -XStrontianite: 2.8843e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 126 -SrCO3 added: 1.2600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 7.0374e-01 -XStrontianite: 2.9626e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 127 -SrCO3 added: 1.2700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.9608e-01 -XStrontianite: 3.0392e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 128 -SrCO3 added: 1.2800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.8859e-01 -XStrontianite: 3.1141e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 129 -SrCO3 added: 1.2900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.8126e-01 -XStrontianite: 3.1874e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 130 -SrCO3 added: 1.3000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.7408e-01 -XStrontianite: 3.2592e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 131 -SrCO3 added: 1.3100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.6705e-01 -XStrontianite: 3.3295e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 132 -SrCO3 added: 1.3200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.6017e-01 -XStrontianite: 3.3983e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 133 -SrCO3 added: 1.3300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.5342e-01 -XStrontianite: 3.4658e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 134 -SrCO3 added: 1.3400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.4682e-01 -XStrontianite: 3.5318e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 135 -SrCO3 added: 1.3500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.4034e-01 -XStrontianite: 3.5966e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 136 -SrCO3 added: 1.3600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.3399e-01 -XStrontianite: 3.6601e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 137 -SrCO3 added: 1.3700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.2777e-01 -XStrontianite: 3.7223e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 138 -SrCO3 added: 1.3800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.2167e-01 -XStrontianite: 3.7833e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 139 -SrCO3 added: 1.3900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.1569e-01 -XStrontianite: 3.8431e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 140 -SrCO3 added: 1.4000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.0982e-01 -XStrontianite: 3.9018e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 141 -SrCO3 added: 1.4100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 6.0406e-01 -XStrontianite: 3.9594e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 142 -SrCO3 added: 1.4200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.9841e-01 -XStrontianite: 4.0159e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 143 -SrCO3 added: 1.4300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.9286e-01 -XStrontianite: 4.0714e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 144 -SrCO3 added: 1.4400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.8742e-01 -XStrontianite: 4.1258e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 145 -SrCO3 added: 1.4500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.8207e-01 -XStrontianite: 4.1793e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 146 -SrCO3 added: 1.4600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.7683e-01 -XStrontianite: 4.2317e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 147 -SrCO3 added: 1.4700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.7167e-01 -XStrontianite: 4.2833e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 148 -SrCO3 added: 1.4800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.6661e-01 -XStrontianite: 4.3339e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 149 -SrCO3 added: 1.4900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.6163e-01 -XStrontianite: 4.3837e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 150 -SrCO3 added: 1.5000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.5675e-01 -XStrontianite: 4.4325e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 151 -SrCO3 added: 1.5100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.5194e-01 -XStrontianite: 4.4806e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 152 -SrCO3 added: 1.5200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.4722e-01 -XStrontianite: 4.5278e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 153 -SrCO3 added: 1.5300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.4258e-01 -XStrontianite: 4.5742e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 154 -SrCO3 added: 1.5400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.3802e-01 -XStrontianite: 4.6198e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 155 -SrCO3 added: 1.5500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.3353e-01 -XStrontianite: 4.6647e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 156 -SrCO3 added: 1.5600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.2912e-01 -XStrontianite: 4.7088e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 157 -SrCO3 added: 1.5700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.2477e-01 -XStrontianite: 4.7523e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 158 -SrCO3 added: 1.5800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.2050e-01 -XStrontianite: 4.7950e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 159 -SrCO3 added: 1.5900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.1630e-01 -XStrontianite: 4.8370e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 160 -SrCO3 added: 1.6000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.1217e-01 -XStrontianite: 4.8783e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 161 -SrCO3 added: 1.6100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.0810e-01 -XStrontianite: 4.9190e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 162 -SrCO3 added: 1.6200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.0410e-01 -XStrontianite: 4.9590e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 163 -SrCO3 added: 1.6300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 5.0016e-01 -XStrontianite: 4.9984e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 164 -SrCO3 added: 1.6400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.9628e-01 -XStrontianite: 5.0372e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 165 -SrCO3 added: 1.6500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.9246e-01 -XStrontianite: 5.0754e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 166 -SrCO3 added: 1.6600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.8869e-01 -XStrontianite: 5.1131e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 167 -SrCO3 added: 1.6700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.8499e-01 -XStrontianite: 5.1501e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 168 -SrCO3 added: 1.6800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.8134e-01 -XStrontianite: 5.1866e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 169 -SrCO3 added: 1.6900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.7774e-01 -XStrontianite: 5.2226e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 170 -SrCO3 added: 1.7000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.7420e-01 -XStrontianite: 5.2580e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 171 -SrCO3 added: 1.7100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.7071e-01 -XStrontianite: 5.2929e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 172 -SrCO3 added: 1.7200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.6728e-01 -XStrontianite: 5.3272e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 173 -SrCO3 added: 1.7300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.6389e-01 -XStrontianite: 5.3611e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 174 -SrCO3 added: 1.7400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.6055e-01 -XStrontianite: 5.3945e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 175 -SrCO3 added: 1.7500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.5726e-01 -XStrontianite: 5.4274e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 176 -SrCO3 added: 1.7600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.5401e-01 -XStrontianite: 5.4599e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 177 -SrCO3 added: 1.7700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.5081e-01 -XStrontianite: 5.4919e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 178 -SrCO3 added: 1.7800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.4766e-01 -XStrontianite: 5.5234e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 179 -SrCO3 added: 1.7900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.4455e-01 -XStrontianite: 5.5545e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 180 -SrCO3 added: 1.8000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.4148e-01 -XStrontianite: 5.5852e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 181 -SrCO3 added: 1.8100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.3845e-01 -XStrontianite: 5.6155e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 182 -SrCO3 added: 1.8200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.3547e-01 -XStrontianite: 5.6453e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 183 -SrCO3 added: 1.8300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.3252e-01 -XStrontianite: 5.6748e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 184 -SrCO3 added: 1.8400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.2962e-01 -XStrontianite: 5.7038e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 185 -SrCO3 added: 1.8500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.2675e-01 -XStrontianite: 5.7325e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 186 -SrCO3 added: 1.8600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.2392e-01 -XStrontianite: 5.7608e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 187 -SrCO3 added: 1.8700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.2113e-01 -XStrontianite: 5.7887e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 188 -SrCO3 added: 1.8800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.1838e-01 -XStrontianite: 5.8162e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 189 -SrCO3 added: 1.8900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.1566e-01 -XStrontianite: 5.8434e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 190 -SrCO3 added: 1.9000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.1298e-01 -XStrontianite: 5.8702e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 191 -SrCO3 added: 1.9100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.1033e-01 -XStrontianite: 5.8967e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 192 -SrCO3 added: 1.9200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.0771e-01 -XStrontianite: 5.9229e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 193 -SrCO3 added: 1.9300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.0513e-01 -XStrontianite: 5.9487e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 194 -SrCO3 added: 1.9400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.0258e-01 -XStrontianite: 5.9742e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 195 -SrCO3 added: 1.9500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 4.0006e-01 -XStrontianite: 5.9994e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 196 -SrCO3 added: 1.9600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.9758e-01 -XStrontianite: 6.0242e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 197 -SrCO3 added: 1.9700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.9512e-01 -XStrontianite: 6.0488e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 198 -SrCO3 added: 1.9800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.9270e-01 -XStrontianite: 6.0730e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 199 -SrCO3 added: 1.9900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.9030e-01 -XStrontianite: 6.0970e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 200 -SrCO3 added: 2.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.8793e-01 -XStrontianite: 6.1207e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 201 -SrCO3 added: 2.0100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.8559e-01 -XStrontianite: 6.1441e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 202 -SrCO3 added: 2.0200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.8328e-01 -XStrontianite: 6.1672e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 203 -SrCO3 added: 2.0300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.8100e-01 -XStrontianite: 6.1900e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 204 -SrCO3 added: 2.0400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.7875e-01 -XStrontianite: 6.2125e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 205 -SrCO3 added: 2.0500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.7652e-01 -XStrontianite: 6.2348e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 206 -SrCO3 added: 2.0600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.7431e-01 -XStrontianite: 6.2569e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 207 -SrCO3 added: 2.0700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.7214e-01 -XStrontianite: 6.2786e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 208 -SrCO3 added: 2.0800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.6998e-01 -XStrontianite: 6.3002e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 209 -SrCO3 added: 2.0900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.6786e-01 -XStrontianite: 6.3214e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 210 -SrCO3 added: 2.1000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.6575e-01 -XStrontianite: 6.3425e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 211 -SrCO3 added: 2.1100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.6367e-01 -XStrontianite: 6.3633e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 212 -SrCO3 added: 2.1200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.6162e-01 -XStrontianite: 6.3838e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 213 -SrCO3 added: 2.1300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.5958e-01 -XStrontianite: 6.4042e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 214 -SrCO3 added: 2.1400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.5757e-01 -XStrontianite: 6.4243e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 215 -SrCO3 added: 2.1500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.5559e-01 -XStrontianite: 6.4441e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 216 -SrCO3 added: 2.1600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.5362e-01 -XStrontianite: 6.4638e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 217 -SrCO3 added: 2.1700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.5168e-01 -XStrontianite: 6.4832e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 218 -SrCO3 added: 2.1800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4975e-01 -XStrontianite: 6.5025e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 219 -SrCO3 added: 2.1900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4785e-01 -XStrontianite: 6.5215e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 220 -SrCO3 added: 2.2000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4597e-01 -XStrontianite: 6.5403e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 221 -SrCO3 added: 2.2100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4411e-01 -XStrontianite: 6.5589e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 222 -SrCO3 added: 2.2200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4227e-01 -XStrontianite: 6.5773e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 223 -SrCO3 added: 2.2300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.4045e-01 -XStrontianite: 6.5955e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 224 -SrCO3 added: 2.2400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.3864e-01 -XStrontianite: 6.6136e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 225 -SrCO3 added: 2.2500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.3686e-01 -XStrontianite: 6.6314e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 226 -SrCO3 added: 2.2600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.3510e-01 -XStrontianite: 6.6490e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 227 -SrCO3 added: 2.2700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.3335e-01 -XStrontianite: 6.6665e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 228 -SrCO3 added: 2.2800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.3162e-01 -XStrontianite: 6.6838e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 229 -SrCO3 added: 2.2900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2991e-01 -XStrontianite: 6.7009e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 230 -SrCO3 added: 2.3000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2822e-01 -XStrontianite: 6.7178e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 231 -SrCO3 added: 2.3100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2654e-01 -XStrontianite: 6.7346e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 232 -SrCO3 added: 2.3200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2489e-01 -XStrontianite: 6.7511e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 233 -SrCO3 added: 2.3300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2324e-01 -XStrontianite: 6.7676e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 234 -SrCO3 added: 2.3400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2162e-01 -XStrontianite: 6.7838e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 235 -SrCO3 added: 2.3500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.2001e-01 -XStrontianite: 6.7999e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 236 -SrCO3 added: 2.3600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1842e-01 -XStrontianite: 6.8158e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 237 -SrCO3 added: 2.3700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1684e-01 -XStrontianite: 6.8316e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 238 -SrCO3 added: 2.3800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1528e-01 -XStrontianite: 6.8472e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 239 -SrCO3 added: 2.3900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1373e-01 -XStrontianite: 6.8627e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 240 -SrCO3 added: 2.4000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1220e-01 -XStrontianite: 6.8780e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 241 -SrCO3 added: 2.4100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.1068e-01 -XStrontianite: 6.8932e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 242 -SrCO3 added: 2.4200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0918e-01 -XStrontianite: 6.9082e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 243 -SrCO3 added: 2.4300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0770e-01 -XStrontianite: 6.9230e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 244 -SrCO3 added: 2.4400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0622e-01 -XStrontianite: 6.9378e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 245 -SrCO3 added: 2.4500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0476e-01 -XStrontianite: 6.9524e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 246 -SrCO3 added: 2.4600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0332e-01 -XStrontianite: 6.9668e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 247 -SrCO3 added: 2.4700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0189e-01 -XStrontianite: 6.9811e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 248 -SrCO3 added: 2.4800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.0047e-01 -XStrontianite: 6.9953e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 249 -SrCO3 added: 2.4900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9907e-01 -XStrontianite: 7.0093e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 250 -SrCO3 added: 2.5000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9767e-01 -XStrontianite: 7.0233e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 251 -SrCO3 added: 2.5100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9629e-01 -XStrontianite: 7.0371e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 252 -SrCO3 added: 2.5200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9493e-01 -XStrontianite: 7.0507e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 253 -SrCO3 added: 2.5300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9358e-01 -XStrontianite: 7.0642e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 254 -SrCO3 added: 2.5400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9223e-01 -XStrontianite: 7.0777e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 255 -SrCO3 added: 2.5500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.9091e-01 -XStrontianite: 7.0909e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 256 -SrCO3 added: 2.5600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8959e-01 -XStrontianite: 7.1041e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 257 -SrCO3 added: 2.5700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8828e-01 -XStrontianite: 7.1172e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 258 -SrCO3 added: 2.5800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8699e-01 -XStrontianite: 7.1301e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 259 -SrCO3 added: 2.5900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8571e-01 -XStrontianite: 7.1429e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 260 -SrCO3 added: 2.6000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8444e-01 -XStrontianite: 7.1556e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 261 -SrCO3 added: 2.6100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8318e-01 -XStrontianite: 7.1682e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 262 -SrCO3 added: 2.6200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8193e-01 -XStrontianite: 7.1807e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 263 -SrCO3 added: 2.6300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.8069e-01 -XStrontianite: 7.1931e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 264 -SrCO3 added: 2.6400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7947e-01 -XStrontianite: 7.2053e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 265 -SrCO3 added: 2.6500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7825e-01 -XStrontianite: 7.2175e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 266 -SrCO3 added: 2.6600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7705e-01 -XStrontianite: 7.2295e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 267 -SrCO3 added: 2.6700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7585e-01 -XStrontianite: 7.2415e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 268 -SrCO3 added: 2.6800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7467e-01 -XStrontianite: 7.2533e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 269 -SrCO3 added: 2.6900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7349e-01 -XStrontianite: 7.2651e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 270 -SrCO3 added: 2.7000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7233e-01 -XStrontianite: 7.2767e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 271 -SrCO3 added: 2.7100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7117e-01 -XStrontianite: 7.2883e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 272 -SrCO3 added: 2.7200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.7003e-01 -XStrontianite: 7.2997e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 273 -SrCO3 added: 2.7300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6889e-01 -XStrontianite: 7.3111e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 274 -SrCO3 added: 2.7400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6777e-01 -XStrontianite: 7.3223e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 275 -SrCO3 added: 2.7500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6665e-01 -XStrontianite: 7.3335e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 276 -SrCO3 added: 2.7600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6555e-01 -XStrontianite: 7.3445e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 277 -SrCO3 added: 2.7700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6445e-01 -XStrontianite: 7.3555e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 278 -SrCO3 added: 2.7800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6336e-01 -XStrontianite: 7.3664e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 279 -SrCO3 added: 2.7900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6228e-01 -XStrontianite: 7.3772e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 280 -SrCO3 added: 2.8000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6121e-01 -XStrontianite: 7.3879e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 281 -SrCO3 added: 2.8100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.6015e-01 -XStrontianite: 7.3985e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 282 -SrCO3 added: 2.8200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5909e-01 -XStrontianite: 7.4091e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 283 -SrCO3 added: 2.8300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5805e-01 -XStrontianite: 7.4195e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 284 -SrCO3 added: 2.8400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5701e-01 -XStrontianite: 7.4299e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 285 -SrCO3 added: 2.8500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5598e-01 -XStrontianite: 7.4402e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 286 -SrCO3 added: 2.8600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5496e-01 -XStrontianite: 7.4504e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 287 -SrCO3 added: 2.8700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5395e-01 -XStrontianite: 7.4605e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 288 -SrCO3 added: 2.8800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5295e-01 -XStrontianite: 7.4705e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 289 -SrCO3 added: 2.8900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5195e-01 -XStrontianite: 7.4805e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 290 -SrCO3 added: 2.9000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.5096e-01 -XStrontianite: 7.4904e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 291 -SrCO3 added: 2.9100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4998e-01 -XStrontianite: 7.5002e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 292 -SrCO3 added: 2.9200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4901e-01 -XStrontianite: 7.5099e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 293 -SrCO3 added: 2.9300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4804e-01 -XStrontianite: 7.5196e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 294 -SrCO3 added: 2.9400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4708e-01 -XStrontianite: 7.5292e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 295 -SrCO3 added: 2.9500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4613e-01 -XStrontianite: 7.5387e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 296 -SrCO3 added: 2.9600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4519e-01 -XStrontianite: 7.5481e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 297 -SrCO3 added: 2.9700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4425e-01 -XStrontianite: 7.5575e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 298 -SrCO3 added: 2.9800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4332e-01 -XStrontianite: 7.5668e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 299 -SrCO3 added: 2.9900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4240e-01 -XStrontianite: 7.5760e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 300 -SrCO3 added: 3.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4149e-01 -XStrontianite: 7.5851e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 301 -SrCO3 added: 3.0100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4058e-01 -XStrontianite: 7.5942e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 302 -SrCO3 added: 3.0200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3968e-01 -XStrontianite: 7.6032e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 303 -SrCO3 added: 3.0300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3878e-01 -XStrontianite: 7.6122e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 304 -SrCO3 added: 3.0400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3790e-01 -XStrontianite: 7.6210e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 305 -SrCO3 added: 3.0500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3701e-01 -XStrontianite: 7.6299e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 306 -SrCO3 added: 3.0600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3614e-01 -XStrontianite: 7.6386e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 307 -SrCO3 added: 3.0700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3527e-01 -XStrontianite: 7.6473e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 308 -SrCO3 added: 3.0800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3441e-01 -XStrontianite: 7.6559e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 309 -SrCO3 added: 3.0900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3355e-01 -XStrontianite: 7.6645e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 310 -SrCO3 added: 3.1000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3270e-01 -XStrontianite: 7.6730e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 311 -SrCO3 added: 3.1100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3186e-01 -XStrontianite: 7.6814e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 312 -SrCO3 added: 3.1200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3102e-01 -XStrontianite: 7.6898e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 313 -SrCO3 added: 3.1300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.3019e-01 -XStrontianite: 7.6981e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 314 -SrCO3 added: 3.1400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2937e-01 -XStrontianite: 7.7063e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 315 -SrCO3 added: 3.1500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2855e-01 -XStrontianite: 7.7145e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 316 -SrCO3 added: 3.1600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2773e-01 -XStrontianite: 7.7227e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 317 -SrCO3 added: 3.1700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2692e-01 -XStrontianite: 7.7308e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 318 -SrCO3 added: 3.1800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2612e-01 -XStrontianite: 7.7388e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 319 -SrCO3 added: 3.1900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2533e-01 -XStrontianite: 7.7467e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 320 -SrCO3 added: 3.2000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2454e-01 -XStrontianite: 7.7546e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 321 -SrCO3 added: 3.2100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2375e-01 -XStrontianite: 7.7625e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 322 -SrCO3 added: 3.2200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2297e-01 -XStrontianite: 7.7703e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 323 -SrCO3 added: 3.2300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2220e-01 -XStrontianite: 7.7780e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 324 -SrCO3 added: 3.2400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2143e-01 -XStrontianite: 7.7857e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 325 -SrCO3 added: 3.2500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.2066e-01 -XStrontianite: 7.7934e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 326 -SrCO3 added: 3.2600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1990e-01 -XStrontianite: 7.8010e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 327 -SrCO3 added: 3.2700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1915e-01 -XStrontianite: 7.8085e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 328 -SrCO3 added: 3.2800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1840e-01 -XStrontianite: 7.8160e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 329 -SrCO3 added: 3.2900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1766e-01 -XStrontianite: 7.8234e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 330 -SrCO3 added: 3.3000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1692e-01 -XStrontianite: 7.8308e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 331 -SrCO3 added: 3.3100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1619e-01 -XStrontianite: 7.8381e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 332 -SrCO3 added: 3.3200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1546e-01 -XStrontianite: 7.8454e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 333 -SrCO3 added: 3.3300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1474e-01 -XStrontianite: 7.8526e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 334 -SrCO3 added: 3.3400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1402e-01 -XStrontianite: 7.8598e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 335 -SrCO3 added: 3.3500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1330e-01 -XStrontianite: 7.8670e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 336 -SrCO3 added: 3.3600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1260e-01 -XStrontianite: 7.8740e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 337 -SrCO3 added: 3.3700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1189e-01 -XStrontianite: 7.8811e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 338 -SrCO3 added: 3.3800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1119e-01 -XStrontianite: 7.8881e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 339 -SrCO3 added: 3.3900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.1050e-01 -XStrontianite: 7.8950e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 340 -SrCO3 added: 3.4000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0981e-01 -XStrontianite: 7.9019e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 341 -SrCO3 added: 3.4100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0912e-01 -XStrontianite: 7.9088e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 342 -SrCO3 added: 3.4200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0844e-01 -XStrontianite: 7.9156e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 343 -SrCO3 added: 3.4300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0776e-01 -XStrontianite: 7.9224e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 344 -SrCO3 added: 3.4400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0709e-01 -XStrontianite: 7.9291e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 345 -SrCO3 added: 3.4500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0642e-01 -XStrontianite: 7.9358e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 346 -SrCO3 added: 3.4600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0576e-01 -XStrontianite: 7.9424e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 347 -SrCO3 added: 3.4700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0510e-01 -XStrontianite: 7.9490e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 348 -SrCO3 added: 3.4800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0444e-01 -XStrontianite: 7.9556e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 349 -SrCO3 added: 3.4900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0379e-01 -XStrontianite: 7.9621e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 350 -SrCO3 added: 3.5000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0314e-01 -XStrontianite: 7.9686e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 351 -SrCO3 added: 3.5100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0250e-01 -XStrontianite: 7.9750e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 352 -SrCO3 added: 3.5200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0186e-01 -XStrontianite: 7.9814e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 353 -SrCO3 added: 3.5300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0123e-01 -XStrontianite: 7.9877e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 354 -SrCO3 added: 3.5400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.0060e-01 -XStrontianite: 7.9940e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 355 -SrCO3 added: 3.5500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9997e-01 -XStrontianite: 8.0003e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 356 -SrCO3 added: 3.5600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9935e-01 -XStrontianite: 8.0065e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 357 -SrCO3 added: 3.5700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9873e-01 -XStrontianite: 8.0127e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 358 -SrCO3 added: 3.5800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9811e-01 -XStrontianite: 8.0189e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 359 -SrCO3 added: 3.5900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9750e-01 -XStrontianite: 8.0250e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 360 -SrCO3 added: 3.6000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9689e-01 -XStrontianite: 8.0311e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 361 -SrCO3 added: 3.6100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9629e-01 -XStrontianite: 8.0371e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 362 -SrCO3 added: 3.6200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9569e-01 -XStrontianite: 8.0431e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 363 -SrCO3 added: 3.6300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9509e-01 -XStrontianite: 8.0491e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 364 -SrCO3 added: 3.6400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9450e-01 -XStrontianite: 8.0550e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 365 -SrCO3 added: 3.6500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9391e-01 -XStrontianite: 8.0609e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 366 -SrCO3 added: 3.6600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9332e-01 -XStrontianite: 8.0668e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 367 -SrCO3 added: 3.6700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9274e-01 -XStrontianite: 8.0726e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 368 -SrCO3 added: 3.6800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9216e-01 -XStrontianite: 8.0784e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 369 -SrCO3 added: 3.6900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9158e-01 -XStrontianite: 8.0842e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 370 -SrCO3 added: 3.7000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9101e-01 -XStrontianite: 8.0899e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 371 -SrCO3 added: 3.7100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.9044e-01 -XStrontianite: 8.0956e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 372 -SrCO3 added: 3.7200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8988e-01 -XStrontianite: 8.1012e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 373 -SrCO3 added: 3.7300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8932e-01 -XStrontianite: 8.1068e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 374 -SrCO3 added: 3.7400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8876e-01 -XStrontianite: 8.1124e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 375 -SrCO3 added: 3.7500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8820e-01 -XStrontianite: 8.1180e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 376 -SrCO3 added: 3.7600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8765e-01 -XStrontianite: 8.1235e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 377 -SrCO3 added: 3.7700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8710e-01 -XStrontianite: 8.1290e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 378 -SrCO3 added: 3.7800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8656e-01 -XStrontianite: 8.1344e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 379 -SrCO3 added: 3.7900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8601e-01 -XStrontianite: 8.1399e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 380 -SrCO3 added: 3.8000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8547e-01 -XStrontianite: 8.1453e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 381 -SrCO3 added: 3.8100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8494e-01 -XStrontianite: 8.1506e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 382 -SrCO3 added: 3.8200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8440e-01 -XStrontianite: 8.1560e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 383 -SrCO3 added: 3.8300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8387e-01 -XStrontianite: 8.1613e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 384 -SrCO3 added: 3.8400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8335e-01 -XStrontianite: 8.1665e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 385 -SrCO3 added: 3.8500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8282e-01 -XStrontianite: 8.1718e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 386 -SrCO3 added: 3.8600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8230e-01 -XStrontianite: 8.1770e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 387 -SrCO3 added: 3.8700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8178e-01 -XStrontianite: 8.1822e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 388 -SrCO3 added: 3.8800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8127e-01 -XStrontianite: 8.1873e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 389 -SrCO3 added: 3.8900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8076e-01 -XStrontianite: 8.1924e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 390 -SrCO3 added: 3.9000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.8025e-01 -XStrontianite: 8.1975e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 391 -SrCO3 added: 3.9100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7974e-01 -XStrontianite: 8.2026e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 392 -SrCO3 added: 3.9200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7924e-01 -XStrontianite: 8.2076e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 393 -SrCO3 added: 3.9300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7874e-01 -XStrontianite: 8.2126e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 394 -SrCO3 added: 3.9400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7824e-01 -XStrontianite: 8.2176e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 395 -SrCO3 added: 3.9500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7774e-01 -XStrontianite: 8.2226e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 396 -SrCO3 added: 3.9600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7725e-01 -XStrontianite: 8.2275e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 397 -SrCO3 added: 3.9700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7676e-01 -XStrontianite: 8.2324e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 398 -SrCO3 added: 3.9800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7627e-01 -XStrontianite: 8.2373e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 399 -SrCO3 added: 3.9900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7579e-01 -XStrontianite: 8.2421e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 400 -SrCO3 added: 4.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7531e-01 -XStrontianite: 8.2469e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 401 -SrCO3 added: 4.0100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7483e-01 -XStrontianite: 8.2517e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 402 -SrCO3 added: 4.0200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7435e-01 -XStrontianite: 8.2565e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 403 -SrCO3 added: 4.0300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7388e-01 -XStrontianite: 8.2612e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 404 -SrCO3 added: 4.0400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7341e-01 -XStrontianite: 8.2659e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 405 -SrCO3 added: 4.0500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7294e-01 -XStrontianite: 8.2706e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 406 -SrCO3 added: 4.0600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7247e-01 -XStrontianite: 8.2753e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 407 -SrCO3 added: 4.0700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7201e-01 -XStrontianite: 8.2799e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 408 -SrCO3 added: 4.0800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7155e-01 -XStrontianite: 8.2845e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 409 -SrCO3 added: 4.0900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7109e-01 -XStrontianite: 8.2891e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 410 -SrCO3 added: 4.1000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7063e-01 -XStrontianite: 8.2937e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 411 -SrCO3 added: 4.1100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7018e-01 -XStrontianite: 8.2982e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 412 -SrCO3 added: 4.1200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6973e-01 -XStrontianite: 8.3027e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 413 -SrCO3 added: 4.1300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6928e-01 -XStrontianite: 8.3072e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 414 -SrCO3 added: 4.1400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6883e-01 -XStrontianite: 8.3117e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 415 -SrCO3 added: 4.1500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6839e-01 -XStrontianite: 8.3161e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 416 -SrCO3 added: 4.1600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6794e-01 -XStrontianite: 8.3206e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 417 -SrCO3 added: 4.1700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6750e-01 -XStrontianite: 8.3250e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 418 -SrCO3 added: 4.1800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6707e-01 -XStrontianite: 8.3293e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 419 -SrCO3 added: 4.1900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6663e-01 -XStrontianite: 8.3337e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 420 -SrCO3 added: 4.2000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6620e-01 -XStrontianite: 8.3380e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 421 -SrCO3 added: 4.2100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6577e-01 -XStrontianite: 8.3423e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 422 -SrCO3 added: 4.2200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6534e-01 -XStrontianite: 8.3466e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 423 -SrCO3 added: 4.2300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6491e-01 -XStrontianite: 8.3509e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 424 -SrCO3 added: 4.2400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6449e-01 -XStrontianite: 8.3551e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 425 -SrCO3 added: 4.2500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6407e-01 -XStrontianite: 8.3593e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 426 -SrCO3 added: 4.2600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6365e-01 -XStrontianite: 8.3635e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 427 -SrCO3 added: 4.2700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6323e-01 -XStrontianite: 8.3677e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 428 -SrCO3 added: 4.2800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6282e-01 -XStrontianite: 8.3718e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 429 -SrCO3 added: 4.2900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6240e-01 -XStrontianite: 8.3760e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 430 -SrCO3 added: 4.3000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6199e-01 -XStrontianite: 8.3801e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 431 -SrCO3 added: 4.3100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6158e-01 -XStrontianite: 8.3842e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 432 -SrCO3 added: 4.3200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6117e-01 -XStrontianite: 8.3883e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 433 -SrCO3 added: 4.3300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6077e-01 -XStrontianite: 8.3923e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 434 -SrCO3 added: 4.3400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.6037e-01 -XStrontianite: 8.3963e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 435 -SrCO3 added: 4.3500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5997e-01 -XStrontianite: 8.4003e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 436 -SrCO3 added: 4.3600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5957e-01 -XStrontianite: 8.4043e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 437 -SrCO3 added: 4.3700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5917e-01 -XStrontianite: 8.4083e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 438 -SrCO3 added: 4.3800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5877e-01 -XStrontianite: 8.4123e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 439 -SrCO3 added: 4.3900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5838e-01 -XStrontianite: 8.4162e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 440 -SrCO3 added: 4.4000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5799e-01 -XStrontianite: 8.4201e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 441 -SrCO3 added: 4.4100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5760e-01 -XStrontianite: 8.4240e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 442 -SrCO3 added: 4.4200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5721e-01 -XStrontianite: 8.4279e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 443 -SrCO3 added: 4.4300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5683e-01 -XStrontianite: 8.4317e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 444 -SrCO3 added: 4.4400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5644e-01 -XStrontianite: 8.4356e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 445 -SrCO3 added: 4.4500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5606e-01 -XStrontianite: 8.4394e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 446 -SrCO3 added: 4.4600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5568e-01 -XStrontianite: 8.4432e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 447 -SrCO3 added: 4.4700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5530e-01 -XStrontianite: 8.4470e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 448 -SrCO3 added: 4.4800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5493e-01 -XStrontianite: 8.4507e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 449 -SrCO3 added: 4.4900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5455e-01 -XStrontianite: 8.4545e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 450 -SrCO3 added: 4.5000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5418e-01 -XStrontianite: 8.4582e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 451 -SrCO3 added: 4.5100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5381e-01 -XStrontianite: 8.4619e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 452 -SrCO3 added: 4.5200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5344e-01 -XStrontianite: 8.4656e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 453 -SrCO3 added: 4.5300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5307e-01 -XStrontianite: 8.4693e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 454 -SrCO3 added: 4.5400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5271e-01 -XStrontianite: 8.4729e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 455 -SrCO3 added: 4.5500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5235e-01 -XStrontianite: 8.4765e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 456 -SrCO3 added: 4.5600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5198e-01 -XStrontianite: 8.4802e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 457 -SrCO3 added: 4.5700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5162e-01 -XStrontianite: 8.4838e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 458 -SrCO3 added: 4.5800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5127e-01 -XStrontianite: 8.4873e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 459 -SrCO3 added: 4.5900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5091e-01 -XStrontianite: 8.4909e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 460 -SrCO3 added: 4.6000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5055e-01 -XStrontianite: 8.4945e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 461 -SrCO3 added: 4.6100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.5020e-01 -XStrontianite: 8.4980e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 462 -SrCO3 added: 4.6200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4985e-01 -XStrontianite: 8.5015e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 463 -SrCO3 added: 4.6300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4950e-01 -XStrontianite: 8.5050e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 464 -SrCO3 added: 4.6400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4915e-01 -XStrontianite: 8.5085e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 465 -SrCO3 added: 4.6500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4880e-01 -XStrontianite: 8.5120e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 466 -SrCO3 added: 4.6600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4846e-01 -XStrontianite: 8.5154e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 467 -SrCO3 added: 4.6700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4811e-01 -XStrontianite: 8.5189e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 468 -SrCO3 added: 4.6800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4777e-01 -XStrontianite: 8.5223e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 469 -SrCO3 added: 4.6900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4743e-01 -XStrontianite: 8.5257e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 470 -SrCO3 added: 4.7000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4709e-01 -XStrontianite: 8.5291e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 471 -SrCO3 added: 4.7100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4675e-01 -XStrontianite: 8.5325e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 472 -SrCO3 added: 4.7200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4642e-01 -XStrontianite: 8.5358e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 473 -SrCO3 added: 4.7300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4608e-01 -XStrontianite: 8.5392e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 474 -SrCO3 added: 4.7400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4575e-01 -XStrontianite: 8.5425e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 475 -SrCO3 added: 4.7500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4542e-01 -XStrontianite: 8.5458e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 476 -SrCO3 added: 4.7600e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4509e-01 -XStrontianite: 8.5491e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 477 -SrCO3 added: 4.7700e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4476e-01 -XStrontianite: 8.5524e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 478 -SrCO3 added: 4.7800e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4443e-01 -XStrontianite: 8.5557e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 479 -SrCO3 added: 4.7900e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4411e-01 -XStrontianite: 8.5589e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 480 -SrCO3 added: 4.8000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4379e-01 -XStrontianite: 8.5621e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 481 -SrCO3 added: 4.8100e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4346e-01 -XStrontianite: 8.5654e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 482 -SrCO3 added: 4.8200e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4314e-01 -XStrontianite: 8.5686e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 483 -SrCO3 added: 4.8300e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4282e-01 -XStrontianite: 8.5718e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 484 -SrCO3 added: 4.8400e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4250e-01 -XStrontianite: 8.5750e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 485 -SrCO3 added: 4.8500e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.4219e-01 -XStrontianite: 8.5781e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 486 -SrCO3 added: 4.8600e-03 -Log Sigma pi: -8.2975e+00 -XAragonite: 1.4210e-01 -XStrontianite: 8.5790e-01 -XCa: 9.0899e-01 -XSr: 9.1014e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 487 -SrCO3 added: 4.8700e-03 -Log Sigma pi: -8.2976e+00 -XAragonite: 1.4206e-01 -XStrontianite: 8.5794e-01 -XCa: 9.0895e-01 -XSr: 9.1046e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 488 -SrCO3 added: 4.8800e-03 -Log Sigma pi: -8.2977e+00 -XAragonite: 1.4202e-01 -XStrontianite: 8.5798e-01 -XCa: 9.0892e-01 -XSr: 9.1078e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 489 -SrCO3 added: 4.8900e-03 -Log Sigma pi: -8.2979e+00 -XAragonite: 1.4197e-01 -XStrontianite: 8.5803e-01 -XCa: 9.0889e-01 -XSr: 9.1110e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 490 -SrCO3 added: 4.9000e-03 -Log Sigma pi: -8.2980e+00 -XAragonite: 1.4193e-01 -XStrontianite: 8.5807e-01 -XCa: 9.0886e-01 -XSr: 9.1142e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 491 -SrCO3 added: 4.9100e-03 -Log Sigma pi: -8.2981e+00 -XAragonite: 1.4189e-01 -XStrontianite: 8.5811e-01 -XCa: 9.0883e-01 -XSr: 9.1174e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 492 -SrCO3 added: 4.9200e-03 -Log Sigma pi: -8.2982e+00 -XAragonite: 1.4185e-01 -XStrontianite: 8.5815e-01 -XCa: 9.0879e-01 -XSr: 9.1206e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 493 -SrCO3 added: 4.9300e-03 -Log Sigma pi: -8.2984e+00 -XAragonite: 1.4181e-01 -XStrontianite: 8.5819e-01 -XCa: 9.0876e-01 -XSr: 9.1238e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 494 -SrCO3 added: 4.9400e-03 -Log Sigma pi: -8.2985e+00 -XAragonite: 1.4176e-01 -XStrontianite: 8.5824e-01 -XCa: 9.0873e-01 -XSr: 9.1270e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 495 -SrCO3 added: 4.9500e-03 -Log Sigma pi: -8.2986e+00 -XAragonite: 1.4172e-01 -XStrontianite: 8.5828e-01 -XCa: 9.0870e-01 -XSr: 9.1302e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 496 -SrCO3 added: 4.9600e-03 -Log Sigma pi: -8.2988e+00 -XAragonite: 1.4168e-01 -XStrontianite: 8.5832e-01 -XCa: 9.0867e-01 -XSr: 9.1334e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 497 -SrCO3 added: 4.9700e-03 -Log Sigma pi: -8.2989e+00 -XAragonite: 1.4164e-01 -XStrontianite: 8.5836e-01 -XCa: 9.0863e-01 -XSr: 9.1366e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 498 -SrCO3 added: 4.9800e-03 -Log Sigma pi: -8.2990e+00 -XAragonite: 1.4160e-01 -XStrontianite: 8.5840e-01 -XCa: 9.0860e-01 -XSr: 9.1398e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 499 -SrCO3 added: 4.9900e-03 -Log Sigma pi: -8.2991e+00 -XAragonite: 1.4155e-01 -XStrontianite: 8.5845e-01 -XCa: 9.0857e-01 -XSr: 9.1429e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 4 -Reaction step number: 500 -SrCO3 added: 5.0000e-03 -Log Sigma pi: -8.2993e+00 -XAragonite: 1.4151e-01 -XStrontianite: 8.5849e-01 -XCa: 9.0854e-01 -XSr: 9.1461e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - - USE solution 1 - USE solid_solution 1 - REACTION 1 - SrCO3 1.0 - .1 in 100 steps - END -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 1 -SrCO3 added: 1.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 9.8567e-01 -XStrontianite: 1.4329e-02 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 2 -SrCO3 added: 2.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 3.8793e-01 -XStrontianite: 6.1207e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 3 -SrCO3 added: 3.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 2.4149e-01 -XStrontianite: 7.5851e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 4 -SrCO3 added: 4.0000e-03 -Log Sigma pi: -8.2974e+00 -XAragonite: 1.7531e-01 -XStrontianite: 8.2469e-01 -XCa: 9.0901e-01 -XSr: 9.0987e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 5 -SrCO3 added: 5.0000e-03 -Log Sigma pi: -8.2993e+00 -XAragonite: 1.4151e-01 -XStrontianite: 8.5849e-01 -XCa: 9.0854e-01 -XSr: 9.1461e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 6 -SrCO3 added: 6.0000e-03 -Log Sigma pi: -8.3118e+00 -XAragonite: 1.3751e-01 -XStrontianite: 8.6249e-01 -XCa: 9.0539e-01 -XSr: 9.4606e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 7 -SrCO3 added: 7.0000e-03 -Log Sigma pi: -8.3236e+00 -XAragonite: 1.3383e-01 -XStrontianite: 8.6617e-01 -XCa: 9.0233e-01 -XSr: 9.7673e-02 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 8 -SrCO3 added: 8.0000e-03 -Log Sigma pi: -8.3349e+00 -XAragonite: 1.3043e-01 -XStrontianite: 8.6957e-01 -XCa: 8.9933e-01 -XSr: 1.0067e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 9 -SrCO3 added: 9.0000e-03 -Log Sigma pi: -8.3456e+00 -XAragonite: 1.2726e-01 -XStrontianite: 8.7274e-01 -XCa: 8.9640e-01 -XSr: 1.0360e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 10 -SrCO3 added: 1.0000e-02 -Log Sigma pi: -8.3559e+00 -XAragonite: 1.2431e-01 -XStrontianite: 8.7569e-01 -XCa: 8.9352e-01 -XSr: 1.0648e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 11 -SrCO3 added: 1.1000e-02 -Log Sigma pi: -8.3658e+00 -XAragonite: 1.2155e-01 -XStrontianite: 8.7845e-01 -XCa: 8.9070e-01 -XSr: 1.0930e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 12 -SrCO3 added: 1.2000e-02 -Log Sigma pi: -8.3752e+00 -XAragonite: 1.1895e-01 -XStrontianite: 8.8105e-01 -XCa: 8.8792e-01 -XSr: 1.1208e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 13 -SrCO3 added: 1.3000e-02 -Log Sigma pi: -8.3843e+00 -XAragonite: 1.1650e-01 -XStrontianite: 8.8350e-01 -XCa: 8.8519e-01 -XSr: 1.1481e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 14 -SrCO3 added: 1.4000e-02 -Log Sigma pi: -8.3931e+00 -XAragonite: 1.1419e-01 -XStrontianite: 8.8581e-01 -XCa: 8.8251e-01 -XSr: 1.1749e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 15 -SrCO3 added: 1.5000e-02 -Log Sigma pi: -8.4016e+00 -XAragonite: 1.1199e-01 -XStrontianite: 8.8801e-01 -XCa: 8.7986e-01 -XSr: 1.2014e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 16 -SrCO3 added: 1.6000e-02 -Log Sigma pi: -8.4098e+00 -XAragonite: 1.0991e-01 -XStrontianite: 8.9009e-01 -XCa: 8.7725e-01 -XSr: 1.2275e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 17 -SrCO3 added: 1.7000e-02 -Log Sigma pi: -8.4178e+00 -XAragonite: 1.0793e-01 -XStrontianite: 8.9207e-01 -XCa: 8.7468e-01 -XSr: 1.2532e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 18 -SrCO3 added: 1.8000e-02 -Log Sigma pi: -8.4254e+00 -XAragonite: 1.0604e-01 -XStrontianite: 8.9396e-01 -XCa: 8.7214e-01 -XSr: 1.2786e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 19 -SrCO3 added: 1.9000e-02 -Log Sigma pi: -8.4329e+00 -XAragonite: 1.0423e-01 -XStrontianite: 8.9577e-01 -XCa: 8.6963e-01 -XSr: 1.3037e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 20 -SrCO3 added: 2.0000e-02 -Log Sigma pi: -8.4401e+00 -XAragonite: 1.0251e-01 -XStrontianite: 8.9749e-01 -XCa: 8.6716e-01 -XSr: 1.3284e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 21 -SrCO3 added: 2.1000e-02 -Log Sigma pi: -8.4472e+00 -XAragonite: 1.0086e-01 -XStrontianite: 8.9914e-01 -XCa: 8.6471e-01 -XSr: 1.3529e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 22 -SrCO3 added: 2.2000e-02 -Log Sigma pi: -8.4540e+00 -XAragonite: 9.9270e-02 -XStrontianite: 9.0073e-01 -XCa: 8.6230e-01 -XSr: 1.3770e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 23 -SrCO3 added: 2.3000e-02 -Log Sigma pi: -8.4607e+00 -XAragonite: 9.7747e-02 -XStrontianite: 9.0225e-01 -XCa: 8.5991e-01 -XSr: 1.4009e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 24 -SrCO3 added: 2.4000e-02 -Log Sigma pi: -8.4672e+00 -XAragonite: 9.6283e-02 -XStrontianite: 9.0372e-01 -XCa: 8.5754e-01 -XSr: 1.4246e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 25 -SrCO3 added: 2.5000e-02 -Log Sigma pi: -8.4735e+00 -XAragonite: 9.4874e-02 -XStrontianite: 9.0513e-01 -XCa: 8.5520e-01 -XSr: 1.4480e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 26 -SrCO3 added: 2.6000e-02 -Log Sigma pi: -8.4797e+00 -XAragonite: 9.3517e-02 -XStrontianite: 9.0648e-01 -XCa: 8.5289e-01 -XSr: 1.4711e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 27 -SrCO3 added: 2.7000e-02 -Log Sigma pi: -8.4857e+00 -XAragonite: 9.2208e-02 -XStrontianite: 9.0779e-01 -XCa: 8.5060e-01 -XSr: 1.4940e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 28 -SrCO3 added: 2.8000e-02 -Log Sigma pi: -8.4915e+00 -XAragonite: 9.0944e-02 -XStrontianite: 9.0906e-01 -XCa: 8.4833e-01 -XSr: 1.5167e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 29 -SrCO3 added: 2.9000e-02 -Log Sigma pi: -8.4973e+00 -XAragonite: 8.9723e-02 -XStrontianite: 9.1028e-01 -XCa: 8.4608e-01 -XSr: 1.5392e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 30 -SrCO3 added: 3.0000e-02 -Log Sigma pi: -8.5029e+00 -XAragonite: 8.8542e-02 -XStrontianite: 9.1146e-01 -XCa: 8.4386e-01 -XSr: 1.5614e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 31 -SrCO3 added: 3.1000e-02 -Log Sigma pi: -8.5084e+00 -XAragonite: 8.7400e-02 -XStrontianite: 9.1260e-01 -XCa: 8.4166e-01 -XSr: 1.5834e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 32 -SrCO3 added: 3.2000e-02 -Log Sigma pi: -8.5137e+00 -XAragonite: 8.6294e-02 -XStrontianite: 9.1371e-01 -XCa: 8.3947e-01 -XSr: 1.6053e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 33 -SrCO3 added: 3.3000e-02 -Log Sigma pi: -8.5190e+00 -XAragonite: 8.5221e-02 -XStrontianite: 9.1478e-01 -XCa: 8.3731e-01 -XSr: 1.6269e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 34 -SrCO3 added: 3.4000e-02 -Log Sigma pi: -8.5241e+00 -XAragonite: 8.4182e-02 -XStrontianite: 9.1582e-01 -XCa: 8.3516e-01 -XSr: 1.6484e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 35 -SrCO3 added: 3.5000e-02 -Log Sigma pi: -8.5292e+00 -XAragonite: 8.3173e-02 -XStrontianite: 9.1683e-01 -XCa: 8.3304e-01 -XSr: 1.6696e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 36 -SrCO3 added: 3.6000e-02 -Log Sigma pi: -8.5341e+00 -XAragonite: 8.2193e-02 -XStrontianite: 9.1781e-01 -XCa: 8.3093e-01 -XSr: 1.6907e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 37 -SrCO3 added: 3.7000e-02 -Log Sigma pi: -8.5390e+00 -XAragonite: 8.1241e-02 -XStrontianite: 9.1876e-01 -XCa: 8.2884e-01 -XSr: 1.7116e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 38 -SrCO3 added: 3.8000e-02 -Log Sigma pi: -8.5437e+00 -XAragonite: 8.0316e-02 -XStrontianite: 9.1968e-01 -XCa: 8.2677e-01 -XSr: 1.7323e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 39 -SrCO3 added: 3.9000e-02 -Log Sigma pi: -8.5484e+00 -XAragonite: 7.9416e-02 -XStrontianite: 9.2058e-01 -XCa: 8.2471e-01 -XSr: 1.7529e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 40 -SrCO3 added: 4.0000e-02 -Log Sigma pi: -8.5529e+00 -XAragonite: 7.8540e-02 -XStrontianite: 9.2146e-01 -XCa: 8.2267e-01 -XSr: 1.7733e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 41 -SrCO3 added: 4.1000e-02 -Log Sigma pi: -8.5574e+00 -XAragonite: 7.7688e-02 -XStrontianite: 9.2231e-01 -XCa: 8.2065e-01 -XSr: 1.7935e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 42 -SrCO3 added: 4.2000e-02 -Log Sigma pi: -8.5618e+00 -XAragonite: 7.6857e-02 -XStrontianite: 9.2314e-01 -XCa: 8.1865e-01 -XSr: 1.8135e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 43 -SrCO3 added: 4.3000e-02 -Log Sigma pi: -8.5662e+00 -XAragonite: 7.6048e-02 -XStrontianite: 9.2395e-01 -XCa: 8.1665e-01 -XSr: 1.8335e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 44 -SrCO3 added: 4.4000e-02 -Log Sigma pi: -8.5704e+00 -XAragonite: 7.5259e-02 -XStrontianite: 9.2474e-01 -XCa: 8.1468e-01 -XSr: 1.8532e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 45 -SrCO3 added: 4.5000e-02 -Log Sigma pi: -8.5746e+00 -XAragonite: 7.4489e-02 -XStrontianite: 9.2551e-01 -XCa: 8.1272e-01 -XSr: 1.8728e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 46 -SrCO3 added: 4.6000e-02 -Log Sigma pi: -8.5787e+00 -XAragonite: 7.3738e-02 -XStrontianite: 9.2626e-01 -XCa: 8.1077e-01 -XSr: 1.8923e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 47 -SrCO3 added: 4.7000e-02 -Log Sigma pi: -8.5827e+00 -XAragonite: 7.3005e-02 -XStrontianite: 9.2699e-01 -XCa: 8.0884e-01 -XSr: 1.9116e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 48 -SrCO3 added: 4.8000e-02 -Log Sigma pi: -8.5867e+00 -XAragonite: 7.2290e-02 -XStrontianite: 9.2771e-01 -XCa: 8.0692e-01 -XSr: 1.9308e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 49 -SrCO3 added: 4.9000e-02 -Log Sigma pi: -8.5906e+00 -XAragonite: 7.1590e-02 -XStrontianite: 9.2841e-01 -XCa: 8.0502e-01 -XSr: 1.9498e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 50 -SrCO3 added: 5.0000e-02 -Log Sigma pi: -8.5945e+00 -XAragonite: 7.0907e-02 -XStrontianite: 9.2909e-01 -XCa: 8.0313e-01 -XSr: 1.9687e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 51 -SrCO3 added: 5.1000e-02 -Log Sigma pi: -8.5982e+00 -XAragonite: 7.0239e-02 -XStrontianite: 9.2976e-01 -XCa: 8.0125e-01 -XSr: 1.9875e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 52 -SrCO3 added: 5.2000e-02 -Log Sigma pi: -8.6020e+00 -XAragonite: 6.9586e-02 -XStrontianite: 9.3041e-01 -XCa: 7.9939e-01 -XSr: 2.0061e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 53 -SrCO3 added: 5.3000e-02 -Log Sigma pi: -8.6056e+00 -XAragonite: 6.8947e-02 -XStrontianite: 9.3105e-01 -XCa: 7.9753e-01 -XSr: 2.0247e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 54 -SrCO3 added: 5.4000e-02 -Log Sigma pi: -8.6092e+00 -XAragonite: 6.8322e-02 -XStrontianite: 9.3168e-01 -XCa: 7.9570e-01 -XSr: 2.0430e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 55 -SrCO3 added: 5.5000e-02 -Log Sigma pi: -8.6128e+00 -XAragonite: 6.7710e-02 -XStrontianite: 9.3229e-01 -XCa: 7.9387e-01 -XSr: 2.0613e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 56 -SrCO3 added: 5.6000e-02 -Log Sigma pi: -8.6163e+00 -XAragonite: 6.7111e-02 -XStrontianite: 9.3289e-01 -XCa: 7.9206e-01 -XSr: 2.0794e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 57 -SrCO3 added: 5.7000e-02 -Log Sigma pi: -8.6198e+00 -XAragonite: 6.6524e-02 -XStrontianite: 9.3348e-01 -XCa: 7.9026e-01 -XSr: 2.0974e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 58 -SrCO3 added: 5.8000e-02 -Log Sigma pi: -8.6232e+00 -XAragonite: 6.5950e-02 -XStrontianite: 9.3405e-01 -XCa: 7.8847e-01 -XSr: 2.1153e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 59 -SrCO3 added: 5.9000e-02 -Log Sigma pi: -8.6265e+00 -XAragonite: 6.5386e-02 -XStrontianite: 9.3461e-01 -XCa: 7.8669e-01 -XSr: 2.1331e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 60 -SrCO3 added: 6.0000e-02 -Log Sigma pi: -8.6298e+00 -XAragonite: 6.4834e-02 -XStrontianite: 9.3517e-01 -XCa: 7.8492e-01 -XSr: 2.1508e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 61 -SrCO3 added: 6.1000e-02 -Log Sigma pi: -8.6331e+00 -XAragonite: 6.4293e-02 -XStrontianite: 9.3571e-01 -XCa: 7.8317e-01 -XSr: 2.1683e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 62 -SrCO3 added: 6.2000e-02 -Log Sigma pi: -8.6363e+00 -XAragonite: 6.3762e-02 -XStrontianite: 9.3624e-01 -XCa: 7.8142e-01 -XSr: 2.1858e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 63 -SrCO3 added: 6.3000e-02 -Log Sigma pi: -8.6395e+00 -XAragonite: 6.3242e-02 -XStrontianite: 9.3676e-01 -XCa: 7.7969e-01 -XSr: 2.2031e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 64 -SrCO3 added: 6.4000e-02 -Log Sigma pi: -8.6426e+00 -XAragonite: 6.2731e-02 -XStrontianite: 9.3727e-01 -XCa: 7.7797e-01 -XSr: 2.2203e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 65 -SrCO3 added: 6.5000e-02 -Log Sigma pi: -8.6457e+00 -XAragonite: 6.2230e-02 -XStrontianite: 9.3777e-01 -XCa: 7.7626e-01 -XSr: 2.2374e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 66 -SrCO3 added: 6.6000e-02 -Log Sigma pi: -8.6487e+00 -XAragonite: 6.1738e-02 -XStrontianite: 9.3826e-01 -XCa: 7.7456e-01 -XSr: 2.2544e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 67 -SrCO3 added: 6.7000e-02 -Log Sigma pi: -8.6517e+00 -XAragonite: 6.1255e-02 -XStrontianite: 9.3875e-01 -XCa: 7.7287e-01 -XSr: 2.2713e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 68 -SrCO3 added: 6.8000e-02 -Log Sigma pi: -8.6547e+00 -XAragonite: 6.0780e-02 -XStrontianite: 9.3922e-01 -XCa: 7.7119e-01 -XSr: 2.2881e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 69 -SrCO3 added: 6.9000e-02 -Log Sigma pi: -8.6576e+00 -XAragonite: 6.0314e-02 -XStrontianite: 9.3969e-01 -XCa: 7.6952e-01 -XSr: 2.3048e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 70 -SrCO3 added: 7.0000e-02 -Log Sigma pi: -8.6605e+00 -XAragonite: 5.9857e-02 -XStrontianite: 9.4014e-01 -XCa: 7.6786e-01 -XSr: 2.3214e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 71 -SrCO3 added: 7.1000e-02 -Log Sigma pi: -8.6634e+00 -XAragonite: 5.9407e-02 -XStrontianite: 9.4059e-01 -XCa: 7.6621e-01 -XSr: 2.3379e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 72 -SrCO3 added: 7.2000e-02 -Log Sigma pi: -8.6662e+00 -XAragonite: 5.8965e-02 -XStrontianite: 9.4103e-01 -XCa: 7.6457e-01 -XSr: 2.3543e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 73 -SrCO3 added: 7.3000e-02 -Log Sigma pi: -8.6690e+00 -XAragonite: 5.8531e-02 -XStrontianite: 9.4147e-01 -XCa: 7.6294e-01 -XSr: 2.3706e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 74 -SrCO3 added: 7.4000e-02 -Log Sigma pi: -8.6718e+00 -XAragonite: 5.8104e-02 -XStrontianite: 9.4190e-01 -XCa: 7.6132e-01 -XSr: 2.3868e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 75 -SrCO3 added: 7.5000e-02 -Log Sigma pi: -8.6745e+00 -XAragonite: 5.7684e-02 -XStrontianite: 9.4232e-01 -XCa: 7.5970e-01 -XSr: 2.4030e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 76 -SrCO3 added: 7.6000e-02 -Log Sigma pi: -8.6772e+00 -XAragonite: 5.7271e-02 -XStrontianite: 9.4273e-01 -XCa: 7.5810e-01 -XSr: 2.4190e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 77 -SrCO3 added: 7.7000e-02 -Log Sigma pi: -8.6798e+00 -XAragonite: 5.6864e-02 -XStrontianite: 9.4314e-01 -XCa: 7.5651e-01 -XSr: 2.4349e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 78 -SrCO3 added: 7.8000e-02 -Log Sigma pi: -8.6824e+00 -XAragonite: 5.6465e-02 -XStrontianite: 9.4354e-01 -XCa: 7.5492e-01 -XSr: 2.4508e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 79 -SrCO3 added: 7.9000e-02 -Log Sigma pi: -8.6850e+00 -XAragonite: 5.6071e-02 -XStrontianite: 9.4393e-01 -XCa: 7.5335e-01 -XSr: 2.4665e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 80 -SrCO3 added: 8.0000e-02 -Log Sigma pi: -8.6876e+00 -XAragonite: 5.5684e-02 -XStrontianite: 9.4432e-01 -XCa: 7.5178e-01 -XSr: 2.4822e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 81 -SrCO3 added: 8.1000e-02 -Log Sigma pi: -8.6901e+00 -XAragonite: 5.5303e-02 -XStrontianite: 9.4470e-01 -XCa: 7.5023e-01 -XSr: 2.4977e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 82 -SrCO3 added: 8.2000e-02 -Log Sigma pi: -8.6926e+00 -XAragonite: 5.4928e-02 -XStrontianite: 9.4507e-01 -XCa: 7.4868e-01 -XSr: 2.5132e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 83 -SrCO3 added: 8.3000e-02 -Log Sigma pi: -8.6951e+00 -XAragonite: 5.4559e-02 -XStrontianite: 9.4544e-01 -XCa: 7.4714e-01 -XSr: 2.5286e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 84 -SrCO3 added: 8.4000e-02 -Log Sigma pi: -8.6976e+00 -XAragonite: 5.4196e-02 -XStrontianite: 9.4580e-01 -XCa: 7.4560e-01 -XSr: 2.5440e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 85 -SrCO3 added: 8.5000e-02 -Log Sigma pi: -8.7000e+00 -XAragonite: 5.3837e-02 -XStrontianite: 9.4616e-01 -XCa: 7.4408e-01 -XSr: 2.5592e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 86 -SrCO3 added: 8.6000e-02 -Log Sigma pi: -8.7024e+00 -XAragonite: 5.3485e-02 -XStrontianite: 9.4652e-01 -XCa: 7.4256e-01 -XSr: 2.5744e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 87 -SrCO3 added: 8.7000e-02 -Log Sigma pi: -8.7047e+00 -XAragonite: 5.3137e-02 -XStrontianite: 9.4686e-01 -XCa: 7.4106e-01 -XSr: 2.5894e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 88 -SrCO3 added: 8.8000e-02 -Log Sigma pi: -8.7071e+00 -XAragonite: 5.2795e-02 -XStrontianite: 9.4721e-01 -XCa: 7.3956e-01 -XSr: 2.6044e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 89 -SrCO3 added: 8.9000e-02 -Log Sigma pi: -8.7094e+00 -XAragonite: 5.2457e-02 -XStrontianite: 9.4754e-01 -XCa: 7.3807e-01 -XSr: 2.6193e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 90 -SrCO3 added: 9.0000e-02 -Log Sigma pi: -8.7117e+00 -XAragonite: 5.2125e-02 -XStrontianite: 9.4788e-01 -XCa: 7.3658e-01 -XSr: 2.6342e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 91 -SrCO3 added: 9.1000e-02 -Log Sigma pi: -8.7140e+00 -XAragonite: 5.1797e-02 -XStrontianite: 9.4820e-01 -XCa: 7.3511e-01 -XSr: 2.6489e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 92 -SrCO3 added: 9.2000e-02 -Log Sigma pi: -8.7162e+00 -XAragonite: 5.1474e-02 -XStrontianite: 9.4853e-01 -XCa: 7.3364e-01 -XSr: 2.6636e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 93 -SrCO3 added: 9.3000e-02 -Log Sigma pi: -8.7185e+00 -XAragonite: 5.1155e-02 -XStrontianite: 9.4884e-01 -XCa: 7.3218e-01 -XSr: 2.6782e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 94 -SrCO3 added: 9.4000e-02 -Log Sigma pi: -8.7207e+00 -XAragonite: 5.0841e-02 -XStrontianite: 9.4916e-01 -XCa: 7.3073e-01 -XSr: 2.6927e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 95 -SrCO3 added: 9.5000e-02 -Log Sigma pi: -8.7228e+00 -XAragonite: 5.0531e-02 -XStrontianite: 9.4947e-01 -XCa: 7.2928e-01 -XSr: 2.7072e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 96 -SrCO3 added: 9.6000e-02 -Log Sigma pi: -8.7250e+00 -XAragonite: 5.0226e-02 -XStrontianite: 9.4977e-01 -XCa: 7.2784e-01 -XSr: 2.7216e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 97 -SrCO3 added: 9.7000e-02 -Log Sigma pi: -8.7271e+00 -XAragonite: 4.9924e-02 -XStrontianite: 9.5008e-01 -XCa: 7.2641e-01 -XSr: 2.7359e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 98 -SrCO3 added: 9.8000e-02 -Log Sigma pi: -8.7292e+00 -XAragonite: 4.9627e-02 -XStrontianite: 9.5037e-01 -XCa: 7.2499e-01 -XSr: 2.7501e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 99 -SrCO3 added: 9.9000e-02 -Log Sigma pi: -8.7313e+00 -XAragonite: 4.9334e-02 -XStrontianite: 9.5067e-01 -XCa: 7.2357e-01 -XSr: 2.7643e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 5 -Reaction step number: 100 -SrCO3 added: 1.0000e-01 -Log Sigma pi: -8.7334e+00 -XAragonite: 4.9044e-02 -XStrontianite: 9.5096e-01 -XCa: 7.2216e-01 -XSr: 2.7784e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - - USE solution 1 - USE solid_solution 1 - REACTION 1 - SrCO3 1.0 - 10.0 in 100 steps - END -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 1 -SrCO3 added: 1.0000e-01 -Log Sigma pi: -8.7334e+00 -XAragonite: 4.9044e-02 -XStrontianite: 9.5096e-01 -XCa: 7.2216e-01 -XSr: 2.7784e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 2 -SrCO3 added: 2.0000e-01 -Log Sigma pi: -8.8746e+00 -XAragonite: 3.1529e-02 -XStrontianite: 9.6847e-01 -XCa: 6.0843e-01 -XSr: 3.9157e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 3 -SrCO3 added: 3.0000e-01 -Log Sigma pi: -8.9515e+00 -XAragonite: 2.3611e-02 -XStrontianite: 9.7639e-01 -XCa: 5.2912e-01 -XSr: 4.7088e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 4 -SrCO3 added: 4.0000e-01 -Log Sigma pi: -9.0015e+00 -XAragonite: 1.8992e-02 -XStrontianite: 9.8101e-01 -XCa: 4.6954e-01 -XSr: 5.3046e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 5 -SrCO3 added: 5.0000e-01 -Log Sigma pi: -9.0371e+00 -XAragonite: 1.5935e-02 -XStrontianite: 9.8407e-01 -XCa: 4.2272e-01 -XSr: 5.7728e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 6 -SrCO3 added: 6.0000e-01 -Log Sigma pi: -9.0640e+00 -XAragonite: 1.3750e-02 -XStrontianite: 9.8625e-01 -XCa: 3.8479e-01 -XSr: 6.1521e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 7 -SrCO3 added: 7.0000e-01 -Log Sigma pi: -9.0851e+00 -XAragonite: 1.2105e-02 -XStrontianite: 9.8790e-01 -XCa: 3.5335e-01 -XSr: 6.4665e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 8 -SrCO3 added: 8.0000e-01 -Log Sigma pi: -9.1022e+00 -XAragonite: 1.0819e-02 -XStrontianite: 9.8918e-01 -XCa: 3.2680e-01 -XSr: 6.7320e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 9 -SrCO3 added: 9.0000e-01 -Log Sigma pi: -9.1162e+00 -XAragonite: 9.7855e-03 -XStrontianite: 9.9021e-01 -XCa: 3.0406e-01 -XSr: 6.9594e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 10 -SrCO3 added: 1 -Log Sigma pi: -9.1281e+00 -XAragonite: 8.9352e-03 -XStrontianite: 9.9106e-01 -XCa: 2.8435e-01 -XSr: 7.1565e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 11 -SrCO3 added: 1.1000e+00 -Log Sigma pi: -9.1382e+00 -XAragonite: 8.2229e-03 -XStrontianite: 9.9178e-01 -XCa: 2.6708e-01 -XSr: 7.3292e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 12 -SrCO3 added: 1.2000e+00 -Log Sigma pi: -9.1470e+00 -XAragonite: 7.6172e-03 -XStrontianite: 9.9238e-01 -XCa: 2.5183e-01 -XSr: 7.4817e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 13 -SrCO3 added: 1.3000e+00 -Log Sigma pi: -9.1547e+00 -XAragonite: 7.0957e-03 -XStrontianite: 9.9290e-01 -XCa: 2.3825e-01 -XSr: 7.6175e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 14 -SrCO3 added: 1.4000e+00 -Log Sigma pi: -9.1614e+00 -XAragonite: 6.6418e-03 -XStrontianite: 9.9336e-01 -XCa: 2.2608e-01 -XSr: 7.7392e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 15 -SrCO3 added: 1.5000e+00 -Log Sigma pi: -9.1674e+00 -XAragonite: 6.2431e-03 -XStrontianite: 9.9376e-01 -XCa: 2.1511e-01 -XSr: 7.8489e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 16 -SrCO3 added: 1.6000e+00 -Log Sigma pi: -9.1728e+00 -XAragonite: 5.8899e-03 -XStrontianite: 9.9411e-01 -XCa: 2.0516e-01 -XSr: 7.9484e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 17 -SrCO3 added: 1.7000e+00 -Log Sigma pi: -9.1776e+00 -XAragonite: 5.5749e-03 -XStrontianite: 9.9443e-01 -XCa: 1.9610e-01 -XSr: 8.0390e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 18 -SrCO3 added: 1.8000e+00 -Log Sigma pi: -9.1820e+00 -XAragonite: 5.2921e-03 -XStrontianite: 9.9471e-01 -XCa: 1.8782e-01 -XSr: 8.1218e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 19 -SrCO3 added: 1.9000e+00 -Log Sigma pi: -9.1860e+00 -XAragonite: 5.0369e-03 -XStrontianite: 9.9496e-01 -XCa: 1.8021e-01 -XSr: 8.1979e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 20 -SrCO3 added: 2 -Log Sigma pi: -9.1896e+00 -XAragonite: 4.8052e-03 -XStrontianite: 9.9519e-01 -XCa: 1.7320e-01 -XSr: 8.2680e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 21 -SrCO3 added: 2.1000e+00 -Log Sigma pi: -9.1929e+00 -XAragonite: 4.5941e-03 -XStrontianite: 9.9541e-01 -XCa: 1.6672e-01 -XSr: 8.3328e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 22 -SrCO3 added: 2.2000e+00 -Log Sigma pi: -9.1960e+00 -XAragonite: 4.4009e-03 -XStrontianite: 9.9560e-01 -XCa: 1.6071e-01 -XSr: 8.3929e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 23 -SrCO3 added: 2.3000e+00 -Log Sigma pi: -9.1988e+00 -XAragonite: 4.2233e-03 -XStrontianite: 9.9578e-01 -XCa: 1.5512e-01 -XSr: 8.4488e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 24 -SrCO3 added: 2.4000e+00 -Log Sigma pi: -9.2015e+00 -XAragonite: 4.0596e-03 -XStrontianite: 9.9594e-01 -XCa: 1.4990e-01 -XSr: 8.5010e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 25 -SrCO3 added: 2.5000e+00 -Log Sigma pi: -9.2039e+00 -XAragonite: 3.9082e-03 -XStrontianite: 9.9609e-01 -XCa: 1.4503e-01 -XSr: 8.5497e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 26 -SrCO3 added: 2.6000e+00 -Log Sigma pi: -9.2062e+00 -XAragonite: 3.7677e-03 -XStrontianite: 9.9623e-01 -XCa: 1.4047e-01 -XSr: 8.5953e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 27 -SrCO3 added: 2.7000e+00 -Log Sigma pi: -9.2083e+00 -XAragonite: 3.6370e-03 -XStrontianite: 9.9636e-01 -XCa: 1.3618e-01 -XSr: 8.6382e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 28 -SrCO3 added: 2.8000e+00 -Log Sigma pi: -9.2103e+00 -XAragonite: 3.5151e-03 -XStrontianite: 9.9648e-01 -XCa: 1.3216e-01 -XSr: 8.6784e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 29 -SrCO3 added: 2.9000e+00 -Log Sigma pi: -9.2122e+00 -XAragonite: 3.4011e-03 -XStrontianite: 9.9660e-01 -XCa: 1.2836e-01 -XSr: 8.7164e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 30 -SrCO3 added: 3 -Log Sigma pi: -9.2139e+00 -XAragonite: 3.2944e-03 -XStrontianite: 9.9671e-01 -XCa: 1.2478e-01 -XSr: 8.7522e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 31 -SrCO3 added: 3.1000e+00 -Log Sigma pi: -9.2156e+00 -XAragonite: 3.1941e-03 -XStrontianite: 9.9681e-01 -XCa: 1.2139e-01 -XSr: 8.7861e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 32 -SrCO3 added: 3.2000e+00 -Log Sigma pi: -9.2171e+00 -XAragonite: 3.0998e-03 -XStrontianite: 9.9690e-01 -XCa: 1.1818e-01 -XSr: 8.8182e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 33 -SrCO3 added: 3.3000e+00 -Log Sigma pi: -9.2186e+00 -XAragonite: 3.0109e-03 -XStrontianite: 9.9699e-01 -XCa: 1.1514e-01 -XSr: 8.8486e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 34 -SrCO3 added: 3.4000e+00 -Log Sigma pi: -9.2200e+00 -XAragonite: 2.9270e-03 -XStrontianite: 9.9707e-01 -XCa: 1.1225e-01 -XSr: 8.8775e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 35 -SrCO3 added: 3.5000e+00 -Log Sigma pi: -9.2213e+00 -XAragonite: 2.8476e-03 -XStrontianite: 9.9715e-01 -XCa: 1.0950e-01 -XSr: 8.9050e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 36 -SrCO3 added: 3.6000e+00 -Log Sigma pi: -9.2226e+00 -XAragonite: 2.7725e-03 -XStrontianite: 9.9723e-01 -XCa: 1.0688e-01 -XSr: 8.9312e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 37 -SrCO3 added: 3.7000e+00 -Log Sigma pi: -9.2238e+00 -XAragonite: 2.7012e-03 -XStrontianite: 9.9730e-01 -XCa: 1.0439e-01 -XSr: 8.9561e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 38 -SrCO3 added: 3.8000e+00 -Log Sigma pi: -9.2249e+00 -XAragonite: 2.6335e-03 -XStrontianite: 9.9737e-01 -XCa: 1.0201e-01 -XSr: 8.9799e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 39 -SrCO3 added: 3.9000e+00 -Log Sigma pi: -9.2260e+00 -XAragonite: 2.5691e-03 -XStrontianite: 9.9743e-01 -XCa: 9.9738e-02 -XSr: 9.0026e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 40 -SrCO3 added: 4 -Log Sigma pi: -9.2270e+00 -XAragonite: 2.5078e-03 -XStrontianite: 9.9749e-01 -XCa: 9.7564e-02 -XSr: 9.0244e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 41 -SrCO3 added: 4.1000e+00 -Log Sigma pi: -9.2280e+00 -XAragonite: 2.4494e-03 -XStrontianite: 9.9755e-01 -XCa: 9.5483e-02 -XSr: 9.0452e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 42 -SrCO3 added: 4.2000e+00 -Log Sigma pi: -9.2289e+00 -XAragonite: 2.3936e-03 -XStrontianite: 9.9761e-01 -XCa: 9.3489e-02 -XSr: 9.0651e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 43 -SrCO3 added: 4.3000e+00 -Log Sigma pi: -9.2298e+00 -XAragonite: 2.3404e-03 -XStrontianite: 9.9766e-01 -XCa: 9.1577e-02 -XSr: 9.0842e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 44 -SrCO3 added: 4.4000e+00 -Log Sigma pi: -9.2307e+00 -XAragonite: 2.2894e-03 -XStrontianite: 9.9771e-01 -XCa: 8.9742e-02 -XSr: 9.1026e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 45 -SrCO3 added: 4.5000e+00 -Log Sigma pi: -9.2315e+00 -XAragonite: 2.2406e-03 -XStrontianite: 9.9776e-01 -XCa: 8.7979e-02 -XSr: 9.1202e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 46 -SrCO3 added: 4.6000e+00 -Log Sigma pi: -9.2323e+00 -XAragonite: 2.1939e-03 -XStrontianite: 9.9781e-01 -XCa: 8.6284e-02 -XSr: 9.1372e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 47 -SrCO3 added: 4.7000e+00 -Log Sigma pi: -9.2331e+00 -XAragonite: 2.1491e-03 -XStrontianite: 9.9785e-01 -XCa: 8.4653e-02 -XSr: 9.1535e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 48 -SrCO3 added: 4.8000e+00 -Log Sigma pi: -9.2338e+00 -XAragonite: 2.1060e-03 -XStrontianite: 9.9789e-01 -XCa: 8.3083e-02 -XSr: 9.1692e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 49 -SrCO3 added: 4.9000e+00 -Log Sigma pi: -9.2345e+00 -XAragonite: 2.0647e-03 -XStrontianite: 9.9794e-01 -XCa: 8.1570e-02 -XSr: 9.1843e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 50 -SrCO3 added: 5 -Log Sigma pi: -9.2352e+00 -XAragonite: 2.0249e-03 -XStrontianite: 9.9798e-01 -XCa: 8.0112e-02 -XSr: 9.1989e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 51 -SrCO3 added: 5.1000e+00 -Log Sigma pi: -9.2359e+00 -XAragonite: 1.9867e-03 -XStrontianite: 9.9801e-01 -XCa: 7.8704e-02 -XSr: 9.2130e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 52 -SrCO3 added: 5.2000e+00 -Log Sigma pi: -9.2365e+00 -XAragonite: 1.9499e-03 -XStrontianite: 9.9805e-01 -XCa: 7.7346e-02 -XSr: 9.2265e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 53 -SrCO3 added: 5.3000e+00 -Log Sigma pi: -9.2371e+00 -XAragonite: 1.9144e-03 -XStrontianite: 9.9809e-01 -XCa: 7.6033e-02 -XSr: 9.2397e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 54 -SrCO3 added: 5.4000e+00 -Log Sigma pi: -9.2377e+00 -XAragonite: 1.8802e-03 -XStrontianite: 9.9812e-01 -XCa: 7.4765e-02 -XSr: 9.2524e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 55 -SrCO3 added: 5.5000e+00 -Log Sigma pi: -9.2383e+00 -XAragonite: 1.8472e-03 -XStrontianite: 9.9815e-01 -XCa: 7.3538e-02 -XSr: 9.2646e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 56 -SrCO3 added: 5.6000e+00 -Log Sigma pi: -9.2388e+00 -XAragonite: 1.8153e-03 -XStrontianite: 9.9818e-01 -XCa: 7.2350e-02 -XSr: 9.2765e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 57 -SrCO3 added: 5.7000e+00 -Log Sigma pi: -9.2393e+00 -XAragonite: 1.7845e-03 -XStrontianite: 9.9822e-01 -XCa: 7.1201e-02 -XSr: 9.2880e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 58 -SrCO3 added: 5.8000e+00 -Log Sigma pi: -9.2398e+00 -XAragonite: 1.7548e-03 -XStrontianite: 9.9825e-01 -XCa: 7.0087e-02 -XSr: 9.2991e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 59 -SrCO3 added: 5.9000e+00 -Log Sigma pi: -9.2403e+00 -XAragonite: 1.7260e-03 -XStrontianite: 9.9827e-01 -XCa: 6.9008e-02 -XSr: 9.3099e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 60 -SrCO3 added: 6 -Log Sigma pi: -9.2408e+00 -XAragonite: 1.6982e-03 -XStrontianite: 9.9830e-01 -XCa: 6.7962e-02 -XSr: 9.3204e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 61 -SrCO3 added: 6.1000e+00 -Log Sigma pi: -9.2413e+00 -XAragonite: 1.6712e-03 -XStrontianite: 9.9833e-01 -XCa: 6.6947e-02 -XSr: 9.3305e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 62 -SrCO3 added: 6.2000e+00 -Log Sigma pi: -9.2417e+00 -XAragonite: 1.6451e-03 -XStrontianite: 9.9835e-01 -XCa: 6.5961e-02 -XSr: 9.3404e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 63 -SrCO3 added: 6.3000e+00 -Log Sigma pi: -9.2422e+00 -XAragonite: 1.6198e-03 -XStrontianite: 9.9838e-01 -XCa: 6.5005e-02 -XSr: 9.3500e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 64 -SrCO3 added: 6.4000e+00 -Log Sigma pi: -9.2426e+00 -XAragonite: 1.5952e-03 -XStrontianite: 9.9840e-01 -XCa: 6.4076e-02 -XSr: 9.3592e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 65 -SrCO3 added: 6.5000e+00 -Log Sigma pi: -9.2430e+00 -XAragonite: 1.5714e-03 -XStrontianite: 9.9843e-01 -XCa: 6.3173e-02 -XSr: 9.3683e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 66 -SrCO3 added: 6.6000e+00 -Log Sigma pi: -9.2434e+00 -XAragonite: 1.5483e-03 -XStrontianite: 9.9845e-01 -XCa: 6.2295e-02 -XSr: 9.3771e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 67 -SrCO3 added: 6.7000e+00 -Log Sigma pi: -9.2438e+00 -XAragonite: 1.5258e-03 -XStrontianite: 9.9847e-01 -XCa: 6.1441e-02 -XSr: 9.3856e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 68 -SrCO3 added: 6.8000e+00 -Log Sigma pi: -9.2442e+00 -XAragonite: 1.5040e-03 -XStrontianite: 9.9850e-01 -XCa: 6.0610e-02 -XSr: 9.3939e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 69 -SrCO3 added: 6.9000e+00 -Log Sigma pi: -9.2446e+00 -XAragonite: 1.4829e-03 -XStrontianite: 9.9852e-01 -XCa: 5.9802e-02 -XSr: 9.4020e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 70 -SrCO3 added: 7 -Log Sigma pi: -9.2449e+00 -XAragonite: 1.4623e-03 -XStrontianite: 9.9854e-01 -XCa: 5.9015e-02 -XSr: 9.4099e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 71 -SrCO3 added: 7.1000e+00 -Log Sigma pi: -9.2453e+00 -XAragonite: 1.4422e-03 -XStrontianite: 9.9856e-01 -XCa: 5.8248e-02 -XSr: 9.4175e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 72 -SrCO3 added: 7.2000e+00 -Log Sigma pi: -9.2456e+00 -XAragonite: 1.4227e-03 -XStrontianite: 9.9858e-01 -XCa: 5.7501e-02 -XSr: 9.4250e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 73 -SrCO3 added: 7.3000e+00 -Log Sigma pi: -9.2459e+00 -XAragonite: 1.4038e-03 -XStrontianite: 9.9860e-01 -XCa: 5.6773e-02 -XSr: 9.4323e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 74 -SrCO3 added: 7.4000e+00 -Log Sigma pi: -9.2463e+00 -XAragonite: 1.3853e-03 -XStrontianite: 9.9861e-01 -XCa: 5.6063e-02 -XSr: 9.4394e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 75 -SrCO3 added: 7.5000e+00 -Log Sigma pi: -9.2466e+00 -XAragonite: 1.3673e-03 -XStrontianite: 9.9863e-01 -XCa: 5.5370e-02 -XSr: 9.4463e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 76 -SrCO3 added: 7.6000e+00 -Log Sigma pi: -9.2469e+00 -XAragonite: 1.3498e-03 -XStrontianite: 9.9865e-01 -XCa: 5.4695e-02 -XSr: 9.4530e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 77 -SrCO3 added: 7.7000e+00 -Log Sigma pi: -9.2472e+00 -XAragonite: 1.3327e-03 -XStrontianite: 9.9867e-01 -XCa: 5.4036e-02 -XSr: 9.4596e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 78 -SrCO3 added: 7.8000e+00 -Log Sigma pi: -9.2475e+00 -XAragonite: 1.3160e-03 -XStrontianite: 9.9868e-01 -XCa: 5.3392e-02 -XSr: 9.4661e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 79 -SrCO3 added: 7.9000e+00 -Log Sigma pi: -9.2478e+00 -XAragonite: 1.2998e-03 -XStrontianite: 9.9870e-01 -XCa: 5.2764e-02 -XSr: 9.4724e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 80 -SrCO3 added: 8 -Log Sigma pi: -9.2480e+00 -XAragonite: 1.2840e-03 -XStrontianite: 9.9872e-01 -XCa: 5.2150e-02 -XSr: 9.4785e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 81 -SrCO3 added: 8.1000e+00 -Log Sigma pi: -9.2483e+00 -XAragonite: 1.2685e-03 -XStrontianite: 9.9873e-01 -XCa: 5.1551e-02 -XSr: 9.4845e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 82 -SrCO3 added: 8.2000e+00 -Log Sigma pi: -9.2486e+00 -XAragonite: 1.2534e-03 -XStrontianite: 9.9875e-01 -XCa: 5.0965e-02 -XSr: 9.4903e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 83 -SrCO3 added: 8.3000e+00 -Log Sigma pi: -9.2488e+00 -XAragonite: 1.2386e-03 -XStrontianite: 9.9876e-01 -XCa: 5.0392e-02 -XSr: 9.4961e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 84 -SrCO3 added: 8.4000e+00 -Log Sigma pi: -9.2491e+00 -XAragonite: 1.2242e-03 -XStrontianite: 9.9878e-01 -XCa: 4.9832e-02 -XSr: 9.5017e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 85 -SrCO3 added: 8.5000e+00 -Log Sigma pi: -9.2493e+00 -XAragonite: 1.2102e-03 -XStrontianite: 9.9879e-01 -XCa: 4.9285e-02 -XSr: 9.5072e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 86 -SrCO3 added: 8.6000e+00 -Log Sigma pi: -9.2496e+00 -XAragonite: 1.1964e-03 -XStrontianite: 9.9880e-01 -XCa: 4.8749e-02 -XSr: 9.5125e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 87 -SrCO3 added: 8.7000e+00 -Log Sigma pi: -9.2498e+00 -XAragonite: 1.1830e-03 -XStrontianite: 9.9882e-01 -XCa: 4.8225e-02 -XSr: 9.5178e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 88 -SrCO3 added: 8.8000e+00 -Log Sigma pi: -9.2500e+00 -XAragonite: 1.1698e-03 -XStrontianite: 9.9883e-01 -XCa: 4.7712e-02 -XSr: 9.5229e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 89 -SrCO3 added: 8.9000e+00 -Log Sigma pi: -9.2503e+00 -XAragonite: 1.1570e-03 -XStrontianite: 9.9884e-01 -XCa: 4.7209e-02 -XSr: 9.5279e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 90 -SrCO3 added: 9 -Log Sigma pi: -9.2505e+00 -XAragonite: 1.1444e-03 -XStrontianite: 9.9886e-01 -XCa: 4.6718e-02 -XSr: 9.5328e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 91 -SrCO3 added: 9.1000e+00 -Log Sigma pi: -9.2507e+00 -XAragonite: 1.1321e-03 -XStrontianite: 9.9887e-01 -XCa: 4.6236e-02 -XSr: 9.5376e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 92 -SrCO3 added: 9.2000e+00 -Log Sigma pi: -9.2509e+00 -XAragonite: 1.1201e-03 -XStrontianite: 9.9888e-01 -XCa: 4.5764e-02 -XSr: 9.5424e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 93 -SrCO3 added: 9.3000e+00 -Log Sigma pi: -9.2511e+00 -XAragonite: 1.1083e-03 -XStrontianite: 9.9889e-01 -XCa: 4.5302e-02 -XSr: 9.5470e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 94 -SrCO3 added: 9.4000e+00 -Log Sigma pi: -9.2513e+00 -XAragonite: 1.0967e-03 -XStrontianite: 9.9890e-01 -XCa: 4.4849e-02 -XSr: 9.5515e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 95 -SrCO3 added: 9.5000e+00 -Log Sigma pi: -9.2515e+00 -XAragonite: 1.0854e-03 -XStrontianite: 9.9891e-01 -XCa: 4.4405e-02 -XSr: 9.5560e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 96 -SrCO3 added: 9.6000e+00 -Log Sigma pi: -9.2517e+00 -XAragonite: 1.0744e-03 -XStrontianite: 9.9893e-01 -XCa: 4.3969e-02 -XSr: 9.5603e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 97 -SrCO3 added: 9.7000e+00 -Log Sigma pi: -9.2519e+00 -XAragonite: 1.0635e-03 -XStrontianite: 9.9894e-01 -XCa: 4.3543e-02 -XSr: 9.5646e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 98 -SrCO3 added: 9.8000e+00 -Log Sigma pi: -9.2521e+00 -XAragonite: 1.0529e-03 -XStrontianite: 9.9895e-01 -XCa: 4.3124e-02 -XSr: 9.5688e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 99 -SrCO3 added: 9.9000e+00 -Log Sigma pi: -9.2523e+00 -XAragonite: 1.0425e-03 -XStrontianite: 9.9896e-01 -XCa: 4.2713e-02 -XSr: 9.5729e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -----------------------------------User print----------------------------------- - -Simulation number: 6 -Reaction step number: 100 -SrCO3 added: 10 -Log Sigma pi: -9.2525e+00 -XAragonite: 1.0323e-03 -XStrontianite: 9.9897e-01 -XCa: 4.2310e-02 -XSr: 9.5769e-01 -Misc 1: 4.8032e-03 -Misc 2: 8.5786e-01 - -No memory leaks diff --git a/Sun/examples/ex10.sel b/Sun/examples/ex10.sel deleted file mode 100644 index a04f5970..00000000 --- a/Sun/examples/ex10.sel +++ /dev/null @@ -1,701 +0,0 @@ - reaction lg_SigmaPi X_Arag X_Stront X_Ca_aq X_Sr_aq mol_Misc1 mol_Misc2 mol_Arag mol_Stront - 1.0000e-05 -8.3356e+00 9.9996e-01 4.2096e-05 9.9905e-01 9.4867e-04 1.0000e-10 1.0000e-10 6.5428e-06 2.7544e-10 - 2.0000e-05 -8.3352e+00 9.9992e-01 8.4301e-05 9.9810e-01 1.8967e-03 1.0000e-10 1.0000e-10 1.3083e-05 1.1030e-09 - 3.0000e-05 -8.3348e+00 9.9987e-01 1.2662e-04 9.9716e-01 2.8440e-03 1.0000e-10 1.0000e-10 1.9622e-05 2.4848e-09 - 4.0000e-05 -8.3345e+00 9.9983e-01 1.6904e-04 9.9621e-01 3.7906e-03 1.0000e-10 1.0000e-10 2.6159e-05 4.4226e-09 - 5.0000e-05 -8.3341e+00 9.9979e-01 2.1158e-04 9.9526e-01 4.7366e-03 1.0000e-10 1.0000e-10 3.2693e-05 6.9185e-09 - 6.0000e-05 -8.3337e+00 9.9975e-01 2.5422e-04 9.9432e-01 5.6819e-03 1.0000e-10 1.0000e-10 3.9225e-05 9.9745e-09 - 7.0000e-05 -8.3333e+00 9.9970e-01 2.9698e-04 9.9337e-01 6.6265e-03 1.0000e-10 1.0000e-10 4.5755e-05 1.3593e-08 - 8.0000e-05 -8.3329e+00 9.9966e-01 3.3985e-04 9.9243e-01 7.5705e-03 1.0000e-10 1.0000e-10 5.2283e-05 1.7775e-08 - 9.0000e-05 -8.3325e+00 9.9962e-01 3.8284e-04 9.9149e-01 8.5137e-03 1.0000e-10 1.0000e-10 5.8809e-05 2.2523e-08 - 1.0000e-04 -8.3321e+00 9.9957e-01 4.2593e-04 9.9054e-01 9.4563e-03 1.0000e-10 1.0000e-10 6.5333e-05 2.7839e-08 - 1.1000e-04 -8.3318e+00 9.9953e-01 4.6914e-04 9.8960e-01 1.0398e-02 1.0000e-10 1.0000e-10 7.1855e-05 3.3726e-08 - 1.2000e-04 -8.3314e+00 9.9949e-01 5.1247e-04 9.8866e-01 1.1340e-02 1.0000e-10 1.0000e-10 7.8374e-05 4.0185e-08 - 1.3000e-04 -8.3310e+00 9.9944e-01 5.5591e-04 9.8772e-01 1.2280e-02 1.0000e-10 1.0000e-10 8.4891e-05 4.7218e-08 - 1.4000e-04 -8.3306e+00 9.9940e-01 5.9946e-04 9.8678e-01 1.3220e-02 1.0000e-10 1.0000e-10 9.1407e-05 5.4828e-08 - 1.5000e-04 -8.3302e+00 9.9936e-01 6.4313e-04 9.8584e-01 1.4159e-02 1.0000e-10 1.0000e-10 9.7920e-05 6.3016e-08 - 1.6000e-04 -8.3298e+00 9.9931e-01 6.8692e-04 9.8490e-01 1.5098e-02 1.0000e-10 1.0000e-10 1.0443e-04 7.1784e-08 - 1.7000e-04 -8.3294e+00 9.9927e-01 7.3082e-04 9.8396e-01 1.6036e-02 1.0000e-10 1.0000e-10 1.1094e-04 8.1136e-08 - 1.8000e-04 -8.3290e+00 9.9923e-01 7.7484e-04 9.8303e-01 1.6973e-02 1.0000e-10 1.0000e-10 1.1745e-04 9.1072e-08 - 1.9000e-04 -8.3287e+00 9.9918e-01 8.1897e-04 9.8209e-01 1.7909e-02 1.0000e-10 1.0000e-10 1.2395e-04 1.0160e-07 - 2.0000e-04 -8.3283e+00 9.9914e-01 8.6323e-04 9.8115e-01 1.8845e-02 1.0000e-10 1.0000e-10 1.3045e-04 1.1271e-07 - 2.1000e-04 -8.3279e+00 9.9909e-01 9.0760e-04 9.8022e-01 1.9780e-02 1.0000e-10 1.0000e-10 1.3695e-04 1.2441e-07 - 2.2000e-04 -8.3275e+00 9.9905e-01 9.5209e-04 9.7929e-01 2.0715e-02 1.0000e-10 1.0000e-10 1.4345e-04 1.3671e-07 - 2.3000e-04 -8.3271e+00 9.9900e-01 9.9670e-04 9.7835e-01 2.1649e-02 1.0000e-10 1.0000e-10 1.4995e-04 1.4960e-07 - 2.4000e-04 -8.3267e+00 9.9896e-01 1.0414e-03 9.7742e-01 2.2582e-02 1.0000e-10 1.0000e-10 1.5644e-04 1.6309e-07 - 2.5000e-04 -8.3263e+00 9.9891e-01 1.0863e-03 9.7649e-01 2.3514e-02 1.0000e-10 1.0000e-10 1.6293e-04 1.7719e-07 - 2.6000e-04 -8.3259e+00 9.9887e-01 1.1313e-03 9.7555e-01 2.4446e-02 1.0000e-10 1.0000e-10 1.6942e-04 1.9188e-07 - 2.7000e-04 -8.3256e+00 9.9882e-01 1.1764e-03 9.7462e-01 2.5377e-02 1.0000e-10 1.0000e-10 1.7591e-04 2.0718e-07 - 2.8000e-04 -8.3252e+00 9.9878e-01 1.2216e-03 9.7369e-01 2.6308e-02 1.0000e-10 1.0000e-10 1.8240e-04 2.2308e-07 - 2.9000e-04 -8.3248e+00 9.9873e-01 1.2669e-03 9.7276e-01 2.7238e-02 1.0000e-10 1.0000e-10 1.8888e-04 2.3960e-07 - 3.0000e-04 -8.3244e+00 9.9869e-01 1.3124e-03 9.7183e-01 2.8167e-02 1.0000e-10 1.0000e-10 1.9536e-04 2.5672e-07 - 3.1000e-04 -8.3240e+00 9.9864e-01 1.3580e-03 9.7090e-01 2.9095e-02 1.0000e-10 1.0000e-10 2.0184e-04 2.7446e-07 - 3.2000e-04 -8.3236e+00 9.9860e-01 1.4037e-03 9.6998e-01 3.0023e-02 1.0000e-10 1.0000e-10 2.0832e-04 2.9282e-07 - 3.3000e-04 -8.3232e+00 9.9855e-01 1.4495e-03 9.6905e-01 3.0950e-02 1.0000e-10 1.0000e-10 2.1479e-04 3.1179e-07 - 3.4000e-04 -8.3228e+00 9.9850e-01 1.4955e-03 9.6812e-01 3.1877e-02 1.0000e-10 1.0000e-10 2.2126e-04 3.3139e-07 - 3.5000e-04 -8.3225e+00 9.9846e-01 1.5416e-03 9.6720e-01 3.2802e-02 1.0000e-10 1.0000e-10 2.2773e-04 3.5161e-07 - 3.6000e-04 -8.3221e+00 9.9841e-01 1.5878e-03 9.6627e-01 3.3727e-02 1.0000e-10 1.0000e-10 2.3420e-04 3.7245e-07 - 3.7000e-04 -8.3217e+00 9.9837e-01 1.6341e-03 9.6535e-01 3.4652e-02 1.0000e-10 1.0000e-10 2.4067e-04 3.9392e-07 - 3.8000e-04 -8.3213e+00 9.9832e-01 1.6806e-03 9.6442e-01 3.5576e-02 1.0000e-10 1.0000e-10 2.4713e-04 4.1602e-07 - 3.9000e-04 -8.3209e+00 9.9827e-01 1.7272e-03 9.6350e-01 3.6499e-02 1.0000e-10 1.0000e-10 2.5359e-04 4.3876e-07 - 4.0000e-04 -8.3205e+00 9.9823e-01 1.7739e-03 9.6258e-01 3.7421e-02 1.0000e-10 1.0000e-10 2.6005e-04 4.6213e-07 - 4.1000e-04 -8.3201e+00 9.9818e-01 1.8208e-03 9.6166e-01 3.8343e-02 1.0000e-10 1.0000e-10 2.6651e-04 4.8614e-07 - 4.2000e-04 -8.3197e+00 9.9813e-01 1.8677e-03 9.6074e-01 3.9264e-02 1.0000e-10 1.0000e-10 2.7297e-04 5.1078e-07 - 4.3000e-04 -8.3193e+00 9.9809e-01 1.9149e-03 9.5982e-01 4.0184e-02 1.0000e-10 1.0000e-10 2.7942e-04 5.3607e-07 - 4.4000e-04 -8.3190e+00 9.9804e-01 1.9621e-03 9.5890e-01 4.1104e-02 1.0000e-10 1.0000e-10 2.8587e-04 5.6201e-07 - 4.5000e-04 -8.3186e+00 9.9799e-01 2.0095e-03 9.5798e-01 4.2023e-02 1.0000e-10 1.0000e-10 2.9232e-04 5.8859e-07 - 4.6000e-04 -8.3182e+00 9.9794e-01 2.0570e-03 9.5706e-01 4.2941e-02 1.0000e-10 1.0000e-10 2.9877e-04 6.1583e-07 - 4.7000e-04 -8.3178e+00 9.9790e-01 2.1046e-03 9.5614e-01 4.3859e-02 1.0000e-10 1.0000e-10 3.0521e-04 6.4371e-07 - 4.8000e-04 -8.3174e+00 9.9785e-01 2.1524e-03 9.5522e-01 4.4776e-02 1.0000e-10 1.0000e-10 3.1165e-04 6.7225e-07 - 4.9000e-04 -8.3170e+00 9.9780e-01 2.2003e-03 9.5431e-01 4.5692e-02 1.0000e-10 1.0000e-10 3.1809e-04 7.0145e-07 - 5.0000e-04 -8.3166e+00 9.9775e-01 2.2484e-03 9.5339e-01 4.6608e-02 1.0000e-10 1.0000e-10 3.2453e-04 7.3131e-07 - 5.1000e-04 -8.3162e+00 9.9770e-01 2.2966e-03 9.5248e-01 4.7523e-02 1.0000e-10 1.0000e-10 3.3097e-04 7.6183e-07 - 5.2000e-04 -8.3159e+00 9.9766e-01 2.3449e-03 9.5156e-01 4.8437e-02 1.0000e-10 1.0000e-10 3.3740e-04 7.9302e-07 - 5.3000e-04 -8.3155e+00 9.9761e-01 2.3933e-03 9.5065e-01 4.9351e-02 1.0000e-10 1.0000e-10 3.4383e-04 8.2488e-07 - 5.4000e-04 -8.3151e+00 9.9756e-01 2.4419e-03 9.4974e-01 5.0264e-02 1.0000e-10 1.0000e-10 3.5026e-04 8.5740e-07 - 5.5000e-04 -8.3147e+00 9.9751e-01 2.4907e-03 9.4882e-01 5.1176e-02 1.0000e-10 1.0000e-10 3.5669e-04 8.9060e-07 - 5.6000e-04 -8.3143e+00 9.9746e-01 2.5395e-03 9.4791e-01 5.2088e-02 1.0000e-10 1.0000e-10 3.6311e-04 9.2448e-07 - 5.7000e-04 -8.3139e+00 9.9741e-01 2.5885e-03 9.4700e-01 5.2999e-02 1.0000e-10 1.0000e-10 3.6954e-04 9.5904e-07 - 5.8000e-04 -8.3135e+00 9.9736e-01 2.6377e-03 9.4609e-01 5.3909e-02 1.0000e-10 1.0000e-10 3.7596e-04 9.9428e-07 - 5.9000e-04 -8.3131e+00 9.9731e-01 2.6870e-03 9.4518e-01 5.4819e-02 1.0000e-10 1.0000e-10 3.8237e-04 1.0302e-06 - 6.0000e-04 -8.3127e+00 9.9726e-01 2.7364e-03 9.4427e-01 5.5728e-02 1.0000e-10 1.0000e-10 3.8879e-04 1.0668e-06 - 6.1000e-04 -8.3123e+00 9.9721e-01 2.7860e-03 9.4336e-01 5.6636e-02 1.0000e-10 1.0000e-10 3.9520e-04 1.1041e-06 - 6.2000e-04 -8.3120e+00 9.9716e-01 2.8357e-03 9.4246e-01 5.7544e-02 1.0000e-10 1.0000e-10 4.0162e-04 1.1421e-06 - 6.3000e-04 -8.3116e+00 9.9711e-01 2.8856e-03 9.4155e-01 5.8451e-02 1.0000e-10 1.0000e-10 4.0803e-04 1.1808e-06 - 6.4000e-04 -8.3112e+00 9.9706e-01 2.9356e-03 9.4064e-01 5.9357e-02 1.0000e-10 1.0000e-10 4.1443e-04 1.2202e-06 - 6.5000e-04 -8.3108e+00 9.9701e-01 2.9857e-03 9.3974e-01 6.0263e-02 1.0000e-10 1.0000e-10 4.2084e-04 1.2603e-06 - 6.6000e-04 -8.3104e+00 9.9696e-01 3.0360e-03 9.3883e-01 6.1167e-02 1.0000e-10 1.0000e-10 4.2724e-04 1.3011e-06 - 6.7000e-04 -8.3100e+00 9.9691e-01 3.0864e-03 9.3793e-01 6.2072e-02 1.0000e-10 1.0000e-10 4.3364e-04 1.3426e-06 - 6.8000e-04 -8.3096e+00 9.9686e-01 3.1370e-03 9.3702e-01 6.2975e-02 1.0000e-10 1.0000e-10 4.4004e-04 1.3848e-06 - 6.9000e-04 -8.3092e+00 9.9681e-01 3.1878e-03 9.3612e-01 6.3878e-02 1.0000e-10 1.0000e-10 4.4644e-04 1.4277e-06 - 7.0000e-04 -8.3088e+00 9.9676e-01 3.2386e-03 9.3522e-01 6.4780e-02 1.0000e-10 1.0000e-10 4.5283e-04 1.4713e-06 - 7.1000e-04 -8.3084e+00 9.9671e-01 3.2897e-03 9.3432e-01 6.5682e-02 1.0000e-10 1.0000e-10 4.5922e-04 1.5157e-06 - 7.2000e-04 -8.3081e+00 9.9666e-01 3.3409e-03 9.3342e-01 6.6583e-02 1.0000e-10 1.0000e-10 4.6561e-04 1.5608e-06 - 7.3000e-04 -8.3077e+00 9.9661e-01 3.3922e-03 9.3252e-01 6.7483e-02 1.0000e-10 1.0000e-10 4.7200e-04 1.6066e-06 - 7.4000e-04 -8.3073e+00 9.9656e-01 3.4437e-03 9.3162e-01 6.8383e-02 1.0000e-10 1.0000e-10 4.7839e-04 1.6531e-06 - 7.5000e-04 -8.3069e+00 9.9650e-01 3.4953e-03 9.3072e-01 6.9282e-02 1.0000e-10 1.0000e-10 4.8477e-04 1.7004e-06 - 7.6000e-04 -8.3065e+00 9.9645e-01 3.5471e-03 9.2982e-01 7.0180e-02 1.0000e-10 1.0000e-10 4.9115e-04 1.7484e-06 - 7.7000e-04 -8.3061e+00 9.9640e-01 3.5990e-03 9.2892e-01 7.1077e-02 1.0000e-10 1.0000e-10 4.9753e-04 1.7971e-06 - 7.8000e-04 -8.3057e+00 9.9635e-01 3.6511e-03 9.2803e-01 7.1974e-02 1.0000e-10 1.0000e-10 5.0391e-04 1.8466e-06 - 7.9000e-04 -8.3053e+00 9.9630e-01 3.7034e-03 9.2713e-01 7.2870e-02 1.0000e-10 1.0000e-10 5.1028e-04 1.8968e-06 - 8.0000e-04 -8.3049e+00 9.9624e-01 3.7558e-03 9.2623e-01 7.3766e-02 1.0000e-10 1.0000e-10 5.1665e-04 1.9477e-06 - 8.1000e-04 -8.3045e+00 9.9619e-01 3.8083e-03 9.2534e-01 7.4661e-02 1.0000e-10 1.0000e-10 5.2302e-04 1.9995e-06 - 8.2000e-04 -8.3042e+00 9.9614e-01 3.8611e-03 9.2445e-01 7.5555e-02 1.0000e-10 1.0000e-10 5.2939e-04 2.0519e-06 - 8.3000e-04 -8.3038e+00 9.9609e-01 3.9139e-03 9.2355e-01 7.6448e-02 1.0000e-10 1.0000e-10 5.3576e-04 2.1052e-06 - 8.4000e-04 -8.3034e+00 9.9603e-01 3.9670e-03 9.2266e-01 7.7341e-02 1.0000e-10 1.0000e-10 5.4212e-04 2.1591e-06 - 8.5000e-04 -8.3030e+00 9.9598e-01 4.0202e-03 9.2177e-01 7.8233e-02 1.0000e-10 1.0000e-10 5.4848e-04 2.2139e-06 - 8.6000e-04 -8.3026e+00 9.9593e-01 4.0735e-03 9.2088e-01 7.9125e-02 1.0000e-10 1.0000e-10 5.5484e-04 2.2694e-06 - 8.7000e-04 -8.3022e+00 9.9587e-01 4.1270e-03 9.1998e-01 8.0016e-02 1.0000e-10 1.0000e-10 5.6120e-04 2.3257e-06 - 8.8000e-04 -8.3018e+00 9.9582e-01 4.1807e-03 9.1909e-01 8.0906e-02 1.0000e-10 1.0000e-10 5.6755e-04 2.3827e-06 - 8.9000e-04 -8.3014e+00 9.9577e-01 4.2346e-03 9.1820e-01 8.1795e-02 1.0000e-10 1.0000e-10 5.7390e-04 2.4406e-06 - 9.0000e-04 -8.3010e+00 9.9571e-01 4.2886e-03 9.1732e-01 8.2684e-02 1.0000e-10 1.0000e-10 5.8025e-04 2.4992e-06 - 9.1000e-04 -8.3006e+00 9.9566e-01 4.3427e-03 9.1643e-01 8.3572e-02 1.0000e-10 1.0000e-10 5.8660e-04 2.5586e-06 - 9.2000e-04 -8.3002e+00 9.9560e-01 4.3971e-03 9.1554e-01 8.4460e-02 1.0000e-10 1.0000e-10 5.9295e-04 2.6187e-06 - 9.3000e-04 -8.2999e+00 9.9555e-01 4.4516e-03 9.1465e-01 8.5347e-02 1.0000e-10 1.0000e-10 5.9929e-04 2.6797e-06 - 9.4000e-04 -8.2995e+00 9.9549e-01 4.5062e-03 9.1377e-01 8.6233e-02 1.0000e-10 1.0000e-10 6.0563e-04 2.7415e-06 - 9.5000e-04 -8.2991e+00 9.9544e-01 4.5611e-03 9.1288e-01 8.7118e-02 1.0000e-10 1.0000e-10 6.1197e-04 2.8040e-06 - 9.6000e-04 -8.2987e+00 9.9538e-01 4.6161e-03 9.1200e-01 8.8003e-02 1.0000e-10 1.0000e-10 6.1831e-04 2.8674e-06 - 9.7000e-04 -8.2983e+00 9.9533e-01 4.6713e-03 9.1111e-01 8.8887e-02 1.0000e-10 1.0000e-10 6.2464e-04 2.9316e-06 - 9.8000e-04 -8.2979e+00 9.9527e-01 4.7266e-03 9.1023e-01 8.9770e-02 1.0000e-10 1.0000e-10 6.3097e-04 2.9965e-06 - 9.9000e-04 -8.2975e+00 9.9522e-01 4.7821e-03 9.0935e-01 9.0653e-02 1.0000e-10 1.0000e-10 6.3730e-04 3.0623e-06 - 1.0000e-03 -8.2974e+00 9.8567e-01 1.4329e-02 9.0901e-01 9.0987e-02 6.4175e-04 7.2473e-06 6.3970e-04 9.2997e-06 - 1.0100e-03 -8.2974e+00 9.7071e-01 2.9286e-02 9.0901e-01 9.0987e-02 6.4009e-04 1.8914e-05 6.3970e-04 1.9300e-05 - 1.0200e-03 -8.2974e+00 9.5620e-01 4.3796e-02 9.0901e-01 9.0987e-02 6.3842e-04 3.0580e-05 6.3970e-04 2.9300e-05 - 1.0300e-03 -8.2974e+00 9.4212e-01 5.7879e-02 9.0901e-01 9.0987e-02 6.3675e-04 4.2246e-05 6.3970e-04 3.9300e-05 - 1.0400e-03 -8.2974e+00 9.2845e-01 7.1552e-02 9.0901e-01 9.0987e-02 6.3509e-04 5.3912e-05 6.3970e-04 4.9300e-05 - 1.0500e-03 -8.2974e+00 9.1516e-01 8.4835e-02 9.0901e-01 9.0987e-02 6.3342e-04 6.5578e-05 6.3970e-04 5.9300e-05 - 1.0600e-03 -8.2974e+00 9.0226e-01 9.7743e-02 9.0901e-01 9.0987e-02 6.3176e-04 7.7245e-05 6.3970e-04 6.9300e-05 - 1.0700e-03 -8.2974e+00 8.8971e-01 1.1029e-01 9.0901e-01 9.0987e-02 6.3009e-04 8.8911e-05 6.3970e-04 7.9300e-05 - 1.0800e-03 -8.2974e+00 8.7750e-01 1.2250e-01 9.0901e-01 9.0987e-02 6.2842e-04 1.0058e-04 6.3970e-04 8.9300e-05 - 1.0900e-03 -8.2974e+00 8.6563e-01 1.3437e-01 9.0901e-01 9.0987e-02 6.2676e-04 1.1224e-04 6.3970e-04 9.9300e-05 - 1.1000e-03 -8.2974e+00 8.5407e-01 1.4593e-01 9.0901e-01 9.0987e-02 6.2509e-04 1.2391e-04 6.3970e-04 1.0930e-04 - 1.1100e-03 -8.2974e+00 8.4282e-01 1.5718e-01 9.0901e-01 9.0987e-02 6.2342e-04 1.3558e-04 6.3970e-04 1.1930e-04 - 1.1200e-03 -8.2974e+00 8.3186e-01 1.6814e-01 9.0901e-01 9.0987e-02 6.2176e-04 1.4724e-04 6.3970e-04 1.2930e-04 - 1.1300e-03 -8.2974e+00 8.2118e-01 1.7882e-01 9.0901e-01 9.0987e-02 6.2009e-04 1.5891e-04 6.3970e-04 1.3930e-04 - 1.1400e-03 -8.2974e+00 8.1077e-01 1.8923e-01 9.0901e-01 9.0987e-02 6.1843e-04 1.7057e-04 6.3970e-04 1.4930e-04 - 1.1500e-03 -8.2974e+00 8.0063e-01 1.9937e-01 9.0901e-01 9.0987e-02 6.1676e-04 1.8224e-04 6.3970e-04 1.5930e-04 - 1.1600e-03 -8.2974e+00 7.9073e-01 2.0927e-01 9.0901e-01 9.0987e-02 6.1509e-04 1.9391e-04 6.3970e-04 1.6930e-04 - 1.1700e-03 -8.2974e+00 7.8107e-01 2.1893e-01 9.0901e-01 9.0987e-02 6.1343e-04 2.0557e-04 6.3970e-04 1.7930e-04 - 1.1800e-03 -8.2974e+00 7.7165e-01 2.2835e-01 9.0901e-01 9.0987e-02 6.1176e-04 2.1724e-04 6.3970e-04 1.8930e-04 - 1.1900e-03 -8.2974e+00 7.6246e-01 2.3754e-01 9.0901e-01 9.0987e-02 6.1009e-04 2.2891e-04 6.3970e-04 1.9930e-04 - 1.2000e-03 -8.2974e+00 7.5348e-01 2.4652e-01 9.0901e-01 9.0987e-02 6.0843e-04 2.4057e-04 6.3970e-04 2.0930e-04 - 1.2100e-03 -8.2974e+00 7.4470e-01 2.5530e-01 9.0901e-01 9.0987e-02 6.0676e-04 2.5224e-04 6.3970e-04 2.1930e-04 - 1.2200e-03 -8.2974e+00 7.3613e-01 2.6387e-01 9.0901e-01 9.0987e-02 6.0510e-04 2.6390e-04 6.3970e-04 2.2930e-04 - 1.2300e-03 -8.2974e+00 7.2776e-01 2.7224e-01 9.0901e-01 9.0987e-02 6.0343e-04 2.7557e-04 6.3970e-04 2.3930e-04 - 1.2400e-03 -8.2974e+00 7.1957e-01 2.8043e-01 9.0901e-01 9.0987e-02 6.0176e-04 2.8724e-04 6.3970e-04 2.4930e-04 - 1.2500e-03 -8.2974e+00 7.1157e-01 2.8843e-01 9.0901e-01 9.0987e-02 6.0010e-04 2.9890e-04 6.3970e-04 2.5930e-04 - 1.2600e-03 -8.2974e+00 7.0374e-01 2.9626e-01 9.0901e-01 9.0987e-02 5.9843e-04 3.1057e-04 6.3970e-04 2.6930e-04 - 1.2700e-03 -8.2974e+00 6.9608e-01 3.0392e-01 9.0901e-01 9.0987e-02 5.9677e-04 3.2223e-04 6.3970e-04 2.7930e-04 - 1.2800e-03 -8.2974e+00 6.8859e-01 3.1141e-01 9.0901e-01 9.0987e-02 5.9510e-04 3.3390e-04 6.3970e-04 2.8930e-04 - 1.2900e-03 -8.2974e+00 6.8126e-01 3.1874e-01 9.0901e-01 9.0987e-02 5.9343e-04 3.4557e-04 6.3970e-04 2.9930e-04 - 1.3000e-03 -8.2974e+00 6.7408e-01 3.2592e-01 9.0901e-01 9.0987e-02 5.9177e-04 3.5723e-04 6.3970e-04 3.0930e-04 - 1.3100e-03 -8.2974e+00 6.6705e-01 3.3295e-01 9.0901e-01 9.0987e-02 5.9010e-04 3.6890e-04 6.3970e-04 3.1930e-04 - 1.3200e-03 -8.2974e+00 6.6017e-01 3.3983e-01 9.0901e-01 9.0987e-02 5.8843e-04 3.8057e-04 6.3970e-04 3.2930e-04 - 1.3300e-03 -8.2974e+00 6.5342e-01 3.4658e-01 9.0901e-01 9.0987e-02 5.8677e-04 3.9223e-04 6.3970e-04 3.3930e-04 - 1.3400e-03 -8.2974e+00 6.4682e-01 3.5318e-01 9.0901e-01 9.0987e-02 5.8510e-04 4.0390e-04 6.3970e-04 3.4930e-04 - 1.3500e-03 -8.2974e+00 6.4034e-01 3.5966e-01 9.0901e-01 9.0987e-02 5.8344e-04 4.1556e-04 6.3970e-04 3.5930e-04 - 1.3600e-03 -8.2974e+00 6.3399e-01 3.6601e-01 9.0901e-01 9.0987e-02 5.8177e-04 4.2723e-04 6.3970e-04 3.6930e-04 - 1.3700e-03 -8.2974e+00 6.2777e-01 3.7223e-01 9.0901e-01 9.0987e-02 5.8010e-04 4.3890e-04 6.3970e-04 3.7930e-04 - 1.3800e-03 -8.2974e+00 6.2167e-01 3.7833e-01 9.0901e-01 9.0987e-02 5.7844e-04 4.5056e-04 6.3970e-04 3.8930e-04 - 1.3900e-03 -8.2974e+00 6.1569e-01 3.8431e-01 9.0901e-01 9.0987e-02 5.7677e-04 4.6223e-04 6.3970e-04 3.9930e-04 - 1.4000e-03 -8.2974e+00 6.0982e-01 3.9018e-01 9.0901e-01 9.0987e-02 5.7510e-04 4.7390e-04 6.3970e-04 4.0930e-04 - 1.4100e-03 -8.2974e+00 6.0406e-01 3.9594e-01 9.0901e-01 9.0987e-02 5.7344e-04 4.8556e-04 6.3970e-04 4.1930e-04 - 1.4200e-03 -8.2974e+00 5.9841e-01 4.0159e-01 9.0901e-01 9.0987e-02 5.7177e-04 4.9723e-04 6.3970e-04 4.2930e-04 - 1.4300e-03 -8.2974e+00 5.9286e-01 4.0714e-01 9.0901e-01 9.0987e-02 5.7011e-04 5.0889e-04 6.3970e-04 4.3930e-04 - 1.4400e-03 -8.2974e+00 5.8742e-01 4.1258e-01 9.0901e-01 9.0987e-02 5.6844e-04 5.2056e-04 6.3970e-04 4.4930e-04 - 1.4500e-03 -8.2974e+00 5.8207e-01 4.1793e-01 9.0901e-01 9.0987e-02 5.6677e-04 5.3223e-04 6.3970e-04 4.5930e-04 - 1.4600e-03 -8.2974e+00 5.7683e-01 4.2317e-01 9.0901e-01 9.0987e-02 5.6511e-04 5.4389e-04 6.3970e-04 4.6930e-04 - 1.4700e-03 -8.2974e+00 5.7167e-01 4.2833e-01 9.0901e-01 9.0987e-02 5.6344e-04 5.5556e-04 6.3970e-04 4.7930e-04 - 1.4800e-03 -8.2974e+00 5.6661e-01 4.3339e-01 9.0901e-01 9.0987e-02 5.6178e-04 5.6723e-04 6.3970e-04 4.8930e-04 - 1.4900e-03 -8.2974e+00 5.6163e-01 4.3837e-01 9.0901e-01 9.0987e-02 5.6011e-04 5.7889e-04 6.3970e-04 4.9930e-04 - 1.5000e-03 -8.2974e+00 5.5675e-01 4.4325e-01 9.0901e-01 9.0987e-02 5.5844e-04 5.9056e-04 6.3970e-04 5.0930e-04 - 1.5100e-03 -8.2974e+00 5.5194e-01 4.4806e-01 9.0901e-01 9.0987e-02 5.5678e-04 6.0222e-04 6.3970e-04 5.1930e-04 - 1.5200e-03 -8.2974e+00 5.4722e-01 4.5278e-01 9.0901e-01 9.0987e-02 5.5511e-04 6.1389e-04 6.3970e-04 5.2930e-04 - 1.5300e-03 -8.2974e+00 5.4258e-01 4.5742e-01 9.0901e-01 9.0987e-02 5.5344e-04 6.2556e-04 6.3970e-04 5.3930e-04 - 1.5400e-03 -8.2974e+00 5.3802e-01 4.6198e-01 9.0901e-01 9.0987e-02 5.5178e-04 6.3722e-04 6.3970e-04 5.4930e-04 - 1.5500e-03 -8.2974e+00 5.3353e-01 4.6647e-01 9.0901e-01 9.0987e-02 5.5011e-04 6.4889e-04 6.3970e-04 5.5930e-04 - 1.5600e-03 -8.2974e+00 5.2912e-01 4.7088e-01 9.0901e-01 9.0987e-02 5.4845e-04 6.6055e-04 6.3970e-04 5.6930e-04 - 1.5700e-03 -8.2974e+00 5.2477e-01 4.7523e-01 9.0901e-01 9.0987e-02 5.4678e-04 6.7222e-04 6.3970e-04 5.7930e-04 - 1.5800e-03 -8.2974e+00 5.2050e-01 4.7950e-01 9.0901e-01 9.0987e-02 5.4511e-04 6.8389e-04 6.3970e-04 5.8930e-04 - 1.5900e-03 -8.2974e+00 5.1630e-01 4.8370e-01 9.0901e-01 9.0987e-02 5.4345e-04 6.9555e-04 6.3970e-04 5.9930e-04 - 1.6000e-03 -8.2974e+00 5.1217e-01 4.8783e-01 9.0901e-01 9.0987e-02 5.4178e-04 7.0722e-04 6.3970e-04 6.0930e-04 - 1.6100e-03 -8.2974e+00 5.0810e-01 4.9190e-01 9.0901e-01 9.0987e-02 5.4011e-04 7.1889e-04 6.3970e-04 6.1930e-04 - 1.6200e-03 -8.2974e+00 5.0410e-01 4.9590e-01 9.0901e-01 9.0987e-02 5.3845e-04 7.3055e-04 6.3970e-04 6.2930e-04 - 1.6300e-03 -8.2974e+00 5.0016e-01 4.9984e-01 9.0901e-01 9.0987e-02 5.3678e-04 7.4222e-04 6.3970e-04 6.3930e-04 - 1.6400e-03 -8.2974e+00 4.9628e-01 5.0372e-01 9.0901e-01 9.0987e-02 5.3512e-04 7.5388e-04 6.3970e-04 6.4930e-04 - 1.6500e-03 -8.2974e+00 4.9246e-01 5.0754e-01 9.0901e-01 9.0987e-02 5.3345e-04 7.6555e-04 6.3970e-04 6.5930e-04 - 1.6600e-03 -8.2974e+00 4.8869e-01 5.1131e-01 9.0901e-01 9.0987e-02 5.3178e-04 7.7722e-04 6.3970e-04 6.6930e-04 - 1.6700e-03 -8.2974e+00 4.8499e-01 5.1501e-01 9.0901e-01 9.0987e-02 5.3012e-04 7.8888e-04 6.3970e-04 6.7930e-04 - 1.6800e-03 -8.2974e+00 4.8134e-01 5.1866e-01 9.0901e-01 9.0987e-02 5.2845e-04 8.0055e-04 6.3970e-04 6.8930e-04 - 1.6900e-03 -8.2974e+00 4.7774e-01 5.2226e-01 9.0901e-01 9.0987e-02 5.2678e-04 8.1222e-04 6.3970e-04 6.9930e-04 - 1.7000e-03 -8.2974e+00 4.7420e-01 5.2580e-01 9.0901e-01 9.0987e-02 5.2512e-04 8.2388e-04 6.3970e-04 7.0930e-04 - 1.7100e-03 -8.2974e+00 4.7071e-01 5.2929e-01 9.0901e-01 9.0987e-02 5.2345e-04 8.3555e-04 6.3970e-04 7.1930e-04 - 1.7200e-03 -8.2974e+00 4.6728e-01 5.3272e-01 9.0901e-01 9.0987e-02 5.2179e-04 8.4721e-04 6.3970e-04 7.2930e-04 - 1.7300e-03 -8.2974e+00 4.6389e-01 5.3611e-01 9.0901e-01 9.0987e-02 5.2012e-04 8.5888e-04 6.3970e-04 7.3930e-04 - 1.7400e-03 -8.2974e+00 4.6055e-01 5.3945e-01 9.0901e-01 9.0987e-02 5.1845e-04 8.7055e-04 6.3970e-04 7.4930e-04 - 1.7500e-03 -8.2974e+00 4.5726e-01 5.4274e-01 9.0901e-01 9.0987e-02 5.1679e-04 8.8221e-04 6.3970e-04 7.5930e-04 - 1.7600e-03 -8.2974e+00 4.5401e-01 5.4599e-01 9.0901e-01 9.0987e-02 5.1512e-04 8.9388e-04 6.3970e-04 7.6930e-04 - 1.7700e-03 -8.2974e+00 4.5081e-01 5.4919e-01 9.0901e-01 9.0987e-02 5.1346e-04 9.0554e-04 6.3970e-04 7.7930e-04 - 1.7800e-03 -8.2974e+00 4.4766e-01 5.5234e-01 9.0901e-01 9.0987e-02 5.1179e-04 9.1721e-04 6.3970e-04 7.8930e-04 - 1.7900e-03 -8.2974e+00 4.4455e-01 5.5545e-01 9.0901e-01 9.0987e-02 5.1012e-04 9.2888e-04 6.3970e-04 7.9930e-04 - 1.8000e-03 -8.2974e+00 4.4148e-01 5.5852e-01 9.0901e-01 9.0987e-02 5.0846e-04 9.4054e-04 6.3970e-04 8.0930e-04 - 1.8100e-03 -8.2974e+00 4.3845e-01 5.6155e-01 9.0901e-01 9.0987e-02 5.0679e-04 9.5221e-04 6.3970e-04 8.1930e-04 - 1.8200e-03 -8.2974e+00 4.3547e-01 5.6453e-01 9.0901e-01 9.0987e-02 5.0512e-04 9.6388e-04 6.3970e-04 8.2930e-04 - 1.8300e-03 -8.2974e+00 4.3252e-01 5.6748e-01 9.0901e-01 9.0987e-02 5.0346e-04 9.7554e-04 6.3970e-04 8.3930e-04 - 1.8400e-03 -8.2974e+00 4.2962e-01 5.7038e-01 9.0901e-01 9.0987e-02 5.0179e-04 9.8721e-04 6.3970e-04 8.4930e-04 - 1.8500e-03 -8.2974e+00 4.2675e-01 5.7325e-01 9.0901e-01 9.0987e-02 5.0013e-04 9.9887e-04 6.3970e-04 8.5930e-04 - 1.8600e-03 -8.2974e+00 4.2392e-01 5.7608e-01 9.0901e-01 9.0987e-02 4.9846e-04 1.0105e-03 6.3970e-04 8.6930e-04 - 1.8700e-03 -8.2974e+00 4.2113e-01 5.7887e-01 9.0901e-01 9.0987e-02 4.9679e-04 1.0222e-03 6.3970e-04 8.7930e-04 - 1.8800e-03 -8.2974e+00 4.1838e-01 5.8162e-01 9.0901e-01 9.0987e-02 4.9513e-04 1.0339e-03 6.3970e-04 8.8930e-04 - 1.8900e-03 -8.2974e+00 4.1566e-01 5.8434e-01 9.0901e-01 9.0987e-02 4.9346e-04 1.0455e-03 6.3970e-04 8.9930e-04 - 1.9000e-03 -8.2974e+00 4.1298e-01 5.8702e-01 9.0901e-01 9.0987e-02 4.9179e-04 1.0572e-03 6.3970e-04 9.0930e-04 - 1.9100e-03 -8.2974e+00 4.1033e-01 5.8967e-01 9.0901e-01 9.0987e-02 4.9013e-04 1.0689e-03 6.3970e-04 9.1930e-04 - 1.9200e-03 -8.2974e+00 4.0771e-01 5.9229e-01 9.0901e-01 9.0987e-02 4.8846e-04 1.0805e-03 6.3970e-04 9.2930e-04 - 1.9300e-03 -8.2974e+00 4.0513e-01 5.9487e-01 9.0901e-01 9.0987e-02 4.8680e-04 1.0922e-03 6.3970e-04 9.3930e-04 - 1.9400e-03 -8.2974e+00 4.0258e-01 5.9742e-01 9.0901e-01 9.0987e-02 4.8513e-04 1.1039e-03 6.3970e-04 9.4930e-04 - 1.9500e-03 -8.2974e+00 4.0006e-01 5.9994e-01 9.0901e-01 9.0987e-02 4.8346e-04 1.1155e-03 6.3970e-04 9.5930e-04 - 1.9600e-03 -8.2974e+00 3.9758e-01 6.0242e-01 9.0901e-01 9.0987e-02 4.8180e-04 1.1272e-03 6.3970e-04 9.6930e-04 - 1.9700e-03 -8.2974e+00 3.9512e-01 6.0488e-01 9.0901e-01 9.0987e-02 4.8013e-04 1.1389e-03 6.3970e-04 9.7930e-04 - 1.9800e-03 -8.2974e+00 3.9270e-01 6.0730e-01 9.0901e-01 9.0987e-02 4.7846e-04 1.1505e-03 6.3970e-04 9.8930e-04 - 1.9900e-03 -8.2974e+00 3.9030e-01 6.0970e-01 9.0901e-01 9.0987e-02 4.7680e-04 1.1622e-03 6.3970e-04 9.9930e-04 - 2.0000e-03 -8.2974e+00 3.8793e-01 6.1207e-01 9.0901e-01 9.0987e-02 4.7513e-04 1.1739e-03 6.3970e-04 1.0093e-03 - 2.0100e-03 -8.2974e+00 3.8559e-01 6.1441e-01 9.0901e-01 9.0987e-02 4.7347e-04 1.1855e-03 6.3970e-04 1.0193e-03 - 2.0200e-03 -8.2974e+00 3.8328e-01 6.1672e-01 9.0901e-01 9.0987e-02 4.7180e-04 1.1972e-03 6.3970e-04 1.0293e-03 - 2.0300e-03 -8.2974e+00 3.8100e-01 6.1900e-01 9.0901e-01 9.0987e-02 4.7013e-04 1.2089e-03 6.3970e-04 1.0393e-03 - 2.0400e-03 -8.2974e+00 3.7875e-01 6.2125e-01 9.0901e-01 9.0987e-02 4.6847e-04 1.2205e-03 6.3970e-04 1.0493e-03 - 2.0500e-03 -8.2974e+00 3.7652e-01 6.2348e-01 9.0901e-01 9.0987e-02 4.6680e-04 1.2322e-03 6.3970e-04 1.0593e-03 - 2.0600e-03 -8.2974e+00 3.7431e-01 6.2569e-01 9.0901e-01 9.0987e-02 4.6514e-04 1.2439e-03 6.3970e-04 1.0693e-03 - 2.0700e-03 -8.2974e+00 3.7214e-01 6.2786e-01 9.0901e-01 9.0987e-02 4.6347e-04 1.2555e-03 6.3970e-04 1.0793e-03 - 2.0800e-03 -8.2974e+00 3.6998e-01 6.3002e-01 9.0901e-01 9.0987e-02 4.6180e-04 1.2672e-03 6.3970e-04 1.0893e-03 - 2.0900e-03 -8.2974e+00 3.6786e-01 6.3214e-01 9.0901e-01 9.0987e-02 4.6014e-04 1.2789e-03 6.3970e-04 1.0993e-03 - 2.1000e-03 -8.2974e+00 3.6575e-01 6.3425e-01 9.0901e-01 9.0987e-02 4.5847e-04 1.2905e-03 6.3970e-04 1.1093e-03 - 2.1100e-03 -8.2974e+00 3.6367e-01 6.3633e-01 9.0901e-01 9.0987e-02 4.5680e-04 1.3022e-03 6.3970e-04 1.1193e-03 - 2.1200e-03 -8.2974e+00 3.6162e-01 6.3838e-01 9.0901e-01 9.0987e-02 4.5514e-04 1.3139e-03 6.3970e-04 1.1293e-03 - 2.1300e-03 -8.2974e+00 3.5958e-01 6.4042e-01 9.0901e-01 9.0987e-02 4.5347e-04 1.3255e-03 6.3970e-04 1.1393e-03 - 2.1400e-03 -8.2974e+00 3.5757e-01 6.4243e-01 9.0901e-01 9.0987e-02 4.5181e-04 1.3372e-03 6.3970e-04 1.1493e-03 - 2.1500e-03 -8.2974e+00 3.5559e-01 6.4441e-01 9.0901e-01 9.0987e-02 4.5014e-04 1.3489e-03 6.3970e-04 1.1593e-03 - 2.1600e-03 -8.2974e+00 3.5362e-01 6.4638e-01 9.0901e-01 9.0987e-02 4.4847e-04 1.3605e-03 6.3970e-04 1.1693e-03 - 2.1700e-03 -8.2974e+00 3.5168e-01 6.4832e-01 9.0901e-01 9.0987e-02 4.4681e-04 1.3722e-03 6.3970e-04 1.1793e-03 - 2.1800e-03 -8.2974e+00 3.4975e-01 6.5025e-01 9.0901e-01 9.0987e-02 4.4514e-04 1.3839e-03 6.3970e-04 1.1893e-03 - 2.1900e-03 -8.2974e+00 3.4785e-01 6.5215e-01 9.0901e-01 9.0987e-02 4.4347e-04 1.3955e-03 6.3970e-04 1.1993e-03 - 2.2000e-03 -8.2974e+00 3.4597e-01 6.5403e-01 9.0901e-01 9.0987e-02 4.4181e-04 1.4072e-03 6.3970e-04 1.2093e-03 - 2.2100e-03 -8.2974e+00 3.4411e-01 6.5589e-01 9.0901e-01 9.0987e-02 4.4014e-04 1.4189e-03 6.3970e-04 1.2193e-03 - 2.2200e-03 -8.2974e+00 3.4227e-01 6.5773e-01 9.0901e-01 9.0987e-02 4.3848e-04 1.4305e-03 6.3970e-04 1.2293e-03 - 2.2300e-03 -8.2974e+00 3.4045e-01 6.5955e-01 9.0901e-01 9.0987e-02 4.3681e-04 1.4422e-03 6.3970e-04 1.2393e-03 - 2.2400e-03 -8.2974e+00 3.3864e-01 6.6136e-01 9.0901e-01 9.0987e-02 4.3514e-04 1.4539e-03 6.3970e-04 1.2493e-03 - 2.2500e-03 -8.2974e+00 3.3686e-01 6.6314e-01 9.0901e-01 9.0987e-02 4.3348e-04 1.4655e-03 6.3970e-04 1.2593e-03 - 2.2600e-03 -8.2974e+00 3.3510e-01 6.6490e-01 9.0901e-01 9.0987e-02 4.3181e-04 1.4772e-03 6.3970e-04 1.2693e-03 - 2.2700e-03 -8.2974e+00 3.3335e-01 6.6665e-01 9.0901e-01 9.0987e-02 4.3015e-04 1.4889e-03 6.3970e-04 1.2793e-03 - 2.2800e-03 -8.2974e+00 3.3162e-01 6.6838e-01 9.0901e-01 9.0987e-02 4.2848e-04 1.5005e-03 6.3970e-04 1.2893e-03 - 2.2900e-03 -8.2974e+00 3.2991e-01 6.7009e-01 9.0901e-01 9.0987e-02 4.2681e-04 1.5122e-03 6.3970e-04 1.2993e-03 - 2.3000e-03 -8.2974e+00 3.2822e-01 6.7178e-01 9.0901e-01 9.0987e-02 4.2515e-04 1.5239e-03 6.3970e-04 1.3093e-03 - 2.3100e-03 -8.2974e+00 3.2654e-01 6.7346e-01 9.0901e-01 9.0987e-02 4.2348e-04 1.5355e-03 6.3970e-04 1.3193e-03 - 2.3200e-03 -8.2974e+00 3.2489e-01 6.7511e-01 9.0901e-01 9.0987e-02 4.2181e-04 1.5472e-03 6.3970e-04 1.3293e-03 - 2.3300e-03 -8.2974e+00 3.2324e-01 6.7676e-01 9.0901e-01 9.0987e-02 4.2015e-04 1.5589e-03 6.3970e-04 1.3393e-03 - 2.3400e-03 -8.2974e+00 3.2162e-01 6.7838e-01 9.0901e-01 9.0987e-02 4.1848e-04 1.5705e-03 6.3970e-04 1.3493e-03 - 2.3500e-03 -8.2974e+00 3.2001e-01 6.7999e-01 9.0901e-01 9.0987e-02 4.1682e-04 1.5822e-03 6.3970e-04 1.3593e-03 - 2.3600e-03 -8.2974e+00 3.1842e-01 6.8158e-01 9.0901e-01 9.0987e-02 4.1515e-04 1.5939e-03 6.3970e-04 1.3693e-03 - 2.3700e-03 -8.2974e+00 3.1684e-01 6.8316e-01 9.0901e-01 9.0987e-02 4.1348e-04 1.6055e-03 6.3970e-04 1.3793e-03 - 2.3800e-03 -8.2974e+00 3.1528e-01 6.8472e-01 9.0901e-01 9.0987e-02 4.1182e-04 1.6172e-03 6.3970e-04 1.3893e-03 - 2.3900e-03 -8.2974e+00 3.1373e-01 6.8627e-01 9.0901e-01 9.0987e-02 4.1015e-04 1.6288e-03 6.3970e-04 1.3993e-03 - 2.4000e-03 -8.2974e+00 3.1220e-01 6.8780e-01 9.0901e-01 9.0987e-02 4.0848e-04 1.6405e-03 6.3970e-04 1.4093e-03 - 2.4100e-03 -8.2974e+00 3.1068e-01 6.8932e-01 9.0901e-01 9.0987e-02 4.0682e-04 1.6522e-03 6.3970e-04 1.4193e-03 - 2.4200e-03 -8.2974e+00 3.0918e-01 6.9082e-01 9.0901e-01 9.0987e-02 4.0515e-04 1.6638e-03 6.3970e-04 1.4293e-03 - 2.4300e-03 -8.2974e+00 3.0770e-01 6.9230e-01 9.0901e-01 9.0987e-02 4.0349e-04 1.6755e-03 6.3970e-04 1.4393e-03 - 2.4400e-03 -8.2974e+00 3.0622e-01 6.9378e-01 9.0901e-01 9.0987e-02 4.0182e-04 1.6872e-03 6.3970e-04 1.4493e-03 - 2.4500e-03 -8.2974e+00 3.0476e-01 6.9524e-01 9.0901e-01 9.0987e-02 4.0015e-04 1.6988e-03 6.3970e-04 1.4593e-03 - 2.4600e-03 -8.2974e+00 3.0332e-01 6.9668e-01 9.0901e-01 9.0987e-02 3.9849e-04 1.7105e-03 6.3970e-04 1.4693e-03 - 2.4700e-03 -8.2974e+00 3.0189e-01 6.9811e-01 9.0901e-01 9.0987e-02 3.9682e-04 1.7222e-03 6.3970e-04 1.4793e-03 - 2.4800e-03 -8.2974e+00 3.0047e-01 6.9953e-01 9.0901e-01 9.0987e-02 3.9515e-04 1.7338e-03 6.3970e-04 1.4893e-03 - 2.4900e-03 -8.2974e+00 2.9907e-01 7.0093e-01 9.0901e-01 9.0987e-02 3.9349e-04 1.7455e-03 6.3970e-04 1.4993e-03 - 2.5000e-03 -8.2974e+00 2.9767e-01 7.0233e-01 9.0901e-01 9.0987e-02 3.9182e-04 1.7572e-03 6.3970e-04 1.5093e-03 - 2.5100e-03 -8.2974e+00 2.9629e-01 7.0371e-01 9.0901e-01 9.0987e-02 3.9016e-04 1.7688e-03 6.3970e-04 1.5193e-03 - 2.5200e-03 -8.2974e+00 2.9493e-01 7.0507e-01 9.0901e-01 9.0987e-02 3.8849e-04 1.7805e-03 6.3970e-04 1.5293e-03 - 2.5300e-03 -8.2974e+00 2.9358e-01 7.0642e-01 9.0901e-01 9.0987e-02 3.8682e-04 1.7922e-03 6.3970e-04 1.5393e-03 - 2.5400e-03 -8.2974e+00 2.9223e-01 7.0777e-01 9.0901e-01 9.0987e-02 3.8516e-04 1.8038e-03 6.3970e-04 1.5493e-03 - 2.5500e-03 -8.2974e+00 2.9091e-01 7.0909e-01 9.0901e-01 9.0987e-02 3.8349e-04 1.8155e-03 6.3970e-04 1.5593e-03 - 2.5600e-03 -8.2974e+00 2.8959e-01 7.1041e-01 9.0901e-01 9.0987e-02 3.8183e-04 1.8272e-03 6.3970e-04 1.5693e-03 - 2.5700e-03 -8.2974e+00 2.8828e-01 7.1172e-01 9.0901e-01 9.0987e-02 3.8016e-04 1.8388e-03 6.3970e-04 1.5793e-03 - 2.5800e-03 -8.2974e+00 2.8699e-01 7.1301e-01 9.0901e-01 9.0987e-02 3.7849e-04 1.8505e-03 6.3970e-04 1.5893e-03 - 2.5900e-03 -8.2974e+00 2.8571e-01 7.1429e-01 9.0901e-01 9.0987e-02 3.7683e-04 1.8622e-03 6.3970e-04 1.5993e-03 - 2.6000e-03 -8.2974e+00 2.8444e-01 7.1556e-01 9.0901e-01 9.0987e-02 3.7516e-04 1.8738e-03 6.3970e-04 1.6093e-03 - 2.6100e-03 -8.2974e+00 2.8318e-01 7.1682e-01 9.0901e-01 9.0987e-02 3.7349e-04 1.8855e-03 6.3970e-04 1.6193e-03 - 2.6200e-03 -8.2974e+00 2.8193e-01 7.1807e-01 9.0901e-01 9.0987e-02 3.7183e-04 1.8972e-03 6.3970e-04 1.6293e-03 - 2.6300e-03 -8.2974e+00 2.8069e-01 7.1931e-01 9.0901e-01 9.0987e-02 3.7016e-04 1.9088e-03 6.3970e-04 1.6393e-03 - 2.6400e-03 -8.2974e+00 2.7947e-01 7.2053e-01 9.0901e-01 9.0987e-02 3.6850e-04 1.9205e-03 6.3970e-04 1.6493e-03 - 2.6500e-03 -8.2974e+00 2.7825e-01 7.2175e-01 9.0901e-01 9.0987e-02 3.6683e-04 1.9322e-03 6.3970e-04 1.6593e-03 - 2.6600e-03 -8.2974e+00 2.7705e-01 7.2295e-01 9.0901e-01 9.0987e-02 3.6516e-04 1.9438e-03 6.3970e-04 1.6693e-03 - 2.6700e-03 -8.2974e+00 2.7585e-01 7.2415e-01 9.0901e-01 9.0987e-02 3.6350e-04 1.9555e-03 6.3970e-04 1.6793e-03 - 2.6800e-03 -8.2974e+00 2.7467e-01 7.2533e-01 9.0901e-01 9.0987e-02 3.6183e-04 1.9672e-03 6.3970e-04 1.6893e-03 - 2.6900e-03 -8.2974e+00 2.7349e-01 7.2651e-01 9.0901e-01 9.0987e-02 3.6016e-04 1.9788e-03 6.3970e-04 1.6993e-03 - 2.7000e-03 -8.2974e+00 2.7233e-01 7.2767e-01 9.0901e-01 9.0987e-02 3.5850e-04 1.9905e-03 6.3970e-04 1.7093e-03 - 2.7100e-03 -8.2974e+00 2.7117e-01 7.2883e-01 9.0901e-01 9.0987e-02 3.5683e-04 2.0022e-03 6.3970e-04 1.7193e-03 - 2.7200e-03 -8.2974e+00 2.7003e-01 7.2997e-01 9.0901e-01 9.0987e-02 3.5517e-04 2.0138e-03 6.3970e-04 1.7293e-03 - 2.7300e-03 -8.2974e+00 2.6889e-01 7.3111e-01 9.0901e-01 9.0987e-02 3.5350e-04 2.0255e-03 6.3970e-04 1.7393e-03 - 2.7400e-03 -8.2974e+00 2.6777e-01 7.3223e-01 9.0901e-01 9.0987e-02 3.5183e-04 2.0372e-03 6.3970e-04 1.7493e-03 - 2.7500e-03 -8.2974e+00 2.6665e-01 7.3335e-01 9.0901e-01 9.0987e-02 3.5017e-04 2.0488e-03 6.3970e-04 1.7593e-03 - 2.7600e-03 -8.2974e+00 2.6555e-01 7.3445e-01 9.0901e-01 9.0987e-02 3.4850e-04 2.0605e-03 6.3970e-04 1.7693e-03 - 2.7700e-03 -8.2974e+00 2.6445e-01 7.3555e-01 9.0901e-01 9.0987e-02 3.4683e-04 2.0722e-03 6.3970e-04 1.7793e-03 - 2.7800e-03 -8.2974e+00 2.6336e-01 7.3664e-01 9.0901e-01 9.0987e-02 3.4517e-04 2.0838e-03 6.3970e-04 1.7893e-03 - 2.7900e-03 -8.2974e+00 2.6228e-01 7.3772e-01 9.0901e-01 9.0987e-02 3.4350e-04 2.0955e-03 6.3970e-04 1.7993e-03 - 2.8000e-03 -8.2974e+00 2.6121e-01 7.3879e-01 9.0901e-01 9.0987e-02 3.4184e-04 2.1072e-03 6.3970e-04 1.8093e-03 - 2.8100e-03 -8.2974e+00 2.6015e-01 7.3985e-01 9.0901e-01 9.0987e-02 3.4017e-04 2.1188e-03 6.3970e-04 1.8193e-03 - 2.8200e-03 -8.2974e+00 2.5909e-01 7.4091e-01 9.0901e-01 9.0987e-02 3.3850e-04 2.1305e-03 6.3970e-04 1.8293e-03 - 2.8300e-03 -8.2974e+00 2.5805e-01 7.4195e-01 9.0901e-01 9.0987e-02 3.3684e-04 2.1422e-03 6.3970e-04 1.8393e-03 - 2.8400e-03 -8.2974e+00 2.5701e-01 7.4299e-01 9.0901e-01 9.0987e-02 3.3517e-04 2.1538e-03 6.3970e-04 1.8493e-03 - 2.8500e-03 -8.2974e+00 2.5598e-01 7.4402e-01 9.0901e-01 9.0987e-02 3.3351e-04 2.1655e-03 6.3970e-04 1.8593e-03 - 2.8600e-03 -8.2974e+00 2.5496e-01 7.4504e-01 9.0901e-01 9.0987e-02 3.3184e-04 2.1772e-03 6.3970e-04 1.8693e-03 - 2.8700e-03 -8.2974e+00 2.5395e-01 7.4605e-01 9.0901e-01 9.0987e-02 3.3017e-04 2.1888e-03 6.3970e-04 1.8793e-03 - 2.8800e-03 -8.2974e+00 2.5295e-01 7.4705e-01 9.0901e-01 9.0987e-02 3.2851e-04 2.2005e-03 6.3970e-04 1.8893e-03 - 2.8900e-03 -8.2974e+00 2.5195e-01 7.4805e-01 9.0901e-01 9.0987e-02 3.2684e-04 2.2122e-03 6.3970e-04 1.8993e-03 - 2.9000e-03 -8.2974e+00 2.5096e-01 7.4904e-01 9.0901e-01 9.0987e-02 3.2517e-04 2.2238e-03 6.3970e-04 1.9093e-03 - 2.9100e-03 -8.2974e+00 2.4998e-01 7.5002e-01 9.0901e-01 9.0987e-02 3.2351e-04 2.2355e-03 6.3970e-04 1.9193e-03 - 2.9200e-03 -8.2974e+00 2.4901e-01 7.5099e-01 9.0901e-01 9.0987e-02 3.2184e-04 2.2472e-03 6.3970e-04 1.9293e-03 - 2.9300e-03 -8.2974e+00 2.4804e-01 7.5196e-01 9.0901e-01 9.0987e-02 3.2018e-04 2.2588e-03 6.3970e-04 1.9393e-03 - 2.9400e-03 -8.2974e+00 2.4708e-01 7.5292e-01 9.0901e-01 9.0987e-02 3.1851e-04 2.2705e-03 6.3970e-04 1.9493e-03 - 2.9500e-03 -8.2974e+00 2.4613e-01 7.5387e-01 9.0901e-01 9.0987e-02 3.1684e-04 2.2822e-03 6.3970e-04 1.9593e-03 - 2.9600e-03 -8.2974e+00 2.4519e-01 7.5481e-01 9.0901e-01 9.0987e-02 3.1518e-04 2.2938e-03 6.3970e-04 1.9693e-03 - 2.9700e-03 -8.2974e+00 2.4425e-01 7.5575e-01 9.0901e-01 9.0987e-02 3.1351e-04 2.3055e-03 6.3970e-04 1.9793e-03 - 2.9800e-03 -8.2974e+00 2.4332e-01 7.5668e-01 9.0901e-01 9.0987e-02 3.1184e-04 2.3172e-03 6.3970e-04 1.9893e-03 - 2.9900e-03 -8.2974e+00 2.4240e-01 7.5760e-01 9.0901e-01 9.0987e-02 3.1018e-04 2.3288e-03 6.3970e-04 1.9993e-03 - 3.0000e-03 -8.2974e+00 2.4149e-01 7.5851e-01 9.0901e-01 9.0987e-02 3.0851e-04 2.3405e-03 6.3970e-04 2.0093e-03 - 3.0100e-03 -8.2974e+00 2.4058e-01 7.5942e-01 9.0901e-01 9.0987e-02 3.0685e-04 2.3522e-03 6.3970e-04 2.0193e-03 - 3.0200e-03 -8.2974e+00 2.3968e-01 7.6032e-01 9.0901e-01 9.0987e-02 3.0518e-04 2.3638e-03 6.3970e-04 2.0293e-03 - 3.0300e-03 -8.2974e+00 2.3878e-01 7.6122e-01 9.0901e-01 9.0987e-02 3.0351e-04 2.3755e-03 6.3970e-04 2.0393e-03 - 3.0400e-03 -8.2974e+00 2.3790e-01 7.6210e-01 9.0901e-01 9.0987e-02 3.0185e-04 2.3872e-03 6.3970e-04 2.0493e-03 - 3.0500e-03 -8.2974e+00 2.3701e-01 7.6299e-01 9.0901e-01 9.0987e-02 3.0018e-04 2.3988e-03 6.3970e-04 2.0593e-03 - 3.0600e-03 -8.2974e+00 2.3614e-01 7.6386e-01 9.0901e-01 9.0987e-02 2.9852e-04 2.4105e-03 6.3970e-04 2.0693e-03 - 3.0700e-03 -8.2974e+00 2.3527e-01 7.6473e-01 9.0901e-01 9.0987e-02 2.9685e-04 2.4222e-03 6.3970e-04 2.0793e-03 - 3.0800e-03 -8.2974e+00 2.3441e-01 7.6559e-01 9.0901e-01 9.0987e-02 2.9518e-04 2.4338e-03 6.3970e-04 2.0893e-03 - 3.0900e-03 -8.2974e+00 2.3355e-01 7.6645e-01 9.0901e-01 9.0987e-02 2.9352e-04 2.4455e-03 6.3970e-04 2.0993e-03 - 3.1000e-03 -8.2974e+00 2.3270e-01 7.6730e-01 9.0901e-01 9.0987e-02 2.9185e-04 2.4571e-03 6.3970e-04 2.1093e-03 - 3.1100e-03 -8.2974e+00 2.3186e-01 7.6814e-01 9.0901e-01 9.0987e-02 2.9018e-04 2.4688e-03 6.3970e-04 2.1193e-03 - 3.1200e-03 -8.2974e+00 2.3102e-01 7.6898e-01 9.0901e-01 9.0987e-02 2.8852e-04 2.4805e-03 6.3970e-04 2.1293e-03 - 3.1300e-03 -8.2974e+00 2.3019e-01 7.6981e-01 9.0901e-01 9.0987e-02 2.8685e-04 2.4921e-03 6.3970e-04 2.1393e-03 - 3.1400e-03 -8.2974e+00 2.2937e-01 7.7063e-01 9.0901e-01 9.0987e-02 2.8519e-04 2.5038e-03 6.3970e-04 2.1493e-03 - 3.1500e-03 -8.2974e+00 2.2855e-01 7.7145e-01 9.0901e-01 9.0987e-02 2.8352e-04 2.5155e-03 6.3970e-04 2.1593e-03 - 3.1600e-03 -8.2974e+00 2.2773e-01 7.7227e-01 9.0901e-01 9.0987e-02 2.8185e-04 2.5271e-03 6.3970e-04 2.1693e-03 - 3.1700e-03 -8.2974e+00 2.2692e-01 7.7308e-01 9.0901e-01 9.0987e-02 2.8019e-04 2.5388e-03 6.3970e-04 2.1793e-03 - 3.1800e-03 -8.2974e+00 2.2612e-01 7.7388e-01 9.0901e-01 9.0987e-02 2.7852e-04 2.5505e-03 6.3970e-04 2.1893e-03 - 3.1900e-03 -8.2974e+00 2.2533e-01 7.7467e-01 9.0901e-01 9.0987e-02 2.7685e-04 2.5621e-03 6.3970e-04 2.1993e-03 - 3.2000e-03 -8.2974e+00 2.2454e-01 7.7546e-01 9.0901e-01 9.0987e-02 2.7519e-04 2.5738e-03 6.3970e-04 2.2093e-03 - 3.2100e-03 -8.2974e+00 2.2375e-01 7.7625e-01 9.0901e-01 9.0987e-02 2.7352e-04 2.5855e-03 6.3970e-04 2.2193e-03 - 3.2200e-03 -8.2974e+00 2.2297e-01 7.7703e-01 9.0901e-01 9.0987e-02 2.7186e-04 2.5971e-03 6.3970e-04 2.2293e-03 - 3.2300e-03 -8.2974e+00 2.2220e-01 7.7780e-01 9.0901e-01 9.0987e-02 2.7019e-04 2.6088e-03 6.3970e-04 2.2393e-03 - 3.2400e-03 -8.2974e+00 2.2143e-01 7.7857e-01 9.0901e-01 9.0987e-02 2.6852e-04 2.6205e-03 6.3970e-04 2.2493e-03 - 3.2500e-03 -8.2974e+00 2.2066e-01 7.7934e-01 9.0901e-01 9.0987e-02 2.6686e-04 2.6321e-03 6.3970e-04 2.2593e-03 - 3.2600e-03 -8.2974e+00 2.1990e-01 7.8010e-01 9.0901e-01 9.0987e-02 2.6519e-04 2.6438e-03 6.3970e-04 2.2693e-03 - 3.2700e-03 -8.2974e+00 2.1915e-01 7.8085e-01 9.0901e-01 9.0987e-02 2.6352e-04 2.6555e-03 6.3970e-04 2.2793e-03 - 3.2800e-03 -8.2974e+00 2.1840e-01 7.8160e-01 9.0901e-01 9.0987e-02 2.6186e-04 2.6671e-03 6.3970e-04 2.2893e-03 - 3.2900e-03 -8.2974e+00 2.1766e-01 7.8234e-01 9.0901e-01 9.0987e-02 2.6019e-04 2.6788e-03 6.3970e-04 2.2993e-03 - 3.3000e-03 -8.2974e+00 2.1692e-01 7.8308e-01 9.0901e-01 9.0987e-02 2.5853e-04 2.6905e-03 6.3970e-04 2.3093e-03 - 3.3100e-03 -8.2974e+00 2.1619e-01 7.8381e-01 9.0901e-01 9.0987e-02 2.5686e-04 2.7021e-03 6.3970e-04 2.3193e-03 - 3.3200e-03 -8.2974e+00 2.1546e-01 7.8454e-01 9.0901e-01 9.0987e-02 2.5519e-04 2.7138e-03 6.3970e-04 2.3293e-03 - 3.3300e-03 -8.2974e+00 2.1474e-01 7.8526e-01 9.0901e-01 9.0987e-02 2.5353e-04 2.7255e-03 6.3970e-04 2.3393e-03 - 3.3400e-03 -8.2974e+00 2.1402e-01 7.8598e-01 9.0901e-01 9.0987e-02 2.5186e-04 2.7371e-03 6.3970e-04 2.3493e-03 - 3.3500e-03 -8.2974e+00 2.1330e-01 7.8670e-01 9.0901e-01 9.0987e-02 2.5020e-04 2.7488e-03 6.3970e-04 2.3593e-03 - 3.3600e-03 -8.2974e+00 2.1260e-01 7.8740e-01 9.0901e-01 9.0987e-02 2.4853e-04 2.7605e-03 6.3970e-04 2.3693e-03 - 3.3700e-03 -8.2974e+00 2.1189e-01 7.8811e-01 9.0901e-01 9.0987e-02 2.4686e-04 2.7721e-03 6.3970e-04 2.3793e-03 - 3.3800e-03 -8.2974e+00 2.1119e-01 7.8881e-01 9.0901e-01 9.0987e-02 2.4520e-04 2.7838e-03 6.3970e-04 2.3893e-03 - 3.3900e-03 -8.2974e+00 2.1050e-01 7.8950e-01 9.0901e-01 9.0987e-02 2.4353e-04 2.7955e-03 6.3970e-04 2.3993e-03 - 3.4000e-03 -8.2974e+00 2.0981e-01 7.9019e-01 9.0901e-01 9.0987e-02 2.4186e-04 2.8071e-03 6.3970e-04 2.4093e-03 - 3.4100e-03 -8.2974e+00 2.0912e-01 7.9088e-01 9.0901e-01 9.0987e-02 2.4020e-04 2.8188e-03 6.3970e-04 2.4193e-03 - 3.4200e-03 -8.2974e+00 2.0844e-01 7.9156e-01 9.0901e-01 9.0987e-02 2.3853e-04 2.8305e-03 6.3970e-04 2.4293e-03 - 3.4300e-03 -8.2974e+00 2.0776e-01 7.9224e-01 9.0901e-01 9.0987e-02 2.3687e-04 2.8421e-03 6.3970e-04 2.4393e-03 - 3.4400e-03 -8.2974e+00 2.0709e-01 7.9291e-01 9.0901e-01 9.0987e-02 2.3520e-04 2.8538e-03 6.3970e-04 2.4493e-03 - 3.4500e-03 -8.2974e+00 2.0642e-01 7.9358e-01 9.0901e-01 9.0987e-02 2.3353e-04 2.8655e-03 6.3970e-04 2.4593e-03 - 3.4600e-03 -8.2974e+00 2.0576e-01 7.9424e-01 9.0901e-01 9.0987e-02 2.3187e-04 2.8771e-03 6.3970e-04 2.4693e-03 - 3.4700e-03 -8.2974e+00 2.0510e-01 7.9490e-01 9.0901e-01 9.0987e-02 2.3020e-04 2.8888e-03 6.3970e-04 2.4793e-03 - 3.4800e-03 -8.2974e+00 2.0444e-01 7.9556e-01 9.0901e-01 9.0987e-02 2.2853e-04 2.9005e-03 6.3970e-04 2.4893e-03 - 3.4900e-03 -8.2974e+00 2.0379e-01 7.9621e-01 9.0901e-01 9.0987e-02 2.2687e-04 2.9121e-03 6.3970e-04 2.4993e-03 - 3.5000e-03 -8.2974e+00 2.0314e-01 7.9686e-01 9.0901e-01 9.0987e-02 2.2520e-04 2.9238e-03 6.3970e-04 2.5093e-03 - 3.5100e-03 -8.2974e+00 2.0250e-01 7.9750e-01 9.0901e-01 9.0987e-02 2.2354e-04 2.9355e-03 6.3970e-04 2.5193e-03 - 3.5200e-03 -8.2974e+00 2.0186e-01 7.9814e-01 9.0901e-01 9.0987e-02 2.2187e-04 2.9471e-03 6.3970e-04 2.5293e-03 - 3.5300e-03 -8.2974e+00 2.0123e-01 7.9877e-01 9.0901e-01 9.0987e-02 2.2020e-04 2.9588e-03 6.3970e-04 2.5393e-03 - 3.5400e-03 -8.2974e+00 2.0060e-01 7.9940e-01 9.0901e-01 9.0987e-02 2.1854e-04 2.9705e-03 6.3970e-04 2.5493e-03 - 3.5500e-03 -8.2974e+00 1.9997e-01 8.0003e-01 9.0901e-01 9.0987e-02 2.1687e-04 2.9821e-03 6.3970e-04 2.5593e-03 - 3.5600e-03 -8.2974e+00 1.9935e-01 8.0065e-01 9.0901e-01 9.0987e-02 2.1520e-04 2.9938e-03 6.3970e-04 2.5693e-03 - 3.5700e-03 -8.2974e+00 1.9873e-01 8.0127e-01 9.0901e-01 9.0987e-02 2.1354e-04 3.0055e-03 6.3970e-04 2.5793e-03 - 3.5800e-03 -8.2974e+00 1.9811e-01 8.0189e-01 9.0901e-01 9.0987e-02 2.1187e-04 3.0171e-03 6.3970e-04 2.5893e-03 - 3.5900e-03 -8.2974e+00 1.9750e-01 8.0250e-01 9.0901e-01 9.0987e-02 2.1021e-04 3.0288e-03 6.3970e-04 2.5993e-03 - 3.6000e-03 -8.2974e+00 1.9689e-01 8.0311e-01 9.0901e-01 9.0987e-02 2.0854e-04 3.0405e-03 6.3970e-04 2.6093e-03 - 3.6100e-03 -8.2974e+00 1.9629e-01 8.0371e-01 9.0901e-01 9.0987e-02 2.0687e-04 3.0521e-03 6.3970e-04 2.6193e-03 - 3.6200e-03 -8.2974e+00 1.9569e-01 8.0431e-01 9.0901e-01 9.0987e-02 2.0521e-04 3.0638e-03 6.3970e-04 2.6293e-03 - 3.6300e-03 -8.2974e+00 1.9509e-01 8.0491e-01 9.0901e-01 9.0987e-02 2.0354e-04 3.0755e-03 6.3970e-04 2.6393e-03 - 3.6400e-03 -8.2974e+00 1.9450e-01 8.0550e-01 9.0901e-01 9.0987e-02 2.0188e-04 3.0871e-03 6.3970e-04 2.6493e-03 - 3.6500e-03 -8.2974e+00 1.9391e-01 8.0609e-01 9.0901e-01 9.0987e-02 2.0021e-04 3.0988e-03 6.3970e-04 2.6593e-03 - 3.6600e-03 -8.2974e+00 1.9332e-01 8.0668e-01 9.0901e-01 9.0987e-02 1.9854e-04 3.1105e-03 6.3970e-04 2.6693e-03 - 3.6700e-03 -8.2974e+00 1.9274e-01 8.0726e-01 9.0901e-01 9.0987e-02 1.9688e-04 3.1221e-03 6.3970e-04 2.6793e-03 - 3.6800e-03 -8.2974e+00 1.9216e-01 8.0784e-01 9.0901e-01 9.0987e-02 1.9521e-04 3.1338e-03 6.3970e-04 2.6893e-03 - 3.6900e-03 -8.2974e+00 1.9158e-01 8.0842e-01 9.0901e-01 9.0987e-02 1.9354e-04 3.1455e-03 6.3970e-04 2.6993e-03 - 3.7000e-03 -8.2974e+00 1.9101e-01 8.0899e-01 9.0901e-01 9.0987e-02 1.9188e-04 3.1571e-03 6.3970e-04 2.7093e-03 - 3.7100e-03 -8.2974e+00 1.9044e-01 8.0956e-01 9.0901e-01 9.0987e-02 1.9021e-04 3.1688e-03 6.3970e-04 2.7193e-03 - 3.7200e-03 -8.2974e+00 1.8988e-01 8.1012e-01 9.0901e-01 9.0987e-02 1.8855e-04 3.1805e-03 6.3970e-04 2.7293e-03 - 3.7300e-03 -8.2974e+00 1.8932e-01 8.1068e-01 9.0901e-01 9.0987e-02 1.8688e-04 3.1921e-03 6.3970e-04 2.7393e-03 - 3.7400e-03 -8.2974e+00 1.8876e-01 8.1124e-01 9.0901e-01 9.0987e-02 1.8521e-04 3.2038e-03 6.3970e-04 2.7493e-03 - 3.7500e-03 -8.2974e+00 1.8820e-01 8.1180e-01 9.0901e-01 9.0987e-02 1.8355e-04 3.2155e-03 6.3970e-04 2.7593e-03 - 3.7600e-03 -8.2974e+00 1.8765e-01 8.1235e-01 9.0901e-01 9.0987e-02 1.8188e-04 3.2271e-03 6.3970e-04 2.7693e-03 - 3.7700e-03 -8.2974e+00 1.8710e-01 8.1290e-01 9.0901e-01 9.0987e-02 1.8021e-04 3.2388e-03 6.3970e-04 2.7793e-03 - 3.7800e-03 -8.2974e+00 1.8656e-01 8.1344e-01 9.0901e-01 9.0987e-02 1.7855e-04 3.2505e-03 6.3970e-04 2.7893e-03 - 3.7900e-03 -8.2974e+00 1.8601e-01 8.1399e-01 9.0901e-01 9.0987e-02 1.7688e-04 3.2621e-03 6.3970e-04 2.7993e-03 - 3.8000e-03 -8.2974e+00 1.8547e-01 8.1453e-01 9.0901e-01 9.0987e-02 1.7522e-04 3.2738e-03 6.3970e-04 2.8093e-03 - 3.8100e-03 -8.2974e+00 1.8494e-01 8.1506e-01 9.0901e-01 9.0987e-02 1.7355e-04 3.2855e-03 6.3970e-04 2.8193e-03 - 3.8200e-03 -8.2974e+00 1.8440e-01 8.1560e-01 9.0901e-01 9.0987e-02 1.7188e-04 3.2971e-03 6.3970e-04 2.8293e-03 - 3.8300e-03 -8.2974e+00 1.8387e-01 8.1613e-01 9.0901e-01 9.0987e-02 1.7022e-04 3.3088e-03 6.3970e-04 2.8393e-03 - 3.8400e-03 -8.2974e+00 1.8335e-01 8.1665e-01 9.0901e-01 9.0987e-02 1.6855e-04 3.3204e-03 6.3970e-04 2.8493e-03 - 3.8500e-03 -8.2974e+00 1.8282e-01 8.1718e-01 9.0901e-01 9.0987e-02 1.6689e-04 3.3321e-03 6.3970e-04 2.8593e-03 - 3.8600e-03 -8.2974e+00 1.8230e-01 8.1770e-01 9.0901e-01 9.0987e-02 1.6522e-04 3.3438e-03 6.3970e-04 2.8693e-03 - 3.8700e-03 -8.2974e+00 1.8178e-01 8.1822e-01 9.0901e-01 9.0987e-02 1.6355e-04 3.3554e-03 6.3970e-04 2.8793e-03 - 3.8800e-03 -8.2974e+00 1.8127e-01 8.1873e-01 9.0901e-01 9.0987e-02 1.6189e-04 3.3671e-03 6.3970e-04 2.8893e-03 - 3.8900e-03 -8.2974e+00 1.8076e-01 8.1924e-01 9.0901e-01 9.0987e-02 1.6022e-04 3.3788e-03 6.3970e-04 2.8993e-03 - 3.9000e-03 -8.2974e+00 1.8025e-01 8.1975e-01 9.0901e-01 9.0987e-02 1.5855e-04 3.3904e-03 6.3970e-04 2.9093e-03 - 3.9100e-03 -8.2974e+00 1.7974e-01 8.2026e-01 9.0901e-01 9.0987e-02 1.5689e-04 3.4021e-03 6.3970e-04 2.9193e-03 - 3.9200e-03 -8.2974e+00 1.7924e-01 8.2076e-01 9.0901e-01 9.0987e-02 1.5522e-04 3.4138e-03 6.3970e-04 2.9293e-03 - 3.9300e-03 -8.2974e+00 1.7874e-01 8.2126e-01 9.0901e-01 9.0987e-02 1.5356e-04 3.4254e-03 6.3970e-04 2.9393e-03 - 3.9400e-03 -8.2974e+00 1.7824e-01 8.2176e-01 9.0901e-01 9.0987e-02 1.5189e-04 3.4371e-03 6.3970e-04 2.9493e-03 - 3.9500e-03 -8.2974e+00 1.7774e-01 8.2226e-01 9.0901e-01 9.0987e-02 1.5022e-04 3.4488e-03 6.3970e-04 2.9593e-03 - 3.9600e-03 -8.2974e+00 1.7725e-01 8.2275e-01 9.0901e-01 9.0987e-02 1.4856e-04 3.4604e-03 6.3970e-04 2.9693e-03 - 3.9700e-03 -8.2974e+00 1.7676e-01 8.2324e-01 9.0901e-01 9.0987e-02 1.4689e-04 3.4721e-03 6.3970e-04 2.9793e-03 - 3.9800e-03 -8.2974e+00 1.7627e-01 8.2373e-01 9.0901e-01 9.0987e-02 1.4522e-04 3.4838e-03 6.3970e-04 2.9893e-03 - 3.9900e-03 -8.2974e+00 1.7579e-01 8.2421e-01 9.0901e-01 9.0987e-02 1.4356e-04 3.4954e-03 6.3970e-04 2.9993e-03 - 4.0000e-03 -8.2974e+00 1.7531e-01 8.2469e-01 9.0901e-01 9.0987e-02 1.4189e-04 3.5071e-03 6.3970e-04 3.0093e-03 - 4.0100e-03 -8.2974e+00 1.7483e-01 8.2517e-01 9.0901e-01 9.0987e-02 1.4023e-04 3.5188e-03 6.3970e-04 3.0193e-03 - 4.0200e-03 -8.2974e+00 1.7435e-01 8.2565e-01 9.0901e-01 9.0987e-02 1.3856e-04 3.5304e-03 6.3970e-04 3.0293e-03 - 4.0300e-03 -8.2974e+00 1.7388e-01 8.2612e-01 9.0901e-01 9.0987e-02 1.3689e-04 3.5421e-03 6.3970e-04 3.0393e-03 - 4.0400e-03 -8.2974e+00 1.7341e-01 8.2659e-01 9.0901e-01 9.0987e-02 1.3523e-04 3.5538e-03 6.3970e-04 3.0493e-03 - 4.0500e-03 -8.2974e+00 1.7294e-01 8.2706e-01 9.0901e-01 9.0987e-02 1.3356e-04 3.5654e-03 6.3970e-04 3.0593e-03 - 4.0600e-03 -8.2974e+00 1.7247e-01 8.2753e-01 9.0901e-01 9.0987e-02 1.3189e-04 3.5771e-03 6.3970e-04 3.0693e-03 - 4.0700e-03 -8.2974e+00 1.7201e-01 8.2799e-01 9.0901e-01 9.0987e-02 1.3023e-04 3.5888e-03 6.3970e-04 3.0793e-03 - 4.0800e-03 -8.2974e+00 1.7155e-01 8.2845e-01 9.0901e-01 9.0987e-02 1.2856e-04 3.6004e-03 6.3970e-04 3.0893e-03 - 4.0900e-03 -8.2974e+00 1.7109e-01 8.2891e-01 9.0901e-01 9.0987e-02 1.2690e-04 3.6121e-03 6.3970e-04 3.0993e-03 - 4.1000e-03 -8.2974e+00 1.7063e-01 8.2937e-01 9.0901e-01 9.0987e-02 1.2523e-04 3.6238e-03 6.3970e-04 3.1093e-03 - 4.1100e-03 -8.2974e+00 1.7018e-01 8.2982e-01 9.0901e-01 9.0987e-02 1.2356e-04 3.6354e-03 6.3970e-04 3.1193e-03 - 4.1200e-03 -8.2974e+00 1.6973e-01 8.3027e-01 9.0901e-01 9.0987e-02 1.2190e-04 3.6471e-03 6.3970e-04 3.1293e-03 - 4.1300e-03 -8.2974e+00 1.6928e-01 8.3072e-01 9.0901e-01 9.0987e-02 1.2023e-04 3.6588e-03 6.3970e-04 3.1393e-03 - 4.1400e-03 -8.2974e+00 1.6883e-01 8.3117e-01 9.0901e-01 9.0987e-02 1.1857e-04 3.6704e-03 6.3970e-04 3.1493e-03 - 4.1500e-03 -8.2974e+00 1.6839e-01 8.3161e-01 9.0901e-01 9.0987e-02 1.1690e-04 3.6821e-03 6.3970e-04 3.1593e-03 - 4.1600e-03 -8.2974e+00 1.6794e-01 8.3206e-01 9.0901e-01 9.0987e-02 1.1523e-04 3.6938e-03 6.3970e-04 3.1693e-03 - 4.1700e-03 -8.2974e+00 1.6750e-01 8.3250e-01 9.0901e-01 9.0987e-02 1.1357e-04 3.7054e-03 6.3970e-04 3.1793e-03 - 4.1800e-03 -8.2974e+00 1.6707e-01 8.3293e-01 9.0901e-01 9.0987e-02 1.1190e-04 3.7171e-03 6.3970e-04 3.1893e-03 - 4.1900e-03 -8.2974e+00 1.6663e-01 8.3337e-01 9.0901e-01 9.0987e-02 1.1023e-04 3.7288e-03 6.3970e-04 3.1993e-03 - 4.2000e-03 -8.2974e+00 1.6620e-01 8.3380e-01 9.0901e-01 9.0987e-02 1.0857e-04 3.7404e-03 6.3970e-04 3.2093e-03 - 4.2100e-03 -8.2974e+00 1.6577e-01 8.3423e-01 9.0901e-01 9.0987e-02 1.0690e-04 3.7521e-03 6.3970e-04 3.2193e-03 - 4.2200e-03 -8.2974e+00 1.6534e-01 8.3466e-01 9.0901e-01 9.0987e-02 1.0524e-04 3.7638e-03 6.3970e-04 3.2293e-03 - 4.2300e-03 -8.2974e+00 1.6491e-01 8.3509e-01 9.0901e-01 9.0987e-02 1.0357e-04 3.7754e-03 6.3970e-04 3.2393e-03 - 4.2400e-03 -8.2974e+00 1.6449e-01 8.3551e-01 9.0901e-01 9.0987e-02 1.0190e-04 3.7871e-03 6.3970e-04 3.2493e-03 - 4.2500e-03 -8.2974e+00 1.6407e-01 8.3593e-01 9.0901e-01 9.0987e-02 1.0024e-04 3.7988e-03 6.3970e-04 3.2593e-03 - 4.2600e-03 -8.2974e+00 1.6365e-01 8.3635e-01 9.0901e-01 9.0987e-02 9.8571e-05 3.8104e-03 6.3970e-04 3.2693e-03 - 4.2700e-03 -8.2974e+00 1.6323e-01 8.3677e-01 9.0901e-01 9.0987e-02 9.6905e-05 3.8221e-03 6.3970e-04 3.2793e-03 - 4.2800e-03 -8.2974e+00 1.6282e-01 8.3718e-01 9.0901e-01 9.0987e-02 9.5238e-05 3.8338e-03 6.3970e-04 3.2893e-03 - 4.2900e-03 -8.2974e+00 1.6240e-01 8.3760e-01 9.0901e-01 9.0987e-02 9.3572e-05 3.8454e-03 6.3970e-04 3.2993e-03 - 4.3000e-03 -8.2974e+00 1.6199e-01 8.3801e-01 9.0901e-01 9.0987e-02 9.1906e-05 3.8571e-03 6.3970e-04 3.3093e-03 - 4.3100e-03 -8.2974e+00 1.6158e-01 8.3842e-01 9.0901e-01 9.0987e-02 9.0240e-05 3.8688e-03 6.3970e-04 3.3193e-03 - 4.3200e-03 -8.2974e+00 1.6117e-01 8.3883e-01 9.0901e-01 9.0987e-02 8.8574e-05 3.8804e-03 6.3970e-04 3.3293e-03 - 4.3300e-03 -8.2974e+00 1.6077e-01 8.3923e-01 9.0901e-01 9.0987e-02 8.6907e-05 3.8921e-03 6.3970e-04 3.3393e-03 - 4.3400e-03 -8.2974e+00 1.6037e-01 8.3963e-01 9.0901e-01 9.0987e-02 8.5241e-05 3.9038e-03 6.3970e-04 3.3493e-03 - 4.3500e-03 -8.2974e+00 1.5997e-01 8.4003e-01 9.0901e-01 9.0987e-02 8.3575e-05 3.9154e-03 6.3970e-04 3.3593e-03 - 4.3600e-03 -8.2974e+00 1.5957e-01 8.4043e-01 9.0901e-01 9.0987e-02 8.1909e-05 3.9271e-03 6.3970e-04 3.3693e-03 - 4.3700e-03 -8.2974e+00 1.5917e-01 8.4083e-01 9.0901e-01 9.0987e-02 8.0243e-05 3.9388e-03 6.3970e-04 3.3793e-03 - 4.3800e-03 -8.2974e+00 1.5877e-01 8.4123e-01 9.0901e-01 9.0987e-02 7.8576e-05 3.9504e-03 6.3970e-04 3.3893e-03 - 4.3900e-03 -8.2974e+00 1.5838e-01 8.4162e-01 9.0901e-01 9.0987e-02 7.6910e-05 3.9621e-03 6.3970e-04 3.3993e-03 - 4.4000e-03 -8.2974e+00 1.5799e-01 8.4201e-01 9.0901e-01 9.0987e-02 7.5244e-05 3.9738e-03 6.3970e-04 3.4093e-03 - 4.4100e-03 -8.2974e+00 1.5760e-01 8.4240e-01 9.0901e-01 9.0987e-02 7.3578e-05 3.9854e-03 6.3970e-04 3.4193e-03 - 4.4200e-03 -8.2974e+00 1.5721e-01 8.4279e-01 9.0901e-01 9.0987e-02 7.1912e-05 3.9971e-03 6.3970e-04 3.4293e-03 - 4.4300e-03 -8.2974e+00 1.5683e-01 8.4317e-01 9.0901e-01 9.0987e-02 7.0245e-05 4.0088e-03 6.3970e-04 3.4393e-03 - 4.4400e-03 -8.2974e+00 1.5644e-01 8.4356e-01 9.0901e-01 9.0987e-02 6.8579e-05 4.0204e-03 6.3970e-04 3.4493e-03 - 4.4500e-03 -8.2974e+00 1.5606e-01 8.4394e-01 9.0901e-01 9.0987e-02 6.6913e-05 4.0321e-03 6.3970e-04 3.4593e-03 - 4.4600e-03 -8.2974e+00 1.5568e-01 8.4432e-01 9.0901e-01 9.0987e-02 6.5247e-05 4.0438e-03 6.3970e-04 3.4693e-03 - 4.4700e-03 -8.2974e+00 1.5530e-01 8.4470e-01 9.0901e-01 9.0987e-02 6.3581e-05 4.0554e-03 6.3970e-04 3.4793e-03 - 4.4800e-03 -8.2974e+00 1.5493e-01 8.4507e-01 9.0901e-01 9.0987e-02 6.1914e-05 4.0671e-03 6.3970e-04 3.4893e-03 - 4.4900e-03 -8.2974e+00 1.5455e-01 8.4545e-01 9.0901e-01 9.0987e-02 6.0248e-05 4.0788e-03 6.3970e-04 3.4993e-03 - 4.5000e-03 -8.2974e+00 1.5418e-01 8.4582e-01 9.0901e-01 9.0987e-02 5.8582e-05 4.0904e-03 6.3970e-04 3.5093e-03 - 4.5100e-03 -8.2974e+00 1.5381e-01 8.4619e-01 9.0901e-01 9.0987e-02 5.6916e-05 4.1021e-03 6.3970e-04 3.5193e-03 - 4.5200e-03 -8.2974e+00 1.5344e-01 8.4656e-01 9.0901e-01 9.0987e-02 5.5250e-05 4.1138e-03 6.3970e-04 3.5293e-03 - 4.5300e-03 -8.2974e+00 1.5307e-01 8.4693e-01 9.0901e-01 9.0987e-02 5.3583e-05 4.1254e-03 6.3970e-04 3.5393e-03 - 4.5400e-03 -8.2974e+00 1.5271e-01 8.4729e-01 9.0901e-01 9.0987e-02 5.1917e-05 4.1371e-03 6.3970e-04 3.5493e-03 - 4.5500e-03 -8.2974e+00 1.5235e-01 8.4765e-01 9.0901e-01 9.0987e-02 5.0251e-05 4.1487e-03 6.3970e-04 3.5593e-03 - 4.5600e-03 -8.2974e+00 1.5198e-01 8.4802e-01 9.0901e-01 9.0987e-02 4.8585e-05 4.1604e-03 6.3970e-04 3.5693e-03 - 4.5700e-03 -8.2974e+00 1.5162e-01 8.4838e-01 9.0901e-01 9.0987e-02 4.6919e-05 4.1721e-03 6.3970e-04 3.5793e-03 - 4.5800e-03 -8.2974e+00 1.5127e-01 8.4873e-01 9.0901e-01 9.0987e-02 4.5252e-05 4.1837e-03 6.3970e-04 3.5893e-03 - 4.5900e-03 -8.2974e+00 1.5091e-01 8.4909e-01 9.0901e-01 9.0987e-02 4.3586e-05 4.1954e-03 6.3970e-04 3.5993e-03 - 4.6000e-03 -8.2974e+00 1.5055e-01 8.4945e-01 9.0901e-01 9.0987e-02 4.1920e-05 4.2071e-03 6.3970e-04 3.6093e-03 - 4.6100e-03 -8.2974e+00 1.5020e-01 8.4980e-01 9.0901e-01 9.0987e-02 4.0254e-05 4.2187e-03 6.3970e-04 3.6193e-03 - 4.6200e-03 -8.2974e+00 1.4985e-01 8.5015e-01 9.0901e-01 9.0987e-02 3.8588e-05 4.2304e-03 6.3970e-04 3.6293e-03 - 4.6300e-03 -8.2974e+00 1.4950e-01 8.5050e-01 9.0901e-01 9.0987e-02 3.6921e-05 4.2421e-03 6.3970e-04 3.6393e-03 - 4.6400e-03 -8.2974e+00 1.4915e-01 8.5085e-01 9.0901e-01 9.0987e-02 3.5255e-05 4.2537e-03 6.3970e-04 3.6493e-03 - 4.6500e-03 -8.2974e+00 1.4880e-01 8.5120e-01 9.0901e-01 9.0987e-02 3.3589e-05 4.2654e-03 6.3970e-04 3.6593e-03 - 4.6600e-03 -8.2974e+00 1.4846e-01 8.5154e-01 9.0901e-01 9.0987e-02 3.1923e-05 4.2771e-03 6.3970e-04 3.6693e-03 - 4.6700e-03 -8.2974e+00 1.4811e-01 8.5189e-01 9.0901e-01 9.0987e-02 3.0257e-05 4.2887e-03 6.3970e-04 3.6793e-03 - 4.6800e-03 -8.2974e+00 1.4777e-01 8.5223e-01 9.0901e-01 9.0987e-02 2.8590e-05 4.3004e-03 6.3970e-04 3.6893e-03 - 4.6900e-03 -8.2974e+00 1.4743e-01 8.5257e-01 9.0901e-01 9.0987e-02 2.6924e-05 4.3121e-03 6.3970e-04 3.6993e-03 - 4.7000e-03 -8.2974e+00 1.4709e-01 8.5291e-01 9.0901e-01 9.0987e-02 2.5258e-05 4.3237e-03 6.3970e-04 3.7093e-03 - 4.7100e-03 -8.2974e+00 1.4675e-01 8.5325e-01 9.0901e-01 9.0987e-02 2.3592e-05 4.3354e-03 6.3970e-04 3.7193e-03 - 4.7200e-03 -8.2974e+00 1.4642e-01 8.5358e-01 9.0901e-01 9.0987e-02 2.1926e-05 4.3471e-03 6.3970e-04 3.7293e-03 - 4.7300e-03 -8.2974e+00 1.4608e-01 8.5392e-01 9.0901e-01 9.0987e-02 2.0259e-05 4.3587e-03 6.3970e-04 3.7393e-03 - 4.7400e-03 -8.2974e+00 1.4575e-01 8.5425e-01 9.0901e-01 9.0987e-02 1.8593e-05 4.3704e-03 6.3970e-04 3.7493e-03 - 4.7500e-03 -8.2974e+00 1.4542e-01 8.5458e-01 9.0901e-01 9.0987e-02 1.6927e-05 4.3821e-03 6.3970e-04 3.7593e-03 - 4.7600e-03 -8.2974e+00 1.4509e-01 8.5491e-01 9.0901e-01 9.0987e-02 1.5261e-05 4.3937e-03 6.3970e-04 3.7693e-03 - 4.7700e-03 -8.2974e+00 1.4476e-01 8.5524e-01 9.0901e-01 9.0987e-02 1.3595e-05 4.4054e-03 6.3970e-04 3.7793e-03 - 4.7800e-03 -8.2974e+00 1.4443e-01 8.5557e-01 9.0901e-01 9.0987e-02 1.1928e-05 4.4171e-03 6.3970e-04 3.7893e-03 - 4.7900e-03 -8.2974e+00 1.4411e-01 8.5589e-01 9.0901e-01 9.0987e-02 1.0262e-05 4.4287e-03 6.3970e-04 3.7993e-03 - 4.8000e-03 -8.2974e+00 1.4379e-01 8.5621e-01 9.0901e-01 9.0987e-02 8.5959e-06 4.4404e-03 6.3970e-04 3.8093e-03 - 4.8100e-03 -8.2974e+00 1.4346e-01 8.5654e-01 9.0901e-01 9.0987e-02 6.9297e-06 4.4521e-03 6.3970e-04 3.8193e-03 - 4.8200e-03 -8.2974e+00 1.4314e-01 8.5686e-01 9.0901e-01 9.0987e-02 5.2635e-06 4.4637e-03 6.3970e-04 3.8293e-03 - 4.8300e-03 -8.2974e+00 1.4282e-01 8.5718e-01 9.0901e-01 9.0987e-02 3.5973e-06 4.4754e-03 6.3970e-04 3.8393e-03 - 4.8400e-03 -8.2974e+00 1.4250e-01 8.5750e-01 9.0901e-01 9.0987e-02 1.9311e-06 4.4871e-03 6.3970e-04 3.8493e-03 - 4.8500e-03 -8.2974e+00 1.4219e-01 8.5781e-01 9.0901e-01 9.0987e-02 2.6493e-07 4.4987e-03 6.3970e-04 3.8593e-03 - 4.8600e-03 -8.2975e+00 1.4210e-01 8.5790e-01 9.0899e-01 9.1014e-02 1.0000e-10 1.0000e-10 6.4087e-04 3.8691e-03 - 4.8700e-03 -8.2976e+00 1.4206e-01 8.5794e-01 9.0895e-01 9.1046e-02 1.0000e-10 1.0000e-10 6.4227e-04 3.8789e-03 - 4.8800e-03 -8.2977e+00 1.4202e-01 8.5798e-01 9.0892e-01 9.1078e-02 1.0000e-10 1.0000e-10 6.4366e-04 3.8886e-03 - 4.8900e-03 -8.2979e+00 1.4197e-01 8.5803e-01 9.0889e-01 9.1110e-02 1.0000e-10 1.0000e-10 6.4505e-04 3.8984e-03 - 4.9000e-03 -8.2980e+00 1.4193e-01 8.5807e-01 9.0886e-01 9.1142e-02 1.0000e-10 1.0000e-10 6.4644e-04 3.9081e-03 - 4.9100e-03 -8.2981e+00 1.4189e-01 8.5811e-01 9.0883e-01 9.1174e-02 1.0000e-10 1.0000e-10 6.4783e-04 3.9179e-03 - 4.9200e-03 -8.2982e+00 1.4185e-01 8.5815e-01 9.0879e-01 9.1206e-02 1.0000e-10 1.0000e-10 6.4922e-04 3.9276e-03 - 4.9300e-03 -8.2984e+00 1.4181e-01 8.5819e-01 9.0876e-01 9.1238e-02 1.0000e-10 1.0000e-10 6.5060e-04 3.9374e-03 - 4.9400e-03 -8.2985e+00 1.4176e-01 8.5824e-01 9.0873e-01 9.1270e-02 1.0000e-10 1.0000e-10 6.5199e-04 3.9471e-03 - 4.9500e-03 -8.2986e+00 1.4172e-01 8.5828e-01 9.0870e-01 9.1302e-02 1.0000e-10 1.0000e-10 6.5338e-04 3.9569e-03 - 4.9600e-03 -8.2988e+00 1.4168e-01 8.5832e-01 9.0867e-01 9.1334e-02 1.0000e-10 1.0000e-10 6.5476e-04 3.9667e-03 - 4.9700e-03 -8.2989e+00 1.4164e-01 8.5836e-01 9.0863e-01 9.1366e-02 1.0000e-10 1.0000e-10 6.5615e-04 3.9764e-03 - 4.9800e-03 -8.2990e+00 1.4160e-01 8.5840e-01 9.0860e-01 9.1398e-02 1.0000e-10 1.0000e-10 6.5753e-04 3.9862e-03 - 4.9900e-03 -8.2991e+00 1.4155e-01 8.5845e-01 9.0857e-01 9.1429e-02 1.0000e-10 1.0000e-10 6.5891e-04 3.9959e-03 - 5.0000e-03 -8.2993e+00 1.4151e-01 8.5849e-01 9.0854e-01 9.1461e-02 1.0000e-10 1.0000e-10 6.6029e-04 4.0057e-03 - 1.0000e-03 -8.2974e+00 9.8567e-01 1.4329e-02 9.0901e-01 9.0987e-02 6.4175e-04 7.2473e-06 6.3970e-04 9.2997e-06 - 2.0000e-03 -8.2974e+00 3.8793e-01 6.1207e-01 9.0901e-01 9.0987e-02 4.7513e-04 1.1739e-03 6.3970e-04 1.0093e-03 - 3.0000e-03 -8.2974e+00 2.4149e-01 7.5851e-01 9.0901e-01 9.0987e-02 3.0851e-04 2.3405e-03 6.3970e-04 2.0093e-03 - 4.0000e-03 -8.2974e+00 1.7531e-01 8.2469e-01 9.0901e-01 9.0987e-02 1.4189e-04 3.5071e-03 6.3970e-04 3.0093e-03 - 5.0000e-03 -8.2993e+00 1.4151e-01 8.5849e-01 9.0854e-01 9.1461e-02 1.0000e-10 1.0000e-10 6.6029e-04 4.0057e-03 - 6.0000e-03 -8.3118e+00 1.3751e-01 8.6249e-01 9.0539e-01 9.4606e-02 1.0000e-10 1.0000e-10 7.9428e-04 4.9819e-03 - 7.0000e-03 -8.3236e+00 1.3383e-01 8.6617e-01 9.0233e-01 9.7673e-02 1.0000e-10 1.0000e-10 9.2071e-04 5.9590e-03 - 8.0000e-03 -8.3349e+00 1.3043e-01 8.6957e-01 8.9933e-01 1.0067e-01 1.0000e-10 1.0000e-10 1.0405e-03 6.9369e-03 - 9.0000e-03 -8.3456e+00 1.2726e-01 8.7274e-01 8.9640e-01 1.0360e-01 1.0000e-10 1.0000e-10 1.1543e-03 7.9155e-03 - 1.0000e-02 -8.3559e+00 1.2431e-01 8.7569e-01 8.9352e-01 1.0648e-01 1.0000e-10 1.0000e-10 1.2627e-03 8.8947e-03 - 1.1000e-02 -8.3658e+00 1.2155e-01 8.7845e-01 8.9070e-01 1.0930e-01 1.0000e-10 1.0000e-10 1.3663e-03 9.8746e-03 - 1.2000e-02 -8.3752e+00 1.1895e-01 8.8105e-01 8.8792e-01 1.1208e-01 1.0000e-10 1.0000e-10 1.4655e-03 1.0855e-02 - 1.3000e-02 -8.3843e+00 1.1650e-01 8.8350e-01 8.8519e-01 1.1481e-01 1.0000e-10 1.0000e-10 1.5607e-03 1.1836e-02 - 1.4000e-02 -8.3931e+00 1.1419e-01 8.8581e-01 8.8251e-01 1.1749e-01 1.0000e-10 1.0000e-10 1.6522e-03 1.2817e-02 - 1.5000e-02 -8.4016e+00 1.1199e-01 8.8801e-01 8.7986e-01 1.2014e-01 1.0000e-10 1.0000e-10 1.7403e-03 1.3799e-02 - 1.6000e-02 -8.4098e+00 1.0991e-01 8.9009e-01 8.7725e-01 1.2275e-01 1.0000e-10 1.0000e-10 1.8252e-03 1.4781e-02 - 1.7000e-02 -8.4178e+00 1.0793e-01 8.9207e-01 8.7468e-01 1.2532e-01 1.0000e-10 1.0000e-10 1.9072e-03 1.5764e-02 - 1.8000e-02 -8.4254e+00 1.0604e-01 8.9396e-01 8.7214e-01 1.2786e-01 1.0000e-10 1.0000e-10 1.9864e-03 1.6746e-02 - 1.9000e-02 -8.4329e+00 1.0423e-01 8.9577e-01 8.6963e-01 1.3037e-01 1.0000e-10 1.0000e-10 2.0631e-03 1.7730e-02 - 2.0000e-02 -8.4401e+00 1.0251e-01 8.9749e-01 8.6716e-01 1.3284e-01 1.0000e-10 1.0000e-10 2.1374e-03 1.8713e-02 - 2.1000e-02 -8.4472e+00 1.0086e-01 8.9914e-01 8.6471e-01 1.3529e-01 1.0000e-10 1.0000e-10 2.2094e-03 1.9697e-02 - 2.2000e-02 -8.4540e+00 9.9270e-02 9.0073e-01 8.6230e-01 1.3770e-01 1.0000e-10 1.0000e-10 2.2793e-03 2.0681e-02 - 2.3000e-02 -8.4607e+00 9.7747e-02 9.0225e-01 8.5991e-01 1.4009e-01 1.0000e-10 1.0000e-10 2.3472e-03 2.1666e-02 - 2.4000e-02 -8.4672e+00 9.6283e-02 9.0372e-01 8.5754e-01 1.4246e-01 1.0000e-10 1.0000e-10 2.4132e-03 2.2650e-02 - 2.5000e-02 -8.4735e+00 9.4874e-02 9.0513e-01 8.5520e-01 1.4480e-01 1.0000e-10 1.0000e-10 2.4774e-03 2.3635e-02 - 2.6000e-02 -8.4797e+00 9.3517e-02 9.0648e-01 8.5289e-01 1.4711e-01 1.0000e-10 1.0000e-10 2.5400e-03 2.4621e-02 - 2.7000e-02 -8.4857e+00 9.2208e-02 9.0779e-01 8.5060e-01 1.4940e-01 1.0000e-10 1.0000e-10 2.6009e-03 2.5606e-02 - 2.8000e-02 -8.4915e+00 9.0944e-02 9.0906e-01 8.4833e-01 1.5167e-01 1.0000e-10 1.0000e-10 2.6603e-03 2.6592e-02 - 2.9000e-02 -8.4973e+00 8.9723e-02 9.1028e-01 8.4608e-01 1.5392e-01 1.0000e-10 1.0000e-10 2.7182e-03 2.7578e-02 - 3.0000e-02 -8.5029e+00 8.8542e-02 9.1146e-01 8.4386e-01 1.5614e-01 1.0000e-10 1.0000e-10 2.7748e-03 2.8564e-02 - 3.1000e-02 -8.5084e+00 8.7400e-02 9.1260e-01 8.4166e-01 1.5834e-01 1.0000e-10 1.0000e-10 2.8300e-03 2.9550e-02 - 3.2000e-02 -8.5137e+00 8.6294e-02 9.1371e-01 8.3947e-01 1.6053e-01 1.0000e-10 1.0000e-10 2.8840e-03 3.0536e-02 - 3.3000e-02 -8.5190e+00 8.5221e-02 9.1478e-01 8.3731e-01 1.6269e-01 1.0000e-10 1.0000e-10 2.9367e-03 3.1523e-02 - 3.4000e-02 -8.5241e+00 8.4182e-02 9.1582e-01 8.3516e-01 1.6484e-01 1.0000e-10 1.0000e-10 2.9883e-03 3.2510e-02 - 3.5000e-02 -8.5292e+00 8.3173e-02 9.1683e-01 8.3304e-01 1.6696e-01 1.0000e-10 1.0000e-10 3.0388e-03 3.3497e-02 - 3.6000e-02 -8.5341e+00 8.2193e-02 9.1781e-01 8.3093e-01 1.6907e-01 1.0000e-10 1.0000e-10 3.0882e-03 3.4484e-02 - 3.7000e-02 -8.5390e+00 8.1241e-02 9.1876e-01 8.2884e-01 1.7116e-01 1.0000e-10 1.0000e-10 3.1366e-03 3.5472e-02 - 3.8000e-02 -8.5437e+00 8.0316e-02 9.1968e-01 8.2677e-01 1.7323e-01 1.0000e-10 1.0000e-10 3.1840e-03 3.6459e-02 - 3.9000e-02 -8.5484e+00 7.9416e-02 9.2058e-01 8.2471e-01 1.7529e-01 1.0000e-10 1.0000e-10 3.2304e-03 3.7447e-02 - 4.0000e-02 -8.5529e+00 7.8540e-02 9.2146e-01 8.2267e-01 1.7733e-01 1.0000e-10 1.0000e-10 3.2760e-03 3.8435e-02 - 4.1000e-02 -8.5574e+00 7.7688e-02 9.2231e-01 8.2065e-01 1.7935e-01 1.0000e-10 1.0000e-10 3.3206e-03 3.9423e-02 - 4.2000e-02 -8.5618e+00 7.6857e-02 9.2314e-01 8.1865e-01 1.8135e-01 1.0000e-10 1.0000e-10 3.3645e-03 4.0411e-02 - 4.3000e-02 -8.5662e+00 7.6048e-02 9.2395e-01 8.1665e-01 1.8335e-01 1.0000e-10 1.0000e-10 3.4075e-03 4.1399e-02 - 4.4000e-02 -8.5704e+00 7.5259e-02 9.2474e-01 8.1468e-01 1.8532e-01 1.0000e-10 1.0000e-10 3.4497e-03 4.2388e-02 - 4.5000e-02 -8.5746e+00 7.4489e-02 9.2551e-01 8.1272e-01 1.8728e-01 1.0000e-10 1.0000e-10 3.4911e-03 4.3376e-02 - 4.6000e-02 -8.5787e+00 7.3738e-02 9.2626e-01 8.1077e-01 1.8923e-01 1.0000e-10 1.0000e-10 3.5318e-03 4.4365e-02 - 4.7000e-02 -8.5827e+00 7.3005e-02 9.2699e-01 8.0884e-01 1.9116e-01 1.0000e-10 1.0000e-10 3.5718e-03 4.5354e-02 - 4.8000e-02 -8.5867e+00 7.2290e-02 9.2771e-01 8.0692e-01 1.9308e-01 1.0000e-10 1.0000e-10 3.6111e-03 4.6343e-02 - 4.9000e-02 -8.5906e+00 7.1590e-02 9.2841e-01 8.0502e-01 1.9498e-01 1.0000e-10 1.0000e-10 3.6498e-03 4.7332e-02 - 5.0000e-02 -8.5945e+00 7.0907e-02 9.2909e-01 8.0313e-01 1.9687e-01 1.0000e-10 1.0000e-10 3.6878e-03 4.8321e-02 - 5.1000e-02 -8.5982e+00 7.0239e-02 9.2976e-01 8.0125e-01 1.9875e-01 1.0000e-10 1.0000e-10 3.7252e-03 4.9310e-02 - 5.2000e-02 -8.6020e+00 6.9586e-02 9.3041e-01 7.9939e-01 2.0061e-01 1.0000e-10 1.0000e-10 3.7619e-03 5.0300e-02 - 5.3000e-02 -8.6056e+00 6.8947e-02 9.3105e-01 7.9753e-01 2.0247e-01 1.0000e-10 1.0000e-10 3.7981e-03 5.1289e-02 - 5.4000e-02 -8.6092e+00 6.8322e-02 9.3168e-01 7.9570e-01 2.0430e-01 1.0000e-10 1.0000e-10 3.8337e-03 5.2279e-02 - 5.5000e-02 -8.6128e+00 6.7710e-02 9.3229e-01 7.9387e-01 2.0613e-01 1.0000e-10 1.0000e-10 3.8688e-03 5.3269e-02 - 5.6000e-02 -8.6163e+00 6.7111e-02 9.3289e-01 7.9206e-01 2.0794e-01 1.0000e-10 1.0000e-10 3.9033e-03 5.4258e-02 - 5.7000e-02 -8.6198e+00 6.6524e-02 9.3348e-01 7.9026e-01 2.0974e-01 1.0000e-10 1.0000e-10 3.9373e-03 5.5248e-02 - 5.8000e-02 -8.6232e+00 6.5950e-02 9.3405e-01 7.8847e-01 2.1153e-01 1.0000e-10 1.0000e-10 3.9708e-03 5.6238e-02 - 5.9000e-02 -8.6265e+00 6.5386e-02 9.3461e-01 7.8669e-01 2.1331e-01 1.0000e-10 1.0000e-10 4.0037e-03 5.7228e-02 - 6.0000e-02 -8.6298e+00 6.4834e-02 9.3517e-01 7.8492e-01 2.1508e-01 1.0000e-10 1.0000e-10 4.0362e-03 5.8219e-02 - 6.1000e-02 -8.6331e+00 6.4293e-02 9.3571e-01 7.8317e-01 2.1683e-01 1.0000e-10 1.0000e-10 4.0683e-03 5.9209e-02 - 6.2000e-02 -8.6363e+00 6.3762e-02 9.3624e-01 7.8142e-01 2.1858e-01 1.0000e-10 1.0000e-10 4.0999e-03 6.0199e-02 - 6.3000e-02 -8.6395e+00 6.3242e-02 9.3676e-01 7.7969e-01 2.2031e-01 1.0000e-10 1.0000e-10 4.1310e-03 6.1190e-02 - 6.4000e-02 -8.6426e+00 6.2731e-02 9.3727e-01 7.7797e-01 2.2203e-01 1.0000e-10 1.0000e-10 4.1617e-03 6.2180e-02 - 6.5000e-02 -8.6457e+00 6.2230e-02 9.3777e-01 7.7626e-01 2.2374e-01 1.0000e-10 1.0000e-10 4.1920e-03 6.3171e-02 - 6.6000e-02 -8.6487e+00 6.1738e-02 9.3826e-01 7.7456e-01 2.2544e-01 1.0000e-10 1.0000e-10 4.2218e-03 6.4162e-02 - 6.7000e-02 -8.6517e+00 6.1255e-02 9.3875e-01 7.7287e-01 2.2713e-01 1.0000e-10 1.0000e-10 4.2513e-03 6.5153e-02 - 6.8000e-02 -8.6547e+00 6.0780e-02 9.3922e-01 7.7119e-01 2.2881e-01 1.0000e-10 1.0000e-10 4.2804e-03 6.6144e-02 - 6.9000e-02 -8.6576e+00 6.0314e-02 9.3969e-01 7.6952e-01 2.3048e-01 1.0000e-10 1.0000e-10 4.3091e-03 6.7135e-02 - 7.0000e-02 -8.6605e+00 5.9857e-02 9.4014e-01 7.6786e-01 2.3214e-01 1.0000e-10 1.0000e-10 4.3374e-03 6.8126e-02 - 7.1000e-02 -8.6634e+00 5.9407e-02 9.4059e-01 7.6621e-01 2.3379e-01 1.0000e-10 1.0000e-10 4.3654e-03 6.9117e-02 - 7.2000e-02 -8.6662e+00 5.8965e-02 9.4103e-01 7.6457e-01 2.3543e-01 1.0000e-10 1.0000e-10 4.3930e-03 7.0108e-02 - 7.3000e-02 -8.6690e+00 5.8531e-02 9.4147e-01 7.6294e-01 2.3706e-01 1.0000e-10 1.0000e-10 4.4202e-03 7.1099e-02 - 7.4000e-02 -8.6718e+00 5.8104e-02 9.4190e-01 7.6132e-01 2.3868e-01 1.0000e-10 1.0000e-10 4.4471e-03 7.2091e-02 - 7.5000e-02 -8.6745e+00 5.7684e-02 9.4232e-01 7.5970e-01 2.4030e-01 1.0000e-10 1.0000e-10 4.4737e-03 7.3082e-02 - 7.6000e-02 -8.6772e+00 5.7271e-02 9.4273e-01 7.5810e-01 2.4190e-01 1.0000e-10 1.0000e-10 4.5000e-03 7.4074e-02 - 7.7000e-02 -8.6798e+00 5.6864e-02 9.4314e-01 7.5651e-01 2.4349e-01 1.0000e-10 1.0000e-10 4.5259e-03 7.5065e-02 - 7.8000e-02 -8.6824e+00 5.6465e-02 9.4354e-01 7.5492e-01 2.4508e-01 1.0000e-10 1.0000e-10 4.5515e-03 7.6057e-02 - 7.9000e-02 -8.6850e+00 5.6071e-02 9.4393e-01 7.5335e-01 2.4665e-01 1.0000e-10 1.0000e-10 4.5769e-03 7.7049e-02 - 8.0000e-02 -8.6876e+00 5.5684e-02 9.4432e-01 7.5178e-01 2.4822e-01 1.0000e-10 1.0000e-10 4.6019e-03 7.8040e-02 - 8.1000e-02 -8.6901e+00 5.5303e-02 9.4470e-01 7.5023e-01 2.4977e-01 1.0000e-10 1.0000e-10 4.6266e-03 7.9032e-02 - 8.2000e-02 -8.6926e+00 5.4928e-02 9.4507e-01 7.4868e-01 2.5132e-01 1.0000e-10 1.0000e-10 4.6511e-03 8.0024e-02 - 8.3000e-02 -8.6951e+00 5.4559e-02 9.4544e-01 7.4714e-01 2.5286e-01 1.0000e-10 1.0000e-10 4.6752e-03 8.1016e-02 - 8.4000e-02 -8.6976e+00 5.4196e-02 9.4580e-01 7.4560e-01 2.5440e-01 1.0000e-10 1.0000e-10 4.6991e-03 8.2008e-02 - 8.5000e-02 -8.7000e+00 5.3837e-02 9.4616e-01 7.4408e-01 2.5592e-01 1.0000e-10 1.0000e-10 4.7228e-03 8.3000e-02 - 8.6000e-02 -8.7024e+00 5.3485e-02 9.4652e-01 7.4256e-01 2.5744e-01 1.0000e-10 1.0000e-10 4.7461e-03 8.3992e-02 - 8.7000e-02 -8.7047e+00 5.3137e-02 9.4686e-01 7.4106e-01 2.5894e-01 1.0000e-10 1.0000e-10 4.7693e-03 8.4984e-02 - 8.8000e-02 -8.7071e+00 5.2795e-02 9.4721e-01 7.3956e-01 2.6044e-01 1.0000e-10 1.0000e-10 4.7921e-03 8.5977e-02 - 8.9000e-02 -8.7094e+00 5.2457e-02 9.4754e-01 7.3807e-01 2.6193e-01 1.0000e-10 1.0000e-10 4.8147e-03 8.6969e-02 - 9.0000e-02 -8.7117e+00 5.2125e-02 9.4788e-01 7.3658e-01 2.6342e-01 1.0000e-10 1.0000e-10 4.8371e-03 8.7961e-02 - 9.1000e-02 -8.7140e+00 5.1797e-02 9.4820e-01 7.3511e-01 2.6489e-01 1.0000e-10 1.0000e-10 4.8592e-03 8.8954e-02 - 9.2000e-02 -8.7162e+00 5.1474e-02 9.4853e-01 7.3364e-01 2.6636e-01 1.0000e-10 1.0000e-10 4.8811e-03 8.9946e-02 - 9.3000e-02 -8.7185e+00 5.1155e-02 9.4884e-01 7.3218e-01 2.6782e-01 1.0000e-10 1.0000e-10 4.9028e-03 9.0939e-02 - 9.4000e-02 -8.7207e+00 5.0841e-02 9.4916e-01 7.3073e-01 2.6927e-01 1.0000e-10 1.0000e-10 4.9243e-03 9.1932e-02 - 9.5000e-02 -8.7228e+00 5.0531e-02 9.4947e-01 7.2928e-01 2.7072e-01 1.0000e-10 1.0000e-10 4.9455e-03 9.2924e-02 - 9.6000e-02 -8.7250e+00 5.0226e-02 9.4977e-01 7.2784e-01 2.7216e-01 1.0000e-10 1.0000e-10 4.9665e-03 9.3917e-02 - 9.7000e-02 -8.7271e+00 4.9924e-02 9.5008e-01 7.2641e-01 2.7359e-01 1.0000e-10 1.0000e-10 4.9873e-03 9.4910e-02 - 9.8000e-02 -8.7292e+00 4.9627e-02 9.5037e-01 7.2499e-01 2.7501e-01 1.0000e-10 1.0000e-10 5.0079e-03 9.5903e-02 - 9.9000e-02 -8.7313e+00 4.9334e-02 9.5067e-01 7.2357e-01 2.7643e-01 1.0000e-10 1.0000e-10 5.0283e-03 9.6895e-02 - 1.0000e-01 -8.7334e+00 4.9044e-02 9.5096e-01 7.2216e-01 2.7784e-01 1.0000e-10 1.0000e-10 5.0485e-03 9.7888e-02 - 1.0000e-01 -8.7334e+00 4.9044e-02 9.5096e-01 7.2216e-01 2.7784e-01 1.0000e-10 1.0000e-10 5.0485e-03 9.7888e-02 - 2.0000e-01 -8.8746e+00 3.1529e-02 9.6847e-01 6.0843e-01 3.9157e-01 1.0000e-10 1.0000e-10 6.4250e-03 1.9735e-01 - 3.0000e-01 -8.9515e+00 2.3611e-02 9.7639e-01 5.2912e-01 4.7088e-01 1.0000e-10 1.0000e-10 7.1824e-03 2.9701e-01 - 4.0000e-01 -9.0015e+00 1.8992e-02 9.8101e-01 4.6954e-01 5.3046e-01 1.0000e-10 1.0000e-10 7.6814e-03 3.9677e-01 - 5.0000e-01 -9.0371e+00 1.5935e-02 9.8407e-01 4.2272e-01 5.7728e-01 1.0000e-10 1.0000e-10 8.0411e-03 4.9659e-01 - 6.0000e-01 -9.0640e+00 1.3750e-02 9.8625e-01 3.8479e-01 6.1521e-01 1.0000e-10 1.0000e-10 8.3153e-03 5.9645e-01 - 7.0000e-01 -9.0851e+00 1.2105e-02 9.8790e-01 3.5335e-01 6.4665e-01 1.0000e-10 1.0000e-10 8.5323e-03 6.9633e-01 - 8.0000e-01 -9.1022e+00 1.0819e-02 9.8918e-01 3.2680e-01 6.7320e-01 1.0000e-10 1.0000e-10 8.7090e-03 7.9623e-01 - 9.0000e-01 -9.1162e+00 9.7855e-03 9.9021e-01 3.0406e-01 6.9594e-01 1.0000e-10 1.0000e-10 8.8560e-03 8.9615e-01 - 1.0000e+00 -9.1281e+00 8.9352e-03 9.9106e-01 2.8435e-01 7.1565e-01 1.0000e-10 1.0000e-10 8.9804e-03 9.9608e-01 - 1.1000e+00 -9.1382e+00 8.2229e-03 9.9178e-01 2.6708e-01 7.3292e-01 1.0000e-10 1.0000e-10 9.0872e-03 1.0960e+00 - 1.2000e+00 -9.1470e+00 7.6172e-03 9.9238e-01 2.5183e-01 7.4817e-01 1.0000e-10 1.0000e-10 9.1799e-03 1.1960e+00 - 1.3000e+00 -9.1547e+00 7.0957e-03 9.9290e-01 2.3825e-01 7.6175e-01 1.0000e-10 1.0000e-10 9.2612e-03 1.2959e+00 - 1.4000e+00 -9.1614e+00 6.6418e-03 9.9336e-01 2.2608e-01 7.7392e-01 1.0000e-10 1.0000e-10 9.3332e-03 1.3959e+00 - 1.5000e+00 -9.1674e+00 6.2431e-03 9.9376e-01 2.1511e-01 7.8489e-01 1.0000e-10 1.0000e-10 9.3973e-03 1.4958e+00 - 1.6000e+00 -9.1728e+00 5.8899e-03 9.9411e-01 2.0516e-01 7.9484e-01 1.0000e-10 1.0000e-10 9.4548e-03 1.5958e+00 - 1.7000e+00 -9.1776e+00 5.5749e-03 9.9443e-01 1.9610e-01 8.0390e-01 1.0000e-10 1.0000e-10 9.5068e-03 1.6958e+00 - 1.8000e+00 -9.1820e+00 5.2921e-03 9.9471e-01 1.8782e-01 8.1218e-01 1.0000e-10 1.0000e-10 9.5539e-03 1.7957e+00 - 1.9000e+00 -9.1860e+00 5.0369e-03 9.9496e-01 1.8021e-01 8.1979e-01 1.0000e-10 1.0000e-10 9.5968e-03 1.8957e+00 - 2.0000e+00 -9.1896e+00 4.8052e-03 9.9519e-01 1.7320e-01 8.2680e-01 1.0000e-10 1.0000e-10 9.6361e-03 1.9957e+00 - 2.1000e+00 -9.1929e+00 4.5941e-03 9.9541e-01 1.6672e-01 8.3328e-01 1.0000e-10 1.0000e-10 9.6722e-03 2.0957e+00 - 2.2000e+00 -9.1960e+00 4.4009e-03 9.9560e-01 1.6071e-01 8.3929e-01 1.0000e-10 1.0000e-10 9.7055e-03 2.1957e+00 - 2.3000e+00 -9.1988e+00 4.2233e-03 9.9578e-01 1.5512e-01 8.4488e-01 1.0000e-10 1.0000e-10 9.7364e-03 2.2956e+00 - 2.4000e+00 -9.2015e+00 4.0596e-03 9.9594e-01 1.4990e-01 8.5010e-01 1.0000e-10 1.0000e-10 9.7650e-03 2.3956e+00 - 2.5000e+00 -9.2039e+00 3.9082e-03 9.9609e-01 1.4503e-01 8.5497e-01 1.0000e-10 1.0000e-10 9.7916e-03 2.4956e+00 - 2.6000e+00 -9.2062e+00 3.7677e-03 9.9623e-01 1.4047e-01 8.5953e-01 1.0000e-10 1.0000e-10 9.8164e-03 2.5956e+00 - 2.7000e+00 -9.2083e+00 3.6370e-03 9.9636e-01 1.3618e-01 8.6382e-01 1.0000e-10 1.0000e-10 9.8396e-03 2.6956e+00 - 2.8000e+00 -9.2103e+00 3.5151e-03 9.9648e-01 1.3216e-01 8.6784e-01 1.0000e-10 1.0000e-10 9.8614e-03 2.7956e+00 - 2.9000e+00 -9.2122e+00 3.4011e-03 9.9660e-01 1.2836e-01 8.7164e-01 1.0000e-10 1.0000e-10 9.8818e-03 2.8955e+00 - 3.0000e+00 -9.2139e+00 3.2944e-03 9.9671e-01 1.2478e-01 8.7522e-01 1.0000e-10 1.0000e-10 9.9010e-03 2.9955e+00 - 3.1000e+00 -9.2156e+00 3.1941e-03 9.9681e-01 1.2139e-01 8.7861e-01 1.0000e-10 1.0000e-10 9.9191e-03 3.0955e+00 - 3.2000e+00 -9.2171e+00 3.0998e-03 9.9690e-01 1.1818e-01 8.8182e-01 1.0000e-10 1.0000e-10 9.9363e-03 3.1955e+00 - 3.3000e+00 -9.2186e+00 3.0109e-03 9.9699e-01 1.1514e-01 8.8486e-01 1.0000e-10 1.0000e-10 9.9524e-03 3.2955e+00 - 3.4000e+00 -9.2200e+00 2.9270e-03 9.9707e-01 1.1225e-01 8.8775e-01 1.0000e-10 1.0000e-10 9.9678e-03 3.3955e+00 - 3.5000e+00 -9.2213e+00 2.8476e-03 9.9715e-01 1.0950e-01 8.9050e-01 1.0000e-10 1.0000e-10 9.9823e-03 3.4955e+00 - 3.6000e+00 -9.2226e+00 2.7725e-03 9.9723e-01 1.0688e-01 8.9312e-01 1.0000e-10 1.0000e-10 9.9961e-03 3.5955e+00 - 3.7000e+00 -9.2238e+00 2.7012e-03 9.9730e-01 1.0439e-01 8.9561e-01 1.0000e-10 1.0000e-10 1.0009e-02 3.6955e+00 - 3.8000e+00 -9.2249e+00 2.6335e-03 9.9737e-01 1.0201e-01 8.9799e-01 1.0000e-10 1.0000e-10 1.0022e-02 3.7955e+00 - 3.9000e+00 -9.2260e+00 2.5691e-03 9.9743e-01 9.9738e-02 9.0026e-01 1.0000e-10 1.0000e-10 1.0034e-02 3.8955e+00 - 4.0000e+00 -9.2270e+00 2.5078e-03 9.9749e-01 9.7564e-02 9.0244e-01 1.0000e-10 1.0000e-10 1.0045e-02 3.9954e+00 - 4.1000e+00 -9.2280e+00 2.4494e-03 9.9755e-01 9.5483e-02 9.0452e-01 1.0000e-10 1.0000e-10 1.0056e-02 4.0954e+00 - 4.2000e+00 -9.2289e+00 2.3936e-03 9.9761e-01 9.3489e-02 9.0651e-01 1.0000e-10 1.0000e-10 1.0066e-02 4.1954e+00 - 4.3000e+00 -9.2298e+00 2.3404e-03 9.9766e-01 9.1577e-02 9.0842e-01 1.0000e-10 1.0000e-10 1.0076e-02 4.2954e+00 - 4.4000e+00 -9.2307e+00 2.2894e-03 9.9771e-01 8.9742e-02 9.1026e-01 1.0000e-10 1.0000e-10 1.0086e-02 4.3954e+00 - 4.5000e+00 -9.2315e+00 2.2406e-03 9.9776e-01 8.7979e-02 9.1202e-01 1.0000e-10 1.0000e-10 1.0095e-02 4.4954e+00 - 4.6000e+00 -9.2323e+00 2.1939e-03 9.9781e-01 8.6284e-02 9.1372e-01 1.0000e-10 1.0000e-10 1.0104e-02 4.5954e+00 - 4.7000e+00 -9.2331e+00 2.1491e-03 9.9785e-01 8.4653e-02 9.1535e-01 1.0000e-10 1.0000e-10 1.0112e-02 4.6954e+00 - 4.8000e+00 -9.2338e+00 2.1060e-03 9.9789e-01 8.3083e-02 9.1692e-01 1.0000e-10 1.0000e-10 1.0121e-02 4.7954e+00 - 4.9000e+00 -9.2345e+00 2.0647e-03 9.9794e-01 8.1570e-02 9.1843e-01 1.0000e-10 1.0000e-10 1.0128e-02 4.8954e+00 - 5.0000e+00 -9.2352e+00 2.0249e-03 9.9798e-01 8.0112e-02 9.1989e-01 1.0000e-10 1.0000e-10 1.0136e-02 4.9954e+00 - 5.1000e+00 -9.2359e+00 1.9867e-03 9.9801e-01 7.8704e-02 9.2130e-01 1.0000e-10 1.0000e-10 1.0143e-02 5.0954e+00 - 5.2000e+00 -9.2365e+00 1.9499e-03 9.9805e-01 7.7346e-02 9.2265e-01 1.0000e-10 1.0000e-10 1.0150e-02 5.1954e+00 - 5.3000e+00 -9.2371e+00 1.9144e-03 9.9809e-01 7.6033e-02 9.2397e-01 1.0000e-10 1.0000e-10 1.0157e-02 5.2954e+00 - 5.4000e+00 -9.2377e+00 1.8802e-03 9.9812e-01 7.4765e-02 9.2524e-01 1.0000e-10 1.0000e-10 1.0163e-02 5.3954e+00 - 5.5000e+00 -9.2383e+00 1.8472e-03 9.9815e-01 7.3538e-02 9.2646e-01 1.0000e-10 1.0000e-10 1.0170e-02 5.4954e+00 - 5.6000e+00 -9.2388e+00 1.8153e-03 9.9818e-01 7.2350e-02 9.2765e-01 1.0000e-10 1.0000e-10 1.0176e-02 5.5954e+00 - 5.7000e+00 -9.2393e+00 1.7845e-03 9.9822e-01 7.1201e-02 9.2880e-01 1.0000e-10 1.0000e-10 1.0182e-02 5.6954e+00 - 5.8000e+00 -9.2398e+00 1.7548e-03 9.9825e-01 7.0087e-02 9.2991e-01 1.0000e-10 1.0000e-10 1.0187e-02 5.7954e+00 - 5.9000e+00 -9.2403e+00 1.7260e-03 9.9827e-01 6.9008e-02 9.3099e-01 1.0000e-10 1.0000e-10 1.0193e-02 5.8954e+00 - 6.0000e+00 -9.2408e+00 1.6982e-03 9.9830e-01 6.7962e-02 9.3204e-01 1.0000e-10 1.0000e-10 1.0198e-02 5.9954e+00 - 6.1000e+00 -9.2413e+00 1.6712e-03 9.9833e-01 6.6947e-02 9.3305e-01 1.0000e-10 1.0000e-10 1.0204e-02 6.0953e+00 - 6.2000e+00 -9.2417e+00 1.6451e-03 9.9835e-01 6.5961e-02 9.3404e-01 1.0000e-10 1.0000e-10 1.0209e-02 6.1953e+00 - 6.3000e+00 -9.2422e+00 1.6198e-03 9.9838e-01 6.5005e-02 9.3500e-01 1.0000e-10 1.0000e-10 1.0213e-02 6.2953e+00 - 6.4000e+00 -9.2426e+00 1.5952e-03 9.9840e-01 6.4076e-02 9.3592e-01 1.0000e-10 1.0000e-10 1.0218e-02 6.3953e+00 - 6.5000e+00 -9.2430e+00 1.5714e-03 9.9843e-01 6.3173e-02 9.3683e-01 1.0000e-10 1.0000e-10 1.0223e-02 6.4953e+00 - 6.6000e+00 -9.2434e+00 1.5483e-03 9.9845e-01 6.2295e-02 9.3771e-01 1.0000e-10 1.0000e-10 1.0227e-02 6.5953e+00 - 6.7000e+00 -9.2438e+00 1.5258e-03 9.9847e-01 6.1441e-02 9.3856e-01 1.0000e-10 1.0000e-10 1.0232e-02 6.6953e+00 - 6.8000e+00 -9.2442e+00 1.5040e-03 9.9850e-01 6.0610e-02 9.3939e-01 1.0000e-10 1.0000e-10 1.0236e-02 6.7953e+00 - 6.9000e+00 -9.2446e+00 1.4829e-03 9.9852e-01 5.9802e-02 9.4020e-01 1.0000e-10 1.0000e-10 1.0240e-02 6.8953e+00 - 7.0000e+00 -9.2449e+00 1.4623e-03 9.9854e-01 5.9015e-02 9.4099e-01 1.0000e-10 1.0000e-10 1.0244e-02 6.9953e+00 - 7.1000e+00 -9.2453e+00 1.4422e-03 9.9856e-01 5.8248e-02 9.4175e-01 1.0000e-10 1.0000e-10 1.0248e-02 7.0953e+00 - 7.2000e+00 -9.2456e+00 1.4227e-03 9.9858e-01 5.7501e-02 9.4250e-01 1.0000e-10 1.0000e-10 1.0252e-02 7.1953e+00 - 7.3000e+00 -9.2459e+00 1.4038e-03 9.9860e-01 5.6773e-02 9.4323e-01 1.0000e-10 1.0000e-10 1.0255e-02 7.2953e+00 - 7.4000e+00 -9.2463e+00 1.3853e-03 9.9861e-01 5.6063e-02 9.4394e-01 1.0000e-10 1.0000e-10 1.0259e-02 7.3953e+00 - 7.5000e+00 -9.2466e+00 1.3673e-03 9.9863e-01 5.5370e-02 9.4463e-01 1.0000e-10 1.0000e-10 1.0262e-02 7.4953e+00 - 7.6000e+00 -9.2469e+00 1.3498e-03 9.9865e-01 5.4695e-02 9.4530e-01 1.0000e-10 1.0000e-10 1.0266e-02 7.5953e+00 - 7.7000e+00 -9.2472e+00 1.3327e-03 9.9867e-01 5.4036e-02 9.4596e-01 1.0000e-10 1.0000e-10 1.0269e-02 7.6953e+00 - 7.8000e+00 -9.2475e+00 1.3160e-03 9.9868e-01 5.3392e-02 9.4661e-01 1.0000e-10 1.0000e-10 1.0273e-02 7.7953e+00 - 7.9000e+00 -9.2478e+00 1.2998e-03 9.9870e-01 5.2764e-02 9.4724e-01 1.0000e-10 1.0000e-10 1.0276e-02 7.8953e+00 - 8.0000e+00 -9.2480e+00 1.2840e-03 9.9872e-01 5.2150e-02 9.4785e-01 1.0000e-10 1.0000e-10 1.0279e-02 7.9953e+00 - 8.1000e+00 -9.2483e+00 1.2685e-03 9.9873e-01 5.1551e-02 9.4845e-01 1.0000e-10 1.0000e-10 1.0282e-02 8.0953e+00 - 8.2000e+00 -9.2486e+00 1.2534e-03 9.9875e-01 5.0965e-02 9.4903e-01 1.0000e-10 1.0000e-10 1.0285e-02 8.1953e+00 - 8.3000e+00 -9.2488e+00 1.2386e-03 9.9876e-01 5.0392e-02 9.4961e-01 1.0000e-10 1.0000e-10 1.0288e-02 8.2953e+00 - 8.4000e+00 -9.2491e+00 1.2242e-03 9.9878e-01 4.9832e-02 9.5017e-01 1.0000e-10 1.0000e-10 1.0290e-02 8.3953e+00 - 8.5000e+00 -9.2493e+00 1.2102e-03 9.9879e-01 4.9285e-02 9.5072e-01 1.0000e-10 1.0000e-10 1.0293e-02 8.4953e+00 - 8.6000e+00 -9.2496e+00 1.1964e-03 9.9880e-01 4.8749e-02 9.5125e-01 1.0000e-10 1.0000e-10 1.0296e-02 8.5953e+00 - 8.7000e+00 -9.2498e+00 1.1830e-03 9.9882e-01 4.8225e-02 9.5178e-01 1.0000e-10 1.0000e-10 1.0299e-02 8.6953e+00 - 8.8000e+00 -9.2500e+00 1.1698e-03 9.9883e-01 4.7712e-02 9.5229e-01 1.0000e-10 1.0000e-10 1.0301e-02 8.7953e+00 - 8.9000e+00 -9.2503e+00 1.1570e-03 9.9884e-01 4.7209e-02 9.5279e-01 1.0000e-10 1.0000e-10 1.0304e-02 8.8953e+00 - 9.0000e+00 -9.2505e+00 1.1444e-03 9.9886e-01 4.6718e-02 9.5328e-01 1.0000e-10 1.0000e-10 1.0306e-02 8.9953e+00 - 9.1000e+00 -9.2507e+00 1.1321e-03 9.9887e-01 4.6236e-02 9.5376e-01 1.0000e-10 1.0000e-10 1.0309e-02 9.0953e+00 - 9.2000e+00 -9.2509e+00 1.1201e-03 9.9888e-01 4.5764e-02 9.5424e-01 1.0000e-10 1.0000e-10 1.0311e-02 9.1953e+00 - 9.3000e+00 -9.2511e+00 1.1083e-03 9.9889e-01 4.5302e-02 9.5470e-01 1.0000e-10 1.0000e-10 1.0313e-02 9.2953e+00 - 9.4000e+00 -9.2513e+00 1.0967e-03 9.9890e-01 4.4849e-02 9.5515e-01 1.0000e-10 1.0000e-10 1.0316e-02 9.3953e+00 - 9.5000e+00 -9.2515e+00 1.0854e-03 9.9891e-01 4.4405e-02 9.5560e-01 1.0000e-10 1.0000e-10 1.0318e-02 9.4953e+00 - 9.6000e+00 -9.2517e+00 1.0744e-03 9.9893e-01 4.3969e-02 9.5603e-01 1.0000e-10 1.0000e-10 1.0320e-02 9.5953e+00 - 9.7000e+00 -9.2519e+00 1.0635e-03 9.9894e-01 4.3543e-02 9.5646e-01 1.0000e-10 1.0000e-10 1.0322e-02 9.6953e+00 - 9.8000e+00 -9.2521e+00 1.0529e-03 9.9895e-01 4.3124e-02 9.5688e-01 1.0000e-10 1.0000e-10 1.0324e-02 9.7953e+00 - 9.9000e+00 -9.2523e+00 1.0425e-03 9.9896e-01 4.2713e-02 9.5729e-01 1.0000e-10 1.0000e-10 1.0326e-02 9.8953e+00 - 1.0000e+01 -9.2525e+00 1.0323e-03 9.9897e-01 4.2310e-02 9.5769e-01 1.0000e-10 1.0000e-10 1.0328e-02 9.9953e+00 diff --git a/Sun/examples/ex11.log b/Sun/examples/ex11.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex11.out b/Sun/examples/ex11.out deleted file mode 100644 index fcfa23e9..00000000 --- a/Sun/examples/ex11.out +++ /dev/null @@ -1,2858 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex11 - Output file: ex11.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - PRINT - TITLE Example 11.--Transport and ion exchange. - SOLUTION 0 CaCl2 - units mmol/kgw - temp 25.0 - pH 7.0 charge - pe 12.5 O2(g) -0.68 - Ca 0.6 - Cl 1.2 - SOLUTION 1-40 Initial solution for column - units mmol/kgw - temp 25.0 - pH 7.0 charge - pe 12.5 O2(g) -0.68 - Na 1.0 - K 0.2 - N(5) 1.2 - EXCHANGE 1-40 - equilibrate 1 - X 0.0011 - ADVECTION - cells 40 - shifts 120 - punch_cells 40 - punch_frequency 1 - print_cells 40 - print_frequency 20 - SELECTED_OUTPUT - file ex11adv.sel - reset false - step - totals Na Cl K Ca - USER_PUNCH - heading Pore_vol - 10 PUNCH (STEP_NO + .5) / 40. - END ------ -TITLE ------ - - Example 11.--Transport and ion exchange. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. CaCl2 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 6.000e-04 6.000e-04 - Cl 1.200e-03 1.200e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.800e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -5.732e-20 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 4.630e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 4 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 6.000e-04 - Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 - CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.68 -3.64 -2.96 O2 - -Initial solution 1. Initial solution for column - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 2.000e-04 2.000e-04 - N(5) 1.200e-03 1.200e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.114e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -8.455e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(5) 1.200e-03 - NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.68 -3.64 -2.96 O2 - -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 0. CaCl2 -Using exchange 1. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 4.933e-04 9.866e-04 8.969e-01 -0.069 - KX 9.224e-05 9.224e-05 8.385e-02 -0.018 - NaX 2.120e-05 2.120e-05 1.928e-02 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.067e-04 1.067e-04 - Cl 1.200e-03 1.200e-03 - K 4.584e-04 4.584e-04 - Na 5.281e-04 5.281e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.307e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.215e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 9.601e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 8 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.042e-07 1.003e-07 -6.982 -6.999 -0.017 - OH- 1.040e-07 9.983e-08 -6.983 -7.001 -0.018 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 1.067e-04 - Ca+2 1.067e-04 9.098e-05 -3.972 -4.041 -0.069 - CaOH+ 1.568e-10 1.506e-10 -9.805 -9.822 -0.018 -Cl 1.200e-03 - Cl- 1.200e-03 1.152e-03 -2.921 -2.938 -0.018 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 4.584e-04 - K+ 4.584e-04 4.402e-04 -3.339 -3.356 -0.018 - KOH 1.522e-11 1.522e-11 -10.818 -10.818 0.000 -Na 5.281e-04 - Na+ 5.281e-04 5.073e-04 -3.277 -3.295 -0.017 - NaOH 3.342e-11 3.343e-11 -10.476 -10.476 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.82 -6.23 1.58 NaCl - O2(g) -0.68 -3.64 -2.96 O2 - ------------------------------------- -Beginning of advection calculations. ------------------------------------- - -Beginning of advection time step 1, cumulative pore volumes 0.025000. -Beginning of advection time step 2, cumulative pore volumes 0.050000. -Beginning of advection time step 3, cumulative pore volumes 0.075000. -Beginning of advection time step 4, cumulative pore volumes 0.100000. -Beginning of advection time step 5, cumulative pore volumes 0.125000. -Beginning of advection time step 6, cumulative pore volumes 0.150000. -Beginning of advection time step 7, cumulative pore volumes 0.175000. -Beginning of advection time step 8, cumulative pore volumes 0.200000. -Beginning of advection time step 9, cumulative pore volumes 0.225000. -Beginning of advection time step 10, cumulative pore volumes 0.250000. -Beginning of advection time step 11, cumulative pore volumes 0.275000. -Beginning of advection time step 12, cumulative pore volumes 0.300000. -Beginning of advection time step 13, cumulative pore volumes 0.325000. -Beginning of advection time step 14, cumulative pore volumes 0.350000. -Beginning of advection time step 15, cumulative pore volumes 0.375000. -Beginning of advection time step 16, cumulative pore volumes 0.400000. -Beginning of advection time step 17, cumulative pore volumes 0.425000. -Beginning of advection time step 18, cumulative pore volumes 0.450000. -Beginning of advection time step 19, cumulative pore volumes 0.475000. -Beginning of advection time step 20, cumulative pore volumes 0.500000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 2.000e-04 2.000e-04 - N 1.200e-03 1.200e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.114e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.539e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 - NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 -N(0) 2.552e-19 - N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 -N(3) 2.686e-16 - NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 -N(5) 1.200e-03 - NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.63 -18.89 -3.26 N2 - NH3(g) -66.75 -64.98 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Beginning of advection time step 21, cumulative pore volumes 0.525000. -Beginning of advection time step 22, cumulative pore volumes 0.550000. -Beginning of advection time step 23, cumulative pore volumes 0.575000. -Beginning of advection time step 24, cumulative pore volumes 0.600000. -Beginning of advection time step 25, cumulative pore volumes 0.625000. -Beginning of advection time step 26, cumulative pore volumes 0.650000. -Beginning of advection time step 27, cumulative pore volumes 0.675000. -Beginning of advection time step 28, cumulative pore volumes 0.700000. -Beginning of advection time step 29, cumulative pore volumes 0.725000. -Beginning of advection time step 30, cumulative pore volumes 0.750000. -Beginning of advection time step 31, cumulative pore volumes 0.775000. -Beginning of advection time step 32, cumulative pore volumes 0.800000. -Beginning of advection time step 33, cumulative pore volumes 0.825000. -Beginning of advection time step 34, cumulative pore volumes 0.850000. -Beginning of advection time step 35, cumulative pore volumes 0.875000. -Beginning of advection time step 36, cumulative pore volumes 0.900000. -Beginning of advection time step 37, cumulative pore volumes 0.925000. -Beginning of advection time step 38, cumulative pore volumes 0.950000. -Beginning of advection time step 39, cumulative pore volumes 0.975000. -Beginning of advection time step 40, cumulative pore volumes 1.000000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.200e-03 1.200e-03 - K 2.000e-04 2.000e-04 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.450e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.960e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Cl 1.200e-03 - Cl- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.54 -5.95 1.58 NaCl - O2(g) -0.68 -3.64 -2.96 O2 - -Beginning of advection time step 41, cumulative pore volumes 1.025000. -Beginning of advection time step 42, cumulative pore volumes 1.050000. -Beginning of advection time step 43, cumulative pore volumes 1.075000. -Beginning of advection time step 44, cumulative pore volumes 1.100000. -Beginning of advection time step 45, cumulative pore volumes 1.125000. -Beginning of advection time step 46, cumulative pore volumes 1.150000. -Beginning of advection time step 47, cumulative pore volumes 1.175000. -Beginning of advection time step 48, cumulative pore volumes 1.200000. -Beginning of advection time step 49, cumulative pore volumes 1.225000. -Beginning of advection time step 50, cumulative pore volumes 1.250000. -Beginning of advection time step 51, cumulative pore volumes 1.275000. -Beginning of advection time step 52, cumulative pore volumes 1.300000. -Beginning of advection time step 53, cumulative pore volumes 1.325000. -Beginning of advection time step 54, cumulative pore volumes 1.350000. -Beginning of advection time step 55, cumulative pore volumes 1.375000. -Beginning of advection time step 56, cumulative pore volumes 1.400000. -Beginning of advection time step 57, cumulative pore volumes 1.425000. -Beginning of advection time step 58, cumulative pore volumes 1.450000. -Beginning of advection time step 59, cumulative pore volumes 1.475000. -Beginning of advection time step 60, cumulative pore volumes 1.500000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 7.000e-04 7.000e-04 6.363e-01 -0.017 - NaX 4.000e-04 4.000e-04 3.637e-01 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.200e-03 1.200e-03 - K 3.105e-04 3.105e-04 - Na 8.895e-04 8.895e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -2.836e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 3.548e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 4 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Cl 1.200e-03 - Cl- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 3.105e-04 - K+ 3.105e-04 2.986e-04 -3.508 -3.525 -0.017 - KOH 1.033e-11 1.033e-11 -10.986 -10.986 0.000 -Na 8.895e-04 - Na+ 8.895e-04 8.558e-04 -3.051 -3.068 -0.017 - NaOH 5.641e-11 5.643e-11 -10.249 -10.249 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.59 -6.01 1.58 NaCl - O2(g) -0.68 -3.64 -2.96 O2 - -Beginning of advection time step 61, cumulative pore volumes 1.525000. -Beginning of advection time step 62, cumulative pore volumes 1.550000. -Beginning of advection time step 63, cumulative pore volumes 1.575000. -Beginning of advection time step 64, cumulative pore volumes 1.600000. -Beginning of advection time step 65, cumulative pore volumes 1.625000. -Beginning of advection time step 66, cumulative pore volumes 1.650000. -Beginning of advection time step 67, cumulative pore volumes 1.675000. -Beginning of advection time step 68, cumulative pore volumes 1.700000. -Beginning of advection time step 69, cumulative pore volumes 1.725000. -Beginning of advection time step 70, cumulative pore volumes 1.750000. -Beginning of advection time step 71, cumulative pore volumes 1.775000. -Beginning of advection time step 72, cumulative pore volumes 1.800000. -Beginning of advection time step 73, cumulative pore volumes 1.825000. -Beginning of advection time step 74, cumulative pore volumes 1.850000. -Beginning of advection time step 75, cumulative pore volumes 1.875000. -Beginning of advection time step 76, cumulative pore volumes 1.900000. -Beginning of advection time step 77, cumulative pore volumes 1.925000. -Beginning of advection time step 78, cumulative pore volumes 1.950000. -Beginning of advection time step 79, cumulative pore volumes 1.975000. -Beginning of advection time step 80, cumulative pore volumes 2.000000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 - KX 6.870e-09 6.870e-09 6.246e-06 -0.021 - NaX 2.513e-21 2.513e-21 2.285e-18 -0.020 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 6.000e-04 6.000e-04 - Cl 1.200e-03 1.200e-03 - K 7.667e-08 7.667e-08 - Na 1.406e-19 1.406e-19 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.800e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.294e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 3.976e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 6 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 6.000e-04 - Ca+2 6.000e-04 4.984e-04 -3.222 -3.302 -0.081 - CaOH+ 8.617e-10 8.220e-10 -9.065 -9.085 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 7.667e-08 - K+ 7.667e-08 7.312e-08 -7.115 -7.136 -0.021 - KOH 2.519e-15 2.520e-15 -14.599 -14.599 0.000 -Na 1.406e-19 - Na+ 1.406e-19 1.341e-19 -18.852 -18.872 -0.020 - NaOH 8.804e-27 8.807e-27 -26.055 -26.055 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -23.40 -21.81 1.58 NaCl - O2(g) -0.68 -3.64 -2.96 O2 - -Beginning of advection time step 81, cumulative pore volumes 2.025000. -Beginning of advection time step 82, cumulative pore volumes 2.050000. -Beginning of advection time step 83, cumulative pore volumes 2.075000. -Beginning of advection time step 84, cumulative pore volumes 2.100000. -Beginning of advection time step 85, cumulative pore volumes 2.125000. -Beginning of advection time step 86, cumulative pore volumes 2.150000. -Beginning of advection time step 87, cumulative pore volumes 2.175000. -Beginning of advection time step 88, cumulative pore volumes 2.200000. -Beginning of advection time step 89, cumulative pore volumes 2.225000. -Beginning of advection time step 90, cumulative pore volumes 2.250000. -Beginning of advection time step 91, cumulative pore volumes 2.275000. -Beginning of advection time step 92, cumulative pore volumes 2.300000. -Beginning of advection time step 93, cumulative pore volumes 2.325000. -Beginning of advection time step 94, cumulative pore volumes 2.350000. -Beginning of advection time step 95, cumulative pore volumes 2.375000. -Beginning of advection time step 96, cumulative pore volumes 2.400000. -Beginning of advection time step 97, cumulative pore volumes 2.425000. -Beginning of advection time step 98, cumulative pore volumes 2.450000. -Beginning of advection time step 99, cumulative pore volumes 2.475000. -Beginning of advection time step 100, cumulative pore volumes 2.500000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 6.000e-04 6.000e-04 - Cl 1.200e-03 1.200e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.800e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -5.732e-20 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 3.546e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 6.000e-04 - Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 - CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.68 -3.64 -2.96 O2 - -Beginning of advection time step 101, cumulative pore volumes 2.525000. -Beginning of advection time step 102, cumulative pore volumes 2.550000. -Beginning of advection time step 103, cumulative pore volumes 2.575000. -Beginning of advection time step 104, cumulative pore volumes 2.600000. -Beginning of advection time step 105, cumulative pore volumes 2.625000. -Beginning of advection time step 106, cumulative pore volumes 2.650000. -Beginning of advection time step 107, cumulative pore volumes 2.675000. -Beginning of advection time step 108, cumulative pore volumes 2.700000. -Beginning of advection time step 109, cumulative pore volumes 2.725000. -Beginning of advection time step 110, cumulative pore volumes 2.750000. -Beginning of advection time step 111, cumulative pore volumes 2.775000. -Beginning of advection time step 112, cumulative pore volumes 2.800000. -Beginning of advection time step 113, cumulative pore volumes 2.825000. -Beginning of advection time step 114, cumulative pore volumes 2.850000. -Beginning of advection time step 115, cumulative pore volumes 2.875000. -Beginning of advection time step 116, cumulative pore volumes 2.900000. -Beginning of advection time step 117, cumulative pore volumes 2.925000. -Beginning of advection time step 118, cumulative pore volumes 2.950000. -Beginning of advection time step 119, cumulative pore volumes 2.975000. -Beginning of advection time step 120, cumulative pore volumes 3.000000. - -Cell 40. - -Using solution 40. Solution after simulation 1. -Using exchange 40. Exchange assemblage after simulation 1. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 6.000e-04 6.000e-04 - Cl 1.200e-03 1.200e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.800e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -5.732e-20 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 3.546e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 6.000e-04 - Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 - CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.68 -3.64 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1-40 Initial solution for column - units mmol/kgw - temp 25.0 - pH 7.0 charge - pe 12.5 O2(g) -0.68 - Na 1.0 - K 0.2 - N(5) 1.2 - EXCHANGE 1-40 - equilibrate 1 - X 0.0011 - TRANSPORT - cells 40 - length 0.002 - shifts 120 - time_step 720.0 - flow_direction forward - boundary_conditions flux flux - diffc 0.0e-9 - dispersivity 0.002 - correct_disp true - punch 40 - punch_frequency 1 - print 40 - print_frequency 20 - SELECTED_OUTPUT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 40. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 40. - file ex11trn.sel - reset false - step - totals Na Cl K Ca - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Initial solution for column - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 2.000e-04 2.000e-04 - N(5) 1.200e-03 1.200e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.114e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -8.455e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(5) 1.200e-03 - NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.68 -3.64 -2.96 O2 - -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Initial solution for column -Using exchange 1. Exchange assemblage after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 2.000e-04 2.000e-04 - N 1.200e-03 1.200e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.114e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.532e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 - NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 -N(0) 2.552e-19 - N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 -N(3) 2.686e-16 - NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 -N(5) 1.200e-03 - NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.63 -18.89 -3.26 N2 - NH3(g) -66.75 -64.98 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - ------------------------------------- -Beginning of transport calculations. ------------------------------------- - -------------------------------- -Equilibrating initial solutions -------------------------------- - -Using solution 40. Initial solution for column -Using exchange 40. Exchanger defined in simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - NH4X 4.148e-63 4.148e-63 3.771e-60 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 2.000e-04 2.000e-04 - N 1.200e-03 1.200e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.114e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.532e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.722 -62.739 -0.017 - NH3 0.000e+00 0.000e+00 -64.984 -64.984 0.000 -N(0) 2.552e-19 - N2 1.276e-19 1.276e-19 -18.894 -18.894 0.000 -N(3) 2.686e-16 - NO2- 2.686e-16 2.583e-16 -15.571 -15.588 -0.017 -N(5) 1.200e-03 - NO3- 1.200e-03 1.154e-03 -2.921 -2.938 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.63 -18.89 -3.26 N2 - NH3(g) -66.75 -64.98 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 1. - -Transport step 1. Mixrun 1. - -Transport step 1. Mixrun 2. - -Transport step 1. Mixrun 3. - -Transport step 1. Mixrun 4. - -Transport step 2. - -Transport step 2. Mixrun 1. - -Transport step 2. Mixrun 2. - -Transport step 2. Mixrun 3. - -Transport step 2. Mixrun 4. - -Transport step 3. - -Transport step 3. Mixrun 1. - -Transport step 3. Mixrun 2. - -Transport step 3. Mixrun 3. - -Transport step 3. Mixrun 4. - -Transport step 4. - -Transport step 4. Mixrun 1. - -Transport step 4. Mixrun 2. - -Transport step 4. Mixrun 3. - -Transport step 4. Mixrun 4. - -Transport step 5. - -Transport step 5. Mixrun 1. - -Transport step 5. Mixrun 2. - -Transport step 5. Mixrun 3. - -Transport step 5. Mixrun 4. - -Transport step 6. - -Transport step 6. Mixrun 1. - -Transport step 6. Mixrun 2. - -Transport step 6. Mixrun 3. - -Transport step 6. Mixrun 4. - -Transport step 7. - -Transport step 7. Mixrun 1. - -Transport step 7. Mixrun 2. - -Transport step 7. Mixrun 3. - -Transport step 7. Mixrun 4. - -Transport step 8. - -Transport step 8. Mixrun 1. - -Transport step 8. Mixrun 2. - -Transport step 8. Mixrun 3. - -Transport step 8. Mixrun 4. - -Transport step 9. - -Transport step 9. Mixrun 1. - -Transport step 9. Mixrun 2. - -Transport step 9. Mixrun 3. - -Transport step 9. Mixrun 4. - -Transport step 10. - -Transport step 10. Mixrun 1. - -Transport step 10. Mixrun 2. - -Transport step 10. Mixrun 3. - -Transport step 10. Mixrun 4. - -Transport step 11. - -Transport step 11. Mixrun 1. - -Transport step 11. Mixrun 2. - -Transport step 11. Mixrun 3. - -Transport step 11. Mixrun 4. - -Transport step 12. - -Transport step 12. Mixrun 1. - -Transport step 12. Mixrun 2. - -Transport step 12. Mixrun 3. - -Transport step 12. Mixrun 4. - -Transport step 13. - -Transport step 13. Mixrun 1. - -Transport step 13. Mixrun 2. - -Transport step 13. Mixrun 3. - -Transport step 13. Mixrun 4. - -Transport step 14. - -Transport step 14. Mixrun 1. - -Transport step 14. Mixrun 2. - -Transport step 14. Mixrun 3. - -Transport step 14. Mixrun 4. - -Transport step 15. - -Transport step 15. Mixrun 1. - -Transport step 15. Mixrun 2. - -Transport step 15. Mixrun 3. - -Transport step 15. Mixrun 4. - -Transport step 16. - -Transport step 16. Mixrun 1. - -Transport step 16. Mixrun 2. - -Transport step 16. Mixrun 3. - -Transport step 16. Mixrun 4. - -Transport step 17. - -Transport step 17. Mixrun 1. - -Transport step 17. Mixrun 2. - -Transport step 17. Mixrun 3. - -Transport step 17. Mixrun 4. - -Transport step 18. - -Transport step 18. Mixrun 1. - -Transport step 18. Mixrun 2. - -Transport step 18. Mixrun 3. - -Transport step 18. Mixrun 4. - -Transport step 19. - -Transport step 19. Mixrun 1. - -Transport step 19. Mixrun 2. - -Transport step 19. Mixrun 3. - -Transport step 19. Mixrun 4. - -Transport step 20. - -Transport step 20. Mixrun 1. - -Transport step 20. Mixrun 2. - -Transport step 20. Mixrun 3. - -Transport step 20. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.507e-04 5.507e-04 5.006e-01 -0.017 - NaX 5.493e-04 5.493e-04 4.994e-01 -0.017 - NH4X 4.141e-63 4.141e-63 3.765e-60 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.848e-06 1.848e-06 - K 2.000e-04 2.000e-04 - N 1.198e-03 1.198e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.424e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 1.564e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.551027e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Cl 1.848e-06 - Cl- 1.848e-06 1.777e-06 -5.733 -5.750 -0.017 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.000e-04 - K+ 2.000e-04 1.923e-04 -3.699 -3.716 -0.017 - KOH 6.654e-12 6.656e-12 -11.177 -11.177 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.723 -62.740 -0.017 - NH3 0.000e+00 0.000e+00 -64.985 -64.985 0.000 -N(0) 2.544e-19 - N2 1.272e-19 1.272e-19 -18.895 -18.895 0.000 -N(3) 2.682e-16 - NO2- 2.682e-16 2.579e-16 -15.571 -15.589 -0.017 -N(5) 1.198e-03 - NO3- 1.198e-03 1.152e-03 -2.921 -2.939 -0.017 -Na 1.000e-03 - Na+ 1.000e-03 9.621e-04 -3.000 -3.017 -0.017 - NaOH 6.342e-11 6.344e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -10.35 -8.77 1.58 NaCl - N2(g) -15.64 -18.90 -3.26 N2 - NH3(g) -66.75 -64.98 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 21. - -Transport step 21. Mixrun 1. - -Transport step 21. Mixrun 2. - -Transport step 21. Mixrun 3. - -Transport step 21. Mixrun 4. - -Transport step 22. - -Transport step 22. Mixrun 1. - -Transport step 22. Mixrun 2. - -Transport step 22. Mixrun 3. - -Transport step 22. Mixrun 4. - -Transport step 23. - -Transport step 23. Mixrun 1. - -Transport step 23. Mixrun 2. - -Transport step 23. Mixrun 3. - -Transport step 23. Mixrun 4. - -Transport step 24. - -Transport step 24. Mixrun 1. - -Transport step 24. Mixrun 2. - -Transport step 24. Mixrun 3. - -Transport step 24. Mixrun 4. - -Transport step 25. - -Transport step 25. Mixrun 1. - -Transport step 25. Mixrun 2. - -Transport step 25. Mixrun 3. - -Transport step 25. Mixrun 4. - -Transport step 26. - -Transport step 26. Mixrun 1. - -Transport step 26. Mixrun 2. - -Transport step 26. Mixrun 3. - -Transport step 26. Mixrun 4. - -Transport step 27. - -Transport step 27. Mixrun 1. - -Transport step 27. Mixrun 2. - -Transport step 27. Mixrun 3. - -Transport step 27. Mixrun 4. - -Transport step 28. - -Transport step 28. Mixrun 1. - -Transport step 28. Mixrun 2. - -Transport step 28. Mixrun 3. - -Transport step 28. Mixrun 4. - -Transport step 29. - -Transport step 29. Mixrun 1. - -Transport step 29. Mixrun 2. - -Transport step 29. Mixrun 3. - -Transport step 29. Mixrun 4. - -Transport step 30. - -Transport step 30. Mixrun 1. - -Transport step 30. Mixrun 2. - -Transport step 30. Mixrun 3. - -Transport step 30. Mixrun 4. - -Transport step 31. - -Transport step 31. Mixrun 1. - -Transport step 31. Mixrun 2. - -Transport step 31. Mixrun 3. - -Transport step 31. Mixrun 4. - -Transport step 32. - -Transport step 32. Mixrun 1. - -Transport step 32. Mixrun 2. - -Transport step 32. Mixrun 3. - -Transport step 32. Mixrun 4. - -Transport step 33. - -Transport step 33. Mixrun 1. - -Transport step 33. Mixrun 2. - -Transport step 33. Mixrun 3. - -Transport step 33. Mixrun 4. - -Transport step 34. - -Transport step 34. Mixrun 1. - -Transport step 34. Mixrun 2. - -Transport step 34. Mixrun 3. - -Transport step 34. Mixrun 4. - -Transport step 35. - -Transport step 35. Mixrun 1. - -Transport step 35. Mixrun 2. - -Transport step 35. Mixrun 3. - -Transport step 35. Mixrun 4. - -Transport step 36. - -Transport step 36. Mixrun 1. - -Transport step 36. Mixrun 2. - -Transport step 36. Mixrun 3. - -Transport step 36. Mixrun 4. - -Transport step 37. - -Transport step 37. Mixrun 1. - -Transport step 37. Mixrun 2. - -Transport step 37. Mixrun 3. - -Transport step 37. Mixrun 4. - -Transport step 38. - -Transport step 38. Mixrun 1. - -Transport step 38. Mixrun 2. - -Transport step 38. Mixrun 3. - -Transport step 38. Mixrun 4. - -Transport step 39. - -Transport step 39. Mixrun 1. - -Transport step 39. Mixrun 2. - -Transport step 39. Mixrun 3. - -Transport step 39. Mixrun 4. - -Transport step 40. - -Transport step 40. Mixrun 1. - -Transport step 40. Mixrun 2. - -Transport step 40. Mixrun 3. - -Transport step 40. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 5.512e-04 5.512e-04 5.011e-01 -0.017 - NaX 5.488e-04 5.488e-04 4.989e-01 -0.017 - NH4X 1.796e-63 1.796e-63 1.633e-60 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 6.801e-04 6.801e-04 - K 2.004e-04 2.004e-04 - N 5.199e-04 5.199e-04 - Na 9.996e-04 9.996e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.848e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.884e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550823e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Cl 6.801e-04 - Cl- 6.801e-04 6.540e-04 -3.167 -3.184 -0.017 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 2.004e-04 - K+ 2.004e-04 1.927e-04 -3.698 -3.715 -0.017 - KOH 6.666e-12 6.668e-12 -11.176 -11.176 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -63.085 -63.102 -0.017 - NH3 0.000e+00 0.000e+00 -65.348 -65.347 0.000 -N(0) 4.792e-20 - N2 2.396e-20 2.397e-20 -19.621 -19.620 0.000 -N(3) 1.164e-16 - NO2- 1.164e-16 1.119e-16 -15.934 -15.951 -0.017 -N(5) 5.199e-04 - NO3- 5.199e-04 4.999e-04 -3.284 -3.301 -0.017 -Na 9.996e-04 - Na+ 9.996e-04 9.617e-04 -3.000 -3.017 -0.017 - NaOH 6.340e-11 6.341e-11 -10.198 -10.198 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.78 -6.20 1.58 NaCl - N2(g) -16.36 -19.62 -3.26 N2 - NH3(g) -67.12 -65.35 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 41. - -Transport step 41. Mixrun 1. - -Transport step 41. Mixrun 2. - -Transport step 41. Mixrun 3. - -Transport step 41. Mixrun 4. - -Transport step 42. - -Transport step 42. Mixrun 1. - -Transport step 42. Mixrun 2. - -Transport step 42. Mixrun 3. - -Transport step 42. Mixrun 4. - -Transport step 43. - -Transport step 43. Mixrun 1. - -Transport step 43. Mixrun 2. - -Transport step 43. Mixrun 3. - -Transport step 43. Mixrun 4. - -Transport step 44. - -Transport step 44. Mixrun 1. - -Transport step 44. Mixrun 2. - -Transport step 44. Mixrun 3. - -Transport step 44. Mixrun 4. - -Transport step 45. - -Transport step 45. Mixrun 1. - -Transport step 45. Mixrun 2. - -Transport step 45. Mixrun 3. - -Transport step 45. Mixrun 4. - -Transport step 46. - -Transport step 46. Mixrun 1. - -Transport step 46. Mixrun 2. - -Transport step 46. Mixrun 3. - -Transport step 46. Mixrun 4. - -Transport step 47. - -Transport step 47. Mixrun 1. - -Transport step 47. Mixrun 2. - -Transport step 47. Mixrun 3. - -Transport step 47. Mixrun 4. - -Transport step 48. - -Transport step 48. Mixrun 1. - -Transport step 48. Mixrun 2. - -Transport step 48. Mixrun 3. - -Transport step 48. Mixrun 4. - -Transport step 49. - -Transport step 49. Mixrun 1. - -Transport step 49. Mixrun 2. - -Transport step 49. Mixrun 3. - -Transport step 49. Mixrun 4. - -Transport step 50. - -Transport step 50. Mixrun 1. - -Transport step 50. Mixrun 2. - -Transport step 50. Mixrun 3. - -Transport step 50. Mixrun 4. - -Transport step 51. - -Transport step 51. Mixrun 1. - -Transport step 51. Mixrun 2. - -Transport step 51. Mixrun 3. - -Transport step 51. Mixrun 4. - -Transport step 52. - -Transport step 52. Mixrun 1. - -Transport step 52. Mixrun 2. - -Transport step 52. Mixrun 3. - -Transport step 52. Mixrun 4. - -Transport step 53. - -Transport step 53. Mixrun 1. - -Transport step 53. Mixrun 2. - -Transport step 53. Mixrun 3. - -Transport step 53. Mixrun 4. - -Transport step 54. - -Transport step 54. Mixrun 1. - -Transport step 54. Mixrun 2. - -Transport step 54. Mixrun 3. - -Transport step 54. Mixrun 4. - -Transport step 55. - -Transport step 55. Mixrun 1. - -Transport step 55. Mixrun 2. - -Transport step 55. Mixrun 3. - -Transport step 55. Mixrun 4. - -Transport step 56. - -Transport step 56. Mixrun 1. - -Transport step 56. Mixrun 2. - -Transport step 56. Mixrun 3. - -Transport step 56. Mixrun 4. - -Transport step 57. - -Transport step 57. Mixrun 1. - -Transport step 57. Mixrun 2. - -Transport step 57. Mixrun 3. - -Transport step 57. Mixrun 4. - -Transport step 58. - -Transport step 58. Mixrun 1. - -Transport step 58. Mixrun 2. - -Transport step 58. Mixrun 3. - -Transport step 58. Mixrun 4. - -Transport step 59. - -Transport step 59. Mixrun 1. - -Transport step 59. Mixrun 2. - -Transport step 59. Mixrun 3. - -Transport step 59. Mixrun 4. - -Transport step 60. - -Transport step 60. Mixrun 1. - -Transport step 60. Mixrun 2. - -Transport step 60. Mixrun 3. - -Transport step 60. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 9.451e-04 9.451e-04 8.592e-01 -0.017 - NaX 1.549e-04 1.549e-04 1.408e-01 -0.017 - CaX2 2.150e-20 4.300e-20 3.909e-17 -0.067 - NH4X 5.255e-65 5.255e-65 4.777e-62 -0.017 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 9.153e-23 9.153e-23 - Cl 1.171e-03 1.171e-03 - K 6.589e-04 6.589e-04 - N 2.918e-05 2.918e-05 - Na 5.411e-04 5.411e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.999 Charge balance - pe = 13.611 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.200e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.591e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 3.043e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550676e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.040e-07 1.002e-07 -6.983 -6.999 -0.016 - OH- 1.039e-07 9.991e-08 -6.983 -7.000 -0.017 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 9.153e-23 - Ca+2 9.153e-23 7.852e-23 -22.038 -22.105 -0.067 - CaOH+ 1.352e-28 1.301e-28 -27.869 -27.886 -0.017 -Cl 1.171e-03 - Cl- 1.171e-03 1.126e-03 -2.932 -2.948 -0.017 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 6.589e-04 - K+ 6.589e-04 6.337e-04 -3.181 -3.198 -0.017 - KOH 2.192e-11 2.193e-11 -10.659 -10.659 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -64.336 -64.353 -0.017 - NH3 0.000e+00 0.000e+00 -66.598 -66.598 0.000 -N(0) 1.509e-22 - N2 7.545e-23 7.547e-23 -22.122 -22.122 0.000 -N(3) 6.532e-18 - NO2- 6.532e-18 6.281e-18 -17.185 -17.202 -0.017 -N(5) 2.918e-05 - NO3- 2.918e-05 2.805e-05 -4.535 -4.552 -0.017 -Na 5.411e-04 - Na+ 5.411e-04 5.206e-04 -3.267 -3.284 -0.017 - NaOH 3.432e-11 3.433e-11 -10.464 -10.464 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.81 -6.23 1.58 NaCl - N2(g) -18.86 -22.12 -3.26 N2 - NH3(g) -68.37 -66.60 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 61. - -Transport step 61. Mixrun 1. - -Transport step 61. Mixrun 2. - -Transport step 61. Mixrun 3. - -Transport step 61. Mixrun 4. - -Transport step 62. - -Transport step 62. Mixrun 1. - -Transport step 62. Mixrun 2. - -Transport step 62. Mixrun 3. - -Transport step 62. Mixrun 4. - -Transport step 63. - -Transport step 63. Mixrun 1. - -Transport step 63. Mixrun 2. - -Transport step 63. Mixrun 3. - -Transport step 63. Mixrun 4. - -Transport step 64. - -Transport step 64. Mixrun 1. - -Transport step 64. Mixrun 2. - -Transport step 64. Mixrun 3. - -Transport step 64. Mixrun 4. - -Transport step 65. - -Transport step 65. Mixrun 1. - -Transport step 65. Mixrun 2. - -Transport step 65. Mixrun 3. - -Transport step 65. Mixrun 4. - -Transport step 66. - -Transport step 66. Mixrun 1. - -Transport step 66. Mixrun 2. - -Transport step 66. Mixrun 3. - -Transport step 66. Mixrun 4. - -Transport step 67. - -Transport step 67. Mixrun 1. - -Transport step 67. Mixrun 2. - -Transport step 67. Mixrun 3. - -Transport step 67. Mixrun 4. - -Transport step 68. - -Transport step 68. Mixrun 1. - -Transport step 68. Mixrun 2. - -Transport step 68. Mixrun 3. - -Transport step 68. Mixrun 4. - -Transport step 69. - -Transport step 69. Mixrun 1. - -Transport step 69. Mixrun 2. - -Transport step 69. Mixrun 3. - -Transport step 69. Mixrun 4. - -Transport step 70. - -Transport step 70. Mixrun 1. - -Transport step 70. Mixrun 2. - -Transport step 70. Mixrun 3. - -Transport step 70. Mixrun 4. - -Transport step 71. - -Transport step 71. Mixrun 1. - -Transport step 71. Mixrun 2. - -Transport step 71. Mixrun 3. - -Transport step 71. Mixrun 4. - -Transport step 72. - -Transport step 72. Mixrun 1. - -Transport step 72. Mixrun 2. - -Transport step 72. Mixrun 3. - -Transport step 72. Mixrun 4. - -Transport step 73. - -Transport step 73. Mixrun 1. - -Transport step 73. Mixrun 2. - -Transport step 73. Mixrun 3. - -Transport step 73. Mixrun 4. - -Transport step 74. - -Transport step 74. Mixrun 1. - -Transport step 74. Mixrun 2. - -Transport step 74. Mixrun 3. - -Transport step 74. Mixrun 4. - -Transport step 75. - -Transport step 75. Mixrun 1. - -Transport step 75. Mixrun 2. - -Transport step 75. Mixrun 3. - -Transport step 75. Mixrun 4. - -Transport step 76. - -Transport step 76. Mixrun 1. - -Transport step 76. Mixrun 2. - -Transport step 76. Mixrun 3. - -Transport step 76. Mixrun 4. - -Transport step 77. - -Transport step 77. Mixrun 1. - -Transport step 77. Mixrun 2. - -Transport step 77. Mixrun 3. - -Transport step 77. Mixrun 4. - -Transport step 78. - -Transport step 78. Mixrun 1. - -Transport step 78. Mixrun 2. - -Transport step 78. Mixrun 3. - -Transport step 78. Mixrun 4. - -Transport step 79. - -Transport step 79. Mixrun 1. - -Transport step 79. Mixrun 2. - -Transport step 79. Mixrun 3. - -Transport step 79. Mixrun 4. - -Transport step 80. - -Transport step 80. Mixrun 1. - -Transport step 80. Mixrun 2. - -Transport step 80. Mixrun 3. - -Transport step 80. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.430e-04 1.086e-03 9.874e-01 -0.079 - KX 1.370e-05 1.370e-05 1.245e-02 -0.020 - NaX 2.152e-07 2.152e-07 1.956e-04 -0.020 - NH4X 7.135e-68 7.135e-68 6.486e-65 -0.020 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 5.226e-04 5.226e-04 - Cl 1.199e-03 1.199e-03 - K 1.436e-04 1.436e-04 - N 5.912e-07 5.912e-07 - Na 1.130e-05 1.130e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.998 Charge balance - pe = 13.612 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.723e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.957e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 9.758e-12 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550668e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.050e-07 1.006e-07 -6.979 -6.998 -0.019 - OH- 1.043e-07 9.954e-08 -6.982 -7.002 -0.020 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 5.226e-04 - Ca+2 5.226e-04 4.358e-04 -3.282 -3.361 -0.079 - CaOH+ 7.530e-10 7.191e-10 -9.123 -9.143 -0.020 -Cl 1.199e-03 - Cl- 1.199e-03 1.145e-03 -2.921 -2.941 -0.020 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 1.436e-04 - K+ 1.436e-04 1.370e-04 -3.843 -3.863 -0.020 - KOH 4.723e-12 4.725e-12 -11.326 -11.326 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -66.026 -66.047 -0.020 - NH3 0.000e+00 0.000e+00 -68.293 -68.293 0.000 -N(0) 6.148e-26 - N2 3.074e-26 3.075e-26 -25.512 -25.512 0.000 -N(3) 1.324e-19 - NO2- 1.324e-19 1.263e-19 -18.878 -18.899 -0.020 -N(5) 5.912e-07 - NO3- 5.912e-07 5.642e-07 -6.228 -6.249 -0.020 -Na 1.130e-05 - Na+ 1.130e-05 1.080e-05 -4.947 -4.967 -0.020 - NaOH 7.089e-13 7.092e-13 -12.149 -12.149 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -9.49 -7.91 1.58 NaCl - N2(g) -22.25 -25.51 -3.26 N2 - NH3(g) -70.06 -68.29 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 81. - -Transport step 81. Mixrun 1. - -Transport step 81. Mixrun 2. - -Transport step 81. Mixrun 3. - -Transport step 81. Mixrun 4. - -Transport step 82. - -Transport step 82. Mixrun 1. - -Transport step 82. Mixrun 2. - -Transport step 82. Mixrun 3. - -Transport step 82. Mixrun 4. - -Transport step 83. - -Transport step 83. Mixrun 1. - -Transport step 83. Mixrun 2. - -Transport step 83. Mixrun 3. - -Transport step 83. Mixrun 4. - -Transport step 84. - -Transport step 84. Mixrun 1. - -Transport step 84. Mixrun 2. - -Transport step 84. Mixrun 3. - -Transport step 84. Mixrun 4. - -Transport step 85. - -Transport step 85. Mixrun 1. - -Transport step 85. Mixrun 2. - -Transport step 85. Mixrun 3. - -Transport step 85. Mixrun 4. - -Transport step 86. - -Transport step 86. Mixrun 1. - -Transport step 86. Mixrun 2. - -Transport step 86. Mixrun 3. - -Transport step 86. Mixrun 4. - -Transport step 87. - -Transport step 87. Mixrun 1. - -Transport step 87. Mixrun 2. - -Transport step 87. Mixrun 3. - -Transport step 87. Mixrun 4. - -Transport step 88. - -Transport step 88. Mixrun 1. - -Transport step 88. Mixrun 2. - -Transport step 88. Mixrun 3. - -Transport step 88. Mixrun 4. - -Transport step 89. - -Transport step 89. Mixrun 1. - -Transport step 89. Mixrun 2. - -Transport step 89. Mixrun 3. - -Transport step 89. Mixrun 4. - -Transport step 90. - -Transport step 90. Mixrun 1. - -Transport step 90. Mixrun 2. - -Transport step 90. Mixrun 3. - -Transport step 90. Mixrun 4. - -Transport step 91. - -Transport step 91. Mixrun 1. - -Transport step 91. Mixrun 2. - -Transport step 91. Mixrun 3. - -Transport step 91. Mixrun 4. - -Transport step 92. - -Transport step 92. Mixrun 1. - -Transport step 92. Mixrun 2. - -Transport step 92. Mixrun 3. - -Transport step 92. Mixrun 4. - -Transport step 93. - -Transport step 93. Mixrun 1. - -Transport step 93. Mixrun 2. - -Transport step 93. Mixrun 3. - -Transport step 93. Mixrun 4. - -Transport step 94. - -Transport step 94. Mixrun 1. - -Transport step 94. Mixrun 2. - -Transport step 94. Mixrun 3. - -Transport step 94. Mixrun 4. - -Transport step 95. - -Transport step 95. Mixrun 1. - -Transport step 95. Mixrun 2. - -Transport step 95. Mixrun 3. - -Transport step 95. Mixrun 4. - -Transport step 96. - -Transport step 96. Mixrun 1. - -Transport step 96. Mixrun 2. - -Transport step 96. Mixrun 3. - -Transport step 96. Mixrun 4. - -Transport step 97. - -Transport step 97. Mixrun 1. - -Transport step 97. Mixrun 2. - -Transport step 97. Mixrun 3. - -Transport step 97. Mixrun 4. - -Transport step 98. - -Transport step 98. Mixrun 1. - -Transport step 98. Mixrun 2. - -Transport step 98. Mixrun 3. - -Transport step 98. Mixrun 4. - -Transport step 99. - -Transport step 99. Mixrun 1. - -Transport step 99. Mixrun 2. - -Transport step 99. Mixrun 3. - -Transport step 99. Mixrun 4. - -Transport step 100. - -Transport step 100. Mixrun 1. - -Transport step 100. Mixrun 2. - -Transport step 100. Mixrun 3. - -Transport step 100. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.499e-04 1.100e-03 9.999e-01 -0.080 - KX 1.363e-07 1.363e-07 1.239e-04 -0.021 - NaX 1.851e-09 1.851e-09 1.683e-06 -0.020 - NH4X 8.683e-70 8.683e-70 7.894e-67 -0.021 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 5.992e-04 5.992e-04 - Cl 1.200e-03 1.200e-03 - K 1.520e-06 1.520e-06 - N 7.648e-09 7.648e-09 - Na 1.035e-07 1.035e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.799e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 6.006e-20 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.774e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 5.992e-04 - Ca+2 5.992e-04 4.978e-04 -3.222 -3.303 -0.080 - CaOH+ 8.606e-10 8.210e-10 -9.065 -9.086 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 1.520e-06 - K+ 1.520e-06 1.450e-06 -5.818 -5.839 -0.021 - KOH 4.994e-14 4.996e-14 -13.302 -13.301 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -67.914 -67.935 -0.021 - NH3 0.000e+00 0.000e+00 -70.182 -70.182 0.000 -N(0) 1.028e-29 - N2 5.139e-30 5.141e-30 -29.289 -29.289 0.000 -N(3) 1.712e-21 - NO2- 1.712e-21 1.632e-21 -20.766 -20.787 -0.021 -N(5) 7.648e-09 - NO3- 7.648e-09 7.291e-09 -8.116 -8.137 -0.021 -Na 1.035e-07 - Na+ 1.035e-07 9.874e-08 -6.985 -7.006 -0.020 - NaOH 6.480e-15 6.483e-15 -14.188 -14.188 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -11.53 -9.95 1.58 NaCl - N2(g) -26.03 -29.29 -3.26 N2 - NH3(g) -71.95 -70.18 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - -Transport step 101. - -Transport step 101. Mixrun 1. - -Transport step 101. Mixrun 2. - -Transport step 101. Mixrun 3. - -Transport step 101. Mixrun 4. - -Transport step 102. - -Transport step 102. Mixrun 1. - -Transport step 102. Mixrun 2. - -Transport step 102. Mixrun 3. - -Transport step 102. Mixrun 4. - -Transport step 103. - -Transport step 103. Mixrun 1. - -Transport step 103. Mixrun 2. - -Transport step 103. Mixrun 3. - -Transport step 103. Mixrun 4. - -Transport step 104. - -Transport step 104. Mixrun 1. - -Transport step 104. Mixrun 2. - -Transport step 104. Mixrun 3. - -Transport step 104. Mixrun 4. - -Transport step 105. - -Transport step 105. Mixrun 1. - -Transport step 105. Mixrun 2. - -Transport step 105. Mixrun 3. - -Transport step 105. Mixrun 4. - -Transport step 106. - -Transport step 106. Mixrun 1. - -Transport step 106. Mixrun 2. - -Transport step 106. Mixrun 3. - -Transport step 106. Mixrun 4. - -Transport step 107. - -Transport step 107. Mixrun 1. - -Transport step 107. Mixrun 2. - -Transport step 107. Mixrun 3. - -Transport step 107. Mixrun 4. - -Transport step 108. - -Transport step 108. Mixrun 1. - -Transport step 108. Mixrun 2. - -Transport step 108. Mixrun 3. - -Transport step 108. Mixrun 4. - -Transport step 109. - -Transport step 109. Mixrun 1. - -Transport step 109. Mixrun 2. - -Transport step 109. Mixrun 3. - -Transport step 109. Mixrun 4. - -Transport step 110. - -Transport step 110. Mixrun 1. - -Transport step 110. Mixrun 2. - -Transport step 110. Mixrun 3. - -Transport step 110. Mixrun 4. - -Transport step 111. - -Transport step 111. Mixrun 1. - -Transport step 111. Mixrun 2. - -Transport step 111. Mixrun 3. - -Transport step 111. Mixrun 4. - -Transport step 112. - -Transport step 112. Mixrun 1. - -Transport step 112. Mixrun 2. - -Transport step 112. Mixrun 3. - -Transport step 112. Mixrun 4. - -Transport step 113. - -Transport step 113. Mixrun 1. - -Transport step 113. Mixrun 2. - -Transport step 113. Mixrun 3. - -Transport step 113. Mixrun 4. - -Transport step 114. - -Transport step 114. Mixrun 1. - -Transport step 114. Mixrun 2. - -Transport step 114. Mixrun 3. - -Transport step 114. Mixrun 4. - -Transport step 115. - -Transport step 115. Mixrun 1. - -Transport step 115. Mixrun 2. - -Transport step 115. Mixrun 3. - -Transport step 115. Mixrun 4. - -Transport step 116. - -Transport step 116. Mixrun 1. - -Transport step 116. Mixrun 2. - -Transport step 116. Mixrun 3. - -Transport step 116. Mixrun 4. - -Transport step 117. - -Transport step 117. Mixrun 1. - -Transport step 117. Mixrun 2. - -Transport step 117. Mixrun 3. - -Transport step 117. Mixrun 4. - -Transport step 118. - -Transport step 118. Mixrun 1. - -Transport step 118. Mixrun 2. - -Transport step 118. Mixrun 3. - -Transport step 118. Mixrun 4. - -Transport step 119. - -Transport step 119. Mixrun 1. - -Transport step 119. Mixrun 2. - -Transport step 119. Mixrun 3. - -Transport step 119. Mixrun 4. - -Transport step 120. - -Transport step 120. Mixrun 1. - -Transport step 120. Mixrun 2. - -Transport step 120. Mixrun 3. - -Transport step 120. Mixrun 4. - -Using mix 40. -Using exchange 40. Exchange assemblage after simulation 2. - -Mixture 40. - - 2.625e-01 Solution 39 Solution after simulation 2. - 0.000e+00 Solution 41 Initial solution for column - 7.375e-01 Solution 40 Solution after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.100e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 5.500e-04 1.100e-03 1.000e+00 -0.081 - KX 1.753e-09 1.753e-09 1.593e-06 -0.021 - NaX 1.743e-11 1.743e-11 1.585e-08 -0.020 - NH4X 8.965e-72 8.965e-72 8.150e-69 -0.021 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 6.000e-04 6.000e-04 - Cl 1.200e-03 1.200e-03 - K 1.956e-08 1.956e-08 - N 7.901e-11 7.901e-11 - Na 9.751e-10 9.751e-10 - -----------------------------Description of solution---------------------------- - - pH = 6.997 Charge balance - pe = 13.613 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.800e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -5.732e-19 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 1.157e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550667e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.052e-07 1.006e-07 -6.978 -6.997 -0.019 - OH- 1.043e-07 9.948e-08 -6.982 -7.002 -0.021 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Ca 6.000e-04 - Ca+2 6.000e-04 4.985e-04 -3.222 -3.302 -0.081 - CaOH+ 8.617e-10 8.221e-10 -9.065 -9.085 -0.020 -Cl 1.200e-03 - Cl- 1.200e-03 1.144e-03 -2.921 -2.941 -0.021 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.370 -44.370 0.000 -K 1.956e-08 - K+ 1.956e-08 1.865e-08 -7.709 -7.729 -0.021 - KOH 6.425e-16 6.428e-16 -15.192 -15.192 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -69.900 -69.921 -0.021 - NH3 0.000e+00 0.000e+00 -72.168 -72.168 0.000 -N(0) 1.097e-33 - N2 5.484e-34 5.487e-34 -33.261 -33.261 0.000 -N(3) 1.769e-23 - NO2- 1.769e-23 1.686e-23 -22.752 -22.773 -0.021 -N(5) 7.901e-11 - NO3- 7.901e-11 7.532e-11 -10.102 -10.123 -0.021 -Na 9.751e-10 - Na+ 9.751e-10 9.305e-10 -9.011 -9.031 -0.020 - NaOH 6.107e-17 6.109e-17 -16.214 -16.214 0.000 -O(0) 4.580e-04 - O2 2.290e-04 2.291e-04 -3.640 -3.640 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.22 -44.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -13.55 -11.97 1.58 NaCl - N2(g) -30.00 -33.26 -3.26 N2 - NH3(g) -73.94 -72.17 1.77 NH3 - O2(g) -0.68 -3.64 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex11adv.sel b/Sun/examples/ex11adv.sel deleted file mode 100644 index 1958435f..00000000 --- a/Sun/examples/ex11adv.sel +++ /dev/null @@ -1,125 +0,0 @@ - step Na Cl K Ca Pore_vol - -99 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 1.2500e-02 - -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 - -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 - 1 5.2815e-04 1.2000e-03 4.5842e-04 1.0672e-04 3.7500e-02 - 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 - 2 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.2500e-02 - 3 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.7500e-02 - 4 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.1250e-01 - 5 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.3750e-01 - 6 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.6250e-01 - 7 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.8750e-01 - 8 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.1250e-01 - 9 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.3750e-01 - 10 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.6250e-01 - 11 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 2.8750e-01 - 12 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.1250e-01 - 13 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.3750e-01 - 14 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.6250e-01 - 15 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.8750e-01 - 16 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.1250e-01 - 17 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.3750e-01 - 18 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.6250e-01 - 19 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 4.8750e-01 - 20 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.1250e-01 - 21 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.3750e-01 - 22 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.6250e-01 - 23 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 5.8750e-01 - 24 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.1250e-01 - 25 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.3750e-01 - 26 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.6250e-01 - 27 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.8750e-01 - 28 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.1250e-01 - 29 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.3750e-01 - 30 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.6250e-01 - 31 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 7.8750e-01 - 32 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.1250e-01 - 33 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.3750e-01 - 34 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.6250e-01 - 35 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.8750e-01 - 36 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.1250e-01 - 37 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.3750e-01 - 38 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.6250e-01 - 39 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 9.8750e-01 - 40 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0125e+00 - 41 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0375e+00 - 42 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0625e+00 - 43 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.0875e+00 - 44 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1125e+00 - 45 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1375e+00 - 46 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1625e+00 - 47 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.1875e+00 - 48 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2125e+00 - 49 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2375e+00 - 50 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2625e+00 - 51 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.2875e+00 - 52 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.3125e+00 - 53 1.0000e-03 1.2000e-03 2.0000e-04 0.0000e+00 1.3375e+00 - 54 9.9998e-04 1.2000e-03 2.0002e-04 0.0000e+00 1.3625e+00 - 55 9.9993e-04 1.2000e-03 2.0007e-04 0.0000e+00 1.3875e+00 - 56 9.9969e-04 1.2000e-03 2.0031e-04 0.0000e+00 1.4125e+00 - 57 9.9860e-04 1.2000e-03 2.0140e-04 0.0000e+00 1.4375e+00 - 58 9.9376e-04 1.2000e-03 2.0624e-04 0.0000e+00 1.4625e+00 - 59 9.7266e-04 1.2000e-03 2.2734e-04 0.0000e+00 1.4875e+00 - 60 8.8947e-04 1.2000e-03 3.1053e-04 0.0000e+00 1.5125e+00 - 61 6.5396e-04 1.2000e-03 5.4604e-04 0.0000e+00 1.5375e+00 - 62 3.1876e-04 1.2000e-03 8.8124e-04 0.0000e+00 1.5625e+00 - 63 1.0663e-04 1.2000e-03 1.0934e-03 0.0000e+00 1.5875e+00 - 64 2.9829e-05 1.2000e-03 1.1702e-03 0.0000e+00 1.6125e+00 - 65 7.8763e-06 1.2000e-03 1.1921e-03 1.2216e-27 1.6375e+00 - 66 2.0460e-06 1.2000e-03 1.1980e-03 1.8112e-25 1.6625e+00 - 67 5.2878e-07 1.2000e-03 1.1995e-03 2.6557e-23 1.6875e+00 - 68 1.3629e-07 1.2000e-03 1.1999e-03 3.9376e-21 1.7125e+00 - 69 3.5021e-08 1.2000e-03 1.2000e-03 5.8912e-19 1.7375e+00 - 70 8.9558e-09 1.2000e-03 1.2000e-03 8.8181e-17 1.7625e+00 - 71 2.2719e-09 1.2000e-03 1.2000e-03 1.3080e-14 1.7875e+00 - 72 5.6835e-10 1.2000e-03 1.2000e-03 1.9126e-12 1.8125e+00 - 73 1.3869e-10 1.2000e-03 1.2000e-03 2.7576e-10 1.8375e+00 - 74 3.2281e-11 1.2000e-03 1.1999e-03 3.9374e-08 1.8625e+00 - 75 6.7673e-12 1.2000e-03 1.1890e-03 5.4946e-06 1.8875e+00 - 76 8.0510e-13 1.2000e-03 7.0494e-04 2.4753e-04 1.9125e+00 - 77 2.1968e-14 1.2000e-03 9.6079e-05 5.5196e-04 1.9375e+00 - 78 4.1771e-16 1.2000e-03 9.1269e-06 5.9544e-04 1.9625e+00 - 79 7.6748e-18 1.2000e-03 8.3782e-07 5.9958e-04 1.9875e+00 - 80 1.4057e-19 1.2000e-03 7.6671e-08 5.9996e-04 2.0125e+00 - 81 2.5740e-21 1.2000e-03 7.0147e-09 6.0000e-04 2.0375e+00 - 82 4.7052e-23 1.2000e-03 6.4179e-10 6.0000e-04 2.0625e+00 - 83 8.2642e-25 1.2000e-03 5.8721e-11 6.0000e-04 2.0875e+00 - 84 0.0000e+00 1.2000e-03 5.3731e-12 6.0000e-04 2.1125e+00 - 85 0.0000e+00 1.2000e-03 4.9168e-13 6.0000e-04 2.1375e+00 - 86 0.0000e+00 1.2000e-03 4.4995e-14 6.0000e-04 2.1625e+00 - 87 0.0000e+00 1.2000e-03 4.1178e-15 6.0000e-04 2.1875e+00 - 88 0.0000e+00 1.2000e-03 3.7688e-16 6.0000e-04 2.2125e+00 - 89 0.0000e+00 1.2000e-03 3.4497e-17 6.0000e-04 2.2375e+00 - 90 0.0000e+00 1.2000e-03 3.1577e-18 6.0000e-04 2.2625e+00 - 91 0.0000e+00 1.2000e-03 2.8907e-19 6.0000e-04 2.2875e+00 - 92 0.0000e+00 1.2000e-03 2.6465e-20 6.0000e-04 2.3125e+00 - 93 0.0000e+00 1.2000e-03 2.4231e-21 6.0000e-04 2.3375e+00 - 94 0.0000e+00 1.2000e-03 2.2183e-22 6.0000e-04 2.3625e+00 - 95 0.0000e+00 1.2000e-03 2.0287e-23 6.0000e-04 2.3875e+00 - 96 0.0000e+00 1.2000e-03 1.8364e-24 6.0000e-04 2.4125e+00 - 97 0.0000e+00 1.2000e-03 1.5102e-25 6.0000e-04 2.4375e+00 - 98 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.4625e+00 - 99 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.4875e+00 - 100 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5125e+00 - 101 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5375e+00 - 102 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5625e+00 - 103 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.5875e+00 - 104 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6125e+00 - 105 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6375e+00 - 106 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6625e+00 - 107 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.6875e+00 - 108 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7125e+00 - 109 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7375e+00 - 110 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7625e+00 - 111 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.7875e+00 - 112 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8125e+00 - 113 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8375e+00 - 114 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8625e+00 - 115 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.8875e+00 - 116 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9125e+00 - 117 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9375e+00 - 118 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9625e+00 - 119 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 2.9875e+00 - 120 0.0000e+00 1.2000e-03 0.0000e+00 6.0000e-04 3.0125e+00 diff --git a/Sun/examples/ex11trn.sel b/Sun/examples/ex11trn.sel deleted file mode 100644 index ca370b4c..00000000 --- a/Sun/examples/ex11trn.sel +++ /dev/null @@ -1,125 +0,0 @@ - step Na Cl K Ca Pore_vol - -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 - -99 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 - 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 - 0 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.2500e-02 - 1 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 3.7500e-02 - 2 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 6.2500e-02 - 3 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 8.7500e-02 - 4 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.1250e-01 - 5 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.3750e-01 - 6 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.6250e-01 - 7 1.0000e-03 0.0000e+00 2.0000e-04 0.0000e+00 1.8750e-01 - 8 1.0000e-03 3.0997e-22 2.0000e-04 0.0000e+00 2.1250e-01 - 9 1.0000e-03 1.5009e-17 2.0000e-04 0.0000e+00 2.3750e-01 - 10 1.0000e-03 6.3378e-15 2.0000e-04 0.0000e+00 2.6250e-01 - 11 1.0000e-03 4.4948e-13 2.0000e-04 0.0000e+00 2.8750e-01 - 12 1.0000e-03 1.1487e-11 2.0000e-04 0.0000e+00 3.1250e-01 - 13 1.0000e-03 1.5022e-10 2.0000e-04 0.0000e+00 3.3750e-01 - 14 1.0000e-03 1.2225e-09 2.0000e-04 0.0000e+00 3.6250e-01 - 15 1.0000e-03 6.9925e-09 2.0000e-04 0.0000e+00 3.8750e-01 - 16 1.0000e-03 3.0480e-08 2.0000e-04 0.0000e+00 4.1250e-01 - 17 1.0000e-03 1.0717e-07 2.0000e-04 0.0000e+00 4.3750e-01 - 18 1.0000e-03 3.1679e-07 2.0000e-04 0.0000e+00 4.6250e-01 - 19 1.0000e-03 8.1192e-07 2.0000e-04 0.0000e+00 4.8750e-01 - 20 1.0000e-03 1.8478e-06 2.0000e-04 0.0000e+00 5.1250e-01 - 21 1.0000e-03 3.8042e-06 2.0000e-04 0.0000e+00 5.3750e-01 - 22 1.0000e-03 7.1918e-06 2.0000e-04 0.0000e+00 5.6250e-01 - 23 1.0000e-03 1.2635e-05 2.0000e-04 0.0000e+00 5.8750e-01 - 24 1.0000e-03 2.0834e-05 2.0000e-04 0.0000e+00 6.1250e-01 - 25 1.0000e-03 3.2507e-05 2.0000e-04 0.0000e+00 6.3750e-01 - 26 1.0000e-03 4.8325e-05 2.0000e-04 0.0000e+00 6.6250e-01 - 27 1.0000e-03 6.8844e-05 2.0000e-04 0.0000e+00 6.8750e-01 - 28 1.0000e-03 9.4449e-05 2.0000e-04 0.0000e+00 7.1250e-01 - 29 1.0000e-03 1.2532e-04 2.0000e-04 0.0000e+00 7.3750e-01 - 30 1.0000e-03 1.6140e-04 2.0000e-04 0.0000e+00 7.6250e-01 - 31 1.0000e-03 2.0242e-04 2.0000e-04 0.0000e+00 7.8750e-01 - 32 1.0000e-03 2.4790e-04 2.0000e-04 0.0000e+00 8.1250e-01 - 33 9.9999e-04 2.9719e-04 2.0001e-04 0.0000e+00 8.3750e-01 - 34 9.9999e-04 3.4951e-04 2.0001e-04 0.0000e+00 8.6250e-01 - 35 9.9998e-04 4.0403e-04 2.0002e-04 0.0000e+00 8.8750e-01 - 36 9.9996e-04 4.5987e-04 2.0004e-04 0.0000e+00 9.1250e-01 - 37 9.9993e-04 5.1616e-04 2.0007e-04 0.0000e+00 9.3750e-01 - 38 9.9988e-04 5.7209e-04 2.0012e-04 0.0000e+00 9.6250e-01 - 39 9.9979e-04 6.2694e-04 2.0021e-04 0.0000e+00 9.8750e-01 - 40 9.9964e-04 6.8006e-04 2.0036e-04 0.0000e+00 1.0125e+00 - 41 9.9940e-04 7.3093e-04 2.0060e-04 0.0000e+00 1.0375e+00 - 42 9.9902e-04 7.7913e-04 2.0098e-04 0.0000e+00 1.0625e+00 - 43 9.9842e-04 8.2437e-04 2.0158e-04 0.0000e+00 1.0875e+00 - 44 9.9749e-04 8.6644e-04 2.0251e-04 0.0000e+00 1.1125e+00 - 45 9.9606e-04 9.0523e-04 2.0394e-04 0.0000e+00 1.1375e+00 - 46 9.9390e-04 9.4071e-04 2.0610e-04 0.0000e+00 1.1625e+00 - 47 9.9067e-04 9.7294e-04 2.0933e-04 0.0000e+00 1.1875e+00 - 48 9.8590e-04 1.0020e-03 2.1410e-04 0.0000e+00 1.2125e+00 - 49 9.7896e-04 1.0281e-03 2.2104e-04 0.0000e+00 1.2375e+00 - 50 9.6900e-04 1.0513e-03 2.3100e-04 0.0000e+00 1.2625e+00 - 51 9.5496e-04 1.0718e-03 2.4504e-04 0.0000e+00 1.2875e+00 - 52 9.3563e-04 1.0899e-03 2.6437e-04 0.0000e+00 1.3125e+00 - 53 9.0974e-04 1.1058e-03 2.9026e-04 0.0000e+00 1.3375e+00 - 54 8.7620e-04 1.1196e-03 3.2380e-04 0.0000e+00 1.3625e+00 - 55 8.3445e-04 1.1316e-03 3.6555e-04 0.0000e+00 1.3875e+00 - 56 7.8479e-04 1.1420e-03 4.1521e-04 0.0000e+00 1.4125e+00 - 57 7.2845e-04 1.1510e-03 4.7155e-04 3.5277e-28 1.4375e+00 - 58 6.6747e-04 1.1587e-03 5.3253e-04 4.2108e-26 1.4625e+00 - 59 6.0423e-04 1.1652e-03 5.9577e-04 2.1113e-24 1.4875e+00 - 60 5.4107e-04 1.1708e-03 6.5893e-04 9.1531e-23 1.5125e+00 - 61 4.7992e-04 1.1756e-03 7.2008e-04 3.5143e-21 1.5375e+00 - 62 4.2217e-04 1.1796e-03 7.7783e-04 1.2072e-19 1.5625e+00 - 63 3.6873e-04 1.1830e-03 8.3127e-04 3.6941e-18 1.5875e+00 - 64 3.2004e-04 1.1859e-03 8.7996e-04 1.0357e-16 1.6125e+00 - 65 2.7623e-04 1.1883e-03 9.2377e-04 2.6573e-15 1.6375e+00 - 66 2.3720e-04 1.1903e-03 9.6280e-04 6.2721e-14 1.6625e+00 - 67 2.0268e-04 1.1920e-03 9.9732e-04 1.4041e-12 1.6875e+00 - 68 1.7232e-04 1.1934e-03 1.0277e-03 2.9709e-11 1.7125e+00 - 69 1.4570e-04 1.1945e-03 1.0543e-03 5.8657e-10 1.7375e+00 - 70 1.2238e-04 1.1955e-03 1.0776e-03 1.1507e-08 1.7625e+00 - 71 1.0193e-04 1.1963e-03 1.0977e-03 2.0826e-07 1.7875e+00 - 72 8.3815e-05 1.1970e-03 1.1095e-03 3.3299e-06 1.8125e+00 - 73 6.6682e-05 1.1975e-03 1.0249e-03 5.4190e-05 1.8375e+00 - 74 5.0532e-05 1.1980e-03 7.3505e-04 2.0721e-04 1.8625e+00 - 75 3.8797e-05 1.1983e-03 5.3569e-04 3.1276e-04 1.8875e+00 - 76 3.0077e-05 1.1986e-03 4.0212e-04 3.8390e-04 1.9125e+00 - 77 2.3445e-05 1.1989e-03 3.0685e-04 4.3485e-04 1.9375e+00 - 78 1.8340e-05 1.1991e-03 2.3662e-04 4.7252e-04 1.9625e+00 - 79 1.4384e-05 1.1993e-03 1.8380e-04 5.0091e-04 1.9875e+00 - 80 1.1303e-05 1.1994e-03 1.4355e-04 5.2257e-04 2.0125e+00 - 81 8.8949e-06 1.1995e-03 1.1260e-04 5.3925e-04 2.0375e+00 - 82 7.0081e-06 1.1996e-03 8.8613e-05 5.5219e-04 2.0625e+00 - 83 5.5269e-06 1.1997e-03 6.9934e-05 5.6227e-04 2.0875e+00 - 84 4.3622e-06 1.1997e-03 5.5321e-05 5.7016e-04 2.1125e+00 - 85 3.4452e-06 1.1998e-03 4.3847e-05 5.7635e-04 2.1375e+00 - 86 2.7225e-06 1.1998e-03 3.4813e-05 5.8123e-04 2.1625e+00 - 87 2.1523e-06 1.1999e-03 2.7680e-05 5.8508e-04 2.1875e+00 - 88 1.7023e-06 1.1999e-03 2.2038e-05 5.8813e-04 2.2125e+00 - 89 1.3467e-06 1.1999e-03 1.7565e-05 5.9054e-04 2.2375e+00 - 90 1.0658e-06 1.1999e-03 1.4014e-05 5.9246e-04 2.2625e+00 - 91 8.4359e-07 1.1999e-03 1.1192e-05 5.9398e-04 2.2875e+00 - 92 6.6787e-07 1.2000e-03 8.9443e-06 5.9519e-04 2.3125e+00 - 93 5.2883e-07 1.2000e-03 7.1535e-06 5.9616e-04 2.3375e+00 - 94 4.1880e-07 1.2000e-03 5.7250e-06 5.9693e-04 2.3625e+00 - 95 3.3169e-07 1.2000e-03 4.5844e-06 5.9754e-04 2.3875e+00 - 96 2.6273e-07 1.2000e-03 3.6730e-06 5.9803e-04 2.4125e+00 - 97 2.0811e-07 1.2000e-03 2.9442e-06 5.9842e-04 2.4375e+00 - 98 1.6486e-07 1.2000e-03 2.3611e-06 5.9874e-04 2.4625e+00 - 99 1.3060e-07 1.2000e-03 1.8942e-06 5.9899e-04 2.4875e+00 - 100 1.0347e-07 1.2000e-03 1.5202e-06 5.9919e-04 2.5125e+00 - 101 8.1970e-08 1.2000e-03 1.2205e-06 5.9935e-04 2.5375e+00 - 102 6.4939e-08 1.2000e-03 9.8015e-07 5.9948e-04 2.5625e+00 - 103 5.1446e-08 1.2000e-03 7.8736e-07 5.9958e-04 2.5875e+00 - 104 4.0756e-08 1.2000e-03 6.3266e-07 5.9966e-04 2.6125e+00 - 105 3.2287e-08 1.2000e-03 5.0848e-07 5.9973e-04 2.6375e+00 - 106 2.5577e-08 1.2000e-03 4.0877e-07 5.9978e-04 2.6625e+00 - 107 2.0260e-08 1.2000e-03 3.2868e-07 5.9983e-04 2.6875e+00 - 108 1.6048e-08 1.2000e-03 2.6433e-07 5.9986e-04 2.7125e+00 - 109 1.2712e-08 1.2000e-03 2.1262e-07 5.9989e-04 2.7375e+00 - 110 1.0068e-08 1.2000e-03 1.7105e-07 5.9991e-04 2.7625e+00 - 111 7.9740e-09 1.2000e-03 1.3763e-07 5.9993e-04 2.7875e+00 - 112 6.3151e-09 1.2000e-03 1.1076e-07 5.9994e-04 2.8125e+00 - 113 5.0010e-09 1.2000e-03 8.9141e-08 5.9995e-04 2.8375e+00 - 114 3.9601e-09 1.2000e-03 7.1753e-08 5.9996e-04 2.8625e+00 - 115 3.1357e-09 1.2000e-03 5.7764e-08 5.9997e-04 2.8875e+00 - 116 2.4828e-09 1.2000e-03 4.6507e-08 5.9998e-04 2.9125e+00 - 117 1.9657e-09 1.2000e-03 3.7447e-08 5.9998e-04 2.9375e+00 - 118 1.5562e-09 1.2000e-03 3.0156e-08 5.9998e-04 2.9625e+00 - 119 1.2319e-09 1.2000e-03 2.4286e-08 5.9999e-04 2.9875e+00 - 120 9.7513e-10 1.2000e-03 1.9560e-08 5.9999e-04 3.0125e+00 diff --git a/Sun/examples/ex12.log b/Sun/examples/ex12.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex12.out b/Sun/examples/ex12.out deleted file mode 100644 index 8ed928a7..00000000 --- a/Sun/examples/ex12.out +++ /dev/null @@ -1,99 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex12 - Output file: ex12.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 12.--Advective and diffusive transport of heat and solutes. - Constant boundary condition at one end, closed at other. - The problem is designed so that temperature should equal Na-conc - (in mmol/kgw) after diffusion. - EXCHANGE_SPECIES - Na+ + X- = NaX - log_k 0.0 - gamma 4.0 0.075 - H+ + X- = HX - log_k -99. - gamma 9.0 0.0 - K+ + X- = KX - log_k 0.0 - gamma 3.5 0.015 - SOLUTION 0 24.0 mM KNO3 - units mol/kgw - temp 0 # Incoming solution 0C - pH 7.0 - pe 12.0 O2(g) -0.67 - K 24.e-3 - N(5) 24.e-3 - SOLUTION 1-20 0.001 mM KCl - units mol/kgw - temp 25 # Column is at 25C - pH 7.0 - pe 12.0 O2(g) -0.67 - K 1e-6 - Cl 1e-6 - EXCHANGE 1-20 - KX 0.048 - TRANSPORT # Make column temperature 0C, displace Cl - cells 20 - shifts 19 - flow_direction forward - bcond flux flux - length 1.0 - disp 0.0 # No dispersion - diffc 0.0 # No diffusion - thermal_diffusion 1.0 # No retardation for heat - PRINT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. - reset false - END - SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - SOLUTION 20 Same as soln 0 in cell 20 at closed column end (second type boundary cond) - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - EXCHANGE 20 - NaX 0.048 - TRANSPORT # Diffuse 24C, NaCl solution from column end - shifts 1 - flow_direction diffusion - bcond constant closed - thermal_diffusion 3.0 # heat is retarded equal to Na - diffc 0.3e-9 # m^2/s - timest 1.0e+10 # 317 years, 19 substeps will be used - SELECTED_OUTPUT - file ex12.sel - high_precision true - reset false - distance true - temperature true - USER_PUNCH - heading Na_mmol K_mmol Cl_mmol - 10 PUNCH TOT("Na")*1000, TOT("K")*1000, TOT("Cl")*1000 - END -No memory leaks diff --git a/Sun/examples/ex12.sel b/Sun/examples/ex12.sel deleted file mode 100644 index 84fd56c2..00000000 --- a/Sun/examples/ex12.sel +++ /dev/null @@ -1,44 +0,0 @@ - dist_x temp Na_mmol K_mmol Cl_mmol - -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - -99 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000010e+01 0.000000000000e+00 - 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 19.5 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - 0.5 1.686181418415e+01 1.686181416184e+01 7.138185829939e+00 2.011377529332e+01 - 1.5 6.421492325960e+00 6.421492342616e+00 1.757850764418e+01 1.294968671951e+01 - 2.5 1.759908541854e+00 1.759908557221e+00 2.224009143309e+01 7.342808261321e+00 - 3.5 3.571924631562e-01 3.571924666823e-01 2.364280752813e+01 3.623408283684e+00 - 4.5 5.490209781370e-02 5.490209803302e-02 2.394509789974e+01 1.538555967129e+00 - 5.5 6.484238380348e-03 6.484238322345e-03 2.399351576095e+01 5.556625533113e-01 - 6.5 5.926340095484e-04 5.926339925265e-04 2.399940736587e+01 1.684990632469e-01 - 7.5 4.190926756604e-05 4.190926525116e-05 2.399995809080e+01 4.224784404205e-02 - 8.5 2.276345750780e-06 2.276345548554e-06 2.399999772377e+01 8.664946370896e-03 - 9.5 1.396593677778e-07 1.396593266673e-07 2.399999986046e+01 2.055609847093e-03 - 10.5 1.138869021831e-06 1.138868368161e-06 2.399999886125e+01 4.374443607427e-03 - 11.5 2.090811414205e-05 2.090810331638e-05 2.399997909199e+01 2.044715368548e-02 - 12.5 2.951795282278e-04 2.951793938629e-04 2.399970482061e+01 7.995922685941e-02 - 13.5 3.221164570742e-03 3.221163321490e-03 2.399677883641e+01 2.567109777341e-01 - 14.5 2.715473190226e-02 2.715472330367e-02 2.397284527577e+01 6.850286499844e-01 - 15.5 1.753541123879e-01 1.753540697297e-01 2.382464592812e+01 1.533872870596e+00 - 16.5 8.525032220200e-01 8.525030769812e-01 2.314749691919e+01 2.902126148041e+00 - 17.5 3.032149931402e+00 3.032149625513e+00 2.096785036949e+01 4.663139220104e+00 - 18.5 7.550952821146e+00 7.550952502686e+00 1.644904749357e+01 6.385483516941e+00 - 19.5 1.235834674495e+01 1.235834658501e+01 1.164165341481e+01 7.468268986482e+00 diff --git a/Sun/examples/ex12a.log b/Sun/examples/ex12a.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex12a.out b/Sun/examples/ex12a.out deleted file mode 100644 index 1dc02b37..00000000 --- a/Sun/examples/ex12a.out +++ /dev/null @@ -1,188 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex12a - Output file: ex12a.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 12a.--Advective and diffusive transport of heat and solutes. - Constant boundary condition at one end, closed at other. - The problem is designed so that temperature should equal Na-conc - (in mmol/kgw) after diffusion. Compares with analytical solution - for 20-cell and 60-cell models. - EXCHANGE_SPECIES - Na+ + X- = NaX - log_k 0.0 - gamma 4.0 0.075 - H+ + X- = HX - log_k -99. - gamma 9.0 0.0 - K+ + X- = KX - log_k 0.0 - gamma 3.5 0.015 - SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - SOLUTION 1-19 24.0 mM KNO3 - units mol/kgw - temp 0 # Incoming solution 0C - pH 7.0 - pe 12.0 O2(g) -0.67 - K 24.e-3 - N(5) 24.e-3 - EXCHANGE 1-19 - KX 0.048 - SOLUTION 20 Same as soln 0 in cell 20 at closed column end (second type boundary cond) - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - EXCHANGE 20 - NaX 0.048 - PRINT - reset false - END - TRANSPORT # Diffuse 24C, NaCl solution from column end - cells 20 - shifts 1 - flow_direction diffusion - bcond constant closed - length 1.0 - thermal_diffusion 3.0 # Heat is retarded equal to Na - disp 0.0 # No dispersion - diffc 0.3e-9 # m^2/s - timest 1.0e+10 # 317 years, 19 substeps will be used - SELECTED_OUTPUT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. - file ex12a.sel - high_precision true - reset false - distance true - temperature true - USER_PUNCH - heading Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic - 10 PUNCH TOT("Na")*1000, TOT("K")*1000, TOT("Cl")*1000 - 20 DATA 0.254829592, -0.284496736, 1.421413741, -1.453152027, 1.061405429 - 30 x = DIST - 40 if (x > 8.5 OR SIM_TIME <= 0) THEN END - 50 IF (ABS(x MOD 0.5) > 1e-3) OR (TC <= 0) THEN END - 60 READ a1, a2, a3, a4, a5 - 70 REM calculate error in Cl - 80 Arg = x / (2*SQRT(3e-10 * SIM_TIME / 1.0)) - 90 e = 1/(1 + 0.3275911 * Arg) - 100 erfc_Cl = (e*(a1+e*(a2+e*(a3+e*(a4+e*a5)))))*EXP(-Arg*Arg) - 110 REM calculate error in Na - 120 Arg = x / (2*SQRT(3e-10 * SIM_TIME / 3.0)) - 130 e = 1/(1 + 0.3275911 * Arg) - 140 erfc_Na = (e*(a1+e*(a2+e*(a3+e*(a4+e*a5)))))*EXP(-Arg*Arg) - 150 REM punch results - 160 error_Cl = 0.024 * erfc_Cl - TOT("Cl") - 170 error_Na = 0.024 * erfc_Na - TOT("Na") - 180 PUNCH error_Cl, error_Na - 190 REM store results - 200 j = x - 0.5 - 210 PUT(error_Cl, SIM_NO, j, 1) - 220 PUT(error_Na, SIM_NO, j, 2) - 500 END - END - SELECTED_OUTPUT - user_punch false - SOLUTION 0 Fixed temp 24C, and NaCl conc (first type boundary cond) at inlet - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - SOLUTION 1-59 24.0 mM KNO3 - units mol/kgw - temp 0 # Incoming solution 0C - pH 7.0 - pe 12.0 O2(g) -0.67 - K 24.e-3 - N(5) 24.e-3 - EXCHANGE 1-59 - KX 0.048 - SOLUTION 60 Same as soln 0 in cell 60 at closed column end (second type boundary cond) - units mol/kgw - temp 24 - pH 7.0 - pe 12.0 O2(g) -0.67 - Na 24.e-3 - Cl 24.e-3 - EXCHANGE 60 - NaX 0.048 - END - TRANSPORT # Diffuse 24C, NaCl solution from column end - cells 60 - shifts 1 - flow_direction diffusion - bcond constant closed - thermal_diffusion 3.0 # Heat is retarded equal to Na - disp 0.0 # No dispersion - diffc 0.3e-9 # m^2/s - length .33333333333333333 - timest 1.0e+10 # 317 years - punch_cells 1-60 - SELECTED_OUTPUT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 60. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 60. - high_precision true - user_punch true - reset false - distance true - temperature true - END - SOLUTION # Initial solution calculation for pure water - PRINT - reset false # Initial solution calculation not printed - user_print true - SELECTED_OUTPUT - high_precision false # Controls precision for USER_PRINT too. - USER_PRINT - 10 PRINT " Error in Cl concentration Error in Na concentration" - 20 PRINT " ------------------------- -------------------------" - 30 PRINT " Distance 20-cell 60-cell 20-cell 60-cell" - 40 PRINT " " - 50 FOR j = 0 TO 8 - 60 PRINT j + 0.5, GET(2, j, 1), GET(4, j, 1), GET(2, j, 2), GET(4, j, 2) - 70 NEXT j - END -----------------------------------User print----------------------------------- - - Error in Cl concentration Error in Na concentration - ------------------------- ------------------------- - Distance 20-cell 60-cell 20-cell 60-cell - - 5.0000e-01 4.3817e-06 9.0009e-08 5.0636e-04 3.9397e-05 - 1.5000e+00 1.7304e-05 1.0407e-06 5.1077e-04 5.5286e-05 - 2.5000e+00 3.5613e-05 3.2028e-06 9.0486e-05 1.4725e-05 - 3.5000e+00 4.9599e-05 5.2170e-06 -3.7312e-05 -3.8884e-06 - 4.5000e+00 5.0063e-05 5.6394e-06 -1.9794e-05 -2.5770e-06 - 5.5000e+00 3.8208e-05 4.4562e-06 -4.0684e-06 -5.0254e-07 - 6.5000e+00 2.2627e-05 2.7007e-06 -4.8926e-07 -4.8938e-08 - 7.5000e+00 1.0547e-05 1.2850e-06 -3.9174e-08 -2.7009e-09 - 8.5000e+00 3.8231e-06 4.5302e-07 -2.2318e-09 -9.0081e-11 - -No memory leaks diff --git a/Sun/examples/ex12a.sel b/Sun/examples/ex12a.sel deleted file mode 100644 index 2a0be12f..00000000 --- a/Sun/examples/ex12a.sel +++ /dev/null @@ -1,169 +0,0 @@ - dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic - 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000009e+01 0.000000000000e+00 - 19.5 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - 0.5 1.686181418415e+01 1.686181419284e+01 7.138185798940e+00 2.011377529332e+01 4.381717721817e-06 5.063555346726e-04 - 1.5 6.421492325960e+00 6.421492401967e+00 1.757850758482e+01 1.294968671951e+01 1.730376465525e-05 5.107739267532e-04 - 2.5 1.759908541854e+00 1.759908596887e+00 2.224009139342e+01 7.342808261321e+00 3.561257289983e-05 9.048612448212e-05 - 3.5 3.571924631562e-01 3.571924817826e-01 2.364280751302e+01 3.623408283684e+00 4.959925523712e-05 -3.731213350966e-05 - 4.5 5.490209781370e-02 5.490210180416e-02 2.394509789597e+01 1.538555967129e+00 5.006313596727e-05 -1.979378199416e-05 - 5.5 6.484238380348e-03 6.484238983030e-03 2.399351576028e+01 5.556625533113e-01 3.820767165714e-05 -4.068366980646e-06 - 6.5 5.926340095484e-04 5.926340766447e-04 2.399940736578e+01 1.684990632469e-01 2.262672987200e-05 -4.892608394194e-07 - 7.5 4.190926756604e-05 4.190927316640e-05 2.399995809078e+01 4.224784404205e-02 1.054699173423e-05 -3.917411153365e-08 - 8.5 2.276345750780e-06 2.276346101865e-06 2.399999772376e+01 8.664946370896e-03 3.823149392506e-06 -2.231772077916e-09 - 9.5 1.396593677778e-07 1.396593921606e-07 2.399999986046e+01 2.055609847093e-03 - 10.5 1.138869021831e-06 1.138869196840e-06 2.399999886124e+01 4.374443607427e-03 - 11.5 2.090811414205e-05 2.090811693112e-05 2.399997909197e+01 2.044715368548e-02 - 12.5 2.951795282278e-04 2.951795617161e-04 2.399970482043e+01 7.995922685941e-02 - 13.5 3.221164570742e-03 3.221164872772e-03 2.399677883485e+01 2.567109777341e-01 - 14.5 2.715473190226e-02 2.715473392142e-02 2.397284526515e+01 6.850286499844e-01 - 15.5 1.753541123879e-01 1.753541220807e-01 2.382464587576e+01 1.533872870596e+00 - 16.5 8.525032220200e-01 8.525032534626e-01 2.314749674271e+01 2.902126148041e+00 - 17.5 3.032149931402e+00 3.032149994216e+00 2.096785000078e+01 4.663139220104e+00 - 18.5 7.550952821146e+00 7.550952899109e+00 1.644904709714e+01 6.385483516941e+00 - 19.5 1.235834674495e+01 1.235834684370e+01 1.164165315611e+01 7.468268986482e+00 - dist_x temp - -99 2.400000000000e+01 - -99 0.000000000000e+00 - -99 2.400000000000e+01 - -99 2.400000000000e+01 - dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic - 0.166667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 0.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 0.833333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 1.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 1.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 1.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 2.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 2.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 2.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 3.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 3.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 3.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 4.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 4.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 4.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 5.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 5.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 5.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 6.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 6.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 6.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 7.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 7.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 7.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 8.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 8.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 8.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 9.16667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 9.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 9.83333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 10.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 10.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 10.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 11.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 11.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 11.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 12.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 12.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 12.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 13.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 13.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 13.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 14.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 14.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 14.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 15.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 15.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 15.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 16.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 16.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 16.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 17.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 17.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 17.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 18.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 18.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 18.8333 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 19.1667 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 19.5 0.000000000000e+00 0.000000000000e+00 2.400000000000e+01 0.000000000000e+00 - 19.8333 2.400000000000e+01 2.400000000000e+01 0.000000000000e+00 2.400000000000e+01 - 0.166667 2.173421305916e+01 2.173421306343e+01 2.265786933713e+00 2.269804666237e+01 - 0.5 1.732877230198e+01 1.732877231885e+01 6.671227673618e+00 2.011806700231e+01 9.000873062853e-08 3.939740866218e-05 - 0.833333 1.328083118787e+01 1.328083122259e+01 1.071916876673e+01 1.760855984610e+01 - 1.16667 9.764783869793e+00 9.764783923632e+00 1.423521606399e+01 1.521226338251e+01 - 1.5 6.876979954453e+00 6.876980022636e+00 1.712301996456e+01 1.296594983180e+01 1.040652364160e-06 5.528630608450e-05 - 1.83333 4.633445178532e+00 4.633445251920e+00 1.936655473578e+01 1.089878644688e+01 - 2.16667 2.983957613764e+00 2.983957682799e+00 2.101604230602e+01 9.031332911172e+00 - 2.5 1.835670035272e+00 1.835670093239e+00 2.216432989702e+01 7.375218041863e+00 3.202792358406e-06 1.472462813043e-05 - 2.83333 1.078309641703e+00 1.078309685856e+00 2.292169030595e+01 5.933464823536e+00 - 3.16667 6.047271172834e-01 6.047271481610e-01 2.339527284513e+01 4.701369002513e+00 - 3.5 3.237687663205e-01 3.237687863260e-01 2.367623120832e+01 3.667790505378e+00 5.217033543007e-06 -3.888438053093e-06 - 3.83333 1.655091653734e-01 1.655091774636e-01 2.383449081836e+01 2.816693047508e+00 - 4.16667 8.080184009388e-02 8.080184694439e-02 2.391919814987e+01 2.128765884991e+00 - 4.5 3.768529738011e-02 3.768530103391e-02 2.396231469660e+01 1.582979737206e+00 5.639365889894e-06 -2.576981223905e-06 - 4.83333 1.679748179371e-02 1.679748363383e-02 2.398320251464e+01 1.157961028529e+00 - 5.16667 7.158658672534e-03 7.158659549847e-03 2.399284133922e+01 8.331081560779e-01 - 5.5 2.918406916536e-03 2.918407313331e-03 2.399708159183e+01 5.894139758477e-01 4.456249120743e-06 -5.025353109470e-07 - 5.83333 1.138704483513e-03 1.138704654056e-03 2.399886129476e+01 4.099947290008e-01 - 6.16667 4.254614091980e-04 4.254614789566e-04 2.399957453813e+01 2.803535790356e-01 - 6.5 1.523110828875e-04 1.523111100786e-04 2.399984768864e+01 1.884251292313e-01 2.700663887612e-06 -4.893787285338e-08 - 6.83333 5.227158932778e-05 5.227159943954e-05 2.399994772825e+01 1.244558376472e-01 - 7.16667 1.720693829075e-05 1.720694188206e-05 2.399998279298e+01 8.077556918093e-02 - 7.5 5.436060808742e-06 5.436062028079e-06 2.399999456390e+01 5.150981286307e-02 1.285022913218e-06 -2.700900395322e-09 - 7.83333 1.649087567417e-06 1.649087963540e-06 2.399999835090e+01 3.227276557119e-02 - 8.16667 4.806328011003e-07 4.806329243359e-07 2.399999951938e+01 1.987075437176e-02 - 8.5 1.346545980534e-07 1.346546347973e-07 2.399999986537e+01 1.203507596490e-02 4.530197984976e-07 -9.008061084852e-11 - 8.83333 3.628418612942e-08 3.628419663780e-08 2.399999996375e+01 7.194421703709e-03 - 9.16667 9.420115605087e-09 9.420118494085e-09 2.399999999061e+01 4.290208467916e-03 - 9.5 2.409789753518e-09 2.409790536015e-09 2.399999999763e+01 2.633460429579e-03 - 9.83333 8.318493065839e-10 8.318495907164e-10 2.399999999921e+01 1.799170182453e-03 - 10.1667 1.239138622414e-09 1.239139029450e-09 2.399999999880e+01 1.552911248870e-03 - 10.5 4.450121249069e-09 4.450122620282e-09 2.399999999559e+01 1.804410616828e-03 - 10.8333 1.697307773631e-08 1.697308267056e-08 2.399999998306e+01 2.583364148394e-03 - 11.1667 6.262520065472e-08 6.262521780825e-08 2.399999993741e+01 4.033590225456e-03 - 11.5 2.221760110271e-07 2.221760682136e-07 2.399999977785e+01 6.422343300949e-03 - 11.8333 7.572168365738e-07 7.572170191795e-07 2.399999924281e+01 1.016200278611e-02 - 12.1667 2.477714073998e-06 2.477714631994e-06 2.399999752230e+01 1.584124624556e-02 - 12.5 7.778925375184e-06 7.778927005412e-06 2.399999222108e+01 2.426212581439e-02 - 12.8333 2.341776426203e-05 2.341776881132e-05 2.399997658222e+01 3.647820852624e-02 - 13.1667 6.755207229881e-05 6.755208441218e-05 2.399993244787e+01 5.382725013175e-02 - 13.5 1.865949099352e-04 1.865949406769e-04 2.399981340498e+01 7.795002257855e-02 - 13.8333 4.931967003130e-04 4.931967745830e-04 2.399950680310e+01 1.107853267574e-01 - 14.1667 1.246472753669e-03 1.246472924261e-03 2.399875352688e+01 1.545304347559e-01 - 14.5 3.009977094510e-03 3.009977466523e-03 2.399699002225e+01 2.115568175130e-01 - 14.8333 6.939537438586e-03 6.939538207639e-03 2.399306046140e+01 2.842735712027e-01 - 15.1667 1.526331935379e-02 1.526332085840e-02 2.398473667861e+01 3.749358095681e-01 - 15.5 3.200217915009e-02 3.200218193090e-02 2.396799781737e+01 4.854024361712e-01 - 15.8333 6.391193399667e-02 6.391193884267e-02 2.393608806026e+01 6.168566584837e-01 - 16.1667 1.214834631133e-01 1.214834710604e-01 2.387851652783e+01 7.695123116931e-01 - 16.5 2.196089759550e-01 2.196089881955e-01 2.378039101048e+01 9.423379783552e-01 - 16.8333 3.772704376914e-01 3.772704553669e-01 2.362272954311e+01 1.132837159798e+00 - 17.1667 6.154714589941e-01 6.154714828922e-01 2.338452851541e+01 1.336924520486e+00 - 17.5 9.528239860304e-01 9.528240162733e-01 2.304717598190e+01 1.548934044811e+00 - 17.8333 1.398887571630e+00 1.398887607499e+00 2.260111239061e+01 1.761784203671e+00 - 18.1667 1.946511170344e+00 1.946511210371e+00 2.205348878777e+01 1.967308461518e+00 - 18.5 2.565669345631e+00 2.565669387970e+00 2.143433061028e+01 2.156738468785e+00 - 18.8333 3.201925616708e+00 3.201925659659e+00 2.079807433877e+01 2.321305007457e+00 - 19.1667 3.781994216092e+00 3.781994258530e+00 2.021800574010e+01 2.452901809002e+00 - 19.5 4.226690935644e+00 4.226690977196e+00 1.977330902162e+01 2.544743405451e+00 - 19.8333 4.468507319433e+00 4.468507360365e+00 1.953149263856e+01 2.591943163049e+00 - dist_x temp Na_mmol K_mmol Cl_mmol Cl-analytic Na_analytic - -99 25.000 0.0000e+00 0.0000e+00 0.0000e+00 diff --git a/Sun/examples/ex13a.log b/Sun/examples/ex13a.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex13a.out b/Sun/examples/ex13a.out deleted file mode 100644 index 77218db9..00000000 --- a/Sun/examples/ex13a.out +++ /dev/null @@ -1,310 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13a - Output file: ex13a.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 13A.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - Implicit definition of first-order exchange model. - SOLUTION 0 # 1 mmol/l NaCl - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - Na 1.0 # Na has Retardation = 2 - Cl 1.0 # Cl has Retardation = 1, stagnant exchange - N(5) 1.0 # NO3 is conservative - END ------ -TITLE ------ - - Example 13A.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - Implicit definition of first-order exchange model. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.500e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.551e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.000e-03 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 - H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -Cl 1.000e-03 - Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 -Na 1.000e-03 - Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 - NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 -O(0) 4.374e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.62 -6.04 1.58 NaCl - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1-41 # Column with KNO3 - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - EXCHANGE 1-41 - equilibrate 1 - X 1.e-3 - EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX - K+ + X- = KX - log_k 0.0 - gamma 3.5 0.015 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.70 -3.66 -2.96 O2 - -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using exchange 1. Exchange assemblage after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 13.605 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 - NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 -N(0) 1.994e-19 - N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 -N(3) 2.291e-16 - NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.74 -19.00 -3.26 N2 - NH3(g) -66.79 -65.02 1.77 NH3 - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - TRANSPORT - cells 20 - shifts 5 - flow_direction forward - timest 3600 - bcond flux flux - diffc 0.0 - length 0.1 - disp 0.015 - stagnant 1 6.8e-6 0.3 0.1 - PRINT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. - reset false - END - SOLUTION 0 # Original solution reenters - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - TRANSPORT - shifts 10 - punch_frequency 10 - punch_cells 1-20 - SELECTED_OUTPUT - file ex13a.sel - reset false - solution - distance true - USER_PUNCH - heading Cl_mmol Na_mmol - 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 - END -No memory leaks diff --git a/Sun/examples/ex13a.sel b/Sun/examples/ex13a.sel deleted file mode 100644 index 68d5fffe..00000000 --- a/Sun/examples/ex13a.sel +++ /dev/null @@ -1,42 +0,0 @@ - soln dist_x Cl_mmol Na_mmol - 0 -99 0.0000e+00 0.0000e+00 - 1 0.05 9.6495e-01 8.8504e-01 - 2 0.15 9.1812e-01 6.9360e-01 - 3 0.25 8.4451e-01 4.3288e-01 - 4 0.35 7.1652e-01 1.9734e-01 - 5 0.45 4.9952e-01 6.0705e-02 - 6 0.55 2.4048e-01 1.1785e-02 - 7 0.65 7.2812e-02 1.4039e-03 - 8 0.75 1.3132e-02 9.9324e-05 - 9 0.85 1.2882e-03 3.8318e-06 - 10 0.95 5.2940e-05 6.2140e-08 - 11 1.05 0.0000e+00 0.0000e+00 - 12 1.15 0.0000e+00 0.0000e+00 - 13 1.25 0.0000e+00 0.0000e+00 - 14 1.35 0.0000e+00 0.0000e+00 - 15 1.45 0.0000e+00 0.0000e+00 - 16 1.55 0.0000e+00 0.0000e+00 - 17 1.65 0.0000e+00 0.0000e+00 - 18 1.75 0.0000e+00 0.0000e+00 - 19 1.85 0.0000e+00 0.0000e+00 - 20 1.95 0.0000e+00 0.0000e+00 - 1 0.05 7.5889e-03 2.0250e-02 - 2 0.15 1.7993e-02 5.0943e-02 - 3 0.25 3.3135e-02 1.0209e-01 - 4 0.35 5.3591e-02 1.7480e-01 - 5 0.45 8.0158e-02 2.5484e-01 - 6 0.55 1.1396e-01 3.1308e-01 - 7 0.65 1.5767e-01 3.2277e-01 - 8 0.75 2.1666e-01 2.7968e-01 - 9 0.85 2.9573e-01 2.0468e-01 - 10 0.95 3.8769e-01 1.2726e-01 - 11 1.05 4.6467e-01 6.7581e-02 - 12 1.15 4.9243e-01 3.0745e-02 - 13 1.25 4.5811e-01 1.1988e-02 - 14 1.35 3.7620e-01 3.9981e-03 - 15 1.45 2.7323e-01 1.1366e-03 - 16 1.55 1.7416e-01 2.7440e-04 - 17 1.65 9.6074e-02 5.6038e-05 - 18 1.75 4.5211e-02 9.6477e-06 - 19 1.85 1.7934e-02 1.3954e-06 - 20 1.95 6.4869e-03 1.7678e-07 diff --git a/Sun/examples/ex13b.log b/Sun/examples/ex13b.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex13b.out b/Sun/examples/ex13b.out deleted file mode 100644 index f705879b..00000000 --- a/Sun/examples/ex13b.out +++ /dev/null @@ -1,430 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13b - Output file: ex13b.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 13B.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - Explicit definition of first-order exchange factors. - SOLUTION 0 # 1 mmol/l NaCl - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - Na 1.0 # Na has Retardation = 2 - Cl 1.0 # Cl has Retardation = 1, stagnant exchange - N(5) 1.0 # NO3 is conservative - END ------ -TITLE ------ - - Example 13B.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - Explicit definition of first-order exchange factors. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.500e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.551e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.000e-03 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 - H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -Cl 1.000e-03 - Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 -Na 1.000e-03 - Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 - NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 -O(0) 4.374e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.62 -6.04 1.58 NaCl - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1-41 # Column with KNO3 - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - EXCHANGE 1-41 - equilibrate 1 - X 1.e-3 - EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX - K+ + X- = KX - log_k 0.0 - gamma 3.5 0.015 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.70 -3.66 -2.96 O2 - -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using exchange 1. Exchange assemblage after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 13.605 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 - NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 -N(0) 1.994e-19 - N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 -N(3) 2.291e-16 - NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.74 -19.00 -3.26 N2 - NH3(g) -66.79 -65.02 1.77 NH3 - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - MIX 1 - 1 .93038 - 22 .06962 - MIX 2 - 2 .93038 - 23 .06962 - MIX 3 - 3 .93038 - 24 .06962 - MIX 4 - 4 .93038 - 25 .06962 - MIX 5 - 5 .93038 - 26 .06962 - MIX 6 - 6 .93038 - 27 .06962 - MIX 7 - 7 .93038 - 28 .06962 - MIX 8 - 8 .93038 - 29 .06962 - MIX 9 - 9 .93038 - 30 .06962 - MIX 10 - 10 .93038 - 31 .06962 - MIX 11 - 11 .93038 - 32 .06962 - MIX 12 - 12 .93038 - 33 .06962 - MIX 13 - 13 .93038 - 34 .06962 - MIX 14 - 14 .93038 - 35 .06962 - MIX 15 - 15 .93038 - 36 .06962 - MIX 16 - 16 .93038 - 37 .06962 - MIX 17 - 17 .93038 - 38 .06962 - MIX 18 - 18 .93038 - 39 .06962 - MIX 19 - 19 .93038 - 40 .06962 - MIX 20 - 20 .93038 - 41 .06962 - MIX 22 - 1 .20886 - 22 .79114 - MIX 23 - 2 .20886 - 23 .79114 - MIX 24 - 3 .20886 - 24 .79114 - MIX 25 - 4 .20886 - 25 .79114 - MIX 26 - 5 .20886 - 26 .79114 - MIX 27 - 6 .20886 - 27 .79114 - MIX 28 - 7 .20886 - 28 .79114 - MIX 29 - 8 .20886 - 29 .79114 - MIX 30 - 9 .20886 - 30 .79114 - MIX 31 - 10 .20886 - 31 .79114 - MIX 32 - 11 .20886 - 32 .79114 - MIX 33 - 12 .20886 - 33 .79114 - MIX 34 - 13 .20886 - 34 .79114 - MIX 35 - 14 .20886 - 35 .79114 - MIX 36 - 15 .20886 - 36 .79114 - MIX 37 - 16 .20886 - 37 .79114 - MIX 38 - 17 .20886 - 38 .79114 - MIX 39 - 18 .20886 - 39 .79114 - MIX 40 - 19 .20886 - 40 .79114 - MIX 41 - 20 .20886 - 41 .79114 - TRANSPORT - cells 20 - shifts 5 - flow_direction forward - timest 3600 - bcond flux flux - diffc 0.0 - length 0.1 - disp 0.015 - stagnant 1 - PRINT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. - reset false - END - SOLUTION 0 # Original solution reenters - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - TRANSPORT - shifts 10 - punch_frequency 10 - punch_cells 1-20 - SELECTED_OUTPUT - file ex13b.sel - reset false - distance true - solution - USER_PUNCH - heading Cl_mmol Na_mmol - 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 - END -No memory leaks diff --git a/Sun/examples/ex13b.sel b/Sun/examples/ex13b.sel deleted file mode 100644 index 21837b16..00000000 --- a/Sun/examples/ex13b.sel +++ /dev/null @@ -1,42 +0,0 @@ - soln dist_x Cl_mmol Na_mmol - 0 -99 0.0000e+00 0.0000e+00 - 1 0.05 9.6495e-01 8.8504e-01 - 2 0.15 9.1812e-01 6.9360e-01 - 3 0.25 8.4451e-01 4.3288e-01 - 4 0.35 7.1652e-01 1.9734e-01 - 5 0.45 4.9952e-01 6.0705e-02 - 6 0.55 2.4048e-01 1.1785e-02 - 7 0.65 7.2813e-02 1.4039e-03 - 8 0.75 1.3132e-02 9.9324e-05 - 9 0.85 1.2882e-03 3.8318e-06 - 10 0.95 5.2941e-05 6.2140e-08 - 11 1.05 0.0000e+00 0.0000e+00 - 12 1.15 0.0000e+00 0.0000e+00 - 13 1.25 0.0000e+00 0.0000e+00 - 14 1.35 0.0000e+00 0.0000e+00 - 15 1.45 0.0000e+00 0.0000e+00 - 16 1.55 0.0000e+00 0.0000e+00 - 17 1.65 0.0000e+00 0.0000e+00 - 18 1.75 0.0000e+00 0.0000e+00 - 19 1.85 0.0000e+00 0.0000e+00 - 20 1.95 0.0000e+00 0.0000e+00 - 1 0.05 7.5889e-03 2.0249e-02 - 2 0.15 1.7993e-02 5.0943e-02 - 3 0.25 3.3135e-02 1.0209e-01 - 4 0.35 5.3590e-02 1.7480e-01 - 5 0.45 8.0158e-02 2.5484e-01 - 6 0.55 1.1395e-01 3.1308e-01 - 7 0.65 1.5766e-01 3.2277e-01 - 8 0.75 2.1666e-01 2.7969e-01 - 9 0.85 2.9573e-01 2.0468e-01 - 10 0.95 3.8768e-01 1.2727e-01 - 11 1.05 4.6467e-01 6.7581e-02 - 12 1.15 4.9243e-01 3.0745e-02 - 13 1.25 4.5811e-01 1.1988e-02 - 14 1.35 3.7620e-01 3.9981e-03 - 15 1.45 2.7323e-01 1.1366e-03 - 16 1.55 1.7416e-01 2.7440e-04 - 17 1.65 9.6075e-02 5.6039e-05 - 18 1.75 4.5211e-02 9.6477e-06 - 19 1.85 1.7934e-02 1.3954e-06 - 20 1.95 6.4870e-03 1.7678e-07 diff --git a/Sun/examples/ex13c.log b/Sun/examples/ex13c.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex13c.out b/Sun/examples/ex13c.out deleted file mode 100644 index d073ce4e..00000000 --- a/Sun/examples/ex13c.out +++ /dev/null @@ -1,751 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex13c - Output file: ex13c.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 13C.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - 5 layer stagnant zone with finite differences. - SOLUTION 0 # 1 mmol/l NaCl - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - Na 1.0 # Na has Retardation = 2 - Cl 1.0 # Cl has Retardation = 1, stagnant exchange - N(5) 1.0 # NO3 is conservative - END ------ -TITLE ------ - - Example 13C.--1 mmol/l NaCl/NO3 enters column with stagnant zones. - 5 layer stagnant zone with finite differences. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.500e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.551e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.000e-03 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -33.33 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.046e-07 1.001e-07 -6.981 -7.000 -0.019 - H+ 1.042e-07 1.000e-07 -6.982 -7.000 -0.018 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -Cl 1.000e-03 - Cl- 1.000e-03 9.576e-04 -3.000 -3.019 -0.019 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.573e-04 -3.000 -3.019 -0.019 -Na 1.000e-03 - Na+ 1.000e-03 9.580e-04 -3.000 -3.019 -0.019 - NaOH 6.327e-11 6.329e-11 -10.199 -10.199 0.000 -O(0) 4.374e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -7.62 -6.04 1.58 NaCl - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1-121 # Column with KNO3 - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - EXCHANGE 1-121 - equilibrate 1 - X 1.e-3 - EXCHANGE_SPECIES # For linear exchange, make KX exch. coeff. equal to NaX - K+ + X- = KX - log_k 0.0 - gamma 3.5 0.015 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N(5) 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.605 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -0.70 -3.66 -2.96 O2 - -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using exchange 1. Exchange assemblage after simulation 2. - ------------------------------Exchange composition------------------------------ - -X 1.000e-03 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - KX 1.000e-03 1.000e-03 1.000e+00 -0.016 - NH4X 6.872e-63 6.872e-63 6.872e-60 -0.016 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - K 1.000e-03 1.000e-03 - N 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 13.605 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.351e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.351e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.038e-07 1.001e-07 -6.984 -7.000 -0.016 - H+ 1.034e-07 1.000e-07 -6.985 -7.000 -0.015 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -K 1.000e-03 - K+ 1.000e-03 9.649e-04 -3.000 -3.016 -0.016 - KOH 3.345e-11 3.346e-11 -10.476 -10.476 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -62.763 -62.779 -0.016 - NH3 0.000e+00 0.000e+00 -65.023 -65.023 0.000 -N(0) 1.994e-19 - N2 9.971e-20 9.973e-20 -19.001 -19.001 0.000 -N(3) 2.291e-16 - NO2- 2.291e-16 2.210e-16 -15.640 -15.656 -0.016 -N(5) 1.000e-03 - NO3- 1.000e-03 9.647e-04 -3.000 -3.016 -0.016 -O(0) 4.375e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -15.74 -19.00 -3.26 N2 - NH3(g) -66.79 -65.02 1.77 NH3 - O2(g) -0.70 -3.66 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - MIX 1 - 1 0.90712 - 22 0.09288 - MIX 22 - 1 0.57098 - 22 0.21656 - 42 0.21246 - MIX 42 - 22 0.35027 - 42 0.45270 - 62 0.19703 - MIX 62 - 42 0.38368 - 62 0.44579 - 82 0.17053 - MIX 82 - 62 0.46286 - 82 0.42143 - 102 0.11571 - MIX 102 - 82 0.81000 - 102 0.19000 - MIX 2 - 2 0.90712 - 23 0.09288 - MIX 23 - 2 0.57098 - 23 0.21656 - 43 0.21246 - MIX 43 - 23 0.35027 - 43 0.45270 - 63 0.19703 - MIX 63 - 43 0.38368 - 63 0.44579 - 83 0.17053 - MIX 83 - 63 0.46286 - 83 0.42143 - 103 0.11571 - MIX 103 - 83 0.81000 - 103 0.19000 - MIX 3 - 3 0.90712 - 24 0.09288 - MIX 24 - 3 0.57098 - 24 0.21656 - 44 0.21246 - MIX 44 - 24 0.35027 - 44 0.45270 - 64 0.19703 - MIX 64 - 44 0.38368 - 64 0.44579 - 84 0.17053 - MIX 84 - 64 0.46286 - 84 0.42143 - 104 0.11571 - MIX 104 - 84 0.81000 - 104 0.19000 - MIX 4 - 4 0.90712 - 25 0.09288 - MIX 25 - 4 0.57098 - 25 0.21656 - 45 0.21246 - MIX 45 - 25 0.35027 - 45 0.45270 - 65 0.19703 - MIX 65 - 45 0.38368 - 65 0.44579 - 85 0.17053 - MIX 85 - 65 0.46286 - 85 0.42143 - 105 0.11571 - MIX 105 - 85 0.81000 - 105 0.19000 - MIX 5 - 5 0.90712 - 26 0.09288 - MIX 26 - 5 0.57098 - 26 0.21656 - 46 0.21246 - MIX 46 - 26 0.35027 - 46 0.45270 - 66 0.19703 - MIX 66 - 46 0.38368 - 66 0.44579 - 86 0.17053 - MIX 86 - 66 0.46286 - 86 0.42143 - 106 0.11571 - MIX 106 - 86 0.81000 - 106 0.19000 - MIX 6 - 6 0.90712 - 27 0.09288 - MIX 27 - 6 0.57098 - 27 0.21656 - 47 0.21246 - MIX 47 - 27 0.35027 - 47 0.45270 - 67 0.19703 - MIX 67 - 47 0.38368 - 67 0.44579 - 87 0.17053 - MIX 87 - 67 0.46286 - 87 0.42143 - 107 0.11571 - MIX 107 - 87 0.81000 - 107 0.19000 - MIX 7 - 7 0.90712 - 28 0.09288 - MIX 28 - 7 0.57098 - 28 0.21656 - 48 0.21246 - MIX 48 - 28 0.35027 - 48 0.45270 - 68 0.19703 - MIX 68 - 48 0.38368 - 68 0.44579 - 88 0.17053 - MIX 88 - 68 0.46286 - 88 0.42143 - 108 0.11571 - MIX 108 - 88 0.81000 - 108 0.19000 - MIX 8 - 8 0.90712 - 29 0.09288 - MIX 29 - 8 0.57098 - 29 0.21656 - 49 0.21246 - MIX 49 - 29 0.35027 - 49 0.45270 - 69 0.19703 - MIX 69 - 49 0.38368 - 69 0.44579 - 89 0.17053 - MIX 89 - 69 0.46286 - 89 0.42143 - 109 0.11571 - MIX 109 - 89 0.81000 - 109 0.19000 - MIX 9 - 9 0.90712 - 30 0.09288 - MIX 30 - 9 0.57098 - 30 0.21656 - 50 0.21246 - MIX 50 - 30 0.35027 - 50 0.45270 - 70 0.19703 - MIX 70 - 50 0.38368 - 70 0.44579 - 90 0.17053 - MIX 90 - 70 0.46286 - 90 0.42143 - 110 0.11571 - MIX 110 - 90 0.81000 - 110 0.19000 - MIX 10 - 10 0.90712 - 31 0.09288 - MIX 31 - 10 0.57098 - 31 0.21656 - 51 0.21246 - MIX 51 - 31 0.35027 - 51 0.45270 - 71 0.19703 - MIX 71 - 51 0.38368 - 71 0.44579 - 91 0.17053 - MIX 91 - 71 0.46286 - 91 0.42143 - 111 0.11571 - MIX 111 - 91 0.81000 - 111 0.19000 - MIX 11 - 11 0.90712 - 32 0.09288 - MIX 32 - 11 0.57098 - 32 0.21656 - 52 0.21246 - MIX 52 - 32 0.35027 - 52 0.45270 - 72 0.19703 - MIX 72 - 52 0.38368 - 72 0.44579 - 92 0.17053 - MIX 92 - 72 0.46286 - 92 0.42143 - 112 0.11571 - MIX 112 - 92 0.81000 - 112 0.19000 - MIX 12 - 12 0.90712 - 33 0.09288 - MIX 33 - 12 0.57098 - 33 0.21656 - 53 0.21246 - MIX 53 - 33 0.35027 - 53 0.45270 - 73 0.19703 - MIX 73 - 53 0.38368 - 73 0.44579 - 93 0.17053 - MIX 93 - 73 0.46286 - 93 0.42143 - 113 0.11571 - MIX 113 - 93 0.81000 - 113 0.19000 - MIX 13 - 13 0.90712 - 34 0.09288 - MIX 34 - 13 0.57098 - 34 0.21656 - 54 0.21246 - MIX 54 - 34 0.35027 - 54 0.45270 - 74 0.19703 - MIX 74 - 54 0.38368 - 74 0.44579 - 94 0.17053 - MIX 94 - 74 0.46286 - 94 0.42143 - 114 0.11571 - MIX 114 - 94 0.81000 - 114 0.19000 - MIX 14 - 14 0.90712 - 35 0.09288 - MIX 35 - 14 0.57098 - 35 0.21656 - 55 0.21246 - MIX 55 - 35 0.35027 - 55 0.45270 - 75 0.19703 - MIX 75 - 55 0.38368 - 75 0.44579 - 95 0.17053 - MIX 95 - 75 0.46286 - 95 0.42143 - 115 0.11571 - MIX 115 - 95 0.81000 - 115 0.19000 - MIX 15 - 15 0.90712 - 36 0.09288 - MIX 36 - 15 0.57098 - 36 0.21656 - 56 0.21246 - MIX 56 - 36 0.35027 - 56 0.45270 - 76 0.19703 - MIX 76 - 56 0.38368 - 76 0.44579 - 96 0.17053 - MIX 96 - 76 0.46286 - 96 0.42143 - 116 0.11571 - MIX 116 - 96 0.81000 - 116 0.19000 - MIX 16 - 16 0.90712 - 37 0.09288 - MIX 37 - 16 0.57098 - 37 0.21656 - 57 0.21246 - MIX 57 - 37 0.35027 - 57 0.45270 - 77 0.19703 - MIX 77 - 57 0.38368 - 77 0.44579 - 97 0.17053 - MIX 97 - 77 0.46286 - 97 0.42143 - 117 0.11571 - MIX 117 - 97 0.81000 - 117 0.19000 - MIX 17 - 17 0.90712 - 38 0.09288 - MIX 38 - 17 0.57098 - 38 0.21656 - 58 0.21246 - MIX 58 - 38 0.35027 - 58 0.45270 - 78 0.19703 - MIX 78 - 58 0.38368 - 78 0.44579 - 98 0.17053 - MIX 98 - 78 0.46286 - 98 0.42143 - 118 0.11571 - MIX 118 - 98 0.81000 - 118 0.19000 - MIX 18 - 18 0.90712 - 39 0.09288 - MIX 39 - 18 0.57098 - 39 0.21656 - 59 0.21246 - MIX 59 - 39 0.35027 - 59 0.45270 - 79 0.19703 - MIX 79 - 59 0.38368 - 79 0.44579 - 99 0.17053 - MIX 99 - 79 0.46286 - 99 0.42143 - 119 0.11571 - MIX 119 - 99 0.81000 - 119 0.19000 - MIX 19 - 19 0.90712 - 40 0.09288 - MIX 40 - 19 0.57098 - 40 0.21656 - 60 0.21246 - MIX 60 - 40 0.35027 - 60 0.45270 - 80 0.19703 - MIX 80 - 60 0.38368 - 80 0.44579 - 100 0.17053 - MIX 100 - 80 0.46286 - 100 0.42143 - 120 0.11571 - MIX 120 - 100 0.81000 - 120 0.19000 - MIX 20 - 20 0.90712 - 41 0.09288 - MIX 41 - 20 0.57098 - 41 0.21656 - 61 0.21246 - MIX 61 - 41 0.35027 - 61 0.45270 - 81 0.19703 - MIX 81 - 61 0.38368 - 81 0.44579 - 101 0.17053 - MIX 101 - 81 0.46286 - 101 0.42143 - 121 0.11571 - MIX 121 - 101 0.81000 - 121 0.19000 - TRANSPORT - cells 20 - shifts 5 - flow_direction forward - timest 3600 - tempr 3.0 - bcond flux flux - diffc 0.0 - length 0.10 - disp 0.015 - stagnant 5 - PRINT -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 20. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 20. - reset false - END - SOLUTION 0 # Original solution reenters - units mmol/l - pH 7.0 - pe 13.0 O2(g) -0.7 - K 1.0 - N(5) 1.0 - TRANSPORT - shifts 10 - punch_frequency 10 - punch_cells 1-20 - SELECTED_OUTPUT - file ex13c.sel - reset false - solution - distance true - USER_PUNCH - heading Cl_mmol Na_mmol - 10 PUNCH TOT("Cl")*1000, TOT("Na")*1000 - END -No memory leaks diff --git a/Sun/examples/ex13c.sel b/Sun/examples/ex13c.sel deleted file mode 100644 index 7969e528..00000000 --- a/Sun/examples/ex13c.sel +++ /dev/null @@ -1,42 +0,0 @@ - soln dist_x Cl_mmol Na_mmol - 0 -99 0.0000e+00 0.0000e+00 - 1 0.05 9.7683e-01 8.8829e-01 - 2 0.15 9.4255e-01 6.9066e-01 - 3 0.25 8.7253e-01 4.2503e-01 - 4 0.35 7.2600e-01 1.9091e-01 - 5 0.45 4.8246e-01 5.8021e-02 - 6 0.55 2.2239e-01 1.1177e-02 - 7 0.65 6.5489e-02 1.3256e-03 - 8 0.75 1.1639e-02 9.3569e-05 - 9 0.85 1.1350e-03 3.6065e-06 - 10 0.95 4.6646e-05 5.8485e-08 - 11 1.05 0.0000e+00 0.0000e+00 - 12 1.15 0.0000e+00 0.0000e+00 - 13 1.25 0.0000e+00 0.0000e+00 - 14 1.35 0.0000e+00 0.0000e+00 - 15 1.45 0.0000e+00 0.0000e+00 - 16 1.55 0.0000e+00 0.0000e+00 - 17 1.65 0.0000e+00 0.0000e+00 - 18 1.75 0.0000e+00 0.0000e+00 - 19 1.85 0.0000e+00 0.0000e+00 - 20 1.95 0.0000e+00 0.0000e+00 - 1 0.05 4.7101e-03 1.6916e-02 - 2 0.15 1.0234e-02 4.9729e-02 - 3 0.25 1.8109e-02 1.0883e-01 - 4 0.35 2.9565e-02 1.9194e-01 - 5 0.45 4.7408e-02 2.7841e-01 - 6 0.55 7.7191e-02 3.3492e-01 - 7 0.65 1.2832e-01 3.3632e-01 - 8 0.75 2.1109e-01 2.8375e-01 - 9 0.85 3.2572e-01 2.0251e-01 - 10 0.95 4.4908e-01 1.2304e-01 - 11 1.05 5.3819e-01 6.3977e-02 - 12 1.15 5.5716e-01 2.8554e-02 - 13 1.25 5.0158e-01 1.0943e-02 - 14 1.35 3.9581e-01 3.5935e-03 - 15 1.45 2.7424e-01 1.0078e-03 - 16 1.55 1.6586e-01 2.4047e-04 - 17 1.65 8.6688e-02 4.8621e-05 - 18 1.75 3.8743e-02 8.3007e-06 - 19 1.85 1.4669e-02 1.1922e-06 - 20 1.95 5.0940e-03 1.5016e-07 diff --git a/Sun/examples/ex14.log b/Sun/examples/ex14.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex14.out b/Sun/examples/ex14.out deleted file mode 100644 index bf8f9286..00000000 --- a/Sun/examples/ex14.out +++ /dev/null @@ -1,3000 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex14 - Output file: ex14.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/wateq4f.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 14.--Transport with equilibrium_phases, exchange, and surface reactions - *********** - PLEASE NOTE: This problem requires database file wateq4f.dat! - Arsenic data of Archer and Nordstrom (2002) included in - wateq4f.dat (PHREEQC Version 2.8). - Results differ from WRIR 99-4259 because of revised data. - *********** - SURFACE_SPECIES - Hfo_wOH + Mg+2 = Hfo_wOMg+ + H+ - log_k -15. - Hfo_wOH + Ca+2 = Hfo_wOCa+ + H+ - log_k -15. - SOLUTION 1 Brine - pH 5.713 - pe 4.0 O2(g) -0.7 - temp 25. - units mol/kgw - Ca .4655 - Mg .1609 - Na 5.402 - Cl 6.642 charge - C .00396 - S .004725 - As .05 umol/kgw - END ------ -TITLE ------ - - Example 14.--Transport with equilibrium_phases, exchange, and surface reactions -*********** -PLEASE NOTE: This problem requires database file wateq4f.dat! - Arsenic data of Archer and Nordstrom (2002) included in - wateq4f.dat (PHREEQC Version 2.8). - Results differ from WRIR 99-4259 because of revised data. -*********** - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Brine - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 5.000e-08 5.000e-08 - C 3.960e-03 3.960e-03 - Ca 4.655e-01 4.655e-01 - Cl 6.642e+00 6.642e+00 Charge balance - Mg 1.609e-01 1.609e-01 - Na 5.402e+00 5.402e+00 - S 4.725e-03 4.725e-03 - -----------------------------Description of solution---------------------------- - - pH = 5.713 - pe = 14.945 Equilibrium with O2(g) - Activity of water = 0.785 - Ionic strength = 7.269e+00 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.333e-03 - Total CO2 (mol/kg) = 3.960e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.964e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 11 - Total H = 1.110158e+02 - Total O = 5.553645e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.755e-06 1.936e-06 -5.560 -5.713 -0.153 - OH- 7.396e-10 4.056e-09 -9.131 -8.392 0.739 - H2O 5.551e+01 7.846e-01 1.744 -0.105 0.000 -As(3) 2.742e-33 - H3AsO3 2.741e-33 1.462e-32 -32.562 -31.835 0.727 - H2AsO3- 9.743e-37 5.343e-36 -36.011 -35.272 0.739 - H4AsO3+ 2.557e-39 1.402e-38 -38.592 -37.853 0.739 - HAsO3-2 0.000e+00 0.000e+00 -47.216 -44.259 2.956 - AsO3-3 0.000e+00 0.000e+00 -60.898 -54.246 6.652 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -302.180 -301.440 0.739 - As3S4(HS)2- 0.000e+00 0.000e+00 -897.970 -897.231 0.739 -As(5) 5.000e-08 - H2AsO4- 4.997e-08 2.740e-07 -7.301 -6.562 0.739 - H3AsO4 1.986e-11 1.059e-10 -10.702 -9.975 0.727 - HAsO4-2 1.082e-11 9.791e-09 -10.966 -8.009 2.956 - AsO4-3 2.522e-21 1.132e-14 -20.598 -13.946 6.652 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.861 -143.135 0.727 -C(4) 3.960e-03 - HCO3- 1.045e-03 6.049e-04 -2.981 -3.218 -0.238 - CaHCO3+ 1.002e-03 5.494e-03 -2.999 -2.260 0.739 - MgHCO3+ 6.754e-04 3.704e-03 -3.170 -2.431 0.739 - CO2 6.296e-04 3.357e-03 -3.201 -2.474 0.727 - NaHCO3 6.026e-04 3.213e-03 -3.220 -2.493 0.727 - CaCO3 3.278e-06 1.748e-05 -5.484 -4.758 0.727 - MgCO3 1.372e-06 7.316e-06 -5.863 -5.136 0.727 - NaCO3- 4.698e-07 2.577e-06 -6.328 -5.589 0.739 - CO3-2 1.307e-07 1.465e-08 -6.884 -7.834 -0.950 -Ca 4.655e-01 - Ca+2 4.629e-01 7.121e-01 -0.335 -0.147 0.187 - CaSO4 1.606e-03 8.565e-03 -2.794 -2.067 0.727 - CaHCO3+ 1.002e-03 5.494e-03 -2.999 -2.260 0.739 - CaCO3 3.278e-06 1.748e-05 -5.484 -4.758 0.727 - CaHSO4+ 1.772e-08 9.716e-08 -7.752 -7.012 0.739 - CaOH+ 8.731e-09 4.788e-08 -8.059 -7.320 0.739 -Cl 6.642e+00 - Cl- 6.642e+00 3.947e+00 0.822 0.596 -0.226 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -45.192 -44.465 0.727 -Mg 1.609e-01 - Mg+2 1.588e-01 5.233e-01 -0.799 -0.281 0.518 - MgSO4 1.387e-03 7.395e-03 -2.858 -2.131 0.727 - MgHCO3+ 6.754e-04 3.704e-03 -3.170 -2.431 0.739 - MgCO3 1.372e-06 7.316e-06 -5.863 -5.136 0.727 - MgOH+ 1.404e-07 7.698e-07 -6.853 -6.114 0.739 -Na 5.402e+00 - Na+ 5.401e+00 9.445e+00 0.732 0.975 0.243 - NaHCO3 6.026e-04 3.213e-03 -3.220 -2.493 0.727 - NaSO4- 5.203e-04 2.854e-03 -3.284 -2.545 0.739 - NaCO3- 4.698e-07 2.577e-06 -6.328 -5.589 0.739 -O(0) 8.206e-05 - O2 4.103e-05 2.188e-04 -4.387 -3.660 0.727 -S(-2) 0.000e+00 - H2S 0.000e+00 0.000e+00 -140.569 -139.842 0.727 - HS- 0.000e+00 0.000e+00 -141.810 -141.070 0.739 - S5-2 0.000e+00 0.000e+00 -144.480 -144.952 -0.473 - S4-2 0.000e+00 0.000e+00 -144.629 -145.186 -0.558 - S6-2 0.000e+00 0.000e+00 -144.828 -145.238 -0.410 - S3-2 0.000e+00 0.000e+00 -147.960 -148.639 -0.680 - S2-2 0.000e+00 0.000e+00 -149.072 -149.885 -0.813 - S-2 0.000e+00 0.000e+00 -151.232 -148.275 2.956 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -302.180 -301.440 0.739 - As3S4(HS)2- 0.000e+00 0.000e+00 -897.970 -897.231 0.739 -S(6) 4.725e-03 - CaSO4 1.606e-03 8.565e-03 -2.794 -2.067 0.727 - MgSO4 1.387e-03 7.395e-03 -2.858 -2.131 0.727 - SO4-2 1.211e-03 6.028e-05 -2.917 -4.220 -1.303 - NaSO4- 5.203e-04 2.854e-03 -3.284 -2.545 0.739 - CaHSO4+ 1.772e-08 9.716e-08 -7.752 -7.012 0.739 - HSO4- 2.069e-09 1.135e-08 -8.684 -7.945 0.739 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.01 -4.37 -4.36 CaSO4 - Aragonite 0.35 -7.98 -8.34 CaCO3 - Arsenolite -61.97 -63.35 -1.38 As2O3 - Artinite -7.10 2.50 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -27.86 -19.63 8.23 As2O5 - As2S3(am) -458.49 -503.39 -44.90 As2S3 - As_native -80.96 -93.49 -12.53 As - Brucite -5.91 10.93 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -9.85 -28.76 -18.91 Ca3(AsO4)2:4H2O - Calcite 0.50 -7.98 -8.48 CaCO3 - CH4(g) -140.27 -143.13 -2.86 CH4 - Claudetite -62.01 -63.35 -1.34 As2O3 - CO2(g) -1.01 -2.47 -1.47 CO2 - Dolomite 0.99 -16.10 -17.09 CaMg(CO3)2 - Dolomite(d) 0.44 -16.10 -16.54 CaMg(CO3)2 - Epsomite -3.10 -5.24 -2.14 MgSO4:7H2O - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -41.32 -44.47 -3.15 H2 - H2O(g) -1.62 -0.11 1.51 H2O - H2S(g) -138.84 -139.84 -1.00 H2S - Halite -0.01 1.57 1.58 NaCl - Huntite -2.36 -32.33 -29.97 CaMg3(CO3)4 - Hydromagnesite -13.19 -21.95 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.09 -8.12 -8.03 MgCO3 - Mirabilite -2.21 -3.32 -1.11 Na2SO4:10H2O - Nahcolite -1.70 -2.24 -0.55 NaHCO3 - Natron -5.63 -6.94 -1.31 Na2CO3:10H2O - Nesquehonite -2.81 -8.43 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -457.09 -503.39 -46.30 As2S3 - Portlandite -11.73 11.07 22.80 Ca(OH)2 - Realgar -179.02 -198.96 -19.94 AsS - Sulfur -103.36 -118.39 -15.03 S - Thenardite -2.09 -2.27 -0.18 Na2SO4 - Thermonatrite -6.11 -5.99 0.12 Na2CO3:H2O - Trona -7.54 -8.34 -0.80 NaHCO3:Na2CO3:2H2O - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - USE solution 1 - EQUILIBRIUM_PHASES 1 - Dolomite 0.0 1.6 - Calcite 0.0 0.1 - SAVE solution 1 - SELECTED_OUTPUT - file ex14.sel - reset false - step - USER_PUNCH - heading m_Ca m_Mg m_Na umol_As pH - 10 PUNCH TOT("Ca"), TOT("Mg"), TOT("Na"), TOT("As")*1e6, -LA("H+") - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Brine -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e-01 1.020e-01 1.982e-03 - Dolomite 0.00 -17.09 -17.09 1.600e+00 1.599e+00 -7.679e-04 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 5.000e-08 5.000e-08 - C 3.514e-03 3.514e-03 - Ca 4.643e-01 4.643e-01 - Cl 6.642e+00 6.642e+00 - Mg 1.617e-01 1.617e-01 - Na 5.402e+00 5.402e+00 - S 4.725e-03 4.725e-03 - -----------------------------Description of solution---------------------------- - - pH = 5.350 Charge balance - pe = 15.308 Adjusted to redox equilibrium - Activity of water = 0.785 - Ionic strength = 7.269e+00 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.441e-03 - Total CO2 (mol/kg) = 3.514e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 4.107e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 4 - Total H = 1.110158e+02 - Total O = 5.553511e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.361e-06 4.471e-06 -5.196 -5.350 -0.153 - OH- 3.204e-10 1.757e-09 -9.494 -8.755 0.739 - H2O 5.551e+01 7.846e-01 1.744 -0.105 0.000 -As(3) 6.327e-33 - H3AsO3 6.326e-33 3.373e-32 -32.199 -31.472 0.727 - H2AsO3- 9.740e-37 5.341e-36 -36.011 -35.272 0.739 - H4AsO3+ 1.363e-38 7.471e-38 -37.866 -37.127 0.739 - HAsO3-2 0.000e+00 0.000e+00 -47.579 -44.623 2.956 - AsO3-3 0.000e+00 0.000e+00 -61.625 -54.973 6.652 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -300.727 -299.988 0.739 - As3S4(HS)2- 0.000e+00 0.000e+00 -892.885 -892.146 0.739 -As(5) 5.000e-08 - H2AsO4- 4.995e-08 2.739e-07 -7.301 -6.562 0.739 - H3AsO4 4.583e-11 2.443e-10 -10.339 -9.612 0.727 - HAsO4-2 4.687e-12 4.238e-09 -11.329 -8.373 2.956 - AsO4-3 4.733e-22 2.122e-15 -21.325 -14.673 6.652 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.632 -142.905 0.727 -C(4) 3.514e-03 - CO2 1.068e-03 5.694e-03 -2.971 -2.245 0.727 - HCO3- 7.680e-04 4.444e-04 -3.115 -3.352 -0.238 - CaHCO3+ 7.345e-04 4.028e-03 -3.134 -2.395 0.739 - MgHCO3+ 4.991e-04 2.737e-03 -3.302 -2.563 0.739 - NaHCO3 4.428e-04 2.361e-03 -3.354 -2.627 0.727 - CaCO3 1.041e-06 5.550e-06 -5.983 -5.256 0.727 - MgCO3 4.392e-07 2.341e-06 -6.357 -5.631 0.727 - NaCO3- 1.495e-07 8.199e-07 -6.825 -6.086 0.739 - CO3-2 4.158e-08 4.662e-09 -7.381 -8.331 -0.950 -Ca 4.643e-01 - Ca+2 4.619e-01 7.106e-01 -0.335 -0.148 0.187 - CaSO4 1.601e-03 8.538e-03 -2.796 -2.069 0.727 - CaHCO3+ 7.345e-04 4.028e-03 -3.134 -2.395 0.739 - CaCO3 1.041e-06 5.550e-06 -5.983 -5.256 0.727 - CaHSO4+ 4.078e-08 2.236e-07 -7.390 -6.650 0.739 - CaOH+ 3.774e-09 2.069e-08 -8.423 -7.684 0.739 -Cl 6.642e+00 - Cl- 6.642e+00 3.947e+00 0.822 0.596 -0.226 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -45.192 -44.465 0.727 -Mg 1.617e-01 - Mg+2 1.598e-01 5.263e-01 -0.796 -0.279 0.518 - MgSO4 1.394e-03 7.430e-03 -2.856 -2.129 0.727 - MgHCO3+ 4.991e-04 2.737e-03 -3.302 -2.563 0.739 - MgCO3 4.392e-07 2.341e-06 -6.357 -5.631 0.727 - MgOH+ 6.115e-08 3.353e-07 -7.214 -6.475 0.739 -Na 5.402e+00 - Na+ 5.401e+00 9.445e+00 0.732 0.975 0.243 - NaSO4- 5.199e-04 2.851e-03 -3.284 -2.545 0.739 - NaHCO3 4.428e-04 2.361e-03 -3.354 -2.627 0.727 - NaCO3- 1.495e-07 8.199e-07 -6.825 -6.086 0.739 -O(0) 8.206e-05 - O2 4.103e-05 2.188e-04 -4.387 -3.660 0.727 -S(-2) 0.000e+00 - H2S 0.000e+00 0.000e+00 -139.842 -139.115 0.727 - HS- 0.000e+00 0.000e+00 -141.447 -140.707 0.739 - S5-2 0.000e+00 0.000e+00 -144.480 -144.953 -0.473 - S4-2 0.000e+00 0.000e+00 -144.629 -145.187 -0.558 - S6-2 0.000e+00 0.000e+00 -144.829 -145.239 -0.410 - S3-2 0.000e+00 0.000e+00 -147.960 -148.640 -0.680 - S2-2 0.000e+00 0.000e+00 -149.073 -149.886 -0.813 - S-2 0.000e+00 0.000e+00 -151.232 -148.276 2.956 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -300.727 -299.988 0.739 - As3S4(HS)2- 0.000e+00 0.000e+00 -892.885 -892.146 0.739 -S(6) 4.725e-03 - CaSO4 1.601e-03 8.538e-03 -2.796 -2.069 0.727 - MgSO4 1.394e-03 7.430e-03 -2.856 -2.129 0.727 - SO4-2 1.210e-03 6.022e-05 -2.917 -4.220 -1.303 - NaSO4- 5.199e-04 2.851e-03 -3.284 -2.545 0.739 - CaHSO4+ 4.078e-08 2.236e-07 -7.390 -6.650 0.739 - HSO4- 4.774e-09 2.618e-08 -8.321 -7.582 0.739 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.01 -4.37 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Arsenolite -61.25 -62.63 -1.38 As2O3 - Artinite -8.32 1.28 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -27.14 -18.91 8.23 As2O5 - As2S3(am) -455.58 -500.48 -44.90 As2S3 - As_native -80.60 -93.13 -12.53 As - Brucite -6.63 10.21 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -11.31 -30.21 -18.91 Ca3(AsO4)2:4H2O - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -140.04 -142.90 -2.86 CH4 - Claudetite -61.29 -62.63 -1.34 As2O3 - CO2(g) -0.78 -2.24 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -3.10 -5.24 -2.14 MgSO4:7H2O - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -41.32 -44.47 -3.15 H2 - H2O(g) -1.62 -0.11 1.51 H2O - H2S(g) -138.12 -139.12 -1.00 H2S - Halite -0.01 1.57 1.58 NaCl - Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 - Hydromagnesite -15.89 -24.65 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.58 -8.61 -8.03 MgCO3 - Mirabilite -2.21 -3.32 -1.11 Na2SO4:10H2O - Nahcolite -1.83 -2.38 -0.55 NaHCO3 - Natron -6.12 -7.43 -1.31 Na2CO3:10H2O - Nesquehonite -3.31 -8.93 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -454.18 -500.48 -46.30 As2S3 - Portlandite -12.46 10.34 22.80 Ca(OH)2 - Realgar -177.93 -197.87 -19.94 AsS - Sulfur -102.63 -117.66 -15.03 S - Thenardite -2.09 -2.27 -0.18 Na2SO4 - Thermonatrite -6.61 -6.49 0.12 Na2CO3:H2O - Trona -8.17 -8.97 -0.80 NaHCO3:Na2CO3:2H2O - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - PRINT - selected_output false - EXCHANGE 1 - equilibrate with solution 1 - X 1.0 - SURFACE 1 - equilibrate solution 1 - Hfo_w 0.07 600. 30. - END -------------------------------------------------------- -Beginning of initial exchange-composition calculations. -------------------------------------------------------- - -Exchange 1. - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - NaX 9.355e-01 9.355e-01 9.355e-01 0.000 - CaX2 2.199e-02 4.398e-02 4.398e-02 0.000 - MgX2 1.028e-02 2.055e-02 2.055e-02 0.000 - HX 4.428e-06 4.428e-06 4.428e-06 0.000 - ------------------------------------------------------- -Beginning of initial surface-composition calculations. ------------------------------------------------------- - -Surface 1. - -Hfo - 6.234e-02 Surface charge, eq - 3.342e-01 sigma, C/m**2 - 4.729e-02 psi, V - -1.841e+00 -F*psi/RT - 1.587e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH2+ 6.388e-02 0.913 6.388e-02 -1.195 - Hfo_wOH 4.617e-03 0.066 4.616e-03 -2.336 - Hfo_wSO4- 6.015e-04 0.009 6.015e-04 -3.221 - Hfo_wHAsO4- 5.089e-04 0.007 5.089e-04 -3.293 - Hfo_wH2AsO4 2.279e-04 0.003 2.279e-04 -3.642 - Hfo_wOHAsO4-3 9.316e-05 0.001 9.316e-05 -4.031 - Hfo_wOHSO4-2 6.805e-05 0.001 6.805e-05 -4.167 - Hfo_wO- 7.643e-06 0.000 7.643e-06 -5.117 - Hfo_wOCa+ 1.165e-13 0.000 1.165e-13 -12.934 - Hfo_wOMg+ 8.626e-14 0.000 8.626e-14 -13.064 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - SOLUTION 0 20 x precipitation - pH 4.6 - pe 4.0 O2(g) -0.7 - temp 25. - units mmol/kgw - Ca .191625 - Mg .035797 - Na .122668 - Cl .133704 - C .01096 - S .235153 charge - EQUILIBRIUM_PHASES 0 - Dolomite 0.0 1.6 - Calcite 0.0 0.1 - CO2(g) -1.5 10. - SAVE solution 0 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. 20 x precipitation - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.096e-05 1.096e-05 - Ca 1.916e-04 1.916e-04 - Cl 1.337e-04 1.337e-04 - Mg 3.580e-05 3.580e-05 - Na 1.227e-04 1.227e-04 - S 2.351e-04 2.351e-04 Charge balance - -----------------------------Description of solution---------------------------- - - pH = 4.600 - pe = 16.005 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.035e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -2.630e-05 - Total CO2 (mol/kg) = 1.096e-05 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.119e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 9 - Total H = 1.110125e+02 - Total O = 5.550762e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.600e-05 2.512e-05 -4.585 -4.600 -0.015 - OH- 4.132e-10 3.985e-10 -9.384 -9.400 -0.016 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -145.418 -145.418 0.000 -C(4) 1.096e-05 - CO2 1.076e-05 1.076e-05 -4.968 -4.968 0.000 - HCO3- 1.975e-07 1.906e-07 -6.704 -6.720 -0.015 - CaHCO3+ 4.049e-10 3.905e-10 -9.393 -9.408 -0.016 - MgHCO3+ 6.905e-11 6.660e-11 -10.161 -10.177 -0.016 - NaHCO3 1.267e-11 1.267e-11 -10.897 -10.897 0.000 - CO3-2 4.105e-13 3.559e-13 -12.387 -12.449 -0.062 - CaCO3 9.575e-14 9.577e-14 -13.019 -13.019 0.000 - MgCO3 1.014e-14 1.014e-14 -13.994 -13.994 0.000 - NaCO3- 8.122e-16 7.833e-16 -15.090 -15.106 -0.016 -Ca 1.916e-04 - Ca+2 1.853e-04 1.606e-04 -3.732 -3.794 -0.062 - CaSO4 6.296e-06 6.297e-06 -5.201 -5.201 0.000 - CaHSO4+ 9.608e-10 9.267e-10 -9.017 -9.033 -0.016 - CaHCO3+ 4.049e-10 3.905e-10 -9.393 -9.408 -0.016 - CaOH+ 1.100e-12 1.061e-12 -11.958 -11.974 -0.016 - CaCO3 9.575e-14 9.577e-14 -13.019 -13.019 0.000 -Cl 1.337e-04 - Cl- 1.337e-04 1.289e-04 -3.874 -3.890 -0.016 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.360 -44.360 0.000 -Mg 3.580e-05 - Mg+2 3.442e-05 2.986e-05 -4.463 -4.525 -0.062 - MgSO4 1.375e-06 1.375e-06 -5.862 -5.862 0.000 - MgHCO3+ 6.905e-11 6.660e-11 -10.161 -10.177 -0.016 - MgOH+ 4.475e-12 4.316e-12 -11.349 -11.365 -0.016 - MgCO3 1.014e-14 1.014e-14 -13.994 -13.994 0.000 -Na 1.227e-04 - Na+ 1.225e-04 1.182e-04 -3.912 -3.927 -0.016 - NaSO4- 1.207e-07 1.164e-07 -6.918 -6.934 -0.016 - NaHCO3 1.267e-11 1.267e-11 -10.897 -10.897 0.000 - NaCO3- 8.122e-16 7.833e-16 -15.090 -15.106 -0.016 -O(0) 4.374e-04 - O2 2.187e-04 2.188e-04 -3.660 -3.660 0.000 -S(-2) 0.000e+00 - H2S 0.000e+00 0.000e+00 -137.103 -137.103 0.000 - HS- 0.000e+00 0.000e+00 -139.429 -139.444 -0.016 - S5-2 0.000e+00 0.000e+00 -144.381 -144.439 -0.058 - S4-2 0.000e+00 0.000e+00 -144.614 -144.673 -0.059 - S6-2 0.000e+00 0.000e+00 -144.668 -144.725 -0.057 - S-2 0.000e+00 0.000e+00 -147.700 -147.762 -0.063 - S3-2 0.000e+00 0.000e+00 -148.066 -148.126 -0.060 - S2-2 0.000e+00 0.000e+00 -149.311 -149.372 -0.061 -S(6) 2.351e-04 - SO4-2 2.268e-04 1.965e-04 -3.644 -3.707 -0.062 - CaSO4 6.296e-06 6.297e-06 -5.201 -5.201 0.000 - MgSO4 1.375e-06 1.375e-06 -5.862 -5.862 0.000 - HSO4- 4.975e-07 4.798e-07 -6.303 -6.319 -0.016 - NaSO4- 1.207e-07 1.164e-07 -6.918 -6.934 -0.016 - CaHSO4+ 9.608e-10 9.267e-10 -9.017 -9.033 -0.016 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.14 -7.50 -4.36 CaSO4 - Aragonite -7.91 -16.24 -8.34 CaCO3 - Artinite -21.90 -12.30 9.60 MgCO3:Mg(OH)2:3H2O - Brucite -12.16 4.68 16.84 Mg(OH)2 - Calcite -7.76 -16.24 -8.48 CaCO3 - CH4(g) -142.56 -145.42 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Dolomite -16.13 -33.22 -17.09 CaMg(CO3)2 - Dolomite(d) -16.68 -33.22 -16.54 CaMg(CO3)2 - Epsomite -6.09 -8.23 -2.14 MgSO4:7H2O - Gypsum -2.92 -7.50 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -136.11 -137.10 -1.00 H2S - Halite -9.40 -7.82 1.58 NaCl - Huntite -37.20 -67.16 -29.97 CaMg3(CO3)4 - Hydromagnesite -54.46 -63.22 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -8.94 -16.97 -8.03 MgCO3 - Mirabilite -10.45 -11.56 -1.11 Na2SO4:10H2O - Nahcolite -10.10 -10.65 -0.55 NaHCO3 - Natron -18.99 -20.30 -1.31 Na2CO3:10H2O - Nesquehonite -11.35 -16.97 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Portlandite -17.39 5.41 22.80 Ca(OH)2 - Sulfur -100.73 -115.75 -15.03 S - Thenardite -11.38 -11.56 -0.18 Na2SO4 - Thermonatrite -20.43 -20.30 0.12 Na2CO3:H2O - Trona -30.16 -30.95 -0.80 NaHCO3:Na2CO3:2H2O - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 0. 20 x precipitation -Using pure phase assemblage 0. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e-01 9.966e-02 -3.443e-04 - CO2(g) -1.50 -19.65 -18.15 1.000e+01 9.996e+00 -4.067e-03 - Dolomite 0.00 -17.09 -17.09 1.600e+00 1.599e+00 -1.349e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 7.120e-03 7.119e-03 - Ca 1.885e-03 1.885e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.385e-03 1.384e-03 - Na 1.227e-04 1.227e-04 - S 2.351e-04 2.351e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.047 Charge balance - pe = 13.558 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.629e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.057e-03 - Total CO2 (mol/kg) = 7.120e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.173e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 16 - Total H = 1.110125e+02 - Total O = 5.552487e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.234e-07 1.115e-07 -6.909 -6.953 -0.044 - H+ 9.814e-08 8.977e-08 -7.008 -7.047 -0.039 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.421 -143.420 0.001 -C(4) 7.120e-03 - HCO3- 5.883e-03 5.333e-03 -2.230 -2.273 -0.043 - CO2 1.074e-03 1.077e-03 -2.969 -2.968 0.001 - CaHCO3+ 8.950e-05 8.087e-05 -4.048 -4.092 -0.044 - MgHCO3+ 6.082e-05 5.496e-05 -4.216 -4.260 -0.044 - CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 - CO3-2 4.124e-06 2.786e-06 -5.385 -5.555 -0.170 - MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 - NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 - NaCO3- 6.351e-09 5.738e-09 -8.197 -8.241 -0.044 -Ca 1.885e-03 - Ca+2 1.761e-03 1.189e-03 -2.754 -2.925 -0.171 - CaHCO3+ 8.950e-05 8.087e-05 -4.048 -4.092 -0.044 - CaSO4 2.881e-05 2.887e-05 -4.540 -4.539 0.001 - CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 - CaOH+ 2.432e-09 2.198e-09 -8.614 -8.658 -0.044 - CaHSO4+ 1.681e-11 1.518e-11 -10.775 -10.819 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.385e-03 - Mg+2 1.296e-03 8.806e-04 -2.887 -3.055 -0.168 - MgHCO3+ 6.082e-05 5.496e-05 -4.216 -4.260 -0.044 - MgSO4 2.507e-05 2.513e-05 -4.601 -4.600 0.001 - MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 - MgOH+ 3.941e-08 3.561e-08 -7.404 -7.448 -0.044 -Na 1.227e-04 - Na+ 1.223e-04 1.106e-04 -3.913 -3.956 -0.044 - NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 - NaSO4- 7.467e-08 6.747e-08 -7.127 -7.171 -0.044 - NaCO3- 6.351e-09 5.738e-09 -8.197 -8.241 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.057 -142.101 -0.044 - H2S 0.000e+00 0.000e+00 -142.207 -142.206 0.001 - S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 - S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 - S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 - S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 - S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 - S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 -S(6) 2.351e-04 - SO4-2 1.811e-04 1.217e-04 -3.742 -3.915 -0.173 - CaSO4 2.881e-05 2.887e-05 -4.540 -4.539 0.001 - MgSO4 2.507e-05 2.513e-05 -4.601 -4.600 0.001 - NaSO4- 7.467e-08 6.747e-08 -7.127 -7.171 -0.044 - HSO4- 1.176e-09 1.062e-09 -8.930 -8.974 -0.044 - CaHSO4+ 1.681e-11 1.518e-11 -10.775 -10.819 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.48 -6.84 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Artinite -7.17 2.43 9.60 MgCO3:Mg(OH)2:3H2O - Brucite -5.80 11.04 16.84 Mg(OH)2 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -140.56 -143.42 -2.86 CH4 - CO2(g) -1.50 -2.97 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.83 -6.97 -2.14 MgSO4:7H2O - Gypsum -2.26 -6.84 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.21 -142.21 -1.00 H2S - Halite -9.46 -7.87 1.58 NaCl - Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.64 -23.40 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.58 -8.61 -8.03 MgCO3 - Mirabilite -10.71 -11.83 -1.11 Na2SO4:10H2O - Nahcolite -5.68 -6.23 -0.55 NaHCO3 - Natron -12.16 -13.47 -1.31 Na2CO3:10H2O - Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Portlandite -11.63 11.17 22.80 Ca(OH)2 - Sulfur -105.83 -120.86 -15.03 S - Thenardite -11.65 -11.83 -0.18 Na2SO4 - Thermonatrite -13.59 -13.47 0.12 Na2CO3:H2O - Trona -18.90 -19.70 -0.80 NaHCO3:Na2CO3:2H2O - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 5. ------------------------------------- - - PRINT - selected_output true - ADVECTION - cells 1 - shifts 200 - print_frequency 20 - END ------------------------------------- -Beginning of advection calculations. ------------------------------------- - -Beginning of advection time step 1, cumulative pore volumes 1.000000. -Beginning of advection time step 2, cumulative pore volumes 2.000000. -Beginning of advection time step 3, cumulative pore volumes 3.000000. -Beginning of advection time step 4, cumulative pore volumes 4.000000. -Beginning of advection time step 5, cumulative pore volumes 5.000000. -Beginning of advection time step 6, cumulative pore volumes 6.000000. -Beginning of advection time step 7, cumulative pore volumes 7.000000. -Beginning of advection time step 8, cumulative pore volumes 8.000000. -Beginning of advection time step 9, cumulative pore volumes 9.000000. -Beginning of advection time step 10, cumulative pore volumes 10.000000. -Beginning of advection time step 11, cumulative pore volumes 11.000000. -Beginning of advection time step 12, cumulative pore volumes 12.000000. -Beginning of advection time step 13, cumulative pore volumes 13.000000. -Beginning of advection time step 14, cumulative pore volumes 14.000000. -Beginning of advection time step 15, cumulative pore volumes 15.000000. -Beginning of advection time step 16, cumulative pore volumes 16.000000. -Beginning of advection time step 17, cumulative pore volumes 17.000000. -Beginning of advection time step 18, cumulative pore volumes 18.000000. -Beginning of advection time step 19, cumulative pore volumes 19.000000. -Beginning of advection time step 20, cumulative pore volumes 20.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 5.212e-02 5.085e-02 -1.272e-03 - Dolomite 0.00 -17.09 -17.09 1.576e+00 1.575e+00 -1.774e-04 - -------------------------------Surface composition------------------------------ - -Hfo - -2.907e-03 Surface charge, eq - -1.559e-02 sigma, C/m**2 - -5.497e-02 psi, V - 2.140e+00 -F*psi/RT - 8.498e+00 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.310e-02 0.759 5.310e-02 -1.275 - Hfo_wO- 8.255e-03 0.118 8.256e-03 -2.083 - Hfo_wOH2+ 7.823e-03 0.112 7.824e-03 -2.107 - Hfo_wOHAsO4-3 8.244e-04 0.012 8.245e-04 -3.084 - Hfo_wOHSO4-2 6.801e-07 0.000 6.802e-07 -6.167 - Hfo_wHAsO4- 4.008e-07 0.000 4.008e-07 -6.397 - Hfo_wSO4- 5.024e-08 0.000 5.024e-08 -7.299 - Hfo_wH2AsO4 1.911e-09 0.000 1.911e-09 -8.719 - Hfo_wOCa+ 4.391e-12 0.000 4.391e-12 -11.357 - Hfo_wOMg+ 3.252e-12 0.000 3.252e-12 -11.488 - Hfo_wH2AsO3 4.273e-34 0.000 4.274e-34 -33.369 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - NaX 6.110e-01 6.110e-01 6.110e-01 -0.000 - CaX2 1.325e-01 2.651e-01 2.651e-01 -0.000 - MgX2 6.194e-02 1.239e-01 1.239e-01 -0.000 - HX 6.196e-07 6.196e-07 6.196e-07 -0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.542e-07 1.542e-07 - C 8.747e-03 8.746e-03 - Ca 1.972e-05 1.972e-05 - Cl 1.337e-04 1.337e-04 - Mg 1.279e-05 1.279e-05 - Na 9.850e-03 9.850e-03 - S 2.350e-04 2.350e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.051 Charge balance - pe = 11.554 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.065e-02 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 9.399e-03 - Total CO2 (mol/kg) = 8.747e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -8.721e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.44 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.552976e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.251e-05 1.125e-05 -4.903 -4.949 -0.046 - H+ 9.756e-10 8.892e-10 -9.011 -9.051 -0.040 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -As(3) 5.893e-38 - H3AsO3 3.122e-38 3.130e-38 -37.506 -37.504 0.001 - H2AsO3- 2.771e-38 2.492e-38 -37.557 -37.603 -0.046 - HAsO3-2 0.000e+00 0.000e+00 -43.068 -43.252 -0.184 - H4AsO3+ 0.000e+00 0.000e+00 -46.814 -46.860 -0.046 - AsO3-3 0.000e+00 0.000e+00 -49.487 -49.901 -0.414 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -316.500 -316.546 -0.046 - As3S4(HS)2- 0.000e+00 0.000e+00 -949.494 -949.540 -0.046 -As(5) 1.542e-07 - HAsO4-2 1.521e-07 9.955e-08 -6.818 -7.002 -0.184 - H2AsO4- 1.423e-09 1.280e-09 -8.847 -8.893 -0.046 - AsO4-3 6.505e-10 2.506e-10 -9.187 -9.601 -0.414 - H3AsO4 2.265e-16 2.270e-16 -15.645 -15.644 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -145.291 -145.290 0.001 -C(4) 8.747e-03 - HCO3- 8.041e-03 7.259e-03 -2.095 -2.139 -0.044 - CO3-2 5.765e-04 3.828e-04 -3.239 -3.417 -0.178 - NaCO3- 6.950e-05 6.252e-05 -4.158 -4.204 -0.046 - NaHCO3 3.571e-05 3.580e-05 -4.447 -4.446 0.001 - CO2 1.448e-05 1.452e-05 -4.839 -4.838 0.001 - CaCO3 5.536e-06 5.550e-06 -5.257 -5.256 0.001 - MgCO3 2.336e-06 2.341e-06 -5.632 -5.631 0.001 - CaHCO3+ 8.907e-07 8.011e-07 -6.050 -6.096 -0.046 - MgHCO3+ 6.052e-07 5.444e-07 -6.218 -6.264 -0.046 -Ca 1.972e-05 - Ca+2 1.304e-05 8.653e-06 -4.885 -5.063 -0.178 - CaCO3 5.536e-06 5.550e-06 -5.257 -5.256 0.001 - CaHCO3+ 8.907e-07 8.011e-07 -6.050 -6.096 -0.046 - CaSO4 2.584e-07 2.590e-07 -6.588 -6.587 0.001 - CaOH+ 1.795e-09 1.614e-09 -8.746 -8.792 -0.046 - CaHSO4+ 1.500e-15 1.349e-15 -14.824 -14.870 -0.046 -Cl 1.337e-04 - Cl- 1.337e-04 1.200e-04 -3.874 -3.921 -0.047 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.362 -44.361 0.001 -Mg 1.279e-05 - Mg+2 9.592e-06 6.409e-06 -5.018 -5.193 -0.175 - MgCO3 2.336e-06 2.341e-06 -5.632 -5.631 0.001 - MgHCO3+ 6.052e-07 5.444e-07 -6.218 -6.264 -0.046 - MgSO4 2.249e-07 2.254e-07 -6.648 -6.647 0.001 - MgOH+ 2.909e-08 2.616e-08 -7.536 -7.582 -0.046 -Na 9.850e-03 - Na+ 9.738e-03 8.769e-03 -2.012 -2.057 -0.045 - NaCO3- 6.950e-05 6.252e-05 -4.158 -4.204 -0.046 - NaHCO3 3.571e-05 3.580e-05 -4.447 -4.446 0.001 - NaSO4- 7.331e-06 6.594e-06 -5.135 -5.181 -0.046 -O(0) 4.375e-04 - O2 2.187e-04 2.193e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -143.968 -144.014 -0.046 - S5-2 0.000e+00 0.000e+00 -144.409 -144.559 -0.149 - S4-2 0.000e+00 0.000e+00 -144.635 -144.793 -0.157 - S6-2 0.000e+00 0.000e+00 -144.702 -144.845 -0.143 - H2S 0.000e+00 0.000e+00 -146.125 -146.124 0.001 - S-2 0.000e+00 0.000e+00 -147.697 -147.882 -0.184 - S3-2 0.000e+00 0.000e+00 -148.080 -148.246 -0.165 - S2-2 0.000e+00 0.000e+00 -149.319 -149.492 -0.172 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -316.500 -316.546 -0.046 - As3S4(HS)2- 0.000e+00 0.000e+00 -949.494 -949.540 -0.046 -S(6) 2.350e-04 - SO4-2 2.272e-04 1.500e-04 -3.644 -3.824 -0.180 - NaSO4- 7.331e-06 6.594e-06 -5.135 -5.181 -0.046 - CaSO4 2.584e-07 2.590e-07 -6.588 -6.587 0.001 - MgSO4 2.249e-07 2.254e-07 -6.648 -6.647 0.001 - HSO4- 1.442e-11 1.297e-11 -10.841 -10.887 -0.046 - CaHSO4+ 1.500e-15 1.349e-15 -14.824 -14.870 -0.046 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -4.53 -8.89 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Arsenolite -73.63 -75.01 -1.38 As2O3 - Artinite -5.30 4.30 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -39.52 -31.29 8.23 As2O5 - As2S3(am) -489.30 -534.20 -44.90 As2S3 - As_native -86.79 -99.32 -12.53 As - Brucite -3.93 12.91 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -15.49 -34.39 -18.91 Ca3(AsO4)2:4H2O - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -142.43 -145.29 -2.86 CH4 - Claudetite -73.67 -75.01 -1.34 As2O3 - CO2(g) -3.37 -4.84 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -6.88 -9.02 -2.14 MgSO4:7H2O - Gypsum -4.31 -8.89 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -145.13 -146.12 -1.00 H2S - Halite -7.56 -5.98 1.58 NaCl - Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 - Hydromagnesite -12.77 -21.53 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.58 -8.61 -8.03 MgCO3 - Mirabilite -6.83 -7.94 -1.11 Na2SO4:10H2O - Nahcolite -3.65 -4.20 -0.55 NaHCO3 - Natron -6.22 -7.53 -1.31 Na2CO3:10H2O - Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -487.90 -534.20 -46.30 As2S3 - Portlandite -9.76 13.04 22.80 Ca(OH)2 - Realgar -191.23 -211.17 -19.94 AsS - Sulfur -109.75 -124.77 -15.03 S - Thenardite -7.76 -7.94 -0.18 Na2SO4 - Thermonatrite -7.66 -7.53 0.12 Na2CO3:H2O - Trona -10.93 -11.73 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 21, cumulative pore volumes 21.000000. -Beginning of advection time step 22, cumulative pore volumes 22.000000. -Beginning of advection time step 23, cumulative pore volumes 23.000000. -Beginning of advection time step 24, cumulative pore volumes 24.000000. -Beginning of advection time step 25, cumulative pore volumes 25.000000. -Beginning of advection time step 26, cumulative pore volumes 26.000000. -Beginning of advection time step 27, cumulative pore volumes 27.000000. -Beginning of advection time step 28, cumulative pore volumes 28.000000. -Beginning of advection time step 29, cumulative pore volumes 29.000000. -Beginning of advection time step 30, cumulative pore volumes 30.000000. -Beginning of advection time step 31, cumulative pore volumes 31.000000. -Beginning of advection time step 32, cumulative pore volumes 32.000000. -Beginning of advection time step 33, cumulative pore volumes 33.000000. -Beginning of advection time step 34, cumulative pore volumes 34.000000. -Beginning of advection time step 35, cumulative pore volumes 35.000000. -Beginning of advection time step 36, cumulative pore volumes 36.000000. -Beginning of advection time step 37, cumulative pore volumes 37.000000. -Beginning of advection time step 38, cumulative pore volumes 38.000000. -Beginning of advection time step 39, cumulative pore volumes 39.000000. -Beginning of advection time step 40, cumulative pore volumes 40.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 2.832e-02 2.720e-02 -1.117e-03 - Dolomite -0.00 -17.09 -17.09 1.573e+00 1.573e+00 -5.221e-05 - -------------------------------Surface composition------------------------------ - -Hfo - -1.480e-03 Surface charge, eq - -7.936e-03 sigma, C/m**2 - -3.318e-02 psi, V - 1.291e+00 -F*psi/RT - 3.638e+00 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.308e-02 0.758 5.308e-02 -1.275 - Hfo_wOH2+ 8.547e-03 0.122 8.548e-03 -2.068 - Hfo_wO- 7.550e-03 0.108 7.551e-03 -2.122 - Hfo_wOHAsO4-3 8.229e-04 0.012 8.229e-04 -3.085 - Hfo_wOHSO4-2 3.772e-06 0.000 3.772e-06 -5.423 - Hfo_wHAsO4- 4.779e-07 0.000 4.779e-07 -6.321 - Hfo_wSO4- 3.045e-07 0.000 3.046e-07 -6.516 - Hfo_wH2AsO4 2.490e-09 0.000 2.490e-09 -8.604 - Hfo_wOCa+ 1.877e-12 0.000 1.877e-12 -11.727 - Hfo_wOMg+ 1.390e-12 0.000 1.390e-12 -11.857 - Hfo_wH2AsO3 5.569e-34 0.000 5.569e-34 -33.254 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - NaX 4.267e-01 4.267e-01 4.267e-01 -0.000 - CaX2 1.954e-01 3.907e-01 3.907e-01 -0.000 - MgX2 9.130e-02 1.826e-01 1.826e-01 -0.000 - HX 1.203e-06 1.203e-06 1.203e-06 -0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 3.060e-08 3.059e-08 - C 8.341e-03 8.341e-03 - Ca 4.111e-05 4.111e-05 - Cl 1.337e-04 1.337e-04 - Mg 2.852e-05 2.851e-05 - Na 8.966e-03 8.965e-03 - S 2.347e-04 2.347e-04 - -----------------------------Description of solution---------------------------- - - pH = 8.644 Charge balance - pe = 11.961 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.555e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 8.564e-03 - Total CO2 (mol/kg) = 8.341e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.232e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.34 - Iterations = 12 - Total H = 1.110124e+02 - Total O = 5.552854e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.877e-06 4.408e-06 -5.312 -5.356 -0.044 - H+ 2.481e-09 2.270e-09 -8.605 -8.644 -0.039 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -As(3) 5.480e-38 - H3AsO3 4.072e-38 4.081e-38 -37.390 -37.389 0.001 - H2AsO3- 1.408e-38 1.273e-38 -37.851 -37.895 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -43.776 -43.951 -0.176 - H4AsO3+ 0.000e+00 0.000e+00 -46.294 -46.338 -0.044 - AsO3-3 0.000e+00 0.000e+00 -50.612 -51.008 -0.395 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -315.151 -315.195 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -944.628 -944.672 -0.044 -As(5) 3.060e-08 - HAsO4-2 2.983e-08 1.991e-08 -7.525 -7.701 -0.176 - H2AsO4- 7.228e-10 6.533e-10 -9.141 -9.185 -0.044 - AsO4-3 4.875e-11 1.963e-11 -10.312 -10.707 -0.395 - H3AsO4 2.953e-16 2.959e-16 -15.530 -15.529 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -144.883 -144.882 0.001 -C(4) 8.341e-03 - HCO3- 8.013e-03 7.267e-03 -2.096 -2.139 -0.042 - CO3-2 2.219e-04 1.501e-04 -3.654 -3.824 -0.170 - CO2 3.702e-05 3.711e-05 -4.432 -4.431 0.001 - NaHCO3 3.284e-05 3.292e-05 -4.484 -4.483 0.001 - NaCO3- 2.491e-05 2.251e-05 -4.604 -4.648 -0.044 - CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 - MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 - CaHCO3+ 2.263e-06 2.045e-06 -5.645 -5.689 -0.044 - MgHCO3+ 1.538e-06 1.390e-06 -5.813 -5.857 -0.044 -Ca 4.111e-05 - Ca+2 3.264e-05 2.207e-05 -4.486 -4.656 -0.170 - CaCO3 5.537e-06 5.550e-06 -5.257 -5.256 0.001 - CaHCO3+ 2.263e-06 2.045e-06 -5.645 -5.689 -0.044 - CaSO4 6.701e-07 6.716e-07 -6.174 -6.173 0.001 - CaOH+ 1.784e-09 1.613e-09 -8.749 -8.792 -0.044 - CaHSO4+ 9.883e-15 8.933e-15 -14.005 -14.049 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.207e-04 -3.874 -3.918 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.362 -44.361 0.001 -Mg 2.852e-05 - Mg+2 2.403e-05 1.635e-05 -4.619 -4.787 -0.167 - MgCO3 2.336e-06 2.341e-06 -5.631 -5.631 0.001 - MgHCO3+ 1.538e-06 1.390e-06 -5.813 -5.857 -0.044 - MgSO4 5.832e-07 5.845e-07 -6.234 -6.233 0.001 - MgOH+ 2.891e-08 2.613e-08 -7.539 -7.583 -0.044 -Na 8.966e-03 - Na+ 8.901e-03 8.054e-03 -2.051 -2.094 -0.043 - NaHCO3 3.284e-05 3.292e-05 -4.484 -4.483 0.001 - NaCO3- 2.491e-05 2.251e-05 -4.604 -4.648 -0.044 - NaSO4- 6.812e-06 6.158e-06 -5.167 -5.211 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -143.556 -143.600 -0.044 - S5-2 0.000e+00 0.000e+00 -144.407 -144.551 -0.144 - S4-2 0.000e+00 0.000e+00 -144.634 -144.785 -0.151 - S6-2 0.000e+00 0.000e+00 -144.700 -144.837 -0.137 - H2S 0.000e+00 0.000e+00 -145.303 -145.302 0.001 - S-2 0.000e+00 0.000e+00 -147.699 -147.874 -0.176 - S3-2 0.000e+00 0.000e+00 -148.080 -148.238 -0.158 - S2-2 0.000e+00 0.000e+00 -149.319 -149.484 -0.165 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -315.151 -315.195 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -944.628 -944.672 -0.044 -S(6) 2.347e-04 - SO4-2 2.266e-04 1.525e-04 -3.645 -3.817 -0.172 - NaSO4- 6.812e-06 6.158e-06 -5.167 -5.211 -0.044 - CaSO4 6.701e-07 6.716e-07 -6.174 -6.173 0.001 - MgSO4 5.832e-07 5.845e-07 -6.234 -6.233 0.001 - HSO4- 3.725e-11 3.367e-11 -10.429 -10.473 -0.044 - CaHSO4+ 9.883e-15 8.933e-15 -14.005 -14.049 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -4.11 -8.47 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Arsenolite -73.40 -74.78 -1.38 As2O3 - Artinite -5.71 3.89 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -39.29 -31.06 8.23 As2O5 - As2S3(am) -486.61 -531.51 -44.90 As2S3 - As_native -86.67 -99.20 -12.53 As - Brucite -4.34 12.50 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -16.48 -35.38 -18.91 Ca3(AsO4)2:4H2O - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -142.02 -144.88 -2.86 CH4 - Claudetite -73.44 -74.78 -1.34 As2O3 - CO2(g) -2.96 -4.43 -1.47 CO2 - Dolomite -0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -6.46 -8.60 -2.14 MgSO4:7H2O - Gypsum -3.89 -8.47 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -144.31 -145.30 -1.00 H2S - Halite -7.59 -6.01 1.58 NaCl - Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 - Hydromagnesite -13.18 -21.94 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.58 -8.61 -8.03 MgCO3 - Mirabilite -6.89 -8.01 -1.11 Na2SO4:10H2O - Nahcolite -3.68 -4.23 -0.55 NaHCO3 - Natron -6.70 -8.01 -1.31 Na2CO3:10H2O - Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -485.21 -531.51 -46.30 As2S3 - Portlandite -10.17 12.63 22.80 Ca(OH)2 - Realgar -190.29 -210.24 -19.94 AsS - Sulfur -108.93 -123.95 -15.03 S - Thenardite -7.83 -8.00 -0.18 Na2SO4 - Thermonatrite -8.14 -8.01 0.12 Na2CO3:H2O - Trona -11.45 -12.24 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 41, cumulative pore volumes 41.000000. -Beginning of advection time step 42, cumulative pore volumes 42.000000. -Beginning of advection time step 43, cumulative pore volumes 43.000000. -Beginning of advection time step 44, cumulative pore volumes 44.000000. -Beginning of advection time step 45, cumulative pore volumes 45.000000. -Beginning of advection time step 46, cumulative pore volumes 46.000000. -Beginning of advection time step 47, cumulative pore volumes 47.000000. -Beginning of advection time step 48, cumulative pore volumes 48.000000. -Beginning of advection time step 49, cumulative pore volumes 49.000000. -Beginning of advection time step 50, cumulative pore volumes 50.000000. -Beginning of advection time step 51, cumulative pore volumes 51.000000. -Beginning of advection time step 52, cumulative pore volumes 52.000000. -Beginning of advection time step 53, cumulative pore volumes 53.000000. -Beginning of advection time step 54, cumulative pore volumes 54.000000. -Beginning of advection time step 55, cumulative pore volumes 55.000000. -Beginning of advection time step 56, cumulative pore volumes 56.000000. -Beginning of advection time step 57, cumulative pore volumes 57.000000. -Beginning of advection time step 58, cumulative pore volumes 58.000000. -Beginning of advection time step 59, cumulative pore volumes 59.000000. -Beginning of advection time step 60, cumulative pore volumes 60.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 7.030e-03 6.028e-03 -1.002e-03 - Dolomite 0.00 -17.09 -17.09 1.573e+00 1.573e+00 1.267e-05 - -------------------------------Surface composition------------------------------ - -Hfo - -2.886e-04 Surface charge, eq - -1.547e-03 sigma, C/m**2 - -7.102e-03 psi, V - 2.764e-01 -F*psi/RT - 1.318e+00 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.296e-02 0.757 5.296e-02 -1.276 - Hfo_wOH2+ 9.213e-03 0.132 9.213e-03 -2.036 - Hfo_wO- 6.974e-03 0.100 6.975e-03 -2.156 - Hfo_wOHAsO4-3 8.225e-04 0.012 8.226e-04 -3.085 - Hfo_wOHSO4-2 2.832e-05 0.000 2.833e-05 -4.548 - Hfo_wSO4- 2.470e-06 0.000 2.470e-06 -5.607 - Hfo_wHAsO4- 5.574e-07 0.000 5.574e-07 -6.254 - Hfo_wH2AsO4 3.138e-09 0.000 3.138e-09 -8.503 - Hfo_wOCa+ 6.903e-13 0.000 6.904e-13 -12.161 - Hfo_wOMg+ 5.113e-13 0.000 5.114e-13 -12.291 - Hfo_wH2AsO3 7.018e-34 0.000 7.018e-34 -33.154 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - NaX 2.571e-01 2.571e-01 2.571e-01 0.000 - CaX2 2.531e-01 5.063e-01 5.063e-01 0.000 - MgX2 1.183e-01 2.366e-01 2.366e-01 0.000 - HX 2.343e-06 2.343e-06 2.343e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 4.506e-09 4.505e-09 - C 8.097e-03 8.096e-03 - Ca 1.123e-04 1.123e-04 - Cl 1.337e-04 1.337e-04 - Mg 8.089e-05 8.089e-05 - Na 8.229e-03 8.229e-03 - S 2.318e-04 2.318e-04 - -----------------------------Description of solution---------------------------- - - pH = 8.170 Charge balance - pe = 12.436 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.032e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 8.078e-03 - Total CO2 (mol/kg) = 8.097e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.959e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.35 - Iterations = 11 - Total H = 1.110124e+02 - Total O = 5.552779e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.632e-06 1.479e-06 -5.787 -5.830 -0.043 - H+ 7.382e-09 6.767e-09 -8.132 -8.170 -0.038 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -As(3) 5.738e-38 - H3AsO3 5.143e-38 5.154e-38 -37.289 -37.288 0.001 - H2AsO3- 5.950e-39 5.392e-39 -38.225 -38.268 -0.043 - HAsO3-2 0.000e+00 0.000e+00 -44.627 -44.799 -0.171 - H4AsO3+ 0.000e+00 0.000e+00 -45.720 -45.762 -0.043 - AsO3-3 0.000e+00 0.000e+00 -51.944 -52.329 -0.385 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -313.638 -313.680 -0.043 - As3S4(HS)2- 0.000e+00 0.000e+00 -939.137 -939.180 -0.043 -As(5) 4.506e-09 - HAsO4-2 4.198e-09 2.830e-09 -8.377 -8.548 -0.171 - H2AsO4- 3.055e-10 2.768e-10 -9.515 -9.558 -0.043 - AsO4-3 2.274e-12 9.362e-13 -11.643 -12.029 -0.385 - H3AsO4 3.729e-16 3.737e-16 -15.428 -15.427 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -144.416 -144.415 0.001 -C(4) 8.097e-03 - HCO3- 7.859e-03 7.144e-03 -2.105 -2.146 -0.041 - CO2 1.085e-04 1.087e-04 -3.965 -3.964 0.001 - CO3-2 7.251e-05 4.951e-05 -4.140 -4.305 -0.166 - NaHCO3 2.977e-05 2.983e-05 -4.526 -4.525 0.001 - NaCO3- 7.555e-06 6.846e-06 -5.122 -5.165 -0.043 - CaHCO3+ 6.728e-06 6.097e-06 -5.172 -5.215 -0.043 - CaCO3 5.538e-06 5.550e-06 -5.257 -5.256 0.001 - MgHCO3+ 4.572e-06 4.143e-06 -5.340 -5.383 -0.043 - MgCO3 2.337e-06 2.341e-06 -5.631 -5.631 0.001 -Ca 1.123e-04 - Ca+2 9.805e-05 6.691e-05 -4.009 -4.175 -0.166 - CaHCO3+ 6.728e-06 6.097e-06 -5.172 -5.215 -0.043 - CaCO3 5.538e-06 5.550e-06 -5.257 -5.256 0.001 - CaSO4 2.008e-06 2.013e-06 -5.697 -5.696 0.001 - CaOH+ 1.810e-09 1.640e-09 -8.742 -8.785 -0.043 - CaHSO4+ 8.806e-14 7.979e-14 -13.055 -13.098 -0.043 -Cl 1.337e-04 - Cl- 1.337e-04 1.210e-04 -3.874 -3.917 -0.044 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 8.089e-05 - Mg+2 7.221e-05 4.956e-05 -4.141 -4.305 -0.163 - MgHCO3+ 4.572e-06 4.143e-06 -5.340 -5.383 -0.043 - MgCO3 2.337e-06 2.341e-06 -5.631 -5.631 0.001 - MgSO4 1.748e-06 1.752e-06 -5.757 -5.757 0.001 - MgOH+ 2.934e-08 2.658e-08 -7.533 -7.575 -0.043 -Na 8.229e-03 - Na+ 8.186e-03 7.425e-03 -2.087 -2.129 -0.042 - NaHCO3 2.977e-05 2.983e-05 -4.526 -4.525 0.001 - NaCO3- 7.555e-06 6.846e-06 -5.122 -5.165 -0.043 - NaSO4- 6.192e-06 5.611e-06 -5.208 -5.251 -0.043 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -143.088 -143.131 -0.043 - H2S 0.000e+00 0.000e+00 -144.359 -144.359 0.001 - S5-2 0.000e+00 0.000e+00 -144.415 -144.556 -0.141 - S4-2 0.000e+00 0.000e+00 -144.642 -144.790 -0.148 - S6-2 0.000e+00 0.000e+00 -144.707 -144.842 -0.135 - S-2 0.000e+00 0.000e+00 -147.708 -147.879 -0.171 - S3-2 0.000e+00 0.000e+00 -148.088 -148.243 -0.155 - S2-2 0.000e+00 0.000e+00 -149.328 -149.489 -0.161 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -313.638 -313.680 -0.043 - As3S4(HS)2- 0.000e+00 0.000e+00 -939.137 -939.180 -0.043 -S(6) 2.318e-04 - SO4-2 2.219e-04 1.508e-04 -3.654 -3.822 -0.168 - NaSO4- 6.192e-06 5.611e-06 -5.208 -5.251 -0.043 - CaSO4 2.008e-06 2.013e-06 -5.697 -5.696 0.001 - MgSO4 1.748e-06 1.752e-06 -5.757 -5.757 0.001 - HSO4- 1.095e-10 9.919e-11 -9.961 -10.004 -0.043 - CaHSO4+ 8.806e-14 7.979e-14 -13.055 -13.098 -0.043 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.64 -8.00 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Arsenolite -73.20 -74.58 -1.38 As2O3 - Artinite -6.18 3.42 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -39.08 -30.85 8.23 As2O5 - As2S3(am) -483.58 -528.48 -44.90 As2S3 - As_native -86.57 -99.10 -12.53 As - Brucite -4.81 12.03 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -17.68 -36.58 -18.91 Ca3(AsO4)2:4H2O - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -141.56 -144.42 -2.86 CH4 - Claudetite -73.24 -74.58 -1.34 As2O3 - CO2(g) -2.50 -3.96 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -5.99 -8.13 -2.14 MgSO4:7H2O - Gypsum -3.42 -8.00 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -143.36 -144.36 -1.00 H2S - Halite -7.63 -6.05 1.58 NaCl - Huntite -4.34 -34.31 -29.97 CaMg3(CO3)4 - Hydromagnesite -13.65 -22.41 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.58 -8.61 -8.03 MgCO3 - Mirabilite -6.97 -8.08 -1.11 Na2SO4:10H2O - Nahcolite -3.73 -4.28 -0.55 NaHCO3 - Natron -7.25 -8.57 -1.31 Na2CO3:10H2O - Nesquehonite -2.99 -8.61 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -482.18 -528.48 -46.30 As2S3 - Portlandite -10.64 12.16 22.80 Ca(OH)2 - Realgar -189.25 -209.19 -19.94 AsS - Sulfur -107.98 -123.01 -15.03 S - Thenardite -7.90 -8.08 -0.18 Na2SO4 - Thermonatrite -8.69 -8.56 0.12 Na2CO3:H2O - Trona -12.04 -12.84 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 61, cumulative pore volumes 61.000000. -Beginning of advection time step 62, cumulative pore volumes 62.000000. -Beginning of advection time step 63, cumulative pore volumes 63.000000. -Beginning of advection time step 64, cumulative pore volumes 64.000000. -Beginning of advection time step 65, cumulative pore volumes 65.000000. -Beginning of advection time step 66, cumulative pore volumes 66.000000. -Beginning of advection time step 67, cumulative pore volumes 67.000000. -Beginning of advection time step 68, cumulative pore volumes 68.000000. -Beginning of advection time step 69, cumulative pore volumes 69.000000. -Beginning of advection time step 70, cumulative pore volumes 70.000000. -Beginning of advection time step 71, cumulative pore volumes 71.000000. -Beginning of advection time step 72, cumulative pore volumes 72.000000. -Beginning of advection time step 73, cumulative pore volumes 73.000000. -Beginning of advection time step 74, cumulative pore volumes 74.000000. -Beginning of advection time step 75, cumulative pore volumes 75.000000. -Beginning of advection time step 76, cumulative pore volumes 76.000000. -Beginning of advection time step 77, cumulative pore volumes 77.000000. -Beginning of advection time step 78, cumulative pore volumes 78.000000. -Beginning of advection time step 79, cumulative pore volumes 79.000000. -Beginning of advection time step 80, cumulative pore volumes 80.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.568e+00 1.568e+00 -3.004e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 9.677e-04 Surface charge, eq - 5.188e-03 sigma, C/m**2 - 2.356e-02 psi, V - -9.170e-01 -F*psi/RT - 3.997e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.250e-02 0.750 5.251e-02 -1.280 - Hfo_wOH2+ 1.019e-02 0.146 1.019e-02 -1.992 - Hfo_wO- 6.199e-03 0.089 6.199e-03 -2.208 - Hfo_wOHAsO4-3 8.223e-04 0.012 8.224e-04 -3.085 - Hfo_wOHSO4-2 2.636e-04 0.004 2.636e-04 -3.579 - Hfo_wSO4- 2.564e-05 0.000 2.564e-05 -4.591 - Hfo_wHAsO4- 6.933e-07 0.000 6.933e-07 -6.159 - Hfo_wH2AsO4 4.353e-09 0.000 4.353e-09 -8.361 - Hfo_wOCa+ 2.176e-13 0.000 2.176e-13 -12.662 - Hfo_wOMg+ 1.711e-13 0.000 1.712e-13 -12.767 - Hfo_wH2AsO3 9.736e-34 0.000 9.737e-34 -33.012 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 2.972e-01 5.944e-01 5.944e-01 0.000 - MgX2 1.475e-01 2.950e-01 2.950e-01 0.000 - NaX 1.106e-01 1.106e-01 1.106e-01 0.000 - HX 4.756e-06 4.756e-06 4.756e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 5.470e-10 5.469e-10 - C 7.720e-03 7.720e-03 - Ca 4.118e-04 4.117e-04 - Cl 1.337e-04 1.337e-04 - Mg 3.198e-04 3.198e-04 - Na 6.400e-03 6.399e-03 - S 2.072e-04 2.072e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.604 Charge balance - pe = 13.001 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.663e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 7.379e-03 - Total CO2 (mol/kg) = 7.720e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.390e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.41 - Iterations = 13 - Total H = 1.110123e+02 - Total O = 5.552657e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.429e-07 4.020e-07 -6.354 -6.396 -0.042 - H+ 2.712e-08 2.490e-08 -7.567 -7.604 -0.037 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -As(3) 7.424e-38 - H3AsO3 7.198e-38 7.213e-38 -37.143 -37.142 0.001 - H2AsO3- 2.259e-39 2.051e-39 -38.646 -38.688 -0.042 - H4AsO3+ 0.000e+00 0.000e+00 -45.009 -45.051 -0.042 - HAsO3-2 0.000e+00 0.000e+00 -45.616 -45.784 -0.168 - AsO3-3 0.000e+00 0.000e+00 -53.502 -53.880 -0.378 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -311.923 -311.965 -0.042 - As3S4(HS)2- 0.000e+00 0.000e+00 -932.861 -932.903 -0.042 -As(5) 5.470e-10 - HAsO4-2 4.309e-10 2.926e-10 -9.366 -9.534 -0.168 - H2AsO4- 1.160e-10 1.053e-10 -9.936 -9.978 -0.042 - AsO4-3 6.288e-14 2.631e-14 -13.202 -13.580 -0.378 - H3AsO4 5.219e-16 5.230e-16 -15.282 -15.282 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.884 -143.883 0.001 -C(4) 7.720e-03 - HCO3- 7.261e-03 6.611e-03 -2.139 -2.180 -0.041 - CO2 3.694e-04 3.702e-04 -3.432 -3.432 0.001 - CaHCO3+ 2.398e-05 2.177e-05 -4.620 -4.662 -0.042 - NaHCO3 2.149e-05 2.153e-05 -4.668 -4.667 0.001 - CO3-2 1.812e-05 1.245e-05 -4.742 -4.905 -0.163 - MgHCO3+ 1.730e-05 1.571e-05 -4.762 -4.804 -0.042 - CaCO3 5.375e-06 5.385e-06 -5.270 -5.269 0.001 - MgCO3 2.408e-06 2.413e-06 -5.618 -5.617 0.001 - NaCO3- 1.479e-06 1.343e-06 -5.830 -5.872 -0.042 -Ca 4.118e-04 - Ca+2 3.757e-04 2.581e-04 -3.425 -3.588 -0.163 - CaHCO3+ 2.398e-05 2.177e-05 -4.620 -4.662 -0.042 - CaSO4 6.687e-06 6.700e-06 -5.175 -5.174 0.001 - CaCO3 5.375e-06 5.385e-06 -5.270 -5.269 0.001 - CaOH+ 1.895e-09 1.720e-09 -8.722 -8.764 -0.042 - CaHSO4+ 1.077e-12 9.772e-13 -11.968 -12.010 -0.042 -Cl 1.337e-04 - Cl- 1.337e-04 1.212e-04 -3.874 -3.917 -0.043 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 3.198e-04 - Mg+2 2.939e-04 2.030e-04 -3.532 -3.692 -0.161 - MgHCO3+ 1.730e-05 1.571e-05 -4.762 -4.804 -0.042 - MgSO4 6.180e-06 6.192e-06 -5.209 -5.208 0.001 - MgCO3 2.408e-06 2.413e-06 -5.618 -5.617 0.001 - MgOH+ 3.261e-08 2.960e-08 -7.487 -7.529 -0.042 -Na 6.400e-03 - Na+ 6.373e-03 5.791e-03 -2.196 -2.237 -0.042 - NaHCO3 2.149e-05 2.153e-05 -4.668 -4.667 0.001 - NaSO4- 4.160e-06 3.776e-06 -5.381 -5.423 -0.042 - NaCO3- 1.479e-06 1.343e-06 -5.830 -5.872 -0.042 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.587 -142.629 -0.042 - H2S 0.000e+00 0.000e+00 -143.292 -143.291 0.001 - S5-2 0.000e+00 0.000e+00 -144.481 -144.620 -0.139 - S4-2 0.000e+00 0.000e+00 -144.709 -144.854 -0.145 - S6-2 0.000e+00 0.000e+00 -144.773 -144.906 -0.133 - S-2 0.000e+00 0.000e+00 -147.775 -147.943 -0.168 - S3-2 0.000e+00 0.000e+00 -148.155 -148.307 -0.152 - S2-2 0.000e+00 0.000e+00 -149.395 -149.553 -0.158 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -311.923 -311.965 -0.042 - As3S4(HS)2- 0.000e+00 0.000e+00 -932.861 -932.903 -0.042 -S(6) 2.072e-04 - SO4-2 1.902e-04 1.301e-04 -3.721 -3.886 -0.165 - CaSO4 6.687e-06 6.700e-06 -5.175 -5.174 0.001 - MgSO4 6.180e-06 6.192e-06 -5.209 -5.208 0.001 - NaSO4- 4.160e-06 3.776e-06 -5.381 -5.423 -0.042 - HSO4- 3.469e-10 3.149e-10 -9.460 -9.502 -0.042 - CaHSO4+ 1.077e-12 9.772e-13 -11.968 -12.010 -0.042 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.11 -7.47 -4.36 CaSO4 - Aragonite -0.16 -8.49 -8.34 CaCO3 - Arsenolite -72.90 -74.28 -1.38 As2O3 - Artinite -6.68 2.92 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -38.79 -30.56 8.23 As2O5 - As2S3(am) -480.08 -524.98 -44.90 As2S3 - As_native -86.43 -98.96 -12.53 As - Brucite -5.32 11.52 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.02 -37.92 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.01 -8.49 -8.48 CaCO3 - CH4(g) -141.02 -143.88 -2.86 CH4 - Claudetite -72.94 -74.28 -1.34 As2O3 - CO2(g) -1.96 -3.43 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -5.44 -7.58 -2.14 MgSO4:7H2O - Gypsum -2.89 -7.47 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -142.29 -143.29 -1.00 H2S - Halite -7.74 -6.15 1.58 NaCl - Huntite -4.32 -34.28 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.11 -22.87 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.57 -8.60 -8.03 MgCO3 - Mirabilite -7.25 -8.36 -1.11 Na2SO4:10H2O - Nahcolite -3.87 -4.42 -0.55 NaHCO3 - Natron -8.07 -9.38 -1.31 Na2CO3:10H2O - Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -478.68 -524.98 -46.30 As2S3 - Portlandite -11.18 11.62 22.80 Ca(OH)2 - Realgar -188.04 -207.98 -19.94 AsS - Sulfur -106.91 -121.94 -15.03 S - Thenardite -8.18 -8.36 -0.18 Na2SO4 - Thermonatrite -9.50 -9.38 0.12 Na2CO3:H2O - Trona -13.00 -13.80 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 81, cumulative pore volumes 81.000000. -Beginning of advection time step 82, cumulative pore volumes 82.000000. -Beginning of advection time step 83, cumulative pore volumes 83.000000. -Beginning of advection time step 84, cumulative pore volumes 84.000000. -Beginning of advection time step 85, cumulative pore volumes 85.000000. -Beginning of advection time step 86, cumulative pore volumes 86.000000. -Beginning of advection time step 87, cumulative pore volumes 87.000000. -Beginning of advection time step 88, cumulative pore volumes 88.000000. -Beginning of advection time step 89, cumulative pore volumes 89.000000. -Beginning of advection time step 90, cumulative pore volumes 90.000000. -Beginning of advection time step 91, cumulative pore volumes 91.000000. -Beginning of advection time step 92, cumulative pore volumes 92.000000. -Beginning of advection time step 93, cumulative pore volumes 93.000000. -Beginning of advection time step 94, cumulative pore volumes 94.000000. -Beginning of advection time step 95, cumulative pore volumes 95.000000. -Beginning of advection time step 96, cumulative pore volumes 96.000000. -Beginning of advection time step 97, cumulative pore volumes 97.000000. -Beginning of advection time step 98, cumulative pore volumes 98.000000. -Beginning of advection time step 99, cumulative pore volumes 99.000000. -Beginning of advection time step 100, cumulative pore volumes 100.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 -5.456e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.005e-03 Surface charge, eq - 1.075e-02 sigma, C/m**2 - 4.415e-02 psi, V - -1.719e+00 -F*psi/RT - 1.793e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.116e-02 0.731 5.116e-02 -1.291 - Hfo_wOH2+ 1.176e-02 0.168 1.177e-02 -1.929 - Hfo_wO- 5.096e-03 0.073 5.097e-03 -2.293 - Hfo_wOHSO4-2 1.038e-03 0.015 1.038e-03 -2.984 - Hfo_wOHAsO4-3 8.220e-04 0.012 8.221e-04 -3.085 - Hfo_wSO4- 1.197e-04 0.002 1.197e-04 -3.922 - Hfo_wHAsO4- 9.734e-07 0.000 9.735e-07 -6.012 - Hfo_wH2AsO4 7.244e-09 0.000 7.244e-09 -8.140 - Hfo_wOCa+ 1.086e-13 0.000 1.086e-13 -12.964 - Hfo_wOMg+ 8.842e-14 0.000 8.843e-14 -13.053 - Hfo_wH2AsO3 1.620e-33 0.000 1.620e-33 -32.790 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.218e-01 6.437e-01 6.437e-01 0.000 - MgX2 1.654e-01 3.308e-01 3.308e-01 0.000 - NaX 2.548e-02 2.548e-02 2.548e-02 0.000 - HX 7.530e-06 7.530e-06 7.530e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.811e-10 1.810e-10 - C 7.229e-03 7.228e-03 - Ca 1.222e-03 1.222e-03 - Cl 1.337e-04 1.337e-04 - Mg 9.867e-04 9.866e-04 - Na 2.461e-03 2.461e-03 - S 1.889e-04 1.888e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.182 Charge balance - pe = 13.423 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.921e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.402e-03 - Total CO2 (mol/kg) = 7.229e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.426e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.26 - Iterations = 9 - Total H = 1.110123e+02 - Total O = 5.552502e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.678e-07 1.522e-07 -6.775 -6.818 -0.043 - H+ 7.172e-08 6.577e-08 -7.144 -7.182 -0.038 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.244e-37 - H3AsO3 1.229e-37 1.232e-37 -36.910 -36.909 0.001 - H2AsO3- 1.462e-39 1.326e-39 -38.835 -38.878 -0.043 - H4AsO3+ 0.000e+00 0.000e+00 -44.354 -44.396 -0.043 - HAsO3-2 0.000e+00 0.000e+00 -46.225 -46.396 -0.170 - AsO3-3 0.000e+00 0.000e+00 -54.530 -54.914 -0.383 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.604 -310.646 -0.043 - As3S4(HS)2- 0.000e+00 0.000e+00 -928.060 -928.103 -0.043 -As(5) 1.811e-10 - HAsO4-2 1.060e-10 7.159e-11 -9.975 -10.145 -0.170 - H2AsO4- 7.507e-11 6.806e-11 -10.125 -10.167 -0.043 - AsO4-3 5.890e-15 2.437e-15 -14.230 -14.613 -0.383 - H3AsO4 8.914e-16 8.932e-16 -15.050 -15.049 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.527 -143.526 0.001 -C(4) 7.229e-03 - HCO3- 6.259e-03 5.692e-03 -2.204 -2.245 -0.041 - CO2 8.402e-04 8.419e-04 -3.076 -3.075 0.001 - CaHCO3+ 6.233e-05 5.651e-05 -4.205 -4.248 -0.043 - MgHCO3+ 4.658e-05 4.223e-05 -4.332 -4.374 -0.043 - NaHCO3 7.110e-06 7.125e-06 -5.148 -5.147 0.001 - CO3-2 5.932e-06 4.058e-06 -5.227 -5.392 -0.165 - CaCO3 5.281e-06 5.292e-06 -5.277 -5.276 0.001 - MgCO3 2.450e-06 2.455e-06 -5.611 -5.610 0.001 - NaCO3- 1.856e-07 1.682e-07 -6.732 -6.774 -0.043 -Ca 1.222e-03 - Ca+2 1.138e-03 7.784e-04 -2.944 -3.109 -0.165 - CaHCO3+ 6.233e-05 5.651e-05 -4.205 -4.248 -0.043 - CaSO4 1.640e-05 1.644e-05 -4.785 -4.784 0.001 - CaCO3 5.281e-06 5.292e-06 -5.277 -5.276 0.001 - CaOH+ 2.166e-09 1.964e-09 -8.664 -8.707 -0.043 - CaHSO4+ 6.986e-12 6.334e-12 -11.156 -11.198 -0.043 -Cl 1.337e-04 - Cl- 1.337e-04 1.210e-04 -3.874 -3.917 -0.043 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.360 0.001 -Mg 9.867e-04 - Mg+2 9.219e-04 6.340e-04 -3.035 -3.198 -0.163 - MgHCO3+ 4.658e-05 4.223e-05 -4.332 -4.374 -0.043 - MgSO4 1.570e-05 1.573e-05 -4.804 -4.803 0.001 - MgCO3 2.450e-06 2.455e-06 -5.611 -5.610 0.001 - MgOH+ 3.860e-08 3.499e-08 -7.413 -7.456 -0.043 -Na 2.461e-03 - Na+ 2.453e-03 2.226e-03 -2.610 -2.652 -0.042 - NaHCO3 7.110e-06 7.125e-06 -5.148 -5.147 0.001 - NaSO4- 1.302e-06 1.181e-06 -5.885 -5.928 -0.043 - NaCO3- 1.856e-07 1.682e-07 -6.732 -6.774 -0.043 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.254 -142.297 -0.043 - H2S 0.000e+00 0.000e+00 -142.538 -142.537 0.001 - S5-2 0.000e+00 0.000e+00 -144.569 -144.710 -0.140 - S4-2 0.000e+00 0.000e+00 -144.797 -144.944 -0.147 - S6-2 0.000e+00 0.000e+00 -144.862 -144.996 -0.134 - S-2 0.000e+00 0.000e+00 -147.862 -148.033 -0.170 - S3-2 0.000e+00 0.000e+00 -148.243 -148.397 -0.154 - S2-2 0.000e+00 0.000e+00 -149.483 -149.643 -0.160 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.604 -310.646 -0.043 - As3S4(HS)2- 0.000e+00 0.000e+00 -928.060 -928.103 -0.043 -S(6) 1.889e-04 - SO4-2 1.554e-04 1.058e-04 -3.808 -3.975 -0.167 - CaSO4 1.640e-05 1.644e-05 -4.785 -4.784 0.001 - MgSO4 1.570e-05 1.573e-05 -4.804 -4.803 0.001 - NaSO4- 1.302e-06 1.181e-06 -5.885 -5.928 -0.043 - HSO4- 7.465e-10 6.768e-10 -9.127 -9.170 -0.043 - CaHSO4+ 6.986e-12 6.334e-12 -11.156 -11.198 -0.043 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.72 -7.08 -4.36 CaSO4 - Aragonite -0.16 -8.50 -8.34 CaCO3 - Arsenolite -72.44 -73.82 -1.38 As2O3 - Artinite -7.02 2.58 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -38.33 -30.10 8.23 As2O5 - As2S3(am) -477.35 -522.25 -44.90 As2S3 - As_native -86.19 -98.72 -12.53 As - Brucite -5.67 11.17 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.65 -38.55 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.02 -8.50 -8.48 CaCO3 - CH4(g) -140.67 -143.53 -2.86 CH4 - Claudetite -72.48 -73.82 -1.34 As2O3 - CO2(g) -1.61 -3.07 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -5.03 -7.17 -2.14 MgSO4:7H2O - Gypsum -2.50 -7.08 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.54 -142.54 -1.00 H2S - Halite -8.15 -6.57 1.58 NaCl - Huntite -4.30 -34.27 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.43 -23.19 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.56 -8.59 -8.03 MgCO3 - Mirabilite -8.17 -9.28 -1.11 Na2SO4:10H2O - Nahcolite -4.35 -4.90 -0.55 NaHCO3 - Natron -9.39 -10.70 -1.31 Na2CO3:10H2O - Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -475.95 -522.25 -46.30 As2S3 - Portlandite -11.55 11.25 22.80 Ca(OH)2 - Realgar -187.05 -206.99 -19.94 AsS - Sulfur -106.16 -121.19 -15.03 S - Thenardite -9.10 -9.28 -0.18 Na2SO4 - Thermonatrite -10.82 -10.70 0.12 Na2CO3:H2O - Trona -14.80 -15.59 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 101, cumulative pore volumes 101.000000. -Beginning of advection time step 102, cumulative pore volumes 102.000000. -Beginning of advection time step 103, cumulative pore volumes 103.000000. -Beginning of advection time step 104, cumulative pore volumes 104.000000. -Beginning of advection time step 105, cumulative pore volumes 105.000000. -Beginning of advection time step 106, cumulative pore volumes 106.000000. -Beginning of advection time step 107, cumulative pore volumes 107.000000. -Beginning of advection time step 108, cumulative pore volumes 108.000000. -Beginning of advection time step 109, cumulative pore volumes 109.000000. -Beginning of advection time step 110, cumulative pore volumes 110.000000. -Beginning of advection time step 111, cumulative pore volumes 111.000000. -Beginning of advection time step 112, cumulative pore volumes 112.000000. -Beginning of advection time step 113, cumulative pore volumes 113.000000. -Beginning of advection time step 114, cumulative pore volumes 114.000000. -Beginning of advection time step 115, cumulative pore volumes 115.000000. -Beginning of advection time step 116, cumulative pore volumes 116.000000. -Beginning of advection time step 117, cumulative pore volumes 117.000000. -Beginning of advection time step 118, cumulative pore volumes 118.000000. -Beginning of advection time step 119, cumulative pore volumes 119.000000. -Beginning of advection time step 120, cumulative pore volumes 120.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.153e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.333e-03 Surface charge, eq - 1.251e-02 sigma, C/m**2 - 4.866e-02 psi, V - -1.894e+00 -F*psi/RT - 1.505e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 5.018e-02 0.717 5.018e-02 -1.299 - Hfo_wOH2+ 1.268e-02 0.181 1.268e-02 -1.897 - Hfo_wO- 4.548e-03 0.065 4.548e-03 -2.342 - Hfo_wOHSO4-2 1.569e-03 0.022 1.569e-03 -2.804 - Hfo_wOHAsO4-3 8.218e-04 0.012 8.219e-04 -3.085 - Hfo_wSO4- 1.988e-04 0.003 1.988e-04 -3.702 - Hfo_wHAsO4- 1.176e-06 0.000 1.176e-06 -5.930 - Hfo_wH2AsO4 9.617e-09 0.000 9.618e-09 -8.017 - Hfo_wOCa+ 9.482e-14 0.000 9.482e-14 -13.023 - Hfo_wOMg+ 7.699e-14 0.000 7.699e-14 -13.114 - Hfo_wH2AsO3 2.151e-33 0.000 2.151e-33 -32.667 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.292e-01 6.584e-01 6.584e-01 0.000 - MgX2 1.687e-01 3.373e-01 3.373e-01 0.000 - NaX 4.301e-03 4.301e-03 4.301e-03 0.000 - HX 8.461e-06 8.461e-06 8.461e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.623e-10 1.623e-10 - C 7.117e-03 7.117e-03 - Ca 1.709e-03 1.709e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.376e-03 1.376e-03 - Na 4.854e-04 4.853e-04 - S 2.190e-04 2.189e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.065 Charge balance - pe = 13.540 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.464e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.091e-03 - Total CO2 (mol/kg) = 7.117e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.811e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.552481e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.285e-07 1.162e-07 -6.891 -6.935 -0.044 - H+ 9.412e-08 8.614e-08 -7.026 -7.065 -0.038 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.679e-37 - H3AsO3 1.664e-37 1.667e-37 -36.779 -36.778 0.001 - H2AsO3- 1.515e-39 1.370e-39 -38.819 -38.863 -0.044 - H4AsO3+ 0.000e+00 0.000e+00 -44.104 -44.148 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -46.324 -46.498 -0.175 - AsO3-3 0.000e+00 0.000e+00 -54.740 -55.134 -0.393 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.049 -310.093 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -926.164 -926.208 -0.044 -As(5) 1.623e-10 - HAsO4-2 8.450e-11 5.650e-11 -10.073 -10.248 -0.175 - H2AsO4- 7.779e-11 7.035e-11 -10.109 -10.153 -0.044 - AsO4-3 3.632e-15 1.468e-15 -14.440 -14.833 -0.393 - H3AsO4 1.206e-15 1.209e-15 -14.918 -14.918 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.435 -143.434 0.001 -C(4) 7.117e-03 - HCO3- 5.922e-03 5.373e-03 -2.228 -2.270 -0.042 - CO2 1.039e-03 1.041e-03 -2.984 -2.983 0.001 - CaHCO3+ 8.197e-05 7.412e-05 -4.086 -4.130 -0.044 - MgHCO3+ 6.106e-05 5.522e-05 -4.214 -4.258 -0.044 - CaCO3 5.289e-06 5.300e-06 -5.277 -5.276 0.001 - CO3-2 4.317e-06 2.925e-06 -5.365 -5.534 -0.169 - MgCO3 2.446e-06 2.452e-06 -5.612 -5.611 0.001 - NaHCO3 1.320e-06 1.323e-06 -5.879 -5.878 0.001 - NaCO3- 2.638e-08 2.385e-08 -7.579 -7.622 -0.044 -Ca 1.709e-03 - Ca+2 1.597e-03 1.082e-03 -2.797 -2.966 -0.169 - CaHCO3+ 8.197e-05 7.412e-05 -4.086 -4.130 -0.044 - CaSO4 2.473e-05 2.478e-05 -4.607 -4.606 0.001 - CaCO3 5.289e-06 5.300e-06 -5.277 -5.276 0.001 - CaOH+ 2.304e-09 2.083e-09 -8.638 -8.681 -0.044 - CaHSO4+ 1.383e-11 1.251e-11 -10.859 -10.903 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.207e-04 -3.874 -3.918 -0.044 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.376e-03 - Mg+2 1.289e-03 8.783e-04 -2.890 -3.056 -0.167 - MgHCO3+ 6.106e-05 5.522e-05 -4.214 -4.258 -0.044 - MgSO4 2.359e-05 2.364e-05 -4.627 -4.626 0.001 - MgCO3 2.446e-06 2.452e-06 -5.612 -5.611 0.001 - MgOH+ 4.093e-08 3.701e-08 -7.388 -7.432 -0.044 -Na 4.854e-04 - Na+ 4.837e-04 4.379e-04 -3.315 -3.359 -0.043 - NaHCO3 1.320e-06 1.323e-06 -5.879 -5.878 0.001 - NaSO4- 2.787e-07 2.520e-07 -6.555 -6.599 -0.044 - NaCO3- 2.638e-08 2.385e-08 -7.579 -7.622 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.100 -142.144 -0.044 - H2S 0.000e+00 0.000e+00 -142.268 -142.267 0.001 - S5-2 0.000e+00 0.000e+00 -144.531 -144.674 -0.143 - S4-2 0.000e+00 0.000e+00 -144.758 -144.908 -0.150 - S6-2 0.000e+00 0.000e+00 -144.823 -144.960 -0.137 - S-2 0.000e+00 0.000e+00 -147.822 -147.997 -0.175 - S3-2 0.000e+00 0.000e+00 -148.203 -148.361 -0.158 - S2-2 0.000e+00 0.000e+00 -149.443 -149.607 -0.164 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -310.049 -310.093 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -926.164 -926.208 -0.044 -S(6) 2.190e-04 - SO4-2 1.704e-04 1.148e-04 -3.769 -3.940 -0.171 - CaSO4 2.473e-05 2.478e-05 -4.607 -4.606 0.001 - MgSO4 2.359e-05 2.364e-05 -4.627 -4.626 0.001 - NaSO4- 2.787e-07 2.520e-07 -6.555 -6.599 -0.044 - HSO4- 1.064e-09 9.618e-10 -8.973 -9.017 -0.044 - CaHSO4+ 1.383e-11 1.251e-11 -10.859 -10.903 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.55 -6.91 -4.36 CaSO4 - Aragonite -0.16 -8.50 -8.34 CaCO3 - Arsenolite -72.18 -73.56 -1.38 As2O3 - Artinite -7.12 2.48 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -38.06 -29.83 8.23 As2O5 - As2S3(am) -476.28 -521.18 -44.90 As2S3 - As_native -86.06 -98.59 -12.53 As - Brucite -5.77 11.07 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.66 -38.56 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.02 -8.50 -8.48 CaCO3 - CH4(g) -140.57 -143.43 -2.86 CH4 - Claudetite -72.22 -73.56 -1.34 As2O3 - CO2(g) -1.51 -2.98 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.86 -7.00 -2.14 MgSO4:7H2O - Gypsum -2.33 -6.91 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.27 -142.27 -1.00 H2S - Halite -8.86 -7.28 1.58 NaCl - Huntite -4.30 -34.27 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.53 -23.29 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.56 -8.59 -8.03 MgCO3 - Mirabilite -9.54 -10.66 -1.11 Na2SO4:10H2O - Nahcolite -5.08 -5.63 -0.55 NaHCO3 - Natron -10.94 -12.25 -1.31 Na2CO3:10H2O - Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -474.88 -521.18 -46.30 As2S3 - Portlandite -11.64 11.16 22.80 Ca(OH)2 - Realgar -186.65 -206.59 -19.94 AsS - Sulfur -105.89 -120.92 -15.03 S - Thenardite -10.48 -10.66 -0.18 Na2SO4 - Thermonatrite -12.38 -12.25 0.12 Na2CO3:H2O - Trona -17.08 -17.88 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 121, cumulative pore volumes 121.000000. -Beginning of advection time step 122, cumulative pore volumes 122.000000. -Beginning of advection time step 123, cumulative pore volumes 123.000000. -Beginning of advection time step 124, cumulative pore volumes 124.000000. -Beginning of advection time step 125, cumulative pore volumes 125.000000. -Beginning of advection time step 126, cumulative pore volumes 126.000000. -Beginning of advection time step 127, cumulative pore volumes 127.000000. -Beginning of advection time step 128, cumulative pore volumes 128.000000. -Beginning of advection time step 129, cumulative pore volumes 129.000000. -Beginning of advection time step 130, cumulative pore volumes 130.000000. -Beginning of advection time step 131, cumulative pore volumes 131.000000. -Beginning of advection time step 132, cumulative pore volumes 132.000000. -Beginning of advection time step 133, cumulative pore volumes 133.000000. -Beginning of advection time step 134, cumulative pore volumes 134.000000. -Beginning of advection time step 135, cumulative pore volumes 135.000000. -Beginning of advection time step 136, cumulative pore volumes 136.000000. -Beginning of advection time step 137, cumulative pore volumes 137.000000. -Beginning of advection time step 138, cumulative pore volumes 138.000000. -Beginning of advection time step 139, cumulative pore volumes 139.000000. -Beginning of advection time step 140, cumulative pore volumes 140.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 2.132e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.378e-03 Surface charge, eq - 1.275e-02 sigma, C/m**2 - 4.912e-02 psi, V - -1.912e+00 -F*psi/RT - 1.478e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 4.994e-02 0.713 4.994e-02 -1.302 - Hfo_wOH2+ 1.289e-02 0.184 1.289e-02 -1.890 - Hfo_wO- 4.431e-03 0.063 4.431e-03 -2.353 - Hfo_wOHSO4-2 1.698e-03 0.024 1.698e-03 -2.770 - Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 - Hfo_wSO4- 2.198e-04 0.003 2.198e-04 -3.658 - Hfo_wHAsO4- 1.226e-06 0.000 1.226e-06 -5.911 - Hfo_wH2AsO4 1.025e-08 0.000 1.025e-08 -7.989 - Hfo_wOCa+ 9.387e-14 0.000 9.387e-14 -13.027 - Hfo_wOMg+ 7.538e-14 0.000 7.538e-14 -13.123 - Hfo_wH2AsO3 2.291e-33 0.000 2.292e-33 -32.640 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.314e-01 6.627e-01 6.627e-01 -0.000 - MgX2 1.679e-01 3.358e-01 3.358e-01 -0.000 - NaX 1.435e-03 1.435e-03 1.435e-03 -0.000 - HX 8.602e-06 8.602e-06 8.602e-06 -0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.640e-10 1.639e-10 - C 7.115e-03 7.115e-03 - Ca 1.806e-03 1.805e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.438e-03 1.438e-03 - Na 1.658e-04 1.658e-04 - S 2.323e-04 2.323e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.048 Charge balance - pe = 13.558 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.599e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.055e-03 - Total CO2 (mol/kg) = 7.115e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.682e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 10 - Total H = 1.110125e+02 - Total O = 5.552485e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.236e-07 1.117e-07 -6.908 -6.952 -0.044 - H+ 9.795e-08 8.960e-08 -7.009 -7.048 -0.039 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.797e-37 - H3AsO3 1.781e-37 1.785e-37 -36.749 -36.748 0.001 - H2AsO3- 1.561e-39 1.410e-39 -38.807 -38.851 -0.044 - H4AsO3+ 0.000e+00 0.000e+00 -44.057 -44.101 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -46.327 -46.503 -0.176 - AsO3-3 0.000e+00 0.000e+00 -54.759 -55.155 -0.396 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.927 -309.971 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.763 -925.807 -0.044 -As(5) 1.640e-10 - HAsO4-2 8.383e-11 5.591e-11 -10.077 -10.253 -0.176 - H2AsO4- 8.012e-11 7.240e-11 -10.096 -10.140 -0.044 - AsO4-3 3.475e-15 1.397e-15 -14.459 -14.855 -0.396 - H3AsO4 1.291e-15 1.294e-15 -14.889 -14.888 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.421 -143.420 0.001 -C(4) 7.115e-03 - HCO3- 5.882e-03 5.333e-03 -2.230 -2.273 -0.043 - CO2 1.072e-03 1.075e-03 -2.970 -2.969 0.001 - CaHCO3+ 8.579e-05 7.752e-05 -4.067 -4.111 -0.044 - MgHCO3+ 6.320e-05 5.711e-05 -4.199 -4.243 -0.044 - CaCO3 5.318e-06 5.330e-06 -5.274 -5.273 0.001 - CO3-2 4.130e-06 2.792e-06 -5.384 -5.554 -0.170 - MgCO3 2.433e-06 2.438e-06 -5.614 -5.613 0.001 - NaHCO3 4.474e-07 4.484e-07 -6.349 -6.348 0.001 - NaCO3- 8.600e-09 7.772e-09 -8.065 -8.109 -0.044 -Ca 1.806e-03 - Ca+2 1.687e-03 1.140e-03 -2.773 -2.943 -0.170 - CaHCO3+ 8.579e-05 7.752e-05 -4.067 -4.111 -0.044 - CaSO4 2.733e-05 2.739e-05 -4.563 -4.562 0.001 - CaCO3 5.318e-06 5.330e-06 -5.274 -5.273 0.001 - CaOH+ 2.336e-09 2.111e-09 -8.632 -8.676 -0.044 - CaHSO4+ 1.591e-11 1.437e-11 -10.798 -10.842 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.438e-03 - Mg+2 1.346e-03 9.152e-04 -2.871 -3.038 -0.168 - MgHCO3+ 6.320e-05 5.711e-05 -4.199 -4.243 -0.044 - MgSO4 2.578e-05 2.584e-05 -4.589 -4.588 0.001 - MgCO3 2.433e-06 2.438e-06 -5.614 -5.613 0.001 - MgOH+ 4.103e-08 3.708e-08 -7.387 -7.431 -0.044 -Na 1.658e-04 - Na+ 1.653e-04 1.495e-04 -3.782 -3.825 -0.043 - NaHCO3 4.474e-07 4.484e-07 -6.349 -6.348 0.001 - NaSO4- 9.987e-08 9.025e-08 -7.001 -7.045 -0.044 - NaCO3- 8.600e-09 7.772e-09 -8.065 -8.109 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.062 -142.106 -0.044 - H2S 0.000e+00 0.000e+00 -142.213 -142.212 0.001 - S5-2 0.000e+00 0.000e+00 -144.510 -144.654 -0.144 - S4-2 0.000e+00 0.000e+00 -144.737 -144.888 -0.151 - S6-2 0.000e+00 0.000e+00 -144.802 -144.940 -0.138 - S-2 0.000e+00 0.000e+00 -147.801 -147.977 -0.176 - S3-2 0.000e+00 0.000e+00 -148.182 -148.341 -0.159 - S2-2 0.000e+00 0.000e+00 -149.422 -149.587 -0.165 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.927 -309.971 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.763 -925.807 -0.044 -S(6) 2.323e-04 - SO4-2 1.791e-04 1.204e-04 -3.747 -3.919 -0.172 - CaSO4 2.733e-05 2.739e-05 -4.563 -4.562 0.001 - MgSO4 2.578e-05 2.584e-05 -4.589 -4.588 0.001 - NaSO4- 9.987e-08 9.025e-08 -7.001 -7.045 -0.044 - HSO4- 1.161e-09 1.049e-09 -8.935 -8.979 -0.044 - CaHSO4+ 1.591e-11 1.437e-11 -10.798 -10.842 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.50 -6.86 -4.36 CaSO4 - Aragonite -0.16 -8.50 -8.34 CaCO3 - Arsenolite -72.12 -73.50 -1.38 As2O3 - Artinite -7.14 2.46 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -38.00 -29.78 8.23 As2O5 - As2S3(am) -476.06 -520.96 -44.90 As2S3 - As_native -86.03 -98.56 -12.53 As - Brucite -5.78 11.06 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.63 -38.54 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.02 -8.50 -8.48 CaCO3 - CH4(g) -140.56 -143.42 -2.86 CH4 - Claudetite -72.16 -73.50 -1.34 As2O3 - CO2(g) -1.50 -2.97 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O - Gypsum -2.28 -6.86 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.22 -142.21 -1.00 H2S - Halite -9.33 -7.74 1.58 NaCl - Huntite -4.31 -34.28 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.55 -23.31 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.56 -8.59 -8.03 MgCO3 - Mirabilite -10.46 -11.57 -1.11 Na2SO4:10H2O - Nahcolite -5.55 -6.10 -0.55 NaHCO3 - Natron -11.89 -13.21 -1.31 Na2CO3:10H2O - Nesquehonite -2.97 -8.59 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -474.66 -520.96 -46.30 As2S3 - Portlandite -11.65 11.15 22.80 Ca(OH)2 - Realgar -186.56 -206.51 -19.94 AsS - Sulfur -105.84 -120.86 -15.03 S - Thenardite -11.39 -11.57 -0.18 Na2SO4 - Thermonatrite -13.33 -13.20 0.12 Na2CO3:H2O - Trona -18.51 -19.30 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 141, cumulative pore volumes 141.000000. -Beginning of advection time step 142, cumulative pore volumes 142.000000. -Beginning of advection time step 143, cumulative pore volumes 143.000000. -Beginning of advection time step 144, cumulative pore volumes 144.000000. -Beginning of advection time step 145, cumulative pore volumes 145.000000. -Beginning of advection time step 146, cumulative pore volumes 146.000000. -Beginning of advection time step 147, cumulative pore volumes 147.000000. -Beginning of advection time step 148, cumulative pore volumes 148.000000. -Beginning of advection time step 149, cumulative pore volumes 149.000000. -Beginning of advection time step 150, cumulative pore volumes 150.000000. -Beginning of advection time step 151, cumulative pore volumes 151.000000. -Beginning of advection time step 152, cumulative pore volumes 152.000000. -Beginning of advection time step 153, cumulative pore volumes 153.000000. -Beginning of advection time step 154, cumulative pore volumes 154.000000. -Beginning of advection time step 155, cumulative pore volumes 155.000000. -Beginning of advection time step 156, cumulative pore volumes 156.000000. -Beginning of advection time step 157, cumulative pore volumes 157.000000. -Beginning of advection time step 158, cumulative pore volumes 158.000000. -Beginning of advection time step 159, cumulative pore volumes 159.000000. -Beginning of advection time step 160, cumulative pore volumes 160.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.02 -8.50 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.465e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.383e-03 Surface charge, eq - 1.278e-02 sigma, C/m**2 - 4.916e-02 psi, V - -1.914e+00 -F*psi/RT - 1.476e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 - Hfo_wOH2+ 1.292e-02 0.185 1.292e-02 -1.889 - Hfo_wO- 4.414e-03 0.063 4.415e-03 -2.355 - Hfo_wOHSO4-2 1.717e-03 0.025 1.717e-03 -2.765 - Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 - Hfo_wSO4- 2.229e-04 0.003 2.229e-04 -3.652 - Hfo_wHAsO4- 1.234e-06 0.000 1.234e-06 -5.909 - Hfo_wH2AsO4 1.034e-08 0.000 1.034e-08 -7.985 - Hfo_wOCa+ 9.423e-14 0.000 9.423e-14 -13.026 - Hfo_wOMg+ 7.486e-14 0.000 7.487e-14 -13.126 - Hfo_wH2AsO3 2.312e-33 0.000 2.313e-33 -32.636 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.327e-01 6.654e-01 6.654e-01 0.000 - MgX2 1.668e-01 3.335e-01 3.335e-01 0.000 - NaX 1.101e-03 1.101e-03 1.101e-03 0.000 - HX 8.612e-06 8.612e-06 8.612e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.645e-10 1.645e-10 - C 7.117e-03 7.116e-03 - Ca 1.825e-03 1.825e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.438e-03 1.438e-03 - Na 1.276e-04 1.276e-04 - S 2.347e-04 2.347e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.046 Charge balance - pe = 13.560 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.619e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.052e-03 - Total CO2 (mol/kg) = 7.117e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.135e-08 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110125e+02 - Total O = 5.552486e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.231e-07 1.112e-07 -6.910 -6.954 -0.044 - H+ 9.840e-08 9.000e-08 -7.007 -7.046 -0.039 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.814e-37 - H3AsO3 1.799e-37 1.802e-37 -36.745 -36.744 0.001 - H2AsO3- 1.569e-39 1.418e-39 -38.804 -38.848 -0.044 - H4AsO3+ 0.000e+00 0.000e+00 -44.051 -44.095 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -46.327 -46.503 -0.176 - AsO3-3 0.000e+00 0.000e+00 -54.761 -55.157 -0.396 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.909 -309.953 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.705 -925.749 -0.044 -As(5) 1.645e-10 - HAsO4-2 8.392e-11 5.595e-11 -10.076 -10.252 -0.176 - H2AsO4- 8.055e-11 7.279e-11 -10.094 -10.138 -0.044 - AsO4-3 3.465e-15 1.392e-15 -14.460 -14.856 -0.396 - H3AsO4 1.304e-15 1.307e-15 -14.885 -14.884 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 -C(4) 7.117e-03 - HCO3- 5.878e-03 5.330e-03 -2.231 -2.273 -0.043 - CO2 1.076e-03 1.079e-03 -2.968 -2.967 0.001 - CaHCO3+ 8.665e-05 7.829e-05 -4.062 -4.106 -0.044 - MgHCO3+ 6.315e-05 5.707e-05 -4.200 -4.244 -0.044 - CaCO3 5.347e-06 5.358e-06 -5.272 -5.271 0.001 - CO3-2 4.110e-06 2.777e-06 -5.386 -5.556 -0.170 - MgCO3 2.420e-06 2.425e-06 -5.616 -5.615 0.001 - NaHCO3 3.441e-07 3.449e-07 -6.463 -6.462 0.001 - NaCO3- 6.585e-09 5.951e-09 -8.181 -8.225 -0.044 -Ca 1.825e-03 - Ca+2 1.706e-03 1.152e-03 -2.768 -2.939 -0.171 - CaHCO3+ 8.665e-05 7.829e-05 -4.062 -4.106 -0.044 - CaSO4 2.787e-05 2.793e-05 -4.555 -4.554 0.001 - CaCO3 5.347e-06 5.358e-06 -5.272 -5.271 0.001 - CaOH+ 2.350e-09 2.123e-09 -8.629 -8.673 -0.044 - CaHSO4+ 1.630e-11 1.473e-11 -10.788 -10.832 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.438e-03 - Mg+2 1.347e-03 9.151e-04 -2.871 -3.039 -0.168 - MgHCO3+ 6.315e-05 5.707e-05 -4.200 -4.244 -0.044 - MgSO4 2.601e-05 2.607e-05 -4.585 -4.584 0.001 - MgCO3 2.420e-06 2.425e-06 -5.616 -5.615 0.001 - MgOH+ 4.085e-08 3.691e-08 -7.389 -7.433 -0.044 -Na 1.276e-04 - Na+ 1.272e-04 1.151e-04 -3.895 -3.939 -0.044 - NaHCO3 3.441e-07 3.449e-07 -6.463 -6.462 0.001 - NaSO4- 7.756e-08 7.009e-08 -7.110 -7.154 -0.044 - NaCO3- 6.585e-09 5.951e-09 -8.181 -8.225 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.056 -142.101 -0.044 - H2S 0.000e+00 0.000e+00 -142.206 -142.205 0.001 - S5-2 0.000e+00 0.000e+00 -144.506 -144.650 -0.144 - S4-2 0.000e+00 0.000e+00 -144.733 -144.884 -0.151 - S6-2 0.000e+00 0.000e+00 -144.798 -144.936 -0.138 - S-2 0.000e+00 0.000e+00 -147.797 -147.973 -0.176 - S3-2 0.000e+00 0.000e+00 -148.178 -148.337 -0.159 - S2-2 0.000e+00 0.000e+00 -149.418 -149.583 -0.165 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.909 -309.953 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.705 -925.749 -0.044 -S(6) 2.347e-04 - SO4-2 1.808e-04 1.215e-04 -3.743 -3.915 -0.172 - CaSO4 2.787e-05 2.793e-05 -4.555 -4.554 0.001 - MgSO4 2.601e-05 2.607e-05 -4.585 -4.584 0.001 - NaSO4- 7.756e-08 7.009e-08 -7.110 -7.154 -0.044 - HSO4- 1.177e-09 1.063e-09 -8.929 -8.973 -0.044 - CaHSO4+ 1.630e-11 1.473e-11 -10.788 -10.832 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.49 -6.85 -4.36 CaSO4 - Aragonite -0.16 -8.50 -8.34 CaCO3 - Arsenolite -72.11 -73.49 -1.38 As2O3 - Artinite -7.14 2.46 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -38.00 -29.77 8.23 As2O5 - As2S3(am) -476.03 -520.93 -44.90 As2S3 - As_native -86.03 -98.56 -12.53 As - Brucite -5.79 11.05 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.62 -38.53 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.02 -8.50 -8.48 CaCO3 - CH4(g) -140.56 -143.42 -2.86 CH4 - Claudetite -72.15 -73.49 -1.34 As2O3 - CO2(g) -1.50 -2.97 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.81 -6.95 -2.14 MgSO4:7H2O - Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.21 -142.20 -1.00 H2S - Halite -9.44 -7.86 1.58 NaCl - Huntite -4.31 -34.28 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.57 -23.33 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.57 -8.59 -8.03 MgCO3 - Mirabilite -10.68 -11.79 -1.11 Na2SO4:10H2O - Nahcolite -5.66 -6.21 -0.55 NaHCO3 - Natron -12.12 -13.44 -1.31 Na2CO3:10H2O - Nesquehonite -2.97 -8.60 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -474.63 -520.93 -46.30 As2S3 - Portlandite -11.65 11.15 22.80 Ca(OH)2 - Realgar -186.55 -206.50 -19.94 AsS - Sulfur -105.83 -120.85 -15.03 S - Thenardite -11.61 -11.79 -0.18 Na2SO4 - Thermonatrite -13.56 -13.43 0.12 Na2CO3:H2O - Trona -18.85 -19.65 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 161, cumulative pore volumes 161.000000. -Beginning of advection time step 162, cumulative pore volumes 162.000000. -Beginning of advection time step 163, cumulative pore volumes 163.000000. -Beginning of advection time step 164, cumulative pore volumes 164.000000. -Beginning of advection time step 165, cumulative pore volumes 165.000000. -Beginning of advection time step 166, cumulative pore volumes 166.000000. -Beginning of advection time step 167, cumulative pore volumes 167.000000. -Beginning of advection time step 168, cumulative pore volumes 168.000000. -Beginning of advection time step 169, cumulative pore volumes 169.000000. -Beginning of advection time step 170, cumulative pore volumes 170.000000. -Beginning of advection time step 171, cumulative pore volumes 171.000000. -Beginning of advection time step 172, cumulative pore volumes 172.000000. -Beginning of advection time step 173, cumulative pore volumes 173.000000. -Beginning of advection time step 174, cumulative pore volumes 174.000000. -Beginning of advection time step 175, cumulative pore volumes 175.000000. -Beginning of advection time step 176, cumulative pore volumes 176.000000. -Beginning of advection time step 177, cumulative pore volumes 177.000000. -Beginning of advection time step 178, cumulative pore volumes 178.000000. -Beginning of advection time step 179, cumulative pore volumes 179.000000. -Beginning of advection time step 180, cumulative pore volumes 180.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.206e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.384e-03 Surface charge, eq - 1.278e-02 sigma, C/m**2 - 4.916e-02 psi, V - -1.913e+00 -F*psi/RT - 1.476e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 - Hfo_wOH2+ 1.292e-02 0.185 1.293e-02 -1.889 - Hfo_wO- 4.413e-03 0.063 4.413e-03 -2.355 - Hfo_wOHSO4-2 1.719e-03 0.025 1.719e-03 -2.765 - Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 - Hfo_wSO4- 2.232e-04 0.003 2.232e-04 -3.651 - Hfo_wHAsO4- 1.235e-06 0.000 1.235e-06 -5.908 - Hfo_wH2AsO4 1.035e-08 0.000 1.035e-08 -7.985 - Hfo_wOCa+ 9.467e-14 0.000 9.468e-14 -13.024 - Hfo_wOMg+ 7.451e-14 0.000 7.452e-14 -13.128 - Hfo_wH2AsO3 2.314e-33 0.000 2.314e-33 -32.636 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.337e-01 6.675e-01 6.675e-01 -0.000 - MgX2 1.657e-01 3.315e-01 3.315e-01 -0.000 - NaX 1.062e-03 1.062e-03 1.062e-03 -0.000 - HX 8.606e-06 8.606e-06 8.606e-06 -0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.646e-10 1.646e-10 - C 7.117e-03 7.117e-03 - Ca 1.835e-03 1.834e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.432e-03 1.432e-03 - Na 1.233e-04 1.233e-04 - S 2.351e-04 2.351e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.046 Charge balance - pe = 13.560 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.623e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.053e-03 - Total CO2 (mol/kg) = 7.117e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.004e-09 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 10 - Total H = 1.110125e+02 - Total O = 5.552487e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.230e-07 1.112e-07 -6.910 -6.954 -0.044 - H+ 9.842e-08 9.002e-08 -7.007 -7.046 -0.039 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.816e-37 - H3AsO3 1.800e-37 1.804e-37 -36.745 -36.744 0.001 - H2AsO3- 1.570e-39 1.419e-39 -38.804 -38.848 -0.044 - H4AsO3+ 0.000e+00 0.000e+00 -44.050 -44.094 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -46.326 -46.502 -0.176 - AsO3-3 0.000e+00 0.000e+00 -54.761 -55.157 -0.396 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.700 -925.744 -0.044 -As(5) 1.646e-10 - HAsO4-2 8.397e-11 5.598e-11 -10.076 -10.252 -0.176 - H2AsO4- 8.061e-11 7.284e-11 -10.094 -10.138 -0.044 - AsO4-3 3.467e-15 1.392e-15 -14.460 -14.856 -0.396 - H3AsO4 1.305e-15 1.308e-15 -14.884 -14.883 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 -C(4) 7.117e-03 - HCO3- 5.878e-03 5.330e-03 -2.231 -2.273 -0.043 - CO2 1.077e-03 1.079e-03 -2.968 -2.967 0.001 - CaHCO3+ 8.707e-05 7.868e-05 -4.060 -4.104 -0.044 - MgHCO3+ 6.287e-05 5.681e-05 -4.202 -4.246 -0.044 - CaCO3 5.372e-06 5.384e-06 -5.270 -5.269 0.001 - CO3-2 4.109e-06 2.777e-06 -5.386 -5.556 -0.170 - MgCO3 2.408e-06 2.414e-06 -5.618 -5.617 0.001 - NaHCO3 3.323e-07 3.331e-07 -6.478 -6.477 0.001 - NaCO3- 6.359e-09 5.746e-09 -8.197 -8.241 -0.044 -Ca 1.835e-03 - Ca+2 1.714e-03 1.157e-03 -2.766 -2.937 -0.171 - CaHCO3+ 8.707e-05 7.868e-05 -4.060 -4.104 -0.044 - CaSO4 2.804e-05 2.810e-05 -4.552 -4.551 0.001 - CaCO3 5.372e-06 5.384e-06 -5.270 -5.269 0.001 - CaOH+ 2.361e-09 2.133e-09 -8.627 -8.671 -0.044 - CaHSO4+ 1.640e-11 1.482e-11 -10.785 -10.829 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.432e-03 - Mg+2 1.341e-03 9.110e-04 -2.873 -3.040 -0.168 - MgHCO3+ 6.287e-05 5.681e-05 -4.202 -4.246 -0.044 - MgSO4 2.593e-05 2.599e-05 -4.586 -4.585 0.001 - MgCO3 2.408e-06 2.414e-06 -5.618 -5.617 0.001 - MgOH+ 4.065e-08 3.673e-08 -7.391 -7.435 -0.044 -Na 1.233e-04 - Na+ 1.228e-04 1.111e-04 -3.911 -3.954 -0.044 - NaHCO3 3.323e-07 3.331e-07 -6.478 -6.477 0.001 - NaSO4- 7.500e-08 6.777e-08 -7.125 -7.169 -0.044 - NaCO3- 6.359e-09 5.746e-09 -8.197 -8.241 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.056 -142.100 -0.044 - H2S 0.000e+00 0.000e+00 -142.205 -142.204 0.001 - S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 - S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 - S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 - S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 - S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 - S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.700 -925.744 -0.044 -S(6) 2.351e-04 - SO4-2 1.810e-04 1.217e-04 -3.742 -3.915 -0.173 - CaSO4 2.804e-05 2.810e-05 -4.552 -4.551 0.001 - MgSO4 2.593e-05 2.599e-05 -4.586 -4.585 0.001 - NaSO4- 7.500e-08 6.777e-08 -7.125 -7.169 -0.044 - HSO4- 1.179e-09 1.065e-09 -8.929 -8.973 -0.044 - CaHSO4+ 1.640e-11 1.482e-11 -10.785 -10.829 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.49 -6.85 -4.36 CaSO4 - Aragonite -0.16 -8.49 -8.34 CaCO3 - Arsenolite -72.11 -73.49 -1.38 As2O3 - Artinite -7.15 2.45 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -37.99 -29.77 8.23 As2O5 - As2S3(am) -476.02 -520.92 -44.90 As2S3 - As_native -86.03 -98.56 -12.53 As - Brucite -5.79 11.05 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.62 -38.52 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.01 -8.49 -8.48 CaCO3 - CH4(g) -140.56 -143.42 -2.86 CH4 - Claudetite -72.15 -73.49 -1.34 As2O3 - CO2(g) -1.50 -2.97 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O - Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.21 -142.20 -1.00 H2S - Halite -9.45 -7.87 1.58 NaCl - Huntite -4.32 -34.28 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.58 -23.34 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.57 -8.60 -8.03 MgCO3 - Mirabilite -10.71 -11.82 -1.11 Na2SO4:10H2O - Nahcolite -5.68 -6.23 -0.55 NaHCO3 - Natron -12.15 -13.47 -1.31 Na2CO3:10H2O - Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -474.62 -520.92 -46.30 As2S3 - Portlandite -11.65 11.15 22.80 Ca(OH)2 - Realgar -186.55 -206.49 -19.94 AsS - Sulfur -105.83 -120.85 -15.03 S - Thenardite -11.64 -11.82 -0.18 Na2SO4 - Thermonatrite -13.59 -13.46 0.12 Na2CO3:H2O - Trona -18.90 -19.69 -0.80 NaHCO3:Na2CO3:2H2O - -Beginning of advection time step 181, cumulative pore volumes 181.000000. -Beginning of advection time step 182, cumulative pore volumes 182.000000. -Beginning of advection time step 183, cumulative pore volumes 183.000000. -Beginning of advection time step 184, cumulative pore volumes 184.000000. -Beginning of advection time step 185, cumulative pore volumes 185.000000. -Beginning of advection time step 186, cumulative pore volumes 186.000000. -Beginning of advection time step 187, cumulative pore volumes 187.000000. -Beginning of advection time step 188, cumulative pore volumes 188.000000. -Beginning of advection time step 189, cumulative pore volumes 189.000000. -Beginning of advection time step 190, cumulative pore volumes 190.000000. -Beginning of advection time step 191, cumulative pore volumes 191.000000. -Beginning of advection time step 192, cumulative pore volumes 192.000000. -Beginning of advection time step 193, cumulative pore volumes 193.000000. -Beginning of advection time step 194, cumulative pore volumes 194.000000. -Beginning of advection time step 195, cumulative pore volumes 195.000000. -Beginning of advection time step 196, cumulative pore volumes 196.000000. -Beginning of advection time step 197, cumulative pore volumes 197.000000. -Beginning of advection time step 198, cumulative pore volumes 198.000000. -Beginning of advection time step 199, cumulative pore volumes 199.000000. -Beginning of advection time step 200, cumulative pore volumes 200.000000. - -Cell 1. - -Using solution 1. Solution after simulation 4. -Using exchange 1. Exchange assemblage after simulation 5. -Using surface 1. Surface assemblage after simulation 5. -Using pure phase assemblage 1. Pure-phase assemblage after simulation 5. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite -0.01 -8.49 -8.48 0.000e+00 0.000e+00 - Dolomite 0.00 -17.09 -17.09 1.565e+00 1.565e+00 1.046e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.383e-03 Surface charge, eq - 1.278e-02 sigma, C/m**2 - 4.915e-02 psi, V - -1.913e+00 -F*psi/RT - 1.476e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 1.800e+04 m**2 for 3.000e+01 g - - -Hfo_w - 7.000e-02 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 4.990e-02 0.713 4.990e-02 -1.302 - Hfo_wOH2+ 1.292e-02 0.185 1.292e-02 -1.889 - Hfo_wO- 4.413e-03 0.063 4.414e-03 -2.355 - Hfo_wOHSO4-2 1.719e-03 0.025 1.719e-03 -2.765 - Hfo_wOHAsO4-3 8.218e-04 0.012 8.218e-04 -3.085 - Hfo_wSO4- 2.231e-04 0.003 2.232e-04 -3.651 - Hfo_wHAsO4- 1.234e-06 0.000 1.234e-06 -5.909 - Hfo_wH2AsO4 1.035e-08 0.000 1.035e-08 -7.985 - Hfo_wOCa+ 9.507e-14 0.000 9.508e-14 -13.022 - Hfo_wOMg+ 7.422e-14 0.000 7.422e-14 -13.129 - Hfo_wH2AsO3 2.314e-33 0.000 2.314e-33 -32.636 - ------------------------------Exchange composition------------------------------ - -X 1.000e+00 mol - - Equiv- Equivalent Log - Species Moles alents Fraction Gamma - - CaX2 3.346e-01 6.693e-01 6.693e-01 0.000 - MgX2 1.648e-01 3.297e-01 3.297e-01 0.000 - NaX 1.058e-03 1.058e-03 1.058e-03 0.000 - HX 8.599e-06 8.599e-06 8.599e-06 0.000 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - As 1.646e-10 1.646e-10 - C 7.117e-03 7.117e-03 - Ca 1.841e-03 1.841e-03 - Cl 1.337e-04 1.337e-04 - Mg 1.426e-03 1.426e-03 - Na 1.228e-04 1.228e-04 - S 2.351e-04 2.351e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.046 Charge balance - pe = 13.559 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.624e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.053e-03 - Total CO2 (mol/kg) = 7.117e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 1.225e-08 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 10 - Total H = 1.110125e+02 - Total O = 5.552487e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.231e-07 1.112e-07 -6.910 -6.954 -0.044 - H+ 9.839e-08 9.000e-08 -7.007 -7.046 -0.039 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -As(3) 1.815e-37 - H3AsO3 1.800e-37 1.804e-37 -36.745 -36.744 0.001 - H2AsO3- 1.570e-39 1.419e-39 -38.804 -38.848 -0.044 - H4AsO3+ 0.000e+00 0.000e+00 -44.051 -44.095 -0.044 - HAsO3-2 0.000e+00 0.000e+00 -46.326 -46.502 -0.176 - AsO3-3 0.000e+00 0.000e+00 -54.760 -55.157 -0.396 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.701 -925.745 -0.044 -As(5) 1.646e-10 - HAsO4-2 8.400e-11 5.600e-11 -10.076 -10.252 -0.176 - H2AsO4- 8.061e-11 7.284e-11 -10.094 -10.138 -0.044 - AsO4-3 3.469e-15 1.393e-15 -14.460 -14.856 -0.396 - H3AsO4 1.305e-15 1.308e-15 -14.884 -14.883 0.001 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -143.420 -143.419 0.001 -C(4) 7.117e-03 - HCO3- 5.879e-03 5.330e-03 -2.231 -2.273 -0.043 - CO2 1.076e-03 1.079e-03 -2.968 -2.967 0.001 - CaHCO3+ 8.741e-05 7.898e-05 -4.058 -4.102 -0.044 - MgHCO3+ 6.260e-05 5.656e-05 -4.203 -4.247 -0.044 - CaCO3 5.394e-06 5.406e-06 -5.268 -5.267 0.001 - CO3-2 4.111e-06 2.778e-06 -5.386 -5.556 -0.170 - MgCO3 2.398e-06 2.404e-06 -5.620 -5.619 0.001 - NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 - NaCO3- 6.335e-09 5.724e-09 -8.198 -8.242 -0.044 -Ca 1.841e-03 - Ca+2 1.721e-03 1.162e-03 -2.764 -2.935 -0.171 - CaHCO3+ 8.741e-05 7.898e-05 -4.058 -4.102 -0.044 - CaSO4 2.815e-05 2.821e-05 -4.551 -4.550 0.001 - CaCO3 5.394e-06 5.406e-06 -5.268 -5.267 0.001 - CaOH+ 2.371e-09 2.142e-09 -8.625 -8.669 -0.044 - CaHSO4+ 1.646e-11 1.487e-11 -10.784 -10.828 -0.044 -Cl 1.337e-04 - Cl- 1.337e-04 1.206e-04 -3.874 -3.919 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.361 -44.361 0.001 -Mg 1.426e-03 - Mg+2 1.335e-03 9.069e-04 -2.875 -3.042 -0.168 - MgHCO3+ 6.260e-05 5.656e-05 -4.203 -4.247 -0.044 - MgSO4 2.582e-05 2.587e-05 -4.588 -4.587 0.001 - MgCO3 2.398e-06 2.404e-06 -5.620 -5.619 0.001 - MgOH+ 4.049e-08 3.658e-08 -7.393 -7.437 -0.044 -Na 1.228e-04 - Na+ 1.224e-04 1.107e-04 -3.912 -3.956 -0.044 - NaHCO3 3.310e-07 3.317e-07 -6.480 -6.479 0.001 - NaSO4- 7.471e-08 6.751e-08 -7.127 -7.171 -0.044 - NaCO3- 6.335e-09 5.724e-09 -8.198 -8.242 -0.044 -O(0) 4.375e-04 - O2 2.187e-04 2.192e-04 -3.660 -3.659 0.001 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -142.056 -142.100 -0.044 - H2S 0.000e+00 0.000e+00 -142.205 -142.204 0.001 - S5-2 0.000e+00 0.000e+00 -144.505 -144.649 -0.144 - S4-2 0.000e+00 0.000e+00 -144.732 -144.883 -0.151 - S6-2 0.000e+00 0.000e+00 -144.797 -144.935 -0.138 - S-2 0.000e+00 0.000e+00 -147.796 -147.972 -0.176 - S3-2 0.000e+00 0.000e+00 -148.177 -148.336 -0.159 - S2-2 0.000e+00 0.000e+00 -149.417 -149.582 -0.165 - AsS(OH)(HS)- 0.000e+00 0.000e+00 -309.907 -309.951 -0.044 - As3S4(HS)2- 0.000e+00 0.000e+00 -925.701 -925.745 -0.044 -S(6) 2.351e-04 - SO4-2 1.811e-04 1.217e-04 -3.742 -3.915 -0.173 - CaSO4 2.815e-05 2.821e-05 -4.551 -4.550 0.001 - MgSO4 2.582e-05 2.587e-05 -4.588 -4.587 0.001 - NaSO4- 7.471e-08 6.751e-08 -7.127 -7.171 -0.044 - HSO4- 1.178e-09 1.065e-09 -8.929 -8.973 -0.044 - CaHSO4+ 1.646e-11 1.487e-11 -10.784 -10.828 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.49 -6.85 -4.36 CaSO4 - Aragonite -0.16 -8.49 -8.34 CaCO3 - Arsenolite -72.11 -73.49 -1.38 As2O3 - Artinite -7.15 2.45 9.60 MgCO3:Mg(OH)2:3H2O - As2O5(cr) -37.99 -29.77 8.23 As2O5 - As2S3(am) -476.02 -520.92 -44.90 As2S3 - As_native -86.03 -98.56 -12.53 As - Brucite -5.79 11.05 16.84 Mg(OH)2 - Ca3(AsO4)2:4w -19.61 -38.52 -18.91 Ca3(AsO4)2:4H2O - Calcite -0.01 -8.49 -8.48 CaCO3 - CH4(g) -140.56 -143.42 -2.86 CH4 - Claudetite -72.15 -73.49 -1.34 As2O3 - CO2(g) -1.50 -2.97 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Dolomite(d) -0.55 -17.09 -16.54 CaMg(CO3)2 - Epsomite -4.82 -6.96 -2.14 MgSO4:7H2O - Gypsum -2.27 -6.85 -4.58 CaSO4:2H2O - H2(g) -41.21 -44.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -141.21 -142.20 -1.00 H2S - Halite -9.46 -7.87 1.58 NaCl - Huntite -4.32 -34.29 -29.97 CaMg3(CO3)4 - Hydromagnesite -14.58 -23.35 -8.76 Mg5(CO3)4(OH)2:4H2O - Magnesite -0.57 -8.60 -8.03 MgCO3 - Mirabilite -10.71 -11.83 -1.11 Na2SO4:10H2O - Nahcolite -5.68 -6.23 -0.55 NaHCO3 - Natron -12.16 -13.47 -1.31 Na2CO3:10H2O - Nesquehonite -2.98 -8.60 -5.62 MgCO3:3H2O - O2(g) -0.70 -3.66 -2.96 O2 - Orpiment -474.62 -520.92 -46.30 As2S3 - Portlandite -11.64 11.16 22.80 Ca(OH)2 - Realgar -186.55 -206.49 -19.94 AsS - Sulfur -105.83 -120.85 -15.03 S - Thenardite -11.65 -11.83 -0.18 Na2SO4 - Thermonatrite -13.59 -13.47 0.12 Na2CO3:H2O - Trona -18.90 -19.70 -0.80 NaHCO3:Na2CO3:2H2O - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 6. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex14.sel b/Sun/examples/ex14.sel deleted file mode 100644 index 48a4e9ba..00000000 --- a/Sun/examples/ex14.sel +++ /dev/null @@ -1,202 +0,0 @@ - step m_Ca m_Mg m_Na umol_As pH - 1 4.6428e-01 1.6167e-01 5.4020e+00 5.0000e-02 5.3496e+00 - 1 5.2071e-04 3.6797e-04 1.0345e-01 2.9703e-04 7.0358e+00 - 2 4.3418e-05 3.0073e-05 2.7681e-02 1.4274e-02 8.4251e+00 - 3 1.6723e-05 1.0553e-05 1.5102e-02 1.7369e-01 9.0861e+00 - 4 1.3810e-05 8.4300e-06 1.2580e-02 3.4749e-01 9.2687e+00 - 5 1.3241e-05 8.0170e-06 1.1705e-02 4.2057e-01 9.3189e+00 - 6 1.3253e-05 8.0279e-06 1.1293e-02 4.3148e-01 9.3249e+00 - 7 1.3481e-05 8.1962e-06 1.1055e-02 4.1548e-01 9.3142e+00 - 8 1.3805e-05 8.4346e-06 1.0889e-02 3.9004e-01 9.2967e+00 - 9 1.4178e-05 8.7091e-06 1.0758e-02 3.6247e-01 9.2767e+00 - 10 1.4581e-05 9.0053e-06 1.0645e-02 3.3557e-01 9.2558e+00 - 11 1.5006e-05 9.3176e-06 1.0542e-02 3.1029e-01 9.2348e+00 - 12 1.5449e-05 9.6438e-06 1.0447e-02 2.8686e-01 9.2138e+00 - 13 1.5911e-05 9.9834e-06 1.0358e-02 2.6525e-01 9.1929e+00 - 14 1.6392e-05 1.0337e-05 1.0274e-02 2.4534e-01 9.1722e+00 - 15 1.6892e-05 1.0704e-05 1.0195e-02 2.2698e-01 9.1517e+00 - 16 1.7412e-05 1.1087e-05 1.0119e-02 2.1004e-01 9.1314e+00 - 17 1.7954e-05 1.1485e-05 1.0047e-02 1.9440e-01 9.1111e+00 - 18 1.8519e-05 1.1901e-05 9.9787e-03 1.7994e-01 9.0910e+00 - 19 1.9109e-05 1.2335e-05 9.9131e-03 1.6656e-01 9.0710e+00 - 20 1.9725e-05 1.2787e-05 9.8504e-03 1.5418e-01 9.0510e+00 - 21 2.0368e-05 1.3260e-05 9.7904e-03 1.4270e-01 9.0311e+00 - 22 2.1041e-05 1.3755e-05 9.7328e-03 1.3206e-01 9.0112e+00 - 23 2.1745e-05 1.4273e-05 9.6775e-03 1.2220e-01 8.9913e+00 - 24 2.2482e-05 1.4815e-05 9.6243e-03 1.1304e-01 8.9714e+00 - 25 2.3254e-05 1.5383e-05 9.5731e-03 1.0454e-01 8.9515e+00 - 26 2.4064e-05 1.5978e-05 9.5238e-03 9.6657e-02 8.9316e+00 - 27 2.4914e-05 1.6603e-05 9.4761e-03 8.9334e-02 8.9116e+00 - 28 2.5807e-05 1.7260e-05 9.4301e-03 8.2534e-02 8.8916e+00 - 29 2.6745e-05 1.7950e-05 9.3855e-03 7.6219e-02 8.8715e+00 - 30 2.7732e-05 1.8675e-05 9.3423e-03 7.0356e-02 8.8514e+00 - 31 2.8770e-05 1.9439e-05 9.3004e-03 6.4912e-02 8.8312e+00 - 32 2.9863e-05 2.0243e-05 9.2597e-03 5.9857e-02 8.8109e+00 - 33 3.1015e-05 2.1090e-05 9.2200e-03 5.5166e-02 8.7905e+00 - 34 3.2230e-05 2.1983e-05 9.1814e-03 5.0812e-02 8.7699e+00 - 35 3.3513e-05 2.2926e-05 9.1436e-03 4.6773e-02 8.7493e+00 - 36 3.4867e-05 2.3922e-05 9.1067e-03 4.3028e-02 8.7285e+00 - 37 3.6299e-05 2.4975e-05 9.0705e-03 3.9555e-02 8.7076e+00 - 38 3.7813e-05 2.6089e-05 9.0350e-03 3.6337e-02 8.6865e+00 - 39 3.9416e-05 2.7267e-05 9.0000e-03 3.3356e-02 8.6653e+00 - 40 4.1113e-05 2.8516e-05 8.9656e-03 3.0597e-02 8.6439e+00 - 41 4.2913e-05 2.9840e-05 8.9315e-03 2.8043e-02 8.6224e+00 - 42 4.4823e-05 3.1244e-05 8.8978e-03 2.5682e-02 8.6006e+00 - 43 4.6851e-05 3.2736e-05 8.8643e-03 2.3500e-02 8.5787e+00 - 44 4.9006e-05 3.4321e-05 8.8310e-03 2.1485e-02 8.5565e+00 - 45 5.1298e-05 3.6006e-05 8.7977e-03 1.9626e-02 8.5342e+00 - 46 5.3738e-05 3.7800e-05 8.7644e-03 1.7911e-02 8.5116e+00 - 47 5.6337e-05 3.9712e-05 8.7309e-03 1.6331e-02 8.4889e+00 - 48 5.9107e-05 4.1749e-05 8.6973e-03 1.4877e-02 8.4658e+00 - 49 6.2064e-05 4.3924e-05 8.6633e-03 1.3539e-02 8.4426e+00 - 50 6.5221e-05 4.6246e-05 8.6288e-03 1.2309e-02 8.4191e+00 - 51 6.8596e-05 4.8728e-05 8.5938e-03 1.1181e-02 8.3954e+00 - 52 7.2206e-05 5.1383e-05 8.5581e-03 1.0146e-02 8.3714e+00 - 53 7.6071e-05 5.4225e-05 8.5216e-03 9.1972e-03 8.3471e+00 - 54 8.0212e-05 5.7271e-05 8.4840e-03 8.3294e-03 8.3226e+00 - 55 8.4653e-05 6.0537e-05 8.4454e-03 7.5361e-03 8.2978e+00 - 56 8.9419e-05 6.4042e-05 8.4055e-03 6.8118e-03 8.2727e+00 - 57 9.4538e-05 6.7807e-05 8.3641e-03 6.1514e-03 8.2473e+00 - 58 1.0004e-04 7.1853e-05 8.3211e-03 5.5498e-03 8.2217e+00 - 59 1.0596e-04 7.6206e-05 8.2762e-03 5.0027e-03 8.1958e+00 - 60 1.1233e-04 8.0892e-05 8.2293e-03 4.5057e-03 8.1696e+00 - 61 1.1919e-04 8.5939e-05 8.1800e-03 4.0548e-03 8.1431e+00 - 62 1.2659e-04 9.1378e-05 8.1283e-03 3.6464e-03 8.1164e+00 - 63 1.3456e-04 9.7244e-05 8.0737e-03 3.2769e-03 8.0893e+00 - 64 1.4317e-04 1.0357e-04 8.0161e-03 2.9432e-03 8.0621e+00 - 65 1.5246e-04 1.1040e-04 7.9550e-03 2.6421e-03 8.0345e+00 - 66 1.6249e-04 1.1778e-04 7.8904e-03 2.3710e-03 8.0067e+00 - 67 1.7301e-04 1.2608e-04 7.8205e-03 2.1257e-03 7.9786e+00 - 68 1.8432e-04 1.3516e-04 7.7465e-03 1.9049e-03 7.9501e+00 - 69 1.9654e-04 1.4497e-04 7.6681e-03 1.7071e-03 7.9214e+00 - 70 2.0974e-04 1.5559e-04 7.5847e-03 1.5302e-03 7.8925e+00 - 71 2.2397e-04 1.6707e-04 7.4960e-03 1.3724e-03 7.8636e+00 - 72 2.3933e-04 1.7947e-04 7.4015e-03 1.2317e-03 7.8345e+00 - 73 2.5587e-04 1.9285e-04 7.3009e-03 1.1064e-03 7.8054e+00 - 74 2.7370e-04 2.0729e-04 7.1938e-03 9.9507e-04 7.7763e+00 - 75 2.9288e-04 2.2286e-04 7.0799e-03 8.9618e-04 7.7472e+00 - 76 3.1349e-04 2.3961e-04 6.9590e-03 8.0843e-04 7.7182e+00 - 77 3.3561e-04 2.5763e-04 6.8306e-03 7.3066e-04 7.6893e+00 - 78 3.5933e-04 2.7696e-04 6.6948e-03 6.6179e-04 7.6606e+00 - 79 3.8469e-04 2.9767e-04 6.5512e-03 6.0086e-04 7.6321e+00 - 80 4.1177e-04 3.1980e-04 6.3998e-03 5.4698e-04 7.6039e+00 - 81 4.4060e-04 3.4340e-04 6.2406e-03 4.9938e-04 7.5760e+00 - 82 4.7122e-04 3.6849e-04 6.0737e-03 4.5735e-04 7.5485e+00 - 83 5.0365e-04 3.9509e-04 5.8993e-03 4.2027e-04 7.5215e+00 - 84 5.3788e-04 4.2320e-04 5.7176e-03 3.8756e-04 7.4950e+00 - 85 5.7386e-04 4.5277e-04 5.5290e-03 3.5874e-04 7.4691e+00 - 86 6.1156e-04 4.8377e-04 5.3342e-03 3.3335e-04 7.4438e+00 - 87 6.5087e-04 5.1613e-04 5.1337e-03 3.1101e-04 7.4193e+00 - 88 6.9168e-04 5.4973e-04 4.9284e-03 2.9135e-04 7.3955e+00 - 89 7.3384e-04 5.8447e-04 4.7190e-03 2.7407e-04 7.3726e+00 - 90 7.7716e-04 6.2017e-04 4.5066e-03 2.5890e-04 7.3505e+00 - 91 8.2146e-04 6.5669e-04 4.2923e-03 2.4559e-04 7.3293e+00 - 92 8.6649e-04 6.9381e-04 4.0771e-03 2.3392e-04 7.3090e+00 - 93 9.1201e-04 7.3133e-04 3.8623e-03 2.2372e-04 7.2897e+00 - 94 9.5775e-04 7.6903e-04 3.6490e-03 2.1480e-04 7.2714e+00 - 95 1.0035e-03 8.0669e-04 3.4384e-03 2.0702e-04 7.2541e+00 - 96 1.0489e-03 8.4407e-04 3.2315e-03 2.0024e-04 7.2377e+00 - 97 1.0937e-03 8.8096e-04 3.0295e-03 1.9436e-04 7.2223e+00 - 98 1.1377e-03 9.1715e-04 2.8333e-03 1.8926e-04 7.2079e+00 - 99 1.1807e-03 9.5246e-04 2.6436e-03 1.8485e-04 7.1945e+00 - 100 1.2224e-03 9.8670e-04 2.4613e-03 1.8105e-04 7.1819e+00 - 101 1.2628e-03 1.0197e-03 2.2869e-03 1.7780e-04 7.1703e+00 - 102 1.3015e-03 1.0514e-03 2.1208e-03 1.7501e-04 7.1595e+00 - 103 1.3386e-03 1.0817e-03 1.9634e-03 1.7264e-04 7.1495e+00 - 104 1.3740e-03 1.1105e-03 1.8148e-03 1.7063e-04 7.1403e+00 - 105 1.4074e-03 1.1377e-03 1.6752e-03 1.6893e-04 7.1318e+00 - 106 1.4391e-03 1.1633e-03 1.5444e-03 1.6752e-04 7.1239e+00 - 107 1.4689e-03 1.1874e-03 1.4225e-03 1.6634e-04 7.1168e+00 - 108 1.4968e-03 1.2099e-03 1.3090e-03 1.6537e-04 7.1102e+00 - 109 1.5229e-03 1.2309e-03 1.2038e-03 1.6458e-04 7.1042e+00 - 110 1.5472e-03 1.2503e-03 1.1066e-03 1.6394e-04 7.0987e+00 - 111 1.5699e-03 1.2683e-03 1.0170e-03 1.6344e-04 7.0937e+00 - 112 1.5909e-03 1.2849e-03 9.3458e-04 1.6305e-04 7.0891e+00 - 113 1.6103e-03 1.3002e-03 8.5895e-04 1.6275e-04 7.0850e+00 - 114 1.6282e-03 1.3143e-03 7.8970e-04 1.6254e-04 7.0812e+00 - 115 1.6448e-03 1.3271e-03 7.2642e-04 1.6239e-04 7.0777e+00 - 116 1.6600e-03 1.3389e-03 6.6867e-04 1.6229e-04 7.0746e+00 - 117 1.6740e-03 1.3496e-03 6.1608e-04 1.6225e-04 7.0718e+00 - 118 1.6868e-03 1.3594e-03 5.6824e-04 1.6224e-04 7.0692e+00 - 119 1.6986e-03 1.3682e-03 5.2478e-04 1.6226e-04 7.0669e+00 - 120 1.7093e-03 1.3763e-03 4.8535e-04 1.6230e-04 7.0648e+00 - 121 1.7192e-03 1.3836e-03 4.4962e-04 1.6236e-04 7.0629e+00 - 122 1.7282e-03 1.3901e-03 4.1726e-04 1.6244e-04 7.0612e+00 - 123 1.7365e-03 1.3960e-03 3.8800e-04 1.6252e-04 7.0596e+00 - 124 1.7441e-03 1.4014e-03 3.6155e-04 1.6262e-04 7.0582e+00 - 125 1.7509e-03 1.4062e-03 3.3765e-04 1.6272e-04 7.0569e+00 - 126 1.7572e-03 1.4105e-03 3.1609e-04 1.6282e-04 7.0558e+00 - 127 1.7630e-03 1.4143e-03 2.9664e-04 1.6292e-04 7.0547e+00 - 128 1.7683e-03 1.4178e-03 2.7910e-04 1.6302e-04 7.0538e+00 - 129 1.7731e-03 1.4208e-03 2.6330e-04 1.6312e-04 7.0529e+00 - 130 1.7774e-03 1.4236e-03 2.4907e-04 1.6321e-04 7.0522e+00 - 131 1.7815e-03 1.4260e-03 2.3626e-04 1.6331e-04 7.0515e+00 - 132 1.7851e-03 1.4281e-03 2.2472e-04 1.6339e-04 7.0509e+00 - 133 1.7885e-03 1.4300e-03 2.1435e-04 1.6348e-04 7.0503e+00 - 134 1.7916e-03 1.4317e-03 2.0502e-04 1.6356e-04 7.0498e+00 - 135 1.7944e-03 1.4331e-03 1.9662e-04 1.6364e-04 7.0494e+00 - 136 1.7970e-03 1.4344e-03 1.8908e-04 1.6371e-04 7.0490e+00 - 137 1.7994e-03 1.4355e-03 1.8230e-04 1.6377e-04 7.0486e+00 - 138 1.8016e-03 1.4364e-03 1.7621e-04 1.6384e-04 7.0483e+00 - 139 1.8036e-03 1.4372e-03 1.7073e-04 1.6390e-04 7.0480e+00 - 140 1.8055e-03 1.4379e-03 1.6582e-04 1.6395e-04 7.0477e+00 - 141 1.8072e-03 1.4385e-03 1.6140e-04 1.6400e-04 7.0475e+00 - 142 1.8088e-03 1.4390e-03 1.5743e-04 1.6405e-04 7.0473e+00 - 143 1.8103e-03 1.4394e-03 1.5387e-04 1.6409e-04 7.0471e+00 - 144 1.8117e-03 1.4397e-03 1.5068e-04 1.6413e-04 7.0469e+00 - 145 1.8130e-03 1.4399e-03 1.4780e-04 1.6417e-04 7.0467e+00 - 146 1.8142e-03 1.4401e-03 1.4523e-04 1.6421e-04 7.0466e+00 - 147 1.8153e-03 1.4402e-03 1.4291e-04 1.6424e-04 7.0465e+00 - 148 1.8164e-03 1.4402e-03 1.4084e-04 1.6427e-04 7.0464e+00 - 149 1.8174e-03 1.4402e-03 1.3897e-04 1.6429e-04 7.0463e+00 - 150 1.8183e-03 1.4402e-03 1.3730e-04 1.6432e-04 7.0462e+00 - 151 1.8192e-03 1.4401e-03 1.3580e-04 1.6434e-04 7.0461e+00 - 152 1.8200e-03 1.4400e-03 1.3445e-04 1.6436e-04 7.0461e+00 - 153 1.8208e-03 1.4399e-03 1.3325e-04 1.6438e-04 7.0460e+00 - 154 1.8216e-03 1.4397e-03 1.3216e-04 1.6440e-04 7.0459e+00 - 155 1.8223e-03 1.4396e-03 1.3119e-04 1.6441e-04 7.0459e+00 - 156 1.8230e-03 1.4394e-03 1.3032e-04 1.6443e-04 7.0459e+00 - 157 1.8236e-03 1.4391e-03 1.2953e-04 1.6444e-04 7.0458e+00 - 158 1.8243e-03 1.4389e-03 1.2883e-04 1.6446e-04 7.0458e+00 - 159 1.8249e-03 1.4386e-03 1.2820e-04 1.6447e-04 7.0458e+00 - 160 1.8255e-03 1.4384e-03 1.2763e-04 1.6448e-04 7.0457e+00 - 161 1.8260e-03 1.4381e-03 1.2713e-04 1.6449e-04 7.0457e+00 - 162 1.8266e-03 1.4378e-03 1.2667e-04 1.6450e-04 7.0457e+00 - 163 1.8271e-03 1.4375e-03 1.2626e-04 1.6451e-04 7.0457e+00 - 164 1.8276e-03 1.4372e-03 1.2590e-04 1.6451e-04 7.0457e+00 - 165 1.8281e-03 1.4369e-03 1.2557e-04 1.6452e-04 7.0457e+00 - 166 1.8286e-03 1.4366e-03 1.2527e-04 1.6453e-04 7.0457e+00 - 167 1.8291e-03 1.4363e-03 1.2501e-04 1.6453e-04 7.0456e+00 - 168 1.8296e-03 1.4360e-03 1.2477e-04 1.6454e-04 7.0456e+00 - 169 1.8300e-03 1.4356e-03 1.2456e-04 1.6454e-04 7.0456e+00 - 170 1.8305e-03 1.4353e-03 1.2437e-04 1.6455e-04 7.0456e+00 - 171 1.8309e-03 1.4350e-03 1.2420e-04 1.6455e-04 7.0456e+00 - 172 1.8313e-03 1.4347e-03 1.2404e-04 1.6456e-04 7.0456e+00 - 173 1.8318e-03 1.4343e-03 1.2390e-04 1.6456e-04 7.0456e+00 - 174 1.8322e-03 1.4340e-03 1.2378e-04 1.6456e-04 7.0456e+00 - 175 1.8326e-03 1.4337e-03 1.2367e-04 1.6457e-04 7.0456e+00 - 176 1.8330e-03 1.4333e-03 1.2357e-04 1.6457e-04 7.0456e+00 - 177 1.8334e-03 1.4330e-03 1.2348e-04 1.6457e-04 7.0456e+00 - 178 1.8338e-03 1.4327e-03 1.2340e-04 1.6458e-04 7.0456e+00 - 179 1.8342e-03 1.4323e-03 1.2333e-04 1.6458e-04 7.0457e+00 - 180 1.8346e-03 1.4320e-03 1.2326e-04 1.6458e-04 7.0457e+00 - 181 1.8349e-03 1.4317e-03 1.2321e-04 1.6458e-04 7.0457e+00 - 182 1.8353e-03 1.4313e-03 1.2315e-04 1.6459e-04 7.0457e+00 - 183 1.8357e-03 1.4310e-03 1.2311e-04 1.6459e-04 7.0457e+00 - 184 1.8360e-03 1.4307e-03 1.2306e-04 1.6459e-04 7.0457e+00 - 185 1.8364e-03 1.4304e-03 1.2303e-04 1.6459e-04 7.0457e+00 - 186 1.8368e-03 1.4300e-03 1.2299e-04 1.6460e-04 7.0457e+00 - 187 1.8371e-03 1.4297e-03 1.2296e-04 1.6460e-04 7.0457e+00 - 188 1.8375e-03 1.4294e-03 1.2294e-04 1.6460e-04 7.0457e+00 - 189 1.8378e-03 1.4291e-03 1.2291e-04 1.6460e-04 7.0457e+00 - 190 1.8382e-03 1.4287e-03 1.2289e-04 1.6460e-04 7.0457e+00 - 191 1.8385e-03 1.4284e-03 1.2287e-04 1.6460e-04 7.0457e+00 - 192 1.8388e-03 1.4281e-03 1.2285e-04 1.6461e-04 7.0457e+00 - 193 1.8392e-03 1.4278e-03 1.2284e-04 1.6461e-04 7.0457e+00 - 194 1.8395e-03 1.4275e-03 1.2282e-04 1.6461e-04 7.0457e+00 - 195 1.8398e-03 1.4272e-03 1.2281e-04 1.6461e-04 7.0457e+00 - 196 1.8402e-03 1.4269e-03 1.2280e-04 1.6461e-04 7.0458e+00 - 197 1.8405e-03 1.4266e-03 1.2279e-04 1.6461e-04 7.0458e+00 - 198 1.8408e-03 1.4263e-03 1.2278e-04 1.6462e-04 7.0458e+00 - 199 1.8411e-03 1.4260e-03 1.2277e-04 1.6462e-04 7.0458e+00 - 200 1.8415e-03 1.4257e-03 1.2276e-04 1.6462e-04 7.0458e+00 diff --git a/Sun/examples/ex15.log b/Sun/examples/ex15.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex15.out b/Sun/examples/ex15.out deleted file mode 100644 index fd32cad1..00000000 --- a/Sun/examples/ex15.out +++ /dev/null @@ -1,2299 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex15 - Output file: ex15.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex15.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 15.--1D Transport: Kinetic Biodegradation, Cell Growth, and Sorption - *********** - PLEASE NOTE: This problem requires database file ex15.dat!! - *********** - SOLUTION 0 Pulse solution with NTA and cobalt - units umol/L - pH 6 - C .49 - O(0) 62.5 - Nta 5.23 - Co 5.23 - Na 1000 - Cl 1000 - END ------ -TITLE ------ - - Example 15.--1D Transport: Kinetic Biodegradation, Cell Growth, and Sorption -*********** -PLEASE NOTE: This problem requires database file ex15.dat!! -*********** - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. Pulse solution with NTA and cobalt - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.900e-07 4.900e-07 - Cl 1.000e-03 1.000e-03 - Co 5.230e-06 5.230e-06 - Na 1.000e-03 1.000e-03 - Nta 5.230e-06 5.230e-06 - O(0) 6.250e-05 6.250e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.005e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.539e-05 - Total CO2 (mol/kg) = 4.900e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.954e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 - Iterations = 6 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - O(-2)/O(0) 14.3937 0.8515 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 - OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 4.900e-07 - CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 - HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 5.230e-06 - CoNta- 4.793e-06 4.793e-06 -5.319 -5.319 -0.000 - Co+2 4.370e-07 4.370e-07 -6.360 -6.360 -0.000 - CoOH+ 8.719e-11 8.719e-11 -10.060 -10.060 -0.000 - CoOHNta-2 3.024e-11 3.024e-11 -10.519 -10.519 -0.000 - CoNta2-4 6.618e-14 6.618e-14 -13.179 -13.179 -0.000 - Co(OH)2 5.501e-18 5.501e-18 -17.260 -17.260 0.000 - Co(OH)3- 1.382e-20 1.382e-20 -19.860 -19.860 -0.000 -H(0) 1.416e-23 - H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 5.230e-06 - CoNta- 4.793e-06 4.793e-06 -5.319 -5.319 -0.000 - HNta-2 4.366e-07 4.366e-07 -6.360 -6.360 -0.000 - H2Nta- 4.366e-10 4.366e-10 -9.360 -9.360 -0.000 - CoOHNta-2 3.024e-11 3.024e-11 -10.519 -10.519 -0.000 - Nta-3 2.188e-11 2.188e-11 -10.660 -10.660 -0.000 - CoNta2-4 6.618e-14 6.618e-14 -13.179 -13.179 -0.000 - H3Nta 1.738e-14 1.738e-14 -13.760 -13.760 0.000 -O(0) 6.250e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1-10 Background solution initially filling column # 1-20 - units umol/L - pH 6 - C .49 - O(0) 62.5 - Na 1000 - Cl 1000 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Background solution initially filling column - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.900e-07 4.900e-07 - Cl 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - O(0) 6.250e-05 6.250e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.414e-07 - Total CO2 (mol/kg) = 4.900e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 4 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - O(-2)/O(0) 14.3937 0.8515 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 - OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 4.900e-07 - CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 - HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -H(0) 1.416e-23 - H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -O(0) 6.250e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - RATES Rate expressions for the four kinetic reactions - HNTA-2 - start - 10 Ks = 7.64e-7 - 20 Ka = 6.25e-6 - 30 qm = 1.407e-3/3600 - 40 f1 = MOL("HNta-2")/(Ks + MOL("HNta-2")) - 50 f2 = MOL("O2")/(Ka + MOL("O2")) - 60 rate = -qm * KIN("Biomass") * f1 * f2 - 70 moles = rate * TIME - 80 PUT(rate, 1) # save the rate for use in Biomass rate calculation - 90 SAVE moles - end - Biomass - start - 10 Y = 65.14 - 20 b = 0.00208/3600 - 30 rate = GET(1) # uses rate calculated in HTNA-2 rate calculation - 40 rate = -Y*rate -b*M - 50 moles = -rate * TIME - 60 if (M + moles) < 0 then moles = -M - 70 SAVE moles - end - Co_sorption - start - 10 km = 1/3600 - 20 kd = 5.07e-3 - 30 solids = 3.75e3 - 40 rate = -km*(MOL("Co+2") - (M/solids)/kd) - 50 moles = rate * TIME - 60 if (M - moles) < 0 then moles = M - 70 SAVE moles - end - CoNta_sorption - start - 10 km = 1/3600 - 20 kd = 5.33e-4 - 30 solids = 3.75e3 - 40 rate = -km*(MOL("CoNta-") - (M/solids)/kd) - 50 moles = rate * TIME - 60 if (M - moles) < 0 then moles = M - 70 SAVE moles - end - KINETICS 1-10 Four kinetic reactions for all cells # 1-20 - HNTA-2 - formula C -3.12 H -1.968 O -4.848 N -0.424 Nta 1. - Biomass - formula H 0.0 - m 1.36e-4 - Co_sorption - formula CoCl2 - m 0.0 - tol 1e-11 - CoNta_sorption - formula NaCoNta - m 0.0 - tol 1e-11 - SELECTED_OUTPUT - file ex15.sel - molalities Nta-3 CoNta- HNta-2 Co+2 - USER_PUNCH - heading hours Co_sorb CoNta_sorb Biomass - start - 10 punch TOTAL_TIME/3600 + 1800/3600 # TOTAL_TIME/3600 + 900/3600 - 20 punch KIN("Co_sorption")/3.75e3 - 30 punch KIN("CoNta_sorption")/3.75e3 - 40 punch KIN("Biomass") - end - TRANSPORT First 20 hours have NTA and cobalt in infilling solution - cells 10 # 20 - length 1 # 0.5 - shifts 20 # 40 - time_step 3600 # 1800 - flow_direction forward - boundary_conditions flux flux - dispersivity .05 - correct_disp true - diffusion_coefficient 0.0e-9 - punch_cells 10 # 20 - punch_frequency 1 # 2 - print_cells 10 # 20 - print_frequency 5 # 10 - END -WARNING: Cell-lengths were read for 1 cells. Last value is used till cell 10. -WARNING: Dispersivities were read for 1 cells. Last value is used till cell 10. ------------------------------------- -Beginning of transport calculations. ------------------------------------- - -------------------------------- -Equilibrating initial solutions -------------------------------- - -Using solution 10. Background solution initially filling column - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.900e-07 4.900e-07 - Cl 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.000 Charge balance - pe = 14.394 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.414e-07 - Total CO2 (mol/kg) = 4.900e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 - OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 4.900e-07 - CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 - HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -O(0) 6.250e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 1. - -Transport step 1. Mixrun 1. - -Transport step 2. - -Transport step 2. Mixrun 1. - -Transport step 3. - -Transport step 3. Mixrun 1. - -Transport step 4. - -Transport step 4. Mixrun 1. - -Transport step 5. - -Transport step 5. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 3. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 3. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 18000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 9.570e-14 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass -2.804e-07 1.346e-04 H 0 - Co_sorption 2.317e-14 2.317e-14 CoCl2 1 - CoNta_sorption 5.391e-19 5.391e-19 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.900e-07 4.900e-07 - Cl 1.000e-03 1.000e-03 - Co 2.318e-14 2.318e-14 - N 4.652e-13 4.652e-13 - Na 1.000e-03 1.000e-03 - Nta 8.316e-13 8.316e-13 - -----------------------------Description of solution---------------------------- - - pH = 6.000 Charge balance - pe = 14.394 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.414e-07 - Total CO2 (mol/kg) = 4.900e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 - OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 4.900e-07 - CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 - HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 2.318e-14 - Co+2 2.317e-14 2.317e-14 -13.635 -13.635 -0.000 - CoOH+ 4.623e-18 4.623e-18 -17.335 -17.335 -0.000 - CoNta- 4.836e-19 4.836e-19 -18.316 -18.316 -0.000 - CoOHNta-2 3.051e-24 3.051e-24 -23.516 -23.516 -0.000 - Co(OH)2 2.917e-25 2.917e-25 -24.535 -24.535 0.000 - Co(OH)3- 7.327e-28 7.327e-28 -27.135 -27.135 -0.000 - CoNta2-4 1.270e-32 1.270e-32 -31.896 -31.896 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -N 4.652e-13 - NH4+ 4.649e-13 4.649e-13 -12.333 -12.333 -0.000 - NH3 2.330e-16 2.330e-16 -15.633 -15.633 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 8.316e-13 - HNta-2 8.308e-13 8.308e-13 -12.081 -12.081 -0.000 - H2Nta- 8.308e-16 8.308e-16 -15.081 -15.081 -0.000 - Nta-3 4.164e-17 4.164e-17 -16.381 -16.381 -0.000 - CoNta- 4.836e-19 4.836e-19 -18.316 -18.316 -0.000 - H3Nta 3.307e-20 3.307e-20 -19.481 -19.481 0.000 - CoOHNta-2 3.051e-24 3.051e-24 -23.516 -23.516 -0.000 - CoNta2-4 1.270e-32 1.270e-32 -31.896 -31.896 -0.000 -O(0) 6.250e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 6. - -Transport step 6. Mixrun 1. - -Transport step 7. - -Transport step 7. Mixrun 1. - -Transport step 8. - -Transport step 8. Mixrun 1. - -Transport step 9. - -Transport step 9. Mixrun 1. - -Transport step 10. - -Transport step 10. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 3. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 3. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 36000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 2.135e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 1.110e-06 1.356e-04 H 0 - Co_sorption 1.871e-09 3.691e-09 CoCl2 1 - CoNta_sorption 7.149e-09 9.228e-09 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.541e-06 1.541e-06 - Cl 9.992e-04 9.992e-04 - Co 9.656e-09 9.656e-09 - N 1.429e-07 1.429e-07 - Na 9.967e-04 9.967e-04 - Nta 1.196e-07 1.196e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.237 Charge balance - pe = 14.155 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.989e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.439e-06 - Total CO2 (mol/kg) = 1.541e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.646e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.13 - Iterations = 25 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 5.796e-07 5.796e-07 -6.237 -6.237 -0.000 - OH- 1.725e-08 1.725e-08 -7.763 -7.763 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 1.541e-06 - CO2 8.705e-07 8.705e-07 -6.060 -6.060 0.000 - HCO3- 6.709e-07 6.709e-07 -6.173 -6.173 -0.000 - CO3-2 5.414e-11 5.414e-11 -10.266 -10.266 -0.000 -Cl 9.992e-04 - Cl- 9.992e-04 9.992e-04 -3.000 -3.000 -0.000 -Co 9.656e-09 - CoNta- 8.000e-09 8.000e-09 -8.097 -8.097 -0.000 - Co+2 1.655e-09 1.655e-09 -8.781 -8.781 -0.000 - CoOH+ 5.698e-13 5.698e-13 -12.244 -12.244 -0.000 - CoOHNta-2 8.710e-14 8.710e-14 -13.060 -13.060 -0.000 - CoNta2-4 4.869e-17 4.869e-17 -16.313 -16.313 -0.000 - Co(OH)2 6.203e-20 6.203e-20 -19.207 -19.207 0.000 - Co(OH)3- 2.688e-22 2.688e-22 -21.571 -21.571 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.934 -43.934 0.000 -N 1.429e-07 - NH4+ 1.428e-07 1.428e-07 -6.845 -6.845 -0.000 - NH3 1.235e-10 1.235e-10 -9.908 -9.908 0.000 -Na 9.967e-04 - Na+ 9.967e-04 9.967e-04 -3.001 -3.001 -0.000 -Nta 1.196e-07 - HNta-2 1.115e-07 1.115e-07 -6.953 -6.953 -0.000 - CoNta- 8.000e-09 8.000e-09 -8.097 -8.097 -0.000 - H2Nta- 6.464e-11 6.464e-11 -10.190 -10.190 -0.000 - Nta-3 9.645e-12 9.645e-12 -11.016 -11.016 -0.000 - CoOHNta-2 8.710e-14 8.710e-14 -13.060 -13.060 -0.000 - H3Nta 1.491e-15 1.491e-15 -14.826 -14.826 0.000 - CoNta2-4 4.869e-17 4.869e-17 -16.313 -16.313 -0.000 -O(0) 6.141e-05 - O2 3.071e-05 3.071e-05 -4.513 -4.513 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 11. - -Transport step 11. Mixrun 1. - -Transport step 12. - -Transport step 12. Mixrun 1. - -Transport step 13. - -Transport step 13. Mixrun 1. - -Transport step 14. - -Transport step 14. Mixrun 1. - -Transport step 15. - -Transport step 15. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 3. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 3. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 54000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 4.019e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 2.318e-06 1.453e-04 H 0 - Co_sorption 1.090e-08 3.661e-08 CoCl2 1 - CoNta_sorption 9.432e-08 2.656e-07 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.330e-06 2.330e-06 - Cl 9.985e-04 9.985e-04 - Co 1.862e-07 1.862e-07 - N 2.500e-07 2.500e-07 - Na 9.958e-04 9.958e-04 - Nta 4.001e-07 4.001e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.448 Charge balance - pe = 13.942 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.987e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 6.603e-06 - Total CO2 (mol/kg) = 2.330e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.954e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 - Iterations = 21 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.564e-07 3.564e-07 -6.448 -6.448 -0.000 - OH- 2.806e-08 2.806e-08 -7.552 -7.552 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.330e-06 - HCO3- 1.296e-06 1.296e-06 -5.887 -5.887 -0.000 - CO2 1.034e-06 1.034e-06 -5.985 -5.985 0.000 - CO3-2 1.700e-10 1.700e-10 -9.769 -9.769 -0.000 -Cl 9.985e-04 - Cl- 9.985e-04 9.985e-04 -3.001 -3.001 -0.000 -Co 1.862e-07 - CoNta- 1.751e-07 1.751e-07 -6.757 -6.757 -0.000 - Co+2 1.105e-08 1.105e-08 -7.957 -7.957 -0.000 - CoOH+ 6.187e-12 6.187e-12 -11.209 -11.209 -0.000 - CoOHNta-2 3.100e-12 3.100e-12 -11.509 -11.509 -0.000 - CoNta2-4 3.494e-15 3.494e-15 -14.457 -14.457 -0.000 - Co(OH)2 1.095e-18 1.095e-18 -17.960 -17.960 0.000 - Co(OH)3- 7.718e-21 7.718e-21 -20.112 -20.112 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.931 -43.931 0.000 -N 2.500e-07 - NH4+ 2.497e-07 2.497e-07 -6.603 -6.603 -0.000 - NH3 3.511e-10 3.511e-10 -9.455 -9.455 0.000 -Na 9.958e-04 - Na+ 9.958e-04 9.958e-04 -3.002 -3.002 -0.000 -Nta 4.001e-07 - HNta-2 2.249e-07 2.249e-07 -6.648 -6.648 -0.000 - CoNta- 1.751e-07 1.751e-07 -6.757 -6.757 -0.000 - H2Nta- 8.014e-11 8.014e-11 -10.096 -10.096 -0.000 - Nta-3 3.162e-11 3.162e-11 -10.500 -10.500 -0.000 - CoOHNta-2 3.100e-12 3.100e-12 -11.509 -11.509 -0.000 - CoNta2-4 3.494e-15 3.494e-15 -14.457 -14.457 -0.000 - H3Nta 1.137e-15 1.137e-15 -14.944 -14.944 0.000 -O(0) 6.059e-05 - O2 3.030e-05 3.030e-05 -4.519 -4.519 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 16. - -Transport step 16. Mixrun 1. - -Transport step 17. - -Transport step 17. Mixrun 1. - -Transport step 18. - -Transport step 18. Mixrun 1. - -Transport step 19. - -Transport step 19. Mixrun 1. - -Transport step 20. - -Transport step 20. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 3. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 3. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 72000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 4.950e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 2.897e-06 1.588e-04 H 0 - Co_sorption 2.585e-08 1.347e-07 CoCl2 1 - CoNta_sorption 2.379e-07 1.169e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.638e-06 2.638e-06 - Cl 9.982e-04 9.982e-04 - Co 7.184e-07 7.184e-07 - N 2.918e-07 2.918e-07 - Na 9.965e-04 9.965e-04 - Nta 9.571e-07 9.571e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.540 Charge balance - pe = 13.850 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.994e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.227e-06 - Total CO2 (mol/kg) = 2.638e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.954e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 - Iterations = 51 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.887e-07 2.887e-07 -6.540 -6.540 -0.000 - OH- 3.464e-08 3.464e-08 -7.460 -7.460 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.638e-06 - HCO3- 1.602e-06 1.602e-06 -5.795 -5.795 -0.000 - CO2 1.035e-06 1.035e-06 -5.985 -5.985 0.000 - CO3-2 2.596e-10 2.596e-10 -9.586 -9.586 -0.000 -Cl 9.982e-04 - Cl- 9.982e-04 9.982e-04 -3.001 -3.001 -0.000 -Co 7.184e-07 - CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 - Co+2 2.952e-08 2.952e-08 -7.530 -7.530 -0.000 - CoOH+ 2.040e-11 2.040e-11 -10.690 -10.690 -0.000 - CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 - CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 - Co(OH)2 4.459e-18 4.459e-18 -17.351 -17.351 0.000 - Co(OH)3- 3.880e-20 3.880e-20 -19.411 -19.411 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 -N 2.918e-07 - NH4+ 2.913e-07 2.913e-07 -6.536 -6.536 -0.000 - NH3 5.058e-10 5.058e-10 -9.296 -9.296 0.000 -Na 9.965e-04 - Na+ 9.965e-04 9.965e-04 -3.002 -3.002 -0.000 -Nta 9.571e-07 - CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 - HNta-2 2.682e-07 2.682e-07 -6.572 -6.572 -0.000 - H2Nta- 7.742e-11 7.742e-11 -10.111 -10.111 -0.000 - Nta-3 4.656e-11 4.656e-11 -10.332 -10.332 -0.000 - CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 - CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 - H3Nta 8.897e-16 8.897e-16 -15.051 -15.051 0.000 -O(0) 6.027e-05 - O2 3.014e-05 3.014e-05 -4.521 -4.521 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - PRINT - selected_output false - SOLUTION 0 New infilling solution, same as background solution - units umol/L - pH 6 - C .49 - O(0) 62.5 - Na 1000 - Cl 1000 - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 0. New infilling solution, same as background solution - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.900e-07 4.900e-07 - Cl 1.000e-03 1.000e-03 - Na 1.000e-03 1.000e-03 - O(0) 6.250e-05 6.250e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.414e-07 - Total CO2 (mol/kg) = 4.900e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 4 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - O(-2)/O(0) 14.3937 0.8515 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.000e-06 1.000e-06 -6.000 -6.000 -0.000 - OH- 1.000e-08 1.000e-08 -8.000 -8.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 4.900e-07 - CO2 3.387e-07 3.387e-07 -6.470 -6.470 0.000 - HCO3- 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CO3-2 7.077e-12 7.077e-12 -11.150 -11.150 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -H(0) 1.416e-23 - H2 7.079e-24 7.079e-24 -23.150 -23.150 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -O(0) 6.250e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 5. ------------------------------------- - - PRINT - selected_output true - TRANSPORT Last 55 hours with background infilling solution - shifts 55 # 110 - END ------------------------------------- -Column data retained from former run ------------------------------------- - ------------------------------------- -Beginning of transport calculations. ------------------------------------- - -------------------------------- -Equilibrating initial solutions -------------------------------- - -Using solution 10. Solution after simulation 3. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.638e-06 2.638e-06 - Cl 9.982e-04 9.982e-04 - Co 7.184e-07 7.184e-07 - N 2.918e-07 2.918e-07 - Na 9.965e-04 9.965e-04 - Nta 9.571e-07 9.571e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.540 Charge balance - pe = 13.850 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.994e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.227e-06 - Total CO2 (mol/kg) = 2.638e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.954e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.887e-07 2.887e-07 -6.540 -6.540 -0.000 - OH- 3.464e-08 3.464e-08 -7.460 -7.460 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.638e-06 - HCO3- 1.602e-06 1.602e-06 -5.795 -5.795 -0.000 - CO2 1.035e-06 1.035e-06 -5.985 -5.985 0.000 - CO3-2 2.596e-10 2.596e-10 -9.586 -9.586 -0.000 -Cl 9.982e-04 - Cl- 9.982e-04 9.982e-04 -3.001 -3.001 -0.000 -Co 7.184e-07 - CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 - Co+2 2.952e-08 2.952e-08 -7.530 -7.530 -0.000 - CoOH+ 2.040e-11 2.040e-11 -10.690 -10.690 -0.000 - CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 - CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 - Co(OH)2 4.459e-18 4.459e-18 -17.351 -17.351 0.000 - Co(OH)3- 3.880e-20 3.880e-20 -19.411 -19.411 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 -N 2.918e-07 - NH4+ 2.913e-07 2.913e-07 -6.536 -6.536 -0.000 - NH3 5.058e-10 5.058e-10 -9.296 -9.296 0.000 -Na 9.965e-04 - Na+ 9.965e-04 9.965e-04 -3.002 -3.002 -0.000 -Nta 9.571e-07 - CoNta- 6.888e-07 6.888e-07 -6.162 -6.162 -0.000 - HNta-2 2.682e-07 2.682e-07 -6.572 -6.572 -0.000 - H2Nta- 7.742e-11 7.742e-11 -10.111 -10.111 -0.000 - Nta-3 4.656e-11 4.656e-11 -10.332 -10.332 -0.000 - CoOHNta-2 1.505e-11 1.505e-11 -10.822 -10.822 -0.000 - CoNta2-4 2.024e-14 2.024e-14 -13.694 -13.694 -0.000 - H3Nta 8.897e-16 8.897e-16 -15.051 -15.051 0.000 -O(0) 6.027e-05 - O2 3.014e-05 3.014e-05 -4.521 -4.521 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 1. - -Transport step 1. Mixrun 1. - -Transport step 2. - -Transport step 2. Mixrun 1. - -Transport step 3. - -Transport step 3. Mixrun 1. - -Transport step 4. - -Transport step 4. Mixrun 1. - -Transport step 5. - -Transport step 5. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 90000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 5.582e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 3.276e-06 1.744e-04 H 0 - Co_sorption 4.161e-08 3.117e-07 CoCl2 1 - CoNta_sorption 3.270e-07 2.663e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.855e-06 2.855e-06 - Cl 9.981e-04 9.981e-04 - Co 1.525e-06 1.525e-06 - N 3.213e-07 3.213e-07 - Na 9.973e-04 9.973e-04 - Nta 1.754e-06 1.754e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.593 Charge balance - pe = 13.797 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.000e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.229e-05 - Total CO2 (mol/kg) = 2.855e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.954e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.20 - Iterations = 49 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.555e-07 2.555e-07 -6.593 -6.593 -0.000 - OH- 3.914e-08 3.914e-08 -7.407 -7.407 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.855e-06 - HCO3- 1.816e-06 1.816e-06 -5.741 -5.741 -0.000 - CO2 1.039e-06 1.039e-06 -5.984 -5.984 0.000 - CO3-2 3.324e-10 3.324e-10 -9.478 -9.478 -0.000 -Cl 9.981e-04 - Cl- 9.981e-04 9.981e-04 -3.001 -3.001 -0.000 -Co 1.525e-06 - CoNta- 1.472e-06 1.472e-06 -5.832 -5.832 -0.000 - Co+2 5.314e-08 5.314e-08 -7.275 -7.275 -0.000 - CoOH+ 4.150e-11 4.150e-11 -10.382 -10.382 -0.000 - CoOHNta-2 3.634e-11 3.634e-11 -10.440 -10.440 -0.000 - CoNta2-4 5.131e-14 5.131e-14 -13.290 -13.290 -0.000 - Co(OH)2 1.025e-17 1.025e-17 -16.989 -16.989 0.000 - Co(OH)3- 1.008e-19 1.008e-19 -18.997 -18.997 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.929 -43.929 0.000 -N 3.213e-07 - NH4+ 3.207e-07 3.207e-07 -6.494 -6.494 -0.000 - NH3 6.291e-10 6.291e-10 -9.201 -9.201 0.000 -Na 9.973e-04 - Na+ 9.973e-04 9.973e-04 -3.001 -3.001 -0.000 -Nta 1.754e-06 - CoNta- 1.472e-06 1.472e-06 -5.832 -5.832 -0.000 - HNta-2 2.817e-07 2.817e-07 -6.550 -6.550 -0.000 - H2Nta- 7.197e-11 7.197e-11 -10.143 -10.143 -0.000 - Nta-3 5.526e-11 5.526e-11 -10.258 -10.258 -0.000 - CoOHNta-2 3.634e-11 3.634e-11 -10.440 -10.440 -0.000 - CoNta2-4 5.131e-14 5.131e-14 -13.290 -13.290 -0.000 - H3Nta 7.320e-16 7.320e-16 -15.136 -15.136 0.000 -O(0) 6.005e-05 - O2 3.002e-05 3.002e-05 -4.523 -4.523 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 6. - -Transport step 6. Mixrun 1. - -Transport step 7. - -Transport step 7. Mixrun 1. - -Transport step 8. - -Transport step 8. Mixrun 1. - -Transport step 9. - -Transport step 9. Mixrun 1. - -Transport step 10. - -Transport step 10. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 108000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 5.493e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 3.184e-06 1.911e-04 H 0 - Co_sorption 5.379e-08 5.596e-07 CoCl2 1 - CoNta_sorption 3.109e-07 4.300e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.617e-06 2.617e-06 - Cl 9.984e-04 9.984e-04 - Co 2.356e-06 2.356e-06 - N 2.891e-07 2.891e-07 - Na 1.002e-03 1.002e-03 - Nta 2.524e-06 2.524e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.680 Charge balance - pe = 13.710 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.003e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.418e-05 - Total CO2 (mol/kg) = 2.617e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -4.697e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 47 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.092e-07 2.092e-07 -6.680 -6.680 -0.000 - OH- 4.781e-08 4.781e-08 -7.321 -7.321 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.617e-06 - HCO3- 1.782e-06 1.782e-06 -5.749 -5.749 -0.000 - CO2 8.346e-07 8.346e-07 -6.079 -6.079 0.000 - CO3-2 3.985e-10 3.985e-10 -9.400 -9.400 -0.000 -Cl 9.984e-04 - Cl- 9.984e-04 9.984e-04 -3.001 -3.001 -0.000 -Co 2.356e-06 - CoNta- 2.278e-06 2.278e-06 -5.642 -5.642 -0.000 - Co+2 7.711e-08 7.711e-08 -7.113 -7.113 -0.000 - CoOH+ 7.356e-11 7.356e-11 -10.133 -10.133 -0.000 - CoOHNta-2 6.872e-11 6.872e-11 -10.163 -10.163 -0.000 - CoNta2-4 8.474e-14 8.474e-14 -13.072 -13.072 -0.000 - Co(OH)2 2.219e-17 2.219e-17 -16.654 -16.654 0.000 - Co(OH)3- 2.664e-19 2.664e-19 -18.574 -18.574 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.930 -43.930 0.000 -N 2.891e-07 - NH4+ 2.884e-07 2.884e-07 -6.540 -6.540 -0.000 - NH3 6.910e-10 6.910e-10 -9.161 -9.161 0.000 -Na 1.002e-03 - Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 -Nta 2.524e-06 - CoNta- 2.278e-06 2.278e-06 -5.642 -5.642 -0.000 - HNta-2 2.460e-07 2.460e-07 -6.609 -6.609 -0.000 - CoOHNta-2 6.872e-11 6.872e-11 -10.163 -10.163 -0.000 - Nta-3 5.895e-11 5.895e-11 -10.230 -10.230 -0.000 - H2Nta- 5.146e-11 5.146e-11 -10.289 -10.289 -0.000 - CoNta2-4 8.474e-14 8.474e-14 -13.072 -13.072 -0.000 - H3Nta 4.285e-16 4.285e-16 -15.368 -15.368 0.000 -O(0) 6.029e-05 - O2 3.015e-05 3.015e-05 -4.521 -4.521 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 11. - -Transport step 11. Mixrun 1. - -Transport step 12. - -Transport step 12. Mixrun 1. - -Transport step 13. - -Transport step 13. Mixrun 1. - -Transport step 14. - -Transport step 14. Mixrun 1. - -Transport step 15. - -Transport step 15. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 126000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 5.701e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 3.286e-06 2.072e-04 H 0 - Co_sorption 6.691e-08 8.668e-07 CoCl2 1 - CoNta_sorption 1.292e-07 5.375e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.207e-06 2.207e-06 - Cl 9.987e-04 9.987e-04 - Co 2.833e-06 2.833e-06 - N 2.334e-07 2.334e-07 - Na 1.004e-03 1.004e-03 - Nta 2.963e-06 2.963e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.644 Charge balance - pe = 13.747 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.004e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.435e-05 - Total CO2 (mol/kg) = 2.207e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.384e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 18 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.271e-07 2.271e-07 -6.644 -6.644 -0.000 - OH- 4.403e-08 4.403e-08 -7.356 -7.356 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 2.207e-06 - HCO3- 1.463e-06 1.463e-06 -5.835 -5.835 -0.000 - CO2 7.440e-07 7.440e-07 -6.128 -6.128 0.000 - CO3-2 3.013e-10 3.013e-10 -9.521 -9.521 -0.000 -Cl 9.987e-04 - Cl- 9.987e-04 9.987e-04 -3.001 -3.001 -0.000 -Co 2.833e-06 - CoNta- 2.728e-06 2.728e-06 -5.564 -5.564 -0.000 - Co+2 1.049e-07 1.049e-07 -6.979 -6.979 -0.000 - CoOH+ 9.212e-11 9.212e-11 -10.036 -10.036 -0.000 - CoOHNta-2 7.577e-11 7.577e-11 -10.120 -10.120 -0.000 - CoNta2-4 8.932e-14 8.932e-14 -13.049 -13.049 -0.000 - Co(OH)2 2.559e-17 2.559e-17 -16.592 -16.592 0.000 - Co(OH)3- 2.830e-19 2.830e-19 -18.548 -18.548 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.931 -43.931 0.000 -N 2.334e-07 - NH4+ 2.329e-07 2.329e-07 -6.633 -6.633 -0.000 - NH3 5.139e-10 5.139e-10 -9.289 -9.289 0.000 -Na 1.004e-03 - Na+ 1.004e-03 1.004e-03 -2.998 -2.998 -0.000 -Nta 2.963e-06 - CoNta- 2.728e-06 2.728e-06 -5.564 -5.564 -0.000 - HNta-2 2.352e-07 2.352e-07 -6.629 -6.629 -0.000 - CoOHNta-2 7.577e-11 7.577e-11 -10.120 -10.120 -0.000 - H2Nta- 5.342e-11 5.342e-11 -10.272 -10.272 -0.000 - Nta-3 5.190e-11 5.190e-11 -10.285 -10.285 -0.000 - CoNta2-4 8.932e-14 8.932e-14 -13.049 -13.049 -0.000 - H3Nta 4.830e-16 4.830e-16 -15.316 -15.316 0.000 -O(0) 6.072e-05 - O2 3.036e-05 3.036e-05 -4.518 -4.518 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 16. - -Transport step 16. Mixrun 1. - -Transport step 17. - -Transport step 17. Mixrun 1. - -Transport step 18. - -Transport step 18. Mixrun 1. - -Transport step 19. - -Transport step 19. Mixrun 1. - -Transport step 20. - -Transport step 20. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 144000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 5.782e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 3.305e-06 2.237e-04 H 0 - Co_sorption 7.697e-08 1.234e-06 CoCl2 1 - CoNta_sorption -1.235e-07 5.251e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.847e-06 1.847e-06 - Cl 9.990e-04 9.990e-04 - Co 2.681e-06 2.681e-06 - N 1.845e-07 1.845e-07 - Na 1.003e-03 1.003e-03 - Nta 2.767e-06 2.767e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.540 Charge balance - pe = 13.851 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.004e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.265e-05 - Total CO2 (mol/kg) = 1.847e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 19 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.881e-07 2.881e-07 -6.540 -6.540 -0.000 - OH- 3.471e-08 3.471e-08 -7.460 -7.460 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 1.847e-06 - HCO3- 1.123e-06 1.123e-06 -5.950 -5.950 -0.000 - CO2 7.243e-07 7.243e-07 -6.140 -6.140 0.000 - CO3-2 1.823e-10 1.823e-10 -9.739 -9.739 -0.000 -Cl 9.990e-04 - Cl- 9.990e-04 9.990e-04 -3.000 -3.000 -0.000 -Co 2.681e-06 - CoNta- 2.547e-06 2.547e-06 -5.594 -5.594 -0.000 - Co+2 1.332e-07 1.332e-07 -6.875 -6.875 -0.000 - CoOH+ 9.225e-11 9.225e-11 -10.035 -10.035 -0.000 - CoOHNta-2 5.579e-11 5.579e-11 -10.253 -10.253 -0.000 - CoNta2-4 6.133e-14 6.133e-14 -13.212 -13.212 -0.000 - Co(OH)2 2.020e-17 2.020e-17 -16.695 -16.695 0.000 - Co(OH)3- 1.761e-19 1.761e-19 -18.754 -18.754 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.933 -43.933 0.000 -N 1.845e-07 - NH4+ 1.841e-07 1.841e-07 -6.735 -6.735 -0.000 - NH3 3.203e-10 3.203e-10 -9.494 -9.494 0.000 -Na 1.003e-03 - Na+ 1.003e-03 1.003e-03 -2.999 -2.999 -0.000 -Nta 2.767e-06 - CoNta- 2.547e-06 2.547e-06 -5.594 -5.594 -0.000 - HNta-2 2.193e-07 2.193e-07 -6.659 -6.659 -0.000 - H2Nta- 6.319e-11 6.319e-11 -10.199 -10.199 -0.000 - CoOHNta-2 5.579e-11 5.579e-11 -10.253 -10.253 -0.000 - Nta-3 3.816e-11 3.816e-11 -10.418 -10.418 -0.000 - CoNta2-4 6.133e-14 6.133e-14 -13.212 -13.212 -0.000 - H3Nta 7.247e-16 7.247e-16 -15.140 -15.140 0.000 -O(0) 6.109e-05 - O2 3.055e-05 3.055e-05 -4.515 -4.515 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 21. - -Transport step 21. Mixrun 1. - -Transport step 22. - -Transport step 22. Mixrun 1. - -Transport step 23. - -Transport step 23. Mixrun 1. - -Transport step 24. - -Transport step 24. Mixrun 1. - -Transport step 25. - -Transport step 25. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 162000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 5.421e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 3.036e-06 2.396e-04 H 0 - Co_sorption 7.935e-08 1.630e-06 CoCl2 1 - CoNta_sorption -2.766e-07 4.115e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.473e-06 1.473e-06 - Cl 9.994e-04 9.994e-04 - Co 2.065e-06 2.065e-06 - N 1.336e-07 1.336e-07 - Na 1.002e-03 1.002e-03 - Nta 2.097e-06 2.097e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.412 Charge balance - pe = 13.980 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.003e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.478e-06 - Total CO2 (mol/kg) = 1.473e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 50 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.871e-07 3.871e-07 -6.412 -6.412 -0.000 - OH- 2.584e-08 2.584e-08 -7.588 -7.588 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 1.473e-06 - HCO3- 7.893e-07 7.893e-07 -6.103 -6.103 -0.000 - CO2 6.840e-07 6.840e-07 -6.165 -6.165 0.000 - CO3-2 9.539e-11 9.539e-11 -10.021 -10.021 -0.000 -Cl 9.994e-04 - Cl- 9.994e-04 9.994e-04 -3.000 -3.000 -0.000 -Co 2.065e-06 - CoNta- 1.909e-06 1.909e-06 -5.719 -5.719 -0.000 - Co+2 1.565e-07 1.565e-07 -6.806 -6.806 -0.000 - CoOH+ 8.067e-11 8.067e-11 -10.093 -10.093 -0.000 - CoOHNta-2 3.111e-11 3.111e-11 -10.507 -10.507 -0.000 - CoNta2-4 2.931e-14 2.931e-14 -13.533 -13.533 -0.000 - Co(OH)2 1.315e-17 1.315e-17 -16.881 -16.881 0.000 - Co(OH)3- 8.534e-20 8.534e-20 -19.069 -19.069 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.934 -43.934 0.000 -N 1.336e-07 - NH4+ 1.335e-07 1.335e-07 -6.875 -6.875 -0.000 - NH3 1.728e-10 1.728e-10 -9.762 -9.762 0.000 -Na 1.002e-03 - Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 -Nta 2.097e-06 - CoNta- 1.909e-06 1.909e-06 -5.719 -5.719 -0.000 - HNta-2 1.879e-07 1.879e-07 -6.726 -6.726 -0.000 - H2Nta- 7.274e-11 7.274e-11 -10.138 -10.138 -0.000 - CoOHNta-2 3.111e-11 3.111e-11 -10.507 -10.507 -0.000 - Nta-3 2.434e-11 2.434e-11 -10.614 -10.614 -0.000 - CoNta2-4 2.931e-14 2.931e-14 -13.533 -13.533 -0.000 - H3Nta 1.121e-15 1.121e-15 -14.950 -14.950 0.000 -O(0) 6.148e-05 - O2 3.074e-05 3.074e-05 -4.512 -4.512 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 26. - -Transport step 26. Mixrun 1. - -Transport step 27. - -Transport step 27. Mixrun 1. - -Transport step 28. - -Transport step 28. Mixrun 1. - -Transport step 29. - -Transport step 29. Mixrun 1. - -Transport step 30. - -Transport step 30. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 180000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 4.557e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 2.444e-06 2.531e-04 H 0 - Co_sorption 7.182e-08 2.008e-06 CoCl2 1 - CoNta_sorption -2.844e-07 2.658e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.132e-06 1.132e-06 - Cl 9.997e-04 9.997e-04 - Co 1.349e-06 1.349e-06 - N 8.723e-08 8.723e-08 - Na 1.002e-03 1.002e-03 - Nta 1.324e-06 1.324e-06 - -----------------------------Description of solution---------------------------- - - pH = 6.278 Charge balance - pe = 14.115 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.002e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 6.102e-06 - Total CO2 (mol/kg) = 1.132e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 50 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 5.273e-07 5.273e-07 -6.278 -6.278 -0.000 - OH- 1.896e-08 1.896e-08 -7.722 -7.722 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 1.132e-06 - CO2 6.128e-07 6.128e-07 -6.213 -6.213 0.000 - HCO3- 5.191e-07 5.191e-07 -6.285 -6.285 -0.000 - CO3-2 4.605e-11 4.605e-11 -10.337 -10.337 -0.000 -Cl 9.997e-04 - Cl- 9.997e-04 9.997e-04 -3.000 -3.000 -0.000 -Co 1.349e-06 - CoNta- 1.179e-06 1.179e-06 -5.929 -5.929 -0.000 - Co+2 1.705e-07 1.705e-07 -6.768 -6.768 -0.000 - CoOH+ 6.450e-11 6.450e-11 -10.190 -10.190 -0.000 - CoOHNta-2 1.411e-11 1.411e-11 -10.851 -10.851 -0.000 - CoNta2-4 1.026e-14 1.026e-14 -13.989 -13.989 -0.000 - Co(OH)2 7.719e-18 7.719e-18 -17.112 -17.112 0.000 - Co(OH)3- 3.677e-20 3.677e-20 -19.435 -19.435 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.935 -43.935 0.000 -N 8.723e-08 - NH4+ 8.715e-08 8.715e-08 -7.060 -7.060 -0.000 - NH3 8.284e-11 8.284e-11 -10.082 -10.082 0.000 -Na 1.002e-03 - Na+ 1.002e-03 1.002e-03 -2.999 -2.999 -0.000 -Nta 1.324e-06 - CoNta- 1.179e-06 1.179e-06 -5.929 -5.929 -0.000 - HNta-2 1.452e-07 1.452e-07 -6.838 -6.838 -0.000 - H2Nta- 7.654e-11 7.654e-11 -10.116 -10.116 -0.000 - CoOHNta-2 1.411e-11 1.411e-11 -10.851 -10.851 -0.000 - Nta-3 1.380e-11 1.380e-11 -10.860 -10.860 -0.000 - CoNta2-4 1.026e-14 1.026e-14 -13.989 -13.989 -0.000 - H3Nta 1.607e-15 1.607e-15 -14.794 -14.794 0.000 -O(0) 6.184e-05 - O2 3.092e-05 3.092e-05 -4.510 -4.510 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 31. - -Transport step 31. Mixrun 1. - -Transport step 32. - -Transport step 32. Mixrun 1. - -Transport step 33. - -Transport step 33. Mixrun 1. - -Transport step 34. - -Transport step 34. Mixrun 1. - -Transport step 35. - -Transport step 35. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 198000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 3.282e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 1.593e-06 2.629e-04 H 0 - Co_sorption 5.514e-08 2.320e-06 CoCl2 1 - CoNta_sorption -2.069e-07 1.451e-06 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 8.578e-07 8.578e-07 - Cl 1.000e-03 1.000e-03 - Co 7.877e-07 7.877e-07 - N 4.998e-08 4.998e-08 - Na 1.001e-03 1.001e-03 - Nta 7.128e-07 7.128e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.162 Charge balance - pe = 14.231 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.002e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.419e-06 - Total CO2 (mol/kg) = 8.578e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 20 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.892e-07 6.892e-07 -6.162 -6.162 -0.000 - OH- 1.451e-08 1.451e-08 -7.838 -7.838 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 8.578e-07 - CO2 5.205e-07 5.205e-07 -6.284 -6.284 0.000 - HCO3- 3.373e-07 3.373e-07 -6.472 -6.472 -0.000 - CO3-2 2.289e-11 2.289e-11 -10.640 -10.640 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 7.877e-07 - CoNta- 6.150e-07 6.150e-07 -6.211 -6.211 -0.000 - Co+2 1.727e-07 1.727e-07 -6.763 -6.763 -0.000 - CoOH+ 4.999e-11 4.999e-11 -10.301 -10.301 -0.000 - CoOHNta-2 5.630e-12 5.630e-12 -11.249 -11.249 -0.000 - CoNta2-4 2.757e-15 2.757e-15 -14.560 -14.560 -0.000 - Co(OH)2 4.577e-18 4.577e-18 -17.339 -17.339 0.000 - Co(OH)3- 1.668e-20 1.668e-20 -19.778 -19.778 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.936 -43.936 0.000 -N 4.998e-08 - NH4+ 4.995e-08 4.995e-08 -7.301 -7.301 -0.000 - NH3 3.632e-11 3.632e-11 -10.440 -10.440 0.000 -Na 1.001e-03 - Na+ 1.001e-03 1.001e-03 -3.000 -3.000 -0.000 -Nta 7.128e-07 - CoNta- 6.150e-07 6.150e-07 -6.211 -6.211 -0.000 - HNta-2 9.771e-08 9.771e-08 -7.010 -7.010 -0.000 - H2Nta- 6.734e-11 6.734e-11 -10.172 -10.172 -0.000 - Nta-3 7.106e-12 7.106e-12 -11.148 -11.148 -0.000 - CoOHNta-2 5.630e-12 5.630e-12 -11.249 -11.249 -0.000 - CoNta2-4 2.757e-15 2.757e-15 -14.560 -14.560 -0.000 - H3Nta 1.848e-15 1.848e-15 -14.733 -14.733 0.000 -O(0) 6.212e-05 - O2 3.106e-05 3.106e-05 -4.508 -4.508 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 36. - -Transport step 36. Mixrun 1. - -Transport step 37. - -Transport step 37. Mixrun 1. - -Transport step 38. - -Transport step 38. Mixrun 1. - -Transport step 39. - -Transport step 39. Mixrun 1. - -Transport step 40. - -Transport step 40. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 216000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 1.946e-08 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 7.109e-07 2.681e-04 H 0 - Co_sorption 3.544e-08 2.536e-06 CoCl2 1 - CoNta_sorption -1.186e-07 6.881e-07 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 6.715e-07 6.715e-07 - Cl 1.000e-03 1.000e-03 - Co 4.456e-07 4.456e-07 - N 2.467e-08 2.467e-08 - Na 1.000e-03 1.000e-03 - Nta 3.350e-07 3.350e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.081 Charge balance - pe = 14.313 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.709e-06 - Total CO2 (mol/kg) = 6.715e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 8.307e-07 8.307e-07 -6.081 -6.081 -0.000 - OH- 1.204e-08 1.204e-08 -7.919 -7.919 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 6.715e-07 - CO2 4.367e-07 4.367e-07 -6.360 -6.360 0.000 - HCO3- 2.348e-07 2.348e-07 -6.629 -6.629 -0.000 - CO3-2 1.322e-11 1.322e-11 -10.879 -10.879 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 4.456e-07 - CoNta- 2.794e-07 2.794e-07 -6.554 -6.554 -0.000 - Co+2 1.662e-07 1.662e-07 -6.779 -6.779 -0.000 - CoOH+ 3.992e-11 3.992e-11 -10.399 -10.399 -0.000 - CoOHNta-2 2.122e-12 2.122e-12 -11.673 -11.673 -0.000 - CoNta2-4 5.911e-16 5.911e-16 -15.228 -15.228 -0.000 - Co(OH)2 3.032e-18 3.032e-18 -17.518 -17.518 0.000 - Co(OH)3- 9.168e-21 9.168e-21 -20.038 -20.038 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -N 2.467e-08 - NH4+ 2.465e-08 2.465e-08 -7.608 -7.608 -0.000 - NH3 1.487e-11 1.487e-11 -10.828 -10.828 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 3.350e-07 - CoNta- 2.794e-07 2.794e-07 -6.554 -6.554 -0.000 - HNta-2 5.558e-08 5.558e-08 -7.255 -7.255 -0.000 - H2Nta- 4.618e-11 4.618e-11 -10.336 -10.336 -0.000 - Nta-3 3.353e-12 3.353e-12 -11.475 -11.475 -0.000 - CoOHNta-2 2.122e-12 2.122e-12 -11.673 -11.673 -0.000 - H3Nta 1.527e-15 1.527e-15 -14.816 -14.816 0.000 - CoNta2-4 5.911e-16 5.911e-16 -15.228 -15.228 -0.000 -O(0) 6.232e-05 - O2 3.116e-05 3.116e-05 -4.506 -4.506 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 41. - -Transport step 41. Mixrun 1. - -Transport step 42. - -Transport step 42. Mixrun 1. - -Transport step 43. - -Transport step 43. Mixrun 1. - -Transport step 44. - -Transport step 44. Mixrun 1. - -Transport step 45. - -Transport step 45. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 234000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 9.475e-09 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass 5.654e-08 2.696e-04 H 0 - Co_sorption 2.003e-08 2.664e-06 CoCl2 1 - CoNta_sorption -5.697e-08 2.930e-07 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.676e-07 5.676e-07 - Cl 1.000e-03 1.000e-03 - Co 2.732e-07 2.732e-07 - N 1.054e-08 1.054e-08 - Na 1.000e-03 1.000e-03 - Nta 1.416e-07 1.416e-07 - -----------------------------Description of solution---------------------------- - - pH = 6.035 Charge balance - pe = 14.359 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.065e-07 - Total CO2 (mol/kg) = 5.676e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 23 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.228e-07 9.228e-07 -6.035 -6.035 -0.000 - OH- 1.084e-08 1.084e-08 -7.965 -7.965 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 5.676e-07 - CO2 3.825e-07 3.825e-07 -6.417 -6.417 0.000 - HCO3- 1.851e-07 1.851e-07 -6.733 -6.733 -0.000 - CO3-2 9.383e-12 9.383e-12 -11.028 -11.028 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 2.732e-07 - Co+2 1.583e-07 1.583e-07 -6.801 -6.801 -0.000 - CoNta- 1.149e-07 1.149e-07 -6.940 -6.940 -0.000 - CoOH+ 3.422e-11 3.422e-11 -10.466 -10.466 -0.000 - CoOHNta-2 7.856e-13 7.856e-13 -12.105 -12.105 -0.000 - CoNta2-4 1.050e-16 1.050e-16 -15.979 -15.979 -0.000 - Co(OH)2 2.339e-18 2.339e-18 -17.631 -17.631 0.000 - Co(OH)3- 6.368e-21 6.368e-21 -20.196 -20.196 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -N 1.054e-08 - NH4+ 1.054e-08 1.054e-08 -7.977 -7.977 -0.000 - NH3 5.723e-12 5.723e-12 -11.242 -11.242 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 1.416e-07 - CoNta- 1.149e-07 1.149e-07 -6.940 -6.940 -0.000 - HNta-2 2.667e-08 2.667e-08 -7.574 -7.574 -0.000 - H2Nta- 2.461e-11 2.461e-11 -10.609 -10.609 -0.000 - Nta-3 1.449e-12 1.449e-12 -11.839 -11.839 -0.000 - CoOHNta-2 7.856e-13 7.856e-13 -12.105 -12.105 -0.000 - H3Nta 9.043e-16 9.043e-16 -15.044 -15.044 0.000 - CoNta2-4 1.050e-16 1.050e-16 -15.979 -15.979 -0.000 -O(0) 6.242e-05 - O2 3.121e-05 3.121e-05 -4.506 -4.506 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 46. - -Transport step 46. Mixrun 1. - -Transport step 47. - -Transport step 47. Mixrun 1. - -Transport step 48. - -Transport step 48. Mixrun 1. - -Transport step 49. - -Transport step 49. Mixrun 1. - -Transport step 50. - -Transport step 50. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 252000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 3.947e-09 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass -3.021e-07 2.687e-04 H 0 - Co_sorption 1.119e-08 2.735e-06 CoCl2 1 - CoNta_sorption -2.428e-08 1.158e-07 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.197e-07 5.197e-07 - Cl 1.000e-03 1.000e-03 - Co 1.976e-07 1.976e-07 - N 4.028e-09 4.028e-09 - Na 1.000e-03 1.000e-03 - Nta 5.550e-08 5.550e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.014 Charge balance - pe = 14.380 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.997e-07 - Total CO2 (mol/kg) = 5.197e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 23 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.693e-07 9.693e-07 -6.014 -6.014 -0.000 - OH- 1.032e-08 1.032e-08 -7.986 -7.986 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 5.197e-07 - CO2 3.557e-07 3.557e-07 -6.449 -6.449 0.000 - HCO3- 1.639e-07 1.639e-07 -6.785 -6.785 -0.000 - CO3-2 7.911e-12 7.911e-12 -11.102 -11.102 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 1.976e-07 - Co+2 1.533e-07 1.533e-07 -6.815 -6.815 -0.000 - CoNta- 4.433e-08 4.433e-08 -7.353 -7.353 -0.000 - CoOH+ 3.155e-11 3.155e-11 -10.501 -10.501 -0.000 - CoOHNta-2 2.886e-13 2.886e-13 -12.540 -12.540 -0.000 - CoNta2-4 1.614e-17 1.614e-17 -16.792 -16.792 -0.000 - Co(OH)2 2.054e-18 2.054e-18 -17.687 -17.687 0.000 - Co(OH)3- 5.322e-21 5.322e-21 -20.274 -20.274 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -N 4.028e-09 - NH4+ 4.026e-09 4.026e-09 -8.395 -8.395 -0.000 - NH3 2.082e-12 2.082e-12 -11.682 -11.682 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 5.550e-08 - CoNta- 4.433e-08 4.433e-08 -7.353 -7.353 -0.000 - HNta-2 1.116e-08 1.116e-08 -7.952 -7.952 -0.000 - H2Nta- 1.082e-11 1.082e-11 -10.966 -10.966 -0.000 - Nta-3 5.770e-13 5.770e-13 -12.239 -12.239 -0.000 - CoOHNta-2 2.886e-13 2.886e-13 -12.540 -12.540 -0.000 - H3Nta 4.174e-16 4.174e-16 -15.379 -15.379 0.000 - CoNta2-4 1.614e-17 1.614e-17 -16.792 -16.792 -0.000 -O(0) 6.247e-05 - O2 3.124e-05 3.124e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - -Transport step 51. - -Transport step 51. Mixrun 1. - -Transport step 52. - -Transport step 52. Mixrun 1. - -Transport step 53. - -Transport step 53. Mixrun 1. - -Transport step 54. - -Transport step 54. Mixrun 1. - -Transport step 55. - -Transport step 55. Mixrun 1. - -Using mix 10. -Using kinetics 10. Kinetics defined in simulation 3. - -Mixture 10. - - 6.000e-02 Solution 9 Solution after simulation 5. - 0.000e+00 Solution 11 Background solution initially filling column - 9.400e-01 Solution 10 Solution after simulation 5. - -Kinetics 10. Kinetics defined in simulation 3. - - Time: 270000 seconds - Time step: 3600 seconds - - Rate name Delta Moles Total Moles Reactant Coefficient - - HNTA-2 1.487e-09 1.000e+00 C -3.12 - H -1.968 - O -4.848 - N -0.424 - Nta 1 - Biomass -4.583e-07 2.667e-04 H 0 - Co_sorption 6.974e-09 2.777e-06 CoCl2 1 - CoNta_sorption -9.586e-09 4.346e-08 NaCoNta 1 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.005e-07 5.005e-07 - Cl 1.000e-03 1.000e-03 - Co 1.677e-07 1.677e-07 - N 1.429e-09 1.429e-09 - Na 1.000e-03 1.000e-03 - Nta 2.065e-08 2.065e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.005 Charge balance - pe = 14.389 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.001e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.359e-07 - Total CO2 (mol/kg) = 5.005e-07 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.387e-07 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.04 - Iterations = 23 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.888e-07 9.888e-07 -6.005 -6.005 -0.000 - OH- 1.011e-08 1.011e-08 -7.995 -7.995 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C 5.005e-07 - CO2 3.448e-07 3.448e-07 -6.462 -6.462 0.000 - HCO3- 1.558e-07 1.558e-07 -6.808 -6.808 -0.000 - CO3-2 7.368e-12 7.368e-12 -11.133 -11.133 -0.000 -Cl 1.000e-03 - Cl- 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Co 1.677e-07 - Co+2 1.513e-07 1.513e-07 -6.820 -6.820 -0.000 - CoNta- 1.638e-08 1.638e-08 -7.786 -7.786 -0.000 - CoOH+ 3.053e-11 3.053e-11 -10.515 -10.515 -0.000 - CoOHNta-2 1.045e-13 1.045e-13 -12.981 -12.981 -0.000 - CoNta2-4 2.232e-18 2.232e-18 -17.651 -17.651 -0.000 - Co(OH)2 1.948e-18 1.948e-18 -17.710 -17.710 0.000 - Co(OH)3- 4.948e-21 4.948e-21 -20.306 -20.306 -0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.937 -43.937 0.000 -N 1.429e-09 - NH4+ 1.429e-09 1.429e-09 -8.845 -8.845 -0.000 - NH3 7.241e-13 7.241e-13 -12.140 -12.140 0.000 -Na 1.000e-03 - Na+ 1.000e-03 1.000e-03 -3.000 -3.000 -0.000 -Nta 2.065e-08 - CoNta- 1.638e-08 1.638e-08 -7.786 -7.786 -0.000 - HNta-2 4.262e-09 4.262e-09 -8.370 -8.370 -0.000 - H2Nta- 4.214e-12 4.214e-12 -11.375 -11.375 -0.000 - Nta-3 2.160e-13 2.160e-13 -12.666 -12.666 -0.000 - CoOHNta-2 1.045e-13 1.045e-13 -12.981 -12.981 -0.000 - H3Nta 1.659e-16 1.659e-16 -15.780 -15.780 0.000 - CoNta2-4 2.232e-18 2.232e-18 -17.651 -17.651 -0.000 -O(0) 6.249e-05 - O2 3.125e-05 3.125e-05 -4.505 -4.505 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 6. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex15.sel b/Sun/examples/ex15.sel deleted file mode 100644 index ecf04dff..00000000 --- a/Sun/examples/ex15.sel +++ /dev/null @@ -1,78 +0,0 @@ - sim state soln dist_x time step pH pe m_Nta-3 m_CoNta- m_HNta-2 m_Co+2 hours Co_sorb CoNta_sorb Biomass - 1 transp 10 9.5 0 0 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 5.0000e-01 0.0000e+00 0.0000e+00 0.0000e+00 - 1 transp 10 9.5 3600 1 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 1.5000e+00 0.0000e+00 0.0000e+00 1.3572e-04 - 1 transp 10 9.5 7200 2 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 2.5000e+00 0.0000e+00 0.0000e+00 1.3544e-04 - 1 transp 10 9.5 10800 3 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.5000e+00 0.0000e+00 0.0000e+00 1.3515e-04 - 1 transp 10 9.5 14400 4 6 14.3937 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 4.5000e+00 0.0000e+00 0.0000e+00 1.3487e-04 - 1 transp 10 9.5 18000 5 6 14.3937 4.1637e-17 4.8355e-19 8.3076e-13 2.3172e-14 5.5000e+00 6.1781e-18 1.4377e-22 1.3459e-04 - 1 transp 10 9.5 21600 6 6.00019 14.3935 5.3587e-15 7.6672e-15 1.0687e-10 2.8548e-12 6.5000e+00 1.0994e-15 2.6066e-18 1.3431e-04 - 1 transp 10 9.5 25200 7 6.00441 14.3893 1.1039e-13 3.4338e-12 2.1803e-09 6.2065e-11 7.5000e+00 2.2731e-14 9.7754e-16 1.3406e-04 - 1 transp 10 9.5 28800 8 6.03587 14.3576 8.7248e-13 1.8088e-10 1.6028e-08 4.1366e-10 8.5000e+00 1.5703e-13 4.8045e-14 1.3399e-04 - 1 transp 10 9.5 32400 9 6.12883 14.264 3.7779e-12 1.9561e-09 5.6030e-08 1.0331e-09 9.5000e+00 4.8525e-13 5.5433e-13 1.3445e-04 - 1 transp 10 9.5 36000 10 6.2369 14.1549 9.6448e-12 8.0004e-09 1.1153e-07 1.6551e-09 1.0500e+01 9.8421e-13 2.4608e-12 1.3556e-04 - 1 transp 10 9.5 39600 11 6.30614 14.0851 1.5152e-11 2.0272e-08 1.4940e-07 2.6695e-09 1.1500e+01 1.7623e-12 6.7849e-12 1.3707e-04 - 1 transp 10 9.5 43200 12 6.35376 14.0371 1.9799e-11 4.1065e-08 1.7494e-07 4.1384e-09 1.2500e+01 2.9364e-12 1.4662e-11 1.3886e-04 - 1 transp 10 9.5 46800 13 6.3909 13.9998 2.3996e-11 7.2616e-08 1.9464e-07 6.0380e-09 1.3500e+01 4.6059e-12 2.7261e-11 1.4085e-04 - 1 transp 10 9.5 50400 14 6.4217 13.9688 2.7923e-11 1.1683e-07 2.1099e-07 8.3484e-09 1.4500e+01 6.8561e-12 4.5675e-11 1.4301e-04 - 1 transp 10 9.5 54000 15 6.44804 13.9423 3.1619e-11 1.7515e-07 2.2486e-07 1.1052e-08 1.5500e+01 9.7615e-12 7.0827e-11 1.4533e-04 - 1 transp 10 9.5 57600 16 6.47097 13.9193 3.5087e-11 2.4844e-07 2.3669e-07 1.4128e-08 1.6500e+01 1.3385e-11 1.0340e-10 1.4778e-04 - 1 transp 10 9.5 61200 17 6.49117 13.8989 3.8321e-11 3.3699e-07 2.4675e-07 1.7546e-08 1.7500e+01 1.7779e-11 1.4381e-10 1.5036e-04 - 1 transp 10 9.5 64800 18 6.50914 13.8808 4.1316e-11 4.4051e-07 2.5526e-07 2.1274e-08 1.8500e+01 2.2982e-11 1.9215e-10 1.5306e-04 - 1 transp 10 9.5 68400 19 6.52519 13.8647 4.4065e-11 5.5820e-07 2.6236e-07 2.5276e-08 1.9500e+01 2.9022e-11 2.4826e-10 1.5586e-04 - 1 transp 10 9.5 72000 20 6.53959 13.8502 4.6562e-11 6.8880e-07 2.6819e-07 2.9517e-08 2.0500e+01 3.5915e-11 3.1170e-10 1.5876e-04 - 2 transp 10 9.5 72000 0 6.53959 13.8502 4.6562e-11 6.8880e-07 2.6819e-07 2.9517e-08 2.0500e+01 0.0000e+00 0.0000e+00 0.0000e+00 - 2 transp 10 9.5 75600 1 6.55254 13.8371 4.8804e-11 8.3068e-07 2.7284e-07 3.3961e-08 2.1500e+01 4.3669e-11 3.8179e-10 1.6174e-04 - 2 transp 10 9.5 79200 2 6.56419 13.8254 5.0791e-11 9.8198e-07 2.7644e-07 3.8576e-08 2.2500e+01 5.2280e-11 4.5769e-10 1.6481e-04 - 2 transp 10 9.5 82800 3 6.57469 13.8148 5.2526e-11 1.1406e-06 2.7905e-07 4.3329e-08 2.3500e+01 6.1739e-11 5.3842e-10 1.6796e-04 - 2 transp 10 9.5 86400 4 6.58413 13.8053 5.4012e-11 1.3046e-06 2.8077e-07 4.8193e-08 2.4500e+01 7.2027e-11 6.2293e-10 1.7117e-04 - 2 transp 10 9.5 90000 5 6.59263 13.7967 5.5256e-11 1.4717e-06 2.8168e-07 5.3142e-08 2.5500e+01 8.3123e-11 7.1013e-10 1.7444e-04 - 2 transp 10 9.5 93600 6 6.60028 13.789 5.6269e-11 1.6400e-06 2.8183e-07 5.8153e-08 2.6500e+01 9.4998e-11 7.9893e-10 1.7778e-04 - 2 transp 10 9.5 97200 7 6.60754 13.7817 5.7056e-11 1.8075e-06 2.8103e-07 6.3208e-08 2.7500e+01 1.0762e-10 8.8826e-10 1.8116e-04 - 2 transp 10 9.5 100800 8 6.61795 13.7713 5.7637e-11 1.9718e-06 2.7717e-07 6.8258e-08 2.8500e+01 1.2096e-10 9.7697e-10 1.8457e-04 - 2 transp 10 9.5 104400 9 6.64212 13.7473 5.8212e-11 2.1299e-06 2.6478e-07 7.3002e-08 2.9500e+01 1.3490e-10 1.0636e-09 1.8791e-04 - 2 transp 10 9.5 108000 10 6.6795 13.7103 5.8949e-11 2.2783e-06 2.4602e-07 7.7114e-08 3.0500e+01 1.4924e-10 1.1465e-09 1.9109e-04 - 2 transp 10 9.5 111600 11 6.69156 13.6985 5.8746e-11 2.4117e-06 2.3846e-07 8.1911e-08 3.1500e+01 1.6415e-10 1.2236e-09 1.9424e-04 - 2 transp 10 9.5 115200 12 6.68638 13.7039 5.7684e-11 2.5260e-06 2.3696e-07 8.7374e-08 3.2500e+01 1.7978e-10 1.2925e-09 1.9741e-04 - 2 transp 10 9.5 118800 13 6.67462 13.7157 5.6097e-11 2.6183e-06 2.3676e-07 9.3127e-08 3.3500e+01 1.9616e-10 1.3514e-09 2.0062e-04 - 2 transp 10 9.5 122400 14 6.66009 13.7304 5.4144e-11 2.6860e-06 2.3630e-07 9.8982e-08 3.4500e+01 2.1330e-10 1.3987e-09 2.0387e-04 - 2 transp 10 9.5 126000 15 6.64373 13.7469 5.1900e-11 2.7276e-06 2.3520e-07 1.0486e-07 3.5500e+01 2.3114e-10 1.4332e-09 2.0716e-04 - 2 transp 10 9.5 129600 16 6.62579 13.7649 4.9419e-11 2.7424e-06 2.3341e-07 1.1072e-07 3.6500e+01 2.4964e-10 1.4540e-09 2.1047e-04 - 2 transp 10 9.5 133200 17 6.60638 13.7845 4.6754e-11 2.7304e-06 2.3091e-07 1.1652e-07 3.7500e+01 2.6875e-10 1.4608e-09 2.1379e-04 - 2 transp 10 9.5 136800 18 6.58562 13.8054 4.3956e-11 2.6927e-06 2.2772e-07 1.2223e-07 3.8500e+01 2.8841e-10 1.4537e-09 2.1712e-04 - 2 transp 10 9.5 140400 19 6.56361 13.8275 4.1075e-11 2.6309e-06 2.2386e-07 1.2780e-07 3.9500e+01 3.0854e-10 1.4333e-09 2.2044e-04 - 2 transp 10 9.5 144000 20 6.54047 13.8508 3.8158e-11 2.5474e-06 2.1934e-07 1.3320e-07 4.0500e+01 3.2906e-10 1.4004e-09 2.2375e-04 - 2 transp 10 9.5 147600 21 6.51631 13.8751 3.5247e-11 2.4449e-06 2.1419e-07 1.3841e-07 4.1500e+01 3.4990e-10 1.3562e-09 2.2702e-04 - 2 transp 10 9.5 151200 22 6.49127 13.9003 3.2379e-11 2.3266e-06 2.0845e-07 1.4337e-07 4.2500e+01 3.7097e-10 1.3021e-09 2.3026e-04 - 2 transp 10 9.5 154800 23 6.46547 13.9262 2.9588e-11 2.1956e-06 2.0213e-07 1.4806e-07 4.3500e+01 3.9217e-10 1.2398e-09 2.3344e-04 - 2 transp 10 9.5 158400 24 6.43907 13.9527 2.6899e-11 2.0552e-06 1.9529e-07 1.5245e-07 4.4500e+01 4.1340e-10 1.1710e-09 2.3656e-04 - 2 transp 10 9.5 162000 25 6.41223 13.9797 2.4336e-11 1.9087e-06 1.8794e-07 1.5649e-07 4.5500e+01 4.3456e-10 1.0972e-09 2.3959e-04 - 2 transp 10 9.5 165600 26 6.38512 14.0069 2.1913e-11 1.7589e-06 1.8013e-07 1.6016e-07 4.6500e+01 4.5554e-10 1.0202e-09 2.4253e-04 - 2 transp 10 9.5 169200 27 6.35794 14.0343 1.9643e-11 1.6088e-06 1.7189e-07 1.6342e-07 4.7500e+01 4.7623e-10 9.4150e-10 2.4537e-04 - 2 transp 10 9.5 172800 28 6.33089 14.0614 1.7532e-11 1.4607e-06 1.6329e-07 1.6624e-07 4.8500e+01 4.9652e-10 8.6254e-10 2.4809e-04 - 2 transp 10 9.5 176400 29 6.30416 14.0883 1.5584e-11 1.3168e-06 1.5436e-07 1.6859e-07 4.9500e+01 5.1630e-10 7.8460e-10 2.5068e-04 - 2 transp 10 9.5 180000 30 6.27797 14.1146 1.3798e-11 1.1788e-06 1.4516e-07 1.7047e-07 5.0500e+01 5.3545e-10 7.0877e-10 2.5312e-04 - 2 transp 10 9.5 183600 31 6.25252 14.1402 1.2170e-11 1.0482e-06 1.3576e-07 1.7185e-07 5.1500e+01 5.5388e-10 6.3597e-10 2.5541e-04 - 2 transp 10 9.5 187200 32 6.228 14.1648 1.0695e-11 9.2591e-07 1.2623e-07 1.7274e-07 5.2500e+01 5.7148e-10 5.6693e-10 2.5754e-04 - 2 transp 10 9.5 190800 33 6.20459 14.1883 9.3648e-12 8.1273e-07 1.1666e-07 1.7316e-07 5.3500e+01 5.8818e-10 5.0219e-10 2.5949e-04 - 2 transp 10 9.5 194400 34 6.18244 14.2105 8.1717e-12 7.0904e-07 1.0712e-07 1.7312e-07 5.4500e+01 6.0391e-10 4.4212e-10 2.6127e-04 - 2 transp 10 9.5 198000 35 6.16167 14.2314 7.1059e-12 6.1497e-07 9.7713e-08 1.7268e-07 5.5500e+01 6.1861e-10 3.8695e-10 2.6286e-04 - 2 transp 10 9.5 201600 36 6.14237 14.2508 6.1578e-12 5.3042e-07 8.8524e-08 1.7187e-07 5.6500e+01 6.3226e-10 3.3676e-10 2.6427e-04 - 2 transp 10 9.5 205200 37 6.12459 14.2686 5.3178e-12 4.5509e-07 7.9641e-08 1.7075e-07 5.7500e+01 6.4483e-10 2.9149e-10 2.6550e-04 - 2 transp 10 9.5 208800 38 6.10837 14.2849 4.5763e-12 3.8853e-07 7.1145e-08 1.6940e-07 5.8500e+01 6.5634e-10 2.5101e-10 2.6655e-04 - 2 transp 10 9.5 212400 39 6.09369 14.2996 3.9244e-12 3.3017e-07 6.3107e-08 1.6787e-07 5.9500e+01 6.6679e-10 2.1511e-10 2.6742e-04 - 2 transp 10 9.5 216000 40 6.08053 14.3129 3.3534e-12 2.7937e-07 5.5584e-08 1.6623e-07 6.0500e+01 6.7624e-10 1.8349e-10 2.6813e-04 - 2 transp 10 9.5 219600 41 6.06883 14.3246 2.8552e-12 2.3545e-07 4.8619e-08 1.6454e-07 6.1500e+01 6.8474e-10 1.5585e-10 2.6869e-04 - 2 transp 10 9.5 223200 42 6.05851 14.335 2.4224e-12 1.9772e-07 4.2241e-08 1.6286e-07 6.2500e+01 6.9233e-10 1.3184e-10 2.6910e-04 - 2 transp 10 9.5 226800 43 6.04948 14.3441 2.0479e-12 1.6548e-07 3.6461e-08 1.6123e-07 6.3500e+01 6.9911e-10 1.1112e-10 2.6938e-04 - 2 transp 10 9.5 230400 44 6.04163 14.3519 1.7253e-12 1.3809e-07 3.1277e-08 1.5969e-07 6.4500e+01 7.0513e-10 9.3326e-11 2.6955e-04 - 2 transp 10 9.5 234000 45 6.03487 14.3587 1.4485e-12 1.1491e-07 2.6672e-08 1.5827e-07 6.5500e+01 7.1047e-10 7.8132e-11 2.6960e-04 - 2 transp 10 9.5 237600 46 6.02908 14.3645 1.2122e-12 9.5378e-08 2.2620e-08 1.5699e-07 6.6500e+01 7.1521e-10 6.5220e-11 2.6957e-04 - 2 transp 10 9.5 241200 47 6.02415 14.3695 1.0113e-12 7.8988e-08 1.9086e-08 1.5585e-07 6.7500e+01 7.1941e-10 5.4292e-11 2.6945e-04 - 2 transp 10 9.5 244800 48 6.01999 14.3737 8.4110e-13 6.5277e-08 1.6027e-08 1.5485e-07 6.8500e+01 7.2315e-10 4.5082e-11 2.6926e-04 - 2 transp 10 9.5 248400 49 6.01648 14.3772 6.9760e-13 5.3842e-08 1.3400e-08 1.5400e-07 6.9500e+01 7.2648e-10 3.7348e-11 2.6901e-04 - 2 transp 10 9.5 252000 50 6.01355 14.3801 5.7705e-13 4.4330e-08 1.1160e-08 1.5328e-07 7.0500e+01 7.2947e-10 3.0873e-11 2.6870e-04 - 2 transp 10 9.5 255600 51 6.01111 14.3826 4.7615e-13 3.6437e-08 9.2604e-09 1.5268e-07 7.1500e+01 7.3215e-10 2.5469e-11 2.6836e-04 - 2 transp 10 9.5 259200 52 6.00908 14.3846 3.9198e-13 2.9901e-08 7.6592e-09 1.5220e-07 7.2500e+01 7.3458e-10 2.0972e-11 2.6798e-04 - 2 transp 10 9.5 262800 53 6.00741 14.3863 3.2200e-13 2.4501e-08 6.3161e-09 1.5182e-07 7.3500e+01 7.3678e-10 1.7238e-11 2.6756e-04 - 2 transp 10 9.5 266400 54 6.00603 14.3877 2.6398e-13 2.0046e-08 5.1944e-09 1.5152e-07 7.4500e+01 7.3880e-10 1.4145e-11 2.6713e-04 - 2 transp 10 9.5 270000 55 6.0049 14.3888 2.1600e-13 1.6379e-08 4.2615e-09 1.5130e-07 7.5500e+01 7.4066e-10 1.1589e-11 2.6667e-04 diff --git a/Sun/examples/ex16.log b/Sun/examples/ex16.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex16.out b/Sun/examples/ex16.out deleted file mode 100644 index afb2e8ae..00000000 --- a/Sun/examples/ex16.out +++ /dev/null @@ -1,435 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex16 - Output file: ex16.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 16.--Inverse modeling of Sierra springs - SOLUTION_SPREAD - units mmol/L - Number pH Si Ca Mg Na K Alkalinity S(6) Cl - 1 6.2 0.273 0.078 0.029 0.134 0.028 0.328 0.01 0.014 - 2 6.8 0.41 0.26 0.071 0.259 0.04 0.895 0.025 0.03 - INVERSE_MODELING 1 - solutions 1 2 - uncertainty 0.025 - range - phases - Halite - Gypsum - Kaolinite precip - Ca-montmorillonite precip - CO2(g) - Calcite - Chalcedony precip - Biotite dissolve - Plagioclase dissolve - balances - Ca 0.05 0.025 - PHASES - Biotite - KMg3AlSi3O10(OH)2 + 6H+ + 4H2O = K+ + 3Mg+2 + Al(OH)4- + 3H4SiO4 - log_k 0.0 # No log_k, Inverse modeling only - Plagioclase - Na0.62Ca0.38Al1.38Si2.62O8 + 5.52 H+ + 2.48H2O = 0.62Na+ + 0.38Ca+2 + 1.38Al+3 + 2.62H4SiO4 - log_k 0.0 # No log_k, inverse modeling only - END ------ -TITLE ------ - - Example 16.--Inverse modeling of Sierra springs - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Alkalinity 3.280e-04 3.280e-04 - Ca 7.800e-05 7.800e-05 - Cl 1.400e-05 1.400e-05 - K 2.800e-05 2.800e-05 - Mg 2.900e-05 2.900e-05 - Na 1.340e-04 1.340e-04 - S(6) 1.000e-05 1.000e-05 - Si 2.730e-04 2.730e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.200 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 4.851e-04 - Mass of water (kg) = 1.000e+00 - Total carbon (mol/kg) = 7.825e-04 - Total CO2 (mol/kg) = 7.825e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 1.400e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 1.90 - Iterations = 7 - Total H = 1.110139e+02 - Total O = 5.550924e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.464e-07 6.310e-07 -6.189 -6.200 -0.011 - OH- 1.627e-08 1.587e-08 -7.789 -7.800 -0.011 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(4) 7.825e-04 - CO2 4.540e-04 4.540e-04 -3.343 -3.343 0.000 - HCO3- 3.281e-04 3.200e-04 -3.484 -3.495 -0.011 - CaHCO3+ 2.940e-07 2.868e-07 -6.532 -6.542 -0.011 - MgHCO3+ 1.003e-07 9.783e-08 -6.999 -7.010 -0.011 - CO3-2 2.628e-08 2.379e-08 -7.580 -7.624 -0.043 - NaHCO3 2.351e-08 2.352e-08 -7.629 -7.629 0.000 - CaCO3 2.806e-09 2.807e-09 -8.552 -8.552 0.000 - MgCO3 5.929e-10 5.930e-10 -9.227 -9.227 0.000 - NaCO3- 5.935e-11 5.788e-11 -10.227 -10.237 -0.011 -Ca 7.800e-05 - Ca+2 7.758e-05 7.023e-05 -4.110 -4.153 -0.043 - CaHCO3+ 2.940e-07 2.868e-07 -6.532 -6.542 -0.011 - CaSO4 1.244e-07 1.245e-07 -6.905 -6.905 0.000 - CaCO3 2.806e-09 2.807e-09 -8.552 -8.552 0.000 - CaOH+ 1.894e-11 1.847e-11 -10.723 -10.733 -0.011 - CaHSO4+ 4.717e-13 4.600e-13 -12.326 -12.337 -0.011 -Cl 1.400e-05 - Cl- 1.400e-05 1.365e-05 -4.854 -4.865 -0.011 -H(0) 5.636e-24 - H2 2.818e-24 2.818e-24 -23.550 -23.550 0.000 -K 2.800e-05 - K+ 2.800e-05 2.730e-05 -4.553 -4.564 -0.011 - KSO4- 1.747e-09 1.704e-09 -8.758 -8.769 -0.011 - KOH 1.500e-13 1.500e-13 -12.824 -12.824 0.000 -Mg 2.900e-05 - Mg+2 2.885e-05 2.612e-05 -4.540 -4.583 -0.043 - MgHCO3+ 1.003e-07 9.783e-08 -6.999 -7.010 -0.011 - MgSO4 5.438e-08 5.439e-08 -7.265 -7.264 0.000 - MgCO3 5.929e-10 5.930e-10 -9.227 -9.227 0.000 - MgOH+ 1.541e-10 1.503e-10 -9.812 -9.823 -0.011 -Na 1.340e-04 - Na+ 1.340e-04 1.307e-04 -3.873 -3.884 -0.011 - NaHCO3 2.351e-08 2.352e-08 -7.629 -7.629 0.000 - NaSO4- 5.964e-09 5.816e-09 -8.224 -8.235 -0.011 - NaCO3- 5.935e-11 5.788e-11 -10.227 -10.237 -0.011 - NaOH 1.368e-12 1.368e-12 -11.864 -11.864 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -45.280 -45.280 0.000 -S(6) 1.000e-05 - SO4-2 9.813e-06 8.882e-06 -5.008 -5.052 -0.043 - CaSO4 1.244e-07 1.245e-07 -6.905 -6.905 0.000 - MgSO4 5.438e-08 5.439e-08 -7.265 -7.264 0.000 - NaSO4- 5.964e-09 5.816e-09 -8.224 -8.235 -0.011 - KSO4- 1.747e-09 1.704e-09 -8.758 -8.769 -0.011 - HSO4- 5.587e-10 5.448e-10 -9.253 -9.264 -0.011 - CaHSO4+ 4.717e-13 4.600e-13 -12.326 -12.337 -0.011 -Si 2.730e-04 - H4SiO4 2.729e-04 2.730e-04 -3.564 -3.564 0.000 - H3SiO4- 6.541e-08 6.379e-08 -7.184 -7.195 -0.011 - H2SiO4-2 7.604e-15 6.877e-15 -14.119 -14.163 -0.044 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -4.84 -9.20 -4.36 CaSO4 - Aragonite -3.44 -11.78 -8.34 CaCO3 - Calcite -3.30 -11.78 -8.48 CaCO3 - Chalcedony -0.01 -3.56 -3.55 SiO2 - Chrysotile -15.88 16.32 32.20 Mg3Si2O5(OH)4 - CO2(g) -1.87 -3.34 -1.47 CO2 - Dolomite -6.89 -23.98 -17.09 CaMg(CO3)2 - Gypsum -4.62 -9.20 -4.58 CaSO4:2H2O - H2(g) -20.40 -23.55 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -10.33 -8.75 1.58 NaCl - O2(g) -42.32 -45.28 -2.96 O2 - Quartz 0.42 -3.56 -3.98 SiO2 - Sepiolite -10.82 4.94 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -13.72 4.94 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -0.85 -3.56 -2.71 SiO2 - Talc -12.20 9.20 21.40 Mg3Si4O10(OH)2 - -Initial solution 2. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Alkalinity 8.951e-04 8.951e-04 - Ca 2.600e-04 2.600e-04 - Cl 3.000e-05 3.000e-05 - K 4.000e-05 4.000e-05 - Mg 7.101e-05 7.101e-05 - Na 2.590e-04 2.590e-04 - S(6) 2.500e-05 2.500e-05 - Si 4.100e-04 4.100e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.800 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.313e-03 - Mass of water (kg) = 1.000e+00 - Total carbon (mol/kg) = 1.199e-03 - Total CO2 (mol/kg) = 1.199e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.400e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.73 - Iterations = 6 - Total H = 1.110150e+02 - Total O = 5.551125e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.647e-07 1.585e-07 -6.783 -6.800 -0.017 - OH- 6.579e-08 6.316e-08 -7.182 -7.200 -0.018 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(4) 1.199e-03 - HCO3- 8.907e-04 8.559e-04 -3.050 -3.068 -0.017 - CO2 3.049e-04 3.050e-04 -3.516 -3.516 0.000 - CaHCO3+ 2.485e-06 2.387e-06 -5.605 -5.622 -0.017 - MgHCO3+ 6.235e-07 5.987e-07 -6.205 -6.223 -0.018 - CO3-2 2.971e-07 2.533e-07 -6.527 -6.596 -0.069 - NaHCO3 1.196e-07 1.197e-07 -6.922 -6.922 0.000 - CaCO3 9.299e-08 9.302e-08 -7.032 -7.031 0.000 - MgCO3 1.444e-08 1.445e-08 -7.840 -7.840 0.000 - NaCO3- 1.221e-09 1.173e-09 -8.913 -8.931 -0.018 -Ca 2.600e-04 - Ca+2 2.566e-04 2.186e-04 -3.591 -3.660 -0.069 - CaHCO3+ 2.485e-06 2.387e-06 -5.605 -5.622 -0.017 - CaSO4 8.841e-07 8.843e-07 -6.054 -6.053 0.000 - CaCO3 9.299e-08 9.302e-08 -7.032 -7.031 0.000 - CaOH+ 2.384e-10 2.289e-10 -9.623 -9.640 -0.018 - CaHSO4+ 8.551e-13 8.211e-13 -12.068 -12.086 -0.018 -Cl 3.000e-05 - Cl- 3.000e-05 2.880e-05 -4.523 -4.541 -0.018 -H(0) 3.555e-25 - H2 1.778e-25 1.778e-25 -24.750 -24.750 0.000 -K 4.000e-05 - K+ 4.000e-05 3.840e-05 -4.398 -4.416 -0.018 - KSO4- 5.696e-09 5.470e-09 -8.244 -8.262 -0.018 - KOH 8.398e-13 8.401e-13 -12.076 -12.076 0.000 -Mg 7.101e-05 - Mg+2 7.008e-05 5.978e-05 -4.154 -4.223 -0.069 - MgHCO3+ 6.235e-07 5.987e-07 -6.205 -6.223 -0.018 - MgSO4 2.840e-07 2.841e-07 -6.547 -6.547 0.000 - MgCO3 1.444e-08 1.445e-08 -7.840 -7.840 0.000 - MgOH+ 1.426e-09 1.370e-09 -8.846 -8.863 -0.018 -Na 2.590e-04 - Na+ 2.589e-04 2.486e-04 -3.587 -3.604 -0.018 - NaHCO3 1.196e-07 1.197e-07 -6.922 -6.922 0.000 - NaSO4- 2.631e-08 2.526e-08 -7.580 -7.598 -0.018 - NaCO3- 1.221e-09 1.173e-09 -8.913 -8.931 -0.018 - NaOH 1.036e-11 1.036e-11 -10.985 -10.984 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.880 -42.880 0.000 -S(6) 2.500e-05 - SO4-2 2.380e-05 2.027e-05 -4.623 -4.693 -0.070 - CaSO4 8.841e-07 8.843e-07 -6.054 -6.053 0.000 - MgSO4 2.840e-07 2.841e-07 -6.547 -6.547 0.000 - NaSO4- 2.631e-08 2.526e-08 -7.580 -7.598 -0.018 - KSO4- 5.696e-09 5.470e-09 -8.244 -8.262 -0.018 - HSO4- 3.253e-10 3.124e-10 -9.488 -9.505 -0.018 - CaHSO4+ 8.551e-13 8.211e-13 -12.068 -12.086 -0.018 -Si 4.100e-04 - H4SiO4 4.096e-04 4.098e-04 -3.388 -3.387 0.000 - H3SiO4- 3.970e-07 3.812e-07 -6.401 -6.419 -0.018 - H2SiO4-2 1.924e-13 1.636e-13 -12.716 -12.786 -0.070 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.99 -8.35 -4.36 CaSO4 - Aragonite -1.92 -10.26 -8.34 CaCO3 - Calcite -1.78 -10.26 -8.48 CaCO3 - Chalcedony 0.16 -3.39 -3.55 SiO2 - Chrysotile -10.85 21.35 32.20 Mg3Si2O5(OH)4 - CO2(g) -2.05 -3.52 -1.47 CO2 - Dolomite -3.99 -21.08 -17.09 CaMg(CO3)2 - Gypsum -3.77 -8.35 -4.58 CaSO4:2H2O - H2(g) -21.60 -24.75 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -9.73 -8.14 1.58 NaCl - O2(g) -39.92 -42.88 -2.96 O2 - Quartz 0.59 -3.39 -3.98 SiO2 - Sepiolite -7.17 8.59 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -10.07 8.59 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -0.68 -3.39 -2.71 SiO2 - Talc -6.82 14.58 21.40 Mg3Si4O10(OH)2 - -------------------------------------------- -Beginning of inverse modeling calculations. -------------------------------------------- - - -Solution 1: - - Input Delta Input+Delta - pH 6.200e+00 + 1.246e-02 = 6.212e+00 - Al 0.000e+00 + 0.000e+00 = 0.000e+00 - Alkalinity 3.280e-04 + 5.500e-06 = 3.335e-04 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 7.825e-04 + 0.000e+00 = 7.825e-04 - Ca 7.800e-05 + -3.900e-06 = 7.410e-05 - Cl 1.400e-05 + 0.000e+00 = 1.400e-05 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 2.800e-05 + -7.000e-07 = 2.730e-05 - Mg 2.900e-05 + 0.000e+00 = 2.900e-05 - Na 1.340e-04 + 0.000e+00 = 1.340e-04 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 1.000e-05 + 0.000e+00 = 1.000e-05 - Si 2.730e-04 + 0.000e+00 = 2.730e-04 - -Solution 2: - - Input Delta Input+Delta - pH 6.800e+00 + -3.407e-03 = 6.797e+00 - Al 0.000e+00 + 0.000e+00 = 0.000e+00 - Alkalinity 8.951e-04 + -1.796e-06 = 8.933e-04 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 1.199e-03 + 0.000e+00 = 1.199e-03 - Ca 2.600e-04 + 6.501e-06 = 2.665e-04 - Cl 3.000e-05 + 0.000e+00 = 3.000e-05 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 4.000e-05 + 1.000e-06 = 4.100e-05 - Mg 7.101e-05 + -8.979e-07 = 7.011e-05 - Na 2.590e-04 + 0.000e+00 = 2.590e-04 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 2.500e-05 + 0.000e+00 = 2.500e-05 - Si 4.100e-04 + 0.000e+00 = 4.100e-04 - -Solution fractions: Minimum Maximum - Solution 1 1.000e+00 1.000e+00 1.000e+00 - Solution 2 1.000e+00 1.000e+00 1.000e+00 - -Phase mole transfers: Minimum Maximum - Halite 1.600e-05 1.490e-05 1.710e-05 NaCl - Gypsum 1.500e-05 1.413e-05 1.588e-05 CaSO4:2H2O - Kaolinite -3.392e-05 -5.587e-05 -1.224e-05 Al2Si2O5(OH)4 -Ca-Montmorillon -8.090e-05 -1.100e-04 -5.154e-05 Ca0.165Al2.33Si3.67O10(OH)2 - CO2(g) 2.928e-04 2.363e-04 3.563e-04 CO2 - Calcite 1.240e-04 1.007e-04 1.309e-04 CaCO3 - Biotite 1.370e-05 1.317e-05 1.370e-05 KMg3AlSi3O10(OH)2 - Plagioclase 1.758e-04 1.582e-04 1.935e-04 Na0.62Ca0.38Al1.38Si2.62O8 - -Redox mole transfers: - -Sum of residuals (epsilons in documentation): 5.574e+00 -Sum of delta/uncertainty limit: 5.574e+00 -Maximum fractional error in element concentration: 5.000e-02 - -Model contains minimum number of phases. -=============================================================================== - - -Solution 1: - - Input Delta Input+Delta - pH 6.200e+00 + 1.246e-02 = 6.212e+00 - Al 0.000e+00 + 0.000e+00 = 0.000e+00 - Alkalinity 3.280e-04 + 5.500e-06 = 3.335e-04 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 7.825e-04 + 0.000e+00 = 7.825e-04 - Ca 7.800e-05 + -3.900e-06 = 7.410e-05 - Cl 1.400e-05 + 0.000e+00 = 1.400e-05 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 2.800e-05 + -7.000e-07 = 2.730e-05 - Mg 2.900e-05 + 0.000e+00 = 2.900e-05 - Na 1.340e-04 + 0.000e+00 = 1.340e-04 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 1.000e-05 + 0.000e+00 = 1.000e-05 - Si 2.730e-04 + 0.000e+00 = 2.730e-04 - -Solution 2: - - Input Delta Input+Delta - pH 6.800e+00 + -3.407e-03 = 6.797e+00 - Al 0.000e+00 + 0.000e+00 = 0.000e+00 - Alkalinity 8.951e-04 + -1.796e-06 = 8.933e-04 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 1.199e-03 + 0.000e+00 = 1.199e-03 - Ca 2.600e-04 + 6.501e-06 = 2.665e-04 - Cl 3.000e-05 + 0.000e+00 = 3.000e-05 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 4.000e-05 + 1.000e-06 = 4.100e-05 - Mg 7.101e-05 + -8.980e-07 = 7.011e-05 - Na 2.590e-04 + 0.000e+00 = 2.590e-04 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 2.500e-05 + 0.000e+00 = 2.500e-05 - Si 4.100e-04 + 0.000e+00 = 4.100e-04 - -Solution fractions: Minimum Maximum - Solution 1 1.000e+00 1.000e+00 1.000e+00 - Solution 2 1.000e+00 1.000e+00 1.000e+00 - -Phase mole transfers: Minimum Maximum - Halite 1.600e-05 1.490e-05 1.710e-05 NaCl - Gypsum 1.500e-05 1.413e-05 1.588e-05 CaSO4:2H2O - Kaolinite -1.282e-04 -1.403e-04 -1.159e-04 Al2Si2O5(OH)4 - CO2(g) 3.061e-04 2.490e-04 3.703e-04 CO2 - Calcite 1.106e-04 8.680e-05 1.182e-04 CaCO3 - Chalcedony -1.084e-04 -1.473e-04 -6.906e-05 SiO2 - Biotite 1.370e-05 1.317e-05 1.370e-05 KMg3AlSi3O10(OH)2 - Plagioclase 1.758e-04 1.582e-04 1.935e-04 Na0.62Ca0.38Al1.38Si2.62O8 - -Redox mole transfers: - -Sum of residuals (epsilons in documentation): 5.574e+00 -Sum of delta/uncertainty limit: 5.574e+00 -Maximum fractional error in element concentration: 5.000e-02 - -Model contains minimum number of phases. -=============================================================================== - - -Summary of inverse modeling: - - Number of models found: 2 - Number of minimal models found: 2 - Number of infeasible sets of phases saved: 20 - Number of calls to cl1: 62 ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex17.log b/Sun/examples/ex17.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex17.out b/Sun/examples/ex17.out deleted file mode 100644 index 857c94be..00000000 --- a/Sun/examples/ex17.out +++ /dev/null @@ -1,349 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex17 - Output file: ex17.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 17.--Inverse modeling of Black Sea water evaporation - SOLUTION 1 Black Sea water - units mg/L - density 1.014 - pH 8.0 # estimated - Ca 233 - Mg 679 - Na 5820 - K 193 - S(6) 1460 - Cl 10340 - Br 35 - C 1 CO2(g) -3.5 - SOLUTION 2 Composition during halite precipitation - units mg/L - density 1.271 - pH 5.0 # estimated - Ca 0.0 - Mg 50500 - Na 55200 - K 15800 - S(6) 76200 - Cl 187900 - Br 2670 - C 1 CO2(g) -3.5 - INVERSE_MODELING - solutions 1 2 - uncertainties .025 - range - balances - Br - K - Mg - phases - H2O(g) pre - Calcite pre - CO2(g) pre - Gypsum pre - Halite pre - END ------ -TITLE ------ - - Example 17.--Inverse modeling of Black Sea water evaporation - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Black Sea water - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Br 4.401e-04 4.401e-04 - C 8.284e-04 8.284e-04 Equilibrium with CO2(g) - Ca 5.841e-03 5.841e-03 - Cl 2.930e-01 2.930e-01 - K 4.959e-03 4.959e-03 - Mg 2.806e-02 2.806e-02 - Na 2.544e-01 2.544e-01 - S(6) 1.527e-02 1.527e-02 - -----------------------------Description of solution---------------------------- - - pH = 8.000 - pe = 4.000 - Activity of water = 0.990 - Ionic strength = 3.540e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.625e-04 - Total CO2 (mol/kg) = 8.284e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.240e-03 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.36 - Iterations = 5 - Total H = 1.110132e+02 - Total O = 5.556978e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.500e-06 9.909e-07 -5.824 -6.004 -0.180 - H+ 1.288e-08 1.000e-08 -7.890 -8.000 -0.110 - H2O 5.551e+01 9.899e-01 1.744 -0.004 0.000 -Br 4.401e-04 - Br- 4.401e-04 2.835e-04 -3.356 -3.547 -0.191 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -76.604 -76.569 0.035 -C(4) 8.284e-04 - HCO3- 6.657e-04 4.740e-04 -3.177 -3.324 -0.147 - MgHCO3+ 5.725e-05 4.187e-05 -4.242 -4.378 -0.136 - NaHCO3 4.444e-05 4.822e-05 -4.352 -4.317 0.035 - MgCO3 1.476e-05 1.601e-05 -4.831 -4.796 0.035 - CaHCO3+ 1.247e-05 8.879e-06 -4.904 -5.052 -0.147 - NaCO3- 1.024e-05 7.488e-06 -4.990 -5.126 -0.136 - CO2 9.923e-06 1.077e-05 -5.003 -4.968 0.035 - CO3-2 8.646e-06 2.223e-06 -5.063 -5.653 -0.590 - CaCO3 5.053e-06 5.483e-06 -5.296 -5.261 0.035 -Ca 5.841e-03 - Ca+2 5.267e-03 1.468e-03 -2.278 -2.833 -0.555 - CaSO4 5.563e-04 6.035e-04 -3.255 -3.219 0.035 - CaHCO3+ 1.247e-05 8.879e-06 -4.904 -5.052 -0.147 - CaCO3 5.053e-06 5.483e-06 -5.296 -5.261 0.035 - CaOH+ 3.298e-08 2.412e-08 -7.482 -7.618 -0.136 - CaHSO4+ 4.835e-11 3.536e-11 -10.316 -10.452 -0.136 -Cl 2.930e-01 - Cl- 2.930e-01 1.960e-01 -0.533 -0.708 -0.175 -H(0) 1.305e-27 - H2 6.525e-28 7.079e-28 -27.185 -27.150 0.035 -K 4.959e-03 - K+ 4.895e-03 3.274e-03 -2.310 -2.485 -0.175 - KSO4- 6.480e-05 4.739e-05 -4.188 -4.324 -0.136 - KOH 1.036e-09 1.124e-09 -8.985 -8.949 0.035 -Mg 2.806e-02 - Mg+2 2.463e-02 7.549e-03 -1.609 -2.122 -0.514 - MgSO4 3.360e-03 3.646e-03 -2.474 -2.438 0.035 - MgHCO3+ 5.725e-05 4.187e-05 -4.242 -4.378 -0.136 - MgCO3 1.476e-05 1.601e-05 -4.831 -4.796 0.035 - MgOH+ 3.710e-06 2.713e-06 -5.431 -5.567 -0.136 -Na 2.544e-01 - Na+ 2.518e-01 1.809e-01 -0.599 -0.743 -0.144 - NaSO4- 2.554e-03 1.868e-03 -2.593 -2.729 -0.136 - NaHCO3 4.444e-05 4.822e-05 -4.352 -4.317 0.035 - NaCO3- 1.024e-05 7.488e-06 -4.990 -5.126 -0.136 - NaOH 1.090e-07 1.183e-07 -6.962 -6.927 0.035 -O(0) 1.502e-38 - O2 7.512e-39 8.150e-39 -38.124 -38.089 0.035 -S(6) 1.527e-02 - SO4-2 8.735e-03 2.060e-03 -2.059 -2.686 -0.627 - MgSO4 3.360e-03 3.646e-03 -2.474 -2.438 0.035 - NaSO4- 2.554e-03 1.868e-03 -2.593 -2.729 -0.136 - CaSO4 5.563e-04 6.035e-04 -3.255 -3.219 0.035 - KSO4- 6.480e-05 4.739e-05 -4.188 -4.324 -0.136 - HSO4- 2.739e-09 2.003e-09 -8.562 -8.698 -0.136 - CaHSO4+ 4.835e-11 3.536e-11 -10.316 -10.452 -0.136 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -1.16 -5.52 -4.36 CaSO4 - Aragonite -0.15 -8.49 -8.34 CaCO3 - Calcite -0.01 -8.49 -8.48 CaCO3 - CH4(g) -73.71 -76.57 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Dolomite 0.83 -16.26 -17.09 CaMg(CO3)2 - Gypsum -0.95 -5.53 -4.58 CaSO4:2H2O - H2(g) -24.00 -27.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -3.03 -1.45 1.58 NaCl - O2(g) -35.13 -38.09 -2.96 O2 - -Initial solution 2. Composition during halite precipitation - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Br 3.785e-02 3.785e-02 - C 7.019e-06 7.019e-06 Equilibrium with CO2(g) - Cl 6.004e+00 6.004e+00 - K 4.578e-01 4.578e-01 - Mg 2.353e+00 2.353e+00 - Na 2.720e+00 2.720e+00 - S(6) 8.986e-01 8.986e-01 - -----------------------------Description of solution---------------------------- - - pH = 5.000 - pe = 4.000 - Activity of water = 0.802 - Ionic strength = 7.827e+00 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -9.195e-06 - Total CO2 (mol/kg) = 7.019e-06 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 4.491e-02 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.36 - Iterations = 10 - Total H = 1.110125e+02 - Total O = 5.910064e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.425e-05 1.000e-05 -4.846 -5.000 -0.154 - OH- 1.749e-09 8.029e-10 -8.757 -9.095 -0.338 - H2O 5.551e+01 8.021e-01 1.744 -0.096 0.000 -Br 3.785e-02 - Br- 3.785e-02 1.580e-02 -1.422 -1.801 -0.379 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -53.169 -52.386 0.783 -C(4) 7.019e-06 - MgHCO3+ 4.391e-06 2.905e-05 -5.357 -4.537 0.821 - CO2 1.776e-06 1.077e-05 -5.751 -4.968 0.783 - HCO3- 6.660e-07 3.841e-07 -6.177 -6.416 -0.239 - NaHCO3 1.847e-07 1.120e-06 -6.734 -5.951 0.783 - MgCO3 1.833e-09 1.111e-08 -8.737 -7.954 0.783 - NaCO3- 2.628e-11 1.739e-10 -10.580 -9.760 0.821 - CO3-2 1.629e-11 1.801e-12 -10.788 -11.744 -0.956 -Cl 6.004e+00 - Cl- 6.004e+00 3.612e+00 0.778 0.558 -0.221 -H(0) 2.335e-22 - H2 1.168e-22 7.079e-22 -21.933 -21.150 0.783 -K 4.578e-01 - K+ 4.568e-01 2.748e-01 -0.340 -0.561 -0.221 - KSO4- 9.513e-04 6.294e-03 -3.022 -2.201 0.821 - KOH 1.261e-11 7.643e-11 -10.899 -10.117 0.783 -Mg 2.353e+00 - Mg+2 1.538e+00 6.465e+00 0.187 0.811 0.624 - MgSO4 8.148e-01 4.940e+00 -0.089 0.694 0.783 - MgHCO3+ 4.391e-06 2.905e-05 -5.357 -4.537 0.821 - MgOH+ 2.845e-07 1.883e-06 -6.546 -5.725 0.821 - MgCO3 1.833e-09 1.111e-08 -8.737 -7.954 0.783 -Na 2.720e+00 - Na+ 2.707e+00 5.184e+00 0.433 0.715 0.282 - NaSO4- 1.280e-02 8.469e-02 -1.893 -1.072 0.821 - NaHCO3 1.847e-07 1.120e-06 -6.734 -5.951 0.783 - NaOH 4.531e-10 2.747e-09 -9.344 -8.561 0.783 - NaCO3- 2.628e-11 1.739e-10 -10.580 -9.760 0.821 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -51.054 -50.272 0.783 -S(6) 8.986e-01 - MgSO4 8.148e-01 4.940e+00 -0.089 0.694 0.783 - SO4-2 7.004e-02 3.259e-03 -1.155 -2.487 -1.332 - NaSO4- 1.280e-02 8.469e-02 -1.893 -1.072 0.821 - KSO4- 9.513e-04 6.294e-03 -3.022 -2.201 0.821 - HSO4- 4.789e-07 3.169e-06 -6.320 -5.499 0.821 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - CH4(g) -49.53 -52.39 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - H2(g) -18.00 -21.15 -3.15 H2 - H2O(g) -1.61 -0.10 1.51 H2O - Halite -0.31 1.27 1.58 NaCl - O2(g) -47.31 -50.27 -2.96 O2 - -------------------------------------------- -Beginning of inverse modeling calculations. -------------------------------------------- - - -Solution 1: Black Sea water - - Input Delta Input+Delta - pH 8.000e+00 + 0.000e+00 = 8.000e+00 - Alkalinity 8.625e-04 + 0.000e+00 = 8.625e-04 - Br 4.401e-04 + 0.000e+00 = 4.401e-04 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 8.284e-04 + 0.000e+00 = 8.284e-04 - Ca 5.841e-03 + 0.000e+00 = 5.841e-03 - Cl 2.930e-01 + 7.845e-04 = 2.938e-01 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 4.959e-03 + 1.034e-04 = 5.063e-03 - Mg 2.806e-02 + -7.016e-04 = 2.736e-02 - Na 2.544e-01 + 0.000e+00 = 2.544e-01 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 1.527e-02 + 7.768e-05 = 1.535e-02 - -Solution 2: Composition during halite precipitation - - Input Delta Input+Delta - pH 5.000e+00 + 5.711e-14 = 5.000e+00 - Alkalinity -9.195e-06 + 0.000e+00 = -9.195e-06 - Br 3.785e-02 + 9.440e-04 = 3.880e-02 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 7.019e-06 + 0.000e+00 = 7.019e-06 - Ca 0.000e+00 + 0.000e+00 = 0.000e+00 - Cl 6.004e+00 + 1.501e-01 = 6.154e+00 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 4.578e-01 + -1.144e-02 = 4.463e-01 - Mg 2.353e+00 + 5.883e-02 = 2.412e+00 - Na 2.720e+00 + -4.500e-02 = 2.675e+00 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 8.986e-01 + -2.247e-02 = 8.761e-01 - -Solution fractions: Minimum Maximum - Solution 1 8.815e+01 8.780e+01 8.815e+01 - Solution 2 1.000e+00 1.000e+00 1.000e+00 - -Phase mole transfers: Minimum Maximum - H2O(g) -4.837e+03 -4.817e+03 -4.817e+03 H2O - Calcite -3.802e-02 -3.897e-02 -3.692e-02 CaCO3 - CO2(g) -3.500e-02 -3.615e-02 -3.371e-02 CO2 - Gypsum -4.769e-01 -4.907e-01 -4.612e-01 CaSO4:2H2O - Halite -1.975e+01 -2.033e+01 -1.901e+01 NaCl - -Redox mole transfers: - -Sum of residuals (epsilons in documentation): 1.947e+02 -Sum of delta/uncertainty limit: 7.804e+00 -Maximum fractional error in element concentration: 2.500e-02 - -Model contains minimum number of phases. -=============================================================================== - - -Summary of inverse modeling: - - Number of models found: 1 - Number of minimal models found: 1 - Number of infeasible sets of phases saved: 6 - Number of calls to cl1: 22 ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex18.log b/Sun/examples/ex18.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex18.out b/Sun/examples/ex18.out deleted file mode 100644 index 106cdf99..00000000 --- a/Sun/examples/ex18.out +++ /dev/null @@ -1,550 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex18 - Output file: ex18.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 18.--Inverse modeling of Madison aquifer - SOLUTION 1 Recharge number 3 - units mmol/kgw - temp 9.9 - pe 0. - pH 7.55 - Ca 1.2 - Mg 1.01 - Na 0.02 - K 0.02 - Fe(2) 0.001 - Cl 0.02 - S(6) 0.16 - S(-2) 0 - C(4) 4.30 - isotope 13C -7.0 1.4 - isotope 34S 9.7 0.9 - SOLUTION 2 Mysse - units mmol/kgw - temp 63. - pH 6.61 - pe 0. - redox S(6)/S(-2) - Ca 11.28 - Mg 4.54 - Na 31.89 - K 2.54 - Fe(2) 0.0004 - Cl 17.85 - S(6) 19.86 - S(-2) 0.26 - C(4) 6.87 - isotope 13C -2.3 0.2 - isotope 34S(6) 16.3 1.5 - isotope 34S(-2) -22.1 7 - INVERSE_MODELING 1 - solutions 1 2 - uncertainty 0.05 - range - isotopes - 13C - 34S - balances - Fe(2) 1.0 - ph 0.1 - phases - Dolomite dis 13C 3.0 2 - Calcite pre 13C -1.5 1 - Anhydrite dis 34S 13.5 2 - CH2O dis 13C -25.0 5 - Goethite - Pyrite pre 34S -22. 2 - CaX2 pre - Ca.75Mg.25X2 pre - MgX2 pre - NaX - Halite - Sylvite - PHASES - Sylvite - KCl = K+ + Cl- - log_k 0.0 - CH2O - CH2O + H2O = CO2 + 4H+ + 4e- - log_k 0.0 - EXCHANGE_SPECIES - 0.75Ca+2 + 0.25Mg+2 + 2X- = Ca.75Mg.25X2 - log_k 0.0 - END ------ -TITLE ------ - - Example 18.--Inverse modeling of Madison aquifer - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Recharge number 3 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C(4) 4.300e-03 4.300e-03 - Ca 1.200e-03 1.200e-03 - Cl 2.000e-05 2.000e-05 - Fe(2) 1.000e-06 1.000e-06 - K 2.000e-05 2.000e-05 - Mg 1.010e-03 1.010e-03 - Na 2.000e-05 2.000e-05 - S(6) 1.600e-04 1.600e-04 - -----------------------------Description of solution---------------------------- - - pH = 7.550 - pe = 0.000 - Activity of water = 1.000 - Ionic strength = 6.543e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.016e-03 - Total CO2 (mol/kg) = 4.300e-03 - Temperature (deg C) = 9.900 - Electrical balance (eq) = 1.061e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 1.24 - Iterations = 8 - Total H = 1.110164e+02 - Total O = 5.551946e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.120e-07 1.029e-07 -6.951 -6.988 -0.037 - H+ 3.038e-08 2.818e-08 -7.517 -7.550 -0.033 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(4) 4.300e-03 - HCO3- 3.929e-03 3.623e-03 -2.406 -2.441 -0.035 - CO2 2.970e-04 2.974e-04 -3.527 -3.527 0.001 - MgHCO3+ 3.098e-05 2.850e-05 -4.509 -4.545 -0.036 - CaHCO3+ 3.027e-05 2.792e-05 -4.519 -4.554 -0.035 - CO3-2 5.765e-06 4.168e-06 -5.239 -5.380 -0.141 - CaCO3 4.727e-06 4.734e-06 -5.325 -5.325 0.001 - MgCO3 2.208e-06 2.211e-06 -5.656 -5.655 0.001 - FeHCO3+ 2.086e-07 1.919e-07 -6.681 -6.717 -0.036 - FeCO3 5.289e-08 5.297e-08 -7.277 -7.276 0.001 - NaHCO3 3.737e-08 3.742e-08 -7.428 -7.427 0.001 - NaCO3- 6.948e-10 6.391e-10 -9.158 -9.194 -0.036 -Ca 1.200e-03 - Ca+2 1.151e-03 8.317e-04 -2.939 -3.080 -0.141 - CaHCO3+ 3.027e-05 2.792e-05 -4.519 -4.554 -0.035 - CaSO4 1.393e-05 1.395e-05 -4.856 -4.855 0.001 - CaCO3 4.727e-06 4.734e-06 -5.325 -5.325 0.001 - CaOH+ 5.323e-09 4.897e-09 -8.274 -8.310 -0.036 - CaHSO4+ 2.136e-12 1.965e-12 -11.670 -11.707 -0.036 -Cl 2.000e-05 - Cl- 2.000e-05 1.838e-05 -4.699 -4.736 -0.037 - FeCl+ 1.461e-11 1.344e-11 -10.835 -10.872 -0.036 -Fe(2) 1.000e-06 - Fe+2 7.296e-07 5.298e-07 -6.137 -6.276 -0.139 - FeHCO3+ 2.086e-07 1.919e-07 -6.681 -6.717 -0.036 - FeCO3 5.289e-08 5.297e-08 -7.277 -7.276 0.001 - FeSO4 6.861e-09 6.871e-09 -8.164 -8.163 0.001 - FeOH+ 1.969e-09 1.811e-09 -8.706 -8.742 -0.036 - FeCl+ 1.461e-11 1.344e-11 -10.835 -10.872 -0.036 - FeHSO4+ 1.361e-15 1.252e-15 -14.866 -14.903 -0.036 -H(0) 1.316e-18 - H2 6.579e-19 6.588e-19 -18.182 -18.181 0.001 -K 2.000e-05 - K+ 1.999e-05 1.837e-05 -4.699 -4.736 -0.037 - KSO4- 1.037e-08 9.538e-09 -7.984 -8.021 -0.036 - KOH 2.256e-12 2.260e-12 -11.647 -11.646 0.001 -Mg 1.010e-03 - Mg+2 9.662e-04 7.011e-04 -3.015 -3.154 -0.139 - MgHCO3+ 3.098e-05 2.850e-05 -4.509 -4.545 -0.036 - MgSO4 1.063e-05 1.064e-05 -4.974 -4.973 0.001 - MgCO3 2.208e-06 2.211e-06 -5.656 -5.655 0.001 - MgOH+ 2.335e-08 2.148e-08 -7.632 -7.668 -0.036 -Na 2.000e-05 - Na+ 1.995e-05 1.837e-05 -4.700 -4.736 -0.036 - NaHCO3 3.737e-08 3.742e-08 -7.428 -7.427 0.001 - NaSO4- 8.826e-09 8.119e-09 -8.054 -8.090 -0.036 - NaCO3- 6.948e-10 6.391e-10 -9.158 -9.194 -0.036 - NaOH 4.299e-12 4.306e-12 -11.367 -11.366 0.001 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -61.151 -61.151 0.001 -S(6) 1.600e-04 - SO4-2 1.354e-04 9.754e-05 -3.868 -4.011 -0.142 - CaSO4 1.393e-05 1.395e-05 -4.856 -4.855 0.001 - MgSO4 1.063e-05 1.064e-05 -4.974 -4.973 0.001 - KSO4- 1.037e-08 9.538e-09 -7.984 -8.021 -0.036 - NaSO4- 8.826e-09 8.119e-09 -8.054 -8.090 -0.036 - FeSO4 6.861e-09 6.871e-09 -8.164 -8.163 0.001 - HSO4- 2.136e-10 1.965e-10 -9.670 -9.707 -0.036 - CaHSO4+ 2.136e-12 1.965e-12 -11.670 -11.707 -0.036 - FeHSO4+ 1.361e-15 1.252e-15 -14.866 -14.903 -0.036 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.76 -7.09 -4.34 CaSO4 - Aragonite -0.21 -8.46 -8.25 CaCO3 - Calcite -0.05 -8.46 -8.41 CaCO3 - CH2O -33.73 -33.73 0.00 CH2O - CO2(g) -2.26 -3.53 -1.27 CO2 - Dolomite -0.27 -16.99 -16.72 CaMg(CO3)2 - Gypsum -2.50 -7.09 -4.59 CaSO4:2H2O - H2(g) -15.10 -18.18 -3.08 H2 - H2O(g) -1.92 -0.00 1.92 H2O - Halite -11.02 -9.47 1.55 NaCl - Melanterite -7.88 -10.29 -2.41 FeSO4:7H2O - O2(g) -58.26 -61.15 -2.89 O2 - Siderite -0.86 -11.66 -10.79 FeCO3 - Sylvite -9.47 -9.47 0.00 KCl - -Initial solution 2. Mysse - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C(4) 6.870e-03 6.870e-03 - Ca 1.128e-02 1.128e-02 - Cl 1.785e-02 1.785e-02 - Fe(2) 4.000e-07 4.000e-07 - K 2.540e-03 2.540e-03 - Mg 4.540e-03 4.540e-03 - Na 3.189e-02 3.189e-02 - S(-2) 2.600e-04 2.600e-04 - S(6) 1.986e-02 1.986e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.610 - pe = 0.000 - Activity of water = 0.999 - Ionic strength = 7.256e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.258e-03 - Total CO2 (mol/kg) = 6.870e-03 - Temperature (deg C) = 63.000 - Electrical balance (eq) = 3.242e-03 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 3.20 - Iterations = 8 - Total H = 1.110179e+02 - Total O = 5.560448e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - S(-2)/S(6) -3.6487 -0.2434 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.726e-07 4.419e-07 -6.242 -6.355 -0.112 - H+ 2.963e-07 2.455e-07 -6.528 -6.610 -0.082 - H2O 5.551e+01 9.985e-01 1.744 -0.001 0.000 -C(4) 6.870e-03 - HCO3- 4.711e-03 3.746e-03 -2.327 -2.426 -0.100 - CO2 1.784e-03 1.814e-03 -2.749 -2.741 0.007 - CaHCO3+ 2.347e-04 1.867e-04 -3.629 -3.729 -0.100 - MgHCO3+ 6.578e-05 5.169e-05 -4.182 -4.287 -0.105 - NaHCO3 5.046e-05 5.131e-05 -4.297 -4.290 0.007 - CaCO3 1.560e-05 1.586e-05 -4.807 -4.800 0.007 - NaCO3- 3.512e-06 2.760e-06 -5.454 -5.559 -0.105 - CO3-2 2.780e-06 1.112e-06 -5.556 -5.954 -0.398 - MgCO3 1.642e-06 1.670e-06 -5.784 -5.777 0.007 - FeHCO3+ 1.177e-08 9.248e-09 -7.929 -8.034 -0.105 - FeCO3 6.474e-10 6.583e-10 -9.189 -9.182 0.007 -Ca 1.128e-02 - Ca+2 7.217e-03 2.899e-03 -2.142 -2.538 -0.396 - CaSO4 3.813e-03 3.877e-03 -2.419 -2.411 0.007 - CaHCO3+ 2.347e-04 1.867e-04 -3.629 -3.729 -0.100 - CaCO3 1.560e-05 1.586e-05 -4.807 -4.800 0.007 - CaHSO4+ 1.322e-08 1.039e-08 -7.879 -7.983 -0.105 - CaOH+ 2.491e-09 1.957e-09 -8.604 -8.708 -0.105 -Cl 1.785e-02 - Cl- 1.785e-02 1.381e-02 -1.748 -1.860 -0.111 - FeCl+ 5.988e-10 4.706e-10 -9.223 -9.327 -0.105 -Fe(2) 4.000e-07 - Fe(HS)2 2.830e-07 2.878e-07 -6.548 -6.541 0.007 - Fe+2 5.978e-08 2.468e-08 -7.223 -7.608 -0.384 - FeSO4 3.911e-08 3.977e-08 -7.408 -7.400 0.007 - FeHCO3+ 1.177e-08 9.248e-09 -7.929 -8.034 -0.105 - Fe(HS)3- 4.561e-09 3.585e-09 -8.341 -8.446 -0.105 - FeCO3 6.474e-10 6.583e-10 -9.189 -9.182 0.007 - FeCl+ 5.988e-10 4.706e-10 -9.223 -9.327 -0.105 - FeOH+ 5.014e-10 3.940e-10 -9.300 -9.404 -0.105 - FeHSO4+ 1.125e-13 8.843e-14 -12.949 -13.053 -0.105 -H(0) 1.190e-09 - H2 5.948e-10 6.048e-10 -9.226 -9.218 0.007 -K 2.540e-03 - K+ 2.394e-03 1.852e-03 -2.621 -2.732 -0.111 - KSO4- 1.459e-04 1.146e-04 -3.836 -3.941 -0.105 - KOH 2.569e-11 2.613e-11 -10.590 -10.583 0.007 -Mg 4.540e-03 - MgSO4 2.360e-03 2.399e-03 -2.627 -2.620 0.007 - Mg+2 2.113e-03 8.783e-04 -2.675 -3.056 -0.381 - MgHCO3+ 6.578e-05 5.169e-05 -4.182 -4.287 -0.105 - MgCO3 1.642e-06 1.670e-06 -5.784 -5.777 0.007 - MgOH+ 3.463e-07 2.721e-07 -6.461 -6.565 -0.105 -Na 3.189e-02 - Na+ 3.090e-02 2.435e-02 -1.510 -1.613 -0.103 - NaSO4- 9.408e-04 7.393e-04 -3.027 -3.131 -0.105 - NaHCO3 5.046e-05 5.131e-05 -4.297 -4.290 0.007 - NaCO3- 3.512e-06 2.760e-06 -5.454 -5.559 -0.105 - NaOH 6.437e-10 6.545e-10 -9.191 -9.184 0.007 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -63.075 -63.067 0.007 -S(-2) 2.600e-04 - HS- 1.482e-04 1.144e-04 -3.829 -3.942 -0.112 - H2S 1.112e-04 1.131e-04 -3.954 -3.947 0.007 - Fe(HS)2 2.830e-07 2.878e-07 -6.548 -6.541 0.007 - Fe(HS)3- 4.561e-09 3.585e-09 -8.341 -8.446 -0.105 - S-2 1.449e-09 5.662e-10 -8.839 -9.247 -0.408 -S(6) 1.986e-02 - SO4-2 1.260e-02 4.892e-03 -1.900 -2.311 -0.411 - CaSO4 3.813e-03 3.877e-03 -2.419 -2.411 0.007 - MgSO4 2.360e-03 2.399e-03 -2.627 -2.620 0.007 - NaSO4- 9.408e-04 7.393e-04 -3.027 -3.131 -0.105 - KSO4- 1.459e-04 1.146e-04 -3.836 -3.941 -0.105 - HSO4- 3.792e-07 2.980e-07 -6.421 -6.526 -0.105 - FeSO4 3.911e-08 3.977e-08 -7.408 -7.400 0.007 - CaHSO4+ 1.322e-08 1.039e-08 -7.879 -7.983 -0.105 - FeHSO4+ 1.125e-13 8.843e-14 -12.949 -13.053 -0.105 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.14 -4.85 -4.71 CaSO4 - Aragonite 0.18 -8.49 -8.67 CaCO3 - Calcite 0.30 -8.49 -8.79 CaCO3 - CH2O -14.59 -14.59 0.00 CH2O - CO2(g) -0.94 -2.74 -1.80 CO2 - Dolomite 0.37 -17.50 -17.87 CaMg(CO3)2 - FeS(ppt) -1.02 -4.94 -3.92 FeS - Gypsum -0.18 -4.85 -4.67 CaSO4:2H2O - H2(g) -5.92 -9.22 -3.30 H2 - H2O(g) -0.64 -0.00 0.64 H2O - H2S(g) -2.57 -3.95 -1.38 H2S - Halite -5.13 -3.47 1.66 NaCl - Mackinawite -0.29 -4.94 -4.65 FeS - Melanterite -8.07 -9.92 -1.85 FeSO4:7H2O - O2(g) -59.95 -63.07 -3.11 O2 - Pyrite 7.97 -9.57 -17.54 FeS2 - Siderite -2.47 -13.56 -11.10 FeCO3 - Sulfur -2.12 1.98 4.09 S - Sylvite -4.59 -4.59 0.00 KCl - -------------------------------------------- -Beginning of inverse modeling calculations. -------------------------------------------- - - -Solution 1: Recharge number 3 - - Input Delta Input+Delta - pH 7.550e+00 + 0.000e+00 = 7.550e+00 - Alkalinity 4.016e-03 + 0.000e+00 = 4.016e-03 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 4.300e-03 + 0.000e+00 = 4.300e-03 - Ca 1.200e-03 + -5.306e-05 = 1.147e-03 - Cl 2.000e-05 + 0.000e+00 = 2.000e-05 - Fe(2) 1.000e-06 + 0.000e+00 = 1.000e-06 - Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 2.000e-05 + 0.000e+00 = 2.000e-05 - Mg 1.010e-03 + 0.000e+00 = 1.010e-03 - Na 2.000e-05 + 0.000e+00 = 2.000e-05 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 1.600e-04 + 0.000e+00 = 1.600e-04 - X 0.000e+00 + 0.000e+00 = 0.000e+00 - 13C(-4) -7 + 0 = -7 - 13C(4) -7 + 0 = -7 - 34S(-2) 9.7 + 0 = 9.7 - 34S(6) 9.7 + 0 = 9.7 - -Solution 2: Mysse - - Input Delta Input+Delta - pH 6.610e+00 + 0.000e+00 = 6.610e+00 - Alkalinity 5.258e-03 + 0.000e+00 = 5.258e-03 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 6.870e-03 + 0.000e+00 = 6.870e-03 - Ca 1.128e-02 + 0.000e+00 = 1.128e-02 - Cl 1.785e-02 + 0.000e+00 = 1.785e-02 - Fe(2) 4.000e-07 + 0.000e+00 = 4.000e-07 - Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 - H(0) 1.190e-09 + 0.000e+00 = 1.190e-09 - K 2.540e-03 + 0.000e+00 = 2.540e-03 - Mg 4.540e-03 + 0.000e+00 = 4.540e-03 - Na 3.189e-02 + -1.256e-03 = 3.063e-02 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 2.600e-04 + 0.000e+00 = 2.600e-04 - S(6) 1.986e-02 + 9.930e-04 = 2.085e-02 - X 0.000e+00 + 0.000e+00 = 0.000e+00 - 13C(-4) -2.3 + 0 = -2.3 - 13C(4) -2.3 + 0 = -2.3 - 34S(-2) -22.1 + 0 = -22.1 - 34S(6) 16.3 + 0 = 16.3 - -Isotopic composition of phases: - 13C Dolomite 3 + 0 = 3 - 13C Calcite -1.5 + 0 = -1.5 - 34S Anhydrite 13.5 + -0.65116 = 12.8488 - 13C CH2O -25 + 3.56577 = -21.4342 - 34S Pyrite -22 + 2 = -20 - -Solution fractions: Minimum Maximum - Solution 1 1.000e+00 9.999e-01 1.000e+00 - Solution 2 1.000e+00 1.000e+00 1.000e+00 - -Phase mole transfers: Minimum Maximum - Dolomite 1.118e-02 1.022e-02 1.193e-02 CaMg(CO3)2 - Calcite -2.393e-02 -2.567e-02 -2.144e-02 CaCO3 - Anhydrite 2.288e-02 2.076e-02 2.348e-02 CaSO4 - CH2O 4.138e-03 3.003e-03 5.273e-03 CH2O - Goethite 9.642e-04 6.533e-04 1.275e-03 FeOOH - Pyrite -9.648e-04 -1.274e-03 -6.553e-04 FeS2 - MgX2 -7.652e-03 -8.576e-03 -6.972e-03 MgX2 - NaX 1.530e-02 1.394e-02 1.715e-02 NaX - Halite 1.531e-02 1.429e-02 1.633e-02 NaCl - Sylvite 2.520e-03 2.392e-03 2.648e-03 KCl - -Redox mole transfers: - Fe(3) 9.642e-04 - H(0) -1.190e-09 - S(-2) -2.190e-03 - -Sum of residuals (epsilons in documentation): 2.684e+00 -Sum of delta/uncertainty limit: 4.711e+00 -Maximum fractional error in element concentration: 5.000e-02 - -Model contains minimum number of phases. -=============================================================================== - - -Solution 1: Recharge number 3 - - Input Delta Input+Delta - pH 7.550e+00 + 0.000e+00 = 7.550e+00 - Alkalinity 4.016e-03 + 1.061e-04 = 4.122e-03 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 4.300e-03 + 1.136e-04 = 4.414e-03 - Ca 1.200e-03 + 0.000e+00 = 1.200e-03 - Cl 2.000e-05 + 0.000e+00 = 2.000e-05 - Fe(2) 1.000e-06 + 0.000e+00 = 1.000e-06 - Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 - H(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - K 2.000e-05 + 0.000e+00 = 2.000e-05 - Mg 1.010e-03 + 0.000e+00 = 1.010e-03 - Na 2.000e-05 + 0.000e+00 = 2.000e-05 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(6) 1.600e-04 + 0.000e+00 = 1.600e-04 - X 0.000e+00 + 0.000e+00 = 0.000e+00 - 13C(-4) -7 + 0 = -7 - 13C(4) -7 + 0 = -7 - 34S(-2) 9.7 + 0 = 9.7 - 34S(6) 9.7 + 0 = 9.7 - -Solution 2: Mysse - - Input Delta Input+Delta - pH 6.610e+00 + 5.872e-02 = 6.669e+00 - Alkalinity 5.258e-03 + 0.000e+00 = 5.258e-03 - C(-4) 0.000e+00 + 0.000e+00 = 0.000e+00 - C(4) 6.870e-03 + -2.581e-04 = 6.612e-03 - Ca 1.128e-02 + 0.000e+00 = 1.128e-02 - Cl 1.785e-02 + 0.000e+00 = 1.785e-02 - Fe(2) 4.000e-07 + 0.000e+00 = 4.000e-07 - Fe(3) 0.000e+00 + 0.000e+00 = 0.000e+00 - H(0) 1.190e-09 + 0.000e+00 = 1.190e-09 - K 2.540e-03 + 0.000e+00 = 2.540e-03 - Mg 4.540e-03 + 0.000e+00 = 4.540e-03 - Na 3.189e-02 + -1.256e-03 = 3.063e-02 - O(0) 0.000e+00 + 0.000e+00 = 0.000e+00 - S(-2) 2.600e-04 + 0.000e+00 = 2.600e-04 - S(6) 1.986e-02 + 9.930e-04 = 2.085e-02 - X 0.000e+00 + 0.000e+00 = 0.000e+00 - 13C(-4) -2.3 + 0 = -2.3 - 13C(4) -2.3 + 0 = -2.3 - 34S(-2) -22.1 + 0 = -22.1 - 34S(6) 16.3 + 0 = 16.3 - -Isotopic composition of phases: - 13C Dolomite 3 + 2 = 5 - 13C Calcite -1.5 + -1 = -2.5 - 34S Anhydrite 13.5 + -0.119926 = 13.3801 - 13C CH2O -25 + 5 = -20 - 34S Pyrite -22 + 2 = -20 - -Solution fractions: Minimum Maximum - Solution 1 1.000e+00 1.000e+00 1.000e+00 - Solution 2 1.000e+00 1.000e+00 1.000e+00 - -Phase mole transfers: Minimum Maximum - Dolomite 5.443e-03 4.995e-03 5.838e-03 CaMg(CO3)2 - Calcite -1.214e-02 -1.333e-02 -1.098e-02 CaCO3 - Anhydrite 2.252e-02 2.076e-02 2.297e-02 CaSO4 - CH2O 3.455e-03 3.003e-03 4.297e-03 CH2O - Goethite 7.821e-04 6.533e-04 1.015e-03 FeOOH - Pyrite -7.827e-04 -1.014e-03 -6.553e-04 FeS2 - Ca.75Mg.25X2 -7.652e-03 -8.576e-03 -6.972e-03 Ca.75Mg.25X2 - NaX 1.530e-02 1.394e-02 1.715e-02 NaX - Halite 1.531e-02 1.429e-02 1.633e-02 NaCl - Sylvite 2.520e-03 2.392e-03 2.648e-03 KCl - -Redox mole transfers: - Fe(3) 7.821e-04 - H(0) -1.190e-09 - S(-2) -1.825e-03 - -Sum of residuals (epsilons in documentation): 4.207e+00 -Sum of delta/uncertainty limit: 8.243e+00 -Maximum fractional error in element concentration: 5.000e-02 - -Model contains minimum number of phases. -=============================================================================== - - -Summary of inverse modeling: - - Number of models found: 2 - Number of minimal models found: 2 - Number of infeasible sets of phases saved: 28 - Number of calls to cl1: 80 ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex2.log b/Sun/examples/ex2.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex2.out b/Sun/examples/ex2.out deleted file mode 100644 index 5f57d4e9..00000000 --- a/Sun/examples/ex2.out +++ /dev/null @@ -1,4037 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex2 - Output file: ex2.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 2.--Temperature dependence of solubility - of gypsum and anhydrite - SOLUTION 1 Pure water - pH 7.0 - temp 25.0 - EQUILIBRIUM_PHASES 1 - Gypsum 0.0 1.0 - Anhydrite 0.0 1.0 - REACTION_TEMPERATURE 1 - 25.0 75.0 in 51 steps - SELECTED_OUTPUT - file ex2.sel - temperature - si anhydrite gypsum - END ------ -TITLE ------ - - Example 2.--Temperature dependence of solubility - of gypsum and anhydrite - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Pure water - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Pure water - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.082e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 - H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 -H(0) 1.416e-25 - H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 0.00 1.51 H2O - O2(g) -39.12 -42.08 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.22 -4.58 -4.36 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.849e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.564e-02 1.508e-02 - S 1.564e-02 1.508e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.067 Charge balance - pe = 10.686 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.178e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -9.881e-11 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070728e+02 - Total O = 5.359671e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.417e-07 1.167e-07 -6.849 -6.933 -0.084 - H+ 9.957e-08 8.575e-08 -7.002 -7.067 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.564e-02 - Ca+2 1.045e-02 5.176e-03 -1.981 -2.286 -0.305 - CaSO4 5.191e-03 5.242e-03 -2.285 -2.281 0.004 - CaOH+ 1.204e-08 1.001e-08 -7.919 -7.999 -0.080 - CaHSO4+ 3.166e-09 2.633e-09 -8.499 -8.580 -0.080 -H(0) 4.375e-39 - H2 2.187e-39 2.209e-39 -38.660 -38.656 0.004 -O(0) 1.691e-15 - O2 8.457e-16 8.539e-16 -15.073 -15.069 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -117.650 -117.734 -0.084 - H2S 0.000e+00 0.000e+00 -117.863 -117.859 0.004 - S-2 0.000e+00 0.000e+00 -123.274 -123.585 -0.312 -S(6) 1.564e-02 - SO4-2 1.045e-02 5.075e-03 -1.981 -2.295 -0.313 - CaSO4 5.191e-03 5.242e-03 -2.285 -2.281 0.004 - HSO4- 5.088e-08 4.231e-08 -7.293 -7.374 -0.080 - CaHSO4+ 3.166e-09 2.633e-09 -8.499 -8.580 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.22 -4.58 -4.36 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -35.51 -38.66 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -116.86 -117.86 -1.00 H2S - O2(g) -12.11 -15.07 -2.96 O2 - Sulfur -87.24 -82.35 4.88 S - -Reaction step 2. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.22 -4.58 -4.37 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.849e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.569e-02 1.514e-02 - S 1.569e-02 1.514e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.053 Charge balance - pe = 10.617 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.182e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 26.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.070730e+02 - Total O = 5.359703e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.482e-07 1.220e-07 -6.829 -6.914 -0.084 - H+ 1.027e-07 8.845e-08 -6.988 -7.053 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.569e-02 - Ca+2 1.046e-02 5.174e-03 -1.981 -2.286 -0.306 - CaSO4 5.236e-03 5.287e-03 -2.281 -2.277 0.004 - CaOH+ 1.167e-08 9.704e-09 -7.933 -8.013 -0.080 - CaHSO4+ 3.337e-09 2.774e-09 -8.477 -8.557 -0.080 -H(0) 6.343e-39 - H2 3.172e-39 3.202e-39 -38.499 -38.495 0.004 -O(0) 1.687e-15 - O2 8.436e-16 8.517e-16 -15.074 -15.070 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -117.121 -117.205 -0.084 - H2S 0.000e+00 0.000e+00 -117.334 -117.330 0.004 - S-2 0.000e+00 0.000e+00 -122.728 -123.041 -0.312 -S(6) 1.569e-02 - SO4-2 1.046e-02 5.073e-03 -1.981 -2.295 -0.314 - CaSO4 5.236e-03 5.287e-03 -2.281 -2.277 0.004 - HSO4- 5.364e-08 4.459e-08 -7.270 -7.351 -0.080 - CaHSO4+ 3.337e-09 2.774e-09 -8.477 -8.557 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.22 -4.58 -4.37 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -35.34 -38.49 -3.15 H2 - H2O(g) -1.48 -0.00 1.48 H2O - H2S(g) -116.32 -117.33 -1.01 H2S - O2(g) -12.11 -15.07 -2.96 O2 - Sulfur -86.85 -81.99 4.86 S - -Reaction step 3. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.21 -4.58 -4.37 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.848e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.574e-02 1.519e-02 - S 1.574e-02 1.519e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.040 Charge balance - pe = 10.572 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.186e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 27.000 - Electrical balance (eq) = -1.001e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 20 - Total H = 1.070732e+02 - Total O = 5.359733e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.548e-07 1.274e-07 -6.810 -6.895 -0.085 - H+ 1.060e-07 9.122e-08 -6.975 -7.040 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.574e-02 - Ca+2 1.047e-02 5.172e-03 -1.980 -2.286 -0.306 - CaSO4 5.279e-03 5.330e-03 -2.277 -2.273 0.004 - CaOH+ 1.132e-08 9.405e-09 -7.946 -8.027 -0.080 - CaHSO4+ 3.516e-09 2.922e-09 -8.454 -8.534 -0.080 -H(0) 8.213e-39 - H2 4.107e-39 4.146e-39 -38.387 -38.382 0.004 -O(0) 2.100e-15 - O2 1.050e-15 1.060e-15 -14.979 -14.975 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -116.788 -116.873 -0.085 - H2S 0.000e+00 0.000e+00 -117.001 -116.997 0.004 - S-2 0.000e+00 0.000e+00 -122.379 -122.692 -0.313 -S(6) 1.574e-02 - SO4-2 1.047e-02 5.071e-03 -1.980 -2.295 -0.315 - CaSO4 5.279e-03 5.330e-03 -2.277 -2.273 0.004 - HSO4- 5.655e-08 4.699e-08 -7.248 -7.328 -0.080 - CaHSO4+ 3.516e-09 2.922e-09 -8.454 -8.534 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.21 -4.58 -4.37 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -35.22 -38.38 -3.16 H2 - H2O(g) -1.46 -0.00 1.46 H2O - H2S(g) -115.98 -117.00 -1.02 H2S - O2(g) -12.01 -14.97 -2.97 O2 - Sulfur -86.61 -81.77 4.84 S - -Reaction step 4. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.21 -4.58 -4.37 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.848e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.579e-02 1.523e-02 - S 1.579e-02 1.523e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.027 Charge balance - pe = 10.479 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.189e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 28.000 - Electrical balance (eq) = -9.955e-11 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 22 - Total H = 1.070734e+02 - Total O = 5.359762e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.617e-07 1.330e-07 -6.791 -6.876 -0.085 - H+ 1.093e-07 9.404e-08 -6.961 -7.027 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.579e-02 - Ca+2 1.047e-02 5.168e-03 -1.980 -2.287 -0.307 - CaSO4 5.321e-03 5.373e-03 -2.274 -2.270 0.004 - CaOH+ 1.097e-08 9.117e-09 -7.960 -8.040 -0.081 - CaHSO4+ 3.703e-09 3.076e-09 -8.431 -8.512 -0.081 -H(0) 1.325e-38 - H2 6.624e-39 6.688e-39 -38.179 -38.175 0.004 -O(0) 1.677e-15 - O2 8.383e-16 8.464e-16 -15.077 -15.072 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -116.073 -116.158 -0.085 - H2S 0.000e+00 0.000e+00 -116.285 -116.281 0.004 - S-2 0.000e+00 0.000e+00 -121.647 -121.961 -0.314 -S(6) 1.579e-02 - SO4-2 1.047e-02 5.067e-03 -1.980 -2.295 -0.315 - CaSO4 5.321e-03 5.373e-03 -2.274 -2.270 0.004 - HSO4- 5.959e-08 4.950e-08 -7.225 -7.305 -0.081 - CaHSO4+ 3.703e-09 3.076e-09 -8.431 -8.512 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.21 -4.58 -4.37 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -35.01 -38.17 -3.16 H2 - H2O(g) -1.43 -0.00 1.43 H2O - H2S(g) -115.25 -116.28 -1.03 H2S - O2(g) -12.10 -15.07 -2.97 O2 - Sulfur -86.08 -81.27 4.81 S - -Reaction step 5. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.20 -4.58 -4.38 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.847e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.584e-02 1.528e-02 - S 1.584e-02 1.528e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.014 Charge balance - pe = 10.411 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.191e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 29.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.070735e+02 - Total O = 5.359788e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.688e-07 1.388e-07 -6.773 -6.858 -0.085 - H+ 1.127e-07 9.693e-08 -6.948 -7.014 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.584e-02 - Ca+2 1.048e-02 5.164e-03 -1.980 -2.287 -0.307 - CaSO4 5.361e-03 5.413e-03 -2.271 -2.267 0.004 - CaOH+ 1.064e-08 8.838e-09 -7.973 -8.054 -0.081 - CaHSO4+ 3.899e-09 3.238e-09 -8.409 -8.490 -0.081 -H(0) 1.909e-38 - H2 9.547e-39 9.639e-39 -38.020 -38.016 0.004 -O(0) 1.668e-15 - O2 8.339e-16 8.420e-16 -15.079 -15.075 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -115.552 -115.637 -0.085 - H2S 0.000e+00 0.000e+00 -115.764 -115.759 0.004 - S-2 0.000e+00 0.000e+00 -121.110 -121.424 -0.314 -S(6) 1.584e-02 - SO4-2 1.048e-02 5.063e-03 -1.980 -2.296 -0.316 - CaSO4 5.361e-03 5.413e-03 -2.271 -2.267 0.004 - HSO4- 6.279e-08 5.214e-08 -7.202 -7.283 -0.081 - CaHSO4+ 3.899e-09 3.238e-09 -8.409 -8.490 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.20 -4.58 -4.38 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -34.85 -38.02 -3.17 H2 - H2O(g) -1.41 -0.00 1.41 H2O - H2S(g) -114.72 -115.76 -1.04 H2S - O2(g) -12.10 -15.07 -2.98 O2 - Sulfur -85.70 -80.91 4.79 S - -Reaction step 6. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.20 -4.58 -4.39 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.847e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.588e-02 1.532e-02 - S 1.588e-02 1.532e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.001 Charge balance - pe = 10.344 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.193e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 30.000 - Electrical balance (eq) = -9.775e-11 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.070737e+02 - Total O = 5.359813e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.762e-07 1.448e-07 -6.754 -6.839 -0.085 - H+ 1.161e-07 9.988e-08 -6.935 -7.001 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.588e-02 - Ca+2 1.048e-02 5.160e-03 -1.980 -2.287 -0.308 - CaSO4 5.400e-03 5.453e-03 -2.268 -2.263 0.004 - CaOH+ 1.032e-08 8.569e-09 -7.986 -8.067 -0.081 - CaHSO4+ 4.103e-09 3.406e-09 -8.387 -8.468 -0.081 -H(0) 2.734e-38 - H2 1.367e-38 1.380e-38 -37.864 -37.860 0.004 -O(0) 1.673e-15 - O2 8.364e-16 8.445e-16 -15.078 -15.073 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -115.042 -115.128 -0.085 - H2S 0.000e+00 0.000e+00 -115.253 -115.249 0.004 - S-2 0.000e+00 0.000e+00 -120.584 -120.899 -0.315 -S(6) 1.588e-02 - SO4-2 1.048e-02 5.059e-03 -1.980 -2.296 -0.316 - CaSO4 5.400e-03 5.453e-03 -2.268 -2.263 0.004 - HSO4- 6.614e-08 5.491e-08 -7.180 -7.260 -0.081 - CaHSO4+ 4.103e-09 3.406e-09 -8.387 -8.468 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.20 -4.58 -4.39 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -34.69 -37.86 -3.17 H2 - H2O(g) -1.38 -0.00 1.38 H2O - H2S(g) -114.20 -115.25 -1.05 H2S - O2(g) -12.09 -15.07 -2.98 O2 - Sulfur -85.33 -80.56 4.77 S - -Reaction step 7. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.19 -4.58 -4.39 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.58 -4.58 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.592e-02 1.536e-02 - S 1.592e-02 1.536e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.988 Charge balance - pe = 10.277 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.194e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 31.000 - Electrical balance (eq) = -1.014e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.070739e+02 - Total O = 5.359836e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.837e-07 1.510e-07 -6.736 -6.821 -0.085 - H+ 1.197e-07 1.029e-07 -6.922 -6.988 -0.066 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.592e-02 - Ca+2 1.049e-02 5.154e-03 -1.979 -2.288 -0.308 - CaSO4 5.438e-03 5.491e-03 -2.265 -2.260 0.004 - CaOH+ 1.001e-08 8.310e-09 -7.999 -8.080 -0.081 - CaHSO4+ 4.317e-09 3.582e-09 -8.365 -8.446 -0.081 -H(0) 3.917e-38 - H2 1.959e-38 1.978e-38 -37.708 -37.704 0.004 -O(0) 1.668e-15 - O2 8.342e-16 8.423e-16 -15.079 -15.075 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -114.531 -114.617 -0.085 - H2S 0.000e+00 0.000e+00 -114.740 -114.736 0.004 - S-2 0.000e+00 0.000e+00 -120.057 -120.372 -0.315 -S(6) 1.592e-02 - SO4-2 1.048e-02 5.053e-03 -1.979 -2.296 -0.317 - CaSO4 5.438e-03 5.491e-03 -2.265 -2.260 0.004 - HSO4- 6.966e-08 5.780e-08 -7.157 -7.238 -0.081 - CaHSO4+ 4.317e-09 3.582e-09 -8.365 -8.446 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.19 -4.58 -4.39 CaSO4 - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -34.53 -37.70 -3.18 H2 - H2O(g) -1.36 -0.00 1.36 H2O - H2S(g) -113.67 -114.74 -1.06 H2S - O2(g) -12.09 -15.07 -2.99 O2 - Sulfur -84.95 -80.21 4.74 S - -Reaction step 8. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.19 -4.59 -4.40 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.596e-02 1.539e-02 - S 1.596e-02 1.539e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.975 Charge balance - pe = 10.210 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.194e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 32.000 - Electrical balance (eq) = -1.029e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070740e+02 - Total O = 5.359858e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.916e-07 1.573e-07 -6.718 -6.803 -0.085 - H+ 1.233e-07 1.060e-07 -6.909 -6.975 -0.066 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.596e-02 - Ca+2 1.049e-02 5.148e-03 -1.979 -2.288 -0.309 - CaSO4 5.474e-03 5.527e-03 -2.262 -2.258 0.004 - CaOH+ 9.715e-09 8.059e-09 -8.013 -8.094 -0.081 - CaHSO4+ 4.540e-09 3.766e-09 -8.343 -8.424 -0.081 -H(0) 5.596e-38 - H2 2.798e-38 2.825e-38 -37.553 -37.549 0.004 -O(0) 1.666e-15 - O2 8.330e-16 8.410e-16 -15.079 -15.075 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -114.024 -114.110 -0.085 - H2S 0.000e+00 0.000e+00 -114.232 -114.228 0.004 - S-2 0.000e+00 0.000e+00 -119.534 -119.850 -0.316 -S(6) 1.596e-02 - SO4-2 1.049e-02 5.047e-03 -1.979 -2.297 -0.318 - CaSO4 5.474e-03 5.527e-03 -2.262 -2.258 0.004 - HSO4- 7.334e-08 6.084e-08 -7.135 -7.216 -0.081 - CaHSO4+ 4.540e-09 3.766e-09 -8.343 -8.424 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.19 -4.59 -4.40 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -34.37 -37.55 -3.18 H2 - H2O(g) -1.33 -0.00 1.33 H2O - H2S(g) -113.15 -114.23 -1.07 H2S - O2(g) -12.08 -15.08 -2.99 O2 - Sulfur -84.58 -79.86 4.72 S - -Reaction step 9. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.18 -4.59 -4.40 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.599e-02 1.543e-02 - S 1.599e-02 1.543e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.962 Charge balance - pe = 10.149 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.194e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 33.000 - Electrical balance (eq) = -9.966e-11 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.070741e+02 - Total O = 5.359877e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.996e-07 1.639e-07 -6.700 -6.785 -0.086 - H+ 1.270e-07 1.091e-07 -6.896 -6.962 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.599e-02 - Ca+2 1.049e-02 5.142e-03 -1.979 -2.289 -0.309 - CaSO4 5.508e-03 5.562e-03 -2.259 -2.255 0.004 - CaOH+ 9.427e-09 7.818e-09 -8.026 -8.107 -0.081 - CaHSO4+ 4.772e-09 3.957e-09 -8.321 -8.403 -0.081 -H(0) 7.777e-38 - H2 3.888e-38 3.926e-38 -37.410 -37.406 0.004 -O(0) 1.749e-15 - O2 8.746e-16 8.831e-16 -15.058 -15.054 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -113.565 -113.650 -0.086 - H2S 0.000e+00 0.000e+00 -113.771 -113.767 0.004 - S-2 0.000e+00 0.000e+00 -119.058 -119.374 -0.316 -S(6) 1.599e-02 - SO4-2 1.048e-02 5.041e-03 -1.979 -2.297 -0.318 - CaSO4 5.508e-03 5.562e-03 -2.259 -2.255 0.004 - HSO4- 7.720e-08 6.402e-08 -7.112 -7.194 -0.081 - CaHSO4+ 4.772e-09 3.957e-09 -8.321 -8.403 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.18 -4.59 -4.40 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -34.22 -37.41 -3.18 H2 - H2O(g) -1.31 -0.00 1.31 H2O - H2S(g) -112.68 -113.77 -1.08 H2S - O2(g) -12.06 -15.05 -3.00 O2 - Sulfur -84.24 -79.54 4.70 S - -Reaction step 10. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.18 -4.59 -4.41 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.602e-02 1.546e-02 - S 1.602e-02 1.546e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.950 Charge balance - pe = 10.078 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.193e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 34.000 - Electrical balance (eq) = -1.005e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.070743e+02 - Total O = 5.359895e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.079e-07 1.707e-07 -6.682 -6.768 -0.086 - H+ 1.307e-07 1.123e-07 -6.884 -6.950 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.602e-02 - Ca+2 1.048e-02 5.134e-03 -1.980 -2.290 -0.310 - CaSO4 5.541e-03 5.595e-03 -2.256 -2.252 0.004 - CaOH+ 9.149e-09 7.585e-09 -8.039 -8.120 -0.081 - CaHSO4+ 5.015e-09 4.157e-09 -8.300 -8.381 -0.081 -H(0) 1.129e-37 - H2 5.647e-38 5.701e-38 -37.248 -37.244 0.004 -O(0) 1.675e-15 - O2 8.373e-16 8.454e-16 -15.077 -15.073 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -113.028 -113.114 -0.086 - H2S 0.000e+00 0.000e+00 -113.233 -113.229 0.004 - S-2 0.000e+00 0.000e+00 -118.505 -118.822 -0.317 -S(6) 1.602e-02 - SO4-2 1.048e-02 5.034e-03 -1.980 -2.298 -0.319 - CaSO4 5.541e-03 5.595e-03 -2.256 -2.252 0.004 - HSO4- 8.124e-08 6.734e-08 -7.090 -7.172 -0.081 - CaHSO4+ 5.015e-09 4.157e-09 -8.300 -8.381 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.18 -4.59 -4.41 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -34.06 -37.24 -3.19 H2 - H2O(g) -1.28 -0.00 1.28 H2O - H2S(g) -112.13 -113.23 -1.10 H2S - O2(g) -12.07 -15.07 -3.00 O2 - Sulfur -83.85 -79.17 4.68 S - -Reaction step 11. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.17 -4.59 -4.42 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.985e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.605e-02 1.548e-02 - S 1.605e-02 1.548e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.937 Charge balance - pe = 10.013 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.191e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 35.000 - Electrical balance (eq) = -1.043e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 20 - Total H = 1.070744e+02 - Total O = 5.359911e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.165e-07 1.776e-07 -6.665 -6.750 -0.086 - H+ 1.345e-07 1.155e-07 -6.871 -6.937 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.605e-02 - Ca+2 1.048e-02 5.126e-03 -1.980 -2.290 -0.310 - CaSO4 5.573e-03 5.627e-03 -2.254 -2.250 0.004 - CaOH+ 8.881e-09 7.360e-09 -8.052 -8.133 -0.082 - CaHSO4+ 5.267e-09 4.365e-09 -8.278 -8.360 -0.082 -H(0) 1.600e-37 - H2 8.002e-38 8.080e-38 -37.097 -37.093 0.004 -O(0) 1.676e-15 - O2 8.378e-16 8.459e-16 -15.077 -15.073 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -112.533 -112.619 -0.086 - H2S 0.000e+00 0.000e+00 -112.737 -112.733 0.004 - S-2 0.000e+00 0.000e+00 -117.994 -118.312 -0.317 -S(6) 1.605e-02 - SO4-2 1.048e-02 5.026e-03 -1.980 -2.299 -0.319 - CaSO4 5.573e-03 5.627e-03 -2.254 -2.250 0.004 - HSO4- 8.546e-08 7.082e-08 -7.068 -7.150 -0.082 - CaHSO4+ 5.267e-09 4.365e-09 -8.278 -8.360 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.17 -4.59 -4.42 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -33.90 -37.09 -3.19 H2 - H2O(g) -1.26 -0.00 1.26 H2O - H2S(g) -111.63 -112.73 -1.11 H2S - O2(g) -12.07 -15.07 -3.00 O2 - Sulfur -83.49 -78.83 4.66 S - -Reaction step 12. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.17 -4.59 -4.42 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.608e-02 1.551e-02 - S 1.608e-02 1.551e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.925 Charge balance - pe = 9.946 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.189e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 36.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.070745e+02 - Total O = 5.359925e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.253e-07 1.848e-07 -6.647 -6.733 -0.086 - H+ 1.384e-07 1.189e-07 -6.859 -6.925 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.608e-02 - Ca+2 1.047e-02 5.118e-03 -1.980 -2.291 -0.311 - CaSO4 5.603e-03 5.657e-03 -2.252 -2.247 0.004 - CaOH+ 8.622e-09 7.143e-09 -8.064 -8.146 -0.082 - CaHSO4+ 5.530e-09 4.582e-09 -8.257 -8.339 -0.082 -H(0) 2.285e-37 - H2 1.143e-37 1.154e-37 -36.942 -36.938 0.004 -O(0) 1.644e-15 - O2 8.221e-16 8.301e-16 -15.085 -15.081 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -112.024 -112.110 -0.086 - H2S 0.000e+00 0.000e+00 -112.227 -112.223 0.004 - S-2 0.000e+00 0.000e+00 -117.470 -117.788 -0.318 -S(6) 1.608e-02 - SO4-2 1.047e-02 5.018e-03 -1.980 -2.300 -0.320 - CaSO4 5.603e-03 5.657e-03 -2.252 -2.247 0.004 - HSO4- 8.988e-08 7.446e-08 -7.046 -7.128 -0.082 - CaHSO4+ 5.530e-09 4.582e-09 -8.257 -8.339 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.17 -4.59 -4.42 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -33.74 -36.94 -3.20 H2 - H2O(g) -1.24 -0.00 1.24 H2O - H2S(g) -111.11 -112.22 -1.12 H2S - O2(g) -12.07 -15.08 -3.01 O2 - Sulfur -83.11 -78.48 4.63 S - -Reaction step 13. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.16 -4.59 -4.43 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.610e-02 1.553e-02 - S 1.610e-02 1.553e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.913 Charge balance - pe = 9.884 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.186e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 37.000 - Electrical balance (eq) = -1.048e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 22 - Total H = 1.070745e+02 - Total O = 5.359938e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.344e-07 1.922e-07 -6.630 -6.716 -0.086 - H+ 1.423e-07 1.222e-07 -6.847 -6.913 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.610e-02 - Ca+2 1.047e-02 5.109e-03 -1.980 -2.292 -0.311 - CaSO4 5.632e-03 5.686e-03 -2.249 -2.245 0.004 - CaOH+ 8.373e-09 6.934e-09 -8.077 -8.159 -0.082 - CaHSO4+ 5.804e-09 4.807e-09 -8.236 -8.318 -0.082 -H(0) 3.186e-37 - H2 1.593e-37 1.609e-37 -36.798 -36.794 0.004 -O(0) 1.684e-15 - O2 8.422e-16 8.504e-16 -15.075 -15.070 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -111.557 -111.643 -0.086 - H2S 0.000e+00 0.000e+00 -111.757 -111.753 0.004 - S-2 0.000e+00 0.000e+00 -116.986 -117.305 -0.318 -S(6) 1.610e-02 - SO4-2 1.047e-02 5.009e-03 -1.980 -2.300 -0.320 - CaSO4 5.632e-03 5.686e-03 -2.249 -2.245 0.004 - HSO4- 9.450e-08 7.827e-08 -7.025 -7.106 -0.082 - CaHSO4+ 5.804e-09 4.807e-09 -8.236 -8.318 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.16 -4.59 -4.43 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -33.59 -36.79 -3.20 H2 - H2O(g) -1.21 -0.00 1.21 H2O - H2S(g) -110.63 -111.75 -1.13 H2S - O2(g) -12.06 -15.07 -3.01 O2 - Sulfur -82.77 -78.16 4.61 S - -Reaction step 14. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.15 -4.59 -4.44 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.59 -4.59 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.612e-02 1.554e-02 - S 1.612e-02 1.554e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.901 Charge balance - pe = 9.865 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.183e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 38.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070746e+02 - Total O = 5.359949e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.438e-07 1.999e-07 -6.613 -6.699 -0.086 - H+ 1.464e-07 1.256e-07 -6.835 -6.901 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.612e-02 - Ca+2 1.046e-02 5.099e-03 -1.981 -2.293 -0.312 - CaSO4 5.659e-03 5.714e-03 -2.247 -2.243 0.004 - CaOH+ 8.132e-09 6.733e-09 -8.090 -8.172 -0.082 - CaHSO4+ 6.089e-09 5.042e-09 -8.215 -8.297 -0.082 -H(0) 3.638e-37 - H2 1.819e-37 1.837e-37 -36.740 -36.736 0.004 -O(0) 2.562e-15 - O2 1.281e-15 1.293e-15 -14.893 -14.888 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -111.435 -111.521 -0.086 - H2S 0.000e+00 0.000e+00 -111.634 -111.630 0.004 - S-2 0.000e+00 0.000e+00 -116.849 -117.168 -0.319 -S(6) 1.612e-02 - SO4-2 1.046e-02 4.999e-03 -1.981 -2.301 -0.321 - CaSO4 5.659e-03 5.714e-03 -2.247 -2.243 0.004 - HSO4- 9.933e-08 8.224e-08 -7.003 -7.085 -0.082 - CaHSO4+ 6.089e-09 5.042e-09 -8.215 -8.297 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.15 -4.59 -4.44 CaSO4 - Gypsum 0.00 -4.59 -4.59 CaSO4:2H2O - H2(g) -33.53 -36.74 -3.20 H2 - H2O(g) -1.19 -0.00 1.19 H2O - H2S(g) -110.49 -111.63 -1.14 H2S - O2(g) -11.87 -14.89 -3.02 O2 - Sulfur -82.69 -78.10 4.59 S - -Reaction step 15. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.15 -4.60 -4.45 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.613e-02 1.556e-02 - S 1.613e-02 1.556e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.889 Charge balance - pe = 9.755 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.179e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 39.000 - Electrical balance (eq) = -1.056e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070747e+02 - Total O = 5.359958e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.534e-07 2.077e-07 -6.596 -6.683 -0.086 - H+ 1.504e-07 1.291e-07 -6.823 -6.889 -0.066 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.613e-02 - Ca+2 1.045e-02 5.089e-03 -1.981 -2.293 -0.312 - CaSO4 5.684e-03 5.739e-03 -2.245 -2.241 0.004 - CaOH+ 7.899e-09 6.538e-09 -8.102 -8.185 -0.082 - CaHSO4+ 6.386e-09 5.286e-09 -8.195 -8.277 -0.082 -H(0) 6.313e-37 - H2 3.156e-37 3.187e-37 -36.501 -36.497 0.004 -O(0) 1.680e-15 - O2 8.399e-16 8.480e-16 -15.076 -15.072 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -110.586 -110.673 -0.086 - H2S 0.000e+00 0.000e+00 -110.783 -110.779 0.004 - S-2 0.000e+00 0.000e+00 -115.984 -116.304 -0.319 -S(6) 1.613e-02 - SO4-2 1.045e-02 4.989e-03 -1.981 -2.302 -0.321 - CaSO4 5.684e-03 5.739e-03 -2.245 -2.241 0.004 - HSO4- 1.044e-07 8.640e-08 -6.981 -7.064 -0.082 - CaHSO4+ 6.386e-09 5.286e-09 -8.195 -8.277 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.15 -4.60 -4.45 CaSO4 - Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O - H2(g) -33.29 -36.50 -3.21 H2 - H2O(g) -1.16 -0.00 1.16 H2O - H2S(g) -109.63 -110.78 -1.15 H2S - O2(g) -12.05 -15.07 -3.02 O2 - Sulfur -82.06 -77.49 4.57 S - -Reaction step 16. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.14 -4.60 -4.46 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.614e-02 1.557e-02 - S 1.614e-02 1.557e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.877 Charge balance - pe = 9.692 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.174e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 40.000 - Electrical balance (eq) = -1.037e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070747e+02 - Total O = 5.359965e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.634e-07 2.158e-07 -6.579 -6.666 -0.086 - H+ 1.546e-07 1.326e-07 -6.811 -6.877 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.614e-02 - Ca+2 1.044e-02 5.078e-03 -1.981 -2.294 -0.313 - CaSO4 5.708e-03 5.764e-03 -2.243 -2.239 0.004 - CaOH+ 7.675e-09 6.351e-09 -8.115 -8.197 -0.082 - CaHSO4+ 6.694e-09 5.539e-09 -8.174 -8.257 -0.082 -H(0) 8.826e-37 - H2 4.413e-37 4.456e-37 -36.355 -36.351 0.004 -O(0) 1.689e-15 - O2 8.445e-16 8.527e-16 -15.073 -15.069 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -110.112 -110.198 -0.086 - H2S 0.000e+00 0.000e+00 -110.307 -110.303 0.004 - S-2 0.000e+00 0.000e+00 -115.494 -115.814 -0.320 -S(6) 1.614e-02 - SO4-2 1.044e-02 4.979e-03 -1.981 -2.303 -0.321 - CaSO4 5.708e-03 5.764e-03 -2.243 -2.239 0.004 - HSO4- 1.097e-07 9.073e-08 -6.960 -7.042 -0.082 - CaHSO4+ 6.694e-09 5.539e-09 -8.174 -8.257 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.14 -4.60 -4.46 CaSO4 - Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O - H2(g) -33.14 -36.35 -3.21 H2 - H2O(g) -1.14 -0.00 1.14 H2O - H2S(g) -109.15 -110.30 -1.16 H2S - O2(g) -12.04 -15.07 -3.02 O2 - Sulfur -81.71 -77.16 4.55 S - -Reaction step 17. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.13 -4.60 -4.47 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.615e-02 1.558e-02 - S 1.615e-02 1.558e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.866 Charge balance - pe = 9.629 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.169e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 41.000 - Electrical balance (eq) = -1.043e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070748e+02 - Total O = 5.359970e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.736e-07 2.241e-07 -6.563 -6.649 -0.087 - H+ 1.588e-07 1.362e-07 -6.799 -6.866 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.615e-02 - Ca+2 1.042e-02 5.066e-03 -1.982 -2.295 -0.313 - CaSO4 5.731e-03 5.786e-03 -2.242 -2.238 0.004 - CaOH+ 7.458e-09 6.170e-09 -8.127 -8.210 -0.082 - CaHSO4+ 7.014e-09 5.802e-09 -8.154 -8.236 -0.082 -H(0) 1.237e-36 - H2 6.185e-37 6.244e-37 -36.209 -36.205 0.004 -O(0) 1.683e-15 - O2 8.416e-16 8.497e-16 -15.075 -15.071 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -109.633 -109.719 -0.087 - H2S 0.000e+00 0.000e+00 -109.826 -109.822 0.004 - S-2 0.000e+00 0.000e+00 -115.000 -115.320 -0.320 -S(6) 1.615e-02 - SO4-2 1.042e-02 4.967e-03 -1.982 -2.304 -0.322 - CaSO4 5.731e-03 5.786e-03 -2.242 -2.238 0.004 - HSO4- 1.152e-07 9.526e-08 -6.939 -7.021 -0.082 - CaHSO4+ 7.014e-09 5.802e-09 -8.154 -8.236 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.13 -4.60 -4.47 CaSO4 - Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O - H2(g) -32.99 -36.20 -3.22 H2 - H2O(g) -1.12 -0.00 1.12 H2O - H2S(g) -108.65 -109.82 -1.17 H2S - O2(g) -12.04 -15.07 -3.03 O2 - Sulfur -81.36 -76.83 4.53 S - -Reaction step 18. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.13 -4.60 -4.47 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.616e-02 1.559e-02 - S 1.616e-02 1.559e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.854 Charge balance - pe = 9.564 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.164e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 42.000 - Electrical balance (eq) = -1.067e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070748e+02 - Total O = 5.359974e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.842e-07 2.327e-07 -6.546 -6.633 -0.087 - H+ 1.631e-07 1.398e-07 -6.788 -6.854 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.616e-02 - Ca+2 1.041e-02 5.054e-03 -1.983 -2.296 -0.314 - CaSO4 5.752e-03 5.808e-03 -2.240 -2.236 0.004 - CaHSO4+ 7.346e-09 6.075e-09 -8.134 -8.216 -0.082 - CaOH+ 7.249e-09 5.995e-09 -8.140 -8.222 -0.082 -H(0) 1.736e-36 - H2 8.682e-37 8.766e-37 -36.061 -36.057 0.004 -O(0) 1.664e-15 - O2 8.322e-16 8.402e-16 -15.080 -15.076 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -109.150 -109.237 -0.087 - H2S 0.000e+00 0.000e+00 -109.341 -109.337 0.004 - S-2 0.000e+00 0.000e+00 -114.502 -114.822 -0.321 -S(6) 1.616e-02 - SO4-2 1.041e-02 4.956e-03 -1.983 -2.305 -0.322 - CaSO4 5.752e-03 5.808e-03 -2.240 -2.236 0.004 - HSO4- 1.209e-07 9.998e-08 -6.918 -7.000 -0.082 - CaHSO4+ 7.346e-09 6.075e-09 -8.134 -8.216 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.13 -4.60 -4.47 CaSO4 - Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O - H2(g) -32.84 -36.06 -3.22 H2 - H2O(g) -1.09 -0.00 1.09 H2O - H2S(g) -108.16 -109.34 -1.18 H2S - O2(g) -12.04 -15.08 -3.03 O2 - Sulfur -81.01 -76.50 4.51 S - -Reaction step 19. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.12 -4.60 -4.48 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.60 -4.60 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.616e-02 1.559e-02 - S 1.616e-02 1.559e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.843 Charge balance - pe = 9.503 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.157e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 43.000 - Electrical balance (eq) = -1.056e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070748e+02 - Total O = 5.359977e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.950e-07 2.416e-07 -6.530 -6.617 -0.087 - H+ 1.674e-07 1.435e-07 -6.776 -6.843 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.616e-02 - Ca+2 1.039e-02 5.042e-03 -1.983 -2.297 -0.314 - CaSO4 5.772e-03 5.827e-03 -2.239 -2.235 0.004 - CaHSO4+ 7.691e-09 6.359e-09 -8.114 -8.197 -0.083 - CaOH+ 7.048e-09 5.827e-09 -8.152 -8.235 -0.083 -H(0) 2.404e-36 - H2 1.202e-36 1.213e-36 -35.920 -35.916 0.004 -O(0) 1.686e-15 - O2 8.429e-16 8.510e-16 -15.074 -15.070 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -108.692 -108.778 -0.087 - H2S 0.000e+00 0.000e+00 -108.881 -108.877 0.004 - S-2 0.000e+00 0.000e+00 -114.027 -114.348 -0.321 -S(6) 1.616e-02 - SO4-2 1.039e-02 4.944e-03 -1.983 -2.306 -0.323 - CaSO4 5.772e-03 5.827e-03 -2.239 -2.235 0.004 - HSO4- 1.269e-07 1.049e-07 -6.897 -6.979 -0.083 - CaHSO4+ 7.691e-09 6.359e-09 -8.114 -8.197 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.12 -4.60 -4.48 CaSO4 - Gypsum 0.00 -4.60 -4.60 CaSO4:2H2O - H2(g) -32.69 -35.92 -3.22 H2 - H2O(g) -1.07 -0.00 1.07 H2O - H2S(g) -107.69 -108.88 -1.19 H2S - O2(g) -12.03 -15.07 -3.04 O2 - Sulfur -80.67 -76.18 4.49 S - -Reaction step 20. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.11 -4.61 -4.49 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.617e-02 1.559e-02 - S 1.617e-02 1.559e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.832 Charge balance - pe = 9.445 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.150e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 44.000 - Electrical balance (eq) = -1.062e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070748e+02 - Total O = 5.359977e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.062e-07 2.506e-07 -6.514 -6.601 -0.087 - H+ 1.718e-07 1.473e-07 -6.765 -6.832 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.617e-02 - Ca+2 1.038e-02 5.028e-03 -1.984 -2.299 -0.315 - CaSO4 5.790e-03 5.845e-03 -2.237 -2.233 0.004 - CaHSO4+ 8.049e-09 6.653e-09 -8.094 -8.177 -0.083 - CaOH+ 6.853e-09 5.665e-09 -8.164 -8.247 -0.083 -H(0) 3.282e-36 - H2 1.641e-36 1.657e-36 -35.785 -35.781 0.004 -O(0) 1.748e-15 - O2 8.739e-16 8.823e-16 -15.059 -15.054 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -108.256 -108.343 -0.087 - H2S 0.000e+00 0.000e+00 -108.443 -108.439 0.004 - S-2 0.000e+00 0.000e+00 -113.577 -113.898 -0.321 -S(6) 1.617e-02 - SO4-2 1.038e-02 4.931e-03 -1.984 -2.307 -0.323 - CaSO4 5.790e-03 5.845e-03 -2.237 -2.233 0.004 - HSO4- 1.331e-07 1.100e-07 -6.876 -6.958 -0.083 - CaHSO4+ 8.049e-09 6.653e-09 -8.094 -8.177 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.11 -4.61 -4.49 CaSO4 - Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O - H2(g) -32.55 -35.78 -3.23 H2 - H2O(g) -1.05 -0.00 1.05 H2O - H2S(g) -107.24 -108.44 -1.20 H2S - O2(g) -12.01 -15.05 -3.04 O2 - Sulfur -80.35 -75.89 4.46 S - -Reaction step 21. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.11 -4.61 -4.50 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.616e-02 1.559e-02 - S 1.616e-02 1.559e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.821 Charge balance - pe = 9.379 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.143e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 45.000 - Electrical balance (eq) = -1.068e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070748e+02 - Total O = 5.359976e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.177e-07 2.600e-07 -6.498 -6.585 -0.087 - H+ 1.762e-07 1.510e-07 -6.754 -6.821 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.616e-02 - Ca+2 1.036e-02 5.015e-03 -1.985 -2.300 -0.315 - CaSO4 5.806e-03 5.862e-03 -2.236 -2.232 0.004 - CaHSO4+ 8.419e-09 6.957e-09 -8.075 -8.158 -0.083 - CaOH+ 6.666e-09 5.508e-09 -8.176 -8.259 -0.083 -H(0) 4.641e-36 - H2 2.320e-36 2.343e-36 -35.634 -35.630 0.004 -O(0) 1.682e-15 - O2 8.410e-16 8.491e-16 -15.075 -15.071 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -107.759 -107.846 -0.087 - H2S 0.000e+00 0.000e+00 -107.944 -107.940 0.004 - S-2 0.000e+00 0.000e+00 -113.064 -113.386 -0.322 -S(6) 1.616e-02 - SO4-2 1.036e-02 4.918e-03 -1.985 -2.308 -0.323 - CaSO4 5.806e-03 5.862e-03 -2.236 -2.232 0.004 - HSO4- 1.396e-07 1.154e-07 -6.855 -6.938 -0.083 - CaHSO4+ 8.419e-09 6.957e-09 -8.075 -8.158 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.11 -4.61 -4.50 CaSO4 - Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O - H2(g) -32.40 -35.63 -3.23 H2 - H2O(g) -1.03 -0.00 1.03 H2O - H2S(g) -106.73 -107.94 -1.21 H2S - O2(g) -12.03 -15.07 -3.04 O2 - Sulfur -79.98 -75.54 4.44 S - -Reaction step 22. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.10 -4.61 -4.51 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.616e-02 1.559e-02 - S 1.616e-02 1.559e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.810 Charge balance - pe = 9.316 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.135e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 46.000 - Electrical balance (eq) = -1.073e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070748e+02 - Total O = 5.359973e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.296e-07 2.696e-07 -6.482 -6.569 -0.087 - H+ 1.807e-07 1.549e-07 -6.743 -6.810 -0.067 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -Ca 1.616e-02 - Ca+2 1.034e-02 5.001e-03 -1.986 -2.301 -0.315 - CaSO4 5.821e-03 5.877e-03 -2.235 -2.231 0.004 - CaHSO4+ 8.804e-09 7.273e-09 -8.055 -8.138 -0.083 - CaOH+ 6.484e-09 5.357e-09 -8.188 -8.271 -0.083 -H(0) 6.456e-36 - H2 3.228e-36 3.259e-36 -35.491 -35.487 0.004 -O(0) 1.666e-15 - O2 8.330e-16 8.410e-16 -15.079 -15.075 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -107.291 -107.378 -0.087 - H2S 0.000e+00 0.000e+00 -107.473 -107.469 0.004 - S-2 0.000e+00 0.000e+00 -112.580 -112.902 -0.322 -S(6) 1.616e-02 - SO4-2 1.034e-02 4.904e-03 -1.986 -2.309 -0.324 - CaSO4 5.821e-03 5.877e-03 -2.235 -2.231 0.004 - HSO4- 1.464e-07 1.210e-07 -6.834 -6.917 -0.083 - CaHSO4+ 8.804e-09 7.273e-09 -8.055 -8.138 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.10 -4.61 -4.51 CaSO4 - Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O - H2(g) -32.25 -35.49 -3.23 H2 - H2O(g) -1.00 -0.00 1.00 H2O - H2S(g) -106.25 -107.47 -1.22 H2S - O2(g) -12.03 -15.08 -3.05 O2 - Sulfur -79.64 -75.22 4.42 S - -Reaction step 23. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.09 -4.61 -4.52 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.61 -4.61 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.615e-02 1.558e-02 - S 1.615e-02 1.558e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.799 Charge balance - pe = 9.255 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.127e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 47.000 - Electrical balance (eq) = -1.079e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.070747e+02 - Total O = 5.359969e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.417e-07 2.795e-07 -6.466 -6.554 -0.087 - H+ 1.852e-07 1.587e-07 -6.732 -6.799 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.615e-02 - Ca+2 1.032e-02 4.986e-03 -1.986 -2.302 -0.316 - CaSO4 5.835e-03 5.891e-03 -2.234 -2.230 0.004 - CaHSO4+ 9.202e-09 7.600e-09 -8.036 -8.119 -0.083 - CaOH+ 6.310e-09 5.211e-09 -8.200 -8.283 -0.083 -H(0) 8.884e-36 - H2 4.442e-36 4.485e-36 -35.352 -35.348 0.004 -O(0) 1.679e-15 - O2 8.396e-16 8.477e-16 -15.076 -15.072 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -106.840 -106.927 -0.087 - H2S 0.000e+00 0.000e+00 -107.020 -107.016 0.004 - S-2 0.000e+00 0.000e+00 -112.114 -112.436 -0.323 -S(6) 1.615e-02 - SO4-2 1.032e-02 4.890e-03 -1.986 -2.311 -0.324 - CaSO4 5.835e-03 5.891e-03 -2.234 -2.230 0.004 - HSO4- 1.535e-07 1.268e-07 -6.814 -6.897 -0.083 - CaHSO4+ 9.202e-09 7.600e-09 -8.036 -8.119 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.09 -4.61 -4.52 CaSO4 - Gypsum 0.00 -4.61 -4.61 CaSO4:2H2O - H2(g) -32.11 -35.35 -3.24 H2 - H2O(g) -0.98 -0.00 0.98 H2O - H2S(g) -105.79 -107.02 -1.23 H2S - O2(g) -12.02 -15.07 -3.05 O2 - Sulfur -79.31 -74.91 4.40 S - -Reaction step 24. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.08 -4.62 -4.53 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.614e-02 1.557e-02 - S 1.614e-02 1.557e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.789 Charge balance - pe = 9.192 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.118e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 48.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070747e+02 - Total O = 5.359963e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.543e-07 2.897e-07 -6.451 -6.538 -0.087 - H+ 1.898e-07 1.626e-07 -6.722 -6.789 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.614e-02 - Ca+2 1.029e-02 4.971e-03 -1.987 -2.304 -0.316 - CaSO4 5.847e-03 5.903e-03 -2.233 -2.229 0.004 - CaHSO4+ 9.614e-09 7.938e-09 -8.017 -8.100 -0.083 - CaOH+ 6.141e-09 5.070e-09 -8.212 -8.295 -0.083 -H(0) 1.237e-35 - H2 6.183e-36 6.242e-36 -35.209 -35.205 0.004 -O(0) 1.648e-15 - O2 8.239e-16 8.317e-16 -15.084 -15.080 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -106.369 -106.456 -0.087 - H2S 0.000e+00 0.000e+00 -106.546 -106.542 0.004 - S-2 0.000e+00 0.000e+00 -111.627 -111.950 -0.323 -S(6) 1.614e-02 - SO4-2 1.029e-02 4.875e-03 -1.987 -2.312 -0.325 - CaSO4 5.847e-03 5.903e-03 -2.233 -2.229 0.004 - HSO4- 1.609e-07 1.328e-07 -6.794 -6.877 -0.083 - CaHSO4+ 9.614e-09 7.938e-09 -8.017 -8.100 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.08 -4.62 -4.53 CaSO4 - Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O - H2(g) -31.96 -35.20 -3.24 H2 - H2O(g) -0.96 -0.00 0.96 H2O - H2S(g) -105.31 -106.54 -1.24 H2S - O2(g) -12.02 -15.08 -3.06 O2 - Sulfur -78.96 -74.58 4.38 S - -Reaction step 25. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.08 -4.62 -4.54 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.844e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.613e-02 1.556e-02 - S 1.613e-02 1.556e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.778 Charge balance - pe = 9.142 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.108e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 49.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070747e+02 - Total O = 5.359956e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.672e-07 3.002e-07 -6.435 -6.523 -0.087 - H+ 1.945e-07 1.666e-07 -6.711 -6.778 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.613e-02 - Ca+2 1.027e-02 4.956e-03 -1.988 -2.305 -0.317 - CaSO4 5.858e-03 5.914e-03 -2.232 -2.228 0.004 - CaHSO4+ 1.004e-08 8.288e-09 -7.998 -8.082 -0.083 - CaOH+ 5.978e-09 4.935e-09 -8.223 -8.307 -0.083 -H(0) 1.623e-35 - H2 8.115e-36 8.192e-36 -35.091 -35.087 0.004 -O(0) 1.812e-15 - O2 9.060e-16 9.146e-16 -15.043 -15.039 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -106.000 -106.087 -0.087 - H2S 0.000e+00 0.000e+00 -106.175 -106.171 0.004 - S-2 0.000e+00 0.000e+00 -111.243 -111.566 -0.323 -S(6) 1.613e-02 - SO4-2 1.027e-02 4.860e-03 -1.988 -2.313 -0.325 - CaSO4 5.858e-03 5.914e-03 -2.232 -2.228 0.004 - HSO4- 1.685e-07 1.391e-07 -6.773 -6.857 -0.083 - CaHSO4+ 1.004e-08 8.288e-09 -7.998 -8.082 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.08 -4.62 -4.54 CaSO4 - Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O - H2(g) -31.84 -35.09 -3.25 H2 - H2O(g) -0.94 -0.00 0.94 H2O - H2S(g) -104.92 -106.17 -1.25 H2S - O2(g) -11.98 -15.04 -3.06 O2 - Sulfur -78.69 -74.33 4.36 S - -Reaction step 26. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.07 -4.62 -4.55 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.611e-02 1.554e-02 - S 1.611e-02 1.554e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.768 Charge balance - pe = 9.071 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.098e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 50.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070746e+02 - Total O = 5.359947e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.805e-07 3.110e-07 -6.420 -6.507 -0.088 - H+ 1.992e-07 1.706e-07 -6.701 -6.768 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.611e-02 - Ca+2 1.025e-02 4.940e-03 -1.989 -2.306 -0.317 - CaSO4 5.867e-03 5.923e-03 -2.232 -2.227 0.004 - CaHSO4+ 1.048e-08 8.650e-09 -7.980 -8.063 -0.083 - CaOH+ 5.820e-09 4.804e-09 -8.235 -8.318 -0.083 -H(0) 2.343e-35 - H2 1.172e-35 1.183e-35 -34.931 -34.927 0.004 -O(0) 1.639e-15 - O2 8.196e-16 8.274e-16 -15.086 -15.082 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -105.464 -105.552 -0.088 - H2S 0.000e+00 0.000e+00 -105.636 -105.632 0.004 - S-2 0.000e+00 0.000e+00 -110.692 -111.015 -0.324 -S(6) 1.611e-02 - SO4-2 1.025e-02 4.845e-03 -1.989 -2.315 -0.325 - CaSO4 5.867e-03 5.923e-03 -2.232 -2.227 0.004 - HSO4- 1.765e-07 1.457e-07 -6.753 -6.837 -0.083 - CaHSO4+ 1.048e-08 8.650e-09 -7.980 -8.063 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.07 -4.62 -4.55 CaSO4 - Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O - H2(g) -31.68 -34.93 -3.25 H2 - H2O(g) -0.91 -0.00 0.91 H2O - H2S(g) -104.38 -105.63 -1.26 H2S - O2(g) -12.02 -15.08 -3.06 O2 - Sulfur -78.30 -73.96 4.34 S - -Reaction step 27. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.06 -4.62 -4.56 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.62 -4.62 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.609e-02 1.552e-02 - S 1.609e-02 1.552e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.758 Charge balance - pe = 9.012 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.088e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 51.000 - Electrical balance (eq) = -1.081e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.070745e+02 - Total O = 5.359936e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.941e-07 3.221e-07 -6.404 -6.492 -0.088 - H+ 2.039e-07 1.746e-07 -6.691 -6.758 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.609e-02 - Ca+2 1.022e-02 4.923e-03 -1.991 -2.308 -0.317 - CaSO4 5.875e-03 5.930e-03 -2.231 -2.227 0.004 - CaHSO4+ 1.094e-08 9.025e-09 -7.961 -8.045 -0.083 - CaOH+ 5.668e-09 4.677e-09 -8.247 -8.330 -0.083 -H(0) 3.183e-35 - H2 1.592e-35 1.607e-35 -34.798 -34.794 0.004 -O(0) 1.669e-15 - O2 8.347e-16 8.426e-16 -15.078 -15.074 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -105.034 -105.122 -0.088 - H2S 0.000e+00 0.000e+00 -105.204 -105.200 0.004 - S-2 0.000e+00 0.000e+00 -110.247 -110.570 -0.324 -S(6) 1.609e-02 - SO4-2 1.022e-02 4.829e-03 -1.991 -2.316 -0.326 - CaSO4 5.875e-03 5.930e-03 -2.231 -2.227 0.004 - HSO4- 1.848e-07 1.525e-07 -6.733 -6.817 -0.083 - CaHSO4+ 1.094e-08 9.025e-09 -7.961 -8.045 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.06 -4.62 -4.56 CaSO4 - Gypsum 0.00 -4.62 -4.62 CaSO4:2H2O - H2(g) -31.54 -34.79 -3.25 H2 - H2O(g) -0.89 -0.00 0.89 H2O - H2S(g) -103.93 -105.20 -1.27 H2S - O2(g) -12.01 -15.07 -3.07 O2 - Sulfur -77.98 -73.66 4.32 S - -Reaction step 28. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.05 -4.63 -4.58 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.63 -4.63 1.000e+00 1.984e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.607e-02 1.550e-02 - S 1.607e-02 1.550e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.748 Charge balance - pe = 8.953 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.077e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 52.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070744e+02 - Total O = 5.359924e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.081e-07 3.335e-07 -6.389 -6.477 -0.088 - H+ 2.087e-07 1.787e-07 -6.680 -6.748 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.607e-02 - Ca+2 1.019e-02 4.906e-03 -1.992 -2.309 -0.318 - CaSO4 5.881e-03 5.937e-03 -2.231 -2.226 0.004 - CaHSO4+ 1.141e-08 9.411e-09 -7.943 -8.026 -0.084 - CaOH+ 5.521e-09 4.555e-09 -8.258 -8.342 -0.084 -H(0) 4.352e-35 - H2 2.176e-35 2.196e-35 -34.662 -34.658 0.004 -O(0) 1.672e-15 - O2 8.358e-16 8.437e-16 -15.078 -15.074 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -104.592 -104.680 -0.088 - H2S 0.000e+00 0.000e+00 -104.759 -104.755 0.004 - S-2 0.000e+00 0.000e+00 -109.789 -110.114 -0.324 -S(6) 1.607e-02 - SO4-2 1.019e-02 4.813e-03 -1.992 -2.318 -0.326 - CaSO4 5.881e-03 5.937e-03 -2.231 -2.226 0.004 - HSO4- 1.934e-07 1.596e-07 -6.714 -6.797 -0.084 - CaHSO4+ 1.141e-08 9.411e-09 -7.943 -8.026 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.05 -4.63 -4.58 CaSO4 - Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O - H2(g) -31.40 -34.66 -3.26 H2 - H2O(g) -0.87 -0.00 0.87 H2O - H2S(g) -103.48 -104.76 -1.28 H2S - O2(g) -12.00 -15.07 -3.07 O2 - Sulfur -77.66 -73.35 4.30 S - -Reaction step 29. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.04 -4.63 -4.59 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.63 -4.63 1.000e+00 1.985e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.605e-02 1.548e-02 - S 1.605e-02 1.548e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.738 Charge balance - pe = 8.891 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.066e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 53.000 - Electrical balance (eq) = 1.076e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 24 - Total H = 1.070744e+02 - Total O = 5.359910e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.225e-07 3.452e-07 -6.374 -6.462 -0.088 - H+ 2.136e-07 1.828e-07 -6.670 -6.738 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.605e-02 - Ca+2 1.016e-02 4.889e-03 -1.993 -2.311 -0.318 - CaSO4 5.886e-03 5.942e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.189e-08 9.811e-09 -7.925 -8.008 -0.084 - CaOH+ 5.379e-09 4.437e-09 -8.269 -8.353 -0.084 -H(0) 5.999e-35 - H2 3.000e-35 3.028e-35 -34.523 -34.519 0.004 -O(0) 1.640e-15 - O2 8.200e-16 8.278e-16 -15.086 -15.082 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -104.136 -104.224 -0.088 - H2S 0.000e+00 0.000e+00 -104.300 -104.296 0.004 - S-2 0.000e+00 0.000e+00 -109.318 -109.642 -0.325 -S(6) 1.605e-02 - SO4-2 1.016e-02 4.796e-03 -1.993 -2.319 -0.326 - CaSO4 5.886e-03 5.942e-03 -2.230 -2.226 0.004 - HSO4- 2.024e-07 1.669e-07 -6.694 -6.778 -0.084 - CaHSO4+ 1.189e-08 9.811e-09 -7.925 -8.008 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.04 -4.63 -4.59 CaSO4 - Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O - H2(g) -31.26 -34.52 -3.26 H2 - H2O(g) -0.85 -0.00 0.85 H2O - H2S(g) -103.01 -104.30 -1.28 H2S - O2(g) -12.01 -15.08 -3.08 O2 - Sulfur -77.32 -73.04 4.28 S - -Reaction step 30. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.03 -4.63 -4.60 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.63 -4.63 1.000e+00 1.985e+00 9.845e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.602e-02 1.546e-02 - S 1.602e-02 1.546e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.728 Charge balance - pe = 8.834 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.054e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 54.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.070743e+02 - Total O = 5.359895e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.374e-07 3.573e-07 -6.359 -6.447 -0.088 - H+ 2.184e-07 1.869e-07 -6.661 -6.728 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.602e-02 - Ca+2 1.013e-02 4.871e-03 -1.994 -2.312 -0.318 - CaSO4 5.890e-03 5.945e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.240e-08 1.022e-08 -7.907 -7.990 -0.084 - CaOH+ 5.242e-09 4.323e-09 -8.280 -8.364 -0.084 -H(0) 8.078e-35 - H2 4.039e-35 4.077e-35 -34.394 -34.390 0.004 -O(0) 1.680e-15 - O2 8.401e-16 8.480e-16 -15.076 -15.072 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -103.720 -103.807 -0.088 - H2S 0.000e+00 0.000e+00 -103.881 -103.877 0.004 - S-2 0.000e+00 0.000e+00 -108.886 -109.211 -0.325 -S(6) 1.602e-02 - SO4-2 1.013e-02 4.779e-03 -1.994 -2.321 -0.327 - CaSO4 5.890e-03 5.945e-03 -2.230 -2.226 0.004 - HSO4- 2.117e-07 1.746e-07 -6.674 -6.758 -0.084 - CaHSO4+ 1.240e-08 1.022e-08 -7.907 -7.990 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.03 -4.63 -4.60 CaSO4 - Gypsum 0.00 -4.63 -4.63 CaSO4:2H2O - H2(g) -31.13 -34.39 -3.26 H2 - H2O(g) -0.83 -0.00 0.83 H2O - H2S(g) -102.58 -103.88 -1.29 H2S - O2(g) -11.99 -15.07 -3.08 O2 - Sulfur -77.02 -72.75 4.26 S - -Reaction step 31. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.03 -4.64 -4.61 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.600e-02 1.543e-02 - S 1.600e-02 1.543e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.719 Charge balance - pe = 8.773 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.042e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 55.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.070741e+02 - Total O = 5.359879e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.526e-07 3.697e-07 -6.344 -6.432 -0.088 - H+ 2.233e-07 1.911e-07 -6.651 -6.719 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.600e-02 - Ca+2 1.010e-02 4.853e-03 -1.995 -2.314 -0.318 - CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.292e-08 1.065e-08 -7.889 -7.973 -0.084 - CaOH+ 5.110e-09 4.213e-09 -8.292 -8.375 -0.084 -H(0) 1.113e-34 - H2 5.565e-35 5.617e-35 -34.255 -34.250 0.004 -O(0) 1.638e-15 - O2 8.188e-16 8.264e-16 -15.087 -15.083 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -103.263 -103.351 -0.088 - H2S 0.000e+00 0.000e+00 -103.421 -103.417 0.004 - S-2 0.000e+00 0.000e+00 -108.414 -108.739 -0.325 -S(6) 1.600e-02 - SO4-2 1.010e-02 4.761e-03 -1.995 -2.322 -0.327 - CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 - HSO4- 2.214e-07 1.825e-07 -6.655 -6.739 -0.084 - CaHSO4+ 1.292e-08 1.065e-08 -7.889 -7.973 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.03 -4.64 -4.61 CaSO4 - Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O - H2(g) -30.98 -34.25 -3.27 H2 - H2O(g) -0.81 -0.00 0.80 H2O - H2S(g) -102.11 -103.42 -1.30 H2S - O2(g) -12.00 -15.08 -3.08 O2 - Sulfur -76.68 -72.43 4.25 S - -Reaction step 32. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.02 -4.64 -4.62 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.597e-02 1.540e-02 - S 1.597e-02 1.540e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.709 Charge balance - pe = 8.716 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.029e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 56.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 20 - Total H = 1.070740e+02 - Total O = 5.359861e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.683e-07 3.824e-07 -6.330 -6.417 -0.088 - H+ 2.283e-07 1.953e-07 -6.642 -6.709 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.597e-02 - Ca+2 1.007e-02 4.835e-03 -1.997 -2.316 -0.319 - CaSO4 5.893e-03 5.948e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.345e-08 1.109e-08 -7.871 -7.955 -0.084 - CaOH+ 4.982e-09 4.106e-09 -8.303 -8.387 -0.084 -H(0) 1.497e-34 - H2 7.485e-35 7.554e-35 -34.126 -34.122 0.004 -O(0) 1.669e-15 - O2 8.344e-16 8.422e-16 -15.079 -15.075 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -102.848 -102.936 -0.088 - H2S 0.000e+00 0.000e+00 -103.003 -102.999 0.004 - S-2 0.000e+00 0.000e+00 -107.984 -108.309 -0.325 -S(6) 1.597e-02 - SO4-2 1.007e-02 4.743e-03 -1.997 -2.324 -0.327 - CaSO4 5.893e-03 5.948e-03 -2.230 -2.226 0.004 - HSO4- 2.314e-07 1.907e-07 -6.636 -6.720 -0.084 - CaHSO4+ 1.345e-08 1.109e-08 -7.871 -7.955 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.02 -4.64 -4.62 CaSO4 - Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O - H2(g) -30.85 -34.12 -3.27 H2 - H2O(g) -0.78 -0.00 0.78 H2O - H2S(g) -101.69 -103.00 -1.31 H2S - O2(g) -11.99 -15.07 -3.09 O2 - Sulfur -76.38 -72.15 4.23 S - -Reaction step 33. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite -0.01 -4.64 -4.63 1.000e+00 -1.000e+00 - Gypsum 0.00 -4.64 -4.64 1.000e+00 1.985e+00 9.846e-01 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.593e-02 1.537e-02 - S 1.593e-02 1.537e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.700 Charge balance - pe = 8.659 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.016e-02 - Mass of water (kg) = 9.645e-01 - Total alkalinity (eq/kg) = 1.122e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 57.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 23 - Total H = 1.070739e+02 - Total O = 5.359842e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.844e-07 3.955e-07 -6.315 -6.403 -0.088 - H+ 2.333e-07 1.995e-07 -6.632 -6.700 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.593e-02 - Ca+2 1.004e-02 4.816e-03 -1.998 -2.317 -0.319 - CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.400e-08 1.154e-08 -7.854 -7.938 -0.084 - CaOH+ 4.858e-09 4.004e-09 -8.314 -8.398 -0.084 -H(0) 2.017e-34 - H2 1.009e-34 1.018e-34 -33.996 -33.992 0.004 -O(0) 1.688e-15 - O2 8.441e-16 8.519e-16 -15.074 -15.070 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -102.429 -102.517 -0.088 - H2S 0.000e+00 0.000e+00 -102.581 -102.577 0.004 - S-2 0.000e+00 0.000e+00 -107.549 -107.875 -0.326 -S(6) 1.593e-02 - SO4-2 1.004e-02 4.725e-03 -1.998 -2.326 -0.327 - CaSO4 5.892e-03 5.947e-03 -2.230 -2.226 0.004 - HSO4- 2.418e-07 1.993e-07 -6.616 -6.700 -0.084 - CaHSO4+ 1.400e-08 1.154e-08 -7.854 -7.938 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.01 -4.64 -4.63 CaSO4 - Gypsum 0.00 -4.64 -4.64 CaSO4:2H2O - H2(g) -30.72 -33.99 -3.27 H2 - H2O(g) -0.76 -0.00 0.76 H2O - H2S(g) -101.26 -102.58 -1.32 H2S - O2(g) -11.98 -15.07 -3.09 O2 - Sulfur -76.07 -71.86 4.21 S - -Reaction step 34. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.65 -4.65 1.000e+00 1.984e+00 9.835e-01 - Gypsum -0.00 -4.65 -4.65 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.588e-02 1.646e-02 - S 1.588e-02 1.646e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.691 Charge balance - pe = 8.590 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.000e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 58.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.150124e+02 - Total O = 5.757204e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.008e-07 4.089e-07 -6.300 -6.388 -0.088 - H+ 2.383e-07 2.038e-07 -6.623 -6.691 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.588e-02 - Ca+2 1.000e-02 4.794e-03 -2.000 -2.319 -0.319 - CaSO4 5.884e-03 5.939e-03 -2.230 -2.226 0.004 - CaHSO4+ 1.456e-08 1.200e-08 -7.837 -7.921 -0.084 - CaOH+ 4.735e-09 3.902e-09 -8.325 -8.409 -0.084 -H(0) 2.861e-34 - H2 1.431e-34 1.444e-34 -33.844 -33.840 0.004 -O(0) 1.535e-15 - O2 7.677e-16 7.749e-16 -15.115 -15.111 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -101.920 -102.008 -0.088 - H2S 0.000e+00 0.000e+00 -102.070 -102.066 0.004 - S-2 0.000e+00 0.000e+00 -107.026 -107.352 -0.326 -S(6) 1.588e-02 - SO4-2 9.999e-03 4.704e-03 -2.000 -2.328 -0.327 - CaSO4 5.884e-03 5.939e-03 -2.230 -2.226 0.004 - HSO4- 2.526e-07 2.081e-07 -6.598 -6.682 -0.084 - CaHSO4+ 1.456e-08 1.200e-08 -7.837 -7.921 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.65 -4.65 CaSO4 - Gypsum -0.00 -4.65 -4.65 CaSO4:2H2O - H2(g) -30.56 -33.84 -3.28 H2 - H2O(g) -0.74 -0.00 0.74 H2O - H2S(g) -100.74 -102.07 -1.33 H2S - O2(g) -12.02 -15.11 -3.09 O2 - Sulfur -75.69 -71.50 4.19 S - -Reaction step 35. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.66 -4.66 1.000e+00 1.984e+00 9.839e-01 - Gypsum -0.01 -4.66 -4.65 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.558e-02 1.614e-02 - S 1.558e-02 1.614e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.681 Charge balance - pe = 8.533 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.929e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 59.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.757079e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.158e-07 4.215e-07 -6.288 -6.375 -0.088 - H+ 2.438e-07 2.087e-07 -6.613 -6.681 -0.068 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.558e-02 - Ca+2 9.822e-03 4.724e-03 -2.008 -2.326 -0.318 - CaSO4 5.760e-03 5.812e-03 -2.240 -2.236 0.004 - CaHSO4+ 1.485e-08 1.225e-08 -7.828 -7.912 -0.084 - CaOH+ 4.554e-09 3.756e-09 -8.342 -8.425 -0.084 -H(0) 3.871e-34 - H2 1.935e-34 1.953e-34 -33.713 -33.709 0.004 -O(0) 1.530e-15 - O2 7.652e-16 7.721e-16 -15.116 -15.112 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -101.498 -101.585 -0.088 - H2S 0.000e+00 0.000e+00 -101.643 -101.639 0.004 - S-2 0.000e+00 0.000e+00 -106.590 -106.915 -0.324 -S(6) 1.558e-02 - SO4-2 9.822e-03 4.637e-03 -2.008 -2.334 -0.326 - CaSO4 5.760e-03 5.812e-03 -2.240 -2.236 0.004 - HSO4- 2.615e-07 2.157e-07 -6.582 -6.666 -0.084 - CaHSO4+ 1.485e-08 1.225e-08 -7.828 -7.912 -0.084 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.66 -4.66 CaSO4 - Gypsum -0.01 -4.66 -4.65 CaSO4:2H2O - H2(g) -30.43 -33.71 -3.28 H2 - H2O(g) -0.72 -0.00 0.72 H2O - H2S(g) -100.30 -101.64 -1.34 H2S - O2(g) -12.01 -15.11 -3.10 O2 - Sulfur -75.38 -71.21 4.17 S - -Reaction step 36. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.67 -4.67 1.000e+00 1.984e+00 9.842e-01 - Gypsum -0.02 -4.67 -4.65 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.528e-02 1.583e-02 - S 1.528e-02 1.583e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.670 Charge balance - pe = 8.477 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.858e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 60.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756954e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.310e-07 4.344e-07 -6.275 -6.362 -0.087 - H+ 2.494e-07 2.136e-07 -6.603 -6.670 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.528e-02 - Ca+2 9.645e-03 4.654e-03 -2.016 -2.332 -0.316 - CaSO4 5.636e-03 5.686e-03 -2.249 -2.245 0.004 - CaHSO4+ 1.515e-08 1.250e-08 -7.820 -7.903 -0.083 - CaOH+ 4.379e-09 3.615e-09 -8.359 -8.442 -0.083 -H(0) 5.203e-34 - H2 2.602e-34 2.625e-34 -33.585 -33.581 0.004 -O(0) 1.539e-15 - O2 7.696e-16 7.765e-16 -15.114 -15.110 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -101.086 -101.173 -0.087 - H2S 0.000e+00 0.000e+00 -101.226 -101.222 0.004 - S-2 0.000e+00 0.000e+00 -106.166 -106.489 -0.323 -S(6) 1.528e-02 - SO4-2 9.644e-03 4.570e-03 -2.016 -2.340 -0.324 - CaSO4 5.636e-03 5.686e-03 -2.249 -2.245 0.004 - HSO4- 2.707e-07 2.234e-07 -6.568 -6.651 -0.083 - CaHSO4+ 1.515e-08 1.250e-08 -7.820 -7.903 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.67 -4.67 CaSO4 - Gypsum -0.02 -4.67 -4.65 CaSO4:2H2O - H2(g) -30.30 -33.58 -3.29 H2 - H2O(g) -0.70 -0.00 0.70 H2O - H2S(g) -99.87 -101.22 -1.35 H2S - O2(g) -12.01 -15.11 -3.10 O2 - Sulfur -75.08 -70.93 4.15 S - -Reaction step 37. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.69 -4.69 1.000e+00 1.984e+00 9.845e-01 - Gypsum -0.03 -4.69 -4.66 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.498e-02 1.552e-02 - S 1.498e-02 1.552e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.660 Charge balance - pe = 8.422 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.787e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 61.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756829e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.465e-07 4.476e-07 -6.262 -6.349 -0.087 - H+ 2.551e-07 2.186e-07 -6.593 -6.660 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.498e-02 - Ca+2 9.468e-03 4.584e-03 -2.024 -2.339 -0.315 - CaSO4 5.511e-03 5.559e-03 -2.259 -2.255 0.004 - CaHSO4+ 1.544e-08 1.275e-08 -7.811 -7.894 -0.083 - CaOH+ 4.211e-09 3.479e-09 -8.376 -8.459 -0.083 -H(0) 6.963e-34 - H2 3.482e-34 3.512e-34 -33.458 -33.454 0.004 -O(0) 1.557e-15 - O2 7.783e-16 7.851e-16 -15.109 -15.105 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -100.681 -100.768 -0.087 - H2S 0.000e+00 0.000e+00 -100.816 -100.812 0.004 - S-2 0.000e+00 0.000e+00 -105.748 -106.070 -0.321 -S(6) 1.498e-02 - SO4-2 9.467e-03 4.503e-03 -2.024 -2.347 -0.323 - CaSO4 5.511e-03 5.559e-03 -2.259 -2.255 0.004 - HSO4- 2.801e-07 2.314e-07 -6.553 -6.636 -0.083 - CaHSO4+ 1.544e-08 1.275e-08 -7.811 -7.894 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.69 -4.69 CaSO4 - Gypsum -0.03 -4.69 -4.66 CaSO4:2H2O - H2(g) -30.17 -33.45 -3.29 H2 - H2O(g) -0.68 -0.00 0.68 H2O - H2S(g) -99.45 -100.81 -1.36 H2S - O2(g) -12.00 -15.11 -3.11 O2 - Sulfur -74.78 -70.65 4.13 S - -Reaction step 38. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.70 -4.70 1.000e+00 1.985e+00 9.848e-01 - Gypsum -0.04 -4.70 -4.66 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.468e-02 1.521e-02 - S 1.468e-02 1.521e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.650 Charge balance - pe = 8.365 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.717e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 62.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756704e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.623e-07 4.611e-07 -6.250 -6.336 -0.086 - H+ 2.608e-07 2.236e-07 -6.584 -6.650 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.468e-02 - Ca+2 9.291e-03 4.514e-03 -2.032 -2.345 -0.314 - CaSO4 5.386e-03 5.433e-03 -2.269 -2.265 0.004 - CaHSO4+ 1.572e-08 1.300e-08 -7.803 -7.886 -0.083 - CaOH+ 4.049e-09 3.349e-09 -8.393 -8.475 -0.083 -H(0) 9.437e-34 - H2 4.719e-34 4.759e-34 -33.326 -33.322 0.004 -O(0) 1.529e-15 - O2 7.646e-16 7.712e-16 -15.117 -15.113 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -100.254 -100.340 -0.086 - H2S 0.000e+00 0.000e+00 -100.384 -100.380 0.004 - S-2 0.000e+00 0.000e+00 -105.309 -105.628 -0.320 -S(6) 1.468e-02 - SO4-2 9.291e-03 4.435e-03 -2.032 -2.353 -0.321 - CaSO4 5.386e-03 5.433e-03 -2.269 -2.265 0.004 - HSO4- 2.897e-07 2.396e-07 -6.538 -6.621 -0.083 - CaHSO4+ 1.572e-08 1.300e-08 -7.803 -7.886 -0.083 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.70 -4.70 CaSO4 - Gypsum -0.04 -4.70 -4.66 CaSO4:2H2O - H2(g) -30.03 -33.32 -3.29 H2 - H2O(g) -0.66 -0.00 0.66 H2O - H2S(g) -99.01 -100.38 -1.37 H2S - O2(g) -12.00 -15.11 -3.11 O2 - Sulfur -74.46 -70.35 4.11 S - -Reaction step 39. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.71 -4.71 1.000e+00 1.985e+00 9.851e-01 - Gypsum -0.05 -4.71 -4.67 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.438e-02 1.490e-02 - S 1.438e-02 1.490e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.641 Charge balance - pe = 8.221 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.646e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 63.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756580e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.784e-07 4.748e-07 -6.238 -6.324 -0.086 - H+ 2.666e-07 2.287e-07 -6.574 -6.641 -0.067 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.438e-02 - Ca+2 9.116e-03 4.444e-03 -2.040 -2.352 -0.312 - CaSO4 5.262e-03 5.307e-03 -2.279 -2.275 0.004 - CaHSO4+ 1.600e-08 1.325e-08 -7.796 -7.878 -0.082 - CaOH+ 3.894e-09 3.223e-09 -8.410 -8.492 -0.082 -H(0) 1.894e-33 - H2 9.471e-34 9.551e-34 -33.024 -33.020 0.004 -O(0) 6.826e-16 - O2 3.413e-16 3.442e-16 -15.467 -15.463 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -99.144 -99.230 -0.086 - H2S 0.000e+00 0.000e+00 -99.269 -99.265 0.004 - S-2 0.000e+00 0.000e+00 -104.186 -104.504 -0.318 -S(6) 1.438e-02 - SO4-2 9.115e-03 4.368e-03 -2.040 -2.360 -0.319 - CaSO4 5.262e-03 5.307e-03 -2.279 -2.275 0.004 - HSO4- 2.995e-07 2.479e-07 -6.524 -6.606 -0.082 - CaHSO4+ 1.600e-08 1.325e-08 -7.796 -7.878 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.71 -4.71 CaSO4 - Gypsum -0.05 -4.71 -4.67 CaSO4:2H2O - H2(g) -29.72 -33.02 -3.30 H2 - H2O(g) -0.64 -0.00 0.64 H2O - H2S(g) -97.89 -99.27 -1.38 H2S - O2(g) -12.35 -15.46 -3.11 O2 - Sulfur -73.64 -69.54 4.09 S - -Reaction step 40. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.73 -4.73 1.000e+00 1.985e+00 9.854e-01 - Gypsum -0.06 -4.73 -4.67 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.408e-02 1.459e-02 - S 1.408e-02 1.459e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.631 Charge balance - pe = 8.254 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.576e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 64.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756456e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.948e-07 4.888e-07 -6.226 -6.311 -0.085 - H+ 2.725e-07 2.339e-07 -6.565 -6.631 -0.066 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.408e-02 - Ca+2 8.941e-03 4.374e-03 -2.049 -2.359 -0.310 - CaSO4 5.138e-03 5.181e-03 -2.289 -2.286 0.004 - CaHSO4+ 1.628e-08 1.349e-08 -7.788 -7.870 -0.082 - CaOH+ 3.744e-09 3.102e-09 -8.427 -8.508 -0.082 -H(0) 1.693e-33 - H2 8.466e-34 8.536e-34 -33.072 -33.069 0.004 -O(0) 1.531e-15 - O2 7.655e-16 7.718e-16 -15.116 -15.112 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -99.439 -99.524 -0.085 - H2S 0.000e+00 0.000e+00 -99.559 -99.555 0.004 - S-2 0.000e+00 0.000e+00 -104.469 -104.785 -0.316 -S(6) 1.408e-02 - SO4-2 8.941e-03 4.301e-03 -2.049 -2.366 -0.318 - CaSO4 5.138e-03 5.181e-03 -2.289 -2.286 0.004 - HSO4- 3.096e-07 2.565e-07 -6.509 -6.591 -0.082 - CaHSO4+ 1.628e-08 1.349e-08 -7.788 -7.870 -0.082 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.73 -4.73 CaSO4 - Gypsum -0.06 -4.73 -4.67 CaSO4:2H2O - H2(g) -29.77 -33.07 -3.30 H2 - H2O(g) -0.62 -0.00 0.62 H2O - H2S(g) -98.17 -99.56 -1.38 H2S - O2(g) -12.00 -15.11 -3.12 O2 - Sulfur -73.86 -69.79 4.08 S - -Reaction step 41. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.74 -4.74 1.000e+00 1.986e+00 9.857e-01 - Gypsum -0.07 -4.74 -4.67 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.378e-02 1.428e-02 - S 1.378e-02 1.428e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.621 Charge balance - pe = 8.199 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.507e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 65.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756333e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.114e-07 5.030e-07 -6.214 -6.298 -0.085 - H+ 2.785e-07 2.392e-07 -6.555 -6.621 -0.066 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.378e-02 - Ca+2 8.767e-03 4.305e-03 -2.057 -2.366 -0.309 - CaSO4 5.015e-03 5.056e-03 -2.300 -2.296 0.004 - CaHSO4+ 1.656e-08 1.373e-08 -7.781 -7.862 -0.081 - CaOH+ 3.600e-09 2.986e-09 -8.444 -8.525 -0.081 -H(0) 2.266e-33 - H2 1.133e-33 1.142e-33 -32.946 -32.942 0.004 -O(0) 1.527e-15 - O2 7.634e-16 7.696e-16 -15.117 -15.114 0.004 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -99.033 -99.117 -0.085 - H2S 0.000e+00 0.000e+00 -99.147 -99.144 0.004 - S-2 0.000e+00 0.000e+00 -104.050 -104.365 -0.315 -S(6) 1.378e-02 - SO4-2 8.767e-03 4.234e-03 -2.057 -2.373 -0.316 - CaSO4 5.015e-03 5.056e-03 -2.300 -2.296 0.004 - HSO4- 3.199e-07 2.653e-07 -6.495 -6.576 -0.081 - CaHSO4+ 1.656e-08 1.373e-08 -7.781 -7.862 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.74 -4.74 CaSO4 - Gypsum -0.07 -4.74 -4.67 CaSO4:2H2O - H2(g) -29.64 -32.94 -3.30 H2 - H2O(g) -0.60 -0.00 0.60 H2O - H2S(g) -97.75 -99.14 -1.39 H2S - O2(g) -11.99 -15.11 -3.12 O2 - Sulfur -73.56 -69.50 4.06 S - -Reaction step 42. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.75 -4.75 1.000e+00 1.986e+00 9.860e-01 - Gypsum -0.08 -4.75 -4.68 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.349e-02 1.397e-02 - S 1.349e-02 1.397e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.612 Charge balance - pe = 8.055 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.438e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 66.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.756211e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.283e-07 5.176e-07 -6.202 -6.286 -0.084 - H+ 2.845e-07 2.445e-07 -6.546 -6.612 -0.066 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.349e-02 - Ca+2 8.594e-03 4.236e-03 -2.066 -2.373 -0.307 - CaSO4 4.893e-03 4.931e-03 -2.310 -2.307 0.003 - CaHSO4+ 1.683e-08 1.397e-08 -7.774 -7.855 -0.081 - CaOH+ 3.462e-09 2.874e-09 -8.461 -8.541 -0.081 -H(0) 4.558e-33 - H2 2.279e-33 2.297e-33 -32.642 -32.639 0.003 -O(0) 6.716e-16 - O2 3.358e-16 3.384e-16 -15.474 -15.471 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -97.918 -98.002 -0.084 - H2S 0.000e+00 0.000e+00 -98.027 -98.024 0.003 - S-2 0.000e+00 0.000e+00 -102.923 -103.236 -0.313 -S(6) 1.349e-02 - SO4-2 8.594e-03 4.167e-03 -2.066 -2.380 -0.314 - CaSO4 4.893e-03 4.931e-03 -2.310 -2.307 0.003 - HSO4- 3.304e-07 2.743e-07 -6.481 -6.562 -0.081 - CaHSO4+ 1.683e-08 1.397e-08 -7.774 -7.855 -0.081 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.75 -4.75 CaSO4 - Gypsum -0.08 -4.75 -4.68 CaSO4:2H2O - H2(g) -29.33 -32.64 -3.31 H2 - H2O(g) -0.58 -0.00 0.58 H2O - H2S(g) -96.62 -98.02 -1.40 H2S - O2(g) -12.35 -15.47 -3.12 O2 - Sulfur -72.73 -68.69 4.04 S - -Reaction step 43. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.77 -4.77 1.000e+00 1.986e+00 9.863e-01 - Gypsum -0.09 -4.77 -4.68 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.319e-02 1.367e-02 - S 1.319e-02 1.367e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.602 Charge balance - pe = 8.092 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.369e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 67.000 - Electrical balance (eq) = -1.080e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.756089e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.456e-07 5.324e-07 -6.190 -6.274 -0.084 - H+ 2.905e-07 2.499e-07 -6.537 -6.602 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.319e-02 - Ca+2 8.423e-03 4.167e-03 -2.075 -2.380 -0.306 - CaSO4 4.771e-03 4.808e-03 -2.321 -2.318 0.003 - CaHSO4+ 1.709e-08 1.420e-08 -7.767 -7.848 -0.080 - CaOH+ 3.329e-09 2.766e-09 -8.478 -8.558 -0.080 -H(0) 3.979e-33 - H2 1.990e-33 2.005e-33 -32.701 -32.698 0.003 -O(0) 1.562e-15 - O2 7.812e-16 7.873e-16 -15.107 -15.104 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -98.253 -98.336 -0.084 - H2S 0.000e+00 0.000e+00 -98.356 -98.353 0.003 - S-2 0.000e+00 0.000e+00 -103.246 -103.557 -0.311 -S(6) 1.319e-02 - SO4-2 8.422e-03 4.101e-03 -2.075 -2.387 -0.313 - CaSO4 4.771e-03 4.808e-03 -2.321 -2.318 0.003 - HSO4- 3.412e-07 2.835e-07 -6.467 -6.547 -0.080 - CaHSO4+ 1.709e-08 1.420e-08 -7.767 -7.848 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.77 -4.77 CaSO4 - Gypsum -0.09 -4.77 -4.68 CaSO4:2H2O - H2(g) -29.39 -32.70 -3.31 H2 - H2O(g) -0.56 -0.00 0.56 H2O - H2S(g) -96.94 -98.35 -1.41 H2S - O2(g) -11.98 -15.10 -3.13 O2 - Sulfur -72.99 -68.96 4.02 S - -Reaction step 44. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.78 -4.78 1.000e+00 1.987e+00 9.866e-01 - Gypsum -0.10 -4.78 -4.69 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.290e-02 1.337e-02 - S 1.290e-02 1.337e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.593 Charge balance - pe = 8.038 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.301e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 68.000 - Electrical balance (eq) = -1.073e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.755969e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.631e-07 5.475e-07 -6.178 -6.262 -0.083 - H+ 2.966e-07 2.553e-07 -6.528 -6.593 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.290e-02 - Ca+2 8.252e-03 4.098e-03 -2.083 -2.387 -0.304 - CaSO4 4.650e-03 4.685e-03 -2.333 -2.329 0.003 - CaHSO4+ 1.735e-08 1.443e-08 -7.761 -7.841 -0.080 - CaOH+ 3.201e-09 2.663e-09 -8.495 -8.575 -0.080 -H(0) 5.280e-33 - H2 2.640e-33 2.660e-33 -32.578 -32.575 0.003 -O(0) 1.569e-15 - O2 7.846e-16 7.906e-16 -15.105 -15.102 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -97.860 -97.943 -0.083 - H2S 0.000e+00 0.000e+00 -97.958 -97.955 0.003 - S-2 0.000e+00 0.000e+00 -102.841 -103.150 -0.309 -S(6) 1.290e-02 - SO4-2 8.252e-03 4.034e-03 -2.083 -2.394 -0.311 - CaSO4 4.650e-03 4.685e-03 -2.333 -2.329 0.003 - HSO4- 3.522e-07 2.929e-07 -6.453 -6.533 -0.080 - CaHSO4+ 1.735e-08 1.443e-08 -7.761 -7.841 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.78 -4.78 CaSO4 - Gypsum -0.10 -4.78 -4.69 CaSO4:2H2O - H2(g) -29.26 -32.58 -3.31 H2 - H2O(g) -0.54 -0.00 0.54 H2O - H2S(g) -96.54 -97.95 -1.42 H2S - O2(g) -11.97 -15.10 -3.13 O2 - Sulfur -72.70 -68.69 4.00 S - -Reaction step 45. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.80 -4.80 1.000e+00 1.987e+00 9.869e-01 - Gypsum -0.11 -4.80 -4.69 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.261e-02 1.307e-02 - S 1.261e-02 1.307e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.584 Charge balance - pe = 7.985 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.233e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 69.000 - Electrical balance (eq) = -1.068e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.755849e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.808e-07 5.628e-07 -6.167 -6.250 -0.083 - H+ 3.028e-07 2.608e-07 -6.519 -6.584 -0.065 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -Ca 1.261e-02 - Ca+2 8.083e-03 4.029e-03 -2.092 -2.395 -0.302 - CaSO4 4.530e-03 4.564e-03 -2.344 -2.341 0.003 - CaHSO4+ 1.760e-08 1.466e-08 -7.754 -7.834 -0.080 - CaOH+ 3.078e-09 2.563e-09 -8.512 -8.591 -0.080 -H(0) 6.996e-33 - H2 3.498e-33 3.524e-33 -32.456 -32.453 0.003 -O(0) 1.575e-15 - O2 7.874e-16 7.932e-16 -15.104 -15.101 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -97.469 -97.552 -0.083 - H2S 0.000e+00 0.000e+00 -97.562 -97.558 0.003 - S-2 0.000e+00 0.000e+00 -102.438 -102.746 -0.308 -S(6) 1.261e-02 - SO4-2 8.083e-03 3.968e-03 -2.092 -2.401 -0.309 - CaSO4 4.530e-03 4.564e-03 -2.344 -2.341 0.003 - HSO4- 3.634e-07 3.026e-07 -6.440 -6.519 -0.080 - CaHSO4+ 1.760e-08 1.466e-08 -7.754 -7.834 -0.080 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.80 -4.80 CaSO4 - Gypsum -0.11 -4.80 -4.69 CaSO4:2H2O - H2(g) -29.14 -32.45 -3.32 H2 - H2O(g) -0.52 -0.00 0.52 H2O - H2S(g) -96.13 -97.56 -1.43 H2S - O2(g) -11.97 -15.10 -3.13 O2 - Sulfur -72.41 -68.42 3.99 S - -Reaction step 46. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.81 -4.81 1.000e+00 1.987e+00 9.872e-01 - Gypsum -0.12 -4.81 -4.69 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.233e-02 1.277e-02 - S 1.233e-02 1.277e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.574 Charge balance - pe = 7.930 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.166e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 70.000 - Electrical balance (eq) = -1.062e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.755730e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.989e-07 5.785e-07 -6.156 -6.238 -0.082 - H+ 3.091e-07 2.664e-07 -6.510 -6.574 -0.065 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.233e-02 - Ca+2 7.916e-03 3.961e-03 -2.101 -2.402 -0.301 - CaSO4 4.411e-03 4.444e-03 -2.355 -2.352 0.003 - CaHSO4+ 1.785e-08 1.488e-08 -7.748 -7.827 -0.079 - CaOH+ 2.959e-09 2.467e-09 -8.529 -8.608 -0.079 -H(0) 9.312e-33 - H2 4.656e-33 4.690e-33 -32.332 -32.329 0.003 -O(0) 1.561e-15 - O2 7.805e-16 7.862e-16 -15.108 -15.104 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -97.070 -97.152 -0.082 - H2S 0.000e+00 0.000e+00 -97.157 -97.154 0.003 - S-2 0.000e+00 0.000e+00 -102.027 -102.333 -0.306 -S(6) 1.233e-02 - SO4-2 7.916e-03 3.902e-03 -2.102 -2.409 -0.307 - CaSO4 4.411e-03 4.444e-03 -2.355 -2.352 0.003 - HSO4- 3.748e-07 3.125e-07 -6.426 -6.505 -0.079 - CaHSO4+ 1.785e-08 1.488e-08 -7.748 -7.827 -0.079 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.81 -4.81 CaSO4 - Gypsum -0.12 -4.81 -4.69 CaSO4:2H2O - H2(g) -29.01 -32.33 -3.32 H2 - H2O(g) -0.50 -0.00 0.50 H2O - H2S(g) -95.72 -97.15 -1.44 H2S - O2(g) -11.97 -15.10 -3.14 O2 - Sulfur -72.11 -68.14 3.97 S - -Reaction step 47. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.83 -4.83 1.000e+00 1.988e+00 9.875e-01 - Gypsum -0.13 -4.83 -4.70 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.204e-02 1.248e-02 - S 1.204e-02 1.248e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.565 Charge balance - pe = 7.877 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.100e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 71.000 - Electrical balance (eq) = -1.058e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.755613e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.173e-07 5.944e-07 -6.144 -6.226 -0.082 - H+ 3.154e-07 2.720e-07 -6.501 -6.565 -0.064 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.204e-02 - Ca+2 7.750e-03 3.893e-03 -2.111 -2.410 -0.299 - CaSO4 4.294e-03 4.325e-03 -2.367 -2.364 0.003 - CaHSO4+ 1.809e-08 1.510e-08 -7.742 -7.821 -0.079 - CaOH+ 2.846e-09 2.375e-09 -8.546 -8.624 -0.079 -H(0) 1.231e-32 - H2 6.154e-33 6.198e-33 -32.211 -32.208 0.003 -O(0) 1.564e-15 - O2 7.818e-16 7.874e-16 -15.107 -15.104 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -96.683 -96.764 -0.082 - H2S 0.000e+00 0.000e+00 -96.764 -96.761 0.003 - S-2 0.000e+00 0.000e+00 -101.628 -101.932 -0.304 -S(6) 1.204e-02 - SO4-2 7.750e-03 3.837e-03 -2.111 -2.416 -0.305 - CaSO4 4.294e-03 4.325e-03 -2.367 -2.364 0.003 - HSO4- 3.865e-07 3.225e-07 -6.413 -6.491 -0.079 - CaHSO4+ 1.809e-08 1.510e-08 -7.742 -7.821 -0.079 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.83 -4.83 CaSO4 - Gypsum -0.13 -4.83 -4.70 CaSO4:2H2O - H2(g) -28.89 -32.21 -3.32 H2 - H2O(g) -0.48 -0.00 0.48 H2O - H2S(g) -95.32 -96.76 -1.44 H2S - O2(g) -11.96 -15.10 -3.14 O2 - Sulfur -71.83 -67.88 3.95 S - -Reaction step 48. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.84 -4.84 1.000e+00 1.988e+00 9.878e-01 - Gypsum -0.14 -4.84 -4.70 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.176e-02 1.219e-02 - S 1.176e-02 1.219e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.556 Charge balance - pe = 7.824 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.034e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 72.000 - Electrical balance (eq) = -1.056e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.150124e+02 - Total O = 5.755497e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.359e-07 6.106e-07 -6.133 -6.214 -0.081 - H+ 3.218e-07 2.777e-07 -6.492 -6.556 -0.064 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.176e-02 - Ca+2 7.586e-03 3.826e-03 -2.120 -2.417 -0.297 - CaSO4 4.178e-03 4.207e-03 -2.379 -2.376 0.003 - CaHSO4+ 1.833e-08 1.531e-08 -7.737 -7.815 -0.078 - CaOH+ 2.736e-09 2.286e-09 -8.563 -8.641 -0.078 -H(0) 1.624e-32 - H2 8.122e-33 8.179e-33 -32.090 -32.087 0.003 -O(0) 1.566e-15 - O2 7.832e-16 7.887e-16 -15.106 -15.103 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -96.298 -96.379 -0.081 - H2S 0.000e+00 0.000e+00 -96.373 -96.370 0.003 - S-2 0.000e+00 0.000e+00 -101.231 -101.533 -0.302 -S(6) 1.176e-02 - SO4-2 7.585e-03 3.772e-03 -2.120 -2.423 -0.303 - CaSO4 4.178e-03 4.207e-03 -2.379 -2.376 0.003 - HSO4- 3.984e-07 3.328e-07 -6.400 -6.478 -0.078 - CaHSO4+ 1.833e-08 1.531e-08 -7.737 -7.815 -0.078 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.84 -4.84 CaSO4 - Gypsum -0.14 -4.84 -4.70 CaSO4:2H2O - H2(g) -28.76 -32.09 -3.33 H2 - H2O(g) -0.46 -0.00 0.46 H2O - H2S(g) -94.92 -96.37 -1.45 H2S - O2(g) -11.96 -15.10 -3.14 O2 - Sulfur -71.54 -67.61 3.93 S - -Reaction step 49. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.86 -4.86 1.000e+00 1.988e+00 9.881e-01 - Gypsum -0.15 -4.86 -4.71 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.149e-02 1.190e-02 - S 1.149e-02 1.190e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.547 Charge balance - pe = 7.769 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.969e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 73.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.755382e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.548e-07 6.271e-07 -6.122 -6.203 -0.081 - H+ 3.282e-07 2.835e-07 -6.484 -6.547 -0.064 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.149e-02 - Ca+2 7.423e-03 3.759e-03 -2.129 -2.425 -0.295 - CaSO4 4.063e-03 4.091e-03 -2.391 -2.388 0.003 - CaHSO4+ 1.856e-08 1.552e-08 -7.731 -7.809 -0.078 - CaOH+ 2.631e-09 2.200e-09 -8.580 -8.658 -0.078 -H(0) 2.169e-32 - H2 1.084e-32 1.092e-32 -31.965 -31.962 0.003 -O(0) 1.528e-15 - O2 7.641e-16 7.694e-16 -15.117 -15.114 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -95.892 -95.973 -0.081 - H2S 0.000e+00 0.000e+00 -95.962 -95.959 0.003 - S-2 0.000e+00 0.000e+00 -100.813 -101.114 -0.300 -S(6) 1.149e-02 - SO4-2 7.423e-03 3.707e-03 -2.129 -2.431 -0.302 - CaSO4 4.063e-03 4.091e-03 -2.391 -2.388 0.003 - HSO4- 4.106e-07 3.434e-07 -6.387 -6.464 -0.078 - CaHSO4+ 1.856e-08 1.552e-08 -7.731 -7.809 -0.078 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.86 -4.86 CaSO4 - Gypsum -0.15 -4.86 -4.71 CaSO4:2H2O - H2(g) -28.63 -31.96 -3.33 H2 - H2O(g) -0.44 -0.00 0.44 H2O - H2S(g) -94.50 -95.96 -1.46 H2S - O2(g) -11.97 -15.11 -3.15 O2 - Sulfur -71.24 -67.33 3.92 S - -Reaction step 50. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.87 -4.87 1.000e+00 1.988e+00 9.884e-01 - Gypsum -0.16 -4.87 -4.71 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.121e-02 1.162e-02 - S 1.121e-02 1.162e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.539 Charge balance - pe = 7.717 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.905e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 74.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.755268e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.741e-07 6.439e-07 -6.111 -6.191 -0.080 - H+ 3.347e-07 2.893e-07 -6.475 -6.539 -0.063 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.121e-02 - Ca+2 7.263e-03 3.693e-03 -2.139 -2.433 -0.294 - CaSO4 3.950e-03 3.976e-03 -2.403 -2.401 0.003 - CaHSO4+ 1.878e-08 1.572e-08 -7.726 -7.803 -0.077 - CaOH+ 2.530e-09 2.118e-09 -8.597 -8.674 -0.077 -H(0) 2.852e-32 - H2 1.426e-32 1.436e-32 -31.846 -31.843 0.003 -O(0) 1.531e-15 - O2 7.657e-16 7.709e-16 -15.116 -15.113 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -95.513 -95.593 -0.080 - H2S 0.000e+00 0.000e+00 -95.576 -95.573 0.003 - S-2 0.000e+00 0.000e+00 -100.421 -100.720 -0.299 -S(6) 1.121e-02 - SO4-2 7.262e-03 3.642e-03 -2.139 -2.439 -0.300 - CaSO4 3.950e-03 3.976e-03 -2.403 -2.401 0.003 - HSO4- 4.230e-07 3.541e-07 -6.374 -6.451 -0.077 - CaHSO4+ 1.878e-08 1.572e-08 -7.726 -7.803 -0.077 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.87 -4.87 CaSO4 - Gypsum -0.16 -4.87 -4.71 CaSO4:2H2O - H2(g) -28.51 -31.84 -3.33 H2 - H2O(g) -0.42 -0.00 0.42 H2O - H2S(g) -94.10 -95.57 -1.47 H2S - O2(g) -11.96 -15.11 -3.15 O2 - Sulfur -70.96 -67.06 3.90 S - -Reaction step 51. - -Using solution 1. Pure water -Using pure phase assemblage 1. -Using temperature 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Anhydrite 0.00 -4.89 -4.89 1.000e+00 1.989e+00 9.887e-01 - Gypsum -0.17 -4.89 -4.72 1.000e+00 -1.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Ca 1.094e-02 1.134e-02 - S 1.094e-02 1.134e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.530 Charge balance - pe = 7.664 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.841e-02 - Mass of water (kg) = 1.036e+00 - Total alkalinity (eq/kg) = 1.044e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 75.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 17 - Total H = 1.150124e+02 - Total O = 5.755156e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.935e-07 6.609e-07 -6.100 -6.180 -0.079 - H+ 3.412e-07 2.952e-07 -6.467 -6.530 -0.063 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Ca 1.094e-02 - Ca+2 7.104e-03 3.627e-03 -2.149 -2.440 -0.292 - CaSO4 3.838e-03 3.863e-03 -2.416 -2.413 0.003 - CaHSO4+ 1.900e-08 1.592e-08 -7.721 -7.798 -0.077 - CaOH+ 2.432e-09 2.039e-09 -8.614 -8.691 -0.077 -H(0) 3.754e-32 - H2 1.877e-32 1.889e-32 -31.727 -31.724 0.003 -O(0) 1.528e-15 - O2 7.641e-16 7.691e-16 -15.117 -15.114 0.003 -S(-2) 0.000e+00 - HS- 0.000e+00 0.000e+00 -95.131 -95.211 -0.079 - H2S 0.000e+00 0.000e+00 -95.188 -95.185 0.003 - S-2 0.000e+00 0.000e+00 -100.028 -100.325 -0.297 -S(6) 1.094e-02 - SO4-2 7.103e-03 3.579e-03 -2.149 -2.446 -0.298 - CaSO4 3.838e-03 3.863e-03 -2.416 -2.413 0.003 - HSO4- 4.356e-07 3.651e-07 -6.361 -6.438 -0.077 - CaHSO4+ 1.900e-08 1.592e-08 -7.721 -7.798 -0.077 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite 0.00 -4.89 -4.89 CaSO4 - Gypsum -0.17 -4.89 -4.72 CaSO4:2H2O - H2(g) -28.39 -31.72 -3.34 H2 - H2O(g) -0.40 -0.00 0.40 H2O - H2S(g) -93.71 -95.19 -1.48 H2S - O2(g) -11.96 -15.11 -3.15 O2 - Sulfur -70.68 -66.80 3.88 S - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex2.sel b/Sun/examples/ex2.sel deleted file mode 100644 index 6c7eed43..00000000 --- a/Sun/examples/ex2.sel +++ /dev/null @@ -1,53 +0,0 @@ - sim state soln dist_x time step pH pe temp si_anhydrite si_gypsum - 1 i_soln 1 -99 -99 -99 7 4 25.000 -999.9990 -999.9990 - 1 react 1 -99 0 1 7.06676 10.6862 25.000 -0.2197 0.0000 - 1 react 1 -99 0 2 7.05329 10.6168 26.000 -0.2157 0.0000 - 1 react 1 -99 0 3 7.03993 10.5719 27.000 -0.2115 0.0000 - 1 react 1 -99 0 4 7.02667 10.4793 28.000 -0.2071 0.0000 - 1 react 1 -99 0 5 7.01353 10.4109 29.000 -0.2025 0.0000 - 1 react 1 -99 0 6 7.00051 10.3439 30.000 -0.1977 0.0000 - 1 react 1 -99 0 7 6.9876 10.2766 31.000 -0.1928 0.0000 - 1 react 1 -99 0 8 6.97482 10.2099 32.000 -0.1877 0.0000 - 1 react 1 -99 0 9 6.96217 10.149 33.000 -0.1824 0.0000 - 1 react 1 -99 0 10 6.94965 10.0785 34.000 -0.1769 0.0000 - 1 react 1 -99 0 11 6.93726 10.0131 35.000 -0.1713 0.0000 - 1 react 1 -99 0 12 6.925 9.94603 36.000 -0.1655 0.0000 - 1 react 1 -99 0 13 6.91288 9.88397 37.000 -0.1595 0.0000 - 1 react 1 -99 0 14 6.90089 9.86516 38.000 -0.1533 0.0000 - 1 react 1 -99 0 15 6.88905 9.75536 39.000 -0.1470 0.0000 - 1 react 1 -99 0 16 6.87734 9.69233 40.000 -0.1406 0.0000 - 1 react 1 -99 0 17 6.86578 9.62865 41.000 -0.1340 0.0000 - 1 react 1 -99 0 18 6.85435 9.56448 42.000 -0.1272 0.0000 - 1 react 1 -99 0 19 6.84307 9.50323 43.000 -0.1203 0.0000 - 1 react 1 -99 0 20 6.83193 9.44484 44.000 -0.1132 0.0000 - 1 react 1 -99 0 21 6.82093 9.37869 45.000 -0.1060 0.0000 - 1 react 1 -99 0 22 6.81008 9.31598 46.000 -0.0986 0.0000 - 1 react 1 -99 0 23 6.79936 9.25548 47.000 -0.0911 0.0000 - 1 react 1 -99 0 24 6.78879 9.19236 48.000 -0.0835 0.0000 - 1 react 1 -99 0 25 6.77836 9.14193 49.000 -0.0757 0.0000 - 1 react 1 -99 0 26 6.76807 9.07059 50.000 -0.0678 0.0000 - 1 react 1 -99 0 27 6.75793 9.01241 51.000 -0.0597 0.0000 - 1 react 1 -99 0 28 6.74792 8.95269 52.000 -0.0515 0.0000 - 1 react 1 -99 0 29 6.73806 8.89104 53.000 -0.0432 0.0000 - 1 react 1 -99 0 30 6.72833 8.83437 54.000 -0.0347 0.0000 - 1 react 1 -99 0 31 6.71874 8.77256 55.000 -0.0261 0.0000 - 1 react 1 -99 0 32 6.7093 8.71589 56.000 -0.0174 0.0000 - 1 react 1 -99 0 33 6.69999 8.65867 57.000 -0.0085 0.0000 - 1 react 1 -99 0 34 6.69076 8.59025 58.000 0.0000 -0.0004 - 1 react 1 -99 0 35 6.68054 8.53312 59.000 0.0000 -0.0095 - 1 react 1 -99 0 36 6.67043 8.4773 60.000 0.0000 -0.0187 - 1 react 1 -99 0 37 6.66041 8.42236 61.000 0.0000 -0.0280 - 1 react 1 -99 0 38 6.65049 8.36458 62.000 0.0000 -0.0375 - 1 react 1 -99 0 39 6.64066 8.22145 63.000 0.0000 -0.0471 - 1 react 1 -99 0 40 6.63093 8.25388 64.000 0.0000 -0.0567 - 1 react 1 -99 0 41 6.62129 8.1986 65.000 0.0000 -0.0665 - 1 react 1 -99 0 42 6.61175 8.05474 66.000 0.0000 -0.0764 - 1 react 1 -99 0 43 6.6023 8.09202 67.000 0.0000 -0.0864 - 1 react 1 -99 0 44 6.59294 8.03836 68.000 0.0000 -0.0966 - 1 react 1 -99 0 45 6.58367 7.98491 69.000 0.0000 -0.1068 - 1 react 1 -99 0 46 6.57449 7.93039 70.000 0.0000 -0.1171 - 1 react 1 -99 0 47 6.5654 7.87729 71.000 0.0000 -0.1276 - 1 react 1 -99 0 48 6.55641 7.82446 72.000 0.0000 -0.1381 - 1 react 1 -99 0 49 6.5475 7.76904 73.000 0.0000 -0.1488 - 1 react 1 -99 0 50 6.53867 7.71679 74.000 0.0000 -0.1595 - 1 react 1 -99 0 51 6.52994 7.66434 75.000 0.0000 -0.1704 diff --git a/Sun/examples/ex3.log b/Sun/examples/ex3.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex3.out b/Sun/examples/ex3.out deleted file mode 100644 index c04b11b6..00000000 --- a/Sun/examples/ex3.out +++ /dev/null @@ -1,789 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex3 - Output file: ex3.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 3, part A.--Calcite equilibrium at log Pco2 = -2.0 and 25C. - SOLUTION 1 Pure water - pH 7.0 - temp 25.0 - EQUILIBRIUM_PHASES - CO2(g) -2.0 - Calcite 0.0 - SAVE solution 1 - END ------ -TITLE ------ - - Example 3, part A.--Calcite equilibrium at log Pco2 = -2.0 and 25C. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Pure water - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Pure water - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.082e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 - H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 -H(0) 1.416e-25 - H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 0.00 1.51 H2O - O2(g) -39.12 -42.08 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Pure water -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.998e+00 -1.646e-03 - CO2(g) -2.00 -20.15 -18.15 1.000e+01 9.998e+00 -1.976e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 3.622e-03 3.622e-03 - Ca 1.646e-03 1.646e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.297 Charge balance - pe = -0.987 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.826e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.291e-03 - Total CO2 (mol/kg) = 3.622e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.110124e+02 - Total O = 5.551511e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.137e-07 1.982e-07 -6.670 -6.703 -0.033 - H+ 5.403e-08 5.050e-08 -7.267 -7.297 -0.029 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 2.799e-30 - CH4 2.799e-30 2.802e-30 -29.553 -29.552 0.000 -C(4) 3.622e-03 - HCO3- 3.224e-03 2.998e-03 -2.492 -2.523 -0.032 - CO2 3.401e-04 3.405e-04 -3.468 -3.468 0.000 - CaHCO3+ 4.894e-05 4.551e-05 -4.310 -4.342 -0.032 - CaCO3 5.559e-06 5.565e-06 -5.255 -5.255 0.000 - CO3-2 3.721e-06 2.784e-06 -5.429 -5.555 -0.126 -Ca 1.646e-03 - Ca+2 1.591e-03 1.190e-03 -2.798 -2.925 -0.126 - CaHCO3+ 4.894e-05 4.551e-05 -4.310 -4.342 -0.032 - CaCO3 5.559e-06 5.565e-06 -5.255 -5.255 0.000 - CaOH+ 4.212e-09 3.910e-09 -8.376 -8.408 -0.032 -H(0) 3.403e-16 - H2 1.701e-16 1.703e-16 -15.769 -15.769 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -60.843 -60.843 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -26.69 -29.55 -2.86 CH4 - CO2(g) -2.00 -3.47 -1.47 CO2 - H2(g) -12.62 -15.77 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -57.88 -60.84 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - TITLE Example 3, part B.--Definition of seawater. - SOLUTION 2 Seawater - units ppm - pH 8.22 - pe 8.451 - density 1.023 - temp 25.0 - Ca 412.3 - Mg 1291.8 - Na 10768.0 - K 399.1 - Si 4.28 - Cl 19353.0 - Alkalinity 141.682 as HCO3 - S(6) 2712.0 - END ------ -TITLE ------ - - Example 3, part B.--Definition of seawater. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 2. Seawater - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Alkalinity 2.406e-03 2.406e-03 - Ca 1.066e-02 1.066e-02 - Cl 5.657e-01 5.657e-01 - K 1.058e-02 1.058e-02 - Mg 5.507e-02 5.507e-02 - Na 4.854e-01 4.854e-01 - S(6) 2.926e-02 2.926e-02 - Si 7.382e-05 7.382e-05 - -----------------------------Description of solution---------------------------- - - pH = 8.220 - pe = 8.451 - Activity of water = 0.981 - Ionic strength = 6.748e-01 - Mass of water (kg) = 1.000e+00 - Total carbon (mol/kg) = 2.180e-03 - Total CO2 (mol/kg) = 2.180e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.967e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.07 - Iterations = 7 - Total H = 1.110147e+02 - Total O = 5.563008e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.674e-06 1.629e-06 -5.573 -5.788 -0.215 - H+ 7.981e-09 6.026e-09 -8.098 -8.220 -0.122 - H2O 5.551e+01 9.806e-01 1.744 -0.009 0.000 -C(4) 2.180e-03 - HCO3- 1.514e-03 1.023e-03 -2.820 -2.990 -0.170 - MgHCO3+ 2.196e-04 1.640e-04 -3.658 -3.785 -0.127 - NaHCO3 1.668e-04 1.948e-04 -3.778 -3.710 0.067 - MgCO3 8.914e-05 1.041e-04 -4.050 -3.982 0.067 - NaCO3- 6.719e-05 5.020e-05 -4.173 -4.299 -0.127 - CaHCO3+ 4.598e-05 3.106e-05 -4.337 -4.508 -0.170 - CO3-2 3.821e-05 7.960e-06 -4.418 -5.099 -0.681 - CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 - CO2 1.210e-05 1.413e-05 -4.917 -4.850 0.067 -Ca 1.066e-02 - Ca+2 9.504e-03 2.380e-03 -2.022 -2.623 -0.601 - CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 - CaHCO3+ 4.598e-05 3.106e-05 -4.337 -4.508 -0.170 - CaCO3 2.725e-05 3.183e-05 -4.565 -4.497 0.067 - CaOH+ 8.604e-08 6.429e-08 -7.065 -7.192 -0.127 - CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 -Cl 5.657e-01 - Cl- 5.657e-01 3.528e-01 -0.247 -0.452 -0.205 -H(0) 5.515e-37 - H2 2.757e-37 3.221e-37 -36.559 -36.492 0.067 -K 1.058e-02 - K+ 1.041e-02 6.495e-03 -1.982 -2.187 -0.205 - KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 - KOH 3.137e-09 3.665e-09 -8.503 -8.436 0.067 -Mg 5.507e-02 - Mg+2 4.742e-02 1.371e-02 -1.324 -1.863 -0.539 - MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 - MgHCO3+ 2.196e-04 1.640e-04 -3.658 -3.785 -0.127 - MgCO3 8.914e-05 1.041e-04 -4.050 -3.982 0.067 - MgOH+ 1.084e-05 8.100e-06 -4.965 -5.092 -0.127 -Na 4.854e-01 - Na+ 4.791e-01 3.387e-01 -0.320 -0.470 -0.151 - NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 - NaHCO3 1.668e-04 1.948e-04 -3.778 -3.710 0.067 - NaCO3- 6.719e-05 5.020e-05 -4.173 -4.299 -0.127 - NaOH 3.117e-07 3.641e-07 -6.506 -6.439 0.067 -O(0) 6.614e-20 - O2 3.307e-20 3.863e-20 -19.481 -19.413 0.067 -S(6) 2.926e-02 - SO4-2 1.463e-02 2.664e-03 -1.835 -2.574 -0.740 - MgSO4 7.330e-03 8.562e-03 -2.135 -2.067 0.067 - NaSO4- 6.053e-03 4.523e-03 -2.218 -2.345 -0.127 - CaSO4 1.083e-03 1.266e-03 -2.965 -2.898 0.067 - KSO4- 1.627e-04 1.216e-04 -3.789 -3.915 -0.127 - HSO4- 2.089e-09 1.561e-09 -8.680 -8.807 -0.127 - CaHSO4+ 5.979e-11 4.467e-11 -10.223 -10.350 -0.127 -Si 7.382e-05 - H4SiO4 7.110e-05 8.306e-05 -4.148 -4.081 0.067 - H3SiO4- 2.720e-06 2.032e-06 -5.565 -5.692 -0.127 - H2SiO4-2 7.362e-11 2.294e-11 -10.133 -10.639 -0.506 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.84 -5.20 -4.36 CaSO4 - Aragonite 0.61 -7.72 -8.34 CaCO3 - Calcite 0.76 -7.72 -8.48 CaCO3 - Chalcedony -0.51 -4.06 -3.55 SiO2 - Chrysotile 3.36 35.56 32.20 Mg3Si2O5(OH)4 - CO2(g) -3.38 -4.85 -1.47 CO2 - Dolomite 2.41 -14.68 -17.09 CaMg(CO3)2 - Gypsum -0.63 -5.21 -4.58 CaSO4:2H2O - H2(g) -33.34 -36.49 -3.15 H2 - H2O(g) -1.52 -0.01 1.51 H2O - Halite -2.50 -0.92 1.58 NaCl - O2(g) -16.45 -19.41 -2.96 O2 - Quartz -0.08 -4.06 -3.98 SiO2 - Sepiolite 1.16 16.92 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -1.74 16.92 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -1.35 -4.06 -2.71 SiO2 - Talc 6.04 27.44 21.40 Mg3Si4O10(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - TITLE Example 3, part C.--Mix 70% ground water, 30% seawater. - MIX 1 - 1 0.7 - 2 0.3 - SAVE solution 3 - END ------ -TITLE ------ - - Example 3, part C.--Mix 70% ground water, 30% seawater. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using mix 1. - -Mixture 1. - - 7.000e-01 Solution 1 Solution after simulation 1. - 3.000e-01 Solution 2 Seawater - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 3.189e-03 3.189e-03 - Ca 4.350e-03 4.350e-03 - Cl 1.697e-01 1.697e-01 - K 3.173e-03 3.173e-03 - Mg 1.652e-02 1.652e-02 - Na 1.456e-01 1.456e-01 - S 8.777e-03 8.777e-03 - Si 2.215e-05 2.215e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.351 Charge balance - pe = -1.717 Adjusted to redox equilibrium - Activity of water = 0.994 - Ionic strength = 2.087e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.026e-03 - Total CO2 (mol/kg) = 3.189e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.390e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 - Iterations = 13 - Total H = 1.110131e+02 - Total O = 5.554960e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.170e-07 2.231e-07 -6.499 -6.651 -0.153 - H+ 5.603e-08 4.460e-08 -7.252 -7.351 -0.099 - H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 -C(-4) 4.007e-25 - CH4 4.007e-25 4.204e-25 -24.397 -24.376 0.021 -C(4) 3.189e-03 - HCO3- 2.662e-03 1.980e-03 -2.575 -2.703 -0.129 - CO2 1.904e-04 1.998e-04 -3.720 -3.699 0.021 - MgHCO3+ 1.545e-04 1.151e-04 -3.811 -3.939 -0.128 - NaHCO3 1.137e-04 1.192e-04 -3.944 -3.924 0.021 - CaHCO3+ 4.245e-05 3.158e-05 -4.372 -4.501 -0.129 - MgCO3 9.408e-06 9.871e-06 -5.027 -5.006 0.021 - CO3-2 6.803e-06 2.082e-06 -5.167 -5.682 -0.514 - NaCO3- 5.572e-06 4.151e-06 -5.254 -5.382 -0.128 - CaCO3 4.166e-06 4.371e-06 -5.380 -5.359 0.021 -Ca 4.350e-03 - Ca+2 3.928e-03 1.250e-03 -2.406 -2.903 -0.497 - CaSO4 3.753e-04 3.938e-04 -3.426 -3.405 0.021 - CaHCO3+ 4.245e-05 3.158e-05 -4.372 -4.501 -0.129 - CaCO3 4.166e-06 4.371e-06 -5.380 -5.359 0.021 - CaOH+ 6.204e-09 4.622e-09 -8.207 -8.335 -0.128 - CaHSO4+ 1.381e-10 1.029e-10 -9.860 -9.988 -0.128 -Cl 1.697e-01 - Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 -H(0) 7.279e-15 - H2 3.640e-15 3.819e-15 -14.439 -14.418 0.021 -K 3.173e-03 - K+ 3.140e-03 2.226e-03 -2.503 -2.652 -0.149 - KSO4- 3.316e-05 2.470e-05 -4.479 -4.607 -0.128 - KOH 1.639e-10 1.720e-10 -9.785 -9.764 0.021 -Mg 1.652e-02 - Mg+2 1.460e-02 4.968e-03 -1.836 -2.304 -0.468 - MgSO4 1.753e-03 1.839e-03 -2.756 -2.735 0.021 - MgHCO3+ 1.545e-04 1.151e-04 -3.811 -3.939 -0.128 - MgCO3 9.408e-06 9.871e-06 -5.027 -5.006 0.021 - MgOH+ 5.396e-07 4.020e-07 -6.268 -6.396 -0.128 -Na 1.456e-01 - Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 - NaSO4- 1.138e-03 8.476e-04 -2.944 -3.072 -0.128 - NaHCO3 1.137e-04 1.192e-04 -3.944 -3.924 0.021 - NaCO3- 5.572e-06 4.151e-06 -5.254 -5.382 -0.128 - NaOH 1.503e-08 1.577e-08 -7.823 -7.802 0.021 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -63.570 -63.549 0.021 -S(-2) 4.890e-22 - HS- 3.876e-22 2.728e-22 -21.412 -21.564 -0.153 - H2S 1.014e-22 1.064e-22 -21.994 -21.973 0.021 - S-2 2.513e-27 7.386e-28 -26.600 -27.132 -0.532 -S(6) 8.777e-03 - SO4-2 5.478e-03 1.579e-03 -2.261 -2.802 -0.540 - MgSO4 1.753e-03 1.839e-03 -2.756 -2.735 0.021 - NaSO4- 1.138e-03 8.476e-04 -2.944 -3.072 -0.128 - CaSO4 3.753e-04 3.938e-04 -3.426 -3.405 0.021 - KSO4- 3.316e-05 2.470e-05 -4.479 -4.607 -0.128 - HSO4- 9.193e-09 6.849e-09 -8.037 -8.164 -0.128 - CaHSO4+ 1.381e-10 1.029e-10 -9.860 -9.988 -0.128 -Si 2.215e-05 - H4SiO4 2.204e-05 2.313e-05 -4.657 -4.636 0.021 - H3SiO4- 1.026e-07 7.646e-08 -6.989 -7.117 -0.128 - H2SiO4-2 3.784e-13 1.166e-13 -12.422 -12.933 -0.511 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -1.34 -5.70 -4.36 CaSO4 - Aragonite -0.25 -8.58 -8.34 CaCO3 - Calcite -0.10 -8.58 -8.48 CaCO3 - CH4(g) -21.52 -24.38 -2.86 CH4 - Chalcedony -1.08 -4.63 -3.55 SiO2 - Chrysotile -4.28 27.92 32.20 Mg3Si2O5(OH)4 - CO2(g) -2.23 -3.70 -1.47 CO2 - Dolomite 0.52 -16.57 -17.09 CaMg(CO3)2 - Gypsum -1.13 -5.71 -4.58 CaSO4:2H2O - H2(g) -11.27 -14.42 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -20.98 -21.97 -1.00 H2S - Halite -3.47 -1.89 1.58 NaCl - O2(g) -60.59 -63.55 -2.96 O2 - Quartz -0.65 -4.63 -3.98 SiO2 - Sepiolite -4.87 10.89 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -7.77 10.89 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -1.92 -4.63 -2.71 SiO2 - Sulfur -15.59 -10.71 4.88 S - Talc -2.74 18.66 21.40 Mg3Si4O10(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - TITLE Example 3, part D.--Equilibrate mixture with calcite and dolomite. - EQUILIBRIUM_PHASES 1 - Calcite 0.0 - Dolomite 0.0 - USE solution 3 - END ------ -TITLE ------ - - Example 3, part D.--Equilibrate mixture with calcite and dolomite. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 3. Solution after simulation 3. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.984e+00 -1.571e-02 - Dolomite 0.00 -17.09 -17.09 1.000e+01 1.001e+01 7.935e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 3.029e-03 3.029e-03 - Ca 1.213e-02 1.212e-02 - Cl 1.697e-01 1.697e-01 - K 3.173e-03 3.173e-03 - Mg 8.585e-03 8.585e-03 - Na 1.456e-01 1.456e-01 - S 8.777e-03 8.777e-03 - Si 2.215e-05 2.215e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.056 Charge balance - pe = -1.421 Adjusted to redox equilibrium - Activity of water = 0.994 - Ionic strength = 2.087e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.704e-03 - Total CO2 (mol/kg) = 3.029e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.390e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 - Iterations = 5 - Total H = 1.110131e+02 - Total O = 5.554912e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.609e-07 1.132e-07 -6.793 -6.946 -0.153 - H+ 1.104e-07 8.788e-08 -6.957 -7.056 -0.099 - H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 -C(-4) 6.977e-25 - CH4 6.977e-25 7.320e-25 -24.156 -24.135 0.021 -C(4) 3.029e-03 - HCO3- 2.397e-03 1.783e-03 -2.620 -2.749 -0.129 - CO2 3.377e-04 3.543e-04 -3.471 -3.451 0.021 - CaHCO3+ 1.065e-04 7.920e-05 -3.973 -4.101 -0.129 - NaHCO3 1.023e-04 1.073e-04 -3.990 -3.969 0.021 - MgHCO3+ 7.221e-05 5.380e-05 -4.141 -4.269 -0.128 - CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 - CO3-2 3.109e-06 9.513e-07 -5.507 -6.022 -0.514 - NaCO3- 2.546e-06 1.897e-06 -5.594 -5.722 -0.128 - MgCO3 2.232e-06 2.341e-06 -5.651 -5.631 0.021 -Ca 1.213e-02 - Ca+2 1.095e-02 3.482e-03 -1.961 -2.458 -0.497 - CaSO4 1.067e-03 1.119e-03 -2.972 -2.951 0.021 - CaHCO3+ 1.065e-04 7.920e-05 -3.973 -4.101 -0.129 - CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 - CaOH+ 8.774e-09 6.537e-09 -8.057 -8.185 -0.128 - CaHSO4+ 7.734e-10 5.762e-10 -9.112 -9.239 -0.128 -Cl 1.697e-01 - Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 -H(0) 7.246e-15 - H2 3.623e-15 3.801e-15 -14.441 -14.420 0.021 -K 3.173e-03 - K+ 3.140e-03 2.225e-03 -2.503 -2.653 -0.149 - KSO4- 3.381e-05 2.519e-05 -4.471 -4.599 -0.128 - KOH 8.319e-11 8.729e-11 -10.080 -10.059 0.021 -Mg 8.585e-03 - Mg+2 7.582e-03 2.579e-03 -2.120 -2.588 -0.468 - MgSO4 9.283e-04 9.740e-04 -3.032 -3.011 0.021 - MgHCO3+ 7.221e-05 5.380e-05 -4.141 -4.269 -0.128 - MgCO3 2.232e-06 2.341e-06 -5.651 -5.631 0.021 - MgOH+ 1.422e-07 1.059e-07 -6.847 -6.975 -0.128 -Na 1.456e-01 - Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 - NaSO4- 1.160e-03 8.644e-04 -2.935 -3.063 -0.128 - NaHCO3 1.023e-04 1.073e-04 -3.990 -3.969 0.021 - NaCO3- 2.546e-06 1.897e-06 -5.594 -5.722 -0.128 - NaOH 7.627e-09 8.002e-09 -8.118 -8.097 0.021 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -63.566 -63.545 0.021 -S(-2) 1.159e-21 - HS- 7.648e-22 5.382e-22 -21.116 -21.269 -0.153 - H2S 3.941e-22 4.136e-22 -21.404 -21.383 0.021 - S-2 2.517e-27 7.397e-28 -26.599 -27.131 -0.532 -S(6) 8.777e-03 - SO4-2 5.588e-03 1.611e-03 -2.253 -2.793 -0.540 - NaSO4- 1.160e-03 8.644e-04 -2.935 -3.063 -0.128 - CaSO4 1.067e-03 1.119e-03 -2.972 -2.951 0.021 - MgSO4 9.283e-04 9.740e-04 -3.032 -3.011 0.021 - KSO4- 3.381e-05 2.519e-05 -4.471 -4.599 -0.128 - HSO4- 1.847e-08 1.376e-08 -7.733 -7.861 -0.128 - CaHSO4+ 7.734e-10 5.762e-10 -9.112 -9.239 -0.128 -Si 2.215e-05 - H4SiO4 2.210e-05 2.318e-05 -4.656 -4.635 0.021 - H3SiO4- 5.221e-08 3.890e-08 -7.282 -7.410 -0.128 - H2SiO4-2 9.772e-14 3.011e-14 -13.010 -13.521 -0.511 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.89 -5.25 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -21.28 -24.14 -2.86 CH4 - Chalcedony -1.08 -4.63 -3.55 SiO2 - Chrysotile -6.90 25.30 32.20 Mg3Si2O5(OH)4 - CO2(g) -1.98 -3.45 -1.47 CO2 - Dolomite 0.00 -17.09 -17.09 CaMg(CO3)2 - Gypsum -0.68 -5.26 -4.58 CaSO4:2H2O - H2(g) -11.27 -14.42 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -20.39 -21.38 -1.00 H2S - Halite -3.47 -1.89 1.58 NaCl - O2(g) -60.58 -63.54 -2.96 O2 - Quartz -0.65 -4.63 -3.98 SiO2 - Sepiolite -6.62 9.14 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -9.52 9.14 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -1.92 -4.63 -2.71 SiO2 - Sulfur -15.00 -10.11 4.88 S - Talc -5.36 16.04 21.40 Mg3Si4O10(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 5. ------------------------------------- - - TITLE Example 3, part E.--Equilibrate mixture with calcite only. - EQUILIBRIUM_PHASES 2 - Calcite 0.0 - USE solution 3 - END ------ -TITLE ------ - - Example 3, part E.--Equilibrate mixture with calcite only. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 3. Solution after simulation 3. -Using pure phase assemblage 2. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 1.000e+01 -3.992e-05 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 3.229e-03 3.229e-03 - Ca 4.390e-03 4.390e-03 - Cl 1.697e-01 1.697e-01 - K 3.173e-03 3.173e-03 - Mg 1.652e-02 1.652e-02 - Na 1.456e-01 1.456e-01 - S 8.777e-03 8.777e-03 - Si 2.215e-05 2.215e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.442 Charge balance - pe = -1.861 Adjusted to redox equilibrium - Activity of water = 0.994 - Ionic strength = 2.088e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.106e-03 - Total CO2 (mol/kg) = 3.229e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.390e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.06 - Iterations = 6 - Total H = 1.110131e+02 - Total O = 5.554972e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.915e-07 2.755e-07 -6.407 -6.560 -0.153 - H+ 4.537e-08 3.612e-08 -7.343 -7.442 -0.099 - H2O 5.551e+01 9.941e-01 1.744 -0.003 0.000 -C(-4) 8.842e-25 - CH4 8.842e-25 9.278e-25 -24.053 -24.033 0.021 -C(4) 3.229e-03 - HCO3- 2.721e-03 2.024e-03 -2.565 -2.694 -0.129 - MgHCO3+ 1.579e-04 1.176e-04 -3.802 -3.930 -0.128 - CO2 1.576e-04 1.653e-04 -3.803 -3.782 0.021 - NaHCO3 1.161e-04 1.219e-04 -3.935 -3.914 0.021 - CaHCO3+ 4.376e-05 3.255e-05 -4.359 -4.487 -0.129 - MgCO3 1.187e-05 1.245e-05 -4.926 -4.905 0.021 - CO3-2 8.587e-06 2.628e-06 -5.066 -5.580 -0.514 - NaCO3- 7.033e-06 5.240e-06 -5.153 -5.281 -0.128 - CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 -Ca 4.390e-03 - Ca+2 3.963e-03 1.261e-03 -2.402 -2.899 -0.497 - CaSO4 3.784e-04 3.971e-04 -3.422 -3.401 0.021 - CaHCO3+ 4.376e-05 3.255e-05 -4.359 -4.487 -0.129 - CaCO3 5.304e-06 5.565e-06 -5.275 -5.255 0.021 - CaOH+ 7.728e-09 5.758e-09 -8.112 -8.240 -0.128 - CaHSO4+ 1.128e-10 8.402e-11 -9.948 -10.076 -0.128 -Cl 1.697e-01 - Cl- 1.697e-01 1.203e-01 -0.770 -0.920 -0.149 -H(0) 9.302e-15 - H2 4.651e-15 4.880e-15 -14.332 -14.312 0.021 -K 3.173e-03 - K+ 3.140e-03 2.226e-03 -2.503 -2.652 -0.149 - KSO4- 3.314e-05 2.469e-05 -4.480 -4.607 -0.128 - KOH 2.025e-10 2.124e-10 -9.694 -9.673 0.021 -Mg 1.652e-02 - Mg+2 1.460e-02 4.966e-03 -1.836 -2.304 -0.468 - MgSO4 1.752e-03 1.838e-03 -2.757 -2.736 0.021 - MgHCO3+ 1.579e-04 1.176e-04 -3.802 -3.930 -0.128 - MgCO3 1.187e-05 1.245e-05 -4.926 -4.905 0.021 - MgOH+ 6.661e-07 4.963e-07 -6.176 -6.304 -0.128 -Na 1.456e-01 - Na+ 1.444e-01 1.071e-01 -0.841 -0.970 -0.130 - NaSO4- 1.137e-03 8.472e-04 -2.944 -3.072 -0.128 - NaHCO3 1.161e-04 1.219e-04 -3.935 -3.914 0.021 - NaCO3- 7.033e-06 5.240e-06 -5.153 -5.281 -0.128 - NaOH 1.856e-08 1.947e-08 -7.731 -7.711 0.021 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -63.783 -63.762 0.021 -S(-2) 1.014e-21 - HS- 8.367e-22 5.888e-22 -21.077 -21.230 -0.153 - H2S 1.772e-22 1.860e-22 -21.751 -21.731 0.021 - S-2 6.701e-27 1.969e-27 -26.174 -26.706 -0.532 -S(6) 8.777e-03 - SO4-2 5.477e-03 1.579e-03 -2.261 -2.802 -0.540 - MgSO4 1.752e-03 1.838e-03 -2.757 -2.736 0.021 - NaSO4- 1.137e-03 8.472e-04 -2.944 -3.072 -0.128 - CaSO4 3.784e-04 3.971e-04 -3.422 -3.401 0.021 - KSO4- 3.314e-05 2.469e-05 -4.480 -4.607 -0.128 - HSO4- 7.441e-09 5.544e-09 -8.128 -8.256 -0.128 - CaHSO4+ 1.128e-10 8.402e-11 -9.948 -10.076 -0.128 -Si 2.215e-05 - H4SiO4 2.202e-05 2.311e-05 -4.657 -4.636 0.021 - H3SiO4- 1.266e-07 9.432e-08 -6.898 -7.025 -0.128 - H2SiO4-2 5.766e-13 1.776e-13 -12.239 -12.750 -0.511 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -1.34 -5.70 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -21.17 -24.03 -2.86 CH4 - Chalcedony -1.08 -4.63 -3.55 SiO2 - Chrysotile -3.73 28.47 32.20 Mg3Si2O5(OH)4 - CO2(g) -2.31 -3.78 -1.47 CO2 - Dolomite 0.73 -16.36 -17.09 CaMg(CO3)2 - Gypsum -1.13 -5.71 -4.58 CaSO4:2H2O - H2(g) -11.16 -14.31 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -20.73 -21.73 -1.00 H2S - Halite -3.47 -1.89 1.58 NaCl - O2(g) -60.80 -63.76 -2.96 O2 - Quartz -0.65 -4.63 -3.98 SiO2 - Sepiolite -4.51 11.25 15.76 Mg2Si3O7.5OH:3H2O - Sepiolite(d) -7.41 11.25 18.66 Mg2Si3O7.5OH:3H2O - SiO2(a) -1.92 -4.63 -2.71 SiO2 - Sulfur -15.45 -10.57 4.88 S - Talc -2.19 19.21 21.40 Mg3Si4O10(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 6. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex4.log b/Sun/examples/ex4.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex4.out b/Sun/examples/ex4.out deleted file mode 100644 index 146247a6..00000000 --- a/Sun/examples/ex4.out +++ /dev/null @@ -1,478 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex4 - Output file: ex4.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 4a.--Rain water evaporation - SOLUTION 1 Precipitation from Central Oklahoma - units mg/L - pH 4.5 # estimated - temp 25.0 - Ca .384 - Mg .043 - Na .141 - K .036 - Cl .236 - C(4) .1 CO2(g) -3.5 - S(6) 1.3 - N(-3) .208 - N(5) .237 - REACTION 1 - H2O -1.0 - 52.73 moles - SAVE solution 2 - END ------ -TITLE ------ - - Example 4a.--Rain water evaporation - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. Precipitation from Central Oklahoma - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C(4) 1.092e-05 1.092e-05 Equilibrium with CO2(g) - Ca 9.581e-06 9.581e-06 - Cl 6.657e-06 6.657e-06 - K 9.207e-07 9.207e-07 - Mg 1.769e-06 1.769e-06 - N(-3) 1.485e-05 1.485e-05 - N(5) 1.692e-05 1.692e-05 - Na 6.133e-06 6.133e-06 - S(6) 1.353e-05 1.353e-05 - -----------------------------Description of solution---------------------------- - - pH = 4.500 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 8.838e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.185e-05 - Total CO2 (mol/kg) = 1.092e-05 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.581e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 20.29 - Iterations = 3 - Total H = 1.110125e+02 - Total O = 5.550634e+01 - ----------------------------------Redox couples--------------------------------- - - Redox couple pe Eh (volts) - - N(-3)/N(5) 9.2667 0.5482 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.196e-05 3.162e-05 -4.495 -4.500 -0.005 - OH- 3.200e-10 3.166e-10 -9.495 -9.500 -0.005 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(4) 1.092e-05 - CO2 1.077e-05 1.077e-05 -4.968 -4.968 0.000 - HCO3- 1.531e-07 1.514e-07 -6.815 -6.820 -0.005 - CaHCO3+ 1.787e-11 1.768e-11 -10.748 -10.753 -0.005 - MgHCO3+ 3.025e-12 2.992e-12 -11.519 -11.524 -0.005 - NaHCO3 5.166e-13 5.166e-13 -12.287 -12.287 0.000 - CO3-2 2.345e-13 2.246e-13 -12.630 -12.649 -0.019 - CaCO3 3.452e-15 3.452e-15 -14.462 -14.462 0.000 - MgCO3 3.619e-16 3.619e-16 -15.441 -15.441 0.000 - NaCO3- 2.565e-17 2.537e-17 -16.591 -16.596 -0.005 -Ca 9.581e-06 - Ca+2 9.557e-06 9.151e-06 -5.020 -5.039 -0.019 - CaSO4 2.353e-08 2.353e-08 -7.628 -7.628 0.000 - CaHCO3+ 1.787e-11 1.768e-11 -10.748 -10.753 -0.005 - CaHSO4+ 4.408e-12 4.360e-12 -11.356 -11.361 -0.005 - CaOH+ 4.855e-14 4.803e-14 -13.314 -13.319 -0.005 - CaCO3 3.452e-15 3.452e-15 -14.462 -14.462 0.000 -Cl 6.657e-06 - Cl- 6.657e-06 6.585e-06 -5.177 -5.181 -0.005 -H(0) 1.416e-20 - H2 7.079e-21 7.079e-21 -20.150 -20.150 0.000 -K 9.207e-07 - K+ 9.206e-07 9.106e-07 -6.036 -6.041 -0.005 - KSO4- 8.337e-11 8.247e-11 -10.079 -10.084 -0.005 - KOH 9.984e-17 9.985e-17 -16.001 -16.001 0.000 -Mg 1.769e-06 - Mg+2 1.764e-06 1.689e-06 -5.754 -5.772 -0.019 - MgSO4 5.103e-09 5.103e-09 -8.292 -8.292 0.000 - MgHCO3+ 3.025e-12 2.992e-12 -11.519 -11.524 -0.005 - MgOH+ 1.960e-13 1.939e-13 -12.708 -12.712 -0.005 - MgCO3 3.619e-16 3.619e-16 -15.441 -15.441 0.000 -N(-3) 1.485e-05 - NH4+ 1.485e-05 1.469e-05 -4.828 -4.833 -0.005 - NH4SO4- 2.465e-09 2.438e-09 -8.608 -8.613 -0.005 - NH3 2.646e-10 2.647e-10 -9.577 -9.577 0.000 -N(5) 1.692e-05 - NO3- 1.692e-05 1.674e-05 -4.772 -4.776 -0.005 -Na 6.133e-06 - Na+ 6.133e-06 6.066e-06 -5.212 -5.217 -0.005 - NaSO4- 3.962e-10 3.919e-10 -9.402 -9.407 -0.005 - NaHCO3 5.166e-13 5.166e-13 -12.287 -12.287 0.000 - NaOH 1.267e-15 1.267e-15 -14.897 -14.897 0.000 - NaCO3- 2.565e-17 2.537e-17 -16.591 -16.596 -0.005 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -52.080 -52.080 0.000 -S(6) 1.353e-05 - SO4-2 1.346e-05 1.289e-05 -4.871 -4.890 -0.019 - HSO4- 4.006e-08 3.963e-08 -7.397 -7.402 -0.005 - CaSO4 2.353e-08 2.353e-08 -7.628 -7.628 0.000 - MgSO4 5.103e-09 5.103e-09 -8.292 -8.292 0.000 - NH4SO4- 2.465e-09 2.438e-09 -8.608 -8.613 -0.005 - NaSO4- 3.962e-10 3.919e-10 -9.402 -9.407 -0.005 - KSO4- 8.337e-11 8.247e-11 -10.079 -10.084 -0.005 - CaHSO4+ 4.408e-12 4.360e-12 -11.356 -11.361 -0.005 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -5.57 -9.93 -4.36 CaSO4 - Aragonite -9.35 -17.69 -8.34 CaCO3 - Calcite -9.21 -17.69 -8.48 CaCO3 - CO2(g) -3.50 -4.97 -1.47 CO2 - Dolomite -19.02 -36.11 -17.09 CaMg(CO3)2 - Gypsum -5.35 -9.93 -4.58 CaSO4:2H2O - H2(g) -17.00 -20.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -11.98 -10.40 1.58 NaCl - NH3(g) -11.35 -9.58 1.77 NH3 - O2(g) -49.12 -52.08 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Precipitation from Central Oklahoma -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 5.273e+01 moles of the following reaction have been added: - - Relative - Reactant moles - - H2O -1.00 - - Relative - Element moles - H -2.00 - O -1.00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.183e-04 1.092e-05 - Ca 1.916e-04 9.581e-06 - Cl 1.331e-04 6.657e-06 - K 1.841e-05 9.207e-07 - Mg 3.536e-05 1.769e-06 - N 6.352e-04 3.177e-05 - Na 1.226e-04 6.133e-06 - S 2.706e-04 1.353e-05 - -----------------------------Description of solution---------------------------- - - pH = 3.148 Charge balance - pe = 16.530 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.528e-03 - Mass of water (kg) = 5.002e-02 - Total alkalinity (eq/kg) = -7.555e-04 - Total CO2 (mol/kg) = 2.183e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.581e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 24.31 - Iterations = 20 - Total H = 5.552525e+00 - Total O = 2.776344e+00 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 7.406e-04 7.108e-04 -3.130 -3.148 -0.018 - OH- 1.472e-11 1.408e-11 -10.832 -10.851 -0.019 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -136.693 -136.693 0.000 -C(4) 2.183e-04 - CO2 2.182e-04 2.182e-04 -3.661 -3.661 0.000 - HCO3- 1.425e-07 1.366e-07 -6.846 -6.865 -0.019 - CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 - MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 - NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 - CO3-2 1.070e-14 9.010e-15 -13.971 -14.045 -0.074 - CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 - MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 - NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 -Ca 1.916e-04 - Ca+2 1.851e-04 1.559e-04 -3.733 -3.807 -0.075 - CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 - CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 - CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 - CaOH+ 3.801e-14 3.639e-14 -13.420 -13.439 -0.019 - CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 -Cl 1.331e-04 - Cl- 1.331e-04 1.274e-04 -3.876 -3.895 -0.019 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.506 -42.506 0.000 -K 1.841e-05 - K+ 1.838e-05 1.759e-05 -4.736 -4.755 -0.019 - KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 - KOH 8.579e-17 8.582e-17 -16.067 -16.066 0.000 -Mg 3.536e-05 - Mg+2 3.396e-05 2.864e-05 -4.469 -4.543 -0.074 - MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 - MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 - MgOH+ 1.528e-13 1.463e-13 -12.816 -12.835 -0.019 - MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -48.438 -48.457 -0.019 - NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 - NH3 0.000e+00 0.000e+00 -54.553 -54.553 0.000 -N(0) 4.751e-04 - N2 2.375e-04 2.376e-04 -3.624 -3.624 0.000 -N(3) 2.623e-15 - NO2- 2.623e-15 2.510e-15 -14.581 -14.600 -0.019 -N(5) 1.601e-04 - NO3- 1.601e-04 1.532e-04 -3.796 -3.815 -0.019 -Na 1.226e-04 - Na+ 1.225e-04 1.173e-04 -3.912 -3.931 -0.019 - NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 - NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 - NaOH 1.090e-15 1.090e-15 -14.963 -14.962 0.000 - NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 -O(0) 8.553e-08 - O2 4.277e-08 4.278e-08 -7.369 -7.369 0.000 -S(-2) 0.000e+00 - H2S 0.000e+00 0.000e+00 -126.809 -126.809 0.000 - HS- 0.000e+00 0.000e+00 -130.583 -130.602 -0.019 - S-2 0.000e+00 0.000e+00 -140.297 -140.372 -0.075 -S(6) 2.706e-04 - SO4-2 2.475e-04 2.083e-04 -3.606 -3.681 -0.075 - HSO4- 1.503e-05 1.439e-05 -4.823 -4.842 -0.019 - CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 - MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 - NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 - CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 - KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 - NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.13 -7.49 -4.36 CaSO4 - Aragonite -9.52 -17.85 -8.34 CaCO3 - Calcite -9.37 -17.85 -8.48 CaCO3 - CH4(g) -133.83 -136.69 -2.86 CH4 - CO2(g) -2.19 -3.66 -1.47 CO2 - Dolomite -19.35 -36.44 -17.09 CaMg(CO3)2 - Gypsum -2.91 -7.49 -4.58 CaSO4:2H2O - H2(g) -39.36 -42.51 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -125.81 -126.81 -1.00 H2S - Halite -9.41 -7.83 1.58 NaCl - N2(g) -0.36 -3.62 -3.26 N2 - NH3(g) -56.32 -54.55 1.77 NH3 - O2(g) -4.41 -7.37 -2.96 O2 - Sulfur -92.34 -87.45 4.88 S - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - TITLE Example 4b.--Factor of 20 more solution - MIX - 2 20. - SAVE solution 3 - END ------ -TITLE ------ - - Example 4b.--Factor of 20 more solution - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using mix 1. - -Mixture 1. - - 2.000e+01 Solution 2 Solution after simulation 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.183e-04 2.184e-04 - Ca 1.916e-04 1.916e-04 - Cl 1.331e-04 1.331e-04 - K 1.841e-05 1.841e-05 - Mg 3.536e-05 3.537e-05 - N 6.352e-04 6.354e-04 - Na 1.226e-04 1.227e-04 - S 2.706e-04 2.707e-04 - -----------------------------Description of solution---------------------------- - - pH = 3.148 Charge balance - pe = 16.530 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.528e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -7.555e-04 - Total CO2 (mol/kg) = 2.183e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 5.162e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 24.31 - Iterations = 0 - Total H = 1.110505e+02 - Total O = 5.552687e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 7.406e-04 7.108e-04 -3.130 -3.148 -0.018 - OH- 1.472e-11 1.408e-11 -10.832 -10.851 -0.019 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(-4) 0.000e+00 - CH4 0.000e+00 0.000e+00 -136.693 -136.693 0.000 -C(4) 2.183e-04 - CO2 2.182e-04 2.182e-04 -3.661 -3.661 0.000 - HCO3- 1.425e-07 1.366e-07 -6.846 -6.865 -0.019 - CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 - MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 - NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 - CO3-2 1.070e-14 9.010e-15 -13.971 -14.045 -0.074 - CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 - MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 - NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 -Ca 1.916e-04 - Ca+2 1.851e-04 1.559e-04 -3.733 -3.807 -0.075 - CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 - CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 - CaHCO3+ 2.834e-10 2.715e-10 -9.548 -9.566 -0.019 - CaOH+ 3.801e-14 3.639e-14 -13.420 -13.439 -0.019 - CaCO3 2.358e-15 2.359e-15 -14.627 -14.627 0.000 -Cl 1.331e-04 - Cl- 1.331e-04 1.274e-04 -3.876 -3.895 -0.019 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.506 -42.506 0.000 -K 1.841e-05 - K+ 1.838e-05 1.759e-05 -4.736 -4.755 -0.019 - KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 - KOH 8.579e-17 8.582e-17 -16.067 -16.066 0.000 -Mg 3.536e-05 - Mg+2 3.396e-05 2.864e-05 -4.469 -4.543 -0.074 - MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 - MgHCO3+ 4.780e-11 4.576e-11 -10.321 -10.340 -0.019 - MgOH+ 1.528e-13 1.463e-13 -12.816 -12.835 -0.019 - MgCO3 2.461e-16 2.462e-16 -15.609 -15.609 0.000 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -48.438 -48.457 -0.019 - NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 - NH3 0.000e+00 0.000e+00 -54.553 -54.553 0.000 -N(0) 4.751e-04 - N2 2.375e-04 2.376e-04 -3.624 -3.624 0.000 -N(3) 2.623e-15 - NO2- 2.623e-15 2.510e-15 -14.581 -14.600 -0.019 -N(5) 1.601e-04 - NO3- 1.601e-04 1.532e-04 -3.796 -3.815 -0.019 -Na 1.226e-04 - Na+ 1.225e-04 1.173e-04 -3.912 -3.931 -0.019 - NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 - NaHCO3 9.005e-12 9.008e-12 -11.046 -11.045 0.000 - NaOH 1.090e-15 1.090e-15 -14.963 -14.962 0.000 - NaCO3- 2.056e-17 1.968e-17 -16.687 -16.706 -0.019 -O(0) 8.553e-08 - O2 4.277e-08 4.278e-08 -7.369 -7.369 0.000 -S(-2) 0.000e+00 - H2S 0.000e+00 0.000e+00 -126.809 -126.809 0.000 - HS- 0.000e+00 0.000e+00 -130.583 -130.602 -0.019 - S-2 0.000e+00 0.000e+00 -140.297 -140.372 -0.075 -S(6) 2.706e-04 - SO4-2 2.475e-04 2.083e-04 -3.606 -3.681 -0.075 - HSO4- 1.503e-05 1.439e-05 -4.823 -4.842 -0.019 - CaSO4 6.474e-06 6.477e-06 -5.189 -5.189 0.000 - MgSO4 1.398e-06 1.398e-06 -5.855 -5.854 0.000 - NaSO4- 1.279e-07 1.224e-07 -6.893 -6.912 -0.019 - CaHSO4+ 2.817e-08 2.697e-08 -7.550 -7.569 -0.019 - KSO4- 2.689e-08 2.575e-08 -7.570 -7.589 -0.019 - NH4SO4- 0.000e+00 0.000e+00 -51.009 -51.028 -0.019 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -3.13 -7.49 -4.36 CaSO4 - Aragonite -9.52 -17.85 -8.34 CaCO3 - Calcite -9.37 -17.85 -8.48 CaCO3 - CH4(g) -133.83 -136.69 -2.86 CH4 - CO2(g) -2.19 -3.66 -1.47 CO2 - Dolomite -19.35 -36.44 -17.09 CaMg(CO3)2 - Gypsum -2.91 -7.49 -4.58 CaSO4:2H2O - H2(g) -39.36 -42.51 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -125.81 -126.81 -1.00 H2S - Halite -9.41 -7.83 1.58 NaCl - N2(g) -0.36 -3.62 -3.26 N2 - NH3(g) -56.32 -54.55 1.77 NH3 - O2(g) -4.41 -7.37 -2.96 O2 - Sulfur -92.34 -87.45 4.88 S - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex5.log b/Sun/examples/ex5.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex5.out b/Sun/examples/ex5.out deleted file mode 100644 index d335bbe5..00000000 --- a/Sun/examples/ex5.out +++ /dev/null @@ -1,942 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex5 - Output file: ex5.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 5.--Add oxygen, equilibrate with pyrite, calcite, and goethite. - SOLUTION 1 PURE WATER - pH 7.0 - temp 25.0 - EQUILIBRIUM_PHASES 1 - Pyrite 0.0 - Goethite 0.0 - Calcite 0.0 - CO2(g) -3.5 - Gypsum 0.0 0.0 - REACTION 1 - O2 1.0 - NaCl 0.5 - 0.0 0.001 0.005 0.01 0.05 - SELECTED_OUTPUT - file ex5.sel - totals Cl - si Gypsum - equilibrium_phases pyrite goethite calcite CO2(g) gypsum - END ------ -TITLE ------ - - Example 5.--Add oxygen, equilibrate with pyrite, calcite, and goethite. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. PURE WATER - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Pure water - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.082e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 - H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 -H(0) 1.416e-25 - H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 0.00 1.51 H2O - O2(g) -39.12 -42.08 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 0.000e+00 moles of the following reaction have been added: - - Relative - Reactant moles - - O2 1.00 - NaCl 0.50 - - Relative - Element moles - Cl 0.50 - Na 0.50 - O 2.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 1.000e+01 -4.934e-04 - CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 -4.870e-04 - Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 1.105e-08 - Gypsum -6.13 -10.71 -4.58 0.000e+00 0.000e+00 - Pyrite 0.00 -85.78 -85.78 1.000e+01 1.000e+01 -3.154e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 9.804e-04 9.804e-04 - Ca 4.934e-04 4.934e-04 - Fe 2.049e-08 2.049e-08 - S 6.308e-08 6.308e-08 - -----------------------------Description of solution---------------------------- - - pH = 8.279 Charge balance - pe = -4.943 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.463e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.867e-04 - Total CO2 (mol/kg) = 9.803e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.550867e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.987e-06 1.903e-06 -5.702 -5.720 -0.019 - H+ 5.476e-09 5.260e-09 -8.262 -8.279 -0.018 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -C(-4) 5.403e-08 - CH4 5.403e-08 5.405e-08 -7.267 -7.267 0.000 -C(4) 9.803e-04 - HCO3- 9.494e-04 9.104e-04 -3.023 -3.041 -0.018 - CO2 1.076e-05 1.077e-05 -4.968 -4.968 0.000 - CO3-2 9.603e-06 8.117e-06 -5.018 -5.091 -0.073 - CaCO3 5.563e-06 5.565e-06 -5.255 -5.255 0.000 - CaHCO3+ 4.943e-06 4.740e-06 -5.306 -5.324 -0.018 - FeCO3 2.600e-09 2.601e-09 -8.585 -8.585 0.000 - FeHCO3+ 1.269e-09 1.216e-09 -8.896 -8.915 -0.019 -Ca 4.934e-04 - Ca+2 4.829e-04 4.081e-04 -3.316 -3.389 -0.073 - CaCO3 5.563e-06 5.565e-06 -5.255 -5.255 0.000 - CaHCO3+ 4.943e-06 4.740e-06 -5.306 -5.324 -0.018 - CaOH+ 1.344e-08 1.288e-08 -7.872 -7.890 -0.019 - CaSO4 3.896e-09 3.897e-09 -8.409 -8.409 0.000 - CaHSO4+ 1.253e-16 1.201e-16 -15.902 -15.920 -0.019 -Fe(2) 2.049e-08 - Fe+2 1.578e-08 1.336e-08 -7.802 -7.874 -0.072 - FeCO3 2.600e-09 2.601e-09 -8.585 -8.585 0.000 - FeHCO3+ 1.269e-09 1.216e-09 -8.896 -8.915 -0.019 - FeOH+ 8.381e-10 8.031e-10 -9.077 -9.095 -0.019 - FeSO4 1.137e-13 1.137e-13 -12.944 -12.944 0.000 - Fe(HS)2 6.287e-17 6.289e-17 -16.202 -16.201 0.000 - FeHSO4+ 4.102e-21 3.931e-21 -20.387 -20.406 -0.019 - Fe(HS)3- 1.643e-23 1.574e-23 -22.784 -22.803 -0.019 -Fe(3) 3.369e-14 - Fe(OH)3 2.753e-14 2.754e-14 -13.560 -13.560 0.000 - Fe(OH)4- 4.984e-15 4.776e-15 -14.302 -14.321 -0.019 - Fe(OH)2+ 1.174e-15 1.124e-15 -14.931 -14.949 -0.019 - FeOH+2 2.119e-20 1.786e-20 -19.674 -19.748 -0.074 - Fe+3 2.091e-26 1.455e-26 -25.680 -25.837 -0.158 - FeSO4+ 7.970e-30 7.637e-30 -29.099 -29.117 -0.019 - Fe(SO4)2- 8.346e-36 7.997e-36 -35.079 -35.097 -0.019 - FeHSO4+2 1.276e-37 1.076e-37 -36.894 -36.968 -0.074 - Fe2(OH)2+4 1.700e-38 8.587e-39 -37.769 -38.066 -0.297 - Fe3(OH)4+5 0.000e+00 0.000e+00 -50.232 -50.695 -0.464 -H(0) 3.009e-10 - H2 1.505e-10 1.505e-10 -9.823 -9.822 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -72.735 -72.735 0.000 -S(-2) 2.505e-09 - HS- 2.399e-09 2.298e-09 -8.620 -8.639 -0.019 - H2S 1.057e-10 1.057e-10 -9.976 -9.976 0.000 - S-2 6.249e-14 5.278e-14 -13.204 -13.278 -0.073 - Fe(HS)2 6.287e-17 6.289e-17 -16.202 -16.201 0.000 - Fe(HS)3- 1.643e-23 1.574e-23 -22.784 -22.803 -0.019 -S(6) 6.057e-08 - SO4-2 5.668e-08 4.786e-08 -7.247 -7.320 -0.073 - CaSO4 3.896e-09 3.897e-09 -8.409 -8.409 0.000 - FeSO4 1.137e-13 1.137e-13 -12.944 -12.944 0.000 - HSO4- 2.554e-14 2.448e-14 -13.593 -13.611 -0.019 - CaHSO4+ 1.253e-16 1.201e-16 -15.902 -15.920 -0.019 - FeHSO4+ 4.102e-21 3.931e-21 -20.387 -20.406 -0.019 - FeSO4+ 7.970e-30 7.637e-30 -29.099 -29.117 -0.019 - Fe(SO4)2- 8.346e-36 7.997e-36 -35.079 -35.097 -0.019 - FeHSO4+2 1.276e-37 1.076e-37 -36.894 -36.968 -0.074 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -6.35 -10.71 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -4.41 -7.27 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 - FeS(ppt) -4.32 -8.23 -3.92 FeS - Goethite 0.00 -1.00 -1.00 FeOOH - Gypsum -6.13 -10.71 -4.58 CaSO4:2H2O - H2(g) -6.67 -9.82 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -8.98 -9.98 -1.00 H2S - Hematite 2.01 -2.00 -4.01 Fe2O3 - Mackinawite -3.59 -8.23 -4.65 FeS - Melanterite -12.99 -15.19 -2.21 FeSO4:7H2O - O2(g) -69.78 -72.74 -2.96 O2 - Pyrite 0.00 -18.48 -18.48 FeS2 - Siderite -2.07 -12.96 -10.89 FeCO3 - Sulfur -8.19 -3.30 4.88 S - -Reaction step 2. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 1.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - O2 1.00 - NaCl 0.50 - - Relative - Element moles - Cl 0.50 - Na 0.50 - O 2.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.999e+00 -9.277e-04 - CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 1.418e-04 - Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 2.667e-04 - Gypsum -2.02 -6.60 -4.58 0.000e+00 0.000e+00 - Pyrite 0.00 -85.78 -85.78 1.000e+01 1.000e+01 -2.667e-04 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 7.859e-04 7.859e-04 - Ca 9.277e-04 9.277e-04 - Cl 5.000e-04 5.000e-04 - Fe 9.939e-09 9.939e-09 - Na 5.000e-04 5.000e-04 - S 5.333e-04 5.333e-04 - -----------------------------Description of solution---------------------------- - - pH = 8.171 Charge balance - pe = -4.287 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.591e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 7.887e-04 - Total CO2 (mol/kg) = 7.859e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 24 - Total H = 1.110122e+02 - Total O = 5.551018e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.585e-06 1.484e-06 -5.800 -5.829 -0.029 - H+ 7.160e-09 6.745e-09 -8.145 -8.171 -0.026 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 2.240e-12 - CH4 2.240e-12 2.242e-12 -11.650 -11.649 0.000 -C(4) 7.859e-04 - HCO3- 7.565e-04 7.099e-04 -3.121 -3.149 -0.028 - CO2 1.076e-05 1.077e-05 -4.968 -4.968 0.000 - CaHCO3+ 6.477e-06 6.078e-06 -5.189 -5.216 -0.028 - CO3-2 6.364e-06 4.936e-06 -5.196 -5.307 -0.110 - CaCO3 5.560e-06 5.565e-06 -5.255 -5.255 0.000 - NaHCO3 1.865e-07 1.867e-07 -6.729 -6.729 0.000 - NaCO3- 4.587e-08 4.298e-08 -7.338 -7.367 -0.028 - FeCO3 7.363e-10 7.369e-10 -9.133 -9.133 0.000 - FeHCO3+ 4.715e-10 4.418e-10 -9.327 -9.355 -0.028 -Ca 9.277e-04 - Ca+2 8.657e-04 6.711e-04 -3.063 -3.173 -0.111 - CaSO4 4.996e-05 5.000e-05 -4.301 -4.301 0.000 - CaHCO3+ 6.477e-06 6.078e-06 -5.189 -5.216 -0.028 - CaCO3 5.560e-06 5.565e-06 -5.255 -5.255 0.000 - CaOH+ 1.762e-08 1.651e-08 -7.754 -7.782 -0.028 - CaHSO4+ 2.108e-12 1.976e-12 -11.676 -11.704 -0.028 -Cl 5.000e-04 - Cl- 5.000e-04 4.682e-04 -3.301 -3.330 -0.029 - FeCl+ 4.293e-12 4.023e-12 -11.367 -11.396 -0.028 - FeCl+2 5.629e-28 4.339e-28 -27.250 -27.363 -0.113 - FeCl2+ 9.686e-31 9.076e-31 -30.014 -30.042 -0.028 - FeCl3 4.246e-35 4.250e-35 -34.372 -34.372 0.000 -Fe(2) 9.939e-09 - Fe+2 8.002e-09 6.223e-09 -8.097 -8.206 -0.109 - FeCO3 7.363e-10 7.369e-10 -9.133 -9.133 0.000 - FeHCO3+ 4.715e-10 4.418e-10 -9.327 -9.355 -0.028 - FeSO4 4.129e-10 4.132e-10 -9.384 -9.384 0.000 - FeOH+ 3.114e-10 2.918e-10 -9.507 -9.535 -0.028 - FeCl+ 4.293e-12 4.023e-12 -11.367 -11.396 -0.028 - FeHSO4+ 1.955e-17 1.832e-17 -16.709 -16.737 -0.028 - Fe(HS)2 5.043e-18 5.047e-18 -17.297 -17.297 0.000 - Fe(HS)3- 5.596e-25 5.243e-25 -24.252 -24.280 -0.028 -Fe(3) 3.303e-14 - Fe(OH)3 2.752e-14 2.754e-14 -13.560 -13.560 0.000 - Fe(OH)4- 3.974e-15 3.724e-15 -14.401 -14.429 -0.028 - Fe(OH)2+ 1.539e-15 1.442e-15 -14.813 -14.841 -0.028 - FeOH+2 3.810e-20 2.937e-20 -19.419 -19.532 -0.113 - FeSO4+ 1.341e-25 1.256e-25 -24.873 -24.901 -0.028 - Fe+3 5.252e-26 3.069e-26 -25.280 -25.513 -0.233 - Fe(SO4)2- 1.095e-27 1.026e-27 -26.960 -26.989 -0.028 - FeCl+2 5.629e-28 4.339e-28 -27.250 -27.363 -0.113 - FeCl2+ 9.686e-31 9.076e-31 -30.014 -30.042 -0.028 - FeHSO4+2 2.943e-33 2.269e-33 -32.531 -32.644 -0.113 - FeCl3 4.246e-35 4.250e-35 -34.372 -34.372 0.000 - Fe2(OH)2+4 6.575e-38 2.322e-38 -37.182 -37.634 -0.452 - Fe3(OH)4+5 0.000e+00 0.000e+00 -49.449 -50.155 -0.706 -H(0) 2.414e-11 - H2 1.207e-11 1.208e-11 -10.918 -10.918 0.000 -Na 5.000e-04 - Na+ 4.988e-04 4.677e-04 -3.302 -3.330 -0.028 - NaSO4- 9.340e-07 8.752e-07 -6.030 -6.058 -0.028 - NaHCO3 1.865e-07 1.867e-07 -6.729 -6.729 0.000 - NaCO3- 4.587e-08 4.298e-08 -7.338 -7.367 -0.028 - NaOH 4.577e-10 4.581e-10 -9.339 -9.339 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -70.545 -70.544 0.000 -S(-2) 1.075e-09 - HS- 1.019e-09 9.540e-10 -8.992 -9.020 -0.029 - H2S 5.621e-11 5.626e-11 -10.250 -10.250 0.000 - S-2 2.207e-14 1.708e-14 -13.656 -13.767 -0.111 - Fe(HS)2 5.043e-18 5.047e-18 -17.297 -17.297 0.000 - Fe(HS)3- 5.596e-25 5.243e-25 -24.252 -24.280 -0.028 -S(6) 5.333e-04 - SO4-2 4.824e-04 3.734e-04 -3.317 -3.428 -0.111 - CaSO4 4.996e-05 5.000e-05 -4.301 -4.301 0.000 - NaSO4- 9.340e-07 8.752e-07 -6.030 -6.058 -0.028 - FeSO4 4.129e-10 4.132e-10 -9.384 -9.384 0.000 - HSO4- 2.613e-10 2.449e-10 -9.583 -9.611 -0.028 - CaHSO4+ 2.108e-12 1.976e-12 -11.676 -11.704 -0.028 - FeHSO4+ 1.955e-17 1.832e-17 -16.709 -16.737 -0.028 - FeSO4+ 1.341e-25 1.256e-25 -24.873 -24.901 -0.028 - Fe(SO4)2- 1.095e-27 1.026e-27 -26.960 -26.989 -0.028 - FeHSO4+2 2.943e-33 2.269e-33 -32.531 -32.644 -0.113 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -2.24 -6.60 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -8.79 -11.65 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 - FeS(ppt) -5.14 -9.06 -3.92 FeS - Goethite -0.00 -1.00 -1.00 FeOOH - Gypsum -2.02 -6.60 -4.58 CaSO4:2H2O - H2(g) -7.77 -10.92 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -9.25 -10.25 -1.00 H2S - Halite -8.24 -6.66 1.58 NaCl - Hematite 2.01 -2.00 -4.01 Fe2O3 - Mackinawite -4.41 -9.06 -4.65 FeS - Melanterite -9.42 -11.63 -2.21 FeSO4:7H2O - O2(g) -67.58 -70.54 -2.96 O2 - Pyrite -0.00 -18.48 -18.48 FeS2 - Siderite -2.62 -13.51 -10.89 FeCO3 - Sulfur -7.36 -2.48 4.88 S - -Reaction step 3. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 5.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - O2 1.00 - NaCl 0.50 - - Relative - Element moles - Cl 0.50 - Na 0.50 - O 2.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.997e+00 -2.937e-03 - CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.000e+01 2.395e-03 - Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 1.333e-03 - Gypsum -1.06 -5.64 -4.58 0.000e+00 0.000e+00 - Pyrite 0.00 -85.78 -85.78 1.000e+01 9.999e+00 -1.333e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.424e-04 5.424e-04 - Ca 2.937e-03 2.937e-03 - Cl 2.500e-03 2.500e-03 - Fe 2.124e-08 2.124e-08 - Na 2.500e-03 2.500e-03 - S 2.667e-03 2.667e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.982 Charge balance - pe = -3.970 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.210e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.415e-04 - Total CO2 (mol/kg) = 5.424e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 25 - Total H = 1.110111e+02 - Total O = 5.551757e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.077e-06 9.604e-07 -5.968 -6.018 -0.050 - H+ 1.149e-08 1.042e-08 -7.940 -7.982 -0.042 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 2.129e-13 - CH4 2.129e-13 2.135e-13 -12.672 -12.671 0.001 -C(4) 5.424e-04 - HCO3- 5.118e-04 4.594e-04 -3.291 -3.338 -0.047 - CO2 1.074e-05 1.077e-05 -4.969 -4.968 0.001 - CaHCO3+ 1.046e-05 9.392e-06 -4.980 -5.027 -0.047 - CaCO3 5.549e-06 5.565e-06 -5.256 -5.255 0.001 - CO3-2 3.184e-06 2.067e-06 -5.497 -5.685 -0.188 - NaHCO3 5.724e-07 5.740e-07 -6.242 -6.241 0.001 - NaCO3- 9.566e-08 8.553e-08 -7.019 -7.068 -0.049 - FeHCO3+ 5.691e-10 5.088e-10 -9.245 -9.293 -0.049 - FeCO3 5.477e-10 5.493e-10 -9.261 -9.260 0.001 -Ca 2.937e-03 - Ca+2 2.469e-03 1.602e-03 -2.607 -2.795 -0.188 - CaSO4 4.520e-04 4.532e-04 -3.345 -3.344 0.001 - CaHCO3+ 1.046e-05 9.392e-06 -4.980 -5.027 -0.047 - CaCO3 5.549e-06 5.565e-06 -5.256 -5.255 0.001 - CaOH+ 2.854e-08 2.551e-08 -7.545 -7.593 -0.049 - CaHSO4+ 3.095e-11 2.767e-11 -10.509 -10.558 -0.049 -Cl 2.500e-03 - Cl- 2.500e-03 2.230e-03 -2.602 -2.652 -0.050 - FeCl+ 3.814e-11 3.410e-11 -10.419 -10.467 -0.049 - FeCl+2 1.194e-26 7.627e-27 -25.923 -26.118 -0.194 - FeCl2+ 8.499e-29 7.599e-29 -28.071 -28.119 -0.049 - FeCl3 1.690e-32 1.695e-32 -31.772 -31.771 0.001 -Fe(2) 2.124e-08 - Fe+2 1.693e-08 1.108e-08 -7.771 -7.956 -0.184 - FeSO4 2.784e-09 2.792e-09 -8.555 -8.554 0.001 - FeHCO3+ 5.691e-10 5.088e-10 -9.245 -9.293 -0.049 - FeCO3 5.477e-10 5.493e-10 -9.261 -9.260 0.001 - FeOH+ 3.758e-10 3.360e-10 -9.425 -9.474 -0.049 - FeCl+ 3.814e-11 3.410e-11 -10.419 -10.467 -0.049 - FeHSO4+ 2.139e-16 1.913e-16 -15.670 -15.718 -0.049 - Fe(HS)2 2.796e-18 2.804e-18 -17.553 -17.552 0.001 - Fe(HS)3- 1.820e-25 1.627e-25 -24.740 -24.789 -0.049 -Fe(3) 3.265e-14 - Fe(OH)3 2.746e-14 2.754e-14 -13.561 -13.560 0.001 - Fe(OH)4- 2.695e-15 2.409e-15 -14.569 -14.618 -0.049 - Fe(OH)2+ 2.492e-15 2.228e-15 -14.603 -14.652 -0.049 - FeOH+2 1.098e-19 7.014e-20 -18.960 -19.154 -0.194 - FeSO4+ 1.968e-24 1.760e-24 -23.706 -23.755 -0.049 - Fe+3 2.720e-25 1.132e-25 -24.566 -24.946 -0.381 - Fe(SO4)2- 6.105e-26 5.458e-26 -25.214 -25.263 -0.049 - FeCl+2 1.194e-26 7.627e-27 -25.923 -26.118 -0.194 - FeCl2+ 8.499e-29 7.599e-29 -28.071 -28.119 -0.049 - FeHSO4+2 7.686e-32 4.911e-32 -31.114 -31.309 -0.194 - FeCl3 1.690e-32 1.695e-32 -31.772 -31.771 0.001 - Fe2(OH)2+4 7.941e-37 1.324e-37 -36.100 -36.878 -0.778 - Fe3(OH)4+5 0.000e+00 0.000e+00 -47.995 -49.210 -1.216 -H(0) 1.338e-11 - H2 6.691e-12 6.710e-12 -11.174 -11.173 0.001 -Na 2.500e-03 - Na+ 2.482e-03 2.222e-03 -2.605 -2.653 -0.048 - NaSO4- 1.766e-05 1.579e-05 -4.753 -4.802 -0.049 - NaHCO3 5.724e-07 5.740e-07 -6.242 -6.241 0.001 - NaCO3- 9.566e-08 8.553e-08 -7.019 -7.068 -0.049 - NaOH 1.404e-09 1.408e-09 -8.853 -8.851 0.001 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -70.035 -70.034 0.001 -S(-2) 6.460e-10 - HS- 5.976e-10 5.329e-10 -9.224 -9.273 -0.050 - H2S 4.843e-11 4.856e-11 -10.315 -10.314 0.001 - S-2 9.562e-15 6.176e-15 -14.019 -14.209 -0.190 - Fe(HS)2 2.796e-18 2.804e-18 -17.553 -17.552 0.001 - Fe(HS)3- 1.820e-25 1.627e-25 -24.740 -24.789 -0.049 -S(6) 2.667e-03 - SO4-2 2.197e-03 1.418e-03 -2.658 -2.848 -0.190 - CaSO4 4.520e-04 4.532e-04 -3.345 -3.344 0.001 - NaSO4- 1.766e-05 1.579e-05 -4.753 -4.802 -0.049 - FeSO4 2.784e-09 2.792e-09 -8.555 -8.554 0.001 - HSO4- 1.606e-09 1.436e-09 -8.794 -8.843 -0.049 - CaHSO4+ 3.095e-11 2.767e-11 -10.509 -10.558 -0.049 - FeHSO4+ 2.139e-16 1.913e-16 -15.670 -15.718 -0.049 - FeSO4+ 1.968e-24 1.760e-24 -23.706 -23.755 -0.049 - Fe(SO4)2- 6.105e-26 5.458e-26 -25.214 -25.263 -0.049 - FeHSO4+2 7.686e-32 4.911e-32 -31.114 -31.309 -0.194 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -1.28 -5.64 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -9.81 -12.67 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 - FeS(ppt) -5.33 -9.25 -3.92 FeS - Goethite -0.00 -1.00 -1.00 FeOOH - Gypsum -1.06 -5.64 -4.58 CaSO4:2H2O - H2(g) -8.02 -11.17 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -9.32 -10.31 -1.00 H2S - Halite -6.89 -5.30 1.58 NaCl - Hematite 2.01 -2.00 -4.01 Fe2O3 - Mackinawite -4.60 -9.25 -4.65 FeS - Melanterite -8.60 -10.80 -2.21 FeSO4:7H2O - O2(g) -67.07 -70.03 -2.96 O2 - Pyrite -0.00 -18.48 -18.48 FeS2 - Siderite -2.75 -13.64 -10.89 FeCO3 - Sulfur -7.17 -2.29 4.88 S - -Reaction step 4. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 1.000e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - O2 1.00 - NaCl 0.50 - - Relative - Element moles - Cl 0.50 - Na 0.50 - O 2.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.994e+00 -5.559e-03 - CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.001e+01 5.105e-03 - Goethite 0.00 12.02 12.02 1.000e+01 1.000e+01 2.667e-03 - Gypsum -0.65 -5.23 -4.58 0.000e+00 0.000e+00 - Pyrite -0.00 -85.78 -85.78 1.000e+01 9.997e+00 -2.667e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.540e-04 4.540e-04 - Ca 5.560e-03 5.559e-03 - Cl 5.000e-03 5.000e-03 - Fe 3.429e-08 3.429e-08 - Na 5.000e-03 5.000e-03 - S 5.333e-03 5.333e-03 - -----------------------------Description of solution---------------------------- - - pH = 7.884 Charge balance - pe = -3.817 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.218e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.522e-04 - Total CO2 (mol/kg) = 4.540e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 25 - Total H = 1.110098e+02 - Total O = 5.552735e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 8.898e-07 7.665e-07 -6.051 -6.115 -0.065 - H+ 1.474e-08 1.306e-08 -7.832 -7.884 -0.053 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -C(-4) 7.696e-14 - CH4 7.696e-14 7.735e-14 -13.114 -13.112 0.002 -C(4) 4.540e-04 - HCO3- 4.210e-04 3.666e-04 -3.376 -3.436 -0.060 - CaHCO3+ 1.351e-05 1.177e-05 -4.869 -4.929 -0.060 - CO2 1.071e-05 1.077e-05 -4.970 -4.968 0.002 - CaCO3 5.536e-06 5.565e-06 -5.257 -5.255 0.002 - CO3-2 2.289e-06 1.317e-06 -5.640 -5.880 -0.240 - NaHCO3 8.791e-07 8.836e-07 -6.056 -6.054 0.002 - NaCO3- 1.214e-07 1.051e-07 -6.916 -6.978 -0.063 - FeHCO3+ 6.487e-10 5.616e-10 -9.188 -9.251 -0.063 - FeCO3 4.814e-10 4.839e-10 -9.317 -9.315 0.002 -Ca 5.560e-03 - Ca+2 4.373e-03 2.515e-03 -2.359 -2.599 -0.240 - CaSO4 1.168e-03 1.174e-03 -2.933 -2.930 0.002 - CaHCO3+ 1.351e-05 1.177e-05 -4.869 -4.929 -0.060 - CaCO3 5.536e-06 5.565e-06 -5.257 -5.255 0.002 - CaOH+ 3.692e-08 3.196e-08 -7.433 -7.495 -0.063 - CaHSO4+ 1.037e-10 8.977e-11 -9.984 -10.047 -0.063 -Cl 5.000e-03 - Cl- 5.000e-03 4.311e-03 -2.301 -2.365 -0.064 - FeCl+ 1.053e-10 9.114e-11 -9.978 -10.040 -0.063 - FeCl+2 5.162e-26 2.899e-26 -25.287 -25.538 -0.251 - FeCl2+ 6.449e-28 5.583e-28 -27.191 -27.253 -0.063 - FeCl3 2.394e-31 2.406e-31 -30.621 -30.619 0.002 -Fe(2) 3.429e-08 - Fe+2 2.629e-08 1.532e-08 -7.580 -7.815 -0.235 - FeSO4 6.337e-09 6.369e-09 -8.198 -8.196 0.002 - FeHCO3+ 6.487e-10 5.616e-10 -9.188 -9.251 -0.063 - FeCO3 4.814e-10 4.839e-10 -9.317 -9.315 0.002 - FeOH+ 4.284e-10 3.708e-10 -9.368 -9.431 -0.063 - FeCl+ 1.053e-10 9.114e-11 -9.978 -10.040 -0.063 - FeHSO4+ 6.314e-16 5.466e-16 -15.200 -15.262 -0.063 - Fe(HS)2 2.164e-18 2.175e-18 -17.665 -17.663 0.002 - Fe(HS)3- 1.092e-25 9.454e-26 -24.962 -25.024 -0.063 -Fe(3) 3.284e-14 - Fe(OH)3 2.739e-14 2.753e-14 -13.562 -13.560 0.002 - Fe(OH)2+ 3.224e-15 2.791e-15 -14.492 -14.554 -0.063 - Fe(OH)4- 2.221e-15 1.923e-15 -14.653 -14.716 -0.063 - FeOH+2 1.960e-19 1.101e-19 -18.708 -18.958 -0.251 - FeSO4+ 6.596e-24 5.710e-24 -23.181 -23.243 -0.063 - Fe+3 6.635e-25 2.227e-25 -24.178 -24.652 -0.474 - Fe(SO4)2- 3.374e-25 2.921e-25 -24.472 -24.534 -0.063 - FeCl+2 5.162e-26 2.899e-26 -25.287 -25.538 -0.251 - FeCl2+ 6.449e-28 5.583e-28 -27.191 -27.253 -0.063 - FeHSO4+2 3.555e-31 1.996e-31 -30.449 -30.700 -0.251 - FeCl3 2.394e-31 2.406e-31 -30.621 -30.619 0.002 - Fe2(OH)2+4 3.279e-36 3.263e-37 -35.484 -36.486 -1.002 - Fe3(OH)4+5 0.000e+00 0.000e+00 -47.155 -48.721 -1.566 -H(0) 1.036e-11 - H2 5.179e-12 5.205e-12 -11.286 -11.284 0.002 -Na 5.000e-03 - Na+ 4.941e-03 4.286e-03 -2.306 -2.368 -0.062 - NaSO4- 5.802e-05 5.023e-05 -4.236 -4.299 -0.063 - NaHCO3 8.791e-07 8.836e-07 -6.056 -6.054 0.002 - NaCO3- 1.214e-07 1.051e-07 -6.916 -6.978 -0.063 - NaOH 2.157e-09 2.168e-09 -8.666 -8.664 0.002 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -69.815 -69.813 0.002 -S(-2) 5.087e-10 - HS- 4.634e-10 3.992e-10 -9.334 -9.399 -0.065 - H2S 4.533e-11 4.557e-11 -10.344 -10.341 0.002 - S-2 6.474e-15 3.693e-15 -14.189 -14.433 -0.244 - Fe(HS)2 2.164e-18 2.175e-18 -17.665 -17.663 0.002 - Fe(HS)3- 1.092e-25 9.454e-26 -24.962 -25.024 -0.063 -S(6) 5.333e-03 - SO4-2 4.108e-03 2.338e-03 -2.386 -2.631 -0.245 - CaSO4 1.168e-03 1.174e-03 -2.933 -2.930 0.002 - NaSO4- 5.802e-05 5.023e-05 -4.236 -4.299 -0.063 - FeSO4 6.337e-09 6.369e-09 -8.198 -8.196 0.002 - HSO4- 3.429e-09 2.968e-09 -8.465 -8.527 -0.063 - CaHSO4+ 1.037e-10 8.977e-11 -9.984 -10.047 -0.063 - FeHSO4+ 6.314e-16 5.466e-16 -15.200 -15.262 -0.063 - FeSO4+ 6.596e-24 5.710e-24 -23.181 -23.243 -0.063 - Fe(SO4)2- 3.374e-25 2.921e-25 -24.472 -24.534 -0.063 - FeHSO4+2 3.555e-31 1.996e-31 -30.449 -30.700 -0.251 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.87 -5.23 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -10.25 -13.11 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 - FeS(ppt) -5.41 -9.33 -3.92 FeS - Goethite -0.00 -1.00 -1.00 FeOOH - Gypsum -0.65 -5.23 -4.58 CaSO4:2H2O - H2(g) -8.13 -11.28 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -9.34 -10.34 -1.00 H2S - Halite -6.32 -4.73 1.58 NaCl - Hematite 2.01 -2.00 -4.01 Fe2O3 - Mackinawite -4.68 -9.33 -4.65 FeS - Melanterite -8.24 -10.45 -2.21 FeSO4:7H2O - O2(g) -66.85 -69.81 -2.96 O2 - Pyrite -0.00 -18.48 -18.48 FeS2 - Siderite -2.81 -13.70 -10.89 FeCO3 - Sulfur -7.09 -2.21 4.88 S - -Reaction step 5. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 1. - - 5.000e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - O2 1.00 - NaCl 0.50 - - Relative - Element moles - Cl 0.50 - Na 0.50 - O 2.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.973e+00 -2.684e-02 - CO2(g) -3.50 -21.65 -18.15 1.000e+01 1.003e+01 2.649e-02 - Goethite 0.00 12.02 12.02 1.000e+01 1.001e+01 1.333e-02 - Gypsum 0.00 -4.58 -4.58 0.000e+00 9.002e-03 9.002e-03 - Pyrite -0.00 -85.78 -85.78 1.000e+01 9.987e+00 -1.333e-02 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 3.526e-04 3.524e-04 - Ca 1.785e-02 1.784e-02 - Cl 2.501e-02 2.500e-02 - Fe 8.735e-08 8.732e-08 - Na 2.501e-02 2.500e-02 - S 1.767e-02 1.766e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.719 Charge balance - pe = -3.565 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 7.432e-02 - Mass of water (kg) = 9.996e-01 - Total alkalinity (eq/kg) = 3.499e-04 - Total CO2 (mol/kg) = 3.526e-04 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -4.778e-11 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 25 - Total H = 1.109631e+02 - Total O = 5.555309e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.681e-07 5.237e-07 -6.175 -6.281 -0.106 - H+ 2.279e-08 1.909e-08 -7.642 -7.719 -0.077 - H2O 5.551e+01 9.986e-01 1.744 -0.001 0.000 -C(-4) 1.534e-14 - CH4 1.534e-14 1.561e-14 -13.814 -13.807 0.007 -C(4) 3.526e-04 - HCO3- 3.108e-04 2.505e-04 -3.508 -3.601 -0.094 - CaHCO3+ 2.134e-05 1.720e-05 -4.671 -4.764 -0.094 - CO2 1.058e-05 1.077e-05 -4.975 -4.968 0.007 - CaCO3 5.470e-06 5.565e-06 -5.262 -5.255 0.007 - NaHCO3 2.706e-06 2.752e-06 -5.568 -5.560 0.007 - CO3-2 1.458e-06 6.155e-07 -5.836 -6.211 -0.374 - NaCO3- 2.804e-07 2.239e-07 -6.552 -6.650 -0.098 - FeHCO3+ 8.424e-10 6.727e-10 -9.074 -9.172 -0.098 - FeCO3 3.897e-10 3.964e-10 -9.409 -9.402 0.007 -Ca 1.785e-02 - Ca+2 1.266e-02 5.382e-03 -1.898 -2.269 -0.371 - CaSO4 5.162e-03 5.251e-03 -2.287 -2.280 0.007 - CaHCO3+ 2.134e-05 1.720e-05 -4.671 -4.764 -0.094 - CaCO3 5.470e-06 5.565e-06 -5.262 -5.255 0.007 - CaOH+ 5.853e-08 4.673e-08 -7.233 -7.330 -0.098 - CaHSO4+ 7.355e-10 5.872e-10 -9.133 -9.231 -0.098 -Cl 2.501e-02 - Cl- 2.501e-02 1.966e-02 -1.602 -1.706 -0.105 - FeCl+ 9.125e-10 7.286e-10 -9.040 -9.138 -0.098 - FeCl+2 1.019e-24 4.140e-25 -23.992 -24.383 -0.391 - FeCl2+ 4.553e-26 3.635e-26 -25.342 -25.439 -0.098 - FeCl3 7.025e-29 7.146e-29 -28.153 -28.146 0.007 -Fe(2) 8.735e-08 - Fe+2 6.170e-08 2.685e-08 -7.210 -7.571 -0.361 - FeSO4 2.295e-08 2.335e-08 -7.639 -7.632 0.007 - FeCl+ 9.125e-10 7.286e-10 -9.040 -9.138 -0.098 - FeHCO3+ 8.424e-10 6.727e-10 -9.074 -9.172 -0.098 - FeOH+ 5.563e-10 4.442e-10 -9.255 -9.352 -0.098 - FeCO3 3.897e-10 3.964e-10 -9.409 -9.402 0.007 - FeHSO4+ 3.669e-15 2.930e-15 -14.435 -14.533 -0.098 - Fe(HS)2 1.432e-18 1.457e-18 -17.844 -17.837 0.007 - Fe(HS)3- 4.903e-26 3.915e-26 -25.310 -25.407 -0.098 -Fe(3) 3.379e-14 - Fe(OH)3 2.704e-14 2.750e-14 -13.568 -13.561 0.007 - Fe(OH)2+ 5.111e-15 4.081e-15 -14.291 -14.389 -0.098 - Fe(OH)4- 1.644e-15 1.312e-15 -14.784 -14.882 -0.098 - FeOH+2 5.796e-19 2.356e-19 -18.237 -18.628 -0.391 - FeSO4+ 4.683e-23 3.739e-23 -22.329 -22.427 -0.098 - Fe(SO4)2- 5.010e-24 4.000e-24 -23.300 -23.398 -0.098 - Fe+3 3.432e-24 6.974e-25 -23.464 -24.156 -0.692 - FeCl+2 1.019e-24 4.140e-25 -23.992 -24.383 -0.391 - FeCl2+ 4.553e-26 3.635e-26 -25.342 -25.439 -0.098 - FeCl3 7.025e-29 7.146e-29 -28.153 -28.146 0.007 - FeHSO4+2 4.703e-30 1.911e-30 -29.328 -29.719 -0.391 - Fe2(OH)2+4 5.473e-35 1.494e-36 -34.262 -35.826 -1.564 - Fe3(OH)4+5 0.000e+00 0.000e+00 -45.451 -47.895 -2.444 -H(0) 6.856e-12 - H2 3.428e-12 3.487e-12 -11.465 -11.458 0.007 -Na 2.501e-02 - Na+ 2.441e-02 1.954e-02 -1.612 -1.709 -0.097 - NaSO4- 5.997e-04 4.788e-04 -3.222 -3.320 -0.098 - NaHCO3 2.706e-06 2.752e-06 -5.568 -5.560 0.007 - NaCO3- 2.804e-07 2.239e-07 -6.552 -6.650 -0.098 - NaOH 6.639e-09 6.753e-09 -8.178 -8.170 0.007 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -69.474 -69.466 0.007 -S(-2) 3.552e-10 - HS- 3.148e-10 2.467e-10 -9.502 -9.608 -0.106 - H2S 4.048e-11 4.118e-11 -10.393 -10.385 0.007 - S-2 3.777e-15 1.561e-15 -14.423 -14.807 -0.384 - Fe(HS)2 1.432e-18 1.457e-18 -17.844 -17.837 0.007 - Fe(HS)3- 4.903e-26 3.915e-26 -25.310 -25.407 -0.098 -S(6) 1.767e-02 - SO4-2 1.191e-02 4.890e-03 -1.924 -2.311 -0.387 - CaSO4 5.162e-03 5.251e-03 -2.287 -2.280 0.007 - NaSO4- 5.997e-04 4.788e-04 -3.222 -3.320 -0.098 - FeSO4 2.295e-08 2.335e-08 -7.639 -7.632 0.007 - HSO4- 1.137e-08 9.075e-09 -7.944 -8.042 -0.098 - CaHSO4+ 7.355e-10 5.872e-10 -9.133 -9.231 -0.098 - FeHSO4+ 3.669e-15 2.930e-15 -14.435 -14.533 -0.098 - FeSO4+ 4.683e-23 3.739e-23 -22.329 -22.427 -0.098 - Fe(SO4)2- 5.010e-24 4.000e-24 -23.300 -23.398 -0.098 - FeHSO4+2 4.703e-30 1.911e-30 -29.328 -29.719 -0.391 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Anhydrite -0.22 -4.58 -4.36 CaSO4 - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -10.95 -13.81 -2.86 CH4 - CO2(g) -3.50 -4.97 -1.47 CO2 - Fe(OH)3(a) -5.89 -1.00 4.89 Fe(OH)3 - FeS(ppt) -5.54 -9.46 -3.92 FeS - Goethite 0.00 -1.00 -1.00 FeOOH - Gypsum 0.00 -4.58 -4.58 CaSO4:2H2O - H2(g) -8.31 -11.46 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - H2S(g) -9.39 -10.39 -1.00 H2S - Halite -5.00 -3.42 1.58 NaCl - Hematite 2.01 -2.00 -4.01 Fe2O3 - Mackinawite -4.81 -9.46 -4.65 FeS - Melanterite -7.68 -9.89 -2.21 FeSO4:7H2O - O2(g) -66.51 -69.47 -2.96 O2 - Pyrite -0.00 -18.48 -18.48 FeS2 - Siderite -2.89 -13.78 -10.89 FeCO3 - Sulfur -6.96 -2.08 4.88 S - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex5.sel b/Sun/examples/ex5.sel deleted file mode 100644 index a017da32..00000000 --- a/Sun/examples/ex5.sel +++ /dev/null @@ -1,7 +0,0 @@ - sim state soln dist_x time step pH pe Cl pyrite d_pyrite goethite d_goethite calcite d_calcite CO2(g) d_CO2(g) gypsum d_gypsum si_Gypsum - 1 i_soln 1 -99 -99 -99 7 4 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -999.9990 - 1 react 1 -99 0 1 8.27904 -4.94284 0.0000e+00 1.0000e+01 -3.1538e-08 1.0000e+01 1.1047e-08 9.9995e+00 -4.9340e-04 9.9995e+00 -4.8697e-04 0.0000e+00 0.0000e+00 -6.1283 - 1 react 1 -99 0 2 8.17103 -4.28707 5.0000e-04 9.9997e+00 -2.6667e-04 1.0000e+01 2.6666e-04 9.9991e+00 -9.2766e-04 1.0000e+01 1.4180e-04 0.0000e+00 0.0000e+00 -2.0202 - 1 react 1 -99 0 3 7.98207 -3.97043 2.5000e-03 9.9987e+00 -1.3333e-03 1.0001e+01 1.3333e-03 9.9971e+00 -2.9374e-03 1.0002e+01 2.3951e-03 0.0000e+00 0.0000e+00 -1.0629 - 1 react 1 -99 0 4 7.88418 -3.81741 5.0001e-03 9.9973e+00 -2.6667e-03 1.0003e+01 2.6666e-03 9.9944e+00 -5.5594e-03 1.0005e+01 5.1054e-03 0.0000e+00 0.0000e+00 -0.6499 - 1 react 1 -99 0 5 7.71922 -3.56545 2.5011e-02 9.9867e+00 -1.3333e-02 1.0013e+01 1.3333e-02 9.9732e+00 -2.6841e-02 1.0026e+01 2.6489e-02 9.0018e-03 9.0018e-03 0.0000 diff --git a/Sun/examples/ex6.log b/Sun/examples/ex6.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex6.out b/Sun/examples/ex6.out deleted file mode 100644 index 49aa2d56..00000000 --- a/Sun/examples/ex6.out +++ /dev/null @@ -1,3053 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex6 - Output file: ex6.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 6A.--React to phase boundaries. - SOLUTION 1 PURE WATER - pH 7.0 charge - temp 25.0 - PHASES - Gibbsite - Al(OH)3 + 3 H+ = Al+3 + 3 H2O - log_k 8.049 - delta_h -22.792 kcal - Kaolinite - Al2Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 2 Al+3 - log_k 5.708 - delta_h -35.306 kcal - K-mica - KAl3Si3O10(OH)2 + 10 H+ = 3 Al+3 + 3 H4SiO4 + K+ - log_k 12.970 - delta_h -59.377 kcal - K-feldspar - KAlSi3O8 + 4 H2O + 4 H+ = Al+3 + 3 H4SiO4 + K+ - log_k 0.875 - delta_h -12.467 kcal - SELECTED_OUTPUT - file ex6A-B.sel - activities K+ H+ H4SiO4 - si Gibbsite Kaolinite K-mica K-feldspar - equilibrium_phases Gibbsite Kaolinite K-mica K-feldspar - END ------ -TITLE ------ - - Example 6A.--React to phase boundaries. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. PURE WATER - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Pure water - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.121e-18 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.121e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 2 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.001e-07 1.001e-07 -7.000 -7.000 -0.000 - H+ 1.001e-07 1.001e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -H(0) 1.417e-25 - H2 7.087e-26 7.087e-26 -25.150 -25.150 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.081 -42.081 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -39.12 -42.08 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - TITLE Example 6A1.--Find amount of K-feldspar dissolved to - reach gibbsite saturation. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 KAlSi3O8 10.0 - Kaolinite 0.0 0.0 - K-mica 0.0 0.0 - K-feldspar 0.0 0.0 - END ------ -TITLE ------ - - Example 6A1.--Find amount of K-feldspar dissolved to - reach gibbsite saturation. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.671e-08 - K-feldspar -14.68 -13.81 0.88 0.000e+00 0.000e+00 - K-mica -10.68 2.29 12.97 0.000e+00 0.000e+00 - Kaolinite -3.80 1.90 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 2.671e-08 2.671e-08 - K 2.671e-08 2.671e-08 - Si 8.013e-08 8.013e-08 - -----------------------------Description of solution---------------------------- - - pH = 7.006 Charge balance - pe = 11.468 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.262e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.068e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.300e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.016e-07 1.015e-07 -6.993 -6.993 -0.000 - H+ 9.865e-08 9.861e-08 -7.006 -7.006 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 2.671e-08 - Al(OH)4- 2.455e-08 2.454e-08 -7.610 -7.610 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 8.597e-10 8.594e-10 -9.066 -9.066 -0.000 - AlOH+2 1.083e-11 1.081e-11 -10.965 -10.966 -0.001 - Al+3 1.077e-13 1.073e-13 -12.968 -12.969 -0.002 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.099 -40.099 0.000 -K 2.671e-08 - K+ 2.671e-08 2.670e-08 -7.573 -7.574 -0.000 - KOH 9.388e-16 9.388e-16 -15.027 -15.027 0.000 -O(0) 1.314e-12 - O2 6.572e-13 6.572e-13 -12.182 -12.182 0.000 -Si 8.013e-08 - H4SiO4 8.001e-08 8.001e-08 -7.097 -7.097 0.000 - H3SiO4- 1.197e-10 1.196e-10 -9.922 -9.922 -0.000 - H2SiO4-2 8.267e-17 8.253e-17 -16.083 -16.083 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -3.55 -7.10 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -36.95 -40.10 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -14.68 -13.81 0.88 KAlSi3O8 - K-mica -10.68 2.29 12.97 KAl3Si3O10(OH)2 - Kaolinite -3.80 1.90 5.71 Al2Si2O5(OH)4 - O2(g) -9.22 -12.18 -2.96 O2 - Quartz -3.12 -7.10 -3.98 SiO2 - SiO2(a) -4.39 -7.10 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - TITLE Example 6A2.--Find amount of K-feldspar dissolved to - reach kaolinite saturation. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 0.0 - Kaolinite 0.0 KAlSi3O8 10.0 - K-mica 0.0 0.0 - K-feldspar 0.0 0.0 - END ------ -TITLE ------ - - Example 6A2.--Find amount of K-feldspar dissolved to - reach kaolinite saturation. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.00 8.05 8.05 0.000e+00 1.782e-06 1.782e-06 - K-feldspar -5.86 -4.99 0.88 0.000e+00 0.000e+00 - K-mica -1.86 11.11 12.97 0.000e+00 0.000e+00 - Kaolinite -0.00 5.71 5.71 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.179e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 3.968e-07 3.968e-07 - K 2.179e-06 2.179e-06 - Si 6.536e-06 6.536e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.212 Charge balance - pe = 9.894 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.185e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.369e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.876e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550623e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.636e-06 1.633e-06 -5.786 -5.787 -0.001 - H+ 6.141e-09 6.131e-09 -8.212 -8.212 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 3.968e-07 - Al(OH)4- 3.955e-07 3.948e-07 -6.403 -6.404 -0.001 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 5.352e-11 5.343e-11 -10.271 -10.272 -0.001 - AlOH+2 4.208e-14 4.179e-14 -13.376 -13.379 -0.003 - Al+3 2.620e-17 2.579e-17 -16.582 -16.588 -0.007 -H(0) 8.674e-40 - H2 4.337e-40 4.337e-40 -39.363 -39.363 0.000 -K 2.179e-06 - K+ 2.179e-06 2.175e-06 -5.662 -5.663 -0.001 - KOH 1.230e-12 1.230e-12 -11.910 -11.910 0.000 -O(0) 4.433e-14 - O2 2.216e-14 2.216e-14 -13.654 -13.654 0.000 -Si 6.536e-06 - H4SiO4 6.383e-06 6.383e-06 -5.195 -5.195 0.000 - H3SiO4- 1.538e-07 1.535e-07 -6.813 -6.814 -0.001 - H2SiO4-2 1.715e-12 1.703e-12 -11.766 -11.769 -0.003 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -1.64 -5.20 -3.55 SiO2 - Gibbsite -0.00 8.05 8.05 Al(OH)3 - H2(g) -36.21 -39.36 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -5.86 -4.99 0.88 KAlSi3O8 - K-mica -1.86 11.11 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -10.69 -13.65 -2.96 O2 - Quartz -1.21 -5.20 -3.98 SiO2 - SiO2(a) -2.48 -5.20 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - TITLE Example 6A3.--Find amount of K-feldspar dissolved to - reach K-mica saturation. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 0.0 - Kaolinite 0.0 0.0 - K-mica 0.0 KAlSi3O8 10.0 - K-feldspar 0.0 0.0 - END ------ -TITLE ------ - - Example 6A3.--Find amount of K-feldspar dissolved to - reach K-mica saturation. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.73 7.32 8.05 0.000e+00 0.000e+00 - K-feldspar -2.55 -1.67 0.88 0.000e+00 0.000e+00 - K-mica -0.00 12.97 12.97 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -2.001e-05 - Kaolinite 0.00 5.71 5.71 0.000e+00 9.715e-06 9.715e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.851e-07 5.851e-07 - K 2.001e-05 2.001e-05 - Si 4.062e-05 4.061e-05 - -----------------------------Description of solution---------------------------- - - pH = 9.109 Charge balance - pe = 9.063 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.002e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.177e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.710e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550629e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.293e-05 1.286e-05 -4.888 -4.891 -0.002 - H+ 7.822e-10 7.782e-10 -9.107 -9.109 -0.002 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.851e-07 - Al(OH)4- 5.849e-07 5.818e-07 -6.233 -6.235 -0.002 - Al(OH)3 2.402e-10 2.402e-10 -9.619 -9.619 0.000 - Al(OH)2+ 1.275e-12 1.269e-12 -11.894 -11.897 -0.002 - AlOH+2 1.286e-16 1.260e-16 -15.891 -15.900 -0.009 - Al+3 1.034e-20 9.870e-21 -19.985 -20.006 -0.020 -H(0) 6.411e-40 - H2 3.206e-40 3.206e-40 -39.494 -39.494 0.000 -K 2.001e-05 - K+ 2.001e-05 1.991e-05 -4.699 -4.701 -0.002 - KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 -O(0) 8.113e-14 - O2 4.057e-14 4.057e-14 -13.392 -13.392 0.000 -Si 4.062e-05 - H4SiO4 3.412e-05 3.412e-05 -4.467 -4.467 0.000 - H3SiO4- 6.498e-06 6.464e-06 -5.187 -5.189 -0.002 - H2SiO4-2 5.770e-10 5.651e-10 -9.239 -9.248 -0.009 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.48 7.32 10.80 Al(OH)3 - Chalcedony -0.92 -4.47 -3.55 SiO2 - Gibbsite -0.73 7.32 8.05 Al(OH)3 - H2(g) -36.34 -39.49 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -2.55 -1.67 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -10.43 -13.39 -2.96 O2 - Quartz -0.49 -4.47 -3.98 SiO2 - SiO2(a) -1.76 -4.47 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 5. ------------------------------------- - - TITLE Example 6A4.--Find amount of K-feldspar dissolved to - reach K-feldspar saturation. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 0.0 - Kaolinite 0.0 0.0 - K-mica 0.0 0.0 - K-feldspar 0.0 KAlSi3O8 10.0 - END ------ -TITLE ------ - - Example 6A4.--Find amount of K-feldspar dissolved to - reach K-feldspar saturation. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 - K-feldspar -0.00 0.87 0.88 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -1.909e-04 - K-mica -0.00 12.97 12.97 0.000e+00 6.361e-05 6.361e-05 - Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.990e-08 5.989e-08 - K 1.273e-04 1.273e-04 - Si 3.818e-04 3.818e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.389 Charge balance - pe = 8.719 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.273e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.275e-04 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.063e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.110123e+02 - Total O = 5.550698e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 - H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.990e-08 - Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 - Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 - Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 - AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 - Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 -H(0) 8.588e-40 - H2 4.294e-40 4.294e-40 -39.367 -39.367 0.000 -K 1.273e-04 - K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 - KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 -O(0) 4.521e-14 - O2 2.261e-14 2.261e-14 -13.646 -13.646 0.000 -Si 3.818e-04 - H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 - H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 - H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 - Chalcedony -0.00 -3.55 -3.55 SiO2 - Gibbsite -2.00 6.05 8.05 Al(OH)3 - H2(g) -36.22 -39.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -0.00 0.87 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 - O2(g) -10.69 -13.65 -2.96 O2 - Quartz 0.43 -3.55 -3.98 SiO2 - SiO2(a) -0.84 -3.55 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 6. ------------------------------------- - - TITLE Example 6A5.--Find point with kaolinite present, - but no gibbsite. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 KAlSi3O8 10.0 - Kaolinite 0.0 1.0 - END ------ -TITLE ------ - - Example 6A5.--Find point with kaolinite present, - but no gibbsite. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -3.023e-06 - Kaolinite -0.00 5.71 5.71 1.000e+00 1.000e+00 1.237e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.493e-07 5.493e-07 - K 3.023e-06 3.023e-06 - Si 6.596e-06 6.596e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.354 Charge balance - pe = 9.786 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.028e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.671e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.021e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550623e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.267e-06 2.262e-06 -5.645 -5.646 -0.001 - H+ 4.435e-09 4.426e-09 -8.353 -8.354 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.493e-07 - Al(OH)4- 5.480e-07 5.469e-07 -6.261 -6.262 -0.001 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 3.865e-11 3.857e-11 -10.413 -10.414 -0.001 - AlOH+2 2.196e-14 2.178e-14 -13.658 -13.662 -0.004 - Al+3 9.882e-18 9.704e-18 -17.005 -17.013 -0.008 -H(0) 7.444e-40 - H2 3.722e-40 3.722e-40 -39.429 -39.429 0.000 -K 3.023e-06 - K+ 3.023e-06 3.017e-06 -5.520 -5.520 -0.001 - KOH 2.364e-12 2.364e-12 -11.626 -11.626 0.000 -O(0) 6.019e-14 - O2 3.009e-14 3.009e-14 -13.522 -13.522 0.000 -Si 6.596e-06 - H4SiO4 6.383e-06 6.383e-06 -5.195 -5.195 0.000 - H3SiO4- 2.131e-07 2.127e-07 -6.671 -6.672 -0.001 - H2SiO4-2 3.295e-12 3.269e-12 -11.482 -11.486 -0.004 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -1.64 -5.20 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -36.28 -39.43 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -5.58 -4.70 0.88 KAlSi3O8 - K-mica -1.57 11.40 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -10.56 -13.52 -2.96 O2 - Quartz -1.21 -5.20 -3.98 SiO2 - SiO2(a) -2.48 -5.20 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 7. ------------------------------------- - - TITLE Example 6A6.--Find point with K-mica present, - but no kaolinite - USE solution 1 - EQUILIBRIUM_PHASES 1 - Kaolinite 0.0 KAlSi3O8 10.0 - K-mica 0.0 1.0 - END ------ -TITLE ------ - - Example 6A6.--Find point with K-mica present, - but no kaolinite - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - K-mica 0.00 12.97 12.97 1.000e+00 1.000e+00 1.079e-05 - Kaolinite 0.00 5.71 5.71 - KAlSi3O8 is reactant 1.000e+01 1.000e+01 -3.268e-05 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 3.263e-07 3.263e-07 - K 2.190e-05 2.190e-05 - Si 6.569e-05 6.569e-05 - -----------------------------Description of solution---------------------------- - - pH = 9.070 Charge balance - pe = 8.836 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.190e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.288e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.154e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550635e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.183e-05 1.176e-05 -4.927 -4.930 -0.002 - H+ 8.558e-10 8.512e-10 -9.068 -9.070 -0.002 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 3.263e-07 - Al(OH)4- 3.262e-07 3.244e-07 -6.487 -6.489 -0.002 - Al(OH)3 1.465e-10 1.465e-10 -9.834 -9.834 0.000 - Al(OH)2+ 8.509e-13 8.463e-13 -12.070 -12.072 -0.002 - AlOH+2 9.393e-17 9.191e-17 -16.027 -16.037 -0.009 - Al+3 8.269e-21 7.876e-21 -20.083 -20.104 -0.021 -H(0) 2.179e-39 - H2 1.089e-39 1.089e-39 -38.963 -38.963 0.000 -K 2.190e-05 - K+ 2.190e-05 2.178e-05 -4.660 -4.662 -0.002 - KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 -O(0) 7.024e-15 - O2 3.512e-15 3.512e-15 -14.454 -14.454 0.000 -Si 6.569e-05 - H4SiO4 5.595e-05 5.595e-05 -4.252 -4.252 0.000 - H3SiO4- 9.745e-06 9.692e-06 -5.011 -5.014 -0.002 - H2SiO4-2 7.916e-10 7.745e-10 -9.101 -9.111 -0.009 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.69 7.11 10.80 Al(OH)3 - Chalcedony -0.70 -4.25 -3.55 SiO2 - Gibbsite -0.94 7.11 8.05 Al(OH)3 - H2(g) -35.81 -38.96 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -2.12 -1.24 0.88 KAlSi3O8 - K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -11.49 -14.45 -2.96 O2 - Quartz -0.27 -4.25 -3.98 SiO2 - SiO2(a) -1.54 -4.25 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 8. ------------------------------------- - - TITLE Example 6B.--Path between phase boundaries. - USE solution 1 - EQUILIBRIUM_PHASES 1 - Kaolinite 0.0 0.0 - Gibbsite 0.0 0.0 - K-mica 0.0 0.0 - K-feldspar 0.0 0.0 - REACTION 1 - K-feldspar 1.0 - 0.04 0.08 0.16 0.32 0.64 1.0 2.0 4.0 - 8.0 16.0 32.0 64.0 100 200 umol - END ------ -TITLE ------ - - Example 6B.--Path between phase boundaries. - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 4.000e-08 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.00 8.05 8.05 0.000e+00 1.187e-08 1.187e-08 - K-feldspar -13.96 -13.08 0.88 0.000e+00 0.000e+00 - K-mica -9.95 3.02 12.97 0.000e+00 0.000e+00 - Kaolinite -3.45 2.25 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 2.813e-08 2.813e-08 - K 4.000e-08 4.000e-08 - Si 1.200e-07 1.200e-07 - -----------------------------Description of solution---------------------------- - - pH = 7.031 Charge balance - pe = 11.457 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.339e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.244e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.761e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.077e-07 1.076e-07 -6.968 -6.968 -0.000 - H+ 9.306e-08 9.302e-08 -7.031 -7.031 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 2.813e-08 - Al(OH)4- 2.603e-08 2.602e-08 -7.585 -7.585 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 8.110e-10 8.107e-10 -9.091 -9.091 -0.000 - AlOH+2 9.638e-12 9.621e-12 -11.016 -11.017 -0.001 - Al+3 9.044e-14 9.009e-14 -13.044 -13.045 -0.002 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.127 -40.127 0.000 -K 4.000e-08 - K+ 4.000e-08 3.998e-08 -7.398 -7.398 -0.000 - KOH 1.490e-15 1.490e-15 -14.827 -14.827 0.000 -O(0) 1.494e-12 - O2 7.470e-13 7.470e-13 -12.127 -12.127 0.000 -Si 1.200e-07 - H4SiO4 1.198e-07 1.198e-07 -6.922 -6.922 0.000 - H3SiO4- 1.900e-10 1.899e-10 -9.721 -9.721 -0.000 - H2SiO4-2 1.391e-16 1.389e-16 -15.857 -15.857 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -3.37 -6.92 -3.55 SiO2 - Gibbsite -0.00 8.05 8.05 Al(OH)3 - H2(g) -36.98 -40.13 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -13.96 -13.08 0.88 KAlSi3O8 - K-mica -9.95 3.02 12.97 KAl3Si3O10(OH)2 - Kaolinite -3.45 2.25 5.71 Al2Si2O5(OH)4 - O2(g) -9.17 -12.13 -2.96 O2 - Quartz -2.94 -6.92 -3.98 SiO2 - SiO2(a) -4.21 -6.92 -2.71 SiO2 - -Reaction step 2. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 8.000e-08 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.00 8.05 8.05 0.000e+00 4.713e-08 4.713e-08 - K-feldspar -12.68 -11.80 0.88 0.000e+00 0.000e+00 - K-mica -8.68 4.29 12.97 0.000e+00 0.000e+00 - Kaolinite -2.85 2.86 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 3.287e-08 3.287e-08 - K 8.000e-08 8.000e-08 - Si 2.400e-07 2.400e-07 - -----------------------------Description of solution---------------------------- - - pH = 7.106 Charge balance - pe = 11.288 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.591e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.786e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.120e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.278e-07 1.277e-07 -6.894 -6.894 -0.000 - H+ 7.842e-08 7.838e-08 -7.106 -7.106 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 3.287e-08 - Al(OH)4- 3.089e-08 3.088e-08 -7.510 -7.510 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 6.834e-10 6.831e-10 -9.165 -9.166 -0.000 - AlOH+2 6.845e-12 6.832e-12 -11.165 -11.165 -0.001 - Al+3 5.414e-14 5.391e-14 -13.267 -13.268 -0.002 -H(0) 2.308e-40 - H2 1.154e-40 1.154e-40 -39.938 -39.938 0.000 -K 8.000e-08 - K+ 8.000e-08 7.996e-08 -7.097 -7.097 -0.000 - KOH 3.537e-15 3.537e-15 -14.451 -14.451 0.000 -O(0) 6.262e-13 - O2 3.131e-13 3.131e-13 -12.504 -12.504 0.000 -Si 2.400e-07 - H4SiO4 2.395e-07 2.395e-07 -6.621 -6.621 0.000 - H3SiO4- 4.508e-10 4.506e-10 -9.346 -9.346 -0.000 - H2SiO4-2 3.918e-16 3.911e-16 -15.407 -15.408 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -3.07 -6.62 -3.55 SiO2 - Gibbsite -0.00 8.05 8.05 Al(OH)3 - H2(g) -36.79 -39.94 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -12.68 -11.80 0.88 KAlSi3O8 - K-mica -8.68 4.29 12.97 KAl3Si3O10(OH)2 - Kaolinite -2.85 2.86 5.71 Al2Si2O5(OH)4 - O2(g) -9.54 -12.50 -2.96 O2 - Quartz -2.64 -6.62 -3.98 SiO2 - SiO2(a) -3.91 -6.62 -2.71 SiO2 - -Reaction step 3. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 1.600e-07 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 0.000e+00 1.160e-07 1.160e-07 - K-feldspar -11.34 -10.47 0.88 0.000e+00 0.000e+00 - K-mica -7.34 5.63 12.97 0.000e+00 0.000e+00 - Kaolinite -2.25 3.46 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 4.398e-08 4.398e-08 - K 1.600e-07 1.600e-07 - Si 4.800e-07 4.800e-07 - -----------------------------Description of solution---------------------------- - - pH = 7.241 Charge balance - pe = 11.241 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.179e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.919e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.323e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.745e-07 1.744e-07 -6.758 -6.758 -0.000 - H+ 5.743e-08 5.740e-08 -7.241 -7.241 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 4.398e-08 - Al(OH)4- 4.219e-08 4.217e-08 -7.375 -7.375 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 5.005e-10 5.002e-10 -9.301 -9.301 -0.000 - AlOH+2 3.671e-12 3.663e-12 -11.435 -11.436 -0.001 - Al+3 2.127e-14 2.117e-14 -13.672 -13.674 -0.002 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.113 -40.113 0.000 -K 1.600e-07 - K+ 1.600e-07 1.599e-07 -6.796 -6.796 -0.000 - KOH 9.661e-15 9.661e-15 -14.015 -14.015 0.000 -O(0) 1.405e-12 - O2 7.025e-13 7.025e-13 -12.153 -12.153 0.000 -Si 4.800e-07 - H4SiO4 4.788e-07 4.788e-07 -6.320 -6.320 0.000 - H3SiO4- 1.231e-09 1.230e-09 -8.910 -8.910 -0.000 - H2SiO4-2 1.461e-15 1.458e-15 -14.835 -14.836 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -2.77 -6.32 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -36.96 -40.11 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -11.34 -10.47 0.88 KAlSi3O8 - K-mica -7.34 5.63 12.97 KAl3Si3O10(OH)2 - Kaolinite -2.25 3.46 5.71 Al2Si2O5(OH)4 - O2(g) -9.19 -12.15 -2.96 O2 - Quartz -2.34 -6.32 -3.98 SiO2 - SiO2(a) -3.61 -6.32 -2.71 SiO2 - -Reaction step 4. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 3.200e-07 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.00 8.05 8.05 0.000e+00 2.499e-07 2.499e-07 - K-feldspar -9.93 -9.05 0.88 0.000e+00 0.000e+00 - K-mica -5.93 7.04 12.97 0.000e+00 0.000e+00 - Kaolinite -1.65 4.06 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 7.007e-08 7.007e-08 - K 3.200e-07 3.200e-07 - Si 9.600e-07 9.600e-07 - -----------------------------Description of solution---------------------------- - - pH = 7.451 Charge balance - pe = 11.188 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 3.557e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.302e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.281e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.832e-07 2.830e-07 -6.548 -6.548 -0.000 - H+ 3.539e-08 3.537e-08 -7.451 -7.451 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 7.007e-08 - Al(OH)4- 6.848e-08 6.843e-08 -7.164 -7.165 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 3.085e-10 3.082e-10 -9.511 -9.511 -0.000 - AlOH+2 1.395e-12 1.391e-12 -11.855 -11.857 -0.001 - Al+3 4.984e-15 4.953e-15 -14.302 -14.305 -0.003 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.429 -40.429 0.000 -K 3.200e-07 - K+ 3.200e-07 3.198e-07 -6.495 -6.495 -0.000 - KOH 3.135e-14 3.135e-14 -13.504 -13.504 0.000 -O(0) 6.000e-12 - O2 3.000e-12 3.000e-12 -11.523 -11.523 0.000 -Si 9.600e-07 - H4SiO4 9.560e-07 9.560e-07 -6.020 -6.020 0.000 - H3SiO4- 3.988e-09 3.986e-09 -8.399 -8.400 -0.000 - H2SiO4-2 7.687e-15 7.665e-15 -14.114 -14.115 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -2.47 -6.02 -3.55 SiO2 - Gibbsite -0.00 8.05 8.05 Al(OH)3 - H2(g) -37.28 -40.43 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -9.93 -9.05 0.88 KAlSi3O8 - K-mica -5.93 7.04 12.97 KAl3Si3O10(OH)2 - Kaolinite -1.65 4.06 5.71 Al2Si2O5(OH)4 - O2(g) -8.56 -11.52 -2.96 O2 - Quartz -2.04 -6.02 -3.98 SiO2 - SiO2(a) -3.31 -6.02 -2.71 SiO2 - -Reaction step 5. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 6.400e-07 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 0.000e+00 5.130e-07 5.130e-07 - K-feldspar -8.47 -7.59 0.88 0.000e+00 0.000e+00 - K-mica -4.46 8.51 12.97 0.000e+00 0.000e+00 - Kaolinite -1.05 4.66 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.270e-07 1.270e-07 - K 6.400e-07 6.400e-07 - Si 1.920e-06 1.920e-06 - -----------------------------Description of solution---------------------------- - - pH = 7.715 Charge balance - pe = 10.994 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 6.595e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.021e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.096e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 5.193e-07 5.189e-07 -6.285 -6.285 -0.000 - H+ 1.931e-08 1.929e-08 -7.714 -7.715 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.270e-07 - Al(OH)4- 1.256e-07 1.254e-07 -6.901 -6.902 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 1.683e-10 1.681e-10 -9.774 -9.774 -0.000 - AlOH+2 4.155e-13 4.139e-13 -12.381 -12.383 -0.002 - Al+3 8.109e-16 8.040e-16 -15.091 -15.095 -0.004 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.567 -40.567 0.000 -K 6.400e-07 - K+ 6.400e-07 6.394e-07 -6.194 -6.194 -0.000 - KOH 1.149e-13 1.149e-13 -12.940 -12.940 0.000 -O(0) 1.135e-11 - O2 5.673e-12 5.673e-12 -11.246 -11.246 0.000 -Si 1.920e-06 - H4SiO4 1.905e-06 1.905e-06 -5.720 -5.720 0.000 - H3SiO4- 1.458e-08 1.456e-08 -7.836 -7.837 -0.000 - H2SiO4-2 5.153e-14 5.134e-14 -13.288 -13.290 -0.002 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -2.17 -5.72 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -37.42 -40.57 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -8.47 -7.59 0.88 KAlSi3O8 - K-mica -4.46 8.51 12.97 KAl3Si3O10(OH)2 - Kaolinite -1.05 4.66 5.71 Al2Si2O5(OH)4 - O2(g) -8.29 -11.25 -2.96 O2 - Quartz -1.74 -5.72 -3.98 SiO2 - SiO2(a) -3.01 -5.72 -2.71 SiO2 - -Reaction step 6. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 1.000e-06 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 0.000e+00 8.081e-07 8.081e-07 - K-feldspar -7.51 -6.64 0.88 0.000e+00 0.000e+00 - K-mica -3.51 9.46 12.97 0.000e+00 0.000e+00 - Kaolinite -0.67 5.04 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.919e-07 1.919e-07 - K 1.000e-06 1.000e-06 - Si 3.000e-06 3.000e-06 - -----------------------------Description of solution---------------------------- - - pH = 7.896 Charge balance - pe = 10.790 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.013e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.576e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.467e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 11 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.879e-07 7.870e-07 -6.104 -6.104 -0.001 - H+ 1.274e-08 1.272e-08 -7.895 -7.896 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.919e-07 - Al(OH)4- 1.905e-07 1.903e-07 -6.720 -6.721 -0.001 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 1.110e-10 1.109e-10 -9.955 -9.955 -0.001 - AlOH+2 1.808e-13 1.799e-13 -12.743 -12.745 -0.002 - Al+3 2.328e-16 2.304e-16 -15.633 -15.638 -0.005 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.520 -40.520 0.000 -K 1.000e-06 - K+ 1.000e-06 9.988e-07 -6.000 -6.001 -0.001 - KOH 2.723e-13 2.723e-13 -12.565 -12.565 0.000 -O(0) 9.161e-12 - O2 4.580e-12 4.580e-12 -11.339 -11.339 0.000 -Si 3.000e-06 - H4SiO4 2.966e-06 2.966e-06 -5.528 -5.528 0.000 - H3SiO4- 3.442e-08 3.438e-08 -7.463 -7.464 -0.001 - H2SiO4-2 1.847e-13 1.838e-13 -12.734 -12.736 -0.002 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -1.98 -5.53 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -37.37 -40.52 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -7.51 -6.64 0.88 KAlSi3O8 - K-mica -3.51 9.46 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.67 5.04 5.71 Al2Si2O5(OH)4 - O2(g) -8.38 -11.34 -2.96 O2 - Quartz -1.55 -5.53 -3.98 SiO2 - SiO2(a) -2.82 -5.53 -2.71 SiO2 - -Reaction step 7. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 2.000e-06 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 0.000e+00 1.633e-06 1.633e-06 - K-feldspar -6.04 -5.17 0.88 0.000e+00 0.000e+00 - K-mica -2.04 10.93 12.97 0.000e+00 0.000e+00 - Kaolinite -0.07 5.64 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 3.666e-07 3.666e-07 - K 2.000e-06 2.000e-06 - Si 6.000e-06 6.000e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.178 Charge balance - pe = 10.498 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.007e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.100e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.114e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 12 - Total H = 1.110124e+02 - Total O = 5.550623e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.511e-06 1.508e-06 -5.821 -5.822 -0.001 - H+ 6.648e-09 6.637e-09 -8.177 -8.178 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 3.666e-07 - Al(OH)4- 3.653e-07 3.647e-07 -6.437 -6.438 -0.001 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 5.794e-11 5.784e-11 -10.237 -10.238 -0.001 - AlOH+2 4.931e-14 4.898e-14 -13.307 -13.310 -0.003 - Al+3 3.322e-17 3.273e-17 -16.479 -16.485 -0.006 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -40.501 -40.501 0.000 -K 2.000e-06 - K+ 2.000e-06 1.997e-06 -5.699 -5.700 -0.001 - KOH 1.043e-12 1.043e-12 -11.982 -11.982 0.000 -O(0) 8.387e-12 - O2 4.194e-12 4.194e-12 -11.377 -11.377 0.000 -Si 6.000e-06 - H4SiO4 5.869e-06 5.869e-06 -5.231 -5.231 0.000 - H3SiO4- 1.306e-07 1.304e-07 -6.884 -6.885 -0.001 - H2SiO4-2 1.345e-12 1.336e-12 -11.871 -11.874 -0.003 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -1.68 -5.23 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -37.35 -40.50 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -6.04 -5.17 0.88 KAlSi3O8 - K-mica -2.04 10.93 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.07 5.64 5.71 Al2Si2O5(OH)4 - O2(g) -8.42 -11.38 -2.96 O2 - Quartz -1.25 -5.23 -3.98 SiO2 - SiO2(a) -2.52 -5.23 -2.71 SiO2 - -Reaction step 8. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 4.000e-06 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.11 7.94 8.05 0.000e+00 0.000e+00 - K-feldspar -5.11 -4.23 0.88 0.000e+00 0.000e+00 - K-mica -1.32 11.65 12.97 0.000e+00 0.000e+00 - Kaolinite -0.00 5.71 5.71 0.000e+00 1.712e-06 1.712e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.761e-07 5.761e-07 - K 4.000e-06 4.000e-06 - Si 8.576e-06 8.576e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.484 Charge balance - pe = 9.390 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.003e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.728e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.241e-17 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 12 - Total H = 1.110124e+02 - Total O = 5.550623e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.059e-06 3.051e-06 -5.514 -5.516 -0.001 - H+ 3.288e-09 3.281e-09 -8.483 -8.484 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.761e-07 - Al(OH)4- 5.751e-07 5.737e-07 -6.240 -6.241 -0.001 - Al(OH)3 9.987e-10 9.987e-10 -9.001 -9.001 0.000 - Al(OH)2+ 2.229e-11 2.224e-11 -10.652 -10.653 -0.001 - AlOH+2 9.396e-15 9.309e-15 -14.027 -14.031 -0.004 - Al+3 3.140e-18 3.074e-18 -17.503 -17.512 -0.009 -H(0) 2.529e-39 - H2 1.264e-39 1.264e-39 -38.898 -38.898 0.000 -K 4.000e-06 - K+ 4.000e-06 3.991e-06 -5.398 -5.399 -0.001 - KOH 4.218e-12 4.218e-12 -11.375 -11.375 0.000 -O(0) 5.215e-15 - O2 2.607e-15 2.607e-15 -14.584 -14.584 0.000 -Si 8.576e-06 - H4SiO4 8.206e-06 8.206e-06 -5.086 -5.086 0.000 - H3SiO4- 3.697e-07 3.688e-07 -6.432 -6.433 -0.001 - H2SiO4-2 7.719e-12 7.647e-12 -11.112 -11.116 -0.004 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.86 7.94 10.80 Al(OH)3 - Chalcedony -1.53 -5.09 -3.55 SiO2 - Gibbsite -0.11 7.94 8.05 Al(OH)3 - H2(g) -35.75 -38.90 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -5.11 -4.23 0.88 KAlSi3O8 - K-mica -1.32 11.65 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -11.62 -14.58 -2.96 O2 - Quartz -1.11 -5.09 -3.98 SiO2 - SiO2(a) -2.37 -5.09 -2.71 SiO2 - -Reaction step 9. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 8.000e-06 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.38 7.67 8.05 0.000e+00 0.000e+00 - K-feldspar -3.97 -3.10 0.88 0.000e+00 0.000e+00 - K-mica -0.73 12.24 12.97 0.000e+00 0.000e+00 - Kaolinite -0.00 5.71 5.71 0.000e+00 3.695e-06 3.695e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 6.110e-07 6.110e-07 - K 8.000e-06 8.000e-06 - Si 1.661e-05 1.661e-05 - -----------------------------Description of solution---------------------------- - - pH = 8.779 Charge balance - pe = 9.506 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.002e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.833e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.133e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550625e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.035e-06 6.015e-06 -5.219 -5.221 -0.001 - H+ 1.670e-09 1.664e-09 -8.777 -8.779 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 6.110e-07 - Al(OH)4- 6.105e-07 6.084e-07 -6.214 -6.216 -0.001 - Al(OH)3 5.373e-10 5.373e-10 -9.270 -9.270 0.000 - Al(OH)2+ 6.089e-12 6.069e-12 -11.215 -11.217 -0.001 - AlOH+2 1.306e-15 1.289e-15 -14.884 -14.890 -0.006 - Al+3 2.224e-19 2.159e-19 -18.653 -18.666 -0.013 -H(0) 3.823e-40 - H2 1.911e-40 1.911e-40 -39.719 -39.719 0.000 -K 8.000e-06 - K+ 8.000e-06 7.974e-06 -5.097 -5.098 -0.001 - KOH 1.661e-11 1.661e-11 -10.780 -10.780 0.000 -O(0) 2.282e-13 - O2 1.141e-13 1.141e-13 -12.943 -12.943 0.000 -Si 1.661e-05 - H4SiO4 1.525e-05 1.525e-05 -4.817 -4.817 0.000 - H3SiO4- 1.356e-06 1.352e-06 -5.868 -5.869 -0.001 - H2SiO4-2 5.598e-11 5.524e-11 -10.252 -10.258 -0.006 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.13 7.67 10.80 Al(OH)3 - Chalcedony -1.27 -4.82 -3.55 SiO2 - Gibbsite -0.38 7.67 8.05 Al(OH)3 - H2(g) -36.57 -39.72 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -3.97 -3.10 0.88 KAlSi3O8 - K-mica -0.73 12.24 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -9.98 -12.94 -2.96 O2 - Quartz -0.84 -4.82 -3.98 SiO2 - SiO2(a) -2.10 -4.82 -2.71 SiO2 - -Reaction step 10. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 1.600e-05 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.64 7.41 8.05 0.000e+00 0.000e+00 - K-feldspar -2.89 -2.01 0.88 0.000e+00 0.000e+00 - K-mica -0.17 12.80 12.97 0.000e+00 0.000e+00 - Kaolinite 0.00 5.71 5.71 0.000e+00 7.701e-06 7.701e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.987e-07 5.987e-07 - K 1.600e-05 1.600e-05 - Si 3.260e-05 3.260e-05 - -----------------------------Description of solution---------------------------- - - pH = 9.035 Charge balance - pe = 8.801 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.600e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.780e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.512e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550628e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.089e-05 1.084e-05 -4.963 -4.965 -0.002 - H+ 9.275e-10 9.232e-10 -9.033 -9.035 -0.002 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.987e-07 - Al(OH)4- 5.984e-07 5.956e-07 -6.223 -6.225 -0.002 - Al(OH)3 2.918e-10 2.918e-10 -9.535 -9.535 0.000 - Al(OH)2+ 1.837e-12 1.828e-12 -11.736 -11.738 -0.002 - AlOH+2 2.194e-16 2.153e-16 -15.659 -15.667 -0.008 - Al+3 2.087e-20 2.001e-20 -19.681 -19.699 -0.018 -H(0) 3.011e-39 - H2 1.505e-39 1.505e-39 -38.822 -38.822 0.000 -K 1.600e-05 - K+ 1.600e-05 1.593e-05 -4.796 -4.798 -0.002 - KOH 5.981e-11 5.981e-11 -10.223 -10.223 0.000 -O(0) 3.679e-15 - O2 1.840e-15 1.840e-15 -14.735 -14.735 0.000 -Si 3.260e-05 - H4SiO4 2.809e-05 2.809e-05 -4.551 -4.551 0.000 - H3SiO4- 4.508e-06 4.487e-06 -5.346 -5.348 -0.002 - H2SiO4-2 3.368e-10 3.306e-10 -9.473 -9.481 -0.008 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.39 7.41 10.80 Al(OH)3 - Chalcedony -1.00 -4.55 -3.55 SiO2 - Gibbsite -0.64 7.41 8.05 Al(OH)3 - H2(g) -35.67 -38.82 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -2.89 -2.01 0.88 KAlSi3O8 - K-mica -0.17 12.80 12.97 KAl3Si3O10(OH)2 - Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -11.78 -14.74 -2.96 O2 - Quartz -0.57 -4.55 -3.98 SiO2 - SiO2(a) -1.84 -4.55 -2.71 SiO2 - -Reaction step 11. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 3.200e-05 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.93 7.12 8.05 0.000e+00 0.000e+00 - K-feldspar -2.14 -1.26 0.88 0.000e+00 0.000e+00 - K-mica -0.00 12.97 12.97 0.000e+00 1.020e-05 1.020e-05 - Kaolinite 0.00 5.71 5.71 0.000e+00 5.270e-07 5.270e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 3.349e-07 3.349e-07 - K 2.180e-05 2.180e-05 - Si 6.434e-05 6.433e-05 - -----------------------------Description of solution---------------------------- - - pH = 9.072 Charge balance - pe = 8.977 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.180e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.280e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 2.694e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 13 - Total H = 1.110124e+02 - Total O = 5.550635e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.188e-05 1.182e-05 -4.925 -4.928 -0.002 - H+ 8.519e-10 8.473e-10 -9.070 -9.072 -0.002 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 3.349e-07 - Al(OH)4- 3.348e-07 3.330e-07 -6.475 -6.478 -0.002 - Al(OH)3 1.497e-10 1.497e-10 -9.825 -9.825 0.000 - Al(OH)2+ 8.654e-13 8.607e-13 -12.063 -12.065 -0.002 - AlOH+2 9.510e-17 9.305e-17 -16.022 -16.031 -0.009 - Al+3 8.332e-21 7.937e-21 -20.079 -20.100 -0.021 -H(0) 1.127e-39 - H2 5.637e-40 5.637e-40 -39.249 -39.249 0.000 -K 2.180e-05 - K+ 2.180e-05 2.168e-05 -4.662 -4.664 -0.002 - KOH 8.871e-11 8.872e-11 -10.052 -10.052 0.000 -O(0) 2.624e-14 - O2 1.312e-14 1.312e-14 -13.882 -13.882 0.000 -Si 6.434e-05 - H4SiO4 5.475e-05 5.475e-05 -4.262 -4.262 0.000 - H3SiO4- 9.581e-06 9.529e-06 -5.019 -5.021 -0.002 - H2SiO4-2 7.819e-10 7.650e-10 -9.107 -9.116 -0.009 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.68 7.12 10.80 Al(OH)3 - Chalcedony -0.71 -4.26 -3.55 SiO2 - Gibbsite -0.93 7.12 8.05 Al(OH)3 - H2(g) -36.10 -39.25 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -2.14 -1.26 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite 0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -10.92 -13.88 -2.96 O2 - Quartz -0.28 -4.26 -3.98 SiO2 - SiO2(a) -1.55 -4.26 -2.71 SiO2 - -Reaction step 12. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 6.400e-05 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -1.35 6.69 8.05 0.000e+00 0.000e+00 - K-feldspar -1.29 -0.42 0.88 0.000e+00 0.000e+00 - K-mica 0.00 12.97 12.97 0.000e+00 2.127e-05 2.127e-05 - Kaolinite -0.30 5.41 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.812e-07 1.812e-07 - K 4.273e-05 4.273e-05 - Si 1.282e-04 1.282e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.225 Charge balance - pe = 8.690 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 4.273e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.327e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.000e-13 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 21 - Total H = 1.110124e+02 - Total O = 5.550647e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.694e-05 1.681e-05 -4.771 -4.774 -0.003 - H+ 5.999e-10 5.954e-10 -9.222 -9.225 -0.003 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.812e-07 - Al(OH)4- 1.812e-07 1.798e-07 -6.742 -6.745 -0.003 - Al(OH)3 5.680e-11 5.680e-11 -10.246 -10.246 0.000 - Al(OH)2+ 2.313e-13 2.295e-13 -12.636 -12.639 -0.003 - AlOH+2 1.797e-17 1.744e-17 -16.745 -16.759 -0.013 - Al+3 1.118e-21 1.045e-21 -20.951 -20.981 -0.029 -H(0) 2.093e-39 - H2 1.046e-39 1.046e-39 -38.980 -38.980 0.000 -K 4.273e-05 - K+ 4.273e-05 4.240e-05 -4.369 -4.373 -0.003 - KOH 2.469e-10 2.469e-10 -9.607 -9.607 0.000 -O(0) 7.616e-15 - O2 3.808e-15 3.808e-15 -14.419 -14.419 0.000 -Si 1.282e-04 - H4SiO4 1.026e-04 1.026e-04 -3.989 -3.989 0.000 - H3SiO4- 2.560e-05 2.540e-05 -4.592 -4.595 -0.003 - H2SiO4-2 2.992e-09 2.902e-09 -8.524 -8.537 -0.013 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.11 6.69 10.80 Al(OH)3 - Chalcedony -0.44 -3.99 -3.55 SiO2 - Gibbsite -1.35 6.69 8.05 Al(OH)3 - H2(g) -35.83 -38.98 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -1.29 -0.42 0.88 KAlSi3O8 - K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.30 5.41 5.71 Al2Si2O5(OH)4 - O2(g) -11.46 -14.42 -2.96 O2 - Quartz -0.01 -3.99 -3.98 SiO2 - SiO2(a) -1.28 -3.99 -2.71 SiO2 - -Reaction step 13. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 1.000e-04 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -1.62 6.43 8.05 0.000e+00 0.000e+00 - K-feldspar -0.76 0.11 0.88 0.000e+00 0.000e+00 - K-mica 0.00 12.97 12.97 0.000e+00 3.329e-05 3.329e-05 - Kaolinite -0.48 5.23 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.179e-07 1.179e-07 - K 6.671e-05 6.671e-05 - Si 2.001e-04 2.001e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.305 Charge balance - pe = 8.570 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 6.671e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 6.706e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.012e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.550662e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.038e-05 2.019e-05 -4.691 -4.695 -0.004 - H+ 5.006e-10 4.959e-10 -9.301 -9.305 -0.004 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.179e-07 - Al(OH)4- 1.179e-07 1.167e-07 -6.929 -6.933 -0.004 - Al(OH)3 3.072e-11 3.072e-11 -10.513 -10.513 0.000 - Al(OH)2+ 1.044e-13 1.034e-13 -12.981 -12.985 -0.004 - AlOH+2 6.796e-18 6.543e-18 -17.168 -17.184 -0.016 - Al+3 3.554e-22 3.267e-22 -21.449 -21.486 -0.037 -H(0) 2.521e-39 - H2 1.260e-39 1.260e-39 -38.899 -38.899 0.000 -K 6.671e-05 - K+ 6.671e-05 6.608e-05 -4.176 -4.180 -0.004 - KOH 4.620e-10 4.620e-10 -9.335 -9.335 0.000 -O(0) 5.248e-15 - O2 2.624e-15 2.624e-15 -14.581 -14.581 0.000 -Si 2.001e-04 - H4SiO4 1.539e-04 1.539e-04 -3.813 -3.813 0.000 - H3SiO4- 4.620e-05 4.576e-05 -4.335 -4.339 -0.004 - H2SiO4-2 6.519e-09 6.277e-09 -8.186 -8.202 -0.016 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.37 6.43 10.80 Al(OH)3 - Chalcedony -0.26 -3.81 -3.55 SiO2 - Gibbsite -1.62 6.43 8.05 Al(OH)3 - H2(g) -35.75 -38.90 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -0.76 0.11 0.88 KAlSi3O8 - K-mica 0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.48 5.23 5.71 Al2Si2O5(OH)4 - O2(g) -11.62 -14.58 -2.96 O2 - Quartz 0.17 -3.81 -3.98 SiO2 - SiO2(a) -1.10 -3.81 -2.71 SiO2 - -Reaction step 14. - -Using solution 1. PURE WATER -Using pure phase assemblage 1. -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 8. - - 2.000e-04 moles of the following reaction have been added: - - Relative - Reactant moles - - K-feldspar 1.00 - - Relative - Element moles - Al 1.00 - K 1.00 - O 8.00 - Si 3.00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 - K-feldspar 0.00 0.88 0.88 0.000e+00 9.120e-06 9.120e-06 - K-mica -0.00 12.97 12.97 0.000e+00 6.361e-05 6.361e-05 - Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.990e-08 5.989e-08 - K 1.273e-04 1.273e-04 - Si 3.818e-04 3.818e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.389 Charge balance - pe = 8.947 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.273e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.275e-04 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.728e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 15 - Total H = 1.110123e+02 - Total O = 5.550698e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 - H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.990e-08 - Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 - Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 - Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 - AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 - Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 -H(0) 3.013e-40 - H2 1.507e-40 1.507e-40 -39.822 -39.822 0.000 -K 1.273e-04 - K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 - KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 -O(0) 3.673e-13 - O2 1.836e-13 1.836e-13 -12.736 -12.736 0.000 -Si 3.818e-04 - H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 - H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 - H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 - Chalcedony -0.00 -3.55 -3.55 SiO2 - Gibbsite -2.00 6.05 8.05 Al(OH)3 - H2(g) -36.67 -39.82 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar 0.00 0.88 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 - O2(g) -9.78 -12.74 -2.96 O2 - Quartz 0.43 -3.55 -3.98 SiO2 - SiO2(a) -0.84 -3.55 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 9. ------------------------------------- - - TITLE Example 6C.--kinetic calculation - SOLUTION 1 - units mol/kgw - Al 1.e-13 - K 1.e-13 - Si 3.e-13 - EQUILIBRIUM_PHASES 1 - Gibbsite 0.0 0.0 - Kaolinite 0.0 0.0 - K-mica 0.0 0.0 - KINETICS 1 - K-feldspar - parms 1.36e-11 - m0 2.16 - m 1.94 - step_divide 1e-6 - steps 1e2 1e3 1e4 1e5 1e6 1e7 1e8 - INCREMENTAL_REACTIONS true - RATES - K-feldspar - start - 10 REM store the initial amount of K-feldspar - 20 IF EXISTS(1) = 0 THEN PUT(M, 1) - 30 REM calculate moles of reaction - 40 SR_kfld = SR("K-feldspar") - 50 moles = PARM(1) * (M/M0)^0.67 * (1 - SR_kfld) * TIME - 60 REM The following is for printout of phase transitions - 80 REM Start Gibbsite - 90 if ABS(SI("Gibbsite")) > 1e-3 THEN GOTO 150 - 100 i = 2 - 110 GOSUB 1500 - 150 REM Start Gibbsite -> Kaolinite - 160 if ABS(SI("Kaolinite")) > 1e-3 THEN GOTO 200 - 170 i = 3 - 180 GOSUB 1500 - 200 REM End Gibbsite -> Kaolinite - 210 if ABS(SI("Kaolinite")) > 1e-3 OR EQUI("Gibbsite") > 0 THEN GOTO 250 - 220 i = 4 - 230 GOSUB 1500 - 250 REM Start Kaolinite -> K-mica - 260 if ABS(SI("K-mica")) > 1e-3 THEN GOTO 300 - 270 i = 5 - 280 GOSUB 1500 - 300 REM End Kaolinite -> K-mica - 310 if ABS(SI("K-mica")) > 1e-3 OR EQUI("Kaolinite") > 0 THEN GOTO 350 - 320 i = 6 - 330 GOSUB 1500 - 350 REM Start K-mica -> K-feldspar - 360 if ABS(SI("K-feldspar")) > 1e-3 THEN GOTO 1000 - 370 i = 7 - 380 GOSUB 1500 - 1000 SAVE moles - 1010 END - 1500 REM subroutine to store data - 1510 if GET(i) >= M THEN RETURN - 1520 PUT(M, i) - 1530 PUT(TOTAL_TIME, i, 1) - 1540 PUT(LA("K+")-LA("H+"), i, 2) - 1550 PUT(LA("H4SiO4"), i, 3) - 1560 RETURN - end - USER_PRINT - 10 DATA "A: Gibbsite ", "B: Gibbsite -> Kaolinite ", "C: Gibbsite -> Kaolinite ", "D: Kaolinite -> K-mica ", "E: Kaolinite -> K-mica ", "F: K-mica -> K-feldspar" - 20 PRINT " Transition Time K-feldspar LA(K/H) LA(H4SiO4)" - 30 PRINT " reacted" - 40 PRINT " (moles)" - 50 FOR i = 2 TO 7 - 60 READ s$ - 70 IF EXISTS(i) THEN PRINT s$, GET(i,1), GET(1) - GET(i), GET(i,2), GET(i,3) - 80 NEXT i - SELECTED_OUTPUT - file ex6C.sel - reset false - USER_PUNCH - heading pH+log[K] log[H4SiO4] - 10 PUNCH LA("K+")-LA("H+") LA("H4SiO4") - END ------ -TITLE ------ - - Example 6C.--kinetic calculation - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.000e-13 1.000e-13 - K 1.000e-13 1.000e-13 - Si 3.000e-13 3.000e-13 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.086e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 3 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.001e-07 1.001e-07 -6.999 -7.000 -0.000 - H+ 1.000e-07 1.000e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.000e-13 - Al(OH)4- 9.178e-14 9.175e-14 -13.037 -13.037 -0.000 - Al(OH)3 4.868e-15 4.868e-15 -14.313 -14.313 0.000 - Al(OH)2+ 3.305e-15 3.304e-15 -14.481 -14.481 -0.000 - AlOH+2 4.222e-17 4.215e-17 -16.375 -16.375 -0.001 - Al+3 4.258e-19 4.244e-19 -18.371 -18.372 -0.001 -H(0) 1.416e-25 - H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 -K 1.000e-13 - K+ 1.000e-13 9.996e-14 -13.000 -13.000 -0.000 - KOH 3.466e-21 3.466e-21 -20.460 -20.460 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 -Si 3.000e-13 - H4SiO4 2.996e-13 2.996e-13 -12.524 -12.524 0.000 - H3SiO4- 4.419e-16 4.417e-16 -15.355 -15.355 -0.000 - H2SiO4-2 3.009e-22 3.005e-22 -21.522 -21.522 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -8.17 2.63 10.80 Al(OH)3 - Chalcedony -8.97 -12.52 -3.55 SiO2 - Gibbsite -5.42 2.63 8.05 Al(OH)3 - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -41.82 -40.94 0.88 KAlSi3O8 - K-mica -48.66 -35.69 12.97 KAl3Si3O10(OH)2 - Kaolinite -25.50 -19.79 5.71 Al2Si2O5(OH)4 - O2(g) -39.12 -42.08 -2.96 O2 - Quartz -8.54 -12.52 -3.98 SiO2 - SiO2(a) -9.81 -12.52 -2.71 SiO2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 100 seconds (Incremented time: 100 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.266e-09 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -1.32 6.73 8.05 0.000e+00 0.000e+00 - K-mica -19.94 -6.97 12.97 0.000e+00 0.000e+00 - Kaolinite -9.09 -3.38 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.266e-09 1.266e-09 - K 1.266e-09 1.266e-09 - Si 3.797e-09 3.797e-09 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 11.049 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.013e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.171e-09 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 35 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.002e-07 1.002e-07 -6.999 -6.999 -0.000 - H+ 9.997e-08 9.993e-08 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.266e-09 - Al(OH)4- 1.162e-09 1.161e-09 -8.935 -8.935 -0.000 - Al(OH)3 6.157e-11 6.157e-11 -10.211 -10.211 0.000 - Al(OH)2+ 4.178e-11 4.176e-11 -10.379 -10.379 -0.000 - AlOH+2 5.332e-13 5.324e-13 -12.273 -12.274 -0.001 - Al+3 5.375e-15 5.356e-15 -14.270 -14.271 -0.001 -H(0) 1.128e-39 - H2 5.642e-40 5.642e-40 -39.249 -39.249 0.000 -K 1.266e-09 - K+ 1.266e-09 1.265e-09 -8.898 -8.898 -0.000 - KOH 4.390e-17 4.390e-17 -16.358 -16.358 0.000 -O(0) 2.619e-14 - O2 1.309e-14 1.309e-14 -13.883 -13.883 0.000 -Si 3.797e-09 - H4SiO4 3.791e-09 3.791e-09 -8.421 -8.421 0.000 - H3SiO4- 5.596e-12 5.594e-12 -11.252 -11.252 -0.000 - H2SiO4-2 3.814e-18 3.808e-18 -17.419 -17.419 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.07 6.73 10.80 Al(OH)3 - Chalcedony -4.87 -8.42 -3.55 SiO2 - Gibbsite -1.32 6.73 8.05 Al(OH)3 - H2(g) -36.10 -39.25 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -21.31 -20.43 0.88 KAlSi3O8 - K-mica -19.94 -6.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -9.09 -3.38 5.71 Al2Si2O5(OH)4 - O2(g) -10.92 -13.88 -2.96 O2 - Quartz -4.44 -8.42 -3.98 SiO2 - SiO2(a) -5.71 -8.42 -2.71 SiO2 - -Reaction step 2. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 1000 seconds (Incremented time: 1100 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.266e-08 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.28 7.77 8.05 0.000e+00 0.000e+00 - K-mica -12.66 0.31 12.97 0.000e+00 0.000e+00 - Kaolinite -4.93 0.78 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 1.392e-08 1.392e-08 - K 1.392e-08 1.392e-08 - Si 4.176e-08 4.176e-08 - -----------------------------Description of solution---------------------------- - - pH = 7.003 Charge balance - pe = 11.058 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.137e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.579e-08 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 7 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.009e-07 1.009e-07 -6.996 -6.996 -0.000 - H+ 9.928e-08 9.924e-08 -7.003 -7.003 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 1.392e-08 - Al(OH)4- 1.279e-08 1.278e-08 -7.893 -7.893 -0.000 - Al(OH)3 6.731e-10 6.731e-10 -9.172 -9.172 0.000 - Al(OH)2+ 4.535e-10 4.533e-10 -9.343 -9.344 -0.000 - AlOH+2 5.749e-12 5.740e-12 -11.240 -11.241 -0.001 - Al+3 5.755e-14 5.734e-14 -13.240 -13.242 -0.002 -H(0) 1.070e-39 - H2 5.349e-40 5.349e-40 -39.272 -39.272 0.000 -K 1.392e-08 - K+ 1.392e-08 1.392e-08 -7.856 -7.856 -0.000 - KOH 4.862e-16 4.862e-16 -15.313 -15.313 0.000 -O(0) 2.914e-14 - O2 1.457e-14 1.457e-14 -13.837 -13.837 0.000 -Si 4.176e-08 - H4SiO4 4.170e-08 4.170e-08 -7.380 -7.380 0.000 - H3SiO4- 6.199e-11 6.196e-11 -10.208 -10.208 -0.000 - H2SiO4-2 4.254e-17 4.247e-17 -16.371 -16.372 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.03 7.77 10.80 Al(OH)3 - Chalcedony -3.83 -7.38 -3.55 SiO2 - Gibbsite -0.28 7.77 8.05 Al(OH)3 - H2(g) -36.12 -39.27 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -16.10 -15.22 0.88 KAlSi3O8 - K-mica -12.66 0.31 12.97 KAl3Si3O10(OH)2 - Kaolinite -4.93 0.78 5.71 Al2Si2O5(OH)4 - O2(g) -10.88 -13.84 -2.96 O2 - Quartz -3.40 -7.38 -3.98 SiO2 - SiO2(a) -4.67 -7.38 -2.71 SiO2 - -Reaction step 3. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 10000 seconds (Incremented time: 11100 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.266e-07 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) -A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 0.000e+00 9.936e-08 9.936e-08 - K-mica -7.59 5.38 12.97 0.000e+00 0.000e+00 - Kaolinite -2.36 3.35 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 4.111e-08 4.111e-08 - K 1.405e-07 1.405e-07 - Si 4.214e-07 4.214e-07 - -----------------------------Description of solution---------------------------- - - pH = 7.210 Charge balance - pe = 10.821 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 2.027e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.639e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 - Iterations = 8 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.625e-07 1.624e-07 -6.789 -6.789 -0.000 - H+ 6.167e-08 6.164e-08 -7.210 -7.210 -0.000 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 4.111e-08 - Al(OH)4- 3.929e-08 3.927e-08 -7.406 -7.406 -0.000 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 5.374e-10 5.372e-10 -9.270 -9.270 -0.000 - AlOH+2 4.233e-12 4.224e-12 -11.373 -11.374 -0.001 - Al+3 2.634e-14 2.621e-14 -13.579 -13.582 -0.002 -H(0) 1.226e-39 - H2 6.128e-40 6.128e-40 -39.213 -39.213 0.000 -K 1.405e-07 - K+ 1.405e-07 1.404e-07 -6.852 -6.853 -0.000 - KOH 7.899e-15 7.899e-15 -14.102 -14.102 0.000 -O(0) 2.220e-14 - O2 1.110e-14 1.110e-14 -13.955 -13.955 0.000 -Si 4.214e-07 - H4SiO4 4.204e-07 4.204e-07 -6.376 -6.376 0.000 - H3SiO4- 1.006e-09 1.006e-09 -8.997 -8.997 -0.000 - H2SiO4-2 1.112e-15 1.110e-15 -14.954 -14.955 -0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -2.82 -6.38 -3.55 SiO2 - Gibbsite -0.00 8.05 8.05 Al(OH)3 - H2(g) -36.06 -39.21 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -11.60 -10.72 0.88 KAlSi3O8 - K-mica -7.59 5.38 12.97 KAl3Si3O10(OH)2 - Kaolinite -2.36 3.35 5.71 Al2Si2O5(OH)4 - O2(g) -10.99 -13.95 -2.96 O2 - Quartz -2.40 -6.38 -3.98 SiO2 - SiO2(a) -3.66 -6.38 -2.71 SiO2 - -Reaction step 4. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 100000 seconds (Incremented time: 111100 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.266e-06 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) -A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite 0.00 8.05 8.05 9.936e-08 1.142e-06 1.043e-06 - K-mica -2.79 10.18 12.97 0.000e+00 0.000e+00 - Kaolinite -0.37 5.33 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 2.640e-07 2.640e-07 - K 1.406e-06 1.406e-06 - Si 4.218e-06 4.218e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.035 Charge balance - pe = 10.027 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.415e-06 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.198e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 65 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.086e-06 1.085e-06 -5.964 -5.965 -0.001 - H+ 9.240e-09 9.228e-09 -8.034 -8.035 -0.001 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 2.640e-07 - Al(OH)4- 2.626e-07 2.623e-07 -6.581 -6.581 -0.001 - Al(OH)3 1.284e-09 1.284e-09 -8.891 -8.891 0.000 - Al(OH)2+ 8.053e-11 8.042e-11 -10.094 -10.095 -0.001 - AlOH+2 9.521e-14 9.468e-14 -13.021 -13.024 -0.002 - Al+3 8.906e-17 8.796e-17 -16.050 -16.056 -0.005 -H(0) 1.066e-39 - H2 5.332e-40 5.332e-40 -39.273 -39.273 0.000 -K 1.406e-06 - K+ 1.406e-06 1.404e-06 -5.852 -5.853 -0.001 - KOH 5.276e-13 5.276e-13 -12.278 -12.278 0.000 -O(0) 2.932e-14 - O2 1.466e-14 1.466e-14 -13.834 -13.834 0.000 -Si 4.218e-06 - H4SiO4 4.152e-06 4.152e-06 -5.382 -5.382 0.000 - H3SiO4- 6.643e-08 6.634e-08 -7.178 -7.178 -0.001 - H2SiO4-2 4.918e-13 4.890e-13 -12.308 -12.311 -0.002 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -2.75 8.05 10.80 Al(OH)3 - Chalcedony -1.83 -5.38 -3.55 SiO2 - Gibbsite 0.00 8.05 8.05 Al(OH)3 - H2(g) -36.12 -39.27 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -6.79 -5.91 0.88 KAlSi3O8 - K-mica -2.79 10.18 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.37 5.33 5.71 Al2Si2O5(OH)4 - O2(g) -10.87 -13.83 -2.96 O2 - Quartz -1.40 -5.38 -3.98 SiO2 - SiO2(a) -2.67 -5.38 -2.71 SiO2 - -Reaction step 5. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 1e+06 seconds (Incremented time: 1.1111e+06 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.265e-05 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) -A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 -B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 -C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -0.59 7.45 8.05 1.142e-06 -1.142e-06 - K-mica -0.27 12.70 12.97 0.000e+00 0.000e+00 - Kaolinite 0.00 5.71 5.71 0.000e+00 6.727e-06 6.727e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 6.045e-07 6.045e-07 - K 1.406e-05 1.406e-05 - Si 2.872e-05 2.872e-05 - -----------------------------Description of solution---------------------------- - - pH = 8.990 Charge balance - pe = 9.170 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.406e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.587e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 467 - Total H = 1.110124e+02 - Total O = 5.550627e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 9.825e-06 9.782e-06 -5.008 -5.010 -0.002 - H+ 1.028e-09 1.023e-09 -8.988 -8.990 -0.002 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 6.045e-07 - Al(OH)4- 6.042e-07 6.015e-07 -6.219 -6.221 -0.002 - Al(OH)3 3.266e-10 3.266e-10 -9.486 -9.486 0.000 - Al(OH)2+ 2.279e-12 2.269e-12 -11.642 -11.644 -0.002 - AlOH+2 3.015e-16 2.963e-16 -15.521 -15.528 -0.008 - Al+3 3.174e-20 3.052e-20 -19.498 -19.515 -0.017 -H(0) 6.790e-40 - H2 3.395e-40 3.395e-40 -39.469 -39.469 0.000 -K 1.406e-05 - K+ 1.406e-05 1.400e-05 -4.852 -4.854 -0.002 - KOH 4.742e-11 4.742e-11 -10.324 -10.324 0.000 -O(0) 7.232e-14 - O2 3.616e-14 3.616e-14 -13.442 -13.442 0.000 -Si 2.872e-05 - H4SiO4 2.509e-05 2.509e-05 -4.600 -4.600 0.000 - H3SiO4- 3.631e-06 3.615e-06 -5.440 -5.442 -0.002 - H2SiO4-2 2.445e-10 2.403e-10 -9.612 -9.619 -0.008 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -3.35 7.45 10.80 Al(OH)3 - Chalcedony -1.05 -4.60 -3.55 SiO2 - Gibbsite -0.59 7.45 8.05 Al(OH)3 - H2(g) -36.32 -39.47 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -3.09 -2.21 0.88 KAlSi3O8 - K-mica -0.27 12.70 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.00 5.71 5.71 Al2Si2O5(OH)4 - O2(g) -10.48 -13.44 -2.96 O2 - Quartz -0.62 -4.60 -3.98 SiO2 - SiO2(a) -1.89 -4.60 -2.71 SiO2 - -Reaction step 6. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 1e+07 seconds (Incremented time: 1.11111e+07 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -1.126e-04 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) -A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 -B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 -C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 -D: Kaolinite -> K-mica 1.5869e+06 2.0070e-05 4.4080e+00 -4.4659e+00 -E: Kaolinite -> K-mica 2.5972e+06 3.2791e-05 4.4103e+00 -4.2509e+00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -1.76 6.29 8.05 0.000e+00 0.000e+00 - K-mica -0.00 12.97 12.97 0.000e+00 4.218e-05 4.218e-05 - Kaolinite -0.57 5.14 5.71 6.727e-06 -6.727e-06 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 9.274e-08 9.274e-08 - K 8.444e-05 8.444e-05 - Si 2.533e-04 2.533e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.339 Charge balance - pe = -4.518 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.445e-05 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.472e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.113e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 3145 - Total H = 1.110123e+02 - Total O = 5.550672e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.211e-05 2.187e-05 -4.655 -4.660 -0.005 - H+ 4.625e-10 4.577e-10 -9.335 -9.339 -0.005 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 9.274e-08 - Al(OH)4- 9.272e-08 9.174e-08 -7.033 -7.037 -0.005 - Al(OH)3 2.228e-11 2.228e-11 -10.652 -10.652 0.000 - Al(OH)2+ 6.994e-14 6.920e-14 -13.155 -13.160 -0.005 - AlOH+2 4.217e-18 4.041e-18 -17.375 -17.393 -0.018 - Al+3 2.046e-22 1.862e-22 -21.689 -21.730 -0.041 -H(0) 3.219e-13 - H2 1.610e-13 1.610e-13 -12.793 -12.793 0.000 -K 8.444e-05 - K+ 8.444e-05 8.355e-05 -4.073 -4.078 -0.005 - KOH 6.329e-10 6.329e-10 -9.199 -9.199 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -66.794 -66.794 0.000 -Si 2.533e-04 - H4SiO4 1.911e-04 1.911e-04 -3.719 -3.719 0.000 - H3SiO4- 6.222e-05 6.157e-05 -4.206 -4.211 -0.005 - H2SiO4-2 9.548e-09 9.150e-09 -8.020 -8.039 -0.018 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.51 6.29 10.80 Al(OH)3 - Chalcedony -0.17 -3.72 -3.55 SiO2 - Gibbsite -1.76 6.29 8.05 Al(OH)3 - H2(g) -9.64 -12.79 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -0.48 0.39 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.57 5.14 5.71 Al2Si2O5(OH)4 - O2(g) -63.83 -66.79 -2.96 O2 - Quartz 0.26 -3.72 -3.98 SiO2 - SiO2(a) -1.01 -3.72 -2.71 SiO2 - -Reaction step 7. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 9. - -Kinetics 1. Kinetics defined in simulation 9. - - Time step: 1e+08 seconds (Incremented time: 1.11111e+08 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - K-feldspar -6.426e-05 1.940e+00 K-feldspar 1 - -----------------------------------User print----------------------------------- - - Transition Time K-feldspar LA(K/H) LA(H4SiO4) - reacted - (moles) -A: Gibbsite 1100 1.4048e-07 3.5755e-01 -6.3763e+00 -B: Gibbsite -> Kaolinite 1.7434e+05 2.2064e-06 2.5609e+00 -5.1950e+00 -C: Gibbsite -> Kaolinite 2.3929e+05 3.0284e-06 2.8352e+00 -5.1943e+00 -D: Kaolinite -> K-mica 1.5869e+06 2.0070e-05 4.4080e+00 -4.4659e+00 -E: Kaolinite -> K-mica 2.5972e+06 3.2791e-05 4.4103e+00 -4.2509e+00 -F: K-mica -> K-feldspar 4.7840e+07 1.9072e-04 5.4879e+00 -3.5540e+00 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Gibbsite -2.00 6.05 8.05 0.000e+00 0.000e+00 - K-mica 0.00 12.97 12.97 4.218e-05 6.361e-05 2.143e-05 - Kaolinite -0.72 4.99 5.71 0.000e+00 0.000e+00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Al 5.990e-08 5.989e-08 - K 1.273e-04 1.273e-04 - Si 3.818e-04 3.818e-04 - -----------------------------Description of solution---------------------------- - - pH = 9.389 Charge balance - pe = -4.454 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.273e-04 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.275e-04 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.114e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 1788 - Total H = 1.110123e+02 - Total O = 5.550698e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.486e-05 2.453e-05 -4.605 -4.610 -0.006 - H+ 4.133e-10 4.080e-10 -9.384 -9.389 -0.006 - H2O 5.551e+01 1.000e+00 1.744 -0.000 0.000 -Al 5.990e-08 - Al(OH)4- 5.988e-08 5.911e-08 -7.223 -7.228 -0.006 - Al(OH)3 1.280e-11 1.280e-11 -10.893 -10.893 0.000 - Al(OH)2+ 3.590e-14 3.544e-14 -13.445 -13.451 -0.006 - AlOH+2 1.944e-18 1.845e-18 -17.711 -17.734 -0.023 - Al+3 8.505e-23 7.579e-23 -22.070 -22.120 -0.050 -H(0) 1.911e-13 - H2 9.553e-14 9.553e-14 -13.020 -13.020 0.000 -K 1.273e-04 - K+ 1.273e-04 1.256e-04 -3.895 -3.901 -0.006 - KOH 1.067e-09 1.067e-09 -8.972 -8.972 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -66.340 -66.340 0.000 -Si 3.818e-04 - H4SiO4 2.795e-04 2.795e-04 -3.554 -3.554 0.000 - H3SiO4- 1.023e-04 1.010e-04 -3.990 -3.996 -0.006 - H2SiO4-2 1.774e-08 1.684e-08 -7.751 -7.774 -0.023 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Al(OH)3(a) -4.75 6.05 10.80 Al(OH)3 - Chalcedony -0.00 -3.55 -3.55 SiO2 - Gibbsite -2.00 6.05 8.05 Al(OH)3 - H2(g) -9.87 -13.02 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - K-feldspar -0.00 0.87 0.88 KAlSi3O8 - K-mica -0.00 12.97 12.97 KAl3Si3O10(OH)2 - Kaolinite -0.72 4.99 5.71 Al2Si2O5(OH)4 - O2(g) -63.38 -66.34 -2.96 O2 - Quartz 0.43 -3.55 -3.98 SiO2 - SiO2(a) -0.84 -3.55 -2.71 SiO2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 10. -------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex6A-B.sel b/Sun/examples/ex6A-B.sel deleted file mode 100644 index a623a401..00000000 --- a/Sun/examples/ex6A-B.sel +++ /dev/null @@ -1,22 +0,0 @@ - sim state soln dist_x time step pH pe la_K+ la_H+ la_H4SiO4 Gibbsite d_Gibbsite Kaolinite d_Kaolinite K-mica d_K-mica K-feldspar d_K-feldspar si_Gibbsite si_Kaolinite si_K-mica si_K-feldspar - 1 i_soln 1 -99 -99 -99 6.99977 4 -1.0000e+03 -6.9998e+00 -1.0000e+03 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -999.9990 -999.9990 -999.9990 -999.9990 - 2 react 1 -99 0 1 7.00609 11.4683 -7.5735e+00 -7.0061e+00 -7.0969e+00 1.0000e+01 -2.6709e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -3.8037 -10.6810 -14.6840 - 3 react 1 -99 0 1 8.2125 9.89391 -5.6625e+00 -8.2125e+00 -5.1950e+00 1.7820e-06 1.7820e-06 1.0000e+01 -2.1788e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -0.0000 -1.8580 -5.8610 - 4 react 1 -99 0 1 9.10891 9.06313 -4.7009e+00 -9.1089e+00 -4.4670e+00 0.0000e+00 0.0000e+00 9.7149e-06 9.7149e-06 1.0000e+01 -2.0015e-05 0.0000e+00 0.0000e+00 -0.7280 0.0000 -0.0000 -2.5471 - 5 react 1 -99 0 1 9.3893 8.71926 -3.9009e+00 -9.3893e+00 -3.5536e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.3607e-05 6.3607e-05 9.9998e+00 -1.9088e-04 -2.0015 -0.7202 -0.0000 -0.0000 - 6 react 1 -99 0 1 8.35402 9.7856 -5.5204e+00 -8.3540e+00 -5.1950e+00 1.0000e+01 -3.0232e-06 1.0000e+00 1.2370e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.0000 -1.5744 -5.5774 - 7 react 1 -99 0 1 9.06998 8.8364 -4.6620e+00 -9.0700e+00 -4.2522e+00 0.0000e+00 0.0000e+00 1.0000e+01 -3.2683e-05 1.0000e+00 1.0785e-05 0.0000e+00 0.0000e+00 -0.9428 0.0000 0.0000 -2.1175 - 8 react 1 -99 0 1 7.03143 11.4569 -7.3981e+00 -7.0314e+00 -6.9215e+00 1.1865e-08 1.1865e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -3.4530 -9.9542 -13.9572 - 8 react 1 -99 0 2 7.10578 11.2881 -7.0971e+00 -7.1058e+00 -6.6206e+00 4.7135e-08 4.7135e-08 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -2.8512 -8.6762 -12.6792 - 8 react 1 -99 0 3 7.24112 11.2405 -6.7961e+00 -7.2411e+00 -6.3199e+00 1.1602e-07 1.1602e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -2.2497 -7.3376 -11.3406 - 8 react 1 -99 0 4 7.45138 11.1879 -6.4952e+00 -7.4514e+00 -6.0195e+00 2.4993e-07 2.4993e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.0000 -1.6491 -5.9254 -9.9284 - 8 react 1 -99 0 5 7.71458 10.9939 -6.1942e+00 -7.7146e+00 -5.7200e+00 5.1299e-07 5.1299e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -1.0500 -4.4627 -8.4657 - 8 react 1 -99 0 6 7.89551 10.7897 -6.0005e+00 -7.8955e+00 -5.5279e+00 8.0811e-07 8.0811e-07 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.6658 -3.5117 -7.5147 - 8 react 1 -99 0 7 8.17803 10.4976 -5.6997e+00 -8.1780e+00 -5.2314e+00 1.6334e-06 1.6334e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000 -0.0728 -2.0389 -6.0419 - 8 react 1 -99 0 8 8.48402 9.39003 -5.3990e+00 -8.4840e+00 -5.0858e+00 0.0000e+00 0.0000e+00 1.7119e-06 1.7119e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.1092 -0.0000 -1.3229 -5.1076 - 8 react 1 -99 0 9 8.77878 9.50556 -5.0983e+00 -8.7788e+00 -4.8166e+00 0.0000e+00 0.0000e+00 3.6945e-06 3.6945e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.3784 -0.0000 -0.7276 -3.9737 - 8 react 1 -99 0 10 9.0347 8.80148 -4.7979e+00 -9.0347e+00 -4.5514e+00 0.0000e+00 0.0000e+00 7.7006e-06 7.7006e-06 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 -0.6436 0.0000 -0.1712 -2.8871 - 8 react 1 -99 0 11 9.07198 8.97748 -4.6640e+00 -9.0720e+00 -4.2616e+00 0.0000e+00 0.0000e+00 5.2701e-07 5.2701e-07 1.0204e-05 1.0204e-05 0.0000e+00 0.0000e+00 -0.9334 0.0000 -0.0000 -2.1362 - 8 react 1 -99 0 12 9.2252 8.68998 -4.3726e+00 -9.2252e+00 -3.9889e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 2.1273e-05 2.1273e-05 0.0000e+00 0.0000e+00 -1.3543 -0.2964 0.0000 -1.2945 - 8 react 1 -99 0 13 9.30457 8.57016 -4.1800e+00 -9.3046e+00 -3.8127e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3.3294e-05 3.3294e-05 0.0000e+00 0.0000e+00 -1.6212 -0.4777 0.0000 -0.7607 - 8 react 1 -99 0 14 9.3893 8.9467 -3.9009e+00 -9.3893e+00 -3.5536e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 6.3607e-05 6.3607e-05 9.1200e-06 9.1200e-06 -2.0015 -0.7202 -0.0000 0.0000 diff --git a/Sun/examples/ex6C.sel b/Sun/examples/ex6C.sel deleted file mode 100644 index efc12a6c..00000000 --- a/Sun/examples/ex6C.sel +++ /dev/null @@ -1,9 +0,0 @@ - pH+log[K] log[H4SiO4] - -6.0002e+00 -1.2524e+01 - -1.8975e+00 -8.4212e+00 - -8.5316e-01 -7.3798e+00 - 3.5755e-01 -6.3763e+00 - 2.1823e+00 -5.3818e+00 - 4.1360e+00 -4.6005e+00 - 5.2614e+00 -3.7187e+00 - 5.4884e+00 -3.5536e+00 diff --git a/Sun/examples/ex7.log b/Sun/examples/ex7.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex7.out b/Sun/examples/ex7.out deleted file mode 100644 index 8e79de41..00000000 --- a/Sun/examples/ex7.out +++ /dev/null @@ -1,2819 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex7 - Output file: ex7.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 7.--Organic decomposition with fixed-pressure and - fixed-volume gas phases - SOLUTION 1 - EQUILIBRIUM_PHASES 1 - Calcite - CO2(g) -1.5 - SAVE solution 1 - SELECTED_OUTPUT - reset false - file ex7.sel - simulation true - state true - reaction true - si CO2(g) CH4(g) N2(g) NH3(g) - gases CO2(g) CH4(g) N2(g) NH3(g) - END ------ -TITLE ------ - - Example 7.--Organic decomposition with fixed-pressure and - fixed-volume gas phases - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Pure water - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 4.000 - Activity of water = 1.000 - Ionic strength = 1.001e-07 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.082e-10 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.082e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 0 - Total H = 1.110124e+02 - Total O = 5.550622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.002e-07 1.001e-07 -6.999 -6.999 -0.000 - H+ 1.001e-07 1.000e-07 -7.000 -7.000 -0.000 - H2O 5.551e+01 1.000e+00 1.744 0.000 0.000 -H(0) 1.416e-25 - H2 7.079e-26 7.079e-26 -25.150 -25.150 0.000 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -42.080 -42.080 0.000 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -22.00 -25.15 -3.15 H2 - H2O(g) -1.51 0.00 1.51 H2O - O2(g) -39.12 -42.08 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Calcite 0.00 -8.48 -8.48 1.000e+01 9.997e+00 -2.502e-03 - CO2(g) -1.50 -19.65 -18.15 1.000e+01 9.996e+00 -3.568e-03 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 6.071e-03 6.071e-03 - Ca 2.502e-03 2.502e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.971 Charge balance - pe = -0.653 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.282e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.004e-03 - Total CO2 (mol/kg) = 6.071e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 16 - Total H = 1.110124e+02 - Total O = 5.552086e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.159e-07 1.070e-07 -6.936 -6.971 -0.035 - OH- 1.025e-07 9.358e-08 -6.989 -7.029 -0.040 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 7.589e-30 - CH4 7.589e-30 7.602e-30 -29.120 -29.119 0.001 -C(4) 6.071e-03 - HCO3- 4.883e-03 4.476e-03 -2.311 -2.349 -0.038 - CO2 1.075e-03 1.077e-03 -2.969 -2.968 0.001 - CaHCO3+ 1.052e-04 9.640e-05 -3.978 -4.016 -0.038 - CaCO3 5.556e-06 5.565e-06 -5.255 -5.255 0.001 - CO3-2 2.778e-06 1.962e-06 -5.556 -5.707 -0.151 -Ca 2.502e-03 - Ca+2 2.391e-03 1.688e-03 -2.621 -2.773 -0.151 - CaHCO3+ 1.052e-04 9.640e-05 -3.978 -4.016 -0.038 - CaCO3 5.556e-06 5.565e-06 -5.255 -5.255 0.001 - CaOH+ 2.864e-09 2.619e-09 -8.543 -8.582 -0.039 -H(0) 3.273e-16 - H2 1.636e-16 1.639e-16 -15.786 -15.785 0.001 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -60.810 -60.809 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite 0.00 -8.48 -8.48 CaCO3 - CH4(g) -26.26 -29.12 -2.86 CH4 - CO2(g) -1.50 -2.97 -1.47 CO2 - H2(g) -12.64 -15.79 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -57.85 -60.81 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - USE solution 1 - GAS_PHASE 1 Fixed-pressure gas phase - fixed_pressure - pressure 1.1 - CO2(g) 0.0 - CH4(g) 0.0 - N2(g) 0.0 - NH3(g) 0.0 - REACTION 1 - CH2O(NH3)0.07 1.0 - 1. 2. 3. 4. 8. 16. 32 64. 125. 250. 500. 1000. mmol - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 1.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 7.071e-03 7.071e-03 - Ca 2.502e-03 2.502e-03 - N 7.000e-05 7.000e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.831 Charge balance - pe = -3.723 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.353e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.074e-03 - Total CO2 (mol/kg) = 6.571e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.110146e+02 - Total O = 5.552186e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.597e-07 1.474e-07 -6.797 -6.831 -0.035 - OH- 7.440e-08 6.789e-08 -7.128 -7.168 -0.040 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 5.001e-04 - CH4 5.001e-04 5.009e-04 -3.301 -3.300 0.001 -C(4) 6.571e-03 - HCO3- 4.955e-03 4.541e-03 -2.305 -2.343 -0.038 - CO2 1.503e-03 1.505e-03 -2.823 -2.822 0.001 - CaHCO3+ 1.066e-04 9.766e-05 -3.972 -4.010 -0.038 - CaCO3 4.083e-06 4.090e-06 -5.389 -5.388 0.001 - CO3-2 2.048e-06 1.445e-06 -5.689 -5.840 -0.152 -Ca 2.502e-03 - Ca+2 2.392e-03 1.686e-03 -2.621 -2.773 -0.152 - CaHCO3+ 1.066e-04 9.766e-05 -3.972 -4.010 -0.038 - CaCO3 4.083e-06 4.090e-06 -5.389 -5.388 0.001 - CaOH+ 2.076e-09 1.897e-09 -8.683 -8.722 -0.039 -H(0) 8.575e-10 - H2 4.287e-10 4.295e-10 -9.368 -9.367 0.001 -N(-3) 6.986e-05 - NH4+ 6.962e-05 6.338e-05 -4.157 -4.198 -0.041 - NH3 2.446e-07 2.450e-07 -6.612 -6.611 0.001 -N(0) 1.394e-07 - N2 6.970e-08 6.981e-08 -7.157 -7.156 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.351 -62.391 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.704 -84.744 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.647 -73.646 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.28 -8.61 -8.34 CaCO3 - Calcite -0.13 -8.61 -8.48 CaCO3 - CH4(g) -0.44 -3.30 -2.86 CH4 - CO2(g) -1.35 -2.82 -1.47 CO2 - H2(g) -6.22 -9.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.90 -7.16 -3.26 N2 - NH3(g) -8.38 -6.61 1.77 NH3 - O2(g) -70.69 -73.65 -2.96 O2 - -Reaction step 2. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 2.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 8.071e-03 8.071e-03 - Ca 2.502e-03 2.502e-03 - N 1.400e-04 1.400e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.728 Charge balance - pe = -3.644 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.422e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.144e-03 - Total CO2 (mol/kg) = 7.071e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 20 - Total H = 1.110169e+02 - Total O = 5.552286e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.026e-07 1.869e-07 -6.693 -6.728 -0.035 - OH- 5.871e-08 5.355e-08 -7.231 -7.271 -0.040 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 1.000e-03 - CH4 1.000e-03 1.002e-03 -3.000 -2.999 0.001 -C(4) 7.071e-03 - HCO3- 5.026e-03 4.604e-03 -2.299 -2.337 -0.038 - CO2 1.932e-03 1.935e-03 -2.714 -2.713 0.001 - CaHCO3+ 1.079e-04 9.886e-05 -3.967 -4.005 -0.038 - CaCO3 3.261e-06 3.266e-06 -5.487 -5.486 0.001 - CO3-2 1.640e-06 1.155e-06 -5.785 -5.937 -0.152 -Ca 2.502e-03 - Ca+2 2.391e-03 1.683e-03 -2.621 -2.774 -0.153 - CaHCO3+ 1.079e-04 9.886e-05 -3.967 -4.005 -0.038 - CaCO3 3.261e-06 3.266e-06 -5.487 -5.486 0.001 - CaOH+ 1.635e-09 1.494e-09 -8.786 -8.826 -0.039 -H(0) 9.576e-10 - H2 4.788e-10 4.796e-10 -9.320 -9.319 0.001 -N(-3) 1.398e-04 - NH4+ 1.394e-04 1.268e-04 -3.856 -3.897 -0.041 - NH3 3.860e-07 3.867e-07 -6.413 -6.413 0.001 -N(0) 2.493e-07 - N2 1.247e-07 1.249e-07 -6.904 -6.904 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.399 -62.440 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.800 -84.841 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.743 -73.742 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.38 -8.71 -8.34 CaCO3 - Calcite -0.23 -8.71 -8.48 CaCO3 - CH4(g) -0.14 -3.00 -2.86 CH4 - CO2(g) -1.25 -2.71 -1.47 CO2 - H2(g) -6.17 -9.32 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.64 -6.90 -3.26 N2 - NH3(g) -8.18 -6.41 1.77 NH3 - O2(g) -70.78 -73.74 -2.96 O2 - -Reaction step 3. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 3.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 1.91e-03 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) 0.01 1.030e+00 0.000e+00 8.036e-05 8.036e-05 -CO2(g) -1.16 6.932e-02 0.000e+00 5.406e-06 5.406e-06 -N2(g) -3.50 3.151e-04 0.000e+00 2.458e-08 2.458e-08 -NH3(g) -8.09 8.187e-09 0.000e+00 6.386e-13 6.386e-13 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 8.985e-03 8.985e-03 - Ca 2.502e-03 2.502e-03 - N 2.100e-04 2.100e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.648 Charge balance - pe = -3.572 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.491e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.214e-03 - Total CO2 (mol/kg) = 7.565e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 23 - Total H = 1.110187e+02 - Total O = 5.552385e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.438e-07 2.249e-07 -6.613 -6.648 -0.035 - OH- 4.882e-08 4.451e-08 -7.311 -7.352 -0.040 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 1.420e-03 - CH4 1.420e-03 1.422e-03 -2.848 -2.847 0.001 -C(4) 7.565e-03 - HCO3- 5.096e-03 4.667e-03 -2.293 -2.331 -0.038 - CO2 2.356e-03 2.360e-03 -2.628 -2.627 0.001 - CaHCO3+ 1.092e-04 1.000e-04 -3.962 -4.000 -0.038 - CaCO3 2.742e-06 2.747e-06 -5.562 -5.561 0.001 - CO3-2 1.384e-06 9.733e-07 -5.859 -6.012 -0.153 -Ca 2.502e-03 - Ca+2 2.390e-03 1.680e-03 -2.622 -2.775 -0.153 - CaHCO3+ 1.092e-04 1.000e-04 -3.962 -4.000 -0.038 - CaCO3 2.742e-06 2.747e-06 -5.562 -5.561 0.001 - CaOH+ 1.357e-09 1.240e-09 -8.867 -8.907 -0.039 -H(0) 9.947e-10 - H2 4.974e-10 4.982e-10 -9.303 -9.303 0.001 -N(-3) 2.096e-04 - NH4+ 2.091e-04 1.902e-04 -3.680 -3.721 -0.041 - NH3 4.813e-07 4.821e-07 -6.318 -6.317 0.001 -N(0) 3.457e-07 - N2 1.729e-07 1.732e-07 -6.762 -6.762 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.433 -62.474 -0.041 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.851 -84.891 -0.041 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.776 -73.775 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.45 -8.79 -8.34 CaCO3 - Calcite -0.31 -8.79 -8.48 CaCO3 - CH4(g) 0.01 -2.85 -2.86 CH4 - CO2(g) -1.16 -2.63 -1.47 CO2 - H2(g) -6.15 -9.30 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.50 -6.76 -3.26 N2 - NH3(g) -8.09 -6.32 1.77 NH3 - O2(g) -70.81 -73.77 -2.96 O2 - -Reaction step 4. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 4.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 1.43e-02 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) 0.01 1.019e+00 0.000e+00 5.966e-04 5.966e-04 -CO2(g) -1.09 8.074e-02 0.000e+00 4.728e-05 4.728e-05 -N2(g) -3.32 4.773e-04 0.000e+00 2.795e-07 2.795e-07 -NH3(g) -8.02 9.476e-09 0.000e+00 5.549e-12 5.549e-12 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 9.427e-03 9.427e-03 - Ca 2.502e-03 2.502e-03 - N 2.795e-04 2.794e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.588 Charge balance - pe = -3.502 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.558e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 5.283e-03 - Total CO2 (mol/kg) = 8.023e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 23 - Total H = 1.110189e+02 - Total O = 5.552477e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.803e-07 2.585e-07 -6.552 -6.588 -0.035 - OH- 4.248e-08 3.872e-08 -7.372 -7.412 -0.040 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 1.404e-03 - CH4 1.404e-03 1.406e-03 -2.853 -2.852 0.001 -C(4) 8.023e-03 - HCO3- 5.165e-03 4.728e-03 -2.287 -2.325 -0.038 - CO2 2.744e-03 2.749e-03 -2.562 -2.561 0.001 - CaHCO3+ 1.105e-04 1.012e-04 -3.957 -3.995 -0.038 - CaCO3 2.412e-06 2.417e-06 -5.618 -5.617 0.001 - CO3-2 1.221e-06 8.579e-07 -5.913 -6.067 -0.153 -Ca 2.502e-03 - Ca+2 2.389e-03 1.677e-03 -2.622 -2.775 -0.154 - CaHCO3+ 1.105e-04 1.012e-04 -3.957 -3.995 -0.038 - CaCO3 2.412e-06 2.417e-06 -5.618 -5.617 0.001 - CaOH+ 1.179e-09 1.076e-09 -8.928 -8.968 -0.040 -H(0) 9.548e-10 - H2 4.774e-10 4.782e-10 -9.321 -9.320 0.001 -N(-3) 2.789e-04 - NH4+ 2.784e-04 2.531e-04 -3.555 -3.597 -0.041 - NH3 5.570e-07 5.580e-07 -6.254 -6.253 0.001 -N(0) 5.237e-07 - N2 2.619e-07 2.623e-07 -6.582 -6.581 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.377 -62.418 -0.041 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.777 -84.817 -0.041 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.740 -73.739 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.51 -8.84 -8.34 CaCO3 - Calcite -0.36 -8.84 -8.48 CaCO3 - CH4(g) 0.01 -2.85 -2.86 CH4 - CO2(g) -1.09 -2.56 -1.47 CO2 - H2(g) -6.17 -9.32 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.32 -6.58 -3.26 N2 - NH3(g) -8.02 -6.25 1.77 NH3 - O2(g) -70.78 -73.74 -2.96 O2 - -Reaction step 5. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 8.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 6.67e-02 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.01 9.758e-01 0.000e+00 2.659e-03 2.659e-03 -CO2(g) -0.91 1.230e-01 0.000e+00 3.351e-04 3.351e-04 -N2(g) -2.90 1.257e-03 0.000e+00 3.425e-06 3.425e-06 -NH3(g) -7.89 1.292e-08 0.000e+00 3.520e-11 3.520e-11 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.108e-02 1.108e-02 - Ca 2.502e-03 2.502e-03 - N 5.532e-04 5.532e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.426 Charge balance - pe = -3.316 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.823e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 5.556e-03 - Total CO2 (mol/kg) = 9.733e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.074e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.110195e+02 - Total O = 5.552819e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 4.068e-07 3.747e-07 -6.391 -6.426 -0.036 - OH- 2.935e-08 2.671e-08 -7.532 -7.573 -0.041 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 1.344e-03 - CH4 1.344e-03 1.347e-03 -2.871 -2.871 0.001 -C(4) 9.733e-03 - HCO3- 5.435e-03 4.969e-03 -2.265 -2.304 -0.039 - CO2 4.180e-03 4.187e-03 -2.379 -2.378 0.001 - CaHCO3+ 1.155e-04 1.056e-04 -3.938 -3.977 -0.039 - CaCO3 1.736e-06 1.740e-06 -5.760 -5.760 0.001 - CO3-2 8.902e-07 6.219e-07 -6.051 -6.206 -0.156 -Ca 2.502e-03 - Ca+2 2.385e-03 1.665e-03 -2.623 -2.779 -0.156 - CaHCO3+ 1.155e-04 1.056e-04 -3.938 -3.977 -0.039 - CaCO3 1.736e-06 1.740e-06 -5.760 -5.760 0.001 - CaOH+ 8.088e-10 7.373e-10 -9.092 -9.132 -0.040 -H(0) 8.501e-10 - H2 4.251e-10 4.258e-10 -9.372 -9.371 0.001 -N(-3) 5.518e-04 - NH4+ 5.510e-04 5.003e-04 -3.259 -3.301 -0.042 - NH3 7.594e-07 7.608e-07 -6.120 -6.119 0.001 -N(0) 1.379e-06 - N2 6.895e-07 6.907e-07 -6.161 -6.161 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.252 -62.293 -0.041 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.601 -84.642 -0.041 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.639 -73.639 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.65 -8.98 -8.34 CaCO3 - Calcite -0.51 -8.98 -8.48 CaCO3 - CH4(g) -0.01 -2.87 -2.86 CH4 - CO2(g) -0.91 -2.38 -1.47 CO2 - H2(g) -6.22 -9.37 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.90 -6.16 -3.26 N2 - NH3(g) -7.89 -6.12 1.77 NH3 - O2(g) -70.68 -73.64 -2.96 O2 - -Reaction step 6. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 1.600e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 1.83e-01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.04 9.042e-01 0.000e+00 6.775e-03 6.775e-03 -CO2(g) -0.72 1.925e-01 0.000e+00 1.442e-03 1.442e-03 -N2(g) -2.47 3.359e-03 0.000e+00 2.517e-05 2.517e-05 -NH3(g) -7.76 1.735e-08 0.000e+00 1.300e-10 1.300e-10 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.385e-02 1.385e-02 - Ca 2.502e-03 2.502e-03 - N 1.070e-03 1.070e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.269 Charge balance - pe = -3.131 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.320e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.070e-03 - Total CO2 (mol/kg) = 1.261e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 20 - Total H = 1.110207e+02 - Total O = 5.553398e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 5.850e-07 5.377e-07 -6.233 -6.269 -0.037 - OH- 2.050e-08 1.861e-08 -7.688 -7.730 -0.042 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -C(-4) 1.246e-03 - CH4 1.246e-03 1.248e-03 -2.905 -2.904 0.001 -C(4) 1.261e-02 - CO2 6.541e-03 6.553e-03 -2.184 -2.184 0.001 - HCO3- 5.941e-03 5.419e-03 -2.226 -2.266 -0.040 - CaHCO3+ 1.246e-04 1.136e-04 -3.905 -3.945 -0.040 - CaCO3 1.302e-06 1.304e-06 -5.885 -5.885 0.001 - CO3-2 6.830e-07 4.726e-07 -6.166 -6.326 -0.160 -Ca 2.502e-03 - Ca+2 2.376e-03 1.643e-03 -2.624 -2.784 -0.160 - CaHCO3+ 1.246e-04 1.136e-04 -3.905 -3.945 -0.040 - CaCO3 1.302e-06 1.304e-06 -5.885 -5.885 0.001 - CaOH+ 5.575e-10 5.070e-10 -9.254 -9.295 -0.041 -H(0) 7.456e-10 - H2 3.728e-10 3.735e-10 -9.429 -9.428 0.001 -N(-3) 1.066e-03 - NH4+ 1.065e-03 9.641e-04 -2.973 -3.016 -0.043 - NH3 1.020e-06 1.022e-06 -5.991 -5.991 0.001 -N(0) 3.685e-06 - N2 1.842e-06 1.846e-06 -5.735 -5.734 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -62.109 -62.151 -0.043 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.401 -84.444 -0.043 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.526 -73.525 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.77 -9.11 -8.34 CaCO3 - Calcite -0.63 -9.11 -8.48 CaCO3 - CH4(g) -0.04 -2.90 -2.86 CH4 - CO2(g) -0.72 -2.18 -1.47 CO2 - H2(g) -6.28 -9.43 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.47 -5.73 -3.26 N2 - NH3(g) -7.76 -5.99 1.77 NH3 - O2(g) -70.56 -73.52 -2.96 O2 - -Reaction step 7. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 3.200e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 4.56e-01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.09 8.051e-01 0.000e+00 1.502e-02 1.502e-02 -CO2(g) -0.54 2.859e-01 0.000e+00 5.333e-03 5.333e-03 -N2(g) -2.05 8.992e-03 0.000e+00 1.677e-04 1.677e-04 -NH3(g) -7.63 2.343e-08 0.000e+00 4.372e-10 4.372e-10 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.772e-02 1.772e-02 - Ca 2.502e-03 2.502e-03 - N 1.905e-03 1.905e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.152 Charge balance - pe = -2.985 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.121e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 6.899e-03 - Total CO2 (mol/kg) = 1.661e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.110231e+02 - Total O = 5.554219e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 7.692e-07 7.048e-07 -6.114 -6.152 -0.038 - OH- 1.571e-08 1.420e-08 -7.804 -7.848 -0.044 - H2O 5.551e+01 9.996e-01 1.744 -0.000 0.000 -C(-4) 1.109e-03 - CH4 1.109e-03 1.111e-03 -2.955 -2.954 0.001 -C(4) 1.661e-02 - CO2 9.712e-03 9.733e-03 -2.013 -2.012 0.001 - HCO3- 6.756e-03 6.139e-03 -2.170 -2.212 -0.042 - CaHCO3+ 1.387e-04 1.261e-04 -3.858 -3.899 -0.042 - CaCO3 1.102e-06 1.104e-06 -5.958 -5.957 0.001 - CO3-2 5.992e-07 4.085e-07 -6.222 -6.389 -0.166 -Ca 2.502e-03 - Ca+2 2.362e-03 1.609e-03 -2.627 -2.793 -0.167 - CaHCO3+ 1.387e-04 1.261e-04 -3.858 -3.899 -0.042 - CaCO3 1.102e-06 1.104e-06 -5.958 -5.957 0.001 - CaOH+ 4.182e-10 3.788e-10 -9.379 -9.422 -0.043 -H(0) 6.560e-10 - H2 3.280e-10 3.287e-10 -9.484 -9.483 0.001 -N(-3) 1.895e-03 - NH4+ 1.893e-03 1.707e-03 -2.723 -2.768 -0.045 - NH3 1.377e-06 1.380e-06 -5.861 -5.860 0.001 -N(0) 9.862e-06 - N2 4.931e-06 4.941e-06 -5.307 -5.306 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.927 -61.972 -0.044 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -84.164 -84.209 -0.044 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.415 -73.414 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.85 -9.18 -8.34 CaCO3 - Calcite -0.70 -9.18 -8.48 CaCO3 - CH4(g) -0.09 -2.95 -2.86 CH4 - CO2(g) -0.54 -2.01 -1.47 CO2 - H2(g) -6.33 -9.48 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.05 -5.31 -3.26 N2 - NH3(g) -7.63 -5.86 1.77 NH3 - O2(g) -70.45 -73.41 -2.96 O2 - -Reaction step 8. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 6.400e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 1.10e+00 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.15 7.052e-01 0.000e+00 3.167e-02 3.167e-02 -CO2(g) -0.42 3.760e-01 0.000e+00 1.689e-02 1.689e-02 -N2(g) -1.73 1.883e-02 0.000e+00 8.456e-04 8.456e-04 -NH3(g) -7.54 2.911e-08 0.000e+00 1.307e-09 1.307e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.151e-02 2.151e-02 - Ca 2.502e-03 2.502e-03 - N 2.789e-03 2.789e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.083 Charge balance - pe = -2.895 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 9.965e-03 - Mass of water (kg) = 9.999e-01 - Total alkalinity (eq/kg) = 7.773e-03 - Total CO2 (mol/kg) = 2.054e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.110272e+02 - Total O = 5.555108e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.035e-07 8.254e-07 -6.044 -6.083 -0.039 - OH- 1.346e-08 1.212e-08 -7.871 -7.916 -0.046 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -C(-4) 9.712e-04 - CH4 9.712e-04 9.734e-04 -3.013 -3.012 0.001 -C(4) 2.054e-02 - CO2 1.277e-02 1.280e-02 -1.894 -1.893 0.001 - HCO3- 7.616e-03 6.895e-03 -2.118 -2.161 -0.043 - CaHCO3+ 1.532e-04 1.387e-04 -3.815 -3.858 -0.043 - CaCO3 1.035e-06 1.037e-06 -5.985 -5.984 0.001 - CO3-2 5.831e-07 3.917e-07 -6.234 -6.407 -0.173 -Ca 2.502e-03 - Ca+2 2.348e-03 1.576e-03 -2.629 -2.802 -0.173 - CaHCO3+ 1.532e-04 1.387e-04 -3.815 -3.858 -0.043 - CaCO3 1.035e-06 1.037e-06 -5.985 -5.984 0.001 - CaOH+ 3.511e-10 3.168e-10 -9.455 -9.499 -0.045 -H(0) 5.924e-10 - H2 2.962e-10 2.969e-10 -9.528 -9.527 0.001 -N(-3) 2.768e-03 - NH4+ 2.767e-03 2.483e-03 -2.558 -2.605 -0.047 - NH3 1.710e-06 1.714e-06 -5.767 -5.766 0.001 -N(0) 2.065e-05 - N2 1.032e-05 1.035e-05 -4.986 -4.985 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.767 -61.814 -0.046 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.960 -84.006 -0.046 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.327 -73.326 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.87 -9.21 -8.34 CaCO3 - Calcite -0.73 -9.21 -8.48 CaCO3 - CH4(g) -0.15 -3.01 -2.86 CH4 - CO2(g) -0.42 -1.89 -1.47 CO2 - H2(g) -6.38 -9.53 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.73 -4.99 -3.26 N2 - NH3(g) -7.54 -5.77 1.77 NH3 - O2(g) -70.37 -73.33 -2.96 O2 - -Reaction step 9. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 1.250e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 2.44e+00 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.20 6.377e-01 0.000e+00 6.367e-02 6.367e-02 -CO2(g) -0.36 4.352e-01 0.000e+00 4.345e-02 4.345e-02 -N2(g) -1.57 2.715e-02 0.000e+00 2.711e-03 2.711e-03 -NH3(g) -7.50 3.187e-08 0.000e+00 3.182e-09 3.182e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.396e-02 2.396e-02 - Ca 2.502e-03 2.502e-03 - N 3.328e-03 3.328e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.048 Charge balance - pe = -2.846 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 1.048e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.302e-03 - Total CO2 (mol/kg) = 2.308e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.107e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 19 - Total H = 1.110340e+02 - Total O = 5.555897e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.825e-07 8.960e-07 -6.008 -6.048 -0.040 - OH- 1.243e-08 1.117e-08 -7.905 -7.952 -0.047 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -C(-4) 8.781e-04 - CH4 8.781e-04 8.802e-04 -3.056 -3.055 0.001 -C(4) 2.308e-02 - CO2 1.478e-02 1.482e-02 -1.830 -1.829 0.001 - HCO3- 8.137e-03 7.351e-03 -2.090 -2.134 -0.044 - CaHCO3+ 1.616e-04 1.460e-04 -3.791 -3.836 -0.044 - CaCO3 1.004e-06 1.006e-06 -5.998 -5.997 0.001 - CO3-2 5.776e-07 3.847e-07 -6.238 -6.415 -0.177 -Ca 2.502e-03 - Ca+2 2.339e-03 1.557e-03 -2.631 -2.808 -0.177 - CaHCO3+ 1.616e-04 1.460e-04 -3.791 -3.836 -0.044 - CaCO3 1.004e-06 1.006e-06 -5.998 -5.997 0.001 - CaOH+ 3.202e-10 2.883e-10 -9.495 -9.540 -0.046 -H(0) 5.569e-10 - H2 2.784e-10 2.791e-10 -9.555 -9.554 0.001 -N(-3) 3.298e-03 - NH4+ 3.296e-03 2.951e-03 -2.482 -2.530 -0.048 - NH3 1.872e-06 1.877e-06 -5.728 -5.727 0.001 -N(0) 2.977e-05 - N2 1.489e-05 1.492e-05 -4.827 -4.826 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.682 -61.730 -0.047 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.848 -83.896 -0.047 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.273 -73.272 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.89 -9.22 -8.34 CaCO3 - Calcite -0.74 -9.22 -8.48 CaCO3 - CH4(g) -0.20 -3.06 -2.86 CH4 - CO2(g) -0.36 -1.83 -1.47 CO2 - H2(g) -6.40 -9.55 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.57 -4.83 -3.26 N2 - NH3(g) -7.50 -5.73 1.77 NH3 - O2(g) -70.31 -73.27 -2.96 O2 - -Reaction step 10. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 2.500e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 5.29e+00 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.22 5.988e-01 0.000e+00 1.294e-01 1.294e-01 -CO2(g) -0.33 4.690e-01 0.000e+00 1.013e-01 1.013e-01 -N2(g) -1.49 3.216e-02 0.000e+00 6.949e-03 6.949e-03 -NH3(g) -7.48 3.294e-08 0.000e+00 7.117e-09 7.117e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.532e-02 2.532e-02 - Ca 2.502e-03 2.502e-03 - N 3.602e-03 3.602e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.029 Charge balance - pe = -2.819 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 1.074e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.570e-03 - Total CO2 (mol/kg) = 2.450e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 23 - Total H = 1.110473e+02 - Total O = 5.556816e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.028e-06 9.364e-07 -5.988 -6.029 -0.040 - OH- 1.191e-08 1.069e-08 -7.924 -7.971 -0.047 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -C(-4) 8.246e-04 - CH4 8.246e-04 8.266e-04 -3.084 -3.083 0.001 -C(4) 2.450e-02 - CO2 1.593e-02 1.597e-02 -1.798 -1.797 0.001 - HCO3- 8.400e-03 7.581e-03 -2.076 -2.120 -0.045 - CaHCO3+ 1.659e-04 1.497e-04 -3.780 -3.825 -0.045 - CaCO3 9.846e-07 9.870e-07 -6.007 -6.006 0.001 - CO3-2 5.724e-07 3.797e-07 -6.242 -6.421 -0.178 -Ca 2.502e-03 - Ca+2 2.335e-03 1.548e-03 -2.632 -2.810 -0.179 - CaHCO3+ 1.659e-04 1.497e-04 -3.780 -3.825 -0.045 - CaCO3 9.846e-07 9.870e-07 -6.007 -6.006 0.001 - CaOH+ 3.049e-10 2.741e-10 -9.516 -9.562 -0.046 -H(0) 5.380e-10 - H2 2.690e-10 2.697e-10 -9.570 -9.569 0.001 -N(-3) 3.566e-03 - NH4+ 3.564e-03 3.187e-03 -2.448 -2.497 -0.049 - NH3 1.935e-06 1.939e-06 -5.713 -5.712 0.001 -N(0) 3.526e-05 - N2 1.763e-05 1.767e-05 -4.754 -4.753 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.642 -61.690 -0.048 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.793 -83.841 -0.048 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.243 -73.242 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.89 -9.23 -8.34 CaCO3 - Calcite -0.75 -9.23 -8.48 CaCO3 - CH4(g) -0.22 -3.08 -2.86 CH4 - CO2(g) -0.33 -1.80 -1.47 CO2 - H2(g) -6.42 -9.57 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.49 -4.75 -3.26 N2 - NH3(g) -7.48 -5.71 1.77 NH3 - O2(g) -70.28 -73.24 -2.96 O2 - -Reaction step 11. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 5.000e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 1.10e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.24 5.791e-01 0.000e+00 2.609e-01 2.609e-01 -CO2(g) -0.31 4.862e-01 0.000e+00 2.191e-01 2.191e-01 -N2(g) -1.46 3.469e-02 0.000e+00 1.563e-02 1.563e-02 -NH3(g) -7.48 3.333e-08 0.000e+00 1.502e-08 1.502e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.600e-02 2.601e-02 - Ca 2.501e-03 2.502e-03 - N 3.730e-03 3.731e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.019 Charge balance - pe = -2.806 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 1.086e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 8.694e-03 - Total CO2 (mol/kg) = 2.520e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.094e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 23 - Total H = 1.110737e+02 - Total O = 5.558262e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.051e-06 9.573e-07 -5.978 -6.019 -0.041 - OH- 1.166e-08 1.045e-08 -7.933 -7.981 -0.047 - H2O 5.551e+01 9.995e-01 1.744 -0.000 0.000 -C(-4) 7.973e-04 - CH4 7.973e-04 7.993e-04 -3.098 -3.097 0.001 -C(4) 2.520e-02 - CO2 1.651e-02 1.655e-02 -1.782 -1.781 0.001 - HCO3- 8.522e-03 7.687e-03 -2.069 -2.114 -0.045 - CaHCO3+ 1.678e-04 1.513e-04 -3.775 -3.820 -0.045 - CaCO3 9.737e-07 9.761e-07 -6.012 -6.011 0.001 - CO3-2 5.689e-07 3.766e-07 -6.245 -6.424 -0.179 -Ca 2.501e-03 - Ca+2 2.333e-03 1.543e-03 -2.632 -2.812 -0.179 - CaHCO3+ 1.678e-04 1.513e-04 -3.775 -3.820 -0.045 - CaCO3 9.737e-07 9.761e-07 -6.012 -6.011 0.001 - CaOH+ 2.975e-10 2.673e-10 -9.527 -9.573 -0.046 -H(0) 5.287e-10 - H2 2.643e-10 2.650e-10 -9.578 -9.577 0.001 -N(-3) 3.691e-03 - NH4+ 3.690e-03 3.297e-03 -2.433 -2.482 -0.049 - NH3 1.958e-06 1.962e-06 -5.708 -5.707 0.001 -N(0) 3.804e-05 - N2 1.902e-05 1.907e-05 -4.721 -4.720 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.623 -61.671 -0.048 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.767 -83.815 -0.048 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.228 -73.227 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.90 -9.24 -8.34 CaCO3 - Calcite -0.76 -9.24 -8.48 CaCO3 - CH4(g) -0.24 -3.10 -2.86 CH4 - CO2(g) -0.31 -1.78 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.46 -4.72 -3.26 N2 - NH3(g) -7.48 -5.71 1.77 NH3 - O2(g) -70.27 -73.23 -2.96 O2 - -Reaction step 12. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed-pressure gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 2. - - 1.000e+00 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1000 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.24 5.692e-01 0.000e+00 5.241e-01 5.241e-01 -CO2(g) -0.31 4.949e-01 0.000e+00 4.557e-01 4.557e-01 -N2(g) -1.44 3.595e-02 0.000e+00 3.310e-02 3.310e-02 -NH3(g) -7.48 3.349e-08 0.000e+00 3.083e-08 3.083e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.634e-02 2.636e-02 - Ca 2.500e-03 2.502e-03 - N 3.791e-03 3.794e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.014 Charge balance - pe = -2.799 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 1.091e-02 - Mass of water (kg) = 1.001e+00 - Total alkalinity (eq/kg) = 8.752e-03 - Total CO2 (mol/kg) = 2.556e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.077e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 24 - Total H = 1.111262e+02 - Total O = 5.560955e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.063e-06 9.680e-07 -5.973 -6.014 -0.041 - OH- 1.153e-08 1.034e-08 -7.938 -7.986 -0.047 - H2O 5.551e+01 9.994e-01 1.744 -0.000 0.000 -C(-4) 7.837e-04 - CH4 7.837e-04 7.857e-04 -3.106 -3.105 0.001 -C(4) 2.556e-02 - CO2 1.681e-02 1.685e-02 -1.775 -1.773 0.001 - HCO3- 8.579e-03 7.737e-03 -2.067 -2.111 -0.045 - CaHCO3+ 1.686e-04 1.520e-04 -3.773 -3.818 -0.045 - CaCO3 9.674e-07 9.698e-07 -6.014 -6.013 0.001 - CO3-2 5.667e-07 3.748e-07 -6.247 -6.426 -0.180 -Ca 2.500e-03 - Ca+2 2.331e-03 1.540e-03 -2.633 -2.812 -0.180 - CaHCO3+ 1.686e-04 1.520e-04 -3.773 -3.818 -0.045 - CaCO3 9.674e-07 9.698e-07 -6.014 -6.013 0.001 - CaOH+ 2.937e-10 2.639e-10 -9.532 -9.579 -0.047 -H(0) 5.241e-10 - H2 2.621e-10 2.627e-10 -9.582 -9.581 0.001 -N(-3) 3.752e-03 - NH4+ 3.750e-03 3.350e-03 -2.426 -2.475 -0.049 - NH3 1.967e-06 1.972e-06 -5.706 -5.705 0.001 -N(0) 3.942e-05 - N2 1.971e-05 1.976e-05 -4.705 -4.704 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.614 -61.663 -0.048 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.754 -83.802 -0.048 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.221 -73.219 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.90 -9.24 -8.34 CaCO3 - Calcite -0.76 -9.24 -8.48 CaCO3 - CH4(g) -0.24 -3.10 -2.86 CH4 - CO2(g) -0.31 -1.77 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.44 -4.70 -3.26 N2 - NH3(g) -7.48 -5.71 1.77 NH3 - O2(g) -70.26 -73.22 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - USE solution 1 - USE reaction 1 - GAS_PHASE 1 Fixed volume gas phase - fixed_volume - volume 22.5 - CO2(g) 0.0 - CH4(g) 0.0 - N2(g) 0.0 - NH3(g) 0.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 1.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0024 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -3.24 5.712e-04 0.000e+00 5.253e-04 5.253e-04 -CO2(g) -2.76 1.756e-03 0.000e+00 1.615e-03 1.615e-03 -N2(g) -4.42 3.775e-05 0.000e+00 3.472e-05 3.472e-05 -NH3(g) -9.17 6.759e-10 0.000e+00 6.216e-10 6.216e-10 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.930e-03 4.930e-03 - Ca 2.502e-03 2.502e-03 - N 5.596e-07 5.596e-07 - -----------------------------Description of solution---------------------------- - - pH = 8.204 Charge balance - pe = -4.921 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.093e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.005e-03 - Total CO2 (mol/kg) = 4.930e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110125e+02 - Total O = 5.551863e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.754e-06 1.603e-06 -5.756 -5.795 -0.039 - H+ 6.760e-09 6.246e-09 -8.170 -8.204 -0.034 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 7.871e-07 - CH4 7.871e-07 7.884e-07 -6.104 -6.103 0.001 -C(4) 4.930e-03 - HCO3- 4.640e-03 4.258e-03 -2.334 -2.371 -0.037 - CaHCO3+ 9.719e-05 8.918e-05 -4.012 -4.050 -0.037 - CaCO3 8.803e-05 8.818e-05 -4.055 -4.055 0.001 - CO2 5.969e-05 5.979e-05 -4.224 -4.223 0.001 - CO3-2 4.508e-05 3.197e-05 -4.346 -4.495 -0.149 -Ca 2.502e-03 - Ca+2 2.317e-03 1.642e-03 -2.635 -2.785 -0.150 - CaHCO3+ 9.719e-05 8.918e-05 -4.012 -4.050 -0.037 - CaCO3 8.803e-05 8.818e-05 -4.055 -4.055 0.001 - CaOH+ 4.766e-08 4.362e-08 -7.322 -7.360 -0.038 -H(0) 3.826e-10 - H2 1.913e-10 1.916e-10 -9.718 -9.718 0.001 -N(-3) 5.182e-07 - NH4+ 4.784e-07 4.362e-07 -6.320 -6.360 -0.040 - NH3 3.974e-08 3.980e-08 -7.401 -7.400 0.001 -N(0) 4.143e-08 - N2 2.071e-08 2.075e-08 -7.684 -7.683 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.716 -60.756 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -82.719 -82.758 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -72.946 -72.945 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 1.06 -7.28 -8.34 CaCO3 - Calcite 1.20 -7.28 -8.48 CaCO3 - CH4(g) -3.24 -6.10 -2.86 CH4 - CO2(g) -2.76 -4.22 -1.47 CO2 - H2(g) -6.57 -9.72 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.42 -7.68 -3.26 N2 - NH3(g) -9.17 -7.40 1.77 NH3 - O2(g) -69.98 -72.94 -2.96 O2 - -Reaction step 2. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 2.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0034 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -2.94 1.142e-03 0.000e+00 1.051e-03 1.051e-03 -CO2(g) -2.65 2.226e-03 0.000e+00 2.047e-03 2.047e-03 -N2(g) -4.12 7.549e-05 0.000e+00 6.942e-05 6.942e-05 -NH3(g) -8.95 1.134e-09 0.000e+00 1.043e-09 1.043e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 4.973e-03 4.973e-03 - Ca 2.502e-03 2.502e-03 - N 1.156e-06 1.156e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.106 Charge balance - pe = -4.847 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.132e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.005e-03 - Total CO2 (mol/kg) = 4.972e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110127e+02 - Total O = 5.551877e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.399e-06 1.278e-06 -5.854 -5.893 -0.039 - H+ 8.478e-09 7.832e-09 -8.072 -8.106 -0.034 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 1.574e-06 - CH4 1.574e-06 1.577e-06 -5.803 -5.802 0.001 -C(4) 4.972e-03 - HCO3- 4.690e-03 4.303e-03 -2.329 -2.366 -0.037 - CaHCO3+ 9.880e-05 9.064e-05 -4.005 -4.043 -0.037 - CO2 7.565e-05 7.577e-05 -4.121 -4.120 0.001 - CaCO3 7.135e-05 7.146e-05 -4.147 -4.146 0.001 - CO3-2 3.636e-05 2.576e-05 -4.439 -4.589 -0.150 -Ca 2.502e-03 - Ca+2 2.332e-03 1.651e-03 -2.632 -2.782 -0.150 - CaHCO3+ 9.880e-05 9.064e-05 -4.005 -4.043 -0.037 - CaCO3 7.135e-05 7.146e-05 -4.147 -4.146 0.001 - CaOH+ 3.823e-08 3.498e-08 -7.418 -7.456 -0.039 -H(0) 4.288e-10 - H2 2.144e-10 2.148e-10 -9.669 -9.668 0.001 -N(-3) 1.074e-06 - NH4+ 1.007e-06 9.178e-07 -5.997 -6.037 -0.040 - NH3 6.667e-08 6.678e-08 -7.176 -7.175 0.001 -N(0) 8.283e-08 - N2 4.142e-08 4.148e-08 -7.383 -7.382 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.738 -60.778 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -82.790 -82.830 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.045 -73.044 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.96 -7.37 -8.34 CaCO3 - Calcite 1.11 -7.37 -8.48 CaCO3 - CH4(g) -2.94 -5.80 -2.86 CH4 - CO2(g) -2.65 -4.12 -1.47 CO2 - H2(g) -6.52 -9.67 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.12 -7.38 -3.26 N2 - NH3(g) -8.95 -7.18 1.77 NH3 - O2(g) -70.08 -73.04 -2.96 O2 - -Reaction step 3. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 3.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0045 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -2.77 1.713e-03 0.000e+00 1.576e-03 1.576e-03 -CO2(g) -2.57 2.703e-03 0.000e+00 2.486e-03 2.486e-03 -N2(g) -3.95 1.132e-04 0.000e+00 1.041e-04 1.041e-04 -NH3(g) -8.82 1.503e-09 0.000e+00 1.382e-09 1.382e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.009e-03 5.009e-03 - Ca 2.502e-03 2.502e-03 - N 1.822e-06 1.822e-06 - -----------------------------Description of solution---------------------------- - - pH = 8.025 Charge balance - pe = -4.777 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.159e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.006e-03 - Total CO2 (mol/kg) = 5.006e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.101e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 8 - Total H = 1.110128e+02 - Total O = 5.551889e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.160e-06 1.060e-06 -5.936 -5.975 -0.039 - H+ 1.023e-08 9.445e-09 -7.990 -8.025 -0.034 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 2.361e-06 - CH4 2.361e-06 2.365e-06 -5.627 -5.626 0.001 -C(4) 5.006e-03 - HCO3- 4.724e-03 4.334e-03 -2.326 -2.363 -0.037 - CaHCO3+ 9.991e-05 9.166e-05 -4.000 -4.038 -0.037 - CO2 9.189e-05 9.204e-05 -4.037 -4.036 0.001 - CaCO3 5.983e-05 5.992e-05 -4.223 -4.222 0.001 - CO3-2 3.039e-05 2.152e-05 -4.517 -4.667 -0.150 -Ca 2.502e-03 - Ca+2 2.342e-03 1.658e-03 -2.630 -2.781 -0.150 - CaHCO3+ 9.991e-05 9.166e-05 -4.000 -4.038 -0.037 - CaCO3 5.983e-05 5.992e-05 -4.223 -4.222 0.001 - CaOH+ 3.183e-08 2.912e-08 -7.497 -7.536 -0.039 -H(0) 4.521e-10 - H2 2.260e-10 2.264e-10 -9.646 -9.645 0.001 -N(-3) 1.698e-06 - NH4+ 1.609e-06 1.467e-06 -5.793 -5.834 -0.040 - NH3 8.836e-08 8.851e-08 -7.054 -7.053 0.001 -N(0) 1.242e-07 - N2 6.210e-08 6.220e-08 -7.207 -7.206 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.766 -60.806 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -82.841 -82.881 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.091 -73.090 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.89 -7.45 -8.34 CaCO3 - Calcite 1.03 -7.45 -8.48 CaCO3 - CH4(g) -2.77 -5.63 -2.86 CH4 - CO2(g) -2.57 -4.04 -1.47 CO2 - H2(g) -6.50 -9.65 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.95 -7.21 -3.26 N2 - NH3(g) -8.82 -7.05 1.77 NH3 - O2(g) -70.13 -73.09 -2.96 O2 - -Reaction step 4. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 4.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0056 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -2.64 2.285e-03 0.000e+00 2.101e-03 2.101e-03 -CO2(g) -2.50 3.186e-03 0.000e+00 2.930e-03 2.930e-03 -N2(g) -3.82 1.508e-04 0.000e+00 1.387e-04 1.387e-04 -NH3(g) -8.74 1.817e-09 0.000e+00 1.671e-09 1.671e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.040e-03 5.039e-03 - Ca 2.502e-03 2.502e-03 - N 2.554e-06 2.554e-06 - -----------------------------Description of solution---------------------------- - - pH = 7.956 Charge balance - pe = -4.715 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.179e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.007e-03 - Total CO2 (mol/kg) = 5.036e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.089e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 8 - Total H = 1.110129e+02 - Total O = 5.551900e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 9.896e-07 9.039e-07 -6.005 -6.044 -0.039 - H+ 1.199e-08 1.107e-08 -7.921 -7.956 -0.035 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 3.148e-06 - CH4 3.148e-06 3.154e-06 -5.502 -5.501 0.001 -C(4) 5.036e-03 - HCO3- 4.750e-03 4.357e-03 -2.323 -2.361 -0.038 - CO2 1.083e-04 1.085e-04 -3.965 -3.965 0.001 - CaHCO3+ 1.007e-04 9.240e-05 -3.997 -4.034 -0.038 - CaCO3 5.144e-05 5.153e-05 -4.289 -4.288 0.001 - CO3-2 2.607e-05 1.845e-05 -4.584 -4.734 -0.150 -Ca 2.502e-03 - Ca+2 2.350e-03 1.662e-03 -2.629 -2.779 -0.150 - CaHCO3+ 1.007e-04 9.240e-05 -3.997 -4.034 -0.038 - CaCO3 5.144e-05 5.153e-05 -4.289 -4.288 0.001 - CaOH+ 2.723e-08 2.491e-08 -7.565 -7.604 -0.039 -H(0) 4.662e-10 - H2 2.331e-10 2.335e-10 -9.632 -9.632 0.001 -N(-3) 2.389e-06 - NH4+ 2.282e-06 2.079e-06 -5.642 -5.682 -0.040 - NH3 1.068e-07 1.070e-07 -6.971 -6.971 0.001 -N(0) 1.655e-07 - N2 8.276e-08 8.289e-08 -7.082 -7.081 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.793 -60.833 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -82.881 -82.921 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.117 -73.117 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.82 -7.51 -8.34 CaCO3 - Calcite 0.97 -7.51 -8.48 CaCO3 - CH4(g) -2.64 -5.50 -2.86 CH4 - CO2(g) -2.50 -3.96 -1.47 CO2 - H2(g) -6.48 -9.63 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.82 -7.08 -3.26 N2 - NH3(g) -8.74 -6.97 1.77 NH3 - O2(g) -70.16 -73.12 -2.96 O2 - -Reaction step 5. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 8.000e-03 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0100 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -2.34 4.569e-03 0.000e+00 4.202e-03 4.202e-03 -CO2(g) -2.29 5.141e-03 0.000e+00 4.728e-03 4.728e-03 -N2(g) -3.52 3.012e-04 0.000e+00 2.770e-04 2.770e-04 -NH3(g) -8.56 2.783e-09 0.000e+00 2.559e-09 2.559e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.141e-03 5.141e-03 - Ca 2.502e-03 2.502e-03 - N 6.067e-06 6.067e-06 - -----------------------------Description of solution---------------------------- - - pH = 7.753 Charge balance - pe = -4.524 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.225e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.010e-03 - Total CO2 (mol/kg) = 5.135e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.182e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 8 - Total H = 1.110133e+02 - Total O = 5.551940e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 6.208e-07 5.669e-07 -6.207 -6.246 -0.039 - H+ 1.912e-08 1.766e-08 -7.718 -7.753 -0.035 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 6.296e-06 - CH4 6.296e-06 6.307e-06 -5.201 -5.200 0.001 -C(4) 5.135e-03 - HCO3- 4.808e-03 4.409e-03 -2.318 -2.356 -0.038 - CO2 1.748e-04 1.750e-04 -3.758 -3.757 0.001 - CaHCO3+ 1.026e-04 9.408e-05 -3.989 -4.027 -0.038 - CaCO3 3.285e-05 3.290e-05 -4.483 -4.483 0.001 - CO3-2 1.656e-05 1.171e-05 -4.781 -4.931 -0.150 -Ca 2.502e-03 - Ca+2 2.367e-03 1.673e-03 -2.626 -2.777 -0.151 - CaHCO3+ 1.026e-04 9.408e-05 -3.989 -4.027 -0.038 - CaCO3 3.285e-05 3.290e-05 -4.483 -4.483 0.001 - CaOH+ 1.719e-08 1.572e-08 -7.765 -7.804 -0.039 -H(0) 4.919e-10 - H2 2.459e-10 2.464e-10 -9.609 -9.608 0.001 -N(-3) 5.737e-06 - NH4+ 5.573e-06 5.077e-06 -5.254 -5.294 -0.040 - NH3 1.636e-07 1.639e-07 -6.786 -6.785 0.001 -N(0) 3.305e-07 - N2 1.652e-07 1.655e-07 -6.782 -6.781 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.880 -60.920 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -82.992 -83.032 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.164 -73.163 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.63 -7.71 -8.34 CaCO3 - Calcite 0.77 -7.71 -8.48 CaCO3 - CH4(g) -2.34 -5.20 -2.86 CH4 - CO2(g) -2.29 -3.76 -1.47 CO2 - H2(g) -6.46 -9.61 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.52 -6.78 -3.26 N2 - NH3(g) -8.56 -6.79 1.77 NH3 - O2(g) -70.20 -73.16 -2.96 O2 - -Reaction step 6. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 1.600e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0188 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -2.04 9.136e-03 0.000e+00 8.402e-03 8.402e-03 -CO2(g) -2.04 9.088e-03 0.000e+00 8.358e-03 8.358e-03 -N2(g) -3.22 6.006e-04 0.000e+00 5.523e-04 5.523e-04 -NH3(g) -8.39 4.116e-09 0.000e+00 3.786e-09 3.786e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.311e-03 5.311e-03 - Ca 2.502e-03 2.502e-03 - N 1.533e-05 1.533e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.510 Charge balance - pe = -4.288 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.265e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.019e-03 - Total CO2 (mol/kg) = 5.299e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 8 - Total H = 1.110142e+02 - Total O = 5.552014e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 3.548e-07 3.239e-07 -6.450 -6.490 -0.040 - H+ 3.347e-08 3.090e-08 -7.475 -7.510 -0.035 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 1.259e-05 - CH4 1.259e-05 1.261e-05 -4.900 -4.899 0.001 -C(4) 5.299e-03 - HCO3- 4.857e-03 4.453e-03 -2.314 -2.351 -0.038 - CO2 3.089e-04 3.094e-04 -3.510 -3.509 0.001 - CaHCO3+ 1.041e-04 9.544e-05 -3.983 -4.020 -0.038 - CaCO3 1.904e-05 1.907e-05 -4.720 -4.720 0.001 - CO3-2 9.566e-06 6.759e-06 -5.019 -5.170 -0.151 -Ca 2.502e-03 - Ca+2 2.379e-03 1.680e-03 -2.624 -2.775 -0.151 - CaHCO3+ 1.041e-04 9.544e-05 -3.983 -4.020 -0.038 - CaCO3 1.904e-05 1.907e-05 -4.720 -4.720 0.001 - CaOH+ 9.866e-09 9.021e-09 -8.006 -8.045 -0.039 -H(0) 5.073e-10 - H2 2.536e-10 2.541e-10 -9.596 -9.595 0.001 -N(-3) 1.467e-05 - NH4+ 1.443e-05 1.314e-05 -4.841 -4.881 -0.041 - NH3 2.420e-07 2.424e-07 -6.616 -6.615 0.001 -N(0) 6.590e-07 - N2 3.295e-07 3.301e-07 -6.482 -6.481 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -60.993 -61.033 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.118 -83.158 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.191 -73.190 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.39 -7.94 -8.34 CaCO3 - Calcite 0.53 -7.94 -8.48 CaCO3 - CH4(g) -2.04 -4.90 -2.86 CH4 - CO2(g) -2.04 -3.51 -1.47 CO2 - H2(g) -6.45 -9.60 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.22 -6.48 -3.26 N2 - NH3(g) -8.39 -6.62 1.77 NH3 - O2(g) -70.23 -73.19 -2.96 O2 - -Reaction step 7. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 3.200e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0365 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -1.74 1.827e-02 0.000e+00 1.680e-02 1.680e-02 -CO2(g) -1.77 1.701e-02 0.000e+00 1.564e-02 1.564e-02 -N2(g) -2.92 1.196e-03 0.000e+00 1.100e-03 1.100e-03 -NH3(g) -8.23 5.955e-09 0.000e+00 5.476e-09 5.476e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 5.630e-03 5.630e-03 - Ca 2.502e-03 2.502e-03 - N 4.035e-05 4.035e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.242 Charge balance - pe = -4.023 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.308e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.043e-03 - Total CO2 (mol/kg) = 5.605e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110160e+02 - Total O = 5.552158e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.915e-07 1.748e-07 -6.718 -6.757 -0.040 - H+ 6.203e-08 5.726e-08 -7.207 -7.242 -0.035 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 2.517e-05 - CH4 2.517e-05 2.522e-05 -4.599 -4.598 0.001 -C(4) 5.605e-03 - HCO3- 4.906e-03 4.497e-03 -2.309 -2.347 -0.038 - CO2 5.780e-04 5.790e-04 -3.238 -3.237 0.001 - CaHCO3+ 1.054e-04 9.659e-05 -3.977 -4.015 -0.038 - CaCO3 1.040e-05 1.042e-05 -4.983 -4.982 0.001 - CO3-2 5.218e-06 3.683e-06 -5.283 -5.434 -0.151 -Ca 2.502e-03 - Ca+2 2.386e-03 1.683e-03 -2.622 -2.774 -0.152 - CaHCO3+ 1.054e-04 9.659e-05 -3.977 -4.015 -0.038 - CaCO3 1.040e-05 1.042e-05 -4.983 -4.982 0.001 - CaOH+ 5.337e-09 4.879e-09 -8.273 -8.312 -0.039 -H(0) 5.158e-10 - H2 2.579e-10 2.583e-10 -9.589 -9.588 0.001 -N(-3) 3.904e-05 - NH4+ 3.869e-05 3.523e-05 -4.412 -4.453 -0.041 - NH3 3.501e-07 3.506e-07 -6.456 -6.455 0.001 -N(0) 1.312e-06 - N2 6.561e-07 6.572e-07 -6.183 -6.182 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.122 -61.162 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.254 -83.295 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.205 -73.204 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite 0.13 -8.21 -8.34 CaCO3 - Calcite 0.27 -8.21 -8.48 CaCO3 - CH4(g) -1.74 -4.60 -2.86 CH4 - CO2(g) -1.77 -3.24 -1.47 CO2 - H2(g) -6.44 -9.59 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.92 -6.18 -3.26 N2 - NH3(g) -8.23 -6.46 1.77 NH3 - O2(g) -70.24 -73.20 -2.96 O2 - -Reaction step 8. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 6.400e-02 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.0718 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -1.44 3.653e-02 0.000e+00 3.359e-02 3.359e-02 -CO2(g) -1.48 3.285e-02 0.000e+00 3.021e-02 3.021e-02 -N2(g) -2.62 2.377e-03 0.000e+00 2.186e-03 2.186e-03 -NH3(g) -8.07 8.504e-09 0.000e+00 7.820e-09 7.820e-09 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 6.268e-03 6.268e-03 - Ca 2.502e-03 2.502e-03 - N 1.082e-04 1.082e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.963 Charge balance - pe = -3.746 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.383e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.110e-03 - Total CO2 (mol/kg) = 6.217e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 12 - Total H = 1.110195e+02 - Total O = 5.552443e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.180e-07 1.089e-07 -6.928 -6.963 -0.035 - OH- 1.008e-07 9.192e-08 -6.997 -7.037 -0.040 - H2O 5.551e+01 9.999e-01 1.744 -0.000 0.000 -C(-4) 5.033e-05 - CH4 5.033e-05 5.042e-05 -4.298 -4.297 0.001 -C(4) 6.217e-03 - HCO3- 4.985e-03 4.568e-03 -2.302 -2.340 -0.038 - CO2 1.117e-03 1.118e-03 -2.952 -2.951 0.001 - CaHCO3+ 1.071e-04 9.809e-05 -3.970 -4.008 -0.038 - CaCO3 5.553e-06 5.563e-06 -5.255 -5.255 0.001 - CO3-2 2.791e-06 1.967e-06 -5.554 -5.706 -0.152 -Ca 2.502e-03 - Ca+2 2.389e-03 1.683e-03 -2.622 -2.774 -0.152 - CaHCO3+ 1.071e-04 9.809e-05 -3.970 -4.008 -0.038 - CaCO3 5.553e-06 5.563e-06 -5.255 -5.255 0.001 - CaOH+ 2.807e-09 2.565e-09 -8.552 -8.591 -0.039 -H(0) 5.202e-10 - H2 2.601e-10 2.605e-10 -9.585 -9.584 0.001 -N(-3) 1.056e-04 - NH4+ 1.051e-04 9.568e-05 -3.978 -4.019 -0.041 - NH3 4.999e-07 5.007e-07 -6.301 -6.300 0.001 -N(0) 2.608e-06 - N2 1.304e-06 1.306e-06 -5.885 -5.884 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.258 -61.298 -0.040 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.394 -83.434 -0.040 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.213 -73.212 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.14 -8.48 -8.34 CaCO3 - Calcite -0.00 -8.48 -8.48 CaCO3 - CH4(g) -1.44 -4.30 -2.86 CH4 - CO2(g) -1.48 -2.95 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.62 -5.88 -3.26 N2 - NH3(g) -8.07 -6.30 1.77 NH3 - O2(g) -70.25 -73.21 -2.96 O2 - -Reaction step 9. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 1.250e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.1390 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -1.15 7.131e-02 0.000e+00 6.558e-02 6.558e-02 -CO2(g) -1.20 6.304e-02 0.000e+00 5.798e-02 5.798e-02 -N2(g) -2.34 4.605e-03 0.000e+00 4.235e-03 4.235e-03 -NH3(g) -7.92 1.191e-08 0.000e+00 1.096e-08 1.096e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 7.514e-03 7.514e-03 - Ca 2.502e-03 2.502e-03 - N 2.794e-04 2.794e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.694 Charge balance - pe = -3.478 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.551e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.278e-03 - Total CO2 (mol/kg) = 7.416e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 18 - Total H = 1.110264e+02 - Total O = 5.552991e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.192e-07 2.021e-07 -6.659 -6.694 -0.035 - OH- 5.433e-08 4.952e-08 -7.265 -7.305 -0.040 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 9.827e-05 - CH4 9.827e-05 9.844e-05 -4.008 -4.007 0.001 -C(4) 7.416e-03 - HCO3- 5.158e-03 4.722e-03 -2.288 -2.326 -0.038 - CO2 2.143e-03 2.146e-03 -2.669 -2.668 0.001 - CaHCO3+ 1.103e-04 1.010e-04 -3.957 -3.996 -0.038 - CaCO3 3.080e-06 3.086e-06 -5.511 -5.511 0.001 - CO3-2 1.560e-06 1.096e-06 -5.807 -5.960 -0.153 -Ca 2.502e-03 - Ca+2 2.388e-03 1.677e-03 -2.622 -2.776 -0.154 - CaHCO3+ 1.103e-04 1.010e-04 -3.957 -3.996 -0.038 - CaCO3 3.080e-06 3.086e-06 -5.511 -5.511 0.001 - CaOH+ 1.508e-09 1.376e-09 -8.822 -8.861 -0.040 -H(0) 5.224e-10 - H2 2.612e-10 2.617e-10 -9.583 -9.582 0.001 -N(-3) 2.744e-04 - NH4+ 2.737e-04 2.488e-04 -3.563 -3.604 -0.041 - NH3 7.003e-07 7.015e-07 -6.155 -6.154 0.001 -N(0) 5.053e-06 - N2 2.526e-06 2.531e-06 -5.597 -5.597 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.385 -61.426 -0.041 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.523 -83.564 -0.041 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.216 -73.216 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.40 -8.74 -8.34 CaCO3 - Calcite -0.26 -8.74 -8.48 CaCO3 - CH4(g) -1.15 -4.01 -2.86 CH4 - CO2(g) -1.20 -2.67 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.34 -5.60 -3.26 N2 - NH3(g) -7.92 -6.15 1.77 NH3 - O2(g) -70.26 -73.22 -2.96 O2 - -Reaction step 10. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 2.500e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.2765 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.85 1.426e-01 0.000e+00 1.311e-01 1.311e-01 -CO2(g) -0.90 1.249e-01 0.000e+00 1.148e-01 1.148e-01 -N2(g) -2.04 9.123e-03 0.000e+00 8.390e-03 8.390e-03 -NH3(g) -7.77 1.683e-08 0.000e+00 1.547e-08 1.547e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.015e-02 1.015e-02 - Ca 2.502e-03 2.502e-03 - N 7.205e-04 7.206e-04 - -----------------------------Description of solution---------------------------- - - pH = 6.432 Charge balance - pe = -3.216 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 7.974e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.714e-03 - Total CO2 (mol/kg) = 9.953e-03 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.110405e+02 - Total O = 5.554122e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 4.021e-07 3.702e-07 -6.396 -6.432 -0.036 - OH- 2.973e-08 2.704e-08 -7.527 -7.568 -0.041 - H2O 5.551e+01 9.998e-01 1.744 -0.000 0.000 -C(-4) 1.964e-04 - CH4 1.964e-04 1.968e-04 -3.707 -3.706 0.001 -C(4) 9.953e-03 - HCO3- 5.589e-03 5.106e-03 -2.253 -2.292 -0.039 - CO2 4.243e-03 4.251e-03 -2.372 -2.372 0.001 - CaHCO3+ 1.182e-04 1.080e-04 -3.927 -3.967 -0.039 - CaCO3 1.798e-06 1.802e-06 -5.745 -5.744 0.001 - CO3-2 9.288e-07 6.469e-07 -6.032 -6.189 -0.157 -Ca 2.502e-03 - Ca+2 2.382e-03 1.658e-03 -2.623 -2.780 -0.157 - CaHCO3+ 1.182e-04 1.080e-04 -3.927 -3.967 -0.039 - CaCO3 1.798e-06 1.802e-06 -5.745 -5.744 0.001 - CaOH+ 8.158e-10 7.431e-10 -9.088 -9.129 -0.041 -H(0) 5.236e-10 - H2 2.618e-10 2.623e-10 -9.582 -9.581 0.001 -N(-3) 7.105e-04 - NH4+ 7.095e-04 6.436e-04 -3.149 -3.191 -0.042 - NH3 9.890e-07 9.908e-07 -6.005 -6.004 0.001 -N(0) 1.001e-05 - N2 5.004e-06 5.013e-06 -5.301 -5.300 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.500 -61.542 -0.042 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.639 -83.681 -0.042 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.219 -73.218 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.63 -8.97 -8.34 CaCO3 - Calcite -0.49 -8.97 -8.48 CaCO3 - CH4(g) -0.85 -3.71 -2.86 CH4 - CO2(g) -0.90 -2.37 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.04 -5.30 -3.26 N2 - NH3(g) -7.77 -6.00 1.77 NH3 - O2(g) -70.26 -73.22 -2.96 O2 - -Reaction step 11. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 5.000e-01 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 0.5515 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.55 2.850e-01 0.000e+00 2.621e-01 2.621e-01 -CO2(g) -0.60 2.484e-01 0.000e+00 2.284e-01 2.284e-01 -N2(g) -1.74 1.809e-02 0.000e+00 1.663e-02 1.663e-02 -NH3(g) -7.62 2.373e-08 0.000e+00 2.183e-08 2.183e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 1.554e-02 1.555e-02 - Ca 2.501e-03 2.502e-03 - N 1.731e-03 1.732e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.201 Charge balance - pe = -2.986 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 8.940e-03 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 6.713e-03 - Total CO2 (mol/kg) = 1.515e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 10 - Total H = 1.110691e+02 - Total O = 5.556400e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.859e-07 6.290e-07 -6.164 -6.201 -0.038 - OH- 1.758e-08 1.591e-08 -7.755 -7.798 -0.043 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -C(-4) 3.926e-04 - CH4 3.926e-04 3.934e-04 -3.406 -3.405 0.001 -C(4) 1.515e-02 - CO2 8.439e-03 8.457e-03 -2.074 -2.073 0.001 - HCO3- 6.573e-03 5.978e-03 -2.182 -2.223 -0.041 - CaHCO3+ 1.355e-04 1.233e-04 -3.868 -3.909 -0.041 - CaCO3 1.208e-06 1.210e-06 -5.918 -5.917 0.001 - CO3-2 6.516e-07 4.457e-07 -6.186 -6.351 -0.165 -Ca 2.501e-03 - Ca+2 2.364e-03 1.616e-03 -2.626 -2.792 -0.165 - CaHCO3+ 1.355e-04 1.233e-04 -3.868 -3.909 -0.041 - CaCO3 1.208e-06 1.210e-06 -5.918 -5.917 0.001 - CaOH+ 4.702e-10 4.262e-10 -9.328 -9.370 -0.043 -H(0) 5.241e-10 - H2 2.620e-10 2.626e-10 -9.582 -9.581 0.001 -N(-3) 1.711e-03 - NH4+ 1.710e-03 1.543e-03 -2.767 -2.812 -0.045 - NH3 1.395e-06 1.398e-06 -5.856 -5.855 0.001 -N(0) 1.984e-05 - N2 9.920e-06 9.940e-06 -5.004 -5.003 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.580 -61.624 -0.044 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.719 -83.764 -0.044 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.220 -73.219 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.81 -9.14 -8.34 CaCO3 - Calcite -0.66 -9.14 -8.48 CaCO3 - CH4(g) -0.55 -3.41 -2.86 CH4 - CO2(g) -0.60 -2.07 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.74 -5.00 -3.26 N2 - NH3(g) -7.62 -5.85 1.77 NH3 - O2(g) -70.26 -73.22 -2.96 O2 - -Reaction step 12. - -Using solution 1. Solution after simulation 1. -Using gas phase 1. Fixed volume gas phase -Using reaction 1. - -Reaction 1. Irreversible reaction defined in simulation 3. - - 1.000e+00 moles of the following reaction have been added: - - Relative - Reactant moles - - CH2O(NH3)0.07 1.00 - - Relative - Element moles - C 1.00 - H 2.21 - N 0.07 - O 1.00 - ------------------------------------Gas phase----------------------------------- - - -Total pressure: 1.1013 atmospheres - Gas volume: 2.25e+01 liters - - Moles in gas - ---------------------------------- -Component log P P Initial Final Delta -CH4(g) -0.24 5.698e-01 0.000e+00 5.241e-01 5.241e-01 -CO2(g) -0.31 4.954e-01 0.000e+00 4.556e-01 4.556e-01 -N2(g) -1.44 3.599e-02 0.000e+00 3.310e-02 3.310e-02 -NH3(g) -7.47 3.351e-08 0.000e+00 3.081e-08 3.081e-08 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - C 2.636e-02 2.638e-02 - Ca 2.500e-03 2.502e-03 - N 3.796e-03 3.799e-03 - -----------------------------Description of solution---------------------------- - - pH = 6.014 Charge balance - pe = -2.799 Adjusted to redox equilibrium - Activity of water = 0.999 - Ionic strength = 1.092e-02 - Mass of water (kg) = 1.001e+00 - Total alkalinity (eq/kg) = 8.756e-03 - Total CO2 (mol/kg) = 2.558e-02 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.075e-10 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 13 - Total H = 1.111262e+02 - Total O = 5.560960e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.064e-06 9.687e-07 -5.973 -6.014 -0.041 - OH- 1.152e-08 1.033e-08 -7.938 -7.986 -0.048 - H2O 5.551e+01 9.994e-01 1.744 -0.000 0.000 -C(-4) 7.846e-04 - CH4 7.846e-04 7.866e-04 -3.105 -3.104 0.001 -C(4) 2.558e-02 - CO2 1.683e-02 1.687e-02 -1.774 -1.773 0.001 - HCO3- 8.584e-03 7.741e-03 -2.066 -2.111 -0.045 - CaHCO3+ 1.687e-04 1.521e-04 -3.773 -3.818 -0.045 - CaCO3 9.672e-07 9.696e-07 -6.014 -6.013 0.001 - CO3-2 5.667e-07 3.748e-07 -6.247 -6.426 -0.180 -Ca 2.500e-03 - Ca+2 2.330e-03 1.540e-03 -2.633 -2.812 -0.180 - CaHCO3+ 1.687e-04 1.521e-04 -3.773 -3.818 -0.045 - CaCO3 9.672e-07 9.696e-07 -6.014 -6.013 0.001 - CaOH+ 2.935e-10 2.637e-10 -9.532 -9.579 -0.047 -H(0) 5.241e-10 - H2 2.621e-10 2.627e-10 -9.582 -9.581 0.001 -N(-3) 3.756e-03 - NH4+ 3.754e-03 3.354e-03 -2.425 -2.474 -0.049 - NH3 1.968e-06 1.973e-06 -5.706 -5.705 0.001 -N(0) 3.946e-05 - N2 1.973e-05 1.978e-05 -4.705 -4.704 0.001 -N(3) 0.000e+00 - NO2- 0.000e+00 0.000e+00 -61.615 -61.663 -0.048 -N(5) 0.000e+00 - NO3- 0.000e+00 0.000e+00 -83.754 -83.802 -0.048 -O(0) 0.000e+00 - O2 0.000e+00 0.000e+00 -73.221 -73.219 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Aragonite -0.90 -9.24 -8.34 CaCO3 - Calcite -0.76 -9.24 -8.48 CaCO3 - CH4(g) -0.24 -3.10 -2.86 CH4 - CO2(g) -0.31 -1.77 -1.47 CO2 - H2(g) -6.43 -9.58 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -1.44 -4.70 -3.26 N2 - NH3(g) -7.47 -5.70 1.77 NH3 - O2(g) -70.26 -73.22 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex7.sel b/Sun/examples/ex7.sel deleted file mode 100644 index e4582478..00000000 --- a/Sun/examples/ex7.sel +++ /dev/null @@ -1,27 +0,0 @@ - sim state reaction si_CO2(g) si_CH4(g) si_N2(g) si_NH3(g) pressure total mol volume g_CO2(g) g_CH4(g) g_N2(g) g_NH3(g) - 1 i_soln -99 -999.9990 -999.9990 -999.9990 -999.9990 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 - 1 react -99 -1.5000 -26.2591 -999.9990 -999.9990 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 - 2 react 1.0000e-03 -1.3544 -0.4402 -3.8961 -8.3809 1.1000e+00 1.0000e-25 2.2242e-24 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 - 2 react 2.0000e-03 -1.2453 -0.1392 -3.6436 -8.1826 1.1000e+00 1.0000e-25 2.2242e-24 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 - 2 react 3.0000e-03 -1.1592 0.0130 -3.5015 -8.0869 1.1000e+00 8.5793e-05 1.9082e-03 5.4061e-06 8.0362e-05 2.4578e-08 6.3856e-13 - 2 react 4.0000e-03 -1.0929 0.0081 -3.3212 -8.0234 1.1000e+00 6.4416e-04 1.4327e-02 4.7279e-05 5.9660e-04 2.7953e-07 5.5492e-12 - 2 react 8.0000e-03 -0.9101 -0.0107 -2.9007 -7.8887 1.1000e+00 2.9972e-03 6.6664e-02 3.3511e-04 2.6587e-03 3.4247e-06 3.5204e-11 - 2 react 1.6000e-02 -0.7156 -0.0438 -2.4738 -7.7606 1.1000e+00 8.2421e-03 1.8332e-01 1.4423e-03 6.7746e-03 2.5169e-05 1.3002e-10 - 2 react 3.2000e-02 -0.5438 -0.0941 -2.0462 -7.6302 1.1000e+00 2.0521e-02 4.5644e-01 5.3332e-03 1.5021e-02 1.6775e-04 4.3718e-10 - 2 react 6.4000e-02 -0.4248 -0.1517 -1.7252 -7.5359 1.1000e+00 4.9404e-02 1.0988e+00 1.6888e-02 3.1671e-02 8.4558e-04 1.3075e-09 - 2 react 1.2500e-01 -0.3613 -0.1954 -1.5662 -7.4966 1.1000e+00 1.0982e-01 2.4427e+00 4.3447e-02 6.3666e-02 2.7111e-03 3.1820e-09 - 2 react 2.5000e-01 -0.3288 -0.2227 -1.4927 -7.4823 1.1000e+00 2.3770e-01 5.2868e+00 1.0135e-01 1.2940e-01 6.9491e-03 7.1171e-09 - 2 react 5.0000e-01 -0.3131 -0.2373 -1.4597 -7.4772 1.1000e+00 4.9570e-01 1.1025e+01 2.1912e-01 2.6094e-01 1.5635e-02 1.5019e-08 - 2 react 1.0000e+00 -0.3055 -0.2448 -1.4443 -7.4751 1.1000e+00 1.0128e+00 2.2527e+01 4.5565e-01 5.2406e-01 3.3103e-02 3.0832e-08 - 3 react 1.0000e-03 -2.7554 -3.2432 -4.4230 -9.1701 2.3652e-03 2.1751e-03 2.2500e+01 1.6151e-03 5.2527e-04 3.4720e-05 6.2162e-10 - 3 react 2.0000e-03 -2.6525 -2.9422 -4.1221 -8.9453 3.4435e-03 3.1668e-03 2.2500e+01 2.0468e-03 1.0505e-03 6.9421e-05 1.0430e-09 - 3 react 3.0000e-03 -2.5681 -2.7661 -3.9462 -8.8230 4.5301e-03 4.1661e-03 2.2500e+01 2.4862e-03 1.5758e-03 1.0409e-04 1.3823e-09 - 3 react 4.0000e-03 -2.4967 -2.6412 -3.8215 -8.7406 5.6217e-03 5.1699e-03 2.2500e+01 2.9303e-03 2.1010e-03 1.3872e-04 1.6713e-09 - 3 react 8.0000e-03 -2.2889 -2.3402 -3.5212 -8.5555 1.0011e-02 9.2068e-03 2.2500e+01 4.7283e-03 4.2016e-03 2.7697e-04 2.5595e-09 - 3 react 1.6000e-02 -2.0415 -2.0392 -3.2214 -8.3855 1.8825e-02 1.7312e-02 2.2500e+01 8.3576e-03 8.4019e-03 5.5233e-04 3.7856e-09 - 3 react 3.2000e-02 -1.7694 -1.7383 -2.9223 -8.2251 3.6471e-02 3.3540e-02 2.2500e+01 1.5640e-02 1.6800e-02 1.0998e-03 5.4762e-09 - 3 react 6.4000e-02 -1.4834 -1.4374 -2.6240 -8.0704 7.1755e-02 6.5989e-02 2.2500e+01 3.0213e-02 3.3590e-02 2.1859e-03 7.8205e-09 - 3 react 1.2500e-01 -1.2004 -1.1468 -2.3367 -7.9240 1.3896e-01 1.2779e-01 2.2500e+01 5.7976e-02 6.5580e-02 4.2353e-03 1.0956e-08 - 3 react 2.5000e-01 -0.9036 -0.8460 -2.0399 -7.7740 2.7653e-01 2.5431e-01 2.2500e+01 1.1482e-01 1.3110e-01 8.3897e-03 1.5474e-08 - 3 react 5.0000e-01 -0.6049 -0.5452 -1.7426 -7.6246 5.5147e-01 5.0716e-01 2.2500e+01 2.2843e-01 2.6209e-01 1.6634e-02 2.1827e-08 - 3 react 1.0000e+00 -0.3050 -0.2442 -1.4438 -7.4749 1.1013e+00 1.0128e+00 2.2500e+01 4.5563e-01 5.2406e-01 3.3101e-02 3.0813e-08 diff --git a/Sun/examples/ex8.log b/Sun/examples/ex8.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex8.out b/Sun/examples/ex8.out deleted file mode 100644 index 5afdec15..00000000 --- a/Sun/examples/ex8.out +++ /dev/null @@ -1,3612 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex8 - Output file: ex8.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 8.--Sorption of zinc on hydrous - iron oxides. - SURFACE_SPECIES - Hfo_sOH + H+ = Hfo_sOH2+ - log_k 7.18 - Hfo_sOH = Hfo_sO- + H+ - log_k -8.82 - Hfo_sOH + Zn+2 = Hfo_sOZn+ + H+ - log_k 0.66 - Hfo_wOH + H+ = Hfo_wOH2+ - log_k 7.18 - Hfo_wOH = Hfo_wO- + H+ - log_k -8.82 - Hfo_wOH + Zn+2 = Hfo_wOZn+ + H+ - log_k -2.32 - SURFACE 1 - Hfo_sOH 5e-6 600. 0.09 - Hfo_wOH 2e-4 - SOLUTION 1 - units mmol/kgw - pH 8.0 - Zn 0.0001 - Na 100. charge - N(5) 100. - SOLUTION 2 - units mmol/kgw - pH 8.0 - Zn 0.1 - Na 100. charge - N(5) 100. - USE solution none - PHASES - Fix_H+ - H+ = H+ - log_k 0.0 - END ------ -TITLE ------ - - Example 8.--Sorption of zinc on hydrous - iron oxides. - -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N(5) 1.000e-01 1.000e-01 - Na 1.000e-01 1.000e-01 Charge balance - Zn 1.000e-07 1.000e-07 - -----------------------------Description of solution---------------------------- - - pH = 8.000 - pe = 4.000 - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.361e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.936e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 9 - Total H = 1.110124e+02 - Total O = 5.580622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 - H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 1.384e-27 - H2 6.918e-28 7.079e-28 -27.160 -27.150 0.010 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 1.000e-01 - Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 - NaOH 5.038e-08 5.155e-08 -7.298 -7.288 0.010 -O(0) 1.615e-38 - O2 8.073e-39 8.261e-39 -38.093 -38.083 0.010 -Zn 1.000e-07 - Zn+2 9.102e-08 3.428e-08 -7.041 -7.465 -0.424 - ZnOH+ 4.793e-09 3.746e-09 -8.319 -8.426 -0.107 - Zn(OH)2 4.189e-09 4.286e-09 -8.378 -8.368 0.010 - Zn(OH)3- 1.729e-12 1.351e-12 -11.762 -11.869 -0.107 - Zn(OH)4-2 5.721e-17 2.134e-17 -16.243 -16.671 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -8.00 -8.00 0.00 H+ - H2(g) -24.00 -27.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -35.12 -38.08 -2.96 O2 - Zn(OH)2(e) -2.97 8.53 11.50 Zn(OH)2 - -Initial solution 2. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N(5) 1.000e-01 1.000e-01 - Na 9.981e-02 9.981e-02 Charge balance - Zn 1.000e-04 1.000e-04 - -----------------------------Description of solution---------------------------- - - pH = 8.000 - pe = 4.000 - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.452e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 7.433e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 9 - Total H = 1.110124e+02 - Total O = 5.580623e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 - H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 1.384e-27 - H2 6.918e-28 7.079e-28 -27.160 -27.150 0.010 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.981e-02 - Na+ 9.981e-02 7.814e-02 -1.001 -1.107 -0.106 - NaOH 5.028e-08 5.145e-08 -7.299 -7.289 0.010 -O(0) 1.615e-38 - O2 8.073e-39 8.261e-39 -38.093 -38.083 0.010 -Zn 1.000e-04 - Zn+2 9.102e-05 3.427e-05 -4.041 -4.465 -0.424 - ZnOH+ 4.792e-06 3.745e-06 -5.319 -5.427 -0.107 - Zn(OH)2 4.187e-06 4.285e-06 -5.378 -5.368 0.010 - Zn(OH)3- 1.728e-09 1.350e-09 -8.762 -8.870 -0.107 - Zn(OH)4-2 5.721e-14 2.133e-14 -13.243 -13.671 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -8.00 -8.00 0.00 H+ - H2(g) -24.00 -27.15 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - O2(g) -35.12 -38.08 -2.96 O2 - Zn(OH)2(e) 0.03 11.53 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SELECTED_OUTPUT - file ex8.sel - molalities Zn+2 Hfo_wOZn+ Hfo_sOZn+ - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.00 -5.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.273e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 1.123e-04 Surface charge, eq - 2.007e-01 sigma, C/m**2 - 1.228e-01 psi, V - -4.778e+00 -F*psi/RT - 8.410e-03 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH2+ 2.778e-06 0.556 2.778e-06 -5.556 - Hfo_sOH 2.182e-06 0.436 2.182e-06 -5.661 - Hfo_sO- 3.928e-08 0.008 3.928e-08 -7.406 - Hfo_sOZn+ 3.150e-10 0.000 3.150e-10 -9.502 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH2+ 1.111e-04 0.556 1.111e-04 -3.954 - Hfo_wOH 8.730e-05 0.437 8.730e-05 -4.059 - Hfo_wO- 1.571e-06 0.008 1.571e-06 -5.804 - Hfo_wOZn+ 1.319e-11 0.000 1.319e-11 -10.880 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.987e-02 9.987e-02 - Zn 9.967e-08 9.967e-08 - -----------------------------Description of solution---------------------------- - - pH = 5.000 Charge balance - pe = 15.095 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.994e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.211e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.123e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.06 - Iterations = 17 - Total H = 1.110122e+02 - Total O = 5.580609e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.211e-05 1.000e-05 -4.917 -5.000 -0.083 - OH- 1.309e-09 9.977e-10 -8.883 -9.001 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.349 -43.339 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -52.670 -52.798 -0.128 - NH3 0.000e+00 0.000e+00 -57.052 -57.042 0.010 -N(0) 1.543e-06 - N2 7.717e-07 7.897e-07 -6.113 -6.103 0.010 -N(3) 2.412e-13 - NO2- 2.412e-13 1.818e-13 -12.618 -12.740 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.987e-02 - Na+ 9.987e-02 7.819e-02 -1.001 -1.107 -0.106 - NaOH 5.032e-11 5.149e-11 -10.298 -10.288 0.010 -O(0) 3.859e-06 - O2 1.929e-06 1.974e-06 -5.715 -5.705 0.010 -Zn 9.967e-08 - Zn+2 9.967e-08 3.754e-08 -7.001 -7.425 -0.424 - ZnOH+ 5.250e-12 4.103e-12 -11.280 -11.387 -0.107 - Zn(OH)2 4.588e-15 4.695e-15 -14.338 -14.328 0.010 - Zn(OH)3- 1.893e-21 1.479e-21 -20.723 -20.830 -0.107 - Zn(OH)4-2 6.265e-29 2.337e-29 -28.203 -28.631 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.00 -5.00 0.00 H+ - H2(g) -40.19 -43.34 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.84 -6.10 -3.26 N2 - NH3(g) -58.81 -57.04 1.77 NH3 - O2(g) -2.74 -5.70 -2.96 O2 - Zn(OH)2(e) -8.93 2.57 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.25 -5.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.060e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 9.671e-05 Surface charge, eq - 1.728e-01 sigma, C/m**2 - 1.152e-01 psi, V - -4.485e+00 -F*psi/RT - 1.127e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 2.520e-06 0.504 2.520e-06 -5.599 - Hfo_sOH2+ 2.419e-06 0.484 2.419e-06 -5.616 - Hfo_sO- 6.017e-08 0.012 6.017e-08 -7.221 - Hfo_sOZn+ 8.622e-10 0.000 8.622e-10 -9.064 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.008e-04 0.504 1.008e-04 -3.996 - Hfo_wOH2+ 9.676e-05 0.484 9.676e-05 -4.014 - Hfo_wO- 2.407e-06 0.012 2.407e-06 -5.618 - Hfo_wOZn+ 3.612e-11 0.000 3.612e-11 -10.442 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.990e-02 9.990e-02 - Zn 9.910e-08 9.910e-08 - -----------------------------Description of solution---------------------------- - - pH = 5.250 Charge balance - pe = 14.809 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.995e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.809e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -9.671e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 17 - Total H = 1.110122e+02 - Total O = 5.580611e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.812e-06 5.623e-06 -5.167 -5.250 -0.083 - OH- 2.329e-09 1.774e-09 -8.633 -8.751 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.278 -43.268 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -52.884 -53.012 -0.128 - NH3 0.000e+00 0.000e+00 -57.017 -57.007 0.010 -N(0) 1.111e-06 - N2 5.554e-07 5.683e-07 -6.255 -6.245 0.010 -N(3) 2.843e-13 - NO2- 2.843e-13 2.143e-13 -12.546 -12.669 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.990e-02 - Na+ 9.990e-02 7.821e-02 -1.000 -1.107 -0.106 - NaOH 8.949e-11 9.158e-11 -10.048 -10.038 0.010 -O(0) 2.777e-06 - O2 1.388e-06 1.421e-06 -5.857 -5.847 0.010 -Zn 9.910e-08 - Zn+2 9.909e-08 3.733e-08 -7.004 -7.428 -0.424 - ZnOH+ 9.281e-12 7.254e-12 -11.032 -11.139 -0.107 - Zn(OH)2 1.442e-14 1.476e-14 -13.841 -13.831 0.010 - Zn(OH)3- 1.058e-20 8.272e-21 -19.975 -20.082 -0.107 - Zn(OH)4-2 6.228e-28 2.323e-28 -27.206 -27.634 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.25 -5.25 0.00 H+ - H2(g) -40.12 -43.27 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.99 -6.25 -3.26 N2 - NH3(g) -58.78 -57.01 1.77 NH3 - O2(g) -2.89 -5.85 -2.96 O2 - Zn(OH)2(e) -8.43 3.07 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 4. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.50 -5.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 8.815e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 8.217e-05 Surface charge, eq - 1.468e-01 sigma, C/m**2 - 1.071e-01 psi, V - -4.168e+00 -F*psi/RT - 1.549e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 2.820e-06 0.564 2.820e-06 -5.550 - Hfo_sOH2+ 2.090e-06 0.418 2.090e-06 -5.680 - Hfo_sO- 8.716e-08 0.017 8.716e-08 -7.060 - Hfo_sOZn+ 2.320e-09 0.000 2.320e-09 -8.635 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.129e-04 0.564 1.129e-04 -3.947 - Hfo_wOH2+ 8.365e-05 0.418 8.365e-05 -4.078 - Hfo_wO- 3.488e-06 0.017 3.488e-06 -5.457 - Hfo_wOZn+ 9.722e-11 0.000 9.722e-11 -10.012 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.991e-02 9.991e-02 - Zn 9.758e-08 9.758e-08 - -----------------------------Description of solution---------------------------- - - pH = 5.500 Charge balance - pe = 14.523 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.996e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.826e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -8.217e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.04 - Iterations = 16 - Total H = 1.110123e+02 - Total O = 5.580613e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.830e-06 3.162e-06 -5.417 -5.500 -0.083 - OH- 4.141e-09 3.155e-09 -8.383 -8.501 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.206 -43.196 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.099 -53.227 -0.128 - NH3 0.000e+00 0.000e+00 -56.981 -56.971 0.010 -N(0) 7.994e-07 - N2 3.997e-07 4.090e-07 -6.398 -6.388 0.010 -N(3) 3.351e-13 - NO2- 3.351e-13 2.526e-13 -12.475 -12.598 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.991e-02 - Na+ 9.991e-02 7.822e-02 -1.000 -1.107 -0.106 - NaOH 1.592e-10 1.629e-10 -9.798 -9.788 0.010 -O(0) 1.998e-06 - O2 9.992e-07 1.023e-06 -6.000 -5.990 0.010 -Zn 9.758e-08 - Zn+2 9.757e-08 3.675e-08 -7.011 -7.435 -0.424 - ZnOH+ 1.625e-11 1.270e-11 -10.789 -10.896 -0.107 - Zn(OH)2 4.491e-14 4.595e-14 -13.348 -13.338 0.010 - Zn(OH)3- 5.860e-20 4.580e-20 -19.232 -19.339 -0.107 - Zn(OH)4-2 6.133e-27 2.288e-27 -26.212 -26.641 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.50 -5.50 0.00 H+ - H2(g) -40.05 -43.20 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.13 -6.39 -3.26 N2 - NH3(g) -58.74 -56.97 1.77 NH3 - O2(g) -3.03 -5.99 -2.96 O2 - Zn(OH)2(e) -7.94 3.56 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 5. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.75 -5.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 7.298e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 6.891e-05 Surface charge, eq - 1.231e-01 sigma, C/m**2 - 9.836e-02 psi, V - -3.829e+00 -F*psi/RT - 2.174e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.075e-06 0.615 3.075e-06 -5.512 - Hfo_sOH2+ 1.799e-06 0.360 1.799e-06 -5.745 - Hfo_sO- 1.204e-07 0.024 1.204e-07 -6.919 - Hfo_sOZn+ 6.061e-09 0.001 6.061e-09 -8.217 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.231e-04 0.616 1.231e-04 -3.910 - Hfo_wOH2+ 7.205e-05 0.360 7.205e-05 -4.142 - Hfo_wO- 4.821e-06 0.024 4.821e-06 -5.317 - Hfo_wOZn+ 2.542e-10 0.000 2.542e-10 -9.595 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.993e-02 9.993e-02 - Zn 9.368e-08 9.368e-08 - -----------------------------Description of solution---------------------------- - - pH = 5.750 Charge balance - pe = 14.237 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.997e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -2.146e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.891e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 - Iterations = 15 - Total H = 1.110123e+02 - Total O = 5.580615e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.154e-06 1.778e-06 -5.667 -5.750 -0.083 - OH- 7.364e-09 5.610e-09 -8.133 -8.251 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.135 -43.125 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.313 -53.441 -0.128 - NH3 0.000e+00 0.000e+00 -56.945 -56.935 0.010 -N(0) 5.753e-07 - N2 2.877e-07 2.944e-07 -6.541 -6.531 0.010 -N(3) 3.950e-13 - NO2- 3.950e-13 2.977e-13 -12.403 -12.526 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.993e-02 - Na+ 9.993e-02 7.824e-02 -1.000 -1.107 -0.106 - NaOH 2.831e-10 2.897e-10 -9.548 -9.538 0.010 -O(0) 1.438e-06 - O2 7.191e-07 7.359e-07 -6.143 -6.133 0.010 -Zn 9.368e-08 - Zn+2 9.366e-08 3.528e-08 -7.028 -7.452 -0.424 - ZnOH+ 2.774e-11 2.168e-11 -10.557 -10.664 -0.107 - Zn(OH)2 1.363e-13 1.395e-13 -12.865 -12.855 0.010 - Zn(OH)3- 3.163e-19 2.472e-19 -18.500 -18.607 -0.107 - Zn(OH)4-2 5.887e-26 2.196e-26 -25.230 -25.658 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.75 -5.75 0.00 H+ - H2(g) -39.97 -43.12 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.27 -6.53 -3.26 N2 - NH3(g) -58.71 -56.94 1.77 NH3 - O2(g) -3.17 -6.13 -2.96 O2 - Zn(OH)2(e) -7.46 4.04 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 6. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.00 -6.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 5.997e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 5.703e-05 Surface charge, eq - 1.019e-01 sigma, C/m**2 - 8.913e-02 psi, V - -3.469e+00 -F*psi/RT - 3.114e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.280e-06 0.656 3.280e-06 -5.484 - Hfo_sOH2+ 1.546e-06 0.309 1.546e-06 -5.811 - Hfo_sO- 1.594e-07 0.032 1.594e-07 -6.797 - Hfo_sOZn+ 1.486e-08 0.003 1.486e-08 -7.828 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.316e-04 0.658 1.316e-04 -3.881 - Hfo_wOH2+ 6.202e-05 0.310 6.202e-05 -4.207 - Hfo_wO- 6.395e-06 0.032 6.395e-06 -5.194 - Hfo_wOZn+ 6.241e-10 0.000 6.241e-10 -9.205 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.994e-02 9.994e-02 - Zn 8.452e-08 8.452e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.000 Charge balance - pe = 13.952 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.997e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.198e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.703e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 - Iterations = 15 - Total H = 1.110123e+02 - Total O = 5.580616e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.211e-06 1.000e-06 -5.917 -6.000 -0.083 - OH- 1.310e-08 9.977e-09 -7.883 -8.001 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.063 -43.053 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.527 -53.655 -0.128 - NH3 0.000e+00 0.000e+00 -56.909 -56.899 0.010 -N(0) 4.140e-07 - N2 2.070e-07 2.118e-07 -6.684 -6.674 0.010 -N(3) 4.656e-13 - NO2- 4.656e-13 3.509e-13 -12.332 -12.455 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.994e-02 - Na+ 9.994e-02 7.824e-02 -1.000 -1.107 -0.106 - NaOH 5.035e-10 5.152e-10 -9.298 -9.288 0.010 -O(0) 1.035e-06 - O2 5.176e-07 5.296e-07 -6.286 -6.276 0.010 -Zn 8.452e-08 - Zn+2 8.448e-08 3.182e-08 -7.073 -7.497 -0.424 - ZnOH+ 4.449e-11 3.477e-11 -10.352 -10.459 -0.107 - Zn(OH)2 3.888e-13 3.979e-13 -12.410 -12.400 0.010 - Zn(OH)3- 1.604e-18 1.254e-18 -17.795 -17.902 -0.107 - Zn(OH)4-2 5.310e-25 1.981e-25 -24.275 -24.703 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.00 -6.00 0.00 H+ - H2(g) -39.90 -43.05 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.41 -6.67 -3.26 N2 - NH3(g) -58.67 -56.90 1.77 NH3 - O2(g) -3.32 -6.28 -2.96 O2 - Zn(OH)2(e) -7.00 4.50 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 7. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.25 -6.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 4.875e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 4.650e-05 Surface charge, eq - 8.309e-02 sigma, C/m**2 - 7.940e-02 psi, V - -3.091e+00 -F*psi/RT - 4.547e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.435e-06 0.687 3.435e-06 -5.464 - Hfo_sOH2+ 1.330e-06 0.266 1.330e-06 -5.876 - Hfo_sO- 2.033e-07 0.041 2.033e-07 -6.692 - Hfo_sOZn+ 3.190e-08 0.006 3.190e-08 -7.496 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.383e-04 0.691 1.383e-04 -3.859 - Hfo_wOH2+ 5.352e-05 0.268 5.352e-05 -4.271 - Hfo_wO- 8.186e-06 0.041 8.186e-06 -5.087 - Hfo_wOZn+ 1.345e-09 0.000 1.345e-09 -8.871 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.995e-02 9.995e-02 - Zn 6.676e-08 6.676e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.250 Charge balance - pe = 13.666 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.998e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.569e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -4.650e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 14 - Total H = 1.110123e+02 - Total O = 5.580617e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.812e-07 5.623e-07 -6.167 -6.250 -0.083 - OH- 2.329e-08 1.774e-08 -7.633 -7.751 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.992 -42.982 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.742 -53.869 -0.128 - NH3 0.000e+00 0.000e+00 -56.874 -56.864 0.010 -N(0) 2.980e-07 - N2 1.490e-07 1.525e-07 -6.827 -6.817 0.010 -N(3) 5.488e-13 - NO2- 5.488e-13 4.137e-13 -12.261 -12.383 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.995e-02 - Na+ 9.995e-02 7.825e-02 -1.000 -1.106 -0.106 - NaOH 8.954e-10 9.163e-10 -9.048 -9.038 0.010 -O(0) 7.449e-07 - O2 3.725e-07 3.811e-07 -6.429 -6.419 0.010 -Zn 6.676e-08 - Zn+2 6.670e-08 2.512e-08 -7.176 -7.600 -0.424 - ZnOH+ 6.247e-11 4.882e-11 -10.204 -10.311 -0.107 - Zn(OH)2 9.707e-13 9.933e-13 -12.013 -12.003 0.010 - Zn(OH)3- 7.123e-18 5.567e-18 -17.147 -17.254 -0.107 - Zn(OH)4-2 4.192e-24 1.564e-24 -23.378 -23.806 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.25 -6.25 0.00 H+ - H2(g) -39.83 -42.98 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.56 -6.82 -3.26 N2 - NH3(g) -58.63 -56.86 1.77 NH3 - O2(g) -3.46 -6.42 -2.96 O2 - Zn(OH)2(e) -6.60 4.90 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 8. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.50 -6.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 3.904e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 3.724e-05 Surface charge, eq - 6.654e-02 sigma, C/m**2 - 6.920e-02 psi, V - -2.694e+00 -F*psi/RT - 6.764e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.546e-06 0.709 3.546e-06 -5.450 - Hfo_sOH2+ 1.148e-06 0.230 1.148e-06 -5.940 - Hfo_sO- 2.509e-07 0.050 2.509e-07 -6.600 - Hfo_sOZn+ 5.526e-08 0.011 5.526e-08 -7.258 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.434e-04 0.717 1.434e-04 -3.843 - Hfo_wOH2+ 4.643e-05 0.232 4.643e-05 -4.333 - Hfo_wO- 1.015e-05 0.051 1.015e-05 -4.994 - Hfo_wOZn+ 2.341e-09 0.000 2.341e-09 -8.631 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.996e-02 9.996e-02 - Zn 4.239e-08 4.239e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.500 Charge balance - pe = 13.380 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.998e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.400e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.724e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580618e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.831e-07 3.162e-07 -6.417 -6.500 -0.083 - OH- 4.141e-08 3.155e-08 -7.383 -7.501 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.921 -42.911 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.956 -54.084 -0.128 - NH3 0.000e+00 0.000e+00 -56.838 -56.828 0.010 -N(0) 2.145e-07 - N2 1.072e-07 1.097e-07 -6.970 -6.960 0.010 -N(3) 6.470e-13 - NO2- 6.470e-13 4.876e-13 -12.189 -12.312 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.996e-02 - Na+ 9.996e-02 7.826e-02 -1.000 -1.106 -0.106 - NaOH 1.592e-09 1.630e-09 -8.798 -8.788 0.010 -O(0) 5.361e-07 - O2 2.681e-07 2.743e-07 -6.572 -6.562 0.010 -Zn 4.239e-08 - Zn+2 4.232e-08 1.594e-08 -7.373 -7.797 -0.424 - ZnOH+ 7.049e-11 5.509e-11 -10.152 -10.259 -0.107 - Zn(OH)2 1.948e-12 1.993e-12 -11.710 -11.700 0.010 - Zn(OH)3- 2.542e-17 1.986e-17 -16.595 -16.702 -0.107 - Zn(OH)4-2 2.660e-23 9.922e-24 -22.575 -23.003 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.50 -6.50 0.00 H+ - H2(g) -39.76 -42.91 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.70 -6.96 -3.26 N2 - NH3(g) -58.60 -56.83 1.77 NH3 - O2(g) -3.60 -6.56 -2.96 O2 - Zn(OH)2(e) -6.30 5.20 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 9. ------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.75 -6.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 3.063e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.913e-05 Surface charge, eq - 5.205e-02 sigma, C/m**2 - 5.854e-02 psi, V - -2.278e+00 -F*psi/RT - 1.024e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.624e-06 0.725 3.624e-06 -5.441 - Hfo_sOH2+ 9.992e-07 0.200 9.992e-07 -6.000 - Hfo_sO- 3.011e-07 0.060 3.011e-07 -6.521 - Hfo_sOZn+ 7.566e-08 0.015 7.566e-08 -7.121 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.472e-04 0.736 1.472e-04 -3.832 - Hfo_wOH2+ 4.058e-05 0.203 4.058e-05 -4.392 - Hfo_wO- 1.223e-05 0.061 1.223e-05 -4.913 - Hfo_wOZn+ 3.218e-09 0.000 3.218e-09 -8.492 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.997e-02 9.997e-02 - Zn 2.112e-08 2.112e-08 - -----------------------------Description of solution---------------------------- - - pH = 6.750 Charge balance - pe = 13.095 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.999e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.389e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.913e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580619e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.154e-07 1.778e-07 -6.667 -6.750 -0.083 - OH- 7.364e-08 5.610e-08 -7.133 -7.251 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.849 -42.839 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.170 -54.298 -0.128 - NH3 0.000e+00 0.000e+00 -56.802 -56.792 0.010 -N(0) 1.543e-07 - N2 7.717e-08 7.897e-08 -7.113 -7.103 0.010 -N(3) 7.626e-13 - NO2- 7.626e-13 5.748e-13 -12.118 -12.240 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.997e-02 - Na+ 9.997e-02 7.827e-02 -1.000 -1.106 -0.106 - NaOH 2.832e-09 2.898e-09 -8.548 -8.538 0.010 -O(0) 3.858e-07 - O2 1.929e-07 1.974e-07 -6.715 -6.705 0.010 -Zn 2.112e-08 - Zn+2 2.105e-08 7.929e-09 -7.677 -8.101 -0.424 - ZnOH+ 6.235e-11 4.872e-11 -10.205 -10.312 -0.107 - Zn(OH)2 3.064e-12 3.135e-12 -11.514 -11.504 0.010 - Zn(OH)3- 7.110e-17 5.556e-17 -16.148 -16.255 -0.107 - Zn(OH)4-2 1.323e-22 4.935e-23 -21.878 -22.307 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.75 -6.75 0.00 H+ - H2(g) -39.69 -42.84 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.84 -7.10 -3.26 N2 - NH3(g) -58.56 -56.79 1.77 NH3 - O2(g) -3.74 -6.70 -2.96 O2 - Zn(OH)2(e) -6.10 5.40 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 10. -------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.00 -7.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 2.330e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.203e-05 Surface charge, eq - 3.936e-02 sigma, C/m**2 - 4.744e-02 psi, V - -1.847e+00 -F*psi/RT - 1.578e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.681e-06 0.736 3.681e-06 -5.434 - Hfo_sOH2+ 8.789e-07 0.176 8.789e-07 -6.056 - Hfo_sO- 3.531e-07 0.071 3.531e-07 -6.452 - Hfo_sOZn+ 8.747e-08 0.017 8.747e-08 -7.058 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.498e-04 0.749 1.498e-04 -3.824 - Hfo_wOH2+ 3.578e-05 0.179 3.578e-05 -4.446 - Hfo_wO- 1.437e-05 0.072 1.437e-05 -4.842 - Hfo_wOZn+ 3.729e-09 0.000 3.729e-09 -8.428 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.998e-02 9.998e-02 - Zn 8.799e-09 8.799e-09 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 12.809 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.999e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.491e-08 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.203e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580619e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-07 9.977e-08 -6.883 -7.001 -0.118 - H+ 1.211e-07 1.000e-07 -6.917 -7.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.778 -42.768 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.384 -54.512 -0.128 - NH3 0.000e+00 0.000e+00 -56.767 -56.757 0.010 -N(0) 1.111e-07 - N2 5.554e-08 5.683e-08 -7.255 -7.245 0.010 -N(3) 8.990e-13 - NO2- 8.990e-13 6.775e-13 -12.046 -12.169 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.998e-02 - Na+ 9.998e-02 7.827e-02 -1.000 -1.106 -0.106 - NaOH 5.037e-09 5.154e-09 -8.298 -8.288 0.010 -O(0) 2.777e-07 - O2 1.388e-07 1.421e-07 -6.857 -6.847 0.010 -Zn 8.799e-09 - Zn+2 8.749e-09 3.295e-09 -8.058 -8.482 -0.424 - ZnOH+ 4.608e-11 3.601e-11 -10.336 -10.444 -0.107 - Zn(OH)2 4.027e-12 4.121e-12 -11.395 -11.385 0.010 - Zn(OH)3- 1.662e-16 1.299e-16 -15.779 -15.887 -0.107 - Zn(OH)4-2 5.499e-22 2.051e-22 -21.260 -21.688 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.00 -7.00 0.00 H+ - H2(g) -39.62 -42.77 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.99 -7.25 -3.26 N2 - NH3(g) -58.53 -56.76 1.77 NH3 - O2(g) -3.89 -6.85 -2.96 O2 - Zn(OH)2(e) -5.99 5.51 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 11. -------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.25 -7.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.683e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 1.576e-05 Surface charge, eq - 2.816e-02 sigma, C/m**2 - 3.596e-02 psi, V - -1.400e+00 -F*psi/RT - 2.467e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.720e-06 0.744 3.720e-06 -5.429 - Hfo_sOH2+ 7.810e-07 0.156 7.810e-07 -6.107 - Hfo_sO- 4.060e-07 0.081 4.060e-07 -6.392 - Hfo_sOZn+ 9.271e-08 0.019 9.271e-08 -7.033 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.516e-04 0.758 1.516e-04 -3.819 - Hfo_wOH2+ 3.183e-05 0.159 3.183e-05 -4.497 - Hfo_wO- 1.655e-05 0.083 1.655e-05 -4.781 - Hfo_wOZn+ 3.956e-09 0.000 3.956e-09 -8.403 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.998e-02 9.998e-02 - Zn 3.336e-09 3.336e-09 - -----------------------------Description of solution---------------------------- - - pH = 7.250 Charge balance - pe = 12.523 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 9.999e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.738e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.576e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580620e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.329e-07 1.774e-07 -6.633 -6.751 -0.118 - H+ 6.812e-08 5.623e-08 -7.167 -7.250 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.706 -42.696 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.599 -54.727 -0.128 - NH3 0.000e+00 0.000e+00 -56.731 -56.721 0.010 -N(0) 7.994e-08 - N2 3.997e-08 4.090e-08 -7.398 -7.388 0.010 -N(3) 1.060e-12 - NO2- 1.060e-12 7.987e-13 -11.975 -12.098 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.998e-02 - Na+ 9.998e-02 7.828e-02 -1.000 -1.106 -0.106 - NaOH 8.957e-09 9.166e-09 -8.048 -8.038 0.010 -O(0) 1.998e-07 - O2 9.992e-08 1.022e-07 -7.000 -6.990 0.010 -Zn 3.336e-09 - Zn+2 3.300e-09 1.243e-09 -8.481 -8.906 -0.424 - ZnOH+ 3.091e-11 2.415e-11 -10.510 -10.617 -0.107 - Zn(OH)2 4.803e-12 4.915e-12 -11.319 -11.309 0.010 - Zn(OH)3- 3.524e-16 2.754e-16 -15.453 -15.560 -0.107 - Zn(OH)4-2 2.074e-21 7.736e-22 -20.683 -21.111 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.25 -7.25 0.00 H+ - H2(g) -39.55 -42.70 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.13 -7.39 -3.26 N2 - NH3(g) -58.49 -56.72 1.77 NH3 - O2(g) -4.03 -6.99 -2.96 O2 - Zn(OH)2(e) -5.91 5.59 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 12. -------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.50 -7.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.097e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 1.014e-05 Surface charge, eq - 1.812e-02 sigma, C/m**2 - 2.417e-02 psi, V - -9.409e-01 -F*psi/RT - 3.903e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.746e-06 0.749 3.746e-06 -5.426 - Hfo_sOH2+ 6.998e-07 0.140 6.998e-07 -6.155 - Hfo_sO- 4.594e-07 0.092 4.594e-07 -6.338 - Hfo_sOZn+ 9.474e-08 0.019 9.474e-08 -7.023 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.527e-04 0.764 1.527e-04 -3.816 - Hfo_wOH2+ 2.853e-05 0.143 2.853e-05 -4.545 - Hfo_wO- 1.873e-05 0.094 1.873e-05 -4.727 - Hfo_wOZn+ 4.045e-09 0.000 4.045e-09 -8.393 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.999e-02 9.999e-02 - Zn 1.216e-09 1.216e-09 - -----------------------------Description of solution---------------------------- - - pH = 7.500 Charge balance - pe = 12.237 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.918e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.014e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580621e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.141e-07 3.155e-07 -6.383 -6.501 -0.118 - H+ 3.831e-08 3.162e-08 -7.417 -7.500 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.635 -42.625 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.813 -54.941 -0.128 - NH3 0.000e+00 0.000e+00 -56.695 -56.685 0.010 -N(0) 5.753e-08 - N2 2.876e-08 2.943e-08 -7.541 -7.531 0.010 -N(3) 1.249e-12 - NO2- 1.249e-12 9.414e-13 -11.903 -12.026 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.999e-02 - Na+ 9.999e-02 7.828e-02 -1.000 -1.106 -0.106 - NaOH 1.593e-08 1.630e-08 -7.798 -7.788 0.010 -O(0) 1.438e-07 - O2 7.191e-08 7.359e-08 -7.143 -7.133 0.010 -Zn 1.216e-09 - Zn+2 1.190e-09 4.483e-10 -8.924 -9.348 -0.424 - ZnOH+ 1.982e-11 1.549e-11 -10.703 -10.810 -0.107 - Zn(OH)2 5.478e-12 5.606e-12 -11.261 -11.251 0.010 - Zn(OH)3- 7.149e-16 5.587e-16 -15.146 -15.253 -0.107 - Zn(OH)4-2 7.481e-21 2.790e-21 -20.126 -20.554 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.50 -7.50 0.00 H+ - H2(g) -39.47 -42.62 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.27 -7.53 -3.26 N2 - NH3(g) -58.46 -56.69 1.77 NH3 - O2(g) -4.17 -7.13 -2.96 O2 - Zn(OH)2(e) -5.85 5.65 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 13. -------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.75 -7.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 5.425e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 4.965e-06 Surface charge, eq - 8.872e-03 sigma, C/m**2 - 1.217e-02 psi, V - -4.735e-01 -F*psi/RT - 6.228e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.760e-06 0.752 3.760e-06 -5.425 - Hfo_sOH2+ 6.303e-07 0.126 6.303e-07 -6.200 - Hfo_sO- 5.139e-07 0.103 5.139e-07 -6.289 - Hfo_sOZn+ 9.548e-08 0.019 9.548e-08 -7.020 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.533e-04 0.767 1.533e-04 -3.814 - Hfo_wOH2+ 2.570e-05 0.129 2.570e-05 -4.590 - Hfo_wO- 2.096e-05 0.105 2.096e-05 -4.679 - Hfo_wOZn+ 4.077e-09 0.000 4.077e-09 -8.390 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 1.000e-01 1.000e-01 - Zn 4.397e-10 4.397e-10 - -----------------------------Description of solution---------------------------- - - pH = 7.750 Charge balance - pe = 11.952 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 7.432e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -4.965e-06 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580621e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.364e-07 5.610e-07 -6.133 -6.251 -0.118 - H+ 2.154e-08 1.778e-08 -7.667 -7.750 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.563 -42.553 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -55.027 -55.155 -0.128 - NH3 0.000e+00 0.000e+00 -56.659 -56.649 0.010 -N(0) 4.140e-08 - N2 2.070e-08 2.118e-08 -7.684 -7.674 0.010 -N(3) 1.472e-12 - NO2- 1.472e-12 1.110e-12 -11.832 -11.955 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 1.000e-01 - Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 - NaOH 2.833e-08 2.899e-08 -7.548 -7.538 0.010 -O(0) 1.035e-07 - O2 5.175e-08 5.296e-08 -7.286 -7.276 0.010 -Zn 4.397e-10 - Zn+2 4.211e-10 1.586e-10 -9.376 -9.800 -0.424 - ZnOH+ 1.247e-11 9.747e-12 -10.904 -11.011 -0.107 - Zn(OH)2 6.129e-12 6.272e-12 -11.213 -11.203 0.010 - Zn(OH)3- 1.422e-15 1.112e-15 -14.847 -14.954 -0.107 - Zn(OH)4-2 2.647e-20 9.873e-21 -19.577 -20.006 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.75 -7.75 0.00 H+ - H2(g) -39.40 -42.55 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.41 -7.67 -3.26 N2 - NH3(g) -58.42 -56.65 1.77 NH3 - O2(g) -4.32 -7.28 -2.96 O2 - Zn(OH)2(e) -5.80 5.70 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 14. -------------------------------------- - - USE solution 1 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -8.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 1. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -8.00 -8.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -1.388e-07 - -------------------------------Surface composition------------------------------ - -Hfo - 1.788e-08 Surface charge, eq - 3.195e-05 sigma, C/m**2 - 4.422e-05 psi, V - -1.721e-03 -F*psi/RT - 9.983e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 3.765e-06 0.753 3.765e-06 -5.424 - Hfo_sO- 5.708e-07 0.114 5.708e-07 -6.244 - Hfo_sOH2+ 5.688e-07 0.114 5.688e-07 -6.245 - Hfo_sOZn+ 9.575e-08 0.019 9.575e-08 -7.019 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.535e-04 0.768 1.535e-04 -3.814 - Hfo_wO- 2.328e-05 0.116 2.328e-05 -4.633 - Hfo_wOH2+ 2.320e-05 0.116 2.320e-05 -4.635 - Hfo_wOZn+ 4.089e-09 0.000 4.089e-09 -8.388 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 1.000e-01 1.000e-01 - Zn 1.626e-10 1.626e-10 - -----------------------------Description of solution---------------------------- - - pH = 8.000 Charge balance - pe = 11.666 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.348e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.788e-08 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 14 - Total H = 1.110124e+02 - Total O = 5.580622e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 - H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.492 -42.482 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -55.242 -55.369 -0.128 - NH3 0.000e+00 0.000e+00 -56.624 -56.614 0.010 -N(0) 2.980e-08 - N2 1.490e-08 1.525e-08 -7.827 -7.817 0.010 -N(3) 1.736e-12 - NO2- 1.736e-12 1.308e-12 -11.761 -11.883 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 1.000e-01 - Na+ 1.000e-01 7.829e-02 -1.000 -1.106 -0.106 - NaOH 5.038e-08 5.155e-08 -7.298 -7.288 0.010 -O(0) 7.449e-08 - O2 3.725e-08 3.811e-08 -7.429 -7.419 0.010 -Zn 1.626e-10 - Zn+2 1.480e-10 5.574e-11 -9.830 -10.254 -0.424 - ZnOH+ 7.794e-12 6.091e-12 -11.108 -11.215 -0.107 - Zn(OH)2 6.811e-12 6.969e-12 -11.167 -11.157 0.010 - Zn(OH)3- 2.811e-15 2.196e-15 -14.551 -14.658 -0.107 - Zn(OH)4-2 9.302e-20 3.469e-20 -19.031 -19.460 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -8.00 -8.00 0.00 H+ - H2(g) -39.33 -42.48 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.56 -7.82 -3.26 N2 - NH3(g) -58.38 -56.61 1.77 NH3 - O2(g) -4.46 -7.42 -2.96 O2 - Zn(OH)2(e) -5.76 5.74 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 15. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.00 -5.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.399e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 1.124e-04 Surface charge, eq - 2.008e-01 sigma, C/m**2 - 1.228e-01 psi, V - -4.779e+00 -F*psi/RT - 8.404e-03 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH2+ 2.613e-06 0.523 2.613e-06 -5.583 - Hfo_sOH 2.054e-06 0.411 2.054e-06 -5.687 - Hfo_sOZn+ 2.962e-07 0.059 2.962e-07 -6.528 - Hfo_sO- 3.700e-08 0.007 3.700e-08 -7.432 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH2+ 1.111e-04 0.555 1.111e-04 -3.954 - Hfo_wOH 8.733e-05 0.437 8.733e-05 -4.059 - Hfo_wO- 1.573e-06 0.008 1.573e-06 -5.803 - Hfo_wOZn+ 1.319e-08 0.000 1.319e-08 -7.880 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.967e-02 9.967e-02 - Zn 9.969e-05 9.969e-05 - -----------------------------Description of solution---------------------------- - - pH = 5.000 Charge balance - pe = 15.095 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.211e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.124e-04 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.06 - Iterations = 21 - Total H = 1.110122e+02 - Total O = 5.580609e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.211e-05 1.000e-05 -4.917 -5.000 -0.083 - OH- 1.310e-09 9.977e-10 -8.883 -9.001 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.349 -43.339 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -52.670 -52.798 -0.128 - NH3 0.000e+00 0.000e+00 -57.052 -57.042 0.010 -N(0) 1.543e-06 - N2 7.716e-07 7.896e-07 -6.113 -6.103 0.010 -N(3) 2.412e-13 - NO2- 2.412e-13 1.818e-13 -12.618 -12.741 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.967e-02 - Na+ 9.967e-02 7.803e-02 -1.001 -1.108 -0.106 - NaOH 5.021e-11 5.138e-11 -10.299 -10.289 0.010 -O(0) 3.858e-06 - O2 1.929e-06 1.974e-06 -5.715 -5.705 0.010 -Zn 9.969e-05 - Zn+2 9.969e-05 3.754e-05 -4.001 -4.426 -0.424 - ZnOH+ 5.249e-09 4.102e-09 -8.280 -8.387 -0.107 - Zn(OH)2 4.587e-12 4.694e-12 -11.338 -11.328 0.010 - Zn(OH)3- 1.893e-18 1.479e-18 -17.723 -17.830 -0.107 - Zn(OH)4-2 6.266e-26 2.337e-26 -25.203 -25.631 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.00 -5.00 0.00 H+ - H2(g) -40.19 -43.34 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.84 -6.10 -3.26 N2 - NH3(g) -58.81 -57.04 1.77 NH3 - O2(g) -2.74 -5.70 -2.96 O2 - Zn(OH)2(e) -5.93 5.57 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 16. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.25 -5.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.178e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 9.693e-05 Surface charge, eq - 1.732e-01 sigma, C/m**2 - 1.153e-01 psi, V - -4.489e+00 -F*psi/RT - 1.124e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 2.154e-06 0.431 2.154e-06 -5.667 - Hfo_sOH2+ 2.060e-06 0.412 2.060e-06 -5.686 - Hfo_sOZn+ 7.349e-07 0.147 7.349e-07 -6.134 - Hfo_sO- 5.159e-08 0.010 5.159e-08 -7.287 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.010e-04 0.505 1.010e-04 -3.996 - Hfo_wOH2+ 9.657e-05 0.483 9.657e-05 -4.015 - Hfo_wO- 2.419e-06 0.012 2.419e-06 -5.616 - Hfo_wOZn+ 3.608e-08 0.000 3.608e-08 -7.443 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.970e-02 9.970e-02 - Zn 9.923e-05 9.923e-05 - -----------------------------Description of solution---------------------------- - - pH = 5.250 Charge balance - pe = 14.809 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -6.800e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -9.693e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.05 - Iterations = 21 - Total H = 1.110122e+02 - Total O = 5.580611e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.812e-06 5.623e-06 -5.167 -5.250 -0.083 - OH- 2.329e-09 1.774e-09 -8.633 -8.751 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.278 -43.268 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -52.884 -53.012 -0.128 - NH3 0.000e+00 0.000e+00 -57.017 -57.007 0.010 -N(0) 1.111e-06 - N2 5.553e-07 5.683e-07 -6.255 -6.245 0.010 -N(3) 2.843e-13 - NO2- 2.843e-13 2.142e-13 -12.546 -12.669 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.970e-02 - Na+ 9.970e-02 7.805e-02 -1.001 -1.108 -0.106 - NaOH 8.931e-11 9.139e-11 -10.049 -10.039 0.010 -O(0) 2.777e-06 - O2 1.388e-06 1.421e-06 -5.858 -5.848 0.010 -Zn 9.923e-05 - Zn+2 9.922e-05 3.736e-05 -4.003 -4.428 -0.424 - ZnOH+ 9.291e-09 7.261e-09 -8.032 -8.139 -0.107 - Zn(OH)2 1.444e-11 1.477e-11 -10.841 -10.831 0.010 - Zn(OH)3- 1.060e-17 8.280e-18 -16.975 -17.082 -0.107 - Zn(OH)4-2 6.236e-25 2.326e-25 -24.205 -24.633 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.25 -5.25 0.00 H+ - H2(g) -40.12 -43.27 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -2.99 -6.25 -3.26 N2 - NH3(g) -58.78 -57.01 1.77 NH3 - O2(g) -2.89 -5.85 -2.96 O2 - Zn(OH)2(e) -5.43 6.07 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 17. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.50 -5.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 9.839e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 8.263e-05 Surface charge, eq - 1.476e-01 sigma, C/m**2 - 1.073e-01 psi, V - -4.178e+00 -F*psi/RT - 1.533e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOH 1.934e-06 0.387 1.934e-06 -5.714 - Hfo_sOZn+ 1.587e-06 0.317 1.587e-06 -5.800 - Hfo_sOH2+ 1.419e-06 0.284 1.419e-06 -5.848 - Hfo_sO- 6.036e-08 0.012 6.036e-08 -7.219 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.132e-04 0.566 1.132e-04 -3.946 - Hfo_wOH2+ 8.312e-05 0.416 8.312e-05 -4.080 - Hfo_wO- 3.535e-06 0.018 3.535e-06 -5.452 - Hfo_wOZn+ 9.730e-08 0.000 9.730e-08 -7.012 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.972e-02 9.972e-02 - Zn 9.832e-05 9.832e-05 - -----------------------------Description of solution---------------------------- - - pH = 5.500 Charge balance - pe = 14.523 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -3.810e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -8.263e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.04 - Iterations = 21 - Total H = 1.110123e+02 - Total O = 5.580613e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.831e-06 3.162e-06 -5.417 -5.500 -0.083 - OH- 4.141e-09 3.155e-09 -8.383 -8.501 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.206 -43.196 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.099 -53.227 -0.128 - NH3 0.000e+00 0.000e+00 -56.981 -56.971 0.010 -N(0) 7.994e-07 - N2 3.997e-07 4.090e-07 -6.398 -6.388 0.010 -N(3) 3.351e-13 - NO2- 3.351e-13 2.525e-13 -12.475 -12.598 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.972e-02 - Na+ 9.972e-02 7.806e-02 -1.001 -1.108 -0.106 - NaOH 1.588e-10 1.625e-10 -9.799 -9.789 0.010 -O(0) 1.998e-06 - O2 9.991e-07 1.022e-06 -6.000 -5.990 0.010 -Zn 9.832e-05 - Zn+2 9.830e-05 3.702e-05 -4.007 -4.432 -0.424 - ZnOH+ 1.637e-08 1.279e-08 -7.786 -7.893 -0.107 - Zn(OH)2 4.523e-11 4.628e-11 -10.345 -10.335 0.010 - Zn(OH)3- 5.903e-17 4.613e-17 -16.229 -16.336 -0.107 - Zn(OH)4-2 6.178e-24 2.304e-24 -23.209 -23.638 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.50 -5.50 0.00 H+ - H2(g) -40.05 -43.20 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.13 -6.39 -3.26 N2 - NH3(g) -58.74 -56.97 1.77 NH3 - O2(g) -3.03 -5.99 -2.96 O2 - Zn(OH)2(e) -4.93 6.57 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 18. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -5.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -5.75 -5.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 8.089e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 6.973e-05 Surface charge, eq - 1.246e-01 sigma, C/m**2 - 9.892e-02 psi, V - -3.850e+00 -F*psi/RT - 2.127e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 2.766e-06 0.553 2.766e-06 -5.558 - Hfo_sOH 1.385e-06 0.277 1.385e-06 -5.858 - Hfo_sOH2+ 7.933e-07 0.159 7.933e-07 -6.101 - Hfo_sO- 5.543e-08 0.011 5.543e-08 -7.256 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.239e-04 0.619 1.239e-04 -3.907 - Hfo_wOH2+ 7.092e-05 0.355 7.092e-05 -4.149 - Hfo_wO- 4.955e-06 0.025 4.955e-06 -5.305 - Hfo_wOZn+ 2.589e-07 0.001 2.589e-07 -6.587 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.973e-02 9.973e-02 - Zn 9.698e-05 9.698e-05 - -----------------------------Description of solution---------------------------- - - pH = 5.750 Charge balance - pe = 14.237 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -2.117e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -6.973e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 - Iterations = 21 - Total H = 1.110123e+02 - Total O = 5.580615e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.154e-06 1.778e-06 -5.667 -5.750 -0.083 - OH- 7.365e-09 5.610e-09 -8.133 -8.251 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.135 -43.125 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.313 -53.441 -0.128 - NH3 0.000e+00 0.000e+00 -56.945 -56.935 0.010 -N(0) 5.754e-07 - N2 2.877e-07 2.944e-07 -6.541 -6.531 0.010 -N(3) 3.950e-13 - NO2- 3.950e-13 2.977e-13 -12.403 -12.526 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.973e-02 - Na+ 9.973e-02 7.808e-02 -1.001 -1.107 -0.106 - NaOH 2.825e-10 2.891e-10 -9.549 -9.539 0.010 -O(0) 1.438e-06 - O2 7.190e-07 7.358e-07 -6.143 -6.133 0.010 -Zn 9.698e-05 - Zn+2 9.695e-05 3.651e-05 -4.013 -4.438 -0.424 - ZnOH+ 2.871e-08 2.243e-08 -7.542 -7.649 -0.107 - Zn(OH)2 1.411e-10 1.443e-10 -9.851 -9.841 0.010 - Zn(OH)3- 3.274e-16 2.558e-16 -15.485 -15.592 -0.107 - Zn(OH)4-2 6.093e-23 2.272e-23 -22.215 -22.644 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -5.75 -5.75 0.00 H+ - H2(g) -39.97 -43.12 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.27 -6.53 -3.26 N2 - NH3(g) -58.71 -56.94 1.77 NH3 - O2(g) -3.17 -6.13 -2.96 O2 - Zn(OH)2(e) -4.44 7.06 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 19. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.00 -6.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 6.529e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 5.823e-05 Surface charge, eq - 1.041e-01 sigma, C/m**2 - 9.012e-02 psi, V - -3.508e+00 -F*psi/RT - 2.996e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 3.830e-06 0.766 3.830e-06 -5.417 - Hfo_sOH 7.781e-07 0.156 7.781e-07 -6.109 - Hfo_sOH2+ 3.529e-07 0.071 3.529e-07 -6.452 - Hfo_sO- 3.930e-08 0.008 3.930e-08 -7.406 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.325e-04 0.663 1.325e-04 -3.878 - Hfo_wOH2+ 6.010e-05 0.301 6.010e-05 -4.221 - Hfo_wO- 6.694e-06 0.033 6.694e-06 -5.174 - Hfo_wOZn+ 6.830e-07 0.003 6.830e-07 -6.166 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.975e-02 9.975e-02 - Zn 9.549e-05 9.549e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.000 Charge balance - pe = 13.952 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.147e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -5.823e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.03 - Iterations = 21 - Total H = 1.110123e+02 - Total O = 5.580617e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.211e-06 1.000e-06 -5.917 -6.000 -0.083 - OH- 1.310e-08 9.977e-09 -7.883 -8.001 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -43.063 -43.053 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.527 -53.655 -0.128 - NH3 0.000e+00 0.000e+00 -56.909 -56.899 0.010 -N(0) 4.143e-07 - N2 2.072e-07 2.120e-07 -6.684 -6.674 0.010 -N(3) 4.657e-13 - NO2- 4.657e-13 3.510e-13 -12.332 -12.455 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.975e-02 - Na+ 9.975e-02 7.809e-02 -1.001 -1.107 -0.106 - NaOH 5.025e-10 5.142e-10 -9.299 -9.289 0.010 -O(0) 1.035e-06 - O2 5.173e-07 5.294e-07 -6.286 -6.276 0.010 -Zn 9.549e-05 - Zn+2 9.544e-05 3.594e-05 -4.020 -4.444 -0.424 - ZnOH+ 5.025e-08 3.927e-08 -7.299 -7.406 -0.107 - Zn(OH)2 4.391e-10 4.493e-10 -9.357 -9.347 0.010 - Zn(OH)3- 1.812e-15 1.416e-15 -14.742 -14.849 -0.107 - Zn(OH)4-2 5.998e-22 2.237e-22 -21.222 -21.650 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.00 -6.00 0.00 H+ - H2(g) -39.90 -43.05 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.41 -6.67 -3.26 N2 - NH3(g) -58.67 -56.90 1.77 NH3 - O2(g) -3.32 -6.28 -2.96 O2 - Zn(OH)2(e) -3.95 7.55 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 20. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.25 -6.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 5.100e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 4.813e-05 Surface charge, eq - 8.601e-02 sigma, C/m**2 - 8.101e-02 psi, V - -3.153e+00 -F*psi/RT - 4.272e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.478e-06 0.896 4.478e-06 -5.349 - Hfo_sOH 3.657e-07 0.073 3.657e-07 -6.437 - Hfo_sOH2+ 1.330e-07 0.027 1.330e-07 -6.876 - Hfo_sO- 2.304e-08 0.005 2.304e-08 -7.637 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.389e-04 0.695 1.389e-04 -3.857 - Hfo_wOH2+ 5.052e-05 0.253 5.052e-05 -4.297 - Hfo_wO- 8.755e-06 0.044 8.755e-06 -5.058 - Hfo_wOZn+ 1.781e-06 0.009 1.781e-06 -5.749 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.976e-02 9.976e-02 - Zn 9.374e-05 9.374e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.250 Charge balance - pe = 13.666 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -5.666e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -4.813e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.580618e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.812e-07 5.623e-07 -6.167 -6.250 -0.083 - OH- 2.329e-08 1.774e-08 -7.633 -7.751 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.992 -42.982 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.742 -53.869 -0.128 - NH3 0.000e+00 0.000e+00 -56.874 -56.864 0.010 -N(0) 2.980e-07 - N2 1.490e-07 1.525e-07 -6.827 -6.817 0.010 -N(3) 5.489e-13 - NO2- 5.489e-13 4.136e-13 -12.261 -12.383 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.976e-02 - Na+ 9.976e-02 7.810e-02 -1.001 -1.107 -0.106 - NaOH 8.936e-10 9.145e-10 -9.049 -9.039 0.010 -O(0) 7.449e-07 - O2 3.724e-07 3.811e-07 -6.429 -6.419 0.010 -Zn 9.374e-05 - Zn+2 9.365e-05 3.526e-05 -4.028 -4.453 -0.424 - ZnOH+ 8.769e-08 6.853e-08 -7.057 -7.164 -0.107 - Zn(OH)2 1.363e-09 1.394e-09 -8.866 -8.856 0.010 - Zn(OH)3- 1.000e-14 7.814e-15 -14.000 -14.107 -0.107 - Zn(OH)4-2 5.886e-21 2.195e-21 -20.230 -20.659 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.25 -6.25 0.00 H+ - H2(g) -39.83 -42.98 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.56 -6.82 -3.26 N2 - NH3(g) -58.63 -56.86 1.77 NH3 - O2(g) -3.46 -6.42 -2.96 O2 - Zn(OH)2(e) -3.46 8.04 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 21. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.50 -6.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 3.598e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 3.959e-05 Surface charge, eq - 7.074e-02 sigma, C/m**2 - 7.194e-02 psi, V - -2.800e+00 -F*psi/RT - 6.079e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.781e-06 0.956 4.781e-06 -5.320 - Hfo_sOH 1.595e-07 0.032 1.595e-07 -6.797 - Hfo_sOH2+ 4.642e-08 0.009 4.642e-08 -7.333 - Hfo_sO- 1.256e-08 0.003 1.256e-08 -7.901 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.427e-04 0.714 1.427e-04 -3.845 - Hfo_wOH2+ 4.153e-05 0.208 4.153e-05 -4.382 - Hfo_wO- 1.124e-05 0.056 1.124e-05 -4.949 - Hfo_wOZn+ 4.480e-06 0.022 4.480e-06 -5.349 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.978e-02 9.978e-02 - Zn 9.074e-05 9.074e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.500 Charge balance - pe = 13.380 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = -1.809e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.959e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.580620e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.831e-07 3.162e-07 -6.417 -6.500 -0.083 - OH- 4.141e-08 3.155e-08 -7.383 -7.501 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.921 -42.911 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -53.956 -54.084 -0.128 - NH3 0.000e+00 0.000e+00 -56.838 -56.828 0.010 -N(0) 2.144e-07 - N2 1.072e-07 1.097e-07 -6.970 -6.960 0.010 -N(3) 6.470e-13 - NO2- 6.470e-13 4.876e-13 -12.189 -12.312 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.978e-02 - Na+ 9.978e-02 7.811e-02 -1.001 -1.107 -0.106 - NaOH 1.589e-09 1.626e-09 -8.799 -8.789 0.010 -O(0) 5.361e-07 - O2 2.680e-07 2.743e-07 -6.572 -6.562 0.010 -Zn 9.074e-05 - Zn+2 9.058e-05 3.411e-05 -4.043 -4.467 -0.424 - ZnOH+ 1.508e-07 1.179e-07 -6.822 -6.929 -0.107 - Zn(OH)2 4.168e-09 4.265e-09 -8.380 -8.370 0.010 - Zn(OH)3- 5.439e-14 4.250e-14 -13.264 -13.372 -0.107 - Zn(OH)4-2 5.693e-20 2.123e-20 -19.245 -19.673 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.50 -6.50 0.00 H+ - H2(g) -39.76 -42.91 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.70 -6.96 -3.26 N2 - NH3(g) -58.60 -56.83 1.77 NH3 - O2(g) -3.60 -6.56 -2.96 O2 - Zn(OH)2(e) -2.97 8.53 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 22. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -6.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -6.75 -6.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 1.709e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 3.290e-05 Surface charge, eq - 5.878e-02 sigma, C/m**2 - 6.370e-02 psi, V - -2.480e+00 -F*psi/RT - 8.378e-02 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.905e-06 0.981 4.905e-06 -5.309 - Hfo_sOH 7.153e-08 0.014 7.153e-08 -7.146 - Hfo_sOH2+ 1.613e-08 0.003 1.613e-08 -7.792 - Hfo_sO- 7.267e-09 0.001 7.267e-09 -8.139 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.430e-04 0.715 1.430e-04 -3.845 - Hfo_wOH2+ 3.224e-05 0.161 3.224e-05 -4.492 - Hfo_wO- 1.452e-05 0.073 1.452e-05 -4.838 - Hfo_wOZn+ 1.027e-05 0.051 1.027e-05 -4.989 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.980e-02 9.980e-02 - Zn 8.483e-05 8.483e-05 - -----------------------------Description of solution---------------------------- - - pH = 6.750 Charge balance - pe = 13.095 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.361e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -3.290e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.02 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.580621e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 2.154e-07 1.778e-07 -6.667 -6.750 -0.083 - OH- 7.365e-08 5.610e-08 -7.133 -7.251 -0.118 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.849 -42.839 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.170 -54.298 -0.128 - NH3 0.000e+00 0.000e+00 -56.802 -56.792 0.010 -N(0) 1.544e-07 - N2 7.718e-08 7.898e-08 -7.113 -7.102 0.010 -N(3) 7.627e-13 - NO2- 7.627e-13 5.748e-13 -12.118 -12.240 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.980e-02 - Na+ 9.980e-02 7.813e-02 -1.001 -1.107 -0.106 - NaOH 2.827e-09 2.893e-09 -8.549 -8.539 0.010 -O(0) 3.858e-07 - O2 1.929e-07 1.974e-07 -6.715 -6.705 0.010 -Zn 8.483e-05 - Zn+2 8.457e-05 3.184e-05 -4.073 -4.497 -0.424 - ZnOH+ 2.504e-07 1.957e-07 -6.601 -6.708 -0.107 - Zn(OH)2 1.230e-08 1.259e-08 -7.910 -7.900 0.010 - Zn(OH)3- 2.856e-13 2.231e-13 -12.544 -12.651 -0.107 - Zn(OH)4-2 5.315e-19 1.982e-19 -18.274 -18.703 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -6.75 -6.75 0.00 H+ - H2(g) -39.69 -42.84 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.84 -7.10 -3.26 N2 - NH3(g) -58.56 -56.79 1.77 NH3 - O2(g) -3.74 -6.70 -2.96 O2 - Zn(OH)2(e) -2.50 9.00 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 23. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.00 -7.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -7.621e-06 - -------------------------------Surface composition------------------------------ - -Hfo - 2.821e-05 Surface charge, eq - 5.040e-02 sigma, C/m**2 - 5.718e-02 psi, V - -2.226e+00 -F*psi/RT - 1.080e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.953e-06 0.991 4.953e-06 -5.305 - Hfo_sOH 3.573e-08 0.007 3.573e-08 -7.447 - Hfo_sOH2+ 5.840e-09 0.001 5.840e-09 -8.234 - Hfo_sO- 5.008e-09 0.001 5.008e-09 -8.300 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.380e-04 0.690 1.380e-04 -3.860 - Hfo_wOH2+ 2.256e-05 0.113 2.256e-05 -4.647 - Hfo_wOZn+ 2.004e-05 0.100 2.004e-05 -4.698 - Hfo_wO- 1.935e-05 0.097 1.935e-05 -4.713 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.982e-02 9.982e-02 - Zn 7.501e-05 7.501e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.000 Charge balance - pe = 12.809 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.001e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.762e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.821e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 22 - Total H = 1.110125e+02 - Total O = 5.580624e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-07 9.977e-08 -6.883 -7.001 -0.118 - H+ 1.211e-07 1.000e-07 -6.917 -7.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.778 -42.768 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.384 -54.512 -0.128 - NH3 0.000e+00 0.000e+00 -56.766 -56.756 0.010 -N(0) 1.112e-07 - N2 5.561e-08 5.691e-08 -7.255 -7.245 0.010 -N(3) 8.992e-13 - NO2- 8.992e-13 6.777e-13 -12.046 -12.169 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.982e-02 - Na+ 9.982e-02 7.815e-02 -1.001 -1.107 -0.106 - NaOH 5.028e-09 5.146e-09 -8.299 -8.289 0.010 -O(0) 2.775e-07 - O2 1.388e-07 1.420e-07 -6.858 -6.848 0.010 -Zn 7.501e-05 - Zn+2 7.458e-05 2.808e-05 -4.127 -4.552 -0.424 - ZnOH+ 3.927e-07 3.069e-07 -6.406 -6.513 -0.107 - Zn(OH)2 3.432e-08 3.512e-08 -7.465 -7.454 0.010 - Zn(OH)3- 1.416e-12 1.107e-12 -11.849 -11.956 -0.107 - Zn(OH)4-2 4.688e-18 1.748e-18 -17.329 -17.757 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.00 -7.00 0.00 H+ - H2(g) -39.62 -42.77 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -3.98 -7.24 -3.26 N2 - NH3(g) -58.53 -56.76 1.77 NH3 - O2(g) -3.89 -6.85 -2.96 O2 - Zn(OH)2(e) -2.05 9.45 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 24. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.25 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.25 -7.25 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -3.628e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.514e-05 Surface charge, eq - 4.492e-02 sigma, C/m**2 - 5.252e-02 psi, V - -2.044e+00 -F*psi/RT - 1.295e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.973e-06 0.995 4.973e-06 -5.303 - Hfo_sOH 2.031e-08 0.004 2.031e-08 -7.692 - Hfo_sO- 4.222e-09 0.001 4.222e-09 -8.375 - Hfo_sOH2+ 2.238e-09 0.000 2.238e-09 -8.650 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.270e-04 0.635 1.270e-04 -3.896 - Hfo_wOZn+ 3.257e-05 0.163 3.257e-05 -4.487 - Hfo_wO- 2.640e-05 0.132 2.640e-05 -4.578 - Hfo_wOH2+ 1.400e-05 0.070 1.400e-05 -4.854 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.985e-02 9.985e-02 - Zn 6.245e-05 6.245e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.250 Charge balance - pe = 12.523 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.321e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.514e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 22 - Total H = 1.110125e+02 - Total O = 5.580627e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 2.329e-07 1.774e-07 -6.633 -6.751 -0.118 - H+ 6.812e-08 5.623e-08 -7.167 -7.250 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.706 -42.696 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.596 -54.724 -0.128 - NH3 0.000e+00 0.000e+00 -56.729 -56.719 0.010 -N(0) 8.046e-08 - N2 4.023e-08 4.117e-08 -7.395 -7.385 0.010 -N(3) 1.061e-12 - NO2- 1.061e-12 7.997e-13 -11.974 -12.097 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.536e-02 -1.000 -1.123 -0.123 -Na 9.985e-02 - Na+ 9.985e-02 7.817e-02 -1.001 -1.107 -0.106 - NaOH 8.944e-09 9.153e-09 -8.048 -8.038 0.010 -O(0) 1.993e-07 - O2 9.966e-08 1.020e-07 -7.001 -6.991 0.010 -Zn 6.245e-05 - Zn+2 6.179e-05 2.327e-05 -4.209 -4.633 -0.424 - ZnOH+ 5.786e-07 4.521e-07 -6.238 -6.345 -0.107 - Zn(OH)2 8.990e-08 9.200e-08 -7.046 -7.036 0.010 - Zn(OH)3- 6.598e-12 5.156e-12 -11.181 -11.288 -0.107 - Zn(OH)4-2 3.883e-17 1.448e-17 -16.411 -16.839 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.25 -7.25 0.00 H+ - H2(g) -39.55 -42.70 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.13 -7.39 -3.26 N2 - NH3(g) -58.49 -56.72 1.77 NH3 - O2(g) -4.03 -6.99 -2.96 O2 - Zn(OH)2(e) -1.64 9.86 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 25. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.5 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.50 -7.50 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -6.533e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.290e-05 Surface charge, eq - 4.091e-02 sigma, C/m**2 - 4.889e-02 psi, V - -1.903e+00 -F*psi/RT - 1.491e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.982e-06 0.996 4.982e-06 -5.303 - Hfo_sOH 1.269e-08 0.003 1.269e-08 -7.897 - Hfo_sO- 4.073e-09 0.001 4.073e-09 -8.390 - Hfo_sOH2+ 9.054e-10 0.000 9.054e-10 -9.043 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 1.109e-04 0.554 1.109e-04 -3.955 - Hfo_wOZn+ 4.560e-05 0.228 4.560e-05 -4.341 - Hfo_wO- 3.560e-05 0.178 3.560e-05 -4.449 - Hfo_wOH2+ 7.913e-06 0.040 7.913e-06 -5.102 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.988e-02 9.988e-02 - Zn 4.942e-05 4.942e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.500 Charge balance - pe = 12.237 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.643e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.290e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 24 - Total H = 1.110126e+02 - Total O = 5.580630e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 4.141e-07 3.155e-07 -6.383 -6.501 -0.118 - H+ 3.831e-08 3.162e-08 -7.417 -7.500 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.635 -42.625 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -54.813 -54.941 -0.128 - NH3 0.000e+00 0.000e+00 -56.695 -56.685 0.010 -N(0) 5.753e-08 - N2 2.876e-08 2.943e-08 -7.541 -7.531 0.010 -N(3) 1.249e-12 - NO2- 1.249e-12 9.414e-13 -11.903 -12.026 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.988e-02 - Na+ 9.988e-02 7.819e-02 -1.001 -1.107 -0.106 - NaOH 1.591e-08 1.628e-08 -7.798 -7.788 0.010 -O(0) 1.438e-07 - O2 7.191e-08 7.359e-08 -7.143 -7.133 0.010 -Zn 4.942e-05 - Zn+2 4.839e-05 1.822e-05 -4.315 -4.739 -0.424 - ZnOH+ 8.058e-07 6.297e-07 -6.094 -6.201 -0.107 - Zn(OH)2 2.227e-07 2.278e-07 -6.652 -6.642 0.010 - Zn(OH)3- 2.906e-11 2.271e-11 -10.537 -10.644 -0.107 - Zn(OH)4-2 3.041e-16 1.134e-16 -15.517 -15.945 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.50 -7.50 0.00 H+ - H2(g) -39.47 -42.62 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.27 -7.53 -3.26 N2 - NH3(g) -58.46 -56.69 1.77 NH3 - O2(g) -4.17 -7.13 -2.96 O2 - Zn(OH)2(e) -1.24 10.26 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 26. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -7.75 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -7.75 -7.75 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -9.246e-05 - -------------------------------Surface composition------------------------------ - -Hfo - 2.082e-05 Surface charge, eq - 3.720e-02 sigma, C/m**2 - 4.536e-02 psi, V - -1.765e+00 -F*psi/RT - 1.711e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.987e-06 0.997 4.987e-06 -5.302 - Hfo_sOH 8.383e-09 0.002 8.383e-09 -8.077 - Hfo_sO- 4.170e-09 0.001 4.170e-09 -8.380 - Hfo_sOH2+ 3.861e-10 0.000 3.861e-10 -9.413 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 9.232e-05 0.462 9.232e-05 -4.035 - Hfo_wOZn+ 5.751e-05 0.288 5.751e-05 -4.240 - Hfo_wO- 4.592e-05 0.230 4.592e-05 -4.338 - Hfo_wOH2+ 4.251e-06 0.021 4.251e-06 -5.371 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.991e-02 9.991e-02 - Zn 3.750e-05 3.750e-05 - -----------------------------Description of solution---------------------------- - - pH = 7.750 Charge balance - pe = 11.952 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.853e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -2.082e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 23 - Total H = 1.110126e+02 - Total O = 5.580632e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 7.364e-07 5.610e-07 -6.133 -6.251 -0.118 - H+ 2.154e-08 1.778e-08 -7.667 -7.750 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.563 -42.553 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -55.027 -55.155 -0.128 - NH3 0.000e+00 0.000e+00 -56.659 -56.649 0.010 -N(0) 4.145e-08 - N2 2.072e-08 2.121e-08 -7.684 -7.674 0.010 -N(3) 1.473e-12 - NO2- 1.473e-12 1.110e-12 -11.832 -11.955 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.991e-02 - Na+ 9.991e-02 7.821e-02 -1.000 -1.107 -0.106 - NaOH 2.830e-08 2.896e-08 -7.548 -7.538 0.010 -O(0) 1.035e-07 - O2 5.173e-08 5.294e-08 -7.286 -7.276 0.010 -Zn 3.750e-05 - Zn+2 3.592e-05 1.353e-05 -4.445 -4.869 -0.424 - ZnOH+ 1.064e-06 8.312e-07 -5.973 -6.080 -0.107 - Zn(OH)2 5.227e-07 5.349e-07 -6.282 -6.272 0.010 - Zn(OH)3- 1.213e-10 9.479e-11 -9.916 -10.023 -0.107 - Zn(OH)4-2 2.258e-15 8.419e-16 -14.646 -15.075 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -7.75 -7.75 0.00 H+ - H2(g) -39.40 -42.55 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.41 -7.67 -3.26 N2 - NH3(g) -58.42 -56.65 1.77 NH3 - O2(g) -4.32 -7.28 -2.96 O2 - Zn(OH)2(e) -0.87 10.63 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 27. -------------------------------------- - - USE solution 2 - USE surface 1 - EQUILIBRIUM_PHASES 1 - Fix_H+ -8.0 NaOH 10.0 - END ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -Using solution 2. -Using surface 1. -Using pure phase assemblage 1. - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - Fix_H+ -8.00 -8.00 0.00 - NaOH is reactant 1.000e+01 1.000e+01 -1.167e-04 - -------------------------------Surface composition------------------------------ - -Hfo - 1.856e-05 Surface charge, eq - 3.316e-02 sigma, C/m**2 - 4.130e-02 psi, V - -1.607e+00 -F*psi/RT - 2.004e-01 exp(-F*psi/RT) - 6.000e+02 specific area, m**2/g - 5.400e+01 m**2 for 9.000e-02 g - - -Hfo_s - 5.000e-06 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_sOZn+ 4.990e-06 0.998 4.990e-06 -5.302 - Hfo_sOH 5.756e-09 0.001 5.756e-09 -8.240 - Hfo_sO- 4.347e-09 0.001 4.347e-09 -8.362 - Hfo_sOH2+ 1.746e-10 0.000 1.746e-10 -9.758 - -Hfo_w - 2.000e-04 moles - Mole Log - Species Moles Fraction Molality Molality - - Hfo_wOH 7.426e-05 0.371 7.426e-05 -4.129 - Hfo_wOZn+ 6.740e-05 0.337 6.740e-05 -4.171 - Hfo_wO- 5.608e-05 0.280 5.608e-05 -4.251 - Hfo_wOH2+ 2.252e-06 0.011 2.252e-06 -5.647 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - N 1.000e-01 1.000e-01 - Na 9.993e-02 9.993e-02 - Zn 2.761e-05 2.761e-05 - -----------------------------Description of solution---------------------------- - - pH = 8.000 Charge balance - pe = 11.666 Adjusted to redox equilibrium - Activity of water = 0.997 - Ionic strength = 1.000e-01 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 4.985e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.856e-05 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.01 - Iterations = 25 - Total H = 1.110127e+02 - Total O = 5.580635e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.310e-06 9.977e-07 -5.883 -6.001 -0.118 - H+ 1.211e-08 1.000e-08 -7.917 -8.000 -0.083 - H2O 5.551e+01 9.966e-01 1.744 -0.001 0.000 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -42.492 -42.482 0.010 -N(-3) 0.000e+00 - NH4+ 0.000e+00 0.000e+00 -55.242 -55.369 -0.128 - NH3 0.000e+00 0.000e+00 -56.624 -56.614 0.010 -N(0) 2.980e-08 - N2 1.490e-08 1.525e-08 -7.827 -7.817 0.010 -N(3) 1.736e-12 - NO2- 1.736e-12 1.308e-12 -11.761 -11.883 -0.123 -N(5) 1.000e-01 - NO3- 1.000e-01 7.537e-02 -1.000 -1.123 -0.123 -Na 9.993e-02 - Na+ 9.993e-02 7.823e-02 -1.000 -1.107 -0.106 - NaOH 5.034e-08 5.151e-08 -7.298 -7.288 0.010 -O(0) 7.449e-08 - O2 3.725e-08 3.811e-08 -7.429 -7.419 0.010 -Zn 2.761e-05 - Zn+2 2.513e-05 9.463e-06 -4.600 -5.024 -0.424 - ZnOH+ 1.323e-06 1.034e-06 -5.878 -5.985 -0.107 - Zn(OH)2 1.156e-06 1.183e-06 -5.937 -5.927 0.010 - Zn(OH)3- 4.772e-10 3.729e-10 -9.321 -9.428 -0.107 - Zn(OH)4-2 1.579e-14 5.890e-15 -13.802 -14.230 -0.428 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Fix_H+ -8.00 -8.00 0.00 H+ - H2(g) -39.33 -42.48 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - N2(g) -4.56 -7.82 -3.26 N2 - NH3(g) -58.38 -56.61 1.77 NH3 - O2(g) -4.46 -7.42 -2.96 O2 - Zn(OH)2(e) -0.53 10.97 11.50 Zn(OH)2 - ------------------- -End of simulation. ------------------- - -------------------------------------- -Reading input data for simulation 28. -------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex8.sel b/Sun/examples/ex8.sel deleted file mode 100644 index 7bbafc65..00000000 --- a/Sun/examples/ex8.sel +++ /dev/null @@ -1,27 +0,0 @@ - sim state soln dist_x time step pH pe m_Zn+2 m_Hfo_wOZn+ m_Hfo_sOZn+ - 2 react 1 -99 0 1 5 15.0946 9.9667e-08 1.3194e-11 3.1498e-10 - 3 react 1 -99 0 1 5.25 14.8089 9.9093e-08 3.6118e-11 8.6216e-10 - 4 react 1 -99 0 1 5.5 14.5232 9.7567e-08 9.7221e-11 2.3200e-09 - 5 react 1 -99 0 1 5.75 14.2374 9.3657e-08 2.5418e-10 6.0611e-09 - 6 react 1 -99 0 1 6 13.9517 8.4476e-08 6.2406e-10 1.4855e-08 - 7 react 1 -99 0 1 6.25 13.666 6.6695e-08 1.3446e-09 3.1897e-08 - 8 react 1 -99 0 1 6.5 13.3803 4.2322e-08 2.3406e-09 5.5265e-08 - 9 react 1 -99 0 1 6.75 13.0946 2.1052e-08 3.2179e-09 7.5665e-08 - 10 react 1 -99 0 1 7 12.8089 8.7494e-09 3.7289e-09 8.7472e-08 - 11 react 1 -99 0 1 7.25 12.5232 3.3000e-09 3.9564e-09 9.2708e-08 - 12 react 1 -99 0 1 7.5 12.2374 1.1903e-09 4.0447e-09 9.4740e-08 - 13 react 1 -99 0 1 7.75 11.9517 4.2114e-10 4.0771e-09 9.5483e-08 - 14 react 1 -99 0 1 8 11.666 1.4799e-10 4.0887e-09 9.5749e-08 - 15 react 2 -99 0 1 5 15.0946 9.9686e-05 1.3187e-08 2.9620e-07 - 16 react 2 -99 0 1 5.25 14.8089 9.9220e-05 3.6081e-08 7.3494e-07 - 17 react 2 -99 0 1 5.5 14.5231 9.8300e-05 9.7297e-08 1.5866e-06 - 18 react 2 -99 0 1 5.75 14.2374 9.6947e-05 2.5891e-07 2.7658e-06 - 19 react 2 -99 0 1 6 13.9517 9.5437e-05 6.8302e-07 3.8297e-06 - 20 react 2 -99 0 1 6.25 13.666 9.3651e-05 1.7815e-06 4.4782e-06 - 21 react 2 -99 0 1 6.5 13.3803 9.0584e-05 4.4798e-06 4.7815e-06 - 22 react 2 -99 0 1 6.75 13.0946 8.4566e-05 1.0266e-05 4.9051e-06 - 23 react 2 -99 0 1 7 12.8088 7.4581e-05 2.0039e-05 4.9534e-06 - 24 react 2 -99 0 1 7.25 12.5229 6.1786e-05 3.2572e-05 4.9732e-06 - 25 react 2 -99 0 1 7.5 12.2374 4.8388e-05 4.5601e-05 4.9823e-06 - 26 react 2 -99 0 1 7.75 11.9517 3.5918e-05 5.7508e-05 4.9871e-06 - 27 react 2 -99 0 1 8 11.666 2.5127e-05 6.7404e-05 4.9897e-06 diff --git a/Sun/examples/ex9.log b/Sun/examples/ex9.log deleted file mode 100644 index e69de29b..00000000 diff --git a/Sun/examples/ex9.out b/Sun/examples/ex9.out deleted file mode 100644 index e865b680..00000000 --- a/Sun/examples/ex9.out +++ /dev/null @@ -1,1284 +0,0 @@ - Input file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../examples/ex9 - Output file: ex9.out -Database file: /z/parkplace/home/dlpark/../../home/dlpark/programs/phreeqc/src/../src/Sun/../../database/phreeqc.dat - ------------------- -Reading data base. ------------------- - - SOLUTION_MASTER_SPECIES - SOLUTION_SPECIES - PHASES - EXCHANGE_MASTER_SPECIES - EXCHANGE_SPECIES - SURFACE_MASTER_SPECIES - SURFACE_SPECIES - RATES - END ------------------------------------- -Reading input data for simulation 1. ------------------------------------- - - TITLE Example 9.--Kinetically controlled oxidation of ferrous - iron. Decoupled valence states of iron. - SOLUTION_MASTER_SPECIES - Fe_di Fe_di+2 0.0 Fe_di 55.847 - Fe_tri Fe_tri+3 0.0 Fe_tri 55.847 - SOLUTION_SPECIES - Fe_di+2 = Fe_di+2 - log_k 0.0 - Fe_tri+3 = Fe_tri+3 - log_k 0.0 - Fe_di+2 + H2O = Fe_diOH+ + H+ - log_k -9.5 - delta_h 13.20 kcal - Fe_di+2 + Cl- = Fe_diCl+ - log_k 0.14 - Fe_di+2 + CO3-2 = Fe_diCO3 - log_k 4.38 - Fe_di+2 + HCO3- = Fe_diHCO3+ - log_k 2.0 - Fe_di+2 + SO4-2 = Fe_diSO4 - log_k 2.25 - delta_h 3.230 kcal - Fe_di+2 + HSO4- = Fe_diHSO4+ - log_k 1.08 - Fe_di+2 + 2HS- = Fe_di(HS)2 - log_k 8.95 - Fe_di+2 + 3HS- = Fe_di(HS)3- - log_k 10.987 - Fe_di+2 + HPO4-2 = Fe_diHPO4 - log_k 3.6 - Fe_di+2 + H2PO4- = Fe_diH2PO4+ - log_k 2.7 - Fe_di+2 + F- = Fe_diF+ - log_k 1.0 - Fe_tri+3 + H2O = Fe_triOH+2 + H+ - log_k -2.19 - delta_h 10.4 kcal - Fe_tri+3 + 2 H2O = Fe_tri(OH)2+ + 2 H+ - log_k -5.67 - delta_h 17.1 kcal - Fe_tri+3 + 3 H2O = Fe_tri(OH)3 + 3 H+ - log_k -12.56 - delta_h 24.8 kcal - Fe_tri+3 + 4 H2O = Fe_tri(OH)4- + 4 H+ - log_k -21.6 - delta_h 31.9 kcal - 2 Fe_tri+3 + 2 H2O = Fe_tri2(OH)2+4 + 2 H+ - log_k -2.95 - delta_h 13.5 kcal - 3 Fe_tri+3 + 4 H2O = Fe_tri3(OH)4+5 + 4 H+ - log_k -6.3 - delta_h 14.3 kcal - Fe_tri+3 + Cl- = Fe_triCl+2 - log_k 1.48 - delta_h 5.6 kcal - Fe_tri+3 + 2 Cl- = Fe_triCl2+ - log_k 2.13 - Fe_tri+3 + 3 Cl- = Fe_triCl3 - log_k 1.13 - Fe_tri+3 + SO4-2 = Fe_triSO4+ - log_k 4.04 - delta_h 3.91 kcal - Fe_tri+3 + HSO4- = Fe_triHSO4+2 - log_k 2.48 - Fe_tri+3 + 2 SO4-2 = Fe_tri(SO4)2- - log_k 5.38 - delta_h 4.60 kcal - Fe_tri+3 + HPO4-2 = Fe_triHPO4+ - log_k 5.43 - delta_h 5.76 kcal - Fe_tri+3 + H2PO4- = Fe_triH2PO4+2 - log_k 5.43 - Fe_tri+3 + F- = Fe_triF+2 - log_k 6.2 - delta_h 2.7 kcal - Fe_tri+3 + 2 F- = Fe_triF2+ - log_k 10.8 - delta_h 4.8 kcal - Fe_tri+3 + 3 F- = Fe_triF3 - log_k 14.0 - delta_h 5.4 kcal - PHASES - Goethite - Fe_triOOH + 3 H+ = Fe_tri+3 + 2 H2O - log_k -1.0 - END ------ -TITLE ------ - - Example 9.--Kinetically controlled oxidation of ferrous - iron. Decoupled valence states of iron. - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 2. ------------------------------------- - - SOLUTION 1 - pH 7.0 - pe 10.0 O2(g) -0.67 - Fe_di 0.1 - Na 10. - Cl 10. charge - EQUILIBRIUM_PHASES 1 - O2(g) -0.67 - RATES - Fe_di_ox - start - 10 Fe_di = TOT("Fe_di") - 20 if (Fe_di <= 0) then goto 200 - 30 p_o2 = 10^(SI("O2(g)")) - 40 moles = (2.91e-9 + 1.33e12 * (ACT("OH-"))^2 * p_o2) * Fe_di * TIME - 200 SAVE moles - end - KINETICS 1 - Fe_di_ox - formula Fe_di -1.0 Fe_tri 1.0 - steps 100 400 3100 10800 21600 5.04e4 8.64e4 1.728e5 1.728e5 1.728e5 1.728e5 - INCREMENTAL_REACTIONS true - SELECTED_OUTPUT - file ex9.sel - reset false - USER_PUNCH - headings Days Fe(2) Fe(3) pH si_goethite - 10 PUNCH SIM_TIME/3600/24 TOT("Fe_di")*1e6, TOT("Fe_tri")*1e6, -LA("H+"), SI("Goethite") - END -------------------------------------------- -Beginning of initial solution calculations. -------------------------------------------- - -Initial solution 1. - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 Charge balance - Fe_di 1.000e-04 1.000e-04 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 7.000 - pe = 13.613 Equilibrium with O2(g) - Activity of water = 1.000 - Ionic strength = 1.030e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.308e-07 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = -1.740e-18 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = -0.00 - Iterations = 9 - Total H = 1.110124e+02 - Total O = 5.550668e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - OH- 1.113e-07 1.001e-07 -6.953 -7.000 -0.046 - H+ 1.096e-07 1.000e-07 -6.960 -7.000 -0.040 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 9.149e-07 8.242e-07 -6.039 -6.084 -0.045 -Fe_di 1.000e-04 - Fe_di+2 9.886e-05 6.510e-05 -4.005 -4.186 -0.181 - Fe_diCl+ 9.149e-07 8.242e-07 -6.039 -6.084 -0.045 - Fe_diOH+ 2.285e-07 2.058e-07 -6.641 -6.687 -0.045 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 5.943e-10 5.957e-10 -9.226 -9.225 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - ------------------------------------------ -Beginning of batch-reaction calculations. ------------------------------------------ - -Reaction step 1. - -WARNING: Element Fe_tri has negative moles in solution, -5.977583e-06. - Erroneous mole balance occurs as moles are added to produce zero moles. - Usually caused by KINETICS, REACTION, or diffuse layer calculation. - May be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer. -WARNING: Element Fe_tri has negative moles in solution, -1.366855e-06. - Erroneous mole balance occurs as moles are added to produce zero moles. - Usually caused by KINETICS, REACTION, or diffuse layer calculation. - May be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer. -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 100 seconds (Incremented time: 100 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.058e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -2.645e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.894e-05 9.894e-05 - Fe_tri 1.058e-06 1.058e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 6.048 Charge balance - pe = 14.565 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.030e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.289e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.530e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 206 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.821e-07 8.962e-07 -6.008 -6.048 -0.040 - OH- 1.242e-08 1.117e-08 -7.906 -7.952 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 9.071e-07 8.172e-07 -6.042 -6.088 -0.045 - Fe_triCl+2 1.330e-13 8.757e-14 -12.876 -13.058 -0.181 - Fe_triCl2+ 3.982e-15 3.587e-15 -14.400 -14.445 -0.045 - Fe_triCl3 3.282e-18 3.290e-18 -17.484 -17.483 0.001 -Fe_di 9.894e-05 - Fe_di+2 9.801e-05 6.455e-05 -4.009 -4.190 -0.181 - Fe_diCl+ 9.071e-07 8.172e-07 -6.042 -6.088 -0.045 - Fe_diOH+ 2.527e-08 2.277e-08 -7.597 -7.643 -0.045 -Fe_tri 1.058e-06 - Fe_tri(OH)2+ 9.336e-07 8.410e-07 -6.030 -6.075 -0.045 - Fe_tri(OH)3 1.206e-07 1.209e-07 -6.919 -6.918 0.001 - Fe_triOH+2 3.457e-09 2.277e-09 -8.461 -8.643 -0.181 - Fe_tri(OH)4- 1.365e-10 1.229e-10 -9.865 -9.910 -0.045 - Fe_tri+3 8.092e-13 3.162e-13 -12.092 -12.500 -0.408 - Fe_triCl+2 1.330e-13 8.757e-14 -12.876 -13.058 -0.181 - Fe_triCl2+ 3.982e-15 3.587e-15 -14.400 -14.445 -0.045 - Fe_tri2(OH)2+4 7.418e-16 1.396e-16 -15.130 -15.855 -0.726 - Fe_triCl3 3.282e-18 3.290e-18 -17.484 -17.483 0.001 - Fe_tri3(OH)4+5 3.336e-19 2.452e-20 -18.477 -19.610 -1.134 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 6.631e-11 6.647e-11 -10.178 -10.177 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.64 5.64 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 2. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 400 seconds (Incremented time: 500 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -7.364e-07 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -1.841e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.821e-05 9.821e-05 - Fe_tri 1.794e-06 1.794e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 5.810 Charge balance - pe = 14.803 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.030e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.025e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 8.635e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 25 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.699e-06 1.550e-06 -5.770 -5.810 -0.040 - OH- 7.183e-09 6.457e-09 -8.144 -8.190 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 9.005e-07 8.112e-07 -6.046 -6.091 -0.045 - Fe_triCl+2 7.069e-13 4.656e-13 -12.151 -12.332 -0.181 - Fe_triCl2+ 2.117e-14 1.907e-14 -13.674 -13.720 -0.045 - Fe_triCl3 1.745e-17 1.749e-17 -16.758 -16.757 0.001 -Fe_di 9.821e-05 - Fe_di+2 9.729e-05 6.408e-05 -4.012 -4.193 -0.181 - Fe_diCl+ 9.005e-07 8.112e-07 -6.046 -6.091 -0.045 - Fe_diOH+ 1.451e-08 1.307e-08 -7.838 -7.884 -0.045 -Fe_tri 1.794e-06 - Fe_tri(OH)2+ 1.660e-06 1.495e-06 -5.780 -5.825 -0.045 - Fe_tri(OH)3 1.239e-07 1.242e-07 -6.907 -6.906 0.001 - Fe_triOH+2 1.063e-08 7.000e-09 -7.974 -8.155 -0.181 - Fe_tri(OH)4- 8.110e-11 7.306e-11 -10.091 -10.136 -0.045 - Fe_tri+3 4.302e-12 1.681e-12 -11.366 -11.774 -0.408 - Fe_triCl+2 7.069e-13 4.656e-13 -12.151 -12.332 -0.181 - Fe_triCl2+ 2.117e-14 1.907e-14 -13.674 -13.720 -0.045 - Fe_tri2(OH)2+4 7.010e-15 1.319e-15 -14.154 -14.880 -0.726 - Fe_triCl3 1.745e-17 1.749e-17 -16.758 -16.757 0.001 - Fe_tri3(OH)4+5 5.604e-18 4.120e-19 -17.252 -18.385 -1.134 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 3.834e-11 3.843e-11 -10.416 -10.415 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.65 5.65 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 3. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 3100 seconds (Incremented time: 3600 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.614e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.036e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.659e-05 9.659e-05 - Fe_tri 3.408e-06 3.408e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 5.525 Charge balance - pe = 15.088 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.029e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 3.639e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 9.240e-16 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 65 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 3.274e-06 2.988e-06 -5.485 -5.525 -0.040 - OH- 3.726e-09 3.349e-09 -8.429 -8.475 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 8.857e-07 7.979e-07 -6.053 -6.098 -0.045 - Fe_triCl+2 5.132e-12 3.380e-12 -11.290 -11.471 -0.181 - Fe_triCl2+ 1.537e-13 1.385e-13 -12.813 -12.859 -0.045 - Fe_triCl3 1.267e-16 1.270e-16 -15.897 -15.896 0.001 -Fe_di 9.659e-05 - Fe_di+2 9.570e-05 6.303e-05 -4.019 -4.200 -0.181 - Fe_diCl+ 8.857e-07 7.979e-07 -6.053 -6.098 -0.045 - Fe_diOH+ 7.403e-09 6.669e-09 -8.131 -8.176 -0.045 -Fe_tri 3.408e-06 - Fe_tri(OH)2+ 3.242e-06 2.921e-06 -5.489 -5.534 -0.045 - Fe_tri(OH)3 1.256e-07 1.259e-07 -6.901 -6.900 0.001 - Fe_triOH+2 4.003e-08 2.636e-08 -7.398 -7.579 -0.181 - Fe_tri(OH)4- 4.265e-11 3.842e-11 -10.370 -10.415 -0.045 - Fe_tri+3 3.123e-11 1.220e-11 -10.505 -10.913 -0.408 - Fe_triCl+2 5.132e-12 3.380e-12 -11.290 -11.471 -0.181 - Fe_triCl2+ 1.537e-13 1.385e-13 -12.813 -12.859 -0.045 - Fe_tri2(OH)2+4 9.943e-14 1.871e-14 -13.002 -13.728 -0.725 - Fe_tri3(OH)4+5 1.553e-16 1.142e-17 -15.809 -16.942 -1.134 - Fe_triCl3 1.267e-16 1.270e-16 -15.897 -15.896 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 1.989e-11 1.994e-11 -10.701 -10.700 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 4. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 10800 seconds (Incremented time: 14400 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.953e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.883e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.464e-05 9.464e-05 - Fe_tri 5.361e-06 5.361e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 5.327 Charge balance - pe = 15.286 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.029e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 5.592e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.873e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 24 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 5.163e-06 4.711e-06 -5.287 -5.327 -0.040 - OH- 2.363e-09 2.124e-09 -8.627 -8.673 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 8.679e-07 7.819e-07 -6.062 -6.107 -0.045 - Fe_triCl+2 2.021e-11 1.331e-11 -10.694 -10.876 -0.181 - Fe_triCl2+ 6.053e-13 5.453e-13 -12.218 -12.263 -0.045 - Fe_triCl3 4.990e-16 5.001e-16 -15.302 -15.301 0.001 -Fe_di 9.464e-05 - Fe_di+2 9.377e-05 6.176e-05 -4.028 -4.209 -0.181 - Fe_diCl+ 8.679e-07 7.819e-07 -6.062 -6.107 -0.045 - Fe_diOH+ 4.600e-09 4.144e-09 -8.337 -8.383 -0.045 -Fe_tri 5.361e-06 - Fe_tri(OH)2+ 5.135e-06 4.626e-06 -5.289 -5.335 -0.045 - Fe_tri(OH)3 1.261e-07 1.264e-07 -6.899 -6.898 0.001 - Fe_triOH+2 9.996e-08 6.584e-08 -7.000 -7.182 -0.181 - Fe_tri+3 1.230e-10 4.806e-11 -9.910 -10.318 -0.408 - Fe_tri(OH)4- 2.716e-11 2.447e-11 -10.566 -10.611 -0.045 - Fe_triCl+2 2.021e-11 1.331e-11 -10.694 -10.876 -0.181 - Fe_tri2(OH)2+4 6.200e-13 1.167e-13 -12.208 -12.933 -0.725 - Fe_triCl2+ 6.053e-13 5.453e-13 -12.218 -12.263 -0.045 - Fe_tri3(OH)4+5 1.533e-15 1.128e-16 -14.814 -15.948 -1.133 - Fe_triCl3 4.990e-16 5.001e-16 -15.302 -15.301 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 1.261e-11 1.264e-11 -10.899 -10.898 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 5. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 21600 seconds (Incremented time: 36000 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.875e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.688e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.276e-05 9.276e-05 - Fe_tri 7.236e-06 7.236e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 5.197 Charge balance - pe = 15.415 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.029e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 7.467e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.886e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 6.954e-06 6.346e-06 -5.158 -5.197 -0.040 - OH- 1.754e-09 1.577e-09 -8.756 -8.802 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.171e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 8.507e-07 7.664e-07 -6.070 -6.116 -0.045 - Fe_triCl+2 4.947e-11 3.258e-11 -10.306 -10.487 -0.181 - Fe_triCl2+ 1.482e-12 1.335e-12 -11.829 -11.875 -0.045 - Fe_triCl3 1.221e-15 1.224e-15 -14.913 -14.912 0.001 -Fe_di 9.276e-05 - Fe_di+2 9.191e-05 6.054e-05 -4.037 -4.218 -0.181 - Fe_diCl+ 8.507e-07 7.664e-07 -6.070 -6.116 -0.045 - Fe_diOH+ 3.347e-09 3.016e-09 -8.475 -8.521 -0.045 -Fe_tri 7.236e-06 - Fe_tri(OH)2+ 6.928e-06 6.241e-06 -5.159 -5.205 -0.045 - Fe_triOH+2 1.817e-07 1.196e-07 -6.741 -6.922 -0.181 - Fe_tri(OH)3 1.263e-07 1.266e-07 -6.898 -6.897 0.001 - Fe_tri+3 3.010e-10 1.176e-10 -9.521 -9.929 -0.408 - Fe_triCl+2 4.947e-11 3.258e-11 -10.306 -10.487 -0.181 - Fe_tri(OH)4- 2.020e-11 1.819e-11 -10.695 -10.740 -0.045 - Fe_tri2(OH)2+4 2.047e-12 3.853e-13 -11.689 -12.414 -0.725 - Fe_triCl2+ 1.482e-12 1.335e-12 -11.829 -11.875 -0.045 - Fe_tri3(OH)4+5 6.830e-15 5.024e-16 -14.166 -15.299 -1.133 - Fe_triCl3 1.221e-15 1.224e-15 -14.913 -14.912 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.019e-03 -2.000 -2.045 -0.045 - NaOH 9.365e-12 9.387e-12 -11.029 -11.027 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 6. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 50400 seconds (Incremented time: 86400 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -2.406e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -6.016e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 9.036e-05 9.036e-05 - Fe_tri 9.642e-06 9.642e-06 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 5.075 Charge balance - pe = 15.538 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.029e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 9.873e-06 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.884e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 22 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 9.220e-06 8.414e-06 -5.035 -5.075 -0.040 - OH- 1.323e-09 1.189e-09 -8.878 -8.925 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 8.287e-07 7.466e-07 -6.082 -6.127 -0.045 - Fe_triCl+2 1.154e-10 7.603e-11 -9.938 -10.119 -0.181 - Fe_triCl2+ 3.457e-12 3.115e-12 -11.461 -11.507 -0.045 - Fe_triCl3 2.850e-15 2.857e-15 -14.545 -14.544 0.001 -Fe_di 9.036e-05 - Fe_di+2 8.953e-05 5.897e-05 -4.048 -4.229 -0.181 - Fe_diCl+ 8.287e-07 7.466e-07 -6.082 -6.127 -0.045 - Fe_diOH+ 2.459e-09 2.216e-09 -8.609 -8.655 -0.045 -Fe_tri 9.642e-06 - Fe_tri(OH)2+ 9.195e-06 8.284e-06 -5.036 -5.082 -0.045 - Fe_triOH+2 3.197e-07 2.106e-07 -6.495 -6.677 -0.181 - Fe_tri(OH)3 1.265e-07 1.268e-07 -6.898 -6.897 0.001 - Fe_tri+3 7.023e-10 2.745e-10 -9.153 -9.561 -0.408 - Fe_triCl+2 1.154e-10 7.603e-11 -9.938 -10.119 -0.181 - Fe_tri(OH)4- 1.525e-11 1.374e-11 -10.817 -10.862 -0.045 - Fe_tri2(OH)2+4 6.340e-12 1.193e-12 -11.198 -11.923 -0.725 - Fe_triCl2+ 3.457e-12 3.115e-12 -11.461 -11.507 -0.045 - Fe_tri3(OH)4+5 2.807e-14 2.065e-15 -13.552 -14.685 -1.133 - Fe_triCl3 2.850e-15 2.857e-15 -14.545 -14.544 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 7.063e-12 7.080e-12 -11.151 -11.150 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 7. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 86400 seconds (Incremented time: 172800 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -2.462e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -6.156e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 8.790e-05 8.790e-05 - Fe_tri 1.210e-05 1.210e-05 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 4.979 Charge balance - pe = 15.634 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.029e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.233e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.894e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 21 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.150e-05 1.050e-05 -4.939 -4.979 -0.040 - OH- 1.061e-09 9.534e-10 -8.974 -9.021 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 8.062e-07 7.263e-07 -6.094 -6.139 -0.045 - Fe_triCl+2 2.242e-10 1.477e-10 -9.649 -9.831 -0.181 - Fe_triCl2+ 6.716e-12 6.050e-12 -11.173 -11.218 -0.045 - Fe_triCl3 5.536e-15 5.549e-15 -14.257 -14.256 0.001 -Fe_di 8.790e-05 - Fe_di+2 8.709e-05 5.737e-05 -4.060 -4.241 -0.181 - Fe_diCl+ 8.062e-07 7.263e-07 -6.094 -6.139 -0.045 - Fe_diOH+ 1.918e-09 1.728e-09 -8.717 -8.763 -0.045 -Fe_tri 1.210e-05 - Fe_tri(OH)2+ 1.148e-05 1.034e-05 -4.940 -4.985 -0.045 - Fe_triOH+2 4.978e-07 3.279e-07 -6.303 -6.484 -0.181 - Fe_tri(OH)3 1.266e-07 1.269e-07 -6.898 -6.897 0.001 - Fe_tri+3 1.364e-09 5.332e-10 -8.865 -9.273 -0.408 - Fe_triCl+2 2.242e-10 1.477e-10 -9.649 -9.831 -0.181 - Fe_tri2(OH)2+4 1.537e-11 2.894e-12 -10.813 -11.539 -0.725 - Fe_tri(OH)4- 1.223e-11 1.102e-11 -10.912 -10.958 -0.045 - Fe_triCl2+ 6.716e-12 6.050e-12 -11.173 -11.218 -0.045 - Fe_tri3(OH)4+5 8.494e-14 6.251e-15 -13.071 -14.204 -1.133 - Fe_triCl3 5.536e-15 5.549e-15 -14.257 -14.256 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 5.662e-12 5.676e-12 -11.247 -11.246 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 8. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 172800 seconds (Incremented time: 345600 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -3.088e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -7.722e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 8.481e-05 8.481e-05 - Fe_tri 1.519e-05 1.519e-05 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 4.884 Charge balance - pe = 15.729 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.028e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.542e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 6.894e-15 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 21 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.431e-05 1.306e-05 -4.844 -4.884 -0.040 - OH- 8.523e-10 7.662e-10 -9.069 -9.116 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 7.779e-07 7.008e-07 -6.109 -6.154 -0.045 - Fe_triCl+2 4.323e-10 2.848e-10 -9.364 -9.546 -0.181 - Fe_triCl2+ 1.295e-11 1.167e-11 -10.888 -10.933 -0.045 - Fe_triCl3 1.068e-14 1.070e-14 -13.972 -13.971 0.001 -Fe_di 8.481e-05 - Fe_di+2 8.403e-05 5.535e-05 -4.076 -4.257 -0.181 - Fe_diCl+ 7.779e-07 7.008e-07 -6.109 -6.154 -0.045 - Fe_diOH+ 1.487e-09 1.340e-09 -8.828 -8.873 -0.045 -Fe_tri 1.519e-05 - Fe_tri(OH)2+ 1.429e-05 1.288e-05 -4.845 -4.890 -0.045 - Fe_triOH+2 7.712e-07 5.080e-07 -6.113 -6.294 -0.181 - Fe_tri(OH)3 1.266e-07 1.269e-07 -6.897 -6.896 0.001 - Fe_tri+3 2.630e-09 1.028e-09 -8.580 -8.988 -0.408 - Fe_triCl+2 4.323e-10 2.848e-10 -9.364 -9.546 -0.181 - Fe_tri2(OH)2+4 3.689e-11 6.947e-12 -10.433 -11.158 -0.725 - Fe_triCl2+ 1.295e-11 1.167e-11 -10.888 -10.933 -0.045 - Fe_tri(OH)4- 9.835e-12 8.861e-12 -11.007 -11.053 -0.045 - Fe_tri3(OH)4+5 2.539e-13 1.869e-14 -12.595 -13.728 -1.133 - Fe_triCl3 1.068e-14 1.070e-14 -13.972 -13.971 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 4.550e-12 4.561e-12 -11.342 -11.341 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 9. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 172800 seconds (Incremented time: 518400 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -2.157e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -5.393e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 8.265e-05 8.265e-05 - Fe_tri 1.735e-05 1.735e-05 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 4.829 Charge balance - pe = 15.784 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.028e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.758e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 5.287e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 18 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.624e-05 1.482e-05 -4.789 -4.829 -0.040 - OH- 7.509e-10 6.751e-10 -9.124 -9.171 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 7.581e-07 6.830e-07 -6.120 -6.166 -0.045 - Fe_triCl+2 6.322e-10 4.164e-10 -9.199 -9.380 -0.181 - Fe_triCl2+ 1.894e-11 1.706e-11 -10.723 -10.768 -0.045 - Fe_triCl3 1.561e-14 1.565e-14 -13.807 -13.806 0.001 -Fe_di 8.265e-05 - Fe_di+2 8.189e-05 5.395e-05 -4.087 -4.268 -0.181 - Fe_diCl+ 7.581e-07 6.830e-07 -6.120 -6.166 -0.045 - Fe_diOH+ 1.277e-09 1.150e-09 -8.894 -8.939 -0.045 -Fe_tri 1.735e-05 - Fe_tri(OH)2+ 1.622e-05 1.462e-05 -4.790 -4.835 -0.045 - Fe_triOH+2 9.937e-07 6.546e-07 -6.003 -6.184 -0.181 - Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 - Fe_tri+3 3.845e-09 1.503e-09 -8.415 -8.823 -0.408 - Fe_triCl+2 6.322e-10 4.164e-10 -9.199 -9.380 -0.181 - Fe_tri2(OH)2+4 6.124e-11 1.153e-11 -10.213 -10.938 -0.725 - Fe_triCl2+ 1.894e-11 1.706e-11 -10.723 -10.768 -0.045 - Fe_tri(OH)4- 8.668e-12 7.809e-12 -11.062 -11.107 -0.045 - Fe_tri3(OH)4+5 4.783e-13 3.522e-14 -12.320 -13.453 -1.133 - Fe_triCl3 1.561e-14 1.565e-14 -13.807 -13.806 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 4.009e-12 4.019e-12 -11.397 -11.396 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 10. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 172800 seconds (Incremented time: 691200 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.711e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -4.279e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 8.094e-05 8.094e-05 - Fe_tri 1.906e-05 1.906e-05 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 4.790 Charge balance - pe = 15.822 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.028e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 1.929e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 5.594e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 18 - Total H = 1.110124e+02 - Total O = 5.550669e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.776e-05 1.621e-05 -4.751 -4.790 -0.040 - OH- 6.869e-10 6.175e-10 -9.163 -9.209 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 7.425e-07 6.689e-07 -6.129 -6.175 -0.045 - Fe_triCl+2 8.261e-10 5.442e-10 -9.083 -9.264 -0.181 - Fe_triCl2+ 2.475e-11 2.230e-11 -10.606 -10.652 -0.045 - Fe_triCl3 2.040e-14 2.045e-14 -13.690 -13.689 0.001 -Fe_di 8.094e-05 - Fe_di+2 8.020e-05 5.283e-05 -4.096 -4.277 -0.181 - Fe_diCl+ 7.425e-07 6.689e-07 -6.129 -6.175 -0.045 - Fe_diOH+ 1.144e-09 1.031e-09 -8.942 -8.987 -0.045 -Fe_tri 1.906e-05 - Fe_tri(OH)2+ 1.774e-05 1.598e-05 -4.751 -4.796 -0.045 - Fe_triOH+2 1.188e-06 7.825e-07 -5.925 -6.107 -0.181 - Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 - Fe_tri+3 5.025e-09 1.965e-09 -8.299 -8.707 -0.408 - Fe_triCl+2 8.261e-10 5.442e-10 -9.083 -9.264 -0.181 - Fe_tri2(OH)2+4 8.749e-11 1.648e-11 -10.058 -10.783 -0.725 - Fe_triCl2+ 2.475e-11 2.230e-11 -10.606 -10.652 -0.045 - Fe_tri(OH)4- 7.930e-12 7.145e-12 -11.101 -11.146 -0.045 - Fe_tri3(OH)4+5 7.472e-13 5.503e-14 -12.127 -13.259 -1.133 - Fe_triCl3 2.040e-14 2.045e-14 -13.690 -13.689 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 3.667e-12 3.676e-12 -11.436 -11.435 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - -Reaction step 11. - -Using solution 1. -Using pure phase assemblage 1. -Using kinetics 1. Kinetics defined in simulation 2. - -Kinetics 1. Kinetics defined in simulation 2. - - Time step: 172800 seconds (Incremented time: 864000 seconds) - - Rate name Delta Moles Total Moles Reactant Coefficient - - Fe_di_ox -1.441e-06 1.000e+00 Fe_di -1 - Fe_tri 1 - --------------------------------Phase assemblage-------------------------------- - - Moles in assemblage - Phase SI log IAP log KT Initial Final Delta - - O2(g) -0.67 82.45 83.12 1.000e+01 1.000e+01 -3.603e-07 - ------------------------------Solution composition------------------------------ - - Elements Molality Moles - - Cl 1.020e-02 1.020e-02 - Fe_di 7.950e-05 7.950e-05 - Fe_tri 2.050e-05 2.050e-05 - Na 1.000e-02 1.000e-02 - -----------------------------Description of solution---------------------------- - - pH = 4.760 Charge balance - pe = 15.852 Adjusted to redox equilibrium - Activity of water = 1.000 - Ionic strength = 1.028e-02 - Mass of water (kg) = 1.000e+00 - Total alkalinity (eq/kg) = 2.073e-05 - Total carbon (mol/kg) = 0.000e+00 - Total CO2 (mol/kg) = 0.000e+00 - Temperature (deg C) = 25.000 - Electrical balance (eq) = 5.638e-14 - Percent error, 100*(Cat-|An|)/(Cat+|An|) = 0.00 - Iterations = 18 - Total H = 1.110124e+02 - Total O = 5.550670e+01 - -----------------------------Distribution of species---------------------------- - - Log Log Log - Species Molality Activity Molality Activity Gamma - - H+ 1.902e-05 1.736e-05 -4.721 -4.760 -0.040 - OH- 6.413e-10 5.765e-10 -9.193 -9.239 -0.046 - H2O 5.551e+01 9.997e-01 1.744 -0.000 0.000 -Cl 1.020e-02 - Cl- 1.020e-02 9.172e-03 -1.991 -2.038 -0.046 - Fe_diCl+ 7.293e-07 6.570e-07 -6.137 -6.182 -0.045 - Fe_triCl+2 1.015e-09 6.689e-10 -8.993 -9.175 -0.181 - Fe_triCl2+ 3.042e-11 2.740e-11 -10.517 -10.562 -0.045 - Fe_triCl3 2.508e-14 2.513e-14 -13.601 -13.600 0.001 -Fe_di 7.950e-05 - Fe_di+2 7.877e-05 5.189e-05 -4.104 -4.285 -0.181 - Fe_diCl+ 7.293e-07 6.570e-07 -6.137 -6.182 -0.045 - Fe_diOH+ 1.049e-09 9.450e-10 -8.979 -9.025 -0.045 -Fe_tri 2.050e-05 - Fe_tri(OH)2+ 1.900e-05 1.712e-05 -4.721 -4.766 -0.045 - Fe_triOH+2 1.363e-06 8.979e-07 -5.866 -6.047 -0.181 - Fe_tri(OH)3 1.267e-07 1.270e-07 -6.897 -6.896 0.001 - Fe_tri+3 6.176e-09 2.415e-09 -8.209 -8.617 -0.408 - Fe_triCl+2 1.015e-09 6.689e-10 -8.993 -9.175 -0.181 - Fe_tri2(OH)2+4 1.152e-10 2.170e-11 -9.939 -10.664 -0.725 - Fe_triCl2+ 3.042e-11 2.740e-11 -10.517 -10.562 -0.045 - Fe_tri(OH)4- 7.405e-12 6.671e-12 -11.130 -11.176 -0.045 - Fe_tri3(OH)4+5 1.054e-12 7.762e-14 -11.977 -13.110 -1.133 - Fe_triCl3 2.508e-14 2.513e-14 -13.601 -13.600 0.001 -H(0) 0.000e+00 - H2 0.000e+00 0.000e+00 -44.376 -44.375 0.001 -Na 1.000e-02 - Na+ 1.000e-02 9.020e-03 -2.000 -2.045 -0.045 - NaOH 3.424e-12 3.432e-12 -11.465 -11.464 0.001 -O(0) 4.677e-04 - O2 2.339e-04 2.344e-04 -3.631 -3.630 0.001 - -------------------------------Saturation indices------------------------------- - - Phase SI log IAP log KT - - Goethite 6.66 5.66 -1.00 Fe_triOOH - H2(g) -41.23 -44.38 -3.15 H2 - H2O(g) -1.51 -0.00 1.51 H2O - Halite -5.66 -4.08 1.58 NaCl - O2(g) -0.67 -3.63 -2.96 O2 - ------------------- -End of simulation. ------------------- - ------------------------------------- -Reading input data for simulation 3. ------------------------------------- - ------------ -End of run. ------------ - -No memory leaks diff --git a/Sun/examples/ex9.sel b/Sun/examples/ex9.sel deleted file mode 100644 index 98dc3b1e..00000000 --- a/Sun/examples/ex9.sel +++ /dev/null @@ -1,13 +0,0 @@ - Days Fe(2) Fe(3) pH si_goethite - 0.0000e+00 1.0000e+02 0.0000e+00 7.0000e+00 -9.9990e+01 - 1.1574e-03 9.8942e+01 1.0578e+00 6.0476e+00 6.6424e+00 - 5.7870e-03 9.8206e+01 1.7942e+00 5.8097e+00 6.6543e+00 - 4.1667e-02 9.6592e+01 3.4082e+00 5.5247e+00 6.6602e+00 - 1.6667e-01 9.4639e+01 5.3610e+00 5.3268e+00 6.6620e+00 - 4.1667e-01 9.2764e+01 7.2360e+00 5.1975e+00 6.6627e+00 - 1.0000e+00 9.0358e+01 9.6422e+00 5.0750e+00 6.6632e+00 - 2.0000e+00 8.7896e+01 1.2104e+01 4.9790e+00 6.6635e+00 - 4.0000e+00 8.4808e+01 1.5192e+01 4.8840e+00 6.6638e+00 - 6.0000e+00 8.2651e+01 1.7349e+01 4.8290e+00 6.6639e+00 - 8.0000e+00 8.0939e+01 1.9061e+01 4.7903e+00 6.6640e+00 - 1.0000e+01 7.9498e+01 2.0502e+01 4.7605e+00 6.6640e+00 diff --git a/advection.cpp b/advection.cpp deleted file mode 100644 index 9453c372..00000000 --- a/advection.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: advection.c 78 2005-02-01 22:47:12Z dlpark $"; - -/* ---------------------------------------------------------------------- */ -int advection(void) -/* ---------------------------------------------------------------------- */ -{ - int i, n; - LDBLE kin_time; - if (svnid == NULL) fprintf(stderr," "); -/* - * Calculate advection - */ - state = ADVECTION; -/* mass_water_switch = TRUE; */ -/* - * Check existence of all solutions - */ - for (i = 0; i <= count_ad_cells; i++) { - if (solution_bsearch(i, &n, TRUE) == NULL) { - input_error++; - sprintf(error_string, "Solution %d is needed for advection, but is not defined.", i); - error_msg(error_string, CONTINUE); - } - } -/* - * Check kinetics logic - */ - kin_time = advection_kin_time; - if (kin_time <= 0.0) { - for (i = 1; i <= count_ad_cells; i++) { - if (kinetics_bsearch(i, &n) != NULL) { - input_error++; - sprintf(error_string, "KINETIC reaction(s) defined, but time_step is not defined in ADVECTION keyword."); - error_msg(error_string, CONTINUE); - break; - } - } - } -/* - * Quit on error - */ - if (input_error > 0) { - error_msg("Program terminating due to input errors.", STOP); - } -/* - * Equilibrate solutions with phases, exchangers, surfaces - */ - last_model.force_prep = TRUE; - rate_sim_time_start = 0; - for (advection_step = 1; advection_step <= count_ad_shifts; advection_step++) { - output_msg(OUTPUT_LOG, "\nBeginning of advection time step %d, cumulative pore volumes %f.\n", advection_step, (double) (((LDBLE) advection_step) / ((LDBLE) count_ad_cells))); - if (pr.use == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE, "Beginning of advection time step %d, cumulative pore volumes %f.\n", - advection_step, (double) (((LDBLE) advection_step) / ((LDBLE) count_ad_cells))); - } -/* - * Advect - */ - for (i = count_ad_cells; i > 0; i--) { - solution_duplicate(i - 1, i); - } -/* - * Equilibrate and (or) mix - */ - for (i = 1; i <= count_ad_cells; i++) { - - cell_no = i; - set_advection(i, TRUE, TRUE, i); - run_reactions(i, kin_time, TRUE, 1.0); - if (advection_kin_time_defined == TRUE) { - rate_sim_time = rate_sim_time_start + kin_time; - } - output_msg(OUTPUT_LOG, "\nCell %d.\n\n", i); - if (pr.use == TRUE && pr.all == TRUE && - advection_step % print_ad_modulus == 0 && - advection_print[i-1] == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nCell %d.\n\n", i); - } - if (advection_step % punch_ad_modulus == 0 && - advection_punch[i-1] == TRUE ) { - punch_all(); - } - if (advection_step % print_ad_modulus == 0 && - advection_print[i-1] == TRUE ) { - print_all(); - } - if (i > 1) solution_duplicate(-2, i-1); - saver(); - } - solution_duplicate(-2, count_ad_cells); - rate_sim_time_start += kin_time; - } - initial_total_time += rate_sim_time_start; - /* free_model_allocs(); */ - mass_water_switch = FALSE; - return(OK); -} diff --git a/basic.cpp b/basic.cpp deleted file mode 100644 index 5b567552..00000000 --- a/basic.cpp +++ /dev/null @@ -1,4400 +0,0 @@ -/* Output from p2c, the Pascal-to-C translator */ -/* From input file "basic.p" */ - - -static char const svnid[] = "$Id: basic.c 247 2005-04-14 13:47:35Z dlpark $"; - -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -int n_user_punch_index; -#ifdef PHREEQ98 -void GridChar(char* s, char* a); -extern int colnr, rownr; -#endif - -#include "p2c.h" - -static int sget_logical_line(char **ptr, int *l, char *return_line); - -#define checking true -#define varnamelen 20 -#define maxdims 4 - -typedef Char varnamestring[varnamelen + 1]; -typedef Char string255[256]; - -#define tokvar 0 -#define toknum 1 -#define tokstr 2 -#define toksnerr 3 -#define tokplus 4 -#define tokminus 5 -#define toktimes 6 -#define tokdiv 7 -#define tokup 8 -#define toklp 9 -#define tokrp 10 -#define tokcomma 11 -#define toksemi 12 -#define tokcolon 13 -#define tokeq 14 -#define toklt 15 -#define tokgt 16 -#define tokle 17 -#define tokge 18 -#define tokne 19 -#define tokand 20 -#define tokor 21 -#define tokxor 22 -#define tokmod 23 -#define toknot 24 -#define toksqr 25 -#define toksqrt 26 -#define toksin 27 -#define tokcos 28 -#define toktan 29 -#define tokarctan 30 -#define toklog 31 -#define tokexp 32 -#define tokabs 33 -#define toksgn 34 -#define tokstr_ 35 -#define tokval 36 -#define tokchr_ 37 -#define tokasc 38 -#define toklen 39 -#define tokmid_ 40 -#define tokpeek 41 -#define tokrem 42 -#define toklet 43 -#define tokprint 44 -#define tokinput 45 -#define tokgoto 46 -#define tokif 47 -#define tokend 48 -#define tokstop 49 -#define tokfor 50 -#define toknext 51 -#define tokwhile 52 -#define tokwend 53 -#define tokgosub 54 -#define tokreturn 55 -#define tokread 56 -#define tokdata 57 -#define tokrestore 58 -#define tokgotoxy 59 -#define tokon 60 -#define tokdim 61 -#define tokpoke 62 -#define toklist 63 -#define tokrun 64 -#define toknew 65 -#define tokload 66 -#define tokmerge 67 -#define toksave 68 -#define tokbye 69 -#define tokdel 70 -#define tokrenum 71 -#define tokthen 72 -#define tokelse 73 -#define tokto 74 -#define tokstep 75 -#define toktc 76 -#define tokm0 77 -#define tokm 78 -#define tokparm 79 -#define tokact 80 -#define tokmol 81 -#define tokla 82 -#define toklm 83 -#define toksr 84 -#define toksi 85 -#define toktot 86 -#define toktk 87 -#define toktime 88 -#define toklog10 89 -#define toksim_time 90 -#define tokequi 91 -#define tokgas 92 -#define tokpunch 93 -#define tokkin 94 -#define toks_s 95 -#define tokmu 96 -#define tokalk 97 -#define tokrxn 98 -#define tokdist 99 -#define tokmisc1 100 -#define tokmisc2 101 -#define tokedl 102 -#define tokstep_no 103 -#define toksim_no 104 -#define toktotal_time 105 -#define tokput 106 -#define tokget 107 -#define tokcharge_balance 109 -#define tokpercent_error 110 -#ifdef PHREEQ98 -#define tokgraph_x 111 -#define tokgraph_y 112 -#define tokgraph_sy 113 -#endif -#define tokcell_no 114 -#define tokexists 115 -#define toksurf 116 -#define toklk_species 117 -#define toklk_named 118 -#define toklk_phase 119 -#define toksum_species 120 -#define toksum_gas 121 -#define toksum_s_s 122 -#define tokcalc_value 123 -#define tokdescription 124 -#define toksys 125 -#define tokinstr 126 -#define tokltrim 127 -#define tokrtrim 128 -#define toktrim 129 -#define tokpad 130 - -typedef LDBLE numarray[]; -typedef Char *strarray[]; - -#define forloop 0 -#define whileloop 1 -#define gosubloop 2 - -typedef struct tokenrec { - struct tokenrec *next; - int kind; - union { - struct varrec *vp; - LDBLE num; - Char *sp; - Char snch; - } UU; -} tokenrec; - -typedef struct linerec { - long num, num2; - tokenrec *txt; - struct linerec *next; -} linerec; - -typedef struct varrec { - varnamestring name; - struct varrec *next; - long dims[maxdims]; - char numdims; - boolean stringvar; - union { - struct { - LDBLE *arr; - LDBLE *val, rv; - } U0; - struct { - Char **sarr; - Char **sval, *sv; - } U1; - } UU; -} varrec; - -typedef struct valrec { - boolean stringval; - union { - LDBLE val; - Char *sval; - } UU; -} valrec; - -typedef struct looprec { - struct looprec *next; - linerec *homeline; - tokenrec *hometok; - int kind; - union { - struct { - varrec *vp; - LDBLE max, step; - } U0; - } UU; -} looprec; - - -Static Char *inbuf; -Static linerec *linebase; -Static varrec *varbase; -Static looprec *loopbase; -Static long curline; -Static linerec *stmtline, *dataline; -Static tokenrec *stmttok, *datatok, *buf; -Static boolean exitflag; - -Static int free_dim_stringvar(struct varrec *varbase); -extern long EXCP_LINE; -Static void parseinput(tokenrec **buf); -Static void exec(void); -Static void disposetokens(tokenrec **tok); - -/*$if not checking$ - $range off$ -$end$*/ -static HashTable *command_hash_table; -static const struct key command[] = { - {"and", tokand}, - {"or", tokor}, - {"xor", tokxor}, - {"not", toknot}, - {"mod", tokmod}, - {"sqr", toksqr}, - {"sqrt", toksqrt}, - {"sin", toksin}, - {"cos", tokcos}, - {"tan", toktan}, - {"arctan", tokarctan}, - {"log", toklog}, - {"exp", tokexp}, - {"abs", tokabs}, - {"sgn", toksgn}, - {"str$", tokstr_}, - {"val", tokval}, - {"chr$", tokchr_}, - {"asc", tokasc}, - {"len", toklen}, - {"mid$", tokmid_}, - {"peek", tokpeek}, - {"let", toklet}, - {"print", tokprint}, - {"punch", tokpunch}, -#ifdef PHREEQ98 - {"graph_x", tokgraph_x}, - {"graph_y", tokgraph_y}, - {"graph_sy", tokgraph_sy}, -#endif - {"input", tokinput}, - {"goto", tokgoto}, - {"go to", tokgoto}, - {"if", tokif}, - {"end", tokend}, - {"stop", tokstop}, - {"for", tokfor}, - {"next", toknext}, - {"while", tokwhile}, - {"wend", tokwend}, - {"gosub", tokgosub}, - {"return", tokreturn}, - {"read", tokread}, - {"data", tokdata}, - {"restore", tokrestore}, - {"gotoxy", tokgotoxy}, - {"on", tokon}, - {"dim", tokdim}, - {"poke", tokpoke}, - {"list", toklist}, - {"run", tokrun}, - {"new", toknew}, - {"load", tokload}, - {"merge", tokmerge}, - {"save", toksave}, - {"bye", tokbye}, - {"quit", tokbye}, - {"del", tokdel}, - {"renum", tokrenum}, - {"then", tokthen}, - {"else", tokelse}, - {"to", tokto}, - {"step", tokstep}, - {"tc", toktc}, - {"tk", toktk}, - {"time", toktime}, - {"sim_time", toksim_time}, - {"total_time", toktotal_time}, - {"m0", tokm0}, - {"m", tokm}, - {"parm", tokparm}, - {"act", tokact}, - {"edl", tokedl}, - {"surf", toksurf}, - {"equi", tokequi}, - {"kin", tokkin}, - {"gas", tokgas}, - {"s_s", toks_s}, - {"misc1", tokmisc1}, - {"misc2", tokmisc2}, - {"mu", tokmu}, - {"alk", tokalk}, - {"lk_species", toklk_species}, - {"lk_named", toklk_named}, - {"lk_phase", toklk_phase}, - {"sum_species", toksum_species}, - {"sum_gas", toksum_gas}, - {"sum_s_s", toksum_s_s}, - {"calc_value", tokcalc_value}, - {"description", tokdescription}, - {"sys", toksys}, - {"instr", tokinstr}, - {"ltrim", tokltrim}, - {"rtrim", tokrtrim}, - {"trim", toktrim}, - {"pad", tokpad}, - {"rxn", tokrxn}, - {"dist", tokdist}, - {"mol", tokmol}, - {"la", tokla}, - {"lm", toklm}, - {"sr", toksr}, - {"si", toksi}, - {"step_no", tokstep_no}, - {"cell_no", tokcell_no}, - {"sim_no", toksim_no}, - {"tot", toktot}, - {"log10", toklog10}, - {"charge_balance", tokcharge_balance}, - {"percent_error", tokpercent_error}, - {"put", tokput}, - {"get", tokget}, - {"exists", tokexists}, - {"rem", tokrem} -}; -static int NCMDS = (sizeof(command) / sizeof(struct key)); - -/* ---------------------------------------------------------------------- */ -void cmd_initialize(void) -/* ---------------------------------------------------------------------- */ -{ - ENTRY item, *found_item; - int i; -/* - * create hash table - */ - hcreate_multi((unsigned) 2*NCMDS, &command_hash_table); -/* - * fill with commands - */ - for (i = 0; i < NCMDS; i++) { - item.key = command[i].name; - item.data = (void *) &command[i]; - found_item = hsearch_multi(command_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in basic commands initialization."); - error_msg(error_string, STOP); - } - } - return; -} -/* ---------------------------------------------------------------------- */ -void cmd_free(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * destroy hash table - */ - hdestroy_multi(command_hash_table); - command_hash_table = NULL; - return; -} - -#ifdef SKIP -int main(int argc, Char *argv[]) -{ /*main*/ - char commands[] = "10a=1\n20a=a*2;30print a;40quit;run"; - basic_main(commands); - return 0; -} -#endif -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) -{ /*main*/ - int l; - char *ptr; - if (svnid == NULL) fprintf(stderr," "); - - PASCAL_MAIN(0, NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - do { - TRY(try2); - ptr = commands; - do { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) { - strcpy(inbuf, "bye"); - } - parseinput(&buf); - if (curline == 0) { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) { -#ifdef SKIP - printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); -#endif - sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); - error_msg(error_string, CONTINUE); - } else { - putchar('\n'); - } - ENDTRY(try2); - } while (!(exitflag || P_eof())); - /* exit(EXIT_SUCCESS); */ - free(inbuf); - *lnbase = (void *) linebase; - *vbase = (void *) varbase; - *lpbase = (void *) loopbase; - return(P_escapecode); -} -int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) -{ /*main*/ - int l, i; - char *ptr; - PASCAL_MAIN(0,NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - do { - TRY(try2); - i = 0; - ptr = commands; - do { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) { - i++; - if (i == 1) { - strcpy(inbuf, "renum"); - } else if (i == 2) { - strcpy(inbuf, "list"); - } else if (i == 3) { - strcpy(inbuf, "new"); - } else if (i == 4) { - strcpy(inbuf, "bye"); - } - } - parseinput(&buf); - if (curline == 0) { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) { -#ifdef SKIP - printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); -#endif - sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); - error_msg(error_string, CONTINUE); - } else { - putchar('\n'); - } - ENDTRY(try2); - } while (!(exitflag || P_eof())); - /* exit(EXIT_SUCCESS); */ - free(inbuf); - *lnbase = (void *) linebase; - *vbase = (void *) varbase; - *lpbase = (void *) loopbase; - - return(P_escapecode); -} -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) -{ /*main*/ - int l; - char *ptr; - PASCAL_MAIN(0,NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if ( inbuf == NULL) malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - linebase = (linerec *) lnbase; - varbase = (varrec *) vbase; - loopbase = (looprec *) lpbase; - do { - TRY(try2); - do { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) { - strcpy(inbuf, "bye"); - } - parseinput(&buf); - if (curline == 0) { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) { -#ifdef SKIP - printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); -#endif - sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); - error_msg(error_string, CONTINUE); - } else { - putchar('\n'); - } - ENDTRY(try2); - } while (!(exitflag || P_eof())); - - /* exit(EXIT_SUCCESS); */ - free(inbuf); - return(P_escapecode); -} -int basic_main(char *commands) -{ /*main*/ - int l; - char *ptr; -#ifdef SKIP - PASCAL_MAIN(argc, argv); -#endif - PASCAL_MAIN(0,NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; -#ifdef SKIP - printf("Chipmunk BASIC 1.0\n\n"); -#endif - exitflag = false; - ptr = commands; - do { - TRY(try2); - do { -#ifdef SKIP - putchar('>'); -#endif - if (sget_logical_line(&ptr, &l, inbuf) == EOF) { - strcpy(inbuf, "bye"); - } -#ifdef SKIP - gets(inbuf); -#endif - parseinput(&buf); - if (curline == 0) { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) { -#ifdef SKIP - printf("Error %d/%d!\n", (int)P_escapecode, (int)P_ioresult); -#endif - sprintf(error_string,"%d/%d",(int)P_escapecode, (int)P_ioresult); - error_msg(error_string, CONTINUE); - } else { - putchar('\n'); - } - ENDTRY(try2); - } while (!(exitflag || P_eof())); - return 1; -/* exit(EXIT_SUCCESS); */ -} - - - - - - - -/* End. */ -/* ---------------------------------------------------------------------- */ -int sget_logical_line(char **ptr, int *l, char *return_line) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads file fp until end of line, ";", or eof - * stores characters in line_save - * reallocs line_save and line if more space is needed - * - * returns: - * EOF on empty line on end of file or - * OK otherwise - * *l returns length of line - */ - int i; - char c; - i = 0; - if (**ptr == '\0') return (EOF); - for (;;) { - c = **ptr; - if (c == '\0') break; - (*ptr)++; - if (c == ';' || c == '\n') break; - return_line[i++] = c; - } - return_line[i] = '\0'; - *l = i; - return(1); -} -Static void restoredata(void) -{ - dataline = NULL; - datatok = NULL; -} - - - -Static void clearloops(void) -{ - looprec *l; - - while (loopbase != NULL) { - l = loopbase->next; - free(loopbase); - loopbase = l; - } -} - - - -#ifdef SKIP -Static long arraysize(varrec *v) -{ - long i, j, FORLIM; - - if (v->stringvar) - j = 4; - else - j = 8; - FORLIM = v->numdims; - for (i = 0; i < FORLIM; i++) - j *= v->dims[i]; - return j; -} -#endif - -Static void clearvar(varrec *v) -{ - if (v->numdims != 0) { - if (v->stringvar == 0) { - free(v->UU.U0.arr); - v->UU.U0.arr = NULL; - } else { - free_dim_stringvar(v); - } - } else if (v->stringvar && v->UU.U1.sv != NULL) { - free(v->UU.U1.sv); - } - v->numdims = 0; - if (v->stringvar) { - v->UU.U1.sv = NULL; - v->UU.U1.sval = &v->UU.U1.sv; - } else { - v->UU.U0.rv = 0.0; - v->UU.U0.val = &v->UU.U0.rv; - } -} - - -Static void clearvars(void) -{ - varrec *v; - - v = varbase; - while (v != NULL) { - clearvar(v); - v = v->next; - } -} - -Static Char *numtostr(Char *Result, LDBLE n) -{ - /*string255 s;*/ - char *s; - long i; - - s = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (s == NULL) malloc_error(); - s[max_line - 1] = '\0'; -/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ - if (ceil(n) == floor(n)) { - if (punch.high_precision == FALSE) { - sprintf(s, "%12g", (double) n); - } else { - sprintf(s, "%19g", (double) n); - } - } else { - if (punch.high_precision == FALSE) { - sprintf(s, "%12.4e", (double) n); - } else { - sprintf(s, "%20.12e", (double) n); - } - } - i = strlen(s) + 1; - s[i - 1] = '\0'; -/* p2c: basic.p, line 237: - * Note: Modification of string length may translate incorrectly [146] */ - strcpy(Result, s); - free_check_null(s); - return (Result); -/* } else { - if (punch.high_precision == FALSE) sprintf(s, "%30.10f", n); - else sprintf(s, "%30.12f", n); - i = strlen(s) + 1; - do { - i--; - } while (s[i - 1] == '0'); - if (s[i - 1] == '.') - i--; - s[i] = '\0'; - * p2c: basic.p, line 248: - * Note: Modification of string length may translate incorrectly [146] * - return strcpy(Result, strltrim(s)); - } */ -} - -#define toklength 20 - - -typedef long chset[9]; - - - - - -Static void parse(Char *inbuf, tokenrec **buf) -{ - long i, j, begin, len, m; - Char token[toklength + 1]; - tokenrec *t, *tptr; - varrec *v; - Char ch; - ENTRY item, *found_item; - char *ptr; - - tptr = NULL; - *buf = NULL; - i = 1; - do { - ch = ' '; - while (i <= (int) strlen(inbuf) && (ch == ' ' || ch == '\t')) { - ch = inbuf[i - 1]; - i++; - } - if (ch != ' ') { - t = (tokenrec *) PHRQ_malloc(sizeof(tokenrec)); - if ( t == NULL) malloc_error(); - if (tptr == NULL) - *buf = t; - else - tptr->next = t; - tptr = t; - t->next = NULL; - switch (ch) { - - case '"': - case '\'': - t->kind = tokstr; - j = 0; - len = strlen(inbuf); - begin = i; - while (i <= len && inbuf[i - 1] != ch) { - ++j; - ++i; - } - m = 256; - if (j + 1 > m) m = j + 1; - t->UU.sp = (char *) PHRQ_malloc(m); - if (t->UU.sp == NULL) malloc_error(); - strncpy(t->UU.sp, inbuf + begin - 1, j); - t->UU.sp[j] = '\0'; -/* p2c: basic.p, line 415: - * Note: Modification of string length may translate incorrectly [146] */ - i++; - break; - - case '+': - t->kind = tokplus; - break; - - case '-': - t->kind = tokminus; - break; - - case '*': - t->kind = toktimes; - break; - - case '/': - t->kind = tokdiv; - break; - - case '^': - t->kind = tokup; - break; - - case '(': - case '[': - t->kind = toklp; - break; - - case ')': - case ']': - t->kind = tokrp; - break; - - case ',': - t->kind = tokcomma; - break; - - case ';': - t->kind = toksemi; - break; - - case ':': - t->kind = tokcolon; - break; - - case '?': - t->kind = tokprint; - break; - - case '=': - t->kind = tokeq; - break; - - case '<': - if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '=') { - t->kind = tokle; - i++; - } else if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '>') { - t->kind = tokne; - i++; - } else - t->kind = toklt; - break; - - case '>': - if (i <= (int) strlen(inbuf) && inbuf[i - 1] == '=') { - t->kind = tokge; - i++; - } else - t->kind = tokgt; - break; - - default: - if (isalpha((int) ch)) { - i--; - j = 0; - token[toklength] = '\0'; - while (i <= (int) strlen(inbuf) && - (inbuf[i - 1] == '$' || inbuf[i - 1] == '_' || - isalnum((int) inbuf[i - 1]))) { - if (j < toklength) { - j++; - token[j - 1] = inbuf[i - 1]; - } - i++; - } - token[j] = '\0'; -/* p2c: basic.p, line 309: - * Note: Modification of string length may translate incorrectly [146] */ -#define INT -#ifdef INT -/* - * Search hash list - */ - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(command_hash_table, item, FIND); - if (found_item != NULL) { - t->kind = ((struct key *) (found_item->data))->keycount; - if (t->kind == tokrem) { - m = strlen(inbuf) + 1; - if (m < 256) m = 256; - t->UU.sp = (char *) PHRQ_malloc(m); - if ( t->UU.sp == NULL) malloc_error(); - sprintf(t->UU.sp, "%.*s", - (int)(strlen(inbuf) - i + 1), inbuf + i - 1); - i = strlen(inbuf) + 1; - } -#endif -#ifdef LONG - if (!strcmp(token, "and")) - t->kind = tokand; - else if (!strcmp(token, "or")) - t->kind = tokor; - else if (!strcmp(token, "xor")) - t->kind = tokxor; - else if (!strcmp(token, "not")) - t->kind = toknot; - else if (!strcmp(token, "mod")) - t->kind = tokmod; - else if (!strcmp(token, "sqr")) - t->kind = toksqr; - else if (!strcmp(token, "sqrt")) - t->kind = toksqrt; - else if (!strcmp(token, "sin")) - t->kind = toksin; - else if (!strcmp(token, "cos")) - t->kind = tokcos; - else if (!strcmp(token, "tan")) - t->kind = toktan; - else if (!strcmp(token, "arctan")) - t->kind = tokarctan; - else if (!strcmp(token, "log")) - t->kind = toklog; - else if (!strcmp(token, "exp")) - t->kind = tokexp; - else if (!strcmp(token, "abs")) - t->kind = tokabs; - else if (!strcmp(token, "sgn")) - t->kind = toksgn; - else if (!strcmp(token, "str$")) - t->kind = tokstr_; - else if (!strcmp(token, "val")) - t->kind = tokval; - else if (!strcmp(token, "chr$")) - t->kind = tokchr_; - else if (!strcmp(token, "asc")) - t->kind = tokasc; - else if (!strcmp(token, "len")) - t->kind = toklen; - else if (!strcmp(token, "mid$")) - t->kind = tokmid_; - else if (!strcmp(token, "peek")) - t->kind = tokpeek; - else if (!strcmp(token, "let")) - t->kind = toklet; - else if (!strcmp(token, "print")) - t->kind = tokprint; - else if (!strcmp(token, "punch")) - t->kind = tokpunch; -#ifdef PHREEQ98 - else if (!strcmp(token, "graph_x")) - t->kind = tokgraph_x; - else if (!strcmp(token, "graph_y")) - t->kind = tokgraph_y; - else if (!strcmp(token, "graph_sy")) - t->kind = tokgraph_sy; -#endif - else if (!strcmp(token, "input")) - t->kind = tokinput; - else if (!strcmp(token, "goto")) - t->kind = tokgoto; - else if (!strcmp(token, "go to")) - t->kind = tokgoto; - else if (!strcmp(token, "if")) - t->kind = tokif; - else if (!strcmp(token, "end")) - t->kind = tokend; - else if (!strcmp(token, "stop")) - t->kind = tokstop; - else if (!strcmp(token, "for")) - t->kind = tokfor; - else if (!strcmp(token, "next")) - t->kind = toknext; - else if (!strcmp(token, "while")) - t->kind = tokwhile; - else if (!strcmp(token, "wend")) - t->kind = tokwend; - else if (!strcmp(token, "gosub")) - t->kind = tokgosub; - else if (!strcmp(token, "return")) - t->kind = tokreturn; - else if (!strcmp(token, "read")) - t->kind = tokread; - else if (!strcmp(token, "data")) - t->kind = tokdata; - else if (!strcmp(token, "restore")) - t->kind = tokrestore; - else if (!strcmp(token, "gotoxy")) - t->kind = tokgotoxy; - else if (!strcmp(token, "on")) - t->kind = tokon; - else if (!strcmp(token, "dim")) - t->kind = tokdim; - else if (!strcmp(token, "poke")) - t->kind = tokpoke; - else if (!strcmp(token, "list")) - t->kind = toklist; - else if (!strcmp(token, "run")) - t->kind = tokrun; - else if (!strcmp(token, "new")) - t->kind = toknew; - else if (!strcmp(token, "load")) - t->kind = tokload; - else if (!strcmp(token, "merge")) - t->kind = tokmerge; - else if (!strcmp(token, "save")) - t->kind = toksave; - else if (!strcmp(token, "bye")) - t->kind = tokbye; - else if (!strcmp(token, "quit")) - t->kind = tokbye; - else if (!strcmp(token, "del")) - t->kind = tokdel; - else if (!strcmp(token, "renum")) - t->kind = tokrenum; - else if (!strcmp(token, "then")) - t->kind = tokthen; - else if (!strcmp(token, "else")) - t->kind = tokelse; - else if (!strcmp(token, "to")) - t->kind = tokto; - else if (!strcmp(token, "step")) - t->kind = tokstep; -/* - * dlp: added functions - */ - else if (!strcmp(token, "tc")) - t->kind = toktc; - else if (!strcmp(token, "tk")) - t->kind = toktk; - else if (!strcmp(token, "time")) - t->kind = toktime; - else if (!strcmp(token, "sim_time")) - t->kind = toksim_time; - else if (!strcmp(token, "total_time")) - t->kind = toktotal_time; - else if (!strcmp(token, "m0")) - t->kind = tokm0; - else if (!strcmp(token, "m")) - t->kind = tokm; - else if (!strcmp(token, "parm")) - t->kind = tokparm; - else if (!strcmp(token, "act")) - t->kind = tokact; - else if (!strcmp(token, "edl")) - t->kind = tokedl; - else if (!strcmp(token, "surf")) - t->kind = toksurf; - else if (!strcmp(token, "equi")) - t->kind = tokequi; - else if (!strcmp(token, "kin")) - t->kind = tokkin; - else if (!strcmp(token, "gas")) - t->kind = tokgas; - else if (!strcmp(token, "s_s")) - t->kind = toks_s; - else if (!strcmp(token, "misc1")) - t->kind = tokmisc1; - else if (!strcmp(token, "misc2")) - t->kind = tokmisc2; - else if (!strcmp(token, "mu")) - t->kind = tokmu; - else if (!strcmp(token, "alk")) - t->kind = tokalk; - else if (!strcmp(token, "lk_species")) - t->kind = toklk_species; - else if (!strcmp(token, "lk_named")) - t->kind = toklk_named; - else if (!strcmp(token, "lk_phase")) - t->kind = toklk_phase; - else if (!strcmp(token, "sum_species")) - t->kind = toksum_species; - else if (!strcmp(token, "sum_gas")) - t->kind = toksum_gas; - else if (!strcmp(token, "sum_s_s")) - t->kind = toksum_s_s; - else if (!strcmp(token, "calc_value")) - t->kind = tokcalc_value; - else if (!strcmp(token, "description")) - t->kind = tokdescription; - else if (!strcmp(token, "sys")) - t->kind = toksys; - else if (!strcmp(token, "instr")) - t->kind = tokinstr; - else if (!strcmp(token, "ltrim")) - t->kind = tokltrim; - else if (!strcmp(token, "rtrim")) - t->kind = tokrtrim; - else if (!strcmp(token, "trim")) - t->kind = toktrim; - else if (!strcmp(token, "pad")) - t->kind = tokpad; - else if (!strcmp(token, "rxn")) - t->kind = tokrxn; - else if (!strcmp(token, "dist")) - t->kind = tokdist; - else if (!strcmp(token, "mol")) - t->kind = tokmol; - else if (!strcmp(token, "la")) - t->kind = tokla; - else if (!strcmp(token, "lm")) - t->kind = toklm; - else if (!strcmp(token, "sr")) - t->kind = toksr; - else if (!strcmp(token, "step_no")) - t->kind = tokstep_no; - else if (!strcmp(token, "cell_no")) - t->kind = tokcell_no; - else if (!strcmp(token, "sim_no")) - t->kind = toksim_no; - else if (!strcmp(token, "si")) - t->kind = toksi; - else if (!strcmp(token, "tot")) - t->kind = toktot; - else if (!strcmp(token, "log10")) - t->kind = toklog10; - else if (!strcmp(token, "put")) - t->kind = tokput; - else if (!strcmp(token, "get")) - t->kind = tokget; - else if (!strcmp(token, "exists")) - t->kind = tokexists; - else if (!strcmp(token, "charge_balance")) - t->kind = tokcharge_balance; - else if (!strcmp(token, "percent_error")) - t->kind = tokpercent_error; - else if (!strcmp(token, "rem")) { - t->kind = tokrem; - m = strlen(inbuf) + 1; - if (m < 256) m = 256; - t->UU.sp = (char *) PHRQ_malloc(m)); - if ( t->UU.sp == NULL) malloc_error(); - sprintf(t->UU.sp, "%.*s", - (int)(strlen(inbuf) - i + 1), inbuf + i - 1); - i = strlen(inbuf) + 1; -#endif - } else { - t->kind = tokvar; - v = varbase; - while (v != NULL && strcmp(v->name, token)) - v = v->next; - if (v == NULL) { - v = (varrec *) PHRQ_malloc(sizeof(varrec)); - if ( v == NULL) malloc_error(); - v->UU.U0.arr = NULL; - v->next = varbase; - varbase = v; - strcpy(v->name, token); - v->numdims = 0; - if (token[strlen(token) - 1] == '$') { - v->stringvar = true; - v->UU.U1.sv = NULL; - v->UU.U1.sval = &v->UU.U1.sv; - } else { - v->stringvar = false; - v->UU.U0.rv = 0.0; - v->UU.U0.val = &v->UU.U0.rv; - } - } - t->UU.vp = v; - } - } else if (isdigit((int) ch) || ch == '.') { - t->kind = toknum; - i--; - t->UU.num = strtod(&inbuf[i-1], &ptr); - if (&inbuf[i-1] == ptr) { - /* - Note: the following causes an infinite loop: - X = ..9 - */ - t->kind = toksnerr; - t->UU.snch = ch; - i++; - break; - } - i += (int) (ptr - &inbuf[i-1]); - } else { - t->kind = toksnerr; - t->UU.snch = ch; - } - break; - } - } - } while (i <= (int) strlen(inbuf)); -} - -#undef toklength - - - -Static void listtokens(FILE *f, tokenrec *buf) -{ - boolean ltr; - Char STR1[256]; - char *string; - ltr = false; - while (buf != NULL) { - if ((buf->kind >= (long)toknot && buf->kind <= (long)tokrenum) || - buf->kind == (long)toknum || buf->kind == (long)tokvar || - buf->kind >= (long)toktc) { - if (ltr) - /*putc(' ', f);*/ - output_msg(OUTPUT_BASIC, " "); - ltr = (boolean) (buf->kind != toknot); - } else - ltr = false; - switch (buf->kind) { - - case tokvar: - /*fputs(buf->UU.vp->name, f);*/ - output_msg(OUTPUT_BASIC, "%s", buf->UU.vp->name); - break; - - case toknum: - /*fputs(numtostr(STR1, buf->UU.num), f);*/ - string = numtostr(STR1, buf->UU.num); - string_trim(string); - output_msg(OUTPUT_BASIC, "%s", string); - break; - - case tokstr: - output_msg(OUTPUT_BASIC, "\"%s\"", buf->UU.sp); - break; - - case toksnerr: - output_msg(OUTPUT_BASIC, "{%c}", buf->UU.snch); - break; - - case tokplus: - /*putc('+', f);*/ - output_msg(OUTPUT_BASIC, "+"); - break; - - case tokminus: - /*putc('-', f);*/ - output_msg(OUTPUT_BASIC, "-"); - break; - - case toktimes: - /*putc('*', f);*/ - output_msg(OUTPUT_BASIC, "*"); - break; - - case tokdiv: - /*putc('/', f);*/ - output_msg(OUTPUT_BASIC, "/"); - break; - - case tokup: - /*putc('^', f);*/ - output_msg(OUTPUT_BASIC, "^"); - break; - - case toklp: - /*putc('(', f);*/ - output_msg(OUTPUT_BASIC, "("); - break; - - case tokrp: - /*putc(')', f);*/ - output_msg(OUTPUT_BASIC, ")"); - break; - - case tokcomma: - /*putc(',', f);*/ - output_msg(OUTPUT_BASIC, ","); - break; - - case toksemi: - /*putc(';', f);*/ - output_msg(OUTPUT_BASIC, ";"); - break; - - case tokcolon: - output_msg(OUTPUT_BASIC, " : "); - break; - - case tokeq: - output_msg(OUTPUT_BASIC, " = "); - break; - - case toklt: - output_msg(OUTPUT_BASIC, " < "); - break; - - case tokgt: - output_msg(OUTPUT_BASIC, " > "); - break; - - case tokle: - output_msg(OUTPUT_BASIC, " <= "); - break; - - case tokge: - output_msg(OUTPUT_BASIC, " >= "); - break; - - case tokne: - output_msg(OUTPUT_BASIC, " <> "); - break; - - case tokand: - output_msg(OUTPUT_BASIC, " AND "); - break; - - case tokor: - output_msg(OUTPUT_BASIC, " OR "); - break; - - case tokxor: - output_msg(OUTPUT_BASIC, " XOR "); - break; - - case tokmod: - output_msg(OUTPUT_BASIC, " MOD "); - break; - - case toknot: - output_msg(OUTPUT_BASIC, "NOT "); - break; - - case toksqr: - output_msg(OUTPUT_BASIC, "SQR"); - break; - - case toksqrt: - output_msg(OUTPUT_BASIC, "SQRT"); - break; - - case toksin: - output_msg(OUTPUT_BASIC, "SIN"); - break; - - case tokcos: - output_msg(OUTPUT_BASIC, "COS"); - break; - - case toktan: - output_msg(OUTPUT_BASIC, "TAN"); - break; - - case tokarctan: - output_msg(OUTPUT_BASIC, "ARCTAN"); - break; - - case toklog: - output_msg(OUTPUT_BASIC, "LOG"); - break; - - case tokexp: - output_msg(OUTPUT_BASIC, "EXP"); - break; - - case tokabs: - output_msg(OUTPUT_BASIC, "ABS"); - break; - - case toksgn: - output_msg(OUTPUT_BASIC, "SGN"); - break; - - case tokstr_: - output_msg(OUTPUT_BASIC, "STR$"); - break; - - case tokval: - output_msg(OUTPUT_BASIC, "VAL"); - break; - - case tokchr_: - output_msg(OUTPUT_BASIC, "CHR$"); - break; - - case tokasc: - output_msg(OUTPUT_BASIC, "ASC"); - break; - - case toklen: - output_msg(OUTPUT_BASIC, "LEN"); - break; - - case tokmid_: - output_msg(OUTPUT_BASIC, "MID$"); - break; - - case tokpeek: - output_msg(OUTPUT_BASIC, "PEEK"); - break; - - case tokrem: - output_msg(OUTPUT_BASIC, "REM%s", buf->UU.sp); - break; - - case toklet: - output_msg(OUTPUT_BASIC, "LET"); - break; - - case tokprint: - output_msg(OUTPUT_BASIC, "PRINT"); - break; - - case tokinput: - output_msg(OUTPUT_BASIC, "INPUT"); - break; - - case tokgoto: - output_msg(OUTPUT_BASIC, "GOTO"); - break; - - case tokif: - output_msg(OUTPUT_BASIC, "IF"); - break; - - case tokend: - output_msg(OUTPUT_BASIC, "END"); - break; - - case tokstop: - output_msg(OUTPUT_BASIC, "STOP"); - break; - - case tokfor: - output_msg(OUTPUT_BASIC, "FOR"); - break; - - case toknext: - output_msg(OUTPUT_BASIC, "NEXT"); - break; - - case tokwhile: - output_msg(OUTPUT_BASIC, "WHILE"); - break; - - case tokwend: - output_msg(OUTPUT_BASIC, "WEND"); - break; - - case tokgosub: - output_msg(OUTPUT_BASIC, "GOSUB"); - break; - - case tokreturn: - output_msg(OUTPUT_BASIC, "RETURN"); - break; - - case tokread: - output_msg(OUTPUT_BASIC, "READ"); - break; - - case tokdata: - output_msg(OUTPUT_BASIC, "DATA"); - break; - - case tokrestore: - output_msg(OUTPUT_BASIC, "RESTORE"); - break; - - case tokgotoxy: - output_msg(OUTPUT_BASIC, "GOTOXY"); - break; - - case tokon: - output_msg(OUTPUT_BASIC, "ON"); - break; - - case tokdim: - output_msg(OUTPUT_BASIC, "DIM"); - break; - - case tokpoke: - output_msg(OUTPUT_BASIC, "POKE"); - break; - - case toklist: - output_msg(OUTPUT_BASIC, "LIST"); - break; - - case tokrun: - output_msg(OUTPUT_BASIC, "RUN"); - break; - - case toknew: - output_msg(OUTPUT_BASIC, "NEW"); - break; - - case tokload: - output_msg(OUTPUT_BASIC, "LOAD"); - break; - - case tokmerge: - output_msg(OUTPUT_BASIC, "MERGE"); - break; - - case toksave: - output_msg(OUTPUT_BASIC, "SAVE"); - break; - - case tokbye: - output_msg(OUTPUT_BASIC, "BYE"); - break; - - case tokdel: - output_msg(OUTPUT_BASIC, "DEL"); - break; - - case tokrenum: - output_msg(OUTPUT_BASIC, "RENUM"); - break; - - case tokthen: - output_msg(OUTPUT_BASIC, " THEN "); - break; - - case tokelse: - output_msg(OUTPUT_BASIC, " ELSE "); - break; - - case tokto: - output_msg(OUTPUT_BASIC, " TO "); - break; - - case tokstep: - output_msg(OUTPUT_BASIC, " STEP "); - break; - - case toktc: - output_msg(OUTPUT_BASIC, "TC"); - break; - - case tokm0: - output_msg(OUTPUT_BASIC, "M0"); - break; - - case tokm: - output_msg(OUTPUT_BASIC, "M"); - break; - - case tokparm: - output_msg(OUTPUT_BASIC, "PARM"); - break; - - case tokact: - output_msg(OUTPUT_BASIC, "ACT"); - break; - - case tokmol: - output_msg(OUTPUT_BASIC, "MOL"); - break; - - case tokla: - output_msg(OUTPUT_BASIC, "LA"); - break; - - case toklm: - output_msg(OUTPUT_BASIC, "LM"); - break; - - case toksr: - output_msg(OUTPUT_BASIC, "SR"); - break; - - case toksi: - output_msg(OUTPUT_BASIC, "SI"); - break; - - case toktot: - output_msg(OUTPUT_BASIC, "TOT"); - break; - - case toktk: - output_msg(OUTPUT_BASIC, "TK"); - break; - - case toktime: - output_msg(OUTPUT_BASIC, "TIME"); - break; - - case toklog10: - output_msg(OUTPUT_BASIC, "LOG10"); - break; - - case toksim_time: - output_msg(OUTPUT_BASIC, "SIM_TIME"); - break; - - case tokequi: - output_msg(OUTPUT_BASIC, "EQUI"); - break; - - case tokgas: - output_msg(OUTPUT_BASIC, "GAS"); - break; - - case tokpunch: - output_msg(OUTPUT_BASIC, "PUNCH"); - break; - - case tokkin: - output_msg(OUTPUT_BASIC, "KIN"); - break; - - case toks_s: - output_msg(OUTPUT_BASIC, "S_S"); - break; - - case tokmu: - output_msg(OUTPUT_BASIC, "MU"); - break; - - case tokalk: - output_msg(OUTPUT_BASIC, "ALK"); - break; - - case toklk_species: - output_msg(OUTPUT_BASIC, "LK_SPECIES"); - break; - - case toklk_named: - output_msg(OUTPUT_BASIC, "LK_NAMED"); - break; - - case toklk_phase: - output_msg(OUTPUT_BASIC, "LK_PHASE"); - break; - - case toksum_species: - output_msg(OUTPUT_BASIC, "SUM_SPECIES"); - break; - - case toksum_gas: - output_msg(OUTPUT_BASIC, "SUM_GAS"); - break; - - case toksum_s_s: - output_msg(OUTPUT_BASIC, "SUM_s_s"); - break; - - case tokcalc_value: - output_msg(OUTPUT_BASIC, "CALC_VALUE"); - break; - - case tokdescription: - output_msg(OUTPUT_BASIC, "DESCRIPTION"); - break; - - case toksys: - output_msg(OUTPUT_BASIC, "SYS"); - break; - - case tokinstr: - output_msg(OUTPUT_BASIC, "INSTR"); - break; - - case tokltrim: - output_msg(OUTPUT_BASIC, "LTRIM"); - break; - - case tokrtrim: - output_msg(OUTPUT_BASIC, "RTRIM"); - break; - - case toktrim: - output_msg(OUTPUT_BASIC, "TRIM"); - break; - - case tokpad: - output_msg(OUTPUT_BASIC, "PAD"); - break; - - case tokrxn: - output_msg(OUTPUT_BASIC, "RXN"); - break; - - case tokdist: - output_msg(OUTPUT_BASIC, "DIST"); - break; - - case tokmisc1: - output_msg(OUTPUT_BASIC, "MISC1"); - break; - - case tokmisc2: - output_msg(OUTPUT_BASIC, "MISC2"); - break; - - case tokedl: - output_msg(OUTPUT_BASIC, "EDL"); - break; - - case toksurf: - output_msg(OUTPUT_BASIC, "SURF"); - break; - - case tokstep_no: - output_msg(OUTPUT_BASIC, "STEP_NO"); - break; - - case toksim_no: - output_msg(OUTPUT_BASIC, "SIM_NO"); - break; - - case toktotal_time: - output_msg(OUTPUT_BASIC, "TOTAL_TIME"); - break; - - case tokput: - output_msg(OUTPUT_BASIC, "PUT"); - break; - - case tokget: - output_msg(OUTPUT_BASIC, "GET"); - break; - - case tokcharge_balance: - output_msg(OUTPUT_BASIC, "CHARGE_BALANCE"); - break; - - case tokpercent_error: - output_msg(OUTPUT_BASIC, "PERCENT_ERROR"); - break; - -#ifdef PHREEQ98 - case tokgraph_x: - output_msg(OUTPUT_BASIC, "GRAPH_X"); - break; - - case tokgraph_y: - output_msg(OUTPUT_BASIC, "GRAPH_Y"); - break; - - case tokgraph_sy: - output_msg(OUTPUT_BASIC, "GRAPH_SY"); - break; -#endif - - case tokcell_no: - output_msg(OUTPUT_BASIC, "CELL_NO"); - break; - - case tokexists: - output_msg(OUTPUT_BASIC, "EXISTS"); - break; - - } - buf = buf->next; - } -} - - - -Static void disposetokens(tokenrec **tok) -{ - tokenrec *tok1; - - while (*tok != NULL) { - tok1 = (*tok)->next; - if ((*tok)->kind == (long)tokrem || (*tok)->kind == (long)tokstr) { - (*tok)->UU.sp = (char*) free_check_null((*tok)->UU.sp); - } - *tok = (struct tokenrec *)free_check_null(*tok); - *tok = tok1; - } -} - - - -Static void parseinput(tokenrec **buf) -{ - linerec *l, *l0, *l1; - - while (replace("\t"," ",inbuf)); - while (replace("\r"," ",inbuf)); - string_trim(inbuf); - curline = 0; - while (*inbuf != '\0' && isdigit((int) inbuf[0])) { - curline = curline * 10 + inbuf[0] - 48; -#ifdef SKIP - strcpy(inbuf, inbuf + 1); -#endif - memmove(inbuf, inbuf + 1, strlen(inbuf)); - } - parse(inbuf, buf); - if (curline == 0) - return; - l = linebase; - l0 = NULL; - while (l != NULL && l->num < curline) { - l0 = l; - l = l->next; - } - if (l != NULL && l->num == curline) { - l1 = l; - l = l->next; - if (l0 == NULL) - linebase = l; - else - l0->next = l; - disposetokens(&l1->txt); - free(l1); - } - if (*buf != NULL) { - l1 = (linerec *) PHRQ_malloc(sizeof(linerec)); - if ( l1 == NULL) malloc_error(); - l1->next = l; - if (l0 == NULL) - linebase = l1; - else - l0->next = l1; - l1->num = curline; - l1->txt = *buf; - } - clearloops(); - restoredata(); -} - -Static void errormsg(Char *s) -{ -#ifdef SKIP - printf("\007%s", s); -#endif - error_msg(s, CONTINUE); - _Escape(42); -} - - -Static void snerr(void) -{ - errormsg("Syntax error"); -} - - -Static void tmerr(void) -{ - errormsg("Type mismatch error"); -} - - -Static void badsubscr(void) -{ - errormsg("Bad subscript"); -} - - -/* Local variables for exec: */ -struct LOC_exec { - boolean gotoflag, elseflag; - tokenrec *t; -} ; - -Local valrec factor(struct LOC_exec *LINK); -Local valrec expr(struct LOC_exec *LINK); -Local Char *stringfactor(Char *Result, struct LOC_exec *LINK); - -Local LDBLE realfactor(struct LOC_exec *LINK) -{ - valrec n; - - n = factor(LINK); - if (n.stringval) - tmerr(); - return (n.UU.val); -} - -Local Char *strfactor(struct LOC_exec *LINK) -{ - valrec n; - - n = factor(LINK); - if (!n.stringval) - tmerr(); - return (n.UU.sval); -} - -Local Char *stringfactor(Char *Result, struct LOC_exec *LINK) -{ - valrec n; - - n = factor(LINK); - if (!n.stringval) - tmerr(); - strcpy(Result, n.UU.sval); - free(n.UU.sval); - return Result; -} - -Local long intfactor(struct LOC_exec *LINK) -{ - return ((long)floor(realfactor(LINK) + 0.5)); -} - -Local LDBLE realexpr(struct LOC_exec *LINK) -{ - valrec n; - - n = expr(LINK); - if (n.stringval) - tmerr(); - return (n.UU.val); -} - -Local Char *strexpr(struct LOC_exec *LINK) -{ - valrec n; - - n = expr(LINK); - if (!n.stringval) - tmerr(); - return (n.UU.sval); -} - -Local Char *stringexpr(Char *Result, struct LOC_exec *LINK) -{ - valrec n; - - n = expr(LINK); - if (!n.stringval) - tmerr(); - strcpy(Result, n.UU.sval); - free(n.UU.sval); - return Result; -} - -Local long intexpr(struct LOC_exec *LINK) -{ - return ((long)floor(realexpr(LINK) + 0.5)); -} - - -Local void require(int k, struct LOC_exec *LINK) -{ - if (LINK->t == NULL || LINK->t->kind != k) - snerr(); - LINK->t = LINK->t->next; -} - - -Local void skipparen(struct LOC_exec *LINK) -{ - do { - if (LINK->t == NULL) - snerr(); - if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) - goto _L1; - if (LINK->t->kind == toklp) { - LINK->t = LINK->t->next; - skipparen(LINK); - } - LINK->t = LINK->t->next; - } while (true); -_L1: ; -} - - -Local varrec *findvar(struct LOC_exec *LINK) -{ - varrec *v; - long i, j, k; - tokenrec *tok; - long FORLIM; - - if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(); - v = LINK->t->UU.vp; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != toklp) { - if (v->numdims != 0) - badsubscr(); - return v; - } - if (v->numdims == 0) { - tok = LINK->t; - i = 0; - j = 1; - do { - if (i >= maxdims) - badsubscr(); - LINK->t = LINK->t->next; - skipparen(LINK); - j *= 11; - i++; - v->dims[i - 1] = 11; - } while (LINK->t->kind != tokrp); - v->numdims = (char) i; - if (v->stringvar) { - v->UU.U1.sarr = (Char **) PHRQ_malloc(j * sizeof(char *)); - if (v->UU.U1.sarr == NULL) malloc_error(); - for (k = 0; k < j; k++) - v->UU.U1.sarr[k] = NULL; - } else { - v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); - if ( v->UU.U0.arr == NULL) malloc_error(); - for (k = 0; k < j; k++) - v->UU.U0.arr[k] = 0.0; - } - LINK->t = tok; - } - k = 0; - LINK->t = LINK->t->next; - FORLIM = v->numdims; - for (i = 1; i <= FORLIM; i++) { - j = intexpr(LINK); - if ((unsigned long)j >= (unsigned long) v->dims[i - 1]) - badsubscr(); - k = k * v->dims[i - 1] + j; - if (i < v->numdims) - require(tokcomma, LINK); - } - require(tokrp, LINK); - if (v->stringvar) - v->UU.U1.sval = &v->UU.U1.sarr[k]; - else - v->UU.U0.val = &v->UU.U0.arr[k]; - return v; -} - - -#ifdef SKIP -Local long inot(long i, struct LOC_exec *LINK) -{ - return (-i - 1); -} - -Local long ixor(long a, long b, struct LOC_exec *LINK) -{ - return ((a & (~b)) | ((~a) & b)); -} -#endif - -Local valrec factor(struct LOC_exec *LINK) -{ - varrec *v; - tokenrec *facttok; - valrec n; - long i, j, m; - tokenrec *tok, *tok1; - Char *s; - LDBLE dummy; - int i_rate; - union { - long i; - Char *c; - } trick; - struct save_values s_v, *s_v_ptr; - int k; - LDBLE TEMP; - Char *STR1, *STR2; - char *elt_name, *surface_name, *mytemplate, *name; - struct varrec *count_varrec=NULL, *names_varrec=NULL, *types_varrec=NULL, *moles_varrec=NULL; - char **names_arg, **types_arg; - LDBLE *moles_arg; - int arg_num; - LDBLE count_species; - char *ptr, *string1, *string2; - - STR1 = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (STR1 == NULL) malloc_error(); - STR2 = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (STR2 == NULL) malloc_error(); - - if (LINK->t == NULL) - snerr(); - facttok = LINK->t; - LINK->t = LINK->t->next; - n.stringval = false; - s_v.count_subscripts = 0; - s_v.subscripts = (int*) PHRQ_malloc(sizeof(int)); - switch (facttok->kind) { - - case toknum: - n.UU.val = facttok->UU.num; - break; - - case tokstr: - n.stringval = true; - m = strlen(facttok->UU.sp) + 1; - if (m < 256) m = 256; - n.UU.sval = (char *) PHRQ_malloc(m); - if (n.UU.sval == NULL) malloc_error(); - strcpy(n.UU.sval, facttok->UU.sp); - break; - - case tokvar: - LINK->t = facttok; - v = findvar(LINK); - n.stringval = v->stringvar; - if (n.stringval) { - if (*v->UU.U1.sval != NULL) { - m = strlen(*v->UU.U1.sval) + 1; - if (m < 256) m = 256; - } else { - m = 256; - } - n.UU.sval = (char *) PHRQ_malloc(m); - if (n.UU.sval == NULL) malloc_error(); - if (*v->UU.U1.sval != NULL) { - strcpy(n.UU.sval, *v->UU.U1.sval); - } - - } else - n.UU.val = *v->UU.U0.val; - break; - - case toklp: - n = expr(LINK); - require(tokrp, LINK); - break; - - case tokminus: - n.UU.val = -realfactor(LINK); - break; - - case tokplus: - n.UU.val = realfactor(LINK); - break; - - case toknot: - n.UU.val = ~intfactor(LINK); - break; - - case toksqr: - TEMP = realfactor(LINK); - n.UU.val = TEMP * TEMP; - break; - - case toksqrt: - n.UU.val = sqrt(realfactor(LINK)); - break; - - case toktc: - n.UU.val = tc_x; - break; - - case toktk: - n.UU.val = tc_x+273.16; - break; - - case toktime: - n.UU.val = rate_time; - break; - - case toksim_time: - if (use.kinetics_in == FALSE) { - if (state == PHAST) { - n.UU.val = rate_sim_time; - } else if (state == TRANSPORT) { - n.UU.val = transport_step * timest; - } else if (state == ADVECTION) { - if (advection_kin_time_defined == TRUE) { - n.UU.val = advection_step * advection_kin_time; - } else { - n.UU.val = advection_step; - } - } else { - n.UU.val = 0; - } - } else { - n.UU.val = rate_sim_time; - } - break; - - case toktotal_time: - if (use.kinetics_in == FALSE) { - if (state == PHAST) { - n.UU.val = rate_sim_time_end; - } else if (state == TRANSPORT) { - n.UU.val = initial_total_time + transport_step * timest; - } else if (state == ADVECTION) { - n.UU.val = initial_total_time + advection_step * advection_kin_time; - } else { - n.UU.val = 0; - } - } else { - n.UU.val = initial_total_time + rate_sim_time; - } - break; - - case tokm0: - n.UU.val = rate_m0; - break; - - case tokm: - n.UU.val = rate_m; - break; - - case tokparm: - i_rate = intfactor(LINK); - if ( i_rate > count_rate_p) { - errormsg("Parameter subscript out of range."); - } - n.UU.val = rate_p[i_rate - 1]; - break; - - case tokact: - n.UU.val = activity(stringfactor(STR1, LINK)); - break; - - case tokedl: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - surface_name = stringfactor(STR2, LINK); - } else { - surface_name = NULL; - } - require(tokrp, LINK); - n.UU.val = diff_layer_total(elt_name, surface_name); - break; - - case toksurf: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - surface_name = stringfactor(STR2, LINK); - } else { - surface_name = NULL; - } - require(tokrp, LINK); - n.UU.val = surf_total(elt_name, surface_name); - break; - - case tokequi: - n.UU.val = equi_phase(stringfactor(STR1, LINK)); - break; - - case tokkin: - n.UU.val = kinetics_moles(stringfactor(STR1, LINK)); - break; - - case tokgas: - n.UU.val = find_gas_comp(stringfactor(STR1, LINK)); - break; - - case toks_s: - n.UU.val = find_s_s_comp(stringfactor(STR1, LINK)); - break; - - case tokmisc1: - n.UU.val = find_misc1(stringfactor(STR1, LINK)); - break; - - case tokmisc2: - n.UU.val = find_misc2(stringfactor(STR1, LINK)); - break; - - case tokmu: - n.UU.val = mu_x; - break; - - case tokalk: - n.UU.val = total_alkalinity/mass_water_aq_x; - break; - - case toklk_species: - n.UU.val = calc_logk_s(stringfactor(STR1, LINK)); - break; - - case toklk_named: - n.UU.val = calc_logk_n(stringfactor(STR1, LINK)); - break; - - case toklk_phase: - n.UU.val = calc_logk_p(stringfactor(STR1, LINK)); - break; - - case toksum_species: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } else { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = sum_match_species(mytemplate, elt_name); - break; - - case toksum_gas: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } else { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = sum_match_gases(mytemplate, elt_name); - break; - - case toksum_s_s: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } else { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = sum_match_s_s(mytemplate, elt_name); - break; - - case tokcalc_value: - require(toklp, LINK); - name = stringfactor(STR1, LINK); - require(tokrp, LINK); - n.UU.val = get_calculate_value(name); - break; - - case tokdescription: - n.stringval = true; - n.UU.sval = string_duplicate(use.solution_ptr->description); - while (replace("\t"," ",n.UU.sval)); - break; - - case tokinstr: - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokcomma, LINK); - string2 = stringfactor(STR2, LINK); - require(tokrp, LINK); - ptr = strstr(string1, string2); - if (ptr == NULL) { - n.UU.val = 0; - } else { - n.UU.val = ((LDBLE) (ptr - string1)) + 1; - } - break; - - case tokltrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - string_trim_left(string1); - n.UU.sval = string_duplicate(string1); - break; - - case tokrtrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - string_trim_right(string1); - n.UU.sval = string_duplicate(string1); - break; - - case toktrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - string_trim(string1); - n.UU.sval = string_duplicate(string1); - break; - - case tokpad: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokcomma, LINK); - i = intexpr(LINK); - require(tokrp, LINK); - n.UU.sval = string_pad(string1, i); - break; - - case toksys: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - /* - * Parse arguments - */ - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ - /* return number of species */ - LINK->t = LINK->t->next; - count_varrec = LINK->t->UU.vp; - if (count_varrec->stringvar != 0) snerr(); - - /* return number of names of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - names_varrec = LINK->t->UU.vp; - if (names_varrec->stringvar != 1) snerr(); - - /* return number of types of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - types_varrec = LINK->t->UU.vp; - if (types_varrec->stringvar != 1) snerr(); - - /* return number of moles of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - moles_varrec = LINK->t->UU.vp; - if (moles_varrec->stringvar != 0) snerr(); - LINK->t = LINK->t->next; - arg_num = 4; - } else { - arg_num = 1; - } - require(tokrp, LINK); - - if (arg_num > 1) { - free_dim_stringvar(names_varrec); - free_dim_stringvar(types_varrec); - free_check_null(moles_varrec->UU.U0.arr); - moles_varrec->UU.U0.arr = NULL; - } - /* - * Call subroutine - */ - /* - n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); - */ - n.UU.val = system_total(elt_name, &count_species, &(names_arg), &(types_arg), &(moles_arg)); - - /* - * fill in varrec structure - */ - if (arg_num > 1) { - *count_varrec->UU.U0.val = count_species; - names_varrec->UU.U1.sarr = names_arg; - types_varrec->UU.U1.sarr = types_arg; - moles_varrec->UU.U0.arr = moles_arg; - - for (i = 0; i < maxdims; i++) { - names_varrec->dims[i] = 0; - types_varrec->dims[i] = 0; - moles_varrec->dims[i] = 0; - } - names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - types_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - names_varrec->numdims = 1; - types_varrec->numdims = 1; - moles_varrec->numdims = 1; - } else { - for (i = 0; i < count_species + 1; i++) { - free_check_null(names_arg[i]); - free_check_null(types_arg[i]); - } - free_check_null(names_arg); - free_check_null(types_arg); - free_check_null(moles_arg); - } - break; - case tokrxn: - if (state == REACTION) { - n.UU.val = step_x; - } else { - n.UU.val = 0.0; - } - break; - - case tokdist: - if (state == PHAST) { - n.UU.val = 0; - } else if (state == TRANSPORT) { - n.UU.val = cell_data[cell-1].mid_cell_x; - } else if (state == ADVECTION) { - n.UU.val = (LDBLE) use.n_solution_user; - } else { - n.UU.val = 0; - } - break; - - case tokmol: - n.UU.val = molality(stringfactor(STR1, LINK)); - break; - - case tokla: - n.UU.val = log_activity(stringfactor(STR1, LINK)); - break; - - case toklm: - n.UU.val = log_molality(stringfactor(STR1, LINK)); - break; - - case toksr: - n.UU.val = saturation_ratio(stringfactor(STR1, LINK)); - break; - - case tokstep_no: - if (state == PHAST) { - n.UU.val = 0; - } else if (state == TRANSPORT) { - n.UU.val = transport_step; - } else if (state == ADVECTION) { - n.UU.val = advection_step; - } else if (state == REACTION) { - n.UU.val = reaction_step; - } else { - n.UU.val = 0; - } - break; - - case tokcell_no: - if (state == TRANSPORT) { - n.UU.val = cell_no; - } else if (state == PHAST) { - n.UU.val = cell_no; - } else if (state == ADVECTION) { - n.UU.val = cell_no; - } else if (state < REACTION) { - n.UU.val = use.solution_ptr->n_user; - } else { - if (use.mix_in == TRUE) { - n.UU.val = use.n_mix_user; - } else { - n.UU.val = use.n_solution_user; - } - } - break; - - case toksim_no: - n.UU.val = simulation; - break; - - case tokget: - require(toklp, LINK); - - s_v.count_subscripts = 0; - /* get first subscript */ - if (LINK->t != NULL && LINK->t->kind != tokrp) { - i = intexpr(LINK); - s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); - if (s_v.subscripts == NULL) malloc_error(); - s_v.subscripts[s_v.count_subscripts] = i; - s_v.count_subscripts++; - } - - /* get other subscripts */ - for (;;) { - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - j = intexpr(LINK); - s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); - if (s_v.subscripts == NULL) malloc_error(); - s_v.subscripts[s_v.count_subscripts] = j; - s_v.count_subscripts++; - } else { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - s_v_ptr = save_values_bsearch(&s_v, &k); - if (s_v_ptr == NULL) { - n.UU.val = 0; - } else { - n.UU.val = s_v_ptr->value; - } - break; - - case tokexists: - require(toklp, LINK); - - s_v.count_subscripts = 0; - /* get first subscript */ - if (LINK->t != NULL && LINK->t->kind != tokrp) { - i = intexpr(LINK); - s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); - if (s_v.subscripts == NULL) malloc_error(); - s_v.subscripts[s_v.count_subscripts] = i; - s_v.count_subscripts++; - } - - /* get other subscripts */ - for (;;) { - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - j = intexpr(LINK); - s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) (s_v.count_subscripts + 1) * sizeof(int)); - if (s_v.subscripts == NULL) malloc_error(); - s_v.subscripts[s_v.count_subscripts] = j; - s_v.count_subscripts++; - } else { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - s_v_ptr = save_values_bsearch(&s_v, &k); - if (s_v_ptr == NULL) { - n.UU.val = 0; - } else { - n.UU.val = 1; - } - break; - - case tokcharge_balance: - n.UU.val = cb_x; - break; - - case tokpercent_error: - n.UU.val = 100*cb_x/total_ions_x; - break; - - case toksi: - saturation_index(stringfactor(STR1, LINK), &dummy, &n.UU.val); - break; - - case toktot: - n.UU.val = total(stringfactor(STR1, LINK)); - break; - - case toklog10: - n.UU.val = log10(realfactor(LINK)); - break; - - case toksin: - n.UU.val = sin(realfactor(LINK)); - break; - - case tokcos: - n.UU.val = cos(realfactor(LINK)); - break; - - case toktan: - n.UU.val = realfactor(LINK); - n.UU.val = sin(n.UU.val) / cos(n.UU.val); - break; - - case tokarctan: - n.UU.val = atan(realfactor(LINK)); - break; - - case toklog: - n.UU.val = log(realfactor(LINK)); - break; - - case tokexp: - n.UU.val = exp(realfactor(LINK)); - break; - - case tokabs: - n.UU.val = fabs(realfactor(LINK)); - break; - - case toksgn: - n.UU.val = realfactor(LINK); - n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); - break; - - case tokstr_: - n.stringval = true; - n.UU.sval = (char *) PHRQ_malloc(256); - if (n.UU.sval == NULL) malloc_error(); - numtostr(n.UU.sval, realfactor(LINK)); - break; - - case tokval: - s = strfactor(LINK); - tok1 = LINK->t; - parse(s, &LINK->t); - tok = LINK->t; - if (tok == NULL) - n.UU.val = 0.0; - else - n = expr(LINK); - disposetokens(&tok); - LINK->t = tok1; - free(s); - break; - - case tokchr_: - n.stringval = true; - n.UU.sval = (char *) PHRQ_malloc(256); - if (n.UU.sval == NULL) malloc_error(); - strcpy(n.UU.sval, " "); - n.UU.sval[0] = (Char)intfactor(LINK); - break; - - case tokasc: - s = strfactor(LINK); - if (*s == '\0') - n.UU.val = 0.0; - else - n.UU.val = s[0]; - free(s); - break; - - case tokmid_: - n.stringval = true; - require(toklp, LINK); - n.UU.sval = strexpr(LINK); - require(tokcomma, LINK); - i = intexpr(LINK); - if (i < 1) - i = 1; - /*j = 255;*/ - j = strlen(n.UU.sval); - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - j = intexpr(LINK); - } - if (j > (int) strlen(n.UU.sval) - i + 1) - j = strlen(n.UU.sval) - i + 1; - if (i > (int) strlen(n.UU.sval)) - *n.UU.sval = '\0'; - else { - STR1 = (char *) PHRQ_realloc(STR1, j + 1); - if (STR1 == NULL) malloc_error(); - sprintf(STR1, "%.*s", (int)j, n.UU.sval + i - 1); - strcpy(n.UU.sval, STR1); - } - require(tokrp, LINK); - break; - - case toklen: - s = strfactor(LINK); - n.UU.val = strlen(s); - free(s); - break; - - case tokpeek: -/* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ - trick.i = intfactor(LINK); - n.UU.val = *trick.c; -/* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ - break; - - default: - snerr(); - break; - } - s_v.subscripts = (int*) free_check_null(s_v.subscripts); - free_check_null(STR1); - free_check_null(STR2); - return n; -} - -Local valrec upexpr(struct LOC_exec *LINK) -{ - valrec n, n2; - - n = factor(LINK); - while (LINK->t != NULL && LINK->t->kind == tokup) { - if (n.stringval) - tmerr(); - LINK->t = LINK->t->next; - n2 = upexpr(LINK); - if (n2.stringval) - tmerr(); - if (n.UU.val >= 0) { - if (n.UU.val >0) { - n.UU.val = exp(n2.UU.val * log(n.UU.val)); - } - continue; - } - if (n2.UU.val != (long)n2.UU.val) - n.UU.val = log(n.UU.val); - n.UU.val = exp(n2.UU.val * log(-n.UU.val)); - if (((long)n2.UU.val) & 1) - n.UU.val = -n.UU.val; - } - return n; -} - -Local valrec term(struct LOC_exec *LINK) -{ - valrec n, n2; - int k; - - n = upexpr(LINK); - while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & ((1L << ((long)toktimes)) | - (1L << ((long)tokdiv)) | (1L << ((long)tokmod)))) != 0) { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = upexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(); - if (k == tokmod) { - /* n.UU.val = (long)floor(n.UU.val + 0.5) % (long)floor(n2.UU.val + 0.5); */ - if (n.UU.val != 0) { - n.UU.val = fabs(n.UU.val)/n.UU.val * fmod(fabs(n.UU.val) + 1e-14, n2.UU.val); - } else { - n.UU.val = 0; - } -/* p2c: basic.p, line 1078: - * Note: Using % for possibly-negative arguments [317] */ - } else if (k == toktimes) - n.UU.val *= n2.UU.val; - else - if (n2.UU.val != 0) { - n.UU.val /= n2.UU.val; - } else { - error_msg("Zero divide in Basic. Value set to zero.", CONTINUE); - n.UU.val = 0; - } - } - return n; -} - -Local valrec sexpr(struct LOC_exec *LINK) -{ - valrec n, n2; - int k, m; - - n = term(LINK); - while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)tokplus)) | (1L << ((long)tokminus)))) != 0) { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = term(LINK); - if (n.stringval != n2.stringval) - tmerr(); - if (k == tokplus) { - if (n.stringval) { - m = strlen(n.UU.sval) + strlen(n2.UU.sval) + 1; - if (m < 256) m = 256; - - n.UU.sval = (char *) PHRQ_realloc(n.UU.sval, m); - if (n.UU.sval == NULL) malloc_error(); - strcat(n.UU.sval, n2.UU.sval); - free(n2.UU.sval); - } else - n.UU.val += n2.UU.val; - } else { - if (n.stringval) - tmerr(); - else - n.UU.val -= n2.UU.val; - } - } - return n; -} - -Local valrec relexpr(struct LOC_exec *LINK) -{ - valrec n, n2; - boolean f; - int k; - - n = sexpr(LINK); - while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)tokne + 1)) - (1L << ((long)tokeq)))) != 0) { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = sexpr(LINK); - if (n.stringval != n2.stringval) - tmerr(); - if (n.stringval) { - f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)tokeq)) | - (1L << ((long)tokge)) | (1L << ((long)tokle)))) != 0) || - (strcmp(n.UU.sval, n2.UU.sval) < 0 && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)toklt)) | - (1L << ((long)tokle)) | (1L << ((long)tokne)))) != 0) || - (strcmp(n.UU.sval, n2.UU.sval) > 0 && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)tokgt)) | - (1L << ((long)tokge)) | (1L << ((long)tokne)))) != 0)); - /* p2c: basic.p, line 2175: Note: - * Line breaker spent 0.0+1.00 seconds, 5000 tries on line 1518 [251] */ - free(n.UU.sval); - free(n2.UU.sval); - } else - f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)tokeq)) | - (1L << ((long)tokge)) | (1L << ((long)tokle)))) != 0) || - (n.UU.val < n2.UU.val && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)toklt)) | - (1L << ((long)tokle)) | (1L << ((long)tokne)))) != 0) || - (n.UU.val > n2.UU.val && (unsigned long)k < 32 && - ((1L << ((long)k)) & ((1L << ((long)tokgt)) | - (1L << ((long)tokge)) | (1L << ((long)tokne)))) != 0)); - /* p2c: basic.p, line 2175: Note: - * Line breaker spent 0.0+2.00 seconds, 5000 tries on line 1532 [251] */ - n.stringval = false; - n.UU.val = f; - } - return n; -} - -Local valrec andexpr(struct LOC_exec *LINK) -{ - valrec n, n2; - - n = relexpr(LINK); - while (LINK->t != NULL && LINK->t->kind == tokand) { - LINK->t = LINK->t->next; - n2 = relexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(); - n.UU.val = ((long)n.UU.val) & ((long)n2.UU.val); - } - return n; -} - -Local valrec expr(struct LOC_exec *LINK) -{ - valrec n, n2; - int k; - - n = andexpr(LINK); - while (LINK->t != NULL && (unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)tokor)) | (1L << ((long)tokxor)))) != 0) { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = andexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(); - if (k == tokor) - n.UU.val = ((long)n.UU.val) | ((long)n2.UU.val); - else - n.UU.val = ((long)n.UU.val) ^ ((long)n2.UU.val); - } - return n; -} - - -Local void checkextra(struct LOC_exec *LINK) -{ - if (LINK->t != NULL) - errormsg("Extra information on line"); -} - - -Local boolean iseos(struct LOC_exec *LINK) -{ - return ( (boolean) (LINK->t == NULL || LINK->t->kind == (long)tokelse || - LINK->t->kind == (long)tokcolon) ); -} - - -Local void skiptoeos(struct LOC_exec *LINK) -{ - while (!iseos(LINK)) - LINK->t = LINK->t->next; -} - - -#ifdef SKIP -/* LINK not used */ -Local linerec *findline(long n, struct LOC_exec *LINK) -#endif -Local linerec *findline(long n) -{ - linerec *l; - - l = linebase; - while (l != NULL && l->num != n) - l = l->next; - return l; -} - - -#ifdef SKIP -Local linerec *mustfindline(long n, struct LOC_exec *LINK) -#endif -Local linerec *mustfindline(long n) -{ - linerec *l; - -#ifdef SKIP - l = findline(n, LINK); -#endif - l = findline(n); - if (l == NULL) - errormsg("Undefined line"); - return l; -} - - -Local void cmdend(struct LOC_exec *LINK) -{ - stmtline = NULL; - LINK->t = NULL; -} - - -Local void cmdnew(struct LOC_exec *LINK) -{ - void *p; - int i, k; - - cmdend(LINK); - clearloops(); - restoredata(); - while (linebase != NULL) { - p = linebase->next; - disposetokens(&linebase->txt); - free(linebase); - linebase = (struct linerec *) p; - } - while (varbase != NULL) { - p = varbase->next; - if (varbase->stringvar) { - if (varbase->numdims > 0) { - k = 1; - for (i = 0; i < varbase->numdims; i++) { - k = k*(varbase->dims[i]); - } - for (i = 0; i < k; i++) { - free_check_null(varbase->UU.U1.sarr[i]); - } - free_check_null(varbase->UU.U1.sarr); - } else if (*varbase->UU.U1.sval != NULL) { - *varbase->UU.U1.sval = (char*) free_check_null(*varbase->UU.U1.sval); - } - - } else { - free_check_null(varbase->UU.U0.arr); - varbase->UU.U0.arr = NULL; - } - free(varbase); - varbase = (struct varrec *) p; - } -} - - -Local void cmdlist(struct LOC_exec *LINK) -{ - linerec *l; - long n1, n2; - - do { - n1 = 0; - n2 = LONG_MAX; - if (LINK->t != NULL && LINK->t->kind == toknum) { - n1 = (long)LINK->t->UU.num; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != tokminus) - n2 = n1; - } - if (LINK->t != NULL && LINK->t->kind == tokminus) { - LINK->t = LINK->t->next; - if (LINK->t != NULL && LINK->t->kind == toknum) { - n2 = (long)LINK->t->UU.num; - LINK->t = LINK->t->next; - } else - n2 = LONG_MAX; - } - l = linebase; - while (l != NULL && l->num <= n2) { - if (l->num >= n1) { - /* printf("%ld ", l->num); */ - /* listtokens(stdout, l->txt); */ - /* putchar('\n'); */ - output_msg(OUTPUT_MESSAGE, "%ld ", l->num); - listtokens(NULL, l->txt); - output_msg(OUTPUT_MESSAGE, "\n"); - } - l = l->next; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } while (!iseos(LINK)); -} - - -Local void cmdload(boolean merging, Char *name, struct LOC_exec *LINK) -{ - FILE *f; - tokenrec *buf; - Char STR1[256]; - Char *TEMP; - - f = NULL; - if (!merging) - cmdnew(LINK); - if (f != NULL) { - sprintf(STR1, "%s.TEXT", name); - f = freopen(STR1, "r", f); - } else { - sprintf(STR1, "%s.TEXT", name); - f = fopen(STR1, "r"); - } - if (f == NULL) - _EscIO(FileNotFound); - while (fgets(inbuf, 256, f) != NULL) { - TEMP = strchr(inbuf, '\n'); - if (TEMP != NULL) - *TEMP = 0; - parseinput(&buf); - if (curline == 0) { - printf("Bad line in file\n"); - disposetokens(&buf); - } - } - if (f != NULL) - fclose(f); - f = NULL; - if (f != NULL) - fclose(f); -} - - -Local void cmdrun(struct LOC_exec *LINK) -{ - linerec *l; - long i; - /*string255 s;*/ - char *s; - - s = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (s == NULL) malloc_error(); - - l = linebase; - if (!iseos(LINK)) { - if (LINK->t->kind == toknum) -#ifdef SKIP - l = mustfindline(intexpr(LINK), LINK); -#endif - l = mustfindline(intexpr(LINK)); - else { - stringexpr(s, LINK); - i = 0; - if (!iseos(LINK)) { - require(tokcomma, LINK); - i = intexpr(LINK); - } - checkextra(LINK); - cmdload(false, s, LINK); - if (i == 0) - l = linebase; - else -#ifdef SKIP - l = mustfindline(i, LINK); -#endif - l = mustfindline(i); - } - } - stmtline = l; - LINK->gotoflag = true; - clearvars(); - clearloops(); - restoredata(); - free_check_null(s); - return; -} - -#ifdef SKIP -Local void cmdsave(struct LOC_exec *LINK) -{ - FILE *f; - linerec *l; - Char STR1[256], STR2[256]; - - f = NULL; - if (f != NULL) { - sprintf(STR2, "%s.TEXT", stringexpr(STR1, LINK)); - f = freopen(STR2, "w", f); - } else { - sprintf(STR2, "%s.TEXT", stringexpr(STR1, LINK)); - f = fopen(STR2, "w"); - } - if (f == NULL) - _EscIO(FileNotFound); - l = linebase; - while (l != NULL) { - /* fprintf(f, "%ld ", l->num);*/ - listtokens(f, l->txt); - putc('\n', f); - l = l->next; - } - if (f != NULL) - fclose(f); - f = NULL; - if (f != NULL) - fclose(f); -} -#endif - -/* replace basic save command with transport of rate back to calc_kinetic_rate */ -Local void cmdsave(struct LOC_exec *LINK) -{ -#ifdef SKIP - boolean semiflag; -#endif - valrec n; - while (!iseos(LINK)) { -#ifdef SKIP - semiflag = false; -#endif - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { -#ifdef SKIP - semiflag = true; -#endif - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) { - snerr(); - } else { - rate_moles = n.UU.val; - } - } -} -Local void cmdput(struct LOC_exec *LINK) -{ - int j; - struct save_values s_v; - - s_v.count_subscripts = 0; - s_v.subscripts = (int*) PHRQ_malloc(sizeof(int)); - - /* get parentheses */ - require(toklp, LINK); - - /* get first argumen */ - s_v.value = realexpr(LINK); - - for (;;) { - if (LINK->t != NULL && LINK->t->kind == tokcomma) { - LINK->t = LINK->t->next; - j = intexpr(LINK); - s_v.count_subscripts++; - s_v.subscripts = (int*) PHRQ_realloc(s_v.subscripts, (size_t) s_v.count_subscripts * sizeof(int)); - if (s_v.subscripts == NULL) malloc_error(); - s_v.subscripts[s_v.count_subscripts - 1] = j; - } else { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - - save_values_store(&s_v); - s_v.subscripts = (int*) free_check_null(s_v.subscripts); -} -#ifdef SKIP -/* LINK not used */ -Local void cmdbye(struct LOC_exec *LINK) -#endif -Local void cmdbye(void) -{ - exitflag = true; -} - -Local void cmddel(struct LOC_exec *LINK) -{ - linerec *l, *l0, *l1; - long n1, n2; - - do { - if (iseos(LINK)) - snerr(); - n1 = 0; - n2 = LONG_MAX; - if (LINK->t != NULL && LINK->t->kind == toknum) { - n1 = (long)LINK->t->UU.num; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != tokminus) - n2 = n1; - } - if (LINK->t != NULL && LINK->t->kind == tokminus) { - LINK->t = LINK->t->next; - if (LINK->t != NULL && LINK->t->kind == toknum) { - n2 = (long)LINK->t->UU.num; - LINK->t = LINK->t->next; - } else - n2 = LONG_MAX; - } - l = linebase; - l0 = NULL; - while (l != NULL && l->num <= n2) { - l1 = l->next; - if (l->num >= n1) { - if (l == stmtline) { - cmdend(LINK); - clearloops(); - restoredata(); - } - if (l0 == NULL) - linebase = l->next; - else - l0->next = l->next; - disposetokens(&l->txt); - free(l); - } else - l0 = l; - l = l1; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } while (!iseos(LINK)); -} - - -Local void cmdrenum(struct LOC_exec *LINK) -{ - linerec *l, *l1; - tokenrec *tok; - long lnum, step; - - lnum = 10; - step = 10; - if (!iseos(LINK)) { - lnum = intexpr(LINK); - if (!iseos(LINK)) { - require(tokcomma, LINK); - step = intexpr(LINK); - } - } - l = linebase; - if (l == NULL) - return; - while (l != NULL) { - l->num2 = lnum; - lnum += step; - l = l->next; - } - l = linebase; - do { - tok = l->txt; - do { - if (tok->kind == (long)tokdel || tok->kind == (long)tokrestore || - tok->kind == (long)toklist || tok->kind == (long)tokrun || - tok->kind == (long)tokelse || tok->kind == (long)tokthen || - tok->kind == (long)tokgosub || tok->kind == (long)tokgoto) { - while (tok->next != NULL && tok->next->kind == toknum) { - tok = tok->next; - lnum = (long)floor(tok->UU.num + 0.5); - l1 = linebase; - while (l1 != NULL && l1->num != lnum) - l1 = l1->next; - if (l1 == NULL) - printf("Undefined line %ld in line %ld\n", lnum, l->num2); - else - tok->UU.num = l1->num2; - if (tok->next != NULL && tok->next->kind == tokcomma) - tok = tok->next; - } - } - tok = tok->next; - } while (tok != NULL); - l = l->next; - } while (l != NULL); - l = linebase; - while (l != NULL) { - l->num = l->num2; - l = l->next; - } -} - - -Local void cmdprint(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - Char STR1[256]; - - semiflag = false; - while (!iseos(LINK)) { - semiflag = false; - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - output_msg(OUTPUT_MESSAGE, "%s ", n.UU.sval); - free(n.UU.sval); - } else -/* printf("%s ", numtostr(STR1, n.UU.val)); */ - output_msg(OUTPUT_MESSAGE, "%s ", numtostr(STR1, n.UU.val)); - } - if (!semiflag) -/* putchar('\n');*/ - output_msg(OUTPUT_MESSAGE, "\n"); -} - -Local void cmdpunch(struct LOC_exec *LINK) -{ -#ifdef SKIP - boolean semiflag; -#endif - valrec n; - /* Char STR1[256]; */ - -#ifdef SKIP - semiflag = false; -#endif - while (!iseos(LINK)) { -#ifdef SKIP - semiflag = false; -#endif - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { -#ifdef SKIP - semiflag = true; -#endif - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - if (punch.high_precision == FALSE) { - if (strlen(n.UU.sval) <= 12) { - fpunchf_user(n_user_punch_index, "%12.12s\t", n.UU.sval); - } else { - fpunchf_user(n_user_punch_index, "%s\t", n.UU.sval); - } - } else { - if (strlen(n.UU.sval) <= 20) { - fpunchf_user(n_user_punch_index, "%20.20s\t", n.UU.sval); - } else { - fpunchf_user(n_user_punch_index, "%s\t", n.UU.sval); - } - } - free(n.UU.sval); - } else - if (punch.high_precision == FALSE) { - fpunchf_user(n_user_punch_index, "%12.4e\t", n.UU.val); - } else { - fpunchf_user(n_user_punch_index, "%20.12e\t", n.UU.val); - } - ++n_user_punch_index; - } -} - -#ifdef PHREEQ98 -Local void cmdgraph_x(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - Char STR1[256]; - semiflag = false; - while (!iseos(LINK)) { - semiflag = false; - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (colnr == 0) rownr++; - if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "x"); - Free(n.UU.sval); - } else - GridChar(numtostr(STR1, n.UU.val), "x"); - colnr++; - } -} - -Local void cmdgraph_y(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - Char STR1[256]; - semiflag = false; - while (!iseos(LINK)) { - semiflag = false; - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "y"); - Free(n.UU.sval); - } else - GridChar(numtostr(STR1, n.UU.val), "y"); - colnr++; - } -} - -Local void cmdgraph_sy(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - Char STR1[256]; - semiflag = false; - while (!iseos(LINK)) { - semiflag = false; - if ((unsigned long)LINK->t->kind < 32 && - ((1L << ((long)LINK->t->kind)) & - ((1L << ((long)toksemi)) | (1L << ((long)tokcomma)))) != 0) { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "s"); - Free(n.UU.sval); - } else - GridChar(numtostr(STR1, n.UU.val), "s"); - colnr++; - } -} -#endif - -#ifdef SKIP -Local void cmdinput(struct LOC_exec *LINK) -{ - varrec *v; - /* string255 s; */ - char *s; - tokenrec *tok, *tok0, *tok1; - boolean strflag; - - /* - s = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (s == NULL) malloc_error(); - */ - /* need to free s if this subroutine is used */ - - if (LINK->t != NULL && LINK->t->kind == tokstr) { - fputs(LINK->t->UU.sp, stdout); - LINK->t = LINK->t->next; - require(toksemi, LINK); - } else - printf("? "); - tok = LINK->t; - if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(); - strflag = LINK->t->UU.vp->stringvar; - do { - if (LINK->t != NULL && LINK->t->kind == tokvar) { - if (LINK->t->UU.vp->stringvar != strflag) - snerr(); - } - LINK->t = LINK->t->next; - } while (!iseos(LINK)); - LINK->t = tok; - if (strflag) { - do { - gets(s); - v = findvar(LINK); - if (*v->UU.U1.sval != NULL) - *v->UU.U1.sval = free_check_null(*v->UU.U1.sval); - *v->UU.U1.sval = (char *) PHRQ_malloc(256); - if (*v->UU.U1.sval == NULL) malloc_error(); - strcpy(*v->UU.U1.sval, s); - if (!iseos(LINK)) { - require(tokcomma, LINK); - printf("?? "); - } - } while (!iseos(LINK)); - return; - } - gets(s); - parse(s, &tok); - tok0 = tok; - do { - v = findvar(LINK); - while (tok == NULL) { - printf("?? "); - gets(s); - disposetokens(&tok0); - parse(s, &tok); - tok0 = tok; - } - tok1 = LINK->t; - LINK->t = tok; - *v->UU.U0.val = realexpr(LINK); - if (LINK->t != NULL) { - if (LINK->t->kind == tokcomma) - LINK->t = LINK->t->next; - else - snerr(); - } - tok = LINK->t; - LINK->t = tok1; - if (!iseos(LINK)) - require(tokcomma, LINK); - } while (!iseos(LINK)); - disposetokens(&tok0); -} -#endif - -Local void cmdlet(boolean implied, struct LOC_exec *LINK) -{ - varrec *v; - Char *old, *mynew; - LDBLE d_value; - LDBLE *target; - char **starget; - target = NULL; - starget = NULL; - if (implied) - LINK->t = stmttok; - v = findvar(LINK); - if (v->stringvar) { - starget = v->UU.U1.sval; - } else { - target = v->UU.U0.val; - } - require(tokeq, LINK); - if (!v->stringvar) { - /* in case array is used on right hand side */ - d_value = realexpr(LINK); - v->UU.U0.val = target; - *v->UU.U0.val = d_value; - /* *v->UU.U0.val = realexpr(LINK); */ - return; - } - mynew = strexpr(LINK); - v->UU.U1.sval = starget; - old = *v->UU.U1.sval; - *v->UU.U1.sval = mynew; - if (old != NULL) - free(old); -} - - -Local void cmdgoto(struct LOC_exec *LINK) -{ -#ifdef SKIP - stmtline = mustfindline(intexpr(LINK), LINK); -#endif - stmtline = mustfindline(intexpr(LINK)); - LINK->t = NULL; - LINK->gotoflag = true; -} - - -Local void cmdif(struct LOC_exec *LINK) -{ - LDBLE n; - long i; - - n = realexpr(LINK); - require(tokthen, LINK); - if (n == 0) { - i = 0; - do { - if (LINK->t != NULL) { - if (LINK->t->kind == tokif) - i++; - if (LINK->t->kind == tokelse) - i--; - LINK->t = LINK->t->next; - } - } while (LINK->t != NULL && i >= 0); - } - if (LINK->t != NULL && LINK->t->kind == toknum) - cmdgoto(LINK); - else - LINK->elseflag = true; -} - - -Local void cmdelse(struct LOC_exec *LINK) -{ - LINK->t = NULL; -} - - -Local boolean skiploop(int up, int dn, struct LOC_exec *LINK) -{ - boolean Result; - long i; - linerec *saveline; - - saveline = stmtline; - i = 0; - do { - while (LINK->t == NULL) { - if (stmtline == NULL || stmtline->next == NULL) { - Result = false; - stmtline = saveline; - goto _L1; - } - stmtline = stmtline->next; - LINK->t = stmtline->txt; - } - if (LINK->t->kind == up) - i++; - if (LINK->t->kind == dn) - i--; - LINK->t = LINK->t->next; - } while (i >= 0); - Result = true; -_L1: - return Result; -} - - -Local void cmdfor(struct LOC_exec *LINK) -{ - looprec *l, lr; - linerec *saveline; - long i, j; - - lr.UU.U0.vp = findvar(LINK); - if (lr.UU.U0.vp->stringvar) - snerr(); - require(tokeq, LINK); - *lr.UU.U0.vp->UU.U0.val = realexpr(LINK); - require(tokto, LINK); - lr.UU.U0.max = realexpr(LINK); - if (LINK->t != NULL && LINK->t->kind == tokstep) { - LINK->t = LINK->t->next; - lr.UU.U0.step = realexpr(LINK); - } else - lr.UU.U0.step = 1.0; - lr.homeline = stmtline; - lr.hometok = LINK->t; - lr.kind = forloop; - lr.next = loopbase; - if ((lr.UU.U0.step >= 0 && *lr.UU.U0.vp->UU.U0.val > lr.UU.U0.max) || - (lr.UU.U0.step <= 0 && *lr.UU.U0.vp->UU.U0.val < lr.UU.U0.max)) { - saveline = stmtline; - i = 0; - j = 0; - do { - while (LINK->t == NULL) { - if (stmtline == NULL || stmtline->next == NULL) { - stmtline = saveline; - errormsg("FOR without NEXT"); - } - stmtline = stmtline->next; - LINK->t = stmtline->txt; - } - if (LINK->t->kind == tokfor) { - if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && - LINK->t->next->UU.vp == lr.UU.U0.vp) - j++; - else - i++; - } - if (LINK->t->kind == toknext) { - if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && - LINK->t->next->UU.vp == lr.UU.U0.vp) - j--; - else - i--; - } - LINK->t = LINK->t->next; - } while (i >= 0 && j >= 0); - skiptoeos(LINK); - return; - } - l = (looprec *) PHRQ_malloc(sizeof(looprec)); - if (l == NULL) malloc_error(); - *l = lr; - loopbase = l; -} - - -Local void cmdnext(struct LOC_exec *LINK) -{ - varrec *v; - boolean found; - looprec *l, *WITH; - - if (!iseos(LINK)) - v = findvar(LINK); - else - v = NULL; - do { - if (loopbase == NULL || loopbase->kind == gosubloop) - errormsg("NEXT without FOR"); - found = (boolean) (loopbase->kind == forloop && - (v == NULL || loopbase->UU.U0.vp == v)); - if (!found) { - l = loopbase->next; - free(loopbase); - loopbase = l; - } - } while (!found); - WITH = loopbase; - *WITH->UU.U0.vp->UU.U0.val += WITH->UU.U0.step; - if ((WITH->UU.U0.step < 0 || *WITH->UU.U0.vp->UU.U0.val <= WITH->UU.U0.max) && - (WITH->UU.U0.step > 0 || *WITH->UU.U0.vp->UU.U0.val >= WITH->UU.U0.max)) { - stmtline = WITH->homeline; - LINK->t = WITH->hometok; - return; - } - l = loopbase->next; - free(loopbase); - loopbase = l; -} - - -Local void cmdwhile(struct LOC_exec *LINK) -{ - looprec *l; - - l = (looprec *) PHRQ_malloc(sizeof(looprec)); - if (l == NULL) malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = whileloop; - l->homeline = stmtline; - l->hometok = LINK->t; - if (iseos(LINK)) - return; - if (realexpr(LINK) != 0) - return; - if (!skiploop(tokwhile, tokwend, LINK)) - errormsg("WHILE without WEND"); - l = loopbase->next; - free(loopbase); - loopbase = l; - skiptoeos(LINK); -} - - -Local void cmdwend(struct LOC_exec *LINK) -{ - tokenrec *tok; - linerec *tokline; - looprec *l; - boolean found; - - do { - if (loopbase == NULL || loopbase->kind == gosubloop) - errormsg("WEND without WHILE"); - found = (boolean) (loopbase->kind == whileloop); - if (!found) { - l = loopbase->next; - free(loopbase); - loopbase = l; - } - } while (!found); - if (!iseos(LINK)) { - if (realexpr(LINK) != 0) - found = false; - } - tok = LINK->t; - tokline = stmtline; - if (found) { - stmtline = loopbase->homeline; - LINK->t = loopbase->hometok; - if (!iseos(LINK)) { - if (realexpr(LINK) == 0) - found = false; - } - } - if (found) - return; - LINK->t = tok; - stmtline = tokline; - l = loopbase->next; - free(loopbase); - loopbase = l; -} - - -Local void cmdgosub(struct LOC_exec *LINK) -{ - looprec *l; - - l = (looprec *) PHRQ_malloc(sizeof(looprec)); - if (l == NULL) malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = gosubloop; - l->homeline = stmtline; - l->hometok = LINK->t; - cmdgoto(LINK); -} - - -Local void cmdreturn(struct LOC_exec *LINK) -{ - looprec *l; - boolean found; - - do { - if (loopbase == NULL) - errormsg("RETURN without GOSUB"); - found = (boolean) (loopbase->kind == gosubloop); - if (!found) { - l = loopbase->next; - free(loopbase); - loopbase = l; - } - } while (!found); - stmtline = loopbase->homeline; - LINK->t = loopbase->hometok; - l = loopbase->next; - free(loopbase); - loopbase = l; - skiptoeos(LINK); -} - - -Local void cmdread(struct LOC_exec *LINK) -{ - varrec *v; - tokenrec *tok; - boolean found; - - do { - v = findvar(LINK); - tok = LINK->t; - LINK->t = datatok; - if (dataline == NULL) { - dataline = linebase; - LINK->t = dataline->txt; - } - if (LINK->t == NULL || LINK->t->kind != tokcomma) { - do { - while (LINK->t == NULL) { - if (dataline == NULL || dataline->next == NULL) - errormsg("Out of Data"); - dataline = dataline->next; - LINK->t = dataline->txt; - } - found = (boolean) (LINK->t->kind == tokdata); - LINK->t = LINK->t->next; - } while (!found || iseos(LINK)); - } else - LINK->t = LINK->t->next; - if (v->stringvar) { - if (*v->UU.U1.sval != NULL) - *v->UU.U1.sval = (char *) free_check_null(*v->UU.U1.sval); - *v->UU.U1.sval = strexpr(LINK); - } else - *v->UU.U0.val = realexpr(LINK); - datatok = LINK->t; - LINK->t = tok; - if (!iseos(LINK)) - require(tokcomma, LINK); - } while (!iseos(LINK)); -} - - -Local void cmddata(struct LOC_exec *LINK) -{ - skiptoeos(LINK); -} - - -Local void cmdrestore(struct LOC_exec *LINK) -{ - if (iseos(LINK)) - restoredata(); - else { -#ifdef SKIP - dataline = mustfindline(intexpr(LINK), LINK); -#endif - dataline = mustfindline(intexpr(LINK)); - datatok = dataline->txt; - } -} - - -Local void cmdgotoxy(struct LOC_exec *LINK) -{ -#ifdef SKIP - long i; - - i = intexpr(LINK); -#endif - intexpr(LINK); - require(tokcomma, LINK); -} - - -Local void cmdon(struct LOC_exec *LINK) -{ - long i; - looprec *l; - - i = intexpr(LINK); - if (LINK->t != NULL && LINK->t->kind == tokgosub) { - l = (looprec *) PHRQ_malloc(sizeof(looprec)); - if (l == NULL) malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = gosubloop; - l->homeline = stmtline; - l->hometok = LINK->t; - LINK->t = LINK->t->next; - } else - require(tokgoto, LINK); - if (i < 1) { - skiptoeos(LINK); - return; - } - while (i > 1 && !iseos(LINK)) { - require(toknum, LINK); - if (!iseos(LINK)) - require(tokcomma, LINK); - i--; - } - if (!iseos(LINK)) - cmdgoto(LINK); -} - - -Local void cmddim(struct LOC_exec *LINK) -{ - long i, j, k; - varrec *v; - boolean done; - - do { - if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(); - v = LINK->t->UU.vp; - LINK->t = LINK->t->next; - if (v->numdims != 0) - errormsg("Array already dimensioned"); - j = 1; - i = 0; - require(toklp, LINK); - do { - k = intexpr(LINK) + 1; - if (k < 1) - badsubscr(); - if (i >= maxdims) - badsubscr(); - i++; - v->dims[i - 1] = k; - j *= k; - done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); - if (!done) - require(tokcomma, LINK); - } while (!done); - LINK->t = LINK->t->next; - v->numdims = (char) i; - if (v->stringvar) { - v->UU.U1.sarr = (Char **) PHRQ_malloc(j * sizeof(char *)); - if (v->UU.U1.sarr == NULL) malloc_error(); - for (i = 0; i < j; i++) - v->UU.U1.sarr[i] = NULL; - } else { - v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); - if (v->UU.U0.arr == NULL) malloc_error(); - for (i = 0; i < j; i++) - v->UU.U0.arr[i] = 0.0; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } while (!iseos(LINK)); -} - - -Local void cmdpoke(struct LOC_exec *LINK) -{ - union { - long i; - Char *c; - } trick; - -/* p2c: basic.p, line 2073: Note: Range checking is OFF [216] */ - trick.i = intexpr(LINK); - require(tokcomma, LINK); - *trick.c = (Char)intexpr(LINK); -/* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ -} - - - - - - - - - -Static void exec(void) -{ - struct LOC_exec V; - Char *ioerrmsg; - Char STR1[256]; - - - TRY(try1); - do { - do { - V.gotoflag = false; - V.elseflag = false; - while (stmttok != NULL && stmttok->kind == tokcolon) - stmttok = stmttok->next; - V.t = stmttok; - if (V.t != NULL) { - V.t = V.t->next; - switch (stmttok->kind) { - - case tokrem: - /* blank case */ - break; - - case toklist: - cmdlist(&V); - break; - - case tokrun: - cmdrun(&V); - break; - - case toknew: - cmdnew(&V); - break; - - case tokload: - cmdload(false, stringexpr(STR1, &V), &V); - break; - - case tokmerge: - cmdload(true, stringexpr(STR1, &V), &V); - break; - - case toksave: - cmdsave(&V); - break; - - case tokbye: -#ifdef SKIP - cmdbye(&V); -#endif - cmdbye(); - break; - - case tokdel: - cmddel(&V); - break; - - case tokrenum: - cmdrenum(&V); - break; - - case toklet: - cmdlet(false, &V); - break; - - case tokvar: - cmdlet(true, &V); - break; - - case tokprint: - cmdprint(&V); - break; - - case tokpunch: - cmdpunch(&V); - break; - - case tokput: - cmdput(&V); - break; - -#ifdef PHREEQ98 - case tokgraph_x: - cmdgraph_x(&V); - break; - - case tokgraph_y: - cmdgraph_y(&V); - break; - - case tokgraph_sy: - cmdgraph_sy(&V); - break; -#endif - - case tokinput: - error_msg("Basic command INPUT is not a legal command in PHREEQC.", STOP); -#ifdef SKIP - cmdinput(&V); -#endif - break; - - case tokgoto: - cmdgoto(&V); - break; - - case tokif: - cmdif(&V); - break; - - case tokelse: - cmdelse(&V); - break; - - case tokend: - cmdend(&V); - break; - - case tokstop: - P_escapecode = -20; - goto _Ltry1; - - case tokfor: - cmdfor(&V); - break; - - case toknext: - cmdnext(&V); - break; - - case tokwhile: - cmdwhile(&V); - break; - - case tokwend: - cmdwend(&V); - break; - - case tokgosub: - cmdgosub(&V); - break; - - case tokreturn: - cmdreturn(&V); - break; - - case tokread: - cmdread(&V); - break; - - case tokdata: - cmddata(&V); - break; - - case tokrestore: - cmdrestore(&V); - break; - - case tokgotoxy: - cmdgotoxy(&V); - break; - - case tokon: - cmdon(&V); - break; - - case tokdim: - cmddim(&V); - break; - - case tokpoke: - cmdpoke(&V); - break; - - default: - errormsg("Illegal command"); - break; - } - } - if (!V.elseflag && !iseos(&V)) - checkextra(&V); - stmttok = V.t; - } while (V.t != NULL); - if (stmtline != NULL) { - if (!V.gotoflag) - stmtline = stmtline->next; - if (stmtline != NULL) - stmttok = stmtline->txt; - } - } while (stmtline != NULL); - RECOVER2(try1,_Ltry1); - if (P_escapecode == -20) - error_msg("Break", CONTINUE); -#ifdef SKIP - printf("Break"); -#endif - else if (P_escapecode != 42) { - switch (P_escapecode) { - - case -4: -#ifdef SKIP - printf("\007Integer overflow"); -#endif - error_msg("Integer overflow", CONTINUE); - break; - - case -5: -#ifdef SKIP - printf("\007Divide by zero"); -#endif - error_msg("Divide by zero", CONTINUE); - break; - - case -6: -#ifdef SKIP - printf("\007Real math overflow"); -#endif - error_msg("Real math overflow", CONTINUE); - break; - - case -7: -#ifdef SKIP - printf("\007Real math underflow"); -#endif - error_msg("Real math underflow", CONTINUE); - break; - - case -8: - case -19: - case -18: - case -17: - case -16: - case -15: -#ifdef SKIP - printf("\007Value range error"); -#endif - error_msg("Value range error", CONTINUE); - break; - - case -10: - ioerrmsg = (char *) PHRQ_malloc(256); - if (ioerrmsg == NULL) malloc_error(); - sprintf(ioerrmsg, "I/O Error %d", (int)P_ioresult); -#ifdef SKIP - printf("\007%s", ioerrmsg); -#endif - error_msg(ioerrmsg, CONTINUE); - free(ioerrmsg); - break; - - default: - if (EXCP_LINE != -1) { - sprintf(error_string, "%12ld\n", EXCP_LINE); - error_msg(error_string, CONTINUE); - } -#ifdef SKIP - printf("%12ld\n", EXCP_LINE); -#endif - _Escape(P_escapecode); - break; - } - } - if (stmtline != NULL) { - sprintf(error_string, " in line %ld", stmtline->num); - error_msg(error_string, CONTINUE); - } -#ifdef SKIP - printf(" in %ld", stmtline->num); - putchar('\n'); -#endif - ENDTRY(try1); -} /*exec*/ - -int free_dim_stringvar(struct varrec *varbase) -{ - int i, k; - if (varbase->numdims > 0) { - k = 1; - for (i = 0; i < varbase->numdims; i++) { - k = k*(varbase->dims[i]); - } - for (i = 0; i < k; i++) { - free_check_null(varbase->UU.U1.sarr[i]); - } - varbase->UU.U1.sarr = (char **) free_check_null(varbase->UU.U1.sarr); - } - return(OK); -} diff --git a/basicsubs.cpp b/basicsubs.cpp deleted file mode 100644 index cf129578..00000000 --- a/basicsubs.cpp +++ /dev/null @@ -1,1774 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: basicsubs.c 338 2005-06-15 14:10:45Z dlpark $"; - -struct system_species { - char * name; - char *type; - LDBLE moles; -}; -struct system_species *sys; -int count_sys, max_sys; -LDBLE sys_tot; - -/* ---------------------------------------------------------------------- */ -LDBLE activity (char *species_name) -/* ---------------------------------------------------------------------- */ -{ - struct species *s_ptr; - LDBLE a; - if (svnid == NULL) fprintf(stderr," "); - - s_ptr = s_search(species_name); - if (s_ptr == s_h2o) { - a = pow(10., s_h2o->la); - } else if (s_ptr == s_eminus) { - a = pow(10.,s_eminus->la); - } else if (s_ptr == NULL || s_ptr->in == FALSE) { - a = 1e-99; - } else { - a = pow(10., s_ptr->lm + s_ptr->lg); - } - return(a); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_logk_n(char *name) -/* ---------------------------------------------------------------------- */ -{ - char token[MAX_LENGTH]; - int i; - LDBLE lk; - struct logk *logk_ptr; - LDBLE logk[8]; - struct name_coef add_logk; - - for (i = 0; i < 8; i++) { - logk[i] = 0.0; - } - strcpy(token, name); - logk_ptr = logk_search(token); - if (logk_ptr != NULL) { - add_logk.name = token; - add_logk.coef = 1.0; - add_other_logk(logk, 1, &add_logk); - lk = k_calc(logk, tk_x); - return(lk); - } - return(-999.99); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_logk_p(char *name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - char token[MAX_LENGTH]; - struct phase *phase_ptr; - LDBLE lk; - LDBLE logk[8]; - - strcpy(token, name); - phase_ptr = phase_bsearch(token, &j, FALSE); - if (phase_ptr != NULL) { - for (i = 0; i < 8; i++) { - logk[i] = 0.0; - } - select_log_k_expression(phase_ptr->logk, logk); - add_other_logk(logk, phase_ptr->count_add_logk, phase_ptr->add_logk); - lk = k_calc(logk, tk_x); - return(lk); - } - return(-999.99); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_logk_s(char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - char token[MAX_LENGTH]; - struct species *s_ptr; - LDBLE lk, logk[8]; - - strcpy(token, name); - s_ptr = s_search(token); - if (s_ptr != NULL) { - for (i = 0; i < 8; i++) { - logk[i] = 0.0; - } - select_log_k_expression(s_ptr->logk, logk); - add_other_logk(logk, s_ptr->count_add_logk, s_ptr->add_logk); - lk = k_calc(logk, tk_x); - return(lk); - } - return(-999.99); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_surface_charge(char *surface_name) -/* ---------------------------------------------------------------------- */ -{ - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char *ptr; - int i, j, k; - LDBLE charge; - struct rxn_token_temp *token_ptr; - struct master *master_ptr; - - /* - * Go through species, sum charge - */ - charge = 0; - for (k = 0; k < count_s_x; k++) { - if (s_x[k]->type != SURF) continue; - /* - * Match surface_name - */ - count_trxn=0; - trxn_add (s_x[k]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ - for (i=1; i < count_trxn; i++) { - token_ptr = &(trxn.token[i]); - if (token_ptr->s->type != SURF) continue; - master_ptr = trxn.token[i].s->primary; - strcpy(token, master_ptr->elt->name); - replace ("_", " ", token); - ptr = token; - copy_token(token1, &ptr, &j); - if (strcmp(surface_name, token1) == 0) { - charge += s_x[k]->moles *s_x[k]->z; - } - } - } - return(charge); -} -/* ---------------------------------------------------------------------- */ -LDBLE diff_layer_total(char *total_name, char *surface_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in LDBLE layer - */ - int i, j, k, count_g; - struct surface_charge *surface_charge_ptr1; - char name[MAX_LENGTH], token[MAX_LENGTH]; - char surface_name_local[MAX_LENGTH]; - char *ptr; - - LDBLE mass_water_surface; - LDBLE molality, moles_excess, moles_surface, charge; - - if (use.surface_ptr == NULL || (diffuse_layer_x == FALSE && - strcmp_nocase("psi", total_name) != 0 && - strcmp_nocase("charge", total_name) != 0 && - strcmp_nocase("sigma", total_name) != 0 ) - ) return(0); - -/* - * Find surface... - */ - i = 0; - for (j =0; j < count_unknowns; j++) { - if (use.surface_ptr->edl == TRUE) { - if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace ("_psi", "", name); - } else { - if (x[j]->type != SURFACE) continue; - strcpy(token, x[j]->master[0]->elt->name); - replace ("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); - } - if (surface_name != NULL) { - if (strcmp(name, surface_name) == 0) break; - } else { - break; - } - } - if (j >= count_unknowns) return(0); - strcpy(surface_name_local, name); - /* - * Psi, charge, sigma - */ - if (strcmp_nocase("psi", total_name) == 0) { - if (use.surface_ptr->edl == TRUE) { - return((LDBLE) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * - tk_x * LOG_10 / F_KJ_V_EQ)); - } else { - return(0); - } - } else if (strcmp_nocase("charge", total_name) == 0) { - if (use.surface_ptr->edl == TRUE && diffuse_layer_x == FALSE) { - return((LDBLE) (x[j]->f)); - } else { - return(calc_surface_charge(surface_name_local)); - } - } else if (strcmp_nocase("sigma", total_name) == 0) { - if (use.surface_ptr->edl == TRUE) { - if (diffuse_layer_x == TRUE) { - charge = calc_surface_charge(surface_name_local); - } else { - charge = x[j]->f; - } - if ((x[j]->surface_charge->specific_area * x[j]->surface_charge->grams) > 0) { - return((LDBLE) (charge * F_C_MOL / (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams))); - } else { - return(0); - } - } else { - return(0); - } - } else if (strcmp_nocase("water", total_name) == 0) { - if (diffuse_layer_x == TRUE) { - return(x[j]->surface_charge->mass_water); - } else { - return(0); - } - } -/* - * find total moles of each element in diffuse layer... - */ - surface_charge_ptr1 = x[j]->surface_charge; - mass_water_surface = surface_charge_ptr1->mass_water; - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) { - if (s_x[j]->type > HPLUS) continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; - - moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; - moles_surface = mass_water_surface * molality + moles_excess; -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } -/* - * Return totals - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - return((LDBLE) elt_list[j].coef); - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE equi_phase (char *phase_name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - - if (use.pp_assemblage_in == FALSE || use.pp_assemblage_ptr == NULL) return(0); - for( j = 0; j < count_unknowns; j++) { - if (x[j]->type != PP) continue; - if (strcmp_nocase(x[j]->pure_phase->name, phase_name) == 0) { - break; - } - } -/* - * Print pure phase assemblage data - */ - if (j == count_unknowns) { - /* if not an unknown */ - for (i=0; i < use.pp_assemblage_ptr->count_comps; i++) { - if (strcmp_nocase(use.pp_assemblage_ptr->pure_phases[i].name,phase_name) == 0) { - return(use.pp_assemblage_ptr->pure_phases[i].moles); - } - } - } else { - /* if an unknown */ - if (x[j]->moles < 0.0) x[j]->moles = 0.0; - return(x[j]->moles); - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE find_gas_comp (char *gas_comp_name) -/* ---------------------------------------------------------------------- */ -{ - int i; - - if (use.gas_phase_in == FALSE || use.gas_phase_ptr == NULL) return(0); - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - if (strcmp_nocase(use.gas_phase_ptr->comps[i].name, gas_comp_name) == 0) { - return(use.gas_phase_ptr->comps[i].phase->moles_x); - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE find_misc1 (char *s_s_name) -/* ---------------------------------------------------------------------- */ -{ - int j; - - if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0.0); - for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, s_s_name) == 0) { - if (use.s_s_assemblage_ptr->s_s[j].miscibility == TRUE) { - return(use.s_s_assemblage_ptr->s_s[j].xb1); - } else { - return(1.0); - } - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE find_misc2 (char *s_s_name) -/* ---------------------------------------------------------------------- */ -{ - int j; - - if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0.0); - for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, s_s_name) == 0) { - if (use.s_s_assemblage_ptr->s_s[j].miscibility == TRUE) { - return(use.s_s_assemblage_ptr->s_s[j].xb2); - } else { - return(1.0); - } - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE find_s_s_comp (char *s_s_comp_name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - - if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); - for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].comps[i].name, s_s_comp_name) == 0) { - if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { - return(use.s_s_assemblage_ptr->s_s[j].comps[i].moles); - } else { - return(0.0); - } - } - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE get_calculate_value(char *name) -/* ---------------------------------------------------------------------- */ -/* - * Gets value from a calclate_value structure - * arguments: name - * return: LDBLE of value - */ -{ - struct calculate_value *calculate_value_ptr; - calculate_value_ptr = calculate_value_search(name); - if (calculate_value_ptr == NULL) { - sprintf(error_string, "CALC_VALUE Basic function, %s not found.", name); - error_msg(error_string, CONTINUE); - input_error++; - return(MISSING); - } - if (name == NULL) { - sprintf(error_string, "Definition for calculated value not found, %s", name); - input_error++; - error_msg(error_string, CONTINUE); - return (MISSING); - } - if (calculate_value_ptr->calculated == FALSE) { - sprintf(error_string, "Calculated value used before it has been calculated, %s.\nCalculated values are evalutated in the order in which they were defined.", name); - input_error++; - error_msg(error_string, CONTINUE); - return (MISSING); - } - return(calculate_value_ptr->value); -} -/* ---------------------------------------------------------------------- */ -LDBLE kinetics_moles (char *kinetics_name) -/* ---------------------------------------------------------------------- */ -{ - int i; - - if (use.kinetics_in == FALSE || use.kinetics_ptr == NULL) return(0); - for (i = 0; i < use.kinetics_ptr->count_comps; i++) { - if (strcmp_nocase(use.kinetics_ptr->comps[i].rate_name, kinetics_name) == 0) { - return (use.kinetics_ptr->comps[i].m); - } - } - - sprintf(error_string, "No data for rate %s in KINETICS keyword.", kinetics_name); - warning_msg(error_string); - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE log_activity (char *species_name) -/* ---------------------------------------------------------------------- */ -{ - struct species *s_ptr; - LDBLE la; - - s_ptr = s_search(species_name); - - if (s_ptr == s_eminus) { - la = s_eminus->la; - } else if (s_ptr == NULL || s_ptr->in == FALSE) { - la = -99.99; - } else if (s_ptr == s_h2o) { - la = s_h2o->la; - } else { - la = s_ptr->lm + s_ptr->lg; - } - return(la); -} -/* ---------------------------------------------------------------------- */ -LDBLE log_molality (char *species_name) -/* ---------------------------------------------------------------------- */ -{ - struct species *s_ptr; - LDBLE lm; - - s_ptr = s_search(species_name); - - if (s_ptr == s_eminus) { - lm = -99.99; - } else if (s_ptr == NULL || s_ptr->in == FALSE) { - lm = -99.99; - } else if (s_ptr == s_h2o) { - lm = log10(s_ptr->moles / mass_water_aq_x); - } else { - lm = s_ptr->lm; - } - return(lm); -} -/* ---------------------------------------------------------------------- */ -LDBLE molality (char *species_name) -/* ---------------------------------------------------------------------- */ -{ - struct species *s_ptr; - LDBLE m; - - s_ptr = s_search(species_name); - if (s_ptr == NULL || s_ptr == s_eminus || s_ptr->in == FALSE) { - m = 1e-99; - } else { - /* m = pow(10., s_ptr->lm); */ - m = s_ptr->moles/mass_water_aq_x; - } - return(m); -} -/* ---------------------------------------------------------------------- */ -LDBLE saturation_ratio (char *phase_name) -/* ---------------------------------------------------------------------- */ -{ - struct rxn_token *rxn_ptr; - struct phase *phase_ptr; - int l; - LDBLE si, iap; - - iap = 0.0; - phase_ptr = phase_bsearch(phase_name, &l, FALSE); - if (phase_ptr == NULL) { - sprintf(error_string, "Mineral %s, not found.", phase_name); - warning_msg(error_string); - return(1e-99); - } else if (phase_ptr->in != FALSE) { - for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->s->la * rxn_ptr->coef; - } - si = iap - phase_ptr->lk; - return(pow(10.0, si)); - } - return(0.0); - -} -/* ---------------------------------------------------------------------- */ -int saturation_index (char *phase_name, LDBLE *iap, LDBLE *si) -/* ---------------------------------------------------------------------- */ -{ - struct rxn_token *rxn_ptr; - struct phase *phase_ptr; - int l; - - *si = -99.99; - *iap = 0.0; - phase_ptr = phase_bsearch(phase_name, &l, FALSE); - if (phase_ptr == NULL) { - sprintf(error_string, "Mineral %s, not found.", phase_name); - warning_msg(error_string); - *si = -99; - } else if (phase_ptr->in != FALSE) { - for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - *iap += rxn_ptr->s->la * rxn_ptr->coef; - } - *si = *iap - phase_ptr->lk; - } else { - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE sum_match_gases (char *mytemplate, char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE tot; - struct elt_list *next_elt; - - if (use.gas_phase_in == FALSE || use.gas_phase_ptr == NULL) return(0); - tot = 0; - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - if (match_elts_in_species(use.gas_phase_ptr->comps[i].phase->formula,mytemplate) == TRUE) { - if (name == NULL) { - tot += use.gas_phase_ptr->comps[i].phase->moles_x; - } else { - for (next_elt = use.gas_phase_ptr->comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { - if (strcmp(next_elt->elt->name, name) == 0) { - tot += next_elt->coef * use.gas_phase_ptr->comps[i].phase->moles_x; - break; - } - } - } - } - } - return(tot); -} -/* ---------------------------------------------------------------------- */ -LDBLE sum_match_species (char *mytemplate, char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE tot; - struct elt_list *next_elt; - - count_elts = 0; - paren_count = 0; - tot = 0; - for (i = 0; i < count_s_x; i++) { - if (match_elts_in_species(s_x[i]->name, mytemplate) == TRUE) { - if (name == NULL) { - tot += s_x[i]->moles; - } else { - for (next_elt = s_x[i]->next_elt; next_elt->elt != NULL; next_elt++) { - if (strcmp(next_elt->elt->name, name) == 0) { - tot += next_elt->coef * s_x[i]->moles; - break; - } - } - } - } - } - return(tot); -} -/* ---------------------------------------------------------------------- */ -LDBLE sum_match_s_s (char *mytemplate, char *name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE tot; - struct elt_list *next_elt; - - if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); - tot = 0; - for (j=0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - if (strcmp_nocase(use.s_s_assemblage_ptr->s_s[j].name, mytemplate) == 0) { - if (use.s_s_assemblage_ptr->s_s[j].s_s_in == FALSE) { - tot = 0; - break; - } - for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (name == NULL) { - tot += use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - } else { - for (next_elt = use.s_s_assemblage_ptr->s_s[j].comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { - if (strcmp(next_elt->elt->name, name) == 0) { - tot += next_elt->coef * use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - break; - } - } - } - } - break; - } - } - return(tot); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE sum_match_s_s (char *template, char *name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE tot; - struct elt_list *next_elt; - - if (use.s_s_assemblage_in == FALSE || use.s_s_assemblage_ptr == NULL) return(0); - tot = 0; - for (j=0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (match_elts_in_species(use.s_s_assemblage_ptr->s_s[j].comps[i].phase->formula,template) == TRUE) { - if (name == NULL) { - tot += use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - } else { - for (next_elt = use.s_s_assemblage_ptr->s_s[j].comps[i].phase->next_elt; next_elt->elt != NULL; next_elt++) { - if (strcmp(next_elt->elt->name, name) == 0) { - tot += next_elt->coef * use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - break; - } - } - } - } - } - } - return(tot); -} -#endif -/* ---------------------------------------------------------------------- */ -int match_elts_in_species (char *name, char *mytemplate) -/* ---------------------------------------------------------------------- */ -{ -/* - * Makes a list of elements with their coefficients, stores elements - * in elt_list at position count_elts. Global variable count_elts is - * updated with each stored element. Also uses static global variable - * paren_count. - * - * Arguments: - * **t_ptr input, point in token string to start looking - * output, is next position to start looking - * coef input, coefficient to multiply subscripts by - */ - int i, i1, l, case_no, match; - char c, c1; - char *ptr, *ptr1, *replace_name, *name_ptr; - LDBLE d; - char element[MAX_LENGTH]; - char token[MAX_LENGTH], equal_list[MAX_LENGTH], elt_name[MAX_LENGTH]; - char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH]; - char str[2]; - - strcpy(token, name); - squeeze_white(token); - while (replace("(+","(",token)); - while (replace("++++++","+6",token)); - while (replace("+++++","+5",token)); - while (replace("++++","+4",token)); - while (replace("+++","+3",token)); - while (replace("++","+2",token)); - while (replace("------","-6",token)); - while (replace("-----","-5",token)); - while (replace("----","-4",token)); - while (replace("---","-3",token)); - while (replace("--","-2",token)); - - ptr = token; - count_match_tokens = 0; - while ( (c=*ptr) != '\0') { - c1=*(ptr+1); - str[0] = c; - str[1] = '\0'; -/* - * New element - */ - if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) { - /* - * Get new element and subscript - */ - if ( get_elt( &ptr, element, &l) == ERROR) { - return(ERROR); - } - match_tokens[count_match_tokens].name = string_hsave(element); - if ( get_num( &ptr , &d ) == ERROR) { - return(ERROR); - } - match_tokens[count_match_tokens++].coef = d; - } else { - match_tokens[count_match_tokens].name = string_hsave(str); - match_tokens[count_match_tokens++].coef = 1.0; - ptr += 1; - } - } - /* - * Replace elements with first of equivalent elements - */ - strcpy(template1, mytemplate); - squeeze_white(template1); - ptr = template1; - while (extract_bracket(&ptr, equal_list) == TRUE) { - replace("{","",equal_list); - replace("}","",equal_list); - while (replace(","," ",equal_list) == TRUE); - ptr1 = equal_list; - /* - * Get first name in a list from template - */ - if (copy_token(elt_name, &ptr1, &l) == EMPTY) { - sprintf(error_string, "Expecting a nonempty list of element names in isotope sum. %s", mytemplate); - error_msg(error_string, CONTINUE); - return(ERROR); - } - replace_name = string_hsave(elt_name); - /* - * Replace in species all equivalent names from template - */ - while (copy_token(elt_name, &ptr1, &l) != EMPTY) { - name_ptr = string_hsave (elt_name); - for (i = 0; i < count_match_tokens; i++) { - if (name_ptr == match_tokens[i].name) { - match_tokens[i].name = replace_name; - } - } - } - } - /* - * Combine contiguous elements - */ - i1 = 0; - for ( i = 1; i < count_match_tokens; i++) { - if ((isupper((int) (match_tokens[i].name[0])) != FALSE) && (match_tokens[i].name == match_tokens[i1].name)) { - match_tokens[i1].coef += match_tokens[i].coef; - } else { - i1++; - match_tokens[i1].name = match_tokens[i].name; - match_tokens[i1].coef = match_tokens[i].coef; - } - } - count_match_tokens = i1 + 1; - /* - * write out string - */ - token[0] = '\0'; - for (i = 0; i < count_match_tokens; i++) { - strcat(token, match_tokens[i].name); - if (match_tokens[i].coef != 1.0) { - sprintf(token1, "%g", (double) match_tokens[i].coef); - strcat(token, token1); - } - } - /* - * Write a template name using first of equivalent elements - */ - strcpy(template1, mytemplate); - squeeze_white(template1); - ptr = template1; - while (extract_bracket(&ptr, equal_list) == TRUE) { - strcpy(equal_list1, equal_list); - replace("{","",equal_list); - replace("}","",equal_list); - while (replace(","," ",equal_list) == TRUE); - ptr1 = equal_list; - /* - * Get first name in a list - */ - if (copy_token(elt_name, &ptr1, &l) == EMPTY) { - sprintf(error_string, "Expecting a nonempty list of element names in isotope sum. %s", mytemplate); - error_msg(error_string, CONTINUE); - return(ERROR); - } - replace_name = string_hsave(elt_name); - replace(equal_list1, replace_name, template1); - squeeze_white(template1); - ptr = template1; - } - /* - * Compare string - */ - /* Cases: 0 exact match - * 1 leading wild card - * 2 trailing wild card - * 3 leading and trailing wild card - */ - case_no = 0; - if (template1[0] == '*') case_no = 1; - l = strlen(template1); - if (template1[l - 1] == '*') { - if (case_no != 1) { - case_no = 2; - } else { - case_no = 3; - } - } - while (replace("*","",template1)); - match = FALSE; - switch (case_no) { - case 0: - /* exact match */ - if (strcmp(token, template1) == 0) match = TRUE; - break; - case 1: - /* leading wild card */ - if ((ptr = strstr(token, template1)) == NULL) { - match = FALSE; - } else { - if (strcmp(ptr, template1) == 0) match = TRUE; - } - break; - case 2: - /* trailing wild card */ - if (strstr(token, template1) == token) match = TRUE; - break; - case 3: - /* trailing wild card */ - if (strstr(token, template1) != NULL) match = TRUE; - break; - } - return (match); -} -/* ---------------------------------------------------------------------- */ -int extract_bracket(char **string, char *bracket_string) -/* ---------------------------------------------------------------------- */ -{ - char *ptr, *ptr1; - - if ((ptr = strstr(*string, "{")) == NULL) return(FALSE); - strcpy(bracket_string, ptr); - if ((ptr1 = strstr(bracket_string, "}")) == NULL) { - sprintf(error_string, "No matching bracket (}) in isotope template string %s", *string); - error_msg(error_string, CONTINUE); - input_error++; - return(FALSE); - } - ptr1[1] = '\0'; - *string = strstr(*string, "}"); - *string += 1; - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -LDBLE surf_total(char *total_name, char *surface_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in LDBLE layer - */ - int i, j, k; - char name[MAX_LENGTH], token[MAX_LENGTH]; - char surface_name_local[MAX_LENGTH]; - char *ptr; - - if (use.surface_ptr == NULL) return(0); - -/* - * Find surface... - */ - for (j =0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE) continue; - strcpy(token, x[j]->master[0]->elt->name); - replace ("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); - if (surface_name != NULL) { - if (strcmp(name, surface_name) == 0) break; - } else { - break; - } - } - if (j >= count_unknowns) return(0); - strcpy(surface_name_local, name); -/* - * find total moles of each element in diffuse layer... - */ - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) { - if (s_x[j]->type != SURF) continue; - for (i=0; s_x[j]->next_elt[i].elt != NULL; i++) { - strcpy(token, s_x[j]->next_elt[i].elt->name); - replace ("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); - if (strcmp(name, surface_name_local) == 0) { -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, s_x[j]->moles); - break; - } - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } -/* - * Return totals - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - return((LDBLE) elt_list[j].coef); - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -LDBLE total (char *total_name) -/* ---------------------------------------------------------------------- */ -{ - struct master *master_ptr; - LDBLE t; - int i; - - if (strcmp_nocase(total_name,"water") == 0) { - return(mass_water_aq_x); - } - if (strcmp(total_name,"H") == 0) { - return(total_h_x/mass_water_aq_x); - } - if (strcmp(total_name,"O") == 0) { - return(total_o_x/mass_water_aq_x); - } - master_ptr = master_bsearch(total_name); - t = 0.0; - if (master_ptr == NULL) { - sprintf(error_string,"Can not find definition for master species, %s.", total_name); - warning_msg(error_string); -/* - * Primary master species - */ - } else if (master_ptr->primary == TRUE) { - /* - * Not a redox element - */ - if (master_ptr->s->secondary == NULL) { - t = master_ptr->total/mass_water_aq_x; - /* - * Redox element, need to sum totals of all redox states - */ - } else { - t = 0; - for (i = master_ptr->number + 1; master[i]->elt->primary == master_ptr; i++) { - t += master[i]->total/mass_water_aq_x; - } - } -/* - * Secondary master species - */ - } else { - t = master_ptr->total/mass_water_aq_x; - } - return(t); -} -/* ---------------------------------------------------------------------- */ -LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; - - sys_tot = 0; - count_sys = 0; - max_sys = 100; - space ((void **) ((void *) &sys), INIT, &max_sys, sizeof (struct system_species)); - if (strcmp_nocase(total_name,"elements") == 0) { - system_total_elements(); - } else if (strcmp_nocase(total_name,"phases") == 0) { - system_total_si(); - } else if (strcmp_nocase(total_name,"aq") == 0) { - system_total_aq(); - } else if (strcmp_nocase(total_name,"ex") == 0) { - system_total_ex(); - } else if (strcmp_nocase(total_name,"surf") == 0) { - system_total_surf(); - } else if (strcmp_nocase(total_name,"s_s") == 0) { - system_total_s_s(); - } else if (strcmp_nocase(total_name,"gas") == 0) { - system_total_gas(); - } else { - if (strstr(total_name,"(") == NULL) { - system_total_elt(total_name); - } else { - system_total_elt_secondary(total_name); - } - } - /* - * Sort system species - */ - if (count_sys > 1 ) { - qsort (sys, (size_t) count_sys, - (size_t) sizeof(struct system_species), system_species_compare); - } - /* - * malloc space - */ - *names = (char **) PHRQ_malloc((size_t) (count_sys+1) * sizeof (char *)); - if (names == NULL) malloc_error(); - *types = (char **) PHRQ_malloc((size_t) (count_sys+1) * sizeof (char *)); - if (types == NULL) malloc_error(); - *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys+1) * sizeof (LDBLE)); - if (moles == NULL) malloc_error(); - - (*names)[0] = NULL; - (*types)[0] = NULL; - (*moles)[0] = 0; - for(i = 0; i < count_sys; i++) { - /* output_msg(OUTPUT_MESSAGE, "%20s\t%10s\t%e\n", sys[i].name, sys[i].type, sys[i].moles); */ - (*names)[i + 1] = sys[i].name; - (*types)[i + 1] = sys[i].type; - (*moles)[i + 1] = sys[i].moles; - } - *count = (LDBLE) count_sys; - PHRQ_free(sys); - if (strcmp_nocase(total_name,"elements") == 0) { - sys_tot = 0;; - for (i = 0; i < count_sys; i++) { - if (strcmp(sys[i].type,"dis") == 0 && - strstr(sys[i].name,"(") == NULL && - strcmp(sys[i].name,"H") != 0 && - strcmp(sys[i].name,"O") != 0) { - sys_tot += sys[i].moles; - } - } - } - return(sys_tot); -} -/* ---------------------------------------------------------------------- */ -int system_total_elements(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE t; - char name[MAX_LENGTH]; - struct master *master_ptr; - - /* - * Include H and O - */ - sys[count_sys].name = string_duplicate("H"); - sys[count_sys].moles = total_h_x; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("dis"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - sys[count_sys].name = string_duplicate("O"); - sys[count_sys].moles = total_o_x; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("dis"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - /* - * Include H(1) and O(-2) - */ - sys[count_sys].name = string_duplicate("H(1)"); - sys[count_sys].moles = solution_sum_secondary("H(1)"); - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("dis"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - sys[count_sys].name = string_duplicate("O(-2)"); - sys[count_sys].moles = solution_sum_secondary("O(-2)"); - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("dis"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - - for (i = 0; i < count_master; i++) { - master_ptr=master[i]; - if (master_ptr->primary == TRUE && master_ptr->total_primary <= 0) continue; - if (master_ptr->in == FALSE && (master_ptr->primary == FALSE || master_ptr->total_primary == 0)) continue; - /* - * H and O - */ - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } - if (master_ptr->primary == TRUE) { - if (master_ptr->total_primary > 0) { - t = master_ptr->total_primary; - /* - * Not a redox element - */ - } else if (master_ptr->s->secondary == NULL) { - t = master_ptr->total; - /* - * Redox element, need to sum totals of all redox states - */ - } else { - t = 0; - for (j = master_ptr->number + 1; master[j]->elt->primary == master_ptr; j++) { - t += master[j]->total; - } - } - /* - * Secondary master species - */ - } else { - t = master_ptr->total; - } - strcpy(name, master[i]->elt->name); - sys[count_sys].name = string_duplicate(name); - sys[count_sys].moles = t; - sys_tot += sys[count_sys].moles; - if (master[i]->s->type <= SOLID) { - sys[count_sys].type = string_duplicate("dis"); - } else if (master[i]->s->type == EX) { - sys[count_sys].type = string_duplicate("ex"); - } else if (master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) { - sys[count_sys].type = string_duplicate("surf"); - } - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_si(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE si, iap; - struct rxn_token *rxn_ptr; - char name[MAX_LENGTH]; - - for (i=0; i < count_phases; i++) { - if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; -/* - * Print saturation index - */ - iap = 0.0; - for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->s->la * rxn_ptr->coef; - } - si=-phases[i]->lk + iap; - /* output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, si, iap, (LDBLE) phases[i]->lk, phases[i]->formula); */ - strcpy(name, phases[i]->name); - sys[count_sys].name = string_duplicate(name); - sys[count_sys].moles = si; - if (si > sys_tot) sys_tot = si; - sys[count_sys].type = string_duplicate("phase"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_aq(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; -/* - * find total moles in aq, surface, and exchange - */ - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type != AQ) continue; - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = s_x[i]->moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("aq"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_ex(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; -/* - * find total moles in aq, surface, and exchange - */ - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type != EX) continue; - if (s_x[i]->primary != NULL) continue; - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = s_x[i]->moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("ex"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_surf(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; -/* - * find total moles in aq, surface, and exchange - */ - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type != SURF) continue; - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = s_x[i]->moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("surf"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_gas(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i; - -/* - * find total in gas phase - */ - if (use.gas_phase_ptr == NULL) return(OK); - for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { - sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); - sys[count_sys].moles = use.gas_phase_ptr->comps[i].phase->moles_x; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_s_s(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i, k; - -/* - * Solid solutions - */ - if (use.s_s_assemblage_ptr == NULL) return(OK); - for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { - sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); - sys[count_sys].moles = use.s_s_assemblage_ptr->s_s[k].comps[i].moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_elt(char *total_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i, j, k, count_g; - LDBLE molality, moles_excess, moles_surface, mass_water_surface; - char name[MAX_LENGTH]; - -/* - * find total moles in aq, surface, and exchange - */ - for (i = 0; i < count_s_x; i++) { - count_elts = 0; - paren_count = 0; - add_elt_list(s_x[i]->next_elt, s_x[i]->moles); - - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* - * Look for element - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - if (s_x[i]->type == AQ) { - sys[count_sys].type = string_duplicate("aq"); - } else if (s_x[i]->type == EX) { - sys[count_sys].type = string_duplicate("ex"); - } else if (s_x[i]->type == SURF) { - sys[count_sys].type = string_duplicate("surf"); - } else if (s_x[i]->type == HPLUS) { - sys[count_sys].type = string_duplicate("aq"); - /* sys[count_sys].moles = total_h_x; */ - } else if (s_x[i]->type == H2O) { - sys[count_sys].type = string_duplicate("aq"); - /* sys[count_sys].moles = total_o_x; */ - } else { - error_msg("System_total", STOP); - } - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { - /* - * Find position of component in surface charge data - */ - i = -1; - for (k = 0; k < count_unknowns; k++) { - if (x[k]->type != SURFACE_CB) continue; - i++; - /* - * Loop through all surface components, calculate each H2O surface (diffuse layer), - * H2O aq, and H2O bulk (diffuse layers plus aqueous). - */ - mass_water_surface = x[k]->surface_charge->mass_water; - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) { - if (s_x[j]->type > HPLUS) continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; - moles_excess = mass_water_aq_x * molality * x[k]->surface_charge->g[count_g].g; - moles_surface = mass_water_surface * molality + moles_excess; - /* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* - * Print totals - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - strcpy(name, x[k]->master[0]->elt->name); - replace ("_psi", "", name); - sys[count_sys].name = string_duplicate(name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("diff"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } -/* - * find total moles in mineral phases - */ - if (use.pp_assemblage_in == TRUE && use.pp_assemblage_ptr != NULL) { - for( i = 0; i < count_unknowns; i++) { - if (x[i]->type != PP) continue; - if (x[i]->pure_phase->add_formula != NULL) continue; - count_elts = 0; - paren_count = 0; - add_elt_list(x[i]->pure_phase->phase->next_elt, x[i]->moles); - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(x[i]->pure_phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("equi"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } -/* - * Solid solutions - */ - if (use.s_s_assemblage_ptr != NULL) { - for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { - if (use.s_s_assemblage_ptr->s_s[k].s_s_in == TRUE) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { - count_elts = 0; - paren_count = 0; - add_elt_list(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->next_elt, use.s_s_assemblage_ptr->s_s[k].comps[i].moles); - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - } -/* - * find total in gas phase - */ - if (use.gas_phase_ptr != NULL) { - for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { - if (use.gas_phase_ptr->comps[i].phase->in == TRUE) { - count_elts = 0; - paren_count = 0; - add_elt_list(use.gas_phase_ptr->comps[i].phase->next_elt, use.gas_phase_ptr->comps[i].phase->moles_x); - - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* - * Look for element - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_total_elt_secondary(char *total_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i, j, k, l, count_g; - LDBLE molality, moles_excess, moles_surface, mass_water_surface, sum, coef; - char name[MAX_LENGTH]; -/* - * find total moles in aq, surface, and exchange - */ - for (i = 0; i < count_s_x; i++) { - count_elts = 0; - paren_count = 0; - if (s_x[i]->next_secondary != NULL) { - add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); - } else { - add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* debug - output_msg(OUTPUT_MESSAGE, "%s\n", s_x[i]->name); - for ( j=0; j < count_elts; j++ ) { - output_msg(OUTPUT_MESSAGE, "\t%10s\t%g\n", elt_list[j].elt->name, elt_list[j].coef); - } - */ - /* - * Look for element - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(s_x[i]->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - if (s_x[i]->type == AQ) { - sys[count_sys].type = string_duplicate("aq"); - } else if (s_x[i]->type == EX) { - sys[count_sys].type = string_duplicate("ex"); - } else if (s_x[i]->type == SURF) { - sys[count_sys].type = string_duplicate("surf"); - } else if (s_x[i]->type == HPLUS) { - sys[count_sys].type = string_duplicate("aq"); - /* sys[count_sys].moles = total_h_x; */ - } else if (s_x[i]->type == H2O) { - sys[count_sys].type = string_duplicate("aq"); - /* sys[count_sys].moles = total_o_x; */ - } else { - error_msg("System_total", STOP); - } - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { - /* - * Find position of component in surface charge data - */ - i = -1; - for (k = 0; k < count_unknowns; k++) { - if (x[k]->type != SURFACE_CB) continue; - i++; - /* - * Loop through all surface components, calculate each H2O surface (diffuse layer), - * H2O aq, and H2O bulk (diffuse layers plus aqueous). - */ - mass_water_surface = x[k]->surface_charge->mass_water; - sum = 0; - for (j = 0; j < count_s_x; j++) { - count_elts = 0; - paren_count = 0; - if (s_x[i]->next_secondary != NULL) { - add_elt_list(s_x[i]->next_secondary, 1); - } else { - add_elt_list(s_x[i]->next_sys_total, 1); - } - for ( l=0; l < count_elts; l++ ) { - if (strcmp(elt_list[l].elt->name, total_name) == 0) { - coef = elt_list[l].coef; - if (s_x[j]->type > H2O) continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; - moles_excess = mass_water_aq_x * molality * x[k]->surface_charge->g[count_g].g; - moles_surface = mass_water_surface * molality + moles_excess; - sum += moles_surface * coef; - break; - } - } - if (l >= count_elts) continue; - strcpy(name, x[k]->master[0]->elt->name); - replace ("_psi", "", name); - sys[count_sys].name = string_duplicate(name); - sys[count_sys].moles = sum; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("diff"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } -/* - * find total moles in mineral phases - */ - if (use.pp_assemblage_in == TRUE && use.pp_assemblage_ptr != NULL) { - for( i = 0; i < count_unknowns; i++) { - if (x[i]->type != PP) continue; - if (x[i]->pure_phase->add_formula != NULL) continue; - count_elts = 0; - paren_count = 0; - add_elt_list(x[i]->pure_phase->phase->next_sys_total, x[i]->moles); - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* debug - output_msg(OUTPUT_MESSAGE, "%s\n", x[i]->pure_phase->phase->name); - for ( j=0; j < count_elts; j++ ) { - output_msg(OUTPUT_MESSAGE, "\t%10s\t%g\n", elt_list[j].elt->name, elt_list[j].coef); - } - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(x[i]->pure_phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("equi"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } -/* - * Solid solutions - */ - if (use.s_s_assemblage_ptr != NULL) { - for( k = 0; k < use.s_s_assemblage_ptr->count_s_s; k++) { - if (use.s_s_assemblage_ptr->s_s[k].s_s_in == TRUE) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[k].count_comps; i++) { - count_elts = 0; - paren_count = 0; - add_elt_list(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->next_sys_total, use.s_s_assemblage_ptr->s_s[k].comps[i].moles); - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(use.s_s_assemblage_ptr->s_s[k].comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - } -/* - * find total in gas phase - */ - if (use.gas_phase_ptr != NULL) { - for( i = 0; i < use.gas_phase_ptr->count_comps; i++) { - if (use.gas_phase_ptr->comps[i].phase->in == TRUE) { - count_elts = 0; - paren_count = 0; - add_elt_list(use.gas_phase_ptr->comps[i].phase->next_sys_total, use.gas_phase_ptr->comps[i].phase->moles_x); - - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* - * Look for element - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sys[count_sys].name = string_duplicate(use.gas_phase_ptr->comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("gas"); - count_sys++; - space ((void **) ((void *) &sys), count_sys, &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE solution_sum_secondary(char *total_name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i, j; - LDBLE sum; -/* - * find total moles in aq, surface, and exchange - */ - sum = 0; - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type > H2O) continue; - count_elts = 0; - paren_count = 0; - if (s_x[i]->next_secondary != NULL) { - add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); - } else { - add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - /* - * Look for element - */ - for ( j=0; j < count_elts; j++ ) { - if (strcmp(elt_list[j].elt->name, total_name) == 0) { - sum += elt_list[j].coef; - break; - } - } - } - return(sum); -} -/* ---------------------------------------------------------------------- */ -int system_species_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct system_species *a, *b; - - a=(const struct system_species *) ptr1; - b=(const struct system_species *) ptr2; - if (a->moles < b->moles) return(1); - if (a->moles > b->moles) return(-1); - return(0); -} - -/* ---------------------------------------------------------------------- */ -int system_total_solids(struct exchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, - struct surface *surface_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in solid phases - */ - int i, j; - - count_elts = 0; - paren_count = 0; -/* - * find total moles in exchanger - */ - if (exchange_ptr != NULL) { - for( i = 0; i < exchange_ptr->count_comps; i++) { - add_elt_list(exchange_ptr->comps[i].totals, 1.0); - } - } - if (surface_ptr != NULL) { - for( i = 0; i < surface_ptr->count_comps; i++) { - add_elt_list(surface_ptr->comps[i].totals, 1.0); - } - } - if (s_s_assemblage_ptr != NULL) { - for( i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - for (j = 0; j < s_s_assemblage_ptr->s_s[i].count_comps; j++) { - add_elt_list(s_s_assemblage_ptr->s_s[i].comps[j].phase->next_elt, s_s_assemblage_ptr->s_s[i].comps[j].moles); - } - } - } - if (gas_phase_ptr != NULL) { - for( i = 0; i < gas_phase_ptr->count_comps; i++) { - add_elt_list(gas_phase_ptr->comps[i].phase->next_elt, gas_phase_ptr->comps[i].moles); - } - } - if (pp_assemblage_ptr != NULL) { - for( i = 0; i < pp_assemblage_ptr->count_comps; i++) { - add_elt_list(pp_assemblage_ptr->pure_phases[i].phase->next_elt, pp_assemblage_ptr->pure_phases[i].moles); - } - } - - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - return(OK); -} diff --git a/cl1.cpp b/cl1.cpp deleted file mode 100644 index 93fc89e7..00000000 --- a/cl1.cpp +++ /dev/null @@ -1,753 +0,0 @@ -#include -#include -#include -#include - -/* must be defined here and in global.h */ -#if !defined(WIN32_MEMORY_DEBUG) -#define USE_PHRQ_ALLOC -#endif -#include "phqalloc.h" -#include "output.h" -#include "phrqtype.h" - -int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q, - int *kode, LDBLE toler, - int *iter, LDBLE *x, LDBLE *res, LDBLE *error, - LDBLE *cu, int *iu, int *s, - int check); -static char const svnid[] = "$Id: cl1.c 248 2005-04-14 17:10:53Z dlpark $"; - -extern void *free_check_null(void *ptr); -extern void malloc_error(void); - -/* debug -#define DEBUG_CL1 -#define CHECK_ERRORS - */ - -int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q, - int *kode, LDBLE toler, - int *iter, LDBLE *x, LDBLE *res, LDBLE *error, - LDBLE *cu, int *iu, int *s, int check) -{ - /* System generated locals */ - LDBLE *scratch; - union double_or_int {int ival; LDBLE dval;} *q2; - - /* Local variables */ - static int nklm; - static LDBLE xmin, xmax; - static int iout, i, j; - static LDBLE z; - static int maxit, n1, n2; - static LDBLE pivot; - static int ia, ii, kk, in, nk, js; - static LDBLE sn; - static int iphase, kforce; - static LDBLE zu, zv; - static LDBLE tpivot; - static int klm, jmn, nkl, jpn; - static LDBLE cuv, sum; - static int klm1; - int q_dim, cu_dim; - int kode_arg; - LDBLE *x_arg, *res_arg, check_toler; -#ifdef CHECK_ERRORS - extern char **col_name, **row_name; - extern int *row_back, *col_back; -#endif -/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ -/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ -/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ -/* AX=B */ -/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ -/* CX=D */ -/* AND M LINEAR INEQUALITY CONSTRAINTS */ -/* EX.LE.F. */ -/* DESCRIPTION OF PARAMETERS */ -/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ -/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ -/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ -/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ -/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ -/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ -/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ -/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ -/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ -/* AT LEAST N2D COLUMNS. */ -/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ -/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ -/* AND N+1 COLUMNS OF Q AS FOLLOWS */ -/* A B */ -/* Q = C D */ -/* E F */ -/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ -/* KODE A CODE USED ON ENTRY TO, AND EXIT */ -/* FROM, THE SUBROUTINE. */ -/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ -/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ -/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ -/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ -/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ -/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ -/* RES (SEE BELOW). */ -/* ON EXIT, KODE HAS ONE OF THE */ -/* FOLLOWING VALUES */ -/* 0- OPTIMAL SOLUTION FOUND, */ -/* 1- NO FEASIBLE SOLUTION TO THE */ -/* CONSTRAINTS, */ -/* 2- CALCULATIONS TERMINATED */ -/* PREMATURELY DUE TO ROUNDING ERRORS, */ -/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ -/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ -/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ -/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ -/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ -/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ -/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ -/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ -/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ -/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ -/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ -/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ -/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ -/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ -/* ON EXIT THIS ARRAY CONTAINS A */ -/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ -/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ -/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ -/* VARIABLES. THE VALUES -1, 0, OR 1 */ -/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ -/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ -/* OR .GE.0 RESPECTIVELY. */ -/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ -/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ -/* IN THE FIRST K COMPONENTS, D-CX IN THE */ -/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ -/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ -/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ -/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ -/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ -/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ -/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ -/* RESPECTIVELY. */ -/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ -/* ABSOLUTE VALUES OF THE RESIDUALS. */ -/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ -/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ -/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ -/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ -/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ -/* WORKSPACE. */ -/* DOUBLE PRECISION DBLE */ -/* REAL */ - -/* INITIALIZATION. */ - if (svnid == NULL) fprintf(stderr," "); - - - zv = 0; - kode_arg = *kode; - x_arg = NULL; - res_arg = NULL; - if (check == 1) { - /* - q_arg = PHRQ_malloc((size_t) (max_row_count * max_column_count * sizeof(LDBLE))); - if (q_arg == NULL) malloc_error(); - for (i = 0; i < max_row_count*max_column_count; i++) { - q_arg[i] = q[i]; - } - */ - x_arg = (double *) PHRQ_malloc((size_t) (n2d * sizeof(LDBLE))); - if (x_arg == NULL) malloc_error(); - for (i = 0; i < n2d; i++) { - x_arg[i] = x[i]; - } - res_arg = (double *) PHRQ_malloc((size_t) ((k + l + m) * sizeof(LDBLE))); - if (res_arg == NULL) malloc_error(); - for (i = 0; i < k + l + m; i++) { - res_arg[i] = res[i]; - } - } -/* Parameter adjustments */ - q_dim = n2d; - q2 = (union double_or_int *) q; - cu_dim = nklmd; - -/* Function Body */ - maxit = *iter; - n1 = n + 1; - n2 = n + 2; - nk = n + k; - nkl = nk + l; - klm = k + l + m; - klm1 = klm + 1; - nklm = n + klm; - kforce = 1; - *iter = 0; - js = 0; - ia = -1; -/* Make scratch space */ - scratch = (LDBLE *) PHRQ_malloc( (size_t) nklmd * sizeof(LDBLE)); - if (scratch == NULL) malloc_error(); - for (i=0; i < nklmd; i++) { - scratch[i] = 0.0; - } -/* SET UP LABELS IN Q. */ - for (j = 0; j < n; ++j) { - q2[ klm1 * q_dim + j ].ival = j + 1; - } -/* L10: */ - for (i = 0; i < klm; ++i) { - q2[ i * q_dim + n1 ].ival = n + i + 1; - if (q2[ i * q_dim + n ].dval < 0.) { - for (j = 0; j < n1; ++j) { - q2[ i * q_dim + j ].dval = -q2[ i * q_dim + j ].dval; - } - q2[ i * q_dim + n1 ].ival = -q2[ i * q_dim + n1 ].ival; -/* L20: */ - } - } -/* L30: */ -/* SET UP PHASE 1 COSTS. */ - iphase = 2; -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Set up phase 1 costs\n"); -#endif -/* Zero first row of cu and iu */ - memcpy( (void *) &(cu[0]), (void *) &(scratch[0]), - (size_t) nklm * sizeof(LDBLE) ); - for (j = 0; j < nklm; ++j) { - iu[ j ] = 0; - } -/* L40: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L40\n"); -#endif - if (l != 0) { - for (j = nk; j < nkl; ++j) { - cu[ j ] = 1.; - iu[ j ] = 1; - } -/* L50: */ - iphase = 1; - } - -/* Copy first row of cu and iu to second row */ - memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), - (size_t) nklm * sizeof(LDBLE) ); - memcpy( (void *) &(iu[cu_dim]), (void *) &(iu[0]), - (size_t) nklm * sizeof(int) ); - -/* L60: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L60\n"); -#endif - if (m != 0) { - for (j = nkl; j < nklm; ++j) { - cu[ cu_dim + j ] = 1.; - iu[ cu_dim + j ] = 1; - jmn = j - n; - if (q2[ jmn * q_dim + n1 ].ival < 0) { - iphase = 1; - } - } -/* L70: */ - } -/* L80: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L80\n"); -#endif - if (*kode != 0) { - for (j = 0; j < n; ++j) { - if ( x[j] < 0.) { -/* L90: */ - cu[ j ] = 1.; - iu[ j ] = 1; - } else if (x[j] > 0.) { - cu[ cu_dim + j ] = 1.; - iu[ cu_dim + j ] = 1; - } - } -/* L110: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L110\n"); -#endif - for (j = 0; j < k; ++j) { - jpn = j + n; - if ( res[j] < 0.) { -/* L120: */ - cu[ jpn ] = 1.; - iu[ jpn ] = 1; - if (q2[ j * q_dim + n1 ].ival > 0) { - iphase = 1; - } - } else if (res[j] > 0.) { -/* L130: */ - cu[ cu_dim + jpn ] = 1.; - iu[ cu_dim + jpn ] = 1; - if (q2[ j * q_dim + n1 ].ival < 0) { - iphase = 1; - } - } - } -/* L140: */ - } -/* L150: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L150\n"); -#endif - if (iphase == 2) { - goto L500; - } -/* COMPUTE THE MARGINAL COSTS. */ -L160: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L160\n"); -#endif - for (j = js; j < n1; ++j) { - sum = 0.; - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - if (ii < 0) { - z = cu[ cu_dim - ii - 1 ]; - } else { - z = cu[ ii - 1 ]; - } - sum += q2[ i * q_dim + j ].dval * z; - } - q2[ klm * q_dim + j ].dval = sum; - } - for (j = js; j < n; ++j) { - ii = q2[ klm1 * q_dim + j].ival; - if (ii < 0) { - z = cu[ cu_dim - ii - 1 ]; - } else { - z = cu[ ii - 1 ]; - } - q2[ klm * q_dim + j ].dval -= z; - } -/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ -L240: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L240, xmax %e\n", xmax); -#endif - xmax = 0.; - if (js >= n) { - goto L490; /* test for optimality */ - } - for (j = js; j < n; ++j) { - zu = q2[ klm * q_dim + j ].dval; - ii = q2[ klm1 * q_dim + j ].ival; - if (ii > 0) { - zv = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; - } else { - ii = -ii; - zv = zu; - zu = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; - } -/* L260 */ - if (kforce == 1 && ii > n) { - continue; - } - if (iu[ ii - 1 ] != 1 && zu > xmax){ - xmax = zu; - in = j; - } -/* L270 */ - if (iu[ cu_dim + ii - 1 ] != 1 && zv > xmax ) { - xmax = zv; - in = j; - } - } -/* L280 */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L280 xmax %e, toler %e\n", xmax, toler); -#endif - if (xmax <= toler) { -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "xmax before optimality test %e\n",xmax); -#endif - goto L490; /* test for optimality */ - } - if (q2[ klm * q_dim + in ].dval != xmax) { - for (i = 0; i < klm1; ++i) { - q2[ i * q_dim + in ].dval = -q2[ i * q_dim + in ].dval; - } - q2[ klm1 * q_dim + in ].ival = -q2[ klm1 * q_dim + in ].ival; -/* L290: */ - q2[ klm * q_dim + in ].dval = xmax; - } -/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ - if (iphase != 1 && ia != -1) { - xmax = 0.; -/* find maximum absolute value in column "in" */ - for (i = 0; i <= ia; ++i) { - z = fabs(q2[ i * q_dim + in ].dval); - if (z > xmax) { - xmax = z; - iout = i; - } - } -/* L310: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L310, xmax %e\n", xmax); -#endif -/* switch row ia with row iout, use memcpy */ - if (xmax > toler) { - memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ iout * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ iout * q_dim ]), (void *) &(scratch[ 0 ]), - (size_t) n2 * sizeof(LDBLE) ); -/* L320: */ -/* set pivot to row ia, column in */ - iout = ia; - --ia; - pivot = q2[ iout * q_dim + in ].dval; - goto L420; /* Gauss Jordan */ - } - } -/* L330: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L330, xmax %e\n", xmax); -#endif - kk = -1; -/* divide column n1 by positive value in column "in" greater than toler */ - for (i = 0; i < klm; ++i) { - z = q2[ i * q_dim + in ].dval; - if (z > toler) { - ++kk; - res[kk] = q2[ i * q_dim + n ].dval / z; - s[kk] = i; - } - } -/* L340: */ -#ifdef DEBUG_CL1 - if (kk < 0) { - output_msg(OUTPUT_MESSAGE, "kode = 2 in loop 340.\n"); - } -#endif -L350: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L350, xmax %e\n", xmax); -#endif - if (kk < 0) { -/* no positive value found in L340 or bypass intermediate verticies */ - *kode = 2; - goto L590; - } -/* L360: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L360, xmax %e\n", xmax); -#endif -/* find minimum residual */ - xmin = res[ 0 ]; - iout = s[ 0 ]; - j = 0; - if (kk != 0) { - for (i = 1; i <= kk; ++i) { - if (res[i] < xmin) { - j = i; - xmin = res[i]; - iout = s[i]; - } - } -/* L370: */ -/* put kk in position j */ - res[j] = res[kk]; - s[j] = s[kk]; - } -/* L380: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L380 iout %d, xmin %e, xmax %e\n", iout, xmin, xmax); -#endif - --kk; - pivot = q2[ iout * q_dim + in ].dval; - ii = q2[ iout * q_dim + n1 ].ival; - if (iphase != 1) { - if (ii < 0) { -/* L390: */ - if (iu[ - ii - 1 ] == 1) { - goto L420; - } - } else { - if (iu[ cu_dim + ii - 1 ] == 1) { - goto L420; - } - } - } -/* L400: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L400\n"); -#endif - ii = abs(ii); - cuv = cu[ ii - 1 ] + cu[ cu_dim + ii - 1]; - if (q2[ klm * q_dim + in ].dval - pivot * cuv > toler) { - -/* BYPASS INTERMEDIATE VERTICES. */ - for (j = js; j < n1; ++j) { - z = q2[ iout * q_dim + j ].dval; - q2[ klm * q_dim + j ].dval -= z * cuv; - q2[ iout * q_dim + j ].dval = -z; - } -/* L410: */ - q2[ iout * q_dim + n1 ].ival = -q2[ iout * q_dim + n1 ].ival; - goto L350; - } -/* GAUSS-JORDAN ELIMINATION. */ -L420: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Gauss Jordon %d\n", *iter); -#endif - if (*iter >= maxit) { - *kode = 3; - goto L590; - } -/* L430: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L430\n"); -#endif - ++(*iter); - for (j = js; j < n1; ++j) { - if (j != in) { - q2[ iout * q_dim + j ].dval /= pivot; - } - } -/* L440: */ - for (j = js; j < n1; ++j) { - if (j != in) { - z = -q2[ iout * q_dim + j ].dval; - for (i = 0; i < klm1; ++i) { - if (i != iout) { - q2[ i * q_dim + j ].dval += z * q2[ i * q_dim + in ].dval; - } - } -/* L450: */ - } - } -/* L460: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L460\n"); -#endif - tpivot = -pivot; - for (i = 0; i < klm1; ++i) { - if (i != iout) { - q2[ i * q_dim + in ].dval /= tpivot; - } - } -/* L470: */ - q2[ iout * q_dim + in ].dval = 1. / pivot; - ii = q2[ iout * q_dim + n1 ].ival; - q2[ iout * q_dim + n1 ].ival = q2[ klm1 * q_dim + in ].ival; - q2[ klm1 * q_dim + in ].ival = ii; - ii = abs(ii); - if (iu[ ii - 1 ] == 0 || iu[ cu_dim + ii - 1 ] == 0) { - goto L240; - } -/* switch column */ - for (i = 0; i < klm1; ++i) { - z = q2[ i * q_dim + in ].dval; - q2[ i * q_dim + in ].dval = q2[ i * q_dim + js ].dval; - q2[ i * q_dim + js ].dval = z; - } - i = q2[ klm1 * q_dim + in ].ival; - q2[ klm1 * q_dim + in ].ival = q2[ klm1 * q_dim + js ].ival; - q2[ klm1 * q_dim + js ].ival = i; -/* L480: */ - ++js; - goto L240; -/* TEST FOR OPTIMALITY. */ -L490: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L490\n"); -#endif - if (kforce == 0) { - if (iphase == 1) { - if (q2[ klm * q_dim + n ].dval <= toler) { - goto L500; - } -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE,"q2[klm1-1, n1-1] > *toler. %e\n",q2[ ( klm1 - 1 ) * q_dim + n1 - 1 ].dval); -#endif - *kode = 1; - goto L590; - } - *kode = 0; - goto L590; - } - if (iphase != 1 || q2[ klm * q_dim + n ].dval > toler) { - kforce = 0; - goto L240; - } -/* SET UP PHASE 2 COSTS. */ -L500: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Set up phase 2 costs %d\n", *iter); -#endif - iphase = 2; - for (j = 0; j < nklm; ++j) { - cu[ j ] = 0.; - } -/* L510: */ - for (j = n; j < nk; ++j) { - cu[ j ] = 1.; - } - memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), - (size_t) nklm * sizeof(LDBLE) ); -/* L520: */ - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - if (ii <= 0) { - if (iu[ cu_dim - ii - 1 ] == 0) { - continue; - } - cu[ cu_dim - ii - 1 ] = 0.; - } else { -/* L530: */ - if (iu[ ii - 1 ] == 0) { - continue; - } - cu[ ii - 1 ] = 0.; - } -/* L540: */ - ++ia; -/* switch row */ - memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ i * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ i * q_dim ]), (void *) &(scratch[ 0 ]), - (size_t) n2 * sizeof(LDBLE) ); -/* L550: */ - } -/* L560: */ - goto L160; - - -/* PREPARE OUTPUT. */ -L590: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L590\n"); -#endif - sum = 0.; - for (j = 0; j < n; ++j) { - x[j] = 0.; - } -/* L600: */ - for (i = 0; i < klm; ++i) { - res[i] = 0.; - } -/* L610: */ - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - sn = 1.; - if (ii < 0) { - ii = -ii; - sn = -1.; - } - if (ii <= n) { -/* L620: */ - x[ii - 1] = sn * q2[ i * q_dim + n ].dval; - } else { -/* L630: */ - res[ii - n - 1] = sn * q2[ i * q_dim + n ].dval; - if (ii >= n1 && ii <= nk ) { -/* * DBLE(Q(I,N1)) */ - sum += q2[ i * q_dim + n ].dval; - } - } - } -/* L640: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L640\n"); -#endif - *error = sum; - scratch = (double *) free_check_null (scratch); - /* - * Check calculation - */ - if ((check == 1) && (*kode == 0)) { - check_toler = 10.*toler; - /* - * Check optimization constraints - */ - if (kode_arg == 1) { - for (i = 0; i < k; i++) { - if (res_arg[i] < 0.0) { - if (res[i] > check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: optimization constraint not satisfied row %d, res %s, constraint %f.\n", row_name[row_back[i]], res[i], res_arg[i]); -#endif - *kode = 1; - } - } else if (res_arg[i] > 0.0) { - if (res[i] < -check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: optimization constraint not satisfied row %s, res %e, constraint %f.\n", row_name[row_back[i]], res[i], res_arg[i]); -#endif - *kode = 1; - } - } - } - } - /* - * Check equalities - */ - for (i = k; i < k + l; i++) { - if (fabs(res[i]) > check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: equality constraint not satisfied row %s, res %e, tolerance %e.\n", row_name[row_back[i]], res[i], check_toler); -#endif - *kode = 1; - } - } - /* - * Check inequalities - */ - for (i = k + l; i < k + l + m; i++) { - if (res[i] < -check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: inequality constraint not satisfied row %s, res %e, tolerance %e.\n", row_name[row_back[i]], res[i], check_toler); -#endif - *kode = 1; - } - } - /* - * Check dissolution/precipitation constraints - */ - if (kode_arg == 1) { - for (i = 0; i < n; i++) { - if (x_arg[i] < 0.0) { - if (x[i] > check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", col_name[col_back[i]], x[i], x_arg[i]); -#endif - *kode = 1; - } - } else if (x_arg[i] > 0.0) { - if (x[i] < -check_toler) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", col_name[col_back[i]], x[i], x_arg[i]); -#endif - *kode = 1; - } - } - } - } - if (*kode == 1) { - output_msg(OUTPUT_MESSAGE, "\n\tCL1: Roundoff errors in optimization.\n\t Try using -multiple_precision in INVERSE_MODELING\n"); - } - } - if (check == 1) { - x_arg = (double *) free_check_null(x_arg); - res_arg = (double *) free_check_null(res_arg); - } - return 0; -} diff --git a/cl1mp.cpp b/cl1mp.cpp deleted file mode 100644 index ca15c0bb..00000000 --- a/cl1mp.cpp +++ /dev/null @@ -1,974 +0,0 @@ -#include -#include -#include -#include -#include - -/* must be defined here and in global.h */ -#if !defined(WIN32_MEMORY_DEBUG) -#define USE_PHRQ_ALLOC -#endif -#include "phqalloc.h" -#include "output.h" -#include "phrqtype.h" - -extern int max_row_count, max_column_count; -static char const svnid[] = "$Id: cl1mp.c 78 2005-02-01 22:47:12Z dlpark $"; - -int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error, - LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg); -extern void *free_check_null(void *ptr); -extern void malloc_error(void); - -/* debug -#define DEBUG_CL1 -#define CHECK_ERRORS - */ - - -int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q_arg, - int *kode_arg, LDBLE toler_arg, - int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error_arg, - LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg) -{ - /* System generated locals */ - union double_or_int {int ival; mpf_t dval;} *q2; - - /* Local variables */ - static int nklm; - static int iout, i, j; - static int maxit, n1, n2; - static int ia, ii, kk, in, nk, js; - static int iphase, kforce; - static int klm, jmn, nkl, jpn; - static int klm1; - static int *kode; - int q_dim, cu_dim; - int iswitch; - mpf_t *q; - mpf_t *x; - mpf_t *res; - mpf_t error; - mpf_t *cu; - mpf_t dummy, dummy1, sum, z, zu, zv, xmax, minus_one, toler, check_toler; - /*mpf_t *scratch;*/ - mpf_t pivot, xmin, cuv, tpivot, sn; - mpf_t zero; - int censor; - mpf_t censor_tol; -/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ -/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ -/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ -/* AX=B */ -/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ -/* CX=D */ -/* AND M LINEAR INEQUALITY CONSTRAINTS */ -/* EX.LE.F. */ -/* DESCRIPTION OF PARAMETERS */ -/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ -/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ -/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ -/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ -/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ -/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ -/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ -/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ -/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ -/* AT LEAST N2D COLUMNS. */ -/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ -/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ -/* AND N+1 COLUMNS OF Q AS FOLLOWS */ -/* A B */ -/* Q = C D */ -/* E F */ -/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ -/* KODE A CODE USED ON ENTRY TO, AND EXIT */ -/* FROM, THE SUBROUTINE. */ -/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ -/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ -/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ -/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ -/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ -/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ -/* RES (SEE BELOW). */ -/* ON EXIT, KODE HAS ONE OF THE */ -/* FOLLOWING VALUES */ -/* 0- OPTIMAL SOLUTION FOUND, */ -/* 1- NO FEASIBLE SOLUTION TO THE */ -/* CONSTRAINTS, */ -/* 2- CALCULATIONS TERMINATED */ -/* PREMATURELY DUE TO ROUNDING ERRORS, */ -/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ -/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ -/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ -/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ -/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ -/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ -/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ -/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ -/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ -/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ -/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ -/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ -/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ -/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ -/* ON EXIT THIS ARRAY CONTAINS A */ -/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ -/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ -/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ -/* VARIABLES. THE VALUES -1, 0, OR 1 */ -/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ -/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ -/* OR .GE.0 RESPECTIVELY. */ -/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ -/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ -/* IN THE FIRST K COMPONENTS, D-CX IN THE */ -/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ -/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ -/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ -/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ -/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ -/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ -/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ -/* RESPECTIVELY. */ -/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ -/* ABSOLUTE VALUES OF THE RESIDUALS. */ -/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ -/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ -/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ -/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ -/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ -/* WORKSPACE. */ -/* DOUBLE PRECISION DBLE */ -/* REAL */ - -/* INITIALIZATION. */ - if (svnid == NULL) fprintf(stderr," "); - /* - * mp variables - */ - censor = 1; - if (censor_arg == 0.0) censor = 0; - mpf_set_default_prec(96); - mpf_init(zero); - mpf_init(dummy); - mpf_init(dummy1); - mpf_init_set_d(censor_tol, censor_arg); - q = (mpf_t *) PHRQ_malloc((size_t) (max_row_count * max_column_count * sizeof(mpf_t))); - if (q == NULL) malloc_error(); - for (i = 0; i < max_row_count*max_column_count; i++) { - mpf_init_set_d(q[i], q_arg[i]); - if (censor == 1) { - if (mpf_cmp(q[ i ], zero) != 0) { - mpf_abs(dummy1, q[ i ]); - if (mpf_cmp(dummy1, censor_tol) <= 0) { - mpf_set_si(q[ i ], 0); - } - } - } - } - x = (mpf_t *) PHRQ_malloc((size_t) (n2d * sizeof(mpf_t))); - if (x == NULL) malloc_error(); - for (i = 0; i < n2d; i++) { - mpf_init_set_d (x[i], x_arg[i]); - } - res = (mpf_t *) PHRQ_malloc((size_t) ((k + l + m) * sizeof(mpf_t))); - if (res == NULL) malloc_error(); - for (i = 0; i < k + l + m; i++) { - mpf_init_set_d (res[i], res_arg[i]); - } - cu = (mpf_t *) PHRQ_malloc((size_t) (2*nklmd * sizeof(mpf_t))); - if (cu == NULL) malloc_error(); - for (i = 0; i < 2*nklmd; i++) { - mpf_init_set_d (cu[i], cu_arg[i]); - } - kode = (int *) PHRQ_malloc(sizeof(int)); - if (kode == NULL) malloc_error(); - *kode = *kode_arg; - mpf_init(sum); - mpf_init(error); - mpf_init(z); - mpf_init(zu); - mpf_init(zv); - mpf_init(xmax); - mpf_init_set_si(minus_one, -1); - mpf_init_set_d(toler, toler_arg); - mpf_init_set_d(check_toler, toler_arg); - mpf_init(pivot); - mpf_init(xmin); - mpf_init(cuv); - mpf_init(tpivot); - mpf_init(sn); -/* Parameter adjustments */ - q_dim = n2d; - q2 = (union double_or_int *) q; - cu_dim = nklmd; - -/* Function Body */ - maxit = *iter; - n1 = n + 1; - n2 = n + 2; - nk = n + k; - nkl = nk + l; - klm = k + l + m; - klm1 = klm + 1; - nklm = n + klm; - kforce = 1; - *iter = 0; - js = 0; - ia = -1; -/* Make scratch space */ -/* - scratch = (LDBLE *) PHRQ_malloc( (size_t) nklmd * sizeof(LDBLE)); - if (scratch == NULL) malloc_error(); - for (i=0; i < nklmd; i++) { - scratch[i] = 0.0; - } -*/ -/* - scratch = (mpf_t *) PHRQ_malloc( (size_t) nklmd * sizeof(mpf_t)); - if (scratch == NULL) malloc_error(); - for (i=0; i < nklmd; i++) { - mpf_init(scratch[i]); - } -*/ -/* SET UP LABELS IN Q. */ - for (j = 0; j < n; ++j) { - q2[ klm1 * q_dim + j ].ival = j + 1; - } -/* L10: */ - for (i = 0; i < klm; ++i) { - q2[ i * q_dim + n1 ].ival = n + i + 1; - if (mpf_cmp_d(q2[ i * q_dim + n ].dval, 0.0) < 0) { - for (j = 0; j < n1; ++j) { - /* q2[ i * q_dim + j ].dval = -q2[ i * q_dim + j ].dval; */ - mpf_neg(q2[ i * q_dim + j ].dval, q2[ i * q_dim + j ].dval); - } - q2[ i * q_dim + n1 ].ival = -q2[ i * q_dim + n1 ].ival; -/* L20: */ - } - } -/* L30: */ -/* SET UP PHASE 1 COSTS. */ - iphase = 2; -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Set up phase 1 costs\n"); -#endif -/* Zero first row of cu and iu */ - /*memcpy( (void *) &(cu[0]), (void *) &(scratch[0]), (size_t) nklm * sizeof(mpf_t) );*/ - for (j = 0; j < nklm; ++j) { - mpf_set_si(cu[j], 0); - iu[ j ] = 0; - } -/* L40: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L40\n"); -#endif - if (l != 0) { - for (j = nk; j < nkl; ++j) { - mpf_set_si(cu[j], 1); - /*cu[ j ] = 1.;*/ - iu[ j ] = 1; - } -/* L50: */ - iphase = 1; - } - -/* Copy first row of cu and iu to second row */ - /*memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(mpf_t) );*/ - for (i = 0; i < nklm; i++) { - mpf_set(cu[cu_dim + i], cu[i]); - } - memcpy( (void *) &(iu[cu_dim]), (void *) &(iu[0]), (size_t) nklm * sizeof(int) ); -/* L60: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L60\n"); -#endif - if (m != 0) { - for (j = nkl; j < nklm; ++j) { - /* cu[ cu_dim + j ] = 1.;*/ - mpf_set_si(cu[cu_dim + j], 1); - iu[ cu_dim + j ] = 1; - jmn = j - n; - if (q2[ jmn * q_dim + n1 ].ival < 0) { - iphase = 1; - } - } -/* L70: */ - } -/* L80: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L80\n"); -#endif - if (*kode != 0) { - for (j = 0; j < n; ++j) { - /* if ( x[j] < 0.) { */ - if (mpf_cmp_si(x[j], 0) < 0) { -/* L90: */ - /* cu[ j ] = 1.;*/ - mpf_set_si(cu[j], 1); - iu[ j ] = 1; - /* } else if (x[j] > 0.) {*/ - } else if (mpf_cmp_si(x[j], 0) > 0) { - /* cu[ cu_dim + j ] = 1.; */ - mpf_set_si(cu[cu_dim + j], 1); - iu[ cu_dim + j ] = 1; - } - } -/* L110: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L110\n"); -#endif - for (j = 0; j < k; ++j) { - jpn = j + n; - /* if (res[j] < 0.) { */ - if (mpf_cmp_si(res[j], 0) < 0) { -/* L120: */ - /* cu[ jpn ] = 1.;*/ - mpf_set_si(cu[jpn], 1); - iu[ jpn ] = 1; - if (q2[ j * q_dim + n1 ].ival > 0) { - iphase = 1; - } - /* } else if (res[j] > 0.) { */ - } else if (mpf_cmp_si(res[j], 0) > 0) { -/* L130: */ - /* cu[ cu_dim + jpn ] = 1.;*/ - mpf_set_si(cu[cu_dim + jpn], 1); - iu[ cu_dim + jpn ] = 1; - if (q2[ j * q_dim + n1 ].ival < 0) { - iphase = 1; - } - } - } -/* L140: */ - } -/* L150: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L150\n"); -#endif - if (iphase == 2) { - goto L500; - } -/* COMPUTE THE MARGINAL COSTS. */ -L160: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L160\n"); -#endif - for (j = js; j < n1; ++j) { - mpf_set_si(sum, 0); - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - if (ii < 0) { - /* z = cu[ cu_dim - ii - 1 ];*/ - mpf_set(z, cu[ cu_dim - ii - 1 ]); - } else { - /*z = cu[ ii - 1 ];*/ - mpf_set(z, cu[ ii - 1 ]); - } - /*sum += q2[ i * q_dim + j ].dval * z;*/ - mpf_mul(dummy, q2[ i * q_dim + j ].dval, z); - mpf_add(sum, sum, dummy); - } - /*q2[ klm * q_dim + j ].dval = sum;*/ - mpf_set(q2[ klm * q_dim + j ].dval, sum); - } - for (j = js; j < n; ++j) { - ii = q2[ klm1 * q_dim + j].ival; - if (ii < 0) { - /*z = cu[ cu_dim - ii - 1 ];*/ - mpf_set(z, cu[ cu_dim - ii - 1 ]); - } else { - /*z = cu[ ii - 1 ];*/ - mpf_set(z, cu[ ii - 1 ]); - } - /*q2[ klm * q_dim + j ].dval -= z;*/ - mpf_sub(q2[ klm * q_dim + j ].dval, q2[ klm * q_dim + j ].dval, z); - } -/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ -L240: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L240, xmax %e\n", mpf_get_d(xmax)); -#endif - /*xmax = 0.;*/ - mpf_set_si(xmax, 0); - if (js >= n) { - goto L490; /* test for optimality */ - } - for (j = js; j < n; ++j) { - /*zu = q2[ klm * q_dim + j ].dval;*/ - mpf_set(zu, q2[ klm * q_dim + j ].dval); - ii = q2[ klm1 * q_dim + j ].ival; - if (ii > 0) { - /*zv = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ];*/ - mpf_mul(dummy, cu[ cu_dim + ii - 1 ], minus_one); - mpf_sub(dummy, dummy, cu[ ii - 1 ]); - mpf_sub(zv, dummy, zu); - } else { - ii = -ii; - /* zv = zu; */ - mpf_set(zv, zu); - /* zu = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; */ - mpf_mul(dummy, cu[ cu_dim + ii - 1 ], minus_one); - mpf_sub(dummy, dummy, cu[ ii - 1 ]); - mpf_sub(zu, dummy, zu); - } -/* L260 */ - if (kforce == 1 && ii > n) { - continue; - } - /*if (iu[ ii - 1 ] != 1 && zu > xmax){*/ - if ((iu[ ii - 1 ] != 1) && (mpf_cmp(zu, xmax) > 0)) { - /*xmax = zu;*/ - mpf_set(xmax, zu); - in = j; - } -/* L270 */ - /*if (iu[ cu_dim + ii - 1 ] != 1 && zv > xmax ) {*/ - if ((iu[ cu_dim + ii - 1 ] != 1) && (mpf_cmp(zv, xmax) > 0)) { - /*xmax = zv;*/ - mpf_set(xmax, zv); - in = j; - } - } -/* L280 */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L280 xmax %e, toler %e\n", mpf_get_d(xmax), mpf_get_d(toler)); -#endif - /*if (xmax <= toler) {*/ - if (mpf_cmp(xmax, toler) <= 0) { -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "xmax before optimality test %e\n", mpf_get_d(xmax)); -#endif - goto L490; /* test for optimality */ - } - /*if (q2[ klm * q_dim + in ].dval != xmax) {*/ - if (mpf_cmp(q2[ klm * q_dim + in ].dval,xmax) != 0) { - for (i = 0; i < klm1; ++i) { - /*q2[ i * q_dim + in ].dval = -q2[ i * q_dim + in ].dval;*/ - mpf_neg(q2[ i * q_dim + in ].dval, q2[ i * q_dim + in ].dval); - } - q2[ klm1 * q_dim + in ].ival = -q2[ klm1 * q_dim + in ].ival; -/* L290: */ - /*q2[ klm * q_dim + in ].dval = xmax;*/ - mpf_set(q2[ klm * q_dim + in ].dval, xmax); - } -/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ - if (iphase != 1 && ia != -1) { - /*xmax = 0.;*/ - mpf_set_si(xmax, 0); -/* find maximum absolute value in column "in" */ - for (i = 0; i <= ia; ++i) { - /*z = fabs(q2[ i * q_dim + in ].dval);*/ - mpf_abs(z, q2[ i * q_dim + in ].dval); - /*if (z > xmax) {*/ - if (mpf_cmp(z, xmax) > 0) { - /*xmax = z;*/ - mpf_set(xmax, z); - iout = i; - } - } -/* L310: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L310, xmax %e\n", mpf_get_d(xmax)); -#endif -/* switch row ia with row iout, use memcpy */ - /*if (xmax > toler) {*/ - if (mpf_cmp(xmax, toler) > 0) { - /* - memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), - (size_t) n2 * sizeof(mpf_t) ); - memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ iout * q_dim]), - (size_t) n2 * sizeof(mpf_t) ); - memcpy( (void *) &(q2[ iout * q_dim ]), (void *) &(scratch[ 0 ]), - (size_t) n2 * sizeof(mpf_t) ); - */ - for (i = 0; i < n1; i++) { - mpf_set(dummy, q2[ ia * q_dim + i].dval); - mpf_set(q2[ ia * q_dim + i].dval, q2[ iout * q_dim + i].dval); - mpf_set(q2[ iout * q_dim + i].dval, dummy); - } - j = q2[ ia * q_dim + n1].ival; - q2[ ia * q_dim + n1].ival = q2[ iout * q_dim + n1].ival; - q2[ iout * q_dim + n1].ival = j; - -/* L320: */ -/* set pivot to row ia, column in */ - iout = ia; - --ia; - /*pivot = q2[ iout * q_dim + in ].dval;*/ - mpf_set(pivot, q2[ iout * q_dim + in ].dval); - goto L420; /* Gauss Jordan */ - } - } -/* L330: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L330, xmax %e\n", mpf_get_d(xmax)); -#endif - kk = -1; -/* divide column n1 by positive value in column "in" greater than toler */ - for (i = 0; i < klm; ++i) { - /*z = q2[ i * q_dim + in ].dval;*/ - mpf_set(z, q2[ i * q_dim + in ].dval); - /*if (z > toler) {*/ - if (mpf_cmp(z, toler) > 0) { - ++kk; - /*res[kk] = q2[ i * q_dim + n ].dval / z;*/ - mpf_div(res[kk], q2[ i * q_dim + n ].dval, z); - s[kk] = i; - } - } -/* L340: */ - if (kk < 0) { - output_msg(OUTPUT_MESSAGE, "kode = 2 in loop 340.\n"); - } -L350: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L350, xmax %e\n", mpf_get_d(xmax)); -#endif - if (kk < 0) { -/* no positive value found in L340 or bypass intermediate verticies */ - *kode = 2; - goto L590; - } -/* L360: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L360, xmax %e\n", mpf_get_d(xmax)); -#endif -/* find minimum residual */ - /*xmin = res[ 0 ];*/ - mpf_set(xmin, res[0]); - iout = s[ 0 ]; - j = 0; - if (kk != 0) { - for (i = 1; i <= kk; ++i) { - /*if (res[i] < xmin) {*/ - if (mpf_cmp(res[i], xmin) < 0) { - j = i; - /*xmin = res[i];*/ - mpf_set(xmin, res[i]); - iout = s[i]; - } - } -/* L370: */ -/* put kk in position j */ - /*res[j] = res[kk];*/ - mpf_set(res[j], res[kk]); - s[j] = s[kk]; - } -/* L380: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L380 iout %d, xmin %e, xmax %e\n", iout, mpf_get_d(xmin), mpf_get_d(xmax)); -#endif - --kk; - /*pivot = q2[ iout * q_dim + in ].dval;*/ - mpf_set(pivot, q2[ iout * q_dim + in ].dval); - ii = q2[ iout * q_dim + n1 ].ival; - if (iphase != 1) { - if (ii < 0) { -/* L390: */ - if (iu[ - ii - 1 ] == 1) { - goto L420; - } - } else { - if (iu[ cu_dim + ii - 1 ] == 1) { - goto L420; - } - } - } -/* L400: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L400\n"); -#endif - ii = abs(ii); - /*cuv = cu[ ii - 1 ] + cu[ cu_dim + ii - 1];*/ - mpf_add(cuv, cu[ ii - 1 ], cu[ cu_dim + ii - 1]); - /*if (q2[ klm * q_dim + in ].dval - pivot * cuv > toler) {*/ - mpf_mul(dummy, pivot, cuv); - mpf_sub(dummy, q2[ klm * q_dim + in ].dval, dummy); - if (mpf_cmp(dummy, toler) > 0) { -/* BYPASS INTERMEDIATE VERTICES. */ - for (j = js; j < n1; ++j) { - /*z = q2[ iout * q_dim + j ].dval;*/ - mpf_set(z, q2[ iout * q_dim + j ].dval); - /*q2[ klm * q_dim + j ].dval -= z * cuv;*/ - mpf_mul(dummy1, z, cuv); - mpf_sub(q2[ klm * q_dim + j ].dval, q2[ klm * q_dim + j ].dval, dummy1); - - if (censor == 1) { - if (mpf_cmp(q2[ klm * q_dim + j ].dval, zero) != 0) { - mpf_abs(dummy1, q2[ klm * q_dim + j ].dval); - if (mpf_cmp(dummy1, censor_tol) <= 0) { - mpf_set_si(q2[ klm * q_dim + j ].dval, 0); - } - } - } - - /*q2[ iout * q_dim + j ].dval = -z;*/ - mpf_neg(q2[ iout * q_dim + j ].dval, z); - } -/* L410: */ - q2[ iout * q_dim + n1 ].ival = -q2[ iout * q_dim + n1 ].ival; - goto L350; - } -/* GAUSS-JORDAN ELIMINATION. */ -L420: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Gauss Jordon %d\n", *iter); -#endif - if (*iter >= maxit) { - *kode = 3; - goto L590; - } -/* L430: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L430\n"); -#endif - ++(*iter); - for (j = js; j < n1; ++j) { - if (j != in) { - /*q2[ iout * q_dim + j ].dval /= pivot;*/ - mpf_div(q2[ iout * q_dim + j ].dval, q2[ iout * q_dim + j ].dval, pivot); - } - } -/* L440: */ - for (j = js; j < n1; ++j) { - if (j != in) { - /*z = -q2[ iout * q_dim + j ].dval;*/ - mpf_neg(z, q2[ iout * q_dim + j ].dval); - for (i = 0; i < klm1; ++i) { - if (i != iout) { - /*q2[ i * q_dim + j ].dval += z * q2[ i * q_dim + in ].dval;*/ - mpf_mul(dummy, z, q2[ i * q_dim + in ].dval); - mpf_add(q2[ i * q_dim + j ].dval, q2[ i * q_dim + j ].dval, dummy); - - if (censor == 1) { - if (mpf_cmp(q2[ i * q_dim + j ].dval, zero) != 0) { - mpf_abs(dummy1, q2[ i * q_dim + j ].dval); - if (mpf_cmp(dummy1, censor_tol) <= 0) { - mpf_set_si(q2[ i * q_dim + j ].dval, 0); - } - } - } - } - } -/* L450: */ - } - } -/* L460: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L460\n"); -#endif - /*tpivot = -pivot;*/ - mpf_neg(tpivot, pivot); - for (i = 0; i < klm1; ++i) { - if (i != iout) { - /*q2[ i * q_dim + in ].dval /= tpivot;*/ - mpf_div(q2[ i * q_dim + in ].dval, q2[ i * q_dim + in ].dval, tpivot); - } - } -/* L470: */ - /*q2[ iout * q_dim + in ].dval = 1. / pivot;*/ - mpf_set_si(dummy, 1); - mpf_div(q2[ iout * q_dim + in ].dval, dummy, pivot); - ii = q2[ iout * q_dim + n1 ].ival; - q2[ iout * q_dim + n1 ].ival = q2[ klm1 * q_dim + in ].ival; - q2[ klm1 * q_dim + in ].ival = ii; - ii = abs(ii); - if (iu[ ii - 1 ] == 0 || iu[ cu_dim + ii - 1 ] == 0) { - goto L240; - } -/* switch column */ - for (i = 0; i < klm1; ++i) { - /*z = q2[ i * q_dim + in ].dval;*/ - mpf_set(z, q2[ i * q_dim + in ].dval); - /*q2[ i * q_dim + in ].dval = q2[ i * q_dim + js ].dval;*/ - mpf_set(q2[ i * q_dim + in ].dval, q2[ i * q_dim + js ].dval); - /*q2[ i * q_dim + js ].dval = z;*/ - mpf_set(q2[ i * q_dim + js ].dval, z); - } - i = q2[ klm1 * q_dim + in ].ival; - q2[ klm1 * q_dim + in ].ival = q2[ klm1 * q_dim + js ].ival; - q2[ klm1 * q_dim + js ].ival = i; -/* L480: */ - ++js; - goto L240; -/* TEST FOR OPTIMALITY. */ -L490: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L490\n"); -#endif - if (kforce == 0) { - if (iphase == 1) { - /*if (q2[ klm * q_dim + n ].dval <= toler) {*/ - if (mpf_cmp(q2[ klm * q_dim + n ].dval, toler) <= 0) { - goto L500; - } -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE,"q2[klm1-1, n1-1] > *toler. %e\n", mpf_get_d(q2[ ( klm1 - 1 ) * q_dim + n1 - 1 ].dval)); -#endif - *kode = 1; - goto L590; - } - *kode = 0; - goto L590; - } - /*if (iphase != 1 || q2[ klm * q_dim + n ].dval > toler) {*/ - if ((iphase != 1) || (mpf_cmp(q2[ klm * q_dim + n ].dval, toler) > 0)) { - kforce = 0; - goto L240; - } -/* SET UP PHASE 2 COSTS. */ -L500: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "Set up phase 2 costs %d\n", *iter); -#endif - iphase = 2; - for (j = 0; j < nklm; ++j) { - /*cu[ j ] = 0.;*/ - mpf_set_si(cu[j], 0); - } -/* L510: */ - for (j = n; j < nk; ++j) { - /*cu[ j ] = 1.;*/ - mpf_set_si(cu[j], 1); - } - /* - memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(LDBLE) ); - */ - for (i = 0; i < nklm; i++) { - mpf_set(cu[cu_dim + i], cu[i]); - } - -/* L520: */ - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - if (ii <= 0) { - if (iu[ cu_dim - ii - 1 ] == 0) { - continue; - } - /*cu[ cu_dim - ii - 1 ] = 0.;*/ - mpf_set_si(cu[ cu_dim - ii - 1 ], 0); - } else { -/* L530: */ - if (iu[ ii - 1 ] == 0) { - continue; - } - /*cu[ ii - 1 ] = 0.;*/ - mpf_set_si(cu[ ii - 1 ], 0); - } -/* L540: */ - ++ia; -/* switch row */ - /* - memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ i * q_dim]), - (size_t) n2 * sizeof(LDBLE) ); - memcpy( (void *) &(q2[ i * q_dim ]), (void *) &(scratch[ 0 ]), - (size_t) n2 * sizeof(LDBLE) ); - */ - for (iswitch = 0; iswitch < n1; iswitch++) { - mpf_set(dummy, q2[ ia * q_dim + iswitch].dval); - mpf_set(q2[ ia * q_dim + iswitch].dval, q2[ i * q_dim + iswitch].dval); - mpf_set(q2[ i * q_dim + iswitch].dval, dummy); - } - iswitch = q2[ ia * q_dim + n1].ival; - q2[ ia * q_dim + n1].ival = q2[ i * q_dim + n1].ival; - q2[ i * q_dim + n1].ival = iswitch; -/* L550: */ - } -/* L560: */ - goto L160; - - -/* PREPARE OUTPUT. */ -L590: -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L590\n"); -#endif - /*sum = 0.;*/ - mpf_set_si(sum, 0); - for (j = 0; j < n; ++j) { - /*x[j] = 0.;*/ - mpf_set_si(x[j], 0); - } -/* L600: */ - for (i = 0; i < klm; ++i) { - /*res[i] = 0.;*/ - mpf_set_si(res[i], 0); - } -/* L610: */ - for (i = 0; i < klm; ++i) { - ii = q2[ i * q_dim + n1 ].ival; - /*sn = 1.;*/ - mpf_set_si(sn, 1); - if (ii < 0) { - ii = -ii; - /*sn = -1.;*/ - mpf_set_si(sn, -1); - } - if (ii <= n) { -/* L620: */ - /*x[ii - 1] = sn * q2[ i * q_dim + n ].dval;*/ - mpf_mul(x[ii - 1], sn, q2[ i * q_dim + n ].dval); - } else { -/* L630: */ - /*res[ii - n - 1] = sn * q2[ i * q_dim + n ].dval;*/ - mpf_mul(res[ii - n - 1], sn, q2[ i * q_dim + n ].dval); - if (ii >= n1 && ii <= nk ) { -/* * DBLE(Q(I,N1)) */ - /*sum += q2[ i * q_dim + n ].dval;*/ - mpf_add(sum, sum, q2[ i * q_dim + n ].dval); - } - } - } -/* L640: */ -#ifdef DEBUG_CL1 - output_msg(OUTPUT_MESSAGE, "L640\n"); -#endif - /* - * Check calculation - */ - mpf_set_si(dummy, 100); - mpf_mul(check_toler, toler, dummy); - if (check && *kode == 0) { - /* - * Check optimization constraints - */ - if (*kode_arg == 1) { - for (i = 0; i < k; i++) { - if (res_arg[i] < 0.0) { - mpf_sub(dummy, res[i], check_toler); - mpf_set_si(dummy1, 0); - if (mpf_cmp(dummy,dummy1) > 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", i, mpf_get_d(res[i]), res_arg[i]); -#endif - *kode = 1; - } - } else if (res_arg[i] > 0.0) { - mpf_add(dummy, res[i], check_toler); - mpf_set_si(dummy1, 0); - if (mpf_cmp(dummy,dummy1) < 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", i, mpf_get_d(res[i]), res_arg[i]); -#endif - *kode = 1; - } - } - } - } - /* - * Check equalities - */ - for (i = k; i < k + l; i++) { - mpf_abs(dummy, res[i]); - if (mpf_cmp(dummy, check_toler) > 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: equality constraint not satisfied row %d, res %e, tolerance %e.\n", i, mpf_get_d(res[i]), mpf_get_d(check_toler)); -#endif - - *kode = 1; - } - } - /* - * Check inequalities - */ - for (i = k + l; i < k + l + m; i++) { - mpf_neg(dummy, check_toler); - if (mpf_cmp(res[i], dummy) < 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: inequality constraint not satisfied row %d, res %e, tolerance %e.\n", i, mpf_get_d(res[i]), mpf_get_d(check_toler)); -#endif - *kode = 1; - } - } - /* - * Check dissolution/precipitation constraints - */ - if (*kode_arg == 1) { - for (i = 0; i < n; i++) { - if (x_arg[i] < 0.0) { - mpf_sub(dummy, x[i], check_toler); - mpf_set_si(dummy1, 0); - if (mpf_cmp(dummy,dummy1) > 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", i, mpf_get_d(x[i]), x_arg[i]); -#endif - *kode = 1; - } - } else if (x_arg[i] > 0.0) { - mpf_add(dummy, x[i], check_toler); - mpf_set_si(dummy1, 0); - if (mpf_cmp(dummy,dummy1) < 0) { -#ifdef CHECK_ERRORS - output_msg(OUTPUT_MESSAGE, "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", i, mpf_get_d(x[i]), x_arg[i]); -#endif - *kode = 1; - } - } - } - } - if (*kode == 1) { - output_msg(OUTPUT_MESSAGE, "\n\tCL1MP: Roundoff errors in optimization.\n\t Deleting model.\n"); - } - } - /* - * set return variables - */ - /**error = sum;*/ - mpf_set(error, sum); - *error_arg = mpf_get_d(error); - *kode_arg = *kode; - for (i = 0; i < n2d; i++) { - x_arg[i] = mpf_get_d (x[i]); - } - for (i = 0; i < k + l + m; i++) { - res_arg[i] = mpf_get_d (res[i]); - } - - /*scratch = free_check_null (scratch);*/ - - for (i = 0; i < max_row_count*max_column_count; i++) { - mpf_clear(q[i]); - } - q = (mpf_t *) free_check_null(q); - for (i = 0; i < n2d; i++) { - mpf_clear (x[i]); - } - x = (mpf_t *) free_check_null(x); - for (i = 0; i < k + l + m; i++) { - mpf_clear (res[i]); - } - res = (mpf_t *) free_check_null(res); - for (i = 0; i < 2*nklmd; i++) { - mpf_clear (cu[i]); - } - cu = (mpf_t *) free_check_null(cu); - mpf_clear(dummy); - mpf_clear(dummy1); - mpf_clear(sum); - mpf_clear(error); - mpf_clear(z); - mpf_clear(zu); - mpf_clear(zv); - mpf_clear(xmax); - mpf_clear(minus_one); - mpf_clear(toler); - mpf_clear(check_toler); - mpf_clear(pivot); - mpf_clear(xmin); - mpf_clear(cuv); - mpf_clear(tpivot); - mpf_clear(sn); - mpf_clear(censor_tol); - kode = (int *) free_check_null(kode); - return 0; -} diff --git a/cvdense.cpp b/cvdense.cpp deleted file mode 100644 index 62538545..00000000 --- a/cvdense.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/******************************************************************* - * * - * File : cvdense.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for the CVODE dense linear * - * solver, CVDENSE. * - * * - *******************************************************************/ - - -#include -#include -#include -#include "cvdense.h" -#include "cvode.h" -#include "dense.h" -#include "sundialstypes.h" -#include "nvector.h" -#include "sundialsmath.h" -#include "output.h" -#include "phqalloc.h" -/* WARNING don't include any headers below here */ -#define malloc PHRQ_malloc - -static char const svnid[] = "$Id: cvdense.c 78 2005-02-01 22:47:12Z dlpark $"; - -/* Error Messages */ - -#define CVDENSE "CVDense/CVReInitDense-- " - -#define MSG_CVMEM_NULL CVDENSE "CVode Memory is NULL.\n\n" - -#define MSG_MEM_FAIL CVDENSE "A memory request failed.\n\n" - -#define MSG_WRONG_NVEC CVDENSE "Incompatible NVECTOR implementation.\n\n" - -/* Other Constants */ - -#define MIN_INC_MULT RCONST(1000.0) -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) - - -/****************************************************************** - * * - * Types : CVDenseMemRec, CVDenseMem * - *----------------------------------------------------------------* - * The type CVDenseMem is pointer to a CVDenseMemRec. This * - * structure contains CVDense solver-specific data. * - * * - ******************************************************************/ - -typedef struct { - - CVDenseJacFn d_jac; /* jac = Jacobian routine to be called */ - - DenseMat d_M; /* M = I - gamma J, gamma = h / l1 */ - - integertype *d_pivots; /* pivots = pivot array for PM = LU */ - - DenseMat d_savedJ; /* savedJ = old Jacobian */ - - long int d_nstlj; /* nstlj = nst at last Jacobian eval. */ - - long int d_nje; /* nje = no. of calls to jac */ - - void *d_J_data; /* J_data is passed to jac */ - -} CVDenseMemRec, *CVDenseMem; - - -/* CVDENSE linit, lsetup, lsolve, lfree, and DQJac routines */ - -static int CVDenseInit(CVodeMem cv_mem); - -static int CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3); - -static int CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, - N_Vector fcur); - -static void CVDenseFree(CVodeMem cv_mem); - -static void CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, - realtype t, N_Vector y, N_Vector fy, N_Vector ewt, - realtype h, realtype uround, void *jac_data, - long int *nfePtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3); - - -/*************** CVDenseDQJac **************************************** - - This routine generates a dense difference quotient approximation to - the Jacobian of f(t,y). It assumes that a dense matrix of type - DenseMat is stored column-wise, and that elements within each column - are contiguous. The address of the jth column of J is obtained via - the macro DENSE_COL and an N_Vector with the jth column as the - component array is created using N_VMake and N_VSetData. Finally, the - actual computation of the jth column of the Jacobian is done with a - call to N_VLinearSum. - -**********************************************************************/ - -static void CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, - realtype tn, N_Vector y, N_Vector fy, N_Vector ewt, - realtype h, realtype uround, void *jac_data, - long int *nfePtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3) -{ - realtype fnorm, minInc, inc, inc_inv, yjsaved, srur; - realtype *y_data, *ewt_data; - N_Vector ftemp, jthCol; - M_Env machEnv; - integertype j; - - if (svnid == NULL) fprintf(stderr," "); - machEnv = y->menv; /* Get machine environment */ - - ftemp = vtemp1; /* Rename work vector for use as f vector value */ - - /* Obtain pointers to the data for ewt, y */ - ewt_data = N_VGetData(ewt); - y_data = N_VGetData(y); - - /* Set minimum increment based on uround and norm of f */ - srur = RSqrt(uround); - fnorm = N_VWrmsNorm(fy, ewt); - minInc = (fnorm != ZERO) ? - (MIN_INC_MULT * ABS(h) * uround * N * fnorm) : ONE; - - jthCol = N_VMake(N, y_data, machEnv); /* j loop overwrites this data address */ - - /* This is the only for loop for 0..N-1 in CVODE */ - for (j = 0; j < N; j++) { - - /* Generate the jth col of J(tn,y) */ - - N_VSetData(DENSE_COL(J,j), jthCol); - yjsaved = y_data[j]; - inc = MAX(srur*ABS(yjsaved), minInc/ewt_data[j]); - y_data[j] += inc; - f(N, tn, y, ftemp, f_data); - inc_inv = ONE/inc; - N_VLinearSum(inc_inv, ftemp, -inc_inv, fy, jthCol); - y_data[j] = yjsaved; - } - - N_VDispose(jthCol); - - /* Increment counter nfe = *nfePtr */ - *nfePtr += N; -} - - -/* Readability Replacements */ - -#define N (cv_mem->cv_N) -#define lmm (cv_mem->cv_lmm) -#define f (cv_mem->cv_f) -#define f_data (cv_mem->cv_f_data) -#define uround (cv_mem->cv_uround) -#define nst (cv_mem->cv_nst) -#define tn (cv_mem->cv_tn) -#define h (cv_mem->cv_h) -#define gamma (cv_mem->cv_gamma) -#define gammap (cv_mem->cv_gammap) -#define gamrat (cv_mem->cv_gamrat) -#define ewt (cv_mem->cv_ewt) -#define nfe (cv_mem->cv_nfe) -#define errfp (cv_mem->cv_errfp) -#define iopt (cv_mem->cv_iopt) -#define linit (cv_mem->cv_linit) -#define lsetup (cv_mem->cv_lsetup) -#define lsolve (cv_mem->cv_lsolve) -#define lfree (cv_mem->cv_lfree) -#define lmem (cv_mem->cv_lmem) -#define setupNonNull (cv_mem->cv_setupNonNull) -#define machenv (cv_mem->cv_machenv) - -#define jac (cvdense_mem->d_jac) -#define M (cvdense_mem->d_M) -#define pivots (cvdense_mem->d_pivots) -#define savedJ (cvdense_mem->d_savedJ) -#define nstlj (cvdense_mem->d_nstlj) -#define nje (cvdense_mem->d_nje) -#define J_data (cvdense_mem->d_J_data) - - -/*************** CVDense ********************************************* - - This routine initializes the memory record and sets various function - fields specific to the dense linear solver module. CVDense first - calls the existing lfree routine if this is not NULL. Then it sets - the cv_linit, cv_lsetup, cv_lsolve, cv_lfree fields in (*cvode_mem) - to be CVDenseInit, CVDenseSetup, CVDenseSolve, and CVDenseFree, - respectively. It allocates memory for a structure of type - CVDenseMemRec and sets the cv_lmem field in (*cvode_mem) to the - address of this structure. It sets setupNonNull in (*cvode_mem) to - TRUE, the d_J_data field in CVDenseMemRec to be the input - parameter jac_data, and the d_jac field to be: - (1) the input parameter djac if djac != NULL or - (2) CVDenseDQJac if djac == NULL. - Finally, it allocates memory for M, savedJ, and pivots. - The return value is SUCCESS = 0, or LMEM_FAIL = -1. - - NOTE: The dense linear solver assumes a serial implementation - of the NVECTOR package. Therefore, CVDense will first - test for compatible a compatible N_Vector internal - representation by checking (1) the machine environment - ID tag and (2) that the functions N_VMake, N_VDispose, - N_VGetData, and N_VSetData are implemented. - -**********************************************************************/ - -int CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) -{ - CVodeMem cv_mem; - CVDenseMem cvdense_mem; - - /* Return immediately if cvode_mem is NULL */ - cv_mem = (CVodeMem) cvode_mem; - if (cv_mem == NULL) { /* CVode reports this error */ - output_msg(OUTPUT_CVODE, MSG_CVMEM_NULL); - return(LMEM_FAIL); - } - - /* Test if the NVECTOR package is compatible with the DENSE solver */ - if ((strcmp(machenv->tag,"serial")) || - machenv->ops->nvmake == NULL || - machenv->ops->nvdispose == NULL || - machenv->ops->nvgetdata == NULL || - machenv->ops->nvsetdata == NULL) { - output_msg(OUTPUT_CVODE, MSG_WRONG_NVEC); - return(LMEM_FAIL); - } - - if (lfree !=NULL) lfree(cv_mem); - - /* Set four main function fields in cv_mem */ - linit = CVDenseInit; - lsetup = CVDenseSetup; - lsolve = CVDenseSolve; - lfree = CVDenseFree; - - /* Get memory for CVDenseMemRec */ - lmem = cvdense_mem = (CVDenseMem) malloc(sizeof(CVDenseMemRec)); - if (cvdense_mem == NULL) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - return(LMEM_FAIL); - } - - /* Set Jacobian routine field, J_data, and setupNonNull */ - if (djac == NULL) { - jac = CVDenseDQJac; - } else { - jac = djac; - } - J_data = jac_data; - setupNonNull = TRUE; - - /* Allocate memory for M, savedJ, and pivot array */ - - M = DenseAllocMat(N); - if (M == NULL) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - return(LMEM_FAIL); - } - savedJ = DenseAllocMat(N); - if (savedJ == NULL) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - DenseFreeMat(M); - return(LMEM_FAIL); - } - pivots = DenseAllocPiv(N); - if (pivots == NULL) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - DenseFreeMat(M); - DenseFreeMat(savedJ); - return(LMEM_FAIL); - } - - return(SUCCESS); -} - -/*************** CVReInitDense**************************************** - - This routine resets the link between the main CVODE module and the - dense linear solver module CVDENSE. No memory freeing or allocation - operations are done, as the existing linear solver memory is assumed - sufficient. All other initializations are the same as in CVDense. - The return value is SUCCESS = 0, or LMEM_FAIL = -1. - -**********************************************************************/ - -int CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) -{ - CVodeMem cv_mem; - CVDenseMem cvdense_mem; - - /* Return immediately if cvode_mem is NULL */ - cv_mem = (CVodeMem) cvode_mem; - if (cv_mem == NULL) { /* CVode reports this error */ - output_msg(OUTPUT_CVODE, MSG_CVMEM_NULL); - return(LMEM_FAIL); - } - - /* Test if the NVECTOR package is compatible with the DENSE solver */ - if ((strcmp(machenv->tag,"serial")) || - machenv->ops->nvmake == NULL || - machenv->ops->nvdispose == NULL || - machenv->ops->nvgetdata == NULL || - machenv->ops->nvsetdata == NULL) { - output_msg(OUTPUT_CVODE, MSG_WRONG_NVEC); - return(LMEM_FAIL); - } - - cvdense_mem = (CVDenseMem) lmem; /* Use existing linear solver memory pointer */ - - /* Set four main function fields in cv_mem */ - linit = CVDenseInit; - lsetup = CVDenseSetup; - lsolve = CVDenseSolve; - lfree = CVDenseFree; - - /* Set Jacobian routine field, J_data, and setupNonNull */ - if (djac == NULL) { - jac = CVDenseDQJac; - } else { - jac = djac; - } - J_data = jac_data; - setupNonNull = TRUE; - - return(SUCCESS); -} - -/*************** CVDenseInit ***************************************** - - This routine does remaining initializations specific to the dense - linear solver. - -**********************************************************************/ - -static int CVDenseInit(CVodeMem cv_mem) -{ - CVDenseMem cvdense_mem; - cvdense_mem = (CVDenseMem) lmem; - - /* Initialize nje and nstlj, and set workspace lengths */ - - nje = 0; - if (iopt != NULL) { - iopt[DENSE_NJE] = nje; - iopt[DENSE_LRW] = 2*N*N; - iopt[DENSE_LIW] = N; - } - nstlj = 0; - - return(LINIT_OK); -} - -/*************** CVDenseSetup **************************************** - - This routine does the setup operations for the dense linear solver. - It makes a decision whether or not to call the Jacobian evaluation - routine based on various state variables, and if not it uses the - saved copy. In any case, it constructs the Newton matrix - M = I - gamma*J, updates counters, and calls the dense LU - factorization routine. - -**********************************************************************/ - -static int CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) -{ - booleantype jbad, jok; - realtype dgamma; - integertype ier; - CVDenseMem cvdense_mem; - - cvdense_mem = (CVDenseMem) lmem; - - /* Use nst, gamma/gammap, and convfail to set J eval. flag jok */ - - dgamma = ABS((gamma/gammap) - ONE); - jbad = (nst == 0) || (nst > nstlj + CVD_MSBJ) || - ((convfail == FAIL_BAD_J) && (dgamma < CVD_DGMAX)) || - (convfail == FAIL_OTHER); - jok = !jbad; - - if (jok) { - /* If jok = TRUE, use saved copy of J */ - *jcurPtr = FALSE; - DenseCopy(savedJ, M); - } else { - /* If jok = FALSE, call jac routine for new J value */ - nje++; - if (iopt != NULL) iopt[DENSE_NJE] = nje; - nstlj = nst; - *jcurPtr = TRUE; - DenseZero(M); - jac(N, M, f, f_data, tn, ypred, fpred, ewt, h, - uround, J_data, &nfe, vtemp1, vtemp2, vtemp3); - DenseCopy(M, savedJ); - } - - /* Scale and add I to get M = I - gamma*J */ - DenseScale(-gamma, M); - DenseAddI(M); - - /* Do LU factorization of M */ - ier = DenseFactor(M, pivots); - - /* Return 0 if the LU was complete; otherwise return 1 */ - if (ier > 0) return(1); - return(0); -} - -/*************** CVDenseSolve **************************************** - - This routine handles the solve operation for the dense linear solver - by calling the dense backsolve routine. The returned value is 0. - -**********************************************************************/ - -static int CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, - N_Vector fcur) -{ - CVDenseMem cvdense_mem; - realtype *bd; - - cvdense_mem = (CVDenseMem) lmem; - - bd = N_VGetData(b); - DenseBacksolve(M, pivots, bd); - N_VSetData(bd, b); - - /* If BDF, scale the correction to account for change in gamma */ - if ((lmm == BDF) && (gamrat != ONE)) { - N_VScale(TWO/(ONE + gamrat), b, b); - } - - return(0); -} - -/*************** CVDenseFree ***************************************** - - This routine frees memory specific to the dense linear solver. - -**********************************************************************/ - -static void CVDenseFree(CVodeMem cv_mem) -{ - CVDenseMem cvdense_mem; - - cvdense_mem = (CVDenseMem) lmem; - - DenseFreeMat(M); - DenseFreeMat(savedJ); - DenseFreePiv(pivots); - free(cvdense_mem); -} diff --git a/cvode.cpp b/cvode.cpp deleted file mode 100644 index b5c07e94..00000000 --- a/cvode.cpp +++ /dev/null @@ -1,3330 +0,0 @@ -/*#define DEBUG_CVODE*/ -extern char *error_string; -/******************************************************************* - * * - * File : cvode.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, * - * and Dan Shumaker @ LLNL * - * Version of : 24 July 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for the main CVODE integrator. * - * It is independent of the CVODE linear solver in use. * - * * - *******************************************************************/ - - -/************************************************************/ -/******************* BEGIN Imports **************************/ -/************************************************************/ - -#include -#include -#include "cvode.h" -#include "sundialstypes.h" -#include "nvector.h" -#include "sundialsmath.h" -#include "output.h" -#define KINETICS_EXTERNAL -#include "kinetics.h" -#include "phqalloc.h" -/* WARNING don't include any headers below here */ -#define malloc PHRQ_malloc -static char const svnid[] = "$Id: cvode.c 663 2005-11-16 00:46:04Z dlpark $"; - -/************************************************************/ -/******************** END Imports ***************************/ -/************************************************************/ - - -/***************************************************************/ -/*********************** BEGIN Macros **************************/ -/***************************************************************/ - -/* Macro: loop */ - -#define loop for(;;) - -/***************************************************************/ -/************************ END Macros ***************************/ -/***************************************************************/ - - - -/************************************************************/ -/************** BEGIN CVODE Private Constants ***************/ -/************************************************************/ - -#define FOURTH RCONST(0.25) /* real 0.25 */ -#define THREE RCONST(3.0) /* real 3.0 */ -#define FOUR RCONST(4.0) /* real 4.0 */ -#define HUN RCONST(100.0) /* real 100.0 */ -#define TINY RCONST(1.0e-10) /* small number */ -#define HALF RCONST(0.5) /* real 0.5 */ -#define ZERO RCONST(0.0) /* real 0.0 */ -#define ONE RCONST(1.0) /* real 1.0 */ -#define TWO RCONST(2.0) /* real 2.0 */ -#define TWELVE RCONST(12.0) /* real 12.0 */ - -/***************************************************************/ -/************** BEGIN Default Constants ************************/ -/***************************************************************/ - -#define HMIN_DEFAULT ZERO /* hmin default value */ -#define HMAX_INV_DEFAULT ZERO /* hmax_inv default value */ -#define MXHNIL_DEFAULT 10 /* mxhnil default value */ -#define MXSTEP_DEFAULT 50 /* mxstep default value */ - - -/***************************************************************/ -/*************** END Default Constants *************************/ -/***************************************************************/ - - -/***************************************************************/ -/************ BEGIN Routine-Specific Constants *****************/ -/***************************************************************/ - -/* CVodeDky */ - -#define FUZZ_FACTOR RCONST(100.0) - -/* CVHin */ - -#define HLB_FACTOR RCONST(100.0) -#define HUB_FACTOR RCONST(0.1) -#define H_BIAS HALF -#define MAX_ITERS 4 - -/* CVSet */ - -#define CORTES RCONST(0.1) - -/* CVStep return values */ - -#define SUCCESS_STEP 0 -#define REP_ERR_FAIL -1 -#define REP_CONV_FAIL -2 -#define SETUP_FAILED -3 -#define SOLVE_FAILED -4 - -/* CVStep control constants */ - -#define PREDICT_AGAIN -5 -#define DO_ERROR_TEST 1 - -/* CVStep */ - -#define THRESH RCONST(1.5) -#define ETAMX1 RCONST(10000.0) -#define ETAMX2 RCONST(10.0) -#define ETAMX3 RCONST(10.0) -#define ETAMXF RCONST(0.2) -#define ETAMIN RCONST(0.1) -#define ETACF RCONST(0.25) -#define ADDON RCONST(0.000001) -#define BIAS1 RCONST(6.0) -#define BIAS2 RCONST(6.0) -#define BIAS3 RCONST(10.0) -#define ONEPSM RCONST(1.000001) - -#define SMALL_NST 10 /* nst > SMALL_NST => use ETAMX3 */ -#define MXNCF 10 /* max no. of convergence failures during */ - /* one step try */ -#define MXNEF 7 /* max no. of error test failures during */ - /* one step try */ -#define MXNEF1 3 /* max no. of error test failures before */ - /* forcing a reduction of order */ -#define SMALL_NEF 2 /* if an error failure occurs and */ - /* SMALL_NEF <= nef <= MXNEF1, then */ - /* reset eta = MIN(eta, ETAMXF) */ -#define LONG_WAIT 10 /* number of steps to wait before */ - /* considering an order change when */ - /* q==1 and MXNEF1 error test failures */ - /* have occurred */ - -/* CVnls return values */ - -#define SOLVED 0 -#define CONV_FAIL -1 -#define SETUP_FAIL_UNREC -2 -#define SOLVE_FAIL_UNREC -3 - -/* CVnls input flags */ - -#define FIRST_CALL 0 -#define PREV_CONV_FAIL -1 -#define PREV_ERR_FAIL -2 - -/* CVnls other constants */ - -#define FUNC_MAXCOR 3 /* maximum no. of corrector iterations */ - /* for iter == FUNCTIONAL */ -#define NEWT_MAXCOR 3 /* maximum no. of corrector iterations */ - /* for iter == NEWTON */ - -#define CRDOWN RCONST(0.3) /* constant used in the estimation of the */ - /* convergence rate (crate) of the */ - /* iterates for the nonlinear equation */ -#define DGMAX RCONST(0.3) /* iter == NEWTON, |gamma/gammap-1| > DGMAX */ - /* => call lsetup */ - -#define RDIV TWO /* declare divergence if ratio del/delp > RDIV */ -#define MSBP 20 /* max no. of steps between lsetup calls */ - -#define TRY_AGAIN 99 /* control constant for CVnlsNewton - should be */ - /* distinct from CVnls return values */ - - -/***************************************************************/ -/*************** END Routine-Specific Constants ***************/ -/***************************************************************/ - - -/***************************************************************/ -/***************** BEGIN Error Messages ************************/ -/***************************************************************/ - -/* CVodeMalloc/CVReInit Error Messages */ - -#define CVM "CVodeMalloc/CVReInit-- " - -#define MSG_Y0_NULL CVM "y0=NULL illegal.\n\n" - -#define MSG_BAD_N CVM "N=%ld < 1 illegal.\n\n" - -#define MSG_BAD_LMM_1 CVM "lmm=%d illegal.\n" -#define MSG_BAD_LMM_2 "The legal values are ADAMS=%d and BDF=%d.\n\n" -#define MSG_BAD_LMM MSG_BAD_LMM_1 MSG_BAD_LMM_2 - -#define MSG_BAD_ITER_1 CVM "iter=%d illegal.\n" -#define MSG_BAD_ITER_2 "The legal values are FUNCTIONAL=%d " -#define MSG_BAD_ITER_3 "and NEWTON=%d.\n\n" -#define MSG_BAD_ITER MSG_BAD_ITER_1 MSG_BAD_ITER_2 MSG_BAD_ITER_3 - -#define MSG_BAD_ITOL_1 CVM "itol=%d illegal.\n" -#define MSG_BAD_ITOL_2 "The legal values are SS=%d and SV=%d.\n\n" -#define MSG_BAD_ITOL MSG_BAD_ITOL_1 MSG_BAD_ITOL_2 - -#define MSG_F_NULL CVM "f=NULL illegal.\n\n" - -#define MSG_RELTOL_NULL CVM "reltol=NULL illegal.\n\n" - -#define MSG_BAD_RELTOL CVM "*reltol=%g < 0 illegal.\n\n" - -#define MSG_ABSTOL_NULL CVM "abstol=NULL illegal.\n\n" - -#define MSG_BAD_ABSTOL CVM "Some abstol component < 0.0 illegal.\n\n" - -#define MSG_BAD_OPTIN_1 CVM "optIn=%d illegal.\n" -#define MSG_BAD_OPTIN_2 "The legal values are FALSE=%d and TRUE=%d.\n\n" -#define MSG_BAD_OPTIN MSG_BAD_OPTIN_1 MSG_BAD_OPTIN_2 - -#define MSG_BAD_OPT CVM "optIn=TRUE, but iopt=ropt=NULL.\n\n" - -#define MSG_MEM_FAIL CVM "A memory request failed.\n\n" - -#define MSG_BAD_EWT CVM "Some initial ewt component = 0.0 illegal.\n\n" - -#define MSG_REI_NO_MEM "CVReInit-- cvode_mem = NULL illegal.\n\n" - -#define MSG_REI_MAXORD1 "CVReInit-- Illegal attempt to increase " -#define MSG_REI_MAXORD2 "maximum method order from %d to %d.\n\n" -#define MSG_REI_MAXORD MSG_REI_MAXORD1 MSG_REI_MAXORD2 - - -/* CVode error messages */ - -#define CVODE "CVode-- " - -#define NO_MEM "cvode_mem=NULL illegal.\n\n" - -#define MSG_CVODE_NO_MEM CVODE NO_MEM - -#define MSG_LINIT_NULL CVODE "The linear solver's init routine is NULL.\n\n" - -#define MSG_LSETUP_NULL CVODE "The linear solver's setup routine is NULL.\n\n" - -#define MSG_LSOLVE_NULL CVODE "The linear solver's solve routine is NULL.\n\n" - -#define MSG_LFREE_NULL CVODE "The linear solver's free routine is NULL.\n\n" - -#define MSG_LINIT_FAIL CVODE "The linear solver's init routine failed.\n\n" - -#define MSG_YOUT_NULL CVODE "yout=NULL illegal.\n\n" - -#define MSG_T_NULL CVODE "t=NULL illegal.\n\n" - -#define MSG_BAD_ITASK_1 CVODE "itask=%d illegal.\nThe legal values are" -#define MSG_BAD_ITASK_2 " NORMAL=%d and ONE_STEP=%d.\n\n" -#define MSG_BAD_ITASK MSG_BAD_ITASK_1 MSG_BAD_ITASK_2 - -#define MSG_BAD_HMIN_HMAX_1 CVODE "Inconsistent step size limits:\n" -#define MSG_BAD_HMIN_HMAX_2 "ropt[HMIN]=%g > ropt[HMAX]=%g.\n\n" -#define MSG_BAD_HMIN_HMAX MSG_BAD_HMIN_HMAX_1 MSG_BAD_HMIN_HMAX_2 - -#define MSG_BAD_H0 CVODE "h0=%g and tout-t0=%g inconsistent.\n\n" - -#define MSG_BAD_TOUT_1 CVODE "Trouble interpolating at tout = %g.\n" -#define MSG_BAD_TOUT_2 "tout too far back in direction of integration.\n\n" -#define MSG_BAD_TOUT MSG_BAD_TOUT_1 MSG_BAD_TOUT_2 - -#define MSG_MAX_STEPS_1 CVODE "At t=%g, mxstep=%d steps taken on " -#define MSG_MAX_STEPS_2 "this call before\nreaching tout=%g.\n\n" -#define MSG_MAX_STEPS MSG_MAX_STEPS_1 MSG_MAX_STEPS_2 - -#define MSG_EWT_NOW_BAD_1 CVODE "At t=%g, " -#define MSG_EWT_NOW_BAD_2 "some ewt component has become <= 0.0.\n\n" -#define MSG_EWT_NOW_BAD MSG_EWT_NOW_BAD_1 MSG_EWT_NOW_BAD_2 - -#define MSG_TOO_MUCH_ACC CVODE "At t=%g, too much accuracy requested.\n\n" - -#define MSG_HNIL_1 CVODE "Warning.. internal t=%g and step size h=%g\n" -#define MSG_HNIL_2 "are such that t + h == t on the next step.\n" -#define MSG_HNIL_3 "The solver will continue anyway.\n\n" -#define MSG_HNIL MSG_HNIL_1 MSG_HNIL_2 MSG_HNIL_3 - -#define MSG_HNIL_DONE_1 CVODE "The above warning has been issued %d times " -#define MSG_HNIL_DONE_2 "and will not be\nissued again for this problem.\n\n" -#define MSG_HNIL_DONE MSG_HNIL_DONE_1 MSG_HNIL_DONE_2 - -#define MSG_ERR_FAILS_1 CVODE "At t=%g and step size h=%g, the error test\n" -#define MSG_ERR_FAILS_2 "failed repeatedly or with |h| = hmin.\n\n" -#define MSG_ERR_FAILS MSG_ERR_FAILS_1 MSG_ERR_FAILS_2 - -#define MSG_CONV_FAILS_1 CVODE "At t=%g and step size h=%g, the corrector\n" -#define MSG_CONV_FAILS_2 "convergence failed repeatedly or " -#define MSG_CONV_FAILS_3 "with |h| = hmin.\n\n" -#define MSG_CONV_FAILS MSG_CONV_FAILS_1 MSG_CONV_FAILS_2 MSG_CONV_FAILS_3 - -#define MSG_SETUP_FAILED_1 CVODE "At t=%g, the setup routine failed in an " -#define MSG_SETUP_FAILED_2 "unrecoverable manner.\n\n" -#define MSG_SETUP_FAILED MSG_SETUP_FAILED_1 MSG_SETUP_FAILED_2 - -#define MSG_SOLVE_FAILED_1 CVODE "At t=%g, the solve routine failed in an " -#define MSG_SOLVE_FAILED_2 "unrecoverable manner.\n\n" -#define MSG_SOLVE_FAILED MSG_SOLVE_FAILED_1 MSG_SOLVE_FAILED_2 - -#define MSG_TOO_CLOSE_1 CVODE "tout=%g too close to t0=%g to start" -#define MSG_TOO_CLOSE_2 " integration.\n\n" -#define MSG_TOO_CLOSE MSG_TOO_CLOSE_1 MSG_TOO_CLOSE_2 - - -/* CVodeDky Error Messages */ - -#define DKY "CVodeDky-- " - -#define MSG_DKY_NO_MEM DKY NO_MEM - -#define MSG_BAD_K DKY "k=%d illegal.\n\n" - -#define MSG_BAD_T_1 DKY "t=%g illegal.\n" -#define MSG_BAD_T_2 "t not in interval tcur-hu=%g to tcur=%g.\n\n" -#define MSG_BAD_T MSG_BAD_T_1 MSG_BAD_T_2 - -#define MSG_BAD_DKY DKY "dky=NULL illegal.\n\n" - -/***************************************************************/ -/****************** END Error Messages *************************/ -/***************************************************************/ - - -/************************************************************/ -/*************** END CVODE Private Constants ****************/ -/************************************************************/ - - -/**************************************************************/ -/********* BEGIN Private Helper Functions Prototypes **********/ -/**************************************************************/ - -static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq, int maxord, - M_Env machEnv); -static void CVFreeVectors(CVodeMem cv_mem, int maxord); - -static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur); -static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur); -static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur); - -static booleantype CVHin(CVodeMem cv_mem, realtype tout); -static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist); -static realtype CVYddNorm(CVodeMem cv_mem, realtype hg); - -static int CVStep(CVodeMem cv_mem); - -static int CVsldet(CVodeMem cv_mem); - -static void CVAdjustParams(CVodeMem cv_mem); -static void CVAdjustOrder(CVodeMem cv_mem, int deltaq); -static void CVAdjustAdams(CVodeMem cv_mem, int deltaq); -static void CVAdjustBDF(CVodeMem cv_mem, int deltaq); -static void CVIncreaseBDF(CVodeMem cv_mem); -static void CVDecreaseBDF(CVodeMem cv_mem); - -static void CVRescale(CVodeMem cv_mem); - -static void CVPredict(CVodeMem cv_mem); - -static void CVSet(CVodeMem cv_mem); -static void CVSetAdams(CVodeMem cv_mem); -static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]); -static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], - realtype hsum); -static realtype CVAltSum(int iend, realtype a[], int k); -static void CVSetBDF(CVodeMem cv_mem); -static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, - realtype alpha0_hat, realtype xi_inv, realtype xistar_inv); - -static int CVnls(CVodeMem cv_mem, int nflag); -static int CVnlsFunctional(CVodeMem cv_mem); -static int CVnlsNewton(CVodeMem cv_mem, int nflag); -static int CVNewtonIteration(CVodeMem cv_mem); - -static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - int *ncfPtr); - -static void CVRestore(CVodeMem cv_mem, realtype saved_t); - -static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, - realtype saved_t, int *nefPtr, realtype *dsmPtr); - -static void CVCompleteStep(CVodeMem cv_mem); - -static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm); -static void CVSetEta(CVodeMem cv_mem); -static realtype CVComputeEtaqm1(CVodeMem cv_mem); -static realtype CVComputeEtaqp1(CVodeMem cv_mem); -static void CVChooseEta(CVodeMem cv_mem); -static void CVBDFStab(CVodeMem cv_mem); - -static int CVHandleFailure(CVodeMem cv_mem,int kflag); - - -/**************************************************************/ -/********** END Private Helper Functions Prototypes ***********/ -/**************************************************************/ - - -/**************************************************************/ -/**************** BEGIN Readability Constants *****************/ -/**************************************************************/ - - -#define uround (cv_mem->cv_uround) -#define zn (cv_mem->cv_zn) -#define ewt (cv_mem->cv_ewt) -#define y (cv_mem->cv_y) -#define acor (cv_mem->cv_acor) -#define tempv (cv_mem->cv_tempv) -#define ftemp (cv_mem->cv_ftemp) -#define q (cv_mem->cv_q) -#define qprime (cv_mem->cv_qprime) -#define qwait (cv_mem->cv_qwait) -#define L (cv_mem->cv_L) -#define h (cv_mem->cv_h) -#define hprime (cv_mem->cv_hprime) -#define eta (cv_mem-> cv_eta) -#define etaqm1 (cv_mem-> cv_etaqm1) -#define etaq (cv_mem-> cv_etaq) -#define etaqp1 (cv_mem-> cv_etaqp1) -#define nscon (cv_mem->cv_nscon) -#define ssdat (cv_mem->cv_ssdat) -#define hscale (cv_mem->cv_hscale) -#define tn (cv_mem->cv_tn) -#define tau (cv_mem->cv_tau) -#define tq (cv_mem->cv_tq) -#define l (cv_mem->cv_l) -#define rl1 (cv_mem->cv_rl1) -#define gamma (cv_mem->cv_gamma) -#define gammap (cv_mem->cv_gammap) -#define gamrat (cv_mem->cv_gamrat) -#define crate (cv_mem->cv_crate) -#define acnrm (cv_mem->cv_acnrm) -#define mnewt (cv_mem->cv_mnewt) -#define qmax (cv_mem->cv_qmax) -#define mxstep (cv_mem->cv_mxstep) -#define maxcor (cv_mem->cv_maxcor) -#define mxhnil (cv_mem->cv_mxhnil) -#define hmin (cv_mem->cv_hmin) -#define hmax_inv (cv_mem->cv_hmax_inv) -#define etamax (cv_mem->cv_etamax) -#define nst (cv_mem->cv_nst) -#define nfe (cv_mem->cv_nfe) -#define ncfn (cv_mem->cv_ncfn) -#define netf (cv_mem->cv_netf) -#define nni (cv_mem-> cv_nni) -#define nsetups (cv_mem->cv_nsetups) -#define nhnil (cv_mem->cv_nhnil) -#define lrw (cv_mem->cv_lrw) -#define liw (cv_mem->cv_liw) -#define linit (cv_mem->cv_linit) -#define lsetup (cv_mem->cv_lsetup) -#define lsolve (cv_mem->cv_lsolve) -#define lfree (cv_mem->cv_lfree) -#define lmem (cv_mem->cv_lmem) -#define qu (cv_mem->cv_qu) -#define nstlp (cv_mem->cv_nstlp) -#define hu (cv_mem->cv_hu) -#define saved_tq5 (cv_mem->cv_saved_tq5) -#define jcur (cv_mem->cv_jcur) -#define tolsf (cv_mem->cv_tolsf) -#define setupNonNull (cv_mem->cv_setupNonNull) -#define machenv (cv_mem->cv_machenv) -#define sldeton (cv_mem->cv_sldeton) - -/**************************************************************/ -/***************** END Readability Constants ******************/ -/**************************************************************/ - - -/***************************************************************/ -/************* BEGIN CVODE Implementation **********************/ -/***************************************************************/ - - -/***************************************************************/ -/********* BEGIN Exported Functions Implementation *************/ -/***************************************************************/ - - -/******************** CVodeMalloc ******************************* - - CVodeMalloc allocates and initializes memory for a problem. All - problem specification inputs are checked for errors. If any - error occurs during initialization, it is reported to the file - whose file pointer is errfp and NULL is returned. Otherwise, the - pointer to successfully initialized problem memory is returned. - -*****************************************************************/ - -void *CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, - int lmm, int iter, int itol, - realtype *reltol, void *abstol, - void *f_data, FILE *errfp, booleantype optIn, - long int iopt[], realtype ropt[], M_Env machEnv) -{ - booleantype allocOK, ioptExists, roptExists, neg_abstol, ewtsetOK; - int maxord; - CVodeMem cv_mem; - FILE *fp; - int i,k; - - if (svnid == NULL) fprintf(stderr," "); - /* Check for legal input parameters */ - - fp = (errfp == NULL) ? stdout : errfp; - - if (y0==NULL) { - output_msg(OUTPUT_CVODE, MSG_Y0_NULL); - return(NULL); - } - - if (N <= 0) { - output_msg(OUTPUT_CVODE, MSG_BAD_N, N); - return(NULL); - } - - if ((lmm != ADAMS) && (lmm != BDF)) { - output_msg(OUTPUT_CVODE, MSG_BAD_LMM, lmm, ADAMS, BDF); - return(NULL); - } - - if ((iter != FUNCTIONAL) && (iter != NEWTON)) { - output_msg(OUTPUT_CVODE, MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON); - return(NULL); - } - - if ((itol != SS) && (itol != SV)) { - output_msg(OUTPUT_CVODE, MSG_BAD_ITOL, itol, SS, SV); - return(NULL); - } - - if (f == NULL) { - output_msg(OUTPUT_CVODE, MSG_F_NULL); - return(NULL); - } - - if (reltol == NULL) { - output_msg(OUTPUT_CVODE, MSG_RELTOL_NULL); - return(NULL); - } - - if (*reltol < ZERO) { - output_msg(OUTPUT_CVODE, MSG_BAD_RELTOL, (double) *reltol); - return(NULL); - } - - if (abstol == NULL) { - output_msg(OUTPUT_CVODE, MSG_ABSTOL_NULL); - return(NULL); - } - - if (itol == SS) { - neg_abstol = (*((realtype *)abstol) < ZERO); - } else { - neg_abstol = (N_VMin((N_Vector)abstol) < ZERO); - } - if (neg_abstol) { - output_msg(OUTPUT_CVODE, MSG_BAD_ABSTOL); - return(NULL); - } - - if ((optIn != FALSE) && (optIn != TRUE)) { - output_msg(OUTPUT_CVODE, MSG_BAD_OPTIN, optIn, FALSE, TRUE); - return(NULL); - } - - if ((optIn) && (iopt == NULL) && (ropt == NULL)) { - output_msg(OUTPUT_CVODE, MSG_BAD_OPT); - return(NULL); - } - - ioptExists = (iopt != NULL); - roptExists = (ropt != NULL); - - /* Compute maxord */ - - maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; - - if (optIn && ioptExists) { - if (iopt[MAXORD] > 0) maxord = MIN(maxord, iopt[MAXORD]); - } - - cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); - if (cv_mem == NULL) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - return(NULL); - } - - /* Allocate the vectors */ - - allocOK = CVAllocVectors(cv_mem, N, maxord, machEnv); - if (!allocOK) { - output_msg(OUTPUT_CVODE, MSG_MEM_FAIL); - free(cv_mem); - return(NULL); - } - - /* Copy tolerances into memory, and set the ewt vector */ - - cv_mem->cv_itol = itol; - cv_mem->cv_reltol = reltol; - cv_mem->cv_abstol = abstol; - ewtsetOK = CVEwtSet(cv_mem, y0); - if (!ewtsetOK) { - output_msg(OUTPUT_CVODE, MSG_BAD_EWT); - CVFreeVectors(cv_mem, maxord); - free(cv_mem); - return(NULL); - } - - /* All error checking is complete at this point */ - - /* Copy the remaining input parameters into CVODE memory */ - - cv_mem->cv_N = N; - cv_mem->cv_f = f; - cv_mem->cv_f_data = f_data; - cv_mem->cv_lmm = lmm; - cv_mem->cv_iter = iter; - cv_mem->cv_optIn = optIn; - cv_mem->cv_iopt = iopt; - cv_mem->cv_ropt = ropt; - cv_mem->cv_errfp = fp; - tn = t0; - machenv = machEnv; - - /* Set step parameters */ - - q = 1; - L = 2; - qwait = L; - qmax = maxord; - etamax = ETAMX1; - - /* Set uround */ - - uround = UnitRoundoff(); - - /* Set the linear solver addresses to NULL. - (We check != NULL later, in CVode, if using NEWTON.) */ - - linit = NULL; - lsetup = NULL; - lsolve = NULL; - lfree = NULL; - lmem = NULL; - - /* Initialize zn[0] in the history array */ - - N_VScale(ONE, y0, zn[0]); - - /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ - - hmax_inv = HMAX_INV_DEFAULT; - hmin = HMIN_DEFAULT; - if (optIn && roptExists) { - if (ropt[HMIN] > ZERO) hmin = ropt[HMIN]; - } - - mxhnil = MXHNIL_DEFAULT; - mxstep = MXSTEP_DEFAULT; - if (optIn && ioptExists) { - if (iopt[MXHNIL] != 0) mxhnil = iopt[MXHNIL]; - if (iopt[MXSTEP] > 0) mxstep = iopt[MXSTEP]; - } - - if ((!optIn) && roptExists) ropt[H0] = ZERO; - - /* Set maxcor */ - - maxcor = (iter==NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; - - /* Initialize all the counters */ - - nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; - - /* Initialize all other variables corresponding to optional outputs */ - - qu = 0; - hu = ZERO; - tolsf = ONE; - - /* Initialize optional output locations in iopt, ropt */ - /* and Stablilty Limit Detection data. */ - - nscon = 0; - sldeton = FALSE; - if (ioptExists) { - iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; - iopt[NCFN] = iopt[NETF] = 0; - iopt[QU] = qu; - iopt[QCUR] = 0; - iopt[LENRW] = lrw; - iopt[LENIW] = liw; - if(optIn && iopt[SLDET] && (lmm == BDF)) { - sldeton = TRUE; - iopt[NOR] = 0; - for (i = 1; i <= 5; i++) { - for (k = 1; k <= 3; k++) ssdat[i-1][k-1] = ZERO;} - } - } - - if (roptExists) { - ropt[HU] = hu; - ropt[HCUR] = ZERO; - ropt[TCUR] = t0; - ropt[TOLSF] = tolsf; - } - - - /* Problem has been successfully initialized */ - - return((void *)cv_mem); -} - - -/******************** CVReInit ********************************** - - CVReInit re-initializes CVODE's memory for a problem, assuming - it has already been allocated in a prior CVodeMalloc call. - All problem specification inputs are checked for errors. - The problem size N is assumed to be unchanged since the call to - CVodeMalloc, and the maximum order maxord must not be larger. - If any error occurs during initialization, it is reported to the - file whose file pointer is errfp. - The return value is SUCCESS = 0 if no errors occurred, or - a negative value otherwise. - -*****************************************************************/ - -int CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, - int lmm, int iter, int itol, - realtype *reltol, void *abstol, - void *f_data, FILE *errfp, booleantype optIn, - long int iopt[], realtype ropt[], M_Env machEnv) -{ - booleantype ioptExists, roptExists, neg_abstol, ewtsetOK; - int maxord, i,k; - CVodeMem cv_mem; - FILE *fp; - - /* Check for legal input parameters */ - - fp = (errfp == NULL) ? stdout : errfp; - - if (cvode_mem == NULL) { - output_msg(OUTPUT_CVODE, MSG_REI_NO_MEM); - return(CVREI_NO_MEM); - } - cv_mem = (CVodeMem) cvode_mem; - - if (y0 == NULL) { - output_msg(OUTPUT_CVODE, MSG_Y0_NULL); - return(CVREI_ILL_INPUT); - } - - if ((lmm != ADAMS) && (lmm != BDF)) { - output_msg(OUTPUT_CVODE, MSG_BAD_LMM, lmm, ADAMS, BDF); - return(CVREI_ILL_INPUT); - } - - if ((iter != FUNCTIONAL) && (iter != NEWTON)) { - output_msg(OUTPUT_CVODE, MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON); - return(CVREI_ILL_INPUT); - } - - if ((itol != SS) && (itol != SV)) { - output_msg(OUTPUT_CVODE, MSG_BAD_ITOL, itol, SS, SV); - return(CVREI_ILL_INPUT); - } - - if (f == NULL) { - output_msg(OUTPUT_CVODE, MSG_F_NULL); - return(CVREI_ILL_INPUT); - } - - if (reltol == NULL) { - output_msg(OUTPUT_CVODE, MSG_RELTOL_NULL); - return(CVREI_ILL_INPUT); - } - - if (*reltol < ZERO) { - output_msg(OUTPUT_CVODE, MSG_BAD_RELTOL,(double) *reltol); - return(CVREI_ILL_INPUT); - } - - if (abstol == NULL) { - output_msg(OUTPUT_CVODE, MSG_ABSTOL_NULL); - return(CVREI_ILL_INPUT); - } - - if (itol == SS) { - neg_abstol = (*((realtype *)abstol) < ZERO); - } else { - neg_abstol = (N_VMin((N_Vector)abstol) < ZERO); - } - if (neg_abstol) { - output_msg(OUTPUT_CVODE, MSG_BAD_ABSTOL); - return(CVREI_ILL_INPUT); - } - - if ((optIn != FALSE) && (optIn != TRUE)) { - output_msg(OUTPUT_CVODE, MSG_BAD_OPTIN, optIn, FALSE, TRUE); - return(CVREI_ILL_INPUT); - } - - if ((optIn) && (iopt == NULL) && (ropt == NULL)) { - output_msg(OUTPUT_CVODE, MSG_BAD_OPT); - return(CVREI_ILL_INPUT); - } - - ioptExists = (iopt != NULL); - roptExists = (ropt != NULL); - - /* Compute new maxord and check against old value */ - - maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; - if (optIn && ioptExists) - { if (iopt[MAXORD] > 0) maxord = MIN(maxord, iopt[MAXORD]); } - if (maxord > qmax) { - output_msg(OUTPUT_CVODE, MSG_REI_MAXORD, qmax, maxord); - return(CVREI_ILL_INPUT); - } - - /* Copy tolerances into memory, and set the ewt vector */ - - cv_mem->cv_itol = itol; - cv_mem->cv_reltol = reltol; - cv_mem->cv_abstol = abstol; - ewtsetOK = CVEwtSet(cv_mem, y0); - if (!ewtsetOK) { - output_msg(OUTPUT_CVODE, MSG_BAD_EWT); - return(CVREI_ILL_INPUT); - } - - /* All error checking is complete at this point */ - - /* Copy the remaining input parameters into CVODE memory */ - - cv_mem->cv_f = f; - cv_mem->cv_f_data = f_data; - cv_mem->cv_lmm = lmm; - cv_mem->cv_iter = iter; - cv_mem->cv_optIn = optIn; - cv_mem->cv_iopt = iopt; - cv_mem->cv_ropt = ropt; - cv_mem->cv_errfp = fp; - tn = t0; - machenv = machEnv; - - /* Set step parameters */ - - q = 1; - L = 2; - qwait = L; - qmax = maxord; - etamax = ETAMX1; - - /* Set uround */ - - uround = UnitRoundoff(); - - /* Initialize zn[0] in the history array */ - - N_VScale(ONE, y0, zn[0]); - - /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ - - hmax_inv = HMAX_INV_DEFAULT; - hmin = HMIN_DEFAULT; - if (optIn && roptExists) { - if (ropt[HMIN] > ZERO) hmin = ropt[HMIN]; - } - - mxhnil = MXHNIL_DEFAULT; - mxstep = MXSTEP_DEFAULT; - if (optIn && ioptExists) { - if (iopt[MXHNIL] != 0) mxhnil = iopt[MXHNIL]; - if (iopt[MXSTEP] > 0) mxstep = iopt[MXSTEP]; - } - - if ((!optIn) && roptExists) ropt[H0] = ZERO; - - /* Set maxcor */ - - maxcor = (iter==NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; - - /* Initialize all the counters */ - - nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; - - /* Initialize all other vars corresponding to optional outputs */ - - qu = 0; - hu = ZERO; - tolsf = ONE; - - /* Initialize optional output locations in iopt, ropt */ - /* and Stablilty Limit Detection data. */ - - nscon = 0; - sldeton = FALSE; - if (ioptExists) { - iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; - iopt[NCFN] = iopt[NETF] = 0; - iopt[QU] = qu; - iopt[QCUR] = 0; - iopt[LENRW] = lrw; - iopt[LENIW] = liw; - if(optIn && iopt[SLDET] && (lmm == BDF)) { - sldeton = TRUE; - iopt[NOR] = 0; - for (i = 1; i <= 5; i++) { - for (k = 1; k <= 3; k++) ssdat[i-1][k-1] = ZERO;} - } - } - - if (roptExists) { - ropt[HU] = hu; - ropt[HCUR] = ZERO; - ropt[TCUR] = t0; - ropt[TOLSF] = tolsf; - } - - /* Problem has been successfully re-initialized */ - - return(SUCCESS); -} - - -/**************************************************************/ -/************** BEGIN More Readability Constants **************/ -/**************************************************************/ - -#define N (cv_mem->cv_N) -#define f (cv_mem->cv_f) -#define f_data (cv_mem->cv_f_data) -#define lmm (cv_mem->cv_lmm) -#define iter (cv_mem->cv_iter) -#define itol (cv_mem->cv_itol) -#define reltol (cv_mem->cv_reltol) -#define abstol (cv_mem->cv_abstol) -#define optIn (cv_mem->cv_optIn) -#define iopt (cv_mem->cv_iopt) -#define ropt (cv_mem->cv_ropt) -#define errfp (cv_mem->cv_errfp) - -/**************************************************************/ -/*************** END More Readability Constants ***************/ -/**************************************************************/ - - -/********************* CVode **************************************** - - This routine is the main driver of the CVODE package. - - It integrates over a time interval defined by the user, by calling - CVStep to do internal time steps. - - The first time that CVode is called for a successfully initialized - problem, it computes a tentative initial step size h. - - CVode supports two modes, specified by itask: NORMAL and ONE_STEP. - In the NORMAL mode, the solver steps until it reaches or passes tout - and then interpolates to obtain y(tout). - In the ONE_STEP mode, it takes one internal step and returns. - -********************************************************************/ - -int CVode(void *cvode_mem, realtype tout, N_Vector yout, - realtype *t, int itask) -{ - int nstloc, kflag, istate, next_q, ier; - realtype rh, next_h; - booleantype hOK, ewtsetOK; - CVodeMem cv_mem; - realtype t0; - - /* Check for legal inputs in all cases */ - - cv_mem = (CVodeMem) cvode_mem; - if (cvode_mem == NULL) { - output_msg(OUTPUT_CVODE, MSG_CVODE_NO_MEM); - return(CVODE_NO_MEM); - } - - if ((y = yout) == NULL) { - output_msg(OUTPUT_CVODE, MSG_YOUT_NULL); - return(ILL_INPUT); - } - - if (t == NULL) { - output_msg(OUTPUT_CVODE, MSG_T_NULL); - return(ILL_INPUT); - } - t0 = tn; - *t = tn; - - if ((itask != NORMAL) && (itask != ONE_STEP)) { - output_msg(OUTPUT_CVODE, MSG_BAD_ITASK, itask, NORMAL, ONE_STEP); - return(ILL_INPUT); - } - - /* Set hmax_inv from ropt[HMAX] and test for hmin > hmax */ - - if (optIn && ropt != NULL) { - if (ropt[HMAX] > ZERO) hmax_inv = ONE/ropt[HMAX]; - if (hmin*hmax_inv > ONE) { - output_msg(OUTPUT_CVODE, MSG_BAD_HMIN_HMAX, (double) hmin, (double) ropt[HMAX]); - return(ILL_INPUT); - } - } - - /* On first call, check solver functions and call linit function */ - - if (nst == 0) { - if (iter == NEWTON) { - if (linit == NULL) { - output_msg(OUTPUT_CVODE, MSG_LINIT_NULL); - return(ILL_INPUT); - } - if (lsetup == NULL) { - output_msg(OUTPUT_CVODE, MSG_LSETUP_NULL); - return(ILL_INPUT); - } - if (lsolve == NULL) { - output_msg(OUTPUT_CVODE, MSG_LSOLVE_NULL); - return(ILL_INPUT); - } - if (lfree == NULL) { - output_msg(OUTPUT_CVODE, MSG_LFREE_NULL); - return(ILL_INPUT); - } - ier = linit(cv_mem); - if (ier != LINIT_OK) { - output_msg(OUTPUT_CVODE, MSG_LINIT_FAIL); - return(ILL_INPUT); - } - } - - /* On the first call, call f at (t0,y0), set zn[1] = y'(t0), - set initial h (from H0 or CVHin), and scale zn[1] by h */ - cvode_rate_sim_time = cvode_rate_sim_time_start + tn; - cvode_step_fraction = 0; - - f(N, tn, zn[0], zn[1], f_data); - nfe = 1; - h = ZERO; - if (ropt != NULL) h = ropt[H0]; - if ( (h != ZERO) && ((tout-tn)*h < ZERO) ) { - output_msg(OUTPUT_CVODE, MSG_BAD_H0, (double) h, (double) (tout-tn)); - return(ILL_INPUT); - } - if (h == ZERO) { - hOK = CVHin(cv_mem, tout); - if (!hOK) { - output_msg(OUTPUT_CVODE, MSG_TOO_CLOSE, (double) tout, (double) tn); - return(ILL_INPUT); - } - } - rh = ABS(h)*hmax_inv; - if (rh > ONE) h /= rh; - if (ABS(h) < hmin) h *= hmin/ABS(h); - hscale = h; - N_VScale(h, zn[1], zn[1]); - - } /* end of first call block */ - - /* If not the first call, check if tout already reached */ - - if ( (itask == NORMAL) && (nst > 0) && ((tn-tout)*h >= ZERO) ) { - *t = tout; - ier = CVodeDky(cv_mem, tout, 0, yout); - if (ier != OKAY) { /* ier must be == BAD_T */ - output_msg(OUTPUT_CVODE, MSG_BAD_TOUT, (double) tout); - return(ILL_INPUT); - } - return(SUCCESS); - } - - /* Looping point for internal steps */ - - nstloc = 0; - loop { - - next_h = h; - next_q = q; - - /* Reset and check ewt */ - - if (nst > 0) { - ewtsetOK = CVEwtSet(cv_mem, zn[0]); - if (!ewtsetOK) { - output_msg(OUTPUT_CVODE, MSG_EWT_NOW_BAD, (double) tn); - istate = ILL_INPUT; - *t = tn; - N_VScale(ONE, zn[0], yout); - break; - } - } - - /* Check for too many steps */ - - if (nstloc >= mxstep) { - /* output_msg(OUTPUT_CVODE, MSG_MAX_STEPS, tn, mxstep, tout); */ - istate = TOO_MUCH_WORK; - *t = tn; - N_VScale(ONE, zn[0], yout); - break; - } - - /* Check for too much accuracy requested */ - - if ((tolsf = uround * N_VWrmsNorm(zn[0], ewt)) > ONE) { - output_msg(OUTPUT_CVODE, MSG_TOO_MUCH_ACC, (double) tn); - istate = TOO_MUCH_ACC; - *t = tn; - N_VScale(ONE, zn[0], yout); - tolsf *= TWO; - break; - } - - /* Check for h below roundoff level in tn */ - - if (tn + h == tn) { - nhnil++; - if (nhnil <= mxhnil) output_msg(OUTPUT_CVODE, MSG_HNIL, (double) tn, (double) h); - if (nhnil == mxhnil) output_msg(OUTPUT_CVODE, MSG_HNIL_DONE, mxhnil); - } - - /* Call CVStep to take a step */ - - kflag = CVStep(cv_mem); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After CVStep, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After CVStep, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After CVStep, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After CVStep, zn OK\n"); - } -#endif - /* Process failed step cases, and exit loop */ - - if (kflag != SUCCESS_STEP) { - istate = CVHandleFailure(cv_mem, kflag); - *t = tn; - N_VScale(ONE, zn[0], yout); - break; - } - - nstloc++; - - /* Check if in one-step mode, and if so copy y and exit loop */ - - if (itask == ONE_STEP) { - istate = SUCCESS; - *t = tn; - N_VScale(ONE, zn[0], yout); - next_q = qprime; - next_h = hprime; - break; - } - cvode_rate_sim_time = cvode_rate_sim_time_start + tn; - cvode_step_fraction = (tn - t0)/(tout - t0); - /* - output_msg(OUTPUT_CVODE, "ODE: tn %e, t0 %e, tout %e, step_frac %e\n", (double) tn, (double) t0, (double) tout, (double) cvode_step_fraction); - */ - /* Check if tout reached, and if so interpolate and exit loop */ - - if ((tn-tout)*h >= ZERO) { - /* - output_msg(OUTPUT_CVODE, "*tn %e, t0 %e, tout %e, h %e\n", tn, t0, tout,h); - */ - cvode_rate_sim_time = cvode_rate_sim_time_start + tout; - cvode_step_fraction = 1.0; - istate = SUCCESS; - *t = tout; - (void) CVodeDky(cv_mem, tout, 0, yout); - next_q = qprime; - next_h = hprime; - break; - } - } - - /* End of step loop; load optional outputs and return */ - - if (iopt != NULL) { - iopt[NST] = nst; - iopt[NFE] = nfe; - iopt[NSETUPS] = nsetups; - iopt[NNI] = nni; - iopt[NCFN] = ncfn; - iopt[NETF] = netf; - iopt[QU] = q; - iopt[QCUR] = next_q; - } - - if (ropt != NULL) { - ropt[HU] = h; - ropt[HCUR] = next_h; - ropt[TCUR] = tn; - ropt[TOLSF] = tolsf; - } -#ifdef DEBUG_CVODE - /* - * check interpolation - */ - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"End of cvode, Interpolated y Fail\n"); - return(-1); - } else { - output_msg(OUTPUT_CVODE,"End of cvode, Interpolated y OK\n"); - } -#endif - return(istate); -} - -/*************** CVodeDky ******************************************** - - This routine computes the k-th derivative of the interpolating - polynomial at the time t and stores the result in the vector dky. - The formula is: - q - dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] , - j=k - where c(j,k) = j*(j-1)*...*(j-k+1), q is the current order, and - zn[j] is the j-th column of the Nordsieck history array. - - This function is called by CVode with k = 0 and t = tout, but - may also be called directly by the user. - -**********************************************************************/ - -int CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky) -{ - realtype s, c, r; - realtype tfuzz, tp, tn1; - int i, j; - CVodeMem cv_mem; - - cv_mem = (CVodeMem) cvode_mem; - - /* Check all inputs for legality */ - - if (cvode_mem == NULL) { - output_msg(OUTPUT_CVODE, MSG_DKY_NO_MEM); - return(DKY_NO_MEM); - } - - if (dky == NULL) { - output_msg(OUTPUT_CVODE, MSG_BAD_DKY); - return(BAD_DKY); - } - - if ((k < 0) || (k > q)) { - output_msg(OUTPUT_CVODE, MSG_BAD_K, k); - return(BAD_K); - } - - tfuzz = FUZZ_FACTOR * uround * (ABS(tn) + ABS(hu)); - if (hu < ZERO) tfuzz = -tfuzz; - tp = tn - hu - tfuzz; - tn1 = tn + tfuzz; - if ((t-tp)*(t-tn1) > ZERO) { - output_msg(OUTPUT_CVODE, MSG_BAD_T, (double) t, (double) (tn-hu), (double) tn); - return(BAD_T); - } - - /* Sum the differentiated interpolating polynomial */ - - s = (t - tn) / h; - for (j=q; j >= k; j--) { - c = ONE; - for (i=j; i >= j-k+1; i--) c *= i; - if (j == q) { - N_VScale(c, zn[q], dky); - } else { - N_VLinearSum(c, zn[j], s, dky, dky); - } - } - if (k == 0) return(OKAY); - r = RPowerI(h,-k); - N_VScale(r, dky, dky); - return(OKAY); -} - -/********************* CVodeFree ********************************** - - This routine frees the problem memory allocated by CVodeMalloc. - Such memory includes all the vectors allocated by CVAllocVectors, - and the memory lmem for the linear solver (deallocated by a call - to lfree). - -*******************************************************************/ - -void CVodeFree(void *cvode_mem) -{ - CVodeMem cv_mem; - - cv_mem = (CVodeMem) cvode_mem; - - if (cvode_mem == NULL) return; - - CVFreeVectors(cv_mem, qmax); - if (iter == NEWTON) lfree(cv_mem); - free(cv_mem); -} - - -/***************************************************************/ -/********** END Exported Functions Implementation **************/ -/***************************************************************/ - - -/*******************************************************************/ -/******** BEGIN Private Helper Functions Implementation ************/ -/*******************************************************************/ - -/****************** CVAllocVectors *********************************** - - This routine allocates the CVODE vectors ewt, acor, tempv, ftemp, and - zn[0], ..., zn[maxord]. The length of the vectors is the input - parameter neq and the maximum order (needed to allocate zn) is the - input parameter maxord. If all memory allocations are successful, - CVAllocVectors returns TRUE. Otherwise all allocated memory is freed - and CVAllocVectors returns FALSE. - This routine also sets the optional outputs lrw and liw, which are - (respectively) the lengths of the real and integer work spaces - allocated here. - -**********************************************************************/ - -static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq, - int maxord, M_Env machEnv) -{ - int i, j; - - /* Allocate ewt, acor, tempv, ftemp */ - - ewt = N_VNew(neq, machEnv); - if (ewt == NULL) return(FALSE); - acor = N_VNew(neq, machEnv); - if (acor == NULL) { - N_VFree(ewt); - return(FALSE); - } - tempv = N_VNew(neq, machEnv); - if (tempv == NULL) { - N_VFree(ewt); - N_VFree(acor); - return(FALSE); - } - ftemp = N_VNew(neq, machEnv); - if (ftemp == NULL) { - N_VFree(tempv); - N_VFree(ewt); - N_VFree(acor); - return(FALSE); - } - - /* Allocate zn[0] ... zn[maxord] */ - - for (j=0; j <= maxord; j++) { - zn[j] = N_VNew(neq, machEnv); - if (zn[j] == NULL) { - N_VFree(ewt); - N_VFree(acor); - N_VFree(tempv); - N_VFree(ftemp); - for (i=0; i < j; i++) N_VFree(zn[i]); - return(FALSE); - } - } - - /* Set solver workspace lengths */ - - lrw = (maxord + 5)*neq; - liw = 0; - - return(TRUE); -} - -/***************** CVFreeVectors ********************************* - - This routine frees the CVODE vectors allocated in CVAllocVectors. - -******************************************************************/ - -static void CVFreeVectors(CVodeMem cv_mem, int maxord) -{ - int j; - - N_VFree(ewt); - N_VFree(acor); - N_VFree(tempv); - N_VFree(ftemp); - for(j=0; j <= maxord; j++) N_VFree(zn[j]); -} - -/*********************** CVEwtSet ************************************** - - This routine is responsible for setting the error weight vector ewt, - according to tol_type, as follows: - - (1) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + *abstol), i=0,...,neq-1 - if tol_type = SS - (2) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + abstol[i]), i=0,...,neq-1 - if tol_type = SV - - CVEwtSet returns TRUE if ewt is successfully set as above to a - positive vector and FALSE otherwise. In the latter case, ewt is - considered undefined after the FALSE return from CVEwtSet. - - All the real work is done in the routines CVEwtSetSS, CVEwtSetSV. - -***********************************************************************/ - -static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur) -{ - switch(itol) { - case SS: return(CVEwtSetSS(cv_mem, ycur)); - case SV: return(CVEwtSetSV(cv_mem, ycur)); - } - return(-99); -} - -/*********************** CVEwtSetSS ********************************* - - This routine sets ewt as decribed above in the case tol_type = SS. - It tests for non-positive components before inverting. CVEwtSetSS - returns TRUE if ewt is successfully set to a positive vector - and FALSE otherwise. In the latter case, ewt is considered - undefined after the FALSE return from CVEwtSetSS. - -********************************************************************/ - -static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur) -{ - realtype rtoli, atoli; - - rtoli = *reltol; - atoli = *((realtype *)abstol); - N_VAbs(ycur, tempv); - N_VScale(rtoli, tempv, tempv); - N_VAddConst(tempv, atoli, tempv); - if (N_VMin(tempv) <= ZERO) return(FALSE); - N_VInv(tempv, ewt); - return(TRUE); -} - -/*********************** CVEwtSetSV ********************************* - - This routine sets ewt as decribed above in the case tol_type = SV. - It tests for non-positive components before inverting. CVEwtSetSV - returns TRUE if ewt is successfully set to a positive vector - and FALSE otherwise. In the latter case, ewt is considered - undefined after the FALSE return from CVEwtSetSV. - -********************************************************************/ - -static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur) -{ - realtype rtoli; - rtoli = *reltol; - N_VAbs(ycur, tempv); - N_VLinearSum(rtoli, tempv, ONE, (N_Vector) abstol, tempv); - if (N_VMin(tempv) <= ZERO) return(FALSE); - N_VInv(tempv, ewt); - return(TRUE); -} - -/******************* CVHin *************************************** - - This routine computes a tentative initial step size h0. - If tout is too close to tn (= t0), then CVHin returns FALSE and - h remains uninitialized. Otherwise, CVHin sets h to the chosen - value h0 and returns TRUE. - - The algorithm used seeks to find h0 as a solution of - (WRMS norm of (h0^2 ydd / 2)) = 1, - where ydd = estimated second derivative of y. - -*****************************************************************/ - -static booleantype CVHin(CVodeMem cv_mem, realtype tout) -{ - int sign, count; - realtype tdiff, tdist, tround, hlb, hub; - realtype hg, hgs, hnew, hrat, h0, yddnrm; - - /* Test for tout too close to tn */ - - if ((tdiff = tout-tn) == ZERO) return(FALSE); - - sign = (tdiff > ZERO) ? 1 : -1; - tdist = ABS(tdiff); - tround = uround * MAX(ABS(tn), ABS(tout)); - if (tdist < TWO*tround) return(FALSE); - - /* Set lower and upper bounds on h0, and take geometric mean - Exit with this value if the bounds cross each other */ - - hlb = HLB_FACTOR * tround; - hub = CVUpperBoundH0(cv_mem, tdist); - hg = RSqrt(hlb*hub); - if (hub < hlb) { - if (sign == -1) hg = -hg; - h = hg; - return(TRUE); - } - - /* Loop up to MAX_ITERS times to find h0. - Stop if new and previous values differ by a factor < 2. - Stop if hnew/hg > 2 after one iteration, as this probably means - that the ydd value is bad because of cancellation error. */ - - count = 0; - loop { - hgs = hg*sign; - yddnrm = CVYddNorm(cv_mem, hgs); - if (cvode_error == TRUE) { - hg /= 2.; -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE, "halving step in CVHin\n"); -#endif - continue; - } - - hnew = (yddnrm*hub*hub > TWO) ? RSqrt(TWO/yddnrm) : RSqrt(hg*hub); - count++; - if (count >= MAX_ITERS) break; - hrat = hnew/hg; - if ((hrat > HALF) && (hrat < TWO)) break; - if ((count >= 2) && (hrat > TWO)) { - hnew = hg; - break; - } - hg = hnew; - } - - /* Apply bounds, bias factor, and attach sign */ - - h0 = H_BIAS*hnew; - if (h0 < hlb) h0 = hlb; - if (h0 > hub) h0 = hub; - if (sign == -1) h0 = -h0; - h = h0; - return(TRUE); -} - -/******************** CVUpperBoundH0 ****************************** - - This routine sets an upper bound on abs(h0) based on - tdist = abs(tout - t0) and the values of y[i]/y'[i]. - -******************************************************************/ - -static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist) -{ - realtype atoli, hub_inv, hub; - booleantype vectorAtol; - N_Vector temp1, temp2; - - atoli = 0; - vectorAtol = (itol == SV); - if (!vectorAtol) atoli = *((realtype *) abstol); - temp1 = tempv; - temp2 = acor; - N_VAbs(zn[0], temp1); - N_VAbs(zn[1], temp2); - if (vectorAtol) { - N_VLinearSum(HUB_FACTOR, temp1, ONE, (N_Vector)abstol, temp1); - } else { - N_VScale(HUB_FACTOR, temp1, temp1); - N_VAddConst(temp1, atoli, temp1); - } - N_VDiv(temp2, temp1, temp1); - hub_inv = N_VMaxNorm(temp1); - hub = HUB_FACTOR*tdist; - if (hub*hub_inv > ONE) hub = ONE/hub_inv; - return(hub); -} - -/****************** CVYddNorm ************************************* - - This routine computes an estimate of the second derivative of y - using a difference quotient, and returns its WRMS norm. - -******************************************************************/ - -static realtype CVYddNorm(CVodeMem cv_mem, realtype hg) -{ - realtype yddnrm; - - N_VLinearSum(hg, zn[1], ONE, zn[0], y); - f(N, tn+hg, y, tempv, f_data); -#ifdef DEBUG_CVODE - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"CVYddNorm error\n"); - } -#endif - nfe++; - N_VLinearSum(ONE, tempv, -ONE, zn[1], tempv); - N_VScale(ONE/hg, tempv, tempv); - - yddnrm = N_VWrmsNorm(tempv, ewt); - return(yddnrm); -} - -/********************* CVStep ************************************** - - This routine performs one internal cvode step, from tn to tn + h. - It calls other routines to do all the work. - - The main operations done here are as follows: - * preliminary adjustments if a new step size was chosen; - * prediction of the Nordsieck history array zn at tn + h; - * setting of multistep method coefficients and test quantities; - * solution of the nonlinear system; - * testing the local error; - * updating zn and other state data if successful; - * resetting stepsize and order for the next step. - * if SLDET is on, check for stability, reduce order if necessary. - On a failure in the nonlinear system solution or error test, the - step may be reattempted, depending on the nature of the failure. - -********************************************************************/ - -static int CVStep(CVodeMem cv_mem) -{ - realtype saved_t, dsm; - int ncf, nef, nflag; - booleantype passed; - - int kflag; - - saved_t = tn; - ncf = nef = 0; - nflag = FIRST_CALL; - - - if ((nst > 0) && (hprime != h)) CVAdjustParams(cv_mem); - - /* Looping point for attempts to take a step */ - loop { - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"Before predict, y Fail, time %e\n", tn); -#endif - } else { - cvode_prev_good_time = cvode_last_good_time; - N_VScale(1.0, cvode_last_good_y, cvode_prev_good_y); - cvode_last_good_time = tn; - N_VScale(1.0, y, cvode_last_good_y); -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"Before predict, y OK, time %e\n", tn); -#endif - } -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"Before predict, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"Before predict, zn OK\n"); - } - saved_t = tn; -#endif - CVPredict(cv_mem); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After predict, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After predict, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After predict, zn Fail\n"); - - } else { - output_msg(OUTPUT_CVODE,"After predict, zn OK\n"); - } -#endif - CVSet(cv_mem); - - nflag = CVnls(cv_mem, nflag); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After CVnls, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After CVnls, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After CVnls, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After CVnls, zn OK\n"); - } -#endif - kflag = CVHandleNFlag(cv_mem, &nflag, saved_t, &ncf); - if (kflag == PREDICT_AGAIN) continue; - if (kflag != DO_ERROR_TEST) return(kflag); - /* Return if nonlinear solve failed and recovery not possible. */ -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"Before error test, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"Before error test, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"Before error test, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"Before error test, zn OK\n"); - } -#endif - passed = CVDoErrorTest(cv_mem, &nflag, &kflag, saved_t, &nef, &dsm); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After error test, y Fail, passed %d\n", passed); - } else { - output_msg(OUTPUT_CVODE,"After error test, y OK, passed %d\n", passed); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After error test, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After error test, zn OK\n"); - } -#endif - /* Return if error test failed and recovery not possible. */ - if ((!passed) && (kflag == REP_ERR_FAIL)) return(kflag); - if (passed) break; - /* Retry step if error test failed, nflag == PREV_ERR_FAIL */ - } -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE, "Finished step in CVStep\n"); -#endif - /* Nonlinear system solve and error test were both successful. - Update data, and consider change of step and/or order. */ - - - CVCompleteStep(cv_mem); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After complete step, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After complete step, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After complete step, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After complete step, zn OK\n"); - } -#endif - CVPrepareNextStep(cv_mem, dsm); - - /* If Stablilty Limit Detection is turned on, call stability limit - detection routine for possible order reduction. */ - - if (sldeton) CVBDFStab(cv_mem); -#ifdef DEBUG_CVODE - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After cvbfdstab, y Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After cvbfdstab, y OK\n"); - } - cvode_test = TRUE; - f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"After cvbfdstab, zn Fail\n"); - } else { - output_msg(OUTPUT_CVODE,"After cvbfdstab, zn OK\n"); - } -#endif - etamax = (nst <= SMALL_NST) ? ETAMX2 : ETAMX3; - - /* Finally, we rescale the acor array to be the - estimated local error vector. */ - - N_VScale(ONE/tq[2], acor, acor); - return(SUCCESS_STEP); - -} - - -/********************* CVAdjustParams ******************************** - - This routine is called when a change in step size was decided upon, - and it handles the required adjustments to the history array zn. - If there is to be a change in order, we call CVAdjustOrder and reset - q, L = q+1, and qwait. Then in any case, we call CVRescale, which - resets h and rescales the Nordsieck array. - -**********************************************************************/ - -static void CVAdjustParams(CVodeMem cv_mem) -{ - if (qprime != q) { - CVAdjustOrder(cv_mem, qprime-q); - q = qprime; - L = q+1; - qwait = L; - } - CVRescale(cv_mem); -} - -/********************* CVAdjustOrder ***************************** - - This routine is a high level routine which handles an order - change by an amount deltaq (= +1 or -1). If a decrease in order - is requested and q==2, then the routine returns immediately. - Otherwise CVAdjustAdams or CVAdjustBDF is called to handle the - order change (depending on the value of lmm). - -******************************************************************/ - -static void CVAdjustOrder(CVodeMem cv_mem, int deltaq) -{ - if ((q==2) && (deltaq != 1)) return; - - switch(lmm){ - case ADAMS: CVAdjustAdams(cv_mem, deltaq); - break; - case BDF: CVAdjustBDF(cv_mem, deltaq); - break; - } -} - -/*************** CVAdjustAdams *********************************** - - This routine adjusts the history array on a change of order q by - deltaq, in the case that lmm == ADAMS. - -*****************************************************************/ - -static void CVAdjustAdams(CVodeMem cv_mem, int deltaq) -{ - int i, j; - realtype xi, hsum; - - /* On an order increase, set new column of zn to zero and return */ - - if (deltaq==1) { - N_VConst(ZERO, zn[L]); - return; - } - - /* On an order decrease, each zn[j] is adjusted by a multiple - of zn[q]. The coefficients in the adjustment are the - coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_j), - integrated, where xi_j = [t_n - t_(n-j)]/h. */ - - for (i=0; i <= qmax; i++) l[i] = ZERO; - l[1] = ONE; - hsum = ZERO; - for (j=1; j <= q-2; j++) { - hsum += tau[j]; - xi = hsum / hscale; - for (i=j+1; i >= 1; i--) l[i] = l[i]*xi + l[i-1]; - } - - for (j=1; j <= q-2; j++) l[j+1] = q * (l[j] / (j+1)); - - for (j=2; j < q; j++) - N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); -} - -/********************** CVAdjustBDF ******************************* - - This is a high level routine which handles adjustments to the - history array on a change of order by deltaq in the case that - lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and - CVDecreaseBDF if deltaq = -1 to do the actual work. - -******************************************************************/ - -static void CVAdjustBDF(CVodeMem cv_mem, int deltaq) -{ - switch(deltaq) { - case 1 : CVIncreaseBDF(cv_mem); - return; - case -1: CVDecreaseBDF(cv_mem); - return; - } -} - -/******************** CVIncreaseBDF ********************************** - - This routine adjusts the history array on an increase in the - order q in the case that lmm == BDF. - A new column zn[q+1] is set equal to a multiple of the saved - vector (= acor) in zn[qmax]. Then each zn[j] is adjusted by - a multiple of zn[q+1]. The coefficients in the adjustment are the - coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-1)), - where xi_j = [t_n - t_(n-j)]/h. - -*********************************************************************/ - -static void CVIncreaseBDF(CVodeMem cv_mem) -{ - realtype alpha0, alpha1, prod, xi, xiold, hsum, A1; - int i, j; - - for (i=0; i <= qmax; i++) l[i] = ZERO; - l[2] = alpha1 = prod = xiold = ONE; - alpha0 = -ONE; - hsum = hscale; - if (q > 1) { - for (j=1; j < q; j++) { - hsum += tau[j+1]; - xi = hsum / hscale; - prod *= xi; - alpha0 -= ONE / (j+1); - alpha1 += ONE / xi; - for (i=j+2; i >= 2; i--) l[i] = l[i]*xiold + l[i-1]; - xiold = xi; - } - } - A1 = (-alpha0 - alpha1) / prod; - N_VScale(A1, zn[qmax], zn[L]); - for (j=2; j <= q; j++) { - N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); - } -} - -/********************* CVDecreaseBDF ****************************** - - This routine adjusts the history array on a decrease in the - order q in the case that lmm == BDF. - Each zn[j] is adjusted by a multiple of zn[q]. The coefficients - in the adjustment are the coefficients of the polynomial - x*x*(x+xi_1)*...*(x+xi_(q-2)), where xi_j = [t_n - t_(n-j)]/h. - -******************************************************************/ - -static void CVDecreaseBDF(CVodeMem cv_mem) -{ - realtype hsum, xi; - int i, j; - - for (i=0; i <= qmax; i++) l[i] = ZERO; - l[2] = ONE; - hsum = ZERO; - for(j=1; j <= q-2; j++) { - hsum += tau[j]; - xi = hsum /hscale; - for (i=j+2; i >= 2; i--) l[i] = l[i]*xi + l[i-1]; - } - - for(j=2; j < q; j++) - N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); -} - -/**************** CVRescale *********************************** - - This routine rescales the Nordsieck array by multiplying the - jth column zn[j] by eta^j, j = 1, ..., q. Then the value of - h is rescaled by eta, and hscale is reset to h. - -***************************************************************/ - -static void CVRescale(CVodeMem cv_mem) -{ - int j; - realtype factor; - - factor = eta; - for (j=1; j <= q; j++) { - N_VScale(factor, zn[j], zn[j]); - factor *= eta; - } - h = hscale * eta; - hscale = h; - nscon = 0; -} - -/********************* CVPredict ************************************* - - This routine advances tn by the tentative step size h, and computes - the predicted array z_n(0), which is overwritten on zn. The - prediction of zn is done by repeated additions. - -*********************************************************************/ - -static void CVPredict(CVodeMem cv_mem) -{ - int j, k; - - tn += h; - for (k = 1; k <= q; k++) - for (j = q; j >= k; j--) - N_VLinearSum(ONE, zn[j-1], ONE, zn[j], zn[j-1]); -} - -/************************** CVSet ********************************* - - This routine is a high level routine which calls CVSetAdams or - CVSetBDF to set the polynomial l, the test quantity array tq, - and the related variables rl1, gamma, and gamrat. - -******************************************************************/ - -static void CVSet(CVodeMem cv_mem) -{ - switch(lmm) { - case ADAMS: CVSetAdams(cv_mem); - break; - case BDF : CVSetBDF(cv_mem); - break; - } - rl1 = ONE / l[1]; - gamma = h * rl1; - if (nst == 0) gammap = gamma; - gamrat = (nst > 0) ? gamma / gammap : ONE; /* protect x / x != 1.0 */ -} - -/******************** CVSetAdams ********************************* - - This routine handles the computation of l and tq for the - case lmm == ADAMS. - - The components of the array l are the coefficients of a - polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by - q-1 - (d/dx) Lambda(x) = c * PRODUCT (1 + x / xi_i) , where - i=1 - Lambda(-1) = 0, Lambda(0) = 1, and c is a normalization factor. - Here xi_i = [t_n - t_(n-i)] / h. - - The array tq is set to test quantities used in the convergence - test, the error test, and the selection of h at a new order. - -*****************************************************************/ - -static void CVSetAdams(CVodeMem cv_mem) -{ - realtype m[L_MAX], M[3], hsum; - - if (q == 1) { - l[0] = l[1] = tq[1] = tq[5] = ONE; - tq[2] = TWO; - tq[3] = TWELVE; - tq[4] = CORTES * tq[2]; /* = 0.1 * tq[2] */ - return; - } - - hsum = CVAdamsStart(cv_mem, m); - - M[0] = CVAltSum(q-1, m, 1); - M[1] = CVAltSum(q-1, m, 2); - - CVAdamsFinish(cv_mem, m, M, hsum); -} - -/****************** CVAdamsStart ******************************** - - This routine generates in m[] the coefficients of the product - polynomial needed for the Adams l and tq coefficients for q > 1. - -******************************************************************/ - -static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]) -{ - realtype hsum, xi_inv, sum; - int i, j; - - hsum = h; - m[0] = ONE; - for (i=1; i <= q; i++) m[i] = ZERO; - for (j=1; j < q; j++) { - if ((j==q-1) && (qwait == 1)) { - sum = CVAltSum(q-2, m, 2); - tq[1] = m[q-2] / (q * sum); - } - xi_inv = h / hsum; - for (i=j; i >= 1; i--) m[i] += m[i-1] * xi_inv; - hsum += tau[j]; - /* The m[i] are coefficients of product(1 to j) (1 + x/xi_i) */ - } - return(hsum); -} - -/****************** CVAdamsFinish ******************************* - - This routine completes the calculation of the Adams l and tq. - -******************************************************************/ - -static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], - realtype hsum) -{ - int i; - realtype M0_inv, xi, xi_inv; - - M0_inv = ONE / M[0]; - - l[0] = ONE; - for (i=1; i <= q; i++) l[i] = M0_inv * (m[i-1] / i); - xi = hsum / h; - xi_inv = ONE / xi; - - tq[2] = xi * M[0] / M[1]; - tq[5] = xi / l[q]; - - if (qwait == 1) { - for (i=q; i >= 1; i--) m[i] += m[i-1] * xi_inv; - M[2] = CVAltSum(q, m, 2); - tq[3] = L * M[0] / M[2]; - } - - tq[4] = CORTES * tq[2]; -} - -/****************** CVAltSum ************************************** - - CVAltSum returns the value of the alternating sum - sum (i= 0 ... iend) [ (-1)^i * (a[i] / (i + k)) ]. - If iend < 0 then CVAltSum returns 0. - This operation is needed to compute the integral, from -1 to 0, - of a polynomial x^(k-1) M(x) given the coefficients of M(x). - -******************************************************************/ - -static realtype CVAltSum(int iend, realtype a[], int k) -{ - int i, sign; - realtype sum; - - if (iend < 0) return(ZERO); - - sum = ZERO; - sign = 1; - for (i=0; i <= iend; i++) { - sum += sign * (a[i] / (i+k)); - sign = -sign; - } - return(sum); -} - -/***************** CVSetBDF ************************************** - - This routine computes the coefficients l and tq in the case - lmm == BDF. CVSetBDF calls CVSetTqBDF to set the test - quantity array tq. - - The components of the array l are the coefficients of a - polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by - q-1 - Lambda(x) = (1 + x / xi*_q) * PRODUCT (1 + x / xi_i) , where - i=1 - xi_i = [t_n - t_(n-i)] / h. - - The array tq is set to test quantities used in the convergence - test, the error test, and the selection of h at a new order. - - -*****************************************************************/ - -static void CVSetBDF(CVodeMem cv_mem) -{ - realtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum; - int i,j; - - l[0] = l[1] = xi_inv = xistar_inv = ONE; - for (i=2; i <= q; i++) l[i] = ZERO; - alpha0 = alpha0_hat = -ONE; - hsum = h; - if (q > 1) { - for (j=2; j < q; j++) { - hsum += tau[j-1]; - xi_inv = h / hsum; - alpha0 -= ONE / j; - for(i=j; i >= 1; i--) l[i] += l[i-1]*xi_inv; - /* The l[i] are coefficients of product(1 to j) (1 + x/xi_i) */ - } - - /* j = q */ - alpha0 -= ONE / q; - xistar_inv = -l[1] - alpha0; - hsum += tau[q-1]; - xi_inv = h / hsum; - alpha0_hat = -l[1] - xi_inv; - for (i=q; i >= 1; i--) l[i] += l[i-1]*xistar_inv; - } - - CVSetTqBDF(cv_mem, hsum, alpha0, alpha0_hat, xi_inv, xistar_inv); -} - -/****************** CVSetTqBDF ************************************ - - This routine sets the test quantity array tq when lmm == BDF. - -******************************************************************/ - -static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, - realtype alpha0_hat, realtype xi_inv, realtype xistar_inv) -{ - realtype A1, A2, A3, A4, A5, A6; - realtype C, CPrime, CPrimePrime; - - A1 = ONE - alpha0_hat + alpha0; - A2 = ONE + q * A1; - tq[2] = ABS(alpha0 * (A2 / A1)); - tq[5] = ABS((A2) / (l[q] * xi_inv/xistar_inv)); - if (qwait == 1) { - C = xistar_inv / l[q]; - A3 = alpha0 + ONE / q; - A4 = alpha0_hat + xi_inv; - CPrime = A3 / (ONE - A4 + A3); - tq[1] = ABS(CPrime / C); - hsum += tau[q]; - xi_inv = h / hsum; - A5 = alpha0 - (ONE / (q+1)); - A6 = alpha0_hat - xi_inv; - CPrimePrime = A2 / (ONE - A6 + A5); - tq[3] = ABS(CPrimePrime * xi_inv * (q+2) * A5); - } - tq[4] = CORTES * tq[2]; -} - -/****************** CVnls ***************************************** - - This routine attempts to solve the nonlinear system associated - with a single implicit step of the linear multistep method. - Depending on iter, it calls CVnlsFunctional or CVnlsNewton - to do the work. - -******************************************************************/ - -static int CVnls(CVodeMem cv_mem, int nflag) -{ - switch(iter) { - case FUNCTIONAL : return(CVnlsFunctional(cv_mem)); - case NEWTON : return(CVnlsNewton(cv_mem, nflag)); - } - return(-99); -} - -/***************** CVnlsFunctional ******************************** - - This routine attempts to solve the nonlinear system using - functional iteration (no matrices involved). - -******************************************************************/ - -static int CVnlsFunctional(CVodeMem cv_mem) -{ - int m; - realtype del, delp, dcon; - - /* Initialize counter and evaluate f at predicted y */ - - delp = 0; - crate = ONE; - m = 0; - f(N, tn, zn[0], tempv, f_data); - nfe++; - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsFunctional, Fail at beginning\n"); -#endif - return(CONV_FAIL); - } else { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsFunctional, OK at beginning\n"); -#endif - } - N_VConst(ZERO, acor); - - /* Loop until convergence; accumulate corrections in acor */ - - loop { - /* Correct y directly from the last f value */ - N_VLinearSum(h, tempv, -ONE, zn[1], tempv); - N_VScale(rl1, tempv, tempv); - N_VLinearSum(ONE, zn[0], ONE, tempv, y); - /* Get WRMS norm of current correction to use in convergence test */ - N_VLinearSum(ONE, tempv, -ONE, acor, acor); - del = N_VWrmsNorm(acor, ewt); - N_VScale(ONE, tempv, acor); - - /* Test for convergence. If m > 0, an estimate of the convergence - rate constant is stored in crate, and used in the test. */ - if (m > 0) crate = MAX(CRDOWN * crate, del / delp); - dcon = del * MIN(ONE, crate) / tq[4]; - if (dcon <= ONE) { - acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt); - return(SOLVED); /* Convergence achieved */ - } - - /* Stop at maxcor iterations or if iter. seems to be diverging */ - m++; - if ((m==maxcor) || ((m >= 2) && (del > RDIV * delp))) - return(CONV_FAIL); - /* Save norm of correction, evaluate f, and loop again */ - delp = del; - f(N, tn, y, tempv, f_data); - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsFunctional, Fail at end\n"); -#endif - return(CONV_FAIL); - } else { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsFunctional, OK at end\n"); -#endif - } - nfe++; - } -} - -/*********************** CVnlsNewton ********************************** - - This routine handles the Newton iteration. It calls lsetup if - indicated, calls CVNewtonIteration to perform the iteration, and - retries a failed attempt at Newton iteration if that is indicated. - See return values at top of this file. - -**********************************************************************/ - -static int CVnlsNewton(CVodeMem cv_mem, int nflag) -{ - N_Vector vtemp1, vtemp2, vtemp3; - int convfail, ier; - booleantype callSetup; - - vtemp1 = acor; /* rename acor as vtemp1 for readability */ - vtemp2 = y; /* rename y as vtemp2 for readability */ - vtemp3 = tempv; /* rename tempv as vtemp3 for readability */ - - /* Set flag convfail, input to lsetup for its evaluation decision */ - convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) ? - NO_FAILURES : FAIL_OTHER; - - /* Decide whether or not to call setup routine (if one exists) */ - if (setupNonNull) { - callSetup = (nflag == PREV_CONV_FAIL) || (nflag == PREV_ERR_FAIL) || - (nst == 0) || (nst >= nstlp + MSBP) || (ABS(gamrat-ONE) > DGMAX); - } else { - crate = ONE; - callSetup = FALSE; - } - - /* Looping point for the solution of the nonlinear system. - Evaluate f at the predicted y, call lsetup if indicated, and - call CVNewtonIteration for the Newton iteration itself. */ - - loop { - - f(N, tn, zn[0], ftemp, f_data); - - nfe++; - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsNewton, start of loop, time %e\n", tn); -#endif - return (CONV_FAIL); - } else { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsNewton, OK, start of loop, time %e\n", tn); -#endif - } - - if (callSetup) { - ier = lsetup(cv_mem, convfail, zn[0], ftemp, &jcur, - vtemp1, vtemp2, vtemp3); - nsetups++; - callSetup = FALSE; - gamrat = crate = ONE; - gammap = gamma; - nstlp = nst; - /* Return if lsetup failed */ - if (ier < 0) return(SETUP_FAIL_UNREC); - if (ier > 0) return(CONV_FAIL); - } - - /* Set acor to zero and load prediction into y vector */ - N_VConst(ZERO, acor); - N_VScale(ONE, zn[0], y); - - /* Do the Newton iteration */ - ier = CVNewtonIteration(cv_mem); - - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"After CVNewtonIteration, Fail, ier %d\n", ier); -#endif - return(CONV_FAIL); - } else { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"After CVNewtonIteration, OK, ier %d\n", ier); -#endif - } - /* If there is a convergence failure and the Jacobian-related - data appears not to be current, loop again with a call to lsetup - in which convfail=FAIL_BAD_J. Otherwise return. */ - if (ier != TRY_AGAIN) return(ier); - callSetup = TRUE; - convfail = FAIL_BAD_J; - } -} - -/********************** CVNewtonIteration **************************** - - This routine performs the Newton iteration. If the iteration succeeds, - it returns the value SOLVED. If not, it may signal the CVnlsNewton - routine to call lsetup again and reattempt the iteration, by - returning the value TRY_AGAIN. (In this case, CVnlsNewton must set - convfail to FAIL_BAD_J before calling setup again). - Otherwise, this routine returns one of the appropriate values - SOLVE_FAIL_UNREC or CONV_FAIL back to CVnlsNewton. - -*********************************************************************/ - -static int CVNewtonIteration(CVodeMem cv_mem) -{ - int m, ret; - realtype del, delp, dcon; - N_Vector b; - - - mnewt = m = 0; - delp = 0; - - /* Looping point for Newton iteration */ - loop { - - /* Evaluate the residual of the nonlinear system*/ - N_VLinearSum(rl1, zn[1], ONE, acor, tempv); - N_VLinearSum(gamma, ftemp, -ONE, tempv, tempv); - - /* Call the lsolve function */ - b = tempv; - ret = lsolve(cv_mem, b, y, ftemp); - nni++; - - if (ret < 0) return(SOLVE_FAIL_UNREC); - - /* If lsolve had a recoverable failure and Jacobian data is - not current, signal to try the solution again */ - if (ret > 0) { - if ((!jcur) && (setupNonNull)) return(TRY_AGAIN); - return(CONV_FAIL); - } - /* Get WRMS norm of correction; add correction to acor and y */ - del = N_VWrmsNorm(b, ewt); - N_VLinearSum(ONE, acor, ONE, b, acor); - N_VLinearSum(ONE, zn[0], ONE, acor, y); - - /* Test for convergence. If m > 0, an estimate of the convergence - rate constant is stored in crate, and used in the test. */ - if (m > 0) { - crate = MAX(CRDOWN * crate, del/delp); - } - dcon = del * MIN(ONE, crate) / tq[4]; - -#ifdef DEBUG_CVODE - /* added before SOLVED */ - cvode_test = TRUE; - f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE,"CVnlsNewton, Fail at SOLVED\n"); - return(CONV_FAIL); - } else { - output_msg(OUTPUT_CVODE,"CVnlsNewton, OK at SOLVED\n"); - } -#endif - if (dcon <= ONE) { - acnrm = (m==0) ? del : N_VWrmsNorm(acor, ewt); - jcur = FALSE; - return(SOLVED); /* Nonlinear system was solved successfully */ - } - - mnewt = ++m; - - /* Stop at maxcor iterations or if iter. seems to be diverging. - If still not converged and Jacobian data is not current, - signal to try the solution again */ - if ((m == maxcor) || ((m >= 2) && (del > RDIV*delp))) { - if ((!jcur) && (setupNonNull)) return(TRY_AGAIN); - return(CONV_FAIL); - } - - /* Save norm of correction, evaluate f, and loop again */ - delp = del; - f(N, tn, y, ftemp, f_data); - - if (cvode_error == TRUE) { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsNewton, Fail at end\n"); -#endif - return(CONV_FAIL); - } else { -#ifdef DEBUG_CVODE - output_msg(OUTPUT_CVODE,"CVnlsNewton, OK at end\n"); -#endif - } - nfe++; - } -} - -/********************** CVHandleNFlag ******************************* - - This routine takes action on the return value nflag = *nflagPtr - returned by CVnls, as follows: - - If CVnls succeeded in solving the nonlinear system, then - CVHandleNFlag returns the constant DO_ERROR_TEST, which tells CVStep - to perform the error test. - - If the nonlinear system was not solved successfully, then ncfn and - ncf = *ncfPtr are incremented and Nordsieck array zn is restored. - - If the solution of the nonlinear system failed due to an - unrecoverable failure by setup, we return the value SETUP_FAILED. - - If it failed due to an unrecoverable failure in solve, then we return - the value SOLVE_FAILED. - - Otherwise, a recoverable failure occurred when solving the - nonlinear system (CVnls returned nflag == CONV_FAIL). - In this case, we return the value REP_CONV_FAIL if ncf is now - equal to MXNCF or |h| = hmin. - If not, we set *nflagPtr = PREV_CONV_FAIL and return the value - PREDICT_AGAIN, telling CVStep to reattempt the step. - -*********************************************************************/ - -static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, - int *ncfPtr) -{ - int nflag; - - nflag = *nflagPtr; - - if (nflag == SOLVED) return(DO_ERROR_TEST); - - /* The nonlinear soln. failed; increment ncfn and restore zn */ - ncfn++; - CVRestore(cv_mem, saved_t); - - /* Return if lsetup or lsolve failed unrecoverably */ - if (nflag == SETUP_FAIL_UNREC) return(SETUP_FAILED); - if (nflag == SOLVE_FAIL_UNREC) return(SOLVE_FAILED); - - /* At this point, nflag == CONV_FAIL; increment ncf */ - - (*ncfPtr)++; - etamax = ONE; - /* If we had MXNCF failures or |h| = hmin, return REP_CONV_FAIL */ - if ((ABS(h) <= hmin*ONEPSM) || (*ncfPtr == MXNCF)) - return(REP_CONV_FAIL); - - /* Reduce step size; return to reattempt the step */ - eta = MAX(ETACF, hmin / ABS(h)); - *nflagPtr = PREV_CONV_FAIL; - CVRescale(cv_mem); - return(PREDICT_AGAIN); -} - -/********************** CVRestore ************************************ - - This routine restores the value of tn to saved_t and undoes the - prediction. After execution of CVRestore, the Nordsieck array zn has - the same values as before the call to CVPredict. - -********************************************************************/ - -static void CVRestore(CVodeMem cv_mem, realtype saved_t) -{ - int j, k; - - tn = saved_t; - for (k = 1; k <= q; k++) - for (j = q; j >= k; j--) - N_VLinearSum(ONE, zn[j-1], -ONE, zn[j], zn[j-1]); -} - -/******************* CVDoErrorTest ******************************** - - This routine performs the local error test. - The weighted local error norm dsm is loaded into *dsmPtr, and - the test dsm ?<= 1 is made. - - If the test passes, CVDoErrorTest returns TRUE. - - If the test fails, we undo the step just taken (call CVRestore), - set *nflagPtr to PREV_ERR_FAIL, and return FALSE. - - If MXNEF error test failures have occurred or if ABS(h) = hmin, - we set *kflagPtr = REP_ERR_FAIL. (Otherwise *kflagPtr has the - value last returned by CVHandleNflag.) - - If more than MXNEF1 error test failures have occurred, an order - reduction is forced. - -******************************************************************/ - -static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, - realtype saved_t, int *nefPtr, realtype *dsmPtr) -{ - realtype dsm; - - dsm = acnrm / tq[2]; - - /* If est. local error norm dsm passes test, return TRUE */ - *dsmPtr = dsm; - if (dsm <= ONE) return(TRUE); - - /* Test failed; increment counters, set nflag, and restore zn array */ - (*nefPtr)++; - netf++; - *nflagPtr = PREV_ERR_FAIL; - CVRestore(cv_mem, saved_t); - - /* At MXNEF failures or |h| = hmin, return with kflag = REP_ERR_FAIL */ - if ((ABS(h) <= hmin*ONEPSM) || (*nefPtr == MXNEF)) { - *kflagPtr = REP_ERR_FAIL; - return(FALSE); - } - - /* Set etamax = 1 to prevent step size increase at end of this step */ - etamax = ONE; - - /* Set h ratio eta from dsm, rescale, and return for retry of step */ - if (*nefPtr <= MXNEF1) { - eta = ONE / (RPowerR(BIAS2*dsm,ONE/L) + ADDON); - eta = MAX(ETAMIN, MAX(eta, hmin / ABS(h))); - if (*nefPtr >= SMALL_NEF) eta = MIN(eta, ETAMXF); - CVRescale(cv_mem); - return(FALSE); - } - - /* After MXNEF1 failures, force an order reduction and retry step */ - if (q > 1) { - eta = MAX(ETAMIN, hmin / ABS(h)); - CVAdjustOrder(cv_mem,-1); - L = q; - q--; - qwait = L; - CVRescale(cv_mem); - return(FALSE); - } - - /* If already at order 1, restart: reload zn from scratch */ - eta = MAX(ETAMIN, hmin / ABS(h)); - h *= eta; - hscale = h; - qwait = LONG_WAIT; - nscon = 0; - f(N, tn, zn[0], tempv, f_data); - if (cvode_error == TRUE) { - output_msg(OUTPUT_CVODE, "CVDoErrorTest"); - /*exit(8);*/ - error_msg("CVDoErrorTest", 1 /* STOP */); - } - nfe++; - N_VScale(h, tempv, zn[1]); - return(FALSE); -} - -/*************** CVCompleteStep ********************************** - - This routine performs various update operations when the solution - to the nonlinear system has passed the local error test. - We increment the step counter nst, record the values hu and qu, - update the tau array, and apply the corrections to the zn array. - The tau[i] are the last q values of h, with tau[1] the most recent. - The counter qwait is decremented, and if qwait == 1 (and q < qmax) - we save acor and tq[5] for a possible order increase. - -******************************************************************/ - -static void CVCompleteStep(CVodeMem cv_mem) -{ - int i, j; - - nst++; - nscon++; - hu = h; - qu = q; - - for (i=q; i >= 2; i--) tau[i] = tau[i-1]; - if ((q==1) && (nst > 1)) tau[2] = tau[1]; - tau[1] = h; - - for (j=0; j <= q; j++) - N_VLinearSum(l[j], acor, ONE, zn[j], zn[j]); - qwait--; - if ((qwait == 1) && (q != qmax)) { - N_VScale(ONE, acor, zn[qmax]); - saved_tq5 = tq[5]; - } -} - -/************* CVPrepareNextStep ********************************** - - This routine handles the setting of stepsize and order for the - next step -- hprime and qprime. Along with hprime, it sets the - ratio eta = hprime/h. It also updates other state variables - related to a change of step size or order. - -******************************************************************/ - - static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm) -{ - /* If etamax = 1, defer step size or order changes */ - if (etamax == ONE) { - qwait = MAX(qwait, 2); - qprime = q; - hprime = h; - eta = ONE; - return; - } - - /* etaq is the ratio of new to old h at the current order */ - etaq = ONE /(RPowerR(BIAS2*dsm,ONE/L) + ADDON); - - /* If no order change, adjust eta and acor in CVSetEta and return */ - if (qwait != 0) { - eta = etaq; - qprime = q; - CVSetEta(cv_mem); - return; - } - - /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are - the ratios of new to old h at orders q-1 and q+1, respectively. - CVChooseEta selects the largest; CVSetEta adjusts eta and acor */ - qwait = 2; - etaqm1 = CVComputeEtaqm1(cv_mem); - etaqp1 = CVComputeEtaqp1(cv_mem); - CVChooseEta(cv_mem); - CVSetEta(cv_mem); -} - -/***************** CVSetEta *************************************** - - This routine adjusts the value of eta according to the various - heuristic limits and the optional input hmax. It also resets - etamax to be the estimated local error vector. - -*******************************************************************/ - -static void CVSetEta(CVodeMem cv_mem) -{ - - /* If eta below the threshhold THRESH, reject a change of step size */ - if (eta < THRESH) { - eta = ONE; - hprime = h; - } else { - /* Limit eta by etamax and hmax, then set hprime */ - eta = MIN(eta, etamax); - eta /= MAX(ONE, ABS(h)*hmax_inv*eta); - hprime = h * eta; - if (qprime < q) nscon = 0; - } - - /* Reset etamax for the next step size change, and scale acor */ -} - -/*************** CVComputeEtaqm1 ********************************** - - This routine computes and returns the value of etaqm1 for a - possible decrease in order by 1. - -******************************************************************/ - -static realtype CVComputeEtaqm1(CVodeMem cv_mem) -{ - realtype ddn; - - etaqm1 = ZERO; - if (q > 1) { - ddn = N_VWrmsNorm(zn[q], ewt) / tq[1]; - etaqm1 = ONE/(RPowerR(BIAS1*ddn, ONE/q) + ADDON); - } - return(etaqm1); -} - -/*************** CVComputeEtaqp1 ********************************** - - This routine computes and returns the value of etaqp1 for a - possible increase in order by 1. - -******************************************************************/ - -static realtype CVComputeEtaqp1(CVodeMem cv_mem) -{ - realtype dup, cquot; - - etaqp1 = ZERO; - if (q != qmax) { - cquot = (tq[5] / saved_tq5) * RPowerI(h/tau[2], L); - N_VLinearSum(-cquot, zn[qmax], ONE, acor, tempv); - dup = N_VWrmsNorm(tempv, ewt) /tq[3]; - etaqp1 = ONE / (RPowerR(BIAS3*dup, ONE/(L+1)) + ADDON); - } - return(etaqp1); -} - -/******************* CVChooseEta ********************************** - - Given etaqm1, etaq, etaqp1 (the values of eta for qprime = - q - 1, q, or q + 1, respectively), this routine chooses the - maximum eta value, sets eta to that value, and sets qprime to the - corresponding value of q. If there is a tie, the preference - order is to (1) keep the same order, then (2) decrease the order, - and finally (3) increase the order. If the maximum eta value - is below the threshhold THRESH, the order is kept unchanged and - eta is set to 1. - -******************************************************************/ - -static void CVChooseEta(CVodeMem cv_mem) -{ - realtype etam; - - etam = MAX(etaqm1, MAX(etaq, etaqp1)); - - if (etam < THRESH) { - eta = ONE; - qprime = q; - return; - } - - if (etam == etaq) { - eta = etaq; - qprime = q; - } else if (etam == etaqm1) { - eta = etaqm1; - qprime = q - 1; - } else { - eta = etaqp1; - qprime = q + 1; - if (lmm == BDF) N_VScale(ONE, acor, zn[qmax]); - } -} - -/****************** CVHandleFailure ****************************** - - This routine prints error messages for all cases of failure by - CVStep. It returns to CVode the value that CVode is to return to - the user. - -*****************************************************************/ - -static int CVHandleFailure(CVodeMem cv_mem, int kflag) -{ - char error_string_long[1000]; - /* Set vector of absolute weighted local errors */ - N_VProd(acor, ewt, tempv); - N_VAbs(tempv, tempv); - - /* Depending on kflag, print error message and return error flag */ - switch (kflag) { - case REP_ERR_FAIL: - sprintf(error_string_long, MSG_ERR_FAILS, (double) tn, (double) h); - warning_msg(error_string_long); - return(ERR_FAILURE); - case REP_CONV_FAIL: - sprintf(error_string_long, MSG_CONV_FAILS, (double) tn, (double) h); - warning_msg(error_string_long); - return(CONV_FAILURE); - case SETUP_FAILED: - sprintf(error_string_long, MSG_SETUP_FAILED, (double) tn); - warning_msg(error_string_long); - return(SETUP_FAILURE); - case SOLVE_FAILED: - sprintf(error_string_long, MSG_SOLVE_FAILED, (double) tn); - warning_msg(error_string_long); - return(SOLVE_FAILURE); - } - return(-99); -} - -/****************** CVBDFStab *********************************** - This routine handles the BDF Stability Limit Detection Algorithm - STALD. It is called if lmm = BDF and the SLDET option is on. - If the order is 3 or more, the required norm data is saved. - If a decision to reduce order has not already been made, and - enough data has been saved, CVsldet is called. If it signals - a stability limit violation, the order is reduced, and the step - size is reset accordingly. - -*****************************************************************/ - -void CVBDFStab(CVodeMem cv_mem) -{ - int i,k, ldflag, factorial; - realtype sq, sqm1, sqm2; - - /* If order is 3 or greater, then save scaled derivative data, - push old data down in i, then add current values to top. */ - - if (q >= 3) { - for (k = 1; k <= 3; k++) - { for (i = 5; i >= 2; i--) ssdat[i][k] = ssdat[i-1][k]; } - factorial = 1; - for (i = 1; i <= q-1; i++) factorial *= i; - sq = factorial*q*(q+1)*acnrm/tq[5]; - sqm1 = factorial*q*N_VWrmsNorm(zn[q], ewt); - sqm2 = factorial*N_VWrmsNorm(zn[q-1], ewt); - ssdat[1][1] = sqm2*sqm2; - ssdat[1][2] = sqm1*sqm1; - ssdat[1][3] = sq*sq; - } - - if (qprime >= q) { - - /* If order is 3 or greater, and enough ssdat has been saved, - nscon >= q+5, then call stability limit detection routine. */ - - if ( (q >= 3) && (nscon >= q+5) ) { - ldflag = CVsldet(cv_mem); - if (ldflag > 3) { - /* A stability limit violation is indicated by - a return flag of 4, 5, or 6. - Reduce new order. */ - qprime = q-1; - eta = etaqm1; - eta = MIN(eta,etamax); - eta = eta/MAX(ONE,ABS(h)*hmax_inv*eta); - hprime = h*eta; - iopt[NOR] =iopt[NOR] + 1; - /* output_msg(OUTPUT_CVODE, - " Order reduced to %d by CVBDFStab at nst = %d,\n h = %e hnew = %e\n", - qprime,nst,h,h*eta); */ - } - } - } - else { - /* Otherwise, let order increase happen, and - reset stability limit counter, nscon. */ - nscon = 0; - } -} - -/********************* CVsldet ************************************ - This routine detects stability limitation using stored scaled - derivatives data. CVsldet returns the magnitude of the - dominate characteristic root, rr. The presents of a stability - limit is indicated by rr > "something a little less then 1.0", - and a positive kflag. This routine should only be called if - order is greater than or equal to 3, and data has been collected - for 5 time steps. - - Returned values: - kflag = 1 -> Found stable characteristic root, normal matrix case - kflag = 2 -> Found stable characteristic root, quartic solution - kflag = 3 -> Found stable characteristic root, quartic solution, - with Newton correction - kflag = 4 -> Found stability violation, normal matrix case - kflag = 5 -> Found stability violation, quartic solution - kflag = 6 -> Found stability violation, quartic solution, - with Newton correction - - kflag < 0 -> No stability limitation, - or could not compute limitation. - - kflag = -1 -> Min/max ratio of ssdat too small. - kflag = -2 -> For normal matrix case, vmax > vrrt2*vrrt2 - kflag = -3 -> For normal matrix case, The three ratios - are inconsistent. - kflag = -4 -> Small coefficient prevents elimination of quartics. - kflag = -5 -> R value from quartics not consistent. - kflag = -6 -> No corrected root passes test on qk values - kflag = -7 -> Trouble solving for sigsq. - kflag = -8 -> Trouble solving for B, or R via B. - kflag = -9 -> R via sigsq[k] disagrees with R from data. - -********************************************************************/ - -static int CVsldet(CVodeMem cv_mem) -{ - integertype i, k, j, it, kmin, kflag = 0; - realtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4]; - realtype drr[4], rrc[4],sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; - realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; - realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; - realtype small, tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; - realtype rsa, rsb, rsc, rsd, rse, rd1a, rd1b, rd1c, rd1d; - realtype rd2a, rd2b, rd2c, rd3a, rd3b, cest1, corr1; - realtype ratp, ratm, qfac1, qfac2, bb, rrb; - - /* The following are cutoffs and tolerances used by this routine */ - - rrcut = 0.98; - vrrtol = 1.0e-4; - vrrt2 = 5.0e-4; - sqtol = 1.0e-3; - rrtol = 1.0e-2; - - rr = ZERO; - - /* Index k corresponds to the degree of the interpolating polynomial. */ - /* k = 1 -> q-1 */ - /* k = 2 -> q */ - /* k = 3 -> q+1 */ - - /* Index i is a backward-in-time index, i = 1 -> current time, */ - /* i = 2 -> previous step, etc */ - - /* get maxima, minima, and variances, and form quartic coefficients */ - - for (k=1; k<=3; k++) { - smink = ssdat[1][k]; - smaxk = ZERO; - - for (i=1; i<=5; i++) { - smink = MIN(smink,ssdat[i][k]); - smaxk = MAX(smaxk,ssdat[i][k]); - } - - if (smink < TINY*smaxk) { - kflag = -1; - return(kflag); - } - smax[k] = smaxk; - ssmax[k] = smaxk*smaxk; - - sumrat = ZERO; - sumrsq = ZERO; - for (i=1; i<=4; i++) { - rat[i][k] = ssdat[i][k]/ssdat[i+1][k]; - sumrat = sumrat + rat[i][k]; - sumrsq = sumrsq + rat[i][k]*rat[i][k]; - } - rav[k] = FOURTH*sumrat; - vrat[k] = ABS(FOURTH*sumrsq - rav[k]*rav[k]); - - qc[5][k] = ssdat[1][k]*ssdat[3][k] - ssdat[2][k]*ssdat[2][k]; - qc[4][k] = ssdat[2][k]*ssdat[3][k] - ssdat[1][k]*ssdat[4][k]; - qc[3][k] = ZERO; - qc[2][k] = ssdat[2][k]*ssdat[5][k] - ssdat[3][k]*ssdat[4][k]; - qc[1][k] = ssdat[4][k]*ssdat[4][k] - ssdat[3][k]*ssdat[5][k]; - - for (i=1; i<=5; i++) { - qco[i][k] = qc[i][k]; - } - } /* End of k loop */ - - /* Isolate normal or nearly-normal matrix case. Three quartic will - have common or nearly-common roots in this case. - Return a kflag = 1 if this procedure works. If three root - differ more than vrrt2, return error kflag = -3. */ - - vmin = MIN(vrat[1],MIN(vrat[2],vrat[3])); - vmax = MAX(vrat[1],MAX(vrat[2],vrat[3])); - - if(vmin < vrrtol*vrrtol) { - if (vmax > vrrt2*vrrt2) { - kflag = -2; - return(kflag); - } else { - rr = (rav[1] + rav[2] + rav[3])/THREE; - - drrmax = ZERO; - for(k = 1;k<=3;k++) { - adrr = ABS(rav[k] - rr); - drrmax = MAX(drrmax, adrr); - } - if (drrmax > vrrt2) { - kflag = -3; - } - - kflag = 1; - - /* can compute charactistic root, drop to next section */ - - } - } else { - - /* use the quartics to get rr. */ - - if (ABS(qco[1][1]) < TINY*ssmax[1]) { - small = qco[1][1]; - kflag = -4; - return(kflag); - } - - tem = qco[1][2]/qco[1][1]; - for(i=2; i<=5; i++) { - qco[i][2] = qco[i][2] - tem*qco[i][1]; - } - - qco[1][2] = ZERO; - tem = qco[1][3]/qco[1][1]; - for(i=2; i<=5; i++) { - qco[i][3] = qco[i][3] - tem*qco[i][1]; - } - qco[1][3] = ZERO; - - if (ABS(qco[2][2]) < TINY*ssmax[2]) { - small = qco[2][2]; - kflag = -4; - return(kflag); - } - - tem = qco[2][3]/qco[2][2]; - for(i=3; i<=5; i++) { - qco[i][3] = qco[i][3] - tem*qco[i][2]; - } - - if (ABS(qco[4][3]) < TINY*ssmax[3]) { - small = qco[4][3]; - kflag = -4; - return(kflag); - } - - rr = -qco[5][3]/qco[4][3]; - - if (rr < TINY || rr > HUN) { - kflag = -5; - return(kflag); - } - - for(k=1; k<=3; k++) { - qkr[k] = qc[5][k] + rr*(qc[4][k] + rr*rr*(qc[2][k] + rr*qc[1][k])); - } - - sqmax = ZERO; - for(k=1; k<=3; k++) { - saqk = ABS(qkr[k])/ssmax[k]; - if (saqk > sqmax) sqmax = saqk; - } - sqmin = sqmax; - if (sqmax < sqtol) { - kflag = 2; - - /* can compute charactistic root, drop to "given rr,etc" */ - - } else { - - /* do Newton corrections to improve rr. */ - - for(it=1; it<=3; it++) { - for(k=1; k<=3; k++) { - qp = qc[4][k] + rr*rr*(THREE*qc[2][k] + rr*FOUR*qc[1][k]); - drr[k] = ZERO; - if (ABS(qp) > TINY*ssmax[k]) drr[k] = -qkr[k]/qp; - rrc[k] = rr + drr[k]; - } - - for(k=1; k<=3; k++) { - s = rrc[k]; - sqmaxk = ZERO; - for(j=1; j<=3; j++) { - qjk[j][k] = qc[5][j] + s*(qc[4][j] + - s*s*(qc[2][j] + s*qc[1][j])); - saqj = ABS(qjk[j][k])/ssmax[j]; - if (saqj > sqmaxk) sqmaxk = saqj; - } - sqmx[k] = sqmaxk; - } - - sqmin = sqmx[1]; kmin = 1; - for(k=2; k<=3; k++) { - if (sqmx[k] < sqmin) { - kmin = k; - sqmin = sqmx[k]; - } - } - rr = rrc[kmin]; - - if (sqmin < sqtol) { - kflag = 3; - /* can compute charactistic root */ - /* break out of Newton correction loop and drop to "given rr,etc" */ - break; - } else { - for(j=1; j<=3; j++) { - qkr[j] = qjk[j][kmin]; - } - } - } /* end of Newton correction loop */ - - if (sqmin > sqtol) { - kflag = -6; - return(kflag); - } - } /* end of if (sqmax < sqtol) else */ - } /* end of if(vmin < vrrtol*vrrtol) else, quartics to get rr. */ - - /* given rr, find sigsq[k] and verify rr. */ - /* All positive kflag drop to this section */ - - for(k=1; k<=3; k++) { - rsa = ssdat[1][k]; - rsb = ssdat[2][k]*rr; - rsc = ssdat[3][k]*rr*rr; - rsd = ssdat[4][k]*rr*rr*rr; - rse = ssdat[5][k]*rr*rr*rr*rr; - rd1a = rsa - rsb; - rd1b = rsb - rsc; - rd1c = rsc - rsd; - rd1d = rsd - rse; - rd2a = rd1a - rd1b; - rd2b = rd1b - rd1c; - rd2c = rd1c - rd1d; - rd3a = rd2a - rd2b; - rd3b = rd2b - rd2c; - - if (ABS(rd1b) < TINY*smax[k]) { - kflag = -7; - return(kflag); - } - - cest1 = -rd3a/rd1b; - if (cest1 < TINY || cest1 > FOUR) { - kflag = -7; - return(kflag); - } - corr1 = (rd2b/cest1)/(rr*rr); - sigsq[k] = ssdat[3][k] + corr1; - } - - if (sigsq[2] < TINY) { - kflag = -8; - return(kflag); - } - - ratp = sigsq[3]/sigsq[2]; - ratm = sigsq[1]/sigsq[2]; - qfac1 = FOURTH*(q*q - ONE); - qfac2 = TWO/(q - ONE); - bb = ratp*ratm - ONE - qfac1*ratp; - tem = ONE - qfac2*bb; - - if (ABS(tem) < TINY) { - kflag = -8; - return(kflag); - } - - rrb = ONE/tem; - - if (ABS(rrb - rr) > rrtol) { - kflag = -9; - return(kflag); - } - - /* Check to see if rr is above cutoff rrcut */ - if (rr > rrcut) { - if (kflag == 1) kflag = 4; - if (kflag == 2) kflag = 5; - if (kflag == 3) kflag = 6; - } - - /* All positive kflag returned at this point */ - - return(kflag); - -} - - -/*******************************************************************/ -/********* END Private Helper Functions Implementation *************/ -/*******************************************************************/ - - -/***************************************************************/ -/************** END CVODE Implementation ***********************/ -/***************************************************************/ diff --git a/dense.cpp b/dense.cpp deleted file mode 100644 index a0648504..00000000 --- a/dense.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************* - * * - * File : dense.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic DENSE linear * - * solver package. * - * * - *******************************************************************/ - -#include -#include -#include "sundialstypes.h" -#include "sundialsmath.h" -#include "dense.h" -#include "smalldense.h" -#include "output.h" -#include "phqalloc.h" -/* WARNING don't include any headers below here */ -#define malloc PHRQ_malloc -static char const svnid[] = "$Id: dense.c 78 2005-02-01 22:47:12Z dlpark $"; - -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) - - -/* Implementation */ - - -DenseMat DenseAllocMat(integertype N) -{ - DenseMat A; - - if (svnid == NULL) fprintf(stderr," "); - if (N <= 0) return(NULL); - - A = (DenseMat) malloc(sizeof *A); - if (A==NULL) return (NULL); - - A->data = denalloc(N); - if (A->data == NULL) { - free(A); - return(NULL); - } - - A->size = N; - - return(A); -} - - -integertype *DenseAllocPiv(integertype N) -{ - if (N <= 0) return(NULL); - - return((integertype *) malloc(N * sizeof(integertype))); -} - - -integertype DenseFactor(DenseMat A, integertype *p) -{ - return(gefa(A->data, A->size, p)); -} - - -void DenseBacksolve(DenseMat A, integertype *p, realtype *b) -{ - gesl(A->data, A->size, p, b); -} - - -void DenseZero(DenseMat A) -{ - denzero(A->data, A->size); -} - -void DenseCopy(DenseMat A, DenseMat B) -{ - dencopy(A->data, B->data, A->size); -} - -void DenseScale(realtype c, DenseMat A) -{ - denscale(c, A->data, A->size); -} - -void DenseAddI(DenseMat A) -{ - denaddI(A->data, A->size); -} - -void DenseFreeMat(DenseMat A) -{ - denfree(A->data); - free(A); -} - -void DenseFreePiv(integertype *p) -{ - free(p); -} - -void DensePrint(DenseMat A) -{ - denprint(A->data, A->size); -} - diff --git a/dense.h b/dense.h deleted file mode 100644 index c2c019c1..00000000 --- a/dense.h +++ /dev/null @@ -1,298 +0,0 @@ -/******************************************************************* - * * - * File : dense.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic DENSE linear solver * - * package. The routines listed in this file all use type * - * DenseMat, defined below, for matrices. These routines in turn * - * call routines in the smalldense.h/smalldense.c module, which * - * use the type realtype** for matrices. This separation allows * - * for possible modifications in which matrices of type DenseMat * - * may not be stored contiguously, while small matrices can still * - * be treated with the routines in smalldense. * - * * - * Routines that work with the type DenseMat begin with "Dense". * - * The DenseAllocMat function allocates a dense matrix for use in * - * the other DenseMat routines listed in this file. Matrix * - * storage details are given in the documentation for the type * - * DenseMat. The DenseAllocPiv function allocates memory for * - * pivot information. The storage allocated by DenseAllocMat and * - * DenseAllocPiv is deallocated by the routines DenseFreeMat and * - * DenseFreePiv, respectively. The DenseFactor and DenseBacksolve * - * routines perform the actual solution of a dense linear system. * - * * - * Routines that work with realtype** begin with "den" (except for * - * the factor and solve routines which are called gefa and gesl, * - * respectively). The underlying matrix storage is described in * - * the documentation for denalloc in smalldense.h * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svniddense[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif -#ifndef _dense_h -#define _dense_h - - -#include "sundialstypes.h" -#include "smalldense.h" - - -/****************************************************************** - * * - * Type: DenseMat * - *----------------------------------------------------------------* - * The type DenseMat is defined to be a pointer to a structure * - * with a size and a data field. The size field indicates the * - * number of columns (== number of rows) of a dense matrix, while * - * the data field is a two dimensional array used for component * - * storage. The elements of a dense matrix are stored columnwise * - * (i.e columns are stored one on top of the other in memory). If * - * A is of type DenseMat, then the (i,j)th element of A (with * - * 0 <= i,j <= size-1) is given by the expression (A->data)[j][i] * - * or by the expression (A->data)[0][j*n+i]. The macros below * - * allow a user to access efficiently individual matrix * - * elements without writing out explicit data structure * - * references and without knowing too much about the underlying * - * element storage. The only storage assumption needed is that * - * elements are stored columnwise and that a pointer to the jth * - * column of elements can be obtained via the DENSE_COL macro. * - * Users should use these macros whenever possible. * - * * - ******************************************************************/ - -typedef struct _DenseMat { - integertype size; - realtype **data; -} *DenseMat; - - -/* DenseMat accessor macros */ - - -/****************************************************************** - * * - * Macro : DENSE_ELEM * - * Usage : DENSE_ELEM(A,i,j) = a_ij; OR * - * a_ij = DENSE_ELEM(A,i,j); * - *----------------------------------------------------------------* - * DENSE_ELEM(A,i,j) references the (i,j)th element of the N by N * - * DenseMat A, 0 <= i,j <= N-1. * - * * - ******************************************************************/ - -#define DENSE_ELEM(A,i,j) ((A->data)[j][i]) - - -/****************************************************************** - * * - * Macro : DENSE_COL * - * Usage : col_j = DENSE_COL(A,j); * - *----------------------------------------------------------------* - * DENSE_COL(A,j) references the jth column of the N by N * - * DenseMat A, 0 <= j <= N-1. The type of the expression * - * DENSE_COL(A,j) is realtype *. After the assignment in the usage* - * above, col_j may be treated as an array indexed from 0 to N-1. * - * The (i,j)th element of A is referenced by col_j[i]. * - * * - ******************************************************************/ - -#define DENSE_COL(A,j) ((A->data)[j]) - - -/* Functions that use the DenseMat representation for a dense matrix */ - - -/****************************************************************** - * * - * Function : DenseAllocMat * - * Usage : A = DenseAllocMat(N); * - * if (A == NULL) ... memory request failed * - *----------------------------------------------------------------* - * DenseAllocMat allocates memory for an N by N dense matrix and * - * returns the storage allocated (type DenseMat). DenseAllocMat * - * returns NULL if the request for matrix storage cannot be * - * satisfied. See the above documentation for the type DenseMat * - * for matrix storage details. * - * * - ******************************************************************/ - -DenseMat DenseAllocMat(integertype N); - - -/****************************************************************** - * * - * Function : DenseAllocPiv * - * Usage : p = DenseAllocPiv(N); * - * if (p == NULL) ... memory request failed * - *----------------------------------------------------------------* - * DenseAllocPiv allocates memory for pivot information to be * - * filled in by the DenseFactor routine during the factorization * - * of an N by N dense matrix. The underlying type for pivot * - * information is an array of N integers and this routine returns * - * the pointer to the memory it allocates. If the request for * - * pivot storage cannot be satisfied, DenseAllocPiv returns NULL. * - * * - ******************************************************************/ - -integertype *DenseAllocPiv(integertype N); - - -/****************************************************************** - * * - * Function : DenseFactor * - * Usage : ier = DenseFactor(A, p); * - * if (ier != 0) ... A is singular * - *----------------------------------------------------------------* - * DenseFactor performs the LU factorization of the N by N dense * - * matrix A. This is done using standard Gaussian elimination * - * with partial pivoting. * - * * - * A successful LU factorization leaves the matrix A and the * - * pivot array p with the following information: * - * * - * (1) p[k] contains the row number of the pivot element chosen * - * at the beginning of elimination step k, k=0, 1, ..., N-1. * - * * - * (2) If the unique LU factorization of A is given by PA = LU, * - * where P is a permutation matrix, L is a lower triangular * - * matrix with all 1's on the diagonal, and U is an upper * - * triangular matrix, then the upper triangular part of A * - * (including its diagonal) contains U and the strictly lower * - * triangular part of A contains the multipliers, I-L. * - * * - * DenseFactor returns 0 if successful. Otherwise it encountered * - * a zero diagonal element during the factorization. In this case * - * it returns the column index (numbered from one) at which * - * it encountered the zero. * - * * - ******************************************************************/ - -integertype DenseFactor(DenseMat A, integertype *p); - - -/****************************************************************** - * * - * Function : DenseBacksolve * - * Usage : DenseBacksolve(A, p, b); * - *----------------------------------------------------------------* - * DenseBacksolve solves the N-dimensional system A x = b using * - * the LU factorization in A and the pivot information in p * - * computed in DenseFactor. The solution x is returned in b. This * - * routine cannot fail if the corresponding call to DenseFactor * - * did not fail. * - * * - ******************************************************************/ - -void DenseBacksolve(DenseMat A, integertype *p, realtype *b); - - -/****************************************************************** - * * - * Function : DenseZero * - * Usage : DenseZero(A); * - *----------------------------------------------------------------* - * DenseZero sets all the elements of the N by N matrix A to 0.0. * - * * - ******************************************************************/ - -void DenseZero(DenseMat A); - - -/****************************************************************** - * * - * Function : DenseCopy * - * Usage : DenseCopy(A, B); * - *----------------------------------------------------------------* - * DenseCopy copies the contents of the N by N matrix A into the * - * N by N matrix B. * - * * - ******************************************************************/ - -void DenseCopy(DenseMat A, DenseMat B); - - -/****************************************************************** - * * - * Function: DenseScale * - * Usage : DenseScale(c, A); * - *----------------------------------------------------------------* - * DenseScale scales the elements of the N by N matrix A by the * - * constant c and stores the result back in A. * - * * - ******************************************************************/ - -void DenseScale(realtype c, DenseMat A); - - -/****************************************************************** - * * - * Function : DenseAddI * - * Usage : DenseAddI(A); * - *----------------------------------------------------------------* - * DenseAddI adds the identity matrix to A and stores the result * - * back in A. * - * * - ******************************************************************/ - -void DenseAddI(DenseMat A); - - -/****************************************************************** - * * - * Function : DenseFreeMat * - * Usage : DenseFreeMat(A); * - *----------------------------------------------------------------* - * DenseFreeMat frees the memory allocated by DenseAllocMat for * - * the N by N matrix A. * - * * - ******************************************************************/ - -void DenseFreeMat(DenseMat A); - - -/****************************************************************** - * * - * Function : DenseFreePiv * - * Usage : DenseFreePiv(p); * - *----------------------------------------------------------------* - * DenseFreePiv frees the memory allocated by DenseAllocPiv for * - * the pivot information array p. * - * * - ******************************************************************/ - -void DenseFreePiv(integertype *p); - - -/****************************************************************** - * * - * Function : DensePrint * - * Usage : DensePrint(A); * - *----------------------------------------------------------------* - * This routine prints the N by N dense matrix A to standard * - * output as it would normally appear on paper. It is intended * - * as a debugging tool with small values of N. The elements are * - * printed using the %g option. A blank line is printed before * - * and after the matrix. * - * * - ******************************************************************/ - -void DensePrint(DenseMat A); - - -#endif -#ifdef __cplusplus -} -#endif diff --git a/dw.cpp b/dw.cpp deleted file mode 100644 index 662551a8..00000000 --- a/dw.cpp +++ /dev/null @@ -1,349 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phrqproto.h" -#include "output.h" -#define PITZER_EXTERNAL extern -#include "pitzer.h" - -static int BB (double T); -static double PS (double T); -static double VLEST (double T); -static int DFIND (double *DOUT, double P, double D, double T); -static int QQ (double T, double D); -static double BASE (double D); - -/* COMMON /QQQQ/ */ -static double Q0,Q5; -/* COMMON /ACONST/ */ -static double GASCON=0.461522e0, TZ=647.073e0, AA=1.e0; -static double Z, DZ, Y; -/* COMMON /ELLCON/ */ -static double G1=11.e0,G2=44.333333333333e0,GF=3.5e0; -static double B1, B2, B1T, B2T, B1TT, B2TT; - -/* ---------------------------------------------------------------------- */ -int DW (double T) -/* ---------------------------------------------------------------------- */ -/* -C -C SUBROUTINE TO CALCULATE THE DENSITY OF WATER AS A FUNCTION OF -C TEMPERATURE. T IS IN KELVIN, P IS IN PASCALS, DW0 IS IN G/CM^3 -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - double FP = 9.869232667e0, P, DGSS, D; - - BB (T); - P=1.0e0/FP; - if (T > 373.149e0) P=PS(T); - DGSS=P/T/.4e0; - if (T < TZ) { - DGSS=1.0e0/(VLEST(T)); - } - DFIND (&D,P,DGSS,T); - DW0=D; - VP=P*FP; - return OK; -} - -/* ---------------------------------------------------------------------- */ -static int BB (double T) -/* ---------------------------------------------------------------------- */ -/* - -C -C THIS SUBROUTINE CALCULATES THE B'S NEEDED FOR FUNCTION DW. -C THE B'S CALCULATED HERE ARE IN CM3/G. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - double V[11]; - int I; - /* COMMON /BCONST/ */ - double P[11]={0, 0.7478629e0, -.3540782e0, 0.e0, 0e0, .007159876e0, 0.e0, - -.003528426e0, 0., 0., 0.}; - double Q[11]={0, 1.1278334e0,0.e0,-.5944001e0,-5.010996e0,0.e0,.63684256e0, - 0., 0., 0., 0.}; - - V[1]=1.0; - for (I = 2; I <= 10; I++) { - V[I]=V[I-1]*TZ/T; - } - B1=P[1]+P[2]*log(1.e0/V[2]); - B2=Q[1]; - B1T=P[2]*V[2]/TZ; - B2T=0.e0; - B1TT=0.e0; - B2TT=0.e0; - for (I = 3; I <= 10; I++) { - B1=B1+P[I]*V[I-1]; - B2=B2+Q[I]*V[I-1]; - B1T=B1T-(I-2)*P[I]*V[I-1]/T; - B2T=B2T-(I-2)*Q[I]*V[I-1]/T; - B1TT=B1TT+P[I]*(I-2)*(I-2)*V[I-1]/T/T; - B2TT=B2TT+Q[I]*(I-2)*(I-2)*V[I-1]/T/T; - } - B1TT=B1TT-B1T/T; - B2TT=B2TT-B2T/T; - return OK; -} -/* ---------------------------------------------------------------------- */ -static double PS (double T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES AN APPROXIMATION TO THE VAPOR PRESSURE, P -C AS A FUNCTION OF THE INPUT TEMPERATURE. THE VAPOR PRESSURE -C CALCULATED AGREES WITH THE VAPOR PRESSURE PREDICTED BY THE SURFACE -C TO WITHIN .02% TO WITHIN A DEGREE OR SO OF THE CRITICAL TEMPERATUR -C AND CAN SERVE AS AN INITIAL GUESS FOR FURTHER REFINEMENT BY -C IMPOSING THE CONDITION THAT GL=GV. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - double A[9]={0, -7.8889166e0,2.5514255e0,-6.716169e0, - 33.239495e0,-105.38479e0,174.35319e0,-148.39348e0, - 48.631602e0}; - double PL, V, W, B, Z, Q; - int I; - if(T <= 314.e0) { - PL=6.3573118e0-8858.843e0/T+607.56335e0*pow(T,-.6e0); - return (.1e0*exp(PL)); - } - V=T/647.25e0; - W=fabs(1.e0-V); - B=0.e0; - for (I = 1; I <= 8; I++) { - Z=I; - B=B+A[I]*pow(W,((Z+1.e0)/2.e0)); - } - Q=B/V; - return (22.093e0*exp(Q)); -} -/* ---------------------------------------------------------------------- */ -static double VLEST (double T) -/* ---------------------------------------------------------------------- */ -/* -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - double A=-1.59259e1,B=6.57886e-2,C=-1.12666e-4,D=7.33191e-8, - E=1.60229e3,F=2.88572e0,G=650.0e0; - - return (A+B*T+C*T*T+D*T*T*T+E/T+F/(G-T)); -} -/* ---------------------------------------------------------------------- */ -static int DFIND (double *DOUT, double P, double D, double T) -/* ---------------------------------------------------------------------- */ -/* -C -C ROUTINE TO FIND DENSITY CORRESPONDING TO INPUT PRESSURE P(MPA), AN -C TEMPERATURE T(K), USING INITIAL GUESS DENSITY D(G/CM3). THE OUTPUT -C DENSITY IS IN G/CM3. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - int L; - double DD, RT, PP_dfind, DPD, DPDX, DP, X; - /* double DD, RT, PP, DPD, DPDX, DP, X; */ - - DD=D; - RT=GASCON*T; - if(DD <= 0.e0) DD=1.e-8; - if(DD > 1.9e0) DD=1.9e0; - L=0; - for (L=1; L <= 30; L++) { - if(DD <= 0.e0) DD=1.e-8; - if(DD > 1.9e0) DD=1.9e0; - QQ(T,DD); - PP_dfind = RT*DD*BASE(DD)+Q0; - DPD=RT*(Z+Y*DZ)+Q5; - /* -C -C THE FOLLOWING 3 LINES CHECK FOR NEGATIVE DP/DRHO, AND IF SO ASSUME -C GUESS TO BE IN 2-PHASE REGION, AND CORRECT GUESS ACCORDINGLY. -C - */ - if(DPD <= 0.e0) { - if(D >= .2967e0) DD=DD*1.02e0; - if(D < .2967e0) DD=DD*.98e0; - if(L <= 10) continue; - } else { -/* 13 */ - DPDX=DPD*1.1e0; - if(DPDX < 0.1e0) DPDX=0.1e0; - DP=fabs(1.e0-PP_dfind/P); - if(DP < 1.e-8) break; - if(D > .3e0 && DP < 1.e-7) break; - if(D > .7e0 && DP < 1.e-6) break; - X=(P-PP_dfind)/DPDX; - if(fabs(X) > .1e0) X=X*.1e0/fabs(X); - DD=DD+X; - if(DD < 0.e0) DD=1.e-8; - } - } - if (L > 30) error_msg("In subroutine DFIND", STOP); -/* 20 CONTINUE */ - *DOUT=DD; - return OK; -} -/* ---------------------------------------------------------------------- */ -static int QQ (double T, double D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS ROUTINE CALCULATES, FOR A GIVEN T(K) AND D(G/CM3), THE RESIDUL -C CONTRIBUTIONS TO: PRESSURE (Q), DP/DRHO (Q5) -C THIS SUBROUTINE IS USED IN DENSITY OF WATER CALCULATION. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - /* COMMON /NCONST/ */ - double G[41]={0,-.53062968529023e3,.22744901424408e4,.78779333020687e3 - ,-.69830527374994e2,.17863832875422e5,-.39514731563338e5 - ,.33803884280753e5,-.13855050202703e5,-.25637436613260e6 - ,.48212575981415e6,-.34183016969660e6, .12223156417448e6 - ,.11797433655832e7,-.21734810110373e7, .10829952168620e7 - ,-.25441998064049e6,-.31377774947767e7,.52911910757704e7 - ,-.13802577177877e7,-.25109914369001e6, .46561826115608e7 - ,-.72752773275387e7,.41774246148294e6,.14016358244614e7 - ,-.31555231392127e7,.47929666384584e7,.40912664781209e6 - ,-.13626369388386e7, .69625220862664e6,-.10834900096447e7 - ,-.22722827401688e6,.38365486000660e6,.68833257944332e4 - ,.21757245522644e5,-.26627944829770e4,-.70730418082074e5 - ,-.225e0,-1.68e0,.055e0,-93.0e0}; - /*int II[41]={0,4*0,4*1,4*2,4*3,4*4,4*5,4*6,4*8,2*2,0,4,3*2,4};*/ - int II[41]={0, 0,0,0,0, 1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4, 5,5,5,5, 6,6,6,6, 8,8,8,8, 2,2, 0,4, 2,2,2,4}; - /*int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,3*4,0,2,0,0};*/ - int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,4,4,4,0,2,0,0}; - int NC=36; - /* COMMON /ADDCON/ */ - double ATZ[5]={0,64.e1,64.e1,641.6e0,27.e1},ADZ[5]={0,.319e0,.319e0,.319e0,1.55e0}, - AAT[5]={0,2.e4,2.e4,4.e4,25.e0}, AAD[5]={0,34.e0,4.e1,3.e1,1.05e3}; - double *QZT; - double QR[12],QT[11] /*, QZT[10]*/; - /*EQUIVALENCE (QT(2),QZT(1))*/ - - double E, Q10, Q20, V, QP, DDZ, DEL, EX1, DEX, ATT, TX, - TAU, EX2, TEX, QM, FCT, Q5T; - int I, K, L, J, KM; - QZT = &(QT[1]); - QR[1]=0.e0; - Q5=0.e0; - Q0=0.e0; - E=exp(-AA*D); - Q10=D*D*E; - Q20=1.e0-E; - QR[2]=Q10; - V=TZ/T; - QT[1]=T/TZ; - /*DO 4 I=2,10*/ - for (I = 2; I <= 10; I++) { - QR[I+1]=QR[I]*Q20; - /* 4 QT[I]=QT[I-1]*V*/ - QT[I]=QT[I-1]*V; - } - /* DO 10 I=1,NC */ - for (I = 1; I <= NC; I++) { - K=II[I]+1; - L=JJ[I]; - QP=G[I]*AA*QR[K+1]*QZT[L]; - Q0=Q0+QP; - /*10 Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP*/ - Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP; - } - QP=0.e0; - /* DO 20 J=37,40 */ - for (J=37; J <= 40; J++) { - if(fabs(G[J]) < 1.0e-20) continue; - K=II[J]; - KM=JJ[J]; - DDZ = ADZ[J-36]; - DEL = D/DDZ - 1.e0; - if(fabs(DEL) < 1.e-10) DEL=1.e-10; - EX1 = -AAD[J-36]*pow(DEL,K); - if (EX1 <= -88.028e0) { - DEX=0.e0; - } else { - DEX=exp(EX1)*pow(DEL,KM); - } - ATT = AAT[J-36]; - TX = ATZ[J-36]; - TAU = T/TX-1.e0; - EX2 = -ATT*TAU*TAU; - if (EX2 <= -88.028e0) { - TEX=0.e0; - } else { - TEX = exp(EX2); - } - Q10 = DEX*TEX; - QM = KM/DEL - K*AAD[J-36]*pow(DEL,(K-1)); - FCT=QM*D*D*Q10/DDZ; - Q5T = FCT*(2.e0/D+QM/DDZ)-pow((D/DDZ),2)*Q10*(KM/DEL/DEL+ - K*(K-1)*AAD[J-36]*pow(DEL,(K-2))); - Q5 = Q5 + Q5T*G[J]; - QP = QP + G[J]*FCT; - /* 20 CONTINUE */ - } - Q0=Q0+QP; - return OK; -} -/* ---------------------------------------------------------------------- */ -static double BASE (double D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE Z (=PBASE/(DRT)) NEEDED FOR FUNCTION -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - double X, Z0, DZ0; -/* -C -C G1,G2 AND GF ARE THE ALPHA, BETA AND GAMMA FOR DENSITY OF WATER -C CALCULATIONS. B1 AND B2 ARE THE 'EXCLUDED VOLUME' AND '2ND VIRIAL -C SUPPLIED BY THE SUBROUTINE BB(T), WHICH ALSO SUPPLIES THE 1ST AND -C 2ND DERIVATIVES WITH RESPECT TO T (B1T,B2T,B1TT,B2TT). -C -*/ - Y=.25e0*B1*D; - X=1.e0-Y; - Z0=(1.e0+G1*Y+G2*Y*Y)/pow(X,3); - Z=Z0+4.e0*Y*(B2/B1-GF); - DZ0=(G1+2.e0*G2*Y)/pow(X,3) + 3.e0*(1.e0+G1*Y+G2*Y*Y)/pow(X,4); - DZ=DZ0+4.e0*(B2/B1-GF); - return(Z); -} -/* ---------------------------------------------------------------------- */ -double DC (double T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE RELATIVE DIELECTRIC CONSTANT AS A -C FUNCTION OF TEMPERATURE, ASSUMING ONE ATMOSPHERE PRESSURE -C ACCORDING TO D. J. BRADLEY AND K. S. PITZER, (1979) -C -*/ -{ - double D1000, C, B; - double U[10]={0, 3.4279e2, -5.0866e-3, 9.4690e-7, -2.0525e0, 3.1159e3, - -1.8289e2, -8.0325e3, 4.2142e6, 2.1417e0}; - D1000=U[1]*exp(U[2]*T+U[3]*T*T); - C=U[4]+U[5]/(U[6]+T); - B=U[7]+U[8]/T+U[9]*T; - return (D1000+C*log((B+VP*1.01325e0)/(B+1000.0e0))); -} diff --git a/global.h b/global.h deleted file mode 100644 index 9fb1f7f9..00000000 --- a/global.h +++ /dev/null @@ -1,1638 +0,0 @@ - -#ifdef PHREEQC_IDENT -static char const svnidglobal[] = "$Id$"; -#endif -#ifndef _INC_GLOBAL_H -#define _INC_GLOBAL_H - -#define NO_DOS -/* #define PHREEQ98 */ /* PHREEQ98: code for graphical user interface */ -#ifdef PHREEQ98 -/*#define fprintf fprintf98*/ -#endif -/* - * uncomment following line, to use default DOS file name for - * output file - */ -/*#define DOS*/ -/* - * BUG FIX FOR DGs - */ -#ifndef __OPEN_NAMESPACE__ -#define __OPEN_NAMESPACE__ -#endif -/* ---------------------------------------------------------------------- - * INCLUDE FILES - * ---------------------------------------------------------------------- */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" - -/* must be defined here and in cl.c */ -/* #include */ -#ifndef NAN -# define NAN -99999999 -#endif -#define MISSING -9999.999 -/* search.h -- declarations for POSIX/SVID-compatible search functions */ - - /* HSEARCH(3C) */ - typedef struct entry { char *key; void *data; } ENTRY; - typedef enum { FIND, ENTER } ACTION; - - /* TSEARCH(3C) */ - typedef enum { preorder, postorder, endorder, leaf } VISIT; - -/* ---------------------------------------------------------------------- - * DEFINITIONS - * ---------------------------------------------------------------------- */ -#define F_C_MOL 96493.5 /* C/mol or joule/volt-eq*/ -#define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ -#define F_KCAL_V_EQ 23.0623 /* kcal/volt-eq */ -#define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ -#define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ -#define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ -#define EPSILON 78.5 /* dialectric constant, dimensionless */ -#define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ -#define JOULES_PER_CALORIE 4.1840 - -typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; - -#define TRUE 1 -#define FALSE 0 -#define OK 1 -#define ERROR 0 -#define STOP 1 -#define CONTINUE 0 - -#define DISP 2 -#define STAG 3 -#define NOMIX 4 - -#define CONVERGED 2 -#define MASS_BALANCE 3 -/* -#define OSCILLATE 4 -#define H2O_LIMITS 5 - */ -#define REWRITE 2 -#define INIT -1 - -/* check_line values, plus EMPTY, EOF, OK */ -#define KEYWORD 3 - -/* copy_token values */ -#define EMPTY 2 -#define UPPER 4 -#define LOWER 5 -#define DIGIT 6 -#define UNKNOWN 7 -#define OPTION 8 - -/* species types */ -#define AQ 0 -#define HPLUS 1 -#define H2O 2 -#define EMINUS 3 -#define SOLID 4 -#define EX 5 -#define SURF 6 -#define SURF_PSI 7 - -/* unknown types */ -#define MB 10 -#define ALK 11 -#define CB 12 -#define SOLUTION_PHASE_BOUNDARY 13 -#define MU 14 -#define AH2O 15 -#define MH 16 -#define MH2O 17 -#define PP 18 -#define EXCH 19 -#define SURFACE 20 -#define SURFACE_CB 21 -#define GAS_MOLES 23 -#define S_S_MOLES 24 -#define PITZER_GAMMA 25 -/* state */ -#define INITIALIZE 0 -#define INITIAL_SOLUTION 1 -#define INITIAL_EXCHANGE 2 -#define INITIAL_SURFACE 3 -#define INITIAL_GAS_PHASE 4 -#define REACTION 5 -#define INVERSE 6 -#define ADVECTION 7 -#define TRANSPORT 8 -#define PHAST 9 - -/* constaints in mass balance */ -#define EITHER 0 -#define DISSOLVE 1 -#define PRECIPITATE -1 - -/* gas phase type */ -#define PRESSURE 1 -#define VOLUME 2 - -#define MAX_PP_ASSEMBLAGE 10 /* default estimate of the number of phase assemblages */ -#define MAX_ADD_EQUATIONS 20 /* maximum number of equations added together to reduce eqn to - master species */ -#define MAX_ELEMENTS 50 /* default estimate of the number of elements */ -#define MAX_LENGTH 200 /* maximum number of characters component name */ -#define MAX_LINE 80 /* estimate of maximum line length */ -#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ -#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ -#define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ -#define MAX_MASTER 50 /* default estimate of the number of master species */ -#define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in - an equation */ -#define MAX_PHASES 500 /* initial guess of number of phases defined */ -#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ -#define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ -#define MAX_STRINGS 3000 -#define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ -#define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ -#define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ -#define MAX_SUM_MB 500 /* list used to calculate mass balance sums */ -#define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ -#define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ -#define TOL 1e-9 /* tolerance for comparisons of double numbers */ -#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-25 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -30 -/* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ -struct model { - int force_prep; - LDBLE temperature; - int count_exchange; - struct master **exchange; - - int count_kinetics; - struct kinetics *kinetics; - - int count_gas_phase; - struct phase **gas_phase; - - int count_s_s_assemblage; - char **s_s_assemblage; - - int count_pp_assemblage; - struct phase **pp_assemblage; - char **add_formula; - LDBLE *si; - - int diffuse_layer; - int count_surface_comp; - struct master **surface_comp; - int count_surface_charge; - struct master **surface_charge; -}; -EXTERNAL struct model last_model; -EXTERNAL int same_model; -EXTERNAL int same_temperature; - -struct name_master { - char *name; - struct master *master; -}; -struct name_species { - char *name; - struct species *s; -}; -struct name_phase { - char *name; - struct phase *phase; -}; -struct punch { - int in; - int new_def; - struct name_master *totals; - int count_totals; - struct name_species *molalities; - int count_molalities; - struct name_species *activities; - int count_activities; - struct name_phase *pure_phases; - int count_pure_phases; - struct name_phase *si; - int count_si; - struct name_phase *gases; - int count_gases; - struct name_phase *s_s; - int count_s_s; - struct name_phase *kinetics; - int count_kinetics; - struct name_master *isotopes; - int count_isotopes; - struct name_master *calculate_values; - int count_calculate_values; - int inverse; - int sim; - int state; - int soln; - int dist; - int time; - int step; - int rxn; - int temp; - int ph; - int pe; - int alk; - int mu; - int water; - int high_precision; - int user_punch; - int charge_balance; - int percent_error; -}; -EXTERNAL struct punch punch; -/* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ -struct temperature { - int n_user; - int n_user_end; - char *description; - LDBLE *t; - int count_t; -}; -EXTERNAL struct temperature *temperature; -EXTERNAL int count_temperature; -/* ---------------------------------------------------------------------- - * Surface - * ---------------------------------------------------------------------- */ -struct surface { - int n_user; - int n_user_end; - int new_def; - int diffuse_layer; - int edl; - int only_counter_ions; - int donnan; - LDBLE thickness; - LDBLE debye_units; - char *description; - int solution_equilibria; - int n_solution; - int count_comps; - struct surface_comp *comps; - int count_charge; - struct surface_charge *charge; - int related_phases; - int related_rate; - int transport; -}; -struct surface_comp { - char *formula; - LDBLE moles; - struct master *master; - struct elt_list *totals; - LDBLE la; - int charge; - LDBLE cb; - char *phase_name; - LDBLE phase_proportion; - char *rate_name; -}; -struct surface_charge { - char *name; - LDBLE specific_area; - LDBLE grams; - LDBLE charge_balance; - LDBLE mass_water; - struct elt_list *diffuse_layer_totals; - int count_g; - struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ - struct master *psi_master; - LDBLE la_psi; -}; -struct surface_diff_layer { - LDBLE charge; - LDBLE g; - LDBLE dg; - LDBLE psi_to_z; -}; -EXTERNAL struct surface *surface; -EXTERNAL struct surface *dbg_surface; -EXTERNAL int count_surface; -EXTERNAL int max_surface; -EXTERNAL struct charge_group { - LDBLE z; - LDBLE eq; -} *charge_group; -/* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ -struct exchange { - int n_user; - int n_user_end; - int new_def; - char *description; - int solution_equilibria; - int n_solution; - int count_comps; - struct exch_comp *comps; - int related_phases; - int related_rate; - int pitzer_exchange_gammas; -}; -struct exch_comp { - char *formula; - LDBLE formula_z; - struct elt_list *formula_totals; - LDBLE moles; - struct master *master; - struct elt_list *totals; - LDBLE la; - LDBLE charge_balance; - char *phase_name; - LDBLE phase_proportion; - char *rate_name; -}; -EXTERNAL struct exchange *exchange; -EXTERNAL struct exchange *dbg_exchange; -EXTERNAL int count_exchange; -EXTERNAL int max_exchange; -/* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ -struct kinetics { - int n_user; - int n_user_end; - char *description; - int count_comps; - struct kinetics_comp *comps; - int count_steps; - LDBLE *steps; - LDBLE step_divide; - /*char *units;*/ - struct elt_list *totals; - int rk; - int bad_step_max; - int use_cvode; -}; -struct kinetics_comp { - char *rate_name; -#ifdef SKIP - char *formula; -#endif - struct name_coef *list; - int count_list; -/* struct phase *phase; */ - LDBLE tol; - LDBLE m; - LDBLE initial_moles; - LDBLE m0; - LDBLE moles; - int count_c_params; - char **c_params; - int count_d_params; - LDBLE *d_params; -}; -EXTERNAL struct kinetics *kinetics; -EXTERNAL struct kinetics *dbg_kinetics; -EXTERNAL int count_kinetics; -EXTERNAL int max_kinetics; - -struct save_values { - LDBLE value; - int count_subscripts; - int *subscripts; -}; -EXTERNAL int count_save_values; -EXTERNAL struct save_values *save_values; - -#ifdef SKIP -struct kin_exch { - char *exch_name; - char *phase_name; - LDBLE phase_proportion; -}; -EXTERNAL struct kin_exch *kin_exch; -EXTERNAL int count_kin_exch; -struct kin_surf { - char *surf_name; - char *phase_name; - LDBLE phase_proportion; -}; -EXTERNAL struct kin_surf *kin_surf; -EXTERNAL int count_kin_surf; -#endif -/*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ -struct save { - int solution; - int n_solution_user; - int n_solution_user_end; - int mix; - int n_mix_user; - int n_mix_user_end; - int irrev; - int n_irrev_user; - int n_irrev_user_end; - int pp_assemblage; - int n_pp_assemblage_user; - int n_pp_assemblage_user_end; - int exchange; - int n_exchange_user; - int n_exchange_user_end; - int kinetics; - int n_kinetics_user; - int n_kinetics_user_end; - int surface; - int n_surface_user; - int n_surface_user_end; - int gas_phase; - int n_gas_phase_user; - int n_gas_phase_user_end; - int s_s_assemblage; - int n_s_s_assemblage_user; - int n_s_s_assemblage_user_end; -}; -EXTERNAL struct save save; -/*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ -struct use { - int solution_in; - int n_solution_user; - int n_solution; - struct solution *solution_ptr; - - int pp_assemblage_in; - int n_pp_assemblage_user; - int n_pp_assemblage; - struct pp_assemblage *pp_assemblage_ptr; - - int mix_in; - int n_mix_user; - int n_mix; - struct mix *mix_ptr; - int n_mix_user_orig; - - int irrev_in; - int n_irrev_user; - int n_irrev; - struct irrev *irrev_ptr; - - int exchange_in; - int n_exchange_user; - int n_exchange; - struct exchange *exchange_ptr; - - int kinetics_in; - int n_kinetics_user; - int n_kinetics; - struct kinetics *kinetics_ptr; - - int surface_in; - int n_surface_user; - int n_surface; - struct surface *surface_ptr; - - int temperature_in; - int n_temperature_user; - int n_temperature; - struct temperature *temperature_ptr; - - int inverse_in; - int n_inverse_user; - int n_inverse; - struct inverse *inverse_ptr; - - int gas_phase_in; - int n_gas_phase_user; - int n_gas_phase; - struct gas_phase *gas_phase_ptr; - - int s_s_assemblage_in; - int n_s_s_assemblage_user; - int n_s_s_assemblage; - struct s_s_assemblage *s_s_assemblage_ptr; - - int trans_in; - int advect_in; -}; -EXTERNAL struct use use; -EXTERNAL struct use *dbg_use; -/*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ -struct copier { - int count; - int max; - int *n_user; - int *start; - int *end; -}; -EXTERNAL struct copier copy_solution; -EXTERNAL struct copier copy_pp_assemblage; -EXTERNAL struct copier copy_exchange; -EXTERNAL struct copier copy_surface; -EXTERNAL struct copier copy_s_s_assemblage; -EXTERNAL struct copier copy_gas_phase; -EXTERNAL struct copier copy_kinetics; -EXTERNAL struct copier copy_mix; -EXTERNAL struct copier copy_irrev; -EXTERNAL struct copier copy_temperature; - - -/*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ -struct inverse { - int n_user; - char *description; - int new_def; - int minimal; - int range; - int mp; - LDBLE mp_censor; - LDBLE range_max; - LDBLE tolerance; - LDBLE mp_tolerance; - int count_uncertainties; - LDBLE *uncertainties; - int count_ph_uncertainties; - LDBLE *ph_uncertainties; -#ifdef SKIP - LDBLE *alk_uncertainties; -#endif - LDBLE water_uncertainty; - int mineral_water; - int carbon; - LDBLE *dalk_dph; - LDBLE *dalk_dc; - int count_solns; - int *solns; - int count_force_solns; - int *force_solns; - int count_elts; - struct inv_elts *elts; - int count_phases; - struct inv_phases *phases; - int count_master_list; - struct master **master_list; - int count_redox_rxns; - int count_isotopes; - struct inv_isotope *isotopes; - int count_i_u; - struct inv_isotope *i_u; - int count_isotope_unknowns; - struct isotope *isotope_unknowns; -}; -struct inv_elts { - char *name; - struct master *master; - int row; - int count_uncertainties; - LDBLE *uncertainties; -}; -struct inv_isotope { - char *isotope_name; - LDBLE isotope_number; - char *elt_name; - int count_uncertainties; - LDBLE *uncertainties; -}; -struct inv_phases { - char *name; - struct phase *phase; - int column; - int constraint; - int force; - int count_isotopes; - struct isotope *isotopes; -}; -EXTERNAL struct inverse *inverse; -EXTERNAL int count_inverse; - -/*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ -struct mix { - int n_user; - int n_user_end; - char *description; - int count_comps; - struct mix_comp *comps; -}; -struct mix_comp { - int n_solution; - LDBLE fraction; -}; -EXTERNAL struct mix *mix; -EXTERNAL struct mix *dbg_mix; -EXTERNAL int count_mix; -/*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ -struct irrev { - int n_user; - int n_user_end; - char *description; - struct name_coef *list; - struct elt_list *elts; - LDBLE *steps; - char *units; - int count_steps; - int count_list; -}; -struct name_coef { - char *name; - LDBLE coef; -}; -EXTERNAL struct irrev *irrev; -EXTERNAL struct irrev *dbg_irrev; -EXTERNAL int count_irrev; -/*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ -struct gas_phase { - int n_user; - int n_user_end; - char *description; - int new_def; - int solution_equilibria; - int n_solution; - int type; - LDBLE total_p; - LDBLE total_moles; - LDBLE volume; - LDBLE temperature; - int count_comps; - struct gas_comp *comps; -}; -struct gas_comp { - struct phase *phase; - char *name; - LDBLE p_read; - LDBLE moles; - LDBLE initial_moles; -}; -EXTERNAL int count_gas_phase; -EXTERNAL int max_gas_phase; -EXTERNAL struct gas_phase *gas_phase; -/*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ -struct s_s_assemblage { - int n_user; - int n_user_end; - char *description; - int new_def; -/* int type; */ -/* int solution_equilibria; */ -/* int n_solution; */ - int count_s_s; - struct s_s *s_s; -}; -struct s_s { - char *name; - struct s_s_comp *comps; - int count_comps; - LDBLE total_moles; - LDBLE dn; - LDBLE a0, a1; - LDBLE ag0, ag1; - int s_s_in; - int miscibility; - int spinodal; - LDBLE tk, xb1, xb2; - int input_case; - LDBLE p[4]; -}; -struct s_s_comp { - char *name; - struct phase *phase; - LDBLE initial_moles; - LDBLE moles; - LDBLE init_moles; - LDBLE delta; - LDBLE fraction_x; - LDBLE log10_lambda; - LDBLE log10_fraction_x; - LDBLE dn, dnc, dnb; -}; -EXTERNAL int count_s_s_assemblage; -EXTERNAL int max_s_s_assemblage; -EXTERNAL struct s_s_assemblage *s_s_assemblage; -/*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ -struct pp_assemblage { - int n_user; - int n_user_end; - char *description; - int new_def; - struct elt_list *next_elt; - int count_comps; - struct pure_phase *pure_phases; -}; -struct pure_phase { - struct phase *phase; - char *name; - char *add_formula; - LDBLE si; - LDBLE moles; - LDBLE delta; - LDBLE initial_moles; - int dissolve_only; -}; -EXTERNAL int count_pp_assemblage; -EXTERNAL int max_pp_assemblage; -EXTERNAL struct pp_assemblage *pp_assemblage; -EXTERNAL struct pp_assemblage *dbg_pp_assemblage; -/*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ -struct species_list { - struct species *master_s; - struct species *s; - LDBLE coef; -}; -EXTERNAL int count_species_list; -EXTERNAL int max_species_list; -EXTERNAL struct species_list *species_list; -/*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ -struct list0 { - LDBLE *target; - LDBLE coef; -}; -EXTERNAL int count_sum_jacob0; /* number of elements in sum_jacob0 */ -EXTERNAL int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ -EXTERNAL struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - -struct list1 { - LDBLE *source; - LDBLE *target; -}; -EXTERNAL int count_sum_mb1; /* number of elements in sum_mb1 */ -EXTERNAL int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ -EXTERNAL struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ -EXTERNAL int count_sum_jacob1; /* number of elements in sum_jacob1 */ -EXTERNAL int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ -EXTERNAL struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ -struct list2 { - LDBLE *source; - LDBLE *target; - LDBLE coef; -}; -EXTERNAL int count_sum_mb2; /* number of elements in sum_mb2 */ -EXTERNAL int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ -EXTERNAL struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ -EXTERNAL int count_sum_jacob2; /* number of elements in sum_jacob2 */ -EXTERNAL int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ -EXTERNAL struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ -EXTERNAL int count_sum_delta; /* number of elements in sum_delta */ -EXTERNAL int max_sum_delta; /* calculated maximum number of elements in sum_delta */ -EXTERNAL struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ -/*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ -struct solution { - int new_def; - int n_user; - int n_user_end; - char *description; - LDBLE tc; - LDBLE ph; - LDBLE solution_pe; - LDBLE mu; - LDBLE ah2o; - LDBLE density; - LDBLE total_h; - LDBLE total_o; - LDBLE cb; - LDBLE mass_water; - LDBLE total_alkalinity; - /*LDBLE total_co2;*/ - char *units; - struct pe_data *pe; - int default_pe; - struct conc *totals; - struct master_activity *master_activity; - int count_master_activity; - int count_isotopes; - struct isotope *isotopes; - struct master_activity *species_gamma; - int count_species_gamma; -}; -struct master_activity { - char *description; - LDBLE la; -}; -struct conc { - char *description; - /*int skip;*/ - LDBLE moles; - LDBLE input_conc; - char *units; - char *equation_name; - struct phase *phase; - LDBLE phase_si; - int n_pe; - char *as; - LDBLE gfw; -}; -struct pe_data { - char *name; - struct reaction *rxn; -}; -struct isotope { - LDBLE isotope_number; - char *elt_name; - char *isotope_name; - LDBLE total; - LDBLE ratio; - LDBLE ratio_uncertainty; - LDBLE x_ratio_uncertainty; - struct master *master; - struct master *primary; - LDBLE coef; /* coefficient of element in phase */ -}; -EXTERNAL struct solution **solution; -EXTERNAL struct solution **dbg_solution; -EXTERNAL int count_solution; -EXTERNAL int max_solution; -struct iso { - char *name; - LDBLE value; - LDBLE uncertainty; -}; -#ifdef MAINSUBS -struct iso iso_defaults[] = { - {"13C", -10, 1}, - {"13C(4)", -10, 1}, - {"13C(-4)", -50, 5}, - {"34S", 10, 1}, - {"34S(6)", 10, 1}, - {"34S(-2)", -30, 5}, - {"2H", -28, 1}, - {"18O", -5, .1}, - {"87Sr", .71, .01}, - {"11B", 20, 5} -}; -int count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct iso)); -#else -extern struct iso iso_defaults[]; -extern int count_iso_defaults; -#endif -/*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ -EXTERNAL char *title_x; -EXTERNAL int new_x; -EXTERNAL char *description_x; -EXTERNAL LDBLE tc_x; -EXTERNAL LDBLE tk_x; -EXTERNAL LDBLE ph_x; -EXTERNAL LDBLE solution_pe_x; -EXTERNAL LDBLE mu_x; -EXTERNAL LDBLE ah2o_x; -EXTERNAL LDBLE density_x; -EXTERNAL LDBLE total_h_x; -EXTERNAL LDBLE total_o_x; -EXTERNAL LDBLE cb_x; -EXTERNAL LDBLE total_ions_x; -EXTERNAL LDBLE mass_water_aq_x; -EXTERNAL LDBLE mass_water_surfaces_x; -EXTERNAL LDBLE mass_water_bulk_x; -EXTERNAL char *units_x; -EXTERNAL struct pe_data *pe_x; -EXTERNAL int count_isotopes_x; -EXTERNAL struct isotope *isotopes_x; -EXTERNAL int default_pe_x; -EXTERNAL int diffuse_layer_x; -EXTERNAL LDBLE total_carbon; -EXTERNAL LDBLE total_co2; -EXTERNAL LDBLE total_alkalinity; -EXTERNAL LDBLE gfw_water; -EXTERNAL LDBLE step_x; -EXTERNAL LDBLE kin_time_x; -/*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ -EXTERNAL int count_cells; -EXTERNAL int count_shifts; -EXTERNAL int ishift; -EXTERNAL int bcon_first; -EXTERNAL int bcon_last; -EXTERNAL int correct_disp; -EXTERNAL LDBLE tempr; -EXTERNAL LDBLE timest; -EXTERNAL int simul_tr; -EXTERNAL LDBLE diffc; -EXTERNAL LDBLE heat_diffc; -EXTERNAL int cell; -/* !!!!! EXTERNAL int count_stag; */ -EXTERNAL struct stag_data { - int count_stag; - LDBLE exch_f; - LDBLE th_m; - LDBLE th_im; -} *stag_data; -EXTERNAL int print_modulus; -EXTERNAL int punch_modulus; -EXTERNAL int dump_in; -EXTERNAL int dump_modulus; -EXTERNAL int transport_warnings; -EXTERNAL struct cell_data { - LDBLE length; - LDBLE mid_cell_x; - LDBLE disp; - LDBLE temp; - int punch; - int print; -} *cell_data; -EXTERNAL int cell_no; -/*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ -EXTERNAL int count_ad_cells; -EXTERNAL int count_ad_shifts; -EXTERNAL int print_ad_modulus; -EXTERNAL int punch_ad_modulus; -EXTERNAL int *advection_punch, *advection_print; -EXTERNAL LDBLE advection_kin_time; -EXTERNAL LDBLE advection_kin_time_defined; -EXTERNAL int advection_warnings; - -/*---------------------------------------------------------------------- - * Keywords - *---------------------------------------------------------------------- */ -struct key { - char *name; - int keycount; -}; -#ifdef MAINSUBS - /* list of valid keywords */ -struct key keyword[] = { - {"eof", 0}, - {"end", 0}, - {"solution_species", 0}, - {"solution_master_species", 0}, - {"solution", 0}, - {"phases", 0}, - {"pure_phases", 0}, - {"reaction", 0}, - {"mix", 0}, - {"use", 0}, - {"save", 0}, - {"exchange_species", 0}, - {"exchange_master_species", 0}, - {"exchange", 0}, - {"surface_species", 0}, - {"surface_master_species", 0}, - {"surface", 0}, - {"reaction_temperature", 0}, - {"inverse_modeling", 0}, - {"gas_phase", 0}, - {"transport", 0}, - {"debug", 0}, - {"selected_output", 0}, - {"select_output", 0}, - {"knobs", 0}, - {"print", 0}, - {"equilibrium_phases", 0}, - {"equilibria", 0}, - {"equilibrium", 0}, - {"pure", 0}, - {"title", 0}, - {"comment", 0}, - {"advection", 0}, - {"kinetics", 0}, - {"incremental_reactions", 0}, - {"incremental", 0}, - {"rates", 0}, - {"solution_s", 0}, - {"user_print", 0}, - {"user_punch", 0}, - {"solid_solutions", 0}, - {"solid_solution", 0}, - {"solution_spread", 0}, - {"spread_solution", 0}, - {"selected_out", 0}, - {"select_out", 0}, - {"user_graph", 0}, - {"llnl_aqueous_model_parameters", 0}, - {"llnl_aqueous_model", 0}, - {"database", 0}, - {"named_analytical_expression", 0}, - {"named_analytical_expressions", 0}, - {"named_expressions", 0}, - {"named_log_k", 0}, - {"isotopes", 0}, - {"calculate_values", 0}, - {"isotope_ratios", 0}, - {"isotope_alphas", 0}, - {"copy", 0}, - {"pitzer", 0}, - {"solution_raw", 0}, - {"exchange_raw", 0}, - {"surface_raw", 0}, - {"equilibrium_phases_raw", 0}, - {"kinetics_raw", 0}, - {"solid_solutions_raw", 0}, - {"gas_phase_raw", 0}, - {"reaction_raw", 0}, - {"mix_raw", 0}, - {"reaction_temperature_raw", 0} -}; -int NKEYS = (sizeof(keyword) / sizeof(struct key)); /* Number of valid keywords */ -#else - extern struct key keyword[]; - extern int NKEYS; -#endif -EXTERNAL struct key *keyword_hash; -EXTERNAL int new_model, new_exchange, new_pp_assemblage, new_surface, new_reaction, new_temperature, - new_mix, new_solution, new_gas_phase, new_inverse, new_punch, new_s_s_assemblage, - new_kinetics, new_copy, new_pitzer; -/*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ -struct element { - char *name; /* element name */ -/* int in; */ - struct master *master; - struct master *primary; - LDBLE gfw; -}; -EXTERNAL struct element **elements; -EXTERNAL int count_elements; -EXTERNAL int max_elements; -EXTERNAL struct element *element_h_one; - -/*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ -struct elt_list { /* list of name and number of elements in an equation */ - struct element *elt; /* pointer to element structure */ - LDBLE coef; /* number of element e's in eqn */ -}; -EXTERNAL struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order*/ -EXTERNAL int count_elts; /* number of elements in elt_list = position of next */ -EXTERNAL int max_elts; -/*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ -struct reaction { - LDBLE logk[8]; - struct rxn_token *token; -}; -struct rxn_token { - struct species *s; - LDBLE coef; -}; -/*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ -struct species { /* all data pertinent to an aqueous species */ - char *name; /* name of species */ - char *mole_balance; /* formula for mole balance */ - int in; /* species used in model if TRUE */ - int number; - struct master *primary; /* points to master species list, NULL if not primary master */ - struct master *secondary; /* points to master species list, NULL if not secondary master */ - LDBLE gfw; /* gram formula wt of species */ - LDBLE z; /* charge of species */ - LDBLE equiv; /* equivalents in exchange species */ - LDBLE alk; /* alkalinity of species, used for cec in exchange */ - LDBLE carbon; /* stoichiometric coefficient of carbon in species */ - LDBLE co2; /* stoichiometric coefficient of C(4) in species */ - LDBLE h; /* stoichiometric coefficient of H in species */ - LDBLE o; /* stoichiometric coefficient of O in species */ - LDBLE dha, dhb; /* WATEQ Debye Huckel a and b-dot */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ - int count_add_logk; - struct name_coef *add_logk; - LDBLE lg; /* log10 activity coefficient, gamma */ - LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */ - LDBLE lm; /* log10 molality */ - LDBLE la; /* log10 activity */ - LDBLE dg; /* gamma term for jacobian */ - LDBLE dg_total_g; - LDBLE moles; /* moles in solution; moles/mass_water = molality */ - int type; /* flag indicating presence in model and types of equations */ - int gflag; /* flag for preferred activity coef eqn */ - int exch_gflag; /* flag for preferred activity coef eqn */ - struct elt_list *next_elt; /* pointer to next element */ - struct elt_list *next_secondary; - struct elt_list *next_sys_total; - int check_equation; /* switch to check equation for charge and element balance */ - struct reaction *rxn; /* pointer to data base reaction */ - struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary - master species */ - struct reaction *rxn_x; /* reaction to be used in model */ - LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ - LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ - struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each - surface */ -}; -struct logk { /* Named log K's */ - char *name; /* name of species */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE log_k[8]; /* log kt0, delh, 6 coefficients analalytical expression */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ -}; -EXTERNAL struct logk **logk; -EXTERNAL int count_logk; -EXTERNAL int max_logk; -struct species_diff_layer { - struct surface_charge *charge; - int count_g; - LDBLE g_moles; - LDBLE dg_g_moles; /* g_moles*dgterm */ - LDBLE dx_moles; - LDBLE dh2o_moles; /* moles*g*Ws/Waq */ - LDBLE drelated_moles; /* for related phase */ -}; -EXTERNAL char *moles_per_kilogram_string; -EXTERNAL char *pe_string; - -EXTERNAL struct species **s; -EXTERNAL int count_s; -EXTERNAL int max_s; - -EXTERNAL struct species **s_x; -EXTERNAL int count_s_x; -EXTERNAL int max_s_x; - -EXTERNAL struct species *s_h2o; -EXTERNAL struct species *s_hplus ; -EXTERNAL struct species *s_h3oplus ; -EXTERNAL struct species *s_eminus; -EXTERNAL struct species *s_co3; -EXTERNAL struct species *s_h2; -EXTERNAL struct species *s_o2; -/*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ -struct phase { /* all data pertinent to a pure solid phase */ - char *name; /* name of species */ - char *formula; /* chemical formula */ - int in; /* species used in model if TRUE */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ - int count_add_logk; - struct name_coef *add_logk; - LDBLE moles_x; - LDBLE p_soln_x; - LDBLE fraction_x; - LDBLE log10_lambda, log10_fraction_x; - LDBLE dn, dnb, dnc; - LDBLE gn, gntot; - LDBLE gn_n, gntot_n; - - int type; /* flag indicating presence in model and types of equations */ - struct elt_list *next_elt; /* pointer to list of elements in phase */ - /* struct elt_list *next_secondary; */ - struct elt_list *next_sys_total; - int check_equation; /* switch to check equation for charge and element balance */ - struct reaction *rxn; /* pointer to data base reaction */ - struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary - master species */ - struct reaction *rxn_x; /* reaction to be used in model */ - int in_system; -}; -EXTERNAL struct phase **phases; -EXTERNAL int count_phases; -EXTERNAL int max_phases; -/*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ -struct master { /* list of name and number of elements in an equation */ - int in; /* TRUE if in model, FALSE if out, REWRITE if other mb eq */ - int number; /* sequence number in list of masters */ - int last_model; /* saved to determine if model has changed */ - int type; /* AQ or EX */ - int primary; /* TRUE if master species is primary */ - LDBLE coef; /* coefficient of element in master species */ - LDBLE total; /* total concentration for element or valence state */ - LDBLE isotope_ratio; - LDBLE isotope_ratio_uncertainty; - int isotope; - LDBLE total_primary; -/* LDBLE la; */ /* initial guess of master species log activity */ - struct element *elt; /* element structure */ - LDBLE alk; /* alkalinity of species */ - LDBLE gfw; /* default gfw for species */ - char *gfw_formula; /* formula from which to calcuate gfw */ - struct unknown *unknown; /* pointer to unknown structure */ - struct species *s; /* pointer to species structure */ - struct reaction *rxn_primary; /* reaction writes master species in terms of primary - master species */ - struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary - master species */ - struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points - to location */ - int minor_isotope; -}; -EXTERNAL struct master **master; /* structure array of master species */ -EXTERNAL int count_master; -EXTERNAL int max_master; -/*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ -struct unknown { - int type; - LDBLE moles; - LDBLE ln_moles; - LDBLE f; - LDBLE sum; - LDBLE delta; - LDBLE la; - int number; - char *description; - struct master **master; - struct phase *phase; - LDBLE si; - struct gas_phase *gas_phase; - struct conc *total; - struct species *s; - struct exch_comp *exch_comp; - struct pure_phase *pure_phase; - struct s_s *s_s; - struct s_s_comp *s_s_comp; - int s_s_comp_number; - int s_s_in; - struct surface_comp *surface_comp; - LDBLE related_moles; - struct unknown *potential_unknown; - struct unknown *phase_unknown; - struct surface_charge *surface_charge; - LDBLE mass_water; - int dissolve_only; -}; -EXTERNAL struct unknown **x; -EXTERNAL int count_unknowns; -EXTERNAL int max_unknowns; - -EXTERNAL struct unknown *ah2o_unknown; -EXTERNAL struct unknown *alkalinity_unknown; -EXTERNAL struct unknown *carbon_unknown; -EXTERNAL struct unknown *charge_balance_unknown; -EXTERNAL struct unknown *exchange_unknown; -EXTERNAL struct unknown *mass_hydrogen_unknown; -EXTERNAL struct unknown *mass_oxygen_unknown; -EXTERNAL struct unknown *mb_unknown; -EXTERNAL struct unknown *mu_unknown; -EXTERNAL struct unknown *pe_unknown; -EXTERNAL struct unknown *ph_unknown; -EXTERNAL struct unknown *pure_phase_unknown; -EXTERNAL struct unknown *solution_phase_boundary_unknown; -EXTERNAL struct unknown *surface_unknown; -EXTERNAL struct unknown *gas_unknown; -EXTERNAL struct unknown *s_s_unknown; -/*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ -struct reaction_temp { - LDBLE logk[8]; - struct rxn_token_temp *token; -}; -struct rxn_token_temp { /* data for equations, aq. species or minerals */ - char *name; /* pointer to a species name (formula) */ - LDBLE z; /* charge on species */ - struct species *s; - struct unknown *unknown; - LDBLE coef; /* coefficient of species name */ -}; -EXTERNAL struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ -EXTERNAL int count_trxn; /* number of reactants in trxn = position of next */ -EXTERNAL int max_trxn; -struct unknown_list { - struct unknown *unknown; - LDBLE *source; - LDBLE *gamma_source; -/* int row; */ -/* int col; */ - LDBLE coef; -}; -EXTERNAL struct unknown_list *mb_unknowns; -EXTERNAL int count_mb_unknowns; -EXTERNAL int max_mb_unknowns; -/* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ -struct prints { - int all; - int initial_solutions; - int initial_exchangers; - int reactions; - int gas_phase; - int s_s_assemblage; - int pp_assemblage; - int surface; - int exchange; - int kinetics; - int totals; - int eh; - int species; - int saturation_indices; - int irrev; - int mix; - int reaction; - int use; - int logfile; - int punch; - int status; - int inverse; - int dump; - int user_print; - int headings; - int user_graph; - int echo_input; - int warnings; - int initial_isotopes; - int isotope_ratios; - int isotope_alphas; - int hdf; - int alkalinity; -}; -EXTERNAL struct prints pr; -EXTERNAL int status_on; -EXTERNAL int count_warnings; - -/* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ -struct rate { - char *name; - char *commands; - int new_def; - void *linebase; - void *varbase; - void *loopbase; -}; -EXTERNAL struct rate *rates; -EXTERNAL int count_rates; -EXTERNAL LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; -EXTERNAL int count_rate_p; -/* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ -EXTERNAL struct rate *user_print; -EXTERNAL struct rate *user_punch; -EXTERNAL char **user_punch_headings; -EXTERNAL int user_punch_count_headings; -#ifdef PHREEQ98 -EXTERNAL struct rate *user_graph; -EXTERNAL char **user_graph_headings; -EXTERNAL int user_graph_count_headings; -#endif - -/* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ -EXTERNAL char error_string[10*MAX_LENGTH]; -EXTERNAL int simulation; -EXTERNAL int state; -EXTERNAL int reaction_step; -EXTERNAL int transport_step; -EXTERNAL int transport_start; -EXTERNAL int advection_step; -EXTERNAL int stop_program; -EXTERNAL int incremental_reactions; - -EXTERNAL int count_strings; -EXTERNAL int max_strings; - -EXTERNAL LDBLE *array; -EXTERNAL LDBLE *delta; -EXTERNAL LDBLE *residual; - -EXTERNAL int input_error; -EXTERNAL int next_keyword; -EXTERNAL int parse_error; -EXTERNAL int paren_count; -EXTERNAL int iterations; -EXTERNAL int gamma_iterations; -EXTERNAL int run_reactions_iterations; - -EXTERNAL int max_line; -EXTERNAL char *line; -EXTERNAL char *line_save; - -EXTERNAL LDBLE LOG_10; - -EXTERNAL int debug_model; -EXTERNAL int debug_prep; -EXTERNAL int debug_set; -EXTERNAL int debug_diffuse_layer; -EXTERNAL int debug_inverse; - -EXTERNAL LDBLE inv_tol_default; -EXTERNAL int itmax; -EXTERNAL LDBLE ineq_tol; -EXTERNAL LDBLE convergence_tolerance; -EXTERNAL LDBLE step_size; -EXTERNAL LDBLE pe_step_size; -EXTERNAL LDBLE step_size_now; -EXTERNAL LDBLE pe_step_size_now; -EXTERNAL LDBLE pp_scale; -EXTERNAL LDBLE pp_column_scale; -EXTERNAL int diagonal_scale; /* 0 not used, 1 used */ -EXTERNAL int mass_water_switch; -EXTERNAL int delay_mass_water; -EXTERNAL LDBLE censor; -EXTERNAL int aqueous_only; -EXTERNAL int negative_concentrations; - -EXTERNAL int count_total_steps; -EXTERNAL int phast; -EXTERNAL LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; -EXTERNAL int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, llnl_count_co2_coefs; - -EXTERNAL char *selected_output_file_name; -EXTERNAL char *dump_file_name; -struct spread_row { - int count; - int empty, string, number; - char **char_vector; - LDBLE *d_vector; - int *type_vector; -}; -struct defaults { - LDBLE temp; - LDBLE density; - char *units; - char *redox; - LDBLE ph; - LDBLE pe; - LDBLE water; - int count_iso; - struct iso *iso; -}; -struct spread_sheet { - struct spread_row *heading; - struct spread_row *units; - int count_rows; - struct spread_row **rows; - struct defaults defaults; -}; -#ifdef PHREEQCI_GUI -EXTERNAL struct spread_sheet g_spread_sheet; -#endif - -/* ---------------------------------------------------------------------- */ -/* - * Hash definitions - */ -/* -** Constants -*/ - -# define SegmentSize 256 -# define SegmentSizeShift 8 /* log2(SegmentSize) */ -# define DirectorySize 256 -# define DirectorySizeShift 8 /* log2(DirectorySize) */ -# define Prime1 37 -# define Prime2 1048583 -# define DefaultMaxLoadFactor 5 - - -typedef struct Element - { - /* - ** The user only sees the first two fields, - ** as we pretend to pass back only a pointer to ENTRY. - ** {S}he doesn't know what else is in here. - */ - char *Key; - char *Data; - struct Element *Next; /* secret from user */ - } Element,*Segment; - -typedef struct - { - short p; /* Next bucket to be split */ - short maxp; /* upper bound on p during expansion */ - long KeyCount; /* current # keys */ - short SegmentCount; /* current # segments */ - short MinLoadFactor; - short MaxLoadFactor; - Segment *Directory[DirectorySize]; - } HashTable; - -typedef unsigned long Address; - -EXTERNAL HashTable *strings_hash_table; -EXTERNAL HashTable *elements_hash_table; -EXTERNAL HashTable *species_hash_table; -EXTERNAL HashTable *phases_hash_table; -EXTERNAL HashTable *keyword_hash_table; -EXTERNAL HashTable *logk_hash_table; -EXTERNAL HashTable *master_isotope_hash_table; - -#if defined(PHREEQCI_GUI) -#include "../../phreeqci_gui.h" -#endif /* defined(PHREEQCI_GUI) */ - -EXTERNAL struct name_coef match_tokens[50]; -EXTERNAL int count_match_tokens; -struct master_isotope { - char *name; - struct master *master; - struct element *elt; - char *units; - LDBLE standard; - LDBLE ratio; - LDBLE moles; - int total_is_major; - int minor_isotope; -}; -EXTERNAL int count_master_isotope; -EXTERNAL struct master_isotope **master_isotope; -EXTERNAL int max_master_isotope; -EXTERNAL int initial_solution_isotopes; - -#define OPTION_EOF -1 -#define OPTION_KEYWORD -2 -#define OPTION_ERROR -3 -#define OPTION_DEFAULT -4 -#define OPT_1 -5 - -struct calculate_value { - char *name; - LDBLE value; - char *commands; - int new_def; - int calculated; - void *linebase; - void *varbase; - void *loopbase; -}; -EXTERNAL int count_calculate_value; -EXTERNAL struct calculate_value **calculate_value; -EXTERNAL int max_calculate_value; -EXTERNAL HashTable *calculate_value_hash_table; - -struct isotope_ratio { - char *name; - char *isotope_name; - LDBLE ratio; - LDBLE converted_ratio; -}; -EXTERNAL int count_isotope_ratio; -EXTERNAL struct isotope_ratio **isotope_ratio; -EXTERNAL int max_isotope_ratio; -EXTERNAL HashTable *isotope_ratio_hash_table; -struct isotope_alpha { - char *name; - char *named_logk; - LDBLE value; -}; -EXTERNAL int count_isotope_alpha; -EXTERNAL struct isotope_alpha **isotope_alpha; -EXTERNAL int max_isotope_alpha; -EXTERNAL HashTable *isotope_alpha_hash_table; - -EXTERNAL int phreeqc_mpi_myself; - -enum entity_type { Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, Kinetics, Mix, Temperature, UnKnown }; - -EXTERNAL int first_read_input; -EXTERNAL char *user_database; -EXTERNAL int pitzer_model; -EXTERNAL int full_pitzer, always_full_pitzer, ICON, IC; -EXTERNAL double COSMOT; -EXTERNAL double AW; - -EXTERNAL jmp_buf mark; - -#if defined(WIN32) -#include -#endif - -#if defined(WIN32_MEMORY_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif - -#endif /* _INC_GLOBAL_H */ diff --git a/input.cpp b/input.cpp deleted file mode 100644 index 812a92ba..00000000 --- a/input.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#define EXTERNAL extern -#include -#include "global.h" -#include "input.h" -#include "output.h" -#include "phrqproto.h" -#include "phqalloc.h" - -static char const svnid[] = "$Id: input.c 78 2005-02-01 22:47:12Z dlpark $"; - -int check_line_return; - -static struct read_callback s_read_callback; - - -/* ---------------------------------------------------------------------- */ -int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database) -/* ---------------------------------------------------------------------- */ -{ - if (svnid == NULL) fprintf(stderr," "); - s_read_callback.callback = pfn; - s_read_callback.cookie = cookie; - s_read_callback.database = database; - return OK; -} -/* ---------------------------------------------------------------------- */ -int reading_database(void) -/* ---------------------------------------------------------------------- */ -{ - return s_read_callback.database; -} -/* ---------------------------------------------------------------------- */ -int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) -/* ---------------------------------------------------------------------- */ -{ - assert(s_read_callback.callback != NULL); - if (s_read_callback.callback == NULL) return EOF; - if (reading_database()) print = FALSE; - return check_line_impl(s_read_callback.callback, s_read_callback.cookie, string, allow_empty, allow_eof, allow_keyword, print); -} -/* ---------------------------------------------------------------------- */ -int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function gets a new line and checks for empty, eof, and keywords. - * - * Arguments: - * string Input, character string used in printing error message - * allow_empty Input, True or false, if a blank line is accepable - * if false, another line is read - * allow_eof Input, True or false, if EOF is acceptable - * allow_keyword Input, True or false, if a keyword is acceptable - * - * Returns: - * EMPTY if empty line read and allow_empty == true - * KEYWORD if line begins with keyword - * EOF if eof and allow_eof == true - * OK otherwise - * OPTION if line begins with -[alpha] - * - * Terminates if EOF and allow_eof == false. - */ - int i; - - -/* Get line */ - do { - i = get_line(pfn, cookie); - if ((print == TRUE && i != EOF) || i == KEYWORD) { - output_msg(OUTPUT_CHECKLINE,"\t%s\n",line_save); - } - } while ( i == EMPTY && allow_empty == FALSE ); -/* Check eof */ - if ( i == EOF && allow_eof == FALSE ) { - sprintf(error_string,"Unexpected eof while reading %s\nExecution terminated.\n",string); - error_msg(error_string, STOP); - } -/* Check keyword */ - if (i == KEYWORD && allow_keyword == FALSE ) { - sprintf(error_string, "Expected data for %s, but got a keyword ending data block.", string); - error_msg(error_string, CONTINUE); - input_error++; - } - check_line_return = i; - return (i); -} -/* ---------------------------------------------------------------------- */ -int get_line(PFN_READ_CALLBACK pfn, void *cookie) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read a line from input file put in "line". - * Copy of input line is stored in "line_save". - * Characters after # are discarded in line but retained in "line_save" - * - * Arguments: - * fp is file name - * Returns: - * EMPTY, - * EOF, - * KEYWORD, - * OK, - * OPTION - */ - int i, j, return_value, empty, l; - char *ptr; - char token[MAX_LENGTH]; - - return_value = EMPTY; - while (return_value == EMPTY) { -/* - * Eliminate all characters after # sign as a comment - */ - i=-1; - empty=TRUE; -/* - * Get line, check for eof - */ - if (get_logical_line(pfn, cookie, &l) == EOF) { - next_keyword=0; - return (EOF); - } -/* - * Get long lines - */ - j = l; - ptr = strchr (line_save, '#'); - if (ptr != NULL) { - j = ptr - line_save; - } - strncpy(line, line_save, (unsigned) j); - line[j] = '\0'; - for (i = 0; i < j; i++) { - if (! isspace((int) line[i]) ) { - empty = FALSE; - break; - } - } -/* - * New line character encountered - */ - - if (empty == TRUE) { - return_value=EMPTY; - } else { - return_value=OK; - } - } -/* - * Determine return_value - */ - if (return_value == OK) { - if ( check_key(line) == TRUE) { - return_value=KEYWORD; - } else { - ptr = line; - copy_token(token, &ptr, &i); - if (token[0] == '-' && isalpha((int) token[1])) { - return_value = OPTION; - } - } - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads file fp until end of line, ";", or eof - * stores characters in line_save - * reallocs line_save and line if more space is needed - * - * returns: - * EOF on empty line on end of file or - * OK otherwise - * *l returns length of line - */ - int i, j; - int pos; - char c; - i = 0; - if (!pfn) return EOF; - while ((j = pfn(cookie)) != EOF) { - c = (char) j; - if (c == '#') { - /* ignore all chars after # until newline */ - do { - c = (char) j; - if (c == '\n') { - break; - } - add_char_to_line(&i, c); - } while ((j = pfn(cookie)) != EOF); - } - if (c == ';') break; - if (c == '\n') { - break; - } - if (c == '\\') { - pos = i; - add_char_to_line(&i, c); - while ((j = pfn(cookie)) != EOF) { - c = (char) j; - if (c == '\\') { - pos = i; - add_char_to_line(&i, c); - continue; - } - if (c == '\n') { - /* remove '\\' */ - for (; pos < i; pos++) { - line_save[pos] = line_save[pos+1]; - } - i--; - break; - } - add_char_to_line(&i, c); - if (!isspace(j)) break; - } - } else { - add_char_to_line(&i, c); - } - } - if (j == EOF && i == 0) { - *l = 0; - line_save[i] = '\0'; - return(EOF); - } - line_save[i] = '\0'; - *l = i; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_char_to_line(int *i, char c) -/* ---------------------------------------------------------------------- */ -{ - if ( *i + 20 >= max_line) { - max_line *= 2; - line_save = (char *) PHRQ_realloc(line_save, (size_t) max_line * sizeof(char)); - if (line_save == NULL) malloc_error(); - line = (char *) PHRQ_realloc(line, (size_t) max_line * sizeof(char)); - if (line == NULL) malloc_error(); - } - line_save[*i] = c; - *i += 1; - return(OK); -} diff --git a/input.h b/input.h deleted file mode 100644 index ed35503f..00000000 --- a/input.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _INC_INPUT_H -#define _INC_INPUT_H - -#ifdef PHREEQC_IDENT -static char const svnidinput[] = "$Id$"; -#endif -typedef int (*PFN_READ_CALLBACK)(void *cookie); - -struct read_callback { - PFN_READ_CALLBACK callback; - void *cookie; - int database; -}; - -int add_char_to_line(int *i, char c); -int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); -int get_line(PFN_READ_CALLBACK pfn, void *cookie); -int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); -int read_database(PFN_READ_CALLBACK pfn, void *cookie); -int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); -int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); - - -#endif /* _INC_INPUT_H */ diff --git a/integrate.cpp b/integrate.cpp deleted file mode 100644 index 86245c73..00000000 --- a/integrate.cpp +++ /dev/null @@ -1,851 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: integrate.c 78 2005-02-01 22:47:12Z dlpark $"; - -#define MAX_QUAD 20 -#define K_POLY 5 -static LDBLE g_function(LDBLE x_value); -static LDBLE midpnt (LDBLE x1, LDBLE x2, int n); -static void polint(LDBLE *xa, LDBLE *ya, int n, LDBLE xv, LDBLE *yv, LDBLE *dy); -static LDBLE qromb_midpnt (LDBLE x1, LDBLE x2); -static LDBLE z, xd, alpha, G_TOL; -static struct surface_charge *surface_charge_ptr; - -/*static LDBLE calc_psi_avg(char *name);*/ -static LDBLE calc_psi_avg(LDBLE surf_chrg_eq); - -/* ---------------------------------------------------------------------- */ -int calc_all_g( void ) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - int converge, converge1; - int count_g, count_charge; - LDBLE new_g, xd1; - LDBLE epsilon; - - if (svnid == NULL) fprintf(stderr," "); - if (use.surface_ptr == NULL) return(OK); -/* - * calculate g for each surface - */ -#ifdef SKIP - if (punch.high_precision == FALSE) { - epsilon = 1e-8; - G_TOL = 1e-9; - } else { - epsilon = 1.e-12; - G_TOL = 1e-10; - } -#endif - epsilon = convergence_tolerance; - if (convergence_tolerance >= 1e-8) { - G_TOL = 1e-9; - } else { - G_TOL = 1e-10; - } - - converge = TRUE; - count_charge = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - if (debug_diffuse_layer == TRUE) output_msg(OUTPUT_MESSAGE, "Calc_all_g, X[%d]\n", j); - surface_charge_ptr = x[j]->surface_charge; - count_g = 1; - x[j]->surface_charge->g[0].charge = 0.0; - x[j]->surface_charge->g[0].g = 0.0; - x[j]->surface_charge->g[0].dg = 0.0; - xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); - /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ - /* 1000 J/kJ and 1000 L/m**3 */ - alpha = sqrt( EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); -/* - * calculate g for given surface for each species - */ - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type > HPLUS) continue; - for (k=0; k < count_g; k++) { - if (equal(x[j]->surface_charge->g[k].charge, s_x[i]->z, G_TOL) == TRUE) { - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - break; - } - } - if (k < count_g) continue; - - if (x[j]->surface_charge->grams > 0.0) { - z = s_x[i]->z; - if ((use.surface_ptr->only_counter_ions == FALSE) || - (((x[j]->master[0]->s->la > 0) && (z < 0)) || ((x[j]->master[0]->s->la < 0) && (z > 0)))) { - if (xd > 0.1) { - new_g = qromb_midpnt( 1.0, xd); - } else if (xd > 0.01) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, xd); - } else if (xd > 0.001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, xd); - } else if (xd > 0.0001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, xd); - } else if (xd > 0.00001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, .0001); - new_g += qromb_midpnt( 0.0001, xd); - } else if (xd > 0.000001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, .0001); - new_g += qromb_midpnt( 0.0001, .00001); - new_g += qromb_midpnt( 0.00001, xd); - } else if (xd > 0.0000001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, .0001); - new_g += qromb_midpnt( 0.0001, .00001); - new_g += qromb_midpnt( 0.00001, .000001); - new_g += qromb_midpnt( 0.000001, xd); - } else if (xd > 0.00000001) { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, .0001); - new_g += qromb_midpnt( 0.0001, .00001); - new_g += qromb_midpnt( 0.00001, .000001); - new_g += qromb_midpnt( 0.000001, .0000001); - new_g += qromb_midpnt( 0.0000001, xd); - } else { - new_g = qromb_midpnt( 1.0, 0.1); - new_g += qromb_midpnt( 0.1, 0.01); - new_g += qromb_midpnt( 0.01, .001); - new_g += qromb_midpnt( 0.001, .0001); - new_g += qromb_midpnt( 0.0001, .00001); - new_g += qromb_midpnt( 0.00001, .000001); - new_g += qromb_midpnt( 0.000001, .0000001); - new_g += qromb_midpnt( 0.0000001, .00000001); - new_g += qromb_midpnt( 0.00000001, xd); - } - } else { - new_g = 0; - } - } else { - new_g = 0.0; - } - if ((use.surface_ptr->only_counter_ions == TRUE) && new_g < 0) new_g = 0; - x[j]->surface_charge->g[count_g].charge = s_x[i]->z; - converge1 = TRUE; - if (fabs(new_g) >= 1.) { - if (fabs((new_g - x[j]->surface_charge->g[count_g].g)/new_g) > epsilon) { - converge1 = FALSE; - } - } else { - if (fabs(new_g - x[j]->surface_charge->g[count_g].g) > epsilon) { - converge1 = FALSE; - } - } - if (converge1 == FALSE) { - converge = FALSE; - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[count_g].charge, - (double) x[j]->surface_charge->g[count_g].g, - (double) new_g, - (double) (new_g - x[j]->surface_charge->g[count_g].g) ); - } - } - x[j]->surface_charge->g[count_g].g = new_g; - if (new_g == 0) { - x[j]->surface_charge->g[count_g].dg = 0; - } else { - if (x[j]->surface_charge->grams > 0.0) { - x[j]->surface_charge->g[count_g].dg = surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha * g_function(xd) / F_C_MOL; - x[j]->surface_charge->g[count_g].dg *= -2. / - (exp(x[j]->master[0]->s->la * LOG_10) * - exp(x[j]->master[0]->s->la * LOG_10)); - if ((xd - 1) < 0.0) { - x[j]->surface_charge->g[count_g].dg *= -1.0; - } - if (fabs(x[j]->surface_charge->g[count_g].dg) < 1e-8) { - xd1 = exp(-2 * 1e-3 * LOG_10); - - - new_g = qromb_midpnt( 1.0, xd1); - x[j]->surface_charge->g[count_g].dg = new_g/.001; - } - } else { - x[j]->surface_charge->g[count_g].dg = 0.0; - } - } - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = count_g; - count_g++; - - } - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nSurface component %d: charge,\tg,\tdg/dlny,\txd\n", count_charge); - for (i = 0; i < count_g; i++) { - output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg, - (double) xd); - } - } - count_charge++; - } - return (converge); -} -/* ---------------------------------------------------------------------- */ -LDBLE g_function(LDBLE x_value) -/* ---------------------------------------------------------------------- */ -{ - LDBLE sum, return_value, sum1; - int i, j; - LDBLE ln_x_value; - - if (equal(x_value, 1.0, G_TOL*100) == TRUE) return(0.0); - sum = 0.0; - ln_x_value = log(x_value); - for (j = 0; j < use.surface_ptr->charge[0].count_g; j++) { - use.surface_ptr->charge[0].g[j].psi_to_z = - exp(ln_x_value * use.surface_ptr->charge[0].g[j].charge) - 1.0; - } - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { - for(j = 0; j < use.surface_ptr->charge[0].count_g; j++) { - if(use.surface_ptr->charge[0].g[j].charge == s_x[i]->z) { - sum += s_x[i]->moles * use.surface_ptr->charge[0].g[j].psi_to_z; - break; - } - } - } - } - if (sum < 0.0) { - sum = 0.0; - sum1 = 0.0; - output_msg(OUTPUT_MESSAGE, "Species\tmoles\tX**z-1\tsum\tsum charge\n"); - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { - sum += s_x[i]->moles * (pow(x_value, s_x[i]->z) - 1.0); - sum1 += s_x[i]->moles * s_x[i]->z; - output_msg(OUTPUT_MESSAGE, "%s\t%e\t%e\t%e\t%e\n", s_x[i]->name, (double) s_x[i]->moles, (double) (pow(x_value, (double) s_x[i]->z) - 1.0), (double) sum, (double) sum1); - } - } - sprintf(error_string, "Negative sum in g_function, %e\t%e.", (double) sum, (double) x_value); - error_msg(error_string, CONTINUE); - sprintf(error_string, "Solutions must be charge balanced, charge imbalance is %e\n", (double) sum1); - error_msg(error_string, STOP); - } - - return_value = ( exp (ln_x_value * z) - 1) / sqrt((x_value * x_value * mass_water_aq_x * sum )); - return(return_value); -} -/* ---------------------------------------------------------------------- */ -void polint(LDBLE *xa, LDBLE *ya, int n, LDBLE xv, LDBLE *yv, LDBLE *dy) -/* ---------------------------------------------------------------------- */ -{ - int i, m, ns; - LDBLE den, dif, dift, ho, hp, w; - LDBLE *c, *d; - - ns = 1; - dif = fabs(xv-xa[1]); -/* - * Malloc work space - */ - c = (double *) PHRQ_malloc((size_t) (n + 1) * sizeof (LDBLE) ); - if (c == NULL) malloc_error(); - d = (double *) PHRQ_malloc((size_t) (n + 1) * sizeof (LDBLE) ); - if (d == NULL) malloc_error(); - - - - for (i=1; i <= n; i++) { - dift = fabs(xv-xa[i]); - if ( dift < dif ) { - ns = i; - dif = dift; - } - c[i] = ya[i]; - d[i] = ya[i]; - } - - *yv = ya[ns--]; - for (m = 1; m < n; m++) { - for (i=1; i <= n - m; i++) { - ho = xa[i] - xv; - hp = xa[i+m] - xv; - w = c[i+1] - d[i]; - if ( (den=ho-hp) == 0.0) { - error_msg("In subroutine polint.", STOP); - } - den = w/den; - d[i] = hp*den; - c[i] = ho*den; - } - if (2 * ns < (n-m) ) { - *dy = c[ns+1]; - } else { - *dy = d[ns--]; - } - *yv += *dy; - -/* *yv += (*dy = (2 * ns < (n-m) ? c[ns+1] : d[ns--])); */ - } - c = (double *) free_check_null(c); - d = (double *) free_check_null(d); - return; -} -/* ---------------------------------------------------------------------- */ -LDBLE midpnt (LDBLE x1, LDBLE x2, int n) -/* ---------------------------------------------------------------------- */ -{ - LDBLE xv, tnm, sum, del, ddel; - static LDBLE sv; - int it, j; - - if (n == 1) { - sv = (x2-x1) * g_function(0.5 * (x1 + x2)); - return(sv); - } else { - for (it=1, j=1; jgrams * surface_charge_ptr->specific_area * - alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ - if ((x2 - 1) < 0.0) sv[j] *= -1.0; - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "Iterations in qromb_midpnt: %d\n", j); - } - return(sv[j]); - } - - if (j >= K_POLY - 1) { - polint( &h[j - K_POLY], &sv[j - K_POLY], K_POLY, 0.0, &ss, &dss); - if (fabs(dss) <= G_TOL * fabs(ss) || fabs(dss) < G_TOL) { - ss *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * - alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ - if ((x2 - 1) < 0.0) ss *= -1.0; - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "Iterations in qromb_midpnt: %d\n", j); - } - return(ss); - } - } - - } - sprintf(error_string, "\nToo many iterations integrating diffuse layer.\n"); - error_msg(error_string, STOP); - return(-999.9); -} -/* ---------------------------------------------------------------------- */ -int calc_init_g(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - int count_g, count_charge; - - if (use.surface_ptr == NULL) return(OK); - -/* - * calculate g for each surface - */ - count_charge = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; - count_g = 0; - if (x[j]->surface_charge->g != NULL) { - count_g = x[j]->surface_charge->count_g; - } - if( count_g == 0 ) { - x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_malloc((size_t) sizeof(struct surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) malloc_error(); - x[j]->surface_charge->g[0].charge = 0.0; - x[j]->surface_charge->g[0].g = 0.0; - x[j]->surface_charge->g[0].dg = 0.0; - xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); - /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ - /* second 1000 is liters/m**3 */ - alpha = sqrt( EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); - } -/* - * calculate g for given surface for each species - */ - count_g = 1; - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type > HPLUS) continue; - for (k=0; k < count_g; k++) { - if (equal(x[j]->surface_charge->g[k].charge, s_x[i]->z, G_TOL) == TRUE) { - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - break; - } - } - if (k >= count_g) { - - /* malloc space to save g for charge */ - x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_realloc(x[j]->surface_charge->g, - (size_t) (count_g + 1) * - sizeof(struct surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) malloc_error(); - - /* save g for charge */ - x[j]->surface_charge->g[count_g].charge = s_x[i]->z; - if (x[j]->surface_charge->grams > 0.0) { - x[j]->surface_charge->g[count_g].g = 2 * alpha * sqrt(mu_x) * (pow(xd, s_x[i]->z / 2.0) - 1) *surface_charge_ptr->grams * surface_charge_ptr->specific_area / F_C_MOL; - x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; - if ((use.surface_ptr->only_counter_ions == TRUE) && - x[j]->surface_charge->g[count_g].g < 0) { - x[j]->surface_charge->g[count_g].g = 0; - x[j]->surface_charge->g[count_g].dg = 0; - } - } else { - x[j]->surface_charge->g[count_g].g = 0.0; - x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; - } - /* save g for species */ - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = count_g; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - count_g++; - } - } - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nSurface component %d: charge,\tg,\tdg\n", count_charge); - for (i = 0; i < count_g; i++) { - output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, (double) x[j]->surface_charge->g[i].g, (double) x[j]->surface_charge->g[i].dg ); - } - } - count_charge++; - x[j]->surface_charge->count_g = count_g; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int initial_surface_water(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * In initial surface calculation, need to calculate - * mass of water in diffuse layer. - * diffuse layer water + aqueous solution water = bulk water. - * Ionic strength is fixed, so diffuse-layer water will not change - */ - int i; -/*#define DEBYE*/ -#ifdef DEBYE - LDBLE debye_length; - LDBLE volume_diffuse_layer; -#endif - LDBLE mass_water_surface; -/* - * Debye length = 1/k = sqrt[eta*eta_zero*R*T/(2*F**2*mu_x*1000)], Dzombak and Morel, p 36 - * - * 1000 converts kJ to J; 1000 converts Liters to meter**3; debye_length is in meters. - */ -#ifdef DEBYE - debye_length = (EPSILON * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) - / (2. * F_C_MOL * F_C_MOL * mu_x * 1000.); - debye_length = sqrt(debye_length); -#endif -/* - * Loop through all surface components, calculate each H2O surface (diffuse layer), - * H2O aq, and H2O bulk (diffuse layers plus aqueous). - */ - mass_water_surfaces_x = 0.0; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != SURFACE_CB) continue; -#ifdef DEBYE - /* 1000 converts volume from m**3 to Liters */ - volume_diffuse_layer = x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams * debye_length * 1000; - - /* Assume mol/L = mol/kgw */ - mass_water_surface = volume_diffuse_layer; -#else - /* make constant thickness of, default 1e-8 m (100 Angstroms) */ - mass_water_surface = x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams * use.surface_ptr->thickness * 1000; -#endif - x[i]->surface_charge->mass_water = mass_water_surface; - mass_water_surfaces_x += mass_water_surface; - } - mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) -/* ---------------------------------------------------------------------- */ -{ - int i, j, count_g; - LDBLE mass_water_surface; - LDBLE molality, moles_excess, moles_surface; - - if (use.surface_ptr == NULL) return(OK); -/* - * Find position of component in list of components - */ - i = 0; - - for (j =0; j < use.surface_ptr->count_charge; j++) { - if (&(use.surface_ptr->charge[j]) == surface_charge_ptr1) { - i = j; - break; - } - } - if (j >= use.surface_ptr->count_charge) { - sprintf(error_string, "In sum_diffuse_layer, component not found, %s.", surface_charge_ptr1->name); - error_msg(error_string, STOP); - } -/* - * Loop through all surface components, calculate each H2O surface (diffuse layer), - * H2O aq, and H2O bulk (diffuse layers plus aqueous). - */ - count_elts = 0; - paren_count = 0; - mass_water_surface = surface_charge_ptr1->mass_water; - for (j = 0; j < count_s_x; j++) { - if (s_x[j]->type > HPLUS) continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; -#ifdef SKIP - moles_excess = mass_water_bulk_x * -/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ - surface_charge_ptr1->g[count_g].g * molality; -#endif - moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; - - moles_surface = mass_water_surface * molality + moles_excess; -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } - add_elt_list(s_h2o->next_elt, mass_water_surface / gfw_water); - - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int calc_all_donnan(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - int count_g, count_charge, converge; - char name[MAX_LENGTH]; - LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; - LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif; - - if (use.surface_ptr == NULL) return(OK); - f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); -/* - * calculate g for each surface... - */ - converge = TRUE; - count_charge = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; - - if (debug_diffuse_layer == TRUE) output_msg(OUTPUT_MESSAGE, "Calc_all_g, X[%d]\n", j); -/* - * sum eq of each charge number in solution... - */ - count_g = x[j]->surface_charge->count_g; - for (i = 0; i < count_g; i++) { - charge_group[i].eq = 0.0; - } - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { - charge_group[k].eq += s_x[i]->z * s_x[i]->moles; - break; - } - } - } - /* find surface charge from potential... */ - A_surf = x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; - f_psi = x[j]->master[0]->s->la * LOG_10; - surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; - /* also for the derivative... */ - dif = 1e-5; - f_psi2 = f_psi + dif; - surf_chrg_eq2 = A_surf * f_sinh * sinh(f_psi2) / F_C_MOL; - - - /* find psi_avg that matches surface charge... */ - psi_avg = calc_psi_avg(surf_chrg_eq); - psi_avg2 = calc_psi_avg(surf_chrg_eq2); - - /* fill in g's */ - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; - - for (k = 0; k < count_g; k++) { - x[j]->surface_charge->g[k].charge = charge_group[k].z; - - new_g = exp(-charge_group[k].z * psi_avg) - 1; - if (new_g <= - ratio_aq) new_g = G_TOL; - new_g2 = exp(-charge_group[k].z * psi_avg2) - 1; - if (new_g2 <= - ratio_aq) new_g2 = G_TOL; - - if (fabs(new_g) >= 1) { - if (fabs((new_g - x[j]->surface_charge->g[k].g) / new_g) > convergence_tolerance) { - converge = FALSE; - } - } else { - if (fabs(new_g - x[j]->surface_charge->g[k].g) > convergence_tolerance) { - converge = FALSE; - } - } - x[j]->surface_charge->g[k].g = new_g; - if (new_g != 0) { - x[j]->surface_charge->g[k].dg = (new_g2 - new_g) / dif; - } else { - x[j]->surface_charge->g[k].dg = -charge_group[k].z; - } - /* save g for species */ - for (i = 0; i < count_s_x; i++) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - } - } - } - if (debug_diffuse_layer == TRUE) { - strcpy(name, x[j]->master[0]->elt->name); - replace ("_psi", "", name); -/* surf_chrg_eq = calc_surface_charge(name); - */ - output_msg(OUTPUT_MESSAGE, "\nDonnan all on %s (%d): charge, \tg, \tdg, Psi_surface = %8f V. \n", name, count_charge, - x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ); - for (i = 0; i < count_g; i++) { - output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg); - } - } - count_charge++; - } - return (converge); -} -/* ---------------------------------------------------------------------- */ -int calc_init_donnan(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - int count_g, count_charge; - char name[MAX_LENGTH]; - LDBLE f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; - - if (use.surface_ptr == NULL) return(OK); - f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); -/* - * sum eq of each charge number in solution... - */ - charge_group = (struct charge_group *) free_check_null(charge_group); - charge_group = (struct charge_group *) PHRQ_malloc((size_t) sizeof(struct charge_group)); - if (charge_group == NULL) malloc_error(); - charge_group[0].z = 0.0; - charge_group[0].eq = 0.0; - - count_g = 1; - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { - charge_group[k].eq += s_x[i]->z * s_x[i]->moles; - break; - } - } - if (k >= count_g) { - charge_group = (struct charge_group *) PHRQ_realloc(charge_group, (size_t) (count_g + 1) * - sizeof(struct charge_group)); - if (charge_group == NULL) malloc_error(); - charge_group[count_g].z = s_x[i]->z; - charge_group[count_g].eq = s_x[i]->z * s_x[i]->moles; - - count_g++; - } - } -/* - * calculate g for each surface... - */ - count_charge = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; - - x[j]->surface_charge->g = (struct surface_diff_layer *) PHRQ_malloc((size_t) count_g * sizeof(struct surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) malloc_error(); - x[j]->surface_charge->count_g = count_g; - - /* find surface charge from potential... */ - A_surf = x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; - f_psi = x[j]->master[0]->s->la * LOG_10; - surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; - - /* find psi_avg that matches surface charge... */ - psi_avg = calc_psi_avg(surf_chrg_eq); - - /* fill in g's */ - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; - - for (k = 0; k < count_g; k++) { - x[j]->surface_charge->g[k].charge = charge_group[k].z; - x[j]->surface_charge->g[k].g = exp(-charge_group[k].z * psi_avg) - 1; - if (x[j]->surface_charge->g[k].g != 0) { - x[j]->surface_charge->g[k].dg = - A_surf * f_sinh * cosh(f_psi) / - (charge_group[k].eq * F_C_MOL); - } else { - x[j]->surface_charge->g[k].dg = -charge_group[k].z; - } - /* save g for species */ - for (i = 0; i < count_s_x; i++) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) { - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - } - } - } - if (debug_diffuse_layer == TRUE) { - strcpy(name, x[j]->master[0]->elt->name); - replace ("_psi", "", name); -/* surf_chrg_eq = calc_surface_charge(name); - */ - output_msg(OUTPUT_MESSAGE, "\nDonnan init on %s : charge, \tg, \tdg, Psi_surface = %8f V. \n", name, - x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ); - for (i = 0; i < count_g; i++) { - output_msg(OUTPUT_MESSAGE, "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, (double) x[j]->surface_charge->g[i].g, (double) x[j]->surface_charge->g[i].dg ); - } - } - count_charge++; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_psi_avg(LDBLE surf_chrg_eq) -/* ---------------------------------------------------------------------- */ -{ -/* - * calculate the average (F * Psi / RT) that lets the DL charge counter the surface charge - */ - int i, iter, count_g; - LDBLE fd, fd1, p, temp, ratio_aq; -/* LDBLE dif; - */ - count_g = surface_charge_ptr->count_g; - if (convergence_tolerance >= 1e-8) { - G_TOL = 1e-9; - } else { - G_TOL = 1e-10; - } - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; - p = 0; - if (surf_chrg_eq == 0) { - return(0.0); - } else if (surf_chrg_eq < 0) { - p = -0.5 * log(-surf_chrg_eq * ratio_aq / mu_x + 1); - } else if (surf_chrg_eq > 0) { - p = 0.5 * log(surf_chrg_eq * ratio_aq / mu_x + 1); - } -/* - * Optimize p in SS{s_x[i]->moles * z_i * g(p)} = -surf_chrg_eq - * g(p) = exp(-p * z_i) - 1 - */ - iter = 0; - do { - fd = surf_chrg_eq; - fd1 = 0.0; - for (i = 1; i < count_g; i++) { - temp = exp(-charge_group[i].z * p); - if (temp > 1 - ratio_aq) { - fd += charge_group[i].eq * (temp - 1); - fd1 -= charge_group[i].z * charge_group[i].eq * temp; - } - } -/* fd1 = surf_chrg_eq * ratio_aq; - dif = 1e-5; - p += dif; - for (i = 1; i < count_g; i++) { - temp = exp(-charge_group[i].z * p); - fd1 += charge_group[i].eq * temp; - } - fd /= -(fd1 - fd) / dif; - p -= dif; - p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); - */ - fd /= -fd1; - p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); - if (fabs(p) < G_TOL) p = 0.0; - iter++; - if (iter > 50) { - sprintf(error_string, "\nToo many iterations for surface in subroutine calc_psi_avg.\n"); - error_msg(error_string, STOP); - } - } while (fabs(fd) > G_TOL && p != 0.0); - if (debug_diffuse_layer == TRUE) - output_msg(OUTPUT_MESSAGE, "iter in calc_psi_avg = %d. g(+1) = %8f. surface charge = %8f.\n", - iter, (double) (exp(-p) - 1), (double) surf_chrg_eq); - - return(p); -} diff --git a/inverse.cpp b/inverse.cpp deleted file mode 100644 index a1227358..00000000 --- a/inverse.cpp +++ /dev/null @@ -1,3014 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: inverse.c 588 2005-10-11 20:29:31Z dlpark $"; - -#define MAX_MODELS 20 -#define MIN_TOTAL_INVERSE 1e-14 - -#ifdef INVERSE_CL1MP -/* cl1mp.c */ -extern int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE *x_arg, LDBLE *res_arg, LDBLE *error, - LDBLE *cu_arg, int *iu, int *s, int check, LDBLE censor_arg); -#endif - -/* variables local to module */ - -int max_row_count, max_column_count; -static int carbon; -char **col_name, **row_name; -static int count_rows, count_optimize; -static int col_phases, col_redox, col_epsilon, col_ph, col_water, col_isotopes, col_phase_isotopes; -static int row_mb, row_fract, row_charge, row_carbon, row_isotopes, row_epsilon, row_isotope_epsilon, row_water; -static LDBLE *zero, *array1, *res, *delta1, *delta2, *delta3, *cu, *delta_save; -static LDBLE *min_delta, *max_delta; -static int *iu, *is; -static int klmd, nklmd, n2d, kode, iter; -static LDBLE toler, error, max_pct, scaled_error; -static struct master *master_alk; -int *row_back, *col_back; - -static unsigned long *good, *bad, *minimal; -static int max_good, max_bad, max_minimal; -static int count_good, count_bad, count_minimal, count_calls; -static unsigned long soln_bits, phase_bits, current_bits, temp_bits; - -/* subroutines */ - -static int bit_print(unsigned long bits, int l); -static int carbon_derivs(struct inverse *inv_ptr); -static int check_isotopes(struct inverse *inv_ptr); -static int check_solns(struct inverse *inv_ptr); -static int count_isotope_unknowns(struct inverse *inv_ptr, struct isotope **isotope_unknowns); -static int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); -static int post_mortem(void); -static unsigned long get_bits(unsigned long bits, int position, int number); -static unsigned long minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits); -static int next_set_phases(struct inverse *inv_ptr, - int first_of_model_size, - int model_size); -static int phase_isotope_inequalities(struct inverse *inv_ptr); -static int print_model(struct inverse *inv_ptr); -static int punch_model_heading(struct inverse *inv_ptr); -static int punch_model(struct inverse *inv_ptr); -static int range(struct inverse *inv_ptr, unsigned long cur_bits); -static int save_bad(unsigned long bits); -static int save_good(unsigned long bits); -static int save_minimal(unsigned long bits); -static unsigned long set_bit(unsigned long bits, int position, int value); -static int setup_inverse(struct inverse *inv_ptr); -static int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *soln_ptr_orig, - int n_user_new, - LDBLE d_alk, - LDBLE ph_factor, - LDBLE alk_factor); -static int shrink(struct inverse *inv_ptr, LDBLE *array_in, LDBLE *array_out, - int *k, int *l, int *m, int *n, - unsigned long cur_bits, - LDBLE *delta_l, int *col_back_l, int *row_back_l); -static int solve_inverse(struct inverse *inv_ptr); -static int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); -static int subset_bad(unsigned long bits); -static int subset_minimal(unsigned long bits); -static int superset_minimal(unsigned long bits); -static int write_optimize_names(struct inverse *inv_ptr); - -#ifdef SKIP -#define SCALE_EPSILON .0009765625 -#define SCALE_WATER .0009765625 -#define SCALE_ALL 16 -#endif -#define SCALE_EPSILON .0009765625 -#define SCALE_WATER 1. -#define SCALE_ALL 1. - -/* ---------------------------------------------------------------------- */ -int inverse_models(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of inverse models, make calculations - * for any marked "new". - */ - int n, print1; - - if (svnid == NULL) fprintf(stderr," "); - array1 = NULL; - zero = NULL; - res = NULL; - delta1 = NULL; - delta2 = NULL; - delta3 = NULL; - delta_save = NULL; - cu = NULL; - iu = NULL; - is = NULL; - col_name = NULL; - row_name = NULL; - min_delta = NULL; - max_delta = NULL; - good = NULL; - bad = NULL; - minimal = NULL; - - print1 = TRUE; - state = INVERSE; - diffuse_layer_x = FALSE; - for (n=0; n < count_inverse; n++) { - if (inverse[n].new_def == TRUE) { -/* - * Fill in stucture "use". - */ - use.inverse_in = TRUE; - use.inverse_ptr = &inverse[n]; - use.n_inverse_user = inverse[n].n_user; -/* - * Initial prints - */ - sprintf(error_string,"Beginning of inverse modeling %d calculations.", inverse[n].n_user); - dup_print(error_string, TRUE); - - if (inverse[n].mp == TRUE) { - output_msg(OUTPUT_MESSAGE, "Using Cl1MP multiprecision optimization routine.\n"); - - } else { - output_msg(OUTPUT_MESSAGE, "Using Cl1 standard precision optimization routine.\n"); - } - status(0, NULL); - -/* - * Setup and solve - */ - count_calls = 0; - setup_inverse(&(inverse[n])); - punch_model_heading(&inverse[n]); - solve_inverse(&(inverse[n])); - if (inverse[n].count_isotope_unknowns > 0 ) { - inverse[n].isotope_unknowns = (struct isotope *) free_check_null(inverse[n].isotope_unknowns); - } - inverse[n].new_def = FALSE; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_inverse(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in array for an inverse problem - */ - int i, j, k, i_alk, i_carb; - int max; - int count_rows_t; - int column, row; - int temp, temppun; - LDBLE isotope_number; - LDBLE f, coef, cb, conc; - char token[MAX_LENGTH]; - struct phase *phase_ptr; - struct solution *solution_ptr; - struct reaction *rxn_ptr; - struct master *master_ptr; -/* - * Determine array sizes, row and column positions - */ - toler = inv_ptr->tolerance; - if (inv_ptr->mp == TRUE) { - toler = inv_ptr->mp_tolerance; - } -/* - * Alkalinity derivatives with pH and carbon - */ - carbon = 1; - temp = pr.status; - pr.status = FALSE; - temppun = punch.in; - punch.in = FALSE; - carbon_derivs(inv_ptr); - pr.status = temp; - punch.in = temppun; - state = INVERSE; -/* - * tidy isotopes if necessary - */ - inv_ptr->count_isotope_unknowns = 0; - if (inv_ptr->count_isotopes > 0) { - inv_ptr->count_isotope_unknowns = count_isotope_unknowns(inv_ptr, &inv_ptr->isotope_unknowns); - if (input_error > 0) { - error_msg("Stopping because of input errors.", STOP); - } - check_isotopes(inv_ptr); - if (input_error > 0) { - error_msg("Stopping because of input errors.", STOP); - } - } - -/* - * count unknowns - */ - max_column_count = inv_ptr->count_elts * inv_ptr->count_solns + /* epsilons */ - inv_ptr->count_solns + /* solutions */ - inv_ptr->count_phases + /* phases */ - inv_ptr->count_redox_rxns + /* redox reactions */ - carbon * inv_ptr->count_solns + /* pH */ - 1 + /* water */ - inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* isotopes in solution*/ - inv_ptr->count_isotopes * inv_ptr->count_phases + /* isotopes in phases */ - 1 + 1; /* rhs, ineq */ - count_unknowns = max_column_count - 2; - col_phases = inv_ptr->count_solns; - col_redox = col_phases + inv_ptr->count_phases; - col_epsilon = col_redox + inv_ptr->count_redox_rxns; - col_ph = col_epsilon + inv_ptr->count_elts * inv_ptr->count_solns; - col_water = col_ph + carbon * inv_ptr->count_solns; - col_isotopes = col_water + 1; - col_phase_isotopes = col_isotopes + inv_ptr->count_isotope_unknowns * inv_ptr->count_solns; - max_row_count = - inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ - carbon * inv_ptr->count_solns + /* optimize ph */ - 1 + /* optimize water */ - inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ - inv_ptr->count_isotopes * inv_ptr->count_phases + /* optimize phase isotopes */ - inv_ptr->count_elts + /* mass balances */ - 1 + 1 + /* fractions, init and final */ - inv_ptr->count_solns + /* charge balances */ - carbon * inv_ptr->count_solns + /* dAlk = dC + dph */ - inv_ptr->count_isotopes + /* isotopes */ - 2 * inv_ptr->count_solns * inv_ptr->count_elts + /* epsilon constraints */ - 2 * carbon * inv_ptr->count_solns + /* epsilon on ph */ - 2 + /* epsilon for water */ - 2 * inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* epsilon for isotopes */ - 2 * inv_ptr->count_isotopes * inv_ptr->count_phases + /* epsilon for isotopes in phases */ - 2; /* work space */ - - row_mb =inv_ptr->count_solns * inv_ptr->count_elts + - carbon * inv_ptr->count_solns + 1 + - inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + - inv_ptr->count_isotopes * inv_ptr->count_phases; - row_fract = row_mb + inv_ptr->count_elts; - row_charge = row_fract + 2; - row_carbon = row_charge + inv_ptr->count_solns; - row_isotopes = row_carbon + carbon * inv_ptr->count_solns; - row_epsilon = row_isotopes + inv_ptr->count_isotopes; -/* The next three are not right, some rows of epsilon are deleted */ -/* - row_ph_epsilon = row_epsilon + 2 * inv_ptr->count_solns * inv_ptr->count_elts; - row_water_epsilon = row_ph + 2 * carbon * inv_ptr->count_solns; - row_isotope_epsilon - row_isotope_phase_epsilon - */ -/* - * Malloc space for arrays - */ - array = (LDBLE *) free_check_null(array); - array = (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * sizeof(LDBLE)); - if (array == NULL) malloc_error(); - - array1 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * sizeof(LDBLE)); - if (array1 == NULL) malloc_error(); - - col_name = (char **) PHRQ_malloc((size_t) max_column_count * sizeof(char *)); - if (col_name == NULL) malloc_error(); - - row_name = (char **) PHRQ_malloc((size_t) max_row_count * sizeof(char *)); - if (row_name == NULL) malloc_error(); - - delta = (LDBLE *) free_check_null (delta); - delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (delta == NULL) malloc_error(); - - delta1 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (delta1 == NULL) malloc_error(); - - delta2 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (delta2 == NULL) malloc_error(); - - delta3 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (delta3 == NULL) malloc_error(); - - delta_save = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (delta_save == NULL) malloc_error(); - - min_delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (min_delta == NULL) malloc_error(); - - max_delta = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (max_delta == NULL) malloc_error(); - - res = (LDBLE *) PHRQ_malloc((size_t) max_row_count*sizeof(LDBLE)); - if (res == NULL) malloc_error(); - - if (max_column_count < max_row_count) { - max = max_row_count; - } else { - max = max_column_count; - } - zero = (LDBLE *) PHRQ_malloc((size_t) max * sizeof(LDBLE)); - if (zero == NULL) malloc_error(); -/* - * Define zero and zero array, delta - */ - for (i = 0; i < max; i++) zero[i] = 0.0; - - memcpy((void *) &(delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - for (i = 0; i < max_row_count; i++) { - memcpy((void *) &(array[i*max_column_count]), (void *) &(zero[0]), - (size_t) max_column_count * sizeof(LDBLE)); - } -/* - * begin filling array - */ - count_rows = 0; -/* - * optimization - */ - count_optimize = inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ - carbon * inv_ptr->count_solns + /* optimize ph */ - 1 + /* optimize water */ - inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ - inv_ptr->count_isotopes * inv_ptr->count_phases; /* optimize phase isotopes */ - - for (i = 0; i < count_optimize; i++) { - row_name[count_rows] = string_hsave("optimize"); - count_rows++; - } - write_optimize_names(inv_ptr); -/* - * equalities - */ - -/* - * Mass_balance: solution data - */ - - /* initialize master species */ - for (i = 0; i < count_master; i++) { - master[i]->in = -1; - if (strstr(master[i]->elt->name, "Alk") == master[i]->elt->name) { - master_alk = master[i]; - } - } - /* mark master species included in model, write row names*/ - count_rows_t = count_rows; - i_alk = -1; - i_carb = -1; - for (i = 0; i < inv_ptr->count_elts; i++) { - master_ptr = inv_ptr->elts[i].master; - if (master_ptr == master_alk) i_alk = i; - if (strcmp(master_ptr->elt->name,"C(4)") == 0) i_carb = i; - inv_ptr->elts[i].master->in = count_rows_t; - row_name[count_rows_t] = inv_ptr->elts[i].master->elt->name; - count_rows_t++; - } - /* put concentrations in array */ - for (i=0; i < inv_ptr->count_solns; i++) { - xsolution_zero(); - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - if (solution_ptr == NULL) { - sprintf(error_string, "Solution number %d not found.", - inv_ptr->solns[i]); - error_msg(error_string, STOP); - } - /* write master species concentrations */ - for (j=0; solution_ptr->totals[j].description != NULL; j++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - master_ptr->total += solution_ptr->totals[j].moles; - /* List elements not included in model */ - if (master_ptr->in < 0) { - sprintf(error_string, "%s is included in solution %d, but is not included as a mass-balance constraint.", - solution_ptr->totals[j].description, - inv_ptr->solns[i]); - warning_msg(error_string); - } - } - master_alk->total = solution_ptr->total_alkalinity; - f = 1.0; - if (i == (inv_ptr->count_solns - 1)) { - f = -1.0; - } - column = i; - sprintf(token, "soln %d", i); - col_name[column] = string_hsave(token); - for(j=0; j < count_master; j++) { - if (master[j]->in >= 0) { - array[master[j]->in * max_column_count + i] = f * master[j]->total; - if (master[j]->s == s_eminus) { - array[master[j]->in * max_column_count + i] = 0.0; - } - } - } - /* calculate charge balance for elements in model */ - cb = 0; - for(j=0; j < count_master; j++) { - if (master[j]->in >= 0) { - if (master[j]->s == s_eminus) { - coef = 0.0; - } else if (master[j] == master_alk) { - coef = -1.0; - } else { - coef = master[j]->s->z + master[j]->s->alk; - } - cb += coef * master[j]->total; - } - } - if (fabs(cb) < toler) cb = 0.0; - array[(row_charge + i) * max_column_count + i] = cb; - } - -/* mass_balance: phase data */ - - for (i = 0; i < inv_ptr->count_phases; i++) { - phase_ptr = inv_ptr->phases[i].phase; - rxn_ptr = phase_ptr->rxn_s; - column = col_phases + i; - col_name[column] = phase_ptr->name; - for (j = 1; rxn_ptr->token[j].s != NULL; j++) { - if (rxn_ptr->token[j].s->secondary != NULL) { - master_ptr = rxn_ptr->token[j].s->secondary; - } else { - master_ptr = rxn_ptr->token[j].s->primary; - } - if (master_ptr == NULL) { - sprintf(error_string, "Setup_inverse, reaction for phase, %s.", phase_ptr->name); - error_msg(error_string, STOP); - } - if (master_ptr->s == s_hplus) continue; - if (master_ptr->s == s_h2o) { - row = row_fract; -/* turn off h2o from minerals in water mass balance */ - if (inv_ptr->mineral_water != TRUE) continue; - - } else { - row = master_ptr->in; - } - /* e- has coef of 0 for some reason */ - coef = master_ptr->coef; - if (coef <= 0) coef = 1.0; - array[row*max_column_count + column] = rxn_ptr->token[j].coef * coef; - } - row = master_alk->in; /* include alkalinity for phase */ - array[row * max_column_count + column] = calc_alk(rxn_ptr); - } - -/* mass balance: redox reaction data */ - - k = 0; - for (i = 0; i < inv_ptr->count_elts; i++) { - if (inv_ptr->elts[i].master->s->primary == NULL) { - coef = inv_ptr->elts[i].master->coef ; - rxn_ptr = inv_ptr->elts[i].master->rxn_primary; - column = col_redox + k; - col_name[column] = inv_ptr->elts[i].master->elt->name; - k++; - for (j = 0; rxn_ptr->token[j].s != NULL; j++) { - if (rxn_ptr->token[j].s->secondary != NULL) { - master_ptr = rxn_ptr->token[j].s->secondary; - } else { - master_ptr = rxn_ptr->token[j].s->primary; - } - if (master_ptr == NULL) { - sprintf(error_string, "Subroutine setup_inverse, element not found, %s.", rxn_ptr->token[j].s->name); - error_msg(error_string, STOP); - } - if (master_ptr->s == s_hplus) continue; - if (master_ptr->s == s_h2o) { - row = row_fract; -/* turn off h2o from minerals in water mass balance */ - if (inv_ptr->mineral_water != TRUE) continue; - } else { - row = master_ptr->in; - } - array[row*max_column_count + column] = rxn_ptr->token[j].coef; - /* if coefficient of element is not 1.0 in master species */ - if (j != 0) array[row*max_column_count + column] /= coef; - } - row = master_alk->in; /* include alkalinity for redox reaction */ - array[row * max_column_count + column] = ( calc_alk(rxn_ptr) - inv_ptr->elts[i].master->s->alk ) / coef; - } - } - -/* mass-balance: epsilons */ - - column = col_epsilon; - for (i = 0; i < inv_ptr->count_elts; i++) { - row = inv_ptr->elts[i].master->in; - for (j = 0; j < inv_ptr->count_solns; j++) { - if (j < (inv_ptr->count_solns - 1)) { - array[row * max_column_count + column] = 1.0; - } else { - array[row * max_column_count + column] = -1.0; - } - if (inv_ptr->elts[i].master->s == s_eminus) { - array[row * max_column_count + column] = 0.0; - } - sprintf(token, "%s %d", row_name[row], j); - col_name[column] = string_hsave(token); - column++; - } - } - count_rows += inv_ptr->count_elts; - -/* put names in col_name for ph */ - - for (i = 0; i < inv_ptr->count_solns; i++) { - sprintf(token, "ph %d", i); - col_name[column] = string_hsave(token); - column++; - } -/* put names in col_name for water */ - - sprintf(token, "water"); - col_name[column] = string_hsave(token); - column++; - -/* put names of isotopes in col_name */ - for (i = 0; i < inv_ptr->count_solns; i++) { - for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - sprintf(token, "%d%s %d", - (int) inv_ptr->isotope_unknowns[j].isotope_number, - inv_ptr->isotope_unknowns[j].elt_name, i); - col_name[column] = string_hsave(token); - column++; - } - } - -/* put phase isotopes in col_name */ - - if (inv_ptr->count_isotopes > 0) { - /* isotopes of phases phases */ - for (i = 0; i < inv_ptr->count_phases; i++) { - for (j = 0; j < inv_ptr->count_isotopes; j++) { - sprintf(token, "%d%s %s", - (int) inv_ptr->isotopes[j].isotope_number, - inv_ptr->isotopes[j].elt_name, - inv_ptr->phases[i].phase->name); - col_name[column] = string_hsave(token); - column++; - } - } - } -/* - * Initial solution mixing fractions or water mass balance - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - if (i < inv_ptr->count_solns - 1) { - array[count_rows * max_column_count + i] = 1.0 / gfw_water * solution_ptr->mass_water; - } else { - array[count_rows * max_column_count + inv_ptr->count_solns - 1] = - 1.0 / gfw_water * solution_ptr->mass_water; - } - } - /* coefficient for water uncertainty */ - if (inv_ptr->water_uncertainty > 0 ) { - array[count_rows * max_column_count + col_water] = 1.0; - } - row_name[count_rows] = string_hsave("H2O"); - row_water = count_rows; - count_rows++; - -/* - * Final solution fraction equals 1.0 - */ - - array[count_rows * max_column_count + inv_ptr->count_solns - 1] = 1.0 ; - array[count_rows * max_column_count + count_unknowns] = 1.0; - row_name[count_rows] = string_hsave("fract, final"); - count_rows++; - -/* - * Charge balance: - */ - - for (i = 0; i < inv_ptr->count_solns; i++) { -/* solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); */ -/* array[count_rows * max_column_count + i] = solution_ptr->cb; */ - for (j = 0; j < inv_ptr->count_elts; j++) { - column = col_epsilon + j * inv_ptr->count_solns + i; - coef = inv_ptr->elts[j].master->s->z + inv_ptr->elts[j].master->s->alk; - if (inv_ptr->elts[j].master == master_alk) { - coef = -1.0; - } - array[count_rows * max_column_count + column] = coef; - if (inv_ptr->elts[j].master->s == s_eminus) { - array[count_rows * max_column_count + column] = 0.0; - } - } - sprintf(token, "%s %d", "charge", i); - row_name[count_rows] = string_hsave(token); - count_rows++; - } -/* - * dC = (dC/dph)*dph + (dC/dAlk)*dAlk for each solution - */ -/* - * dAlk = (dAlk/dC)*dC + (dAlk/dpH)*dpH for each solution - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - if (inv_ptr->dalk_dph[i] != 0 || inv_ptr->dalk_dc[i] != 0) { - column = col_ph + i; - array[count_rows * max_column_count + column] = inv_ptr->dalk_dph[i]; - column = col_epsilon + i_alk * inv_ptr->count_solns + i; - array[count_rows * max_column_count + column] = -1.0; - column = col_epsilon + i_carb * inv_ptr->count_solns + i; - array[count_rows * max_column_count + column] = inv_ptr->dalk_dc[i]; - } - sprintf(token, "%s %d", "dAlk", i); - row_name[count_rows] = string_hsave(token); - count_rows++; - } -/* - * Isotope mass balances - */ - if (input_error > 0) { - error_msg("Stopping because of input errors.", STOP); - } - if (inv_ptr->count_isotopes != 0) { - for (j = 0; j < inv_ptr->count_isotopes; j++) { - isotope_balance_equation(inv_ptr, count_rows, j); - sprintf(token,"%d%s", (int) inv_ptr->isotopes[j].isotope_number, - inv_ptr->isotopes[j].elt_name); - row_name[count_rows] = string_hsave(token); - count_rows++; - } - } -/* - * inequalities - */ - row_epsilon = count_rows; - for (i = 0; i < inv_ptr->count_solns; i++) { - for (j = 0; j < inv_ptr->count_elts; j++) { - if (inv_ptr->elts[j].master->s == s_eminus) continue; - column = col_epsilon + j*inv_ptr->count_solns + i; - -/* calculate magnitude of bound */ - - coef = inv_ptr->elts[j].uncertainties[i]; - if (coef <= 0.0) { - coef = -coef; - } else { - coef = array[inv_ptr->elts[j].master->in * max_column_count + i] * coef; - coef = fabs(coef); - } - - if (coef < toler) coef = 0; - -/* zero column if uncertainty is zero */ - if (coef == 0.0) { - for(k = 0; k < count_rows; k++) { - array[k * max_column_count + column] = 0.0; - } - continue; - } - -/* this statement probably obviates some of the following logic. */ -/* coef += toler; */ - -/* scale epsilon optimization equation */ - - if (coef < toler) { - array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/toler; - } else { - array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; - } - -/* set upper limit of change in positive direction */ - if (coef < toler) { - coef = toler; - f = 10; - } else { - f = 1.0; - } - array[count_rows * max_column_count + column] = 1.0 * f; - array[count_rows * max_column_count + i] = -coef * f; - sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps+"); - row_name[count_rows] = string_hsave(token); - count_rows++; - -/* set lower limit of change in negative direction */ - conc = array[inv_ptr->elts[j].master->in * max_column_count + i]; - - /* if concentration is zero, only positive direction allowed */ - if (conc == 0.0) { - delta[column] = 1.0; - continue; - } - /* if uncertainty is less than tolerance, set uncertainty to toler */ - if (coef <= toler) { -/* f = 10 * toler / coef; */ - coef = toler; - f = 10; - } else { - f = 1.0; - } - /* if uncertainty is greater than concentration, - maximum negative is equal to concentrations, - except alkalinity */ - if (coef > fabs(conc) && - (strstr(inv_ptr->elts[j].master->elt->name,"Alkalinity") != inv_ptr->elts[j].master->elt->name)) coef = fabs(conc) + toler; - - array[count_rows * max_column_count + i] = -coef * f ; - array[count_rows * max_column_count + column] = -1.0 * f; - sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps-"); - row_name[count_rows] = string_hsave(token); - count_rows++; - } - } -/* - * inequalities for pH - */ - /* row_ph_epsilon = count_rows; */ - if (inv_ptr->carbon == TRUE) { - for (i = 0; i < inv_ptr->count_solns; i++) { - column = col_ph + i; - coef = inv_ptr->ph_uncertainties[i]; - -/* scale epsilon in optimization equation */ - - array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; - -/* set upper limit of change in positive direction */ - - array[count_rows * max_column_count + column] = 1.0; - array[count_rows * max_column_count + i] = -coef; - sprintf(token, "%s %s", "pH", "eps+"); - row_name[count_rows] = string_hsave(token); - count_rows++; - -/* set lower limit of change in negative direction */ - - array[count_rows * max_column_count + column] = -1.0; - array[count_rows * max_column_count + i] = -coef; - sprintf(token, "%s %s", "pH", "eps-"); - row_name[count_rows] = string_hsave(token); - count_rows++; - } - } -/* - * inequalities for water - */ - column = col_water; - coef = inv_ptr->water_uncertainty; - /* row_water_epsilon = count_rows; */ - if (coef > 0.0) { -/* set upper limit of change in positive direction */ - array[count_rows * max_column_count + column] = 1.0; - array[count_rows * max_column_count + count_unknowns] = coef; - sprintf(token, "%s %s", "water", "eps+"); - row_name[count_rows] = string_hsave(token); - count_rows++; - -/* set lower limit of change in negative direction */ - - array[count_rows * max_column_count + column] = -1.0; - array[count_rows * max_column_count + count_unknowns] = coef; - sprintf(token, "%s %s", "water", "eps-"); - row_name[count_rows] = string_hsave(token); - count_rows++; - } -/* - * inequalities for isotopes - */ - row_isotope_epsilon = count_rows; - if (inv_ptr->count_isotopes > 0) { - for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr = solution_bsearch(inv_ptr->solns[i], &k, TRUE); - for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - column = col_isotopes + (i * inv_ptr->count_isotope_unknowns) + j; - master_ptr = inv_ptr->isotope_unknowns[j].master; - isotope_number = inv_ptr->isotope_unknowns[j].isotope_number; - for (k = 0; k < solution_ptr->count_isotopes; k++) { - if (solution_ptr->isotopes[k].master == master_ptr && - solution_ptr->isotopes[k].isotope_number == isotope_number) { - coef = solution_ptr->isotopes[k].x_ratio_uncertainty; - -/* scale epsilon in optimization equation */ - - array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON/coef; - -/* set upper limit of change in positive direction */ - array[count_rows * max_column_count + column] = 1.0; - array[count_rows * max_column_count + i] = -coef; - sprintf(token, "%d%s %s", - (int) solution_ptr->isotopes[k].isotope_number, - solution_ptr->isotopes[k].elt_name, - "eps+"); - row_name[count_rows] = string_hsave(token); - count_rows++; - -/* set lower limit of change in negative direction */ - - array[count_rows * max_column_count + column] = -1.0; - array[count_rows * max_column_count + i] = -coef; - sprintf(token, "%d%s %s", - (int) solution_ptr->isotopes[k].isotope_number, - solution_ptr->isotopes[k].elt_name, - "eps-"); - row_name[count_rows] = string_hsave(token); - count_rows++; - break; - } - } - } - } - } -/* - * inequalities for isotopes in phases - */ - /* row_isotope_phase_epsilon = count_rows; */ - phase_isotope_inequalities(inv_ptr); - if (input_error > 0) { - error_msg("Stopping because of input errors.", STOP); - } -/* - * Set non-negativity constraints - */ - - for (i = 0; i < inv_ptr->count_phases; i++) { - if (inv_ptr->phases[i].constraint == PRECIPITATE) { - delta[col_phases + i] = -1.0; - } else if (inv_ptr->phases[i].constraint == DISSOLVE) { - delta[col_phases + i] = 1.0; - } - } - for (i = 0; i < (inv_ptr->count_solns - 1); i++) { - delta[i] = 1.0; - } -/* - * Scale water equation - */ - for (i = 0; i < max_column_count; i++) { - array[row_water * max_column_count + i] *= SCALE_WATER; - } -/* - * Arrays are complete - */ - if (debug_inverse == TRUE ) { - for (i = 0; i < count_unknowns; i++) { - output_msg(OUTPUT_MESSAGE, "%d\t%s\n", i, col_name[i]); - } - for (i = 0; i < count_rows; i++) { - k = 0; - output_msg(OUTPUT_MESSAGE,"%d\t%s\n", i, row_name[i]); - for (j=0; j < count_unknowns + 1; j++) { - if (k > 7) { - output_msg(OUTPUT_MESSAGE,"\n"); - k = 0; - } - output_msg(OUTPUT_MESSAGE,"%11.2e", (double) array[i*max_column_count + j]); - k++; - } - if (k != 0) { - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE, "row_mb %d\n", row_mb); - output_msg(OUTPUT_MESSAGE, "row_fract %d\n", row_fract); - output_msg(OUTPUT_MESSAGE, "row_charge %d\n", row_charge); - output_msg(OUTPUT_MESSAGE, "row_carbon %d\n", row_carbon); - output_msg(OUTPUT_MESSAGE, "row_isotopes %d\n", row_isotopes); - output_msg(OUTPUT_MESSAGE, "row_epsilon %d\n", row_epsilon); - - output_msg(OUTPUT_MESSAGE, "col_phases %d\n", col_phases); - output_msg(OUTPUT_MESSAGE, "col_redox %d\n", col_redox); - output_msg(OUTPUT_MESSAGE, "col_epsilon %d\n", col_epsilon); - output_msg(OUTPUT_MESSAGE, "col_ph %d\n", col_ph); - output_msg(OUTPUT_MESSAGE, "col_water %d\n", col_water); - output_msg(OUTPUT_MESSAGE, "col_isotopes %d\n", col_isotopes); - output_msg(OUTPUT_MESSAGE, "col_phase_isotopes %d\n", col_phase_isotopes); - output_msg(OUTPUT_MESSAGE, "count_unknowns %d\n", count_unknowns); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solve_inverse(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Exhaustively search for mass-balance models with two options - * -minimal on or off - * -range on or off - * - */ - int i, j, n; - int quit, print, first; - int first_of_model_size, model_size; - unsigned long minimal_bits, good_bits; - char token[MAX_LENGTH]; - - n = count_unknowns; /* columns in A, C, E */ - klmd = max_row_count - 2; - nklmd = n + klmd; - n2d = n + 2; - - max_good = MAX_MODELS; - max_bad = MAX_MODELS; - max_minimal = MAX_MODELS; - - good = (unsigned long *) PHRQ_malloc( (size_t) max_good * sizeof(unsigned long)); - if (good == NULL) malloc_error(); - count_good = 0; - - bad = (unsigned long *) PHRQ_malloc( (size_t) max_bad * sizeof(unsigned long)); - if (bad == NULL) malloc_error(); - count_bad = 0; - - minimal = (unsigned long *) PHRQ_malloc( (size_t) max_minimal * sizeof(unsigned long)); - if (minimal == NULL) malloc_error(); - count_minimal = 0; - - col_back = (int *) PHRQ_malloc((size_t) max_column_count * sizeof(int)); - if (col_back == NULL) malloc_error(); - - row_back = (int *) PHRQ_malloc((size_t) max_row_count * sizeof(int)); - if (row_back == NULL) malloc_error(); - -/* - * Allocate space for arrays - */ - cu = (LDBLE *) PHRQ_malloc((size_t) 2*nklmd*sizeof(LDBLE)); - if (cu == NULL) malloc_error(); - iu = (int *) PHRQ_malloc((size_t) 2*nklmd*sizeof(int)); - if (iu == NULL) malloc_error(); - is = (int *) PHRQ_malloc((size_t) klmd*sizeof(int)); - if (is == NULL) malloc_error(); - - for(i = 0; i < 79; i++) token[i] = '='; - token[79] = '\0'; -/* - * Set solutions, largest bit is final solution, smallest bit is initial solution 1 - * Set phases, largest bit is last phase, smallest bit is first phase - * Set current bits to complete list. - */ - soln_bits = 0; - if (inv_ptr->count_solns + inv_ptr->count_phases > 32) { - error_msg("For inverse modeling, sum of initial solutions and phases must be <= 32.\n\tFor all reasonable calculations, the sum should be much less than 32.", STOP); - } - for (i = inv_ptr->count_solns ; i > 0; i--) { - temp_bits = 1 << (i - 1); - soln_bits += temp_bits; - } - if (check_solns(inv_ptr) == ERROR) { - error_msg("Calculations terminating.", STOP); - } -/* - * solutions are in highest bits, phases are in lower bits; - */ -/* - * All combinations of solutions - */ - first = TRUE; - for ( ; get_bits(soln_bits, inv_ptr->count_solns - 2, inv_ptr->count_solns - 1) > 0; soln_bits--) { -/* - * Loop through all models of of descending size - */ - for (model_size = inv_ptr->count_phases; model_size >= 0; model_size--) { - first_of_model_size = TRUE; - quit = TRUE; - while ( next_set_phases(inv_ptr, first_of_model_size, model_size) == TRUE) { - first_of_model_size = FALSE; - current_bits = (soln_bits << inv_ptr->count_phases) + phase_bits; - - if (subset_bad(current_bits) == TRUE || subset_minimal(current_bits) == TRUE) continue; - quit = FALSE; -/* - * Switch for finding minimal models only - */ - if (inv_ptr->minimal == TRUE && superset_minimal(current_bits) == TRUE) continue; -/* - * Solve for minimum epsilons, continue if no solution found. - */ - if (solve_with_mask(inv_ptr, current_bits) == ERROR) { - save_bad(current_bits); - if (first == TRUE) { - post_mortem(); - quit = TRUE; - break; - } else { - continue; - } - } - first = FALSE; -/* - * Model has been found, set bits - */ - good_bits = current_bits; - for(i = 0; i < inv_ptr->count_phases; i++) { - if (equal(delta1[i + inv_ptr->count_solns], 0.0, TOL) == TRUE) { - good_bits = set_bit(good_bits, i, 0); - } - } - for(i = 0; i < inv_ptr->count_solns; i++) { - if (equal(delta1[i], 0.0, TOL) == TRUE) { - good_bits = set_bit(good_bits, i + inv_ptr->count_phases, 0); - } - } -/* - * Determine if model is new - */ - for (j = 0; j < count_good; j++) { - if ( good_bits == good[j]) break; - } -/* - * Calculate ranges and print model only if NOT looking for minimal models - */ - print = FALSE; - if ( j >= count_good && inv_ptr->minimal == FALSE) { - print = TRUE; - save_good(good_bits); - if (inv_ptr->range == TRUE) { - range(inv_ptr, good_bits); - } - print_model(inv_ptr); - punch_model(inv_ptr); - } -/* - * If superset of a minimal model continue - */ - minimal_bits = good_bits; - if (superset_minimal(minimal_bits) == TRUE) { - if (print == TRUE) { - if (pr.inverse == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE,"%s\n\n", token); - } - } - continue; - } -/* - * If not superset of minimal model, find minimal model - */ - minimal_bits = minimal_solve(inv_ptr, minimal_bits); - if (minimal_bits == good_bits && print == TRUE) { - if (pr.inverse == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nModel contains minimum number of phases.\n"); - } - } - if (print == TRUE) { - if (pr.inverse == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE,"%s\n\n", token); - } - } - for (j = 0; j < count_good; j++) { - if ( minimal_bits == good[j]) break; - } - if (j >= count_good) { - save_good(minimal_bits); - if (inv_ptr->range == TRUE) { - range(inv_ptr, minimal_bits); - } - print_model(inv_ptr); - if (pr.inverse == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nModel contains minimum number of phases.\n"); - output_msg(OUTPUT_MESSAGE,"%s\n\n", token); - } - punch_model(inv_ptr); - } - save_minimal(minimal_bits); - } - if (quit == TRUE) break; - } - } -/* - * Summary print - */ - if (pr.inverse == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nSummary of inverse modeling:\n\n"); - output_msg(OUTPUT_MESSAGE,"\tNumber of models found: %d\n", count_good); - output_msg(OUTPUT_MESSAGE,"\tNumber of minimal models found: %d\n", count_minimal); - output_msg(OUTPUT_MESSAGE,"\tNumber of infeasible sets of phases saved: %d\n", count_bad); - output_msg(OUTPUT_MESSAGE,"\tNumber of calls to cl1: %d\n", count_calls); - } - array = (LDBLE *) free_check_null(array); - delta = (LDBLE *) free_check_null(delta); - array1 = (LDBLE *) free_check_null(array1); - zero = (LDBLE *) free_check_null(zero); - res = (LDBLE *) free_check_null(res); - delta1 = (LDBLE *) free_check_null(delta1); - delta2 = (LDBLE *) free_check_null(delta2); - delta3 = (LDBLE *) free_check_null(delta3); - delta_save = (LDBLE *) free_check_null(delta_save); - cu = (LDBLE *) free_check_null(cu); - iu = (int *) free_check_null(iu); - is = (int *) free_check_null(is); - col_name = (char **) free_check_null(col_name); - row_name = (char **) free_check_null(row_name); - col_back = (int *) free_check_null(col_back); - row_back = (int *) free_check_null(row_back); - min_delta = (LDBLE *) free_check_null(min_delta); - max_delta = (LDBLE *) free_check_null(max_delta); - good = (unsigned long *) free_check_null(good); - bad = (unsigned long *) free_check_null(bad); - minimal = (unsigned long *) free_check_null(minimal); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -unsigned long minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Starting with phases indicated in minimal bits, sequentially - * remove phases to find minimal solution - */ - int i; - unsigned long temp_bits_l; - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "Beginning minimal solve: \n"); - bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); - } - for (i = 0; i < inv_ptr->count_phases + inv_ptr->count_solns - 1; i++) { - if (get_bits(minimal_bits, i, 1) == 0) continue; - temp_bits_l = 1 << i; /* 0's and one 1 */ - temp_bits_l = ~temp_bits_l; /* 1's and one 0 */ - minimal_bits = minimal_bits & temp_bits_l; - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "Solving for minimal\n"); - bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); - } - -/* - * minimal_bits can not be superset of a minimal model, but - * could be subset of one of the sets of minerals with no feasible solution - * If it is a subset, then replace mineral and go on to next - */ - if ( subset_bad(minimal_bits) == TRUE) { - /* put bit back */ - minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ - continue; - } - if (solve_with_mask (inv_ptr, minimal_bits) == ERROR) { - save_bad(minimal_bits); - /* put bit back */ - minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ - } - - } - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE,"\n\nMINIMAL MODEL\n\n"); - bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); - } - solve_with_mask (inv_ptr, minimal_bits); - return(minimal_bits); -} - -/* ---------------------------------------------------------------------- */ -int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Uses cur_bits to zero out columns of the array and then solves. - */ - int i, k, l, m, n; - -/* - * Calculate dimensions - */ - k = row_mb; /* rows in A */ - l = row_epsilon - row_mb; /* rows in C */ - m = count_rows - row_epsilon; /* rows in E */ - n = count_unknowns; - - - - memcpy( (void *) &(res[0]), (void *) &(zero[0]), (size_t) max_row_count * sizeof(LDBLE)); - memcpy( (void *) &(delta2[0]), (void *) &(delta[0]), (size_t) max_column_count * sizeof(LDBLE)); - memcpy( (void *) &(delta_save[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - - shrink(inv_ptr, array, array1, - &k, &l, &m, &n, - cur_bits, - delta2, col_back, row_back); - /* - * Save delta constraints - */ - for (i=0; i < n; i++) { - delta_save[col_back[i]] = delta2[i]; - } - - - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nColumns\n"); - for (i = 0; i < n; i++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i, col_name[col_back[i]]); - } - - output_msg(OUTPUT_MESSAGE, "\nRows\n"); - for (i = 0; i < k + l + m; i++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i, row_name[row_back[i]]); - } - - output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); - array_print(array1, k + l + m, n + 1, max_column_count); - - output_msg(OUTPUT_MESSAGE, "\nInput delta vector:\n"); - for (i=0; i < n; i++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, col_name[col_back[i]], (double) delta2[i]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - - for (i=0; i < k + l + m; i++) { - if (res[i] == 0) continue; - output_msg(OUTPUT_MESSAGE, "\nInput res is non zero:\n"); - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, row_name[row_back[i]], (double) res[i]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - } -/* - * Call CL1 - */ - - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "k, l, m, n, max_col, max_row\t%d\t%d\t%d\t%d\t%d\t%d\n", - k, l, m, n, max_column_count, max_row_count); - } - - kode = 1; - iter = 1000; - count_calls++; - -#ifdef INVERSE_CL1MP - if(inv_ptr->mp == TRUE) { - cl1mp(k, l, m, n, - nklmd, n2d, array1, - &kode, inv_ptr->mp_tolerance, &iter, - delta2, res, &error, cu, iu, is, TRUE, inv_ptr->mp_censor); - } else { - cl1(k, l, m, n, - nklmd, n2d, array1, - &kode, toler, &iter, - delta2, res, &error, cu, iu, is, TRUE); - } -#else - cl1(k, l, m, n, - nklmd, n2d, array1, - &kode, toler, &iter, - delta2, res, &error, cu, iu, is, TRUE); -#endif - if (kode == 3) { - sprintf(error_string, "Exceeded maximum iterations in inverse modeling: %d.\n" - "Recompile program with larger limit.", iter); - error_msg(error_string, STOP); - } - memcpy( (void *) &(delta1[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - for(i = 0; i < n; i++) { - delta1[col_back[i]] = delta2[i]; - } - -/* - * Debug, write results - */ - - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error); - output_msg(OUTPUT_MESSAGE, "\nsolution vector:\n"); - for (i=0; i < n; i++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", i, col_name[col_back[i]], (double) delta2[i]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - - output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); - for (i=0; i < (k + l + m); i++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, row_name[row_back[i]], (double) res[i]); - } - } - - if (kode != 0) { - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -unsigned long get_bits(unsigned long bits, int position, int number) -/* ---------------------------------------------------------------------- */ -{ -/* - * Returns number of bits from position and below. - * position begins at 0. - */ - return( (bits >> (position + 1 - number)) & ~(~0 << number)); -} -/* ---------------------------------------------------------------------- */ -int save_minimal(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Keeps list of minimal models - */ - minimal[count_minimal] = bits; - count_minimal++; - if (count_minimal >= max_minimal) { - max_minimal *= 2; - minimal = (unsigned long *) PHRQ_realloc(minimal, (size_t) max_minimal * sizeof (unsigned long)); - if (minimal == NULL) malloc_error(); - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int save_good(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Keeps list of good models, not necessarily minimal - */ - good[count_good] = bits; - count_good++; - if (count_good >= max_good) { - max_good *= 2; - good = (unsigned long *) PHRQ_realloc(good, (size_t) max_good * sizeof (unsigned long)); - if (good == NULL) malloc_error(); - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int save_bad(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Keeps list of sets of phases with no feasible solution - */ - bad[count_bad] = bits; - count_bad++; - if (count_bad >= max_bad) { - max_bad *= 2; - bad = (unsigned long *) PHRQ_realloc(bad, (size_t) max_bad * sizeof (unsigned long)); - if (bad == NULL) malloc_error(); - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int superset_minimal(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks whether bits is a superset of any of the minimal models - */ - int i; - unsigned long temp_bits_l; - for (i=0; i < count_minimal; i++) { - temp_bits_l = bits | minimal[i]; - if (temp_bits_l == bits) { - return(TRUE); - } - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -int subset_bad(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks whether bits is a superset of any of the bad models - */ - int i; - unsigned long temp_bits_l; - for (i=0; i < count_bad; i++) { - temp_bits_l = bits | bad[i]; - if (temp_bits_l == bad[i]) { - return(TRUE); - } - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -int subset_minimal(unsigned long bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks whether bits is a subset of any of the minimal models - */ - int i; - unsigned long temp_bits_l; - for (i=0; i < count_minimal; i++) { - temp_bits_l = bits | minimal[i]; - if (temp_bits_l == minimal[i]) { - return(TRUE); - } - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -int bit_print(unsigned long bits, int l) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints l bits of an unsigned long - */ - int i; - - for (i = l - 1; i >= 0; i--) { - output_msg(OUTPUT_MESSAGE,"%lu ", get_bits(bits, i, 1)); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_model(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints model - */ - int i, j, k; - int column; - int print_msg; - struct solution *solution_ptr; - struct master *master_ptr; - struct isotope *isotope_ptr; - LDBLE d1, d2, d3, d4; - char token[MAX_LENGTH]; -/* - * Update screen - */ - status(count_good, NULL); -/* - * print solution data, epsilons, and revised data - */ - if (pr.inverse == FALSE || pr.all == FALSE) return(OK); - max_pct = 0; - scaled_error = 0; - for (i = 0; i < inv_ptr->count_solns; i++) { - if (equal(delta1[i], 0.0, toler) == TRUE) continue; - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - xsolution_zero(); - for (j=0; solution_ptr->totals[j].description != NULL; j++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - master_ptr->total = solution_ptr->totals[j].moles; - } - - output_msg(OUTPUT_MESSAGE,"\nSolution %d: %s\n", inv_ptr->solns[i], solution_ptr->description); - output_msg(OUTPUT_MESSAGE,"\n%15.15s %12.12s %12.12s %12.12s\n", - " ", "Input", "Delta", "Input+Delta"); - master_alk->total = solution_ptr->total_alkalinity; - if (inv_ptr->carbon == TRUE) { - d1 = solution_ptr->ph; - d2 = delta1[col_ph + i] / delta1[i]; - d3 = d1 + d2; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - output_msg(OUTPUT_MESSAGE,"%15.15s %12.3e +%12.3e =%12.3e\n", - "pH", (double) d1, (double) d2, (double) d3); - if (inv_ptr->ph_uncertainties[i] > 0) { - scaled_error += fabs(d2) / inv_ptr->ph_uncertainties[i]; -/* debug - output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / inv_ptr->ph_uncertainties[i], fabs(d2), inv_ptr->ph_uncertainties[i]); - */ - } else if (d2 != 0.0) { - error_msg("Computing delta pH/uncertainty", CONTINUE); - } - } - for (j = 0; j < inv_ptr->count_elts; j++) { - if (inv_ptr->elts[j].master->s == s_eminus) continue; - d1 = inv_ptr->elts[j].master->total; - d2 = delta1[col_epsilon + j * inv_ptr->count_solns + i] / delta1[i]; - d3 = d1 + d2; - - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - - output_msg(OUTPUT_MESSAGE,"%15.15s %12.3e +%12.3e =%12.3e\n", - inv_ptr->elts[j].master->elt->name, (double) d1, (double) d2, (double) d3); - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE ) { - d3 = fabs(d2/d1); - if (d3 > max_pct) max_pct = d3; - } - d4 = 0; - if (inv_ptr->elts[j].uncertainties[i] > 0) { - d4 = fabs(inv_ptr->elts[j].uncertainties[i] * d1); - } else if (inv_ptr->elts[j].uncertainties[i] < 0) { - d4 = -inv_ptr->elts[j].uncertainties[i]; - } - if (d4 > 0) { - scaled_error += fabs(d2) / d4; -/* debug - output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / d4, fabs(d2), d4); - */ - } else if (d2 != 0.0) { - error_msg("Computing delta element/uncertainty", CONTINUE); - } - } - if (inv_ptr->count_isotopes > 0) { - /* adjustments to solution isotope composition */ - for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - for (k = 0; k < solution_ptr->count_isotopes; k++) { - if (inv_ptr->isotope_unknowns[j].elt_name != - solution_ptr->isotopes[k].elt_name || - inv_ptr->isotope_unknowns[j].isotope_number != - solution_ptr->isotopes[k].isotope_number) continue; - d1 = solution_ptr->isotopes[k].ratio; - d2 = delta1[col_isotopes + i * inv_ptr->count_isotope_unknowns + j] / delta1[i]; - d3 = d1 + d2; - - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - sprintf(token, "%d%s", - (int) inv_ptr->isotope_unknowns[j].isotope_number, - inv_ptr->isotope_unknowns[j].elt_name); - output_msg(OUTPUT_MESSAGE,"%15.15s %12g +%12g =%12g\n", token, - (double) d1, (double) d2, (double) d3); -/* - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE ) { - d3 = fabs(d2/d1); - if (d3 > max_pct) max_pct = d3; - } - */ - if (solution_ptr->isotopes[k].x_ratio_uncertainty > 0) { - scaled_error += fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty; -/* debug - output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty , fabs(d2), solution_ptr->isotopes[k].x_ratio_uncertainty); - */ - } else if (d2 != 0.0) { - error_msg("Computing delta solution isotope/uncertainty", CONTINUE); - } - } - } - } - } - -/* - * Adjustments to phases - */ - print_msg = FALSE; - if (inv_ptr->count_isotopes > 0) { - output_msg(OUTPUT_MESSAGE,"\nIsotopic composition of phases:\n"); - for (i = 0; i < inv_ptr->count_phases; i++) { - if (inv_ptr->phases[i].count_isotopes == 0) continue; - j = col_phases + i; - if (equal(delta1[j], 0.0, toler) == TRUE && - equal(min_delta[j], 0.0, toler) == TRUE && - equal(max_delta[j], 0.0, toler) == TRUE ) continue; - isotope_ptr = inv_ptr->phases[i].isotopes; - for (j = 0; j < inv_ptr->count_isotopes; j++) { - for (k = 0; k < inv_ptr->phases[i].count_isotopes; k++) { - if (inv_ptr->isotopes[j].elt_name != - isotope_ptr[k].elt_name || - inv_ptr->isotopes[j].isotope_number != - isotope_ptr[k].isotope_number) continue; - d1 = isotope_ptr[k].ratio; - column = col_phase_isotopes + i * inv_ptr->count_isotopes + j; - if (delta1[col_phases + i] != 0.0) { - d2 = delta1[column] / delta1[col_phases + i]; - } else { - continue; - } - d3 = d1 + d2; - if (equal(d1, 0.0, 1e-7) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, 1e-7) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, 1e-7) == TRUE) d3 = 0.0; - sprintf(token, "%d%s %s", - (int) inv_ptr->isotopes[j].isotope_number, - inv_ptr->isotopes[j].elt_name, - inv_ptr->phases[i].phase->name); - output_msg(OUTPUT_MESSAGE,"%15.15s %12g +%12g =%12g", token, - (double) d1, (double) d2, (double) d3); - if (fabs(d2) > (isotope_ptr[k].ratio_uncertainty + toler)) { - output_msg(OUTPUT_MESSAGE," **"); - print_msg = TRUE; - } - output_msg(OUTPUT_MESSAGE,"\n"); - if (isotope_ptr[k].ratio_uncertainty > 0) { - scaled_error += fabs(d2) / isotope_ptr[k].ratio_uncertainty; -/* debug - output_msg(OUTPUT_MESSAGE, "%e\t%e\t%e\n", fabs(d2) / isotope_ptr[k].ratio_uncertainty, fabs(d2), isotope_ptr[k].ratio_uncertainty); - */ - } else if (d2 != 0.0) { - error_msg("Computing delta phase isotope/uncertainty", CONTINUE); - } - } - } - } - } - if (print_msg == TRUE) { - output_msg(OUTPUT_MESSAGE,"\n**\tWARNING: The adjustment to at least one isotopic" - "\n\tcomposition of a phase exceeded the specified uncertainty" - "\n\tfor the phase. If the phase is not constrained to dissolve" - "\n\tor precipitate, then the isotopic composition of the phase" - "\n\tis also unconstrained.\n"); - } - output_msg(OUTPUT_MESSAGE,"\n%-20.20s %7s %12.12s %12.12s\n", "Solution fractions:", " ", "Minimum","Maximum"); - for (i = 0; i < inv_ptr->count_solns; i++) { - d1 = delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - output_msg(OUTPUT_MESSAGE, "%11s%4d %12.3e %12.3e %12.3e\n", "Solution", - inv_ptr->solns[i], (double) d1, (double) d2, (double) d3); - } - - output_msg(OUTPUT_MESSAGE,"\n%-25.25s %2s %12.12s %12.12s\n", - "Phase mole transfers:", " ", "Minimum","Maximum"); - for (i = col_phases; i < col_redox; i++) { - if (equal(delta1[i], 0.0, toler) == TRUE && - equal(min_delta[i], 0.0, toler) == TRUE && - equal(max_delta[i], 0.0, toler) == TRUE ) continue; - d1 = delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - output_msg(OUTPUT_MESSAGE, "%15.15s %12.3e %12.3e %12.3e %s\n", col_name[i], (double) d1, - (double) d2, (double) d3, inv_ptr->phases[i - col_phases].phase->formula); - } - - output_msg(OUTPUT_MESSAGE,"\n%-25.25s\n", "Redox mole transfers:"); - for (i = col_redox; i < col_epsilon; i++) { - if (equal(delta1[i], 0.0, toler) == TRUE) continue; - output_msg(OUTPUT_MESSAGE, "%15.15s %12.3e\n", col_name[i], (double) delta1[i]); - } - - output_msg(OUTPUT_MESSAGE,"\nSum of residuals (epsilons in documentation): %12.3e\n", ((double) error/SCALE_EPSILON)); - output_msg(OUTPUT_MESSAGE, "Sum of delta/uncertainty limit: %12.3e\n", (double) scaled_error); - output_msg(OUTPUT_MESSAGE, "Maximum fractional error in element concentration: %12.3e\n", (double) max_pct); -/* - * Flush buffer after each model - */ - output_fflush(OUTPUT_MESSAGE); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_model_heading(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints model headings to selected output file - */ - int i; - char token[MAX_LENGTH]; - if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) return(OK); -/* - * Print sum of residuals and maximum fractional error - */ - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH,"%12s\t%12s\t%12s\t","Sum_resid", "Sum_Delta/U","MaxFracErr"); - } else { - output_msg(OUTPUT_PUNCH,"%20s\t%20s\t%20s\t","Sum_resid", "Sum_Delta/U","MaxFracErr"); - } -/* - * Print solution numbers - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - sprintf(token, "Soln %d", inv_ptr->solns[i]); - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH,"%12s\t%12s\t%12s\t", token, "min", "max"); - } else { - output_msg(OUTPUT_PUNCH,"%20s\t%20s\t%20s\t", token, "min","max"); - } - } -/* - * Print phase names - */ - for (i = col_phases; i < col_redox; i++) { - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH, "%12s\t%12s\t%12s\t", col_name[i], " min", " max"); - } else { - output_msg(OUTPUT_PUNCH, "%20s\t%20s\t%20s\t", col_name[i], " min", " max"); - } - } - output_msg(OUTPUT_PUNCH, "\n"); -/* - * Flush buffer after each model - */ - output_fflush(OUTPUT_PUNCH); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_model(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints model to selected output file - */ - int i; - LDBLE d1, d2, d3; - if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) return(OK); -/* - * write residual info - */ - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH,"%12.4e\t", ((double) error/SCALE_EPSILON)); - output_msg(OUTPUT_PUNCH,"%12.4e\t", (double) scaled_error); - output_msg(OUTPUT_PUNCH,"%12.4e\t", (double) max_pct); - } else { - output_msg(OUTPUT_PUNCH,"%20.12e\t", ((double) error/SCALE_EPSILON)); - output_msg(OUTPUT_PUNCH,"%20.12e\t", (double) scaled_error); - output_msg(OUTPUT_PUNCH,"%20.12e\t", (double) max_pct); - } -/* - * write solution fractions - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - d1 = delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH, "%12.4e\t%12.4e\t%12.4e\t", (double) d1, (double) d2, (double) d3); - } else { - output_msg(OUTPUT_PUNCH, "%20.12e\t%20.12e\t%20.12e\t", (double) d1, (double) d2, (double) d3); - } - } -/* - * write phase transfers - */ - for (i = col_phases; i < col_redox; i++) { - d1 = delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) d3 = 0.0; - if (punch.high_precision == FALSE) { - output_msg(OUTPUT_PUNCH, "%12.4e\t%12.4e\t%12.4e\t", (double) d1, (double) d2, (double) d3); - } else { - output_msg(OUTPUT_PUNCH, "%20.12e\t%20.12e\t%20.12e\t", (double) d1, (double) d2, (double) d3); - } - } - output_msg(OUTPUT_PUNCH, "\n"); -/* - * Flush buffer after each model - */ - output_fflush(OUTPUT_PUNCH); - return(OK); -} -/* ---------------------------------------------------------------------- */ -unsigned long set_bit(unsigned long bits, int position, int value) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sets a single bit - */ - unsigned long temp_bits_l; - - temp_bits_l = 1 << position; - if (value == 0) { - temp_bits_l = ~temp_bits_l; - temp_bits_l = bits & temp_bits_l; - } else { - temp_bits_l = bits | temp_bits_l; - } - return(temp_bits_l); -} -/* ---------------------------------------------------------------------- */ -int next_set_phases(struct inverse *inv_ptr, - int first_of_model_size, - int model_size) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - unsigned long temp_bits_l; - static int min_position[32], max_position[32], now[32]; - -/* - * min_ and max_position are arrays, logically with length - * of model_size, that contain minimum and maximum - * phase numbers that can be in that model position. - * - * now contains a list of phase numbers to mark as in for this - * model - */ - -/* - * Initialize for a given model_size - */ - if (first_of_model_size == TRUE) { - for (i = 0; i < model_size; i++) { - min_position[i] = i; - now[i] = i; - max_position[i] = inv_ptr->count_phases - model_size + i; - } - } else { -/* - * Determine next combination of phases for fixed model_size - */ - for (i = (model_size - 1); i >= 0; i--) { - if (now[i] < max_position[i]) { - now[i]++; - if (i < (model_size - 1) ) { - k = now[i]; - for (j = (i + 1); j < model_size; j++) { - k++; - now[j] = k; - } - } - break; - } - } - if (i < 0) return(FALSE); - } -/* - * Set bits which switch in phases - */ - temp_bits_l = 0; - for (j = 0; j < model_size; j++) { - temp_bits_l += (1 << now[j]); - } - phase_bits = temp_bits_l; - return(TRUE); -} - -/* ---------------------------------------------------------------------- */ -int range(struct inverse *inv_ptr, unsigned long cur_bits) -/* ---------------------------------------------------------------------- */ -{ -/* - * Takes the model from cur_bits and sequentially determines the - * minimum and maximum values for each solution fraction and - * each phase mass transfer. - */ - int i, j; - int k, l, m, n; - int f; - unsigned long bits; - LDBLE error2; -/* - * Include forced solutions and phases in range calculation - */ - for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) { - if (i < inv_ptr->count_phases) { - if (inv_ptr->phases[i].force == TRUE) { - cur_bits = set_bit(cur_bits, i , 1); - } - } else { - if (inv_ptr->force_solns[i - inv_ptr->count_phases] == TRUE) { - cur_bits = set_bit(cur_bits, i, 1); - } - } - } - - memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); -/* - * Switch bits so that phases are high and solutions are low - */ - bits = get_bits(cur_bits, inv_ptr->count_phases + inv_ptr->count_solns - 1, inv_ptr->count_solns); - bits += (get_bits(cur_bits, inv_ptr->count_phases - 1, inv_ptr->count_phases) << inv_ptr->count_solns); -/* - * Do range calculation - */ - for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) { - if (inv_ptr->count_solns == i + 1) { - min_delta[i] = 1.0; - max_delta[i] = 1.0; - continue; - } - if (get_bits(bits, i, 1) == 0) continue; -/* - * Calculate min and max - */ - for (f = -1; f < 2; f += 2) { - k = row_mb; /* rows in A */ - l = row_epsilon - row_mb; /* rows in C */ - m = count_rows - row_epsilon; /* rows in E */ - n = count_unknowns; /* number of variables */ -/* - * Copy equations - */ - memcpy((void *) &(array1[0]), (void *) &(array[0]), - (size_t) max_column_count * max_row_count * sizeof(LDBLE)); - memcpy((void *) &(delta2[0]), (void *) &(delta[0]), - (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(delta3[0]), (void *) &(zero[0]), - (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(delta_save[0]), (void *) &(zero[0]), - (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(res[0]), (void *) &(zero[0]), - (size_t) max_row_count * sizeof(LDBLE)); - -/* - * Change optimization - */ - for (j = 0; j < k; j++) { - memcpy((void *) &(array1[j * max_column_count]), (void *) &(zero[0]), - (size_t) max_column_count * sizeof(LDBLE)); - } - array1[i] = 1.0; - if (f < 1) { - array1[n] = -fabs(inv_ptr->range_max); - } else { - array1[n] = fabs(inv_ptr->range_max); - } - shrink(inv_ptr, array1, array1, - &k, &l, &m, &n, - cur_bits, - delta2, col_back, row_back); - /* - * Save delta constraints - */ - for (j=0; j < n; j++) { - delta_save[col_back[j]] = delta2[j]; - } - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nInput delta:\n\n"); - for (j = 0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d %s\t%g\n", j, col_name[col_back[j]], (double) delta2[j]); - } - output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); - array_print(array1, k + l + m, - n + 1, max_column_count); - } - kode = 1; - iter = 200; - count_calls++; -#ifdef INVERSE_CL1MP - if(inv_ptr->mp == TRUE) { - cl1mp(k, l, m, n, - nklmd, n2d, array1, - &kode, inv_ptr->mp_tolerance, &iter, - delta2, res, &error2, cu, iu, is, TRUE, inv_ptr->mp_censor); - } else { - cl1(k, l, m, n, - nklmd, n2d, array1, - &kode, toler, &iter, - delta2, res, &error2, cu, iu, is, TRUE); - } -#else - cl1(k, l, m, n, - nklmd, n2d, array1, - &kode, toler, &iter, - delta2, res, &error2, cu, iu, is, TRUE); -#endif - if (kode != 0) { - output_msg(OUTPUT_MESSAGE, "Error in subroutine range. Kode = %d\n", kode); - } - - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error2); - output_msg(OUTPUT_MESSAGE, "k, l, m, n: %d\t%d\t%d\t%d\n", k, l, m, n); - output_msg(OUTPUT_MESSAGE, "\nsolution vector %s\n", col_name[i]); - for (j = 0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], (double) delta2[j]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - - output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); - for (j = 0; j < (k + l + m); j++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n", j, row_name[row_back[j]], (double) res[j]); - } - } - for(j = 0; j < n; j++) { - if (col_back[j] == i) break; - } - if (f < 0) { - min_delta[i] = delta2[j]; - } else { - max_delta[i] = delta2[j]; - } - for(j = 0; j < n; j++) { - delta3[col_back[j]] = delta2[j]; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int shrink(struct inverse *inv_ptr, LDBLE *array_in, LDBLE *array_out, - int *k, int *l, int *m, int *n, - unsigned long cur_bits, - LDBLE *delta_l, int *col_back_l, int *row_back_l) -/* ---------------------------------------------------------------------- */ -{ -/* - * Shrink eliminates any rows that are all zeros and any columns - * that are not in cur_bits, result is put in array_out - * - * k, l, m, n return the new sizes of the array. - * delta is remapped to retain any non-negativity constraints - * Col_back maps columns that remain back to original columns - * Row_back maps rows that remain back to original rows - */ - int i, j, row; - int k1, l1, m1; - int cur_col, column; - int nonzero; -/* - * Copy array_in to array_out - */ - if (array_in != array_out) { - for (i = 0; i < (*k + *l + *m); i++) { - memcpy(&(array_out[i * max_column_count]), &(array_in[i * max_column_count]), - (size_t) max_column_count * sizeof(LDBLE)); - } - } -/* - * Determine columns to eliminate - */ - for (i = 0; i < (*n + 1); i++) col_back_l[i] = i; - -/* - * Drop phases not in model - */ - for (i = 0; i < inv_ptr->count_phases; i++) { - if (get_bits(cur_bits, i, 1) == 0) { - col_back_l[col_phases + i] = -1; - /* drop isotopes */ - if (inv_ptr->count_isotopes > 0 ) { - for (j =0; j < inv_ptr->count_isotopes; j++) { - column = col_phase_isotopes + i * inv_ptr->count_isotopes + j; - col_back_l[column] = -1; - } - } - } - } -/* - * Drop solutions not in model - */ - for (i = 0; i < (inv_ptr->count_solns - 1) ; i++) { - if (get_bits(cur_bits, inv_ptr->count_phases + i, 1) == 0) { - col_back_l[i] = -1; - /* drop all epsilons for the solution */ - for(j = 0; j < inv_ptr->count_elts; j++) { - column = col_epsilon + j * inv_ptr->count_solns + i; - col_back_l[column] = -1; - } - /* drop pH for the solution */ - if (inv_ptr->carbon == TRUE) { - column = col_ph + i; - col_back_l[column] = -1; - } - /* drop isotopes */ - if (inv_ptr->count_isotopes > 0) { - for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - column = col_isotopes + i * inv_ptr->count_isotope_unknowns + j; - col_back_l[column] = -1; - } - } - } - } - -/* - * Drop epsilons not used - */ - for (i = col_epsilon; i < *n; i++) { - if (col_back_l[i] < 0) continue; - for (j = 0; j < (*k + *l + *m); j++) { - if (array_out[j * max_column_count + i] != 0) break; - } - if (j == (*k + *l + *m)) { - col_back_l[i] = -1; - } - } -/* - * rewrite array_out - */ - cur_col = 0; - for (i = 0; i < (*n + 1); i++) { - if (col_back_l[i] < 0) continue; - if (cur_col == col_back_l[i]) { - cur_col++; - continue; - } - for (j=0; j < (*k + *l + *m); j++) { - array_out[j * max_column_count + cur_col] = array_out[j * max_column_count + i]; - } - col_back_l[cur_col] = col_back_l[i]; - delta_l[cur_col] = delta_l[i]; - cur_col++; - } - *n = cur_col - 1; -/* - * Eliminate unnecessary optimization eqns - */ - row = 0; - k1 = 0; - for(i=0; i < *k; i++) { - if (memcmp(&(array_out[i*max_column_count]), &(zero[0]), - (size_t) (*n) * sizeof(LDBLE)) == 0) { - continue; - } -/* - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) max_column_count * sizeof(LDBLE)); - */ - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); - row_back_l[row] = i; - row++; - k1++; - } - -/* - * Eliminate unnecessary equality eqns - */ - l1 = 0; - for (i = *k; i < (*k + *l); i++) { - nonzero = FALSE; - for (j = 0; j < *n; j++) { - if (equal(array_out[i * max_column_count + j], 0.0, toler) == FALSE) { - nonzero = TRUE; - break; - } - } - if (nonzero == FALSE) continue; -/* - if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), - (size_t) (*n) * sizeof(LDBLE)) == 0) { - continue; - } - */ -/* - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) max_column_count * sizeof(LDBLE)); - */ - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); - row_back_l[row] = i; - row++; - l1++; - } -/* - * Eliminate unnecessary inequality eqns - */ - m1 = 0; - for (i = (*k + *l); i < (*k + *l + *m); i++) { - nonzero = FALSE; - for (j = 0; j < *n; j++) { - if (equal(array_out[i * max_column_count + j], 0.0, toler) == FALSE) { - nonzero = TRUE; - break; - } - } - if (nonzero == FALSE) continue; -/* - if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), - (size_t) (*n) * sizeof(LDBLE)) == 0) { - continue; - } - */ -/* - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) max_column_count * sizeof(LDBLE)); - */ - memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); - row_back_l[row] = i; - row++; - m1++; - } - - *k = k1; - *l = l1; - *m = m1; -/* - * Scale all inequality rows - */ - - for (i = *k + *l; i < *k + *l + *m; i++) { - for (j = 0; j < *n + 1; j++) { - array_out[i*max_column_count + j] *= SCALE_ALL; - } - } - - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int check_solns(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check_solns checks that each solution can be charge balanced within - * the given constraints. If not, it is an error and the program will - * terminate. - */ - int i, j; - int k, l, m, n; - int return_value; - unsigned long bits; - LDBLE error2; - - memcpy((void *) &(min_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(max_delta[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - -/* - * Switch bits so that phases are high and solutions are low - */ - return_value = OK; - for (i = 0; i < inv_ptr->count_solns; i++) { - bits = 0; - bits += 1 << (inv_ptr->count_phases + i); -/* - * Check for feasibility of charge balance with given uncertainties - */ - k = row_mb; /* rows in A */ - l = row_epsilon - row_mb; /* rows in C */ - m = count_rows - row_epsilon; /* rows in E */ - n = count_unknowns; /* number of variables */ -/* debug - output_msg(OUTPUT_MESSAGE, "\nColumns\n"); - for (j = 0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, col_name[j]); - } - - output_msg(OUTPUT_MESSAGE, "\nRows\n"); - for (j = 0; j < k + l + m; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, row_name[j]); - } - - output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); - array_print(array, k + l + m, - n + 1, max_column_count); - */ -/* - * Copy equations - */ - memcpy((void *) &(array1[0]), (void *) &(array[0]), - (size_t) max_column_count * max_row_count * sizeof(LDBLE)); - memcpy((void *) &(delta2[0]), (void *) &(delta[0]), - (size_t) max_column_count * sizeof(LDBLE)); - memcpy((void *) &(res[0]), (void *) &(zero[0]), - (size_t) max_row_count * sizeof(LDBLE)); - -/* - * Keep optimization - */ -/* - * Zero out mass balance rows and fraction rows - */ - for (j = row_mb; j < row_charge; j++) { - memcpy((void *) &(array1[j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - } -/* - * Set fraction of solution to 1.0 - */ - array1[(row_charge - 1) * max_column_count + i] = 1.0; - array1[(row_charge - 1) * max_column_count + n] = 1.0; - -/* - * Zero out charge balance rows for other solutions - */ - for (j = 0; j < inv_ptr->count_solns; j++) { - if ( j == i ) continue; - memcpy((void *) &(array1[(row_charge + j) * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - } - -/* - * Zero out isotope mole balance - */ - for (j = row_isotopes; j < row_epsilon; j++) { - memcpy((void *) &(array1[ j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - } - -/* - * Zero out isotope uncertainties - */ - for (j = row_isotope_epsilon; j < count_rows; j++) { - memcpy((void *) &(array1[ j * max_column_count]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); - } -/* - * Can't Zero out epsilon constraint rows for other solutions because not sure which - * are which - */ - - shrink(inv_ptr, array1, array1, - &k, &l, &m, &n, - bits, - delta2, col_back, row_back); -/* Debug - - output_msg(OUTPUT_MESSAGE, "\nColumns\n"); - for (j = 0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, col_name[col_back[j]]); - } - - output_msg(OUTPUT_MESSAGE, "\nRows\n"); - for (j = 0; j < k + l + m; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", j, row_name[row_back[j]]); - } - - output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); - array_print(array1, k + l + m, - n + 1, max_column_count); - - output_msg(OUTPUT_MESSAGE, "\nInput delta vector:\n"); - for (j=0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - */ - - kode = 1; - iter = 200; - count_calls++; - cl1(k, l, m, n, - nklmd, n2d, array1, - &kode, toler, &iter, - delta2, res, &error2, cu, iu, is, TRUE); - - if (kode != 0) { - sprintf(error_string, "Not possible to balance solution %d with input uncertainties.", inv_ptr->solns[i]); - error_msg(error_string, CONTINUE); - return_value = ERROR; - } - -/* Debug - output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, error); - output_msg(OUTPUT_MESSAGE, "k, l, m, n: %d\t%d\t%d\t%d\n", k, l, m, n); - - output_msg(OUTPUT_MESSAGE, "\nsolution vector %s\n", col_name[i]); - for (j = 0; j < n; j++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j]); - output_msg(OUTPUT_MESSAGE, "\n"); - } - - output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); - for (j = 0; j < (k + l + m); j++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n", j, row_name[row_back[j]], res[j]); - } - */ - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int post_mortem(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Post_mortem simply identifies which equality and inequality of the - * array have not been satisfied. - * - */ - int i, j; - LDBLE sum; -/* - * Check equalities - */ - output_msg(OUTPUT_MESSAGE, "\nPost_mortem examination of inverse modeling:\n\n"); - for (i = row_mb; i < row_epsilon; i++) { - sum = 0; - for (j = 0; j < count_unknowns; j++) { - sum += delta1[j] * array[i * max_column_count + j]; - } - - if ( equal(sum, array[(i * max_column_count) + count_unknowns], toler) == FALSE) { - output_msg(OUTPUT_MESSAGE, "\tERROR: equality not satisfied for %s, %e.\n", row_name[i], sum - array[(i * max_column_count) + count_unknowns]); - } - } -/* - * Check inequalities - */ - for (i = row_epsilon; i < count_rows; i++) { - sum = 0; - for (j = 0; j < count_unknowns; j++) { - sum += delta1[j] * array[i * max_column_count + j]; - } - - if ( sum > array[(i * max_column_count) + count_unknowns] + toler) { - output_msg(OUTPUT_MESSAGE, "\tERROR: inequality not satisfied for %s, %e\n", row_name[i], sum - array[(i * max_column_count) + count_unknowns]); - } - } -/* - * Check dissolution/precipitation constraints - */ - for (i = 0; i < count_unknowns; i++) { - if (delta_save[i] > 0.5 && delta1[i] < -toler) { - output_msg(OUTPUT_MESSAGE, "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", i, col_name[i], delta1[i]); - } else if (delta_save[i] < -0.5 && delta1[i] > toler) { - output_msg(OUTPUT_MESSAGE, "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", i, col_name[i], delta1[i]); - } - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int carbon_derivs(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, n, temp; - LDBLE c_uncertainty, d_carbon, alk_plus, alk_minus; - struct solution *solution_ptr_orig, *solution_ptr; - - inv_ptr->dalk_dph = (LDBLE *) free_check_null(inv_ptr->dalk_dph); - inv_ptr->dalk_dph = (LDBLE *) PHRQ_malloc( (size_t) inv_ptr->count_solns * sizeof(LDBLE) ); - if (inv_ptr->dalk_dph == NULL) malloc_error(); - - inv_ptr->dalk_dc = (LDBLE *) free_check_null(inv_ptr->dalk_dc); - inv_ptr->dalk_dc = (LDBLE *) PHRQ_malloc( (size_t) inv_ptr->count_solns * sizeof(LDBLE) ); - if (inv_ptr->dalk_dc == NULL) malloc_error(); - - for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &n, TRUE); - if (solution_ptr_orig == NULL) { - sprintf(error_string, "Solution %d for inverse " - "modeling not found.", inv_ptr->solns[i]); - error_msg(error_string, STOP); - } -/* - * Find carbon uncertainty - */ - c_uncertainty = 0; - d_carbon = 0; - for (j = 0; j < inv_ptr->count_elts; j++) { - if (inv_ptr->elts[j].master == s_co3->secondary) { - c_uncertainty = inv_ptr->elts[j].uncertainties[i]; - break; - } - } - if (c_uncertainty < 0.0) { - d_carbon = -c_uncertainty; - } else if (c_uncertainty > 0.0) { - for (k = 0; solution_ptr_orig->totals[k].description != NULL; k++) { - if (strcmp(solution_ptr_orig->totals[k].description, "C(4)") == 0) { - d_carbon = solution_ptr_orig->totals[k].moles / - solution_ptr_orig->mass_water * c_uncertainty; - break; - } - - } - } - -/* - * Make four copies of solution - * Modify ph and carbon in solutions - */ - set_ph_c(inv_ptr, i, solution_ptr_orig, -5, 0.0, 1.0, 0.0); - set_ph_c(inv_ptr, i, solution_ptr_orig, -4, 0.0, -1.0, 0.0); - if (c_uncertainty != 0) { - set_ph_c(inv_ptr, i, solution_ptr_orig, -3, d_carbon, 0.0, 1.0); - set_ph_c(inv_ptr, i, solution_ptr_orig, -2, d_carbon, 0.0, -1.0); - } -/* */ - temp = pr.all; - pr.all = FALSE; - initial_solutions(FALSE); - pr.all = temp; -/* - * dAlk/dpH - */ - solution_ptr = solution_bsearch(-5, &n, TRUE); - alk_plus = solution_ptr->total_alkalinity; - solution_ptr = solution_bsearch(-4, &n, TRUE); - alk_minus = solution_ptr->total_alkalinity; - inv_ptr->dalk_dph[i] = (alk_plus - alk_minus) / - (2.0 * inv_ptr->ph_uncertainties[i]); -/* - * dAlk/dC - */ - if (d_carbon != 0) { - solution_ptr = solution_bsearch(-3, &n, TRUE); - alk_plus = solution_ptr->total_alkalinity; - solution_ptr = solution_bsearch(-2, &n, TRUE); - alk_minus = solution_ptr->total_alkalinity; - inv_ptr->dalk_dc[i] = (alk_plus - alk_minus) / (2.0 * d_carbon); - } else { - inv_ptr->dalk_dc[i] = 0.0; - } - if (debug_inverse == TRUE) { - output_msg(OUTPUT_MESSAGE, "dAlk/dph = %e\tdAlk/dC = %e\n", - (double) inv_ptr->dalk_dph[i], (double) inv_ptr->dalk_dc[i]); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *solution_ptr_orig, - int n_user_new, - LDBLE d_carbon, - LDBLE ph_factor, - LDBLE c_factor) -/* ---------------------------------------------------------------------- */ -{ - int j, n_user_orig; - struct solution *solution_ptr; - struct conc *conc_ptr; - - n_user_orig = inv_ptr->solns[i]; - solution_duplicate(n_user_orig, n_user_new); - solution_ptr = solution_bsearch(n_user_new, &j, TRUE); - solution_ptr->new_def = TRUE; - solution_ptr->n_user_end = n_user_new; - solution_ptr->ph += inv_ptr->ph_uncertainties[i] * ph_factor; - for (j = 0; solution_ptr->totals[j].description != NULL; j++) { - conc_ptr = &solution_ptr->totals[j]; - conc_ptr->input_conc = conc_ptr->moles / - solution_ptr_orig->mass_water; - conc_ptr->units = string_hsave("Mol/kgw"); - if (strcmp(conc_ptr->description, "C(4)") == 0) { - conc_ptr->input_conc += d_carbon * c_factor; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int isotope_balance_equation(struct inverse *inv_ptr, int row, int n) -/* ---------------------------------------------------------------------- */ -/* - * routine fills in an isotope balance equation - * - * row is the row in array that needs to be filled - * n is the isotope number in inv_ptr - */ -{ - int i, j, k; - LDBLE isotope_number; - int column; - LDBLE f; - struct master *primary_ptr; - struct solution *solution_ptr; - struct isotope *isotope_ptr; -/* - * Determine primary master species and isotope number for - * isotope mass-balance equation - */ - column = 0; - primary_ptr = master_bsearch_primary(inv_ptr->isotopes[n].elt_name); - isotope_number = inv_ptr->isotopes[n].isotope_number; - /* isotope element must be defined */ - if (primary_ptr == NULL) { - sprintf(error_string, "In isotope calculation: element not defined: %s.", - inv_ptr->isotopes[n].elt_name); - error_msg(error_string, CONTINUE); - input_error++; - } - - /* isotope element must be primary */ - if (primary_ptr->primary != TRUE) { - sprintf(error_string, "Isotope mass-balance may only be used" - " for total element concentrations.\n" - "Secondary species not allowed: %s.", - inv_ptr->isotopes[n].elt_name); - error_msg(error_string, CONTINUE); - input_error++; - } - -/* - * Fill in terms for each solution - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - if (i == (inv_ptr->count_solns - 1)) { - f = -1.0; - } else { - f = 1.0; - } - - /* mixing fraction term */ - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - isotope_ptr = solution_ptr->isotopes; - for (j = 0; j < solution_ptr->count_isotopes; j++) { - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) { - array[row * max_column_count + i] += f * isotope_ptr[j].total * isotope_ptr[j].ratio; - } - } - - /* epsilon of total moles of element valence * ratio */ - for (j = 0; j < solution_ptr->count_isotopes; j++) { - - /* What to do with H and O, skip for now ??? */ - if (primary_ptr == s_hplus->primary || - primary_ptr == s_h2o->primary) continue; - - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) { - - /* find column of master for solution i*/ - for (k = 0; k < inv_ptr->count_elts; k++) { - if (isotope_ptr[j].master == inv_ptr->elts[k].master) break; - } - column = col_epsilon + (k * inv_ptr->count_solns) + i; - array[row * max_column_count + column] += f * isotope_ptr[j].ratio; - } - } - - /* epsilon of ratio * total of element valence */ - for (j = 0; j < solution_ptr->count_isotopes; j++) { - - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) { - - /* find column of epsilon for ratio of valence */ - for (k = 0; k < inv_ptr->count_isotope_unknowns; k++) { - if (isotope_ptr[j].master == inv_ptr->isotope_unknowns[k].master && - isotope_ptr[j].isotope_number == inv_ptr->isotope_unknowns[k].isotope_number) { - column = col_isotopes + (i * inv_ptr->count_isotope_unknowns) + k; - } - } - array[row * max_column_count + column] += f * isotope_ptr[j].total; - } - } - } -/* - * Fill in terms for each phase - */ - for (i = 0; i < inv_ptr->count_phases; i++) { - if (inv_ptr->phases[i].count_isotopes <= 0) continue; - isotope_ptr = inv_ptr->phases[i].isotopes; - for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) { - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) { - /* term for alpha phase unknowns */ - column = col_phases + i; - array[row * max_column_count + column] = isotope_ptr[j].ratio * isotope_ptr[j].coef; - /* term for phase isotope uncertainty unknown */ - column = col_phase_isotopes + i * inv_ptr->count_isotopes + n; - array[row * max_column_count + column] = isotope_ptr[j].coef; - break; - } - } - - } - return OK; -} -/* ---------------------------------------------------------------------- */ -int count_isotope_unknowns(struct inverse *inv_ptr, struct isotope **isotope_unknowns) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through elements for which isotope balances are requested - * and make a array of isotope structures - * return total number of isotope unknowns and structure array - */ - int i, k; - LDBLE isotope_number; - struct master *primary_ptr; - int count_isotopes; - struct isotope *isotopes; - - if (inv_ptr->count_isotopes == 0) { - *isotope_unknowns = NULL; - return(0); - } - isotopes = (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); - if (isotopes == NULL) malloc_error(); - count_isotopes = 0; - - for (i = 0; i < inv_ptr->count_isotopes; i++) { - primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); - isotope_number = inv_ptr->isotopes[i].isotope_number; - if (primary_ptr == NULL) { - sprintf(error_string, "Element not found for isotope calculation: %s.", - inv_ptr->isotopes[i].elt_name); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (primary_ptr->primary != TRUE) { - sprintf(error_string, "Isotope mass-balance may only be used" - " for total element concentrations.\n" - "Secondary species not allowed: %s.", - inv_ptr->isotopes[i].elt_name); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - - /* nonredox element */ - if (primary_ptr->s->secondary == NULL) { - isotopes = (struct isotope *) PHRQ_realloc(isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); - if (isotopes == NULL) malloc_error(); - isotopes[count_isotopes].primary = primary_ptr; - isotopes[count_isotopes].master = primary_ptr; - isotopes[count_isotopes].isotope_number = isotope_number; - isotopes[count_isotopes].elt_name = primary_ptr->elt->name; - count_isotopes++; - - /* redox element */ - } else { - - /* find master */ - for (k = 0; k < count_master; k++) { - if (master[k] == primary_ptr) break; - } - - /* sum all secondary for master */ - k++; - for ( ; k < count_master; k++) { - if (master[k]->elt->primary != primary_ptr) break; - isotopes = (struct isotope *) PHRQ_realloc(isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); - if (isotopes == NULL) malloc_error(); - isotopes[count_isotopes].primary = primary_ptr; - isotopes[count_isotopes].master = master[k]; - isotopes[count_isotopes].isotope_number = isotope_number; - isotopes[count_isotopes].elt_name = master[k]->elt->name; - count_isotopes++; - } - } - } - *isotope_unknowns = isotopes; - return (count_isotopes); -} -/* ---------------------------------------------------------------------- */ -int check_isotopes(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through elements for which isotope balances are requested - * and make sure each solution has isotope ratios defined - */ - int i, ii, j, k, l; - int err, found_isotope; - LDBLE isotope_number; - struct master *master_ptr, *primary_ptr; - struct solution *solution_ptr; - struct phase *phase_ptr; - char token[MAX_LENGTH]; - -/* - * Check solutions for necessary isotope data - */ - for (j = 0; j < inv_ptr->count_solns; j++) { - solution_ptr = solution_bsearch(inv_ptr->solns[j], &i, TRUE); - xsolution_zero(); - add_solution (solution_ptr, 1.0, 1.0); -/* - * Go through inverse isotopes and make sure isotope data for each solution - * inv_ptr->isotopes has elements; inv_ptr->i_u has redox states and uncertainties - */ - for (i = 0; i < inv_ptr->count_isotopes; i++) { - err = FALSE; - primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); - isotope_number = inv_ptr->isotopes[i].isotope_number; - found_isotope = FALSE; - for (k = 0; k < solution_ptr->count_isotopes; k++) { - if (solution_ptr->isotopes[k].primary == primary_ptr && - solution_ptr->isotopes[k].isotope_number == isotope_number) { - found_isotope = TRUE; - break; - } - } - if (found_isotope == TRUE) continue; - - /* did not find isotope, which is ok if element not in solution */ - if (primary_ptr == s_h2o->primary || primary_ptr == s_hplus->primary) { - err = TRUE; - } else if (primary_ptr->total > 0) { - err = TRUE; - } - if (err == TRUE) { - sprintf(error_string, - "In solution %d, isotope ratio(s) are needed for element: %g%s.", - solution_ptr->n_user, (double) isotope_number, primary_ptr->elt->name); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - } -/* - * Go through solution isotopes and set uncertainties - */ - for (k = 0; k < solution_ptr->count_isotopes; k++) { - solution_ptr->isotopes[k].x_ratio_uncertainty = NAN; -/* - * Search for secondary or primary master in inverse uncertainties - */ - ii = -1; - for (i = 0; i < inv_ptr->count_i_u; i++) { - master_ptr = master_bsearch(inv_ptr->i_u[i].elt_name); - if (master_ptr == solution_ptr->isotopes[k].master) { - ii = i; - break; - } - if (master_ptr == solution_ptr->isotopes[k].primary) { - ii = i; - } - } - /* solution isotope data not being used in inverse */ - if (ii == -1) continue; - - i = ii; - /* use inverse-defined uncertainties first */ - if (j < inv_ptr->i_u[i].count_uncertainties && inv_ptr->i_u[i].uncertainties[j] != NAN) { - solution_ptr->isotopes[k].x_ratio_uncertainty = inv_ptr->i_u[i].uncertainties[j]; - - /* use solution-defined uncertainties second */ - } else if (solution_ptr->isotopes[k].ratio_uncertainty != NAN) { - solution_ptr->isotopes[k].x_ratio_uncertainty = solution_ptr->isotopes[k].ratio_uncertainty; - /* use isotope defaults third */ - } else { - sprintf(token,"%g%s", (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name); - for (l = 0; l < count_iso_defaults; l++) { - if (strcmp(token, iso_defaults[l].name) == 0) { - solution_ptr->isotopes[k].x_ratio_uncertainty = iso_defaults[l].uncertainty; - sprintf(error_string, "Solution %d, element %g%s: default isotope ratio uncertainty is used, %g.", solution_ptr->n_user, (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name, (double) solution_ptr->isotopes[k].x_ratio_uncertainty); - warning_msg(error_string); - break; - } - } - } - if (solution_ptr->isotopes[k].x_ratio_uncertainty == NAN) { - sprintf(error_string, - "In solution %d, isotope ratio uncertainty is needed for element: %g%s.", solution_ptr->n_user, (double) solution_ptr->isotopes[k].isotope_number, solution_ptr->isotopes[k].elt_name); - error_msg(error_string, CONTINUE); - input_error++; - } - } - } -/* - * Check phases for necessary isotope data - */ - for (j = 0; j < inv_ptr->count_phases; j++) { - for (i = 0; i < inv_ptr->count_isotopes; i++) { - primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); - isotope_number = inv_ptr->isotopes[i].isotope_number; - found_isotope = FALSE; - for (k = 0; k < inv_ptr->phases[j].count_isotopes; k++) { - if (inv_ptr->phases[j].isotopes[k].primary == primary_ptr && - inv_ptr->phases[j].isotopes[k].isotope_number == isotope_number) { - found_isotope = TRUE; - break; - } - } - if (found_isotope == TRUE) continue; - - /* did not find isotope, which is ok if element not in solution */ - phase_ptr = inv_ptr->phases[j].phase; - k = 0; - while (phase_ptr->next_elt[k].elt != NULL) { - if (phase_ptr->next_elt[k].elt->primary == primary_ptr) { - if (s_hplus->primary == primary_ptr || - s_h2o->primary == primary_ptr) { - k++; - continue; - } else { - sprintf(error_string, - "In phase %s, isotope ratio(s) are needed for element: %g%s.", - phase_ptr->name, (double) isotope_number, primary_ptr->elt->name); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - } - k++; - } - } - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int phase_isotope_inequalities(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - int column; - char token[MAX_LENGTH]; - if (inv_ptr->count_isotopes <= 0 ) return OK; - for (i = 0; i < inv_ptr->count_phases; i++) { - if (inv_ptr->phases[i].count_isotopes <= 0) continue; - - for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) { - /* find index number */ - for (k = 0; k < inv_ptr->count_isotopes; k++) { - if (inv_ptr->phases[i].isotopes[j].elt_name == inv_ptr->isotopes[k].elt_name && - inv_ptr->phases[i].isotopes[j].isotope_number == inv_ptr->isotopes[k].isotope_number) { - break; - } - } - if (k >= inv_ptr->count_isotopes) break; - column = col_phase_isotopes + i * inv_ptr->count_isotopes + k; -/* - * zero column if uncertainty is zero - */ - if (inv_ptr->phases[i].isotopes[j].ratio_uncertainty == 0) { - for (k = 0; k < count_rows; k++) { - array[k * max_column_count + column] = 0.0; - } - continue; - } - -/* - * optimization - */ - array[(column - col_epsilon) * max_column_count + column] = SCALE_EPSILON / inv_ptr->phases[i].isotopes[j].ratio_uncertainty; -/* - * two inequalities to account for absolute value - */ - /* for phases constrained to precipitate */ - if (inv_ptr->phases[i].constraint == PRECIPITATE) { - array[count_rows * max_column_count + col_phases + i] = - inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - array[count_rows * max_column_count + column] = 1.0; - sprintf(token, "%s %s", - inv_ptr->phases[i].phase->name, - "iso pos"); - row_name[count_rows] = string_hsave(token); - count_rows++; - - array[count_rows * max_column_count + col_phases + i] = - inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - array[count_rows * max_column_count + column] = -1.0; - sprintf(token, "%s %s", - inv_ptr->phases[i].phase->name, - "iso neg"); - row_name[count_rows] = string_hsave(token); - count_rows++; - - /* for phases constrained to dissolve */ - } else if (inv_ptr->phases[i].constraint == DISSOLVE) { - array[count_rows * max_column_count + col_phases + i] = - -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - array[count_rows * max_column_count + column] = -1.0; - sprintf(token, "%s %s", - inv_ptr->phases[i].phase->name, - "iso pos"); - row_name[count_rows] = string_hsave(token); - count_rows++; - - array[count_rows * max_column_count + col_phases + i] = - -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - array[count_rows * max_column_count + column] = 1.0; - sprintf(token, "%s %s", - inv_ptr->phases[i].phase->name, - "iso neg"); - row_name[count_rows] = string_hsave(token); - count_rows++; - - /* Error if phase is not constrained*/ - } else { - sprintf(error_string, - "In isotope calculations, all phases containing isotopes must be" - " constrained.\nPhase %s is not constrained.\n", - inv_ptr->phases[i].phase->name); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - } - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int write_optimize_names(struct inverse *inv_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, j, row; - char token[MAX_LENGTH]; - row = 0; -/* - * epsilons for analytical data - */ - for (j = 0; j < inv_ptr->count_elts; j++) { - for (i = 0; i < inv_ptr->count_solns; i++) { - sprintf(token,"%s %s %d","optimize", - inv_ptr->elts[j].master->elt->name, - inv_ptr->solns[i]); - row_name[row] = string_hsave(token); - row++; - } - } -/* - * pH - */ - if (carbon > 0) { - for (i = 0; i < inv_ptr->count_solns; i++) { - sprintf(token,"%s %s %d","optimize", - "pH", - inv_ptr->solns[i]); - row_name[row] = string_hsave(token); - row++; - } - } -/* - * water - */ - sprintf(token,"%s %s","optimize", "water"); - row_name[row] = string_hsave(token); - row++; -/* - * solution isotopes - */ - for (i = 0; i < inv_ptr->count_solns; i++) { - for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - sprintf(token,"%s %d%s %d","optimize", - (int) inv_ptr->isotope_unknowns[j].isotope_number, - inv_ptr->isotope_unknowns[j].elt_name, - inv_ptr->solns[i]); - row_name[row] = string_hsave(token); - row++; - } - } -/* - * phase isotopes - */ - - for (i = 0; i < inv_ptr->count_phases; i++) { - for (j = 0; j < inv_ptr->count_isotopes; j++) { - sprintf(token,"%s %s %d%s","optimize", - inv_ptr->phases[i].phase->name, - (int) inv_ptr->isotopes[j].isotope_number, - inv_ptr->isotopes[j].elt_name); - row_name[row] = string_hsave(token); - row++; - } - } - return OK; -} diff --git a/isotopes.cpp b/isotopes.cpp deleted file mode 100644 index 885b19bc..00000000 --- a/isotopes.cpp +++ /dev/null @@ -1,1540 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: isotopes.c 402 2005-07-25 23:26:07Z dlpark $"; - -static int calculate_value_init(struct calculate_value *calculate_value_ptr); -static int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); -static int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); -static int master_isotope_init(struct master_isotope *master_isotope_ptr); - -/* ---------------------------------------------------------------------- */ -int read_isotopes(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads master species information for isotopes - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - - int j, l; - struct master_isotope *master_isotope_ptr, *master_isotope_ptr_major; - char token[MAX_LENGTH]; - struct element *elt_ptr; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "isotope", /* 0 */ - "total_is_major" /* 1 */ - }; - int count_opt_list = 2; - if (svnid == NULL) fprintf(stderr," "); - - master_isotope_ptr = NULL; - elt_ptr = NULL; -/* - * Read name followed by options - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SPECIES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* isotope */ - if (elt_ptr == NULL) { - sprintf(error_string, "The element of which this isotope is a minor isotope has not been defined, %s. ISOTOPES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - /* - * Save an isotope - */ - master_isotope_ptr = NULL; - j = copy_token(token, &next_char, &l); - master_isotope_ptr = master_isotope_store(token, TRUE); - master_isotope_ptr->elt = elt_ptr; - master_isotope_ptr->minor_isotope = TRUE; - master_isotope_ptr->total_is_major = FALSE; - /* - * Read units - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting units for isotopic values, %s. ISOTOPES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - master_isotope_ptr->units = string_hsave(token); - /* - * Read standard - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting isotope ratio of standard, %s. ISOTOPES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - sscanf(token,SCANFORMAT, &(master_isotope_ptr->standard)); - opt_save = OPTION_DEFAULT; - break; - case 1: /* total_is_major_isotope */ -#ifdef SKIP - if (elt_ptr == NULL) { - sprintf(error_string, "The element of which this isotope is a minor isotope has not been defined, %s. ISOTOPES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - master_isotope_ptr_major->total_is_major = get_true_false(next_char, TRUE); -#endif - sprintf(error_string, "Obsolete identifier. The total of the element must be the sum of all isotopes. ISOTOPES data block.\n%s", line); - warning_msg(error_string); - break; - case OPTION_DEFAULT: -/* - * Read and element name - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting an element name for isotope definition, %s. ISOTOPES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - elt_ptr = element_store(token); - master_isotope_ptr = master_isotope_store(token, TRUE); - master_isotope_ptr_major = master_isotope_ptr; - master_isotope_ptr->elt = elt_ptr; - master_isotope_ptr->minor_isotope = FALSE; - master_isotope_ptr->total_is_major = FALSE; - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_calculate_values (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate calculate_value - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - int l, length, line_length, n; - int return_value, opt, opt_save; - char token[MAX_LENGTH]; - struct calculate_value *calculate_value_ptr; - char *description; - int n_user, n_user_end; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end" /* 1 */ - }; - int count_opt_list = 2; -/* - * Read advection number (not currently used) - */ - n = -1; - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - return_value = UNKNOWN; - calculate_value_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in CALCULATE_VALUE keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPT_1; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: /* read calculate_value name */ -/* - * Read calculate_value name - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting a name for calculate_value definition, %s. CALCULATE_VALUES data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - calculate_value_ptr = calculate_value_store(token, TRUE); - calculate_value_ptr->new_def = TRUE; - calculate_value_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); - if (calculate_value_ptr->commands == NULL) malloc_error(); - calculate_value_ptr->commands[0] = '\0'; - calculate_value_ptr->linebase = NULL; - calculate_value_ptr->varbase = NULL; - calculate_value_ptr->loopbase = NULL; - opt_save = OPT_1; - break; - - case OPT_1: /* read command */ - length = strlen(calculate_value_ptr->commands); - line_length = strlen(line); - calculate_value_ptr->commands = (char *) PHRQ_realloc(calculate_value_ptr->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (calculate_value_ptr->commands == NULL) malloc_error(); - calculate_value_ptr->commands[length] = ';'; - calculate_value_ptr->commands[length + 1] = '\0'; - strcat((calculate_value_ptr->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* output_msg(OUTPUT_MESSAGE, "%s", calculate_value[0].commands); - */ return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_isotope_ratios (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads isotope_ratio info, ratios are calculated with - * Basic programs read in CALCULATE_VALUE data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - int l, n; - int return_value, opt, opt_save; - char token[MAX_LENGTH]; - struct isotope_ratio *isotope_ratio_ptr; - char *description; - int n_user, n_user_end; - char *next_char; - const char *opt_list[] = { - "no_options" /* 0 */ - }; - int count_opt_list = 0; -/* - * Read number (not currently used) - */ - n = -1; - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - return_value = UNKNOWN; - isotope_ratio_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in ISOTOPE_RATIOS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case OPTION_DEFAULT: /* read isotope_ratio name */ -/* - * Read isotope_ratio name - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting a name for isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - isotope_ratio_ptr = isotope_ratio_store(token, TRUE); - /* - * Read isotope - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting a name of isotope for an isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - isotope_ratio_ptr->isotope_name = string_hsave(token); - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_isotope_alphas (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads isotope_alpha info, ratios are calculated with - * Basic programs read in CALCULATE_VALUE data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - int l, n; - int return_value, opt, opt_save; - char token[MAX_LENGTH]; - struct isotope_alpha *isotope_alpha_ptr; - char *description; - int n_user, n_user_end; - char *next_char; - const char *opt_list[] = { - "no_options" /* 0 */ - }; - int count_opt_list = 0; -/* - * Read number (not currently used) - */ - n = -1; - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - return_value = UNKNOWN; - isotope_alpha_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in ISOTOPE_ALPHAS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case OPTION_DEFAULT: /* read isotope_alpha name */ -/* - * Read isotope_alpha name - */ - if (copy_token(token, &next_char, &l) == EMPTY) { - sprintf(error_string, "Expecting a name for isotope_alpha definition, %s. ISOTOPE_ALPHAS data block.", line); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - isotope_alpha_ptr = isotope_alpha_store(token, TRUE); - isotope_alpha_ptr->name = string_hsave(token); - if (copy_token(token, &next_char, &l) != EMPTY) { - isotope_alpha_ptr->named_logk = string_hsave(token); - } - - - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int add_isotopes(struct solution *solution_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; - char *ptr; - struct master_isotope *master_isotope_ptr; - LDBLE total_moles; - /* - * zero out isotopes - */ - for (i = 0; i < count_master_isotope; i++) { - master_isotope[i]->moles = 0; - } - master_isotope_ptr = master_isotope_search("H"); - if (master_isotope_ptr != NULL) { - total_moles = total_h_x; - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); - } - master_isotope_ptr = master_isotope_search("O"); - if (master_isotope_ptr != NULL) { - total_moles = total_o_x; - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); - } - for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { - ptr=solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); - if (master_isotope_ptr == NULL) continue; - if (master_isotope_ptr->minor_isotope == FALSE) { - total_moles = total(master_isotope_ptr->name); - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, total_moles); - } - } - /* - * Set isotopes flag - */ - initial_solution_isotopes = FALSE; - for (i= 0; i < count_master_isotope; i++) { - if (master_isotope[i]->minor_isotope == TRUE && master_isotope[i]->moles > 0) { - initial_solution_isotopes = TRUE; - } - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int calculate_isotope_moles(struct element *elt_ptr, struct solution *solution_ptr, LDBLE total_moles) -/* ---------------------------------------------------------------------- */ -{ - int i, j, iter; - int count_isotopes, total_is_major; - char *ptr; - struct master_isotope *master_isotope_ptr, *master_isotope_ptr1; - struct master_isotope list[MAX_ELTS]; - LDBLE m_major, tot; -#ifdef SKIP - struct elt_list *iso_elt_list; - struct master *master_ptr; -#endif - /* - * Get total concentration of elt_ptr - */ - if (total_moles <= 0) { - sprintf(error_string, "Can not calculate molality of isotopes, molality of element is zero, %s", elt_ptr->name); - warning_msg(error_string); - return(ERROR); - } - m_major = total_moles; - /* - * Make a list of isotopes - */ - count_isotopes = 0; - total_is_major = FALSE; - master_isotope_ptr = master_isotope_search("H"); - if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) { - memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); - list[count_isotopes].ratio = 1.0; - if (list[count_isotopes].minor_isotope == FALSE) { - total_is_major = list[count_isotopes].total_is_major; - } - count_isotopes++; - } - master_isotope_ptr = master_isotope_search("O"); - if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) { - memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); - list[count_isotopes].ratio = 1.0; - if (list[count_isotopes].minor_isotope == FALSE) { - total_is_major = list[count_isotopes].total_is_major; - } - count_isotopes++; - } - for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { - ptr=solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); - if (master_isotope_ptr == NULL) continue; - if (master_isotope_ptr->elt != elt_ptr) continue; - memcpy(&(list[count_isotopes]), master_isotope_ptr, sizeof(struct master_isotope)); - if (list[count_isotopes].minor_isotope == FALSE) { - total_is_major = list[count_isotopes].total_is_major; - } - count_isotopes++; - } - /* - * Loop to calculate isotope molalities - */ - for (iter = 0; iter < itmax; iter++) { - tot = 0; - for (i = 0; i < count_isotopes; i++) { - if (list[i].minor_isotope == FALSE) { - list[i].moles = m_major; - tot += m_major; - continue; - } - if (strcmp_nocase(list[i].units, "permil") == 0) { - from_permil(&(list[i]), m_major); - tot += list[i].moles; - continue; - } - if (strcmp_nocase(list[i].units, "pct") == 0) { - from_pct(&(list[i]), total_moles); - tot += list[i].moles; - continue; - } - if (strcmp_nocase(list[i].units, "pmc") == 0) { - from_pct(&(list[i]), total_moles); - tot += list[i].moles; - continue; - } - if (strcmp_nocase(list[i].units, "tu") == 0) { - from_tu(&(list[i])); - tot += list[i].moles; - continue; - } - if (strcmp_nocase(list[i].units, "pci/l") == 0) { - from_pcil(&(list[i])); - tot += list[i].moles; - continue; - } - sprintf(error_string, "Isotope units not recognized, %s",list[i].units); - input_error++; - error_msg(error_string, CONTINUE); - } - if (total_is_major == TRUE) break; - if (fabs(total_moles - tot) < convergence_tolerance*total_moles) { - break; - } else { - m_major = m_major*total_moles/tot; - } - } - if (iter >= itmax) { - error_msg("Failed to converge in CALCULATE_ISOTOPE_MOLES.", STOP); - } - /* - * Update master_isotope - */ - for (j = 0; j < count_master_isotope; j++) { - for (i = 0; i < count_isotopes; i++) { - if (list[i].name== master_isotope[j]->name) { - memcpy(master_isotope[j], &(list[i]), sizeof(struct master_isotope)); - } - } - } - /* - * Update solution - */ - master_isotope_ptr1 = master_isotope_search("H"); - if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) { - total_h_x = m_major; - } - master_isotope_ptr1 = master_isotope_search("O"); - if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) { - total_o_x = m_major; - } - for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { - ptr=solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); - if (master_isotope_ptr == NULL) continue; - if (master_isotope_ptr->elt != elt_ptr) continue; - solution_ptr->totals[i].moles = master_isotope_ptr->moles; - solution_ptr->totals[i].input_conc = master_isotope_ptr->moles; - } - -#ifdef SKIP - /* - * make elt list - */ - iso_elt_list = PHRQ_malloc((size_t) (count_isotopes + 1)*sizeof(struct elt_list)); - if (iso_elt_list == NULL) malloc_error(); - for (i = 0; i < count_isotopes; i++) { - master_ptr = master_bsearch(list[i].name); - if (master_ptr == NULL) { - sprintf(error_string, "Did not find element in CALCULATE_ISOTOPES, %s.", list[i].name); - error_msg(error_string, STOP); - } - iso_elt_list[i].elt = master_ptr->elt; - iso_elt_list[i].coef = list[i].moles; - } - iso_elt_list[i].elt = NULL; -#endif - return(OK); -} -/* ---------------------------------------------------------------------- */ -int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total) -/* ---------------------------------------------------------------------- */ -{ - LDBLE r; - - r = (master_isotope_ptr->ratio/1000. + 1.0)*master_isotope_ptr->standard; - master_isotope_ptr->moles = major_total * r; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int from_pct(struct master_isotope *master_isotope_ptr, LDBLE total_moles) -/* ---------------------------------------------------------------------- */ -{ - master_isotope_ptr->moles = master_isotope_ptr->ratio/100*master_isotope_ptr->standard*total_moles; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int from_tu(struct master_isotope *master_isotope_ptr) -/* ---------------------------------------------------------------------- */ -{ - master_isotope_ptr->moles = master_isotope_ptr->ratio*master_isotope_ptr->standard*mass_water_aq_x/gfw_water; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int from_pcil(struct master_isotope *master_isotope_ptr) -/* ---------------------------------------------------------------------- */ -{ - master_isotope_ptr->moles = master_isotope_ptr->ratio*master_isotope_ptr->standard*mass_water_aq_x/gfw_water; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_initial_solution_isotopes(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print isotopes for initial solution - */ - int i, j; - int print_isotope; - - if (pr.initial_isotopes == FALSE || pr.all == FALSE) return(OK); - if (state != INITIAL_SOLUTION) return(OK); - if (initial_solution_isotopes == FALSE) return(OK); -/* - * Print heading - */ - print_centered("Isotopes"); - output_msg(OUTPUT_MESSAGE,"%10s\t%12s\t%12s\t%12s\t%12s\n\n", "Isotope","Molality","Moles","Ratio", "Units"); - for (i = 0; i < count_master_isotope; i++) { - if (master_isotope[i]->minor_isotope == FALSE) { - print_isotope = FALSE; - for (j = 0; j < count_master_isotope; j++) { - if ((master_isotope[j]->elt == master_isotope[i]->elt) && - (master_isotope[j]->minor_isotope == TRUE) && - (master_isotope[j]->moles > 0)) { - print_isotope = TRUE; - break; - } - } - if (print_isotope == FALSE) continue; - /* - * Print isotope values - */ - output_msg(OUTPUT_MESSAGE,"%10s\t%12.5e\t%12.5e\n", master_isotope[i]->name, (double) (master_isotope[i]->moles/mass_water_aq_x), (double) master_isotope[i]->moles); - for (j = 0; j < count_master_isotope; j++) { - if (i == j) continue; - if ((master_isotope[j]->elt == master_isotope[i]->elt) && - (master_isotope[j]->minor_isotope == TRUE)) { - output_msg(OUTPUT_MESSAGE,"%10s\t%12.5e\t%12.5e\t%12.5e\t%12s\n", master_isotope[j]->name, (double) (master_isotope[j]->moles/mass_water_aq_x), (double) master_isotope[j]->moles, (double) master_isotope[j]->ratio, master_isotope[j]->units); - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_isotopes(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Punch isotope ratios relative to standards - */ - int i; - LDBLE iso; - struct isotope_ratio *isotope_ratio_ptr; - struct master_isotope *master_isotope_ptr; - - if (punch.in == FALSE || punch.isotopes == FALSE) return(OK); - if (punch.count_isotopes == 0) return(OK); - for (i = 0; i < punch.count_isotopes; i++) { - iso = MISSING; - if (state == INITIAL_SOLUTION) { - isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); - if (isotope_ratio_ptr != NULL) { - master_isotope_ptr = master_isotope_search(isotope_ratio_ptr->isotope_name); - if (master_isotope_ptr != NULL && master_isotope_ptr->minor_isotope == TRUE) { - iso = master_isotope_ptr->ratio; - } - } - } else { - isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); - if (isotope_ratio_ptr != NULL) { - iso = isotope_ratio_ptr->converted_ratio; - } - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("I_%s",punch.isotopes[i].name),"%12.4e\t", iso); - } else { - fpunchf(sformatf("I_%s",punch.isotopes[i].name),"%20.12e\t", iso); - } - - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_calculate_values(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Punch calculate values - */ - int i; - LDBLE result; - struct calculate_value *calculate_value_ptr; - - if (punch.in == FALSE || punch.calculate_values == FALSE) return(OK); - if (punch.count_calculate_values == 0) return(OK); - for (i = 0; i < punch.count_calculate_values; i++) { - result = MISSING; - calculate_value_ptr = calculate_value_search(punch.calculate_values[i].name); - if (calculate_value_ptr != NULL) { - result = calculate_value_ptr->value; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("V_%s",punch.calculate_values[i].name),"%12.4e\t", result); - } else { - fpunchf(sformatf("V_%s",punch.calculate_values[i].name),"%20.12e\t", result); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_isotope_ratios(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print isotopes for initial solution - */ - int i, j; - int print_isotope; - struct master *master_ptr; - struct master_isotope *master_isotope_ptr; - struct isotope_ratio *isotope_ratio_ptr; - char token[MAX_LENGTH]; - - - if (pr.isotope_ratios == FALSE || pr.all == FALSE) return(OK); - if (state == INITIAL_SOLUTION) return(OK); -/* - * Print heading - */ - print_isotope = FALSE; - for (i = 0; i < count_master_isotope; i++) { - if (master_isotope[i]->minor_isotope == FALSE) continue; - master_ptr = master_bsearch(master_isotope[i]->name); - if (master_ptr == NULL) continue; - if (master_ptr->total > 0 || master_ptr->s->moles > 0) { - print_isotope = TRUE; - break; - } - } - if (print_isotope == FALSE) return(OK); - - print_centered("Isotope Ratios"); - output_msg(OUTPUT_MESSAGE,"%25s\t%12s\t%15s\n\n", "Isotope Ratio","Ratio","Input Units"); - - for (j = 0; j < count_isotope_ratio; j++) { - if (isotope_ratio[j]->ratio == MISSING) continue; - isotope_ratio_ptr = isotope_ratio[j]; - master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name); - /* - * Print isotope ratio - */ - strcpy(token, isotope_ratio[j]->name); - while(replace("_"," ",token) == TRUE); - output_msg(OUTPUT_MESSAGE," %-20s\t%12.5e\t%15.5g %-10s\n", token, (double) isotope_ratio[j]->ratio, (double) isotope_ratio[j]->converted_ratio, master_isotope_ptr->units); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_isotope_alphas(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print isotopes for initial solution - */ - int i, j; - int print_isotope; - struct master *master_ptr; - struct isotope_alpha *isotope_alpha_ptr; - char token[MAX_LENGTH]; - LDBLE log_alpha; - - if (pr.isotope_alphas == FALSE || pr.all == FALSE) return(OK); - if (state == INITIAL_SOLUTION) return(OK); -/* - * Print heading - */ - print_isotope = FALSE; - for (i = 0; i < count_master_isotope; i++) { - if (master_isotope[i]->minor_isotope == FALSE) continue; - master_ptr = master_bsearch(master_isotope[i]->name); - if (master_ptr == NULL) continue; - if (master_ptr->total > 0 || master_ptr->s->moles > 0) { - print_isotope = TRUE; - break; - } - } - if (print_isotope == FALSE) return(OK); - - print_centered("Isotope Alphas"); - output_msg(OUTPUT_MESSAGE,"%75s\n", "1000ln(Alpha)"); - output_msg(OUTPUT_MESSAGE,"%79s\n", "----------------------"); - output_msg(OUTPUT_MESSAGE,"%-37s%14s%14s%12.1f C\n\n", " Isotope Ratio", "Solution alpha", "Solution", (double) tc_x); - - for (j = 0; j < count_isotope_alpha; j++) { - if (isotope_alpha[j]->value == MISSING) continue; - isotope_alpha_ptr = isotope_alpha[j]; - /* - * Print isotope ratio - */ - strcpy(token, isotope_alpha[j]->name); - while(replace("_"," ",token) == TRUE); - if (isotope_alpha[j]->named_logk != NULL) { - if (isotope_alpha[j]->value <=0) { - log_alpha = -999.999; - } else { - log_alpha = 1000*log(isotope_alpha[j]->value); - } - output_msg(OUTPUT_MESSAGE,"%-37s%14.5g%14.5g%14.5g\n", token, (double) isotope_alpha[j]->value, (double) log_alpha, (double) (1000*calc_logk_n(isotope_alpha[j]->named_logk)*LOG_10)); - } else { - output_msg(OUTPUT_MESSAGE,"%-37s%14.5g%14.5g\n", token, (double) isotope_alpha[j]->value, (double) (1000*log(isotope_alpha[j]->value))); - } - - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int calculate_values(void) -/* ---------------------------------------------------------------------- */ -{ - int j; - struct calculate_value *calculate_value_ptr; - struct isotope_ratio *isotope_ratio_ptr; - struct isotope_alpha *isotope_alpha_ptr; - struct master_isotope *master_isotope_ptr; - char command[] = "run"; - - - /* - * initialize ratios as missing - */ - for (j = 0; j < count_calculate_value; j++) { - calculate_value[j]->calculated = FALSE; - calculate_value[j]->value = MISSING; - } - - for (j = 0; j < count_calculate_value; j++) { - calculate_value_ptr = calculate_value[j]; - rate_moles = NAN; - if (calculate_value_ptr->new_def == TRUE) { - if (basic_compile(calculate_value[j]->commands, &calculate_value[j]->linebase, &calculate_value[j]->varbase, &calculate_value[j]->loopbase) != 0) { - sprintf (error_string, "Fatal Basic error in CALCULATE_VALUES %s.", calculate_value[j]->name); - error_msg(error_string, STOP); - } - calculate_value_ptr->new_def = FALSE; - } - if (basic_run(command, calculate_value[j]->linebase, calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) { - sprintf (error_string, "Fatal Basic error in calculate_value %s.", calculate_value[j]->name); - error_msg(error_string, STOP); - } - if (rate_moles == NAN) { - sprintf(error_string, "Calculated value not SAVE'd for %s.", calculate_value[j]->name); - error_msg(error_string, STOP); - } else { - calculate_value[j]->calculated = TRUE; - calculate_value[j]->value = rate_moles; - } - } - for (j = 0; j < count_isotope_ratio; j++) { - isotope_ratio_ptr = isotope_ratio[j]; - master_isotope_ptr = master_isotope_search(isotope_ratio_ptr->isotope_name); - calculate_value_ptr = calculate_value_search(isotope_ratio_ptr->name); - /* - * Calculate converted isotope ratio - */ - if (calculate_value_ptr->value == MISSING) { - isotope_ratio_ptr->ratio = MISSING; - isotope_ratio_ptr->converted_ratio = MISSING; - } else { - isotope_ratio_ptr->ratio = calculate_value_ptr->value; - isotope_ratio_ptr->converted_ratio = convert_isotope(master_isotope_ptr, calculate_value_ptr->value); - } - } - for (j = 0; j < count_isotope_alpha; j++) { - isotope_alpha_ptr = isotope_alpha[j]; - calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); - /* - * Calculate converted isotope ratio - */ - if (calculate_value_ptr->value == MISSING) { - isotope_alpha_ptr->value = MISSING; - } else { - isotope_alpha_ptr->value = calculate_value_ptr->value; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio) -/* ---------------------------------------------------------------------- */ -{ - char *units; - units = master_isotope_ptr->units; - - if (strcmp_nocase(units, "permil") == 0) { - return( (ratio/master_isotope_ptr->standard - 1) * 1000); - } - if (strcmp_nocase(units, "pct") == 0) { - return(ratio/master_isotope_ptr->standard*100.); - } - if (strcmp_nocase(units, "pmc") == 0) { - return(ratio/master_isotope_ptr->standard*100.); - } - if (strcmp_nocase(units, "tu") == 0) { - return(ratio/master_isotope_ptr->standard); - } - if (strcmp_nocase(units, "pci/l") == 0) { - return(ratio/master_isotope_ptr->standard); - } - sprintf(error_string, "Did not recognize isotope units in convert_isotope, %s", units); - error_msg(error_string, STOP); - return (-99.0); -} -/* - * Utility routines for master_isotope - */ - -/* ---------------------------------------------------------------------- */ -struct master_isotope *master_isotope_store (char *name, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for master_isotope. - * - * Pointer to a master_isotope structure is always returned. - * - * If the string is not found, a new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old master_isotope structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old master_isotope structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "master_isotope". - * replace_if_found input, TRUE means reinitialize master_isotope structure if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to master_isotope structure "master_isotope" where "name" can be found. - */ - int n; - struct master_isotope *master_isotope_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - - item.key = name; - item.data = NULL; - found_item = hsearch_multi(master_isotope_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - master_isotope_ptr = (struct master_isotope *) (found_item->data); - return (master_isotope_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - master_isotope_ptr = (struct master_isotope *) (found_item->data); - master_isotope_init(master_isotope_ptr); - } else { - n = count_master_isotope++; - /* make sure there is space in s */ - if (count_master_isotope >= max_master_isotope) { - space ((void **) ((void *) &master_isotope), count_master_isotope, &max_master_isotope, sizeof(struct master_isotope *)); - } - /* Make new master_isotope structure */ - master_isotope[n] = master_isotope_alloc(); - master_isotope_ptr = master_isotope[n]; - } - /* set name and z in pointer in master_isotope structure */ - master_isotope_ptr->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = master_isotope_ptr->name; - item.data = (void *) master_isotope_ptr; - found_item = hsearch_multi(master_isotope_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in master_isotope_store."); - error_msg(error_string, CONTINUE); - } - - return (master_isotope_ptr); -} -/* ---------------------------------------------------------------------- */ -struct master_isotope *master_isotope_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a master_isotope structure, initializes - * arguments: void - * return: pointer to a master_isotope structure - */ -{ - struct master_isotope *master_isotope_ptr; - master_isotope_ptr=(struct master_isotope *) PHRQ_malloc(sizeof(struct master_isotope)); - if (master_isotope_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - master_isotope_init(master_isotope_ptr); - - return(master_isotope_ptr); -} -/* ---------------------------------------------------------------------- */ -static int master_isotope_init(struct master_isotope *master_isotope_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a master_isotope structure - */ -{ -/* - * set pointers in structure to NULL - */ - master_isotope_ptr->name=NULL; - master_isotope_ptr->units=NULL; - master_isotope_ptr->standard=0; - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct master_isotope *master_isotope_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for master_isotope. - * - * Arguments: - * name input, character string to be found in "master_isotope". - * - * Returns: - * pointer to master_isotope structure "master_isotope" where "name" can be found. - * or NULL if not found. - */ - struct master_isotope *master_isotope_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - item.key = name; - item.data = NULL; - found_item = hsearch_multi(master_isotope_hash_table, item, FIND); - - if (found_item != NULL) { - master_isotope_ptr = (struct master_isotope *) (found_item->data); - return (master_isotope_ptr); - } - return(NULL); -} -/* - * Utility routines for calculate_value - */ - -/* ---------------------------------------------------------------------- */ -struct calculate_value *calculate_value_store (char *name, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for calculate_value. - * - * Pointer to a calculate_value structure is always returned. - * - * If the string is not found, a new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old calculate_value structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old calculate_value structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "calculate_value". - * replace_if_found input, TRUE means reinitialize calculate_value structure if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to calculate_value structure "calculate_value" where "name" can be found. - */ - int n; - struct calculate_value *calculate_value_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(calculate_value_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - calculate_value_ptr = (struct calculate_value *) (found_item->data); - return (calculate_value_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - calculate_value_ptr = (struct calculate_value *) (found_item->data); - calculate_value_free(calculate_value_ptr); - calculate_value_init(calculate_value_ptr); - } else { - n = count_calculate_value++; - /* make sure there is space in s */ - if (count_calculate_value >= max_calculate_value) { - space ((void **) ((void *) &calculate_value), count_calculate_value, &max_calculate_value, sizeof(struct calculate_value *)); - } - /* Make new calculate_value structure */ - calculate_value[n] = calculate_value_alloc(); - calculate_value_ptr = calculate_value[n]; - } - /* set name and z in pointer in calculate_value structure */ - calculate_value_ptr->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = string_hsave(token); - item.data = (void *) calculate_value_ptr; - found_item = hsearch_multi(calculate_value_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in calculate_value_store."); - error_msg(error_string, CONTINUE); - } - - return (calculate_value_ptr); -} -/* ---------------------------------------------------------------------- */ -struct calculate_value *calculate_value_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a calculate_value structure, initializes - * arguments: void - * return: pointer to a calculate_value structure - */ -{ - struct calculate_value *calculate_value_ptr; - calculate_value_ptr=(struct calculate_value *) PHRQ_malloc(sizeof(struct calculate_value)); - if (calculate_value_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - calculate_value_init(calculate_value_ptr); - - return(calculate_value_ptr); -} -/* ---------------------------------------------------------------------- */ -static int calculate_value_init(struct calculate_value *calculate_value_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a calculate_value structure - */ -{ -/* - * set pointers in structure to NULL - */ - calculate_value_ptr->name=NULL; - calculate_value_ptr->commands=NULL; - calculate_value_ptr->linebase=NULL; - calculate_value_ptr->varbase=NULL; - calculate_value_ptr->loopbase=NULL; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct calculate_value *calculate_value_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for calculate_value. - * - * Arguments: - * name input, character string to be found in "calculate_value". - * - * Returns: - * pointer to calculate_value structure "calculate_value" where "name" can be found. - * or NULL if not found. - */ - struct calculate_value *calculate_value_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(calculate_value_hash_table, item, FIND); - - if (found_item != NULL) { - calculate_value_ptr = (struct calculate_value *) (found_item->data); - return (calculate_value_ptr); - } - return(NULL); -} -/* ---------------------------------------------------------------------- */ -int calculate_value_free(struct calculate_value *calculate_value_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees memory allocated within calculate_value[i], does not free calculate_value structure - * Input: i, number of calculate_value - * Return: OK - */ - char cmd[] = "new; quit"; - - if (calculate_value_ptr == NULL) return(ERROR); - calculate_value_ptr->commands = (char *) free_check_null(calculate_value_ptr->commands); - basic_run(cmd, calculate_value_ptr->linebase, calculate_value_ptr->varbase, calculate_value_ptr->loopbase); - calculate_value_ptr->linebase = NULL; - calculate_value_ptr->varbase = NULL; - calculate_value_ptr->loopbase = NULL; - return(OK); -} -/* - * Utility routines for isotope_ratio - */ - -/* ---------------------------------------------------------------------- */ -struct isotope_ratio *isotope_ratio_store (char *name, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for isotope_ratio. - * - * Pointer to a isotope_ratio structure is always returned. - * - * If the string is not found, a new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old isotope_ratio structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old isotope_ratio structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "isotope_ratio". - * replace_if_found input, TRUE means reinitialize isotope_ratio structure if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. - */ - int n; - struct isotope_ratio *isotope_ratio_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); - return (isotope_ratio_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); - isotope_ratio_init(isotope_ratio_ptr); - } else { - n = count_isotope_ratio++; - /* make sure there is space in s */ - if (count_isotope_ratio >= max_isotope_ratio) { - space ((void **) ((void *) &isotope_ratio), count_isotope_ratio, &max_isotope_ratio, sizeof(struct isotope_ratio *)); - } - /* Make new isotope_ratio structure */ - isotope_ratio[n] = isotope_ratio_alloc(); - isotope_ratio_ptr = isotope_ratio[n]; - } - /* set name and z in pointer in isotope_ratio structure */ - isotope_ratio_ptr->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = string_hsave(token); - item.data = (void *) isotope_ratio_ptr; - found_item = hsearch_multi(isotope_ratio_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in isotope_ratio_store."); - error_msg(error_string, CONTINUE); - } - - return (isotope_ratio_ptr); -} -/* ---------------------------------------------------------------------- */ -struct isotope_ratio *isotope_ratio_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a isotope_ratio structure, initializes - * arguments: void - * return: pointer to a isotope_ratio structure - */ -{ - struct isotope_ratio *isotope_ratio_ptr; - isotope_ratio_ptr=(struct isotope_ratio *) PHRQ_malloc(sizeof(struct isotope_ratio)); - if (isotope_ratio_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - isotope_ratio_init(isotope_ratio_ptr); - - return(isotope_ratio_ptr); -} -/* ---------------------------------------------------------------------- */ -static int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a isotope_ratio structure - */ -{ -/* - * set pointers in structure to NULL - */ - isotope_ratio_ptr->name=NULL; - isotope_ratio_ptr->isotope_name=NULL; - isotope_ratio_ptr->ratio = MISSING; - isotope_ratio_ptr->converted_ratio = MISSING; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct isotope_ratio *isotope_ratio_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for isotope_ratio. - * - * Arguments: - * name input, character string to be found in "isotope_ratio". - * - * Returns: - * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. - * or NULL if not found. - */ - struct isotope_ratio *isotope_ratio_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); - - if (found_item != NULL) { - isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); - return (isotope_ratio_ptr); - } - return(NULL); -} -/* - * Utility routines for isotope_alpha - */ - -/* ---------------------------------------------------------------------- */ -struct isotope_alpha *isotope_alpha_store (char *name, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for isotope_alpha. - * - * Pointer to a isotope_alpha structure is always returned. - * - * If the string is not found, a new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old isotope_alpha structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old isotope_alpha structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "isotope_alpha". - * replace_if_found input, TRUE means reinitialize isotope_alpha structure if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. - */ - int n; - struct isotope_alpha *isotope_alpha_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); - return (isotope_alpha_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); - isotope_alpha_init(isotope_alpha_ptr); - } else { - n = count_isotope_alpha++; - /* make sure there is space in s */ - if (count_isotope_alpha >= max_isotope_alpha) { - space ((void **) ((void *) &isotope_alpha), count_isotope_alpha, &max_isotope_alpha, sizeof(struct isotope_alpha *)); - } - /* Make new isotope_alpha structure */ - isotope_alpha[n] = isotope_alpha_alloc(); - isotope_alpha_ptr = isotope_alpha[n]; - } - /* set name and z in pointer in isotope_alpha structure */ - isotope_alpha_ptr->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = string_hsave(token); - item.data = (void *) isotope_alpha_ptr; - found_item = hsearch_multi(isotope_alpha_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in isotope_alpha_store."); - error_msg(error_string, CONTINUE); - } - - return (isotope_alpha_ptr); -} -/* ---------------------------------------------------------------------- */ -struct isotope_alpha *isotope_alpha_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a isotope_alpha structure, initializes - * arguments: void - * return: pointer to a isotope_alpha structure - */ -{ - struct isotope_alpha *isotope_alpha_ptr; - isotope_alpha_ptr=(struct isotope_alpha *) PHRQ_malloc(sizeof(struct isotope_alpha)); - if (isotope_alpha_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - isotope_alpha_init(isotope_alpha_ptr); - - return(isotope_alpha_ptr); -} -/* ---------------------------------------------------------------------- */ -static int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a isotope_alpha structure - */ -{ -/* - * set pointers in structure to NULL - */ - isotope_alpha_ptr->name=NULL; - isotope_alpha_ptr->named_logk=NULL; - isotope_alpha_ptr->value = MISSING; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct isotope_alpha *isotope_alpha_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for isotope_alpha. - * - * Arguments: - * name input, character string to be found in "isotope_alpha". - * - * Returns: - * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. - * or NULL if not found. - */ - struct isotope_alpha *isotope_alpha_ptr; - char token[MAX_LENGTH]; - ENTRY item, *found_item; -/* - * Search list - */ - strcpy(token, name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); - - if (found_item != NULL) { - isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); - return (isotope_alpha_ptr); - } - return(NULL); -} diff --git a/kinetics.cpp b/kinetics.cpp deleted file mode 100644 index 0f5c751a..00000000 --- a/kinetics.cpp +++ /dev/null @@ -1,2288 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -#include "sundialstypes.h" /* definitions of types realtype and */ - /* integertype, and the constant FALSE */ -#include "cvode.h" /* prototypes for CVodeMalloc, CVode, and */ - /* CVodeFree, constants OPT_SIZE, BDF, NEWTON, */ - /* SV, SUCCESS, NST,NFE,NSETUPS, NNI, NCFN, NETF */ -#include "cvdense.h" /* prototype for CVDense, constant DENSE_NJE */ -#include "nvector_serial.h" /* definitions of type N_Vector and macro */ - /* NV_Ith_S, prototypes for N_VNew, N_VFree */ -#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM*/ -#define KINETICS_EXTERNAL extern -#include "kinetics.h" -/* These macros are defined in order to write code which exactly matches - the mathematical problem description given above. - - Ith(v,i) references the ith component of the vector v, where i is in - the range [1..NEQ] and NEQ is defined below. The Ith macro is defined - using the N_VIth macro in nvector.h. N_VIth numbers the components of - a vector starting from 0. - - IJth(A,i,j) references the (i,j)th element of the dense matrix A, where - i and j are in the range [1..NEQ]. The IJth macro is defined using the - DENSE_ELEM macro in dense.h. DENSE_ELEM numbers rows and columns of a - dense matrix starting from 0. */ - -#define Ith(v,i) NV_Ith_S(v,i-1) /* Ith numbers components 1..NEQ */ -#define IJth(A,i,j) DENSE_ELEM(A,i-1,j-1) /* IJth numbers rows,cols 1..NEQ */ - -static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); - -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - -static char const svnid[] = "$Id: kinetics.c 738 2006-01-26 17:22:32Z dlpark $"; -static int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); -static int calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step); -static int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction); -static int set_reaction(int i, int use_mix, int use_kinetics); -static int set_transport(int i, int use_mix, int use_kinetics, int nsaver); -static int store_get_equi_reactants(int k, int kin_end); - -#define MAX_DIVIDE 2 -#define KINETICS_TOL 1e-8; - -LDBLE *m_original; -LDBLE *m_temp; - -extern LDBLE min_value; -extern int count_total_steps; - -/* ---------------------------------------------------------------------- */ -int calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components to - * determine rates and - * a list of elements and amounts in - * the reaction. - */ - int i, j, return_value; - LDBLE coef; -/* char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; - */ char command[] = "run"; - struct rate *rate_ptr; -/* LDBLE t1, t2; */ - if (svnid == NULL) fprintf(stderr," "); -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - return_value = OK; - count_elts = 0; - paren_count = 0; - - rate_time = time_step; - -/* t1 = clock(); */ - for (i=0; i < kinetics_ptr->count_comps; i++) { - coef = 0.0; -/* - * Send command to basic interpreter - */ - rate_ptr = rate_search (kinetics_ptr->comps[i].rate_name, &j); - if (rate_ptr == NULL) { - sprintf(error_string,"Rate not found for %s",kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } else { - rate_moles = NAN; - rate_m = kinetics_ptr->comps[i].m; - rate_m0 = kinetics_ptr->comps[i].m0; - rate_p = kinetics_ptr->comps[i].d_params; - count_rate_p = kinetics_ptr->comps[i].count_d_params; - if (rate_ptr->new_def == TRUE) { - if (basic_compile(rates[j].commands, &rates[j].linebase, &rates[j].varbase, &rates[j].loopbase) != 0) { - sprintf (error_string, "Fatal Basic error in rate %s.",kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - - rate_ptr->new_def = FALSE; - } - if (basic_run(command, rates[j].linebase, rates[j].varbase, rates[j].loopbase) != 0) { - sprintf (error_string, "Fatal Basic error in rate %s.",kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - if (rate_moles == NAN) { - sprintf(error_string, "Moles of reaction not SAVE'd for %s.",kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } else { - - coef = rate_moles; - } - } -/* - * Accumulate moles of reaction for component - */ - kinetics_ptr->comps[i].moles += coef; - if (coef == 0.0) continue; - } -/* t2=clock(); - printf("secs in reac %e, t2 %e\n", t2-t1, t1); - */ - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components to - * using extrapolated values, which were - * stored in moles in run_kinetics - */ - int i, j, k; - LDBLE coef; - char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; - struct master *master_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - kinetics_ptr->totals = (struct elt_list *) free_check_null(kinetics_ptr->totals); - count_elts = 0; - paren_count = 0; - for (i=0; i < kinetics_ptr->count_comps; i++) { - if (kinetics_ptr->comps[i].moles > m_temp[i]) { - kinetics_ptr->comps[i].moles = m_temp[i]; - kinetics_ptr->comps[i].m = 0; - } - coef = kinetics_ptr->comps[i].moles; - if (coef == 0.0) continue; -/* - * Reactant is a pure phase, copy formula into token - */ - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { - phase_ptr = NULL; - strcpy(token, kinetics_ptr->comps[i].list[j].name); - phase_ptr = phase_bsearch(token, &k, FALSE); - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, coef * kinetics_ptr->comps[i].list[j].coef); - } else { - ptr = kinetics_ptr->comps[i].list[j].name; - get_elts_in_species (&ptr, coef * kinetics_ptr->comps[i].list[j].coef); - } - } -#ifdef SKIP - phase_ptr = NULL; - if (kinetics_ptr->comps[i].count_list == 1) { - strcpy(token, kinetics_ptr->comps[i].list[0].name); - phase_ptr = phase_bsearch(token, &j, FALSE); - } - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, coef * kinetics_ptr->comps[i].list[0].coef); - } else { - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { - ptr = kinetics_ptr->comps[i].list[j].name; - get_elts_in_species (&ptr, coef * kinetics_ptr->comps[i].list[j].coef); - } - } -#endif - if (use.exchange_ptr != NULL && use.exchange_ptr->related_rate == TRUE) { - for (j = 0; j < use.exchange_ptr->count_comps; j++) { - if (use.exchange_ptr->comps[j].rate_name != NULL) { - if (strcmp_nocase(kinetics_ptr->comps[i].rate_name, use.exchange_ptr->comps[j].rate_name) == 0) { - /* found kinetics component */ - add_elt_list(use.exchange_ptr->comps[j].formula_totals, -coef * use.exchange_ptr->comps[j].phase_proportion); - } - } - } - } - if (use.surface_ptr != NULL && use.surface_ptr->related_rate == TRUE) { - for (j = 0; j < use.surface_ptr->count_comps; j++) { - if (use.surface_ptr->comps[j].rate_name != NULL) { - if (strcmp_nocase(kinetics_ptr->comps[i].rate_name, use.surface_ptr->comps[j].rate_name) == 0) { - /* found kinetics component */ - ptr = use.surface_ptr->comps[j].formula; -/* Surface = 0 when m becomes low ... - */ - if (0.9 * use.surface_ptr->comps[j].phase_proportion * (kinetics_ptr->comps[i].m) < MIN_RELATED_SURFACE) { - master_ptr = master_bsearch(ptr); - master_ptr->total = 0.0; - } else { - get_elts_in_species (&ptr, -coef * use.surface_ptr->comps[j].phase_proportion); - } - } - } - } - } - } - kinetics_ptr->totals = elt_list_save(); - /* - output_msg(OUTPUT_MESSAGE, "Calc_final_kinetic_reaction \n"); - elt_list_print(kinetics_ptr->totals); - */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Runge-Kutta-Fehlberg method; 6 evaluations of the derivative - * give O(h^5) global error and error estimate - * calc_kinetic_reaction(.., ..) calculates moles of intermediate derivatives; - * these are calc'd for the whole step h. - * calc_final_kinetic reaction(..) translates moles to PHREEQC reaction. - */ - int j, k, m, save_old; - int bad, step_bad, step_ok; - int n_reactions; - LDBLE h, h_old, h_sum; - LDBLE *rk_moles; - LDBLE error, error_max, safety, moles_max, moles_reduction; - struct kinetics *kinetics_ptr; - int equal_rate, zero_rate; - - struct pp_assemblage *pp_assemblage_save = NULL; - struct s_s_assemblage *s_s_assemblage_save = NULL; - -#ifdef SKIP - struct gas_phase *gas_phase_save = NULL; - struct solution *solution_save = NULL; - struct exchange *exchange_save = NULL; - struct surface *surface_save = NULL; -#endif - - static LDBLE b31 = 3./40., b32 = 9./40., - b51 = -11./54., b53 = -70./27., b54 = 35./27., - b61 = 1631./55296., b62 = 175./512., b63 = 575./13824., b64 = 44275./110592., b65 = 253./4096., - c1 = 37./378., c3 = 250./621., c4 = 125./594., c6 = 512./1771., - dc5 = -277./14336.; - LDBLE dc1 = c1 - 2825./27648., dc3 = c3 - 18575./48384., - dc4 = c4 - 13525./55296., dc6 = c6 - 0.25; -/* - * Save kinetics i and solution i, if necessary - */ - save_old = -2 - (count_cells + 1); - kinetics_duplicate(i, save_old); - if (nsaver != i) { - solution_duplicate(i, save_old); - } - -/* - * Malloc some space - */ - if (kinetics_bsearch(i, &m) == NULL) return(OK); - n_reactions = kinetics[m].count_comps; - rk_moles = (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); - if (rk_moles == NULL) malloc_error(); - - /*if (use_mix != NOMIX) last_model.force_prep = TRUE;*/ - set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); - run_reactions_iterations += iterations; - saver(); - - if (state == TRANSPORT || state == PHAST) { - set_transport(i, NOMIX, TRUE, i); - } else if (state == ADVECTION) { - set_advection(i, NOMIX, TRUE, i); - } else if (state == REACTION) { - set_reaction(i, NOMIX, TRUE); - } - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_save == NULL) malloc_error(); - } - if (use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); - if (s_s_assemblage_save == NULL) malloc_error(); - } - - kinetics_ptr = kinetics_bsearch(i, &m); - - step_bad = step_ok = 0; - bad = FALSE; - h_sum = 0.; - h = h_old = kin_time; - moles_max = 0.1; - moles_reduction = 1.0; - safety = 0.7; - if (kinetics_ptr->rk < 1) { - kinetics_ptr->rk = 1; - } else if (kinetics_ptr->rk > 3 && kinetics_ptr->rk < 6) { - kinetics_ptr->rk = 6; - } else if (kinetics_ptr->rk > 6) { - kinetics_ptr->rk = 6; - } - if (kinetics_ptr->rk == 6) equal_rate = FALSE; else equal_rate = TRUE; -/* - * if step_divide > 1, initial timestep is divided - * if < 1, step_divide indicates maximal reaction... - */ - if (kinetics_ptr->step_divide > 1.0) { - h = h_old = kin_time / kinetics_ptr->step_divide; - equal_rate = FALSE; - } else if (kinetics_ptr->step_divide < 1.0) { - moles_max = kinetics_ptr->step_divide; - } - - rate_sim_time = rate_sim_time_start + h_sum; - - status(0, NULL); - while (h_sum < kin_time) { - - if (step_bad > kinetics_ptr->bad_step_max) { - sprintf(error_string,"Bad RK steps > %d. Please decrease (time)step or increase -bad_step_max.", - kinetics_ptr->bad_step_max); - error_msg(error_string, STOP); - } - - MOLES_TOO_LARGE: - if (moles_reduction > 1.0) { - h_old = h; - h = safety * h / (1.0 + moles_reduction); - moles_reduction = 1.0; - equal_rate = FALSE; - bad = TRUE; - } -/* - * find k1 - */ - if (bad == TRUE) { - for (j=0; j < n_reactions; j++) { - rk_moles[j] *= (h / h_old); - kinetics_ptr->comps[j].moles = rk_moles[j] * 0.2; - kinetics_ptr->comps[j].m = m_temp[j]; - } - bad = FALSE; - } else { -/* - * define pointers for calc_kinetic_, they are lost after saver()... - */ - if (state == TRANSPORT || state == PHAST) { - set_transport(i, NOMIX, TRUE, i); - } else if (state == ADVECTION) { - set_advection(i, NOMIX, TRUE, i); - } else if (state == REACTION) { - set_reaction(i, NOMIX, TRUE); - } - /* - * Moles of minerals and solid solutions may change to make positive - * concentrations. Reactions may take out more than is present in - * solution. - */ - if (pp_assemblage_save != NULL) { - pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); - } - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = 0.; - m_temp[j] = kinetics_ptr->comps[j].m; - } - - rate_sim_time = rate_sim_time_start + h_sum; - calc_kinetic_reaction(kinetics_ptr, h); - - /* store k1 in rk_moles ... */ - for (j=0; j < n_reactions; j++) { - if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { - moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k2 ... */ - rk_moles[j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles *= 0.2; - } - if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; - } -/* - * Quit rk with rk = 1 and equal rates ... - */ - if (kinetics_ptr->rk == 1 && equal_rate) { - zero_rate = TRUE; - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = rk_moles[j]; - if (fabs (kinetics_ptr->comps[j].moles) > MIN_TOTAL) zero_rate = FALSE; - } - - if (zero_rate == FALSE) { - calc_final_kinetic_reaction(kinetics_ptr); - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; - calc_kinetic_reaction(kinetics_ptr, h); - for (j=0; j < n_reactions; j++) { - if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { - equal_rate = FALSE; - break; - } - } - } - if (zero_rate || equal_rate) { - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - } - goto EQUAL_RATE_OUT; - } else { - kinetics_ptr->rk = 3; - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = 0.2 * rk_moles[j]; - } - } - } -/* - * Continue with rk ... - */ - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; - -/* - * find k2 - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.2 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - - /* store k2 in rk_moles */ - k = n_reactions; - for (j=0; j < n_reactions; j++) { - if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { - moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k3 */ - rk_moles[k+j] = kinetics_ptr->comps[j].moles; - - kinetics_ptr->comps[j].moles = b31 * rk_moles[j] - + b32 * rk_moles[k+j]; -/* - * check for equal_rate ... - */ - if (equal_rate && fabs( rk_moles[j] - rk_moles[k + j]) > kinetics_ptr->comps[j].tol) { - equal_rate = FALSE; - } - } - if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; -/* - * Quit rk with rk = 2 and equal rates ... - */ - if (kinetics_ptr->rk == 2 && equal_rate) { - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] + 0.7 * rk_moles[k + j]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j=0; j < n_reactions; j++) { - if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { - equal_rate = FALSE; - break; - } - } - if (equal_rate) kinetics_ptr->rk = 1; - - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - } - goto EQUAL_RATE_OUT; - } -/* - * Continue runge_kutta.. - */ - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k3 - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.3 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - - /* store k3 in rk_moles */ - k = 2 * n_reactions; - for (j=0; j < n_reactions; j++) { - if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { - moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k4 ... */ - rk_moles[k+j] = kinetics_ptr->comps[j].moles; - - kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] - - 0.9 * rk_moles[ n_reactions + j ] - + 1.2 * rk_moles[k+j]; -/* - * check for equal_rate ... - */ - if (equal_rate && fabs ( rk_moles[j] - rk_moles[k+j]) > kinetics_ptr->comps[j].tol) - equal_rate = FALSE; - } - if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; -/* - * Quit rk with rk = 3 and equal rates ... - */ - if (kinetics_ptr->rk == 3 && equal_rate) { - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = 0.5 * rk_moles[j] - - 1.5 * rk_moles[n_reactions + j] - + 2 * rk_moles[k + j]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j=0; j < n_reactions; j++) { - if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { - equal_rate = FALSE; - break; - } - } - if (equal_rate) kinetics_ptr->rk = 1; - - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - } - goto EQUAL_RATE_OUT; - } -/* - * Continue runge_kutta.. - */ - - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k4 - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.6 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - - /* store k4 in rk_moles */ - k = 3 * n_reactions; - for (j=0; j < n_reactions; j++) { - if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { - moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - - /* define reaction for calculating k5 */ - rk_moles[k+j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = b51 * rk_moles[j] - + 2.5 * rk_moles[ n_reactions + j ] - + b53 * rk_moles[ 2*n_reactions + j ] - + b54 * rk_moles[ k + j ]; - } - if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k5 - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - - /* store k5 in rk_moles */ - k = 4 * n_reactions; - for (j=0; j < n_reactions; j++) { - if (moles_reduction * moles_max < fabs(kinetics_ptr->comps[j].moles)) { - moles_reduction = fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - - /* define reaction for calculating k6 */ - rk_moles[k+j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = b61 * rk_moles[j] - + b62 * rk_moles[ n_reactions + j ] - + b63 * rk_moles[ 2*n_reactions + j ] - + b64 * rk_moles[ 3*n_reactions + j ] - + b65 * rk_moles[ k + j ]; - } - if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k6 - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.875 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - - /* store k6 in rk_moles */ - k = 5 * n_reactions; - for (j=0; j < n_reactions; j++) { - rk_moles[k+j] = kinetics_ptr->comps[j].moles; - } - -/* - * Evaluate error - */ - error_max = 0.; - for (j=0; j < n_reactions; j++) { - error = fabs ( dc1 * rk_moles[j] - + dc3 * rk_moles[ 2*n_reactions + j ] - + dc4 * rk_moles[ 3*n_reactions + j ] - + dc5 * rk_moles[ 4*n_reactions + j ] - + dc6 * rk_moles[ 5*n_reactions + j ] ); - - /* tol is in moles/l */ - error /= kinetics_ptr->comps[j].tol; - if (error > error_max) error_max = error; - } - -/* - * repeat with smaller step - */ -/* printf("timest %g ; error_max %g\n", h, error_max); */ - if (error_max > 1) { - h_old = h; - if (step_ok == 0) - h = h * safety / error_max; - else h = h * safety * pow(error_max, -0.25); - bad = TRUE; - step_bad ++; - } else { -/* - * OK, calculate result - */ - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = c1 * rk_moles[j] - + c3 * rk_moles[ 2*n_reactions + j ] - + c4 * rk_moles[ 3*n_reactions + j ] - + c6 * rk_moles[ 5*n_reactions + j ]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j=0; j < n_reactions; j++) { - kinetics_ptr->comps[j].m = m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j=0; j < n_reactions; j++) { - if (fabs( rk_moles[j] - kinetics_ptr->comps[j].moles) > kinetics_ptr->comps[j].tol) { - equal_rate = FALSE; - break; - } - } - if (equal_rate && kinetics_ptr->rk < 6) kinetics_ptr->rk = 1; - - saver(); - - step_ok ++; - h_sum += h; - /* Free space */ - - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - } -/* - * and increase step size ... - */ - if (h_sum < kin_time) { - if (error_max > 0.000577) { - h = h * safety * pow(error_max, -0.2); - } else { - h *= 4; - } - if (h > (kin_time - h_sum)) h = (kin_time - h_sum); - } - } -#if !defined(PHREEQCI_GUI) -#ifndef PHREEQ98 - if (pr.status == TRUE && status_on == TRUE) { - char str[MAX_LENGTH]; - backspace_screen(37); - sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, step_ok, (int) (100*h_sum/kin_time)); - output_msg(OUTPUT_SCREEN, "%-37s", str); - } -#endif -#endif - } - - EQUAL_RATE_OUT: - -/* - * Run one more time to get distribution of species - */ - if (state >= REACTION || nsaver != i) { - set_and_run_wrapper(i, NOMIX, FALSE, nsaver, 0.); - run_reactions_iterations += iterations; - } - /* reset for printing */ - if (use_mix == DISP) { - use.mix_ptr = &mix[count_mix - count_cells + i - 1]; - use.mix_in = TRUE; - use.n_mix_user = i; - } else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) { - use.mix_ptr = mix_search (i, &use.n_mix, FALSE); - if (use.mix_ptr != NULL) { - use.mix_in = TRUE; - use.n_mix_user = i; - } - } -/* - * Restore solution i, if necessary - */ - if (nsaver != i) { - solution_duplicate(save_old, i); - } - rk_moles = (LDBLE *) free_check_null(rk_moles); - -#ifdef SKIP - if (state != TRANSPORT) { -#ifdef DOS - output_msg(OUTPUT_SCREEN, "\n"); -#else - output_msg(OUTPUT_SCREEN, "\n%-80s", " "); -#endif - } -#endif - rate_sim_time = rate_sim_time_start + kin_time; - use.kinetics_in = TRUE; - - /* Free space */ - - if (pp_assemblage_save != NULL) { - pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ - int j, converge, max_try; - int old_diag, old_itmax; - LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; - LDBLE small_pe_step, small_step; - struct pp_assemblage *pp_assemblage_save = NULL; - struct s_s_assemblage *s_s_assemblage_save = NULL; - struct kinetics *kinetics_save = NULL; - - /* 0 -- normal */ - /* 1 -- try smaller step size, more iterations */ - /* 2 -- try diagonal scaling */ - /* 3 -- try smaller tolerance */ - /* 4 -- try alternate scaling */ - small_pe_step = 5.; - small_step = 10.; - converge = FALSE; - - old_diag = diagonal_scale; - old_itmax = itmax; - old_tol = ineq_tol; - old_step = step_size; - old_pe = pe_step_size; - old_min_value = min_value; - old_pp_column_scale = pp_column_scale; - - if (state == TRANSPORT || state == PHAST) { - set_transport(i, use_mix, use_kinetics, i); - } else if (state == ADVECTION) { - set_advection(i, use_mix, use_kinetics, i); - } else if (state == REACTION) { - set_reaction(i, use_mix, use_kinetics); - } - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_save == NULL) malloc_error(); - pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); - } - if (use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); - if (s_s_assemblage_save == NULL) malloc_error(); - s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); - } - if (use.kinetics_ptr != NULL) { - kinetics_save = (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); - if (kinetics_save == NULL) malloc_error(); - kinetics_copy(use.kinetics_ptr, kinetics_save, use.kinetics_ptr->n_user); - } - - if (pitzer_model == TRUE) { - diagonal_scale = TRUE; - always_full_pitzer = FALSE; - max_try = 2; - } else { - max_try = 11; - } - for (j = 0; j < max_try; j++) { - if (j == 1) { - always_full_pitzer = TRUE; - if (pe_step_size <= small_pe_step && step_size <= small_step) continue; - itmax *= 2; - step_size = small_step; - pe_step_size = small_pe_step; - sprintf(error_string, "Trying smaller step size, pe step size %g, %g ... \n", (double) step_size, (double) pe_step_size); - warning_msg(error_string); - } else if (j == 2) { - itmax *= 2; - if (diagonal_scale == TRUE) { - diagonal_scale = FALSE; - } else { - diagonal_scale = TRUE; - } - sprintf(error_string, "Trying diagonal scaling ...\n"); - warning_msg(error_string); - } else if (j == 3) { - itmax *= 2; - ineq_tol /= 10.; - sprintf(error_string, "Trying reduced tolerance %g ...\n", (double) ineq_tol); - warning_msg(error_string); - } else if (j == 4) { - itmax *= 2; - ineq_tol *= 10.; - sprintf(error_string, "Trying increased tolerance %g ...\n", (double) ineq_tol); - warning_msg(error_string); - } else if (j == 5) { - itmax *= 2; - if (diagonal_scale == TRUE) { - diagonal_scale = FALSE; - } else { - diagonal_scale = TRUE; - } - ineq_tol /= 10.; - sprintf(error_string, "Trying diagonal scaling and reduced tolerance %g ...\n", (double) ineq_tol); - warning_msg(error_string); - } else if (j == 6) { - itmax *= 2; - pp_column_scale = 1e-10; - sprintf(error_string, "Trying scaling pure_phase columns %g ...\n", (double) pp_column_scale); - warning_msg(error_string); - } else if (j == 7) { - itmax *= 2; - pp_column_scale = 1e-10; - if (diagonal_scale == TRUE) { - diagonal_scale = FALSE; - } else { - diagonal_scale = TRUE; - } - sprintf(error_string, "Trying scaling pure_phase columns and diagonal scale %g ...\n", (double) pp_column_scale); - warning_msg(error_string); - } else if (j == 8) { - itmax *= 2; - min_value *= 10; - sprintf(error_string, "Trying increased scaling %g ...\n", (double) min_value); - warning_msg(error_string); - } else if (j == 9) { - aqueous_only = 5; - sprintf(error_string, "Skipping optimize equations for first %d iterations ...\n", aqueous_only); - warning_msg(error_string); - } else if (j == 10) { - negative_concentrations = TRUE; - sprintf(error_string, "Adding inequality to make concentrations greater than zero.\n"); - warning_msg(error_string); - } - if (j > 0) { - if (pp_assemblage_save != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, pp_assemblage_save->n_user); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, s_s_assemblage_save->n_user); - } - if (kinetics_save != NULL) { - kinetics_free(use.kinetics_ptr); - kinetics_copy(kinetics_save, use.kinetics_ptr, kinetics_save->n_user); - } - } - - converge = set_and_run(i, use_mix, use_kinetics, nsaver, step_fraction); - /* reset values */ - diagonal_scale = old_diag; - itmax = old_itmax; - ineq_tol = old_tol; - step_size = old_step; - pe_step_size = old_pe; - min_value = old_min_value; - pp_column_scale = old_pp_column_scale; - aqueous_only = 0; - negative_concentrations = FALSE; - if (converge == TRUE) { - break; - } else if (converge == MASS_BALANCE) { - break; - } - warning_msg("Numerical method failed with this set of convergence parameters.\n"); - } - if (converge == FALSE && use.kinetics_ptr != NULL && use.kinetics_ptr->use_cvode == TRUE) { - sprintf(error_string, "Numerical method failed on all parameter combinations, retrying integration"); - /*output_msg(OUTPUT_MESSAGE, "Numerical method failed on all parameter combinations, retrying integration\n"); */ - warning_msg(error_string); - converge = MASS_BALANCE; - } - if (converge == FALSE) { -/* - * write to error.inp what failed to converge. - */ - if( output_open(OUTPUT_DUMP, "error.inp") != OK) { - sprintf(error_string, "Can't open file, %s.", "error.inp"); - error_msg(error_string, CONTINUE); - input_error++; - } else { - if (use.irrev_in == TRUE) { - dump_reaction(use.n_mix_user); - } - if (use.kinetics_ptr != NULL) { - dump_kinetics(use.kinetics_ptr->n_user); - } - output_msg(OUTPUT_DUMP, "END\n"); - if (use.solution_ptr != NULL) { - dump_solution(use.n_solution_user); - } else if (use.mix_ptr != NULL) { - dump_mix(use.n_mix_user); - } - if (use.pp_assemblage_in == TRUE) { - dump_pp_assemblage(use.n_pp_assemblage_user); - } - if (use.exchange_in == TRUE) { - dump_exchange(use.n_exchange_user); - } - if (use.surface_in == TRUE) { - dump_surface(use.n_surface_user); - } - if (use.gas_phase_in == TRUE) { - dump_gas_phase(use.n_gas_phase_user); - } - if (use.s_s_assemblage_in == TRUE) { - dump_s_s_assemblage(use.n_s_s_assemblage_user); - } - output_msg(OUTPUT_DUMP, "END\n"); - } - /* if (state == TRANSPORT && dump_modulus == 0) dump(); */ - check_residuals(); - pr.all = TRUE; - pr.gas_phase = use.gas_phase_in; - pr.pp_assemblage = use.pp_assemblage_in; - pr.s_s_assemblage = use.s_s_assemblage_in; - pr.surface = use.surface_in; - pr.exchange = use.exchange_in; - pr.totals = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = use.irrev_in; - pr.mix = use.mix_in; - pr.reaction = TRUE; - pr.use = TRUE; - sum_species(); - print_all(); - sprintf(error_string, "Numerical method failed on all combinations of convergence parameters"); - error_msg(error_string, STOP); - } - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); - } - if (kinetics_save != NULL) { - kinetics_free(kinetics_save); - kinetics_save = (struct kinetics *) free_check_null(kinetics_save); - } - if (converge == MASS_BALANCE) { - return(MASS_BALANCE); - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * i --user number for soln, reaction, etc. - * use_mix --integer flag - state == TRANSPORT: DISP, STAG, NOMIX - state == REACTION: TRUE, FALSE - * use_kinetics --true or false flag to calculate kinetic reactions - * nsaver --user number to store solution - * step_fraction--fraction of irreversible reaction to add - */ - int n, n1, n2, converge; - if (state == TRANSPORT || state == PHAST) { - set_transport(i, use_mix, use_kinetics, nsaver); - } else if (state == ADVECTION) { - set_advection(i, use_mix, use_kinetics, nsaver); - } else if (state == REACTION) { - set_reaction(i, use_mix, use_kinetics); - } - cell = i; -/* - * Take step - */ - if (state >= REACTION) { - if (step(step_fraction) == MASS_BALANCE) { - return(MASS_BALANCE); - } -/* - * Always use solution, exchange, and surface -1 - */ - use.solution_ptr = solution_bsearch(-1, &n, TRUE); - - /* new */ - if (use.exchange_ptr != NULL) { - use.exchange_ptr = exchange_bsearch(-1, &n1); - } - if (use.surface_ptr != NULL) { - use.surface_ptr = surface_bsearch(-1, &n2); - } - } - /* end new */ -#ifdef SKIP -/* a quick one ...*/ - if (state == TRANSPORT /*&& ishift == 0*/ && - (cell == 1 || cell == count_cells)) last_model.force_prep = TRUE; -#endif - if (use.surface_ptr != NULL ) { - diffuse_layer_x = use.surface_ptr->diffuse_layer; - } - if (use.surface_ptr != NULL && diffuse_layer_x == TRUE) { - converge = surface_model(); - } else { - prep(); -#ifdef SKIP - k_temp(solution[n]->tc); -#endif - k_temp(use.solution_ptr->tc); - set(FALSE); - converge = model(); - } - sum_species(); - return(converge); -} -/* ---------------------------------------------------------------------- */ -int set_transport(int i, int use_mix, int use_kinetics, int nsaver) -/* ---------------------------------------------------------------------- */ -{ -/* - * i --user number for soln, reaction, etc. - * use_mix --integer flag - state == TRANSPORT: DISP, STAG, NOMIX - state == REACTION: TRUE, FALSE - * use_kinetics --true or false flag to calculate kinetic reactions - * nsaver --user number to store solution - */ - int n; - - cell = i; - reaction_step = 1; -#ifdef SKIP - if (pr.use == TRUE && pr.all == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nCell %d\n", i); - } -#endif -/* - * Find mixture or solution - */ - - use.mix_ptr = NULL; - use.mix_in = FALSE; - if (use_mix == DISP) { - use.mix_ptr = &mix[count_mix - count_cells + i - 1]; - use.mix_in = TRUE; - use.n_mix_user = i; - use.n_mix_user_orig = i; - } else if (use_mix == STAG) { - use.mix_ptr = mix_search (i, &use.n_mix, FALSE); - if (use.mix_ptr != NULL) { - use.mix_in = TRUE; - use.n_mix_user = i; - use.n_mix_user_orig = i; - } else { - use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); - if (use.solution_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", use.n_solution_user); - error_msg(error_string, STOP); - } - use.n_solution_user = i; - use.solution_in = TRUE; - } - } else { - use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); - if (use.solution_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", use.n_solution_user); - error_msg(error_string, STOP); - } - use.n_solution_user = i; - use.solution_in = TRUE; - } - save.solution = TRUE; - save.n_solution_user = nsaver; - save.n_solution_user_end = nsaver; -/* - * Find pure phase assemblage - */ - - use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); - if (use.pp_assemblage_ptr != NULL) { - use.pp_assemblage_in = TRUE; - use.n_pp_assemblage_user = i; - save.pp_assemblage = TRUE; - save.n_pp_assemblage_user = i; - save.n_pp_assemblage_user_end = i; - } else { - use.pp_assemblage_in = FALSE; - save.pp_assemblage = FALSE; - } -/* - * Find irreversible reaction - */ - use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); - if (use.irrev_ptr != NULL) { - use.irrev_in = TRUE; - use.n_irrev_user = i; - } else { - use.irrev_in = FALSE; - } -/* - * Find exchange - */ - use.exchange_ptr = exchange_bsearch(i, &use.n_exchange); - if (use.exchange_ptr != NULL) { - use.exchange_in = TRUE; - use.n_exchange_user = i; - save.exchange = TRUE; - save.n_exchange_user = i; - save.n_exchange_user_end = i; - } else { - use.exchange_in = FALSE; - save.exchange = FALSE; - } - -/* - * Find surface - */ - use.surface_ptr = surface_bsearch(i, &use.n_surface); - if (use.surface_ptr != NULL) { - use.surface_in = TRUE; - use.n_surface_user = i; - save.surface = TRUE; - save.n_surface_user = i; - save.n_surface_user_end = i; - } else { - use.surface_in = FALSE; - save.surface = FALSE; - } -/* - * Find temperature; temp retardation is done in step - */ - use.temperature_ptr = temperature_bsearch(i, &use.n_temperature); - if (use.temperature_ptr != NULL) { - use.temperature_in = TRUE; - use.n_temperature_user = i; - } else { - use.temperature_in = FALSE; - } -/* - * Find gas - */ - use.gas_phase_ptr = gas_phase_bsearch(i, &use.n_gas_phase); - if (use.gas_phase_ptr != NULL) { - use.gas_phase_in = TRUE; - use.n_gas_phase_user = i; - save.gas_phase = TRUE; - save.n_gas_phase_user = i; - save.n_gas_phase_user_end = i; - } else { - use.gas_phase_in = FALSE; - save.gas_phase = FALSE; - } -/* - * Find s_s_assemblage - */ - use.s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &use.n_s_s_assemblage); - if (use.s_s_assemblage_ptr != NULL) { - use.s_s_assemblage_in = TRUE; - use.n_s_s_assemblage_user = i; - save.s_s_assemblage = TRUE; - save.n_s_s_assemblage_user = i; - save.n_s_s_assemblage_user_end = i; - } else { - use.s_s_assemblage_in = FALSE; - save.s_s_assemblage = FALSE; - } -/* - * Find kinetics - */ - if (use_kinetics == TRUE && (use.kinetics_ptr = kinetics_bsearch(i, &n)) != NULL) { - use.n_kinetics_user = i; - use.n_kinetics = n; - use.kinetics_in = TRUE; - save.kinetics = TRUE; - save.n_kinetics_user = i; - save.n_kinetics_user_end = i; - } else { - use.kinetics_ptr = NULL; - use.kinetics_in = FALSE; - save.kinetics = FALSE; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_reaction(int i, int use_mix, int use_kinetics) -/* ---------------------------------------------------------------------- */ -{ -/* - * i --user number for soln, reaction, etc. - * use_mix --integer flag - state == TRANSPORT: DISP, STAG, NOMIX - state == REACTION: TRUE, FALSE - * use_kinetics --true or false flag to calculate kinetic reactions - */ -/* - * Find mixture or solution - */ - use.mix_ptr = NULL; - use.solution_ptr = NULL; - if (use_mix == TRUE && use.mix_in == TRUE) { - use.mix_ptr = mix_bsearch (i, &use.n_mix); - if (use.mix_ptr == NULL) { - sprintf(error_string, "MIX %d not found.", i); - error_msg(error_string, STOP); - } - } else { - use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); - if (use.solution_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find pure phase assemblage - */ - if (use.pp_assemblage_in == TRUE) { - use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); - if (use.pp_assemblage_ptr == NULL) { - sprintf(error_string, "PP_ASSEMBLAGE %d not found.", i); - error_msg(error_string, STOP); - } - } - -/* - * Find irreversible reaction - */ - if (use.irrev_in == TRUE) { - use.irrev_ptr = irrev_bsearch (i, &use.n_irrev); - if (use.irrev_ptr == NULL) { - sprintf(error_string, "REACTION %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find exchange - */ - if (use.exchange_in == TRUE) { - use.exchange_ptr = exchange_bsearch (i, &use.n_exchange); - if (use.exchange_ptr == NULL) { - sprintf(error_string, "EXCHANGE %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find surface - */ - if (use.surface_in == TRUE) { - use.surface_ptr = surface_bsearch (i, &use.n_surface); - if (use.surface_ptr == NULL) { - sprintf(error_string, "SURFACE %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find temperature; temp retardation is done in step - */ - if (use.temperature_in == TRUE) { - use.temperature_ptr = temperature_bsearch (i, &use.n_temperature); - if (use.temperature_ptr == NULL) { - sprintf(error_string, "TEMPERATURE %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find gas - */ - if (use.gas_phase_in == TRUE) { - use.gas_phase_ptr = gas_phase_bsearch (i, &use.n_gas_phase); - if (use.gas_phase_ptr == NULL) { - sprintf(error_string, "GAS_PHASE %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find s_s_assemblage - */ - if (use.s_s_assemblage_in == TRUE) { - use.s_s_assemblage_ptr = s_s_assemblage_bsearch (i, &use.n_s_s_assemblage); - if (use.s_s_assemblage_ptr == NULL) { - sprintf(error_string, "Solid-solution Assemblage %d not found.", i); - error_msg(error_string, STOP); - } - } -/* - * Find kinetics - */ - if (use_kinetics == TRUE && use.kinetics_in == TRUE) { - use.kinetics_ptr = kinetics_bsearch (i, &use.n_kinetics); - if (use.kinetics_ptr == NULL) { - sprintf(error_string, "KINETICS %d not found.", i); - error_msg(error_string, STOP); - } - } else { - use.kinetics_ptr = NULL; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Kinetics calculations - * Rates and moles of each reaction are calculated in calc_kinetic_reaction - * Total number of moles in reaction is stored in kinetics[i].totals - */ - - int j, n, converge, iter; - int pr_all_save; - int nsaver; - struct kinetics *kinetics_ptr; - struct pp_assemblage *pp_assemblage_ptr; - struct s_s_assemblage *s_s_assemblage_ptr; - - int save_old, m, n_reactions /*, nok, nbad */; - - /* CVODE definitions */ - realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; - long int iopt[OPT_SIZE]; - int flag; -/* - * Set nsaver - */ - run_reactions_iterations = 0; - kin_time_x = kin_time; - nsaver = i; - if (state == TRANSPORT || state == PHAST) { - if (use_mix == DISP) { - nsaver = -2; - } else if (use_mix == STAG) { - nsaver = -2-i; - } - } if (state == ADVECTION) { - nsaver = -2; - } -/* - * Check that reaction exists for this cell .. - */ - if (kin_time <= 0 || - (state == REACTION && use.kinetics_in == FALSE) || - (state == TRANSPORT && kinetics_bsearch(i, &n) == NULL) || - (state == PHAST && kinetics_bsearch(i, &n) == NULL) || - (state == ADVECTION && kinetics_bsearch(i, &n) == NULL)) { - converge = set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); - if (converge == MASS_BALANCE) error_msg("Negative concentration in system. Stopping calculation.",STOP); - run_reactions_iterations += iterations; - } else { -/* - * Save moles of kinetic reactants for printout... - */ - kinetics_ptr = kinetics_bsearch(i, &n); - - m_temp = (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * sizeof(LDBLE)); - if (m_temp == NULL) malloc_error(); - - m_original = (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * sizeof(LDBLE)); - if (m_original == NULL) malloc_error(); - - for (j = 0; j < kinetics_ptr->count_comps; j++) { - m_original[j] = kinetics_ptr->comps[j].m; - m_temp[j] = kinetics_ptr->comps[j].m; - } -/* - * Start the loop for timestepping ... - * Use either Runge-Kutta-Fehlberg, or final result extrapolation - */ - pr_all_save = pr.all; - pr.all = FALSE; -/* - * This condition makes output equal for incremental_reactions TRUE/FALSE... - * (if (incremental_reactions == FALSE || reaction_step == 1) - */ - store_get_equi_reactants(i, FALSE); - if (kinetics_ptr->use_cvode == FALSE) { - rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); - } else { - save_old = -2 - (count_cells + 1); - if (nsaver != i) { - solution_duplicate(i, save_old); - } - for (j = 0; j < OPT_SIZE; j++) { - iopt[j] = 0; - ropt[j] = 0; - } - -/* - * Do mix first - */ - kinetics_ptr = kinetics_bsearch(i, &m); - n_reactions = kinetics_ptr->count_comps; - cvode_n_user = i; - cvode_kinetics_ptr = (void *) kinetics_ptr; - cvode_n_reactions = n_reactions; - cvode_rate_sim_time_start = rate_sim_time_start; - cvode_rate_sim_time = rate_sim_time; - - converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); - if (converge == MASS_BALANCE) error_msg("Negative concentration in system. Stopping calculation.",STOP); - saver(); - pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); - s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &n); - if (pp_assemblage_ptr != NULL) { - cvode_pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); - if (cvode_pp_assemblage_save == NULL) malloc_error(); - pp_assemblage_copy(pp_assemblage_ptr, cvode_pp_assemblage_save, pp_assemblage_ptr->n_user); - } - if (s_s_assemblage_ptr != NULL) { - cvode_s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); - if (cvode_s_s_assemblage_save == NULL) malloc_error(); - s_s_assemblage_copy(s_s_assemblage_ptr, cvode_s_s_assemblage_save, s_s_assemblage_ptr->n_user); - } - - /* allocate space for CVODE */ - kinetics_machEnv = M_EnvInit_Serial(n_reactions); - kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (kinetics_y == NULL) malloc_error(); - cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_last_good_y == NULL) malloc_error(); - cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_prev_good_y == NULL) malloc_error(); - kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); - if (kinetics_abstol == NULL) malloc_error(); - -/* - * Set y to 0.0 - */ - for (j = 0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = 0.0; - Ith(kinetics_y,j+1) = 0.0; - Ith(kinetics_abstol,j+1) = kinetics_ptr->comps[j].tol; - /*Ith(abstol,j+1) = 1e-8; */ - /* m_temp[j] = kinetics_ptr->comps[j].m; */ - } - reltol = 0.0; - - /* Call CVodeMalloc to initialize CVODE: - - NEQ is the problem size = number of equations - f is the user's right hand side function in y'=f(t,y) - T0 is the initial time - y is the initial dependent variable vector - BDF specifies the Backward Differentiation Formula - NEWTON specifies a Newton iteration - SV specifies scalar relative and vector absolute tolerances - &reltol is a pointer to the scalar relative tolerance - abstol is the absolute tolerance vector - FALSE indicates there are no optional inputs in iopt and ropt - iopt is an array used to communicate optional integer input and output - ropt is an array used to communicate optional real input and output - - A pointer to CVODE problem memory is returned and stored in cvode_mem. */ - /* Don't know what this does */ - /* - iopt[SLDET] = TRUE; - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); - */ - kinetics_cvode_mem = CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, &reltol, kinetics_abstol, NULL, NULL, TRUE, iopt, ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - - flag = CVDense(kinetics_cvode_mem, Jac, NULL); - if (flag != SUCCESS) { - error_msg("CVDense failed.", STOP); - } - t = 0; - tout = kin_time; - /*ropt[HMAX] = tout/10.;*/ - /*ropt[HMIN] = 1e-17;*/ - flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); - rate_sim_time = rate_sim_time_start + t; - /* - printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", - t, Ith(y,1), Ith(y,2), Ith(y,3)); - */ - iter = 0; - sum_t = 0; - RESTART: - while (flag != SUCCESS) { - sum_t += cvode_last_good_time; - cvode_last_good_time = 0; - if (++iter >= 200) { - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - error_msg("Repeated restart of integration.", STOP); - } - tout1 = tout - sum_t; - t = 0; - N_VScale(1.0, cvode_last_good_y, kinetics_y); - for (j = 0; j < OPT_SIZE; j++) { - iopt[j] = 0; - ropt[j] = 0; - } - CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ - kinetics_cvode_mem = CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, &reltol, kinetics_abstol, NULL, NULL, FALSE, iopt, ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - - flag = CVDense(kinetics_cvode_mem, Jac, NULL); - if (flag != SUCCESS) { - error_msg("CVDense failed.", STOP); - } - flag = CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); - /* - sprintf(error_string, "CVode failed, flag=%d.\n", flag); - error_msg(error_string, STOP); - */ - } - - - /* - odeint(&ystart[-1], n_reactions, 0, kin_time, kinetics_ptr->comps[0].tol, kin_time/kinetics_ptr->step_divide, 0.0, &nok, &nbad, i, nsaver ); - */ - for (j = 0; j < n_reactions; j++) { - kinetics_ptr->comps[j].moles = Ith(kinetics_y,j+1); - kinetics_ptr->comps[j].m = m_original[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 0) { - kinetics_ptr->comps[j].moles = m_original[j]; - kinetics_ptr->comps[j].m = 0.0; - } - /* output_msg(OUTPUT_MESSAGE,"%d y[%d] %g\n", i, j, ystart[j]); */ - } - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, i); - } - if (use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(cvode_s_s_assemblage_save, use.s_s_assemblage_ptr, i); - } - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) { - /*error_msg("FAIL 2 after successful integration in CVode", CONTINUE);*/ - warning_msg("FAIL 2 after successful integration in CVode"); - flag = -1; - goto RESTART; - } - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_ptr->comps[j].m = m_original[j] - kinetics_ptr->comps[j].moles; - } -/* - * Restore solution i, if necessary - */ - if (nsaver != i) { - solution_duplicate(save_old, i); - } - free_cvode(); - } - - store_get_equi_reactants(i, TRUE); - pr.all = pr_all_save; - - kinetics_ptr = kinetics_bsearch(i, &n); - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_ptr->comps[j].moles = m_original[j] - kinetics_ptr->comps[j].m; -/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0; - */ } - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - } - iterations = run_reactions_iterations; - if (cvode_pp_assemblage_save != NULL) { - pp_assemblage_free(cvode_pp_assemblage_save); - cvode_pp_assemblage_save = (struct pp_assemblage *) free_check_null(cvode_pp_assemblage_save); - } - if (cvode_s_s_assemblage_save != NULL) { - s_s_assemblage_free(cvode_s_s_assemblage_save); - cvode_s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(cvode_s_s_assemblage_save); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int free_cvode(void) -/* ---------------------------------------------------------------------- */ -{ - if (kinetics_y != NULL) N_VFree(kinetics_y); /* Free vector */ - kinetics_y = NULL; - if (cvode_last_good_y != NULL) N_VFree(cvode_last_good_y); /* Free vector */ - cvode_last_good_y = NULL; - if (cvode_prev_good_y != NULL) N_VFree(cvode_prev_good_y); /* Free vector */ - cvode_prev_good_y = NULL; - if (kinetics_abstol != NULL) N_VFree(kinetics_abstol); /* Free vector */ - kinetics_abstol = NULL; - if (kinetics_cvode_mem != NULL) CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ - kinetics_cvode_mem = NULL; - if (kinetics_machEnv != NULL) M_EnvFree_Serial(kinetics_machEnv); /* Free the machine environment memory */ - kinetics_machEnv = NULL; - if (cvode_pp_assemblage_save != NULL) { - pp_assemblage_free(cvode_pp_assemblage_save); - cvode_pp_assemblage_save = (struct pp_assemblage *) free_check_null(cvode_pp_assemblage_save); - } - if (cvode_s_s_assemblage_save != NULL) { - s_s_assemblage_free(cvode_s_s_assemblage_save); - cvode_s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(cvode_s_s_assemblage_save); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_advection(int i, int use_mix, int use_kinetics, int nsaver) -/* ---------------------------------------------------------------------- */ -{ -/* - * i --user number for soln, reaction, etc. - * use_mix --integer flag - state == TRANSPORT: DISP, STAG, NOMIX - state == REACTION: TRUE, FALSE - state == ADVECTION: TRUE, FALSE - * use_kinetics --true or false flag to calculate kinetic reactions - * nsaver --user number to store solution - */ - int n; - - cell = i; - reaction_step = 1; -/* - * Find mixture or solution - */ - - use.mix_ptr = NULL; - use.mix_in = FALSE; - if (use_mix == TRUE && - (use.mix_ptr = mix_search (i, &use.n_mix, FALSE)) != NULL) { - use.mix_in = TRUE; - use.n_mix_user = i; - use.n_mix_user_orig = i; - use.n_solution_user = i; - } else { - use.solution_ptr = solution_bsearch (i, &use.n_solution, FALSE); - if (use.solution_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", use.n_solution_user); - error_msg(error_string, STOP); - } - use.n_solution_user = i; - use.solution_in = TRUE; - } - save.solution = TRUE; - save.n_solution_user = nsaver; - save.n_solution_user_end = nsaver; -/* - * Find pure phase assemblage - */ - - use.pp_assemblage_ptr = pp_assemblage_bsearch (i, &use.n_pp_assemblage); - if (use.pp_assemblage_ptr != NULL) { - use.pp_assemblage_in = TRUE; - use.n_pp_assemblage_user = i; - save.pp_assemblage = TRUE; - save.n_pp_assemblage_user = i; - save.n_pp_assemblage_user_end = i; - } else { - use.pp_assemblage_in = FALSE; - save.pp_assemblage = FALSE; - } -/* - * Find irreversible reaction - */ - use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); - if (use.irrev_ptr != NULL) { - use.irrev_in = TRUE; - use.n_irrev_user = i; - } else { - use.irrev_in = FALSE; - } -/* - * Find exchange - */ - use.exchange_ptr = exchange_bsearch(i, &use.n_exchange); - if (use.exchange_ptr != NULL) { - use.exchange_in = TRUE; - use.n_exchange_user = i; - save.exchange = TRUE; - save.n_exchange_user = i; - save.n_exchange_user_end = i; - } else { - use.exchange_in = FALSE; - save.exchange = FALSE; - } - -/* - * Find surface - */ - use.surface_ptr = surface_bsearch(i, &use.n_surface); - if (use.surface_ptr != NULL) { - use.surface_in = TRUE; - use.n_surface_user = i; - save.surface = TRUE; - save.n_surface_user = i; - save.n_surface_user_end = i; - } else { - use.surface_in = FALSE; - save.surface = FALSE; - } -/* - * Find temperature; temp retardation is done in step - */ - use.temperature_ptr = temperature_bsearch(i, &use.n_temperature); - if (use.temperature_ptr != NULL) { - use.temperature_in = TRUE; - use.n_temperature_user = i; - } else { - use.temperature_in = FALSE; - } -/* - * Find gas - */ - use.gas_phase_ptr = gas_phase_bsearch(i, &use.n_gas_phase); - if (use.gas_phase_ptr != NULL) { - use.gas_phase_in = TRUE; - use.n_gas_phase_user = i; - save.gas_phase = TRUE; - save.n_gas_phase_user = i; - save.n_gas_phase_user_end = i; - } else { - use.gas_phase_in = FALSE; - save.gas_phase = FALSE; - } -/* - * Find s_s_assemblage - */ - use.s_s_assemblage_ptr = s_s_assemblage_bsearch(i, &use.n_s_s_assemblage); - if (use.s_s_assemblage_ptr != NULL) { - use.s_s_assemblage_in = TRUE; - use.n_s_s_assemblage_user = i; - save.s_s_assemblage = TRUE; - save.n_s_s_assemblage_user = i; - save.n_s_s_assemblage_user_end = i; - } else { - use.s_s_assemblage_in = FALSE; - save.s_s_assemblage = FALSE; - } -/* - * Find kinetics - */ - if (use_kinetics == TRUE && (use.kinetics_ptr = kinetics_bsearch(i, &n)) != NULL) { - use.n_kinetics_user = i; - use.n_kinetics = n; - use.kinetics_in = TRUE; - save.kinetics = TRUE; - save.n_kinetics_user = i; - save.n_kinetics_user_end = i; - } else { - use.kinetics_ptr = NULL; - use.kinetics_in = FALSE; - save.kinetics = FALSE; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_get_equi_reactants(int l, int kin_end) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - static int count_pp, count_pg, count_s_s; - static LDBLE *x0_moles; - - if (use.pp_assemblage_in == TRUE) { - use.pp_assemblage_ptr = pp_assemblage_bsearch (l, &use.n_pp_assemblage); - } else use.pp_assemblage_ptr = NULL; - if (use.gas_phase_in == TRUE) { - use.gas_phase_ptr = gas_phase_bsearch(l, &use.n_gas_phase); - } else use.gas_phase_ptr = NULL; - if (use.s_s_assemblage_in == TRUE) { - use.s_s_assemblage_ptr = s_s_assemblage_bsearch(l, &use.n_s_s_assemblage); - } else use.s_s_assemblage_ptr = NULL; - - if (kin_end == FALSE) { - count_pp = count_s_s = count_pg = 0; - if (use.pp_assemblage_ptr != NULL) count_pp = use.pp_assemblage_ptr->count_comps; - if (use.gas_phase_ptr != NULL) count_pg = use.gas_phase_ptr->count_comps; - if (use.s_s_assemblage_ptr != NULL) { - for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - count_s_s++; - } - } - } - k = count_pp + count_s_s + count_pg; - x0_moles = NULL; - if (k == 0) return(OK); - x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE)); - if (x0_moles == NULL) malloc_error(); - - k = -1; - for (j = 0; j < count_pp; j++) { - x0_moles[++k] = use.pp_assemblage_ptr->pure_phases[j].moles; - } - for (j = 0; j < count_pg; j++) { - x0_moles[++k] = use.gas_phase_ptr->comps[j].moles; - } - if (count_s_s != 0) { - for(j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - x0_moles[++k] = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - } -/*!!!! also miscibility gap comps ?? - */ - } - } - } else { - k = -1; - for (j = 0; j < count_pp; j++) { - use.pp_assemblage_ptr->pure_phases[j].moles = x0_moles[++k]; - use.pp_assemblage_ptr->pure_phases[j].delta = 0.0; - } - for (j = 0; j < count_pg; j++) { - use.gas_phase_ptr->comps[j].moles = x0_moles[++k]; - } - if (count_s_s != 0) { - for(j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles = x0_moles[++k]; - } -/*!!!! also miscibility gap comps ?? - */ - } - } -/* - * This condition makes output equal for incremental_reactions TRUE/FALSE... - * if (incremental_reactions == FALSE || reaction_step == count_total_steps) - */ - x0_moles = (LDBLE *) free_check_null(x0_moles); - } - return(OK); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -static void derivs (LDBLE x, LDBLE y[], LDBLE dydx[], int n_reactions, int n_user, struct kinetics *kinetics_ptr, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -#endif -static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data) -{ - int i, n_reactions, n_user; - LDBLE step_fraction; - struct kinetics *kinetics_ptr; - - cvode_error = FALSE; - n_reactions = cvode_n_reactions; - n_user = cvode_n_user; - kinetics_ptr = (struct kinetics *) cvode_kinetics_ptr; - step_fraction = cvode_step_fraction; - rate_sim_time = cvode_rate_sim_time; - - for (i = 0; i < n_reactions; i++) { - /* - kinetics_ptr->comps[i].moles = y[i + 1]; - kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; - */ - kinetics_ptr->comps[i].moles = Ith(y,i + 1); - kinetics_ptr->comps[i].m = m_original[i] - Ith(y,i + 1); - if (kinetics_ptr->comps[i].m < 0) { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - calc_final_kinetic_reaction(kinetics_ptr); - /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); - } - if (use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(cvode_s_s_assemblage_save, use.s_s_assemblage_ptr, n_user); - } - - if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) { - run_reactions_iterations += iterations; - cvode_error = TRUE; - /* - error_msg("Mass balance error in f", CONTINUE); - */ - return; - } - if (cvode_test == TRUE) { - return; - } - run_reactions_iterations += iterations; - for (i = 0; i < n_reactions; i++) { - kinetics_ptr->comps[i].moles = 0.0; - } - calc_kinetic_reaction(kinetics_ptr, 1.0); - for (i = 0; i < n_reactions; i++) { - /* - dydx[i + 1] = kinetics_ptr->comps[i].moles; - */ - Ith(ydot,i + 1) = kinetics_ptr->comps[i].moles; - } - return; -} - -/* -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); -*/ -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -void jacobn (LDBLE x, LDBLE y[], LDBLE dfdx[], LDBLE **dfdy, int n_reactions, int n_user, struct kinetics *kinetics_ptr, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -#endif -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) -{ - int count_cvode_errors; - int i, j, n_reactions, n_user; - LDBLE *initial_rates, del; - struct kinetics *kinetics_ptr; - LDBLE step_fraction; - - cvode_error = FALSE; - n_reactions = cvode_n_reactions; - n_user = cvode_n_user; - kinetics_ptr = (struct kinetics *) cvode_kinetics_ptr; - step_fraction = cvode_step_fraction; - rate_sim_time = cvode_rate_sim_time; - - initial_rates = (LDBLE *) PHRQ_malloc((size_t) n_reactions * sizeof(LDBLE)); - if (initial_rates == NULL) malloc_error(); - - for (i = 0; i < n_reactions; i++) { - /* - kinetics_ptr->comps[i].moles = y[i + 1]; - kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; - */ - kinetics_ptr->comps[i].moles = Ith(y, i + 1); - kinetics_ptr->comps[i].m = m_original[i] - Ith(y, i + 1); - if (kinetics_ptr->comps[i].m < 0) { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - calc_final_kinetic_reaction(kinetics_ptr); - /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) {*/ - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); - } - if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) { - run_reactions_iterations += iterations; - cvode_error = TRUE; - /* - error_msg("Mass balance error in jacobian", CONTINUE); - */ - initial_rates = (LDBLE *) free_check_null(initial_rates); - return; - } - run_reactions_iterations += iterations; - for (i = 0; i < n_reactions; i++) kinetics_ptr->comps[i].moles = 0.0; - calc_kinetic_reaction(kinetics_ptr, 1.0); - for (i = 0; i < n_reactions; i++) { - initial_rates[i] = kinetics_ptr->comps[i].moles; - } - for (i = 0; i < n_reactions; i++) { - /* calculate reaction up to current time */ - del = 1e-12; - cvode_error = TRUE; - count_cvode_errors = 0; - while (cvode_error == TRUE) { - del /= 10.; - for (j = 0; j < n_reactions; j++) { - /* - kinetics_ptr->comps[j].moles = y[j + 1]; - kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; - */ - kinetics_ptr->comps[j].moles = Ith(y, j+1); - kinetics_ptr->comps[j].m = m_original[j] - Ith(y,j + 1); - if (kinetics_ptr->comps[i].m < 0) { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - - /* Add small amount of ith reaction */ - kinetics_ptr->comps[i].m -= del; - if (kinetics_ptr->comps[i].m < 0) { - kinetics_ptr->comps[i].m = 0; - } - kinetics_ptr->comps[i].moles += del; - calc_final_kinetic_reaction(kinetics_ptr); - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(cvode_pp_assemblage_save, use.pp_assemblage_ptr, n_user); - } -#ifdef SKIP - if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { - run_reactions_iterations += iterations; - /* - error_msg("Mass balance error in jacobian 2", CONTINUE); - */ - cvode_error = TRUE; - initial_rates = (LDBLE *) free_check_null(initial_rates); - return; - } -#endif - if (set_and_run_wrapper(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { - count_cvode_errors++; - cvode_error = TRUE; - if (count_cvode_errors > 30) { - initial_rates = (LDBLE *) free_check_null(initial_rates); - return; - } - run_reactions_iterations += iterations; - continue; - } - cvode_error = FALSE; - run_reactions_iterations += iterations; - /*kinetics_ptr->comps[i].moles -= del;*/ - for (j = 0; j < n_reactions; j++) kinetics_ptr->comps[j].moles = 0.0; - calc_kinetic_reaction(kinetics_ptr, 1.0); - - /* calculate new rates for df/dy[i] */ - /* dfdx[i + 1] = 0.0; */ - for (j = 0; j < n_reactions; j++) { - IJth(J,j+1,i+1) = (kinetics_ptr->comps[j].moles - initial_rates[j])/del; - } - } - } - for (i = 0; i < n_reactions; i++) { - kinetics_ptr->comps[i].moles = 0; - } - initial_rates = (LDBLE *) free_check_null(initial_rates); - return; -} - -void cvode_init(void) -{ - cvode_kinetics_ptr = NULL; - cvode_test = 0; - cvode_error = 0; - cvode_n_user = -99; - cvode_n_reactions = -99; - cvode_step_fraction = 0.0; - cvode_rate_sim_time = 0.0; - cvode_rate_sim_time_start = 0.0; - cvode_last_good_time = 0.0; - cvode_prev_good_time = 0.0; - cvode_last_good_y = NULL; - cvode_prev_good_y = NULL; - kinetics_machEnv = NULL; - kinetics_y = kinetics_abstol = NULL; - kinetics_cvode_mem = NULL; - cvode_pp_assemblage_save = NULL; - cvode_s_s_assemblage_save = NULL; - return; -} diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 073e5d25..00000000 --- a/main.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#define EXTERNAL -#include "global.h" -#include "output.h" -#include "phrqproto.h" -#include "input.h" - -/*#define PHREEQC_XML*/ -#ifdef PHREEQC_XML -#include "SAXPhreeqc.h" -extern void SAX_cleanup(void); -#endif - -static char const svnid[] = "$Id: main.c 715 2006-01-18 01:26:29Z dlpark $"; - -#ifdef DOS -static int write_banner(void); -#endif - -/* ---------------------------------------------------------------------- - * MAIN - * ---------------------------------------------------------------------- */ -int main(int argc, char *argv[]) -/* - * Main program for PHREEQC - */ -{ - int errors; - void *db_cookie = NULL; - void *input_cookie = NULL; - if (svnid == NULL) fprintf(stderr," "); - phast = FALSE; -/* - * Add callbacks for error_msg and warning_msg - */ - if (add_output_callback(phreeqc_handler, NULL) != OK) { - fprintf(stderr, "ERROR: %s\n", "NULL pointer returned from malloc or realloc."); - fprintf(stderr, "ERROR: %s\n", "Program terminating."); - return -1; - } - -/* - * Open input/output files - */ - errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); - if (errors != 0) { - clean_up(); - return errors; - } -#ifdef DOS - write_banner(); -#endif - -/* - * Initialize arrays - */ - errors = do_initialize(); - if (errors != 0) { - clean_up(); - return errors; - } - -/* - * Load database into memory - */ - errors = read_database(getc_callback, db_cookie); - if (errors != 0) { - clean_up(); - return errors; - } - -/* - * Read input data for simulation - */ - errors = run_simulations(getc_callback, input_cookie); - if (errors != 0) { - clean_up(); - return errors; - } - - -/* - * Display successful status - */ - errors = do_status(); - if (errors != 0) { - clean_up(); - return errors; - } -#ifdef PHREEQC_XML -{ - int n; - SAX_StartSystem(); - for (n = 0; n < count_solution; ++n) - { - SAX_AddSolution(solution[n]); - } - SAX_EndSystem(); - SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); - } -#endif - - clean_up(); - close_input_files(); - close_output_files(); -#ifdef PHREEQC_XML - SAX_cleanup(); -#endif - return 0; -} -/* ---------------------------------------------------------------------- */ -int write_banner(void) -/* ---------------------------------------------------------------------- */ -{ - char buffer[80]; - int len, indent; - output_msg(OUTPUT_SCREEN, " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); - output_msg(OUTPUT_SCREEN, " º º\n"); - - /* version */ - len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); - indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' '); - - output_msg(OUTPUT_SCREEN, " º º\n"); - output_msg(OUTPUT_SCREEN, " º A hydrogeochemical transport model º\n"); - output_msg(OUTPUT_SCREEN, " º º\n"); - output_msg(OUTPUT_SCREEN, " º by º\n"); - output_msg(OUTPUT_SCREEN, " º D.L. Parkhurst and C.A.J. Appelo º\n"); - output_msg(OUTPUT_SCREEN, " º º\n"); - - - /* date */ - len = sprintf(buffer, "%s", "@VER_DATE@"); - indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' '); - - output_msg(OUTPUT_SCREEN, " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); - -return 0; -} diff --git a/mainsubs.cpp b/mainsubs.cpp deleted file mode 100644 index 8c1d6df2..00000000 --- a/mainsubs.cpp +++ /dev/null @@ -1,2486 +0,0 @@ -#define EXTERNAL extern -#define MAINSUBS -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -#include "input.h" - -extern void test_classes(void); -#define PHREEQC_XML -#ifdef PHREEQC_XML -#include "SAXPhreeqc.h" -extern void SAX_cleanup(void); -#endif - -static char const svnid[] = "$Id: mainsubs.c 715 2006-01-18 01:26:29Z dlpark $"; - -#if defined(WINDOWS) || defined(_WINDOWS) -#include -#endif - -static int copy_use (int i); -static int set_use(void); -static int xexchange_save(int n_user); -static int xgas_save(int n_user); -static int xpp_assemblage_save(int n_user); -static int xs_s_assemblage_save(int n_user); -static int xsurface_save(int n_user); - -#ifdef PHREEQ98 -extern int phreeq98_debug; -extern int AddSeries, connect_simulations; -#endif -/* ---------------------------------------------------------------------- */ -void initialize(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Initialize global variables - */ - ENTRY item, *found_item; - int i; - struct logk *logk_ptr; - char token[MAX_LENGTH]; - if (svnid == NULL) fprintf(stderr," "); - - moles_per_kilogram_string = string_duplicate("Mol/kgw"); - pe_string = string_duplicate("pe"); - - debug_model = FALSE; - debug_prep = FALSE; - debug_set = FALSE; - debug_diffuse_layer = FALSE; - debug_inverse = FALSE; - itmax=100; -#ifdef USE_LONG_LDBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow(10, -LDBL_DIG); -#else - ineq_tol = pow(10, -DBL_DIG); -#endif - convergence_tolerance = 1e-8; -#ifdef USE_LONG_LDBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow(10, -LDBL_DIG+5); -#else - inv_tol_default = pow(10, -DBL_DIG+5); -#endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - /* mass_water_switch = TRUE; */ - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; - negative_concentrations = FALSE; - - LOG_10 = log(10.0); - /* Use space for all memory allocation */ - max_solution=MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; - max_s_s_assemblage = MAX_PP_ASSEMBLAGE; - - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_strings = MAX_STRINGS; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; - - count_solution = 0; - count_pp_assemblage = 0; - count_exchange = 0; - count_surface = 0; - count_gas_phase = 0; - count_kinetics = 0; - count_s_s_assemblage = 0; - - count_elements = 0; - count_irrev = 0; - count_master = 0; - count_mix = 0; - count_phases=0; - count_s = 0; - count_temperature = 0; - count_logk = 0; - count_master_isotope = 0; -/* - * Initialize advection - */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - advection_punch = (int *) PHRQ_malloc(sizeof(int)); - if (advection_punch == NULL) malloc_error(); - advection_punch[0] = TRUE; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = (int *) PHRQ_malloc(sizeof(int)); - if (advection_print == NULL) malloc_error(); - advection_print[0] = TRUE; - advection_warnings = TRUE; -/* - * Initialize transport - */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; -/* !!!! count_stag = 0; */ - - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; -/* - * Allocate space - */ - space ((void **) ((void *) &pp_assemblage), INIT, &max_pp_assemblage, sizeof(struct pp_assemblage)); - - space ((void **) ((void *) &exchange), INIT, &max_exchange, sizeof(struct exchange)); - - space ((void **) ((void *) &surface), INIT, &max_surface, sizeof(struct surface)); - - space ((void **) ((void *) &gas_phase), INIT, &max_gas_phase, sizeof(struct gas_phase)); - - space ((void **) ((void *) &kinetics), INIT, &max_kinetics, sizeof(struct kinetics)); - - space ((void **) ((void *) &s_s_assemblage), INIT, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - - space ((void **) ((void *) &cell_data), INIT, &count_cells, - sizeof(struct cell_data)); - - space ((void **) ((void *) &elements), INIT, &max_elements, sizeof(struct element *)); - - space ((void **) ((void *) &elt_list), INIT, &max_elts, sizeof(struct elt_list)); - - - inverse = (struct inverse *) PHRQ_malloc( (size_t) sizeof (struct inverse) ); - if (inverse == NULL) malloc_error(); - count_inverse = 0; - - irrev = (struct irrev *) PHRQ_malloc( (size_t) sizeof (struct irrev) ); - if (irrev == NULL) malloc_error(); - - space ((void **) ((void *) &line), INIT, &max_line, sizeof(char)); - - space ((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); - - space ((void **) ((void *) &master), INIT, &max_master, sizeof(struct master *)); - - space ((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, sizeof(struct unknown_list)); - - mix = (struct mix *) PHRQ_malloc((size_t) sizeof(struct mix)); - if (mix == NULL) malloc_error(); - count_mix = 0; -/* !!!! */ - stag_data = (struct stag_data *) PHRQ_calloc (1, sizeof(struct stag_data)); - if (stag_data == NULL) malloc_error(); - stag_data->count_stag = 0; - stag_data->exch_f = 0; - stag_data->th_m = 0; - stag_data->th_im = 0; - - space ((void **) ((void *) &phases), INIT, &max_phases, sizeof(struct phase *)); - - space ((void **) &trxn.token, INIT, &max_trxn, - sizeof(struct rxn_token_temp)); - - space ((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); - - space ((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); - - space ((void **) ((void *) &master_isotope), INIT, &max_master_isotope, sizeof(struct master_isotope *)); - - solution = (struct solution **) PHRQ_malloc((size_t) MAX_SOLUTION * sizeof(struct solution *)); - if (solution == NULL) malloc_error(); - - temperature = (struct temperature *) PHRQ_malloc((size_t) sizeof (struct temperature)); - if (temperature == NULL) malloc_error(); - - title_x = NULL; - pe_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; -/* SRC ADDED */ - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; -/* SRC ADDED */ - isotopes_x = (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); - if (isotopes_x == NULL) malloc_error(); - x = NULL; - max_unknowns = 0; - - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; - - hcreate_multi((unsigned) max_logk, &logk_hash_table); - hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); -/* - * Create hash table for strings - */ - hcreate_multi((unsigned) max_strings, &strings_hash_table); - hcreate_multi((unsigned) max_elements, &elements_hash_table); - hcreate_multi((unsigned) max_s, &species_hash_table); - hcreate_multi((unsigned) max_phases, &phases_hash_table); - hcreate_multi((unsigned) 2*NKEYS, &keyword_hash_table); -/* - * Initialize use pointers - */ - use.solution_in = FALSE; - use.pp_assemblage_in = FALSE; - use.mix_in = FALSE; - use.irrev_in = FALSE; -/* - * Initialize punch - */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.totals == NULL) malloc_error(); - punch.count_molalities = 0; - punch.molalities = (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.molalities == NULL) malloc_error(); - punch.count_activities = 0; - punch.activities = (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.activities == NULL) malloc_error(); - punch.count_pure_phases = 0; - punch.pure_phases = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.pure_phases == NULL) malloc_error(); - punch.count_si = 0; - punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.si == NULL) malloc_error(); - punch.count_gases = 0; - punch.gases = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.gases == NULL) malloc_error(); - punch.count_s_s = 0; - punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.s_s == NULL) malloc_error(); - - punch.count_kinetics = 0; - punch.kinetics = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.kinetics == NULL) malloc_error(); - - punch.count_isotopes = 0; - punch.isotopes = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.isotopes == NULL) malloc_error(); - - punch.count_calculate_values = 0; - punch.calculate_values = (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.calculate_values == NULL) malloc_error(); - - count_save_values = 0; - save_values = (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); - if (save_values == NULL) malloc_error(); - - punch.inverse = TRUE; - - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -/* - * last model - */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; - last_model.s_s_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; - last_model.surface_charge = NULL; -/* - * Update hash table - */ - keyword_hash = (struct key *) PHRQ_malloc((size_t) NKEYS * sizeof(struct key)); - if (keyword_hash == NULL) malloc_error(); - for (i = 0; i < NKEYS; i++) { - keyword_hash[i].name = string_hsave(keyword[i].name); - keyword_hash[i].keycount = i; - item.key = keyword_hash[i].name; - item.data = (void *) &keyword_hash[i]; - found_item = hsearch_multi(keyword_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in keyword initialization."); - error_msg(error_string, STOP); - } - } -/* - * rates - */ - rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); - if (rates == NULL) malloc_error(); - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - rate_p = NULL; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; - initial_total_time = 0; - -/* - * user_print, user_punch - */ - user_print = (struct rate *) PHRQ_malloc((size_t) sizeof (struct rate)); - if (user_print == NULL) malloc_error(); - user_print->commands = NULL; - user_print->linebase = NULL; - user_print->varbase = NULL; - user_print->loopbase = NULL; - user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof (struct rate)); - if (user_punch == NULL) malloc_error(); - user_punch->commands = NULL; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - user_punch_headings = (char **) PHRQ_malloc(sizeof(char *)); - if (user_punch_headings == NULL) malloc_error(); - user_punch_count_headings = 0; -#ifdef PHREEQ98 -/* - * user_graph - */ - user_graph = PHRQ_malloc((size_t) sizeof (struct rate)); - if (user_graph == NULL) malloc_error(); - user_graph->commands = NULL; - user_graph->linebase = NULL; - user_graph->varbase = NULL; - user_graph->loopbase = NULL; - user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); - if (user_graph_headings == NULL) malloc_error(); - user_graph_count_headings = 0; -#endif - /* - Initialize llnl aqueous model parameters - */ - llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_temp == NULL) malloc_error(); - llnl_count_temp = 0; - llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_adh == NULL) malloc_error(); - llnl_count_adh = 0; - llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_bdh == NULL) malloc_error(); - llnl_count_bdh = 0; - llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_bdot == NULL) malloc_error(); - llnl_count_bdot = 0; - llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_co2_coefs == NULL) malloc_error(); - llnl_count_co2_coefs = 0; -/* - * - */ - cmd_initialize(); -#if defined(WINDOWS) || defined(_WINDOWS) - /* SRC pr.status = FALSE; */ -#endif - /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; - if (phast == TRUE) { - pr.status = FALSE; - } else { - pr.status = TRUE; - } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - - species_list = NULL; - - user_database = NULL; - first_read_input = TRUE; - selected_output_file_name = NULL; - dump_file_name = NULL; - -#ifdef PHREEQCI_GUI - g_spread_sheet.heading = NULL; - g_spread_sheet.units = NULL; - g_spread_sheet.count_rows = 0; - g_spread_sheet.rows = NULL; - g_spread_sheet.defaults.units = NULL; - g_spread_sheet.defaults.count_iso = 0; - g_spread_sheet.defaults.iso = NULL; -#endif - /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - space ((void **) ((void *) &calculate_value), INIT, &max_calculate_value, sizeof(struct calculate_value *)); - hcreate_multi((unsigned) max_calculate_value, &calculate_value_hash_table); - - /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - space ((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, sizeof(struct isotope_ratio *)); - hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); - - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - space ((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, sizeof(struct isotope_alpha *)); - hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); - - /* - * define constant named log_k - */ - strcpy(token, "XconstantX"); - logk_ptr = logk_store(token, TRUE); - read_log_k_only("1.0", &logk_ptr->log_k[0]); - - phreeqc_mpi_myself = 0; - - copier_init(©_solution); - copier_init(©_pp_assemblage); - copier_init(©_exchange); - copier_init(©_surface); - copier_init(©_s_s_assemblage); - copier_init(©_gas_phase); - copier_init(©_kinetics); - copier_init(©_mix); - copier_init(©_irrev); - copier_init(©_temperature); - - set_forward_output_to_log(FALSE); - simulation = 0; - /* - * cvode - */ - cvode_init(); - /* - * Pitzer - */ - pitzer_init(); - /* - * to facilitate debuging - */ - dbg_use = &use; - dbg_solution = solution; - dbg_exchange = exchange; - dbg_surface = surface; - dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; - dbg_irrev = irrev; - dbg_mix = mix; - return; -} -/* ---------------------------------------------------------------------- */ -static int set_use(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Structure "use" has list of solution, ex, surf, pp_assemblage, - * gas_phase and solid solution to use in current calculations, - * also mix, irrev, and temp. - * This routine searches for the user numbers in each list - * (solution, ex, ...) and sets a pointer in structure use - */ - -/* - * Initial solution case - */ - use.pp_assemblage_ptr = NULL; - use.mix_ptr = NULL; - use.irrev_ptr = NULL; - use.exchange_ptr = NULL; - use.kinetics_ptr = NULL; - use.surface_ptr = NULL; - use.temperature_ptr = NULL; - use.gas_phase_ptr = NULL; - use.s_s_assemblage_ptr = NULL; - - if (state < REACTION) { - return(OK); - } -/* - * Reaction case - */ - if (use.pp_assemblage_in == FALSE && - use.irrev_in == FALSE && - use.mix_in == FALSE && - use.exchange_in == FALSE && - use.kinetics_in == FALSE && - use.surface_in == FALSE && - use.temperature_in == FALSE && - use.gas_phase_in == FALSE && - use.s_s_assemblage_in == FALSE) { - return (FALSE); - } - if (use.solution_in == FALSE && use.mix_in == FALSE) return(FALSE); -/* - * Find solution - */ - if (use.solution_in == TRUE) { - use.solution_ptr = solution_bsearch (use.n_solution_user, &use.n_solution, FALSE); - if (use.solution_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", use.n_solution_user); - error_msg(error_string, STOP); - } - } -/* - * Find mixture - */ - if (use.mix_in == TRUE) { - use.mix_ptr = mix_bsearch(use.n_mix_user, &use.n_mix); - use.n_mix_user_orig = use.n_mix_user; - if (use.mix_ptr == NULL) { - sprintf(error_string, "Mixture %d not found.", use.n_mix_user); - error_msg(error_string, STOP); - } - } else { - use.mix_ptr = NULL; - } -/* - * Find pure phase assemblage - */ - if (use.pp_assemblage_in == TRUE) { - use.pp_assemblage_ptr = pp_assemblage_bsearch (use.n_pp_assemblage_user, &use.n_pp_assemblage); - if (use.pp_assemblage_ptr == NULL) { - sprintf(error_string, "Pure phase assemblage %d not found.", use.n_pp_assemblage_user); - error_msg(error_string, STOP); - } - } else { - use.pp_assemblage_ptr = NULL; - } -/* - * Find irrev reaction - */ - if (use.irrev_in == TRUE) { - use.irrev_ptr = irrev_bsearch(use.n_irrev_user, &use.n_irrev); - if (use.irrev_ptr == NULL) { - sprintf(error_string, "Irreversible reaction %d not found.", use.n_irrev_user); - error_msg(error_string, STOP); - } - } else { - use.irrev_ptr = NULL; - } -/* - * Find exchange - */ - if (use.exchange_in == TRUE) { - use.exchange_ptr = exchange_bsearch(use.n_exchange_user, &use.n_exchange); - if (use.exchange_ptr == NULL) { - sprintf(error_string, "Exchange %d not found.", use.n_exchange_user); - error_msg(error_string, STOP); - } - } else { - use.exchange_ptr = NULL; - } -/* - * Find kinetics - */ - if (use.kinetics_in == TRUE) { - use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &use.n_kinetics); - if (use.kinetics_ptr == NULL) { - sprintf(error_string, "Kinetics %d not found.", use.n_kinetics_user); - error_msg(error_string, STOP); - } - } else { - use.kinetics_ptr = NULL; - } -/* - * Find surface - */ - diffuse_layer_x = FALSE; - if (use.surface_in == TRUE) { - use.surface_ptr = surface_bsearch(use.n_surface_user, &use.n_surface); - if (use.surface_ptr == NULL) { - sprintf(error_string, "Surface %d not found.", use.n_surface_user); - error_msg(error_string, STOP); - } - } else { - use.surface_ptr = NULL; - } -/* - * Find temperature - */ - if (use.temperature_in == TRUE) { - use.temperature_ptr = temperature_bsearch(use.n_temperature_user, &use.n_temperature); - if (use.temperature_ptr == NULL) { - sprintf(error_string, "Temperature %d not found.", use.n_temperature_user); - error_msg(error_string, STOP); - } - } else { - use.temperature_ptr = NULL; - } -/* - * Find gas - */ - if (use.gas_phase_in == TRUE) { - use.gas_phase_ptr = gas_phase_bsearch(use.n_gas_phase_user, &use.n_gas_phase); - if (use.gas_phase_ptr == NULL) { - sprintf(error_string, "Gas_phase %d not found.", use.n_gas_phase_user); - error_msg(error_string, STOP); - } - } else { - use.gas_phase_ptr = NULL; - } -/* - * Find s_s_assemblage - */ - if (use.s_s_assemblage_in == TRUE) { - use.s_s_assemblage_ptr = s_s_assemblage_bsearch(use.n_s_s_assemblage_user, &use.n_s_s_assemblage); - if (use.s_s_assemblage_ptr == NULL) { - sprintf(error_string, "s_s_assemblage %d not found.", use.n_s_s_assemblage_user); - error_msg(error_string, STOP); - } - } else { - use.s_s_assemblage_ptr = NULL; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_solutions(int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of solutions, make initial solution calculations - * for any marked "new". - */ - int i, converge, converge1; - int n, last, n_user, print1; - char token[2*MAX_LENGTH]; - - state = INITIAL_SOLUTION; - set_use(); - print1 = TRUE; - diffuse_layer_x = FALSE; - for (n=0; n < count_solution; n++) { - initial_solution_isotopes = FALSE; - if (solution[n] != NULL && solution[n]->new_def == TRUE) { - if (print1 == TRUE && print == TRUE) { - dup_print("Beginning of initial solution calculations.", TRUE); - print1 = FALSE; - } - if (print == TRUE) { - sprintf(token, "Initial solution %d.\t%.350s", solution[n]->n_user, solution[n]->description); - dup_print(token, FALSE); - } - use.solution_ptr = solution[n]; - prep(); - k_temp(solution[n]->tc); - set(TRUE); - converge = model(); - converge1 = check_residuals(); - sum_species(); - add_isotopes(solution[n]); - punch_all(); - print_all(); - /* free_model_allocs(); */ - if (converge == ERROR || converge1 == ERROR) { - error_msg("Model failed to converge for initial solution.", STOP); - } - n_user = solution[n]->n_user; - last = solution[n]->n_user_end; - /* copy isotope data */ - if (solution[n]->count_isotopes > 0) { - count_isotopes_x = solution[n]->count_isotopes; - isotopes_x = (struct isotope *) PHRQ_realloc(isotopes_x, (size_t) count_isotopes_x * sizeof(struct isotope)); - if (isotopes_x == NULL) malloc_error(); - memcpy(isotopes_x, solution[n]->isotopes, (size_t) count_isotopes_x * sizeof(struct isotope)); - } else { - count_isotopes_x = 0; - } - xsolution_save(n_user); - for (i = n_user + 1; i <= last; i++) { - solution_duplicate(n_user, i); - } - } - } - initial_solution_isotopes = FALSE; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_exchangers(int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of exchangers, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a - * solution. - */ - int i, converge, converge1; - int n, last, n_user, print1; - char token[2*MAX_LENGTH]; - - state = INITIAL_EXCHANGE; - set_use(); - print1 = TRUE; - diffuse_layer_x = FALSE; - for (n=0; n < count_exchange; n++) { - if (exchange[n].new_def != TRUE) continue; - n_user = exchange[n].n_user; - last = exchange[n].n_user_end; - exchange[n].n_user_end = n_user; - if (exchange[n].solution_equilibria == TRUE) { - if (print1 == TRUE && print == TRUE) { - dup_print("Beginning of initial exchange" - "-composition calculations.", TRUE); - print1 = FALSE; - } - if (print == TRUE) { - sprintf(token, "Exchange %d.\t%.350s", - exchange[n].n_user, - exchange[n].description); - dup_print(token, FALSE); - } - use.exchange_ptr = &(exchange[n]); - use.solution_ptr = solution_bsearch(exchange[n].n_solution, &i, TRUE); - if (use.solution_ptr == NULL) { - error_msg("Solution not found for initial exchange calculation", STOP); - } -#ifdef PHREEQC_XML -{ - // int n; - //SAX_StartSystem(); - //SAX_AddSolution(use.solution_ptr); - //SAX_EndSystem(); - //SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); - //SAX_cleanup(); - } -#endif - prep(); - k_temp(use.solution_ptr->tc); - set(TRUE); - converge = model(); - converge1 = check_residuals(); - sum_species(); - species_list_sort(); - print_exchange(); - xexchange_save(n_user); - punch_all(); - /* free_model_allocs(); */ - if (converge == ERROR || converge1 == ERROR) { - error_msg("Model failed to converge for initial exchange calculation.", STOP); - } - } - for (i = n_user + 1; i <= last; i++) { - exchange_duplicate(n_user, i); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_gas_phases(int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of gas_phases, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a - * solution. - */ - int i, converge, converge1; - int n, last, n_user, print1; - char token[2*MAX_LENGTH]; - struct gas_comp *gas_comp_ptr; - struct phase *phase_ptr; - struct rxn_token *rxn_ptr; - LDBLE lp; - - state = INITIAL_GAS_PHASE; - set_use(); - print1 = TRUE; - diffuse_layer_x = FALSE; - for (n=0; n < count_gas_phase; n++) { - if (gas_phase[n].new_def != TRUE) continue; - n_user = gas_phase[n].n_user; - last = gas_phase[n].n_user_end; - gas_phase[n].n_user_end = n_user; - if (gas_phase[n].solution_equilibria == TRUE) { - if (print1 == TRUE && print == TRUE) { - dup_print("Beginning of initial gas_phase" - "-composition calculations.", TRUE); - print1 = FALSE; - } - if (print == TRUE) { - sprintf(token, "Gas_Phase %d.\t%.350s", - gas_phase[n].n_user, - gas_phase[n].description); - dup_print(token, FALSE); - } - use.solution_ptr = solution_bsearch(gas_phase[n].n_solution, &i, TRUE); - prep(); - k_temp(use.solution_ptr->tc); - set(TRUE); - converge = model(); - converge1 = check_residuals(); - if (converge == ERROR || converge1 == ERROR) { - /* free_model_allocs(); */ - error_msg("Model failed to converge for initial gas phase calculation.", STOP); - } - use.gas_phase_ptr = &(gas_phase[n]); - use.gas_phase_ptr->total_p = 0; - use.gas_phase_ptr->total_moles = 0; - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); - phase_ptr = gas_comp_ptr->phase; - if (phase_ptr->in == TRUE) { - lp=-phase_ptr->lk; - for (rxn_ptr=phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - gas_comp_ptr->phase->p_soln_x = exp(lp * LOG_10); - use.gas_phase_ptr->total_p += gas_comp_ptr->phase->p_soln_x; - gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * - use.gas_phase_ptr->volume / (R_LITER_ATM * tk_x); - gas_comp_ptr->moles = gas_comp_ptr->phase->moles_x; - use.gas_phase_ptr->total_moles += gas_comp_ptr->moles; - } else { - gas_comp_ptr->phase->moles_x = 0; - } - } - print_gas_phase(); - xgas_save(n_user); - punch_all(); - /* free_model_allocs(); */ - } - for (i = n_user + 1; i <= last; i++) { - gas_phase_duplicate(n_user, i); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_surfaces(int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of surfaces, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a - * solution. - */ - int i; - int n, last, n_user, print1; - char token[2*MAX_LENGTH]; - - state = INITIAL_SURFACE; - set_use(); - print1 = TRUE; - for (n=0; n < count_surface; n++) { - if (surface[n].new_def != TRUE) continue; - n_user = surface[n].n_user; - last = surface[n].n_user_end; - surface[n].n_user_end = n_user; - if (surface[n].solution_equilibria == TRUE) { - if (print1 == TRUE && print == TRUE) { - dup_print("Beginning of initial surface-composition calculations.", TRUE); - print1 = FALSE; - } - if (print == TRUE) { - sprintf(token, "Surface %d.\t%.350s", - surface[n].n_user, - surface[n].description); - dup_print(token, FALSE); - } - use.surface_ptr = &(surface[n]); - diffuse_layer_x = use.surface_ptr->diffuse_layer; - use.solution_ptr = solution_bsearch(surface[n].n_solution, &i, TRUE); - if (use.solution_ptr == NULL) { - error_msg("Solution not found for initial surface calculation", STOP); - } -#ifdef SKIP - if (diffuse_layer_x == TRUE) { - converge = surface_model(); - } else { - prep(); - k_temp(use.solution_ptr->tc); - set(TRUE); - converge = model(); - } - converge1 = check_residuals(); - sum_species(); -#endif - set_and_run_wrapper(-1, FALSE, FALSE, -1, 0.0); - species_list_sort(); - print_surface(); - punch_all(); -#ifdef SKIP - if (converge == ERROR || converge1 == ERROR) { - /* free_model_allocs(); */ - error_msg("Model failed to converge for initial surface calculation.", STOP); - } -#endif - xsurface_save(n_user); - /* free_model_allocs(); */ - } - for (i = n_user + 1; i <= last; i++) { - surface_duplicate(n_user, i); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int reactions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make all reaction calculation which could include: - * equilibrium with a pure-phase assemblage, - * equilibrium with an exchanger, - * equilibrium with an surface, - * equilibrium with a gas phase, - * equilibrium with a solid solution assemblage, - * kinetics, - * change of temperature, - * mixture, - * or irreversible reaction. - */ - int count_steps, use_mix, m; - char token[2*MAX_LENGTH]; - struct save save_data; - LDBLE kin_time; - struct kinetics *kinetics_ptr; - - state = REACTION; - /* last_model.force_prep = TRUE; */ - if (set_use() == FALSE) return(OK); -/* - * Find maximum number of steps - */ - dup_print ("Beginning of batch-reaction calculations.", TRUE); - count_steps = 1; - if (use.irrev_in == TRUE && use.irrev_ptr != NULL) { - if (abs(use.irrev_ptr->count_steps) > count_steps) - count_steps = abs(use.irrev_ptr->count_steps); - } - if (use.kinetics_in == TRUE && use.kinetics_ptr != NULL) { - if (abs(use.kinetics_ptr->count_steps) > count_steps) - count_steps = abs(use.kinetics_ptr->count_steps); - } - if (use.temperature_in == TRUE && use.temperature_ptr != NULL) { - if (abs(use.temperature_ptr->count_t) > count_steps) - count_steps = abs(use.temperature_ptr->count_t); - } - count_total_steps = count_steps; -/* - * save data for saving solutions - */ - memcpy(&save_data, &save, sizeof(struct save)); - /* - *Copy everything to -2 - */ - copy_use(-2); - rate_sim_time_start = 0; - rate_sim_time = 0; - for (reaction_step=1; reaction_step <= count_steps; reaction_step++) { - sprintf(token,"Reaction step %d.", reaction_step); - if (reaction_step > 1 && incremental_reactions == FALSE) { - copy_use(-2); - } - set_initial_moles(-2); - dup_print(token, FALSE); -/* - * Determine time step for kinetics - */ - kin_time = 0.0; - if ( use.kinetics_in == TRUE) { - kinetics_ptr = kinetics_bsearch(-2, &m); - if (incremental_reactions == FALSE) { - if (kinetics_ptr->count_steps > 0) { - if (reaction_step > kinetics_ptr->count_steps) { - kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } else { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } else if (kinetics_ptr->count_steps < 0) { - if (reaction_step > -kinetics_ptr->count_steps) { - kin_time = kinetics_ptr->steps[0]; - } else { - kin_time = reaction_step * kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); - } - } - } else { - /* incremental reactions */ - if (kinetics_ptr->count_steps > 0) { - if (reaction_step > kinetics_ptr->count_steps) { - kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } else { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } else if (kinetics_ptr->count_steps < 0) { - if (reaction_step > -kinetics_ptr->count_steps) { - kin_time = 0; - } else { - kin_time = kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); - } - } - } - } - if (incremental_reactions == FALSE || - (incremental_reactions == TRUE && reaction_step == 1)) { - use_mix = TRUE; - } else { - use_mix = FALSE; - } -/* - * Run reaction step - */ - run_reactions(-2, kin_time, use_mix, 1.0); - if (incremental_reactions == TRUE) { - rate_sim_time_start += kin_time; - rate_sim_time = rate_sim_time_start; - } else { - rate_sim_time = kin_time; - } - if (state != ADVECTION) { - punch_all(); - print_all(); - } - /* saves back into -2 */ - if (reaction_step < count_steps) { - saver(); - } - } -/* - * save end of reaction - */ - memcpy(&save, &save_data, sizeof(struct save)); - if (use.kinetics_in == TRUE) { - kinetics_duplicate(-2, use.n_kinetics_user); - } - saver(); - - /* free_model_allocs(); */ - /* last_model.force_prep = TRUE; */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int saver(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save results of calcuations (data in variables with _x, - * in unknown structure x, in master, or s) into structure - * arrays. Structure "save" has info on whether to save - * data for each entity (solution, ex, surf, pp, gas, or s_s). - * Initial calculation may be saved into multiple "n_user" - * slots. - */ - int i, n; - char token[MAX_LENGTH]; - - if (save.solution == TRUE) { - sprintf(token, "Solution after simulation %d.", simulation); - description_x = (char *) free_check_null(description_x); - description_x = string_duplicate(token); - n = save.n_solution_user; - xsolution_save(n); - for(i = save.n_solution_user + 1; i <= save.n_solution_user_end; i++) { - solution_duplicate(n, i); - } - } - if (save.pp_assemblage == TRUE) { - n = save.n_pp_assemblage_user; - xpp_assemblage_save(n); - for(i = save.n_pp_assemblage_user + 1; i <= save.n_pp_assemblage_user_end; i++) { - pp_assemblage_duplicate(n, i); - } - } - if (save.exchange == TRUE) { - n = save.n_exchange_user; - xexchange_save(n); - for(i = save.n_exchange_user + 1; i <= save.n_exchange_user_end; i++) { - exchange_duplicate(n, i); - } - } - if (save.surface == TRUE) { - n = save.n_surface_user; - xsurface_save(n); - for(i = save.n_surface_user + 1; i <= save.n_surface_user_end; i++) { - surface_duplicate(n, i); - } - } - if (save.gas_phase == TRUE) { - n = save.n_gas_phase_user; - xgas_save(n); - for(i = save.n_gas_phase_user + 1; i <= save.n_gas_phase_user_end; i++) { - gas_phase_duplicate(n, i); - } - } - if (save.s_s_assemblage == TRUE) { - n = save.n_s_s_assemblage_user; - xs_s_assemblage_save(n); - for(i = save.n_s_s_assemblage_user + 1; i <= save.n_s_s_assemblage_user_end; i++) { - s_s_assemblage_duplicate(n, i); - } - } - if (save.kinetics == TRUE && use.kinetics_in == TRUE && use.kinetics_ptr != NULL) { - n = use.kinetics_ptr->n_user; - for(i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) { - kinetics_duplicate(n, i); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int xexchange_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save exchanger assemblage into structure exchange with user - * number n_user. - */ - int i, j, n; - char token[MAX_LENGTH]; - int count_comps; - struct exchange temp_exchange, *exchange_ptr; - LDBLE charge; - if (use.exchange_ptr == NULL) return(OK); -/* - * Store data for structure exchange - */ - memcpy(&temp_exchange, use.exchange_ptr, sizeof(struct exchange)); - temp_exchange.n_user = n_user; - temp_exchange.n_user_end = n_user; - temp_exchange.new_def = FALSE; - sprintf(token, "Exchange assemblage after simulation %d.", simulation); - temp_exchange.description = string_duplicate(token); - temp_exchange.solution_equilibria = FALSE; - temp_exchange.n_solution = -2; - temp_exchange.count_comps = 0; -/* - * Count exchange components and allocate space - */ - count_comps = 0; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == EXCH) count_comps++; - } - temp_exchange.comps = (struct exch_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct exch_comp)); - if (temp_exchange.comps == NULL) malloc_error(); - temp_exchange.count_comps = count_comps; -/* - * Write exch_comp structure for each exchange component - */ - count_comps = 0; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == EXCH) { - memcpy(&temp_exchange.comps[count_comps], x[i]->exch_comp, sizeof(struct exch_comp)); - temp_exchange.comps[count_comps].master = x[i]->master[0]; - temp_exchange.comps[count_comps].la = x[i]->master[0]->s->la; - temp_exchange.comps[count_comps].formula_totals = elt_list_dup(x[i]->exch_comp->formula_totals); - temp_exchange.comps[count_comps].moles = 0.; -/* - * Save element concentrations on exchanger - */ - count_elts = 0; - paren_count = 0; - charge = 0.0; - for (j=0; j < count_species_list; j++) { - if (species_list[j].master_s == x[i]->master[0]->s) { - add_elt_list(species_list[j].s->next_elt, species_list[j].s->moles); - charge += species_list[j].s->moles * species_list[j].s->z; - } - } -/* - * Keep exchanger related to phase even if none currently in solution - */ - if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) { - add_elt_list(x[i]->master[0]->s->next_elt, 1e-20); - } -/* - * Store list - */ - temp_exchange.comps[count_comps].charge_balance = charge; - temp_exchange.comps[count_comps].totals = elt_list_save(); -/* debug - output_msg(OUTPUT_MESSAGE, "Exchange charge_balance: %e\n", charge); - */ - /* update unknown pointer */ - x[i]->exch_comp = &(temp_exchange.comps[count_comps]); - count_comps++; - } - } -/* - * Finish up - */ - exchange_ptr = exchange_bsearch(n_user, &n); - if (exchange_ptr == NULL) { - n = count_exchange++; - space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); - } else { - exchange_free(&exchange[n]); - } - memcpy(&exchange[n], &temp_exchange, sizeof(struct exchange)); - /* sort only if necessary */ - if (n == count_exchange - 1 && count_exchange > 1) { - if (exchange[n].n_user < exchange[n-1].n_user) { - qsort (exchange, - (size_t) count_exchange, - (size_t) sizeof (struct exchange), - exchange_compare); - } - } - use.exchange_ptr = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int xgas_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save gas composition into structure gas_phase with user - * number n_user. - */ - int count_comps, n, i; - struct gas_phase temp_gas_phase, *gas_phase_ptr; - char token[MAX_LENGTH]; - - if (use.gas_phase_ptr == NULL) return(OK); -/* - * Count gases - */ - count_comps = use.gas_phase_ptr->count_comps; -/* - * Malloc space and copy - */ - temp_gas_phase.comps = (struct gas_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct gas_comp)); - if (temp_gas_phase.comps == NULL) malloc_error(); - memcpy( (void *) temp_gas_phase.comps, (void *) use.gas_phase_ptr->comps, (size_t) count_comps * sizeof(struct gas_comp) ); -/* - * Store in gas_phase - */ - - temp_gas_phase.n_user = n_user; - temp_gas_phase.n_user_end = n_user; - sprintf(token, "Gas phase after simulation %d.", simulation); - temp_gas_phase.description = string_duplicate(token); - temp_gas_phase.new_def = FALSE; - temp_gas_phase.solution_equilibria = FALSE; - temp_gas_phase.n_solution = -99; - temp_gas_phase.type = use.gas_phase_ptr->type; - temp_gas_phase.total_p = use.gas_phase_ptr->total_p; - temp_gas_phase.total_moles = use.gas_phase_ptr->total_moles; - temp_gas_phase.volume = use.gas_phase_ptr->volume; - temp_gas_phase.temperature = use.gas_phase_ptr->temperature; - temp_gas_phase.count_comps = count_comps; -/* - * Update amounts - */ - for (i = 0; i < count_comps; i++) { - temp_gas_phase.comps[i].moles = use.gas_phase_ptr->comps[i].phase->moles_x; - } -/* - * Finish up - */ - gas_phase_ptr = gas_phase_bsearch(n_user, &n); - if (gas_phase_ptr == NULL) { - n = count_gas_phase++; - space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); - } else { - gas_phase_free(&gas_phase[n]); - } - memcpy(&gas_phase[n], &temp_gas_phase, sizeof(struct gas_phase)); - - /* update unknown pointer */ - if (gas_unknown != NULL) { - gas_unknown->gas_phase = &(gas_phase[n]); - } - /* sort only if necessary */ - if (n == count_gas_phase - 1 && count_gas_phase > 1) { - if (gas_phase[n].n_user < gas_phase[n-1].n_user) { - qsort (gas_phase, - (size_t) count_gas_phase, - (size_t) sizeof (struct gas_phase), - gas_phase_compare); - } - } - use.gas_phase_ptr = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int xs_s_assemblage_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save s_s_assemblage composition into structure s_s_assemblage with user - * number n_user. - */ - int i, j, n; - int count_comps, count_s_s; - struct s_s_assemblage temp_s_s_assemblage, *s_s_assemblage_ptr; - char token[MAX_LENGTH]; - - if (use.s_s_assemblage_ptr == NULL) return(OK); -/* - * Set s_s_assemblage - */ - temp_s_s_assemblage.n_user = n_user; - temp_s_s_assemblage.n_user_end = n_user; - sprintf(token, "Solid solution assemblage after simulation %d.", simulation); - temp_s_s_assemblage.description = string_duplicate(token); - temp_s_s_assemblage.new_def = FALSE; -#ifdef SKIP - temp_s_s_assemblage.type = use.s_s_assemblage_ptr->type; - temp_s_s_assemblage.solution_equilibria = FALSE; - temp_s_s_assemblage.n_solution = -99; -#endif - count_s_s = use.s_s_assemblage_ptr->count_s_s; - temp_s_s_assemblage.count_s_s = count_s_s; -/* - * Malloc space for solid solutions - */ - /* s_s_assemblage->s_s */ - temp_s_s_assemblage.s_s = (struct s_s *) PHRQ_malloc( (size_t) count_s_s * sizeof(struct s_s)); - if (temp_s_s_assemblage.s_s == NULL) malloc_error(); - for (i = 0; i < count_s_s; i++) { - memcpy(&(temp_s_s_assemblage.s_s[i]), &(use.s_s_assemblage_ptr->s_s[i]), sizeof(struct s_s)); - /* - * Malloc space for solid soution components - */ - count_comps = use.s_s_assemblage_ptr->s_s[i].count_comps; - temp_s_s_assemblage.s_s[i].comps = (struct s_s_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct s_s_comp)); - if (temp_s_s_assemblage.s_s[i].comps == NULL) malloc_error(); - memcpy( (void *) temp_s_s_assemblage.s_s[i].comps, (void *) use.s_s_assemblage_ptr->s_s[i].comps, (size_t) count_comps * sizeof(struct s_s_comp) ); - - /* set initial moles for quick setup*/ - for (j = 0; j < count_comps; j++) { - temp_s_s_assemblage.s_s[i].comps[j].initial_moles = temp_s_s_assemblage.s_s[i].comps[j].moles; - } - } -/* - * Finish up - */ - s_s_assemblage_ptr = s_s_assemblage_bsearch(n_user, &n); - if (s_s_assemblage_ptr == NULL) { - space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - n = count_s_s_assemblage++; - } else { - s_s_assemblage_free(&s_s_assemblage[n]); - } - memcpy(&s_s_assemblage[n], &temp_s_s_assemblage, sizeof(struct s_s_assemblage)); - /* sort only if necessary */ - if (n == count_s_s_assemblage - 1 && count_s_s_assemblage > 1) { - if (s_s_assemblage[n].n_user < s_s_assemblage[n-1].n_user) { - qsort (s_s_assemblage, - (size_t) count_s_s_assemblage, - (size_t) sizeof (struct s_s_assemblage), - s_s_assemblage_compare); - } - } - use.s_s_assemblage_ptr = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int xpp_assemblage_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save pure_phase assemblage into structure pp_assemblage with user - * number n_user. - */ - int count_comps, n, j, i; - struct pp_assemblage temp_pp_assemblage, *pp_assemblage_ptr; - char token[MAX_LENGTH]; - - if (use.pp_assemblage_ptr == NULL) return(OK); -/* - * Count pure phases - */ - count_comps = use.pp_assemblage_ptr->count_comps; - - temp_pp_assemblage.n_user = n_user; - temp_pp_assemblage.n_user_end = n_user; - sprintf(token, "Pure-phase assemblage after simulation %d.", simulation); - temp_pp_assemblage.description = string_duplicate(token); - temp_pp_assemblage.new_def = FALSE; - temp_pp_assemblage.count_comps = count_comps; - temp_pp_assemblage.next_elt = elt_list_dup(use.pp_assemblage_ptr->next_elt); -/* - * Malloc space and copy pure phase data - */ - temp_pp_assemblage.pure_phases = (struct pure_phase *) PHRQ_malloc( (size_t) count_comps * sizeof(struct pure_phase)); - if (temp_pp_assemblage.pure_phases == NULL) malloc_error(); - memcpy( (void *) temp_pp_assemblage.pure_phases, (void *) use.pp_assemblage_ptr->pure_phases, (size_t) count_comps * sizeof(struct pure_phase) ); -/* - * Update amounts - */ - i = 0; - for (j=0; j < count_unknowns; j++) { - if (x[j]->type != PP) continue; - temp_pp_assemblage.pure_phases[i].moles = x[j]->moles; - temp_pp_assemblage.pure_phases[i].delta = 0.0; - - /* update unknown ptr, old may be freed later */ - x[j]->pure_phase = &(temp_pp_assemblage.pure_phases[i]); - i++; - } -/* - * Finish up - */ - pp_assemblage_ptr = pp_assemblage_bsearch(n_user, &n); - if (pp_assemblage_ptr == NULL) { - space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); - n = count_pp_assemblage++; - } else { - pp_assemblage_free(&pp_assemblage[n]); - } - memcpy(&pp_assemblage[n], &temp_pp_assemblage, sizeof(struct pp_assemblage)); - /* sort only if necessary */ - if (n == count_pp_assemblage - 1 && count_pp_assemblage > 1) { - if (pp_assemblage[n].n_user < pp_assemblage[n-1].n_user) { - qsort (pp_assemblage, - (size_t) count_pp_assemblage, - (size_t) sizeof (struct pp_assemblage), - pp_assemblage_compare); - } - } - use.pp_assemblage_ptr = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int xsolution_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save solution composition into structure solution with user number - * n_user. - * - * input: n_user is user solution number of target - */ - int i, j, n; - int count_mass_balance, count_master_activity; - int max_mass_balance, max_master_activity; - struct solution *solution_ptr; - struct master *master_i_ptr, *master_ptr; -/* - * Malloc space for solution data - */ - solution_ptr = solution_alloc(); - - max_mass_balance=MAX_MASS_BALANCE; - max_master_activity=MAX_MASS_BALANCE; - - solution_ptr->n_user = n_user; - solution_ptr->n_user_end = n_user; - solution_ptr->new_def = FALSE; - solution_ptr->description = string_duplicate(description_x); - solution_ptr->tc = tc_x; - solution_ptr->ph = ph_x; - solution_ptr->solution_pe = solution_pe_x; - solution_ptr->mu = mu_x; - solution_ptr->ah2o = ah2o_x; - solution_ptr->density = density_x; - solution_ptr->total_h = total_h_x; - solution_ptr->total_o = total_o_x; - solution_ptr->cb = cb_x; /* cb_x does not include surface charge sfter sum_species */ - /* does include surface charge after step */ - - solution_ptr->mass_water = mass_water_aq_x; - solution_ptr->total_alkalinity = total_alkalinity; - /*solution_ptr->total_co2 = total_co2;*/ - solution_ptr->units = moles_per_kilogram_string; -/* - * Copy pe data - */ - - pe_data_free(solution_ptr->pe); - /*solution_ptr->pe = pe_data_dup(pe_x); */ - solution_ptr->pe = pe_data_alloc(); - solution_ptr->default_pe = 0; - /* - * Add in minor isotopes if initial solution calculation - */ - if (initial_solution_isotopes == TRUE) { - for (i = 0; i < count_master_isotope; i++) { - if (master_isotope[i]->moles > 0) { - master_i_ptr = master_bsearch(master_isotope[i]->name); - master_ptr = master_isotope[i]->elt->master; - if (master_isotope[i]->minor_isotope == TRUE) { - master_i_ptr->total = master_isotope[i]->moles; - if (master_ptr->total > 0) { - master_i_ptr->s->la = master_ptr->s->la + log10(master_i_ptr->total / master_ptr->total); - } else { - master_i_ptr->s->la = master_ptr->s->la; - } - } else if (master_isotope[i]->minor_isotope == FALSE && master_ptr->s != s_hplus && master_ptr->s != s_h2o) { - if (master_ptr->s->secondary != NULL) { - master_ptr->s->secondary->total = master_isotope[i]->moles; - } else { - master_ptr->s->primary->total = master_isotope[i]->moles; - } - } - } - } - } -/* - * Copy totals data - */ - count_mass_balance = 0; - count_master_activity = 0; - for (i=0; i < count_master; i++) { - if (master[i]->s->type == EX || - master[i]->s->type == SURF || - master[i]->s->type == SURF_PSI) continue; - if (strcmp(master[i]->elt->name,"H") == 0 || - strcmp(master[i]->elt->name,"H(1)") == 0 || - strcmp(master[i]->elt->name,"O") == 0 || - strcmp(master[i]->elt->name,"O(-2)") == 0) continue; -/* - * Save list of log activities - */ - if (master[i]->in != FALSE) { - count_master_activity++; - } - } - solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(solution_ptr->master_activity, (size_t) (count_master_activity + 1)*sizeof(struct master_activity)); - solution_ptr->count_master_activity = count_master_activity; - count_master_activity = 0; - for (i=0; i < count_master; i++) { - if (master[i]->s->type == EX || - master[i]->s->type == SURF || - master[i]->s->type == SURF_PSI) continue; - if (strcmp(master[i]->elt->name,"H") == 0 || - strcmp(master[i]->elt->name,"H(1)") == 0 || - strcmp(master[i]->elt->name,"O") == 0 || - strcmp(master[i]->elt->name,"O(-2)") == 0) continue; -/* - * Save list of log activities - */ - if (master[i]->in != FALSE) { - solution_ptr->master_activity[count_master_activity].description = master[i]->elt->name; - solution_ptr->master_activity[count_master_activity++].la = master[i]->s->la; - /* - if (count_master_activity + 2 >= max_master_activity) { - space ((void *) &(solution_ptr->master_activity), count_master_activity + 2, - &max_master_activity, sizeof (struct master_activity)); - } - */ - } - if (master[i]->total <= MIN_TOTAL) { - master[i]->total = 0.0; - master[i]->total_primary = 0.0; - continue; - } -/* if (master[i]->total <= 0.0) continue; */ -/* - * Save list of concentrations - */ - solution_ptr->totals[count_mass_balance].description = master[i]->elt->name; - solution_ptr->totals[count_mass_balance].input_conc = master[i]->total; - solution_ptr->totals[count_mass_balance].moles = master[i]->total; - solution_ptr->totals[count_mass_balance].units = solution_ptr->units; - solution_ptr->totals[count_mass_balance].equation_name = NULL; - solution_ptr->totals[count_mass_balance].n_pe = 0; - solution_ptr->totals[count_mass_balance].phase = NULL; - solution_ptr->totals[count_mass_balance].phase_si = 0.0; - solution_ptr->totals[count_mass_balance].as = NULL; - solution_ptr->totals[count_mass_balance].gfw = 0.0; - count_mass_balance++; -/* - * Make space - */ - if (count_mass_balance + 2 >= max_mass_balance) { - space ((void **) &(solution_ptr->totals), count_mass_balance + 2, - &max_mass_balance, sizeof (struct conc)); - } - } - if (pitzer_model == TRUE) { - i = 0; - for (j = 0; j < count_s; j++) { - if (s[j]->lg != 0.0) i++; - } - solution_ptr->species_gamma = (struct master_activity *) PHRQ_realloc(solution_ptr->species_gamma, (size_t) (i * sizeof(struct master_activity))); - i = 0; - for (j= 0; j < count_s; j++) { - if (s[j]->lg != 0.0) { - solution_ptr->species_gamma[i].la = s[j]->lg; - solution_ptr->species_gamma[i].description = s[j]->name; - i++; - } - } - solution_ptr->count_species_gamma = i; - } else { - solution_ptr->species_gamma = NULL; - solution_ptr->count_species_gamma = 0; - } -/* - * Mark end of totals - */ - solution_ptr->totals[count_mass_balance].description = NULL; - count_mass_balance++; - solution_ptr->master_activity[count_master_activity].description = NULL; - count_master_activity++; - solution_ptr->totals = (struct conc *) PHRQ_realloc(solution_ptr->totals, (size_t) count_mass_balance * sizeof(struct conc)); - if (solution_ptr->totals == NULL) malloc_error(); - solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(solution_ptr->master_activity, (size_t) count_master_activity * sizeof(struct master_activity)); - if (solution_ptr->master_activity == NULL) malloc_error(); - solution_ptr->count_master_activity = count_master_activity; -/* - * Save isotope data - */ - if (count_isotopes_x > 0 ) { - solution_ptr->count_isotopes = count_isotopes_x; - solution_ptr->isotopes = (struct isotope *) PHRQ_realloc(solution_ptr->isotopes, (size_t) count_isotopes_x * sizeof(struct isotope)); - if (solution_ptr->isotopes == NULL) malloc_error(); - memcpy(solution_ptr->isotopes, isotopes_x, (size_t) count_isotopes_x * sizeof(struct isotope)); - for (i = 0; i < count_isotopes_x; i++) { - solution_ptr->isotopes[i].total = solution_ptr->isotopes[i].master->total; - if (solution_ptr->isotopes[i].master == s_hplus->secondary) { - solution_ptr->isotopes[i].total = 2 * mass_water_aq_x / gfw_water; - } - if (solution_ptr->isotopes[i].master == s_h2o->secondary) { - solution_ptr->isotopes[i].total = mass_water_aq_x / gfw_water; - } - } - } else { - solution_ptr->count_isotopes = 0; - solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = NULL; - } -/* - * Save solution in solution - */ - if (solution_bsearch (n_user, &n, FALSE) != NULL) { - solution_free(solution[n]); - } else { - n = count_solution++; - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); - } - } - solution[n] = solution_ptr; - /* sort only if necessary */ - if (count_solution > 1 && (solution[count_solution -1]->n_user < solution[count_solution - 2]->n_user)) { - solution_sort(); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int xsurface_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save surface data into structure surface with user - * number n_user. - */ - int i, j, n, last_charge; - int count_comps, count_charge; - char token[MAX_LENGTH]; - struct surface temp_surface, *surface_ptr; - LDBLE charge; - - if (use.surface_ptr == NULL) return(OK); -/* - * Store data for structure surface - */ - memcpy(&temp_surface, use.surface_ptr, sizeof(struct surface)); - temp_surface.n_user = n_user; - temp_surface.n_user_end = n_user; - temp_surface.new_def = FALSE; - temp_surface.diffuse_layer = diffuse_layer_x; - sprintf(token, "Surface assemblage after simulation %d.", simulation); - temp_surface.description = string_duplicate(token); - temp_surface.solution_equilibria = FALSE; - temp_surface.n_solution = -10; -/* - * Allocate space to pointer comps - */ - - count_comps = use.surface_ptr->count_comps; - count_charge = use.surface_ptr->count_charge; - temp_surface.count_comps = count_comps; - temp_surface.comps = (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct surface_comp)); - if (temp_surface.comps == NULL) malloc_error(); - if (temp_surface.edl == FALSE) { - temp_surface.charge = NULL; - temp_surface.count_charge = 0; - } else { - temp_surface.count_charge = count_charge; - temp_surface.charge = (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * sizeof (struct surface_charge)); - if (temp_surface.charge == NULL) malloc_error(); - } -/* - * Write surface_comp structure for each surf component into comps_ptr - */ - count_comps = 0; - count_charge = 0; - /* - * Initial entry of surface sites is random - * Charge balance numbering follows the initial entry - * Surface sites are then sorted alphabetically - * Now when we save, the site order differs from the charge order - * last_charge sets up logic to renumber charge balance equations. - */ - last_charge = -1; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE) { - memcpy(&temp_surface.comps[count_comps], x[i]->surface_comp, sizeof(struct surface_comp)); - - temp_surface.comps[count_comps].master = x[i]->master[0]; - temp_surface.comps[count_comps].la = x[i]->master[0]->s->la; - /* temp_surface.comps[count_comps].formula = NULL; */ - temp_surface.comps[count_comps].moles = 0.; - if (x[i]->surface_comp->charge == last_charge) { - temp_surface.comps[count_comps].charge = count_charge - 1; - } else { - temp_surface.comps[count_comps].charge = count_charge; - } - last_charge = x[i]->surface_comp->charge; -/* - * Save element concentrations on surface - */ - count_elts = 0; - paren_count = 0; - charge = 0.0; - for (j=0; j < count_species_list; j++) { - if (species_list[j].master_s == x[i]->master[0]->s) { - add_elt_list(species_list[j].s->next_elt, species_list[j].s->moles); - charge += species_list[j].s->moles * - species_list[j].s->z; - } - } - temp_surface.comps[count_comps].totals = elt_list_save(); - temp_surface.comps[count_comps].cb = charge; - - /* update unknown pointer */ - x[i]->surface_comp = &(temp_surface.comps[count_comps]); - count_comps++; - } else if (x[i]->type == SURFACE_CB) { - memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, sizeof(struct surface_charge)); - temp_surface.charge[count_charge].charge_balance = x[i]->f; - temp_surface.charge[count_charge].mass_water = x[i]->surface_charge->mass_water; - temp_surface.charge[count_charge].diffuse_layer_totals = NULL; - temp_surface.charge[count_charge].count_g = 0; - temp_surface.charge[count_charge].g = NULL; -/* - * Added code to save g - */ -/* - if (x[i]->surface_charge->count_g > 0) { - temp_surface.charge[count_charge].count_g = x[i]->surface_charge->count_g; - temp_surface.charge[count_charge].g = (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]->surface_charge->count_g * sizeof(struct surface_diff_layer)); - if (temp_surface.charge[count_charge].g == NULL) malloc_error(); - memcpy(temp_surface.charge[count_charge].g, x[i]->surface_charge->g, (size_t) x[i]->surface_charge->count_g * sizeof(struct surface_diff_layer)); - } -*/ - temp_surface.charge[count_charge].psi_master = x[i]->master[0]; - temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; -/* - * Store moles from diffuse_layer - */ - if (diffuse_layer_x == TRUE) { - sum_diffuse_layer(x[i]->surface_charge); - temp_surface.charge[count_charge].diffuse_layer_totals = elt_list_save(); - } - - /* update unknown pointer */ - x[i]->surface_charge = &(temp_surface.charge[count_charge]); - x[i]->surface_comp = x[i - 1]->surface_comp; - - count_charge++; - } - } -/* - * Finish up - */ - surface_ptr = surface_bsearch(n_user, &n); - if (surface_ptr == NULL) { - n = count_surface++; - space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); - } else { - surface_free(&surface[n]); - } - memcpy(&surface[n], &temp_surface, sizeof(struct surface)); - if (n == count_surface - 1 && count_surface > 1) { - if (surface[n].n_user < surface[n-1].n_user) { - qsort (surface, - (size_t) count_surface, - (size_t) sizeof (struct surface), - surface_compare); - } - } - use.surface_ptr = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -FILE *file_open (char *query, char *default_name, const char *status, int batch) -/* ---------------------------------------------------------------------- */ -{ - char name[MAX_LENGTH], answer[MAX_LENGTH]; - FILE *new_file; - int l; - - for (;;) { -/* - * Get file name - */ - strcpy(name, default_name); - if (batch == FALSE) { - output_msg(OUTPUT_SCREEN,"%s\n", query); - if (default_name[0] != '\0') { - output_msg(OUTPUT_SCREEN,"Default: %s\n", default_name); - } - fgets(name, MAX_LENGTH, stdin); - l = strlen(name); - name[l-1]='\0'; - if (name[0] == '\0') { - strcpy(name, default_name); - } - } -/* - * Open existing file to read - */ - if (status[0] == 'r') { - if ((new_file = fopen(name, "r")) == NULL) { - sprintf(error_string, "Can't open file, %s.", name); - output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); - output_fflush(OUTPUT_SCREEN); - batch = FALSE; - continue; - } - break; -/* - * Open file to write, no check - */ - } else if (status[0] == 'w') { - if ((new_file = fopen(name, "w")) == NULL) { - sprintf(error_string, "Error opening file, %s.", name); - output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); - output_fflush(OUTPUT_SCREEN); - batch = FALSE; - continue; - } - break; -/* - * Open file to write, check for existence - */ - } else if (status[0] == 'c') { - for (;;) { - if ((new_file = fopen(name, "r")) != NULL) { - fclose(new_file); - output_msg(OUTPUT_SCREEN,"Warning: File already exists, %s.\n" - "Enter new file name or to overwrite:", name); - fgets(answer, MAX_LENGTH, stdin); - l = strlen(answer); - answer[l-1]='\0'; - if (answer != '\0') { - strcpy(name, answer); - continue; - } - } - break; - } - if ((new_file = fopen(name, "w")) == NULL) { - sprintf(error_string, "Error opening file, %s.", name) ; - output_msg(OUTPUT_SCREEN,"\nERROR: %s\n", error_string); - output_fflush(OUTPUT_SCREEN); - batch = FALSE; - continue; - } - break; - } - } - strncpy(default_name, name, MAX_LENGTH); - return(new_file); -} -/* ---------------------------------------------------------------------- */ -int copy_use (int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Find mixture - */ - if (use.mix_in == TRUE) { - mix_duplicate(use.n_mix_user, i); - } -/* - * Find solution - */ - if (use.solution_in == TRUE) { - solution_duplicate(use.n_solution_user, i); - } -/* - * Always save solution to i, mixing or not - */ - save.solution = TRUE; - save.n_solution_user = i; - save.n_solution_user_end = i; -/* - * Find pure phase assemblage - */ - if (use.pp_assemblage_in == TRUE) { - pp_assemblage_duplicate(use.n_pp_assemblage_user, i); - save.pp_assemblage = TRUE; - save.n_pp_assemblage_user = i; - save.n_pp_assemblage_user_end = i; - } else { - save.pp_assemblage = FALSE; - } -/* - * Find irrev reaction - */ - if (use.irrev_in == TRUE) { - irrev_duplicate(use.n_irrev_user, i); - save.irrev = TRUE; - save.n_irrev_user = i; - save.n_irrev_user_end = i; - } else { - save.irrev = FALSE; - } -/* - * Find exchange - */ - if (use.exchange_in == TRUE) { - exchange_duplicate(use.n_exchange_user, i); - save.exchange = TRUE; - save.n_exchange_user = i; - save.n_exchange_user_end = i; - } else { - save.exchange = FALSE; - } -/* - * Find kinetics - */ - if (use.kinetics_in == TRUE) { - kinetics_duplicate(use.n_kinetics_user, i); - save.kinetics = TRUE; - save.n_kinetics_user = i; - save.n_kinetics_user_end = i; - } else { - save.kinetics = FALSE; - } -/* - * Find surface - */ - diffuse_layer_x = FALSE; - if (use.surface_in == TRUE) { - surface_duplicate(use.n_surface_user, i); - save.surface = TRUE; - save.n_surface_user = i; - save.n_surface_user_end = i; - } else { - save.surface = FALSE; - } -/* - * Find temperature - */ - if (use.temperature_in == TRUE) { - temperature_duplicate(use.n_temperature_user, i); - } -/* - * Find gas - */ - if (use.gas_phase_in == TRUE) { - gas_phase_duplicate(use.n_gas_phase_user, i); - save.gas_phase = TRUE; - save.n_gas_phase_user = i; - save.n_gas_phase_user_end = i; - } else { - save.gas_phase = FALSE; - } -/* - * Find solid solution - */ - if (use.s_s_assemblage_in == TRUE) { - s_s_assemblage_duplicate(use.n_s_s_assemblage_user, i); - save.s_s_assemblage = TRUE; - save.n_s_s_assemblage_user = i; - save.n_s_s_assemblage_user_end = i; - } else { - save.s_s_assemblage = FALSE; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int step_save_exch(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save solution composition into structure solution with user number - * n_user. - * - * input: n_user is user solution number of target - */ - int i, j, k, n; - int found; - struct exchange *exchange_ptr; -/* - * Malloc space for solution data - */ - if (use.exchange_ptr == NULL) return(OK); - exchange_duplicate(use.exchange_ptr->n_user, n_user); - exchange_ptr = exchange_bsearch(n_user, &n); - for (i=0; i < count_master; i++) { - if (master[i]->s->type != EX) continue; - found = FALSE; - for (j = 0; j < exchange_ptr->count_comps; j++) { - for (k = 0; exchange_ptr->comps[j].totals[k].elt != NULL; k++ ) { - if(exchange_ptr->comps[j].totals[k].elt == master[i]->elt) { - if (found == FALSE) { - found = TRUE; - if (master[i]->total <= MIN_TOTAL) { - exchange_ptr->comps[j].totals[k].coef = MIN_TOTAL; - } else { - exchange_ptr->comps[j].totals[k].coef = master[i]->total; - } - break; - } else { - exchange_ptr->comps[j].totals[k].coef = 0; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int step_save_surf(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save surface for intermediate calculation - * Amt of surface may have changed due to reaction or surface related - * to kinetic reactant. - * - * input: n_user is user solution number of target - */ - int i, j, k, n, m; - struct surface *surface_ptr; -/* - * Malloc space for solution data - */ - if (use.surface_ptr == NULL) return(OK); - surface_duplicate(use.surface_ptr->n_user, n_user); - surface_ptr = surface_bsearch(n_user, &n); - for (i=0; i < count_master; i++) { - if (master[i]->s->type != SURF) continue; - for (j = 0; j < surface_ptr->count_comps; j++) { - for (k = 0; surface_ptr->comps[j].totals[k].elt != NULL; k++ ) { - if(surface_ptr->comps[j].totals[k].elt == master[i]->elt) { - if (master[i]->total <= MIN_TOTAL) { - surface_ptr->comps[j].totals[k].coef = MIN_TOTAL; - } else { - surface_ptr->comps[j].totals[k].coef = master[i]->total; - } - break; - } - } - } - } - /* - * Update grams - */ - if (surface_ptr->edl == TRUE && surface_ptr->related_rate == TRUE && use.kinetics_ptr != NULL) { - for (j = 0; j < surface_ptr->count_comps; j++) { - if (surface_ptr->comps[j].rate_name != NULL) { - for (m = 0; m < use.kinetics_ptr->count_comps; m++) { - if (strcmp_nocase(use.kinetics_ptr->comps[m].rate_name, surface_ptr->comps[j].rate_name) != 0) continue; - surface_ptr->charge[surface_ptr->comps[j].charge].grams = use.kinetics_ptr->comps[m].m; - break; - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int copy_entities(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, n, return_value; - return_value = OK; - if (copy_solution.count > 0) { - for (j = 0; j < copy_solution.count; j++) { - if (solution_bsearch(copy_solution.n_user[j], &n, FALSE) != NULL) { - for (i = copy_solution.start[j]; i <= copy_solution.end[j]; i++) { - if (i == copy_solution.n_user[j]) continue; - solution_duplicate(copy_solution.n_user[j], i); - } - } else { - warning_msg("SOLUTION to copy not found."); - return_value = ERROR; - } - } - } - if (copy_pp_assemblage.count > 0) { - for (j = 0; j < copy_pp_assemblage.count; j++) { - if (pp_assemblage_bsearch(copy_pp_assemblage.n_user[j], &n) != NULL) { - for (i = copy_pp_assemblage.start[j]; i <= copy_pp_assemblage.end[j]; i++) { - if (i == copy_pp_assemblage.n_user[j]) continue; - pp_assemblage_duplicate(copy_pp_assemblage.n_user[j], i); - } - } else { - warning_msg("EQUILIBRIUM_PHASES to copy not found."); - return_value = ERROR; - } - } - } - if (copy_irrev.count > 0) { - for (j = 0; j < copy_irrev.count; j++) { - if (irrev_bsearch(copy_irrev.n_user[j], &n) != NULL) { - for (i = copy_irrev.start[j]; i <= copy_irrev.end[j]; i++) { - if (i == copy_irrev.n_user[j]) continue; - irrev_duplicate(copy_irrev.n_user[j], i); - } - } else { - warning_msg("REACTION to copy not found."); - return_value = ERROR; - } - } - } - if (copy_mix.count > 0) { - for (j = 0; j < copy_mix.count; j++) { - if (mix_bsearch(copy_mix.n_user[j], &n) != NULL) { - for (i = copy_mix.start[j]; i <= copy_mix.end[j]; i++) { - if (i == copy_mix.n_user[j]) continue; - mix_duplicate(copy_mix.n_user[j], i); - } - } else { - warning_msg("MIX to copy not found."); - return_value = ERROR; - } - } - } - if (copy_exchange.count > 0) { - for (j = 0; j < copy_exchange.count; j++) { - if (exchange_bsearch(copy_exchange.n_user[j], &n) != NULL) { - for (i = copy_exchange.start[j]; i <= copy_exchange.end[j]; i++) { - if (i == copy_exchange.n_user[j]) continue; - exchange_duplicate(copy_exchange.n_user[j], i); - } - } else { - warning_msg("EXCHANGE to copy not found."); - return_value = ERROR; - } - } - } - if (copy_surface.count > 0) { - for (j = 0; j < copy_surface.count; j++) { - if (surface_bsearch(copy_surface.n_user[j], &n) != NULL) { - for (i = copy_surface.start[j]; i <= copy_surface.end[j]; i++) { - if (i == copy_surface.n_user[j]) continue; - surface_duplicate(copy_surface.n_user[j], i); - } - } else { - warning_msg("SURFACE to copy not found."); - return_value = ERROR; - } - } - } - if (copy_temperature.count > 0) { - for (j = 0; j < copy_temperature.count; j++) { - if (temperature_bsearch(copy_temperature.n_user[j], &n) != NULL) { - for (i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++) { - if (i == copy_temperature.n_user[j]) continue; - temperature_duplicate(copy_temperature.n_user[j], i); - } - } else { - warning_msg("TEMPERATURE to copy not found."); - return_value = ERROR; - } - } - } - if (copy_gas_phase.count > 0) { - for (j = 0; j < copy_gas_phase.count; j++) { - if (gas_phase_bsearch(copy_gas_phase.n_user[j], &n) != NULL) { - for (i = copy_gas_phase.start[j]; i <= copy_gas_phase.end[j]; i++) { - if (i == copy_gas_phase.n_user[j]) continue; - gas_phase_duplicate(copy_gas_phase.n_user[j], i); - } - } else { - warning_msg("GAS_PHASE to copy not found."); - return_value = ERROR; - } - } - } - if (copy_kinetics.count > 0) { - for (j = 0; j < copy_kinetics.count; j++) { - if (kinetics_bsearch(copy_kinetics.n_user[j], &n) != NULL) { - for (i = copy_kinetics.start[j]; i <= copy_kinetics.end[j]; i++) { - if (i == copy_kinetics.n_user[j]) continue; - kinetics_duplicate(copy_kinetics.n_user[j], i); - } - } else { - warning_msg("KINETICS to copy not found."); - return_value = ERROR; - } - } - } - if (copy_s_s_assemblage.count > 0) { - for (j = 0; j < copy_s_s_assemblage.count; j++) { - if (s_s_assemblage_bsearch(copy_s_s_assemblage.n_user[j], &n) != NULL) { - for (i = copy_s_s_assemblage.start[j]; i <= copy_s_s_assemblage.end[j]; i++) { - if (i == copy_s_s_assemblage.n_user[j]) continue; - s_s_assemblage_duplicate(copy_s_s_assemblage.n_user[j], i); - } - } else { - warning_msg("SOLID_SOLUTIONS to copy not found."); - return_value = ERROR; - } - } - } - copy_solution.count = 0; - copy_pp_assemblage.count = 0; - copy_exchange.count = 0; - copy_surface.count = 0; - copy_s_s_assemblage.count = 0; - copy_gas_phase.count = 0; - copy_kinetics.count = 0; - copy_mix.count = 0; - copy_irrev.count = 0; - copy_temperature.count = 0; - new_copy = FALSE; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_database(PFN_READ_CALLBACK pfn, void *cookie) -/* ---------------------------------------------------------------------- */ -{ - int errors; - simulation = 0; - -/* - * Prepare error handling - */ - errors = setjmp(mark); - if (errors != 0) { - return errors; - } - - set_read_callback(pfn, cookie, TRUE); - dup_print("Reading data base.", TRUE); - read_input(); - tidy_model(); - status(0, NULL); - return 0; -} -/* ---------------------------------------------------------------------- */ -int run_simulations(PFN_READ_CALLBACK pfn, void *cookie) -/* ---------------------------------------------------------------------- */ -{ - int errors; - char token[MAX_LENGTH]; - -/* - * Prepare error handling - */ - errors = setjmp(mark); - if (errors != 0) { - return errors; - } - - set_read_callback(pfn, cookie, FALSE); - -/* - * Read input data for simulation - */ - for (simulation = 1; ; simulation++) { - -#ifdef PHREEQ98 - AddSeries = !connect_simulations; -#endif - sprintf(token, "Reading input data for simulation %d.", simulation); - - output_msg(OUTPUT_GUI_ERROR, "\nSimulation %d\n", simulation); - - dup_print(token, TRUE); - if (read_input() == EOF) break; - - if (title_x != NULL) { - sprintf(token, "TITLE"); - dup_print(token, TRUE); - if (pr.headings == TRUE) output_msg(OUTPUT_MESSAGE,"%s\n\n", title_x); - } - tidy_model(); - test_classes(); - -#ifdef PHREEQ98 - if (!phreeq98_debug) { -#endif - -/* - * Calculate distribution of species for initial solutions - */ - if (new_solution) initial_solutions(TRUE); -/* - * Calculate distribution for exchangers - */ - if (new_exchange) initial_exchangers(TRUE); -/* - * Calculate distribution for surfaces - */ - if (new_surface) initial_surfaces(TRUE); -/* - * Calculate initial gas composition - */ - if (new_gas_phase) initial_gas_phases(TRUE); -/* - * Calculate reactions - */ - reactions(); -/* - * Calculate inverse models - */ - inverse_models(); -/* - * Calculate advection - */ - if (use.advect_in == TRUE) { - dup_print ("Beginning of advection calculations.", TRUE); - advection(); - } -/* - * Calculate transport - */ - if (use.trans_in == TRUE) { - dup_print ("Beginning of transport calculations.", TRUE); - transport(); - } -/* - * Copy - */ - if (new_copy) copy_entities(); -/* - * End of simulation - */ - dup_print( "End of simulation.", TRUE); -#ifdef PHREEQ98 - } /* if (!phreeq98_debug) */ -#endif - #ifdef SKIP - -{ - int n; - SAX_StartSystem(); - for (n = 0; n < count_solution; ++n) - { - SAX_AddSolution(solution[n]); - } - SAX_EndSystem(); - SAX_UnpackSolutions(SAX_GetXMLStr(), SAX_GetXMLLength()); - } - #endif - - } - - - return 0; -} -/* ---------------------------------------------------------------------- */ -int do_initialize(void) -/* ---------------------------------------------------------------------- */ -{ - int errors; -/* - * Prepare error handling - */ - errors = setjmp(mark); - if (errors != 0) { - return errors; - } - - state = INITIALIZE; - initialize(); - - return 0; -} -/* ---------------------------------------------------------------------- */ -int do_status(void) -/* ---------------------------------------------------------------------- */ -{ - int errors; -/* - * Prepare error handling - */ - errors = setjmp(mark); - if (errors != 0) { - return errors; - } - - if (pr.status == TRUE) { -#if defined(PHREEQCI_GUI) - state = -1; - status(0, "\r\nDone."); -#else - status(0, "\nDone."); -#endif - output_msg(OUTPUT_SCREEN,"\n"); - output_msg(OUTPUT_SEND_MESSAGE,"\r\n"); - } - dup_print ("End of run.", TRUE); - output_msg(OUTPUT_SCREEN,"\nEnd of Run.\n"); - output_msg(OUTPUT_SEND_MESSAGE,"\r\nEnd of Run.\r\n"); - - return 0; -} diff --git a/model.cpp b/model.cpp deleted file mode 100644 index 6c0d19b4..00000000 --- a/model.cpp +++ /dev/null @@ -1,3102 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: model.c 632 2005-11-08 17:59:00Z dlpark $"; - -static LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); -static LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); -static LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); - -#ifdef SKIP -static int adjust_step_size(void); -#endif - -/*#define SLNQ*/ - -#ifdef SLNQ -static int add_trivial_eqns(int rows, int cols, LDBLE *matrix); -extern int slnq (int n, LDBLE *a, LDBLE *delta, int ncols, int print); -#endif - -static int calc_gas_pressures(void); -static int calc_s_s_fractions(void); -static int gammas (LDBLE mu); -static int initial_guesses(void); -static int revise_guesses(void); -static int s_s_binary(struct s_s *s_s_ptr); -static int s_s_ideal(struct s_s *s_s_ptr); - -static int remove_unstable_phases; -static int gas_in; - -LDBLE min_value = 1e-10; - - -/* ---------------------------------------------------------------------- */ -int model(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * model is called after the equations have been set up by prep - * and initial guesses have been made in set. - * - * Here is the outline of the calculation sequence: - * residuals--residuals are calculated, if small we are done - * sum_jacobian--jacobian is calculated - * ineq--inequality solver is called - * reset--estimates of unknowns revised, if changes are small solution - * has been found, usually convergence is found in residuals. - * gammas--new activity coefficients - * molalities--calculate molalities - * mb_sums--calculate mass-balance sums - * mb_gases--decide if gas_phase exists - * mb_s_s--decide if solid_solutions exists - * switch_bases--check to see if new basis species is needed - * reprep--rewrite equations with new basis species if needed - * revise_guesses--revise unknowns to get initial mole balance - * check_residuals--check convergence one last time - * sum_species--calculate sums of elements from species concentrations - * - * An additional pass through may be needed if unstable phases still exist - * in the phase assemblage. - */ - int kode, return_kode; - int r; - int count_infeasible, count_basis_change; - int debug_model_save; - int mass_water_switch_save; - if (svnid == NULL) fprintf(stderr," "); - -/* debug_model = TRUE; */ -/* debug_prep = TRUE; */ -/* debug_set = TRUE; */ - /* mass_water_switch == TRUE, mass of water is constant */ - if (pitzer_model == TRUE) return model_pz(); - mass_water_switch_save = mass_water_switch; - if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) { - mass_water_switch = TRUE; - } - debug_model_save = debug_model; - pe_step_size_now = pe_step_size; - step_size_now = step_size; - status(0, NULL); - iterations=0; - count_basis_change = count_infeasible = 0; - stop_program = FALSE; - remove_unstable_phases = FALSE; - for (; ; ) { - mb_gases(); - mb_s_s(); - kode = 1; - while ( ( r = residuals() ) != CONVERGED || remove_unstable_phases == TRUE) { -#if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill*/, 0) == WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } -#endif - iterations++; - if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { - set_forward_output_to_log(TRUE); - debug_model = TRUE; - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nIteration %d\tStep_size = %f\n", - iterations, (double) step_size_now); - output_msg(OUTPUT_MESSAGE,"\t\tPe_step_size = %f\n\n", (double) pe_step_size_now); - } -/* - * Iterations exceeded - */ - if (iterations > itmax ) { - sprintf(error_string,"Maximum iterations exceeded, %d\n",itmax); - warning_msg(error_string); - stop_program = TRUE; - break; - } -/* - * Calculate jacobian - */ - jacobian_sums(); -/* - * Full matrix with pure phases - */ - if ( r == OK || remove_unstable_phases == TRUE) { - return_kode = ineq(kode); - if ( return_kode != OK ) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "Ineq had infeasible solution, " - "kode %d, iteration %d\n", - return_kode, iterations); - } - output_msg(OUTPUT_LOG, "Ineq had infeasible solution, " - "kode %d, iteration %d\n", return_kode, iterations); - count_infeasible++; - } - if ( return_kode == 2 ) { - ineq(0); - } - reset(); - } - gammas(mu_x); - if (molalities(FALSE) == ERROR) { - revise_guesses(); -/* adjust_step_size(); */ - } - if(use.surface_ptr != NULL && - use.surface_ptr->diffuse_layer == TRUE && - use.surface_ptr->related_phases == TRUE) - initial_surface_water(); - mb_sums(); - mb_gases(); - mb_s_s(); -/* - * Switch bases if necessary - */ - - if (switch_bases() == TRUE ) { - count_basis_change++; - reprep(); - gammas(mu_x); - molalities(TRUE); - if(use.surface_ptr != NULL && - use.surface_ptr->diffuse_layer == TRUE && - use.surface_ptr->related_phases == TRUE) - initial_surface_water(); - revise_guesses(); - mb_sums(); - mb_gases(); - mb_s_s(); - } -/* debug - species_list_sort(); - sum_species(); - print_species(); - print_exchange(); - print_surface(); - */ - if (stop_program == TRUE) { - break; - } - } -/* - * Check for stop_program - */ - - if (stop_program == TRUE) { - break; - } - if (check_residuals() == ERROR) { - stop_program = TRUE; - break; - } - if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE && - mass_water_switch == TRUE) { - output_msg(OUTPUT_LOG,"\nChanging water switch to FALSE. Iteration %d.\n", iterations); - mass_water_switch = FALSE; - continue; - } - if (remove_unstable_phases == FALSE) break; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nRemoving unstable phases. Iteration %d.\n", iterations); - } - output_msg(OUTPUT_LOG,"\nRemoving unstable phases. Iteration %d.\n", iterations); - } - output_msg(OUTPUT_LOG,"\nNumber of infeasible solutions: %d\n",count_infeasible); - output_msg(OUTPUT_LOG,"Number of basis changes: %d\n\n",count_basis_change); - output_msg(OUTPUT_LOG,"Number of iterations: %d\n\n", iterations); - debug_model = debug_model_save; - set_forward_output_to_log(FALSE); - if (stop_program == TRUE) { - return(ERROR); - } - return(OK); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int adjust_step_size(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Step sizes are cut down if overflow occurs in molalities - */ - pe_step_size_now -= (pe_step_size_now - 1.0) / 2.0; - step_size_now -= (step_size_now - 1.) / 2.0; - if (pe_step_size_now < 1.5) pe_step_size_now = 1.5; - if (step_size_now < 1.5) step_size_now = 1.5; - output_msg(OUTPUT_LOG,"\tNew step sizes: %f\t%f\t%d\n", - step_size_now, pe_step_size_now, iterations); - return(OK); -} -#endif -/* ---------------------------------------------------------------------- */ -int check_residuals(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks for convergence of all equations, prints any nonconvergence - * Sets variable remove_unstable_phases if a phase is present, - * but undersaturated (i.e. aragonite in calcite-saturated solution). - */ - int i, return_value; - LDBLE epsilon; -#ifdef SKIP - if (punch.high_precision == FALSE) - epsilon = 1e-8; - else - epsilon = 1.e-12; -#endif - epsilon = convergence_tolerance; - - return_value = OK; - if (stop_program == TRUE) { - warning_msg("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:"); - /*error_msg("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:", CONTINUE);*/ - } - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == MB || x[i]->type == ALK) { - if ( fabs(residual[i]) >= epsilon*x[i]->moles && x[i]->moles > MIN_TOTAL /* || stop_program == TRUE */) { -#ifdef SKIP - if ( fabs(residual[i]) >= epsilon*x[i]->moles /* || stop_program == TRUE */) { -#endif - sprintf(error_string,"%20s has not converged. Total: %e\tCalculated: " - "%e\tResidual: %e\n", x[i]->description, (double) x[i]->moles, - (double) x[i]->f, (double) residual[i]); - error_msg(error_string, CONTINUE); - if (x[i]->type == ALK) { - error_msg("Is non-carbonate alkalinity " - "greater than total alkalinity?\n", CONTINUE); - } - return_value = ERROR; - } - } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - if (fabs (residual[i]) >= epsilon /* || stop_program == TRUE */) { - sprintf(error_string,"%20s solution phase boundary has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == CB) { - if (fabs (residual[i]) >= epsilon * mu_x *mass_water_aq_x /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Charge balance has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == MU && pitzer_model == FALSE) { - if (fabs (residual[i]) >= epsilon * mu_x * mass_water_aq_x /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Ionic strength has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == AH2O && pitzer_model == FALSE) { - if (fabs (residual[i]) >= epsilon /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Activity of water has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == MH && pitzer_model == FALSE) { -#define COMBINE - /*#define COMBINE_CHARGE*/ -#ifdef COMBINE -#ifndef COMBINE_CHARGE - if (fabs(residual[i]) > epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles)) -#else - if (fabs(residual[i]) > epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles + charge_balance_unknown->moles)) -#endif -#else - if (fabs (residual[i]) >= epsilon * x[i]->moles /* || stop_program == TRUE */) -#endif - { - sprintf(error_string,"%20s Mass of hydrogen has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == MH2O) { - if (mass_water_switch == TRUE) continue; - if (fabs (residual[i]) >= 0.01 * epsilon * x[i]->moles /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Mass of oxygen has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == PP) { - if (x[i]->pure_phase->add_formula == NULL) { - if (x[i]->dissolve_only == TRUE) { - if ((residual[i] > epsilon && x[i]->moles > 0.0) || ((residual[i] < -epsilon && (x[i]->pure_phase->initial_moles - x[i]->moles) > 0))) { - output_msg(OUTPUT_LOG,"%20s Dissolve_only pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); - } - } else { - if ((residual[i] >= epsilon && x[i]->moles > 0.0) /* || stop_program == TRUE */) { - remove_unstable_phases = TRUE; - output_msg(OUTPUT_LOG,"%20s Pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); - } else if (residual[i] <= -epsilon ) { - sprintf(error_string,"%20s Pure phase has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } - } else { - if ((fabs(residual[i]) >= epsilon && x[i]->moles > 0.0) /* || stop_program == TRUE */) { - output_msg(OUTPUT_LOG,"%s, Pure phase has not converged. \tResidual: %e\n", x[i]->description, (double) residual[i]); - sprintf(error_string,"%s, Pure phase with add formula has not converged.\n\t SI may be a local minimum." - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - warning_msg(error_string); - } - } - } else if (x[i]->type == EXCH) { - if (/* stop_program == TRUE || */ - (x[i]->moles <= MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) || - (x[i]->moles > MIN_RELATED_SURFACE && (fabs(residual[i]) > epsilon * x[i]->moles))) { - sprintf(error_string,"%20s Exchanger mass balance has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == SURFACE) { - if (/* stop_program == TRUE || */ - (x[i]->moles <= MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) || - (x[i]->moles > MIN_RELATED_SURFACE && (fabs(residual[i]) > epsilon * x[i]->moles))) { - sprintf(error_string,"%20s Surface mass balance has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == SURFACE_CB) { - if ((x[i]->surface_charge->grams > MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Surface charge/potential has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == GAS_MOLES) { - if (gas_in == FALSE) continue; - if (residual[i] >= epsilon || residual[i] <= -epsilon /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Total moles in gas phase has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } else if (x[i]->type == PITZER_GAMMA) { - if (fabs(residual[i]) > epsilon ) { - sprintf(error_string,"%20s log gamma not converged.\tResidual: %e\n", x[i]->description, (double) residual[i]); - } - } else if (x[i]->type == S_S_MOLES) { - if (x[i]->s_s_in == FALSE) continue; - if (residual[i] >= epsilon || residual[i] <= -epsilon /* || stop_program == TRUE */) { - sprintf(error_string,"%20s Total moles in solid solution has not converged. " - "\tResidual: %e\n", x[i]->description, (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } - } - if (remove_unstable_phases == TRUE) { - output_msg(OUTPUT_LOG, "%20sRemoving unstable phases, iteration %d."," ", iterations); - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int gammas (LDBLE mu) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates gammas and [moles * d(ln gamma)/d mu] for all aqueous - * species. - */ - int i, j; - int ifirst, ilast; - LDBLE f, a_llnl, b_llnl, bdot_llnl, log_g_co2, dln_g_co2, c2_llnl; - LDBLE s1, s2, s3; - LDBLE c1, c2, a, b; - LDBLE muhalf; - /* Initialize */ - if (pitzer_model == TRUE) return gammas_pz(); - a_llnl = b_llnl = bdot_llnl = log_g_co2 = dln_g_co2 = c2_llnl = 0; -/* - * compute temperature dependence of a and b for debye-huckel - */ - s1=374.11-tc_x; - s2=pow(s1,1.0/3.0); - s3=1.0+0.1342489*s2-3.946263e-03*s1; - s3=s3/(3.1975-0.3151548*s2-1.203374e-03*s1+7.48908e-13*(s1*s1*s1*s1)); - s3=sqrt(s3); - if (tk_x >= 373.15) { - c1=5321.0/tk_x+233.76-tk_x*(tk_x*(8.292e-07*tk_x-1.417e-03)+0.9297); - } else { - /* replaced by wateq4f expression - c1=87.74-tc_x*(tc_x*(1.41e-06*tc_x-9.398e-04)+0.4008); - */ - c1 = 2727.586+0.6224107*tk_x-466.9151*log(tk_x)-52000.87/tk_x; - } - c1=sqrt(c1*tk_x); - /* replaced by wateq4f expressions - a=1824600.0*s3/(c1 * c1 * c1); - b=50.29*s3/c1; - */ - a = 1824827.7 * s3 / (c1 * c1 * c1); - b = 50.2905 * s3 / c1; - /* - * LLNL temperature dependence - */ - if (llnl_count_temp > 0) { - ifirst = 0; - ilast = llnl_count_temp; - if (tc_x < llnl_temp[0] || tc_x > llnl_temp[llnl_count_temp - 1]) { - error_msg("Temperature out of range of LLNL_AQUEOUS_MODEL parameters", STOP); - } - for (i = 0; i < llnl_count_temp; i++) { - if (tc_x >= llnl_temp[i]) ifirst = i; - if (tc_x <= llnl_temp[i]) { - ilast = i; - break; - } - } - if (ilast == ifirst) { - f = 1; - } else { - f = (tc_x - llnl_temp[ifirst])/(llnl_temp[ilast] - llnl_temp[ifirst]); - } - a_llnl = (1 - f)*llnl_adh[ifirst] + f*llnl_adh[ilast]; - b_llnl = (1 - f)*llnl_bdh[ifirst] + f*llnl_bdh[ilast]; - bdot_llnl = (1 - f)*llnl_bdot[ifirst] + f*llnl_bdot[ilast]; - /* - * CO2 activity coefficient - */ - log_g_co2 = (llnl_co2_coefs[0] + llnl_co2_coefs[1]*tk_x + llnl_co2_coefs[2]/tk_x)*mu - - (llnl_co2_coefs[3] + llnl_co2_coefs[4]*tk_x)*(mu/(mu+1)); - log_g_co2 /= LOG_10; - dln_g_co2 = (llnl_co2_coefs[0] + llnl_co2_coefs[1]*tk_x + llnl_co2_coefs[2]/tk_x) - - (llnl_co2_coefs[3] + llnl_co2_coefs[4]*tk_x)*(1/((mu+1)*(mu+1))); - } - -/* - * constants for equations - */ - muhalf = sqrt(mu); - c1=(-a)*LOG_10*(1.0/(2*muhalf*(muhalf+1.0)*(muhalf+1.0))-0.3); - c2=-a/(2*muhalf); - if (llnl_count_temp > 0) { - c2_llnl = -a_llnl/(2*muhalf); - } - -/* - * Calculate activity coefficients - */ - for (i=0; i < count_s_x; i++) { - switch (s_x[i]->gflag) { - case 0: /* uncharged */ - s_x[i]->lg = s_x[i]->dhb * mu; - s_x[i]->dg = s_x[i]->dhb * LOG_10 * s_x[i]->moles; - break; - case 1: /* Davies */ - s_x[i]->lg = - s_x[i]->z * s_x[i]->z * a * - ( muhalf / (1.0 + muhalf) - 0.3 * mu); - s_x[i]->dg = c1 * s_x[i]->z * s_x[i]->z * s_x[i]->moles; - break; - case 2: /* Extended D-H, WATEQ D-H */ - s_x[i]->lg = -a * muhalf * s_x[i]->z * s_x[i]->z / - (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu; - s_x[i]->dg = (c2 * s_x[i]->z * s_x[i]->z / - ((1.0 + s_x[i]->dha * b * muhalf)*(1.0 + s_x[i]->dha * b * muhalf)) + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; -/* if (mu_x < 1e-6) s_x[i]->dg = 0.0; */ - break; - case 3: /* Always 1.0 */ - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - break; - case 4: /* Exchange */ -/* - * Find CEC - * z contains valence of cation for exchange species, alk contains cec - */ -/* !!!!! */ - for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { - if (s_x[i]->rxn_x->token[j].s->type == EX) { - s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; - break; - } - } - if (s_x[i]->exch_gflag == 1 && s_x[i]->alk > 0) { - /* Davies */ - s_x[i]->lg = - s_x[i]->equiv * s_x[i]->equiv * a * - ( muhalf / (1.0 + muhalf) - 0.3 * mu) + - log10(fabs(s_x[i]->equiv)/s_x[i]->alk); - s_x[i]->dg = c1 * s_x[i]->equiv * s_x[i]->equiv * s_x[i]->moles; - } else if (s_x[i]->exch_gflag == 2 && s_x[i]->alk > 0) { - /* Extended D-H, WATEQ D-H */ - s_x[i]->lg = -a * muhalf * s_x[i]->equiv * s_x[i]->equiv / - (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu + - log10(fabs(s_x[i]->equiv)/s_x[i]->alk); - s_x[i]->dg = (c2 * s_x[i]->equiv * s_x[i]->equiv / - ((1.0 + s_x[i]->dha * b * muhalf)*(1.0 + s_x[i]->dha * b * muhalf)) + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; - } else if (s_x[i]->exch_gflag == 7 && s_x[i]->alk > 0) { - if (llnl_count_temp >0 ) { - s_x[i]->lg = -a_llnl * muhalf * s_x[i]->equiv * s_x[i]->equiv / (1.0 + s_x[i]->dha * b_llnl * muhalf) + bdot_llnl * mu + log10(fabs(s_x[i]->equiv)/s_x[i]->alk); - s_x[i]->dg = (c2_llnl * s_x[i]->equiv * s_x[i]->equiv / ((1.0 + s_x[i]->dha * b_llnl * muhalf)*(1.0 + s_x[i]->dha * b_llnl * muhalf)) + bdot_llnl) * LOG_10 * s_x[i]->moles; - } else { - error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); - } - } else { -/* - * Master species is a dummy variable with meaningless activity and mass - */ - if (s_x[i]->primary != NULL) { - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - } else { - if (s_x[i]->alk <= 0) { - s_x[i]->lg = 0.0; - } else { - s_x[i]->lg = log10(fabs(s_x[i]->equiv)/s_x[i]->alk); - } - s_x[i]->dg = 0.0; - } - } - break; - case 5: /* Always 1.0 */ - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - break; - case 6: /* Surface */ -/* - * Find moles of sites. - * s_x[i]->equiv is stoichiometric coefficient of sites in species - */ - for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { - if (s_x[i]->rxn_x->token[j].s->type == SURF) { - s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; - break; - } - } - if (s_x[i]->alk > 0) { - s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); - s_x[i]->dg = 0.0; - } else { - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - } - break; - case 7: /* LLNL */ - if (llnl_count_temp >0 ) { - if (s_x[i]->z == 0) { - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - } else { - s_x[i]->lg = -a_llnl * muhalf * s_x[i]->z * s_x[i]->z / - (1.0 + s_x[i]->dha * b_llnl * muhalf) + bdot_llnl * mu; - s_x[i]->dg = (c2_llnl * s_x[i]->z * s_x[i]->z / ((1.0 + s_x[i]->dha * b_llnl * muhalf)*(1.0 + s_x[i]->dha * b_llnl * muhalf)) + bdot_llnl) * LOG_10 * s_x[i]->moles; - break; - } - } else { - error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); - } - break; - case 8: /* LLNL CO2*/ - if (llnl_count_temp > 0) { - s_x[i]->lg = log_g_co2; - s_x[i]->dg = dln_g_co2 * s_x[i]->moles; - } else { - error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); - } - break; - case 9: /* activity water */ - s_x[i]->lg = log10(exp( s_h2o->la * LOG_10) * gfw_water); - s_x[i]->dg = 0.0; - break; - } -/* - if (mu_unknown != NULL) { - if (fabs(residual[mu_unknown->number]) > 0.1 && - fabs(residual[mu_unknown->number])/mu_x > 0.5) { - s_x[i]->dg = 0.0; - } - } - */ - } - return(OK); -} -/* ------------------------------------------------------------------------------- */ -int ineq(int in_kode) -/* ------------------------------------------------------------------------------- */ -{ -/* - * Sets up equations and inequalities for Cl1. - * Scales columns if necessary. - * Eliminates equations that are not necessary because - * gas_phase, s_s, or phase equation is not needed - * Mallocs space - * Calls Cl1 - * Rescales results if necessary - */ - int i, j; - int return_code; - int *back; - int count_rows; - int count_optimize, count_equal; - extern int max_row_count, max_column_count; - int k, l, m, n; - int klmd, nklmd, n2d; - int iter; - LDBLE error; - LDBLE *ineq_array, *res, *cu; - LDBLE *zero, *delta1; - int *iu, *is; - LDBLE *normal; - LDBLE max; - int kode; -#ifdef SKIP - LDBLE *save_row; -#endif - LDBLE min; -#ifdef SLNQ - LDBLE *slnq_array; - LDBLE *slnq_delta1; -#endif -/* Debug - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "\narray:\n\n"); - array_print(array, count_unknowns, count_unknowns + 1, count_unknowns + 1); - } - */ -/* - * Special case for removing unstable phases - */ - if ( remove_unstable_phases == TRUE ) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nSolution vector for removing unstable phases:\n"); - } - for (i=0; i< count_unknowns; i++) { - if (x[i]->type == PP && residual[i] > 0e-8 && x[i]->moles > 0 && - x[i]->pure_phase->add_formula == NULL && x[i]->dissolve_only == FALSE) { -/* - * Set mass transfer to all of phase - */ - delta[i] = x[i]->moles; - } else { - delta[i] = 0.0; - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, - x[i]->description, (double) delta[i]); - } - } - remove_unstable_phases = FALSE; - return(OK); - } -/* - * Pitzer model does not have activity of water or mu - */ - if (pitzer_model == TRUE) { - for (i=0; i < count_unknowns; i++) { - if ( (x[i]->type == AH2O && full_pitzer == FALSE) || - x[i]->type == MH || - x[i]->type == MU || - (x[i]->type == PITZER_GAMMA && full_pitzer == FALSE)) { - for (j=0; jtype == MB || x[i]->type == ALK || x[i]->type == EXCH || x[i]->type == SURFACE || x[i]->type == SURFACE_CB) { -/* !!!! */ if ( x[i]->moles <= MIN_RELATED_SURFACE && (x[i]->type == EXCH || x[i]->type == SURFACE)) continue; - for (j = 0; j < count_unknowns; j++) { - if (x[i]->type == SURFACE && x[j]->type == SURFACE_CB ) continue; - - if (fabs(array[j *(count_unknowns + 1) + i]) > max) { - max = fabs(array[j * (count_unknowns + 1) + i]); - if (max > min_value) break; - } - } - if (diagonal_scale == TRUE) { - if (fabs(array[i *(count_unknowns + 1) + i]) < min_value) { - max = fabs(array[i * (count_unknowns + 1) + i]); - } - } - - if (max == 0) { - array[i *(count_unknowns + 1) + i] = 1e-5*x[i]->moles; - max = fabs(1e-5*x[i]->moles); - } - } - - if (x[i]->type == MH && pitzer_model == FALSE) { - /* make absolute value of diagonal at least 1e-12 */ - - min = 1e-12; - min = MIN_TOTAL; - array[x[i]->number * (count_unknowns + 1) + x[i]->number] += min; - if (fabs(array[x[i]->number * (count_unknowns + 1) + x[i]->number]) < min) - array[x[i]->number * (count_unknowns + 1) + x[i]->number] = min; - max = 0.0; - - for (j=0; jtype != MB && - x[j]->type != SURFACE && - x[j]->type != SURFACE_CB && - x[j]->type != EXCH && - x[j]->type != MH && - x[j]->type != MH2O) continue; - if (fabs(array[j * (count_unknowns + 1) + i]) > max) { - max = fabs(array[j * (count_unknowns + 1) + i]); - if (max > min_value) break; - } - } - } - - if (max > 0.0 && max < min_value) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "Scaling column for %s, max= %e\n", - x[i]->description, (double) max); - } - for (j=0; j < count_unknowns; j++) { - array[j * (count_unknowns + 1) + i] *= min_value / max ; - } - normal[i] = min_value / max; - } - } - -/* - * Allocate arrays for inequality solver - */ - max_row_count = 2*count_unknowns + 2; - max_column_count = count_unknowns + 2; - ineq_array = (LDBLE *) PHRQ_malloc((size_t) max_row_count * max_column_count * - sizeof(LDBLE)); - if (ineq_array == NULL) malloc_error(); - - back = (int *) PHRQ_malloc((size_t) max_row_count * sizeof(int)); - if (back == NULL) malloc_error(); - - zero = (LDBLE *) PHRQ_malloc((size_t) max_row_count*sizeof(LDBLE)); - if (zero == NULL) malloc_error(); - for (i=0; itype == PP ) { - /* not in model, ignore */ - if (x[i]->pure_phase->phase->in == FALSE) continue; - /* Undersaturated and no mass, ignore */ - if (x[i]->f > 0e-8 && x[i]->moles <= 0 && x[i]->pure_phase->add_formula == NULL) { - continue; - } else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { - continue; - } else { - /* Copy in saturation index equation (has mass or supersaturated) */ - memcpy((void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - if (x[i]->pure_phase->add_formula == NULL && x[i]->dissolve_only == FALSE) { - res[count_rows] = 1.0; - } -/* - * If infeasible solution on first attempt, remove constraints on IAP - */ -#ifdef SKIP -#endif - if (pp_scale != 1){ - for (j = 0; j < count_unknowns +1; j++) { - ineq_array[count_rows * max_column_count + j] *= pp_scale; - } - } - - - if (in_kode != 1) { - res[count_rows] = 0.0; - } - count_rows++; - } - } else if (x[i]->type == ALK || - x[i]->type == SOLUTION_PHASE_BOUNDARY ) { -/* - * Alkalinity and solution phase boundary - */ - memcpy((void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - count_rows++; -/* - * Gas phase - */ - } else if (x[i]->type == GAS_MOLES && gas_in == TRUE) { - memcpy((void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - - res[count_rows] = 1.0; - if (in_kode != 1) { - res[count_rows] = 0.0; - } - count_rows++; -/* - * Solid solution - */ - } else if (x[i]->type == S_S_MOLES && x[i]->s_s_in == TRUE) { - memcpy((void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - res[count_rows] = 1.0; - if (in_kode != 1) { - res[count_rows] = 0.0; - } - count_rows++; - } - } - count_optimize = count_rows; -/* - * Copy equality equations into ineq_array - */ - for (i=0; i< count_unknowns; i++) { - if (x[i]->type != SOLUTION_PHASE_BOUNDARY && - x[i]->type != ALK && - x[i]->type != GAS_MOLES && - x[i]->type != S_S_MOLES && - x[i]->type != PP ) { - if(x[i]->type == MH && pitzer_model == TRUE) continue; - if(mass_water_switch == TRUE && x[i] == mass_oxygen_unknown) continue; -/* - * Mass balance, CB, MU, AH2O, MH, MH2O, others - */ - if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) continue; - if (x[i]->type == SURFACE && - x[i]->phase_unknown == NULL && - x[i]->moles <= MIN_RELATED_SURFACE) continue; - if (x[i]->type == SURFACE_CB && - /* x[i-1]->phase_unknown == NULL && */ - /* x[i-1]->moles <= MIN_RELATED_SURFACE) continue; */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) continue; - if (x[i]->type == SURFACE && - x[i]->phase_unknown != NULL && -/* x[i]->phase_unknown->f > 0e-8 && */ - x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && - x[i]->phase_unknown->pure_phase->add_formula == NULL) continue; - if (x[i]->type == SURFACE_CB && - x[i-1]->phase_unknown != NULL && -/* x[i-1]->phase_unknown->f > 0e-8 && */ -/* x[i-1]->phase_unknown->moles <= MIN_RELATED_SURFACE && */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && - x[i-1]->phase_unknown->pure_phase->add_formula == NULL) continue; - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - if(mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown) { - k = mass_oxygen_unknown->number; - for (j = 0; j < count_unknowns; j++) { - ineq_array[count_rows * max_column_count + j] -= 2*array[k * (count_unknowns + 1) + j]; - } - } - count_rows++; - } else if (x[i]->type == PITZER_GAMMA) { - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - } - } - count_equal = count_rows - count_optimize; -/* - * Copy inequality constraints into ineq - */ - if (pure_phase_unknown != NULL) { - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == PP) { - /* not in model, ignore */ - if (x[i]->pure_phase->phase->in == FALSE) continue; - /* No moles and undersaturated, ignore */ - if (x[i]->moles <= 0.0 && x[i]->f > 0e-8 && - x[i]->pure_phase->add_formula == NULL) { - continue; - /* No moles of pure phase present, must precipitate */ - } else if (x[i]->moles <= 0.0 ) { - delta1[i] = -1.0; - } else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { - continue; - } else { - - /* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */ - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(zero[ 0 ]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[count_rows*max_column_count + i] = 1.0; - ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->moles; - back[count_rows] = i; - count_rows++; - } - /* Pure phase is present and dissolve_only, force ppt to be <= amount of dissolved so far */ - if (x[i]->dissolve_only == TRUE) { - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), (void *) &(zero[ 0 ]), (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[count_rows*max_column_count + i] = -1.0; - ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->pure_phase->initial_moles - x[i]->moles; - back[count_rows] = i; - count_rows++; - } - } - } - } -/* - * Add inequality for mass of oxygen greater than zero - */ -#ifdef SKIP -#endif - if (pitzer_model) { - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == MH2O) { - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type < PP) { - ineq_array[count_rows*max_column_count + j] = 0.0; - } else { - /*ineq_array[count_rows*max_column_count + j] = -ineq_array[count_rows*max_column_count + j]; */ - } - } - ineq_array[count_rows*max_column_count + count_unknowns] = 0.5*x[i]->moles; - count_rows++; - } - } - } - - -/* - * Hydrogen mass balance is good - */ -/* - * No moles and undersaturated, mass transfer must be zero - */ - if (pure_phase_unknown != NULL) { - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == PP) { - if ((x[i]->moles <= 0.0 && x[i]->f > 0e-8 && - x[i]->pure_phase->add_formula == NULL) || x[i]->pure_phase->phase->in == FALSE) { - for (j=0; jdissolve_only == TRUE) { - if (x[i]->f < 0e-8 && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) { - for (j=0; jrelated_phases == TRUE || use.exchange_ptr->related_rate == TRUE )) { - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == EXCH && x[i]->moles <= 0) { - for (j=0; jrelated_phases == TRUE || use.surface_ptr->related_rate == TRUE ) ) { - for (i=0; i < count_unknowns; i++) { - if ((x[i]->type == SURFACE && - x[i]->phase_unknown != NULL && -/* x[i]->phase_unknown->f > 0e-8 && */ - x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && - x[i]->phase_unknown->pure_phase->add_formula == NULL) || - (x[i]->type == SURFACE_CB && - x[i-1]->phase_unknown != NULL && -/* x[i-1]->phase_unknown->f > 0e-8 && */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && - x[i-1]->phase_unknown->pure_phase->add_formula == NULL)) { - for (j=0; jtype == SURFACE && - x[i]->phase_unknown == NULL && - x[i]->moles <= MIN_RELATED_SURFACE) || - (x[i]->type == SURFACE_CB && - x[i-1]->phase_unknown == NULL && - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE)) { - for (j=0; j= zero - */ - if (gas_in == TRUE) { - i = gas_unknown->number; - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(zero[ 0 ]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[count_rows*max_column_count + i] = -1.0; - ineq_array[count_rows*max_column_count + count_unknowns ] = x[i]->moles; - back[count_rows] = i; - count_rows++; - } else if (use.gas_phase_ptr != NULL && gas_in == FALSE) { -/* - * Moles of gas small and sum p < ptotal - */ - i = gas_unknown->number; - for (j=0; j= zero - */ - - if (s_s_unknown != NULL) { - for (i = s_s_unknown->number; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) break; - if (x[i]->phase->in == TRUE && x[i]->s_s_in == TRUE) { - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(zero[ 0 ]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[count_rows*max_column_count + i] = 1.0; - ineq_array[count_rows*max_column_count + count_unknowns ] = 0.99*x[i]->moles - MIN_TOTAL; - back[count_rows] = i; - count_rows++; - } else { - for (j=0; jtype == MB && x[i]->moles < 0.0 ) { - memcpy( (void *) &(ineq_array[count_rows*max_column_count]), - (void *) &(array[i*(count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back[count_rows] = i; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type < PP) { - ineq_array[count_rows*max_column_count + j] = 0.0; - } - } - count_rows++; - } - } - } -/* - * Zero column for mass of water - */ - if(mass_oxygen_unknown != NULL && mass_water_switch == TRUE) { - k = mass_oxygen_unknown->number; - for (j = 0; j < count_rows + 1; j++) { - ineq_array[j * max_column_count + k] = 0; - } - } -/* - * Scale column for pure phases - */ - for (i=0; i < count_unknowns; i++) { - if ( (x[i]->type == PP || x[i]->type == S_S_MOLES) && pp_column_scale != 1.0) { - for (j = 0; j < count_rows; j++) { - ineq_array[j* max_column_count + i] *= pp_column_scale; - } - normal[i] = pp_column_scale; - } - - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "\nA and B arrays:\n\n"); - array_print(ineq_array, count_rows, count_unknowns + 1, max_column_count); - } -/* - * Calculate dimensions - */ - k = count_optimize; /* rows in A */ - l = count_equal; /* rows in C */ - m = count_rows - l - k; /* rows in E */ - if (m < 0) m = 0; - - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "k, l, m\t%d\t%d\t%d\n",k, l, m); - } - - n = count_unknowns; /* columns in A, C, E */ - klmd = max_row_count - 2; - nklmd = n+klmd; - n2d = n + 2; -/* - * Retain constraints on mineral mass transfers, even if infeasible on - * first attempt. - */ - kode = 1; - - if (in_kode == 2) { - kode = 1; - } - iter = 200; -/* - * Allocate space for arrays - */ - cu = (LDBLE *) PHRQ_malloc((size_t) 2*nklmd*sizeof(LDBLE)); - if (cu == NULL) malloc_error(); - iu = (int *) PHRQ_malloc((size_t) 2*nklmd*sizeof(int)); - if (iu == NULL) malloc_error(); - is = (int *) PHRQ_malloc((size_t) klmd*sizeof(int)); - if (is == NULL) malloc_error(); -#ifdef SLNQ - slnq_array = (LDBLE *) PHRQ_malloc((size_t) count_unknowns*(count_unknowns+1)*sizeof(LDBLE)); - if (slnq_array == NULL) malloc_error(); - for (i = 0; i < k+l; i++) { - for (j = 0; j <= count_unknowns; j++) { - slnq_array[i*(count_unknowns + 1) + j] = ineq_array[i*max_column_count + j]; - } - } - slnq_delta1 = (LDBLE *) PHRQ_malloc( (size_t) max_column_count * sizeof(LDBLE)); - if (slnq_delta1 == NULL) malloc_error(); - memcpy( (void *) &(slnq_delta1[0]), (void *) &(zero[0]), (size_t) max_column_count * sizeof(LDBLE)); -#endif -/* - * Call CL1 - */ - cl1(k, l, m, n, - nklmd, n2d, ineq_array, - &kode, ineq_tol, &iter, - delta1, res, &error, cu, iu, is, FALSE); - -/* Set return_kode */ - if ( kode == 1) { - return_code = ERROR; - } else if (kode == 2) { - return_code = 2; - } else { - return_code = OK; - } -#ifdef SLNQ -/* if (kode > 0 && ((k + l) == count_unknowns)) { */ - if (kode > 0 && ((k + l) <= count_unknowns)) { - if (add_trivial_eqns(k+l, count_unknowns, slnq_array) == TRUE) { - if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Calling SLNQ, iteration %d\n", iterations); - output_msg(OUTPUT_LOG, "Calling SLNQ, iteration %d\n", iterations); - if (slnq(count_unknowns, slnq_array, slnq_delta1, count_unknowns+1, debug_model) == OK) { - memcpy( (void *) &(delta1[0]), (void *) &(slnq_delta1[0]), - (size_t) count_unknowns * sizeof(LDBLE)); - if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Using SLNQ results.\n"); - output_msg(OUTPUT_LOG, "Using SLNQ results.\n"); - return_code = OK; - } else { - if (debug_model == TRUE) output_msg(OUTPUT_MESSAGE, "Could not use SLNQ results.\n"); - output_msg(OUTPUT_LOG, "Could not use SLNQ results.\n"); - } - } else { - output_msg(OUTPUT_LOG, "Could not call SLNQ, row %d, unknowns %d, iteration %d\n", k+l, count_unknowns, iterations); - } - } else if (kode > 0) { - output_msg(OUTPUT_LOG, "Could not call SLNQ, row %d, unknowns %d\n", k+l, count_unknowns); - } -#endif -/* Copy delta1 into delta and scale */ - - memcpy( (void *) &(delta[0]), (void *) &(delta1[0]), - (size_t) count_unknowns * sizeof(LDBLE)); - for (i = 0; i < count_unknowns; i++) delta[i] *= normal[i]; -/* - * Rescale columns of array - */ - for (i = 0; i < count_unknowns; i++) { - if (normal[i] != 1.0) { - for (j=0; j < count_unknowns; j++) { - array[j * (count_unknowns + 1) + i] /= normal[i]; - } - } - } - -/* - * Debug, write results of ineq - */ - - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "kode: %d\titer: %d\terror: %e\n", kode, iter, (double) error); - output_msg(OUTPUT_MESSAGE, "\nsolution vector:\n"); - for (i=0; i < count_unknowns; i++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e",i, x[i]->description, (double) delta[i]); - if (x[i]->type == PP) { - output_msg(OUTPUT_MESSAGE, " -SI %10.2e Moles %10.2e", (double) x[i]->f, (double) x[i]->moles); - if (x[i]->f < 0e-8 || x[i]->moles > 0.0) { - output_msg(OUTPUT_MESSAGE, " **"); - } - } - output_msg(OUTPUT_MESSAGE, "\n"); - } - - output_msg(OUTPUT_MESSAGE, "\nresidual vector:\n"); - for (i=0; i < count_rows; i++) { - output_msg(OUTPUT_MESSAGE, "%6d %-12.12s %10.2e\n",i, x[back[i]]->description, (double) res[i]); - } - } - normal = (LDBLE *) free_check_null(normal); - ineq_array = (LDBLE *) free_check_null(ineq_array); - back = (int *) free_check_null(back); - zero = (LDBLE *) free_check_null(zero); - res = (LDBLE *) free_check_null(res); - delta1 = (LDBLE *) free_check_null(delta1); - cu = (LDBLE *) free_check_null(cu); - iu = (int *) free_check_null(iu); - is = (int *) free_check_null(is); -#ifdef SLNQ - slnq_array = free_check_null(slnq_array); - slnq_delta1 = free_check_null(slnq_delta1); -#endif - return(return_code); -} -/* ---------------------------------------------------------------------- */ -int jacobian_sums (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fills in jacobian array, uses arrays sum_jacob0, sum_jacob1, and - * sum_jacob2. - */ - int i, j, k; - LDBLE sinh_constant; -/* - * Clear array, note residuals are in array[i, count_unknowns+1] - */ - for (i=0; i < count_unknowns; i++) { - array[i]=0.0; - } - for (i=1; i < count_unknowns; i++) { - memcpy ( (void *) &(array[i*(count_unknowns + 1)]), (void *) &(array[0]), - (size_t) count_unknowns * sizeof(LDBLE)); - } -/* - * Add constant terms - */ - for (k=0; k < count_sum_jacob0; k++) { - *sum_jacob0[k].target += sum_jacob0[k].coef; - } -/* - * Add terms with coefficients of 1.0 - */ - for (k=0; k < count_sum_jacob1; k++) { - *sum_jacob1[k].target += *sum_jacob1[k].source; - } -/* - * Add terms with coefficients != 1.0 - */ - for (k=0; k < count_sum_jacob2; k++) { - *sum_jacob2[k].target += *sum_jacob2[k].source * sum_jacob2[k].coef; - } -/* - * Make final adustments to jacobian array - */ -/* - * Ionic strength - */ - if (mu_unknown != NULL) { - for (i=0; inumber*(count_unknowns+1)+i] *= 0.5; - } - array[mu_unknown->number*(count_unknowns+1)+mu_unknown->number] -= mass_water_aq_x; - } -/* - * Mass of oxygen - */ - if (mass_oxygen_unknown != NULL && mu_unknown != NULL) { - array[mu_unknown->number*(count_unknowns+1)+mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x; - } -/* - * Activity of water - */ - if (ah2o_unknown != NULL) { - for (i=0; inumber*(count_unknowns+1)+i] *= -0.017; - } - array[ah2o_unknown->number*(count_unknowns+1)+ah2o_unknown->number] -= mass_water_aq_x*exp(s_h2o->la * LOG_10); - } - if (mass_oxygen_unknown != NULL && ah2o_unknown != NULL) { - array[ah2o_unknown->number*(count_unknowns+1)+mass_oxygen_unknown->number] -= - (exp(s_h2o->la * LOG_10) - 1) * mass_water_aq_x; - } -/* - * Surface charge balance - */ - if (surface_unknown != NULL && diffuse_layer_x == FALSE) { - sinh_constant = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*tk_x*1000); - for (i=0; itype == SURFACE_CB && x[i]->surface_charge->grams > 0 ) { - for (j=0; j < count_unknowns; j++) { - array[x[i]->number * (count_unknowns + 1) + j] *= - F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams); - } - array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= - sinh_constant * sqrt(mu_x) * cosh(x[i]->master[0]->s->la * LOG_10); - if (mu_unknown != NULL) { - array[x[i]->number * (count_unknowns + 1) + mu_unknown->number] -= - 0.5 * sinh_constant / sqrt(mu_x) * sinh(x[i]->master[0]->s->la * LOG_10); - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_sums (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates sums of species for calculation of mass balances, charge - * balance. Also calculates saturation indices for solution_phase_boundaries - * and pure_phases. After this routine total calcium calculated from all - * calcium species in solution is stored in x[i]->f. Also calculates - * x[i]->sum for some types of unknowns. Uses arrays sum_mb1 and - * sum_mb1, which are generated in prep and reprep. - */ - int k; -/* - * Clear functions in unknowns - */ - for (k=0; k < count_unknowns; k++) { - x[k]->f=0.0; - x[k]->sum=0.0; - } -/* - * Add terms with coefficients of 1.0 - */ - for (k=0; k < count_sum_mb1; k++) { - *sum_mb1[k].target += *sum_mb1[k].source; -/* { k += 1; k -= 1;} */ - } -/* - * Add terms with coefficients != 1.0 - */ - for (k=0; k < count_sum_mb2; k++) { - *sum_mb2[k].target += *sum_mb2[k].source * sum_mb2[k].coef; -/* { k += 1; k -= 1;} */ - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_gases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Determines whether gas_phase equation is needed - */ - gas_in = FALSE; - if (gas_unknown == NULL || use.gas_phase_ptr == NULL) return(OK); - if (use.gas_phase_ptr->type == PRESSURE) { - if (gas_unknown->f > use.gas_phase_ptr->total_p + 1e-7 || - gas_unknown->moles > MIN_TOTAL) { - gas_in = TRUE; - } - } else { - gas_in = FALSE; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_s_s(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE lp, log10_iap, total_moles; - LDBLE iapc, iapb, kc, kb, lc, lb, xcaq, xbaq, xb, xc; - LDBLE sigmapi_aq, sigmapi_solid; - LDBLE total_p; - struct s_s *s_s_ptr; - struct rxn_token *rxn_ptr; - struct phase *phase_ptr; -/* - * Determines whether solid solution equation is needed - */ - if (s_s_unknown == NULL || use.s_s_assemblage_ptr == NULL) return(OK); - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - s_s_ptr = &(use.s_s_assemblage_ptr->s_s[i]); - total_moles = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) { - total_moles += s_s_ptr->comps[j].moles; - } - if (total_moles > 1e-13) { - s_s_ptr->s_s_in = TRUE; - } else if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) { - /* - * Calculate IAPc and IAPb - */ - if (s_s_ptr->comps[0].phase->rxn_x != NULL) { - log10_iap = 0; - for (rxn_ptr = s_s_ptr->comps[0].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - log10_iap += rxn_ptr->s->la * rxn_ptr->coef; - } - iapc = exp(log10_iap * LOG_10); - } else { - iapc = 1e-99; - } - if (s_s_ptr->comps[1].phase->rxn_x != NULL) { - log10_iap = 0; - for (rxn_ptr = s_s_ptr->comps[1].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - log10_iap += rxn_ptr->s->la * rxn_ptr->coef; - } - iapb = exp(log10_iap * LOG_10); - } else { - iapb = 1e-99; - } - /* - * Calculate sigma pi, aq - */ - sigmapi_aq = iapc + iapb; - /* - * Calculate xc,aq and xb, aq - */ - xcaq = iapc/(iapb + iapc); - xbaq = iapb/(iapb + iapc); - /* - * Get Kc and Kb - */ - kc = exp(s_s_ptr->comps[0].phase->lk*LOG_10); - kb = exp(s_s_ptr->comps[1].phase->lk*LOG_10); - /* - * Solve for xb - */ - xb = s_s_root(s_s_ptr->a0, s_s_ptr->a1, kc, kb, xcaq, xbaq); - /* - * Calculate lambdac and lambdab - */ - xc = 1 - xb; - lc = exp((s_s_ptr->a0 - s_s_ptr->a1*(-4*xb + 3))*xb*xb); - lb = exp((s_s_ptr->a0 + s_s_ptr->a1*(4*xb - 3))*xc*xc); - /* - * Calculate sigma pi, solid - */ - sigmapi_solid = xb*lb*kb + xc*lc*kc; - /* - * If Sigma pi, solid < sigma pi, aq, then use eqns - */ - if (sigmapi_solid < sigmapi_aq) { - s_s_ptr->s_s_in = TRUE; - } else { - s_s_ptr->s_s_in = FALSE; - } - } else { - /* - * Calculate total mole fraction from solution activities - */ - total_p = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) { - phase_ptr = s_s_ptr->comps[j].phase; - if (phase_ptr->in == TRUE) { - lp=-phase_ptr->lk; - for (rxn_ptr = s_s_ptr->comps[j].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - total_p += exp(lp * LOG_10); - } - } - if (total_p > 1.0) { - s_s_ptr->s_s_in = TRUE; - } else { - s_s_ptr->s_s_in= FALSE; - } - } - } - for (i = s_s_unknown->number; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) break; - x[i]->s_s_in = x[i]->s_s->s_s_in; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int molalities (int allow_overflow) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates la for master species - * Calculates lm and moles from lk, lg, and la's of master species - * Adjusts lm of h2 and o2. - */ - int i, j, count_g; - LDBLE total_g; - struct rxn_token *rxn_ptr; -/* - * la for master species - */ - for (i=0; i < count_master; i++) { - if (master[i]->in == REWRITE) { - master[i]->s->la = master[i]->s->lm + master[i]->s->lg; - } - } - if (diffuse_layer_x == TRUE) { - s_h2o->tot_g_moles = s_h2o->moles; - s_h2o->tot_dh2o_moles = 0.0; - } - for (i=0; i < count_s_x; i++) { - if (s_x[i]->type > HPLUS && s_x[i]->type != EX && s_x[i]->type != SURF) continue; -/* - * lm and moles for all aqueous species - */ - s_x[i]->lm=s_x[i]->lk - s_x[i]->lg; - for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef; - } - if (s_x[i]->type == EX ) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - } else if (s_x[i]->type == SURF ) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); /* formerly * mass water */ - - } else { - s_x[i]->moles = under (s_x[i]->lm) * mass_water_aq_x; - if (s_x[i]->moles/mass_water_aq_x > 30) { - output_msg(OUTPUT_LOG,"Overflow: %s\t%e\t%e\t%d\n", s_x[i]->name, (double) (s_x[i]->moles/mass_water_aq_x), (double) s_x[i]->lm, iterations); - - if (iterations >= 0 && allow_overflow == FALSE) { - return(ERROR); - } - } - - } -/* - * other terms for diffuse layer model - */ - if (use.surface_ptr != NULL && diffuse_layer_x == TRUE && s_x[i]->type <= HPLUS) { - total_g = 0.0; - s_x[i]->tot_dh2o_moles = 0.0; - for (j = 0; j < use.surface_ptr->count_charge; j++) { - count_g = s_x[i]->diff_layer[j].count_g; -#ifdef SKIP -/* - * original formulation incorrectly mixes concentrations of surface relative - * to moles_water_aq_x and concentrations of diffuse layer in terms - * of moles_water_bulk_x. Moles_water_bulk_x is wrong anyway because - * an individual surface sees only moles_water_aq_x + moles_water_surface - * (not sum of all surfaces) - */ - s_x[i]->diff_layer[j].g_moles = s_x[i]->moles * - (s_x[i]->diff_layer[j].charge->g[count_g].g * - mass_water_bulk_x / mass_water_aq_x + - s_x[i]->diff_layer[j].charge->mass_water / - mass_water_aq_x); - - /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ - s_x[i]->diff_layer[j].dx_moles = s_x[i]->moles * - s_x[i]->diff_layer[j].charge->g[count_g].dg * - mass_water_bulk_x / mass_water_aq_x; - - total_g += s_x[i]->diff_layer[j].charge->g[count_g].g * - mass_water_bulk_x / mass_water_aq_x + - s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; - - s_x[i]->diff_layer[j].dh2o_moles = - s_x[i]->moles * - (s_x[i]->diff_layer[j].charge->g[count_g].g + 1) * - s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; - - s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; - - /* surface related to phase */ - - s_x[i]->diff_layer[j].drelated_moles = s_x[i]->moles * (s_x[i]->diff_layer[j].charge->g[count_g].g + 1) * use.surface_ptr->charge[j].specific_area * use.surface_ptr->thickness / mass_water_aq_x; -#endif -/* - * partially corrected formulation assumes mass of water in diffuse layer - * is insignificant. Excess is calculated on the basis of moles_water_aq_x - * instead of moles_water_bulk. - */ - /* revised eq. 61 */ - s_x[i]->diff_layer[j].g_moles = s_x[i]->moles * - (s_x[i]->diff_layer[j].charge->g[count_g].g + - s_x[i]->diff_layer[j].charge->mass_water / - mass_water_aq_x); - if (s_x[i]->moles > 1e-30) { - s_x[i]->diff_layer[j].dg_g_moles = s_x[i]->dg * s_x[i]->diff_layer[j].g_moles / s_x[i]->moles; - } - - /* - * first term of 63 is summed for all surfaces in - * s_x[i]->tot_g_moles. This sum is then used in - * the jacobian for species i - */ - total_g += s_x[i]->diff_layer[j].charge->g[count_g].g + s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; - - /* revised eq. 63, second term */ - /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ - s_x[i]->diff_layer[j].dx_moles = s_x[i]->moles * s_x[i]->diff_layer[j].charge->g[count_g].dg; - - /* revised eq. 63, third term */ - s_x[i]->diff_layer[j].dh2o_moles = - s_x[i]->moles * s_x[i]->diff_layer[j].charge->mass_water / mass_water_aq_x; - s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; - - /* surface related to phase */ - s_x[i]->diff_layer[j].drelated_moles = s_x[i]->moles * - use.surface_ptr->charge[j].specific_area * - use.surface_ptr->thickness / mass_water_aq_x; - } - s_x[i]->tot_g_moles = s_x[i]->moles * (1 + total_g); - - /* note that dg is for cb, act water, mu eqns */ - /* dg_total_g for mole balance eqns */ - /* dg_g_moles for surface cb */ - - if (s_x[i]->moles > 1e-30) { - s_x[i]->dg_total_g = s_x[i]->dg * s_x[i]->tot_g_moles / s_x[i]->moles; - } else { - s_x[i]->dg_total_g = 0.0; - } -#ifdef SKIP -#endif - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "%s\t%e\t%e\n", s_x[i]->name, (double) s_x[i]->moles, (double) s_x[i]->tot_g_moles); - output_msg(OUTPUT_MESSAGE, "\tg\n"); - for (j=0; j < use.surface_ptr->count_charge; j++) { - count_g = s_x[i]->diff_layer[j].count_g; - output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].charge->g[count_g].g); - } - output_msg(OUTPUT_MESSAGE, "\n\tg_moles\n"); - for (j=0; j < use.surface_ptr->count_charge; j++) { - output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].g_moles); - } - output_msg(OUTPUT_MESSAGE, "\n\tdg\n"); - for (j=0; j < use.surface_ptr->count_charge; j++) { - count_g = s_x[i]->diff_layer[j].count_g; - output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].charge->g[count_g].dg); - } - output_msg(OUTPUT_MESSAGE, "\n\tdx_moles\n"); - for (j=0; j < use.surface_ptr->count_charge; j++) { - output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].dx_moles); - } - output_msg(OUTPUT_MESSAGE, "\n\tdh2o_moles\t%e\n", (double) s_x[i]->tot_dh2o_moles); - for (j=0; j < use.surface_ptr->count_charge; j++) { - output_msg(OUTPUT_MESSAGE, "\t%e", (double) s_x[i]->diff_layer[j].dh2o_moles); - } - output_msg(OUTPUT_MESSAGE, "\n"); - } - } - } - if (use.gas_phase_ptr != NULL) calc_gas_pressures(); - if (use.s_s_assemblage_ptr != NULL) calc_s_s_fractions(); - - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int calc_gas_pressures(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE lp; - struct rxn_token *rxn_ptr; - struct gas_comp *gas_comp_ptr; - struct phase *phase_ptr; -/* - * moles and partial pressures for gases - */ - if (use.gas_phase_ptr == NULL) return(OK); - if (use.gas_phase_ptr->type == VOLUME) { - use.gas_phase_ptr->total_p = 0; - use.gas_phase_ptr->total_moles = 0; - } - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); - phase_ptr = use.gas_phase_ptr->comps[i].phase; - if (phase_ptr->in == TRUE) { - lp=-phase_ptr->lk; - for (rxn_ptr=phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - gas_comp_ptr->phase->p_soln_x = exp(lp * LOG_10); - if (use.gas_phase_ptr->type == PRESSURE) { - gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * - gas_unknown->moles / gas_unknown->gas_phase->total_p; - gas_comp_ptr->phase->fraction_x = gas_comp_ptr->phase->moles_x / gas_unknown->moles; - } else { - gas_comp_ptr->phase->moles_x = gas_comp_ptr->phase->p_soln_x * - use.gas_phase_ptr->volume / (R_LITER_ATM * tk_x); - use.gas_phase_ptr->total_p += gas_comp_ptr->phase->p_soln_x; - use.gas_phase_ptr->total_moles += gas_comp_ptr->phase->moles_x; - } - } else { - gas_comp_ptr->phase->moles_x = 0; - gas_comp_ptr->phase->fraction_x = 0; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int calc_s_s_fractions(void) -/* ---------------------------------------------------------------------- */ -{ - int i, k; - LDBLE moles, n_tot; - struct s_s *s_s_ptr; - -/* - * moles and lambdas for solid solutions - */ - if (s_s_unknown == NULL) return(OK); -/* - * Calculate mole fractions and log lambda and derivative factors - */ - if (use.s_s_assemblage_ptr == NULL) return(OK); - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - s_s_ptr = &(use.s_s_assemblage_ptr->s_s[i]); - n_tot = 0; - for (k = 0; k < s_s_ptr->count_comps; k++) { - moles = s_s_ptr->comps[k].moles; - if (s_s_ptr->comps[k].moles < 0) { - moles = MIN_TOTAL; - s_s_ptr->comps[k].initial_moles = moles; - } - n_tot += moles; - } - s_s_ptr->total_moles = n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) { - moles = s_s_ptr->comps[k].moles; - if (s_s_ptr->comps[k].moles < 0) { - moles = MIN_TOTAL; - } - s_s_ptr->comps[k].fraction_x = moles / n_tot; - s_s_ptr->comps[k].log10_fraction_x = log10(moles / n_tot); - - /* all mb and jacobian items must be in x or phase to be static between models */ - s_s_ptr->comps[k].phase->log10_fraction_x = s_s_ptr->comps[k].log10_fraction_x; - } - if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0) { - s_s_binary(s_s_ptr); - } else { - s_s_ideal(s_s_ptr); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_binary(struct s_s *s_s_ptr) -/* ---------------------------------------------------------------------- */ -{ - LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, a0, a1; - LDBLE xb2, xb3, xb4, xc2, xc3; - LDBLE xb1, xc1; -/* - * component 0 is major component - * component 1 is minor component - * xb is the mole fraction of second component (formerly trace) - * xc is the mole fraction of first component (formerly major) -*/ -/* - * Calculate mole fractions and log lambda and derivative factors - */ - n_tot = s_s_ptr->total_moles; - - nc = s_s_ptr->comps[0].moles; - xc = nc/n_tot; - nb = s_s_ptr->comps[1].moles; - xb = nb/n_tot; -/* - * In miscibility gap - */ - a0 = s_s_ptr->a0; - a1 = s_s_ptr->a1; - if (s_s_ptr->miscibility == TRUE && xb > s_s_ptr->xb1 && xb < s_s_ptr->xb2) { - xb1 = s_s_ptr->xb1; - xc1 = 1.0 - xb1; - s_s_ptr->comps[0].fraction_x = xc1; - s_s_ptr->comps[0].log10_fraction_x = log10(xc1); - s_s_ptr->comps[0].phase->log10_fraction_x = s_s_ptr->comps[0].log10_fraction_x; - - s_s_ptr->comps[1].fraction_x = xb1; - s_s_ptr->comps[1].log10_fraction_x = log10(xb1); - s_s_ptr->comps[1].phase->log10_fraction_x = s_s_ptr->comps[1].log10_fraction_x; - - s_s_ptr->comps[0].log10_lambda = xb1*xb1*(a0 - a1*(3 -4*xb1))/LOG_10; - s_s_ptr->comps[0].phase->log10_lambda = s_s_ptr->comps[0].log10_lambda; - - s_s_ptr->comps[1].log10_lambda = xc1*xc1*(a0 + a1*(4*xb1 - 1))/LOG_10; - s_s_ptr->comps[1].phase->log10_lambda = s_s_ptr->comps[1].log10_lambda; - - s_s_ptr->comps[0].dnb = 0; - s_s_ptr->comps[0].dnc = 0; - s_s_ptr->comps[1].dnb = 0; - s_s_ptr->comps[1].dnc = 0; - s_s_ptr->comps[0].phase->dnb = 0; - s_s_ptr->comps[0].phase->dnc = 0; - s_s_ptr->comps[1].phase->dnb = 0; - s_s_ptr->comps[1].phase->dnc = 0; - } else { -/* - * Not in miscibility gap - */ - s_s_ptr->comps[0].fraction_x = xc; - s_s_ptr->comps[0].log10_fraction_x = log10(xc); - s_s_ptr->comps[0].phase->log10_fraction_x = s_s_ptr->comps[0].log10_fraction_x; - - s_s_ptr->comps[1].fraction_x = xb; - s_s_ptr->comps[1].log10_fraction_x = log10(xb); - s_s_ptr->comps[1].phase->log10_fraction_x = s_s_ptr->comps[1].log10_fraction_x; - - s_s_ptr->comps[0].log10_lambda = xb*xb*(a0 - a1*(3 -4*xb))/LOG_10; - s_s_ptr->comps[0].phase->log10_lambda = s_s_ptr->comps[0].log10_lambda; - - s_s_ptr->comps[1].log10_lambda = xc*xc*(a0 + a1*(4*xb - 1))/LOG_10; - s_s_ptr->comps[1].phase->log10_lambda = s_s_ptr->comps[1].log10_lambda; - - xc2 = xc*xc; - xc3 = xc2*xc; - xb2 = xb*xb; - xb3 = xb2*xb; - xb4 = xb3*xb; -#ifdef SKIP - /* first component */ - dnb = -2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 - 4*a1*xc*xb4 - 8*a1*xb3*xc2 - - 4*a1*xb2*xc3 - 2*a0*xc*xb2 - 8*a1*xc*xb3 + 6*a1*xc*xb2 + 1; - s_s_ptr->comps[0].phase->dnb = dnb/n_tot; - dnc = 2*a0*xb3 + 2*a0*xc*xb2 + 8*a1*xb4 + 8*a1*xc*xb3 - 2*a1*xb3 - 6*a1*xc*xb2; - s_s_ptr->comps[0].phase->dnc = - xb/nc + dnc/n_tot; - - /* second component */ - dnb = 2*a0*xb*xc2 + 2*a0*xc3 + 8*a1*xb2*xc2 + 8*a1*xb*xc3 - 2*a1*xb*xc2 -6*a1*xc3; - s_s_ptr->comps[1].phase->dnb = -xc/nb + dnb/n_tot; - dnc = -2*a0*xc*xb2 - 8*a1*xc*xb3 + 2*a1*xc*xb2 - 2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 + 1; - s_s_ptr->comps[1].phase->dnc = dnc/n_tot; -#endif - /* used derivation that did not substitute x2 = 1-x1 */ - - /* first component, df1/dn1*/ - dnc = 2*a0*xb2 + 12*a1*xc*xb2 + 6*a1*xb2; - s_s_ptr->comps[0].phase->dnc = - xb/nc + dnc/n_tot; - - - /* first component, df1/dn2*/ - dnb = 1 - 2*a0*xb + 2*a0*xb2 + 8*a1*xc*xb - 12*a1*xc*xb2 - 2*a1*xb + 2*a1*xb2; - s_s_ptr->comps[0].phase->dnb = dnb/n_tot; - - /* second component, df2/dn1 */ - dnc = 1 -2*a0*xc +2*a0*xc2 - 8*a1*xb*xc + 12*a1*xb*xc2 + 2*a1*xc - 2*a1*xc2; - s_s_ptr->comps[1].phase->dnc = dnc/n_tot; - - /* second component, df2/dn2 */ - dnb = 2*a0*xc2 + 12*a1*xb*xc2 - 6*a1*xc2; - s_s_ptr->comps[1].phase->dnb = -xc/nb + dnb/n_tot; - - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_ideal(struct s_s *s_s_ptr) -/* ---------------------------------------------------------------------- */ -{ - int k, j; - LDBLE n_tot, n_tot1; - -/* - * component 0 is major component - * component 1 is minor component - * xb is the mole fraction of second component (formerly trace) - * xc is the mole fraction of first component (formerly major) -*/ -/* - * Calculate mole fractions and log lambda and derivative factors - */ - n_tot = s_s_ptr->total_moles; - -/* - * Ideal solid solution - */ - s_s_ptr->dn = 1.0 / n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) { - n_tot1 = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) { - if (j != k) { - n_tot1 += s_s_ptr->comps[j].moles; - } - } - s_s_ptr->comps[k].log10_lambda = 0; - s_s_ptr->comps[k].phase->log10_lambda = 0; - - s_s_ptr->comps[k].dnb = -(n_tot1)/(s_s_ptr->comps[k].moles*n_tot); - s_s_ptr->comps[k].phase->dnb = s_s_ptr->comps[k].dnb; - - s_s_ptr->comps[k].dn = s_s_ptr->dn; - s_s_ptr->comps[k].phase->dn = s_s_ptr->dn; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int reset(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks deltas (changes to unknowns) to make sure they are reasonable - * Scales deltas if necessary - * Updates unknowns with deltas - */ - - int i, j; - int converge; - LDBLE up, down; - LDBLE d; - LDBLE factor, f0; - LDBLE sum_deltas; - LDBLE step_up; -#ifdef SKIP - LDBLE epsilon; -#endif - LDBLE mu_calc; - LDBLE old_moles; -/*appt char name[MAX_LENGTH]; LDBLE surf_chrg_eq; - */ -/* - * Calculate interphase mass transfers - */ -#ifdef SKIP - if (punch.high_precision == FALSE) - epsilon = 1e-9; - else - epsilon = 1.e-12; -#endif - step_up = log(step_size_now); - factor = 1.; - - if ( pure_phase_unknown != NULL || s_s_unknown != NULL) { -/* - * Don't take out more mineral than is present - */ - for (i=0; itype == PP || x[i]->type == S_S_MOLES) { - if (/* delta[i] > 0.0 && */ x[i]->moles > 0.0 && delta[i] > x[i]->moles ) { - f0 = delta[i] / x[i]->moles; - if (f0 > factor) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s, Removing more than total mineral.\t%f\n", - x[i]->description, (double) f0); - } - factor=f0; - } - } else if ( delta[i] > 0.0 && x[i]->moles <= 0.0 ) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "%-10.10s\tDelta: %e\tMass: %e " - "Dissolving mineral with 0.0 mass.\n ", - x[i]->description, (double) delta[i], (double) x[i]->moles); - } - delta[i] = 0.0 ; - } else if (delta[i] < 0.0 && x[i]->moles > 0.0 && delta[i] < -100.0 ) { - f0 = -delta[i] / 100.0 ; - if (f0 > factor) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s, Precipitating too much mineral.\t%f\n", x[i]->description, (double) f0); - } - factor=f0; - } - } - } - } - } -/* - * Calculate change in element concentrations due to pure phases and gases - */ - if (pure_phase_unknown != NULL || gas_unknown != NULL || s_s_unknown != NULL) { - for(i=0; i < count_unknowns; i++) { - x[i]->delta = 0.0; - } - - for (i=0; i < count_sum_delta; i++) { - *sum_delta[i].target += *sum_delta[i].source * sum_delta[i].coef; - } - -/* - * Apply factor from minerals to deltas - */ - - - for(i=0; i < count_unknowns; i++) { - x[i]->delta /= factor; - if (x[i]->type == PP || x[i]->type == S_S_MOLES) delta[i] /= factor; - } - - } - - -/* - * Calc factor for mass balance equations for aqueous unknowns - */ - factor=1.0; - sum_deltas=0.0; - for (i=0; i < count_unknowns; i++) { - sum_deltas += fabs(delta[i]); - up = step_up; - down = up; - if (x[i]->type <= SOLUTION_PHASE_BOUNDARY) { - up = step_up; - down = 1.3 * up; - } else if (x[i]->type == MU) { - up = 100 * mu_x; -#ifdef SKIP - if (up > 0.1) { - up = 2 * mu_x; - up = 0.1; - } -#endif -#ifdef SKIP - down = 0.7 * mu_x; - if (down < 0.1) down = 0.1; -#endif - down = mu_x; - } else if (x[i]->type == AH2O) { - down = up; - } else if (x[i]->type == MH) { - up = log(pe_step_size_now); - down = 1.3*up; - } else if (x[i]->type == MH2O) { - /* ln gH2O + delta; ln(gH2O*delta); */ - /* - up = log(10.); - down = log(4.); - */ - up = log(1.3); - down = log(1.2); - - } else if (x[i]->type == PP) { - continue; - } else if (x[i]->type == GAS_MOLES) { - up = 1000. * x[i]->moles; - if (up <= 0.0) up = 1e-1; - if (up >= 1.0) up = 1.; - down = x[i]->moles; - } else if (x[i]->type == S_S_MOLES) { - continue; - } else if (x[i]->type == EXCH) { - up = step_up; - down = 1.3 * up; - } else if (x[i]->type == SURFACE) { - up = step_up; - down = 1.3 * up; - } else if (x[i]->type == SURFACE_CB) { - up = step_up; - down = 1.3 * up; - } - - if (delta[i] > 0.0) { - f0=delta[i]/up; - if (f0 > factor) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s\t%f\n",x[i]->description, (double) f0); - } - factor=f0; - } - } else { - f0=delta[i]/(-down); - if (f0 > factor) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s\t%f\n",x[i]->description, (double) f0); - } - factor=f0; - } - } - } - - /*converge=TRUE;*/ - - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nSum of deltas: %12.6f\n", (double) sum_deltas); - output_msg(OUTPUT_MESSAGE,"Factor: %12.4e\n", (double) factor); - } - factor = 1.0/factor; - - for (i=0; itype != PP && x[i]->type != S_S_MOLES) delta[i] *= factor; - } -/* - * Solution mass balances: MB, ALK, CB, SOLUTION_PHASE_BOUNDARY - */ - for (i=0; i < count_unknowns ; i++) { - if (x[i]->type == MB || x[i]->type == ALK || x[i]->type == EXCH || x[i]->type == SURFACE) { - /*if ( fabs(delta[i]) >= epsilon ) converge = FALSE;*/ - d = delta[i] / LOG_10; - /* surface */ - if (x[i]->type == SURFACE) { - old_moles = x[i]->moles; - if (x[i]->phase_unknown != NULL) { - x[i]->moles = x[i]->surface_comp->phase_proportion * - (x[i]->phase_unknown->moles - - delta[x[i]->phase_unknown->number]); - if (x[i]->phase_unknown->moles - delta[x[i]->phase_unknown->number] <= MIN_RELATED_SURFACE) { - x[i]->moles = 0.0; - if (fabs(x[i]->f) > MIN_RELATED_SURFACE) { - x[i]->master[0]->s->la -= 5.; - } - } - if (old_moles <= 0 && x[i]->moles > 0) { - x[i]->master[0]->s->la = log10(x[i]->moles) - 5.; - } - } - } - /* exch */ - if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) { - x[i]->moles = 0.0; - if (fabs(x[i]->f) > MIN_RELATED_SURFACE) { - x[i]->master[0]->s->la -= 5.; - } - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e " - "%-8s%10.2e\n", x[i]->description, - "old la", (double) x[i]->master[0]->s->la, - "new la", (double) x[i]->master[0]->s->la + (double) d, - "delta", (double) delta[i], "delta/c", (double) d); - } - x[i]->master[0]->s->la += d; - if (x[i]->master[0]->s->la < (double) (DBL_MIN_10_EXP+10)) x[i]->master[0]->s->la = (double) (DBL_MIN_10_EXP+10); - -/* - * Surface charge balance - */ - - } else if ( x[i]->type == SURFACE_CB ) { - d = delta[i] / LOG_10; - if (x[i]->phase_unknown != NULL) { - x[i]->surface_charge->grams = /* !!!! x[i]->surface_comp->phase_proportion * */ - (x[i]->phase_unknown->moles - - delta[x[i]->phase_unknown->number]); - if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { - x[i]->surface_charge->grams = 0.0; - } - } - if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { - x[i]->surface_charge->grams = 0.0; - } -#ifdef SKIP - else if (fabs(delta[i]) > epsilon) { - converge=FALSE; - } -#endif - x[i]->related_moles = x[i]->surface_charge->grams; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", - x[i]->description, "old f*psi", (double) x[i]->master[0]->s->la, "new f*psi", (double) x[i]->master[0]->s->la + (double) d,"delta", (double) d); - } - - x[i]->master[0]->s->la += d; - - /* recalculte g's for component */ - if (diffuse_layer_x == TRUE) { - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "\ncharge, old g, new g, dg*delta," - " dg, delta\n"); - } - for (j = 0; j < x[i]->surface_charge->count_g; j++) { - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE, "%12f\t%12.4e\t%12.4e\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[i]->surface_charge->g[j].charge, - (double) x[i]->surface_charge->g[j].g, - (double) x[i]->surface_charge->g[j].g + - (double) (x[i]->surface_charge->g[j].dg * delta[i]), - (double) (x[i]->surface_charge->g[j].dg * delta[i]), - (double) x[i]->surface_charge->g[j].dg, - (double) delta[i]); - } -/*appt*/ if (use.surface_ptr->donnan != TRUE) { - x[i]->surface_charge->g[j].g += x[i]->surface_charge->g[j].dg * delta[i]; - } - } -/*appt*/ if (use.surface_ptr->donnan == TRUE) { - calc_all_donnan(); - } - } - -/* Solution phase boundary */ - } else if ( x[i]->type == SOLUTION_PHASE_BOUNDARY ) { - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - d = delta[i] / LOG_10; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); - } - x[i]->master[0]->s->la += d; -/* Charge balance */ - } else if ( x[i]->type == CB ) { - /*if (fabs(delta[i]) > epsilon * mu_x * mass_water_aq_x ) converge=FALSE;*/ - d = delta[i] / LOG_10; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); - } - x[i]->master[0]->s->la += d; -/* Ionic strength */ - } else if (x[i]->type == MU) { - - /*if (fabs(delta[i]) > epsilon * mu_x ) converge=FALSE;*/ - mu_calc = 0.5*mu_unknown->f/mass_water_aq_x; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"Calculated mu: %e\n", (double) mu_calc); - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", - x[i]->description, "old mu", (double) mu_x, "new mu", - (double) (mu_x + delta[i]), - "delta", (double) delta[i]); - } - d = mu_x + delta[i]; - if (d < 1e-7) { - delta[i] = sqrt(mu_calc * mu_x) - mu_x; - mu_x = sqrt(mu_calc * mu_x); - } else { - mu_x += delta[i]; - } - if (mu_x <= 1e-8) { - mu_x = 1e-8; - } -/* Activity of water */ - } else if (x[i]->type == AH2O) { - /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue;*/ - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - d = delta[i] / LOG_10; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old la", (double) x[i]->master[0]->s->la, "new la", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); - } - s_h2o->la += d; - if (pitzer_model == FALSE) { - if (s_h2o->la < -1.0) { - d = -1.0 - s_h2o->la; - delta[i] = d * LOG_10; - s_h2o->la = -1.0; - } - } -/* pe */ - } else if (x[i]->type == MH) { - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - d = delta[i] / LOG_10; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old pe", (double) x[i]->master[0]->s->la, "new pe", (double) (x[i]->master[0]->s->la + d), "delta", (double) delta[i], "delta/c", (double) d); - } - s_eminus->la += d; -/* Mass of water */ - } else if (x[i]->type == MH2O) { - if (mass_water_switch == TRUE) continue; - /*if (fabs(delta[i]) > epsilon * mass_water_aq_x) converge=FALSE;*/ - /* ln(gh2o) + delta, log(gh2o) + d, gh2o * 10**d */ - d = exp(delta[i]); - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old MH2O", (double) mass_water_aq_x, "new MH2O", (double) (mass_water_aq_x * d), "delta", (double) delta[i], "10**d/c", (double) d); - } - mass_water_aq_x *= d; - mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; - if (debug_model == TRUE && diffuse_layer_x == TRUE) { - output_msg(OUTPUT_MESSAGE,"mass_water bulk: %e\taq: %e\tsurfaces: %e\n", - (double) mass_water_bulk_x, (double) mass_water_aq_x, (double) mass_water_surfaces_x); - } - x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; - - if (mass_water_aq_x < 1e-10) { - sprintf(error_string, "Mass of water is less than 1e-10 kilogram.\n" - "The aqueous phase may not be stable relative to given masses of minerals."); - warning_msg(error_string); - stop_program = TRUE; - return(TRUE); - } -/* Pure phases */ - } else if (x[i]->type == PP) { - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", - x[i]->description, "old mass", (double) x[i]->moles, - "new mass", (double) (x[i]->moles - delta[i]), "delta", (double) delta[i]); - } - x[i]->moles -= delta[i]; -/* if (fabs(x[i]->moles) < MIN_RELATED_SURFACE) x[i]->moles = 0.0; */ - } else if (x[i]->type == GAS_MOLES) { - - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - /*if (gas_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE;*/ - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", - x[i]->description, "old mol", (double) x[i]->moles, - "new mol", (double) (x[i]->moles + delta[i]), - "delta", (double) delta[i]); - } - x[i]->moles += delta[i]; - if (x[i]->moles < MIN_TOTAL) x[i]->moles = MIN_TOTAL; - } else if (x[i]->type == S_S_MOLES) { - - /*if (fabs(delta[i]) > epsilon) converge=FALSE;*/ - /*if (x[i]->s_s_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE;*/ - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", - x[i]->description, "old mol", (double) x[i]->moles, - "new mol", (double) (x[i]->moles - delta[i]), - "delta", (double) delta[i]); - } - x[i]->moles -= delta[i]; - if (x[i]->moles < MIN_TOTAL) x[i]->moles = MIN_TOTAL; - x[i]->s_s_comp->moles = x[i]->moles; -/* Pitzer gamma */ - } else if ( x[i]->type == PITZER_GAMMA ) { - if (full_pitzer == FALSE) continue; - d = delta[i]; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", x[i]->description, "old lg", (double) x[i]->s->lg, "new lg", (double) (x[i]->s->lg + d), "delta", (double) delta[i], "delta", (double) d); - } - x[i]->s->lg += d; - } - } -/* - * Reset total molalities in mass balance equations - */ - if (pure_phase_unknown != NULL || gas_unknown != NULL || s_s_unknown != NULL) { - for (i=0; itype == MB || x[i]->type == MH || - x[i]->type == MH2O || - x[i]->type == CB || x[i]->type == EXCH || - x[i]->type == SURFACE ) { - /*if (fabs(x[i]->delta) > epsilon*x[i]->moles) converge = FALSE;*/ - if (x[i]->type == SURFACE) x[i]->delta = 0.0; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", - x[i]->description, "old mole", (double) x[i]->moles, - "new mole", (double) (x[i]->moles + x[i]->delta), - "delta", (double) x[i]->delta); - } - x[i]->moles += x[i]->delta; - } - } - } - converge = FALSE; - return(converge); -} -/* ---------------------------------------------------------------------- */ -int residuals(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates residuals for all equations - */ - int i; - int converge; - - LDBLE toler; - LDBLE sum_residual; - LDBLE sinh_constant; - - sum_residual = 0.0; - -/* - * Calculate residuals - */ - converge = TRUE; -#ifdef SKIP - if (punch.high_precision == FALSE) - toler = 1e-8; - else - toler = 1.e-12; -#endif - toler = convergence_tolerance; - - for (i=0; i < count_unknowns; i++) { - if (x[i]->type == MB ) { - residual[i] = x[i]->moles - x[i]->f; - if (fabs(residual[i]) > toler * x[i]->moles && x[i]->moles > MIN_TOTAL ) { - /* - fprintf(stderr,"Residuals %d: %s %d %e\n", iterations, x[i]->description, i, residual[i]); - */ - converge = FALSE; - } - } else if (x[i]->type == ALK) { - residual[i] = x[i]->moles - x[i]->f; - if (fabs(residual[i]) > toler * x[i]->moles ) converge = FALSE; - } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - residual[i] = x[i]->f * LOG_10; - if (fabs(residual[i]) > toler ) converge = FALSE; - } else if (x[i]->type == CB) { - residual[i] = - x[i]->f; - if (ph_unknown == charge_balance_unknown) { - residual[i] += x[i]->moles; - } - if (fabs(residual[i]) >= toler * mu_x * mass_water_aq_x ) converge = FALSE; - } else if (x[i]->type == MU && pitzer_model == FALSE) { - residual[i] = mass_water_aq_x * mu_x - 0.5*x[i]->f; - if (fabs(residual[i]) > toler*mu_x * mass_water_aq_x ) converge = FALSE; - } else if (x[i]->type == AH2O /*&& pitzer_model == FALSE*/) { - /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue;*/ - residual[i] = mass_water_aq_x*exp(s_h2o->la * LOG_10) - mass_water_aq_x + 0.017 * x[i]->f; - if (pitzer_model) { - residual[i] = pow(10.0,s_h2o->la) - AW; - if (full_pitzer == FALSE) { - residual[i] = 0.0; - } - } - if (fabs(residual[i]) > toler ) converge = FALSE; - } else if (x[i]->type == MH && pitzer_model == FALSE) { -#ifdef COMBINE - residual[i] = x[i]->moles - x[i]->f; -#else - residual[i] = (x[i]->moles - 2*s_h2o->moles) - x[i]->f; - x[i]->f += 2 * s_h2o->moles; -#endif - if (mass_water_switch == TRUE) { - residual[i] -= 2 * (mass_oxygen_unknown->moles - mass_oxygen_unknown->f); - } -#ifdef COMBINE -#ifndef COMBINE_CHARGE - if (fabs(residual[i]) > toler*(x[i]->moles + 2 * mass_oxygen_unknown->moles)) converge = FALSE; -#else - if (fabs(residual[i]) > toler*(x[i]->moles + 2 * mass_oxygen_unknown->moles + charge_balance_unknown->moles)) converge = FALSE; -#endif -#else - if (fabs(residual[i]) > toler*x[i]->moles ) converge = FALSE; -#endif - } else if (x[i]->type == MH2O) { - if (mass_water_switch == TRUE) continue; -#ifdef COMBINE - residual[i] = x[i]->moles - x[i]->f; -#else - residual[i] = (x[i]->moles - s_h2o->moles) - x[i]->f; - x[i]->f += s_h2o->moles; -#endif - if (fabs(residual[i]) > 0.01 * toler*x[i]->moles ) converge = FALSE; - } else if (x[i]->type == PP) { - residual[i] = x[i]->f * LOG_10; - if (x[i]->pure_phase->add_formula == NULL) { - if (x[i]->dissolve_only == TRUE) { - if ((residual[i] > toler && x[i]->moles > 0.0) || (residual[i] < -toler && (x[i]->pure_phase->initial_moles - x[i]->moles) > 0)) { - converge = FALSE; - } - } else { - if (residual[i] < -toler || iterations < 1) converge = FALSE; - } - } else { - /* if (x[i]->moles > 0.0 && fabs(residual[i]) > toler) converge = FALSE;*/ - if (residual[i] < -toler || iterations < 1) { - converge = FALSE; - } - } - } else if (x[i]->type == GAS_MOLES) { - residual[i] = x[i]->gas_phase->total_p - x[i]->f; - if (fabs(residual[i]) > toler && gas_in == TRUE) converge = FALSE; - } else if (x[i]->type == S_S_MOLES) { - residual[i] = x[i]->f * LOG_10; - if (fabs(residual[i]) > toler && x[i]->s_s_in == TRUE) converge = FALSE; - } else if (x[i]->type == EXCH) { - residual[i] = x[i]->moles - x[i]->f; - if (x[i]->moles <= MIN_RELATED_SURFACE) { - if (fabs(residual[i]) > toler) converge = FALSE; - } else if (fabs(residual[i]) > toler * x[i]->moles ) { - converge = FALSE; - } - } else if (x[i]->type == SURFACE) { - residual[i] = x[i]->moles - x[i]->f; - if (x[i]->moles <= MIN_RELATED_SURFACE) { - if ( fabs(residual[i]) > toler ) converge = FALSE; - } else if (fabs(residual[i]) > toler * x[i]->moles ) { - converge = FALSE; - } - } else if (x[i]->type == PITZER_GAMMA) { - if (full_pitzer == FALSE) continue; - residual[i] = x[i]->s->lg - x[i]->s->lg_pitzer; - if (fabs(residual[i]) > toler ) { - /* - fprintf(stderr,"Residuals %d: %s %d %e\n", iterations, x[i]->description, i, residual[i]); - */ - converge = FALSE; - } - } else if (x[i]->type == SURFACE_CB) { - /*sinh_constant = 0.1174;*/ - sinh_constant = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*tk_x*1000); -/* if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { */ - if (x[i]->surface_charge->grams == 0) { - residual[i] = 0.0; - } else if (diffuse_layer_x == TRUE) { - residual[i] = - x[i]->f; - } else { -/* - * sinh_constant is (8 e e0 R T 1000)**1/2 - * = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*t_x*1000) - * ~ 0.1174 at 25C - */ - residual[i] = sinh_constant * sqrt(mu_x) * - sinh(x[i]->master[0]->s->la * LOG_10) - - x[i]->f * F_C_MOL / - (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams); - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"Charge/Potential\n"); - if (x[i]->surface_charge->grams > 0) { - output_msg(OUTPUT_MESSAGE,"\tSum of surface charge %e eq\n", - (double) (x[i]->f /* F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams)*/)); - } else { - output_msg(OUTPUT_MESSAGE,"\tResidual %e\n", (double) x[i]->f ); - } - output_msg(OUTPUT_MESSAGE,"\t grams %g\n", (double) x[i]->surface_charge->grams); - output_msg(OUTPUT_MESSAGE,"\tCharge from potential %e eq\n", - (double) (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams / F_C_MOL * - sinh_constant * sqrt(mu_x) * - sinh(x[i]->master[0]->s->la * LOG_10))); - output_msg(OUTPUT_MESSAGE,"\t FPsi/2RT %e\n", - (double) (x[i]->master[0]->s->la * LOG_10)); - output_msg(OUTPUT_MESSAGE,"\t Sinh(FPsi/2RT) %e\n", - sinh(x[i]->master[0]->s->la * LOG_10)); - output_msg(OUTPUT_MESSAGE,"\t Cosh(FPsi/2RT) %e\n", - cosh(x[i]->master[0]->s->la * LOG_10)); - output_msg(OUTPUT_MESSAGE,"\t Sqrt(mu_x) %e\n", - sqrt(mu_x)); - } - if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE && fabs(residual[i]) > toler ) converge = FALSE; - } -/* - * Store residuals in array - */ - array[(i+1)*(count_unknowns+1)-1] = residual[i]; - sum_residual += fabs(residual[i]); - } -/* - * Return - */ - if (pitzer_model == TRUE && iterations < 1) return(OK); - if (converge == TRUE ) { - return (CONVERGED); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set(int initial) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sets initial guesses for unknowns if initial == TRUE - * Revises guesses whether initial is true or not - */ - int i; - struct solution *solution_ptr; -/* - * Set initial log concentrations to zero - */ - if (pitzer_model == TRUE) return(set_pz(initial)); - iterations = -1; - solution_ptr = use.solution_ptr; - for (i=0; i < count_s_x; i++) { - s_x[i]->lm = LOG_ZERO_MOLALITY; - s_x[i]->lg = 0.0; - } -/* - * Set master species activities - */ - - tc_x=solution_ptr->tc; - tk_x=tc_x+273.15; -/* - * H+, e-, H2O - */ - mass_water_aq_x = solution_ptr->mass_water; - mu_x = solution_ptr->mu; - s_h2o->moles = mass_water_aq_x/gfw_water; - s_h2o->la = log10(solution_ptr->ah2o); - s_hplus->la = - solution_ptr->ph; - s_hplus->lm = s_hplus->la; - s_hplus->moles = exp(s_hplus->lm * LOG_10)*mass_water_aq_x; - s_eminus->la= - solution_ptr->solution_pe; - if (initial == TRUE) initial_guesses(); - if (diffuse_layer_x == TRUE) initial_surface_water(); - revise_guesses(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_guesses(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make initial guesses for activities of master species and - * ionic strength - */ - int i; - struct solution *solution_ptr; - - solution_ptr = use.solution_ptr; - mu_x = s_hplus->moles + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; - mu_x /= mass_water_aq_x; - s_h2o->la=0.0; - for ( i=0; i < count_unknowns; i++ ) { - if (x[i] == ph_unknown || x[i] == pe_unknown ) continue; - if (x[i]->type < CB) { - mu_x += x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * - x[i]->master[0]->s->z; - x[i]->master[0]->s->la = log10(x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == CB) { - x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == EXCH) { - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - x[i]->master[0]->s->la = log10(x[i]->moles); - } - } else if (x[i]->type == SURFACE) { - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); - } - } else if (x[i]->type == SURFACE_CB) { - x[i]->master[0]->s->la = 0.0; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int revise_guesses(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Revise la's of master species - */ - int i; - int iter, max_iter, repeat, fail; - LDBLE weight, f; -/*appt char name[MAX_LENGTH]; LDBLE surf_chrg_eq; - */ - max_iter = 10; - gammas(mu_x); - iter = 0; - repeat = TRUE; - fail = FALSE;; - while ( repeat == TRUE ) { - iter++; - if (debug_set == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nBeginning set iteration %d.\n", iter); - } - if (iter == max_iter + 1) { - output_msg(OUTPUT_LOG, "Did not converge in set, iteration %d.\n", iterations); - fail = TRUE; - } - if (iter > 2*max_iter) { - output_msg(OUTPUT_LOG, "Did not converge with relaxed criteria in set.\n"); - return(OK); - } - molalities(TRUE); - mb_sums(); - if (state < REACTION) { - sum_species(); - } else { - for (i = 0; i < count_unknowns; i++) { - x[i]->sum = x[i]->f; - } - } -/* debug - if (debug_set == TRUE) { - pr.species = TRUE; - pr.all = TRUE; - print_species(); - } - */ - repeat=FALSE; - for ( i=0; i < count_unknowns; i++ ) { - if (x[i] == ph_unknown || x[i] == pe_unknown) continue; - if (x[i]->type == MB || -/* x[i]->type == ALK || */ - x[i]->type == CB || - x[i]->type == SOLUTION_PHASE_BOUNDARY || - x[i]->type == EXCH || - x[i]->type == SURFACE ) { - - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\t%5s at beginning of set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - if (fabs(x[i]->moles) < 1e-30) x[i]->moles = 0; - f = fabs(x[i]->sum); - if (f == 0 && x[i]->moles == 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - continue; - } else if (f == 0) { - repeat = TRUE; - x[i]->master[0]->s->la += 5; -/*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { - continue; - } else if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - repeat = TRUE; - x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); - } - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t%5s not converged in set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - } - } else if (x[i]->type == ALK) { - f = total_co2; - if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { - continue; - } - if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { - repeat = TRUE; - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; - x[i]->master[0]->s->la += weight * - log10(fabs(x[i]->moles / x[i]->sum)); - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"%s not converged in set. %e\t%e\t%e\n", x[i]->description, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - } - } - } - } - output_msg(OUTPUT_LOG,"Iterations in revise_guesses: %d\n", iter); - mu_x = mu_unknown->f * 0.5 / mass_water_aq_x; - if (mu_x <= 1e-8) { - mu_x = 1e-8; - } - gammas(mu_x); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int sum_species(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates total alk, total carbon, total co2, electrical balance, - * total hydrogen, and total oxygen. - * - * Sorts species for summing and printing based on valence state and - * concentrations. - * - * Sums total valence states and stores in master[i]->total. - */ - int i, j; - struct master *master_ptr; -/* - * Set global variables - */ - ph_x = -s_hplus->la; - solution_pe_x = -s_eminus->la; - ah2o_x = exp(s_h2o->la * LOG_10); - density_x = 1.0; - if (s_o2 != NULL) s_o2->moles = under(s_o2->lm) * mass_water_aq_x; - if (s_h2 != NULL) s_h2->moles = under(s_h2->lm) * mass_water_aq_x; - -/* - * Calculate sums - */ - total_alkalinity = 0.0; - total_carbon = 0.0; - total_co2 = 0.0; - cb_x = 0.0; - total_ions_x = 0.0; - total_o_x = 0.0; - total_h_x = 0.0; - for (i=0; i < count_s_x; i++) { - if (s_x[i]->type == EX ) continue; - if (s_x[i]->type == SURF ) continue; - cb_x += s_x[i]->z * s_x[i]->moles; - total_ions_x += fabs(s_x[i]->z * s_x[i]->moles); - total_alkalinity += s_x[i]->alk * s_x[i]->moles; - total_carbon += s_x[i]->carbon * s_x[i]->moles; - total_co2 += s_x[i]->co2 * s_x[i]->moles; - total_h_x += s_x[i]->h * s_x[i]->moles; - total_o_x += s_x[i]->o * s_x[i]->moles; - } -/* - * Sum valence states, put in master->total - */ - for (i=0; i < count_master; i++) { - master[i]->total=0.0; - master[i]->total_primary = 0.0; - } - for (i=0; i < count_species_list; i++) { - if (species_list[i].master_s->secondary != NULL) { - master_ptr = species_list[i].master_s->secondary; - } else { - master_ptr = species_list[i].master_s->primary; - } - master_ptr->total += species_list[i].s->moles * species_list[i].coef; - } -/* - * Calculate mass-balance sums - */ - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == MB || - x[i]->type == SOLUTION_PHASE_BOUNDARY || - x[i]->type == EXCH || - x[i]->type == SURFACE || - ( x[i]->type == CB && x[i] != ph_unknown && x[i] != pe_unknown ) ) { - x[i]->sum = 0.0; - for (j = 0; x[i]->master[j] != NULL; j++) { - x[i]->sum += x[i]->master[j]->total; - } - } else if (x[i]->type == ALK) { - x[i]->sum = total_co2; - } - } -/* - * Calculate total element concentrations - */ - for (i = 0; i < count_master; i++) { - master[i]->elt->primary->total_primary += - master[i]->total; - } - /* - * Calculate isotope ratios - */ - calculate_values(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_model(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Use extra iterative loop to converge on g_factors - */ - int i, g_iterations, debug_diffuse_layer_save, debug_model_save; - -/* - * Allocate space for g factors for diffuse layer in surface complexation - */ - debug_diffuse_layer_save = debug_diffuse_layer; - debug_model_save = debug_model; - if (last_model.force_prep == TRUE) { - same_model = FALSE; - } else { - same_model = check_same_model(); - } - if (diffuse_layer_x == TRUE && same_model == FALSE) { - for (i=0; i < count_s; i++) { - s[i]->diff_layer = (struct species_diff_layer *) free_check_null(s[i]->diff_layer); - s[i]->diff_layer = (struct species_diff_layer *) PHRQ_malloc((size_t) use.surface_ptr->count_charge * sizeof (struct species_diff_layer)); - if (s[i]->diff_layer == NULL) malloc_error(); - } - } - prep(); - k_temp(tc_x); - if (use.surface_ptr->donnan == TRUE) { - initial_surface_water(); - calc_init_donnan(); - } else { - calc_init_g(); - } - if (state >= REACTION && use.surface_ptr->new_def == FALSE) { - set(FALSE); - } else { - set(TRUE); - } - if (model() == ERROR) return(ERROR); - g_iterations = 0; - if (use.surface_ptr->donnan == TRUE) { - do { - g_iterations++; - k_temp(tc_x); - gammas(mu_x); - molalities(TRUE); - mb_sums(); - if (model() == ERROR) return(ERROR); - if (use.surface_ptr->related_phases != TRUE && use.surface_ptr->related_rate != TRUE) initial_surface_water(); - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "Surface_model (Donnan approximation): %d g_iterations, %d model iterations\n", - g_iterations, iterations); - } - } while (calc_all_donnan() == FALSE && g_iterations < itmax); - } else { - do { - g_iterations++; - if (g_iterations > itmax - 10) { - debug_model = TRUE; - debug_diffuse_layer = TRUE; - } - k_temp(tc_x); - gammas(mu_x); - molalities(TRUE); - mb_sums(); - if (model() == ERROR) return(ERROR); - if (use.surface_ptr->related_phases != TRUE && use.surface_ptr->related_rate != TRUE) initial_surface_water(); - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "Surface_model (full integration): %d g_iterations, %d iterations\n", - g_iterations, iterations); - } - } while (calc_all_g() == FALSE && g_iterations < itmax); - } - if (g_iterations >= itmax) { - error_msg("Did not converge on g (diffuse layer excess)", STOP); - } -/* - print_all(); - */ - debug_diffuse_layer = debug_diffuse_layer_save; - debug_model = debug_model_save; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int free_model_allocs(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * free space allocated in model - */ - int i; - if (x != NULL) { - for (i = 0; i < max_unknowns; i++) { - unknown_free(x[i]); - } - } - x = (struct unknown **) free_check_null(x); - max_unknowns = 0; - array = (LDBLE *) free_check_null(array); - delta = (LDBLE *) free_check_null(delta); - residual = (LDBLE *) free_check_null(residual); - s_x = (struct species **) free_check_null(s_x); - sum_mb1 = (struct list1*) free_check_null(sum_mb1); - sum_mb2 = (struct list2 *) free_check_null(sum_mb2); - sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); - sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); - sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); - sum_delta = (struct list2 *) free_check_null(sum_delta); - charge_group = (struct charge_group *) free_check_null(charge_group); - return(OK); -} -#ifdef SLNQ -/* ---------------------------------------------------------------------- */ -int add_trivial_eqns(int rows, int cols, LDBLE *matrix) -/* ---------------------------------------------------------------------- */ -{ - int r, i, j; - r = rows; - if (rows == cols) return(OK); - if (rows > cols) return(ERROR); - for (i = 0; i < cols; i++) { - for (j = 0; j < rows; j++) { - if (matrix[j*(cols+1) + i] != 0.0) break; - } - if (j < rows) continue; - for (j = 0; j < cols+1; j++) matrix[r*(cols+1) + j] = 0.0; - matrix[r*(cols+1) + i] = 1.0; - r++; - } - if (r == cols) return(OK); - return(ERROR); -} -#endif -#define ZERO_TOL 1.0e-30 -/* ---------------------------------------------------------------------- */ -LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE x0, y0, x1, y1, xb, miny; - -/* - * Bracket answer - */ - x0 = 0.0; - x1 = 0.0; - y0 = s_s_f( x0, a0, a1, kc, kb, xcaq, xbaq); - miny = fabs(y0); - for (i = 1; i <= 10; i++) { - x1 = (LDBLE) i / 10; - y1 = s_s_f( x1, a0, a1, kc, kb, xcaq, xbaq); - if (fabs(y1) < miny) { - miny = fabs(y1); - } - if (y0*y1 < 0) { - break; - } else { - x0 = x1; - y0 = y1; - } - } -/* - * Interval halve - */ - if (i > 10) { - xb = 0.0; - } else { - xb = s_s_halve(a0, a1, x0, x1, kc, kb, xcaq, xbaq); - } - return(xb); -} -/* ---------------------------------------------------------------------- */ -LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE x, y0, dx, y; - - y0 = s_s_f( x0, a0, a1, kc, kb, xcaq, xbaq); - dx = (x1 - x0); -/* - * Loop for interval halving - */ - for (i = 0; i < 100; i++) { - dx *= 0.5; - x = x0 + dx; - y = s_s_f( x, a0, a1, kc, kb, xcaq, xbaq); - if (dx < 1e-8 || y == 0) { - break; - } -#ifdef SKIP - if (y0*y < 0) { - x1 = x; - } else { - x0 = x; - y0 = y; - } -#endif - if (y0*y >= 0) { - x0 = x; - y0 = y; - } - } - return(x0 + dx); -} -/* ---------------------------------------------------------------------- */ -LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq) -/* ---------------------------------------------------------------------- */ -{ -/* - * Need root of this function to determine xb - */ - LDBLE lb, lc, f, xc, r; - xc = 1 - xb; - if (xb == 0) xb = 1e-20; - if (xc == 0) xc = 1e-20; - lc = exp((a0-a1*(-4*xb + 3))*xb*xb); - lb = exp((a0+a1*(4*xb - 3))*xc*xc); - r = lc*kc/(lb*kb); - f = xcaq*(xb/r + xc) + xbaq*(xb + r*xc) - 1; - return(f); -} - - - diff --git a/nvector.cpp b/nvector.cpp deleted file mode 100644 index 331479d8..00000000 --- a/nvector.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************* - * * - * File : nvector.c * - * Programmers : Radu Serban, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic NVECTOR * - * package. It contains the implementation of the N_Vector * - * kernels listed in nvector.h. * - * * - *******************************************************************/ - -#include "nvector.h" /* generic M_Env and N_Vector */ -#include "output.h" -static char const svnid[] = "$Id: nvector.c 78 2005-02-01 22:47:12Z dlpark $"; - -N_Vector N_VNew(integertype n, M_Env machEnv) -{ - N_Vector v_new; - v_new = machEnv->ops->nvnew(n, machEnv); - return(v_new); -} - -N_Vector_S N_VNew_S(integertype ns, integertype n, M_Env machEnv) -{ - N_Vector_S vs_new; - vs_new = machEnv->ops->nvnewS(ns, n, machEnv); - return(vs_new); -} - -void N_VFree(N_Vector v) -{ - v->menv->ops->nvfree(v); -} - -void N_VFree_S(integertype ns, N_Vector_S vs) -{ - (*vs)->menv->ops->nvfreeS(ns, vs); -} - -N_Vector N_VMake(integertype n, realtype *v_data, M_Env machEnv) -{ - N_Vector v_new; - v_new = machEnv->ops->nvmake(n, v_data, machEnv); - return(v_new); -} - -void N_VDispose(N_Vector v) -{ - v->menv->ops->nvdispose(v); -} - -realtype *N_VGetData(N_Vector v) -{ - realtype *data; - data = v->menv->ops->nvgetdata(v); - return(data); -} - -void N_VSetData(realtype *v_data, N_Vector v) -{ - v->menv->ops->nvsetdata(v_data, v); -} - -void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) -{ - z->menv->ops->nvlinearsum(a, x, b, y, z); -} - -void N_VConst(realtype c, N_Vector z) -{ - z->menv->ops->nvconst(c, z); -} - -void N_VProd(N_Vector x, N_Vector y, N_Vector z) -{ - z->menv->ops->nvprod(x, y, z); -} - -void N_VDiv(N_Vector x, N_Vector y, N_Vector z) -{ - z->menv->ops->nvdiv(x, y, z); -} - -void N_VScale(realtype c, N_Vector x, N_Vector z) -{ - z->menv->ops->nvscale(c, x, z); -} - -void N_VAbs(N_Vector x, N_Vector z) -{ - z->menv->ops->nvabs(x, z); -} - -void N_VInv(N_Vector x, N_Vector z) -{ - z->menv->ops->nvinv(x, z); -} - -void N_VAddConst(N_Vector x, realtype b, N_Vector z) -{ - z->menv->ops->nvaddconst(x, b, z); -} - -realtype N_VDotProd(N_Vector x, N_Vector y) -{ - realtype prod; - prod = y->menv->ops->nvdotprod(x, y); - return(prod); -} - -realtype N_VMaxNorm(N_Vector x) -{ - realtype norm; - norm = x->menv->ops->nvmaxnorm(x); - return(norm); -} - -realtype N_VWrmsNorm(N_Vector x, N_Vector w) -{ - realtype norm; - norm = x->menv->ops->nvwrmsnorm(x, w); - return(norm); -} - -realtype N_VMin(N_Vector x) -{ - realtype minval; - minval = x->menv->ops->nvmin(x); - return(minval); -} - -realtype N_VWL2Norm(N_Vector x, N_Vector w) -{ - realtype norm; - norm = x->menv->ops->nvwl2norm(x, w); - return(norm); -} - -realtype N_VL1Norm(N_Vector x) -{ - realtype norm; - norm = x->menv->ops->nvl1norm(x); - return(norm); -} - -void N_VOneMask(N_Vector x) -{ - x->menv->ops->nvonemask(x); -} - -void N_VCompare(realtype c, N_Vector x, N_Vector z) -{ - z->menv->ops->nvcompare(c, x, z); -} - -booleantype N_VInvTest(N_Vector x, N_Vector z) -{ - booleantype flag; - flag = z->menv->ops->nvinvtest(x, z); - return(flag); -} - -booleantype N_VConstrProdPos(N_Vector c, N_Vector x) -{ - booleantype flag; - flag = x->menv->ops->nvconstrprodpos(c, x); - return(flag); -} - -booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m) -{ - booleantype flag; - flag = x->menv->ops->nvconstrmask(c, x, m); - return(flag); -} - -realtype N_VMinQuotient(N_Vector num, N_Vector denom) -{ - realtype quotient; - quotient = num->menv->ops->nvminquotient(num, denom); - return(quotient); -} - -void N_VPrint(N_Vector x) -{ - x->menv->ops->nvprint(x); -} diff --git a/nvector.h b/nvector.h deleted file mode 100644 index 9be6345d..00000000 --- a/nvector.h +++ /dev/null @@ -1,441 +0,0 @@ -/******************************************************************* - * * - * File : nvector.h * - * Programmers : Radu Serban, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic NVECTOR package. * - * It defines the N_Vector and M_Env structures: * - * M_Env has an implementation-dependent 'content' field * - * which contains the data needed to generate a new * - * nvector in that implementation and an 'ops' filed * - * which is a structure listing operations acting on * - * such nvectors. * - * N_Vector has an implementation-dependent 'content' field * - * which contains the description and actual data of * - * the nvector and a 'menv' field which points to the * - * M_Env structure used in creating the nvector. * - * * - * Part I of this file contains type declarations for the * - * the following structures: _generic_M_Env, _generic_N_Vector, * - * and _generic_N_Vector_Ops, as well as references to pointers * - * to such structures (M_Env and N_Vector). * - * * - * Part II of this file contains the prototypes for the vector * - * kernels which operate on N_Vector. * - * * - * A particular implementation of an NVECTOR package must then * - * specify the 'content' fields of M_Env and N_Vector, define * - * the propotypes for kernel operations on those N_Vectors * - * (NOTE: kernel routine names must be unique to that * - * implementation), and finally provide an initialization * - * routine (which generates an M_Env with that particular * - * 'content' field and links the defined vector kernel routines * - * into the 'ops' field). * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidnvector[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef included_nvector_h -#define included_nvector_h - -#include "sundialstypes.h" /* definition of types */ - -/**************************************************************** - * Generic definitions of machine environment and N_Vector * - ****************************************************************/ - -/* Forward reference for pointer to N_Vector_Ops object */ -typedef struct _generic_N_Vector_Ops *N_Vector_Ops; - -/* Forward reference for pointer to M_Env object */ -typedef struct _generic_M_Env *M_Env; - -/* Forward reference for pointer to N_Vector object */ -typedef struct _generic_N_Vector *N_Vector; - -/* Define array of N_Vectors */ -typedef N_Vector *N_Vector_S; - -/* Structure containing function pointers to vector operations */ -struct _generic_N_Vector_Ops { - N_Vector (*nvnew)(integertype, M_Env); - N_Vector_S (*nvnewS)(integertype, integertype, M_Env); - void (*nvfree)(N_Vector); - void (*nvfreeS)(integertype, N_Vector_S); - N_Vector (*nvmake)(integertype, realtype *, M_Env); - void (*nvdispose)(N_Vector); - realtype* (*nvgetdata)(N_Vector); - void (*nvsetdata)(realtype *, N_Vector); - void (*nvlinearsum)(realtype, N_Vector, realtype, N_Vector, N_Vector); - void (*nvconst)(realtype, N_Vector); - void (*nvprod)(N_Vector, N_Vector, N_Vector); - void (*nvdiv)(N_Vector, N_Vector, N_Vector); - void (*nvscale)(realtype, N_Vector, N_Vector); - void (*nvabs)(N_Vector, N_Vector); - void (*nvinv)(N_Vector, N_Vector); - void (*nvaddconst)(N_Vector, realtype, N_Vector); - realtype (*nvdotprod)(N_Vector, N_Vector); - realtype (*nvmaxnorm)(N_Vector); - realtype (*nvwrmsnorm)(N_Vector, N_Vector); - realtype (*nvmin)(N_Vector); - realtype (*nvwl2norm)(N_Vector, N_Vector); - realtype (*nvl1norm)(N_Vector); - void (*nvonemask)(N_Vector); - void (*nvcompare)(realtype, N_Vector, N_Vector); - booleantype (*nvinvtest)(N_Vector, N_Vector); - booleantype (*nvconstrprodpos)(N_Vector, N_Vector); - booleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector); - realtype (*nvminquotient)(N_Vector, N_Vector); - void (*nvprint)(N_Vector); -}; - -/* A machine environment is a structure with an implementation - dependent 'content' representation (used to generate a new vector - in that implementation), a set of operations defined in the above - structure, and an ID tag */ -struct _generic_M_Env { - void *content; - struct _generic_N_Vector_Ops *ops; - char tag[8]; -}; - -/* A vector is a structure with an implementation dependent content - representation and a pointer to the machine environment - corresponding to that implementation */ -struct _generic_N_Vector { - void *content; - struct _generic_M_Env *menv; -}; - -/**************************************************************** - * Functions exported by nvector * - ****************************************************************/ - -/*--------------------------------------------------------------* - * Function : N_VNew * - * Usage : v = N_VNew(n, machEnv); * - *--------------------------------------------------------------* - * Returns a new N_Vector of length n. The parameter machEnv * - * is a pointer to machine environment-specific information. * - * If there is not enough memory for a new N_Vector, then * - * N_VNew returns NULL. * - *--------------------------------------------------------------*/ - -N_Vector N_VNew(integertype n, M_Env machEnv); - -/*--------------------------------------------------------------* - * Function : N_VNew_S * - * Usage : v = N_VNew_S(ns, n, machEnv); * - *--------------------------------------------------------------* - * Returns an array of ns new N_Vectors of length n. The * - * parameter machEnv is a pointer to machine environment * - * specific information. * - * If there is not enough memory for a new array of N_Vectors * - * or for one of the components, then N_VNew_S returns NULL. * - *--------------------------------------------------------------*/ - -N_Vector_S N_VNew_S(integertype ns, integertype n, M_Env machEnv); - -/*--------------------------------------------------------------* - * Function : N_VFree * - * Usage : N_VFree(v); * - *--------------------------------------------------------------* - * Frees the N_Vector v. It is illegal to use v after the call * - * N_VFree(v). * - *--------------------------------------------------------------*/ - -void N_VFree(N_Vector v); - -/*--------------------------------------------------------------* - * Function : N_VFree_S * - * Usage : N_VFree_S(ns, vs); * - *--------------------------------------------------------------* - * Frees the array of ns N_Vectors vs. * - * It is illegal to use vs after the call N_VFree_S(Ns,vs). * - *--------------------------------------------------------------*/ - -void N_VFree_S(integertype ns, N_Vector_S vs); - -/*--------------------------------------------------------------* - * Function : N_VMake * - * Usage : v = N_VMake(n, v_data, machEnv); * - *--------------------------------------------------------------* - * Creates an N_Vector with component array data allocated by * - * the user. * - *--------------------------------------------------------------*/ - -N_Vector N_VMake(integertype n, realtype *v_data, M_Env machEnv); - -/*--------------------------------------------------------------* - * Function : N_VDispose * - * Usage : N_VDispose(v); * - *--------------------------------------------------------------* - * Destroys an N_Vector with component array data allocated by * - * the user. * - *--------------------------------------------------------------*/ - -void N_VDispose(N_Vector v); - -/*--------------------------------------------------------------* - * Function : N_VGetData * - * Usage : v_data = N_VGetData(v); * - *--------------------------------------------------------------* - * Extracts the data component array from the N_Vector v. * - * Note: this routine is used in the solver-specific interfaces * - * to the dense and banded linear solvers, as well as the * - * interfaces to the banded preconditioners provided with * - * SUNDIALS. It needs not be implemented by a user * - * defined NVECTOR module, if these linear solvers are not* - * used. * - *--------------------------------------------------------------*/ - -realtype *N_VGetData(N_Vector v); - -/*--------------------------------------------------------------* - * Function : N_VSetData * - * Usage : N_VSetData(v_data, v); * - *--------------------------------------------------------------* - * Attaches the data component array v_data to the N_Vector v. * - * Note: this routine is used in the solver-specific interfaces * - * to the dense and banded linear solvers, as well as the * - * interfaces to the banded preconditioners provided with * - * SUNDIALS. It needs not be implemented by a user * - * defined NVECTOR module, if these linear solvers are not* - * used. * - *--------------------------------------------------------------*/ - -void N_VSetData(realtype *v_data, N_Vector v); - -/*--------------------------------------------------------------* - * Function : N_VLinearSum * - * Operation : z = a x + b y * - *--------------------------------------------------------------*/ - -void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, - N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VConst * - * Operation : z[i] = c for i=0, 1, ..., N-1 * - *--------------------------------------------------------------*/ - -void N_VConst(realtype c, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VProd * - * Operation : z[i] = x[i] * y[i] for i=0, 1, ..., N-1 * - *--------------------------------------------------------------*/ - -void N_VProd(N_Vector x, N_Vector y, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VDiv * - * Operation : z[i] = x[i] / y[i] for i=0, 1, ..., N-1 * - *--------------------------------------------------------------*/ - -void N_VDiv(N_Vector x, N_Vector y, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VScale * - * Operation : z = c x * - *--------------------------------------------------------------*/ - -void N_VScale(realtype c, N_Vector x, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VAbs * - * Operation : z[i] = |x[i]|, for i=0, 1, ..., N-1 * - *--------------------------------------------------------------*/ - -void N_VAbs(N_Vector x, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VInv * - * Operation : z[i] = 1.0 / x[i] for i = 0, 1, ..., N-1 * - *--------------------------------------------------------------* - * This routine does not check for division by 0. It should be * - * called only with an N_Vector x which is guaranteed to have * - * all non-zero components. * - *--------------------------------------------------------------*/ - -void N_VInv(N_Vector x, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VAddConst * - * Operation : z[i] = x[i] + b for i = 0, 1, ..., N-1 * - *--------------------------------------------------------------*/ - -void N_VAddConst(N_Vector x, realtype b, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VDotProd * - * Usage : dotprod = N_VDotProd(x, y); * - *--------------------------------------------------------------* - * Returns the value of the ordinary dot product of x and y: * - * -> sum (i=0 to N-1) {x[i] * y[i]} * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VDotProd(N_Vector x, N_Vector y); - -/*--------------------------------------------------------------* - * Function : N_VMaxNorm * - * Usage : maxnorm = N_VMaxNorm(x); * - *--------------------------------------------------------------* - * Returns the maximum norm of x: * - * -> max (i=0 to N-1) |x[i]| * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VMaxNorm(N_Vector x); - -/*--------------------------------------------------------------* - * Function : N_VWrmsNorm * - * Usage : wrmsnorm = N_VWrmsNorm(x, w); * - *--------------------------------------------------------------* - * Returns the weighted root mean square norm of x with * - * weight vector w: * - * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) / N] * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VWrmsNorm(N_Vector x, N_Vector w); - -/*--------------------------------------------------------------* - * Function : N_VMin * - * Usage : min = N_VMin(x); * - *--------------------------------------------------------------* - * Returns the smallest element of x: * - * -> min (i=0 to N-1) x[i] * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VMin(N_Vector x); - -/*--------------------------------------------------------------* - * Function : N_VWL2Norm * - * Usage : wl2norm = N_VWL2Norm(x, w); * - *--------------------------------------------------------------* - * Returns the weighted Euclidean L2 norm of x with * - * weight vector w: * - * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) ] * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VWL2Norm(N_Vector x, N_Vector w); - -/*--------------------------------------------------------------* - * Function : N_VL1Norm * - * Usage : l1norm = N_VL1Norm(x); * - *--------------------------------------------------------------* - * Returns the L1 norm of x: * - * -> sum (i=0 to N-1) {ABS(x[i])} * - * Returns 0.0 if N <= 0. * - *--------------------------------------------------------------*/ - -realtype N_VL1Norm(N_Vector x); - -/*--------------------------------------------------------------* - * Function : N_VOneMask * - * Operation : x[i] = 1.0 if |x[i]| != 0. i = 0, 1, ..., N-1 * - * 0.0 otherwise * - *--------------------------------------------------------------*/ - -void N_VOneMask(N_Vector x); - -/*--------------------------------------------------------------* - * Function : N_VCompare * - * Operation : z[i] = 1.0 if |x[i]| >= c i = 0, 1, ..., N-1 * - * 0.0 otherwise * - *--------------------------------------------------------------*/ - -void N_VCompare(realtype c, N_Vector x, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VInvTest * - * Operation : z[i] = 1.0 / x[i] with a test for x[i]==0.0 * - * before inverting x[i]. * - *--------------------------------------------------------------* - * This routine returns TRUE if all components of x are * - * non-zero (successful inversion) and returns FALSE * - * otherwise. * - *--------------------------------------------------------------*/ - -booleantype N_VInvTest(N_Vector x, N_Vector z); - -/*--------------------------------------------------------------* - * Function : N_VConstrProdPos * - * Usage : booltest = N_VConstrProdPos(c,x); * - *--------------------------------------------------------------* - * Returns a boolean equal to * - * FALSE if some c[i] != 0.0 and x[i]*c[i] <= 0.0, or * - * TRUE otherwise. * - * * - * This routine is used for constraint checking. * - *--------------------------------------------------------------*/ - -booleantype N_VConstrProdPos(N_Vector c, N_Vector x); - -/*--------------------------------------------------------------* - * Function : N_VConstrMask * - * Operation : m[i] = 1.0 if constraint test fails for x[i] * - * m[i] = 0.0 if constraint test passes for x[i] * - * where the constraint tests are as follows: * - * If c[i] = 2.0, then x[i] must be > 0.0. * - * If c[i] = 1.0, then x[i] must be >= 0.0. * - * If c[i] = -1.0, then x[i] must be <= 0.0. * - * If c[i] = -2.0, then x[i] must be < 0.0. * - *--------------------------------------------------------------* - * This routine returns a boolean FALSE if any element failed * - * the constraint test, TRUE if all passed. It also sets a * - * mask vector m, with elements equal to 1.0 where the * - * corresponding constraint test failed, and equal to 0.0 * - * where the constraint test passed. * - * This routine is specialized in that it is used only for * - * constraint checking. * - *--------------------------------------------------------------*/ - -booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); - -/*--------------------------------------------------------------* - * Function : N_VMinQuotient * - * Operation : minq = min ( num[i]/denom[i]) over all i such * - * that denom[i] != 0. * - *--------------------------------------------------------------* - * This routine returns the minimum of the quotients obtained * - * by term-wise dividing num[i] by denom[i]. A zero element * - * in denom will be skipped. If no such quotients are found, * - * then the large value 1.e99 is returned. * - *--------------------------------------------------------------*/ - -realtype N_VMinQuotient(N_Vector num, N_Vector denom); - -/*--------------------------------------------------------------* - * Function : N_VPrint * - * Usage : N_VPrint(x); * - *--------------------------------------------------------------* - * Prints the N_Vector x to stdout. * - * This routine is provided as an aid in debugging code which * - * uses this vector package. * - *--------------------------------------------------------------*/ - -void N_VPrint(N_Vector x); - - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/nvector_serial.cpp b/nvector_serial.cpp deleted file mode 100644 index cef66fd6..00000000 --- a/nvector_serial.cpp +++ /dev/null @@ -1,869 +0,0 @@ -/******************************************************************* - * * - * File : nvector_serial.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * - * Radu Serban, and Allan G. Taylor, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a serial implementation * - * of the NVECTOR package. It contains the implementation of * - * the serial machine environment intialization and free * - * routines (and of the Fortran callable interfaces to them) * - * and of the N_Vector kernels listed in nvector_serial.h. * - * * - *******************************************************************/ - -#include -#include -#include -#include "nvector_serial.h" -#include "sundialstypes.h" -#include "sundialsmath.h" -#include "output.h" -#include "phqalloc.h" -/* WARNING don't include any headers below here */ -#define malloc PHRQ_malloc -static char const svnid[] = "$Id: nvector_serial.c 663 2005-11-16 00:46:04Z dlpark $"; - -#define ZERO RCONST(0.0) -#define HALF RCONST(0.5) -#define ONE RCONST(1.0) -#define ONEPT5 RCONST(1.5) - - -/* Private Helper Prototypes */ -/* z=x */ -static void VCopy_Serial(N_Vector x, N_Vector z); -/* z=x+y */ -static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z); -/* z=x-y */ -static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z); -/* z=-x */ -static void VNeg_Serial(N_Vector x, N_Vector z); -/* z=c(x+y) */ -static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); -/* z=c(x-y) */ -static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); -/* z=ax+y */ -static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); -/* z=ax-y */ -static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); -/* y <- ax+y */ -static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y); -/* x <- ax */ -static void VScaleBy_Serial(realtype a, N_Vector x); - -/********************* Exported Functions ************************/ - -/* Serial implementation of the machine environment - initialization routine */ - -M_Env M_EnvInit_Serial(integertype vec_length) -{ - M_Env me; - - if (svnid == NULL) fprintf(stderr," "); - /* Create machine environment structure */ - me = (M_Env) malloc(sizeof *me); - if (me == NULL) return(NULL); - - /* Create serial content of machine environment structure */ - me->content = (M_EnvSerialContent) malloc(sizeof(struct _M_EnvSerialContent)); - if (me->content == NULL) { - free(me); - return(NULL); - } - - /* Load serial content of machine environment structure */ - ME_CONTENT_S(me)->length = vec_length; - - /* Attach vector operations */ - me->ops = (N_Vector_Ops) malloc(sizeof(struct _generic_N_Vector_Ops)); - if (me->ops == NULL) { - free(me->content); - free(me); - return(NULL); - } - - me->ops->nvnew = N_VNew_Serial; - me->ops->nvnewS = N_VNew_S_Serial; - me->ops->nvfree = N_VFree_Serial; - me->ops->nvfreeS = N_VFree_S_Serial; - me->ops->nvmake = N_VMake_Serial; - me->ops->nvdispose = N_VDispose_Serial; - me->ops->nvgetdata = N_VGetData_Serial; - me->ops->nvsetdata = N_VSetData_Serial; - me->ops->nvlinearsum = N_VLinearSum_Serial; - me->ops->nvconst = N_VConst_Serial; - me->ops->nvprod = N_VProd_Serial; - me->ops->nvdiv = N_VDiv_Serial; - me->ops->nvscale = N_VScale_Serial; - me->ops->nvabs = N_VAbs_Serial; - me->ops->nvinv = N_VInv_Serial; - me->ops->nvaddconst = N_VAddConst_Serial; - me->ops->nvdotprod = N_VDotProd_Serial; - me->ops->nvmaxnorm = N_VMaxNorm_Serial; - me->ops->nvwrmsnorm = N_VWrmsNorm_Serial; - me->ops->nvmin = N_VMin_Serial; - me->ops->nvwl2norm = N_VWL2Norm_Serial; - me->ops->nvl1norm = N_VL1Norm_Serial; - me->ops->nvonemask = N_VOneMask_Serial; - me->ops->nvcompare = N_VCompare_Serial; - me->ops->nvinvtest = N_VInvTest_Serial; - me->ops->nvconstrprodpos = N_VConstrProdPos_Serial; - me->ops->nvconstrmask = N_VConstrMask_Serial; - me->ops->nvminquotient = N_VMinQuotient_Serial; - me->ops->nvprint = N_VPrint_Serial; - - /* Attach ID tag */ - strcpy(me->tag, ID_TAG_S); - - return(me); - -} - -/* Serial implementation of the machine environment - free routine */ - -void M_EnvFree_Serial(M_Env machEnv) -{ - if (machEnv == NULL) return; - - free(machEnv->content); - free(machEnv->ops); - free(machEnv); -} - -/***************************************************************************/ - -/* BEGIN implementation of vector operations */ - -N_Vector N_VNew_Serial(integertype n, M_Env machEnv) -{ - N_Vector v; - integertype length; - - if (n <= 0) return(NULL); - - if (machEnv == NULL) return(NULL); - - v = (N_Vector) malloc(sizeof *v); - if (v == NULL) return(NULL); - - v->content = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); - if (v->content == NULL) { - free(v); - return(NULL); - } - - length = ME_CONTENT_S(machEnv)->length; - - NV_CONTENT_S(v)->data = (realtype *) malloc(length * sizeof(realtype)); - if(NV_CONTENT_S(v)->data == NULL) { - free(v->content); - free(v); - return(NULL); - } - - NV_CONTENT_S(v)->length = length; - - v->menv = machEnv; - - return(v); -} - - -N_Vector_S N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv) -{ - N_Vector_S vs; - integertype is, j; - - - if (ns <= 0 || n <= 0) return(NULL); - - if (machEnv == NULL) return(NULL); - - vs = (N_Vector_S) malloc(ns * sizeof(N_Vector *)); - if (vs == NULL) return(NULL); - - for (is=0; iscontent = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); - if (v->content == NULL) { - free(v); - return(NULL); - } - - length = ME_CONTENT_S(machEnv)->length; - - NV_CONTENT_S(v)->data = v_data; - - NV_CONTENT_S(v)->length = length; - - v->menv = machEnv; - - return(v); -} - -void N_VDispose_Serial(N_Vector v) -{ - free(NV_CONTENT_S(v)); - free(v); -} - -realtype *N_VGetData_Serial(N_Vector v) -{ - realtype *v_data; - v_data = NV_CONTENT_S(v)->data; - return(v_data); -} - -void N_VSetData_Serial(realtype *v_data, N_Vector v) -{ - NV_CONTENT_S(v)->data = v_data; -} - -void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) -{ - integertype i, N; - realtype c, *xd, *yd, *zd; - N_Vector v1, v2; - booleantype test; - - if ((b == ONE) && (z == y)) { /* BLAS usage: axpy y <- ax+y */ - Vaxpy_Serial(a,x,y); - return; - } - - if ((a == ONE) && (z == x)) { /* BLAS usage: axpy x <- by+x */ - Vaxpy_Serial(b,y,x); - return; - } - - /* Case: a == b == 1.0 */ - - if ((a == ONE) && (b == ONE)) { - VSum_Serial(x, y, z); - return; - } - - /* Cases: (1) a == 1.0, b = -1.0, (2) a == -1.0, b == 1.0 */ - - /*if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) {*/ - test = ((a == ONE) && (b == -ONE)); - if (test || ((a == -ONE) && (b == ONE))) { - v1 = test ? y : x; - v2 = test ? x : y; - VDiff_Serial(v2, v1, z); - return; - } - - /* Cases: (1) a == 1.0, b == other or 0.0, (2) a == other or 0.0, b == 1.0 */ - /* if a or b is 0.0, then user should have called N_VScale */ - - /*if ((test = (a == ONE)) || (b == ONE)) {*/ - test = (a == ONE); - if (test || (b == ONE)) { - c = test ? b : a; - v1 = test ? y : x; - v2 = test ? x : y; - VLin1_Serial(c, v1, v2, z); - return; - } - - /* Cases: (1) a == -1.0, b != 1.0, (2) a != 1.0, b == -1.0 */ - - /*if ((test = (a == -ONE)) || (b == -ONE)) {*/ - test = (a == -ONE); - if (test || (b == -ONE)) { - c = test ? b : a; - v1 = test ? y : x; - v2 = test ? x : y; - VLin2_Serial(c, v1, v2, z); - return; - } - - /* Case: a == b */ - /* catches case both a and b are 0.0 - user should have called N_VConst */ - - if (a == b) { - VScaleSum_Serial(a, x, y, z); - return; - } - - /* Case: a == -b */ - - if (a == -b) { - VScaleDiff_Serial(a, x, y, z); - return; - } - - /* Do all cases not handled above: - (1) a == other, b == 0.0 - user should have called N_VScale - (2) a == 0.0, b == other - user should have called N_VScale - (3) a,b == other, a !=b, a != -b */ - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - yd = NV_DATA_S(y); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = a * (*xd++) + b * (*yd++); -} - - -void N_VConst_Serial(realtype c, N_Vector z) -{ - integertype i, N; - realtype *zd; - - N = NV_LENGTH_S(z); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = c; -} - - -void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) -{ - integertype i, N; - realtype *xd, *yd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - yd = NV_DATA_S(y); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = (*xd++) * (*yd++); -} - - -void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z) -{ - integertype i, N; - realtype *xd, *yd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - yd = NV_DATA_S(y); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = (*xd++) / (*yd++); -} - - -void N_VScale_Serial(realtype c, N_Vector x, N_Vector z) -{ - integertype i, N; - realtype *xd, *zd; - - if (z == x) { /* BLAS usage: scale x <- cx */ - VScaleBy_Serial(c, x); - return; - } - - if (c == ONE) { - VCopy_Serial(x, z); - } else if (c == -ONE) { - VNeg_Serial(x, z); - } else { - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - zd = NV_DATA_S(z); - for (i=0; i < N; i++) - *zd++ = c * (*xd++); - } -} - - -void N_VAbs_Serial(N_Vector x, N_Vector z) -{ - integertype i, N; - realtype *xd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++, xd++, zd++) - *zd = ABS(*xd); -} - - -void N_VInv_Serial(N_Vector x, N_Vector z) -{ - integertype i, N; - realtype *xd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = ONE / (*xd++); -} - - -void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z) -{ - integertype i, N; - realtype *xd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) - *zd++ = (*xd++) + b; -} - - -realtype N_VDotProd_Serial(N_Vector x, N_Vector y) -{ - integertype i, N; - realtype sum = ZERO, *xd, *yd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - yd = NV_DATA_S(y); - - for (i=0; i < N; i++) - sum += (*xd++) * (*yd++); - - return(sum); -} - - -realtype N_VMaxNorm_Serial(N_Vector x) -{ - integertype i, N; - realtype max = ZERO, *xd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - - for (i=0; i < N; i++, xd++) { - if (ABS(*xd) > max) max = ABS(*xd); - } - - return(max); -} - - -realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w) -{ - integertype i, N; - realtype sum = ZERO, prodi, *xd, *wd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - wd = NV_DATA_S(w); - - for (i=0; i < N; i++) { - prodi = (*xd++) * (*wd++); - sum += prodi * prodi; - } - - return(RSqrt(sum / N)); -} - - -realtype N_VMin_Serial(N_Vector x) -{ - integertype i, N; - realtype min, *xd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - - min = xd[0]; - - xd++; - for (i=1; i < N; i++, xd++) { - if ((*xd) < min) min = *xd; - } - - return(min); -} - - -realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w) -{ - integertype i, N; - realtype sum = ZERO, prodi, *xd, *wd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - wd = NV_DATA_S(w); - - for (i=0; i < N; i++) { - prodi = (*xd++) * (*wd++); - sum += prodi * prodi; - } - - return(RSqrt(sum)); -} - - -realtype N_VL1Norm_Serial(N_Vector x) -{ - integertype i, N; - realtype sum = ZERO, *xd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - - for (i=0; i= c) ? ONE : ZERO; - } -} - - -booleantype N_VInvTest_Serial(N_Vector x, N_Vector z) -{ - integertype i, N; - realtype *xd, *zd; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - zd = NV_DATA_S(z); - - for (i=0; i < N; i++) { - if (*xd == ZERO) return(FALSE); - *zd++ = ONE / (*xd++); - } - - return(TRUE); -} - - -booleantype N_VConstrProdPos_Serial(N_Vector c, N_Vector x) -{ - integertype i, N; - realtype *xd, *cd; - booleantype test; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - cd = NV_DATA_S(c); - - test = TRUE; - - for (i=0; i < N; i++, xd++,cd++) { - if (*cd != ZERO) { - if ((*xd)*(*cd) <= ZERO) { - test = FALSE; - break; - } - } - } - return(test); -} - - -booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) -{ - integertype i, N; - booleantype test; - realtype *cd, *xd, *md; - - N = NV_LENGTH_S(x); - xd = NV_DATA_S(x); - cd = NV_DATA_S(c); - md = NV_DATA_S(m); - - test = TRUE; - - for (i=0; i ONEPT5 || (*cd) < -ONEPT5) { - if ( (*xd)*(*cd) <= ZERO) {test = FALSE; *md = ONE; } - continue; - } - if ( (*cd) > HALF || (*cd) < -HALF) { - if ( (*xd)*(*cd) < ZERO ) {test = FALSE; *md = ONE; } - } - } - return(test); -} - - -realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom) -{ - booleantype notEvenOnce; - integertype i, N; - realtype *nd, *dd, min; - - N = NV_LENGTH_S(num); - nd = NV_DATA_S(num); - dd = NV_DATA_S(denom); - min = 0; - - notEvenOnce = TRUE; - - for (i=0; i since these macros expand to calls to * - * malloc and free. * - * * - * When looping over the components of an N_Vector v, it is * - * more efficient to first obtain the component array via * - * v_data=NV_DATA_S(v) and then access v_data[i] within the * - * loop than it is to use NV_Ith_S(v,i) within the loop. * - * * - * NV_MAKE_S and NV_DISPOSE_S are similar to N_VNew_Serial and * - * N_VFree_Serial, while NVS_MAKE_S and NVS_DISPOSE_S are * - * similar to N_VNew_S_Serial and N_VFree_S_Serial. The * - * difference is one of responsibility for component memory * - * allocation and deallocation. N_VNew_Serial allocates memory * - * for the N_Vector components and N_VFree_Serial frees the * - * component memory allocated by N_VNew_Serial. For NV_MAKE_S * - * and NV_DISPOSE_S, the component memory is allocated and * - * freed by the user of this package. Similar remarks hold for * - * NVS_MAKE_S, NVS_DISPOSE_S and N_VNew_S_Serial, * - * N_VFree_S_Serial. * - * * - ****************************************************************/ - -#define NV_MAKE_S(v, v_data, machenv) \ - v = (N_Vector) malloc(sizeof(*v)); \ - v->content = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); \ - v->content->data = v_data; \ - v->content->length = machenv->content->v_len; \ - v->menv = machenv - -#define NV_DISPOSE_S(v) \ - free((N_VectorSerialContent)(v->content)); \ - free(v) - -#define NVS_MAKE_S(vs, vs_data, s_len, machenv) \ - vs = (N_Vector_S) malloc(s_len*sizeof(N_Vector *)); \ - for ((int)is=0; iscontent) ) - -#define NV_CONTENT_S(v) ( (N_VectorSerialContent)(v->content) ) - -#define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) - -#define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) - -#define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) - - -/**************************************************************** - * PART III: * - * Functions exported by nvector_serial * - ****************************************************************/ - -/*--------------------------------------------------------------* - * Routine : M_EnvInit_Serial * - *--------------------------------------------------------------* - * This function sets the content field of the machine * - * environment for the serial implementation to a structure of * - * type _MEnvSerialContent and attaches the vector operations * - * defined for this implementation. * - * * - * If successful, M_EnvInit_Serial returns a pointer of type * - * M_Env. This pointer should in turn be passed in any user * - * calls to N_VNew, or uses of the macros NV_MAKE_S and * - * NVS_MAKE_S. * - * * - *--------------------------------------------------------------* - * * - * vec_length is the length of the vector. * - * * - *--------------------------------------------------------------*/ - -M_Env M_EnvInit_Serial(integertype vec_length); - -/*--------------------------------------------------------------* - * Function M_EnvFree_Serial * - *--------------------------------------------------------------* - * Function to free the block of machine-dependent environment * - * information created by M_EnvInit_Serial. * - * Its only argument is the pointer machenv returned by * - * M_EnvInit_Serial. * - * * - *--------------------------------------------------------------*/ - -void M_EnvFree_Serial(M_Env machenv); - -/*--------------------------------------------------------------* - * Serial implementations of the vector operations * - * * - * For a complete description of each of the following routines * - * see the header file nvector.h * - *--------------------------------------------------------------*/ - -N_Vector N_VNew_Serial(integertype n, M_Env machEnv); -N_Vector_S N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv); -void N_VFree_Serial(N_Vector v); -void N_VFree_S_Serial(integertype ns, N_Vector_S vs); -N_Vector N_VMake_Serial(integertype n, realtype *v_data, M_Env machEnv); -void N_VDispose_Serial(N_Vector v); -realtype *N_VGetData_Serial(N_Vector v); -void N_VSetData_Serial(realtype *v_data, N_Vector v); -void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); -void N_VConst_Serial(realtype c, N_Vector z); -void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); -void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); -void N_VScale_Serial(realtype c, N_Vector x, N_Vector z); -void N_VAbs_Serial(N_Vector x, N_Vector z); -void N_VInv_Serial(N_Vector x, N_Vector z); -void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z); -realtype N_VDotProd_Serial(N_Vector x, N_Vector y); -realtype N_VMaxNorm_Serial(N_Vector x); -realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); -realtype N_VMin_Serial(N_Vector x); -realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); -realtype N_VL1Norm_Serial(N_Vector x); -void N_VOneMask_Serial(N_Vector x); -void N_VCompare_Serial(realtype c, N_Vector x, N_Vector z); -booleantype N_VInvTest_Serial(N_Vector x, N_Vector z); -booleantype N_VConstrProdPos_Serial(N_Vector c, N_Vector x); -booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); -realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); -void N_VPrint_Serial(N_Vector x); - - - -#endif -#ifdef __cplusplus -} -#endif diff --git a/output.cpp b/output.cpp deleted file mode 100644 index 51ecd413..00000000 --- a/output.cpp +++ /dev/null @@ -1,182 +0,0 @@ -#define EXTERNAL extern -#include -#include "global.h" -#include "output.h" -#include "phrqproto.h" -#include "phqalloc.h" -static char const svnid[] = "$Id: output.c 663 2005-11-16 00:46:04Z dlpark $"; - -#define MAX_CALLBACKS 10 -static struct output_callback output_callbacks[MAX_CALLBACKS]; -static size_t count_output_callback = 0; -static int forward_output_to_log = 0; - -/* ---------------------------------------------------------------------- */ -int add_output_callback(PFN_OUTPUT_CALLBACK pfn, void *cookie) -/* ---------------------------------------------------------------------- */ -{ - if (svnid == NULL) fprintf(stderr," "); - if (pfn) { - if (count_output_callback >= MAX_CALLBACKS - 1) { - sprintf(error_string, "Too many callbacks.\nSee %s\n", __FILE__); - fprintf(stderr, "%s", error_string); - error_msg(error_string, STOP); - return ERROR; - } - output_callbacks[count_output_callback].callback = pfn; - output_callbacks[count_output_callback].cookie = cookie; - ++count_output_callback; - } - return OK; -} - -/* ---------------------------------------------------------------------- */ -int output_message(const int type, const char *err_str, const int stop, const char *format, va_list args) -/* ---------------------------------------------------------------------- */ -{ - extern jmp_buf mark; - size_t i; - - for (i = 0; i < count_output_callback; ++i) { - (output_callbacks[i].callback)(ACTION_OUTPUT, type, err_str, stop, output_callbacks[i].cookie, format, args); - } - - if (stop == STOP) { - longjmp(mark, input_error); - } - return OK; -} - -/* ---------------------------------------------------------------------- */ -int clean_up_output_callbacks(void) -/* ---------------------------------------------------------------------- */ -{ - count_output_callback = 0; - return OK; -} - -/* ---------------------------------------------------------------------- */ -int error_msg (const char *err_str, const int stop, ...) -/* ---------------------------------------------------------------------- */ -{ - va_list args; - int return_value; - - if (input_error <= 0) input_error = 1; - va_start(args, stop); - return_value = output_message(OUTPUT_ERROR, err_str, stop, "", args); - va_end(args); - return(return_value); -} - -/* ---------------------------------------------------------------------- */ -int warning_msg (const char *err_str, ...) -/* ---------------------------------------------------------------------- */ -{ - va_list args; - int return_value; - - va_start(args, err_str); - return_value = output_message(OUTPUT_WARNING, err_str, CONTINUE, "", args); - count_warnings++; - va_end(args); - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int output_msg (const int type, const char* format, ...) -/* ---------------------------------------------------------------------- */ -{ - int return_value; - va_list args; - - va_start(args, format); - return_value = output_message(type, NULL, CONTINUE, format, args); - va_end(args); - - return(return_value); -} -/* ---------------------------------------------------------------------- */ -void set_forward_output_to_log(int value) -/* ---------------------------------------------------------------------- */ -{ - forward_output_to_log = value; -} -/* ---------------------------------------------------------------------- */ -int get_forward_output_to_log(void) -/* ---------------------------------------------------------------------- */ -{ - return forward_output_to_log; -} -/* ---------------------------------------------------------------------- */ -int output_fflush(const int type, ...) -/* ---------------------------------------------------------------------- */ -{ - size_t i; - int check; - va_list args; - - check = OK; - va_start(args, type); - for (i = 0; i < count_output_callback; ++i) { - check = (output_callbacks[i].callback)(ACTION_FLUSH, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); - if (check != OK) break; - } - va_end(args); - if (check != OK) return(ERROR); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int output_rewind(const int type, ...) -/* ---------------------------------------------------------------------- */ -{ - size_t i; - int check; - va_list args; - - check = OK; - va_start(args, type); - for (i = 0; i < count_output_callback; ++i) { - check = (output_callbacks[i].callback)(ACTION_REWIND, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); - if (check != OK) break; - } - va_end(args); - if (check != OK) return(ERROR); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int output_close(const int type, ...) -/* ---------------------------------------------------------------------- */ -{ - size_t i; - int check; - va_list args; - - check = OK; - va_start(args, type); - for (i = 0; i < count_output_callback; ++i) { - check = (output_callbacks[i].callback)(ACTION_CLOSE, type, NULL, CONTINUE, output_callbacks[i].cookie, NULL, args); - if (check != OK) break; - } - va_end(args); - if (check != OK) return(ERROR); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int output_open(const int type, const char *file_name, ...) -/* ---------------------------------------------------------------------- */ -{ - size_t i; - int check; - va_list args; - assert(file_name && strlen(file_name)); - - check = OK; - va_start(args, file_name); - for (i = 0; i < count_output_callback; ++i) { - check = (output_callbacks[i].callback)(ACTION_OPEN, type, file_name, CONTINUE, output_callbacks[i].cookie, NULL, args); - if (check != OK) break; - } - va_end(args); - if (check != OK) return(ERROR); - return(OK); -} diff --git a/output.h b/output.h deleted file mode 100644 index 4ad59e67..00000000 --- a/output.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _INC_MESSAGE_H -#define _INC_MESSAGE_H - -#include -#ifdef PHREEQC_IDENT -static char const svnidoutput[] = "$Id$"; -#endif - -typedef int (*PFN_OUTPUT_CALLBACK)(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *, va_list args); - -struct output_callback { - PFN_OUTPUT_CALLBACK callback; - void *cookie; -}; - -int add_output_callback(PFN_OUTPUT_CALLBACK pfn, void *cookie); -int clean_up_output_callbacks(void); -int output_msg (const int type, const char* format, ...); -int warning_msg (const char *err_str, ...); -int error_msg (const char *err_str, const int stop, ...); -int phreeqc_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *, va_list args); -void set_forward_output_to_log(int value); -int get_forward_output_to_log(void); - -/* - * Functions for output callbacks - */ -int output_open(const int type, const char *file_name, ...); -int output_fflush(const int type, ...); -int output_rewind(const int type, ...); -int output_close(const int type, ...); - -typedef enum { - OUTPUT_ERROR, - OUTPUT_WARNING, - OUTPUT_MESSAGE, - OUTPUT_PUNCH, - OUTPUT_SCREEN, - OUTPUT_LOG, - OUTPUT_CHECKLINE, - OUTPUT_GUI_ERROR, - OUTPUT_BASIC, - OUTPUT_CVODE, - OUTPUT_DUMP, - OUTPUT_STDERR, - OUTPUT_SEND_MESSAGE -} output_type; - -typedef enum { - ACTION_OPEN, - ACTION_OUTPUT, - ACTION_CLOSE, - ACTION_REWIND, - ACTION_FLUSH -} action_type; - -#endif /* _INC_MESSAGE_H */ diff --git a/p2c.h b/p2c.h deleted file mode 100644 index 725328dd..00000000 --- a/p2c.h +++ /dev/null @@ -1,543 +0,0 @@ -#ifndef P2C_H -#define P2C_H - -#ifdef PHREEQC_IDENT -static char const svnidp2c[] = "$Id$"; -#endif - -/* Header file for code generated by "p2c", the Pascal-to-C translator */ - -/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. - * This file may be copied, modified, etc. in any way. It is not restricted - * by the licence agreement accompanying p2c itself. - */ - - -#include - - - -/* If the following heuristic fails, compile -DBSD=0 for non-BSD systems, - or -DBSD=1 for BSD systems. */ - -#ifdef M_XENIX -# define BSD 0 -#endif - -#ifdef vms -# define BSD 0 -# ifndef __STDC__ -# define __STDC__ 1 -# endif -#endif - -#ifdef __TURBOC__ -# define MSDOS 1 -#endif - -#ifdef MSDOS -# define BSD 0 -#endif - -#ifdef FILE /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */ -# ifndef BSD /* (a convenient, but horrible kludge!) */ -# define BSD 1 -# endif -#endif - -#ifdef BSD -# if !BSD -# undef BSD -# endif -#endif - - -#if (defined(__STDC__) && !defined(M_XENIX)) || defined(__TURBOC__) -# include -# include -# define HAS_STDLIB -# if defined(vms) || defined(__TURBOC__) -# define __ID__(a)a -# endif -#else -# ifndef BSD -# ifndef __TURBOC__ -# include -# endif -# endif -# ifdef hpux -# ifdef _INCLUDE__STDC__ -# include -# include -# endif -# endif -# include -# if !defined(MSDOS) || defined(__TURBOC__) -# define __ID__(a)a -# endif -#endif - -#ifdef __ID__ -# define __CAT__(a,b)__ID__(a)b -#else -# define __CAT__(a,b)a##b -#endif - - -#ifdef BSD -# include -# define memcpy(a,b,n) (bcopy(b,a,n),a) -# define memcmp(a,b,n) bcmp(a,b,n) -# define strchr(s,c) index(s,c) -# define strrchr(s,c) rindex(s,c) -#else -# include -#endif - -#include -#include -#include -#include - - -#ifndef NO_LACK -#ifdef vms - -#define LACK_LABS -#define LACK_MEMMOVE -#define LACK_MEMCPY - -#else - -#define LACK_LABS /* Undefine these if your library has these */ -#ifdef SKIP -#define LACK_MEMMOVE -#endif - -#endif -#endif - - -typedef struct __p2c_jmp_buf { - struct __p2c_jmp_buf *next; - jmp_buf jbuf; -} __p2c_jmp_buf; - - -/* Warning: The following will not work if setjmp is used simultaneously. - This also violates the ANSI restriction about using vars after longjmp, - but a typical implementation of longjmp will get it right anyway. */ - -#ifndef FAKE_TRY -# define TRY(x) do { __p2c_jmp_buf __try_jb; \ - __try_jb.next = __top_jb; \ - if (!setjmp((__top_jb = &__try_jb)->jbuf)) { -# define RECOVER(x) __top_jb = __try_jb.next; } else { -#ifdef SKIP -# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ - if (0) { L: __top_jb = __try_jb.next; } -#endif -# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ - { L: __top_jb = __try_jb.next; } -# define ENDTRY(x) } } while (0) -#else -# define TRY(x) if (1) { -# define RECOVER(x) } else do { -# define RECOVER2(x,L) } else do { L: ; -# define ENDTRY(x) } while (0) -#endif - - - -#ifdef M_XENIX /* avoid compiler bug */ -# define INT_MAX (32767) -# define INT_MIN (-32768) -#endif - - -/* The following definitions work only on twos-complement machines */ -#ifndef INT_MAX -# define INT_MAX ((int)(((unsigned int) -1) >> 1)) -# define INT_MIN (~INT_MAX) -#endif - -#ifndef INT_MAX -# define INT_MAX ((int)(((unsigned int) -1) >> 1)) -# define INT_MIN (~INT_MAX) -#endif - -#ifndef LONG_MAX -# define LONG_MAX ((long)(((unsigned long) -1) >> 1)) -# define LONG_MIN (~LONG_MAX) -#endif - -#ifndef SEEK_SET -# define SEEK_SET 0 -# define SEEK_CUR 1 -# define SEEK_END 2 -#endif - -#ifndef EXIT_SUCCESS -# ifdef vms -# define EXIT_SUCCESS 1 -# define EXIT_FAILURE (02000000000L) -# else -# define EXIT_SUCCESS 0 -# define EXIT_FAILURE 1 -# endif -#endif - - -#define SETBITS 32 - -#ifdef SKIP -#if defined(__STDC__) || defined(__TURBOC__) -# if !defined(vms) && !defined(M_LINT) -# define Signed signed -# else -# define Signed -# endif -# define Void void /* Void f() = procedure */ -# ifndef Const -# define Const const -# endif -# ifndef Volatile -# define Volatile volatile -# endif -# ifdef M_LINT -# define P2PP(x) () -# define PV() () -typedef char *Anyptr; -# else -# define P2PP(x) x /* function prototype */ -# define PV() (void) /* null function prototype */ -typedef void *Anyptr; -# endif -#else -# define Signed -# define Void void -# ifndef Const -# define Const -# endif -# ifndef Volatile -# define Volatile -# endif -# define P2PP(x) () -# define PV() () -typedef char *Anyptr; -#endif -#endif - - -#define Signed -#define Void void -#ifndef Const -# define Const -#endif -#ifndef Volatile -# define Volatile -#endif -#define P2PP(x) () -#define PV() () -typedef char *Anyptr; - - -#ifdef __GNUC__ -# define Inline inline -#else -# define Inline -#endif - -#define Register register /* Register variables */ -#define Char char /* Characters (not bytes) */ - -#ifndef Static -# define Static static /* Private global funcs and vars */ -#endif - -#ifndef Local -# define Local static /* Nested functions */ -#endif - -typedef Signed char schar; -/*typedef unsigned char uchar;*/ -typedef unsigned char boolean; - -#ifndef true -# define true 1 -# define false 0 -#endif - -#ifndef TRUE -# define TRUE 1 -# define FALSE 0 -#endif - - -typedef struct { - Anyptr proc, link; -} _PROCEDURE; - -#ifndef _FNSIZE -# define _FNSIZE 120 -#endif - - -/*extern Void PASCAL_MAIN P2PP( (int, Char **) );*/ -extern Void PASCAL_MAIN (int, Char **) ; -/* -extern Char **P_argv; -extern int P_argc; -*/ -extern int P_escapecode; -extern int P_ioresult; -extern __p2c_jmp_buf *__top_jb; - - -#ifdef P2C_H_PROTO /* if you have Ansi C but non-prototyped header files */ -extern Char *strcat P2PP( (Char *, Const Char *) ); -extern Char *strchr P2PP( (Const Char *, int) ); -extern int strcmp P2PP( (Const Char *, Const Char *) ); -extern Char *strcpy P2PP( (Char *, Const Char *) ); -extern size_t strlen P2PP( (Const Char *) ); -extern Char *strncat P2PP( (Char *, Const Char *, size_t) ); -extern int strncmp P2PP( (Const Char *, Const Char *, size_t) ); -extern Char *strncpy P2PP( (Char *, Const Char *, size_t) ); -extern Char *strrchr P2PP( (Const Char *, int) ); - -extern Anyptr memchr P2PP( (Const Anyptr, int, size_t) ); -extern Anyptr memmove P2PP( (Anyptr, Const Anyptr, size_t) ); -extern Anyptr memset P2PP( (Anyptr, int, size_t) ); -#ifndef memcpy -extern Anyptr memcpy P2PP( (Anyptr, Const Anyptr, size_t) ); -extern int memcmp P2PP( (Const Anyptr, Const Anyptr, size_t) ); -#endif - -extern int atoi P2PP( (Const Char *) ); -extern LDBLE atof P2PP( (Const Char *) ); -extern long atol P2PP( (Const Char *) ); -extern LDBLE strtod P2PP( (Const Char *, Char **) ); -extern long strtol P2PP( (Const Char *, Char **, int) ); -#endif /*P2C_H_PROTO*/ - -/* force stdlib for DEC */ -#define HAS_STDLIB -#ifndef HAS_STDLIB -extern Anyptr malloc P2PP( (size_t) ); -extern Void free P2PP( (Anyptr) ); -#endif - -extern int _OutMem PV(); -extern int _CaseCheck PV(); -extern int _NilCheck PV(); -/*extern int _Escape P2PP( (int) );*/ -extern int _Escape(int); -/*extern int _EscIO P2PP( (int) );*/ -extern int _EscIO (int); -extern long ipow P2PP( (long, long) ); -extern Char *strsub P2PP( (Char *, Char *, int, int) ); -extern Char *strltrim P2PP( (Char *) ); -extern Char *strrtrim P2PP( (Char *) ); -extern Char *strrpt P2PP( (Char *, Char *, int) ); -extern Char *strpad P2PP( (Char *, Char *, int, int) ); -extern int strpos2 P2PP( (Char *, Char *, int) ); -extern long memavail PV(); -extern int P_peek P2PP( (FILE *) ); -extern int P_eof P2PP( (FILE *) ); -extern int P_eoln P2PP( (FILE *) ); -extern Void P_readpaoc P2PP( (FILE *, Char *, int) ); -extern Void P_readlnpaoc P2PP( (FILE *, Char *, int) ); -extern long P_maxpos P2PP( (FILE *) ); -extern Char *P_trimname P2PP( (Char *, int) ); -extern long *P_setunion P2PP( (long *, long *, long *) ); -extern long *P_setint P2PP( (long *, long *, long *) ); -extern long *P_setdiff P2PP( (long *, long *, long *) ); -extern long *P_setxor P2PP( (long *, long *, long *) ); -extern int P_inset P2PP( (unsigned, long *) ); -extern int P_setequal P2PP( (long *, long *) ); -extern int P_subset P2PP( (long *, long *) ); -extern long *P_addset P2PP( (long *, unsigned) ); -extern long *P_addsetr P2PP( (long *, unsigned, unsigned) ); -extern long *P_remset P2PP( (long *, unsigned) ); -extern long *P_setcpy P2PP( (long *, long *) ); -extern long *P_expset P2PP( (long *, long) ); -extern long P_packset P2PP( (long *) ); -extern int P_getcmdline P2PP( (int, int, Char *) ); -extern Void TimeStamp P2PP( (int *, int *, int *, - int *, int *, int *) ); -extern Void P_sun_argv P2PP( (char *, int, int) ); - - -/* I/O error handling */ -#define _CHKIO(cond,ior,val,def) ((cond) ? P_ioresult=0,(val) \ - : P_ioresult=(ior),(def)) -#define _SETIO(cond,ior) (P_ioresult = (cond) ? 0 : (ior)) - -/* Following defines are suitable for the HP Pascal operating system */ -#define FileNotFound 10 -#define FileNotOpen 13 -#define FileWriteError 38 -#define BadInputFormat 14 -#define EndOfFile 30 - -#define FILENOTFOUND 10 -#define FILENOTOPEN 13 -#define FILEWRITEERROR 38 -#define BADINPUTFORMAT 14 -#define ENDOFFILE 30 - -/* Creating temporary files */ -#if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE) -# define tmpfile() (fopen(tmpnam(NULL), "w+")) -#endif - -/* File buffers */ -#define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS); \ - sc type __CAT__(f,_BUFFER) -#define FILEBUFNC(f,type) int __CAT__(f,_BFLAGS); \ - type __CAT__(f,_BUFFER) - -#define RESETBUF(f,type) (__CAT__(f,_BFLAGS) = 1) -#define SETUPBUF(f,type) (__CAT__(f,_BFLAGS) = 0) - -#define GETFBUF(f,type) (*((__CAT__(f,_BFLAGS) == 1 && \ - ((__CAT__(f,_BFLAGS) = 2), \ - fread(&__CAT__(f,_BUFFER), \ - sizeof(type),1,(f)))),\ - &__CAT__(f,_BUFFER))) -#define AGETFBUF(f,type) ((__CAT__(f,_BFLAGS) == 1 && \ - ((__CAT__(f,_BFLAGS) = 2), \ - fread(__CAT__(f,_BUFFER), \ - sizeof(type),1,(f)))),\ - __CAT__(f,_BUFFER)) - -#define PUTFBUF(f,type,v) (GETFBUF(f,type) = (v)) -#define CPUTFBUF(f,v) (PUTFBUF(f,char,v)) -#define APUTFBUF(f,type,v) (memcpy(AGETFBUF(f,type), (v), \ - sizeof(__CAT__(f,_BUFFER)))) - -#define GET(f,type) (__CAT__(f,_BFLAGS) == 1 ? \ - fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) : \ - (__CAT__(f,_BFLAGS) = 1)) - -#define PUT(f,type) (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)), \ - (__CAT__(f,_BFLAGS) = 0)) -#define CPUT(f) (PUT(f,char)) - -#define BUFEOF(f) (__CAT__(f,_BFLAGS) != 2 && P_eof(f)) -#define BUFFPOS(f) (ftell(f) - (__CAT__(f,_BFLAGS) == 2)) - -#ifdef SKIP -typedef struct { - FILE *f; - FILEBUFNC(f,Char); - Char name[_FNSIZE]; -} _TEXT; -#endif - -/* Memory allocation */ -#ifdef __GCC__ -# define Malloc(n) (PHRQ_malloc(n) ?: (Anyptr)_OutMem()) -#else -extern Anyptr __MallocTemp__; -# define Malloc(n) ((__MallocTemp__ = PHRQ_malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem()) -#endif -#define FreeR(p) (free((Anyptr)(p))) /* used if arg is an rvalue */ -#define Free(p) (free((Anyptr)(p)), (p)=NULL) - -/* sign extension */ -#define SEXT(x,n) ((x) | -(((x) & (1L<<((n)-1))) << 1)) - -/* packed arrays */ /* BEWARE: these are untested! */ -#define P_getbits_UB(a,i,n,L) ((int)((a)[(i)>>(L)-(n)] >> \ - (((~(i))&((1<<(L)-(n))-1)) << (n)) & \ - (1<<(1<<(n)))-1)) - -#define P_getbits_SB(a,i,n,L) ((int)((a)[(i)>>(L)-(n)] << \ - (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\ - (n)) >> (16-(1<<(n)))))) - -#define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |= \ - (x) << (((~(i))&((1<<(L)-(n))-1)) << (n))) - -#define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |= \ - ((x) & (1<<(1<<(n)))-1) << \ - (((~(i))&((1<<(L)-(n))-1)) << (n))) - -#define P_clrbits_B(a,i,n,L) ((a)[(i)>>(L)-(n)] &= \ - ~( ((1<<(1<<(n)))-1) << \ - (((~(i))&((1<<(L)-(n))-1)) << (n))) ) - -/* small packed arrays */ -#define P_getbits_US(v,i,n) ((int)((v) >> ((i)<<(n)) & (1<<(1<<(n)))-1)) -#define P_getbits_SS(v,i,n) ((int)((long)(v) << (SETBITS - (((i)+1) << (n))) >> (SETBITS-(1<<(n))))) -#define P_putbits_US(v,i,x,n) ((v) |= (x) << ((i) << (n))) -#define P_putbits_SS(v,i,x,n) ((v) |= ((x) & (1<<(1<<(n)))-1) << ((i)<<(n))) -#define P_clrbits_S(v,i,n) ((v) &= ~( ((1<<(1<<(n)))-1) << ((i)<<(n)) )) - -#define P_max(a,b) ((a) > (b) ? (a) : (b)) -#define P_min(a,b) ((a) < (b) ? (a) : (b)) - - -/* Fix ANSI-isms */ - -#ifdef LACK_LABS -# ifndef labs -# define labs my_labs - extern long my_labs P2PP( (long) ); -# endif -#endif - -#ifdef LACK_MEMMOVE -# ifndef memmove -# define memmove my_memmove - extern Anyptr my_memmove P2PP( (Anyptr, Const Anyptr, size_t) ); -# endif -#endif - -#ifdef LACK_MEMCPY -# ifndef memcpy -# define memcpy my_memcpy - extern Anyptr my_memcpy P2PP( (Anyptr, Const Anyptr, size_t) ); -# endif -# ifndef memcmp -# define memcmp my_memcmp - extern int my_memcmp P2PP( (Const Anyptr, Const Anyptr, size_t) ); -# endif -# ifndef memset -# define memset my_memset - extern Anyptr my_memset P2PP( (Anyptr, int, size_t) ); -# endif -#endif - -/* Fix toupper/tolower on Suns and other stupid BSD systems */ -#ifdef toupper -# undef toupper -# undef tolower -# define toupper(c) my_toupper(c) -# define tolower(c) my_tolower(c) -#endif - -#ifndef _toupper -# if 'A' == 65 && 'a' == 97 -# define _toupper(c) ((c)-'a'+'A') -# define _tolower(c) ((c)-'A'+'a') -# else -# ifdef toupper -# undef toupper /* hope these are shadowing real functions, */ -# undef tolower /* because my_toupper calls _toupper! */ -# endif -# define _toupper(c) toupper(c) -# define _tolower(c) tolower(c) -# endif -#endif - - -#endif /* P2C_H */ - - - -/* End. */ - - diff --git a/p2clib.cpp b/p2clib.cpp deleted file mode 100644 index 88b662b8..00000000 --- a/p2clib.cpp +++ /dev/null @@ -1,936 +0,0 @@ - -/* Run-time library for use with "p2c", the Pascal to C translator */ - -/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. - * This file may be copied, modified, etc. in any way. It is not restricted - * by the licence agreement accompanying p2c itself. - */ - -static char const svnid[] = "$Id: p2clib.c 663 2005-11-16 00:46:04Z dlpark $"; - -#include "p2c.h" -#include "output.h" -#define STOP 1 -#define CONTINUE 0 - -#define NO_TIME -#ifndef NO_TIME -# include -#endif -#include - -#define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ - - - - -static int P_argc; -static char **P_argv; -static char *_ShowEscape(char *buf, int code, int ior, char *prefix); - -int P_escapecode; -int P_ioresult; - -long EXCP_LINE; /* Used by Pascal workstation system */ - -Anyptr __MallocTemp__; - -__p2c_jmp_buf *__top_jb; - -void PASCAL_MAIN(int argc, char **argv) -{ - if (svnid == NULL) fprintf(stderr," "); - P_argc = argc; - P_argv = argv; - __top_jb = NULL; - P_escapecode = 0; - P_ioresult = 0; -#ifdef LOCAL_INIT - LOCAL_INIT(); -#endif -} - - - - - -/* In case your system lacks these... */ - -long my_labs(long x) -{ - return((x > 0) ? x : -x); -} - - -/* #define __STDC__ */ /* PHREEQ98 */ - -Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n) -{ - register char *dd = (char *)d, *ss = (char *)s; - if (dd < ss || (unsigned int) (dd - ss) >= n) { - memcpy(dd, ss, n); - } else if (n > 0) { - dd += n; - ss += n; - while (n-- > 0) - *--dd = *--ss; - } - return d; -} - - -Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n) - -{ - register char *ss = (char *)s, *dd = (char *)d; - while (n-- > 0) - *dd++ = *ss++; - return d; -} - -int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) -{ - register char *a = (char *)s1, *b = (char *)s2; - register int i; - while (n-- > 0) - if ((i = (*a++) - (*b++)) != 0) - return i; - return 0; -} - -Anyptr my_memset(Anyptr d, int c, size_t n) -{ - register char *dd = (char *)d; - while (n-- > 0) - *dd++ = (char) c; - return d; -} - -int my_toupper(int c) -{ - if (islower(c)) - return _toupper(c); - else - return c; -} - - -int my_tolower(int c) - -{ - if (isupper(c)) - return _tolower(c); - else - return c; -} - - - - -long ipow(long a, long b) -{ - long v; - - if (a == 0 || a == 1) - return a; - if (a == -1) - return (b & 1) ? -1 : 1; - if (b < 0) - return 0; - if (a == 2) - return 1L << b; - v = (b & 1) ? a : 1; - while ((b >>= 1) > 0) { - a *= a; - if (b & 1) - v *= a; - } - return v; -} - - - - -/* Common string functions: */ - -/* Store in "ret" the substring of length "len" starting from "pos" (1-based). - Store a shorter or null string if out-of-range. Return "ret". */ -char *strsub(register char *ret, register char *s, register int pos, register int len) -{ - register char *s2; - - if (--pos < 0 || len <= 0) { - *ret = 0; - return ret; - } - while (pos > 0) { - if (!*s++) { - *ret = 0; - return ret; - } - pos--; - } - s2 = ret; - while (--len >= 0) { - if (!(*s2++ = *s++)) - return ret; - } - *s2 = 0; - return ret; -} - - -/* Return the index of the first occurrence of "pat" as a substring of "s", - starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ - -int strpos2(char *s, register char *pat, register int pos) -{ - register char *cp, ch; - register int slen; - - if (--pos < 0) - return 0; - slen = strlen(s) - pos; - cp = s + pos; - if (!(ch = *pat++)) - return 0; - pos = strlen(pat); - slen -= pos; - while (--slen >= 0) { - if (*cp++ == ch && !strncmp(cp, pat, pos)) - return cp - s; - } - return 0; -} - - -/* Case-insensitive version of strcmp. */ -int strcicmp(register char *s1, register char *s2) -{ - register unsigned char c1, c2; - - while (*s1) { - if (*s1++ != *s2++) { - if (!s2[-1]) - return 1; - c1 = (unsigned char) toupper(s1[-1]); - c2 = (unsigned char) toupper(s2[-1]); - if (c1 != c2) - return c1 - c2; - } - } - if (*s2) - return -1; - return 0; -} - - - - -/* HP and Turbo Pascal string functions: */ - -/* Trim blanks at left end of string. */ -char *strltrim(register char *s) -{ - while (Isspace((int) *s++)) ; - return s - 1; -} - - -/* Trim blanks at right end of string. */ -char *strrtrim(register char *s) -{ - register char *s2 = s; - - if (!*s) - return s; - while (*++s2) ; - while (s2 > s && Isspace((int) *--s2)) - *s2 = 0; - return s; -} - - -/* Store in "ret" "num" copies of string "s". Return "ret". */ -#ifdef SKIP -char *strrpt(ret, s, num) -char *ret; -register char *s; -register int num; -{ - register char *s2 = ret; - register char *s1; - - while (--num >= 0) { - s1 = s; - while ((*s2++ = *s1++)) ; - s2--; - } - return ret; -} -#endif - -/* Store in "ret" string "s" with enough pad chars added to reach "size". */ - -#ifdef SKIP -char *strpad -(ret, s, padchar, num) -char *ret; -register char *s; -register int padchar, num; -{ - register char *d = ret; - - if (s == d) { - while (*d++) ; - } else { - while ((*d++ = *s++)) ; - } - num -= (--d - ret); - while (--num >= 0) - *d++ = (char) padchar; - *d = 0; - return ret; -} -#endif - -/* Copy the substring of length "len" from index "spos" of "s" (1-based) - to index "dpos" of "d", lengthening "d" if necessary. Length and - indices must be in-range. */ -void strmove(register int len, register char *s, register int spos, register char *d, register int dpos) -{ - s += spos - 1; - d += dpos - 1; - while (*d && --len >= 0) - *d++ = *s++; - if (len > 0) { - while (--len >= 0) - *d++ = *s++; - *d = 0; - } -} - - -/* Delete the substring of length "len" at index "pos" from "s". - Delete less if out-of-range. */ -#ifdef SKIP -void strdelete(s, pos, len) -register char *s; -register int pos, len; -{ - register int slen; - - if (--pos < 0) - return; - slen = strlen(s) - pos; - if (slen <= 0) - return; - s += pos; - if (slen <= len) { - *s = 0; - return; - } - while ((*s = s[len])) s++; -} -#endif - -/* Insert string "src" at index "pos" of "dst". */ -void strinsert(register char *src, register char *dst, register int pos) -{ - register int slen, dlen; - - if (--pos < 0) - return; - dlen = strlen(dst); - dst += dlen; - dlen -= pos; - if (dlen <= 0) { - strcpy(dst, src); - return; - } - slen = strlen(src); - do { - dst[slen] = *dst; - --dst; - } while (--dlen >= 0); - dst++; - while (--slen >= 0) - *dst++ = *src++; -} - - - - -/* File functions */ - -/* Peek at next character of input stream; return EOF at end-of-file. */ -int P_peek(FILE *f) -{ - int ch; - - ch = getc(f); - if (ch == EOF) - return EOF; - ungetc(ch, f); - return (ch == '\n') ? ' ' : ch; -} - - -/* Check if at end of file, using Pascal "eof" semantics. End-of-file for - stdin is broken; remove the special case for it to be broken in a - different way. */ -/*int P_eof(FILE *f)*/ -int P_eof(void) -{ -#ifdef SKIP - register int ch; - if (feof(f)) - return 1; - if (f == stdin) - return 0; /* not safe to look-ahead on the keyboard! */ - ch = getc(f); - if (ch == EOF) - return 1; - ungetc(ch, f); -#endif - return 0; -} - - -/* Check if at end of line (or end of entire file). */ -int P_eoln(FILE *f) -{ - register int ch; - - ch = getc(f); - if (ch == EOF) - return 1; - ungetc(ch, f); - return (ch == '\n'); -} - - -/* Read a packed array of characters from a file. */ -Void P_readpaoc(FILE *f, char *s, int len) -{ - int ch; - - for (;;) { - if (len <= 0) - return; - ch = getc(f); - if (ch == EOF || ch == '\n') - break; - *s++ = (char) ch; - --len; - } - while (--len >= 0) - *s++ = ' '; - if (ch != EOF) - ungetc(ch, f); -} -Void P_readlnpaoc(FILE *f, char *s, int len) -{ - int ch; - - for (;;) { - ch = getc(f); - if (ch == EOF || ch == '\n') - break; - if (len > 0) { - *s++ = (char) ch; - --len; - } - } - while (--len >= 0) - *s++ = ' '; -} - - -/* Compute maximum legal "seek" index in file (0-based). */ -long P_maxpos(FILE *f) -{ - long savepos = ftell(f); - long val; - - if (fseek(f, 0L, SEEK_END)) - return -1; - val = ftell(f); - if (fseek(f, savepos, SEEK_SET)) - return -1; - return val; -} - - -/* Use packed array of char for a file name. */ -Char *P_trimname(register Char *fn, register int len) -{ - static Char fnbuf[256]; - register Char *cp = fnbuf; - - while (--len >= 0 && *fn && !isspace((int) *fn)) - *cp++ = *fn++; - *cp = 0; - return fnbuf; -} - - - - -/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. - We fix memory size as 10Meg as a reasonable compromise. */ - -long memavail(void) -{ - return 10000000; /* worry about this later! */ -} - -long maxavail(void) -{ - return memavail(); -} - - - - -/* Sets are stored as an array of longs. S[0] is the size of the set; - S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum - I such that S[I] is nonzero. S[0] is zero for an empty set. Within - each long, bits are packed from lsb to msb. The first bit of the - set is the element with ordinal value 0. (Thus, for a "set of 5..99", - the lowest five bits of the first long are unused and always zero.) */ - -/* (Sets with 32 or fewer elements are normally stored as plain longs.) */ -long *P_setunion(register long *d, register long *s1, register long *s2) /* d := s1 + s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (sz1 > 0 && sz2 > 0) { - *d++ = *s1++ | *s2++; - sz1--, sz2--; - } - while (--sz1 >= 0) - *d++ = *s1++; - while (--sz2 >= 0) - *d++ = *s2++; - *dbase = d - dbase - 1; - return dbase; -} - -long *P_setint(register long *d, register long *s1, register long *s2) /* d := s1 * s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (--sz1 >= 0 && --sz2 >= 0) - *d++ = *s1++ & *s2++; - while (--d > dbase && !*d) ; - *dbase = d - dbase; - return dbase; -} - -long *P_setdiff(register long *d, register long *s1, register long *s2) /* d := s1 - s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (--sz1 >= 0 && --sz2 >= 0) - *d++ = *s1++ & ~*s2++; - if (sz1 >= 0) { - while (sz1-- >= 0) - *d++ = *s1++; - } - while (--d > dbase && !*d) ; - *dbase = d - dbase; - return dbase; -} - -long *P_setxor(register long *d, register long *s1, register long *s2) /* d := s1 / s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (sz1 > 0 && sz2 > 0) { - *d++ = *s1++ ^ *s2++; - sz1--, sz2--; - } - while (--sz1 >= 0) - *d++ = *s1++; - while (--sz2 >= 0) - *d++ = *s2++; - while (--d > dbase && !*d) ; - *dbase = d - dbase; - return dbase; -} - -int P_inset(register unsigned val, register long *s) /* val IN s */ -{ - register int bit; - bit = val % SETBITS; - val /= SETBITS; - if ((long) val < (*s++ && ((1L< size) { - s += size; - while ((long) val > size) - *++s = 0, size++; - *sbase = size; - } else - s += val; - *s |= 1L< (int)v2) - return sbase; - b1 = v1 % SETBITS; - v1 /= SETBITS; - b2 = v2 % SETBITS; - v2 /= SETBITS; - size = *s; - v1++; - if ((int) ++v2 > size) { - while ((int) v2 > size) - s[++size] = 0; - s[v2] = 0; - *s = v2; - } - s += v1; - if (v1 == v2) { - *s |= (~((-2L)<<(b2-b1))) << b1; - } else { - *s++ |= (-1L) << b1; - while (++v1 < v2) - *s++ = -1; - *s |= ~((-2L) << b2); - } - return sbase; -} - -long *P_remset(register long *s, register unsigned val) /* s := s - [val] */ -{ - register int bit; - bit = val % SETBITS; - val /= SETBITS; - if ((long) ++val <= *s) { - if (!(s[val] &= ~(1L<= 0) { - if (*s1++ != *s2++) - return 0; - } - return 1; -} - -int P_subset(register long *s1, register long *s2) /* s1 <= s2 */ -{ - register int sz1 = *s1++, sz2 = *s2++; - if (sz1 > sz2) - return 0; - while (--sz1 >= 0) { - if (*s1++ & ~*s2++) - return 0; - } - return 1; -} - -long *P_setcpy(register long *d, register long *s) /* d := s */ -{ - register long *save_d = d; - -#ifdef SETCPY_MEMCPY - memcpy(d, s, (*s + 1) * sizeof(long)); -#else - register int i = *s + 1; - while (--i >= 0) - *d++ = *s++; -#endif - return save_d; -} - - -/* s is a "smallset", i.e., a 32-bit or less set stored - directly in a long. */ -long *P_expset(register long *d, register long s) /* d := s */ -{ - if (s) { - d[1] = s; - *d = 1; - } else - *d = 0; - return d; -} - -long P_packset(register long *s) /* convert s to a small-set */ -{ - if (*s++) - return *s; - else - return 0; -} - - - - - -/* Oregon Software Pascal extensions, courtesy of William Bader */ -int P_getcmdline(int l, int h, Char *line) -{ - int i, len; - char *s; - - h = h - l + 1; - len = 0; - for(i = 1; i < P_argc; i++) { - s = P_argv[i]; - while (*s) { - if (len >= h) return len; - line[len++] = *s++; - } - if (len >= h) return len; - line[len++] = ' '; - } - return len; -} - -#ifndef NO_TIME -Void TimeStamp(Day, Month, Year, Hour, Min, Sec) -int *Day, *Month, *Year, *Hour, *Min, *Sec; -{ - struct tm *tm; - long clock; - - time(&clock); - tm = localtime(&clock); - *Day = tm->tm_mday; - *Month = tm->tm_mon + 1; /* Jan = 0 */ - *Year = tm->tm_year; - if (*Year < 1900) - *Year += 1900; /* year since 1900 */ - *Hour = tm->tm_hour; - *Min = tm->tm_min; - *Sec = tm->tm_sec; -} - -Void VAXdate(s) -char *s; -{ - long clock; - char *c; - int i; - static int where[] = {8, 9, 0, 4, 5, 6, 0, 20, 21, 22, 23}; - - time(&clock); - c = ctime(&clock); - for (i = 0; i < 11; i++) - s[i] = my_toupper(c[where[i]]); - s[2] = '-'; - s[6] = '-'; -} - -Void VAXtime(s) -char *s; -{ - long clock; - char *c; - int i; - - time(&clock); - c = ctime(&clock); - for (i = 0; i < 8; i++) - s[i] = c[i+11]; - s[8] = '.'; - s[9] = '0'; - s[10] = '0'; -} -#endif - - - - -/* SUN Berkeley Pascal extensions */ -Void P_sun_argv(register char *s, register int len, register int n) -{ - register char *cp; - - if (n < P_argc) - cp = P_argv[n]; - else - cp = ""; - while (*cp && --len >= 0) - *s++ = *cp++; - while (--len >= 0) - *s++ = ' '; -} - - - - -int _OutMem(void) -{ - return _Escape(-2); -} - -int _CaseCheck(void) -{ - return _Escape(-9); -} - -int _NilCheck(void) -{ - return _Escape(-3); -} - - - - - -/* The following is suitable for the HP Pascal operating system. - It might want to be revised when emulating another system. */ - -#ifdef SKIP -static char *_ShowEscape(buf, code, ior, prefix) -char *buf, *prefix; -int code, ior; -#endif -static char *_ShowEscape(char *buf, int code, int ior, char *prefix) -{ - char *bufp; - - if (prefix && *prefix) { - strcpy(buf, prefix); - strcat(buf, ": "); - bufp = buf + strlen(buf); - } else { - bufp = buf; - } - if (code == -10) { - sprintf(bufp, "Pascal system I/O error %d", ior); - switch (ior) { - case 3: - strcat(buf, " (illegal I/O request)"); - break; - case 7: - strcat(buf, " (bad file name)"); - break; - case FileNotFound: /*10*/ - strcat(buf, " (file not found)"); - break; - case FileNotOpen: /*13*/ - strcat(buf, " (file not open)"); - break; - case BadInputFormat: /*14*/ - strcat(buf, " (bad input format)"); - break; - case 24: - strcat(buf, " (not open for reading)"); - break; - case 25: - strcat(buf, " (not open for writing)"); - break; - case 26: - strcat(buf, " (not open for direct access)"); - break; - case 28: - strcat(buf, " (string subscript out of range)"); - break; - case EndOfFile: /*30*/ - strcat(buf, " (end-of-file)"); - break; - case FileWriteError: /*38*/ - strcat(buf, " (file write error)"); - break; - } - } else { - sprintf(bufp, "Pascal system error %d", code); - switch (code) { - case -2: - strcat(buf, " (out of memory)"); - break; - case -3: - strcat(buf, " (reference to NIL pointer)"); - break; - case -4: - strcat(buf, " (integer overflow)"); - break; - case -5: - strcat(buf, " (divide by zero)"); - break; - case -6: - strcat(buf, " (real math overflow)"); - break; - case -8: - strcat(buf, " (value range error)"); - break; - case -9: - strcat(buf, " (CASE value range error)"); - break; - case -12: - strcat(buf, " (bus error)"); - break; - case -20: - strcat(buf, " (stopped by user)"); - break; - } - } - return buf; -} -int _Escape(int code) -{ - char buf[100]; - char token[200]; - - P_escapecode = code; - if (__top_jb) { - __p2c_jmp_buf *jb = __top_jb; - __top_jb = jb->next; - longjmp(jb->jbuf, 1); - } - if (code == 0) - /* exit(EXIT_SUCCESS); */ - error_msg("Exit success in Basic", STOP); - if (code == -1) { - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", _ShowEscape(buf, P_escapecode, P_ioresult, "")); - error_msg(token, STOP); - exit(EXIT_FAILURE); - } - /* fprintf(stderr, "%s\n", _ShowEscape(buf, P_escapecode, P_ioresult, "")); */ - /* exit(EXIT_FAILURE); */ - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", _ShowEscape(buf, P_escapecode, P_ioresult, "")); - error_msg(token, STOP); - return(1); -} -int _EscIO(int code) -{ - P_ioresult = code; - return _Escape(-10); -} - - - - -/* End. */ diff --git a/parse.cpp b/parse.cpp deleted file mode 100644 index 27d39c58..00000000 --- a/parse.cpp +++ /dev/null @@ -1,904 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: parse.c 392 2005-07-19 16:05:07Z dlpark $"; - -static int get_coef(LDBLE *coef, char **eqnaddr); -static int get_secondary (char **t_ptr, char *element, int *i); -static int get_species (char **ptr); - -/* ---------------------------------------------------------------------- */ -int parse_eq(char *eqn, struct elt_list **elt_ptr, int association) -/* ---------------------------------------------------------------------- */ -/* - * function to break equation up into component species - * returns species name, coefficient, and charge in global variable "rxn_list". - * Also returns pointer to elt_list structure array with list of elements - * and coefficients in species. - * rxn_list global variable, output with contiguous rxn_list structures, - * which is the reaction. Target species is first in - * list, coefficient is -1.0. - * - * Argurments: - * *eqn input, pointer to equation to be parsed. - * **elt_ptr output, pointer to contiguous elt_list structures, - * which is list of elements and coefficients in the - * target species. - * association input, TRUE or FALSE if reaction is an association reaction - */ -{ - int i; - LDBLE coef, z; - char c; - char *ptr, *char_ptr; - if (svnid == NULL) fprintf(stderr," "); - - paren_count = 0; -/* - * Remove white space - */ - squeeze_white(eqn); -/* - * Check for illegal characters - */ - for (i = 0; (c=eqn[i]) != '\0'; i++) { - if( islegit(c) == FALSE ){ - sprintf(error_string,"Character is not allowed,\ - %c (octal: %o).",c,c); - error_msg(error_string, CONTINUE); - return(ERROR); - } - } - -/* - * Find coefficients, name, and charge for each species for lhs - */ - count_trxn=0; - ptr=eqn; - c = ptr[0]; - for (;;) { - if (c == '=') break; - if (c == '\0'){ - sprintf(error_string,"Equation has no equal sign.\n\t%s",eqn); - error_msg(error_string, CONTINUE); - return(ERROR); - } - if ( get_species (&ptr) == ERROR ){ - return(ERROR); - } - c = ptr[0]; - if ( association == FALSE ) { - trxn.token[count_trxn].coef *= -1.0; - } - count_trxn++; - } -/* - * Get coefficient, name, and charge of species for dissociation reaction - */ - ptr++; - if ( association == TRUE ) { - if ( get_species (&ptr) == ERROR ){ - return(ERROR); - } - trxn.token[count_trxn].coef *= -1.0; - /* Swap species into first structure position */ - char_ptr=trxn.token[0].name; - coef=trxn.token[0].coef; - z=trxn.token[0].z; - trxn.token[0].name=trxn.token[count_trxn].name; - trxn.token[0].coef=trxn.token[count_trxn].coef; - trxn.token[0].z=trxn.token[count_trxn].z; - trxn.token[count_trxn].name=char_ptr; - trxn.token[count_trxn].coef=coef; - trxn.token[count_trxn].z=z; - count_trxn++; - } -/* - * Get reaction species from rhs of equation - */ - c = ptr[0]; - for (;;) { - if (c == '\0') break; - if ( get_species (&ptr) == ERROR ){ - return(ERROR); - } - c = ptr[0]; - if ( association == TRUE ) { - trxn.token[count_trxn].coef *= -1.0; - } - count_trxn++; - } -/* - * Sort list of reaction species - */ - trxn_sort(); -/* - * Get elements in species or mineral formula - */ - count_elts=0; - char_ptr=trxn.token[0].name; - if ( get_elts_in_species( &char_ptr , trxn.token[0].coef ) == ERROR ) { - return(ERROR); - } -/* - * Sort elements in reaction and combine - */ - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - if (elt_list_combine () == ERROR) return(ERROR); -/* - * Malloc space and store element data for return - */ - *elt_ptr=(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1)*sizeof(struct elt_list)); - if (*elt_ptr == NULL ) malloc_error(); - for ( i=0; i < count_elts; i++ ) { - (*elt_ptr)[i].elt=elt_list[i].elt; - (*elt_ptr)[i].coef=-elt_list[i].coef; - } - (*elt_ptr)[count_elts].elt=NULL; -/* - * Debugging print of parsed equation - trxn_print(); - */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int check_eqn ( int association ) -/* ---------------------------------------------------------------------- */ -/* - * Check that equation is balanced reaction. Uses array "trxn.token" and - * assumes "count_trxn" is set to number of species in reaction. - * Charge and elements are checked. - * - * Arguments: - * - * association input, TRUE or FALSE if reaction is an association reaction. - */ -{ - int i; - int oops=0; - char *t_ptr; - LDBLE sumcharge; - - paren_count=0; - count_elts=0; -/* - * Check that coefficient of first species is -1.0 - */ - if ( equal(trxn.token[0].coef,-1.0,TOL) == FALSE ) { - if (association == TRUE) { - sprintf(error_string, "Coefficient of first species on rhs is not equal to 1.0."); - error_msg(error_string, CONTINUE); - } else { - sprintf(error_string, "Coefficient of mineral (first on lhs) is not equal to 1.0."); - error_msg(error_string, CONTINUE); - } - return(ERROR); - } -/* - * Go through all species in the reaction; sum the charge and store elements - */ - sumcharge=0.0; - for (i=0; i < count_trxn; i++) { - sumcharge += ( trxn.token[i].coef)*(trxn.token[i].z); - t_ptr=trxn.token[i].name; - if ( get_elts_in_species(&t_ptr, trxn.token[i].coef ) == ERROR ) { - return(ERROR); - } - } -/* - * Sort elements in reaction and combine - */ - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - if (elt_list_combine() == ERROR) return(ERROR); -/* - * Check charge - */ - if ( equal(sumcharge, 0.0, TOL) == FALSE) { - sprintf(error_string, "Equation is not charge balanced."); - error_msg(error_string, CONTINUE); - oops++; - } -/* - * Check mass balance - */ - for ( i=0; i < count_elts; i++) { - if ( (equal(elt_list[i].coef,0.0,TOL) == FALSE) && - strncmp( (elt_list[i].elt)->name , "e" , MAX_LENGTH) != 0) { - sprintf(error_string, "Equation does not balance for element, %s.", (elt_list[i].elt)->name); - error_msg(error_string, CONTINUE); - oops++; - } - } - if (oops == 0) { - return(OK); - } else { - return(ERROR); - } -} -/* ---------------------------------------------------------------------- */ -int get_charge(char *charge, LDBLE *z) -/* ---------------------------------------------------------------------- */ -/* - * Function takes character string and calculates the charge on - * the species. Charge can be in two forms: (1) string of "+" or "-" - * or (2) + or - followed by an integer. Charge is reduced to form (2) - * and stored in the pointer location *charge. - * - * Arguments: - * *charge input, string containing charge - * output, string containing charge of the form + or - - * followed by an integer, if integer greater than 1. - * *z output, value of charge. - * - * Returns: - * ERROR, - * OK. - */ -{ - int i; - char *ptr; - char c,c1; -/* - * Charge is zero - */ - if((c=charge[0]) == '\0'){ - *z=0.0; - return(OK); - } -/* - * Error check for + or - at start of string - */ - if(c != '+' && c != '-'){ - sprintf(error_string,"Character string for charge does not start with + or -,\t%s.", charge); - error_msg(error_string, CONTINUE); - return(ERROR); - } -/* - * Count string of +'s or -'s - */ - i=0; - while (c == (c1=charge[i++]) ); - i--; - if (c1 == '\0') { - if (c == '-') i=-i; - } else { -/* - * + or - followed by a number - */ - errno=0; - i=strtol(charge,&ptr,0); -#ifdef SKIP - if (errno == ERANGE) { - sprintf(error_string, "Error in character string for charge, %s.", charge); - error_msg(error_string, CONTINUE); - return(ERROR); - } -#endif -/* - * Truncate fractional part of charge if all zeros - */ - if (*ptr != '\0') { - if ( *ptr == '.') { - while (*(++ptr) != '\0') { - if (*ptr != '0') { - *z = strtod(charge, &ptr); - return(OK); -#ifdef SKIP - sprintf(error_string, "Charge must be an integer, %s.", charge); - error_msg(error_string, CONTINUE); - return(ERROR); -#endif - } - } -/* - * Non-numeric characters - */ - } else { - sprintf(error_string, "Error in character string for charge, %s.", charge); - error_msg(error_string, CONTINUE); - return(ERROR); - } - } - } -/* - * Charge is zero, must have had +0 or -0 in eqn - */ - if (i == 0) { - charge[0]='\0'; - } -/* - * Charge is +1 or -1, single + or - - */ - if (abs(i) == 1) { - charge[0]=c; - charge[1]='\0'; - } -/* - * Abs(z)>1, set charge to + or - plus integer - */ - if (abs(i)>1) { - if (sprintf(charge,"%-+d",i) == EOF){ - sprintf(error_string, "Error converting charge to character string, %s.", charge); - error_msg(error_string, CONTINUE); - return(ERROR); - } - } - *z=i; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_coef(LDBLE *coef, char **eqnaddr) -/* ---------------------------------------------------------------------- */ -/* - * Function reads through eqn and determines the coefficient of the next - * species. - * - * Arguments: - * *coef output, coefficient of next species. - * - * **eqnaddr input, pointer to a position in eqn to start parsing - * output, pointer to next position after coefficient - * - * Returns: - * ERROR, - * OK. - */ -{ - int i; - char c,c1; - char *ptr, *ptr1, *rest; - char token[MAX_LENGTH];; - - rest=*eqnaddr; - ptr=*eqnaddr; /* address of a position in eqn */ - c=*ptr; /* character in eqn */ - *coef=0.0; -/* - * No leading sign or number - */ - if (isalpha((int) c) || - (c == '(') || - (c == ')') || - (c == '[') || - (c == ']') - ) { - *coef=1.0; - return(OK); - } -/* - * Leading +, no digits - */ - c1=*(ptr+1); - if (c == '+' && - ( isalpha((int) c1) || - (c1 == '(') || - (c1 == ')') || - (c1 == '[') || - (c1 == ']') ) ) { - *eqnaddr=++ptr; - *coef=1.0; - return(OK); - } -/* - * Leading -, no digits - */ - if (c == '-' && - ( isalpha((int) c1) || - (c1 == '(') || - (c1 == ')') || - (c1 == '[') || - (c1 == ']') - ) ) { - *eqnaddr=++ptr; - *coef=-1.0; - return(OK); - } - i=0; -/* - * Has number coefficient - */ - if (isdigit((int) c) || c == '+' || c == '-' || c =='.') { - while (isdigit((int) c) || c == '+' || c == '-' || c =='.') { - token[i++]=c; - if (i >= MAX_LENGTH) { - sprintf(error_string, "Coefficient has more than MAX_LENGTH characters."); - error_msg(error_string, CONTINUE); - return(ERROR); - } - c=*(++ptr); - } - token[i]='\0'; - *eqnaddr=ptr; - errno = 0; - *coef=strtod(token,&ptr1); - if ((errno == ERANGE) || - (*ptr1 != '\0') ) { - sprintf(error_string, "Error converting coefficient in get_coef, %s.", token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - return(OK); - } -/* - * None of the above, unknown construct - */ - sprintf(error_string, "Illegal equation construct detected in get_coef.\n\t%s.", rest); - error_msg(error_string, CONTINUE); - return(ERROR); -} -/* ---------------------------------------------------------------------- */ -int get_elt (char **t_ptr, char *element, int *i) -/* ---------------------------------------------------------------------- */ -/* - * Function reads an element name out of the equation string. - * An element name is composed of a capital letter followed by any number - * of lower case characters. - * - * Arguments: - * **t_ptr input, points to position in the equation to begin - * output, points to next character of equation after - * element name. - * *element input pointer to place to return element character string - */ -{ - char c; - - c=*(*t_ptr)++; - if (c == '\0') { - sprintf(error_string, "Empty string in get_elt. Expected an element name."); - error_msg(error_string, CONTINUE); - return(ERROR); - } -/* - * Load name into char array element - */ - element[0]=c; - *i=1; - if (c == '[') { - while ((c=(**t_ptr)) != ']') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - if ((c=(**t_ptr)) == ']') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - break; - } else if (**t_ptr == '\0') { - error_msg("No ending bracket (]) for element name", CONTINUE); - input_error++; - break; - } - } - while (islower((int) (c=(**t_ptr))) || c == '_') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } - } else { - while (islower((int) (c=(**t_ptr))) || c == '_') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } - } - element[*i]='\0'; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_elts_in_species (char **t_ptr, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Makes a list of elements with their coefficients, stores elements - * in elt_list at position count_elts. Global variable count_elts is - * updated with each stored element. Also uses static global variable - * paren_count. - * - * Arguments: - * **t_ptr input, point in token string to start looking - * output, is next position to start looking - * coef input, coefficient to multiply subscripts by - */ - int i, count, l; - char c, c1; - LDBLE d; - char element[MAX_LENGTH]; - - while ( ( (c=**t_ptr) != '+') && - (c != '-') && (c != '\0') ) { - /* close parenthesis */ - if (c == ')') { - paren_count--; - if (paren_count < 0) { - sprintf(error_string,"Too many right parentheses."); - error_msg(error_string, CONTINUE); - return(ERROR); - } - (*t_ptr)++; - return(OK); - } - c1=*((*t_ptr)+1); - /* beginning of element name */ - if (isupper((int) c) || - (c == 'e' && c1 == '-') - || (c == '[') - ) { -/* - * Get new element and subscript - */ - if ( get_elt( t_ptr, element, &l) == ERROR) { - return(ERROR); - } - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - elt_list[count_elts].elt = element_store ( element ); - if ( get_num( t_ptr , &d ) == ERROR) { - return(ERROR); - } - elt_list[count_elts].coef = d*coef; - count_elts++; -/* - * Expand working space for elements if necessary - */ - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - continue; - } -/* - * Open parentheses - */ - if (c=='(') { - count=count_elts; - if (c1 == ')') { - sprintf(error_string, "Empty parentheses."); - warning_msg(error_string); - } - paren_count++; - (*t_ptr)++; - if ( get_elts_in_species(t_ptr, coef ) == ERROR ) { - return(ERROR); - } - if (get_num (t_ptr, &d) == ERROR ) { - return(ERROR); - } - for (i=count; i < count_elts; i++) { - elt_list[i].coef *= d; - } - continue; - } -/* - * Colon - */ - if (c==':') { - count=count_elts; - (*t_ptr)++; - if (get_num (t_ptr, &d) == ERROR ) { - return(ERROR); - } - if ( get_elts_in_species(t_ptr, coef ) == ERROR ) { - return(ERROR); - } - for (i=count; i < count_elts; i++) { - elt_list[i].coef *= d; - } - continue; - } -/* - * Not beginning of element and not opening paren - */ - sprintf(error_string, "Parsing error in get_elts_in_species, unexpected character, %c.", c); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - if (paren_count != 0) { - sprintf(error_string,"Unbalanced parentheses."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -static int get_secondary (char **t_ptr, char *element, int *i) -/* ---------------------------------------------------------------------- */ -/* - * Function reads an element name out of the equation string. - * An element name is composed of a capital letter followed by any number - * of lower case characters. - * - * Arguments: - * **t_ptr input, points to position in the equation to begin - * output, points to next character of equation after - * element name. - * *element input pointer to place to return element character string - */ -{ - int j; - char c; - char *ptr; - - c=*(*t_ptr)++; - if (c == '\0') { - sprintf(error_string, "Empty string in get_elt. Expected an element name."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Load name into char array element - */ - element[0]=c; - *i=1; - if (c == '[') { - while ((c=(**t_ptr)) != ']') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - if ((c=(**t_ptr)) == ']') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - c=(**t_ptr); - break; - } else if ((c=(**t_ptr)) == '\0') { - error_msg("Did not find ending bracket (])", CONTINUE); - input_error++; - return(ERROR); - } - } - while (islower((int) (c=(**t_ptr))) || c == '_') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } - } else { - while (islower((int) (c=(**t_ptr))) || c == '_') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } - } -/* - * Check if secondary master species element - */ - j = *i; - ptr = *t_ptr; - if (c == '(') { - /* copy parenthesis */ - element[*i]=c; - (*i)++; - (*t_ptr)++; - /* copy number */ - for (;;) { - c = **t_ptr; - if (isdigit((int) c) || c == '-' || c == '.') { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } else if (c == '+') { - (*t_ptr)++; - } else { - break; - } - } - /* go back to before parenthesis */ - if (c != ')' ) { - *i = j; - *t_ptr = ptr; - /* put in closing parenthesis */ - } else { - element[*i]=c; - (*i)++; - (*t_ptr)++; - } - } - element[*i]='\0'; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_secondary_in_species (char **t_ptr, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Makes a list of elements with their coefficients, stores elements - * in elt_list at position count_elts. Global variable count_elts is - * updated with each stored element. Also uses static global variable - * paren_count. - * - * Arguments: - * **t_ptr input, point in token string to start looking - * output, is next position to start looking - * coef input, coefficient to multiply subscripts by - */ - int i, count, l; - char c, c1; - LDBLE d; - char element[MAX_LENGTH]; - - while ( ( (c=**t_ptr) != '+') && - (c != '-') && (c != '\0') ) { - /* close parenthesis */ - if (c == ')') { - paren_count--; - if (paren_count < 0) { - sprintf(error_string,"Too many right parentheses."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } - (*t_ptr)++; - return(OK); - } - c1=*((*t_ptr)+1); - /* beginning of element name */ - if (isupper((int) c) || - c == '[' || - (c == 'e' && c1 == '-') ) { -/* - * Get new element and subscript - */ - if ( get_secondary( t_ptr, element, &l) == ERROR) { - return(ERROR); - } - elt_list[count_elts].elt = element_store ( element ); - if ( get_num( t_ptr , &d ) == ERROR) { - return(ERROR); - } - elt_list[count_elts].coef = d*coef; - count_elts++; -/* - * Expand working space for elements if necessary - */ - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - continue; - } -/* - * Open parentheses - */ - if (c=='(') { - count=count_elts; - if (c1 == ')') { - sprintf(error_string, "Empty parentheses."); - warning_msg(error_string); - } - paren_count++; - (*t_ptr)++; - if ( get_secondary_in_species(t_ptr, coef ) == ERROR ) { - return(ERROR); - } - if (get_num (t_ptr, &d) == ERROR ) { - return(ERROR); - } - for (i=count; i < count_elts; i++) { - elt_list[i].coef *= d; - } - continue; - } -/* - * Colon - */ - if (c==':') { - count=count_elts; - (*t_ptr)++; - if (get_num (t_ptr, &d) == ERROR ) { - return(ERROR); - } - if ( get_secondary_in_species(t_ptr, coef ) == ERROR ) { - return(ERROR); - } - for (i=count; i < count_elts; i++) { - elt_list[i].coef *= d; - } - continue; - } -/* - * Not beginning of element and not opening paren - */ - sprintf(error_string, "Parsing error in get_secondary_in_species, unexpected character, %c.", c); - error_msg(error_string, CONTINUE); - return (ERROR); - } - if (paren_count != 0) { - sprintf(error_string,"Unbalanced parentheses."); - error_msg(error_string, CONTINUE); - return(ERROR); - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int get_num (char **t_ptr, LDBLE *num) -/* ---------------------------------------------------------------------- */ -/* - * Function reads through a string looking for leading numeric field - * if no numeric field is found, the number is set to 1.0. - * - * Arguments: - * - * **t_ptr input, points to a position in a character string from which - * a number is to be extracted. - * output, points to next position to be parsed. - * *num address where the number is to be stored. - * - * Returns: - * ERROR, - * OK. - */ -{ - int i, decimal; - char c; - char *ptr1; - char token[MAX_LENGTH]; - - *num=1.0; - i=0; - c=**t_ptr; - decimal=0; - if (isdigit((int) c) || (c == '.') ){ - while (isdigit((int) c) || (c == '.') ) { - if (c == '.') decimal++; - if (decimal > 1) break; - token[i++]=c; - /* check number length */ - if (i >= MAX_LENGTH ) { - sprintf(error_string, "Number was greater than MAX_LENGTH characters."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } - c=*(++(*t_ptr)); - } - token[i]='\0'; - errno=0; - *num=strtod(token,&ptr1); - if ( errno == ERANGE ) { - sprintf(error_string,"Converting number in get_num, %s.", token); - input_error++; - error_msg(error_string, CONTINUE); - return(ERROR); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_species (char **ptr) -/* ---------------------------------------------------------------------- */ -{ -/* Function reads next species out of the equation, including optional - * preceding coefficient and optional trailing charge. Data are - * store in trxn.token[count]. - * - * Arguments: - * **ptr input, points to the position in the equation to pick up the species. - * output, points to the next character after the species charge. - * - */ - char string[MAX_LENGTH]; - int l; - - if (count_trxn + 1 >= max_trxn) { - space ((void **) &(trxn.token), count_trxn+1, &max_trxn, - sizeof(struct rxn_token_temp)); - } - /* coefficient */ - if ( get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR ) { - return(ERROR); - } - /* name and charge */ - if ( get_token( ptr, string, &trxn.token[count_trxn].z, &l) == ERROR ) { - return(ERROR); - } - trxn.token[count_trxn].name = string_hsave ( string ); - return(OK); -} diff --git a/phqalloc.cpp b/phqalloc.cpp deleted file mode 100644 index 30b6b0f2..00000000 --- a/phqalloc.cpp +++ /dev/null @@ -1,246 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "output.h" -/*#include */ -#include -#include -#include -static char const svnid[] = "$Id: phqalloc.c 78 2005-02-01 22:47:12Z dlpark $"; - -#if defined(PHREEQCI_GUI) -#define _CRTDBG_MAP_ALLOC -#include -#endif - -typedef struct PHRQMemHeader { - struct PHRQMemHeader *pNext; /* memory allocated just after this one */ - struct PHRQMemHeader *pPrev; /* memory allocated just prior to this one */ -#if !defined(NDEBUG) - size_t size; /* memory request + sizeof(PHRQMemHeader) */ - char *szFileName; /* file name */ - int nLine; /* line number */ - int dummy; /* alignment */ -#endif -} PHRQMemHeader; - -/* - * This pointer points to the last allocated block - * Note: s_pTail->pNext should always be NULL - */ -static PHRQMemHeader *s_pTail = NULL; - - -/* ---------------------------------------------------------------------- */ -#if !defined(NDEBUG) -void *PHRQ_malloc( size_t size, const char *szFileName, int nLine) -#else -void *PHRQ_malloc( size_t size) -#endif -/* ---------------------------------------------------------------------- */ -{ - PHRQMemHeader *p; - if (svnid == NULL) fprintf(stderr," "); - - assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); - - p = (PHRQMemHeader*)malloc(sizeof(PHRQMemHeader) + size); - - if (p == NULL) return NULL; - -#if !defined(NDEBUG) - memset(p, 0, sizeof(PHRQMemHeader) + size); -#endif - p->pNext = NULL; - - if ( (p->pPrev = s_pTail) != NULL ) { - s_pTail->pNext = p; - } - -#if !defined(NDEBUG) - p->size = sizeof(PHRQMemHeader) + size; - p->szFileName = (char *) malloc(strlen(szFileName) + 1); - if (p->szFileName) strcpy(p->szFileName, szFileName); - p->nLine = nLine; -#endif - - s_pTail = p; - p++; - return ((void *)(p)); -} - -/* ---------------------------------------------------------------------- */ -void PHRQ_free( void *ptr ) -/* ---------------------------------------------------------------------- */ -{ - PHRQMemHeader *p; - - assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); - - if (ptr == NULL) return; - - p = (PHRQMemHeader *)ptr - 1; - - if (p->pNext != NULL) { - p->pNext->pPrev = p->pPrev; - } else { - /* Handle special case when (p == s_pTail) */ - assert(s_pTail != NULL); - assert(p == s_pTail); - s_pTail = p->pPrev; - } - - if (p->pPrev) { - p->pPrev->pNext = p->pNext; - } - -#if !defined(NDEBUG) - free(p->szFileName); -#endif - - free(p); -} - -/* ---------------------------------------------------------------------- */ -void PHRQ_free_all( void ) -/* ---------------------------------------------------------------------- */ -{ - assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); - - if (s_pTail == NULL) { -#if !defined(NDEBUG) - output_msg(OUTPUT_MESSAGE, "No memory leaks\n"); -#endif - return; - } - while (s_pTail->pPrev != NULL) - { - s_pTail = s_pTail->pPrev; -#if !defined(NDEBUG) - output_msg(OUTPUT_MESSAGE, "%s(%d) %p: freed in PHRQ_free_all\n", - s_pTail->pNext->szFileName, s_pTail->pNext->nLine, (void *) (s_pTail->pNext + 1)); - free(s_pTail->pNext->szFileName); -#endif - free(s_pTail->pNext); - } - -#if !defined(NDEBUG) - output_msg(OUTPUT_MESSAGE, "%s(%d) %p: freed in PHRQ_free_all\n", - s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail+1)); - if (phast == TRUE) { - output_msg(OUTPUT_STDERR, "%s(%d) %p: freed in PHRQ_free_all, %d\n", - s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail+1), phreeqc_mpi_myself); - } - free(s_pTail->szFileName); -#endif - free(s_pTail); - s_pTail = NULL; -} - -/* ---------------------------------------------------------------------- */ -void *PHRQ_calloc( size_t num, - size_t size -#if !defined(NDEBUG) - , - const char *szFileName, - int nLine -#endif - ) -/* ---------------------------------------------------------------------- */ -{ - PHRQMemHeader *p; - - assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); - - p = (PHRQMemHeader*)malloc(sizeof(PHRQMemHeader) + size * num); - - if (p == NULL) return NULL; - - p->pNext = NULL; - - if ( (p->pPrev = s_pTail) != NULL ) { - s_pTail->pNext = p; - } - -#if !defined(NDEBUG) - p->size = sizeof(PHRQMemHeader) + size * num; - p->szFileName = (char *) malloc(strlen(szFileName) + 1); - if (p->szFileName) strcpy(p->szFileName, szFileName); - p->nLine = nLine; -#endif - - s_pTail = p; - p++; - return memset(p, 0, size * num); -} - -/* ---------------------------------------------------------------------- */ -void *PHRQ_realloc( void *ptr, - size_t size -#if !defined(NDEBUG) - , - const char *szFileName, - int nLine -#endif - ) -/* ---------------------------------------------------------------------- */ -{ - PHRQMemHeader *p; - size_t new_size; - -#if !defined(NDEBUG) - size_t old_size; -#endif - - if (ptr == NULL) - { - return PHRQ_malloc(size -#if !defined(NDEBUG) - , - szFileName, - nLine -#endif - ); - } - - assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); - - p = (PHRQMemHeader*)ptr - 1; - - new_size = sizeof(PHRQMemHeader) + size; - -#if defined(NDEBUG) - p = (PHRQMemHeader*)realloc(p, new_size); -#else - old_size = p->size; - p = (PHRQMemHeader*)realloc(p, new_size); - if (p != NULL) { - p->size = new_size; - if (new_size > old_size) { - memset((char*)p + old_size, 0, new_size - old_size); - } - } -#endif - - if (p == NULL) return NULL; - - if (p->pPrev != NULL) { - p->pPrev->pNext = p; - } - - if (p->pNext != NULL) { - p->pNext->pPrev = p; - } else { - s_pTail = p; - } - -#if !defined(NDEBUG) - free(p->szFileName); - p->szFileName = (char *) malloc(strlen(szFileName) + 1); - if (p->szFileName) strcpy(p->szFileName, szFileName); - p->nLine = nLine; -#endif - - p++; - return ((void *)(p)); -} - diff --git a/phreeqc_files.cpp b/phreeqc_files.cpp deleted file mode 100644 index 4d4990df..00000000 --- a/phreeqc_files.cpp +++ /dev/null @@ -1,524 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -#include "input.h" - -/* following line defines path for default data base file */ -const char *default_data_base = "phreeqc.dat"; - -static FILE *input_file = NULL; -static FILE *database_file = NULL; -static FILE *output = NULL; /* OUTPUT_MESSAGE */ -static FILE *log_file = NULL; /* OUTPUT_LOG */ -static FILE *punch_file = NULL; /* OUTPUT_PUNCH */ -static FILE *error_file = NULL; /* OUTPUT_ERROR */ -static FILE *dump_file = NULL; /* OUTPUT_DUMP */ - -static int fileop_handler(const int type, int (*PFN)(FILE*)); -static int open_handler(const int type, const char *file_name); -static int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); -static int rewind_wrapper(FILE* file_ptr); - -static char const svnid[] = "$Id: phreeqc_files.c 78 2005-02-01 22:47:12Z dlpark $"; - -/* ---------------------------------------------------------------------- */ -int phreeqc_handler(const int action, const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -/* ---------------------------------------------------------------------- */ -{ - int i; - - switch (action) { - case ACTION_OPEN: - return open_handler(type, err_str); - break; - case ACTION_OUTPUT: - return output_handler(type, err_str, stop, cookie, format, args); - break; - case ACTION_FLUSH: - return fileop_handler(type, fflush); - break; - case ACTION_REWIND: - return fileop_handler(type, rewind_wrapper); - break; - case ACTION_CLOSE: - - i = fileop_handler(type, fclose); - switch (type) { - case OUTPUT_ERROR: - error_file = NULL; - break; - - case OUTPUT_WARNING: - break; - - case OUTPUT_MESSAGE: - output = NULL; - break; - - case OUTPUT_PUNCH: - punch_file = NULL; - break; - - case OUTPUT_SCREEN: - break; - - case OUTPUT_LOG: - log_file = NULL; - break; - - case OUTPUT_STDERR: - break; - - case OUTPUT_DUMP: - dump_file = NULL; - break; - } - - - return(i); - break; - } - return ERROR; -} -/* ---------------------------------------------------------------------- */ -int close_input_files(void) -/* ---------------------------------------------------------------------- */ -{ - int i = 0; - i |= fclose(database_file); - i |= fclose(input_file); - input_file = database_file = NULL; - return (i); -} -/* ---------------------------------------------------------------------- */ -int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log) -/* ---------------------------------------------------------------------- */ -{ - int l; - char token[2*MAX_LENGTH], default_name[2*MAX_LENGTH]; - char query[2*MAX_LENGTH]; - char in_file[2*MAX_LENGTH], out_file[2*MAX_LENGTH]; - char *env_ptr; - char *ptr; - int errors; - ENTRY item, *found_item; - -/* - * Prepare error handling - */ - errors = setjmp(mark); - if (errors != 0) { - return errors; - } - -/* - * Prep for get_line - */ - max_line = MAX_LINE; - space ((void **) ((void *) &line), INIT, &max_line, sizeof(char)); - space ((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); - hcreate_multi(5, &strings_hash_table); - hcreate_multi(2, &keyword_hash_table); - -/* - * Initialize hash table - */ - keyword_hash = (struct key *) PHRQ_malloc(sizeof(struct key)); - if (keyword_hash == NULL) { - malloc_error(); - } else { - keyword_hash->name = string_hsave("database"); - keyword_hash->keycount = 0; - item.key = keyword_hash->name; - item.data = keyword_hash; - found_item = hsearch_multi(keyword_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in keyword initialization."); - error_msg(error_string, STOP); - } - } - - -/* - * Open file for screen output - */ - if (argc > 4) { - error_file = fopen(argv[4], "w"); - if (error_file == NULL) { - error_file = stderr; - sprintf(error_string, "Error opening file, %s.", argv[4]); - warning_msg(error_string); - } - } else { - error_file = stderr; - } - -/* - * Open user-input file - */ - strcpy(query,"Name of input file?"); - if (argc <= 1) { - default_name[0]='\0'; - input_file = file_open(query, default_name, "r", FALSE); - } else { - strcpy(default_name, argv[1]); - input_file = file_open(query, default_name, "r", TRUE); - } - output_msg(OUTPUT_SCREEN, "Input file: %s\n\n", default_name); - output_msg(OUTPUT_SEND_MESSAGE, "Input file: %s\r\n\r\n", default_name); - strcpy(in_file, default_name); -/* - * Open file for output - */ - strcpy(query,"Name of output file?"); -#ifdef DOS - replace("."," ",default_name); -#endif - ptr = default_name; - copy_token(token, &ptr, &l); - strcat(token,".out"); - if (argc <= 1) { - output = file_open(query, token, "w", FALSE); - } else if (argc == 2) { - output = file_open(query, token, "w", TRUE); - } else if (argc >= 3) { - strcpy(token, argv[2]); - output = file_open(query, token, "w", TRUE); - } - output_msg(OUTPUT_SCREEN, "Output file: %s\n\n", token); - output_msg(OUTPUT_SEND_MESSAGE, "Output file: %s\r\n\r\n", token); - strcpy(out_file, token); -/* - * Open file for errors - */ - if (log == TRUE) { - if ((log_file = fopen("phreeqc.log","w")) == NULL) { - error_msg ("Can't open log file, phreeqc.log.", STOP); - } - } - /* - * Read input file for DATABASE keyword - */ - if (get_line(getc_callback, input_file) == KEYWORD) { - ptr = line; - copy_token(token, &ptr, &l); - if (strcmp_nocase(token, "database") == 0) { - user_database = string_duplicate(ptr); - if (string_trim(user_database) == EMPTY) { - warning_msg("DATABASE file name is missing; default database will be used."); - user_database = (char *) free_check_null(user_database); - } - } - } - fclose(input_file); - if ((input_file = fopen(in_file,"r")) == NULL) {; - error_msg ("Can't reopen input file.", STOP); - } -/* - * Open data base - */ - strcpy(query,"Name of database file?"); - env_ptr = getenv("PHREEQC_DATABASE"); - if (user_database != NULL) { - strcpy(token, user_database); - } else if (env_ptr != NULL) { - strcpy(token, env_ptr); - } else { - strcpy(token, default_data_base); - } - if (argc <= 1) { - database_file = file_open(query, token, "r", FALSE); - } else if (argc < 4) { - database_file = file_open(query, token, "r", TRUE); - } else if (argc >= 4) { - if (user_database == NULL) { - strcpy(token, argv[3]); - } else { -#ifndef PHREEQCI_GUI - warning_msg("Database file from DATABASE keyword is used; command line argument ignored."); -#endif - } - database_file = file_open(query, token, "r", TRUE); - } - output_msg(OUTPUT_SCREEN, "Database file: %s\n\n", token); - output_msg(OUTPUT_SEND_MESSAGE, "Database file: %s\r\n\r\n", token); - - - output_msg(OUTPUT_MESSAGE, " Input file: %s\n", in_file); - output_msg(OUTPUT_MESSAGE, " Output file: %s\n", out_file); - output_msg(OUTPUT_MESSAGE, "Database file: %s\n\n", token); - - -/* - * local cleanup - */ - user_database = (char *) free_check_null(user_database); - line = (char *) free_check_null(line); - line_save = (char *) free_check_null(line_save); - - hdestroy_multi(keyword_hash_table); - keyword_hash = (struct key *) free_check_null(keyword_hash); - keyword_hash_table = NULL; - - free_hash_strings(strings_hash_table); - hdestroy_multi(strings_hash_table); - strings_hash_table = NULL; - - *db_cookie = database_file; - *input_cookie = input_file; - - return 0; -} -/* ---------------------------------------------------------------------- */ -int getc_callback(void* cookie) -/* ---------------------------------------------------------------------- */ -{ - int i; - assert(cookie); - i = getc((FILE*)cookie); -#ifdef PHREEQ98 - if (i == '\n') ++inputlinenr; -#endif - return i; -} - -/* ---------------------------------------------------------------------- */ -static int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args) -/* ---------------------------------------------------------------------- */ -{ - int flush; - FILE *save_output = NULL; - - flush = TRUE; - - if (get_forward_output_to_log()) { - save_output = output; - output = log_file; - } - - switch (type) { - - case OUTPUT_ERROR: - if (status_on == TRUE) { - if (error_file != NULL) { - fprintf(error_file, "\n"); - } -#ifndef DOS - status_on = FALSE; -#endif - } - if (error_file != NULL) { - fprintf(error_file, "ERROR: %s\n", err_str); - if (flush) fflush(error_file); - } - if (output != NULL) { - fprintf(output, "ERROR: %s\n", err_str); - if (flush) fflush(output); - } - if (stop == STOP) { - if (error_file != NULL) { - fprintf(error_file, "Stopping.\n"); - fflush(error_file); - } - if (output != NULL) { - fprintf(output, "Stopping.\n"); - fflush(output); - } - } - break; - - case OUTPUT_WARNING: - if (pr.logfile == TRUE && log_file != NULL) { - fprintf(log_file,"WARNING: %s\n", err_str); - if (flush) fflush(log_file); - } - if (state == TRANSPORT && transport_warnings == FALSE) return(OK); - if (state == ADVECTION && advection_warnings == FALSE) return(OK); - if (pr.warnings >= 0) { - if (count_warnings > pr.warnings) return(OK); - } - if (status_on == TRUE) { - if (error_file != NULL) { - fprintf(error_file,"\n"); - } -#ifndef DOS - status_on = FALSE; -#endif - } - if (error_file != NULL) { - fprintf(error_file,"WARNING: %s\n", err_str); - if (flush) fflush(error_file); - } - if (output != NULL) { - fprintf(output,"WARNING: %s\n", err_str); - if (flush) fflush(output); - } - break; - case OUTPUT_CHECKLINE: - if (pr.echo_input == TRUE) { - if (output != NULL) { - vfprintf(output, format, args); - if (flush) fflush(output); - } - } - break; - case OUTPUT_MESSAGE: - case OUTPUT_BASIC: - if (output != NULL) { - vfprintf(output, format, args); - if (flush) fflush(output); - } - break; - case OUTPUT_PUNCH: - if (punch_file != NULL) { - if (pr.punch == TRUE && punch.in == TRUE) { - vfprintf(punch_file, format, args); - if (flush) fflush(punch_file); - } - } - break; - case OUTPUT_LOG: - if (pr.logfile == TRUE && log_file != NULL) { - vfprintf(log_file, format, args); - if (flush) fflush(log_file); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL) { - vfprintf(error_file, format, args); - if (flush) fflush(error_file); - } - break; - case OUTPUT_STDERR: - case OUTPUT_CVODE: - if (stderr != NULL) { - vfprintf(stderr, format, args); - fflush(stderr); - } - break; - case OUTPUT_DUMP: - if (dump_file != NULL) { - vfprintf(dump_file, format, args); - if (flush) fflush(dump_file); - } - break; - } - - if (get_forward_output_to_log()) { - output = save_output; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int close_output_files(void) -/* ---------------------------------------------------------------------- */ -{ - int ret = 0; - - if (output != NULL) ret |= fclose(output); - if (log_file != NULL) ret |= fclose(log_file); - if (punch_file != NULL) ret |= fclose(punch_file); - if (dump_file != NULL) ret |= fclose(dump_file); - if (error_file != NULL) ret |= fclose(error_file); - error_file = NULL; - output = log_file = punch_file = dump_file = NULL; - return ret; -} -/* ---------------------------------------------------------------------- */ -static int open_handler(const int type, const char *file_name) -/* ---------------------------------------------------------------------- */ -{ - switch (type) { - - case OUTPUT_PUNCH: - if (punch_file != NULL) { - fclose(punch_file); - punch_file = NULL; - } - if( (punch_file = fopen(file_name, "w")) == NULL) { - return ERROR; - } else { - free_check_null(selected_output_file_name); - selected_output_file_name = string_duplicate(file_name); - } - break; - - case OUTPUT_DUMP: - if (dump_file != NULL) { - fclose(dump_file); - dump_file = NULL; - } - if( (dump_file = fopen(file_name, "w")) == NULL) { - return ERROR; - } else { - free_check_null(dump_file_name); - dump_file_name = string_duplicate(file_name); - } - break; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int fileop_handler(const int type, int (*PFN)(FILE*)) -/* ---------------------------------------------------------------------- */ -{ - FILE *save_output = NULL; - - int forward = get_forward_output_to_log(); - if (forward) { - save_output = output; - output = log_file; - } - - switch (type) { - case OUTPUT_ERROR: - if (error_file) PFN(error_file); - break; - - case OUTPUT_WARNING: - if (error_file) PFN(error_file); - if (output) PFN(output); - break; - - case OUTPUT_MESSAGE: - case OUTPUT_CHECKLINE: - case OUTPUT_BASIC: - if (output) PFN(output); - break; - - case OUTPUT_PUNCH: - if (punch_file) PFN(punch_file); - break; - - case OUTPUT_SCREEN: - if (error_file) PFN(error_file); - break; - - case OUTPUT_LOG: - if (log_file) PFN(log_file); - break; - - case OUTPUT_CVODE: - case OUTPUT_STDERR: - if (stderr) PFN(stderr); - break; - - case OUTPUT_DUMP: - if (dump_file) PFN(dump_file); - break; - } - - if (forward) { - output = save_output; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int rewind_wrapper(FILE* file_ptr) -/* ---------------------------------------------------------------------- */ -{ - rewind(file_ptr); - return(OK); -} diff --git a/phrqproto.h b/phrqproto.h deleted file mode 100644 index f83016db..00000000 --- a/phrqproto.h +++ /dev/null @@ -1,515 +0,0 @@ -#ifdef PHREEQC_IDENT -static char const svnidphrqproto[] = "$Id$"; -#endif -/* advection.c */ -int advection(void); -/* basic.c */ -LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles); -int basic_main(char *commands); -void cmd_initialize(void); -void cmd_free(void); -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -/* basicsubs.c */ -LDBLE activity (char *species_name); -LDBLE calc_logk_n(char *name); -LDBLE calc_logk_p(char *name); -LDBLE calc_logk_s(char *name); -LDBLE calc_surface_charge(char *surface_name); -LDBLE diff_layer_total(char *total_name, char *surface_name); -LDBLE equi_phase (char *phase_name); -LDBLE find_gas_comp (char *gas_comp_name); -LDBLE find_misc1 (char *s_s_name); -LDBLE find_misc2 (char *s_s_name); -LDBLE find_s_s_comp (char *s_s_comp_name); -LDBLE get_calculate_value(char *name); -LDBLE kinetics_moles (char *kinetics_name); -LDBLE log_activity (char *species_name); -LDBLE log_molality (char *species_name); -LDBLE molality (char *species_name); -LDBLE saturation_ratio (char *phase_name); -int saturation_index (char *phase_name, LDBLE *iap, LDBLE *si); -LDBLE solution_sum_secondary(char *total_name); -LDBLE sum_match_gases (char *stemplate, char *name); -LDBLE sum_match_species (char *stemplate, char *name); -LDBLE sum_match_s_s (char *stemplate, char *name); -int match_elts_in_species (char *name, char *stemplate); -int extract_bracket(char **string, char *bracket_string); -LDBLE surf_total(char *total_name, char *surface_name); -int system_species_compare(const void *ptr1, const void *ptr2); -LDBLE system_total(char *total_name, LDBLE *count, char ***names, char ***types, LDBLE **moles); -int system_total_elements(void); -int system_total_si(void); -int system_total_aq(void); -int system_total_ex(void); -int system_total_surf(void); -int system_total_gas(void); -int system_total_s_s(void); -int system_total_elt(char *total_name); -int system_total_elt_secondary(char *total_name); -LDBLE total (char *total_name); - -/* cl1.c */ -int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE *q, - int *kode, LDBLE toler, - int *iter, LDBLE *x, LDBLE *res, LDBLE *error, - LDBLE *cu, int *iu, int *s, - int check); - -/* default.c */ -int close_input_files(void); -int close_output_files(void); -int getc_callback(void* cookie); -int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); - -/* integrate.c */ -int calc_all_g(void); -int calc_init_g(void); -int initial_surface_water(void); -int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); -int calc_all_donnan(void); -int calc_init_donnan(void); - -/* inverse.c */ -int inverse_models(void); - -/* isotopes.c */ -int add_isotopes(struct solution *solution_ptr); -int calculate_values(void); -int calculate_isotope_moles(struct element *elt_ptr, struct solution *solution_ptr, LDBLE total_moles); -LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); -int from_pcil(struct master_isotope *master_isotope_ptr); -int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_tu(struct master_isotope *master_isotope_ptr); -struct calculate_value *calculate_value_alloc(void); -int calculate_value_free(struct calculate_value *calculate_value_ptr); -struct calculate_value *calculate_value_search (char *name); -struct calculate_value *calculate_value_store (char *name, int replace_if_found); -struct isotope_alpha *isotope_alpha_alloc(void); -struct isotope_alpha *isotope_alpha_search (char *name); -struct isotope_alpha *isotope_alpha_store (char *name, int replace_if_found); -struct isotope_ratio *isotope_ratio_alloc(void); -struct isotope_ratio *isotope_ratio_search (char *name); -struct isotope_ratio *isotope_ratio_store (char *name, int replace_if_found); -struct master_isotope *master_isotope_store (char *name, int replace_if_found); -struct master_isotope *master_isotope_alloc(void); -struct master_isotope *master_isotope_search (char *name); -int print_initial_solution_isotopes(void); -int print_isotope_ratios(void); -int print_isotope_alphas(void); -int punch_isotopes(void); -int punch_calculate_values(void); -int read_calculate_values (void); -int read_isotopes(void); -int read_isotope_ratios (void); -int read_isotope_alphas (void); - -/* kinetics.c */ - -void cvode_init(void); -int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); -int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); -int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); -int set_advection(int i, int use_mix, int use_kinetics, int nsaver); -int free_cvode(void); - -/* main.c */ -int main(int argc, char *argv[]); - -/* mainsubs.c */ -FILE *file_open (char *query, char *default_name, const char *status, int batch); -int copy_entities(void); -void initialize(void); -int initial_exchangers(int print); -int initial_gas_phases(int print); -int initial_solutions(int print); -int step_save_exch(int n_user); -int step_save_surf(int n_user); -int initial_surfaces(int print); -int k_temp(LDBLE tempc); -int reactions(void); -int saver(void); -int xsolution_save(int k_user); -int do_initialize(void); -int do_status(void); - -/* model.c */ -int check_residuals(void); -int free_model_allocs(void); -int ineq(int kode); -int model(void); -int jacobian_sums (void); -int mb_gases(void); -int mb_s_s(void); -int mb_sums (void); -int molalities (int allow_overflow); -int reset(void); -int residuals(void); -int set(int initial); -int sum_species(void); -int surface_model(void); - -/* p2clib.c */ - -/* parse.c */ -int check_eqn ( int association ); -int get_charge(char *charge, LDBLE *z); -int get_elt (char **t_ptr, char *element, int *i); -int get_elts_in_species (char **t_ptr, LDBLE coef); -int get_num (char **t_ptr, LDBLE *num); -int get_secondary_in_species (char **t_ptr, LDBLE coef); -int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - -/* pitzer.c */ -int gammas_pz(void); -int model_pz(void); -int pitzer (void); -int pitzer_clean_up(void); -int pitzer_init (void); -int pitzer_tidy (void); -int read_pitzer (void); -int set_pz(int initial); - -/* prep.c */ -int check_same_model(void); -int k_temp(LDBLE tc); -LDBLE k_calc(LDBLE *logk, LDBLE tempk); -int prep(void); -int reprep (void); -int rewrite_master_to_secondary(struct master *master_ptr1, struct master *master_ptr2); -int switch_bases(void); -int write_phase_sys_total (int n); - -/* print.c */ -int fpunchf(const char* name, const char* format, ...); -int fpunchf_user(int user_index, const char* format, ...); -char *sformatf(const char* format, ...); -int array_print(LDBLE *array_l, int row_count, int column_count, int max_column_count); -int print_all(void); -int print_exchange(void); -int print_gas_phase(void); -int print_master_reactions(void); -int print_reaction(struct reaction *rxn_ptr); -int print_species(void); -int print_surface(void); -int punch_all(void); - -/* read.c */ -int read_input(void); -int read_conc(int n, int count_mass_balance, char *str); -int *read_list_ints_range (char **ptr, int *count_ints, int positive, int *int_list ); -int read_log_k_only (char *ptr, LDBLE *log_k); -int read_number_description (char *ptr, int *n_user, int *n_user_end, - char **description); -int check_key (char *str); -int check_units (char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print); -int find_option(char *item, int *n, const char **list, int count_list, int exact); -int get_option (const char **opt_list, int count_opt_list, char **next_char); -int get_true_false(char *string, int default_value); - -/* readtr.c */ -int read_transport (void); -int dump(void); -int dump_exchange(int k); -int dump_gas_phase(int k); -int dump_kinetics (int k); -int dump_mix (int k); -int dump_pp_assemblage(int k); -int dump_reaction (int k); -int dump_s_s_assemblage (int k); -int dump_solution (int k); -int dump_surface(int k); - -/* spread.c */ -int read_solution_spread(void); - -/* step.c */ -int step(LDBLE step_fraction); -int xsolution_zero (void); -int add_exchange (struct exchange *exchange_ptr); -int add_gas_phase (struct gas_phase *gas_phase_ptr); -int add_kinetics (struct kinetics *kinetics_ptr); -int add_mix (struct mix *mix_ptr); -int add_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr); -int add_reaction (struct irrev *irrev_ptr, int step_number, LDBLE step_fraction); -int add_s_s_assemblage (struct s_s_assemblage *s_s_assemblage_ptr); -int add_solution (struct solution *solution_ptr, LDBLE extensive, - LDBLE intensive); -int add_surface (struct surface *surface_ptr); -int add_temperature(struct temperature *temperature_ptr, int step_number); - -/* structures.c */ -int clean_up(void); -int copier_add(struct copier *copier_ptr, int n_user, int start, int end); -int copier_free(struct copier *copier_ptr); -int copier_init(struct copier *copier_ptr); -int copy_entities(void); -int element_compare(const void *ptr1, const void *ptr2); -struct element *element_store (char *element); -int elt_list_combine(void); -int elt_list_compare(const void *ptr1, const void *ptr2); -struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); -int elt_list_print(struct elt_list *elt_list_ptr); -struct elt_list *elt_list_save(void); - -struct exchange *exchange_alloc (void); -struct exchange *exchange_bsearch (int k, int *n); -int exchange_comp_compare(const void *ptr1, const void *ptr2); -int exchange_copy(struct exchange *exchange_old_ptr, struct exchange *exchange_new_ptr, int n_user_new); -int exchange_compare (const void *ptr1, const void *ptr2); -int exchange_copy_to_last(int n, int n_user); -int exchange_delete(int n_user_old); -int exchange_duplicate(int n_user_old, int n_user_new); -int exchange_init (struct exchange *exchange_ptr, int n_user, int n_user_end, char *description); -int exchange_free (struct exchange *exchange_ptr); -int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); -struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new); -struct exchange *exchange_search(int n_user, int *n, int print); -int exchange_sort(void); - -int gas_comp_compare(const void *ptr1, const void *ptr2); -struct gas_phase *gas_phase_alloc (void); -struct gas_phase *gas_phase_bsearch (int k, int *n); -int gas_phase_compare (const void *ptr1, const void *ptr2); -int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new); -int gas_phase_copy_to_last(int n, int n_user); -int gas_phase_delete(int n_user_old); -int gas_phase_duplicate(int n_user_old, int n_user_new); -int gas_phase_init (struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description); -int gas_phase_free (struct gas_phase *gas_phase_ptr); -int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new); -struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, int n_user_new); -struct gas_phase *gas_phase_search (int n_user, int *n); -int gas_phase_sort(void); - -enum entity_type get_entity_enum (char *name); - -struct inverse *inverse_alloc(void); -int inverse_delete (int i); -int inverse_isotope_compare (const void *ptr1, const void *ptr2); -struct inverse *inverse_search (int n_user, int *n); -int inverse_sort(void); - -struct irrev *irrev_bsearch (int k, int *n); -int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, int n_user_new); -int irrev_duplicate(int n_user_old, int n_user_new); -int irrev_free (struct irrev *irrev_ptr); -struct irrev *irrev_search(int n_user, int *n); - -struct kinetics *kinetics_alloc (void); -struct kinetics *kinetics_bsearch (int k, int *n); -int kinetics_delete(int n_user_old); -int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr); -int kinetics_compare (const void *ptr1, const void *ptr2); -int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new); -int kinetics_copy_to_last(int n, int n_user); -int kinetics_duplicate(int n_user_old, int n_user_new); -int kinetics_init (struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description); -int kinetics_free (struct kinetics *kinetics_ptr); -int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); -struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new); -struct kinetics *kinetics_search(int n_user, int *n, int print); -int kinetics_sort(void); - -struct logk *logk_alloc(void); -struct logk *logk_store (char *name, int replace_if_found); -struct logk *logk_search (char *name); - -struct master *master_alloc(void); -int master_compare (const void *ptr1, const void *ptr2); -int master_delete(char *ptr); -struct master *master_bsearch (const char *ptr); -struct master *master_bsearch_primary (char *ptr); -struct master *master_search (char *ptr, int *n); - -struct mix *mix_bsearch (int k, int *n); -int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new); -int mix_duplicate(int n_user_old, int n_user_new); -int mix_free (struct mix *mix_ptr); -struct mix *mix_search(int n_user, int *n, int print); -int mix_sort(void); - -struct pe_data *pe_data_alloc(void); -struct pe_data *pe_data_dup (struct pe_data *pe_ptr_old); -int pe_data_free (struct pe_data *pe_data_ptr); -int pe_data_store (struct pe_data **pe, const char *token); - -struct phase *phase_bsearch (char *ptr, int *j, int print); -int phase_compare(const void *ptr1, const void *ptr2); -int phase_delete(int i); -struct phase *phase_store (char *name); - -struct pp_assemblage *pp_assemblage_alloc (void); -struct pp_assemblage *pp_assemblage_bsearch (int k, int *n); -int pp_assemblage_compare(const void *ptr1, const void *ptr2); -int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new); -int pp_assemblage_copy_to_last(int n, int n_user); -int pp_assemblage_delete(int n_user_old); -int pp_assemblage_duplicate(int n_user_old, int n_user_new); -int pp_assemblage_free (struct pp_assemblage *pp_assemblage_ptr); -int pp_assemblage_init (struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description); -int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, int n_user_new); -struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, int n_user_new); -struct pp_assemblage *pp_assemblage_search (int n_user, int *n); -int pp_assemblage_sort(void); - -int pure_phase_compare (const void *ptr1, const void *ptr2); - -struct rate *rate_bsearch (char *ptr, int *j); -int rate_free(struct rate *rate_ptr); -struct rate *rate_search (char *name, int *n); -int rate_sort(void); - -struct reaction *rxn_alloc(int ntokens); -struct reaction *rxn_dup(struct reaction *rxn_ptr_old); -LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); -int rxn_free(struct reaction *rxn_ptr); - -int s_compare (const void *ptr1, const void *ptr2); -int s_delete (int i); -struct species *s_search (char *name); -struct species *s_store (char *name, LDBLE z, int replace_if_found); - -struct s_s_assemblage *s_s_assemblage_alloc (void); -struct s_s_assemblage *s_s_assemblage_bsearch (int k, int *n); -int s_s_assemblage_compare (const void *ptr1, const void *ptr2); - -int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new); -int s_s_assemblage_copy_to_last(int n, int n_user); -int s_s_assemblage_duplicate(int n_user_old, int n_user_new); -int s_s_assemblage_delete(int n_user_old); -int s_s_assemblage_free (struct s_s_assemblage *s_s_assemblage_ptr); -int s_s_assemblage_init (struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description); -int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, int n_user_new); -struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage *s_s_assemblage_old_ptr, int n_user_new); -struct s_s_assemblage *s_s_assemblage_search (int n_user, int *n); -int s_s_assemblage_sort(void); -int s_s_compare (const void *ptr1, const void *ptr2); - -struct save_values *save_values_bsearch (struct save_values *k, int *n); -int save_values_compare(const void *ptr1, const void *ptr2); -int save_values_sort(void); -int save_values_store(struct save_values *s_v); - -int conc_compare(const void *ptr1, const void *ptr2); -int conc_init (struct conc *conc_ptr); -int isotope_compare (const void *ptr1, const void *ptr2); -struct solution *solution_alloc(void); -struct solution *solution_bsearch (int k, int *n, int print); -int solution_copy_to_last(int n, int n_user_new); -int solution_duplicate(int n_user_old, int n_user_new); -int solution_delete(int n_user_old); -int solution_free (struct solution *solution_ptr); -int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); -struct solution *solution_replicate(struct solution *solution_old_ptr, int n_user_new); -int solution_sort(void); - -int species_list_compare_alk (const void *ptr1, const void *ptr2); -int species_list_compare_master (const void *ptr1, const void *ptr2); -int species_list_sort(void); - -struct surface *surface_alloc (void); -struct surface *surface_bsearch (int k, int *n); -int surface_comp_compare(const void *ptr1, const void *ptr2); -int surface_compare (const void *ptr1, const void *ptr2); -int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new); -int surface_copy_to_last(int n, int n_user); -int surface_delete(int n_user_old); -int surface_duplicate(int n_user_old, int n_user_new); -int surface_free(struct surface *surface_ptr); -int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description); -int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); -struct surface *surface_replicate(struct surface *surface_old_ptr, int n_user_new); -struct surface *surface_search(int n_user, int *n, int print); -int surface_sort(void); - -int system_duplicate (int i, int save_old); - -struct temperature *temperature_bsearch (int k, int *n); -int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new); -int temperature_duplicate(int n_user_old, int n_user_new); -int temperature_free (struct temperature *temperature_ptr); -struct temperature *temperature_search(int n_user, int *n); -int temperature_sort(void); - -int trxn_add (struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_combine (void); -int trxn_copy (struct reaction *rxn_ptr); -LDBLE trxn_find_coef(const char *str, int start); -int trxn_print (void); -int trxn_reverse_k (void); -int trxn_sort( void ); -int trxn_swap (const char *token); - -struct unknown *unknown_alloc(void); -int unknown_delete(int i); -int unknown_free(struct unknown *unknown_ptr); - -/* tally.c */ -void add_all_components_tally(void); -int build_tally_table(void); -int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); -int diff_tally_table(void); -int extend_tally_table(void); -int free_tally_table(void); -int fill_tally_table(int *n_user, int index_conservative, int n_buffer); -int get_tally_table_rows_columns(int *rows, int *columns); -int get_tally_table_column_heading(int column, int *type, char *string); -int get_tally_table_row_heading(int column, char *string); -int store_tally_table(double *array, int row_dim, int col_dim, double fill_factor); -int zero_tally_table(void); - -/* tidy.c */ -int add_other_logk(LDBLE *source_k, int count_add_logk, struct name_coef *add_logk); -int select_log_k_expression(LDBLE *source_k, LDBLE *target_k); -int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); -int tidy_punch(void); -int tidy_model(void); - -/* transport.c */ -int transport(void); -int set_initial_moles(int i); - -/* utilities.c */ -int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); -int backspace_screen (int spaces); -LDBLE calc_alk(struct reaction *rxn_ptr); -int compute_gfw(const char *string, LDBLE *gfw); -int copy_token (char *token_ptr, char **ptr, int *length); -int dup_print(const char *ptr, int emphasis); -int equal (LDBLE a, LDBLE b, LDBLE eps); -void *free_check_null(void *ptr); -void free_hash_strings(HashTable *Table); -int get_token(char **eqnaddr, char *string, LDBLE *z, int *l); -int hcreate_multi(unsigned Count, HashTable **HashTable_ptr); -void hdestroy_multi(HashTable *HashTable_ptr); -ENTRY * hsearch_multi(HashTable *Table, ENTRY item, ACTION action); -int islegit(const char c); -void malloc_error (void); -int parse_couple(char *token); -int print_centered(const char *string); -int replace(const char *str1, const char *str2, char *str); -void space (void **ptr, int i, int *max, int struct_size); -void squeeze_white(char *s_l); -int status (int count, const char *str); -void str_tolower(char *str); -void str_toupper(char *str); -int strcmp_nocase(const char *str1, const char *str2); -int strcmp_nocase_arg1(const char *str1, const char *str2); -char * string_duplicate (const char *token); -char *string_hsave (const char *str); -char *string_pad (char *str, int i); -int string_trim (char *str); -int string_trim_right (char *str); -int string_trim_left (char *str); -LDBLE under (LDBLE xval); -int get_elts_in_species (char **t_ptr, LDBLE coef); diff --git a/phrqtype.h b/phrqtype.h deleted file mode 100644 index 01ff322c..00000000 --- a/phrqtype.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * The following implements long double - * Many machines long double = double so there is no advantage - * Check float.h include file for number of digits (LDBL_DIG) - * Need to define here and in cl1.c - */ -#ifdef PHREEQC_IDENT -static char const svnidphrqtype[] = "$Id$"; -#endif - -/*#define USE_LONG_DOUBLE*/ -#ifdef USE_LONG_DOUBLE - #define LDBLE long double - #define SCANFORMAT "%Lf" -#else - #define LDBLE double - #define SCANFORMAT "%lf" -#endif - diff --git a/pitzer.cpp b/pitzer.cpp deleted file mode 100644 index ddc59250..00000000 --- a/pitzer.cpp +++ /dev/null @@ -1,1587 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -#define PITZER -#define PITZER_EXTERNAL -#include "pitzer.h" - -static char const svnid[] = "$Id: pitzer.c 248 2005-04-14 17:10:53Z dlpark $"; -/* variables */ -static double A0; -struct species **spec, **cations, **anions, **neutrals; -static int count_cations, count_anions, count_neutrals; -static int MAXCATIONS, FIRSTANION, MAXNEUTRAL; -struct pitz_param *mcb0, *mcb1, *mcc0; -static int *IPRSNT; -static double *M, *LGAMMA; -static double BK[23], DK[23]; - -/* routines */ -static int calc_pitz_param (struct pitz_param *pz_ptr, double TK, double TR); -static int check_gammas_pz(void); -static int ISPEC(char * name); -/*static int DH_AB (double TK, double *A, double *B);*/ -static double G (double Y); -static double GP (double Y); -#ifdef SKIP -static double ETHETAP (double ZJ, double ZK, double I); -static double ETHETA (double ZJ, double ZK, double I); -#endif -static int ETHETAS (double ZJ, double ZK, double I, double *etheta, double *ethetap); -static int BDK (double X); -static int initial_guesses(void); -static int revise_guesses(void); -static int remove_unstable_phases; - - -/* ---------------------------------------------------------------------- */ -int pitzer_init (void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Initialization for pitzer - */ - pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; - space ((void **) ((void *) &pitz_params), INIT, &max_pitz_param, sizeof(struct pitz_param *)); - - max_theta_param = 100; - count_theta_param = 0; - space ((void **) ((void *) &theta_params), INIT, &max_theta_param, sizeof(struct theta_param *)); - - ICON = TRUE; - OTEMP=0.0; - for (i = 0; i < 23; i++) { - BK[i] = 0.0; - DK[i] = 0.0; - } - return OK; -} -/* ---------------------------------------------------------------------- */ -int pitzer_tidy (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make lists of species for cations, anions, neutral - */ - char * string1, *string2; - int i, j, order; - double z0, z1; - struct pitz_param *pzp_ptr; - struct theta_param *theta_param_ptr; - /* - * allocate pointers to species structures - */ - if (spec != NULL) spec = (struct species **) free_check_null(spec); - spec = (struct species **) PHRQ_malloc((size_t) (3*count_s*sizeof(struct species *))); - if (spec == NULL) malloc_error(); - for (i = 0; i < 3*count_s; i++) spec[i] = NULL; - cations = spec; - neutrals = &(spec[count_s]); - anions = &(spec[2*count_s]); - MAXCATIONS = count_s; - FIRSTANION = 2*count_s; - MAXNEUTRAL = count_s; - count_cations = 0; - count_anions = 0; - count_neutrals = 0; - if (itmax < 200) itmax = 200; - /* - * allocate other arrays for Pitzer - */ - if (IPRSNT != NULL) IPRSNT = (int *) free_check_null(IPRSNT); - IPRSNT = (int *) PHRQ_malloc((size_t) (3*count_s*sizeof(int))); - if (IPRSNT == NULL) malloc_error(); - if (M != NULL) M = (double *) free_check_null(M); - M = (double *) PHRQ_malloc((size_t) (3*count_s*sizeof(double))); - if (M == NULL) malloc_error(); - if (LGAMMA != NULL) LGAMMA = (double *) free_check_null(LGAMMA); - LGAMMA = (double *) PHRQ_malloc((size_t) (3*count_s*sizeof(double))); - if (LGAMMA == NULL) malloc_error(); - - - for (i = 0; i < count_s; i++) { - if (s[i] == s_eminus) continue; - if (s[i] == s_h2o) continue; - if (s[i]->z < -.001) { - anions[count_anions++] = s[i]; - } else if (s[i]->z > .001) { - cations[count_cations++] = s[i]; - } else { - neutrals[count_neutrals++] = s[i]; - } - } - /* - * Add etheta to parameter list in case theta not defined for - * cation-cation or anion-anion pair - * Remove old TYPE_ETHETA definitions - */ - j = 0; - for (i = 0; i < count_pitz_param; i++) { - if (pitz_params[i]->type == TYPE_ETHETA) { - pitz_params[i] = (struct pitz_param *) free_check_null(pitz_params[i]); - } else { - pitz_params[j++] = pitz_params[i]; - } - } - count_pitz_param = j; - for (i = 0; i < count_cations - 1; i++) { - for (j = i+1; j < count_cations; j++) { - sprintf(line,"%s %s 1", spec[i]->name, spec[j]->name); - pzp_ptr = pitz_param_read(line, 2); - pzp_ptr->type = TYPE_ETHETA; - if (count_pitz_param >= max_pitz_param) { - space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); - } - pitz_params[count_pitz_param++] = pzp_ptr; - - } - } - for (i = 2*count_s; i < 2*count_s + count_anions - 1; i++) { - for (j = i+1; j < 2*count_s + count_anions; j++) { - sprintf(line,"%s %s 1", spec[i]->name, spec[j]->name); - pzp_ptr = pitz_param_read(line, 2); - pzp_ptr->type = TYPE_ETHETA; - if (count_pitz_param >= max_pitz_param) { - space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); - } - pitz_params[count_pitz_param] = pzp_ptr; - count_pitz_param++; - } - } - /* - * put species numbers in pitz_params - */ - for (i = 0; i < count_pitz_param; i++) { - for (j = 0; j < 3; j++) { - if (pitz_params[i]->species[j] == NULL) continue; - pitz_params[i]->ispec[j] = ISPEC(pitz_params[i]->species[j]); - if ((j < 2 && pitz_params[i]->ispec[j] == -1) || - (j == 3 && (pitz_params[i]->type == TYPE_PSI || pitz_params[i]->type == TYPE_ZETA) && pitz_params[i]->ispec[j] == -1)) { - input_error++; - sprintf(error_string, "Species for Pitzer parameter not defined in SOLUTION_SPECIES, %s", pitz_params[i]->species[j]); - error_msg(error_string, CONTINUE); - return(ERROR); - } - } - } - /* - * McGinnis data - */ - string1 = string_hsave("K+"); - string2 = string_hsave("Cl-"); - IC = ISPEC(string2); - for (i = 0; i < count_pitz_param; i++) { - if (pitz_params[i]->species[0] == string1 && - pitz_params[i]->species[1] == string2) { - switch (pitz_params[i]->type) { - case TYPE_B0: - mcb0 = pitz_params[i]; - break; - case TYPE_B1: - mcb1 = pitz_params[i]; - break; - case TYPE_C0: - mcc0 = pitz_params[i]; - break; - case TYPE_B2: - case TYPE_THETA: - case TYPE_LAMDA: - case TYPE_ZETA: - case TYPE_PSI: - case TYPE_ETHETA: - case TYPE_Other: - break; - } - } - } - /* - * Set alpha values - */ - for (i = 0; i < count_pitz_param; i++) { - z0 = fabs(spec[pitz_params[i]->ispec[0]]->z); - z1 = fabs(spec[pitz_params[i]->ispec[1]]->z); - if (equal(z0, 1.0, 1e-8) || equal(z1, 1.0, 1e-8)) { - order = 1; - } else if (equal(z0,2.0, 1e-8) && equal(z1, 2.0, 1e-8)) { - order = 2; - } else { - order = 3; - } - if (pitz_params[i]->type == TYPE_B1) { - switch (order) { - case 1: - case 3: - pitz_params[i]->alpha = 2.0; - break; - case 2: - pitz_params[i]->alpha = 1.4; - break; - } - } else if (pitz_params[i]->type == TYPE_B2) { - switch (order) { - case 1: - pitz_params[i]->alpha = 12.0; - break; - case 2: - pitz_params[i]->alpha = 12.0; - break; - case 3: - pitz_params[i]->alpha = 50.0; - break; - } - } - } - /* - * Add thetas pointer to etheta pitzer parameters - */ - - if (count_theta_param > 0 ) { - for (i = 0; i < count_theta_param; i++) { - theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); - } - } - count_theta_param = 0; - for (i = 0; i < count_pitz_param; i++) { - if (pitz_params[i]->type == TYPE_ETHETA) { - z0 = spec[pitz_params[i]->ispec[0]]->z; - z1 = spec[pitz_params[i]->ispec[1]]->z; - theta_param_ptr = theta_param_search(z0, z1); - if (theta_param_ptr == NULL) { - if (count_theta_param >= max_theta_param) { - space ((void **) ((void *) &theta_params), count_theta_param, &max_theta_param, sizeof(struct theta_param *)); - } - theta_params[count_theta_param] = theta_param_alloc(); - theta_param_init(theta_params[count_theta_param]); - theta_params[count_theta_param]->zj = z0; - theta_params[count_theta_param]->zk = z1; - theta_param_ptr = theta_params[count_theta_param]; - count_theta_param++; - } - pitz_params[i]->thetas = theta_param_ptr; - } - } - return OK; -} -/* ---------------------------------------------------------------------- */ -int ISPEC(char * name) -/* ---------------------------------------------------------------------- */ -/* - * Find species number in spec for character string species name - */ -{ - int i; - for (i = 0; i < 3*count_s; i++) { - if (spec[i] == NULL) continue; - if (name == spec[i]->name) { - return(i); - } - } - return (-1); -} -/* ---------------------------------------------------------------------- */ -int read_pitzer (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads advection information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ -/* - * Read advection parameters: - * number of cells; - * number of shifts; - */ - int n, j; - struct pitz_param *pzp_ptr; - pitz_param_type pzp_type; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "b0", /* 0 */ - "b1", /* 1 */ - "b2", /* 2 */ - "c0", /* 3 */ - "theta", /* 4 */ - "lamda", /* 5 */ - "zeta", /* 6 */ - "psi", /* 7 */ - "macinnes", /* 8 */ - "macinnis", /* 9 */ - "mac" /* 10 */ - }; - int count_opt_list = 11; -/* - * Read lines - */ - opt_save = OPTION_ERROR; - return_value = UNKNOWN; - n = -1; - pzp_type = TYPE_Other; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - pzp_ptr = pitz_param_read(line, n); - if (pzp_ptr != NULL) { - pzp_ptr->type = pzp_type; - j = pitz_param_search(pzp_ptr); - if (j < 0) { - if (count_pitz_param >= max_pitz_param) { - space ((void **) ((void *) &pitz_params), count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); - } - - pitz_params[count_pitz_param] = pzp_ptr; - count_pitz_param++; - } else { - pitz_params[j] = (struct pitz_param *) free_check_null(pitz_params[j]); - pitz_params[j] = pzp_ptr; - } - } - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in PITZER keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* b0 */ - pzp_type = TYPE_B0; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 1: /* b1 */ - pzp_type = TYPE_B1; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 2: /* b2 */ - pzp_type = TYPE_B2; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 3: /* c0 */ - pzp_type = TYPE_C0; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 4: /* theta */ - pzp_type = TYPE_THETA; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 5: /* lambda */ - pzp_type = TYPE_LAMDA; - n = 2; - opt_save = OPTION_DEFAULT; - break; - case 6: /* zeta */ - pzp_type = TYPE_ZETA; - n = 3; - opt_save = OPTION_DEFAULT; - break; - case 7: /* psi */ - pzp_type = TYPE_PSI; - n = 3; - opt_save = OPTION_DEFAULT; - break; - case 8: /* macinnes */ - case 9: /* macinnis */ - case 10: /* mac */ - opt_save = OPTION_ERROR; - ICON = get_true_false(next_char, TRUE); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - if (count_pitz_param > 0) pitzer_model = TRUE; - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int PTEMP (double TK) -/* ---------------------------------------------------------------------- */ -{ -/* -C -C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER -C -*/ - double DC0; - int i; - double TR=298.15; - - if (fabs(TK-OTEMP) < 0.01e0) return OK; - OTEMP=TK; -/* -C Set DW0 -*/ - DW(TK); - for (i = 0; i < count_pitz_param; i++) { - calc_pitz_param(pitz_params[i], TK, TR); - } - DC0=DC(TK); - if (fabs(TK-TR) < 0.01e0) { - A0=0.392e0; - } else { - DC0=DC(TK); - A0=1.400684e6*sqrt(DW0/(pow((DC0*TK),3.0e0))); - /*A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0*/ - } - return OK; -} - -/* ---------------------------------------------------------------------- */ -int calc_pitz_param (struct pitz_param *pz_ptr, double TK, double TR) -/* ---------------------------------------------------------------------- */ -{ - double param; - /* - */ - - if (fabs(TK-TR) < 0.01) { - param = pz_ptr->a[0]; - } else { - param = (pz_ptr->a[0] + - pz_ptr->a[1]*(1.e0/TK-1.e0/TR) + - pz_ptr->a[2]*log(TK/TR) + - pz_ptr->a[3]*(TK - TR) + - pz_ptr->a[4]*(TK*TK - TR*TR)); - } - pz_ptr->p = param; - switch (pz_ptr->type) { - case TYPE_B0: - pz_ptr->U.b0 = param; - break; - case TYPE_B1: - pz_ptr->U.b1 = param; - break; - case TYPE_B2: - pz_ptr->U.b2 = param; - break; - case TYPE_C0: - pz_ptr->U.c0 = param; - break; - case TYPE_THETA: - pz_ptr->U.theta = param; - break; - case TYPE_LAMDA: - pz_ptr->U.lamda = param; - break; - case TYPE_ZETA: - pz_ptr->U.zeta = param; - break; - case TYPE_ETHETA: - break; - case TYPE_PSI: - pz_ptr->U.psi = param; - break; - case TYPE_Other: - error_msg("Should not be TYPE_Other in function calc_pitz_param", STOP); - break; - } - return OK; -} -/* ---------------------------------------------------------------------- */ -int pitzer (void) -/* ---------------------------------------------------------------------- */ -{ - int i, i0, i1, i2; - double param, alpha, z0, z1, z2; - double etheta, ethetap; - double dummy; - /* - double CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, - CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, - BMXPHI, PHIPHI, AW, A, B; - */ - double CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, - CSUM, PHIMAC, OSMOT, B; - double I, TK; - int LNEUT; - /* - C - C INITIALIZE - C - */ - CONV = 1.0/log(10.0); - XI=0.0e0; - XX=0.0e0; - OSUM=0.0e0; - LNEUT=FALSE; - /*n - I = *I_X; - TK = *TK_X; - */ - I = mu_x; - TK = tk_x; - /* DH_AB(TK, &A, &B); */ - /* - C - C TRANSFER DATA FROM TO M - C - */ - for (i = 0; i < 3*count_s; i++) { - IPRSNT[i] = FALSE; - M[i] = 0.0; - if (spec[i] != NULL && spec[i]->in == TRUE) { - if (spec[i]->type == EX || - spec[i]->type == SURF || - spec[i]->type == SURF_PSI) continue; - M[i] = under(spec[i]->lm); - if (M[i] > MIN_TOTAL) IPRSNT[i] = TRUE; - } - } - if (ICON == TRUE) { - IPRSNT[IC] = TRUE; - } -#ifdef SKIP - for (i = count_s; i < count_s + count_neutrals; i++) { - if (M[i] > MIN_TOTAL) LNEUT = TRUE; - } -#endif - /* - ICON = 0; - M[1] = 1.40070736; - M[4] = 2.52131086E-05; - M[140] = 4.59985435E-09; - */ - -/* -C -C COMPUTE PITZER COEFFICIENTS' TEMPERATURE DEPENDENCE -C -*/ - PTEMP(TK); - for (i = 0; i < 2*count_s + count_anions; i++) { - LGAMMA[i] = 0.0; - if (IPRSNT[i] == TRUE) { - XX=XX+M[i]*fabs(spec[i]->z); - XI=XI+M[i]*spec[i]->z*spec[i]->z; - OSUM=OSUM+M[i]; - } - } - I=XI/2.0e0; -/* -C -C EQUATION (8) -C -*/ - BIGZ=XX; - DI=sqrt(I); -/* -C -C CALCULATE F & GAMCLM -C -*/ - B = 1.2; - F=-A0*(DI/(1.0e0+B*DI)+2.0e0*log(1.0e0+B*DI)/B); - XXX=2.0e0*DI; - XXX=(1.0e0-(1.0e0+XXX-XXX*XXX*0.5e0)*exp(-XXX))/(XXX*XXX); - /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I;*/ - /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I;*/ - GAMCLM=F+I*2.0e0*(mcb0->p + mcb1->p*XXX) + 1.5e0*mcc0->p*I*I; - CSUM=0.0e0; - OSMOT=-(A0)*pow(I,1.5e0)/(1.0e0+B*DI); -/* - * Calculate ethetas - */ - for (i = 0; i < count_theta_param; i++) { - z0 = theta_params[i]->zj; - z1 = theta_params[i]->zk; - ETHETAS(z0, z1, I, ðeta, ðetap); - theta_params[i]->etheta = etheta; - theta_params[i]->ethetap = ethetap; - } -/* - * Sums for F, LGAMMA, and OSMOT - */ - dummy = LGAMMA[1]; - for (i = 0; i < count_pitz_param; i++) { - i0 = pitz_params[i]->ispec[0]; - i1 = pitz_params[i]->ispec[1]; - if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) continue; - z0 = spec[i0]->z; - z1 = spec[i1]->z; - param = pitz_params[i]->p; - alpha = pitz_params[i]->alpha; - switch (pitz_params[i]->type) { - case TYPE_B0: - LGAMMA[i0] += M[i1]*2.0*param; - LGAMMA[i1] += M[i0]*2.0*param; - OSMOT += M[i0]*M[i1]*param; - break; - case TYPE_B1: - F += M[i0]*M[i1]*param*GP(alpha*DI)/I; - LGAMMA[i0] += M[i1]*2.0*param*G(alpha*DI); - LGAMMA[i1] += M[i0]*2.0*param*G(alpha*DI); - OSMOT += M[i0]*M[i1]*param*exp(-alpha*DI); - break; - case TYPE_B2: - F += M[i0]*M[i1]*param*GP(alpha*DI)/I; - LGAMMA[i0] += M[i1]*2.0*param*G(alpha*DI); - LGAMMA[i1] += M[i0]*2.0*param*G(alpha*DI); - OSMOT += M[i0]*M[i1]*param*exp(-alpha*DI); - break; - case TYPE_C0: - CSUM += M[i0]*M[i1]*pitz_params[i]->p/(2.0e0*sqrt(fabs(z0*z1))); - LGAMMA[i0] += M[i1]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); - LGAMMA[i1] += M[i0]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); - OSMOT += M[i0]*M[i1]*BIGZ*param/(2.0*sqrt(fabs(z0*z1))); - break; - case TYPE_THETA: - LGAMMA[i0] += 2.0*M[i1]*(param /*+ ETHETA(z0, z1, I) */ ); - LGAMMA[i1] += 2.0*M[i0]*(param /*+ ETHETA(z0, z1, I) */ ); - OSMOT += M[i0]*M[i1]*param; - break; - case TYPE_ETHETA: - /* - ETHETAS(z0, z1, I, ðeta, ðetap); - */ - etheta = pitz_params[i]->thetas->etheta; - ethetap = pitz_params[i]->thetas->ethetap; - F += M[i0]*M[i1]*ethetap; - LGAMMA[i0] += 2.0*M[i1]*etheta; - LGAMMA[i1] += 2.0*M[i0]*etheta; - OSMOT += M[i0]*M[i1]*(etheta + I*ethetap); - /* - F += M[i0]*M[i1]*ETHETAP(z0, z1, I); - LGAMMA[i0] += 2.0*M[i1]*(ETHETA(z0, z1, I) ); - LGAMMA[i1] += 2.0*M[i0]*(ETHETA(z0, z1, I) ); - OSMOT += M[i0]*M[i1]*(ETHETA(z0, z1, I) + I*ETHETAP(z0, z1, I) ); - */ - break; - case TYPE_PSI: - i2 = pitz_params[i]->ispec[2]; - if (IPRSNT[i2] == FALSE) continue; - z2 = spec[i2]->z; - LGAMMA[i0] += M[i1]*M[i2]*param; - LGAMMA[i1] += M[i0]*M[i2]*param; - LGAMMA[i2] += M[i0]*M[i1]*param; - OSMOT += M[i0]*M[i1]*M[i2]*param; - break; - case TYPE_LAMDA: - LGAMMA[i0] += 2.0*M[i1]*param; - LGAMMA[i1] += 2.0*M[i0]*param; - OSMOT += M[i0]*M[i1]*param; - break; - case TYPE_ZETA: - i2 = pitz_params[i]->ispec[2]; - if (IPRSNT[i2] == FALSE) continue; - LGAMMA[i0] += M[i1]*M[i2]*param; - LGAMMA[i1] += M[i0]*M[i2]*param; - LGAMMA[i2] += M[i0]*M[i1]*param; - OSMOT += M[i0]*M[i1]*M[i2]*param; - break; - case TYPE_Other: - error_msg("TYPE_Other in pitz_param list.", STOP); - break; - } - } - - /* - * Add F and CSUM terms to LGAMMA - */ - - for (i = 0; i < count_cations; i++) { - z0 = spec[i]->z; - LGAMMA[i] += z0*z0*F+fabs(z0)*CSUM; - } - for (i = 2*count_s; i < 2*count_s + count_anions; i++) { - z0 = spec[i]->z; - LGAMMA[i] += z0*z0*F+fabs(z0)*CSUM; - } -/* -C -C CONVERT TO MACINNES CONVENTION -C -*/ - if (ICON == TRUE) { - PHIMAC=LGAMMA[IC]-GAMCLM; -/* -C -C CORRECTED ERROR IN PHIMAC, NOVEMBER, 1989 -C -*/ - for (i = 0; i < 2*count_s + count_anions; i++) { - if (IPRSNT[i] == TRUE) { - LGAMMA[i]=LGAMMA[i]+spec[i]->z*PHIMAC; - } - } - } - - COSMOT = 1.0e0 + 2.0e0*OSMOT/OSUM; -/* -C -C CALCULATE THE ACTIVITY OF WATER -C -*/ - AW=exp(-OSUM*COSMOT/55.50837e0); - if (AW > 1.0) AW = 1.0; - /*s_h2o->la=log10(AW);*/ - mu_x = I; - for (i = 0; i < 2*count_s + count_anions; i++) { - if (IPRSNT[i] == FALSE) continue; - /*spec[i]->lg=LGAMMA[i]*CONV;*/ - spec[i]->lg_pitzer=LGAMMA[i]*CONV; - /* - output_msg(OUTPUT_MESSAGE, "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg); - */ - } - /* - output_msg(OUTPUT_MESSAGE, "OSUM: %e\n", OSUM); - output_msg(OUTPUT_MESSAGE, "OSMOT: %e\n", OSMOT); - output_msg(OUTPUT_MESSAGE, "COSMOT: %e\n", COSMOT); - output_msg(OUTPUT_MESSAGE, "F: %e\n", F); - output_msg(OUTPUT_MESSAGE, "AW: %e\n", AW); - */ - /* - *I_X = I; - *COSMOT_X = COSMOT; - */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -double JAY (double X) -/* ---------------------------------------------------------------------- */ -/* -C -C FUNCTION TO CALCULATE JAY AND JPRIME -C -C J0 AND J1, USED IN CALCULATION OF ETHETA AND ETHEAP -C -*/ -{ - double JAY; - BDK (X); - JAY=X/4.0e0-1.0e0+0.5e0*(BK[0]-BK[2]); - return JAY; -} -/* ---------------------------------------------------------------------- */ -double JPRIME (double Y) -/* ---------------------------------------------------------------------- */ -{ - double DZ; - BDK (Y); - if (Y > 1.0e0) { - DZ=-4.0e0*pow(Y,-1.1e0)/9.0e0; - } else { - DZ=0.8e0*pow(Y,-0.8e0); - } - return (Y*(.25e0+DZ*(DK[0]-DK[2])/2.0e0)); -} - - -/* ---------------------------------------------------------------------- */ -int BDK (double X) -/* ---------------------------------------------------------------------- */ -/* -C -C NUMERICAL APPROXIMATION TO THE INTEGRALS IN THE EXPRESSIONS FOR J0 -C AND J1. CHEBYSHEV APPROXIMATION IS USED. THE CONSTANTS 'AK' ARE -C DEFINED IN BLOCK COMMON. -C -*/ -/* -C -C AK IS USED TO CALCULATE HIGHER ORDER ELECTROSTATIC TERMS IN -C SUBROUTINE PITZER -C -*/ -{ - double AKX[42] = { - 1.925154014814667e0, -.060076477753119e0, -.029779077456514e0, - -.007299499690937e0, 0.000388260636404e0, 0.000636874599598e0, - 0.000036583601823e0, -.000045036975204e0, -.000004537895710e0, - 0.000002937706971e0, 0.000000396566462e0, -.000000202099617e0, - -.000000025267769e0, 0.000000013522610e0, 0.000000001229405e0, - -.000000000821969e0, -.000000000050847e0, 0.000000000046333e0, - 0.000000000001943e0, -.000000000002563e0, -.000000000010991e0, - 0.628023320520852e0, 0.462762985338493e0, 0.150044637187895e0, - -.028796057604906e0, -.036552745910311e0, -.001668087945272e0, - 0.006519840398744e0, 0.001130378079086e0, -.000887171310131e0, - -.000242107641309e0, 0.000087294451594e0, 0.000034682122751e0, - -.000004583768938e0, -.000003548684306e0, -.000000250453880e0, - 0.000000216991779e0, 0.000000080779570e0, 0.000000004558555e0, - -.000000006944757e0, -.000000002849257e0, 0.000000000237816e0}; -/* - DOUBLE PRECISION AK, BK, DK - COMMON / MX8 / AK(0:20,2),BK(0:22),DK(0:22) -*/ - double *AK; - double Z; - int II; - int i; - - if (X <= 1.0e0) { - II=1; - Z=4.0e0*pow(X,0.2e0)-2.0e0; - AK = &AKX[0]; - } else { - II=2; - Z=40.0e0*pow(X,-1.0e-1)/9.0e0-22.0e0/9.0e0; - AK = &AKX[21]; - } - for (i = 20; i >= 0; i--) { - BK[i]=Z*BK[i+1]-BK[i+2]+AK[i]; - DK[i]=BK[i+1]+Z*DK[i+1]-DK[i+2]; - } - return OK; -} -/* ---------------------------------------------------------------------- */ -double G (double Y) -/* ---------------------------------------------------------------------- */ -{ - return (2.0e0*(1.0e0-(1.0e0+Y)*exp(-Y))/(Y*Y)); -} -/* ---------------------------------------------------------------------- */ -double GP (double Y) -/* ---------------------------------------------------------------------- */ -{ - return (-2.0e0*(1.0e0-(1.0e0+Y+Y*Y/2.0e0)*exp(-Y))/(Y*Y)); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -double ETHETA (double ZJ, double ZK, double I) -/* ---------------------------------------------------------------------- */ -{ - double XCON, ZZ; - double XJK, XJJ, XKK; - - if (ZJ == ZK) return(0.0); - XCON=6.0e0*A0*sqrt(I); - ZZ=ZJ*ZK; -/* -C -C NEXT 3 ARE EQUATION (A1) -C -*/ - XJK=XCON*ZZ; - XJJ=XCON*ZJ*ZJ; - XKK=XCON*ZK*ZK; -/* -C -C EQUATION (A2) -C -*/ - - return (ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I)); -} -/* ---------------------------------------------------------------------- */ -double ETHETAP (double ZJ, double ZK, double I) -/* ---------------------------------------------------------------------- */ -{ - double XCON, ZZ, ETHETA, ETHETAP; - double XJK, XJJ, XKK; - - if (ZJ == ZK) return(0.0); - XCON=6.0e0*A0*sqrt(I); - ZZ=ZJ*ZK; -/* -C -C NEXT 3 ARE EQUATION (A1) -C -*/ - XJK=XCON*ZZ; - XJJ=XCON*ZJ*ZJ; - XKK=XCON*ZK*ZK; -/* -C -C EQUATION (A3) -C -*/ - ETHETA=ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I); - ETHETAP=ZZ*(JPRIME(XJK)-JPRIME(XJJ)/2.0e0-JPRIME(XKK)/2.0e0)/(8.0e0*I*I) - ETHETA/I; - return (ETHETAP); -} -#endif -/* ---------------------------------------------------------------------- */ -int ETHETAS (double ZJ, double ZK, double I, double *etheta, double *ethetap) -/* ---------------------------------------------------------------------- */ -{ - double XCON, ZZ; - double XJK, XJJ, XKK; - - *etheta = 0.0; - *ethetap = 0.0; - if (ZJ == ZK) return(OK); - XCON=6.0e0*A0*sqrt(I); - ZZ=ZJ*ZK; -/* -C -C NEXT 3 ARE EQUATION (A1) -C -*/ - XJK=XCON*ZZ; - XJJ=XCON*ZJ*ZJ; - XKK=XCON*ZK*ZK; -/* -C -C EQUATION (A3) -C -*/ - *etheta=ZZ*(JAY(XJK)-JAY(XJJ)/2.0e0-JAY(XKK)/2.0e0)/(4.0e0*I); - *ethetap=ZZ*(JPRIME(XJK)-JPRIME(XJJ)/2.0e0-JPRIME(XKK)/2.0e0)/(8.0e0*I*I) - *etheta/I; - return (OK); -} -/* ---------------------------------------------------------------------- */ -int pitzer_clean_up(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free all allocated memory, except strings - */ - int i; - - if (svnid == NULL) fprintf(stderr," "); - for (i = 0; i < count_pitz_param; i++) { - pitz_params[i] = (struct pitz_param *) free_check_null(pitz_params[i]); - } - pitz_params = (struct pitz_param **) free_check_null(pitz_params); - for (i = 0; i < count_theta_param; i++) { - theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]); - } - theta_params = (struct theta_param **) free_check_null(theta_params); - LGAMMA = (double *) free_check_null(LGAMMA); - IPRSNT = (int *) free_check_null(IPRSNT); - spec = (struct species **) free_check_null(spec); - M = (double *) free_check_null(M); - - return OK; -} - -/* ---------------------------------------------------------------------- */ -int set_pz(int initial) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sets initial guesses for unknowns if initial == TRUE - * Revises guesses whether initial is true or not - */ - int i; - struct solution *solution_ptr; -/* - * Set initial log concentrations to zero - */ - iterations = -1; - solution_ptr = use.solution_ptr; - for (i=0; i < count_s_x; i++) { - s_x[i]->lm = LOG_ZERO_MOLALITY; - /*s_x[i]->lg = 0.0;*/ - s_x[i]->lg_pitzer = 0.0; - } -/* - * Set master species activities - */ - - tc_x=solution_ptr->tc; - tk_x=tc_x+273.15; -/* - * H+, e-, H2O - */ - mass_water_aq_x = solution_ptr->mass_water; - mu_x = solution_ptr->mu; - s_h2o->moles = mass_water_aq_x/gfw_water; - s_h2o->la = log10(solution_ptr->ah2o); - AW = pow(10.0, s_h2o->la); - s_hplus->la = - solution_ptr->ph; - s_hplus->lm = s_hplus->la; - s_hplus->moles = exp(s_hplus->lm * LOG_10)*mass_water_aq_x; - s_eminus->la= - solution_ptr->solution_pe; - if (initial == TRUE) initial_guesses(); - if (diffuse_layer_x == TRUE) initial_surface_water(); - revise_guesses(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int initial_guesses(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make initial guesses for activities of master species and - * ionic strength - */ - int i; - struct solution *solution_ptr; - - solution_ptr = use.solution_ptr; - mu_x = s_hplus->moles + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; - mu_x /= mass_water_aq_x; - s_h2o->la=0.0; - for ( i=0; i < count_unknowns; i++ ) { - if (x[i] == ph_unknown || x[i] == pe_unknown ) continue; - if (x[i]->type < CB) { - mu_x += x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * - x[i]->master[0]->s->z; - x[i]->master[0]->s->la = log10(x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == CB) { - x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - x[i]->master[0]->s->la = log10(0.001 * x[i]->moles/mass_water_aq_x); - } else if (x[i]->type == EXCH) { - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - x[i]->master[0]->s->la = log10(x[i]->moles); - } - } else if (x[i]->type == SURFACE) { - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); - } - } else if (x[i]->type == SURFACE_CB) { - x[i]->master[0]->s->la = 0.0; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int revise_guesses(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Revise molalities species - */ - int i; - int iter, max_iter, repeat, fail; - LDBLE weight, f; - - max_iter = 10; - /* gammas(mu_x);*/ - iter = 0; - repeat = TRUE; - fail = FALSE;; - while ( repeat == TRUE ) { - iter++; - if (debug_set == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nBeginning set iteration %d.\n", iter); - } - if (iter == max_iter + 1) { - output_msg(OUTPUT_LOG, "Did not converge in set, iteration %d.\n", iterations); - fail = TRUE; - } - if (iter > 2*max_iter) { - output_msg(OUTPUT_LOG, "Did not converge with relaxed criteria in set.\n"); - return(OK); - } - molalities(TRUE); - /*pitzer();*/ - /*s_h2o->la = 0.0;*/ - /*molalities(TRUE);*/ - mb_sums(); - if (state < REACTION) { - sum_species(); - } else { - for (i = 0; i < count_unknowns; i++) { - x[i]->sum = x[i]->f; - } - } - /*n - if (debug_set == TRUE) { - pr.species = TRUE; - pr.all = TRUE; - print_species(); - } - */ - repeat=FALSE; - for ( i=0; i < count_unknowns; i++ ) { - if (x[i] == ph_unknown || x[i] == pe_unknown) continue; - if (x[i]->type == MB || -/* x[i]->type == ALK || */ - x[i]->type == CB || - x[i]->type == SOLUTION_PHASE_BOUNDARY || - x[i]->type == EXCH || - x[i]->type == SURFACE ) { - - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\t%5s at beginning of set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - if (fabs(x[i]->moles) < 1e-30) x[i]->moles = 0; - f = fabs(x[i]->sum); - if (f == 0 && x[i]->moles == 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - continue; - } else if (f == 0) { - repeat = TRUE; - x[i]->master[0]->s->la += 5; -/*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { - continue; - } else if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; - if (x[i]->moles <= 0) { - x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; - } else { - repeat = TRUE; - x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); - } - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t%5s not converged in set %d: %e\t%e\t%e\n", x[i]->description, iter, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - } - } else if (x[i]->type == ALK) { - f = total_co2; - if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { - continue; - } - if (f > 1.5 * fabs(x[i]->moles) || f < 1e-5 * fabs(x[i]->moles) ) { - repeat = TRUE; - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; - x[i]->master[0]->s->la += weight * - log10(fabs(x[i]->moles / x[i]->sum)); - if ( debug_set == TRUE ) { - output_msg(OUTPUT_MESSAGE,"%s not converged in set. %e\t%e\t%e\n", x[i]->description, (double) x[i]->sum, (double) x[i]->moles, (double) x[i]->master[0]->s->la); - } - } - } - } - } - output_msg(OUTPUT_LOG,"Iterations in revise_guesses: %d\n", iter); - /*mu_x = mu_unknown->f * 0.5 / mass_water_aq_x;*/ - if (mu_x <= 1e-8) { - mu_x = 1e-8; - } - /*gammas(mu_x);*/ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int jacobian_pz(void) -/* ---------------------------------------------------------------------- */ -{ - double *base; - double d, d1, d2; - int i, j; - - if (full_pitzer == TRUE) { - molalities(TRUE); - pitzer(); - residuals(); - } - base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); - if (base == NULL) malloc_error(); - for (i = 0; i < count_unknowns; i++) { - base[i] = residual[i]; - } - d = 0.0001; - d1 = d*log(10.0); - d2 = 0; - for (i = 0; i < count_unknowns; i++) { - switch (x[i]->type) { - case MB: - case ALK: - case CB: - case SOLUTION_PHASE_BOUNDARY: - case EXCH: - case SURFACE: - case SURFACE_CB: - x[i]->master[0]->s->la += d; - d2 = d1; - break; - case AH2O: - x[i]->master[0]->s->la += d; - d2 = d1; - break; - case PITZER_GAMMA: - x[i]->s->lg += d; - d2 = d; - break; - case MH2O: - mass_water_aq_x *= (1.0 + d); - x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; - d2 = log(1.0 + d); - break; - case MU: - case MH: - case PP: - case S_S_MOLES: - continue; - break; - } - molalities(TRUE); - if (full_pitzer == TRUE) pitzer(); - mb_sums(); - residuals(); - for (j = 0; j < count_unknowns; j++) { - array[j*(count_unknowns + 1) + i] = -(residual[j] - base[j])/d2; - } - switch (x[i]->type) { - case MB: - case ALK: - case CB: - case SOLUTION_PHASE_BOUNDARY: - case EXCH: - case SURFACE: - case SURFACE_CB: - case AH2O: - x[i]->master[0]->s->la -= d; - break; - case PITZER_GAMMA: - x[i]->s->lg -= d; - break; - case MH2O: - mass_water_aq_x /= (1 + d); - x[i]->master[0]->s->moles = mass_water_aq_x/gfw_water; - break; - } - } - molalities(TRUE); - if (full_pitzer == TRUE) pitzer(); - mb_sums(); - residuals(); - free_check_null(base); - return OK; -} -/* ---------------------------------------------------------------------- */ -int model_pz(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * model is called after the equations have been set up by prep - * and initial guesses have been made in set. - * - * Here is the outline of the calculation sequence: - * residuals--residuals are calculated, if small we are done - * sum_jacobian--jacobian is calculated - * ineq--inequality solver is called - * reset--estimates of unknowns revised, if changes are small solution - * has been found, usually convergence is found in residuals. - * gammas--new activity coefficients - * molalities--calculate molalities - * mb_sums--calculate mass-balance sums - * mb_gases--decide if gas_phase exists - * mb_s_s--decide if solid_solutions exists - * switch_bases--check to see if new basis species is needed - * reprep--rewrite equations with new basis species if needed - * revise_guesses--revise unknowns to get initial mole balance - * check_residuals--check convergence one last time - * sum_species--calculate sums of elements from species concentrations - * - * An additional pass through may be needed if unstable phases still exist - * in the phase assemblage. - */ - int kode, return_kode; - int r; - int count_infeasible, count_basis_change; - int debug_model_save; - int mass_water_switch_save; - if (svnid == NULL) fprintf(stderr," "); - -/* debug_model = TRUE; */ -/* debug_prep = TRUE; */ -/* debug_set = TRUE; */ - /* mass_water_switch == TRUE, mass of water is constant */ - mass_water_switch_save = mass_water_switch; - if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) { - mass_water_switch = TRUE; - } - debug_model_save = debug_model; - pe_step_size_now = pe_step_size; - step_size_now = step_size; - status(0, NULL); - iterations=0; - gamma_iterations = 0; - count_basis_change = count_infeasible = 0; - stop_program = FALSE; - remove_unstable_phases = FALSE; - if (always_full_pitzer == TRUE) { - full_pitzer = TRUE; - } else { - full_pitzer = FALSE; - } - for (; ; ) { - mb_gases(); - mb_s_s(); - kode = 1; - while ( ( r = residuals() ) != CONVERGED || remove_unstable_phases == TRUE) { -#if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill*/, 0) == WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } -#endif - iterations++; - if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { - set_forward_output_to_log(TRUE); - debug_model = TRUE; - } - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nIteration %d\tStep_size = %f\n", - iterations, (double) step_size_now); - output_msg(OUTPUT_MESSAGE,"\t\tPe_step_size = %f\n\n", (double) pe_step_size_now); - } - /* - * Iterations exceeded - */ - if (iterations > itmax ) { - sprintf(error_string,"Maximum iterations exceeded, %d\n",itmax); - warning_msg(error_string); - stop_program = TRUE; - break; - } - /* - * Calculate jacobian - */ - gammas_pz(); - jacobian_sums(); - jacobian_pz(); - /* - * Full matrix with pure phases - */ - if ( r == OK || remove_unstable_phases == TRUE) { - return_kode = ineq(kode); - if ( return_kode != OK ) { - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE, "Ineq had infeasible solution, " - "kode %d, iteration %d\n", - return_kode, iterations); - } - output_msg(OUTPUT_LOG, "Ineq had infeasible solution, " - "kode %d, iteration %d\n", return_kode, iterations); - count_infeasible++; - } - if ( return_kode == 2 ) { - ineq(0); - } - reset(); - } - gammas_pz(); - if (full_pitzer == TRUE) pitzer(); - if (always_full_pitzer == TRUE) { - full_pitzer = TRUE; - } else { - full_pitzer = FALSE; - } - molalities(TRUE); - if(use.surface_ptr != NULL && - use.surface_ptr->diffuse_layer == TRUE && - use.surface_ptr->related_phases == TRUE) - initial_surface_water(); - mb_sums(); - mb_gases(); - mb_s_s(); - /* debug - species_list_sort(); - sum_species(); - print_species(); - print_exchange(); - print_surface(); - */ - if (stop_program == TRUE) { - break; - } - } -/* - * Check for stop_program - */ - - if (stop_program == TRUE) { - break; - } - if (check_residuals() == ERROR) { - stop_program = TRUE; - break; - } - if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE && - mass_water_switch == TRUE) { - output_msg(OUTPUT_LOG,"\nChanging water switch to FALSE. Iteration %d.\n", iterations); - mass_water_switch = FALSE; - continue; - } - gamma_iterations++; - if (gamma_iterations > itmax ) { - sprintf(error_string,"Maximum gamma iterations exceeded, %d\n", itmax); - warning_msg(error_string); - stop_program = TRUE; - break; - } - if (check_gammas_pz() != TRUE) { - full_pitzer = TRUE; - continue; - } - if (remove_unstable_phases == FALSE) break; - if (debug_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nRemoving unstable phases. Iteration %d.\n", iterations); - } - output_msg(OUTPUT_LOG,"\nRemoving unstable phases. Iteration %d.\n", iterations); - } - output_msg(OUTPUT_LOG,"\nNumber of infeasible solutions: %d\n",count_infeasible); - output_msg(OUTPUT_LOG,"Number of basis changes: %d\n\n",count_basis_change); - output_msg(OUTPUT_LOG,"Number of iterations: %d\n\n", iterations); - debug_model = debug_model_save; - set_forward_output_to_log(FALSE); - if (stop_program == TRUE) { - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int check_gammas_pz(void) -/* ---------------------------------------------------------------------- */ -{ - double old_aw, old_mu, tol; - int converge, i; - - old_mu = mu_x; - old_aw = s_h2o->la; - pitzer(); - molalities(TRUE); - mb_sums(); - converge = TRUE; - tol = convergence_tolerance*10.; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != PITZER_GAMMA) continue; - if (fabs(x[i]->s->lg - x[i]->s->lg_pitzer) > tol) { - converge = FALSE; - } - } - if (fabs(old_mu - mu_x) > tol) converge = FALSE; - if ((pow(10.0,s_h2o->la) - AW) > tol) converge = FALSE; - return converge; -} -/* ---------------------------------------------------------------------- */ -int gammas_pz () -/* ---------------------------------------------------------------------- */ -{ -/* - * Need exchange gammas for pitzer - */ - int i, j; - double coef; - /* Initialize */ -/* - * Calculate activity coefficients - */ - for (i=0; i < count_s_x; i++) { - switch (s_x[i]->gflag) { - case 0: /* uncharged */ - case 1: /* Davies */ - case 2: /* Extended D-H, WATEQ D-H */ - case 3: /* Always 1.0 */ - break; - case 4: /* Exchange */ - /* Now calculated in next loop */ - break; - case 5: /* Always 1.0 */ - break; - case 6: /* Surface */ -/* - * Find moles of sites. - * s_x[i]->equiv is stoichiometric coefficient of sites in species - */ - for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { - if (s_x[i]->rxn_x->token[j].s->type == SURF) { - s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; - break; - } - } - if (s_x[i]->alk > 0) { - s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); - s_x[i]->dg = 0.0; - } else { - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - } - break; - case 7: /* LLNL */ - break; - case 8: /* LLNL CO2*/ - break; - case 9: /* activity water */ - s_x[i]->lg = log10(exp( s_h2o->la * LOG_10) * gfw_water); - s_x[i]->dg = 0.0; - break; - } -/* - if (mu_unknown != NULL) { - if (fabs(residual[mu_unknown->number]) > 0.1 && - fabs(residual[mu_unknown->number])/mu_x > 0.5) { - s_x[i]->dg = 0.0; - } - } - */ - } - /* - * calculate exchange gammas - */ - - if (use.exchange_ptr != NULL) { - for (i=0; i < count_s_x; i++) { - switch (s_x[i]->gflag) { - case 0: /* uncharged */ - case 1: /* Davies */ - case 2: /* Extended D-H, WATEQ D-H */ - case 3: /* Always 1.0 */ - case 5: /* Always 1.0 */ - case 6: /* Surface */ - case 7: /* LLNL */ - case 8: /* LLNL CO2*/ - case 9: /* activity water */ - break; - case 4: /* Exchange */ - - /* - * Find CEC - * z contains valence of cation for exchange species, alk contains cec - */ - /* !!!!! */ - for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { - if (s_x[i]->rxn_x->token[j].s->type == EX) { - s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles; - break; - } - } - /* - * Master species is a dummy variable with meaningless activity and mass - */ - s_x[i]->lg = 0.0; - s_x[i]->dg = 0.0; - if (s_x[i]->primary != NULL) { - break; - } - /* - * All other species - */ - - /* modific 29 july 2005... */ - if (s_x[i]->equiv != 0 && s_x[i]->alk > 0) { - s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); - } - if (use.exchange_ptr->pitzer_exchange_gammas == TRUE) { - /* Assume equal gamma's of solute and exchangeable species... */ - for (j=1; s_x[i]->rxn_x->token[j].s != NULL; j++) { - if (s_x[i]->rxn_x->token[j].s->type == EX) continue; - coef = s_x[i]->rxn_x->token[j].coef; - s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg; - s_x[i]->dg += coef * s_x[i]->rxn_x->token[j].s->dg; - } - } - } - } - } -/* ...end modific 29 july 2005 */ - - return(OK); -} diff --git a/pitzer.h b/pitzer.h deleted file mode 100644 index 46c50843..00000000 --- a/pitzer.h +++ /dev/null @@ -1,50 +0,0 @@ -typedef enum { TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, TYPE_PSI, TYPE_ETHETA, TYPE_Other } pitz_param_type; - - -PITZER_EXTERNAL double VP, DW0; - -struct pitz_param { - char * species[3]; - int ispec[3]; - pitz_param_type type; - double p; - union {double b0; - double b1; - double b2; - double c0; - double theta; - double lamda; - double zeta; - double psi;} U; - double a[5]; - double alpha; - struct theta_param *thetas; -}; - -PITZER_EXTERNAL struct pitz_param **pitz_params; -PITZER_EXTERNAL int count_pitz_param, max_pitz_param; - - - -/* routines define in pitzer_structures.c */ -PITZER_EXTERNAL struct pitz_param *pitz_param_read (char *string, int n); -PITZER_EXTERNAL int pitz_param_search(struct pitz_param *pzp_ptr); -PITZER_EXTERNAL struct theta_param *theta_param_search(double zj, double zk); -PITZER_EXTERNAL struct theta_param *theta_param_alloc (void); -PITZER_EXTERNAL int theta_param_init (struct theta_param *theta_param_ptr); - - - -/* defined in DW */ -PITZER_EXTERNAL int DW (double T); -PITZER_EXTERNAL double DC (double T); - -struct theta_param { - double zj; - double zk; - double etheta; - double ethetap; -}; -PITZER_EXTERNAL struct theta_param **theta_params; -PITZER_EXTERNAL int count_theta_param, max_theta_param; -PITZER_EXTERNAL double OTEMP; diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp deleted file mode 100644 index e42d13d1..00000000 --- a/pitzer_structures.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -#define PITZER_EXTERNAL extern -#include "pitzer.h" - -static char const svnid[] = "$Id: structures.c 269 2005-04-27 19:54:25Z dlpark $"; - - -static struct pitz_param *pitz_param_alloc (void); -static int pitz_param_init (struct pitz_param *pitz_param_ptr); -static struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); -static int pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr); - - -/* ********************************************************************** - * - * Routines related to structure "pitz_param" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct pitz_param *pitz_param_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct pitz_param *pitz_param_ptr; - pitz_param_ptr = (struct pitz_param *) PHRQ_malloc(sizeof (struct pitz_param)); - if (pitz_param_ptr == NULL) malloc_error(); - return ( pitz_param_ptr ); -} -/* ---------------------------------------------------------------------- */ -int pitz_param_init (struct pitz_param *pitz_param_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Frees all data associated with pitz_param structure. - */ - - if (pitz_param_ptr == NULL) return(ERROR); - pitz_param_ptr->species[0] = NULL; - pitz_param_ptr->species[1] = NULL; - pitz_param_ptr->species[2] = NULL; - pitz_param_ptr->ispec[0] = -1; - pitz_param_ptr->ispec[1] = -1; - pitz_param_ptr->ispec[2] = -1; - pitz_param_ptr->type = TYPE_Other; - pitz_param_ptr->p = 0.0; - pitz_param_ptr->U.b0 = 0.0; - for (i = 0; i < 5; i++) { - pitz_param_ptr->a[i] = 0.0; - } - pitz_param_ptr->alpha = 0.0; - pitz_param_ptr->thetas = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct pitz_param *pitz_param_read (char *string, int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read pitzer parameter info from string - * n is number of species (character values) - * - */ - int l, i, j, k; - char *ptr; - char token[2*MAX_LENGTH]; - struct pitz_param pzp, *pzp_ptr; - - if (n != 2 && n != 3) return (NULL); - if (string == NULL) return (NULL); - - pitz_param_init(&pzp); - ptr = string; - if (copy_token(token, &ptr, &l) == EMPTY) return(NULL); - ptr = string; - for (i = 0; i < n; i++) { - if (copy_token(token, &ptr, &l) == EMPTY) return(NULL); - pzp.species[i] = string_hsave(token); - } - k = 0; - for (i = 0; i < 5; i++) { - if (copy_token(token, &ptr, &l) == EMPTY) break; - j=sscanf(token,"%le", &pzp.a[i]); - if (j <= 0) break; - k++; - } - if (k <= 0) return(NULL); - pzp_ptr = pitz_param_duplicate(&pzp); - return ( pzp_ptr); -} -/* ---------------------------------------------------------------------- */ -struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocates space and makes duplicate copy of pitz_param structure - */ - struct pitz_param *new_ptr; - - new_ptr = pitz_param_alloc(); - pitz_param_init(new_ptr); -/* - * Copy data - */ - pitz_param_copy(old_ptr, new_ptr); - return(new_ptr); -} -/* ---------------------------------------------------------------------- */ -int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies pitz_param data from old_ptr to new location, new_ptr. - * Space for the new_ptr structure must already be malloced. - */ -/* - * Store data for structure pitz_param - */ - memcpy(new_ptr, old_ptr, sizeof(struct pitz_param)); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pitz_param_search(struct pitz_param *pzp_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Does linear search of pitz_params for same type and species - * Returns -1 if not found, index number in pitz_params if found - */ - int i; - if (pzp_ptr == NULL) return -1; - if (pzp_ptr->type == TYPE_Other) return -1; - for (i = 0; i < count_pitz_param; i++) { - if (pitz_params[i]->type == pzp_ptr->type && - pitz_params[i]->species[0] == pzp_ptr->species[0] && - pitz_params[i]->species[1] == pzp_ptr->species[1] && - pitz_params[i]->species[2] == pzp_ptr->species[2] ) { - break; - } - } - if (i >= count_pitz_param) { - return -1; - } - return i; -} -/* ********************************************************************** - * - * Routines related to structure "theta_parm" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct theta_param *theta_param_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct theta_param *theta_param_ptr; - theta_param_ptr = (struct theta_param *) PHRQ_malloc(sizeof (struct theta_param)); - if (theta_param_ptr == NULL) malloc_error(); - return ( theta_param_ptr ); -} -/* ---------------------------------------------------------------------- */ -int theta_param_init (struct theta_param *theta_param_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all data associated with theta_param structure. - */ - - if (theta_param_ptr == NULL) return(ERROR); - theta_param_ptr->zj = 0; - theta_param_ptr->zk = 0; - theta_param_ptr->etheta = 0; - theta_param_ptr->ethetap = 0; - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct theta_param *theta_param_search(double zj, double zk) -/* ---------------------------------------------------------------------- */ -{ -/* - * Does linear search of theta_params for same charge - * Returns NULL if not found, index number in theta_params if found - */ - int i; - for (i = 0; i < count_theta_param; i++) { - if ((theta_params[i]->zj == zj && theta_params[i]->zk == zk) || - (theta_params[i]->zj == zk && theta_params[i]->zk == zj)) { - return theta_params[i]; - } - } - return NULL; -} diff --git a/prep.cpp b/prep.cpp deleted file mode 100644 index 880aa76d..00000000 --- a/prep.cpp +++ /dev/null @@ -1,4055 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: prep.c 655 2005-11-14 23:06:29Z dlpark $"; - -static int add_potential_factor(void); -static int add_surface_charge_balance(void); -static int build_gas_phase(void); -static int build_jacobian_sums (int k); -static int build_mb_sums(void); -static int build_min_exch(void); -static int build_model(void); -static int build_pure_phases(void); -static int build_s_s_assemblage(void); -static int build_solution_phase_boundaries(void); -static int build_species_list(int n); -static int build_min_surface(void); -static int change_hydrogen_in_elt_list(LDBLE charge); -static int clear (void); -static int convert_units(struct solution *solution_ptr); -static struct unknown *find_surface_charge_unknown(char *str_ptr); -static struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr); -static int inout(void); -static int is_special(struct species *spec); -static int mb_for_species_aq(int n); -static int mb_for_species_ex(int n); -static int mb_for_species_surf(int n); -static int quick_setup (void); -static int resetup_master (void); -static int save_model(void); -static int setup_exchange (void); -static int setup_gas_phase(void); -static int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); -static int setup_pure_phases(void); -static int setup_related_surface (void); -static int setup_s_s_assemblage(void); -static int setup_solution (void); -static int setup_surface (void); -static int setup_unknowns (void); -static int store_dn (int k, LDBLE *source, int row, LDBLE coef_in, LDBLE *gamma_source); -static int store_jacob(LDBLE *source, LDBLE *target, LDBLE coef); -static int store_jacob0(int row, int column, LDBLE coef); -int store_mb(LDBLE *source, LDBLE *target, LDBLE coef); -static int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE *LDBLE_ptr, LDBLE coef, LDBLE *gamma_ptr); -static int store_sum_deltas(LDBLE *source, LDBLE *target, LDBLE coef); -static int tidy_redox (void); -static struct master **unknown_alloc_master(void); -static int write_mb_eqn_x (void); -static int write_mb_for_species_list (int n); -static int write_mass_action_eqn_x (int stop); - -/* ---------------------------------------------------------------------- */ -int prep(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Input is model defined by the structure use. - * Most of routine is skipped if model, as defined by master.total - * plus use.pure_phases, is same as previous calculation. - * Routine sets up struct unknown for each unknown. - * Determines elements, species, and phases that are in the model. - * Calculates mass-action equations for each species and phase. - * Routine builds a set of lists for calculating mass balance and - * for building jacobian. - */ - struct solution *solution_ptr; - if (svnid == NULL) fprintf(stderr," "); - - if (state >= REACTION) { - same_model = check_same_model(); - } else { - same_model = FALSE; - last_model.force_prep = TRUE; - } - /*same_model = FALSE;*/ -/* - * Initialize s, master, and unknown pointers - */ - solution_ptr = use.solution_ptr; - if (solution_ptr == NULL) { - error_msg("Solution needed for calculation not found, stopping.", STOP); - } - description_x = (char *) free_check_null(description_x); - description_x = string_duplicate(solution_ptr->description); -/* - * Allocate space for unknowns - * Must allocate all necessary space before pointers to - * X are set. - */ - - if (same_model == FALSE) { - clear(); - setup_unknowns(); -/* - * Set unknown pointers, unknown types, validity checks - */ - if (state == INITIAL_SOLUTION) convert_units(solution_ptr); - setup_solution(); - setup_exchange(); - setup_surface(); - setup_pure_phases(); - setup_gas_phase(); - setup_s_s_assemblage(); - setup_related_surface(); - tidy_redox(); - if (input_error > 0) { - error_msg("Program terminating due to input errors.", STOP); - } -/* - * Allocate space for array - */ -/* - array = (LDBLE *) PHRQ_malloc( (size_t) (count_unknowns+1) * count_unknowns * sizeof( LDBLE )); - if (array == NULL) malloc_error(); - delta = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); - if (delta == NULL) malloc_error(); - residual = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); - if (residual == NULL) malloc_error(); -*/ - array = (LDBLE *) PHRQ_malloc( (size_t) (max_unknowns+1) * max_unknowns * sizeof( LDBLE )); - if (array == NULL) malloc_error(); - delta = (LDBLE *) PHRQ_malloc( (size_t) max_unknowns * sizeof( LDBLE )); - if (delta == NULL) malloc_error(); - residual = (LDBLE *) PHRQ_malloc( (size_t) max_unknowns * sizeof( LDBLE )); - if (residual == NULL) malloc_error(); -/* - * Build lists to fill Jacobian array and species list - */ - build_model(); - } else { -/* - * If model is same, just update masses, don't rebuild unknowns and lists - */ - quick_setup(); - } - if (input_error > 0) { - error_msg("Program stopping due to input errors.", STOP); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int quick_setup (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Routine is used if model is the same as previous model - * Assumes moles of elements, exchangers, surfaces, gases, and solid solutions have - * been accumulated in array master, usually by subroutine step. - * Updates essential information for the model. - */ - int i, j, k, l; - - for (i = 0; i < count_master; i++) { - if (master[i]->s->type == SURF_PSI) continue; - if (master[i]->s == s_eminus || - master[i]->s == s_hplus || - master[i]->s == s_h2o || - master[i]->s == s_h2 || - master[i]->s == s_o2) continue; - if(master[i]->total > 0) { - if (master[i]->s->secondary != NULL) { - master[i]->s->secondary->unknown->moles = master[i]->total; - } else { - master[i]->unknown->moles = master[i]->total; - } - } - } -/* - * Reaction: pH for charge balance - */ - ph_unknown->moles = use.solution_ptr->cb; -/* - * Reaction: pe for total hydrogen - */ - if (mass_hydrogen_unknown != NULL) { -#define COMBINE - /*#define COMBINE_CHARGE*/ -#ifdef COMBINE -#ifndef COMBINE_CHARGE - mass_hydrogen_unknown->moles = use.solution_ptr->total_h - 2 * use.solution_ptr->total_o; -#else - mass_hydrogen_unknown->moles = use.solution_ptr->total_h - 2 * use.solution_ptr->total_o - use.solution_ptr->cb; -#endif -#else - mass_hydrogen_unknown->moles = use.solution_ptr->total_h; -#endif - } -/* - * Reaction H2O for total oxygen - */ - if (mass_oxygen_unknown != NULL) { - mass_oxygen_unknown->moles = use.solution_ptr->total_o; - } - -/* - * pp_assemblage - */ - j = 0; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == PP) { - x[i]->moles = use.pp_assemblage_ptr->pure_phases[j].moles; - x[i]->dissolve_only = use.pp_assemblage_ptr->pure_phases[j].dissolve_only; - use.pp_assemblage_ptr->pure_phases[j].delta = 0.0; - x[i]->pure_phase = &(use.pp_assemblage_ptr->pure_phases[j]); - j++; - } - } -/* - * gas phase - */ - if (gas_unknown != NULL) { - gas_unknown->moles = 0.0; - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - gas_unknown->moles += use.gas_phase_ptr->comps[i].moles; - } - if (gas_unknown->moles <= 0) gas_unknown->moles = MIN_TOTAL; - gas_unknown->ln_moles = log(gas_unknown->moles); - gas_unknown->gas_phase = use.gas_phase_ptr; - } -/* - * s_s_assemblage - */ - if (s_s_unknown != NULL) { - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == S_S_MOLES) break; - } - for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (k = 0; k < use.s_s_assemblage_ptr->s_s[j].count_comps; k++) { - x[i]->s_s = &(use.s_s_assemblage_ptr->s_s[j]); - x[i]->s_s_comp = &(use.s_s_assemblage_ptr->s_s[j].comps[k]); - x[i]->s_s_comp_number = j; - x[i]->moles = x[i]->s_s_comp->moles; - if (x[i]->moles <= 0) { - x[i]->moles = MIN_TOTAL; - x[i]->s_s_comp->moles = MIN_TOTAL; - } - x[i]->s_s_comp->initial_moles = x[i]->moles; - x[i]->ln_moles = log(x[i]->moles); - - x[i]->phase->dn = x[i]->s_s_comp->dn; - x[i]->phase->dnb = x[i]->s_s_comp->dnb; - x[i]->phase->dnc = x[i]->s_s_comp->dnc; - x[i]->phase->log10_fraction_x = x[i]->s_s_comp->log10_fraction_x; - x[i]->phase->log10_lambda = x[i]->s_s_comp->log10_lambda; - i++; - } - } - } -/* - * exchange - */ - if (use.exchange_ptr != NULL) { - k = 0; - for (i = 0 ; i < count_unknowns; i++) { - if (x[i]->type == EXCH) { - x[i]->exch_comp = &(use.exchange_ptr->comps[k++]); - if (x[i]->exch_comp->rate_name != NULL) { - for (l = 0; x[i]->exch_comp->totals[l].elt != NULL; l++) { - if (x[i]->exch_comp->totals[l].elt->master->type != EX) continue; - if (strcmp_nocase(x[i]->description, x[i]->exch_comp->totals[l].elt->name) == 0) { - x[i]->moles = x[i]->exch_comp->totals[l].coef; -/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ - break; - } - } - } - -#ifdef SKIP - if (count_kin_exch > 0) { - for (l = 0; x[i]->exch_comp->totals[l].elt != NULL; l++) { - if (x[i]->exch_comp->totals[l].elt->master->type != EX) continue; - if (strcmp_nocase(x[i]->description, x[i]->exch_comp->totals[l].elt->name) == 0) { - x[i]->moles = x[i]->exch_comp->totals[l].coef; -/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ - } - } - } -#endif - } - } - } -/* - * surface - */ - if (use.surface_ptr != NULL) { - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE) { - break; - } - } - j = 0; - k = 0; - for ( ; i < count_unknowns; i++) { - if (x[i]->type == SURFACE_CB) { - x[i]->surface_charge = &(use.surface_ptr->charge[j]); - x[i]->related_moles = x[i]->surface_charge->grams; - x[i]->mass_water = use.surface_ptr->charge[j++].mass_water; - x[i]->surface_comp = x[i-1]->surface_comp; - /* moles picked up from master->total */ - } else if (x[i]->type == SURFACE) { - x[i]->surface_comp = &(use.surface_ptr->comps[k++]); - /* moles picked up from master->total - except for surfaces related to kinetic minerals ... */ - if (x[i]->surface_comp->rate_name != NULL) { - for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; l++) { - if (x[i]->surface_comp->totals[l].elt->master->type != SURF) continue; - if (strcmp_nocase(x[i]->description, x[i]->surface_comp->totals[l].elt->name) == 0) { - x[i]->moles = x[i]->surface_comp->totals[l].coef; - /* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ - } - } - } -/* !!!! */ -#ifdef SKIP - if (count_kin_surf > 0) { - for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; l++) { - if (x[i]->surface_comp->totals[l].elt->master->type != SURF) continue; - - if (strcmp_nocase(x[i]->description, x[i]->surface_comp->totals[l].elt->name) == 0) { - x[i]->moles = x[i]->surface_comp->totals[l].coef; -/* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ - } - } - } -#endif - } else { - break; - } - - } - } - save_model(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Put coefficients into lists to sum iaps to test for equilibrium - * Put coefficients into lists to build jacobian for - * sum of partial pressures equation and - * mass balance equations for elements contained in gases - */ - int i, j; - int row, col; - struct master *master_ptr; - struct rxn_token *rxn_ptr; - struct gas_comp *gas_comp_ptr; - struct phase *phase_ptr; - struct unknown *unknown_ptr; - LDBLE coef, coef_elt; - - if (gas_unknown == NULL) return(OK); - for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { -/* - * Determine elements in gas component - */ - count_elts = 0; - paren_count = 0; - gas_comp_ptr = &(use.gas_phase_ptr->comps[i]); - phase_ptr = gas_comp_ptr->phase; - if (phase_ptr->rxn_x == NULL) continue; - add_elt_list(phase_ptr->next_elt, 1.0); -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif -/* - * Build mass balance sums for each element in gas - */ - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\tMass balance summations %s.\n\n", - gas_comp_ptr->phase->name); - } - - /* All elements in gas */ - for (j = 0; j < count_elts; j++) { - unknown_ptr = NULL; - if (strcmp(elt_list[j].elt->name,"H") == 0) { - unknown_ptr = mass_hydrogen_unknown; - } else if (strcmp(elt_list[j].elt->name,"O") == 0) { - unknown_ptr = mass_oxygen_unknown; - } else { - if (elt_list[j].elt->primary->in == TRUE) { - unknown_ptr = elt_list[j].elt->primary->unknown; - } else if (elt_list[j].elt->primary->s->secondary != NULL) { - unknown_ptr = elt_list[j].elt->primary->s->secondary->unknown; - } - } - if (unknown_ptr != NULL) { - coef = elt_list[j].coef; - store_mb(&(gas_comp_ptr->phase->moles_x), &(unknown_ptr->f), coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\n", - unknown_ptr->description, - (double) coef); - } - } - } - if (use.gas_phase_ptr->type == PRESSURE) { - /* Total pressure of gases */ - store_mb(&(gas_comp_ptr->phase->p_soln_x), &(gas_unknown->f), 1.0); - } -/* - * Build jacobian sums for mass balance equations - */ - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\tJacobian summations %s.\n\n", - phase_ptr->name); - } - for (j = 0; j < count_elts; j++) { - unknown_ptr = NULL; - if (strcmp(elt_list[j].elt->name,"H") == 0) { - unknown_ptr = mass_hydrogen_unknown; - } else if (strcmp(elt_list[j].elt->name,"O") == 0) { - unknown_ptr = mass_oxygen_unknown; - } else { - if (elt_list[j].elt->primary->in == TRUE) { - unknown_ptr = elt_list[j].elt->primary->unknown; - } else if (elt_list[j].elt->primary->s->secondary != NULL) { - unknown_ptr = elt_list[j].elt->primary->s->secondary->unknown; - } - } - if (unknown_ptr == NULL) { -#ifdef SKIP - error_msg("NULL pointer in subroutine build_gas_phase.", STOP); -#endif - continue; - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\t%s.\n", - unknown_ptr->description); - } - row = unknown_ptr->number * (count_unknowns + 1); - coef_elt = elt_list[j].coef; - for (rxn_ptr = phase_ptr->rxn_x->token+1; - rxn_ptr->s != NULL; rxn_ptr++) { - - if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if (master_ptr == NULL) { - sprintf(error_string, "Element needed for gas component, %s, is not in model.", phase_ptr->name); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); - } - if (master_ptr->unknown == NULL) { -#ifdef SKIP - input_error++; -#endif - continue; - } - if (master_ptr->in == FALSE ) { - sprintf(error_string, "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); - error_msg(error_string, CONTINUE); - input_error++; - } - col = master_ptr->unknown->number; - coef = coef_elt * rxn_ptr->coef; - store_jacob (&(gas_comp_ptr->phase->moles_x), &(array[row + col]), coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, row/(count_unknowns+1), col); - } - } - if (use.gas_phase_ptr->type == PRESSURE) { - /* derivative wrt total moles of gas */ - store_jacob (&(gas_comp_ptr->phase->fraction_x), &(array[row + gas_unknown->number]), coef_elt); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n","gas moles", (double) elt_list[j].coef, row/(count_unknowns+1), gas_unknown->number); - } - } - } -/* - * Build jacobian sums for sum of partial pressures equation - */ - if (use.gas_phase_ptr->type != PRESSURE) continue; - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\tPartial pressure eqn %s.\n\n", - phase_ptr->name); - } - unknown_ptr = gas_unknown; - row = unknown_ptr->number * (count_unknowns + 1); - for (rxn_ptr = phase_ptr->rxn_x->token+1; - rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); - } - if (master_ptr->unknown == NULL) { -#ifdef SKIP - input_error++; -#endif - continue; - } - if (master_ptr->in == FALSE ) { - sprintf(error_string, "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); - error_msg(error_string, CONTINUE); - input_error++; - } - col = master_ptr->unknown->number; - coef = rxn_ptr->coef; - store_jacob (&(gas_comp_ptr->phase->p_soln_x), &(array[row + col]), coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, - row/(count_unknowns+1), col); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_s_s_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Put coefficients into lists to sum iaps to test for equilibrium - * Put coefficients into lists to build jacobian for - * mass action equation for component - * mass balance equations for elements contained in solid solutions - */ - int i, j, k, l, stop; - int row, col; - struct master *master_ptr; - struct rxn_token *rxn_ptr; - struct s_s *s_s_ptr, *s_s_ptr_old; - char token[MAX_LENGTH]; - char *ptr; - - if (s_s_unknown == NULL) return(OK); - s_s_ptr_old = NULL; - col = 0; - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) continue; - s_s_ptr = x[i]->s_s; - if (s_s_ptr != s_s_ptr_old) { - col = x[i]->number; - s_s_ptr_old = s_s_ptr; - } -/* - * Calculate function value (inverse saturation index) - */ - if (x[i]->phase->rxn_x == NULL) continue; - store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); - } - /* include mole fraction */ - store_mb(&(x[i]->phase->log10_fraction_x), &(x[i]->f), 1.0); - - /* include activity coeficient */ - store_mb(&(x[i]->phase->log10_lambda), &(x[i]->f), 1.0); -/* - * Put coefficients into mass action equations - */ - /* first IAP terms */ - for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s->secondary != NULL && - rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if (master_ptr == NULL || master_ptr->unknown == NULL) continue; - store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); - } - - if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) { -/* - * For binary solid solution - */ - /* next dnc terms */ - row = x[i]->number * (count_unknowns + 1); - if (x[i]->s_s_comp_number == 0) { - col = x[i]->number; - } else { - col = x[i]->number -1; - } - store_jacob (&(x[i]->phase->dnc), &(array[row + col]), -1); - - /* next dnb terms */ - col++; - store_jacob (&(x[i]->phase->dnb), &(array[row + col]), -1); - } else { -/* - * For ideal solid solution - */ - row = x[i]->number * (count_unknowns + 1); - for (j = 0; j < s_s_ptr->count_comps; j++) { - if (j != x[i]->s_s_comp_number) { -/* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ - store_jacob (&(x[i]->phase->dn), &(array[row + col + j]), -1.0); - } else { - store_jacob (&(x[i]->phase->dnb), &(array[row + col + j]), -1.0); - } - } - } -/* - * Put coefficients into mass balance equations - */ - count_elts = 0; - paren_count = 0; - strcpy(token, x[i]->phase->formula); - ptr = token; - get_elts_in_species (&ptr, 1.0); -/* - * Go through elements in phase - */ -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif - for (j = 0; j < count_elts; j++) { - - if (strcmp(elt_list[j].elt->name, "H") == 0 && mass_hydrogen_unknown != NULL) { - store_jacob0(mass_hydrogen_unknown->number, x[i]->number, -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, elt_list[j].coef); - - } else if (strcmp(elt_list[j].elt->name, "O") == 0 && mass_oxygen_unknown != NULL) { - store_jacob0(mass_oxygen_unknown->number, x[i]->number, -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, elt_list[j].coef); - - } else { - master_ptr = elt_list[j].elt->primary; - if (master_ptr->in == FALSE) { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL || master_ptr->in == FALSE) { - if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { - sprintf(error_string, "Element in phase, %s, is not in model.", x[i]->phase->name); - warning_msg(error_string); - } - if (master_ptr != NULL) { - master_ptr->s->la = -999.9; - } -/* - * Master species is in model - */ - } else if (master_ptr->in == TRUE ) { - store_jacob0(master_ptr->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &master_ptr->unknown->delta, elt_list[j].coef); -/* - * Master species in equation needs to be rewritten - */ - } else if (master_ptr->in == REWRITE ) { - stop = FALSE; - for (k=0; k < count_unknowns; k++) { - if (x[k]->type != MB) continue; - for (l = 0; x[k]->master[l] != NULL; l++) { - if (x[k]->master[l] == master_ptr) { - store_jacob0(x[k]->master[0]->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &x[k]->master[0]->unknown->delta, - elt_list[j].coef); - stop = TRUE; - break; - } - } - if (stop == TRUE) break; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_jacobian_sums (int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function builds lists sum_jacob1 and sum_jacob2 that describe how to sum molalities - * to form jacobian. - */ - int i, j, kk; - int count_g; - LDBLE coef; - LDBLE *source, *target; - - if (debug_prep == TRUE) output_msg(OUTPUT_MESSAGE,"\n\tJacobian summations.\n"); -/* - * Calculate jacobian coefficients for each mass balance equation - */ - for (i = 0; i < count_mb_unknowns; i++) { -#ifdef SKIP - /* switch for mu term */ - if (diffuse_layer_x == TRUE && ((mb_unknowns[i].unknown == charge_balance_unknown) || - (mb_unknowns[i].unknown == ah2o_unknown) || - (mb_unknowns[i].unknown == mu_unknown))) { - use_tot_g = 1; - } else if (diffuse_layer_x == TRUE && mb_unknowns[i].unknown->type == SURFACE_CB) { - use_tot_g = 2; - } else { - use_tot_g = 0; - } -#endif -/* - * Store d(moles) for a mass balance equation - */ - /* initial solution only */ - if (mb_unknowns[i].unknown->type == SOLUTION_PHASE_BOUNDARY) { - continue; - } - coef = mb_unknowns[i].coef; - if (debug_prep == TRUE) output_msg(OUTPUT_MESSAGE,"\n\tMass balance eq: %s\t%f\n", - mb_unknowns[i].unknown->description, (double) coef); - store_dn(k, mb_unknowns[i].source, mb_unknowns[i].unknown->number, coef, mb_unknowns[i].gamma_source); -/* - * Add extra terms for change in dg/dx in diffuse layer model - */ - if (s[k]->type >= H2O || diffuse_layer_x == FALSE) { - continue; - } else if ( (mb_unknowns[i].unknown->type == MB || - mb_unknowns[i].unknown->type == MH || - mb_unknowns[i].unknown->type == MH2O) && state >= REACTION) { - if (mass_oxygen_unknown != NULL) { - /* term for water, sum of all surfaces */ - source = &s[k]->tot_dh2o_moles; - target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", "sum[dn(i,s)/dlnwater]", (double) coef, - mb_unknowns[i].unknown->number, mass_oxygen_unknown->number); - } - } - - /* terms for psi, one for each surface */ - count_g = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - source = &s[k]->diff_layer[count_g].dx_moles; - target = &(array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + - x[j]->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - "dg/dlny", (double) coef, - mb_unknowns[i].unknown->number, - x[j]->number); - } - count_g++; - if (count_g >= use.surface_ptr->count_charge) break; - } - - /* terms for related phases */ - count_g = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - - /* has related phase */ - if (x[j-1]->surface_comp->phase_name == NULL) continue; - - /* now find the related phase */ - for (kk = count_unknowns - 1; kk >= 0; kk--) { - if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == x[j-1]->surface_comp->phase_name) break; - } - - if (kk >= 0) { - source = &s[k]->diff_layer[count_g].drelated_moles; - target = &(array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + - x[kk]->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - "dphase", (double) coef, - mb_unknowns[i].unknown->number, - x[kk]->number); - } - } - count_g++; - if (count_g >= use.surface_ptr->count_charge) break; - } - - } else if (mb_unknowns[i].unknown->type == SURFACE_CB) { - count_g = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - if (mb_unknowns[i].unknown->number == x[j]->number) { - source = &s[k]->diff_layer[count_g].dx_moles; - target = &(array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + - x[j]->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - "dg/dlny", (double) coef, - mb_unknowns[i].unknown->number, - x[j]->number); - } - - /* term for related phase */ - /* has related phase */ - if (x[j-1]->surface_comp->phase_name != NULL) { - - /* now find the related phase */ - for (kk = count_unknowns - 1; kk >= 0; kk--) { - if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == x[j-1]->surface_comp->phase_name) break; - } - if (kk >= 0) { - source = &s[k]->diff_layer[count_g].drelated_moles; - target = &(array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + - x[kk]->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - "dphase", (double) coef, - mb_unknowns[i].unknown->number, - x[kk]->number); - } - } - } - - if (mass_oxygen_unknown != NULL) { - /* term for water, for same surfaces */ - source = &s[k]->diff_layer[count_g].dh2o_moles; - target = &(array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + mass_oxygen_unknown->number]); - store_jacob(source, target, coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - "dn(i,s)/dlnwater", (double) coef, - mb_unknowns[i].unknown->number, - mass_oxygen_unknown->number); - } - } - break; - } - count_g++; - if (count_g >= use.surface_ptr->count_charge) break; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_mb_sums(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function builds lists sum_mb1 and sum_mb2 that describe how to sum molalities - * to calculate mass balance sums, including activity of water, ionic strength, - * charge balance, and alkalinity. - */ - int i; - LDBLE *target; -/* - * Make space for lists - */ - if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) { - space ((void **) ((void *) &sum_mb1), count_sum_mb1 + count_mb_unknowns, - &max_sum_mb1, sizeof(struct list1)); - } - if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) { - space ((void **) ((void *) &sum_mb2), count_sum_mb2 + count_mb_unknowns, - &max_sum_mb2, sizeof(struct list2)); - } - - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\n\tMass balance summations.\n\n"); - } - for (i = 0; i < count_mb_unknowns; i++) { - target = &(mb_unknowns[i].unknown->f); - store_mb(mb_unknowns[i].source, target, mb_unknowns[i].coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\n", - mb_unknowns[i].unknown->description, - (double) mb_unknowns[i].coef); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_model(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Guts of prep. Determines species in model, rewrites equations, - * builds lists for mass balance and jacobian sums. - */ - int i, j, j0, k; - LDBLE coef_e; - - if (s_hplus == NULL || s_eminus == NULL || s_h2o == NULL) { - error_msg("Data base is missing H+, H2O, or e- species.", CONTINUE); - input_error++; - } -/* - * Make space for lists of pointers to species in the model - */ - - max_s_x = MAX_S; - space ((void **) ((void *) &s_x), INIT, &max_s_x, sizeof(struct species *)); - - max_sum_mb1=MAX_SUM_MB; - count_sum_mb1=0; - space ((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, sizeof(struct list1)); - - max_sum_mb2=MAX_SUM_MB; - count_sum_mb2=0; - space ((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, sizeof(struct list2)); - - max_sum_jacob0=MAX_SUM_JACOB0; - count_sum_jacob0=0; - space ((void **) ((void *) &sum_jacob0), INIT, &max_sum_jacob0, - sizeof(struct list0)); - - max_sum_jacob1=MAX_SUM_JACOB1; - count_sum_jacob1=0; - space ((void **) ((void *) &sum_jacob1), INIT, &max_sum_jacob1, - sizeof(struct list1)); - - max_sum_jacob2=MAX_SUM_JACOB2; - count_sum_jacob2=0; - space ((void **) ((void *) &sum_jacob2), INIT, &max_sum_jacob2, - sizeof(struct list2)); - - - max_sum_delta=MAX_SUM_JACOB0; - count_sum_delta=0; - space ((void **) ((void *) &sum_delta), INIT, &max_sum_delta, - sizeof(struct list2)); - - max_species_list = 5 * MAX_S; - count_species_list = 0; - species_list = (struct species_list *) free_check_null(species_list); - space ((void **) ((void *) &species_list), INIT, &max_species_list, - sizeof (struct species_list)); - -/* - * Pick species in the model, determine reaction for model, build jacobian - */ - count_s_x=0; - compute_gfw("H2O", &gfw_water); - gfw_water *= 0.001; - for (i=0; i < count_s; i++) { - if (s[i]->type > H2O && s[i]->type != EX && s[i]->type != SURF) continue; - s[i]->in=FALSE; - count_trxn=0; - trxn_add (s[i]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ -/* - * Check if species is in model - */ - s[i]->in = inout(); - if (s[i]->in == TRUE) { - /* for isotopes, activity of water is for 1H and 16O */ - if (s[i]->gflag == 9 ) { - gfw_water = 18.0/1000.0; - } - if (pitzer_model == FALSE) s[i]->lg = 0.0; - if (count_s_x + 1 >= max_s_x) { - space ((void **) ((void *) &s_x), count_s_x + 1, - &max_s_x, - sizeof (struct species *)); - } - s_x[count_s_x++] = s[i]; -/* - * Write mass action equation for current model - */ - write_mass_action_eqn_x(STOP); - if (s[i]->type == SURF) { - add_potential_factor(); - } - rxn_free(s[i]->rxn_x); - s[i]->rxn_x = rxn_alloc(count_trxn+1); - trxn_copy (s[i]->rxn_x); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\nSpecies: %s\n", s[i]->name); - trxn_print(); - } -/* - * Determine mass balance equations, build sums for mass balance, build sums for jacobian - */ - count_trxn=0; - trxn_add (s[i]->rxn_s, 1.0, FALSE); - if (s[i]->next_secondary == NULL) { - write_mb_eqn_x(); - } else { - count_elts = 0; - add_elt_list(s[i]->next_secondary, 1.0); - } - if (s[i]->type == SURF) { - add_potential_factor(); - add_surface_charge_balance(); - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"%s\n", trxn.token[0].s->name); - for (j = 0; j < count_elts; j++) { - output_msg(OUTPUT_MESSAGE,"\t%s\t%f\n", elt_list[j].elt->name, (double) elt_list[j].coef); - } - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\nSpecies: %s\n", s[i]->name); - trxn_print(); - } - if (s[i]->type < EMINUS) { - mb_for_species_aq(i); - } else if (s[i]->type == EX) { - mb_for_species_ex(i); - } else if (s[i]->type == SURF) { - mb_for_species_surf(i); - } -#ifdef COMBINE - build_mb_sums(); -#else - if (s[i] != s_h2o) { - build_mb_sums(); - } -#endif - if (!pitzer_model) build_jacobian_sums(i); -/* - * Build list of species for summing and printing - */ - if (s[i]->next_secondary == NULL) { - write_mb_for_species_list(i); - } else { - count_elts = 0; - add_elt_list(s[i]->next_secondary, 1.0); - } - build_species_list(i); - } - } - if (diffuse_layer_x == TRUE && pitzer_model == TRUE) { - error_msg("-diffuse_layer option not available for Pizer model", STOP); - } -/* - * Sum diffuse layer water into hydrogen and oxygen mass balances - */ - if (diffuse_layer_x == TRUE && state >= REACTION) { - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE_CB) { -#ifndef COMBINE - store_mb(&(x[i]->mass_water), - &(mass_hydrogen_unknown->f), - 2 / gfw_water); -#endif - if (mass_oxygen_unknown != NULL) { - store_mb(&(x[i]->mass_water), - &(mass_oxygen_unknown->f), - 1 / gfw_water); - } - } - } - } -/* - * For Pizer model add lg unknown for each aqueous species - */ - - if (pitzer_model == TRUE) { - j0 = count_unknowns; - j = count_unknowns + count_s_x; - k = j0; - for (i = j0; i < j; i++) { - if (s_x[i - j0]->type == EX) continue; - if (s_x[i - j0]->type == SURF) continue; - x[k]->number = k; - x[k]->type = PITZER_GAMMA; - x[k]->s = s_x[i - j0]; - x[k]->description = s_x[i - j0]->name; - k++; - count_unknowns++; - } - } -/* - * Rewrite phases to current master species - */ - for (i=0; i < count_phases; i++) { - count_trxn=0; - trxn_add(phases[i]->rxn_s, 1.0, FALSE); - trxn_reverse_k(); - phases[i]->in = inout(); - if (phases[i]->in == TRUE) { -/* - * Replace e- in original equation with default redox reaction - */ - coef_e=trxn_find_coef ("e-", 1); - if ( equal(coef_e,0.0,TOL) == FALSE ) { - trxn_add( pe_x[default_pe_x].rxn, coef_e, TRUE); - } -/* - * Rewrite reaction to current master species - */ - write_mass_action_eqn_x(STOP); - trxn_reverse_k(); - rxn_free(phases[i]->rxn_x); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\nPhase: %s\n", phases[i]->name); - trxn_print(); - } - phases[i]->rxn_x = rxn_alloc(count_trxn+1); - trxn_copy (phases[i]->rxn_x); - write_phase_sys_total(i); - } - } - build_solution_phase_boundaries(); - build_pure_phases(); - build_min_exch(); - build_min_surface(); - build_gas_phase(); - build_s_s_assemblage(); -/* - * Sort species list, by master only - */ - qsort (&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), species_list_compare_master); -/* - * Print size information to logfile - */ -/* - output_msg(OUTPUT_LOG, "\nMemory used:\n"); - output_msg(OUTPUT_LOG, "count_s: %d\tmax_s: %d\t\tbytes: %d\n", count_s, max_s, (int) (max_s * sizeof(struct species))); - output_msg(OUTPUT_LOG, "count_s_x: %d\tmax_s_x: %d\t\tbytes: %d\n", count_s_x, max_s_x, (int) (max_s_x * sizeof(struct species *))); - output_msg(OUTPUT_LOG, "count_sum_mb1: %d\tmax_sum_mb1: %d\t\tbytes: %d\n", count_sum_mb1, max_sum_mb1, (int) (max_sum_mb1 * sizeof(struct list1))); - output_msg(OUTPUT_LOG, "count_sum_mb2: %d\tmax_sum_mb2: %d\t\tbytes: %d\n", count_sum_mb2, max_sum_mb2, (int) (max_sum_mb2 * sizeof(struct list2))); - output_msg(OUTPUT_LOG, "count_sum_jacob0: %d\tmax_sum_jacob0: %d\t\tbytes: %d\n", count_sum_jacob0, max_sum_jacob0, (int) (max_sum_jacob0 * sizeof(struct list0))); - output_msg(OUTPUT_LOG, "count_sum_jacob1: %d\tmax_sum_jacob1: %d\t\tbytes: %d\n", count_sum_jacob1, max_sum_jacob1, (int) (max_sum_jacob1 * sizeof(struct list1))); - output_msg(OUTPUT_LOG_LOG, "count_sum_jacob2: %d\tmax_sum_jacob2: %d\t\tbytes: %d\n", count_sum_jacob2, max_sum_jacob2, (int) (max_sum_jacob2 * sizeof(struct list2))); - output_msg(OUTPUT_LOG_LOG, "count_sum_delta: %d\tmax_sum_delta: %d\t\tbytes: %d\n", count_sum_delta, max_sum_delta, (int) (max_sum_delta * sizeof(struct list2))); - output_msg(OUTPUT_LOG, "count_unknowns: %d\n", count_unknowns); - output_msg(OUTPUT_LOG_LOG, "\n"); - */ -/* - * Save model description - */ - /* if (state >= REACTION) save_model(); */ - save_model(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Includes calculation of inverse saturation index in sum_mb. - * Puts coefficients in iap and mass balance equations for each phase. - */ - int i; - int stop, j, k, l; - char token[MAX_LENGTH]; - char *ptr; - struct master *master_ptr; - struct rxn_token *rxn_ptr; -/* - * Build into sums the logic to calculate inverse saturation indices for - * pure phases - */ - if (pure_phase_unknown == NULL) return(OK); -/* - * Calculate inverse saturation index - */ - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) continue; - if (pure_phase_unknown == NULL) pure_phase_unknown = x[i]; - - store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); - store_mb(&(x[i]->si), &(x[i]->f), 1.0); - - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); - } - } - for (i = 0; i < count_unknowns; i++) { -/* - * rxn_x is null if an element in phase is not in solution - */ - if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) continue; -/* - * Put coefficients into IAP equations - */ - for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s->secondary != NULL && - rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if (master_ptr == NULL || master_ptr->unknown == NULL) continue; - store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); - } -/* - * Put coefficients into mass balance equations - */ - count_elts = 0; - paren_count = 0; - if (x[i]->pure_phase->add_formula != NULL) { - strcpy(token, x[i]->pure_phase->add_formula); - ptr = token; - get_elts_in_species (&ptr, 1.0); - } else { - strcpy(token, x[i]->phase->formula); - ptr = token; - get_elts_in_species (&ptr, 1.0); - } -/* - * Go through elements in phase - */ - -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif - for (j = 0; j < count_elts; j++) { - - if (strcmp(elt_list[j].elt->name, "H") == 0 && mass_hydrogen_unknown != NULL) { - store_jacob0(mass_hydrogen_unknown->number, x[i]->number, -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, elt_list[j].coef); - - } else if (strcmp(elt_list[j].elt->name, "O") == 0 && mass_oxygen_unknown != NULL) { - store_jacob0(mass_oxygen_unknown->number, x[i]->number, -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, elt_list[j].coef); - - } else { - master_ptr = elt_list[j].elt->primary; - if (master_ptr->in == FALSE) { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL || master_ptr->in == FALSE) { - if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { - sprintf(error_string, "Element in phase, %s, is not in model.", x[i]->phase->name); - warning_msg(error_string); - } - if (master_ptr != NULL) { - master_ptr->s->la = -999.9; - } -/* - * Master species is in model - */ - } else if (master_ptr->in == TRUE ) { - store_jacob0(master_ptr->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &master_ptr->unknown->delta, elt_list[j].coef); -/* - * Master species in equation needs to be rewritten - */ - } else if (master_ptr->in == REWRITE ) { - stop = FALSE; - for (k=0; k < count_unknowns; k++) { - if (x[k]->type != MB) continue; - for (l = 0; x[k]->master[l] != NULL; l++) { - if (x[k]->master[l] == master_ptr) { - store_jacob0(x[k]->master[0]->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &x[k]->master[0]->unknown->delta, - elt_list[j].coef); - stop = TRUE; - break; - } - } - if (stop == TRUE) break; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_solution_phase_boundaries(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct master *master_ptr; - struct rxn_token *rxn_ptr; -/* - * Build into sums the logic to calculate inverse saturation indices for - * solution phase boundaries - */ - if (solution_phase_boundary_unknown == NULL) return(OK); -/* - * Calculate inverse saturation index - */ - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != SOLUTION_PHASE_BOUNDARY) continue; - - store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); - store_mb(&(x[i]->si), &(x[i]->f), 1.0); - if (x[i]->phase->in != TRUE) { - sprintf(error_string, "Solution does not contain all elements for phase-boundary mineral, %s.", x[i]->phase->name); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); - } - } - if (input_error > 0) return(ERROR); -/* - * Put coefficients into array - */ - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != SOLUTION_PHASE_BOUNDARY) continue; - for (rxn_ptr=x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s->secondary != NULL && - rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if (master_ptr->unknown == NULL) continue; - store_jacob0(x[i]->number, master_ptr->unknown->number, rxn_ptr->coef); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_species_list(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Builds a list that includes an entry for each master species in each - * secondary reaction. Used for summing species of each element and - * printing results. - */ - int j; - struct master *master_ptr; -/* - * Check space and store reaction token name and pointer to species - */ - if (count_species_list + count_elts >= max_species_list) { - space ((void **) ((void *) &species_list), count_species_list + count_elts, - &max_species_list, sizeof (struct species_list)); - } -/* - * Treat species made only with H+, e-, and H2O specially - */ - if ( is_special(s[n]) == TRUE ) { - species_list[count_species_list].master_s = s_hplus; - species_list[count_species_list].s = s[n]; - species_list[count_species_list].coef = 0.0; - count_species_list++; - return(OK); - } -/* - * Treat exchange species specially - */ - if (s[n]->type == EX) { - if (s[n]->primary != NULL) return(OK); /* master species has zero molality */ - for (j = 0; j < count_elts; j++) { - if ( elt_list[j].elt->master->s->type != EX ) continue; - master_ptr = elt_list[j].elt->master; - species_list[count_species_list].master_s = elt_list[j].elt->master->s; - species_list[count_species_list].s = s[n]; - species_list[count_species_list].coef = master_ptr->coef * - elt_list[j].coef; - count_species_list++; - } - return(OK); - } -/* - * Treat surface species specially - */ - if (s[n]->type == SURF_PSI) return(OK); - if (s[n]->type == SURF) { - for (j=0; j < count_elts; j++) { - if ( elt_list[j].elt->master->s->type != SURF ) continue; - master_ptr = elt_list[j].elt->master; - species_list[count_species_list].master_s = elt_list[j].elt->master->s; - species_list[count_species_list].s = s[n]; - species_list[count_species_list].coef = master_ptr->coef * - elt_list[j].coef; - count_species_list++; - } - return(OK); - } -/* - * Other aqueous species - */ - for (j=0; j < count_elts; j++) { - if ( is_special(elt_list[j].elt->master->s) == TRUE ) continue; - if (elt_list[j].elt->master->s->secondary != NULL) { - master_ptr = elt_list[j].elt->master->s->secondary; - } else { - master_ptr = elt_list[j].elt->master->s->primary; - } - species_list[count_species_list].master_s = master_ptr->s; - species_list[count_species_list].s = s[n]; -/* - * Find coefficient for element represented by master species - */ - species_list[count_species_list].coef = master_ptr->coef * - elt_list[j].coef; - count_species_list++; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int clear (void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Resets information for setting up a new model - */ - struct solution *solution_ptr; -/* - * Clear species solution-dependent data - */ - solution_ptr = use.solution_ptr; - - for (i=0; i < count_s; i++) { - s[i]->in=FALSE; - } -/* - * Set pe structure - */ - pe_data_free(pe_x); - pe_x = pe_data_dup(solution_ptr->pe); - default_pe_x = solution_ptr->default_pe; -/* - * Clear master species solution-dependent data - */ - for (i=0; i < count_master; i++) { - master[i]->in=FALSE; - master[i]->unknown=NULL; - master[i]->pe_rxn = &(pe_x[solution_ptr->default_pe].rxn); -/* - * copy primary reaction to secondary reaction - */ - rxn_free (master[i]->rxn_secondary); - master[i]->rxn_secondary = rxn_dup (master[i]->rxn_primary); - } - - if (state == INITIAL_SOLUTION) { - s_h2o->secondary->in=TRUE; - s_hplus->secondary->in=TRUE; - } else { - s_h2o->primary->in=TRUE; - s_hplus->primary->in=TRUE; - } - s_eminus->primary->in=TRUE; -/* - * Set all unknown pointers to NULL - */ - mb_unknown = NULL; - ah2o_unknown = NULL; - mass_hydrogen_unknown = NULL; - mass_oxygen_unknown = NULL; - mu_unknown = NULL; - alkalinity_unknown = NULL; - carbon_unknown = NULL; - ph_unknown = NULL; - pe_unknown = NULL; - charge_balance_unknown = NULL; - solution_phase_boundary_unknown = NULL; - pure_phase_unknown = NULL; - exchange_unknown = NULL; - surface_unknown = NULL; - gas_unknown = NULL; - s_s_unknown = NULL; -/* - * Free arrays used in model - */ - free_model_allocs(); - - return (OK); -} -/* ---------------------------------------------------------------------- */ -int convert_units(struct solution *solution_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Converts solution concentrations to moles/kg water - * Uses totals.input conc to calculate totals.moles. - */ - int i, l; - LDBLE sum_solutes; - char c; - struct master *master_ptr; - struct conc *tot_ptr; - char token[MAX_LENGTH]; - char *ptr; -/* - * Convert units - */ - sum_solutes= exp(-solution_ptr->ph * LOG_10); - for ( i=0; solution_ptr->totals[i].description != NULL; i++) { - master_ptr = master_bsearch (solution_ptr->totals[i].description); - if (master_ptr != NULL) { - if (master_ptr->minor_isotope == TRUE) continue; - } - tot_ptr=&(solution_ptr->totals[i]); - tot_ptr->moles = 0.0; - if (strcmp(tot_ptr->description,"H(1)") == 0 || - strcmp(tot_ptr->description,"E" ) == 0 ) { - continue; - } - if (tot_ptr->input_conc <= 0) continue; -/* - * Get gfw - */ - /* use given gfw if gfw > 0.0 */ - /* use formula give with "as" */ - if (tot_ptr->gfw <= 0.0) { - if ( tot_ptr->as != NULL ) { - /* use given chemical formula to calculate gfw */ - if (compute_gfw(tot_ptr->as, &(tot_ptr->gfw) ) == ERROR ) { - sprintf(error_string, "Could not compute gfw, %s.", tot_ptr->as); - error_msg(error_string, CONTINUE); - input_error++; - } - if (strcmp (tot_ptr->description,"Alkalinity") == 0 && - strcmp (tot_ptr->as, "CaCO3") == 0) { - tot_ptr->gfw /= 2.; - sprintf(error_string, "Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.", (double) tot_ptr->gfw); - warning_msg(error_string); - } - /* use gfw of master species */ - } else { - ptr = tot_ptr->description; - copy_token(token, &ptr, &l); - master_ptr = master_bsearch (token); - if (master_ptr != NULL) { - /* use gfw for element redox state*/ - tot_ptr->gfw = master_ptr->gfw; - } else { - sprintf(error_string, "Could not find gfw, %s.", tot_ptr->description); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - } - } -/* - * Convert liters to kg solution - */ - tot_ptr->moles=tot_ptr->input_conc; - if (strstr (solution_ptr->units, "/l") != NULL ) { - tot_ptr->moles *= 1.0/(solution_ptr->density); - } -/* - * Convert milli or micro - */ - c=tot_ptr->units[0]; - if (c == 'm') { - tot_ptr->moles *= 1e-3; - } else if ( c == 'u' ) { - tot_ptr->moles *= 1e-6; - } -/* - * Sum grams of solute, convert from moles necessary - */ - if (strstr (tot_ptr->units, "g/kgs") != NULL || - strstr (tot_ptr->units,"g/l") != NULL ) { - sum_solutes += tot_ptr->moles; - } else if (strstr (tot_ptr->units, "Mol/kgs") != NULL || - strstr (tot_ptr->units, "Mol/l") != NULL || - strstr (tot_ptr->units, "eq/l") != NULL ) { - sum_solutes += (tot_ptr->moles)*(tot_ptr->gfw); - } -/* - * Convert grams to moles, if necessary - */ - if ( strstr (tot_ptr->units, "g/") != NULL && tot_ptr->gfw != 0.0) { - tot_ptr->moles /= tot_ptr->gfw; - } - } -/* - * Convert /kgs to /kgw - */ - if (strstr( solution_ptr->units, "kgs") != NULL || - strstr( solution_ptr->units, "/l") != NULL ) { - mass_water_aq_x = 1.0 - 1e-3*sum_solutes; - for ( i=0; solution_ptr->totals[i].description != NULL; i++) { - solution_ptr->totals[i].moles /= mass_water_aq_x; - } - } -/* - * Scale by mass of water in solution - */ - mass_water_aq_x = solution_ptr->mass_water; - for ( i=0; solution_ptr->totals[i].description != NULL; i++) { - solution_ptr->totals[i].moles *= mass_water_aq_x; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Input: ptr contains a list of one or more master species names - * Output: space is allocated and a list of master species pointers is - * returned. - */ - int j, l, count_list; - char token[MAX_LENGTH]; - struct master **master_ptr_list; - struct master *master_ptr0; -/* - * Make list of master species pointers - */ - count_list = 0; - master_ptr_list = unknown_alloc_master(); - master_ptr0=master_ptr; - if (master_ptr0 == master_ptr->s->primary) { -/* - * First in list is primary species - */ - for (j = 0; j < count_master; j++) { - if (master[j] == master_ptr0) break; - } - j++; -/* - * Element has only one valence - */ - if ( j >= count_master || master[j]->elt->primary != master_ptr0) { - master_ptr_list[count_list++] = master_ptr0; -/* - * Element has multiple valences - */ - } else { - if (master_ptr0->s->secondary == NULL) { - sprintf(error_string, "Master species for valence states of element %s are not correct.\n\tPossibly related to master species for %s.", master_ptr0->elt->name, master[j]->elt->name); - error_msg(error_string, CONTINUE); - input_error++; - } - master_ptr_list[count_list++] = master_ptr0->s->secondary; - while (j < count_master && master[j]->elt->primary == master_ptr0) { - if (master[j]->s->primary == NULL) { - master_ptr_list = (struct master **) PHRQ_realloc((void *) master_ptr_list, (size_t) (count_list + 2) * sizeof(struct master *)); - if (master_ptr_list == NULL) malloc_error(); - master_ptr_list[count_list++] = master[j]; - } - j++; - } - } - } else { -/* - * First in list is secondary species, Include all valences from input - */ - master_ptr_list[count_list++]=master_ptr0; - while (copy_token(token,&ptr, &l) != EMPTY) { - master_ptr = master_bsearch(token); - if (master_ptr != NULL) { - master_ptr_list = (struct master **) PHRQ_realloc((void *) master_ptr_list, (size_t) (count_list + 2) * sizeof(struct master *)); - if (master_ptr_list == NULL) malloc_error(); - master_ptr_list[count_list++] = master_ptr; - } - } - } - master_ptr_list[count_list] = NULL; - return (master_ptr_list); -} -/* ---------------------------------------------------------------------- */ -int inout(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct rxn_token_temp *token_ptr; -/* - * Routine goes through trxn to determine if each master species is - * in this model. - * Assumes equation is written in terms of primary and secondary species - * Checks to see if in is TRUE or REWRITE for each species - * Returns TRUE if in model - * FALSE if not - */ - for (i=1; i < count_trxn; i++) { - token_ptr = &(trxn.token[i]); - /* Check primary master species in */ - if (token_ptr->s->primary != NULL && (token_ptr->s->primary->in == TRUE) ) continue; - /* Check secondary master species */ - if ( (token_ptr->s->secondary != NULL) && (token_ptr->s->secondary->in != FALSE) ) { - continue; - } - /* Must be primary master species that is out */ - return(FALSE); - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int is_special(struct species *spec) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks to see if a species is composed of only H, O, and e- - * Returns TRUE if true - * FALSE if not - */ - int special; - struct rxn_token *token_ptr; - - special = TRUE; - for ( token_ptr = spec->rxn_s->token + 1; token_ptr->s != NULL; token_ptr++) { - if (token_ptr->s != s_hplus && - token_ptr->s != s_h2o && - token_ptr->s != s_eminus ) { - special = FALSE; - break; - } - } - return(special); -} -/* ---------------------------------------------------------------------- */ -int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE *LDBLE_ptr, LDBLE coef, LDBLE *gamma_ptr) -/* ---------------------------------------------------------------------- */ -/* - * Takes an unknown pointer and a coefficient and puts in - * list of mb_unknowns - */ -{ - if (equal(coef, 0.0, TOL) == TRUE) return(OK); - if ( (count_mb_unknowns + 1) >= max_mb_unknowns) { - space ((void **) ((void *) &mb_unknowns), count_mb_unknowns + 1, &max_mb_unknowns, - sizeof(struct unknown_list)); - } - mb_unknowns[count_mb_unknowns].unknown = unknown_ptr; - mb_unknowns[count_mb_unknowns].source = LDBLE_ptr; - mb_unknowns[count_mb_unknowns].gamma_source = gamma_ptr; - mb_unknowns[count_mb_unknowns].coef = coef; - count_mb_unknowns++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_for_species_aq(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make list of mass balance and charge balance equations in which - * to insert species n. - * - * count_mb_unknowns - number of equations and summation relations - * mb_unknowns.unknown - pointer to unknown which contains row number - * mb_unknowns.source - pointer to the LDBLE number to be multiplied - * by coef, usually moles. - * mb_unknowns.coef - coefficient of s[n] in equation or relation - */ - int i, j; - struct master *master_ptr; - - count_mb_unknowns = 0; -/* - * e- does not appear in any mass balances - */ - if (s[n]->type == EMINUS) return(OK); -/* - * Do not include diffuse layer in cb, alk, ah2o, mu - */ - if (charge_balance_unknown != NULL && s[n]->type < H2O) { - store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); - } - if (alkalinity_unknown != NULL && s[n]->type < H2O ) { - store_mb_unknowns(alkalinity_unknown, &s[n]->moles, s[n]->alk, &s[n]->dg); - } - if (ah2o_unknown != NULL && s[n]->type < H2O ) { - store_mb_unknowns(ah2o_unknown, &s[n]->moles, 1.0, &s[n]->dg); - } - if (mu_unknown != NULL && s[n]->type < H2O ) { - store_mb_unknowns(mu_unknown, &s[n]->moles, s[n]->z * s[n]->z, &s[n]->dg); - } -/* - * Include diffuse layer in hydrogen and oxygen mass balance - */ - if (mass_hydrogen_unknown != NULL ) { - if (diffuse_layer_x == TRUE && state >= REACTION) { -#ifdef COMBINE -#ifndef COMBINE_CHARGE - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h - 2 *s[n]->o, &s[n]->dg_total_g); -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h - 2 *s[n]->o - s[n]->z, &s[n]->dg_total_g); -#endif -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, s[n]->h, &s[n]->dg_total_g ); -#endif - } else { -#ifdef COMBINE -#ifndef COMBINE_CHARGE - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2* s[n]->o, &s[n]->dg); -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2* s[n]->o - s[n]->z, &s[n]->dg); -#endif -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg); -#endif - } - } - if (mass_oxygen_unknown != NULL ) { - if (diffuse_layer_x == TRUE && state >= REACTION) { - store_mb_unknowns(mass_oxygen_unknown, &s[n]->tot_g_moles, s[n]->o, &s[n]->dg_total_g ); - } else { - store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); - } - } -/* - * Sum diffuse layer charge into (surface + DL) charge balance - */ - if (use.surface_ptr != NULL && s[n]->type < H2O && diffuse_layer_x == TRUE) { - j = 0; - for(i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE_CB) { - store_mb_unknowns(x[i], &s[n]->diff_layer[j].g_moles, s[n]->z, &s[n]->diff_layer[j].dg_g_moles); - j++; - } - } - } -/* - * Other mass balances - */ - for (i = 0; i < count_elts; i++) { - if (elt_list[i].elt->master->s->type > AQ && - elt_list[i].elt->master->s->type < SOLID) continue; - master_ptr = elt_list[i].elt->master; - if (master_ptr->primary == TRUE) { - if (master_ptr->s->secondary != NULL) { - master_ptr = master_ptr->s->secondary; - } - } - if (master_ptr->unknown == ph_unknown ) { - continue; - } else if (master_ptr->unknown == pe_unknown ) { - continue; - } else if (master_ptr->unknown == charge_balance_unknown ) { - continue; - } else if (master_ptr->unknown == alkalinity_unknown ) { - continue; - } else if (master_ptr->unknown->type == SOLUTION_PHASE_BOUNDARY ) { - continue; - } - if (diffuse_layer_x == TRUE && state >= REACTION) { - store_mb_unknowns(master_ptr->unknown, - &s[n]->tot_g_moles, - elt_list[i].coef * master_ptr->coef, &s[n]->dg_total_g ); - } else { - store_mb_unknowns(master_ptr->unknown, - &s[n]->moles, - elt_list[i].coef * master_ptr->coef, &s[n]->dg); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_for_species_ex(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make list of mass balance and charge balance equations in which - * to insert exchange species n. - * - * count_mb_unknowns - number of equations and summation relations - * mb_unknowns.source - pointer to the LDBLE number to be multiplied - * by coef, usually moles. - * mb_unknowns.unknown - pointer to unknown which contains row number - * mb_unknowns.coef - coefficient of s[n] in equation or relation - */ - int i; - struct master *master_ptr; - count_mb_unknowns = 0; -/* - * Master species for exchange do not appear in any mass balances - */ - if (s[n]->type == EX && s[n]->primary != NULL) return(OK); -/* - * Include diffuse layer in hydrogen and oxygen mass balance - */ - if (charge_balance_unknown != NULL) { - store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); - } - if (mass_hydrogen_unknown != NULL ) { -#ifdef COMBINE -#ifndef COMBINE_CHARGE - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2 * s[n]->o, &s[n]->dg); -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2 * s[n]->o - s[n]->z, &s[n]->dg); -#endif -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg ); -#endif - } - if (mass_oxygen_unknown != NULL ) { - store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); - } -/* - * Other mass balances - */ - for (i = 0; i < count_elts; i++) { - if (elt_list[i].elt->master->s->type > AQ && - elt_list[i].elt->master->s->type < SOLID) continue; - master_ptr = elt_list[i].elt->master; - if (master_ptr->primary == TRUE) { - if (master_ptr->s->secondary != NULL) { - master_ptr = master_ptr->s->secondary; - } - } -/* - * Special for ph_unknown, pe_unknown, and alkalinity_unknown - */ - if (master_ptr->unknown == ph_unknown ) { - continue; - } else if (master_ptr->unknown == pe_unknown ) { - continue; - } else if (master_ptr->unknown == alkalinity_unknown ) { - continue; - } -/* - * EX, sum exchange species only into EXCH mass balance in initial calculation - * into all mass balances in reaction calculation - */ - if ( state >= REACTION || master_ptr->s->type == EX) { - store_mb_unknowns(master_ptr->unknown, &s[n]->moles, - elt_list[i].coef * master_ptr->coef, &s[n]->dg); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mb_for_species_surf(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make list of mass balance and charge balance equations in which - * to insert species n. - * - * count_mb_unknowns - number of equations and summation relations - * mb_unknowns.source - pointer to the LDBLE number to be multiplied - * by coef, usually moles. - * mb_unknowns.unknown - pointer to unknown which contains row number - * mb_unknowns.coef - coefficient of s[n] in equation or relation - */ - int i; - struct master *master_ptr; - - count_mb_unknowns = 0; -/* - * Include in charge balance, if diffuse_layer_x == FALSE - */ - if (charge_balance_unknown != NULL && diffuse_layer_x == FALSE) { - store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); - } -/* - * Include diffuse layer in hydrogen and oxygen mass balance - */ - if (mass_hydrogen_unknown != NULL ) { -#ifdef COMBINE -#ifndef COMBINE_CHARGE - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2*s[n]->o, &s[n]->dg); -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h - 2*s[n]->o -s[n]->z, &s[n]->dg); - -#endif -#else - store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, &s[n]->dg ); -#endif - } - if (mass_oxygen_unknown != NULL ) { - store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, &s[n]->dg ); - } -/* - * Other mass balances - */ -/* - * Other mass balances - */ - for (i = 0; i < count_elts; i++) { -/* Skip H+, e-, and H2O */ - if (elt_list[i].elt->master->s->type > AQ && - elt_list[i].elt->master->s->type < SOLID) continue; - master_ptr = elt_list[i].elt->master; - if (master_ptr->primary == TRUE) { - if (master_ptr->s->secondary != NULL) { - master_ptr = master_ptr->s->secondary; - } - } -/* - * SURF_PSI, sum surface species in (surface + DL) charge balance - */ - if (master_ptr->s->type == SURF_PSI) { - store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->z, &s[n]->dg ); - continue; - } -/* - * Special for ph_unknown, pe_unknown, and alkalinity_unknown - */ - if (master_ptr->unknown == ph_unknown ) { - continue; - } else if (master_ptr->unknown == pe_unknown ) { - continue; - } else if (master_ptr->unknown == alkalinity_unknown ) { - continue; - } -/* - * SURF, sum surface species only into SURFACE mass balance in initial calculation - * into all mass balances in reaction calculation - */ - if ( state >= REACTION || master_ptr->s->type == SURF) { - store_mb_unknowns(master_ptr->unknown, &s[n]->moles, - elt_list[i].coef * master_ptr->coef, &s[n]->dg); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int reprep (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * If a basis species has been switched, makes new model. - * Unknowns are not changed, but mass-action equations are - * rewritten and lists for mass balance and jacobian are regenerated - */ - int i; -/* - * Initialize s, master, and unknown pointers - */ - for (i=0; i < count_master; i++) { - if (master[i]->in == FALSE) continue; - rxn_free (master[i]->rxn_secondary); - master[i]->rxn_secondary = rxn_dup (master[i]->rxn_primary); - } - resetup_master(); -/* - * Set unknown pointers, unknown types, validity checks - */ - tidy_redox(); - if (input_error > 0) { - error_msg("Program terminating due to input errors.", STOP); - } -/* - * Free arrays built in build_model - */ - s_x = (struct species **) free_check_null(s_x); - sum_mb1 = (struct list1 *) free_check_null(sum_mb1); - sum_mb2 = (struct list2 *) free_check_null(sum_mb2); - sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); - sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); - sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); - sum_delta = (struct list2 *) free_check_null(sum_delta); -/* - * Build model again - */ - build_model(); - same_model = FALSE; - k_temp(tc_x); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int resetup_master (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * For basis switch, rewrite equations for master species - * Set master_ptr->rxn_secondary, - * master_ptr->pe_rxn, - * and special cases for alkalinity, carbon, and pH. - */ - int i, j; - struct master *master_ptr, *master_ptr0; - - for (i = 0; i < count_unknowns; i++ ) { - if (x[i]->type != MB) continue; - master_ptr0=x[i]->master[0]; - for (j = 0; (master_ptr = x[i]->master[j]) != NULL; j++) { -/* - * Set flags - */ - if (j == 0) { - if (master_ptr->s->primary == NULL) { - rxn_free(master_ptr->rxn_secondary); - master_ptr->rxn_secondary = rxn_dup(master_ptr->s->rxn_s); - } - } else { - if (master_ptr0->s->primary == NULL) { - rewrite_master_to_secondary(master_ptr, master_ptr0); - rxn_free(master_ptr->rxn_secondary); - master_ptr->rxn_secondary = rxn_alloc(count_trxn+1); - trxn_copy (master_ptr->rxn_secondary); - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int write_mass_action_eqn_x (int stop) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reduce mass-action equation to the master species that are in the model - */ - LDBLE coef_e; - int count, repeat; - int i, count_rxn_orig; -/* - * Rewrite any secondary master species flagged REWRITE - * Replace pe if necessary - */ - count = 0; - repeat = TRUE; - while (repeat == TRUE) { - count++; - if (count > MAX_ADD_EQUATIONS) { - sprintf(error_string, "Could not reduce equation " - "to primary and secondary species that are " - "in the model\n\t Species: %s.", - trxn.token[0].s->name); - if (stop == STOP) { - input_error++; - error_msg(error_string, CONTINUE); - } else { - warning_msg(error_string); - } - return(ERROR); - } - repeat = FALSE; - count_rxn_orig=count_trxn; - for (i=1; i < count_rxn_orig; i++) { - if (trxn.token[i].s->secondary == NULL) continue; - if (trxn.token[i].s->secondary->in == REWRITE ) { - repeat=TRUE; - coef_e=rxn_find_coef (trxn.token[i].s->secondary->rxn_secondary, - "e-"); - trxn_add(trxn.token[i].s->secondary->rxn_secondary, - trxn.token[i].coef, FALSE); - if ( equal(coef_e,0.0,TOL) == FALSE ) { - trxn_add( *(trxn.token[i].s->secondary->pe_rxn), - trxn.token[i].coef*coef_e, FALSE); - } - } - } - trxn_combine(); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_potential_factor(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add the potential factor to surface mass-action equations. - * Factor is essentially the activity coefficient, representing - * the work required to bring charged ions to the surface - */ - int i; - char token[MAX_LENGTH]; - LDBLE sum_z; - struct master *master_ptr; - struct unknown *unknown_ptr; - - if (use.surface_ptr->edl == FALSE) return(OK); - sum_z = 0.0; - master_ptr = NULL; -/* - * Find sum of charge of aqueous species and surface master species - */ - for (i=1; i < count_trxn; i++) { - if (trxn.token[i].s->type == AQ || trxn.token[i].s == s_hplus || - trxn.token[i].s == s_eminus) { - sum_z += trxn.token[i].s->z * trxn.token[i].coef; - } - if (trxn.token[i].s->type == SURF) { - master_ptr = trxn.token[i].s->primary; - } - } -/* - * Find potential unknown for surface species - */ - if (master_ptr == NULL) { - sprintf(error_string,"Did not find a surface species in equation defining %s", trxn.token[0].name); - error_msg(error_string, CONTINUE); - sprintf(error_string,"One of the following must be defined with SURFACE_SPECIES:"); - error_msg(error_string, CONTINUE); - for (i=1; i < count_trxn; i++) { - sprintf(error_string," %s", trxn.token[i].name); - error_msg(error_string, CONTINUE); - } - input_error++; - return(ERROR); - } - strcpy(token, master_ptr->elt->name); - unknown_ptr = find_surface_charge_unknown(token); - if (unknown_ptr == NULL) { - sprintf(error_string, "No potential unknown found for surface species %s.", token); - error_msg(error_string, STOP); - } - master_ptr = unknown_ptr->master[0]; /* potential for surface component */ -/* - * Make sure there is space - */ - if (count_trxn + 1 >= max_trxn) { - space ((void **) &(trxn.token), count_trxn+1, &max_trxn, - sizeof(struct rxn_token_temp)); - } -/* - * Include psi in mass action equation - */ - if (master_ptr != NULL) { - trxn.token[count_trxn].name = master_ptr->s->name; - trxn.token[count_trxn].s = master_ptr->s; - trxn.token[count_trxn].coef = -2.0 * sum_z; - count_trxn++; - } else { - output_msg(OUTPUT_MESSAGE, "How did this happen in add potential factor?\n"); - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_surface_charge_balance(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add the potential factor to surface mass-action equations. - * Factor is essentially the activity coefficient, representing - * the work required to bring charged ions to the surface - */ - int i; - char *ptr; - char token[MAX_LENGTH]; - - struct master *master_ptr; - struct unknown *unknown_ptr; - - if (use.surface_ptr->edl == FALSE) return(OK); - master_ptr = NULL; -/* - * Find master species - */ - for (i=0; i < count_elts; i++) { - if (elt_list[i].elt->primary->s->type == SURF) { - master_ptr = elt_list[i].elt->primary; - break; - } - } - if (i >= count_elts) { - sprintf(error_string, "No surface master species found for surface species."); - error_msg(error_string, STOP); - } -/* - * Find potential unknown for surface species - */ - strcpy(token, master_ptr->elt->name); - unknown_ptr = find_surface_charge_unknown(token); - if (unknown_ptr == NULL) { - sprintf(error_string, "No potential unknown found for surface species %s.", token); - error_msg(error_string, STOP); - } - master_ptr = unknown_ptr->master[0]; /* potential for surface component */ -/* - * Include charge balance in list for mass-balance equations - */ - ptr = master_ptr->elt->name; - get_secondary_in_species(&ptr, 1.0); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int rewrite_master_to_secondary(struct master *master_ptr1, struct master *master_ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Write equation for secondary master species in terms of another secondary master species - * Store result in rxn_secondary of master_ptr. - */ - LDBLE coef1, coef2; - struct master *master_ptr_p1, *master_ptr_p2; -/* - * Check that the two master species have the same primary master species - */ - master_ptr_p1 = master_ptr1->elt->primary; - master_ptr_p2 = master_ptr2->elt->primary; - if (master_ptr_p1 != master_ptr_p2 || - master_ptr_p1 == NULL ) { - sprintf(error_string, "All redox states must be for the same element. %s\t%s.", - master_ptr1->elt->name, master_ptr2->elt->name); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find coefficient of primary master in reaction - */ - coef1=rxn_find_coef(master_ptr1->rxn_primary, master_ptr_p1->s->name); - coef2=rxn_find_coef(master_ptr2->rxn_primary, master_ptr_p1->s->name); - if ( equal(coef1,0.0,TOL) == TRUE || equal(coef2,0.0,TOL) == TRUE ) { - sprintf(error_string, "One of these equations does not contain master species for element, %s or %s.", - master_ptr1->s->name, master_ptr2->s->name); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Rewrite equation to secondary master species - */ - count_trxn=0; - trxn_add(master_ptr1->rxn_primary, 1.0, FALSE); - trxn_add(master_ptr2->rxn_primary, -coef1/coef2, TRUE); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_exchange (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for exchanger in unknowns structures - */ - int i, j; - struct master *master_ptr; - struct master **master_ptr_list; - - if (use.exchange_ptr == NULL) return(OK); - - for (j = 0; j < use.exchange_ptr->count_comps; j++) { - for (i = 0; use.exchange_ptr->comps[j].totals[i].elt != NULL; i++ ) { -/* - * Find master species - */ - master_ptr = use.exchange_ptr->comps[j].totals[i].elt->master; - if (master_ptr == NULL) { - sprintf(error_string, "Master species not in data " - "base for %s, skipping element.", - use.exchange_ptr->comps[j].totals[i].elt->name); - input_error++; - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != EX) continue; -/* - * Check for data already given - */ - if (master_ptr->in != FALSE ) { - x[master_ptr->unknown->number]->moles += use.exchange_ptr->comps[j].totals[i].coef; - - } else { -/* - * Set flags - */ - master_ptr_list = unknown_alloc_master(); - master_ptr_list[0] = master_ptr; - master_ptr->in = TRUE; -/* - * Set unknown data - */ - x[count_unknowns]->type = EXCH; - x[count_unknowns]->exch_comp = &(use.exchange_ptr->comps[j]); - x[count_unknowns]->description = use.exchange_ptr->comps[j].totals[i].elt->name; - x[count_unknowns]->moles = use.exchange_ptr->comps[j].totals[i].coef; - x[count_unknowns]->master = master_ptr_list; - x[count_unknowns]->master[0]->unknown = x[count_unknowns]; - count_unknowns++; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for gas phase unknown (sum of partial pressures) - * in unknown structure - */ - int i; - if (use.gas_phase_ptr == NULL) return(OK); -/* - * One for total moles in gas - */ - x[count_unknowns]->type = GAS_MOLES; - x[count_unknowns]->description = string_hsave("gas moles"); - x[count_unknowns]->moles = 0.0; - for (i=0; i < use.gas_phase_ptr->count_comps; i++) { - x[count_unknowns]->moles += use.gas_phase_ptr->comps[i].moles; - } - if (x[count_unknowns]->moles <= 0) x[count_unknowns]->moles = MIN_TOTAL; - x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); - x[count_unknowns]->gas_phase = use.gas_phase_ptr; - gas_unknown = x[count_unknowns]; - count_unknowns++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_s_s_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for solid solution unknowns (sum of partial pressures) - * in unknown structure - */ - int i, j; - if (use.s_s_assemblage_ptr == NULL) return(OK); -/* - * One for each component in each solid solution - */ - s_s_unknown = NULL; - for (j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i=0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - x[count_unknowns]->type = S_S_MOLES; - x[count_unknowns]->description = string_hsave(use.s_s_assemblage_ptr->s_s[j].comps[i].name); - x[count_unknowns]->moles = 0.0; - if (use.s_s_assemblage_ptr->s_s[j].comps[i].moles <= 0) { - use.s_s_assemblage_ptr->s_s[j].comps[i].moles = MIN_TOTAL; - } - x[count_unknowns]->moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles = x[count_unknowns]->moles; - x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); - x[count_unknowns]->s_s = &(use.s_s_assemblage_ptr->s_s[j]); - x[count_unknowns]->s_s_comp = &(use.s_s_assemblage_ptr->s_s[j].comps[i]); - x[count_unknowns]->s_s_comp_number = i; - x[count_unknowns]->phase = use.s_s_assemblage_ptr->s_s[j].comps[i].phase; - x[count_unknowns]->number = count_unknowns; - x[count_unknowns]->phase->dn = use.s_s_assemblage_ptr->s_s[j].comps[i].dn; - x[count_unknowns]->phase->dnb = use.s_s_assemblage_ptr->s_s[j].comps[i].dnb; - x[count_unknowns]->phase->dnc = use.s_s_assemblage_ptr->s_s[j].comps[i].dnc; - x[count_unknowns]->phase->log10_fraction_x = use.s_s_assemblage_ptr->s_s[j].comps[i].log10_fraction_x; - x[count_unknowns]->phase->log10_lambda = use.s_s_assemblage_ptr->s_s[j].comps[i].log10_lambda; - if (s_s_unknown == NULL) s_s_unknown = x[count_unknowns]; - count_unknowns++; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_surface (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for surface assemblage in unknown structure - */ - int i, j, k; - struct master *master_ptr; - struct master **master_ptr_list; - struct unknown *unknown_ptr; - char token[MAX_LENGTH]; - char *name1, *name2; - if (use.surface_ptr == NULL) return(OK); - - for (i = 0; i < use.surface_ptr->count_comps; i++ ) { -/* - * Find master species for each surface, setup unknown structure - */ - for (j = 0; use.surface_ptr->comps[i].totals[j].elt != NULL; j++) { - master_ptr = use.surface_ptr->comps[i].totals[j].elt->master; - if (master_ptr == NULL) { - sprintf(error_string, "Master species not in data base for %s, skipping element.", use.surface_ptr->comps[i].totals[j].elt->name); - warning_msg(error_string); - continue; - } - if (master_ptr->type != SURF) continue; -/* - * Check that data not already given - */ if (master_ptr->in != FALSE ) { - sprintf(error_string, "Analytical data entered twice for %s.", master_ptr->s->name); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } -/* - * Set flags - */ - use.surface_ptr->comps[i].master = master_ptr; - master_ptr_list = unknown_alloc_master(); - master_ptr_list[0] = master_ptr; - master_ptr->in = TRUE; -/* - * Setup mass balance unknown - */ - x[count_unknowns]->type = SURFACE; - x[count_unknowns]->description = use.surface_ptr->comps[i].totals[j].elt->name; - x[count_unknowns]->number = count_unknowns; - x[count_unknowns]->surface_comp = &(use.surface_ptr->comps[i]); - x[count_unknowns]->master = master_ptr_list; - x[count_unknowns]->master[0]->unknown = x[count_unknowns]; - x[count_unknowns]->moles = use.surface_ptr->comps[i].totals[j].coef; - if (surface_unknown == NULL) surface_unknown = x[count_unknowns]; - x[count_unknowns]->potential_unknown = NULL; - count_unknowns++; - if (use.surface_ptr->edl == FALSE) continue; -/* - * Setup surface-potential unknown - */ - strcpy(token, master_ptr->elt->name); - unknown_ptr = find_surface_charge_unknown(token); - if (unknown_ptr != NULL) { - x[count_unknowns - 1]->potential_unknown = unknown_ptr; - } else { -/* - * Find master species - */ - replace ("_CB", "_psi", token); - master_ptr = master_bsearch (token); - master_ptr_list = unknown_alloc_master(); - master_ptr_list[0] = master_ptr; - master_ptr->in = TRUE; -/* - * Find surface charge structure - */ - x[count_unknowns]->type = SURFACE_CB; - k = use.surface_ptr->comps[i].charge; - x[count_unknowns]->surface_charge = &use.surface_ptr->charge[k]; - x[count_unknowns]->related_moles = x[count_unknowns]->surface_charge->grams; - x[count_unknowns]->mass_water = use.surface_ptr->charge[k].mass_water; - replace("_psi","_CB",token); - x[count_unknowns]->description = string_hsave(token); - x[count_unknowns]->master = master_ptr_list; - use.surface_ptr->charge[k].psi_master = x[count_unknowns]->master[0]; - x[count_unknowns]->master[0]->unknown = x[count_unknowns]; - x[count_unknowns]->moles = 0.0; - x[count_unknowns - 1]->potential_unknown = x[count_unknowns]; - x[count_unknowns]->surface_comp = x[count_unknowns - 1]->surface_comp; - count_unknowns++; - } - } - } -/* - * check related phases - */ - if (use.surface_ptr->related_phases == TRUE) { - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != SURFACE_CB) continue; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE) continue; - if (x[j]->potential_unknown != x[i]) continue; - if (x[j]->surface_comp->phase_name != x[i]->surface_comp->phase_name) { - if (x[i]->surface_comp->phase_name == NULL) { - name1 = string_hsave("None"); - } else { - name1 = x[i]->surface_comp->phase_name; - } - if (x[j]->surface_comp->phase_name == NULL) { - name2 = string_hsave("None"); - } else { - name2 = x[j]->surface_comp->phase_name; - } - input_error++; - sprintf(error_string,"All surface sites for a single component must be related to the same phase.\n\tSite: %s is related to %s, Site: %s is related to %s", - x[i]->surface_comp->master->s->name, name1, - x[j]->surface_comp->master->s->name, name2); - - error_msg(error_string, CONTINUE); - } - } - } - } -/* - * check related kinetics - */ - if (use.surface_ptr->related_rate == TRUE) { - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != SURFACE_CB) continue; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE) continue; - if (x[j]->potential_unknown != x[i]) continue; - if (x[j]->surface_comp->rate_name != x[i]->surface_comp->rate_name) { - if (x[i]->surface_comp->rate_name == NULL) { - name1 = string_hsave("None"); - } else { - name1 = x[i]->surface_comp->rate_name; - } - if (x[j]->surface_comp->rate_name == NULL) { - name2 = string_hsave("None"); - } else { - name2 = x[j]->surface_comp->rate_name; - } - input_error++; - sprintf(error_string,"All surface sites for a single component must be related to the same kinetic reaction.\n\tSite: %s is related to %s, Site: %s is related to %s", - x[i]->surface_comp->master->s->name, name1, - x[j]->surface_comp->master->s->name, name2); - - error_msg(error_string, CONTINUE); - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct unknown *find_surface_charge_unknown(char *str_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Makes name for the potential unknown and returns in str_ptr - * Returns NULL if this unknown not in unknown list else - * returns a pointer to the potential unknown - */ - int i; - char *ptr; - char token[MAX_LENGTH]; - - replace ("_", " ", str_ptr); - ptr = str_ptr; - copy_token(token, &ptr, &i); - strcat(token, "_CB"); - strcpy(str_ptr, token); - for (i = 0; i < count_unknowns; i++) { - if ( strcmp(token, x[i]->description) == 0 ) { - return(x[i]); - } - } - return(NULL); -} - -/* ---------------------------------------------------------------------- */ -int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn) -/* ---------------------------------------------------------------------- */ -{ -/* - * Rewrites rxn_secondary for all redox states in list - * First, in = TRUE; others, in = REWRITE - */ - int j; - struct master *master_ptr, *master_ptr0; -/* - * Set master_ptr->in, master_ptr->rxn - */ - master_ptr0 = master_ptr_list[0]; - for (j = 0; (master_ptr = master_ptr_list[j]) != NULL; j++) { -/* - * Check that data not already given - */ - if (master_ptr->s == s_h2o) { - sprintf(error_string, "Can not enter concentration data for O(-2),\n\tdissolved oxygen is O(0),\n\tfor mass of water, use -water identifier."); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - - if (master_ptr->in != FALSE ) { - if (master_ptr->s != s_eminus && master_ptr->s != s_hplus) { - sprintf(error_string, "Analytical data entered twice for %s.", master_ptr->s->name); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - } -/* - * Set flags - */ - if (j == 0) { - master_ptr->in = TRUE; - if (master_ptr->s->primary == NULL) { - rxn_free (master_ptr->rxn_secondary); - master_ptr->rxn_secondary = rxn_dup (master_ptr->s->rxn_s); -/* debug - trxn_print (); - */ - } - } else { - master_ptr->in = REWRITE; - if (master_ptr0->s->primary == NULL) { - rewrite_master_to_secondary(master_ptr, master_ptr0); - rxn_free (master_ptr->rxn_secondary); - master_ptr->rxn_secondary = rxn_alloc(count_trxn+1); - trxn_copy (master_ptr->rxn_secondary); -/* debug - trxn_print (); - */ - } - } - master_ptr->pe_rxn = pe_rxn; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Fills in data for pure_phase assemglage in unknown structure - */ - - if (use.pp_assemblage_ptr == NULL) return(OK); -/* - * Setup unknowns - */ - for (i=0; i < use.pp_assemblage_ptr->count_comps; i++) { - x[count_unknowns]->type = PP; - x[count_unknowns]->description = use.pp_assemblage_ptr->pure_phases[i].name; - x[count_unknowns]->moles = use.pp_assemblage_ptr->pure_phases[i].moles; - x[count_unknowns]->phase = use.pp_assemblage_ptr->pure_phases[i].phase; - x[count_unknowns]->si = use.pp_assemblage_ptr->pure_phases[i].si; - x[count_unknowns]->delta = use.pp_assemblage_ptr->pure_phases[i].delta; - x[count_unknowns]->pure_phase = &(use.pp_assemblage_ptr->pure_phases[i]); - x[count_unknowns]->dissolve_only = use.pp_assemblage_ptr->pure_phases[i].dissolve_only; - if (pure_phase_unknown == NULL) pure_phase_unknown = x[count_unknowns]; - count_unknowns++; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_solution (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fills in data in unknown structure for the solution - */ - int l, i, j; - struct master *master_ptr; - struct solution *solution_ptr; - char *ptr; - char token[MAX_LENGTH]; - struct master_isotope *master_isotope_ptr; - - solution_ptr = use.solution_ptr; - count_unknowns = 0; - for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) { - /*solution_ptr->totals[i].skip = FALSE;*/ - ptr=solution_ptr->totals[i].description; - copy_token(token, &ptr, &l); - master_ptr = master_bsearch(token); - /* - * Treat minor isotopes as special in initial solution calculation - */ - if ((state == INITIAL_SOLUTION) && (master_ptr != NULL) && (master_ptr->minor_isotope == TRUE) && (initial_solution_isotopes == FALSE)) { - master_isotope_ptr = master_isotope_search(token); - if (master_isotope_ptr != NULL) { - master_isotope_ptr->ratio = solution_ptr->totals[i].input_conc; - } - /*solution_ptr->totals[i].skip = TRUE;*/ - continue; - } -/* - * Check that total not <= zero - */ - if (solution_ptr->totals[i].input_conc <= 0.0) { - if (strcmp(token,"H(1)") != 0 && - strcmp(token,"E") != 0 ) { - /*solution_ptr->totals[i].skip = TRUE;*/ - continue; - } - } -/* - * Find master species - */ - master_ptr = master_bsearch(token); - if (master_ptr == NULL) { - /*solution_ptr->totals[i].skip = TRUE;*/ - sprintf(error_string,"Master species not in data base for %s, skipping element.", solution_ptr->totals[i].description); - warning_msg(error_string); - continue; - } - if (master_ptr->type != AQ) { - /*solution_ptr->totals[i].skip = TRUE;*/ - sprintf(error_string, "Only aqueous concentrations are allowed in solution data, ignoring %s.", solution_ptr->totals[i].description); - warning_msg(error_string); - continue; - } -/* - * Store list of master species pointers, set master[i].in and master[i].rxn for list - */ - x[count_unknowns]->master = get_list_master_ptrs(ptr, master_ptr); - setup_master_rxn(x[count_unknowns]->master, &(pe_x[solution_ptr->totals[i].n_pe].rxn)); -/* - * Set default unknown data - */ - x[count_unknowns]->type = MB; - x[count_unknowns]->description = solution_ptr->totals[i].description; - x[count_unknowns]->total = &(solution_ptr->totals[i]); - for (j=0; x[count_unknowns]->master[j] != NULL; j++) { - x[count_unknowns]->master[j]->unknown = x[count_unknowns]; - } - x[count_unknowns]->moles = solution_ptr->totals[i].moles; -/* - * Set pointers - */ - ptr=solution_ptr->totals[i].description; - copy_token(token, &ptr, &l); - str_tolower(token); - if (strstr( token,"alk") != NULL) { - if (alkalinity_unknown == NULL) { - x[count_unknowns]->type = ALK; - alkalinity_unknown=x[count_unknowns]; - } else { - error_msg("Alkalinity entered more than once.", CONTINUE); - input_error++; - } - } else if (strcmp(token,"c") == 0 || strcmp(token,"c(4)") == 0 ) { - if (carbon_unknown == NULL) { - carbon_unknown=x[count_unknowns]; - } else { - error_msg("Carbon entered more than once.", CONTINUE); - input_error++; - } - } else if (strcmp(token,"h(1)") == 0 ) { - if (ph_unknown == NULL) { - ph_unknown=x[count_unknowns]; - } else { - error_msg("pH entered more than once.", CONTINUE); - input_error++; - } - } else if (strcmp(token,"e") == 0 ) { - if (pe_unknown == NULL) { - pe_unknown=x[count_unknowns]; - } else { - error_msg("pe entered more than once.", CONTINUE); - input_error++; - } - } -/* - * Charge balance unknown - */ - if (solution_ptr->totals[i].equation_name != NULL ) { - ptr = solution_ptr->totals[i].equation_name; - copy_token(token, &ptr, &l); - str_tolower(token); - if (strstr(token,"charge") != NULL) { - if (charge_balance_unknown == NULL) { - charge_balance_unknown=x[count_unknowns]; - x[count_unknowns]->type = CB; - if (charge_balance_unknown == ph_unknown ) { - x[count_unknowns]->moles = solution_ptr->cb; - } - } else { - error_msg("Charge balance specified for more" - " than one species.", CONTINUE); - input_error++; - } - } else { -/* - * Solution phase boundaries - */ - solution_ptr->totals[i].phase= - phase_bsearch(solution_ptr->totals[i].equation_name, &l, FALSE); - if (solution_ptr->totals[i].phase == NULL) { - sprintf(error_string, "Expected a mineral name, %s.", solution_ptr->totals[i].equation_name); - error_msg(error_string, CONTINUE); - input_error++; - } - x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; - x[count_unknowns]->phase=solution_ptr->totals[i].phase; - x[count_unknowns]->si=solution_ptr->totals[i].phase_si; - if (solution_phase_boundary_unknown == NULL) { - solution_phase_boundary_unknown = x[count_unknowns]; - } - } - } - count_unknowns++; - } -/* - * Set mb_unknown - */ - if (count_unknowns > 0) mb_unknown=x[0]; -/* - * Special for alkalinity - */ - if (alkalinity_unknown != NULL) { - if (carbon_unknown != NULL) { -/* - * pH adjusted to obtain given alkalinity - */ - if (ph_unknown == NULL) { - output_msg(OUTPUT_MESSAGE,"\npH will be adjusted to obtain desired alkalinity.\n\n"); - ph_unknown = alkalinity_unknown; - master_ptr=master_bsearch("H(1)"); - alkalinity_unknown->master[0] = master_ptr; - master_ptr->in = TRUE; - master_ptr->unknown = ph_unknown; - ph_unknown->master[0] = master_ptr; - ph_unknown->description = string_hsave( "H(1)" ); - } else { - error_msg("pH adjustment is needed for alkalinity but" - " charge balance or a phase boundary was also specified.", CONTINUE); - input_error++; - } -/* - * Carbonate ion adjusted to obtain given alkalintiy - */ - } else { - if (alkalinity_unknown->master[0]->s->secondary != NULL) { - alkalinity_unknown->master[0]->s->secondary->in=TRUE; - alkalinity_unknown->master[0]->s->secondary->unknown=alkalinity_unknown; - } else { - error_msg("Error in definition of Alkalinity in SOLUTION_MASTER_SPECIES and SOLUTION_SPECIES.\n\tAlkalinity master species should be same as master species for C(4).", CONTINUE); - input_error++; - } - } - } - if (pitzer_model == FALSE) { - /* - * Ionic strength - */ - mu_unknown=x[count_unknowns]; - x[count_unknowns]->description= string_hsave( "Mu" ); - x[count_unknowns]->type=MU; - x[count_unknowns]->number=count_unknowns; - x[count_unknowns]->moles = 0.0; - mu_unknown = x[count_unknowns]; - count_unknowns++; - } - /* - * Activity of water - */ - ah2o_unknown=x[count_unknowns]; - ah2o_unknown->description= string_hsave( "A(H2O)" ); - ah2o_unknown->type=AH2O; - ah2o_unknown->number=count_unknowns; - ah2o_unknown->master = unknown_alloc_master(); - ah2o_unknown->master[0] = master_bsearch ("O"); - ah2o_unknown->master[0]->unknown = ah2o_unknown; - ah2o_unknown->moles = 0.0; - count_unknowns++; - - if (state >= REACTION) { -/* - - * Reaction: pH for charge balance - */ - ph_unknown = x[count_unknowns]; - ph_unknown->description = string_hsave( "pH" ); - ph_unknown->type = CB; - ph_unknown->moles = solution_ptr->cb; - ph_unknown->number = count_unknowns; - ph_unknown->master = unknown_alloc_master(); - ph_unknown->master[0] = s_hplus->primary; - ph_unknown->master[0]->unknown = ph_unknown; - charge_balance_unknown = ph_unknown; - count_unknowns++; -/* - * Reaction: pe for total hydrogen - */ - pe_unknown = x[count_unknowns]; - mass_hydrogen_unknown = x[count_unknowns]; - mass_hydrogen_unknown->description = string_hsave( "Hydrogen" ); - mass_hydrogen_unknown->type = MH; -#ifdef COMBINE -#ifndef COMBINE_CHARGE - mass_hydrogen_unknown->moles = solution_ptr->total_h - 2*solution_ptr->total_o ; -#else - mass_hydrogen_unknown->moles = solution_ptr->total_h - 2*solution_ptr->total_o - solution_ptr->cb ; -#endif -#else - mass_hydrogen_unknown->moles = solution_ptr->total_h; -#endif - mass_hydrogen_unknown->number = count_unknowns; - mass_hydrogen_unknown->master = unknown_alloc_master(); - mass_hydrogen_unknown->master[0] = s_eminus->primary; - mass_hydrogen_unknown->master[0]->unknown = mass_hydrogen_unknown; - count_unknowns++; -/* - * Reaction H2O for total oxygen - */ - mass_oxygen_unknown = x[count_unknowns]; - mass_oxygen_unknown->description = string_hsave( "Oxygen" ); - mass_oxygen_unknown->type = MH2O; - mass_oxygen_unknown->moles = solution_ptr->total_o; - mass_oxygen_unknown->number = count_unknowns; - mass_oxygen_unknown->master = unknown_alloc_master(); - mass_oxygen_unknown->master[0] = s_h2o->primary; - count_unknowns++; - } -/* - * Validity tests - */ - if ( (ph_unknown != NULL) && - (ph_unknown == charge_balance_unknown) && - (alkalinity_unknown != NULL) ) { - error_msg("pH adustment can not attain charge balance" - " when alkalinity is fixed.", CONTINUE); - input_error++; - } - if ( (alkalinity_unknown != NULL) && - (alkalinity_unknown->type == CB || - alkalinity_unknown->type == SOLUTION_PHASE_BOUNDARY)) { - error_msg("Alkalinity can not be used with charge balance" - " or solution phase boundary constraints.", CONTINUE); - input_error++; - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct master **unknown_alloc_master(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocates space for a list of 2 master pointers - */ - struct master **master_ptr; - - master_ptr = (struct master **) PHRQ_malloc( 2 * sizeof(struct master *) ); - if (master_ptr == NULL) malloc_error(); - master_ptr[0] = NULL; - master_ptr[1] = NULL; - return(master_ptr); -} -/* ---------------------------------------------------------------------- */ -int setup_unknowns (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Counts unknowns and allocates space for unknown structures - */ - int i, j; - struct solution *solution_ptr; - - solution_ptr = use.solution_ptr; -/* - * Calculate maximum number of unknowns - */ - max_unknowns = 0; -/* - * Count mass balance in solution - */ - for (i = 0; solution_ptr->totals[i].description != NULL; i++ ) max_unknowns++; -/* - * Add 5 for ionic strength, activity of water, charge balance, total H, total O - */ - max_unknowns += 5; -/* - * Count pure phases - */ - if (use.pp_assemblage_ptr != NULL) { - max_unknowns += use.pp_assemblage_ptr->count_comps; -/* - for (i = 0; use.pp_assemblage_ptr->pure_phases[i].name != NULL; i++ ) { - max_unknowns++; - } - */ - } -/* - * Count exchange - */ - if (use.exchange_ptr != NULL) { - for (j = 0; j < use.exchange_ptr->count_comps; j++) { - for (i = 0; use.exchange_ptr->comps[j].totals[i].elt != NULL; i++) { - if (use.exchange_ptr->comps[j].totals[i].elt->master == NULL) { - sprintf(error_string, "Master species missing for element %s", use.exchange_ptr->comps[j].totals[i].elt->name); - error_msg(error_string, STOP); - } - if (use.exchange_ptr->comps[j].totals[i].elt->master->type == EX) { - max_unknowns++; - } - } - } - } -/* - * Count surfaces - */ - if (use.surface_ptr != NULL) { - max_unknowns += use.surface_ptr->count_comps + use.surface_ptr->count_charge; - } -/* - * Count gas components - */ - if (use.gas_phase_ptr != NULL) { - max_unknowns++; - } -/* - * Count solid solutions - */ - if (use.s_s_assemblage_ptr != NULL) { - /* max_unknowns += 2 * use.s_s_assemblage_ptr->count_s_s;*/ - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - max_unknowns += use.s_s_assemblage_ptr->s_s[i].count_comps; - } - } - -/* - * One for luck - */ - max_unknowns++; - if (pitzer_model == TRUE) { - max_unknowns += count_s; - } -/* - * Allocate space for pointer array and structures - */ - - space ((void **) ((void *) &x), INIT, &max_unknowns, sizeof(struct unknown *)); - for (i = 0; i < max_unknowns; i++) { - x[i] = (struct unknown *) unknown_alloc (); - x[i]->number = i; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_dn (int k, LDBLE *source, int row, LDBLE coef_in, LDBLE *gamma_source) -/* ---------------------------------------------------------------------- */ -{ -/* - * Stores the terms for d moles of species k in solution into row, multiplied - * by coef_in - */ - int col; - LDBLE coef; - struct rxn_token *rxn_ptr; - struct master *master_ptr; - - if (equal(coef_in, 0.0, TOL) == TRUE) { - return(OK); - } -/* Gamma term for d molality of species */ -/* Note dg includes molality as a factor */ - - row = row * (count_unknowns + 1); - if (s[k]->type != SURF && s[k] != s_h2o ) { - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n","Activity coefficient", (double) (-1.0 * coef_in), row/(count_unknowns + 1), mu_unknown->number); - } - /* mu term */ - if (gamma_source != NULL) { - store_jacob(gamma_source, &array[row + mu_unknown->number], -1.0 * coef_in); -#ifdef SKIP - if (use_tot_g == 0) { - store_jacob(&(s[k]->dg_total_g), &array[row + mu_unknown->number], -1.0 * coef_in); - } else if (use_tot_g == 1) { - store_jacob(&(s[k]->dg), &array[row + mu_unknown->number], -1.0 * coef_in); - } -#endif - } - } -/* - * Mass of water factor - */ - if (mass_oxygen_unknown != NULL && s[k]->type != EX && s[k]->type != SURF) { - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n", - mass_oxygen_unknown->master[0]->s->name, (double) coef_in, - row/(count_unknowns+1), - mass_oxygen_unknown->number); - } - store_jacob(source, &(array[row + mass_oxygen_unknown->number]), coef_in); - } - if ( s[k] == s_h2o ) return(OK); - for ( rxn_ptr = s[k]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s->secondary != NULL && rxn_ptr->s->secondary->in == TRUE ) { - master_ptr=rxn_ptr->s->secondary; - } else { - master_ptr=rxn_ptr->s->primary; - } - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\n",master_ptr->s->name); - } - if (master_ptr->unknown == NULL) continue; - col = master_ptr->unknown->number; - coef = coef_in * rxn_ptr->coef; - store_jacob (source, &(array[row + col]), coef); - if ( debug_prep == TRUE ) { - output_msg(OUTPUT_MESSAGE,"\t\t%-24s%10.3f\t%d\t%d\n",master_ptr->s->name, (double) coef, - row/(count_unknowns+1), col); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_jacob(LDBLE *source, LDBLE *target, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Adds a new item to either sum_jacob1 or sum_jacob2 - * If coef is 1.0, adds to sum_jacob1, which does not require a multiply - * Otherwise, adds to sum_jacob2, which allows multiply by coef - */ - if (equal(coef, 1.0, TOL) == TRUE) { - if (debug_prep == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t\tjacob1 %d\n", count_sum_jacob1); - } - sum_jacob1[count_sum_jacob1].source = source; - sum_jacob1[count_sum_jacob1++].target = target; - /* Check space */ - if (count_sum_jacob1 >= max_sum_jacob1) { - space ((void **) ((void *) &sum_jacob1), count_sum_jacob1, - &max_sum_jacob1, - sizeof(struct list1)); - } - } else { - if (debug_prep == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t\tjacob2 %d\n", count_sum_jacob2); - } - sum_jacob2[count_sum_jacob2].source = source; - sum_jacob2[count_sum_jacob2].target = target; - sum_jacob2[count_sum_jacob2++].coef=coef; - /* Check space */ - if (count_sum_jacob2 >= max_sum_jacob2) { - space ((void **) ((void *) &sum_jacob2), count_sum_jacob2, &max_sum_jacob2, - sizeof(struct list2)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_jacob0(int row, int column, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Stores in list a constant coef which will be added into jacobian array - */ - sum_jacob0[count_sum_jacob0].target = &(array[row*(count_unknowns+1) + column]); - sum_jacob0[count_sum_jacob0++].coef=coef; - /* Check space */ - if (count_sum_jacob0 >= max_sum_jacob0) { - space ((void **) ((void *) &sum_jacob0), count_sum_jacob0, - &max_sum_jacob0, - sizeof(struct list0)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_mb(LDBLE *source, LDBLE *target, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Adds item to list sum_mb1 or sum_mb2 - * If coef is 1.0, adds to sum_mb1, which does not require a multiply - * else, adds to sum_mb2, which will multiply by coef - */ - if (equal(coef, 1.0, TOL) == TRUE ) { - sum_mb1[count_sum_mb1].source = source; - sum_mb1[count_sum_mb1++].target = target; - if (count_sum_mb1 >= max_sum_mb1) { - space ((void **) ((void *) &sum_mb1), count_sum_mb1 + count_trxn + 4, - &max_sum_mb1, sizeof(struct list1)); - } - } else { - sum_mb2[count_sum_mb2].source = source; - sum_mb2[count_sum_mb2].coef = coef; - sum_mb2[count_sum_mb2++].target = target; - if (count_sum_mb2 >= max_sum_mb2) { - space ((void **) ((void *) &sum_mb2), count_sum_mb2, - &max_sum_mb2, sizeof(struct list2)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_sum_deltas(LDBLE *source, LDBLE *target, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * List sum_delta is summed to determine the change in the mass of - * each element due to mass transfers of minerals, changes show up - * in x[i]->delta. These may be multiplied by a factor under some - * situations where the entire calculated step is not taken - */ - sum_delta[count_sum_delta].source = source; - sum_delta[count_sum_delta].target = target; - sum_delta[count_sum_delta++].coef=coef; - /* Check space */ - if (count_sum_delta >= max_sum_delta) { - space ((void **) ((void *) &sum_delta), count_sum_delta, &max_sum_delta, - sizeof(struct list2)); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int switch_bases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check if activity of first master species is predominant among activities of - * secondary master species included in mass balance. - */ - int i, j; - int first; - int return_value; - LDBLE la, la1; - struct master *master_ptr; - - return_value = FALSE; - for (i=0; i < count_unknowns; i++) { - if (x[i]->type != MB) continue; - first = 0; - la = x[i]->master[0]->s->la; - for (j=1; x[i]->master[j] != NULL; j++) { - la1 = x[i]->master[j]->s->lm + x[i]->master[j]->s->lg; - if (first == 0 && la1 > la + 10.) { - la = la1; - first = j; - } else if (first != 0 && la1 > la ) { - la = la1; - first = j; - } - } - if (first != 0) { - master_ptr = x[i]->master[0]; - x[i]->master[0] = x[i]->master[first]; - x[i]->master[0]->in = TRUE; - x[i]->master[first] = master_ptr; - x[i]->master[first]->in = REWRITE; - output_msg(OUTPUT_LOG,"Switching bases to %s.\tIteration %d\n", - x[i]->master[0]->s->name, iterations); - return_value = TRUE; - } - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int tidy_redox (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Write pe redox reactions (rxn in struct pe_data) in terms of master species - * defined in analytical data - * - */ - int i, j, l; - char *ptr; - char token[MAX_LENGTH], tok1[MAX_LENGTH], tok2[MAX_LENGTH]; - struct pe_data *pe_data_ptr; - struct master *master_ptr1, *master_ptr2; -/* - * Keep valences of oxygen and hydrogen in model, if not already in - */ - for (i=0; i < count_master; i++) { - if (master[i]->primary == TRUE && - (master[i]->s == s_hplus || - master[i]->s == s_h2o ) ) { - j = i+1; - while (j < count_master && master[j]->elt->primary == master[i]) { - if (master[j]->in == FALSE && - master[j]->s != master[i]->s) { - master[j]->in = REWRITE; - master[j]->pe_rxn = master[i]->pe_rxn; - } - j++; - } - } - } -/* - * Writes equations for e- for each redox couple used in solution n - */ - for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) { - if (strcmp_nocase_arg1(pe_data_ptr->name,"pe") == 0 ) { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); - } else { - strcpy(token, pe_data_ptr->name); - replace ("/"," ",token); - ptr=token; -/* - * Get redox states and elements from redox couple - */ - copy_token (tok1, &ptr, &l); - copy_token (tok2, &ptr, &l); -/* - * Find master species - */ - master_ptr1 = master_bsearch(tok1); - master_ptr2 = master_bsearch(tok2); - if (master_ptr1 != NULL && master_ptr2 != NULL ) { - rewrite_master_to_secondary (master_ptr1, master_ptr2); -/* - * Rewrite equation to e- - */ - trxn_swap ("e-"); - } else { - sprintf(error_string, "Can not find master species for redox couple, %s.", pe_data_ptr->name); - error_msg(error_string, STOP); - } - if (inout() == FALSE) { - sprintf(error_string, "Analytical data missing for redox couple, %s\n\t Using pe instead.", pe_data_ptr->name ); - warning_msg(error_string); - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); - pe_data_ptr->name = pe_x[0].name; - } else { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_alloc(count_trxn+1); - trxn_copy (pe_data_ptr->rxn); - } - } - } -/* - * Rewrite equations to master species that are "in" the model - */ - for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) { - count_trxn=0; - trxn_add(pe_data_ptr->rxn, 1.0, FALSE); - if (write_mass_action_eqn_x(CONTINUE) == FALSE) { - sprintf(error_string, "Could not rewrite redox " - "couple equation for %s\n\t Possibly missing data for one " - "of the redox states.", pe_data_ptr->name); - warning_msg(error_string); - sprintf(error_string, "Using pe instead of %s.", pe_data_ptr->name); - warning_msg(error_string); - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup (pe_x[0].rxn); - pe_data_ptr->name = pe_x[0].name; - } else { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_alloc(count_trxn+1); - trxn_copy (pe_data_ptr->rxn); - } - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int write_mb_eqn_x (void) -/* ---------------------------------------------------------------------- */ -{ - int count, repeat; - int i, count_rxn_orig; - int j, k; - char *ptr; - struct master *master_ptr; -/* - * Rewrite any secondary master species flagged REWRITE - * Don't add in any pe reactions - */ - count = 0; - repeat = TRUE; - while (repeat == TRUE) { - count++; - if (count > MAX_ADD_EQUATIONS) { - sprintf(error_string, "Could not reduce equation " - "to primary and secondary species that are " - "in the model, %s.", trxn.token[0].s->name); - error_msg(error_string, CONTINUE); - return(ERROR); - } - repeat = FALSE; - count_rxn_orig=count_trxn; - for (i=1; i < count_rxn_orig; i++) { - if (trxn.token[i].s->secondary == NULL) continue; - if (trxn.token[i].s->secondary->in == REWRITE ) { - repeat=TRUE; - trxn_add(trxn.token[i].s->secondary->rxn_secondary, - trxn.token[i].coef, FALSE); - } - } - trxn_combine(); - } -/* - * - */ - count_elts = 0; - paren_count = 0; - for (i = 1; i < count_trxn; i++) { - j = count_elts; - ptr = trxn.token[i].s->name; - get_elts_in_species(&ptr, trxn.token[i].coef); - for (k = j; k < count_elts; k++) { - if (trxn.token[i].s->secondary != NULL) { - master_ptr = trxn.token[i].s->secondary->elt->primary; - } else { - master_ptr = trxn.token[i].s->primary; - } - if (elt_list[k].elt == master_ptr->elt) { - elt_list[k].coef = 0.0; - break; - } - } - if (trxn.token[i].s->secondary == NULL) { - ptr = trxn.token[i].s->primary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } else { - ptr = trxn.token[i].s->secondary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int write_mb_for_species_list (int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sets up data to add to species_list - * Original secondary redox states are retained - */ - int i; - char *ptr; -/* - * Start with secondary reaction - */ - count_trxn=0; - trxn_add (s[n]->rxn_s, 1.0, FALSE); -/* - * Copy to elt_list - */ - count_elts = 0; - paren_count = 0; - for (i = 1; i < count_trxn; i++) { - if (trxn.token[i].s->secondary == NULL) { - ptr = trxn.token[i].s->primary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } else { - ptr = trxn.token[i].s->secondary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } - } - for (i = 0; i < count_elts; i++) { - if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - elt_list[count_elts].elt = element_h_one; - elt_list[count_elts].coef = elt_list[i].coef*2; - count_elts++; - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } - s[n]->next_sys_total = (struct elt_list *) free_check_null(s[n]->next_sys_total); - s[n]->next_sys_total = elt_list_save(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int write_phase_sys_total (int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sets up data to add to species_list - * Original secondary redox states are retained - */ - int i; - char *ptr; -/* - * Start with secondary reaction - */ - count_trxn=0; - trxn_add (phases[n]->rxn_s, 1.0, FALSE); -/* - * Copy to elt_list - */ - count_elts = 0; - paren_count = 0; - for (i = 1; i < count_trxn; i++) { - if (trxn.token[i].s->secondary == NULL) { - ptr = trxn.token[i].s->primary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } else { - ptr = trxn.token[i].s->secondary->elt->name; - get_secondary_in_species(&ptr, trxn.token[i].coef); - } - } - for (i = 0; i < count_elts; i++) { - if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) { - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - elt_list[count_elts].elt = element_h_one; - elt_list[count_elts].coef = elt_list[i].coef*2; - count_elts++; - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } - phases[n]->next_sys_total = (struct elt_list *) free_check_null(phases[n]->next_sys_total); - phases[n]->next_sys_total = elt_list_save(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int k_temp(LDBLE tempc) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates log k's for all species and pure_phases - */ - int i; - LDBLE tempk; - - if (same_model == TRUE && same_temperature == TRUE) return(OK); - - tempk=tempc+273.15; -/* - * Calculate log k for all aqueous species - */ - for (i=0; i < count_s_x; i++) { - s_x[i]->lk = k_calc(s_x[i]->rxn_x->logk, tempk); - } -/* - * Calculate log k for all pure phases - */ - for (i=0; i < count_phases; i++) { - if (phases[i]->in == TRUE) { - phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk); - } - } -/* - * Calculate miscibility gaps for solid solutions - */ - if (use.s_s_assemblage_ptr != NULL ) { - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - if (fabs(tempk - use.s_s_assemblage_ptr->s_s[i].tk) > 0.01) { - s_s_prep(tempk, &(use.s_s_assemblage_ptr->s_s[i]), FALSE); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE k_calc(LDBLE *logk, LDBLE tempk) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates log k at specified temperature - * - * Input: - * *logk is pointer to logkt0, deltah, and analytical expression data - * tempk is temperature in degrees K. - * - * Returns calculated log k. - */ - return(logk[0] - - logk[1]*(298.15-tempk)/(298.15*tempk*LOG_10*R_KJ_DEG_MOL) - + logk[2] - + logk[3]*tempk - + logk[4]/tempk - + logk[5]*log10(tempk) - + logk[6]/(tempk*tempk) ); -} -/* ---------------------------------------------------------------------- */ -static int save_model(void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * save temperature - */ - last_model.temperature = tc_x; -/* - * mark master species - */ - for (i = 0; i < count_master; i++) { - master[i]->last_model = FALSE; - if (master[i]->total > 0) { - if (master[i]->primary == TRUE) { - master[i]->last_model = TRUE; - } else { - /* mark primary master */ - master[i]->s->secondary->elt->primary->last_model = TRUE; - } - } - } -/* - * save list of phase pointers for gas phase - */ - last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); - if (use.gas_phase_ptr != NULL) { - last_model.count_gas_phase = use.gas_phase_ptr->count_comps; - last_model.gas_phase = (struct phase **) PHRQ_malloc((size_t) use.gas_phase_ptr->count_comps * sizeof(struct phase *)); - if (last_model.gas_phase == NULL) malloc_error(); - for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { - last_model.gas_phase[i] = use.gas_phase_ptr->comps[i].phase; - } - } else { - last_model.count_gas_phase = 0; - last_model.gas_phase = NULL; - } -/* - * save list of names of solid solutions - */ - last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); - if (use.s_s_assemblage_ptr != NULL) { - last_model.count_s_s_assemblage = use.s_s_assemblage_ptr->count_s_s; - last_model.s_s_assemblage = (char **) PHRQ_malloc((size_t) use.s_s_assemblage_ptr->count_s_s * sizeof(char *)); - if (last_model.s_s_assemblage == NULL) malloc_error(); - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - last_model.s_s_assemblage[i] = use.s_s_assemblage_ptr->s_s[i].name; - } - } else { - last_model.count_s_s_assemblage = 0; - last_model.s_s_assemblage = NULL; - } -/* - * save list of phase pointers for pp_assemblage - */ - last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); - last_model.add_formula = (char **) free_check_null(last_model.add_formula); - last_model.si = (double *) free_check_null(last_model.si); - if (use.pp_assemblage_ptr != NULL) { - last_model.count_pp_assemblage = use.pp_assemblage_ptr->count_comps; - last_model.pp_assemblage = (struct phase **) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(struct phase *)); - if (last_model.pp_assemblage == NULL) malloc_error(); - last_model.add_formula = (char **) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(char *)); - if (last_model.add_formula == NULL) malloc_error(); - last_model.si = (double *) PHRQ_malloc((size_t) use.pp_assemblage_ptr->count_comps * sizeof(LDBLE)); - if (last_model.si == NULL) malloc_error(); - for (i = 0; i < use.pp_assemblage_ptr->count_comps; i++) { - last_model.pp_assemblage[i] = use.pp_assemblage_ptr->pure_phases[i].phase; - last_model.add_formula[i] = use.pp_assemblage_ptr->pure_phases[i].add_formula; - last_model.si[i] = use.pp_assemblage_ptr->pure_phases[i].si; - } - } else { - last_model.count_pp_assemblage = 0; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int check_same_model(void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Force new model to be built in prep - */ - if (last_model.force_prep == TRUE) { - last_model.force_prep = FALSE; - same_temperature = FALSE; - return(FALSE); - } -/* - * Check temperature - */ - if (fabs(tc_x - last_model.temperature) < 0.05) { - same_temperature = TRUE; - } else { - same_temperature = FALSE; - } -/* - * Check master species - */ - for (i = 0; i < count_master; i++) { -/* - output_msg(OUTPUT_MESSAGE,"%s\t%e\t%d\n", master[i]->elt->name, - master[i]->total, master[i]->last_model); - */ - if (master[i]->s == s_hplus || master[i]->s == s_h2o) continue; - if (master[i]->total > MIN_TOTAL && master[i]->last_model == TRUE) continue; - if (master[i]->total <= MIN_TOTAL && master[i]->last_model == FALSE) continue; - return(FALSE); - } -/* - * Check gas_phase - */ - if (use.gas_phase_ptr != NULL) { - if (last_model.count_gas_phase != use.gas_phase_ptr->count_comps) return(FALSE); - for (i = 0; i < use.gas_phase_ptr->count_comps; i++) { - if(last_model.gas_phase[i] != use.gas_phase_ptr->comps[i].phase) { - return(FALSE); - } - } - } else { - if(last_model.gas_phase != NULL) return(FALSE); - } -/* - * Check solid solutions - */ - if (use.s_s_assemblage_ptr != NULL) { - if (last_model.count_s_s_assemblage != use.s_s_assemblage_ptr->count_s_s) return(FALSE); - for (i = 0; i < use.s_s_assemblage_ptr->count_s_s; i++) { - if(last_model.s_s_assemblage[i] != use.s_s_assemblage_ptr->s_s[i].name) { - return(FALSE); - } - } - } else { - if(last_model.s_s_assemblage != NULL) return(FALSE); - } -/* - * Check pure_phases - */ - if (use.pp_assemblage_ptr != NULL) { - if (last_model.count_pp_assemblage != use.pp_assemblage_ptr->count_comps) return(FALSE); - for (i = 0; i < use.pp_assemblage_ptr->count_comps; i++) { - if(last_model.pp_assemblage[i] != use.pp_assemblage_ptr->pure_phases[i].phase) { - return(FALSE); - } - if(last_model.add_formula[i] != use.pp_assemblage_ptr->pure_phases[i].add_formula) { - return(FALSE); - } - if(last_model.si[i] != use.pp_assemblage_ptr->pure_phases[i].si) { - return(FALSE); - } - } - } else { - if(last_model.pp_assemblage != NULL) return(FALSE); - } -/* - * Model is the same - */ - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int build_min_exch(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Defines proportionality factor between mineral and exchanger to - * jacob0 - */ - int i, j, k, n, jj; - int row; - struct exch_comp *comp_ptr; - struct master *master_ptr; - struct unknown *unknown_ptr; - LDBLE coef; - - if (use.exchange_ptr == NULL) return(OK); - if (exchange_bsearch(use.exchange_ptr->n_user, &n) == NULL) { - input_error++; - sprintf(error_string,"Exchange %d not found.", use.exchange_ptr->n_user); - error_msg(error_string, CONTINUE); - } - if (exchange[n].related_phases == FALSE) return(OK); - for (i=0; i=0; j--) { - if (x[j]->type != EXCH) continue; - if (x[j]->master[0] == exchange[n].comps[i].master) break; - } - for (k=count_unknowns-1; k>=0; k--) { - if (x[k]->type != PP) continue; - if (x[k]->phase->name == exchange[n].comps[i].phase_name) break; - } - if (j == -1 ) { - input_error++; - sprintf(error_string,"Did not find unknown for master exchange species %s", exchange[n].comps[i].master->s->name); - error_msg(error_string, CONTINUE); - } - if (j == -1 || k == -1) continue; -/* - * Build jacobian - */ - comp_ptr = &exchange[n].comps[i]; - - /* charge balance */ - store_jacob0(charge_balance_unknown->number, x[k]->number, comp_ptr->formula_z * comp_ptr->phase_proportion); - store_sum_deltas(&delta[k], &charge_balance_unknown->delta, -comp_ptr->formula_z * comp_ptr->phase_proportion); - - - /* mole balance balance */ - for (jj = 0; comp_ptr->formula_totals[jj].elt != NULL; jj++) { - master_ptr = comp_ptr->formula_totals[jj].elt->primary; - if (master_ptr->in == FALSE) { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL) { - input_error++; - sprintf(error_string,"Did not find unknown for exchange related to mineral %s", exchange[n].comps[i].phase_name); - error_msg(error_string, STOP); - } - if (master_ptr->s->type == EX) { - if (equal(x[j]->moles, x[k]->moles * comp_ptr->formula_totals[jj].coef * comp_ptr->phase_proportion, 1.e-8) == FALSE) { - input_error++; - sprintf(error_string,"Number of sites in exchanger %s (=%e) not consistent with moles calculated from phase %s (%e).", master_ptr->s->name, (double) x[j]->moles, comp_ptr->phase_name, (double) (x[k]->moles * comp_ptr->formula_totals[jj].coef * comp_ptr->phase_proportion)); - error_msg(error_string, CONTINUE); - } - } - coef = comp_ptr->formula_totals[jj].coef; - if (master_ptr->s == s_hplus) { - row = mass_hydrogen_unknown->number; - unknown_ptr = mass_hydrogen_unknown; -#ifdef COMBINE -#ifndef COMBINE_CHARGE - coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o; -#else - coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o - x[j]->master[0]->s->z ; -#endif -#endif - } else if (master_ptr->s == s_h2o) { - row = mass_oxygen_unknown->number; - unknown_ptr = mass_oxygen_unknown; - } else { - row = master_ptr->unknown->number; - unknown_ptr = master_ptr->unknown; - } - store_jacob0(row, x[k]->number, coef * comp_ptr->phase_proportion); - store_sum_deltas(&delta[k], &unknown_ptr->delta, -coef * comp_ptr->phase_proportion); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_min_surface(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Defines proportionality factor between mineral and surface to - * jacob0 - */ - int i, j, k, n, jj, row; - struct elt_list *next_elt; - struct surface_comp *comp_ptr; - struct unknown *unknown_ptr; - struct master *master_ptr; - LDBLE coef; - - if (use.surface_ptr == NULL) return(OK); - if (surface_bsearch(use.surface_ptr->n_user, &n) == NULL) { - input_error++; - sprintf(error_string,"Surface %d not found.", use.surface_ptr->n_user); - error_msg(error_string, CONTINUE); - } - if (surface[n].related_phases == FALSE) return(OK); - for (i=0; i=0; j--) { - if (x[j]->type != SURFACE) continue; - if (x[j]->master[0] == surface[n].comps[i].master) break; - } - for (k=count_unknowns-1; k>=0; k--) { - if (x[k]->type != PP) continue; - if (x[k]->phase->name == surface[n].comps[i].phase_name) break; - } - if (j == -1 ) { - input_error++; - sprintf(error_string,"Did not find unknown for master surface species %s", surface[n].comps[i].master->s->name); - error_msg(error_string, CONTINUE); - } - if (j == -1 || k == -1) continue; - - next_elt = x[j]->master[0]->s->next_elt; - comp_ptr = x[j]->surface_comp; - - /* update grams == moles in this case */ - if(j < count_unknowns - 1 && x[j+1]->type == SURFACE_CB) { -#ifdef SKIP -/* Major error, can't use "use." because it changes every time - have to use only things allocated in prep.c Now put - grams into unknown structure. */ -/* - store_sum_deltas(&delta[k], &(use.surface_ptr->charge[comp_ptr->charge].grams), -1.0); - */ -#endif - store_sum_deltas(&delta[k], &(x[j+1]->related_moles), -1.0); - } - /* mole balance balance */ - for (jj = 0; next_elt[jj].elt != NULL; jj++) { - master_ptr = next_elt[jj].elt->primary; - if (master_ptr->in == FALSE) { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL) { - input_error++; - sprintf(error_string,"Did not find unknown for surface related to mineral %s", surface[n].comps[i].phase_name); - error_msg(error_string, STOP); - } - if (master_ptr->s->type == SURF) { - if (equal(x[j]->moles, x[k]->moles * next_elt[jj].coef * comp_ptr->phase_proportion, 1.e-8) == FALSE) { - input_error++; - sprintf(error_string,"Number of sites in surface %s (=%e) not consistent with moles of phase %s (=%e).\n%s", master_ptr->s->name, (double) x[j]->moles, comp_ptr->phase_name, (double) (x[k]->moles * next_elt[jj].coef * comp_ptr->phase_proportion), "\tHas equilibrium_phase assemblage been redefined?\n"); - error_msg(error_string, CONTINUE); - } - } - coef = next_elt[jj].coef; - if (master_ptr->s == s_hplus) { - row = mass_hydrogen_unknown->number; - unknown_ptr = mass_hydrogen_unknown; -#ifdef COMBINE -#ifndef COMBINE_CHARGE - coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o; -#else - coef = x[j]->master[0]->s->h - 2 * x[j]->master[0]->s->o - x[j]->master[0]->s->z; -#endif -#endif - } else if (master_ptr->s == s_h2o) { - row = mass_oxygen_unknown->number; - unknown_ptr = mass_oxygen_unknown; - } else { - row = master_ptr->unknown->number; - unknown_ptr = master_ptr->unknown; - } - store_jacob0(row, x[k]->number, coef * comp_ptr->phase_proportion); - store_sum_deltas(&delta[k], &unknown_ptr->delta, -coef * comp_ptr->phase_proportion); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int setup_related_surface (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for surface assemblage in unknown structure - */ - int i, k; - struct surface_comp *comp_ptr; - - if (use.surface_ptr == NULL) return(OK); - if (use.surface_ptr->related_phases == FALSE) return(OK); - - for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE && x[i]->surface_comp->phase_name != NULL) { - for (k=count_unknowns-1; k>=0; k--) { - if (x[k]->type != PP) continue; - if (x[k]->phase->name == x[i]->surface_comp->phase_name) break; - } - if (k == -1) continue; - - comp_ptr = x[i]->surface_comp; - x[i]->phase_unknown = x[k]; -/* !!!!! */ - x[i]->moles = x[k]->moles * comp_ptr->phase_proportion; - - } else if (x[i]->type == SURFACE_CB && x[i-1]->surface_comp->phase_name != NULL) { - for (k=count_unknowns-1; k>=0; k--) { - if (x[k]->type != PP) continue; - if (x[k]->phase->name == x[i]->surface_comp->phase_name) break; - } - if (k == -1) continue; - - comp_ptr = x[i]->surface_comp; - x[i]->phase_unknown = x[k]; -/* !!!! Added for security, not checked... */ - x[i]->related_moles = x[k]->moles * comp_ptr->phase_proportion; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int change_hydrogen_in_elt_list(LDBLE charge) -/* ---------------------------------------------------------------------- */ -{ - int j; - int found_h, found_o; - LDBLE coef_h, coef_o, coef; - found_h = -1; - found_o = -1; - coef_h = 0.0; - coef_o = 0.0; - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - for (j = 0; j < count_elts; j++) { - if (strcmp(elt_list[j].elt->name,"H") == 0) { - found_h = j; - coef_h = elt_list[j].coef; - } else if (strcmp(elt_list[j].elt->name,"O") == 0) { - found_o = j; - coef_o = elt_list[j].coef; - } - } - coef = coef_h-2*coef_o - charge; - if (found_h < 0 && found_o < 0) return(OK); - if (found_h >= 0 && found_o < 0) return(OK); - if (found_h < 0 && found_o >= 0) { - elt_list[count_elts].elt = s_hplus->primary->elt; - elt_list[count_elts].coef = coef; - count_elts++; - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - return(OK); - } - elt_list[found_h].coef = coef; - return(OK); -} diff --git a/print.cpp b/print.cpp deleted file mode 100644 index 223c3e72..00000000 --- a/print.cpp +++ /dev/null @@ -1,2259 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -#define PITZER_EXTERNAL extern -#include "pitzer.h" -#include - -static char const svnid[] = "$Id: print.c 701 2005-12-22 15:20:59Z dlpark $"; - -static int print_alkalinity(void); -static int print_diffuse_layer(struct surface_charge *surface_charge_ptr); -static int print_eh(void); -static int print_irrev(void); -static int print_kinetics(void); -static int print_mix(void); -static int print_pp_assemblage(void); -static int print_s_s_assemblage(void); -static int print_saturation_indices(void); -static int print_totals(void); -static int print_using(void); -static int print_user_print(void); -static int punch_gas_phase(void); -static int punch_identifiers(void); -static int punch_kinetics(void); -static int punch_molalities(void); -static int punch_activities(void); -static int punch_pp_assemblage(void); -static int punch_s_s_assemblage(void); -static int punch_saturation_indices(void); -static int punch_totals(void); -static int punch_user_punch(void); - -#ifdef PHREEQ98 -static int punch_user_graph(void); -extern int colnr, rownr; -extern int graph_initial_solutions; -extern int prev_advection_step, prev_transport_step; /*, prev_reaction_step*/ -/* extern int shifts_as_points; */ -extern int chart_type; -extern int AddSeries; -extern int FirstCallToUSER_GRAPH; -#endif - -#if defined(SWIG_SHARED_OBJ) -extern void EndRow(void); -extern void AddSelectedOutput(const char* name, const char* format, va_list argptr); -#endif - -/* ---------------------------------------------------------------------- */ -int array_print(LDBLE *array_l, int row_count, int column_count, int max_column_count) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - if (svnid == NULL) fprintf(stderr," "); - - - for (i=0; i < row_count; i++) { - k = 0; - output_msg(OUTPUT_MESSAGE,"%d\n", i); - for (j=0; j < column_count; j++) { - if (k > 7) { - output_msg(OUTPUT_MESSAGE,"\n"); - k = 0; - } - output_msg(OUTPUT_MESSAGE,"%11.2e", (double) array_l[i*max_column_count + j]); - k++; - } - if (k != 0) { - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_all(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print each block of results in sequence to file output - * also print selected output to punch_file - * Each routine is controlled by a variable in structure print. - * print.all == FALSE will turn off all prints. - */ -/* - * Makes sorted list including all species for each valence state - */ - if (pr.all == FALSE) return(OK); - if(pr.surface == TRUE || - pr.exchange == TRUE || - pr.species == TRUE ) { - species_list_sort(); - } -/* - * Print results - */ - s_h2o->lm = s_h2o->la; - print_using(); - print_mix(); - print_irrev(); - print_kinetics(); - print_user_print(); - print_gas_phase(); - print_pp_assemblage(); - print_s_s_assemblage(); - print_surface(); - print_exchange(); - print_initial_solution_isotopes(); - print_isotope_ratios(); - print_isotope_alphas(); - print_totals(); - print_eh(); - print_species(); - print_alkalinity(); - print_saturation_indices(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_all(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - -#ifndef PHREEQ98 /* if not PHREEQ98 use the standard declaration */ - if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) return(OK); -/* - * Punch results - */ - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); - } else if (use.kinetics_in != FALSE) { - use.kinetics_ptr = kinetics_bsearch(-2, &i); - } -#else /* if PHREEQ98 execute punch_user_graph first, that is, before punch.in and pr.punch is checked */ - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); - } else if (use.kinetics_in != FALSE) { - use.kinetics_ptr = kinetics_bsearch(-2, &i); - } - if (pr.user_graph == TRUE) punch_user_graph(); - - if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) return(OK); -#endif - punch_identifiers(); - punch_totals(); - punch_molalities(); - punch_activities(); - punch_pp_assemblage(); - punch_saturation_indices(); - punch_gas_phase(); - punch_kinetics(); - punch_s_s_assemblage(); - punch_isotopes(); - punch_calculate_values(); - punch_user_punch(); -/* - * new line for punch_file - */ - fpunchf(NULL, "\n"); - -#if defined(SWIG_SHARED_OBJ) - EndRow(); -#endif - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_diffuse_layer(struct surface_charge *surface_charge_ptr1) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints total moles of each element in diffuse layer - * Remove comment to print total moles of each species - */ - int i, j, count_g; - LDBLE mass_water_surface; - LDBLE molality, moles_excess, moles_surface; - - if (use.surface_ptr == NULL) return(OK); -/* - * Find position of component in surface charge data - */ - i = 0; - for (j = 0; j < count_unknowns; j++) { - if (x[j]->type != SURFACE_CB) continue; - if (x[j]->surface_charge == surface_charge_ptr1) { - break; - } - i++; - } - if (j >= count_unknowns) { - sprintf(error_string, "In print_diffuse_layer: component not found, %s.", surface_charge_ptr1->name); - error_msg(error_string, STOP); - } -/* - * Loop through all surface components, calculate each H2O surface (diffuse layer), - * H2O aq, and H2O bulk (diffuse layers plus aqueous). - */ - - output_msg(OUTPUT_MESSAGE,"\tKg water in diffuse layer: %e\n", - (double) surface_charge_ptr1->mass_water); - - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE,"\n\t\tDistribution of species in diffuse layer\n\n"); - output_msg(OUTPUT_MESSAGE,"\n\tSpecies \t Moles \tMoles excess\t g\n"); - } - mass_water_surface = surface_charge_ptr1->mass_water; - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) { - if (s_x[j]->type > HPLUS) continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; -#ifdef SKIP - moles_excess = mass_water_bulk_x * -/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ - surface_charge_ptr1->g[count_g].g * molality; -#endif - moles_excess = mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; - moles_surface = mass_water_surface * molality + moles_excess; - if (debug_diffuse_layer == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", s_x[j]->name, - moles_surface, moles_excess, s_x[j]->diff_layer[i].charge->g[count_g].g); - } -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } -/* - strcpy(token, s_h2o->name); - ptr = &(token[0]); - get_elts_in_species (&ptr, mass_water_surface / gfw_water); - */ - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } -/* - * Print totals - */ - if (use.surface_ptr->donnan == FALSE) { - output_msg(OUTPUT_MESSAGE,"\n\tTotal moles in diffuse layer (excluding water)\n\n"); - } else { - output_msg(OUTPUT_MESSAGE,"\n\tTotal moles in diffuse layer (excluding water), Donnan calculation \n\n"); - } - output_msg(OUTPUT_MESSAGE,"\tElement \t Moles\n"); - for ( j=0; j < count_elts; j++ ) { - output_msg(OUTPUT_MESSAGE, "\t%-14s\t%12.4e\n", - elt_list[j].elt->name, - (double) elt_list[j].coef); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_eh(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints eh calculated from redox couples - * Only calculates eh if two redox states of an element have mass balance - * equations. - */ - int i, j, k, first; - LDBLE pe, eh; - struct master *master_ptr0, *master_ptr1; - char token[MAX_LENGTH]; - - if (pr.eh == FALSE || pr.all == FALSE) return(OK); - - tk_x=tc_x+273.15; - - first = TRUE; - for (i=0; i < count_master; i++) { - if (master[i]->in != TRUE ) continue; - if (master[i]->primary == TRUE) continue; -/* - * Secondary master species has mass balance equation - */ - master_ptr0 = master[i]->elt->primary; - for (k = i + 1; k < count_master; k++) { - if (master[k]->in != TRUE) continue; - master_ptr1 = master[k]->elt->primary; - if ( master_ptr1 != master_ptr0) break; -/* - * Another secondary master species of same element has mass balance equation - * Rewrite equations to calculate pe - */ - rewrite_master_to_secondary ( master[k], master[i] ); - trxn_swap ("e-"); -/* debug - trxn_print(); - */ -/* - * Calculate pe, eh - */ - pe = -k_calc(trxn.logk, tk_x); - for (j = 1; j < count_trxn; j++) { - pe -= trxn.token[j].s->la * trxn.token[j].coef; - } - eh = ( (LOG_10 * R_KJ_DEG_MOL * tk_x) / F_KJ_V_EQ ) * pe; -/* - * Print heading - */ - if (first == TRUE) { - print_centered("Redox couples"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s\n\n","Redox couple","pe","Eh (volts)"); - first = FALSE; - } -/* - * Print result - */ - strcpy(token,master[i]->elt->name); - strcat(token,"/"); - strcat(token,master[k]->elt->name); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.4f%12.4f\n", token, (double) pe, (double) eh); - } - } - if (first == FALSE) output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_exchange(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print moles of each exchange species - */ - int i; - struct exchange *exchange_ptr; - char *name, *name1; - struct master *master_ptr; - LDBLE dum, dum2; -/* - * Print exchange data - */ - exchange_ptr = use.exchange_ptr; - if (exchange_ptr == NULL || pr.exchange == FALSE || pr.all == FALSE) return(OK); - - if (state >= REACTION) { - print_centered("Exchange composition"); - } -/* - * Print list of species - */ - - s_h2o->lm = s_h2o->la; - name = s_hplus->secondary->elt->name; - for (i=0; i < count_species_list; i++) { -/* - * Get name of master species - */ - if (species_list[i].s->type != EX) continue; - if (species_list[i].master_s->secondary != NULL ) { - master_ptr = species_list[i].master_s->secondary; - name1=species_list[i].master_s->secondary->elt->name; - } else { - master_ptr = species_list[i].master_s->primary; - name1=species_list[i].master_s->primary->elt->name; - } -/* - * Check if new master species, print total molality - */ - if (name1 != name) { - name = name1; - output_msg(OUTPUT_MESSAGE,"%-14s%12.3e mol", name, (double) master_ptr->unknown->moles); - if (master_ptr->unknown->exch_comp->phase_name != NULL) { - output_msg(OUTPUT_MESSAGE, "\t[%g (mol %s)/(mol %s)]", - (double) master_ptr->unknown->exch_comp->phase_proportion, - master_ptr->unknown->exch_comp->formula, - master_ptr->unknown->exch_comp->phase_name); - } else - if (master_ptr->unknown->exch_comp->rate_name != NULL) { - output_msg(OUTPUT_MESSAGE, "\t[%g (mol %s)/(mol kinetic reactant %s)]", - (double) master_ptr->unknown->exch_comp->phase_proportion, - master_ptr->unknown->exch_comp->formula, - master_ptr->unknown->exch_comp->rate_name); - } - output_msg(OUTPUT_MESSAGE, "\n\n"); - /* Heading for species */ - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%10s\n"," "," ","Equiv- ", - "Equivalent","Log "); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%10s\n\n","Species","Moles ","alents ", - "Fraction", "Gamma"); - } -/* - * Print species data - */ -/* !!!!! */ - if (master_ptr->total > 1.0e-10) { - if (species_list[i].s->equiv != 0.0) { - dum = fabs(species_list[i].s->equiv)/master_ptr->total; - } else { - if (species_list[i].master_s->z == 0) { - dum = 1 / master_ptr->total; - } else { - dum = 1; - } - } - if (species_list[i].master_s->z != 0.0) { - dum2 = fabs(species_list[i].master_s->z); - } else { - dum2 =1; - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%12.3e%10.3f\n", - species_list[i].s->name, - (double) species_list[i].s->moles, - (double) (species_list[i].s->moles * dum2 * species_list[i].s->equiv), - (double) (species_list[i].s->moles * dum /* / dum2 */), - (double) (species_list[i].s->lg - log10(dum)) ); - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints gas phase composition if present - */ - int j; - LDBLE lp, moles, initial_moles, delta_moles; - struct rxn_token *rxn_ptr; - - if (pr.gas_phase == FALSE || pr.all == FALSE) return(OK); - if (use.gas_phase_ptr == NULL) return(OK); - if (use.gas_phase_ptr->type == PRESSURE) { - if (gas_unknown == NULL) return(OK); - if (gas_unknown->moles < 1e-12) return(OK); - use.gas_phase_ptr->total_moles = gas_unknown->moles; - use.gas_phase_ptr->volume = use.gas_phase_ptr->total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; - } -/* - * Print heading - */ - print_centered("Gas phase"); - output_msg(OUTPUT_MESSAGE,"\n"); - output_msg(OUTPUT_MESSAGE, "Total pressure: %8.4f atmospheres\n", (double) use.gas_phase_ptr->total_p); - output_msg(OUTPUT_MESSAGE, " Gas volume: %10.2e liters\n", (double) use.gas_phase_ptr->volume); - - output_msg(OUTPUT_MESSAGE, "\n%66s\n%75s\n", "Moles in gas", "----------------------------------"); - output_msg(OUTPUT_MESSAGE,"%-15s%12s%12s%12s%12s%12s\n","Component","log P", "P", "Initial", "Final", - "Delta"); - - for( j = 0; j < use.gas_phase_ptr->count_comps; j++) { -/* - * Calculate partial pressure - */ - if (use.gas_phase_ptr->comps[j].phase->in == TRUE) { - lp=-use.gas_phase_ptr->comps[j].phase->lk; - for (rxn_ptr = use.gas_phase_ptr->comps[j].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - moles = use.gas_phase_ptr->comps[j].phase->moles_x; - } else { - lp = -99.99; - moles = 0; - use.gas_phase_ptr->comps[j].phase->p_soln_x = 0; - } -/* - * Print gas composition - */ - if (state != TRANSPORT && state != PHAST) { - initial_moles = use.gas_phase_ptr->comps[j].moles; - delta_moles = use.gas_phase_ptr->comps[j].phase->moles_x - - use.gas_phase_ptr->comps[j].moles; - } else { - initial_moles = use.gas_phase_ptr->comps[j].initial_moles; - delta_moles = use.gas_phase_ptr->comps[j].initial_moles - - use.gas_phase_ptr->comps[j].moles; - } - if (moles <= MIN_TOTAL) moles = 0.0; - if (fabs(delta_moles) <= MIN_TOTAL) delta_moles = 0.0; - output_msg(OUTPUT_MESSAGE,"%-15s%12.2f%12.3e%12.3e%12.3e%12.3e\n", - use.gas_phase_ptr->comps[j].phase->name, - (double) lp, - (double) use.gas_phase_ptr->comps[j].phase->p_soln_x, - (double) initial_moles, - (double) moles, - (double) delta_moles); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_s_s_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - /* - * Prints solid solution composition if present - */ - int i, j; - LDBLE delta_moles; - LDBLE nb, nc, xb, xb1, xb2, xb1moles, xb2moles; - struct s_s *s_s_ptr; - - if (pr.s_s_assemblage == FALSE || pr.all == FALSE) return(OK); - if (use.s_s_assemblage_ptr == NULL) return(OK); - /* - * Print heading - */ - print_centered("Solid solutions"); - output_msg(OUTPUT_MESSAGE,"\n"); - output_msg(OUTPUT_MESSAGE, "\t%-15s %15s %11s %11s %11s\n", "Solid solution", "Component", "Moles", - "Delta moles", "Mole fract"); - /* - * Print solid solutions - */ - for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { - /* solid solution name, moles */ - output_msg(OUTPUT_MESSAGE,"\t%-15s %15s %11.2e\n", use.s_s_assemblage_ptr->s_s[j].name," ", - (double) use.s_s_assemblage_ptr->s_s[j].total_moles); - /* component name, moles, delta moles, mole fraction */ - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (state != TRANSPORT && state != PHAST) { - delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].delta; - } else { - delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].init_moles; - } - output_msg(OUTPUT_MESSAGE, "\t%15s %15s %11.2e %11.2e %11.2e\n", " ", - use.s_s_assemblage_ptr->s_s[j].comps[i].name, - (double) use.s_s_assemblage_ptr->s_s[j].comps[i].moles, - (double) delta_moles, - (double) (use.s_s_assemblage_ptr->s_s[j].comps[i].moles/ - use.s_s_assemblage_ptr->s_s[j].total_moles)); - } - s_s_ptr = &(use.s_s_assemblage_ptr->s_s[j]); - if(s_s_ptr->miscibility == TRUE) { - nc = s_s_ptr->comps[0].moles; - nb = s_s_ptr->comps[1].moles; - xb = nb/(nb + nc); - xb1 = s_s_ptr->xb1; - xb2 = s_s_ptr->xb2; - - if (xb > xb1 && xb < xb2) { - xb2moles = (xb1 - 1)/xb1*nb + nc; - xb2moles = xb2moles / ((xb1 - 1)/xb1*xb2 + (1 - xb2)); - xb1moles = (nb - xb2moles*xb2)/xb1; - output_msg(OUTPUT_MESSAGE, "\n\t%15s Solid solution is in miscibility gap\n", " "); - output_msg(OUTPUT_MESSAGE, "\t%15s End members in pct of %s\n\n", " ", s_s_ptr->comps[1].name); - output_msg(OUTPUT_MESSAGE, "\t%15s %11g pct %11.2e\n", " ", (double) xb1, (double) xb1moles); - output_msg(OUTPUT_MESSAGE, "\t%15s %11g pct %11.2e\n", " ", (double) xb2, (double) xb2moles); - } - } - } else { - /* solid solution name, moles */ - output_msg(OUTPUT_MESSAGE,"\t%-15s %15s %11.2e\n", use.s_s_assemblage_ptr->s_s[j].name," ", - (double) 0.0); - /* component name, moles, delta moles, mole fraction */ - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (state != TRANSPORT && state != PHAST) { - delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].initial_moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].delta; - } else { - delta_moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles - - use.s_s_assemblage_ptr->s_s[j].comps[i].init_moles; - } - output_msg(OUTPUT_MESSAGE, "\t%15s %15s %11.2e %11.2e %11.2e\n", " ", - use.s_s_assemblage_ptr->s_s[j].comps[i].name, - (double) 0, - (double) delta_moles, - (double) 0 ); - } - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int print_irrev(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints irreversible reaction as defined and as - * relative moles of each element and total amount - * of reaction - */ - int i; - struct irrev *irrev_ptr; - - if (pr.use == FALSE || pr.all == FALSE) return(OK); - if (state < REACTION || use.irrev_in == FALSE) return(OK); - if (state == TRANSPORT && transport_step == 0) return(OK); - irrev_ptr = use.irrev_ptr; -/* - * Print amount of reaction - */ - output_msg(OUTPUT_MESSAGE,"Reaction %d.\t%s\n\n", use.n_irrev_user, irrev_ptr->description); - output_msg(OUTPUT_MESSAGE,"\t%11.3e moles of the following reaction have been added:\n\n", (double) step_x); -/* - * Print reaction - */ - output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", " ", "Relative"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n\n", "Reactant", "moles"); - for (i = 0; i < irrev_ptr->count_list; i++) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%10.2f\n", irrev_ptr->list[i].name, (double) irrev_ptr->list[i].coef); - } - output_msg(OUTPUT_MESSAGE,"\n"); -/* - * Debug - */ - - output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", " ", "Relative"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%10s\n", "Element", "moles"); - for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%10.2f\n", irrev_ptr->elts[i].elt->name, (double) irrev_ptr->elts[i].coef); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int print_kinetics(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints kinetic reaction, - * should be called only on final kinetic step - */ - int i, j; - LDBLE sim_time; - struct kinetics *kinetics_ptr; - if (pr.kinetics == FALSE || pr.all == FALSE) return(OK); - if (state < REACTION) return(OK); - kinetics_ptr = NULL; - if (use.kinetics_in == TRUE) { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); - } else { - kinetics_ptr = kinetics_bsearch(-2, &i); - } - } - if (kinetics_ptr == NULL) return(OK); -/* - * determine time step - */ - if (state == TRANSPORT || state == PHAST) { - kin_time_x = timest; - } else if (state == ADVECTION) { - kin_time_x =advection_kin_time; - } - sim_time = 0.; - if (incremental_reactions == TRUE) { - if (kinetics_ptr->count_steps > 0) { - for (i = 0; i < reaction_step; i++) { - if (i < kinetics_ptr->count_steps) { - sim_time += kinetics_ptr->steps[i]; - } else { - sim_time += kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } - } - } else if (kinetics_ptr->count_steps < 0) { - if (reaction_step > -kinetics_ptr->count_steps) { - sim_time = kinetics_ptr->steps[0]; - } else { - sim_time = reaction_step * kinetics_ptr->steps[0] / ( (LDBLE) (-kinetics_ptr->count_steps)); - } - } - } -/* - * Print amount of reaction - */ - if (phast == FALSE) { - output_msg(OUTPUT_MESSAGE,"Kinetics %d.\t%s\n\n", use.n_kinetics_user, kinetics_ptr->description); - } else { - output_msg(OUTPUT_MESSAGE,"Kinetics.\n\n"); - } -/* - * Print reaction - */ - if (state == TRANSPORT) { - output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n",(double) (initial_total_time + transport_step * timest)); - output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); - } else if (state == ADVECTION) { - output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n",(double) (initial_total_time + advection_step * advection_kin_time)); - output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); - } else if (state == PHAST) { - output_msg(OUTPUT_MESSAGE, "\tTime: %g seconds\n", (double) rate_sim_time_end); - output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); - } else if (state == REACTION) { - if (incremental_reactions == FALSE) { - output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds\n\n", (double) kin_time_x); - } else { - output_msg(OUTPUT_MESSAGE,"\tTime step: %g seconds (Incremented time: %g seconds)\n\n", (double) kin_time_x, (double) sim_time); - } - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s %-15s%12s\n\n", "Rate name", "Delta Moles","Total Moles","Reactant","Coefficient"); - for (i = 0; i < kinetics_ptr->count_comps; i++) { - if (state != TRANSPORT && state != PHAST) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", - kinetics_ptr->comps[i].rate_name, - (double) -kinetics_ptr->comps[i].moles, - (double) kinetics_ptr->comps[i].m); - } else { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", - kinetics_ptr->comps[i].rate_name, - (double) (kinetics_ptr->comps[i].m - kinetics_ptr->comps[i].initial_moles), - (double) kinetics_ptr->comps[i].m); - } - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { - if (j == 0) { - output_msg(OUTPUT_MESSAGE," %-15s%12g\n", kinetics_ptr->comps[i].list[j].name, - (double) kinetics_ptr->comps[i].list[j].coef); - } else { - output_msg(OUTPUT_MESSAGE,"\t%39s %-15s%12g\n"," ", kinetics_ptr->comps[i].list[j].name, - (double) kinetics_ptr->comps[i].list[j].coef); - } - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_master_reactions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Debugging print routine to test primary and secondary reactions - */ - int i; - struct rxn_token *next_token; - - for ( i=0; i < count_master; i++) { - output_msg(OUTPUT_MESSAGE,"%s\t%s\n\tPrimary reaction\n",master[i]->elt->name, master[i]->s->name); - next_token=master[i]->rxn_primary->token; - for (; next_token->s != NULL; next_token++) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); - } - output_msg(OUTPUT_MESSAGE,"\n\tSecondary reaction:\n"); - if (master[i]->rxn_secondary != NULL) { - next_token=master[i]->rxn_secondary->token; - for (; next_token->s != NULL; next_token++) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); - } - } - output_msg(OUTPUT_MESSAGE,"\n\tRedox reaction:\n"); - if (*(master[i]->pe_rxn) != NULL) { - next_token=(*(master[i]->pe_rxn))->token; - for (; next_token->s != NULL; next_token++) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int print_mix(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints definition of mixing, solution number and multiplier - */ - int i, n; - struct mix *mix_ptr; - struct solution *solution_ptr; - - if (pr.use == FALSE || pr.all == FALSE) return(OK); - if (use.mix_in == FALSE || state < REACTION) return(OK); - if (state == TRANSPORT) { - mix_ptr = mix_bsearch(use.n_mix_user, &i); - } else { - mix_ptr = mix_bsearch(use.n_mix_user_orig, &i); - } - if (mix_ptr == NULL) { - mix_ptr = use.mix_ptr; - } -/* - * Print mixture data - */ - if (mix_ptr == NULL) { - return(OK); - - } - if (state == TRANSPORT) { - output_msg(OUTPUT_MESSAGE,"Mixture %d.\t%s\n\n", use.n_mix_user, mix_ptr->description); - } else { - output_msg(OUTPUT_MESSAGE,"Mixture %d.\t%s\n\n", mix_ptr->n_user, mix_ptr->description); - } - for (i = 0; i < mix_ptr->count_comps; i++) { - solution_ptr = solution_bsearch (mix_ptr->comps[i].n_solution, &n, TRUE); - if (solution_ptr == NULL) { - input_error++; - return(ERROR); - } - output_msg(OUTPUT_MESSAGE,"\t%11.3e Solution %d\t%-55s\n", (double) mix_ptr->comps[i].fraction, - mix_ptr->comps[i].n_solution, solution[n]->description); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_reaction(struct reaction *rxn_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Debugging print of individual chemical reactions for - * species or phases - */ - int j; - struct rxn_token *next_token; - - if (pr.use == FALSE || pr.all == FALSE) return(OK); - - output_msg(OUTPUT_MESSAGE,"%s\t\n",rxn_ptr->token[0].s->name); - output_msg(OUTPUT_MESSAGE,"\n\tlog k:\n"); - for (j=0;j<7;j++) { - output_msg(OUTPUT_MESSAGE,"\t%f",(double) rxn_ptr->logk[j]); - } - output_msg(OUTPUT_MESSAGE,"\n\nReaction:\n"); - for (next_token=rxn_ptr->token; next_token->s != NULL; next_token++) { - output_msg(OUTPUT_MESSAGE,"\t\t%s\t%f\n",next_token->s->name, (double) next_token->coef); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_saturation_indices(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints saturation indices of all applicable pure_phases - */ - int i; - LDBLE si, iap; - LDBLE lk; - LDBLE la_eminus; - struct rxn_token *rxn_ptr; - - if (pr.saturation_indices == FALSE || pr.all == FALSE) return(OK); - if (state == INITIAL_SOLUTION) { - iap = 0; - for (rxn_ptr = pe_x[default_pe_x].rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->coef*rxn_ptr->s->la; - /* fprintf(output,"\t%s\t%f\t%f\n", rxn_ptr->s->name, rxn_ptr->coef, rxn_ptr->s->la ); */ - } - lk = k_calc(pe_x[default_pe_x].rxn->logk, tk_x); - la_eminus = lk + iap; - /* fprintf(output,"\t%s\t%f\n", "pe", si ); */ - } else { - la_eminus = s_eminus->la; - } -/* - * Print heading - */ - print_centered("Saturation indices"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%7s%8s%8s\n\n","Phase","SI","log IAP", "log KT"); - - for (i=0; i < count_phases; i++) { - if (phases[i]->in == FALSE || phases[i]->type != SOLID) continue; -/* - * Print saturation index - */ -#ifdef SKIP - iap = 0.0; - for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->s->la * rxn_ptr->coef; - /* fprintf(output,"\t%s\t%f\t%e\n", rxn_ptr->s->name, rxn_ptr->s->la, rxn_ptr->coef); */ - } - si=-phases[i]->lk + iap; - output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, (double) si, (double) iap, (double) phases[i]->lk, phases[i]->formula); - si1 = si; -#endif - - /* pe_value_x = pe_x[default_pe_x].rxn;*/ - lk = k_calc(phases[i]->rxn->logk, tk_x); - iap = 0.0; - for (rxn_ptr = phases[i]->rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - /* iap += rxn_ptr->s->la * rxn_ptr->coef; */ - if (rxn_ptr->s != s_eminus) { - iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; - } else { - iap += la_eminus * rxn_ptr->coef; - } - /* output_msg(OUTPUT_MESSAGE,"\t%s\t%f\t%e\t%e\t%e\n", rxn_ptr->s->name, rxn_ptr->s->la, rxn_ptr->coef, rxn_ptr->s->lm, rxn_ptr->s->lg ); */ - } - si=-lk + iap; - output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f %s\n",phases[i]->name, (double) si, (double) iap, (double) lk, phases[i]->formula); - -#ifdef SKIP - if (fabs(si1-si) > convergence_tolerance) { - sprintf(error_string, "SI1 != SI, %s SI1 %e, SI %e, diff %e\n", phases[i]->name, si1, si, si1 - si); - error_msg(error_string, CONTINUE); - } -#endif - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_pp_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints saturation indices and masses of pure_phases in pp_assemblage - */ - int j, k; - LDBLE si, iap, lk; - char token[MAX_LENGTH]; - struct rxn_token *rxn_ptr; - struct phase *phase_ptr; - - if (pr.pp_assemblage == FALSE || pr.all == FALSE) return(OK); - if (pure_phase_unknown == NULL) return(OK); -/* - * Print heading - */ - print_centered("Phase assemblage"); - output_msg(OUTPUT_MESSAGE, "%74s\n", "Moles in assemblage"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%7s%8s%8s","Phase","SI","log IAP", "log KT"); - output_msg(OUTPUT_MESSAGE,"%12s%12s%12s", " Initial", " Final", " Delta"); - output_msg(OUTPUT_MESSAGE,"\n\n"); - - for( j = 0; j < count_unknowns; j++) { - if (x[j]->type != PP) continue; -/* - * Print saturation index - */ - iap = 0.0; - phase_ptr=x[j]->phase; - if (x[j]->phase->rxn_x == NULL || phase_ptr->in == FALSE) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%23s", x[j]->phase->name, "Element not present."); - } else { - phase_ptr=x[j]->phase; - lk = k_calc(phase_ptr->rxn->logk, tk_x); - for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - if (rxn_ptr->s != s_eminus) { - iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; - } else { - iap += s_eminus->la * rxn_ptr->coef; - } - } - si=-lk + iap; - /* - for (rxn_ptr = x[j]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->s->la * rxn_ptr->coef; - } - si = -x[j]->phase->lk + iap; - output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) x[j]->phase->lk); - */ - output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) lk); - } -/* - * Print pure phase assemblage data - */ - if (x[j]->moles < 0.0) x[j]->moles = 0.0; - if (state != TRANSPORT && state != PHAST) { - sprintf(token, " %11.3e %11.3e %11.3e", - (double) (x[j]->pure_phase->moles + x[j]->pure_phase->delta), - (double) x[j]->moles, - (double) (x[j]->moles - x[j]->pure_phase->moles - x[j]->pure_phase->delta)); - } else { - sprintf(token, " %11.3e %11.3e %11.3e", - (double) x[j]->pure_phase->initial_moles, - (double) x[j]->moles, - (double) (x[j]->moles - x[j]->pure_phase->initial_moles)); - } - if (x[j]->moles <= 0.0) { - for (k=0; k < 11; k++) { - token[12+k] = ' '; - } - } - if (x[j]->pure_phase->add_formula == NULL) { - output_msg(OUTPUT_MESSAGE, "%36s\n", token); - } else { - output_msg(OUTPUT_MESSAGE,"\n\t\t%-15s%-15s%36s\n",x[j]->pure_phase->add_formula," is reactant", token); - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_species(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints description of solution, uses array species_list for - * order of aqueous species. - */ - int i; - char *name, *name1; - struct master *master_ptr; - LDBLE min; - LDBLE lm; - - if (pr.species == FALSE || pr.all == FALSE) return(OK); - min = -1000; - print_centered("Distribution of species"); -/* - * Heading for species - */ - if (pitzer_model == TRUE) { - if (ICON == TRUE) { - output_msg(OUTPUT_MESSAGE,"%67s%11s\n","MacInnes","MacInnes"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," ","MacInnes","Log ","Log ","Log "); - } else { - output_msg(OUTPUT_MESSAGE,"%67s%11s\n","Unscaled","Unscaled"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," ","Unscaled","Log ","Log ","Log "); - } - } else { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n"," "," "," ","Log ","Log ","Log "); - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s%10s%10s\n\n","Species","Molality","Activity", - "Molality","Activity","Gamma"); -/* - * Print list of species - */ - s_h2o->lm = s_h2o->la; - name = s_hplus->secondary->elt->name; - for (i=0; i < count_species_list; i++) { -/* - * Get name of master species - */ - if (species_list[i].s->type == EX) continue; - if (species_list[i].s->type == SURF) continue; - if (species_list[i].master_s->secondary != NULL ) { - master_ptr = species_list[i].master_s->secondary; - name1=species_list[i].master_s->secondary->elt->name; - } else { - master_ptr = species_list[i].master_s->primary; - name1=species_list[i].master_s->primary->elt->name; - } -/* - * Check if new master species, print total molality - */ - if (name1 != name) { - name = name1; - output_msg(OUTPUT_MESSAGE,"%-14s%12.3e\n",name, (double) (master_ptr->total/mass_water_aq_x)); - min = censor*master_ptr->total/mass_water_aq_x; - if (min > 0) { - min = log10(min); - } else { - min = -1000.; - } - } -/* - * Print species data - */ - if (species_list[i].s->lm > min) { - if (species_list[i].s == s_h2o) { - lm = log10(s_h2o->moles / mass_water_aq_x); - } else { - lm = species_list[i].s->lm; - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%10.3f%10.3f%10.3f\n", - species_list[i].s->name, - (double) ((species_list[i].s->moles)/mass_water_aq_x), - (double) under(species_list[i].s->lm + species_list[i].s->lg), - (double) lm, - (double) (species_list[i].s->lm+species_list[i].s->lg), - (double) species_list[i].s->lg ); - } - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_surface(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints description of surface, including charge and potential, - * grams and specific area, moles of each species on surface sites, - * and description of diffuse layer if applicable. - */ - int i, j, k; - struct surface *surface_ptr; - char name[MAX_LENGTH], token[MAX_LENGTH]; - struct master *master_ptr; - LDBLE molfrac, charge; - char *ptr; -/* - * Print surface speciation - */ - surface_ptr = use.surface_ptr; - if (surface_ptr == NULL || pr.surface == FALSE || pr.all == FALSE) return(OK); - - if (state >= REACTION) { - print_centered("Surface composition"); - } -/* - * Print list of species - */ - - s_h2o->lm = s_h2o->la; - for (j =0; j < count_unknowns; j++) { - if (use.surface_ptr->edl == TRUE) { - if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace ("_psi", "", name); - } else { - if (x[j]->type != SURFACE) continue; - strcpy(token, x[j]->master[0]->elt->name); - replace ("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); - } - output_msg(OUTPUT_MESSAGE,"%-14s\n",name); -/* - * Description of surface - */ - if (diffuse_layer_x == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t%11.3e Surface + diffuse layer charge, eq\n", (double) x[j]->f ); - } - if (use.surface_ptr->edl == TRUE && diffuse_layer_x == FALSE) { - charge = x[j]->f; - } else { - charge = calc_surface_charge(name); - } - output_msg(OUTPUT_MESSAGE,"\t%11.3e Surface charge, eq\n", (double) charge); - if (x[j]->type == SURFACE_CB) { - if ((x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) > 0) { - output_msg(OUTPUT_MESSAGE,"\t%11.3e sigma, C/m**2\n", - (double) (charge * F_C_MOL / - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams))); - } else { - output_msg(OUTPUT_MESSAGE,"\tundefined sigma, C/m**2\n"); - } - output_msg(OUTPUT_MESSAGE,"\t%11.3e psi, V\n", - (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * - tk_x * LOG_10 / F_KJ_V_EQ)); - output_msg(OUTPUT_MESSAGE,"\t%11.3e -F*psi/RT\n", - (double) (x[j]->master[0]->s->la * (-2) * LOG_10)); - output_msg(OUTPUT_MESSAGE,"\t%11.3e exp(-F*psi/RT)\n", - exp(x[j]->master[0]->s->la * (-2) * LOG_10)); - if (x[j]->surface_comp->phase_name != NULL) { - output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->phase_name); - output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->phase_name); - } else if (x[j]->surface_comp->rate_name != NULL) { - output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->rate_name); - output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->rate_name); - } else { - output_msg(OUTPUT_MESSAGE,"\t%11.3e specific area, m**2/g\n", - (double) x[j]->surface_charge->specific_area); - output_msg(OUTPUT_MESSAGE,"\t%11.3e m**2 for %11.3e g\n\n", - (double) (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams), - (double) x[j]->surface_charge->grams); - } - if (diffuse_layer_x == TRUE) print_diffuse_layer(x[j]->surface_charge); - output_msg(OUTPUT_MESSAGE,"\n"); -/* - * Heading for species - */ - for (k = j - 1; k < count_unknowns; k++) { - if (x[k]->type != SURFACE) continue; - if (x[j] != x[k]->potential_unknown) continue; - master_ptr = x[k]->master[0]; - output_msg(OUTPUT_MESSAGE,"%-14s\n",x[k]->master[0]->elt->name); - output_msg(OUTPUT_MESSAGE,"\t%11.3e moles", (double) x[k]->moles); - if (x[k]->surface_comp->phase_name != NULL) { - output_msg(OUTPUT_MESSAGE,"\t[%g mol/(mol %s)]\n", (double) x[k]->surface_comp->phase_proportion, x[k]->surface_comp->phase_name); - } else - if (x[k]->surface_comp->rate_name != NULL) { - output_msg(OUTPUT_MESSAGE,"\t[%g mol/(mol kinetic reactant %s)]\n", (double) x[k]->surface_comp->phase_proportion, x[k]->surface_comp->rate_name); - } else { - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n"," "," ","Mole", - " ", "Log"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n\n","Species", - "Moles", "Fraction", "Molality", "Molality"); - for (i=0; i < count_species_list; i++) { - if (species_list[i].master_s != master_ptr->s) continue; -/* - * Print species data - */ - if (x[k]->moles >= MIN_RELATED_SURFACE) { - molfrac = (LDBLE) (species_list[i].s->moles) / x[k]->moles * species_list[i].s->equiv; - } else { - molfrac = 0.0; - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3f%12.3e%12.3f\n", - species_list[i].s->name, - (double) species_list[i].s->moles, - (double) molfrac, - (double) (species_list[i].s->moles/mass_water_aq_x), - log10(species_list[i].s->moles/mass_water_aq_x)); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - } else { - k = j; - master_ptr = x[k]->master[0]; - output_msg(OUTPUT_MESSAGE,"%-14s\n",x[k]->master[0]->elt->name); - output_msg(OUTPUT_MESSAGE,"\t%11.3e moles\n", (double) x[k]->moles); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n"," "," ","Mole", - " ", "Log"); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%12s%12s\n\n","Species", - "Moles", "Fraction", "Molality", "Molality"); - for (i=0; i < count_species_list; i++) { - if (species_list[i].master_s != master_ptr->s) continue; -/* - * Print species data - */ - if (x[k]->moles >= MIN_RELATED_SURFACE) { - molfrac = (double) (species_list[i].s->moles) / x[k]->moles * species_list[i].s->equiv; - } else { - molfrac = 0.0; - } - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3f%12.3e%12.3f\n", - species_list[i].s->name, - (double) species_list[i].s->moles, - (double) molfrac, - (double) (species_list[i].s->moles/mass_water_aq_x), - log10(species_list[i].s->moles/mass_water_aq_x)); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_totals(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print total concentrations of elements, molality and moles. - */ - int i, pure_water; - - if (pr.totals == FALSE || pr.all == FALSE) return(OK); - print_centered("Solution composition"); - pure_water = TRUE; - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s\n\n","Elements","Molality","Moles"); - for (i = 0; i < count_unknowns; i++) { - if (x[i] == alkalinity_unknown) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e\n", x[i]->total->description, - (double) (x[i]->f/mass_water_aq_x), (double) x[i]->f); - pure_water = FALSE; - } - if (x[i] == ph_unknown) continue; - if (x[i] == pe_unknown) continue; - if (x[i] == charge_balance_unknown ) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", x[i]->description, - (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); - output_msg(OUTPUT_MESSAGE," Charge balance\n"); - pure_water = FALSE; - continue; - } - if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e", x[i]->description, - (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); - output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", x[i]->phase->name); - pure_water = FALSE; - continue; - } - if (x[i]->type == MB) { - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e\n", x[i]->description, - (double) (x[i]->sum/mass_water_aq_x), (double) x[i]->sum); - pure_water = FALSE; - } - } - - if (pure_water == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t%-15s\n","Pure water"); - } -/* - * Description of solution - */ - output_msg(OUTPUT_MESSAGE,"\n"); - print_centered("Description of solution"); -/* - * pH - */ - output_msg(OUTPUT_MESSAGE,"%45s%7.3f ","pH = ",(double) (-(s_hplus->la))); - if (ph_unknown == NULL) { - output_msg(OUTPUT_MESSAGE,"\n"); - } else if (ph_unknown == charge_balance_unknown) { - output_msg(OUTPUT_MESSAGE," Charge balance\n"); - } else if (ph_unknown->type == SOLUTION_PHASE_BOUNDARY) { - output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", ph_unknown->phase->name); - } else if (ph_unknown->type == ALK) { - output_msg(OUTPUT_MESSAGE," Adjust alkalinity\n"); - } -/* - * pe - */ - output_msg(OUTPUT_MESSAGE,"%45s%7.3f ","pe = ",(double) (-(s_eminus->la))); - if (pe_unknown == NULL) { - output_msg(OUTPUT_MESSAGE,"\n"); - } else if (pe_unknown == charge_balance_unknown) { - output_msg(OUTPUT_MESSAGE," Charge balance\n"); - } else if (pe_unknown->type == SOLUTION_PHASE_BOUNDARY) { - output_msg(OUTPUT_MESSAGE," Equilibrium with %s\n", pe_unknown->phase->name); - } else if (pe_unknown->type == MH) { - output_msg(OUTPUT_MESSAGE," Adjusted to redox equilibrium\n"); - } -/* - * Others - */ - output_msg(OUTPUT_MESSAGE,"%45s%7.3f\n","Activity of water = ",exp( s_h2o->la * LOG_10)); - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Ionic strength = ", (double) mu_x); - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Mass of water (kg) = ", (double) mass_water_aq_x); - if (alkalinity_unknown == NULL) { - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total alkalinity (eq/kg) = ", (double) (total_alkalinity/mass_water_aq_x)); - } - if (carbon_unknown == NULL) { - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total carbon (mol/kg) = ", (double) (total_carbon/mass_water_aq_x)); - } - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Total CO2 (mol/kg) = ", (double) (total_co2/mass_water_aq_x)); - output_msg(OUTPUT_MESSAGE,"%45s%7.3f\n","Temperature (deg C) = ", (double) tc_x); - output_msg(OUTPUT_MESSAGE,"%45s%11.3e\n","Electrical balance (eq) = ", (double) cb_x); - output_msg(OUTPUT_MESSAGE,"%45s%6.2f\n","Percent error, 100*(Cat-|An|)/(Cat+|An|) = ", (double) (100*cb_x/total_ions_x)); - output_msg(OUTPUT_MESSAGE,"%45s%3d\n","Iterations = ",iterations); - if (pitzer_model == TRUE) { - output_msg(OUTPUT_MESSAGE,"%45s%3d\n","Gamma iterations = ",gamma_iterations); - output_msg(OUTPUT_MESSAGE,"%45s%9.5f\n","Osmotic coefficient = ", COSMOT); - output_msg(OUTPUT_MESSAGE,"%45s%9.5f\n","Density of water = ", DW0); - } - output_msg(OUTPUT_MESSAGE,"%45s%e\n","Total H = ", (double) total_h_x); - output_msg(OUTPUT_MESSAGE,"%45s%e\n","Total O = ", (double) total_o_x); - output_msg(OUTPUT_MESSAGE,"\n"); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_user_print(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print with user defined BASIC print routine - */ - int i; - struct kinetics *kinetics_ptr; - - char command[] = "run"; - - if (pr.user_print == FALSE || pr.all == FALSE) return(OK); - if (user_print->commands == NULL) return(OK); - kinetics_ptr = NULL; - if (use.kinetics_in == TRUE) { - kinetics_ptr = use.kinetics_ptr; - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - use.kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); - } else { - use.kinetics_ptr = kinetics_bsearch(-2, &i); - } - } - print_centered("User print"); - if (user_print->new_def == TRUE) { - /* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */ - if (basic_compile(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase) != 0) { - error_msg("Fatal Basic error in USER_PRINT.", STOP); - } - user_print->new_def = FALSE; - } - if (basic_run(command, user_print->linebase, user_print->varbase, user_print->loopbase) != 0) { - error_msg("Fatal Basic error in USER_PRINT.", STOP); - } - output_msg(OUTPUT_MESSAGE,"\n"); - if (use.kinetics_in == TRUE) { - use.kinetics_ptr = kinetics_ptr; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_using(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print entities used in calculation - */ - struct mix *mix_ptr; - struct solution *solution_ptr; - struct exchange *exchange_ptr; - struct surface *surface_ptr; - struct pp_assemblage *pp_assemblage_ptr; - struct s_s_assemblage *s_s_assemblage_ptr; - struct gas_phase *gas_phase_ptr; - struct temperature *temperature_ptr; - struct irrev *irrev_ptr; - struct kinetics *kinetics_ptr; - int n; - - if (pr.use == FALSE || pr.all == FALSE) return(OK); - if (state < REACTION || phast == TRUE) return(OK); -/* - * Mixture or Solution - */ - if (use.mix_in == TRUE) { - if (state == TRANSPORT) { - mix_ptr = mix_bsearch(use.n_mix_user, &n); - } else { - mix_ptr = mix_bsearch(use.n_mix_user_orig, &n); - } - if (mix_ptr == NULL) { - mix_ptr = use.mix_ptr; - } - if (mix_ptr != NULL) { - if (state == TRANSPORT) { - output_msg(OUTPUT_MESSAGE,"Using mix %d.\t%s\n", use.n_mix_user, mix_ptr->description); - } else { - output_msg(OUTPUT_MESSAGE,"Using mix %d.\t%s\n", use.n_mix_user_orig, mix_ptr->description); - } - - } - } else { - solution_ptr = solution_bsearch (use.n_solution_user, &n, TRUE); - output_msg(OUTPUT_MESSAGE,"Using solution %d.\t%s\n", use.n_solution_user, solution_ptr->description); - } -/* - * Exchange and surface - */ - if (use.exchange_in == TRUE) { - exchange_ptr = exchange_bsearch(use.n_exchange_user, &n); - output_msg(OUTPUT_MESSAGE,"Using exchange %d.\t%s\n", use.n_exchange_user, exchange_ptr->description); - } - if (use.surface_in == TRUE) { - surface_ptr = surface_bsearch(use.n_surface_user, &n); - output_msg(OUTPUT_MESSAGE,"Using surface %d.\t%s\n", use.n_surface_user, surface_ptr->description); - } - if (use.pp_assemblage_in == TRUE) { - pp_assemblage_ptr = pp_assemblage_bsearch(use.n_pp_assemblage_user, &n); - output_msg(OUTPUT_MESSAGE,"Using pure phase assemblage %d.\t%s\n", use.n_pp_assemblage_user, - pp_assemblage_ptr->description); - } - if (use.s_s_assemblage_in == TRUE) { - s_s_assemblage_ptr = s_s_assemblage_bsearch(use.n_s_s_assemblage_user, &n); - output_msg(OUTPUT_MESSAGE,"Using solid solution assemblage %d.\t%s\n", use.n_s_s_assemblage_user, - s_s_assemblage_ptr->description); - } - if (use.gas_phase_in == TRUE) { - gas_phase_ptr = gas_phase_bsearch(use.n_gas_phase_user, &n); - output_msg(OUTPUT_MESSAGE,"Using gas phase %d.\t%s\n", use.n_gas_phase_user, gas_phase_ptr->description); - } - if (use.temperature_in == TRUE) { - temperature_ptr = temperature_bsearch(use.n_temperature_user, &n); - output_msg(OUTPUT_MESSAGE,"Using temperature %d.\t%s\n", use.n_temperature_user, temperature_ptr->description); - } - if (use.irrev_in == TRUE) { - if (state != TRANSPORT || transport_step > 0) { - irrev_ptr = irrev_bsearch(use.n_irrev_user, &n); - output_msg(OUTPUT_MESSAGE,"Using reaction %d.\t%s\n", use.n_irrev_user, irrev_ptr->description); - } - } - if (use.kinetics_in == TRUE) { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &n); - } else { - kinetics_ptr = kinetics_bsearch(-2, &n); - } - output_msg(OUTPUT_MESSAGE,"Using kinetics %d.\t%s\n", use.n_kinetics_user, kinetics_ptr->description); - } - output_msg(OUTPUT_MESSAGE,"\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints selected gas phase data - */ - int i, j; - LDBLE p, total_moles, volume; - LDBLE moles; - - if (punch.count_gases <= 0) return(OK); - p = 0.0; - total_moles = 0.0; - volume = 0.0; - if (gas_unknown != NULL && use.gas_phase_ptr != NULL){ - if (use.gas_phase_ptr->type == PRESSURE) { - use.gas_phase_ptr->total_moles = gas_unknown->moles; - use.gas_phase_ptr->volume = use.gas_phase_ptr->total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; - } - p = use.gas_phase_ptr->total_p; - total_moles = use.gas_phase_ptr->total_moles; - volume = total_moles * R_LITER_ATM * tk_x / use.gas_phase_ptr->total_p; - } - if (punch.high_precision == FALSE) { - fpunchf("pressure", "%12.4e\t", p); - fpunchf("total mol", "%12.4e\t",total_moles); - fpunchf("volume", "%12.4e\t",volume); - } else { - fpunchf("pressure", "%20.12e\t", p); - fpunchf("total mol", "%20.12e\t",total_moles); - fpunchf("volume", "%20.12e\t",volume); - } - for (i = 0; i < punch.count_gases; i++) { - moles = 0.0; - if (use.gas_phase_ptr != NULL && punch.gases[i].phase != NULL) { - for( j = 0; j < use.gas_phase_ptr->count_comps; j++) { - - if (use.gas_phase_ptr->comps[j].phase != punch.gases[i].phase) continue; - moles = use.gas_phase_ptr->comps[j].phase->moles_x; - if ( moles <= MIN_TOTAL ) moles = 0.0; - break; - } - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("g_%s", punch.gases[i].name),"%12.4e\t", moles); - } else { - fpunchf(sformatf("g_%s", punch.gases[i].name),"%20.12e\t", moles); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_s_s_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints solid solution composition if present - */ - int i, j, k; - int found; - LDBLE moles; - -/* - * Print solid solutions - */ - for (k = 0; k < punch.count_s_s; k++) { - found = FALSE; - if (use.s_s_assemblage_ptr != NULL) { - for( j = 0; j < use.s_s_assemblage_ptr->count_s_s; j++) { - for (i = 0; i < use.s_s_assemblage_ptr->s_s[j].count_comps; i++) { - if (strcmp_nocase(punch.s_s[k].name, use.s_s_assemblage_ptr->s_s[j].comps[i].name) == 0) { - if (use.s_s_assemblage_ptr->s_s[j].s_s_in == TRUE) { - moles = use.s_s_assemblage_ptr->s_s[j].comps[i].moles; - } else { - moles = 0; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", - (double) moles); - } else { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", - (double) moles); - } - found = TRUE; - break; - } - } - if (found == TRUE) break; - } - } - if (found == FALSE) { - if (punch.high_precision == FALSE) { - fpunchf(sformatf("s_%s", punch.s_s[k].name),"%12.4e\t", 0.0); - } else { - fpunchf(sformatf("s_%s", punch.s_s[k].name),"%20.12e\t", 0.0); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_totals(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print total concentrations of elements, molality and moles. - */ - int j; - LDBLE molality; - - for (j = 0; j < punch.count_totals; j++) { - if (punch.totals[j].master == NULL) { - molality =0.0; - } else if (punch.totals[j].master->primary == TRUE) { - molality = punch.totals[j].master->total_primary / mass_water_aq_x; - } else { - molality = punch.totals[j].master->total / mass_water_aq_x; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),"%12.4e\t", molality); - } else { - fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name),"%20.12e\t", molality); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_molalities(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print concentrations of species (aq, ex, surf) - */ - int j; - LDBLE molality; - - for (j = 0; j < punch.count_molalities; j++) { - molality = 0.0; - if (punch.molalities[j].s != NULL && punch.molalities[j].s->in == TRUE) { - molality = punch.molalities[j].s->moles / mass_water_aq_x; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),"%12.4e\t", molality); - } else { - fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name),"%20.12e\t", molality); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_activities(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print concentrations of species (aq, ex, surf) - */ - int j; - LDBLE la; - - for (j = 0; j < punch.count_activities; j++) { - la = -999.999; - if (punch.activities[j].s != NULL && punch.activities[j].s->in == TRUE) { - la = punch.activities[j].s->lm + punch.activities[j].s->lg; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("la_%s", punch.activities[j].name),"%12.4e\t", la); - } else { - fpunchf(sformatf("la_%s", punch.activities[j].name),"%20.12e\t", la); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_pp_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints masses of selected pure_phases in pp_assemblage - */ - int i, j; - LDBLE moles, delta_moles; - - for (i = 0; i < punch.count_pure_phases; i++) { - delta_moles = 0; - moles = 0.0; - if (punch.pure_phases[i].phase != NULL) { - for( j = 0; j < count_unknowns; j++) { - if (x == NULL || x[j]->type != PP) continue; -/* - * Print pure phase assemblage data - */ - if (punch.pure_phases[i].phase != x[j]->pure_phase->phase) continue; - if (state != TRANSPORT && state != PHAST) { - moles = x[j]->moles; - delta_moles = x[j]->moles - x[j]->pure_phase->moles - x[j]->pure_phase->delta; - } else { - moles = x[j]->moles; - delta_moles = x[j]->moles - x[j]->pure_phase->initial_moles; - } - break; - } - } - if (punch.high_precision == FALSE) { - fpunchf(punch.pure_phases[i].name,"%12.4e\t", moles); - fpunchf(sformatf("d_%s", punch.pure_phases[i].name),"%12.4e\t", delta_moles); - } else { - fpunchf(punch.pure_phases[i].name,"%20.12e\t", moles); - fpunchf(sformatf("d_%s", punch.pure_phases[i].name),"%20.12e\t", delta_moles); - } - } - return(OK); -} -#define PHAST_NULL(x) (phast ? NULL : x) -/* ---------------------------------------------------------------------- */ -int punch_identifiers(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints series of integers to identify simulation number, - * state of calculations, reaction or transport step number, - * and temp, ph, pe, and mass of water for each line - * of selected output. - */ - const char *sformat; - const char *dformat; - const char *gformat; - int i, l; - char token[MAX_LENGTH]; - if (punch.in == FALSE) return(OK); - if (punch.high_precision == FALSE) { - l = 12; - sformat = "%12s\t"; - dformat = "%12d\t"; - gformat = "%12g\t"; - } else { - l = 20; - sformat = "%20s\t"; - dformat = "%20d\t"; - gformat = "%20g\t"; - } - -/* - * simulation or simul_tr - */ - - if (punch.sim == TRUE) { - if (state != TRANSPORT && state != PHAST) { - fpunchf(PHAST_NULL("sim"), dformat, simulation); - } else { - fpunchf(PHAST_NULL("sim"), dformat, simul_tr); - } - } - if (punch.state == TRUE) { - switch (state) { - case 0: - strcpy(token,"init"); - break; - case 1: - strcpy(token,"i_soln"); - break; - case 2: - strcpy(token,"i_exch"); - break; - case 3: - strcpy(token,"i_surf"); - break; - case 4: - strcpy(token,"i_gas"); - break; - case 5: - strcpy(token,"react"); - break; - case 6: - strcpy(token,"inverse"); - break; - case 7: - strcpy(token,"advect"); - break; - case 8: - strcpy(token,"transp"); - break; - } - fpunchf(PHAST_NULL("state"), sformat, token); - - } -/* - * solution number or cell number and time - */ - if (punch.soln == TRUE) { - if (state == TRANSPORT || state == PHAST) { - fpunchf(PHAST_NULL("soln"), dformat, cell); - } else if (state == ADVECTION) { - fpunchf(PHAST_NULL("soln"), dformat, use.n_solution_user); - } else if (state < REACTION) { - fpunchf(PHAST_NULL("soln"), dformat, use.solution_ptr->n_user); - } else { - if (use.mix_in == TRUE) { - if (state != TRANSPORT) { - fpunchf(PHAST_NULL("soln"),dformat, use.n_mix_user_orig); - } else { - fpunchf(PHAST_NULL("soln"),dformat, use.n_mix_user); - } - - } else { - fpunchf(PHAST_NULL("soln"), dformat, use.n_solution_user); - } - } - } - if (punch.dist == TRUE) { - if (state == ADVECTION) { - fpunchf(PHAST_NULL("dist_x"), dformat, use.n_solution_user); - } else if (state == TRANSPORT) { - fpunchf(PHAST_NULL("dist_x"), gformat, cell_data[cell-1 ].mid_cell_x); - } else { - fpunchf(PHAST_NULL("dist_x"), dformat, -99); - } - } - if (punch.time == TRUE) { - if (state == REACTION && incremental_reactions == TRUE && use.kinetics_ptr != NULL) { - if (use.kinetics_ptr->count_steps > 0) { - kin_time_x = 0.; - for (i = 0; i < reaction_step; i++) { - if (i < use.kinetics_ptr->count_steps) { - kin_time_x += use.kinetics_ptr->steps[i]; - } else { - kin_time_x += use.kinetics_ptr->steps[use.kinetics_ptr->count_steps - 1]; - } - } - } else if (use.kinetics_ptr->count_steps < 0) { - if (reaction_step > -use.kinetics_ptr->count_steps) { - kin_time_x = use.kinetics_ptr->steps[0]; - } else { - kin_time_x = reaction_step * use.kinetics_ptr->steps[0] / ( (LDBLE) (-use.kinetics_ptr->count_steps)); - } - } - } - if (state == REACTION) { - fpunchf(PHAST_NULL("time"), gformat, kin_time_x); - } else if (state == TRANSPORT || state == PHAST ) { - fpunchf(PHAST_NULL("time"), gformat, initial_total_time + rate_sim_time); - } else if (state == ADVECTION) { - if (advection_kin_time_defined == TRUE) { - fpunchf(PHAST_NULL("time"), gformat, initial_total_time + rate_sim_time); - } else { - fpunchf(PHAST_NULL("time"), dformat, advection_step); - } - } else { - fpunchf(PHAST_NULL("time"), dformat, -99); - } - } - -/* - * reaction or transport step - */ - if (punch.step == TRUE) { - if (state == REACTION) { - fpunchf(PHAST_NULL("step"), dformat, reaction_step); - } else if (state == ADVECTION) { - fpunchf(PHAST_NULL("step"), dformat, advection_step); - } else if (state == TRANSPORT) { - fpunchf(PHAST_NULL("step"), dformat, transport_step); - } else { - fpunchf(PHAST_NULL("step"), dformat, -99); - } - } - if (punch.ph == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("pH","%12g\t", (double) (-s_hplus->la)); - } else { - fpunchf("pH","%20.12e\t", (double) (-s_hplus->la)); - } - } - if (punch.pe == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("pe","%12g\t", (double) (-s_eminus->la)); - } else { - fpunchf("pe","%20.12e\t", (double) (-s_eminus->la)); - } - } - if (punch.rxn == TRUE) { - if (state >= REACTION && use.irrev_in == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("reaction","%12.4e\t", step_x); - } else { - fpunchf("reaction","%20.12e\t", step_x); - } - } else { - if (punch.high_precision == FALSE) { - fpunchf("reaction","%12d\t", -99); - } else { - fpunchf("reaction","%20d\t", -99); - } - } - } - if (punch.temp == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("temp(C)","%12.3f\t", tc_x); - } else { - fpunchf("temp(C)","%20.12e\t", tc_x); - } - } - if (punch.alk == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("Alk(eq/kgw)","%12g\t", (double) (total_alkalinity/mass_water_aq_x)); - } else { - fpunchf("Alk(eq/kgw)","%20.12e\t", (double) (total_alkalinity/mass_water_aq_x)); - } - } - if (punch.mu == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("mu","%12g\t", (double) mu_x); - } else { - fpunchf("mu","%20.12e\t", (double) mu_x); - } - } - if (punch.water == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("mass_H2O","%12g\t", (double) mass_water_aq_x); - } else { - fpunchf("mass_H2O","%20.12e\t", (double) mass_water_aq_x); - } - } - if (punch.charge_balance == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("charge(eq)","%12g\t", (double) cb_x); - } else { - fpunchf("charge(eq)","%20.12e\t", (double) cb_x); - } - } - if (punch.percent_error == TRUE) { - if (punch.high_precision == FALSE) { - fpunchf("pct_err","%12g\t", (double) (100*cb_x/total_ions_x)); - } else { - fpunchf("pct_err","%20.12e\t", (double) (100*cb_x/total_ions_x)); - } - } - - return(OK); -} -#undef PHAST_NULL -/* ---------------------------------------------------------------------- */ -int punch_saturation_indices(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints saturation indices of selected phases - */ - int i; - LDBLE si, iap; - struct rxn_token *rxn_ptr; - - for (i=0; i < punch.count_si; i++) { - if (punch.si[i].phase == NULL || punch.si[i].phase->in == FALSE) { - si = -999.999; - } else { -/* - * Print saturation index - */ - iap = 0.0; - for (rxn_ptr = punch.si[i].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - iap += rxn_ptr->s->la * rxn_ptr->coef; - } - si=-punch.si[i].phase->lk + iap; - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("si_%s", punch.si[i].name),"%12.4f\t", si); - } else { - fpunchf(sformatf("si_%s", punch.si[i].name),"%20.12e\t", si); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int punch_kinetics(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints kinetic reaction, - * should be called only on final kinetic step - */ - int i, j; - struct kinetics *kinetics_ptr; - LDBLE moles, delta_moles; - - kinetics_ptr = NULL; - if (use.kinetics_in == TRUE) { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - kinetics_ptr = kinetics_bsearch(use.n_kinetics_user, &i); - } else { - kinetics_ptr = kinetics_bsearch(-2, &i); - } - } - for (i = 0; i < punch.count_kinetics; i++) { - moles = 0.0; - delta_moles = 0.0; - if (kinetics_ptr != NULL) { - for (j = 0; j < kinetics_ptr->count_comps; j++) { - if (strcmp_nocase(punch.kinetics[i].name, kinetics_ptr->comps[j].rate_name) == 0) { - if (state != TRANSPORT && state != PHAST) { - moles = kinetics_ptr->comps[j].m; - delta_moles = -kinetics_ptr->comps[j].moles; - } else { - moles = kinetics_ptr->comps[j].m; - delta_moles = kinetics_ptr->comps[j].m - kinetics_ptr->comps[j].initial_moles; - } - break; - } - } - } - if (punch.high_precision == FALSE) { - fpunchf(sformatf("k_%s", punch.kinetics[i].name),"%12.4e\t", moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name),"%12.4e\t", -delta_moles); - } else { - fpunchf(sformatf("k_%s", punch.kinetics[i].name),"%20.12e\t", moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name),"%20.12e\t", -delta_moles); - } - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int punch_user_punch(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Punch with user defined BASIC print routine - */ - char command[] = "run"; - - extern int n_user_punch_index; - n_user_punch_index = 0; - if (punch.user_punch == FALSE) return(OK); - if (user_punch->commands == NULL) return(OK); - if (user_punch->new_def == TRUE) { - if (basic_compile(user_punch->commands, &user_punch->linebase, &user_punch->varbase, &user_punch->loopbase) != 0) { - error_msg("Fatal Basic error in USER_PUNCH.", STOP); - } - user_punch->new_def = FALSE; - } - if (basic_run(command, user_punch->linebase, user_punch->varbase, user_punch->loopbase) != 0) { - error_msg("Fatal Basic error in USER_PUNCH.", STOP); - } - return(OK); -} - -#ifdef PHREEQ98 -/* ---------------------------------------------------------------------- */ -int punch_user_graph(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Graph with user defined BASIC print routine - */ - char command[] = "run"; - - colnr = 0; -/* //if (pr.user_graph == FALSE || pr.all == FALSE) return(OK); */ -/* //if (punch.user_punch == FALSE) return(OK); */ -/* //if (punch.in == FALSE) return(OK); */ - if (user_graph->commands == NULL) return(OK); - if (((state == INITIAL_SOLUTION) || (state == INITIAL_EXCHANGE) || (state == INITIAL_SURFACE) || (state == INITIAL_GAS_PHASE)) && (graph_initial_solutions == FALSE)) return(OK); - if (FirstCallToUSER_GRAPH) AddSeries = TRUE; - if (state == REACTION) { - /*if (reaction_step == 1) AddSeries = TRUE; - else AddSeries = FALSE; */ - if (reaction_step > 1) AddSeries = FALSE; - } - if (state == ADVECTION) { - if (advection_step == 0 && graph_initial_solutions == FALSE) return(OK); - if (((chart_type == 1) && (advection_step == punch_ad_modulus)) || - ((chart_type == 0) && (advection_step != prev_advection_step))) AddSeries = TRUE; - else AddSeries = FALSE; - } - if (state == TRANSPORT) { - if (transport_step == 0 && graph_initial_solutions == FALSE) return(OK); - if (((chart_type == 1) && (transport_step == punch_modulus)) || - ((chart_type == 0) && (transport_step != prev_transport_step))) AddSeries = TRUE; - else AddSeries = FALSE; - } - if (user_graph->new_def == TRUE) { - if (basic_compile(user_graph->commands, &user_graph->linebase, &user_graph->varbase, &user_graph->loopbase) != 0) { - error_msg("Fatal Basic error in USER_GRAPH.", STOP); - } - user_graph->new_def = FALSE; - } - if (basic_run(command, user_graph->linebase, user_graph->varbase, user_graph->loopbase) != 0) { - error_msg("Fatal Basic error in USER_GRAPH.", STOP); - } - if (state == ADVECTION) prev_advection_step = advection_step; - if (state == TRANSPORT) prev_transport_step = transport_step; - /*if (state == REACTION) prev_reaction_step = reaction_step;*/ - - FirstCallToUSER_GRAPH = FALSE; - - return(OK); -} -#endif - -#if defined(HDF5_CREATE) -extern void HDFWriteHyperSlabV(const char* name, const char* format, va_list argptr); -#endif - -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern int Merge_fpunchf(const int length, const char* format, va_list argptr); -#endif - -int output_message(const int type, const char *err_str, const int stop, const char *format, va_list args); - -int fpunchf(const char* name, const char* format, ...) -{ - int retval = 0; - va_list args; - - va_start(args, format); - retval = output_message(OUTPUT_PUNCH, name, CONTINUE, format, args); - va_end(args); - - return retval; -} -int fpunchf_user(int user_index, const char* format, ...) -{ - static int s_warning = 0; - int retval = 0; - va_list args; - static char buffer[80]; - char* name; - - if (user_index < user_punch_count_headings) { - name = user_punch_headings[user_index]; - } - else { - if (s_warning == 0) { - sprintf(error_string, "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); - warning_msg(error_string); - s_warning = 1; - } - sprintf(buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); - name = buffer; - } - - va_start(args, format); - retval = output_message(OUTPUT_PUNCH, name, CONTINUE, format, args); - va_end(args); - - return retval; -} -#ifdef SAVE -int fpunchf(const char* name, const char* format, ...) -{ - int retval = 0; - va_list args; - static char big_buffer[200]; - -#if defined(HDF5_CREATE) - if (pr.hdf == TRUE) { - va_start(args, format); - HDFWriteHyperSlabV(name, format, args); - va_end(args); - } -#endif - if (pr.punch == TRUE && punch.in == TRUE) { - va_start(args, format); - retval = output_message(OUTPUT_PUNCH, NULL, CONTINUE, format, args); - va_end(args); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - va_start(args, format); - retval = vsprintf(big_buffer, format, args); - Merge_fpunchf(retval, format, args); - va_end(args); -#endif -#if defined(SWIG_SHARED_OBJ) - va_start(args, format); - AddSelectedOutput(name, format, args); - va_end(args); -#endif - } - return retval; -} -int fpunchf_user(int user_index, const char* format, ...) -{ - extern int warning_msg(const char* err_str); - static int s_warning = 0; - int retval = 0; - va_list args; - static char buffer[80]; - char* name; - - if (user_index < user_punch_count_headings) { - name = user_punch_headings[user_index]; - } - else { - if (s_warning == 0) { - sprintf(error_string, "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); - warning_msg(error_string); - s_warning = 1; - } - sprintf(buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); - name = buffer; - } - -#if defined(HDF5_CREATE) - if (pr.hdf == TRUE) { - va_start(args, format); - HDFWriteHyperSlabV(name, format, args); - va_end(args); - } -#endif - - if (punch.in == TRUE && pr.punch == TRUE) { - va_start(args, format); - retval = output_message(OUTPUT_PUNCH, NULL, CONTINUE, format, args); - va_end(args); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - va_start(args, format); - Merge_fpunchf(retval, format, args); - va_end(args); -#endif -#if defined(SWIG_SHARED_OBJ) - va_start(args, format); - AddSelectedOutput(name, format, args); - va_end(args); -#endif - } - return retval; -} -#endif - -char *sformatf(const char* format, ...) -{ -#if defined(HDF5_CREATE) || defined SWIG_SHARED_OBJ - static char scratch[240]; - va_list args; - - va_start(args, format); - if (vsprintf(scratch, format, args) > 239) { - error_msg("buffer overwrite in sformatf", STOP); - } - va_end(args); - return scratch; -#else - return NULL; -#endif -} - -/* ---------------------------------------------------------------------- */ -int print_alkalinity(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints description of solution, uses array species_list for - * order of aqueous species. - */ - int i, j; - struct species_list *alk_list; - int count_alk_list; - double min; - - if (pr.alkalinity == FALSE || pr.all == FALSE) return(OK); - print_centered("Distribution of alkalinity"); - alk_list = (struct species_list *) PHRQ_malloc((size_t) (count_s_x *sizeof(struct species_list))); - if (alk_list == NULL) malloc_error(); - j = 0; - for (i = 0; i < count_s_x; i++) { - if (s_x[i]->alk == 0.0) continue; - alk_list[j].master_s = s_hplus; - alk_list[j].s = s_x[i]; - alk_list[j].coef = s_x[i]->alk; - j++; - } - count_alk_list = j; - min = fabs(censor*total_alkalinity/mass_water_aq_x); - if (count_alk_list > 0) { - output_msg(OUTPUT_MESSAGE,"\t%26s%11.3e\n\n","Total alkalinity (eq/kgw) = ", (double) (total_alkalinity/mass_water_aq_x)); - output_msg(OUTPUT_MESSAGE,"\t%-15s%12s%12s%10s\n\n","Species","Alkalinity","Molality", "Alk/Mol"); - qsort (&alk_list[0], (size_t) count_alk_list, - (size_t) sizeof(struct species_list), species_list_compare_alk); - for (i = 0; i < count_alk_list; i++) { - if (fabs(alk_list[i].s->alk*(alk_list[i].s->moles)/mass_water_aq_x) < min) continue; - output_msg(OUTPUT_MESSAGE,"\t%-15s%12.3e%12.3e%10.2f\n", - alk_list[i].s->name, - (double) (alk_list[i].s->alk*(alk_list[i].s->moles)/mass_water_aq_x), - (double) ((alk_list[i].s->moles)/mass_water_aq_x), - (double) (alk_list[i].s->alk)); - } - } - - output_msg(OUTPUT_MESSAGE,"\n"); - alk_list = (struct species_list *) free_check_null(alk_list); - return(OK); -} diff --git a/read.cpp b/read.cpp deleted file mode 100644 index 949ce156..00000000 --- a/read.cpp +++ /dev/null @@ -1,7904 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" -extern int read_solution_raw (void); -extern int read_exchange_raw (void); -extern int read_surface_raw (void); -extern int read_equilibrium_phases_raw (void); -extern int read_kinetics_raw (void); -extern int read_solid_solutions_raw (void); -extern int read_gas_phase_raw (void); -extern int read_reaction_raw (void); -extern int read_mix_raw (void); -extern int read_temperature_raw (void); -static char const svnid[] = "$Id: read.c 715 2006-01-18 01:26:29Z dlpark $"; - -#if defined(SWIG_SHARED_OBJ) -#define STATIC -#else -#define STATIC static -#endif -STATIC int read_advection (void); -STATIC int read_analytical_expression_only (char *ptr, LDBLE *log_k); -STATIC int read_copy (void); -STATIC int read_debug (void); -STATIC int read_delta_h_only (char *ptr, LDBLE *delta_h, DELTA_H_UNIT *units); -STATIC int read_llnl_aqueous_model_parameters(void); -STATIC int read_exchange(void); -STATIC int read_exchange_master_species (void); -STATIC int read_exchange_species (void); -STATIC int read_gas_phase(void); -STATIC int read_incremental_reactions(void); -STATIC int read_inverse(void); -STATIC int read_inv_balances (struct inverse *inverse_ptr, char *next_char); -STATIC int read_inv_isotopes (struct inverse *inverse_ptr, char *ptr); -STATIC int read_inv_phases (struct inverse *inverse_ptr, char *next_char); -STATIC int read_kinetics (void); -STATIC int read_line_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc); -STATIC int read_lines_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc, const char **opt_list, int count_opt_list, int *opt); -STATIC LDBLE *read_list_doubles(char **ptr, int *count_doubles ); -STATIC int *read_list_ints (char **ptr, int *count_ints, int positive ); -STATIC int *read_list_t_f (char **ptr, int *count_ints ); -STATIC int read_master_species (void); -STATIC int read_mix (void); -STATIC int read_named_logk(void); -STATIC int read_phases(void); -STATIC int read_print (void); -STATIC int read_pure_phases(void); -STATIC int read_rates (void); -STATIC int read_reaction (void); -STATIC int read_reaction_reactants(struct irrev *irrev_ptr); -STATIC int read_reaction_steps(struct irrev *irrev_ptr); -STATIC int read_solid_solutions(void); -STATIC int read_temperature (void); -STATIC int read_reaction_temps(struct temperature *temperature_ptr); -STATIC int read_save(void); -STATIC int read_selected_output (void); -STATIC int read_solution(void); -STATIC int read_species (void); -STATIC int read_surf(void); -STATIC int read_surface_master_species (void); -STATIC int read_surface_species (void); -STATIC int read_use(void); -STATIC int read_title (void); -STATIC int read_user_print (void); -STATIC int read_user_punch (void); -#ifdef PHREEQ98 -STATIC int read_user_graph (void); -extern int connect_simulations, graph_initial_solutions; -/*extern*/ int shifts_as_points; -extern int chart_type; -extern int ShowChart; -extern int RowOffset, ColumnOffset; -#endif - -extern int reading_database(void); -extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, - int print); - -#ifdef PHREEQ98 -extern int copy_title(char *token_ptr, char **ptr, int *length); -extern int OpenCSVFile(char file_name[MAX_LENGTH]); -void GridHeadings(char* s, int i); -void SetAxisTitles(char* s, int i); -void SetAxisScale(char* a, int c, char* v, int l); -void SetChartTitle(char* s); -#endif - -static LDBLE dummy; - -/* ---------------------------------------------------------------------- */ -int read_input(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l; - char *ptr; - char token[2*MAX_LENGTH]; - if (svnid == NULL) fprintf(stderr," "); - - parse_error = 0; - input_error = 0; - next_keyword = 0; - count_warnings = 0; -/* - * Initialize keyword flags - */ - for (i=0; i < NKEYS; i++) { - keyword[i].keycount=0; - } -/* - * Initialize use and save pointers - */ - use.solution_in = FALSE; - use.solution_ptr = NULL; - use.pp_assemblage_in = FALSE; - use.pp_assemblage_ptr = NULL; - use.mix_in = FALSE; - use.mix_ptr = NULL; - use.irrev_in = FALSE; - use.irrev_ptr = NULL; - use.kinetics_in = FALSE; - use.kinetics_ptr = NULL; - use.exchange_in = FALSE; - use.exchange_ptr = NULL; - use.surface_in = FALSE; - use.surface_ptr = NULL; - use.temperature_in = FALSE; - use.temperature_ptr = NULL; - use.gas_phase_in = FALSE; - use.gas_phase_ptr = NULL; - use.s_s_assemblage_in = FALSE; - use.s_s_assemblage_ptr = NULL; - use.trans_in = FALSE; - use.advect_in = FALSE; - - save.solution = FALSE; - save.mix = FALSE; - save.irrev = FALSE; - save.pp_assemblage = FALSE; - save.exchange = FALSE; - save.surface = FALSE; - save.gas_phase = FALSE; - save.s_s_assemblage = FALSE; - title_x = (char *) free_check_null(title_x); - - while ( (i = check_line("Subroutine Read", FALSE, TRUE, TRUE, TRUE)) != KEYWORD) { - /* empty, eof, keyword, print */ - - if ( i == EOF) return(EOF); - sprintf(error_string, "Unknown input, no keyword has been specified."); - warning_msg(error_string); - } -/* - 0 "eof" - 1 "end" - 2 "species" - 3 "master" - 4 "solution" - 5 "phases" - 6 "pure_phases" - 7 "reaction" - 8 "mix" - 9 "use" - 10 "save" - 11 "exchange_species" - 12 "master_exchange_species" - 13 "exchange" - 14 "surface_species" - 15 "master_surface_species" - 16 "surface" - 17 "reacton_temperature" - 18 "inverse_modeling" - 19 "gas_phase" - 20 "transport" - 21 "debug" - 22 "selected_output" - 23 "select_output" - 24 "knobs" - 25 "print" - 26 "equilibrium_phases" - 27 "equilibria" - 28 "equilibrium" - 29 "pure" - 30 "title" - 31 "comment" - 32 "advection" - 33 "kinetics" - 34 "incremental_reactions" - 35 "incremental" - 36 "rates" - 37 "solution_s" - 38 "user_print" - 39 "user_punch" - 40 "solid_solutions" - 41 "solid_solution" - 42 "solution_spread" - 43 "spread_solution" - 44 "selected_out" - 45 "select_out" - 46 "user_graph" - 47 "llnl_aqueous_model_parameters" - 48 "llnl_aqueous_model" - 49 "database" - 50 "named_analytical_expression" - 51 "named_analytical_expressions" - 52 "named_expressions" - 53 "named_log_k" - 54 "isotopes" - 55 "calculate_values" - 56 "isotopes_ratios", - 57 "isotopes_alphas" - 58 "copy" - 59 "pitzer" - 60 "solution_raw" - 61 "exchange_raw" - 62 "surface_raw" - 63 "equilibrium_phases_raw" - 64 "kinetics_raw" - 65 "solid_solutions_raw" - 66 "gas_phase_raw" - 67 "reaction_raw" - 68 "mix_raw" - 69 "reaction_temperature_raw" - */ - for (;;) { - if (next_keyword >= 0) { - /* keyword[next_keyword].keycount++;*/ - if (next_keyword != 49 && !reading_database()) first_read_input = FALSE; - } - switch(next_keyword) { - case -1: /* Have not read line with keyword */ - sprintf(error_string, "Unknown input, no keyword has been specified."); - warning_msg(error_string); - while ((j = check_line ("No keyword", FALSE, TRUE, TRUE, TRUE)) != KEYWORD - && j != EOF ) { - warning_msg(error_string); - } - break; - case 0: /* End encountered */ - case 1: /* EOF encountered */ - goto END_OF_SIMULATION_INPUT; - case 2: /* Read aqueous model */ - keyword[2].keycount++; - read_species(); - break; - case 3: /* Read master species */ - keyword[3].keycount++; - read_master_species(); - break; - case 4: /* Read solution data */ - keyword[4].keycount++; - read_solution(); - solution_sort(); - break; - case 5: - keyword[5].keycount++; - read_phases(); - break; - case 6: - case 26: - case 27: - case 28: - case 29: - keyword[6].keycount++; - keyword[26].keycount++; - keyword[27].keycount++; - keyword[28].keycount++; - keyword[29].keycount++; - read_pure_phases(); - break; - case 7: - keyword[7].keycount++; - read_reaction(); - break; - case 8: - keyword[8].keycount++; - read_mix(); - break; - case 9: - keyword[9].keycount++; - read_use(); - break; - case 10: - keyword[10].keycount++; - read_save(); - break; - case 11: - keyword[11].keycount++; - read_exchange_species(); - break; - case 12: - keyword[12].keycount++; - read_exchange_master_species(); - break; - case 13: - keyword[13].keycount++; - read_exchange(); - break; - case 14: - keyword[14].keycount++; - read_surface_species(); - break; - case 15: - keyword[15].keycount++; - read_surface_master_species(); - break; - case 16: - keyword[16].keycount++; - read_surf(); - break; - case 17: - keyword[17].keycount++; - read_temperature(); - break; - case 18: - keyword[18].keycount++; - read_inverse(); - break; - case 19: - keyword[19].keycount++; - read_gas_phase(); - break; - case 20: - keyword[20].keycount++; - read_transport(); - break; - case 21: - case 24: - keyword[21].keycount++; - keyword[24].keycount++; - read_debug(); - break; - case 22: - case 23: - case 44: - case 45: - keyword[22].keycount++; - keyword[23].keycount++; - keyword[44].keycount++; - keyword[45].keycount++; - read_selected_output(); - break; - case 25: - keyword[25].keycount++; - read_print(); - break; - case 30: - case 31: - keyword[30].keycount++; - keyword[31].keycount++; - read_title(); - break; - case 32: - keyword[32].keycount++; - read_advection(); - break; - case 33: - keyword[33].keycount++; - read_kinetics(); - break; - case 34: - case 35: - keyword[34].keycount++; - keyword[35].keycount++; - read_incremental_reactions(); - break; - case 36: - keyword[36].keycount++; - read_rates(); - break; - case 37: - case 42: - case 43: - keyword[37].keycount++; - keyword[42].keycount++; - keyword[43].keycount++; - read_solution_spread(); -#ifdef SKIP - solution_sort(); -#endif - break; - case 38: - keyword[38].keycount++; - read_user_print(); - break; - case 39: - keyword[39].keycount++; - read_user_punch(); - break; - case 40: - case 41: - keyword[40].keycount++; - keyword[41].keycount++; - read_solid_solutions(); - break; - case 46: - keyword[46].keycount++; -#ifdef PHREEQ98 - read_user_graph(); -# else - for (;;) { - j=check_line ("Reading user_graph", FALSE, TRUE, TRUE, TRUE); - if (j == EOF || j == KEYWORD ) { - break; - } - } -#endif - break; - case 47: - case 48: - keyword[47].keycount++; - keyword[48].keycount++; - read_llnl_aqueous_model_parameters(); - break; - case 49: - keyword[49].keycount++; - if (reading_database()) { - /* warning_msg("DATABASE is ignored in the database file."); */ - } else if (first_read_input == FALSE) { - error_msg("DATABASE must be the first keyword in the input file.", CONTINUE); - input_error++; - } else { - ptr = line; - copy_token(token, &ptr, &l); - user_database = string_duplicate(ptr); - if (string_trim(user_database) == EMPTY) { - error_msg("DATABASE file name is missing.", CONTINUE); - input_error++; - user_database = (char *) free_check_null(user_database); - } - first_read_input = FALSE; - } - j=check_line ("Reading after DATABASE", FALSE, TRUE, TRUE, TRUE); - break; - case 50: - case 51: - case 52: - case 53: - keyword[50].keycount++; - keyword[51].keycount++; - keyword[52].keycount++; - keyword[53].keycount++; - read_named_logk(); - break; - case 54: - keyword[54].keycount++; - read_isotopes(); - break; - case 55: - keyword[55].keycount++; - read_calculate_values(); - break; - case 56: - keyword[56].keycount++; - read_isotope_ratios(); - break; - case 57: - keyword[57].keycount++; - read_isotope_alphas(); - break; - case 58: - keyword[58].keycount++; - read_copy(); - break; - case 59: - keyword[59].keycount++; - read_pitzer(); - break; - case 60: - keyword[60].keycount++; - read_solution_raw(); - break; - case 61: - keyword[61].keycount++; - read_exchange_raw(); - break; - case 62: - keyword[62].keycount++; - read_surface_raw(); - break; - case 63: - keyword[63].keycount++; - read_equilibrium_phases_raw(); - break; - case 64: - keyword[64].keycount++; - read_kinetics_raw(); - break; - case 65: - keyword[65].keycount++; - read_solid_solutions_raw(); - break; - case 66: - keyword[66].keycount++; - read_gas_phase_raw(); - break; - case 67: - keyword[67].keycount++; - read_reaction_raw(); - break; - case 68: - keyword[68].keycount++; - read_mix_raw(); - break; - case 69: - keyword[69].keycount++; - read_temperature_raw(); - break; - } - } - END_OF_SIMULATION_INPUT: - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_conc(int n, int count_mass_balance, char *str) -/* ---------------------------------------------------------------------- */ -{ - int j, l; - int alk; - int count_redox_states; - - char *ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; -/* - * Set defaults - */ - /* - solution[n]->totals[count_mass_balance].equation_name = NULL; - solution[n]->totals[count_mass_balance].phase = NULL; - solution[n]->totals[count_mass_balance].phase_si = 0.0; - solution[n]->totals[count_mass_balance].units=NULL; - solution[n]->totals[count_mass_balance].n_pe=-1; - solution[n]->totals[count_mass_balance].as=NULL; - solution[n]->totals[count_mass_balance].gfw= 0.0; - */ - conc_init(&(solution[n]->totals[count_mass_balance])); - -/* - * Remove space between "kg" and "solution" or "water" in units - */ - replace("Kg","kg",str); - replace("KG","kg",str); - while (replace("kg ","kg",str) == TRUE); - ptr=str; -/* - * Read master species list for mass balance equation - */ - token1[0]='\0'; - count_redox_states=0; - while ( ((j = copy_token(token, &ptr, &l)) == UPPER ) || - ( token[0] == '[' ) || - ( strcmp_nocase_arg1(token,"ph") == 0 ) || - ( strcmp_nocase_arg1(token,"pe") == 0 ) ) { - count_redox_states++; - replace("(+","(",token); - if (count_redox_states > 1) strcat(token1," "); - strcat(token1,token); - } - if (count_redox_states == 0) { - input_error++; - error_msg ("No element or master species given for concentration input.", CONTINUE); - return(ERROR); - } - solution[n]->totals[count_mass_balance].description = string_hsave (token1); -/* - * Determine if reading alkalinity, allow equivalents for units - */ - str_tolower(token1); - if (strstr(token1,"alk") == token1) { - alk=TRUE; - } else { - alk=FALSE; - } -/* - * Read concentration - */ - - j=sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].input_conc)); - if (j == 0 ) { - sprintf(error_string,"Concentration data error for %s in solution input.", token1); - error_msg(error_string, CONTINUE); - return(ERROR); - } - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); -/* - * Read optional data - */ - strcpy(token1,token); -/* - * Check for units info - */ - if (check_units (token1, alk, FALSE, solution[n]->units, FALSE) == OK) { - if (check_units (token1, alk, FALSE, solution[n]->units, TRUE) == OK) { - solution[n]->totals[count_mass_balance].units = - string_hsave( token1 ); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); - } else { - return(ERROR); - } - } -/* - * Check for "as" followed by formula to be used for gfw - */ - strcpy(token1,token); - str_tolower(token1); - if ( strcmp(token1,"as") == 0 ) { - copy_token(token, &ptr, &l); - solution[n]->totals[count_mass_balance].as = string_hsave(token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); -/* - * Check for "gfw" followed by gram formula weight - */ - } else if (strcmp(token1,"gfw") == 0 ) { - if (copy_token(token, &ptr, &l) != DIGIT) { - error_msg("Expecting gram formula weight.", CONTINUE); - return(ERROR); - } else { - sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].gfw)); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); - } - } -/* - * Check for redox couple for pe - */ - if ( strcmp_nocase_arg1(token,"pe") == 0 ) { - solution[n]->totals[count_mass_balance].n_pe = pe_data_store (&(solution[n]->pe), token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); - } else if ( strstr(token,"/") != NULL) { - if (parse_couple(token) == OK ) { - solution[n]->totals[count_mass_balance].n_pe = - pe_data_store (&(solution[n]->pe), token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); - } else { - return(ERROR); - } - } -/* - * Must have phase - */ - solution[n]->totals[count_mass_balance].equation_name = string_hsave(token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) return(OK); -/* - * Check for saturation index - */ - j=sscanf(token,SCANFORMAT, &(solution[n]->totals[count_mass_balance].phase_si)); - if (j != 1 ) { - error_msg("Expected saturation index.", CONTINUE); - return(ERROR); - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int read_exchange_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for exchange species, parse equations - */ - int i; - int association; - char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; - - struct species *s_ptr; - struct elt_list *next_elt; - struct rxn_token *token_ptr; - LDBLE exchange_coef; - LDBLE offset; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "no_check", /* 0 */ - "check", /* 1 */ - "mb", /* 2 */ - "mass_balance", /* 3 */ - "log_k", /* 4 */ - "logk", /* 5 */ - "delta_h", /* 6 */ - "deltah", /* 7 */ - "analytical_expression", /* 8 */ - "a_e", /* 9 */ - "ae", /* 10 */ - "mole_balance", /* 11 */ - "gamma", /* 12 */ - "davies", /* 13 */ - "offset", /* 14 */ - "llnl_gamma", /* 15 */ - "add_logk", /* 16 */ - "add_log_k", /* 17 */ - "add_constant" /* 18 */ - }; - int count_opt_list = 19; - - association=TRUE; - s_ptr = NULL; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in EXCHANGE_SPECIES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* no_check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = FALSE; - break; - case 1: /* check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = TRUE; - break; - case 2: /* mb */ - case 3: /* mass_balance */ - case 11: /* mole_balance */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - count_elts = 0; - paren_count =0; - copy_token(token, &next_char, &i); - s_ptr->mole_balance = string_hsave(token); - ptr = token; - get_secondary_in_species(&ptr, 1.0); - s_ptr->next_secondary = elt_list_save(); -/* debug - for (i = 0; i < count_elts; i++) { - output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, - elt_list[i].coef); - } - */ - opt_save = OPTION_DEFAULT; - break; - case 4: /* log_k */ - case 5: /* logk */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_log_k_only(next_char, &s_ptr->logk[0]); - opt_save = OPTION_DEFAULT; - break; - case 6: /* delta_h */ - case 7: /* deltah */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); - opt_save = OPTION_DEFAULT; - break; - case 8: /* analytical_expression */ - case 9: /* a_e */ - case 10: /* ae */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_analytical_expression_only(next_char, &(s_ptr->logk[2])); - opt_save = OPTION_DEFAULT; - break; - case 12: /* gamma data */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->exch_gflag = 2; - i = sscanf(next_char,SCANFORMAT SCANFORMAT, &s_ptr->dha, &s_ptr->dhb ); - if (i < 2) { - sprintf(error_string, "Expecting 2 activity-" - "coefficient parameters, a and b."); - warning_msg(error_string); - } - if (s_ptr->dha == 0 && s_ptr->dhb == 0) { - s_ptr->dhb = 99.9; - s_ptr->exch_gflag = 1; - } - opt_save = OPTION_DEFAULT; - break; - case 13: /* davies eqn */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->exch_gflag = 1; - s_ptr->dha = 0; - s_ptr->dhb = 99.9; - opt_save = OPTION_DEFAULT; - break; - case 14: /* offset */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (sscanf(next_char, SCANFORMAT, &offset) != 1) { - error_msg("No offset for log K given", STOP); - } - s_ptr->logk[0] += offset; - opt_save = OPTION_DEFAULT; - break; - case 15: /* llnl_gamma */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->exch_gflag = 7; /* llnl D-H */ - i = sscanf(next_char,SCANFORMAT, &s_ptr->dha); - if (i < 1) { - sprintf(error_string, "Expecting activity-coefficient parameter, a."); - warning_msg(error_string); - } - opt_save = OPTION_DEFAULT; - break; - case 16: /* add_logk */ - case 17: /* add_log_k */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - /* read name */ - if (copy_token(token, &next_char, &i) == EMPTY) { - input_error++; - sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); - error_msg(error_string, CONTINUE); - break; - } - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); - /* read coef */ - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; - } - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case 18: /* add_constant */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - input_error++; - sprintf(error_string, "Expected the constant to add for log_K definition."); - error_msg(error_string, CONTINUE); - break; - } - /* set name */ - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); - /* read coef */ - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: -/* - * Get exchange species information and parse equation - */ - s_ptr = NULL; - if ( parse_eq(line, &next_elt, association ) == ERROR) { - parse_error++; - error_msg("Parsing equation.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - } -/* - * Get pointer to each species in the reaction, store new species if necessary - */ - trxn.token[0].s = s_store(trxn.token[0].name, trxn.token[0].z, TRUE); - for (i=1; inext_elt=next_elt; - for ( ; next_elt->elt != NULL; next_elt++) { - if ( strcmp (next_elt->elt->name,"C") == 0 ) { - trxn.token[0].s->carbon = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"H") == 0 ) { - trxn.token[0].s->h = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"O") == 0 ) { - trxn.token[0].s->o = next_elt->coef; - } - } -/* - * Find valence of cation from coefficients of reaction components - * Changed to be coefficient of exchanger - */ - exchange_coef = 0.0; - for (i=1; itype == EX) { - exchange_coef = trxn.token[i].coef; - } - } - trxn.token[0].s->equiv = exchange_coef; -/* - * Malloc space for species reaction - */ - trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); -/* - * Copy reaction to reaction for species - */ - token_ptr=trxn.token[0].s->rxn->token; - for (i=0; itype = EX; - s_ptr=trxn.token[0].s; -/* - * Set gamma data - */ - s_ptr->gflag = 4; - s_ptr->exch_gflag = 3; - s_ptr->dha = 0.0; - s_ptr->dhb = 0.0; - opt_save = OPTION_DEFAULT; -/* - * Save as a phase for inverse modeling only - */ - phase_ptr = phase_store(s_ptr->name); - if (phase_ptr == NULL) { - input_error++; - sprintf(error_string, "Copying exchange to phases."); - error_msg(error_string, CONTINUE); - } - phase_ptr->formula=s_ptr->name; - phase_ptr->check_equation = FALSE; - phase_ptr->type = EX; - phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt); - phase_ptr->rxn = rxn_dup(s_ptr->rxn); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_exchange(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads exchange data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, l, n, count_comps; - int n_user, n_user_end; - LDBLE conc; - char *ptr; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - struct exchange *exchange_ptr; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "equilibrate", /* 0 */ - "equil", /* 1 */ - "pitzer_exchange_gammas", /* 2 */ - "exchange_gammas", /* 3 */ - "gammas" /* 4 */ - }; - int count_opt_list = 5; -/* - * kin_exch is for exchangers, related to kinetically reacting minerals - * they are defined if "sites" is followed by mineral name: - * Z Manganite ('equi' or 'kine') 0.25 - * ^Name ^equi or kinetic mineral ^switch ^prop.factor - */ -/* - * Read exchange number and description - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Find space for exchange data - */ - exchange_ptr = exchange_search(n_user, &n, FALSE); - if (exchange_ptr != NULL) { - exchange_free(exchange_ptr); - } else { - n = count_exchange++; - space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); - } -/* - * Default values - */ - exchange_init(&(exchange[n]), n_user, n_user_end, description); - free_check_null(description); - if (use.exchange_in == FALSE) { - use.exchange_in = TRUE; - use.n_exchange_user = n_user; - } -/* - * Read exchange data - */ - count_comps = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in EXCHANGE keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* equilibrate */ - case 1: - /* - * Read solution to equilibrate with - */ - for (;;) { - i = copy_token(token, &next_char, &l); - if (i == DIGIT) { - sscanf(token, "%d", &exchange[n].n_solution); - exchange[n].new_def = TRUE; - exchange[n].solution_equilibria = TRUE; - break; - } - if (i == EMPTY) { - error_msg("Expected a solution number with which to equilibrate exchanger.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - break; - case 2: /* pitzer_exchange_gammas */ - case 3: /* exchange_gammas */ - case 4: /* gammas */ - exchange[n].pitzer_exchange_gammas = get_true_false(next_char, TRUE); - break; - case OPTION_DEFAULT: - exchange[n].comps = (struct exch_comp *) PHRQ_realloc(exchange[n].comps, (size_t) (count_comps + 1) * sizeof (struct exch_comp)); - if (exchange[n].comps == NULL) malloc_error(); - exchange[n].comps[count_comps].formula = NULL; - exchange[n].comps[count_comps].formula_totals = NULL; - exchange[n].comps[count_comps].phase_name = NULL; - exchange[n].comps[count_comps].phase_proportion = 0.0; - exchange[n].comps[count_comps].rate_name = NULL; - ptr=line; - i = copy_token(token, &ptr, &l); - /* - * Species formula is stored in token - */ - if (i != UPPER && token[0] != '[') { - error_msg("Expected exchanger name to begin with a capital letter.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - exchange[n].comps[count_comps].formula = string_hsave(token); - i = copy_token(token1, &ptr, &l); - if (i == DIGIT) { - /* - * Read exchange concentration - */ - - /* exchanger conc. is read directly .. */ - if ( sscanf(token1, SCANFORMAT, &conc) < 1) { - error_msg("Expected concentration of exchanger.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - j = copy_token(token1, &ptr, &l); - if( j == UPPER || j == LOWER) { - exchange[n].comps[count_comps].rate_name = string_hsave(token1); - if (copy_token(token1, &ptr, &l) != DIGIT) { - error_msg("Expected a coefficient to relate exchange to kinetic reaction.\n", CONTINUE); - input_error++; - break; - } - sscanf(token1, SCANFORMAT, &exchange[n].comps[count_comps].phase_proportion); - exchange[n].related_rate = TRUE; - } - /* - * Read equilibrium phase name or kinetics rate name - */ - } else if (i != EMPTY) { - - /* exchanger conc. is related to mineral or kinetics */ - exchange[n].comps[count_comps].phase_name = string_hsave(token1); - j = copy_token(token1, &ptr, &l); - if (j == DIGIT) { - exchange[n].related_phases = TRUE; - } else { - if (token1[0] == 'K' || token1[0] == 'k') { - exchange[n].comps[count_comps].rate_name = exchange[n].comps[count_comps].phase_name; - exchange[n].comps[count_comps].phase_name = NULL; - exchange[n].related_rate = TRUE; - } else if (token1[0] == 'E' || token1[0] == 'e') { - exchange[n].related_phases = TRUE; - } else { - error_msg("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate exchange to mineral or kinetic reaction.\n", CONTINUE); - input_error++; - break; - } - j = copy_token(token1, &ptr, &l); - } - - - if (j != DIGIT) { - error_msg("Expected a coefficient to relate exchanger to mineral or kinetic reaction.\n", CONTINUE); - input_error++; - break; - } - sscanf(token1, SCANFORMAT, &exchange[n].comps[count_comps].phase_proportion); - /* real conc must be defined in tidy_model */ - conc = 1.0; - } else { - error_msg("Expected concentration of exchanger, mineral name, or kinetic reaction name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - /* - * Accumulate elements in elt_list - */ - count_elts = 0; - paren_count = 0; - ptr = token; - get_elts_in_species(&ptr, conc); - /* - * save formula for adjusting number of exchange sites - */ - ptr = token; - get_token(&ptr, token1, &exchange[n].comps[count_comps].formula_z, &l); - exchange[n].comps[count_comps].formula_totals = elt_list_save(); - /* - * Save elt_list - */ - exchange[n].comps[count_comps].moles = conc; - exchange[n].comps[count_comps].totals = elt_list_save(); - exchange[n].comps[count_comps].charge_balance = 0.0; - count_comps++; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - exchange[n].count_comps = count_comps; - return(return_value); -} - -/* ---------------------------------------------------------------------- */ -int read_exchange_master_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads master species data from data file or input file - */ - int j, l; - char *ptr, *ptr1; - LDBLE z; - struct element *elts_ptr; - struct species *s_ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - for (;;) { - j=check_line ("Exchange species equation", FALSE, TRUE, TRUE, TRUE); - if (j == EOF || j == KEYWORD ) { - break; - } -/* - * Get element name with valence, allocate space, store - */ - ptr=line; -/* - * Get element name and save pointer to character string - */ - if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { - parse_error++; - error_msg("Reading element for master species.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - /* - if (token[0] == '[') { - ptr1 = token; - get_elt(&ptr, element, &l); - strcpy(token, element); - } - */ - replace ("(+", "(", token); -/* - * Delete master if it exists - */ - master_delete(token); -/* - * Increase pointer array, if necessary, and malloc space - */ - if (count_master >= max_master) { - space ((void **) ((void *) &master), count_master+1, &max_master, sizeof(struct master *)); - } - master[count_master] = master_alloc(); -/* - * Set type to EX - */ - master[count_master]->type = EX; -/* - * Save element name - */ - master[count_master]->elt = element_store ( token ); -/* - * Save pointer to species data for master species - */ - if ( ( copy_token(token, &ptr, &l) != UPPER ) && - token[0] != '[' && - ( strcmp_nocase_arg1(token, "e-") != 0 ) ) { - parse_error++; - error_msg("Reading master species name.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - s_ptr=s_search (token); - if (s_ptr != NULL) { - master[count_master]->s = s_ptr; - } else { - ptr1=token; - get_token(&ptr1, token1, &z, &l); - master[count_master]->s = s_store(token1, z, FALSE); - } -/* - * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES - */ - master[count_master]->primary=TRUE; - if ( strcmp(master[count_master]->elt->name,"E") != 0 ) { - elts_ptr = element_store(master[count_master]->elt->name); - elts_ptr->gfw = 0.0; - } - - count_master++; - if (count_master >= max_master) { - space ((void **) ((void *) &master), count_master, &max_master, - sizeof(struct master *)); - } - } - return (j); -} -/* ---------------------------------------------------------------------- */ -int read_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads gas phase data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int count_comps; - int n_user, n_user_end; - char *ptr; - char *description; - char token[MAX_LENGTH]; - struct gas_phase *gas_phase_ptr; - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "pressure", /* 0 */ - "volume", /* 1 */ - "temp", /* 2 */ - "temperature", /* 3 */ - "fixed_pressure", /* 4 */ - "fixed_volume", /* 5 */ - "equilibrium", /* 6 */ - "equilibrate", /* 7 */ - "equil" /* 8 */ - }; - int count_opt_list = 9; -/* - * Read gas_phase number - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Find old gas_phase or alloc space for new gas_phase - */ - gas_phase_ptr = gas_phase_search(n_user, &n); - if (gas_phase_ptr != NULL) { - gas_phase_free(gas_phase_ptr); - } else { - n=count_gas_phase; - count_gas_phase++; - space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); - } -/* - * Initialize - */ - gas_phase_init(&(gas_phase[n]), n_user, n_user_end, description); - free_check_null(description); -/* - * Set use data to first read - */ - if (use.gas_phase_in == FALSE) { - use.gas_phase_in = TRUE; - use.n_gas_phase_user = n_user; - } -/* - * Read phases - */ - count_comps = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in GAS_PHASE keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* pressure */ - sscanf( next_char,SCANFORMAT, &dummy); - gas_phase[n].total_p = (LDBLE) dummy; - break; - case 1: /* Volume */ - sscanf( next_char,SCANFORMAT, &(gas_phase[n].volume) ); - break; - case 2: /* Temperature */ - case 3: - j = sscanf( next_char,SCANFORMAT, &(gas_phase[n].temperature) ); - if (j == 1) { - gas_phase[n].temperature += 273.15; - } - break; - case 4: /* fixed_pressure */ - gas_phase[n].type = PRESSURE; - break; - case 5: /* fixed_volume */ - gas_phase[n].type = VOLUME; - break; - case 6: /* equilibrate */ - case 7: /* equilibrium */ - case 8: /* equil */ -/* - * Read solution to equilibrate with - */ - for (;;) { - i = copy_token(token, &next_char, &l); - if (i == DIGIT) { - sscanf(token, "%d", &gas_phase[n].n_solution); - gas_phase[n].new_def = TRUE; - gas_phase[n].solution_equilibria = TRUE; - break; - } - if (i == EMPTY) { - error_msg("Expected a solution number with which to equilibrate gas phase.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - break; - case OPTION_DEFAULT: -/* - * Make space, set default - */ - gas_phase[n].comps = (struct gas_comp *) PHRQ_realloc(gas_phase[n].comps, (size_t) (count_comps + 1) * sizeof(struct gas_comp)); - if (gas_phase[n].comps == NULL) malloc_error(); - gas_phase[n].comps[count_comps].p_read = 0.0; - gas_phase[n].comps[count_comps].moles = 0.0; - count_comps++; -/* - * Read name - */ - ptr = line; - copy_token(token, &ptr, &l); - gas_phase[n].comps[count_comps - 1].name = string_hsave(token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { - gas_phase[n].comps[count_comps - 1].p_read = NAN; - break; - } -/* - * Read initial partial pressure of gas - */ - - j=sscanf( token,SCANFORMAT, &(gas_phase[n].comps[count_comps - 1].p_read) ); - if (j != 1 ) { - error_msg("Expected partial pressure of gas in gas phase.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* - * Sort components by name (lowercase) - */ - gas_phase[n].count_comps = count_comps; - qsort (gas_phase[n].comps, - (size_t) count_comps, - (size_t) sizeof(struct gas_comp), - gas_comp_compare); - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_inverse(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads data for mass_balance calculations - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int n, j; - int n_user, n_user_end; - char *ptr; - char *description; - LDBLE range_max, inv_tol, water_uncertainty; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "solutions", /* 0 */ - "uncertainty", /* 1 */ - "uncertainties", /* 2 */ - "balances", /* 3 */ - "phase_data", /* 4 */ - "range", /* 5 */ - "minimal", /* 6 */ - "minimum", /* 7 */ - "balance", /* 8 */ - "bal", /* 9 */ - "sol", /* 10 */ - "phases", /* 11 */ - "ranges", /* 12 */ - "tolerance", /* 13 */ - "u_water", /* 14 */ - "uncertainty_water", /* 15 */ - "force", /* 16 */ - "force_solution", /* 17 */ - "force_solutions", /* 18 */ - "isotopes", /* 19 */ - "mineral_water", /* 20 */ - "phase", /* 21 */ - "multiple_precision", /* 22 */ - "mp_tolerance", /* 23 */ - "censor_mp" /* 24 */ - }; - int count_opt_list = 25; - - ptr=line; -/* - * Read solution number and description - */ - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Malloc space for solution data - */ - if (inverse_search(n_user, &n) != NULL) { - inverse_delete(n); - } - inverse_alloc(); - n = count_inverse - 1; -/* - * Initialize structure and use - */ - inverse[n].new_def = TRUE; - inverse[n].n_user = n_user; - inverse[n].range = FALSE; - inverse[n].range_max = 1000.; - inverse[n].tolerance = 1e-10; - inverse[n].minimal = FALSE; - inverse[n].description = description; - inverse[n].count_uncertainties = 1; - inverse[n].uncertainties[0] = 0.05; - inverse[n].count_ph_uncertainties = 1; - inverse[n].ph_uncertainties[0] = 0.05; - inverse[n].water_uncertainty = 0.0; - inverse[n].mineral_water = TRUE; - inverse[n].mp = FALSE; - inverse[n].mp_tolerance = 1e-12; - inverse[n].mp_censor = 1e-20; -/* - * Read data for inverse modeling - */ - opt_save = OPTION_ERROR; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - opt_save = opt; - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in INVERSE_MODELING keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* solutions */ - case 10: /* solution */ - inverse[n].solns = read_list_ints(&next_char, &inverse[n].count_solns, TRUE); - opt_save = OPTION_ERROR; - break; - case 1: /* uncertainty */ - case 2: /* uncertainties */ - inverse[n].uncertainties = (double *) free_check_null (inverse[n].uncertainties); - inverse[n].uncertainties = read_list_doubles(&next_char, &inverse[n].count_uncertainties); - opt_save = OPTION_ERROR; - break; - case 3: /* balances */ - case 8: /* balance */ - case 9: /* bal */ - read_inv_balances( &(inverse[n]), next_char ); - break; - case 4: /* phase_data */ - case 11: /* phases */ - case 21: /* phase */ - read_inv_phases( &(inverse[n]), next_char ); - break; - case 5: /* range */ - case 12: /* ranges */ - inverse[n].range = TRUE; - j = sscanf( next_char, SCANFORMAT, &range_max ) ; - if (j == 1 ) { - inverse[n].range_max = range_max; - } - opt_save = OPTION_ERROR; - break; - case 6: /* minimal */ - case 7: /* minimum */ - inverse[n].minimal = TRUE; - opt_save = OPTION_ERROR; - break; - case 13: /* tolerance */ - j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; - if (j == 1 ) { - inverse[n].tolerance = inv_tol; - } - opt_save = OPTION_ERROR; - break; - case 14: /* u_water */ - case 15: /* uncertainty_water */ - j = sscanf( next_char, SCANFORMAT, &water_uncertainty ) ; - if (j == 1 ) { - inverse[n].water_uncertainty = water_uncertainty; - } - opt_save = OPTION_ERROR; - break; - case 16: /* force */ - case 17: /* force_solution */ - case 18: /* force_solutions */ - inverse[n].force_solns = (int *) free_check_null (inverse[n].force_solns); - inverse[n].force_solns = read_list_t_f(&next_char, - &inverse[n].count_force_solns); - opt_save = OPTION_ERROR; - break; - case 19: /* isotope values */ - read_inv_isotopes( &(inverse[n]), next_char ); - break; - case 20: /* mineral_water */ - inverse[n].mineral_water = get_true_false(next_char, TRUE); - break; - case 22: /* multiple_precision */ - inverse[n].mp = get_true_false(next_char, TRUE); - break; - case 23: /* mp_tolerance */ - j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; - if (j == 1 ) { - inverse[n].mp_tolerance = fabs(inv_tol); - } - break; - case 24: /* censor_mp */ - j = sscanf( next_char, SCANFORMAT, &inv_tol ) ; - if (j == 1 ) { - inverse[n].mp_censor = fabs(inv_tol); - } - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* - * Default: soln 1 -> soln 2 - */ - if (inverse[n].count_solns == 0) { - inverse[n].solns = (int *) PHRQ_malloc( 2 * sizeof( int ) ); - if (inverse[n].solns == NULL) malloc_error(); - inverse[n].solns[0] = 1; - inverse[n].solns[1] = 2; - inverse[n].count_solns = 2; - } -/* - * Sort isotopes - */ - if (inverse[n].count_isotopes > 0) { - qsort (inverse[n].isotopes, - (size_t) inverse[n].count_isotopes, - (size_t) sizeof(struct inv_isotope), - inverse_isotope_compare); - } - - if (inverse[n].count_i_u > 0) { - qsort (inverse[n].i_u, - (size_t) inverse[n].count_i_u, - (size_t) sizeof(struct inv_isotope), - inverse_isotope_compare); - } - - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_inv_balances (struct inverse *inverse_ptr, char *ptr) -/* ---------------------------------------------------------------------- */ -{ - int j, l, count; - char token[MAX_LENGTH]; -/* - * Read element name - */ - j = copy_token(token, &ptr, &l); - if (j == EMPTY) { - return(OK); - } else if (j == LOWER && strcmp_nocase_arg1(token,"ph") != 0) { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } else if (strcmp_nocase_arg1(token, "ph") != 0) { - inverse_ptr->elts = (struct inv_elts *) PHRQ_realloc(inverse_ptr->elts, (size_t) (inverse_ptr->count_elts + 1) * sizeof( struct inv_elts)); - if (inverse_ptr->elts == NULL) malloc_error(); - replace("(+","(",token); - inverse_ptr->elts[inverse_ptr->count_elts].name = string_hsave(token); -/* - * Read element uncertainties - */ - inverse_ptr->elts[inverse_ptr->count_elts].uncertainties = read_list_doubles(&ptr, &count); - inverse_ptr->elts[inverse_ptr->count_elts].count_uncertainties = count; - inverse_ptr->count_elts++; - } else if (strcmp_nocase_arg1(token, "ph") == 0) { - inverse_ptr->ph_uncertainties = (double *) free_check_null (inverse_ptr->ph_uncertainties); - inverse_ptr->ph_uncertainties = read_list_doubles(&ptr, &count); - inverse_ptr->count_ph_uncertainties = count; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_inv_isotopes (struct inverse *inverse_ptr, char *ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l, l1, l2, count; - LDBLE isotope_number; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char *ptr1, *ptr2, *redox_name, *element_name; -/* - * Read element name - */ - ptr1 = ptr; - j = copy_token(token, &ptr1, &l); -/* - * ptr1 is start of uncertainties - */ - if (j == EMPTY) { - return(OK); - } else if (j != DIGIT) { - error_msg("Expecting isotope to begin with isotope number.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Read isotope name - */ - ptr2 = token; - get_num(&ptr2, &isotope_number); - if (ptr2[0] == '\0' || isupper((int) ptr2[0]) == FALSE) { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - - /* redox state name with parentheses */ - redox_name = string_hsave(ptr2); - - copy_token(token, &ptr2, &l1); - replace("("," ",token); - ptr2 = token; - - /* element name, without parentheses */ - copy_token(token1, &ptr2, &l2); - element_name = string_hsave(token1); - -/* - * add element name to inv_ptr->isotopes - */ - for (i = 0; i < inverse_ptr->count_isotopes; i++) { - if (element_name == inverse_ptr->isotopes[i].elt_name) break; - } - if (i == inverse_ptr->count_isotopes) { - inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->isotopes, (size_t) (inverse_ptr->count_isotopes + 1) * sizeof( struct inv_isotope)); - if (inverse_ptr->isotopes == NULL) malloc_error(); - inverse_ptr->isotopes[inverse_ptr->count_isotopes].isotope_number = isotope_number; - inverse_ptr->isotopes[inverse_ptr->count_isotopes].elt_name = element_name; - inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties == NULL) malloc_error(); - inverse_ptr->count_isotopes++; - } -/* - * add redox state name to inv_ptr->i_u - */ - inverse_ptr->i_u = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->i_u, (size_t) (inverse_ptr->count_i_u + 1) * sizeof( struct inv_isotope)); - if (inverse_ptr->i_u == NULL) malloc_error(); - inverse_ptr->i_u[inverse_ptr->count_i_u].elt_name = redox_name; - inverse_ptr->i_u[inverse_ptr->count_i_u].isotope_number = isotope_number; -/* - * Read isotope uncertainties - */ - inverse_ptr->i_u[inverse_ptr->count_i_u].uncertainties = read_list_doubles(&ptr1, &count); - inverse_ptr->i_u[inverse_ptr->count_i_u].count_uncertainties = count; - inverse_ptr->count_i_u++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_inv_phases (struct inverse *inverse_ptr, char *ptr) -/* ---------------------------------------------------------------------- */ -{ - int j, l; - int count_isotopes; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char *ptr1; - struct isotope *isotopes; -/* - * Read phase name - */ - j = copy_token(token, &ptr, &l); - if (j == EMPTY) return(OK); - inverse_ptr->phases = (struct inv_phases *) PHRQ_realloc(inverse_ptr->phases, (size_t) (inverse_ptr->count_phases + 1) * sizeof( struct inv_phases)); - if (inverse_ptr->phases == NULL) malloc_error(); - inverse_ptr->phases[inverse_ptr->count_phases].name = string_hsave(token); -/* - * Read constraint, force, and isotopes - */ - inverse_ptr->phases[inverse_ptr->count_phases].constraint = EITHER; - inverse_ptr->phases[inverse_ptr->count_phases].force = FALSE; - count_isotopes = 0; - isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); - if (isotopes == NULL) malloc_error(); - - for (;;) { - j = copy_token(token, &ptr, &l); - if (j == EMPTY) break; - strcpy(token1, token); - str_tolower(token1); - if (token1[0] == 'p' ) { - inverse_ptr->phases[inverse_ptr->count_phases].constraint = PRECIPITATE; - } else if (token1[0] == 'd' ) { - inverse_ptr->phases[inverse_ptr->count_phases].constraint = DISSOLVE; - } else if (token[0] == 'f' ) { - inverse_ptr->phases[inverse_ptr->count_phases].force = TRUE; - } else if (j == DIGIT) { -/* - * read isotope data - */ - isotopes = (struct isotope *) PHRQ_realloc( isotopes , (size_t) (count_isotopes + 1) * sizeof (struct isotope)); - if (isotopes == NULL) malloc_error(); - ptr1 = token; - - /* isotope number */ - get_num(&ptr1, &(isotopes[count_isotopes].isotope_number)); - if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { - sprintf(error_string, "Expecting element name: %s.", ptr1); - error_msg(error_string, CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - - /* element name */ - isotopes[count_isotopes].elt_name = string_hsave(ptr1); - - /* ratio */ - j = copy_token(token, &ptr, &l); - if (j != DIGIT ) { - error_msg("Expecting isotope ratio for phase.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio)); - - /* read and store isotope ratio uncertainty */ - if (copy_token(token, &ptr, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio_uncertainty)); - - count_isotopes++; - } else { - sprintf(error_string, "Unknown option for inverse modeling phase."); - warning_msg(error_string); - } - } - if (count_isotopes > 0) { - inverse_ptr->phases[inverse_ptr->count_phases].isotopes = isotopes; - inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = count_isotopes; - } else { - inverse_ptr->phases[inverse_ptr->count_phases].isotopes = NULL; - inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = 0; - isotopes = (struct isotope *) free_check_null(isotopes); - } - inverse_ptr->count_phases++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_kinetics (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads kinetics data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ -/* - * Read kinetics - */ - int i, j, k, l, count_comps, count_steps, count_list; - char *ptr; - char *description; - char token[MAX_LENGTH]; - int n; - int n_user, n_user_end; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; - LDBLE step, coef; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "tol", /* 0 */ - "m", /* 1 */ - "m0", /* 2 */ - "parms", /* 3 */ - "formula", /* 4 */ - "steps", /* 5 */ - "step_divide", /* 6 */ - "parameters", /* 7 */ - "runge-kutta", /* 8 */ - "runge_kutta", /* 9 */ - "rk", /* 10 */ - "bad_step_max", /* 11 */ - "cvode" /* 12 */ - }; - int count_opt_list = 13; - -/* - * Read kinetics number - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - -/* - * Find space for kinetics data - */ - kinetics_ptr = kinetics_search(n_user, &n, FALSE); - if (kinetics_ptr != NULL) { - kinetics_free(kinetics_ptr); - } else { - space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); - n = count_kinetics++; - } -/* - * Set use data to first read - */ - if (use.kinetics_in == FALSE) { - use.kinetics_in = TRUE; - use.n_kinetics_user = n_user; - } -/* - * Initialize - */ - kinetics_init(&(kinetics[n]), n_user, n_user_end, description); - free_check_null(description); - kinetics_ptr = &kinetics[n]; - - count_steps = 0; -/* - * Read kinetics data - */ - return_value = UNKNOWN; - kinetics_comp_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: /* allocate space, read new name */ - count_comps = kinetics_ptr->count_comps++; - kinetics_ptr->comps = (struct kinetics_comp *) PHRQ_realloc(kinetics_ptr->comps, (size_t) (count_comps + 1) * sizeof(struct kinetics_comp)); - if (kinetics_ptr->comps == NULL) malloc_error(); - kinetics_ptr->comps[count_comps].moles = 0; - ptr = line; - copy_token (token, &ptr, &l); - kinetics_ptr->comps[count_comps].rate_name = string_hsave(token); -#ifdef SKIP - kinetics_ptr->comps[count_comps].formula = kinetics_ptr->comps[count_comps].rate_name; -#endif - kinetics_ptr->comps[count_comps].tol = 1e-8; - kinetics_ptr->comps[count_comps].m0 = -1.0; - kinetics_ptr->comps[count_comps].m = -1.0; - kinetics_ptr->comps[count_comps].count_c_params = 0; - - kinetics_comp_ptr = &kinetics_ptr->comps[count_comps]; - kinetics_comp_ptr->d_params = (double *) PHRQ_malloc(sizeof(LDBLE)); - if (kinetics_comp_ptr->d_params == NULL) malloc_error(); - kinetics_comp_ptr->count_d_params = 0; - - kinetics_comp_ptr->c_params = (char **) PHRQ_malloc(sizeof(char *)); - if (kinetics_comp_ptr->c_params == NULL) malloc_error(); - kinetics_comp_ptr->count_c_params = 0; - - kinetics_comp_ptr->count_list = 0; - kinetics_comp_ptr->list = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (kinetics_comp_ptr->list == NULL) malloc_error(); - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in KINETICS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* tolerance */ - if (kinetics_comp_ptr == NULL) { - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } else { - if (copy_token (token, &next_char, &l) == DIGIT) { - kinetics_comp_ptr->tol = strtod(token, &ptr); - } else { - sprintf(error_string, "Expecting numerical value for tolerance."); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 1: /* m */ - if (kinetics_comp_ptr == NULL) { - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } else { - if (copy_token (token, &next_char, &l) == DIGIT) { - kinetics_comp_ptr->m = strtod(token, &ptr); - } else { - sprintf(error_string, "Expecting numerical value for moles of reactant."); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 2: /* m0 */ - if (kinetics_comp_ptr == NULL) { - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } else { - if (copy_token (token, &next_char, &l) == DIGIT) { - kinetics_comp_ptr->m0 = strtod(token, &ptr); - } else { - sprintf(error_string, "Expecting numerical value for initial moles of reactant."); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 3: /* parms */ - case 7: /* parameters */ - if (kinetics_comp_ptr == NULL) { - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } else { - while ((j = copy_token (token, &next_char, &l)) != EMPTY) { - /* - * Store a LDBLE parameter - */ - if (j == DIGIT) { - kinetics_comp_ptr->d_params = (double *) PHRQ_realloc(kinetics_comp_ptr->d_params, (size_t) (kinetics_comp_ptr->count_d_params + 1) * sizeof(LDBLE)); - if (kinetics_comp_ptr->d_params == NULL) malloc_error(); - kinetics_comp_ptr->d_params[kinetics_comp_ptr->count_d_params] = strtod(token, &ptr); - kinetics_comp_ptr->count_d_params++; - } else { - /* - * Store a character parameter - */ - kinetics_comp_ptr->c_params = (char **) PHRQ_realloc(kinetics_comp_ptr->c_params, (size_t) (kinetics_comp_ptr->count_c_params + 1) * sizeof(char *)); - if (kinetics_comp_ptr->c_params == NULL) malloc_error(); - kinetics_comp_ptr->c_params[kinetics_comp_ptr->count_c_params] = string_hsave(token); - kinetics_comp_ptr->count_c_params++; - } - } - } - break; - case 4: /* formula */ - if (kinetics_comp_ptr == NULL) { - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } else { - /* - * Store reactant name, default coefficient - */ - ptr = next_char; - while (copy_token (token, &ptr, &l) != EMPTY) { - if ( isalpha((int) token[0]) || (token[0] == '(' ) || (token[0] == '[' )) { - count_list = kinetics_comp_ptr->count_list++; - kinetics_comp_ptr->list = (struct name_coef *) PHRQ_realloc(kinetics_comp_ptr->list, - (size_t) (count_list + 1) * sizeof(struct name_coef)); - if (kinetics_comp_ptr->list == NULL) malloc_error(); - kinetics_comp_ptr->list[count_list].name = string_hsave(token); - kinetics_comp_ptr->list[count_list].coef = 1.0; - } else { - /* - * Store relative coefficient - */ - j = sscanf(token, SCANFORMAT, &coef); - if (j == 1 ) { - count_list = kinetics_comp_ptr->count_list - 1; - kinetics_comp_ptr->list[count_list].coef = coef; - } else { - error_msg("Reading relative coefficient of reactant.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - } - } - break; - case 5: /* steps */ - /* - * Read one or more kinetics time increments - */ - while ( (j = copy_token (token, &next_char, &l)) == DIGIT ) { - /* Read next step increment(s) */ -/* multiple, equal timesteps 15 aug. 2005 */ - if (replace("*"," ",token) == TRUE) { - if (sscanf(token,"%d" SCANFORMAT, &k, &step) == 2) { - for (i = 0; i < k; i++) { - count_steps++; - kinetics_ptr->steps = (double *) PHRQ_realloc(kinetics_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) malloc_error(); - kinetics_ptr->steps[kinetics_ptr->count_steps] = step; - kinetics_ptr->count_steps = count_steps; - } - } else { - input_error++; - error_msg("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", CONTINUE); - } - } else { - step = strtod(token, &ptr); - count_steps++; - kinetics_ptr->steps = (double *) PHRQ_realloc(kinetics_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) malloc_error(); - kinetics_ptr->steps[kinetics_ptr->count_steps] = step; - kinetics_ptr->count_steps = count_steps; - } - } - if (j == EMPTY) break; - /* - * Read number of increments - */ - if (kinetics_ptr->count_steps != 1) { - error_msg("To define equal time increments, only one total time should be defined.", CONTINUE); - input_error++; - break; - } - do { - j = sscanf(token, "%d", &i); - if (j == 1 && i > 0 ) { - kinetics_ptr->count_steps = -i; - break; - } else if (j == 1 && i <= 0 ) { - error_msg("Expecting positive number for number of equal " - "time increments for kinetics.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } while ( copy_token (token, &next_char, &l) != EMPTY ); - break; - case 6: /* step_divide */ - if (copy_token (token, &next_char, &l) == DIGIT) { - sscanf(token, SCANFORMAT, &kinetics_ptr->step_divide); - } else { - sprintf(error_string, "Expecting numerical value for step_divide."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 8: /* runge-kutta */ - case 9: /* runge_kutta */ - case 10: /* rk */ - j = copy_token (token, &next_char, &l); - if ( j == DIGIT) { - kinetics_ptr->rk = (int)strtod(token, &ptr); - } else if (j == EMPTY) { - } else { - sprintf(error_string, "Expecting order for Runge-Kutta method."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 11: /* bad_step_max */ - j = copy_token (token, &next_char, &l); - if ( j == DIGIT) { - kinetics_ptr->bad_step_max = (int)strtod(token, &ptr); - } else if (j == EMPTY) { - } else { - sprintf(error_string, "Expecting maximal bad steps number."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 12: /* cvode */ - kinetics[n].use_cvode = get_true_false(next_char, TRUE); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - -/* - * Default reactant - */ - for (i = 0; i < kinetics[n].count_comps; i++) { - if (kinetics[n].comps[i].count_list == 0) { - kinetics[n].comps[i].list[0].name = kinetics_ptr->comps[i].rate_name; - kinetics[n].comps[i].list[0].coef = 1; - kinetics[n].comps[i].count_list = 1; - } - } -/* - * Default 1 sec - */ - if (kinetics[n].count_steps == 0) { - kinetics[n].count_steps = 1; - kinetics[n].steps[0] = 1.0; - } -/* - * set defaults for moles - */ - for (i = 0; i < kinetics[n].count_comps; i++) { - if (kinetics[n].comps[i].m0 < 0) { - if (kinetics[n].comps[i].m < 0) { - kinetics[n].comps[i].m0 = 1; - } else { - kinetics[n].comps[i].m0 = kinetics[n].comps[i].m; - } - } - if (kinetics[n].comps[i].m < 0) { - kinetics[n].comps[i].m = kinetics[n].comps[i].m0; - } - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -LDBLE *read_list_doubles(char **ptr, int *count_doubles ) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads a list of LDBLE numbers until end of line is reached or - * a LDBLE can not be read from a token. - * - * Arguments: - * ptr entry: points to line to read from - * exit: points to next non-LDBLE token or end of line - * - * count_doubles exit: number of LDBLEs read - * - * Returns: - * pointer to a list of count_doubles LDBLEs. - */ - - LDBLE *LDBLE_list; - char token[MAX_LENGTH]; - LDBLE value; - char *ptr_save; - int l; - - LDBLE_list = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (LDBLE_list == NULL) malloc_error(); - *count_doubles = 0; - - ptr_save = *ptr; - while ( copy_token(token, ptr, &l) != EMPTY) { - if (sscanf(token,SCANFORMAT, &value) == 1) { - *count_doubles = *count_doubles + 1; - LDBLE_list = (LDBLE *) PHRQ_realloc(LDBLE_list, (size_t) (*count_doubles) * sizeof (LDBLE)); - if (LDBLE_list == NULL) malloc_error(); - LDBLE_list[ (*count_doubles) - 1] = value; - ptr_save = *ptr; - } else { - *ptr = ptr_save; - break; - } - } - return(LDBLE_list); -} -/* ---------------------------------------------------------------------- */ -int *read_list_ints (char **ptr, int *count_ints, int positive ) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads a list of int numbers until end of line is reached or - * an int can not be read from a token. - * - * Arguments: - * ptr entry: points to line to read from - * exit: points to next non-int token or end of line - * - * count_ints exit: number of LDBLEs read - * - * positive entry: if TRUE, expects to read only positive integers - * - * Returns: - * pointer to a list of count_ints ints. - */ - int *int_list; - char token[MAX_LENGTH]; - int value; - int l; - char *ptr_save; - - int_list = (int *) PHRQ_malloc(sizeof(int)); - if (int_list == NULL) malloc_error(); - *count_ints = 0; - - ptr_save = *ptr; - while ( copy_token(token, ptr, &l) != EMPTY) { - if (sscanf(token,"%d", &value) == 1) { - (*count_ints)++; - int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); - if (int_list == NULL) malloc_error(); - int_list[(*count_ints) - 1] = value; - if (value <= 0 && positive == TRUE) { - error_msg("Expected an integer greater than zero.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - ptr_save = *ptr; - } else { - *ptr = ptr_save; - break; - } - } - return(int_list); -} -/* ---------------------------------------------------------------------- */ -int *read_list_ints_range (char **ptr, int *count_ints, int positive, int *int_list ) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads a list of int numbers until end of line is reached or - * an int can not be read from a token. - * - * Arguments: - * ptr entry: points to line to read from - * exit: points to next non-int token or end of line - * - * count_ints entry: number of ints already in list - * - * positive entry: if TRUE, expects to read only positive integers - * - * Returns: - * pointer to a list of count_ints ints - */ - char token[MAX_LENGTH]; - int value, value1, value2; - int i, l; - char *ptr_save; - - if (int_list == NULL) { - int_list = (int *) PHRQ_malloc(sizeof(int)); - if (int_list == NULL) malloc_error(); - *count_ints = 0; - } - ptr_save = *ptr; - while ( copy_token(token, ptr, &l) != EMPTY) { - if (sscanf(token,"%d", &value) == 1) { - /* Read an integer */ - (*count_ints)++; - int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); - if (int_list == NULL) malloc_error(); - int_list[(*count_ints) - 1] = value; - if (value <= 0 && positive == TRUE) { - error_msg("Expected an integer greater than zero.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - /* Read range of integers */ - if (replace("-"," ",token) == TRUE) { - if (sscanf(token, "%d %d", &value1, &value2) != 2) { - error_msg("Expected an integer range n-m.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } else if (value2 < value1) { - error_msg("Expected an integer range n-m, with n <= m.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } else if (value2 <= 0 && positive == TRUE) { - error_msg("Expected an integer greater than zero.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } else { - for (i = value1 + 1; i <= value2; i++) { - (*count_ints)++; - int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); - if (int_list == NULL) malloc_error(); - int_list[(*count_ints) - 1] = i; - } - } - } - ptr_save = *ptr; - } else { - *ptr = ptr_save; - break; - } - } - return(int_list); -} -/* ---------------------------------------------------------------------- */ -int *read_list_t_f (char **ptr, int *count_ints ) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads a list of true and false until end of line is reached or - * until non- t or f is found - * - * Arguments: - * ptr entry: points to line to read from - * exit: points to next non-int token or end of line - * - * count_ints exit: number of LDBLEs read - * - * positive entry: if TRUE, expects to read only positive integers - * - * Returns: - * pointer to a list of count_ints ints. - */ - int *int_list; - char token[MAX_LENGTH]; - int value; - int l; - - int_list = (int *) PHRQ_malloc(sizeof(int)); - if (int_list == NULL) malloc_error(); - *count_ints = 0; - - while ( copy_token(token, ptr, &l) != EMPTY) { - str_tolower(token); - if (token[0] == 't') { - value = TRUE; - } else if (token[0] == 'f') { - value = FALSE; - } else { - error_msg("Expected TRUE or FALSE.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - (*count_ints)++; - int_list = (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof (int)); - if (int_list == NULL) malloc_error(); - int_list[(*count_ints) - 1] = value; - } - return(int_list); -} -/* ---------------------------------------------------------------------- */ -int read_log_k_only (char *ptr, LDBLE *log_k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read log k - */ - *log_k = 0.0; - replace("="," ",ptr); - if (sscanf(ptr,SCANFORMAT, log_k) < 1) { - input_error++; - error_msg("Expecting log k.", CONTINUE); - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_delta_h_only (char *ptr, LDBLE *delta_h, DELTA_H_UNIT *units) -/* ---------------------------------------------------------------------- */ -{ - int j, l, kilo, joul; - char token[MAX_LENGTH]; -/* - * Read delta H - */ - *delta_h = 0.0; - replace("="," ",ptr); - j = copy_token(token, &ptr, &l); - if (j == EMPTY) { - input_error++; - error_msg("Expecting numeric value for delta H.", CONTINUE); - return(ERROR); - } - if (sscanf(token,SCANFORMAT, delta_h) < 1) { - input_error++; - error_msg("Expecting numeric value for delta H.", CONTINUE); - return(ERROR); - } -/* - * Read delta H units - */ - j = copy_token(token, &ptr, &l); - *units = kjoules; - kilo = TRUE; - joul = TRUE; - if (j == EMPTY) { - return(OK); - } if (j == UPPER || j == LOWER) { - str_tolower(token); - if(strstr(token,"k") != token) { - /* convert to kilo */ - kilo = FALSE; - *delta_h /= 1000.; - } - if(strstr(token,"c") != NULL) { - /* convert to joules */ - *delta_h *= JOULES_PER_CALORIE; - joul = FALSE; - } - } - if (kilo == TRUE && joul == TRUE) { - *units = kjoules; - } else if (kilo == FALSE && joul == TRUE) { - *units = joules; - } else if (kilo == TRUE && joul == FALSE) { - *units = kcal; - } else if (kilo == FALSE && joul == FALSE) { - *units = cal; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_analytical_expression_only (char *ptr, LDBLE *log_k) -/* ---------------------------------------------------------------------- */ -{ - int j; -/* - * Read analytical expression - */ - for (j = 0; j < 5; j++) { - log_k[j] = 0.0; - } - j=sscanf(ptr,SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &(log_k[0]), &(log_k[1]), &(log_k[2]), &(log_k[3]), - &(log_k[4])); - if (j < 1) { - input_error++; - error_msg("Expecting numeric values for analytical expression.", CONTINUE); - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_incremental_reactions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Define flow only - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int j, l; - char *ptr; - char token[MAX_LENGTH]; - - ptr = line; - /* read keyword */ - copy_token(token, &ptr, &l); - - /* read true or false */ - incremental_reactions = get_true_false(ptr, TRUE); -/* - * find next keyword - */ - while ( (j = check_line("Subroutine Read", FALSE, TRUE, TRUE, FALSE)) != KEYWORD) { - /* empty, eof, keyword, print */ - if ( j == EOF) return(EOF); - sprintf(error_string,"Unknown input: %s", line); - error_msg(error_string, CONTINUE); - input_error++; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_master_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads master species data from data file or input file - */ - int j, i, l; - char *ptr, *ptr1; - LDBLE z; - struct element *elts_ptr; - struct species *s_ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - - elts_ptr = NULL; - for (;;) { - j=check_line ("Master species", FALSE, TRUE, TRUE, TRUE); - if (j == EOF || j == KEYWORD ) { - break; - } -/* - * Get element name with valence, allocate space, store - */ - ptr=line; -/* - * Get element name and save pointer to character string - */ - if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { - parse_error++; - error_msg ("Reading element for master species.", CONTINUE); - error_msg (line_save, CONTINUE); - continue; - } - /* - if (token[0] == '[') { - ptr1 = token; - get_elt(&ptr, element, &l); - strcpy(token, element); - } - */ - replace ("(+", "(", token); -/* - * Delete master if it exists - */ - master_delete(token); -/* - * Increase pointer array, if necessary, and malloc space - */ - if (count_master >= max_master) { - space ((void **) ((void *) &master), count_master+1, &max_master, sizeof(struct master *)); - } - master[count_master] = master_alloc(); -/* - * Set type to AQ - */ - master[count_master]->type = AQ; -/* - * Save element name - */ - master[count_master]->elt = element_store ( token ); -/* - * Save pointer to species data for master species - */ - if ( ( copy_token(token, &ptr, &l) != UPPER ) && - token[0] != '[' && - ( strcmp_nocase_arg1(token, "e-") != 0 ) ) { - parse_error++; - error_msg("Reading master species name.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - - s_ptr=s_search (token); - if (s_ptr != NULL) { - master[count_master]->s = s_ptr; - } else { - ptr1=token; - get_token(&ptr1, token1, &z, &l); - master[count_master]->s = s_store(token1, z, FALSE); - } - -/* - * Read alkalinity for species - */ - copy_token(token, &ptr, &l); - i = sscanf(token,SCANFORMAT, &master[count_master]->alk); - if (i != 1) { - input_error++; - if (elts_ptr != NULL) { - sprintf(error_string, "Expected alkalinity for master species, %s, in master species input.", elts_ptr->name); - } else { - sprintf(error_string, "Expected alkalinity for master species in master species input."); - } - error_msg(error_string, CONTINUE); - continue; - } -/* - * Read default gfw for species - */ - i = copy_token(token, &ptr, &l); - if (i == DIGIT) { - sscanf(token,SCANFORMAT, &master[count_master]->gfw); - } else if (i == UPPER) { - master[count_master]->gfw_formula = string_hsave(token); - } else { - input_error++; - if (elts_ptr != NULL) { - sprintf(error_string, "Expected gram formula weight for master species, %s, in master species input.", elts_ptr->name); - } else { - sprintf(error_string, "Expected gram formula weight for master species in master species input."); - } - error_msg(error_string, CONTINUE); - continue; - } -/* - * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES - */ - if ( strchr(master[count_master]->elt->name,'(') == NULL ) { - master[count_master]->primary=TRUE; - /* Read gram formula weight for primary */ - if ( strcmp(master[count_master]->elt->name,"E") != 0 ) { - elts_ptr = master[count_master]->elt; - i = copy_token(token, &ptr, &l); - if (i == DIGIT) { - sscanf(token,SCANFORMAT, &elts_ptr->gfw); - } else { - input_error++; - if (elts_ptr != NULL) { - sprintf(error_string,"Expected gram formula weight for element, %s.", elts_ptr->name); - } else { - sprintf(error_string,"Expected gram formula weight for element."); - } - - error_msg(error_string, CONTINUE); - continue; - } - } - } else { - master[count_master]->primary=FALSE; - } - count_master++; - if (count_master >= max_master) { - space ((void **) ((void *) &master), count_master, &max_master, - sizeof(struct master *)); - } - - } - return (j); -} -/* ---------------------------------------------------------------------- */ -int read_mix (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads mixing fractions - */ - int n, n_user, n_user_end; - int return_value; - int count_comps; - int n_solution; - LDBLE fraction; - int j, i, l; - char *ptr; - char token[MAX_LENGTH]; - char *description; - struct mix *mix_ptr; -/* - * Read mix number - */ - ptr = line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Update list of mixtures - */ - mix_ptr = mix_search(n_user, &n, FALSE); - if (mix_ptr != NULL) { - mix_free (&mix[n]); - } else { - n = count_mix++; - mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix)); - if (mix == NULL) malloc_error(); - } -/* - * Set use data to first read - */ - if (use.mix_in == FALSE) { - use.mix_in = TRUE; - use.n_mix_user = n_user; - } -/* - * Defaults - */ - mix[n].description = description; - mix[n].n_user = n_user; - mix[n].n_user_end = n_user_end; - mix[n].comps = NULL; - count_comps = 0; -/* - * Read mixture data - */ - for (;;) { - return_value = check_line("Mixture data",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) { - break; - } - ptr=line; -/* - * Read n_user - */ - i = copy_token(token, &ptr, &l); - if (i == DIGIT) { - sscanf(token,"%d ", &n_solution); - } else { - input_error++; - error_msg("Expected a solution number in mix input.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } -/* - * Read fraction for solution - */ - copy_token(token, &ptr, &l); - j = sscanf(token, SCANFORMAT, &fraction); - if (j != 1 ) { - input_error++; - error_msg("Expected a mixing fraction.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } -/* - * Malloc space - */ - count_comps++; - if (mix[n].comps == NULL) { - mix[n].comps = (struct mix_comp *) PHRQ_malloc( (size_t) sizeof (struct mix_comp)); - } else { - mix[n].comps = (struct mix_comp *) PHRQ_realloc(mix[n].comps, - (size_t) count_comps * sizeof (struct mix_comp)); - } - if (mix[n].comps == NULL) malloc_error(); -/* - * Save data - */ - mix[n].comps[count_comps - 1].n_solution = n_solution; - mix[n].comps[count_comps - 1].fraction = fraction; - } - if (count_comps <= 0) { - input_error++; - error_msg("Must define at least one solution number and mixing fraction for MIX input.", CONTINUE); - } - mix[n].count_comps = count_comps; - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_number_description (char *ptr, int *n_user, - int *n_user_end, char **description) -/* ---------------------------------------------------------------------- */ -{ - int l, n; - char token[MAX_LENGTH]; - char *ptr1; -/* - * Read user number - */ - copy_token(token, &ptr, &l); - ptr1 = ptr; - if (copy_token (token, &ptr, &l) != DIGIT) { -/* - sprintf(error_string, "No number given with %s keyword, " - "%s 1 assumed.", str, str); - warning_msg(error_string); - */ - *n_user=1; - *n_user_end = 1; - } else if (strstr(token,"-") != NULL) { - replace("-"," ",token); - n = sscanf(token,"%d%d", n_user, n_user_end); - if (n != 2) { - if (next_keyword >= 0) { - sprintf(error_string, "Reading number range for %s.", - keyword[next_keyword].name); - } else { - sprintf(error_string, "Reading number range for keyword."); - } - error_msg(error_string, CONTINUE); - input_error++; - } - ptr1 = ptr; - } else { - sscanf(token,"%d", n_user); - *n_user_end = *n_user; - ptr1 = ptr; - } -/* - * Read description - */ - for ( ; isspace((int) ptr1[0]) ;ptr1++ ); - *description = string_duplicate ( ptr1 ); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_phases (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for phases, parse equations - */ - int j, i, l; - int association; - char *ptr; - char token[MAX_LENGTH]; - struct phase *phase_ptr; - struct elt_list *next_elt; - struct rxn_token *token_ptr; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "no_check", /* 0 */ - "check", /* 1 */ - "log_k", /* 2 */ - "logk", /* 3 */ - "delta_h", /* 4 */ - "deltah", /* 5 */ - "analytical_expression", /* 6 */ - "a_e", /* 7 */ - "ae", /* 8 */ - "add_logk", /* 9 */ - "add_log_k", /* 10 */ - "add_constant" /* 11 */ - }; - int count_opt_list = 12; - - association=FALSE; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - phase_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in PHASES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* no_check */ - if (phase_ptr == NULL) break; - phase_ptr->check_equation = FALSE; - break; - case 1: /* check */ - if (phase_ptr == NULL) break; - phase_ptr->check_equation = TRUE; - break; - case 2: /* log_k */ - case 3: /* logk */ - if (phase_ptr == NULL) break; - read_log_k_only(next_char, &phase_ptr->logk[0]); - opt_save = OPTION_DEFAULT; - break; - case 4: /* delta_h */ - case 5: /* deltah */ - if (phase_ptr == NULL) break; - read_delta_h_only(next_char, &phase_ptr->logk[1], &phase_ptr->original_units); - opt_save = OPTION_DEFAULT; - break; - case 6: /* analytical_expression */ - case 7: /* a_e */ - case 8: /* ae */ - if (phase_ptr == NULL) break; - read_analytical_expression_only(next_char, &(phase_ptr->logk[2])); - opt_save = OPTION_DEFAULT; - break; - case 9: /* add_logk */ - case 10: /* add_log_k */ - if (phase_ptr == NULL) break; - if (phase_ptr->count_add_logk == 0) { - phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (phase_ptr->add_logk == NULL) malloc_error(); - } else { - phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, (size_t) ((phase_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (phase_ptr->add_logk == NULL) malloc_error(); - } - /* read name */ - if (copy_token(token, &next_char, &i) == EMPTY) { - input_error++; - sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); - error_msg(error_string, CONTINUE); - break; - } - phase_ptr->add_logk[phase_ptr->count_add_logk].name = string_hsave(token); - /* read coef */ - i = sscanf(next_char,SCANFORMAT, &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); - if (i <= 0) { - phase_ptr->add_logk[phase_ptr->count_add_logk].coef = 1; - } - phase_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case 11: /* add_constant */ - if (phase_ptr == NULL) break; - if (phase_ptr->count_add_logk == 0) { - phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (phase_ptr->add_logk == NULL) malloc_error(); - } else { - phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, (size_t) ((phase_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (phase_ptr->add_logk == NULL) malloc_error(); - } - i = sscanf(next_char,SCANFORMAT, &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); - if (i <= 0) { - input_error++; - sprintf(error_string, "Expected the constant to add for log_K definition."); - error_msg(error_string, CONTINUE); - break; - } - /* set name */ - phase_ptr->add_logk[phase_ptr->count_add_logk].name = string_hsave("XconstantX"); - /* read coef */ - phase_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: -/* - * Get element name and save pointer to character string - */ - phase_ptr = NULL; - ptr=line; - copy_token(token, &ptr, &l); -/* - * Get and parse equation - */ - j=check_line ("Phase equation", FALSE, TRUE, TRUE, TRUE); - if (j == EOF || j == KEYWORD ) { - return_value = j; - break; - } - if ( parse_eq(line, &next_elt, association ) == ERROR) { - parse_error++; - error_msg("Parsing equation.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - } - phase_ptr = phase_store (token); -/* - * Get pointer to each species in the reaction, store new species if necessary - */ - phase_ptr->formula = string_hsave(trxn.token[0].name ); - for (i=1; inext_elt=next_elt; -/* - * Malloc space for phase reaction - */ - phase_ptr->rxn = rxn_alloc (count_trxn+1); -/* - * Copy reaction to reaction for phase, first token (token[0]) is not used - * except to check that coef of phase formula = 1.0 - */ - token_ptr=phase_ptr->rxn->token; - /* token_ptr[0].coef=0; */ - token_ptr[0].coef=trxn.token[0].coef; - token_ptr[0].s=trxn.token[1].s; - for (i=1; itype = SOLID; - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads pure phase data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int j, n, l, return_value; - int count_pure_phases; - int n_user, n_user_end; - char *ptr; - char *description; - char token[MAX_LENGTH]; - - ptr=line; -/* - * Read pp_assemblage number - */ - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Find pp_assemblage or realloc space for pp_assemblage - */ - - if (pp_assemblage_search(n_user, &n) != NULL) { - pp_assemblage_free (&pp_assemblage[n]); - } else { - n=count_pp_assemblage++; - space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); - } -/* - * Set use data to first read - */ - if (use.pp_assemblage_in == FALSE) { - use.pp_assemblage_in = TRUE; - use.n_pp_assemblage_user = n_user; - } - - pp_assemblage_init(&(pp_assemblage[n]), n_user, n_user_end, description); - free_check_null(description); -/* - * Read phases - */ - count_pure_phases = 0; - for (;;) { - return_value = check_line("Pure phase data",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) { - break; - } -/* - * Make space, set default - */ - count_pure_phases++; - pp_assemblage[n].pure_phases = (struct pure_phase *) PHRQ_realloc(pp_assemblage[n].pure_phases, (size_t) (count_pure_phases) * sizeof(struct pure_phase)); - if (pp_assemblage[n].pure_phases == NULL) malloc_error(); - pp_assemblage[n].pure_phases[count_pure_phases-1].si = 0.0; - pp_assemblage[n].pure_phases[count_pure_phases-1].add_formula = NULL; - pp_assemblage[n].pure_phases[count_pure_phases-1].moles = 10.0; - pp_assemblage[n].pure_phases[count_pure_phases-1].dissolve_only = FALSE; - pp_assemblage[n].pure_phases[count_pure_phases-1].delta = 0.0; -/* - * Read name - */ - ptr = line; - copy_token(token, &ptr, &l); - pp_assemblage[n].pure_phases[count_pure_phases-1].name = string_hsave(token); - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; -/* - * Read saturation index - */ - j=sscanf(token,SCANFORMAT, &dummy); - pp_assemblage[n].pure_phases[count_pure_phases-1].si = (LDBLE) dummy; - if (j != 1 ) { - error_msg("Expected saturation index.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - continue; - } -/* - * Adding a reaction to the phase boundary - */ - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; - if ( j == UPPER || j == LOWER) { - pp_assemblage[n].pure_phases[count_pure_phases-1].add_formula = string_hsave(token); - j = copy_token(token, &ptr, &l); - } -/* - * Read amount - */ - if ( j == EMPTY) continue; - j=sscanf(token,SCANFORMAT, &dummy); - pp_assemblage[n].pure_phases[count_pure_phases-1].moles = (LDBLE) dummy; - if (j != 1 ) { - error_msg("Expected amount of mineral.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - continue; - } - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) continue; - str_tolower(token); - if (strstr(token,"d") == token) { - pp_assemblage[n].pure_phases[count_pure_phases-1].dissolve_only = TRUE; - } else { - error_msg("Unexpected data at end of equilibrium-phase definition.", CONTINUE); - input_error++; - continue; - } - } - pp_assemblage[n].count_comps = count_pure_phases; -/* - * Sort phases by name (lowercase) - */ - qsort (pp_assemblage[n].pure_phases, - (size_t) count_pure_phases, - (size_t) sizeof(struct pure_phase), - pure_phase_compare); - - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_reaction (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads reaction data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ -/* - * Read reaction - */ - int l; - char *ptr; - char *description; - char token[MAX_LENGTH]; - int n, return_value; - int n_user, n_user_end; - struct irrev *irrev_ptr; -/* - * Read reaction number - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - -/* - * Read reaction or realloc space for irrev reaction - */ - irrev_ptr = irrev_search(n_user, &n); - if (irrev_ptr != NULL) { - irrev_free(&irrev[n]); - } else { - n = count_irrev++; - irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev)); - if (irrev == NULL) malloc_error(); - } -/* - * Set use data to first read - */ - if (use.irrev_in == FALSE) { - use.irrev_in = TRUE; - use.n_irrev_user = n_user; - } -/* - * Defaults - */ - irrev[n].n_user = n_user; - irrev[n].n_user_end = n_user_end; - irrev[n].description = description; - irrev[n].steps = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (irrev[n].steps == NULL) malloc_error(); - irrev[n].list = (struct name_coef *) PHRQ_malloc((size_t) sizeof(struct name_coef)); - if (irrev[n].list == NULL) malloc_error(); - irrev[n].count_steps = 0; - irrev[n].count_list = 0; - irrev[n].units = string_hsave("Mol"); - irrev[n].elts = NULL; -/* - * Read reaction data - */ - for (;;) { -/* - * Read line - */ - return_value = check_line("Pure phase data",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) { - break; - } - ptr = line; - copy_token(token, &ptr, &l); - if (isalpha((int) token[0]) || (token[0] == '(') || (token[0] == '[') ) { -/* - * Read reactant information - */ - read_reaction_reactants(&(irrev[n])); - } else { -/* - * Read steps information - */ - read_reaction_steps(&(irrev[n])); - } - } -/* - * Default 1 mol of reaction - */ - if (irrev[n].count_steps == 0) { - irrev[n].count_steps = 1; - irrev[n].steps[0] = 1.0; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_reaction_reactants(struct irrev *irrev_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read reactants, may be a chemical formula or a pure_phase name - * followed by relative reaction coefficient, default 1.0. - * - */ - int j, l; - int count_list; - char token[MAX_LENGTH]; - LDBLE coef; - char *ptr; -/* - * Read one or more reactants - */ - ptr = line; - while (copy_token (token, &ptr, &l) != EMPTY) { -/* - * Store reactant name, default coefficient - */ - if ( isalpha((int) token[0]) || (token[0] == '(' ) || (token[0] == '[') ) { - irrev_ptr->count_list++; - count_list = irrev_ptr->count_list - 1; - irrev_ptr->list = (struct name_coef *) PHRQ_realloc(irrev_ptr->list, (size_t) (count_list + 1) * sizeof(struct name_coef)); - if (irrev_ptr->list == NULL) malloc_error(); - irrev_ptr->list[count_list].name = string_hsave(token); - irrev_ptr->list[count_list].coef = 1.0; -/* - * Store relative coefficient - */ - } else { - j = sscanf(token, SCANFORMAT, &coef); - if (j == 1 ) { - count_list = irrev_ptr->count_list - 1; - irrev_ptr->list[count_list].coef = coef; - } else { - error_msg("Reading relative coefficient of reactant.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_reaction_steps(struct irrev *irrev_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read amount(s) of irrev reactions in one of three forms: - * - * 6 millimoles in 6 steps or - * - * 1 2 3 4 5 6 millimoles or - * - * 6*1 millimoles - * INCREMENTAL_REACTIONS - */ - int i, j, l, n; - int count_steps; - char *ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - LDBLE step, value; - - ptr = line; - count_steps = irrev_ptr->count_steps; -/* - * Read one or more reaction increments - */ - for (;;) { - if ( copy_token (token, &ptr, &l) == EMPTY ) { - return(OK); - } -/* - * Read next step increment - */ -/* begin modif 29 july 2005... */ - if (replace("*"," ",token) == TRUE) { - if (sscanf(token,"%d" SCANFORMAT, &n, &value) == 2) { - for (i = 0; i < n; i++) { - count_steps++; - irrev_ptr->steps = (double *) PHRQ_realloc(irrev_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); - if (irrev_ptr->steps == NULL) malloc_error(); - irrev_ptr->steps[irrev_ptr->count_steps] = value; - irrev_ptr->count_steps = count_steps; - } - } else { - input_error++; - error_msg("Format error in multiple, equal REACTION steps.\nCorrect is (for example): 0.2 4*0.1 2*0.5 0.3\n", CONTINUE); - } - } else { - j = sscanf(token, SCANFORMAT, &step); - if (j == 1 ) { - count_steps++; - irrev_ptr->steps = (double *) PHRQ_realloc(irrev_ptr->steps, (size_t) count_steps * sizeof(LDBLE)); - if (irrev_ptr->steps == NULL) malloc_error(); - irrev_ptr->steps[irrev_ptr->count_steps] = step; - irrev_ptr->count_steps = count_steps; - } else { - break; - } - } -/* ...end modif 29 july 2005 */ - } -/* - * Read units - */ - strcpy(token1, token); - strcat(token1,"/l"); - if (check_units(token1, FALSE, FALSE, NULL, FALSE) == OK) { - replace("/l", "", token1); - if (strstr(token1, "Mol") == NULL) { - sprintf(error_string, "Units of steps not in moles, %s.", token); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } else { - irrev_ptr->units = string_hsave(token1); - } - if ( copy_token (token, &ptr, &l) == EMPTY ) { - return(OK); - } - } -/* - * Read number of equal increments, store as negative integer - */ - if (count_steps != 1) { - error_msg("To define equal increments, only one reaction increment should be defined.", CONTINUE); - input_error++; - return(ERROR); - } - do { - j = sscanf(token, "%d", &i); - if (j == 1 && i > 0 ) { - irrev_ptr->count_steps = -i; - return(OK); - } else if (j == 1 && i <= 0 ) { - break; - } - } while ( copy_token (token, &ptr, &l) != EMPTY ); - - error_msg("Expecting positive number for number of equal " - "increments to add.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); -} -/* ---------------------------------------------------------------------- */ -int read_save (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution, mix, irreversible reaction, and pure phases to use - * in reaction calculation - */ - int i, l, n, n_user, n_user_end; - char *ptr; - char token[MAX_LENGTH]; -/* - * Read "save" - */ - ptr = line; - copy_token (token, &ptr, &l); -/* - * Read keyword - */ - copy_token (token, &ptr, &l); - check_key (token); - switch (next_keyword) { - case -1: /* Have not read line with keyword */ - case 0: /* End encountered */ - case 1: /* EOF encountered */ - case 2: /* Read aqueous model */ - case 3: /* Read master species */ - case 5: /* Phases */ - case 7: /* Reaction */ - case 8: /* Mix */ - case 9: /* Use */ - case 10: /* Save */ - case 11: - case 12: - case 14: - case 15: - case 17: - case 18: - case 21: - case 22: - case 23: - case 24: - case 25: - case 30: - case 31: - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - case 38: - case 39: - input_error++; - error_msg("Expecting keyword solution, equilibrium_phases, exchange, surface, kinetics, gas_phase, or solid_solutions.", CONTINUE); - error_msg(line_save, CONTINUE); - check_line("End of save",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(ERROR); - } -/* - * Read number - */ - for (;;) { - i = copy_token (token, &ptr, &l); - if (i == DIGIT) { - replace("-"," ",token); - n = sscanf(token,"%d%d",&n_user, &n_user_end); - if (n == 1) { - n_user_end = n_user; - } - if (n_user < 0) { - error_msg("Number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - break; - } else if ( i == EMPTY ) { - sprintf(error_string, "No number given, 1 assumed."); - warning_msg(error_string); - n_user = 1; - n_user_end = 1; - break; - } } - switch (next_keyword) { - case 4: /* Solution */ - save.solution = TRUE; - save.n_solution_user = n_user; - save.n_solution_user_end = n_user_end; - break; - case 6: /* Pure phases */ - case 26: - case 27: - case 28: - case 29: - save.pp_assemblage = TRUE; - save.n_pp_assemblage_user = n_user; - save.n_pp_assemblage_user_end = n_user_end; - break; - case 13: /* exchange */ - save.exchange = TRUE; - save.n_exchange_user = n_user; - save.n_exchange_user_end = n_user_end; - break; - case 16: /* surface */ - save.surface = TRUE; - save.n_surface_user = n_user; - save.n_surface_user_end = n_user_end; - break; - case 19: /* gas_phase */ - save.gas_phase = TRUE; - save.n_gas_phase_user = n_user; - save.n_gas_phase_user_end = n_user_end; - break; - case 40: /* solid_solutions */ - case 41: /* solid_solution */ - save.s_s_assemblage = TRUE; - save.n_s_s_assemblage_user = n_user; - save.n_s_s_assemblage_user_end = n_user_end; - break; - } - check_line("End of save",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_selected_output (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for to output to flat file - */ - int value; - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "file", /* 0 */ - "totals", /* 1 */ - "molalities", /* 2 */ - "activities", /* 3 */ - "pure_phases", /* 4 */ - "si", /* 5 */ - "saturation_indices", /* 6 */ - "gases", /* 7 */ - "equilibrium_phases", /* 8 */ - "equilibria", /* 9 */ - "equilibrium", /* 10 */ - "pure", /* 11 */ - "inverse", /* 12 */ - "kinetic_reactants", /* 13 */ - "kinetics", /* 14 */ - "solid_solutions", /* 15 */ - "inverse_modeling", /* 16 */ - "reset", /* 17 */ - "simulation", /* 18 */ - "sim", /* 19 */ - "state", /* 20 */ - "solution", /* 21 */ - "soln", /* 22 */ - "distance", /* 23 */ - "dist", /* 24 */ - "time", /* 25 */ - "step", /* 26 */ - "reaction", /* 27 */ - "rxn", /* 28 */ - "temperature", /* 29 */ - "temp", /* 30 */ - "ph", /* 31 */ - "pe", /* 32 */ - "alkalinity", /* 33 */ - "alk", /* 34 */ - "ionic_strength", /* 35 */ - "mu", /* 36 */ - "water", /* 37 */ - "high_precision", /* 38 */ - "user_punch", /* 39 */ - "mol", /* 40 */ - "kin", /* 41 */ - "charge_balance", /* 42 */ - "percent_error", /* 43 */ - "selected_out", /* 44 */ - "selected_output", /* 45 */ - "isotopes", /* 46 */ - "calculate_values" /* 47 */ - }; - int count_opt_list = 48; - - int i, l; - char file_name[MAX_LENGTH], token[MAX_LENGTH]; - static int have_punch_name = FALSE; - - punch.in = TRUE; - punch.new_def = TRUE; - punch.count_totals = 0; - punch.count_molalities = 0; - punch.count_activities = 0; - punch.count_pure_phases = 0; - punch.count_si = 0; - punch.count_gases = 0; - punch.count_kinetics = 0; - punch.count_s_s = 0; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_ERROR; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - opt_save = opt; - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* file name */ - /* copy_token(file_name, &next_char, &l); */ - string_trim(next_char); - strcpy(file_name, next_char); - have_punch_name = TRUE; - if (output_open(OUTPUT_PUNCH, file_name) != OK) { - sprintf(error_string, "Can't open file, %s.", file_name); - input_error++; - error_msg(error_string, CONTINUE); - } - opt_save = OPTION_ERROR; - break; - case 1: /* totals */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - if (i != UPPER && token[0] != '[') { - sprintf(error_string, "Expected element name to" - " begin with upper case letter."); - warning_msg(error_string); - } else { - punch.count_totals++; - punch.totals = (struct name_master *) PHRQ_realloc(punch.totals, (size_t) punch.count_totals * sizeof(struct name_master)); - if (punch.totals == NULL) malloc_error(); - punch.totals[punch.count_totals - 1].name = string_hsave(token); - } - } - break; - case 2: /* molalities */ - case 40: /* mol */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - if (i != UPPER && token[0] != '(' && (token[0] != '[')) { - sprintf(error_string, "Expected species name to" - " begin with upper case letter."); - warning_msg(error_string); - } else { - punch.count_molalities++; - punch.molalities = (struct name_species *) PHRQ_realloc(punch.molalities, (size_t) punch.count_molalities * sizeof(struct name_species)); - if (punch.molalities == NULL) malloc_error(); - punch.molalities[punch.count_molalities - 1].name = - string_hsave(token); - } - } - break; - case 3: /* activities */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - if (i != UPPER && token[0] != '(' && (token[0] != '[')) { - sprintf(error_string, "Expected species name to" - " begin with upper case letter."); - warning_msg(error_string); - } else { - punch.count_activities++; - punch.activities = (struct name_species *) PHRQ_realloc(punch.activities, (size_t) punch.count_activities * sizeof(struct name_species)); - if (punch.activities == NULL) malloc_error(); - punch.activities[punch.count_activities - 1].name = - string_hsave(token); - } - } - break; - case 4: /* pure_phases */ - case 8: /* equilibrium_phases */ - case 9: /* equilibria */ - case 10: /* equilibrium */ - case 11: /* pure */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_pure_phases++; - punch.pure_phases = (struct name_phase *) PHRQ_realloc(punch.pure_phases, (size_t) punch.count_pure_phases * sizeof(struct name_phase)); - if (punch.pure_phases == NULL) malloc_error(); - punch.pure_phases[punch.count_pure_phases - 1].name = string_hsave(token); - } - break; - case 5: /* si */ - case 6: /* saturation_index */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_si++; - punch.si = (struct name_phase *) PHRQ_realloc(punch.si, (size_t) punch.count_si * sizeof(struct name_phase)); - if (punch.si == NULL) malloc_error(); - punch.si[punch.count_si - 1].name = string_hsave(token); - } - break; - case 7: /* gases */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_gases++; - punch.gases = (struct name_phase *) PHRQ_realloc(punch.gases, (size_t) punch.count_gases * sizeof(struct name_phase)); - if (punch.gases == NULL) malloc_error(); - punch.gases[punch.count_gases - 1].name = string_hsave(token); - } - break; - case 12: /* inverse */ - case 16: /* inverse_modeling */ - punch.inverse = get_true_false(next_char, TRUE); - break; - case 13: /* kinetic_reactants */ - case 14: /* kinetics */ - case 41: /* kin */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_kinetics++; - punch.kinetics = (struct name_phase *) PHRQ_realloc(punch.kinetics, (size_t) punch.count_kinetics * sizeof(struct name_phase)); - if (punch.kinetics == NULL) malloc_error(); - punch.kinetics[punch.count_kinetics - 1].name = string_hsave(token); - } - break; - case 15: /* solid_solutions */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_s_s++; - punch.s_s = (struct name_phase *) PHRQ_realloc(punch.s_s, (size_t) punch.count_s_s * sizeof(struct name_phase)); - if (punch.s_s == NULL) malloc_error(); - punch.s_s[punch.count_s_s - 1].name = string_hsave(token); - } - break; - case 46: /* isotopes */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - if (i != UPPER && token[0] != '[') { - sprintf(error_string, "Expected element name to" - " begin with upper case letter."); - warning_msg(error_string); - } else { - punch.count_isotopes++; - punch.isotopes = (struct name_master *) PHRQ_realloc(punch.isotopes, (size_t) punch.count_isotopes * sizeof(struct name_master)); - if (punch.isotopes == NULL) malloc_error(); - punch.isotopes[punch.count_isotopes - 1].name = string_hsave(token); - } - } - break; - case 47: /* calculate_values */ - while( (i = copy_token(token, &next_char, &l)) != EMPTY) { - punch.count_calculate_values++; - punch.calculate_values = (struct name_master *) PHRQ_realloc(punch.calculate_values, (size_t) punch.count_calculate_values * sizeof(struct name_master)); - if (punch.calculate_values == NULL) malloc_error(); - punch.calculate_values[punch.count_calculate_values - 1].name = string_hsave(token); - } - break; - case 17: /* reset */ - value = get_true_false(next_char, TRUE); - punch.sim = value; - punch.state = value; - punch.soln = value; - punch.dist = value; - punch.time = value; - punch.step = value; - punch.rxn = value; - punch.temp = value; - punch.ph = value; - punch.pe = value; - punch.alk = value; - punch.mu = value; - punch.water = value; - punch.charge_balance = value; - punch.percent_error = value; - break; - case 18: /* simulation */ - case 19: /* sim */ - punch.sim = get_true_false(next_char, TRUE); - break; - case 20: /* state */ - punch.state = get_true_false(next_char, TRUE); - break; - case 21: /* solution */ - case 22: /* soln */ - punch.soln = get_true_false(next_char, TRUE); - break; - case 23: /* distance */ - case 24: /* dist */ - punch.dist = get_true_false(next_char, TRUE); - break; - case 25: /* time */ - punch.time = get_true_false(next_char, TRUE); - break; - case 26: /* step */ - punch.step = get_true_false(next_char, TRUE); - break; - case 27: /* reaction */ - case 28: /* rxn */ - punch.rxn = get_true_false(next_char, TRUE); - break; - case 29: /* temperature */ - case 30: /* temp */ - punch.temp = get_true_false(next_char, TRUE); - break; - case 31: /* ph */ - punch.ph = get_true_false(next_char, TRUE); - break; - case 32: /* pe */ - punch.pe = get_true_false(next_char, TRUE); - break; - case 33: /* alkalinity */ - case 34: /* alk */ - punch.alk = get_true_false(next_char, TRUE); - break; - case 35: /* ionic strength */ - case 36: /* mu */ - punch.mu = get_true_false(next_char, TRUE); - break; - case 37: /* water */ - punch.water = get_true_false(next_char, TRUE); - break; - case 38: /* high_precision */ - punch.high_precision = get_true_false(next_char, TRUE); - if (punch.high_precision == TRUE && convergence_tolerance > 1e-12) { - convergence_tolerance = 1e-12; - } - break; - case 39: /* user_punch */ - punch.user_punch = get_true_false(next_char, TRUE); - break; - case 42: /* charge_balance */ - punch.charge_balance = get_true_false(next_char, TRUE); - break; - case 43: /* percent_error */ - punch.percent_error = get_true_false(next_char, TRUE); - break; - case 44: /* selected_out */ - case 45: /* selected_output */ - pr.punch = get_true_false(next_char, TRUE); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - if (!have_punch_name) { - if (output_open(OUTPUT_PUNCH, "selected.out") != OK) { - sprintf(error_string, "Can't open file, %s.", "selected.out"); - input_error++; - error_msg(error_string, CONTINUE); - } - } - - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_solution(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int n_user, n_user_end; - int default_pe, alk; - int count_isotopes; - int max_mass_balance, count_mass_balance; - char *ptr, *ptr1; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "temp", /* 0 */ - "temperature", /* 1 */ - "dens", /* 2 */ - "density", /* 3 */ - "units", /* 4 */ - "redox", /* 5 */ - "ph", /* 6 */ - "pe", /* 7 */ - "unit", /* 8 */ - "isotope", /* 9 */ - "water" /* 10 */ - - }; - int count_opt_list = 11; -/* - * Read solution number and description - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Malloc space for solution data - */ - if (solution_bsearch(n_user, &n, FALSE) != NULL) { - solution_free(solution[n]); - } else { - n=count_solution++; - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); - } - } - solution[n] = solution_alloc(); - - solution[n]->n_user = n_user; - solution[n]->n_user_end = n_user_end; - if (use.solution_in == FALSE) { - use.solution_in = TRUE; - use.n_solution_user = n_user; - } - max_mass_balance=MAX_MASS_BALANCE; -/* - * Set default ph, temp, density, pe, units - */ - solution[n]->description = description; - solution[n]->tc=25.0; - solution[n]->ph=7.0; - solution[n]->density=1.0; - solution[n]->solution_pe = 4.0; - solution[n]->mass_water=1.0; - solution[n]->ah2o = 1.0; - solution[n]->mu = 1e-7; - solution[n]->cb = 0.0; - default_pe = 0; - solution[n]->units = string_hsave( "mMol/kgw" ); - solution[n]->totals[0].description=NULL; - count_mass_balance=0; - count_isotopes = 0; -/* - * Read concentration data - */ - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - ptr = next_char; - if (copy_token(token, &ptr, &l) == DIGIT) { - opt = 9; - } - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLUTION keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* temperature */ - case 1: - if (sscanf(next_char,SCANFORMAT, &(solution[n]->tc)) != 1) { - solution[n]->tc = 25; - } - break; - case 2: /* density */ - case 3: - sscanf(next_char,SCANFORMAT, &(solution[n]->density)); - break; - case 4: /* units */ - case 8: /* unit */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (check_units (token, FALSE, FALSE, solution[n]->units, TRUE) == OK) { - solution[n]->units = string_hsave(token); - } else { - input_error++; - } - break; - case 5: /* redox */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (parse_couple(token) == OK) { - default_pe = pe_data_store (&(solution[n]->pe), token); - } else { - input_error++; - } - break; - case 6: /* ph */ - if ( read_conc(n, count_mass_balance, line) == ERROR ) { - input_error++; - break; - } - solution[n]->ph = solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { - break; - } - solution[n]->totals[count_mass_balance].description = string_hsave("H(1)"); - count_mass_balance++; - break; - case 7: /* pe */ - if ( read_conc(n, count_mass_balance, line) == ERROR ) { - input_error++; - break; - } - solution[n]->solution_pe = solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { - break; - } - solution[n]->totals[count_mass_balance].description = string_hsave("E"); - count_mass_balance++; - break; - case 9: /* isotope */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - solution[n]->isotopes = (struct isotope *) PHRQ_realloc(solution[n]->isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); - if (solution[n]->isotopes == NULL) malloc_error(); - - /* read and save element name */ - ptr1 = token; - get_num(&ptr1, &(solution[n]->isotopes[count_isotopes].isotope_number)); - if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - solution[n]->isotopes[count_isotopes].elt_name = string_hsave(ptr1); - - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio)); - - solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; - - /* read and store isotope ratio uncertainty */ - if ((j = copy_token(token, &next_char, &l)) != EMPTY) { - if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio_uncertainty)); - } - count_isotopes++; - break; - case 10: /* water */ - j = copy_token (token, &next_char, &l); - if (j == EMPTY) { - solution[n]->mass_water=1.0; - } else if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } else { - sscanf(token, SCANFORMAT, &dummy); - solution[n]->mass_water = (LDBLE) dummy; - } - break; - case OPTION_DEFAULT: -/* - * Read concentration - */ - if ( read_conc(n, count_mass_balance, line) == ERROR ) { - input_error++; - break; - } - count_mass_balance++; - break; - } - if (count_mass_balance + 1 >= max_mass_balance) { - space ((void **) &(solution[n]->totals), count_mass_balance + 1, - &max_mass_balance, sizeof (struct conc)); - } - if (return_value == EOF || return_value == KEYWORD) break; - } -#ifdef SKIP -/* - * Sort totals by description - */ - qsort (solution[n]->totals, - (size_t) count_mass_balance, - (size_t) sizeof(struct conc), - conc_compare); -#endif -/* - * fix up default units and default pe - */ - for (i=0; i < count_mass_balance; i++) { - strcpy(token, solution[n]->totals[i].description); - str_tolower(token); - if (solution[n]->totals[i].units == NULL) { - solution[n]->totals[i].units = solution[n]->units; - } else { - alk = FALSE; - if (strstr(token, "alk") == token) alk = TRUE; - strcpy(token1, solution[n]->totals[i].units); - if (check_units (token1, alk, TRUE, solution[n]->units, TRUE) == ERROR ) { - input_error++; - } else { - solution[n]->totals[i].units = string_hsave(token1); - } - } - if (solution[n]->totals[i].n_pe < 0) { - solution[n]->totals[i].n_pe = default_pe; - } - } - solution[n]->default_pe = default_pe; -/* - * Mark end of solution - */ - solution[n]->totals[count_mass_balance].description = NULL; - solution[n]->count_isotopes = count_isotopes; -#ifdef SKIP - if (count_isotopes > 0) { - qsort (solution[n]->isotopes, - (size_t) count_isotopes, - (size_t) sizeof(struct isotope), - isotope_compare); - } else { - solution[n]->isotopes = free_check_null(solution[n]->isotopes); - } -#endif - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for aqueous species, parse equations - */ - int i; - int association; - struct species *s_ptr; - struct elt_list *next_elt; - char *ptr, token[MAX_LENGTH]; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "no_check", /* 0 */ - "check", /* 1 */ - "gamma", /* 2 */ - "mb", /* 3 */ - "mass_balance", /* 4 */ - "log_k", /* 5 */ - "logk", /* 6 */ - "delta_h", /* 7 */ - "deltah", /* 8 */ - "analytical_expression", /* 9 */ - "a_e", /* 10 */ - "ae", /* 11 */ - "mole_balance", /* 12 */ - "llnl_gamma", /* 13 */ - "co2_llnl_gamma", /* 14 */ - "activity_water", /* 15 */ - "add_logk", /* 16 */ - "add_log_k", /* 17 */ - "add_constant" /* 18 */ - }; - int count_opt_list = 19; - - association=TRUE; - s_ptr = NULL; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SPECIES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* no_check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = FALSE; - break; - case 1: /* check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = TRUE; - break; - case 2: /* gamma data */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->gflag = 2; /* Wateq D-H */ - i = sscanf(next_char,SCANFORMAT SCANFORMAT, &s_ptr->dha, &s_ptr->dhb ); - if (i < 2) { - sprintf(error_string, "Expecting 2 activity-" - "coefficient parameters, a and b."); - warning_msg(error_string); - } - opt_save = OPTION_DEFAULT; - break; - case 3: /* mb */ - case 4: /* mass_balance */ - case 12: /* mole_balance */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - count_elts = 0; - paren_count =0; - copy_token(token, &next_char, &i); - s_ptr->mole_balance = string_hsave(token); - ptr = token; - get_secondary_in_species(&ptr, 1.0); - s_ptr->next_secondary = elt_list_save(); -/* debug - for (i = 0; i < count_elts; i++) { - output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, - elt_list[i].coef); - } - */ - opt_save = OPTION_DEFAULT; - break; - case 5: /* log_k */ - case 6: /* logk */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_log_k_only(next_char, &s_ptr->logk[0]); - opt_save = OPTION_DEFAULT; - break; - case 7: /* delta_h */ - case 8: /* deltah */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); - opt_save = OPTION_DEFAULT; - break; - case 9: /* analytical_expression */ - case 10: /* a_e */ - case 11: /* ae */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_analytical_expression_only(next_char, &(s_ptr->logk[2])); - opt_save = OPTION_DEFAULT; - break; - case 13: /* llnl_gamma */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->gflag = 7; /* llnl D-H */ - i = sscanf(next_char,SCANFORMAT, &s_ptr->dha); - if (i < 1) { - sprintf(error_string, "Expecting activity-coefficient parameter, a."); - warning_msg(error_string); - } - opt_save = OPTION_DEFAULT; - break; - case 14: /* co2_llnl_gamma */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->gflag = 8; /* llnl CO2 D-H */ - opt_save = OPTION_DEFAULT; - break; - case 15: /* activity water */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->gflag = 9; /* activity_water/55.5 for HDO, D2O, H2[O18], etc */ - opt_save = OPTION_DEFAULT; - break; - case 16: /* add_logk */ - case 17: /* add_log_k */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - /* read name */ - if (copy_token(token, &next_char, &i) == EMPTY) { - input_error++; - sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); - error_msg(error_string, CONTINUE); - break; - } - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); - /* read coef */ - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; - } - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case 18: /* add_constant */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - input_error++; - sprintf(error_string, "Expected the constant to add for log_K definition."); - error_msg(error_string, CONTINUE); - break; - } - /* set name */ - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); - /* read coef */ - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: -/* - * Get space for species information and parse equation - */ - s_ptr = NULL; - if ( parse_eq(line, &next_elt, association ) == ERROR) { - parse_error++; - error_msg("Parsing equation.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - } -/* - * Get pointer to each species in the reaction, store new species if necessary - */ - trxn.token[0].s = s_store( trxn.token[0].name, trxn.token[0].z, TRUE); - for (i=1; inext_elt=next_elt; - trxn.token[0].s->next_secondary = NULL; - for ( ; next_elt->elt != NULL; next_elt++) { - if ( strcmp (next_elt->elt->name,"C") == 0 ) { - trxn.token[0].s->carbon = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"H") == 0 ) { - trxn.token[0].s->h = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"O") == 0 ) { - trxn.token[0].s->o = next_elt->coef; - } - } -/* - * Malloc space for species reaction - */ - trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); -/* - * Copy reaction to reaction for species - */ - trxn_copy(trxn.token[0].s->rxn); - s_ptr=trxn.token[0].s; -/* - * Default gamma data - */ - s_ptr->dha = 0.0; - s_ptr->dhb = 0.0; - if (equal (s_ptr->z, 0.0, TOL) == TRUE) { - s_ptr->gflag = 0; /* Uncharged */ - s_ptr->dhb = 0.1; - } else { - s_ptr->gflag = 1; /* Davies */ - } -/* - * Set type for species - */ - if ( strcmp(trxn.token[0].s->name, "H+" ) == 0) { - s_hplus = trxn.token[0].s; - s_hplus->type = HPLUS; - } else if ( strcmp(trxn.token[0].s->name, "H3O+" ) == 0) { - s_h3oplus = trxn.token[0].s; - s_h3oplus->type = HPLUS; - } else if ( strcmp(trxn.token[0].s->name, "e-" ) == 0) { - s_eminus = trxn.token[0].s; - s_eminus->type = EMINUS; - s_eminus->gflag = 3; /* Always 1 */ - } else if ( strcmp(trxn.token[0].s->name, "H2O" ) == 0) { - s_h2o = trxn.token[0].s; - s_h2o->type = H2O; - s_h2o->gflag = 3; /* Always 1 */ - } else if ( strstr(trxn.token[0].s->name, "(s)" ) != NULL) { - trxn.token[0].s->type = SOLID; - } else if ( strcmp(trxn.token[0].s->name, "H2" ) == 0 ) { - trxn.token[0].s->type = AQ; - s_h2 = trxn.token[0].s; - } else if ( strcmp(trxn.token[0].s->name, "O2" ) == 0 ) { - trxn.token[0].s->type = AQ; - s_o2 = trxn.token[0].s; - } else { - trxn.token[0].s->type = AQ; - } - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_use (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution, mix, irreversible reaction, and pure phases to use - * in reaction calculation - */ - int i, l, n_user, return_value; - char *ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH];; -/* - * Read "use" - */ - ptr = line; - copy_token (token, &ptr, &l); -/* - * Read keyword - */ - copy_token (token, &ptr, &l); - check_key (token); - switch (next_keyword) { - case -1: /* Have not read line with keyword */ - case 0: /* End encountered */ - case 1: /* EOF encountered */ - case 2: /* Read aqueous model */ - case 3: /* Read master species */ - case 5: - case 9: - case 10: - case 11: - case 12: - case 14: - case 15: - case 18: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 30: - case 31: - case 32: - case 34: - case 35: - case 38: - case 39: - input_error++; - error_msg("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions.", CONTINUE); - error_msg(line_save, CONTINUE); - check_line("End of use",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(ERROR); - } -/* - * Read number - */ - strcpy(token1, token); - for (;;) { - i = copy_token (token, &ptr, &l); - if (i == DIGIT) { - sscanf(token,"%d",&n_user); - if (n_user < 0) { - error_msg("Number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - if (strstr(token,"-") != NULL) { - sprintf(error_string, "USE does not accept a range of numbers, %s.", token); - warning_msg(error_string); - sprintf(error_string, "Only %s %d will be used in the batch-reaction calculation.", token1, n_user); - warning_msg(error_string); - sprintf(error_string, "NOTE--USE is not needed for ADVECTION and TRANSPORT calculations."); - warning_msg(error_string); - - } - break; - } else if ( i == EMPTY ) { - sprintf(error_string, "No number given, 1 assumed."); - warning_msg(error_string); - n_user=1; - break; - } else if (token[0] == 'N' || token[0] == 'n') { - n_user = -2; - break; - } - } - switch (next_keyword) { - case 4: /* Solution */ - use.n_solution_user = n_user; - if (n_user >= 0 ) { - use.solution_in = TRUE; - } else { - use.solution_in = FALSE; - } - break; - case 6: /* Pure phases */ - case 26: - case 27: - case 28: - case 29: - use.n_pp_assemblage_user = n_user; - if (n_user >= 0 ) { - use.pp_assemblage_in = TRUE; - } else { - use.pp_assemblage_in = FALSE; - } - break; - case 7: /* Reaction */ - use.n_irrev_user = n_user; - if (n_user >= 0 ) { - use.irrev_in = TRUE; - } else { - use.irrev_in = FALSE; - } - break; - case 8: /* Mix */ - use.n_mix_user = n_user; - if (n_user >= 0 ) { - use.mix_in = TRUE; - } else { - use.mix_in = FALSE; - } - break; - case 13: /* Ex */ - use.n_exchange_user = n_user; - if (n_user >= 0 ) { - use.exchange_in = TRUE; - } else { - use.exchange_in = FALSE; - } - break; - case 16: /* Surface */ - use.n_surface_user = n_user; - if (n_user >= 0 ) { - use.surface_in = TRUE; - } else { - use.surface_in = FALSE; - } - break; - case 17: /* Temperature */ - use.n_temperature_user = n_user; - if (n_user >= 0 ) { - use.temperature_in = TRUE; - } else { - use.temperature_in = FALSE; - } - break; - case 19: /* Gas */ - use.n_gas_phase_user = n_user; - if (n_user >= 0 ) { - use.gas_phase_in = TRUE; - } else { - use.gas_phase_in = FALSE; - } - break; - case 33: /* Kinetics */ - use.n_kinetics_user = n_user; - if (n_user >= 0 ) { - use.kinetics_in = TRUE; - } else { - use.kinetics_in = FALSE; - } - break; - case 40: /* solid_solutions */ - case 41: /* solid_solution */ - use.n_s_s_assemblage_user = n_user; - if (n_user >= 0 ) { - use.s_s_assemblage_in = TRUE; - } else { - use.s_s_assemblage_in = FALSE; - } - break; - } - return_value = check_line("End of use",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_surface_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read data for surface species, parse equations - */ - int i; - int association; - char token[MAX_LENGTH]; - char *ptr; - LDBLE offset; - - struct species *s_ptr; - struct elt_list *next_elt; - struct rxn_token *token_ptr; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "no_check", /* 0 */ - "check", /* 1 */ - "mb", /* 2 */ - "mass_balance", /* 3 */ - "log_k", /* 4 */ - "logk", /* 5 */ - "delta_h", /* 6 */ - "deltah", /* 7 */ - "analytical_expression", /* 8 */ - "a_e", /* 9 */ - "ae", /* 10 */ - "mole_balance", /* 11 */ - "offset", /* 12 */ - "add_logk", /* 13 */ - "add_log_k", /* 14 */ - "add_constant" /* 15 */ - }; - int count_opt_list = 16; - - association=TRUE; -/* - * Read eqn from file and call parser - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - s_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SURFACE_SPECIES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* no_check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = FALSE; - break; - case 1: /* check */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - s_ptr->check_equation = TRUE; - break; - case 2: /* mb */ - case 3: /* mass_balance */ - case 11: /* mole_balance */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - count_elts = 0; - paren_count =0; - copy_token(token, &next_char, &i); - s_ptr->mole_balance = string_hsave(token); - ptr = token; - get_secondary_in_species(&ptr, 1.0); - s_ptr->next_secondary = elt_list_save(); -/* debug - for (i = 0; i < count_elts; i++) { - output_msg(OUTPUT_MESSAGE,"%s\t%f\n", elt_list[i].elt->name, - elt_list[i].coef); - } - */ - opt_save = OPTION_DEFAULT; - break; - case 4: /* log_k */ - case 5: /* logk */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_log_k_only(next_char, &s_ptr->logk[0]); - opt_save = OPTION_DEFAULT; - break; - case 6: /* delta_h */ - case 7: /* deltah */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_delta_h_only(next_char, &s_ptr->logk[1], &s_ptr->original_units); - opt_save = OPTION_DEFAULT; - break; - case 8: /* analytical_expression */ - case 9: /* a_e */ - case 10: /* ae */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_analytical_expression_only(next_char, &(s_ptr->logk[2])); - opt_save = OPTION_DEFAULT; - break; - case 12: /* offset */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (sscanf(next_char, SCANFORMAT, &offset) != 1) { - error_msg("No offset for log K given", STOP); - } - s_ptr->logk[0] += offset; - opt_save = OPTION_DEFAULT; - break; - case 13: /* add_logk */ - case 14: /* add_log_k */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - /* read name */ - if (copy_token(token, &next_char, &i) == EMPTY) { - input_error++; - sprintf(error_string, "Expected the name of a NAMED_EXPRESSION."); - error_msg(error_string, CONTINUE); - break; - } - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); - /* read coef */ - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; - } - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case 15: /* add_constant */ - if (s_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - if (s_ptr->count_add_logk == 0) { - s_ptr->add_logk = (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (s_ptr->add_logk == NULL) malloc_error(); - } else { - s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, (size_t) ((s_ptr->count_add_logk + 1)* sizeof(struct name_coef))); - if (s_ptr->add_logk == NULL) malloc_error(); - } - i = sscanf(next_char,SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); - if (i <= 0) { - input_error++; - sprintf(error_string, "Expected the constant to add for log_K definition."); - error_msg(error_string, CONTINUE); - break; - } - /* set name */ - s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave("XconstantX"); - /* read coef */ - s_ptr->count_add_logk++; - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: -/* - * Get surface species information and parse equation - */ - s_ptr = NULL; - if ( parse_eq(line, &next_elt, association ) == ERROR) { - parse_error++; - error_msg("Parsing equation.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - } -/* - * Get pointer to each species in the reaction, store new species if necessary - */ - trxn.token[0].s = s_store(trxn.token[0].name, trxn.token[0].z, TRUE); - for (i=1; inext_elt=next_elt; - for ( ; next_elt->elt != NULL; next_elt++) { - if ( strcmp (next_elt->elt->name,"C") == 0 ) { - trxn.token[0].s->carbon = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"H") == 0 ) { - trxn.token[0].s->h = next_elt->coef; - } - if ( strcmp (next_elt->elt->name,"O") == 0 ) { - trxn.token[0].s->o = next_elt->coef; - } - } -/* - * Find coefficient of surface in rxn, store in equiv - */ - trxn.token[0].s->equiv = 0.0; - for (i=1; itype == SURF) { - trxn.token[0].s->equiv = trxn.token[i].coef; - } - } - if (trxn.token[0].s->equiv == 0.0) trxn.token[0].s->equiv = 1.0; -/* - * Malloc space for species reaction - */ - trxn.token[0].s->rxn = rxn_alloc (count_trxn+1); -/* - * Copy reaction to reaction for species - */ - token_ptr=trxn.token[0].s->rxn->token; - for (i=0; itype = SURF; - s_ptr=trxn.token[0].s; -/* - * Read gamma data - */ - s_ptr->gflag = 6; - s_ptr->dha = 0.0; - s_ptr->dhb = 0.0; - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_surf(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads surface data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int count_comps, count_charge; - int n_user, n_user_end; - LDBLE conc, area, grams /*, thickness , factor */; - char *ptr, *ptr1; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH], name[MAX_LENGTH]; - struct surface *surface_ptr; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "equilibrate", /* 0 */ - "equil", /* 1 */ - "diff", /* 2 */ - "diffuse_layer", /* 3 */ - "no_edl", /* 4 */ - "no_electrostatic", /* 5 */ - "only_counter_ions", /* 6 */ - "donnan", /* 7 */ - "transport" /* 8 */ - }; - int count_opt_list = 9; -/* - * kin_surf is for Surfaces, related to kinetically reacting minerals - * they are defined if "sites" is followed by mineral name: - * Surf_wOH Manganite [equilibrium_phases or kinetics] 0.25 4000 - * ^Name mineral ^switch ^prop.factor ^m2/mol - */ -/* - * Read surface number and description - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Find space for surface data - */ - surface_ptr = surface_search(n_user, &n, FALSE); - if (surface_ptr != NULL) { - surface_free(&surface[n]); - } else { - n = count_surface++; - space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); - } -/* - * Initialize - */ - surface_init(&(surface[n]), n_user, n_user_end, description); - free_check_null(description); - - if (use.surface_in == FALSE) { - use.surface_in = TRUE; - use.n_surface_user = n_user; - } -/* - * Read surface data - */ - count_charge = 0; - count_comps = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SURFACE keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* equilibrate */ - case 1: - for (;;) { - i = copy_token(token, &next_char, &l); - if (i == DIGIT) { - sscanf(token, "%d", &surface[n].n_solution); - surface[n].solution_equilibria = TRUE; - break; - } - if (i == EMPTY) { - error_msg("Expected a solution number with which to equilibrate surface.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - break; - case 2: /* diffuse_layer */ - case 3: - surface[n].thickness = 1e-8; - surface[n].diffuse_layer = TRUE; - for (;;) { - i = copy_token(token, &next_char, &l); - if (i == DIGIT) { - sscanf(token, SCANFORMAT, &surface[n].thickness); - break; - } else if (i != EMPTY) { - if (token[0] == 'D' || token[0] == 'd') { - surface[n].debye_units = 1.0; - j = copy_token(token1, &ptr, &l); - if (j == DIGIT) { - sscanf(token1, SCANFORMAT, &surface[n].debye_units); - break; - } else if (j != EMPTY) { - error_msg("Expected number of Debye units (1/k) for calculating diffuse layer thickness.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } else break; - } else { - error_msg("Expected D or d for Donnan calculations.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } else break; - } - break; - case 4: /* no electrostatic */ - case 5: - surface[n].edl = FALSE; - break; - case 6: - surface[n].only_counter_ions = TRUE; - break; - case 7: /* donnan for DL conc's */ - surface[n].donnan = TRUE; - break; - case 8: /* transport */ - surface[n].transport = TRUE; - break; - case OPTION_DEFAULT: -/* - * Read surface component - */ - ptr=line; - i = copy_token(token, &ptr, &l); - if (i != UPPER && token[0] != '[' ) { - error_msg("Expected surface name to begin with a capital letter.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } -/* - * Realloc space for new surface component - */ - surface[n].comps = (struct surface_comp *) PHRQ_realloc( surface[n].comps, (size_t) (count_comps + 1) * sizeof (struct surface_comp)); - if (surface[n].comps == NULL) malloc_error(); - surface[n].comps[count_comps].formula = string_hsave(token); - surface[n].comps[count_comps].moles = 0; - surface[n].comps[count_comps].cb = 0; - surface[n].comps[count_comps].phase_name = NULL; - surface[n].comps[count_comps].rate_name = NULL; - i = copy_token(token1, &ptr, &l); - if (i == DIGIT) { -/* - * Read surface concentration - */ - /* surface concentration is read directly */ - if ( sscanf(token1, SCANFORMAT, &conc) < 1) { - error_msg("Expected number of surface sites in moles.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } -#ifdef PHREEQCI_GUI - surface[n].comps[count_comps].moles = conc; -#endif -/* - * Read equilibrium phase name or kinetics rate name - */ - } else if (i != EMPTY) { - - /* surface conc. is related to mineral or kinetics */ - surface[n].comps[count_comps].phase_name = string_hsave(token1); - j = copy_token(token1, &ptr, &l); - - /* read optional 'equilibrium_phases' or 'kinetics' */ - if (j == DIGIT) { - surface[n].related_phases = TRUE; - } else { - if (token1[0] == 'K' || token1[0] == 'k') { - surface[n].comps[count_comps].rate_name = surface[n].comps[count_comps].phase_name; - surface[n].comps[count_comps].phase_name = NULL; - surface[n].related_rate = TRUE; - } else if (token1[0] == 'E' || token1[0] == 'e') { - surface[n].related_phases = TRUE; - surface[n].comps[count_comps].rate_name = NULL; - } else { - error_msg("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate surface to mineral or kinetic reaction.\n", CONTINUE); - input_error++; - break; - } - j = copy_token(token1, &ptr, &l); - } - - /* read proportion */ - if (j != DIGIT) { - error_msg("Expected a coefficient to relate surface to mineral or kinetic reaction.\n", CONTINUE); - input_error++; - break; - } - sscanf(token1, SCANFORMAT, &surface[n].comps[count_comps].phase_proportion); - /* real conc must be defined in tidy_model */ - conc = 1.0; - } else { - error_msg("Expected concentration of surface, mineral name, or kinetic reaction name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } -/* - * Accumulate elements in elt_list - */ - count_elts = 0; - paren_count = 0; - ptr1 = token; - get_elts_in_species(&ptr1, conc); - surface[n].comps[count_comps].totals = elt_list_save(); -/* - * Search for charge structure - */ - ptr1 = token; - get_elt(&ptr1, name, &l); - ptr1 = strchr(name,'_'); - if (ptr1 != NULL) ptr1[0] = '\0'; - for (i = 0; i < count_charge; i++) { - if (strcmp(surface[n].charge[i].name, name) == 0) break; - } - if (i >= count_charge) { - surface[n].charge = (struct surface_charge *) PHRQ_realloc(surface[n].charge, (size_t) ( count_charge + 1) * sizeof(struct surface_charge)); - if (surface[n].charge == NULL) malloc_error(); - i = count_charge; - surface[n].charge[i].name = string_hsave(name); - if (surface[n].comps[count_comps].phase_name == NULL && surface[n].comps[count_comps].rate_name == NULL) { - surface[n].charge[i].specific_area = 600.0; - surface[n].charge[i].grams = 0.0; - } else { - surface[n].charge[i].specific_area = 0.0; - surface[n].charge[i].grams = 1.0; - } - surface[n].charge[i].mass_water = 0.0; - surface[n].charge[i].charge_balance = 0.0; - surface[n].charge[i].diffuse_layer_totals = NULL; - surface[n].charge[i].count_g = 0; - surface[n].charge[i].g = NULL; - surface[n].charge[i].psi_master = NULL; - count_charge++; - } - surface[n].comps[count_comps].charge = i; - count_comps++; -/* - * Read surface area (m2/g) - */ - copy_token(token1, &ptr, &l); - if (sscanf(token1, SCANFORMAT, &area) == 1) { - surface[n].charge[i].specific_area = area; - } else { - break; - } -/* - * Read grams of solid (g) - */ - copy_token(token1, &ptr, &l); - if (sscanf(token1, SCANFORMAT, &grams) == 1 ) { - surface[n].charge[i].grams = grams; - } - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - surface[n].count_comps = count_comps; - surface[n].count_charge = count_charge; -/* - * Make sure surface area is defined - */ - if (surface[n].edl == TRUE) { - for (i = 0; i < count_charge; i++) { - if (surface[n].charge[i].grams * surface[n].charge[i].specific_area <= 0) { - sprintf(error_string, "Surface area not defined for %s.\n", surface[n].charge[i].name); - error_msg(error_string, CONTINUE); - input_error++; - } - } - } else { - if (surface[n].diffuse_layer == TRUE) { - sprintf(error_string, "Diffuse_layer and no_edl are mutually exclusive options.\n"); - error_msg(error_string, CONTINUE); - input_error++; - } - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_surface_master_species (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads master species data from data file or input file - */ - int i, l, n, return_value; - char *ptr, *ptr1; - LDBLE z; - struct master *master_ptr; - struct species *s_ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - - for (;;) { - return_value = check_line ("Surface species equation", FALSE, TRUE, TRUE, TRUE); - if (return_value == EOF || return_value == KEYWORD ) break; -/* - * Get "element" name with valence, allocate space, store - */ - ptr=line; -/* - * Get element name and save pointer to character string - */ - if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { - parse_error++; - error_msg ("Reading element for master species.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - /* - if (token[0] == '[') { - ptr1 = token; - get_elt(&ptr, element, &l); - strcpy(token, element); - } - */ - replace ("(+", "(", token); -/* - * Delete master if it exists - */ - master_delete(token); -/* - * Increase pointer array, if necessary, and malloc space - */ - if (count_master + 2 >= max_master) { - space ((void **) ((void *) &master), count_master+2, &max_master, sizeof(struct master *)); - } -/* - * Save values in master and species structure for surface sites - */ - master[count_master] = master_alloc(); - master[count_master]->type = SURF; - master[count_master]->elt = element_store ( token ); - - if ( copy_token(token, &ptr, &l) != UPPER && token[0] != '[' ) { - parse_error++; - error_msg("Reading surface master species name.", CONTINUE); - error_msg(line_save, CONTINUE); - continue; - } - s_ptr=s_search (token); - if (s_ptr != NULL) { - master[count_master]->s = s_ptr; - } else { - ptr1=token; - get_token(&ptr1, token1, &z, &l); - master[count_master]->s = s_store(token1, z, FALSE); - } - master[count_master]->primary=TRUE; - strcpy(token,master[count_master]->elt->name); - count_master++; -/* - * Save values in master and species structure for surface psi - */ - strcpy(token1, token); - replace ("_", " ", token1); - ptr1 = token1; - copy_token(token, &ptr1, &l); - strcat(token,"_psi"); - master_ptr=master_search (token, &n); - if (master_ptr == NULL) { - master[count_master] = master_alloc(); - master[count_master]->type = SURF_PSI; - master[count_master]->elt = element_store ( token ); - s_ptr=s_search (token); - if (s_ptr != NULL) { - master[count_master]->s = s_ptr; - } else { - master[count_master]->s = s_store(token, 0.0, FALSE); - } - count_elts = 0; - paren_count = 0; - ptr = token; - get_elts_in_species(&ptr, 1.0); - master[count_master]->s->next_elt = elt_list_save(); - - master[count_master]->s->type=SURF_PSI; - master[count_master]->primary=TRUE; - master[count_master]->s->rxn = rxn_alloc(3); -/* - * Define reaction for psi - */ - for( i = 0; i < 8; i++) { - master[count_master]->s->rxn->logk[i] = 0.0; - } - master[count_master]->s->rxn->token[0].s = master[count_master]->s; - master[count_master]->s->rxn->token[0].coef = -1.0; - master[count_master]->s->rxn->token[1].s = master[count_master]->s; - master[count_master]->s->rxn->token[1].coef = 1.0; - master[count_master]->s->rxn->token[2].s = NULL; - count_master++; - } - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int read_temperature (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads temperature data for reaction steps - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - char *description; - int n, return_value; - int n_user, n_user_end; - struct temperature *temperature_ptr; -/* - * Read reaction number - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Read allocate space for temperature - */ - temperature_ptr = temperature_search(n_user, &n); - if (temperature_ptr != NULL) { - temperature_free(&temperature[n]); - } else { - n = count_temperature++; - temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature)); - if (temperature == NULL) malloc_error(); - } -/* - * Set use data to first read - */ - if (use.temperature_in == FALSE) { - use.temperature_in = TRUE; - use.n_temperature_user = n_user; - } -/* - * Defaults - */ - temperature[n].n_user = n_user; - temperature[n].n_user_end = n_user_end; - temperature[n].description = description; - temperature[n].t = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (temperature[n].t == NULL) malloc_error(); - temperature[n].t[0] = 25.0; - temperature[n].count_t = 0; -/* - * Read temperature data - */ - for (;;) { - return_value = check_line("reaction_temperature",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; -/* - * Read steps information - */ - read_reaction_temps(&(temperature[n])); - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_reaction_temps(struct temperature *temperature_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read temperature one of two forms: - * - * (1) 25.0 30. 40. 50. 60. - * - * (2) 25.0 100.0 in 4 steps # (25 50 75 100) - * - */ - int i, j, l; - int count_t; - char *ptr; - char token[MAX_LENGTH]; - LDBLE step; - - ptr = line; - count_t = temperature_ptr->count_t; -/* - * Read one or more reaction increments - */ - for (;;) { - if ( copy_token (token, &ptr, &l) == EMPTY ) { - return(OK); - } -/* - * Read next step increment - */ - j = sscanf(token, SCANFORMAT, &step); - if (j == 1 ) { - count_t++; - temperature_ptr->t = (LDBLE *) PHRQ_realloc(temperature_ptr->t, (size_t) count_t * sizeof(LDBLE)); - if (temperature_ptr->t == NULL) malloc_error(); - temperature_ptr->t[temperature_ptr->count_t] = step; - temperature_ptr->count_t = count_t; - } else { - break; - } - } -/* - * Read number of equal increments, store as negative integer - */ - if (count_t != 2) { - error_msg("To define equal increments, exactly two temperatures should be defined.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - do { - j = sscanf(token, "%d", &i); - if (j == 1 && i > 0 ) { - temperature_ptr->count_t = -i; - return(OK); - } else if (j == 1 && i <= 0 ) { - break; - } - } while ( copy_token (token, &ptr, &l) != EMPTY ); - - error_msg("Expecting positive number for calculation of " - "temperature increments.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); -} -/* ---------------------------------------------------------------------- */ -int read_title (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads title for simulation - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr, *ptr1; - int l, title_x_length, line_length; - int return_value; - char token[MAX_LENGTH]; -/* - * Read anything after keyword - */ - ptr=line; - copy_token(token, &ptr, &l); - ptr1 = ptr; - title_x = (char *) free_check_null(title_x); - if (copy_token(token, &ptr, &l) != EMPTY) { - title_x = string_duplicate(ptr1); - } else { - title_x = (char *) PHRQ_malloc(sizeof(char)); - if (title_x == NULL) malloc_error(); - title_x[0] = '\0'; - } - -/* - * Read additonal lines - */ - for (;;) { - return_value = check_line("title",TRUE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; -/* - * append line to title_x - */ - title_x_length = strlen(title_x); - line_length = strlen(line); - title_x = (char *) PHRQ_realloc(title_x, (size_t) (title_x_length + line_length + 2) * sizeof(char)); - if (title_x == NULL) malloc_error(); - if (title_x_length > 0) { - title_x[title_x_length] = '\n'; - title_x[title_x_length+1] = '\0'; - } - strcat(title_x, line); - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_advection (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads advection information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ -/* - * Read advection parameters: - * number of cells; - * number of shifts; - */ - char *ptr; - char *description; - int n_user, n_user_end, i; - - int count_punch, count_print; - int *punch_temp, *print_temp; - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "cells", /* 0 */ - "shifts", /* 1 */ - "print", /* 2 */ - "selected_output", /* 3 */ - "punch", /* 4 */ - "print_cells", /* 5 */ - "selected_cells", /* 6 */ - "time_step", /* 7 */ - "timest", /* 8 */ - "output", /* 9 */ - "output_frequency", /* 10 */ - "selected_output_frequency",/* 11 */ - "punch_frequency", /* 12 */ - "print_frequency", /* 13 */ - "punch_cells", /* 14 */ - "initial_time", /* 15 */ - "warning", /* 16 */ - "warnings" /* 17 */ - }; - int count_opt_list = 18; -/* - * Read advection number (not currently used) - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); -/* - * Set use data - */ - use.advect_in = TRUE; - count_ad_cells = 0; - count_ad_shifts = 0; - print_ad_modulus = 1; - punch_ad_modulus = 1; - count_punch = 0; - count_print = 0; - punch_temp = (int *) PHRQ_malloc(sizeof(int)); - if (punch_temp == NULL) malloc_error(); - print_temp = (int *) PHRQ_malloc(sizeof(int)); - if (print_temp == NULL) malloc_error(); -/* - * Read lines - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in ADVECTION keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* cells */ - sscanf(next_char, "%d", &count_ad_cells); - opt_save = OPTION_DEFAULT; - break; - case 1: /* shifts */ - sscanf(next_char, "%d", &count_ad_shifts); - opt_save = OPTION_DEFAULT; - break; - case 2: /* print */ - case 5: /* print_cells */ - print_temp = read_list_ints_range (&next_char, &count_print, TRUE, print_temp); -#ifdef SKIP - while (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &l); - print_temp = PHRQ_realloc(print_temp, (size_t) (count_print + 1) * sizeof(int)); - if (print_temp == NULL) malloc_error(); - print_temp[count_print] = l; - count_print++; - } -#endif - opt_save = 2; - break; - case 3: /* selected_output */ - case 11: /* selected_output_frequency */ - case 12: /* punch_frequency */ - sscanf(next_char, "%d", &punch_ad_modulus); - opt_save = OPTION_DEFAULT; - break; - case 4: /* punch */ - case 14: /* punch_cells */ - case 6: /* selected_cells */ - punch_temp = read_list_ints_range (&next_char, &count_punch, TRUE, punch_temp); -#ifdef SKIP - while (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &l); - punch_temp = PHRQ_realloc(punch_temp, (size_t) (count_punch + 1) * sizeof(int)); - if (punch_temp == NULL) malloc_error(); - punch_temp[count_punch] = l; - count_punch++; - } -#endif - opt_save = 4; - break; - case 7: /* time_step */ - case 8: /* timest */ - sscanf(next_char, SCANFORMAT, &advection_kin_time); - advection_kin_time_defined = TRUE; - opt_save = OPTION_DEFAULT; - break; - case 9: /* output */ - case 10: /* output_frequency */ - case 13: /* print_frequency */ - sscanf(next_char, "%d", &print_ad_modulus); - opt_save = OPTION_DEFAULT; - break; - case 15: /* initial_time */ - sscanf(next_char, SCANFORMAT, &initial_total_time); - opt_save = OPTION_DEFAULT; - break; - case 16: /* warning */ - case 17: /* warnings */ - advection_warnings = get_true_false(next_char, TRUE); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* - * Fill in data for punch - */ - advection_punch = (int *) PHRQ_realloc(advection_punch, (size_t) (count_ad_cells + 1) * sizeof(int)); - if (advection_punch == NULL) malloc_error(); - if (count_punch != 0) { - for (i=0; i count_ad_cells || punch_temp[i] < 1) { - sprintf(error_string,"Cell number for punch is out of range, %d. Request ignored.", punch_temp[i]); - warning_msg(error_string); - } else { - advection_punch[punch_temp[i]-1] = TRUE; - } - } - } else { - for (i=0; i count_ad_cells || print_temp[i] < 1) { - sprintf(error_string,"Cell number for print is out of range, %d. Request ignored.", print_temp[i]); - warning_msg(error_string); - } else { - advection_print[print_temp[i]-1] = TRUE; - } - } - } else { - for (i=0; idata))->keycount; - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int check_units (char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print) -/* ---------------------------------------------------------------------- */ -{ -#define NUNITS (sizeof(units) / sizeof(char *)) -/* - * Check if legitimate units - * Input: - * tot_units character string to check, - * alkalinity TRUE if alkalinity, FALSE if any other total, - * check_compatibility TRUE check alk and default units, FALSE otherwise - * default_units character string of default units (check /L, /kg, etc) - * print TRUE print warning messages - * Output: - * tot_units standard form for unit - */ - int i, found; - char *end; - char string[MAX_LENGTH]; - const char *units[] = { - "Mol/l", /* 0 */ - "mMol/l", /* 1 */ - "uMol/l", /* 2 */ - "g/l", /* 3 */ - "mg/l", /* 4 */ - "ug/l", /* 5 */ - "Mol/kgs", /* 6 */ - "mMol/kgs", /* 7 */ - "uMol/kgs", /* 8 */ - "g/kgs", /* 9 = ppt */ - "mg/kgs", /* 10 = ppm */ - "ug/kgs", /* 11 = ppb */ - "Mol/kgw", /* 12 = mol/kg H2O */ - "mMol/kgw", /* 13 = mmol/kg H2O */ - "uMol/kgw", /* 14 = umol/kg H2O */ - "g/kgw", /* 15 = mol/kg H2O */ - "mg/kgw", /* 16 = mmol/kg H2O */ - "ug/kgw", /* 17 = umol/kg H2O */ - "eq/l", /* 18 */ - "meq/l", /* 19 */ - "ueq/l", /* 20 */ - "eq/kgs", /* 21 */ - "meq/kgs", /* 22 */ - "ueq/kgs", /* 23 */ - "eq/kgw", /* 24 */ - "meq/kgw", /* 25 */ - "ueq/kgw", /* 26 */ - }; - - squeeze_white (tot_units); - str_tolower(tot_units); - replace ("milli", "m", tot_units); - replace ("micro", "u", tot_units); - replace ("grams", "g", tot_units); - replace ("gram", "g", tot_units); - replace ("moles", "Mol", tot_units); - replace ("mole", "Mol", tot_units); - replace ("mol", "Mol", tot_units); - replace ("liter", "l", tot_units); - replace ("kgh", "kgw", tot_units); - replace ("ppt", "g/kgs", tot_units); - replace ("ppm", "mg/kgs",tot_units); - replace ("ppb", "ug/kgs",tot_units); - replace ("equivalents","eq", tot_units); - replace ("equivalent", "eq", tot_units); - replace ("equiv", "eq", tot_units); - - if ( (end=strstr(tot_units,"/l")) != NULL) { - *(end+2)='\0'; - } - if ( (end=strstr(tot_units,"/kgs")) != NULL) { - *(end+4)='\0'; - } - if ( (end=strstr(tot_units,"/kgw")) != NULL) { - *(end+4)='\0'; - } -/* - * Check if unit in list - */ - found = FALSE; - for (i=0; i < (int) NUNITS; i++) { - if (strcmp(tot_units, units[i]) == 0) { - found=TRUE; - break; - } - } - if (found == FALSE) { - if (print == TRUE) { - sprintf(error_string, "Unknown unit, %s.", tot_units); - error_msg(error_string, CONTINUE); - } - return (ERROR); - } - -/* - * Check if units are compatible with default_units - */ - if (check_compatibility == FALSE) return (OK); -/* - * Special cases for alkalinity - */ - if (alkalinity == TRUE && strstr(tot_units,"Mol") != NULL) { - if (print == TRUE) { - sprintf(error_string, "Alkalinity given in moles, assumed to be equivalents."); - warning_msg(error_string); - } - replace("Mol","eq",tot_units); - } - if (alkalinity == FALSE && strstr(tot_units,"eq") != NULL) { - if (print == TRUE) { - error_msg("Only alkalinity can be entered in equivalents.", CONTINUE); - } - return (ERROR); - } -/* - * See if default_units are compatible with tot_units - */ - if ( strstr(default_units,"/l") && strstr(tot_units,"/l")) return (OK); - if ( strstr(default_units,"/kgs") && strstr(tot_units,"/kgs")) return (OK); - if ( strstr(default_units,"/kgw") && strstr(tot_units,"/kgw")) return (OK); - - strcpy( string, default_units); - replace ("kgs","kg solution",string); - replace ("kgs","kg solution",tot_units); - replace ("kgw","kg water",string); - replace ("kgw","kg water",tot_units); - replace ("/l","/L",string); - replace ("Mol","mol",string); - replace ("/l","/L",tot_units); - replace ("Mol","mol",tot_units); - if (print == TRUE) { - sprintf(error_string, "Units for master species, %s, are not compatible with default units, %s.", tot_units, string); - error_msg(error_string, CONTINUE); - } - return (ERROR); -} -/* ---------------------------------------------------------------------- */ -int find_option(char *item, int *n, const char **list, int count_list, int exact) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compares a string value to match beginning letters of a list of options - * - * Arguments: - * item entry: pointer to string to compare - * n exit: item in list that was matched - * list entry: pointer to list of character values, assumed to - * be lower case - * count_list entry: number of character values in list - * - * Returns: - * OK item matched - * ERROR item not matched - * n -1 item not matched - * i position of match in list - */ - int i; - char token[MAX_LENGTH]; - - strcpy(token, item); - str_tolower(token); - for (i=0; i < count_list; i++) { - if (exact == TRUE) { - if (strcmp(list[i], token) == 0) { - *n = i; - return(OK); - } - } else { - if (strstr(list[i], token) == list[i]) { - *n = i; - return(OK); - } - } - } - *n = -1; - return(ERROR); -} -/* ---------------------------------------------------------------------- */ -int get_true_false(char *string, int default_value) -/* ---------------------------------------------------------------------- */ -{ -/* - * Returns true unless string starts with "F" or "f" - */ - int l; - char token[MAX_LENGTH]; - char *ptr; - - ptr = string; - - if (copy_token(token, &ptr, &l) == EMPTY) { - return(default_value); - } else { - if (token[0] == 'F' || token[0] == 'f') { - return(FALSE); - } - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int get_option (const char **opt_list, int count_opt_list, char **next_char) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read a line and check for options - */ - int j; - int opt_l, opt; - char *opt_ptr; - char option[MAX_LENGTH]; -/* - * Read line - */ - j = check_line ("get_option", FALSE, TRUE, TRUE, FALSE); - if (j == EOF) { - j = OPTION_EOF; - } else if (j == KEYWORD ) { - j = OPTION_KEYWORD; - } else if (j == OPTION) { - opt_ptr = line; - copy_token(option, &opt_ptr, &opt_l); - if (find_option(&(option[1]), &opt, opt_list, count_opt_list, FALSE) == OK) { - j = opt; - replace(option, opt_list[j], line_save); - replace(option, opt_list[j], line); - opt_ptr = line; - copy_token(option, &opt_ptr, &opt_l); - *next_char = opt_ptr; - if (pr.echo_input == TRUE) { - if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); - } - } else { - if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); - error_msg("Unknown option.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - j = OPTION_ERROR; - *next_char = line; - } - } else { - opt_ptr = line; - copy_token(option, &opt_ptr, &opt_l); - if (find_option(&(option[0]), &opt, opt_list, count_opt_list, TRUE) == OK) { - j = opt; - *next_char = opt_ptr; - } else { - j = OPTION_DEFAULT; - *next_char = line; - } - if (pr.echo_input == TRUE) { - if(!reading_database()) output_msg(OUTPUT_MESSAGE, "\t%s\n", line_save); - } - } - return (j); -} -/* ---------------------------------------------------------------------- */ -int read_rates (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - int l, length, line_length, n; - int return_value, opt, opt_save; - char token[MAX_LENGTH]; - struct rate *rate_ptr; - char *description; - int n_user, n_user_end; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end" /* 1 */ - }; - int count_opt_list = 2; -/* - * Read advection number (not currently used) - */ - n = -1; - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - return_value = UNKNOWN; - rate_ptr = NULL; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in RATES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPT_1; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: /* read rate name */ - ptr = line; - copy_token(token, &ptr, &l); - rate_ptr = rate_search(token, &n); - if (rate_ptr == NULL) { - rates = (struct rate *) PHRQ_realloc(rates, (size_t) (count_rates + 1) * sizeof (struct rate)); - if (rates == NULL) malloc_error(); - rate_ptr = &rates[count_rates]; - count_rates++; - } else { - rate_free(rate_ptr); - } - rate_ptr->new_def = TRUE; - rate_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); - if (rate_ptr->commands == NULL) malloc_error(); - rate_ptr->commands[0] = '\0'; - rate_ptr->name = string_hsave(token); - rate_ptr->linebase = NULL; - rate_ptr->varbase = NULL; - rate_ptr->loopbase = NULL; - opt_save = OPT_1; - break; - case OPT_1: /* read command */ - if (rate_ptr == NULL) { - input_error++; - sprintf(error_string, "No rate name has been defined."); - error_msg(error_string, CONTINUE); - opt_save = OPT_1; - break; - } - length = strlen(rate_ptr->commands); - line_length = strlen(line); - rate_ptr->commands = (char *) PHRQ_realloc(rate_ptr->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (rate_ptr->commands == NULL) malloc_error(); - rate_ptr->commands[length] = ';'; - rate_ptr->commands[length + 1] = '\0'; - strcat((rate_ptr->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* output_msg(OUTPUT_MESSAGE, "%s", rates[0].commands); - */ return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_user_print (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int length, line_length; - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end" /* 1 */ - }; - int count_opt_list = 2; - - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in RATES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPTION_DEFAULT; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: /* read first command */ - rate_free(user_print); - user_print->new_def = TRUE; - user_print->commands = (char *) PHRQ_malloc(sizeof(char)); - if (user_print->commands == NULL) malloc_error(); - user_print->commands[0] = '\0'; - user_print->linebase = NULL; - user_print->varbase = NULL; - user_print->loopbase = NULL; - user_print->name = string_hsave("user defined Basic print routine"); - case OPT_1: /* read command */ - length = strlen(user_print->commands); - line_length = strlen(line); - user_print->commands = (char *) PHRQ_realloc(user_print->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (user_print->commands == NULL) malloc_error(); - user_print->commands[length] = ';'; - user_print->commands[length + 1] = '\0'; - strcat((user_print->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* output_msg(OUTPUT_MESSAGE, "%s", rates[0].commands); - */ return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_user_punch (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int l, length, line_length; - int return_value, opt, opt_save; - char token[MAX_LENGTH]; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end", /* 1 */ - "heading", /* 2 */ - "headings" /* 3 */ - }; - int count_opt_list = 4; - - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - user_punch_count_headings = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in RATES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPTION_DEFAULT; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case 2: /* headings */ - case 3: /* heading*/ - while (copy_token(token, &next_char, &l) != EMPTY) { - user_punch_headings = (char **) PHRQ_realloc(user_punch_headings, (size_t) (user_punch_count_headings + 1) * sizeof(char *)); - if (user_punch_headings == NULL) malloc_error(); - user_punch_headings[user_punch_count_headings] = string_hsave(token); - user_punch_count_headings++; - } - break; - case OPTION_DEFAULT: /* read first command */ - rate_free(user_punch); - user_punch->new_def = TRUE; - user_punch->commands = (char *) PHRQ_malloc(sizeof(char)); - if (user_punch->commands == NULL) malloc_error(); - user_punch->commands[0] = '\0'; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - user_punch->name = string_hsave("user defined Basic punch routine"); - case OPT_1: /* read command */ - length = strlen(user_punch->commands); - line_length = strlen(line); - user_punch->commands = (char *) PHRQ_realloc(user_punch->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (user_punch->commands == NULL) malloc_error(); - user_punch->commands[length] = ';'; - user_punch->commands[length + 1] = '\0'; - strcat((user_punch->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return(return_value); -} -#ifdef PHREEQ98 -/* ---------------------------------------------------------------------- */ -int read_user_graph (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads basic code with which to calculate rates - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int l, length, line_length; - int return_value, opt, opt_save; - char file_name[MAX_LENGTH]; - char token[MAX_LENGTH]; - char *next_char; - const char *opt_list[] = { - "start", /* 0 */ - "end", /* 1 */ - "heading", /* 2 */ - "headings", /* 3 */ - "chart_title", /* 4 */ - "axis_titles", /* 5 */ - "axis_scale", /* 6 */ - "initial_solutions", /* 7 */ - "plot_concentration_vs",/* 8 */ - "shifts_as_points", /* 9 */ - "grid_offset", /* 10 */ - "connect_simulations", /* 11 */ - "plot_csv_file" /* 12 */ - - }; - int count_opt_list = 13; - int i; - - opt_save = OPTION_DEFAULT; -/* - * Read lines - */ - user_graph_count_headings = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* start */ - opt_save = OPTION_DEFAULT; - break; - case 1: /* end */ - opt_save = OPTION_DEFAULT; - break; - case 2: /* headings */ - case 3: /* heading*/ - while (copy_token(token, &next_char, &l) != EMPTY) { - user_graph_headings = PHRQ_realloc(user_graph_headings, (size_t) (user_graph_count_headings + 1) * sizeof(char *)); - if (user_graph_headings == NULL) malloc_error(); - user_graph_headings[user_graph_count_headings] = string_hsave(token); - user_graph_count_headings++; - } - break; -/*Modifications of read_user_punch to change the chart's appearance */ - case 4: /* chart title */ - copy_title(token, &next_char, &l); - SetChartTitle(token); - break; - case 5: { /* axis titles */ - i = 0; - while (copy_title(token, &next_char, &l) != EMPTY) { - SetAxisTitles(token, i); - i++; - } - } - break; - case 6: { /* axis scales */ - char* axis = ""; - int j = 0; - copy_token(token, &next_char, &l); - str_tolower(token); - if (strstr(token, "x") == token) { - axis = "x"; - } else if (strstr(token, "y") == token) { - axis = "y"; - } else if (strstr(token, "s") == token) { - axis = "s"; - } else { - input_error++; - error_msg("Expected axis type.", CONTINUE); - } - while ((j < 4) && (i = copy_token(token, &next_char, &l)) != EMPTY) { - str_tolower(token); - if ((i == DIGIT) || (strstr(token, "auto") == token)) { - SetAxisScale(axis, j, token, FALSE); - } else { - input_error++; - error_msg("Expected numerical value or 'auto'.", CONTINUE); - } - j++; /* counter for categories */ - } - if (j == 4) SetAxisScale(axis, j, 0, get_true_false(next_char, FALSE)); - } - break; - case 7: - graph_initial_solutions = get_true_false(next_char, TRUE); - break; - case 8: - copy_token(token, &next_char, &l); - str_tolower(token); - if (strstr(token, "x") == token) { - chart_type = 0; - } else if (strstr(token, "t") == token) { - chart_type = 1; - } else { - input_error++; - error_msg("Expected simulation type.", CONTINUE); - } - break; - case 9: - shifts_as_points = get_true_false(next_char, TRUE); - if (shifts_as_points == TRUE) chart_type = 0; - else chart_type = 1; - break; - case 10: { - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) sscanf(token, "%d", &RowOffset); - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) sscanf(token, "%d", &ColumnOffset); - } - break; - case 11: - connect_simulations = get_true_false(next_char, TRUE); - break; - case 12: - string_trim(next_char); - strcpy(file_name, next_char); - if (!OpenCSVFile(file_name)) { - sprintf(error_string, "Can't open file, %s.", file_name); - input_error++; - error_msg(error_string, CONTINUE); - } - break; - /* End of modifications */ - case OPTION_DEFAULT: /* read first command */ - rate_free(user_graph); - user_graph->new_def = TRUE; - user_graph->commands = PHRQ_malloc(sizeof(char)); - if (user_graph->commands == NULL) malloc_error(); - user_graph->commands[0] = '\0'; - user_graph->linebase = NULL; - user_graph->varbase = NULL; - user_graph->loopbase = NULL; - user_graph->name = string_hsave("user defined Basic punch routine"); - case OPT_1: /* read command */ - length = strlen(user_graph->commands); - line_length = strlen(line); - user_graph->commands = PHRQ_realloc(user_graph->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (user_graph->commands == NULL) malloc_error(); - user_graph->commands[length] = ';'; - user_graph->commands[length + 1] = '\0'; - strcat((user_graph->commands), line); - opt_save = OPT_1; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - for (i = 0; i < user_graph_count_headings; i++) - GridHeadings(user_graph_headings[i], i); - return(return_value); -} -#endif -/* ---------------------------------------------------------------------- */ -int read_solid_solutions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solid solution data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int count_s_s, number_s_s, count_comps; - int n_user, n_user_end; - char *ptr; - char *description; - char token[MAX_LENGTH]; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "component", /* 0 */ - "comp", /* 1 */ - "parms", /* 2 */ - "gugg_nondimensional", /* 3 */ - "gugg_kj", /* 4 */ - "activity_coefficients", /* 5 */ - "distribution_coefficients", /* 6 */ - "miscibility_gap", /* 7 */ - "spinodal_gap", /* 8 */ - "critical_point", /* 9 */ - "alyotropic_point", /* 10 */ - "temp", /* 11 */ - "tempk", /* 12 */ - "tempc", /* 13 */ - "thompson", /* 14 */ - "margules", /* 15 */ - "comp1", /* 16 */ - "comp2" /* 17 */ - }; - int count_opt_list = 18; -/* - * Read s_s_assemblage number - */ - number_s_s = 0; - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); -/* - * Find old s_s_assemblage or alloc space for new s_s_assemblage - */ - if (s_s_assemblage_search(n_user, &n) != NULL) { - s_s_assemblage_free(&s_s_assemblage[n]); - } else { - n=count_s_s_assemblage; - space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - count_s_s_assemblage++; - } -/* - * Initialize - */ - s_s_assemblage_init(&(s_s_assemblage[n]), n_user, n_user_end, description); - free_check_null(description); -/* - * Set use data to first read - */ - if (use.s_s_assemblage_in == FALSE) { - use.s_s_assemblage_in = TRUE; - use.n_s_s_assemblage_user = n_user; - } -/* - * Read solid solutions - */ - count_s_s = 0; - count_comps = 0; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLID_SOLUTIONS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - -/* - * New component - */ - case 0: /* component */ - case 1: /* comp */ - count_comps=s_s_assemblage[n].s_s[number_s_s].count_comps++; - s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps+1) * sizeof(struct s_s_comp)); - if ( s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); - s_s_assemblage[n].s_s[number_s_s].comps[count_comps].initial_moles = 0; - s_s_assemblage[n].s_s[number_s_s].comps[count_comps].delta = 0; - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - s_s_assemblage[n].s_s[number_s_s].comps[count_comps].name = string_hsave(token); - /* - * Read moles of component - */ - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { - s_s_assemblage[n].s_s[number_s_s].comps[count_comps].moles = NAN; - } else { - j=sscanf( token,SCANFORMAT, &dummy); - s_s_assemblage[n].s_s[number_s_s].comps[count_comps].moles = (LDBLE) dummy; - if (j != 1 ) { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; - case 2: /* parms */ - case 3: /* gugg_nondimensional */ - /* - * Read parameters - */ - - ptr = next_char; - if (copy_token(token, &ptr, &l) != EMPTY) { - sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[0]) ); - } - if (copy_token(token, &ptr, &l) != EMPTY) { - sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[1]) ); - } - s_s_assemblage[n].s_s[number_s_s].input_case = 0; - break; - case 4: /* gugg_kj */ - ptr = next_char; - if (copy_token(token, &ptr, &l) != EMPTY) { - sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[0]) ); - } - if (copy_token(token, &ptr, &l) != EMPTY) { - sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[1]) ); - } - s_s_assemblage[n].s_s[number_s_s].input_case = 7; - break; - case 5: /* activity coefficients */ - ptr = next_char; - j = 0; - for (i = 0; i < 4; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 4) { - sprintf(error_string, "Expected 4 parameters to calculate a0 and a1 from two activity coefficients, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 1; - break; - case 6: /* distribution coefficients */ - ptr = next_char; - j = 0; - for (i = 0; i < 4; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 4) { - sprintf(error_string, "Expected 4 parameters to calculate a0 and a1 from two distribution coefficients, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 2; - break; - case 7: /* miscibility_gap */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected 2 miscibility gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 3; - break; - case 8: /* spinodal_gap */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected 2 spinodal gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 4; - break; - case 9: /* critical point */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected fraction of component 2 and critical temperature to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 5; - break; - case 10: /* alyotropic point */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected fraction of component 2 and sigma pi at alyotropic point to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 6; - break; - case 12: /* tempk */ - ptr = next_char; - j = 0; - if (copy_token(token, &ptr, &l) != EMPTY) { - j = sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].tk) ); - } - if (j != 1) { - sprintf(error_string, "Expected temperature (Kelvin) for parameters, assemblage %d, solid solution %s, using 298.15 K", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - warning_msg(error_string); - s_s_assemblage[n].s_s[number_s_s].tk = 298.15; - } - break; - case 11: /* temp */ - case 13: /* tempc */ - ptr = next_char; - j = 0; - if (copy_token(token, &ptr, &l) != EMPTY) { - j = sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].tk) ); - } - if (j != 1) { - sprintf(error_string, "Expected temperature (Celcius) for parameters, assemblage %d, solid solution %s, using 25 C", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - warning_msg(error_string); - s_s_assemblage[n].s_s[number_s_s].tk = 25.; - } - s_s_assemblage[n].s_s[number_s_s].tk += 273.15; - break; - case 14: /* Thompson and Waldbaum */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected Wg2 and Wg1 Thompson-Waldbaum parameters to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 8; - break; - case 15: /* Margules */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) { - if (copy_token(token, &ptr, &l) != EMPTY) { - j += sscanf( token,SCANFORMAT, &(s_s_assemblage[n].s_s[number_s_s].p[i]) ); - } - } - if (j != 2) { - sprintf(error_string, "Expected alpha2 and alpha3 Margules parameters to calculate a0 and a1, assemblage %d, solid solution %s", s_s_assemblage[n].n_user, s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - s_s_assemblage[n].s_s[number_s_s].input_case = 9; - break; - case 16: /* comp1 */ - if (count_comps < 2) { - s_s_assemblage[n].s_s[number_s_s].count_comps = 2; - count_comps = 2; - s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps) * sizeof(struct s_s_comp)); - if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); - } - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - s_s_assemblage[n].s_s[number_s_s].comps[0].name = string_hsave(token); - /* - * Read moles of component - */ - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { - s_s_assemblage[n].s_s[number_s_s].comps[0].moles = NAN; - } else { - j=sscanf( token,SCANFORMAT, &dummy); - s_s_assemblage[n].s_s[number_s_s].comps[0].moles = (LDBLE) dummy; - if (j != 1 ) { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; - case 17: /* comp2 */ - if (count_comps < 2) { - s_s_assemblage[n].s_s[number_s_s].count_comps = 2; - count_comps = 2; - s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_realloc(s_s_assemblage[n].s_s[number_s_s].comps, (size_t) (count_comps) * sizeof(struct s_s_comp)); - if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); - } - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - s_s_assemblage[n].s_s[number_s_s].comps[1].name = string_hsave(token); - /* - * Read moles of component - */ - if ( (j = copy_token(token, &ptr, &l)) == EMPTY) { - s_s_assemblage[n].s_s[number_s_s].comps[1].moles = NAN; - } else { - j=sscanf( token,SCANFORMAT, &dummy); - s_s_assemblage[n].s_s[number_s_s].comps[1].moles = (LDBLE) dummy; - if (j != 1 ) { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; -/* - * New solid solution - */ - case OPTION_DEFAULT: - number_s_s = count_s_s++; - /* - * Make space, set default - */ - - /* realloc space for one s_s */ - s_s_assemblage[n].s_s = (struct s_s *) PHRQ_realloc(s_s_assemblage[n].s_s, (size_t) (count_s_s + 1) * sizeof(struct s_s)); - if (s_s_assemblage[n].s_s == NULL) malloc_error(); - - /* malloc space for one component */ - s_s_assemblage[n].s_s[number_s_s].comps = (struct s_s_comp *) PHRQ_malloc((size_t) sizeof(struct s_s_comp)); - if (s_s_assemblage[n].s_s[number_s_s].comps == NULL) malloc_error(); - count_comps = 0; - s_s_assemblage[n].s_s[number_s_s].count_comps = 0; - s_s_assemblage[n].s_s[number_s_s].input_case = 0; - s_s_assemblage[n].s_s[number_s_s].miscibility = FALSE; - s_s_assemblage[n].s_s[number_s_s].p[0] = 0.0; - s_s_assemblage[n].s_s[number_s_s].p[1] = 0.0; - s_s_assemblage[n].s_s[number_s_s].tk = 298.15; - /* - * Read solid solution name - */ - ptr = line; - copy_token(token, &ptr, &l); - s_s_assemblage[n].s_s[number_s_s].name = string_hsave(token); - s_s_assemblage[n].s_s[number_s_s].total_moles = NAN; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - for (i = 0; i < s_s_assemblage[n].count_s_s; i++) { - if (s_s_assemblage[n].s_s[i].p[0] != 0.0 || - s_s_assemblage[n].s_s[i].p[1] != 0.0) { - if (s_s_assemblage[n].s_s[number_s_s].count_comps != 2) { - sprintf(error_string, "Solid solution, %s, is nonideal. Must define exactly two components (-comp1 and -comp2).", s_s_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - } - } -/* - * Sort components by name (lowercase) - */ - - s_s_assemblage[n].count_s_s = count_s_s; - qsort (s_s_assemblage[n].s_s, - (size_t) count_s_s, - (size_t) sizeof(struct s_s), - s_s_compare); - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_llnl_aqueous_model_parameters(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads aqueous model parameters - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - extern int check_line_return; /* input.c */ - int i, count_alloc; - char token[MAX_LENGTH]; - - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "temperatures", /* 0 */ - "temperature", /* 1 */ - "temp", /* 2 */ - "adh", /* 3 */ - "debye_huckel_a", /* 4 */ - "dh_a", /* 5 */ - "bdh", /* 6 */ - "debye_huckel_b", /* 7 */ - "dh_b", /* 8 */ - "bdot", /* 9 */ - "b_dot", /* 10 */ - "c_co2", /* 11 */ - "co2_coefs" /* 12 */ - }; - int count_opt_list = 13; -/* - * Initialize - */ -/* - * Read aqueous model parameters - */ - return_value = UNKNOWN; - opt = get_option(opt_list, count_opt_list, &next_char); - for (;;) { - next_char = line; - if (opt >= 0) { - copy_token(token, &next_char , &i); - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in LLNL_AQUEOUS_MODEL_PARAMETERS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - -/* - * New component - */ - case 0: /* temperatures */ - case 1: /* temperature */ - case 2: /* temp */ - count_alloc = 1; - llnl_count_temp = 0; - i = read_lines_doubles(next_char, &(llnl_temp), &(llnl_count_temp), &(count_alloc), opt_list, count_opt_list, &opt); - /* - ptr = next_char; - llnl_temp = read_list_doubles(&ptr, &count); - llnl_count_temp = count; - */ - break; - case 3: /* adh */ - case 4: /* debye_huckel_a */ - case 5: /* dh_a */ - count_alloc = 1; - llnl_count_adh = 0; - i = read_lines_doubles(next_char, &(llnl_adh), &(llnl_count_adh), &(count_alloc), opt_list, count_opt_list, &opt); - /* - ptr = next_char; - llnl_adh = read_list_doubles(&ptr, &count); - llnl_count_adh = count; - */ - break; - case 6: /* bdh */ - case 7: /* debye_huckel_b */ - case 8: /* dh_b */ - count_alloc = 1; - llnl_count_bdh = 0; - i = read_lines_doubles(next_char, &(llnl_bdh), &(llnl_count_bdh), &(count_alloc), opt_list, count_opt_list, &opt); - /* - ptr = next_char; - llnl_bdh = read_list_doubles(&ptr, &count); - llnl_count_bdh = count; - */ - break; - case 9: /* bdot */ - case 10: /* b_dot */ - count_alloc = 1; - llnl_count_bdot = 0; - i = read_lines_doubles(next_char, &(llnl_bdot), &(llnl_count_bdot), &(count_alloc), opt_list, count_opt_list, &opt); - /* - ptr = next_char; - llnl_bdot = read_list_doubles(&ptr, &count); - llnl_count_bdot = count; - */ - break; - case 11: /* c_co2 */ - case 12: /* co2_coefs */ - count_alloc = 1; - llnl_count_co2_coefs = 0; - i = read_lines_doubles(next_char, &(llnl_co2_coefs), &(llnl_count_co2_coefs), &(count_alloc), opt_list, count_opt_list, &opt); - /* - ptr = next_char; - llnl_co2_coefs = read_list_doubles(&ptr, &count); - llnl_count_co2_coefs = count; - */ - break; - } - return_value = check_line_return; - if (return_value == EOF || return_value == KEYWORD) break; - } - /* check consistency */ - if ((llnl_count_temp <= 0) || - (llnl_count_temp != llnl_count_adh) || - (llnl_count_temp != llnl_count_bdh) || - (llnl_count_temp != llnl_count_bdot) ) { - error_msg("Must define equal number (>0) of temperatures, dh_a, dh_b, and bdot parameters\nin LLNL_AQUEOUS_MODEL", CONTINUE); - input_error++; - } - if (llnl_count_co2_coefs != 5) { - error_msg("Must define 5 CO2 activity coefficient parameters in LLNL_AQUEOUS_MODEL", CONTINUE); - input_error++; - } - for (i = 1; i < llnl_count_temp; i++) { - if (llnl_temp[i-1] > llnl_temp[i]) { - error_msg("Temperatures must be in ascending order in LLNL_AQUEOUS_MODEL", CONTINUE); - input_error++; - } - } - - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_lines_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc, const char **opt_list, int count_opt_list, int *opt) -/* ---------------------------------------------------------------------- */ - - { -/* - * Reads LDBLEs on line starting at next_char - * and on succeeding lines. Appends to d. - * Stops at KEYWORD, OPTION, and EOF - * - * Input Arguments: - * next_char points to line to read from - * d points to array of LDBLEs, must be malloced - * count_d number of elements in array - * count_alloc number of elements malloced - * - * Output Arguments: - * d points to array of LDBLEs, may have been - * realloced - * count_d updated number of elements in array - * count_alloc updated of elements malloced - * - * Returns: - * KEYWORD - * OPTION - * EOF - * ERROR if any errors reading LDBLEs - */ - - if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) { - return(ERROR); - } - for(;;) { - *opt = get_option(opt_list, count_opt_list, &next_char); - if (*opt == OPTION_KEYWORD || *opt == OPTION_EOF || *opt ==OPTION_ERROR) { - break; - } else if (*opt >= 0) { - break; - } - next_char = line; - if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) { - return(ERROR); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int read_line_doubles(char *next_char, LDBLE **d, int *count_d, int *count_alloc) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l, n; - LDBLE value; - char token[MAX_LENGTH]; - - for (;;) { - j = copy_token(token, &next_char, &l); - if(j == EMPTY) { - break; - } - if (j != DIGIT) { - return(ERROR); - } - if (replace("*"," ",token) == TRUE) { - if (sscanf(token,"%d" SCANFORMAT, &n, &value) != 2) { - return(ERROR); - } - } else { - sscanf(token,SCANFORMAT, &value); - n = 1; - } - for (;;) { - if ((*count_d) + n > (*count_alloc)) { - *count_alloc *= 2; - *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); - if (*d == NULL ) malloc_error(); - } else { - break; - } - } - for (i = 0; i < n; i++) { - (*d)[(*count_d) + i] = value; - } - *count_d += n; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int next_keyword_or_option(const char **opt_list, int count_opt_list) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads to next keyword or option or eof - * - * Returns: - * KEYWORD - * OPTION - * EOF - */ - int opt; - char *next_char; - - for(;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_EOF) { /* end of file */ - break; - } else if (opt == OPTION_KEYWORD) { /* keyword */ - break; - } else if (opt >= 0 && opt < count_opt_list) { - break; - } else { - error_msg("Expected a keyword or option.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - return(opt); -} -/* ---------------------------------------------------------------------- */ -int read_named_logk(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads K's that can be used to calculate K's for species - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - - int j, l; - int i, empty; - struct logk *logk_ptr; - char token[MAX_LENGTH]; - - int return_value, opt, opt_save; - char *next_char; - const char *opt_list[] = { - "log_k", /* 0 */ - "logk", /* 1 */ - "delta_h", /* 2 */ - "deltah", /* 3 */ - "analytical_expression", /* 4 */ - "a_e", /* 5 */ - "ae", /* 6 */ - "ln_alpha1000" /* 7 */ - }; - int count_opt_list = 8; - logk_ptr = NULL; -/* - * Read name followed by options - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SPECIES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* log_k */ - case 1: /* logk */ - if (logk_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_log_k_only(next_char, &logk_ptr->log_k[0]); - opt_save = OPTION_DEFAULT; - break; - case 2: /* delta_h */ - case 3: /* deltah */ - if (logk_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_delta_h_only(next_char, &logk_ptr->log_k[1], &logk_ptr->original_units); - opt_save = OPTION_DEFAULT; - break; - case 4: /* analytical_expression */ - case 5: /* a_e */ - case 6: /* ae */ - if (logk_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - read_analytical_expression_only(next_char, &(logk_ptr->log_k[2])); - opt_save = OPTION_DEFAULT; - break; - case 7: /* ln_alpha1000 */ - if (logk_ptr == NULL) { - sprintf(error_string, "No reaction defined before option, %s.", opt_list[opt]); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - empty = TRUE; - for (i = 2; i < 7; i++) { - if (logk_ptr->log_k[i] != 0.0) { - empty = FALSE; - logk_ptr->log_k[i] = 0.0; - } - } - if (empty == FALSE) { - sprintf(error_string, "Analytical expression previously defined for %s in NAMED_EXPRESSIONS\nAnalytical expression will be overwritten.", logk_ptr->name); - warning_msg(error_string); - } - read_analytical_expression_only(next_char, &(logk_ptr->log_k[2])); - for (i = 2; i < 7; i++) { - logk_ptr->log_k[i] /= 1000.*LOG_10; - } - opt_save = OPTION_DEFAULT; - break; - case OPTION_DEFAULT: -/* - * Get space for logk information - */ - logk_ptr = NULL; - j = copy_token(token, &next_char, &l); - - logk_ptr = logk_store(token, TRUE); -/* - * Get pointer to each species in the reaction, store new species if necessary - */ - opt_save = OPTION_DEFAULT; - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_copy (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution, - * equilibrium_phases, - * exchange, - * surface, - * solid_solution, - * gas_phase, - * kinetics, - * mix, - * reaction, - * reaction_temperature - * - */ - int i, l, n, n_user, n_user_start, n_user_end, return_value; - char *ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH];; -/* - * Read "copy" - */ - ptr = line; - copy_token (token, &ptr, &l); -/* - * Read keyword - */ - copy_token (token, &ptr, &l); - check_key (token); - switch (next_keyword) { - case -1: /* Have not read line with keyword */ - case 0: /* End encountered */ - case 1: /* EOF encountered */ - case 2: /* Read aqueous model */ - case 3: /* Read master species */ - case 5: - case 9: - case 10: - case 11: - case 12: - case 14: - case 15: - case 18: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 30: - case 31: - case 32: - case 34: - case 35: - case 38: - case 39: - input_error++; - error_msg("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions.", CONTINUE); - error_msg(line_save, CONTINUE); - check_line("End of use",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(ERROR); - } -/* - * Read source index - */ - strcpy(token1, token); - i = copy_token (token, &ptr, &l); - if (i == DIGIT) { - sscanf(token,"%d",&n_user); - if (n_user < 0) { - error_msg("Source index number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - if (strstr(token,"-") != NULL) { - error_msg("COPY does not accept a range of numbers for source index", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - } else { - error_msg("Source index number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Read target index or range of indices - */ - i = copy_token (token, &ptr, &l); - if (i == DIGIT) { - replace("-"," ",token); - n = sscanf(token,"%d%d",&n_user_start, &n_user_end); - if (n == 1) { - n_user_end = n_user_start; - } - if (n_user_start < 0) { - error_msg("Target index number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - } else { - error_msg("Target index number must be a positive integer.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - - switch (next_keyword) { - case 4: /* Solution */ - copier_add(©_solution, n_user, n_user_start, n_user_end); - break; - case 6: /* Pure phases */ - case 26: - case 27: - case 28: - case 29: - copier_add(©_pp_assemblage, n_user, n_user_start, n_user_end); - break; - case 7: /* Reaction */ - copier_add(©_irrev, n_user, n_user_start, n_user_end); - break; - case 8: /* Mix */ - copier_add(©_mix, n_user, n_user_start, n_user_end); - break; - case 13: /* Ex */ - copier_add(©_exchange, n_user, n_user_start, n_user_end); - break; - case 16: /* Surface */ - copier_add(©_surface, n_user, n_user_start, n_user_end); - break; - case 17: /* Temperature */ - copier_add(©_temperature, n_user, n_user_start, n_user_end); - break; - case 19: /* Gas */ - copier_add(©_gas_phase, n_user, n_user_start, n_user_end); - break; - case 33: /* Kinetics */ - copier_add(©_kinetics, n_user, n_user_start, n_user_end); - break; - case 40: /* solid_solutions */ - case 41: /* solid_solution */ - copier_add(©_s_s_assemblage, n_user, n_user_start, n_user_end); - break; - } - return_value = check_line("End of COPY",FALSE,TRUE,TRUE,TRUE); - /* empty, eof, keyword, print */ - return(return_value); -} diff --git a/readtr.cpp b/readtr.cpp deleted file mode 100644 index c29afb06..00000000 --- a/readtr.cpp +++ /dev/null @@ -1,1121 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: readtr.c 430 2005-08-22 22:53:26Z dlpark $"; - -static int read_line_LDBLEs(char *next_char, LDBLE **d, int *count_d, int *count_alloc); - -#define OPTION_EOF -1 -#define OPTION_KEYWORD -2 -#define OPTION_ERROR -3 -#define OPTION_DEFAULT -4 -#define OPTION_DEFAULT2 -5 - -/* ---------------------------------------------------------------------- */ -int read_transport (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads advection and column information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - char *ptr; - int i, j, l; - int old_cells, max; - int count_length, count_disp, count_punch, count_print; - int count_length_alloc, count_disp_alloc; - char token[MAX_LENGTH]; - char *description; - int n_user, n_user_end; - LDBLE *length, *disp; - int *punch_temp, *print_temp; - int return_value, opt, opt_save; - char *next_char, *next_char_save; - char file_name[MAX_LENGTH]; - - const char *opt_list[] = { - "cells", /* 0 */ - "shifts", /* 1 */ - "print", /* 2 */ - "selected_output", /* 3 */ - "bcond", /* 4 */ - "timest", /* 5 */ - "diffc", /* 6 */ - "tempr", /* 7 */ - "length", /* 8 */ - "disp", /* 9 */ - "punch", /* 10 */ - "stagnant", /* 11 */ - "bc", /* 12 */ - "boundary_conditions", /* 13 */ - "time_step", /* 14 */ - "temp_retardation_factor", /* 15 */ - "diffusion_coefficient", /* 16 */ - "dispersivity", /* 17 */ - "direction", /* 18 */ - "temperature_retardation_factor", /* 19 */ - "print_cells", /* 20 */ - "selected_cells", /* 21 */ - "flow_direction", /* 22 */ - "flow", /* 23 */ - "lengths", /* 24 */ - "dispersivities", /* 25 */ - "dump", /* 26 */ - "output", /* 27 */ - "output_frequency", /* 28 */ - "selected_output_frequency",/* 29 */ - "punch_cells", /* 30 */ - "dump_frequency", /* 31 */ - "dump_restart", /* 32 */ - "punch_frequency", /* 33 */ - "print_frequency", /* 34 */ - "correct_disp", /* 35 */ - "initial_time", /* 36 */ - "warning", /* 37 */ - "warnings", /* 38 */ - "thermal_diffusion" /* 39 */ - }; - int count_opt_list = 40; - if (svnid == NULL) fprintf(stderr," "); - - - strcpy(file_name, "phreeqc.dmp"); -/* - * Initialize - */ - simul_tr++; - if (simul_tr == 1) { - correct_disp = FALSE; - old_cells = 0; - } else { - old_cells = count_cells; - } - count_length = count_disp = count_punch = count_print = 0; - length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (length == NULL) malloc_error(); - disp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (disp == NULL) malloc_error(); - punch_temp = (int *) PHRQ_malloc(sizeof(int)); - if (punch_temp == NULL) malloc_error(); - print_temp = (int *) PHRQ_malloc(sizeof(int)); - if (print_temp == NULL) malloc_error(); - count_length_alloc = count_disp_alloc = 1; - transport_start = 1; -/* - * Read transport number (not currently used) - */ - ptr=line; - read_number_description (ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); -/* - * Set use data to last read - */ - use.trans_in = TRUE; - -/* - * Read lines - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) { - opt = opt_save; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - case OPTION_DEFAULT: - input_error++; - error_msg("Unknown input in TRANSPORT keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* cells */ - sscanf(next_char, "%d", &count_cells); - opt_save = OPTION_DEFAULT; - break; - case 1: /* shifts */ - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &count_shifts); - } else { - warning_msg("Expected the number of shifts. One shift is assumed."); - count_shifts = 1; - } - j = copy_token(token, &next_char, &l); - if (j != EMPTY) { - if (j == DIGIT) { - sscanf(token, "%d", &ishift); - } else { - input_error++; - error_msg("Expected shift direction, -1, 0, 1. Use -direction instead.", CONTINUE); - ishift = 1; - } - } - opt_save = OPTION_DEFAULT; - break; - case 2: /* print */ - case 20: /* print_cells */ - print_temp = read_list_ints_range (&next_char, &count_print, TRUE, print_temp); -#ifdef SKIP - while (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &l); - print_temp = PHRQ_realloc(print_temp, (size_t) (count_print + 1) * sizeof(LDBLE)); - if (print_temp == NULL) malloc_error(); - print_temp[count_print] = l; - count_print++; - } -#endif - opt_save = 2; - break; - case 3: /* selected_output */ - case 29: /* selected_output_frequency */ - case 33: /* punch_frequency */ - sscanf(next_char, "%d", &punch_modulus); - opt_save = OPTION_DEFAULT; - break; - case 4: /* bcond */ - case 12: /* bc */ - case 13: /* boundary_conditions */ - /* first cell boundary condition */ - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) { - sscanf(token, "%d", &bcon_first); - if (bcon_first < 1 || bcon_first > 3) { - input_error++; - error_msg("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", CONTINUE); - } - } else if (i == EMPTY) { - bcon_first = 3; - } else if (strstr(token, "co") == token) { - bcon_first = 1; - } else if (strstr(token, "cl") == token) { - bcon_first = 2; - } else if (strstr(token, "f") == token) { - bcon_first = 3; - } else { - input_error++; - error_msg("Expected boundary condition to be 'constant', 'closed', or 'flux'.", CONTINUE); - } - - /* last cell boundary condition */ - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) { - sscanf(token, "%d", &bcon_last); - if (bcon_last < 1 || bcon_last > 3) { - input_error++; - error_msg("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", CONTINUE); - } - } else if (i == EMPTY) { - bcon_last = 3; - } else if (strstr(token, "co") == token) { - bcon_last = 1; - } else if (strstr(token, "cl") == token) { - bcon_last = 2; - } else if (strstr(token, "f") == token) { - bcon_last = 3; - } else { - input_error++; - error_msg("Expected boundary condition to be 'constant', 'closed', or 'flux'.", CONTINUE); - } - opt_save = OPTION_DEFAULT; - break; - case 5: /* timest */ - case 14: /* time_step */ - sscanf(next_char, SCANFORMAT, ×t); - opt_save = OPTION_DEFAULT; - break; - case 6: /* diffc */ - case 16: /* diffusion_coefficient */ - sscanf(next_char, SCANFORMAT, &diffc); - opt_save = OPTION_DEFAULT; - break; - case 7: /* tempr */ - case 15: /* temp_retardation_factor */ - case 19: /* temperature_retardation_factor */ - case 39: /* thermal_diffusion */ - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, SCANFORMAT, &tempr); - } - if (tempr < 1) { - tempr = 1; - warning_msg("Temperature retardation factor < 1 is not possible.\n" - "Temperature retardation factor = 1 assumed."); - } - j = copy_token(token, &next_char, &l); - if (j == DIGIT) { - sscanf(token, SCANFORMAT, &heat_diffc); - } - opt_save = OPTION_DEFAULT; - break; - case 8: /* length */ - case 24: /* lengths */ - if (read_line_LDBLEs(next_char, &length, &count_length, &count_length_alloc) == ERROR) { - input_error++; - error_msg("Reading lengths in TRANSPORT keyword.\n", CONTINUE); - } - opt_save = 8; - break; - case 9: /* disp */ - case 17: /* dispersivity */ - case 25: /* dispersivities */ - if (read_line_LDBLEs(next_char, &disp, &count_disp, &count_disp_alloc) == ERROR) { - input_error++; - error_msg("Reading dispersivities in TRANSPORT keyword.\n", CONTINUE); - } - opt_save = 9; - break; - case 10: /* punch */ - case 21: /* selected_cells */ - case 30: /* punch_cells */ - punch_temp = read_list_ints_range (&next_char, &count_punch, TRUE, punch_temp); -#ifdef SKIP - while (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &l); - punch_temp = PHRQ_realloc(punch_temp, (size_t) (count_punch + 1) * sizeof(LDBLE)); - if (punch_temp == NULL) malloc_error(); - punch_temp[count_punch] = l; - count_punch++; - } -#endif - opt_save = 10; - break; - case 11: /* stagnant */ -/* !!!!! sscanf(next_char, "%d", &count_stag); - */ - if (copy_token(token, &next_char, &l) != EMPTY) { - - /* exchange factor */ - if (sscanf(token, "%d", &(stag_data->count_stag)) != 1) { - input_error++; - sprintf(error_string,"Expecting number of stagnant layers."); - error_msg(error_string, CONTINUE); - break; - } - - /* exchange factor */ - j = copy_token(token, &next_char, &l); - if (j != EMPTY) { - if (sscanf(token, SCANFORMAT, &(stag_data->exch_f)) != 1) { - input_error++; - sprintf(error_string,"Expecting exchange factor for stagnant layers."); - error_msg(error_string, CONTINUE); - break; - } - copy_token(token, &next_char, &l); - if (sscanf(token, SCANFORMAT, &(stag_data->th_m)) != 1) { - input_error++; - sprintf(error_string,"Expecting porosity in the mobile zone."); - error_msg(error_string, CONTINUE); - break; - } - copy_token(token, &next_char, &l); - if (sscanf(token, SCANFORMAT, &(stag_data->th_im)) != 1) { - input_error++; - sprintf(error_string,"Expecting porosity in the immobile zone."); - error_msg(error_string, CONTINUE); - break; - } - } - } - opt_save = OPTION_DEFAULT; - break; - case 18: /* direction */ - case 22: /* flow_direction */ - case 23: /* flow */ - copy_token(token, &next_char, &l); - str_tolower(token); - if (strstr(token, "f") == token) { - ishift = 1; - } else if (strstr(token, "b") == token) { - ishift = -1; - } else if (strstr(token, "d") == token) { - ishift = 0; - } else if (strstr(token, "n") == token) { - ishift = 0; - } else { - input_error++; - error_msg("Expected flow direction to be 'forward', 'back', or 'no_flow'.", CONTINUE); - } - opt_save = OPTION_DEFAULT; - break; - case 26: /* dump */ - dump_in = TRUE; - next_char_save = next_char; - if (copy_token(file_name, &next_char, &l) == EMPTY) { - strcpy(file_name, "phreeqc.dmp"); - } else { - string_trim(next_char_save); - strcpy(file_name, next_char_save); - } -#ifdef SKIP - - /* Can not define dump_modulus an transport_start here */ - - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &dump_modulus); - } - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &transport_start); - } -#endif - opt_save = OPTION_DEFAULT; - break; - case 27: /* output */ - case 28: /* output_frequency */ - case 34: /* print_frequency */ - sscanf(next_char, "%d", &print_modulus); - opt_save = OPTION_DEFAULT; - break; - case 31: /* dump_frequency */ - dump_in = TRUE; - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &dump_modulus); - } else { - warning_msg("Expected integer value for dump_frequency."); - dump_modulus = 0; - } - opt_save = OPTION_DEFAULT; - break; - case 32: /* dump_restart */ - dump_in = TRUE; - if (copy_token(token, &next_char, &l) == DIGIT) { - sscanf(token, "%d", &transport_start); - } else { - warning_msg("Expected shift number to start calculations, 1 will be used."); - transport_start = 1; - } - opt_save = OPTION_DEFAULT; - break; - case 35: /* correct_dispersion */ - correct_disp = get_true_false(next_char, TRUE); - opt_save = OPTION_DEFAULT; - break; - case 36: /* initial_time */ - sscanf(next_char, SCANFORMAT, &initial_total_time); - opt_save = OPTION_DEFAULT; - break; - case 37: /* warning */ - case 38: /* warnings */ - transport_warnings = get_true_false(next_char, TRUE); - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* - * Determine number of cells - */ - max = count_cells; - if (count_length > max) max = count_length; - if (count_disp > max) max = count_disp; - if (max > count_cells) { - if (max == count_length) { - sprintf(token,"Number of cells is increased to number of 'lengths' %d.", count_length); - warning_msg(token); - } else { - sprintf(token,"Number of cells is increased to number of dispersivities %d.", count_disp); - warning_msg(token); - } - } -/* - * Allocate space for cell_data - */ - cell_data = (struct cell_data *)PHRQ_realloc(cell_data, (size_t)(max * (1 + stag_data->count_stag) + 1)*sizeof(struct cell_data)); - if (cell_data == NULL) malloc_error(); -/* - * Fill in data for lengths - */ - if (count_length == 0) { - if (old_cells < max) { - sprintf(error_string,"No cell-lengths were read; length = 1 m assumed."); - warning_msg(error_string); - for (i = 0; i < max; i++) cell_data[i].length = 1.0; - } - } else { - for (i = 0; i < count_length; i++) { - cell_data[i].length = length[i]; - } - if (max > count_length) { - sprintf(error_string,"Cell-lengths were read for %d cells. Last value is used till cell %d.", count_length, max); - warning_msg(error_string); - for (i = count_length - 1; i < max; i++) { - cell_data[i].length = length[count_length - 1]; - } - } - } - cell_data[0].mid_cell_x = cell_data[0].length / 2; - for (i = 1; i < max; i++) { - cell_data[i].mid_cell_x = cell_data[i-1].mid_cell_x + - (cell_data[i-1].length + cell_data[i].length)/2; - } - cell_data[max].mid_cell_x = cell_data[max-1].mid_cell_x + cell_data[max-1].length; -/* - * Fill in data for dispersivities - */ - if (count_disp == 0) { - if (old_cells < max) { - sprintf(error_string,"No dispersivities were read; disp = 0 assumed."); - warning_msg(error_string); - for (i = 0; i < max; i++) cell_data[i].disp = 0.0; - } - } else { - for (i = 0; i < count_disp; i++) { - cell_data[i].disp = disp[i]; - } - if (max > count_disp) { - sprintf(error_string,"Dispersivities were read for %d cells. Last value is used till cell %d.", count_disp, max); - warning_msg(error_string); - for (i = count_disp - 1; i < max; i++) { - cell_data[i].disp = disp[count_disp - 1]; - } - } - } - - count_cells = max; - -/* - * Account for stagnant cells - */ - if (stag_data->count_stag > 0) { - max = count_cells * (1 + stag_data->count_stag) + 1; - for (i = 0; i < count_cells; i++) { - for (l = 1; l <= stag_data->count_stag; l++) { - cell_data [ i+1+l*count_cells ] .mid_cell_x = cell_data[i].mid_cell_x; - } - } - } -/* - * Fill in data for punch - */ - if (count_punch != 0) { - for (i=0; i max || punch_temp[i] < 1) { - sprintf(error_string,"Cell number for punch is out of range, %d. Request ignored.", punch_temp[i]); - warning_msg(error_string); - } else { - cell_data[punch_temp[i]-1].punch = TRUE; - } - } - } else if (simul_tr == 1) { - for (i=0; i max || print_temp[i] < 1) { - sprintf(error_string,"Cell number for print is out of range, %d. Request ignored.", print_temp[i]); - warning_msg(error_string); - } else { - cell_data[print_temp[i]-1].print = TRUE; - } - } - } else if (simul_tr == 1) { - for (i=0; i count_shifts) { - input_error++; - sprintf(error_string,"Starting shift for transport, %d, is greater than number of shifts, %d.", transport_start, count_shifts); - error_msg(error_string, CONTINUE); - } - } -/* - * Check boundary conditions - */ - if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) { - warning_msg("Boundary condition = 'closed' not possible with advective transport.\n\t Boundary condition = 'flux' assumed."); - if (bcon_first == 2) bcon_first =3; - if (bcon_last == 2) bcon_last =3; - } -/* - * Retain data from previous run - */ - if (simul_tr > 1) { - if ((count_length == 0) && (count_disp == 0)) { - dup_print("Column data retained from former run", TRUE); - } - } -/* - * Check heat_diffc - */ - if (heat_diffc < 0) { - heat_diffc = diffc; - } else if (stag_data->count_stag == 1) { - if (stag_data->exch_f > 0) { - if (diffc <= 0 && heat_diffc > 0) { - input_error++; - sprintf(error_string,"Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); - error_msg(error_string, CONTINUE); - } else if (heat_diffc > diffc) { - sprintf(error_string,"Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", (double) diffc); - warning_msg(error_string); - } - } else { - if (heat_diffc > diffc) { - input_error++; - sprintf(error_string,"Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); - error_msg(error_string, CONTINUE); - } - } - } else if (stag_data->count_stag > 1 && heat_diffc > diffc) { - input_error++; - sprintf(error_string,"Only one stagant layer permitted (-stag) when modeling thermal diffusion."); - error_msg(error_string, CONTINUE); - } - -/* - * free storage for length, disp, punch - */ - length = (LDBLE *) free_check_null(length); - disp = (LDBLE *) free_check_null(disp); - punch_temp = (int *) free_check_null(punch_temp); - print_temp = (int *) free_check_null(print_temp); - - if (dump_in == TRUE) { - if(output_open(OUTPUT_DUMP, file_name) != OK) { - sprintf(error_string, "Can't open file, %s.", file_name); - error_msg(error_string, CONTINUE); - input_error++; - } - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int read_line_LDBLEs(char *next_char, LDBLE **d, int *count_d, int *count_alloc) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l, n; - LDBLE value; - char token[MAX_LENGTH]; - - for (;;) { - j = copy_token(token, &next_char, &l); - if(j == EMPTY) { - break; - } - if (j != DIGIT) { - return(ERROR); - } - if (replace("*"," ",token) == TRUE) { - if (sscanf(token,"%d" SCANFORMAT, &n, &value) != 2) { - return(ERROR); - } - } else { - sscanf(token,SCANFORMAT, &value); - n = 1; - } - for (;;) { - if ((*count_d) + n > (*count_alloc)) { - *count_alloc *= 2; - *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); - if (*d == NULL ) malloc_error(); - } else { - break; - } - } - for (i = 0; i < n; i++) { - (*d)[(*count_d) + i] = value; - } - *count_d += n; - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int dump(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * dumps solution compositions to file - */ - - int i, j, k, l; - - if (dump_in == FALSE || pr.dump == FALSE) return(OK); - output_rewind(OUTPUT_DUMP); - output_msg(OUTPUT_DUMP, "# Dumpfile\n# Transport simulation %d. Shift %d.\n#\n", simul_tr, transport_step); - - for (k = 0; k <= 1 + (1 + stag_data->count_stag) * count_cells; k++) { - dump_reaction(k); - dump_kinetics(k); - output_msg(OUTPUT_DUMP, "END\n"); - dump_solution(k); - dump_pp_assemblage(k); - dump_exchange(k); - dump_surface(k); - dump_gas_phase(k); - dump_s_s_assemblage(k); - output_msg(OUTPUT_DUMP, "END\n"); - } - - output_msg(OUTPUT_DUMP, "KNOBS\n"); - output_msg(OUTPUT_DUMP, "\t-iter%15d\n", itmax); - output_msg(OUTPUT_DUMP, "\t-tol %15.3e\n", (double) ineq_tol); - output_msg(OUTPUT_DUMP, "\t-step%15.3e\n", (double) step_size); - output_msg(OUTPUT_DUMP, "\t-pe_s%15.3e\n", (double) pe_step_size); - output_msg(OUTPUT_DUMP, "\t-diag "); - if (diagonal_scale == TRUE) output_msg(OUTPUT_DUMP, "true\n"); - else output_msg(OUTPUT_DUMP, "false\n"); - - output_msg(OUTPUT_DUMP, "SELECTED_OUTPUT\n"); - output_msg(OUTPUT_DUMP, "\t-file %-15s\n", "sel_o$$$.prn"); - if (punch.count_totals != 0) { - output_msg(OUTPUT_DUMP, "\t-tot "); - for (i = 0; i < punch.count_totals; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.totals[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_molalities != 0) { - output_msg(OUTPUT_DUMP, "\t-mol "); - for (i = 0; i < punch.count_molalities; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.molalities[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_activities != 0) { - output_msg(OUTPUT_DUMP, "\t-act "); - for (i = 0; i < punch.count_activities; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.activities[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_pure_phases != 0) { - output_msg(OUTPUT_DUMP, "\t-equ "); - for (i = 0; i < punch.count_pure_phases; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.pure_phases[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_si != 0) { - output_msg(OUTPUT_DUMP, "\t-si "); - for (i = 0; i < punch.count_si; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.si[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_gases != 0) { - output_msg(OUTPUT_DUMP, "\t-gas "); - for (i = 0; i < punch.count_gases; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.gases[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_s_s != 0) { - output_msg(OUTPUT_DUMP, "\t-solid_solutions "); - for (i = 0; i < punch.count_s_s; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.s_s[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - if (punch.count_kinetics != 0) { - output_msg(OUTPUT_DUMP, "\t-kin "); - for (i = 0; i < punch.count_kinetics; i++) { - output_msg(OUTPUT_DUMP, " %s", punch.kinetics[i].name); - } - output_msg(OUTPUT_DUMP, "\n"); - } - output_msg(OUTPUT_DUMP, "TRANSPORT\n"); - output_msg(OUTPUT_DUMP, "\t-cells %6d\n", count_cells); - output_msg(OUTPUT_DUMP, "\t-shifts%6d%6d\n", count_shifts, ishift); - output_msg(OUTPUT_DUMP, "\t-output_frequency %6d\n", print_modulus); - output_msg(OUTPUT_DUMP, "\t-selected_output_frequency %6d\n", punch_modulus); - output_msg(OUTPUT_DUMP, "\t-bcon %6d%6d\n", bcon_first, bcon_last); - output_msg(OUTPUT_DUMP, "\t-timest %13.5e\n", (double) timest); - output_msg(OUTPUT_DUMP, "\t-diffc %13.5e\n", (double) diffc); - output_msg(OUTPUT_DUMP, "\t-tempr %13.5e\n", (double) tempr); - if (correct_disp == TRUE) { - output_msg(OUTPUT_DUMP, "\t-correct_disp %s\n", "True"); - } else { - output_msg(OUTPUT_DUMP, "\t-correct_disp %s\n", "False"); - } - output_msg(OUTPUT_DUMP, "\t-length\n"); - for (i = 0; i < count_cells; i++) { - output_msg(OUTPUT_DUMP, "%12.3e", (double) cell_data[i].length); - if (i > 0 && (i % 8 ) == 0) output_msg(OUTPUT_DUMP, "\n"); - } - output_msg(OUTPUT_DUMP, "\n"); - output_msg(OUTPUT_DUMP, "\t-disp\n"); - for (i = 0; i < count_cells; i++) { - output_msg(OUTPUT_DUMP, "%12.3e", (double) cell_data[i].disp); - if (i > 0 && (i % 8 ) == 0) output_msg(OUTPUT_DUMP, "\n"); - } - output_msg(OUTPUT_DUMP, "\n"); - output_msg(OUTPUT_DUMP, "\t-punch_cells"); - if (stag_data->count_stag > 0) j = 1 + (1 + stag_data->count_stag) * count_cells; - else j = count_cells; - l = 0; - for (i = 0; i < j; i++) { - if (cell_data[i].punch != TRUE) continue; - output_msg(OUTPUT_DUMP, " %d", i+1); - l++; - if ((l % 20) == 0) output_msg(OUTPUT_DUMP, "\n"); - } - output_msg(OUTPUT_DUMP, "\n"); - output_msg(OUTPUT_DUMP, "\t-print_cells"); - if (stag_data->count_stag > 0) j = 1 + (1 + stag_data->count_stag) * count_cells; - else j = count_cells; - l = 0; - for (i = 0; i < j; i++) { - if (cell_data[i].print != TRUE) continue; - output_msg(OUTPUT_DUMP, " %d", i+1); - l++; - if ((l % 20) == 0) output_msg(OUTPUT_DUMP, "\n"); - } - output_msg(OUTPUT_DUMP, "\n"); - output_msg(OUTPUT_DUMP, "\t-dump $$$.dmp\n"); - output_msg(OUTPUT_DUMP, "\t-dump_frequency %d\n", dump_modulus); - output_msg(OUTPUT_DUMP, "\t-dump_restart %d\n", transport_step + 1); - - output_msg(OUTPUT_DUMP, "END\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_exchange(int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print moles of each exchange species - */ - int i, j, n; - struct exchange *exchange_ptr; - - exchange_ptr = exchange_bsearch(k, &n); - if ( exchange_ptr == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "EXCHANGE %d\n", k); -#ifdef SKIP - for (i = 0; i < exchange[n].count_comps; i++) { - output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].formula); - if (exchange[n].comps[i].phase_name != NULL) { - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", - exchange[n].comps[i].phase_name, - exchange[n].comps[i].phase_proportion); - } else { - for (j = 0; exchange[n].comps[i].totals[j].elt != NULL; j++) { - if (strcmp(exchange_ptr->comps[i].totals[j].elt->name, exchange[n].comps[i].formula) == NULL) { - output_msg(OUTPUT_DUMP, "%15.6e\n", exchange[n].comps[i].totals[j].coef); - } - } - } - } -#endif - for (i = 0; i < exchange[n].count_comps; i++) { - if (exchange[n].comps[i].phase_name != NULL) { - output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].formula); - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", - exchange[n].comps[i].phase_name, - (double) exchange[n].comps[i].phase_proportion); - } else { - for (j = 0; exchange[n].comps[i].totals[j].elt != NULL; j++) { -/* if (exchange_ptr->comps[i].totals[j].elt->master->type != EX) continue; */ - output_msg(OUTPUT_DUMP, "\t%-15s", exchange[n].comps[i].totals[j].elt->name); - output_msg(OUTPUT_DUMP, "%15.6e", (double) exchange[n].comps[i].totals[j].coef); - - if (exchange[n].comps[i].rate_name != NULL) { - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", exchange[n].comps[i].rate_name, (double) exchange[n].comps[i].phase_proportion); - } -#ifdef SKIP - for (l = 0; l < count_kin_exch; l++) { - if (strcmp_nocase(kin_exch[l].exch_name, exchange[n].comps[i].totals[j].elt->name) != 0) continue; - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", kin_exch[l].phase_name, kin_exch[l].phase_proportion); - } -#endif - output_msg(OUTPUT_DUMP, "\n"); - } - } - } - output_msg(OUTPUT_DUMP, "\t-equil %d\n", k); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_pp_assemblage(int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints saturation indices and masses of pure_phases in pp_assemblage - */ - int j, n; - - if (pp_assemblage_search(k, &n) == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "EQUILIBRIUM_PHASES %d\n", k); - for (j = 0; j < pp_assemblage[n].count_comps; j++) { - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", - pp_assemblage[n].pure_phases[j].name, - (double) pp_assemblage[n].pure_phases[j].si); - - if (pp_assemblage[n].pure_phases[j].add_formula == NULL) { - output_msg(OUTPUT_DUMP, "%15.6e", - (double) pp_assemblage[n].pure_phases[j].moles); - } else { - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e", - pp_assemblage[n].pure_phases[j].add_formula, - (double) pp_assemblage[n].pure_phases[j].moles); - } - output_msg(OUTPUT_DUMP, "\n"); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_reaction (int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps reaction data - */ - int i; - struct irrev *irrev_ptr; - - if ((irrev_ptr = irrev_search(k, &i)) == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "REACTION %d\n", k); - for (i = 0; i < irrev_ptr->count_list; i++) { - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", - irrev_ptr->list[i].name, - (double) irrev_ptr->list[i].coef); - } - if (irrev_ptr->count_steps >= 1) { - for (i = 0; i < irrev_ptr->count_steps; i++) - output_msg(OUTPUT_DUMP, "%15.6e", (double) irrev_ptr->steps[i]); - } else { - output_msg(OUTPUT_DUMP, "\t%15.6e in %d step", - (double) irrev_ptr->steps[0], - - irrev_ptr->count_steps); - } - output_msg(OUTPUT_DUMP, "\n"); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_surface(int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print moles of each surface master species - */ - int i, j, l, n; - struct surface *surface_ptr; - - if ((surface_ptr = surface_bsearch(k, &n)) == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "SURFACE %d\n", k); - for (i = 0; i < surface[n].count_comps; i++) { - for (j = 0; surface[n].comps[i].totals[j].elt != NULL; j++) { - if (surface_ptr->comps[i].totals[j].elt->master->type != SURF) continue; - output_msg(OUTPUT_DUMP, "\t%-13s", surface[n].comps[i].totals[j].elt->name); - - if (surface[n].comps[i].phase_name != NULL) { - output_msg(OUTPUT_DUMP, "\t%-13s equi %13.5e", - surface[n].comps[i].phase_name, - (double) surface[n].comps[i].phase_proportion); - } else if (surface[n].comps[i].rate_name != NULL) { - output_msg(OUTPUT_DUMP, "\t%-13s kine %13.5e", - surface[n].comps[i].rate_name, - (double) surface[n].comps[i].phase_proportion); - } else { - output_msg(OUTPUT_DUMP, "\t%13.5e", (double) surface[n].comps[i].totals[j].coef); -#ifdef SKIP - for (l = 0; l < count_kin_surf; l++) { - if (strcmp_nocase(kin_surf[l].surf_name, surface[n].comps[i].totals[j].elt->name) != 0) continue; - output_msg(OUTPUT_DUMP, "\t%-13s %13.5e", kin_surf[l].phase_name, kin_surf[l].phase_proportion); - } -#endif - } - if (surface[n].edl == TRUE) { - l = surface[n].comps[i].charge; - output_msg(OUTPUT_DUMP, " %13.5e", (double) surface[n].charge[l].specific_area); - if (surface[n].comps[i].phase_name == NULL && surface[n].comps[i].rate_name == NULL) { - output_msg(OUTPUT_DUMP, " %13.5e\n", (double) surface[n].charge[l].grams); - } else output_msg(OUTPUT_DUMP, "\n"); - } else output_msg(OUTPUT_DUMP, "\n"); - } - } - if (surface[n].diffuse_layer == TRUE) { - output_msg(OUTPUT_DUMP, "\t-diffuse\t%13.5e\n", (double) surface[n].thickness); - } else if (surface[n].edl == FALSE) { - output_msg(OUTPUT_DUMP, "\t-no_edl\n"); - } - - - output_msg(OUTPUT_DUMP, "\t-equil %d\n", k); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_gas_phase(int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps gas phase data - */ - int i, n; - LDBLE lp; - struct rxn_token *rxn_ptr; - struct gas_phase *gas_phase_ptr; - - if ((gas_phase_ptr = gas_phase_bsearch(k, &n)) == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "GAS_PHASE %d\n", k); - output_msg(OUTPUT_DUMP, "\t-pressure%15.6e\n", (double) gas_phase[n].total_p); - output_msg(OUTPUT_DUMP, "\t-volume%15.6e\n", (double) gas_phase[n].volume); - output_msg(OUTPUT_DUMP, "\t-temperature%15.6e\n", (double) gas_phase[n].temperature); - for (i = 0; i < gas_phase[n].count_comps; i++) { -/* - * Calculate partial pressure - */ - lp=-gas_phase_ptr->comps[i].phase->lk; - if (use.gas_phase_ptr->comps[i].phase->rxn_x != NULL) { - for (rxn_ptr = use.gas_phase_ptr->comps[i].phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - } else { - lp = -99.9; - } - output_msg(OUTPUT_DUMP, "\t%-15s%15.6e\n", - gas_phase[n].comps[i].name, - (double) lp); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_s_s_assemblage(int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps solid solution data - */ - int i, j, n; - struct s_s_assemblage *s_s_assemblage_ptr; - - s_s_assemblage_ptr = s_s_assemblage_bsearch(k, &n); - if (s_s_assemblage_ptr == NULL) return(OK); - - output_msg(OUTPUT_DUMP, "SOLID_SOLUTIONS %d\n", k); - for (i = 0; i < s_s_assemblage[n].count_s_s; i++) { - output_msg(OUTPUT_DUMP, "\t%-15s\n", s_s_assemblage[n].s_s[i].name); - for (j = 0; j < s_s_assemblage[n].s_s[i].count_comps; j++) { - output_msg(OUTPUT_DUMP, "\t\t-comp\t%-15s%15.6e\n", - s_s_assemblage[n].s_s[i].comps[j].name, - (double) s_s_assemblage[n].s_s[i].comps[j].moles); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_kinetics (int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps kinetics data - */ - int i, j, n; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; - - if ((kinetics_ptr = kinetics_search(k, &n, FALSE)) == NULL) return(OK); - output_msg(OUTPUT_DUMP, "KINETICS %d\n", k); - for (i = 0; i < kinetics[n].count_comps; i++) { - output_msg(OUTPUT_DUMP, "%-15s\n", kinetics_ptr->comps[i].rate_name); - - kinetics_comp_ptr = &kinetics_ptr->comps[i]; - output_msg(OUTPUT_DUMP, "\t-formula "); - for (j = 0; j < kinetics_comp_ptr->count_list; j++) { - output_msg(OUTPUT_DUMP, " %s %12.3e", kinetics_comp_ptr->list[j].name, (double) kinetics_comp_ptr->list[j].coef); - } - output_msg(OUTPUT_DUMP, "\n"); - - output_msg(OUTPUT_DUMP, "\t-tol %15.2e\n", (double) kinetics_ptr->comps[i].tol); - output_msg(OUTPUT_DUMP, "\t-m0 %15.6e\n", (double) kinetics_ptr->comps[i].m0); - output_msg(OUTPUT_DUMP, "\t-m %15.6e\n", (double) kinetics_ptr->comps[i].m); - - if (kinetics_comp_ptr->count_d_params != 0) { - output_msg(OUTPUT_DUMP, "\t-parm"); - for (j = 0; j < kinetics_comp_ptr->count_d_params; j++) { - output_msg(OUTPUT_DUMP, "%15.6e", (double) kinetics_comp_ptr->d_params[j]); - } - output_msg(OUTPUT_DUMP, "\n"); - } - -/* not dumped: kinetics_comp_ptr->count_c_params = 0 */ - } - output_msg(OUTPUT_DUMP, "\t-step_divide %15.6e\n", (double) kinetics[n].step_divide); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_solution (int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps solution data - */ - int i, j; - struct solution *solution_ptr; - - solution_ptr = solution_bsearch(k, &j, TRUE); - if (solution_ptr != NULL) { - output_msg(OUTPUT_DUMP, "SOLUTION %d\n", k); - output_msg(OUTPUT_DUMP, "\tunits mol/kgw\n"); - output_msg(OUTPUT_DUMP, "\ttemp %5.1f\n", (double) solution_ptr->tc); - output_msg(OUTPUT_DUMP, "\tpH %9.5f\n", (double) solution_ptr->ph); - output_msg(OUTPUT_DUMP, "\tpe %9.5f\n", (double) solution_ptr->solution_pe); - output_msg(OUTPUT_DUMP, "\twater %9.5f\n", (double) solution_ptr->mass_water); - for (i = 0; solution_ptr->totals[i].description != NULL; i++) { - /* - * write out totals... - */ - output_msg(OUTPUT_DUMP, "\t%-6s", solution_ptr->totals[i].description); - output_msg(OUTPUT_DUMP, " %13.5e\n", (double) (solution_ptr->totals[i].moles/solution_ptr->mass_water)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int dump_mix (int k) -/* ---------------------------------------------------------------------- */ -{ -/* - * Dumps solution data - */ - int j; - struct mix *mix_ptr; - - mix_ptr = mix_bsearch(k, &j); - if (mix_ptr == NULL) return(ERROR); - for (j = 0; j < mix_ptr->count_comps; j++) { - dump_solution(mix_ptr->comps[j].n_solution); - } - output_msg(OUTPUT_DUMP, "MIX %d\n", k); - for (j = 0; j < mix_ptr->count_comps; j++) { - output_msg(OUTPUT_DUMP, "\t5%d\t%13.5e\n", mix_ptr->comps[j].n_solution, (double) mix_ptr->comps[j].fraction); - } - return(OK); -} diff --git a/smalldense.cpp b/smalldense.cpp deleted file mode 100644 index 4116703f..00000000 --- a/smalldense.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************* - * * - * File : smalldense.c * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic DENSE linear * - * solver package, intended for small dense matrices. * - * * - *******************************************************************/ - -#include -#include -#include "smalldense.h" -#include "sundialstypes.h" -#include "sundialsmath.h" -#include "output.h" -#include "phqalloc.h" -/* WARNING don't include any headers below here */ -#define malloc PHRQ_malloc -static char const svnid[] = "$Id: smalldense.c 663 2005-11-16 00:46:04Z dlpark $"; - -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) - - -/* Implementation */ - - -realtype **denalloc(integertype n) -{ - integertype j; - realtype **a; - - if (n <= 0) return(NULL); - - a = (realtype **) malloc(n * sizeof(realtype *)); - if (a == NULL) return(NULL); - - a[0] = (realtype *) malloc(n * n * sizeof(realtype)); - if (a[0] == NULL) { - free(a); - return(NULL); - } - - for (j=1; j < n; j++) a[j] = a[0] + j * n; - - return(a); -} - -integertype *denallocpiv(integertype n) -{ - if (n <= 0) return(NULL); - - return((integertype *) malloc(n * sizeof(integertype))); -} - -integertype gefa(realtype **a, integertype n, integertype *p) -{ - integertype i, j, k, l; - realtype *col_j, *col_k, *diag_k; - realtype temp, mult, a_kj; - booleantype swap; - - /* k = elimination step number */ - - for (k=0; k < n-1; k++, p++) { - - col_k = a[k]; - diag_k = col_k + k; - - /* find l = pivot row number */ - - l=k; - for (i=k+1; i < n; i++) - if (ABS(col_k[i]) > ABS(col_k[l])) l=i; - *p = l; - - /* check for zero pivot element */ - - if (col_k[l] == ZERO) return(k+1); - - /* swap a(l,k) and a(k,k) if necessary */ - - /*if ( (swap = (l != k) )) {*/ - swap = (l != k); - if (swap) { - temp = col_k[l]; - col_k[l] = *diag_k; - *diag_k = temp; - } - - /* Scale the elements below the diagonal in */ - /* column k by -1.0 / a(k,k). After the above swap, */ - /* a(k,k) holds the pivot element. This scaling */ - /* stores the pivot row multipliers -a(i,k)/a(k,k) */ - /* in a(i,k), i=k+1, ..., n-1. */ - - mult = -ONE / (*diag_k); - for(i=k+1; i < n; i++) - col_k[i] *= mult; - - /* row_i = row_i - [a(i,k)/a(k,k)] row_k, i=k+1, ..., n-1 */ - /* row k is the pivot row after swapping with row l. */ - /* The computation is done one column at a time, */ - /* column j=k+1, ..., n-1. */ - - for (j=k+1; j < n; j++) { - - col_j = a[j]; - a_kj = col_j[l]; - - /* Swap the elements a(k,j) and a(k,l) if l!=k. */ - - if (swap) { - col_j[l] = col_j[k]; - col_j[k] = a_kj; - } - - /* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */ - /* a_kj = a(k,j), col_k[i] = - a(i,k)/a(k,k) */ - - if (a_kj != ZERO) { - for (i=k+1; i < n; i++) - col_j[i] += a_kj * col_k[i]; - } - } - } - - /* set the last pivot row to be n-1 and check for a zero pivot */ - - *p = n-1; - if (a[n-1][n-1] == ZERO) return(n); - - /* return 0 to indicate success */ - - return(0); -} - -void gesl(realtype **a, integertype n, integertype *p, realtype *b) -{ - integertype k, l, i; - realtype mult, *col_k; - - /* Solve Ly = Pb, store solution y in b */ - - for (k=0; k < n-1; k++) { - l = p[k]; - mult = b[l]; - if (l != k) { - b[l] = b[k]; - b[k] = mult; - } - col_k = a[k]; - for (i=k+1; i < n; i++) - b[i] += mult*col_k[i]; - } - - /* Solve Ux = y, store solution x in b */ - - for (k=n-1; k >= 0; k--) { - col_k = a[k]; - b[k] /= col_k[k]; - mult = -b[k]; - for (i=0; i < k; i++) - b[i] += mult*col_k[i]; - } -} - -void denzero(realtype **a, integertype n) -{ - integertype i, j; - realtype *col_j; - - for (j=0; j < n; j++) { - col_j = a[j]; - for (i=0; i < n; i++) - col_j[i] = ZERO; - } -} - -void dencopy(realtype **a, realtype **b, integertype n) -{ - integertype i, j; - realtype *a_col_j, *b_col_j; - - for (j=0; j < n; j++) { - a_col_j = a[j]; - b_col_j = b[j]; - for (i=0; i < n; i++) - b_col_j[i] = a_col_j[i]; - } - -} - -void denscale(realtype c, realtype **a, integertype n) -{ - integertype i, j; - realtype *col_j; - - for (j=0; j < n; j++) { - col_j = a[j]; - for (i=0; i < n; i++) - col_j[i] *= c; - } -} - -void denaddI(realtype **a, integertype n) -{ - integertype i; - - for (i=0; i < n; i++) a[i][i] += ONE; -} - -void denfreepiv(integertype *p) -{ - free(p); -} - -void denfree(realtype **a) -{ - free(a[0]); - free(a); -} - -void denprint(realtype **a, integertype n) -{ - integertype i, j; - - printf("\n"); - for (i=0; i < n; i++) { - for (j=0; j < n; j++) { - printf("%10g", (double) a[j][i]); - } - printf("\n"); - } - printf("\n"); -} diff --git a/smalldense.h b/smalldense.h deleted file mode 100644 index bffcc85c..00000000 --- a/smalldense.h +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************* - * * - * File : smalldense.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic DENSE linear solver * - * package, intended for small dense matrices. These routines * - * use the type realtype** for dense matrix arguments. * - * * - * These routines begin with "den" (except for the factor and * - * solve routines which are called gefa and gesl, respectively). * - * The underlying matrix storage is described in the * - * documentation for denalloc. * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidsmalldense[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef _smalldense_h -#define _smalldense_h - -#include "sundialstypes.h" - - -/****************************************************************** - * * - * Function : denalloc * - * Usage : realtype **a; * - * a = denalloc(n); * - * if (a == NULL) ... memory request failed * - *----------------------------------------------------------------* - * denalloc(n) allocates storage for an n by n dense matrix. It * - * returns a pointer to the newly allocated storage if * - * successful. If the memory request cannot be satisfied, then * - * denalloc returns NULL. The underlying type of the dense matrix * - * returned is realtype **. If we allocate a dense matrix * - * realtype **a by a = denalloc(n), then a[j][i] references the * - * (i,j)th element of the matrix a, 0 <= i,j <= n-1, and a[j] is * - * a pointer to the first element in the jth column of a. * - * The location a[0] contains a pointer to n^2 contiguous * - * locations which contain the elements of a. * - * * - ******************************************************************/ - -realtype **denalloc(integertype n); - - -/****************************************************************** - * * - * Function : denallocpiv * - * Usage : integertype *pivot; * - * pivot = denallocpiv(n); * - * if (pivot == NULL) ... memory request failed * - *----------------------------------------------------------------* - * denallocpiv(n) allocates an array of n integertype. It returns * - * a pointer to the first element in the array if successful. * - * It returns NULL if the memory request could not be satisfied. * - * * - ******************************************************************/ - -integertype *denallocpiv(integertype n); - - -/****************************************************************** - * * - * Function : gefa * - * Usage : integertype ier; * - * ier = gefa(a,n,p); * - * if (ier > 0) ... zero element encountered during * - * the factorization * - *----------------------------------------------------------------* - * gefa(a,n,p) factors the n by n dense matrix a. It overwrites * - * the elements of a with its LU factors and keeps track of the * - * pivot rows chosen in the pivot array p. * - * * - * A successful LU factorization leaves the matrix a and the * - * pivot array p with the following information: * - * * - * (1) p[k] contains the row number of the pivot element chosen * - * at the beginning of elimination step k, k=0, 1, ..., n-1. * - * * - * (2) If the unique LU factorization of a is given by Pa = LU, * - * where P is a permutation matrix, L is a lower triangular * - * matrix with all 1's on the diagonal, and U is an upper * - * triangular matrix, then the upper triangular part of a * - * (including its diagonal) contains U and the strictly lower * - * triangular part of a contains the multipliers, I-L. * - * * - * gefa returns 0 if successful. Otherwise it encountered a zero * - * diagonal element during the factorization. In this case it * - * returns the column index (numbered from one) at which it * - * encountered the zero. * - * * - ******************************************************************/ - -integertype gefa(realtype **a, integertype n, integertype *p); - - -/****************************************************************** - * * - * Function : gesl * - * Usage : realtype *b; * - * ier = gefa(a,n,p); * - * if (ier == 0) gesl(a,n,p,b); * - *----------------------------------------------------------------* - * gesl(a,n,p,b) solves the n by n linear system ax = b. It * - * assumes that a has been LU factored and the pivot array p has * - * been set by a successful call to gefa(a,n,p). The solution x * - * is written into the b array. * - * * - ******************************************************************/ - -void gesl(realtype **a, integertype n, integertype *p, realtype *b); - - -/****************************************************************** - * * - * Function : denzero * - * Usage : denzero(a,n); * - *----------------------------------------------------------------* - * denzero(a,n) sets all the elements of the n by n dense matrix * - * a to be 0.0. * - * * - ******************************************************************/ - -void denzero(realtype **a, integertype n); - - -/****************************************************************** - * * - * Function : dencopy * - * Usage : dencopy(a,b,n); * - *----------------------------------------------------------------* - * dencopy(a,b,n) copies the n by n dense matrix a into the * - * n by n dense matrix b. * - * * - ******************************************************************/ - -void dencopy(realtype **a, realtype **b, integertype n); - - -/****************************************************************** - * * - * Function : denscale * - * Usage : denscale(c,a,n); * - *----------------------------------------------------------------* - * denscale(c,a,n) scales every element in the n by n dense * - * matrix a by c. * - * * - ******************************************************************/ - -void denscale(realtype c, realtype **a, integertype n); - - -/****************************************************************** - * * - * Function : denaddI * - * Usage : denaddI(a,n); * - *----------------------------------------------------------------* - * denaddI(a,n) increments the n by n dense matrix a by the * - * identity matrix. * - * * - ******************************************************************/ - -void denaddI(realtype **a, integertype n); - - -/****************************************************************** - * * - * Function : denfreepiv * - * Usage : denfreepiv(p); * - *----------------------------------------------------------------* - * denfreepiv(p) frees the pivot array p allocated by * - * denallocpiv. * - * * - ******************************************************************/ - -void denfreepiv(integertype *p); - - -/****************************************************************** - * * - * Function : denfree * - * Usage : denfree(a); * - *----------------------------------------------------------------* - * denfree(a) frees the dense matrix a allocated by denalloc. * - * * - ******************************************************************/ - -void denfree(realtype **a); - - -/****************************************************************** - * * - * Function : denprint * - * Usage : denprint(a,n); * - *----------------------------------------------------------------* - * denprint(a,n) prints the n by n dense matrix a to standard * - * output as it would normally appear on paper. It is intended as * - * a debugging tool with small values of n. The elements are * - * printed using the %g option. A blank line is printed before * - * and after the matrix. * - * * - ******************************************************************/ - -void denprint(realtype **a, integertype n); - - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/spread.cpp b/spread.cpp deleted file mode 100644 index 61fdc15c..00000000 --- a/spread.cpp +++ /dev/null @@ -1,1069 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: spread.c 187 2005-03-16 19:54:17Z charlton $"; - -#define STATIC static - -#define STRING 11 -#define NUMBER 12 -#define MIXED 13 -#define EOL 14 - -#define OPTION_EOF -1 -#define OPTION_KEYWORD -2 -#define OPTION_ERROR -3 -#define OPTION_DEFAULT -4 -#define OPT_1 -5 - -static int copy_token_tab(char *token_ptr, char **ptr, int *length); -static int get_option_string (const char **opt_list, int count_opt_list, char **next_char); -static int spread_row_free(struct spread_row *spread_row_ptr); -static int spread_row_to_solution(struct spread_row *heading, struct spread_row *units, struct spread_row *data, struct defaults defaults); -static struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI -static void add_row(struct spread_row *spread_row_ptr); -static void copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr); -void free_spread(void); -static struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - -/* ---------------------------------------------------------------------- */ -int read_solution_spread(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - struct spread_row *heading, *row_ptr, *units; - int i, j, l, j1, num, count; - int strings, numbers; - int spread_lines; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char *ptr; - struct defaults defaults = { - 25, - 1, - "mmol/kgw", - "pe", - 7, - 4, - 1, - 1, - iso_defaults, - }; - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "temp", /* 0 */ - "temperature", /* 1 */ - "dens", /* 2 */ - "density", /* 3 */ - "units", /* 4 */ - "redox", /* 5 */ - "ph", /* 6 */ - "pe", /* 7 */ - "unit", /* 8 */ - "isotope", /* 9 */ - "water", /* 10 */ - "isotope_uncertainty", /* 11 */ - "uncertainty", /* 12 */ - "uncertainties" /* 13 */ - }; - int count_opt_list = 14; - if (svnid == NULL) fprintf(stderr," "); - - heading = NULL; - units = NULL; - defaults.count_iso = count_iso_defaults; - defaults.iso = (struct iso *) PHRQ_malloc((size_t) defaults.count_iso * sizeof(struct iso)); - if (defaults.iso == NULL) malloc_error(); - memcpy(defaults.iso, iso_defaults, (size_t) defaults.count_iso * sizeof(struct iso)); - return_value = UNKNOWN; - spread_lines = 0; -/* - * Loop on solutions - */ - for (;;) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (spread_lines == 0 && opt != OPTION_DEFAULT) { - row_ptr = string_to_spread_row(line); - count = 0; - ptr = line; - numbers = 0; - strings = 0; - while ( ((j = copy_token(token, &ptr, &l)) != EMPTY)) { - count++; - if (j == UPPER || j == LOWER) strings++; - if (j == DIGIT) numbers++; - } -#ifdef SKIP - for (i = 0; i < row_ptr->count; i++) { - if (row_ptr->type_vector[i] == STRING) { - strings++; - } else if (row_ptr->type_vector[i] == NUMBER) { - numbers++; - } - } -#endif - /* - * Is 2nd token all number - */ - ptr = line; - copy_token(token, &ptr, &l); - j = copy_token(token, &ptr, &l); - num = FALSE; - if (j == DIGIT) { - strtod(token, &ptr); - j1 = copy_token(token1, &ptr, &l); - if (j1 != EMPTY) { - num = FALSE; - } else { - num = TRUE; - } - } - - /* - * Starts with hyphen - */ - ptr = line; - copy_token(token, &ptr, &l); - if (token[0] == '-') { - opt = opt; - } else { - switch (opt) { - case 0: /* temp */ - case 1: /* temperature */ - case 2: /* dens */ - case 3: /* density */ - case 10: /* water */ - if (count == 2 && num == TRUE) { - opt = opt; - } else { - opt = OPTION_DEFAULT; - } - break; - case 6: /* ph */ - case 7: /* pe */ - if ((count == 2 || count == 3 || count == 4) && num == TRUE) { - opt = opt; - } else { - opt = OPTION_DEFAULT; - } - break; - case 5: /* redox */ - case 4: /* units */ - case 8: /* unit */ - if (count == 2) { - opt = opt; - } else { - opt = OPTION_DEFAULT; - } - break; - case 9: /* isotope */ - if (row_ptr->count > 4) { - opt = OPTION_DEFAULT; - } else { - opt = opt; - } - break; - case 11: /* isotope_uncertainty */ - case 12: /* uncertainty */ - case 13: /* uncertainties */ - if (row_ptr->count > 3) { - opt = OPTION_DEFAULT; - } else { - opt = opt; - } - break; - } - } - spread_row_free(row_ptr); - } - if (opt == OPTION_DEFAULT) { - if (spread_lines == 0) { - opt = 100; - } - spread_lines++; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLUTION keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case OPTION_DEFAULT: /* solution definition */ - row_ptr = string_to_spread_row(line); - if (spread_lines == 2) { - numbers = 0; - strings = 0; - for (i = 0; i < heading->count; i++) { - if (row_ptr->type_vector[i] == STRING) { - strings++; - } else if (row_ptr->type_vector[i] == NUMBER) { - numbers++; - } -#ifdef SKIP - if (row_ptr->type_vector[i] == STRING && - (strcmp_nocase(heading->char_vector[i],"units") != 0) && - (strcmp_nocase(heading->char_vector[i],"unit") != 0) && - (strcmp_nocase(heading->char_vector[i],"description") != 0) && - (strcmp_nocase(heading->char_vector[i],"desc") != 0) && - (strcmp_nocase(heading->char_vector[i],"descriptor") != 0) && - (strcmp_nocase(heading->char_vector[i],"redox") != 0) ) { - break; - } -#endif - } -#ifdef SKIP - if (i < heading->count) { - units = row_ptr; - break; - } -#endif - if (numbers == 0) { - units = row_ptr; - break; - } - } - spread_row_to_solution(heading, units, row_ptr, defaults); -#ifdef PHREEQCI_GUI - add_row(row_ptr); -#endif - spread_row_free(row_ptr); - break; - case 0: /* temperature */ - case 1: - sscanf(next_char,SCANFORMAT, &(defaults.temp)); - break; - case 2: /* density */ - case 3: - sscanf(next_char,SCANFORMAT, &(defaults.density)); - break; - case 4: /* units */ - case 8: /* unit */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (check_units (token, FALSE, FALSE, NULL, TRUE) == OK) { - defaults.units = string_hsave(token); - } else { - input_error++; - } - break; - case 5: /* redox */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (parse_couple(token) == OK) { - defaults.redox = string_hsave(token); - } else { - input_error++; - } - break; - case 6: /* ph */ - copy_token (token, &next_char, &l); - sscanf(token,SCANFORMAT, &(defaults.ph)); - if (copy_token (token, &next_char, &l) != EMPTY) { - warning_msg("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD."); - } - break; - case 7: /* pe */ - copy_token (token, &next_char, &l); - sscanf(token,SCANFORMAT, &(defaults.pe)); - if (copy_token (token, &next_char, &l) != EMPTY) { - warning_msg("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD."); - } - break; - case 11: /* isotope_uncertainty */ - case 12: /* uncertainty */ - case 13: /* uncertainties */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - for (i = 0; i < defaults.count_iso; i++) { - if (strcmp(token, defaults.iso[i].name) == 0) { - break; - } - } - if (i == defaults.count_iso) { - defaults.iso = (struct iso *) PHRQ_realloc(defaults.iso, (size_t) (i+1) * sizeof(struct iso)); - if (defaults.iso == NULL) malloc_error(); - defaults.iso[i].name = string_duplicate(token); - defaults.iso[i].value = NAN; - defaults.iso[i].uncertainty = NAN; - defaults.count_iso++; - } - - /* read and store isotope ratio uncertainty */ - if ( (j = copy_token(token, &next_char, &l)) != EMPTY) { - if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } else { - sscanf(token, SCANFORMAT, &(defaults.iso[i].uncertainty)); - } - } else { - defaults.iso[i].uncertainty = NAN; - } - break; - case 10: /* water */ - j = copy_token (token, &next_char, &l); - if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } else { - sscanf(token, SCANFORMAT, &(defaults.water)); - } - break; - case 9: /* isotope */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - for (i = 0; i < defaults.count_iso; i++) { - if (strcmp(token, defaults.iso[i].name) == 0) { - break; - } - } - if (i == defaults.count_iso) { - defaults.iso = (struct iso *) PHRQ_realloc(defaults.iso, (size_t) (i+1) * sizeof(struct iso)); - if (defaults.iso == NULL) malloc_error(); - defaults.iso[i].name = string_duplicate(token); - defaults.iso[i].value = NAN; - defaults.iso[i].uncertainty = NAN; - defaults.count_iso++; - } - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for default isotope ratio."); - error_msg(error_string, CONTINUE); - break; - } - sscanf(token, SCANFORMAT, &(defaults.iso[i].value)); - /* read and store isotope ratio uncertainty */ - if ( (j = copy_token(token, &next_char, &l)) != EMPTY) { - if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for uncertainty in isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } else { - sscanf(token, SCANFORMAT, &(defaults.iso[i].uncertainty)); - } - } - break; - case 100: /* read headings */ - heading = string_to_spread_row(line); - for (i = 0; i < heading->count; i++) { - while(replace(" ", "", heading->char_vector[i]) == TRUE); - while(replace(",", "_", heading->char_vector[i]) == TRUE); - } - - break; - } - if (return_value == EOF || return_value == KEYWORD) break; - } -#ifdef PHREEQCI_GUI - if (heading) g_spread_sheet.heading = copy_row(heading); - if (units) g_spread_sheet.units = copy_row(units); - copy_defaults(&g_spread_sheet.defaults, &defaults); -#endif - spread_row_free(heading); - spread_row_free(units); - /* free non-default iso names */ - for (i = count_iso_defaults; i < defaults.count_iso; i++) { - defaults.iso[i].name = (char *) free_check_null(defaults.iso[i].name); - } - defaults.iso = (struct iso *) free_check_null(defaults.iso); - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int spread_row_to_solution(struct spread_row *heading, struct spread_row *units, - struct spread_row *data, struct defaults defaults) -/* ---------------------------------------------------------------------- */ -{ - int i, j, n, l, next_keyword_save; - int n_user, n_user_end; - int default_pe, alk; - int count_isotopes; - int max_mass_balance, count_mass_balance; - char *ptr, *ptr1; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char string[2*MAX_LENGTH]; - LDBLE dummy; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "temp", /* 0 */ - "temperature", /* 1 */ - "dens", /* 2 */ - "density", /* 3 */ - "units", /* 4 */ - "redox", /* 5 */ - "ph", /* 6 */ - "pe", /* 7 */ - "unit", /* 8 */ - "isotope", /* 9 */ - "water", /* 10 */ - "description", /* 11 */ - "desc", /* 12 */ - "descriptor" /* 13 */ - - }; - int count_opt_list = 14; - -/* - * look for solution number - */ - n_user = -1; - n_user_end = -1; - description = string_duplicate(""); - for (i = 0; i < heading->count; i++) { - if (strcmp_nocase(heading->char_vector[i], "number") == 0) { - break; - } - } - if (i == heading->count || data->type_vector[i] == EMPTY || data->count <= i) { - n_user = -1; -#ifdef SKIP - for (i = 0; i < count_solution; i++) { - if (n_user <= solution[i]->n_user) { - n_user = solution[i]->n_user + 1; - } - } -#endif - } else if (data->type_vector[i] == STRING) { - input_error++; - sprintf(error_string,"Expected solution number or number range in 'number' column, found: %s.", data->char_vector[i]); - error_msg(error_string, CONTINUE); - } else { - strcpy(string, "solution_s "); - strcat(string, data->char_vector[i]); - ptr = string; - description = (char *) free_check_null(description); - next_keyword_save = next_keyword; - next_keyword = 42; - read_number_description (ptr, &n_user, &n_user_end, &description); - next_keyword = next_keyword_save; - } -/* - * set up solution - */ - - if (n_user >= 0 && solution_bsearch(n_user, &n, FALSE) != NULL) { - solution_free(solution[n]); - } else { - n=count_solution++; - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); - } - } - solution[n] = solution_alloc(); - - solution[n]->n_user = n_user; - solution[n]->n_user_end = n_user_end; - if (use.solution_in == FALSE) { - use.solution_in = TRUE; - use.n_solution_user = n_user; - } - max_mass_balance=MAX_MASS_BALANCE; -/* - * Set default ph, temp, density, pe, units - */ - solution[n]->description = description; - solution[n]->tc=defaults.temp; - solution[n]->ph=defaults.ph; - solution[n]->density=defaults.density; - solution[n]->solution_pe = defaults.pe; - solution[n]->mass_water=defaults.water; - solution[n]->ah2o = 1.0; - solution[n]->mu = 1e-7; - solution[n]->cb = 0.0; - default_pe = 0; - solution[n]->units = defaults.units; - solution[n]->totals[0].description=NULL; - count_mass_balance=0; - count_isotopes = 0; - default_pe = pe_data_store (&(solution[n]->pe), defaults.redox); -/* - * Read concentration data - */ - return_value = UNKNOWN; - for (i = 0; i < heading->count; i++) { - if (strcmp_nocase(heading->char_vector[i], "number") == 0) continue; - if (strcmp_nocase(heading->char_vector[i], "uncertainty") == 0) continue; - if (strcmp_nocase(heading->char_vector[i], "uncertainties") == 0) continue; - if (strcmp_nocase(heading->char_vector[i], "isotope_uncertainty") == 0) continue; - /* - * Copy in element name - */ - if (heading->type_vector[i] == EMPTY) continue; - strcpy(string, heading->char_vector[i]); - strcat(string, " "); - /* - * Copy in concentration data - */ - if (i >= data->count || data->type_vector[i] == EMPTY) continue; - strcat(string, data->char_vector[i]); - strcat(string, " "); - /* - * Copy in concentration data - */ - if (units != NULL && i < units->count && units->type_vector[i] != EMPTY) { - strcat(string, units->char_vector[i]); - } -/* - * Parse string just like read_solution input - */ - next_char = string; - opt = get_option_string(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT && heading->type_vector[i] == NUMBER) { - opt = 9; - } - switch (opt) { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLUTION keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* temperature */ - case 1: - sscanf(next_char,SCANFORMAT, &(solution[n]->tc)); - break; - case 2: /* density */ - case 3: - sscanf(next_char,SCANFORMAT, &(solution[n]->density)); - break; - case 4: /* units */ - case 8: /* unit */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (check_units (token, FALSE, FALSE, solution[n]->units, TRUE) == OK) { - solution[n]->units = string_hsave(token); - } else { - input_error++; - } - break; - case 5: /* redox */ - if (copy_token (token, &next_char, &l) == EMPTY) break; - if (parse_couple(token) == OK) { - default_pe = pe_data_store (&(solution[n]->pe), token); - } else { - input_error++; - } - break; - case 6: /* ph */ - next_char = string; - if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { - input_error++; - break; - } - solution[n]->ph = solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { - break; - } - solution[n]->totals[count_mass_balance].description = string_hsave("H(1)"); - count_mass_balance++; - break; - case 7: /* pe */ - next_char = string; - if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { - input_error++; - break; - } - solution[n]->solution_pe = solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL ) { - break; - } - solution[n]->totals[count_mass_balance].description = string_hsave("E"); - count_mass_balance++; - break; - case 9: /* isotope */ - next_char = string; - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - solution[n]->isotopes = (struct isotope *) PHRQ_realloc(solution[n]->isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); - if (solution[n]->isotopes == NULL) malloc_error(); - /* read and save element name */ - ptr1 = token; - get_num(&ptr1, &(solution[n]->isotopes[count_isotopes].isotope_number)); - if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return(ERROR); - } - solution[n]->isotopes[count_isotopes].elt_name = string_hsave(ptr1); - - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, &(solution[n]->isotopes[count_isotopes].ratio)); - - /* read and store isotope ratio uncertainty */ - /* first choice is next column */ - if ((i + 1) < heading->count && - (strcmp_nocase(heading->char_vector[i+1], "uncertainty") == 0 || - strcmp_nocase(heading->char_vector[i+1], "isotope_uncertainty") == 0 || - strcmp_nocase(heading->char_vector[i+1], "uncertainties") == 0) && - (i + 1) < data->count && - data->type_vector[i+1] == NUMBER) { - solution[n]->isotopes[count_isotopes].ratio_uncertainty = data->d_vector[i+1]; - } else { - next_char = string; - copy_token (token, &next_char, &l); - for (j = 0; j < defaults.count_iso; j++) { - if (strcmp(token, defaults.iso[j].name) == 0) { - solution[n]->isotopes[count_isotopes].ratio_uncertainty = defaults.iso[j].uncertainty; - break; - } - } - if (j == defaults.count_iso) { - solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; - } - } - count_isotopes++; - break; - case 10: /* water */ - j = copy_token (token, &next_char, &l); - if (j == EMPTY) { - solution[n]->mass_water=1.0; - } else if (j != DIGIT) { - input_error++; - sprintf(error_string, "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } else { - sscanf(token, SCANFORMAT, &dummy); - solution[n]->mass_water = (LDBLE) dummy; - } - break; - case 11: /* description */ - case 12: /* desc */ - case 13: /* descriptor */ - solution[n]->description = (char *) free_check_null(solution[n]->description); - solution[n]->description = string_duplicate(next_char); - break; - case OPTION_DEFAULT: -/* - * Read concentration - */ - next_char = string; - if (copy_token (token, &next_char, &l) == LOWER) continue; - next_char = string; - if ( read_conc(n, count_mass_balance, next_char) == ERROR ) { -#ifdef SKIP - input_error++; - break; -#endif - } - count_mass_balance++; - break; - } - if (count_mass_balance + 1 >= max_mass_balance) { - space ((void **) &(solution[n]->totals), count_mass_balance + 1, - &max_mass_balance, sizeof (struct conc)); - } - if (return_value == EOF || return_value == KEYWORD) break; - } -/* - * Sort totals by description - */ - qsort (solution[n]->totals, - (size_t) count_mass_balance, - (size_t) sizeof(struct conc), - conc_compare); -/* - * fix up default units and default pe - */ - for (i=0; i < count_mass_balance; i++) { - strcpy(token, solution[n]->totals[i].description); - str_tolower(token); - if (solution[n]->totals[i].units == NULL) { - solution[n]->totals[i].units = solution[n]->units; - } else { - alk = FALSE; - if (strstr(token, "alk") == token) alk = TRUE; - strcpy(token1, solution[n]->totals[i].units); - if (check_units (token1, alk, TRUE, solution[n]->units, TRUE) == ERROR ) { - input_error++; - } else { - solution[n]->totals[i].units = string_hsave(token1); - } - } - if (solution[n]->totals[i].n_pe < 0) { - solution[n]->totals[i].n_pe = default_pe; - } - } - solution[n]->default_pe = default_pe; -/* - * Mark end of solution - */ - solution[n]->totals[count_mass_balance].description = NULL; - solution[n]->count_isotopes = count_isotopes; - if (count_isotopes > 0) { - qsort (solution[n]->isotopes, - (size_t) count_isotopes, - (size_t) sizeof(struct isotope), - isotope_compare); - } else { - solution[n]->isotopes = (struct isotope *) free_check_null(solution[n]->isotopes); - } - return(return_value); -} - -/* ---------------------------------------------------------------------- */ -struct spread_row *string_to_spread_row(char *string) -/* ---------------------------------------------------------------------- */ -{ - int j, l; - int length = 10; - char token[MAX_LENGTH]; - char *ptr; - struct spread_row *spread_row_ptr; -/* - * Allocate space - */ - spread_row_ptr = (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); - if (spread_row_ptr == NULL) malloc_error(); - spread_row_ptr->char_vector = (char **) PHRQ_malloc((size_t) length * sizeof(char *)); - if (spread_row_ptr->char_vector == NULL) malloc_error(); - spread_row_ptr->d_vector = (LDBLE *) PHRQ_malloc((size_t) length * sizeof(LDBLE)); - if (spread_row_ptr->d_vector == NULL) malloc_error(); - spread_row_ptr->type_vector = (int *) PHRQ_malloc((size_t) length * sizeof(int)); - if (spread_row_ptr->type_vector == NULL) malloc_error(); - spread_row_ptr->count = 0; - spread_row_ptr->empty = 0; - spread_row_ptr->string = 0; - spread_row_ptr->number = 0; - ptr = string; -/* - * Split by tabs, reallocate space - */ - for (;;) { - if (spread_row_ptr->count + 1 > length) { - length *= 2; - - spread_row_ptr->char_vector = (char **) PHRQ_realloc(spread_row_ptr->char_vector, (size_t) length * sizeof(char *)); - if (spread_row_ptr->char_vector == NULL) malloc_error(); - - spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, (size_t) length * sizeof(LDBLE)); - if (spread_row_ptr->d_vector == NULL) malloc_error(); - - spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, (size_t) length * sizeof(int)); - if (spread_row_ptr->type_vector == NULL) malloc_error(); - } - j = copy_token_tab(token, &ptr, &l); - if (j == EOL) break; - spread_row_ptr->char_vector[spread_row_ptr->count] = string_duplicate(token); - spread_row_ptr->d_vector[spread_row_ptr->count] = NAN; - if (j == EMPTY || l == 0) { - spread_row_ptr->empty++; - spread_row_ptr->type_vector[spread_row_ptr->count] = EMPTY; - } else if (j == UPPER || j == LOWER) { - spread_row_ptr->string++; - spread_row_ptr->type_vector[spread_row_ptr->count] = STRING; - } else if (j == DIGIT) { - spread_row_ptr->number++; - spread_row_ptr->d_vector[spread_row_ptr->count] = strtod(token, NULL); - spread_row_ptr->type_vector[spread_row_ptr->count] = NUMBER; - } - spread_row_ptr->count++; - } -/* - * Clean up and return - */ - if (spread_row_ptr->count == 0) { - spread_row_ptr->char_vector = (char **) free_check_null(spread_row_ptr->char_vector); - spread_row_ptr->d_vector = (LDBLE *) free_check_null(spread_row_ptr->d_vector); - spread_row_ptr->type_vector = (int *) free_check_null(spread_row_ptr->type_vector); - } else { - spread_row_ptr->char_vector = (char **) PHRQ_realloc(spread_row_ptr->char_vector, (size_t) spread_row_ptr->count * sizeof(char *)); - if (spread_row_ptr->char_vector == NULL) malloc_error(); - spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, (size_t) spread_row_ptr->count * sizeof(LDBLE)); - if (spread_row_ptr->d_vector == NULL) malloc_error(); - spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, (size_t) spread_row_ptr->count * sizeof(int)); - if (spread_row_ptr->type_vector == NULL) malloc_error(); - - } - return (spread_row_ptr); -} -/* ---------------------------------------------------------------------- */ -int spread_row_free(struct spread_row *spread_row_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; - - if (spread_row_ptr == NULL) return(OK); - for (i = 0; i< spread_row_ptr->count; i++) { - spread_row_ptr->char_vector[i] = (char *) free_check_null(spread_row_ptr->char_vector[i]); - } - - spread_row_ptr->char_vector = (char **) free_check_null(spread_row_ptr->char_vector); - spread_row_ptr->d_vector = (double *) free_check_null(spread_row_ptr->d_vector); - spread_row_ptr->type_vector = (int *) free_check_null(spread_row_ptr->type_vector); - spread_row_ptr = (struct spread_row *) free_check_null(spread_row_ptr); - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int copy_token_tab(char *token_ptr, char **ptr, int *length) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies from **ptr to *token_ptr until first tab is encountered. - * - * Arguments: - * *token_ptr output, place to store token - * - * **ptr input, character string to read token from - * output, next position after token - * - * length output, length of token - * - * Returns: - * UPPER, - * LOWER, - * DIGIT, - * EMPTY, - * EOL, - * UNKNOWN. - */ - int i, j, return_value; - char c; -/* - * Strip leading spaces - */ - while ( (c=**ptr) == ' ' ) (*ptr)++; -/* - * Check what we have - */ - if ( isupper((int) c) ) { - return_value=UPPER; - } else if ( islower((int) c) ) { - return_value=LOWER; - } else if ( isdigit((int) c) || c=='.' || c=='-') { - return_value=DIGIT; - } else if ( c == '\0') { - return_value=EOL; - return(return_value); - } else if ( c == '\t') { - return_value=EMPTY; - } else { - return_value=UNKNOWN; - } -/* - * Begin copying to token - */ - i=0; -#ifdef SKIP - while ( (c=**ptr) != '\t' && - c != '\0' ) { - token_ptr[i]=c; - (*ptr)++; - i++; - } -#endif - for (;;) { - c=**ptr; - if (c == '\t') { - (*ptr)++; - break; - } else if (c =='\0') { - break; - } else { - token_ptr[i]=c; - (*ptr)++; - i++; - } - } - token_ptr[i]='\0'; - *length=i; -/* - * Strip trailing spaces - */ - for (j = i-1; j >= 0; j--) { - if (j != ' ') break; - } - if (j != i-1) { - token_ptr[j+1]='\0'; - *length=j+1; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -static int get_option_string (const char **opt_list, int count_opt_list, char **next_char) -/* ---------------------------------------------------------------------- */ -{ -/* - * Read a line and check for options - */ - int j; - int opt_l, opt; - char *opt_ptr; - char option[MAX_LENGTH]; - - opt_ptr = *next_char; - if (opt_ptr[0] == '-') { - opt_ptr++; - copy_token(option, &opt_ptr, &opt_l); - if (find_option(&(option[1]), &opt, opt_list, count_opt_list, FALSE) == OK) { - j = opt; - *next_char = opt_ptr; - } else { - error_msg("Unknown option.", CONTINUE); - error_msg(*next_char, CONTINUE); - input_error++; - j = OPTION_ERROR; - } - } else { - copy_token(option, &opt_ptr, &opt_l); - if (find_option(&(option[0]), &opt, opt_list, count_opt_list, TRUE) == OK) { - j = opt; - *next_char = opt_ptr; - } else { - j = OPTION_DEFAULT; - } - } - return (j); -} -#ifdef PHREEQCI_GUI -/* ---------------------------------------------------------------------- */ -void free_spread(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - spread_row_free(g_spread_sheet.heading); - spread_row_free(g_spread_sheet.units); - for (i = 0; i < g_spread_sheet.count_rows; i++) - { - spread_row_free(g_spread_sheet.rows[i]); - } - g_spread_sheet.rows = free_check_null(g_spread_sheet.rows); - - for (i = 0; i < g_spread_sheet.defaults.count_iso; i++) - { - g_spread_sheet.defaults.iso[i].name = free_check_null(g_spread_sheet.defaults.iso[i].name); - } - g_spread_sheet.defaults.iso = free_check_null(g_spread_sheet.defaults.iso); - - g_spread_sheet.defaults.redox = free_check_null(g_spread_sheet.defaults.redox); - g_spread_sheet.defaults.units = free_check_null(g_spread_sheet.defaults.units); -} -/* ---------------------------------------------------------------------- */ -void add_row(struct spread_row *spread_row_ptr) -/* ---------------------------------------------------------------------- */ -{ - g_spread_sheet.rows = (struct spread_row **) PHRQ_realloc(g_spread_sheet.rows, sizeof(struct spread_row*) * (g_spread_sheet.count_rows + 1)); - if (g_spread_sheet.rows == NULL) - { - malloc_error(); - } - else - { - g_spread_sheet.rows[g_spread_sheet.count_rows++] = copy_row(spread_row_ptr); - } -} -/* ---------------------------------------------------------------------- */ -struct spread_row *copy_row(struct spread_row *spread_row_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct spread_row *new_spread_row_ptr; -/* - * Allocate space - */ - new_spread_row_ptr = (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); - if (new_spread_row_ptr == NULL) malloc_error(); - new_spread_row_ptr->char_vector = (char **) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(char *)); - if (new_spread_row_ptr->char_vector == NULL) malloc_error(); - new_spread_row_ptr->d_vector = (LDBLE *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(LDBLE)); - if (new_spread_row_ptr->d_vector == NULL) malloc_error(); - new_spread_row_ptr->type_vector = (int *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(int)); - if (new_spread_row_ptr->type_vector == NULL) malloc_error(); - - for (i = 0; i < spread_row_ptr->count; i++) - { - new_spread_row_ptr->char_vector[i] = string_duplicate(spread_row_ptr->char_vector[i]); - new_spread_row_ptr->d_vector[i] = spread_row_ptr->d_vector[i]; - new_spread_row_ptr->type_vector[i] = spread_row_ptr->type_vector[i]; - } - new_spread_row_ptr->count = spread_row_ptr->count; - new_spread_row_ptr->empty = spread_row_ptr->empty; - new_spread_row_ptr->number = spread_row_ptr->number; - new_spread_row_ptr->string = spread_row_ptr->string; - - return new_spread_row_ptr; -} -/* ---------------------------------------------------------------------- */ -void copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; - dest_ptr->count_iso = src_ptr->count_iso; - dest_ptr->density = src_ptr->density; - dest_ptr->iso = (struct iso*)PHRQ_malloc(sizeof(struct iso) * src_ptr->count_iso); - if (dest_ptr->iso == NULL) - { - malloc_error(); - } - else - { - for (i = 0; i < src_ptr->count_iso; i++) - { - dest_ptr->iso[i] = src_ptr->iso[i]; - dest_ptr->iso[i].name = string_duplicate(src_ptr->iso[i].name); - } - } - - dest_ptr->pe = src_ptr->pe; - dest_ptr->ph = src_ptr->ph; - dest_ptr->redox = string_duplicate(src_ptr->redox); - dest_ptr->temp = src_ptr->temp; - dest_ptr->units = string_duplicate(src_ptr->units); - dest_ptr->water = src_ptr->water; -} - -#endif diff --git a/step.cpp b/step.cpp deleted file mode 100644 index 1f60ae1d..00000000 --- a/step.cpp +++ /dev/null @@ -1,1028 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: step.c 406 2005-07-27 15:39:12Z dlpark $"; - -static int check_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr); -static int gas_phase_check (struct gas_phase *gas_phase_ptr); -static int pp_assemblage_check (struct pp_assemblage *pp_assemblage_ptr); -static int reaction_calc(struct irrev *irrev_ptr); -static int solution_check (void); -static int s_s_assemblage_check (struct s_s_assemblage *s_s_assemblage_ptr); - -/* ---------------------------------------------------------------------- */ -int step(LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * zero global solution, add solution or mixture, add exchange, - * add surface, add gas phase, add solid solutions, - * set temperature, and add reaction. - * Ensure all elements - * included in any of these are present in small amounts. - * Save result as n_user -1. - */ - LDBLE difftemp; - int step_number; - struct pp_assemblage *pp_assemblage_save = NULL; - struct s_s_assemblage *s_s_assemblage_save = NULL; - - if (svnid == NULL) fprintf(stderr," "); - -/* - * Zero out global solution data - */ - - xsolution_zero(); -/* - * Set reaction to zero - */ - step_x = 0.0; - step_number = reaction_step; -/* - * Mixing or solution - */ - if (use.mix_ptr != NULL) { - add_mix(use.mix_ptr); - } else if ( use.solution_ptr != NULL ) { - add_solution(use.solution_ptr, 1.0, 1.0); - } else { - input_error++; - error_msg("Neither mixing nor an initial solution have " - "been defined in reaction step.", STOP); - } -/* - * Reaction - */ - if(use.irrev_ptr != NULL) { - add_reaction(use.irrev_ptr, step_number, step_fraction); - } -/* - * Kinetics - */ - if(use.kinetics_ptr != NULL) { - add_kinetics(use.kinetics_ptr); - /* - master_ptr =master_bsearch("S(6)"); - output_msg(OUTPUT_MESSAGE,"Added kinetics, S(6) %e\n", master_ptr->total); - master_ptr =master_bsearch("S"); - output_msg(OUTPUT_MESSAGE,"Added kinetics, S %e\n", master_ptr->total); - */ - } -/* - * Exchange - */ - if (use.exchange_ptr != NULL) { - add_exchange(use.exchange_ptr); - } -/* - * Surface - */ - if (use.surface_ptr != NULL) { - add_surface(use.surface_ptr); - } -/* - * Gases - */ - if(use.gas_phase_ptr != NULL) { - add_gas_phase(use.gas_phase_ptr); - } -/* - * Temperature - */ - if(use.temperature_ptr != NULL) { - add_temperature(use.temperature_ptr, step_number); - } - if ((state == TRANSPORT) && (transport_step != 0) && - (cell > 0) && (cell != count_cells+1)) { - difftemp = tc_x - cell_data[cell-1].temp; - cell_data[cell-1].temp += difftemp/tempr; - tc_x = cell_data[cell-1].temp; - } -/* - * Pure phases and solid solutions are added to avoid - * zero or negative concentrations - */ -/* - * Pure phases - */ - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_save = (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_save == NULL) malloc_error(); - pp_assemblage_copy(use.pp_assemblage_ptr, pp_assemblage_save, use.pp_assemblage_ptr->n_user); - add_pp_assemblage (use.pp_assemblage_ptr); - } -/* - * Solid solutions - */ - if(use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_save = (struct s_s_assemblage *) PHRQ_malloc(sizeof(struct s_s_assemblage)); - if (s_s_assemblage_save == NULL) malloc_error(); - s_s_assemblage_copy(use.s_s_assemblage_ptr, s_s_assemblage_save, use.s_s_assemblage_ptr->n_user); - add_s_s_assemblage(use.s_s_assemblage_ptr); - } -/* - * Check that elements are available for gas components, - * pure phases, and solid solutions - */ - if(use.gas_phase_ptr != NULL) { - gas_phase_check(use.gas_phase_ptr); - } - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_check (use.pp_assemblage_ptr); - } - if(use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_check(use.s_s_assemblage_ptr); - } -/* - * Check that element moles are >= zero - */ - if (solution_check() == MASS_BALANCE) { - /* reset moles and deltas */ - if (use.pp_assemblage_ptr != NULL) { - pp_assemblage_free(use.pp_assemblage_ptr); - pp_assemblage_copy(pp_assemblage_save, use.pp_assemblage_ptr, use.pp_assemblage_ptr->n_user); - pp_assemblage_free(pp_assemblage_save); - pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); - } - if (use.s_s_assemblage_ptr != NULL) { - s_s_assemblage_free(use.s_s_assemblage_ptr); - s_s_assemblage_copy(s_s_assemblage_save, use.s_s_assemblage_ptr, use.s_s_assemblage_ptr->n_user); - s_s_assemblage_free(s_s_assemblage_save); - s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); - } - return(MASS_BALANCE); - } -/* - * Copy global into solution n_user = -1 - */ - xsolution_save(-1); - step_save_surf(-1); - step_save_exch(-1); -/* - * Clean up temporary space - */ - if (pp_assemblage_save != NULL) { - pp_assemblage_free(pp_assemblage_save); - pp_assemblage_save = (struct pp_assemblage *) free_check_null(pp_assemblage_save); - } - if (s_s_assemblage_save != NULL) { - s_s_assemblage_free(s_s_assemblage_save); - s_s_assemblage_save = (struct s_s_assemblage *) free_check_null(s_s_assemblage_save); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int xsolution_zero (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Zero out _x variables, master->totals, and species->la - */ - int i; -/* - * Zero totals in master structures - */ - new_x = FALSE; - - tc_x = 0.0; - ph_x = 0.0; - solution_pe_x = 0.0; - mu_x = 0.0; - ah2o_x = 0.0; - density_x = 0.0; - total_h_x = 0.0; - total_o_x = 0.0; - cb_x = 0.0; - mass_water_aq_x = 0.0; - units_x = moles_per_kilogram_string; - - for (i=0; i < count_master; i++) { - master[i]->total = 0.0; - master[i]->total_primary = 0.0; - master[i]->s->la = 0.0; - } - if (pitzer_model == TRUE) { - for (i=0; i < count_s; i++) { - s[i]->lg = 0.0; - } - } -/* - * Copy pe data (not sure this will be used - */ -/* - pe_data_free (pe_x); - pe_x = pe_data_alloc(); - */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_solution (struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate solution data in master->totals and _x variables. - * - * extensive is multiplication factor for solution - * intensive is fraction of all multiplication factors for all solutions - */ - int i; - struct master *master_ptr; - struct species *species_ptr; -/* - * Add solution to global variables - */ - tc_x += solution_ptr->tc * intensive; - ph_x += solution_ptr->ph * intensive; - solution_pe_x += solution_ptr->solution_pe * intensive; - mu_x += solution_ptr->mu * intensive; - ah2o_x += solution_ptr->ah2o * intensive; - density_x += solution_ptr->density * intensive; - - total_h_x += solution_ptr->total_h * extensive; - total_o_x += solution_ptr->total_o * extensive; - cb_x += solution_ptr->cb * extensive; - mass_water_aq_x += solution_ptr->mass_water * extensive; -/* - * Copy totals data into primary master species - */ - for (i=0; solution_ptr->totals[i].description != NULL; i++) { - master_ptr = master_bsearch_primary(solution_ptr->totals[i].description); - master_ptr->total += solution_ptr->totals[i].moles * extensive; - } -/* - * Accumulate initial guesses for activities - */ - /*for (i=0; solution_ptr->master_activity[i].description != NULL; i++) {*/ - for (i=0; i < solution_ptr->count_master_activity; i++) { - if (solution_ptr->master_activity[i].description != NULL) { - master_ptr = master_bsearch(solution_ptr->master_activity[i].description); - if (master_ptr != NULL) { - master_ptr->s->la += solution_ptr->master_activity[i].la * intensive; - } - } - } -/* - * Accumulate initial guesses for log gamma - */ - if (pitzer_model == TRUE) { - for (i=0; i < solution_ptr->count_species_gamma ; i++) { - species_ptr = s_search(solution_ptr->species_gamma[i].description); - if (species_ptr != NULL) { - species_ptr->lg += solution_ptr->species_gamma[i].la * intensive; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_exchange (struct exchange *exchange_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate exchange data in master->totals and _x variables. - */ - int i, j; - struct master *master_ptr; - - if (exchange_ptr == NULL) return(OK); -/* - * Add element concentrations on exchanger to master species totals - */ - for (i = 0; i < exchange_ptr->count_comps; i++) { - for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) { - master_ptr = exchange_ptr->comps[i].totals[j].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += exchange_ptr->comps[i].totals[j].coef; - } else if (master_ptr->s == s_h2o) { - total_o_x += exchange_ptr->comps[i].totals[j].coef; - } else { - master_ptr->total += exchange_ptr->comps[i].totals[j].coef; - } - } - } - if (exchange_ptr->new_def == TRUE) { - for (i = 0; i < count_master; i++) { - if (master[i]->type == EX && master[i]->total > 0) { - master[i]->s->la = log10(0.1 * master[i]->total); - } - } - } else { - for (i = 0; i < exchange_ptr->count_comps; i++) { - exchange_ptr->comps[i].master->s->la = exchange_ptr->comps[i].la; - cb_x += exchange_ptr->comps[i].charge_balance; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_surface (struct surface *surface_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate surface data in master->totals and _x variables. - */ - int i, j; - struct master *master_ptr; - - if (surface_ptr == NULL) return(OK); -/* - * Add element concentrations on surface to master species totals - */ - diffuse_layer_x = surface_ptr->diffuse_layer; - for (i = 0; i < surface_ptr->count_comps; i++) { - if(surface_ptr->edl == FALSE) { - cb_x += surface_ptr->comps[i].cb; - } - if (surface_ptr->new_def == FALSE) { - surface_ptr->comps[i].master->s->la = surface_ptr->comps[i].la; - } -/* - * Add surface and specifically sorbed elements - */ - for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) { - master_ptr = surface_ptr->comps[i].totals[j].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += surface_ptr->comps[i].totals[j].coef; - } else if (master_ptr->s == s_h2o) { - total_o_x += surface_ptr->comps[i].totals[j].coef; - } else { - master_ptr->total += surface_ptr->comps[i].totals[j].coef; - } - } - } - if (surface_ptr->edl == FALSE) return(OK); - for (i = 0; i < surface_ptr->count_charge; i++) { - if (surface_ptr->edl == TRUE) { - cb_x += surface_ptr->charge[i].charge_balance; - } - if (surface_ptr->new_def == FALSE) { - surface_ptr->charge[i].psi_master->s->la = surface_ptr->charge[i].la_psi; - } -/* - * Add diffuse layer elements (including water in Debye layer) - */ - if (surface_ptr->diffuse_layer == TRUE && surface_ptr->new_def == FALSE) { - for (j = 0; surface_ptr->charge[i].diffuse_layer_totals[j].elt != NULL; j++) { - master_ptr = surface_ptr->charge[i].diffuse_layer_totals[j].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += surface_ptr->charge[i].diffuse_layer_totals[j].coef; - } else if (master_ptr->s == s_h2o) { - total_o_x += surface_ptr->charge[i].diffuse_layer_totals[j].coef; - } else { - master_ptr->total += surface_ptr->charge[i].diffuse_layer_totals[j].coef; - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_mix (struct mix *mix_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * calls add_solution to accumulate all data in master->totals - * and other variables. - */ - int i; - int n; - LDBLE sum_fractions, intensive, extensive; - struct solution *solution_ptr; - int count_positive; - LDBLE sum_positive; - - if (mix_ptr == NULL) return(OK); - if (mix_ptr->count_comps <= 0) return(OK); - sum_fractions = 0.0; - sum_positive = 0.0; - count_positive = 0; - for (i = 0; i < mix_ptr->count_comps; i++) { - sum_fractions += mix_ptr->comps[i].fraction; - if (mix_ptr->comps[i].fraction > 0) { - sum_positive += mix_ptr->comps[i].fraction; - count_positive++; - } - } - for (i = 0; i < mix_ptr->count_comps; i++) { - solution_ptr = solution_bsearch (mix_ptr->comps[i].n_solution, &n, TRUE); - if (solution_ptr == NULL) { - input_error++; - continue; - } - extensive = mix_ptr->comps[i].fraction; - intensive = extensive / sum_fractions; - if (count_positive < mix_ptr->count_comps) { - if (mix_ptr->comps[i].fraction > 0) { - intensive = extensive / sum_positive; - } else { - intensive = 0; - } - } - add_solution(solution_ptr, extensive, intensive); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add a small amount of each phase if necessary to insure - * all elements exist in solution. - */ - int i, j; - LDBLE amount_to_add, total; - char token[MAX_LENGTH]; - char *ptr; - struct pure_phase *pure_phase_ptr; - struct master *master_ptr; - - if (check_pp_assemblage(pp_assemblage_ptr) == OK) return(OK); -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - count_elts = 0; - paren_count = 0; -/* - * Check that all elements are in solution for phases with greater than zero mass - */ - pure_phase_ptr = pp_assemblage_ptr->pure_phases; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { - count_elts = 0; - paren_count = 0; - amount_to_add = 0.0; - pure_phase_ptr[j].delta = 0.0; - if (pure_phase_ptr[j].add_formula != NULL) { - strcpy(token, pure_phase_ptr[j].add_formula); - ptr = &(token[0]); - get_elts_in_species (&ptr, 1.0); - } else { - strcpy(token, pure_phase_ptr[j].phase->formula); - add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); - } - if (pure_phase_ptr[j].moles > 0.0) { - for (i = 0; i < count_elts; i++) { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } else if (master_ptr->total > MIN_TOTAL) { - continue; - } else { - total = (-master_ptr->total + 1e-10) / elt_list[i].coef; - if (amount_to_add < total) { - amount_to_add = total; - } - } - } - if (pure_phase_ptr[j].moles < amount_to_add) { - amount_to_add = pure_phase_ptr[j].moles; - } - } - if (amount_to_add > 0.0) { - pure_phase_ptr[j].moles -= amount_to_add; - pure_phase_ptr[j].delta = amount_to_add; -/* - * Add reaction to totals - */ - for (i = 0; i < count_elts; i++) { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += elt_list[i].coef * amount_to_add; - } else if (master_ptr->s == s_h2o) { - total_o_x += elt_list[i].coef * amount_to_add; - } else { - master_ptr->total += elt_list[i].coef * amount_to_add; - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int check_pp_assemblage (struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check list of all elements in pure_phase assemblage to see - * if all are in model. Return true if all are present, - * Return false if one or more is missing. - */ - int j; - struct master *master_ptr; - for (j = 0; pp_assemblage_ptr->next_elt[j].elt != NULL; j++) { - master_ptr = pp_assemblage_ptr->next_elt[j].elt->primary; - if (master_ptr->s == s_h2o || master_ptr->s == s_hplus) continue; - if (master_ptr->total > MIN_TOTAL) continue; - return(FALSE); - } - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int add_reaction (struct irrev *irrev_ptr, int step_number, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add irreversible reaction - */ - int i; - char c; - struct master *master_ptr; -/* - * Calculate and save reaction - */ -/* !!!!! with kinetics reaction, coeff's may change - * and reaction_calc must be called .... - */ - if (irrev_ptr->elts == NULL ) { - if (reaction_calc(irrev_ptr) == ERROR) { - return(ERROR); - } - } -/* - * Step size - */ - if (incremental_reactions == FALSE) { - if (irrev_ptr->count_steps > 0) { - if (step_number > irrev_ptr->count_steps) { - step_x = irrev_ptr->steps[irrev_ptr->count_steps - 1]; - } else { - step_x = irrev_ptr->steps[step_number - 1]; - } - } else if (irrev_ptr->count_steps < 0) { - if (step_number > -irrev_ptr->count_steps) { - step_x = irrev_ptr->steps[0]; - } else { - step_x = irrev_ptr->steps[0] * - ( (LDBLE) step_number ) / ( (LDBLE) (-irrev_ptr->count_steps)); - } - } else { - step_x = 0.0; - } - } else { - /* Incremental reactions */ - if (irrev_ptr->count_steps > 0) { - if (step_number > irrev_ptr->count_steps) { - step_x = irrev_ptr->steps[irrev_ptr->count_steps - 1]; - } else { - step_x = irrev_ptr->steps[step_number - 1]; - } - } else if (irrev_ptr->count_steps < 0) { - if (step_number > -irrev_ptr->count_steps) { - step_x = 0; - } else { - step_x = irrev_ptr->steps[0] / ( (LDBLE) (-irrev_ptr->count_steps)); - } - } else { - step_x = 0.0; - } - } -/* - * Convert units - */ - c = irrev_ptr->units[0]; - if (c == 'm') { - step_x *= 1e-3; - } else if (c == 'u') { - step_x *= 1e-6; - } else if (c == 'n') { - step_x *= 1e-9; - } -/* - * Add reaction to totals - */ - for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) { - master_ptr = irrev_ptr->elts[i].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += irrev_ptr->elts[i].coef * step_x * step_fraction; - } else if (master_ptr->s == s_h2o) { - total_o_x += irrev_ptr->elts[i].coef * step_x * step_fraction; - } else { - master_ptr->total += irrev_ptr->elts[i].coef * step_x * step_fraction; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int reaction_calc(struct irrev *irrev_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through irreversible reaction initially to - * determine a list of elements and amounts in - * the reaction. - */ - int i, j, return_value; - LDBLE coef; - char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - return_value = OK; - count_elts = 0; - paren_count = 0; - - for (i=0; i < irrev_ptr->count_list; i++) { - coef = irrev_ptr->list[i].coef; - strcpy(token, irrev_ptr->list[i].name); - phase_ptr = phase_bsearch(token, &j, FALSE); -/* - * Reactant is a pure phase, copy formula into token - */ - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, coef); - } else { - ptr = &(token[0]); - get_elts_in_species (&ptr, coef); - } - } -/* - * Check that all elements are in database - */ - for (i = 0; i < count_elts; i++) { - if (elt_list[i].elt->master == NULL) { - sprintf(error_string, "Element or phase not defined in database, %s.", elt_list[i].elt->name); - error_msg(error_string, CONTINUE); - input_error++; - return_value = ERROR; - } - } - irrev_ptr->elts = elt_list_save(); - - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int add_temperature (struct temperature *temperature_ptr, int step_number) -/* ---------------------------------------------------------------------- */ -{ -/* - * Determine temperature of reaction step, if reaction_temperature - * information is present. - */ - int denom; - LDBLE tc_temp; -/* - * Find temperature - */ - if (temperature_ptr == NULL) return(ERROR); - if (temperature_ptr->count_t > 0) { - if (step_number > temperature_ptr->count_t) { - tc_temp = temperature_ptr->t[temperature_ptr->count_t - 1]; - } else { - tc_temp = temperature_ptr->t[step_number - 1]; - } - } else if (temperature_ptr->count_t < 0) { - if (step_number > -temperature_ptr->count_t) { - tc_temp = temperature_ptr->t[1]; - } else { - if (-temperature_ptr->count_t <= 1) { - denom = 1; - } else { - denom = -temperature_ptr->count_t - 1; - } - tc_temp = temperature_ptr->t[0] + (temperature_ptr->t[1] - temperature_ptr->t[0]) * - ( (LDBLE) (step_number - 1) ) / ( (LDBLE) denom ); - } - } else { - tc_temp = 25.0; - } - tc_x = tc_temp; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_gas_phase (struct gas_phase *gas_phase_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate gas data in master->totals and _x variables. - */ - int i; - - struct gas_comp *gas_comp_ptr; - struct master *master_ptr; - - if (gas_phase_ptr == NULL) return(OK); - gas_comp_ptr = gas_phase_ptr->comps; -/* - * calculate reaction - */ - count_elts = 0; - paren_count = 0; - for (i = 0; i < gas_phase_ptr->count_comps; i++) { - add_elt_list(gas_comp_ptr[i].phase->next_elt, gas_comp_ptr[i].moles); - } -/* - * Sort elements in reaction and combine - */ - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } -/* - * Add gas elements to totals - */ - for (i = 0; i < count_elts; i++) { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += elt_list[i].coef; - } else if (master_ptr->s == s_h2o) { - total_o_x += elt_list[i].coef; - } else { - master_ptr->total += elt_list[i].coef; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_s_s_assemblage (struct s_s_assemblage *s_s_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate solid_solution data in master->totals and _x variables. - */ - int i, j, k; - LDBLE amount_to_add, total; - struct s_s *s_s_ptr; - struct master *master_ptr; - char token[MAX_LENGTH]; - char *ptr; - - if (s_s_assemblage_ptr == NULL) return(OK); - count_elts = 0; - paren_count = 0; -/* - * Check that all elements are in solution for phases with greater than zero mass - */ - for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - count_elts = 0; - paren_count = 0; - s_s_ptr = &(s_s_assemblage_ptr->s_s[i]); - for (j = 0; j < s_s_ptr->count_comps; j++) { - amount_to_add = 0.0; - s_s_ptr->comps[j].delta = 0.0; - if (s_s_ptr->comps[j].moles > 0.0) { - strcpy(token, s_s_ptr->comps[j].phase->formula); - ptr = &(token[0]); - get_elts_in_species (&ptr, 1.0); - for (k = 0; k < count_elts; k++) { - master_ptr = elt_list[k].elt->primary; - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } else if (master_ptr->total > MIN_TOTAL) { - continue; - } else { - total = (-master_ptr->total + 1e-10) / elt_list[k].coef; - if (amount_to_add < total) { - amount_to_add = total; - } - } - } - } - if (s_s_ptr->comps[j].moles < amount_to_add) { - amount_to_add = s_s_ptr->comps[j].moles; - } - if (amount_to_add > 0.0) { - s_s_ptr->comps[j].moles -= amount_to_add; - s_s_ptr->comps[j].delta = amount_to_add; -/* - * Add reaction to totals - */ - for (k = 0; k < count_elts; k++) { - master_ptr = elt_list[k].elt->primary; - if (master_ptr->s == s_hplus) { - total_h_x += elt_list[k].coef * amount_to_add; - } else if (master_ptr->s == s_h2o) { - total_o_x += elt_list[k].coef * amount_to_add; - } else { - master_ptr->total += elt_list[k].coef * amount_to_add; - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_kinetics (struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add kinetic reaction - */ - int i; - struct master *master_ptr; -/* - * Add reaction to totals - */ - if (kinetics_ptr->totals == NULL) return(OK); - for (i = 0; kinetics_ptr->totals[i].elt != NULL; i++) { - master_ptr = kinetics_ptr->totals[i].elt->primary; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Element %s in kinetic reaction not found in database.", kinetics_ptr->totals[i].elt->name); - error_msg(error_string, STOP); - } - if (master_ptr->s == s_hplus) { - total_h_x += kinetics_ptr->totals[i].coef; - } else if (master_ptr->s == s_h2o) { - total_o_x += kinetics_ptr->totals[i].coef; - } else { - master_ptr->total += kinetics_ptr->totals[i].coef; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_check (struct gas_phase *gas_phase_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i, j; - - struct gas_comp *gas_comp_ptr; - struct master *master_ptr; - - if (gas_phase_ptr == NULL) return(OK); - gas_comp_ptr = gas_phase_ptr->comps; -/* - * Check that all elements are in solution for phases with zero mass - */ - for (i = 0; i < gas_phase_ptr->count_comps; i++) { - count_elts = 0; - paren_count = 0; - if (gas_comp_ptr[i].moles <= 0.0) { - add_elt_list(gas_comp_ptr[i].phase->next_elt, 1.0); - for (j = 0; j < count_elts; j++) { - master_ptr = elt_list[j].elt->primary; - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } else if (master_ptr->total > MIN_TOTAL) { - continue; - } else { - if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { - sprintf(error_string, "Element %s is contained in gas %s (which has 0.0 mass),\nbut is not in solution or other phases.", elt_list[j].elt->name, gas_comp_ptr[i].phase->name); - warning_msg(error_string); - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_check (struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i, j, k; - char token[MAX_LENGTH]; - char *ptr; - struct pure_phase *pure_phase_ptr; - struct master *master_ptr; - - if (check_pp_assemblage(pp_assemblage_ptr) == OK) return(OK); -/* - * Check that all elements are in solution for phases with zero mass - */ - pure_phase_ptr = pp_assemblage_ptr->pure_phases; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { - count_elts = 0; - paren_count = 0; - if (pure_phase_ptr[j].moles <= 0.0) { - pure_phase_ptr[j].delta = 0.0; - if (pure_phase_ptr[j].add_formula != NULL) { - strcpy(token, pure_phase_ptr[j].add_formula); - ptr = &(token[0]); - get_elts_in_species (&ptr, 1.0); - } else { - strcpy(token, pure_phase_ptr[j].phase->formula); - add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); - } - for (i = 0; i < count_elts; i++) { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } else if (master_ptr->total > MIN_TOTAL) { - continue; - } else { - if (state != ADVECTION && state != TRANSPORT && state != PHAST) { - sprintf(error_string, "Element %s is contained in %s (which has 0.0 mass)," - "\t\nbut is not in solution or other phases.", elt_list[i].elt->name, pure_phase_ptr[j].phase->name); - warning_msg(error_string); - } -/* - * Make la's of all master species for the element small, so SI will be small - * and no mass transfer will be calculated - */ - for (k = 0; k < count_master; k++) { - if (master[k]->elt->primary == master_ptr) { - master[k]->s->la = -9999.999; - } - } - } - } - } - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_check (struct s_s_assemblage *s_s_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i, j, k, l; - struct master *master_ptr; - - if (s_s_assemblage_ptr == NULL) return(OK); -/* - * Check that all elements are in solution for phases with zero mass - */ - for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - for (j = 0; j < s_s_assemblage_ptr->s_s[i].count_comps; j++) { - count_elts = 0; - paren_count = 0; - if (s_s_assemblage_ptr->s_s[i].comps[j].moles <= 0.0) { - add_elt_list(s_s_assemblage_ptr->s_s[i].comps[j].phase->next_elt, 1.0); - for (l = 0; l < count_elts; l++) { - master_ptr = elt_list[l].elt->primary; - if (master_ptr->s == s_hplus) { - continue; - } else if (master_ptr->s == s_h2o) { - continue; - } else if (master_ptr->total > MIN_TOTAL) { - continue; - } else { - if (state != ADVECTION && state != TRANSPORT && state != PHAST ) { - sprintf(error_string, "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.", elt_list[l].elt->name, s_s_assemblage_ptr->s_s[i].comps[j].phase->name); - warning_msg(error_string); - } - } - /* - * Make la's of all master species for the element small, - * so SI will be small - * and no mass transfer will be calculated - */ - for (k = 0; k < count_master; k++) { - if (master[k]->elt->primary == master_ptr) { - master[k]->s->la = -9999.999; - } - } - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solution_check (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i; - struct master *master_ptr; - -/* - * Check that all elements are in solution for phases with zero mass - */ - for (i =0; i < count_master; i++) { - master_ptr = master[i]; - if (master_ptr->total >= 0.0) continue; - if (master_ptr->total > -MIN_TOTAL) { - master_ptr->total = 0; - continue; - } - if (master_ptr->s == s_eminus || master_ptr->s == s_h2o || master_ptr->s == s_hplus || master_ptr->s == s_h3oplus) { - master_ptr->total = 0; - continue; - } - sprintf(error_string, "Element %s has negative moles in solution, %e. \n\tErroneous mole balance occurs as moles are added to produce zero moles.\n\tUsually caused by KINETICS, REACTION, or diffuse layer calculation.\n\tMay be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer.", master_ptr->elt->name, (double) master_ptr->total); - warning_msg(error_string); - return(MASS_BALANCE); - } - return(OK); -} diff --git a/structures.cpp b/structures.cpp deleted file mode 100644 index eab00142..00000000 --- a/structures.cpp +++ /dev/null @@ -1,6059 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: structures.c 715 2006-01-18 01:26:29Z dlpark $"; - -static int exchange_compare_int(const void *ptr1, const void *ptr2); -static int gas_phase_compare_int(const void *ptr1, const void *ptr2); - -static int inverse_compare(const void *ptr1, const void *ptr2); -static int inverse_free (struct inverse *inverse_ptr); - -static int irrev_compare (const void *ptr1, const void *ptr2); -static int irrev_compare_int(const void *ptr1, const void *ptr2); -static int irrev_sort(void); - -static int kinetics_compare_int(const void *ptr1, const void *ptr2); - -static int logk_init(struct logk *logk_ptr); - -static int master_compare_string (const void *ptr1, const void *ptr2); -static int master_free(struct master *master_ptr); - -#if defined(PHREEQCI_GUI) -int mix_compare (const void *ptr1, const void *ptr2); -#else -static int mix_compare (const void *ptr1, const void *ptr2); -#endif -static int mix_compare_int(const void *ptr1, const void *ptr2); - -static struct phase *phase_alloc(void); -static int phase_compare_string (const void *ptr1, const void *ptr2); -static int phase_free(struct phase *phase_ptr); -static int phase_init(struct phase *phase_ptr); - -static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); - -static int rate_compare (const void *ptr1, const void *ptr2); -static int rate_compare_string (const void *ptr1, const void *ptr2); - -static struct species *s_alloc(void); -static int s_free (struct species *s_ptr); -static int s_init(struct species *s_ptr); - -static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); - -static int solution_compare(const void *ptr1, const void *ptr2); -static int solution_compare_int(const void *ptr1, const void *ptr2); -static struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); - -static int species_list_compare (const void *ptr1, const void *ptr2); - -static int surface_compare_int(const void *ptr1, const void *ptr2); - -static int temperature_compare (const void *ptr1, const void *ptr2); -static int temperature_compare_int(const void *ptr1, const void *ptr2); - -static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); -static int trxn_multiply (LDBLE coef); - -#ifdef PHREEQCI_GUI -extern void free_spread(void); -#endif -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern void MergeFinalize(void); -#endif - -/* ---------------------------------------------------------------------- */ -int clean_up(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free all allocated memory, except strings - */ - int i, j; - if (svnid == NULL) fprintf(stderr," "); - - description_x = (char *) free_check_null(description_x); - isotopes_x = (struct isotope *) free_check_null(isotopes_x); - moles_per_kilogram_string = (char *) free_check_null(moles_per_kilogram_string); - pe_string = (char *) free_check_null(pe_string); -/* model */ - last_model.exchange = (struct master **) free_check_null(last_model.exchange); - last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); - last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); - last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); - last_model.add_formula = (char **) free_check_null(last_model.add_formula); - last_model.si = (double *) free_check_null(last_model.si); - last_model.surface_comp = (struct master **) free_check_null(last_model.surface_comp); - last_model.surface_charge = (struct master **) free_check_null(last_model.surface_charge); - - /* model */ - free_model_allocs(); - -/* species */ - - for (j=0; jname, element_ptr2->name)); */ - return(strcmp(element_ptr1->name, element_ptr2->name)); - -} -/* ---------------------------------------------------------------------- */ -struct element *element_store (char *element) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "element" in the hash table for elements. - * - * If found, pointer to the appropriate element structure is returned. - * - * If the string is not found, a new entry is made at the end of - * the elements array (position count_elements) and count_elements is - * incremented. A new entry is made in the hash table. Pointer to - * the new structure is returned. - * - * Arguments: - * element input, character string to be located or stored. - * - * Returns: - * The address of an elt structure that contains the element data. - */ - int n; - struct element *elts_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - item.key = element; - item.data = NULL; - found_item = hsearch_multi(elements_hash_table, item, FIND); - if (found_item != NULL) { - elts_ptr = (struct element *) (found_item->data); - return (elts_ptr); - } -/* - * Save new elt structure and return pointer to it - */ - /* make sure there is space in elements */ - elements[count_elements] = (struct element *) PHRQ_malloc((size_t) sizeof(struct element)); - if (elements[count_elements] == NULL) malloc_error(); - /* set name pointer in elements structure */ - elements[count_elements]->name=string_hsave( element ); - /* set return value */ - elements[count_elements]->master = NULL; - elements[count_elements]->primary = NULL; - elements[count_elements]->gfw = 0.0; - n = count_elements++; - if (count_elements >= max_elements) { - space ((void **) ((void *) &elements), count_elements, &max_elements, sizeof(struct element *)); - } -/* - * Update hash table - */ - item.key = elements[n]->name; - item.data = (void *) elements[n]; - found_item = hsearch_multi(elements_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in element_store."); - error_msg(error_string, CONTINUE); - } - return (elements[n]); -} -/* ********************************************************************** - * - * Routines related to structure "elt_list" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -int elt_list_combine(void) -/* ---------------------------------------------------------------------- */ -/* - * Function goes through the list of elements pointed to by elt_list - * and combines the coefficients of elements that are the same. - * Assumes elt_list has been sorted by element name. - */ -{ - int i, j; - - if (count_elts < 1 ) { - output_msg(OUTPUT_MESSAGE, "elt_list_combine: How did this happen?\n"); - return(ERROR); - } - if (count_elts == 1 ) { - return(OK); - } - j=0; - for ( i=1; i < count_elts; i++) { - if ( elt_list[i].elt == elt_list[j].elt ) { - elt_list[j].coef += elt_list[i].coef; - } else { - j++; - if ( i != j ) { - elt_list[j].elt=elt_list[i].elt; - elt_list[j].coef=elt_list[i].coef; - } - } - } - count_elts=j+1; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int elt_list_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct elt_list *a, *b; - - a=(const struct elt_list *) ptr1; - b=(const struct elt_list *) ptr2; - return( strncmp( a->elt->name, b->elt->name, MAX_LENGTH)); -} -/* ---------------------------------------------------------------------- */ -struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old) -/* ---------------------------------------------------------------------- */ -{ -/* - * Duplicates the elt_list structure pointed to by elt_list_ptr_old. - */ - int i, count_totals; - struct elt_list *elt_list_ptr_new; -/* - * Count totals data and copy - */ - if (elt_list_ptr_old == NULL) return (NULL); - for (i = 0; elt_list_ptr_old[i].elt != NULL; i++); - count_totals = i; -/* - * Malloc space and store element data - */ - elt_list_ptr_new = (struct elt_list *) PHRQ_malloc( (size_t) (count_totals + 1) - * sizeof(struct elt_list)); - if (elt_list_ptr_new == NULL ) malloc_error(); - memcpy(elt_list_ptr_new, elt_list_ptr_old, - (size_t) (count_totals + 1) * sizeof(struct elt_list)); - return (elt_list_ptr_new); -} -/* ---------------------------------------------------------------------- */ -int elt_list_print(struct elt_list *elt_list_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Duplicates the elt_list structure pointed to by elt_list_ptr_old. - */ - int i; -/* - * Debug print for element list - */ - if (elt_list_ptr == NULL) return (ERROR); - output_msg(OUTPUT_MESSAGE, "Elt_list\n"); - for (i = 0; elt_list_ptr[i].elt != NULL; i++) { - output_msg(OUTPUT_MESSAGE, "\t%s\t%e\n", elt_list_ptr[i].elt->name, (double) elt_list_ptr[i].coef); - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int elt_list_print0(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Duplicates the elt_list structure pointed to by elt_list_ptr_old. - */ - int i; -/* - * Debug print for element list - */ - output_msg(OUTPUT_STDERR, "Elt_list\n"); - for (i = 0; i < count_elts; i++) { - output_msg(OUTPUT_STDERR, "\t%s\t%e\n", elt_list[i].elt->name, (double) elt_list[i].coef); - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -struct elt_list *elt_list_save(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Takes data from work space elt_list, allocates a new elt_list structure, - * copies data from work space to new structure, and returns pointer to - * new structure. - */ - int j; - struct elt_list *elt_list_ptr; -/* - * Sort elements in reaction and combine - */ - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } -/* - * Malloc space and store element data - */ - elt_list_ptr=(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1)*sizeof(struct elt_list)); - if (elt_list_ptr == NULL ) malloc_error(); - for ( j=0; j < count_elts; j++ ) { - elt_list_ptr[j].elt=elt_list[j].elt; - elt_list_ptr[j].coef=elt_list[j].coef; - } - elt_list_ptr[count_elts].elt=NULL; - return (elt_list_ptr); -} -/* ********************************************************************** - * - * Routines related to structure "exchange" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct exchange *exchange_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct exchange *exchange_ptr; - exchange_ptr = (struct exchange *) PHRQ_malloc(sizeof (struct exchange)); - if (exchange_ptr == NULL) malloc_error(); - exchange_ptr->description = NULL; - exchange_ptr->count_comps = 0; - exchange_ptr->comps = NULL; - return ( exchange_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct exchange *exchange_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search exchange to find if user exchange number k exists. - * Exchange is assumed to be in sort order by user number. - */ - void *void_ptr; - if (count_exchange == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) exchange, - (size_t) count_exchange, - (size_t) sizeof(struct exchange), - exchange_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct exchange *) void_ptr - exchange); - return ( (struct exchange *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int exchange_comp_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct exch_comp *exch_comp_ptr1, *exch_comp_ptr2; - exch_comp_ptr1 = (const struct exch_comp *) ptr1; - exch_comp_ptr2 = (const struct exch_comp *) ptr2; - return(strcmp_nocase(exch_comp_ptr1->master->elt->name, exch_comp_ptr2->master->elt->name)); -} -/* ---------------------------------------------------------------------- */ -int exchange_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct exchange *exchange_ptr1, *exchange_ptr2; - exchange_ptr1 = (const struct exchange *) ptr1; - exchange_ptr2 = (const struct exchange *) ptr2; - if (exchange_ptr1->n_user > exchange_ptr2->n_user) return(1); - if (exchange_ptr1->n_user < exchange_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int exchange_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare exchange user numbers - */ - const int *nptr1; - const struct exchange *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct exchange *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies exchange data from exchange_old_ptr to new location, exchange_new_ptr. - * Space for the exchange_new_ptr structure must already be malloced. - * Space for exchange components is malloced here. - */ - int count_comps, i; - char token[MAX_LENGTH]; -/* - * Store data for structure exchange - */ - memcpy(exchange_new_ptr, exchange_old_ptr, sizeof(struct exchange)); - exchange_new_ptr->n_user = n_user_new; - exchange_new_ptr->n_user_end = n_user_new; - count_comps = exchange_old_ptr->count_comps; - exchange_new_ptr->new_def = exchange_old_ptr->new_def; - exchange_new_ptr->solution_equilibria = FALSE; - exchange_new_ptr->n_solution = -2; - exchange_new_ptr->count_comps = count_comps; - sprintf(token, "Exchanger defined in simulation %d.", simulation); - exchange_new_ptr->description = string_duplicate(token); -/* - * Count exchange components and allocate space - */ - exchange_new_ptr->comps = (struct exch_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct exch_comp)); - if (exchange_new_ptr->comps == NULL) malloc_error(); -/* - * Write exch_comp structure for each exchange component - */ - memcpy(exchange_new_ptr->comps, exchange_old_ptr->comps, - (size_t) (count_comps) * sizeof (struct exch_comp)); - for ( i = 0; i < count_comps; i++) { - exchange_new_ptr->comps[i].totals = elt_list_dup(exchange_old_ptr->comps[i].totals); - exchange_new_ptr->comps[i].formula_totals = elt_list_dup(exchange_old_ptr->comps[i].formula_totals); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an exchange definition from position n to position count_exchange. - * New exchange structure is given user number n_user. - */ - space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); - exchange_copy(&exchange[n], &exchange[count_exchange], n_user); - count_exchange++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array exchange. - */ -{ - int i; - int n_old; - struct exchange *exchange_ptr_old; -/* - * Find n_user_old in structure array - */ - exchange_ptr_old = exchange_bsearch(n_user_old, &n_old); - if (exchange_ptr_old != NULL) { - /* - * Delete exchange - */ - exchange_free(&exchange[n_old]); - - for(i = n_old + 1; i < count_exchange; i++) { - memcpy( (void *) &exchange[i - 1], (void *) &exchange[i], - (size_t) sizeof (struct exchange) ); - } - count_exchange--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies exchange[n_user_old] to old n_user_new space if - * found or to exchange[count_exchange] if not found. - * Exchange array may not be in sort order after the copy. - */ - int sort; - int n_old, n_new; - struct exchange *exchange_ptr_old, *exchange_ptr_new; -/* - * Find n_user_old in structure array exchange - */ - if (n_user_old == n_user_new) return(OK); - exchange_ptr_old = exchange_bsearch(n_user_old, &n_old); - if (exchange_ptr_old == NULL) { - sprintf(error_string, "Exchange %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array exchange or make new space - */ - sort = FALSE; - exchange_ptr_new = exchange_bsearch(n_user_new, &n_new); - if (exchange_ptr_new != NULL) { - exchange_free(exchange_ptr_new); - } else { - space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); - if (n_user_new < exchange[count_exchange-1].n_user) sort = TRUE; - n_new = count_exchange++; - } -/* - * Copy data - */ - exchange_copy(&exchange[n_old], &exchange[n_new], n_user_new); - if (sort == TRUE) exchange_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_free (struct exchange *exchange_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all data associated with exchange structure. - */ - int i; - if (exchange_ptr == NULL) return(ERROR); -/* - * Free space allocated for exchange structure - */ - exchange_ptr->description = (char *) free_check_null (exchange_ptr->description); - for (i=0; i < exchange_ptr->count_comps; i++) { - exchange_ptr->comps[i].totals = (struct elt_list *) free_check_null (exchange_ptr->comps[i].totals); - exchange_ptr->comps[i].formula_totals = (struct elt_list *) free_check_null (exchange_ptr->comps[i].formula_totals); - } - exchange_ptr->comps = (struct exch_comp *) free_check_null (exchange_ptr->comps); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_init (struct exchange *exchange_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all data associated with exchange structure. - */ - - if (exchange_ptr == NULL) return(ERROR); - exchange_ptr->n_user = n_user; - exchange_ptr->n_user_end = n_user_end; - exchange_ptr->new_def = TRUE; - exchange_ptr->description = string_duplicate(description); - exchange_ptr->solution_equilibria = FALSE; - exchange_ptr->n_solution = 0; - exchange_ptr->count_comps = 0; - exchange_ptr->comps = (struct exch_comp *) PHRQ_malloc(sizeof (struct exch_comp)); - if (exchange_ptr->comps == NULL) malloc_error(); - exchange_ptr->related_phases = FALSE; - exchange_ptr->related_rate = FALSE; - exchange_ptr->pitzer_exchange_gammas = TRUE; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int exchange_ptr_to_user(struct exchange *exchange_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies exchange_old_ptr to old n_user_new space if - * found or to exchange[count_exchange] if not found. - * Exchange array may not be in sort order after the copy. - */ - int sort; - int n_new; - struct exchange *exchange_ptr_new; -/* - * Find n_user_old in structure array exchange - */ - if (exchange_ptr_old == NULL) { - sprintf(error_string, "Exchange ptr is NULL"); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array exchange or make new space - */ - sort = FALSE; - exchange_ptr_new = exchange_bsearch(n_user_new, &n_new); - if (exchange_ptr_new == exchange_ptr_old) return(OK); - if (exchange_ptr_new != NULL) { - exchange_free(exchange_ptr_new); - } else { - space ((void **) ((void *) &exchange), count_exchange, &max_exchange, sizeof(struct exchange)); - if (n_user_new < exchange[count_exchange-1].n_user) sort = TRUE; - n_new = count_exchange++; - } -/* - * Copy data - */ - exchange_copy(exchange_ptr_old, &exchange[n_new], n_user_new); - if (sort == TRUE) exchange_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct exchange *exchange_ptr; - exchange_ptr = exchange_alloc(); - exchange_copy(exchange_old_ptr, exchange_ptr, n_user_new); - return (exchange_ptr); -} -/* ---------------------------------------------------------------------- */ -struct exchange *exchange_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Does linear search for user number n_user. - * Returns pointer to exchange structure and position number, n, - * in exchange array if found. - * Returns NULL if not found. - */ - int i; - for (i = 0; i < count_exchange; i++) { - if (n_user == exchange[i].n_user) { - break; - } - } - if (i >= count_exchange) { - if ( print == TRUE) { - sprintf(error_string, "Exchange %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return(NULL); - } - *n = i; - return(&exchange[i]); -} -/* ---------------------------------------------------------------------- */ -int exchange_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of exchange structures - */ - if (count_exchange > 0) { - qsort (exchange, (size_t) count_exchange, (size_t) sizeof(struct exchange), - exchange_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "gas" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -int gas_comp_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct gas_comp *gas_comp_ptr1, *gas_comp_ptr2; - gas_comp_ptr1 = (const struct gas_comp *) ptr1; - gas_comp_ptr2 = (const struct gas_comp *) ptr2; - return(strcmp_nocase(gas_comp_ptr1->name, gas_comp_ptr2->name)); - -} -/* ---------------------------------------------------------------------- */ -struct gas_phase *gas_phase_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct gas_phase *gas_phase_ptr; - gas_phase_ptr = (struct gas_phase *) PHRQ_malloc(sizeof (struct gas_phase)); - if (gas_phase_ptr == NULL) malloc_error(); - gas_phase_ptr->description = NULL; - gas_phase_ptr->count_comps = 0; - gas_phase_ptr->comps = NULL; - return ( gas_phase_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct gas_phase *gas_phase_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search gas_phase to find if user gas_phase number k exists. - * Assumes array gas_phase is in sort order. - */ - void *void_ptr; - if (count_gas_phase == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) gas_phase, - (size_t) count_gas_phase, - (size_t) sizeof(struct gas_phase), - gas_phase_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct gas_phase *) void_ptr - gas_phase); - return ( (struct gas_phase *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct gas_phase *gas_phase_ptr1, *gas_phase_ptr2; - gas_phase_ptr1 = (const struct gas_phase *) ptr1; - gas_phase_ptr2 = (const struct gas_phase *) ptr2; - if (gas_phase_ptr1->n_user > gas_phase_ptr2->n_user) return(1); - if (gas_phase_ptr1->n_user < gas_phase_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int gas_phase_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare gas phase user numbers - */ - const int *nptr1; - const struct gas_phase *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct gas_phase *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies gas_phase structure from gas_phase_old_ptr to new location gas_phase_new_ptr. - * Space for a gas_phase structure must already be malloced - * Space for gas_phase components is alloced here. - */ - int count_comps; - char token[MAX_LENGTH]; -/* - * Store data for structure gas - */ - memcpy(gas_phase_new_ptr, gas_phase_old_ptr, (size_t) sizeof(struct gas_phase)); - count_comps = gas_phase_old_ptr->count_comps; - gas_phase_new_ptr->n_user = n_user_new; - gas_phase_new_ptr->n_user_end = n_user_new; - gas_phase_new_ptr->new_def = FALSE; - sprintf(token, "Gas defined in simulation %d.", simulation); - gas_phase_new_ptr->description = string_duplicate(token); -/* - * Allocate space for gas components - */ - gas_phase_new_ptr->comps = (struct gas_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct gas_comp)); - if (gas_phase_new_ptr->comps == NULL) malloc_error(); -/* - * Write gas_comp structure for each gas component - */ - memcpy(gas_phase_new_ptr->comps, gas_phase_old_ptr->comps, - (size_t) (count_comps) * sizeof (struct gas_comp)); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an gas_phase definition to position count_gas_phase. - */ - space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); - gas_phase_copy(&gas_phase[n], &gas_phase[count_gas_phase], n_user); - count_gas_phase++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array gas_phase. - */ -{ - int i; - int n_old; - struct gas_phase *gas_phase_ptr_old; -/* - * Find n_user_old in structure array - */ - gas_phase_ptr_old = gas_phase_bsearch(n_user_old, &n_old); - if (gas_phase_ptr_old != NULL) { - /* - * Delete gas_phase - */ - gas_phase_free(&gas_phase[n_old]); - - for(i = n_old + 1; i < count_gas_phase; i++) { - memcpy( (void *) &gas_phase[i - 1], (void *) &gas_phase[i], - (size_t) sizeof (struct gas_phase) ); - } - count_gas_phase--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies gas_phase[n_user_old] to old n_user_new space if - * found or to gas_phase[count_gas_phase] if not found. - * Gas_Phase array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct gas_phase *gas_phase_ptr_old, *gas_phase_ptr_new; -/* - * Find n_user_old in structure array gas_phase - */ - if (n_user_old == n_user_new) return(OK); - gas_phase_ptr_old = gas_phase_bsearch(n_user_old, &n_old); - if (gas_phase_ptr_old == NULL) { - sprintf(error_string, "Gas_Phase %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array gas_phase or make new space - */ - sort = FALSE; - gas_phase_ptr_new = gas_phase_bsearch(n_user_new, &n_new); - if (gas_phase_ptr_new != NULL) { - gas_phase_free (&gas_phase[n_new]); -#ifdef SKIP - gas_phase[n_new].comps = free_check_null (gas_phase[n_new].comps); -#endif - } else { - space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); - if (n_user_new < gas_phase[count_gas_phase-1].n_user) sort = TRUE; - n_new = count_gas_phase++; - } -/* - * Copy data - */ - gas_phase_copy(&gas_phase[n_old], &gas_phase[n_new], n_user_new); - if (sort == TRUE) gas_phase_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_free (struct gas_phase *gas_phase_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees space associated with gas_phase_ptr. - */ - if (gas_phase_ptr == NULL) return(ERROR); -/* - * Free space allocated for gas_phase structure - */ - gas_phase_ptr->description = (char *) free_check_null (gas_phase_ptr->description); - gas_phase_ptr->comps = (struct gas_comp *) free_check_null (gas_phase_ptr->comps); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_init (struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees space associated with gas_phase_ptr. - */ - if (gas_phase_ptr == NULL) return(ERROR); - gas_phase_ptr->n_user = n_user; - gas_phase_ptr->n_user_end = n_user_end; - gas_phase_ptr->description = string_duplicate(description); - gas_phase_ptr->new_def = TRUE; - gas_phase_ptr->solution_equilibria = FALSE; - gas_phase_ptr->n_solution = 0; - gas_phase_ptr->type = PRESSURE; - gas_phase_ptr->total_p = 1.0; - gas_phase_ptr->total_moles = 0.0; - gas_phase_ptr->volume = 1.0; - gas_phase_ptr->temperature = 298.15; - gas_phase_ptr->count_comps = 0; - gas_phase_ptr->comps = (struct gas_comp *) PHRQ_malloc((size_t) sizeof(struct gas_comp)); - if (gas_phase_ptr->comps == NULL) malloc_error(); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies gas_phase_ptr_old to old n_user_new space if - * found or to gas_phase[count_gas_phase] if not found. - * Gas_Phase array may not be in sort order after the copy. - */ - int n_new, sort; - struct gas_phase *gas_phase_ptr_new; -/* - * Find n_user_old in structure array gas_phase - */ - if (gas_phase_ptr_old == NULL) { - sprintf(error_string, "Gas_Phase pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array gas_phase or make new space - */ - sort = FALSE; - gas_phase_ptr_new = gas_phase_bsearch(n_user_new, &n_new); - if (gas_phase_ptr_new == gas_phase_ptr_old) return(OK); - if (gas_phase_ptr_new != NULL) { - gas_phase_free (&gas_phase[n_new]); -#ifdef SKIP - gas_phase[n_new].comps = free_check_null (gas_phase[n_new].comps); -#endif - } else { - space ((void **) ((void *) &gas_phase), count_gas_phase, &max_gas_phase, sizeof(struct gas_phase)); - if (n_user_new < gas_phase[count_gas_phase-1].n_user) sort = TRUE; - n_new = count_gas_phase++; - } -/* - * Copy data - */ - gas_phase_copy(gas_phase_ptr_old, &gas_phase[n_new], n_user_new); - if (sort == TRUE) gas_phase_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct gas_phase *gas_phase_ptr; - gas_phase_ptr = gas_phase_alloc(); - gas_phase_copy(gas_phase_old_ptr, gas_phase_ptr, n_user_new); - return (gas_phase_ptr); -} -/* ---------------------------------------------------------------------- */ -struct gas_phase *gas_phase_search (int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "gas_phase" for user number n_user - * - * Arguments: - * n_user input, user number - * n output, position in gas_phase - * - * Returns: - * if found, the address of the gas_phase element - * if not found, NULL - * - */ - int i; - for (i=0; i < count_gas_phase; i++) { - if ( gas_phase[i].n_user == n_user) { - *n = i; - return (&(gas_phase[i])); - } - } -/* - * Gas_phase not found - */ - return (NULL); -} -/* ---------------------------------------------------------------------- */ -int gas_phase_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of gas_phase structures - */ - if (count_gas_phase > 0) { - qsort (gas_phase, (size_t) count_gas_phase, (size_t) sizeof(struct gas_phase), - gas_phase_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "inverse" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct inverse *inverse_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space for a new inverse structure at position count_inverse. - * Initializes structure. - * arguments - * input: none - * output: pointer to an inverse structure - * return: OK - */ -{ - struct inverse *inverse_ptr; - - count_inverse++; - inverse = (struct inverse *) PHRQ_realloc(inverse, (size_t) count_inverse * sizeof(struct inverse)); - if (inverse == NULL) malloc_error(); - inverse_ptr = &(inverse[count_inverse-1]); -/* - * Initialize variables - */ - inverse_ptr->description = NULL; - inverse_ptr->count_uncertainties = 0; - inverse_ptr->count_solns = 0; - inverse_ptr->count_elts = 0; - inverse_ptr->count_isotopes = 0; - inverse_ptr->count_i_u = 0; - inverse_ptr->count_phases = 0; - inverse_ptr->count_force_solns = 0; -/* - * allocate space for pointers in structure to NULL - */ - - inverse_ptr->uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (inverse_ptr->uncertainties == NULL) malloc_error(); - - inverse_ptr->ph_uncertainties = (double *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (inverse_ptr->ph_uncertainties == NULL) malloc_error(); - -#ifdef SKIP - inverse_ptr->alk_uncertainties = PHRQ_malloc((size_t) sizeof(LDBLE)); - if (inverse_ptr->alk_uncertainties == NULL) malloc_error(); -#endif - - inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int)); - if (inverse_ptr->force_solns == NULL) malloc_error(); - - inverse_ptr->dalk_dph = NULL; - inverse_ptr->dalk_dc = NULL; - - - inverse_ptr->solns = NULL; - - inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); - if (inverse_ptr->elts == NULL) malloc_error(); - inverse_ptr->elts[0].name = NULL; - inverse_ptr->elts[0].uncertainties = NULL; - - inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); - if (inverse_ptr->isotopes == NULL) malloc_error(); - inverse_ptr->isotopes[0].isotope_name = NULL; - inverse_ptr->isotopes[0].isotope_number = 0; - inverse_ptr->isotopes[0].elt_name = NULL; - - inverse_ptr->i_u = (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); - if (inverse_ptr->i_u == NULL) malloc_error(); - inverse_ptr->i_u[0].isotope_name = NULL; - inverse_ptr->i_u[0].isotope_number = 0; - inverse_ptr->i_u[0].elt_name = NULL; - - inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); - if (inverse_ptr->phases == NULL) malloc_error(); - - return(inverse_ptr); -} -/* ---------------------------------------------------------------------- */ -int inverse_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare inverse values for n_user - */ - const struct inverse *nptr1; - const struct inverse *nptr2; - - nptr1= (const struct inverse *) ptr1; - nptr2= (const struct inverse *) ptr2; - if (nptr1->n_user > nptr2->n_user) return(1); - if (nptr1->n_user < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int inverse_delete(int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Deletes inverse i from list (i is not user number), - * Frees memory allocated to inverse struct - * Input: i, number of inverse struct to delete - * Return: OK - */ - int j; - - inverse_free ( &(inverse[i]) ); - for (j=i; j < (count_inverse - 1); j++) { - memcpy ( (void *) &(inverse[j]), (void *) &(inverse[j+1]), - (size_t) sizeof (struct inverse)); - } - count_inverse--; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int inverse_free (struct inverse *inverse_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free all memory for an inverse structure. - */ - int i; - - inverse_ptr->description = (char *) free_check_null (inverse_ptr->description); -/* Free solns */ - inverse_ptr->solns = (int *) free_check_null (inverse_ptr->solns); - -/* Free uncertainties */ - inverse_ptr->uncertainties = (double *) free_check_null (inverse_ptr->uncertainties); - inverse_ptr->ph_uncertainties = (double *) free_check_null (inverse_ptr->ph_uncertainties); -#ifdef SKIP - inverse_ptr->alk_uncertainties = (double *) free_check_null (inverse_ptr->alk_uncertainties); -#endif - -/* Free force_solns */ - inverse_ptr->force_solns = (int *) free_check_null (inverse_ptr->force_solns); - -/* Free elts */ - for (i = 0; i < inverse_ptr->count_elts; i++) { - inverse_ptr->elts[i].uncertainties = (double *) free_check_null (inverse_ptr->elts[i].uncertainties); - }; - inverse_ptr->elts = (struct inv_elts *) free_check_null (inverse_ptr->elts); - -/* Free isotopes */ - for (i = 0; i < inverse_ptr->count_isotopes; i++) { - inverse_ptr->isotopes[i].uncertainties = (double *) free_check_null (inverse_ptr->isotopes[i].uncertainties); - }; - inverse_ptr->isotopes = (struct inv_isotope *) free_check_null (inverse_ptr->isotopes); - - for (i = 0; i < inverse_ptr->count_i_u; i++) { - inverse_ptr->i_u[i].uncertainties = (double *) free_check_null (inverse_ptr->i_u[i].uncertainties); - }; - inverse_ptr->i_u = (struct inv_isotope *) free_check_null (inverse_ptr->i_u); - -/* Free phases */ - for (i = 0; i < inverse_ptr->count_phases; i++) { - inverse_ptr->phases[i].isotopes = (struct isotope *) free_check_null(inverse_ptr->phases[i].isotopes); - } - inverse_ptr->phases = (struct inv_phases *) free_check_null (inverse_ptr->phases); - -/* Free carbon derivatives */ - inverse_ptr->dalk_dph = (LDBLE *) free_check_null(inverse_ptr->dalk_dph); - inverse_ptr->dalk_dc = (LDBLE *) free_check_null(inverse_ptr->dalk_dc); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int inverse_isotope_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - int i; - const struct inv_isotope *iso_ptr1, *iso_ptr2; - - iso_ptr1 = (const struct inv_isotope *) ptr1; - iso_ptr2 = (const struct inv_isotope *) ptr2; - i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); - if (i != 0) return(i); - if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) { - return(-1); - } else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) { - return(1); - } - return(0); -} - -/* ---------------------------------------------------------------------- */ -struct inverse *inverse_search (int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "inverse" for user number n_user. - * - * Arguments: - * n_user input, user number - * n output, position in inverse - * - * Returns: - * if found, the address of the inverse element - * if not found, NULL - * - */ - int i; - for (i=0; i < count_inverse; i++) { - if ( inverse[i].n_user == n_user) { - *n = i; - return (&(inverse[i])); - } - } -/* - * An inverse structure with n_user was not found - */ - return (NULL); -} -/* ---------------------------------------------------------------------- */ -int inverse_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of inverse structures - */ - if (count_inverse > 0) { - qsort (inverse, (size_t) count_inverse, (size_t) sizeof(struct inverse), - inverse_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "irrev" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct irrev *irrev_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Search irrev to find if user irrev number k exists. - * Uses binary search, assumes array irrev is in sort order. - */ - void *void_ptr; - if (count_irrev == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) irrev, - (size_t) count_irrev, - (size_t) sizeof(struct irrev), - irrev_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct irrev *) void_ptr - irrev); - return ( (struct irrev *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int irrev_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct irrev *irrev_ptr1, *irrev_ptr2; - irrev_ptr1 = (const struct irrev *) ptr1; - irrev_ptr2 = (const struct irrev *) ptr2; - if (irrev_ptr1->n_user > irrev_ptr2->n_user) return(1); - if (irrev_ptr1->n_user < irrev_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int irrev_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare irrev user numbers - */ - const int *nptr1; - const struct irrev *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct irrev *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies irrev structure from irrev_old_ptr to new location irrev_new_ptr. - * Space for a irrev structure must already be malloced - * Space for irrev components is alloced here. - */ - int count_list, count_steps; - char token[MAX_LENGTH]; -/* - * Store data for structure gas - */ - memcpy(irrev_new_ptr, irrev_old_ptr, (size_t) sizeof(struct irrev)); - irrev_new_ptr->n_user = n_user_new; - irrev_new_ptr->n_user_end = n_user_new; - sprintf(token, "Reaction defined in simulation %d.", simulation); - irrev_new_ptr->description = string_duplicate(token); - count_list = irrev_old_ptr->count_list; - count_steps = irrev_old_ptr->count_steps; -/* - * Allocate space - */ - irrev_new_ptr->list = (struct name_coef *) PHRQ_malloc((size_t) (count_list) * sizeof (struct name_coef)); - if (irrev_new_ptr->list == NULL) malloc_error(); - memcpy(irrev_new_ptr->list, irrev_old_ptr->list, (size_t) (count_list) * sizeof (struct name_coef)); - if (count_steps < 0) count_steps = 1; - irrev_new_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps) * sizeof (LDBLE)); - if (irrev_new_ptr->steps == NULL) malloc_error(); - memcpy(irrev_new_ptr->steps, irrev_old_ptr->steps, (size_t) (count_steps) * sizeof (LDBLE)); - - if (irrev_old_ptr->elts != NULL) { - irrev_new_ptr->elts = elt_list_dup(irrev_old_ptr->elts); - } else { - irrev_new_ptr->elts = NULL; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int irrev_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Finds irrev structure with user number n_user_old, - * copies data to irrev structure with user number n_user_new. - * If n_user_new already exists, it is overwritten and sort order - * is maintained. - * If n_user_new does not exist, a new structure is allocated; sort - * order may not be preserved. - */ - int n_old, n_new, sort; - char token[MAX_LENGTH]; - int count_steps, count_list; - struct irrev *irrev_ptr_old, *irrev_ptr_new; -/* - * Find n_user_old in structure array irrev_assemblage or make new space - */ - if (n_user_old == n_user_new) return(OK); - irrev_ptr_old = irrev_bsearch(n_user_old, &n_old); - if (irrev_ptr_old == NULL) { - sprintf(error_string, "Irreversible reaction %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_old in structure array irrev or make new space - */ - sort = FALSE; - irrev_ptr_new = irrev_bsearch(n_user_new, &n_new); - if (irrev_ptr_new != NULL) { - irrev_free(irrev_ptr_new); - } else { - irrev = (struct irrev *) PHRQ_realloc( irrev, (size_t) (count_irrev + 1) * sizeof (struct irrev)); - if (irrev == NULL) malloc_error(); - if (n_user_new < irrev[count_irrev-1].n_user) sort = TRUE; - n_new = count_irrev++; - } -/* - * Store data for structure irrev - */ - count_steps = irrev[n_old].count_steps; - irrev[n_new].n_user = n_user_new; - irrev[n_new].n_user_end = n_user_new; - sprintf(token, "Irreversible reaction defined in simulation %d.", simulation); - irrev[n_new].description = string_duplicate(token); - irrev[n_new].units = irrev[n_old].units; - irrev[n_new].count_steps = count_steps; - count_list = irrev[n_old].count_list; - irrev[n_new].count_list = irrev[n_old].count_list; -/* - * Allocate space - */ - irrev[n_new].list = (struct name_coef *) PHRQ_malloc((size_t) (count_list) * sizeof (struct name_coef)); - if (irrev[n_new].list == NULL) malloc_error(); - memcpy(irrev[n_new].list, irrev[n_old].list, - (size_t) (count_list) * sizeof (struct name_coef)); - - if (count_steps < 0) count_steps = 1; - irrev[n_new].steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps) * sizeof (LDBLE)); - if (irrev[n_new].steps == NULL) malloc_error(); - memcpy(irrev[n_new].steps, irrev[n_old].steps, - (size_t) (count_steps) * sizeof (LDBLE)); - - if (irrev[n_old].elts != NULL) { - irrev[n_new].elts = elt_list_dup(irrev[n_old].elts); - } else { - irrev[n_new].elts = NULL; - } - if (sort == TRUE) irrev_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int irrev_free (struct irrev *irrev_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free memory pointed to by an irrev structure. - */ - if (irrev_ptr == NULL) return(ERROR); -/* - * Free space allocated for irrev structure - */ - irrev_ptr->description = (char *) free_check_null (irrev_ptr->description); - irrev_ptr->list = (struct name_coef *) free_check_null (irrev_ptr->list); - irrev_ptr->elts = (struct elt_list *) free_check_null (irrev_ptr->elts); - irrev_ptr->steps = (LDBLE *) free_check_null (irrev_ptr->steps); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct irrev *irrev_search(int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Linear search for irrev user number n_user. - * If found, n is position in irrev array and pointer to irrev structure - * is returned - * If not found, NULL is returned. - */ - int i; - for (i = 0; i < count_irrev; i++) { - if (n_user == irrev[i].n_user) { - break; - } - } - if (i >= count_irrev) { - *n = -999; - return(NULL); - } - *n = i; - return(&irrev[i]); -} -/* ---------------------------------------------------------------------- */ -int irrev_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of irrev structures - */ - if (count_irrev > 0) { - qsort (irrev, (size_t) count_irrev, (size_t) sizeof(struct irrev), - irrev_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "kinetics" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct kinetics *kinetics_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct kinetics *kinetics_ptr; - kinetics_ptr = (struct kinetics *) PHRQ_malloc(sizeof (struct kinetics)); - if (kinetics_ptr == NULL) malloc_error(); - kinetics_ptr->description = NULL; - kinetics_ptr->count_comps = 0; - kinetics_ptr->comps = NULL; - kinetics_ptr->count_steps = 0; - kinetics_ptr->steps = NULL; - /*kinetics_ptr->units = NULL;*/ - kinetics_ptr->totals = NULL; - return ( kinetics_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct kinetics *kinetics_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search kinetics to find if user kinetics number k exists. - * Kinetics is assumed to be in sort order by user number. - */ - void *void_ptr; - if (count_kinetics == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) kinetics, - (size_t) count_kinetics, - (size_t) sizeof(struct kinetics), - kinetics_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct kinetics *) void_ptr - kinetics); - return ( (struct kinetics *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int kinetics_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct kinetics *kinetics_ptr1, *kinetics_ptr2; - kinetics_ptr1 = (const struct kinetics *) ptr1; - kinetics_ptr2 = (const struct kinetics *) ptr2; - if (kinetics_ptr1->n_user > kinetics_ptr2->n_user) return(1); - if (kinetics_ptr1->n_user < kinetics_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int kinetics_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare kinetics user numbers - */ - const int *nptr1; - const struct kinetics *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct kinetics *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies kinetics data from kinetics_old_ptr to new location, kinetics_new_ptr. - * Space for the kinetics_new_ptr structure must already be malloced. - * Space for kinetics components is malloced here. - */ - char token[MAX_LENGTH]; - int count_steps, i; -/* - * copy old to new - */ - memcpy(kinetics_new_ptr, kinetics_old_ptr, sizeof (struct kinetics)); -/* - * Store data for structure kinetics - */ - kinetics_new_ptr->n_user = n_user_new; - kinetics_new_ptr->n_user_end = n_user_new; - sprintf(token, "Kinetics defined in simulation %d.", simulation); - kinetics_new_ptr->description = string_duplicate(token); - kinetics_new_ptr->totals = NULL; - kinetics_new_ptr->totals = elt_list_dup(kinetics_old_ptr->totals); -/* - * Copy time steps - */ - if (kinetics_new_ptr->count_steps > 0) { - count_steps = kinetics_new_ptr->count_steps; - } else if (kinetics_new_ptr->count_steps < 0) { - count_steps = 1; - } else { - count_steps = 0; - } - if (count_steps > 0) { - kinetics_new_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (count_steps * sizeof (LDBLE))); - if (kinetics_new_ptr->steps == NULL) malloc_error(); - memcpy(kinetics_new_ptr->steps, kinetics_old_ptr->steps, (size_t) count_steps * sizeof (LDBLE)); - } -/* - * Copy kinetic components - */ - if (kinetics_new_ptr->count_comps > 0) { - kinetics_new_ptr->comps = (struct kinetics_comp *) PHRQ_malloc((size_t) kinetics_old_ptr->count_comps * sizeof (struct kinetics_comp)); - if (kinetics_new_ptr->comps == NULL) malloc_error(); - } else { - kinetics_new_ptr->comps = NULL; - } - for (i = 0; i < kinetics_old_ptr->count_comps; i++) { - kinetics_comp_duplicate(&kinetics_new_ptr->comps[i], &kinetics_old_ptr->comps[i]); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies kinetics comp data from kinetics_comp_old_ptr to new location - * Space for the new structure must already be allocated - */ - memcpy(kinetics_comp_new_ptr, kinetics_comp_old_ptr, sizeof (struct kinetics_comp)); -/* - * Kinetics character parameters - */ - if (kinetics_comp_new_ptr->count_c_params > 0) { - kinetics_comp_new_ptr->c_params = (char **) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_c_params) * sizeof (char *)); - if (kinetics_comp_new_ptr->c_params == NULL) malloc_error(); - memcpy(kinetics_comp_new_ptr->c_params, kinetics_comp_old_ptr->c_params, (size_t) (kinetics_comp_old_ptr->count_c_params) * sizeof (char *)); - } else { - kinetics_comp_new_ptr->c_params = NULL; - } -/* - * Kinetics LDBLE parameters - */ - if (kinetics_comp_new_ptr->count_d_params > 0) { - kinetics_comp_new_ptr->d_params = (LDBLE *) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_d_params) * sizeof (LDBLE)); - if (kinetics_comp_new_ptr->d_params == NULL) malloc_error(); - memcpy(kinetics_comp_new_ptr->d_params, kinetics_comp_old_ptr->d_params, (size_t) (kinetics_comp_old_ptr->count_d_params) * sizeof (LDBLE)); - } else { - kinetics_comp_new_ptr->d_params = (LDBLE *) PHRQ_malloc((size_t) sizeof (LDBLE)); - } -/* - * Kinetics list of formulae - */ - if (kinetics_comp_new_ptr->count_list > 0) { - kinetics_comp_new_ptr->list = (struct name_coef *) PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_list) * sizeof (struct name_coef)); - if (kinetics_comp_new_ptr->list == NULL) malloc_error(); - memcpy(kinetics_comp_new_ptr->list, kinetics_comp_old_ptr->list, (size_t) (kinetics_comp_old_ptr->count_list) * sizeof (struct name_coef)); - } else { - kinetics_comp_new_ptr->d_params = NULL; - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int kinetics_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an kinetics definition from position n to position count_kinetics. - * New kinetics structure is given user number n_user. - */ - space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); - kinetics_copy(&kinetics[n], &kinetics[count_kinetics], n_user); - count_kinetics++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array kinetics. - */ -{ - int i; - int n_old; - struct kinetics *kinetics_ptr_old; -/* - * Find n_user_old in structure array - */ - kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); - if (kinetics_ptr_old != NULL) { - /* - * Delete kinetics - */ - kinetics_free(&kinetics[n_old]); - - for(i = n_old + 1; i < count_kinetics; i++) { - memcpy( (void *) &kinetics[i - 1], (void *) &kinetics[i], - (size_t) sizeof (struct kinetics) ); - } - count_kinetics--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies kinetics[n_user_old] to old n_user_new space if - * found or to kinetics[count_kinetics] if not found. - * Kinetics array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct kinetics *kinetics_ptr_old, *kinetics_ptr_new; -/* - * Find n_user_old in structure array kinetics - */ - if (n_user_old == n_user_new) return(OK); - kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); - if (kinetics_ptr_old == NULL) { - sprintf(error_string, "Kinetics %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array kinetics or make new space - */ - sort = FALSE; - kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); - if (kinetics_ptr_new != NULL) { - kinetics_free(kinetics_ptr_new); - } else { - space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); - if (n_user_new < kinetics[count_kinetics-1].n_user) sort = TRUE; - n_new = count_kinetics++; - } -/* - * Copy data - */ - kinetics_copy(&kinetics[n_old], &kinetics[n_new], n_user_new); - if (sort == TRUE) kinetics_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_free (struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Frees all data associated with kinetics structure. - */ - if (kinetics_ptr == NULL) return(ERROR); -/* - * Free space allocated for kinetics structure - */ - for (i = 0; i < kinetics_ptr->count_comps; i++) { - kinetics_ptr->comps[i].c_params = (char **) free_check_null (kinetics_ptr->comps[i].c_params); - kinetics_ptr->comps[i].d_params = (LDBLE *) free_check_null (kinetics_ptr->comps[i].d_params); - kinetics_ptr->comps[i].list = (struct name_coef *) free_check_null (kinetics_ptr->comps[i].list); - } - kinetics_ptr->description = (char *) free_check_null (kinetics_ptr->description); - kinetics_ptr->steps = (LDBLE *) free_check_null (kinetics_ptr->steps); - kinetics_ptr->comps = (struct kinetics_comp *) free_check_null (kinetics_ptr->comps); - kinetics_ptr->totals = (struct elt_list *) free_check_null (kinetics_ptr->totals); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_init (struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ - if (kinetics_ptr == NULL) return(ERROR); - kinetics_ptr->n_user = n_user; - kinetics_ptr->n_user_end = n_user_end; - kinetics_ptr->description = string_duplicate(description); - kinetics_ptr->count_comps = 0; - kinetics_ptr->comps = (struct kinetics_comp *) PHRQ_malloc((size_t) sizeof(struct kinetics_comp)); - if (kinetics_ptr->comps == NULL) malloc_error(); - kinetics_ptr->count_steps = 0; - kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) malloc_error(); - kinetics_ptr->step_divide = 1.0; - /*kinetics_ptr->units = string_hsave("sec");*/ - kinetics_ptr->totals = NULL; - kinetics_ptr->rk = 3; - kinetics_ptr->bad_step_max = 500; - kinetics_ptr->use_cvode = FALSE; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies kinetics_ptr_old to old n_user_new space if - * found or to kinetics[count_kinetics] if not found. - * Kinetics array may not be in sort order after the copy. - */ - int n_new, sort; - struct kinetics *kinetics_ptr_new; -/* - * Find n_user_old in structure array kinetics - */ - if (kinetics_ptr_old == NULL) { - sprintf(error_string, "Kinetics pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array kinetics or make new space - */ - sort = FALSE; - kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); - if (kinetics_ptr_new == kinetics_ptr_old) return(OK); - if (kinetics_ptr_new != NULL) { - kinetics_free(kinetics_ptr_new); - } else { - space ((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, sizeof(struct kinetics)); - if (n_user_new < kinetics[count_kinetics-1].n_user) sort = TRUE; - n_new = count_kinetics++; - } -/* - * Copy data - */ - kinetics_copy(kinetics_ptr_old, &kinetics[n_new], n_user_new); - if (sort == TRUE) kinetics_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct kinetics *kinetics_ptr; - kinetics_ptr = kinetics_alloc(); - kinetics_copy(kinetics_old_ptr, kinetics_ptr, n_user_new); - return (kinetics_ptr); -} -/* ---------------------------------------------------------------------- */ -struct kinetics *kinetics_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Does linear search for user number n_user. - * Returns pointer to kinetics structure and position number, n, - * in kinetics array if found. - * Returns NULL if not found. - */ - int i; - for (i = 0; i < count_kinetics; i++) { - if (n_user == kinetics[i].n_user) { - break; - } - } - if (i >= count_kinetics) { - if ( print == TRUE) { - sprintf(error_string, "Kinetics %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return(NULL); - } - *n = i; - return(&kinetics[i]); -} -/* ---------------------------------------------------------------------- */ -int kinetics_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of kinetics structures - */ - if (count_kinetics > 0) { - qsort (kinetics, (size_t) count_kinetics, (size_t) sizeof(struct kinetics), - kinetics_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "master" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct master *master_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a master structure and initializes the space. - * arguments: void - * return: pointer to a master structure - */ -{ - struct master *ptr; - ptr=(struct master *) PHRQ_malloc(sizeof(struct master)); - if (ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL - */ - ptr->in=FALSE; - ptr->type=0; - ptr->primary=FALSE; - ptr->coef=0.0; - ptr->total=0.0; - ptr->elt=NULL; - ptr->alk = 0.0; - ptr->gfw = 0.0; - ptr->gfw_formula=NULL; - ptr->unknown=NULL; - ptr->s=NULL; - ptr->rxn_primary=NULL; - ptr->rxn_secondary=NULL; - ptr->pe_rxn=NULL; - ptr->minor_isotope = FALSE; - - return(ptr); -} -/* ---------------------------------------------------------------------- */ -int master_delete(char *ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete master species: Free memory of master species structure, free - * the structure, and remove from array master. - * - * Input - * ptr character string with name of element or valence state - * Returns - * TRUE if master species was deleted. - * FALSE if master species was not found. - */ - int j, n; - - if (master_search(ptr, &n) == NULL) return(FALSE); - master_free (master[n]); - for (j=n; j < (count_master - 1); j++) { - master[j] = master[j+1]; - } - count_master--; - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int master_free(struct master *master_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free memory pointed to by master species pointer, master_ptr. - * Frees master_ptr itself. - */ - if (master_ptr == NULL) return(ERROR); - rxn_free (master_ptr->rxn_primary); - rxn_free (master_ptr->rxn_secondary); - master_ptr = (struct master *) free_check_null (master_ptr); - return(OK); -} - -/* ---------------------------------------------------------------------- */ -struct master *master_bsearch (const char *ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Uses binary search. Assumes master is in sort order. - * Find master species for string (*ptr) containing name of element or valence state. - * - * Input: ptr pointer to string containing element name - * - * Return: pointer to master structure containing name ptr or NULL. - */ - void *void_ptr; - if (count_master == 0) { - return(NULL); - } - void_ptr = bsearch ((const char *) ptr, - (char *) master, - (unsigned) count_master, - sizeof(struct master *), - master_compare_string); - if (void_ptr == NULL) { - return(NULL); - } else { - return (* (struct master **) void_ptr); - } -} -/* ---------------------------------------------------------------------- */ -int master_compare_string (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const char *string_ptr; - const struct master *master_ptr; - - string_ptr = (const char *) ptr1; - master_ptr = * (const struct master **) ptr2; - return(strcmp_nocase(string_ptr, master_ptr->elt->name)); -} -/* ---------------------------------------------------------------------- */ -int master_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct master *master_ptr1, *master_ptr2; - master_ptr1 = * (const struct master **) ptr1; - master_ptr2 = * (const struct master **) ptr2; - return(strcmp_nocase(master_ptr1->elt->name, master_ptr2->elt->name)); -} -/* ---------------------------------------------------------------------- */ -struct master *master_bsearch_primary (char *ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Find primary master species for first element in the string, ptr. - * Uses binary search. Assumes master is in sort order. - */ - int l; - char *ptr1; - char elt[MAX_LENGTH]; - struct master *master_ptr_primary; -/* - * Find element name - */ - ptr1=ptr; - get_elt(&ptr1, elt, &l); -/* - * Search master species list - */ - master_ptr_primary=master_bsearch(elt); - if (master_ptr_primary == NULL ) { - input_error++; - sprintf(error_string, "Could not find primary master species for %s.", ptr); - error_msg(error_string, CONTINUE); - } - return(master_ptr_primary); -} -/* ---------------------------------------------------------------------- */ -struct master *master_search (char *ptr, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Linear search of master to find master species in string, ptr. - * Returns pointer if found. n contains position in array master. - * Returns NULL if not found. - */ - int i; - struct master *master_ptr; -/* - * Search master species list - */ - *n = -999; - for (i = 0; i < count_master; i++) { - if (strcmp(ptr, master[i]->elt->name) == 0) { - *n = i; - master_ptr = master[i]; - return(master_ptr); - } - } - return(NULL); -} -/* ********************************************************************** - * - * Routines related to structure "mix" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct mix *mix_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Search mix to find if user mix number k exists. - * Uses binary search, assumes array mix is in sort order. - */ - void *void_ptr; - if (count_mix == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) mix, - (size_t) count_mix, - (size_t) sizeof(struct mix), - mix_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct mix *) void_ptr - mix); - return ( (struct mix *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int mix_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct mix *mix_ptr1, *mix_ptr2; - mix_ptr1 = (const struct mix *) ptr1; - mix_ptr2 = (const struct mix *) ptr2; - if (mix_ptr1->n_user > mix_ptr2->n_user) return(1); - if (mix_ptr1->n_user < mix_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int mix_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare mix user numbers - */ - const int *nptr1; - const struct mix *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct mix *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies mix data from mix_old_ptr to new location, mix_new_ptr. - * Space for the mix_new_ptr structure must already be malloced. - * Space for mix components is malloced here. - */ - char token[MAX_LENGTH]; -/* - * Copy old to new - */ - memcpy(mix_new_ptr, mix_old_ptr, sizeof (struct mix)); -/* - * Store data for structure mix - */ - mix_new_ptr->n_user = n_user_new; - mix_new_ptr->n_user_end = n_user_new; - sprintf(token, "Mix defined in simulation %d.", simulation); - mix_new_ptr->description = string_duplicate(token); -/* - * Count mix components and allocate space - */ - mix_new_ptr->comps = (struct mix_comp *) PHRQ_malloc((size_t) (mix_old_ptr->count_comps) * sizeof (struct mix_comp)); - if (mix_new_ptr->comps == NULL) malloc_error(); - memcpy(mix_new_ptr->comps, mix_old_ptr->comps, - (size_t) (mix_old_ptr->count_comps) * sizeof (struct mix_comp)); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mix_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies mix[n_user_old] to old n_user_new space if - * found or to mix[count_mix] if not found. - * Mix array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - char token[MAX_LENGTH]; - int count_comps; - struct mix *mix_ptr_old, *mix_ptr_new; -/* - * Find n_user_old in structure array mix or make new space - */ - if (n_user_old == n_user_new) return(OK); - mix_ptr_old = mix_bsearch(n_user_old, &n_old); - if (mix_ptr_old == NULL) { - sprintf(error_string, "Mix %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_old in structure array mix or make new space - */ - sort = FALSE; - mix_ptr_new = mix_bsearch(n_user_new, &n_new); - if (mix_ptr_new != NULL) { - mix_free (&(mix[n_new])); - } else { - mix = (struct mix *) PHRQ_realloc( mix, (size_t) (count_mix + 1) *sizeof (struct mix)); - if (mix == NULL) malloc_error(); - if (n_user_new < mix[count_mix - 1].n_user) sort = TRUE; - n_new = count_mix++; - } -/* - * Store data for structure mix - */ - memcpy(&mix[n_new], &mix[n_old], sizeof(struct mix)); - count_comps = mix[n_old].count_comps; - mix[n_new].n_user = n_user_new; - mix[n_new].n_user_end = n_user_new; - sprintf(token, "Mix defined in simulation %d.", simulation); - mix[n_new].description = string_duplicate(token); -/* - * Count mix components and allocate space - */ - mix[n_new].comps = (struct mix_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct mix_comp)); - if (mix[n_new].comps == NULL) malloc_error(); -/* - * Write mix_comp structure for each mix component - */ - memcpy(mix[n_new].comps, mix[n_old].comps, - (size_t) (count_comps) * sizeof (struct mix_comp)); - if (sort == TRUE) mix_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int mix_free (struct mix *mix_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for mixture structure. - */ - if (mix_ptr == NULL) return(ERROR); - - mix_ptr->description = (char *) free_check_null (mix_ptr->description); - mix_ptr->comps = (struct mix_comp *) free_check_null (mix_ptr->comps); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct mix *mix_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Linear search of mix array for user number n_user. - * Returns pointer to mix structure if found, n is set to position in mix array. - * Returns NULL if not found. - */ - int i; - for (i = 0; i < count_mix; i++) { - if (n_user == mix[i].n_user) { - break; - } - } - if (i >= count_mix) { - if ( print == TRUE) { - sprintf(error_string, "Mix %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return(NULL); - } - *n = i; - return(&mix[i]); -} -/* ---------------------------------------------------------------------- */ -int mix_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of mix structures - */ - if (count_mix > 0) { - qsort (mix, (size_t) count_mix, (size_t) sizeof(struct mix), - mix_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "pe_data" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct pe_data *pe_data_alloc(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocate and initialize an array of struct pe_data - */ - struct pe_data *pe_data_ptr; - char token[MAX_LENGTH]; - - pe_data_ptr = (struct pe_data *) PHRQ_malloc( (size_t) (2 * sizeof (struct pe_data))); - if (pe_data_ptr == NULL) malloc_error(); - pe_data_ptr[0].name = pe_string; - if (s_eminus != NULL && s_eminus->rxn != NULL) { - pe_data_ptr[0].rxn = rxn_dup(s_eminus->rxn); - } else { - pe_data_ptr[0].rxn = rxn_alloc(3); - if (pe_data_ptr[0].rxn == NULL) malloc_error(); - strcpy(token,"e-"); - s_eminus = s_store(token, -1.0, FALSE); - pe_data_ptr[0].rxn->token[0].s = s_eminus; - pe_data_ptr[0].rxn->token[0].coef = -1.0; - pe_data_ptr[0].rxn->token[1].s = s_eminus; - pe_data_ptr[0].rxn->token[1].coef = -1.0; - pe_data_ptr[0].rxn->token[2].s = NULL; - } - pe_data_ptr[1].name = NULL; - pe_data_ptr[1].rxn = NULL; - - return (pe_data_ptr); -} -/* ---------------------------------------------------------------------- */ -struct pe_data *pe_data_dup (struct pe_data *pe_ptr_old) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocate space and copy data from pe_ptr_old into the new space. - * Returns pointer to new space. - */ - int i, count_pe; - struct pe_data *pe_ptr_new; -/* - * Count pe data and copy into new structure - */ - if (pe_ptr_old == NULL) return(ERROR); - for (i = 0; pe_ptr_old[i].name != NULL; i++); - count_pe = i + 1; - pe_ptr_new = (struct pe_data *) PHRQ_malloc( (size_t) count_pe * sizeof(struct pe_data)); - if (pe_ptr_new == NULL) malloc_error(); - memcpy ( (void *) pe_ptr_new, (void *) pe_ptr_old, (size_t) count_pe * sizeof(struct pe_data) ); - for (i = 0; i < count_pe - 1; i++) { - pe_ptr_new[i].rxn = rxn_dup(pe_ptr_old[i].rxn); - } - pe_ptr_new[count_pe - 1].rxn = NULL; - return(pe_ptr_new); -} -/* ---------------------------------------------------------------------- */ -int pe_data_free (struct pe_data *pe_data_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all data for pe_data_ptr, including pe_data_ptr. - */ - int i; - - if ( pe_data_ptr == NULL ) return(ERROR); - for (i=0; pe_data_ptr[i].name != NULL; i++) { - rxn_free(pe_data_ptr[i].rxn); - } - pe_data_ptr = (struct pe_data *) free_check_null (pe_data_ptr); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pe_data_store (struct pe_data **pe, const char *token) -/* ---------------------------------------------------------------------- */ -{ -/* - * Find pe name in current list of pe_data structures - * or allocate new pe_data structure - */ - int i; - struct pe_data *pe_data_ptr; -/* - * Search for pe in list - */ - pe_data_ptr = *pe; - for (i=0; pe_data_ptr[i].name != NULL; i++) { - if (strcmp (token, pe_data_ptr[i].name ) == 0 ) { - return (i); - } - } -/* - * Save new struct pe_data in array - */ - *pe = (struct pe_data *) PHRQ_realloc( (void *) *pe, (size_t) (i+2) * sizeof(struct pe_data)); - if (*pe == NULL) malloc_error(); - pe_data_ptr = *pe; - pe_data_ptr[i].name = string_hsave ( token ); - pe_data_ptr[i].rxn = NULL; - pe_data_ptr[i + 1].name = NULL; - return ( i ); -} - -/* ********************************************************************** - * - * Routines related to structure "phases" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct phase *phase_alloc(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocates space to a phase structure and initializes - * arguments: void - * return: pointer to new phase structure - */ - struct phase *phase_ptr; -/* - * Allocate space - */ - phase_ptr=(struct phase *) PHRQ_malloc(sizeof(struct phase)); - if (phase_ptr == NULL) malloc_error(); -/* - * Initialize space - */ - phase_init(phase_ptr); - return(phase_ptr); -} -/* ---------------------------------------------------------------------- */ -int phase_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compares names of phases for sort - */ - const struct phase *phase_ptr1, *phase_ptr2; - phase_ptr1 = * (const struct phase **) ptr1; - phase_ptr2 = * (const struct phase **) ptr2; - return(strcmp_nocase(phase_ptr1->name, phase_ptr2->name)); -} -/* ---------------------------------------------------------------------- */ -int phase_compare_string (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const char *char_ptr; - const struct phase *phase_ptr; - char_ptr = (const char *) ptr1; - phase_ptr = * (const struct phase **) ptr2; - return(strcmp_nocase(char_ptr, phase_ptr->name)); -} -/* ---------------------------------------------------------------------- */ -int phase_delete(int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Deletes phase i from list, phases - * Frees memory allocated to phase[i] and renumbers phases to remove number i. - * Input: i, number of phase - * Return: OK - */ - int j; - - phase_free(phases[i]); - phases[i] = (struct phase *) free_check_null(phases[i]); - for (j=i; j < (count_phases - 1); j++) { - phases[j]=phases[j+1]; - } - count_phases--; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int phase_free(struct phase *phase_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees memory allocated within phase[i], does not free phase structure - * Input: i, number of phase - * Return: OK - */ - if (phase_ptr == NULL) return(ERROR); - phase_ptr->next_elt = (struct elt_list *) free_check_null (phase_ptr->next_elt); - phase_ptr->next_sys_total = (struct elt_list *) free_check_null (phase_ptr->next_sys_total); - rxn_free (phase_ptr->rxn); - rxn_free (phase_ptr->rxn_s); - rxn_free (phase_ptr->rxn_x); - phase_ptr->add_logk = (struct name_coef *) free_check_null (phase_ptr->add_logk); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct phase *phase_bsearch (char *ptr, int *j, int print) -/* ---------------------------------------------------------------------- */ -{ -/* Binary search the structure array "phases" for a name that is equal to - * ptr. Assumes array phases is in sort order. - * - * Arguments: - * name input, a character string to be located in phases. - * j index number in array phases. - * - * Returns: - * if found, pointer to phase structure. - * if not found, NULL - * - */ - void *void_ptr; - - void_ptr = NULL; - if (count_phases > 0) { - void_ptr = (void *) - bsearch ( (char *) ptr, - (char *) phases, - (size_t) count_phases, - (size_t) sizeof(struct phase *), - phase_compare_string); - } - if (void_ptr == NULL && print == TRUE) { - sprintf(error_string, "Could not find phase in list, %s.", ptr); - error_msg(error_string, CONTINUE); - } - - if (void_ptr == NULL) { - *j = -1; - return(NULL); - } - - *j = (int) ((struct phase **) void_ptr - phases); - return (* (struct phase **) void_ptr); -} -/* ---------------------------------------------------------------------- */ -static int phase_init(struct phase *phase_ptr) -/* ---------------------------------------------------------------------- */ -/* - * set pointers in phase structure to NULL - */ -{ - int i; - - phase_ptr->name=NULL; - phase_ptr->formula=NULL; - phase_ptr->in = FALSE; - phase_ptr->lk = 0.0; - for (i = 0; i < 8; i++) phase_ptr->logk[i]=0.0; - phase_ptr->type = SOLID; - phase_ptr->check_equation = TRUE; - phase_ptr->next_elt = NULL; - phase_ptr->next_sys_total = NULL; - phase_ptr->rxn = NULL; - phase_ptr->rxn_s = NULL; - phase_ptr->rxn_x = NULL; - phase_ptr->add_logk = NULL; - phase_ptr->count_add_logk = 0; - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct phase *phase_store (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for phases. - * - * If found, pointer to the appropriate phase structure is returned. - * - * If the string is not found, a new entry is made at the end of - * the phases array (position count_phases) and count_phases is - * incremented. A new entry is made in the hash table. Pointer to - * the new structure is returned. - * - * Arguments: - * name input, character string to be located or stored. - * - * Returns: - * The address of a phase structure that contains the phase data. - * If phase existed, it is reinitialized. The structure returned - * contains only the name of the phase. - */ - int n; - struct phase *phase_ptr; - ENTRY item, *found_item; - char token[MAX_LENGTH]; - char *ptr; -/* - * Search list - */ - - strcpy(token, name); - str_tolower(token); - ptr = string_hsave(token); - - item.key = ptr; - item.data = NULL; - found_item = hsearch_multi(phases_hash_table, item, FIND); - if (found_item != NULL) { - phase_ptr = (struct phase *) (found_item->data); - phase_free (phase_ptr); - phase_init (phase_ptr); - phase_ptr->name = string_hsave( name ); - return (phase_ptr); - } -/* - * Make new phase structure and return pointer to it - */ - /* make sure there is space in phases */ - n = count_phases++; - if (count_phases >= max_phases) { - space ((void **) ((void *) &phases), count_phases, &max_phases, sizeof(struct phase *)); - } - phases[n]=phase_alloc(); - /* set name in phase structure */ - phases[n]->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = ptr; - item.data = (void *) phases[n]; - found_item = hsearch_multi(phases_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in phase_store."); - error_msg(error_string, CONTINUE); - } - - return (phases[n]); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -struct phase *phase_search (char *ptr, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Linear search of phases to find phase with name in ptr. - * Returns pointer if found. n contains position in array master. - * Returns NULL if not found. - */ - int i; - struct phase *phase_ptr; -/* - * Search phases list - */ - *n = -999; - for (i = 0; i < count_phases; i++) { - if (strcmp_nocase(ptr, phases[i]->name) == 0) { - *n = i; - phase_ptr = phases[i]; - return(phase_ptr); - } - } - return(NULL); -} -/* ---------------------------------------------------------------------- */ -struct phase *phase_store (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for phases. - * - * If found, pointer to the appropriate phase structure is returned. - * - * If the string is not found, a new entry is made at the end of - * the phases array (position count_phases) and count_phases is - * incremented. A new entry is made in the hash table. Pointer to - * the new structure is returned. - * - * Arguments: - * name input, character string to be located or stored. - * - * Returns: - * The address of a phase structure that contains the phase data. - * If phase existed, it is reinitialized. The structure returned - * contains only the name of the phase. - */ - int n; - struct phase *phase_ptr; -/* - * Search list - */ - phase_ptr = phase_search(name, &n); - if (phase_ptr != NULL) { - phase_free (phase_ptr); - phase_init (phase_ptr); - phase_ptr->name = string_hsave( name ); - return (phase_ptr); - } -/* - * Make new phase structure and return pointer to it - */ - /* make sure there is space in phases */ - n = count_phases++; - if (count_phases >= max_phases) { - space ((void **) &phases, count_phases, &max_phases, sizeof(struct phase *)); - } - phases[n]=phase_alloc(); - /* set name in phase structure */ - phases[n]->name = string_hsave( name ); - return (phases[n]); -} -#endif -/* ********************************************************************** - * - * Routines related to structure "pp_assemblage" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct pp_assemblage *pp_assemblage_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct pp_assemblage *pp_assemblage_ptr; - pp_assemblage_ptr = (struct pp_assemblage *) PHRQ_malloc(sizeof (struct pp_assemblage)); - if (pp_assemblage_ptr == NULL) malloc_error(); - pp_assemblage_ptr->description = NULL; - pp_assemblage_ptr->next_elt = NULL; - pp_assemblage_ptr->count_comps = 0; - pp_assemblage_ptr->pure_phases = NULL; - return ( pp_assemblage_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct pp_assemblage *pp_assemblage_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array pp_assemblage to find user number k. - * Assumes pp_assemblage is in sort order. - * - * Input: k, user number to find. - * - * Output: n, position in array pp_assemblage for user number k. - * - * Return: pointer to pp_assemblage structure for user number k, if found. - * NULL if not found. - */ - void *void_ptr; - if (count_pp_assemblage == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) pp_assemblage, - (size_t) count_pp_assemblage, - (size_t) sizeof(struct pp_assemblage), - pp_assemblage_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct pp_assemblage *) void_ptr - pp_assemblage); - return ( (struct pp_assemblage *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct pp_assemblage *pp_assemblage_ptr1, *pp_assemblage_ptr2; - pp_assemblage_ptr1 = (const struct pp_assemblage *) ptr1; - pp_assemblage_ptr2 = (const struct pp_assemblage *) ptr2; - if (pp_assemblage_ptr1->n_user > pp_assemblage_ptr2->n_user) return(1); - if (pp_assemblage_ptr1->n_user < pp_assemblage_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare pp_assemblage user numbers - */ - const int *nptr1; - const struct pp_assemblage *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct pp_assemblage *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies pp_assemblage data from pp_assemblage_old_ptr to pp_assemblage_new_ptr. - * Space for a pp_assemblage_new_ptr must already be malloced. - * Space for list of pure phases in assemblage is malloced here. - */ - int count_comps; - char token[MAX_LENGTH]; -/* - * Store data for structure pp_assemblage - */ - pp_assemblage_new_ptr->n_user = n_user_new; - pp_assemblage_new_ptr->n_user_end = n_user_new; - pp_assemblage_new_ptr->new_def = pp_assemblage_old_ptr->new_def; - sprintf(token, "Pp_Assemblage defined in simulation %d.", simulation); - pp_assemblage_new_ptr->description = string_duplicate(token); - pp_assemblage_new_ptr->next_elt = elt_list_dup(pp_assemblage_old_ptr->next_elt); -/* - * Count pure phases - */ - count_comps = pp_assemblage_old_ptr->count_comps; - pp_assemblage_new_ptr->count_comps = count_comps; -/* - * Malloc space and copy - */ - pp_assemblage_new_ptr->pure_phases = (struct pure_phase *) PHRQ_malloc( (size_t) count_comps * sizeof(struct pure_phase)); - if (pp_assemblage_new_ptr->pure_phases == NULL) malloc_error(); - - memcpy( (void *) pp_assemblage_new_ptr->pure_phases, - (void *) pp_assemblage_old_ptr->pure_phases, - (size_t) count_comps * sizeof(struct pure_phase) ); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an pp_assemblage definition from position n - * to position count_pp_assemblage. - */ - space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); - pp_assemblage_copy(&pp_assemblage[n], &pp_assemblage[count_pp_assemblage], n_user); - count_pp_assemblage++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies pp_assemblage[n_user_old] to old n_user_new space if - * found or to pp_assemblage[count_pp_assemblage] if not found. - * Pp_Assemblage array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct pp_assemblage *pp_assemblage_ptr_old, *pp_assemblage_ptr_new; -/* - * Find n_user_old in structure array pp_assemblage - */ - if (n_user_old == n_user_new) return(OK); - pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); - if (pp_assemblage_ptr_old == NULL) { - sprintf(error_string, "Pp_Assemblage %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array pp_assemblage or make new space - */ - sort = FALSE; - pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); - if (pp_assemblage_ptr_new != NULL) { - pp_assemblage_free(pp_assemblage_ptr_new); - } else { - space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); - if (n_user_new < pp_assemblage[count_pp_assemblage-1].n_user) sort = TRUE; - n_new = count_pp_assemblage++; - } -/* - * Copy data - */ - pp_assemblage_copy(&pp_assemblage[n_old], &pp_assemblage[n_new], n_user_new); - if (sort == TRUE) pp_assemblage_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array pp_assemblage. - */ -{ - int i; - int n_old; - struct pp_assemblage *pp_assemblage_ptr_old; -/* - * Find n_user_old in structure array - */ - pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); - if (pp_assemblage_ptr_old != NULL) { - /* - * Delete pp_assemblage - */ - pp_assemblage_free(&pp_assemblage[n_old]); - - for(i = n_old + 1; i < count_pp_assemblage; i++) { - memcpy( (void *) &pp_assemblage[i - 1], (void *) &pp_assemblage[i], - (size_t) sizeof (struct pp_assemblage) ); - } - count_pp_assemblage--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_free (struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for pp_assemblage structure - */ - if (pp_assemblage_ptr == NULL) return(ERROR); - - pp_assemblage_ptr->description = (char *) free_check_null (pp_assemblage_ptr->description); - pp_assemblage_ptr->next_elt = (struct elt_list *) free_check_null (pp_assemblage_ptr->next_elt); - pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null (pp_assemblage_ptr->pure_phases); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_init (struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides initial values for a new pp_assemblage - * arguments: - * n position in array pp_assemblage - * n_user user number for pp_assemblage - * return: OK - */ - pp_assemblage_ptr->n_user = n_user; - pp_assemblage_ptr->n_user_end = n_user_end; - pp_assemblage_ptr->new_def = TRUE; - pp_assemblage_ptr->description = string_duplicate(description); - - pp_assemblage_ptr->next_elt = NULL; - pp_assemblage_ptr->count_comps = 0; - pp_assemblage_ptr->pure_phases = (struct pure_phase *) PHRQ_malloc((size_t) sizeof(struct pure_phase)); - if (pp_assemblage_ptr->pure_phases == NULL) malloc_error(); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies pp_assemblage_ptr_old to old n_user_new space if - * found or to pp_assemblage[count_pp_assemblage] if not found. - * Pp_Assemblage array may not be in sort order after the copy. - */ - int n_new, sort; - struct pp_assemblage *pp_assemblage_ptr_new; -/* - * Find n_user_old in structure array pp_assemblage - */ - if (pp_assemblage_ptr_old == NULL) { - sprintf(error_string, "Pp_Assemblage pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array pp_assemblage or make new space - */ - sort = FALSE; - pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); - if (pp_assemblage_ptr_new == pp_assemblage_ptr_old) return(OK); - if (pp_assemblage_ptr_new != NULL) { - pp_assemblage_free(pp_assemblage_ptr_new); - } else { - space ((void **) ((void *) &pp_assemblage), count_pp_assemblage, &max_pp_assemblage, sizeof(struct pp_assemblage)); - if (n_user_new < pp_assemblage[count_pp_assemblage-1].n_user) sort = TRUE; - n_new = count_pp_assemblage++; - } -/* - * Copy data - */ - pp_assemblage_copy(pp_assemblage_ptr_old, &pp_assemblage[n_new], n_user_new); - if (sort == TRUE) pp_assemblage_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct pp_assemblage *pp_assemblage_ptr; - pp_assemblage_ptr = pp_assemblage_alloc(); - pp_assemblage_copy(pp_assemblage_old_ptr, pp_assemblage_ptr, n_user_new); - return (pp_assemblage_ptr); -} -/* ---------------------------------------------------------------------- */ -struct pp_assemblage *pp_assemblage_search (int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "pp_assemblage" for user number n_user. - * - * Arguments: - * n_user input, user number - * n output, position in pp_assemblage - * - * Returns: - * if found, the address of the pp_assemblage element - * if not found, NULL - */ - int i; - for (i=0; i < count_pp_assemblage; i++) { - if ( pp_assemblage[i].n_user == n_user) { - *n = i; - return (&(pp_assemblage[i])); - } - } -/* - * Pp_Assemblage not found - */ - return (NULL); -} -/* ---------------------------------------------------------------------- */ -int pp_assemblage_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of pp_assemblage structures - */ - if (count_pp_assemblage > 0) { - qsort (pp_assemblage, (size_t) count_pp_assemblage, (size_t) sizeof(struct pp_assemblage), - pp_assemblage_compare); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int pure_phase_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct pure_phase *pure_phase_ptr1, *pure_phase_ptr2; - pure_phase_ptr1 = (const struct pure_phase *) ptr1; - pure_phase_ptr2 = (const struct pure_phase *) ptr2; - return(strcmp_nocase(pure_phase_ptr1->name, pure_phase_ptr2->name)); - -} -/* ********************************************************************** - * - * Routines related to structure "rates" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct rate *rate_bsearch (char *ptr, int *j) -/* ---------------------------------------------------------------------- */ -{ -/* Binary search the structure array "rates" for a name that is equal to - * ptr. Assumes array rates is in sort order. - * - * Arguments: - * name input, a character string to be located in rates. - * j index number in array rates. - * - * Returns: - * if found, pointer to rate structure. - * if not found, NULL - * - */ - void *void_ptr; - - if (count_rates == 0) { - *j = -1; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) ptr, - (char *) rates, - (size_t) count_rates, - (size_t) sizeof(struct rate *), - rate_compare_string); - - if (void_ptr == NULL) { - *j = -1; - return(NULL); - } - - *j = (int) ((struct rate *) void_ptr - rates); - return ((struct rate *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int rate_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compares names of rates for sort - */ - const struct rate *rate_ptr1, *rate_ptr2; - rate_ptr1 = * (const struct rate **) ptr1; - rate_ptr2 = * (const struct rate **) ptr2; - return(strcmp_nocase(rate_ptr1->name, rate_ptr2->name)); -} -/* ---------------------------------------------------------------------- */ -int rate_compare_string (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const char *char_ptr; - const struct rate *rate_ptr; - char_ptr = (const char *) ptr1; - rate_ptr = * (const struct rate **) ptr2; - return(strcmp_nocase(char_ptr, rate_ptr->name)); -} -/* ---------------------------------------------------------------------- */ -int rate_free(struct rate *rate_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees memory allocated within rate[i], does not free rate structure - * Input: i, number of rate - * Return: OK - */ - char cmd[] = "new; quit"; - - if (rate_ptr == NULL) return(ERROR); - rate_ptr->commands = (char *) free_check_null(rate_ptr->commands); - basic_run(cmd, rate_ptr->linebase, rate_ptr->varbase, rate_ptr->loopbase); - rate_ptr->linebase = NULL; - rate_ptr->varbase = NULL; - rate_ptr->loopbase = NULL; - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct rate *rate_search (char *name, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "rates" for name. - * - * Arguments: - * name input, name of rate - * n output, position in rates - * - * Returns: - * if found, the address of the pp_assemblage element - * if not found, NULL - */ - int i; - *n = -1; - for (i=0; i < count_rates; i++) { - if ( strcmp_nocase(rates[i].name, name) == 0) { - *n = i; - return (&(rates[i])); - } - } -/* - * rate name not found - */ - return (NULL); -} -/* ---------------------------------------------------------------------- */ -int rate_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of rate structures - */ - if (count_rates > 0) { - qsort (rates, (size_t) count_rates, (size_t) sizeof(struct rate), - rate_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "reaction", balanced chemical reactions - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct reaction *rxn_alloc(int ntokens) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Allocates space to a rxn structure - * input: ntokens, number of tokens in reaction - * return: pointer to a species structure - */ - struct reaction *rxn_ptr; -/* - * Malloc reaction structure - */ - rxn_ptr=(struct reaction *) PHRQ_malloc(sizeof(struct reaction)); - if (rxn_ptr == NULL) malloc_error(); -/* - * zero log k data - */ - for (i = 0; i < 7; i++) { - rxn_ptr->logk[i] = 0.0; - } -/* - * Malloc rxn_token structure - */ - rxn_ptr->token = (struct rxn_token *) PHRQ_malloc((size_t) ntokens*sizeof(struct rxn_token)); - if (rxn_ptr->token == NULL) malloc_error(); - return(rxn_ptr); -} -/* ---------------------------------------------------------------------- */ -struct reaction *rxn_dup(struct reaction *rxn_ptr_old) -/* ---------------------------------------------------------------------- */ -{ -/* - * mallocs space for a reaction and copies the reaction - * input: rxn_ptr_old, pointer to a reaction structure to copy - * - * Return: rxn_ptr_new, pointer to duplicated structure to copy - */ - int i; - struct reaction *rxn_ptr_new; - - if (rxn_ptr_old == NULL) return(NULL); - for (i = 0; rxn_ptr_old->token[i].s != NULL; i++); - - rxn_ptr_new = rxn_alloc( i + 1); -/* - * Copy logk data - */ - memcpy (rxn_ptr_new->logk, rxn_ptr_old->logk, (size_t) 7 * sizeof (LDBLE)); -/* - * Copy tokens - */ - memcpy (rxn_ptr_new->token, rxn_ptr_old->token, (size_t) (i + 1) * sizeof (struct rxn_token)); - - return(rxn_ptr_new); -} -/* ---------------------------------------------------------------------- */ -LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Finds coefficient of token in reaction. - * input: r_ptr, pointer to a reaction structure - * str, string to find as reaction token - * - * Return: 0.0, if token not found - * coefficient of token, if found. - */ - struct rxn_token *r_token; - LDBLE coef; - - r_token=r_ptr->token + 1; - coef=0.0; - while (r_token->s != NULL) { - if (strcmp(r_token->s->name, str) == 0) { - coef=r_token->coef; - break; - } - r_token++; - } - return(coef); -} -/* ---------------------------------------------------------------------- */ -int rxn_free(struct reaction *rxn_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees space allocated for a reaction structure - * input: rxn_ptr, pointer to reaction structure - * return: ERROR, if pointer is NULL - * OK, otherwise. - */ - if (rxn_ptr == NULL) return(ERROR); - rxn_ptr->token = (struct rxn_token *) free_check_null (rxn_ptr->token); - rxn_ptr = (struct reaction *) free_check_null (rxn_ptr); - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "species" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct species *s_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a species structure, initializes - * arguments: void - * return: pointer to a species structure - */ -{ - struct species *s_ptr; - s_ptr=(struct species *) PHRQ_malloc(sizeof(struct species)); - if (s_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - s_init(s_ptr); - - return(s_ptr); -} -/* ---------------------------------------------------------------------- */ -int s_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct species *s_ptr1, *s_ptr2; - s_ptr1 = * (const struct species **) ptr1; - s_ptr2 = * (const struct species **) ptr2; - return(strcmp(s_ptr1->name, s_ptr2->name)); - -} -/* ---------------------------------------------------------------------- */ -int s_delete (int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete species i: free memory and renumber array of pointers, s. - */ - int j; - - s_free (s[i]); - s[i] = (struct species *) free_check_null(s[i]); - for (j=i; j < (count_s - 1); j++) { - s[j]=s[j+1]; - } - count_s--; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_free (struct species *s_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for species structure, s_ptr. Does not free s_ptr. - */ - if (s_ptr == NULL) return(ERROR); - s_ptr->next_elt = (struct elt_list *) free_check_null (s_ptr->next_elt); - s_ptr->next_secondary = (struct elt_list *) free_check_null (s_ptr->next_secondary); - s_ptr->next_sys_total = (struct elt_list *) free_check_null (s_ptr->next_sys_total); - s_ptr->add_logk = (struct name_coef *) free_check_null(s_ptr->add_logk); - rxn_free (s_ptr->rxn); - rxn_free (s_ptr->rxn_s); - rxn_free (s_ptr->rxn_x); - s_ptr->diff_layer = (struct species_diff_layer *) free_check_null (s_ptr->diff_layer); - return(OK); -} -/* ---------------------------------------------------------------------- */ -static int s_init(struct species *s_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a species structure - */ -{ - int i; -/* - * set pointers in structure to NULL - */ - s_ptr->name=NULL; - s_ptr->mole_balance=NULL; - s_ptr->primary=NULL; - s_ptr->secondary=NULL; - s_ptr->next_elt=NULL; - s_ptr->next_secondary=NULL; - s_ptr->next_sys_total=NULL; - s_ptr->rxn=NULL; - s_ptr->rxn_s=NULL; - s_ptr->rxn_x=NULL; - s_ptr->diff_layer = NULL; -/* - * set varibles = 0 - */ - s_ptr->in = FALSE; - s_ptr->gfw = 0.0; - s_ptr->z = 0.0; - s_ptr->alk = 0.0; - s_ptr->carbon = 0.0; - s_ptr->co2 = 0.0; - s_ptr->h = 0.0; - s_ptr->o = 0.0; - s_ptr->dha = 0.0; - s_ptr->dhb = 0.0; - s_ptr->lk = 0.0; - for (i =0; i < 8; i++) { - s_ptr->logk[i] = 0.0; - } - s_ptr->count_add_logk = 0; - s_ptr->add_logk = NULL; - s_ptr->lg = 0.0; - s_ptr->lm = 0.0; - s_ptr->la = 0.0; - s_ptr->dg = 0.0; - s_ptr->moles = 0.0; - s_ptr->type = 0; - s_ptr->gflag = 0; - s_ptr->check_equation = TRUE; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct species *s_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for species. - * - * Arguments: - * name input, a character string to be located in species. - * i is obsolete. - * - * Returns: - * If found, pointer to the appropriate species structure is returned. - * else, NULL pointer is returned. - */ - struct species *s_ptr; - ENTRY item, *found_item; - - item.key = name; - item.data = NULL; - found_item = hsearch_multi(species_hash_table, item, FIND); - if (found_item != NULL) { - s_ptr = (struct species *) (found_item->data); - return (s_ptr); - } - return (NULL); -} -/* ---------------------------------------------------------------------- */ -struct species *s_store (char *name, LDBLE z, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for species. - * - * Pointer to a species structure is always returned. - * - * If the string is not found, a new entry is made at the end of - * the elements array (position count_elements) and count_elements is - * incremented. A new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old species structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old species structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "species". - * z input, charge on "name" - * replace_if_found input, TRUE means reinitialize species if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to species structure "s" where "name" can be found. - */ - int n; - struct species *s_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - item.key = name; - item.data = NULL; - found_item = hsearch_multi(species_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - s_ptr = (struct species *) (found_item->data); - return (s_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - s_ptr = (struct species *) (found_item->data); - s_free(s_ptr); - s_init(s_ptr); - } else { - n = count_s++; - /* make sure there is space in s */ - if (count_s >= max_s) { - space ((void **) ((void *) &s), count_s, &max_s, sizeof(struct species *)); - } - /* Make new species structure */ - s[n] = s_alloc(); - s_ptr = s[n]; - } - /* set name and z in pointer in species structure */ - s_ptr->name = string_hsave( name ); - s_ptr->z = z; -/* - * Update hash table - */ - item.key = s_ptr->name; - item.data = (void *) s_ptr; - found_item = hsearch_multi(species_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in species_store."); - error_msg(error_string, CONTINUE); - } - - return (s_ptr); -} -/* ********************************************************************** - * - * Routines related to structure "s_s_assemblage" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct s_s_assemblage *s_s_assemblage_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct s_s_assemblage *s_s_assemblage_ptr; - s_s_assemblage_ptr = (struct s_s_assemblage *) PHRQ_malloc(sizeof (struct s_s_assemblage)); - if (s_s_assemblage_ptr == NULL) malloc_error(); - s_s_assemblage_ptr->description = NULL; - s_s_assemblage_ptr->count_s_s = 0; - s_s_assemblage_ptr->s_s = NULL; - return ( s_s_assemblage_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct s_s_assemblage *s_s_assemblage_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array s_s_assemblage to find user number k. - * Assumes s_s_assemblage is in sort order. - * - * Input: k, user number to find. - * - * Output: n, position in array s_s_assemblage for user number k. - * - * Return: pointer to s_s_assemblage structure for user number k, if found. - * NULL if not found. - */ - void *void_ptr; - if (count_s_s_assemblage == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) s_s_assemblage, - (size_t) count_s_s_assemblage, - (size_t) sizeof(struct s_s_assemblage), - s_s_assemblage_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct s_s_assemblage *) void_ptr - s_s_assemblage); - return ( (struct s_s_assemblage *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct s_s_assemblage *s_s_assemblage_ptr1, *s_s_assemblage_ptr2; - s_s_assemblage_ptr1 = (const struct s_s_assemblage *) ptr1; - s_s_assemblage_ptr2 = (const struct s_s_assemblage *) ptr2; - if (s_s_assemblage_ptr1->n_user > s_s_assemblage_ptr2->n_user) return(1); - if (s_s_assemblage_ptr1->n_user < s_s_assemblage_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare s_s_assemblage user numbers - */ - const int *nptr1; - const struct s_s_assemblage *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct s_s_assemblage *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies s_s_assemblage data from s_s_assemblage_old_ptr to s_s_assemblage_new_ptr. - * Space for a s_s_assemblage_new_ptr must already be malloced. - * Space for list of pure phases in assemblage is malloced here. - */ - int i, count_comps, count_s_s; - char token[MAX_LENGTH]; -/* - * Store data for structure s_s_assemblage - */ - memcpy(s_s_assemblage_new_ptr, s_s_assemblage_old_ptr, sizeof(struct s_s_assemblage)); - s_s_assemblage_new_ptr->n_user = n_user_new; - s_s_assemblage_new_ptr->n_user_end = n_user_new; - sprintf(token, "S_S_Assemblage defined in simulation %d.", simulation); - s_s_assemblage_new_ptr->description = string_duplicate(token); - s_s_assemblage_new_ptr->new_def = FALSE; -/* - * Malloc space for s_s structures and fill - */ - count_s_s = s_s_assemblage_old_ptr->count_s_s; - s_s_assemblage_new_ptr->s_s = (struct s_s *) PHRQ_malloc( (size_t) count_s_s * sizeof(struct s_s)); - if (s_s_assemblage_new_ptr->s_s == NULL) malloc_error(); - memcpy( (void *) s_s_assemblage_new_ptr->s_s, - (void *) s_s_assemblage_old_ptr->s_s, - (size_t) count_s_s * sizeof(struct s_s) ); -/* - * Malloc space for components - */ - for (i = 0; i < count_s_s; i++) { - count_comps = s_s_assemblage_old_ptr->s_s[i].count_comps; - s_s_assemblage_new_ptr->s_s[i].comps = (struct s_s_comp *) PHRQ_malloc( (size_t) count_comps * sizeof(struct s_s_comp)); - if (s_s_assemblage_new_ptr->s_s[i].comps == NULL) malloc_error(); - memcpy( (void *) s_s_assemblage_new_ptr->s_s[i].comps, - (void *) s_s_assemblage_old_ptr->s_s[i].comps, - (size_t) count_comps * sizeof(struct s_s_comp) ); - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an s_s_assemblage definition from position n - * to position count_s_s_assemblage. - */ - space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - s_s_assemblage_copy(&s_s_assemblage[n], &s_s_assemblage[count_s_s_assemblage], n_user); - count_s_s_assemblage++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies s_s_assemblage[n_user_old] to old n_user_new space if - * found or to s_s_assemblage[count_s_s_assemblage] if not found. - * S_S_Assemblage array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct s_s_assemblage *s_s_assemblage_ptr_old, *s_s_assemblage_ptr_new; -/* - * Find n_user_old in structure array s_s_assemblage - */ - if (n_user_old == n_user_new) return(OK); - s_s_assemblage_ptr_old = s_s_assemblage_bsearch(n_user_old, &n_old); - if (s_s_assemblage_ptr_old == NULL) { - sprintf(error_string, "S_S_Assemblage %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array s_s_assemblage or make new space - */ - sort = FALSE; - s_s_assemblage_ptr_new = s_s_assemblage_bsearch(n_user_new, &n_new); - if (s_s_assemblage_ptr_new != NULL) { - s_s_assemblage_free(s_s_assemblage_ptr_new); - } else { - space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - if (n_user_new < s_s_assemblage[count_s_s_assemblage-1].n_user) sort = TRUE; - n_new = count_s_s_assemblage++; - } -/* - * Copy data - */ - s_s_assemblage_copy(&s_s_assemblage[n_old], &s_s_assemblage[n_new], n_user_new); - if (sort == TRUE) s_s_assemblage_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array s_s_assemblage. - */ -{ - int i; - int n_old; - struct s_s_assemblage *s_s_assemblage_ptr_old; -/* - * Find n_user_old in structure array - */ - s_s_assemblage_ptr_old = s_s_assemblage_bsearch(n_user_old, &n_old); - if (s_s_assemblage_ptr_old != NULL) { - /* - * Delete s_s_assemblage - */ - s_s_assemblage_free(&s_s_assemblage[n_old]); - - for(i = n_old + 1; i < count_s_s_assemblage; i++) { - memcpy( (void *) &s_s_assemblage[i - 1], (void *) &s_s_assemblage[i], - (size_t) sizeof (struct s_s_assemblage) ); - } - count_s_s_assemblage--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_free (struct s_s_assemblage *s_s_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for s_s_assemblage structure - */ - int i; - - if (s_s_assemblage_ptr == NULL) return(ERROR); - s_s_assemblage_ptr->description = (char *) free_check_null (s_s_assemblage_ptr->description); - for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - s_s_assemblage_ptr->s_s[i].comps = (struct s_s_comp *) free_check_null(s_s_assemblage_ptr->s_s[i].comps); - } - s_s_assemblage_ptr->s_s = (struct s_s *) free_check_null (s_s_assemblage_ptr->s_s); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_init (struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ - s_s_assemblage_ptr->n_user = n_user; - s_s_assemblage_ptr->n_user_end = n_user_end; - s_s_assemblage_ptr->description = string_duplicate(description); - s_s_assemblage_ptr->new_def = TRUE; - s_s_assemblage_ptr->count_s_s = 0; - s_s_assemblage_ptr->s_s = (struct s_s *) PHRQ_malloc((size_t) sizeof(struct s_s)); - if (s_s_assemblage_ptr->s_s == NULL) malloc_error(); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies s_s_assemblage_ptr_old to old n_user_new space if - * found or to s_s_assemblage[count_s_s_assemblage] if not found. - * S_S_Assemblage array may not be in sort order after the copy. - */ - int n_new, sort; - struct s_s_assemblage *s_s_assemblage_ptr_new; -/* - * Find n_user_old in structure array s_s_assemblage - */ - if (s_s_assemblage_ptr_old == NULL) { - sprintf(error_string, "S_S_Assemblage pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array s_s_assemblage or make new space - */ - sort = FALSE; - s_s_assemblage_ptr_new = s_s_assemblage_bsearch(n_user_new, &n_new); - if (s_s_assemblage_ptr_new == s_s_assemblage_ptr_old) return(OK); - if (s_s_assemblage_ptr_new != NULL) { - s_s_assemblage_free(s_s_assemblage_ptr_new); - } else { - space ((void **) ((void *) &s_s_assemblage), count_s_s_assemblage, &max_s_s_assemblage, sizeof(struct s_s_assemblage)); - if (n_user_new < s_s_assemblage[count_s_s_assemblage-1].n_user) sort = TRUE; - n_new = count_s_s_assemblage++; - } -/* - * Copy data - */ - s_s_assemblage_copy(s_s_assemblage_ptr_old, &s_s_assemblage[n_new], n_user_new); - if (sort == TRUE) s_s_assemblage_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage *s_s_assemblage_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct s_s_assemblage *s_s_assemblage_ptr; - s_s_assemblage_ptr = s_s_assemblage_alloc(); - s_s_assemblage_copy(s_s_assemblage_old_ptr, s_s_assemblage_ptr, n_user_new); - return (s_s_assemblage_ptr); -} -/* ---------------------------------------------------------------------- */ -struct s_s_assemblage *s_s_assemblage_search (int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "s_s_assemblage" for user number n_user. - * - * Arguments: - * n_user input, user number - * n output, position in s_s_assemblage - * - * Returns: - * if found, the address of the s_s_assemblage element - * if not found, NULL - */ - int i; - for (i=0; i < count_s_s_assemblage; i++) { - if ( s_s_assemblage[i].n_user == n_user) { - *n = i; - return (&(s_s_assemblage[i])); - } - } -/* - * S_S_Assemblage not found - */ - return (NULL); -} -/* ---------------------------------------------------------------------- */ -int s_s_assemblage_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of s_s_assemblage structures - */ - if (count_s_s_assemblage > 0) { - qsort (s_s_assemblage, (size_t) count_s_s_assemblage, (size_t) sizeof(struct s_s_assemblage), - s_s_assemblage_compare); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct s_s *s_s_ptr1, *s_s_ptr2; - s_s_ptr1 = (const struct s_s *) ptr1; - s_s_ptr2 = (const struct s_s *) ptr2; - return(strcmp_nocase(s_s_ptr1->name, s_s_ptr2->name)); - -} -/* ********************************************************************** - * - * Routines related to structure "save_values" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct save_values *save_values_bsearch (struct save_values *k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search save_values to find if one exists with given coefficients - * Save_Values is assumed to be in sort order by count_subscripts and - * values of subscripts - */ - void *void_ptr; - if (count_save_values == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) k, - (char *) save_values, - (size_t) count_save_values, - (size_t) sizeof(struct save_values), - save_values_compare); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct save_values *) void_ptr - save_values); - return ( (struct save_values *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int save_values_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - int i; - const struct save_values *save_values_ptr1, *save_values_ptr2; - save_values_ptr1 = (const struct save_values *) ptr1; - save_values_ptr2 = (const struct save_values *) ptr2; - if (save_values_ptr1->count_subscripts < save_values_ptr2->count_subscripts) { - return(-1); - } else if (save_values_ptr1->count_subscripts > save_values_ptr2->count_subscripts) { - return(1); - } else { - for (i=0; i < save_values_ptr1->count_subscripts ;i++) { - if (save_values_ptr1->subscripts[i] < save_values_ptr2->subscripts[i]) { - return(-1); - } else if (save_values_ptr1->subscripts[i] > save_values_ptr2->subscripts[i]) { - return(1); - } - } - } - return(0); -} -/* ---------------------------------------------------------------------- */ -int save_values_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of save_values structures - */ - if (count_save_values > 0) { - qsort (save_values, (size_t) count_save_values, (size_t) sizeof(struct save_values), - save_values_compare); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int save_values_store(struct save_values *s_v) -/* ---------------------------------------------------------------------- */ -{ -/* - * Look for subscripts - */ - int n, i; - struct save_values *s_v_ptr; - - s_v_ptr = save_values_bsearch(s_v, &n); - if (s_v_ptr != NULL) { - s_v_ptr->value = s_v->value; - } else { - save_values = (struct save_values *) PHRQ_realloc(save_values, (size_t) (count_save_values + 1) * sizeof( struct save_values)); - if (save_values == NULL) malloc_error(); - save_values[count_save_values].value = s_v->value; - save_values[count_save_values].count_subscripts = s_v->count_subscripts; - i = s_v->count_subscripts; - if (i == 0) i = 1; - save_values[count_save_values].subscripts = (int *) PHRQ_malloc ((size_t) i * sizeof(int)); - if (save_values[count_save_values].subscripts == NULL) malloc_error(); - save_values[count_save_values].subscripts = (int *) memcpy(save_values[count_save_values].subscripts, s_v->subscripts, (size_t) i * sizeof(int)); - count_save_values++; - save_values_sort(); - } - - if (count_save_values > 0) { - qsort (save_values, (size_t) count_save_values, (size_t) sizeof(struct save_values), - save_values_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "solution" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -int conc_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct conc *conc_ptr1, *conc_ptr2; - conc_ptr1 = (const struct conc *) ptr1; - conc_ptr2 = (const struct conc *) ptr2; - return(strcmp_nocase(conc_ptr1->description, conc_ptr2->description)); - -} -/* ---------------------------------------------------------------------- */ -int conc_init (struct conc *conc_ptr) -/* ---------------------------------------------------------------------- */ -{ - if (conc_ptr == NULL) return(ERROR); - conc_ptr->equation_name = NULL; - conc_ptr->phase = NULL; - conc_ptr->phase_si = 0.0; - conc_ptr->units=NULL; - conc_ptr->n_pe=-1; - conc_ptr->as=NULL; - conc_ptr->gfw= 0.0; - return OK; -} -/* ---------------------------------------------------------------------- */ -int isotope_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - int i; - const struct isotope *iso_ptr1, *iso_ptr2; - - iso_ptr1 = (const struct isotope *) ptr1; - iso_ptr2 = (const struct isotope *) ptr2; - i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); - if (i != 0) return(i); - if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) { - return(-1); - } else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) { - return(1); - } - return(0); -} -/* ---------------------------------------------------------------------- */ -struct solution *solution_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a solution structure - * arguments - * input: none - * return: pointer to a solution structure - */ -{ - int max_mass_balance; - struct solution *solution_ptr; - solution_ptr=(struct solution *) PHRQ_malloc(sizeof(struct solution)); - if (solution_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL - */ - solution_ptr->description=NULL; - solution_ptr->units=NULL; -/* - * Initial allocation of space for totals and activities - */ - max_mass_balance=MAX_MASS_BALANCE; - space ((void **) &(solution_ptr->totals), INIT, &max_mass_balance, sizeof (struct conc)); - max_mass_balance=MAX_MASS_BALANCE; - solution_ptr->totals[0].description = NULL; - space ((void **) &(solution_ptr->master_activity), INIT, &max_mass_balance, sizeof (struct master_activity)); - solution_ptr->master_activity[0].description = NULL; - solution_ptr->species_gamma = NULL; - solution_ptr->count_species_gamma = 0; -/* - * Initial allocation of space for pe's - */ - solution_ptr->pe = pe_data_alloc(); -/* - * Initial allocation of space for isotopes - */ - solution_ptr->isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); - if (solution_ptr->isotopes == NULL) malloc_error(); - solution_ptr->new_def=TRUE; - - return(solution_ptr); -} -/* ---------------------------------------------------------------------- */ -struct solution *solution_bsearch (int k, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of solution solution array to find user number k. - * Assumes array solution is in sort order. - * - * Input: k user number to find. - * print, TRUE print warning if solution not found. - * Output: n, position of solution ptr in solution array. - * Return: pointer to solution structure if found - * NULL if not found. - */ - void *void_ptr; - void_ptr = NULL; - if (count_solution > 0) { - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) solution, - (size_t) count_solution, - (size_t) sizeof(struct solution *), - solution_compare_int); - } - if (void_ptr == NULL && print == TRUE) { - sprintf(error_string, "Solution %d not found.", k); - error_msg(error_string, CONTINUE); - } - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - - *n = (int) ((struct solution **) void_ptr - solution); - return (* (struct solution **) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int solution_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare solution user numbers - */ - const struct solution *nptr1; - const struct solution *nptr2; - - nptr1= *(const struct solution **) ptr1; - nptr2= *(const struct solution **) ptr2; - if (nptr1->n_user > nptr2->n_user) return(1); - if (nptr1->n_user < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int solution_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare solution user number to an integer - */ - const int *nptr1; - const struct solution *nptr2; - - nptr1= (const int *) ptr1; - nptr2= *(const struct solution **) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -static struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies solution data to new structure. - * Space for new structure is malloced here. - * - * Input: solution_old_ptr, pointer to structure to be copied. - * n_user_new, user number to give to the new solution. - * - * Return: pointer to new solution structure. - */ - int i; - int count_totals, count_master_activity; - struct solution *solution_new_ptr; -/* - * malloc space for new solution structure - */ - solution_new_ptr = (struct solution *) PHRQ_malloc(sizeof(struct solution)); - if (solution_new_ptr == NULL) malloc_error(); -/* - * Copy solution data, but set pointers pe and totals to NULL - */ - memcpy ( (void *) solution_new_ptr, (void *) solution_old_ptr, (size_t) sizeof (struct solution)); - solution_new_ptr->n_user = n_user_new; - solution_new_ptr->n_user_end = n_user_new; - solution_new_ptr->description = string_duplicate(solution_old_ptr->description); -/* - * Count totals data and malloc space - */ - for (i = 0; solution_old_ptr->totals[i].description != NULL; i++); - count_totals = i + 1; - solution_new_ptr->totals = (struct conc *) PHRQ_malloc( (size_t) count_totals * sizeof(struct conc)); - if (solution_new_ptr->totals == NULL) malloc_error(); -/* - * Copy totals data - */ - memcpy ( (void *) solution_new_ptr->totals, (void *) solution_old_ptr->totals, (size_t) count_totals * sizeof (struct conc)); -/* - * Count master activity guesses and malloc space - */ - for (i = 0; solution_old_ptr->master_activity[i].description != NULL; i++); - count_master_activity = i + 1; - solution_new_ptr->master_activity = (struct master_activity *) PHRQ_malloc( (size_t) count_master_activity * sizeof(struct master_activity)); - if (solution_new_ptr->master_activity == NULL) malloc_error(); -/* - * Copy master activity guesses - */ - memcpy ( (void *) solution_new_ptr->master_activity, (void *) solution_old_ptr->master_activity, (size_t) count_master_activity * sizeof (struct master_activity)); -/* - * malloc space for species gammas - */ - if (solution_old_ptr->count_species_gamma > 0) { - solution_new_ptr->species_gamma = (struct master_activity *) PHRQ_malloc( (size_t) solution_old_ptr->count_species_gamma * sizeof(struct master_activity)); - if (solution_new_ptr->species_gamma == NULL) malloc_error(); - /* - * Copy species gammas - */ - memcpy ( (void *) solution_new_ptr->species_gamma, (void *) solution_old_ptr->species_gamma, (size_t) solution_old_ptr->count_species_gamma * sizeof (struct master_activity)); - solution_new_ptr->count_species_gamma = solution_old_ptr->count_species_gamma; - } else { - solution_new_ptr->species_gamma = NULL; - solution_new_ptr->count_species_gamma = 0; - } -/* - * Copy pe data - */ - solution_new_ptr->pe = pe_data_dup (solution_old_ptr->pe); -/* - * Malloc and copy isotope data - */ - if (solution_old_ptr->count_isotopes > 0) { - solution_new_ptr->count_isotopes = solution_old_ptr->count_isotopes; - solution_new_ptr->isotopes = (struct isotope *) PHRQ_malloc((size_t) solution_old_ptr->count_isotopes * sizeof(struct isotope)); - if (solution_new_ptr->isotopes == NULL) malloc_error(); - memcpy(solution_new_ptr->isotopes, solution_old_ptr->isotopes, (size_t) solution_old_ptr->count_isotopes * sizeof(struct isotope)); - } else { - solution_new_ptr->count_isotopes = 0; - solution_new_ptr->isotopes = NULL; - } -/* - * Return pointer to new structure - */ - return(solution_new_ptr); -} -/* ---------------------------------------------------------------------- */ -int solution_copy_to_last(int n, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies solution from pointer solution[n]. Makes new structure - * and saves pointer in solution[count_solution]. - */ - /* Make sure solution array is large enough */ - if (count_solution + 1 >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, - sizeof (struct solution *) ); - } - /* malloc space and copy solution */ - solution[count_solution] = solution_copy(solution[n], n_user_new); - count_solution++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solution_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees structure if it does - * Copies structure for solution[n_user_old] to new space - * Saves pointer in old position if it existed, no sort necessary - * Otherwise saves in count_solution position, sort may be necessary - * Solution array is in sort order on exit - */ - int n, n_old, n_new, sort; - struct solution *solution_old_ptr, *solution_new_ptr; -/* - * Find solution n_user_old - */ - if (n_user_old == n_user_new) return(OK); - solution_old_ptr = solution_bsearch(n_user_old, &n_old, TRUE); - if (solution_old_ptr == NULL) { - sprintf(error_string, "Solution %d not found.", n_user_old); - error_msg(error_string, STOP); - } -/* - * Check if solution n_user_new already exists - */ - solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); - if (solution_new_ptr != NULL) { - n = n_new; - solution_free(solution_new_ptr); - sort = FALSE; - } else { - n = count_solution; - count_solution++; - if (n_user_new > solution[n-1]->n_user) { - sort = FALSE; - } else { - sort = TRUE; - } - } - solution[n] = solution_copy(solution_old_ptr, n_user_new); -/* - * Make sure surface array is large enough - */ - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, - sizeof (struct solution *) ); - } -/* - * Sort solution if necessary - */ - if (sort == TRUE) solution_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solution_delete (int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete a solution structure: free memory and renumber solution. - */ - struct solution *solution_ptr; - int j, n; - solution_ptr = solution_bsearch(n_user, &n, FALSE); - if (solution_ptr != NULL) { - solution_free ( solution[n] ); - for (j=n; j < ( count_solution -1 ); j++) { - solution[j]=solution[j+1]; - } - count_solution--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solution_free (struct solution *solution_ptr) -/* ---------------------------------------------------------------------- */ -{ - if (solution_ptr == NULL) return(OK); -/* - * Free all memory unique to a solution structure, free solution_ptr too. - */ - solution_ptr->description = (char *) free_check_null (solution_ptr->description); -/* Free struct conc array */ - solution_ptr->totals = (struct conc *) free_check_null (solution_ptr->totals); - solution_ptr->master_activity = (struct master_activity *) free_check_null (solution_ptr->master_activity); - solution_ptr->species_gamma = (struct master_activity *) free_check_null (solution_ptr->species_gamma); - solution_ptr->count_species_gamma = 0; -/* Free struct pe_data array */ - pe_data_free (solution_ptr->pe); -/* Free isotope data */ - solution_ptr->isotopes = (struct isotope *) free_check_null (solution_ptr->isotopes); -/* Free struct solution */ - solution_ptr = (struct solution *) free_check_null (solution_ptr); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees structure if it does - * Copies structure for solution[n_user_old] to new space - * Saves pointer in old position if it existed, no sort necessary - * Otherwise saves in count_solution position, sort may be necessary - * Solution array is in sort order on exit - */ - int n, n_new, sort; - struct solution *solution_new_ptr; -/* - * Find solution n_user_old - */ - if (solution_old_ptr == NULL) { - sprintf(error_string, "Solution pointer is NULL."); - error_msg(error_string, STOP); - } -/* - * Check if solution n_user_new already exists - */ - solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); - if (solution_new_ptr == solution_old_ptr) return(OK); - if (solution_new_ptr != NULL) { - n = n_new; - solution_free(solution_new_ptr); - sort = FALSE; - } else { - n = count_solution; - count_solution++; - /* - * Make sure surface array is large enough - */ - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, - sizeof (struct solution *) ); - } - if (n_user_new > solution[n-1]->n_user) { - sort = FALSE; - } else { - sort = TRUE; - } - } - solution[n] = solution_copy(solution_old_ptr, n_user_new); -/* - * Sort solution if necessary - */ - if (sort == TRUE) solution_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct solution *solution_replicate(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - return(solution_copy(solution_old_ptr, n_user_new)); -} -/* ---------------------------------------------------------------------- */ -int solution_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of pointers to solution structures, solution. - */ - if (count_solution > 0) { - qsort (solution, - (size_t) count_solution, - (size_t) sizeof(struct solution *), - solution_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "species_list" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -static int species_list_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - int j; - char *name1, *name2; - const struct species_list *nptr1, *nptr2; - - nptr1= (const struct species_list *) ptr1; - nptr2= (const struct species_list *) ptr2; - -/* - * Put H+ first - */ - if (nptr1->master_s != nptr2->master_s) { - if (nptr1->master_s == s_hplus) return (-1); - if (nptr2->master_s == s_hplus) return (1); - } -/* - * Other element valence states - */ - if (nptr1->master_s->secondary != NULL) { - name1 = nptr1->master_s->secondary->elt->name; - } else { - name1 = nptr1->master_s->primary->elt->name; - } - if (nptr2->master_s->secondary != NULL) { - name2 = nptr2->master_s->secondary->elt->name; - } else { - name2 = nptr2->master_s->primary->elt->name; - } -/* - * Compare name of primary or secondary master species; log molality - */ - - j = strcmp( name1, name2 ); - -/* - * Different master species - */ - if (j != 0 ) return(j); - -/* - * Else, descending order by log molality - */ - if ( nptr1->s->lm > nptr2->s->lm) { - return (-1); - } else if ( nptr1->s->lm < nptr2->s->lm) { - return (1); - } else { - return (0); - } -} -/* ---------------------------------------------------------------------- */ -int species_list_compare_alk (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct species_list *nptr1, *nptr2; - double alk1, alk2; - - nptr1= (const struct species_list *) ptr1; - nptr2= (const struct species_list *) ptr2; -/* - * Else, descending order by log molality - */ - alk1 = fabs(under(nptr1->s->lm)*nptr1->s->alk); - alk2 = fabs(under(nptr2->s->lm)*nptr2->s->alk); - - if ( alk1 > alk2) { - return (-1); - } else if ( alk1 < alk2) { - return (1); - } else { - return (0); - } -} -/* ---------------------------------------------------------------------- */ -int species_list_compare_master (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - char *name1, *name2; - const struct species_list *nptr1, *nptr2; - - nptr1= (const struct species_list *) ptr1; - nptr2= (const struct species_list *) ptr2; - -/* - * Put H+ first - */ - if (nptr1->master_s != nptr2->master_s) { - if (nptr1->master_s == s_hplus) return (-1); - if (nptr2->master_s == s_hplus) return (1); - } -/* - * Other element valence states - */ - if (nptr1->master_s->secondary != NULL) { - name1 = nptr1->master_s->secondary->elt->name; - } else { - name1 = nptr1->master_s->primary->elt->name; - } - if (nptr2->master_s->secondary != NULL) { - name2 = nptr2->master_s->secondary->elt->name; - } else { - name2 = nptr2->master_s->primary->elt->name; - } -/* - * Compare name of primary or secondary master species; log molality - */ - - return(strcmp( name1, name2 )); -} -/* ---------------------------------------------------------------------- */ -int species_list_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort list using rules in species_list_compare - */ - if (count_species_list > 0) { - qsort (&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), species_list_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "surface" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct surface *surface_alloc (void) -/* ---------------------------------------------------------------------- */ -{ - struct surface *surface_ptr; - surface_ptr = (struct surface *) PHRQ_malloc(sizeof (struct surface)); - if (surface_ptr == NULL) malloc_error(); - surface_ptr->description = NULL; - surface_ptr->count_comps = 0; - surface_ptr->comps = NULL; - surface_ptr->count_charge = 0; - surface_ptr->charge = NULL; - return ( surface_ptr ); -} -/* ---------------------------------------------------------------------- */ -struct surface *surface_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array surface to find user number k. - * Assumes array surface is in sort order. - * - * Input: k, user number to find. - * Output: n, position in array surface of user number k. - * Return: pointer to surface structure if found, - * NULL if not found. - */ - void *void_ptr; - if (count_surface == 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) surface, - (size_t) count_surface, - (size_t) sizeof(struct surface), - surface_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct surface *) void_ptr - surface); - return ( (struct surface *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int surface_comp_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct surface_comp *surface_comp_ptr1, *surface_comp_ptr2; - surface_comp_ptr1 = (const struct surface_comp *) ptr1; - surface_comp_ptr2 = (const struct surface_comp *) ptr2; - return(strcmp_nocase(surface_comp_ptr1->master->elt->name, surface_comp_ptr2->master->elt->name)); -} -/* ---------------------------------------------------------------------- */ -int surface_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct surface *surface_ptr1, *surface_ptr2; - surface_ptr1 = (const struct surface *) ptr1; - surface_ptr2 = (const struct surface *) ptr2; - if (surface_ptr1->n_user > surface_ptr2->n_user) return(1); - if (surface_ptr1->n_user < surface_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int surface_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare surface user numbers to integer - */ - const int *nptr1; - const struct surface *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct surface *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies data from surface_old_ptr to surface_new_ptr. - * Space for a surface structure must already be malloced. - * User number of new surface structure is n_user. - */ - int count_comps, count_charge, i; - char token[MAX_LENGTH]; -/* - * Store data for structure surface - */ - memcpy(surface_new_ptr, surface_old_ptr, sizeof(struct surface)); - count_comps = surface_old_ptr->count_comps; - count_charge = surface_old_ptr->count_charge; - surface_new_ptr->n_user = n_user_new; - surface_new_ptr->n_user_end = n_user_new; - surface_new_ptr->new_def = surface_old_ptr->new_def; - sprintf(token, "Surface defined in simulation %d.", simulation); - surface_new_ptr->description = string_duplicate(token); - surface_new_ptr->solution_equilibria = FALSE; - surface_new_ptr->n_solution = -10; -/* - * Write surface_comp structure for each surface component - */ - surface_new_ptr->comps = (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * sizeof (struct surface_comp)); - if (surface_new_ptr->comps == NULL) malloc_error(); - memcpy(surface_new_ptr->comps, surface_old_ptr->comps, - (size_t) (count_comps) * sizeof (struct surface_comp)); - for ( i = 0; i < count_comps; i++) { - surface_new_ptr->comps[i].totals = elt_list_dup(surface_old_ptr->comps[i].totals); - } -/* - * Write surface_charge structure for each surface - */ - if (surface_old_ptr->edl == TRUE) { - surface_new_ptr->charge = (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * sizeof (struct surface_charge)); - if (surface_new_ptr->charge == NULL) malloc_error(); - memcpy(surface_new_ptr->charge, surface_old_ptr->charge, - (size_t) (count_charge) * sizeof (struct surface_charge)); - for ( i = 0; i < count_charge; i++) { - surface_new_ptr->charge[i].diffuse_layer_totals = elt_list_dup(surface_old_ptr->charge[i].diffuse_layer_totals); - surface_new_ptr->charge[i].g = NULL; - } - } else { - surface_new_ptr->charge = NULL; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an surface definition to position count_surface. - */ - space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); - surface_copy(&surface[n], &surface[count_surface], n_user); - count_surface++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies surface[n_user_old] to old n_user_new space if - * found or to surface[count_surface] if not found. - * Surface array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct surface *surface_ptr_old, *surface_ptr_new; -/* - * Find n_user_old in structure array surface - */ - if (n_user_old == n_user_new) return(OK); - surface_ptr_old = surface_bsearch(n_user_old, &n_old); - if (surface_ptr_old == NULL) { - sprintf(error_string, "Surface %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array surface or make new space - */ - sort = FALSE; - surface_ptr_new = surface_bsearch(n_user_new, &n_new); - if (surface_ptr_new != NULL) { - surface_free(surface_ptr_new); - } else { - space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); - if (n_user_new < surface[count_surface-1].n_user) sort = TRUE; - n_new = count_surface++; - } -/* - * Copy data - */ - surface_copy(&surface[n_old], &surface[n_new], n_user_new); - if (sort == TRUE) surface_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array surface. - */ -{ - int i; - int n_old; - struct surface *surface_ptr_old; -/* - * Find n_user_old in structure array - */ - surface_ptr_old = surface_bsearch(n_user_old, &n_old); - if (surface_ptr_old != NULL) { - /* - * Delete surface - */ - surface_free(&surface[n_old]); - - for(i = n_old + 1; i < count_surface; i++) { - memcpy( (void *) &surface[i - 1], (void *) &surface[i], - (size_t) sizeof (struct surface) ); - } - count_surface--; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_free(struct surface *surface_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all space related to surface_ptr, but not surface_ptr. - */ - int k; - - if (surface_ptr == NULL) return(ERROR); - surface_ptr->description = (char *) free_check_null(surface_ptr->description); -/* - * totals, then comps - */ - for (k = 0; k < surface_ptr->count_comps; k++) { - surface_ptr->comps[k].totals = (struct elt_list *) free_check_null(surface_ptr->comps[k].totals); - } - surface_ptr->comps = (struct surface_comp *) free_check_null (surface_ptr->comps); -/* - * diffuse_layer_totals and g, then charge - */ - if (surface_ptr->edl == TRUE) { - for (k = 0; k < surface_ptr->count_charge; k++) { - surface_ptr->charge[k].diffuse_layer_totals = (struct elt_list *) free_check_null(surface_ptr->charge[k].diffuse_layer_totals); - surface_ptr->charge[k].g = (struct surface_diff_layer *) free_check_null(surface_ptr->charge[k].g); - } - } - surface_ptr->charge = (struct surface_charge *) free_check_null (surface_ptr->charge); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ - - if (surface_ptr == NULL) return(ERROR); - - surface_ptr->n_user = n_user; - surface_ptr->n_user_end = n_user_end; - surface_ptr->description = string_duplicate(description); - surface_ptr->new_def = TRUE; - surface_ptr->diffuse_layer = FALSE; - surface_ptr->edl = TRUE; - surface_ptr->only_counter_ions = FALSE; - surface_ptr->donnan = FALSE; - surface_ptr->debye_units = 0.0; - surface_ptr->transport = FALSE; - surface_ptr->thickness = 1e-8; - surface_ptr->solution_equilibria = FALSE; - surface_ptr->n_solution = -999; -/* - * Malloc one surface_comp structure - */ - surface_ptr->count_comps = 0; - surface_ptr->comps = (struct surface_comp *) PHRQ_malloc( (size_t) sizeof (struct surface_comp)); - if (surface_ptr->comps == NULL) malloc_error(); - surface_ptr->comps[0].master = NULL; - surface_ptr->comps[0].totals = NULL; - surface_ptr->comps[0].phase_name = NULL; - surface_ptr->comps[0].rate_name = NULL; - surface_ptr->comps[0].charge = -1; - surface_ptr->comps[0].moles = 0; - surface_ptr->comps[0].cb = 0; -/* - * Malloc one charge structure - */ - surface_ptr->count_charge = 0; - surface_ptr->charge = (struct surface_charge *) PHRQ_malloc( (size_t) sizeof (struct surface_charge)); - if (surface_ptr->charge == NULL) malloc_error(); - - surface_ptr->related_phases = FALSE; - surface_ptr->related_rate = FALSE; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies surface_ptr_old to old n_user_new space if - * found or to surface[count_surface] if not found. - * Surface array may not be in sort order after the copy. - */ - int n_new, sort; - struct surface *surface_ptr_new; -/* - * Find n_user_old in structure array surface - */ - if (surface_ptr_old == NULL) { - sprintf(error_string, "Surface pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_new in structure array surface or make new space - */ - sort = FALSE; - surface_ptr_new = surface_bsearch(n_user_new, &n_new); - if (surface_ptr_new == surface_ptr_old) return(OK); - if (surface_ptr_new != NULL) { - surface_free(surface_ptr_new); - } else { - space ((void **) ((void *) &surface), count_surface, &max_surface, sizeof(struct surface)); - if (n_user_new < surface[count_surface-1].n_user) sort = TRUE; - n_new = count_surface++; - } -/* - * Copy data - */ - surface_copy(surface_ptr_old, &surface[n_new], n_user_new); - if (sort == TRUE) surface_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct surface *surface_replicate(struct surface *surface_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct surface *surface_ptr; - surface_ptr = surface_alloc(); - surface_copy(surface_old_ptr, surface_ptr, n_user_new); - return (surface_ptr); -} -/* ---------------------------------------------------------------------- */ -struct surface *surface_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "surface" for user number n_user. - * - * Arguments: - * n_user input, user number. - * n output, position in surface. - * - * Returns: - * if found, pointer to surface structure - * if not found, NULL - */ - int i; - for (i = 0; i < count_surface; i++) { - if (n_user == surface[i].n_user) { - break; - } - } - if (i >= count_surface) { - if ( print == TRUE) { - sprintf(error_string, "Surface %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return(NULL); - } - *n = i; - return(&surface[i]); -} -/* ---------------------------------------------------------------------- */ -int surface_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of surface structures - */ - if (count_surface > 0) { - qsort (surface, (size_t) count_surface, (size_t) sizeof(struct surface), - surface_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "temperature" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct temperature *temperature_bsearch (int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array temperature to find user number k. - * Assumes array temperature is in sort order. - * - * Input: k, user number to find. - * Output: n, position in array temperature of user number k. - * Return: pointer to temperature structure if found, - * NULL if not found. - */ - void *void_ptr; - if (count_temperature <= 0) { - *n = -999; - return(NULL); - } - void_ptr = (void *) - bsearch ( (char *) &k, - (char *) temperature, - (size_t) count_temperature, - (size_t) sizeof(struct temperature), - temperature_compare_int); - if (void_ptr == NULL) { - *n = -999; - return(NULL); - } - *n = (int) ((struct temperature *) void_ptr - temperature); - return ( (struct temperature *) void_ptr); -} -/* ---------------------------------------------------------------------- */ -int temperature_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct temperature *temperature_ptr1, *temperature_ptr2; - temperature_ptr1 = (const struct temperature *) ptr1; - temperature_ptr2 = (const struct temperature *) ptr2; - if (temperature_ptr1->n_user > temperature_ptr2->n_user) return(1); - if (temperature_ptr1->n_user < temperature_ptr2->n_user) return(-1); - return (0); - -} -/* ---------------------------------------------------------------------- */ -static int temperature_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare temperature user numbers - */ - const int *nptr1; - const struct temperature *nptr2; - - nptr1= (const int *) ptr1; - nptr2= (const struct temperature *) ptr2; - if (*nptr1 > nptr2->n_user) return(1); - if (*nptr1 < nptr2->n_user) return(-1); - return (0); -} -/* ---------------------------------------------------------------------- */ -int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies temperature data from temperature_old_ptr to new location, temperature_new_ptr. - * Space for the temperature_new_ptr structure must already be malloced. - * Space for temperature components is malloced here. - */ - int count; - char token[MAX_LENGTH]; -/* - * Copy old to new - */ - memcpy(temperature_new_ptr, temperature_old_ptr, sizeof (struct temperature)); -/* - * Store data for structure temperature - */ - temperature_new_ptr->n_user = n_user_new; - temperature_new_ptr->n_user_end = n_user_new; - sprintf(token, "Temperature defined in simulation %d.", simulation); - temperature_new_ptr->description = string_duplicate(token); -/* - * Count temperature components and allocate space - */ - if (temperature_old_ptr->count_t < 0) { - count = 2; - } else { - count = temperature_old_ptr->count_t; - } - temperature_new_ptr->t = (double *) PHRQ_malloc((size_t) (count) * sizeof (double)); - if (temperature_new_ptr->t == NULL) malloc_error(); - memcpy(temperature_new_ptr->t, temperature_old_ptr->t, - (size_t) (count * sizeof (double))); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int temperature_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies temperature[n_user_old] to old n_user_new space if - * found or to temperature[count_temperature] if not found. - * Temperature array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - char token[MAX_LENGTH]; - int count_t; - struct temperature *temperature_ptr_old, *temperature_ptr_new; -/* - * Find n_user_old in structure array temperature or make new space - */ - if (n_user_old == n_user_new) return(OK); - temperature_ptr_old = temperature_bsearch(n_user_old, &n_old); - if (temperature_ptr_old == NULL) { - sprintf(error_string, "Temperature %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return(ERROR); - } -/* - * Find n_user_old in structure array temperature or make new space - */ - sort = FALSE; - temperature_ptr_new = temperature_bsearch(n_user_new, &n_new); - if (temperature_ptr_new != NULL) { - temperature_free(&temperature[n_new]); - } else { - temperature = (struct temperature *) PHRQ_realloc( temperature, - (size_t) (count_temperature + 1) * - sizeof (struct temperature)); - if (temperature == NULL) malloc_error(); - if (n_user_new < temperature[count_temperature-1].n_user) sort = TRUE; - n_new = count_temperature++; - } -/* - * Store data for structure temperature - */ - count_t = temperature[n_old].count_t; - temperature[n_new].n_user = n_user_new; - temperature[n_new].n_user_end = n_user_new; - sprintf(token, "Temperature defined in simulation %d.", simulation); - temperature[n_new].description = string_duplicate(token); - temperature[n_new].count_t = count_t; - if (count_t < 0) count_t = 2; -/* - * Count temperature components and allocate space - */ - temperature[n_new].t = (LDBLE *) PHRQ_malloc((size_t) (count_t) * - sizeof (LDBLE)); - if (temperature[n_new].t == NULL) malloc_error(); -/* - * Write temperature_comp structure for each temperature component - */ - memcpy(temperature[n_new].t, temperature[n_old].t, - (size_t) (count_t) * sizeof (LDBLE)); - if (sort == TRUE) temperature_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int temperature_free (struct temperature *temperature_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for temperature structure, does not free temperature_ptr. - */ - if (temperature_ptr == NULL) return(ERROR); - - temperature_ptr->description = (char *) free_check_null (temperature_ptr->description); - temperature_ptr->t = (LDBLE *) free_check_null (temperature_ptr->t); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct temperature *temperature_search(int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "temperature" for user number n_user. - * - * Arguments: - * n_user input, user number. - * n output, position in temperature. - * - * Returns: - * if found, pointer to temperature structure - * if not found, NULL - */ - int i; - for (i = 0; i < count_temperature; i++) { - if (n_user == temperature[i].n_user) { - break; - } - } - if (i >= count_temperature) { - *n = -999; - return(NULL); - } - *n = i; - return(&temperature[i]); -} -/* ---------------------------------------------------------------------- */ -int temperature_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of temperature structures - */ - if (count_temperature > 0) { - qsort (temperature, (size_t) count_temperature, (size_t) sizeof(struct temperature), temperature_compare); - } - return(OK); -} -/* ********************************************************************** - * - * Routines related to structure "trxn" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -int rxn_token_temp_compare (const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct rxn_token_temp *rxn_token_temp_ptr1, *rxn_token_temp_ptr2; - rxn_token_temp_ptr1 = (const struct rxn_token_temp *) ptr1; - rxn_token_temp_ptr2 = (const struct rxn_token_temp *) ptr2; - return(strcmp(rxn_token_temp_ptr1->name, rxn_token_temp_ptr2->name)); -} -/* ---------------------------------------------------------------------- */ -int trxn_add (struct reaction *r_ptr, LDBLE coef, int combine) -/* ---------------------------------------------------------------------- */ -{ -/* - * Adds reactions together. - * - * Global variable count_trxn determines which position in trxn is used. - * If count_trxn=0, then the equation effectively is copied into trxn. - * If count_trxn>0, then new equation is added to existing equation. - * - * Arguments: - * *r_ptr points to rxn structure to add. - * - * coef added equation is multiplied by coef. - * combine if TRUE, reaction is reaction is sorted and - * like terms combined. - */ - int i; - struct rxn_token *next_token; -/* - * Accumulate log k for reaction - */ - if (count_trxn == 0) { - memcpy( (void *) trxn.logk, (void *) r_ptr->logk, - (size_t) 7 * sizeof(LDBLE) ); - } else { - for (i=0; i < 7; i++) { - trxn.logk[i] += coef * (r_ptr->logk[i]); - } - } -/* - * Copy equation into work space - */ - next_token = r_ptr->token; - while (next_token->s != NULL) { - if (count_trxn + 1 >= max_trxn) { - space ((void **) &(trxn.token), count_trxn+1, &max_trxn, - sizeof(struct rxn_token_temp)); - } - trxn.token[count_trxn].name = next_token->s->name; - trxn.token[count_trxn].s = next_token->s; - trxn.token[count_trxn].coef = coef*next_token->coef; - count_trxn++; - next_token++; - } - if (combine == TRUE) trxn_combine(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int trxn_combine (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Combines coefficients of tokens that are equal in temporary - * reaction structure, trxn. - */ - int j, k; -/* - * Sort trxn species - */ - trxn_sort(); -/* - * Combine trxn tokens - */ - j=1; - for ( k=2; k < count_trxn; k++) { - if ( ( j > 0 ) && ( trxn.token[k].s == trxn.token[j].s) ) { - trxn.token[j].coef += trxn.token[k].coef; - if (equal(trxn.token[j].coef, 0.0, 1e-5)) j--; - } else { - j++; - if ( k != j ) { - trxn.token[j].name = trxn.token[k].name; - trxn.token[j].s = trxn.token[k].s; - trxn.token[j].coef = trxn.token[k].coef; - } - } - } - count_trxn=j+1; /* number excluding final NULL */ - return(OK); -} -/* ---------------------------------------------------------------------- */ -int trxn_copy (struct reaction *rxn_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies trxn to a reaction structure. - * - * Input: rxn_ptr, pointer to reaction structure to copy trxn to. - * - */ - int i; -/* - * Copy logk data - */ - for (i=0; i<7; i++) { - rxn_ptr->logk[i]=trxn.logk[i]; - } -/* - * Copy tokens - */ - for (i=0; i < count_trxn; i++ ) { - rxn_ptr->token[i].s = trxn.token[i].s; - rxn_ptr->token[i].coef = trxn.token[i].coef; - } - rxn_ptr->token[count_trxn].s=NULL; - - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE trxn_find_coef(const char *str, int start) -/* ---------------------------------------------------------------------- */ -{ -/* - * Finds coefficient of specified token in trxn. - * Input: str, token name in reaction. - * - * Return: 0.0, if token not found. - * coefficient of token, if token found. - */ - int i; - LDBLE coef; - - coef=0.0; - for (i=start; iname, str) == 0) { - coef=trxn.token[i].coef; - break; - } - } - return(coef); -} -/* ---------------------------------------------------------------------- */ -int trxn_multiply (LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ -/* - * Multiplies temporary reaction, trxn, by a constant - * - * Arguments: - * input: coef multiplier. - */ - int i; -/* - * Multiply log k for reaction - */ - for (i=0; i < 7; i++) { - trxn.logk[i] *= coef; - } -/* - * Multiply coefficients of reaction - */ - for (i=0; i < count_trxn; i++ ){ - trxn.token[i].coef *= coef; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int trxn_print (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Prints trxn - */ - int i; -/* - * Print log k for reaction - */ - - output_msg(OUTPUT_MESSAGE,"log k data:\n"); - for (i=0; i < 7; i++) { - output_msg(OUTPUT_MESSAGE,"\t%f",(double) trxn.logk[i]); - } - output_msg(OUTPUT_MESSAGE,"\n"); - -/* - * Print stoichiometry - */ - for (i=0; i 0) { - qsort(&trxn.token[1], - (size_t) count_trxn-1, - (size_t) sizeof(struct rxn_token_temp), - rxn_token_temp_compare); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int trxn_swap (const char *token) -/* ---------------------------------------------------------------------- */ -{ -/* - * Moves specified token to initial position in reaction. - * Input: token, token name to move to initial position. - * - * Return: ERROR, if token not found. - * OK, if token moved to initial position. - */ - int i, j; - LDBLE coef; -/* - * Locate token - */ - for (j=0; j < count_trxn; j++) { - if (strcmp(trxn.token[j].s->name,token) == 0 ) break; - } - if (j >= count_trxn ) { - input_error++; - sprintf(error_string,"Could not find token in equation, %s.", token); - error_msg(error_string, CONTINUE); - for (i=0; itype = 0; - unknown_ptr->moles = 0.0; - unknown_ptr->ln_moles = 0.0; - unknown_ptr->f = 0.0; - unknown_ptr->sum = 0.0; - unknown_ptr->delta = 0.0; - unknown_ptr->la = 0.0; - unknown_ptr->number = 0; - unknown_ptr->description=NULL; - unknown_ptr->master = NULL; - unknown_ptr->phase = NULL; - unknown_ptr->si = 0.0; - unknown_ptr->gas_phase=NULL; - unknown_ptr->total=NULL; - unknown_ptr->s=NULL; - unknown_ptr->exch_comp = NULL; - unknown_ptr->pure_phase = NULL; - unknown_ptr->s_s = NULL; - unknown_ptr->s_s_comp = NULL; - unknown_ptr->s_s_comp_number = 0; - unknown_ptr->s_s_in = FALSE; - unknown_ptr->surface_comp = NULL; - unknown_ptr->related_moles = 0.0; - unknown_ptr->potential_unknown = NULL; - unknown_ptr->phase_unknown = NULL; - unknown_ptr->surface_charge = NULL; - unknown_ptr->mass_water = 0.0; - unknown_ptr->dissolve_only = FALSE; - - return(unknown_ptr); -} -/* ---------------------------------------------------------------------- */ -int unknown_delete(int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete unknow from list x - */ - int j; - - unknown_free(x[i]); - for (j=i; j < (count_unknowns); j++) { - x[j] = x[j+1]; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int unknown_free(struct unknown *unknown_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees space allocated to an unknown structure, frees unknown_ptr. - */ - if (unknown_ptr == NULL) return(ERROR); - unknown_ptr->master = (struct master **) free_check_null (unknown_ptr->master); - unknown_ptr = (struct unknown *) free_check_null (unknown_ptr); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int system_duplicate (int i, int save_old) -/* ---------------------------------------------------------------------- */ -{ - int n; - - if (solution_bsearch(i,&n, TRUE) != NULL) solution_duplicate(i, save_old); - if (pp_assemblage_bsearch(i,&n) != NULL) pp_assemblage_duplicate(i, save_old); - if (exchange_bsearch(i,&n) != NULL) exchange_duplicate(i, save_old); - if (surface_bsearch(i,&n) != NULL) surface_duplicate(i, save_old); - if (gas_phase_bsearch(i,&n) != NULL) gas_phase_duplicate(i, save_old); - if (kinetics_bsearch(i,&n) != NULL) kinetics_duplicate(i, save_old); - if (s_s_assemblage_bsearch(i,&n) != NULL) s_s_assemblage_duplicate(i, save_old); - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct logk *logk_store (char *name, int replace_if_found) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for logk. - * - * Pointer to a logk structure is always returned. - * - * If the string is not found, a new entry is made in the hash table. Pointer to - * the new structure is returned. - * If "name" is found and replace is true, pointers in old logk structure - * are freed and replaced with additional input. - * If "name" is found and replace is false, the old logk structure is not - * modified and a pointer to it is returned. - * - * Arguments: - * name input, character string to be found in "logk". - * replace_if_found input, TRUE means reinitialize logk structure if found - * FALSE means just return pointer if found. - * - * Returns: - * pointer to logk structure "logk" where "name" can be found. - */ - int n; - struct logk *logk_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - str_tolower(name); - item.key = name; - item.data = NULL; - found_item = hsearch_multi(logk_hash_table, item, FIND); - - if (found_item != NULL && replace_if_found == FALSE) { - logk_ptr = (struct logk *) (found_item->data); - return (logk_ptr); - } else if (found_item != NULL && replace_if_found == TRUE) { - logk_ptr = (struct logk *) (found_item->data); - logk_init(logk_ptr); - } else { - n = count_logk++; - /* make sure there is space in s */ - if (count_logk >= max_logk) { - space ((void **) ((void *) &logk), count_logk, &max_logk, sizeof(struct logk *)); - } - /* Make new logk structure */ - logk[n] = logk_alloc(); - logk_ptr = logk[n]; - } - /* set name and z in pointer in logk structure */ - logk_ptr->name = string_hsave( name ); -/* - * Update hash table - */ - item.key = logk_ptr->name; - item.data = (void *) logk_ptr; - found_item = hsearch_multi(logk_hash_table, item, ENTER); - if (found_item == NULL) { - sprintf(error_string, "Hash table error in logk_store."); - error_msg(error_string, CONTINUE); - } - - return (logk_ptr); -} -/* ---------------------------------------------------------------------- */ -struct logk *logk_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a logk structure, initializes - * arguments: void - * return: pointer to a logk structure - */ -{ - struct logk *logk_ptr; - logk_ptr=(struct logk *) PHRQ_malloc(sizeof(struct logk)); - if (logk_ptr == NULL) malloc_error(); -/* - * set pointers in structure to NULL, variables to zero - */ - logk_init(logk_ptr); - - return(logk_ptr); -} -/* ---------------------------------------------------------------------- */ -static int logk_init(struct logk *logk_ptr) -/* ---------------------------------------------------------------------- */ -/* - * return: pointer to a logk structure - */ -{ - int i; -/* - * set pointers in structure to NULL - */ - logk_ptr->name=NULL; -/* - * set varibles = 0 - */ - logk_ptr->lk = 0.0; - for (i =0; i < 8; i++) { - logk_ptr->log_k[i] = 0.0; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -struct logk *logk_search (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function locates the string "name" in the hash table for logk. - * - * Arguments: - * name input, character string to be found in "logk". - * - * Returns: - * pointer to logk structure "logk" where "name" can be found. - * or NULL if not found. - */ - struct logk *logk_ptr; - ENTRY item, *found_item; -/* - * Search list - */ - str_tolower(name); - item.key = name; - item.data = NULL; - found_item = hsearch_multi(logk_hash_table, item, FIND); - - if (found_item != NULL) { - logk_ptr = (struct logk *) (found_item->data); - return (logk_ptr); - } - return(NULL); -} -/* ---------------------------------------------------------------------- */ -int entity_exists (char *name, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution, 0 Solution - * reaction, 1 Reaction - * exchange, 2 Exchange - * surface, 3 Surface - * gas_phase, 4 Gas_phase - * equilibrium_phases, 5 Pure_phase - * solid_solution, 6 Ss_phase - * kinetics, 7 Kinetics - * mix, 8 Mix - * reaction_temperature 9 Temperature - * unknown 10 UnKnown - */ - int i, return_value; - char *ptr; - char token[MAX_LENGTH]; - enum entity_type type; -/* - * Read keyword - */ - ptr = name; - copy_token (token, &ptr, &i); - type = get_entity_enum(token); - return_value = TRUE; - switch (type) { - case UnKnown: - warning_msg("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); - return_value = 2; - break; - case Solution: /* Solution */ - if (solution_bsearch (n_user, &i, FALSE) == NULL) { - return_value = FALSE; - } - break; - case Pure_phase: /* Pure phases */ - if(pp_assemblage_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Reaction: /* Reaction */ - if(irrev_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Mix: /* Mix */ - if(mix_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Exchange: /* Ex */ - if(exchange_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Surface: /* Surface */ - if(surface_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Temperature: /* Temperature */ - if(temperature_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Gas_phase: /* Gas */ - if(gas_phase_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Kinetics: /* Kinetics */ - if(kinetics_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - case Ss_phase: /* solid_solutions */ - if(s_s_assemblage_bsearch (n_user, &i) == NULL) { - return_value = FALSE; - } - break; - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -enum entity_type get_entity_enum (char *name) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution, 0 Solution - * reaction, 1 Reaction - * exchange, 2 Exchange - * surface, 3 Surface - * gas_phase, 4 Gas_phase - * equilibrium_phases, 5 Pure_phase - * solid_solution, 6 Ss_phase - * kinetics, 7 Kinetics - * mix, 8 Mix - * reaction_temperature 9 Temperature - * unknown 10 UnKnown - * - */ - int i; - char *ptr; - char token[MAX_LENGTH]; -/* - * Read keyword - */ - ptr = name; - copy_token (token, &ptr, &i); - check_key (token); - switch (next_keyword) { - case -1: /* Have not read line with keyword */ - case 0: /* End encountered */ - case 1: /* EOF encountered */ - case 2: /* Read aqueous model */ - case 3: /* Read master species */ - case 5: - case 9: - case 10: - case 11: - case 12: - case 14: - case 15: - case 18: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 30: - case 31: - case 32: - case 34: - case 35: - case 38: - case 39: - warning_msg("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); - return(UnKnown); - break; - case 4: /* Solution */ - return(Solution); - break; - case 6: /* Pure phases */ - case 26: - case 27: - case 28: - case 29: - return(Pure_phase); - break; - case 7: /* Reaction */ - return(Reaction); - break; - case 8: /* Mix */ - return(Mix); - break; - case 13: /* Ex */ - return(Exchange); - break; - case 16: /* Surface */ - return(Surface); - break; - case 17: /* Temperature */ - return(Temperature); - break; - case 19: /* Gas */ - return(Gas_phase); - break; - case 33: /* Kinetics */ - return(Kinetics); - break; - case 40: /* solid_solutions */ - case 41: /* solid_solution */ - return(Ss_phase); - break; - } - return(UnKnown); -} -/* - * copier routines - */ -/* ---------------------------------------------------------------------- */ -int copier_add(struct copier *copier_ptr, int n_user, int start, int end) -/* ---------------------------------------------------------------------- */ -/* - * add new set of copy instructions - */ -{ - - if (copier_ptr->count >= copier_ptr->max) { - copier_ptr->max = copier_ptr->count*2; - copier_ptr->n_user = (int *) PHRQ_realloc(copier_ptr->n_user, (size_t) (copier_ptr->max*sizeof(int))); - if (copier_ptr->n_user == NULL) malloc_error(); - copier_ptr->start = (int *) PHRQ_realloc(copier_ptr->start, (size_t) (copier_ptr->max*sizeof(int))); - if (copier_ptr->start == NULL) malloc_error(); - copier_ptr->end = (int *) PHRQ_realloc(copier_ptr->end, (size_t) (copier_ptr->max*sizeof(int))); - if (copier_ptr->end == NULL) malloc_error(); - } - copier_ptr->n_user[copier_ptr->count] = n_user; - copier_ptr->start[copier_ptr->count] = start; - copier_ptr->end[copier_ptr->count] = end; - copier_ptr->count++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int copier_free(struct copier *copier_ptr) -/* ---------------------------------------------------------------------- */ -/* - * initialize copier structure - */ -{ - - copier_ptr->n_user = (int *) free_check_null(copier_ptr->n_user); - copier_ptr->start = (int *) free_check_null(copier_ptr->start); - copier_ptr->end = (int *) free_check_null(copier_ptr->end); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int copier_init(struct copier *copier_ptr) -/* ---------------------------------------------------------------------- */ -/* - * initialize copier structure - */ -{ - - copier_ptr->count = 0; - copier_ptr->max = 10; - copier_ptr->n_user = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); - copier_ptr->start = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); - copier_ptr->end = (int *) PHRQ_malloc((size_t) (copier_ptr->max*sizeof(int))); - return(OK); -} diff --git a/sundialsmath.cpp b/sundialsmath.cpp deleted file mode 100644 index 2ec5ee28..00000000 --- a/sundialsmath.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************* - * * - * File : sundialsmath.c * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a C math library. * - * * - *******************************************************************/ - - -#include -#include -#include "sundialsmath.h" -#include "sundialstypes.h" -#include "output.h" - -static char const svnid[] = "$Id: sundialsmath.c 78 2005-02-01 22:47:12Z dlpark $"; - -#define ZERO RCONST(0.0) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) - - -realtype UnitRoundoff(void) -{ - realtype u; - volatile realtype one_plus_u; - - u = ONE; - one_plus_u = ONE + u; - while (one_plus_u != ONE) { - u /= TWO; - one_plus_u = ONE + u; - } - u *= TWO; - - return(u); -} - - -realtype RPowerI(realtype base, int exponent) -{ - int i, expt; - realtype prod; - - prod = ONE; - expt = ABS(exponent); - for(i=1; i <= expt; i++) prod *= base; - if (exponent < 0) prod = ONE/prod; - return(prod); -} - - -realtype RPowerR(realtype base, realtype exponent) -{ - - if (base <= ZERO) return(ZERO); - - /* return((realtype)pow((double)base,(double)exponent));*/ - return((realtype)pow(base,exponent)); -} - - -realtype RSqrt(realtype x) -{ - if (x <= ZERO) return(ZERO); - - /* return((realtype) sqrt((double) x));*/ - return((realtype) sqrt( x)); -} diff --git a/sundialsmath.h b/sundialsmath.h deleted file mode 100644 index 6c29aa28..00000000 --- a/sundialsmath.h +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************* - * * - * File : sundialsmath.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a C math library. The routines * - * listed here work with the type realtype as defined in * - * sundialstypes.h. * - * To do single precision floating point arithmetic, set the type * - * realtype to be float. To do double precision arithmetic, set * - * the type realtype to be double. The default implementations * - * for RPowerR and RSqrt call standard math library functions * - * which do double precision arithmetic. If this is unacceptable * - * when realtype is float, then the user should re-implement * - * these two routines by calling single precision routines * - * available on his/her machine. * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidsundialsmath[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef _sundialsmath_h -#define _sundialsmath_h - -#include "sundialstypes.h" - - -/****************************************************************** - * * - * Macros : MIN, MAX, ABS, SQR * - *----------------------------------------------------------------* - * MIN(A, B) returns the minimum of A and B. * - * * - * MAX(A, B) returns the maximum of A and B. * - * * - * ABS(A) returns the absolute value of A. * - * * - * SQR(A) returns the square of A. * - * * - ******************************************************************/ -#ifndef MIN -#define MIN(A, B) ((A) < (B) ? (A) : (B)) -#endif - -#ifndef MAX -#define MAX(A, B) ((A) > (B) ? (A) : (B)) -#endif - -#ifndef ABS -#define ABS(A) ((A < 0) ? -(A) : (A)) -#endif - -#ifndef SQR -#define SQR(A) ((A) * (A)) -#endif - -/****************************************************************** - * * - * Function : UnitRoundoff * - * Usage : realtype uround; * - * uround = UnitRoundoff(); * - *----------------------------------------------------------------* - * UnitRoundoff returns the unit roundoff u for real floating * - * point arithmetic, where u is defined to be the smallest * - * positive real such that 1.0 + u != 1.0. * - * * - ******************************************************************/ - -realtype UnitRoundoff(void); - - -/****************************************************************** - * * - * Function : RPowerI * - * Usage : int exponent; * - * realtype base, ans; * - * ans = RPowerI(base,exponent); * - *----------------------------------------------------------------* - * RPowerI returns the value base^exponent, where base is a * - * realtype and exponent is an int. * - * * - ******************************************************************/ - -realtype RPowerI(realtype base, int exponent); - - -/****************************************************************** - * * - * Function : RPowerR * - * Usage : realtype base, exponent, ans; * - * ans = RPowerR(base,exponent); * - *----------------------------------------------------------------* - * RPowerR returns the value base^exponent, where both base and * - * exponent are realtype. If base < 0.0, then RPowerR returns 0.0 * - * * - ******************************************************************/ - -realtype RPowerR(realtype base, realtype exponent); - - -/****************************************************************** - * * - * Function : RSqrt * - * Usage : realtype sqrt_x; * - * sqrt_x = RSqrt(x); * - *----------------------------------------------------------------* - * RSqrt(x) returns the square root of x. If x < 0.0, then RSqrt * - * returns 0.0. * - * * - ******************************************************************/ - -realtype RSqrt(realtype x); - - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/sundialstypes.h b/sundialstypes.h deleted file mode 100644 index a81ed34d..00000000 --- a/sundialstypes.h +++ /dev/null @@ -1,144 +0,0 @@ -#include "phrqtype.h" -/******************************************************************* - * * - * File : sundialstypes.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This header file exports three types: realtype, integertype, * - * and booleantype, as well as the constants TRUE and FALSE. * - * * - * Users should #include "sundialstypes.h" in any file that * - * shhould be easily modifiable to work with different real or * - * integer types and use the exported names realtype and * - * integertype within such a file. * - * The types for realtype and integertype below have been set to * - * double and long int, respectively. A user should modify these * - * type declarations as he/she sees fit. For example, if a user * - * wants the work with type float because double precision * - * floating point arithmetic is too expensive on the user's * - * machine, then the definition below should be changed to: * - * * - * typedef float realtype; * - * * - * Similarly, if a user does not need to work with extremely large * - * integers (see the system header file for the limits * - * on type int and long int on your machine), then the user * - * should change the definition below to: * - * * - * typedef int integertype; * - * * - * The constants SUNDIALS_FLOAT, SUNDIALS_DOUBLE, SUNDIALS_INT, * - * SUNDIALS_LONG indicate the underlying types for realtype and * - * integertype. They should be set as follows: * - * * - * (1) #define SUNDIALS_FLOAT 1 * - * #define SUNDIALS_DOUBLE 0 (real is float) * - * * - * (2) #define SUNDIALS_FLOAT 0 * - * #define SUNDIALS_DOUBLE 1 (real is double) * - * * - * (3) #define SUNDIALS_INT 1 * - * #define SUNDIALS_LONG 0 (integer is int) * - * * - * (4) #define SUNDIALS_INT 0 * - * #define SUNDIALS_LONG 1 (integer is long int) * - * * - * Thus the legal types for realtype are float and double, while * - * the legal types for integertype are int and long int. * - * The macro RCONST gives a user a convenient way to define real * - * constants. To use the real constant 1.0, for example, the * - * user should write * - * * - * #define ONE RCONST(1.0) * - * * - * If realtype is double, then RCONST(1.0) expands to 1.0. * - * If realtype is float, then RCONST(1.0) expands to 1.0F. * - * There is never a need to explicitly cast 1.0 to (realtype). * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidsundialstypes[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef _sundialstypes_h -#define _sundialstypes_h - - -/****************************************************************** - * * - * Types : realtype, integertype * - *----------------------------------------------------------------* - * The types realtype and integertype are currently set to double * - * and int, respectively. See the documentation at the top for * - * usage details and a description of associated constants and * - * macros. * - * * - ******************************************************************/ - -#ifdef USE_LONG_DOUBLE - typedef long double realtype; -#else - typedef double realtype; -#endif -typedef long int integertype; - -#define SUNDIALS_FLOAT 0 -#define SUNDIALS_DOUBLE 1 - -#define SUNDIALS_LONG 1 -#define SUNDIALS_INT 0 - -#if SUNDIALS_FLOAT - -#define RCONST(x) x##F - -#elif SUNDIALS_DOUBLE - -#define RCONST(x) x - -#endif - - -/****************************************************************** - * * - * Type : booleantype * - * Constants : FALSE, TRUE * - *----------------------------------------------------------------* - * ANSI C does not have a built-in boolean type. Below is the * - * definition for a new type booleantype. The advantage of using * - * the name booleantype (instead of int) is an increase in code * - * readability. * - * It allows the programmer to make a distinction between int and * - * boolean data. Variables of type booleantype are intended to * - * have only the two values FALSE and TRUE which are defined * - * below to be equal to 0 and 1, respectively. * - * * - ******************************************************************/ - -#ifndef booleantype -#define booleantype int -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/tally.cpp b/tally.cpp deleted file mode 100644 index 2211863b..00000000 --- a/tally.cpp +++ /dev/null @@ -1,1006 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: tally.c 265 2005-04-25 13:57:00Z dlpark $"; -/* - * storage - */ -struct buffer { - char *name; - struct master *master; - LDBLE moles; - LDBLE gfw; -}; -struct buffer *buffer; -int count_component; -struct tally { - char *name; - enum entity_type type; - char *add_formula; - LDBLE moles; - struct elt_list *formula; - /* - * first total is initial - * second total is final - * third total is difference (final - initial) - */ - struct buffer *total[3]; -}; -struct tally *tally_table; -int count_tally_table_columns; -int count_tally_table_rows; - -static int elt_list_to_tally_table(struct buffer *buffer_ptr); - -/* - Calling sequence - -Initialization: ---------------- - -build_tally_table(); finds all elements (rows), - possible return values (columns), - allocates space -get_tally_table_rows_columns(int *rows, int *columns) - returns number of rows and columns in table -get_tally_table_row_heading(int row, char *string) - row is C row number - returns row descripter for row -get_tally_table_column_heading(int column, int *type, char *string) - column is C column number - returns column heading for column - -Each call to phreeqc: ---------------------- - -zero_tally_table(); initialize table to 0s -set_reaction_moles(n_user, moles) n_user is reservoir number - moles is number of moles of reaction to add - -int set_reaction_temperature(n_user, tc) - -fill_tally_table(int *n_user, int index_conservative, int n_buffer) - n_user is reservoir number - index_conservative is solution number - where conservative mixing is stored - slot is 0 for initial - - run phreeqc here. - -fill_tally_table(int *n_user, int index_conservative, int n_buffer) - n_user is reservoir number - index_conservative is solution number - where conservative mixing is stored - slot is 1 for final -store_tally_table(double *array, int row_dim, int col_dim, double fill_factor) - row_dim is Fortran dimension - col_dim is Fortran dimension - array is space from Fortran - stores conservative mixing (column 0) - stores reaction (column 1) - difference between slot 1 and slot 0 for - all other intities (columns 2-n) - -Finalization: -------------- -int free_tally_table(void); Frees space - -*/ - -/* ---------------------------------------------------------------------- */ -int get_all_components(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Counts components in any defined solution, gas_phase, exchanger, - * surface, or pure_phase_assemblage - * - * Returns n_comp, which is total, including H, O, elements, and Charge - * names contains character strings with names of components - */ - int i, j; -/* - * Accumulate all aqueous components - */ - add_all_components_tally(); -/* - * Count components, 2 for hydrogen, oxygen, + others, - */ - count_component = 0; - for (i = 0; i < count_master; i++) { - if (master[i]->total > 0.0 && master[i]->s->type == AQ) { - count_component++; - } - } -/* - * Put information in buffer. - * Buffer contains an entry for every primary master - * species that can be used in the transport problem. - * Each entry in buffer is sent to HST for transort. - */ - buffer = (struct buffer *) PHRQ_malloc ((size_t) count_component * sizeof(struct buffer)); - j = 0; - for (i = 0; i < count_master; i++) { - if (master[i]->total > 0.0 && master[i]->s->type == AQ) { - buffer[j].name = master[i]->elt->name; - buffer[j].master = master[i]; - buffer[j].gfw = master[i]->elt->gfw; - j++; - } - } -#ifdef SKIP - output_msg(OUTPUT_MESSAGE, "List of Components:\n"); - for (i = 0; i < count_component; i++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\n", i+1, buffer[i].name); - /* - for (j=0; buffer[i].name[j] != '\0'; j++) { - names[i * length + j] = buffer[i].name[j]; - } - */ - } -#endif - /* - * Return value - */ - /**n_comp = count_component;*/ - count_tally_table_rows = count_component; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int store_tally_table(double *array, int row_dim, int col_dim, double fill_factor) -/* ---------------------------------------------------------------------- */ -{ - int i,j; - if (tally_table == NULL) { - input_error++; - error_msg("Tally table not defined, get_tally_table_rows_columns", CONTINUE); - return(ERROR); - } - if (count_tally_table_rows > row_dim) { - input_error++; - error_msg("Too many tally table rows for Fortran storage, store_tally_table", CONTINUE); - return(ERROR); - } - if (count_tally_table_columns > col_dim) { - input_error++; - error_msg("Too many tally table columns for Fortran storage, store_tally_table", CONTINUE); - return(ERROR); - } - /* - * store conservative mixing solution - */ - for (j = 0; j < count_tally_table_rows; j++) { - array[j] = tally_table[0].total[1][j].moles; - } - /* - * store reaction solution - */ - for (j = 0; j < count_tally_table_rows; j++) { - array[row_dim + j] = tally_table[1].total[1][j].moles; - } - /* - * Calculate deltas - */ - - diff_tally_table(); - - /* - * store deltas for all other columns - */ - for (i = 2; i < count_tally_table_columns; i++) { - for (j = 0; j < count_tally_table_rows; j++) { - array[i*row_dim + j] = tally_table[i].total[2][j].moles/fill_factor; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_tally_table_rows_columns(int *rows, int *columns) -/* ---------------------------------------------------------------------- */ -{ - *rows = 0; - *columns = 0; - if (tally_table == NULL) { - input_error++; - error_msg("tally table not defined, get_tally_table_rows_columns", CONTINUE); - return(ERROR); - } - *rows = count_tally_table_rows; - *columns = count_tally_table_columns; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_tally_table_row_heading(int row, char *string) -/* ---------------------------------------------------------------------- */ -{ - /* - * row is C row number - */ - strcpy(string, ""); - if (tally_table == NULL) { - input_error++; - error_msg("Tally table not defined, get_tally_table row_heading", CONTINUE); - return(ERROR); - } - if (row >= count_tally_table_rows) { - input_error++; - error_msg("Row exceeds tally table size, get_tally_table row_heading", CONTINUE); - return(ERROR); - } - strcpy(string, buffer[row].name); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int get_tally_table_column_heading(int column, int *type, char *string) -/* ---------------------------------------------------------------------- */ -{ - /* - * column is C column number - */ - *type = -1; - strcpy(string, ""); - if (tally_table == NULL) { - input_error++; - error_msg("tally table not defined, get_tally_table_column_heading", CONTINUE); - return(ERROR); - } - if (column >= count_tally_table_columns) { - input_error++; - error_msg("column exceeds tally table size, get_tally_table_column_heading", CONTINUE); - return(ERROR); - } - strcpy(string, tally_table[column].name); - *type = tally_table[column].type; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int free_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ - int i, k; - if (tally_table == NULL) return(OK); - for (i = 0; i < count_tally_table_columns; i++) { - if (tally_table[i].formula != NULL) (struct elt_list *) free_check_null(tally_table[i].formula); - for (k = 0; k < 3; k++) { - tally_table[i].total[k] = (struct buffer *) free_check_null(tally_table[i].total[k]); - } - } - tally_table = (struct tally *) free_check_null(tally_table); - buffer = (struct buffer *) free_check_null(buffer); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int zero_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k; - for (i = 0; i < count_tally_table_columns; i++) { - for (j = 0; j < count_tally_table_rows; j++) { - for (k = 0; k < 3; k++) { - tally_table[i].total[k][j].moles = 0; - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int diff_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - /* - output_msg(OUTPUT_MESSAGE,"Difference\n\n"); - */ - for (i = 0; i < count_tally_table_columns; i++) { - for (j = 0; j < count_tally_table_rows; j++) { - tally_table[i].total[2][j].moles = tally_table[i].total[1][j].moles - tally_table[i].total[0][j].moles; - } - - /* - output_msg(OUTPUT_MESSAGE, "Column %d\t%s\tType: %d\n", i, tally_table[i].name, tally_table[i].type); - for (j = 0; j < count_tally_table_rows; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\t%e\n", j, tally_table[i].total[2][j].name, (double) tally_table[i].total[2][j].moles); - } - */ - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - output_msg(OUTPUT_MESSAGE,"Tally_table\n\n"); - for (i = 0; i < count_tally_table_columns; i++) { - output_msg(OUTPUT_MESSAGE, "%s\tType: %d\n", tally_table[i].name, tally_table[i].type); - output_msg(OUTPUT_MESSAGE,"\n"); - output_msg(OUTPUT_MESSAGE, "\t%15s\t%15s\t%15s\n", "Initial", "Final", "Difference"); - for (j = 0; j < count_tally_table_rows; j++) { - output_msg(OUTPUT_MESSAGE,"%5s\t%15g\t%15g\t%15g\n", buffer[j].name, tally_table[i].total[0][j].moles, tally_table[i].total[1][j].moles, tally_table[i].total[2][j].moles); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int fill_tally_table(int *n_user, int index_conservative, int n_buffer) -/* ---------------------------------------------------------------------- */ -{ -/* - * Routine accumulates elements from all solutions, phases, gas phases, - * exchangers, and surfaces. - */ - int i, j, k, n; - struct solution *solution_ptr; - struct irrev *irrev_ptr; - struct pp_assemblage *pp_assemblage_ptr; - struct exchange *exchange_ptr; - struct surface *surface_ptr; - struct s_s_assemblage *s_s_assemblage_ptr; - struct gas_phase *gas_phase_ptr; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; - int found; - LDBLE moles; - char *ptr; - /* - * Cycle through tally table columns - */ - for (i = 0; i < count_tally_table_columns; i++) { - switch (tally_table[i].type) { - case Solution: -/* - * fill solution - */ - if (n_user[Solution] < 0 || n_buffer == 0) break; - if (i == 0) { - solution_ptr = solution_bsearch(index_conservative, &n, TRUE); - } else if (i == 1) { - solution_ptr = solution_bsearch(n_user[Solution], &n, TRUE); - } else { - solution_ptr = NULL; - error_msg("Solution is not in first two columns of tally_table", STOP); - } - if (solution_ptr == NULL) break; - xsolution_zero(); - add_solution(solution_ptr, 1.0, 1.0); - count_elts = 0; - paren_count = 0; - for (j=0; j < count_master; j++) { - if (master[j]->total > 0.0) { - ptr = master[j]->elt->primary->elt->name; - get_elts_in_species (&ptr, master[j]->total); - } - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Reaction: - /* - * fill reaction - */ - if (n_user[Reaction] < 0) break; - irrev_ptr = irrev_bsearch(n_user[Reaction], &n); - if (irrev_ptr == NULL) break; - count_elts = 0; - paren_count = 0; - if (n_buffer == 1) { - moles = irrev_ptr->steps[0]; - } else { - moles = 0.0; - } - add_elt_list(irrev_ptr->elts, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Pure_phase: - /* - * fill an equilibrium phase - */ - if (n_user[Pure_phase] < 0) break; - pp_assemblage_ptr = pp_assemblage_bsearch(n_user[Pure_phase], &n); - if (pp_assemblage_ptr == NULL) break; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { - if (pp_assemblage_ptr->pure_phases[j].name == tally_table[i].name) break; - if (strcmp_nocase(pp_assemblage_ptr->pure_phases[j].name, tally_table[i].name) == 0) break; - } - if (j >= pp_assemblage_ptr->count_comps) break; - count_elts = 0; - paren_count = 0; - moles = pp_assemblage_ptr->pure_phases[j].moles; - add_elt_list(tally_table[i].formula, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Exchange: - /* - * fill exchange - */ - if (n_user[Exchange] < 0) break; - exchange_ptr = exchange_bsearch(n_user[Exchange], &n); - if (exchange_ptr == NULL) break; - count_elts = 0; - paren_count = 0; - for (j = 0; j < exchange_ptr->count_comps; j++) { - add_elt_list(exchange_ptr->comps[j].totals, 1.0); - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Surface: - /* - * fill surface - */ - if (n_user[Surface] < 0) break; - surface_ptr = surface_bsearch(n_user[Surface], &n); - if (surface_ptr == NULL) break; - count_elts = 0; - paren_count = 0; - for (j = 0; j < surface_ptr->count_comps; j++) { - add_elt_list(surface_ptr->comps[j].totals, 1.0); - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Ss_phase: - /* - * fill an solid solution phase - */ - if (n_user[Ss_phase] < 0) break; - s_s_assemblage_ptr = s_s_assemblage_bsearch(n_user[Ss_phase], &n); - if (s_s_assemblage_ptr == NULL) break; - found = FALSE; - moles = 0.0; - for (j = 0; j < s_s_assemblage_ptr->count_s_s; j++) { - for (k = 0; k < s_s_assemblage_ptr->s_s[j].count_comps; k++) { - if (s_s_assemblage_ptr->s_s[j].comps[k].phase->name == tally_table[i].name) break; - if (strcmp_nocase(s_s_assemblage_ptr->s_s[j].comps[k].phase->name, tally_table[i].name) == 0) break; - } - if (k < s_s_assemblage_ptr->s_s[j].count_comps) { - moles = s_s_assemblage_ptr->s_s[j].comps[k].moles; - found = TRUE; - break; - } - } - if (found == FALSE) break; - count_elts = 0; - paren_count = 0; - add_elt_list(tally_table[i].formula, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Gas_phase: - /* - * fill in gas phase - */ - if (n_user[Gas_phase] < 0) break; - gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); - if (gas_phase_ptr == NULL) break; - count_elts = 0; - paren_count = 0; - for (j = 0; j < gas_phase_ptr->count_comps; j++) { - add_elt_list(gas_phase_ptr->comps[j].phase->next_elt, gas_phase_ptr->comps[j].moles); - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Kinetics: - /* - * fill in kinetics - */ - if (n_user[Kinetics] < 0) break; - kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); - if (kinetics_ptr == NULL) break; - kinetics_comp_ptr = NULL; - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_comp_ptr = &kinetics_ptr->comps[j]; - if (kinetics_comp_ptr->rate_name == tally_table[i].name) break; - if (strcmp_nocase(kinetics_comp_ptr->rate_name, tally_table[i].name) == 0) break; - } - if (j >= kinetics_ptr->count_comps) break; - moles = kinetics_comp_ptr->m; - count_elts = 0; - paren_count = 0; - add_elt_list(tally_table[i].formula, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; - case Mix: - break; - case Temperature: - break; - case UnKnown: - break; - } -#ifdef SKIP - output_msg(OUTPUT_MESSAGE, "Column %d\t%s\tType: %d\n", i, tally_table[i].name, tally_table[i].type); - for (j = 0; j < count_tally_table_rows; j++) { - output_msg(OUTPUT_MESSAGE, "\t%d\t%s\t%e\n", j, tally_table[i].total[n_buffer][j].name, (double) tally_table[i].total[n_buffer][j].moles); - } -#endif - } - - return(OK); -} - -/* ---------------------------------------------------------------------- */ -int elt_list_to_tally_table(struct buffer *buffer_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - for (i = 0; i < count_tally_table_rows; i++) { - buffer_ptr[i].moles=0.0; - } - /* - * copy element list amounts to buffer in tally table - * for column number - */ - - for ( j=0; j < count_elts; j++ ) { - if (elt_list[j].elt->primary->s == s_h2o) continue; - if (elt_list[j].elt->primary->s == s_hplus) continue; - if (elt_list[j].elt->primary->s == s_h3oplus) continue; - if (elt_list[j].elt->primary->type != AQ) continue; - for (i = 0; i < count_tally_table_rows; i++) { - if (elt_list[j].elt->primary == buffer_ptr[i].master->elt->primary) { - buffer_ptr[i].moles=elt_list[j].coef; - break; - } - } - if (i >= count_tally_table_rows) { - error_msg("Should not be here in elt_list_to_tally_table", STOP); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int build_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Routine accumulates elements from all solutions, phases, gas phases, - * exchangers, and surfaces. Counts number of aqueous components - * to transport. Stores in global variable count_component. - * Also calculates a number greater than all user numbers and - * stores in global variable first_user_number. - */ - int i, j, k, l, n, p, save_print_use; - int count_tt_reaction, count_tt_exchange, count_tt_surface, count_tt_gas_phase; - int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; - struct pp_assemblage *pp_assemblage_ptr; - struct pure_phase *pure_phase_ptr; - struct s_s_assemblage *s_s_assemblage_ptr; - struct s_s *s_s_ptr; - struct s_s_comp *s_s_comp_ptr; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; - struct phase *phase_ptr; - - - char token[MAX_LENGTH]; - char *ptr; - - if (svnid == NULL) fprintf(stderr," "); -/* - * make list of all elements in all entitites - * defines the number of rows in the table - */ - get_all_components(); - - save_print_use = pr.use; - pr.use = FALSE; -/* - * find nuber of columns - */ - count_tally_table_columns = 0; -/* - * add one for conservative mixing - */ - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Solution_conservative"); - tally_table[n].type = Solution; -/* - * add one for mixing plus reaction - */ - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Solution_reaction"); - tally_table[n].type = Solution; -/* - * add one for reactions - */ - if (count_irrev > 0) { - count_tt_reaction = 1; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Reaction"); - tally_table[n].type = Reaction; - } else { - count_tt_reaction = 0; - } -/* - * add one for exchangers - */ - if (count_exchange > 0) { - count_tt_exchange = 1; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Exchange"); - tally_table[n].type = Exchange; - } else { - count_tt_exchange = 0; - } -/* - * add one for surface - */ - if (count_surface > 0) { - count_tt_surface = 1; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Surface"); - tally_table[n].type = Surface; - } else { - count_tt_surface = 0; - } -/* - * add one for gases - */ - if (count_gas_phase > 0) { - count_tt_gas_phase = 1; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Gas_phase"); - tally_table[n].type = Gas_phase; - } else { - count_tt_gas_phase = 0; - } -/* - * Count pure phases - */ - count_tt_pure_phase = 0; - if (count_pp_assemblage > 0) { - /* - * Go through all pure phases in pure phase assemblages - */ - for (i = 0; i < count_pp_assemblage; i++) { - pp_assemblage_ptr = &pp_assemblage[i]; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { - pure_phase_ptr = &pp_assemblage_ptr->pure_phases[j]; - /* - * check if already in tally_table - */ - for (k = 1; k < count_tally_table_columns; k++) { - if (tally_table[k].type == Pure_phase && - tally_table[k].name == pure_phase_ptr->phase->name && - tally_table[k].add_formula == pure_phase_ptr->add_formula) break; - } - if (k < count_tally_table_columns) continue; - /* - * Add to table - */ - count_tt_pure_phase++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = pure_phase_ptr->phase->name; - tally_table[n].type = Pure_phase; - tally_table[n].add_formula = pure_phase_ptr->add_formula; - count_elts = 0; - paren_count = 0; - if (pure_phase_ptr->add_formula != NULL) { - strcpy(token, pure_phase_ptr->add_formula); - ptr = &(token[0]); - get_elts_in_species (&ptr, 1.0); - } else { - strcpy(token, pure_phase_ptr->phase->formula); - add_elt_list(pure_phase_ptr->phase->next_elt, 1.0); - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } -/* - * Add solid-solution pure phases - */ - count_tt_ss_phase = 0; - if (count_pp_assemblage > 0) { - /* - * Go through all components of all solid solutions in solid-solution assemblages - */ - for (i = 0; i < count_s_s_assemblage; i++) { - s_s_assemblage_ptr = &s_s_assemblage[i]; - for (j = 0; j < s_s_assemblage_ptr->count_s_s; j++) { - s_s_ptr = &s_s_assemblage_ptr->s_s[j]; - for (k = 0; k < s_s_ptr->count_comps; k++) { - s_s_comp_ptr = &s_s_ptr->comps[k]; - /* - * check if already in tally_table - */ - for (l = 1; l < count_tally_table_columns; l++) { - if (tally_table[l].type == Ss_phase && - tally_table[l].name == s_s_comp_ptr->phase->name) break; - } - if (l < count_tally_table_columns) continue; - /* - * Add to table - */ - count_tt_ss_phase++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = s_s_comp_ptr->phase->name; - tally_table[n].type = Ss_phase; - count_elts = 0; - paren_count = 0; - strcpy(token, s_s_comp_ptr->phase->formula); - add_elt_list(s_s_comp_ptr->phase->next_elt, 1.0); - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } - } -/* - * Add kinetic reactants - */ - count_tt_kinetics = 0; - if (count_kinetics > 0) { - for (i = 0; i < count_kinetics; i++) { - kinetics_ptr = &kinetics[i]; - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_comp_ptr = &kinetics_ptr->comps[j]; - /* - * check if already in tally_table - */ - for (l = 1; l < count_tally_table_columns; l++) { - if (tally_table[l].type == Kinetics && - tally_table[l].name == kinetics_comp_ptr->rate_name) break; - } - if (l < count_tally_table_columns) continue; - /* - * Add to table - */ - count_tt_kinetics++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = kinetics_comp_ptr->rate_name; - tally_table[n].type = Kinetics; - /* - * get formula for kinetic component - */ - count_elts = 0; - paren_count = 0; - phase_ptr = NULL; - if (kinetics_ptr->comps[j].count_list == 1) { - strcpy(token, kinetics_ptr->comps[j].list[0].name); - phase_ptr = phase_bsearch(token, &p, FALSE); - } - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, 1.0); - } else { - for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) { - ptr = kinetics_ptr->comps[j].list[k].name; - get_elts_in_species (&ptr, 1.0 * kinetics_ptr->comps[j].list[k].coef); - } - } - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } -#ifdef SKIP - /* - * Debug print for table definition - */ - output_msg(OUTPUT_MESSAGE, "List of rows for tally table\n"); - for (i = 0; i < count_tally_table_rows; i++) { - output_msg(OUTPUT_MESSAGE, "\t%-s\n", buffer[i].name); - } - output_msg(OUTPUT_MESSAGE, "\nList of columns for tally table\n"); - for (i = 0; i < count_tally_table_columns; i++) { - output_msg(OUTPUT_MESSAGE, "\t%-20s\tType: %d\n", tally_table[i].name, tally_table[i].type); - if (tally_table[i].formula != NULL) { - for (j = 0; tally_table[i].formula[j].elt != NULL; j++) { - output_msg(OUTPUT_MESSAGE,"\t\t%-10s\t%f\n", tally_table[i].formula[j].elt->name, (double) tally_table[i].formula[j].coef); - } - } - } -#endif - pr.use = save_print_use; - return(OK); -} -/* ---------------------------------------------------------------------- */ -void add_all_components_tally(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Routine accumulates elements from all solutions, phases, gas phases, - * exchangers, and surfaces. Counts number of aqueous components - * to transport. Stores in global variable count_component. - * Also calculates a number greater than all user numbers and - * stores in global variable first_user_number. - */ - int i, save_print_use; - - save_print_use = pr.use; - pr.use = FALSE; -/* - * Delete solutions less than -1 - */ - while (count_solution > 0 && solution[0]->n_user < -1) { - i = solution[0]->n_user; - solution_delete(i); - } -/* - * add all solutions - */ - xsolution_zero(); - for (i = 0; i < count_solution; i++) { - add_solution(solution[i], 1.0/solution[i]->mass_water, 1.0); - } -/* - * add all irrev reactions - */ - for (i = 0; i < count_irrev; i++) { - add_reaction(&irrev[i], 1, 1.0); - } -/* - * Add pure phases - */ - for (i = 0; i < count_pp_assemblage; i++) { - add_pp_assemblage(&pp_assemblage[i]); - } -/* - * Exchangers - */ - for (i = 0; i < count_exchange; i++) { - add_exchange(&exchange[i]); - } -/* - * Surfaces - */ - for (i = 0; i < count_surface; i++) { - add_surface(&surface[i]); - } -/* - * Gases - */ - for (i = 0; i < count_gas_phase; i++) { - add_gas_phase(&gas_phase[i]); - } -/* - * Add solid-solution pure phases - */ - for (i = 0; i < count_s_s_assemblage; i++) { - add_s_s_assemblage(&s_s_assemblage[i]); - } -/* - * Add elements in kinetic reactions - */ - for (i = 0; i < count_kinetics; i++) { - calc_dummy_kinetic_reaction_tally(&kinetics[i]); - add_kinetics(&kinetics[i]); - } -/* - * reset pr.use - */ - pr.use = save_print_use; - return; -} -/* ---------------------------------------------------------------------- */ -int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components and add positive amount of each reactant - */ - int i, j; - LDBLE coef; - char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - free_check_null(kinetics_ptr->totals); - count_elts = 0; - paren_count = 0; - for (i=0; i < kinetics_ptr->count_comps; i++) { - coef = 1.0; -/* - * Reactant is a pure phase, copy formula into token - */ - phase_ptr = NULL; - if (kinetics_ptr->comps[i].count_list == 1) { - strcpy(token, kinetics_ptr->comps[i].list[0].name); - phase_ptr = phase_bsearch(token, &j, FALSE); - } - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, coef); - } else { - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) { - ptr = kinetics_ptr->comps[i].list[j].name; - get_elts_in_species (&ptr, coef); - } - } - - } - kinetics_ptr->totals = elt_list_save(); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int extend_tally_table(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - /* - * adds another column to tally_table - * increments number of columns - */ - tally_table = (struct tally *)PHRQ_realloc((void *) tally_table, (size_t) (count_tally_table_columns + 1) * sizeof(struct tally)); - if (tally_table == NULL) malloc_error(); - for (i = 0; i < 3; i++) { - tally_table[count_tally_table_columns].total[i] = (struct buffer *)PHRQ_malloc( (size_t) (count_tally_table_rows) * sizeof( struct buffer )); - if (tally_table[count_tally_table_columns].total[i] == NULL) malloc_error(); - for (j = 0; j < count_tally_table_rows; j++) { - tally_table[count_tally_table_columns].total[i][j].name = buffer[j].name; - tally_table[count_tally_table_columns].total[i][j].master = buffer[j].master; - } - } - tally_table[count_tally_table_columns].name = NULL; - tally_table[count_tally_table_columns].type = UnKnown; - tally_table[count_tally_table_columns].add_formula = NULL; - tally_table[count_tally_table_columns].moles = 0.0; - tally_table[count_tally_table_columns].formula = NULL; - count_tally_table_columns++; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_reaction_moles(int n_user, LDBLE moles) -/* ---------------------------------------------------------------------- */ -{ - int n; - struct irrev *irrev_ptr; - - irrev_ptr = irrev_bsearch(n_user, &n); - if (irrev_ptr == NULL) return(ERROR); - irrev_ptr->steps[0] = moles; - irrev_ptr->count_steps = 1; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_reaction_temperature(int n_user, LDBLE tc) -/* ---------------------------------------------------------------------- */ -{ - int n; - struct temperature *temperature_ptr; - - temperature_ptr = temperature_bsearch(n_user, &n); - if (temperature_ptr == NULL) return(ERROR); - temperature_ptr->t[0] = tc; - temperature_ptr->count_t = 1; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_kinetics_time(int n_user, LDBLE step) -/* ---------------------------------------------------------------------- */ -{ - int n; - struct kinetics *kinetics_ptr; - - kinetics_ptr = kinetics_bsearch(n_user, &n); - if (kinetics_ptr == NULL) return(ERROR); - kinetics_ptr->steps[0] = step; - kinetics_ptr->count_steps = 1; - return(OK); -} - diff --git a/tidy.cpp b/tidy.cpp deleted file mode 100644 index b76b509f..00000000 --- a/tidy.cpp +++ /dev/null @@ -1,3333 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: tidy.c 407 2005-07-27 22:06:36Z dlpark $"; - -static int check_species_input(void); -static LDBLE coef_in_master(struct master *master_ptr); -static int phase_rxn_to_trxn(struct phase *phase_ptr); -static int reset_last_model(void); -static int rewrite_eqn_to_primary(void); -static int rewrite_eqn_to_secondary(void); -static int species_rxn_to_trxn(struct species *s_ptr); -static int tidy_min_exchange(void); -static int tidy_kin_exchange(void); -static int tidy_gas_phase(void); -static int tidy_inverse(void); -static int tidy_isotopes (void); -static int tidy_isotope_ratios(void); -static int tidy_isotope_alphas(void); -static int tidy_kin_surface(void); -static int tidy_master_isotope (void); -static int tidy_min_surface(void); -static int tidy_phases(void); -static int tidy_pp_assemblage(void); -static int tidy_solutions(void); -static int tidy_s_s_assemblage(void); -static int tidy_species(void); -static int tidy_surface(void); - -static LDBLE a0, a1, kc, kb; -static int scan(LDBLE f(LDBLE x), LDBLE *xx0, LDBLE *xx1); -static LDBLE halve(LDBLE f(LDBLE x), LDBLE x0, LDBLE x1, LDBLE tol); -static LDBLE f_spinodal(LDBLE x); -static int solve_misc(LDBLE *xxc1, LDBLE *xxc2, LDBLE tol); -static int s_s_calc_a0_a1(struct s_s *s_s_ptr); -#define ZERO_TOL 1.0e-30 - -/* ---------------------------------------------------------------------- */ -int tidy_model(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - int n_user, last; - if (svnid == NULL) fprintf(stderr," "); - /* - * Determine if any new elements, species, phases have been read - */ - new_model = FALSE; - new_pp_assemblage = FALSE; - new_surface = FALSE; - new_exchange = FALSE; - new_reaction = FALSE; - new_temperature = FALSE; - new_mix = FALSE; - new_solution = FALSE; - new_gas_phase = FALSE; - new_inverse = FALSE; - new_punch = FALSE; - new_surface = FALSE; - new_s_s_assemblage = FALSE; - new_kinetics = FALSE; - new_pitzer = FALSE; - if (keyword[2].keycount > 0 || /*"species"*/ - keyword[3].keycount > 0 || /*"master"*/ - keyword[5].keycount > 0 || /*"phases"*/ - keyword[11].keycount > 0 || /*"exchange_species"*/ - keyword[12].keycount > 0 || /*"master_exchange_species"*/ - keyword[14].keycount > 0 || /*"surface_species"*/ - keyword[15].keycount > 0 || /*"master_surface_species"*/ - keyword[36].keycount > 0 || /*"rates"*/ - keyword[47].keycount > 0 || /*"llnl_aqueous_model_parameters"*/ - (keyword[49].keycount > 0 && simulation == 0) || /*"database"*/ - keyword[51].keycount > 0 || /*"named_analytical_expressions"*/ - keyword[54].keycount > 0 || /*"isotopes"*/ - keyword[55].keycount > 0 || /*"calculate_values"*/ - keyword[56].keycount > 0 || /*"isotopes_ratios",*/ - keyword[57].keycount > 0 || /*"isotopes_alphas"*/ - keyword[59].keycount > 0 ) { /*"pitzer"*/ - new_model = TRUE; - } - if (keyword[6].keycount > 0) new_pp_assemblage = TRUE; /*"pure_phases"*/ - if (keyword[16].keycount > 0) new_surface = TRUE; /*"surface"*/ - if (keyword[13].keycount > 0) new_exchange = TRUE; /*"exchange"*/ - if (keyword[7].keycount > 0) new_reaction = TRUE; /*"reaction"*/ - if (keyword[17].keycount > 0) new_temperature = TRUE; /*"reacton_temperature"*/ - if (keyword[8].keycount > 0) new_mix = TRUE; /*"mix"*/ - if (keyword[4].keycount > 0 || /*"solution"*/ - keyword[43].keycount > 0 ) { /*"spread_solution"*/ - new_solution = TRUE; - } - if (keyword[19].keycount > 0) new_gas_phase = TRUE; /*"gas_phase"*/ - if (keyword[18].keycount > 0) new_inverse = TRUE; /*"inverse_modeling"*/ - if (keyword[22].keycount > 0 || /*"selected_output"*/ - keyword[39].keycount > 0 ) { /*"user_punch"*/ - new_punch = TRUE; - } - if (keyword[40].keycount > 0) new_s_s_assemblage = TRUE;/*"solid_solutions"*/ - if (keyword[33].keycount > 0) new_kinetics = TRUE; /*"kinetics"*/ - if (keyword[58].keycount > 0) new_copy = TRUE; /*"copy"*/ - if (keyword[59].keycount > 0) new_pitzer = TRUE; /*"pitzer"*/ - - /* - 0 "eof" - 1 "end" - 2 "species" - 3 "master" - 4 "solution" - 5 "phases" - 6 "pure_phases" - 7 "reaction" - 8 "mix" - 9 "use" - 10 "save" - 11 "exchange_species" - 12 "master_exchange_species" - 13 "exchange" - 14 "surface_species" - 15 "master_surface_species" - 16 "surface" - 17 "reacton_temperature" - 18 "inverse_modeling" - 19 "gas_phase" - 20 "transport" - 21 "debug" - 22 "selected_output" - 23 "select_output" - 24 "knobs" - 25 "print" - 26 "equilibrium_phases" - 27 "equilibria" - 28 "equilibrium" - 29 "pure" - 30 "title" - 31 "comment" - 32 "advection" - 33 "kinetics" - 34 "incremental_reactions" - 35 "incremental" - 36 "rates" - 37 "solution_s" - 38 "user_print" - 39 "user_punch" - 40 "solid_solutions" - 41 "solid_solution" - 42 "solution_spread" - 43 "spread_solution" - 44 "selected_out" - 45 "select_out" - 46 "user_graph" - 47 "llnl_aqueous_model_parameters" - 48 "llnl_aqueous_model" - 49 "database" - 50 "named_analytical_expression" - 51 "named_analytical_expressions" - 52 "named_expressions" - 53 "named_log_k" - 54 "isotopes" - 55 "calculate_values" - 56 "isotopes_ratios", - 57 "isotopes_alphas" - 58 "copy" - 59 "pitzer" - */ - -/* - * Sort arrays - */ - -/* species */ - if (new_model == TRUE) { - qsort (s, - (size_t) count_s, - (size_t) sizeof (struct species *), - s_compare); - -/* master species */ - qsort (master, - (unsigned) count_master, - sizeof(struct master *), - master_compare); - -/* elements */ - qsort (elements, - (size_t) count_elements, - (size_t) sizeof (struct element *), - element_compare); -/* phases */ - qsort (phases, - (size_t) count_phases, - (size_t) sizeof (struct phase *), - phase_compare); - - } -/* pure_phases */ - if (new_pp_assemblage) pp_assemblage_sort(); - -/* solid solutions */ - if (new_s_s_assemblage) s_s_assemblage_sort(); - -/* exchangers */ - if (new_exchange) exchange_sort(); -/* surfaces */ - if (new_surface) surface_sort(); -#ifdef SKIP -/* mixtures */ - qsort (mix, - (size_t) count_mix, - (size_t) sizeof (struct mix), - mix_compare); -#endif - -/* mixtures */ -/* !!!!! - * In transport mode, with stagnant cells, cell number is 'n_mix_user' for - * both mix with stagnant cells and for dispersive mix. - * qsort(mix) then fails. Hence ... - */ - - if ((state != TRANSPORT) || (simul_tr < 2) || (stag_data->count_stag == 0)) { - mix_sort(); - } - -/* gas_phase */ - if (new_gas_phase) gas_phase_sort(); - -/* kinetics */ - if (new_kinetics) kinetics_sort(); -/* - * Check pointers, write reactions for species - */ - if (new_model) { - tidy_species(); - - tidy_phases(); - - tidy_master_isotope(); -/* - * calculate gfw of water, kg/mole - */ - compute_gfw("H2O", &gfw_water); - gfw_water *= 0.001; - } -/* - * tidy surface data - */ - if (new_model || new_surface) tidy_surface(); -/* - * tidy inverse data - */ - if (new_inverse) tidy_inverse(); -/* - * tidy gas phase data - */ - if (new_gas_phase) tidy_gas_phase(); -/* - * tidy pp_assemblage data - */ - if (new_model || new_pp_assemblage) tidy_pp_assemblage(); -/* - * tidy s_s_assemblage data - */ - if (new_model || new_s_s_assemblage) tidy_s_s_assemblage(); -/* - * tidy exchange data, after pp_assemblages - */ - if (new_exchange) tidy_min_exchange(); - if (new_exchange) tidy_kin_exchange(); -/* - * tidy surface data - */ - if (new_surface) tidy_min_surface(); - if (new_surface) tidy_kin_surface(); -/* - * tidy solution isotope data - */ - if (new_solution) tidy_isotopes(); - if (new_model) tidy_isotope_ratios(); - if (new_model) tidy_isotope_alphas(); -/* - * Duplicate reaction - */ - if (new_reaction) { - for ( i = 0; i < count_irrev; i++) { - if ( irrev[i].n_user_end > irrev[i].n_user ) { - n_user = irrev[i].n_user; - last = irrev[i].n_user_end; - irrev[i].n_user_end = irrev[i].n_user; - for (j = n_user + 1; j <= last; j++) { - irrev_duplicate(n_user, j); - } - } - } - } -/* - * Duplicate kinetics - */ - if (new_kinetics) { - for ( i = 0; i < count_kinetics; i++) { - if ( kinetics[i].n_user_end > kinetics[i].n_user ) { - n_user = kinetics[i].n_user; - last = kinetics[i].n_user_end; - kinetics[i].n_user_end = kinetics[i].n_user; - for (j = n_user + 1; j <= last; j++) { - kinetics_duplicate(n_user, j); - } - } - } - } -/* - * Duplicate temperature - */ - if (new_temperature) { - temperature_sort(); - for ( i = 0; i < count_temperature; i++) { - if ( temperature[i].n_user_end > temperature[i].n_user ) { - n_user = temperature[i].n_user; - last = temperature[i].n_user_end; - temperature[i].n_user_end = temperature[i].n_user; - for (j = n_user + 1; j <= last; j++) { - temperature_duplicate(n_user, j); - } - } - } - } -/* - * Tidy pitzer information - */ - if (pitzer_model && new_model) pitzer_tidy(); -/* - * Tidy punch information - */ - if (input_error == 0 && (new_punch || new_model)) tidy_punch(); -/* - * Tidy solution information - */ - if (new_solution) tidy_solutions(); - - /* if (new_model || new_exchange || new_pp_assemblage || new_surface || new_gas_phase || new_kinetics) reset_last_model(); */ - if (new_model) reset_last_model(); -/* - * make sure essential species are defined - */ - if (s_h2o == NULL) { - input_error++; - error_msg("H2O not defined.", STOP); - } - if (s_h2o->primary == NULL) { - input_error++; - error_msg("H2O, primary master species for O, not defined.", CONTINUE); - } - if (s_h2o->secondary == NULL) { - input_error++; - error_msg("H2O, secondary master species for O(-2), not defined.", CONTINUE); - } - if (s_hplus == NULL && s_h3oplus == NULL) { - input_error++; - error_msg("Neither H+ nor H3O+ are defined in solution_species.", STOP); - } else if (s_hplus == NULL && s_h3oplus != NULL) { - s_hplus = s_h3oplus; - s_h3oplus = NULL; - } else if (s_hplus != NULL && s_h3oplus == NULL) { - } else if (s_hplus != NULL && s_h3oplus != NULL) { - input_error++; - error_msg("Can not define both H+ and H3O+ in solution_species.", STOP); - } - if (s_hplus->primary == NULL) { - input_error++; - error_msg("H3O+, primary master species for H, not defined.", CONTINUE); - } - if (s_hplus->secondary == NULL) { - input_error++; - error_msg("H3O+, secondary master species for H(1), not defined.", CONTINUE); - } - if (s_eminus == NULL) { - input_error++; - error_msg("e- not defined in solution_species.", CONTINUE); - } - if (s_eminus->primary == NULL) { - input_error++; - error_msg("e-, primary master species for E-, not defined.", CONTINUE); - } - if (pitzer_model == FALSE) { - if (s_h2 == NULL) { - input_error++; - error_msg("H2(aq) not defined in solution_species.", CONTINUE); - } - if (s_o2 == NULL) { - input_error++; - error_msg("O2(aq) not defined in solution_species.", CONTINUE); - } - } - element_h_one = element_store ("H(1)"); - if (element_h_one == NULL) { - input_error++; - error_msg("H(1) not defined in solution_master_species.", CONTINUE); - } -/* - * Error check, program termination - */ - if (input_error > 0 || parse_error > 0 ) { - error_msg("Calculations terminating due to input errors.", STOP); - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int check_species_input(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check species data for completeness - */ - int i; - int return_value; - - return_value = OK; - for (i=0; i < count_s; i++) { - if (s[i]->next_elt == NULL) { - input_error++; - return_value = ERROR; - sprintf(error_string, "Elements in species have not been tabulated, %s.", s[i]->name); - error_msg(error_string, CONTINUE); - } - if (s[i]->rxn == NULL) { - input_error++; - return_value = ERROR; - sprintf(error_string, "Reaction for species has not been defined, %s.", s[i]->name); - error_msg(error_string, CONTINUE); - } else { - select_log_k_expression(s[i]->logk, s[i]->rxn->logk); - add_other_logk(s[i]->rxn->logk, s[i]->count_add_logk, s[i]->add_logk); - } - } - return(return_value); -} -/* ---------------------------------------------------------------------- */ -int select_log_k_expression(LDBLE *source_k, LDBLE *target_k) -/* ---------------------------------------------------------------------- */ -{ - int j, analytic; - - analytic = FALSE; - for (j=2; j < 7; j++) { - if (source_k[j] != 0.0) { - analytic = TRUE; - break; - } - } - if (analytic == TRUE) { - target_k[0] = 0.0; - target_k[1] = 0.0; - for (j=2; j < 7; j++) { - target_k[j] = source_k[j]; - } - } else { - target_k[0] = source_k[0]; - target_k[1] = source_k[1]; - for (j=2; j < 7; j++) { - target_k[j] = 0.0; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int add_other_logk(LDBLE *source_k, int count_add_logk, struct name_coef *add_logk) -/* ---------------------------------------------------------------------- */ -{ - int i, j, analytic; - struct logk *logk_ptr; - char token[MAX_LENGTH]; - LDBLE coef; - ENTRY item, *found_item; - - if (count_add_logk == 0) return(OK); - for (i = 0; i < count_add_logk; i++) { - coef = add_logk[i].coef; - strcpy(token, add_logk[i].name); - str_tolower(token); - item.key = token; - item.data = NULL; - found_item = hsearch_multi(logk_hash_table, item, FIND); - if (found_item == NULL) { - input_error++; - sprintf(error_string,"Could not find named temperature expression, %s\n", token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - logk_ptr = (struct logk *) found_item->data; - analytic = FALSE; - for (j=2; j < 7; j++) { - if (logk_ptr->log_k[j] != 0.0) { - analytic = TRUE; - break; - } - } - if (analytic == TRUE) { - for (j=2; j < 7; j++) { - source_k[j] += logk_ptr->log_k[j]*coef; - } - } else { - source_k[0] += logk_ptr->log_k[0]*coef; - source_k[1] += logk_ptr->log_k[1]*coef; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE coef_in_master(struct master *master_ptr) -/* ---------------------------------------------------------------------- */ -{ - int l; - LDBLE coef; - char *ptr; - char elt_name[MAX_LENGTH]; - struct elt_list *next_elt; - - coef = 0.0; - ptr = master_ptr->elt->name; - get_elt(&ptr, elt_name, &l); - for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL; next_elt++) { - if ( strcmp(elt_name, next_elt->elt->name) == 0 ) { - coef= next_elt->coef; - break; - } - } - return(coef); -} -/* ---------------------------------------------------------------------- */ -int rewrite_eqn_to_secondary(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Write equation for species in terms of secondary species - * Result is in trxn. - */ - LDBLE coef; - int repeat, i, add_count; - struct rxn_token_temp *token_ptr; -/* - * - */ - add_count=0; - repeat=TRUE; -/* - * Reduce reaction equation to primary and secondary species - */ - while (repeat == TRUE) { - repeat = FALSE; - /* Check for too many iterations */ - if (++add_count > MAX_ADD_EQUATIONS) { - parse_error++; - sprintf(error_string, "Could not reduce equation to secondary master species, %s.", trxn.token[0].name); - error_msg(error_string, CONTINUE); - break; - } - - for (i=1; i < count_trxn; i++) { - token_ptr = &(trxn.token[i]); - if (token_ptr->s->secondary == NULL && - token_ptr->s->primary == NULL) { - coef=token_ptr->coef; - trxn_add(token_ptr->s->rxn, coef, TRUE); - repeat=TRUE; - break; - } - } - } - trxn_combine(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int rewrite_eqn_to_primary(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Write equation for secondary master species in terms of primary master species - * Store result in reaction structure for master species - * rewrite if necessary. - * - */ - int repeat, j, add_count; - -/* - * Check secondary master species - */ - repeat=TRUE; - add_count=0; -/* - * Check if reaction contains only primary master species - */ - while (repeat == TRUE) { - repeat=FALSE; -/* - * Check for too many iterations - */ - if (++add_count > MAX_ADD_EQUATIONS) { - parse_error++; - sprintf(error_string, "Could not reduce equation to primary master species, %s.", trxn.token[0].s->name); - error_msg(error_string, CONTINUE); - break; - } -/* - * Go through species in reaction for secondary master species, look for non-primary - * species as reactants, rewrite - */ - for (j=1; j < count_trxn; j++) { - if (trxn.token[j].s->primary == NULL) { - trxn_add(trxn.token[j].s->rxn, trxn.token[j].coef, TRUE); - repeat = TRUE; - break; - } - } - } - trxn_combine(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, n_user, last; - struct phase *phase_ptr; -/* - * Find all gases for each gas_phase in phase list - */ - for (i = 0; i < count_gas_phase; i++) { - if (gas_phase[i].new_def != TRUE) continue; - gas_phase[i].new_def = FALSE; - for (j=0; j < gas_phase[i].count_comps; j++) { - phase_ptr = phase_bsearch(gas_phase[i].comps[j].name, &k, FALSE); - if (phase_ptr == NULL) { - input_error++; - sprintf(error_string, "Gas not found in PHASES data base, %s.", gas_phase[i].comps[j].name); - error_msg(error_string, CONTINUE); - continue; - } else { - gas_phase[i].comps[j].phase = phase_ptr; - } -/* - * Fixed pressure - */ - if (gas_phase[i].type == PRESSURE) { - if (gas_phase[i].solution_equilibria == TRUE) { - input_error++; - sprintf(error_string, "Gas phase %d: can not use '-equilibrium' option with fixed pressure gas phase.", gas_phase[i].n_user); - error_msg(error_string, CONTINUE); - } - /* calculate moles */ - if (gas_phase[i].comps[j].p_read != NAN) { - gas_phase[i].comps[j].moles = gas_phase[i].comps[j].p_read * - gas_phase[i].volume/R_LITER_ATM/gas_phase[i].temperature; - } else { - input_error++; - sprintf(error_string, "Gas phase %d: partial pressure of gas component %s not defined.", gas_phase[i].n_user, gas_phase[i].comps[j].name); - error_msg(error_string, CONTINUE); - } - } else { -/* - * Fixed volume - */ - if (gas_phase[i].solution_equilibria == FALSE) { - if (gas_phase[i].comps[j].p_read != NAN) { - gas_phase[i].comps[j].moles = gas_phase[i].comps[j].p_read * gas_phase[i].volume/R_LITER_ATM/gas_phase[i].temperature; - } else { - input_error++; - sprintf(error_string, "Gas phase %d: moles of gas component %s not defined.", gas_phase[i].n_user, gas_phase[i].comps[j].name); - error_msg(error_string, CONTINUE); - } - } - } -/* - * Duplicate gas phase, only if not solution equilibria - */ - } - if (gas_phase[i].solution_equilibria == FALSE) { - n_user = gas_phase[i].n_user; - last = gas_phase[i].n_user_end; - gas_phase[i].n_user_end = gas_phase[i].n_user; - for (j = n_user + 1; j <= last; j++) { - gas_phase_duplicate(n_user, j); - } - } else { - gas_phase[i].new_def = TRUE; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_inverse(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * After all of data are read, fill in data for an inverse structure, - * including master species pointers, phase pointers, and uncertainties - * and a list of all elements from phases or -balance input. - */ - int i, j, k, l; - int count_in; - LDBLE value; - struct inv_elts *inv_elts; - struct master *master_ptr; - struct master *master_alk_ptr; - struct elt_list *elt_list_ptr; - master_alk_ptr = master_bsearch("Alkalinity"); - for (i = 0; i < count_inverse; i++) { - if (inverse[i].new_def != TRUE) continue; -/* - * Set default uncertainties for all solutions, if necessary - */ - if (inverse[i].count_uncertainties < inverse[i].count_solns) { - inverse[i].uncertainties = (LDBLE *)PHRQ_realloc(inverse[i].uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); - if (inverse[i].uncertainties == NULL) malloc_error(); - for (j = inverse[i].count_uncertainties; j < inverse[i].count_solns; j++) { - inverse[i].uncertainties[j] = inverse[i].uncertainties[inverse[i].count_uncertainties - 1]; - } - } -/* - * Set default ph uncertainties for all solutions, if necessary - */ - if (inverse[i].count_ph_uncertainties < inverse[i].count_solns) { - inverse[i].ph_uncertainties = (LDBLE *)PHRQ_realloc(inverse[i].ph_uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); - if ( inverse[i].ph_uncertainties == NULL) malloc_error(); - for (j = inverse[i].count_ph_uncertainties; j < inverse[i].count_solns; j++) { - inverse[i].ph_uncertainties[j] = inverse[i].ph_uncertainties[inverse[i].count_ph_uncertainties - 1]; - } - } -/* - * Set default force for all solutions - */ - if (inverse[i].count_force_solns < inverse[i].count_solns) { - inverse[i].force_solns = (int *) PHRQ_realloc(inverse[i].force_solns, (size_t) inverse[i].count_solns * sizeof (int)); - if (inverse[i].force_solns == NULL) malloc_error(); - for (j = inverse[i].count_force_solns; j < inverse[i].count_solns; j++) { - inverse[i].force_solns[j] = FALSE; - } - } -/* - * Find master species for element, set uncertainties - */ - for (j = 0; j < inverse[i].count_elts; j++) { - inverse[i].elts[j].master = master_bsearch_primary(inverse[i].elts[j].name); - if (inverse[i].elts[j].master == NULL) { - input_error++; - sprintf(error_string, "No master species for element, %s.", inverse[i].elts[j].name); - error_msg(error_string, CONTINUE); - continue; - } - inverse[i].elts[j].uncertainties = (double *) PHRQ_realloc(inverse[i].elts[j].uncertainties, (size_t) inverse[i].count_solns * sizeof (LDBLE)); - if (inverse[i].elts[j].uncertainties == NULL) malloc_error(); - if (inverse[i].elts[j].count_uncertainties == 0) { -/* use default uncertainties for element */ - for (k=0; k < inverse[i].count_solns; k++) { - inverse[i].elts[j].uncertainties[k] = inverse[i].uncertainties[k]; - } - } else if (inverse[i].elts[j].count_uncertainties < inverse[i].count_solns) { -/* use input uncertainties, fill in any missing at end */ - value = inverse[i].elts[j].uncertainties[inverse[i].elts[j].count_uncertainties - 1]; - for (k=inverse[i].elts[j].count_uncertainties; k < inverse[i].count_solns; k++) { - inverse[i].elts[j].uncertainties[k] = value; - } - } - } -/* - * Find phase - */ - count_elts = 0; - paren_count = 0; - for (j = 0; j < inverse[i].count_phases; j++) { - inverse[i].phases[j].phase = phase_bsearch(inverse[i].phases[j].name, &k, FALSE); - if (inverse[i].phases[j].phase == NULL) { - input_error++; - sprintf(error_string, "Could not find phase, %s.", inverse[i].phases[j].name); - error_msg(error_string, CONTINUE); - continue; - } -/* - * Find isotope elements - */ - if (inverse[i].phases[j].count_isotopes > 0) { - for (k = 0; k < inverse[i].phases[j].count_isotopes; k++) { - inverse[i].phases[j].isotopes[k].primary = NULL; - inverse[i].phases[j].isotopes[k].master = NULL; - master_ptr = master_bsearch(inverse[i].phases[j].isotopes[k].elt_name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Element not found for isotope calculation: %s.", - inverse[i].phases[j].isotopes[k].elt_name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->primary != TRUE) { - input_error++; - sprintf(error_string, "Isotope ratio may only be used" - " for total element in phase.\n" - "Secondary species not allowed: %s.", - master_ptr->elt->name); - error_msg(error_string, CONTINUE); - continue; - } - inverse[i].phases[j].isotopes[k].primary = master_ptr; - inverse[i].phases[j].isotopes[k].master = master_ptr; - /* find coefficient for element */ - for (elt_list_ptr=inverse[i].phases[j].phase->next_elt; - elt_list_ptr->elt != NULL; elt_list_ptr++) { - if (elt_list_ptr->elt == master_ptr->elt) { - inverse[i].phases[j].isotopes[k].coef = elt_list_ptr->coef; - break; - } - } - if (elt_list_ptr == NULL) { - input_error++; - sprintf(error_string, "Element, %s,for which isotope ratio was defined is not found in phase, %s", - master_ptr->elt->name, inverse[i].phases[j].phase->name); - error_msg(error_string, CONTINUE); - continue; - } - } - qsort (inverse[i].phases[j].isotopes, - (size_t) inverse[i].phases[j].count_isotopes, - (size_t) sizeof(struct isotope), - isotope_compare); - } - add_elt_list(inverse[i].phases[j].phase->next_elt, 1.0); - - } - if (input_error > 0) return(ERROR); -/* - * Sort elements in reaction and combine - */ - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } -/* - * Mark master species list - */ - for (j=0; j < count_master; j++) master[j]->in = FALSE; - for (j=0; j < count_elts; j++) { - elt_list[j].elt->master->in = TRUE; - } - /* Include all input elements */ - for (j = 0; j < inverse[i].count_elts; j++) { - inverse[i].elts[j].master->in = TRUE; - } - s_eminus->primary->in = TRUE; /* Include electrons */ - master_alk_ptr->in = TRUE; /* Include alkalinity */ -/* - * Unmark primary and mark secondary master species for redox elements - */ - count_in = 0; - inverse[i].count_redox_rxns = 0; - for (j=0; j < count_master; j++) { - /* skip all secondary master species in this loop */ - if (master[j]->primary == FALSE || master[j]->in == FALSE ) continue; - count_in++; - if (j+1 == count_master) continue; - /* if next master species is secondary, mark all - secondary master species until a primary is found */ - if (master[j+1]->primary == FALSE) { - master[j]->in = FALSE; - count_in--; - for (k=j+1; k < count_master; k++) { - if (master[k]->primary == FALSE) { - count_in++; - master[k]->in = TRUE; - if (master[k]->s->primary == NULL) { - inverse[i].count_redox_rxns++; - } - } else { - break; - } - } - } - } -/* - * Save list of master species in inv_elts structure - */ - inv_elts = (struct inv_elts *) PHRQ_malloc( (size_t) (count_in) * sizeof(struct inv_elts)); - if (inv_elts == NULL) malloc_error(); - count_in = 0; - for (j=0; j < count_master; j++) { - /* skip H(1) and O(-2) */ - if (master[j]->s == s_hplus || master[j]->s == s_h2o) continue; - if (master[j]->in == TRUE) { - /* set master */ - inv_elts[count_in].master = master[j]; - /* alloc uncertainties and set default */ - inv_elts[count_in].uncertainties = (double *) PHRQ_malloc((size_t) inverse[i].count_solns * sizeof(LDBLE)); - if (inv_elts[count_in].uncertainties == NULL) malloc_error(); - for(k=0; k < inverse[i].count_solns; k++) { - inv_elts[count_in].uncertainties[k] = inverse[i].uncertainties[k]; - } - count_in++; - } - } - if (s_co3->secondary->in == TRUE) { - inverse[i].carbon = TRUE; - } else { - inverse[i].carbon = FALSE; - } -/* - * copy in input uncertainties - */ - /* copy primary redox to all secondary redox */ - for (j=0; j < inverse[i].count_elts; j++) { - master_ptr = master_bsearch(inverse[i].elts[j].name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Element not found, %s.", inverse[i].elts[j].name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->primary == FALSE || master_ptr->s->secondary == NULL) continue; - for (k=0; k < count_in; k++) { - if (master_ptr == inv_elts[k].master->elt->primary) { - for (l=0; l < inverse[i].count_solns; l++) { - inv_elts[k].uncertainties[l] = inverse[i].elts[j].uncertainties[l]; - } - } - } - inverse[i].elts[j].uncertainties = (double *) free_check_null(inverse[i].elts[j].uncertainties); - } - /* copy masters that are not primary redox */ - for (j=0; j < inverse[i].count_elts; j++) { - master_ptr = master_bsearch(inverse[i].elts[j].name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Element not found, %s.", inverse[i].elts[j].name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL) continue; - for (k=0; k < count_in; k++) { - if (master_ptr == inv_elts[k].master) { - for(l=0; l < inverse[i].count_solns; l++) { - inv_elts[k].uncertainties[l] = inverse[i].elts[j].uncertainties[l]; - } - break; - } - } - inverse[i].elts[j].uncertainties = (double *) free_check_null(inverse[i].elts[j].uncertainties); - } -/* - * replace elts in inverse struct - */ - inverse[i].elts = (struct inv_elts *) free_check_null(inverse[i].elts); - inverse[i].elts = inv_elts; - inverse[i].count_elts = count_in; - for (j = 0; j < inverse[i].count_elts; j++) { -#ifdef SKIP -/* make another pointer alkalinity uncertainties */ - if (inverse[i].elts[j].master == master_alk_ptr) { - inverse[i].alk_uncertainties = free_check_null(inverse[i].alk_uncertainties); - inverse[i].alk_uncertainties = inverse[i].elts[j].uncertainties; - } -#endif -/* debug - output_msg(OUTPUT_MESSAGE, "\t%d\t%s", j, inverse[i].elts[j].master->elt->name); - for (k = 0; k < inverse[i].count_solns; k++) { - output_msg(OUTPUT_MESSAGE, "\t%f", inverse[i].elts[j].uncertainties[k]); - } - output_msg(OUTPUT_MESSAGE,"\n"); - */ - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_phases(void) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Rewrite all phases to secondary species - */ - for (i=0; i < count_phases; i++) { -/* - * Check equation - */ - if (phases[i]->check_equation == TRUE) { - phase_rxn_to_trxn(phases[i]); - if (check_eqn(FALSE) == ERROR) { - input_error++; - sprintf(error_string, "Equation for phase %s does not balance.", - phases[i]->name); - error_msg(error_string, CONTINUE); - } - } -/* - * Rewrite equation - */ - select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk); - add_other_logk(phases[i]->rxn->logk, phases[i]->count_add_logk, phases[i]->add_logk); - count_trxn=0; - trxn_add (phases[i]->rxn, 1.0, FALSE); - trxn_reverse_k(); - rewrite_eqn_to_secondary(); - trxn_reverse_k(); - rxn_free (phases[i]->rxn_s); - phases[i]->rxn_s = rxn_alloc(count_trxn+1); - trxn_copy (phases[i]->rxn_s); - /* debug - trxn_print(); - */ - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_pp_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, l, n_user, first, last; - struct phase *phase_ptr; - LDBLE coef; - char *ptr; -/* - * Find pointers for pure phases - */ - for ( i = 0; i < count_pp_assemblage; i++) { - count_elts = 0; - paren_count = 0; - coef = 1.0; - pp_assemblage[i].new_def = FALSE; - for (j=0; j < pp_assemblage[i].count_comps; j++) { - phase_ptr = phase_bsearch(pp_assemblage[i].pure_phases[j].name, &k, FALSE); - if (phase_ptr == NULL) { - input_error++; - sprintf(error_string, "Phase not found in data base, %s.", pp_assemblage[i].pure_phases[j].name); - error_msg(error_string, CONTINUE); - continue; - } else { - pp_assemblage[i].pure_phases[j].phase = phase_ptr; - add_elt_list(phase_ptr->next_elt, coef); - - } - if (pp_assemblage[i].pure_phases[j].add_formula != NULL) { - first = count_elts; - phase_ptr = phase_bsearch(pp_assemblage[i].pure_phases[j].add_formula, &k, FALSE); - if (phase_ptr != NULL) { - pp_assemblage[i].pure_phases[j].add_formula = phase_ptr->formula; - } - ptr = pp_assemblage[i].pure_phases[j].add_formula; - get_elts_in_species(&ptr, coef); - /* check that all elements are in the database */ - for (l = first; l < count_elts; l++) { - if (elt_list[l].elt->master == NULL) { - input_error++; - sprintf(error_string, "Element \"%s\" in alternative phase for \"%s\" in EQUILIBRIUM_PHASES not found in database.", elt_list[l].elt->name, pp_assemblage[i].pure_phases[j].name); - error_msg(error_string, CONTINUE); - } - } - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine (); - } - pp_assemblage[i].next_elt = (struct elt_list *) free_check_null(pp_assemblage[i].next_elt); - pp_assemblage[i].next_elt = elt_list_save(); - -/* - * Store list with all elements in phases and add formulae - */ - -/* - * Duplicate pure phases if necessary - */ - if ( pp_assemblage[i].n_user_end > pp_assemblage[i].n_user ) { - n_user = pp_assemblage[i].n_user; - last = pp_assemblage[i].n_user_end; - pp_assemblage[i].n_user_end = pp_assemblage[i].n_user; - for (j = n_user + 1; j <= last; j++) { - pp_assemblage_duplicate(n_user, j); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_s_s_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, k1, n_user, last; - struct phase *phase_ptr; - struct s_s *s_s_ptr; - LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, a0, a1; - LDBLE xb2, xb3, xb4, xc2, xc3; - LDBLE moles; -/* - * Find pointers for pure phases - */ - for ( i = 0; i < count_s_s_assemblage; i++) { - count_elts = 0; - paren_count = 0; - for (j=0; j < s_s_assemblage[i].count_s_s; j++) { - for (k=0; k < s_s_assemblage[i].s_s[j].count_comps; k++) { - phase_ptr = phase_bsearch(s_s_assemblage[i].s_s[j].comps[k].name, &k1, FALSE); - if (phase_ptr == NULL) { - input_error++; - sprintf(error_string, "Phase not found in data base, %s, assemblage %d.", s_s_assemblage[i].s_s[j].comps[k].name, s_s_assemblage[i].n_user); - error_msg(error_string, CONTINUE); - s_s_assemblage[i].s_s[j].comps[k].phase = NULL; - continue; - } else { - s_s_assemblage[i].s_s[j].comps[k].phase = phase_ptr; - s_s_assemblage[i].s_s[j].comps[k].phase->moles_x = 0; - s_s_assemblage[i].s_s[j].comps[k].phase->fraction_x = 0; - } - if (s_s_assemblage[i].s_s[j].comps[k].moles == NAN) { - input_error++; - sprintf(error_string, "Moles of solid solution component not defined, %s, assemblage %d.", s_s_assemblage[i].s_s[j].comps[k].name, s_s_assemblage[i].n_user); - error_msg(error_string, CONTINUE); - continue; - } - } - - if (s_s_assemblage[i].new_def == TRUE) { - /* - * Calculate a0 and a1 first - */ - s_s_calc_a0_a1(&(s_s_assemblage[i].s_s[j])); - s_s_ptr = &(s_s_assemblage[i].s_s[j]); - - n_tot = 0; - for (k = 0; k < s_s_ptr->count_comps; k++) { - moles = s_s_assemblage[i].s_s[j].comps[k].moles; - if (s_s_assemblage[i].s_s[j].comps[k].moles <= 0.0) { - moles = MIN_TOTAL; - s_s_assemblage[i].s_s[j].comps[k].initial_moles = moles; - } - n_tot += moles; - } - - for (k = 0; k < s_s_ptr->count_comps; k++) { - moles = s_s_assemblage[i].s_s[j].comps[k].moles; - if (s_s_assemblage[i].s_s[j].comps[k].moles <= 0.0) { - moles = MIN_TOTAL; - } - s_s_assemblage[i].s_s[j].comps[k].fraction_x = moles / n_tot; - s_s_assemblage[i].s_s[j].comps[k].log10_fraction_x = log10(moles / n_tot); - } - a0 = s_s_assemblage[i].s_s[j].a0; - a1 = s_s_assemblage[i].s_s[j].a1; - -/* - * Binary solid solution - */ - if (a0 != 0.0 || a1 != 0) { - s_s_assemblage[i].s_s[j].dn = 1.0 / n_tot; - nc = s_s_assemblage[i].s_s[j].comps[0].moles; - if (nc == 0) nc = MIN_TOTAL; - nb = s_s_assemblage[i].s_s[j].comps[1].moles; - if (nb == 0) nb = MIN_TOTAL; - xc = nc/n_tot; - xb = nb/n_tot; - - /* lambdas */ - s_s_assemblage[i].s_s[j].comps[0].log10_lambda = xb*xb*(a0 - a1*(3 -4*xb))/LOG_10; - s_s_assemblage[i].s_s[j].comps[1].log10_lambda = xc*xc*(a0 + a1*(4*xb - 1))/LOG_10; - - /* derivatives wrt nc and nb */ - xc2 = xc*xc; - xc3 = xc2*xc; - xb2 = xb*xb; - xb3 = xb2*xb; - xb4 = xb3*xb; - - /* component 1 */ - dnb = -2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 - 4*a1*xc*xb4 - 8*a1*xb3*xc2 - - 4*a1*xb2*xc3 - 2*a0*xc*xb2 - 8*a1*xc*xb3 + 6*a1*xc*xb2 + 1; - s_s_assemblage[i].s_s[j].comps[0].dnb = dnb/n_tot; - dnc = 2*a0*xb3 + 2*a0*xc*xb2 + 8*a1*xb4 + 8*a1*xc*xb3 - 2*a1*xb3 - 6*a1*xc*xb2; - s_s_assemblage[i].s_s[j].comps[0].dnc = - xb/nc + dnc/n_tot; - s_s_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; - - /* component 2*/ - dnb = 2*a0*xb*xc2 + 2*a0*xc3 + 8*a1*xb2*xc2 + 8*a1*xb*xc3 - 2*a1*xb*xc2 -6*a1*xc3; - s_s_assemblage[i].s_s[j].comps[1].dnb = -xc/nb + dnb/n_tot; - dnc = -2*a0*xc*xb2 - 8*a1*xc*xb3 + 2*a1*xc*xb2 - 2*a0*xb*xc2 - 8*a1*xb2*xc2 + 6*a1*xb*xc2 + 1; - s_s_assemblage[i].s_s[j].comps[1].dnc = dnc/n_tot; - s_s_prep(s_s_assemblage[i].s_s[j].tk, &(s_s_assemblage[i].s_s[j]), TRUE); - s_s_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; -/* - * Ideal solid solution - */ - } else { - s_s_assemblage[i].s_s[j].dn = 1.0 / n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) { - s_s_assemblage[i].s_s[j].comps[k].log10_lambda = 0; - moles = s_s_assemblage[i].s_s[j].comps[k].moles; - if (moles <= 0.0) moles = MIN_TOTAL; - s_s_assemblage[i].s_s[j].comps[k].dnb = (n_tot - moles)/(moles*n_tot); - s_s_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; - } - } - } - } - s_s_assemblage[i].new_def = FALSE; - -/* - * Duplicate s_s_assemblage if necessary - */ - n_user = s_s_assemblage[i].n_user; - last = s_s_assemblage[i].n_user_end; - s_s_assemblage[i].n_user_end = s_s_assemblage[i].n_user; - for (j = n_user + 1; j <= last; j++) { - s_s_assemblage_duplicate(n_user, j); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_punch(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, l; - char token[MAX_LENGTH]; -/* - * tidy punch information - */ - if (punch.high_precision == FALSE) { - l = 12; - } else { - l = 20; - } - if (punch.in == TRUE && pr.punch == TRUE) { - /* totals */ - - for (i = 0; i < punch.count_totals; i++) { - punch.totals[i].master = master_bsearch(punch.totals[i].name); - } - - /* molalities */ - - for (i = 0; i < punch.count_molalities; i++) { - punch.molalities[i].s = s_search(punch.molalities[i].name); - } - - /* log activities */ - - for (i = 0; i < punch.count_activities; i++) { - punch.activities[i].s = s_search(punch.activities[i].name); - } - - /* equilibrium phases */ - - for (i = 0; i < punch.count_pure_phases; i++) { - punch.pure_phases[i].phase = phase_bsearch(punch.pure_phases[i].name, &j, FALSE); - } - - /* saturation indices */ - - for (i = 0; i < punch.count_si; i++) { - punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); - } - - /* gases */ - - for (i = 0; i < punch.count_gases; i++) { - punch.gases[i].phase = phase_bsearch(punch.gases[i].name, &j, FALSE); - } - } - if (punch.new_def == TRUE && punch.in == TRUE && pr.punch == TRUE) { - - /* constant stuff, sim, pH, etc. */ - - if (punch.sim == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "sim"); - } - if (punch.state == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "state"); - } - if (punch.soln == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "soln"); - } - if (punch.dist == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "dist_x"); - } - if (punch.time == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "time"); - } - if (punch.step == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "step"); - } - if (punch.ph == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "pH"); - } - if (punch.pe == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "pe"); - } - if (punch.rxn == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "reaction"); - } - if (punch.temp == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "temp"); - } - if (punch.alk == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "Alk"); - } - if (punch.mu == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "mu"); - } - if (punch.water == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "mass_H2O"); - } - if (punch.charge_balance == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "charge"); - } - if (punch.percent_error == TRUE) { - output_msg(OUTPUT_PUNCH, "%*s\t", l, "pct_err"); - } - /* totals */ - - for (i = 0; i < punch.count_totals; i++) { - output_msg(OUTPUT_PUNCH,"%*s\t", l, punch.totals[i].name); - if (punch.totals[i].master == NULL) { - sprintf(error_string, "Did not find master species," - " %s.", punch.totals[i].name); - warning_msg(error_string); - } - } - - /* molalities */ - - for (i = 0; i < punch.count_molalities; i++) { - strcpy(token,"m_"); - strcat(token, punch.molalities[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - if (punch.molalities[i].s == NULL) { - sprintf(error_string, "Did not find species," - " %s.", punch.molalities[i].name); - warning_msg(error_string); - } - } - - /* log activities */ - - for (i = 0; i < punch.count_activities; i++) { - strcpy(token,"la_"); - strcat(token, punch.activities[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - if (punch.activities[i].s == NULL) { - sprintf(error_string, "Did not find species, " - "%s.", punch.activities[i].name); - warning_msg(error_string); - } - } - - /* equilibrium phases */ - - for (i = 0; i < punch.count_pure_phases; i++) { - strcpy(token,"d_"); - strcat(token, punch.pure_phases[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t%*s\t", l, punch.pure_phases[i].name, l, token); - if (punch.pure_phases[i].phase == NULL) { - sprintf(error_string, "Did not find phase, " - "%s.", punch.pure_phases[i].name); - warning_msg(error_string); - } - } - - /* saturation indices */ - - for (i = 0; i < punch.count_si; i++) { - strcpy(token,"si_"); - strcat(token, punch.si[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - if (punch.si[i].phase == NULL) { - sprintf(error_string, "Did not find phase, " - "%s.", punch.si[i].name); - warning_msg(error_string); - } - } - - /* gases */ - - if (punch.count_gases > 0) { - output_msg(OUTPUT_PUNCH, "%*s\t%*s\t%*s\t", l, "pressure", l, "total mol", l, "volume"); - } - for (i = 0; i < punch.count_gases; i++) { - strcpy(token,"g_"); - strcat(token, punch.gases[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - if (punch.gases[i].phase == NULL) { - sprintf(error_string, "Did not find phase, " - "%s.", punch.gases[i].name); - warning_msg(error_string); - } - } - - /* kinetics */ - - for (i = 0; i < punch.count_kinetics; i++) { - strcpy(token,"k_"); - strcat(token, punch.kinetics[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - strcpy(token,"dk_"); - strcat(token, punch.kinetics[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - } - - /* solid solutions */ - - for (i = 0; i < punch.count_s_s; i++) { - strcpy(token,"s_"); - strcat(token, punch.s_s[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - } - - /* isotopes */ - - for (i = 0; i < punch.count_isotopes; i++) { - if (isotope_ratio_search(punch.isotopes[i].name) == NULL) { - sprintf(error_string, "Did not find isotope_ratio definition for " - "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", punch.isotopes[i].name, punch.isotopes[i].name); - warning_msg(error_string); - } - strcpy(token,"I_"); - strcat(token, punch.isotopes[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - } - - /* calculate_values */ - - for (i = 0; i < punch.count_calculate_values; i++) { - if (calculate_value_search(punch.calculate_values[i].name) == NULL) { - sprintf(error_string, "Did not find calculate_values definition for " - "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", punch.calculate_values[i].name, punch.calculate_values[i].name); - warning_msg(error_string); - } - strcpy(token,"V_"); - strcat(token, punch.calculate_values[i].name); - output_msg(OUTPUT_PUNCH,"%*s\t", l, token); - } - - /* user_punch */ - if (punch.user_punch == TRUE) { - for (i = 0; i < user_punch_count_headings; i++) { - output_msg(OUTPUT_PUNCH,"%*s\t", l, user_punch_headings[i]); - } - } - output_msg(OUTPUT_PUNCH,"\n"); - punch.new_def = FALSE; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_species(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - struct master *master_ptr; - char c, *ptr; -/* - * Make sure species pointers are ok - */ - if (check_species_input() == ERROR) { - error_msg("Calculations terminating due to input errors.", STOP); - } -/* - * Set secondary and primary pointers in species structures - */ - for (i=0; i < count_s; i++) { - s[i]->number = i; - s[i]->primary=NULL; - s[i]->secondary=NULL; - if (s[i]->check_equation == TRUE ) { - species_rxn_to_trxn(s[i]); - if (check_eqn(TRUE) == ERROR) { - input_error++; - sprintf(error_string, "Equation for species %s does not balance.", - s[i]->name); - error_msg(error_string, CONTINUE); - } - } - } - for (i=0; i < count_master; i++) { - ptr = master[i]->elt->name; - if (ptr[0] != '[') { - while ((c = (int) *(++ptr)) != '\0') { - if (isupper((int) c) ) { - input_error++; - sprintf(error_string, "Element or valence name in SOLUTION_MASTER_SPECIES should include only one element, %s.", master[i]->elt->name); - error_msg(error_string, CONTINUE); - break; - } - } - } - /* store sequence number in master structure */ - master[i]->number = i; - if (master[i]->primary == TRUE) { - master[i]->s->primary=master[i]; - } else { - master[i]->s->secondary=master[i]; - } - if (strcmp(master[i]->elt->name,"C") == 0) { - s_co3=master[i]->s; - } - if (master[i]->gfw_formula != NULL) { - if(compute_gfw(master[i]->gfw_formula, &master[i]->gfw) == ERROR){ - input_error++; - sprintf(error_string, "Calculating gfw for master species, %s, formula %s.", - master[i]->elt->name, master[i]->gfw_formula); - error_msg(error_string, CONTINUE); - } - } - } -/* - * Write equations for all master species in terms of primary - * master species, set coefficient of element in master species - */ - for (i=0; i < count_master; i++) { - count_trxn=0; - if ( master[i]->s->primary != NULL ) { - trxn_add(master[i]->s->rxn, 1.0, FALSE); - trxn_add(master[i]->s->rxn, -1.0, TRUE); - } else { - trxn_add(master[i]->s->rxn, 1.0, FALSE); - rewrite_eqn_to_primary(); - } - rxn_free(master[i]->rxn_primary); - master[i]->rxn_primary = rxn_alloc(count_trxn+1); - trxn_copy (master[i]->rxn_primary); - master[i]->coef = coef_in_master(master[i]); - } -/* - * Rewrite all species to secondary species - */ - for (i=0; i < count_s; i++) { - count_trxn=0; - if ( s[i]->primary != NULL || s[i]->secondary != NULL ) { - trxn_add (s[i]->rxn, 1.0, FALSE); - trxn_add (s[i]->rxn, -1.0, TRUE); - } else { - trxn_add (s[i]->rxn, 1.0, FALSE); - rewrite_eqn_to_secondary(); - } - rxn_free (s[i]->rxn_s); - s[i]->rxn_s = rxn_alloc(count_trxn+1); - trxn_copy (s[i]->rxn_s); - /* calculate alkalinity */ - s[i]->alk = calc_alk(s[i]->rxn_s); - /* set co2 coefficient */ - s[i]->co2 = 0.0; - for (j=1; j < count_trxn; j++) { - if (trxn.token[j].s == s_co3) { - s[i]->co2 = trxn.token[j].coef; - break; - } - } - } -/* - * Set pointer in element to master species - */ - for (i=0; i < count_elements; i++) { - elements[i]->master = master_bsearch(elements[i]->name); - if (elements[i]->master == NULL) { - input_error++; - sprintf(error_string, "No master species for element %s.", elements[i]->name); - error_msg(error_string, CONTINUE); - } - elements[i]->primary = master_bsearch_primary(elements[i]->name); - if (elements[i]->primary == NULL) { - input_error++; - sprintf(error_string, "No master species for element %s.", elements[i]->name); - error_msg(error_string, CONTINUE); - } - } -/* - * Make sure all primary master species for redox elements - * are also secondary master species - */ - for (i = 0; i < count_master; i++) { - if (master[i]->primary == FALSE) { - master_ptr = master[i]->s->secondary->elt->primary; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Every primary master species for a redox element\n" - "\tmust also be a secondary master species.\n" - "\tError in definitions related to %s .\n", - master[i]->s->name); - error_msg(error_string, CONTINUE); - - } else if (master_ptr->s->secondary == NULL) { - input_error++; - sprintf(error_string, "Every primary master species for a redox element\n" - "\tmust also be a secondary master species.\n" - "\t%s is the primary master species for element %s.\n" - "\tAnother entry in SOLUTION_MASTER_SPECIES is needed.\n" - "\tDefine species %s as a secondary master species for a valence state.\n" - "\tFor example: \n" - "\t%s(0)\t%s alk gfw", - master_ptr->s->name, master_ptr->elt->name, - master_ptr->s->name, master_ptr->elt->name, - master_ptr->s->name); - error_msg(error_string, CONTINUE); - } - } - } -/* - * Calculate H and O if alternate mass balance is given - */ - for (i = 0; i < count_s; i++) { - if (s[i]->next_secondary != NULL) { - s[i]->h = 0.0; - s[i]->o = 0.0; - for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) { - if (s[i]->next_secondary[j].elt->primary == NULL) continue; - if (s[i]->next_secondary[j].elt->primary->s == s_hplus) { - s[i]->h += s[i]->next_secondary[j].coef; - } else if (s[i]->next_secondary[j].elt->primary->s == s_h2o) { - s[i]->o += s[i]->next_secondary[j].coef; - } else if (s[i]->mole_balance != NULL) { - master_ptr = s[i]->next_secondary[j].elt->master; - if (master_ptr->primary == TRUE) { - if (master_ptr->s->secondary != NULL) { - master_ptr = master_ptr->s->secondary; - } - } - if (master_ptr->coef != 1) { - s[i]->next_secondary[j].coef /= master_ptr->coef; - } - } - } - if (s[i]->type == EX) { - for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) { - if (s[i]->next_secondary[j].elt->primary->s->type == EX) { - s[i]->equiv = s[i]->next_secondary[j].coef; - break; - } - } - } - } - } -#ifdef SKIP - for (i = 0; i < count_s; i++) { - if (match_elts_in_species(s[i]->name, "*{C,[13C]}{O,[18O]}3*") == TRUE) { - output_msg(OUTPUT_MESSAGE, "Match: %s\n", s[i]->name); - } - } -#endif - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_surface(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * After all of data are read, fill in master species for surface comps - * Sort surface - */ - int i, j, k; - struct surface *surface_ptr; - struct master *master_ptr; - - for (k = 0; k < count_surface; k++) { - surface_ptr = &surface[k]; - for (i = 0; i < surface_ptr->count_comps; i++ ) { -/* - * Find master species for each surface, setup unknown structure - */ - for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) { - master_ptr = surface_ptr->comps[i].totals[j].elt->master; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Master species not in data base for %s, " - "skipping element.", surface_ptr->comps[i].totals[j].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != SURF) continue; -/* - * Set flags - */ - surface_ptr->comps[i].master = master_ptr; - break; - } - } -/* - * Sort components - */ - if (input_error == 0) { - qsort (surface[k].comps, - (size_t) surface_ptr->count_comps, - (size_t) sizeof(struct surface_comp), - surface_comp_compare); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_solutions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Define n_user for any solutions read by solution_spread that - * don't have n_user defined - */ - int i, l, n, last; - struct conc *tot_ptr; - char *ptr; - struct master *master_ptr; - char token[MAX_LENGTH]; - for (n=0; n < count_solution; n++) { - /* - * Check that elements are in database - */ - if (solution[n] != NULL && solution[n]->new_def == TRUE) { - /* - * Sort totals by description - */ - i = 0; - while(solution[n]->totals[i].description != NULL) i++; - qsort (solution[n]->totals, - (size_t) i, - (size_t) sizeof(struct conc), - conc_compare); - /* - * sort isotopes - */ - if (solution[n]->count_isotopes > 0) { - qsort (solution[n]->isotopes, - (size_t) solution[n]->count_isotopes, - (size_t) sizeof(struct isotope), - isotope_compare); - } else { - solution[n]->isotopes = (struct isotope *) free_check_null(solution[n]->isotopes); - } - for ( i=0; solution[n]->totals[i].description != NULL; i++) { - tot_ptr=&(solution[n]->totals[i]); - if (strcmp(tot_ptr->description,"H(1)") == 0 || - strcmp(tot_ptr->description,"E" ) == 0 ) { - tot_ptr->moles = 0.0; - continue; - } - ptr = tot_ptr->description; - copy_token(token, &ptr, &l); - master_ptr = master_bsearch (token); - if (master_ptr == NULL) { - sprintf(error_string, "Could not find element in database, %s.\n\tConcentration is set to zero.", tot_ptr->description); - warning_msg(error_string); - tot_ptr->input_conc = 0.0; - continue; - } - } - } - } - /* - * Calculate solution numbers - */ - for (n=0; n < count_solution; n++) { - if (solution[n] != NULL && solution[n]->new_def == TRUE && solution[n]->n_user < 0) { - last = 0; - for (i=0; i < count_solution; i++) { - if (solution[i]->n_user > last) last = solution[i]->n_user; - if (solution[i]->n_user_end > last) last = solution[i]->n_user_end; - } - if (save.solution == TRUE) { - if (save.n_solution_user > last) last = save.n_solution_user; - if (save.n_solution_user_end > last) last = save.n_solution_user_end; - } - for (i=0; i < count_solution; i++) { - if (solution[i]->new_def == TRUE && solution[i]->n_user < 0) { - solution[i]->n_user = ++last; - solution[i]->n_user_end = last; - if (use.solution_in == TRUE && use.n_solution_user == -1) { - use.n_solution_user = last; - } - } - } - break; - } - } - solution_sort(); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int species_rxn_to_trxn(struct species *s_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copy reaction from reaction structure to - * temp reaction structure. - */ - int i; - - for (i = 0; s_ptr->rxn->token[i].s != NULL; i++) { - trxn.token[i].name = s_ptr->rxn->token[i].s->name; - trxn.token[i].z = s_ptr->rxn->token[i].s->z; - trxn.token[i].s = s_ptr->rxn->token[i].s; - trxn.token[i].unknown = NULL; - trxn.token[i].coef = s_ptr->rxn->token[i].coef; - count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) { - space ((void **) &(trxn.token), count_trxn+1, &max_trxn, - sizeof(struct rxn_token_temp)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int phase_rxn_to_trxn(struct phase *phase_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copy reaction from reaction structure to - * temp reaction structure. - */ - int i, l; - char *ptr; - char token[MAX_LENGTH]; - LDBLE z; - - trxn.token[0].name = phase_ptr->formula; - /* charge */ - ptr = phase_ptr->formula; - get_token ( &ptr, token, &z, &l); - trxn.token[0].z = z; - trxn.token[0].s = NULL; - trxn.token[0].unknown = NULL; - /*trxn.token[0].coef = -1.0;*/ - /* check for leading coefficient of 1.0 for phase did not work */ - trxn.token[0].coef = phase_ptr->rxn->token[0].coef; - for (i = 1; phase_ptr->rxn->token[i].s != NULL; i++) { - trxn.token[i].name = phase_ptr->rxn->token[i].s->name; - trxn.token[i].z = phase_ptr->rxn->token[i].s->z; - trxn.token[i].s = NULL; - trxn.token[i].unknown = NULL; - trxn.token[i].coef = phase_ptr->rxn->token[i].coef; - count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) { - space ((void **) &(trxn.token), count_trxn+1, &max_trxn, - sizeof(struct rxn_token_temp)); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_isotopes (void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Isotope ratios for each element or element valence state - */ - int i, j, k, l, n; - int count_isotopes, primary_number, count_primary; - LDBLE isotope_number; - struct master *master_ptr, *primary_ptr; - struct solution *solution_ptr; - struct isotope *new_isotopes; - struct isotope *primary_isotopes; - char token[MAX_LENGTH]; - - primary_number = 0; - primary_ptr = NULL; - for (n = 0; n < count_solution; n++) { - if (solution[n]->new_def != TRUE) continue; - if (solution[n]->count_isotopes == 0) continue; - solution_ptr = solution[n]; - primary_isotopes = (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); - if (primary_isotopes == NULL) malloc_error(); - count_primary = 0; - new_isotopes = (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); - if (new_isotopes == NULL) malloc_error(); - count_isotopes = 0; -/* - * Make list of primary master species for isotopes - */ - for (i = 0; i < solution_ptr->count_isotopes; i++) { - master_ptr = master_bsearch_primary(solution_ptr->isotopes[i].elt_name); - isotope_number = solution_ptr->isotopes[i].isotope_number; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "In isotope calculation: element not defined: %s.", - solution_ptr->isotopes[i].elt_name); - error_msg(error_string, CONTINUE); - continue; - } - for (j = 0; j < count_primary; j++) { - if (primary_isotopes[j].master == master_ptr && - primary_isotopes[j].isotope_number == isotope_number) break; - } - if (j == count_primary) { - primary_isotopes = (struct isotope *) PHRQ_realloc(primary_isotopes, (size_t) (count_primary + 1) * sizeof(struct isotope)); - if (primary_isotopes == NULL) malloc_error(); - primary_isotopes[count_primary].master = master_ptr; - primary_isotopes[count_primary].isotope_number = isotope_number; - count_primary++; - } - } - if (input_error > 0) return(ERROR); -/* - * Go through all redox states of the list of primary species and isotope number - */ - for (j = 0; j < count_primary; j++) { - - /* find index number of master species, set flag to FALSE */ - master_ptr = primary_isotopes[j].master; - isotope_number = primary_isotopes[j].isotope_number; - for (k = 0; k < count_master; k++) { - if (master[k] == master_ptr) { - primary_number = k; - primary_ptr = master[k]; - } - master[k]->isotope = FALSE; - } - - /* go through isotopes of solution and fill in master species */ - for (l = 0; l < solution_ptr->count_isotopes; l++) { - master_ptr = master_bsearch(solution_ptr->isotopes[l].elt_name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "In isotope calculation: element not defined: %s.", - solution_ptr->isotopes[l].elt_name); - error_msg(error_string, CONTINUE); - continue; - } - - /* only fill for pertinent isotope */ - if (master_ptr->elt->primary != primary_ptr) continue; - if (solution_ptr->isotopes[l].isotope_number != isotope_number) continue; - - /* for primary, fill in ratio for all secondary species */ - if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL ) { - for (k = primary_number + 1; k < count_master; k++) { - if (master[k]->elt->primary != primary_ptr) break; - master[k]->isotope_ratio = solution_ptr->isotopes[l].ratio; - master[k]->isotope_ratio_uncertainty = solution_ptr->isotopes[l].ratio_uncertainty; - if (master[k]->isotope == TRUE) { - sprintf(error_string, "In isotope calculation: redefinition of isotope ratio for %s.", solution_ptr->isotopes[l].elt_name); - error_msg(error_string, CONTINUE); - } - master[k]->isotope = TRUE; - } - - /* for secondary and non redox, set ratio */ - } else { - master_ptr->isotope_ratio = solution_ptr->isotopes[l].ratio; - master_ptr->isotope_ratio_uncertainty = solution_ptr->isotopes[l].ratio_uncertainty; - if (master_ptr->isotope == TRUE) { - sprintf(error_string, "In isotope calculation: redefinition of isotope ratio for %s.", solution_ptr->isotopes[l].elt_name); - error_msg(error_string, CONTINUE); - } - master_ptr->isotope = TRUE; - } - } -/* - * Write new isotope structure - */ - for (k = 0; k < count_master; k++) { - /* skip primary master species of redox elements */ - if (master[k]->primary == TRUE && - master[k]->s->secondary != NULL) continue; - if (master[k]->elt->primary == primary_ptr && master[k]->isotope == FALSE) { - input_error++; - sprintf(error_string, "Isotopic ratio not defined for element or valence state %g%s.", (double) isotope_number, master[k]->elt->name); - error_msg(error_string, CONTINUE); - } - if (master[k]->isotope == FALSE) continue; - new_isotopes = (struct isotope *) PHRQ_realloc(new_isotopes, (size_t) (count_isotopes + 1) * sizeof(struct isotope)); - if (new_isotopes == NULL) malloc_error(); - new_isotopes[count_isotopes].master = master[k]; - new_isotopes[count_isotopes].primary = primary_ptr; - new_isotopes[count_isotopes].isotope_number = isotope_number; - new_isotopes[count_isotopes].elt_name = master[k]->elt->name; - new_isotopes[count_isotopes].total = 0; - new_isotopes[count_isotopes].ratio = master[k]->isotope_ratio; - new_isotopes[count_isotopes].ratio_uncertainty = master[k]->isotope_ratio_uncertainty; - sprintf(token,"%d%s", (int) isotope_number, master[k]->elt->name); - new_isotopes[count_isotopes].isotope_name = string_hsave(token); - count_isotopes++; - } - } - primary_isotopes = (struct isotope *) free_check_null(primary_isotopes); - solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = new_isotopes; - solution_ptr->count_isotopes = count_isotopes; - qsort (solution_ptr->isotopes, - (size_t) count_isotopes, - (size_t) sizeof(struct isotope), - isotope_compare); - } - - return (OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_kin_exchange(void) -/* ---------------------------------------------------------------------- */ -/* - * If exchanger is related to mineral, exchanger amount is - * set in proportion - */ -{ - int i, j, k, n; - struct kinetics *kinetics_ptr; - struct exch_comp *comp_ptr; - struct master *master_ptr; - char *ptr; - LDBLE conc; - - for (i=0; i < count_exchange; i++) { - if (exchange[i].new_def == FALSE) continue; - if (exchange[i].n_user < 0) continue; - for (j = 0; j < exchange[i].count_comps; j++) { - if (exchange[i].comps[j].rate_name == NULL) continue; - comp_ptr = &exchange[i].comps[j]; - comp_ptr->master = NULL; - n = exchange[i].n_user; - - /* First find exchange master species */ - - for (k=0; comp_ptr->totals[k].elt != NULL; k++) { - /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Master species not in data " - "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != EX) continue; - comp_ptr->master = master_ptr; - break; - } - if (comp_ptr->master == NULL) { - input_error++; - sprintf(error_string, "Exchange formula does not contain an exchange master species, %s", comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find associated kinetic reaction ... */ - if ((kinetics_ptr=kinetics_bsearch(n, &k)) == NULL) { - input_error++; - sprintf(error_string, "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", n, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - for (k=0; kcount_comps; k++) { - if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { - break; - } - } - if (k == kinetics_ptr->count_comps) { - input_error++; - sprintf(error_string,"Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", comp_ptr->rate_name, comp_ptr->formula, n); - error_msg(error_string, CONTINUE); - continue; - } - - /* use database name for phase */ - comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; - - /* make exchanger concentration proportional to mineral ... */ - conc=kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; - - count_elts = 0; - paren_count = 0; - ptr = comp_ptr->formula; - get_elts_in_species(&ptr, conc); - comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); -/* - * No check on availability of exchange elements - */ - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_min_exchange(void) -/* ---------------------------------------------------------------------- */ -/* - * If exchanger is related to mineral, exchanger amount is - * set in proportion - */ -{ - int i, j, k, n, jj; - struct pp_assemblage *pp_a_ptr; - struct exch_comp *comp_ptr; - struct master *master_ptr; - char *ptr; - LDBLE conc; - - for (i=0; i < count_exchange; i++) { - if (exchange[i].new_def == FALSE) continue; - if (exchange[i].n_user < 0) continue; - for (j = 0; j < exchange[i].count_comps; j++) { - if (exchange[i].comps[j].phase_name == NULL) continue; - comp_ptr = &exchange[i].comps[j]; - comp_ptr->master = NULL; - n = exchange[i].n_user; - - /* First find exchange master species */ - - for (k=0; comp_ptr->totals[k].elt != NULL; k++) { - /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Master species not in data " - "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != EX) continue; - comp_ptr->master = master_ptr; - break; - } - if (comp_ptr->master == NULL) { - input_error++; - sprintf(error_string, "Exchange formula does not contain an exchange master species, %s", comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find the mineral on which exchanger depends... */ - if ((pp_a_ptr=pp_assemblage_bsearch(n, &k)) == NULL) { - input_error++; - sprintf(error_string, "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", n, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - for (k=0; kcount_comps; k++) { - if (strcmp_nocase(comp_ptr->phase_name, pp_a_ptr->pure_phases[k].name) == 0) { - break; - } - } - if (k == pp_a_ptr->count_comps) { - input_error++; - sprintf(error_string,"Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", comp_ptr->phase_name, comp_ptr->formula, n); - error_msg(error_string, CONTINUE); - continue; - } - /* use database name for phase */ - comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; - /* make exchanger concentration proportional to mineral ... */ - conc=pp_a_ptr->pure_phases[k].moles * comp_ptr->phase_proportion; - count_elts = 0; - paren_count = 0; - ptr = comp_ptr->formula; - get_elts_in_species(&ptr, conc); - comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); -/* - * make sure exchange elements are in phase - */ - count_elts = 0; - paren_count = 0; - ptr = comp_ptr->formula; - get_elts_in_species(&ptr, -comp_ptr->phase_proportion); - ptr = pp_a_ptr->pure_phases[k].phase->formula; - get_elts_in_species(&ptr, 1.0); - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - for (jj = 0; jj < count_elts; jj++) { - if (elt_list[jj].elt->primary->s->type != EX && elt_list[jj].coef < 0) { - input_error++; - sprintf(error_string,"Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", comp_ptr->formula, (double) comp_ptr->phase_proportion, pp_a_ptr->pure_phases[k].phase->name, pp_a_ptr->pure_phases[k].phase->formula); - error_msg(error_string, CONTINUE); - break; - } - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_min_surface(void) -/* ---------------------------------------------------------------------- */ -/* - * If surface is related to mineral, surface amount is - * set in proportion - */ -{ - int i, j, k, n, jj; - struct pp_assemblage *pp_a_ptr; - struct surface_comp *comp_ptr; - struct master *master_ptr; - char *ptr; - LDBLE conc; - - for (i=0; i < count_surface; i++) { - if (surface[i].new_def == FALSE) continue; - if (surface[i].n_user < 0) continue; - for (j = 0; j < surface[i].count_comps; j++) { - if (surface[i].comps[j].phase_name == NULL) continue; - comp_ptr = &surface[i].comps[j]; - comp_ptr->master = NULL; - n = surface[i].n_user; - - /* First find surface master species */ - - for (k=0; comp_ptr->totals[k].elt != NULL; k++) { - /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Master species not in data " - "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != SURF) continue; - comp_ptr->master = master_ptr; - break; - } - if (comp_ptr->master == NULL) { - input_error++; - sprintf(error_string, "Surface formula does not contain a surface master species, %s", comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find the mineral on which surface depends... */ - if ((pp_a_ptr=pp_assemblage_bsearch(n, &k)) == NULL) { - input_error++; - sprintf(error_string, "Equilibrium_phases %d must be defined to use surface related to mineral phase, %s", n, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - for (k=0; kcount_comps; k++) { - if (strcmp_nocase(comp_ptr->phase_name, pp_a_ptr->pure_phases[k].name) == 0) { - break; - } - } - if (k == pp_a_ptr->count_comps) { - input_error++; - sprintf(error_string,"Mineral, %s, related to surface, %s, not found in Equilibrium_Phases %d", comp_ptr->phase_name, comp_ptr->formula, n); - error_msg(error_string, CONTINUE); - continue; - } - if (pp_a_ptr->pure_phases[k].phase == NULL) { - input_error++; - sprintf(error_string,"Mineral, %s, related to surface, %s, not found in database.", pp_a_ptr->pure_phases[k].name, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - /* use database name for phase */ - comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; - /* make surface concentration proportional to mineral ... */ - conc=pp_a_ptr->pure_phases[k].moles * comp_ptr->phase_proportion; -/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ - ptr = comp_ptr->formula; - count_elts = 0; - paren_count = 0; - get_elts_in_species(&ptr, conc); - comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); - - /* area */ - surface[i].charge[comp_ptr->charge].grams = pp_a_ptr->pure_phases[k].moles; -/* - * make sure surface elements are in phase - */ - count_elts = 0; - paren_count = 0; - ptr = pp_a_ptr->pure_phases[k].phase->formula; - get_elts_in_species(&ptr, 1.0); - for (jj = 0; jj < surface[i].count_comps; jj++) { - if (comp_ptr->charge != surface[i].comps[jj].charge) continue; - if (surface[i].comps[jj].master->s->z != 0.0) { - input_error++; - sprintf(error_string, "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", surface[i].comps[jj].master->s->name); - error_msg(error_string, CONTINUE); - } - ptr = surface[i].comps[jj].master->s->name; - get_elts_in_species(&ptr, -surface[i].comps[jj].phase_proportion); - } - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); -/* Makes no sense: sorbed species need not be in mineral structure... */ -/* For example, if master species is SurfOH, then increasing the amount of surface - * adds SurfOH to the system, the OH must then come from phase, - * otherwise, O and H are not conserved - */ - for (jj = 0; jj < count_elts; jj++) { - if (elt_list[jj].elt->primary->s->type != SURF && elt_list[jj].coef < 0) { - input_error++; - sprintf(error_string,"Element %s in sum of surface sites,\n" - "\tincluding %s * %g mol sites/mol phase,\n" - "\texceeds stoichiometry in the related phase %s, %s.", - elt_list[jj].elt->name, - comp_ptr->master->s->name, - (double) comp_ptr->phase_proportion, - pp_a_ptr->pure_phases[k].phase->name, - pp_a_ptr->pure_phases[k].phase->formula); - error_msg(error_string, CONTINUE); - break; - } - } - - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_kin_surface(void) -/* ---------------------------------------------------------------------- */ -/* - * If surface is related to mineral, surface amount is - * set in proportion - */ -{ - int i, j, k, n, jj, l; - struct kinetics *kinetics_ptr; - struct surface_comp *comp_ptr; - struct master *master_ptr; - struct phase *phase_ptr; - char token[MAX_LENGTH]; - char *ptr; - LDBLE conc; - struct elt_list *elt_list_kinetics; - int count_elts_kinetics; - - n = -999; - comp_ptr = NULL; - for (i=0; i < count_surface; i++) { - if (surface[i].new_def == FALSE) continue; - if (surface[i].n_user < 0) continue; - for (j = 0; j < surface[i].count_comps; j++) { - if (surface[i].comps[j].rate_name == NULL) continue; - comp_ptr = &surface[i].comps[j]; - comp_ptr->master = NULL; - n = surface[i].n_user; - - /* First find surface master species */ - - for (k=0; comp_ptr->totals[k].elt != NULL; k++) { - /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Master species not in data " - "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != SURF) continue; - comp_ptr->master = master_ptr; - break; - } - if (comp_ptr->master == NULL) { - input_error++; - sprintf(error_string, "Surface formula does not contain a surface master species, %s", comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find the kinetic reaction on which surface depends... */ - if ((kinetics_ptr=kinetics_bsearch(n, &k)) == NULL) { - input_error++; - sprintf(error_string, "Kinetics %d must be defined to use surface related to kinetic reaction, %s", n, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - for (k=0; kcount_comps; k++) { - if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { - break; - } - } - if (k == kinetics_ptr->count_comps) { - input_error++; - sprintf(error_string,"Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", comp_ptr->rate_name, comp_ptr->formula, n); - error_msg(error_string, CONTINUE); - continue; - } - - /* use database name for phase */ - comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; - - /* make surface concentration proportional to mineral ... */ - conc=kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; - -/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ - ptr = comp_ptr->formula; - count_elts = 0; - paren_count = 0; - get_elts_in_species(&ptr, conc); - comp_ptr->totals = (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); - - /* area */ - surface[i].charge[comp_ptr->charge].grams = kinetics_ptr->comps[k].m; - } -/* - * check on elements - */ - /* Go through each kinetic reaction, add all related surface compositions - * check for negative values - */ - if (surface[i].related_rate == FALSE) continue; - kinetics_ptr=kinetics_bsearch(n, &k); - for (k=0; k < kinetics_ptr->count_comps; k++) { - count_elts = 0; - paren_count = 0; - - /* added in kinetics formula */ - for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) { - phase_ptr = NULL; - strcpy(token, kinetics_ptr->comps[k].list[j].name); - phase_ptr = phase_bsearch(token, &jj, FALSE); - if (phase_ptr != NULL) { - add_elt_list(phase_ptr->next_elt, 1.0); - } else { - ptr = kinetics_ptr->comps[k].list[j].name; - get_elts_in_species (&ptr, kinetics_ptr->comps[k].list[j].coef); - } - } - /* save kinetics formula */ - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - elt_list_kinetics = elt_list_save(); - count_elts_kinetics = count_elts; - - /* get surface formulas */ - count_elts = 0; - paren_count = 0; - for (j = 0; j < surface[i].count_comps; j++) { - comp_ptr = &surface[i].comps[j]; - if (comp_ptr->rate_name == NULL) continue; - if (strcmp_nocase(comp_ptr->rate_name, kinetics_ptr->comps[k].rate_name) == 0) { - ptr = comp_ptr->formula; - get_elts_in_species(&ptr, -1 * comp_ptr->phase_proportion); - } - } - if (count_elts > 0 ) { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - for (j = 0; j < count_elts; j++) { - if (elt_list[j].elt->primary->s->type <= H2O) { - for (l = 0; l < count_elts_kinetics; l++) { - if (elt_list[j].elt == elt_list_kinetics[l].elt) { - break; - } - } - if (l == count_elts_kinetics) { - input_error++; - sprintf(error_string,"Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", comp_ptr->formula, (double) comp_ptr->phase_proportion, comp_ptr->rate_name, elt_list[j].elt->name); - error_msg(error_string, CONTINUE); - } else if (fabs(elt_list[j].coef) > fabs(elt_list_kinetics[l].coef)) { - input_error++; - sprintf(error_string,"Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", comp_ptr->formula, (double) comp_ptr->phase_proportion, comp_ptr->rate_name, elt_list[j].elt->name); - error_msg(error_string, CONTINUE); - } - } - } - elt_list_kinetics = (struct elt_list *) free_check_null(elt_list_kinetics); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, converged, divisions; - LDBLE r, rt, ag0, ag1, crit_pt; - LDBLE xc, tc; - LDBLE x, x0, x1, xsm1, xsm2, xb1, xb2; - LDBLE xc1, xc2; - LDBLE facb1, faca1, spim1, xblm1, acrae, acrael, xliapt, xliapm; - LDBLE xaly, xaly1, xaly2; - LDBLE faca, facb, spialy, facal, facbl; - LDBLE tol; - - if (pr.s_s_assemblage == FALSE) print = FALSE; - tol = 1e-6; - r = R_KJ_DEG_MOL; - rt = r * t; - a0 = s_s_ptr->ag0 / rt; - a1 = s_s_ptr->ag1 / rt; - s_s_ptr->a0 = a0; - s_s_ptr->a1 = a1; - ag0 = a0*rt; - ag1 = a1*rt; - kc = exp( k_calc(s_s_ptr->comps[0].phase->rxn->logk, t) * LOG_10); - kb = exp( k_calc(s_s_ptr->comps[1].phase->rxn->logk, t) * LOG_10); - crit_pt = fabs(a0) + fabs(a1); -/* - * Default, no miscibility or spinodal gaps - */ - s_s_ptr->miscibility = FALSE; - s_s_ptr->spinodal = FALSE; - xsm1 = 0.5; - xsm2 = 0.5; - xb1 = 0.5; - xb2 = 0.5; - xc1 = 0; - xc2 = 0; - - if (crit_pt >= tol) { -/* - * Miscibility gap information - */ - if (fabs(a1) < tol) { - xc = 0.5; - tc = ag0/(2*r); - } else { - xc = 0.5 + (pow((ag0*ag0 + 27*ag1*ag1), 0.5) - ag0) / (18*ag1); - tc = (12*ag1*xc - 6*ag1 + 2*ag0) * (xc - xc*xc)/r; - } - if (print == TRUE) { - sprintf(error_string,"Description of Solid Solution %s", s_s_ptr->name); - dup_print(error_string, TRUE); - } - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t Temperature: %g kelvin\n", (double) t); - output_msg(OUTPUT_MESSAGE,"\t A0 (dimensionless): %g\n", (double) a0); - output_msg(OUTPUT_MESSAGE,"\t A1 (dimensionless): %g\n", (double) a1); - output_msg(OUTPUT_MESSAGE,"\t A0 (kJ/mol): %g\n", (double) ag0); - output_msg(OUTPUT_MESSAGE,"\t A1 (kJ/mol): %g\n\n", (double) ag1); - } - if (xc < 0 || xc > 1) { - if (print == TRUE) output_msg(OUTPUT_MESSAGE,"No miscibility gap above 0 degrees kelvin.\n"); - } else { - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t Critical mole-fraction of component 2: %g\n", (double) xc); - output_msg(OUTPUT_MESSAGE,"\t Critical temperature: %g kelvin\n", (double) tc); - output_msg(OUTPUT_MESSAGE,"\n(The critical temperature calculation assumes that the Guggenheim model\ndefined at %g kelvin is valid at the critical temperature.)\n\n\n", (double) t); - } - } -/* - * Calculate miscibility and spinodal gaps - */ - if (tc >= t) { - - /* search for sign changes */ - x0 = 0; - x1 = 1; - if (scan(f_spinodal, &x0, &x1) == TRUE) { - - /* find first spinodal pt */ - xsm1 = halve(f_spinodal, x0, x1, tol); - s_s_ptr->spinodal = TRUE; - - /* find second spinodal pt */ - x0 = x1; - x1 = 1; - if (scan(f_spinodal, &x0, &x1) == TRUE) { - xsm2 = halve(f_spinodal, x0, x1, tol); - } else { - error_msg("Failed to find second spinodal point.", STOP); - } - } - } - } -/* - * Now find Miscibility gap - */ - if (s_s_ptr->spinodal == TRUE) { - if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\t Spinodal-gap mole fractions, component 2: %g\t%g\n", (double) xsm1, (double) xsm2); - converged = FALSE; - if (converged == FALSE) { - for (i = 1; i < 3; i++) { - divisions = (int) pow(10.,i); - for (j = 0; j < divisions; j++) { - for (k = divisions; k > 0; k--) { - xc1 = (LDBLE) j / divisions + 0.001; - xc2 = (LDBLE) k / divisions; - converged = solve_misc(&xc1, &xc2, tol); - if (converged == TRUE) break; - } - if (converged == TRUE) break; - } - if (converged == TRUE) break; - } - } - if (converged == FALSE) { - error_msg("Failed to find miscibility gap.", STOP); - } - s_s_ptr->miscibility = TRUE; - if (xc1 < xc2) { - xb1 = 1 - xc2; - xb2 = 1 - xc1; - xc1 = 1 - xb1; - xc2 = 1 - xb2; - } else { - xb1 = 1 - xc1; - xb2 = 1 - xc2; - } - facb1 = kb*xb1*exp(xc1*xc1*(a0 + a1*(4*xb1 -1))); - faca1 = kc*xc1*exp(xb1*xb1*(a0 - a1*(3-4*xb1))); - spim1 = log10(faca1 + facb1); - xblm1 = 1./(1. + faca1/facb1); - acrae = facb1/faca1; - acrael = log10(acrae); - xliapt = log10(facb1); - xliapm = log10(faca1); - - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE, "\t Miscibility-gap fractions, component 2: %g\t%g\n", (double) xb1, (double) xb2); - output_msg(OUTPUT_MESSAGE, "\n\t\t\tEutectic Point Calculations\n\n"); - output_msg(OUTPUT_MESSAGE, "\t Aqueous activity ratio (comp2/comp1): %g\n", (double) acrae); - output_msg(OUTPUT_MESSAGE, "\t Log aqueous activity ratio (comp2/comp1): %g\n", (double) acrael); - output_msg(OUTPUT_MESSAGE, "\t Aqueous activity fraction of component 2: %g\n", (double) xblm1); - output_msg(OUTPUT_MESSAGE, "\t Log IAP (component 2): %g\n", (double) xliapt); - output_msg(OUTPUT_MESSAGE, "\t Log IAP (component 1): %g\n", (double) xliapm); - output_msg(OUTPUT_MESSAGE, "\t Log Sum Pi: %g\n", (double) spim1); - } - s_s_ptr->tk = t; - s_s_ptr->xb1 = xb1; - s_s_ptr->xb2 = xb2; - } -/* - * Alyotropic point calculation - */ - xaly = -1.0; - x = a0*a0 + 3*a1*a1 + 6*a1*log(kb/kc); - if (x > 0) { - if (fabs(x - a0*a0) >= tol) { - xaly1 = (-(a0 - 3*a1) + pow(x, 0.5)) / (6*a1); - xaly2 = (-(a0 - 3*a1) - pow(x, 0.5)) / (6*a1); - if (xaly1 >= 0 && xaly1 <= 1) { - xaly = xaly1; - } - if (xaly2 >= 0 && xaly2 <= 1) { - xaly = xaly2; - } - } else { - xaly = 0.5 + log(kb/kc) / (2*a0); - } - if (xaly > 0 && xaly < 1) { - faca = kc * (1 - xaly) * exp(xaly*xaly*(a0 - a1 * (3 - 4*xaly))); - facb = kb * xaly * exp((1 - xaly)*(1 - xaly)*(a0 + a1 * (4*xaly - 1.0))); - spialy = log10(faca + facb); - facal = log10(faca); - facbl = log10(facb); - if (xaly > xb1 && xaly < xb2) { - if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\nLocal minimum in the solidus curve coresponding to a maximum\nin the minimum stoichiometric saturation curve.\n\n"); - } else { - if (print == TRUE) output_msg(OUTPUT_MESSAGE,"\n\t\t\tAlyotropic Point\n\n"); - } - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE,"\t Solid mole fraction of component 2: %g\n", (double) xaly); - output_msg(OUTPUT_MESSAGE,"\t Log IAP (component 2): %g\n", (double) facbl); - output_msg(OUTPUT_MESSAGE,"\t Log IAP (component 1): %g\n", (double) facal); - output_msg(OUTPUT_MESSAGE,"\t Log Sum Pi: %g\n", (double) spialy); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -static LDBLE halve(LDBLE f(LDBLE x), LDBLE x0, LDBLE x1, LDBLE tol) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE x, y, y0, dx; - - y0 = f(x0); - dx = (x1 - x0); -/* - * Loop for interval halving - */ - for (i = 0; i < 100; i++) { - dx *= 0.5; - x = x0 + dx; - y = f( x); - if (dx < tol || y == 0) { - break; - } -#ifdef SKIP - if (y0*y < 0) { - x1 = x; - } else { - x0 = x; - y0 = y; - } -#endif - if (y0*y >= 0) { - x0 = x; - y0 = y; - } - } - return(x0 + dx); -} -/* ---------------------------------------------------------------------- */ -static int scan(LDBLE f(LDBLE x), LDBLE *xx0, LDBLE *xx1) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE fx0, fx1, divisions; - LDBLE x0, x1, diff; - - x0 = *xx0; - x1 = *xx1; - diff = x1 - x0; - for (j = 0; j < 3; j++) { - fx0 = f(x0); - divisions = (int) pow(10, j); - for (i = 1; i < divisions; i++) { - x1 = *xx0 + diff * (LDBLE) i / divisions; - fx1 = f(x1); - if (fx0 * fx1 <= 0) { - *xx0 = x0; - *xx1 = x1; - return (TRUE); - } - x0 = x1; - fx0 = fx1; - } - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -static LDBLE f_spinodal(LDBLE x) -/* ---------------------------------------------------------------------- */ -{ - LDBLE fx; - fx = -12*a1*x*x*x + (18*a1 - 2*a0)*x*x + (2*a0 - 6*a1)*x - 1.0; - return(fx); -} -/* ---------------------------------------------------------------------- */ -int slnq (int n, LDBLE *a, LDBLE *delta, int ncols, int print) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, m; -/* debug - */ - int row; - - LDBLE b; -/* Debug -*/ - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nArray in slnq: \n\n"); - for (i=0; i < ncols - 1; i++) { - row=i*(n+1); - for (j=0; j < ncols; j++) { - output_msg(OUTPUT_MESSAGE,"%10.2e",(double) a[row+j]); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - output_msg(OUTPUT_MESSAGE,"\n"); - } - - if (n == 0) return(OK); -/* Trivial case */ - if (n == 1) { - if ( fabs(a[0]) < ZERO_TOL) goto slnq_error; - delta[0]=a[1]/a[0]; - return(OK); - } - -/* Reduction loop */ - for (i=0; i < n-1; i++) { - b=fabs(a[i*ncols + i]); - m=i; - -/* Find maximum value in column */ - for ( j=i+1; j < n; j++) { - if (fabs(a[j*ncols + i]) > b) { - b=fabs(a[j*ncols + i]); - m=j; - } - } - -/* Check for singularity */ - if ( b < ZERO_TOL ) goto slnq_error; - -/* Exchange rows if necessary */ - if (m != i) { - for ( j=i; j <= n; j++ ) { - b=a[i*ncols + j]; - a[i*ncols + j]=a[m*ncols + j]; - a[m*ncols + j]=b; - } - } - -/* Make a[i][i]=1.0 */ - for (j=n; j >= i; j--) { - a[i*ncols + j] /= a[i*ncols + i]; - } - -/* Reduction step */ - for (j=i+1; j < n; j++) { - if (a[j*ncols + i] == 0.0) continue; - b=-a[j*ncols + i]; - for (k=i+1; k <= n ; k++) { - a[j*ncols + k] += b*a[i*ncols + k]; - } - } - } - -/* Calculation of delta[n] */ - if (fabs(a[(n-1)*ncols + n-1]) > ZERO_TOL) { - delta[n-1]=a[(n-1)*ncols + n]/a[(n-1)*ncols + n - 1]; - } else { - output_msg(OUTPUT_MESSAGE,"Error: Divide by zero in slnq.\n"); - delta[n]=0.0; - goto slnq_error; - } - -/* Back substitution for other delta values */ - for (i=n-2; i>=0; i--) { - delta[i]=a[i*ncols + n]; - for (j = i+1; j < n; j++) { - delta[i] -= a[i*ncols + j]*delta[j]; - } - } - if (print == TRUE) { - output_msg(OUTPUT_MESSAGE,"\nResults from slnq: \n\n"); - for (i=0; i 1 || x1 < 0 || x2 > 1 || x2 < 0) { - d[0] *= 0.5; - d[1] *= 0.5; - } else { - repeat = FALSE; - } - }; - xc1 = x1; - xc2 = x2; - - if (fabs(xc1 - xc2) < .01) { - converged = FALSE; - break; - } - } - if (i == max_iter) converged = FALSE; - *xxc1 = xc1; - *xxc2 = xc2; - return(converged); -} -/* ---------------------------------------------------------------------- */ -static int s_s_calc_a0_a1(struct s_s *s_s_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, done; - LDBLE r, rt, *p; - LDBLE q1, q2, xbq1, xbq2, xb1, xb2, xc1, xc2; - LDBLE r1, r2, pa1, pb1, pa2, pb2, xsm1, xsm2; - LDBLE pn9, pn10, c5, c6, pl9, pl10, pj9, pj10; - LDBLE xc, tc; - LDBLE spialy, azero, phi1, phi2, test; - LDBLE dq1, dq2, denom, ratio, dr1, dr2, x21, x22, x61, x62; - LDBLE a0, a1, ag0, ag1; - LDBLE wg2, wg1, alpha2, alpha3; - LDBLE kc, kb; - LDBLE xaly, xcaly, alpha0, alpha1, fx, fx1; - LDBLE tol; - - tol = 1e-6; - rt = s_s_ptr->tk * R_KJ_DEG_MOL; - if (s_s_ptr->comps[0].phase == NULL || s_s_ptr->comps[1].phase == NULL) { - input_error++; - sprintf(error_string, "Two components were not defined for %s solid solution", s_s_ptr->name); - error_msg(error_string, CONTINUE); - return(ERROR); - } - kc = exp( k_calc(s_s_ptr->comps[0].phase->rxn->logk, s_s_ptr->tk) * LOG_10); - kb = exp( k_calc(s_s_ptr->comps[1].phase->rxn->logk, s_s_ptr->tk) * LOG_10); - - p = s_s_ptr->p; - - a0 = 0; - a1 = 0; - ag0 = 0; - ag1 = 0; - dq2 = 0; - switch (s_s_ptr->input_case) { - /* - * dimensionless a0 and a1 - */ - case 0: - a0 = p[0]; - a1 = p[1]; - ag0 = a0*rt; - ag1 = a1*rt; - break; - /* - * two activity coefficients - * q1, q2, xbq1, xbq2 - */ - case 1: - q1 = p[0]; - q2 = p[1]; - xbq1 = p[2]; - xbq2 = p[3]; - done = FALSE; - if (fabs(1 - xbq1) > 0 && q1 > 0) { - dq1 = log(q1)/ ((1 - xbq1)*(1 - xbq1)); - if (xbq2 <= 0 || xbq2 > 1) { - a0 = dq1; - a1 = 0; - done = TRUE; - } - } - if (done == FALSE) { - if (fabs(xbq2) < 0 || q2 <= 0) { - input_error++; - sprintf(error_string, "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - done = TRUE; - } - } - if (done == FALSE) { - dq2 = log(q2) / (xbq2 * xbq2); - if (xbq1 < 0. || xbq2 > 1.) { - a0 = dq2; - a1 = 0; - done = TRUE; - } - } - if (done == FALSE) { - denom = 4 * (xbq1 - xbq2) + 2; - if (fabs(denom) >= tol) { - if (fabs(1 - xbq1) > 0 && q1 > 0) { - dq1 = log(q1)/ ((1 - xbq1)*(1 - xbq1)); - a0 = (dq1 * (3 - 4*xbq2) + dq2 * (4*xbq1 - 1)) / denom; - a1 = (dq1 - dq2) / denom; - done = TRUE; - } - } - } - if (done == FALSE) { - input_error++; - sprintf(error_string, "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - } - /* io = 1 */ - ag0 = a0*rt; - ag1 = a1*rt; - break; - /* - * two distribution coefficients - * q1, q2, xbq1, xbq2 - */ - case 2: - q1 = p[0]; - q2 = p[1]; - xbq1 = p[2]; - xbq2 = p[3]; - ratio = kc/kb; - dr1 = log(q1/ratio); - x21 = 2*xbq1 - 1; - if (fabs(xbq1 - xbq2) < tol || xbq2 < 0) { - a0 = dr1 / x21; - a1 = 0; - } else { - dr2 = log(q2/ratio); - x22 = 2*xbq2 - 1; - if (xbq1 < 0.) { - a0 = dr2/x22; - a1 = 0; - } else { - x61 = 6*xbq1*xbq1 - 6*xbq1 + 1; - x62 = 6*xbq2*xbq2 - 6*xbq2 + 1; - if (fabs(x22*x61 - x21*x62) < tol) { - input_error++; - sprintf(error_string, "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - } - a0 = (x61*dr2 - x62*dr1) / (x22*x61 - x21*x62); - a1 = (x21*dr2 - x22*dr1) / (x21*x62 - x22*x61); - } - } - - /* io = 1 */ - ag0 = a0*rt; - ag1 = a1*rt; - break; - /* - * from miscibility gap fractions - * q1, q2 - */ - case 3: - q1 = p[0]; - q2 = p[1]; - xb1 = q1; - xb2 = q2; - xc1 = 1 - xb1; - xc2 = 1 - xb2; - r1 = log(xb1/xb2); - r2 = log(xc1/xc2); - pa1 = xc2*xc2 - xc1*xc1; - pb1 = 3*(xc2*xc2 - xc1*xc1) - 4*(xc2*xc2*xc2 - xc1*xc1*xc1); - pa2 = xb2*xb2 - xb1*xb1; - pb2 = -(3*(xb2*xb2 - xb1*xb1) - 4*(xb2*xb2*xb2 - xb1*xb1*xb1)); - a0 = (r1 - pb1/pb2*r2) / (pa1 - pa2*pb1/pb2); - a1 = (r1 - pa1/pa2*r2) / (pb1 -pb2*pa1/pa2); - - /* io = 1 */ - ag0 = a0*rt; - ag1 = a1*rt; - break; - /* - * from spinodal gap fractions - * q1, q2 - */ - case 4: - q1 = p[0]; - q2 = p[1]; - xsm1 = q1; - xsm2 = q2; - pn9 = 1/xsm1; - pn10 = 1/xsm2; - c5 = 1 - xsm1; - c6 = 1 - xsm2; - pl9 = 6*c5 - 12*c5*c5; - pl10 = 6*c6 - 12*c6*c6; - pj9 = 2*c5; - pj10 = 2*c6; - a0 = (pn9 - pl9/pl10*pn10) / (pj9 - pl9/pl10*pj10); - a1 = (pn9 - pj9/pj10*pn10) / (pl9 - pj9/pj10*pl10); - - /* io = 1 */ - ag0 = a0*rt; - ag1 = a1*rt; - break; - /* - * from critical point - * q1, q2 - */ - case 5: - xc = p[0]; - tc = p[1]; - r = R_KJ_DEG_MOL; - ag1 = r*tc* (2*xc - 1) / (12*xc*xc*(1 - xc)*(1 - xc)); - ag0 = (r*tc / (xc*(1 - xc)) - (12*xc - 6)*ag1) / 2; - - /* io = 0 */ - a0 = ag0/rt; - a1 = ag1/rt; - break; - /* - * from alyotropic point - * q1, q2 - */ - case 6: - q1 = p[0]; - q2 = p[1]; - xaly = q1; - r = log(kb/kc); - alpha0 = 2*xaly - 1; - alpha1 = 6*xaly*(xaly - 1) + 1; - spialy = pow(10., q2); - a0 = -999.; - a1 = -999.; - if (fabs(alpha0) < tol) { - input_error++; - sprintf(error_string, "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - } else { - azero = 1; - if (fabs(alpha0) > tol) azero = r/alpha0; - xcaly = 1 - xaly; -/* - * Solve for a0 by Newton's method - */ - for (i = 0; i < 50; i++) { - phi1 = xcaly*xcaly*(azero + (r - azero*alpha0)*(4*xaly - 1)/alpha1); - phi2 = xaly*xaly*(azero + (3 - 4*xaly)*(azero*alpha0 - r)/alpha1); - phi1 = xaly*kb*exp(phi1); - phi2 = xcaly*kc*exp(phi2); - fx = phi1 + phi2 - spialy; - fx1 = xcaly*xcaly*(1 - alpha0*(4*xaly - 1)/alpha1)*phi1 + - xaly*xaly*(1 + alpha0*(3 - 4*xaly)/alpha1)*phi2; - if (fabs(fx1) < 1e-10) { - input_error++; - sprintf(error_string, "Could not find A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - break; - } - a0 = azero - fx/fx1; - test = fabs(a0 - azero) + fabs(fx); - azero = a0; - if (test < tol) break; - } - if (i == 50) { - input_error++; - sprintf(error_string, "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", s_s_ptr->name); - error_msg(error_string, CONTINUE); - } else { - a1 = (r - a0 *alpha0) / alpha1; - - /* io = 0 */ - ag0 = a0 * rt; - ag1 = a1 * rt; - } - - } - break; - /* - * dimensional (kJ/mol) Guggenheim parameters - * ag0, ag1 - */ - case 7: - ag0 = p[0]; - ag1 = p[1]; - a0 = ag0 / rt; - a1 = ag1 / rt; - break; - /* - * Waldbaum-Thompson - * wg2, wg1 - */ - case 8: - wg2 = p[0]; - wg1 = p[1]; - ag0 = (wg2 + wg1) / 2; - ag1 = (wg2 - wg1) / 2; - a0 = ag0 / rt; - a1 = ag1 / rt; - break; - /* - * Margules - * alpha2, alpha3 - */ - case 9: - alpha2 = p[0]; - alpha3 = p[1]; - a0 = alpha2 + 3*alpha3/4; - a1 = alpha3/4; - ag0 = a0 * rt; - ag1 = a1 * rt; - break; - } - - s_s_ptr->ag0 = ag0; - s_s_ptr->ag1 = ag1; - s_s_ptr->a0 = a0; - s_s_ptr->a1 = a1; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_master_isotope(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct master *master_ptr; - - for (i = 0; i < count_master_isotope; i++) { - /* - * Mark master species list as minor isotope - */ - if (master_isotope[i]->minor_isotope == TRUE) { - master_ptr = master_bsearch(master_isotope[i]->name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "Did not find master species for isotope, %s", master_isotope[i]->name); - error_msg(error_string,CONTINUE); - master_isotope[i]->master = NULL; - continue; - } else { - master_isotope[i]->master = master_ptr; - } - master_ptr->minor_isotope = TRUE; - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_isotope_ratios(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct master *master_ptr; - struct master_isotope *master_isotope_ptr; - struct calculate_value *calculate_value_ptr; - - for (i = 0; i < count_isotope_ratio; i++) { - /* - * Mark master species list as minor isotope - */ - master_isotope_ptr = master_isotope_search(isotope_ratio[i]->isotope_name); - if (master_isotope_ptr == NULL) { - input_error++; - sprintf(error_string, "For ISOTOPE_RATIO %s, did not find ISOTOPE definition for this isotope, %s", isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); - error_msg(error_string,CONTINUE); - } - master_ptr = master_bsearch(isotope_ratio[i]->isotope_name); - if (master_ptr == NULL) { - input_error++; - sprintf(error_string, "For ISOTOPE_RATIO %s, did not find SOLUTION_MASTER_SPECIES for isotope, %s", isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); - error_msg(error_string,CONTINUE); - } - calculate_value_ptr = calculate_value_search(isotope_ratio[i]->name); - if (calculate_value_ptr == NULL) { - input_error++; - sprintf(error_string, "For ISOTOPE_RATIOS %s, did not find corresponding CALCULATE_VALUE definition", isotope_ratio[i]->name); - error_msg(error_string,CONTINUE); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int tidy_isotope_alphas(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct calculate_value *calculate_value_ptr; - struct logk *logk_ptr; - - for (i = 0; i < count_isotope_alpha; i++) { - /* - * Mark master species list as minor isotope - */ - calculate_value_ptr = calculate_value_search(isotope_alpha[i]->name); - if (calculate_value_ptr == NULL) { - input_error++; - sprintf(error_string, "For ISOTOPE_ALPHAS %s, did not find corresponding CALCULATE_VALUE definition", isotope_alpha[i]->name); - error_msg(error_string,CONTINUE); - } - if (isotope_alpha[i]->named_logk != NULL) { - logk_ptr = logk_search(isotope_alpha[i]->named_logk); - if (logk_ptr == NULL) { - input_error++; - sprintf(error_string, "For ISOTOPE_ALPHAS %s, did not find corresponding NAMED_EXPRESSION definition %s.", isotope_alpha[i]->name, isotope_alpha[i]->named_logk); - error_msg(error_string,CONTINUE); - } - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int reset_last_model(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Initialize model - */ - last_model.force_prep = TRUE; - last_model.count_exchange = 0; - last_model.exchange = (struct master **) free_check_null(last_model.exchange); - last_model.count_gas_phase = 0; - last_model.gas_phase = (struct phase **) free_check_null(last_model.gas_phase); - last_model.count_s_s_assemblage = 0; - last_model.s_s_assemblage = (char **) free_check_null(last_model.s_s_assemblage); - last_model.count_pp_assemblage = 0; - last_model.pp_assemblage = (struct phase **) free_check_null(last_model.pp_assemblage); - last_model.add_formula = (char **) free_check_null(last_model.add_formula); - last_model.si = (LDBLE *) free_check_null(last_model.si); - last_model.diffuse_layer = FALSE; - last_model.count_surface_comp = 0; - last_model.surface_comp = (struct master **) free_check_null(last_model.surface_comp); - last_model.count_surface_charge = 0; - last_model.surface_charge = (struct master **) free_check_null(last_model.surface_charge); - return(OK); -} diff --git a/transport.cpp b/transport.cpp deleted file mode 100644 index 4dba3182..00000000 --- a/transport.cpp +++ /dev/null @@ -1,844 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: transport.c 78 2005-02-01 22:47:12Z dlpark $"; - -static int init_mix(void); -static int init_heat_mix(int nmix); -static int heat_mix(int heat_nmix); -static int mix_stag(int i, LDBLE stagkin_time, int punch, LDBLE step_fraction_kin); - - -LDBLE *heat_mix_array; -LDBLE *temp1, *temp2; -int heat_nmix; -LDBLE heat_mix_f_imm, heat_mix_f_m; - -/* ---------------------------------------------------------------------- */ -int transport(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, n; - int j_imm, n_m, n_imm; - LDBLE b, f, mix_f_m, mix_f_imm; - LDBLE water_m, water_imm; - int first_c, last_c, b_c; - int nmix; - int max_iter; - char token[MAX_LENGTH]; - LDBLE kin_time, stagkin_time, kin_time_save; - struct mix *mix_ptr; - int punch_boolean; - LDBLE step_fraction; - if (svnid == NULL) fprintf(stderr," "); - - state = TRANSPORT; -/* mass_water_switch = TRUE; */ -/* - * Check existence of solutions - */ - j = -1; - /* check column solutions */ - for (i = 1; i <= count_cells; i++) { - use.solution_ptr = solution_bsearch(i, &n, TRUE); - if (use.solution_ptr == NULL) { - input_error++; - sprintf(error_string, "Solution %d is needed for transport, but is not defined.", i); - error_msg(error_string, CONTINUE); - } else { - cell_data[i-1].temp = use.solution_ptr->tc; - } - } - - /* check solution 0 */ - if (ishift == 1) { - if (solution_bsearch(0, &n, TRUE) == NULL) { - input_error++; - sprintf(error_string, "Solution 0 is needed for transport, but is not defined."); - error_msg(error_string, CONTINUE); - } - } - - /* check solution count_cells */ - if (ishift == -1) { - if (solution_bsearch(count_cells+1, &n, TRUE) == NULL) { - input_error++; - sprintf(error_string, "Solution %d is needed for transport, but is not defined.", count_cells+1); - error_msg(error_string, CONTINUE); - } - } -/* - * Stop if error - */ - if (input_error > 0) { - error_msg("Program terminating due to input errors.", STOP); - } -/* - * Initialize temperature in stagnant cells ... - */ - for (n=1; n<=stag_data->count_stag; n++) { - for (i=1; i <= count_cells; i++) { - k = i+1+n*count_cells; - use.solution_ptr = solution_bsearch(k, &use.n_solution, FALSE); - if (use.solution_ptr != NULL) { - cell_data[k-1].temp = use.solution_ptr->tc; - } - } - } - - if (solution_bsearch(0, &n, FALSE) == NULL) solution_duplicate(1,0); - if (solution_bsearch(count_cells+1, &n, FALSE) == NULL) solution_duplicate(count_cells, count_cells+1); - -/* - * Initialize mixing factors, define kinetics times - */ - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { - mix_ptr = &mix[0]; - for (i = 0; i < count_mix; i++) mix_free(mix_ptr++); - count_mix = 2*count_cells; - mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof(struct mix)); - if (mix == NULL) malloc_error(); - memset(mix, 0, sizeof(struct mix) * count_mix); - } - nmix = init_mix(); - heat_nmix = init_heat_mix(nmix); - if (nmix < 2) stagkin_time = timest; else stagkin_time = timest/nmix; - if (ishift != 0 ) kin_time = timest/(1+nmix); else kin_time = stagkin_time; - kin_time_save = kin_time; - -/* Reaction defined for a shift... */ - step_fraction = 1.0/(1.0+nmix); - -/* - * Set boundary conditions, transport direction - */ - last_model.force_prep = TRUE; - if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) { - b_c = 1; - } else { - b_c = 0; - } - if (ishift >= 0) { - last_c = count_cells; - first_c = 1; - } else { - last_c = 1; - first_c = count_cells; - } -/* - * First equilibrate solutions - */ - dup_print("Equilibrating initial solutions", TRUE); - transport_step = 0; - for (i=1; i <= count_cells; i++) { - set_initial_moles(i); - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - if (cell_data[i-1].punch == TRUE) punch_all(); - if (cell_data[i-1].print == TRUE) print_all(); - saver(); - } -/* - * Also stagnant cells - */ - for (n=1; n<=stag_data->count_stag; n++) { - for (i=1; i <= count_cells; i++) { - k = i+1+n*count_cells; - cell_no = k; - if (solution_bsearch(k, &use.n_solution, FALSE) != 0 ) { - set_initial_moles(k); - set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); - if ((cell_data[k-1].punch == TRUE)) punch_all(); - if ((cell_data[k-1].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); - saver(); - } - } - } -/* - * Define stagnant/mobile mix structure, if not read explicitly. - * - * With count_stag = 1, mix factors are calculated from exchange factor à - * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. - * These variables are read under keyword TRANSPORT, after stagnant, in - * structure stag_data. - * MIX 'cell_no' in input file can be an alternative for the calculation here. - */ - - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { - - b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); - f = exp( - stag_data->exch_f * stagkin_time / (b * stag_data->th_im) ); - mix_f_imm = b - b * f; - mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; - - n = 0; - for (i=1; i <= count_cells; i++) { - j = i; - j_imm = j + (1 + count_cells); - if (solution_bsearch(j, &n_m, TRUE) == NULL) { - error_msg("Could not find mobile cell solution in TRANSPORT.", STOP); - } - if (solution_bsearch(j_imm, &n_imm, TRUE) == NULL) { - error_msg("Could not find immobile cell solution in TRANSPORT.", STOP); - } - water_m = solution[n_m]->mass_water; - water_imm = solution[n_imm]->mass_water; -/* - * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 - */ - mix[n].comps = (struct mix_comp *) PHRQ_malloc((size_t) 2*sizeof(struct mix_comp)); - if (mix[n].comps == NULL) malloc_error(); - mix[n].count_comps = 2; - mix[n].description = string_duplicate(" "); - mix[n].n_user = j; - mix[n].n_user_end = j; - mix[n].comps[0].n_solution = j; - mix[n].comps[0].fraction = 1 - mix_f_m; - mix[n].comps[1].n_solution = j_imm; - mix[n].comps[1].fraction = mix_f_m*water_m/water_imm; - n++; -/* - * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... - */ - mix[n].comps = (struct mix_comp *) PHRQ_malloc((size_t) 2*sizeof(struct mix_comp)); - if (mix[n].comps == NULL) malloc_error(); - mix[n].count_comps = 2; - mix[n].description = string_duplicate(" "); - mix[n].n_user = j_imm; - mix[n].n_user_end = j_imm; - mix[n].comps[0].n_solution = j_imm; - mix[n].comps[0].fraction = 1 - mix_f_imm; - mix[n].comps[1].n_solution = j; - mix[n].comps[1].fraction = mix_f_imm*water_imm/water_m; - n++; - } - - if (heat_nmix > 0) { -/* - * Assumption: D_e used for calculating exch_f in input file equals diffc - */ - f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; - f = exp( - f * stagkin_time / (b * stag_data->th_im) ); - heat_mix_f_imm = b - b * f; - heat_mix_f_m = heat_mix_f_imm * stag_data->th_im / stag_data->th_m; - } - } -/* - * Now transport - */ - max_iter = 0; - for (transport_step = transport_start; transport_step <= count_shifts; transport_step++) { - /* - * Set initial moles of phases - */ - for (i = 1; i <= count_cells; i++) { - set_initial_moles(i); - } - -/* - * Start diffusing if boundary cond = 1, (fixed c, or closed) - */ - if (b_c == 1) { - - /* For half of mixing steps */ - - for (j = 1; j <= floor(nmix/2); j++) { - rate_sim_time_start = (transport_step - 1) * timest + (j-1) * kin_time; - rate_sim_time = rate_sim_time_start + kin_time; - - sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); - dup_print(token, FALSE); - - if (heat_nmix > 0) { - heat_mix(heat_nmix); - /* equilibrate again ... */ - for (i=1; i <= count_cells; i++) { - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - saver(); - } - } - - /* Go through cells */ - - for (i = 1; i <= count_cells; i++) { - -#ifdef SKIP -/* this is somewhere lost; quickened in set_and_run ... */ - if (i == 1) { - last_model.force_prep = TRUE; - } -#endif - if (iterations > max_iter) max_iter = iterations; - sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, j, i, max_iter); - status(0, token); - - cell_no = i; - run_reactions(i, kin_time, DISP, step_fraction); - - /* punch and output file */ - if ((ishift == 0) && (j == nmix) && - ((stag_data->count_stag == 0) || - solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0)){ - if ((cell_data[i-1].punch == TRUE) && - (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i-1].print == TRUE) && - (transport_step % print_modulus == 0)) print_all(); - } - if (i > 1) solution_duplicate(-2, i-1); - saver(); - } - solution_duplicate(-2, count_cells); - - /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ - - rate_sim_time_start = (transport_step - 1)*timest + (j-1)*stagkin_time; - rate_sim_time = rate_sim_time_start + stagkin_time; - - if (stag_data->count_stag > 0) { - if ((ishift == 0) && (j == nmix)) punch_boolean = TRUE; else punch_boolean = FALSE; - for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, step_fraction); - } - } - } -/* - * Advective transport - */ - if (ishift !=0) { - sprintf(token, "Transport step %3d.", transport_step); - dup_print(token, FALSE); - if (b_c == 1) { - rate_sim_time_start = (transport_step -1)*timest + (j-1)*kin_time; - } else { - rate_sim_time_start = (transport_step -1)*timest; - } - rate_sim_time = rate_sim_time_start + kin_time; - -/* halftime kinetics for resident water in first cell ... */ - if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) { - cell_no = first_c; - kin_time = kin_time_save / 2; - run_reactions(first_c, kin_time, NOMIX, 0.0); - saver(); - kin_time = kin_time_save; - } - - /* for each cell in column */ -/* Begin revision Dec 7, 1999 */ - for (i = last_c; i != (first_c-ishift); i-=ishift) { - solution_duplicate(i-ishift, i); - } -/* - * thermal diffusion when nmix = 0... - */ - if ((nmix == 0) && (heat_nmix > 0)) { - heat_mix(heat_nmix); - /* equilibrate again ... */ - for (i=1; i <= count_cells; i++) { - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - saver(); - } - } - - for (i = 1; i <= count_cells; i++) { - if (i == first_c && count_cells > 1) kin_time /= 2; - sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, 0, i, max_iter); - status(0, token); - cell_no = i; - run_reactions(i, kin_time, NOMIX, step_fraction); - if (iterations > max_iter) max_iter = iterations; -/* end revision Dec 7, 1999 */ - - if ((nmix == 0) && - ((stag_data->count_stag == 0) || - (solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0))) { - if ((cell_data[i-1].punch == TRUE) && - (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i-1].print == TRUE) && - (transport_step % print_modulus == 0)) print_all(); - } - if (i == first_c && count_cells > 1) kin_time = kin_time_save; - saver(); - - /* If nmix is zero, stagnant zone mixing after - advective step ... */ - - if ((nmix == 0) && (stag_data->count_stag > 0)) mix_stag(i, stagkin_time, TRUE, step_fraction); - } - } - -/* - * Further dispersive and diffusive transport - */ - if (b_c != 1) j = 1; - for (j = j; j <= nmix; j++) { - sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); - dup_print(token, FALSE); - rate_sim_time_start = (transport_step - 1)*timest + (j - 1) * kin_time; - if (ishift != 0) rate_sim_time_start += kin_time; - rate_sim_time = rate_sim_time_start + kin_time; - - if (heat_nmix > 0) { - heat_mix(heat_nmix); - /* equilibrate again ... */ - for (i=1; i <= count_cells; i++) { - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - saver(); - } - } - - /* for each cell in column */ - - for (i = 1; i <= count_cells; i++) { - if (iterations > max_iter) max_iter = iterations; - sprintf(token, "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, j, i, max_iter); - status(0, token); - cell_no = i; - run_reactions(i, kin_time, DISP, step_fraction); - - if ((j == nmix) && - ((stag_data->count_stag == 0) || - (solution_bsearch(i+1+count_cells, &use.n_solution, FALSE) == 0))) { - if ((cell_data[i-1].punch == TRUE) && - (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i-1].print == TRUE) && - (transport_step % print_modulus == 0)) { - print_all(); - } - } - if (i > 1) solution_duplicate(-2, i-1); - saver(); - } - solution_duplicate(-2, count_cells); - /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ - - rate_sim_time_start = (transport_step - 1)*timest + (j - 1) * stagkin_time; - rate_sim_time = rate_sim_time_start + stagkin_time; - - if (stag_data->count_stag > 0) { - if (j == nmix) punch_boolean = TRUE; else punch_boolean = FALSE; - for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, step_fraction); - } - } - if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) dump(); - } -#ifdef DOS - output_msg(OUTPUT_SCREEN, "\n"); -#else - output_msg(OUTPUT_SCREEN, "%s%-80s", "\n", " "); -#endif - /* free_model_allocs(); */ -/* - * free mix structures - */ - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { - mix_ptr = &mix[0]; - for (i = 0; i < count_mix; i++) mix_free(mix_ptr++); - count_mix =0; - } else { - if (nmix > 0) { - mix_ptr = &mix[count_mix - count_cells]; - for (i = count_mix - count_cells; i < count_mix; i++) { - mix_free(mix_ptr++); - } - count_mix -= count_cells; - mix = (struct mix *) PHRQ_realloc(mix, (size_t) (count_mix + 1)*sizeof(struct mix)); - if (mix == NULL) malloc_error(); - } - } - if (heat_nmix > 0) { - free_check_null(heat_mix_array); - free_check_null(temp1); - free_check_null(temp2); - } - - initial_total_time += rate_sim_time; - rate_sim_time = 0; - mass_water_switch = FALSE; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int init_mix(void) -/* ---------------------------------------------------------------------- */ -{ - LDBLE dav, lav, mixf, maxmix, corr_disp; - int i, n, nmix, count_comps, max_mix; - LDBLE *m; - - m = (LDBLE *) PHRQ_malloc((count_cells+1)*sizeof(LDBLE)); - if (m == NULL) malloc_error(); - -/* - * Define mixing factors among inner cells - */ - corr_disp = 1.; - if (correct_disp == TRUE && ishift != 0) { - if (bcon_first == 3) corr_disp += 1. / count_cells; - if (bcon_last == 3) corr_disp += 1. / count_cells; - } - maxmix = 0.0; - for (i=1; i < count_cells; i++) { - lav = (cell_data[i-1].length + cell_data[i].length)/2; - if (ishift != 0) { - dav = (cell_data[i-1].disp + cell_data[i].disp)/2; - } else { - dav = 0; - } - mixf = (diffc*timest/lav + dav) * corr_disp / lav; - - if (mixf > maxmix) maxmix = mixf; - m[i] = mixf; /* m[i] has mixf with lower cell */ - } -/* - * Also for boundary cells - */ - if (bcon_first == 1) { - lav = cell_data[0].length; - if (ishift != 0) { - dav = cell_data[0].disp; - } else { - dav = 0; - } - mixf = (diffc*timest/lav + dav)/lav; - if (mixf > maxmix) maxmix = mixf; - m[0] = 2*mixf; - } else { - m[0] = 0; - } - if (bcon_last == 1) { - lav = cell_data[count_cells-1].length; - if (ishift != 0) { - dav = cell_data[count_cells-1].disp; - } else { - dav = 0; - } - mixf = (diffc*timest/lav + dav)/lav; - if (mixf > maxmix) maxmix = mixf; - m[count_cells] = 2*mixf; - } else { - m[count_cells] = 0; - } -/* - * Find number of mixes - */ - if (maxmix == 0) { - nmix = 0; - } else { - if ((bcon_first == 1) || (bcon_last == 1)) { - nmix = 1 + (int) floor(4.5 * maxmix); - } else { - nmix = 1 + (int) floor(3.0 * maxmix); - } - if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { - if (nmix < 2) nmix = 2; - } - for (i=0; i<=count_cells; i++) m[i] /= nmix; - } - /* - * Fill mix structure - */ - if (nmix != 0) { - mix = (struct mix *) PHRQ_realloc(mix, (size_t) (count_mix + count_cells)*sizeof(struct mix)); - if (mix == NULL) malloc_error(); - count_mix += count_cells; - for (n = count_mix-count_cells; ncount_stag + 1) + 1) { - max_mix = count_cells * (stag_data->count_stag + 1) + 1; - } - for (i=1; i<=count_cells; i++) { - dav = 0; - count_comps = 0; - mix[n].description = (char *) free_check_null(mix[n].description); - mix[n].description = string_duplicate(" "); -/* - * max_mix brings n_user outside range of active cells - * mix[n].n_user = mix[n].n_user_end = -999 has same effect - * but max_mix keeps mix in sort order in case mix_bsearch - * is used - */ - mix[n].n_user = max_mix + i ; - mix[n].n_user_end = max_mix + i ; - - mix[n].comps[count_comps].n_solution = i-1; - mix[n].comps[count_comps].fraction = m[i-1]; - dav += m[i-1]; - count_comps++; - mix[n].comps[count_comps].n_solution = i+1; - mix[n].comps[count_comps].fraction = m[i]; - dav += m[i]; - count_comps++; - mix[n].comps[count_comps].n_solution = i; - mix[n].comps[count_comps].fraction = 1.0 - dav; - - n++; - } - } - m = (LDBLE *) free_check_null(m); - return(nmix); -} -/* ---------------------------------------------------------------------- */ -int mix_stag(int i, LDBLE kin_time, int punch, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ - int n, k, l; - LDBLE t_imm; - struct solution *ptr_imm, *ptr_m; -#ifdef SKIP - char str[MAX_LENGTH]; -#endif -/* - * Kinetics in transport cell is done while transporting - */ - for (n=1; n<=stag_data->count_stag; n++) { - k = i+1+n*count_cells; - if ((ptr_imm = solution_bsearch(k, &use.n_solution, FALSE)) != NULL ) { - if (n == 1) { - if (heat_nmix > 0) { - ptr_m = solution_bsearch(i, &use.n_solution, FALSE); - t_imm = heat_mix_f_imm * ptr_m->tc + (1 - heat_mix_f_imm) * ptr_imm->tc; - ptr_m->tc = heat_mix_f_m * ptr_imm->tc + (1 - heat_mix_f_m) * ptr_m->tc; - cell_data[i-1].temp = ptr_m->tc; - cell_data[k-1].temp = ptr_imm->tc = t_imm; - /* equilibrate again ... */ - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - saver(); - cell_no = k; - set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); - saver(); - } -/* - * Mobile cell, kinetics already done ... - */ - cell_no = i; - set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); - if ((use.kinetics_ptr = kinetics_bsearch(i, &l)) != NULL) { - use.n_kinetics_user = i; - use.kinetics_in = TRUE; - } - if ((punch == TRUE) && - (cell_data[i-1].punch == TRUE) && - (transport_step % punch_modulus == 0)) punch_all(); - if ((punch == TRUE) && - (cell_data[i-1].print == TRUE) && - (transport_step % print_modulus == 0)) { - print_all(); - } - saver(); - } - cell_no = k; - run_reactions(k, kin_time, STAG, step_fraction); - if ((cell_data[k-1].punch == TRUE) && - (punch == TRUE) && - (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[k-1].print == TRUE) && - (punch == TRUE) && - (transport_step % print_modulus == 0)) { - print_all(); - } - saver(); - } - } - for (n=1; n<=stag_data->count_stag; n++) { - k = i+1+n*count_cells; - if (solution_bsearch(k, &use.n_solution, FALSE) != 0 ) { - solution_duplicate(-2-k, k); - if (n == 1) solution_duplicate(-2, i); - } - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int init_heat_mix(int nmix) -/* ---------------------------------------------------------------------- */ -{ - LDBLE lav, mixf, maxmix, corr_disp; - int i, j, k, n; - int heat_nmix; - LDBLE t0; -/* - * Check for need to model thermal diffusion... - */ - if (heat_diffc <= diffc) return(0); - if (count_cells < 2) return(0); - - heat_nmix = 0; - t0 = solution_bsearch(0, &n, FALSE)->tc; - for (i = 0; i < count_cells; i++) { - if (fabs(cell_data[i].temp - t0) > 1.0) { - heat_nmix = 1; - break; - } - } - if (heat_nmix == 0) { - if (fabs(solution_bsearch(count_cells+1, &n, FALSE)->tc - t0) > 1.0) heat_nmix = 1; - for (n = 1; n <= stag_data->count_stag; n++) { - for (i = 1; i < count_cells; i++) { - k = i+1+n*count_cells; - if (solution_bsearch(k, &j, FALSE) != 0 ) { - if (fabs(cell_data[k-1].temp - t0) > 1.0) { - heat_nmix = 1; - break; - } - } - } - } - } - if (heat_nmix == 0) return(0); -/* - * Initialize arrays... - */ - heat_mix_array = (LDBLE *) PHRQ_malloc((count_cells+2)*sizeof(LDBLE)); - if (heat_mix_array == NULL) malloc_error(); - temp1 = (LDBLE *) PHRQ_malloc((count_cells + 2)*sizeof(LDBLE)); - if (temp1 == NULL) malloc_error(); - temp2 = (LDBLE *) PHRQ_malloc((count_cells + 2)*sizeof(LDBLE)); - if (temp2 == NULL) malloc_error(); -/* - * Define mixing factors among inner cells... - */ - corr_disp = 1.; - if (correct_disp == TRUE && ishift != 0) { - if (bcon_first == 3) corr_disp += 1. / count_cells; - if (bcon_last == 3) corr_disp += 1. / count_cells; - } - if (nmix > 0) corr_disp /= nmix; - maxmix = 0.0; - for (i=1; i < count_cells; i++) { - lav = (cell_data[i-1].length + cell_data[i].length)/2; - mixf = (heat_diffc - diffc) * timest * corr_disp / tempr / (lav *lav); - if (mixf > maxmix) maxmix = mixf; - heat_mix_array[i+1] = mixf; /* m[i] has mixf with lower cell */ - } -/* - * Also for boundary cells - */ - if (bcon_first == 1) { - lav = cell_data[0].length; - mixf = (heat_diffc - diffc) * timest * corr_disp / tempr /(lav * lav); - if (2*mixf > maxmix) maxmix = 2*mixf; - heat_mix_array[1] = 2*mixf; - } else { - heat_mix_array[1] = 0; - } - if (bcon_last == 1) { - lav = cell_data[count_cells-1].length; - mixf = (heat_diffc - diffc) * timest * corr_disp / tempr /(lav * lav); - if (2*mixf > maxmix) maxmix = 2*mixf; - heat_mix_array[count_cells+1] = 2*mixf; - } else { - heat_mix_array[count_cells+1] = 0; - } -/* - * Find number of mixes - */ - if (maxmix == 0) { - heat_nmix = 0; - } else { - heat_nmix = 1 + (int) floor(3.0 * maxmix); - for (i=1; i <= count_cells + 1; i++) heat_mix_array[i] /= heat_nmix; - } - - return(heat_nmix); -} -/* ---------------------------------------------------------------------- */ -int heat_mix(int heat_nmix) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - - for (i = 1; i <= count_cells; i++) temp1[i] = solution_bsearch(i, &j, FALSE)->tc; - temp1[0] = solution_bsearch(0, &j, FALSE)->tc; - temp1[count_cells+1] = solution_bsearch((count_cells+1), &j, FALSE)->tc; - - for (i = 1; i <= heat_nmix; i++) { - for (j = 1; j <= count_cells; j++) { - temp2[j] = heat_mix_array[j] * temp1[j-1] + - heat_mix_array[j+1] * temp1[j+1] + - (1 - heat_mix_array[j] - heat_mix_array[j+1]) * temp1[j]; - } - for (j = 1; j <= count_cells; j++) temp1[j] = temp2[j]; - } - - for (i = 1; i <= count_cells; i++) { - cell_data[i-1].temp = temp1[i]; - solution_bsearch(i, &j, FALSE)->tc = temp1[i]; - } - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int set_initial_moles(int i) -/* ---------------------------------------------------------------------- */ -{ - struct pp_assemblage *pp_assemblage_ptr; - struct gas_phase *gas_phase_ptr; - struct kinetics *kinetics_ptr; - struct s_s_assemblage *s_s_assemblage_ptr; - int j, k, n; - /* - * Pure phase assemblage - */ - pp_assemblage_ptr = pp_assemblage_bsearch (i, &n); - if (pp_assemblage_ptr != NULL) { - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) { - pp_assemblage_ptr->pure_phases[j].initial_moles = pp_assemblage_ptr->pure_phases[j].moles; - if (pp_assemblage_ptr->pure_phases[j].initial_moles < 0) pp_assemblage_ptr->pure_phases[j].initial_moles = 0; - } - } - /* - * Gas phase - */ - gas_phase_ptr = gas_phase_bsearch (i, &n); - if (gas_phase_ptr != NULL) { - for (j = 0; j < gas_phase_ptr->count_comps; j++) { - gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; - } - } - /* - * Kinetics - */ - kinetics_ptr = kinetics_bsearch (i, &n); - if (kinetics_ptr != NULL) { - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; - } - } - /* - * Solid solutions - */ - s_s_assemblage_ptr = s_s_assemblage_bsearch (i, &n); - if (s_s_assemblage_ptr != NULL) { - for (k = 0; k < s_s_assemblage_ptr->count_s_s; k++) { - for (j = 0; j < s_s_assemblage_ptr->s_s[k].count_comps; j++) { - s_s_assemblage_ptr->s_s[k].comps[j].init_moles = s_s_assemblage_ptr->s_s[k].comps[j].moles; - } - } - } - return(OK); -} diff --git a/utilities.cpp b/utilities.cpp deleted file mode 100644 index 40a6e640..00000000 --- a/utilities.cpp +++ /dev/null @@ -1,1471 +0,0 @@ -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "output.h" -#include "phrqproto.h" - -static char const svnid[] = "$Id: utilities.c 674 2005-11-21 15:01:22Z dlpark $"; - -#ifdef PHREEQ98 -extern int AutoLoadOutputFile, CreateToC; -extern int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; -extern int outputlinenr; -extern int stop_calculations; -void AddToCEntry(char* a, int l, int i); -void ApplicationProcessMessages(void); -/* void check_line_breaks(char *s); */ -char err_str98[80]; -int copy_title(char *token_ptr, char **ptr, int *length); -extern int clean_up_null(void); -#endif - -static int isamong(char c, const char *s_l); - -/* ---------------------------------------------------------------------- */ -int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef) -/* ---------------------------------------------------------------------- */ -{ - struct elt_list *elt_list_ptr1; - if (svnid == NULL) fprintf(stderr," "); - - if (elt_list_ptr == NULL) return(OK); - - for (elt_list_ptr1=elt_list_ptr; elt_list_ptr1->elt != NULL; elt_list_ptr1++) { - if (count_elts >= max_elts) { - space ((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - elt_list[count_elts].elt = elt_list_ptr1->elt; - elt_list[count_elts].coef = elt_list_ptr1->coef * coef; - count_elts++; - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -LDBLE calc_alk(struct reaction *rxn_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE return_value; - struct master *master_ptr; - - return_value = 0.0; - for ( i=1; rxn_ptr->token[i].s != NULL; i++) { - master_ptr = rxn_ptr->token[i].s->secondary; - if (master_ptr == NULL ) { - master_ptr = rxn_ptr->token[i].s->primary; - } - if (master_ptr == NULL ) { - sprintf(error_string, "Non-master species in secondary reaction, %s.", rxn_ptr->token[0].s->name); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - return_value += rxn_ptr->token[i].coef * master_ptr->alk; - } - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int compute_gfw(const char *string, LDBLE *gfw) -/* ---------------------------------------------------------------------- */ -{ -/* - * Input: string contains a chemical formula - * Output: gfw contains the calculated gfw - */ - int i; - char token[MAX_LENGTH]; - char *ptr; - - count_elts=0; - paren_count=0; - strcpy(token, string); - ptr = token; - if (get_elts_in_species (&ptr, 1.0) == ERROR) { - return(ERROR); - } - *gfw=0.0; - for (i=0; i < count_elts; i++) { - if (elt_list[i].elt->gfw <= 0.0) { - return(ERROR); - } - *gfw += elt_list[i].coef*(elt_list[i].elt)->gfw; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int copy_token (char *token_ptr, char **ptr, int *length) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies from **ptr to *token_ptr until first space is encountered. - * - * Arguments: - * *token_ptr output, place to store token - * - * **ptr input, character string to read token from - * output, next position after token - * - * length output, length of token - * - * Returns: - * UPPER, - * LOWER, - * DIGIT, - * EMPTY, - * UNKNOWN. - */ - int i, return_value; - char c; - -/* - * Read to end of whitespace - */ - while ( isspace((int) (c=**ptr)) ) (*ptr)++; -/* - * Check what we have - */ - if ( isupper((int) c) || c == '[') { - return_value=UPPER; - } else if ( islower((int) c) ) { - return_value=LOWER; - } else if ( isdigit((int) c) || c=='.' || c=='-') { - return_value=DIGIT; - } else if ( c == '\0') { - return_value=EMPTY; - } else { - return_value=UNKNOWN; - } -/* - * Begin copying to token - */ - i=0; - while ( ( ! isspace ((int) (c=**ptr)) ) && - /* c != ',' && */ - c != ';' && - c != '\0' ) { - token_ptr[i]=c; - (*ptr)++; - i++; - } - token_ptr[i]='\0'; - *length=i; -#ifdef PHREEQ98 - if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) { - sprintf(error_string, "Commas are not allowed as decimal separator: %s.", token_ptr); - error_msg(error_string, CONTINUE); - } -#endif - return(return_value); -} -#ifdef PHREEQ98 -/* ---------------------------------------------------------------------- */ -int copy_title(char *token_ptr, char **ptr, int *length) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies from **ptr to *token_ptr until first space or comma is encountered. - * - * Arguments: - * *token_ptr output, place to store token - * - * **ptr input, character string to read token from - * output, next position after token - * - * length output, length of token - * - * Returns: - * UPPER, - * LOWER, - * DIGIT, - * EMPTY, - * UNKNOWN. - */ - int i, return_value; - char c; - int Quote = FALSE; - -/* - * Read to end of whitespace - */ - while ( isspace((int) (c=**ptr)) || (c == ',') || (c == '"')) { - if (c == '"') Quote = TRUE; - (*ptr)++; - } -/* - * Check what we have - */ - if ( isupper((int) c) ) { - return_value=UPPER; - } else if ( islower((int) c) ) { - return_value=LOWER; - } else if ( isdigit((int) c) || c=='.' || c=='-') { - return_value=DIGIT; - } else if ( c == '\0') { - return_value=EMPTY; - } else { - return_value=UNKNOWN; - } -/* - * Begin copying to token - */ - i=0; - if (Quote == TRUE) { - while ( ( (int) (c=**ptr) != '"' ) && - c != '\0' ) { - token_ptr[i]=c; - (*ptr)++; - i++; - } - } else { - while ( ( ! isspace ((int) (c=**ptr)) ) && - c != ',' && - c != ';' && - c != '\0' ) { - token_ptr[i]=c; - (*ptr)++; - i++; - } - } - token_ptr[i]='\0'; - *length=i; - return(return_value); -} -#endif -/* ---------------------------------------------------------------------- */ -int dup_print(const char *ptr, int emphasis) -/* ---------------------------------------------------------------------- */ -{ -/* - * print character string to output and logfile - * if emphasis == TRUE the print is set off by - * a row of dashes before and after the character string. - * - */ - int l, i; - char *dash; - - if (pr.headings == FALSE) return(OK); -#ifdef PHREEQ98 - if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) { - if (strstr(ptr,"Reading") == ptr) AddToCEntry((char*)ptr, 1, outputlinenr); - else if (strstr(ptr,"Beginning") == ptr) AddToCEntry((char*)ptr, 2, outputlinenr); - else if ((strstr(ptr,"TITLE") != ptr) && (strstr(ptr,"End") != ptr)) AddToCEntry((char*)ptr, 3, outputlinenr); - } -#endif - l = strlen(ptr); - dash = (char *) PHRQ_malloc((size_t) (l+2) * sizeof(char)); - if (dash == NULL) malloc_error(); - if (emphasis == TRUE) { - for (i = 0; i < l; i++) dash[i] = '-'; - dash[i] = '\0'; - output_msg(OUTPUT_MESSAGE,"%s\n%s\n%s\n\n", dash, ptr, dash); - output_msg(OUTPUT_LOG,"%s\n%s\n%s\n\n", dash, ptr, dash); - } else { - output_msg(OUTPUT_MESSAGE,"%s\n\n", ptr); - output_msg(OUTPUT_LOG,"%s\n\n", ptr); - } - dash = (char*) free_check_null(dash); - - return(OK); -} -/* ---------------------------------------------------------------------- */ -int equal (LDBLE a, LDBLE b, LDBLE eps) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks equality between two LDBLE precision numbers - */ - if( fabs(a-b) <= eps ) return(TRUE); - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -void *free_check_null(void *ptr) -/* ---------------------------------------------------------------------- */ -{ - if (ptr != NULL) { - free(ptr); - } - return(NULL); -} -/* ---------------------------------------------------------------------- */ -int get_token(char **eqnaddr, char *string, LDBLE *z, int *l) -/* ---------------------------------------------------------------------- */ -/* - * Function finds next species in equation, coefficient has already - * been removed. Also determines charge on the species. - * - * Arguments: - * *eqnaddr input, pointer to position in eqn to start parsing - * output, pointer to a pointer to next position in eqn to start - * parsing. - * *string input pointer to place to store token - * *z charge on token - * *l length of token - * - * Returns: - * ERROR, - * OK. - */ -{ - int i, j; - int ltoken, lcharge; - char c; - char *ptr, *ptr1, *rest; - char charge[MAX_LENGTH]; - - rest=*eqnaddr; - ptr=*eqnaddr; - i=0; -/* - * Find end of token or begining of charge - */ - while ( ( (c=*ptr) != '+' ) && - (c != '-') && - (c != '=') && - (c != '\0') ) { - string[i++]=c; - if (c == '[') { - ptr++; - while ((c=*ptr) != ']') { - if (c == '\0') { - sprintf(error_string, "No final bracket \"]\" for element name, %s.", string); - error_msg(error_string, CONTINUE); - return(ERROR); - } - string[i++]=c; - if (i >= MAX_LENGTH ) { - output_msg(OUTPUT_MESSAGE, - "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", - MAX_LENGTH,string); - return(ERROR); - } - ptr++; - } - string[i++]=c; - } - - /* check for overflow of space */ - if (i >= MAX_LENGTH ) { - output_msg(OUTPUT_MESSAGE, - "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", - MAX_LENGTH,string); - return(ERROR); - } - ptr++; - } - string[i]='\0'; - ltoken=i; -/* - * Check for an empty string - */ - if(i == 0){ - sprintf(error_string, "NULL string detected in get_token, %s.",rest); - error_msg(error_string, CONTINUE); - return(ERROR); - } -/* - * End of token is = or \0, charge is zero - */ - if(c == '=' || c == '\0'){ - *eqnaddr=ptr; - lcharge=0; - *z=0.0; - } else { -/* - * Copy characters into charge until next species or end is detected - */ - j=0; - ptr1=ptr; - while( (isalpha((int) (c=*ptr1)) == FALSE) && - (c != '(') && - (c != ')') && - (c != ']') && - (c != '[') && - (c != '=') && - (c != '\0') ) { - charge[j++]=c; - /* error if no more space */ - if (j >= MAX_LENGTH ) { - error_msg("The charge on a species has exceeded MAX_LENGTH characters.", CONTINUE); - return(ERROR); - } - ptr1++; - } -/* - * Go back to last + or - if not end of side, - * everything before the last + or - in charge is part of the charge - */ - if( (c != '=') && (c != '\0') ) { - while( ((c=*ptr1) != '+') && (c != '-') ) { - j--; - ptr1--; - } - } - charge[j]='\0'; - lcharge=j; - *eqnaddr=ptr1; -/* - * Charge has been written, now need to check if charge has legal format - */ - if ( get_charge( charge, z) == OK ) { - strcat( string, charge); - } else { - return(ERROR); - } - } - *l=ltoken+lcharge; - return(OK); -} -/* ---------------------------------------------------------------------- */ -int isamong(char c, const char *s_l) -/* ---------------------------------------------------------------------- */ -/* - * Function checks if c is among the characters in the string s - * - * Arguments: - * c input, character to check - * *s string of characters - * - * Returns: - * TRUE if c is in set, - * FALSE if c in not in set. - */ -{ - int i; - - for (i=0; s_l[i] != '\0'; i++) { - if (c == s_l[i]) { - return(TRUE); - } - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -int islegit(const char c) -/* ---------------------------------------------------------------------- */ -/* - * Function checks for legal characters for chemical equations - * - * Argument: - * c input, character to check - * - * Returns: - * TRUE if c is in set, - * FALSE if c in not in set. - */ -{ - if( isalpha((int) c) || - isdigit((int) c) || - isamong(c,"+-=().:_[]") ){ - return(TRUE); - } - return(FALSE); -} -/* ---------------------------------------------------------------------- */ -void malloc_error (void) -/* ---------------------------------------------------------------------- */ -{ - error_msg("NULL pointer returned from malloc or realloc.", - CONTINUE); - error_msg("Program terminating.", STOP); - return; -} -/* ---------------------------------------------------------------------- */ -int parse_couple(char *token) -/* ---------------------------------------------------------------------- */ -{ -/* - * Parse couple puts redox couples in standard form - * "+" is removed and couples are rewritten in sort - * order. - */ - int e1, e2, p1, p2; - char *ptr; - char elt1[MAX_LENGTH], elt2[MAX_LENGTH], paren1[MAX_LENGTH], paren2[MAX_LENGTH]; - - if (strcmp_nocase_arg1(token,"pe") == 0) { - str_tolower(token); - return(OK); - } - while (replace("+","",token) == TRUE); - ptr=token; - get_elt( &ptr, elt1, &e1); - if (*ptr != '(') { - sprintf(error_string, "Element name must be followed by " - "parentheses in redox couple, %s.", token); - error_msg(error_string, CONTINUE); - parse_error++; - return(ERROR); - } - paren_count=1; - paren1[0]='('; - p1=1; - while ( ptr != '\0') { - ptr++; - if (*ptr == '/' || *ptr == '\0') { - sprintf(error_string, "End of line or ""/"" encountered before end of parentheses, %s.", token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - paren1[p1++]=*ptr; - if (*ptr == '(') paren_count++; - if (*ptr == ')') paren_count--; - if (paren_count == 0) break; - } - paren1[p1]='\0'; - ptr++; - if (*ptr != '/') { - sprintf(error_string, " ""/"" must follow parentheses " - "ending first half of redox couple, %s.", token); - error_msg(error_string, CONTINUE); - parse_error++; - return(ERROR); - } - ptr++; - get_elt( &ptr, elt2, &e2); - if (strcmp(elt1,elt2) != 0) { - sprintf(error_string, "Redox couple must be two redox states " - "of the same element, %s.", token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - if (*ptr != '(') { - sprintf(error_string, "Element name must be followed by " - "parentheses in redox couple, %s.", token); - error_msg(error_string, CONTINUE); - parse_error++; - return(ERROR); - } - paren2[0]='('; - paren_count=1; - p2=1; - while ( *ptr != '\0') { - ptr++; - if (*ptr == '/' || *ptr == '\0') { - sprintf(error_string, "End of line or ""/"" encountered" - " before end of parentheses, %s.", token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - - paren2[p2++]=*ptr; - if (*ptr == '(') paren_count++; - if (*ptr == ')') paren_count--; - if (paren_count == 0) break; - } - paren2[p2]='\0'; - if (strcmp(paren1,paren2) < 0) { - strcpy(token,elt1); - strcat(token,paren1); - strcat(token,"/"); - strcat(token,elt2); - strcat(token,paren2); - } else if (strcmp(paren1,paren2) > 0) { - strcpy(token,elt2); - strcat(token,paren2); - strcat(token,"/"); - strcat(token,elt1); - strcat(token,paren1); - } else { - sprintf(error_string, "Both parts of redox couple are the same, %s.",token); - error_msg(error_string, CONTINUE); - return(ERROR); - } - return(OK); -} -/* ---------------------------------------------------------------------- */ -int print_centered(const char *string) -/* ---------------------------------------------------------------------- */ -{ - int i, l, l1, l2; - char token[MAX_LENGTH]; - -#ifdef PHREEQ98 - if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) AddToCEntry((char*)string, 4, outputlinenr); -#endif - l = strlen(string); - l1 = (79 - l)/2; - l2 = 79 -l -l1; - for (i=0; i < l1; i++) token[i]='-'; - token[i]='\0'; - strcat(token, string); - for (i=0; i < l2; i++) token[i + l1 + l]='-'; - token[79] = '\0'; - output_msg(OUTPUT_MESSAGE,"%s\n\n",token); - return(OK); -} -/* ---------------------------------------------------------------------- */ -int replace(const char *str1, const char *str2, char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function replaces str1 with str2 in str - * - * Arguments: - * str1 search str for str1 - * str2 replace str1 if str1 found in str - * str string to be searched - * - * Returns - * TRUE if string was replaced - * FALSE if string was not replaced - */ - int l, l1, l2; - char *ptr_start; - - ptr_start=strstr(str, str1); -/* - * Str1 not found, return - */ - if (ptr_start == NULL) return(FALSE); -/* - * Str1 found, replace Str1 with Str2 - */ - l=strlen(str); - l1=strlen(str1); - l2=strlen(str2); -/* - * Make gap in str long enough for str2 - */ -#ifdef SKIP - if (l2 < l1) { - for (ptr = (ptr_start + l1); ptr < ptr_start + l; ptr++) { - ptr1= ptr + l2 - l1; - *ptr1=*ptr; - if (*ptr == '\0') break; - } - } else { - for ( ptr = (str+l); ptr >= ptr_start + l1; ptr--) { - ptr1=ptr+l2-l1; - *ptr1=*ptr; - } - } -#endif - /* The plus one includes the terminating NULL */ - memmove(ptr_start + l2, ptr_start + l1, l - (ptr_start - str + l1) + 1); -/* - * Copy str2 into str - */ -#ifdef SKIP - ptr1=ptr_start; - for (ptr = (char *) str2; *ptr != '\0'; ptr++) { - *ptr1=*ptr; - ptr1++; - } -#endif - memcpy(ptr_start, str2, l2); - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -void space (void **ptr, int i, int *max, int struct_size) -/* ---------------------------------------------------------------------- */ -{ -/* - * Routine has 4 functions, allocate space, reallocate space, test to - * determine whether space is available, and free space. - * - * Arguments: - * ptr pointer to malloced space - * i value for test - * i = INIT, allocates space - * i >= 0 && i < max, space is available, return - * i >= max, reallocate space - * i = FREE, free space. - * max maximum value for i with available space - * struct size size of structure to be allocated - */ -/* - * Return if space exists - */ - if ( ( i >= 0 ) && ( i + 1 < *max ) ) { - return; - } -/* - * Realloc space - */ - if ( i+1 >= *max ) { - if (*max > 1000) { - *max += 1000; - } else { - *max *= 2; - } - if (i+1 > *max) *max = i + 1; - *ptr = PHRQ_realloc( *ptr, (size_t) (*max)*struct_size ); - if (*ptr == NULL ) malloc_error(); - return; - } -/* - * Allocate space - */ - if ( i == INIT ) { -/* free(*ptr); */ - *ptr=PHRQ_malloc((size_t) (*max)*struct_size); - if (*ptr == NULL ) malloc_error(); - return; - } -/* - * Free space - */ -/* - if ( i == FREE ) { - free(*ptr); - return; - } - */ -/* - * Error - */ - error_msg("Illegal argument to function space.", CONTINUE); - error_msg("Program terminating.", STOP); - return; -} -/* ---------------------------------------------------------------------- */ -void squeeze_white(char *s_l) -/* ---------------------------------------------------------------------- */ -/* - * Delete all white space from string s - * - * Argument: - * *s_l input, character string, possibly containing white space - * output, character string with all white space removed - * - * Return: void - */ -{ - int i, j; - - for (i = j = 0; s_l[i] != '\0'; i++){ - if (! isspace((int) s_l[i])) s_l[j++]=s_l[i]; - } - s_l[j]='\0'; -} -/* ---------------------------------------------------------------------- */ -void str_tolower(char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Replaces string, str, with same string, lower case - */ - char *ptr; - ptr=str; - while (*ptr != '\0') { - *ptr= (char) tolower(*ptr); - ptr++; - } -} -/* ---------------------------------------------------------------------- */ -void str_toupper(char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Replaces string, str, with same string, lower case - */ - char *ptr; - ptr=str; - while (*ptr != '\0') { - *ptr= (char) toupper(*ptr); - ptr++; - } -} -/* ---------------------------------------------------------------------- */ -int strcmp_nocase(const char *str1, const char *str2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare two strings disregarding case - */ - int c1, c2; - while ((c1 = tolower(*str1++)) == (c2 = tolower(*str2++))) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); -} -/* ---------------------------------------------------------------------- */ -int strcmp_nocase_arg1(const char *str1, const char *str2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare two strings disregarding case - */ - int c1, c2; - while ((c1 = tolower(*str1++)) == (c2 = *str2++)) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); -} -/* ---------------------------------------------------------------------- */ -char * string_duplicate (const char *token) -/* ---------------------------------------------------------------------- */ -{ - int l; - char *str; - - if (token == NULL) return NULL; - l = strlen(token); - str = (char *) PHRQ_malloc((size_t) (l +1) * sizeof(char) ); - if (str == NULL) malloc_error(); - strcpy (str, token); - return(str); -} -/* ---------------------------------------------------------------------- */ -char *string_hsave (const char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save character string str - * - * Arguments: - * str input string to save. - * l input, length of str - * - * Returns: - * starting address of saved string (str) - */ - char *new_string; - ENTRY item, *found_item; - - new_string = string_duplicate(str); - item.key = new_string; - item.data = new_string; - found_item = hsearch_multi(strings_hash_table, item, ENTER); - if (found_item->key == new_string) { - count_strings++; - return(new_string); - } - new_string = (char*) free_check_null(new_string); - return(found_item->key); -} -/* ---------------------------------------------------------------------- */ -LDBLE under (LDBLE xval) -/* ---------------------------------------------------------------------- */ -{ -/* - * Exponentiate a number, x, but censor large and small numbers - * log values less than MIN_LM are set to 0 - * log values greater than MAX_LM are set to 10**MAX_LM - */ -/* if (xval < MIN_LM) { */ - if (xval < -40.) { - return(0.0); - } -/* if (xval > MAX_LM) { */ - if (xval > 3.) { - return ( 1.0e3 ); -/* return ( pow (10.0, MAX_LM));*/ - } -/* return (pow (10.0, xval)); */ - return (exp (xval * LOG_10)); -} -/* ---------------------------------------------------------------------- */ -int backspace_screen (int spaces) -/* ---------------------------------------------------------------------- */ -{ - int i; - char token[MAX_LENGTH]; - for (i = 0; i < spaces; i++) { - token[i] = '\b'; - } - token[i] = '\0'; - output_msg(OUTPUT_SCREEN,"%s",token); - return(OK); -} -#ifndef PHREEQCI_GUI -/* ---------------------------------------------------------------------- */ -int status (int count, const char *str) -/* ---------------------------------------------------------------------- */ -{ - static int spinner; - char sim_str[20]; - char state_str[45]; - char spin_str[2]; -/* char all[MAX_LENGTH]; */ -#ifdef PHREEQ98 - if (ProcessMessages) ApplicationProcessMessages(); - if (stop_calculations == TRUE) error_msg("Execution canceled by user.", STOP); -#endif - - if (pr.status == FALSE || phast == TRUE) return(OK); - sprintf(sim_str,"Simulation %d.", simulation); - sprintf(state_str," "); - sprintf(spin_str," "); - - if (state == INITIALIZE) { - output_msg(OUTPUT_SCREEN,"\n%-80s","Initializing..."); - - status_on = TRUE; - return(OK); - } -/* - * If str is defined print it - */ - if (str != NULL) { - if (status_on == TRUE) { - backspace_screen(80); - } else { - status_on = TRUE; - } -#ifdef DOS - backspace_screen(80); - /* if (state == TRANSPORT ) backspace_screen(80); */ - output_msg(OUTPUT_SCREEN, "%-79s", str); -#else - output_msg(OUTPUT_SCREEN, "%-80s", str); -#endif - } else if (state != TRANSPORT && state != PHAST ) { - if (state == INITIAL_SOLUTION) { - sprintf(state_str, "Initial solution %d.", use.solution_ptr->n_user); - } else if (state == INITIAL_EXCHANGE) { - sprintf(state_str, "Initial exchange %d.", use.exchange_ptr->n_user); - } else if (state == INITIAL_SURFACE) { - sprintf(state_str, "Initial surface %d.", use.surface_ptr->n_user); - } else if (state == INVERSE) { - sprintf(state_str, "Inverse %d. Models = %d.", - use.inverse_ptr->n_user, count); - } else if (state == REACTION) { - if (use.kinetics_in == TRUE) { - sprintf(state_str, "Kinetic step %d.", reaction_step); - } else { - sprintf(state_str, "Reaction step %d.", reaction_step); - } - } else if (state == ADVECTION || state == TRANSPORT) { - if (state == ADVECTION) { - sprintf(state_str, "Advection, shift %d.", advection_step); - } else if (state == TRANSPORT) { - sprintf(state_str, "Transport, shift %d.", transport_step); - } - spinner++; - if (spinner == 1) { - spin_str[0] = '/'; - } else if (spinner == 2) { - spin_str[0] = '-'; - } else { - spin_str[0] = '\\'; - spinner = 0; - } - } - if (status_on == TRUE) { - backspace_screen(80); - } else { - status_on = TRUE; - } - if (use.kinetics_in == TRUE) { -#ifdef DOS - backspace_screen(80); - output_msg(OUTPUT_SCREEN, "%-15s%-27s%37s", sim_str, state_str, " "); -#else - output_msg(OUTPUT_SCREEN, "%-15s%-27s%38s", sim_str, state_str, " "); -#endif - - } else { -#ifdef DOS - backspace_screen(80); - output_msg(OUTPUT_SCREEN, "%-15s%-27s%1s%36s", sim_str, state_str, spin_str, " "); -#else - output_msg(OUTPUT_SCREEN, "%-15s%-27s%1s%37s", sim_str, state_str, spin_str, " "); -#endif - } - } - return(OK); -} -#endif /*PHREEQCI_GUI*/ -/* -** Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson. -** Coded into C, with minor code improvements, and with hsearch(3) interface, -** by ejp@ausmelb.oz, Jul 26, 1988: 13:16; -** also, hcreate/hdestroy routines added to simulate hsearch(3). -** -** These routines simulate hsearch(3) and family, with the important -** difference that the hash table is dynamic - can grow indefinitely -** beyond its original size (as supplied to hcreate()). -** -** Performance appears to be comparable to that of hsearch(3). -** The 'source-code' options referred to in hsearch(3)'s 'man' page -** are not implemented; otherwise functionality is identical. -** -** Compilation controls: -** DEBUG controls some informative traces, mainly for debugging. -** HASH_STATISTICS causes HashAccesses and HashCollisions to be maintained; -** when combined with DEBUG, these are displayed by hdestroy(). -** -** Problems & fixes to ejp@ausmelb.oz. WARNING: relies on pre-processor -** concatenation property, in probably unnecessary code 'optimisation'. -** Esmond Pitt, Austec (Asia/Pacific) Ltd -** ...!uunet.UU.NET!munnari!ausmelb!ejp,ejp@ausmelb.oz -*/ - -# include - -/* -** Fast arithmetic, relying on powers of 2, -** and on pre-processor concatenation property -*/ - -/* rewrote to remove MUL and DIV */ -#ifdef SKIP -# define MUL(x,y) ((x) << (y/**/Shift)) -# define DIV(x,y) ((x) >> (y/**/Shift)) -#endif -# define MOD(x,y) ((x) & ((y)-1)) - -/* -** local data templates -*/ - - -/* -** external routines -*/ - -/* -extern char *calloc(); -extern int free(); - */ -/* -** Entry points -*/ - - -/* -** Internal routines -*/ - -static Address Hash_multi(HashTable *Table, char *Key); -static void ExpandTable_multi(HashTable *Table); - -/* -** Local data -*/ - -#ifdef HASH_STATISTICS -static long HashAccesses, HashCollisions; -#endif - -/* -** Code -*/ - -int hcreate_multi(unsigned Count, HashTable **HashTable_ptr) -{ - int i; - HashTable *Table; - /* - ** Adjust Count to be nearest higher power of 2, - ** minimum SegmentSize, then convert into segments. - */ - i = SegmentSize; - while (i < (int) Count) - i <<= 1; -/* Count = DIV(i,SegmentSize); */ - Count = ((i) >> (SegmentSizeShift)); - - Table = (HashTable*) PHRQ_calloc(sizeof(HashTable),1); - *HashTable_ptr = Table; - - if (Table == NULL) - return(0); - /* - ** resets are redundant - done by calloc(3) - ** - Table->SegmentCount = Table->p = Table->KeyCount = 0; - */ - /* - ** Allocate initial 'i' segments of buckets - */ - for (i = 0; i < (int) Count; i++) - { - Table->Directory[i] = (Segment*)PHRQ_calloc(sizeof(Segment),SegmentSize); - if (Table->Directory[i] == NULL) - { - hdestroy_multi(Table); - return(0); - } - Table->SegmentCount++; - } -/* Table->maxp = MUL(Count,SegmentSize); */ - Table->maxp = (short) ((Count) << (SegmentSizeShift)); - Table->MinLoadFactor = 1; - Table->MaxLoadFactor = DefaultMaxLoadFactor; -#ifdef DEBUG - output_msg(OUTPUT_STDERR, - "[hcreate] Table %x Count %d maxp %d SegmentCount %d\n", - Table, - Count, - Table->maxp, - Table->SegmentCount - ); -#endif -#ifdef HASH_STATISTICS - HashAccesses = HashCollisions = 0; -#endif - return(1); -} - -void hdestroy_multi(HashTable *Table) -{ - int i,j; - Segment *seg; - Element *p,*q; - - if (Table != NULL) - { - for (i = 0; i < Table->SegmentCount; i++) - { - /* test probably unnecessary */ - if ((seg = Table->Directory[i]) != NULL) { - for (j = 0; j < SegmentSize; j++) { - p = seg[j]; - while (p != NULL) { - q = p->Next; - free((void*)p); - p = q; - } - } - free(Table->Directory[i]); - } - } - free(Table); - /* Table = NULL; */ -#if defined(HASH_STATISTICS) && defined(DEBUG) - output_msg(OUTPUT_STDERR, - "[hdestroy] Accesses %ld Collisions %ld\n", - HashAccesses, - HashCollisions - ); -#endif - } -} - -ENTRY * hsearch_multi(HashTable *Table, ENTRY item, ACTION action) -/* ACTION FIND/ENTER */ -{ - Address h; - Segment *CurrentSegment; - int SegmentIndex; - int SegmentDir; - Segment *p,q; - - assert(Table != NULL); /* Kinder really than return(NULL); */ -#ifdef HASH_STATISTICS - HashAccesses++; -#endif - h = Hash_multi(Table, item.key); -/* SegmentDir = DIV(h,SegmentSize); */ - SegmentDir = ((h) >> (SegmentSizeShift)); - SegmentIndex = MOD(h,SegmentSize); - /* - ** valid segment ensured by Hash() - */ - CurrentSegment = Table->Directory[SegmentDir]; - assert(CurrentSegment != NULL); /* bad failure if tripped */ - p = &CurrentSegment[SegmentIndex]; - q = *p; - /* - ** Follow collision chain - */ - while (q != NULL && strcmp(q->Key,item.key)) - { - p = &q->Next; - q = *p; -#ifdef HASH_STATISTICS - HashCollisions++; -#endif - } - if ( - q != NULL /* found */ - || - action == FIND /* not found, search only */ - || - (q = (Element*)PHRQ_calloc(sizeof(Element),1)) - == - NULL /* not found, no room */ - ) - return((ENTRY*)q); - *p = q; /* link into chain */ - /* - ** Initialize new element - */ - q->Key = item.key; - q->Data =(char*) item.data; - /* - ** cleared by calloc(3) - q->Next = NULL; - */ - /* - ** Table over-full? - */ -/* if (++Table->KeyCount / MUL(Table->SegmentCount,SegmentSize) > Table->MaxLoadFactor) */ - if (++Table->KeyCount / ((Table->SegmentCount) << (SegmentSizeShift)) > Table->MaxLoadFactor) - ExpandTable_multi(Table); /* doesn't affect q */ - return((ENTRY*)q); -} - -/* -** Internal routines -*/ - -static Address Hash_multi(HashTable *Table, char *Key) -{ - Address h,address; - register unsigned char *k = (unsigned char*)Key; - - h = 0; - /* - ** Convert string to integer - */ - while (*k) - h = h*Prime1 ^ (*k++ - ' '); - h %= Prime2; - address = MOD(h,Table->maxp); - if (address < (unsigned long) Table->p) - address = MOD(h,(Table->maxp << 1)); /* h % (2*Table->maxp) */ - return(address); -} - -void ExpandTable_multi(HashTable *Table) -{ - Address NewAddress; - int OldSegmentIndex,NewSegmentIndex; - int OldSegmentDir,NewSegmentDir; - Segment *OldSegment,*NewSegment; - Element *Current,**Previous,**LastOfNew; - -/* if (Table->maxp + Table->p < MUL(DirectorySize,SegmentSize)) */ - if (Table->maxp + Table->p < ((DirectorySize) << (SegmentSizeShift))) - { - /* - ** Locate the bucket to be split - */ -/* OldSegmentDir = DIV(Table->p,SegmentSize); */ - OldSegmentDir = ((Table->p) >> (SegmentSizeShift)); - OldSegment = Table->Directory[OldSegmentDir]; - OldSegmentIndex = MOD(Table->p,SegmentSize); - /* - ** Expand address space; if necessary create a new segment - */ - NewAddress = Table->maxp + Table->p; -/* NewSegmentDir = DIV(NewAddress,SegmentSize); */ - NewSegmentDir = ((NewAddress) >> (SegmentSizeShift)); - NewSegmentIndex = MOD(NewAddress,SegmentSize); - if (NewSegmentIndex == 0) - Table->Directory[NewSegmentDir] = (Segment*)PHRQ_calloc(sizeof(Segment),SegmentSize); - NewSegment = Table->Directory[NewSegmentDir]; - /* - ** Adjust state variables - */ - Table->p++; - if (Table->p == Table->maxp) - { - Table->maxp <<= 1; /* Table->maxp *= 2 */ - Table->p = 0; - } - Table->SegmentCount++; - /* - ** Relocate records to the new bucket - */ - Previous = &OldSegment[OldSegmentIndex]; - Current = *Previous; - LastOfNew = &NewSegment[NewSegmentIndex]; - *LastOfNew = NULL; - while (Current != NULL) - { - if (Hash_multi(Table, Current->Key) == NewAddress) - { - /* - ** Attach it to the end of the new chain - */ - *LastOfNew = Current; - /* - ** Remove it from old chain - */ - *Previous = Current->Next; - LastOfNew = &Current->Next; - Current = Current->Next; - *LastOfNew = NULL; - } - else - { - /* - ** leave it on the old chain - */ - Previous = &Current->Next; - Current = Current->Next; - } - } - } -} - - -void free_hash_strings(HashTable *Table) -{ - int i,j; - Segment *seg; - Element *p,*q; - - if (Table != NULL) - { - for (i = 0; i < Table->SegmentCount; i++) - { - /* test probably unnecessary */ - if ((seg = Table->Directory[i]) != NULL) { - for (j = 0; j < SegmentSize; j++) { - p = seg[j]; - while (p != NULL) { - q = p->Next; - p->Data = (char*) free_check_null((void*)p->Data); - p = q; - } - } - } - } -#if defined(HASH_STATISTICS) && defined(DEBUG) - output_msg(OUTPUT_STDERR, - "[hdestroy] Accesses %ld Collisions %ld\n", - HashAccesses, - HashCollisions - ); -#endif - } -} -/* ---------------------------------------------------------------------- */ -int string_trim (char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function trims white space from left and right of string - * - * Arguments: - * str string to trime - * - * Returns - * TRUE if string was changed - * FALSE if string was not changed - * EMPTY if string is all whitespace - */ - int i, l, start, end, length; - char *ptr_start; - - l=strlen(str); - /* - * leading whitespace - */ - for (i = 0; i < l; i++) { - if (isspace((int) str[i])) continue; - break; - } - if (i == l) return(EMPTY); - start = i; - ptr_start = &(str[i]); - /* - * trailing whitespace - */ - for (i = l-1; i >= 0; i--) { - if (isspace((int) str[i])) continue; - break; - } - end = i; - if (start == 0 && end == l) return(FALSE); - length = end - start + 1; - memmove((void *) str, (void *) ptr_start, (size_t) length); - str[length] = '\0'; - - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int string_trim_right (char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function trims white space from right of string - * - * Arguments: - * str string to trime - * - * Returns - * TRUE if string was changed - * FALSE if string was not changed - * EMPTY if string is all whitespace - */ - int i, l, end, length; - - l=strlen(str); - for (i = l-1; i >= 0; i--) { - if (isspace((int) str[i])) continue; - break; - } - end = i; - length = end + 1; - str[length] = '\0'; - if (end == 0) return(EMPTY); - if (end == l) return(FALSE); - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -int string_trim_left (char *str) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function trims white space from left of string - * - * Arguments: - * str string to trime - * - * Returns - * TRUE if string was changed - * FALSE if string was not changed - * EMPTY if string is all whitespace - */ - int i, l, start, end, length; - char *ptr_start; - - l=strlen(str); - /* - * leading whitespace - */ - for (i = 0; i < l; i++) { - if (isspace((int) str[i])) continue; - break; - } - if (i == l) return(EMPTY); - start = i; - ptr_start = &(str[i]); - end = l; - if (start == 0 && end == l) return(FALSE); - length = end - start + 1; - memmove((void *) str, (void *) ptr_start, (size_t) length); - str[length] = '\0'; - - return(TRUE); -} -/* ---------------------------------------------------------------------- */ -char *string_pad (char *str, int i) -/* ---------------------------------------------------------------------- */ -{ -/* - * Function returns new string padded to width i - * or returns str if longer - * Arguments: - * str string to pad - * - * Returns - * new string of with i - */ - int j, l, max; - char *str_ptr; - - l=strlen(str); - max = l; - if (l < i) max = i; - str_ptr = (char *) PHRQ_malloc((size_t) ((max+1) * sizeof(char))); - if (str_ptr == NULL) malloc_error(); - strcpy(str_ptr, str); - if (i > l) { - for (j = l; j < i; j++) { - str_ptr[j] = ' '; - } - str_ptr[i] = '\0'; - } - return(str_ptr); -} From 3da5643ae7671b7fe51f07fe72ed5441decc7db8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 17:35:35 +0000 Subject: [PATCH 0003/1077] Makefile is working. Will make pc version and then can move on. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@789 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Isotope.h | 2 +- Makefile | 702 ++++++++++++++++++++++++++---------------------- NameDouble.h | 2 +- Parser.h | 2 +- Solution.h | 4 +- Temperature.cxx | 261 ++++++++++++++++++ Temperature.h | 41 +++ cpp.dsw | 29 -- distribution.mk | 368 ------------------------- 9 files changed, 688 insertions(+), 723 deletions(-) create mode 100644 Temperature.cxx create mode 100644 Temperature.h delete mode 100644 cpp.dsw delete mode 100644 distribution.mk diff --git a/Isotope.h b/Isotope.h index 0da740a8..372e5523 100644 --- a/Isotope.h +++ b/Isotope.h @@ -24,7 +24,7 @@ public: void dump_xml(std::ostream& os, unsigned int indent)const; void dump_raw(std::ostream& os, unsigned int indent)const; - CParser::STATUS_TYPE cxxIsotope::read_raw(CParser& parser); + CParser::STATUS_TYPE read_raw(CParser& parser); char * get_isotope_name()const { return this->isotope_name;} void set_isotope_name(char * cstring) { this->isotope_name = cstring;} diff --git a/Makefile b/Makefile index 293b837f..77ee8743 100644 --- a/Makefile +++ b/Makefile @@ -1,348 +1,408 @@ -# -# Make file for PHREEQC +# Makefile for PHREEQCPP +# +# Generates object files and executables for 2 versions of PHREEQCPP +# Release +# Debug +# +# Serial verisons: Release Debug +# +# Makefile sets CFG variable, cd's to appropriate directory, runs Makefile recursively +# Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC # -# $(CURDIR) is current directory -TOPDIR:=$(CURDIR)/.. -PROGRAM=phreeqcsax -EXE=$(TOPDIR)/bin/$(PROGRAM) -EXE=$(PROGRAM) -SRC:=$(CURDIR) -# Do not print commands before executing -#.SILENT: +PROGRAM = phreeqcpp -# Provides compatibility with GNU make -#.SUFFIXES: +all: release debug -# Change to pawd if using automounter -PWD=pwd +RELEASE_DIR = Release +DEBUG_DIR = Debug +MAKEFILE = Makefile -# Change to C compiler on your system -CC=gcc +######################### +#### Serial Versions #### +######################### +.PHONY : Release +release: + mkdir -p $(RELEASE_DIR) + cd $(RELEASE_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE $(PROGRAM) -USE_XML=TRUE -XERCESCROOT=/z/parkplace/home/dlpark/packages/xerces-c-src_2_7_0 +.PHONY : Debug +debug: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG $(PROGRAM) -# Change to C compiler options on your system -ifdef OPTIMIZE - CCFLAGS=-O3 -Wall -ansi -pedantic -I${XERCESCROOT}/include # -frounding-math # -pg - CCFLAGS_MODEL=-O2 -Wall -ansi -pedantic # -pg -else - CCFLAGS=-g -Wall -ansi -pedantic -I${XERCESCROOT}/include # -frounding-math # -pg - CCFLAGS_MODEL=-g -Wall -ansi -pedantic # -pg -endif -# Remove the following definition if you do not have -# gmp (Gnu Multiple Precision) package on your system -INVERSE_CL1MP=TRUE +# Recursive make begins here +# +# ============================================================================= +# Significant suffixes [assuming Fortran 90 (.f90) source code]: +# Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: +# ============================================================================= -LOADFLAGS= -lm -lxerces-c # -pg +#SRC = ../phreeqc +.SUFFIXES : .o .c .cxx -PLATFORM= LINUX -CXX= g++ -c -D${PLATFORM} -D_REENTRANT -fpic -ifdef OPTIMIZE - CXXFLAGS= -O3 -else - CXXFLAGS= -Wall -g -endif -LINK= g++ -D${PLATFORM} -fpic -PLATFORM_LIB_LINK_OPTIONS=-L/usr/lib -L/usr/local/lib -EXTRA_LINK_OPTIONS=-lc -LIBRARY_NAMES= -lxerces-c -LIBRARY_SEARCH_PATHS= -L${XERCESCROOT}/lib # -L/home/dlpark/lib # -INCLUDES= -I${XERCESCROOT}/include +# compilers -#.c.o : -# ${CC} ${CCFLAGS} -c -o $@ $< -#%.o : $(SRC)/%.c -# ${CC} ${CCFLAGS} -c -o $@ $< -%.o : $(SRC)/%.cpp - ${CXX} ${CXXFLAGS} $(INCLUDES) -c -o $@ $< -%.o : $(SRC)/%.cxx - ${CXX} ${CXXFLAGS} $(INCLUDES) -c -o $@ $< +# ----------------------------------------------------------------------------- +.c.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< -# Location to copy scripts on installation -BINDIR=$(HOME)/bin +.cxx.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< -OBJECTS= main.o \ - advection.o \ - basic.o \ - basicsubs.o \ - cl1.o \ - input.o \ - integrate.o \ - inverse.o \ - isotopes.o \ - kinetics.o \ - mainsubs.o \ - output.o \ - model.o \ - p2clib.o \ - parse.o \ - phreeqc_files.o \ - phqalloc.o \ - prep.o \ - print.o \ - read.o \ - readtr.o \ - spread.o \ - step.o \ - structures.o \ - tally.o \ - tidy.o \ - transport.o \ - utilities.o \ - cvdense.o \ - cvode.o \ - dense.o \ - nvector.o \ - nvector_serial.o \ - smalldense.o \ - sundialsmath.o \ - dw.o \ - pitzer.o \ - pitzer_structures.o \ +# ----------------------------------------------------------------------------- +#hdf options +#HDF5_ROOT=$(HOME)/../../usr +#HDF5_INCLUDES=-I$(HDF5_ROOT)/src +#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread -CLASS_OBJECTS= Conc.o \ - Exchange.o \ - ExchComp.o \ - GasPhase.o \ - ISolution.o \ - Isotope.o \ - KineticsCxx.o \ - KineticsComp.o \ - Mix.o \ - NameDouble.o \ - NumKeyword.o \ - Parser.o \ - PPassemblage.o \ - PPassemblageComp.o \ - Reaction.o \ - ReadClass.o \ - Solution.o \ - SSassemblage.o \ - SSassemblageSS.o \ - Surface.o \ - SurfComp.o \ - SurfCharge.o \ - Temperature.o \ - Utils.o +# ----------------------------------------------------------------------------- +# #define compile options -OBJECTS += $(CLASS_OBJECTS) +# ----------------------------------------------------------------------------- +# #define gmp for inverse modeling +# comment the following lines to remove multiprecision option +DINVERSE_CL1MP=TRUE +CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a +CL1MP_OBJS=cl1mp.o -ifdef USE_XML - OBJECTS += SAXPhreeqc.o +# ----------------------------------------------------------------------------- +#efence for debugging +EFENCE_LIB=-L$(HOME)/packages/efence + +# ----------------------------------------------------------------------------- +# 2 Versions +# ----------------------------------------------------------------------------- +ifeq ($(CFG), RELEASE) + DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + CFLAGS_MODEL = -Wall -pedantic -O2 $(DEFINES) + OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} endif -ifdef INVERSE_CL1MP - LOADFLAGS += /z/parkplace/usr/lib/libgmp.a - CCFLAGS += -DINVERSE_CL1MP - CXXFLAGS += -DINVERSE_CL1MP - OBJECTS += cl1mp.o +ifeq ($(CFG), DEBUG) + DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + CFLAGS_MODEL = -Wall -g $(DEFINES) + OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} endif -all: $(EXE) +# ----------------------------------------------------------------------------- +# -install: +COMMON_COBJS = \ + advection.o \ + basic.o \ + basicsubs.o \ + cl1.o \ + cvdense.o \ + cvode.o \ + dense.o \ + dw.o \ + input.o \ + integrate.o \ + inverse.o \ + isotopes.o \ + kinetics.o \ + main.o \ + mainsubs.o \ + model.o \ + nvector.o \ + nvector_serial.o \ + output.o \ + p2clib.o \ + parse.o \ + phqalloc.o \ + phreeqc_files.o \ + pitzer.o \ + pitzer_structures.o \ + prep.o \ + print.o \ + read.o \ + readtr.o \ + smalldense.o \ + spread.o \ + step.o \ + structures.o \ + sundialsmath.o \ + tally.o \ + tidy.o \ + transport.o \ + utilities.o + +COMMON_CXXOBJS = \ + Conc.o \ + Exchange.o \ + ExchComp.o \ + GasPhase.o \ + ISolution.o \ + Isotope.o \ + KineticsComp.o \ + KineticsCxx.o \ + Mix.o \ + NameDouble.o \ + NumKeyword.o \ + Parser.o \ + PPassemblageComp.o \ + PPassemblage.o \ + Reaction.o \ + ReadClass.o \ + Solution.o \ + SSassemblage.o \ + SSassemblageSS.o \ + Surface.o \ + SurfCharge.o \ + SurfComp.o \ + Temperature.o \ + Utils.o + +# ----------------------------------------------------------------------------- +# Assign dependents to target on dependency line & link options on command +# line. Command line is initiated with a tab. ($@ is an internal macro for +# the current target.) + +${PROGRAM} : ${OBJECT_FILES} + ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} + @echo; echo Done making for phast +# ----------------------------------------------------------------------------- +# Module dependency list +# ----------------------------------------------------------------------------- # -# Create directory for binary and scripts if necessary +# CXX files # - if [ ! -d $(BINDIR) ]; \ - then \ - mkdir $(BINDIR); \ - echo Created directory $(BINDIR); \ - fi +Conc.o: ../Conc.cxx ../Conc.h ../Utils.h ../char_star.h ../ISolution.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../Solution.h \ + ../NumKeyword.h ../Isotope.h ../Parser.h ../Conc.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../Conc.h ../Utils.h ../phreeqc/phrqproto.h \ + ../phqalloc.h +Exchange.o: ../Exchange.cxx ../Utils.h ../Exchange.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h ../Parser.h \ + ../char_star.h ../ExchComp.h ../phqalloc.h ../phreeqc/phrqproto.h +ExchComp.o: ../ExchComp.cxx ../Utils.h ../ExchComp.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h +GasPhase.o: ../GasPhase.cxx ../Utils.h ../GasPhase.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +Isotope.o: ../Isotope.cxx ../Isotope.h ../Parser.h ../char_star.h \ + ../Utils.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../KineticsComp.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../char_star.h ../phqalloc.h \ + ../phreeqc/phrqproto.h +KineticsCxx.o: ../KineticsCxx.cxx ../Utils.h ../KineticsCxx.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../char_star.h ../KineticsComp.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +Mix.o: ../Mix.cxx ../Utils.h ../Mix.h ../NumKeyword.h ../Parser.h \ + ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../Conc.h ../Utils.h \ + ../char_star.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ + ../char_star.h +Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ + ../char_star.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ + ../PPassemblageComp.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../PPassemblage.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../PPassemblageComp.h \ + ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ + ../PPassemblageComp.h ../phqalloc.h ../phreeqc/phrqproto.h +Reaction.o: ../Reaction.cxx ../Utils.h ../Reaction.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../phqalloc.h ../phreeqc/phrqproto.h +ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ + ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../Conc.h \ + ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../Exchange.h ../NumKeyword.h ../char_star.h ../ExchComp.h \ + ../NameDouble.h ../char_star.h ../Surface.h ../NumKeyword.h \ + ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h \ + ../SurfCharge.h ../NameDouble.h ../char_star.h ../PPassemblage.h \ + ../NumKeyword.h ../char_star.h ../PPassemblageComp.h ../NameDouble.h \ + ../char_star.h ../KineticsCxx.h ../NumKeyword.h ../char_star.h \ + ../KineticsComp.h ../NameDouble.h ../char_star.h ../SSassemblage.h \ + ../NumKeyword.h ../char_star.h ../SSassemblageSS.h ../NameDouble.h \ + ../char_star.h ../GasPhase.h ../NumKeyword.h ../NameDouble.h \ + ../char_star.h ../Reaction.h ../NumKeyword.h ../NameDouble.h \ + ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h ../Temperature.h \ + ../NumKeyword.h ../char_star.h ../phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../Conc.h \ + ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h ../NumKeyword.h \ + ../Solution.h ../Conc.h ../Exchange.h ../NumKeyword.h ../char_star.h \ + ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ + ../NumKeyword.h ../char_star.h ../SurfComp.h ../NameDouble.h \ + ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ + ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ + ../NameDouble.h ../char_star.h ../KineticsCxx.h ../NumKeyword.h \ + ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ + ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ + ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h \ + ../Temperature.h ../NumKeyword.h ../char_star.h +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ + ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ + ../SSassemblageSS.h ../phqalloc.h ../phreeqc/phrqproto.h +SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../SSassemblageSS.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ + ../NameDouble.h ../phqalloc.h ../phreeqc/phrqproto.h +Surface.o: ../Surface.cxx ../Utils.h ../Surface.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h ../Parser.h \ + ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ + ../SurfComp.h ../phqalloc.h ../phreeqc/phrqproto.h +SurfCharge.o: ../SurfCharge.cxx ../Utils.h ../SurfCharge.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ + ../phreeqc/output.h ../phqalloc.h ../phreeqc/phrqproto.h +SurfComp.o: ../SurfComp.cxx ../Utils.h ../SurfComp.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h +Temperature.o: ../Temperature.cxx ../Utils.h ../Temperature.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../phqalloc.h \ + ../phreeqc/phrqproto.h +Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../char_star.h \ + ../phreeqc/output.h # -# Put path name of current directory into script for -# locating data files, put script in top directory, -# put symbolic link in BINDIR +# PHREEQC files # - cd $(TOPDIR); dir1=`$(PWD)`/bin; cd $(BINDIR); if [ `$(PWD)` = $$dir1 ]; \ - then \ - echo "Can not install to $(BINDIR). Choose another directory."; \ - exit 4 ; \ - fi - cd $(TOPDIR); \ - rm -f $(BINDIR)/$(PROGRAM); \ - rm -f $(PROGRAM); \ - sed "s?TOPDIR=.\{0,80\}?TOPDIR=`$(PWD)`?" bin/$(PROGRAM).orig > $(PROGRAM); \ - chmod 755 $(PROGRAM) - cd $(TOPDIR); dir1=`$(PWD)`; cd $(BINDIR); if [ `$(PWD)` != $$dir1 ]; then \ - ln -s $$dir1/$(PROGRAM) $(BINDIR); \ - echo Symbolic link for $(PROGRAM) has been placed in $(BINDIR). ; \ - fi -# -# Check that all necessary files are in place. -# - if [ -f $(BINDIR)/$(PROGRAM) -a \ - -f $(TOPDIR)/bin/$(PROGRAM) -a \ - -f $(TOPDIR)/$(PROGRAM) ]; \ - then echo "Installation complete."; \ - else echo "Installation incomplete."; \ - for FILE in $(BINDIR)/$(PROGRAM) \ - $(TOPDIR)/bin/$(PROGRAM) $(TOPDIR)/$(PROGRAM) ; \ - do \ - if [ ! -f $$FILE ]; then echo $$FILE is missing.; fi; \ - done; \ - fi - echo "Add directory $(BINDIR) to PATH." +advection.o: ../phreeqc/advection.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +basic.o: ../phreeqc/basic.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/p2c.h +basicsubs.o: ../phreeqc/basicsubs.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +cl1.o: ../phreeqc/cl1.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqtype.h +cl1mp.o: ../phreeqc/cl1mp.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqtype.h +cvdense.o: ../phreeqc/cvdense.c ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ + ../phreeqc/output.h ../phreeqc/phqalloc.h +cvode.o: ../phreeqc/cvode.c ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/sundialsmath.h \ + ../phreeqc/output.h ../phreeqc/kinetics.h ../phreeqc/phqalloc.h +dense.o: ../phreeqc/dense.c ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../phreeqc/output.h ../phreeqc/phqalloc.h +dw.o: ../phreeqc/dw.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h ../phreeqc/pitzer.h +input.o: ../phreeqc/input.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/input.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/phqalloc.h +integrate.o: ../phreeqc/integrate.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +inverse.o: ../phreeqc/inverse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +isotopes.o: ../phreeqc/isotopes.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +kinetics.o: ../phreeqc/kinetics.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/sundialstypes.h ../phreeqc/cvode.h \ + ../phreeqc/nvector.h ../phreeqc/cvdense.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../phreeqc/nvector_serial.h \ + ../phreeqc/kinetics.h +main.o: ../phreeqc/main.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/input.h +mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/input.h +model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h +nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ + ../phreeqc/nvector.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h +output.o: ../phreeqc/output.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h +p2clib.o: ../phreeqc/p2clib.c ../phreeqc/p2c.h ../phreeqc/output.h +parse.o: ../phreeqc/parse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +phqalloc.o: ../phreeqc/phqalloc.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/output.h +phreeqc_files.o: ../phreeqc/phreeqc_files.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/input.h +pitzer.o: ../phreeqc/pitzer.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer.h +pitzer_structures.o: ../phreeqc/pitzer_structures.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/pitzer.h +prep.o: ../phreeqc/prep.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +print.o: ../phreeqc/print.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer.h +read.o: ../phreeqc/read.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +readtr.o: ../phreeqc/readtr.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +smalldense.o: ../phreeqc/smalldense.c ../phreeqc/smalldense.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h +spread.o: ../phreeqc/spread.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +step.o: ../phreeqc/step.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +structures.o: ../phreeqc/structures.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +sundialsmath.o: ../phreeqc/sundialsmath.c ../phreeqc/sundialsmath.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h +tally.o: ../phreeqc/tally.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +tidy.o: ../phreeqc/tidy.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +transport.o: ../phreeqc/transport.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h +# ----------------------------------------------------------------------------- clean: - rm -f $(BINDIR)/$(PROGRAM) - rm -f $(TOPDIR)/bin/$(PROGRAM) - rm -f $(TOPDIR)/src/*.o - rm -f $(SUN_DIR)/bin/$(PROGRAM) - rm -f $(SUN_DIR)/src/*.o - rm -f $(TOPDIR)/src/$(PROGRAM) - rm -f $(DEBUG_DIR)/src/*.o - echo Removed object and executable files generated by make. - -$(EXE): $(OBJECTS) - echo $(TOPDIR) -ifdef USE_XML - ${LINK} ${PLATFORM_LIB_LINK_OPTIONS} ${OBJECTS} -o $(EXE) ${LIBRARY_SEARCH_PATHS} ${LIBRARY_NAMES} ${EXTRA_LINK_OPTIONS} ${LOADFLAGS} -else - $(CC) -o $(EXE) $(OBJECTS) $(LOADFLAGS) # -L/z/estespark/home/dlpark/packages/efence -lefence -endif - echo Compilation complete, $(EXE). - -advection.o: $(SRC)/advection.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -basic.o: $(SRC)/basic.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/p2c.h - -basicsubs.o: $(SRC)/basicsubs.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -cl1.o: $(SRC)/cl1.cpp $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h - -cl1mp.o: $(SRC)/cl1mp.cpp $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h - -cvdense.o: $(SRC)/cvdense.cpp $(SRC)/cvdense.h $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h - -cvode.o: $(SRC)/cvode.cpp $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/kinetics.h $(SRC)/phqalloc.h - -dense.o: $(SRC)/dense.cpp $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/output.h $(SRC)/phqalloc.h - -input.o: $(SRC)/input.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/input.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h - -integrate.o: $(SRC)/integrate.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -inverse.o: $(SRC)/inverse.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -isotopes.o: $(SRC)/isotopes.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -kinetics.o: $(SRC)/kinetics.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/sundialstypes.h $(SRC)/cvode.h $(SRC)/nvector.h $(SRC)/cvdense.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/nvector_serial.h $(SRC)/kinetics.h - -main.o: $(SRC)/main.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h - -mainsubs.o: $(SRC)/mainsubs.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h - -model.o: $(SRC)/model.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - ${CC} $(SRC)/model.cpp ${CCFLAGS_MODEL} -c -o model.o #-ffloat-store - -nvector.o: $(SRC)/nvector.cpp $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h - -nvector_serial.o: $(SRC)/nvector_serial.cpp $(SRC)/nvector_serial.h $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h - -output.o: $(SRC)/output.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h - -p2clib.o: $(SRC)/p2clib.cpp $(SRC)/p2c.h $(SRC)/output.h - -parse.o: $(SRC)/parse.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -phqalloc.o: $(SRC)/phqalloc.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/output.h - -phreeqc_files.o: $(SRC)/phreeqc_files.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h - -pitzer.o: $(SRC)/pitzer.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer.h - -dw.o: $(SRC)/dw.cpp $(SRC)/pitzer.h - -pitzer_structures.o: $(SRC)/pitzer_structures.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer.h - -prep.o: $(SRC)/prep.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -prep.o: $(SRC)/prep.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -print.o: $(SRC)/print.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -read.o: $(SRC)/read.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -readtr.o: $(SRC)/readtr.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -SAXPhreeqc.o: $(SRC)/SAXPhreeqc.cpp $(SRC)/SAXPhreeqc.h $(SRC)/SaxPhreeqcHandlers.h - ${CXX} ${CXXFLAGS} $(INCLUDES) -o SAXPhreeqc.o $(SRC)/SAXPhreeqc.cpp - -smalldense.o: $(SRC)/smalldense.cpp $(SRC)/smalldense.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h - -spread.o: $(SRC)/spread.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -step.o: $(SRC)/step.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -structures.o: $(SRC)/structures.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -sundialsmath.o: $(SRC)/sundialsmath.cpp $(SRC)/sundialsmath.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h - -tally.o: $(SRC)/tally.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -tidy.o: $(SRC)/tidy.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -transport.o: $(SRC)/transport.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -utilities.o: $(SRC)/utilities.cpp $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h - -Conc.o: $(SRC)/Conc.cxx $(SRC)/Conc.h $(SRC)/Utils.h $(SRC)/char_star.h $(SRC)/ISolution.h $(SRC)/NumKeyword.h \ - $(SRC)/Parser.h $(SRC)/Solution.h $(SRC)/Isotope.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ - $(SRC)/phrqproto.h $(SRC)/phqalloc.h -Exchange.o: $(SRC)/Exchange.cxx $(SRC)/Utils.h $(SRC)/Exchange.h $(SRC)/NumKeyword.h Parser.h \ - $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/ExchComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ - $(SRC)/phrqproto.h -ExchComp.o: $(SRC)/ExchComp.cxx $(SRC)/Utils.h $(SRC)/ExchComp.h $(SRC)/NameDouble.h $(SRC)/global.h \ - $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -GasPhase.o: $(SRC)/GasPhase.cxx $(SRC)/Utils.h $(SRC)/GasPhase.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ - $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -ISolution.o: $(SRC)/ISolution.cxx $(SRC)/ISolution.h $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h \ - $(SRC)/Solution.h $(SRC)/Isotope.h $(SRC)/Conc.h $(SRC)/Utils.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ - $(SRC)/phqalloc.h $(SRC)/phrqproto.h -Isotope.o: $(SRC)/Isotope.cxx $(SRC)/Isotope.h $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/Utils.h $(SRC)/global.h \ - $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -KineticsComp.o: $(SRC)/KineticsComp.cxx $(SRC)/Utils.h $(SRC)/KineticsComp.h $(SRC)/NameDouble.h \ - $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -KineticsCxx.o: $(SRC)/KineticsCxx.cxx $(SRC)/Utils.h $(SRC)/KineticsCxx.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ - $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/KineticsComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ - $(SRC)/phrqproto.h -Mix.o: $(SRC)/Mix.cxx $(SRC)/Utils.h $(SRC)/Mix.h $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h \ - $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -NameDouble.o: $(SRC)/NameDouble.cxx $(SRC)/Utils.h $(SRC)/Conc.h $(SRC)/char_star.h $(SRC)/NameDouble.h \ - $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -NumKeyword.o: $(SRC)/NumKeyword.cxx $(SRC)/NumKeyword.h $(SRC)/Parser.h $(SRC)/char_star.h -Reaction.o: $(SRC)/Reaction.cxx $(SRC)/Utils.h $(SRC)/Reaction.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ - $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -ReadClass.o: $(SRC)/ReadClass.cpp -Parser.o: $(SRC)/Parser.cxx $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/Utils.h -PPassemblageComp.o: $(SRC)/PPassemblageComp.cxx $(SRC)/Utils.h $(SRC)/NameDouble.h \ - $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -PPassemblage.o: $(SRC)/PPassemblage.cxx $(SRC)/Utils.h $(SRC)/PPassemblage.h $(SRC)/NumKeyword.h \ - $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/PPassemblageComp.h \ - $(SRC)/NameDouble.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -Solution.o: $(SRC)/Solution.cxx $(SRC)/Utils.h $(SRC)/Solution.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ - $(SRC)/char_star.h $(SRC)/Isotope.h $(SRC)/Conc.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h \ - $(SRC)/phqalloc.h $(SRC)/phrqproto.h $(SRC)/ISolution.h -SSassemblage.o: $(SRC)/SSassemblage.cxx $(SRC)/Utils.h $(SRC)/SSassemblage.h $(SRC)/NumKeyword.h \ - $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/SSassemblageSS.h \ - $(SRC)/NameDouble.h $(SRC)/SSassemblageSS.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h -SSassemblageSS.o: $(SRC)/SSassemblageSS.cxx $(SRC)/Utils.h $(SRC)/SSassemblageSS.h \ - $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h \ - $(SRC)/phrqproto.h -Surface.o: $(SRC)/Surface.cxx $(SRC)/Utils.h $(SRC)/Surface.h $(SRC)/NumKeyword.h $(SRC)/Parser.h \ - $(SRC)/char_star.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/SurfComp.h $(SRC)/NameDouble.h $(SRC)/phqalloc.h \ - $(SRC)/phrqproto.h -SurfComp.o: $(SRC)/SurfComp.cxx $(SRC)/Utils.h $(SRC)/SurfComp.h $(SRC)/NameDouble.h $(SRC)/global.h \ - $(SRC)/phrqtype.h $(SRC)/char_star.h $(SRC)/Parser.h $(SRC)/phqalloc.h $(SRC)/phrqproto.h - -Temperature.o: $(SRC)/Temperature.cxx $(SRC)/Utils.h $(SRC)/Temperature.h $(SRC)/NumKeyword.h \ - $(SRC)/Parser.h $(SRC)/char_star.h $(SRC)/NameDouble.h $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/phqalloc.h \ - $(SRC)/phrqproto.h -Utils.o: $(SRC)/Utils.cxx $(SRC)/Utils.h $(SRC)/Parser.h $(SRC)/char_star.h - --include $(SRC)/distribution.mk - + rm -rf Release Debug +# ============================================================================= +# End of makefile. +# ============================================================================= diff --git a/NameDouble.h b/NameDouble.h index 0977d958..6dc61b4a 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -37,7 +37,7 @@ public: struct name_coef *name_coef()const; - void cxxNameDouble::dump_xml(std::ostream& s_oss, unsigned int indent)const; + void dump_xml(std::ostream& s_oss, unsigned int indent)const; void dump_raw(std::ostream& s_oss, unsigned int indent)const; diff --git a/Parser.h b/Parser.h index 2ed217a5..feafabbe 100644 --- a/Parser.h +++ b/Parser.h @@ -56,7 +56,7 @@ public: enum ONERROR_TYPE { OT_CONTINUE = 0, - OT_STOP = 1, + OT_STOP = 1 }; enum STATUS_TYPE { diff --git a/Solution.h b/Solution.h index e9225701..f0c2696d 100644 --- a/Solution.h +++ b/Solution.h @@ -60,9 +60,9 @@ public: void dump_xml(std::ostream& os, unsigned int indent = 0)const; - void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const; + void dump_raw(std::ostream& s_oss, unsigned int indent)const; - void cxxSolution::read_raw(CParser& parser); + void read_raw(CParser& parser); protected: diff --git a/Temperature.cxx b/Temperature.cxx new file mode 100644 index 00000000..a1db6e32 --- /dev/null +++ b/Temperature.cxx @@ -0,0 +1,261 @@ +// Temperature.cxx: implementation of the cxxTemperature class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "Temperature.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxTemperature::cxxTemperature() + // + // default constructor for cxxTemperature + // +: cxxNumKeyword() +{ + countTemps = 0; + equalIncrements = false; +} + +cxxTemperature::cxxTemperature(struct temperature *temperature_ptr) + // + // constructor for cxxTemperature from struct temperature + // +: +cxxNumKeyword() +{ + int i; + + this->set_description(temperature_ptr->description); + this->n_user = temperature_ptr->n_user; + this->n_user_end = temperature_ptr->n_user_end; + // temps + if (temperature_ptr->count_t < 0) { + for (i = 0; i < 2; i++) { + this->temps.push_back(temperature_ptr->t[i]); + } + this->countTemps = -temperature_ptr->count_t; + this->equalIncrements = true; + } else { + for (i = 0; i < temperature_ptr->count_t; i++) { + this->temps.push_back(temperature_ptr->t[i]); + } + this->countTemps = temperature_ptr->count_t; + this->equalIncrements = false; + } +} + +cxxTemperature::~cxxTemperature() +{ +} + + +struct temperature *cxxTemperature::cxxTemperature2temperature() + // + // Builds a temperature structure from instance of cxxTemperature + // +{ + struct temperature *temperature_ptr; + temperature_ptr = (struct temperature *) PHRQ_malloc(sizeof (struct temperature)); + if (temperature_ptr == NULL) malloc_error(); + + temperature_ptr->description = this->get_description(); + temperature_ptr->n_user = this->n_user; + temperature_ptr->n_user_end = this->n_user_end; + + // temps + temperature_ptr->t = NULL; + if (this->temps.size() > 0) { + temperature_ptr->t = (double *) PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); + if (temperature_ptr->t == NULL) malloc_error(); + std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); + } + if (this->equalIncrements) { + temperature_ptr->count_t = -this->countTemps; + } else { + temperature_ptr->count_t = this->temps.size(); + } + return(temperature_ptr); +} + +#ifdef SKIP +void cxxTemperature::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Temperature element and attributes + s_oss << indent0; + s_oss << "pitzer_temperature_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = temperatureComps.begin(); it != temperatureComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxTemperature::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // Temperature element and attributes + s_oss << indent0; + s_oss << "REACTION_TEMPERATURE_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-temps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector::const_iterator it = this->temps.begin(); it != this->temps.end(); it++) { + if (i++ == 5) { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } + + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; + + s_oss << indent1; + s_oss << "-count_temps " << this->countTemps << std::endl; + + +} + +void cxxTemperature::read_raw(CParser& parser) +{ + + double d; + CParser::TOKEN_TYPE k; + static std::vector vopts; + if (vopts.empty()) { + vopts.reserve(15); + vopts.push_back("temps"); //0 + vopts.push_back("equal_increments"); //1 + vopts.push_back("count_temps"); //2 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read temperature number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool equalIncrements_defined(false); + bool countTemps_defined(false); + + 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 TEMPERATURE_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // temps + while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { + std::istringstream iss(token); + if (!(iss >> d)) { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for temps.", CParser::OT_CONTINUE); + } else { + this->temps.push_back(d); + } + } + opt_save = 0; + useLastLine = false; + break; + + case 1: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; + + case 2: // countTemps + if (!(parser.get_iss() >> this->countTemps)) + { + this->countTemps = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for countTemps.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + countTemps_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + } + // members that must be defined + if (equalIncrements_defined == false) { + parser.incr_input_error(); + parser.error_msg("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE); + } + if (countTemps_defined == false) { + parser.incr_input_error(); + parser.error_msg("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE); + } +} diff --git a/Temperature.h b/Temperature.h new file mode 100644 index 00000000..d0ea2f90 --- /dev/null +++ b/Temperature.h @@ -0,0 +1,41 @@ +#if !defined(TEMPERATURE_H_INCLUDED) +#define TEMPERATURE_H_INCLUDED + +#include "NumKeyword.h" +#define EXTERNAL extern +#include "global.h" +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "char_star.h" + +class cxxTemperature : public cxxNumKeyword +{ + +public: + cxxTemperature(); + cxxTemperature(struct temperature *); + ~cxxTemperature(); + + struct temperature *cxxTemperature2temperature(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + std::vector temps; + int countTemps; + bool equalIncrements; + +public: + //static std::map& map; + +}; + +#endif // !defined(TEMPERATURE_H_INCLUDED) diff --git a/cpp.dsw b/cpp.dsw deleted file mode 100644 index fd89dcc2..00000000 --- a/cpp.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "cpp"=.\cpp.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/distribution.mk b/distribution.mk deleted file mode 100644 index b1603ed1..00000000 --- a/distribution.mk +++ /dev/null @@ -1,368 +0,0 @@ -# Locations to save compressed tar file for distribution -EXPORT=$(TOPDIR)/src/phreeqc_export -EXPORT_DIR=$(EXPORT) -WIN_DIR=$(TOPDIR)/win -DIST_DIR=$(EXPORT_DIR) -DEBUG_DIR=phreeqc_debug -DEBUG_EXE=$(SRC)/$(PROGRAM) -VERSION=2.12 -VER_DATE:=November 10, 2005 -VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") -V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") -GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") -KERNEL_VER:=$(shell uname -r) -ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) -TEXTCP=textcp DOS -SUN_DIR=$(TOPDIR)/src/Sun -UNIX2DOS=unix2dos -CCFLAGS_DBG=-Wall -ansi -g -# list of files for distribution -FILES= \ - src/Makefile \ - src/advection.c \ - src/basic.c \ - src/basicsubs.c \ - src/cl1.c \ - src/cl1mp.c \ - src/cvdense.c \ - src/cvode.c \ - src/dense.c \ - src/dw.c \ - src/input.c \ - src/integrate.c \ - src/inverse.c \ - src/isotopes.c \ - src/kinetics.c \ - src/main.c \ - src/mainsubs.c \ - src/model.c \ - src/nvector.c \ - src/nvector_serial.c \ - src/output.c \ - src/p2clib.c \ - src/parse.c \ - src/phqalloc.c \ - src/phreeqc_files.c \ - src/phreeqc_files.c \ - src/pitzer.c \ - src/pitzer_structures.c \ - src/prep.c \ - src/print.c \ - src/read.c \ - src/readtr.c \ - src/smalldense.c \ - src/spread.c \ - src/step.c \ - src/structures.c \ - src/sundialsmath.c \ - src/tally.c \ - src/tidy.c \ - src/transport.c \ - src/utilities.c \ - src/cvdense.h \ - src/cvode.h \ - src/dense.h \ - src/global.h \ - src/input.h \ - src/kinetics.h \ - src/nvector.h \ - src/nvector_serial.h \ - src/output.h \ - src/p2c.h \ - src/phqalloc.h \ - src/phrqproto.h \ - src/phrqtype.h \ - src/pitzer.h \ - src/smalldense.h \ - src/sundialsmath.h \ - src/sundialstypes.h \ - database/llnl.dat \ - database/minteq.dat \ - database/minteq.v4.dat \ - database/phreeqc.dat \ - database/wateq4f.dat \ - database/iso.dat \ - database/pitzer.dat \ - examples/ex1 examples/ex1.out \ - examples/ex2 examples/ex2.out examples/ex2.sel \ - examples/ex3 examples/ex3.out \ - examples/ex4 examples/ex4.out \ - examples/ex5 examples/ex5.out examples/ex5.sel \ - examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ - examples/ex7 examples/ex7.out examples/ex7.sel \ - examples/ex8 examples/ex8.out examples/ex8.sel \ - examples/ex9 examples/ex9.out examples/ex9.sel \ - examples/ex10 examples/ex10.out examples/ex10.sel \ - examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ - examples/ex12 examples/ex12.out examples/ex12.sel \ - examples/ex12a examples/ex12a.out examples/ex12a.sel \ - examples/ex13a examples/ex13a.out examples/ex13a.sel \ - examples/ex13b examples/ex13b.out examples/ex13b.sel \ - examples/ex13c examples/ex13c.out examples/ex13c.sel \ - examples/ex14 examples/ex14.out examples/ex14.sel \ - examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ - examples/ex16 examples/ex16.out \ - examples/ex17 examples/ex17.out \ - examples/ex18 examples/ex18.out \ - doc/NOTICE.TXT \ - doc/README.TXT \ - doc/RELEASE.TXT \ - doc/manual.pdf \ - doc/wrir02-4172.pdf \ - doc/phreeqc.txt \ - bin/phreeqc.orig \ - test/test.sh \ - test/clean.sh \ - test/check.sh - -SED_ARGS= \ - -e "s/@VERSION@/$(VERSION)/" \ - -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ - -e "s/VERSION_DATE/$(VERSION)/" \ - -e "s^@GCC_VER@^$(GCC_VER)^" \ - -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ - -e "s/@REVISION@/$(REVISION)/" - -remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files - -output_files: linux_output_files # sun_output_files - -# make sure program is compiles, run examples and mytest -linux_output_files: all - cd ../examples; make >& make.out - cd ../mytest; make >& make.out - -clean_linux_output_files: - cd ../examples; make clean - cd ../mytest; make clean - -sun_output_files: phreeqc.sun - ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" - -phreeqc.sun: - ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" - -clean_sun_output_files: - cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean - -all_dist: clean_dist linux source # win # sun - -test_dist: linux_test source_test # sun_test - -# -#Linux -# -linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist - -source: source_export source_clean source_sed_files source_dist - -linux_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Linux - svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux - -linux_clean: - rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o - -linux_sed_list= \ - "$(EXPORT_DIR)/Linux/doc/README.TXT \ - $(EXPORT_DIR)/Linux/src/main.c" - -linux_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/doc/RELEASE.TXT - for FILE in "$(linux_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - -linux_compile: - make -C $(EXPORT_DIR)/Linux/src - -linux_output: - cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out - -linux_dist: - cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) - cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz - cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - -source_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Source - svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source - -source_clean: - rm -f $(EXPORT_DIR/Source/bin/$(PROGRAM) $(EXPORT_DIR/Source/src/*.o - -source_sed_list= \ - "$(EXPORT_DIR)/Source/doc/README.TXT \ - $(EXPORT_DIR)/Source/src/main.c" - -source_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/doc/RELEASE.TXT - for FILE in "$(source_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - -source_dist: - cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar - cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz - cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) - -linux_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh - rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh - -source_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source - cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k - cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh - -# -#Sun -# -sun: sun_export sun_clean sun_sed_files sun_compile sun_output sun_dist - -sun_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Sun - svn export .. $(EXPORT_DIR)/Sun - -sun_clean: - rm -f $(EXPORT_DIR)/Sun/bin/$(PROGRAM) $(EXPORT_DIR)/Sun/src/*.o - -sun_sed_list= \ - "$(EXPORT_DIR)/Sun/doc/README.TXT \ - $(EXPORT_DIR)/Sun/src/main.c" - -sun_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Sun/src/revisions > $(EXPORT_DIR)/Sun/doc/RELEASE.TXT - for FILE in "$(sun_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - -sun_compile: - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/src" - -sun_output: - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples clean" - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples" > $(EXPORT_DIR)/Sun/examples/make.out 2>> $(EXPORT_DIR)/Sun/examples/make.out - -sun_dist: - cd $(EXPORT_DIR)/Sun; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Sun; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Sun; tar -rf $(PROGRAM).tar bin/$(PROGRAM) - cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Sun; tar -czf $(PROGRAM).Sun.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).Sun.tar.gz $(DIST_DIR)/$(ROOTNAME).Sun.tar.gz - cd $(EXPORT_DIR)/Sun; echo $(ROOTNAME).Sun.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) - -sun_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Sun - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Sun.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Sun - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./test.sh" - rm -f $(DIST_DIR)/phreeqc-$(VERSION).Sun/bin/phreeqc - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/src; make -k" - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./clean.sh; ./test.sh" - -clean_dist: - rm -rf $(EXPORT_DIR) - -clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files - -# -#Win -# -win: win_export win_sed_files win_dist - -win_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Win - svn export .. $(EXPORT_DIR)/Win - -win_sed_list= \ - "$(EXPORT_DIR)/Win/src/main.c" - -win_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/doc/RELEASE.TXT - $(UNIX2DOS) $(EXPORT_DIR)/Win/doc/RELEASE.TXT - sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/doc/README.TXT - $(UNIX2DOS) $(EXPORT_DIR)/Win/doc/README.TXT - for FILE in "$(win_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; \ - mv t $$FILE; \ - $(UNIX2DOS) $$FILE; \ - done - -win_dist: - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar -# Translate cr/lf - cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ - if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ - else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done - cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar -# remove example output - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel -# remove bin directory - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin -# remove test directory files - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat -# copy bat file - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat - cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz - cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(PROGRAM).Windows.tar.gz . - cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); mv $(PROGRAM).Windows.tar.gz $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz - @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) - -win_echo_files: - @echo $(FILES) - -debug: - echo DEBUG_EXE $(DEBUG_EXE) - echo SRC $(SRC) - echo CURDIR $(CURDIR) - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(SRC)/Makefile SRC=$(SRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) - -debug_nomp: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(TOPDIR)/src/Makefile SRC=$(TOPDIR)/src CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) - -web: - cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc - cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT - cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT - cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT - cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT - cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt - cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT - - From 0d1acff7dac67a65f4a72766e4aa1539bb0e74e0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 17:54:56 +0000 Subject: [PATCH 0004/1077] removed classes and headers that are in phreeqc directory. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@790 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- classes/Conc.cxx | 188 -------- classes/Conc.h | 60 --- classes/Isotope.cxx | 100 ----- classes/Isotope.h | 40 -- classes/Makefile | 35 -- classes/NumKeyword.cxx | 119 ----- classes/NumKeyword.h | 34 -- classes/Parser.cxx | 836 ------------------------------------ classes/Parser.h | 196 --------- classes/Pe_Data.cxx | 45 -- classes/Pe_Data.h | 27 -- classes/Solution.cxx | 312 -------------- classes/Solution.h | 72 ---- classes/TestCIsotope.cxx | 164 ------- classes/TestCIsotope.h | 39 -- classes/TestCParser.cxx | 192 --------- classes/TestCParser.h | 48 --- classes/TestCSolution.cxx | 124 ------ classes/TestCSolution.h | 24 -- classes/main.cxx | 83 ---- classes/test.cxx | 23 - classes/utilities.cxx | 68 --- classes/utilities.h | 28 -- cvdense.h | 224 ---------- cvode.h | 882 -------------------------------------- phqalloc.h | 46 -- 26 files changed, 4009 deletions(-) delete mode 100644 classes/Conc.cxx delete mode 100644 classes/Conc.h delete mode 100644 classes/Isotope.cxx delete mode 100644 classes/Isotope.h delete mode 100644 classes/Makefile delete mode 100644 classes/NumKeyword.cxx delete mode 100644 classes/NumKeyword.h delete mode 100644 classes/Parser.cxx delete mode 100644 classes/Parser.h delete mode 100644 classes/Pe_Data.cxx delete mode 100644 classes/Pe_Data.h delete mode 100644 classes/Solution.cxx delete mode 100644 classes/Solution.h delete mode 100644 classes/TestCIsotope.cxx delete mode 100644 classes/TestCIsotope.h delete mode 100644 classes/TestCParser.cxx delete mode 100644 classes/TestCParser.h delete mode 100644 classes/TestCSolution.cxx delete mode 100644 classes/TestCSolution.h delete mode 100644 classes/main.cxx delete mode 100644 classes/test.cxx delete mode 100644 classes/utilities.cxx delete mode 100644 classes/utilities.h delete mode 100644 cvdense.h delete mode 100644 cvode.h delete mode 100644 phqalloc.h diff --git a/classes/Conc.cxx b/classes/Conc.cxx deleted file mode 100644 index fae825a6..00000000 --- a/classes/Conc.cxx +++ /dev/null @@ -1,188 +0,0 @@ -#include "Conc.h" -#include "Solution.h" -#include "Utilities.h" -#include - -CConc::CConc(void) -: description("") -, moles(0.0) -, input_conc(0.0) -, units("") -, equation_name("") -, phase_si(0.0) -, n_pe(-1) -, as("") -, gfw(0.0) - //, skip(0); - //, phase(NULL) -{ -} - -CConc::~CConc(void) -{ -} - -#ifdef SKIP -CConc::STATUS_TYPE CConc::read(CParser& parser, CSolution& solution) -{ - // std::string& str = parser.line(); - std::string str = parser.line(); - - // defaults set in ctor - - // Remove space between "kg" and "solution" or "water" in units - Utilities::replace("Kg", "kg", str); - Utilities::replace("KG", "kg", str); - while (Utilities::replace("kg ", "kg", str)); - - std::istream::pos_type ptr = 0; - - // - // Read master species list for mass balance equation - // - std::string token; - std::string token1; - int count_redox_states = 0; - CParser::TOKEN_TYPE j; - while ( ((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER ) || - ( token[0] == '[' ) || - ( Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0 ) || - ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) ) - { - ++count_redox_states; - Utilities::replace("(+", "(", token); - if (count_redox_states > 1) token1 += " "; - token1 += token; - } - if (count_redox_states == 0) { - parser.incr_input_error(); - parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE); - return CConc::ERROR; - } - description = token1; - - // Determine if reading alkalinity, allow equivalents for units - Utilities::str_tolower(token1); - bool alk = false; - if (token1.find("alk") == 0) { - alk = true; - } - - // Read concentration - if (!(std::istringstream(token) >> this->input_conc)) { - std::ostringstream err; - err << "Concentration data error for " << token1 << " in solution input."; - parser.error_msg(err, CParser::OT_CONTINUE); - return CConc::ERROR; - } - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - - // Read optional data - token1 = token; - - // Check for units info - if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) { - if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) { - this->units = token1; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - } else { - return CConc::ERROR; - } - } - - // Check for "as" followed by formula to be used for gfw - token1 = token; - Utilities::str_tolower(token1); - if (token1.compare("as") == 0) - { - parser.copy_token(token, ptr); - this->as = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - } - // Check for "gfw" followed by gram formula weight - else if (token1.compare("gfw") == 0) - { - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { - parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); - return CConc::ERROR; - } else { - parser.get_iss() >> this->gfw; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - } - } - - // Check for redox couple for pe - if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { - this->n_pe = CPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - } else if (token.find("/") != std::string::npos) { - if (parser.parse_couple(token) == CParser::OK) { - this->n_pe = CPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - } else { - return CConc::ERROR; - } - } - - // Must have phase - this->equation_name = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return CConc::OK; - - // Check for saturation index - if (!(std::istringstream(token) >> this->phase_si)) - { - parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); - return CConc::ERROR; - } - return CConc::OK; -} -#endif - -void CConc::dump_xml(const CSolution& solution, std::ostream& os, unsigned int indent)const -{ - unsigned int i; - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->description << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->input_conc << "\n"; - - if (!this->units.empty()) { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->units << "\n"; - } - - if ( !this->as.empty() ) { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->as << "\n"; - } - else if (this->gfw > 0.0) { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->gfw << "\n"; - } - ////if (this->n_pe > 0) { - solution.pe[this->n_pe].dump_xml(os, indent + 1); - ////} - - if (!this->equation_name.empty()) { - if (Utilities::strcmp_nocase_arg1(this->equation_name.c_str(), "charge") == 0) - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - } - else - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->equation_name << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->phase_si << "\n"; - } - } - - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "\n"; -} diff --git a/classes/Conc.h b/classes/Conc.h deleted file mode 100644 index 4b867d2f..00000000 --- a/classes/Conc.h +++ /dev/null @@ -1,60 +0,0 @@ -#if !defined(CONC_H_INCLUDED) -#define CONC_H_INCLUDED - -#include "Parser.h" -#include "Utilities.h" - -#include - -// forward declarations -class CSolution; // reqd for read and dump_xml - -class CConc -{ -public: - CConc(void); - ~CConc(void); - - enum STATUS_TYPE { - ERROR = 0, - OK = 1 - }; - -public: - - STATUS_TYPE read(CParser& parser, CSolution& sol); - - void dump_xml(const CSolution& solution, std::ostream& os, unsigned int indent = 0)const; - - double get_input_conc()const {return this->input_conc;} - void set_input_conc(double input_conc) {this->input_conc = input_conc;} - - std::string get_equation_name()const {return this->equation_name;} - void set_equation_name(std::string equation_name) {this->equation_name = equation_name;} - - std::string get_description()const {return this->description;} - void set_description(std::string description) {this->description = description;} - - std::string get_units()const {return this->units;} - void set_units(std::string units) {this->units = units;} - - int get_n_pe()const {return this->n_pe;} - void set_n_pe(int n_pe) {this->n_pe = n_pe;} - - bool operator<(const CConc& conc)const { return (this->description < conc.description); } - -private: - std::string description; - // int m_skip; - double moles; - double input_conc; - std::string units; - std::string equation_name; - // struct phase *m_phase; - double phase_si; - int n_pe; - std::string as; - double gfw; -}; - -#endif // CONC_H_INCLUDED diff --git a/classes/Isotope.cxx b/classes/Isotope.cxx deleted file mode 100644 index 5654e1df..00000000 --- a/classes/Isotope.cxx +++ /dev/null @@ -1,100 +0,0 @@ -#include "Isotope.h" -#include "Utilities.h" -#include - -CIsotope::CIsotope(void) -: isotope_number(0.0) -, ratio_uncertainty_defined(false) -{ -} - -CIsotope::~CIsotope(void) -{ -} - -std::string CIsotope::get_name()const -{ - std::ostringstream oss; - oss << this->isotope_number << this->elt_name; - return oss.str(); -} -#ifdef SKIP -CIsotope::STATUS CIsotope::read(CParser& parser) -{ - if ( !(parser.get_iss() >> this->isotope_number) ) { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected isotope name to" - " begin with an isotopic number.", CParser::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - - // read and save element name - std::istringstream::int_type c = parser.get_iss().peek(); - if ( c == std::char_traits::eof() || !(::isupper(c)) ) { - parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - parser.incr_input_error(); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - if ( !(parser.get_iss() >> this->elt_name) ) { - // should never get here - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - assert(!this->elt_name.empty() && ::isupper(this->elt_name[0])); - - // read and store isotope ratio - if ( !(parser.get_iss() >> this->ratio) ) { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected numeric value for isotope ratio.", CParser::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - - // read and store isotope ratio - this->ratio_uncertainty_defined = false; - if ( !(parser.get_iss() >> this->ratio_uncertainty)) { - if ( !parser.get_iss().eof() ) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for uncertainty in isotope ratio.", CParser::OT_CONTINUE); - return ERROR; - } - } else { - this->ratio_uncertainty_defined = true; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - return OK; -} -#endif -#ifdef SKIP -void CIsotope::dump_xml(std::ostream& os, unsigned int indent)const -{ - unsigned int i; - - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "ratio << "\""; - if ( this->ratio_uncertainty_defined /* Utilities::isnan(this->ratio_uncertainty) */ ) { - os << "/>\n"; - } - else { - os << ">\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->ratio_uncertainty << "\n"; - - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "\n"; - } -} -#endif -bool CIsotope::operator<(const CIsotope& isotope)const -{ - int i = Utilities::strcmp_nocase(this->elt_name.c_str(), isotope.elt_name.c_str()); - if (i != 0) return (i < 0); - return ( this->isotope_number < isotope.isotope_number ); -} - diff --git a/classes/Isotope.h b/classes/Isotope.h deleted file mode 100644 index 9ded5525..00000000 --- a/classes/Isotope.h +++ /dev/null @@ -1,40 +0,0 @@ -#if !defined(ISOTOPE_H_INCLUDED) -#define ISOTOPE_H_INCLUDED - -#include "Parser.h" -#include // std::ostream -#include // std::string - -class CIsotope -{ -public: - CIsotope(void); - ~CIsotope(void); - - enum STATUS { - ERROR = 0, - OK = 1 - }; - - CIsotope::STATUS read(CParser& parser); - - void dump_xml(std::ostream& os, unsigned int indent)const; - - std::string get_name()const ; - - double get_ratio()const { return this->ratio; } - - double get_ratio_uncertainty()const { return this->ratio_uncertainty; } - - bool get_ratio_uncertainty_defined()const { return this->ratio_uncertainty_defined; } - - bool operator<(const CIsotope& conc)const; - -private: - double isotope_number; - std::string elt_name; - double ratio; - double ratio_uncertainty; - bool ratio_uncertainty_defined; -}; -#endif // ISOTOPE_H_INCLUDED diff --git a/classes/Makefile b/classes/Makefile deleted file mode 100644 index 04119bc6..00000000 --- a/classes/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -.SUFFIXES : .o .cxx - -.cxx.o : - $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $< - -CXX = g++ -CPPFLAGS = -I/z/srv2rcolkr/home/charlton/cppunit-robocomp/include -CXXFLAGS = -Wall -LDFLAGS = -lcppunit -L/z/srv2rcolkr/home/charlton/cppunit-robocomp/lib -static - - -COMMON_OBJS = Conc.o\ - Isotope.o\ - NumKeyword.o\ - Parser.o\ - Pe_Data.o\ - Solution.o\ - Utilities.o - -TEST_OBJS = TestCIsotope.o\ - TestCSolution.o\ - TestCParser.o\ - test.o - -all: phreeqcxx test - - -phreeqcxx : ${COMMON_OBJS} main.o - ${CXX} -o $@ ${COMMON_OBJS} main.o - -test : ${COMMON_OBJS} ${TEST_OBJS} - ${CXX} -o $@ ${COMMON_OBJS} ${TEST_OBJS} ${LDFLAGS} - -clean : - rm -f ${COMMON_OBJS} main.o ${TEST_OBJS} diff --git a/classes/NumKeyword.cxx b/classes/NumKeyword.cxx deleted file mode 100644 index 8590b95f..00000000 --- a/classes/NumKeyword.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// NumKeyword.cxx: implementation of the CNumKeyword class. -// -////////////////////////////////////////////////////////////////////// - -#include "NumKeyword.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CNumKeyword::CNumKeyword() -{ -} - -CNumKeyword::~CNumKeyword() -{ -} - -void CNumKeyword::dump_xml(std::ostream& os, unsigned int indent)const -{ - unsigned int i; - - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->n_user << "" << "\n"; - - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->n_user_end << "" << "\n"; - - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->description << "" << "\n"; -} - -void CNumKeyword::read_number_description(CParser& parser) -{ - // skip keyword - std::string keyword; - std::istream::pos_type ptr; - parser.copy_token(keyword, ptr); - - std::istream::pos_type ptr1 = ptr; - std::string::size_type pos; - std::string token; - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) - { - this->n_user = 1; - this->n_user_end = 1; - } - else if ( (pos = token.find_first_of("-")) != std::string::npos ) - { - token.replace(pos, 1, " "); - std::istringstream iss(token); - if (!(iss >> this->n_user >> this->n_user_end)) - { - std::ostringstream err_oss; - if (parser.next_keyword() >= 0) - { - err_oss << "Reading number range for " << keyword << "."; - } - else - { - err_oss << "Reading number range for keyword."; - } - parser.error_msg(err_oss, CParser::OT_CONTINUE); - parser.incr_input_error(); - } - ptr1 = ptr; - } - else - { - std::istringstream iss(token); - iss >> this->n_user; - this->n_user_end = this->n_user; - ptr1 = ptr; - } - - // reset get position - parser.get_iss().seekg(ptr1); - - // skip whitespace - while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore(); - - // copy description - std::getline(parser.get_iss(), this->description); -} - -void CNumKeyword::read_number_description(std::istream& is) -{ - // KEYWORD [[1[-20]] [This is the description]] - - // eat keyword - std::string token; - is >> token; - - // skip whitespace - while (::isspace(is.peek())) is.ignore(); - - if (::isdigit(is.peek())) - { - is >> this->n_user; - char ch = is.peek(); - if (ch == '-') - { - is >> ch; // eat '-' - is >> this->n_user_end; - } - else - { - this->n_user_end = this->n_user; - } - } - else - { - this->n_user = this->n_user_end = 1; - } - - while (::isspace(is.peek())) is.ignore(); - - std::getline(is, this->description); -} diff --git a/classes/NumKeyword.h b/classes/NumKeyword.h deleted file mode 100644 index 0b885426..00000000 --- a/classes/NumKeyword.h +++ /dev/null @@ -1,34 +0,0 @@ -#if !defined(NUMKEYWORD_H_INCLUDED) -#define NUMKEYWORD_H_INCLUDED - -#include "Parser.h" -#include // std::ostream -#include // std::string - -class CNumKeyword -{ -public: - CNumKeyword(); - virtual ~CNumKeyword(); - - int get_n_user()const { return this->n_user; } - void set_n_user(int user) { this->n_user = user; } - - int get_n_user_end()const { return this->n_user_end; } - void set_n_user_end(int user_end) { this->n_user_end = user_end; } - - bool operator<(const CNumKeyword& key)const { return (this->n_user < key.n_user); } - - virtual void dump_xml(std::ostream& os, unsigned int indent = 0)const; - - void read_number_description(CParser& parser); - -protected: - int n_user; - int n_user_end; - std::string description; - -private: - void read_number_description(std::istream& is); -}; -#endif // !defined(NUMKEYWORD_H_INCLUDED) diff --git a/classes/Parser.cxx b/classes/Parser.cxx deleted file mode 100644 index 3316162d..00000000 --- a/classes/Parser.cxx +++ /dev/null @@ -1,836 +0,0 @@ -// Parser.cpp: implementation of the CParser class. -// -////////////////////////////////////////////////////////////////////// - -#include "Parser.h" -#include "utilities.h" -#include // std::transform -#include // std::map -#include // assert -#include // std::cout std::cerr - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CParser::CParser(std::istream& input) -: m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr) -, m_input_error(0), m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); -} - -CParser::CParser(std::istream& input, std::ostream& output) -: m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr) -, m_input_error(0), m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); -} - -CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) -: m_input_stream(input), m_output_stream(output), m_error_stream(error) -, m_input_error(0), m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); -} - -CParser::~CParser() -{ -} - -CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print) -{ - LINE_TYPE i; - - // Get line - do { - i = get_line(); - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - - - if (true) // pr.echo_input == TRUE - { - if ((print && i != LT_EOF) || i == LT_KEYWORD) - { - get_output() << "\t" << m_line_save << "\n"; - } - } - - } while (i == LT_EMPTY && allow_empty == false); - - // Check eof - if (i == LT_EOF && allow_eof == false) - { - std::ostringstream msg; - msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; - error_msg(msg, OT_STOP); - } - - // Check keyword - if (i == LT_KEYWORD && allow_keyword == false) - { - std::ostringstream msg; - msg << "Expected data for " << str << ", but got a keyword ending data block."; - error_msg(msg, OT_CONTINUE); - incr_input_error(); - } - return i; -} - -CParser::LINE_TYPE CParser::get_line() -{ - CParser::LINE_TYPE return_value = LT_EMPTY; - while (return_value == LT_EMPTY) - { - // - // Eliminate all characters after # sign as a comment - // - - // - // Get line, check for eof - // - if (get_logical_line() == LT_EOF) - { - if (!m_input_stream.eof()) - { - error_msg("Reading input file.", OT_CONTINUE); - error_msg("istream::get() returned an error.", OT_STOP); - } - else - { - //{{MOD - m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); - //}}MOD - m_next_keyword = KT_EOF; - return LT_EOF; - } - } - - // - // Get long lines - // - bool empty = true; - m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); - for (unsigned int i = 0; i < m_line.size(); ++i) - { - if (!::isspace(m_line[i])) - { - empty = false; - break; - } - } - - // - // New line character encountered - // - return_value = (empty ? LT_EMPTY : LT_OK); - } - - // - // Determine return_value - // - if (return_value == LT_OK) - { - if (check_key(m_line.begin(), m_line.end())) - { - return_value = LT_KEYWORD; - } - else - { - std::string::iterator beg = m_line.begin(); - std::string::iterator end = m_line.end(); - std::string token; - copy_token(token, beg, end); - - if (token.size() > 1 && token[0] == '-' && ::isalpha(token[1])) - { - return_value = LT_OPTION; - } - } - } - return return_value; -} - -/** - Reads input stream until end of line, ";", or eof - stores characters in line_save - - returns: - EOF on empty line on end of file or - OK otherwise -*/ -CParser::LINE_TYPE CParser::get_logical_line() -{ - int j; - unsigned int pos; - char c; - - m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); - - while ((j = m_input_stream.get()) != std::char_traits::eof()) { - c = (char) j; - if (c == '#') { - // ignore all chars after # until newline - do { - c = (char) j; - if (c == '\n') { - break; - } - m_line_save += c; - } while ((j = m_input_stream.get()) != std::char_traits::eof()); - } - if (c == ';') break; - if (c == '\n') { - break; - } - if (c == '\\') { - pos = m_line_save.size(); - m_line_save += c; - while ((j = m_input_stream.get()) != std::char_traits::eof()) { - c = (char) j; - if (c == '\\') { - pos = m_line_save.size(); - m_line_save += c; - continue; - } - if (c == '\n') { - // remove '\\' - for (; pos < m_line_save.size(); pos++) { - m_line_save[pos] = m_line_save[pos+1]; - } - m_line_save.erase(m_line_save.size() - 1, 1); - break; - } - m_line_save += c; - if (!::isspace(j)) break; - } - } else { - m_line_save += c; - } - } - if (j == std::char_traits::eof() && m_line_save.size() == 0) { - return(LT_EOF); - } - return(LT_OK); -} - - -//bool CParser::check_key(const std::string::iterator ptr) -bool CParser::check_key(std::string::iterator begin, std::string::iterator end) -{ - static std::map s_keyword_map; - if (s_keyword_map.size() == 0) - { - s_keyword_map.insert(std::map::value_type("solution", KT_SOLUTION)); - s_keyword_map.insert(std::map::value_type("end", KT_END)); - } - - std::string lowercase; - copy_token(lowercase, begin, end); - std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); - - m_next_keyword = KT_NONE; - std::map::iterator map_iter = s_keyword_map.find(lowercase); - if (map_iter == s_keyword_map.end()) - return false; - m_next_keyword = (*map_iter).second; - return true; -} - -CParser::STATUS_TYPE CParser::check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, - const std::string& default_units, bool print) -{ -/* - * Check if legitimate units - * Input: - * tot_units character string to check, - * alkalinity true if alkalinity, false if any other total, - * check_compatibility true check alk and default units, false otherwise - * default_units character string of default units (check /L, /kg, etc) - * print true print warning messages - * Output: - * tot_units standard form for unit - */ - using utilities::str_tolower; - using utilities::replace; - using utilities::squeeze_white; - - static const char *units[] = { - "Mol/l", /* 0 */ - "mMol/l", /* 1 */ - "uMol/l", /* 2 */ - "g/l", /* 3 */ - "mg/l", /* 4 */ - "ug/l", /* 5 */ - "Mol/kgs", /* 6 */ - "mMol/kgs", /* 7 */ - "uMol/kgs", /* 8 */ - "g/kgs", /* 9 = ppt */ - "mg/kgs", /* 10 = ppm */ - "ug/kgs", /* 11 = ppb */ - "Mol/kgw", /* 12 = mol/kg H2O */ - "mMol/kgw", /* 13 = mmol/kg H2O */ - "uMol/kgw", /* 14 = umol/kg H2O */ - "g/kgw", /* 15 = mol/kg H2O */ - "mg/kgw", /* 16 = mmol/kg H2O */ - "ug/kgw", /* 17 = umol/kg H2O */ - "eq/l", /* 18 */ - "meq/l", /* 19 */ - "ueq/l", /* 20 */ - "eq/kgs", /* 21 */ - "meq/kgs", /* 22 */ - "ueq/kgs", /* 23 */ - "eq/kgw", /* 24 */ - "meq/kgw", /* 25 */ - "ueq/kgw", /* 26 */ - }; - - squeeze_white(tot_units); - str_tolower(tot_units); - replace("milli", "m", tot_units); - replace("micro", "u", tot_units); - replace("grams", "g", tot_units); - replace("gram", "g", tot_units); - replace("moles", "Mol", tot_units); - replace("mole", "Mol", tot_units); - replace("mol", "Mol", tot_units); - replace("liter", "l", tot_units); - replace("kgh", "kgw", tot_units); - replace("ppt", "g/kgs", tot_units); - replace("ppm", "mg/kgs", tot_units); - replace("ppb", "ug/kgs", tot_units); - replace("equivalents", "eq", tot_units); - replace("equivalent", "eq", tot_units); - replace("equiv", "eq", tot_units); - - std::string::size_type end; - if ((end = tot_units.find("/l")) != std::string::npos) { - tot_units.resize(end + 2); - } - if ((end = tot_units.find("/kgs")) != std::string::npos) { - tot_units.resize(end + 4); - } - if ((end = tot_units.find("/kgw")) != std::string::npos) { - tot_units.resize(end + 4); - } - - // - // Check if unit in list - // - bool found = false; - for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) { - if (tot_units.compare(units[i]) == 0) { - found = true; - break; - } - } - if (!found) { - if (print) { - std::ostringstream err; - err << "Unknown unit, " << tot_units; - error_msg(err, OT_CONTINUE); - } - return ERROR; - } - - // - // Check if units are compatible with default_units - // - if (check_compatibility == false) return OK; - - // - // Special cases for alkalinity - // - if (alkalinity == true && tot_units.find("Mol") != std::string::npos) { - if (print) { - warning_msg("Alkalinity given in moles, assumed to be equivalents."); - } - replace("Mol", "eq", tot_units); - } - if (alkalinity == false && tot_units.find("eq") != std::string::npos) { - if (print) { - error_msg("Only alkalinity can be entered in equivalents.", OT_CONTINUE); - } - return ERROR; - } - - // - // See if default_units are compatible with tot_units - // - if (default_units.find("/l") != std::string::npos && tot_units.find("/l") != std::string::npos) return OK; - if (default_units.find("/kgs") != std::string::npos && tot_units.find("/kgs") != std::string::npos) return OK; - if (default_units.find("/kgw") != std::string::npos && tot_units.find("/kgw") != std::string::npos) return OK; - - std::string str = default_units; - replace("kgs", "kg solution", str); - replace("kgs", "kg solution", tot_units); - replace("kgw", "kg water", str); - replace("kgw", "kg water", tot_units); - replace("/l", "/L", str); - replace("Mol", "mol", str); - replace("/l", "/L", tot_units); - replace("Mol", "mol", tot_units); - - if (print) { - std::ostringstream err; - err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; - error_msg(err, OT_CONTINUE); - } - return ERROR; -} - -CParser::TOKEN_TYPE CParser::token_type(const std::string& token) -{ - if (!token.empty()) { - if (::isupper(token[0])) { - return CParser::TT_UPPER; - } else if (::islower(token[0])) { - return CParser::TT_LOWER; - } else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') { - return CParser::TT_DIGIT; - } else { - assert(!::isspace(token[0])); - return CParser::TT_UNKNOWN; - } - } - else { - return CParser::TT_EMPTY; - } -} - -CParser::TOKEN_TYPE CParser::peek_token() -{ - std::istringstream::pos_type pos = m_line_iss.tellg(); - std::string token; - m_line_iss >> token; - m_line_iss.seekg(pos); - return token_type(token); -} - -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end) -{ - if (begin != end) - { - std::string::iterator b = begin; - for (; b < end && ::isspace(*b); ++b); - - begin = b; - for (; begin < end && !::isspace(*begin); ++begin); - - token.assign(b, begin); - } - else - { - token.resize(0); - } - - return token_type(token); -} - -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream& is) -{ - is >> token; - return token_type(token); -} - -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream::pos_type& pos) -{ - m_line_iss.seekg(pos); - // m_line_iss >> token; - if( !(m_line_iss >> token)) { - token.erase(token.begin(), token.end()); // token.clear(); - } - pos = m_line_iss.tellg(); - return token_type(token); -} - -CParser::FIND_TYPE CParser::find_option(const std::string& item, int *n, const std::vector& list, bool exact) -{ - std::string token(item); - std::transform(token.begin(), token.end(), token.begin(), tolower); - for (unsigned int i = 0; i < list.size(); i++) - { - if (exact == true) - { - if (list[i].compare(token) == 0) - { - *n = i; - return FT_OK; - } - } - else - { - if(list[i].find(token) == 0) - { - *n = i; - return FT_OK; - } - } - } - - *n = -1; - return FT_ERROR; -} - -// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) -// OPTION_TYPE CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) -int CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) -{ - // - // Read a line and check for options - // - int j; - int /* opt_l, */ opt; - //char *opt_ptr; - std::string::iterator opt_ptr; - - // char option[MAX_LENGTH]; - std::string option; - - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, false); - if (lt == LT_EOF) - { - j = OPTION_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPTION_KEYWORD; - } - else if (lt == LT_OPTION) - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) - { - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - next_char = opt_ptr; - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); - - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; - - j = OPTION_ERROR; - next_char = m_line.begin(); - } - } - else - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_char = opt_ptr; - } - else - { - j = OPTION_DEFAULT; - next_char = m_line.begin(); - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - std::cout << "\t" << m_line_save << "\n"; - } - } - } - return (j); -} - -int CParser::get_option(const std::vector& opt_list, std::istream::pos_type& next_pos) -{ - // - // Read a line and check for options - // - int j; - int opt; - std::istream::pos_type pos_ptr; - std::string option; - - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, false); - if (lt == LT_EOF) - { - j = OPTION_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPTION_KEYWORD; - } - else if (lt == LT_OPTION) - { - std::string::iterator opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) - { - // replace -option with option - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - - pos_ptr = 0; - copy_token(option, pos_ptr); - next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - error_msg("Unknown option.", OT_CONTINUE); - error_msg(m_line_save.c_str(), OT_CONTINUE); - incr_input_error(); - j = OPTION_ERROR; - next_pos = pos_ptr; - } - } - else - { - pos_ptr = 0; - copy_token(option, pos_ptr); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_pos = pos_ptr; - } - else - { - j = OPTION_DEFAULT; - next_pos = 0; - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - return (j); -} - -int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) -{ - m_error_stream << "ERROR: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "ERROR: " << err_str << "\n"; - m_output_stream.flush(); - - if (ot == OT_STOP) - { - exit(1); - } - return 0; -} - -int CParser::warning_msg(const char *err_str) -{ - m_error_stream << "WARNING: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "WARNING: " << err_str << "\n"; - m_output_stream.flush(); - - return 0; -} - -CParser::STATUS_TYPE CParser::get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element) -{ - element.erase(element.begin(), element.end()); // element.clear(); - - if (begin == end) { - error_msg("Empty string in get_elt. Expected an element name.", OT_CONTINUE); - return ERROR; - } - - // - // Load name into char array element - // - char c = *begin; - ++begin; - element.insert(element.end(), c); // element.push_back(c); - if (c == '[') { - while ( (c = *begin) != ']' ) { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if ( (c = *begin) == ']' ) { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - break; - } else if (begin == end) { - error_msg("No ending bracket (]) for element name", OT_CONTINUE); - incr_input_error(); - return ERROR; - } - } - while (::islower(c = *begin) || c == '_') { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) break; - } - } else { - while (::islower(c = *begin) || c == '_') { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) break; - } - } - return OK; -} - -CParser::STATUS_TYPE CParser::parse_couple(std::string& token) -{ - // Parse couple puts redox couples in standard form - // "+" is removed and couples are rewritten in sort - // order. - - if (utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) { - utilities::str_tolower(token); - return OK; - } - - while ( utilities::replace("+", "", token) ); - - std::string::iterator ptr = token.begin(); - std::string elt1; - get_elt(ptr, token.end(), elt1); - - if (*ptr != '(') { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " << - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return ERROR; - } - - int paren_count = 1; - std::string paren1 = "("; - while ( ptr != token.end() ) { - ++ptr; - if (*ptr == '/' || ptr == token.end()) { - std::ostringstream err_msg; - err_msg << "End of line or ""/"" encountered before end of parentheses, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return ERROR; - } - paren1.insert(paren1.end(), *ptr); // element.push_back(c); - if (*ptr == '(') ++paren_count; - if (*ptr == ')') --paren_count; - if (paren_count == 0) break; - } - - ++ptr; - if (ptr == token.end() || *ptr != '/') { - std::ostringstream err_msg; - err_msg << " ""/"" must follow parentheses " << - "ending first half of redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return ERROR; - } - ++ptr; - std::string elt2; - get_elt(ptr, token.end(), elt2); - if (elt1.compare(elt2) != 0) { - std::ostringstream err_msg; - err_msg << "Redox couple must be two redox states " << - "of the same element, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return ERROR; - } - if (*ptr != '(') { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return ERROR; - } - std::string paren2 = "("; - paren_count = 1; - - while ( ptr != token.end() ) { - ++ptr; - if (*ptr == '/' || ptr == token.end()) { - std::ostringstream err_msg; - err_msg << "End of line or ""/"" encountered before end of parentheses, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return ERROR; - } - paren2.insert(paren2.end(), *ptr); // element.push_back(c); - if (*ptr == '(') ++paren_count; - if (*ptr == ')') --paren_count; - if (paren_count == 0) break; - } - if (paren1.compare(paren2) < 0) { - token = elt1 + paren1 + std::string("/") + elt2 + paren2; - } else if (paren1.compare(paren2) > 0) { - token = elt2 + paren2 + std::string("/") + elt1 + paren1; - } else { - std::ostringstream err_msg; - err_msg << "Both parts of redox couple are the same, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return ERROR; - } - return OK; -} diff --git a/classes/Parser.h b/classes/Parser.h deleted file mode 100644 index 71281780..00000000 --- a/classes/Parser.h +++ /dev/null @@ -1,196 +0,0 @@ -#if !defined(PARSER_H_INCLUDED) -#define PARSER_H_INCLUDED - -#include // std::string -#include // std::vector -#include // std::istringstream std::ostringstream -#include // std::ostream -#include // std::istream - -class CParser -{ -public: - CParser(std::istream& input); - CParser(std::istream& input, std::ostream& output); - CParser(std::istream& input, std::ostream& output, std::ostream& error); - - virtual ~CParser(); - - enum LINE_TYPE { - LT_EOF = -1, - LT_OK = 1, - LT_EMPTY = 2, - LT_KEYWORD = 3, - LT_OPTION = 8 - }; - - enum TOKEN_TYPE { - TT_EMPTY = 2, - TT_UPPER = 4, - TT_LOWER = 5, - TT_DIGIT = 6, - TT_UNKNOWN = 7 - }; - - enum FIND_TYPE { - FT_OK = 0, - FT_ERROR = 1 - }; - - enum KEY_TYPE { - KT_NONE = -1, - KT_END = 0, - KT_EOF = 1, - KT_SOLUTION = 4 - }; - - enum OPTION_TYPE { - OPTION_DEFAULT = -4, - OPTION_ERROR = -3, - OPTION_KEYWORD = -2, - OPTION_EOF = -1 - }; - - enum ONERROR_TYPE { - OT_CONTINUE = 0, - OT_STOP = 1, - }; - - enum STATUS_TYPE { - ERROR = 0, - OK = 1 - }; - - /** - Function gets a new line and checks for empty, eof, and keywords. - - Arguments: - string Input, character string used in printing error message - allow_empty Input, True or false, if a blank line is accepable - if false, another line is read - allow_eof Input, True or false, if EOF is acceptable - allow_keyword Input, True or false, if a keyword is acceptable - - Returns: - LT_EMPTY if empty line read and allow_empty == true - LT_KEYWORD if line begins with keyword - LT_EOF if eof and allow_eof == true - LT_OK otherwise - LT_OPTION if line begins with -[alpha] - - Terminates if EOF and allow_eof == false. - */ - LINE_TYPE check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print); - - /** - Read a line from input file put in "line". - Copy of input line is stored in "line_save". - Characters after # are discarded in line but retained in "line_save" - - Arguments: - None - Returns: - LT_EMPTY, - LT_EOF, - LT_KEYWORD, - LT_OK, - LT_OPTION - */ - LINE_TYPE get_line(); - - // bool check_key(const std::string::iterator ptr); - bool check_key(std::string::iterator begin, std::string::iterator end); - - STATUS_TYPE check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, - const std::string& default_units, bool print); - - - KEY_TYPE next_keyword()const { return m_next_keyword; } - int get_option(const std::vector& opt_list, std::string::iterator& next_char); - int get_option(const std::vector& opt_list, std::istream::pos_type& next_pos); - - - std::string& line() {return m_line;} - std::istringstream& get_iss() {return m_line_iss;} - int incr_input_error() {return ++m_input_error;} - std::ostream& get_output() {return m_output_stream;} - int get_input_error() {return m_input_error;} - - - /** - Copies from begin to token until first space is encountered. - - Arguments: - token output, the token - begin input, begin iterator - end input, end iterator - - Returns: - TT_EMPTY - TT_UPPER - TT_LOWER - TT_DIGIT - TT_UNKNOWN - */ - static TOKEN_TYPE copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end); - static TOKEN_TYPE token_type(const std::string& token); - static TOKEN_TYPE copy_token(std::string& token, std::istream& is); - TOKEN_TYPE copy_token(std::string& token, std::istream::pos_type& pos); - CParser::TOKEN_TYPE peek_token(); - - /** - Function reads an element name out of the equation string. - An element name is composed of a capital letter followed by any number - of lower case characters. - - Arguments: - begin input, points to position in the equation to begin - output, points to next character of equation after - element name. - end input, points to last position in the equation - element input pointer to place to return element character string - */ - STATUS_TYPE get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element); - - - /** - Compares a string value to match beginning letters of a list of options - - Arguments: - item entry: pointer to string to compare - n exit: item in list that was matched - list entry: pointer to list of character values, assumed to - be lower case - count_list entry: number of character values in list - - Returns: - OK item matched - ERROR item not matched - n -1 item not matched - i position of match in list - */ - static FIND_TYPE find_option(const std::string& item, int *n, const std::vector& list, bool exact); - - - int error_msg(const std::ostringstream& err_str, ONERROR_TYPE stop) {return error_msg(err_str.str().c_str(), stop);} - int error_msg(const char *err_str, ONERROR_TYPE stop); - int warning_msg(const char *err_str); - - - STATUS_TYPE parse_couple(std::string& token); - -protected: - LINE_TYPE get_logical_line(); - -private: - std::istream& m_input_stream; - std::ostream& m_output_stream; - std::ostream& m_error_stream; - int m_input_error; - KEY_TYPE m_next_keyword; - std::string m_line; - std::string m_line_save; - std::istringstream m_line_iss; -}; - -#endif // PARSER_H_INCLUDED diff --git a/classes/Pe_Data.cxx b/classes/Pe_Data.cxx deleted file mode 100644 index 1109971d..00000000 --- a/classes/Pe_Data.cxx +++ /dev/null @@ -1,45 +0,0 @@ -#include "Pe_Data.h" -#include "Utilities.h" -#include // std::ostream - -CPe_Data::CPe_Data() -: name("") -{ -} - -CPe_Data::CPe_Data(const std::string& name) -: name(name) -{ -} - -CPe_Data::~CPe_Data() -{ -} - -int CPe_Data::store(std::vector& vec_pe_data, const std::string& token) -{ - unsigned int i = 0; - unsigned int size = vec_pe_data.size(); - for (; i < size; ++i) { - if (vec_pe_data[i].name.compare(token) == 0) - return i; - } - vec_pe_data.push_back(token); - return i; -} - -std::vector CPe_Data::alloc() -{ - std::vector vec; - vec.push_back(CPe_Data("pe")); - // TODO: see pe_data_alloc - return vec; -} - -void CPe_Data::dump_xml(std::ostream& os, unsigned int indent)const -{ - unsigned int i; - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "" << this->name << "\n"; -} - diff --git a/classes/Pe_Data.h b/classes/Pe_Data.h deleted file mode 100644 index 263709ea..00000000 --- a/classes/Pe_Data.h +++ /dev/null @@ -1,27 +0,0 @@ -#if !defined(PE_DATA_H_INCLUDED) -#define PE_DATA_H_INCLUDED - -#include -#include - -class CPe_Data -{ -public: - CPe_Data(); - CPe_Data(const std::string& name); - - ~CPe_Data(); - - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - - std::string get_name()const {return this->name;}; - void set_name(std::string name) {this->name = name;}; - - static int store(std::vector& vec, const std::string& token); - static std::vector CPe_Data::alloc(); - -private: - std::string name; -}; - -#endif // PE_DATA_H_INCLUDED diff --git a/classes/Solution.cxx b/classes/Solution.cxx deleted file mode 100644 index 429168d6..00000000 --- a/classes/Solution.cxx +++ /dev/null @@ -1,312 +0,0 @@ -// Solution.cxx: implementation of the CSolutionxx class. -// -////////////////////////////////////////////////////////////////////// - -#include "Solution.h" - -#include // assert -#include // std::sort - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -//static std::map ss_map; -//std::map& CSolution::s_map = ss_map; - -CSolution::CSolution() -: CNumKeyword() -, units("mMol/kgw") -, pe(CPe_Data::alloc()) -{ - ph = 7.0; - tc = 25.0; - density = 1.0; - - solution_pe = 4.0; - mu = 1e-7; - ah2o = 1.0; - mass_water = 1.0; - default_pe = -1; -} - -CSolution::~CSolution() -{ -} -#ifdef SKIP -CSolution& CSolution::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - CSolution numkey; - - // Read solution number and description - numkey.read_number_description(parser); - - // Malloc space for solution data - //// g_solution_map[numkey.n_user()] = numkey; - s_map[numkey.n_user()] = numkey; - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - CSolution& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = CPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - CConc conc; - if (conc.read(parser, sol) == CConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - CConc conc; - if (conc.read(parser, sol) == CConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.solution_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - CIsotope isotope; - if (isotope.read(parser) == CIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - CConc conc; - if (conc.read(parser, sol) == CConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif -void CSolution::dump_xml(std::ostream& os, unsigned int indent)const -{ - unsigned int i; - - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "\n"; - - CNumKeyword::dump_xml(os, indent); - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_tc() << "" << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_ph() << "" << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_solution_pe() << "" << "\n"; - - assert(this->pe.size() > 0); - assert(this->default_pe >= 0); - assert(this->pe.size() > (unsigned int) this->default_pe); - this->pe[this->default_pe].dump_xml(os, indent + 1); - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_units() << "" << "\n"; - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_density() << "" << "\n"; - - // foreach conc - if (!this->totals.empty()) - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - - std::vector::const_iterator iter = this->totals.begin(); - for(; iter != this->totals.end(); ++iter) - { - (*iter).dump_xml(*this, os, indent + 2); - } - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - } - - // foreach isotope - if (!this->isotopes.empty()) - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - - std::list::const_iterator iter = this->isotopes.begin(); - for(; iter != this->isotopes.end(); ++iter) - { - (*iter).dump_xml(os, indent + 2); - } - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - } - - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_mass_water() << "" << "\n"; - - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "" << "\n"; -} - - - - - - - - - - - - - - - diff --git a/classes/Solution.h b/classes/Solution.h deleted file mode 100644 index 012977b9..00000000 --- a/classes/Solution.h +++ /dev/null @@ -1,72 +0,0 @@ -#if !defined(SOLUTION_H_INCLUDED) -#define SOLUTION_H_INCLUDED - -#include "NumKeyword.h" -#include "Parser.h" -#include "Conc.h" -#include "Isotope.h" -#include "Pe_Data.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector - - -class CSolution : public CNumKeyword -{ -public: - CSolution(); - ~CSolution(); - - static CSolution& read(CParser& parser); - - void add(CConc conc) { this->totals.push_back(conc); } - void add(CIsotope isotope) { this->isotopes.push_back(isotope); } - - double get_ph()const {return this->ph;} - void set_ph(double pH) {this->ph = pH;} - - double get_solution_pe()const {return this->solution_pe;} - void set_solution_pe(double solution_pe) {this->solution_pe = solution_pe;} - - double get_tc()const {return this->tc;} - void set_tc(double tc) {this->tc = tc;} - - double get_density()const {return this->density;} - void set_density(double density) {this->density = density;} - - std::string get_units()const {return this->units;} - void set_units(std::string units) {this->units = units;} - - std::string get_redox()const {return this->pe[this->default_pe].get_name();} - - long double get_mass_water()const {return this->mass_water;}; - void set_mass_water(long double mass_water) {this->mass_water = mass_water;}; - - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - -protected: - friend class CConc; // for this->pe access - double ph; - double tc; - double solution_pe; - double mu; - double ah2o; - double density; - long double mass_water; - std::string units; - - - std::vector totals; /// std::set m_totals; ////std::list m_totals; - std::vector pe; - int default_pe; - - std::list isotopes; - -public: - static std::map& map; - -}; - -#endif // !defined(SOLUTION_H_INCLUDED) diff --git a/classes/TestCIsotope.cxx b/classes/TestCIsotope.cxx deleted file mode 100644 index 27f0828e..00000000 --- a/classes/TestCIsotope.cxx +++ /dev/null @@ -1,164 +0,0 @@ -#include "TestCIsotope.h" -#include "Parser.h" -#include "utilities.h" - -TestCIsotope::TestCIsotope() -{ -} - -TestCIsotope::~TestCIsotope() -{ -} - -void TestCIsotope::test_read_1() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("-isotope"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected isotope name to begin with an isotopic number.\n") == 0); -} - -void TestCIsotope::test_read_2() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("-isotope C"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected isotope name to begin with an isotopic number.\n") == 0); -} - -void TestCIsotope::test_read_3() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expecting element name.\nERROR: isotope 13\n") == 0); -} - -void TestCIsotope::test_read_4() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13C"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for isotope ratio.\n") == 0); -} - -void TestCIsotope::test_read_5() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13C -"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for isotope ratio.\n") == 0); -} - -void TestCIsotope::test_read_6() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13C -12."); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::OK); - CPPUNIT_ASSERT(oss_err.str().empty()); - - CPPUNIT_ASSERT(iso.get_name().compare("13C") == 0); - CPPUNIT_ASSERT(iso.get_ratio() == -12.0); - CPPUNIT_ASSERT(!iso.get_ratio_uncertainty_defined()); -} - -void TestCIsotope::test_read_7() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13C -12. a"); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: Expected numeric value for uncertainty in isotope ratio.\n") == 0); -} - -void TestCIsotope::test_read_8() -{ - CIsotope iso; - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream::pos_type next_pos; - std::vector opt_list; - - std::istringstream iss_in("isotope 13C -12. 1."); - - CParser parser(iss_in, oss_out, oss_err); - opt_list.push_back("isotope"); - - CPPUNIT_ASSERT(parser.get_option(opt_list, next_pos) == 0); - CPPUNIT_ASSERT(iso.read(parser) == CIsotope::OK); - CPPUNIT_ASSERT(oss_err.str().empty()); - - CPPUNIT_ASSERT(iso.get_name().compare("13C") == 0); - CPPUNIT_ASSERT(iso.get_ratio() == -12.0); - CPPUNIT_ASSERT(iso.get_ratio_uncertainty() == 1.0); - CPPUNIT_ASSERT(iso.get_ratio_uncertainty_defined()); -} diff --git a/classes/TestCIsotope.h b/classes/TestCIsotope.h deleted file mode 100644 index 97cdaebc..00000000 --- a/classes/TestCIsotope.h +++ /dev/null @@ -1,39 +0,0 @@ -#if !defined(TESTCISOTOPE_H_INCLUDED) -#define TESTCISOTOPE_H_INCLUDED - -#include "Isotope.h" -#include -#include - - -class TestCIsotope : - public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TestCIsotope ); - CPPUNIT_TEST( test_read_1 ); - CPPUNIT_TEST( test_read_2 ); - CPPUNIT_TEST( test_read_3 ); - CPPUNIT_TEST( test_read_4 ); - CPPUNIT_TEST( test_read_5 ); - CPPUNIT_TEST( test_read_6 ); - CPPUNIT_TEST( test_read_7 ); - CPPUNIT_TEST( test_read_8 ); - CPPUNIT_TEST_SUITE_END(); - -public: - TestCIsotope(void); - ~TestCIsotope(void); - -public: - // read - void test_read_1(); - void test_read_2(); - void test_read_3(); - void test_read_4(); - void test_read_5(); - void test_read_6(); - void test_read_7(); - void test_read_8(); -}; - -#endif // TESTCISOTOPE_H_INCLUDED diff --git a/classes/TestCParser.cxx b/classes/TestCParser.cxx deleted file mode 100644 index 4c3de473..00000000 --- a/classes/TestCParser.cxx +++ /dev/null @@ -1,192 +0,0 @@ -#include "TestCParser.h" -#include "Parser.h" - -TestCParser::TestCParser(void) -{ -} - -TestCParser::~TestCParser(void) -{ -} - -void TestCParser::testEmptyInput() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in(""); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); -} - -void TestCParser::testCommentOnlyInput() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("#this is a comment"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); -} - -void TestCParser::testLineContinuation() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("Line \\\n1"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); - CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); - CPPUNIT_ASSERT(parser.line().compare("") == 0); -} - -void TestCParser::testMultipleLineContinuation() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("Line \\\n\\\n\\\n\\\n1"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); - CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); - CPPUNIT_ASSERT(parser.line().compare("") == 0); -} - -void TestCParser::testLogicalLineSeparator() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("Line 1;Line 2"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); - CPPUNIT_ASSERT(parser.line().compare("Line 1") == 0); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_OK); - CPPUNIT_ASSERT(parser.line().compare("Line 2") == 0); - - CPPUNIT_ASSERT(parser.get_line() == CParser::LT_EOF); - CPPUNIT_ASSERT(parser.line().compare("") == 0); -} - -void TestCParser::test_check_line_1() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("SOLUTION"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_KEYWORD); - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); - CPPUNIT_ASSERT(oss_out.str().compare("\tSOLUTION\n") == 0); -} - -void TestCParser::test_check_line_2() -{ - std::ostringstream oss_out; - std::ostringstream oss_err; - std::istringstream iss_in("NOT_A_KEYWORD"); - - CParser parser(iss_in, oss_out, oss_err); - - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_OK); - CPPUNIT_ASSERT(parser.check_line("", false, true, true, true) == CParser::LT_EOF); -} - -void TestCParser::test_get_elt_1() -{ - std::istringstream iss_in; - std::ostringstream oss_out; - std::ostringstream oss_err; - - std::string token(""); - CParser parser(iss_in, oss_out, oss_err); - std::string::iterator begin = token.begin(); - std::string element; - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); - CPPUNIT_ASSERT(element.empty()); -} - -void TestCParser::test_get_elt_2() -{ - std::istringstream iss_in; - std::ostringstream oss_out; - std::ostringstream oss_err; - - std::string token("Ca"); - CParser parser(iss_in, oss_out, oss_err); - std::string::iterator begin = token.begin(); - std::string element; - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); - CPPUNIT_ASSERT(element.compare("Ca") == 0); - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); -} - -void TestCParser::test_get_elt_3() -{ - std::istringstream iss_in; - std::ostringstream oss_out; - std::ostringstream oss_err; - - std::string token("CaCO3"); - CParser parser(iss_in, oss_out, oss_err); - std::string::iterator begin = token.begin(); - std::string element; - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); - CPPUNIT_ASSERT(element.compare("Ca") == 0); - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); - CPPUNIT_ASSERT(element.compare("C") == 0); - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); - CPPUNIT_ASSERT(element.compare("O") == 0); -} - -void TestCParser::test_get_elt_4() -{ - std::istringstream iss_in; - std::ostringstream oss_out; - std::ostringstream oss_err; - - std::string token("[18O]"); - CParser parser(iss_in, oss_out, oss_err); - std::string::iterator begin = token.begin(); - std::string element; - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::OK); - CPPUNIT_ASSERT(element.compare("[18O]") == 0); - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); -} - -void TestCParser::test_get_elt_5() -{ - std::istringstream iss_in; - std::ostringstream oss_out; - std::ostringstream oss_err; - - std::string token("[18O"); - CParser parser(iss_in, oss_out, oss_err); - std::string::iterator begin = token.begin(); - std::string element; - - CPPUNIT_ASSERT(parser.get_elt(begin, token.end(), element) == CParser::ERROR); - CPPUNIT_ASSERT(oss_err.str().compare("ERROR: No ending bracket (]) for element name\n") == 0); -} diff --git a/classes/TestCParser.h b/classes/TestCParser.h deleted file mode 100644 index 315f0428..00000000 --- a/classes/TestCParser.h +++ /dev/null @@ -1,48 +0,0 @@ -#if !defined(TESTCPARSER_H_INCLUDED) -#define TESTCPARSER_H_INCLUDED - -#include -#include - -class TestCParser : - public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TestCParser ); - CPPUNIT_TEST( testEmptyInput ); - CPPUNIT_TEST( testCommentOnlyInput ); - CPPUNIT_TEST( testLineContinuation ); - CPPUNIT_TEST( testMultipleLineContinuation ); - CPPUNIT_TEST( testLogicalLineSeparator ); - CPPUNIT_TEST( test_check_line_1 ); - CPPUNIT_TEST( test_check_line_2 ); - CPPUNIT_TEST( test_get_elt_1 ); - CPPUNIT_TEST( test_get_elt_2 ); - CPPUNIT_TEST( test_get_elt_3 ); - CPPUNIT_TEST( test_get_elt_4 ); - CPPUNIT_TEST( test_get_elt_5 ); - CPPUNIT_TEST_SUITE_END(); - -public: - TestCParser(void); - ~TestCParser(void); - -public: - void testEmptyInput(); - void testCommentOnlyInput(); - void testLineContinuation(); - void testMultipleLineContinuation(); - void testLogicalLineSeparator(); - - // check_line - void test_check_line_1(); - void test_check_line_2(); - - // get_elt - void test_get_elt_1(); - void test_get_elt_2(); - void test_get_elt_3(); - void test_get_elt_4(); - void test_get_elt_5(); - -}; -#endif // TESTCPARSER_H_INCLUDED diff --git a/classes/TestCSolution.cxx b/classes/TestCSolution.cxx deleted file mode 100644 index cd30e0a8..00000000 --- a/classes/TestCSolution.cxx +++ /dev/null @@ -1,124 +0,0 @@ -#include "TestCSolution.h" -#include "Solution.h" -#include "Parser.h" -#include "utilities.h" -#include // std::cout std::cerr - -TestCSolution::TestCSolution() -{ -} - -TestCSolution::~TestCSolution() -{ -} - -CParser::LINE_TYPE read_input(CParser& parser) -{ - CParser::LINE_TYPE i; - while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) - { - if (i == CParser::LT_EOF) return CParser::LT_EOF; - } - - for (;;) { - switch(parser.next_keyword()) - { - case CParser::KT_END: - case CParser::KT_EOF: - case CParser::KT_NONE: - goto END_OF_SIMULATION_INPUT; - break; - - case CParser::KT_SOLUTION: - CSolution::read(parser); - break; - - default: - break; - } - } - -END_OF_SIMULATION_INPUT: - return CParser::LT_OK; -} - -void TestCSolution::test_read_ex1() -{ - CPPUNIT_ASSERT(CSolution::s_map.find(1) == CSolution::s_map.end()); - std::string input = - "SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979)\n" - " units ppm\n" - " pH 8.22\n" - " pe 8.451\n" - " density 1.023\n" - " temp 25.0\n" - " redox O(0)/O(-2)\n" - " Ca 412.3\n" - " Mg 1291.8\n" - " Na 10768.0\n" - " K 399.1\n" - " Fe 0.002\n" - " Mn 0.0002 pe\n" - " Si 4.28\n" - " Cl 19353.0\n" - " Alkalinity 141.682 as HCO3\n" - " S(6) 2712.0\n" - " N(5) 0.29 gfw 62.0\n" - " N(-3) 0.03 as NH4\n" - " U 3.3 ppb N(5)/N(-3)\n" - " O(0) 1.0 O2(g) -0.7\n" - ; - - // setup parser - std::istringstream iss_in(input); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); - for (int simulation = 1; ; ++simulation) { - if (read_input(parser) == CParser::LT_EOF) break; - } - CPPUNIT_ASSERT(parser.get_input_error() == 0); - CPPUNIT_ASSERT(CSolution::s_map.size() == 1); - CPPUNIT_ASSERT(CSolution::s_map.find(1) != CSolution::s_map.end()); - - CPPUNIT_ASSERT(CSolution::s_map[1].get_units().compare("mg/kgs") == 0); - CPPUNIT_ASSERT_DOUBLES_EQUAL(8.22, CSolution::s_map[1].get_ph(), 0.005); - CPPUNIT_ASSERT_DOUBLES_EQUAL(8.451, CSolution::s_map[1].get_solution_pe(), 0.0005); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.023, CSolution::s_map[1].get_density(), 0.0005); - CPPUNIT_ASSERT_DOUBLES_EQUAL(25.0, CSolution::s_map[1].get_tc(), 0.5); - CPPUNIT_ASSERT(CSolution::s_map[1].get_redox().compare("O(-2)/O(0)") == 0); - - // empty map for subsequent tests - CSolution::s_map.erase(CSolution::s_map.begin(), CSolution::s_map.end()); -} - -void TestCSolution::test_read_ex7() -{ - CPPUNIT_ASSERT(CSolution::s_map.find(1) == CSolution::s_map.end()); - std::string input = - "SOLUTION 1\n" - ; - - // setup parser - std::istringstream iss_in(input); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); - for (int simulation = 1; ; ++simulation) { - if (read_input(parser) == CParser::LT_EOF) break; - } - CPPUNIT_ASSERT(parser.get_input_error() == 0); - CPPUNIT_ASSERT(CSolution::s_map.size() == 1); - CPPUNIT_ASSERT(CSolution::s_map.find(1) != CSolution::s_map.end()); - - CPPUNIT_ASSERT(CSolution::s_map[1].get_units().compare("mMol/kgw") == 0); - - CPPUNIT_ASSERT_DOUBLES_EQUAL(7.0, CSolution::s_map[1].get_ph(), 0.05); - CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, CSolution::s_map[1].get_solution_pe(), 0.05); - CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, CSolution::s_map[1].get_density(), 0.05); - CPPUNIT_ASSERT_DOUBLES_EQUAL(25.0, CSolution::s_map[1].get_tc(), 0.5); - CPPUNIT_ASSERT(CSolution::s_map[1].get_redox().compare("pe") == 0); - - // empty map for subsequent tests - CSolution::s_map.erase(CSolution::s_map.begin(), CSolution::s_map.end()); -} diff --git a/classes/TestCSolution.h b/classes/TestCSolution.h deleted file mode 100644 index 8bb8f3cb..00000000 --- a/classes/TestCSolution.h +++ /dev/null @@ -1,24 +0,0 @@ -#if !defined(TESTCSOLUTION_H_INCLUDED) -#define TESTCSOLUTION_H_INCLUDED - -#include -#include - -class TestCSolution : - public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TestCSolution ); - CPPUNIT_TEST( test_read_ex1 ); - CPPUNIT_TEST( test_read_ex7 ); - CPPUNIT_TEST_SUITE_END(); - -public: - TestCSolution(void); - ~TestCSolution(void); - -public: - void test_read_ex1(); - void test_read_ex7(); - -}; -#endif // TESTCSOLUTION_H_INCLUDED diff --git a/classes/main.cxx b/classes/main.cxx deleted file mode 100644 index 81acf510..00000000 --- a/classes/main.cxx +++ /dev/null @@ -1,83 +0,0 @@ -#include // std::cout std::cerr -#include // std::string -#include // std::vector -#include // std::map - -#include "Parser.h" -#include "Solution.h" - -CParser::LINE_TYPE read_input(CParser& parser) -{ - CParser::LINE_TYPE i; - while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) - { - if (i == CParser::LT_EOF) return CParser::LT_EOF; - } - - for (;;) { - switch(parser.next_keyword()) - { - case CParser::KT_END: - case CParser::KT_EOF: - case CParser::KT_NONE: - goto END_OF_SIMULATION_INPUT; - break; - - case CParser::KT_SOLUTION: - CSolution::read(parser); - break; - - default: - break; - } - } - -END_OF_SIMULATION_INPUT: - return CParser::LT_OK; -} - -int main(void) -{ - std::string input = - "SOLUTION 25 Test solution number 25\n" - " temp 25.0 \n" - " pH 7.0 charge \n" - " pe 4.5 \n" - " redox O(-2)/O(0) \n" - " units ppm \n" - " density 1.02 \n" - " Ca 80. \n" - " S(6) 96. as SO4 \n" - " S(-2) 1. as S \n" - " N(5) N(3) 14. as N \n" - " O(0) 8.0 \n" - " C 61.0 as HCO3 CO2(g) -3.5 \n" - " Fe 55. ug/kgs as Fe S(6)/S(-2) Pyrite \n" - " -isotope 13C -12. 1. # permil PDB \n" - " -isotope 34S 15. 1.5 # permil CDT \n" - " -water 0.5 # kg \n" - ; - - // setup parser - std::istringstream iss_in(input); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); - for (int simulation = 1; ; ++simulation) { - if (read_input(parser) == CParser::LT_EOF) break; - } - - // dump solutions as xml string - std::ostringstream oss_tmp; - std::map::const_iterator it = CSolution::s_map.begin(); - for (; it != CSolution::s_map.end(); ++it) - { - (*it).second.dump_xml(oss_tmp); - } - oss_tmp << "\n"; - - // output xml string - std::cout << oss_tmp.str(); - - return 0; -} diff --git a/classes/test.cxx b/classes/test.cxx deleted file mode 100644 index 9046a76f..00000000 --- a/classes/test.cxx +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -#include "TestCParser.h" -#include "TestCIsotope.h" -#include "TestCSolution.h" - -int main(int argc, char **argv) -{ - CppUnit::TextUi::TestRunner runner; - - runner.addTest(TestCParser::suite()); - runner.addTest(TestCIsotope::suite()); - runner.addTest(TestCSolution::suite()); - - runner.setOutputter( - CppUnit::CompilerOutputter::defaultOutputter(&runner.result(), std::cout) - ); - - bool wasSucessful = runner.run("", false); - return wasSucessful; -} - diff --git a/classes/utilities.cxx b/classes/utilities.cxx deleted file mode 100644 index 0a13b46d..00000000 --- a/classes/utilities.cxx +++ /dev/null @@ -1,68 +0,0 @@ -#include // ::tolower -#include // ::tolower -#include //std::transform - -#include "utilities.h" -#include "Parser.h" - -//////////////////////////////////////////////////////////////////////////// -int utilities::strcmp_nocase_arg1(const char *str1, const char *str2) -//////////////////////////////////////////////////////////////////////////// -{ - // - // Compare two strings disregarding case - // - int c1, c2; - while ((c1 = ::tolower(*str1++)) == (c2 = *str2++)) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); -} - -//////////////////////////////////////////////////////////////////////////// -int utilities::strcmp_nocase(const char *str1, const char *str2) -//////////////////////////////////////////////////////////////////////////// -{ - // - // Compare two strings disregarding case - // - int c1, c2; - while ((c1 = ::tolower(*str1++)) == (c2 = ::tolower(*str2++))) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); -} - -//////////////////////////////////////////////////////////////////////////// -void utilities::str_tolower(std::string& str) -//////////////////////////////////////////////////////////////////////////// -{ - std::transform(str.begin(), str.end(), str.begin(), tolower); -} - - - -//////////////////////////////////////////////////////////////////////////// -bool utilities::replace(const char* str1, const char* str2, std::string& str) -//////////////////////////////////////////////////////////////////////////// -{ - std::string::size_type n = str.find(str1, 0); - if (n == std::string::npos) return false; - - str.replace(n, ::strlen(str1), str2); - return true; -} - -//////////////////////////////////////////////////////////////////////////// -void utilities::squeeze_white(std::string& s_l) -//////////////////////////////////////////////////////////////////////////// -{ - std::string str; - std::string::iterator beg = s_l.begin(); - std::string::iterator end = s_l.end(); - CParser::copy_token(str, beg, end); - s_l = str; -} - diff --git a/classes/utilities.h b/classes/utilities.h deleted file mode 100644 index f4580d9d..00000000 --- a/classes/utilities.h +++ /dev/null @@ -1,28 +0,0 @@ -#if !defined(UTILITIES_H_INCLUDED) -#define UTILITIES_H_INCLUDED - -#include - -namespace utilities { - - const char INDENT[] = " "; - - enum STATUS_TYPE { - OK = 0, - ERROR = 1 - }; - - STATUS_TYPE parse_couple(std::string& token); - - int strcmp_nocase(const char *str1, const char *str2); - - int strcmp_nocase_arg1(const char *str1, const char *str2); - - void str_tolower(std::string& str); - - bool replace(const char* str1, const char* str2, std::string& str); - - void squeeze_white(std::string& s_l); -} - -#endif // UTILITIES_H_INCLUDED diff --git a/cvdense.h b/cvdense.h deleted file mode 100644 index af4931c0..00000000 --- a/cvdense.h +++ /dev/null @@ -1,224 +0,0 @@ -/******************************************************************* - * * - * File : cvdense.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for the CVODE dense linear solver, * - * CVDENSE. * - * * - * Note: The type integertype must be large enough to store the * - * value of the linear system size N. * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidcvdense[] = "$Id$"; -#endif - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef _cvdense_h -#define _cvdense_h - - -#include -#include "cvode.h" -#include "sundialstypes.h" -#include "dense.h" -#include "nvector.h" - - -/****************************************************************** - * * - * CVDENSE solver statistics indices * - *----------------------------------------------------------------* - * The following enumeration gives a symbolic name to each * - * CVDENSE statistic. The symbolic names are used as indices into * - * the iopt and ropt arrays passed to CVodeMalloc. * - * The CVDENSE statistics are: * - * * - * iopt[DENSE_NJE] : number of Jacobian evaluations, i.e. of * - * calls made to the dense Jacobian routine * - * (default or user-supplied). * - * * - * iopt[DENSE_LRW] : size (in realtype words) of real workspace * - * matrices and vectors used by this solver. * - * * - * iopt[DENSE_LIW] : size (in integertype words) of integer * - * workspace vectors used by this solver. * - * * - ******************************************************************/ - -enum { DENSE_NJE=CVODE_IOPT_SIZE, DENSE_LRW, DENSE_LIW }; - - -/****************************************************************** - * * - * CVDENSE solver constants * - *----------------------------------------------------------------* - * CVD_MSBJ : maximum number of steps between dense Jacobian * - * evaluations * - * * - * CVD_DGMAX : maximum change in gamma between dense Jacobian * - * evaluations * - * * - ******************************************************************/ - -#define CVD_MSBJ 50 - -#define CVD_DGMAX RCONST(0.2) - - -/****************************************************************** - * * - * Type : CVDenseJacFn * - *----------------------------------------------------------------* - * A dense Jacobian approximation function Jac must have the * - * prototype given below. Its parameters are: * - * * - * N is the length of all vector arguments. * - * * - * J is the dense matrix (of type DenseMat) that will be loaded * - * by a CVDenseJacFn with an approximation to the Jacobian matrix * - * J = (df_i/dy_j) at the point (t,y). * - * J is preset to zero, so only the nonzero elements need to be * - * loaded. Two efficient ways to load J are: * - * * - * (1) (with macros - no explicit data structure references) * - * for (j=0; j < N; j++) { * - * col_j = DENSE_COL(J,j); * - * for (i=0; i < N; i++) { * - * generate J_ij = the (i,j)th Jacobian element * - * col_j[i] = J_ij; * - * } * - * } * - * * - * (2) (without macros - explicit data structure references) * - * for (j=0; j < N; j++) { * - * col_j = (J->data)[j]; * - * for (i=0; i < N; i++) { * - * generate J_ij = the (i,j)th Jacobian element * - * col_j[i] = J_ij; * - * } * - * } * - * * - * The DENSE_ELEM(A,i,j) macro is appropriate for use in small * - * problems in which efficiency of access is NOT a major concern. * - * * - * f is the right hand side function for the ODE problem. * - * * - * f_data is a pointer to user data to be passed to f, the same * - * as the F_data parameter passed to CVodeMalloc. * - * * - * t is the current value of the independent variable. * - * * - * y is the current value of the dependent variable vector, * - * namely the predicted value of y(t). * - * * - * fy is the vector f(t,y). * - * * - * ewt is the error weight vector. * - * * - * h is a tentative step size in t. * - * * - * uround is the machine unit roundoff. * - * * - * jac_data is a pointer to user data - the same as the jac_data * - * parameter passed to CVDense. * - * * - * nfePtr is a pointer to the memory location containing the * - * CVODE problem data nfe = number of calls to f. The Jacobian * - * routine should update this counter by adding on the number * - * of f calls made in order to approximate the Jacobian, if any. * - * For example, if the routine calls f a total of N times, then * - * the update is *nfePtr += N. * - * * - * vtemp1, vtemp2, and vtemp3 are pointers to memory allocated * - * for vectors of length N which can be used by a CVDenseJacFn * - * as temporary storage or work space. * - * * - ******************************************************************/ - -typedef void (*CVDenseJacFn)(integertype N, DenseMat J, RhsFn f, void *f_data, - realtype t, N_Vector y, N_Vector fy, N_Vector ewt, - realtype h, realtype uround, void *jac_data, - long int *nfePtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3); - - -/****************************************************************** - * * - * Function : CVDense * - *----------------------------------------------------------------* - * A call to the CVDense function links the main CVODE integrator * - * with the CVDENSE linear solver. * - * * - * cvode_mem is the pointer to CVODE memory returned by * - * CVodeMalloc. * - * * - * djac is the dense Jacobian approximation routine to be used. * - * A user-supplied djac routine must be of type * - * CVDenseJacFn. Pass NULL for djac to use the default * - * difference quotient routine CVDenseDQJac supplied * - * with this solver. * - * * - * jac_data is a pointer to user data which is passed to the * - * djac routine every time it is called. * - * * - * The return values of CVDense are: * - * SUCCESS = 0 if successful * - * LMEM_FAIL = -1 if there was a memory allocation failure * - * * - * NOTE: The dense linear solver assumes a serial implementation * - * of the NVECTOR package. Therefore, CVDense will first * - * test for a compatible N_Vector internal representation * - * by checking (1) the machine environment ID tag and * - * (2) that the functions N_VMake, N_VDispose, N_VGetData, * - * and N_VSetData are implemented. * - * * - ******************************************************************/ - -int CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); - - -/****************************************************************** - * * - * Function : CVReInitDense * - *----------------------------------------------------------------* - * A call to the CVReInitDense function resets the link between * - * the main CVODE integrator and the CVDENSE linear solver. * - * After solving one problem using CVDENSE, call CVReInit and then* - * CVReInitDense to solve another problem of the same size, if * - * there is a change in the CVDense parameters djac or jac_data. * - * If there is no change in parameters, it is not necessary to * - * call either CVReInitDense or CVDense for the new problem. * - * * - * All arguments to CVReInitDense have the same names and meanings* - * as those of CVDense. The cvode_mem argument must be identical * - * to its value in the previous CVDense call. * - * * - * The return values of CVReInitDense are: * - * SUCCESS = 0 if successful, or * - * LMEM_FAIL = -1 if the cvode_mem argument is NULL * - * * - * NOTE: CVReInitDense performs the same compatibility tests as * - * CVDense. * - * * - ******************************************************************/ - -int CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); - - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/cvode.h b/cvode.h deleted file mode 100644 index 0a81b5bd..00000000 --- a/cvode.h +++ /dev/null @@ -1,882 +0,0 @@ -/******************************************************************* - * * - * File : cvode.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban * - * and Dan Shumaker @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the interface file for the main CVODE integrator. * - * * - *******************************************************************/ -#ifdef PHREEQC_IDENT -static char const svnidcvode[] = "$Id$"; -#endif - - -#ifdef __cplusplus /* wrapper to enable C++ usage */ -extern "C" { -#endif - -#ifndef _cvode_h -#define _cvode_h - - -#include -#include "sundialstypes.h" -#include "nvector.h" - -/****************************************************************** - * * - * CVODE is used to solve numerically the ordinary initial value * - * problem : * - * * - * y' = f(t,y), * - * y(t0) = y0, * - * * - * where t0, y0 in R^N, and f: R x R^N -> R^N are given. * - * * - ******************************************************************/ - - -/****************************************************************** - * * - * Enumerations for inputs to CVodeMalloc, CVReInit, and CVode. * - *----------------------------------------------------------------* - * Symbolic constants for the lmm, iter, and itol input * - * parameters to CVodeMalloc and CVReInit, as well as the input * - * parameter itask to CVode, are given below. * - * * - * lmm : The user of the CVODE package specifies whether to use * - * the ADAMS or BDF (backward differentiation formula) * - * linear multistep method. The BDF method is recommended * - * for stiff problems, and the ADAMS method is recommended * - * for nonstiff problems. * - * * - * iter : At each internal time step, a nonlinear equation must * - * be solved. The user can specify either FUNCTIONAL * - * iteration, which does not require linear algebra, or a * - * NEWTON iteration, which requires the solution of linear * - * systems. In the NEWTON case, the user also specifies a * - * CVODE linear solver. NEWTON is recommended in case of * - * stiff problems. * - * * - * itol : This parameter specifies the relative and absolute * - * tolerance types to be used. The SS tolerance type means * - * a scalar relative and absolute tolerance, while the SV * - * tolerance type means a scalar relative tolerance and a * - * vector absolute tolerance (a potentially different * - * absolute tolerance for each vector component). * - * * - * itask : The itask input parameter to CVode indicates the job * - * of the solver for the next user step. The NORMAL * - * itask is to have the solver take internal steps until * - * it has reached or just passed the user specified tout * - * parameter. The solver then interpolates in order to * - * return an approximate value of y(tout). The ONE_STEP * - * option tells the solver to just take one internal step * - * and return the solution at the point reached by that * - * step. * - * * - ******************************************************************/ - -enum { ADAMS, BDF }; /* lmm */ - -enum { FUNCTIONAL, NEWTON }; /* iter */ - -enum { SS, SV }; /* itol */ - -enum { NORMAL, ONE_STEP }; /* itask */ - - -/****************************************************************** - * * - * Type : RhsFn * - *----------------------------------------------------------------* - * The f function which defines the right hand side of the ODE * - * system y' = f(t,y) must have type RhsFn. * - * f takes as input the problem size N, the independent variable * - * value t, and the dependent variable vector y. It stores the * - * result of f(t,y) in the vector ydot. The y and ydot arguments * - * are of type N_Vector. * - * (Allocation of memory for ydot is handled within CVODE.) * - * The f_data parameter is the same as the f_data * - * parameter passed by the user to the CVodeMalloc routine. This * - * user-supplied pointer is passed to the user's f function * - * every time it is called. * - * A RhsFn f does not have a return value. * - * * - ******************************************************************/ - -typedef void (*RhsFn)(integertype N, realtype t, N_Vector y, - N_Vector ydot, void *f_data); - - -/****************************************************************** - * * - * Function : CVodeMalloc * - *----------------------------------------------------------------* - * CVodeMalloc allocates and initializes memory for a problem to * - * to be solved by CVODE. * - * * - * N is the number of equations in the ODE system. * - * * - * f is the right hand side function in y' = f(t,y). * - * * - * t0 is the initial value of t. * - * * - * y0 is the initial condition vector y(t0). * - * * - * lmm is the type of linear multistep method to be used. * - * The legal values are ADAMS and BDF (see previous * - * description). * - * * - * iter is the type of iteration used to solve the nonlinear * - * system that arises during each internal time step. * - * The legal values are FUNCTIONAL and NEWTON. * - * * - * itol is the type of tolerances to be used. * - * The legal values are: * - * SS (scalar relative and absolute tolerances), * - * SV (scalar relative tolerance and vector * - * absolute tolerance). * - * * - * reltol is a pointer to the relative tolerance scalar. * - * * - * abstol is a pointer to the absolute tolerance scalar or * - * an N_Vector of absolute tolerances. * - * * - * The parameters itol, reltol, and abstol define a vector of * - * error weights, ewt, with components * - * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (if itol = SS), or * - * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (if itol = SV). * - * This vector is used in all error and convergence tests, which * - * use a weighted RMS norm on all error-like vectors v: * - * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ). * - * * - * f_data is a pointer to user data that will be passed to the * - * user's f function every time f is called. * - * * - * errfp is the file pointer for an error file where all CVODE * - * warning and error messages will be written. This * - * parameter can be stdout (standard output), stderr * - * (standard error), a file pointer (corresponding to * - * a user error file opened for writing) returned by * - * fopen, or NULL. If the user passes NULL, then all * - * messages will be written to standard output. * - * * - * optIn is a flag indicating whether there are any optional * - * inputs from the user in the arrays iopt and ropt. * - * Pass FALSE to indicate no optional inputs and TRUE * - * to indicate that optional inputs are present. * - * * - * iopt is the user-allocated array (of size OPT_SIZE given * - * later) that will hold optional integer inputs and * - * outputs. The user can pass NULL if he/she does not * - * wish to use optional integer inputs or outputs. * - * If optIn is TRUE, the user should preset to 0 those * - * locations for which default values are to be used. * - * * - * ropt is the user-allocated array (of size OPT_SIZE given * - * later) that will hold optional real inputs and * - * outputs. The user can pass NULL if he/she does not * - * wish to use optional real inputs or outputs. * - * If optIn is TRUE, the user should preset to 0.0 the * - * locations for which default values are to be used. * - * * - * machEnv is a pointer to machine environment-specific * - * information. * - * * - * Note: The tolerance values may be changed in between calls to * - * CVode for the same problem. These values refer to * - * (*reltol) and either (*abstol), for a scalar absolute * - * tolerance, or the components of abstol, for a vector * - * absolute tolerance. * - * * - * If successful, CVodeMalloc returns a pointer to initialized * - * problem memory. This pointer should be passed to CVode. If * - * an initialization error occurs, CVodeMalloc prints an error * - * message to the file specified by errfp and returns NULL. * - * * - ******************************************************************/ - - -void *CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, - int lmm, int iter, int itol, realtype *reltol, - void *abstol, void *f_data, FILE *errfp, - booleantype optIn, long int iopt[], realtype ropt[], - M_Env machEnv); - - -/****************************************************************** - * * - * Function : CVReInit * - *----------------------------------------------------------------* - * CVReInit re-initializes CVode for the solution of a problem, * - * where a prior call to CVodeMalloc has been made with the same * - * problem size N. CVReInit performs the same input checking * - * and initializations that CVodeMalloc does (except for N). * - * But it does no memory allocation, assuming that the existing * - * internal memory is sufficient for the new problem. * - * * - * The use of CVReInit requires that the maximum method order, * - * maxord, is no larger for the new problem than for the problem * - * specified in the last call to CVodeMalloc. This condition is * - * automatically fulfilled if the multistep method parameter lmm * - * is unchanged (or changed from ADAMS to BDF) and the default * - * value for maxord is specified. * - * * - * If iter = NEWTON, then following the call to CVReInit, a call * - * to the linear solver specification routine is necessary if a * - * different linear solver is chosen, but may not be otherwise. * - * If the same linear solver is chosen, and there are no changes * - * in the input parameters to the specification routine, then no * - * call to that routine is needed. * - * If there are changes in parameters, but they do not increase * - * the linear solver memory size, then a call to the corresponding* - * CVReInit routine must made to communicate the new * - * parameters; in that case the linear solver memory is reused. * - * If the parameter changes do increase the linear solver memory * - * size, then the main linear solver specification routine must be* - * called. See the linear solver documentation for full details. * - * * - * The first argument to CVReInit is: * - * * - * cvode_mem = pointer to CVODE memory returned by CVodeMalloc. * - * * - * All the remaining arguments to CVReInit have names and * - * meanings identical to those of CVodeMalloc. Note that the * - * problem size N is not passed as an argument to CVReInit, * - * as that is assumed to be unchanged since the CVodeMalloc call. * - * * - * The return value of CVReInit is equal to SUCCESS = 0 if there * - * were no errors; otherwise it is a negative int equal to: * - * CVREI_NO_MEM indicating cvode_mem was NULL, or * - * CVREI_ILL_INPUT indicating an input argument was illegal * - * (including an attempt to increase maxord). * - * In case of an error return, an error message is also printed. * - * * - * Note: the reported workspace sizes iopt[LENRW] and iopt[LENIW] * - * are left unchanged from the values computed by CVodeMalloc, and* - * so may be larger than would be computed for the new problem. * - ******************************************************************/ - -int CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, - int lmm, int iter, int itol, realtype *reltol, - void *abstol, void *f_data, FILE *errfp, - booleantype optIn, long int iopt[], - realtype ropt[], M_Env machEnv); - - -/* CVReInit return values: */ - -/* SUCCESS = 0 (Defined under CVode return values, but listed - here also for completeness) */ -enum {CVREI_NO_MEM = -1, CVREI_ILL_INPUT = -2}; - - -/****************************************************************** - * * - * Function : CVode * - *----------------------------------------------------------------* - * CVode integrates the ODE over an interval in t. * - * If itask is NORMAL, then the solver integrates from its * - * current internal t value to a point at or beyond tout, then * - * interpolates to t = tout and returns y(tout) in the user- * - * allocated vector yout. If itask is ONE_STEP, then the solver * - * takes one internal time step and returns in yout the value of * - * y at the new internal time. In this case, tout is used only * - * during the first call to CVode to determine the direction of * - * integration and the rough scale of the problem. In either * - * case, the time reached by the solver is placed in (*t). The * - * user is responsible for allocating the memory for this value. * - * * - * cvode_mem is the pointer to CVODE memory returned by * - * CVodeMalloc. * - * * - * tout is the next time at which a computed solution is desired * - * * - * yout is the computed solution vector. In NORMAL mode with no * - * errors, yout=y(tout). * - * * - * t is a pointer to a real location. CVode sets (*t) to the * - * time reached by the solver and returns yout=y(*t). * - * * - * itask is either NORMAL or ONE_STEP mode. These two modes have * - * been described above. * - * * - * The return values for CVode are defined later in this file. * - * Here is a brief description of each return value: * - * * - * SUCCESS : CVode succeeded. * - * * - * CVODE_NO_MEM : The cvode_mem argument was NULL. * - * * - * ILL_INPUT : One of the inputs to CVode is illegal. This * - * includes the situation when a component of the * - * error weight vectors becomes < 0 during * - * internal time-stepping. The ILL_INPUT flag * - * will also be returned if the linear solver * - * routine CV--- (called by the user after * - * calling CVodeMalloc) failed to set one of the * - * linear solver-related fields in cvode_mem or * - * if the linear solver's init routine failed. In * - * any case, the user should see the printed * - * error message for more details. * - * * - * TOO_MUCH_WORK : The solver took mxstep internal steps but * - * could not reach tout. The default value for * - * mxstep is MXSTEP_DEFAULT = 500. * - * * - * TOO_MUCH_ACC : The solver could not satisfy the accuracy * - * demanded by the user for some internal step. * - * * - * ERR_FAILURE : Error test failures occurred too many times * - * (= MXNEF = 7) during one internal time step or * - * occurred with |h| = hmin. * - * * - * CONV_FAILURE : Convergence test failures occurred too many * - * times (= MXNCF = 10) during one internal time * - * step or occurred with |h| = hmin. * - * * - * SETUP_FAILURE : The linear solver's setup routine failed in an * - * unrecoverable manner. * - * * - * SOLVE_FAILURE : The linear solver's solve routine failed in an * - * unrecoverable manner. * - * * - ******************************************************************/ - - -int CVode(void *cvode_mem, realtype tout, N_Vector yout, - realtype *t, int itask); - - -/* CVode return values */ - -enum { SUCCESS=0, CVODE_NO_MEM=-1, ILL_INPUT=-2, TOO_MUCH_WORK=-3, - TOO_MUCH_ACC=-4, ERR_FAILURE=-5, CONV_FAILURE=-6, - SETUP_FAILURE=-7, SOLVE_FAILURE=-8 }; - - -/****************************************************************** - * * - * Function : CVodeDky * - *----------------------------------------------------------------* - * CVodeDky computes the kth derivative of the y function at * - * time t, where tn-hu <= t <= tn, tn denotes the current * - * internal time reached, and hu is the last internal step size * - * successfully used by the solver. The user may request * - * k=0, 1, ..., qu, where qu is the current order. The * - * derivative vector is returned in dky. This vector must be * - * allocated by the caller. It is only legal to call this * - * function after a successful return from CVode. * - * * - * cvode_mem is the pointer to CVODE memory returned by * - * CVodeMalloc. * - * * - * t is the time at which the kth derivative of y is evaluated. * - * The legal range for t is [tn-hu,tn] as described above. * - * * - * k is the order of the derivative of y to be computed. The * - * legal range for k is [0,qu] as described above. * - * * - * dky is the output derivative vector [(D_k)y](t). * - * * - * The return values for CVodeDky are defined later in this file. * - * Here is a brief description of each return value: * - * * - * OKAY : CVodeDky succeeded. * - * * - * BAD_K : k is not in the range 0, 1, ..., qu. * - * * - * BAD_T : t is not in the interval [tn-hu,tn]. * - * * - * BAD_DKY : The dky argument was NULL. * - * * - * DKY_NO_MEM : The cvode_mem argument was NULL. * - * * - ******************************************************************/ - - -int CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky); - - -/* CVodeDky return values */ - -enum { OKAY=0, BAD_K=-1, BAD_T=-2, BAD_DKY=-3, DKY_NO_MEM=-4 }; - - -/****************************************************************** - * * - * Function : CVodeFree * - *----------------------------------------------------------------* - * CVodeFree frees the problem memory cvode_mem allocated by * - * CVodeMalloc. Its only argument is the pointer cvode_mem * - * returned by CVodeMalloc. * - * * - ******************************************************************/ - -void CVodeFree(void *cvode_mem); - - -/****************************************************************** - * * - * Optional Inputs and Outputs * - *----------------------------------------------------------------* - * The user should declare two arrays for optional input and * - * output, an iopt array for optional integer input and output * - * and an ropt array for optional real input and output. The * - * size of both these arrays should be OPT_SIZE. * - * So the user's declaration should look like: * - * * - * long int iopt[OPT_SIZE]; * - * realtype ropt[OPT_SIZE]; * - * * - * The enumerations below the OPT_SIZE definition * - * are indices into the iopt and ropt arrays. Here is a brief * - * description of the contents of these positions: * - * * - * iopt[MAXORD] : maximum lmm order to be used by the solver. * - * Optional input. (Default = 12 for ADAMS, 5 for * - * BDF). * - * * - * iopt[MXSTEP] : maximum number of internal steps to be taken by * - * the solver in its attempt to reach tout. * - * Optional input. (Default = 500). * - * * - * iopt[MXHNIL] : maximum number of warning messages issued by the* - * solver that t + h = t on the next internal step.* - * A value of -1 means no such messages are issued.* - * Optional input. (Default = 10). * - * * - * iopt[NST] : cumulative number of internal steps taken by * - * the solver (total so far). Optional output. * - * * - * iopt[NFE] : number of calls to the user's f function. * - * Optional output. * - * * - * iopt[NSETUPS] : number of calls made to the linear solver's * - * setup routine. Optional output. * - * * - * iopt[NNI] : number of NEWTON iterations performed. * - * Optional output. * - * * - * iopt[NCFN] : number of nonlinear convergence failures * - * that have occurred. Optional output. * - * * - * iopt[NETF] : number of local error test failures that * - * have occurred. Optional output. * - * * - * iopt[QU] : order used during the last internal step. * - * Optional output. * - * * - * iopt[QCUR] : order to be used on the next internal step. * - * Optional output. * - * * - * iopt[LENRW] : size of required CVODE internal real work * - * space, in realtype words. Optional output. * - * * - * iopt[LENIW] : size of required CVODE internal integer work * - * space, in integertype words. Optional output. * - * * - * iopt[SLDET] : Flag to turn on/off stability limit detection * - * (1 = on, 0 = off). When BDF is used and order * - * is 3 or greater, CVsldet is call to detect * - * stability limit. If limit is detected, the * - * order is reduced. Optional input. * - * * - * iopt[NOR] : Number of order reductions due to * - * stability limit detection. * - * Optional output. * - * * - * ropt[H0] : initial step size. Optional input. * - * * - * ropt[HMAX] : maximum absolute value of step size allowed. * - * Optional input. (Default is infinity). * - * Note: If optIn = TRUE, the value of ropt[HMAX] * - * is examined on every call to CVode, and so can * - * be changed between calls. * - * * - * ropt[HMIN] : minimum absolute value of step size allowed. * - * Optional input. (Default is 0.0). * - * * - * ropt[HU] : step size for the last internal step. * - * Optional output. * - * * - * ropt[HCUR] : step size to be attempted on the next internal * - * step. Optional output. * - * * - * ropt[TCUR] : current internal time reached by the solver. * - * Optional output. * - * * - * ropt[TOLSF] : a suggested factor by which the user's * - * tolerances should be scaled when too much * - * accuracy has been requested for some internal * - * step. Optional output. * - * * - ******************************************************************/ - -/* iopt, ropt array sizes */ - -#define OPT_SIZE 40 - - -/* iopt and ropt offsets * - * The constants CVODE_IOPT_SIZE and CVODE_ROPT_SIZE are equal to * - * the number of integer and real optional inputs and outputs * - * actually accessed in cvode.c. The locations beyond these * - * values are used by the linear solvers. */ - -#define CVODE_IOPT_SIZE 15 -#define CVODE_ROPT_SIZE 7 - -/* iopt indices */ -enum { MAXORD, MXSTEP, MXHNIL, - NST, NFE, NSETUPS, NNI, NCFN, NETF, QU, QCUR, - LENRW, LENIW, SLDET, NOR}; - -/* ropt indices */ - -enum { H0, HMAX, HMIN, - HU, HCUR, TCUR, TOLSF }; - - -/* Basic CVODE constants */ - -#define ADAMS_Q_MAX 12 /* max value of q for lmm == ADAMS */ -#define BDF_Q_MAX 5 /* max value of q for lmm == BDF */ -#define Q_MAX ADAMS_Q_MAX /* max value of q for either lmm */ -#define L_MAX (Q_MAX+1) /* max value of L for either lmm */ -#define NUM_TESTS 5 /* number of error test quantities */ - - -/****************************************************************** - * * - * Types : struct CVodeMemRec, CVodeMem * - *----------------------------------------------------------------* - * The type CVodeMem is type pointer to struct CVodeMemRec. This * - * structure contains fields to keep track of problem state. * - * * - ******************************************************************/ - -typedef struct CVodeMemRec { - - realtype cv_uround; /* machine unit roundoff */ - - /* Problem Specification Data */ - - integertype cv_N; /* ODE system size */ - RhsFn cv_f; /* y' = f(t,y(t)) */ - void *cv_f_data; /* user pointer passed to f */ - int cv_lmm; /* lmm = ADAMS or BDF */ - int cv_iter; /* iter = FUNCTIONAL or NEWTON */ - int cv_itol; /* itol = SS or SV */ - realtype *cv_reltol; /* ptr to relative tolerance */ - void *cv_abstol; /* ptr to absolute tolerance */ - - /* Nordsieck History Array */ - - N_Vector cv_zn[L_MAX]; /* Nordsieck array, of size N x (q+1). */ - /* zn[j] is a vector of length N (j=0,...,q) */ - /* zn[j] = [1/factorial(j)] * h^j * (jth */ - /* derivative of the interpolating polynomial */ - - /* Vectors of length N */ - - N_Vector cv_ewt; /* error weight vector */ - N_Vector cv_y; /* y is used as temporary storage by the solver */ - /* The memory is provided by the user to CVode */ - /* where the vector is named yout. */ - N_Vector cv_acor; /* In the context of the solution of the */ - /* nonlinear equation, acor = y_n(m) - y_n(0). */ - /* On return, this vector is scaled to give */ - /* the estimated local error in y. */ - N_Vector cv_tempv; /* temporary storage vector */ - N_Vector cv_ftemp; /* temporary storage vector */ - - /* Step Data */ - - int cv_q; /* current order */ - int cv_qprime; /* order to be used on the next step */ - /* = q-1, q, or q+1 */ - int cv_qwait; /* number of internal steps to wait before */ - /* considering a change in q */ - int cv_L; /* L = q + 1 */ - - realtype cv_h; /* current step size */ - realtype cv_hprime; /* step size to be used on the next step */ - realtype cv_eta; /* eta = hprime / h */ - realtype cv_hscale; /* value of h used in zn */ - realtype cv_tn; /* current internal value of t */ - - realtype cv_tau[L_MAX+1]; /* array of previous q+1 successful step */ - /* sizes indexed from 1 to q+1 */ - realtype cv_tq[NUM_TESTS+1]; /* array of test quantities indexed from */ - /* 1 to NUM_TESTS(=5) */ - realtype cv_l[L_MAX]; /* coefficients of l(x) (degree q poly) */ - - realtype cv_rl1; /* 1 / l[1] */ - realtype cv_gamma; /* gamma = h * rl1 */ - realtype cv_gammap; /* gamma at the last setup call */ - realtype cv_gamrat; /* gamma / gammap */ - - realtype cv_crate; /* estimated corrector convergence rate */ - realtype cv_acnrm; /* | acor | wrms */ - int cv_mnewt; /* Newton iteration counter */ - - /* Limits */ - - int cv_qmax; /* q <= qmax */ - int cv_mxstep; /* maximum number of internal steps for one user call */ - int cv_maxcor; /* maximum number of corrector iterations for the */ - /* solution of the nonlinear equation */ - int cv_mxhnil; /* maximum number of warning messages issued to the */ - /* user that t + h == t for the next internal step */ - - realtype cv_hmin; /* |h| >= hmin */ - realtype cv_hmax_inv; /* |h| <= 1/hmax_inv */ - realtype cv_etamax; /* eta <= etamax */ - - /* Counters */ - - long int cv_nst; /* number of internal steps taken */ - long int cv_nfe; /* number of f calls */ - long int cv_ncfn; /* number of corrector convergence failures */ - long int cv_netf; /* number of error test failures */ - long int cv_nni; /* number of Newton iterations performed */ - long int cv_nsetups; /* number of setup calls */ - int cv_nhnil; /* number of messages issued to the user that */ - /* t + h == t for the next iternal step */ - long int cv_lrw; /* number of realtype words in CVODE work vectors */ - long int cv_liw; /* no. of integertype words in CVODE work vectors */ - long int cv_nscon; /* counter for STALD method */ - - realtype cv_etaqm1; /* ratio of new to old h for order q-1 */ - realtype cv_etaq; /* ratio of new to old h for order q */ - realtype cv_etaqp1; /* ratio of new to old h for order q+1 */ - realtype cv_ssdat[6][4]; /* scaled data array for STALD */ - - /* Linear Solver Data */ - - /* Linear Solver functions to be called */ - - int (*cv_linit)(struct CVodeMemRec *cv_mem); - - int (*cv_lsetup)(struct CVodeMemRec *cv_mem, int convfail, N_Vector ypred, - N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp1, - N_Vector vtemp2, N_Vector vtemp3); - - int (*cv_lsolve)(struct CVodeMemRec *cv_mem, N_Vector b, N_Vector ycur, - N_Vector fcur); - - void (*cv_lfree)(struct CVodeMemRec *cv_mem); - - /* Linear Solver specific memory */ - - void *cv_lmem; - - /* Saved Values */ - - int cv_qu; /* last successful q value used */ - long int cv_nstlp; /* step number of last setup call */ - realtype cv_hu; /* last successful h value used */ - realtype cv_saved_tq5; /* saved value of tq[5] */ - booleantype cv_jcur; /* Is the Jacobian info used by */ - /* linear solver current? */ - realtype cv_tolsf; /* tolerance scale factor */ - booleantype cv_setupNonNull; /* Does setup do something? */ - - /* Arrays for Optional Input and Optional Output */ - - booleantype cv_optIn; /* boolean input optIn */ - long int *cv_iopt; /* long int optional input, output */ - realtype *cv_ropt; /* real optional input, output */ - - /* Error File */ - - FILE *cv_errfp; /* CVODE error messages are sent to errfp */ - - /* Pointer to Machine Environment-Specific Information */ - - M_Env cv_machenv; - - /* Stability Limit Detection control flag */ - - booleantype cv_sldeton; /* Is Stability Limit Detection on */ - -} *CVodeMem; - - -/****************************************************************** - * * - * Communication between user and a CVODE Linear Solver * - *----------------------------------------------------------------* - * Return values of the linear solver specification routine. * - * The values of these are given in the enum statement below. * - * SUCCESS : The routine was successful. * - * * - * LMEM_FAIL : A memory allocation failed. * - * * - * LIN_ILL_INPUT: Some input was illegal (see message). * - * * - ******************************************************************/ - -/* SUCCESS = 0 (Defined under CVode return values, but listed - here also for completeness) */ -enum {LMEM_FAIL = -1, LIN_ILL_INPUT = -2}; - - -/****************************************************************** - * * - * Communication between cvode.c and a CVODE Linear Solver * - *----------------------------------------------------------------* - * (1) cv_linit return values * - * * - * LINIT_OK : The cv_linit routine succeeded. * - * * - * LINIT_ERR : The cv_linit routine failed. Each linear solver * - * init routine should print an appropriate error * - * message to (cv_mem->errfp). * - * * - * (2) convfail (input to cv_lsetup) * - * * - * NO_FAILURES : Either this is the first cv_setup call for this * - * step, or the local error test failed on the * - * previous attempt at this step (but the Newton * - * iteration converged). * - * * - * FAIL_BAD_J : This value is passed to cv_lsetup if * - * * - * (1) The previous Newton corrector iteration * - * did not converge and the linear solver's * - * setup routine indicated that its Jacobian- * - * related data is not current. * - * or * - * (2) During the previous Newton corrector * - * iteration, the linear solver's solve routine * - * failed in a recoverable manner and the * - * linear solver's setup routine indicated that * - * its Jacobian-related data is not current. * - * * - * FAIL_OTHER : During the current internal step try, the * - * previous Newton iteration failed to converge * - * even though the linear solver was using current * - * Jacobian-related data. * - * * - * (3) Parameter documentation, as well as a brief description * - * of purpose, for each CVODE linear solver routine to be * - * called in cvode.c is given below the constant declarations * - * that follow. * - * * - ******************************************************************/ - -/* cv_linit return values */ - -#define LINIT_OK 0 -#define LINIT_ERR -1 - -/* Constants for convfail (input to cv_lsetup) */ - -#define NO_FAILURES 0 -#define FAIL_BAD_J 1 -#define FAIL_OTHER 2 - - -/******************************************************************* - * * - * int (*cv_linit)(CVodeMem cv_mem); * - *-----------------------------------------------------------------* - * The purpose of cv_linit is to complete initializations for * - * specific linear solver, such as counters and statistics. * - * An LInitFn should return LINIT_OK (= 0) if it has successfully * - * initialized the CVODE linear solver and LINIT_ERR (= -1) * - * otherwise. These constants are defined above. If an error does * - * occur, an appropriate message should be sent to (cv_mem->errfp).* - * * - *******************************************************************/ - -/******************************************************************* - * * - * int (*cv_lsetup)(CVodeMem cv_mem, int convfail, N_Vector ypred, * - * N_Vector fpred, booleantype *jcurPtr, * - * N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); * - *-----------------------------------------------------------------* - * The job of cv_lsetup is to prepare the linear solver for * - * subsequent calls to cv_lsolve. It may re-compute Jacobian- * - * related data is it deems necessary. Its parameters are as * - * follows: * - * * - * cv_mem - problem memory pointer of type CVodeMem. See the big * - * typedef earlier in this file. * - * * - * convfail - a flag to indicate any problem that occurred during * - * the solution of the nonlinear equation on the * - * current time step for which the linear solver is * - * being used. This flag can be used to help decide * - * whether the Jacobian data kept by a CVODE linear * - * solver needs to be updated or not. * - * Its possible values have been documented above. * - * * - * ypred - the predicted y vector for the current CVODE internal * - * step. * - * * - * fpred - f(tn, ypred). * - * * - * jcurPtr - a pointer to a boolean to be filled in by cv_lsetup. * - * The function should set *jcurPtr=TRUE if its Jacobian * - * data is current after the call and should set * - * *jcurPtr=FALSE if its Jacobian data is not current. * - * Note: If cv_lsetup calls for re-evaluation of * - * Jacobian data (based on convfail and CVODE state * - * data), it should return *jcurPtr=TRUE unconditionally;* - * otherwise an infinite loop can result. * - * * - * vtemp1 - temporary N_Vector provided for use by cv_lsetup. * - * * - * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * - * * - * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * - * * - * The cv_lsetup routine should return 0 if successful, * - * a positive value for a recoverable error, and a negative value * - * for an unrecoverable error. * - * * - *******************************************************************/ - -/******************************************************************* - * * - * int (*cv_lsolve)(CVodeMem cv_mem, N_Vector b, N_Vector ycur, * - * N_Vector fcur); * - *-----------------------------------------------------------------* - * cv_lsolve must solve the linear equation P x = b, where * - * P is some approximation to (I - gamma J), J = (df/dy)(tn,ycur) * - * and the RHS vector b is input. The N-vector ycur contains * - * the solver's current approximation to y(tn) and the vector * - * fcur contains the N-vector f(tn,ycur). The solution is to be * - * returned in the vector b. cv_lsolve returns a positive value * - * for a recoverable error and a negative value for an * - * unrecoverable error. Success is indicated by a 0 return value. * - * * - *******************************************************************/ - -/******************************************************************* - * * - * void (*cv_lfree)(CVodeMem cv_mem); * - *-----------------------------------------------------------------* - * cv_lfree should free up any memory allocated by the linear * - * solver. This routine is called once a problem has been * - * completed and the linear solver is no longer needed. * - * * - *******************************************************************/ - - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/phqalloc.h b/phqalloc.h deleted file mode 100644 index 6d06a4b2..00000000 --- a/phqalloc.h +++ /dev/null @@ -1,46 +0,0 @@ -#if !defined (INCLUDE_PHRQALLOC_H) -#define INCLUDE_PHRQALLOC_H - -#if !defined(WIN32_MEMORY_DEBUG) -#define USE_PHRQ_ALLOC -#endif - -#if defined (USE_PHRQ_ALLOC) - -#ifdef PHREEQC_IDENT -static char const svnidphqalloc[] = "$Id$"; -#endif - -#if !defined(NDEBUG) -extern void *PHRQ_malloc(size_t, const char *, int); -extern void *PHRQ_calloc(size_t, size_t, const char *, int); -extern void *PHRQ_realloc(void *, size_t, const char *, int); -#else -extern void *PHRQ_malloc(size_t); -extern void *PHRQ_calloc(size_t, size_t); -extern void *PHRQ_realloc(void *, size_t); -#endif - -extern void PHRQ_free(void *); -extern void PHRQ_free_all(void); - -#if !defined(NDEBUG) -#define PHRQ_malloc(s) PHRQ_malloc(s, __FILE__, __LINE__) -#define PHRQ_calloc(c, s) PHRQ_calloc(c, s, __FILE__, __LINE__) -#define PHRQ_realloc(p, s) PHRQ_realloc(p, s, __FILE__, __LINE__) -#endif - -#define free(p) PHRQ_free(p) - -#else /* defined (USE_PHRQ_ALLOC) */ - -#define PHRQ_malloc malloc -#define PHRQ_realloc realloc -#define PHRQ_calloc calloc -#define PHRQ_free free - -#define PHRQ_free_all() do{}while(0) /* NO-OP */ - -#endif /* defined (USE_PHRQ_ALLOC) */ - -#endif /* !defined (INCLUDE_PHRQALLOC_H) */ From 75b28d81ca687dd6c968bc8594b64378722f848e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 18:34:28 +0000 Subject: [PATCH 0005/1077] Moved Conc to SolutionComp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@791 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 193 ----------------------------------- Exchange.cxx | 191 ---------------------------------- GasPhase.cxx | 191 ---------------------------------- ISolution.cxx | 22 ++-- ISolution.h | 9 +- KineticsComp.cxx | 193 ----------------------------------- KineticsCxx.cxx | 191 ---------------------------------- Makefile | 102 +++++++++--------- NameDouble.cxx | 1 - Solution.h | 2 +- Conc.cxx => SolutionComp.cxx | 48 ++++----- Conc.h => SolutionComp.h | 23 ++--- SurfCharge.cxx | 193 ----------------------------------- SurfComp.cxx | 193 ----------------------------------- Surface.cxx | 191 ---------------------------------- 15 files changed, 104 insertions(+), 1639 deletions(-) rename Conc.cxx => SolutionComp.cxx (84%) rename Conc.h => SolutionComp.h (69%) diff --git a/ExchComp.cxx b/ExchComp.cxx index e0832c5d..07912a84 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -359,196 +359,3 @@ void cxxExchComp::read_raw(CParser& parser) parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); } } - -#ifdef SKIP -cxxExchComp& cxxExchComp::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxExchComp numkey; - - // Read exch_comp number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxExchComp& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in EXCH_COMP keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.exch_comp_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in exch_comp.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif - diff --git a/Exchange.cxx b/Exchange.cxx index 146c2c38..2090d25e 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -220,194 +220,3 @@ void cxxExchange::read_raw(CParser& parser) parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE); } } -#ifdef SKIP -cxxExchange& cxxExchange::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxExchange numkey; - - // Read exchange number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxExchange& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in EXCHANGE keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.exchange_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in exchange.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif diff --git a/GasPhase.cxx b/GasPhase.cxx index aef606b3..a0356136 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -281,194 +281,3 @@ void cxxGasPhase::read_raw(CParser& parser) parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); } } -#ifdef SKIP -cxxGasPhase& cxxGasPhase::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxGasPhase numkey; - - // Read gas_phase number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxGasPhase& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in GAS_PHASE keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.gas_phase_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in gas_phase.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif diff --git a/ISolution.cxx b/ISolution.cxx index a8ea03bb..4891a2f6 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -37,8 +37,8 @@ cxxISolution::cxxISolution(struct solution *solution_ptr) units = solution_ptr->units; // totals for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { - cxxConc c(&(solution_ptr->totals[i])); - concs.insert(c); + cxxSolutionComp c(&(solution_ptr->totals[i])); + comps.insert(c); } default_pe = solution_ptr->default_pe; // pe_data @@ -65,7 +65,7 @@ struct solution *cxxISolution::cxxISolution2solution() soln_ptr->pe = pe_data_dup(this->pes); // totals soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); - soln_ptr->totals = cxxConc::cxxConc2conc(this->concs); + soln_ptr->totals = cxxSolutionComp::cxxSolutionComp2conc(this->comps); return(soln_ptr); } #ifdef SKIP @@ -162,8 +162,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case 6: // ph { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { + cxxSolutionComp conc; + if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { parser.incr_input_error(); break; } @@ -178,8 +178,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case 7: // pe { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { + cxxSolutionComp conc; + if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { parser.incr_input_error(); break; } @@ -216,8 +216,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case CParser::OPTION_DEFAULT: { // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { + cxxSolutionComp conc; + if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { parser.incr_input_error(); } else { sol.add(conc); @@ -238,7 +238,7 @@ cxxISolution& cxxISolution::read(CParser& parser) // fix up default units and default pe // std::string token1; - std::vector::iterator iter = sol.totals.begin(); + std::vector::iterator iter = sol.totals.begin(); for (; iter != sol.totals.end(); ++iter) { token = (*iter).get_description(); @@ -299,7 +299,7 @@ void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; os << "\n"; - std::vector::const_iterator iter = this->totals.begin(); + std::vector::const_iterator iter = this->totals.begin(); for(; iter != this->totals.end(); ++iter) { (*iter).dump_xml(*this, os, indent + 2); diff --git a/ISolution.h b/ISolution.h index c80d7925..b74f2620 100644 --- a/ISolution.h +++ b/ISolution.h @@ -4,7 +4,7 @@ //#include "Parser.h" #include "NumKeyword.h" #include "Solution.h" -#include "Conc.h" +#include "SolutionComp.h" //#include "Isotope.h" #include // assert #include // std::map @@ -25,7 +25,7 @@ public: //static cxxISolution& read(CParser& parser); - //void add(cxxConc conc) { this->concs.push_back(conc); } + //void add(cxxSolutionComp conc) { this->concs.push_back(conc); } struct solution *cxxISolution2solution(); @@ -40,11 +40,10 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; protected: - friend class cxxConc; // for this->pe access + friend class cxxSolutionComp; // for this->pe access double density; std::string units; - std::set concs; - //std::map pe; + std::set comps; struct pe_data *pes; int default_pe; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index ab9b374e..7f06fb1b 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -309,196 +309,3 @@ void cxxKineticsComp::read_raw(CParser& parser) parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE); } } - -#ifdef SKIP -cxxKineticsComp& cxxKineticsComp::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxKineticsComp numkey; - - // Read kinetics_comp number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxKineticsComp& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in KINETICS_COMP keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.kinetics_comp_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in kinetics_comp.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif - diff --git a/KineticsCxx.cxx b/KineticsCxx.cxx index d440bbda..86c3787b 100644 --- a/KineticsCxx.cxx +++ b/KineticsCxx.cxx @@ -345,194 +345,3 @@ void cxxKinetics::read_raw(CParser& parser) parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); } } -#ifdef SKIP -cxxKinetics& cxxKinetics::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxKinetics numkey; - - // Read kinetics number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxKinetics& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in KINETICS keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.kinetics_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in kinetics.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif diff --git a/Makefile b/Makefile index 77ee8743..443c124e 100644 --- a/Makefile +++ b/Makefile @@ -139,7 +139,6 @@ COMMON_COBJS = \ utilities.o COMMON_CXXOBJS = \ - Conc.o \ Exchange.o \ ExchComp.o \ GasPhase.o \ @@ -156,6 +155,7 @@ COMMON_CXXOBJS = \ Reaction.o \ ReadClass.o \ Solution.o \ + SolutionComp.o \ SSassemblage.o \ SSassemblageSS.o \ Surface.o \ @@ -178,43 +178,43 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -Conc.o: ../Conc.cxx ../Conc.h ../Utils.h ../char_star.h ../ISolution.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Isotope.h ../Parser.h ../Conc.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../Conc.h ../Utils.h ../phreeqc/phrqproto.h \ - ../phqalloc.h Exchange.o: ../Exchange.cxx ../Utils.h ../Exchange.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../ExchComp.h ../phqalloc.h ../phreeqc/phrqproto.h + ../char_star.h ../ExchComp.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../ExchComp.h ../NameDouble.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../char_star.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../GasPhase.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +ISolution.o: ../ISolution.cxx ../ISolution.h ../NumKeyword.h ../Parser.h \ + ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h \ + ../SolutionComp.h ../Utils.h ../char_star.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../SolutionComp.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h Isotope.o: ../Isotope.cxx ../Isotope.h ../Parser.h ../char_star.h \ ../Utils.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../KineticsComp.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../char_star.h ../phqalloc.h \ - ../phreeqc/phrqproto.h + ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h KineticsCxx.o: ../KineticsCxx.cxx ../Utils.h ../KineticsCxx.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ ../char_star.h ../Parser.h ../char_star.h ../KineticsComp.h \ - ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Mix.o: ../Mix.cxx ../Utils.h ../Mix.h ../NumKeyword.h ../Parser.h \ ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../phqalloc.h ../phreeqc/phrqproto.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../Conc.h ../Utils.h \ - ../char_star.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ ../char_star.h Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ @@ -222,18 +222,18 @@ Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ ../PPassemblageComp.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../PPassemblage.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../PPassemblageComp.h \ ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ - ../PPassemblageComp.h ../phqalloc.h ../phreeqc/phrqproto.h + ../PPassemblageComp.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Reaction.o: ../Reaction.cxx ../Utils.h ../Reaction.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../Conc.h \ + ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../SolutionComp.h \ ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ ../Exchange.h ../NumKeyword.h ../char_star.h ../ExchComp.h \ @@ -247,50 +247,58 @@ ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ ../char_star.h ../GasPhase.h ../NumKeyword.h ../NameDouble.h \ ../char_star.h ../Reaction.h ../NumKeyword.h ../NameDouble.h \ ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h ../Temperature.h \ - ../NumKeyword.h ../char_star.h ../phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h +SolutionComp.o: ../SolutionComp.cxx ../SolutionComp.h ../Utils.h \ + ../char_star.h ../ISolution.h ../NumKeyword.h ../Parser.h \ + ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h \ + ../SolutionComp.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../SolutionComp.h ../Utils.h ../phreeqc/phrqproto.h \ + ../phreeqc/phqalloc.h Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../Conc.h \ + ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../SolutionComp.h \ ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h ../NumKeyword.h \ - ../Solution.h ../Conc.h ../Exchange.h ../NumKeyword.h ../char_star.h \ - ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ - ../NumKeyword.h ../char_star.h ../SurfComp.h ../NameDouble.h \ - ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ - ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ - ../NameDouble.h ../char_star.h ../KineticsCxx.h ../NumKeyword.h \ - ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ - ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../char_star.h + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h \ + ../NumKeyword.h ../Solution.h ../SolutionComp.h ../Exchange.h \ + ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ + ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ + ../SurfComp.h ../NameDouble.h ../char_star.h ../SurfCharge.h \ + ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ + ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ + ../KineticsCxx.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ + ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ + ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ + ../NumKeyword.h ../char_star.h ../Temperature.h ../NumKeyword.h \ + ../char_star.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ - ../SSassemblageSS.h ../phqalloc.h ../phreeqc/phrqproto.h + ../SSassemblageSS.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../SSassemblageSS.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ - ../NameDouble.h ../phqalloc.h ../phreeqc/phrqproto.h + ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Surface.o: ../Surface.cxx ../Utils.h ../Surface.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h ../Parser.h \ ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ - ../SurfComp.h ../phqalloc.h ../phreeqc/phrqproto.h + ../SurfComp.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SurfCharge.o: ../SurfCharge.cxx ../Utils.h ../SurfCharge.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ - ../phreeqc/output.h ../phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SurfComp.o: ../SurfComp.cxx ../Utils.h ../SurfComp.h ../NameDouble.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../char_star.h ../phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../char_star.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h Temperature.o: ../Temperature.cxx ../Utils.h ../Temperature.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../phqalloc.h \ + ../phreeqc/phrqtype.h ../char_star.h ../phreeqc/phqalloc.h \ ../phreeqc/phrqproto.h Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../char_star.h \ ../phreeqc/output.h diff --git a/NameDouble.cxx b/NameDouble.cxx index b4385bf8..d1ed6b94 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -6,7 +6,6 @@ #endif #include "Utils.h" // define first -#include "Conc.h" #include "NameDouble.h" #define EXTERNAL extern #include "global.h" diff --git a/Solution.h b/Solution.h index f0c2696d..33a35bab 100644 --- a/Solution.h +++ b/Solution.h @@ -3,7 +3,7 @@ #include "NumKeyword.h" #include "Isotope.h" -#include "Conc.h" +#include "SolutionComp.h" #include "NameDouble.h" #define EXTERNAL extern #include "global.h" diff --git a/Conc.cxx b/SolutionComp.cxx similarity index 84% rename from Conc.cxx rename to SolutionComp.cxx index c4e78dbf..8aabc078 100644 --- a/Conc.cxx +++ b/SolutionComp.cxx @@ -2,7 +2,7 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Conc.h" +#include "SolutionComp.h" #include "ISolution.h" #include "Utils.h" #include @@ -11,7 +11,7 @@ #include "phrqproto.h" #include "phqalloc.h" -cxxConc::cxxConc(void) +cxxSolutionComp::cxxSolutionComp(void) : description(NULL) , moles(0.0) , input_conc(0.0) @@ -25,7 +25,7 @@ cxxConc::cxxConc(void) //, phase(NULL) { } -cxxConc::cxxConc(struct conc *conc_ptr) +cxxSolutionComp::cxxSolutionComp(struct conc *conc_ptr) { description = conc_ptr->description; moles = conc_ptr->moles; @@ -40,11 +40,11 @@ cxxConc::cxxConc(struct conc *conc_ptr) //phase = conc_ptr->phase; } -cxxConc::~cxxConc(void) +cxxSolutionComp::~cxxSolutionComp(void) { } /* -struct conc *cxxConc::concarray(std::map &totals) +struct conc *cxxSolutionComp::concarray(std::map &totals) // for Solutions, not ISolutions // takes a map of (elt name, moles) // returns list of conc structures @@ -71,16 +71,16 @@ struct conc *cxxConc::concarray(std::map &totals return(c); } */ -struct conc *cxxConc::cxxConc2conc(const std::set &totals) +struct conc *cxxSolutionComp::cxxSolutionComp2conc(const std::set &totals) // for ISolutions - // takes a std::vector cxxConc structures + // takes a std::vector cxxSolutionComp structures // returns list of conc structures { struct conc *c; c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); if (c == NULL) malloc_error(); int i = 0; - for (std::set::const_iterator it = totals.begin(); it != totals.end(); ++it) { + for (std::set::const_iterator it = totals.begin(); it != totals.end(); ++it) { c[i].description = it->description; c[i].moles = it->moles; c[i].input_conc = it->input_conc; @@ -99,7 +99,7 @@ struct conc *cxxConc::cxxConc2conc(const std::set &totals) } #ifdef SKIP -cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) +cxxSolutionComp::STATUS_TYPE cxxSolutionComp::read(CParser& parser, cxxISolution& solution) { // std::string& str = parser.line(); std::string str = parser.line(); @@ -133,7 +133,7 @@ cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) if (count_redox_states == 0) { parser.incr_input_error(); parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE); - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } description = token1; @@ -149,9 +149,9 @@ cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) std::ostringstream err; err << "Concentration data error for " << token1 << " in solution input."; parser.error_msg(err, CParser::OT_CONTINUE); - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; // Read optional data token1 = token; @@ -160,9 +160,9 @@ cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) { if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) { this->units = token1; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; } else { - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } } @@ -173,49 +173,49 @@ cxxConc::STATUS_TYPE cxxConc::read(CParser& parser, cxxISolution& solution) { parser.copy_token(token, ptr); this->as = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; } // Check for "gfw" followed by gram formula weight else if (token1.compare("gfw") == 0) { if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } else { parser.get_iss() >> this->gfw; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; } } // Check for redox couple for pe if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; } else if (token.find("/") != std::string::npos) { if (parser.parse_couple(token) == CParser::OK) { this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; } else { - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } } // Must have phase this->equation_name = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxConc::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; // Check for saturation index if (!(std::istringstream(token) >> this->phase_si)) { parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); - return cxxConc::ERROR; + return cxxSolutionComp::ERROR; } - return cxxConc::OK; + return cxxSolutionComp::OK; } #endif #ifdef SKIP -void cxxConc::dump_xml(std::ostream& s_oss, unsigned int indent)const +void cxxSolutionComp::dump_xml(std::ostream& s_oss, unsigned int indent)const { unsigned int i; std::string indent0(""); diff --git a/Conc.h b/SolutionComp.h similarity index 69% rename from Conc.h rename to SolutionComp.h index a792408c..b9bbaa66 100644 --- a/Conc.h +++ b/SolutionComp.h @@ -1,5 +1,5 @@ -#if !defined(CONC_H_INCLUDED) -#define CONC_H_INCLUDED +#if !defined(SOLUTIONCOMP_H_INCLUDED) +#define SOLUTIONCOMP_H_INCLUDED //#include "Parser.h" #include "Utils.h" @@ -13,12 +13,12 @@ // forward declarations class cxxISolution; // reqd for read and dump_xml -class cxxConc +class cxxSolutionComp { public: - cxxConc(void); - cxxConc(struct conc *conc_ptr); - ~cxxConc(void); + cxxSolutionComp(void); + cxxSolutionComp(struct conc *conc_ptr); + ~cxxSolutionComp(void); enum STATUS_TYPE { ERROR = 0, @@ -46,12 +46,9 @@ public: int get_n_pe()const {return this->n_pe;} void set_n_pe(int n_pe) {this->n_pe = n_pe;} - //bool operator<(const cxxConc& conc)const { return (this->description < conc.description); } - bool operator<(const cxxConc& conc)const { return ::strcmp(this->description, conc.description) < 0; } + bool operator<(const cxxSolutionComp& conc)const { return ::strcmp(this->description, conc.description) < 0; } - //static struct conc * concarray(std::map &t ); - - static struct conc * cxxConc2conc(const std::set &t ); + static struct conc * cxxSolutionComp2conc(const std::set &t ); private: char * description; @@ -59,12 +56,10 @@ private: double input_conc; char * units; char * equation_name; - //struct phase *phase; double phase_si; int n_pe; char * as; double gfw; - //int skip; }; -#endif // CONC_H_INCLUDED +#endif // SOLUTIONCOMP_H_INCLUDED diff --git a/SurfCharge.cxx b/SurfCharge.cxx index 1a0cf559..5b7242c7 100644 --- a/SurfCharge.cxx +++ b/SurfCharge.cxx @@ -298,196 +298,3 @@ void cxxSurfCharge::read_raw(CParser& parser) parser.error_msg("La_psi not defined for SurfCharge input.", CParser::OT_CONTINUE); } } - -#ifdef SKIP -cxxSurfCharge& cxxSurfCharge::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxSurfCharge numkey; - - // Read surf_charge number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxSurfCharge& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SURF_CHARGE keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.surf_charge_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in surf_charge.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif - diff --git a/SurfComp.cxx b/SurfComp.cxx index e7cb0c55..831b4fc7 100644 --- a/SurfComp.cxx +++ b/SurfComp.cxx @@ -342,196 +342,3 @@ void cxxSurfComp::read_raw(CParser& parser) parser.error_msg("Charge_balance not defined for SurfComp input.", CParser::OT_CONTINUE); } } - -#ifdef SKIP -cxxSurfComp& cxxSurfComp::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxSurfComp numkey; - - // Read surf_comp number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxSurfComp& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SURF_COMP keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.surf_comp_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in surf_comp.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif - diff --git a/Surface.cxx b/Surface.cxx index f4e1a971..55602a90 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -364,194 +364,3 @@ void cxxSurface::read_raw(CParser& parser) parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } } -#ifdef SKIP -cxxSurface& cxxSurface::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxSurface numkey; - - // Read surface number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxSurface& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SURFACE keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.surface_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in surface.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif From 39494b0287712cc58a8e4cbe62fb772e15353485 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 19:52:52 +0000 Subject: [PATCH 0006/1077] Renamed SolutionComp to ISolutionComp because it is not used in cxxSolution. Fixed Makefile to new names git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@792 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 20 +++++------ ISolution.h | 8 ++--- Makefile | 91 ++++++++++++++++++++++++++------------------------- Solution.h | 7 ---- 4 files changed, 60 insertions(+), 66 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 4891a2f6..d3298ba1 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -37,7 +37,7 @@ cxxISolution::cxxISolution(struct solution *solution_ptr) units = solution_ptr->units; // totals for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { - cxxSolutionComp c(&(solution_ptr->totals[i])); + cxxISolutionComp c(&(solution_ptr->totals[i])); comps.insert(c); } default_pe = solution_ptr->default_pe; @@ -65,7 +65,7 @@ struct solution *cxxISolution::cxxISolution2solution() soln_ptr->pe = pe_data_dup(this->pes); // totals soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); - soln_ptr->totals = cxxSolutionComp::cxxSolutionComp2conc(this->comps); + soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(this->comps); return(soln_ptr); } #ifdef SKIP @@ -162,8 +162,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case 6: // ph { - cxxSolutionComp conc; - if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { + cxxISolutionComp conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { parser.incr_input_error(); break; } @@ -178,8 +178,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case 7: // pe { - cxxSolutionComp conc; - if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { + cxxISolutionComp conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { parser.incr_input_error(); break; } @@ -216,8 +216,8 @@ cxxISolution& cxxISolution::read(CParser& parser) case CParser::OPTION_DEFAULT: { // Read concentration - cxxSolutionComp conc; - if (conc.read(parser, sol) == cxxSolutionComp::ERROR) { + cxxISolutionComp conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { parser.incr_input_error(); } else { sol.add(conc); @@ -238,7 +238,7 @@ cxxISolution& cxxISolution::read(CParser& parser) // fix up default units and default pe // std::string token1; - std::vector::iterator iter = sol.totals.begin(); + std::vector::iterator iter = sol.totals.begin(); for (; iter != sol.totals.end(); ++iter) { token = (*iter).get_description(); @@ -299,7 +299,7 @@ void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; os << "\n"; - std::vector::const_iterator iter = this->totals.begin(); + std::vector::const_iterator iter = this->totals.begin(); for(; iter != this->totals.end(); ++iter) { (*iter).dump_xml(*this, os, indent + 2); diff --git a/ISolution.h b/ISolution.h index b74f2620..91a05d78 100644 --- a/ISolution.h +++ b/ISolution.h @@ -2,9 +2,9 @@ #define ISOLUTION_H_INCLUDED //#include "Parser.h" +#include "ISolutionComp.h" #include "NumKeyword.h" #include "Solution.h" -#include "SolutionComp.h" //#include "Isotope.h" #include // assert #include // std::map @@ -25,7 +25,7 @@ public: //static cxxISolution& read(CParser& parser); - //void add(cxxSolutionComp conc) { this->concs.push_back(conc); } + //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } struct solution *cxxISolution2solution(); @@ -40,10 +40,10 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; protected: - friend class cxxSolutionComp; // for this->pe access + friend class cxxISolutionComp; // for this->pe access double density; std::string units; - std::set comps; + std::set comps; struct pe_data *pes; int default_pe; diff --git a/Makefile b/Makefile index 443c124e..5af31c48 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ COMMON_CXXOBJS = \ Reaction.o \ ReadClass.o \ Solution.o \ - SolutionComp.o \ + ISolutionComp.o \ SSassemblage.o \ SSassemblageSS.o \ Surface.o \ @@ -191,12 +191,17 @@ GasPhase.o: ../GasPhase.cxx ../Utils.h ../GasPhase.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -ISolution.o: ../ISolution.cxx ../ISolution.h ../NumKeyword.h ../Parser.h \ - ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h \ - ../SolutionComp.h ../Utils.h ../char_star.h ../NameDouble.h \ +ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ + ../char_star.h ../ISolution.h ../ISolutionComp.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h \ + ../Parser.h ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../Utils.h \ + ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h +ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ + ../Utils.h ../char_star.h ../NumKeyword.h ../Parser.h ../char_star.h \ + ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h ../NameDouble.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../SolutionComp.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Isotope.o: ../Isotope.cxx ../Isotope.h ../Parser.h ../char_star.h \ ../Utils.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h @@ -233,47 +238,38 @@ Reaction.o: ../Reaction.cxx ../Utils.h ../Reaction.h ../NumKeyword.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../SolutionComp.h \ - ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../Exchange.h ../NumKeyword.h ../char_star.h ../ExchComp.h \ - ../NameDouble.h ../char_star.h ../Surface.h ../NumKeyword.h \ - ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h \ - ../SurfCharge.h ../NameDouble.h ../char_star.h ../PPassemblage.h \ - ../NumKeyword.h ../char_star.h ../PPassemblageComp.h ../NameDouble.h \ - ../char_star.h ../KineticsCxx.h ../NumKeyword.h ../char_star.h \ - ../KineticsComp.h ../NameDouble.h ../char_star.h ../SSassemblage.h \ - ../NumKeyword.h ../char_star.h ../SSassemblageSS.h ../NameDouble.h \ - ../char_star.h ../GasPhase.h ../NumKeyword.h ../NameDouble.h \ - ../char_star.h ../Reaction.h ../NumKeyword.h ../NameDouble.h \ - ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h ../Temperature.h \ - ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ + ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../Exchange.h ../NumKeyword.h ../char_star.h \ + ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ + ../NumKeyword.h ../char_star.h ../SurfComp.h ../NameDouble.h \ + ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ + ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ + ../NameDouble.h ../char_star.h ../KineticsCxx.h ../NumKeyword.h \ + ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ + ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ + ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h \ + ../Temperature.h ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ ../phreeqc/output.h ../phreeqc/phrqproto.h -SolutionComp.o: ../SolutionComp.cxx ../SolutionComp.h ../Utils.h \ - ../char_star.h ../ISolution.h ../NumKeyword.h ../Parser.h \ - ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h \ - ../SolutionComp.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../SolutionComp.h ../Utils.h ../phreeqc/phrqproto.h \ - ../phreeqc/phqalloc.h Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../SolutionComp.h \ - ../Utils.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h \ - ../NumKeyword.h ../Solution.h ../SolutionComp.h ../Exchange.h \ - ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ - ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ - ../SurfComp.h ../NameDouble.h ../char_star.h ../SurfCharge.h \ - ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ - ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ - ../KineticsCxx.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ - ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ - ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ - ../NumKeyword.h ../char_star.h ../Temperature.h ../NumKeyword.h \ - ../char_star.h + ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../ISolution.h ../ISolutionComp.h ../Utils.h ../char_star.h \ + ../NumKeyword.h ../Solution.h ../Exchange.h ../NumKeyword.h \ + ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ + ../Surface.h ../NumKeyword.h ../char_star.h ../SurfComp.h \ + ../NameDouble.h ../char_star.h ../SurfCharge.h ../NameDouble.h \ + ../char_star.h ../PPassemblage.h ../NumKeyword.h ../char_star.h \ + ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../KineticsCxx.h \ + ../NumKeyword.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ + ../char_star.h ../SSassemblage.h ../NumKeyword.h ../char_star.h \ + ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../GasPhase.h \ + ../NumKeyword.h ../NameDouble.h ../char_star.h ../Reaction.h \ + ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h \ + ../char_star.h ../Temperature.h ../NumKeyword.h ../char_star.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ @@ -411,6 +407,11 @@ utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ clean: rm -rf Release Debug +dependencies: + mkdir -p $(DEBUG_DIR) + cd Debug; gcc -MM -I../phreeqc ../*.cxx + + # ============================================================================= # End of makefile. # ============================================================================= diff --git a/Solution.h b/Solution.h index 33a35bab..733d9ecc 100644 --- a/Solution.h +++ b/Solution.h @@ -3,7 +3,6 @@ #include "NumKeyword.h" #include "Isotope.h" -#include "SolutionComp.h" #include "NameDouble.h" #define EXTERNAL extern #include "global.h" @@ -76,15 +75,9 @@ protected: double cb; double mass_water; double total_alkalinity; - // maps element name to moles - //std::map totals; cxxNameDouble totals; std::list isotopes; - // maps master species name log activity - //std::map master_activity; cxxNameDouble master_activity; - // maps species name to Pitzer activty coefficient - //std::map species_gamma; cxxNameDouble species_gamma; public: //static std::map& map; From c42d9855589da8d825887c3792e8d438710bf255 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2006 20:09:24 +0000 Subject: [PATCH 0007/1077] Moved Isotope to SolutionIsotope git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@793 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 68 +++++++++++++++--------------- Solution.cxx | 10 ++--- Solution.h | 4 +- Isotope.cxx => SolutionIsotope.cxx | 30 ++++++------- Isotope.h => SolutionIsotope.h | 20 ++++----- 5 files changed, 67 insertions(+), 65 deletions(-) rename Isotope.cxx => SolutionIsotope.cxx (88%) rename Isotope.h => SolutionIsotope.h (74%) diff --git a/Makefile b/Makefile index 5af31c48..89e054c3 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,7 @@ COMMON_CXXOBJS = \ ExchComp.o \ GasPhase.o \ ISolution.o \ - Isotope.o \ + SolutionIsotope.o \ KineticsComp.o \ KineticsCxx.o \ Mix.o \ @@ -193,18 +193,16 @@ GasPhase.o: ../GasPhase.cxx ../Utils.h ../GasPhase.h ../NumKeyword.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ ../char_star.h ../ISolution.h ../ISolutionComp.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h ../Isotope.h \ - ../Parser.h ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../Utils.h \ - ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h + ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../Utils.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ ../Utils.h ../char_star.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../Solution.h ../NumKeyword.h ../Isotope.h ../Parser.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Isotope.o: ../Isotope.cxx ../Isotope.h ../Parser.h ../char_star.h \ - ../Utils.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Solution.h ../NumKeyword.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../KineticsComp.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ @@ -238,27 +236,9 @@ Reaction.o: ../Reaction.cxx ../Utils.h ../Reaction.h ../NumKeyword.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../Isotope.h ../Parser.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../Exchange.h ../NumKeyword.h ../char_star.h \ - ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ - ../NumKeyword.h ../char_star.h ../SurfComp.h ../NameDouble.h \ - ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ - ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ - ../NameDouble.h ../char_star.h ../KineticsCxx.h ../NumKeyword.h \ - ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ - ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../Isotope.h ../Parser.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../ISolution.h ../ISolutionComp.h ../Utils.h ../char_star.h \ - ../NumKeyword.h ../Solution.h ../Exchange.h ../NumKeyword.h \ + ../NumKeyword.h ../Parser.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../Exchange.h ../NumKeyword.h \ ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ ../Surface.h ../NumKeyword.h ../char_star.h ../SurfComp.h \ ../NameDouble.h ../char_star.h ../SurfCharge.h ../NameDouble.h \ @@ -269,7 +249,29 @@ Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../GasPhase.h \ ../NumKeyword.h ../NameDouble.h ../char_star.h ../Reaction.h \ ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h \ - ../char_star.h ../Temperature.h ../NumKeyword.h ../char_star.h + ../char_star.h ../Temperature.h ../NumKeyword.h ../char_star.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../ISolution.h ../ISolutionComp.h ../Utils.h \ + ../char_star.h ../NumKeyword.h ../Solution.h ../Exchange.h \ + ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ + ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ + ../SurfComp.h ../NameDouble.h ../char_star.h ../SurfCharge.h \ + ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ + ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ + ../KineticsCxx.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ + ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ + ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ + ../NumKeyword.h ../char_star.h ../Temperature.h ../NumKeyword.h \ + ../char_star.h +SolutionIsotope.o: ../SolutionIsotope.cxx ../SolutionIsotope.h \ + ../Parser.h ../char_star.h ../Utils.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ diff --git a/Solution.cxx b/Solution.cxx index 9331295c..f13f3515 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -69,7 +69,7 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cx // Isotopes for (i = 0; i < solution_ptr->count_isotopes; i++) { - cxxIsotope iso(&solution_ptr->isotopes[i]); + cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); isotopes.push_back(iso); } @@ -123,7 +123,7 @@ struct solution *cxxSolution::cxxSolution2solution() // isotopes solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = cxxIsotope::list2isotope(this->isotopes); + solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); solution_ptr->count_isotopes = this->isotopes.size(); return(solution_ptr); @@ -223,7 +223,7 @@ void cxxSolution::dump_xml(std::ostream& s_oss, unsigned int indent)const } */ - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { it->dump_xml(s_oss, indent + 1); } @@ -326,7 +326,7 @@ void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "-Isotopes" << std::endl; { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { it->dump_raw(s_oss, indent + 2); } } @@ -429,7 +429,7 @@ void cxxSolution::read_raw(CParser& parser) case 3: // isotopes { - cxxIsotope iso; + cxxSolutionIsotope iso; if ( iso.read_raw(parser) != CParser::PARSER_OK) { parser.incr_input_error(); parser.error_msg("Expected data for isotopes.", CParser::OT_CONTINUE); diff --git a/Solution.h b/Solution.h index 733d9ecc..131063f6 100644 --- a/Solution.h +++ b/Solution.h @@ -2,7 +2,7 @@ #define SOLUTION_H_INCLUDED #include "NumKeyword.h" -#include "Isotope.h" +#include "SolutionIsotope.h" #include "NameDouble.h" #define EXTERNAL extern #include "global.h" @@ -76,7 +76,7 @@ protected: double mass_water; double total_alkalinity; cxxNameDouble totals; - std::list isotopes; + std::list isotopes; cxxNameDouble master_activity; cxxNameDouble species_gamma; public: diff --git a/Isotope.cxx b/SolutionIsotope.cxx similarity index 88% rename from Isotope.cxx rename to SolutionIsotope.cxx index 244d71fe..54afd61d 100644 --- a/Isotope.cxx +++ b/SolutionIsotope.cxx @@ -1,7 +1,7 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Isotope.h" +#include "SolutionIsotope.h" #include "Utils.h" #include "Parser.h" #define EXTERNAL extern @@ -11,12 +11,12 @@ #include #include // std::ostrstream -cxxIsotope::cxxIsotope(void) +cxxSolutionIsotope::cxxSolutionIsotope(void) : isotope_number(0.0) { } -cxxIsotope::cxxIsotope(struct isotope *isotope_ptr) +cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) { isotope_number = isotope_ptr->isotope_number; elt_name = isotope_ptr->elt_name; @@ -26,12 +26,12 @@ cxxIsotope::cxxIsotope(struct isotope *isotope_ptr) ratio_uncertainty = isotope_ptr->ratio_uncertainty; } -cxxIsotope::~cxxIsotope(void) +cxxSolutionIsotope::~cxxSolutionIsotope(void) { } -struct isotope *cxxIsotope::list2isotope(std::list &isolist) - // takes a std::list of cxxIsotope structures +struct isotope *cxxSolutionIsotope::list2isotope(std::list &isolist) + // takes a std::list of cxxSolutionIsotope structures // returns array of isotope structures { struct isotope *iso; @@ -41,7 +41,7 @@ struct isotope *cxxIsotope::list2isotope(std::list &isolist) iso = (struct isotope *) PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); if (iso == NULL) malloc_error(); int i = 0; - for (std::list ::iterator it = isolist.begin(); it != isolist.end(); ++it) { + for (std::list ::iterator it = isolist.begin(); it != isolist.end(); ++it) { iso[i].isotope_number = it->isotope_number; iso[i].elt_name = it->elt_name; iso[i].total = it->total; @@ -56,7 +56,7 @@ struct isotope *cxxIsotope::list2isotope(std::list &isolist) } #ifdef SKIP -std::string cxxIsotope::get_name()const +std::string cxxSolutionIsotope::get_name()const { std::ostringstream oss; //std::ostrstream oss; @@ -65,7 +65,7 @@ std::string cxxIsotope::get_name()const } #endif -void cxxIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const +void cxxSolutionIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const { unsigned int i; @@ -99,7 +99,7 @@ void cxxIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << "\">" << std::endl; } -void cxxIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const +void cxxSolutionIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const { unsigned int i; @@ -118,7 +118,7 @@ void cxxIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << std::endl; } -CParser::STATUS_TYPE cxxIsotope::read_raw(CParser& parser) +CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser& parser) { std::string token; std::istream::pos_type next_char; @@ -168,25 +168,25 @@ CParser::STATUS_TYPE cxxIsotope::read_raw(CParser& parser) return CParser::PARSER_OK; } -bool cxxIsotope::operator<(const cxxIsotope& isotope)const +bool cxxSolutionIsotope::operator<(const cxxSolutionIsotope& isotope)const { int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); if (i != 0) return (i < 0); return ( this->isotope_number < isotope.isotope_number ); } -struct master *cxxIsotope::master(void) +struct master *cxxSolutionIsotope::master(void) { return (master_bsearch(this->elt_name)); } -struct master *cxxIsotope::primary(void) +struct master *cxxSolutionIsotope::primary(void) { return (master_bsearch_primary(this->elt_name)); } #ifdef SKIP -cxxIsotope::STATUS cxxIsotope::read(CParser& parser) +cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser& parser) { if ( !(parser.get_iss() >> this->isotope_number) ) { assert(parser.get_iss().fail()); diff --git a/Isotope.h b/SolutionIsotope.h similarity index 74% rename from Isotope.h rename to SolutionIsotope.h index 372e5523..4fbd821c 100644 --- a/Isotope.h +++ b/SolutionIsotope.h @@ -1,25 +1,25 @@ -#if !defined(ISOTOPE_H_INCLUDED) -#define ISOTOPE_H_INCLUDED +#if !defined(SOLUTIONISOTOPE_H_INCLUDED) +#define SOLUTIONISOTOPE_H_INCLUDED #include "Parser.h" #include // std::ostream #include // std::string #include // std::list -class cxxIsotope +class cxxSolutionIsotope { public: - cxxIsotope(void); - cxxIsotope(struct isotope *isotope_ptr); - ~cxxIsotope(void); + cxxSolutionIsotope(void); + cxxSolutionIsotope(struct isotope *isotope_ptr); + ~cxxSolutionIsotope(void); enum STATUS { ERROR = 0, OK = 1 }; - //cxxIsotope::STATUS read(CParser& parser); - static struct isotope * list2isotope(std::list &t); + //cxxSolutionIsotope::STATUS read(CParser& parser); + static struct isotope * list2isotope(std::list &t); void dump_xml(std::ostream& os, unsigned int indent)const; void dump_raw(std::ostream& os, unsigned int indent)const; @@ -37,7 +37,7 @@ public: bool get_ratio_uncertainty_defined()const { return this->ratio_uncertainty_defined; } - bool operator<(const cxxIsotope& conc)const; + bool operator<(const cxxSolutionIsotope& conc)const; struct master *master(void); struct master *primary(void); @@ -53,4 +53,4 @@ private: //struct master *primary; bool ratio_uncertainty_defined; }; -#endif // ISOTOPE_H_INCLUDED +#endif // SOLUTIONISOTOPE_H_INCLUDED From 2fe8f7d44e7452b210f3a10a24dfe88e53e29637 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Feb 2006 21:17:46 +0000 Subject: [PATCH 0008/1077] Working on saving state. I think there is a compiler bug with map iterators in template definitions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@796 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 7 +++++++ Parser.cxx | 10 +++++++--- Parser.h | 16 +++++++++++----- Solution.cxx | 20 ++++++++++++++++++-- Utils.h | 21 +++++++++++++++++++++ 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 89e054c3..fb90ded5 100644 --- a/Makefile +++ b/Makefile @@ -158,6 +158,7 @@ COMMON_CXXOBJS = \ ISolutionComp.o \ SSassemblage.o \ SSassemblageSS.o \ + StorageBin.o \ Surface.o \ SurfCharge.o \ SurfComp.o \ @@ -178,6 +179,9 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # +EntityMap.o: ../EntityMap.cxx ../Utils.h ../EntityMap.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Exchange.o: ../Exchange.cxx ../Utils.h ../Exchange.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h ../Parser.h \ @@ -281,6 +285,9 @@ SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../SSassemblageSS.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../StorageBin.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h Surface.o: ../Surface.cxx ../Utils.h ../Surface.h ../NumKeyword.h \ ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h ../Parser.h \ diff --git a/Parser.cxx b/Parser.cxx index 48f78c22..af9a95f1 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -233,9 +233,13 @@ bool CParser::check_key(std::string::iterator begin, std::string::iterator end) static std::map s_keyword_map; if (s_keyword_map.size() == 0) { - s_keyword_map.insert(std::map::value_type("solution", KT_SOLUTION)); - s_keyword_map.insert(std::map::value_type("solution_raw", KT_SOLUTION_RAW)); - s_keyword_map.insert(std::map::value_type("end", KT_END)); + s_keyword_map.insert(std::map::value_type("solution_raw", KT_SOLUTION_RAW)); + s_keyword_map.insert(std::map::value_type("exchange_raw", KT_EXCHANGE_RAW)); + s_keyword_map.insert(std::map::value_type("gas_phase_raw", KT_GASPHASE_RAW)); + s_keyword_map.insert(std::map::value_type("kinetics_raw", KT_KINETICS_RAW)); + s_keyword_map.insert(std::map::value_type("equilibrium_phases_raw", KT_PPASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map::value_type("solid_solutions_raw", KT_SSASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map::value_type("surface_raw", KT_SURFACE_RAW)); } std::string lowercase; diff --git a/Parser.h b/Parser.h index feafabbe..b28ccce0 100644 --- a/Parser.h +++ b/Parser.h @@ -40,11 +40,17 @@ public: }; enum KEY_TYPE { - KT_NONE = -1, - KT_END = 0, - KT_EOF = 1, - KT_SOLUTION = 4, - KT_SOLUTION_RAW = 5 + KT_NONE = -1, + KT_END = 0, + KT_EOF = 1, + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + }; enum OPT_TYPE { diff --git a/Solution.cxx b/Solution.cxx index f13f3515..5ae7438b 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -809,6 +809,8 @@ cxxSolution& cxxSolution::read(CParser& parser) #include "Reaction.h" #include "Mix.h" #include "Temperature.h" +#include "StorageBin.h" +#include "NumKeyword.h" #include // std::cout std::cerr //#include #include @@ -816,8 +818,22 @@ cxxSolution& cxxSolution::read(CParser& parser) void test_classes(void) { int i; - bool b(true); - i = (int) b; + + + + /* + std::map Solutions; + cxxSolution soln(solution[0]); + Solutions[solution[0]->n_user] = soln; + bool b = Utilities::exists(Solutions, 1); + */ + /* + cxxEntityMap x; + cxxSolution soln(solution[0]); + cxxNumKeyword nk; + x[solution[0]->n_user] = soln; + */ + for (i=0; i < count_solution; i++) { if (solution[i]->new_def == TRUE) { cxxISolution sol(solution[i]); diff --git a/Utils.h b/Utils.h index 0c1bba6c..714a5bae 100644 --- a/Utils.h +++ b/Utils.h @@ -2,6 +2,11 @@ #define UTILITIES_H_INCLUDED #include +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include // std::map +#include "char_star.h" namespace Utilities { @@ -26,6 +31,22 @@ namespace Utilities { void error_msg(const std::string&, const int stopflag); + // operations on maps of entities (Solution, Exchange, ...) + template + bool exists (std::map b, int i){ + return (b.find(i) != b.end());} + + /* + template + void dump_raw ( std::map b, std::ostream& s_oss, unsigned int indent ) + { + std :: map < int, T > :: iterator it; + for (it = b.begin(); it != b.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + return; + } + */ } #endif // UTILITIES_H_INCLUDED From 90a787e420a18a05260fb76595d740644a7d134d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Feb 2006 21:22:47 +0000 Subject: [PATCH 0009/1077] Changed name to ISolutionComp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@797 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SolutionComp.cxx => ISolutionComp.cxx | 48 +++++++++++++-------------- SolutionComp.h => ISolutionComp.h | 23 +++++-------- 2 files changed, 33 insertions(+), 38 deletions(-) rename SolutionComp.cxx => ISolutionComp.cxx (84%) rename SolutionComp.h => ISolutionComp.h (70%) diff --git a/SolutionComp.cxx b/ISolutionComp.cxx similarity index 84% rename from SolutionComp.cxx rename to ISolutionComp.cxx index 8aabc078..0035ba56 100644 --- a/SolutionComp.cxx +++ b/ISolutionComp.cxx @@ -2,7 +2,7 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "SolutionComp.h" +#include "ISolutionComp.h" #include "ISolution.h" #include "Utils.h" #include @@ -11,7 +11,7 @@ #include "phrqproto.h" #include "phqalloc.h" -cxxSolutionComp::cxxSolutionComp(void) +cxxISolutionComp::cxxISolutionComp(void) : description(NULL) , moles(0.0) , input_conc(0.0) @@ -25,7 +25,7 @@ cxxSolutionComp::cxxSolutionComp(void) //, phase(NULL) { } -cxxSolutionComp::cxxSolutionComp(struct conc *conc_ptr) +cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr) { description = conc_ptr->description; moles = conc_ptr->moles; @@ -40,11 +40,11 @@ cxxSolutionComp::cxxSolutionComp(struct conc *conc_ptr) //phase = conc_ptr->phase; } -cxxSolutionComp::~cxxSolutionComp(void) +cxxISolutionComp::~cxxISolutionComp(void) { } /* -struct conc *cxxSolutionComp::concarray(std::map &totals) +struct conc *cxxISolutionComp::concarray(std::map &totals) // for Solutions, not ISolutions // takes a map of (elt name, moles) // returns list of conc structures @@ -71,16 +71,16 @@ struct conc *cxxSolutionComp::concarray(std::map return(c); } */ -struct conc *cxxSolutionComp::cxxSolutionComp2conc(const std::set &totals) +struct conc *cxxISolutionComp::cxxISolutionComp2conc(const std::set &totals) // for ISolutions - // takes a std::vector cxxSolutionComp structures + // takes a std::vector cxxISolutionComp structures // returns list of conc structures { struct conc *c; c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); if (c == NULL) malloc_error(); int i = 0; - for (std::set::const_iterator it = totals.begin(); it != totals.end(); ++it) { + for (std::set::const_iterator it = totals.begin(); it != totals.end(); ++it) { c[i].description = it->description; c[i].moles = it->moles; c[i].input_conc = it->input_conc; @@ -99,7 +99,7 @@ struct conc *cxxSolutionComp::cxxSolutionComp2conc(const std::set units = token1; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; } else { - return cxxSolutionComp::ERROR; + return cxxISolutionComp::ERROR; } } @@ -173,49 +173,49 @@ cxxSolutionComp::STATUS_TYPE cxxSolutionComp::read(CParser& parser, cxxISolution { parser.copy_token(token, ptr); this->as = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; } // Check for "gfw" followed by gram formula weight else if (token1.compare("gfw") == 0) { if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); - return cxxSolutionComp::ERROR; + return cxxISolutionComp::ERROR; } else { parser.get_iss() >> this->gfw; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; } } // Check for redox couple for pe if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; } else if (token.find("/") != std::string::npos) { if (parser.parse_couple(token) == CParser::OK) { this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; } else { - return cxxSolutionComp::ERROR; + return cxxISolutionComp::ERROR; } } // Must have phase this->equation_name = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxSolutionComp::OK; + if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; // Check for saturation index if (!(std::istringstream(token) >> this->phase_si)) { parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); - return cxxSolutionComp::ERROR; + return cxxISolutionComp::ERROR; } - return cxxSolutionComp::OK; + return cxxISolutionComp::OK; } #endif #ifdef SKIP -void cxxSolutionComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void cxxISolutionComp::dump_xml(std::ostream& s_oss, unsigned int indent)const { unsigned int i; std::string indent0(""); diff --git a/SolutionComp.h b/ISolutionComp.h similarity index 70% rename from SolutionComp.h rename to ISolutionComp.h index b9bbaa66..420f2118 100644 --- a/SolutionComp.h +++ b/ISolutionComp.h @@ -1,5 +1,5 @@ -#if !defined(SOLUTIONCOMP_H_INCLUDED) -#define SOLUTIONCOMP_H_INCLUDED +#if !defined(ISOLUTIONCOMP_H_INCLUDED) +#define ISOLUTIONCOMP_H_INCLUDED //#include "Parser.h" #include "Utils.h" @@ -13,17 +13,12 @@ // forward declarations class cxxISolution; // reqd for read and dump_xml -class cxxSolutionComp +class cxxISolutionComp { public: - cxxSolutionComp(void); - cxxSolutionComp(struct conc *conc_ptr); - ~cxxSolutionComp(void); - - enum STATUS_TYPE { - ERROR = 0, - OK = 1 - }; + cxxISolutionComp(void); + cxxISolutionComp(struct conc *conc_ptr); + ~cxxISolutionComp(void); public: @@ -46,9 +41,9 @@ public: int get_n_pe()const {return this->n_pe;} void set_n_pe(int n_pe) {this->n_pe = n_pe;} - bool operator<(const cxxSolutionComp& conc)const { return ::strcmp(this->description, conc.description) < 0; } + bool operator<(const cxxISolutionComp& conc)const { return ::strcmp(this->description, conc.description) < 0; } - static struct conc * cxxSolutionComp2conc(const std::set &t ); + static struct conc * cxxISolutionComp2conc(const std::set &t ); private: char * description; @@ -62,4 +57,4 @@ private: double gfw; }; -#endif // SOLUTIONCOMP_H_INCLUDED +#endif // ISOLUTIONCOMP_H_INCLUDED From bc1198144870ac7771c7d59f2f1785be93f65a1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Feb 2006 21:24:28 +0000 Subject: [PATCH 0010/1077] Adding StorageBin git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@798 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 189 +++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 64 +++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 StorageBin.cxx create mode 100644 StorageBin.h diff --git a/StorageBin.cxx b/StorageBin.cxx new file mode 100644 index 00000000..ec2a094f --- /dev/null +++ b/StorageBin.cxx @@ -0,0 +1,189 @@ +// StorageBin.cxx: implementation of the cxxStorageBin class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Utils.h" // define first +#include "StorageBin.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxStorageBin::cxxStorageBin() + // + // default constructor for cxxStorageBin + // +{ +} + +cxxStorageBin::~cxxStorageBin() +{ +} + + + +#ifdef SKIP +void cxxStorageBin::dump_xml(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + + // StorageBin element and attributes + s_oss << indent0; + s_oss << "pitzer_mix_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif + +void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const +{ + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + s_oss.precision(DBL_DIG - 1); + + // Solutions + + // for (std::map::const_iterator it = this->Solutions.begin(); it != this->Solutions.end(); ++it) { + //it->second.dump_raw(s_oss, indent); + //} + // Exchange + for (std::map::const_iterator it = this->Exchangers.begin(); it != this->Exchangers.end(); ++it) { + it->second.dump_raw(s_oss, indent); + + } + // Gas Phases + for (std::map::const_iterator it = this->GasPhases.begin(); it != this->GasPhases.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // Kinetics + for (std::map::const_iterator it = this->Kinetics.begin(); it != this->Kinetics.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // PPassemblage + for (std::map::const_iterator it = this->PPassemblages.begin(); it != this->PPassemblages.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // SSassemblage + for (std::map::const_iterator it = this->SSassemblages.begin(); it != this->SSassemblages.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } + // Surface + for (std::map::const_iterator it = this->Surfaces.begin(); it != this->Surfaces.end(); ++it) { + it->second.dump_raw(s_oss, indent); + } +} + +void cxxStorageBin::read_raw(CParser& parser) +{ + CParser::LINE_TYPE i; + while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) return; // CParser::LT_EOF; + } + + for (;;) { + switch(parser.next_keyword()) + { + case CParser::KT_END: + case CParser::KT_EOF: + case CParser::KT_NONE: + goto END_OF_SIMULATION_INPUT; + break; + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ + case CParser::KT_SOLUTION_RAW: + { + cxxSolution entity; + entity.read_raw(parser); + Solutions[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_EXCHANGE_RAW: + { + cxxExchange entity; + entity.read_raw(parser); + Exchangers[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_GASPHASE_RAW: + { + cxxGasPhase entity; + entity.read_raw(parser); + GasPhases[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_KINETICS_RAW: + { + cxxKinetics entity; + entity.read_raw(parser); + Kinetics[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_PPASSEMBLAGE_RAW: + { + cxxPPassemblage entity; + entity.read_raw(parser); + PPassemblages[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_SSASSEMBLAGE_RAW: + { + cxxSSassemblage entity; + entity.read_raw(parser); + SSassemblages[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_SURFACE_RAW: + { + cxxSurface entity; + entity.read_raw(parser); + Surfaces[entity.get_n_user()] = entity; + } + break; + + default: + break; + } + } + +END_OF_SIMULATION_INPUT: + return; //CParser::LT_OK; +} + diff --git a/StorageBin.h b/StorageBin.h new file mode 100644 index 00000000..0eb7a539 --- /dev/null +++ b/StorageBin.h @@ -0,0 +1,64 @@ +#if !defined(STORAGEBIN_H_INCLUDED) +#define STORAGEBIN_H_INCLUDED + +#include "Parser.h" +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "KineticsCxx.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" + +#include "Mix.h" +#include "Reaction.h" +#include "Temperature.h" + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +template +bool exists (std::map b, int i){ + return (b.find(i) != b.end());} + +class cxxStorageBin +{ + +public: + cxxStorageBin(); + ~cxxStorageBin(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; + + void read_raw(CParser& parser); + +protected: + // Tidied classes + std::map Solutions; + std::map Exchangers; + std::map GasPhases; + std::map Kinetics; + std::map PPassemblages; + std::map SSassemblages; + std::map Surfaces; + + //bool b = exists (Solutions, 5); + // Initial classes + //std::map ISolutions; + + // Reaction classes + std::map Mixes; + std::map Reactions; + std::map Temperatures; + +public: + //static std::map& map; + +}; + +#endif // !defined(STORAGEBIN_H_INCLUDED) From e2b5a47014ae7d7199284094829b666d65bff727 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 28 Feb 2006 16:56:34 +0000 Subject: [PATCH 0011/1077] Dump_raw for storage bin works, but have not tested. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@800 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 12 +++++++- StorageBin.cxx | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-- Utils.h | 20 ++++++++----- 3 files changed, 101 insertions(+), 11 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 5ae7438b..1b0f71c6 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -817,11 +817,11 @@ cxxSolution& cxxSolution::read(CParser& parser) #include void test_classes(void) { - int i; /* + int i; std::map Solutions; cxxSolution soln(solution[0]); Solutions[solution[0]->n_user] = soln; @@ -834,6 +834,7 @@ void test_classes(void) x[solution[0]->n_user] = soln; */ +#ifdef SKIP for (i=0; i < count_solution; i++) { if (solution[i]->new_def == TRUE) { cxxISolution sol(solution[i]); @@ -1115,4 +1116,13 @@ void test_classes(void) free_check_null(temperature_ptr); } +#endif + { + cxxStorageBin cstorage; + std::ostringstream oss; + cstorage.dump_raw(oss, 0); + std::cerr << oss.str(); + //char string[200]; + //strcpy_s(string, "abc"); + } } diff --git a/StorageBin.cxx b/StorageBin.cxx index ec2a094f..a6c1c5b5 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -7,6 +7,7 @@ #include "Utils.h" // define first #include "StorageBin.h" +#include "Solution.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -21,8 +22,60 @@ cxxStorageBin::cxxStorageBin() // // default constructor for cxxStorageBin + // pull data out of c storage // { + int i; + + // Solutions + for (i = 0; i < count_solution; i++) { + Solutions[solution[i]->n_user] = cxxSolution(solution[i]); + } + + // Exchangers + for (i = 0; i < count_exchange; i++) { + Exchangers[exchange[i].n_user] = cxxExchange(&exchange[i]); + } + + // GasPhases + for (i = 0; i < count_gas_phase; i++) { + GasPhases[gas_phase[i].n_user] = cxxGasPhase(&gas_phase[i]); + } + + // Kinetics + for (i = 0; i < count_kinetics; i++) { + Kinetics[kinetics[i].n_user] = cxxKinetics(&kinetics[i]); + } + + // PPassemblages + for (i = 0; i < count_pp_assemblage; i++) { + PPassemblages[pp_assemblage[i].n_user] = cxxPPassemblage(&pp_assemblage[i]); + } + + // SSassemblages + for (i = 0; i < count_s_s_assemblage; i++) { + SSassemblages[s_s_assemblage[i].n_user] = cxxSSassemblage(&s_s_assemblage[i]); + } + + // Surfaces + for (i = 0; i < count_surface; i++) { + Surfaces[surface[i].n_user] = cxxSurface(&surface[i]); + } + + // Mixes + for (i = 0; i < count_mix; i++) { + Mixes[mix[i].n_user] = cxxMix(&mix[i]); + } + + // Reactions + for (i = 0; i < count_irrev; i++) { + Reactions[irrev[i].n_user] = cxxReaction(&irrev[i]); + } + + // Temperatures + for (i = 0; i < count_temperature; i++) { + Temperatures[temperature[i].n_user] = cxxTemperature(&temperature[i]); + } } cxxStorageBin::~cxxStorageBin() @@ -66,35 +119,58 @@ void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss.precision(DBL_DIG - 1); // Solutions - - // for (std::map::const_iterator it = this->Solutions.begin(); it != this->Solutions.end(); ++it) { + Utilities::dump_raw(Solutions, s_oss, indent); + //for (std::map::const_iterator it = this->Solutions.begin(); it != this->Solutions.end(); ++it) { //it->second.dump_raw(s_oss, indent); //} + // Exchange + Utilities::dump_raw(Exchangers, s_oss, indent); + /* for (std::map::const_iterator it = this->Exchangers.begin(); it != this->Exchangers.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ + // Gas Phases + Utilities::dump_raw(GasPhases, s_oss, indent); + /* for (std::map::const_iterator it = this->GasPhases.begin(); it != this->GasPhases.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ // Kinetics + Utilities::dump_raw(Kinetics, s_oss, indent); + /* for (std::map::const_iterator it = this->Kinetics.begin(); it != this->Kinetics.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ + // PPassemblage + Utilities::dump_raw(PPassemblages, s_oss, indent); + /* for (std::map::const_iterator it = this->PPassemblages.begin(); it != this->PPassemblages.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ + // SSassemblage + Utilities::dump_raw(SSassemblages, s_oss, indent); + /* for (std::map::const_iterator it = this->SSassemblages.begin(); it != this->SSassemblages.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ + // Surface + Utilities::dump_raw(Surfaces, s_oss, indent); + /* for (std::map::const_iterator it = this->Surfaces.begin(); it != this->Surfaces.end(); ++it) { it->second.dump_raw(s_oss, indent); } + */ } void cxxStorageBin::read_raw(CParser& parser) diff --git a/Utils.h b/Utils.h index 714a5bae..05059306 100644 --- a/Utils.h +++ b/Utils.h @@ -32,21 +32,25 @@ namespace Utilities { void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) - template - bool exists (std::map b, int i){ - return (b.find(i) != b.end());} - - /* - template - void dump_raw ( std::map b, std::ostream& s_oss, unsigned int indent ) + template + void dump_raw (const T &b, std::ostream& s_oss, unsigned int indent) { - std :: map < int, T > :: iterator it; + //std :: map < int, T > :: const_iterator it; + typename T::const_iterator it; for (it = b.begin(); it != b.end(); ++it) { it->second.dump_raw(s_oss, indent); } return; } + template + bool exists (const T &b, int i){ + return (b.find(i) != b.end());} + /* + template + bool exists (std::map b, int i){ + return (b.find(i) != b.end());} */ + } #endif // UTILITIES_H_INCLUDED From 957551d0a7a95b7cb67333b7b1a7f27d00abcb08 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 8 Mar 2006 14:54:34 +0000 Subject: [PATCH 0012/1077] Updates git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@837 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 27 +++++++++++++++++++---- StorageBin.cxx | 60 +++++++++++++------------------------------------- StorageBin.h | 9 ++++---- 3 files changed, 43 insertions(+), 53 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 1b0f71c6..e1b6a5b0 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -14,6 +14,7 @@ #include // assert #include // std::sort + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -1118,11 +1119,29 @@ void test_classes(void) } #endif { + // get all c storage + cxxStorageBin cstorage(cxxStorageBin::SB_GLOBAL); + //std::ostringstream oss; + //cstorage.dump_raw(oss, 0); + //write it out + std::fstream myfile; + myfile.open("tfile", std::ios_base::out); + cstorage.dump_raw(myfile, 0); + myfile.close(); + } + { + // empty storage bin cxxStorageBin cstorage; + // fstream + std::fstream myfile; + myfile.open("tfile", std::ios_base::in); + // ostream std::ostringstream oss; - cstorage.dump_raw(oss, 0); - std::cerr << oss.str(); - //char string[200]; - //strcpy_s(string, "abc"); + // parser + CParser cparser(myfile, oss, std::cerr); + cstorage.read_raw(cparser); + //std::cerr << oss.str(); + + // read it back } } diff --git a/StorageBin.cxx b/StorageBin.cxx index a6c1c5b5..aa366801 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -18,8 +18,11 @@ ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// - cxxStorageBin::cxxStorageBin() +{ +} + +cxxStorageBin::cxxStorageBin(cxxStorageBin::SB_CONSTRUCTOR flag) // // default constructor for cxxStorageBin // pull data out of c storage @@ -120,63 +123,30 @@ void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const // Solutions Utilities::dump_raw(Solutions, s_oss, indent); - //for (std::map::const_iterator it = this->Solutions.begin(); it != this->Solutions.end(); ++it) { - //it->second.dump_raw(s_oss, indent); - //} // Exchange Utilities::dump_raw(Exchangers, s_oss, indent); - /* - for (std::map::const_iterator it = this->Exchangers.begin(); it != this->Exchangers.end(); ++it) { - it->second.dump_raw(s_oss, indent); - - } - */ // Gas Phases Utilities::dump_raw(GasPhases, s_oss, indent); - /* - for (std::map::const_iterator it = this->GasPhases.begin(); it != this->GasPhases.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - */ + // Kinetics Utilities::dump_raw(Kinetics, s_oss, indent); - /* - for (std::map::const_iterator it = this->Kinetics.begin(); it != this->Kinetics.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - */ // PPassemblage Utilities::dump_raw(PPassemblages, s_oss, indent); - /* - for (std::map::const_iterator it = this->PPassemblages.begin(); it != this->PPassemblages.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - */ // SSassemblage Utilities::dump_raw(SSassemblages, s_oss, indent); - /* - for (std::map::const_iterator it = this->SSassemblages.begin(); it != this->SSassemblages.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - */ // Surface Utilities::dump_raw(Surfaces, s_oss, indent); - /* - for (std::map::const_iterator it = this->Surfaces.begin(); it != this->Surfaces.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - */ } void cxxStorageBin::read_raw(CParser& parser) { CParser::LINE_TYPE i; - while ((i = parser.check_line("Subroutine Read", false, true, true, true)) != CParser::LT_KEYWORD) + while ((i = parser.check_line("StorageBin read_raw", false, true, true, true)) != CParser::LT_KEYWORD) { if (i == CParser::LT_EOF) return; // CParser::LT_EOF; } @@ -189,15 +159,15 @@ void cxxStorageBin::read_raw(CParser& parser) case CParser::KT_NONE: goto END_OF_SIMULATION_INPUT; break; - /* - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 - */ + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ case CParser::KT_SOLUTION_RAW: { cxxSolution entity; diff --git a/StorageBin.h b/StorageBin.h index 0eb7a539..343bebe3 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -20,15 +20,16 @@ #include // std::list #include // std::vector -template -bool exists (std::map b, int i){ - return (b.find(i) != b.end());} - class cxxStorageBin { public: + enum SB_CONSTRUCTOR { + SB_GLOBAL = 1 + }; + cxxStorageBin(); + cxxStorageBin(SB_CONSTRUCTOR flag); ~cxxStorageBin(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; From 3261c998918e2a1458e4cb0a6cadfadd9b8bac32 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 11 Apr 2006 23:41:57 +0000 Subject: [PATCH 0013/1077] Added class SolutionIsotopeList Working through using C++ structures in transport git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@855 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 56 ++++++++++------- Mix.h | 2 + NameDouble.cxx | 32 ++++++++++ NameDouble.h | 6 +- Solution.cxx | 136 ++++++++++++++++++++++++++++++++++++++-- Solution.h | 24 +++++-- SolutionIsotope.cxx | 13 ++++ SolutionIsotope.h | 5 +- SolutionIsotopeList.cxx | 78 +++++++++++++++++++++++ SolutionIsotopeList.h | 35 +++++++++++ StorageBin.cxx | 43 ++++++++++++- StorageBin.h | 14 ++++- Utils.h | 11 ++++ 13 files changed, 417 insertions(+), 38 deletions(-) create mode 100644 SolutionIsotopeList.cxx create mode 100644 SolutionIsotopeList.h diff --git a/Makefile b/Makefile index fb90ded5..1bcd9234 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,7 @@ COMMON_CXXOBJS = \ ExchComp.o \ GasPhase.o \ ISolution.o \ - SolutionIsotope.o \ + ISolutionComp.o \ KineticsComp.o \ KineticsCxx.o \ Mix.o \ @@ -155,7 +155,8 @@ COMMON_CXXOBJS = \ Reaction.o \ ReadClass.o \ Solution.o \ - ISolutionComp.o \ + SolutionIsotope.o \ + SolutionIsotopelist.o \ SSassemblage.o \ SSassemblageSS.o \ StorageBin.o \ @@ -255,27 +256,36 @@ ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h \ ../char_star.h ../Temperature.h ../NumKeyword.h ../char_star.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -Solution.o: ../Solution.cxx ../Utils.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../ISolution.h ../ISolutionComp.h ../Utils.h \ - ../char_star.h ../NumKeyword.h ../Solution.h ../Exchange.h \ - ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ - ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ - ../SurfComp.h ../NameDouble.h ../char_star.h ../SurfCharge.h \ - ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ - ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ - ../KineticsCxx.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ - ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ - ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ - ../NumKeyword.h ../char_star.h ../Temperature.h ../NumKeyword.h \ - ../char_star.h +Solution.o: ../Solution.cxx ../Utils.h ../char_star.h ../Solution.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../Mix.h ../NumKeyword.h ../char_star.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../ISolution.h ../ISolutionComp.h ../Utils.h ../char_star.h \ + ../NumKeyword.h ../Solution.h ../Exchange.h ../NumKeyword.h \ + ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ + ../Surface.h ../NumKeyword.h ../char_star.h ../SurfComp.h \ + ../NameDouble.h ../char_star.h ../SurfCharge.h ../NameDouble.h \ + ../char_star.h ../PPassemblage.h ../NumKeyword.h ../char_star.h \ + ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../KineticsCxx.h \ + ../NumKeyword.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ + ../char_star.h ../SSassemblage.h ../NumKeyword.h ../char_star.h \ + ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../GasPhase.h \ + ../NumKeyword.h ../NameDouble.h ../char_star.h ../Reaction.h \ + ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ + ../Temperature.h ../NumKeyword.h ../char_star.h ../StorageBin.h \ + ../Utils.h ../Parser.h ../Solution.h ../Exchange.h ../GasPhase.h \ + ../KineticsCxx.h ../PPassemblage.h ../SSassemblage.h ../Surface.h \ + ../Mix.h ../Reaction.h ../Temperature.h ../NumKeyword.h SolutionIsotope.o: ../SolutionIsotope.cxx ../SolutionIsotope.h \ - ../Parser.h ../char_star.h ../Utils.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Parser.h ../char_star.h ../Utils.h ../char_star.h ../Parser.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ + ../char_star.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../char_star.h ../Parser.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ @@ -418,7 +428,7 @@ clean: dependencies: mkdir -p $(DEBUG_DIR) - cd Debug; gcc -MM -I../phreeqc ../*.cxx + cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx # ============================================================================= diff --git a/Mix.h b/Mix.h index 9180c5b6..654df0d4 100644 --- a/Mix.h +++ b/Mix.h @@ -28,6 +28,8 @@ public: void read_raw(CParser& parser); + std::map comps() {return mixComps;} + protected: std::map mixComps; diff --git a/NameDouble.cxx b/NameDouble.cxx index d1ed6b94..5661c4dd 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -39,6 +39,22 @@ cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr) } this->type = ND_ELT_MOLES; } +cxxNameDouble::cxxNameDouble(const cxxNameDouble &old, double factor) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { + if (old.type == ND_ELT_MOLES) { + if (it->second * factor > 0) { + (*this)[(it->first)] = it->second * factor; + } + } else { + (*this)[(it->first)] = it->second * factor; + } + } + this->type = old.type; +} cxxNameDouble::cxxNameDouble(struct conc *tots) // // constructor for cxxNameDouble from list of elt_list @@ -256,3 +272,19 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_ (*this)[ctoken] = d; return CParser::PARSER_OK; } + +void cxxNameDouble::add(const cxxNameDouble &old, double factor) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) { + (*this)[it->first] = current->second + it->second * factor; + } else { + (*this)[it->first] = it->second * factor; + } + } + +} diff --git a/NameDouble.h b/NameDouble.h index 6dc61b4a..4ac90000 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -27,6 +27,7 @@ public: cxxNameDouble(struct conc *); cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); cxxNameDouble(struct name_coef *nc, int count, ND_TYPE); + cxxNameDouble(const cxxNameDouble &old, double factor); ~cxxNameDouble(); struct elt_list *elt_list(); @@ -43,9 +44,12 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); - enum ND_TYPE type; + void add(const cxxNameDouble &old, double factor); + enum ND_TYPE type; + protected: + //std::map totals; diff --git a/Solution.cxx b/Solution.cxx index e1b6a5b0..b8173fed 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -19,6 +19,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// + cxxSolution::cxxSolution() // // default constructor for cxxSolution @@ -39,7 +40,27 @@ cxxSolution::cxxSolution() master_activity.type = cxxNameDouble::ND_SPECIES_LA; species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } - +cxxSolution::cxxSolution(double zero) + // + // empty cxxSolution constructor + // +: cxxNumKeyword() +{ + assert (zero == 0.0); + tc = 0.0; + ph = 0.0; + pe = 0.0; + mu = 0.0; + ah2o = 0.0; + total_h = 0.0; + total_o = 0.0; + cb = 0.0; + mass_water = 0.0; + total_alkalinity = 0.0; + totals.type = cxxNameDouble::ND_ELT_MOLES; + master_activity.type = cxxNameDouble::ND_SPECIES_LA; + species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; +} cxxSolution::cxxSolution(struct solution *solution_ptr) // // constructor for cxxSolution from struct solution @@ -48,9 +69,9 @@ cxxSolution::cxxSolution(struct solution *solution_ptr) cxxNumKeyword(), totals(solution_ptr->totals), master_activity(solution_ptr->master_activity, solution_ptr->count_master_activity, cxxNameDouble::ND_SPECIES_LA), -species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA) +species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA), +isotopes(solution_ptr) { - int i; this->set_description(solution_ptr->description); n_user = solution_ptr->n_user; @@ -69,19 +90,58 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cx // Totals filled in constructor, just save description and moles // Isotopes + /* for (i = 0; i < solution_ptr->count_isotopes; i++) { cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); isotopes.push_back(iso); } - + */ // Master_activity in constructor // Species_gamma in constructor } +#ifdef SKIP +cxxSolution::cxxSolution(const cxxSolution &old, double intensive, double extensive) + // + // constructor for cxxSolution from struct solution + // +: +cxxNumKeyword(), +totals(old.totals, extensive), +master_activity(old.master_activity, intensive), +species_gamma(old.species_gamma, intensive) +{ + + this->set_description(old.description); + this->n_user = old.n_user; + this->n_user_end = old.n_user_end; + this->tc = old.tc * intensive; + this->ph = old.ph * intensive; + this->pe = old.pe * intensive; + this->mu = old.mu * intensive; + this->ah2o = old.ah2o * intensive; + this->total_h = old.total_h * extensive; + this->total_o = old.total_o * extensive; + this->cb = old.cb * extensive; + this->mass_water = old.mass_water * extensive; + this->total_alkalinity = old.total_alkalinity * extensive; + /* + cxxNameDouble totals; + std::list isotopes; + cxxNameDouble master_activity; + cxxNameDouble species_gamma; + */ + for (std::list::const_iterator it = old.isotopes.begin(); it != old.isotopes.end(); it++) { + this->isotopes.push_back(cxxSolutionIsotope((*it), intensive, extensive)); + } +} +#endif + cxxSolution::~cxxSolution() { } + struct solution *cxxSolution::cxxSolution2solution() // // Builds a solution structure from instance of cxxSolution @@ -124,7 +184,8 @@ struct solution *cxxSolution::cxxSolution2solution() // isotopes solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); + //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); + solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(); solution_ptr->count_isotopes = this->isotopes.size(); return(solution_ptr); @@ -607,6 +668,70 @@ void cxxSolution::read_raw(CParser& parser) return; } +void cxxSolution::add(const cxxSolution &old, double intensive, double extensive) + // + // Add existing solution to "this" solution + // +{ + + this->tc += old.tc * intensive; + this->ph += old.ph * intensive; + this->pe += old.pe * intensive; + this->mu += old.mu * intensive; + this->ah2o += old.ah2o * intensive; + this->total_h += old.total_h * extensive; + this->total_o += old.total_o * extensive; + this->cb += old.cb * extensive; + this->mass_water += old.mass_water * extensive; + this->total_alkalinity += old.total_alkalinity * extensive; + + this->totals.add(old.totals, extensive); + this->master_activity.add(old.master_activity, intensive); + this->species_gamma.add(old.species_gamma, intensive); + this->isotopes.add(old.isotopes, intensive, extensive); + +#ifdef SKIP + // + // isotopes + // go through old list, update or add to current list + // + for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) { + this->isotopes.push_back(*itold); + } + } +#endif + /* + cxxNameDouble totals; + std::list isotopes; + cxxNameDouble master_activity; + cxxNameDouble species_gamma; + */ +} + +double cxxSolution::get_total(char *string)const +{ + cxxNameDouble::const_iterator it = this->totals.find(string); + if (it == this->totals.end()) { + return(0.0); + } else { + return(it->second); + } +} + #ifdef SKIP cxxSolution& cxxSolution::read(CParser& parser) { @@ -1145,3 +1270,4 @@ void test_classes(void) // read it back } } + diff --git a/Solution.h b/Solution.h index 131063f6..789871c1 100644 --- a/Solution.h +++ b/Solution.h @@ -2,8 +2,10 @@ #define SOLUTION_H_INCLUDED #include "NumKeyword.h" -#include "SolutionIsotope.h" +#include "SolutionIsotopeList.h" #include "NameDouble.h" +#include "Mix.h" + #define EXTERNAL extern #include "global.h" #include // assert @@ -19,7 +21,11 @@ class cxxSolution : public cxxNumKeyword public: cxxSolution(); + cxxSolution(double zero); cxxSolution(struct solution *); + cxxSolution(const std::map &solution_map, cxxMix &mx); + cxxSolution(const cxxSolution &old, double intensive, double extensive); + //cxxSolution(const cxxSolution&); ~cxxSolution(); @@ -41,17 +47,21 @@ public: void set_ah2o(double ah2o) {this->pe = ah2o;} double get_total_h()const {return this->total_h;} - void set_total_h(double total_h) {this->pe = mu;} + void set_total_h(double total_h) {this->pe = total_h;} double get_total_o()const {return this->total_o;} - void set_total_o(double total_o) {this->pe = mu;} + void set_total_o(double total_o) {this->pe = total_o;} - double get_mass_water()const {return this->mass_water;}; - void set_mass_water(long double mass_water) {this->mass_water = mass_water;}; + double get_mass_water()const {return this->mass_water;} + void set_mass_water(long double mass_water) {this->mass_water = mass_water;} double get_total_alkalinity()const {return this->total_alkalinity;} void set_total_alkalinity(double total_alkalinity) {this->pe = total_alkalinity;} + double get_cb()const {return this->cb;} + void set_cb(double cb) {this->cb = cb;} + + double get_total(char *string)const; //char * get_pe_reaction()const {return this->pe_reaction;} //void set_pe_reaction(char * pe_reaction) {this->pe_reaction = pe_reaction;} @@ -63,6 +73,7 @@ public: void read_raw(CParser& parser); + void add(const cxxSolution &sol, double intensive, double extensive); protected: double tc; @@ -76,9 +87,10 @@ protected: double mass_water; double total_alkalinity; cxxNameDouble totals; - std::list isotopes; + //std::list isotopes; cxxNameDouble master_activity; cxxNameDouble species_gamma; + cxxSolutionIsotopeList isotopes; public: //static std::map& map; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 54afd61d..25be4d72 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -26,6 +26,7 @@ cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) ratio_uncertainty = isotope_ptr->ratio_uncertainty; } + cxxSolutionIsotope::~cxxSolutionIsotope(void) { } @@ -185,6 +186,18 @@ struct master *cxxSolutionIsotope::primary(void) return (master_bsearch_primary(this->elt_name)); } +void cxxSolutionIsotope::add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive) +{ + if ((this->isotope_number == isotope_ptr.isotope_number) && + (this->elt_name == isotope_ptr.elt_name) && + (this->isotope_name == isotope_ptr.isotope_name)) { + this->total += isotope_ptr.total * extensive; + this->ratio += isotope_ptr.ratio * intensive; + this->ratio_uncertainty += isotope_ptr.ratio_uncertainty * intensive; + this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined || isotope_ptr.ratio_uncertainty_defined); + } +} + #ifdef SKIP cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser& parser) { diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 4fbd821c..4539b1a1 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -42,7 +42,10 @@ public: struct master *master(void); struct master *primary(void); -private: + void add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive); + +protected: + friend class cxxSolutionIsotopeList; double isotope_number; char * elt_name; char * isotope_name; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx new file mode 100644 index 00000000..3ff40e60 --- /dev/null +++ b/SolutionIsotopeList.cxx @@ -0,0 +1,78 @@ +#include "Utils.h" // define first +#include "SolutionIsotopeList.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include // assert +#include // std::sort + +cxxSolutionIsotopeList::cxxSolutionIsotopeList(void) + // + // default constructor for cxxSolution + // +{ +} + +cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) +{ + int i; + // Isotopes + for (i = 0; i < solution_ptr->count_isotopes; i++) { + //cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); + (*this).push_back(&solution_ptr->isotopes[i]); + } +} +void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) +{ + + for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { + + //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) { + cxxSolutionIsotope iso; + iso.total = itold->total * extensive; + iso.ratio = itold->ratio * intensive; + iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; + iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; + this->push_back(iso); + } + } +} +struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() +{ + struct isotope *iso; + if (this->size() <= 0) { + return NULL; + } else { + iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + if (iso == NULL) malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return(iso); +} + diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h new file mode 100644 index 00000000..92301ab1 --- /dev/null +++ b/SolutionIsotopeList.h @@ -0,0 +1,35 @@ +#if !defined(SOLUTIONISOTOPELIST_H_INCLUDED) +#define SOLUTIONISOTOPELIST_H_INCLUDED + +#define EXTERNAL extern +#include "SolutionIsotope.h" +#include "global.h" +#include // assert +#include // std::string +#include // std::list + +#include "char_star.h" +#include "Parser.h" +class cxxSolutionIsotopeList : public std::list +{ + +public: + cxxSolutionIsotopeList(); + + cxxSolutionIsotopeList(struct solution *solution_ptr); + + ~cxxSolutionIsotopeList(); + + struct isotope *cxxSolutionIsotopeList2isotope(); + + void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); + +protected: + + +public: + + +}; + +#endif // !defined(SOLUTIONISOTOPELIST_H_INCLUDED) diff --git a/StorageBin.cxx b/StorageBin.cxx index aa366801..95ad6082 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -20,11 +20,11 @@ ////////////////////////////////////////////////////////////////////// cxxStorageBin::cxxStorageBin() { + // default constructor for cxxStorageBin } cxxStorageBin::cxxStorageBin(cxxStorageBin::SB_CONSTRUCTOR flag) // - // default constructor for cxxStorageBin // pull data out of c storage // { @@ -233,3 +233,44 @@ END_OF_SIMULATION_INPUT: return; //CParser::LT_OK; } +void cxxStorageBin::add(struct system * system_ptr) + // + // add data from a system structure + // +{ + + // Solutions + if (system_ptr->solution != NULL) { + this->Solutions[system_ptr->solution->n_user] = cxxSolution(system_ptr->solution); + } + + // Exchangers + if (system_ptr->exchange != NULL) { + this->Exchangers[system_ptr->exchange->n_user] = cxxExchange(system_ptr->exchange); + } + + // GasPhases + if (system_ptr->gas_phase != NULL) { + this->GasPhases[system_ptr->gas_phase->n_user] = cxxGasPhase(system_ptr->gas_phase); + } + + // Kinetics + if (system_ptr->kinetics != NULL) { + this->Kinetics[system_ptr->kinetics->n_user] = cxxKinetics(system_ptr->kinetics); + } + + // PPassemblages + if (system_ptr->pp_assemblage != NULL) { + this->PPassemblages[system_ptr->pp_assemblage->n_user] = cxxPPassemblage(system_ptr->pp_assemblage); + } + + // SSassemblages + if (system_ptr->s_s_assemblage != NULL) { + this->SSassemblages[system_ptr->s_s_assemblage->n_user] = cxxSSassemblage(system_ptr->s_s_assemblage); + } + + // Surfaces + if (system_ptr->surface != NULL) { + this->Surfaces[system_ptr->surface->n_user] = cxxSurface(system_ptr->surface); + } +} diff --git a/StorageBin.h b/StorageBin.h index 343bebe3..a9153b78 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -1,6 +1,7 @@ #if !defined(STORAGEBIN_H_INCLUDED) #define STORAGEBIN_H_INCLUDED +#include "Utils.h" #include "Parser.h" #include "Solution.h" #include "Exchange.h" @@ -9,7 +10,6 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "Surface.h" - #include "Mix.h" #include "Reaction.h" #include "Temperature.h" @@ -34,10 +34,22 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + struct cxxSolution *get_solution(int i) { + //cxxSolution *solution_ptr = Utilities::get_entity(this->Solutions, i); + return(Utilities::get_entity(this->Solutions, i)); + //if (this->Solutions.find(i) != this->Solutions.end()) { + //return(&(this->Solutions.find(i)->second)); + //} else { + //return(NULL); + //} + } + void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); + void add(struct system *sys_ptr); + protected: // Tidied classes std::map Solutions; diff --git a/Utils.h b/Utils.h index 05059306..148ca967 100644 --- a/Utils.h +++ b/Utils.h @@ -45,6 +45,17 @@ namespace Utilities { template bool exists (const T &b, int i){ return (b.find(i) != b.end());} + + template + T *get_entity(std::map b, int i) { + if (b.find(i) != b.end()) { + return(&(b.find(i)->second)); + } else { + return (NULL); + } + } + + /* template bool exists (std::map b, int i){ From 574da9a1ace19d2c207af3b34dea1058a20d4acf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 12 Apr 2006 21:44:32 +0000 Subject: [PATCH 0014/1077] Working on phast driver to use classes for main storage git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@859 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 2 +- Solution.cxx | 23 ++++++- Solution.h | 30 ++++++--- SolutionIsotopeList.cxx | 7 ++ StorageBin.cxx | 144 ++++++++++++++++++++++++++++++++++++++-- StorageBin.h | 28 ++++---- 6 files changed, 202 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 1bcd9234..b6844869 100644 --- a/Makefile +++ b/Makefile @@ -156,7 +156,7 @@ COMMON_CXXOBJS = \ ReadClass.o \ Solution.o \ SolutionIsotope.o \ - SolutionIsotopelist.o \ + SolutionIsotopeList.o \ SSassemblage.o \ SSassemblageSS.o \ StorageBin.o \ diff --git a/Solution.cxx b/Solution.cxx index b8173fed..d038e147 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -732,6 +732,26 @@ double cxxSolution::get_total(char *string)const } } +void cxxSolution::set_total(char *string, double d) +{ + this->totals[string] = d; +} + +double cxxSolution::get_master_activity(char *string)const +{ + cxxNameDouble::const_iterator it = this->master_activity.find(string); + if (it == this->master_activity.end()) { + return(0.0); + } else { + return(it->second); + } +} + +void cxxSolution::set_master_activity(char *string, double d) +{ + this->master_activity[string] = d; +} + #ifdef SKIP cxxSolution& cxxSolution::read(CParser& parser) { @@ -1245,7 +1265,8 @@ void test_classes(void) #endif { // get all c storage - cxxStorageBin cstorage(cxxStorageBin::SB_GLOBAL); + cxxStorageBin cstorage; + cstorage.import_phreeqc(); //std::ostringstream oss; //cstorage.dump_raw(oss, 0); //write it out diff --git a/Solution.h b/Solution.h index 789871c1..4e2bf157 100644 --- a/Solution.h +++ b/Solution.h @@ -41,29 +41,39 @@ public: void set_pe(double pe) {this->pe =pe;} double get_mu()const {return this->mu;} - void set_mu(double mu) {this->pe = mu;} + void set_mu(double mu) {this->mu = mu;} double get_ah2o()const {return this->ah2o;} - void set_ah2o(double ah2o) {this->pe = ah2o;} + void set_ah2o(double ah2o) {this->ah2o = ah2o;} double get_total_h()const {return this->total_h;} - void set_total_h(double total_h) {this->pe = total_h;} + void set_total_h(double total_h) {this->total_h = total_h;} double get_total_o()const {return this->total_o;} - void set_total_o(double total_o) {this->pe = total_o;} + void set_total_o(double total_o) {this->total_o = total_o;} + + double get_cb()const {return this->cb;} + void set_cb(double cb) {this->cb = cb;} double get_mass_water()const {return this->mass_water;} void set_mass_water(long double mass_water) {this->mass_water = mass_water;} double get_total_alkalinity()const {return this->total_alkalinity;} - void set_total_alkalinity(double total_alkalinity) {this->pe = total_alkalinity;} - - double get_cb()const {return this->cb;} - void set_cb(double cb) {this->cb = cb;} + void set_total_alkalinity(double total_alkalinity) {this->total_alkalinity = total_alkalinity;} double get_total(char *string)const; - //char * get_pe_reaction()const {return this->pe_reaction;} - //void set_pe_reaction(char * pe_reaction) {this->pe_reaction = pe_reaction;} + void set_total(char *string, double value); + + double get_master_activity(char *string)const; + void set_master_activity(char *string, double value); + + /* + double get_species_gamma(char *string)const; + void set_species_gamma(char *string, double value); + + double get_isotope(char *string)const; + void set_isotope(char *string, double value); + */ struct solution *cxxSolution2solution(); diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 3ff40e60..88a0d135 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -14,6 +14,13 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList(void) { } +cxxSolutionIsotopeList::~cxxSolutionIsotopeList(void) + // + // default destructor for cxxSolution + // +{ +} + cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) { int i; diff --git a/StorageBin.cxx b/StorageBin.cxx index 95ad6082..c0053b6a 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -12,6 +12,7 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort @@ -23,7 +24,11 @@ cxxStorageBin::cxxStorageBin() // default constructor for cxxStorageBin } -cxxStorageBin::cxxStorageBin(cxxStorageBin::SB_CONSTRUCTOR flag) +cxxStorageBin::~cxxStorageBin() +{ +} + +void cxxStorageBin::import_phreeqc(void) // // pull data out of c storage // @@ -81,11 +86,6 @@ cxxStorageBin::cxxStorageBin(cxxStorageBin::SB_CONSTRUCTOR flag) } } -cxxStorageBin::~cxxStorageBin() -{ -} - - #ifdef SKIP void cxxStorageBin::dump_xml(std::ostream& s_oss, unsigned int indent)const @@ -274,3 +274,135 @@ void cxxStorageBin::add(struct system * system_ptr) this->Surfaces[system_ptr->surface->n_user] = cxxSurface(system_ptr->surface); } } + +void cxxStorageBin::cxxStorageBin2phreeqc(int n) + // + // copy data fromphreeqc storage to storage bin + // +{ + + // Solutions + { + + std::map ::iterator it = this->Solutions.find(n); + if (it != this->Solutions.end()){ + solution[0] = (it->second).cxxSolution2solution(); + solution[0]->n_user = n; + solution[0]->n_user_end = n; + count_solution++; + } else { + error_msg("cxxSolution not found in system2phreeqc", STOP); + } + } + + // Exchangers + { + std::map ::iterator it = this->Exchangers.find(n); + if ( it != this->Exchangers.end()) { + struct exchange *exchange_ptr = (it->second).cxxExchange2exchange(); + exchange_copy(exchange_ptr, &exchange[0], n); + count_exchange++; + } + } + + // GasPhases + { + std::map ::iterator it = this->GasPhases.find(n); + if ( it != this->GasPhases.end()) { + struct gas_phase *gas_phase_ptr = (it->second).cxxGasPhase2gas_phase(); + gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); + count_gas_phase++; + } + } + + // Kinetics + { + std::map ::iterator it = this->Kinetics.find(n); + if ( it != this->Kinetics.end()) { + struct kinetics *kinetics_ptr = (it->second).cxxKinetics2kinetics(); + kinetics_copy(kinetics_ptr, &kinetics[0], n); + count_kinetics++; + } + } + + // PPassemblages + { + std::map ::iterator it = this->PPassemblages.find(n); + if ( it != this->PPassemblages.end()) { + struct pp_assemblage *pp_assemblage_ptr = (it->second).cxxPPassemblage2pp_assemblage(); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); + count_pp_assemblage++; + } + } + + // SSassemblages + { + std::map ::iterator it = this->SSassemblages.find(n); + if ( it != this->SSassemblages.end()) { + struct s_s_assemblage *s_s_assemblage_ptr = (it->second).cxxSSassemblage2s_s_assemblage(); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); + count_s_s_assemblage++; + } + } + + // Surfaces + { + std::map ::iterator it = this->Surfaces.find(n); + if ( it != this->Surfaces.end()) { + struct surface *surface_ptr = (it->second).cxxSurface2surface(); + surface_copy(surface_ptr, &surface[0], n); + count_surface++; + } + } + +} +void cxxStorageBin::phreeqc2cxxStorageBin(int n) + // + // copy data fromphreeqc storage to storage bin + // +{ + int pos; + + // Solutions + { + solution_bsearch(n, &pos, TRUE); + this->Solutions[n] = cxxSolution(solution[pos]); + } + + // Exchangers + { + exchange_bsearch(n, &pos); + this->Exchangers[n] = cxxExchange(&(exchange[pos])); + } + + // GasPhases + { + gas_phase_bsearch(n, &pos); + this->GasPhases[n] = cxxGasPhase(&(gas_phase[pos])); + } + + // Kinetics + { + kinetics_bsearch(n, &pos); + this->Kinetics[n] = cxxKinetics(&(kinetics[pos])); + } + + // PPassemblages + { + pp_assemblage_bsearch(n, &pos); + this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos])); + } + + // SSassemblages + { + s_s_assemblage_bsearch(n, &pos); + this->SSassemblages[n] = cxxSSassemblage(&(s_s_assemblage[pos])); + } + + // Surfaces + { + surface_bsearch(n, &pos); + this->Surfaces[n] = cxxSurface(&(surface[pos])); + } + +} diff --git a/StorageBin.h b/StorageBin.h index a9153b78..eb76fee6 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -24,24 +24,24 @@ class cxxStorageBin { public: - enum SB_CONSTRUCTOR { - SB_GLOBAL = 1 - }; - cxxStorageBin(); - cxxStorageBin(SB_CONSTRUCTOR flag); + ~cxxStorageBin(); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void import_phreeqc(void); - struct cxxSolution *get_solution(int i) { - //cxxSolution *solution_ptr = Utilities::get_entity(this->Solutions, i); - return(Utilities::get_entity(this->Solutions, i)); - //if (this->Solutions.find(i) != this->Solutions.end()) { - //return(&(this->Solutions.find(i)->second)); - //} else { - //return(NULL); - //} + void cxxStorageBin2phreeqc(int n); + + void phreeqc2cxxStorageBin(int n); + + struct cxxSolution *get_solution(int n_user) { + if (this->Solutions.find(n_user) != this->Solutions.end()) { + return(&(this->Solutions.find(n_user)->second)); + } + return (NULL); + } + void set_solution(int n_user, cxxSolution soln) { + Solutions[n_user] = soln; } void dump_raw(std::ostream& s_oss, unsigned int indent)const; From c41fb4e5ec824db393aaff92eb1518f4d14fcf90 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 13 Apr 2006 21:16:33 +0000 Subject: [PATCH 0015/1077] phastpp works on linear_ic in debug mode. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@862 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 2 +- Mix.h | 3 +- NameDouble.cxx | 6 +- NameDouble.h | 2 +- Reaction.cxx | 2 +- Solution.cxx | 194 ----------------------------------------------- StorageBin.cxx | 84 ++++++++++++++++---- StorageBin.h | 2 + 8 files changed, 81 insertions(+), 214 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 7f06fb1b..7fe51281 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -36,7 +36,7 @@ cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr) // constructor for cxxKineticsComp from struct kinetics_comp // : -namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list, cxxNameDouble::ND_NAME_COEF) +namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) { rate_name = kinetics_comp_ptr->rate_name; tol = kinetics_comp_ptr->tol; diff --git a/Mix.h b/Mix.h index 654df0d4..8a7254b1 100644 --- a/Mix.h +++ b/Mix.h @@ -28,9 +28,10 @@ public: void read_raw(CParser& parser); - std::map comps() {return mixComps;} + std::map *comps() {return &mixComps;} protected: + friend class cxxStorageBin; std::map mixComps; public: diff --git a/NameDouble.cxx b/NameDouble.cxx index 5661c4dd..46bfe2f5 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -66,7 +66,7 @@ cxxNameDouble::cxxNameDouble(struct conc *tots) } this->type = ND_ELT_MOLES; } -cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE) +cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE type) // // constructor for cxxNameDouble from list of elt_list // @@ -76,9 +76,9 @@ cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDoubl if (ma[i].description == NULL) continue; (*this)[ma[i].description] = ma[i].la; } - this->type = ND_SPECIES_LA; + this->type = type; } -cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count, cxxNameDouble::ND_TYPE) +cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) // // constructor for cxxNameDouble from list of elt_list // diff --git a/NameDouble.h b/NameDouble.h index 4ac90000..da71a6a0 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -26,7 +26,7 @@ public: cxxNameDouble(struct elt_list *); cxxNameDouble(struct conc *); cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); - cxxNameDouble(struct name_coef *nc, int count, ND_TYPE); + cxxNameDouble(struct name_coef *nc, int count); cxxNameDouble(const cxxNameDouble &old, double factor); ~cxxNameDouble(); diff --git a/Reaction.cxx b/Reaction.cxx index 6a0af474..52151dc8 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -37,7 +37,7 @@ cxxReaction::cxxReaction(struct irrev *irrev_ptr) // : cxxNumKeyword(), -reactantList(irrev_ptr->list, irrev_ptr->count_list, cxxNameDouble::ND_NAME_COEF), +reactantList(irrev_ptr->list, irrev_ptr->count_list), elementList(irrev_ptr->elts) { int i; diff --git a/Solution.cxx b/Solution.cxx index d038e147..89f7be36 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -752,199 +752,6 @@ void cxxSolution::set_master_activity(char *string, double d) this->master_activity[string] = d; } -#ifdef SKIP -cxxSolution& cxxSolution::read(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxSolution numkey; - - // Read solution number and description - numkey.read_number_description(parser); - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - //cxxSolution& sol = s_map[numkey.n_user()]; - int default_pe = 0; - - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - break; - } - sol.solution_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxConc conc; - if (conc.read(parser, sol) == cxxConc::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif - - #include "ISolution.h" #include "Exchange.h" #include "Surface.h" @@ -1291,4 +1098,3 @@ void test_classes(void) // read it back } } - diff --git a/StorageBin.cxx b/StorageBin.cxx index c0053b6a..c38874fd 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -302,6 +302,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct exchange *exchange_ptr = (it->second).cxxExchange2exchange(); exchange_copy(exchange_ptr, &exchange[0], n); count_exchange++; + exchange_free(exchange_ptr); + exchange_ptr = (struct exchange *) free_check_null(exchange_ptr); } } @@ -312,6 +314,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct gas_phase *gas_phase_ptr = (it->second).cxxGasPhase2gas_phase(); gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); count_gas_phase++; + gas_phase_free(gas_phase_ptr); + gas_phase_ptr = (struct gas_phase *) free_check_null(gas_phase_ptr); } } @@ -322,6 +326,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct kinetics *kinetics_ptr = (it->second).cxxKinetics2kinetics(); kinetics_copy(kinetics_ptr, &kinetics[0], n); count_kinetics++; + kinetics_free(kinetics_ptr); + kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); } } @@ -332,6 +338,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct pp_assemblage *pp_assemblage_ptr = (it->second).cxxPPassemblage2pp_assemblage(); pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); count_pp_assemblage++; + pp_assemblage_free(pp_assemblage_ptr); + pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); } } @@ -342,6 +350,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct s_s_assemblage *s_s_assemblage_ptr = (it->second).cxxSSassemblage2s_s_assemblage(); s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); count_s_s_assemblage++; + s_s_assemblage_free(s_s_assemblage_ptr); + s_s_assemblage_ptr = (struct s_s_assemblage *) free_check_null(s_s_assemblage_ptr); } } @@ -352,6 +362,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) struct surface *surface_ptr = (it->second).cxxSurface2surface(); surface_copy(surface_ptr, &surface[0], n); count_surface++; + surface_free(surface_ptr); + surface_ptr = (struct surface *) free_check_null(surface_ptr); } } @@ -371,38 +383,84 @@ void cxxStorageBin::phreeqc2cxxStorageBin(int n) // Exchangers { - exchange_bsearch(n, &pos); - this->Exchangers[n] = cxxExchange(&(exchange[pos])); + if (exchange_bsearch(n, &pos) != NULL) { + this->Exchangers[n] = cxxExchange(&(exchange[pos])); + } } // GasPhases { - gas_phase_bsearch(n, &pos); - this->GasPhases[n] = cxxGasPhase(&(gas_phase[pos])); + if (gas_phase_bsearch(n, &pos) != NULL) { + this->GasPhases[n] = cxxGasPhase(&(gas_phase[pos])); + } } // Kinetics { - kinetics_bsearch(n, &pos); - this->Kinetics[n] = cxxKinetics(&(kinetics[pos])); + if (kinetics_bsearch(n, &pos) != NULL) { + this->Kinetics[n] = cxxKinetics(&(kinetics[pos])); + } } // PPassemblages { - pp_assemblage_bsearch(n, &pos); - this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos])); + if (pp_assemblage_bsearch(n, &pos) != NULL) { + this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos])); + } } // SSassemblages { - s_s_assemblage_bsearch(n, &pos); - this->SSassemblages[n] = cxxSSassemblage(&(s_s_assemblage[pos])); + if (s_s_assemblage_bsearch(n, &pos) != NULL) { + this->SSassemblages[n] = cxxSSassemblage(&(s_s_assemblage[pos])); + } } // Surfaces { - surface_bsearch(n, &pos); - this->Surfaces[n] = cxxSurface(&(surface[pos])); + if (surface_bsearch(n, &pos) != NULL) { + this->Surfaces[n] = cxxSurface(&(surface[pos])); + } } - +} + +cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) + +{ +/* + * mixes solutions based on cxxMix structure, returns new solution + * return solution must be freed by calling method + */ + double intensive, extensive; + cxxSolution *cxxsoln_ptr, *cxxsoln_ptr1; +/* + * Zero out global solution data + */ + cxxsoln_ptr = new cxxSolution(0.0); +/* + * Determine sum of mixing fractions + */ + extensive = 0.0; + + std::map *mixcomps = mixmap.comps(); + + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) { + extensive += it->second; + } +/* + * Add solutions + */ + for (it = mixcomps->begin(); it != mixcomps->end(); it++) { + cxxsoln_ptr1 = &((this->Solutions.find(it->first))->second); + if (cxxsoln_ptr1 == NULL) { + sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + return(NULL); + } + intensive = it->second/extensive; + cxxsoln_ptr->add(*cxxsoln_ptr1, intensive, it->second); + } + return(cxxsoln_ptr); } diff --git a/StorageBin.h b/StorageBin.h index eb76fee6..3737bf55 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -50,6 +50,8 @@ public: void add(struct system *sys_ptr); + cxxSolution *mix_cxxSolutions(cxxMix &mixmap); + protected: // Tidied classes std::map Solutions; From b3028f79eb7646ae407217ca9a82ac93659e8015 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 13 Apr 2006 23:39:56 +0000 Subject: [PATCH 0016/1077] Roughed in some printing for debugging phast git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@865 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/StorageBin.cxx b/StorageBin.cxx index c38874fd..91b2bd54 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -275,17 +275,20 @@ void cxxStorageBin::add(struct system * system_ptr) } } +//#include // std::cout std::cerr void cxxStorageBin::cxxStorageBin2phreeqc(int n) // // copy data fromphreeqc storage to storage bin // { + //std::ostringstream oss; // Solutions { std::map ::iterator it = this->Solutions.find(n); if (it != this->Solutions.end()){ + //(it->second).dump_raw(oss,0); solution[0] = (it->second).cxxSolution2solution(); solution[0]->n_user = n; solution[0]->n_user_end = n; @@ -299,6 +302,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Exchangers.find(n); if ( it != this->Exchangers.end()) { + //(it->second).dump_raw(oss,0); struct exchange *exchange_ptr = (it->second).cxxExchange2exchange(); exchange_copy(exchange_ptr, &exchange[0], n); count_exchange++; @@ -311,6 +315,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->GasPhases.find(n); if ( it != this->GasPhases.end()) { + //(it->second).dump_raw(oss,0); struct gas_phase *gas_phase_ptr = (it->second).cxxGasPhase2gas_phase(); gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); count_gas_phase++; @@ -323,6 +328,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Kinetics.find(n); if ( it != this->Kinetics.end()) { + //(it->second).dump_raw(oss,0); struct kinetics *kinetics_ptr = (it->second).cxxKinetics2kinetics(); kinetics_copy(kinetics_ptr, &kinetics[0], n); count_kinetics++; @@ -335,6 +341,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->PPassemblages.find(n); if ( it != this->PPassemblages.end()) { + //(it->second).dump_raw(oss,0); struct pp_assemblage *pp_assemblage_ptr = (it->second).cxxPPassemblage2pp_assemblage(); pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); count_pp_assemblage++; @@ -347,6 +354,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->SSassemblages.find(n); if ( it != this->SSassemblages.end()) { + //(it->second).dump_raw(oss,0); struct s_s_assemblage *s_s_assemblage_ptr = (it->second).cxxSSassemblage2s_s_assemblage(); s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); count_s_s_assemblage++; @@ -359,6 +367,8 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Surfaces.find(n); if ( it != this->Surfaces.end()) { + //(it->second).dump_raw(oss,0); + struct surface *surface_ptr = (it->second).cxxSurface2surface(); surface_copy(surface_ptr, &surface[0], n); count_surface++; @@ -366,6 +376,7 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) surface_ptr = (struct surface *) free_check_null(surface_ptr); } } + //std::cerr << oss.str(); } void cxxStorageBin::phreeqc2cxxStorageBin(int n) From 8c747cbbf27bf07919106b7961f9e84432426b6e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 17 Apr 2006 23:42:03 +0000 Subject: [PATCH 0017/1077] Almost working on unsaturated zone serial version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@867 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.h | 65 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/StorageBin.h b/StorageBin.h index 3737bf55..10ce22e5 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -34,14 +34,73 @@ public: void phreeqc2cxxStorageBin(int n); - struct cxxSolution *get_solution(int n_user) { + struct cxxSolution *getSolution(int n_user) { if (this->Solutions.find(n_user) != this->Solutions.end()) { return(&(this->Solutions.find(n_user)->second)); } return (NULL); } - void set_solution(int n_user, cxxSolution soln) { - Solutions[n_user] = soln; + void setSolution(int n_user, cxxSolution *entity) { + Solutions[n_user] = *entity; + } + + struct cxxExchange *getExchange(int n_user) { + if (this->Exchangers.find(n_user) != this->Exchangers.end()) { + return(&(this->Exchangers.find(n_user)->second)); + } + return (NULL); + } + void setExchange(int n_user, cxxExchange *entity) { + Exchangers[n_user] = *entity; + } + + struct cxxPPassemblage *getPPassemblage(int n_user) { + if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) { + return(&(this->PPassemblages.find(n_user)->second)); + } + return (NULL); + } + void setPPassemblage(int n_user, cxxPPassemblage *entity) { + PPassemblages[n_user] = *entity; + } + struct cxxGasPhase *getGasPhase(int n_user) { + if (this->GasPhases.find(n_user) != this->GasPhases.end()) { + return(&(this->GasPhases.find(n_user)->second)); + } + return (NULL); + } + void setGasPhase(int n_user, cxxGasPhase *entity) { + GasPhases[n_user] = *entity; + } + + struct cxxSSassemblage *getSSassemblage(int n_user) { + if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) { + return(&(this->SSassemblages.find(n_user)->second)); + } + return (NULL); + } + void setSSassemblage(int n_user, cxxSSassemblage *entity) { + SSassemblages[n_user] = *entity; + } + + struct cxxKinetics *getKinetics(int n_user) { + if (this->Kinetics.find(n_user) != this->Kinetics.end()) { + return(&(this->Kinetics.find(n_user)->second)); + } + return (NULL); + } + void setKinetics(int n_user, cxxKinetics *entity) { + Kinetics[n_user] = *entity; + } + + struct cxxSurface *getSurface(int n_user) { + if (this->Surfaces.find(n_user) != this->Surfaces.end()) { + return(&(this->Surfaces.find(n_user)->second)); + } + return (NULL); + } + void setSurface(int n_user, cxxSurface *entity) { + Surfaces[n_user] = *entity; } void dump_raw(std::ostream& s_oss, unsigned int indent)const; From 88e3ff60956386bc76daa5e640833f60c14cc7df Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Apr 2006 19:56:18 +0000 Subject: [PATCH 0018/1077] Initialize default NumKeyword n_user = 1. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@870 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NumKeyword.cxx b/NumKeyword.cxx index c0d3e64d..32cb2f15 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -13,6 +13,8 @@ cxxNumKeyword::cxxNumKeyword() { + this->n_user = 1; + this->n_user_end = 1; } cxxNumKeyword::~cxxNumKeyword() From a372f9a8a226f586f8b49519955b1d5850e447ef Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Apr 2006 20:05:46 +0000 Subject: [PATCH 0019/1077] Simplified mix with add(int, factor) method git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@872 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Mix.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Mix.h b/Mix.h index 8a7254b1..ba66169a 100644 --- a/Mix.h +++ b/Mix.h @@ -28,6 +28,10 @@ public: void read_raw(CParser& parser); + void add(int n, double f) { + mixComps[n] = f; + }; + std::map *comps() {return &mixComps;} protected: From cb5ccd55d164d52a803fd3ee51aaade7c8a183a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Apr 2006 20:00:26 +0000 Subject: [PATCH 0020/1077] Works with szBin on serial and parallel. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@876 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 1 + StorageBin.cxx | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 26 ++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/GasPhase.cxx b/GasPhase.cxx index a0356136..8292e24d 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -51,6 +51,7 @@ cxxNumKeyword() // gas_phase components for (i = 0; i < gas_phase_ptr->count_comps; i++) { + if (gas_phase_ptr->comps[i].name == NULL) continue; gasPhaseComps[gas_phase_ptr->comps[i].name] = gas_phase_ptr->comps[i].moles; } } diff --git a/StorageBin.cxx b/StorageBin.cxx index 91b2bd54..d3c8eb3b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -435,6 +435,30 @@ void cxxStorageBin::phreeqc2cxxStorageBin(int n) } } +void cxxStorageBin::remove(int n) +{ + // Solution + this->Solutions.erase(n); + + // Exchanger + this->Exchangers.erase(n); + + // GasPhase + this->GasPhases.erase(n); + + // Kinetics + this->Kinetics.erase(n); + + // PPassemblage + this->PPassemblages.erase(n); + + // SSassemblage + this->SSassemblages.erase(n); + + // Surface + this->Surfaces.erase(n); +} + cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) { @@ -475,3 +499,62 @@ cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) } return(cxxsoln_ptr); } + +struct system *cxxStorageBin::cxxStorageBin2system(int n) + // + // make a system from storagebin + // +{ + struct system *system_ptr = new (struct system); + + // Solutions + + if (this->getSolution(n) != NULL) { + system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(); + } else { + system_ptr->solution = NULL; + } + + // Exchangers + if (this->getExchange(n) != NULL) { + system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(); + } else { + system_ptr->exchange = NULL; + } + + // GasPhases + if (this->getGasPhase(n) != NULL) { + system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(); + } else { + system_ptr->gas_phase = NULL; + } + + // Kinetics + if (this->getKinetics(n) != NULL) { + system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(); + } else { + system_ptr->kinetics = NULL; + } + + // PPassemblages + if (this->getPPassemblage(n) != NULL) { + system_ptr->pp_assemblage = (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(); + } else { + system_ptr->pp_assemblage = NULL; + } + + // SSassemblages + if (this->getSSassemblage(n) != NULL) { + system_ptr->s_s_assemblage = (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(); + } else { + system_ptr->s_s_assemblage = NULL; + } + + // Surfaces + if (this->getSurface(n) != NULL) { + system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(); + } else { + system_ptr->surface = NULL; + } + return system_ptr; +} diff --git a/StorageBin.h b/StorageBin.h index 10ce22e5..58c3f1ef 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -34,6 +34,8 @@ public: void phreeqc2cxxStorageBin(int n); + void remove(int n); + struct cxxSolution *getSolution(int n_user) { if (this->Solutions.find(n_user) != this->Solutions.end()) { return(&(this->Solutions.find(n_user)->second)); @@ -43,6 +45,9 @@ public: void setSolution(int n_user, cxxSolution *entity) { Solutions[n_user] = *entity; } + void removeSolution(int n_user) { + Solutions.erase(n_user); + } struct cxxExchange *getExchange(int n_user) { if (this->Exchangers.find(n_user) != this->Exchangers.end()) { @@ -53,6 +58,9 @@ public: void setExchange(int n_user, cxxExchange *entity) { Exchangers[n_user] = *entity; } + void removeExchange(int n_user) { + Exchangers.erase(n_user); + } struct cxxPPassemblage *getPPassemblage(int n_user) { if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) { @@ -63,6 +71,10 @@ public: void setPPassemblage(int n_user, cxxPPassemblage *entity) { PPassemblages[n_user] = *entity; } + void removePPassemblage(int n_user) { + PPassemblages.erase(n_user); + } + struct cxxGasPhase *getGasPhase(int n_user) { if (this->GasPhases.find(n_user) != this->GasPhases.end()) { return(&(this->GasPhases.find(n_user)->second)); @@ -72,6 +84,9 @@ public: void setGasPhase(int n_user, cxxGasPhase *entity) { GasPhases[n_user] = *entity; } + void removeGasPhase(int n_user) { + GasPhases.erase(n_user); + } struct cxxSSassemblage *getSSassemblage(int n_user) { if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) { @@ -82,6 +97,9 @@ public: void setSSassemblage(int n_user, cxxSSassemblage *entity) { SSassemblages[n_user] = *entity; } + void removeSSassemblage(int n_user) { + SSassemblages.erase(n_user); + } struct cxxKinetics *getKinetics(int n_user) { if (this->Kinetics.find(n_user) != this->Kinetics.end()) { @@ -92,6 +110,9 @@ public: void setKinetics(int n_user, cxxKinetics *entity) { Kinetics[n_user] = *entity; } + void removeKinetics(int n_user) { + Kinetics.erase(n_user); + } struct cxxSurface *getSurface(int n_user) { if (this->Surfaces.find(n_user) != this->Surfaces.end()) { @@ -102,6 +123,9 @@ public: void setSurface(int n_user, cxxSurface *entity) { Surfaces[n_user] = *entity; } + void removeSurface(int n_user) { + Surfaces.erase(n_user); + } void dump_raw(std::ostream& s_oss, unsigned int indent)const; @@ -109,6 +133,8 @@ public: void add(struct system *sys_ptr); + struct system *cxxStorageBin2system(int i); + cxxSolution *mix_cxxSolutions(cxxMix &mixmap); protected: From 8356664d5231d640d1d359f0405077397dc48134 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Apr 2006 22:37:51 +0000 Subject: [PATCH 0021/1077] workds on serial and parallel using StorageBin for uz, sz, and phreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@878 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StorageBin.cxx b/StorageBin.cxx index d3c8eb3b..98ba848b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -505,7 +505,8 @@ struct system *cxxStorageBin::cxxStorageBin2system(int n) // make a system from storagebin // { - struct system *system_ptr = new (struct system); + struct system *system_ptr = (struct system *) PHRQ_malloc(sizeof(struct system)); + if (system_ptr == NULL) malloc_error(); // Solutions From a38caf497005106f7aacf4fc4ee4e6966b04b0ca Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 May 2006 16:31:27 +0000 Subject: [PATCH 0022/1077] Serial version is working for Linux with restart option. Tried including printing just active cells, but went back to writing entire storage bin in case wanted a new head condition with free surface. Waiting for Scott on Windows version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@887 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 24 +++++++++++++++++++++++ StorageBin.cxx | 52 ++++++++++++++++++++++++++++++++++++++++++-------- StorageBin.h | 2 ++ 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 07912a84..64bd3cbd 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -57,6 +57,7 @@ totals(exch_comp_ptr->totals) cxxExchComp::~cxxExchComp() { } +#include // std::cout std::cerr struct master *cxxExchComp::get_master() { @@ -77,11 +78,34 @@ struct master *cxxExchComp::get_master() master_ptr = elt_ptr->master; break; } + if (master_ptr == NULL) { + for (std::map ::iterator it = this->formula_totals.begin(); it != formula_totals.end(); it++) { + + /* Find master species */ + char *eltName = it->first; + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; + //Utilities::error_msg(error_oss.str(), STOP); + error_msg(error_oss.str().c_str(), CONTINUE); + return(NULL); + } + if (elt_ptr->master->type != EX) continue; + master_ptr = elt_ptr->master; + break; + } + } if (master_ptr == NULL) { std::ostringstream error_oss; error_oss << "Exchange formula does not contain an exchange master species, " << this->formula << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); error_msg(error_oss.str().c_str(), CONTINUE); + + std::ostringstream oss; + this->dump_raw(oss, 0); + std::cerr << oss.str(); + } return(master_ptr); } diff --git a/StorageBin.cxx b/StorageBin.cxx index 98ba848b..6132aff0 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -118,6 +118,8 @@ void cxxStorageBin::dump_xml(std::ostream& s_oss, unsigned int indent)const void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const { + // Dump all data + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; s_oss.precision(DBL_DIG - 1); @@ -142,6 +144,48 @@ void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const // Surface Utilities::dump_raw(Surfaces, s_oss, indent); } +void cxxStorageBin::dump_raw(std::ostream& s_oss, int n, unsigned int indent) +{ + // Dump one user number + + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + s_oss.precision(DBL_DIG - 1); + + // Solutions + if (this->getSolution(n) != NULL) { + this->getSolution(n)->dump_raw(s_oss, indent); + } + + // Exchange + if (this->getExchange(n) != NULL) { + this->getExchange(n)->dump_raw(s_oss, indent); + } + + // Gas Phases + if (this->getGasPhase(n) != NULL) { + this->getGasPhase(n)->dump_raw(s_oss, indent); + } + + // Kinetics + if (this->getKinetics(n) != NULL) { + this->getKinetics(n)->dump_raw(s_oss, indent); + } + + // PPassemblage + if (this->getPPassemblage(n) != NULL) { + this->getPPassemblage(n)->dump_raw(s_oss, indent); + } + + // SSassemblage + if (this->getSSassemblage(n) != NULL) { + this->getSSassemblage(n)->dump_raw(s_oss, indent); + } + + // Surface + if (this->getSurface(n) != NULL) { + this->getSurface(n)->dump_raw(s_oss, indent); + } +} void cxxStorageBin::read_raw(CParser& parser) { @@ -288,7 +332,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) std::map ::iterator it = this->Solutions.find(n); if (it != this->Solutions.end()){ - //(it->second).dump_raw(oss,0); solution[0] = (it->second).cxxSolution2solution(); solution[0]->n_user = n; solution[0]->n_user_end = n; @@ -302,7 +345,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Exchangers.find(n); if ( it != this->Exchangers.end()) { - //(it->second).dump_raw(oss,0); struct exchange *exchange_ptr = (it->second).cxxExchange2exchange(); exchange_copy(exchange_ptr, &exchange[0], n); count_exchange++; @@ -315,7 +357,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->GasPhases.find(n); if ( it != this->GasPhases.end()) { - //(it->second).dump_raw(oss,0); struct gas_phase *gas_phase_ptr = (it->second).cxxGasPhase2gas_phase(); gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); count_gas_phase++; @@ -328,7 +369,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Kinetics.find(n); if ( it != this->Kinetics.end()) { - //(it->second).dump_raw(oss,0); struct kinetics *kinetics_ptr = (it->second).cxxKinetics2kinetics(); kinetics_copy(kinetics_ptr, &kinetics[0], n); count_kinetics++; @@ -341,7 +381,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->PPassemblages.find(n); if ( it != this->PPassemblages.end()) { - //(it->second).dump_raw(oss,0); struct pp_assemblage *pp_assemblage_ptr = (it->second).cxxPPassemblage2pp_assemblage(); pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); count_pp_assemblage++; @@ -354,7 +393,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->SSassemblages.find(n); if ( it != this->SSassemblages.end()) { - //(it->second).dump_raw(oss,0); struct s_s_assemblage *s_s_assemblage_ptr = (it->second).cxxSSassemblage2s_s_assemblage(); s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); count_s_s_assemblage++; @@ -367,8 +405,6 @@ void cxxStorageBin::cxxStorageBin2phreeqc(int n) { std::map ::iterator it = this->Surfaces.find(n); if ( it != this->Surfaces.end()) { - //(it->second).dump_raw(oss,0); - struct surface *surface_ptr = (it->second).cxxSurface2surface(); surface_copy(surface_ptr, &surface[0], n); count_surface++; diff --git a/StorageBin.h b/StorageBin.h index 58c3f1ef..ad932f2f 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -129,6 +129,8 @@ public: void dump_raw(std::ostream& s_oss, unsigned int indent)const; + void dump_raw(std::ostream& s_oss, int i, unsigned int indent); + void read_raw(CParser& parser); void add(struct system *sys_ptr); From 297744eafa459c2d6c7fdcc4a1b33397493cb8be Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 3 May 2006 06:37:52 +0000 Subject: [PATCH 0023/1077] Updated for VS7.Net git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@891 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/StorageBin.h b/StorageBin.h index ad932f2f..2e93f6d4 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -36,7 +36,7 @@ public: void remove(int n); - struct cxxSolution *getSolution(int n_user) { + cxxSolution *getSolution(int n_user) { if (this->Solutions.find(n_user) != this->Solutions.end()) { return(&(this->Solutions.find(n_user)->second)); } @@ -49,7 +49,7 @@ public: Solutions.erase(n_user); } - struct cxxExchange *getExchange(int n_user) { + cxxExchange *getExchange(int n_user) { if (this->Exchangers.find(n_user) != this->Exchangers.end()) { return(&(this->Exchangers.find(n_user)->second)); } @@ -62,7 +62,7 @@ public: Exchangers.erase(n_user); } - struct cxxPPassemblage *getPPassemblage(int n_user) { + cxxPPassemblage *getPPassemblage(int n_user) { if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) { return(&(this->PPassemblages.find(n_user)->second)); } @@ -75,7 +75,7 @@ public: PPassemblages.erase(n_user); } - struct cxxGasPhase *getGasPhase(int n_user) { + cxxGasPhase *getGasPhase(int n_user) { if (this->GasPhases.find(n_user) != this->GasPhases.end()) { return(&(this->GasPhases.find(n_user)->second)); } @@ -88,7 +88,7 @@ public: GasPhases.erase(n_user); } - struct cxxSSassemblage *getSSassemblage(int n_user) { + cxxSSassemblage *getSSassemblage(int n_user) { if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) { return(&(this->SSassemblages.find(n_user)->second)); } @@ -101,7 +101,7 @@ public: SSassemblages.erase(n_user); } - struct cxxKinetics *getKinetics(int n_user) { + cxxKinetics *getKinetics(int n_user) { if (this->Kinetics.find(n_user) != this->Kinetics.end()) { return(&(this->Kinetics.find(n_user)->second)); } @@ -114,7 +114,7 @@ public: Kinetics.erase(n_user); } - struct cxxSurface *getSurface(int n_user) { + cxxSurface *getSurface(int n_user) { if (this->Surfaces.find(n_user) != this->Surfaces.end()) { return(&(this->Surfaces.find(n_user)->second)); } From 11431ae291d9c5f5a7fd5d6d24354a527c07681e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 May 2006 00:02:01 +0000 Subject: [PATCH 0024/1077] packing and unpacking cxx classes for mpi is running need to check result. changed SurfComp.h SurfaceComp.h changed SurfComp.cxx SurfaceComp.cxx changed SurfCharge.h SurfaceCharge.h changed SurfCharge.cxx SurfaceCharge.cxx Added Dictionary.cxx and Dictionary.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@894 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 38 ++++- ExchComp.h | 5 + Exchange.cxx | 39 +++++ Exchange.h | 4 + GasPhase.cxx | 33 ++++ GasPhase.h | 5 +- KineticsComp.cxx | 36 ++++ KineticsComp.h | 4 + KineticsCxx.cxx | 45 +++++ KineticsCxx.h | 5 + NameDouble.cxx | 55 ++++++ NameDouble.h | 7 +- PPassemblage.cxx | 36 ++++ PPassemblage.h | 5 + PPassemblageComp.cxx | 30 ++++ PPassemblageComp.h | 5 +- SSassemblage.cxx | 34 ++++ SSassemblage.h | 5 + SSassemblageSS.cxx | 33 ++++ SSassemblageSS.h | 13 +- Solution.cxx | 252 ++++++++++++++++++++++++++++ Solution.h | 6 + SolutionIsotope.h | 3 +- StorageBin.cxx | 220 ++++++++++++++++++++++++ StorageBin.h | 5 + Surface.cxx | 105 +++++++++--- Surface.h | 14 +- SurfCharge.cxx => SurfaceCharge.cxx | 72 +++++--- SurfCharge.h => SurfaceCharge.h | 21 ++- SurfComp.cxx => SurfaceComp.cxx | 74 +++++--- SurfComp.h => SurfaceComp.h | 21 ++- 31 files changed, 1131 insertions(+), 99 deletions(-) rename SurfCharge.cxx => SurfaceCharge.cxx (82%) rename SurfCharge.h => SurfaceCharge.h (60%) rename SurfComp.cxx => SurfaceComp.cxx (85%) rename SurfComp.h => SurfaceComp.h (64%) diff --git a/ExchComp.cxx b/ExchComp.cxx index 64bd3cbd..2b92367d 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -4,7 +4,7 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - +#include // std::cout std::cerr #include "Utils.h" // define first #include "ExchComp.h" #define EXTERNAL extern @@ -57,7 +57,6 @@ totals(exch_comp_ptr->totals) cxxExchComp::~cxxExchComp() { } -#include // std::cout std::cerr struct master *cxxExchComp::get_master() { @@ -383,3 +382,38 @@ void cxxExchComp::read_raw(CParser& parser) parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxExchComp::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + ints.push_back(dictionary.string2int(this->formula)); + doubles.push_back(this->moles); + this->formula_totals.mpi_pack(ints, doubles); + this->totals.mpi_pack(ints, doubles); + doubles.push_back(this->la); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.string2int(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.string2int(this->rate_name)); + doubles.push_back(this->formula_z); +} +void cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->formula = dictionary.int2char(ints[i++]); + this->moles = doubles[d++]; + this->formula_totals.mpi_unpack(ints, &i, doubles, &d); + this->totals.mpi_unpack(ints, &i, doubles, &d); + this->la = doubles[d++]; + this->charge_balance = doubles[d++]; + this->phase_name = dictionary.int2char(ints[i++]); + this->phase_proportion = doubles[d++]; + this->rate_name = dictionary.int2char(ints[i++]); + this->formula_z = doubles[d++]; + *ii = i; + *dd = d; +} +#endif diff --git a/ExchComp.h b/ExchComp.h index 1684c9ab..dc2f7abb 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -22,6 +22,7 @@ public: struct master *get_master(); + char *get_formula()const {return this->formula;} char *get_phase_name()const {return this->phase_name;} char *get_rate_name()const {return this->rate_name;} @@ -33,6 +34,10 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif protected: char * formula; double moles; diff --git a/Exchange.cxx b/Exchange.cxx index 2090d25e..b6438fc0 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -5,6 +5,7 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // std::cout std::cerr #include "Utils.h" // define first #include "Exchange.h" #include "ExchComp.h" @@ -220,3 +221,41 @@ void cxxExchange::read_raw(CParser& parser) parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +/* ---------------------------------------------------------------------- */ +void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + + ints.push_back((int) this->pitzer_exchange_gammas); + ints.push_back(this->exchComps.size()); + for (std::list::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) { + it->mpi_pack(ints, doubles); + } +} +/* ---------------------------------------------------------------------- */ +void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +/* ---------------------------------------------------------------------- */ +{ + int i = *ii; + int d = *dd; + /* int n_user; */ + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + + + this->pitzer_exchange_gammas = (bool) ints[i++]; + int count = ints[i++]; + this->exchComps.clear(); + for (int n = 0; n < count; n++) { + cxxExchComp ec; + ec.mpi_unpack(ints, &i, doubles, &d); + this->exchComps.push_back(ec); + } + *ii = i; + *dd = d; +} +#endif diff --git a/Exchange.h b/Exchange.h index 08c06fee..76306f85 100644 --- a/Exchange.h +++ b/Exchange.h @@ -35,6 +35,10 @@ public: bool get_related_rate(void); +#ifdef USE_MPI + void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles); + void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif protected: std::list exchComps; bool pitzer_exchange_gammas; diff --git a/GasPhase.cxx b/GasPhase.cxx index 8292e24d..2e8f12db 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -282,3 +282,36 @@ void cxxGasPhase::read_raw(CParser& parser) parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +void cxxGasPhase::mpi_pack(std::vector& ints, std::vector& doubles) +{ + ints.push_back(this->n_user); + this->gasPhaseComps.mpi_pack(ints, doubles); + if (this->type == cxxGasPhase::GP_PRESSURE) { + ints.push_back(0); + } else { + ints.push_back(1); + } + doubles.push_back(this->total_p); + doubles.push_back(this->volume); +} +void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + int i = *ii; + int d = *dd; + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + this->gasPhaseComps.mpi_unpack(ints, &i, doubles, &d); + int n = ints[i++]; + if (n == 0) { + this->type = cxxGasPhase::GP_PRESSURE; + } else { + this->type = cxxGasPhase::GP_VOLUME; + } + this->total_p = doubles[d++]; + this->volume = doubles[d++]; + *ii = i; + *dd = d; +} +#endif diff --git a/GasPhase.h b/GasPhase.h index b0bb7c63..6127741b 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -36,7 +36,10 @@ public: void read_raw(CParser& parser); - +#ifdef USE_MPI + void cxxGasPhase::mpi_pack(std::vector& ints, std::vector& doubles); + void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif protected: cxxNameDouble gasPhaseComps; GP_TYPE type; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 7fe51281..41097593 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -309,3 +309,39 @@ void cxxKineticsComp::read_raw(CParser& parser) parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxKineticsComp::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + ints.push_back(dictionary.string2int(this->rate_name)); + this->namecoef.mpi_pack(ints, doubles); + doubles.push_back(this->tol); + doubles.push_back(this->m); + doubles.push_back(this->m0); + doubles.push_back(this->moles); + ints.push_back(this->d_params.size()); + for (std::vector::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) { + doubles.push_back(*it); + } +} +void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->rate_name = dictionary.int2char(ints[i++]); + this->namecoef.mpi_unpack(ints, &i, doubles, &d); + this->tol = doubles[d++]; + this->m = doubles[d++]; + this->m0 = doubles[d++]; + this->moles = doubles[d++]; + int n = ints[i++]; + this->d_params.clear(); + for (int j = 0; j < n; j++) { + this->d_params.push_back(doubles[d++]); + } + *ii = i; + *dd = d; +} +#endif diff --git a/KineticsComp.h b/KineticsComp.h index 899e114e..3c43cb45 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -28,6 +28,10 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector& ints, std::vector& doubles); +#endif protected: char * rate_name; cxxNameDouble namecoef; diff --git a/KineticsCxx.cxx b/KineticsCxx.cxx index 86c3787b..8c329a18 100644 --- a/KineticsCxx.cxx +++ b/KineticsCxx.cxx @@ -345,3 +345,48 @@ void cxxKinetics::read_raw(CParser& parser) parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) +{ + ints.push_back(this->n_user); + ints.push_back(this->kineticsComps.size()); + for (std::list::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { + it->mpi_pack(ints, doubles); + } + ints.push_back(this->steps.size()); + for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { + doubles.push_back(*it); + } + doubles.push_back(this->step_divide); + ints.push_back(this->rk); + ints.push_back(this->bad_step_max); + ints.push_back(this->use_cvode); +} +void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + int i = *ii; + int d = *dd; + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + + int n = ints[i++]; + this->kineticsComps.clear(); + for (int j = 0; j < n; j++) { + cxxKineticsComp kc; + kc.mpi_unpack(ints, &i, doubles, &d); + this->kineticsComps.push_back(kc); + } + n = ints[i++]; + this->steps.clear(); + for (int j = 0; j < n; j++) { + this->steps.push_back(doubles[d++]); + } + this->step_divide = doubles[d++]; + this->rk = ints[i++]; + this->bad_step_max = ints[i++]; + this->use_cvode = (bool) ints[i++]; + *ii = i; + *dd = d; +} +#endif diff --git a/KineticsCxx.h b/KineticsCxx.h index ec218cfa..d0be59e0 100644 --- a/KineticsCxx.h +++ b/KineticsCxx.h @@ -35,6 +35,11 @@ public: bool get_related_rate(void); +#ifdef USE_MPI + void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles); +#endif + protected: std::list kineticsComps; std::vector steps; diff --git a/NameDouble.cxx b/NameDouble.cxx index 46bfe2f5..f1013f35 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -5,10 +5,12 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // std::cout std::cerr #include "Utils.h" // define first #include "NameDouble.h" #define EXTERNAL extern #include "global.h" +#include "output.h" #include "phqalloc.h" #include "phrqproto.h" #include // assert @@ -288,3 +290,56 @@ void cxxNameDouble::add(const cxxNameDouble &old, double factor) } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { + extern cxxDictionary dictionary; + ints.push_back( (*this).size() ); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { + assert(it->first != NULL); + int n = dictionary.string2int(it->first); + ints.push_back(n); + doubles.push_back(it->second); + } +} +void cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) +{ + int i = *ii; + int d = *dd; + extern cxxDictionary dictionary; + //ints.push_back( (*this).size() ); + ints[i++] = this->size(); + for (const_iterator it = this->begin(); it != this->end(); it++) { + int n = dictionary.string2int(it->first); + if (n < 0) { + std::cerr << it->first << std::endl; + error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); + } + //ints.push_back(n); + ints[i++] = n; + //doubles.push_back(it->second); + doubles[d++] = it->second; + } + *ii = i; + *dd = d; +} +void cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + int i = *ii; + int d = *dd; + extern cxxDictionary dictionary; + this->clear(); + int count = ints[i++]; + for (int j = 0; j < count; j++) { + int n = ints[i++]; + assert(n >= 0); + std::string *str = dictionary.int2string(n); + if (str != NULL) { + char *cstr = string_hsave(str->c_str()); + (*this)[cstr] = doubles[d++]; + } + } + *ii = i; + *dd = d; +} +#endif diff --git a/NameDouble.h b/NameDouble.h index da71a6a0..ab6c5b07 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -2,13 +2,13 @@ #define NAMEDOUBLE_H_INCLUDED #define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "global.h" #include "char_star.h" #include "Parser.h" class cxxNameDouble : public std::map @@ -46,6 +46,11 @@ public: void add(const cxxNameDouble &old, double factor); + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(int *ints, int *ii, double *doubles, int *dd); + + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + enum ND_TYPE type; protected: diff --git a/PPassemblage.cxx b/PPassemblage.cxx index a258959b..b08cc5fa 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -189,3 +189,39 @@ void cxxPPassemblage::read_raw(CParser& parser) } // members that must be defined } +#ifdef USE_MPI +/* ---------------------------------------------------------------------- */ +void cxxPPassemblage::mpi_pack(std::vector& ints, std::vector& doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + ints.push_back(this->ppAssemblageComps.size()); + for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) { + it->mpi_pack(ints, doubles); + } + this->eltList.mpi_pack(ints, doubles); +} +/* ---------------------------------------------------------------------- */ +void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +/* ---------------------------------------------------------------------- */ +{ + int i = *ii; + int d = *dd; + /* int n_user; */ + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + + int count = ints[i++]; + this->ppAssemblageComps.clear(); + for (int n = 0; n < count; n++) { + cxxPPassemblageComp ppc; + ppc.mpi_unpack(ints, &i, doubles, &d); + this->ppAssemblageComps.push_back(ppc); + } + this->eltList.mpi_unpack(ints, &i, doubles, &d); + *ii = i; + *dd = d; +} +#endif diff --git a/PPassemblage.h b/PPassemblage.h index 34af42e8..a03790f0 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -31,6 +31,11 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: std::list ppAssemblageComps; cxxNameDouble eltList; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0ba431f6..f040d37a 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -276,3 +276,33 @@ void cxxPPassemblageComp::read_raw(CParser& parser) } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxPPassemblageComp::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + + ints.push_back(dictionary.string2int(this->name)); + ints.push_back(dictionary.string2int(this->add_formula)); + doubles.push_back(this->si); + doubles.push_back(this->moles); + doubles.push_back(this->delta); + doubles.push_back(this->initial_moles); + ints.push_back((int) this->dissolve_only); +} +void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->name = dictionary.int2char(ints[i++]); + this->add_formula = dictionary.int2char(ints[i++]); + this->si = doubles[d++]; + this->moles = doubles[d++]; + this->delta = doubles[d++]; + this->initial_moles = doubles[d++]; + this->dissolve_only = (bool) ints[i++]; + *ii = i; + *dd = d; +} +#endif diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 7020a055..250045a7 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -30,7 +30,10 @@ public: void read_raw(CParser& parser); struct phase *get_phase(); - +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif protected: char * name; char *add_formula; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 8bc3082e..f8834787 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -169,3 +169,37 @@ void cxxSSassemblage::read_raw(CParser& parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } } +#ifdef USE_MPI +/* ---------------------------------------------------------------------- */ +void cxxSSassemblage::mpi_pack(std::vector& ints, std::vector& doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + ints.push_back(this->ssAssemblageSSs.size()); + for (std::list::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) { + it->mpi_pack(ints, doubles); + } +} +/* ---------------------------------------------------------------------- */ +void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +/* ---------------------------------------------------------------------- */ +{ + int i = *ii; + int d = *dd; + /* int n_user; */ + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + + int count = ints[i++]; + this->ssAssemblageSSs.clear(); + for (int n = 0; n < count; n++) { + cxxSSassemblageSS ssc; + ssc.mpi_unpack(ints, &i, doubles, &d); + this->ssAssemblageSSs.push_back(ssc); + } + *ii = i; + *dd = d; +} +#endif diff --git a/SSassemblage.h b/SSassemblage.h index 416c9e34..281910b8 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -31,6 +31,11 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: std::list ssAssemblageSSs; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 2730621a..c57f2192 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -441,3 +441,36 @@ void cxxSSassemblageSS::read_raw(CParser& parser) } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxSSassemblageSS::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + ints.push_back(dictionary.string2int(this->name)); + this->comps.mpi_pack(ints, doubles); + doubles.push_back(this->a0); + doubles.push_back(this->a1); + doubles.push_back(this->ag0); + doubles.push_back(this->ag1); + ints.push_back((int) this->miscibility); + doubles.push_back(this->xb1); + doubles.push_back(this->xb2); +} +void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->name = dictionary.int2char(ints[i++]); + this->comps.mpi_unpack(ints, &i, doubles, &d); + this->a0 = doubles[d++]; + this->a1 = doubles[d++]; + this->ag0 = doubles[d++]; + this->ag1 = doubles[d++]; + this->miscibility = (bool) ints[i++]; + this->xb1 = doubles[d++]; + this->xb2 = doubles[d++]; + *ii = i; + *dd = d; +} +#endif diff --git a/SSassemblageSS.h b/SSassemblageSS.h index cf9c5261..511f1aff 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -42,21 +42,18 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: char *name; - //std::list ppAssemblageSS; cxxNameDouble comps; - //double total_moles; - //double dn; double a0, a1; double ag0, ag1; - //bool s_s_in; bool miscibility; - //bool spinodal; - //double tk; double xb1, xb2; - //SS_PARAMETER_TYPE type; - //double p[4]; public: diff --git a/Solution.cxx b/Solution.cxx index 89f7be36..48efe692 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -11,6 +11,7 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort @@ -746,7 +747,258 @@ double cxxSolution::get_master_activity(char *string)const return(it->second); } } +#ifdef USE_MPI +#include +/* ---------------------------------------------------------------------- */ +void cxxSolution::mpi_pack(std::vector& ints, std::vector& doubles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + ints.push_back(this->n_user); + doubles.push_back(this->tc); + doubles.push_back(this->ph); + doubles.push_back(this->pe); + doubles.push_back(this->mu); + doubles.push_back(this->ah2o); + doubles.push_back(this->total_h); + doubles.push_back(this->total_o); + doubles.push_back(this->cb); + doubles.push_back(this->mass_water); + doubles.push_back(this->total_alkalinity); +/* + * struct conc *totals; +*/ + this->totals.mpi_pack(ints, doubles); +/* + * struct master_activity *master_activity; + */ + this->master_activity.mpi_pack(ints, doubles); +/* + * struct master_activity *species_gamma + */ + this->species_gamma.mpi_pack(ints, doubles); + /* + position = 0; + int i = ints.size(); + int int_array[i]; + int d = doubles.size(); + double double_array[d]; + for (int j = 0; j < i; j++) { + int_array[j] = ints[j]; + } + for (int j = 0; j < d; j++) { + double_array[j] = ints[j]; + } + MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); + MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); + + buffer = (void *) free_check_null(buffer); + */ +} +/* ---------------------------------------------------------------------- */ +void cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +/* ---------------------------------------------------------------------- */ +{ + int i = *ii; + int d = *dd; + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + this->tc = doubles[d++]; + this->ph = doubles[d++]; + this->pe = doubles[d++]; + this->mu = doubles[d++]; + this->ah2o = doubles[d++]; + this->total_h = doubles[d++]; + this->total_o = doubles[d++]; + this->cb = doubles[d++]; + this->mass_water = doubles[d++]; + this->total_alkalinity = doubles[d++]; +/* + * struct conc *totals; +*/ + this->totals.mpi_unpack(ints, &i, doubles, &d); +/* + * struct master_activity *master_activity; + */ + this->master_activity.mpi_unpack(ints, &i, doubles, &d); +/* + * struct master_activity *species_gamma; + */ + this->species_gamma.mpi_unpack(ints, &i, doubles, &d); + + *ii = i; + *dd = d; +} +/* ---------------------------------------------------------------------- */ +void cxxSolution::mpi_send(int task_number) +/* ---------------------------------------------------------------------- */ +{ + //int count_totals, count_totals_position, count_activity, count_activity_position; + int max_size, member_size, position; + //int ints[MESSAGE_MAX_NUMBERS]; + //double doubles[MESSAGE_MAX_NUMBERS]; + void *buffer; + std::vector ints; + std::vector doubles; +/* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + ints.push_back(this->n_user); + /* int n_user_end; */ + /* char *description; */ + doubles.push_back(this->tc); + doubles.push_back(this->ph); + doubles.push_back(this->pe); + doubles.push_back(this->mu); + doubles.push_back(this->ah2o); + doubles.push_back(this->total_h); + doubles.push_back(this->total_o); + doubles.push_back(this->cb); + doubles.push_back(this->mass_water); + doubles.push_back(this->total_alkalinity); +/* + * struct conc *totals; +*/ + this->totals.mpi_pack(ints, doubles); +/* + * struct master_activity *master_activity; + */ + this->master_activity.mpi_pack(ints, doubles); +/* + * struct master_activity *species_gamma + */ + this->species_gamma.mpi_pack(ints, doubles); + + /* int count_isotopes; */ + /* struct isotope *isotopes; */ + if (input_error > 0) { + std::string errstr("Stopping due to errors\n"); + error_msg(errstr.c_str(), STOP); + } +/* + * Malloc space for a buffer + */ + max_size = 0; + //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_INT, MPI_COMM_WORLD, &member_size); + MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); + max_size += member_size; + //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + max_size += member_size + 10; + buffer = PHRQ_malloc(max_size); + if (buffer == NULL) malloc_error(); +/* + * Send message to processor + */ + position = 0; + int i = ints.size(); + int int_array[i]; + int d = doubles.size(); + double double_array[d]; + for (int j = 0; j < i; j++) { + int_array[j] = ints[j]; + } + for (int j = 0; j < d; j++) { + double_array[j] = doubles[j]; + } + + MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); + MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); + + buffer = (void *) free_check_null(buffer); +} +/* ---------------------------------------------------------------------- */ +void cxxSolution::mpi_recv(int task_number) +/* ---------------------------------------------------------------------- */ +{ + MPI_Status mpi_status; +/* + * Malloc space for a buffer + */ + int max_size; + // buffer size + + MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); + void *buffer = PHRQ_malloc(max_size); + if (buffer == NULL) malloc_error(); + /* + * Recieve solution + */ + MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status); + int position = 0; + int msg_size; + MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); + + /* Unpack ints */ + int count_ints; + MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); + int ints[count_ints]; + MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); + + /* Unpack doubles */ + int count_doubles; + MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); + double doubles[count_doubles]; + MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + buffer = free_check_null(buffer); +/* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + int i = 0; + int d = 0; + /* int new_def; */ + /* solution_ptr->new_def = FALSE; */ + /* int n_user; */ + this->n_user = ints[i++]; + /* int n_user_end; */ + this->n_user_end = this->n_user; + + /*debugging*/ + //this->description = (char *) free_check_null(this->description); + //this->description = string_duplicate(" "); + this->description = " "; + this->tc = doubles[d++]; + this->ph = doubles[d++]; + this->pe = doubles[d++]; + this->mu = doubles[d++]; + this->ah2o = doubles[d++]; + this->total_h = doubles[d++]; + this->total_o = doubles[d++]; + this->cb = doubles[d++]; + this->mass_water = doubles[d++]; + this->total_alkalinity = 0; +/* + * struct conc *totals; +*/ + this->totals.mpi_unpack(ints, &i, doubles, &d); +/* + * struct master_activity *master_activity; + */ + this->master_activity.mpi_unpack(ints, &i, doubles, &d); +/* + * struct master_activity *species_gamma; + */ + this->species_gamma.mpi_unpack(ints, &i, doubles, &d); +} +#endif void cxxSolution::set_master_activity(char *string, double d) { this->master_activity[string] = d; diff --git a/Solution.h b/Solution.h index 4e2bf157..564a3c09 100644 --- a/Solution.h +++ b/Solution.h @@ -85,6 +85,12 @@ public: void add(const cxxSolution &sol, double intensive, double extensive); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_send(int task_number); + void mpi_recv(int task_number); +#endif protected: double tc; double ph; diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 4539b1a1..43f1ccf4 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -13,11 +13,12 @@ public: cxxSolutionIsotope(struct isotope *isotope_ptr); ~cxxSolutionIsotope(void); + /* enum STATUS { ERROR = 0, OK = 1 }; - + */ //cxxSolutionIsotope::STATUS read(CParser& parser); static struct isotope * list2isotope(std::list &t); diff --git a/StorageBin.cxx b/StorageBin.cxx index 6132aff0..3f516833 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -5,6 +5,8 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include +#include // std::cout std::cerr #include "Utils.h" // define first #include "StorageBin.h" #include "Solution.h" @@ -595,3 +597,221 @@ struct system *cxxStorageBin::cxxStorageBin2system(int n) } return system_ptr; } +#ifdef USE_MPI +#include +void cxxStorageBin::mpi_send(int n, int task_number) +{ + // + // Send data for system n to task_number + // + std::vector ints; + std::vector doubles; + + // Solution + if (this->getSolution(n) != NULL) { + ints.push_back(1); + this->getSolution(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed Solution" << std::endl; + + // Exchanger + if (this->getExchange(n) != NULL) { + ints.push_back(1); + this->getExchange(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed Exchange" << std::endl; + + // GasPhase + if (this->getGasPhase(n) != NULL) { + ints.push_back(1); + this->getGasPhase(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed GasPhase" << std::endl; + + // Kinetics + if (this->getKinetics(n) != NULL) { + ints.push_back(1); + this->getKinetics(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed Kinetics" << std::endl; + + // PPassemblages + if (this->getPPassemblage(n) != NULL) { + ints.push_back(1); + this->getPPassemblage(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed PPassemblage" << std::endl; + + // SSassemblages + if (this->getSSassemblage(n) != NULL) { + ints.push_back(1); + this->getSSassemblage(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed SSassemblage" << std::endl; + + // Surfaces + if (this->getSurface(n) != NULL) { + ints.push_back(1); + this->getSurface(n)->mpi_pack(ints, doubles); + } else { + ints.push_back(0); + } + //std::cerr << "Packed Surface" << std::endl; + + // Pack data + int max_size = 0; + int member_size = 0; + MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); + max_size += member_size; + MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + max_size += member_size + 10; + void *buffer = PHRQ_malloc(max_size); + if (buffer == NULL) malloc_error(); + + // Convert to arrays + int i = ints.size(); + int int_array[i]; + int d = doubles.size(); + double double_array[d]; + for (int j = 0; j < i; j++) { + int_array[j] = ints[j]; + //std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl; + } + for (int j = 0; j < d; j++) { + double_array[j] = doubles[j]; + //std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl; + } + + /* + * Send message to processor + */ + int position = 0; + MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); + MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); + + buffer = (void *) free_check_null(buffer); +} +/* ---------------------------------------------------------------------- */ +void cxxStorageBin::mpi_recv(int task_number) +/* ---------------------------------------------------------------------- */ +{ + MPI_Status mpi_status; +/* + * Malloc space for a buffer + */ + int max_size; + // buffer size + + MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); + void *buffer = PHRQ_malloc(max_size); + if (buffer == NULL) malloc_error(); + /* + * Recieve system + */ + MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status); + int position = 0; + int msg_size; + MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); + + /* Unpack ints */ + int count_ints; + MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); + int ints[count_ints]; + MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); + + /* Unpack doubles */ + int count_doubles; + MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); + double doubles[count_doubles]; + MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + buffer = free_check_null(buffer); +#ifdef SKIP + for (int j = 0; j < count_ints; j++) { + std::cerr << "Recving ints " << j << " value " << ints[j] << std::endl; + } + for (int j = 0; j < count_doubles; j++) { + std::cerr << "Recving doubles " << j << " value " << doubles[j] << std::endl; + } +#endif + /* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + int i = 0; + int d = 0; + + // Solution + if (ints[i++] != 0) { + cxxSolution entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setSolution(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked Solution" << std::endl; + + // Exchanger + if (ints[i++] != 0) { + cxxExchange entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setExchange(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked Exchange" << std::endl; + + // GasPhase + if (ints[i++] != 0) { + cxxGasPhase entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setGasPhase(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked GasPhase" << std::endl; + + // Kinetics + if (ints[i++] != 0) { + cxxKinetics entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setKinetics(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked Kinetics" << std::endl; + + // PPassemblage + if (ints[i++] != 0) { + cxxPPassemblage entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setPPassemblage(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked PPassemblage" << std::endl; + + // SSassemblage + if (ints[i++] != 0) { + cxxSSassemblage entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setSSassemblage(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked SSassemblage" << std::endl; + + // Surfaces + if (ints[i++] != 0) { + cxxSurface entity; + entity.mpi_unpack(ints, &i, doubles, &d); + this->setSurface(entity.get_n_user(), &entity); + } + //std::cerr << "Unpacked Surface" << std::endl; + +} +#endif diff --git a/StorageBin.h b/StorageBin.h index 2e93f6d4..cb6f9ec1 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -139,6 +139,11 @@ public: cxxSolution *mix_cxxSolutions(cxxMix &mixmap); +#ifdef USE_MPI + void mpi_send(int n, int task_number); + void mpi_recv(int task_number); +#endif + protected: // Tidied classes std::map Solutions; diff --git a/Surface.cxx b/Surface.cxx index 55602a90..d4de9bd3 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -7,7 +7,7 @@ #include "Utils.h" // define first #include "Surface.h" -#include "SurfComp.h" +#include "SurfaceComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -52,13 +52,13 @@ cxxNumKeyword() thickness = surface_ptr->thickness; // Surface components for (i = 0; i < surface_ptr->count_comps; i++) { - cxxSurfComp ec(&(surface_ptr->comps[i])); - surfComps.push_back(ec); + cxxSurfaceComp ec(&(surface_ptr->comps[i])); + surfaceComps.push_back(ec); } // Surface charge for (i = 0; i < surface_ptr->count_charge; i++) { - cxxSurfCharge ec(&(surface_ptr->charge[i])); - surfCharges.push_back(ec); + cxxSurfaceCharge ec(&(surface_ptr->charge[i])); + surfaceCharges.push_back(ec); } } @@ -68,7 +68,7 @@ cxxSurface::~cxxSurface() bool cxxSurface::get_related_phases() { - for (std::list::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + for (std::list::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { if (it->get_phase_name() == NULL) continue; return(true); } @@ -77,7 +77,7 @@ bool cxxSurface::get_related_phases() bool cxxSurface::get_related_rate() { - for (std::list::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + for (std::list::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { if (it->get_rate_name() == NULL) continue; return(true); } @@ -95,7 +95,7 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->n_user = this->n_user; surface_ptr->n_user_end = this->n_user_end; surface_ptr->new_def = FALSE; - surface_ptr->diffuse_layer = this->diffuse_layer; + surface_ptr->diffuse_layer = this->diffuse_layer; surface_ptr->edl = this->edl; surface_ptr->only_counter_ions = this->only_counter_ions; surface_ptr->donnan = this->donnan; @@ -108,15 +108,19 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->transport = FALSE; // Surface comps - surface_ptr->count_comps = this->surfComps.size(); + surface_ptr->count_comps = this->surfaceComps.size(); surface_ptr->comps = (struct surface_comp *) free_check_null(surface_ptr->comps); - surface_ptr->comps = cxxSurfComp::cxxSurfComp2surface_comp(this->surfComps); + surface_ptr->comps = cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); // Surface charge - surface_ptr->count_charge = this->surfCharges.size(); - surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); - surface_ptr->charge = cxxSurfCharge::cxxSurfCharge2surface_charge(this->surfCharges); - + surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); + if (surface_ptr->edl == TRUE) { + surface_ptr->count_charge = this->surfaceCharges.size(); + surface_ptr->charge = cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); + } else { + surface_ptr->count_charge = 0; + } + return(surface_ptr); } @@ -153,14 +157,14 @@ void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) { + for (std::list::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { it->dump_xml(s_oss, indent + 2); } } // surface charge structures s_oss << indent1; s_oss << "::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) { + for (std::list::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { it->dump_xml(s_oss, indent + 2); } @@ -196,15 +200,15 @@ void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "-thickness " << this->thickness << std::endl; - // surfComps structures - for (std::list::const_iterator it = surfComps.begin(); it != surfComps.end(); ++it) { + // surfaceComps structures + for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; it->dump_raw(s_oss, indent + 2); } // surface charge structures { - for (std::list::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) { + for (std::list::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { s_oss << indent1; s_oss << "-charge_component " << std::endl; it->dump_raw(s_oss, indent + 2); @@ -323,18 +327,18 @@ void cxxSurface::read_raw(CParser& parser) case 5: // component { - cxxSurfComp ec; + cxxSurfaceComp ec; ec.read_raw(parser); - this->surfComps.push_back(ec); + this->surfaceComps.push_back(ec); } useLastLine = true; break; case 6: // charge_component { - cxxSurfCharge ec; + cxxSurfaceCharge ec; ec.read_raw(parser); - this->surfCharges.push_back(ec); + this->surfaceCharges.push_back(ec); } useLastLine = true; break; @@ -364,3 +368,58 @@ void cxxSurface::read_raw(CParser& parser) parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +/* ---------------------------------------------------------------------- */ +void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + ints.push_back(this->surfaceComps.size()); + for (std::list::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) { + it->mpi_pack(ints, doubles); + } + ints.push_back(this->surfaceCharges.size()); + for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) { + it->mpi_pack(ints, doubles); + } + ints.push_back((int) this->diffuse_layer); + ints.push_back((int) this->edl); + ints.push_back((int) this->only_counter_ions); + ints.push_back((int) this->donnan); + doubles.push_back(this->thickness); +} +/* ---------------------------------------------------------------------- */ +void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +/* ---------------------------------------------------------------------- */ +{ + int i = *ii; + int d = *dd; + /* int n_user; */ + this->n_user = ints[i++]; + this->n_user_end = this->n_user; + this->description = " "; + + int count = ints[i++]; + this->surfaceComps.clear(); + for (int n = 0; n < count; n++) { + cxxSurfaceComp sc; + sc.mpi_unpack(ints, &i, doubles, &d); + this->surfaceComps.push_back(sc); + } + count = ints[i++]; + this->surfaceCharges.clear(); + for (int n = 0; n < count; n++) { + cxxSurfaceCharge sc; + sc.mpi_unpack(ints, &i, doubles, &d); + this->surfaceCharges.push_back(sc); + } + this->diffuse_layer = (bool) ints[i++]; + this->edl = (bool) ints[i++]; + this->only_counter_ions = (bool) ints[i++]; + this->donnan = (bool) ints[i++]; + this->thickness = doubles[d++]; + *ii = i; + *dd = d; +} +#endif diff --git a/Surface.h b/Surface.h index 03652f56..a96fd50b 100644 --- a/Surface.h +++ b/Surface.h @@ -11,8 +11,8 @@ #include // std::vector #include "char_star.h" -#include "SurfComp.h" -#include "SurfCharge.h" +#include "SurfaceComp.h" +#include "SurfaceCharge.h" class cxxSurface : public cxxNumKeyword { @@ -24,7 +24,7 @@ public: struct surface *cxxSurface2surface(); - struct surf_comp *cxxSurfComp2surf_comp(); + struct surf_comp *cxxSurfaceComp2surf_comp(); void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -36,10 +36,14 @@ public: bool get_related_rate(void); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif protected: - std::list surfComps; - std::list surfCharges; + std::list surfaceComps; + std::list surfaceCharges; bool diffuse_layer; bool edl; bool only_counter_ions; diff --git a/SurfCharge.cxx b/SurfaceCharge.cxx similarity index 82% rename from SurfCharge.cxx rename to SurfaceCharge.cxx index 5b7242c7..44d9e695 100644 --- a/SurfCharge.cxx +++ b/SurfaceCharge.cxx @@ -1,4 +1,4 @@ -// SurfCharge.cxx: implementation of the cxxSurfCharge class. +// SurfaceCharge.cxx: implementation of the cxxSurfaceCharge class. // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG @@ -6,7 +6,7 @@ #endif #include "Utils.h" // define first -#include "SurfCharge.h" +#include "SurfaceCharge.h" #define EXTERNAL extern #include "global.h" #include "output.h" @@ -19,9 +19,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSurfCharge::cxxSurfCharge() +cxxSurfaceCharge::cxxSurfaceCharge() // - // default constructor for cxxSurfCharge + // default constructor for cxxSurfaceCharge // { name = NULL; @@ -33,9 +33,9 @@ cxxSurfCharge::cxxSurfCharge() diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; } -cxxSurfCharge::cxxSurfCharge(struct surface_charge *surf_charge_ptr) +cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr) // - // constructor for cxxSurfCharge from struct surface_charge + // constructor for cxxSurfaceCharge from struct surface_charge // : diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) @@ -48,11 +48,11 @@ diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) la_psi = surf_charge_ptr->la_psi; } -cxxSurfCharge::~cxxSurfCharge() +cxxSurfaceCharge::~cxxSurfaceCharge() { } -struct master *cxxSurfCharge::get_psi_master() +struct master *cxxSurfaceCharge::get_psi_master() { struct master *master_ptr = NULL; std::string str = this->name; @@ -68,16 +68,16 @@ struct master *cxxSurfCharge::get_psi_master() return(master_ptr); } -struct surface_charge *cxxSurfCharge::cxxSurfCharge2surface_charge(std::list& el) +struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list& el) // - // Builds surface_charge structure from of cxxSurfCharge + // Builds surface_charge structure from of cxxSurfaceCharge // { struct surface_charge *surf_charge_ptr = (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); if (surf_charge_ptr == NULL) malloc_error(); int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { surf_charge_ptr[i].name = it->name; surf_charge_ptr[i].specific_area = it->specific_area; surf_charge_ptr[i].grams = it->grams; @@ -93,7 +93,7 @@ struct surface_charge *cxxSurfCharge::cxxSurfCharge2surface_charge(std::listdiffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); - parser.error_msg("Expected element name and molality for SurfCharge diffuse_layer_totals.", CParser::OT_CONTINUE); + parser.error_msg("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", CParser::OT_CONTINUE); } opt_save = 6; break; @@ -275,26 +275,56 @@ void cxxSurfCharge::read_raw(CParser& parser) // members that must be defined if (name_defined == false) { parser.incr_input_error(); - parser.error_msg("Name not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("Name not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } if (specific_area_defined == false) { parser.incr_input_error(); - parser.error_msg("Specific_area not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("Specific_area not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } if (grams_defined == false) { parser.incr_input_error(); - parser.error_msg("Grams not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("Grams not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } if (charge_balance_defined == false) { parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("Charge_balance not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } if (mass_water_defined == false) { parser.incr_input_error(); - parser.error_msg("Mass_water not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("Mass_water not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } if (la_psi_defined == false) { parser.incr_input_error(); - parser.error_msg("La_psi not defined for SurfCharge input.", CParser::OT_CONTINUE); + parser.error_msg("La_psi not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxSurfaceCharge::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + + ints.push_back(dictionary.string2int(this->name)); + doubles.push_back(this->specific_area); + doubles.push_back(this->grams); + doubles.push_back(this->charge_balance); + doubles.push_back(this->mass_water); + doubles.push_back(this->la_psi); + this->diffuse_layer_totals.mpi_pack(ints, doubles); +} +void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->name = dictionary.int2char(ints[i++]); + this->specific_area = doubles[d++]; + this->grams = doubles[d++]; + this->charge_balance = doubles[d++]; + this->mass_water = doubles[d++]; + this->la_psi = doubles[d++]; + this->diffuse_layer_totals.mpi_unpack(ints, &i, doubles, &d); + *ii = i; + *dd = d; +} +#endif diff --git a/SurfCharge.h b/SurfaceCharge.h similarity index 60% rename from SurfCharge.h rename to SurfaceCharge.h index 63022761..38d22fdb 100644 --- a/SurfCharge.h +++ b/SurfaceCharge.h @@ -1,5 +1,5 @@ -#if !defined(SURFCHARGE_H_INCLUDED) -#define SURFCHARGE_H_INCLUDED +#if !defined(SURFACECHARGE_H_INCLUDED) +#define SURFACECHARGE_H_INCLUDED #include "NameDouble.h" #define EXTERNAL extern @@ -12,19 +12,19 @@ #include "char_star.h" -class cxxSurfCharge +class cxxSurfaceCharge { public: - cxxSurfCharge(); - cxxSurfCharge(struct surface_charge *); - ~cxxSurfCharge(); + cxxSurfaceCharge(); + cxxSurfaceCharge(struct surface_charge *); + ~cxxSurfaceCharge(); struct master *get_psi_master(); - static struct surface_charge *cxxSurfCharge2surface_charge(std::list& el); + static struct surface_charge *cxxSurfaceCharge2surface_charge(std::list& el); void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -32,6 +32,11 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: char * name; double specific_area; @@ -47,4 +52,4 @@ public: }; -#endif // !defined(SURFCHARGE_H_INCLUDED) +#endif // !defined(SURFACECHARGE_H_INCLUDED) diff --git a/SurfComp.cxx b/SurfaceComp.cxx similarity index 85% rename from SurfComp.cxx rename to SurfaceComp.cxx index 831b4fc7..f5d8fed5 100644 --- a/SurfComp.cxx +++ b/SurfaceComp.cxx @@ -1,4 +1,4 @@ -// SurfComp.cxx: implementation of the cxxSurfComp class. +// SurfaceComp.cxx: implementation of the cxxSurfaceComp class. // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG @@ -6,7 +6,7 @@ #endif #include "Utils.h" // define first -#include "SurfComp.h" +#include "SurfaceComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -19,9 +19,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSurfComp::cxxSurfComp() +cxxSurfaceComp::cxxSurfaceComp() // - // default constructor for cxxSurfComp + // default constructor for cxxSurfaceComp // { formula = NULL; @@ -35,9 +35,9 @@ cxxSurfComp::cxxSurfComp() rate_name = NULL; } -cxxSurfComp::cxxSurfComp(struct surface_comp *surf_comp_ptr) +cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) // - // constructor for cxxSurfComp from struct surface_comp + // constructor for cxxSurfaceComp from struct surface_comp // : totals(surf_comp_ptr->totals) @@ -52,11 +52,11 @@ totals(surf_comp_ptr->totals) rate_name = surf_comp_ptr->rate_name; } -cxxSurfComp::~cxxSurfComp() +cxxSurfaceComp::~cxxSurfaceComp() { } -struct master *cxxSurfComp::get_master() +struct master *cxxSurfaceComp::get_master() { struct master *master_ptr = NULL; //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { @@ -84,16 +84,16 @@ struct master *cxxSurfComp::get_master() return(master_ptr); } -struct surface_comp *cxxSurfComp::cxxSurfComp2surface_comp(std::list& el) +struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list& el) // - // Builds surface_comp structure from of cxxSurfComp + // Builds surface_comp structure from of cxxSurfaceComp // { struct surface_comp *surf_comp_ptr = (struct surface_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); if (surf_comp_ptr == NULL) malloc_error(); int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { + for (std::list::iterator it = el.begin(); it != el.end(); ++it) { surf_comp_ptr[i].formula = it->formula; surf_comp_ptr[i].moles = it->moles; surf_comp_ptr[i].master = it->get_master(); @@ -110,7 +110,7 @@ struct surface_comp *cxxSurfComp::cxxSurfComp2surface_comp(std::listtotals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); - parser.error_msg("Expected element name and molality for SurfComp totals.", CParser::OT_CONTINUE); + parser.error_msg("Expected element name and molality for SurfaceComp totals.", CParser::OT_CONTINUE); } opt_save = 8; break; @@ -323,22 +323,56 @@ void cxxSurfComp::read_raw(CParser& parser) // members that must be defined if (formula_defined == false) { parser.incr_input_error(); - parser.error_msg("Formula not defined for SurfComp input.", CParser::OT_CONTINUE); + parser.error_msg("Formula not defined for SurfaceComp input.", CParser::OT_CONTINUE); } if (moles_defined == false) { parser.incr_input_error(); - parser.error_msg("Moles not defined for SurfComp input.", CParser::OT_CONTINUE); + parser.error_msg("Moles not defined for SurfaceComp input.", CParser::OT_CONTINUE); } if (la_defined == false) { parser.incr_input_error(); - parser.error_msg("La not defined for SurfComp input.", CParser::OT_CONTINUE); + parser.error_msg("La not defined for SurfaceComp input.", CParser::OT_CONTINUE); } if (charge_number_defined == false) { parser.incr_input_error(); - parser.error_msg("Charge_number not defined for SurfComp input.", CParser::OT_CONTINUE); + parser.error_msg("Charge_number not defined for SurfaceComp input.", CParser::OT_CONTINUE); } if (charge_balance_defined == false) { parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for SurfComp input.", CParser::OT_CONTINUE); + parser.error_msg("Charge_balance not defined for SurfaceComp input.", CParser::OT_CONTINUE); } } +#ifdef USE_MPI +#include "Dictionary.h" +void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubles) +{ + extern cxxDictionary dictionary; + + ints.push_back(dictionary.string2int(this->formula)); + doubles.push_back(this->moles); + this->totals.mpi_pack(ints, doubles); + doubles.push_back(this->la); + ints.push_back(charge_number); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.string2int(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.string2int(this->rate_name)); +} +void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->formula = dictionary.int2char(ints[i++]); + this->moles = doubles[d++]; + this->totals.mpi_unpack(ints, &i, doubles, &d); + this->la = doubles[d++]; + this->charge_number = ints[i++]; + this->charge_balance = doubles[d++]; + this->phase_name = dictionary.int2char(ints[i++]); + this->phase_proportion = doubles[d++]; + this->rate_name = dictionary.int2char(ints[i++]); + *ii = i; + *dd = d; +} +#endif diff --git a/SurfComp.h b/SurfaceComp.h similarity index 64% rename from SurfComp.h rename to SurfaceComp.h index c025dc95..67b88e68 100644 --- a/SurfComp.h +++ b/SurfaceComp.h @@ -1,5 +1,5 @@ -#if !defined(SURFCOMP_H_INCLUDED) -#define SURFCOMP_H_INCLUDED +#if !defined(SURFACECOMP_H_INCLUDED) +#define SURFACECOMP_H_INCLUDED #include "NameDouble.h" #define EXTERNAL extern @@ -12,21 +12,21 @@ #include "char_star.h" -class cxxSurfComp +class cxxSurfaceComp { public: - cxxSurfComp(); - cxxSurfComp(struct surface_comp *); - ~cxxSurfComp(); + cxxSurfaceComp(); + cxxSurfaceComp(struct surface_comp *); + ~cxxSurfaceComp(); struct master *get_master(); char *get_phase_name()const {return this->phase_name;} char *get_rate_name()const {return this->rate_name;} - static struct surface_comp *cxxSurfComp2surface_comp(std::list& el); + static struct surface_comp *cxxSurfaceComp2surface_comp(std::list& el); void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -34,6 +34,11 @@ public: void read_raw(CParser& parser); +#ifdef USE_MPI + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: char * formula; double moles; @@ -49,4 +54,4 @@ public: }; -#endif // !defined(SURFCOMP_H_INCLUDED) +#endif // !defined(SURFACECOMP_H_INCLUDED) From 764d31c7ae4c973355125d18056f060ef9b38b0c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 May 2006 23:09:32 +0000 Subject: [PATCH 0025/1077] Added Dictionary to svn Use pointer to vector instead of copying arrays. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@901 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cxx | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ Dictionary.h | 46 ++++++++++++++++++++++ StorageBin.cxx | 13 +++--- 3 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 Dictionary.cxx create mode 100644 Dictionary.h diff --git a/Dictionary.cxx b/Dictionary.cxx new file mode 100644 index 00000000..e51cc72c --- /dev/null +++ b/Dictionary.cxx @@ -0,0 +1,105 @@ +// StorageBin.cxx: implementation of the cxxStorageBin class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include "Dictionary.h" // define first +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include "output.h" +#include // assert +#include // std::sort + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +cxxDictionary::cxxDictionary() +{ + // default constructor for cxxStorageBin +} + +cxxDictionary::~cxxDictionary() +{ +} + +void cxxDictionary::add_phreeqc() { + HashTable *Table = strings_hash_table; + int i,j; + Segment *seg; + Element *p,*q; + + if (Table != NULL) { + for (i = 0; i < Table->SegmentCount; i++) { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) { + for (j = 0; j < SegmentSize; j++) { + p = seg[j]; + while (p != NULL) { + q = p->Next; + //p->Data = (char*) free_check_null((void*)p->Data); + this->putString((char *) (p->Data)); + p = q; + } + } + } + } + } +} + +int cxxDictionary::putString(std::string str) { + int n; + std::map::iterator it = stringkey.find(str); + if (it != stringkey.end()) { + n = it->second; + } else { + n = stringkey.size(); + stringkey[str] = n; + intkey[n] = str; + } + return(n); +} + +int cxxDictionary::putString(char * str) { + std::string str1(str); + return (putString(str1)); +} + +int cxxDictionary::string2int(std::string str) { + int n; + std::map::iterator it = stringkey.find(str); + if (it != stringkey.end()) { + n = it->second; + } else { + n = -1; + } + return(n); +} + +int cxxDictionary::string2int(char * str) { + if (str == NULL) return (-1); + std::string str1(str); + return(string2int(str1)); +} + + +std::string *cxxDictionary::int2string(int i) { + std::map::iterator it = intkey.find(i); + if (it != intkey.end()) { + return(&it->second); + } else { + return(NULL); + } +} + +char *cxxDictionary::int2char(int i) { + std::map::iterator it = intkey.find(i); + if (it != intkey.end()) { + return(string_hsave(it->second.c_str())); + } else { + return(NULL); + } +} diff --git a/Dictionary.h b/Dictionary.h new file mode 100644 index 00000000..07606db5 --- /dev/null +++ b/Dictionary.h @@ -0,0 +1,46 @@ +#if !defined(DICTIONARY_H_INCLUDED) +#define DICTIONARY_H_INCLUDED + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector +#include "Solution.h" +#include "NameDouble.h" + +class cxxDictionary +{ + +public: + cxxDictionary(); + + ~cxxDictionary(); + + void add_phreeqc(); + + int size() { + return stringkey.size(); + } + + int putString(std::string str); + int putString(char * str); + + int string2int(std::string str); + + int string2int(char * str); + + std::string *int2string(int i); + + char *cxxDictionary::int2char(int i); + +protected: + std::map stringkey; + std::map intkey; + +public: + + +}; + +#endif // !defined(DICTIONARY_H_INCLUDED) diff --git a/StorageBin.cxx b/StorageBin.cxx index 3f516833..fe450649 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -682,9 +682,10 @@ void cxxStorageBin::mpi_send(int n, int task_number) // Convert to arrays int i = ints.size(); - int int_array[i]; + //int int_array[i]; int d = doubles.size(); - double double_array[d]; + //double double_array[d]; + /* for (int j = 0; j < i; j++) { int_array[j] = ints[j]; //std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl; @@ -693,16 +694,18 @@ void cxxStorageBin::mpi_send(int n, int task_number) double_array[j] = doubles[j]; //std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl; } - + */ /* * Send message to processor */ int position = 0; MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + //MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + //MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); From d8a1b2d7fa134f7caab2b16bd677a012d290820d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 May 2006 17:12:45 +0000 Subject: [PATCH 0026/1077] Renaming some files git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@907 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 4 ++-- Solution.cxx | 3 +-- Solution.h | 2 +- StorageBin.h | 4 ++-- KineticsCxx.cxx => cxxKinetics.cxx | 2 +- KineticsCxx.h => cxxKinetics.h | 6 +++--- Mix.cxx => cxxMix.cxx | 2 +- Mix.h => cxxMix.h | 6 +++--- 8 files changed, 14 insertions(+), 15 deletions(-) rename KineticsCxx.cxx => cxxKinetics.cxx (99%) rename KineticsCxx.h => cxxKinetics.h (91%) rename Mix.cxx => cxxMix.cxx (99%) rename Mix.h => cxxMix.h (89%) diff --git a/ReadClass.cxx b/ReadClass.cxx index 188f9881..97dbb881 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -6,11 +6,11 @@ #include "Exchange.h" #include "Surface.h" #include "PPassemblage.h" -#include "KineticsCxx.h" +#include "cxxKinetics.h" #include "SSassemblage.h" #include "GasPhase.h" #include "Reaction.h" -#include "Mix.h" +#include "cxxMix.h" #include "Temperature.h" #define EXTERNAL extern #include "global.h" diff --git a/Solution.cxx b/Solution.cxx index 48efe692..c47bfebc 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1008,11 +1008,10 @@ void cxxSolution::set_master_activity(char *string, double d) #include "Exchange.h" #include "Surface.h" #include "PPassemblage.h" -#include "KineticsCxx.h" +#include "cxxKinetics.h" #include "SSassemblage.h" #include "GasPhase.h" #include "Reaction.h" -#include "Mix.h" #include "Temperature.h" #include "StorageBin.h" #include "NumKeyword.h" diff --git a/Solution.h b/Solution.h index 564a3c09..d2d72cbb 100644 --- a/Solution.h +++ b/Solution.h @@ -4,7 +4,7 @@ #include "NumKeyword.h" #include "SolutionIsotopeList.h" #include "NameDouble.h" -#include "Mix.h" +#include "cxxMix.h" #define EXTERNAL extern #include "global.h" diff --git a/StorageBin.h b/StorageBin.h index cb6f9ec1..c65e8c2f 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -6,11 +6,11 @@ #include "Solution.h" #include "Exchange.h" #include "GasPhase.h" -#include "KineticsCxx.h" +#include "cxxKinetics.h" #include "PPassemblage.h" #include "SSassemblage.h" #include "Surface.h" -#include "Mix.h" +#include "cxxMix.h" #include "Reaction.h" #include "Temperature.h" diff --git a/KineticsCxx.cxx b/cxxKinetics.cxx similarity index 99% rename from KineticsCxx.cxx rename to cxxKinetics.cxx index 8c329a18..bcac3a88 100644 --- a/KineticsCxx.cxx +++ b/cxxKinetics.cxx @@ -6,7 +6,7 @@ #endif #include "Utils.h" // define first -#include "KineticsCxx.h" +#include "cxxKinetics.h" #include "KineticsComp.h" #define EXTERNAL extern #include "global.h" diff --git a/KineticsCxx.h b/cxxKinetics.h similarity index 91% rename from KineticsCxx.h rename to cxxKinetics.h index d0be59e0..f22d6452 100644 --- a/KineticsCxx.h +++ b/cxxKinetics.h @@ -1,5 +1,5 @@ -#if !defined(KINETICS_H_INCLUDED) -#define KINETICS_H_INCLUDED +#if !defined(CXXKINETICS_H_INCLUDED) +#define CXXKINETICS_H_INCLUDED #include "NumKeyword.h" #define EXTERNAL extern @@ -53,4 +53,4 @@ public: }; -#endif // !defined(KINETICS_H_INCLUDED) +#endif // !defined(CXXKINETICS_H_INCLUDED) diff --git a/Mix.cxx b/cxxMix.cxx similarity index 99% rename from Mix.cxx rename to cxxMix.cxx index bc65783f..80801b0b 100644 --- a/Mix.cxx +++ b/cxxMix.cxx @@ -6,7 +6,7 @@ #endif #include "Utils.h" // define first -#include "Mix.h" +#include "cxxMix.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" diff --git a/Mix.h b/cxxMix.h similarity index 89% rename from Mix.h rename to cxxMix.h index ba66169a..4f28bf3f 100644 --- a/Mix.h +++ b/cxxMix.h @@ -1,5 +1,5 @@ -#if !defined(MIX_H_INCLUDED) -#define MIX_H_INCLUDED +#if !defined(CXXMIX_H_INCLUDED) +#define CXXMIX_H_INCLUDED #include "NumKeyword.h" #define EXTERNAL extern @@ -43,4 +43,4 @@ public: }; -#endif // !defined(MIX_H_INCLUDED) +#endif // !defined(CXXMIX_H_INCLUDED) From 6df20749e2e49c762c3bfc54543031c39a278064 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 12 May 2006 19:26:37 +0000 Subject: [PATCH 0027/1077] Added mix_cxxExchange to storage bin with assorted routines and changes to make it work. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@921 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 57 ++++++++++++++++++++++++++++++++-- ExchComp.h | 1 + Exchange.h | 9 ++++-- NameDouble.h | 4 +++ Solution.cxx | 44 ++++++++++++++++++++++++++ StorageBin.cxx | 83 +++++++++++++++++++++++++++++++++++++++++++++++++- StorageBin.h | 1 + 7 files changed, 194 insertions(+), 5 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 2b92367d..d51f3a27 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -25,13 +25,14 @@ cxxExchComp::cxxExchComp() // { moles = 0.0; + formula_totals.type = cxxNameDouble::ND_ELT_MOLES; + totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; charge_balance = 0.0; phase_name = NULL; phase_proportion = 0.0; rate_name = NULL; - totals.type = cxxNameDouble::ND_ELT_MOLES; - formula_totals.type = cxxNameDouble::ND_ELT_MOLES; + formula_z = 0.0; } cxxExchComp::cxxExchComp(struct exch_comp *exch_comp_ptr) @@ -53,6 +54,58 @@ totals(exch_comp_ptr->totals) rate_name = exch_comp_ptr->rate_name; formula_z = exch_comp_ptr->formula_z; } +cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vector &f_vector) + // + // constructor for cxxExchComp from struct exch_comp + // +{ + if (ec_vector.size() <= 0) return; + // + // check consistency + // + std::vector::iterator it_f; + std::vector::iterator it_ec; + // set fixed variables + it_ec = ec_vector.begin(); + this->formula = it_ec->formula; + this->formula_totals = it_ec->formula_totals; + this->formula_z = it_ec->formula_z; + this->phase_name = it_ec->phase_name; + this->rate_name = it_ec->rate_name; + it_ec++; + for ( ; it_ec != ec_vector.end(); it_ec++) { + if (it_ec->formula != this->formula || + it_ec->formula_z != this->formula_z || + it_ec->phase_name != this->phase_name || + this->rate_name != this->rate_name) { + error_msg("Mixing exchange components. Formula, z, phase_name, or rate_name did not match", STOP); + } + } + // calculate sum of extensive factors + double sum_extensive = 0; + for (it_f = f_vector.begin(); it_f != f_vector.end(); it_f++) { + sum_extensive += *it_f; + } + this->moles = 0; + this->la = 0; + this->charge_balance = 0; + this->phase_proportion = 0; + this->totals.clear(); + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + it_ec = ec_vector.begin(); + it_f = f_vector.begin(); + for (; it_ec != ec_vector.end(); ) { + double extensive = *it_f; + double intensive = extensive/sum_extensive; + this->moles += it_ec->moles*extensive; + this->la += it_ec->la*intensive; + this->charge_balance += it_ec->charge_balance*extensive; + this->phase_proportion += it_ec->phase_proportion*intensive; + this->totals.add(it_ec->totals, extensive); + it_ec++; + it_f++; + } +} cxxExchComp::~cxxExchComp() { diff --git a/ExchComp.h b/ExchComp.h index dc2f7abb..64972d6d 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -18,6 +18,7 @@ class cxxExchComp public: cxxExchComp(); cxxExchComp(struct exch_comp *); + cxxExchComp(std::vector &ec_vector, std::vector &f_vector); ~cxxExchComp(); diff --git a/Exchange.h b/Exchange.h index 76306f85..c4b3e34e 100644 --- a/Exchange.h +++ b/Exchange.h @@ -35,10 +35,15 @@ public: bool get_related_rate(void); + std::list &get_exchComps(void) { + return(this->exchComps); + } + #ifdef USE_MPI - void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles); - void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif + protected: std::list exchComps; bool pitzer_exchange_gammas; diff --git a/NameDouble.h b/NameDouble.h index ab6c5b07..cac0a527 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -46,6 +46,10 @@ public: void add(const cxxNameDouble &old, double factor); + void insert(char *str, double d) { + (*this)[str] = d; + } + void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_pack(int *ints, int *ii, double *doubles, int *dd); diff --git a/Solution.cxx b/Solution.cxx index c47bfebc..3f602d52 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1003,6 +1003,50 @@ void cxxSolution::set_master_activity(char *string, double d) { this->master_activity[string] = d; } +#ifdef SKIP +#include "../hst.h" +/* ---------------------------------------------------------------------- */ +void cxxSolution::xsolution_save(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save solution composition into Solution class + * + * input: n is pointer number in solution + */ + this->set_description(" "); + this->n_user = n; + this->n_user_end = n; + this->tc = tc_x; + this->ph = ph_x; + this->pe = solution_pe_x; + this->mu = mu_x; + this->ah2o = ah2o_x; + this->total_h = total_h_x; + this->total_o = total_o_x; + this->cb = cb_x; + this->mass_water = mass_water_aq_x; + this->total_alkalinity = total_alkalinity; +/* + * Copy totals data + */ + for (int j = 2; j < count_total; j++) { + this->totals.insert(buffer[j].master->elt->name, buffer[j].master->total_primary); + } + + for (int j = 0; j < count_activity_list; j++) { + this->master_activity.insert(activity_list[j].master->elt->name, activity_list[j].master->s->la); + } + if (pitzer_model == TRUE) { + for (int j= 0; j < count_s; j++) { + if (s[j]->lg != 0.0) { + this->species_gamma.insert(s[j]->name, s[j]->lg); + } + } + } +} +#endif + #include "ISolution.h" #include "Exchange.h" diff --git a/StorageBin.cxx b/StorageBin.cxx index fe450649..71c0016d 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -321,7 +321,6 @@ void cxxStorageBin::add(struct system * system_ptr) } } -//#include // std::cout std::cerr void cxxStorageBin::cxxStorageBin2phreeqc(int n) // // copy data fromphreeqc storage to storage bin @@ -818,3 +817,85 @@ void cxxStorageBin::mpi_recv(int task_number) } #endif + +cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) + +{ +/* + * mixes exchangers based on cxxMix structure, returns new exchanger + * return exchanger must be freed by calling method + */ + cxxExchange *new_exch_ptr, *old_exch_ptr; +/* + * Zero out global solution data + */ + new_exch_ptr = new cxxExchange(); + + std::map::const_iterator it_mix; + std::map *mixcomps = mixmap.comps(); +/* + * Make list of ExchComps + */ + std::vector ec_vector; + std::vector f_vector; + // + // make list of all exchange components and their mix fractions + // + for (it_mix = mixcomps->begin(); it_mix != mixcomps->end(); it_mix++) { + old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); + if (old_exch_ptr == NULL) { + sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); + error_msg(error_string, CONTINUE); + input_error++; + return(NULL); + } + // Add exchange components to vector ec_vector + std::list::const_iterator it_ec; + std::list &eclist = old_exch_ptr->get_exchComps(); + for (it_ec = eclist.begin(); it_ec != eclist.end(); it_ec++) { + f_vector.push_back(it_mix->second); + //cxxExchComp ec = *it_ec; + //ec_vector.push_back(ec); + ec_vector.push_back(*it_ec); + } + } + // + // Process list to make mixture + // + char *current_formula = ec_vector.begin()->get_formula(); + while (current_formula != NULL) { + + std::vector ec_subvector; + std::vector f_subvector; + std::vector::iterator it_ec = ec_vector.begin(); + std::vector::iterator it_f = f_vector.begin(); + current_formula = NULL; + for ( ; it_ec != ec_vector.end(); it_ec++) { + if (*it_f != 0) { + if (current_formula == NULL) current_formula = it_ec->get_formula(); + if (it_ec->get_formula() == current_formula) { + ec_subvector.push_back(*it_ec); + f_subvector.push_back(*it_f); + *it_f = 0; + //ec_vector.erase(it_ec); + //f_vector.erase(it_f); + } + } + it_f++; + } + // + // mix ec_subvector to make + // one exchange component + // + if (current_formula != NULL) { + cxxExchComp new_comp(ec_subvector, f_subvector); + new_exch_ptr->get_exchComps().push_back(new_comp); + } + } + /* + std::ostringstream oss; + new_exch_ptr->dump_raw(oss, 0); + std::cerr << oss.str(); + */ + return(new_exch_ptr); +} diff --git a/StorageBin.h b/StorageBin.h index c65e8c2f..3b19c292 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -138,6 +138,7 @@ public: struct system *cxxStorageBin2system(int i); cxxSolution *mix_cxxSolutions(cxxMix &mixmap); + cxxExchange *mix_cxxExchange(cxxMix &mixmap); #ifdef USE_MPI void mpi_send(int n, int task_number); From 1e28de647fb01ed31492622be04223eca4fe79cc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 16 May 2006 01:10:25 +0000 Subject: [PATCH 0028/1077] changed automatic arrays to dynamic arrays git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@924 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 12 ++++++++---- StorageBin.cxx | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 3f602d52..3b5f462f 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -904,9 +904,9 @@ void cxxSolution::mpi_send(int task_number) */ position = 0; int i = ints.size(); - int int_array[i]; + int *int_array = new int[i]; int d = doubles.size(); - double double_array[d]; + double *double_array = new double[d]; for (int j = 0; j < i; j++) { int_array[j] = ints[j]; } @@ -922,6 +922,8 @@ void cxxSolution::mpi_send(int task_number) MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); + delete[] int_array; + delete[] double_array; } /* ---------------------------------------------------------------------- */ void cxxSolution::mpi_recv(int task_number) @@ -948,13 +950,13 @@ void cxxSolution::mpi_recv(int task_number) /* Unpack ints */ int count_ints; MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); - int ints[count_ints]; + int *ints = new int[count_ints]; MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); /* Unpack doubles */ int count_doubles; MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); - double doubles[count_doubles]; + double *doubles = new double[count_doubles]; MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); buffer = free_check_null(buffer); /* @@ -997,6 +999,8 @@ void cxxSolution::mpi_recv(int task_number) * struct master_activity *species_gamma; */ this->species_gamma.mpi_unpack(ints, &i, doubles, &d); + delete[] ints; + delete[] doubles; } #endif void cxxSolution::set_master_activity(char *string, double d) diff --git a/StorageBin.cxx b/StorageBin.cxx index 71c0016d..b816f94f 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -734,13 +734,13 @@ void cxxStorageBin::mpi_recv(int task_number) /* Unpack ints */ int count_ints; MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); - int ints[count_ints]; + int *ints = new int[count_ints]; MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); /* Unpack doubles */ int count_doubles; MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); - double doubles[count_doubles]; + double *doubles = new double[count_doubles]; MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); buffer = free_check_null(buffer); #ifdef SKIP @@ -815,6 +815,8 @@ void cxxStorageBin::mpi_recv(int task_number) } //std::cerr << "Unpacked Surface" << std::endl; + delete[] ints; + delete[] doubles; } #endif From 382075cc6ace774db09ac234cab53e39fcebfe51 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 18 May 2006 16:15:04 +0000 Subject: [PATCH 0029/1077] Couple changes for exchange mixing git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@945 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.h | 7 +++++++ StorageBin.cxx | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Exchange.h b/Exchange.h index c4b3e34e..ac7c1a8c 100644 --- a/Exchange.h +++ b/Exchange.h @@ -35,6 +35,13 @@ public: bool get_related_rate(void); + bool get_pitzer_exchange_gammas() { + return this->pitzer_exchange_gammas; + } + void set_pitzer_exchange_gammas(bool b) { + this->pitzer_exchange_gammas = b; + } + std::list &get_exchComps(void) { return(this->exchComps); } diff --git a/StorageBin.cxx b/StorageBin.cxx index b816f94f..8d0e6a4e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -832,9 +832,20 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) * Zero out global solution data */ new_exch_ptr = new cxxExchange(); - + std::map::const_iterator it_mix; std::map *mixcomps = mixmap.comps(); + + // Pitzer_exchange_gammas + it_mix = mixcomps->begin(); + old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); + if (old_exch_ptr == NULL) { + sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); + error_msg(error_string, CONTINUE); + input_error++; + return(NULL); + } + new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr->get_pitzer_exchange_gammas()); /* * Make list of ExchComps */ From a524c4610672fdcb14aa520769243b6f8aa5106a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 24 May 2006 13:50:19 +0000 Subject: [PATCH 0030/1077] Updated to latest PHAST cpp files. Ran test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@954 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 252 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 144 insertions(+), 108 deletions(-) diff --git a/Makefile b/Makefile index b6844869..1bfbf5a1 100644 --- a/Makefile +++ b/Makefile @@ -145,8 +145,8 @@ COMMON_CXXOBJS = \ ISolution.o \ ISolutionComp.o \ KineticsComp.o \ - KineticsCxx.o \ - Mix.o \ + cxxKinetics.o \ + cxxMix.o \ NameDouble.o \ NumKeyword.o \ Parser.o \ @@ -161,8 +161,8 @@ COMMON_CXXOBJS = \ SSassemblageSS.o \ StorageBin.o \ Surface.o \ - SurfCharge.o \ - SurfComp.o \ + SurfaceCharge.o \ + SurfaceComp.o \ Temperature.o \ Utils.o @@ -180,104 +180,120 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -EntityMap.o: ../EntityMap.cxx ../Utils.h ../EntityMap.h \ +cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../char_star.h \ + ../cxxKinetics.h ../NumKeyword.h ../Parser.h ../char_star.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../KineticsComp.h ../NameDouble.h ../char_star.h ../Parser.h \ + ../char_star.h ../KineticsComp.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +cxxMix.o: ../cxxMix.cxx ../Utils.h ../char_star.h ../cxxMix.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +Dictionary.o: ../Dictionary.cxx ../Dictionary.h ../Solution.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ + ../char_star.h ../NameDouble.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h +EntityMap.o: ../EntityMap.cxx ../Utils.h ../char_star.h ../EntityMap.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Exchange.o: ../Exchange.cxx ../Utils.h ../Exchange.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../ExchComp.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../ExchComp.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../GasPhase.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ +Exchange.o: ../Exchange.cxx ../Utils.h ../char_star.h ../Exchange.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../ExchComp.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../char_star.h ../ExchComp.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ - ../char_star.h ../ISolution.h ../ISolutionComp.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../Utils.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h -ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ - ../Utils.h ../char_star.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../KineticsComp.h \ +ExchComp.o: ../ExchComp.cxx ../Utils.h ../char_star.h ../ExchComp.h \ ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -KineticsCxx.o: ../KineticsCxx.cxx ../Utils.h ../KineticsCxx.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../char_star.h ../KineticsComp.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Mix.o: ../Mix.cxx ../Utils.h ../Mix.h ../NumKeyword.h ../Parser.h \ - ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../NameDouble.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +GasPhase.o: ../GasPhase.cxx ../Utils.h ../char_star.h ../GasPhase.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../NameDouble.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ + ../char_star.h ../char_star.h ../ISolution.h ../ISolutionComp.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../Parser.h ../NameDouble.h ../char_star.h ../Parser.h ../cxxMix.h \ + ../NumKeyword.h ../char_star.h ../char_star.h ../Utils.h \ + ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h +ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ + ../Utils.h ../char_star.h ../char_star.h ../NumKeyword.h ../Parser.h \ + ../char_star.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../char_star.h \ + ../KineticsComp.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../char_star.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ ../char_star.h Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ - ../char_star.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ + ../char_star.h ../char_star.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../char_star.h \ ../PPassemblageComp.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../PPassemblage.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../PPassemblageComp.h \ - ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ - ../PPassemblageComp.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Reaction.o: ../Reaction.cxx ../Utils.h ../Reaction.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../char_star.h \ + ../PPassemblage.h ../NumKeyword.h ../Parser.h ../char_star.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../Parser.h \ + ../char_star.h ../PPassemblageComp.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +Reaction.o: ../Reaction.cxx ../Utils.h ../char_star.h ../Reaction.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../NameDouble.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../Exchange.h ../NumKeyword.h \ - ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ - ../Surface.h ../NumKeyword.h ../char_star.h ../SurfComp.h \ - ../NameDouble.h ../char_star.h ../SurfCharge.h ../NameDouble.h \ - ../char_star.h ../PPassemblage.h ../NumKeyword.h ../char_star.h \ - ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../KineticsCxx.h \ - ../NumKeyword.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ - ../char_star.h ../SSassemblage.h ../NumKeyword.h ../char_star.h \ - ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../GasPhase.h \ - ../NumKeyword.h ../NameDouble.h ../char_star.h ../Reaction.h \ - ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h ../NumKeyword.h \ - ../char_star.h ../Temperature.h ../NumKeyword.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../NumKeyword.h ../Parser.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ + ../char_star.h ../Exchange.h ../NumKeyword.h ../char_star.h \ + ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ + ../NumKeyword.h ../char_star.h ../SurfaceComp.h ../NameDouble.h \ + ../char_star.h ../SurfaceCharge.h ../NameDouble.h ../char_star.h \ + ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ + ../NameDouble.h ../char_star.h ../cxxKinetics.h ../NumKeyword.h \ + ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ + ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ + ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ + ../NameDouble.h ../char_star.h ../cxxMix.h ../Temperature.h \ + ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h Solution.o: ../Solution.cxx ../Utils.h ../char_star.h ../Solution.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../Mix.h ../NumKeyword.h ../char_star.h \ + ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../ISolution.h ../ISolutionComp.h ../Utils.h ../char_star.h \ - ../NumKeyword.h ../Solution.h ../Exchange.h ../NumKeyword.h \ - ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ - ../Surface.h ../NumKeyword.h ../char_star.h ../SurfComp.h \ - ../NameDouble.h ../char_star.h ../SurfCharge.h ../NameDouble.h \ - ../char_star.h ../PPassemblage.h ../NumKeyword.h ../char_star.h \ - ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../KineticsCxx.h \ - ../NumKeyword.h ../char_star.h ../KineticsComp.h ../NameDouble.h \ - ../char_star.h ../SSassemblage.h ../NumKeyword.h ../char_star.h \ - ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../GasPhase.h \ - ../NumKeyword.h ../NameDouble.h ../char_star.h ../Reaction.h \ - ../NumKeyword.h ../NameDouble.h ../char_star.h ../Mix.h \ + ../phreeqc/output.h ../ISolution.h ../ISolutionComp.h ../Utils.h \ + ../char_star.h ../NumKeyword.h ../Solution.h ../Exchange.h \ + ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ + ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ + ../SurfaceComp.h ../NameDouble.h ../char_star.h ../SurfaceCharge.h \ + ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ + ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ + ../cxxKinetics.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ + ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ + ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ ../Temperature.h ../NumKeyword.h ../char_star.h ../StorageBin.h \ ../Utils.h ../Parser.h ../Solution.h ../Exchange.h ../GasPhase.h \ - ../KineticsCxx.h ../PPassemblage.h ../SSassemblage.h ../Surface.h \ - ../Mix.h ../Reaction.h ../Temperature.h ../NumKeyword.h + ../cxxKinetics.h ../PPassemblage.h ../SSassemblage.h ../Surface.h \ + ../cxxMix.h ../Reaction.h ../Temperature.h ../NumKeyword.h SolutionIsotope.o: ../SolutionIsotope.cxx ../SolutionIsotope.h \ ../Parser.h ../char_star.h ../Utils.h ../char_star.h ../Parser.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h \ @@ -286,37 +302,57 @@ SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ ../char_star.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../char_star.h ../Parser.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../SSassemblage.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../SSassemblageSS.h \ - ../NameDouble.h ../char_star.h ../Parser.h ../char_star.h \ - ../SSassemblageSS.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../SSassemblageSS.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ - ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../StorageBin.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h \ +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../char_star.h \ + ../SSassemblage.h ../NumKeyword.h ../Parser.h ../char_star.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../Parser.h \ + ../char_star.h ../SSassemblageSS.h ../phreeqc/phqalloc.h \ ../phreeqc/phrqproto.h -Surface.o: ../Surface.cxx ../Utils.h ../Surface.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../SurfComp.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../SurfCharge.h ../NameDouble.h ../char_star.h \ - ../SurfComp.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SurfCharge.o: ../SurfCharge.cxx ../Utils.h ../SurfCharge.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ - ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SurfComp.o: ../SurfComp.cxx ../Utils.h ../SurfComp.h ../NameDouble.h \ +SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../char_star.h \ + ../SSassemblageSS.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../char_star.h ../NameDouble.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../char_star.h ../StorageBin.h \ + ../Utils.h ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h \ + ../Parser.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -Temperature.o: ../Temperature.cxx ../Utils.h ../Temperature.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../phreeqc/phqalloc.h \ + ../NameDouble.h ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h \ + ../char_star.h ../char_star.h ../Exchange.h ../NumKeyword.h \ + ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ + ../cxxKinetics.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ + ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ + ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ + ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ + ../NameDouble.h ../char_star.h ../Surface.h ../NumKeyword.h \ + ../char_star.h ../SurfaceComp.h ../NameDouble.h ../char_star.h \ + ../SurfaceCharge.h ../NameDouble.h ../char_star.h ../cxxMix.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ + ../Temperature.h ../NumKeyword.h ../char_star.h ../Solution.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../char_star.h \ + ../SurfaceCharge.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../char_star.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ ../phreeqc/phrqproto.h -Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../char_star.h \ +SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../char_star.h \ + ../SurfaceComp.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ + ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ ../phreeqc/output.h +Surface.o: ../Surface.cxx ../Utils.h ../char_star.h ../Surface.h \ + ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../char_star.h ../SurfaceComp.h ../NameDouble.h \ + ../char_star.h ../Parser.h ../char_star.h ../SurfaceCharge.h \ + ../NameDouble.h ../char_star.h ../SurfaceComp.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +Temperature.o: ../Temperature.cxx ../Utils.h ../char_star.h \ + ../Temperature.h ../NumKeyword.h ../Parser.h ../char_star.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +Utils.o: ../Utils.cxx ../Utils.h ../char_star.h ../Parser.h \ + ../char_star.h ../phreeqc/output.h # # PHREEQC files # From 309d3d7beeb469408fdd032645e5a5724a58a25b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 7 Jul 2006 21:27:45 +0000 Subject: [PATCH 0031/1077] Fixed cast warnings in c++ git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1008 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cxx | 2 +- Dictionary.h | 2 +- Exchange.cxx | 4 ++-- GasPhase.cxx | 2 +- KineticsComp.cxx | 6 +++--- NameDouble.cxx | 4 ++-- PPassemblage.cxx | 4 ++-- Parser.cxx | 4 ++-- Reaction.cxx | 4 ++-- SSassemblage.cxx | 4 ++-- SSassemblageSS.cxx | 2 +- Solution.cxx | 14 +++++++------- StorageBin.cxx | 8 ++++---- Surface.cxx | 8 ++++---- Temperature.cxx | 4 ++-- cxxKinetics.cxx | 8 ++++---- cxxMix.cxx | 2 +- 17 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Dictionary.cxx b/Dictionary.cxx index e51cc72c..287090b8 100644 --- a/Dictionary.cxx +++ b/Dictionary.cxx @@ -56,7 +56,7 @@ int cxxDictionary::putString(std::string str) { if (it != stringkey.end()) { n = it->second; } else { - n = stringkey.size(); + n = (int) stringkey.size(); stringkey[str] = n; intkey[n] = str; } diff --git a/Dictionary.h b/Dictionary.h index 07606db5..584feebd 100644 --- a/Dictionary.h +++ b/Dictionary.h @@ -20,7 +20,7 @@ public: void add_phreeqc(); int size() { - return stringkey.size(); + return (int) stringkey.size(); } int putString(std::string str); diff --git a/Exchange.cxx b/Exchange.cxx index b6438fc0..cfdb3c45 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -91,7 +91,7 @@ struct exchange *cxxExchange::cxxExchange2exchange() exchange_ptr->related_phases = (int) this->get_related_phases(); exchange_ptr->related_rate = (int) this->get_related_rate(); exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; - exchange_ptr->count_comps = this->exchComps.size(); + exchange_ptr->count_comps = (int) this->exchComps.size(); exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps); exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); return(exchange_ptr); @@ -230,7 +230,7 @@ void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles) ints.push_back(this->n_user); ints.push_back((int) this->pitzer_exchange_gammas); - ints.push_back(this->exchComps.size()); + ints.push_back((int) this->exchComps.size()); for (std::list::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) { it->mpi_pack(ints, doubles); } diff --git a/GasPhase.cxx b/GasPhase.cxx index 2e8f12db..23c11d27 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -103,7 +103,7 @@ struct gas_phase *cxxGasPhase::cxxGasPhase2gas_phase() gas_phase_ptr->temperature = 273.15; // comps - gas_phase_ptr->count_comps = this->gasPhaseComps.size(); + gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size(); gas_phase_ptr->comps = (struct gas_comp *) free_check_null(gas_phase_ptr->comps); gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(); diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 41097593..17bbfbf8 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -64,7 +64,7 @@ struct kinetics_comp *cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list::iterator it = el.begin(); it != el.end(); ++it) { kinetics_comp_ptr[i].rate_name = it->rate_name; kinetics_comp_ptr[i].list = it->namecoef.name_coef(); - kinetics_comp_ptr[i].count_list = it->namecoef.size(); + kinetics_comp_ptr[i].count_list = (int) it->namecoef.size(); kinetics_comp_ptr[i].tol = it->tol; kinetics_comp_ptr[i].m = it->m; kinetics_comp_ptr[i].initial_moles = 0.; @@ -77,7 +77,7 @@ struct kinetics_comp *cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::listd_params.size(); + kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size(); kinetics_comp_ptr[i].d_params = NULL; if (it->d_params.size() > 0) { kinetics_comp_ptr[i].d_params = (double *) PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double))); @@ -320,7 +320,7 @@ void cxxKineticsComp::mpi_pack(std::vector& ints, std::vector& doub doubles.push_back(this->m); doubles.push_back(this->m0); doubles.push_back(this->moles); - ints.push_back(this->d_params.size()); + ints.push_back((int) this->d_params.size()); for (std::vector::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) { doubles.push_back(*it); } diff --git a/NameDouble.cxx b/NameDouble.cxx index f1013f35..cf477416 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -294,7 +294,7 @@ void cxxNameDouble::add(const cxxNameDouble &old, double factor) #include "Dictionary.h" void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; - ints.push_back( (*this).size() ); + ints.push_back( (int) (*this).size() ); for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { assert(it->first != NULL); int n = dictionary.string2int(it->first); @@ -308,7 +308,7 @@ void cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) int d = *dd; extern cxxDictionary dictionary; //ints.push_back( (*this).size() ); - ints[i++] = this->size(); + ints[i++] = (int) this->size(); for (const_iterator it = this->begin(); it != this->end(); it++) { int n = dictionary.string2int(it->first); if (n < 0) { diff --git a/PPassemblage.cxx b/PPassemblage.cxx index b08cc5fa..54458d88 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -62,7 +62,7 @@ struct pp_assemblage *cxxPPassemblage::cxxPPassemblage2pp_assemblage() pp_assemblage_ptr->n_user = this->n_user; pp_assemblage_ptr->n_user_end = this->n_user_end; pp_assemblage_ptr->new_def = FALSE; - pp_assemblage_ptr->count_comps = this->ppAssemblageComps.size(); + pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size(); pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); pp_assemblage_ptr->pure_phases = cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps); pp_assemblage_ptr->next_elt = this->eltList.elt_list(); @@ -196,7 +196,7 @@ void cxxPPassemblage::mpi_pack(std::vector& ints, std::vector& doub { /* int n_user; */ ints.push_back(this->n_user); - ints.push_back(this->ppAssemblageComps.size()); + ints.push_back((int) this->ppAssemblageComps.size()); for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) { it->mpi_pack(ints, doubles); } diff --git a/Parser.cxx b/Parser.cxx index af9a95f1..30153bc1 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -196,12 +196,12 @@ CParser::LINE_TYPE CParser::get_logical_line() break; } if (c == '\\') { - pos = m_line_save.size(); + pos = (int) m_line_save.size(); m_line_save += c; while ((j = m_input_stream.get()) != std::char_traits::eof()) { c = (char) j; if (c == '\\') { - pos = m_line_save.size(); + pos = (int) m_line_save.size(); m_line_save += c; continue; } diff --git a/Reaction.cxx b/Reaction.cxx index 52151dc8..7b2e3c2a 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -81,7 +81,7 @@ struct irrev *cxxReaction::cxxReaction2irrev() irrev_ptr->n_user_end = this->n_user_end; irrev_ptr->list = this->reactantList.name_coef(); - irrev_ptr->count_list = this->reactantList.size(); + irrev_ptr->count_list = (int) this->reactantList.size(); if (this->elementList.size() > 0) { irrev_ptr->elts = this->elementList.elt_list(); } else { @@ -98,7 +98,7 @@ struct irrev *cxxReaction::cxxReaction2irrev() if (this->equalIncrements) { irrev_ptr->count_steps = -this->countSteps; } else { - irrev_ptr->count_steps = this->steps.size(); + irrev_ptr->count_steps = (int) this->steps.size(); } irrev_ptr->units = this->units; return(irrev_ptr); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f8834787..397534bb 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -59,7 +59,7 @@ struct s_s_assemblage *cxxSSassemblage::cxxSSassemblage2s_s_assemblage() s_s_assemblage_ptr->n_user = this->n_user; s_s_assemblage_ptr->n_user_end = this->n_user_end; s_s_assemblage_ptr->new_def = FALSE; - s_s_assemblage_ptr->count_s_s = this->ssAssemblageSSs.size(); + s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size(); s_s_assemblage_ptr->s_s = cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs); return(s_s_assemblage_ptr); } @@ -176,7 +176,7 @@ void cxxSSassemblage::mpi_pack(std::vector& ints, std::vector& doub { /* int n_user; */ ints.push_back(this->n_user); - ints.push_back(this->ssAssemblageSSs.size()); + ints.push_back((int) this->ssAssemblageSSs.size()); for (std::list::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) { it->mpi_pack(ints, doubles); } diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index c57f2192..80be9d60 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -111,7 +111,7 @@ struct s_s *cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::listcomps.size(); + s_s_ptr[j].count_comps = (int) it->comps.size(); s_s_ptr[j].comps = NULL; if (it->comps.size() > 0) { int i = 0; diff --git a/Solution.cxx b/Solution.cxx index 3b5f462f..42843358 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -177,17 +177,17 @@ struct solution *cxxSolution::cxxSolution2solution() // master_activity solution_ptr->master_activity = (struct master_activity *) free_check_null(solution_ptr->master_activity); solution_ptr->master_activity = this->master_activity.master_activity(); - solution_ptr->count_master_activity = this->master_activity.size() + 1; + solution_ptr->count_master_activity = (int) this->master_activity.size() + 1; // species_gamma solution_ptr->species_gamma = this->species_gamma.master_activity(); - solution_ptr->count_species_gamma = this->species_gamma.size(); + solution_ptr->count_species_gamma = (int) this->species_gamma.size(); // isotopes solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(); - solution_ptr->count_isotopes = this->isotopes.size(); + solution_ptr->count_isotopes = (int) this->isotopes.size(); return(solution_ptr); } @@ -892,10 +892,10 @@ void cxxSolution::mpi_send(int task_number) */ max_size = 0; //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_INT, MPI_COMM_WORLD, &member_size); - MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); max_size += member_size; //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_DOUBLE, MPI_COMM_WORLD, &member_size); - MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; buffer = PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); @@ -903,9 +903,9 @@ void cxxSolution::mpi_send(int task_number) * Send message to processor */ position = 0; - int i = ints.size(); + int i = (int) ints.size(); int *int_array = new int[i]; - int d = doubles.size(); + int d = (int) doubles.size(); double *double_array = new double[d]; for (int j = 0; j < i; j++) { int_array[j] = ints[j]; diff --git a/StorageBin.cxx b/StorageBin.cxx index 8d0e6a4e..3a60d7a3 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -672,17 +672,17 @@ void cxxStorageBin::mpi_send(int n, int task_number) // Pack data int max_size = 0; int member_size = 0; - MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); max_size += member_size; - MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; void *buffer = PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); // Convert to arrays - int i = ints.size(); + int i = (int) ints.size(); //int int_array[i]; - int d = doubles.size(); + int d = (int) doubles.size(); //double double_array[d]; /* for (int j = 0; j < i; j++) { diff --git a/Surface.cxx b/Surface.cxx index d4de9bd3..a2cd9246 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -108,14 +108,14 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->transport = FALSE; // Surface comps - surface_ptr->count_comps = this->surfaceComps.size(); + surface_ptr->count_comps = (int) this->surfaceComps.size(); surface_ptr->comps = (struct surface_comp *) free_check_null(surface_ptr->comps); surface_ptr->comps = cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); // Surface charge surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); if (surface_ptr->edl == TRUE) { - surface_ptr->count_charge = this->surfaceCharges.size(); + surface_ptr->count_charge = (int) this->surfaceCharges.size(); surface_ptr->charge = cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); } else { surface_ptr->count_charge = 0; @@ -375,11 +375,11 @@ void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) { /* int n_user; */ ints.push_back(this->n_user); - ints.push_back(this->surfaceComps.size()); + ints.push_back((int) this->surfaceComps.size()); for (std::list::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) { it->mpi_pack(ints, doubles); } - ints.push_back(this->surfaceCharges.size()); + ints.push_back((int) this->surfaceCharges.size()); for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) { it->mpi_pack(ints, doubles); } diff --git a/Temperature.cxx b/Temperature.cxx index a1db6e32..7d5b9e34 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -82,9 +82,9 @@ struct temperature *cxxTemperature::cxxTemperature2temperature() std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); } if (this->equalIncrements) { - temperature_ptr->count_t = -this->countTemps; + temperature_ptr->count_t = - (int) this->countTemps; } else { - temperature_ptr->count_t = this->temps.size(); + temperature_ptr->count_t = (int) this->temps.size(); } return(temperature_ptr); } diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index bcac3a88..c583a0cc 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -85,12 +85,12 @@ struct kinetics *cxxKinetics::cxxKinetics2kinetics() kinetics_ptr->totals = this->totals.elt_list(); // comps - kinetics_ptr->count_comps = this->kineticsComps.size(); + kinetics_ptr->count_comps = (int) this->kineticsComps.size(); kinetics_ptr->comps = (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); kinetics_ptr->comps = cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps); // steps - kinetics_ptr->count_steps = this->steps.size(); + kinetics_ptr->count_steps = (int) this->steps.size(); kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps); if (this->steps.size() > 0) { kinetics_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); @@ -349,11 +349,11 @@ void cxxKinetics::read_raw(CParser& parser) void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) { ints.push_back(this->n_user); - ints.push_back(this->kineticsComps.size()); + ints.push_back((int) this->kineticsComps.size()); for (std::list::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { it->mpi_pack(ints, doubles); } - ints.push_back(this->steps.size()); + ints.push_back((int) this->steps.size()); for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { doubles.push_back(*it); } diff --git a/cxxMix.cxx b/cxxMix.cxx index 80801b0b..4a1665c6 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -76,7 +76,7 @@ struct mix *cxxMix::cxxMix2mix() i++; } } - mix_ptr->count_comps = this->mixComps.size(); + mix_ptr->count_comps = (int) this->mixComps.size(); return(mix_ptr); } From cb46a1debffdba65d2fa8acdcb053af89e363a44 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 7 Jul 2006 22:13:43 +0000 Subject: [PATCH 0032/1077] Removed warning messages from compiler casts, bool conversion, others git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1009 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 4 ++-- PPassemblageComp.cxx | 2 +- SSassemblageSS.cxx | 2 +- Solution.h | 4 ++-- SolutionIsotopeList.h | 5 +++-- Surface.cxx | 8 ++++---- cxxMix.h | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/NameDouble.h b/NameDouble.h index cac0a527..f3994a01 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -1,14 +1,14 @@ #if !defined(NAMEDOUBLE_H_INCLUDED) #define NAMEDOUBLE_H_INCLUDED -#define EXTERNAL extern +//#define EXTERNAL extern #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector -#include "global.h" +//#include "global.h" #include "char_star.h" #include "Parser.h" class cxxNameDouble : public std::map diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index f040d37a..c9a2223a 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -301,7 +301,7 @@ void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *d this->moles = doubles[d++]; this->delta = doubles[d++]; this->initial_moles = doubles[d++]; - this->dissolve_only = (bool) ints[i++]; + this->dissolve_only = (ints[i++] != 0); *ii = i; *dd = d; } diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 80be9d60..4754283d 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -467,7 +467,7 @@ void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->a1 = doubles[d++]; this->ag0 = doubles[d++]; this->ag1 = doubles[d++]; - this->miscibility = (bool) ints[i++]; + this->miscibility = (ints[i++] != 0); this->xb1 = doubles[d++]; this->xb2 = doubles[d++]; *ii = i; diff --git a/Solution.h b/Solution.h index d2d72cbb..52c3983c 100644 --- a/Solution.h +++ b/Solution.h @@ -6,8 +6,8 @@ #include "NameDouble.h" #include "cxxMix.h" -#define EXTERNAL extern -#include "global.h" +//#define EXTERNAL extern +//#include "global.h" #include // assert #include // std::map #include // std::string diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 92301ab1..6867e14c 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -1,15 +1,16 @@ #if !defined(SOLUTIONISOTOPELIST_H_INCLUDED) #define SOLUTIONISOTOPELIST_H_INCLUDED -#define EXTERNAL extern +//#define EXTERNAL extern #include "SolutionIsotope.h" -#include "global.h" +//#include "global.h" #include // assert #include // std::string #include // std::list #include "char_star.h" #include "Parser.h" + class cxxSolutionIsotopeList : public std::list { diff --git a/Surface.cxx b/Surface.cxx index a2cd9246..a32e1dde 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -414,10 +414,10 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) sc.mpi_unpack(ints, &i, doubles, &d); this->surfaceCharges.push_back(sc); } - this->diffuse_layer = (bool) ints[i++]; - this->edl = (bool) ints[i++]; - this->only_counter_ions = (bool) ints[i++]; - this->donnan = (bool) ints[i++]; + this->diffuse_layer = (ints[i++] != 0); + this->edl = (ints[i++] != 0); + this->only_counter_ions = (ints[i++] != 0); + this->donnan = (ints[i++] != 0); this->thickness = doubles[d++]; *ii = i; *dd = d; diff --git a/cxxMix.h b/cxxMix.h index 4f28bf3f..6084c0e5 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -2,8 +2,8 @@ #define CXXMIX_H_INCLUDED #include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" +//#define EXTERNAL extern +//#include "global.h" #include // assert #include // std::map #include // std::string From 217bdd7708845412dc06c434b7b8558aae3c703d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 11 Jul 2006 03:45:46 +0000 Subject: [PATCH 0033/1077] Converted to VS2005. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1022 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index 23c11d27..dc6840b9 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -62,7 +62,8 @@ cxxGasPhase::~cxxGasPhase() struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp() { - struct gas_comp *gas_comp_ptr(NULL); + //struct gas_comp *gas_comp_ptr(NULL); + struct gas_comp *gas_comp_ptr = NULL; if (this->gasPhaseComps.size() > 0) { int i = 0; int n; From 89c12ec0e62953086505d9b0de19a18bdb0559c2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Oct 2006 16:03:36 +0000 Subject: [PATCH 0034/1077] using type and dl_type in Surface git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1315 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 5 +- Surface.cxx | 154 +++++++++++++++++++++++++++++++++++++--------- Surface.h | 11 ++-- SurfaceCharge.cxx | 93 +++++++++++++++++++++++++++- SurfaceCharge.h | 3 +- 5 files changed, 230 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 1bfbf5a1..ec483274 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ ifeq ($(CFG), RELEASE) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - CFLAGS_MODEL = -Wall -pedantic -O2 $(DEFINES) + CXXFLAGS_MODEL = -Wall -pedantic -O2 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} endif @@ -90,7 +90,7 @@ ifeq ($(CFG), DEBUG) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - CFLAGS_MODEL = -Wall -g $(DEFINES) + CXXFLAGS_MODEL = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} endif @@ -405,6 +405,7 @@ mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ ../phreeqc/phrqproto.h ../phreeqc/input.h model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ${CXX} ${CXXFLAGS_MODEL} -c -o $@ $< nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ diff --git a/Surface.cxx b/Surface.cxx index a32e1dde..50e768c1 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -25,10 +25,13 @@ cxxSurface::cxxSurface() // : cxxNumKeyword() { - diffuse_layer = false; - edl = false; + type = NO_EDL; + dl_type = NO_DL; + sites_units = SITES_ABSOLUTE; + //diffuse_layer = false; + //edl = false; only_counter_ions = false; - donnan = false; + //donnan = false; thickness = 0.0; } @@ -45,10 +48,13 @@ cxxNumKeyword() this->set_description(surface_ptr->description); n_user = surface_ptr->n_user; n_user_end = surface_ptr->n_user_end; - diffuse_layer = (surface_ptr->diffuse_layer == TRUE); - edl = (surface_ptr->edl == TRUE); + type = surface_ptr->type; + dl_type = surface_ptr->dl_type; + sites_units = surface_ptr->sites_units; + //diffuse_layer = (surface_ptr->diffuse_layer == TRUE); + //edl = (surface_ptr->edl == TRUE); only_counter_ions = (surface_ptr->only_counter_ions == TRUE); - donnan = (surface_ptr->donnan == TRUE); + //donnan = (surface_ptr->donnan == TRUE); thickness = surface_ptr->thickness; // Surface components for (i = 0; i < surface_ptr->count_comps; i++) { @@ -95,10 +101,13 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->n_user = this->n_user; surface_ptr->n_user_end = this->n_user_end; surface_ptr->new_def = FALSE; - surface_ptr->diffuse_layer = this->diffuse_layer; - surface_ptr->edl = this->edl; + surface_ptr->type = this->type; + surface_ptr->dl_type = this->dl_type; + surface_ptr->sites_units = this->sites_units; + //surface_ptr->diffuse_layer = this->diffuse_layer; + //surface_ptr->edl = this->edl; surface_ptr->only_counter_ions = this->only_counter_ions; - surface_ptr->donnan = this->donnan; + //surface_ptr->donnan = this->donnan; surface_ptr->thickness = this->thickness; surface_ptr->debye_units = 1.0; surface_ptr->solution_equilibria = FALSE; @@ -114,7 +123,8 @@ struct surface *cxxSurface::cxxSurface2surface() // Surface charge surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); - if (surface_ptr->edl == TRUE) { + //if (surface_ptr->edl == TRUE) { + if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) { surface_ptr->count_charge = (int) this->surfaceCharges.size(); surface_ptr->charge = cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); } else { @@ -139,16 +149,21 @@ void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << "diffuse_layer << "\"" << std::endl; + //s_oss << "diffuse_layer=\"" << this->diffuse_layer << "\"" << std::endl; + s_oss << "surface_type=\"" << this->type << "\"" << std::endl; s_oss << indent1; - s_oss << "edl=\"" << this->edl << "\"" << std::endl; + //s_oss << "edl=\"" << this->edl << "\"" << std::endl; + s_oss << "dl_type=\"" << this->dl_type << "\"" << std::endl; + + s_oss << indent1; + s_oss << "sites_units=\"" << this->sites_units << "\"" << std::endl; s_oss << indent1; s_oss << "only_counter_ions=\"" << this->only_counter_ions << "\"" << std::endl; - s_oss << indent1; - s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; + //s_oss << indent1; + //s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; s_oss << indent1; s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; @@ -186,16 +201,21 @@ void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << "SURFACE_RAW " << this->n_user << " " << this->description << std::endl; s_oss << indent1; - s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; + //s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; + s_oss << "-type " << this->type << std::endl; s_oss << indent1; - s_oss << "-edl " << this->edl << std::endl; + //s_oss << "-edl " << this->edl << std::endl; + s_oss << "-dl_type " << this->dl_type << std::endl; + + s_oss << indent1; + s_oss << "-sites_units " << this->sites_units << std::endl; s_oss << indent1; s_oss << "-only_counter_ions " << this->only_counter_ions << std::endl; - s_oss << indent1; - s_oss << "-donnan " << this->donnan << std::endl; + //s_oss << indent1; + //s_oss << "-donnan " << this->donnan << std::endl; s_oss << indent1; s_oss << "-thickness " << this->thickness << std::endl; @@ -221,6 +241,7 @@ void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const void cxxSurface::read_raw(CParser& parser) { static std::vector vopts; + int i = 0; if (vopts.empty()) { vopts.reserve(15); vopts.push_back("diffuse_layer"); // 0 @@ -230,6 +251,9 @@ void cxxSurface::read_raw(CParser& parser) vopts.push_back("thickness"); // 4 vopts.push_back("component"); // 5 vopts.push_back("charge_component"); // 6 + vopts.push_back("type "); // 7 + vopts.push_back("dl_type"); // 8 + vopts.push_back("sites_units"); // 9 } std::istream::pos_type ptr; @@ -242,11 +266,14 @@ void cxxSurface::read_raw(CParser& parser) this->read_number_description(parser); opt_save = CParser::OPT_ERROR; - bool diffuse_layer_defined(false); - bool edl_defined(false); + //bool diffuse_layer_defined(false); + //bool edl_defined(false); bool only_counter_ions_defined(false); - bool donnan_defined(false); + //bool donnan_defined(false); bool thickness_defined(false); + bool type_defined(false); + bool dl_type_defined(false); + bool sites_units_defined(false); for (;;) { @@ -271,6 +298,9 @@ void cxxSurface::read_raw(CParser& parser) break; case 0: // diffuse_layer + parser.incr_input_error(); + parser.error_msg("Diffuse layer is obsolete, use -type.", CParser::OT_CONTINUE); + /* if (!(parser.get_iss() >> this->diffuse_layer)) { this->diffuse_layer = false; @@ -278,10 +308,14 @@ void cxxSurface::read_raw(CParser& parser) parser.error_msg("Expected boolean value for diffuse_layer.", CParser::OT_CONTINUE); } diffuse_layer_defined = true; + */ useLastLine = false; break; case 1: // edl + parser.incr_input_error(); + parser.error_msg("-edl is obsolete, use -type.", CParser::OT_CONTINUE); + /* if (!(parser.get_iss() >> this->edl)) { this->edl = false; @@ -289,6 +323,7 @@ void cxxSurface::read_raw(CParser& parser) parser.error_msg("Expected boolean value for edl.", CParser::OT_CONTINUE); } edl_defined = true; + */ useLastLine = false; break; @@ -304,6 +339,9 @@ void cxxSurface::read_raw(CParser& parser) break; case 3: // donnan + parser.incr_input_error(); + parser.error_msg("-Donnan is obsolete, use -dl_type.", CParser::OT_CONTINUE); + /* if (!(parser.get_iss() >> this->donnan)) { this->donnan = false; @@ -311,6 +349,7 @@ void cxxSurface::read_raw(CParser& parser) parser.error_msg("Expected boolean value for donnan.", CParser::OT_CONTINUE); } donnan_defined = true; + */ useLastLine = false; break; @@ -342,11 +381,48 @@ void cxxSurface::read_raw(CParser& parser) } useLastLine = true; break; + case 7: // type + i = 0; + if (!(parser.get_iss() >> i)) + { + this->type = NO_EDL; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for type.", CParser::OT_CONTINUE); + } + this->type = (SURFACE_TYPE) i; + type_defined = true; + useLastLine = false; + break; + case 8: // dl_type + i = 0; + if (!(parser.get_iss() >> i)) + { + this->dl_type = NO_DL; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for dl_type.", CParser::OT_CONTINUE); + } + this->dl_type = (DIFFUSE_LAYER_TYPE) i; + dl_type_defined = true; + useLastLine = false; + break; + case 9: // type + i = 0; + if (!(parser.get_iss() >> i)) + { + this->sites_units = SITES_ABSOLUTE; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sites_units.", CParser::OT_CONTINUE); + } + this->sites_units = (SITES_UNITS) i; + sites_units_defined = true; + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } // members that must be defined + /* if (diffuse_layer_defined == false) { parser.incr_input_error(); parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); @@ -355,18 +431,33 @@ void cxxSurface::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } + */ if (only_counter_ions_defined == false) { parser.incr_input_error(); parser.error_msg("Only_counter_ions not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } + /* if (donnan_defined == false) { parser.incr_input_error(); parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } + */ if (thickness_defined == false) { parser.incr_input_error(); parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } + if (type_defined == false) { + parser.incr_input_error(); + parser.error_msg("Surface type not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (dl_type_defined == false) { + parser.incr_input_error(); + parser.error_msg("Dl_type not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (sites_units == false) { + parser.incr_input_error(); + parser.error_msg("Sites_units not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI /* ---------------------------------------------------------------------- */ @@ -383,10 +474,14 @@ void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) { it->mpi_pack(ints, doubles); } - ints.push_back((int) this->diffuse_layer); - ints.push_back((int) this->edl); + //ints.push_back((int) this->diffuse_layer); + //ints.push_back((int) this->edl); + ints.push_back((int) this->type); + ints.push_back((int) this->dl_type); + ints.push_back((int) this->sites_units); + ints.push_back((int) this->only_counter_ions); - ints.push_back((int) this->donnan); + //ints.push_back((int) this->donnan); doubles.push_back(this->thickness); } /* ---------------------------------------------------------------------- */ @@ -414,10 +509,13 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) sc.mpi_unpack(ints, &i, doubles, &d); this->surfaceCharges.push_back(sc); } - this->diffuse_layer = (ints[i++] != 0); - this->edl = (ints[i++] != 0); - this->only_counter_ions = (ints[i++] != 0); - this->donnan = (ints[i++] != 0); + //this->diffuse_layer = (bool) ints[i++]; + //this->edl = (bool) ints[i++]; + this->type = (SURFACE_TYPE) ints[i++]; + this->dl_type = (DIFFUSE_LAYER_TYPE) ints[i++]; + this->sites_units = (SITES_UNITS) ints[i++]; + this->only_counter_ions = (bool) ints[i++]; + //this->donnan = (bool) ints[i++]; this->thickness = doubles[d++]; *ii = i; *dd = d; diff --git a/Surface.h b/Surface.h index a96fd50b..43e2df42 100644 --- a/Surface.h +++ b/Surface.h @@ -22,6 +22,10 @@ public: cxxSurface(struct surface *); ~cxxSurface(); + //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; + //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; + //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; + struct surface *cxxSurface2surface(); struct surf_comp *cxxSurfaceComp2surf_comp(); @@ -44,17 +48,16 @@ public: protected: std::list surfaceComps; std::list surfaceCharges; - bool diffuse_layer; - bool edl; + enum SURFACE_TYPE type; + enum DIFFUSE_LAYER_TYPE dl_type; + enum SITES_UNITS sites_units; bool only_counter_ions; - bool donnan; double thickness; //double debye_units; //int transport; public: //static std::map& map; - }; #endif // !defined(SURFACE_H_INCLUDED) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 44d9e695..8f3ac53e 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -30,6 +30,10 @@ cxxSurfaceCharge::cxxSurfaceCharge() charge_balance = 0.0; mass_water = 0.0; la_psi = 0.0; + la_psi1 = 0.0; + la_psi2 = 0.0; + capacitance[0] = 1.0; + capacitance[1] = 5.0; diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; } @@ -46,6 +50,10 @@ diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) charge_balance = surf_charge_ptr->charge_balance; mass_water = surf_charge_ptr->mass_water; la_psi = surf_charge_ptr->la_psi; + la_psi1 = surf_charge_ptr->la_psi1; + la_psi2 = surf_charge_ptr->la_psi2; + capacitance[0] = surf_charge_ptr->capacitance[0]; + capacitance[1] = surf_charge_ptr->capacitance[1]; } cxxSurfaceCharge::~cxxSurfaceCharge() @@ -84,8 +92,12 @@ struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::li surf_charge_ptr[i].charge_balance = it->charge_balance; surf_charge_ptr[i].mass_water = it->mass_water; surf_charge_ptr[i].la_psi = it->la_psi; + surf_charge_ptr[i].la_psi1 = it->la_psi1; + surf_charge_ptr[i].la_psi2 = it->la_psi2; + surf_charge_ptr[i].capacitance[0] = it->capacitance[0]; + surf_charge_ptr[i].capacitance[1] = it->capacitance[1]; surf_charge_ptr[i].diffuse_layer_totals = it->diffuse_layer_totals.elt_list(); - surf_charge_ptr[i].psi_master = it->get_psi_master(); + //surf_charge_ptr[i].psi_master = it->get_psi_master(); surf_charge_ptr[i].count_g = 0; surf_charge_ptr[i].g = NULL; i++; @@ -111,6 +123,9 @@ void cxxSurfaceCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; s_oss << indent0 << "mass_water=\"" << this->mass_water << "\"" << std::endl; s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl; + s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl; + s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl; + s_oss << indent0 << "capacitance=\"" << this->capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl; // totals s_oss << indent0; @@ -137,6 +152,10 @@ void cxxSurfaceCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; s_oss << indent0 << "-mass_water " << this->mass_water << std::endl; s_oss << indent0 << "-la_psi " << this->la_psi << std::endl; + s_oss << indent0 << "-la_psi1 " << this->la_psi1 << std::endl; + s_oss << indent0 << "-la_psi2 " << this->la_psi2 << std::endl; + s_oss << indent0 << "-capacitance0 " << this->capacitance[0] << std::endl; + s_oss << indent0 << "-capacitance1 " << this->capacitance[1] << std::endl; // totals s_oss << indent0; @@ -159,6 +178,10 @@ void cxxSurfaceCharge::read_raw(CParser& parser) vopts.push_back("mass_water"); // 4 vopts.push_back("la_psi"); // 5 vopts.push_back("diffuse_layer_totals"); // 6 + vopts.push_back("la_psi1"); // 7 + vopts.push_back("la_psi2"); // 8 + vopts.push_back("capacitance0"); // 9 + vopts.push_back("capacitance1"); // 10 } std::istream::pos_type ptr; @@ -173,6 +196,10 @@ void cxxSurfaceCharge::read_raw(CParser& parser) bool charge_balance_defined(false); bool mass_water_defined(false); bool la_psi_defined(false); + bool la_psi1_defined(false); + bool la_psi2_defined(false); + bool capacitance0_defined(false); + bool capacitance1_defined(false); for (;;) { @@ -269,6 +296,46 @@ void cxxSurfaceCharge::read_raw(CParser& parser) opt_save = 6; break; + case 7: // la_psi1 + if (!(parser.get_iss() >> this->la_psi1)) + { + this->la_psi1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi1.", CParser::OT_CONTINUE); + } + la_psi1_defined = true; + break; + + case 8: // la_psi2 + if (!(parser.get_iss() >> this->la_psi2)) + { + this->la_psi2 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE); + } + la_psi_defined = true; + break; + + case 9: // capacitance0 + if (!(parser.get_iss() >> this->capacitance[0])) + { + this->capacitance[0] = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for capacitance0.", CParser::OT_CONTINUE); + } + capacitance0_defined = true; + break; + + case 10: // capacitance1 + if (!(parser.get_iss() >> this->capacitance[1])) + { + this->capacitance[1] = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for capacitance1.", CParser::OT_CONTINUE); + } + capacitance1_defined = true; + break; + } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -297,6 +364,22 @@ void cxxSurfaceCharge::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("La_psi not defined for SurfaceCharge input.", CParser::OT_CONTINUE); } + if (la_psi1_defined == false) { + parser.incr_input_error(); + parser.error_msg("La_psi1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); + } + if (la_psi2_defined == false) { + parser.incr_input_error(); + parser.error_msg("La_psi2 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); + } + if (capacitance0_defined == false) { + parser.incr_input_error(); + parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); + } + if (capacitance1_defined == false) { + parser.incr_input_error(); + parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI #include "Dictionary.h" @@ -310,6 +393,10 @@ void cxxSurfaceCharge::mpi_pack(std::vector& ints, std::vector& dou doubles.push_back(this->charge_balance); doubles.push_back(this->mass_water); doubles.push_back(this->la_psi); + doubles.push_back(this->la_psi1); + doubles.push_back(this->la_psi2); + doubles.push_back(this->capacitance[0]); + doubles.push_back(this->capacitance[1]); this->diffuse_layer_totals.mpi_pack(ints, doubles); } void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) @@ -323,6 +410,10 @@ void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->charge_balance = doubles[d++]; this->mass_water = doubles[d++]; this->la_psi = doubles[d++]; + this->la_psi1 = doubles[d++]; + this->la_psi2 = doubles[d++]; + this->capacitance[0] = doubles[d++]; + this->capacitance[1] = doubles[d++]; this->diffuse_layer_totals.mpi_unpack(ints, &i, doubles, &d); *ii = i; *dd = d; diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 38d22fdb..0a761b35 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -43,7 +43,8 @@ protected: double grams; double charge_balance; double mass_water; - double la_psi; + double la_psi, la_psi1, la_psi2; + double capacitance[2]; //std::map g; //char * psi_master_name; cxxNameDouble diffuse_layer_totals; From 119b032594f7c4b72b54799706bda23254785ad1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Oct 2006 18:46:30 +0000 Subject: [PATCH 0035/1077] Had not included formula_totals and formula_z in structure. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1316 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 4 +++- SurfaceComp.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++++ SurfaceComp.h | 2 ++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index d51f3a27..d7848d0f 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -54,9 +54,10 @@ totals(exch_comp_ptr->totals) rate_name = exch_comp_ptr->rate_name; formula_z = exch_comp_ptr->formula_z; } + cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vector &f_vector) // - // constructor for cxxExchComp from struct exch_comp + // constructor for cxxExchComp from mixing // { if (ec_vector.size() <= 0) return; @@ -201,6 +202,7 @@ void cxxExchComp::dump_xml(std::ostream& s_oss, unsigned int indent)const // Exch_Comp element and attributes s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << std::endl; s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index f5d8fed5..640d7c3e 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -25,6 +25,8 @@ cxxSurfaceComp::cxxSurfaceComp() // { formula = NULL; + formula_totals.type = cxxNameDouble::ND_ELT_MOLES; + formula_z = 0.0; moles = 0.0; totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; @@ -40,9 +42,11 @@ cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) // constructor for cxxSurfaceComp from struct surface_comp // : +formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { formula = surf_comp_ptr->formula; + formula_z = surf_comp_ptr->formula_z; moles = surf_comp_ptr->moles; la = surf_comp_ptr->la; charge_number = surf_comp_ptr->charge; @@ -95,6 +99,8 @@ struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list::iterator it = el.begin(); it != el.end(); ++it) { surf_comp_ptr[i].formula = it->formula; + surf_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); + surf_comp_ptr[i].formula_z = it->formula_z; surf_comp_ptr[i].moles = it->moles; surf_comp_ptr[i].master = it->get_master(); surf_comp_ptr[i].totals = it->totals.elt_list(); @@ -123,6 +129,7 @@ void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const // Surf_Comp element and attributes s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << std::endl; s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; @@ -135,6 +142,11 @@ void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const } s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); + // totals s_oss << indent0; s_oss << "formula << std::endl; + s_oss << indent0 << "-formula_z " << this->formula_z << std::endl; s_oss << indent0 << "-moles " << this->moles << std::endl; s_oss << indent0 << "-la " << this->la << std::endl; s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; @@ -167,6 +180,11 @@ void cxxSurfaceComp::dump_raw(std::ostream& s_oss, unsigned int indent)const } s_oss << indent0 << "-phase_proportion " << this->phase_proportion << std::endl; + // formula_totals + s_oss << indent0; + s_oss << "-formula_totals" << std::endl; + this->formula_totals.dump_raw(s_oss, indent + 1); + // totals s_oss << indent0; s_oss << "-totals" << std::endl; @@ -190,6 +208,8 @@ void cxxSurfaceComp::read_raw(CParser& parser) vopts.push_back("rate_name"); // 6 vopts.push_back("phase_proportion"); // 7 vopts.push_back("totals"); // 8 + vopts.push_back("formula_z"); // 9 + vopts.push_back("formula_totals"); // 10 } std::istream::pos_type ptr; @@ -203,6 +223,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) bool la_defined(false); bool charge_number_defined(false); bool charge_balance_defined(false); + bool formula_z_defined(false); for (;;) { @@ -317,6 +338,24 @@ void cxxSurfaceComp::read_raw(CParser& parser) opt_save = 8; break; + case 9: // formula_z + if (!(parser.get_iss() >> this->formula_z)) + { + this->formula_z = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for formula_z.", CParser::OT_CONTINUE); + } + formula_z_defined = true; + break; + + case 10: // formula_totals + if ( this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { + parser.incr_input_error(); + parser.error_msg("Expected element name and molality for SurfaceComp formula totals.", CParser::OT_CONTINUE); + } + opt_save = 10; + break; + } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -325,6 +364,10 @@ void cxxSurfaceComp::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Formula not defined for SurfaceComp input.", CParser::OT_CONTINUE); } + if (formula_z_defined == false) { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); + } if (moles_defined == false) { parser.incr_input_error(); parser.error_msg("Moles not defined for SurfaceComp input.", CParser::OT_CONTINUE); @@ -349,6 +392,8 @@ void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubl extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->formula)); + doubles.push_back(this->formula_z); + this->formula_totals.mpi_pack(ints, doubles); doubles.push_back(this->moles); this->totals.mpi_pack(ints, doubles); doubles.push_back(this->la); @@ -364,6 +409,8 @@ void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) int i = *ii; int d = *dd; this->formula = dictionary.int2char(ints[i++]); + this->formula_z = doubles[d++]; + this->formula_totals.mpi_unpack(ints, &i, doubles, &d); this->moles = doubles[d++]; this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; diff --git a/SurfaceComp.h b/SurfaceComp.h index 67b88e68..97cdd64d 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -41,6 +41,8 @@ public: protected: char * formula; + cxxNameDouble formula_totals; + double formula_z; double moles; cxxNameDouble totals; double la; From 7953591e5c11901d13105f1b5f8b44a810aa8d4c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Oct 2006 19:47:27 +0000 Subject: [PATCH 0036/1077] Working through changes to surface structure git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1318 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Surface.cxx | 4 ++-- SurfaceCharge.cxx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Surface.cxx b/Surface.cxx index 50e768c1..a8a3aed9 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -405,7 +405,7 @@ void cxxSurface::read_raw(CParser& parser) dl_type_defined = true; useLastLine = false; break; - case 9: // type + case 9: // sites_units i = 0; if (!(parser.get_iss() >> i)) { @@ -454,7 +454,7 @@ void cxxSurface::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Dl_type not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } - if (sites_units == false) { + if (sites_units_defined == false) { parser.incr_input_error(); parser.error_msg("Sites_units not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 8f3ac53e..9db0c7a9 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -313,7 +313,7 @@ void cxxSurfaceCharge::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE); } - la_psi_defined = true; + la_psi2_defined = true; break; case 9: // capacitance0 From e4ca1d77c505a48f20c499628c59b3df5ecda6b9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Oct 2006 21:14:22 +0000 Subject: [PATCH 0037/1077] Forgot to include force_equality in PPassemblageComp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1319 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblageComp.cxx | 23 +++++++++++++++++++++++ PPassemblageComp.h | 1 + 2 files changed, 24 insertions(+) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index c9a2223a..a25b0bde 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -29,6 +29,7 @@ cxxPPassemblageComp::cxxPPassemblageComp() moles = 0; delta = 0; initial_moles = 0; + force_equality = false; dissolve_only = false; } @@ -44,6 +45,7 @@ cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase *pure_phase_ptr) moles = pure_phase_ptr->moles; delta = pure_phase_ptr->delta; initial_moles = pure_phase_ptr->initial_moles; + force_equality = ( pure_phase_ptr->force_equality == TRUE); dissolve_only = ( pure_phase_ptr->dissolve_only == TRUE); } @@ -73,6 +75,7 @@ struct pure_phase *cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list pure_phase_ptr[i].moles = it->moles; pure_phase_ptr[i].delta = it->delta; pure_phase_ptr[i].initial_moles = it->initial_moles; + pure_phase_ptr[i].force_equality = (int) it->force_equality; pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; i++; } @@ -97,6 +100,7 @@ void cxxPPassemblageComp::dump_xml(std::ostream& s_oss, unsigned int indent)cons s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl; + s_oss << indent0 << "force_equality=\"" << this->force_equality << "\"" << std::endl; s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl; } @@ -119,6 +123,7 @@ void cxxPPassemblageComp::dump_raw(std::ostream& s_oss, unsigned int indent)cons s_oss << indent0 << "-moles " << this->moles << std::endl; s_oss << indent0 << "-delta " << this->delta << std::endl; s_oss << indent0 << "-initial_moles " << this->initial_moles << std::endl; + s_oss << indent0 << "-force_equality " << this->force_equality << std::endl; s_oss << indent0 << "-dissolve_only " << this->dissolve_only << std::endl; } @@ -136,6 +141,7 @@ void cxxPPassemblageComp::read_raw(CParser& parser) vopts.push_back("delta"); // 4 vopts.push_back("initial_moles"); // 5 vopts.push_back("dissolve_only"); // 6 + vopts.push_back("force_equality"); // 7 } std::istream::pos_type ptr; @@ -150,6 +156,7 @@ void cxxPPassemblageComp::read_raw(CParser& parser) bool delta_defined(false); bool initial_moles_defined(false); bool dissolve_only_defined(false); + bool force_equality_defined(false); for (;;) { @@ -246,6 +253,16 @@ void cxxPPassemblageComp::read_raw(CParser& parser) } dissolve_only_defined = true; break; + + case 7: // force_equality + if (!(parser.get_iss() >> this->force_equality)) + { + this->force_equality = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for force_equality.", CParser::OT_CONTINUE); + } + force_equality_defined = true; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -274,6 +291,10 @@ void cxxPPassemblageComp::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } + if (force_equality_defined == false) { + parser.incr_input_error(); + parser.error_msg("Force_equality not defined for PPassemblageComp input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI @@ -288,6 +309,7 @@ void cxxPPassemblageComp::mpi_pack(std::vector& ints, std::vector& doubles.push_back(this->moles); doubles.push_back(this->delta); doubles.push_back(this->initial_moles); + ints.push_back((int) this->force_equality); ints.push_back((int) this->dissolve_only); } void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) @@ -301,6 +323,7 @@ void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *d this->moles = doubles[d++]; this->delta = doubles[d++]; this->initial_moles = doubles[d++]; + this->force_equality = (ints[i++] != 0); this->dissolve_only = (ints[i++] != 0); *ii = i; *dd = d; diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 250045a7..d925c030 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -41,6 +41,7 @@ protected: double moles; double delta; double initial_moles; + bool force_equality; bool dissolve_only; public: From 812bb1adcc778e58b7efee90cd11c85f3716f90b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Oct 2006 20:04:59 +0000 Subject: [PATCH 0038/1077] Updated with Tony's MCD additions to Surface and SurfaceComp classes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1344 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Surface.cxx | 125 +++++++++++++++++++++++++++++++++++++++++++--- Surface.h | 6 ++- SurfaceCharge.cxx | 4 ++ SurfaceComp.cxx | 22 ++++++++ SurfaceComp.h | 2 +- 5 files changed, 149 insertions(+), 10 deletions(-) diff --git a/Surface.cxx b/Surface.cxx index a8a3aed9..18419a85 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -25,14 +25,18 @@ cxxSurface::cxxSurface() // : cxxNumKeyword() { - type = NO_EDL; - dl_type = NO_DL; - sites_units = SITES_ABSOLUTE; + type = NO_EDL; + dl_type = NO_DL; + sites_units = SITES_ABSOLUTE; //diffuse_layer = false; //edl = false; - only_counter_ions = false; + only_counter_ions = false; //donnan = false; - thickness = 0.0; + thickness = 0.0; + debye_lengths = 0.0; + DDL_viscosity = 0.0; + DDL_limit = 0.0; + transport = false; } cxxSurface::cxxSurface(struct surface *surface_ptr) @@ -56,6 +60,10 @@ cxxNumKeyword() only_counter_ions = (surface_ptr->only_counter_ions == TRUE); //donnan = (surface_ptr->donnan == TRUE); thickness = surface_ptr->thickness; + debye_lengths = surface_ptr->debye_lengths; + DDL_viscosity = surface_ptr->DDL_viscosity; + DDL_limit = surface_ptr->DDL_limit; + transport = (surface_ptr->transport == TRUE); // Surface components for (i = 0; i < surface_ptr->count_comps; i++) { cxxSurfaceComp ec(&(surface_ptr->comps[i])); @@ -109,12 +117,15 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->only_counter_ions = this->only_counter_ions; //surface_ptr->donnan = this->donnan; surface_ptr->thickness = this->thickness; - surface_ptr->debye_units = 1.0; + surface_ptr->debye_lengths = 1.0; surface_ptr->solution_equilibria = FALSE; surface_ptr->n_solution = -2; surface_ptr->related_phases = (int) this->get_related_phases(); surface_ptr->related_rate = (int) this->get_related_rate(); - surface_ptr->transport = FALSE; + surface_ptr->transport = this->transport; + surface_ptr->debye_lengths = this->debye_lengths; + surface_ptr->DDL_viscosity = this->DDL_viscosity; + surface_ptr->DDL_limit = this->DDL_limit; // Surface comps surface_ptr->count_comps = (int) this->surfaceComps.size(); @@ -168,6 +179,18 @@ void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; + s_oss << indent1; + s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << std::endl; + + s_oss << indent1; + s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << std::endl; + + s_oss << indent1; + s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << std::endl; + + s_oss << indent1; + s_oss << "transport=\"" << this->transport << "\"" << std::endl; + // surface component structures s_oss << indent1; s_oss << "thickness << std::endl; + s_oss << indent1; + s_oss << "-debye_lengths " << this->debye_lengths << std::endl; + + s_oss << indent1; + s_oss << "-DDL_viscosity " << this->DDL_viscosity << std::endl; + + s_oss << indent1; + s_oss << "-DDL_limit= " << this->DDL_limit << std::endl; + + s_oss << indent1; + s_oss << "-transport= " << this->transport << std::endl; + // surfaceComps structures for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { s_oss << indent1; @@ -254,6 +289,10 @@ void cxxSurface::read_raw(CParser& parser) vopts.push_back("type "); // 7 vopts.push_back("dl_type"); // 8 vopts.push_back("sites_units"); // 9 + vopts.push_back("debye_lengths"); // 10 + vopts.push_back("DDL_viscosity"); // 11 + vopts.push_back("DDL_limit"); // 12 + vopts.push_back("transport"); // 13 } std::istream::pos_type ptr; @@ -274,6 +313,10 @@ void cxxSurface::read_raw(CParser& parser) bool type_defined(false); bool dl_type_defined(false); bool sites_units_defined(false); + bool debye_lengths_defined(false); + bool DDL_viscosity_defined(false); + bool DDL_limit_defined(false); + bool transport_defined(false); for (;;) { @@ -417,6 +460,50 @@ void cxxSurface::read_raw(CParser& parser) sites_units_defined = true; useLastLine = false; break; + + case 10: // debye_lengths + if (!(parser.get_iss() >> this->debye_lengths)) + { + this->debye_lengths = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for debye_lengths.", CParser::OT_CONTINUE); + } + debye_lengths_defined = true; + useLastLine = false; + break; + + case 11: // DDL_viscosity + if (!(parser.get_iss() >> this->DDL_viscosity)) + { + this->DDL_viscosity = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for DDL_viscosity.", CParser::OT_CONTINUE); + } + DDL_viscosity_defined = true; + useLastLine = false; + break; + + case 12: // DDL_limit + if (!(parser.get_iss() >> this->DDL_limit)) + { + this->DDL_limit = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for DDL_limit.", CParser::OT_CONTINUE); + } + DDL_limit_defined = true; + useLastLine = false; + break; + + case 13: // transport + if (!(parser.get_iss() >> this->transport)) + { + this->transport = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for transport.", CParser::OT_CONTINUE); + } + transport_defined = true; + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -458,6 +545,22 @@ void cxxSurface::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Sites_units not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); } + if (debye_lengths_defined == false) { + parser.incr_input_error(); + parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (DDL_viscosity_defined == false) { + parser.incr_input_error(); + parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (DDL_limit_defined == false) { + parser.incr_input_error(); + parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (transport_defined == false) { + parser.incr_input_error(); + parser.error_msg("Transport not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI /* ---------------------------------------------------------------------- */ @@ -483,6 +586,10 @@ void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) ints.push_back((int) this->only_counter_ions); //ints.push_back((int) this->donnan); doubles.push_back(this->thickness); + doubles.push_back(this->debye_lengths); + doubles.push_back(this->DDL_viscosity); + doubles.push_back(this->DDL_limit); + ints.push_back((int) this->transport); } /* ---------------------------------------------------------------------- */ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) @@ -517,6 +624,10 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->only_counter_ions = (bool) ints[i++]; //this->donnan = (bool) ints[i++]; this->thickness = doubles[d++]; + this->debye_lengths = doubles[d++]; + this->DDL_viscosity = doubles[d++]; + this->DDL_limit = doubles[d++]; + this->transport = (bool) ints[i++]; *ii = i; *dd = d; } diff --git a/Surface.h b/Surface.h index 43e2df42..26a8362b 100644 --- a/Surface.h +++ b/Surface.h @@ -53,8 +53,10 @@ protected: enum SITES_UNITS sites_units; bool only_counter_ions; double thickness; - //double debye_units; - //int transport; + double debye_lengths; + double DDL_viscosity; + double DDL_limit; + bool transport; public: //static std::map& map; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 9db0c7a9..99c44d8e 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -96,6 +96,10 @@ struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::li surf_charge_ptr[i].la_psi2 = it->la_psi2; surf_charge_ptr[i].capacitance[0] = it->capacitance[0]; surf_charge_ptr[i].capacitance[1] = it->capacitance[1]; + surf_charge_ptr[i].sigma0 = 0; + surf_charge_ptr[i].sigma1 = 0; + surf_charge_ptr[i].sigma2 = 0; + surf_charge_ptr[i].sigmaddl = 0; surf_charge_ptr[i].diffuse_layer_totals = it->diffuse_layer_totals.elt_list(); //surf_charge_ptr[i].psi_master = it->get_psi_master(); surf_charge_ptr[i].count_g = 0; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 640d7c3e..99fcb9ac 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -35,6 +35,7 @@ cxxSurfaceComp::cxxSurfaceComp() phase_name = NULL; phase_proportion = 0.0; rate_name = NULL; + Dw = 0.0; } cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) @@ -54,6 +55,7 @@ totals(surf_comp_ptr->totals) phase_name = surf_comp_ptr->phase_name; phase_proportion = surf_comp_ptr->phase_proportion; rate_name = surf_comp_ptr->rate_name; + Dw = surf_comp_ptr->Dw; } cxxSurfaceComp::~cxxSurfaceComp() @@ -110,6 +112,7 @@ struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::listphase_name; surf_comp_ptr[i].phase_proportion = it->phase_proportion; surf_comp_ptr[i].rate_name = it->rate_name; + surf_comp_ptr[i].Dw = it->Dw; surf_comp_ptr[i].master = it->get_master(); i++; } @@ -141,6 +144,7 @@ void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; } s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << std::endl; // formula_totals s_oss << indent0; @@ -179,6 +183,7 @@ void cxxSurfaceComp::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; } s_oss << indent0 << "-phase_proportion " << this->phase_proportion << std::endl; + s_oss << indent0 << "-Dw " << this->Dw << std::endl; // formula_totals s_oss << indent0; @@ -210,6 +215,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) vopts.push_back("totals"); // 8 vopts.push_back("formula_z"); // 9 vopts.push_back("formula_totals"); // 10 + vopts.push_back("Dw"); // 11 } std::istream::pos_type ptr; @@ -224,6 +230,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) bool charge_number_defined(false); bool charge_balance_defined(false); bool formula_z_defined(false); + bool Dw_defined(false); for (;;) { @@ -356,6 +363,15 @@ void cxxSurfaceComp::read_raw(CParser& parser) opt_save = 10; break; + case 11: // Dw + if (!(parser.get_iss() >> this->Dw)) + { + this->Dw = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for Dw.", CParser::OT_CONTINUE); + } + Dw_defined = true; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -384,6 +400,10 @@ void cxxSurfaceComp::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Charge_balance not defined for SurfaceComp input.", CParser::OT_CONTINUE); } + if (Dw_defined == false) { + parser.incr_input_error(); + parser.error_msg("Dw not defined for SurfaceComp input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI #include "Dictionary.h" @@ -402,6 +422,7 @@ void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubl ints.push_back(dictionary.string2int(this->phase_name)); doubles.push_back(this->phase_proportion); ints.push_back(dictionary.string2int(this->rate_name)); + doubles.push_back(this->Dw); } void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { @@ -419,6 +440,7 @@ void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->phase_name = dictionary.int2char(ints[i++]); this->phase_proportion = doubles[d++]; this->rate_name = dictionary.int2char(ints[i++]); + this->Dw = doubles[d++]; *ii = i; *dd = d; } diff --git a/SurfaceComp.h b/SurfaceComp.h index 97cdd64d..9ccef087 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -51,7 +51,7 @@ protected: char *phase_name; double phase_proportion; char *rate_name; - + double Dw; public: }; From 52ab13ec09d6e0f4b4c1ab95be785415a573b2e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Oct 2006 22:11:23 +0000 Subject: [PATCH 0039/1077] Fixed some bugs in C++ classes. Ran test cases with test_classes enabled. Everything appeared to check correctly. Added new test cases to phreeqcpp/mytest. Added zero.sed to examples and mytest. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1376 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 2 +- Solution.cxx | 80 +++++++++++++++++++++++++++++-------------------- Surface.cxx | 10 +++---- SurfaceComp.cxx | 2 +- 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index ec483274..d3faef0f 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,7 @@ ifeq ($(CFG), RELEASE) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - CXXFLAGS_MODEL = -Wall -pedantic -O2 $(DEFINES) $(INCLUDES) + CXXFLAGS_MODEL = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} endif diff --git a/Solution.cxx b/Solution.cxx index 42843358..da9d0727 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1072,8 +1072,9 @@ void test_classes(void) - /* + int i; + /* std::map Solutions; cxxSolution soln(solution[0]); Solutions[solution[0]->n_user] = soln; @@ -1085,10 +1086,12 @@ void test_classes(void) cxxNumKeyword nk; x[solution[0]->n_user] = soln; */ - -#ifdef SKIP + std::ostringstream msg; + status_on = FALSE; + std::cout << std::endl << "TEST CLASSES" << std::endl; for (i=0; i < count_solution; i++) { if (solution[i]->new_def == TRUE) { + std::cout << "Solution new_def " << solution[i]->n_user << std::endl; cxxISolution sol(solution[i]); solution[i] = (struct solution *) solution_free(solution[i]); solution[i] = sol.cxxISolution2solution(); @@ -1096,6 +1099,7 @@ void test_classes(void) soln_ptr = solution[i]; soln_ptr = solution[i]; } else { + std::cout << "Solution " << solution[i]->n_user << std::endl; std::ostringstream oss; cxxSolution sol(solution[i]); solution[i] = (struct solution *) solution_free(solution[i]); @@ -1121,10 +1125,11 @@ void test_classes(void) } for (i=0; i < count_exchange; i++) { if (exchange[i].new_def != TRUE) { + std::cout << "Exchange " << exchange[i].n_user << std::endl; std::ostringstream oss; cxxExchange ex(&(exchange[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxExchange ex1; std::string keyInput = oss.str(); @@ -1147,10 +1152,11 @@ void test_classes(void) } for (i=0; i < count_surface; i++) { if (surface[i].new_def != TRUE) { + std::cout << "Surface " << surface[i].n_user << std::endl; std::ostringstream oss; cxxSurface ex(&(surface[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxSurface ex1; @@ -1176,10 +1182,11 @@ void test_classes(void) } for (i=0; i < count_pp_assemblage; i++) { if (pp_assemblage[i].new_def != TRUE) { + std::cout << "PPassemblage " << pp_assemblage[i].n_user << std::endl; std::ostringstream oss; cxxPPassemblage ex(&(pp_assemblage[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxPPassemblage ex1; @@ -1204,37 +1211,39 @@ void test_classes(void) } for (i=0; i < count_kinetics; i++) { - std::ostringstream oss; - cxxKinetics ex(&(kinetics[i])); - ex.dump_raw(oss, 0); - std::cerr << oss.str(); + std::cout << "Kinetics " << kinetics[i].n_user << std::endl; + std::ostringstream oss; + cxxKinetics ex(&(kinetics[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); + + + cxxKinetics ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); - cxxKinetics ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); + ex1.read_raw(cparser); - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - - ex1.read_raw(cparser); - - struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); - kinetics_free(&kinetics[i]); - kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); - kinetics_free(kinetics_ptr); - free_check_null(kinetics_ptr); + struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); + kinetics_free(&kinetics[i]); + kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); + kinetics_free(kinetics_ptr); + free_check_null(kinetics_ptr); } for (i=0; i < count_s_s_assemblage; i++) { if (s_s_assemblage[i].new_def != TRUE) { + std::cout << "Solid solution " << s_s_assemblage[i].n_user << std::endl; std::ostringstream oss; cxxSSassemblage ex(&(s_s_assemblage[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxSSassemblage ex1; @@ -1260,10 +1269,11 @@ void test_classes(void) } for (i=0; i < count_gas_phase; i++) { if (gas_phase[i].new_def != TRUE) { + std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; std::ostringstream oss; cxxGasPhase ex(&(gas_phase[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxGasPhase ex1; @@ -1288,10 +1298,11 @@ void test_classes(void) } for (i=0; i < count_irrev; i++) { + std::cout << "Reaction " << irrev[i].n_user << std::endl; std::ostringstream oss; cxxReaction ex(&(irrev[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxReaction ex1; @@ -1315,10 +1326,11 @@ void test_classes(void) } for (i=0; i < count_mix; i++) { + std::cout << "Mix " << mix[i].n_user << std::endl; std::ostringstream oss; cxxMix ex(&(mix[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxMix ex1; @@ -1342,10 +1354,11 @@ void test_classes(void) } for (i=0; i < count_temperature; i++) { + std::cout << "Temperature " << temperature[i].n_user << std::endl; std::ostringstream oss; cxxTemperature ex(&(temperature[i])); ex.dump_raw(oss, 0); - std::cerr << oss.str(); + //std::cerr << oss.str(); cxxTemperature ex1; @@ -1368,7 +1381,7 @@ void test_classes(void) free_check_null(temperature_ptr); } -#endif + /* { // get all c storage cxxStorageBin cstorage; @@ -1396,4 +1409,5 @@ void test_classes(void) // read it back } + */ } diff --git a/Surface.cxx b/Surface.cxx index 18419a85..dee0636b 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -250,10 +250,10 @@ void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << "-DDL_viscosity " << this->DDL_viscosity << std::endl; s_oss << indent1; - s_oss << "-DDL_limit= " << this->DDL_limit << std::endl; + s_oss << "-DDL_limit " << this->DDL_limit << std::endl; s_oss << indent1; - s_oss << "-transport= " << this->transport << std::endl; + s_oss << "-transport " << this->transport << std::endl; // surfaceComps structures for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { @@ -290,8 +290,8 @@ void cxxSurface::read_raw(CParser& parser) vopts.push_back("dl_type"); // 8 vopts.push_back("sites_units"); // 9 vopts.push_back("debye_lengths"); // 10 - vopts.push_back("DDL_viscosity"); // 11 - vopts.push_back("DDL_limit"); // 12 + vopts.push_back("ddl_viscosity"); // 11 + vopts.push_back("ddl_limit"); // 12 vopts.push_back("transport"); // 13 } @@ -335,7 +335,7 @@ void cxxSurface::read_raw(CParser& parser) case CParser::OPT_DEFAULT: case CParser::OPT_ERROR: opt = CParser::OPT_EOF; - parser.error_msg("Unknown input in SURF_COMP_RAW keyword.", CParser::OT_CONTINUE); + parser.error_msg("Unknown input in SURFACE keyword.", CParser::OT_CONTINUE); parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); useLastLine = false; break; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 99fcb9ac..f59650fc 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -215,7 +215,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) vopts.push_back("totals"); // 8 vopts.push_back("formula_z"); // 9 vopts.push_back("formula_totals"); // 10 - vopts.push_back("Dw"); // 11 + vopts.push_back("dw"); // 11 } std::istream::pos_type ptr; From f8c7968c722cabb75e53aa47dc7e5f66735b98b6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 26 Oct 2006 14:55:32 +0000 Subject: [PATCH 0040/1077] Fixed incorrect casts. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1388 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index da9d0727..12d2692a 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1093,7 +1093,8 @@ void test_classes(void) if (solution[i]->new_def == TRUE) { std::cout << "Solution new_def " << solution[i]->n_user << std::endl; cxxISolution sol(solution[i]); - solution[i] = (struct solution *) solution_free(solution[i]); + solution_free(solution[i]); + solution[i] = NULL; solution[i] = sol.cxxISolution2solution(); struct solution *soln_ptr; soln_ptr = solution[i]; @@ -1102,7 +1103,8 @@ void test_classes(void) std::cout << "Solution " << solution[i]->n_user << std::endl; std::ostringstream oss; cxxSolution sol(solution[i]); - solution[i] = (struct solution *) solution_free(solution[i]); + solution_free(solution[i]); + solution[i] = NULL; sol.dump_raw(oss, 0); //std::fstream myfile("t"); From 423006926489eacb1d79c0f4776dab7764b256de Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Nov 2006 16:00:47 +0000 Subject: [PATCH 0041/1077] fixed warn again. fixed error when no doubles sent in message. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1422 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 2 +- StorageBin.cxx | 11 ++++++++--- Surface.cxx | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index cfdb3c45..92328c34 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -247,7 +247,7 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->description = " "; - this->pitzer_exchange_gammas = (bool) ints[i++]; + this->pitzer_exchange_gammas = (ints[i++] == TRUE); int count = ints[i++]; this->exchComps.clear(); for (int n = 0; n < count; n++) { diff --git a/StorageBin.cxx b/StorageBin.cxx index 3a60d7a3..36c5d794 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -672,7 +672,7 @@ void cxxStorageBin::mpi_send(int n, int task_number) // Pack data int max_size = 0; int member_size = 0; - MPI_Pack_size((int) ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) ints.size() + 10, MPI_INT, MPI_COMM_WORLD, &member_size); max_size += member_size; MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; @@ -704,7 +704,10 @@ void cxxStorageBin::mpi_send(int n, int task_number) MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); //MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + if (d > 0) { + MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + } + std::cerr << "Packed 4" << std::endl; MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); @@ -741,7 +744,9 @@ void cxxStorageBin::mpi_recv(int task_number) int count_doubles; MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); double *doubles = new double[count_doubles]; - MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + if (count_doubles > 0) { + MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + } buffer = free_check_null(buffer); #ifdef SKIP for (int j = 0; j < count_ints; j++) { diff --git a/Surface.cxx b/Surface.cxx index dee0636b..4cc8fab7 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -621,13 +621,13 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->type = (SURFACE_TYPE) ints[i++]; this->dl_type = (DIFFUSE_LAYER_TYPE) ints[i++]; this->sites_units = (SITES_UNITS) ints[i++]; - this->only_counter_ions = (bool) ints[i++]; + this->only_counter_ions = (ints[i++] == TRUE); //this->donnan = (bool) ints[i++]; this->thickness = doubles[d++]; this->debye_lengths = doubles[d++]; this->DDL_viscosity = doubles[d++]; this->DDL_limit = doubles[d++]; - this->transport = (bool) ints[i++]; + this->transport = (ints[i++] == TRUE); *ii = i; *dd = d; } From eb5b95110d5731b4cd011ed42e175ca6f8e2df96 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Nov 2006 20:03:05 +0000 Subject: [PATCH 0042/1077] Stray debug print removed from StorageBin. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1426 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/StorageBin.cxx b/StorageBin.cxx index 36c5d794..d8d9f3b0 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -707,7 +707,6 @@ void cxxStorageBin::mpi_send(int n, int task_number) if (d > 0) { MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); } - std::cerr << "Packed 4" << std::endl; MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); From 888140c4a58402518bc2d4d57db57887e6fb3332 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Jan 2007 00:03:03 +0000 Subject: [PATCH 0043/1077] Updated with phreeqc files. Main difference is the logic for rebuilding a model. Should run faster now, but has slight differences in example files. Imported changes from ph2orch. Plan to make phreeqcpp a subdirectory of ph2orch/src. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1601 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 92 +++++++++++++++++++++++++++++++++++++++++++++-- ISolution.h | 4 ++- ISolutionComp.cxx | 64 +++++++++++++++++++++++++++------ ISolutionComp.h | 32 +++++++++++++---- NameDouble.cxx | 12 +++++++ NameDouble.h | 1 + Parser.cxx | 65 +++++++++++++++++++++++++++------ Parser.h | 19 ++++++++-- ReadClass.cxx | 22 ++++++------ Solution.cxx | 2 +- Utils.h | 2 +- 11 files changed, 268 insertions(+), 47 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index d3298ba1..e9954d0e 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -6,13 +6,16 @@ #endif #include "ISolution.h" +#include "ISolutionComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort +#include ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -38,7 +41,8 @@ cxxISolution::cxxISolution(struct solution *solution_ptr) // totals for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { cxxISolutionComp c(&(solution_ptr->totals[i])); - comps.insert(c); + //comps.insert(solution_ptr->totals[i].description, c); + comps[solution_ptr->totals[i].description] = c; } default_pe = solution_ptr->default_pe; // pe_data @@ -68,6 +72,88 @@ struct solution *cxxISolution::cxxISolution2solution() soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(this->comps); return(soln_ptr); } +void cxxISolution::ConvertUnits() + // + // Converts from input units to moles per kilogram water + // +{ + double sum_solutes = 0; + // foreach conc + std::map::iterator iter = this->comps.begin(); + for(; iter != this->comps.end(); ++iter) + { + struct master *master_ptr = master_bsearch (iter->first); + if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; + if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; + if (iter->second.get_input_conc() <= 0.0) continue; +/* +* Convert liters to kg solution +*/ + double moles = iter->second.get_input_conc(); + if (this->units.find("/l") != std::string::npos ) + { + moles /= this->density; + } +/* +* Convert to moles +*/ + //set gfw for element + iter->second.set_gfw(); + // convert to moles + if (iter->second.get_units().find("g/") != std::string::npos) + { + if (iter->second.get_gfw() != 0) + { + moles /= iter->second.get_gfw(); + } + else + { + std::ostringstream oss; + oss << "Could not find gfw, " << iter->second.get_description(); + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + } +/* +* Convert milli or micro +*/ + char c = iter->second.get_units().c_str()[0]; + if (c == 'm') + { + moles *= 1e-3; + } + else if (c == 'u') + { + moles *= 1e-6; + } + iter->second.set_moles(moles); +/* +* Sum grams of solute, convert from moles necessary +*/ + sum_solutes += moles * (iter->second.get_gfw()); + } +/* + * Convert /kgs to /kgw + */ + double mass_water; + if ((this->units.find("kgs") != std::string::npos) || + (this->units.find("/l") != std::string::npos)) + { + mass_water = 1.0 - 1e-3 * sum_solutes; + for(; iter != this->comps.end(); ++iter) + { + iter->second.set_moles(iter->second.get_moles() / mass_water); + } + } +/* + * Scale by mass of water in solution + */ + mass_water = this->mass_water; + for(; iter != this->comps.end(); ++iter) + { + iter->second.set_moles(iter->second.get_moles() * mass_water); + } +} #ifdef SKIP cxxISolution& cxxISolution::read(CParser& parser) { @@ -124,8 +210,8 @@ cxxISolution& cxxISolution::read(CParser& parser) break; case CParser::OPTION_ERROR: opt = CParser::OPTION_EOF; - parser.error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + CParser::error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); + CParser::error_msg(parser.line().c_str(), CParser::OT_CONTINUE); break; case 0: // temp diff --git a/ISolution.h b/ISolution.h index 91a05d78..1ded2adc 100644 --- a/ISolution.h +++ b/ISolution.h @@ -39,11 +39,13 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void ConvertUnits(); + protected: friend class cxxISolutionComp; // for this->pe access double density; std::string units; - std::set comps; + std::map comps; struct pe_data *pes; int default_pe; diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 0035ba56..09886e09 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -10,6 +10,7 @@ #include "global.h" #include "phrqproto.h" #include "phqalloc.h" +#include "output.h" cxxISolutionComp::cxxISolutionComp(void) : description(NULL) @@ -71,7 +72,7 @@ struct conc *cxxISolutionComp::concarray(std::map &totals) +struct conc *cxxISolutionComp::cxxISolutionComp2conc(const std::map &totals) // for ISolutions // takes a std::vector cxxISolutionComp structures // returns list of conc structures @@ -80,16 +81,16 @@ struct conc *cxxISolutionComp::cxxISolutionComp2conc(const std::set ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = it->description; - c[i].moles = it->moles; - c[i].input_conc = it->input_conc; - c[i].units = it->units; - c[i].equation_name = it->equation_name; - c[i].phase_si = it->phase_si; - c[i].n_pe = it->n_pe; - c[i].as = it->as; - c[i].gfw = it->gfw; + for (std::map::const_iterator it = totals.begin(); it != totals.end(); ++it) { + c[i].description = it->second.description; + c[i].moles = it->second.moles; + c[i].input_conc = it->second.input_conc; + c[i].units = it->second.units; + c[i].equation_name = it->second.equation_name; + c[i].phase_si = it->second.phase_si; + c[i].n_pe = it->second.n_pe; + c[i].as = it->second.as; + c[i].gfw = it->second.gfw; //c[i].skip = 0; c[i].phase = NULL; i++; @@ -98,6 +99,47 @@ struct conc *cxxISolutionComp::cxxISolutionComp2conc(const std::set gfw > 0.0) return; +// calculate gfw from as or from master species gfw + if (this->as != NULL) + { + /* use given chemical formula to calculate gfw */ + double gfw; + if (compute_gfw (this->as, &gfw) == ERROR) + { + std::ostringstream oss; + oss << "Could not compute gfw, " << this->as; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + if (this->description == "Alkalinity" && this->as == "CaCO3") + { + gfw /= 2.; + } + this->gfw = gfw; + return; + } + /* use gfw of master species */ + std::string str(this->description); + struct master *master_ptr = master_bsearch (str.c_str()); + if (master_ptr != NULL) + { + /* use gfw for element redox state */ + this->gfw = master_ptr->gfw; + return; + } + std::ostringstream oss; + oss << "Could not find gfw, " << this->description; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; +} + + #ifdef SKIP cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser& parser, cxxISolution& solution) { diff --git a/ISolutionComp.h b/ISolutionComp.h index 420f2118..512a3421 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -3,6 +3,10 @@ //#include "Parser.h" #include "Utils.h" +#define EXTERNAL extern +#include "global.h" +#include "phqalloc.h" +#include "phrqproto.h" #include #include // std::map @@ -26,24 +30,38 @@ public: void dump_xml(std::ostream& os, unsigned int indent = 0)const; - double get_input_conc()const {return this->input_conc;} - void set_input_conc(double input_conc) {this->input_conc = input_conc;} - - std::string get_equation_name()const {return this->equation_name;} - void set_equation_name(char * equation_name) {this->equation_name = equation_name;} - std::string get_description()const {return this->description;} void set_description(char * description) {this->description = description;} + double get_moles()const {return this->moles;} + void set_moles(double moles) {this->moles = moles;} + + double get_input_conc()const {return this->input_conc;} + void set_input_conc(double input_conc) {this->input_conc = input_conc;} + std::string get_units()const {return this->units;} void set_units(char * units) {this->units = units;} + std::string get_equation_name()const {return this->equation_name;} + void set_equation_name(char * equation_name) {this->equation_name = equation_name;} + + double get_phase_si()const {return this->phase_si;} + void set_phase_si(int phase_si) {this->phase_si = phase_si;} + int get_n_pe()const {return this->n_pe;} void set_n_pe(int n_pe) {this->n_pe = n_pe;} + char *get_as()const {return this->as;} + void set_as(char *as) {this->as = as;} + + //double get_gfw()const {return this->gfw;} + double get_gfw()const {return this->gfw;}; + void set_gfw(double gfw) {this->gfw = gfw;} + void set_gfw(); + bool operator<(const cxxISolutionComp& conc)const { return ::strcmp(this->description, conc.description) < 0; } - static struct conc * cxxISolutionComp2conc(const std::set &t ); + static struct conc * cxxISolutionComp2conc(const std::map &t ); private: char * description; diff --git a/NameDouble.cxx b/NameDouble.cxx index cf477416..5561713d 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -290,6 +290,18 @@ void cxxNameDouble::add(const cxxNameDouble &old, double factor) } } +void cxxNameDouble::add(char * key, double total) +// +// add to total for a specified element +// +{ + cxxNameDouble::iterator current = (*this).find(key); + if (current != (*this).end()) { + (*this)[key] = current->second + total; + } else { + (*this)[key] = total; + } +} #ifdef USE_MPI #include "Dictionary.h" void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { diff --git a/NameDouble.h b/NameDouble.h index f3994a01..7623c2f5 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -45,6 +45,7 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); void add(const cxxNameDouble &old, double factor); + void add(char * key, double total); void insert(char *str, double d) { (*this)[str] = d; diff --git a/Parser.cxx b/Parser.cxx index 30153bc1..b71bc152 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -7,6 +7,7 @@ #include "Parser.h" #include "Utils.h" +#include "output.h" #include // std::transform #include // std::map #include // assert @@ -24,6 +25,8 @@ CParser::CParser(std::istream& input) { m_line_save.reserve(80); m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; } CParser::CParser(std::istream& input, std::ostream& output) @@ -32,6 +35,8 @@ CParser::CParser(std::istream& input, std::ostream& output) { m_line_save.reserve(80); m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; } CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) @@ -40,6 +45,8 @@ CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) { m_line_save.reserve(80); m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; } CParser::~CParser() @@ -58,15 +65,50 @@ CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, m_line_iss.seekg(0, std::ios_base::beg); m_line_iss.clear(); - - if (true) // pr.echo_input == TRUE - { - if ((print && i != LT_EOF) || i == LT_KEYWORD) - { - get_output() << "\t" << m_line_save << "\n"; - } - } - + // output for stream + switch (this->echo_stream) + { + case EO_NONE: + break; + case EO_ALL: + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; + case EO_KEWORDS: + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; + } + // output for file + switch (this->echo_file) + { + case EO_NONE: + break; + case EO_ALL: + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; + case EO_KEWORDS: + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; + } } while (i == LT_EMPTY && allow_empty == false); // Check eof @@ -507,7 +549,7 @@ int CParser::get_option(const std::vector& opt_list, std::string::i // // Read line // - LINE_TYPE lt = check_line("get_option", false, true, true, false); + LINE_TYPE lt = check_line("get_option", false, true, true, true); if (lt == LT_EOF) { j = OPT_EOF; @@ -598,7 +640,7 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: // // Read line // - LINE_TYPE lt = check_line("get_option", false, true, true, false); + LINE_TYPE lt = check_line("get_option", false, true, true, true); if (lt == LT_EOF) { j = OPT_EOF; @@ -678,6 +720,7 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) { + ::error_msg(err_str, (int)ot); m_error_stream << "ERROR: " << err_str << "\n"; m_error_stream.flush(); diff --git a/Parser.h b/Parser.h index b28ccce0..5c2719d0 100644 --- a/Parser.h +++ b/Parser.h @@ -1,6 +1,7 @@ #if !defined(PARSER_H_INCLUDED) #define PARSER_H_INCLUDED +extern int input_error; #include // std::string #include // std::map #include // std::vector @@ -64,12 +65,19 @@ public: OT_CONTINUE = 0, OT_STOP = 1 }; + + enum ECHO_OPTION { + EO_NONE = 0, + EO_ALL = 1, + EO_KEWORDS = 2 + }; - enum STATUS_TYPE { + enum STATUS_TYPE { PARSER_ERROR = 0, PARSER_OK = 1 }; + /** Function gets a new line and checks for empty, eof, and keywords. @@ -123,7 +131,7 @@ public: std::string& line() {return m_line;} std::istringstream& get_iss() {return m_line_iss;} - int incr_input_error() {return ++m_input_error;} + int incr_input_error() {++::input_error; return ++m_input_error;} std::ostream& get_output() {return m_output_stream;} int get_input_error() {return m_input_error;} @@ -186,7 +194,12 @@ public: int error_msg(const std::ostringstream& err_str, ONERROR_TYPE stop) {return error_msg(err_str.str().c_str(), stop);} int error_msg(const char *err_str, ONERROR_TYPE stop); int warning_msg(const char *err_str); + + void set_echo_file(ECHO_OPTION opt) {echo_file = opt;} + ECHO_OPTION get_echo_file() {return this->echo_file;}; + void set_echo_stream(ECHO_OPTION opt) {echo_stream = opt;} + ECHO_OPTION get_echo_stream() {return this->echo_stream;}; STATUS_TYPE parse_couple(std::string& token); @@ -206,6 +219,8 @@ private: std::string m_line_save; std::istringstream m_line_iss; LINE_TYPE m_line_type; + ECHO_OPTION echo_stream; + ECHO_OPTION echo_file; }; #endif // PARSER_H_INCLUDED diff --git a/ReadClass.cxx b/ReadClass.cxx index 97dbb881..822939ea 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -17,6 +17,8 @@ #include "phqalloc.h" #include "output.h" #include "phrqproto.h" +#include + extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); @@ -50,7 +52,7 @@ int read_solution_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("solution_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -119,7 +121,7 @@ int read_exchange_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -187,7 +189,7 @@ int read_surface_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("surface_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("surface_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -255,7 +257,7 @@ int read_equilibrium_phases_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -323,7 +325,7 @@ int read_kinetics_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -391,7 +393,7 @@ int read_solid_solutions_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -459,7 +461,7 @@ int read_gas_phase_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("gas_phase_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -527,7 +529,7 @@ int read_reaction_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("reaction_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -594,7 +596,7 @@ int read_mix_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("mix_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); @@ -661,7 +663,7 @@ int read_temperature_raw (void) * Read additonal lines */ for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,TRUE); + return_value = check_line("temperature_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ if (return_value == EOF || return_value == KEYWORD ) break; keywordLines.append(line); diff --git a/Solution.cxx b/Solution.cxx index 12d2692a..cb1e65c7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -464,7 +464,7 @@ void cxxSolution::read_raw(CParser& parser) opt = CParser::OPT_EOF; parser.error_msg("Unknown input in SOLUTION_RAW keyword.", CParser::OT_CONTINUE); parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + continue; case 0: // totals if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { diff --git a/Utils.h b/Utils.h index 148ca967..23f25776 100644 --- a/Utils.h +++ b/Utils.h @@ -29,7 +29,7 @@ namespace Utilities { void squeeze_white(std::string& s_l); - void error_msg(const std::string&, const int stopflag); + //void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) template From 3320ef3c938d59eb30f8f9bf6229dafd5994b087 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Jan 2007 16:57:42 +0000 Subject: [PATCH 0044/1077] removed error increment in get_option. Logic allows a missing option in component reads, which bubble up to keyword reads. Turned off echo for initial_condition read of restart file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1604 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser.cxx b/Parser.cxx index b71bc152..3309bfb0 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -688,7 +688,7 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: } //error_msg("Unknown option.", OT_CONTINUE); //error_msg(m_line_save.c_str(), OT_CONTINUE); - incr_input_error(); + //incr_input_error(); j = OPT_ERROR; next_pos = pos_ptr; } From 2dc33fb7aebf676fcbae9e83b3b4fe8a7816cdc3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Jan 2007 21:45:56 +0000 Subject: [PATCH 0045/1077] Working on echoing for CParser git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1605 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 4 +- Parser.h | 2 +- ReadClass.cxx | 191 ++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 173 insertions(+), 24 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index 3309bfb0..4d37eab7 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -78,7 +78,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, get_output() << msg; } break; - case EO_KEWORDS: + case EO_KEYWORDS: if (i == LT_KEYWORD) { std::ostringstream msg; @@ -100,7 +100,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); } break; - case EO_KEWORDS: + case EO_KEYWORDS: if (i == LT_KEYWORD) { std::ostringstream msg; diff --git a/Parser.h b/Parser.h index 5c2719d0..e8cf3658 100644 --- a/Parser.h +++ b/Parser.h @@ -69,7 +69,7 @@ public: enum ECHO_OPTION { EO_NONE = 0, EO_ALL = 1, - EO_KEWORDS = 2 + EO_KEYWORDS = 2 }; enum STATUS_TYPE { diff --git a/ReadClass.cxx b/ReadClass.cxx index 822939ea..9b96967d 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -20,6 +20,7 @@ #include +extern int reading_database (void); extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); @@ -51,6 +52,8 @@ int read_solution_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("solution_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -58,12 +61,20 @@ int read_solution_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -76,20 +87,23 @@ int read_solution_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) { solution_free(solution[n]); + solution[n] = soln_ptr; } else { n=count_solution++; if (count_solution >= max_solution) { space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); } + solution[n] = soln_ptr; + solution_sort (); } - solution[n] = soln_ptr; - + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -120,6 +134,8 @@ int read_exchange_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -127,12 +143,20 @@ int read_exchange_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -144,20 +168,25 @@ int read_exchange_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) { exchange_free(&exchange[n]); + exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); } else { n=count_exchange++; if (count_exchange >= max_exchange) { space ((void **) ((void *) &(exchange)), count_exchange, &max_exchange, sizeof (struct exchange *) ); } + exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); + exchange_sort (); } - exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); exchange_free(exchange_ptr); free_check_null(exchange_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -188,6 +217,8 @@ int read_surface_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("surface_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -195,12 +226,20 @@ int read_surface_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -212,20 +251,25 @@ int read_surface_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (surface_bsearch(surface_ptr->n_user, &n) != NULL) { surface_free(&surface[n]); + surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); } else { n=count_surface++; if (count_surface >= max_surface) { space ((void **) ((void *) &(surface)), count_surface, &max_surface, sizeof (struct surface *) ); } + surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); + surface_sort (); } - surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); surface_free(surface_ptr); free_check_null(surface_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -256,6 +300,8 @@ int read_equilibrium_phases_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -263,12 +309,20 @@ int read_equilibrium_phases_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -280,20 +334,25 @@ int read_equilibrium_phases_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) { pp_assemblage_free(&pp_assemblage[n]); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); } else { n=count_pp_assemblage++; if (count_pp_assemblage >= max_pp_assemblage) { space ((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, &max_pp_assemblage, sizeof (struct pp_assemblage *) ); } + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); + pp_assemblage_sort (); } - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); pp_assemblage_free(pp_assemblage_ptr); free_check_null(pp_assemblage_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -324,6 +383,8 @@ int read_kinetics_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -331,12 +392,20 @@ int read_kinetics_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -348,20 +417,25 @@ int read_kinetics_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) { kinetics_free(&kinetics[n]); + kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); } else { n=count_kinetics++; if (count_kinetics >= max_kinetics) { space ((void **) ((void *) &(kinetics)), count_kinetics, &max_kinetics, sizeof (struct kinetics *) ); } + kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); + kinetics_sort (); } - kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); kinetics_free(kinetics_ptr); free_check_null(kinetics_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -392,6 +466,8 @@ int read_solid_solutions_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -399,12 +475,20 @@ int read_solid_solutions_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -416,20 +500,25 @@ int read_solid_solutions_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) { s_s_assemblage_free(&s_s_assemblage[n]); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); } else { n=count_s_s_assemblage++; if (count_s_s_assemblage >= max_s_s_assemblage) { space ((void **) ((void *) &(s_s_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, sizeof (struct s_s_assemblage *) ); } + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); + s_s_assemblage_sort (); } - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); s_s_assemblage_free(s_s_assemblage_ptr); free_check_null(s_s_assemblage_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -460,6 +549,8 @@ int read_gas_phase_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("gas_phase_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -467,12 +558,20 @@ int read_gas_phase_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -484,20 +583,25 @@ int read_gas_phase_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) { gas_phase_free(&gas_phase[n]); + gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); } else { n=count_gas_phase++; if (count_gas_phase >= max_gas_phase) { space ((void **) ((void *) &(gas_phase)), count_gas_phase, &max_gas_phase, sizeof (struct gas_phase *) ); } + gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); + gas_phase_sort (); } - gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); gas_phase_free(gas_phase_ptr); free_check_null(gas_phase_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -528,6 +632,8 @@ int read_reaction_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("reaction_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -535,12 +641,20 @@ int read_reaction_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -552,19 +666,24 @@ int read_reaction_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) { irrev_free(&irrev[n]); + irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); } else { n=count_irrev++; irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev)); if (irrev == NULL) malloc_error(); + irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); + irrev_sort (); } - irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); irrev_free(irrev_ptr); free_check_null(irrev_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -595,6 +714,8 @@ int read_mix_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("mix_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -602,12 +723,20 @@ int read_mix_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -619,19 +748,24 @@ int read_mix_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (mix_bsearch(mix_ptr->n_user, &n) != NULL) { mix_free(&mix[n]); + mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); } else { n=count_mix++; mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix)); if (mix == NULL) malloc_error(); + mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); + mix_sort (); } - mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); mix_free(mix_ptr); free_check_null(mix_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } /* ---------------------------------------------------------------------- */ @@ -662,6 +796,8 @@ int read_temperature_raw (void) /* * Read additonal lines */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; for (;;) { return_value = check_line("temperature_raw",TRUE,TRUE,TRUE,FALSE); /* empty, eof, keyword, print */ @@ -669,12 +805,20 @@ int read_temperature_raw (void) keywordLines.append(line); keywordLines.append("\n"); } + pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); std::ostringstream oss_out; std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } else if (reading_database ()) + { + parser.set_echo_file(CParser::EO_KEYWORDS); + } //For testing, need to read line to get started std::vector vopts; std::istream::pos_type next_char; @@ -686,18 +830,23 @@ int read_temperature_raw (void) int n; /* - * This is not quite right, may not produce sort order + * This is not quite right, may not produce sort order, forced sort */ if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) { temperature_free(&temperature[n]); + temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); } else { n=count_temperature++; temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature)); if (temperature == NULL) malloc_error(); + temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); + temperature_sort (); } - temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); temperature_free(temperature_ptr); free_check_null(temperature_ptr); + + // Need to output the next keyword + output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); return(return_value); } From 07f03ea2e5e0c567d9cc6321481e05c0ea8d3693 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Jan 2007 23:19:56 +0000 Subject: [PATCH 0046/1077] Fixed echo in parser for ReadClass.cxx. Works with testcase "raw". git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1607 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 17 +++++++++++++++++ Parser.h | 3 ++- ReadClass.cxx | 50 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index 4d37eab7..57db6cb8 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -86,6 +86,14 @@ CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, get_output() << msg; } break; + case EO_NOKEYWORDS: + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; } // output for file switch (this->echo_file) @@ -108,6 +116,15 @@ CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); } break; + + case EO_NOKEYWORDS: + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; } } while (i == LT_EMPTY && allow_empty == false); diff --git a/Parser.h b/Parser.h index e8cf3658..026948e7 100644 --- a/Parser.h +++ b/Parser.h @@ -69,7 +69,8 @@ public: enum ECHO_OPTION { EO_NONE = 0, EO_ALL = 1, - EO_KEYWORDS = 2 + EO_KEYWORDS = 2, + EO_NOKEYWORDS = 3, }; enum STATUS_TYPE { diff --git a/ReadClass.cxx b/ReadClass.cxx index 9b96967d..82a81274 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -68,12 +68,13 @@ int read_solution_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -150,12 +151,13 @@ int read_exchange_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -233,12 +235,13 @@ int read_surface_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -316,12 +319,13 @@ int read_equilibrium_phases_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -399,12 +403,13 @@ int read_kinetics_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -482,12 +487,13 @@ int read_solid_solutions_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -565,12 +571,13 @@ int read_gas_phase_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -648,12 +655,13 @@ int read_reaction_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -730,12 +738,13 @@ int read_mix_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; @@ -812,12 +821,13 @@ int read_temperature_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); + assert (!reading_database ()); if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); - } else if (reading_database ()) + } else { - parser.set_echo_file(CParser::EO_KEYWORDS); + parser.set_echo_file(CParser::EO_NOKEYWORDS); } //For testing, need to read line to get started std::vector vopts; From 4f7eec29d632dd7c4e419744193f961f18ac2209 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Jan 2007 23:46:29 +0000 Subject: [PATCH 0047/1077] gcc did not like comma at end of enumeration ci raw and raw.out, added to Makefile git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1608 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser.h b/Parser.h index 026948e7..335d552c 100644 --- a/Parser.h +++ b/Parser.h @@ -70,7 +70,7 @@ public: EO_NONE = 0, EO_ALL = 1, EO_KEYWORDS = 2, - EO_NOKEYWORDS = 3, + EO_NOKEYWORDS = 3 }; enum STATUS_TYPE { From bd852de57c1a397936b885f210455a72ff4f6cc0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 20 Jan 2007 01:22:45 +0000 Subject: [PATCH 0048/1077] removed extraneous cxxDictionary:: from int2char method git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1645 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dictionary.h b/Dictionary.h index 584feebd..98c0914e 100644 --- a/Dictionary.h +++ b/Dictionary.h @@ -32,7 +32,7 @@ public: std::string *int2string(int i); - char *cxxDictionary::int2char(int i); + char *int2char(int i); protected: std::map stringkey; From 93a7759e1b79d89f3010da96a2f98db82822e827 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Jan 2007 01:05:44 +0000 Subject: [PATCH 0049/1077] Beginning to revise cpp classes. Have worked on mixing solutions. Roughed in mixing Exchange.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1722 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 2 +- Exchange.h | 14 ++-- NameDouble.cxx | 68 +++++++++++++--- NameDouble.h | 4 +- Solution.cxx | 172 ++++++++++++++++++++++++++++++++++------ Solution.h | 22 ++--- SolutionIsotopeList.cxx | 93 +++++++++++----------- StorageBin.cxx | 4 +- StorageBin.h | 14 +++- 9 files changed, 286 insertions(+), 107 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index d7848d0f..f6373344 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -102,7 +102,7 @@ cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vectorla += it_ec->la*intensive; this->charge_balance += it_ec->charge_balance*extensive; this->phase_proportion += it_ec->phase_proportion*intensive; - this->totals.add(it_ec->totals, extensive); + this->totals.add_extensive(it_ec->totals, extensive); it_ec++; it_f++; } diff --git a/Exchange.h b/Exchange.h index ac7c1a8c..22d2f0fa 100644 --- a/Exchange.h +++ b/Exchange.h @@ -1,17 +1,15 @@ #if !defined(EXCHANGE_H_INCLUDED) #define EXCHANGE_H_INCLUDED -#include "NumKeyword.h" #define EXTERNAL extern #include "global.h" #include // assert #include // std::map #include // std::string -#include // std::list -#include // std::vector +#include // std::list -#include "char_star.h" #include "ExchComp.h" +#include "cxxMix.h" class cxxExchange : public cxxNumKeyword { @@ -19,14 +17,13 @@ class cxxExchange : public cxxNumKeyword public: cxxExchange(); cxxExchange(struct exchange *); + cxxExchange(const std::map &exchange_map, cxxMix &mx); ~cxxExchange(); struct exchange *cxxExchange2exchange(); struct exch_comp *cxxExchComp2exch_comp(); - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); @@ -50,6 +47,11 @@ public: void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif +private: + void zero(); + void add(const cxxExchange &ex, double intensive, double extensive); + // not written + void dump_xml(std::ostream& os, unsigned int indent = 0)const; protected: std::list exchComps; diff --git a/NameDouble.cxx b/NameDouble.cxx index 5561713d..e63b47a9 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -275,21 +275,63 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_ return CParser::PARSER_OK; } -void cxxNameDouble::add(const cxxNameDouble &old, double factor) - // - // constructor for cxxNameDouble from list of elt_list - // +void cxxNameDouble::add_extensive(const cxxNameDouble &addee, double factor) +// +// Sums two name doubles, this + factor*nd2 +// { - for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) { - (*this)[it->first] = current->second + it->second * factor; - } else { - (*this)[it->first] = it->second * factor; - } - } - + if (factor == 0) return; + assert (factor > 0.0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = current->second + it->second * factor; + } else { + (*this)[it->first] = it->second * factor; + } + } } +void cxxNameDouble::add_intensive(const cxxNameDouble &addee, double f1, double f2) +// +// Sums two name doubles, this*f1 + f2*nd2 +// +{ + assert(f1 > 0 && f2 > 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = f1*current->second + f2*it->second; + } else { + (*this)[it->first] = f2 * it->second; + } + } +} +void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, double f2) +// +// Sums two name doubles, this*f1 + f2*nd2, assuming log values +// +{ + assert (f1 > 0 && f2 > 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + double a1 = pow(10., current->second); + double a2 = pow(10., it->second); + (*this)[it->first] = log10(f1*a1 + f2*a2); + } else { + //double a2 = pow(10. it->second); + //(*this)[it->first] = log10(f2 * a2); + (*this)[it->first] = it->second + log10(f2); + } + } +} + void cxxNameDouble::add(char * key, double total) // // add to total for a specified element diff --git a/NameDouble.h b/NameDouble.h index 7623c2f5..73e74584 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -44,7 +44,9 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); - void add(const cxxNameDouble &old, double factor); + void add_extensive(const cxxNameDouble &old, double factor); + void add_intensive(const cxxNameDouble &addee, double fthis, double f2); + void add_log_activities(const cxxNameDouble &addee, double fthis, double f2); void add(char * key, double total); void insert(char *str, double d) { diff --git a/Solution.cxx b/Solution.cxx index cb1e65c7..b697ae36 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -27,20 +27,21 @@ cxxSolution::cxxSolution() // : cxxNumKeyword() { - tc = 25.0; - ph = 7.0; - pe = 4.0; - mu = 1e-7; - ah2o = 1.0; - total_h = 111.1; - total_o = 55.55; - cb = 0.0; - mass_water = 1.0; - total_alkalinity = 0.0; - totals.type = cxxNameDouble::ND_ELT_MOLES; - master_activity.type = cxxNameDouble::ND_SPECIES_LA; - species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + this->tc = 25.0; + this->ph = 7.0; + this->pe = 4.0; + this->mu = 1e-7; + this->ah2o = 1.0; + this->total_h = 111.1; + this->total_o = 55.55; + this->cb = 0.0; + this->mass_water = 1.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } +/* cxxSolution::cxxSolution(double zero) // // empty cxxSolution constructor @@ -62,6 +63,7 @@ cxxSolution::cxxSolution(double zero) master_activity.type = cxxNameDouble::ND_SPECIES_LA; species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } +*/ cxxSolution::cxxSolution(struct solution *solution_ptr) // // constructor for cxxSolution from struct solution @@ -75,18 +77,18 @@ isotopes(solution_ptr) { this->set_description(solution_ptr->description); - n_user = solution_ptr->n_user; - n_user_end = solution_ptr->n_user_end; - tc = solution_ptr->tc; - ph = solution_ptr->ph; - pe = solution_ptr->solution_pe; - mu = solution_ptr->mu; - ah2o = solution_ptr->ah2o; - total_h = solution_ptr->total_h; - total_o = solution_ptr->total_o; - cb = solution_ptr->cb; - mass_water = solution_ptr->mass_water; - total_alkalinity = solution_ptr->total_alkalinity; + this->n_user = solution_ptr->n_user; + this->n_user_end = solution_ptr->n_user_end; + this->tc = solution_ptr->tc; + this->ph = solution_ptr->ph; + this->pe = solution_ptr->solution_pe; + this->mu = solution_ptr->mu; + this->ah2o = solution_ptr->ah2o; + this->total_h = solution_ptr->total_h; + this->total_o = solution_ptr->total_o; + this->cb = solution_ptr->cb; + this->mass_water = solution_ptr->mass_water; + this->total_alkalinity = solution_ptr->total_alkalinity; // Totals filled in constructor, just save description and moles @@ -101,6 +103,83 @@ isotopes(solution_ptr) // Species_gamma in constructor } +#ifdef SKIP +cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix) + // + // constructor for cxxSolution from struct solution + //cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) + +{ +/* +* mixes solutions based on cxxMix structure, returns new solution +* return solution must be freed by calling method +*/ + double intensive, extensive; +/* +* Zero out global solution data +*/ + this->zero(); +/* +* Determine sum of mixing fractions +*/ + extensive = 0.0; + + std::map *mixcomps = mix.comps(); + + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) { + extensive += it->second; + } +/* +* Add solutions +*/ + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); + if (cxxsoln_ptr1 == NULL) + { + sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + return; + } + intensive = it->second/extensive; + double ext = it->second; + this->add(*cxxsoln_ptr1, intensive, it->second); + } +} +#endif + +cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix) +// +// constructor for cxxSolution from mixture of solutions +// + +{ + +// +// Zero out solution data +// + this->zero(); +// +// Mix solutions +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); + if (cxxsoln_ptr1 == NULL) + { + sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + return; + } + this->add(*cxxsoln_ptr1, it->second); + } +} + #ifdef SKIP cxxSolution::cxxSolution(const cxxSolution &old, double intensive, double extensive) // @@ -669,6 +748,23 @@ void cxxSolution::read_raw(CParser& parser) return; } +void cxxSolution::zero() +{ + this->tc = 0.0; + this->ph = 0.0; + this->pe = 0.0; + this->mu = 0.0; + this->ah2o = 0.0; + this->total_h = 0.0; + this->total_o = 0.0; + this->cb = 0.0; + this->mass_water = 0.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; +} +#ifdef SKIP void cxxSolution::add(const cxxSolution &old, double intensive, double extensive) // // Add existing solution to "this" solution @@ -722,7 +818,31 @@ void cxxSolution::add(const cxxSolution &old, double intensive, double extensive cxxNameDouble species_gamma; */ } - +#endif +void cxxSolution::add(const cxxSolution &addee, double extensive) + // + // Add existing solution to "this" solution + // +{ + double ext1 = this->mass_water; + double ext2 = addee.mass_water * extensive; + double f1 = ext1/(ext1 + ext2); + double f2 = ext2/(ext1 + ext2); + this->tc = f1*this->tc + f2*addee.tc; + this->ph = f1*this->ph + f2*addee.ph; + this->pe = f1*this->pe + f2*addee.pe; + this->mu = f1*this->mu + f2*addee.mu; + this->ah2o = f1*this->mu + f2*addee.ah2o; + this->total_h += addee.total_h * extensive; + this->total_o += addee.total_o * extensive; + this->cb += addee.cb * extensive; + this->mass_water += addee.mass_water * extensive; + this->total_alkalinity += addee.total_alkalinity * extensive; + this->totals.add_extensive(addee.totals, extensive); + this->master_activity.add_log_activities(addee.master_activity, f1, f2); + this->species_gamma.add_intensive(addee.species_gamma, f1, f2); + this->isotopes.add(addee.isotopes, f2, extensive); +} double cxxSolution::get_total(char *string)const { cxxNameDouble::const_iterator it = this->totals.find(string); diff --git a/Solution.h b/Solution.h index 52c3983c..23f01edd 100644 --- a/Solution.h +++ b/Solution.h @@ -11,7 +11,7 @@ #include // assert #include // std::map #include // std::string -#include // std::list + #include // std::vector #include "char_star.h" @@ -21,12 +21,11 @@ class cxxSolution : public cxxNumKeyword public: cxxSolution(); - cxxSolution(double zero); + //cxxSolution(double zero); cxxSolution(struct solution *); cxxSolution(const std::map &solution_map, cxxMix &mx); - cxxSolution(const cxxSolution &old, double intensive, double extensive); - - //cxxSolution(const cxxSolution&); + //cxxSolution(const cxxSolution &old, double intensive, double extensive); + //cxxSolution(const cxxSolution&); ~cxxSolution(); //static cxxSolution& read(CParser& parser); @@ -77,13 +76,10 @@ public: struct solution *cxxSolution2solution(); - 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 add(const cxxSolution &sol, double intensive, double extensive); #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); @@ -91,6 +87,14 @@ public: void mpi_send(int task_number); void mpi_recv(int task_number); #endif + +private: + void zero(); + //void add(const cxxSolution &sol, double intensive, double extensive); + void add(const cxxSolution &addee, double extensive); + // not checked + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + protected: double tc; double ph; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 88a0d135..0bc81085 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -32,54 +32,55 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) } void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) { - - for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { - - //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); - found = true; - break; - } - } - if (!found) { - cxxSolutionIsotope iso; - iso.total = itold->total * extensive; - iso.ratio = itold->ratio * intensive; - iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; - iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; - this->push_back(iso); - } - } + for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { + //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) + { + //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) + { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) + { + cxxSolutionIsotope iso; + iso.total = itold->total * extensive; + iso.ratio = itold->ratio * intensive; + iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; + iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; + this->push_back(iso); + } + } } struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() { - struct isotope *iso; - if (this->size() <= 0) { - return NULL; - } else { - iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); - if (iso == NULL) malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); - i++; - } - } - return(iso); + struct isotope *iso; + if (this->size() <= 0) { + return NULL; + } else { + iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + if (iso == NULL) malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return(iso); } diff --git a/StorageBin.cxx b/StorageBin.cxx index d8d9f3b0..6eeb6da7 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -495,7 +495,7 @@ void cxxStorageBin::remove(int n) // Surface this->Surfaces.erase(n); } - +#ifdef SKIP cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) { @@ -536,7 +536,7 @@ cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) } return(cxxsoln_ptr); } - +#endif struct system *cxxStorageBin::cxxStorageBin2system(int n) // // make a system from storagebin diff --git a/StorageBin.h b/StorageBin.h index 3b19c292..aa8806e0 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -42,8 +42,8 @@ public: } return (NULL); } - void setSolution(int n_user, cxxSolution *entity) { - Solutions[n_user] = *entity; + void setSolution(int n_user, cxxSolution &entity) { + Solutions[n_user] = entity; } void removeSolution(int n_user) { Solutions.erase(n_user); @@ -137,9 +137,17 @@ public: struct system *cxxStorageBin2system(int i); - cxxSolution *mix_cxxSolutions(cxxMix &mixmap); + //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix &mixmap); + const std::map& getSolutions()const {return this->Solutions;}; + const std::map& getExchangers()const {return this->Exchangers;}; + const std::map& getGasPhases()const {return this->GasPhases;}; + const std::map& getKinetics()const {return this->Kinetics;}; + const std::map& getPPassemblages()const {return this->PPassemblages;}; + const std::map& getSSassemblages()const {return this->SSassemblages;}; + const std::map& getSurfaces()const {return this->Surfaces;}; + #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); From 2b442eef3006739d8bcee7d0e1d4992403c1b41e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Jan 2007 01:34:18 +0000 Subject: [PATCH 0050/1077] git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1723 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 2 +- Exchange.h | 14 ++-- NameDouble.cxx | 68 +++------------- NameDouble.h | 4 +- Solution.cxx | 172 ++++++---------------------------------- Solution.h | 22 +++-- SolutionIsotopeList.cxx | 93 +++++++++++----------- StorageBin.cxx | 4 +- StorageBin.h | 14 +--- 9 files changed, 107 insertions(+), 286 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index f6373344..d7848d0f 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -102,7 +102,7 @@ cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vectorla += it_ec->la*intensive; this->charge_balance += it_ec->charge_balance*extensive; this->phase_proportion += it_ec->phase_proportion*intensive; - this->totals.add_extensive(it_ec->totals, extensive); + this->totals.add(it_ec->totals, extensive); it_ec++; it_f++; } diff --git a/Exchange.h b/Exchange.h index 22d2f0fa..ac7c1a8c 100644 --- a/Exchange.h +++ b/Exchange.h @@ -1,15 +1,17 @@ #if !defined(EXCHANGE_H_INCLUDED) #define EXCHANGE_H_INCLUDED +#include "NumKeyword.h" #define EXTERNAL extern #include "global.h" #include // assert #include // std::map #include // std::string -#include // std::list +#include // std::list +#include // std::vector +#include "char_star.h" #include "ExchComp.h" -#include "cxxMix.h" class cxxExchange : public cxxNumKeyword { @@ -17,13 +19,14 @@ class cxxExchange : public cxxNumKeyword public: cxxExchange(); cxxExchange(struct exchange *); - cxxExchange(const std::map &exchange_map, cxxMix &mx); ~cxxExchange(); struct exchange *cxxExchange2exchange(); struct exch_comp *cxxExchComp2exch_comp(); + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); @@ -47,11 +50,6 @@ public: void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -private: - void zero(); - void add(const cxxExchange &ex, double intensive, double extensive); - // not written - void dump_xml(std::ostream& os, unsigned int indent = 0)const; protected: std::list exchComps; diff --git a/NameDouble.cxx b/NameDouble.cxx index e63b47a9..5561713d 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -275,63 +275,21 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_ return CParser::PARSER_OK; } -void cxxNameDouble::add_extensive(const cxxNameDouble &addee, double factor) -// -// Sums two name doubles, this + factor*nd2 -// +void cxxNameDouble::add(const cxxNameDouble &old, double factor) + // + // constructor for cxxNameDouble from list of elt_list + // { - if (factor == 0) return; - assert (factor > 0.0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - (*this)[it->first] = current->second + it->second * factor; - } else { - (*this)[it->first] = it->second * factor; - } - } -} -void cxxNameDouble::add_intensive(const cxxNameDouble &addee, double f1, double f2) -// -// Sums two name doubles, this*f1 + f2*nd2 -// -{ - assert(f1 > 0 && f2 > 0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - (*this)[it->first] = f1*current->second + f2*it->second; - } else { - (*this)[it->first] = f2 * it->second; - } - } -} -void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, double f2) -// -// Sums two name doubles, this*f1 + f2*nd2, assuming log values -// -{ - assert (f1 > 0 && f2 > 0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - double a1 = pow(10., current->second); - double a2 = pow(10., it->second); - (*this)[it->first] = log10(f1*a1 + f2*a2); - } else { - //double a2 = pow(10. it->second); - //(*this)[it->first] = log10(f2 * a2); - (*this)[it->first] = it->second + log10(f2); - } - } -} + for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) { + (*this)[it->first] = current->second + it->second * factor; + } else { + (*this)[it->first] = it->second * factor; + } + } +} void cxxNameDouble::add(char * key, double total) // // add to total for a specified element diff --git a/NameDouble.h b/NameDouble.h index 73e74584..7623c2f5 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -44,9 +44,7 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); - void add_extensive(const cxxNameDouble &old, double factor); - void add_intensive(const cxxNameDouble &addee, double fthis, double f2); - void add_log_activities(const cxxNameDouble &addee, double fthis, double f2); + void add(const cxxNameDouble &old, double factor); void add(char * key, double total); void insert(char *str, double d) { diff --git a/Solution.cxx b/Solution.cxx index b697ae36..cb1e65c7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -27,21 +27,20 @@ cxxSolution::cxxSolution() // : cxxNumKeyword() { - this->tc = 25.0; - this->ph = 7.0; - this->pe = 4.0; - this->mu = 1e-7; - this->ah2o = 1.0; - this->total_h = 111.1; - this->total_o = 55.55; - this->cb = 0.0; - this->mass_water = 1.0; - this->total_alkalinity = 0.0; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + tc = 25.0; + ph = 7.0; + pe = 4.0; + mu = 1e-7; + ah2o = 1.0; + total_h = 111.1; + total_o = 55.55; + cb = 0.0; + mass_water = 1.0; + total_alkalinity = 0.0; + totals.type = cxxNameDouble::ND_ELT_MOLES; + master_activity.type = cxxNameDouble::ND_SPECIES_LA; + species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } -/* cxxSolution::cxxSolution(double zero) // // empty cxxSolution constructor @@ -63,7 +62,6 @@ cxxSolution::cxxSolution(double zero) master_activity.type = cxxNameDouble::ND_SPECIES_LA; species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } -*/ cxxSolution::cxxSolution(struct solution *solution_ptr) // // constructor for cxxSolution from struct solution @@ -77,18 +75,18 @@ isotopes(solution_ptr) { this->set_description(solution_ptr->description); - this->n_user = solution_ptr->n_user; - this->n_user_end = solution_ptr->n_user_end; - this->tc = solution_ptr->tc; - this->ph = solution_ptr->ph; - this->pe = solution_ptr->solution_pe; - this->mu = solution_ptr->mu; - this->ah2o = solution_ptr->ah2o; - this->total_h = solution_ptr->total_h; - this->total_o = solution_ptr->total_o; - this->cb = solution_ptr->cb; - this->mass_water = solution_ptr->mass_water; - this->total_alkalinity = solution_ptr->total_alkalinity; + n_user = solution_ptr->n_user; + n_user_end = solution_ptr->n_user_end; + tc = solution_ptr->tc; + ph = solution_ptr->ph; + pe = solution_ptr->solution_pe; + mu = solution_ptr->mu; + ah2o = solution_ptr->ah2o; + total_h = solution_ptr->total_h; + total_o = solution_ptr->total_o; + cb = solution_ptr->cb; + mass_water = solution_ptr->mass_water; + total_alkalinity = solution_ptr->total_alkalinity; // Totals filled in constructor, just save description and moles @@ -103,83 +101,6 @@ isotopes(solution_ptr) // Species_gamma in constructor } -#ifdef SKIP -cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix) - // - // constructor for cxxSolution from struct solution - //cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) - -{ -/* -* mixes solutions based on cxxMix structure, returns new solution -* return solution must be freed by calling method -*/ - double intensive, extensive; -/* -* Zero out global solution data -*/ - this->zero(); -/* -* Determine sum of mixing fractions -*/ - extensive = 0.0; - - std::map *mixcomps = mix.comps(); - - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) { - extensive += it->second; - } -/* -* Add solutions -*/ - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); - if (cxxsoln_ptr1 == NULL) - { - sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); - error_msg(error_string, CONTINUE); - input_error++; - return; - } - intensive = it->second/extensive; - double ext = it->second; - this->add(*cxxsoln_ptr1, intensive, it->second); - } -} -#endif - -cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix) -// -// constructor for cxxSolution from mixture of solutions -// - -{ - -// -// Zero out solution data -// - this->zero(); -// -// Mix solutions -// - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); - if (cxxsoln_ptr1 == NULL) - { - sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); - error_msg(error_string, CONTINUE); - input_error++; - return; - } - this->add(*cxxsoln_ptr1, it->second); - } -} - #ifdef SKIP cxxSolution::cxxSolution(const cxxSolution &old, double intensive, double extensive) // @@ -748,23 +669,6 @@ void cxxSolution::read_raw(CParser& parser) return; } -void cxxSolution::zero() -{ - this->tc = 0.0; - this->ph = 0.0; - this->pe = 0.0; - this->mu = 0.0; - this->ah2o = 0.0; - this->total_h = 0.0; - this->total_o = 0.0; - this->cb = 0.0; - this->mass_water = 0.0; - this->total_alkalinity = 0.0; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; -} -#ifdef SKIP void cxxSolution::add(const cxxSolution &old, double intensive, double extensive) // // Add existing solution to "this" solution @@ -818,31 +722,7 @@ void cxxSolution::add(const cxxSolution &old, double intensive, double extensive cxxNameDouble species_gamma; */ } -#endif -void cxxSolution::add(const cxxSolution &addee, double extensive) - // - // Add existing solution to "this" solution - // -{ - double ext1 = this->mass_water; - double ext2 = addee.mass_water * extensive; - double f1 = ext1/(ext1 + ext2); - double f2 = ext2/(ext1 + ext2); - this->tc = f1*this->tc + f2*addee.tc; - this->ph = f1*this->ph + f2*addee.ph; - this->pe = f1*this->pe + f2*addee.pe; - this->mu = f1*this->mu + f2*addee.mu; - this->ah2o = f1*this->mu + f2*addee.ah2o; - this->total_h += addee.total_h * extensive; - this->total_o += addee.total_o * extensive; - this->cb += addee.cb * extensive; - this->mass_water += addee.mass_water * extensive; - this->total_alkalinity += addee.total_alkalinity * extensive; - this->totals.add_extensive(addee.totals, extensive); - this->master_activity.add_log_activities(addee.master_activity, f1, f2); - this->species_gamma.add_intensive(addee.species_gamma, f1, f2); - this->isotopes.add(addee.isotopes, f2, extensive); -} + double cxxSolution::get_total(char *string)const { cxxNameDouble::const_iterator it = this->totals.find(string); diff --git a/Solution.h b/Solution.h index 23f01edd..52c3983c 100644 --- a/Solution.h +++ b/Solution.h @@ -11,7 +11,7 @@ #include // assert #include // std::map #include // std::string - +#include // std::list #include // std::vector #include "char_star.h" @@ -21,11 +21,12 @@ class cxxSolution : public cxxNumKeyword public: cxxSolution(); - //cxxSolution(double zero); + cxxSolution(double zero); cxxSolution(struct solution *); cxxSolution(const std::map &solution_map, cxxMix &mx); - //cxxSolution(const cxxSolution &old, double intensive, double extensive); - //cxxSolution(const cxxSolution&); + cxxSolution(const cxxSolution &old, double intensive, double extensive); + + //cxxSolution(const cxxSolution&); ~cxxSolution(); //static cxxSolution& read(CParser& parser); @@ -76,10 +77,13 @@ public: struct solution *cxxSolution2solution(); - void dump_raw(std::ostream& s_oss, unsigned int indent)const; + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); + void add(const cxxSolution &sol, double intensive, double extensive); #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); @@ -87,14 +91,6 @@ public: void mpi_send(int task_number); void mpi_recv(int task_number); #endif - -private: - void zero(); - //void add(const cxxSolution &sol, double intensive, double extensive); - void add(const cxxSolution &addee, double extensive); - // not checked - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - protected: double tc; double ph; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 0bc81085..88a0d135 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -32,55 +32,54 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) } void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) { - for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { - //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) - { - //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) - { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); - found = true; - break; - } - } - if (!found) - { - cxxSolutionIsotope iso; - iso.total = itold->total * extensive; - iso.ratio = itold->ratio * intensive; - iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; - iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; - this->push_back(iso); - } - } + + for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { + + //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) { + cxxSolutionIsotope iso; + iso.total = itold->total * extensive; + iso.ratio = itold->ratio * intensive; + iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; + iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; + this->push_back(iso); + } + } } struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() { - struct isotope *iso; - if (this->size() <= 0) { - return NULL; - } else { - iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); - if (iso == NULL) malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); - i++; - } - } - return(iso); + struct isotope *iso; + if (this->size() <= 0) { + return NULL; + } else { + iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + if (iso == NULL) malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return(iso); } diff --git a/StorageBin.cxx b/StorageBin.cxx index 6eeb6da7..d8d9f3b0 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -495,7 +495,7 @@ void cxxStorageBin::remove(int n) // Surface this->Surfaces.erase(n); } -#ifdef SKIP + cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) { @@ -536,7 +536,7 @@ cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) } return(cxxsoln_ptr); } -#endif + struct system *cxxStorageBin::cxxStorageBin2system(int n) // // make a system from storagebin diff --git a/StorageBin.h b/StorageBin.h index aa8806e0..3b19c292 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -42,8 +42,8 @@ public: } return (NULL); } - void setSolution(int n_user, cxxSolution &entity) { - Solutions[n_user] = entity; + void setSolution(int n_user, cxxSolution *entity) { + Solutions[n_user] = *entity; } void removeSolution(int n_user) { Solutions.erase(n_user); @@ -137,17 +137,9 @@ public: struct system *cxxStorageBin2system(int i); - //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); + cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix &mixmap); - const std::map& getSolutions()const {return this->Solutions;}; - const std::map& getExchangers()const {return this->Exchangers;}; - const std::map& getGasPhases()const {return this->GasPhases;}; - const std::map& getKinetics()const {return this->Kinetics;}; - const std::map& getPPassemblages()const {return this->PPassemblages;}; - const std::map& getSSassemblages()const {return this->SSassemblages;}; - const std::map& getSurfaces()const {return this->Surfaces;}; - #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); From 546c3e8e95ddf7763c1702f3088f5bde390d6b94 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 16 Mar 2007 18:12:22 +0000 Subject: [PATCH 0051/1077] Had extra :: qualifiers, not needed in header file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@1864 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.h | 4 ++-- cxxKinetics.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GasPhase.h b/GasPhase.h index 6127741b..c80a09ce 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -37,8 +37,8 @@ public: void read_raw(CParser& parser); #ifdef USE_MPI - void cxxGasPhase::mpi_pack(std::vector& ints, std::vector& doubles); - void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif protected: cxxNameDouble gasPhaseComps; diff --git a/cxxKinetics.h b/cxxKinetics.h index f22d6452..525f937a 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -36,8 +36,8 @@ public: bool get_related_rate(void); #ifdef USE_MPI - void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector& ints, std::vector& doubles); #endif protected: From 4a5bbef3244ca1208ac79bb160cd2ea79022318b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 May 2007 21:26:19 +0000 Subject: [PATCH 0052/1077] New compiler, lots of diffs in test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2042 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index d3faef0f..8c885d6a 100644 --- a/Makefile +++ b/Makefile @@ -467,6 +467,11 @@ dependencies: mkdir -p $(DEBUG_DIR) cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx +tester: + cd ../mytest; make clean; make -k >& make.out; make zero; make diff >& diff.out + cd ../examples; make clean; make >& make.out; make zero; make diff >& diff.out + svn status -q ../mytest + svn status -q ../examples # ============================================================================= # End of makefile. From 7830f46d8d158225d4435f9f052aa4d867b922b5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 May 2007 23:43:59 +0000 Subject: [PATCH 0053/1077] Merged 1727 through 2055 from orchestra/phreeqcpp_for_orch into phreeeqcpp trunk git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2057 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 91 +++++++- ExchComp.h | 17 +- Exchange.cxx | 72 +++++++ Exchange.h | 22 +- GasPhase.cxx | 66 ++++++ GasPhase.h | 15 ++ ISolution.cxx | 468 ++++++++++++++++++++++++++++++++++++++++ ISolution.h | 17 +- ISolutionComp.h | 4 +- KineticsComp.cxx | 35 +++ KineticsComp.h | 19 +- NameDouble.cxx | 79 +++++-- NameDouble.h | 5 +- PPassemblage.cxx | 63 +++++- PPassemblage.h | 19 +- PPassemblageComp.cxx | 80 +++++++ PPassemblageComp.h | 17 +- SSassemblage.cxx | 61 +++++- SSassemblage.h | 13 ++ SSassemblageSS.cxx | 48 +++++ SSassemblageSS.h | 12 ++ Solution.cxx | 307 +++++++++++++++----------- Solution.h | 23 +- SolutionIsotopeList.cxx | 93 ++++---- StorageBin.cxx | 7 +- StorageBin.h | 47 ++-- Surface.cxx | 144 ++++++++++++- Surface.h | 12 ++ SurfaceCharge.cxx | 59 +++++ SurfaceCharge.h | 5 + SurfaceComp.cxx | 117 +++++++++- SurfaceComp.h | 33 ++- cxxKinetics.cxx | 62 +++++- cxxKinetics.h | 6 +- 34 files changed, 1864 insertions(+), 274 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index d7848d0f..3971b176 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -54,7 +54,7 @@ totals(exch_comp_ptr->totals) rate_name = exch_comp_ptr->rate_name; formula_z = exch_comp_ptr->formula_z; } - +#ifdef SKIP cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vector &f_vector) // // constructor for cxxExchComp from mixing @@ -102,12 +102,12 @@ cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vectorla += it_ec->la*intensive; this->charge_balance += it_ec->charge_balance*extensive; this->phase_proportion += it_ec->phase_proportion*intensive; - this->totals.add(it_ec->totals, extensive); + this->totals.add_extensive(it_ec->totals, extensive); it_ec++; it_f++; } } - +#endif cxxExchComp::~cxxExchComp() { } @@ -437,6 +437,91 @@ void cxxExchComp::read_raw(CParser& parser) parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); } } +void cxxExchComp::add(const cxxExchComp &addee, double extensive) +{ + double ext1, ext2, f1, f2; + if (extensive == 0.0) return; + if (addee.formula == NULL) return; + // this and addee must have same formula + // otherwise generate a new exchcomp with multiply + + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) { + f1 = ext1/(ext1 + ext2); + f2 = ext2/(ext1 + ext2); + } else { + f1 = 0.5; + f2 = 0.5; + } + + //char * formula; + //cxxNameDouble formula_totals; + if (this->formula == NULL && addee.formula == NULL) { + return; + } + assert (this->formula == addee.formula); + assert (this->formula_z == addee.formula_z); + if (this->formula == NULL && addee.formula != NULL) { + this->formula = addee.formula; + this->formula_totals = addee.formula_totals; + } + //double moles; + this->moles += addee.moles * extensive; + //cxxNameDouble totals; + this->totals.add_extensive(addee.totals, extensive); + //double la; + this->la = f1*this->la + f2*addee.la; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //char *phase_name; + + if (this->phase_name != addee.phase_name) { + std::ostringstream oss; + oss << "Can not mix two exchange components with same formula and different related phases, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } else if (this->phase_name != NULL) { + this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; + } + //char *rate_name; + if (this->rate_name != addee.rate_name) { + std::ostringstream oss; + oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } else if (this->rate_name != NULL) { + //double phase_proportion; + this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; + } + if ((this->rate_name != NULL && addee.phase_name != NULL) || + (this->phase_name != NULL && addee.rate_name != NULL) ) + { + std::ostringstream oss; + oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } +} +void cxxExchComp::multiply(double extensive) +{ + //char * formula; + //double moles; + this->moles *= extensive; + //cxxNameDouble formula_totals; + //cxxNameDouble totals; + this->totals.multiply(extensive); + //double la; + //double charge_balance; + this->charge_balance *= extensive; + //char *phase_name; + //double phase_proportion; + this->phase_proportion *= extensive; + //double formula_z; +} #ifdef USE_MPI #include "Dictionary.h" void cxxExchComp::mpi_pack(std::vector& ints, std::vector& doubles) diff --git a/ExchComp.h b/ExchComp.h index 64972d6d..36da25ae 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -12,16 +12,14 @@ #include "char_star.h" -class cxxExchComp +class cxxExchComp { public: cxxExchComp(); cxxExchComp(struct exch_comp *); - cxxExchComp(std::vector &ec_vector, std::vector &f_vector); ~cxxExchComp(); - struct master *get_master(); char *get_formula()const {return this->formula;} char *get_phase_name()const {return this->phase_name;} @@ -35,6 +33,17 @@ public: void read_raw(CParser& parser); + + const cxxNameDouble &get_totals()const + { + return (this->totals); + }; + + + void add(const cxxExchComp &comp, double extensive); + void multiply(double extensive); + + #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); @@ -43,7 +52,7 @@ protected: char * formula; double moles; cxxNameDouble formula_totals; - cxxNameDouble totals; + cxxNameDouble totals; double la; double charge_balance; char *phase_name; diff --git a/Exchange.cxx b/Exchange.cxx index 92328c34..4219d021 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -13,6 +13,7 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort @@ -51,6 +52,37 @@ cxxNumKeyword() +} +cxxExchange::cxxExchange(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + this->pitzer_exchange_gammas = false; +// +// Mix exchangers +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxExchange *entity_ptr = &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; + } +#ifdef SKIP + if (entity_ptr == NULL) + { + sprintf(error_string, "Exchange %d not found while mixing.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + return; + } +#endif + + } } cxxExchange::~cxxExchange() @@ -221,6 +253,36 @@ void cxxExchange::read_raw(CParser& parser) parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE); } } +void cxxExchange::add(const cxxExchange &addee, double extensive) + // + // Add existing exchange to "this" exchange + // +{ + //std::list exchComps; + // exchComps + if (extensive == 0.0) return; + for (std::list::const_iterator itadd = addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd) + { + bool found = false; + for (std::list::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) { + cxxExchComp exc = *itadd; + exc.multiply(extensive); + //exc.add(*itadd, extensive); + this->exchComps.push_back(exc); + } + } + //bool pitzer_exchange_gammas; + this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; +} #ifdef USE_MPI /* ---------------------------------------------------------------------- */ void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles) @@ -259,3 +321,13 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxExchange::totalize() +{ + this->totals.clear(); + // component structures + for (std::list::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) + { + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; +} \ No newline at end of file diff --git a/Exchange.h b/Exchange.h index ac7c1a8c..44687df6 100644 --- a/Exchange.h +++ b/Exchange.h @@ -1,17 +1,15 @@ #if !defined(EXCHANGE_H_INCLUDED) #define EXCHANGE_H_INCLUDED -#include "NumKeyword.h" #define EXTERNAL extern #include "global.h" #include // assert #include // std::map #include // std::string -#include // std::list -#include // std::vector +#include // std::list -#include "char_star.h" #include "ExchComp.h" +#include "cxxMix.h" class cxxExchange : public cxxNumKeyword { @@ -19,14 +17,13 @@ class cxxExchange : public cxxNumKeyword public: cxxExchange(); cxxExchange(struct exchange *); + cxxExchange(const std::map &exchange_map, cxxMix &mx, int n_user); ~cxxExchange(); struct exchange *cxxExchange2exchange(); struct exch_comp *cxxExchComp2exch_comp(); - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); @@ -45,18 +42,27 @@ public: std::list &get_exchComps(void) { return(this->exchComps); } + void totalize(); + + const cxxNameDouble& get_totals()const + { + return totals; + }; #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif +private: + void add(const cxxExchange &addee, double extensive); + // not written + void dump_xml(std::ostream& os, unsigned int indent = 0)const; protected: std::list exchComps; bool pitzer_exchange_gammas; - + cxxNameDouble totals; public: - //static std::map& map; }; diff --git a/GasPhase.cxx b/GasPhase.cxx index dc6840b9..2ce9229b 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -11,6 +11,7 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort @@ -55,7 +56,53 @@ cxxNumKeyword() gasPhaseComps[gas_phase_ptr->comps[i].name] = gas_phase_ptr->comps[i].moles; } } +cxxGasPhase::cxxGasPhase(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; + total_p = 0; + volume = 0; + bool first = true; +// +// Mix +// + //cxxNameDouble gasPhaseComps; + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxGasPhase *entity_ptr = &(entities.find(it->first)->second); + this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, it->second); + //GP_TYPE type; + //double total_p; + //double volume; + if (first) + { + this->type = entity_ptr->type; + this->total_p = entity_ptr->total_p * it->second; + this->volume = entity_ptr->volume * it->second; + first = false; + } else + { + if (this->type != entity_ptr->type) + { + std::ostringstream oss; + oss << "Can not mix two gas_phases with differing types." ; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + this->total_p += entity_ptr->total_p * it->second; + this->volume += entity_ptr->volume * it->second; + } + } + } +} cxxGasPhase::~cxxGasPhase() { } @@ -316,3 +363,22 @@ void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxGasPhase::totalize() +{ + this->totals.clear(); + // component structures + for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(it->first, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, it->second); + } else + { + assert(false); + } + } + return; +} \ No newline at end of file diff --git a/GasPhase.h b/GasPhase.h index c80a09ce..24188b85 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -12,6 +12,7 @@ #include // std::vector #include "char_star.h" +#include "cxxMix.h" class cxxGasPhase : public cxxNumKeyword { @@ -19,6 +20,7 @@ class cxxGasPhase : public cxxNumKeyword public: cxxGasPhase(); cxxGasPhase(struct gas_phase *); + cxxGasPhase(const std::map &entity_map, cxxMix &mx, int n_user); ~cxxGasPhase(); enum GP_TYPE { @@ -40,11 +42,24 @@ public: void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif + + void totalize(); + + const cxxNameDouble& get_totals()const + { + return this->totals; + }; + +private: + void add(const cxxGasPhase &addee, double extensive); + protected: cxxNameDouble gasPhaseComps; GP_TYPE type; double total_p; double volume; + cxxNameDouble totals; + public: //static std::map& map; diff --git a/ISolution.cxx b/ISolution.cxx index e9954d0e..17a03401 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -418,3 +418,471 @@ void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const os << "" << "\n"; } #endif + +void cxxISolution::ORCH_write_chemistry(std::ostringstream &chemistry_dat) +{ + this->ORCH_write_chemistry_water(chemistry_dat); + this->ORCH_write_chemistry_primary(chemistry_dat); + this->ORCH_write_chemistry_total_O_H(chemistry_dat); + this->ORCH_write_chemistry_alkalinity(chemistry_dat); + this->ORCH_write_chemistry_species(chemistry_dat); + this->ORCH_write_chemistry_minerals(chemistry_dat); +} + + +void cxxISolution::ORCH_write_chemistry_water(std::ostringstream &chemistry_dat) +{ + // + // Write water entities + // + chemistry_dat << std::endl << "//********* The water entities" << std::endl; + + // e- + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + if (this->comps.find("E") == this->comps.end() || this->comps.find("E")->second.get_equation_name() == NULL) + { + // fixed pe + chemistry_dat << "@Calc: (1, \"e-.act = 10^-pe\")" << std::endl; + + } else if (this->comps.find("E")->second.get_equation_name() == string_hsave("charge")) + { + // charge balance + chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; + chemistry_dat << "@solve (e-.act, 1e-6, log, 1, chargebalance, 1e-14)" << std::endl; + } else + { + // adjust to equilbirium with a phase + chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; + int n; + struct phase *phase_ptr = phase_bsearch(this->comps.find("E)")->second.get_equation_name(), &n, FALSE); + assert (phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@solve (e-.act, 1e-6, log, 1, " << phase_name.c_str() << ".si_raw, 1e-9)" << std::endl; + } + + // H+ + if (this->comps.find("H(1)") == this->comps.end() || this->comps.find("H(1)")->second.get_equation_name() == NULL) + { + // fixed pH + chemistry_dat << "@Calc: (1, \"H+.act = 10^-pH\")" << std::endl; + + } else if (this->comps.find("H(1)")->second.get_equation_name() == string_hsave("charge")) + { + // charge balance + chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; + chemistry_dat << "@solve (H+.act, 1e-6, log, 1, chargebalance, 1e-14)" << std::endl; + } else + { + // adjust to equilbirium with a phase + chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; + int n; + struct phase *phase_ptr = phase_bsearch(this->comps.find("H(1)")->second.get_equation_name(), &n, FALSE); + assert (phase_ptr != NULL); + chemistry_dat << "@solve (H+.act, 1e-6, log, 1, " << phase_ptr->name << ".si_raw, 1e-9)" << std::endl; + } + + // H2O + chemistry_dat << "@entity(" << s_h2o->name << ", diss, 55.506)" << std::endl; + chemistry_dat << std::endl; +} + +void cxxISolution::ORCH_write_chemistry_primary(std::ostringstream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* The primary species" << std::endl; + // + // Write other master species definitions, i.e. primary entities + // + std::map::iterator iter = this->comps.begin(); + chemistry_dat << "@species(H+, 1)" << std::endl; + for(; iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->z << ")" << std::endl; + if (iter->second.get_equation_name() == NULL) + { + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr->name << ", 1e-9, diss, 1.0e-9)" << std::endl; + } else + { + std::string eqn(iter->second.get_equation_name()); + if (eqn == "charge") + { + // charge balance + chemistry_dat << "@solve (" << s_ptr->name << ".act, 1e-6, log, 1, chargebalance, 1e-9)" << std::endl; + } else + { + // adjust to phase equilibrium + int n; + struct phase *phase_ptr = phase_bsearch(eqn.c_str(), &n, FALSE); + assert (phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@solve (" << s_ptr->name << ".act, 1e-6, log, 1, " << phase_name << ".si_raw, 1e-9)" << std::endl; + } + } + } + chemistry_dat << std::endl; +} + +void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostringstream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl; + // Define total hydrogen, total oxygen, and difference + //chemistry_dat << "@var: total_diff 0" << std::endl; + //chemistry_dat << "@calc: (5, \"total_diff = total_hydrogen - 2*total_oxygen" << "\")" << std::endl; + + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + int i; + for (i = 0; i < count_s_x; i++) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) + { + if (s_x[i]->h != 0) + { + chemistry_dat << "+"; + if (s_x[i]->h != 1) + { + chemistry_dat << s_x[i]->h << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".diss}"; + } + } + } + chemistry_dat << "\")" << std::endl; + + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->o != 0) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) + { + chemistry_dat << "+"; + if (s_x[i]->o != 1) + { + chemistry_dat << s_x[i]->o << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".diss}"; + } + } + } + chemistry_dat << "\")" << std::endl; + chemistry_dat << std::endl; +} + +void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostringstream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Alkalinity definitions" << std::endl; + // + // Define alkalinity + // + chemistry_dat << "@Var: Alkalinity 0" << std::endl; + chemistry_dat << "@calc: (5, \"Alkalinity = 0"; + for (int i = 0; i < count_s_x; i++) + { + if (s_x[i]->alk == 0) continue; + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + if (s_x[i]->alk < 0) + { + if (s_x[i]->alk != -1) + { + chemistry_dat << s_x[i]->alk << "*{" << name << ".con}"; + } else + { + chemistry_dat << "-{" << name << ".con}"; + } + } else if (s_x[i]->alk > 0) + { + if (s_x[i]->alk != 1) + { + chemistry_dat << "+" << s_x[i]->alk << "*{" << name << ".con}"; + } else + { + chemistry_dat << "+{" << name << ".con}"; + } + } + } + chemistry_dat << "\")" << std::endl; + // + // Alkalinity (or pH) equation + // + std::map::iterator iter = this->comps.begin(); + if ((iter = this->comps.find("Alkalinity")) != this->comps.end()) + { + if ((this->comps.find("C(4)") != this->comps.end()) || (this->comps.find("C") != this->comps.end())) + { + if (this->comps.find("H(1)") != this->comps.end() ) + { + std::ostringstream oss; + oss << "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << std::endl; + chemistry_dat << std::endl; + } else + { + struct master *master_ptr = master_bsearch("Alkalinity"); + if (master_ptr == NULL) + { + std::ostringstream oss; + oss << "Could not find Alkalinity definition in database."; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + chemistry_dat << "@species(" << master_ptr->s->name << ", " << master_ptr->s->z << ")" << std::endl; + chemistry_dat << "@solve (" << master_ptr->s->name << ".act, 1e-6, log, 1, Alkalinity, 1e-9)" << std::endl; + chemistry_dat << std::endl; + } + } +} +void cxxISolution::ORCH_write_chemistry_species(std::ostringstream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Aqueous species" << std::endl; + // + // Write species definitions + // + for (int i = 0; i < count_s_x; i++) { + if (s_x[i]->primary != NULL) continue; + if (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE) continue; + + // write species + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + chemistry_dat << "@species(" << name.c_str() << ", " << s_x[i]->z << ")" << std::endl; + + // write reaction + chemistry_dat << "@reaction(" << name.c_str() << ", " << pow(10.0, s_x[i]->lk); + struct rxn_token *next_token = s_x[i]->rxn_x->token; + next_token++; + while (next_token->s != NULL || next_token->name != NULL) + { + chemistry_dat << ", " << next_token->coef; + if (next_token->s != NULL) + { + chemistry_dat << ", " << next_token->s->name; + } else { + chemistry_dat << ", " << next_token->name; + } + next_token++; + } + chemistry_dat << ")" << std::endl; + } + chemistry_dat << std::endl; +} +void cxxISolution::ORCH_write_chemistry_minerals(std::ostringstream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Adjustments to mineral equilibrium" << std::endl; +// +// Write minerals +// + std::map::iterator iter = this->comps.begin(); + for(iter = this->comps.begin(); iter != this->comps.end(); ++iter) + { + if (iter->second.get_equation_name() != NULL) + { + std::string name(iter->second.get_equation_name()); + if (name != "charge") + { + struct phase *phase_ptr; + int n; + phase_ptr = phase_bsearch(name.c_str(), &n, FALSE); + assert (phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@si_mineral(" << phase_name << ")" << std::endl; + chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, -phase_ptr->lk); + struct rxn_token *next_token = phase_ptr->rxn_x->token; + next_token++; + while (next_token->s != NULL || next_token->name != NULL) + { + chemistry_dat << ", " << next_token->coef; + if (next_token->s != NULL) + { + chemistry_dat << ", " << next_token->s->name; + } else { + chemistry_dat << ", " << next_token->name; + } + next_token++; + } + chemistry_dat << ")" << std::endl; + } + } + } +} +void cxxISolution::ORCH_write_input(std::ostringstream &input_dat) +{ + + +// +// Write orchestra input file info +// + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; + + + // Solution element and attributes + + //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + + //s_oss << "-temp " << this->tc << std::endl; + + //s_oss << "-pH " << this->ph << std::endl; + headings << "pH\t"; + data << this->ph << "\t"; + + //s_oss << "-pe " << this->pe << std::endl; + headings << "pe\t"; + data << this->pe << "\t"; + + //s_oss << "-mu " << this->mu << std::endl; + + //s_oss << "-ah2o " << this->ah2o << std::endl; + headings << "H2O.act\t"; + data << 1 << "\t"; + //s_oss << "-total_h " << this->total_h << std::endl; + + //s_oss << "-total_o " << this->total_o << std::endl; + + //s_oss << "-cb " << this->cb << std::endl; + + //s_oss << "-mass_water " << this->mass_water << std::endl; + + //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + + // soln_total conc structures + //this->totals.dump_raw(s_oss, indent + 2); + //this->totals.write_orchestra(headings, s_oss); + + std::map::iterator iter = this->comps.begin(); + for (; iter != this->comps.end(); ++iter) + { + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch (iter->first); + assert (master_ptr != NULL); + std::string ename(iter->first); + + if (ename != "Alkalinity") + { + ename = master_ptr->s->name; + ename.append(".diss"); + } + + if (iter->second.get_equation_name() == NULL) + { + headings << ename << "\t"; + data << (this->totals.find(iter->first))->second << "\t"; + } else + { + std::string name(iter->second.get_equation_name()); + if (name == "charge") + { + headings << ename << "\t"; + data << (this->totals.find(iter->first))->second << "\t"; + } else + { + int n; + struct phase *phase_ptr = phase_bsearch(name.c_str(),&n, TRUE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + headings << phase_name << ".si_raw" << "\t"; + data << iter->second.get_phase_si() << "\t"; + } + } + // activity estimate + if (ename == "Alkalinity") + { + if ((this->comps.find("C") == this->comps.end()) && (this->comps.find("C(4)") == this->comps.end())) + { + headings << master_ptr->s->name << ".act\t"; + data << iter->second.get_moles()*1e-3 << "\t"; + } + } + else + { + headings << master_ptr->s->name << ".act\t"; + data << iter->second.get_moles()*1e-3 << "\t"; + } + } + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; + + return; +} + +void cxxISolution::ORCH_write_output(std::ostringstream &outstream) +{ + outstream << "Var:"; + outstream << "\tnr_iter"; + // + // Write total concentrations in solution + // + outstream << "\tH2O.diss"; + outstream << "\te-.diss"; + outstream << "\tH+.diss"; + std::map::iterator iter = this->comps.begin(); + for(; iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + outstream << "\t" << s_ptr->name << ".diss"; + } + outstream << "\tchargebalance"; + outstream<< "\tI"; + // + // Write all species activities and concentrations + // + int i; + for (i = 0; i < count_s_x; i++) { + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; + } + outstream << std::endl; + return; +} \ No newline at end of file diff --git a/ISolution.h b/ISolution.h index 1ded2adc..8d516488 100644 --- a/ISolution.h +++ b/ISolution.h @@ -12,8 +12,9 @@ #include // std::list #include // std::vector #include // std::set - - +#include +#include +#include class cxxISolution : public cxxSolution { @@ -40,7 +41,10 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void ConvertUnits(); - + void ORCH_write_chemistry(std::ostringstream &chemistry_dat); + void ORCH_write_input(std::ostringstream &input_dat); + void ORCH_write_output(std::ostringstream &input_dat); + void print(); protected: friend class cxxISolutionComp; // for this->pe access double density; @@ -52,6 +56,13 @@ protected: public: //static std::map& map; +private: + void ORCH_write_chemistry_water(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_primary(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_alkalinity(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_species(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_minerals(std::ostringstream &chemistry_dat); }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/ISolutionComp.h b/ISolutionComp.h index 512a3421..7b48063b 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -30,7 +30,7 @@ public: void dump_xml(std::ostream& os, unsigned int indent = 0)const; - std::string get_description()const {return this->description;} + char * get_description()const {return this->description;} void set_description(char * description) {this->description = description;} double get_moles()const {return this->moles;} @@ -42,7 +42,7 @@ public: std::string get_units()const {return this->units;} void set_units(char * units) {this->units = units;} - std::string get_equation_name()const {return this->equation_name;} + char * get_equation_name()const {return this->equation_name;} void set_equation_name(char * equation_name) {this->equation_name = equation_name;} double get_phase_si()const {return this->phase_si;} diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 17bbfbf8..bb4b7867 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -345,3 +345,38 @@ void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxKineticsComp::add(const cxxKineticsComp &addee, double extensive) +{ + if (extensive == 0.0) return; + if (addee.rate_name == NULL) return; + // this and addee must have same name + // otherwise generate a new KineticsComp with multiply + if (this->rate_name == NULL && addee.rate_name == NULL) { + return; + } + //char * rate_name; + assert (this->rate_name == addee.rate_name); + //cxxNameDouble namecoef; + //double tol; + //double m; + this->m += addee.m * extensive; + //double m0; + this->m0 += addee.m0 * extensive; + //double moles; + this->moles += addee.moles * extensive; + //std::vector d_params; +} + +void cxxKineticsComp::multiply(double extensive) +{ + //char * rate_name; + //cxxNameDouble namecoef; + //double tol; + //double m; + this->m *= extensive; + //double m0; + this->m0 *= extensive; + //double moles; + this->moles *= extensive; + //std::vector d_params; +} diff --git a/KineticsComp.h b/KineticsComp.h index 3c43cb45..7097f34a 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -27,19 +27,24 @@ public: void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); + + char *get_rate_name()const {return this->rate_name;} #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector& ints, std::vector& doubles); #endif + void add(const cxxKineticsComp &comp, double extensive); + void multiply(double extensive); + protected: - char * rate_name; - cxxNameDouble namecoef; - double tol; - double m; - double m0; - double moles; - std::vector d_params; + char * rate_name; + cxxNameDouble namecoef; //stoichiometry of reaction + double tol; + double m; + double m0; + double moles; + std::vector d_params; public: diff --git a/NameDouble.cxx b/NameDouble.cxx index 5561713d..301b9569 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -275,21 +275,63 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_ return CParser::PARSER_OK; } -void cxxNameDouble::add(const cxxNameDouble &old, double factor) - // - // constructor for cxxNameDouble from list of elt_list - // +void cxxNameDouble::add_extensive(const cxxNameDouble &addee, double factor) +// +// Sums two name doubles, this + factor*nd2 +// { - for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) { - (*this)[it->first] = current->second + it->second * factor; - } else { - (*this)[it->first] = it->second * factor; - } - } - + if (factor == 0) return; + assert (factor > 0.0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = current->second + it->second * factor; + } else { + (*this)[it->first] = it->second * factor; + } + } } +void cxxNameDouble::add_intensive(const cxxNameDouble &addee, double f1, double f2) +// +// Sums two name doubles, this*f1 + f2*nd2 +// +{ + assert(f1 >= 0 && f2 >= 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = f1*current->second + f2*it->second; + } else { + (*this)[it->first] = f2 * it->second; + } + } +} +void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, double f2) +// +// Sums two name doubles, this*f1 + f2*nd2, assuming log values +// +{ + assert (f1 >= 0 && f2 >= 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + double a1 = pow(10., current->second); + double a2 = pow(10., it->second); + (*this)[it->first] = log10(f1*a1 + f2*a2); + } else { + //double a2 = pow(10. it->second); + //(*this)[it->first] = log10(f2 * a2); + (*this)[it->first] = it->second + log10(f2); + } + } +} + void cxxNameDouble::add(char * key, double total) // // add to total for a specified element @@ -302,6 +344,17 @@ void cxxNameDouble::add(char * key, double total) (*this)[key] = total; } } +void cxxNameDouble::multiply(double extensive) +{ +// +// Multiplies by extensive +// + + for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++) + { + it->second *= extensive; + } +} #ifdef USE_MPI #include "Dictionary.h" void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { diff --git a/NameDouble.h b/NameDouble.h index 7623c2f5..83754583 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -44,8 +44,11 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); - void add(const cxxNameDouble &old, double factor); + void add_extensive(const cxxNameDouble &old, double factor); + void add_intensive(const cxxNameDouble &addee, double fthis, double f2); + void add_log_activities(const cxxNameDouble &addee, double fthis, double f2); void add(char * key, double total); + void multiply(double factor); void insert(char *str, double d) { (*this)[str] = d; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 54458d88..9dd8bca2 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -46,7 +46,26 @@ eltList(pp_assemblage_ptr->next_elt) ppAssemblageComps.push_back(ppComp); } } - +cxxPPassemblage::cxxPPassemblage(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + eltList.type = cxxNameDouble::ND_ELT_MOLES; +// +// Mix +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxPPassemblage *entity_ptr = &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } +} cxxPPassemblage::~cxxPPassemblage() { } @@ -225,3 +244,45 @@ void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif + +void cxxPPassemblage::totalize() +{ + this->totals.clear(); + // component structures + for (std::list::iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + { + it->totalize(); + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; +} + +void cxxPPassemblage::add(const cxxPPassemblage &addee, double extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // +{ + if (extensive == 0.0) return; + //std::list ppAssemblageComps; + for (std::list::const_iterator itadd = addee.ppAssemblageComps.begin(); itadd != addee.ppAssemblageComps.end(); ++itadd) + { + bool found = false; + for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) { + cxxPPassemblageComp entity = *itadd; + entity.multiply(extensive); + this->ppAssemblageComps.push_back(entity); + } + } + //cxxNameDouble eltList; + this->eltList.add_extensive(addee.eltList, extensive); +} + diff --git a/PPassemblage.h b/PPassemblage.h index a03790f0..659e8304 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -12,6 +12,7 @@ #include "char_star.h" #include "PPassemblageComp.h" +#include "cxxMix.h" class cxxPPassemblage : public cxxNumKeyword { @@ -19,14 +20,13 @@ class cxxPPassemblage : public cxxNumKeyword public: cxxPPassemblage(); cxxPPassemblage(struct pp_assemblage *); - ~cxxPPassemblage(); + cxxPPassemblage(const std::map &entity_map, cxxMix &mx, int n_user); + ~cxxPPassemblage(); struct pp_assemblage *cxxPPassemblage2pp_assemblage(); struct pure_phase *cxxPPassemblageComp2pure_phase(); - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); @@ -36,9 +36,22 @@ public: void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif + void totalize(); + +private: + void add(const cxxPPassemblage &addee, double extensive); + // not written + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + const cxxNameDouble& get_totals()const + { + return this->totals; + }; + protected: std::list ppAssemblageComps; cxxNameDouble eltList; + cxxNameDouble totals; public: //static std::map& map; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index a25b0bde..6d55b2c5 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -11,6 +11,7 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" #include // assert #include // std::sort @@ -329,3 +330,82 @@ void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *d *dd = d; } #endif + +void cxxPPassemblageComp::totalize() +{ + this->totals.clear(); + // component structures + if (this->add_formula != NULL) return; + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(this->name, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, this->moles); + } else + { + assert(false); + } + return; +} + + +void cxxPPassemblageComp::add(const cxxPPassemblageComp &addee, double extensive) +{ + double ext1, ext2, f1, f2; + if (extensive == 0.0) return; + if (addee.name == NULL) return; + // this and addee must have same name + // otherwise generate a new PPassemblagComp with multiply + + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) { + f1 = ext1/(ext1 + ext2); + f2 = ext2/(ext1 + ext2); + } else { + f1 = 0.5; + f2 = 0.5; + } + //char * name; + //char *add_formula; + + if (this->name == NULL && addee.name == NULL) { + return; + } + assert (this->name == addee.name); + if (this->add_formula != addee.add_formula) { + std::ostringstream oss; + oss << "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + //double si; + this->si = this->si * f1 + addee.si * f2; + //double moles; + this->moles += addee.moles * extensive; + //double delta; + this->delta += addee.delta * extensive; + //double initial_moles; + this->initial_moles += addee.initial_moles * extensive; + //bool force_equality; + //bool dissolve_only; + +} + +void cxxPPassemblageComp::multiply(double extensive) +{ + //char * name; + //char *add_formula; + //double si; + //double moles; + this->moles *= extensive; + //double delta; + this->delta *= extensive; + //double initial_moles; + this->initial_moles *= extensive; + //bool force_equality; + //bool dissolve_only; +} diff --git a/PPassemblageComp.h b/PPassemblageComp.h index d925c030..fbb6aa72 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -12,7 +12,7 @@ #include "char_star.h" -class cxxPPassemblageComp +class cxxPPassemblageComp { public: @@ -29,13 +29,25 @@ public: void read_raw(CParser& parser); + char *get_name()const {return this->name;} + struct phase *get_phase(); + + void totalize(); + const cxxNameDouble &get_totals()const + { + return (this->totals); + }; + + void add(const cxxPPassemblageComp &comp, double extensive); + void multiply(double extensive); + #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif protected: - char * name; + char *name; char *add_formula; double si; double moles; @@ -43,6 +55,7 @@ protected: double initial_moles; bool force_equality; bool dissolve_only; + cxxNameDouble totals; public: diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 397534bb..4d2144fe 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -43,7 +43,26 @@ cxxNumKeyword() ssAssemblageSSs.push_back(ssSS); } } - +cxxSSassemblage::cxxSSassemblage(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + //std::list ssAssemblageSSs; +// +// Mix +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxSSassemblage *entity_ptr = &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } +} cxxSSassemblage::~cxxSSassemblage() { } @@ -203,3 +222,43 @@ void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif + +void cxxSSassemblage::totalize() +{ + this->totals.clear(); + // component structures + for (std::list::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + { + it->totalize(); + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; +} + +void cxxSSassemblage::add(const cxxSSassemblage &addee, double extensive) + // + // Add to existing ssassemblage to "this" ssassemblage + // +{ + if (extensive == 0.0) return; + + for (std::list::const_iterator itadd = addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); ++itadd) + { + bool found = false; + for (std::list::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) { + cxxSSassemblageSS entity = *itadd; + entity.multiply(extensive); + this->ssAssemblageSSs.push_back(entity); + } + } +} + diff --git a/SSassemblage.h b/SSassemblage.h index 281910b8..00c5f99d 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -12,6 +12,7 @@ #include "char_star.h" #include "SSassemblageSS.h" +#include "cxxMix.h" class cxxSSassemblage : public cxxNumKeyword { @@ -19,6 +20,7 @@ class cxxSSassemblage : public cxxNumKeyword public: cxxSSassemblage(); cxxSSassemblage(struct s_s_assemblage *); + cxxSSassemblage(const std::map &entity_map, cxxMix &mx, int n_user); ~cxxSSassemblage(); struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); @@ -35,9 +37,20 @@ public: void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif + void totalize(); + + const cxxNameDouble& get_totals()const + { + return this->totals; + }; + + +private: + void add(const cxxSSassemblage &addee, double extensive); protected: std::list ssAssemblageSSs; + cxxNameDouble totals; public: //static std::map& map; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 4754283d..890429ee 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -474,3 +474,51 @@ void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif + +void cxxSSassemblageSS::totalize() +{ + this->totals.clear(); + // component structures + for (cxxNameDouble::const_iterator it = this->comps.begin(); it != this->comps.end(); it++) { + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(it->first, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, it->second); + } else + { + assert(false); + } + } + return; +} + +void cxxSSassemblageSS::add(const cxxSSassemblageSS &addee, double extensive) +{ + if (extensive == 0.0) return; + if (addee.name == NULL) return; + // this and addee must have same name + // otherwise generate a new PPassemblagComp with multiply + + //char *name; + //cxxNameDouble comps; + this->comps.add_extensive(addee.comps, extensive); + //double a0, a1; + //double ag0, ag1; + //bool miscibility; + //double xb1, xb2; +} + +void cxxSSassemblageSS::multiply(double extensive) +{ + //char *name; + //cxxNameDouble comps; + this->comps.multiply(extensive); + //double a0, a1; + //double ag0, ag1; + //bool miscibility; + //double xb1, xb2; +} + diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 511f1aff..ca23b2e4 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -41,12 +41,23 @@ public: void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); + + char *get_name()const {return this->name;} + + void totalize(); + const cxxNameDouble &get_totals()const + { + return (this->totals); + }; #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif + void add(const cxxSSassemblageSS &comp, double extensive); + void multiply(double extensive); + protected: char *name; cxxNameDouble comps; @@ -54,6 +65,7 @@ protected: double ag0, ag1; bool miscibility; double xb1, xb2; + cxxNameDouble totals; public: diff --git a/Solution.cxx b/Solution.cxx index cb1e65c7..64b851d8 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -27,40 +27,19 @@ cxxSolution::cxxSolution() // : cxxNumKeyword() { - tc = 25.0; - ph = 7.0; - pe = 4.0; - mu = 1e-7; - ah2o = 1.0; - total_h = 111.1; - total_o = 55.55; - cb = 0.0; - mass_water = 1.0; - total_alkalinity = 0.0; - totals.type = cxxNameDouble::ND_ELT_MOLES; - master_activity.type = cxxNameDouble::ND_SPECIES_LA; - species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; -} -cxxSolution::cxxSolution(double zero) - // - // empty cxxSolution constructor - // -: cxxNumKeyword() -{ - assert (zero == 0.0); - tc = 0.0; - ph = 0.0; - pe = 0.0; - mu = 0.0; - ah2o = 0.0; - total_h = 0.0; - total_o = 0.0; - cb = 0.0; - mass_water = 0.0; - total_alkalinity = 0.0; - totals.type = cxxNameDouble::ND_ELT_MOLES; - master_activity.type = cxxNameDouble::ND_SPECIES_LA; - species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + this->tc = 25.0; + this->ph = 7.0; + this->pe = 4.0; + this->mu = 1e-7; + this->ah2o = 1.0; + this->total_h = 111.1; + this->total_o = 55.55; + this->cb = 0.0; + this->mass_water = 1.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } cxxSolution::cxxSolution(struct solution *solution_ptr) // @@ -75,18 +54,18 @@ isotopes(solution_ptr) { this->set_description(solution_ptr->description); - n_user = solution_ptr->n_user; - n_user_end = solution_ptr->n_user_end; - tc = solution_ptr->tc; - ph = solution_ptr->ph; - pe = solution_ptr->solution_pe; - mu = solution_ptr->mu; - ah2o = solution_ptr->ah2o; - total_h = solution_ptr->total_h; - total_o = solution_ptr->total_o; - cb = solution_ptr->cb; - mass_water = solution_ptr->mass_water; - total_alkalinity = solution_ptr->total_alkalinity; + this->n_user = solution_ptr->n_user; + this->n_user_end = solution_ptr->n_user_end; + this->tc = solution_ptr->tc; + this->ph = solution_ptr->ph; + this->pe = solution_ptr->solution_pe; + this->mu = solution_ptr->mu; + this->ah2o = solution_ptr->ah2o; + this->total_h = solution_ptr->total_h; + this->total_o = solution_ptr->total_o; + this->cb = solution_ptr->cb; + this->mass_water = solution_ptr->mass_water; + this->total_alkalinity = solution_ptr->total_alkalinity; // Totals filled in constructor, just save description and moles @@ -101,42 +80,38 @@ isotopes(solution_ptr) // Species_gamma in constructor } -#ifdef SKIP -cxxSolution::cxxSolution(const cxxSolution &old, double intensive, double extensive) - // - // constructor for cxxSolution from struct solution - // -: -cxxNumKeyword(), -totals(old.totals, extensive), -master_activity(old.master_activity, intensive), -species_gamma(old.species_gamma, intensive) + +cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix, int n_user) +// +// constructor for cxxSolution from mixture of solutions +// +: +cxxNumKeyword() { - this->set_description(old.description); - this->n_user = old.n_user; - this->n_user_end = old.n_user_end; - this->tc = old.tc * intensive; - this->ph = old.ph * intensive; - this->pe = old.pe * intensive; - this->mu = old.mu * intensive; - this->ah2o = old.ah2o * intensive; - this->total_h = old.total_h * extensive; - this->total_o = old.total_o * extensive; - this->cb = old.cb * extensive; - this->mass_water = old.mass_water * extensive; - this->total_alkalinity = old.total_alkalinity * extensive; - /* - cxxNameDouble totals; - std::list isotopes; - cxxNameDouble master_activity; - cxxNameDouble species_gamma; - */ - for (std::list::const_iterator it = old.isotopes.begin(); it != old.isotopes.end(); it++) { - this->isotopes.push_back(cxxSolutionIsotope((*it), intensive, extensive)); - } +// +// Zero out solution data +// + this->zero(); + this->n_user = this->n_user_end = n_user; +// +// Mix solutions +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); + if (cxxsoln_ptr1 == NULL) + { + sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + return; + } + this->add(*cxxsoln_ptr1, it->second); + } } -#endif cxxSolution::~cxxSolution() { @@ -191,6 +166,7 @@ struct solution *cxxSolution::cxxSolution2solution() return(solution_ptr); } + void cxxSolution::dump_xml(std::ostream& s_oss, unsigned int indent)const { //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; @@ -396,7 +372,93 @@ void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const return; } +void cxxSolution::write_orchestra(std::ostream& headings, std::ostream& data)const +{ + data.precision(DBL_DIG - 1); + + // Solution element and attributes + + //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + + //s_oss << "-temp " << this->tc << std::endl; + + //s_oss << "-pH " << this->ph << std::endl; + headings << "pH\t"; + data << this->ph << "\t"; + + //s_oss << "-pe " << this->pe << std::endl; + headings << "pe\t"; + data << this->pe << "\t"; + + //s_oss << "-mu " << this->mu << std::endl; + + //s_oss << "-ah2o " << this->ah2o << std::endl; + headings << "H2O.act\t"; + data << 1 << "\t"; + //s_oss << "-total_h " << this->total_h << std::endl; + + //s_oss << "-total_o " << this->total_o << std::endl; + + //s_oss << "-cb " << this->cb << std::endl; + + //s_oss << "-mass_water " << this->mass_water << std::endl; + + //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + + // soln_total conc structures + //this->totals.dump_raw(s_oss, indent + 2); + //this->totals.write_orchestra(headings, s_oss); + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) + { + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch (it->first); + if (master_ptr != NULL) + { + //headings << it->first << ".tot" << "\t"; + headings << master_ptr->s->name << ".diss" << "\t"; + data << it->second << "\t"; + } else + { + assert(false); + } + } + + // master_activity map + //this->master_activity.dump_raw(s_oss, indent + 2); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + */ + // species_gamma map + //this->species_gamma.dump_raw(s_oss, indent + 2); + /* + { + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + } + */ + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + return; +} void cxxSolution::read_raw(CParser& parser) { static std::vector vopts; @@ -669,60 +731,48 @@ void cxxSolution::read_raw(CParser& parser) return; } -void cxxSolution::add(const cxxSolution &old, double intensive, double extensive) +void cxxSolution::zero() +{ + this->tc = 0.0; + this->ph = 0.0; + this->pe = 0.0; + this->mu = 0.0; + this->ah2o = 0.0; + this->total_h = 0.0; + this->total_o = 0.0; + this->cb = 0.0; + this->mass_water = 0.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; +} + +void cxxSolution::add(const cxxSolution &addee, double extensive) // // Add existing solution to "this" solution // { - - this->tc += old.tc * intensive; - this->ph += old.ph * intensive; - this->pe += old.pe * intensive; - this->mu += old.mu * intensive; - this->ah2o += old.ah2o * intensive; - this->total_h += old.total_h * extensive; - this->total_o += old.total_o * extensive; - this->cb += old.cb * extensive; - this->mass_water += old.mass_water * extensive; - this->total_alkalinity += old.total_alkalinity * extensive; - - this->totals.add(old.totals, extensive); - this->master_activity.add(old.master_activity, intensive); - this->species_gamma.add(old.species_gamma, intensive); - this->isotopes.add(old.isotopes, intensive, extensive); - -#ifdef SKIP - // - // isotopes - // go through old list, update or add to current list - // - for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); - found = true; - break; - } - } - if (!found) { - this->isotopes.push_back(*itold); - } - } -#endif - /* - cxxNameDouble totals; - std::list isotopes; - cxxNameDouble master_activity; - cxxNameDouble species_gamma; - */ + if (extensive == 0.0) return; + double ext1 = this->mass_water; + double ext2 = addee.mass_water * extensive; + double f1 = ext1/(ext1 + ext2); + double f2 = ext2/(ext1 + ext2); + this->tc = f1*this->tc + f2*addee.tc; + this->ph = f1*this->ph + f2*addee.ph; + this->pe = f1*this->pe + f2*addee.pe; + this->mu = f1*this->mu + f2*addee.mu; + this->ah2o = f1*this->mu + f2*addee.ah2o; + this->total_h += addee.total_h * extensive; + this->total_o += addee.total_o * extensive; + this->cb += addee.cb * extensive; + this->mass_water += addee.mass_water * extensive; + this->total_alkalinity += addee.total_alkalinity * extensive; + this->totals.add_extensive(addee.totals, extensive); + this->master_activity.add_log_activities(addee.master_activity, f1, f2); + this->species_gamma.add_intensive(addee.species_gamma, f1, f2); + this->isotopes.add(addee.isotopes, f2, extensive); } - double cxxSolution::get_total(char *string)const { cxxNameDouble::const_iterator it = this->totals.find(string); @@ -1413,3 +1463,4 @@ void test_classes(void) } */ } + diff --git a/Solution.h b/Solution.h index 52c3983c..967623c3 100644 --- a/Solution.h +++ b/Solution.h @@ -11,8 +11,8 @@ #include // assert #include // std::map #include // std::string -#include // std::list #include // std::vector +#include #include "char_star.h" @@ -21,12 +21,8 @@ class cxxSolution : public cxxNumKeyword public: cxxSolution(); - cxxSolution(double zero); cxxSolution(struct solution *); - cxxSolution(const std::map &solution_map, cxxMix &mx); - cxxSolution(const cxxSolution &old, double intensive, double extensive); - - //cxxSolution(const cxxSolution&); + cxxSolution(const std::map &solution_map, cxxMix &mx, int n_user); ~cxxSolution(); //static cxxSolution& read(CParser& parser); @@ -77,13 +73,11 @@ public: struct solution *cxxSolution2solution(); - 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 write_orchestra(std::ostream& headings, std::ostream& input_data)const; void read_raw(CParser& parser); - void add(const cxxSolution &sol, double intensive, double extensive); #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); @@ -91,6 +85,13 @@ public: void mpi_send(int task_number); void mpi_recv(int task_number); #endif + +private: + void zero(); + void add(const cxxSolution &addee, double extensive); + // not checked + void dump_xml(std::ostream& os, unsigned int indent = 0)const; + protected: double tc; double ph; @@ -107,8 +108,6 @@ protected: cxxNameDouble master_activity; cxxNameDouble species_gamma; cxxSolutionIsotopeList isotopes; -public: - //static std::map& map; }; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 88a0d135..0bc81085 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -32,54 +32,55 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) } void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) { - - for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { - - //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); - found = true; - break; - } - } - if (!found) { - cxxSolutionIsotope iso; - iso.total = itold->total * extensive; - iso.ratio = itold->ratio * intensive; - iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; - iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; - this->push_back(iso); - } - } + for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { + //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) + { + //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) + { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) + { + cxxSolutionIsotope iso; + iso.total = itold->total * extensive; + iso.ratio = itold->ratio * intensive; + iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; + iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; + this->push_back(iso); + } + } } struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() { - struct isotope *iso; - if (this->size() <= 0) { - return NULL; - } else { - iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); - if (iso == NULL) malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); - i++; - } - } - return(iso); + struct isotope *iso; + if (this->size() <= 0) { + return NULL; + } else { + iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + if (iso == NULL) malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return(iso); } diff --git a/StorageBin.cxx b/StorageBin.cxx index d8d9f3b0..4b8b3064 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -495,7 +495,7 @@ void cxxStorageBin::remove(int n) // Surface this->Surfaces.erase(n); } - +#ifdef SKIP cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) { @@ -536,7 +536,7 @@ cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) } return(cxxsoln_ptr); } - +#endif struct system *cxxStorageBin::cxxStorageBin2system(int n) // // make a system from storagebin @@ -823,7 +823,7 @@ void cxxStorageBin::mpi_recv(int task_number) delete[] doubles; } #endif - +#ifdef SKIP cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) { @@ -916,3 +916,4 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) */ return(new_exch_ptr); } +#endif diff --git a/StorageBin.h b/StorageBin.h index 3b19c292..a3ee4123 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -43,6 +43,7 @@ public: return (NULL); } void setSolution(int n_user, cxxSolution *entity) { + if (entity == NULL) return; Solutions[n_user] = *entity; } void removeSolution(int n_user) { @@ -56,7 +57,8 @@ public: return (NULL); } void setExchange(int n_user, cxxExchange *entity) { - Exchangers[n_user] = *entity; + if (entity == NULL) return; + Exchangers[n_user] = *entity; } void removeExchange(int n_user) { Exchangers.erase(n_user); @@ -69,6 +71,7 @@ public: return (NULL); } void setPPassemblage(int n_user, cxxPPassemblage *entity) { + if (entity == NULL) return; PPassemblages[n_user] = *entity; } void removePPassemblage(int n_user) { @@ -81,8 +84,9 @@ public: } return (NULL); } - void setGasPhase(int n_user, cxxGasPhase *entity) { - GasPhases[n_user] = *entity; + void setGasPhase(int n_user, cxxGasPhase *entity) { + if (entity == NULL) return; + GasPhases[n_user] = *entity; } void removeGasPhase(int n_user) { GasPhases.erase(n_user); @@ -94,8 +98,9 @@ public: } return (NULL); } - void setSSassemblage(int n_user, cxxSSassemblage *entity) { - SSassemblages[n_user] = *entity; + void setSSassemblage(int n_user, cxxSSassemblage *entity) { + if (entity == NULL) return; + SSassemblages[n_user] = *entity; } void removeSSassemblage(int n_user) { SSassemblages.erase(n_user); @@ -107,21 +112,25 @@ public: } return (NULL); } - void setKinetics(int n_user, cxxKinetics *entity) { - Kinetics[n_user] = *entity; + void setKinetics(int n_user, cxxKinetics *entity) { + if (entity == NULL) return; + Kinetics[n_user] = *entity; } void removeKinetics(int n_user) { Kinetics.erase(n_user); } - cxxSurface *getSurface(int n_user) { - if (this->Surfaces.find(n_user) != this->Surfaces.end()) { - return(&(this->Surfaces.find(n_user)->second)); - } - return (NULL); + cxxSurface *getSurface(int n_user) + { + if (this->Surfaces.find(n_user) != this->Surfaces.end()) + { + return(&(this->Surfaces.find(n_user)->second)); + } + return (NULL); } - void setSurface(int n_user, cxxSurface *entity) { - Surfaces[n_user] = *entity; + void setSurface(int n_user, cxxSurface *entity) { + if (entity == NULL) return; + Surfaces[n_user] = *entity; } void removeSurface(int n_user) { Surfaces.erase(n_user); @@ -137,9 +146,17 @@ public: struct system *cxxStorageBin2system(int i); - cxxSolution *mix_cxxSolutions(cxxMix &mixmap); + //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix &mixmap); + const std::map& getSolutions()const {return this->Solutions;}; + const std::map& getExchangers()const {return this->Exchangers;}; + const std::map& getGasPhases()const {return this->GasPhases;}; + const std::map& getKinetics()const {return this->Kinetics;}; + const std::map& getPPassemblages()const {return this->PPassemblages;}; + const std::map& getSSassemblages()const {return this->SSassemblages;}; + const std::map& getSurfaces()const {return this->Surfaces;}; + #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); diff --git a/Surface.cxx b/Surface.cxx index 4cc8fab7..a859cd40 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -25,17 +25,17 @@ cxxSurface::cxxSurface() // : cxxNumKeyword() { - type = NO_EDL; + type = DDL; dl_type = NO_DL; sites_units = SITES_ABSOLUTE; //diffuse_layer = false; //edl = false; only_counter_ions = false; //donnan = false; - thickness = 0.0; + thickness = 1e-8; debye_lengths = 0.0; - DDL_viscosity = 0.0; - DDL_limit = 0.0; + DDL_viscosity = 1.0; + DDL_limit = 0.8; transport = false; } @@ -75,6 +75,34 @@ cxxNumKeyword() surfaceCharges.push_back(ec); } } +cxxSurface::cxxSurface(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + type = DDL; + dl_type = NO_DL; + sites_units = SITES_ABSOLUTE; + only_counter_ions = false; + thickness = 1e-8; + debye_lengths = 0.0; + DDL_viscosity = 1.0; + DDL_limit = 0.8; + transport = false; +// +// Mix exchangers +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxSurface *entity_ptr = &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } +} cxxSurface::~cxxSurface() { @@ -141,7 +169,19 @@ struct surface *cxxSurface::cxxSurface2surface() } else { surface_ptr->count_charge = 0; } - + // Need to fill in charge (number) in comps list + int i,j; + for (i = 0; i < surface_ptr->count_comps; i++) { + char *charge_name = cxxSurfaceComp::get_charge_name(surface_ptr->comps[i].formula); + for (j = 0; j < surface_ptr->count_charge; j++) { + if (charge_name == surface_ptr->charge[j].name) { + surface_ptr->comps[i].charge = j; + break; + } + } + assert(j < surface_ptr->count_charge); + } + return(surface_ptr); } @@ -632,3 +672,97 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif + +void cxxSurface::totalize() +{ + this->totals.clear(); + // component structures + for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) + { + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; +} + +void cxxSurface::add(const cxxSurface &addee, double extensive) + // + // Add surface to "this" exchange + // +{ + //std::list surfaceComps; + //std::list surfaceCharges; + //enum SURFACE_TYPE type; + //enum DIFFUSE_LAYER_TYPE dl_type; + //enum SITES_UNITS sites_units; + //bool only_counter_ions; + //double thickness; + //double debye_lengths; + //double DDL_viscosity; + //double DDL_limit; + //bool transport; + if (extensive == 0.0) return; + if (this->surfaceComps.size() == 0) + { + //enum SURFACE_TYPE type; + this->type = addee.type; + //enum DIFFUSE_LAYER_TYPE dl_type; + this->dl_type = addee.dl_type; + //enum SITES_UNITS sites_units; + this->sites_units = addee.sites_units; + //bool only_counter_ions; + this->only_counter_ions = addee.only_counter_ions; + //double thickness; + this->thickness = addee.thickness; + //double debye_lengths; + this->debye_lengths = addee.debye_lengths; + //double DDL_viscosity; + this->DDL_viscosity = addee.DDL_viscosity; + //double DDL_limit; + this->DDL_limit = addee.DDL_limit; + //bool transport; + this->transport = addee.transport; + } + //std::list surfaceComps; + + for (std::list::const_iterator itadd = addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); ++itadd) + { + bool found = false; + for (std::list::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + { + if (it->get_formula() == itadd->get_formula()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) { + cxxSurfaceComp entity = *itadd; + entity.multiply(extensive); + //exc.add(*itadd, extensive); + this->surfaceComps.push_back(entity); + } + } + //std::list surfaceCharges; + for (std::list::const_iterator itadd = addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); ++itadd) + { + bool found = false; + for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) { + cxxSurfaceCharge entity = *itadd; + entity.multiply(extensive); + //exc.add(*itadd, extensive); + this->surfaceCharges.push_back(entity); + } + } + +} + diff --git a/Surface.h b/Surface.h index 26a8362b..f14d2d91 100644 --- a/Surface.h +++ b/Surface.h @@ -13,6 +13,7 @@ #include "char_star.h" #include "SurfaceComp.h" #include "SurfaceCharge.h" +#include "cxxMix.h" class cxxSurface : public cxxNumKeyword { @@ -20,6 +21,7 @@ class cxxSurface : public cxxNumKeyword public: cxxSurface(); cxxSurface(struct surface *); + cxxSurface(const std::map &entity_map, cxxMix &mx, int n_user); ~cxxSurface(); //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; @@ -39,11 +41,20 @@ public: bool get_related_phases(void); bool get_related_rate(void); + + void totalize(); + + const cxxNameDouble& get_totals()const + { + return this->totals; + }; #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif +private: + void add(const cxxSurface &addee, double extensive); protected: std::list surfaceComps; @@ -57,6 +68,7 @@ protected: double DDL_viscosity; double DDL_limit; bool transport; + cxxNameDouble totals; public: //static std::map& map; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 99c44d8e..68d61293 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -423,3 +423,62 @@ void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxSurfaceCharge::add(const cxxSurfaceCharge &addee, double extensive) +{ + if (extensive == 0.0) return; + //char * name; + //double specific_area; + //double grams; + //double charge_balance; + //double mass_water; + //double la_psi, la_psi1, la_psi2; + //double capacitance[2]; + + //char * name; + if (this->name == NULL && addee.name == NULL) { + return; + } + assert (this->name == addee.name); + + double ext1, ext2, f1, f2; + ext1 = this->specific_area * this->grams; + ext2 = addee.specific_area * addee.grams * extensive; + if (ext1 + ext2 != 0) { + f1 = ext1/(ext1 + ext2); + f2 = ext2/(ext1 + ext2); + } else { + f1 = 0.5; + f2 = 0.5; + } + + //double specific_area; + this->specific_area = f1*this->specific_area + f2*addee.specific_area; + //double grams; + this->grams += addee.grams * extensive; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //double mass_water; + this->mass_water += addee.mass_water * extensive; + //double la_psi, la_psi1, la_psi2; + this->la_psi = this->la_psi*f1 + addee.la_psi*f2; + this->la_psi1 = this->la_psi1*f1 + addee.la_psi1*f2; + this->la_psi2 = this->la_psi2*f1 + addee.la_psi2*f2; + //double capacitance[2]; + this->capacitance[0] = this->capacitance[0]*f1 + this->capacitance[0]*f2; + this->capacitance[1] = this->capacitance[1]*f1 + this->capacitance[1]*f2; +} +void cxxSurfaceCharge::multiply(double extensive) +{ + //char * name; + //double specific_area; + //double grams; + this->grams *= extensive; + //double charge_balance; + this->charge_balance *= extensive; + //double mass_water; + this->mass_water *= extensive; + //double la_psi, la_psi1, la_psi2; + //double capacitance[2]; + //cxxNameDouble diffuse_layer_totals; + this->diffuse_layer_totals.multiply(extensive); +} diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 0a761b35..a5d68890 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -32,6 +32,11 @@ public: void read_raw(CParser& parser); + char *get_name()const {return this->name;} + + void add(const cxxSurfaceCharge &comp, double extensive); + void multiply(double extensive); + #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index f59650fc..ceec1387 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -30,7 +30,7 @@ cxxSurfaceComp::cxxSurfaceComp() moles = 0.0; totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; - charge_number = -99; + //charge_number = -99; charge_balance = 0; phase_name = NULL; phase_proportion = 0.0; @@ -50,7 +50,7 @@ totals(surf_comp_ptr->totals) formula_z = surf_comp_ptr->formula_z; moles = surf_comp_ptr->moles; la = surf_comp_ptr->la; - charge_number = surf_comp_ptr->charge; + //charge_number = surf_comp_ptr->charge; charge_balance = surf_comp_ptr->cb; phase_name = surf_comp_ptr->phase_name; phase_proportion = surf_comp_ptr->phase_proportion; @@ -107,7 +107,7 @@ struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::listget_master(); surf_comp_ptr[i].totals = it->totals.elt_list(); surf_comp_ptr[i].la = it->la; - surf_comp_ptr[i].charge = it->charge_number; + //surf_comp_ptr[i].charge = it->charge_number; surf_comp_ptr[i].cb = it->charge_balance; surf_comp_ptr[i].phase_name = it->phase_name; surf_comp_ptr[i].phase_proportion = it->phase_proportion; @@ -135,7 +135,7 @@ void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << std::endl; s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; - s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; + //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; if (this->phase_name != NULL) { s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; @@ -174,7 +174,7 @@ void cxxSurfaceComp::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent0 << "-formula_z " << this->formula_z << std::endl; s_oss << indent0 << "-moles " << this->moles << std::endl; s_oss << indent0 << "-la " << this->la << std::endl; - s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; + //s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; if (this->phase_name != NULL) { s_oss << indent0 << "-phase_name " << this->phase_name << std::endl; @@ -227,7 +227,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) bool formula_defined(false); bool moles_defined(false); bool la_defined(false); - bool charge_number_defined(false); + //bool charge_number_defined(false); bool charge_balance_defined(false); bool formula_z_defined(false); bool Dw_defined(false); @@ -285,7 +285,7 @@ void cxxSurfaceComp::read_raw(CParser& parser) } la_defined = true; break; - +#ifdef SKIP case 3: // charge_number if (!(parser.get_iss() >> this->charge_number)) { @@ -294,8 +294,8 @@ void cxxSurfaceComp::read_raw(CParser& parser) parser.error_msg("Expected integer value for charge_number.", CParser::OT_CONTINUE); } charge_number_defined = true; - break; - + break; +#endif case 4: // charge_balance if (!(parser.get_iss() >> this->charge_balance)) { @@ -392,10 +392,12 @@ void cxxSurfaceComp::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("La not defined for SurfaceComp input.", CParser::OT_CONTINUE); } +#ifdef SKIP if (charge_number_defined == false) { parser.incr_input_error(); parser.error_msg("Charge_number not defined for SurfaceComp input.", CParser::OT_CONTINUE); } +#endif if (charge_balance_defined == false) { parser.incr_input_error(); parser.error_msg("Charge_balance not defined for SurfaceComp input.", CParser::OT_CONTINUE); @@ -417,7 +419,7 @@ void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubl doubles.push_back(this->moles); this->totals.mpi_pack(ints, doubles); doubles.push_back(this->la); - ints.push_back(charge_number); + //ints.push_back(charge_number); doubles.push_back(this->charge_balance); ints.push_back(dictionary.string2int(this->phase_name)); doubles.push_back(this->phase_proportion); @@ -435,7 +437,7 @@ void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->moles = doubles[d++]; this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; - this->charge_number = ints[i++]; + //this->charge_number = ints[i++]; this->charge_balance = doubles[d++]; this->phase_name = dictionary.int2char(ints[i++]); this->phase_proportion = doubles[d++]; @@ -445,3 +447,96 @@ void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxSurfaceComp::add(const cxxSurfaceComp &addee, double extensive) +{ + if (extensive == 0.0) return; + if (addee.formula == NULL) return; + + //char * formula; + //cxxNameDouble formula_totals; + if (this->formula == NULL && addee.formula == NULL) { + return; + } + assert (this->formula == addee.formula); + assert (this->formula_z == addee.formula_z); + if (this->formula == NULL && addee.formula != NULL) { + this->formula = addee.formula; + this->formula_totals = addee.formula_totals; + } + + // this and addee must have same formula + // otherwise generate a new exchcomp with multiply + double ext1, ext2, f1, f2; + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) { + f1 = ext1/(ext1 + ext2); + f2 = ext2/(ext1 + ext2); + } else { + f1 = 0.5; + f2 = 0.5; + } + //double formula_z; + + //double moles; + this->moles += addee.moles * extensive; + //cxxNameDouble totals; + this->totals.add_extensive(addee.totals, extensive); + //double la; + this->la = f1*this->la + f2*addee.la; + //int charge_number; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //char *phase_name; + + if (this->phase_name != addee.phase_name) { + std::ostringstream oss; + oss << "Can not mix two Surface components with same formula and different related phases, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } else if (this->phase_name != NULL) { + this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; + } + + //char *rate_name; + if (this->rate_name != addee.rate_name) { + std::ostringstream oss; + oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } else if (this->rate_name != NULL) { + //double phase_proportion; + this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; + } + if ((this->rate_name != NULL && addee.phase_name != NULL) || + (this->phase_name != NULL && addee.rate_name != NULL) ) + { + std::ostringstream oss; + oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + //double Dw; + +} +void cxxSurfaceComp::multiply(double extensive) +{ + //char * formula; + //cxxNameDouble formula_totals; + //double formula_z; + //double moles; + this->moles *= extensive; + //cxxNameDouble totals; + this->totals.multiply(extensive); + //double la; + //int charge_number; + //double charge_balance; + this->charge_balance *= extensive; + //char *phase_name; + //double phase_proportion; + //char *rate_name; + //double Dw; +} diff --git a/SurfaceComp.h b/SurfaceComp.h index 9ccef087..4eec084f 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -4,6 +4,7 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" +#include "phrqproto.h" #include // assert #include // std::map #include // std::string @@ -12,7 +13,7 @@ #include "char_star.h" -class cxxSurfaceComp +class cxxSurfaceComp { public: @@ -25,6 +26,7 @@ public: struct master *get_master(); char *get_phase_name()const {return this->phase_name;} char *get_rate_name()const {return this->rate_name;} + char *get_formula()const {return this->formula;} static struct surface_comp *cxxSurfaceComp2surface_comp(std::list& el); @@ -33,6 +35,29 @@ public: void dump_raw(std::ostream& s_oss, unsigned int indent)const; void read_raw(CParser& parser); + const cxxNameDouble &get_totals()const + { + return (this->totals); + }; + + + void add(const cxxSurfaceComp &comp, double extensive); + void multiply(double extensive); + + char *charge_name() {return(get_charge_name(this->formula));}; + + static char *get_charge_name(char * token) { + char name[100]; + int l; + char *ptr1 = token; + get_elt (&ptr1, name, &l); + ptr1 = strchr (name, '_'); + if (ptr1 != NULL) + { + ptr1[0] = '\0'; + } + return(string_hsave(name)); + }; #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); @@ -41,12 +66,12 @@ public: protected: char * formula; - cxxNameDouble formula_totals; + cxxNameDouble formula_totals; double formula_z; double moles; - cxxNameDouble totals; + cxxNameDouble totals; double la; - int charge_number; + //int charge_number; double charge_balance; char *phase_name; double phase_proportion; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index c583a0cc..a593f41b 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -61,7 +61,30 @@ totals(kinetics_ptr->totals) this->steps.push_back(kinetics_ptr->steps[i]); } } - +cxxKinetics::cxxKinetics(const std::map &entities, cxxMix &mix, int n_user) +: +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + step_divide = 1.0; + rk = 3; + bad_step_max = 500; + use_cvode = false; + totals.type = cxxNameDouble::ND_ELT_MOLES; +// +// Mix +// + std::map *mixcomps = mix.comps(); + std::map::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxKinetics *entity_ptr = &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } +} cxxKinetics::~cxxKinetics() { } @@ -390,3 +413,40 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +void cxxKinetics::add(const cxxKinetics &addee, double extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // +{ + if (extensive == 0.0) return; + //std::list kineticsComps; + for (std::list::const_iterator itadd = addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); ++itadd) + { + bool found = false; + for (std::list::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); ++it) + { + if (it->get_rate_name() == itadd->get_rate_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) { + cxxKineticsComp entity = *itadd; + entity.multiply(extensive); + this->kineticsComps.push_back(entity); + } + } + //std::vector steps; + this->steps = addee.steps; + //cxxNameDouble totals; + //double step_divide; + this->step_divide = addee.step_divide; + //int rk; + this->rk = addee.rk; + //int bad_step_max; + this->bad_step_max = addee.bad_step_max; + //bool use_cvode; + this->use_cvode = addee.use_cvode; +} diff --git a/cxxKinetics.h b/cxxKinetics.h index 525f937a..2bf75b83 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -12,6 +12,7 @@ #include "char_star.h" #include "KineticsComp.h" +#include "cxxMix.h" class cxxKinetics : public cxxNumKeyword { @@ -19,7 +20,8 @@ class cxxKinetics : public cxxNumKeyword public: cxxKinetics(); cxxKinetics(struct kinetics *); - ~cxxKinetics(); + cxxKinetics(const std::map &entity_map, cxxMix &mx, int n_user); + ~cxxKinetics(); struct kinetics *cxxKinetics2kinetics(); @@ -39,6 +41,8 @@ public: void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector& ints, std::vector& doubles); #endif +private: + void add(const cxxKinetics &addee, double extensive); protected: std::list kineticsComps; From a7a19e57f4aaf85bc4feb27cd574ae88a5b3a84f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 May 2007 21:59:00 +0000 Subject: [PATCH 0054/1077] Still has problems, but roughed in xsolution_save and xexchange_save as constructor methods for Solution and Exchange. Takes c storage and makes C++ objects after a calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2062 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.h | 31 +++++++- Exchange.cxx | 80 ++++++++++++++++++++- Exchange.h | 1 + GasPhase.cxx | 2 +- ISolution.cxx | 2 +- NameDouble.cxx | 16 +++++ NameDouble.h | 1 + Solution.cxx | 178 ++++++++++++++++++++++++++++++++++------------ Solution.h | 1 + SolutionIsotope.h | 8 ++- 10 files changed, 268 insertions(+), 52 deletions(-) diff --git a/ExchComp.h b/ExchComp.h index 36da25ae..640872d2 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -21,9 +21,6 @@ public: ~cxxExchComp(); struct master *get_master(); - char *get_formula()const {return this->formula;} - char *get_phase_name()const {return this->phase_name;} - char *get_rate_name()const {return this->rate_name;} static struct exch_comp *cxxExchComp2exch_comp(std::list& el); @@ -33,6 +30,34 @@ public: void read_raw(CParser& parser); + char * get_formula()const { return this->formula;} + void set_formula(char * cstring) { this->formula = cstring;} + double get_moles()const { return this->moles;} + void set_moles(double d) { this->moles = d;} + double get_la()const { return this->la;} + void set_la(double d) { this->la = d;} + double get_charge_balance()const { return this->charge_balance;} + void set_charge_balance(double d) { this->charge_balance = d;} + char * get_phase_name()const { return this->phase_name;} + void set_phase_name(char * cstring) { this->phase_name = cstring;} + double get_phase_proportion()const { return this->phase_proportion;} + void set_phase_proportion(double d) { this->phase_proportion = d;} + char * get_rate_name()const { return this->rate_name;} + void set_rate_name(char * cstring) { this->rate_name = cstring;} + double get_formula_z()const { return this->formula_z;} + void set_formula_z(double d) { this->formula_z = d;} + void set_totals(struct elt_list *e_l, int count) + {this->totals = cxxNameDouble(e_l, count);} + void set_totals(struct elt_list *e_l) + {this->totals = cxxNameDouble(e_l);} + void set_totals(cxxNameDouble nd) + {this->totals = nd;} + void set_formula_totals(struct elt_list *e_l, int count) + {this->formula_totals = cxxNameDouble(e_l, count);} + void set_formula_totals(struct elt_list *e_l) + {this->formula_totals = cxxNameDouble(e_l);} + void set_formula_totals(cxxNameDouble nd) + {this->formula_totals = nd;} const cxxNameDouble &get_totals()const { diff --git a/Exchange.cxx b/Exchange.cxx index 4219d021..26cbcb05 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -85,6 +85,84 @@ cxxNumKeyword() } } +cxxExchange::cxxExchange(int n_user) + // + // constructor for cxxExchange from reaction calculation + // equivalent of xexchange_save + // std::list exchComps; + // bool pitzer_exchange_gammas; + // cxxNameDouble totals; + +: +cxxNumKeyword() + +{ + int i; + + //this->set_description(exchange_ptr->description); + this->n_user = n_user; + this->n_user_end = n_user; + this->pitzer_exchange_gammas = (use.exchange_ptr->pitzer_exchange_gammas == TRUE); + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == EXCH) + { + cxxExchComp ec; + //char * formula; + ec.set_formula (x[i]->exch_comp->formula); + //double moles; + ec.set_moles (0.0); + //cxxNameDouble formula_totals; + ec.set_formula_totals (x[i]->exch_comp->formula_totals); + //cxxNameDouble totals; see below + //double la; + ec.set_la (x[i]->master[0]->s->la); + //double charge_balance; see below + //char *phase_name; + ec.set_phase_name (x[i]->exch_comp->phase_name); + //double phase_proportion; + ec.set_phase_proportion (x[i]->exch_comp->phase_proportion); + //char *rate_name; + ec.set_rate_name (x[i]->exch_comp->rate_name); + //double formula_z; + ec.set_formula_z (x[i]->exch_comp->formula_z); + + // calculate charge and totals + count_elts = 0; + paren_count = 0; + double charge = 0.0; + int j; + for (j = 0; j < count_species_list; j++) + { + if (species_list[j].master_s == x[i]->master[0]->s) + { + add_elt_list (species_list[j].s->next_elt, + species_list[j].s->moles); + charge += species_list[j].s->moles * species_list[j].s->z; + } + } + // Keep exchanger related to phase even if none currently in solution + if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) + { + add_elt_list (x[i]->master[0]->s->next_elt, 1e-20); + } + //double charge_balance + ec.set_charge_balance (charge); + //cxxNameDouble totals; + if (count_elts > 0) + { + qsort (elt_list, (size_t) count_elts, + (size_t) sizeof (struct elt_list), elt_list_compare); + elt_list_combine (); + } + ec.set_totals(elt_list, count_elts); + + // add to comp list + this->exchComps.push_back(ec); + } + } +} cxxExchange::~cxxExchange() { } @@ -330,4 +408,4 @@ void cxxExchange::totalize() this->totals.add_extensive(it->get_totals(), 1.0); } return; -} \ No newline at end of file +} diff --git a/Exchange.h b/Exchange.h index 44687df6..bd93feca 100644 --- a/Exchange.h +++ b/Exchange.h @@ -16,6 +16,7 @@ class cxxExchange : public cxxNumKeyword public: cxxExchange(); + cxxExchange(int n_user); cxxExchange(struct exchange *); cxxExchange(const std::map &exchange_map, cxxMix &mx, int n_user); ~cxxExchange(); diff --git a/GasPhase.cxx b/GasPhase.cxx index 2ce9229b..4fb9a46c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -381,4 +381,4 @@ void cxxGasPhase::totalize() } } return; -} \ No newline at end of file +} diff --git a/ISolution.cxx b/ISolution.cxx index 17a03401..5e1692cf 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -885,4 +885,4 @@ void cxxISolution::ORCH_write_output(std::ostringstream &outstream) } outstream << std::endl; return; -} \ No newline at end of file +} diff --git a/NameDouble.cxx b/NameDouble.cxx index 301b9569..af5b5087 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -41,6 +41,22 @@ cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr) } this->type = ND_ELT_MOLES; } + +cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count) + // + // constructor for cxxNameDouble from list of elt_list with known count + // +{ + int i; + if (elt_list_ptr != NULL) { + for (i = 0; i < count; i++) + { + (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; + } + } + this->type = ND_ELT_MOLES; +} + cxxNameDouble::cxxNameDouble(const cxxNameDouble &old, double factor) // // constructor for cxxNameDouble from list of elt_list diff --git a/NameDouble.h b/NameDouble.h index 83754583..e0098bfe 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -24,6 +24,7 @@ public: cxxNameDouble(); cxxNameDouble(struct elt_list *); + cxxNameDouble(struct elt_list *, int count); cxxNameDouble(struct conc *); cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); cxxNameDouble(struct name_coef *nc, int count); diff --git a/Solution.cxx b/Solution.cxx index 64b851d8..9ec66220 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -113,6 +113,140 @@ cxxNumKeyword() } } +cxxSolution::cxxSolution(int n_user) + // + // constructor for cxxSolution from results of calculation + // +: +cxxNumKeyword() +{ + + //this->set_description none; + this->n_user = n_user; + this->n_user_end = n_user; + this->tc = tc_x; + this->ph = ph_x; + this->pe = solution_pe_x; + this->mu = mu_x; + this->ah2o = ah2o_x; + this->total_h = total_h_x; + this->total_o = total_o_x; + this->cb = cb_x; + this->mass_water = mass_water_aq_x; + this->total_alkalinity = total_alkalinity; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + /* + * Add in minor isotopes if initial solution calculation + */ + int i; + if (initial_solution_isotopes == TRUE) + { + struct master *master_ptr, *master_i_ptr; + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->moles > 0) + { + master_i_ptr = master_bsearch (master_isotope[i]->name); + master_ptr = master_isotope[i]->elt->master; + if (master_isotope[i]->minor_isotope == TRUE) + { + master_i_ptr->total = master_isotope[i]->moles; + if (master_ptr->total > 0) + { + master_i_ptr->s->la = + master_ptr->s->la + + log10 (master_i_ptr->total / master_ptr->total); + } + else + { + master_i_ptr->s->la = master_ptr->s->la; + } + } + else if (master_isotope[i]->minor_isotope == FALSE + && master_ptr->s != s_hplus && master_ptr->s != s_h2o) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr->s->secondary->total = master_isotope[i]->moles; + } + else + { + master_ptr->s->primary->total = master_isotope[i]->moles; + } + } + } + } + } + /* + cxxNameDouble totals; + cxxNameDouble master_activity; + cxxNameDouble species_gamma; + cxxSolutionIsotopeList isotopes; + */ + +// totals and master_activity + for (i = 0; i < count_master; i++) + { + if (master[i]->s->type == EX || + master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + continue; + if (master[i]->s == s_hplus) continue; + if (master[i]->s == s_h2o) continue; + if (master[i]->in != FALSE) + { + this->master_activity[master[i]->elt->name] = master[i]->s->la; + } + if (master[i]->total <= MIN_TOTAL) + { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + continue; + } + this->totals[master[i]->elt->name] = master[i]->total; + } + +// species_gammas for Pitzer + if (pitzer_model == TRUE) + { + int j; + for (j = 0; j < count_s; j++) + { + if (s[j]->lg != 0.0) + { + this->species_gamma[s[j]->name] = s[j]->lg; + } + } + } + +// Save isotope data + + if (count_isotopes_x > 0) + { + for (i = 0; i < count_isotopes_x; i++) + { + cxxSolutionIsotope cxxiso; + cxxiso.set_isotope_number (isotopes_x[i].isotope_number); + cxxiso.set_elt_name (isotopes_x[i].elt_name); + cxxiso.set_isotope_name (isotopes_x[i].isotope_name); + cxxiso.set_total (isotopes_x[i].master->total); + if (isotopes_x[i].master == s_hplus->secondary) + { + cxxiso.set_total (2 * mass_water_aq_x / gfw_water); + } + if (isotopes_x[i].master == s_h2o->secondary) + { + cxxiso.set_total (mass_water_aq_x / gfw_water); + } + // cxxiso.ratio + // cxxiso.ratio_uncertainty + // cxxiso.ratio_uncertainty_defined + this->isotopes.push_back(cxxiso); + } + } +} + cxxSolution::~cxxSolution() { } @@ -1057,50 +1191,6 @@ void cxxSolution::set_master_activity(char *string, double d) { this->master_activity[string] = d; } -#ifdef SKIP -#include "../hst.h" -/* ---------------------------------------------------------------------- */ -void cxxSolution::xsolution_save(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save solution composition into Solution class - * - * input: n is pointer number in solution - */ - this->set_description(" "); - this->n_user = n; - this->n_user_end = n; - this->tc = tc_x; - this->ph = ph_x; - this->pe = solution_pe_x; - this->mu = mu_x; - this->ah2o = ah2o_x; - this->total_h = total_h_x; - this->total_o = total_o_x; - this->cb = cb_x; - this->mass_water = mass_water_aq_x; - this->total_alkalinity = total_alkalinity; -/* - * Copy totals data - */ - for (int j = 2; j < count_total; j++) { - this->totals.insert(buffer[j].master->elt->name, buffer[j].master->total_primary); - } - - for (int j = 0; j < count_activity_list; j++) { - this->master_activity.insert(activity_list[j].master->elt->name, activity_list[j].master->s->la); - } - if (pitzer_model == TRUE) { - for (int j= 0; j < count_s; j++) { - if (s[j]->lg != 0.0) { - this->species_gamma.insert(s[j]->name, s[j]->lg); - } - } - } -} -#endif - #include "ISolution.h" #include "Exchange.h" diff --git a/Solution.h b/Solution.h index 967623c3..b4045052 100644 --- a/Solution.h +++ b/Solution.h @@ -22,6 +22,7 @@ class cxxSolution : public cxxNumKeyword public: cxxSolution(); cxxSolution(struct solution *); + cxxSolution(int n_user); cxxSolution(const std::map &solution_map, cxxMix &mx, int n_user); ~cxxSolution(); diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 43f1ccf4..7efdfbdc 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -27,10 +27,14 @@ public: CParser::STATUS_TYPE read_raw(CParser& parser); - char * get_isotope_name()const { return this->isotope_name;} - void set_isotope_name(char * cstring) { this->isotope_name = cstring;} + double get_isotope_number()const { return this->isotope_number;} + void set_isotope_number(double d) { this->isotope_number = d;} char * get_elt_name()const { return this->elt_name;} void set_elt_name(char * cstring) { this->elt_name = cstring;} + char * get_isotope_name()const { return this->isotope_name;} + void set_isotope_name(char * cstring) { this->isotope_name = cstring;} + double get_total()const { return this->total;} + void set_total(double d) { this->total = d;} double get_ratio()const { return this->ratio; } From 8a84d79562ead5313fdb96ef394072a13df91139 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 May 2007 22:48:39 +0000 Subject: [PATCH 0055/1077] End of line for now, have solution and exchange saving from c storage after calculation. However, phast uses slightly different storage for total elements in buffer, not individual redox states. Have not done surface, equilibrium_phases, gas, solid solutions, kinetics equivalent of x_save. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2063 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 9ec66220..6e3e834e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -116,7 +116,8 @@ cxxNumKeyword() cxxSolution::cxxSolution(int n_user) // // constructor for cxxSolution from results of calculation - // + // does not work in phast because phast uses only the total molalities + // of elements in buffer, not individual redox states. : cxxNumKeyword() { @@ -133,7 +134,7 @@ cxxNumKeyword() this->total_o = total_o_x; this->cb = cb_x; this->mass_water = mass_water_aq_x; - this->total_alkalinity = total_alkalinity; + this->total_alkalinity = ::total_alkalinity; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; From 4145b60e10770661815b90b27b1c514710eeb38c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Jun 2007 19:25:10 +0000 Subject: [PATCH 0056/1077] Fixes for cxx version of xsolution_save (constructor(n_user)) git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2066 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 20 +++++++++++++++++++- Solution.h | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index 6e3e834e..83c477be 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -917,7 +917,25 @@ double cxxSolution::get_total(char *string)const return(it->second); } } - +double cxxSolution::get_total_element(char *string)const +{ + cxxNameDouble::const_iterator it; + double d = 0.0; + for (it = this->totals.begin(); it != this->totals.end(); ++it) + { + char token[MAX_LENGTH], token1[MAX_LENGTH]; + int n; + char *ptr; + strcpy(token, it->first); + replace("(", "", token); + ptr = token; + copy_token(token1, &ptr, &n); + if (strcmp(token1, string) == 0) { + d += it->second; + } + } + return(d); +} void cxxSolution::set_total(char *string, double d) { this->totals[string] = d; diff --git a/Solution.h b/Solution.h index b4045052..89c7f377 100644 --- a/Solution.h +++ b/Solution.h @@ -59,8 +59,13 @@ public: void set_total_alkalinity(double total_alkalinity) {this->total_alkalinity = total_alkalinity;} double get_total(char *string)const; + double get_total_element(char *string)const; void set_total(char *string, double value); + void set_totals(cxxNameDouble &nd) {this->totals = nd; this->totals.type = cxxNameDouble::ND_ELT_MOLES;} + void clear_totals() {this->totals.clear();} + + double get_master_activity(char *string)const; void set_master_activity(char *string, double value); From 0bebfae5a5b3fd35c928862fb6f0b989478ce644 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Jun 2007 22:49:27 +0000 Subject: [PATCH 0057/1077] Fixed bug in get_total_element git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2067 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 83c477be..3b677a16 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -247,12 +247,9 @@ cxxNumKeyword() } } } - cxxSolution::~cxxSolution() { } - - struct solution *cxxSolution::cxxSolution2solution() // // Builds a solution structure from instance of cxxSolution @@ -927,7 +924,7 @@ double cxxSolution::get_total_element(char *string)const int n; char *ptr; strcpy(token, it->first); - replace("(", "", token); + replace("(", " ", token); ptr = token; copy_token(token1, &ptr, &n); if (strcmp(token1, string) == 0) { From b2dd9ad8d1e94e5fa1149561023c249eb1185e95 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 15 Jun 2007 19:46:31 +0000 Subject: [PATCH 0058/1077] Simplified test for missing solution. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2077 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 3b677a16..f5310e28 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -101,15 +101,17 @@ cxxNumKeyword() std::map::const_iterator it; for (it = mixcomps->begin(); it != mixcomps->end(); it++) { - const cxxSolution *cxxsoln_ptr1 = &(solutions.find(it->first)->second); - if (cxxsoln_ptr1 == NULL) + std::map::const_iterator sol = solutions.find(it->first); + if (sol == solutions.end()) { sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); error_msg(error_string, CONTINUE); input_error++; - return; - } - this->add(*cxxsoln_ptr1, it->second); + } else + { + const cxxSolution *cxxsoln_ptr1 = &(sol->second); + this->add(*cxxsoln_ptr1, it->second); + } } } From c5d2d6d80d1addd205a66638a1d67d40578ea3cb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 15 Jun 2007 21:28:13 +0000 Subject: [PATCH 0059/1077] Fixed some warnings found by Studio (casts) mix.c is now obsolete and eliminated from project. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2079 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index a593f41b..94962dce 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -408,7 +408,7 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->step_divide = doubles[d++]; this->rk = ints[i++]; this->bad_step_max = ints[i++]; - this->use_cvode = (bool) ints[i++]; + this->use_cvode = (ints[i++] == TRUE); *ii = i; *dd = d; } From 1848045bd923f5e215a60a920d1c3d0ab43d7d9f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Jun 2007 19:50:55 +0000 Subject: [PATCH 0060/1077] Added new functions to allow multiply. Now multiply to account for changes in pore volume due to storage. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2098 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 14 ++++++++++++++ Solution.h | 1 + SolutionIsotope.cxx | 4 ++++ SolutionIsotope.h | 1 + SolutionIsotopeList.cxx | 7 +++++++ SolutionIsotopeList.h | 1 + 6 files changed, 28 insertions(+) diff --git a/Solution.cxx b/Solution.cxx index f5310e28..bad764ba 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -907,6 +907,20 @@ void cxxSolution::add(const cxxSolution &addee, double extensive) this->species_gamma.add_intensive(addee.species_gamma, f1, f2); this->isotopes.add(addee.isotopes, f2, extensive); } +void cxxSolution::multiply(double extensive) + // + // Multiply existing solution by extensive + // +{ + if (extensive == 0.0 || extensive == 1.0) return; + this->total_h *= extensive; + this->total_o *= extensive; + this->cb *= extensive; + this->mass_water *= extensive; + this->total_alkalinity *= extensive; + this->totals.multiply(extensive); + this->isotopes.multiply(extensive); +} double cxxSolution::get_total(char *string)const { cxxNameDouble::const_iterator it = this->totals.find(string); diff --git a/Solution.h b/Solution.h index 89c7f377..edadce15 100644 --- a/Solution.h +++ b/Solution.h @@ -83,6 +83,7 @@ public: void write_orchestra(std::ostream& headings, std::ostream& input_data)const; void read_raw(CParser& parser); + void multiply(double extensive); #ifdef USE_MPI diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 25be4d72..771645c2 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -197,6 +197,10 @@ void cxxSolutionIsotope::add(const cxxSolutionIsotope &isotope_ptr, double inten this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined || isotope_ptr.ratio_uncertainty_defined); } } +void cxxSolutionIsotope::multiply(double extensive) +{ + this->total *= extensive; +} #ifdef SKIP cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser& parser) diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 7efdfbdc..50c40eaf 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -48,6 +48,7 @@ public: struct master *primary(void); void add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive); + void multiply(double extensive); protected: friend class cxxSolutionIsotopeList; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 0bc81085..97ddda62 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -61,6 +61,13 @@ void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, d } } } +void cxxSolutionIsotopeList::multiply(double extensive) +{ + for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) + { + it->total *= extensive; + } +} struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() { struct isotope *iso; diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 6867e14c..21a40d8a 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -24,6 +24,7 @@ public: struct isotope *cxxSolutionIsotopeList2isotope(); void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); + void multiply(double extensive); protected: From ea61d055f01848e293939147c823b026a41c33eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 30 Jul 2007 15:07:20 +0000 Subject: [PATCH 0061/1077] Can read a solution result from Orchestra.cxx Now will write routines to put results into unknown structures so that results can be printed. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2166 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 150 +++++++++++++++++++++++++++++++++++++++++++++----- ISolution.h | 18 +++--- Solution.cxx | 84 ++++++++++++++++++++++++++-- Solution.h | 1 + 4 files changed, 224 insertions(+), 29 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 5e1692cf..dbc7e47c 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -30,6 +30,7 @@ units("mMol/kgw") { density = 1.0; default_pe = -1; + pes = NULL; } cxxISolution::cxxISolution(struct solution *solution_ptr) @@ -419,7 +420,7 @@ void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const } #endif -void cxxISolution::ORCH_write_chemistry(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry(std::ostream &chemistry_dat) { this->ORCH_write_chemistry_water(chemistry_dat); this->ORCH_write_chemistry_primary(chemistry_dat); @@ -430,7 +431,7 @@ void cxxISolution::ORCH_write_chemistry(std::ostringstream &chemistry_dat) } -void cxxISolution::ORCH_write_chemistry_water(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_water(std::ostream &chemistry_dat) { // // Write water entities @@ -488,7 +489,7 @@ void cxxISolution::ORCH_write_chemistry_water(std::ostringstream &chemistry_dat) chemistry_dat << std::endl; } -void cxxISolution::ORCH_write_chemistry_primary(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_primary(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* The primary species" << std::endl; // @@ -535,7 +536,7 @@ void cxxISolution::ORCH_write_chemistry_primary(std::ostringstream &chemistry_da chemistry_dat << std::endl; } -void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl; // Define total hydrogen, total oxygen, and difference @@ -587,7 +588,7 @@ void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostringstream &chemistry_ chemistry_dat << std::endl; } -void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Alkalinity definitions" << std::endl; // @@ -655,7 +656,7 @@ void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostringstream &chemistry } } } -void cxxISolution::ORCH_write_chemistry_species(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_species(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Aqueous species" << std::endl; // @@ -690,7 +691,7 @@ void cxxISolution::ORCH_write_chemistry_species(std::ostringstream &chemistry_da } chemistry_dat << std::endl; } -void cxxISolution::ORCH_write_chemistry_minerals(std::ostringstream &chemistry_dat) +void cxxISolution::ORCH_write_chemistry_minerals(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Adjustments to mineral equilibrium" << std::endl; // @@ -731,7 +732,7 @@ void cxxISolution::ORCH_write_chemistry_minerals(std::ostringstream &chemistry_d } } } -void cxxISolution::ORCH_write_input(std::ostringstream &input_dat) +void cxxISolution::ORCH_write_input(std::ostream &input_dat) { @@ -749,6 +750,8 @@ void cxxISolution::ORCH_write_input(std::ostringstream &input_dat) //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; //s_oss << "-temp " << this->tc << std::endl; + headings << "tempc\t"; + data << this->tc << "\t"; //s_oss << "-pH " << this->ph << std::endl; headings << "pH\t"; @@ -847,18 +850,39 @@ void cxxISolution::ORCH_write_input(std::ostringstream &input_dat) return; } -void cxxISolution::ORCH_write_output(std::ostringstream &outstream) +void cxxISolution::ORCH_write_output(std::ostream &outstream) { outstream << "Var:"; outstream << "\tnr_iter"; // - // Write total concentrations in solution + // Serialize solution // + outstream << "\tstart_solution"; + //tc + outstream << "\ttempc"; + //pH + outstream << "\tpH"; + //pe + outstream << "\tpe"; + //mu + outstream << "\tI"; + //ah2o + outstream << "\tH2O.act"; + //total_h; + outstream << "\ttotal_hydrogen"; + //total_o; + outstream << "\ttotal_oxygen"; + //cb + outstream << "\tchargebalance"; + //mass_water; outstream << "\tH2O.diss"; - outstream << "\te-.diss"; + //total_alkalinity; + outstream << "\tAlkalinity"; + //orchestra master variables outstream << "\tH+.diss"; - std::map::iterator iter = this->comps.begin(); - for(; iter != this->comps.end(); ++iter) + outstream << "\te-.diss"; + //totals + for(std::map::iterator iter = this->comps.begin(); iter != this->comps.end(); ++iter) { std::string name(iter->second.get_description()); if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; @@ -871,8 +895,21 @@ void cxxISolution::ORCH_write_output(std::ostringstream &outstream) assert(s_ptr != NULL); outstream << "\t" << s_ptr->name << ".diss"; } - outstream << "\tchargebalance"; - outstream<< "\tI"; + outstream << "\tend_totals"; + for(std::map::iterator iter = this->comps.begin(); iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + outstream << "\t" << s_ptr->name << ".act"; + } + outstream << "\tend_master_activities"; // // Write all species activities and concentrations // @@ -883,6 +920,89 @@ void cxxISolution::ORCH_write_output(std::ostringstream &outstream) std::replace(name.begin(), name.end(), ')', ']'); outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; } + outstream << "\tend_species"; outstream << std::endl; return; } +/* ---------------------------------------------------------------------- */ +int +initial_solutions (int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of solutions, make initial solution calculations + * for any marked "new". + */ + int i, converge, converge1; + int n, last, n_user, print1; + char token[2 * MAX_LENGTH]; + + state = INITIAL_SOLUTION; + set_use (); + for (n = 0; n < count_solution; n++) + { + initial_solution_isotopes = FALSE; + if (solution[n] != NULL && solution[n]->new_def == TRUE) + { + if (print1 == TRUE && print == TRUE) + { + dup_print ("Beginning of initial solution calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) + { + sprintf (token, "Initial solution %d.\t%.350s", solution[n]->n_user, + solution[n]->description); + dup_print (token, FALSE); + } + use.solution_ptr = solution[n]; + prep (); + k_temp (solution[n]->tc); + set (TRUE); + converge = model (); + if (converge == ERROR && diagonal_scale == FALSE) + { + diagonal_scale = TRUE; + set (TRUE); + converge = model (); + diagonal_scale = FALSE; + } + converge1 = check_residuals (); + sum_species (); + add_isotopes (solution[n]); + punch_all (); + print_all (); + /* free_model_allocs(); */ + if (converge == ERROR || converge1 == ERROR) + { + error_msg ("Model failed to converge for initial solution.", STOP); + } + n_user = solution[n]->n_user; + last = solution[n]->n_user_end; + /* copy isotope data */ + if (solution[n]->count_isotopes > 0) + { + count_isotopes_x = solution[n]->count_isotopes; + isotopes_x = + (struct isotope *) PHRQ_realloc (isotopes_x, + (size_t) count_isotopes_x * + sizeof (struct isotope)); + if (isotopes_x == NULL) + malloc_error (); + memcpy (isotopes_x, solution[n]->isotopes, + (size_t) count_isotopes_x * sizeof (struct isotope)); + } + else + { + count_isotopes_x = 0; + } + xsolution_save (n_user); + for (i = n_user + 1; i <= last; i++) + { + solution_duplicate (n_user, i); + } + } + } + initial_solution_isotopes = FALSE; + return (OK); +} diff --git a/ISolution.h b/ISolution.h index 8d516488..0a0a19d9 100644 --- a/ISolution.h +++ b/ISolution.h @@ -41,9 +41,9 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void ConvertUnits(); - void ORCH_write_chemistry(std::ostringstream &chemistry_dat); - void ORCH_write_input(std::ostringstream &input_dat); - void ORCH_write_output(std::ostringstream &input_dat); + void ORCH_write_chemistry(std::ostream &chemistry_dat); + void ORCH_write_input(std::ostream &input_dat); + void ORCH_write_output(std::ostream &input_dat); void print(); protected: friend class cxxISolutionComp; // for this->pe access @@ -57,12 +57,12 @@ public: //static std::map& map; private: - void ORCH_write_chemistry_water(std::ostringstream &chemistry_dat); - void ORCH_write_chemistry_primary(std::ostringstream &chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostringstream &chemistry_dat); - void ORCH_write_chemistry_alkalinity(std::ostringstream &chemistry_dat); - void ORCH_write_chemistry_species(std::ostringstream &chemistry_dat); - void ORCH_write_chemistry_minerals(std::ostringstream &chemistry_dat); + void ORCH_write_chemistry_water(std::ostream &chemistry_dat); + void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); + void ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat); + void ORCH_write_chemistry_species(std::ostream &chemistry_dat); + void ORCH_write_chemistry_minerals(std::ostream &chemistry_dat); }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/Solution.cxx b/Solution.cxx index bad764ba..672f7d3d 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -343,8 +343,8 @@ void cxxSolution::dump_xml(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "soln_total_o=\"" << this->total_o << "\"" << std::endl; - - s_oss << indent1; + + s_oss << indent1; s_oss << "soln_cb=\"" << this->cb << "\"" << std::endl; s_oss << indent1; @@ -446,7 +446,7 @@ void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "-total_o " << this->total_o << std::endl; - // new identifier + // new identifier s_oss << indent1; s_oss << "-cb " << this->cb << std::endl; @@ -819,7 +819,8 @@ void cxxSolution::read_raw(CParser& parser) break; } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } // all members must be defined if (tc_defined == false) { @@ -862,7 +863,7 @@ void cxxSolution::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Total alkalinity not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); } - return; + return; } void cxxSolution::zero() @@ -963,6 +964,79 @@ double cxxSolution::get_master_activity(char *string)const return(it->second); } } +void cxxSolution::read_orchestra(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) +{ + this->tc = it->second; it++; + this->ph = it->second; it++; + this->pe = it->second; it++; + this->mu = it->second; it++; + this->ah2o = it->second; it++; + this->total_h = it->second; it++; + this->total_o = it->second; it++; + this->cb = it->second; it++; + this->mass_water = it->second * gfw_water; it++; + this->total_alkalinity = it->second; it++; + it++; //orch total H+ + it++; //orch total e- + //cxxNameDouble totals; + char token[MAX_LENGTH]; + while (it->first.compare("end_totals") != 0) + { + strcpy(token, it->first.c_str()); + replace(".diss","",token); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); + if (s_ptr->secondary != NULL) + { + this->totals[s_ptr->secondary->elt->name] = it->second; + } else if (s_ptr->primary != NULL) + { + this->totals[s_ptr->primary->elt->name] = it->second; + } else + { + error_msg("Species not secondary or primary master species in orchestra read", STOP); + } + it++; + } + //cxxNameDouble master_activity; + it++; + while (it->first.compare("end_master_activities") != 0) + { + strcpy(token, it->first.c_str()); + replace(".act","",token); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); + if (s_ptr->secondary != NULL) + { + this->master_activity[s_ptr->secondary->elt->name] = log10(it->second); + } else if (s_ptr->primary != NULL) + { + this->master_activity[s_ptr->primary->elt->name] = log10(it->second); + } else + { + error_msg("Species not secondary or primary master species in orchestra read", STOP); + } + it++; + } + //cxxNameDouble species_gamma; + //cxxSolutionIsotopeList isotopes; + // + // Also process aqueous species data + // + it++; + while (it->first.compare("end_species") != 0) + { + strcpy(token, it->first.c_str()); + replace(".act","",token); + while (replace("[","(", token)); + while (replace("]",")", token)); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); + s_ptr->la = log10(it->second); it++; + s_ptr->lm = log10(it->second); it++; + s_ptr->lg = s_ptr->la - s_ptr->lm; + } +} #ifdef USE_MPI #include /* ---------------------------------------------------------------------- */ diff --git a/Solution.h b/Solution.h index edadce15..0f7b1310 100644 --- a/Solution.h +++ b/Solution.h @@ -84,6 +84,7 @@ public: void read_raw(CParser& parser); void multiply(double extensive); + void read_orchestra(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); #ifdef USE_MPI From 0f2ef116f2f9143e79e0ee20be308b8245d21c43 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 31 Jul 2007 19:07:25 +0000 Subject: [PATCH 0062/1077] Have version working that formats an input file for Orchestra, runs Orchestra with a system call to a batch file, reads results from Orchestra, stores results in global phreeqc storage, and prints results. Works only for initial solution calculation. Still some problems with the solver. Ex1 fails. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2167 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 108 ++++++++++++++------------------------------------ ISolution.h | 3 +- Solution.cxx | 5 ++- Solution.h | 4 +- 4 files changed, 36 insertions(+), 84 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index dbc7e47c..dc19c17f 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -788,7 +788,11 @@ void cxxISolution::ORCH_write_input(std::ostream &input_dat) master_ptr = master_bsearch (iter->first); assert (master_ptr != NULL); std::string ename(iter->first); - + double coef = master_ptr->coef; + if (master_ptr->coef == 0) + { + coef = 1; + } if (ename != "Alkalinity") { ename = master_ptr->s->name; @@ -798,14 +802,14 @@ void cxxISolution::ORCH_write_input(std::ostream &input_dat) if (iter->second.get_equation_name() == NULL) { headings << ename << "\t"; - data << (this->totals.find(iter->first))->second << "\t"; + data << (this->totals.find(iter->first))->second / coef << "\t"; } else { std::string name(iter->second.get_equation_name()); if (name == "charge") { headings << ename << "\t"; - data << (this->totals.find(iter->first))->second << "\t"; + data << (this->totals.find(iter->first))->second /coef << "\t"; } else { int n; @@ -924,85 +928,31 @@ void cxxISolution::ORCH_write_output(std::ostream &outstream) outstream << std::endl; return; } -/* ---------------------------------------------------------------------- */ -int -initial_solutions (int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through list of solutions, make initial solution calculations - * for any marked "new". - */ - int i, converge, converge1; - int n, last, n_user, print1; - char token[2 * MAX_LENGTH]; - state = INITIAL_SOLUTION; - set_use (); - for (n = 0; n < count_solution; n++) +void cxxISolution::ORCH_store_global(std::map < std::string, double > output_map) +{ + int i; + tc_x = this->tc; + mass_water_aq_x = this->mass_water; + mu_x = this->mu; + s_h2o->moles = output_map["H2O.con"]; + s_h2o->la = log10(output_map["H2O.act"]); + s_h2o->lm = s_h2o->la; + s_h2o->lg = 0; + for (i = 0; i < count_unknowns; i++) { - initial_solution_isotopes = FALSE; - if (solution[n] != NULL && solution[n]->new_def == TRUE) + residual[i] = 0; + // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O + switch (x[i]->type) { - if (print1 == TRUE && print == TRUE) - { - dup_print ("Beginning of initial solution calculations.", TRUE); - print1 = FALSE; - } - if (print == TRUE) - { - sprintf (token, "Initial solution %d.\t%.350s", solution[n]->n_user, - solution[n]->description); - dup_print (token, FALSE); - } - use.solution_ptr = solution[n]; - prep (); - k_temp (solution[n]->tc); - set (TRUE); - converge = model (); - if (converge == ERROR && diagonal_scale == FALSE) - { - diagonal_scale = TRUE; - set (TRUE); - converge = model (); - diagonal_scale = FALSE; - } - converge1 = check_residuals (); - sum_species (); - add_isotopes (solution[n]); - punch_all (); - print_all (); - /* free_model_allocs(); */ - if (converge == ERROR || converge1 == ERROR) - { - error_msg ("Model failed to converge for initial solution.", STOP); - } - n_user = solution[n]->n_user; - last = solution[n]->n_user_end; - /* copy isotope data */ - if (solution[n]->count_isotopes > 0) - { - count_isotopes_x = solution[n]->count_isotopes; - isotopes_x = - (struct isotope *) PHRQ_realloc (isotopes_x, - (size_t) count_isotopes_x * - sizeof (struct isotope)); - if (isotopes_x == NULL) - malloc_error (); - memcpy (isotopes_x, solution[n]->isotopes, - (size_t) count_isotopes_x * sizeof (struct isotope)); - } - else - { - count_isotopes_x = 0; - } - xsolution_save (n_user); - for (i = n_user + 1; i <= last; i++) - { - solution_duplicate (n_user, i); - } + case MB: + case CB: + case SOLUTION_PHASE_BOUNDARY: + x[i]->sum = this->totals[x[i]->description]*mass_water_aq_x; + break; + case ALK: + x[i]->f = this->total_alkalinity*mass_water_aq_x; + break; } } - initial_solution_isotopes = FALSE; - return (OK); } diff --git a/ISolution.h b/ISolution.h index 0a0a19d9..3574983b 100644 --- a/ISolution.h +++ b/ISolution.h @@ -44,7 +44,8 @@ public: void ORCH_write_chemistry(std::ostream &chemistry_dat); void ORCH_write_input(std::ostream &input_dat); void ORCH_write_output(std::ostream &input_dat); - void print(); + void ORCH_store_global(std::map < std::string, double > output_map); + protected: friend class cxxISolutionComp; // for this->pe access double density; diff --git a/Solution.cxx b/Solution.cxx index 672f7d3d..a090fde9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -506,7 +506,7 @@ void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const return; } -void cxxSolution::write_orchestra(std::ostream& headings, std::ostream& data)const +void cxxSolution::ORCH_write(std::ostream& headings, std::ostream& data)const { data.precision(DBL_DIG - 1); @@ -964,7 +964,7 @@ double cxxSolution::get_master_activity(char *string)const return(it->second); } } -void cxxSolution::read_orchestra(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) +void cxxSolution::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) { this->tc = it->second; it++; this->ph = it->second; it++; @@ -1033,6 +1033,7 @@ void cxxSolution::read_orchestra(std::vector > struct species *s_ptr = s_search(token); if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); s_ptr->la = log10(it->second); it++; + s_ptr->moles = it->second * this->mass_water; s_ptr->lm = log10(it->second); it++; s_ptr->lg = s_ptr->la - s_ptr->lm; } diff --git a/Solution.h b/Solution.h index 0f7b1310..7c3b44f2 100644 --- a/Solution.h +++ b/Solution.h @@ -80,11 +80,11 @@ public: struct solution *cxxSolution2solution(); void dump_raw(std::ostream& s_oss, unsigned int indent)const; - void write_orchestra(std::ostream& headings, std::ostream& input_data)const; void read_raw(CParser& parser); void multiply(double extensive); - void read_orchestra(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); + void ORCH_write(std::ostream& headings, std::ostream& input_data)const; + void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); #ifdef USE_MPI From c78dd87daf8f9eb5afca101c080785e684c77199 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 7 Aug 2007 15:04:13 +0000 Subject: [PATCH 0063/1077] Have version working that formats an input file for Orchestra, runs Orchestra with a system call to a batch file, reads results from Orchestra, stores results in global phreeqc storage, and prints results. Works only for initial solution calculation. Still some problems with the solver. Ex1 fails. Cleaned up organization a little. Ready to start on "reaction" calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2176 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 32 +++----------------------------- ISolution.h | 3 +-- Solution.cxx | 30 ++++++++++++++++++++++++++++++ Solution.h | 2 +- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index dc19c17f..93f9e5f2 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -731,6 +731,8 @@ void cxxISolution::ORCH_write_chemistry_minerals(std::ostream &chemistry_dat) } } } + //chemistry_dat << "@mineral(Quartz)" << std::endl; + //chemistry_dat << "@sreaction(Quartz, 10139.1138573668, -2.0, H2O, 1.0, H4SiO4)" << std::endl; } void cxxISolution::ORCH_write_input(std::ostream &input_dat) { @@ -854,7 +856,7 @@ void cxxISolution::ORCH_write_input(std::ostream &input_dat) return; } -void cxxISolution::ORCH_write_output(std::ostream &outstream) +void cxxISolution::ORCH_write_output_vars(std::ostream &outstream) { outstream << "Var:"; outstream << "\tnr_iter"; @@ -928,31 +930,3 @@ void cxxISolution::ORCH_write_output(std::ostream &outstream) outstream << std::endl; return; } - -void cxxISolution::ORCH_store_global(std::map < std::string, double > output_map) -{ - int i; - tc_x = this->tc; - mass_water_aq_x = this->mass_water; - mu_x = this->mu; - s_h2o->moles = output_map["H2O.con"]; - s_h2o->la = log10(output_map["H2O.act"]); - s_h2o->lm = s_h2o->la; - s_h2o->lg = 0; - for (i = 0; i < count_unknowns; i++) - { - residual[i] = 0; - // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O - switch (x[i]->type) - { - case MB: - case CB: - case SOLUTION_PHASE_BOUNDARY: - x[i]->sum = this->totals[x[i]->description]*mass_water_aq_x; - break; - case ALK: - x[i]->f = this->total_alkalinity*mass_water_aq_x; - break; - } - } -} diff --git a/ISolution.h b/ISolution.h index 3574983b..b629f013 100644 --- a/ISolution.h +++ b/ISolution.h @@ -43,8 +43,7 @@ public: void ConvertUnits(); void ORCH_write_chemistry(std::ostream &chemistry_dat); void ORCH_write_input(std::ostream &input_dat); - void ORCH_write_output(std::ostream &input_dat); - void ORCH_store_global(std::map < std::string, double > output_map); + void ORCH_write_output_vars(std::ostream &input_dat); protected: friend class cxxISolutionComp; // for this->pe access diff --git a/Solution.cxx b/Solution.cxx index a090fde9..04cc70e5 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -964,6 +964,7 @@ double cxxSolution::get_master_activity(char *string)const return(it->second); } } + void cxxSolution::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) { this->tc = it->second; it++; @@ -1038,6 +1039,35 @@ void cxxSolution::ORCH_read(std::vector > outpu s_ptr->lg = s_ptr->la - s_ptr->lm; } } + +void cxxSolution::ORCH_store_global(std::map < std::string, double > output_map) +{ + int i; + tc_x = this->tc; + mass_water_aq_x = this->mass_water; + mu_x = this->mu; + s_h2o->moles = output_map["H2O.con"]; + s_h2o->la = log10(output_map["H2O.act"]); + s_h2o->lm = s_h2o->la; + s_h2o->lg = 0; + for (i = 0; i < count_unknowns; i++) + { + residual[i] = 0; + // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O + switch (x[i]->type) + { + case MB: + case CB: + case SOLUTION_PHASE_BOUNDARY: + x[i]->sum = this->totals[x[i]->description]*mass_water_aq_x; + break; + case ALK: + x[i]->f = this->total_alkalinity*mass_water_aq_x; + break; + } + } +} + #ifdef USE_MPI #include /* ---------------------------------------------------------------------- */ diff --git a/Solution.h b/Solution.h index 7c3b44f2..ef519e4d 100644 --- a/Solution.h +++ b/Solution.h @@ -85,7 +85,7 @@ public: void multiply(double extensive); void ORCH_write(std::ostream& headings, std::ostream& input_data)const; void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); - + void ORCH_store_global(std::map < std::string, double > output_map); #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); From 7ab1e21ce7f91aa48c67fcd63339c3ab3c59473e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Aug 2007 18:51:35 +0000 Subject: [PATCH 0064/1077] Works with reaction calculation of pure phase equilibrium. Worked out relation between phreeqc components H,O,charge and Orchestra H+, e-, H2O. It's a lot of code and still have not implemented SURFACE, EXCHANGE, GAS_PHASE, much les KINETICS. Convergence problem when including pyrite. Also have REACTION (REQCTION_TEMP?); git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2181 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 1 + ISolution.cxx | 70 +++---- ISolution.h | 2 +- PPassemblage.cxx | 72 +++++++ PPassemblage.h | 14 +- Solution.cxx | 2 + Solution.h | 3 +- StorageBin.cxx | 172 +++++++++++++++- StorageBin.h | 53 ++++- Surface.cxx | 1 + SurfaceComp.h | 2 + System.cxx | 513 +++++++++++++++++++++++++++++++++++++++++++++++ System.h | 73 +++++++ 13 files changed, 928 insertions(+), 50 deletions(-) create mode 100644 System.cxx create mode 100644 System.h diff --git a/Exchange.cxx b/Exchange.cxx index 26cbcb05..644d9ea3 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -406,6 +406,7 @@ void cxxExchange::totalize() for (std::list::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { this->totals.add_extensive(it->get_totals(), 1.0); + this->totals.add("Charge", it->get_charge_balance()); } return; } diff --git a/ISolution.cxx b/ISolution.cxx index 93f9e5f2..49e8fa58 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -16,7 +16,7 @@ #include // assert #include // std::sort #include - +extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -426,7 +426,7 @@ void cxxISolution::ORCH_write_chemistry(std::ostream &chemistry_dat) this->ORCH_write_chemistry_primary(chemistry_dat); this->ORCH_write_chemistry_total_O_H(chemistry_dat); this->ORCH_write_chemistry_alkalinity(chemistry_dat); - this->ORCH_write_chemistry_species(chemistry_dat); + ORCH_write_chemistry_species(chemistry_dat); this->ORCH_write_chemistry_minerals(chemistry_dat); } @@ -587,7 +587,6 @@ void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) chemistry_dat << "\")" << std::endl; chemistry_dat << std::endl; } - void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Alkalinity definitions" << std::endl; @@ -656,41 +655,7 @@ void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat) } } } -void cxxISolution::ORCH_write_chemistry_species(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* Aqueous species" << std::endl; - // - // Write species definitions - // - for (int i = 0; i < count_s_x; i++) { - if (s_x[i]->primary != NULL) continue; - if (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE) continue; - // write species - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - chemistry_dat << "@species(" << name.c_str() << ", " << s_x[i]->z << ")" << std::endl; - - // write reaction - chemistry_dat << "@reaction(" << name.c_str() << ", " << pow(10.0, s_x[i]->lk); - struct rxn_token *next_token = s_x[i]->rxn_x->token; - next_token++; - while (next_token->s != NULL || next_token->name != NULL) - { - chemistry_dat << ", " << next_token->coef; - if (next_token->s != NULL) - { - chemistry_dat << ", " << next_token->s->name; - } else { - chemistry_dat << ", " << next_token->name; - } - next_token++; - } - chemistry_dat << ")" << std::endl; - } - chemistry_dat << std::endl; -} void cxxISolution::ORCH_write_chemistry_minerals(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Adjustments to mineral equilibrium" << std::endl; @@ -881,12 +846,13 @@ void cxxISolution::ORCH_write_output_vars(std::ostream &outstream) //cb outstream << "\tchargebalance"; //mass_water; - outstream << "\tH2O.diss"; + outstream << "\tH2O.con"; //total_alkalinity; outstream << "\tAlkalinity"; //orchestra master variables outstream << "\tH+.diss"; outstream << "\te-.diss"; + outstream << "\tH2O.diss"; //totals for(std::map::iterator iter = this->comps.begin(); iter != this->comps.end(); ++iter) { @@ -930,3 +896,31 @@ void cxxISolution::ORCH_write_output_vars(std::ostream &outstream) outstream << std::endl; return; } +void cxxISolution::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) +{ + // + // Write orchestra chemistry file definition + // + chemistry_dat << std::endl << "// Write ORCHESTRA chemistry definitions" << std::endl; + // mark for Orchestra include + chemistry_dat << std::endl << "@class: species_reactions () {" << std::endl; + this->ORCH_write_chemistry(chemistry_dat); + // end orchestra include block + chemistry_dat << std::endl << "}" << std::endl; + // + // Write orchestra input file definition + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + this->ORCH_write_input(input_dat); + input_dat << std::endl << "}" << std::endl; + + // + // Write orchestra output file definition + // + output_dat << std::endl << "Output_every: 1" << std::endl; + this->ORCH_write_output_vars(output_dat); + + //write data to stderr + //std::cerr << chemistry_dat.str() << input_dat.str() << output_dat.str(); + +} diff --git a/ISolution.h b/ISolution.h index b629f013..f747ccd4 100644 --- a/ISolution.h +++ b/ISolution.h @@ -41,6 +41,7 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void ConvertUnits(); + void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); void ORCH_write_chemistry(std::ostream &chemistry_dat); void ORCH_write_input(std::ostream &input_dat); void ORCH_write_output_vars(std::ostream &input_dat); @@ -61,7 +62,6 @@ private: void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); void ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat); - void ORCH_write_chemistry_species(std::ostream &chemistry_dat); void ORCH_write_chemistry_minerals(std::ostream &chemistry_dat); }; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 9dd8bca2..f09e3a1b 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -285,4 +285,76 @@ void cxxPPassemblage::add(const cxxPPassemblage &addee, double extensive) //cxxNameDouble eltList; this->eltList.add_extensive(addee.eltList, extensive); } +void cxxPPassemblage::ORCH_write_chemistry(std::ostream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Mineral equilibria" << std::endl; +// +// Write minerals +// + for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) + { + struct phase *phase_ptr; + int n; + phase_ptr = phase_bsearch(it->get_name(), &n, FALSE); + assert (phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@mineral(" << phase_name << ")" << std::endl; + chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, -phase_ptr->lk); + struct rxn_token *next_token = phase_ptr->rxn_x->token; + next_token++; + while (next_token->s != NULL || next_token->name != NULL) + { + chemistry_dat << ", " << next_token->coef; + if (next_token->s != NULL) + { + chemistry_dat << ", " << next_token->s->name; + } else { + chemistry_dat << ", " << next_token->name; + } + next_token++; + } + chemistry_dat << ")" << std::endl; + } +} +void cxxPPassemblage::ORCH_write_output_vars(std::ostream &outstream) +{ + // + // Write ppassemblage output variables + // + outstream << "\tstart_ppassemblage"; + for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) + { + outstream << "\t" << it->get_name() << ".min"; + } + outstream << "\tend_ppassemblage"; +} +void cxxPPassemblage::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) +{ + while (it->first.compare("end_ppassemblage") != 0) + { + it++; + } +} + +void cxxPPassemblage::ORCH_store_global(std::map < std::string, double > output_map) +{ + int i; + std::map < std::string, double >::iterator it; + for (i = 0; i < count_unknowns; i++) + { + // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O + switch (x[i]->type) + { + case PP: + std::string name(x[i]->phase->name); + name.append(".min"); + it = output_map.find(name); + assert (it != output_map.end()); + x[i]->moles = it->second; + break; + } + } +} diff --git a/PPassemblage.h b/PPassemblage.h index 659e8304..d379bada 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -31,23 +31,27 @@ public: void read_raw(CParser& parser); + const cxxNameDouble& get_totals()const + { + return this->totals; + }; + #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif void totalize(); + void ORCH_write_chemistry(std::ostream &chemistry_dat); + void ORCH_write_output_vars(std::ostream &outstream); + void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); + void ORCH_store_global(std::map < std::string, double > output_map); private: void add(const cxxPPassemblage &addee, double extensive); // not written void dump_xml(std::ostream& os, unsigned int indent = 0)const; - const cxxNameDouble& get_totals()const - { - return this->totals; - }; - protected: std::list ppAssemblageComps; cxxNameDouble eltList; diff --git a/Solution.cxx b/Solution.cxx index 04cc70e5..b3b866f8 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -976,9 +976,11 @@ void cxxSolution::ORCH_read(std::vector > outpu this->total_o = it->second; it++; this->cb = it->second; it++; this->mass_water = it->second * gfw_water; it++; + this->mass_water = 1.0; this->total_alkalinity = it->second; it++; it++; //orch total H+ it++; //orch total e- + it++; //orch total H2O //cxxNameDouble totals; char token[MAX_LENGTH]; while (it->first.compare("end_totals") != 0) diff --git a/Solution.h b/Solution.h index ef519e4d..a0efe286 100644 --- a/Solution.h +++ b/Solution.h @@ -62,10 +62,11 @@ public: double get_total_element(char *string)const; void set_total(char *string, double value); + const cxxNameDouble& get_totals(void)const {return this->totals;} void set_totals(cxxNameDouble &nd) {this->totals = nd; this->totals.type = cxxNameDouble::ND_ELT_MOLES;} void clear_totals() {this->totals.clear();} - + const cxxNameDouble& get_master_activity(void)const {return this->master_activity;} double get_master_activity(char *string)const; void set_master_activity(char *string, double value); diff --git a/StorageBin.cxx b/StorageBin.cxx index 4b8b3064..71bee254 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -9,7 +9,7 @@ #include // std::cout std::cerr #include "Utils.h" // define first #include "StorageBin.h" -#include "Solution.h" +#include "System.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -25,7 +25,73 @@ cxxStorageBin::cxxStorageBin() { // default constructor for cxxStorageBin } +cxxStorageBin::cxxStorageBin(struct Use *use_ptr) +{ + //Construct from use pointer + // Solution + if (use_ptr->solution_ptr != NULL) + { + cxxSolution entity(use_ptr->solution_ptr); + this->setSolution(use_ptr->n_solution_user, &entity); + } + // Exchange + if (use_ptr->exchange_ptr != NULL) + { + cxxExchange entity(use_ptr->exchange_ptr); + this->setExchange(use_ptr->n_exchange_user, &entity); + } + // gas_phase + if (use_ptr->gas_phase_ptr != NULL) + { + cxxGasPhase entity(use_ptr->gas_phase_ptr); + this->setGasPhase(use_ptr->n_gas_phase_user, &entity); + } + // kinetics + if (use_ptr->kinetics_ptr != NULL) + { + cxxKinetics entity(use_ptr->kinetics_ptr); + this->setKinetics(use_ptr->n_kinetics_user, &entity); + } + // pp_assemblage + if (use_ptr->pp_assemblage_ptr != NULL) + { + cxxPPassemblage entity(use_ptr->pp_assemblage_ptr); + this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); + } + // s_s_assemblage + if (use_ptr->s_s_assemblage_ptr != NULL) + { + cxxSSassemblage entity(use_ptr->s_s_assemblage_ptr); + this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); + } + // surface + if (use_ptr->surface_ptr != NULL) + { + cxxSurface entity(use_ptr->surface_ptr); + this->setSurface(use_ptr->n_surface_user, &entity); + } + // mix + if (use_ptr->mix_ptr != NULL) + { + cxxMix entity(use_ptr->mix_ptr); + this->setMix(use_ptr->n_mix_user, &entity); + } + // reaction + if (use_ptr->irrev_ptr != NULL) + { + cxxReaction entity(use_ptr->irrev_ptr); + this->setReaction(use_ptr->n_irrev_user, &entity); + } + // reaction temperature + if (use_ptr->temperature_ptr != NULL) + { + cxxTemperature entity(use_ptr->temperature_ptr); + this->setTemperature(use_ptr->n_temperature_user, &entity); + } + // set system + this->setSystem(use_ptr); +} cxxStorageBin::~cxxStorageBin() { } @@ -917,3 +983,107 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) return(new_exch_ptr); } #endif + +void cxxStorageBin::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) +{ + //std::ostringstream oss; + + // Liter concentrations + this->system.ORCH_write(chemistry_dat, input_dat, output_dat); + +} +void cxxStorageBin::setSystem(struct Use *use_ptr) +{ + // Initialize + this->system.Initialize(); + // Solution + if (use_ptr->solution_ptr != NULL) + { + std::map ::iterator it = this->Solutions.find(use_ptr->n_solution_user); + if (it != this->Solutions.end()) + { + this->system.setSolution(&(it->second)); + } + } + // Exchange + if (use_ptr->exchange_ptr != NULL) + { + std::map ::iterator it = this->Exchangers.find(use_ptr->n_exchange_user); + if (it != this->Exchangers.end()) + { + this->system.setExchange(&(it->second)); + } + } + // gas_phase + if (use_ptr->gas_phase_ptr != NULL) + { + std::map ::iterator it = this->GasPhases.find(use_ptr->n_gas_phase_user); + if (it != this->GasPhases.end()) + { + this->system.setGasPhase(&(it->second)); + } + } + // kinetics + if (use_ptr->kinetics_ptr != NULL) + { + std::map ::iterator it = this->Kinetics.find(use_ptr->n_kinetics_user); + if (it != this->Kinetics.end()) + { + this->system.setKinetics(&(it->second)); + } + } + // pp_assemblage + if (use_ptr->pp_assemblage_ptr != NULL) + { + std::map ::iterator it = this->PPassemblages.find(use_ptr->n_pp_assemblage_user); + if (it != this->PPassemblages.end()) + { + this->system.setPPassemblage(&(it->second)); + } + } + // s_s_assemblage + if (use_ptr->s_s_assemblage_ptr != NULL) + { + std::map ::iterator it = this->SSassemblages.find(use_ptr->n_s_s_assemblage_user); + if (it != this->SSassemblages.end()) + { + this->system.setSSassemblage(&(it->second)); + } + } + // surface + if (use_ptr->surface_ptr != NULL) + { + std::map ::iterator it = this->Surfaces.find(use_ptr->n_surface_user); + if (it != this->Surfaces.end()) + { + this->system.setSurface(&(it->second)); + } + } + // mix + if (use_ptr->mix_ptr != NULL) + { + std::map ::iterator it = this->Mixes.find(use_ptr->n_mix_user); + if (it != this->Mixes.end()) + { + this->system.setMix(&(it->second)); + } + } + // reaction + if (use_ptr->irrev_ptr != NULL) + { + std::map ::iterator it = this->Reactions.find(use_ptr->n_irrev_user); + if (it != this->Reactions.end()) + { + this->system.setReaction(&(it->second)); + } + } + // reaction temperature + if (use_ptr->temperature_ptr != NULL) + { + std::map ::iterator it = this->Temperatures.find(use_ptr->n_temperature_user); + if (it != this->Temperatures.end()) + { + this->system.setTemperature(&(it->second)); + } + } +} \ No newline at end of file diff --git a/StorageBin.h b/StorageBin.h index a3ee4123..22d568cc 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -10,6 +10,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "Surface.h" +#include "System.h" #include "cxxMix.h" #include "Reaction.h" #include "Temperature.h" @@ -25,7 +26,7 @@ class cxxStorageBin public: cxxStorageBin(); - + cxxStorageBin(struct Use *use_ptr); ~cxxStorageBin(); void import_phreeqc(void); @@ -136,7 +137,51 @@ public: Surfaces.erase(n_user); } - void dump_raw(std::ostream& s_oss, unsigned int indent)const; + cxxMix *getMix(int n_user) { + if (this->Mixes.find(n_user) != this->Mixes.end()) { + return(&(this->Mixes.find(n_user)->second)); + } + return (NULL); + } + void setMix(int n_user, cxxMix *entity) { + if (entity == NULL) return; + Mixes[n_user] = *entity; + } + void removeMix(int n_user) { + Mixes.erase(n_user); + } + + cxxReaction *getReaction(int n_user) { + if (this->Reactions.find(n_user) != this->Reactions.end()) { + return(&(this->Reactions.find(n_user)->second)); + } + return (NULL); + } + void setReaction(int n_user, cxxReaction *entity) { + if (entity == NULL) return; + Reactions[n_user] = *entity; + } + void removeReaction(int n_user) { + Reactions.erase(n_user); + } + + cxxTemperature *getTemperature(int n_user) { + if (this->Temperatures.find(n_user) != this->Temperatures.end()) { + return(&(this->Temperatures.find(n_user)->second)); + } + return (NULL); + } + void setTemperature(int n_user, cxxTemperature *entity) { + if (entity == NULL) return; + Temperatures[n_user] = *entity; + } + void removeTemperature(int n_user) { + Temperatures.erase(n_user); + } + + void setSystem(struct Use *use_ptr); + + void dump_raw(std::ostream& s_oss, unsigned int indent)const; void dump_raw(std::ostream& s_oss, int i, unsigned int indent); @@ -161,7 +206,7 @@ public: void mpi_send(int n, int task_number); void mpi_recv(int task_number); #endif - + void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); protected: // Tidied classes std::map Solutions; @@ -180,7 +225,7 @@ protected: std::map Mixes; std::map Reactions; std::map Temperatures; - + cxxSystem system; public: //static std::map& map; diff --git a/Surface.cxx b/Surface.cxx index a859cd40..81c6565d 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -680,6 +680,7 @@ void cxxSurface::totalize() for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { this->totals.add_extensive(it->get_totals(), 1.0); + this->totals.add("Charge", it->get_charge_balance()); } return; } diff --git a/SurfaceComp.h b/SurfaceComp.h index 4eec084f..67a4cce0 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -27,6 +27,8 @@ public: char *get_phase_name()const {return this->phase_name;} char *get_rate_name()const {return this->rate_name;} char *get_formula()const {return this->formula;} + double get_charge_balance()const { return this->charge_balance;} + void set_charge_balance(double d) { this->charge_balance = d;} static struct surface_comp *cxxSurfaceComp2surface_comp(std::list& el); diff --git a/System.cxx b/System.cxx new file mode 100644 index 00000000..ed5e3c54 --- /dev/null +++ b/System.cxx @@ -0,0 +1,513 @@ +#include "System.h" +#include // std::replace +extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); +cxxSystem::cxxSystem(void) +{ + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; +} + +cxxSystem::~cxxSystem(void) +{ +} + +void cxxSystem::Initialize(void) +{ + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; +} +void cxxSystem::totalize(void) +{ + //initialize + this->totals.clear(); + //add solution + if (this->solution != NULL) + { + this->totals["O"] = this->solution->get_total_o(); + this->totals["H"] = this->solution->get_total_h(); + this->totals["Charge"] = this->solution->get_cb(); + this->totals.add_extensive(this->solution->get_totals(), 1.0); + } + if (this->exchange != NULL) + { + this->exchange->totalize(); + this->totals.add_extensive(this->exchange->get_totals(), 1.0); + } + if (this->ppassemblage != NULL) + { + this->ppassemblage->totalize(); + this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + } + if (this->gasphase != NULL) + { + this->gasphase->totalize(); + this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + } + if (this->ssassemblage != NULL) + { + this->ssassemblage->totalize(); + this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + } + if (this->surface != NULL) + { + this->ssassemblage->totalize(); + this->totals.add_extensive(this->surface->get_totals(), 1.0); + } + + //Need to handle the following 3 reactions: + // + //this->kinetics = NULL; + //this->mix = NULL; + //this->reaction = NULL; + //this->temperature = NULL; + //this->totals.dump_raw(std::cerr, 1); + return; +} +void cxxSystem::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) +{ + // + // chemistry file + // + this->totalize(); + // calculate orchestra components from PHREEQC totals + this->ORCH_components(); + // write definitions for chemistry + chemistry_dat << std::endl << "@class: species_reactions () {" << std::endl; + this->ORCH_write_chemistry_water(chemistry_dat); + this->ORCH_write_chemistry_primary(chemistry_dat); + this->ORCH_write_chemistry_total_O_H(chemistry_dat); + ORCH_write_chemistry_species(chemistry_dat); + + // add definitions for pure phases + if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_chemistry(chemistry_dat); + + // add definitions for other PHREEQC entities here + + // finish up + chemistry_dat << std::endl << "}" << std::endl; + // + // input file + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + this->ORCH_write_input(input_dat); + input_dat << std::endl << "}" << std::endl; + // + // output file + // + output_dat << std::endl << "Output_every: 1" << std::endl; + output_dat << "Var:"; + this->ORCH_write_output_vars(output_dat); + // add definitions for pure phases + if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_output_vars(output_dat); + + //finish up + output_dat << std::endl; +}; + +void cxxSystem::ORCH_write_chemistry_water(std::ostream &chemistry_dat) +{ + // + // Write water entities + // + chemistry_dat << std::endl << "//********* The water entities" << std::endl; + + // e-, total hydrogen + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; + chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std::endl; + + // H+, charge balance + chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; + chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std::endl; + + // H2O + chemistry_dat << "@entity(" << s_h2o->name << ", diss, 55.506)" << std::endl; + chemistry_dat << std::endl; +} + +void cxxSystem::ORCH_write_chemistry_primary(std::ostream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* The primary species" << std::endl; + // + // Write other master species definitions, i.e. primary entities + // + chemistry_dat << "@species(H+, 1)" << std::endl; + for(cxxNameDouble::iterator iter = this->totals.begin() ; iter != this->totals.end(); ++iter) + { + std::string name(iter->first); + if (name == "H(1)" || name == "E" || name == "H" || name == "O" || name == "Charge") continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->z << ")" << std::endl; + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr->name << ", 1e-9, liter, 1.0e-9)" << std::endl; + } + chemistry_dat << std::endl; +} + +void cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) +{ + chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl; + + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + int i; + for (i = 0; i < count_s_x; i++) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) + { + if (s_x[i]->h != 0) + { + chemistry_dat << "+"; + if (s_x[i]->h != 1) + { + chemistry_dat << s_x[i]->h << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->o != 0) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) + { + chemistry_dat << "+"; + if (s_x[i]->o != 1) + { + chemistry_dat << s_x[i]->o << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + chemistry_dat << std::endl; +} +#ifdef SKIP +void cxxSystem::ORCH_write_input(std::ostream &input_dat) +{ + + +// +// Write orchestra input file info +// + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; + + + headings << "tempc\t"; + data << this->solution->get_tc() << "\t"; + + headings << "pH\t"; + data << this->solution->get_ph() << "\t"; + + headings << "pe\t"; + data << this->solution->get_pe() << "\t"; + + headings << "H2O.act\t"; + data << 1 << "\t"; + + for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) + { + if (iter->first == "O") continue; + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch (iter->first); + assert (master_ptr != NULL); + double coef = master_ptr->coef; + if (master_ptr->coef == 0) + { + coef = 1; + } + if (iter->first == "H") + { + headings << "system_hydrogen" << "\t"; + data << iter->second << "\t"; + continue; + } else + { + headings << master_ptr->s->name << ".liter" << "\t"; + data << iter->second / coef << "\t"; + } + + // activity estimate + cxxNameDouble ma = this->solution->get_master_activity(); + cxxNameDouble::iterator it = ma.find(iter->first); + if (it == ma.end()) + { + it = ma.find(master_ptr->s->secondary->elt->name); + } + headings << master_ptr->s->name << ".act\t"; + if (it != ma.end()) + { + data << pow(10., it->second) << "\t"; + } else + { + data << 1e-9 << "\t"; + } + } + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; + + return; +} +#endif +void cxxSystem::ORCH_write_input(std::ostream &input_dat) +{ + + +// +// Write orchestra input file info +// + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; + + headings << "tempc\t"; + data << this->solution->get_tc() << "\t"; + + headings << "pH\t"; + data << this->solution->get_ph() << "\t"; + + headings << "pe\t"; + data << this->solution->get_pe() << "\t"; + + headings << "H2O.act\t"; + data << 1 << "\t"; + + headings << "I\t"; + data << this->solution->get_mu() << "\t"; + + for (cxxNameDouble::iterator iter = this->orch_totals.begin(); iter != this->orch_totals.end(); ++iter) + { + headings << iter->first << ".liter" << "\t"; + data << iter->second << "\t"; + } + + // activity estimate + for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) + { + if (iter->first == "O" || iter->first == "Charge") continue; + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch (iter->first); + assert (master_ptr != NULL); + + cxxNameDouble ma = this->solution->get_master_activity(); + cxxNameDouble::iterator it = ma.find(iter->first); + if (it == ma.end()) + { + it = ma.find(master_ptr->s->secondary->elt->name); + } + headings << master_ptr->s->name << ".act\t"; + if (it != ma.end()) + { + data << pow(10., it->second) << "\t"; + } else + { + data << 1e-9 << "\t"; + } + } + + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; + + return; +} + +void cxxSystem::ORCH_components(void) +{ + // translate from H, O, charge to H+tot, e-tot, and H2Otot + cxxNameDouble::iterator it; + cxxNameDouble temp_totals; + // + // Set names in orch_totals to master species names + // + this->orch_totals.clear(); + temp_totals = this->totals; + temp_totals.erase("H"); + temp_totals.erase("O"); + temp_totals.erase("Charge"); + //temp_totals.dump_raw(std::cerr, 1); + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + assert(elt_ptr != NULL); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + assert(master_ptr != NULL); + double coef = master_ptr->coef; + if (master_ptr->coef == 0) + { + coef = 1; + } + this->orch_totals[master_ptr->s->name] = it->second / coef; + } + // + // Calculate h2otot + // + it = this->totals.find("O"); + assert (it != this->totals.end()); + double h2otot = it->second; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + h2otot -= it->second * master_ptr->s->o; + } + // + // Calculate htot + // + it = this->totals.find("H"); + assert (it != this->totals.end()); + double htot = it->second - 2*h2otot; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + htot -= it->second * master_ptr->s->h; + } + // + // Calculate etot + // + it = this->totals.find("Charge"); + assert (it != this->totals.end()); + double etot = -it->second + htot; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + etot += it->second * master_ptr->s->z; + } + // + // store h2otot, htot, etot in orch_totals + // + this->orch_totals["H2O"] = h2otot; + this->orch_totals["H+"] = htot; + this->orch_totals["e-"] = etot; + this->orch_totals.dump_raw(std::cerr, 1); +} +void cxxSystem::ORCH_write_output_vars(std::ostream &outstream) +{ + outstream << "\tnr_iter"; + // + // Serialize solution + // + outstream << "\tstart_solution"; + //tc + outstream << "\ttempc"; + //pH + outstream << "\tpH"; + //pe + outstream << "\tpe"; + //mu + outstream << "\tI"; + //ah2o + outstream << "\tH2O.act"; + //total_h; + outstream << "\ttotal_hydrogen"; + //total_o; + outstream << "\ttotal_oxygen"; + //cb + outstream << "\tchargebalance"; + //mass_water; + outstream << "\tH2O.con"; + //total_alkalinity; + outstream << "\tAlkalinity"; + //orchestra master variables + outstream << "\tH+.diss"; + outstream << "\te-.diss"; + outstream << "\tH2O.diss"; + // + // Write totals + for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) + { + if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; + outstream << "\t" << it->first << ".diss"; + } + outstream << "\tend_totals"; + for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) + { + if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; + struct species *s_ptr = s_search(it->first); + outstream << "\t" << it->first << ".act"; + } + outstream << "\tend_master_activities"; + // + // Write all species activities and concentrations + // + int i; + for (i = 0; i < count_s_x; i++) { + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; + } + outstream << "\tend_species"; +} \ No newline at end of file diff --git a/System.h b/System.h new file mode 100644 index 00000000..6dfe7bb9 --- /dev/null +++ b/System.h @@ -0,0 +1,73 @@ +#if !defined(SYSTEM_H_INCLUDED) +#define SYSTEM_H_INCLUDED +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" +#include "cxxMix.h" +#include "Reaction.h" +#include "Temperature.h" +class cxxSystem +{ +public: + cxxSystem(void); +public: + ~cxxSystem(void); + void Initialize(void); + void setSolution(cxxSolution *entity) { + this->solution = entity; + } + void setExchange(cxxExchange *entity) { + this->exchange = entity; + } + void setPPassemblage(cxxPPassemblage *entity) { + this->ppassemblage = entity; + } + void setGasPhase(cxxGasPhase *entity) { + this->gasphase = entity; + } + void setSSassemblage(cxxSSassemblage *entity) { + this->ssassemblage = entity; + } + void setKinetics(cxxKinetics *entity) { + this->kinetics = entity; + } + void setSurface(cxxSurface *entity) { + this->surface = entity; + } + void setMix(cxxMix *entity) { + this->mix = entity; + } + void setReaction(cxxReaction *entity) { + this->reaction = entity; + } + void setTemperature(cxxTemperature *entity) { + this->temperature = entity; + } + void totalize(); + void ORCH_components(); + void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); + void ORCH_write_chemistry_water(std::ostream &chemistry_dat); + void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); + void ORCH_write_output_vars(std::ostream &outstream); + void ORCH_write_input(std::ostream &input_dat); + +private: + cxxSolution *solution; + cxxExchange *exchange; + cxxPPassemblage *ppassemblage; + cxxGasPhase *gasphase; + cxxSSassemblage *ssassemblage; + cxxKinetics *kinetics; + cxxSurface *surface; + cxxMix *mix; + cxxReaction *reaction; + cxxTemperature *temperature; + cxxNameDouble totals; + cxxNameDouble orch_totals; +}; +#endif // !defined(SYSTEM_H_INCLUDED) From 37b1add9462daff223ca422ad7780d806e3c24b6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Aug 2007 19:49:38 +0000 Subject: [PATCH 0065/1077] Ifdef'd ORCHESTRA. Added lines at end of files. Ran test cases, a few had changes from format and Tony. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2182 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 4 + ISolution.h | 15 ++-- Makefile | 230 +++++++++++++++++++---------------------------- PPassemblage.cxx | 3 + PPassemblage.h | 2 + Solution.cxx | 178 ++++++++++++++++++------------------ Solution.h | 2 + StorageBin.cxx | 4 +- StorageBin.h | 2 + System.cxx | 87 +----------------- System.h | 2 + 11 files changed, 210 insertions(+), 319 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 49e8fa58..a9e14528 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -16,7 +16,9 @@ #include // assert #include // std::sort #include +#ifdef ORCHESTRA extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); +#endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -420,6 +422,7 @@ void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const } #endif +#ifdef ORCHESTRA void cxxISolution::ORCH_write_chemistry(std::ostream &chemistry_dat) { this->ORCH_write_chemistry_water(chemistry_dat); @@ -924,3 +927,4 @@ void cxxISolution::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_d //std::cerr << chemistry_dat.str() << input_dat.str() << output_dat.str(); } +#endif diff --git a/ISolution.h b/ISolution.h index f747ccd4..6d578d72 100644 --- a/ISolution.h +++ b/ISolution.h @@ -41,10 +41,19 @@ public: //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void ConvertUnits(); + +#ifdef ORCHESTRA void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); void ORCH_write_chemistry(std::ostream &chemistry_dat); void ORCH_write_input(std::ostream &input_dat); void ORCH_write_output_vars(std::ostream &input_dat); +private: + void ORCH_write_chemistry_water(std::ostream &chemistry_dat); + void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); + void ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat); + void ORCH_write_chemistry_minerals(std::ostream &chemistry_dat); +#endif protected: friend class cxxISolutionComp; // for this->pe access @@ -57,12 +66,6 @@ protected: public: //static std::map& map; -private: - void ORCH_write_chemistry_water(std::ostream &chemistry_dat); - void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); - void ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat); - void ORCH_write_chemistry_minerals(std::ostream &chemistry_dat); }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/Makefile b/Makefile index 8c885d6a..8519b745 100644 --- a/Makefile +++ b/Makefile @@ -163,6 +163,7 @@ COMMON_CXXOBJS = \ Surface.o \ SurfaceCharge.o \ SurfaceComp.o \ + System.o \ Temperature.o \ Utils.o @@ -181,178 +182,127 @@ ${PROGRAM} : ${OBJECT_FILES} # CXX files # cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../char_star.h \ - ../cxxKinetics.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../KineticsComp.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../KineticsComp.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../cxxKinetics.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../KineticsComp.h ../NameDouble.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../char_star.h ../cxxMix.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../NumKeyword.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Dictionary.o: ../Dictionary.cxx ../Dictionary.h ../Solution.h \ ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ - ../char_star.h ../NameDouble.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -EntityMap.o: ../EntityMap.cxx ../Utils.h ../char_star.h ../EntityMap.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h Exchange.o: ../Exchange.cxx ../Utils.h ../char_star.h ../Exchange.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../ExchComp.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../char_star.h ../ExchComp.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../NameDouble.h \ + ../Parser.h ../cxxMix.h ../NumKeyword.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../char_star.h ../ExchComp.h \ - ../NameDouble.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../char_star.h ../char_star.h \ + ../NameDouble.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../char_star.h ../GasPhase.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../NumKeyword.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ - ../char_star.h ../char_star.h ../ISolution.h ../ISolutionComp.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../Parser.h ../NameDouble.h ../char_star.h ../Parser.h ../cxxMix.h \ - ../NumKeyword.h ../char_star.h ../char_star.h ../Utils.h \ - ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h + ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h \ + ../NumKeyword.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/output.h ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ - ../Utils.h ../char_star.h ../char_star.h ../NumKeyword.h ../Parser.h \ - ../char_star.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Utils.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../NumKeyword.h \ + ../Parser.h ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../NameDouble.h ../cxxMix.h ../phreeqc/output.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../char_star.h \ - ../KineticsComp.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../KineticsComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../char_star.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ ../char_star.h Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ - ../char_star.h ../char_star.h + ../phreeqc/output.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../char_star.h \ - ../PPassemblageComp.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../PPassemblageComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../char_star.h \ - ../PPassemblage.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../PPassemblageComp.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../PPassemblageComp.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../PPassemblage.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../PPassemblageComp.h ../NameDouble.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Reaction.o: ../Reaction.cxx ../Utils.h ../char_star.h ../Reaction.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../NameDouble.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../NumKeyword.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ - ../char_star.h ../Exchange.h ../NumKeyword.h ../char_star.h \ - ../ExchComp.h ../NameDouble.h ../char_star.h ../Surface.h \ - ../NumKeyword.h ../char_star.h ../SurfaceComp.h ../NameDouble.h \ - ../char_star.h ../SurfaceCharge.h ../NameDouble.h ../char_star.h \ - ../PPassemblage.h ../NumKeyword.h ../char_star.h ../PPassemblageComp.h \ - ../NameDouble.h ../char_star.h ../cxxKinetics.h ../NumKeyword.h \ - ../char_star.h ../KineticsComp.h ../NameDouble.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ - ../NameDouble.h ../char_star.h ../GasPhase.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../Reaction.h ../NumKeyword.h \ - ../NameDouble.h ../char_star.h ../cxxMix.h ../Temperature.h \ - ../NumKeyword.h ../char_star.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../NameDouble.h ../cxxMix.h ../Exchange.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ + ../phreeqc/phrqproto.h ../SurfaceCharge.h ../PPassemblage.h \ + ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../SSassemblage.h ../SSassemblageSS.h ../GasPhase.h ../Reaction.h \ + ../Temperature.h ../phreeqc/phqalloc.h ../phreeqc/output.h +SAXPhreeqc.o: ../SAXPhreeqc.cxx ../SAXPhreeqc.h ../SaxPhreeqcHandlers.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h Solution.o: ../Solution.cxx ../Utils.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h ../char_star.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h ../ISolution.h ../ISolutionComp.h ../Utils.h \ - ../char_star.h ../NumKeyword.h ../Solution.h ../Exchange.h \ - ../NumKeyword.h ../char_star.h ../ExchComp.h ../NameDouble.h \ - ../char_star.h ../Surface.h ../NumKeyword.h ../char_star.h \ - ../SurfaceComp.h ../NameDouble.h ../char_star.h ../SurfaceCharge.h \ - ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ - ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ - ../cxxKinetics.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ - ../NameDouble.h ../char_star.h ../SSassemblage.h ../NumKeyword.h \ - ../char_star.h ../SSassemblageSS.h ../NameDouble.h ../char_star.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../char_star.h ../StorageBin.h \ - ../Utils.h ../Parser.h ../Solution.h ../Exchange.h ../GasPhase.h \ - ../cxxKinetics.h ../PPassemblage.h ../SSassemblage.h ../Surface.h \ - ../cxxMix.h ../Reaction.h ../Temperature.h ../NumKeyword.h + ../NumKeyword.h ../Parser.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h ../ISolution.h ../ISolutionComp.h ../Exchange.h \ + ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../PPassemblage.h ../PPassemblageComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../SSassemblage.h ../SSassemblageSS.h ../GasPhase.h \ + ../Reaction.h ../Temperature.h ../StorageBin.h ../System.h SolutionIsotope.o: ../SolutionIsotope.cxx ../SolutionIsotope.h \ - ../Parser.h ../char_star.h ../Utils.h ../char_star.h ../Parser.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../Parser.h ../char_star.h ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ ../char_star.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Parser.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../char_star.h ../Parser.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../SSassemblageSS.h ../NameDouble.h ../char_star.h ../Parser.h \ - ../char_star.h ../SSassemblageSS.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../SSassemblage.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../SSassemblageSS.h ../NameDouble.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../char_star.h \ - ../SSassemblageSS.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../NameDouble.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../SSassemblageSS.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../char_star.h ../StorageBin.h \ - ../Utils.h ../Parser.h ../char_star.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h ../Parser.h \ - ../NameDouble.h ../char_star.h ../Parser.h ../cxxMix.h ../NumKeyword.h \ - ../char_star.h ../char_star.h ../Exchange.h ../NumKeyword.h \ - ../char_star.h ../ExchComp.h ../NameDouble.h ../char_star.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../cxxKinetics.h ../NumKeyword.h ../char_star.h ../KineticsComp.h \ - ../NameDouble.h ../char_star.h ../PPassemblage.h ../NumKeyword.h \ - ../char_star.h ../PPassemblageComp.h ../NameDouble.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../char_star.h ../SSassemblageSS.h \ - ../NameDouble.h ../char_star.h ../Surface.h ../NumKeyword.h \ - ../char_star.h ../SurfaceComp.h ../NameDouble.h ../char_star.h \ - ../SurfaceCharge.h ../NameDouble.h ../char_star.h ../cxxMix.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../char_star.h ../Solution.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h + ../Parser.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../Exchange.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../GasPhase.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ + ../Surface.h ../SurfaceComp.h ../phreeqc/phrqproto.h ../SurfaceCharge.h \ + ../System.h ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../char_star.h \ - ../SurfaceCharge.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ + ../SurfaceCharge.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ ../phreeqc/phrqproto.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../char_star.h \ - ../SurfaceComp.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../Parser.h ../char_star.h \ - ../char_star.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h \ ../phreeqc/output.h Surface.o: ../Surface.cxx ../Utils.h ../char_star.h ../Surface.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../char_star.h ../SurfaceComp.h ../NameDouble.h \ - ../char_star.h ../Parser.h ../char_star.h ../SurfaceCharge.h \ - ../NameDouble.h ../char_star.h ../SurfaceComp.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../NumKeyword.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../SurfaceComp.h ../NameDouble.h ../phreeqc/phrqproto.h \ + ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h +System.o: ../System.cxx ../System.h ../Solution.h ../NumKeyword.h \ + ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../Exchange.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../GasPhase.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ + ../Surface.h ../SurfaceComp.h ../phreeqc/phrqproto.h ../SurfaceCharge.h \ + ../Reaction.h ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../Parser.h ../char_star.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../char_star.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Temperature.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Utils.o: ../Utils.cxx ../Utils.h ../char_star.h ../Parser.h \ - ../char_star.h ../phreeqc/output.h + ../phreeqc/output.h # # PHREEQC files # diff --git a/PPassemblage.cxx b/PPassemblage.cxx index f09e3a1b..77082818 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -285,6 +285,7 @@ void cxxPPassemblage::add(const cxxPPassemblage &addee, double extensive) //cxxNameDouble eltList; this->eltList.add_extensive(addee.eltList, extensive); } +#ifdef ORCHESTRA void cxxPPassemblage::ORCH_write_chemistry(std::ostream &chemistry_dat) { chemistry_dat << std::endl << "//********* Mineral equilibria" << std::endl; @@ -331,6 +332,7 @@ void cxxPPassemblage::ORCH_write_output_vars(std::ostream &outstream) } outstream << "\tend_ppassemblage"; } + void cxxPPassemblage::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) { while (it->first.compare("end_ppassemblage") != 0) @@ -358,3 +360,4 @@ void cxxPPassemblage::ORCH_store_global(std::map < std::string, double > output_ } } } +#endif diff --git a/PPassemblage.h b/PPassemblage.h index d379bada..ff2e3f44 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -42,10 +42,12 @@ public: #endif void totalize(); +#ifdef ORCHESTRA void ORCH_write_chemistry(std::ostream &chemistry_dat); void ORCH_write_output_vars(std::ostream &outstream); void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); void ORCH_store_global(std::map < std::string, double > output_map); +#endif private: void add(const cxxPPassemblage &addee, double extensive); diff --git a/Solution.cxx b/Solution.cxx index b3b866f8..20c2fb72 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -506,93 +506,6 @@ void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const return; } -void cxxSolution::ORCH_write(std::ostream& headings, std::ostream& data)const -{ - - data.precision(DBL_DIG - 1); - - // Solution element and attributes - - //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; - - //s_oss << "-temp " << this->tc << std::endl; - - //s_oss << "-pH " << this->ph << std::endl; - headings << "pH\t"; - data << this->ph << "\t"; - - //s_oss << "-pe " << this->pe << std::endl; - headings << "pe\t"; - data << this->pe << "\t"; - - //s_oss << "-mu " << this->mu << std::endl; - - //s_oss << "-ah2o " << this->ah2o << std::endl; - headings << "H2O.act\t"; - data << 1 << "\t"; - //s_oss << "-total_h " << this->total_h << std::endl; - - //s_oss << "-total_o " << this->total_o << std::endl; - - //s_oss << "-cb " << this->cb << std::endl; - - //s_oss << "-mass_water " << this->mass_water << std::endl; - - //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - - // soln_total conc structures - //this->totals.dump_raw(s_oss, indent + 2); - //this->totals.write_orchestra(headings, s_oss); - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) - { - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch (it->first); - if (master_ptr != NULL) - { - //headings << it->first << ".tot" << "\t"; - headings << master_ptr->s->name << ".diss" << "\t"; - data << it->second << "\t"; - } else - { - assert(false); - } - } - - // master_activity map - //this->master_activity.dump_raw(s_oss, indent + 2); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - */ - // species_gamma map - //this->species_gamma.dump_raw(s_oss, indent + 2); - /* - { - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - } - */ - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - return; -} void cxxSolution::read_raw(CParser& parser) { static std::vector vopts; @@ -965,6 +878,95 @@ double cxxSolution::get_master_activity(char *string)const } } +#ifdef ORCHESTRA +void cxxSolution::ORCH_write(std::ostream& headings, std::ostream& data)const +{ + + data.precision(DBL_DIG - 1); + + // Solution element and attributes + + //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + + //s_oss << "-temp " << this->tc << std::endl; + + //s_oss << "-pH " << this->ph << std::endl; + headings << "pH\t"; + data << this->ph << "\t"; + + //s_oss << "-pe " << this->pe << std::endl; + headings << "pe\t"; + data << this->pe << "\t"; + + //s_oss << "-mu " << this->mu << std::endl; + + //s_oss << "-ah2o " << this->ah2o << std::endl; + headings << "H2O.act\t"; + data << 1 << "\t"; + //s_oss << "-total_h " << this->total_h << std::endl; + + //s_oss << "-total_o " << this->total_o << std::endl; + + //s_oss << "-cb " << this->cb << std::endl; + + //s_oss << "-mass_water " << this->mass_water << std::endl; + + //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + + // soln_total conc structures + //this->totals.dump_raw(s_oss, indent + 2); + //this->totals.write_orchestra(headings, s_oss); + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) + { + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch (it->first); + if (master_ptr != NULL) + { + //headings << it->first << ".tot" << "\t"; + headings << master_ptr->s->name << ".diss" << "\t"; + data << it->second << "\t"; + } else + { + assert(false); + } + } + + // master_activity map + //this->master_activity.dump_raw(s_oss, indent + 2); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + */ + // species_gamma map + //this->species_gamma.dump_raw(s_oss, indent + 2); + /* + { + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + } + */ + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + return; +} + void cxxSolution::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) { this->tc = it->second; it++; @@ -1069,7 +1071,7 @@ void cxxSolution::ORCH_store_global(std::map < std::string, double > output_map) } } } - +#endif #ifdef USE_MPI #include /* ---------------------------------------------------------------------- */ diff --git a/Solution.h b/Solution.h index a0efe286..04261ee8 100644 --- a/Solution.h +++ b/Solution.h @@ -84,9 +84,11 @@ public: void read_raw(CParser& parser); void multiply(double extensive); +#ifdef ORCHESTRA void ORCH_write(std::ostream& headings, std::ostream& input_data)const; void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); void ORCH_store_global(std::map < std::string, double > output_map); +#endif #ifdef USE_MPI void mpi_pack(std::vector& ints, std::vector& doubles); diff --git a/StorageBin.cxx b/StorageBin.cxx index 71bee254..65eaadda 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -984,6 +984,7 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) } #endif +#ifdef ORCHESTRA void cxxStorageBin::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) { //std::ostringstream oss; @@ -992,6 +993,7 @@ void cxxStorageBin::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_ this->system.ORCH_write(chemistry_dat, input_dat, output_dat); } +#endif void cxxStorageBin::setSystem(struct Use *use_ptr) { // Initialize @@ -1086,4 +1088,4 @@ void cxxStorageBin::setSystem(struct Use *use_ptr) this->system.setTemperature(&(it->second)); } } -} \ No newline at end of file +} diff --git a/StorageBin.h b/StorageBin.h index 22d568cc..bcb86ca1 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -206,7 +206,9 @@ public: void mpi_send(int n, int task_number); void mpi_recv(int task_number); #endif +#ifdef ORCHESTRA void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); +#endif protected: // Tidied classes std::map Solutions; diff --git a/System.cxx b/System.cxx index ed5e3c54..f8d8bb31 100644 --- a/System.cxx +++ b/System.cxx @@ -79,6 +79,7 @@ void cxxSystem::totalize(void) //this->totals.dump_raw(std::cerr, 1); return; } +#ifdef ORCHESTRA void cxxSystem::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) { // @@ -214,88 +215,6 @@ void cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) chemistry_dat << "\")" << std::endl; chemistry_dat << std::endl; } -#ifdef SKIP -void cxxSystem::ORCH_write_input(std::ostream &input_dat) -{ - - -// -// Write orchestra input file info -// - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; - - - headings << "tempc\t"; - data << this->solution->get_tc() << "\t"; - - headings << "pH\t"; - data << this->solution->get_ph() << "\t"; - - headings << "pe\t"; - data << this->solution->get_pe() << "\t"; - - headings << "H2O.act\t"; - data << 1 << "\t"; - - for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) - { - if (iter->first == "O") continue; - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch (iter->first); - assert (master_ptr != NULL); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - { - coef = 1; - } - if (iter->first == "H") - { - headings << "system_hydrogen" << "\t"; - data << iter->second << "\t"; - continue; - } else - { - headings << master_ptr->s->name << ".liter" << "\t"; - data << iter->second / coef << "\t"; - } - - // activity estimate - cxxNameDouble ma = this->solution->get_master_activity(); - cxxNameDouble::iterator it = ma.find(iter->first); - if (it == ma.end()) - { - it = ma.find(master_ptr->s->secondary->elt->name); - } - headings << master_ptr->s->name << ".act\t"; - if (it != ma.end()) - { - data << pow(10., it->second) << "\t"; - } else - { - data << 1e-9 << "\t"; - } - } - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; - - return; -} -#endif void cxxSystem::ORCH_write_input(std::ostream &input_dat) { @@ -495,7 +414,6 @@ void cxxSystem::ORCH_write_output_vars(std::ostream &outstream) for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) { if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - struct species *s_ptr = s_search(it->first); outstream << "\t" << it->first << ".act"; } outstream << "\tend_master_activities"; @@ -510,4 +428,5 @@ void cxxSystem::ORCH_write_output_vars(std::ostream &outstream) outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; } outstream << "\tend_species"; -} \ No newline at end of file +} +#endif diff --git a/System.h b/System.h index 6dfe7bb9..f3439283 100644 --- a/System.h +++ b/System.h @@ -48,6 +48,7 @@ public: this->temperature = entity; } void totalize(); +#ifdef ORCHESTRA void ORCH_components(); void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); void ORCH_write_chemistry_water(std::ostream &chemistry_dat); @@ -55,6 +56,7 @@ public: void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); void ORCH_write_output_vars(std::ostream &outstream); void ORCH_write_input(std::ostream &input_dat); +#endif private: cxxSolution *solution; From e3859a08c39089c879cd71ec0e014ca1472afb76 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 28 Aug 2007 20:45:29 +0000 Subject: [PATCH 0066/1077] reordering mpi.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2189 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 6 ++++-- StorageBin.cxx | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 20c2fb72..2cce8e18 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -4,7 +4,10 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - +#ifdef USE_MPI +//MPICH seems to require mpi.h to be first + #include +#endif #include "Utils.h" // define first #include "Solution.h" #define EXTERNAL extern @@ -1073,7 +1076,6 @@ void cxxSolution::ORCH_store_global(std::map < std::string, double > output_map) } #endif #ifdef USE_MPI -#include /* ---------------------------------------------------------------------- */ void cxxSolution::mpi_pack(std::vector& ints, std::vector& doubles) /* ---------------------------------------------------------------------- */ diff --git a/StorageBin.cxx b/StorageBin.cxx index 65eaadda..ebba0f9b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -4,6 +4,10 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#ifdef USE_MPI +//MPICH seems to require mpi.h to be first + #include +#endif #include #include // std::cout std::cerr @@ -663,7 +667,6 @@ struct system *cxxStorageBin::cxxStorageBin2system(int n) return system_ptr; } #ifdef USE_MPI -#include void cxxStorageBin::mpi_send(int n, int task_number) { // From 75255ea2f2dfdf25f95317813888e46e238f6422 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Aug 2007 16:36:35 +0000 Subject: [PATCH 0067/1077] No memory leak check in output files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2205 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8519b745..400edc56 100644 --- a/Makefile +++ b/Makefile @@ -79,18 +79,16 @@ ifeq ($(CFG), RELEASE) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - CXXFLAGS_MODEL = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} endif ifeq ($(CFG), DEBUG) - DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP + DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP -DUSE_PHRQ_ALLOC VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - CXXFLAGS_MODEL = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} endif @@ -355,7 +353,6 @@ mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ ../phreeqc/phrqproto.h ../phreeqc/input.h model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h - ${CXX} ${CXXFLAGS_MODEL} -c -o $@ $< nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ From 8d475282bf1b7b80570606cd3365483d6c8ba1e8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Sep 2007 19:09:38 +0000 Subject: [PATCH 0068/1077] Added read_raw_keyword. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2271 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 1 + 2 files changed, 93 insertions(+) diff --git a/StorageBin.cxx b/StorageBin.cxx index ebba0f9b..409cb60b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -348,7 +348,99 @@ void cxxStorageBin::read_raw(CParser& parser) END_OF_SIMULATION_INPUT: return; //CParser::LT_OK; } +int cxxStorageBin::read_raw_keyword(CParser& parser) +{ + CParser::LINE_TYPE i; + int entity_number = -999; + switch(parser.next_keyword()) + { + case CParser::KT_NONE: + case CParser::KT_END: + while ((i = parser.check_line("StorageBin read_raw_keyword", false, true, true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) break; // CParser::LT_EOF; + } + break; + case CParser::KT_EOF: + break; + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ + case CParser::KT_SOLUTION_RAW: + { + cxxSolution entity; + entity.read_raw(parser); + Solutions[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_EXCHANGE_RAW: + { + cxxExchange entity; + entity.read_raw(parser); + Exchangers[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_GASPHASE_RAW: + { + cxxGasPhase entity; + entity.read_raw(parser); + GasPhases[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_KINETICS_RAW: + { + cxxKinetics entity; + entity.read_raw(parser); + Kinetics[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_PPASSEMBLAGE_RAW: + { + cxxPPassemblage entity; + entity.read_raw(parser); + PPassemblages[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_SSASSEMBLAGE_RAW: + { + cxxSSassemblage entity; + entity.read_raw(parser); + SSassemblages[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_SURFACE_RAW: + { + cxxSurface entity; + entity.read_raw(parser); + Surfaces[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + default: + break; + } + return(entity_number); //CParser::LT_OK; +} void cxxStorageBin::add(struct system * system_ptr) // // add data from a system structure diff --git a/StorageBin.h b/StorageBin.h index bcb86ca1..f806e08b 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -186,6 +186,7 @@ public: void dump_raw(std::ostream& s_oss, int i, unsigned int indent); void read_raw(CParser& parser); + int read_raw_keyword(CParser& parser); void add(struct system *sys_ptr); From e7ec5c7691a942de96adfbf2e026307e3fa0338b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Sep 2007 19:01:46 +0000 Subject: [PATCH 0069/1077] Removed echo that was always true. Made huge string that crashed restart. Results are same without the removed lines. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2276 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Parser.cxx b/Parser.cxx index 57db6cb8..fb94842c 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -563,6 +563,7 @@ int CParser::get_option(const std::vector& opt_list, std::string::i // char option[MAX_LENGTH]; std::string option; + fprintf(stderr, "Did not think this get_option was called\n"); // // Read line // @@ -689,6 +690,7 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: //{{ //// m_line_iss.clear(); //}} +/* if (true) // pr.echo_input == TRUE { if (true) // database_file == NULL @@ -696,13 +698,16 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: get_output() << "\t" << m_line_save << "\n"; } } +*/ } else { +/* if (true) // (database_file == NULL) { get_output() << "\t" << m_line_save << "\n"; } +*/ //error_msg("Unknown option.", OT_CONTINUE); //error_msg(m_line_save.c_str(), OT_CONTINUE); //incr_input_error(); @@ -724,13 +729,16 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: j = OPT_DEFAULT; next_pos = 0; } +/* if (true) // pr.echo_input == TRUE { if (true) // database_file == NULL { + fprintf(stderr, "Yikes 3\n"); get_output() << "\t" << m_line_save << "\n"; } } +*/ } return (j); } From 3f93ab5a1c84d7504d644d2146378c9335fb7a5e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Nov 2007 18:28:25 +0000 Subject: [PATCH 0070/1077] Tried optimizing get_total_element using std::strings git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2374 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Solution.cxx b/Solution.cxx index 2cce8e18..828fdf15 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -853,6 +853,7 @@ double cxxSolution::get_total_element(char *string)const double d = 0.0; for (it = this->totals.begin(); it != this->totals.end(); ++it) { +#ifdef SKIP char token[MAX_LENGTH], token1[MAX_LENGTH]; int n; char *ptr; @@ -863,6 +864,19 @@ double cxxSolution::get_total_element(char *string)const if (strcmp(token1, string) == 0) { d += it->second; } +#endif + std::string ename(string); + std::string current_ename(string); + std::basic_string ::size_type indexCh; + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + if (current_ename == ename) + { + d += it->second; + } } return(d); } From f4777a194bc4a9f93e2651090a2b5c9499bbff3d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Nov 2007 22:23:47 +0000 Subject: [PATCH 0071/1077] Fixed bug, and streamlined. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2376 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index 828fdf15..2970c091 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -865,8 +865,17 @@ double cxxSolution::get_total_element(char *string)const d += it->second; } #endif + char token[MAX_LENGTH], token1[MAX_LENGTH]; + int n; + char *ptr; + strcpy(token, it->first); + replace("(", "\0", token); + if (strcmp(token, string) == 0) { + d += it->second; + } +#ifdef SKIP std::string ename(string); - std::string current_ename(string); + std::string current_ename(it->first); std::basic_string ::size_type indexCh; indexCh = current_ename.find("("); if (indexCh != std::string::npos) @@ -877,6 +886,7 @@ double cxxSolution::get_total_element(char *string)const { d += it->second; } +#endif } return(d); } From 5764f894ad73a414f1cdad300aaa9a782699494f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Nov 2007 00:08:45 +0000 Subject: [PATCH 0072/1077] Simplified get_total_element a bit git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2378 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 2970c091..00b22849 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -853,27 +853,18 @@ double cxxSolution::get_total_element(char *string)const double d = 0.0; for (it = this->totals.begin(); it != this->totals.end(); ++it) { -#ifdef SKIP - char token[MAX_LENGTH], token1[MAX_LENGTH]; - int n; - char *ptr; - strcpy(token, it->first); - replace("(", " ", token); - ptr = token; - copy_token(token1, &ptr, &n); - if (strcmp(token1, string) == 0) { - d += it->second; - } -#endif - char token[MAX_LENGTH], token1[MAX_LENGTH]; - int n; - char *ptr; - strcpy(token, it->first); - replace("(", "\0", token); - if (strcmp(token, string) == 0) { - d += it->second; + char token[MAX_LENGTH]; + if (it->first[0] == string[0]) + { + strcpy(token, it->first); + replace("(", "\0", token); + if (strcmp(token, string) == 0) + { + d += it->second; + } } #ifdef SKIP + // C++ way to do it std::string ename(string); std::string current_ename(it->first); std::basic_string ::size_type indexCh; From 711f5f948ec1a2540ec33683b3acdcaf2e6ffb30 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Nov 2007 21:34:23 +0000 Subject: [PATCH 0073/1077] Fixed syntax for bash cat file > xxx 2>&1; Weird. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2414 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 400edc56..47e9c2a9 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,16 @@ PROGRAM = phreeqcpp +CFG1 :=`uname` +CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") +ifeq ($(CFG), CYGWIN) + SPOOL=> + SPOOL2=2>&1 +else + SPOOL=>& + SPOOL2= +endif + all: release debug RELEASE_DIR = Release @@ -415,8 +425,8 @@ dependencies: cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx tester: - cd ../mytest; make clean; make -k >& make.out; make zero; make diff >& diff.out - cd ../examples; make clean; make >& make.out; make zero; make diff >& diff.out + cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples From f630dd837712b3503175e0617ec4e6f8da8c8372 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 15 Jan 2008 01:20:44 +0000 Subject: [PATCH 0074/1077] added linker option to check for --hash-style availability git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2531 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 47e9c2a9..91db42e0 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,11 @@ RELEASE_DIR = Release DEBUG_DIR = Debug MAKEFILE = Makefile +# ----------------------------------------------------------------------------- +# fixes shared object lookup error(SIGFPE floating point exception) +HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) + + ######################### #### Serial Versions #### ######################### @@ -90,7 +95,7 @@ ifeq ($(CFG), RELEASE) CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif ifeq ($(CFG), DEBUG) @@ -100,7 +105,7 @@ ifeq ($(CFG), DEBUG) CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif # ----------------------------------------------------------------------------- @@ -430,6 +435,13 @@ tester: svn status -q ../mytest svn status -q ../examples +#ld-option +# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) +comma=, +ld-option = $(shell if $(CC) $(1) \ + -nostdlib -o /dev/null -xc /dev/null \ + > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) + # ============================================================================= # End of makefile. # ============================================================================= From 3f9693c68ce553cb3d95de07e9fc5ec743e58f5b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Feb 2008 21:41:45 +0000 Subject: [PATCH 0075/1077] Updated C++ to have new variables for KINETICS cvode_steps, cvode_order. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2684 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 59 +++++++++++++++++++++++++++++++++++++++++++++++-- cxxKinetics.h | 2 ++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 94962dce..e65462e1 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -29,6 +29,8 @@ cxxKinetics::cxxKinetics() rk = 3; bad_step_max = 500; use_cvode = false; + cvode_steps = 100; + cvode_order = 5; totals.type = cxxNameDouble::ND_ELT_MOLES; } @@ -49,6 +51,8 @@ totals(kinetics_ptr->totals) rk = kinetics_ptr->rk; bad_step_max = kinetics_ptr->bad_step_max; use_cvode = (kinetics_ptr->use_cvode == TRUE); + cvode_steps = kinetics_ptr->cvode_steps; + cvode_order = kinetics_ptr->cvode_order; // kinetics components for (i = 0; i < kinetics_ptr->count_comps; i++) { @@ -70,6 +74,8 @@ cxxNumKeyword() rk = 3; bad_step_max = 500; use_cvode = false; + cvode_steps = 100; + cvode_order = 5; totals.type = cxxNameDouble::ND_ELT_MOLES; // // Mix @@ -103,6 +109,8 @@ struct kinetics *cxxKinetics::cxxKinetics2kinetics() kinetics_ptr->rk = this->rk; kinetics_ptr->bad_step_max = this->bad_step_max; kinetics_ptr->use_cvode = (int) this->use_cvode; + kinetics_ptr->cvode_steps = this->cvode_steps; + kinetics_ptr->cvode_order = this->cvode_order; // totals kinetics_ptr->totals = this->totals.elt_list(); @@ -184,7 +192,13 @@ void cxxKinetics::dump_raw(std::ostream& s_oss, unsigned int indent)const s_oss << indent1; s_oss << "-use_cvode " << this->use_cvode << std::endl; - // kineticsComps structures + s_oss << indent1; + s_oss << "-cvode_steps " << this->cvode_steps << std::endl; + + s_oss << indent1; + s_oss << "-cvode_order " << this->cvode_order << std::endl; + + // kineticsComps structures for (std::list::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; @@ -225,10 +239,12 @@ void cxxKinetics::read_raw(CParser& parser) vopts.push_back("step_divide"); vopts.push_back("rk"); vopts.push_back("bad_step_max"); - vopts.push_back("use_cvode"); + vopts.push_back("use_cvode"); vopts.push_back("component"); vopts.push_back("totals"); vopts.push_back("steps"); + vopts.push_back("cvode_steps"); + vopts.push_back("cvode_order"); } std::istream::pos_type ptr; @@ -245,6 +261,8 @@ void cxxKinetics::read_raw(CParser& parser) bool rk_defined(false); bool bad_step_max_defined(false); bool use_cvode_defined(false); + bool cvode_steps_defined(false); + bool cvode_order_defined(false); for (;;) { @@ -347,6 +365,29 @@ void cxxKinetics::read_raw(CParser& parser) } opt_save = 6; useLastLine = false; + + case 7: // cvode_steps + if (!(parser.get_iss() >> this->cvode_steps)) + { + this->cvode_steps = 100; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_steps.", CParser::OT_CONTINUE); + } + cvode_steps_defined = true; + useLastLine = false; + break; + + case 8: // cvode_order + if (!(parser.get_iss() >> this->cvode_order)) + { + this->cvode_order = 5; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_order.", CParser::OT_CONTINUE); + } + cvode_order_defined = true; + useLastLine = false; + break; + } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -367,6 +408,14 @@ void cxxKinetics::read_raw(CParser& parser) parser.incr_input_error(); parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); } + if (cvode_steps_defined == false) { + parser.incr_input_error(); + parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } + if (cvode_order_defined == false) { + parser.incr_input_error(); + parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); + } } #ifdef USE_MPI void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) @@ -384,6 +433,8 @@ void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) ints.push_back(this->rk); ints.push_back(this->bad_step_max); ints.push_back(this->use_cvode); + ints.push_back(this->cvode_steps); + ints.push_back(this->cvode_order); } void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { @@ -409,6 +460,8 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->rk = ints[i++]; this->bad_step_max = ints[i++]; this->use_cvode = (ints[i++] == TRUE); + this->cvode_steps = ints[i++]; + this->cvode_order = ints[i++]; *ii = i; *dd = d; } @@ -449,4 +502,6 @@ void cxxKinetics::add(const cxxKinetics &addee, double extensive) this->bad_step_max = addee.bad_step_max; //bool use_cvode; this->use_cvode = addee.use_cvode; + this->cvode_steps = addee.cvode_steps; + this->cvode_order = addee.cvode_order; } diff --git a/cxxKinetics.h b/cxxKinetics.h index 2bf75b83..595695ea 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -52,6 +52,8 @@ protected: int rk; int bad_step_max; bool use_cvode; + int cvode_steps; + int cvode_order; public: //static std::map& map; From bfec3cc7c72a1ee9609c0779208951073b3ed8fc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Feb 2008 23:14:24 +0000 Subject: [PATCH 0076/1077] Missing break in kinetics_read_raw switch. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2693 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index e65462e1..184937af 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -350,6 +350,7 @@ void cxxKinetics::read_raw(CParser& parser) } opt_save = 5; useLastLine = false; + break; case 6: // steps while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { @@ -365,6 +366,7 @@ void cxxKinetics::read_raw(CParser& parser) } opt_save = 6; useLastLine = false; + break; case 7: // cvode_steps if (!(parser.get_iss() >> this->cvode_steps)) From b9520a207fa3ae8b6b953fe1ba4c9e0f54c5ed22 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 14 Feb 2008 17:56:32 +0000 Subject: [PATCH 0077/1077] Worked on dependencies for Makefile. Made dependencies the same for serial and parallel, can check with make depends and make depends_parallel, dependencies and dependencies_parallel should be the same. Modified fortran with -I/usr/include for gfortran compiler to find mpif.h. Now use mpif.h in mpimod.F90 to define MPI_COMM_WORLD. Dictionary.h moved in cxx files to make serial and parallel dependencies the same. Ifdef'd mpimod to exclude everything in module for serial version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2707 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 2 +- KineticsComp.cxx | 2 +- NameDouble.cxx | 2 +- PPassemblageComp.cxx | 2 +- Pe_Data.cxx | 45 -------------------------------------------- Pe_Data.h | 28 --------------------------- SSassemblageSS.cxx | 2 +- SurfaceCharge.cxx | 2 +- SurfaceComp.cxx | 2 +- 9 files changed, 7 insertions(+), 80 deletions(-) delete mode 100644 Pe_Data.cxx delete mode 100644 Pe_Data.h diff --git a/ExchComp.cxx b/ExchComp.cxx index 3971b176..a9ec5623 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -7,6 +7,7 @@ #include // std::cout std::cerr #include "Utils.h" // define first #include "ExchComp.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -523,7 +524,6 @@ void cxxExchComp::multiply(double extensive) //double formula_z; } #ifdef USE_MPI -#include "Dictionary.h" void cxxExchComp::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index bb4b7867..c93f5d30 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -7,6 +7,7 @@ #include "Utils.h" // define first #include "KineticsComp.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -310,7 +311,6 @@ void cxxKineticsComp::read_raw(CParser& parser) } } #ifdef USE_MPI -#include "Dictionary.h" void cxxKineticsComp::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; diff --git a/NameDouble.cxx b/NameDouble.cxx index af5b5087..b79e8dfb 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -8,6 +8,7 @@ #include // std::cout std::cerr #include "Utils.h" // define first #include "NameDouble.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "output.h" @@ -372,7 +373,6 @@ void cxxNameDouble::multiply(double extensive) } } #ifdef USE_MPI -#include "Dictionary.h" void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; ints.push_back( (int) (*this).size() ); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 6d55b2c5..4d2e77b0 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -7,6 +7,7 @@ #include "Utils.h" // define first #include "PPassemblageComp.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -299,7 +300,6 @@ void cxxPPassemblageComp::read_raw(CParser& parser) } #ifdef USE_MPI -#include "Dictionary.h" void cxxPPassemblageComp::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; diff --git a/Pe_Data.cxx b/Pe_Data.cxx deleted file mode 100644 index 19070934..00000000 --- a/Pe_Data.cxx +++ /dev/null @@ -1,45 +0,0 @@ -#include "Pe_Data.h" -#include "Utilities.h" -#include // std::ostream - -cxxPe_Data::cxxPe_Data() -: name("") -{ -} - -cxxPe_Data::cxxPe_Data(const std::string& name) -: name(name) -{ -} - -cxxPe_Data::~cxxPe_Data() -{ -} - -int cxxPe_Data::store(std::vector& vec_pe_data, const std::string& token) -{ - unsigned int i = 0; - unsigned int size = vec_pe_data.size(); - for (; i < size; ++i) { - if (vec_pe_data[i].name.compare(token) == 0) - return i; - } - vec_pe_data.push_back(token); - return i; -} - -std::vector cxxPe_Data::alloc() -{ - std::vector vec; - vec.push_back(cxxPe_Data("pe")); - // TODO: see pe_data_alloc - return vec; -} - -void cxxPe_Data::dump_xml(std::ostream& os, unsigned int indent)const -{ - unsigned int i; - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "" << this->name << "\n"; -} - diff --git a/Pe_Data.h b/Pe_Data.h deleted file mode 100644 index b26ff260..00000000 --- a/Pe_Data.h +++ /dev/null @@ -1,28 +0,0 @@ -#if !defined(PE_DATA_H_INCLUDED) -#define PE_DATA_H_INCLUDED - -#include -#include - -class cxxPe_Data -{ -public: - cxxPe_Data(); - cxxPe_Data(struct pe *pe_ptr); - cxxPe_Data(const std::string& name); - - ~cxxPe_Data(); - - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - - std::string get_name()const {return this->name;}; - void set_name(std::string name) {this->name = name;}; - - static int store(std::vector& vec, const std::string& token); - static std::vector cxxPe_Data::alloc(); - -private: - std::string name; -}; - -#endif // PE_DATA_H_INCLUDED diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 890429ee..daa9a9cc 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -8,6 +8,7 @@ #include "Utils.h" // define first #include "SSassemblageSS.h" #include "NameDouble.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -442,7 +443,6 @@ void cxxSSassemblageSS::read_raw(CParser& parser) } #ifdef USE_MPI -#include "Dictionary.h" void cxxSSassemblageSS::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 68d61293..13bd836a 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -7,6 +7,7 @@ #include "Utils.h" // define first #include "SurfaceCharge.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "output.h" @@ -386,7 +387,6 @@ void cxxSurfaceCharge::read_raw(CParser& parser) } } #ifdef USE_MPI -#include "Dictionary.h" void cxxSurfaceCharge::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index ceec1387..b7c9d747 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -7,6 +7,7 @@ #include "Utils.h" // define first #include "SurfaceComp.h" +#include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -408,7 +409,6 @@ void cxxSurfaceComp::read_raw(CParser& parser) } } #ifdef USE_MPI -#include "Dictionary.h" void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubles) { extern cxxDictionary dictionary; From 25666df97c6a8d2277720912c980c126562090ad Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Feb 2008 22:05:11 +0000 Subject: [PATCH 0078/1077] Used new gcc on srv2rcolkr. Cleaned up all the const errors when using constant string in arguments to functions. removed ex1. Modified makefile to include/exclude cl1mp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2712 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 3 +- ISolutionComp.cxx | 3 +- Makefile | 15 ++++++--- NameDouble.cxx | 5 ++- NameDouble.h | 2 +- System.cxx | 10 ++++-- ex1 | 77 ----------------------------------------------- 7 files changed, 27 insertions(+), 88 deletions(-) delete mode 100644 ex1 diff --git a/ISolution.cxx b/ISolution.cxx index a9e14528..65f68667 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -87,7 +87,8 @@ void cxxISolution::ConvertUnits() { struct master *master_ptr = master_bsearch (iter->first); if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; - if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; + //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; + if (strcmp(iter->second.get_description(),"H(1)") == 0 || strcmp(iter->second.get_description(), "E")) continue; if (iter->second.get_input_conc() <= 0.0) continue; /* * Convert liters to kg solution diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 09886e09..69c45d1d 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -116,7 +116,8 @@ void cxxISolutionComp::set_gfw() input_error++; return; } - if (this->description == "Alkalinity" && this->as == "CaCO3") + //if (this->description == "Alkalinity" && this->as == "CaCO3") + if (strcmp(this->description,"Alkalinity") == 0 && strcmp(this->as, "CaCO3")) { gfw /= 2.; } diff --git a/Makefile b/Makefile index 91db42e0..1fe1b048 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,11 @@ endif all: release debug +Release: release + +Debug: debug + + RELEASE_DIR = Release DEBUG_DIR = Debug MAKEFILE = Makefile @@ -78,8 +83,10 @@ debug: # #define gmp for inverse modeling # comment the following lines to remove multiprecision option DINVERSE_CL1MP=TRUE -CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a -CL1MP_OBJS=cl1mp.o +ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +endif # ----------------------------------------------------------------------------- #efence for debugging @@ -89,7 +96,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), RELEASE) - DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP + DEFINES = -DPHREEQC_CPP $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ @@ -99,7 +106,7 @@ ifeq ($(CFG), RELEASE) endif ifeq ($(CFG), DEBUG) - DEFINES = -DPHREEQC_CPP -DINVERSE_CL1MP -DUSE_PHRQ_ALLOC + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ diff --git a/NameDouble.cxx b/NameDouble.cxx index b79e8dfb..d9cc422a 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -349,11 +349,14 @@ void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, do } } -void cxxNameDouble::add(char * key, double total) +void cxxNameDouble::add(const char * token, double total) // // add to total for a specified element // { + char key[MAX_LENGTH]; + strcpy(key, token); + cxxNameDouble::iterator current = (*this).find(key); if (current != (*this).end()) { (*this)[key] = current->second + total; diff --git a/NameDouble.h b/NameDouble.h index e0098bfe..43130853 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -48,7 +48,7 @@ public: void add_extensive(const cxxNameDouble &old, double factor); void add_intensive(const cxxNameDouble &addee, double fthis, double f2); void add_log_activities(const cxxNameDouble &addee, double fthis, double f2); - void add(char * key, double total); + void add(const char * key, double total); void multiply(double factor); void insert(char *str, double d) { diff --git a/System.cxx b/System.cxx index f8d8bb31..efa912c4 100644 --- a/System.cxx +++ b/System.cxx @@ -39,9 +39,13 @@ void cxxSystem::totalize(void) //add solution if (this->solution != NULL) { - this->totals["O"] = this->solution->get_total_o(); - this->totals["H"] = this->solution->get_total_h(); - this->totals["Charge"] = this->solution->get_cb(); + char token[MAX_LENGTH]; + strcpy(token, "O"); + this->totals[token] = this->solution->get_total_o(); + strcpy(token, "H"); + this->totals[token] = this->solution->get_total_h(); + strcpy(token, "Charge"); + this->totals[token] = this->solution->get_cb(); this->totals.add_extensive(this->solution->get_totals(), 1.0); } if (this->exchange != NULL) diff --git a/ex1 b/ex1 deleted file mode 100644 index 8021fa1a..00000000 --- a/ex1 +++ /dev/null @@ -1,77 +0,0 @@ -PRINT - -status false -TITLE Example 1.--Add uranium and speciate seawater. -SOLUTION 1 SEAWATER FROM NORDSTROM ET AL. (1979) - units ppm - pH 8.22 - pe 8.451 - density 1.023 - temp 25.0 - redox O(0)/O(-2) - Ca 412.3 - Mg 1291.8 - Na 10768.0 - K 399.1 - Fe 0.002 - Mn 0.0002 pe - Si 4.28 - Cl 19353.0 - Alkalinity 141.682 as HCO3 - S(6) 2712.0 - N(5) 0.29 gfw 62.0 - N(-3) 0.03 as NH4 - U 3.3 ppb N(5)/N(-3) - O(0) 1.0 O2(g) -0.7 - 12C 1 .1 -SOLUTION_MASTER_SPECIES - U U+4 0.0 238.0290 238.0290 - U(4) U+4 0.0 238.0290 - U(5) UO2+ 0.0 238.0290 - U(6) UO2+2 0.0 238.0290 -SOLUTION_SPECIES - #primary master species for U - #is also secondary master species for U(4) - U+4 = U+4 - log_k 0.0 - U+4 + 4 H2O = U(OH)4 + 4 H+ - log_k -8.538 - delta_h 24.760 kcal - U+4 + 5 H2O = U(OH)5- + 5 H+ - log_k -13.147 - delta_h 27.580 kcal - #secondary master species for U(5) - U+4 + 2 H2O = UO2+ + 4 H+ + e- - log_k -6.432 - delta_h 31.130 kcal - #secondary master species for U(6) - U+4 + 2 H2O = UO2+2 + 4 H+ + 2 e- - log_k -9.217 - delta_h 34.430 kcal - UO2+2 + H2O = UO2OH+ + H+ - log_k -5.782 - delta_h 11.015 kcal - 2UO2+2 + 2H2O = (UO2)2(OH)2+2 + 2H+ - log_k -5.626 - delta_h -36.04 kcal - 3UO2+2 + 5H2O = (UO2)3(OH)5+ + 5H+ - log_k -15.641 - delta_h -44.27 kcal - UO2+2 + CO3-2 = UO2CO3 - log_k 10.064 - delta_h 0.84 kcal - UO2+2 + 2CO3-2 = UO2(CO3)2-2 - log_k 16.977 - delta_h 3.48 kcal - UO2+2 + 3CO3-2 = UO2(CO3)3-4 - log_k 21.397 - delta_h -8.78 kcal -PHASES - Uraninite - UO2 + 4 H+ = U+4 + 2 H2O - log_k -3.490 - delta_h -18.630 kcal -END -USE solution 1 -REACTION_TEMPERATURE - 30 -END \ No newline at end of file From d106dbea5c7da5943747a7a3be6ceabd2bcf7d55 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Feb 2008 23:28:29 +0000 Subject: [PATCH 0079/1077] Added missing tests from phreeqc/mytest and related files: netpathxl eq_EC salt_ec Fixed Makefile to include gmp library and fix typo on INVERSE_CL1MP definition. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2713 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1fe1b048..dbc52345 100644 --- a/Makefile +++ b/Makefile @@ -82,10 +82,11 @@ debug: # ----------------------------------------------------------------------------- # #define gmp for inverse modeling # comment the following lines to remove multiprecision option -DINVERSE_CL1MP=TRUE +INVERSE_CL1MP=TRUE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o + CL1MP_LIB=-lgmp endif # ----------------------------------------------------------------------------- From 7a60bb98774ed433b952048a48857c9c60e08342 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 11 Mar 2008 22:04:33 +0000 Subject: [PATCH 0080/1077] Write around assert. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2746 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Surface.cxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Surface.cxx b/Surface.cxx index 81c6565d..ab3bf3d9 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -170,16 +170,19 @@ struct surface *cxxSurface::cxxSurface2surface() surface_ptr->count_charge = 0; } // Need to fill in charge (number) in comps list - int i,j; - for (i = 0; i < surface_ptr->count_comps; i++) { - char *charge_name = cxxSurfaceComp::get_charge_name(surface_ptr->comps[i].formula); - for (j = 0; j < surface_ptr->count_charge; j++) { - if (charge_name == surface_ptr->charge[j].name) { - surface_ptr->comps[i].charge = j; - break; + if (surface_ptr->type != NO_EDL) + { + int i,j; + for (i = 0; i < surface_ptr->count_comps; i++) { + char *charge_name = cxxSurfaceComp::get_charge_name(surface_ptr->comps[i].formula); + for (j = 0; j < surface_ptr->count_charge; j++) { + if (charge_name == surface_ptr->charge[j].name) { + surface_ptr->comps[i].charge = j; + break; + } } + assert(j < surface_ptr->count_charge); } - assert(j < surface_ptr->count_charge); } return(surface_ptr); From 193e8ef865dc25fceabf3471b5f1c6d615dff83f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 24 Apr 2008 23:59:55 +0000 Subject: [PATCH 0081/1077] Bug with adding mixing solution when already in list. Replaced old fraction with new fraction. Now adds the two fractions. This created a bug with rivers when mixing with the same solution. The mass fraction was calculated incorrectly because only the second part of the solution was used (solution, frac 2). git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@2888 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxMix.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cxxMix.h b/cxxMix.h index 6084c0e5..0131d937 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -29,7 +29,13 @@ public: void read_raw(CParser& parser); void add(int n, double f) { - mixComps[n] = f; + if (this->mixComps.find(n) != this->mixComps.end()) + { + mixComps[n] += f; + } else + { + mixComps[n] = f; + } }; std::map *comps() {return &mixComps;} From 60d57c5062fffe2c2b761f0ab9253964f123a903 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 18 Sep 2008 15:46:01 +0000 Subject: [PATCH 0082/1077] Delete kinetics.h at PhreeqcPP src level. Duplicate I assume git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3099 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.h | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 kinetics.h diff --git a/kinetics.h b/kinetics.h deleted file mode 100644 index 60df9d12..00000000 --- a/kinetics.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef PHREEQC_IDENT -static char const svnidkinetics[] = "$Id$"; -#endif -KINETICS_EXTERNAL void *cvode_kinetics_ptr; -KINETICS_EXTERNAL int cvode_test; -KINETICS_EXTERNAL int cvode_error; -KINETICS_EXTERNAL int cvode_n_user; -KINETICS_EXTERNAL int cvode_n_reactions; -KINETICS_EXTERNAL realtype cvode_step_fraction; -KINETICS_EXTERNAL realtype cvode_rate_sim_time; -KINETICS_EXTERNAL realtype cvode_rate_sim_time_start; -KINETICS_EXTERNAL realtype cvode_last_good_time; -KINETICS_EXTERNAL realtype cvode_prev_good_time; -KINETICS_EXTERNAL N_Vector cvode_last_good_y; -KINETICS_EXTERNAL N_Vector cvode_prev_good_y; -KINETICS_EXTERNAL M_Env kinetics_machEnv; -KINETICS_EXTERNAL N_Vector kinetics_y, kinetics_abstol; -KINETICS_EXTERNAL void *kinetics_cvode_mem; -KINETICS_EXTERNAL struct pp_assemblage *cvode_pp_assemblage_save; -KINETICS_EXTERNAL struct s_s_assemblage *cvode_s_s_assemblage_save; - From 3313c814a988b130edc63c1283c815b94957804a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 31 Oct 2008 15:19:39 +0000 Subject: [PATCH 0083/1077] Ran indent program on phreeqcpp indent -bli0 -i4 -ts4 -npcs -nbc *.cxx git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3168 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cxx | 115 +- ExchComp.cxx | 942 +++++++------ Exchange.cxx | 686 +++++----- GasPhase.cxx | 600 +++++---- ISolution.cxx | 1698 +++++++++++++----------- ISolutionComp.cxx | 428 +++--- KineticsComp.cxx | 636 +++++---- NameDouble.cxx | 702 +++++----- NumKeyword.cxx | 205 +-- PPassemblage.cxx | 568 ++++---- PPassemblageComp.cxx | 694 +++++----- Parser.cxx | 1996 +++++++++++++++------------- Reaction.cxx | 524 ++++---- ReadClass.cxx | 540 +++++--- SAXPhreeqc.cxx | 1134 +++++++++------- SSassemblage.cxx | 394 +++--- SSassemblageSS.cxx | 900 +++++++------ Solution.cxx | 2758 +++++++++++++++++++++------------------ SolutionIsotope.cxx | 405 +++--- SolutionIsotopeList.cxx | 156 ++- StorageBin.cxx | 1232 +++++++++-------- Surface.cxx | 1243 ++++++++++-------- SurfaceCharge.cxx | 839 ++++++------ SurfaceComp.cxx | 972 ++++++++------ System.cxx | 942 +++++++------ Temperature.cxx | 422 +++--- Utils.cxx | 97 +- cxxKinetics.cxx | 840 ++++++------ cxxMix.cxx | 288 ++-- 29 files changed, 12741 insertions(+), 10215 deletions(-) diff --git a/Dictionary.cxx b/Dictionary.cxx index 287090b8..4566fa55 100644 --- a/Dictionary.cxx +++ b/Dictionary.cxx @@ -2,43 +2,50 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Dictionary.h" // define first +#include "Dictionary.h" // define first #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxDictionary::cxxDictionary() { - // default constructor for cxxStorageBin + // default constructor for cxxStorageBin } cxxDictionary::~cxxDictionary() { } -void cxxDictionary::add_phreeqc() { +void +cxxDictionary::add_phreeqc() +{ HashTable *Table = strings_hash_table; - int i,j; - Segment *seg; - Element *p,*q; + int i, j; + Segment *seg; + Element *p, *q; - if (Table != NULL) { - for (i = 0; i < Table->SegmentCount; i++) { - /* test probably unnecessary */ - if ((seg = Table->Directory[i]) != NULL) { - for (j = 0; j < SegmentSize; j++) { + if (Table != NULL) + { + for (i = 0; i < Table->SegmentCount; i++) + { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) + { + for (j = 0; j < SegmentSize; j++) + { p = seg[j]; - while (p != NULL) { + while (p != NULL) + { q = p->Next; //p->Data = (char*) free_check_null((void*)p->Data); this->putString((char *) (p->Data)); @@ -50,56 +57,82 @@ void cxxDictionary::add_phreeqc() { } } -int cxxDictionary::putString(std::string str) { +int +cxxDictionary::putString(std::string str) +{ int n; - std::map::iterator it = stringkey.find(str); - if (it != stringkey.end()) { + std::map < std::string, int >::iterator it = stringkey.find(str); + if (it != stringkey.end()) + { n = it->second; - } else { + } + else + { n = (int) stringkey.size(); stringkey[str] = n; intkey[n] = str; } - return(n); + return (n); } -int cxxDictionary::putString(char * str) { +int +cxxDictionary::putString(char *str) +{ std::string str1(str); return (putString(str1)); } -int cxxDictionary::string2int(std::string str) { +int +cxxDictionary::string2int(std::string str) +{ int n; - std::map::iterator it = stringkey.find(str); - if (it != stringkey.end()) { + std::map < std::string, int >::iterator it = stringkey.find(str); + if (it != stringkey.end()) + { n = it->second; - } else { + } + else + { n = -1; } - return(n); + return (n); } -int cxxDictionary::string2int(char * str) { - if (str == NULL) return (-1); +int +cxxDictionary::string2int(char *str) +{ + if (str == NULL) + return (-1); std::string str1(str); - return(string2int(str1)); + return (string2int(str1)); } -std::string *cxxDictionary::int2string(int i) { - std::map::iterator it = intkey.find(i); - if (it != intkey.end()) { - return(&it->second); - } else { - return(NULL); +std::string * cxxDictionary::int2string(int i) +{ + std::map < int, + std::string >::iterator + it = intkey.find(i); + if (it != intkey.end()) + { + return (&it->second); + } + else + { + return (NULL); } } -char *cxxDictionary::int2char(int i) { - std::map::iterator it = intkey.find(i); - if (it != intkey.end()) { - return(string_hsave(it->second.c_str())); - } else { - return(NULL); +char * +cxxDictionary::int2char(int i) +{ + std::map < int, std::string >::iterator it = intkey.find(i); + if (it != intkey.end()) + { + return (string_hsave(it->second.c_str())); + } + else + { + return (NULL); } } diff --git a/ExchComp.cxx b/ExchComp.cxx index a9ec5623..9abde51e 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -2,10 +2,10 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // std::cout std::cerr -#include "Utils.h" // define first +#include // std::cout std::cerr +#include "Utils.h" // define first #include "ExchComp.h" #include "Dictionary.h" #define EXTERNAL extern @@ -13,79 +13,86 @@ #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxExchComp::cxxExchComp() - // - // default constructor for cxxExchComp - // + // + // default constructor for cxxExchComp + // { - moles = 0.0; - formula_totals.type = cxxNameDouble::ND_ELT_MOLES; - totals.type = cxxNameDouble::ND_ELT_MOLES; - la = 0.0; - charge_balance = 0.0; - phase_name = NULL; - phase_proportion = 0.0; - rate_name = NULL; - formula_z = 0.0; + moles = 0.0; + formula_totals.type = cxxNameDouble::ND_ELT_MOLES; + totals.type = cxxNameDouble::ND_ELT_MOLES; + la = 0.0; + charge_balance = 0.0; + phase_name = NULL; + phase_proportion = 0.0; + rate_name = NULL; + formula_z = 0.0; } -cxxExchComp::cxxExchComp(struct exch_comp *exch_comp_ptr) - // - // constructor for cxxExchComp from struct exch_comp - // -: -formula_totals(exch_comp_ptr->formula_totals), -totals(exch_comp_ptr->totals) +cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr) + // + // constructor for cxxExchComp from struct exch_comp + // +: +formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) { - formula = exch_comp_ptr->formula; - moles = exch_comp_ptr->moles; - // totals in constructor - //formula_totals in constructor - la = exch_comp_ptr->la; - charge_balance = exch_comp_ptr->charge_balance; - phase_name = exch_comp_ptr->phase_name; - phase_proportion = exch_comp_ptr->phase_proportion; - rate_name = exch_comp_ptr->rate_name; - formula_z = exch_comp_ptr->formula_z; + formula = exch_comp_ptr->formula; + moles = exch_comp_ptr->moles; + // totals in constructor + //formula_totals in constructor + la = exch_comp_ptr->la; + charge_balance = exch_comp_ptr->charge_balance; + phase_name = exch_comp_ptr->phase_name; + phase_proportion = exch_comp_ptr->phase_proportion; + rate_name = exch_comp_ptr->rate_name; + formula_z = exch_comp_ptr->formula_z; } + #ifdef SKIP -cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vector &f_vector) - // - // constructor for cxxExchComp from mixing - // +cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, + std::vector < double >&f_vector) + // + // constructor for cxxExchComp from mixing + // { - if (ec_vector.size() <= 0) return; + if (ec_vector.size() <= 0) + return; // // check consistency // - std::vector::iterator it_f; - std::vector::iterator it_ec; + std::vector < double >::iterator it_f; + std::vector < cxxExchComp >::iterator it_ec; // set fixed variables it_ec = ec_vector.begin(); - this->formula = it_ec->formula; - this->formula_totals = it_ec->formula_totals; - this->formula_z = it_ec->formula_z; - this->phase_name = it_ec->phase_name; - this->rate_name = it_ec->rate_name; + this->formula = it_ec->formula; + this->formula_totals = it_ec->formula_totals; + this->formula_z = it_ec->formula_z; + this->phase_name = it_ec->phase_name; + this->rate_name = it_ec->rate_name; it_ec++; - for ( ; it_ec != ec_vector.end(); it_ec++) { + for (; it_ec != ec_vector.end(); it_ec++) + { if (it_ec->formula != this->formula || - it_ec->formula_z != this->formula_z || - it_ec->phase_name != this->phase_name || - this->rate_name != this->rate_name) { - error_msg("Mixing exchange components. Formula, z, phase_name, or rate_name did not match", STOP); + it_ec->formula_z != this->formula_z || + it_ec->phase_name != this->phase_name || + this->rate_name != this->rate_name) + { + error_msg + ("Mixing exchange components. Formula, z, phase_name, or rate_name did not match", + STOP); } } // calculate sum of extensive factors double sum_extensive = 0; - for (it_f = f_vector.begin(); it_f != f_vector.end(); it_f++) { + for (it_f = f_vector.begin(); it_f != f_vector.end(); it_f++) + { sum_extensive += *it_f; } this->moles = 0; @@ -96,13 +103,14 @@ cxxExchComp::cxxExchComp(std::vector &ec_vector, std::vectortotals.type = cxxNameDouble::ND_ELT_MOLES; it_ec = ec_vector.begin(); it_f = f_vector.begin(); - for (; it_ec != ec_vector.end(); ) { + for (; it_ec != ec_vector.end();) + { double extensive = *it_f; - double intensive = extensive/sum_extensive; - this->moles += it_ec->moles*extensive; - this->la += it_ec->la*intensive; - this->charge_balance += it_ec->charge_balance*extensive; - this->phase_proportion += it_ec->phase_proportion*intensive; + double intensive = extensive / sum_extensive; + this->moles += it_ec->moles * extensive; + this->la += it_ec->la * intensive; + this->charge_balance += it_ec->charge_balance * extensive; + this->phase_proportion += it_ec->phase_proportion * intensive; this->totals.add_extensive(it_ec->totals, extensive); it_ec++; it_f++; @@ -113,418 +121,526 @@ cxxExchComp::~cxxExchComp() { } -struct master *cxxExchComp::get_master() -{ - struct master *master_ptr = NULL; - for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { +struct master * +cxxExchComp::get_master() +{ + struct master *master_ptr = NULL; + for (std::map < char *, double, CHARSTAR_LESS >::iterator it = + totals.begin(); it != totals.end(); it++) + { - /* Find master species */ - char *eltName = it->first; - struct element *elt_ptr = element_store(eltName); - if (elt_ptr->master == NULL) { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; - //Utilities::error_msg(error_oss.str(), STOP); + /* Find master species */ + char *eltName = it->first; + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) + { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr-> + name << std::endl; + //Utilities::error_msg(error_oss.str(), STOP); error_msg(error_oss.str().c_str(), CONTINUE); - return(NULL); - } - if (elt_ptr->master->type != EX) continue; - master_ptr = elt_ptr->master; - break; - } - if (master_ptr == NULL) { - for (std::map ::iterator it = this->formula_totals.begin(); it != formula_totals.end(); it++) { + return (NULL); + } + if (elt_ptr->master->type != EX) + continue; + master_ptr = elt_ptr->master; + break; + } + if (master_ptr == NULL) + { + for (std::map < char *, double, CHARSTAR_LESS >::iterator it = + this->formula_totals.begin(); it != formula_totals.end(); it++) + { /* Find master species */ char *eltName = it->first; struct element *elt_ptr = element_store(eltName); - if (elt_ptr->master == NULL) { + if (elt_ptr->master == NULL) + { std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; + error_oss << "Master species not in data base for " << + elt_ptr->name << std::endl; //Utilities::error_msg(error_oss.str(), STOP); error_msg(error_oss.str().c_str(), CONTINUE); - return(NULL); + return (NULL); } - if (elt_ptr->master->type != EX) continue; + if (elt_ptr->master->type != EX) + continue; master_ptr = elt_ptr->master; break; } - } - if (master_ptr == NULL) { - std::ostringstream error_oss; - error_oss << "Exchange formula does not contain an exchange master species, " << this->formula << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); + } + if (master_ptr == NULL) + { + std::ostringstream error_oss; + error_oss << + "Exchange formula does not contain an exchange master species, " + << this->formula << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); error_msg(error_oss.str().c_str(), CONTINUE); std::ostringstream oss; this->dump_raw(oss, 0); std::cerr << oss.str(); - } - return(master_ptr); + } + return (master_ptr); } -struct exch_comp *cxxExchComp::cxxExchComp2exch_comp(std::list& el) - // - // Builds exch_comp structure from of cxxExchComp - // +struct exch_comp * +cxxExchComp::cxxExchComp2exch_comp(std::list < cxxExchComp > &el) + // + // Builds exch_comp structure from of cxxExchComp + // { - struct exch_comp *exch_comp_ptr = (struct exch_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); - if (exch_comp_ptr == NULL) malloc_error(); + struct exch_comp *exch_comp_ptr = + (struct exch_comp *) + PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); + if (exch_comp_ptr == NULL) + malloc_error(); - int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - exch_comp_ptr[i].formula = it->formula; - exch_comp_ptr[i].formula_z = it->formula_z; - exch_comp_ptr[i].totals = it->totals.elt_list(); - exch_comp_ptr[i].moles = it->moles; - exch_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); - exch_comp_ptr[i].la = it->la; - exch_comp_ptr[i].charge_balance = it->charge_balance; - exch_comp_ptr[i].phase_name = it->phase_name; - exch_comp_ptr[i].phase_proportion = it->phase_proportion; - exch_comp_ptr[i].rate_name = it->rate_name; - exch_comp_ptr[i].master = it->get_master(); - i++; - } - return(exch_comp_ptr); + int i = 0; + for (std::list < cxxExchComp >::iterator it = el.begin(); it != el.end(); + ++it) + { + exch_comp_ptr[i].formula = it->formula; + exch_comp_ptr[i].formula_z = it->formula_z; + exch_comp_ptr[i].totals = it->totals.elt_list(); + exch_comp_ptr[i].moles = it->moles; + exch_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); + exch_comp_ptr[i].la = it->la; + exch_comp_ptr[i].charge_balance = it->charge_balance; + exch_comp_ptr[i].phase_name = it->phase_name; + exch_comp_ptr[i].phase_proportion = it->phase_proportion; + exch_comp_ptr[i].rate_name = it->rate_name; + exch_comp_ptr[i].master = it->get_master(); + i++; + } + return (exch_comp_ptr); } -void cxxExchComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Exch_Comp element and attributes + // Exch_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; - s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; - s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; - if (this->phase_name != NULL) { - s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; - } - if (this->rate_name != NULL) { - s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; - } - s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula_z=\"" << this-> + formula_z << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this-> + charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) + { + s_oss << indent0 << "phase_name=\"" << this-> + phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) + { + s_oss << indent0 << "rate_name=\"" << this-> + rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this-> + phase_proportion << "\"" << std::endl; - // totals - s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); } -void cxxExchComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Exch_Comp element and attributes + // Exch_Comp element and attributes - s_oss << indent0 << "-formula " << this->formula << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-la " << this->la << std::endl; - s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; - if (this->phase_name != NULL) { - s_oss << indent0 << "-phase_name " << this->phase_name << std::endl; - } - if (this->rate_name != NULL) { - s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; - } - s_oss << indent0 << "-phase_proportion " << this->phase_proportion << std::endl; - s_oss << indent0 << "-formula_z " << this->formula_z << std::endl; + s_oss << indent0 << "-formula " << this-> + formula << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-la " << this->la << std::endl; + s_oss << indent0 << "-charge_balance " << this-> + charge_balance << std::endl; + if (this->phase_name != NULL) + { + s_oss << indent0 << "-phase_name " << this-> + phase_name << std::endl; + } + if (this->rate_name != NULL) + { + s_oss << indent0 << "-rate_name " << this-> + rate_name << std::endl; + } + s_oss << indent0 << "-phase_proportion " << this-> + phase_proportion << 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); + // totals + s_oss << indent0; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 1); - // formula_totals - s_oss << indent0; - s_oss << "-formula_totals" << std::endl; - this->formula_totals.dump_raw(s_oss, indent + 1); + // formula_totals + s_oss << indent0; + s_oss << "-formula_totals" << std::endl; + this->formula_totals.dump_raw(s_oss, indent + 1); } -void cxxExchComp::read_raw(CParser& parser) +void +cxxExchComp::read_raw(CParser & parser) { - std::string str; - - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("formula"); // 0 - vopts.push_back("moles"); // 1 - vopts.push_back("la"); // 2 - vopts.push_back("charge_balance"); // 3 - vopts.push_back("phase_name"); // 4 - vopts.push_back("rate_name"); // 5 - vopts.push_back("formula_z"); // 6 - vopts.push_back("phase_proportion"); // 7 - vopts.push_back("totals"); // 8 - vopts.push_back("formula_totals"); // 9 - } + std::string str; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("formula"); // 0 + vopts.push_back("moles"); // 1 + vopts.push_back("la"); // 2 + vopts.push_back("charge_balance"); // 3 + vopts.push_back("phase_name"); // 4 + vopts.push_back("rate_name"); // 5 + vopts.push_back("formula_z"); // 6 + vopts.push_back("phase_proportion"); // 7 + vopts.push_back("totals"); // 8 + vopts.push_back("formula_totals"); // 9 + } - opt_save = CParser::OPT_ERROR; - bool formula_defined(false); - bool moles_defined(false); - bool la_defined(false); - bool charge_balance_defined(false); - bool formula_z_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool formula_defined(false); + bool moles_defined(false); + bool la_defined(false); + bool charge_balance_defined(false); + bool formula_z_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in EXCH_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // formula - if (!(parser.get_iss() >> str)) - { - this->formula = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); - } else { - this->formula = string_hsave(str.c_str()); - } - formula_defined = true; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in EXCH_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 1: // moles - if (!(parser.get_iss() >> this->moles)) - { - this->moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); - } - moles_defined = true; - break; + case 0: // formula + if (!(parser.get_iss() >> str)) + { + this->formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for formula.", + CParser::OT_CONTINUE); + } + else + { + this->formula = string_hsave(str.c_str()); + } + formula_defined = true; + break; - case 2: // la - if (!(parser.get_iss() >> this->la)) - { - this->la = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la.", CParser::OT_CONTINUE); - } - la_defined = true; - break; + case 1: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + CParser::OT_CONTINUE); + } + moles_defined = true; + break; - case 3: // charge_balance - if (!(parser.get_iss() >> this->charge_balance)) - { - this->charge_balance = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); - } - charge_balance_defined = true; - break; + case 2: // la + if (!(parser.get_iss() >> this->la)) + { + this->la = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la.", + CParser::OT_CONTINUE); + } + la_defined = true; + break; - case 4: // phase_name - if (!(parser.get_iss() >> str)) - { - this->phase_name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); - } else { - this->phase_name = string_hsave(str.c_str()); - } - break; + case 3: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", + CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; - case 5: // rate_name - if (!(parser.get_iss() >> str)) - { - this->rate_name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); - } else { - this->rate_name = string_hsave(str.c_str()); - } - break; + case 4: // phase_name + if (!(parser.get_iss() >> str)) + { + this->phase_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for phase_name.", + CParser::OT_CONTINUE); + } + else + { + this->phase_name = string_hsave(str.c_str()); + } + break; - case 6: // formula_z - if (!(parser.get_iss() >> this->formula_z)) - { - this->formula_z = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for formula_z.", CParser::OT_CONTINUE); - } - formula_z_defined = true; - break; + case 5: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", + CParser::OT_CONTINUE); + } + else + { + this->rate_name = string_hsave(str.c_str()); + } + break; - case 7: // phase_proportion - if (!(parser.get_iss() >> this->phase_proportion)) - { - this->phase_proportion = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for phase_proportion.", CParser::OT_CONTINUE); - } - break; + case 6: // formula_z + if (!(parser.get_iss() >> this->formula_z)) + { + this->formula_z = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for formula_z.", + CParser::OT_CONTINUE); + } + formula_z_defined = true; + break; - case 8: // totals - if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for ExchComp totals.", CParser::OT_CONTINUE); - } - opt_save = 8; - break; + case 7: // phase_proportion + if (!(parser.get_iss() >> this->phase_proportion)) + { + this->phase_proportion = 0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for phase_proportion.", + CParser::OT_CONTINUE); + } + break; - case 9: // formula_totals - if ( this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for ExchComp formula totals.", CParser::OT_CONTINUE); - } - opt_save = 9; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (formula_defined == false) { - parser.incr_input_error(); - parser.error_msg("Formula not defined for ExchComp input.", CParser::OT_CONTINUE); - } - if (moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Moles not defined for ExchComp input.", CParser::OT_CONTINUE); - } - if (la_defined == false) { - parser.incr_input_error(); - parser.error_msg("La not defined for ExchComp input.", CParser::OT_CONTINUE); - } - if (charge_balance_defined == false) { - parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for ExchComp input.", CParser::OT_CONTINUE); - } - if (formula_z_defined == false) { - parser.incr_input_error(); - parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); - } + case 8: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for ExchComp totals.", + CParser::OT_CONTINUE); + } + opt_save = 8; + break; + + case 9: // formula_totals + if (this->formula_totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for ExchComp formula totals.", + CParser::OT_CONTINUE); + } + opt_save = 9; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (formula_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (la_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (formula_z_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", + CParser::OT_CONTINUE); + } } -void cxxExchComp::add(const cxxExchComp &addee, double extensive) +void +cxxExchComp::add(const cxxExchComp & addee, double extensive) { - double ext1, ext2, f1, f2; - if (extensive == 0.0) return; - if (addee.formula == NULL) return; - // this and addee must have same formula - // otherwise generate a new exchcomp with multiply + double ext1, ext2, f1, f2; + if (extensive == 0.0) + return; + if (addee.formula == NULL) + return; + // this and addee must have same formula + // otherwise generate a new exchcomp with multiply - ext1 = this->moles; - ext2 = addee.moles * extensive; - if (ext1 + ext2 != 0) { - f1 = ext1/(ext1 + ext2); - f2 = ext2/(ext1 + ext2); - } else { - f1 = 0.5; - f2 = 0.5; - } + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } - //char * formula; - //cxxNameDouble formula_totals; - if (this->formula == NULL && addee.formula == NULL) { - return; - } - assert (this->formula == addee.formula); - assert (this->formula_z == addee.formula_z); - if (this->formula == NULL && addee.formula != NULL) { - this->formula = addee.formula; - this->formula_totals = addee.formula_totals; - } - //double moles; - this->moles += addee.moles * extensive; - //cxxNameDouble totals; - this->totals.add_extensive(addee.totals, extensive); - //double la; - this->la = f1*this->la + f2*addee.la; - //double charge_balance; - this->charge_balance += addee.charge_balance * extensive; - //char *phase_name; + //char * formula; + //cxxNameDouble formula_totals; + if (this->formula == NULL && addee.formula == NULL) + { + return; + } + assert(this->formula == addee.formula); + assert(this->formula_z == addee.formula_z); + if (this->formula == NULL && addee.formula != NULL) + { + this->formula = addee.formula; + this->formula_totals = addee.formula_totals; + } + //double moles; + this->moles += addee.moles * extensive; + //cxxNameDouble totals; + this->totals.add_extensive(addee.totals, extensive); + //double la; + this->la = f1 * this->la + f2 * addee.la; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //char *phase_name; - if (this->phase_name != addee.phase_name) { - std::ostringstream oss; - oss << "Can not mix two exchange components with same formula and different related phases, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } else if (this->phase_name != NULL) { - this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; - } - //char *rate_name; - if (this->rate_name != addee.rate_name) { - std::ostringstream oss; - oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } else if (this->rate_name != NULL) { - //double phase_proportion; - this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; - } - if ((this->rate_name != NULL && addee.phase_name != NULL) || - (this->phase_name != NULL && addee.rate_name != NULL) ) - { - std::ostringstream oss; - oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } + if (this->phase_name != addee.phase_name) + { + std::ostringstream oss; + oss << + "Can not mix two exchange components with same formula and different related phases, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + else if (this->phase_name != NULL) + { + this->phase_proportion = + this->phase_proportion * f1 + addee.phase_proportion * f2; + } + //char *rate_name; + if (this->rate_name != addee.rate_name) + { + std::ostringstream oss; + oss << + "Can not mix two exchange components with same formula and different related kinetics, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + else if (this->rate_name != NULL) + { + //double phase_proportion; + this->phase_proportion = + this->phase_proportion * f1 + addee.phase_proportion * f2; + } + if ((this->rate_name != NULL && addee.phase_name != NULL) || + (this->phase_name != NULL && addee.rate_name != NULL)) + { + std::ostringstream oss; + oss << + "Can not mix exchange components related to phase with exchange components related to kinetics, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } } -void cxxExchComp::multiply(double extensive) +void +cxxExchComp::multiply(double extensive) { - //char * formula; - //double moles; - this->moles *= extensive; - //cxxNameDouble formula_totals; - //cxxNameDouble totals; - this->totals.multiply(extensive); - //double la; - //double charge_balance; - this->charge_balance *= extensive; - //char *phase_name; - //double phase_proportion; - this->phase_proportion *= extensive; - //double formula_z; + //char * formula; + //double moles; + this->moles *= extensive; + //cxxNameDouble formula_totals; + //cxxNameDouble totals; + this->totals.multiply(extensive); + //double la; + //double charge_balance; + this->charge_balance *= extensive; + //char *phase_name; + //double phase_proportion; + this->phase_proportion *= extensive; + //double formula_z; } + #ifdef USE_MPI -void cxxExchComp::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxExchComp::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->formula)); @@ -532,13 +648,15 @@ void cxxExchComp::mpi_pack(std::vector& ints, std::vector& doubles) this->formula_totals.mpi_pack(ints, doubles); this->totals.mpi_pack(ints, doubles); doubles.push_back(this->la); - doubles.push_back(this->charge_balance); + doubles.push_back(this->charge_balance); ints.push_back(dictionary.string2int(this->phase_name)); doubles.push_back(this->phase_proportion); ints.push_back(dictionary.string2int(this->rate_name)); doubles.push_back(this->formula_z); } -void cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -548,11 +666,11 @@ void cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->formula_totals.mpi_unpack(ints, &i, doubles, &d); this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; - this->charge_balance = doubles[d++]; + this->charge_balance = doubles[d++]; this->phase_name = dictionary.int2char(ints[i++]); - this->phase_proportion = doubles[d++]; + this->phase_proportion = doubles[d++]; this->rate_name = dictionary.int2char(ints[i++]); - this->formula_z = doubles[d++]; + this->formula_z = doubles[d++]; *ii = i; *dd = d; } diff --git a/Exchange.cxx b/Exchange.cxx index 644d9ea3..d47ba542 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -2,11 +2,11 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // std::cout std::cerr -#include "Utils.h" // define first +#include // std::cout std::cerr +#include "Utils.h" // define first #include "Exchange.h" #include "ExchComp.h" #define EXTERNAL extern @@ -14,369 +14,422 @@ #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxExchange::cxxExchange() - // - // default constructor for cxxExchange - // -: cxxNumKeyword() + // + // default constructor for cxxExchange + // +: cxxNumKeyword() { - pitzer_exchange_gammas = false; + pitzer_exchange_gammas = false; } -cxxExchange::cxxExchange(struct exchange *exchange_ptr) - // - // constructor for cxxExchange from struct exchange - // -: -cxxNumKeyword() - -{ - int i; - - this->set_description(exchange_ptr->description); - n_user = exchange_ptr->n_user; - n_user_end = exchange_ptr->n_user_end; - pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); - for (i = 0; i < exchange_ptr->count_comps; i++) { - cxxExchComp ec(&(exchange_ptr->comps[i])); - exchComps.push_back(ec); - } - - - - -} -cxxExchange::cxxExchange(const std::map &entities, cxxMix &mix, int n_user) +cxxExchange::cxxExchange(struct exchange * exchange_ptr) + // + // constructor for cxxExchange from struct exchange + // : cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - this->pitzer_exchange_gammas = false; + int i; + + this->set_description(exchange_ptr->description); + n_user = exchange_ptr->n_user; + n_user_end = exchange_ptr->n_user_end; + pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); + for (i = 0; i < exchange_ptr->count_comps; i++) + { + cxxExchComp ec(&(exchange_ptr->comps[i])); + exchComps.push_back(ec); + } + + + + +} +cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities, + cxxMix & mix, int n_user): +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + this->pitzer_exchange_gammas = false; // // Mix exchangers // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxExchange *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); - this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxExchange *entity_ptr = + &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; + } #ifdef SKIP - if (entity_ptr == NULL) - { - sprintf(error_string, "Exchange %d not found while mixing.", it->first); - error_msg(error_string, CONTINUE); - input_error++; - return; - } + if (entity_ptr == NULL) + { + sprintf(error_string, "Exchange %d not found while mixing.", + it->first); + error_msg(error_string, CONTINUE); + input_error++; + return; + } #endif - } + } } cxxExchange::cxxExchange(int n_user) - // - // constructor for cxxExchange from reaction calculation - // equivalent of xexchange_save - // std::list exchComps; - // bool pitzer_exchange_gammas; + // + // constructor for cxxExchange from reaction calculation + // equivalent of xexchange_save + // std::list exchComps; + // bool pitzer_exchange_gammas; // cxxNameDouble totals; - -: +: cxxNumKeyword() - { - int i; + int i; - //this->set_description(exchange_ptr->description); - this->n_user = n_user; - this->n_user_end = n_user; - this->pitzer_exchange_gammas = (use.exchange_ptr->pitzer_exchange_gammas == TRUE); - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - for (i = 0; i < count_unknowns; i++) - { - if (x[i]->type == EXCH) - { - cxxExchComp ec; - //char * formula; - ec.set_formula (x[i]->exch_comp->formula); - //double moles; - ec.set_moles (0.0); - //cxxNameDouble formula_totals; - ec.set_formula_totals (x[i]->exch_comp->formula_totals); - //cxxNameDouble totals; see below - //double la; - ec.set_la (x[i]->master[0]->s->la); - //double charge_balance; see below - //char *phase_name; - ec.set_phase_name (x[i]->exch_comp->phase_name); - //double phase_proportion; - ec.set_phase_proportion (x[i]->exch_comp->phase_proportion); - //char *rate_name; - ec.set_rate_name (x[i]->exch_comp->rate_name); - //double formula_z; - ec.set_formula_z (x[i]->exch_comp->formula_z); - - // calculate charge and totals - count_elts = 0; - paren_count = 0; - double charge = 0.0; - int j; - for (j = 0; j < count_species_list; j++) - { - if (species_list[j].master_s == x[i]->master[0]->s) + //this->set_description(exchange_ptr->description); + this->n_user = n_user; + this->n_user_end = n_user; + this->pitzer_exchange_gammas = + (use.exchange_ptr->pitzer_exchange_gammas == TRUE); + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + for (i = 0; i < count_unknowns; i++) { - add_elt_list (species_list[j].s->next_elt, - species_list[j].s->moles); - charge += species_list[j].s->moles * species_list[j].s->z; - } - } - // Keep exchanger related to phase even if none currently in solution - if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) - { - add_elt_list (x[i]->master[0]->s->next_elt, 1e-20); - } - //double charge_balance - ec.set_charge_balance (charge); - //cxxNameDouble totals; - if (count_elts > 0) - { - qsort (elt_list, (size_t) count_elts, - (size_t) sizeof (struct elt_list), elt_list_compare); - elt_list_combine (); - } - ec.set_totals(elt_list, count_elts); + if (x[i]->type == EXCH) + { + cxxExchComp ec; + //char * formula; + ec.set_formula(x[i]->exch_comp->formula); + //double moles; + ec.set_moles(0.0); + //cxxNameDouble formula_totals; + ec.set_formula_totals(x[i]->exch_comp->formula_totals); + //cxxNameDouble totals; see below + //double la; + ec.set_la(x[i]->master[0]->s->la); + //double charge_balance; see below + //char *phase_name; + ec.set_phase_name(x[i]->exch_comp->phase_name); + //double phase_proportion; + ec.set_phase_proportion(x[i]->exch_comp->phase_proportion); + //char *rate_name; + ec.set_rate_name(x[i]->exch_comp->rate_name); + //double formula_z; + ec.set_formula_z(x[i]->exch_comp->formula_z); - // add to comp list - this->exchComps.push_back(ec); - } - } + // calculate charge and totals + count_elts = 0; + paren_count = 0; + double charge = 0.0; + int j; + for (j = 0; j < count_species_list; j++) + { + if (species_list[j].master_s == x[i]->master[0]->s) + { + add_elt_list(species_list[j].s->next_elt, + species_list[j].s->moles); + charge += species_list[j].s->moles * species_list[j].s->z; + } + } + // Keep exchanger related to phase even if none currently in solution + if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) + { + add_elt_list(x[i]->master[0]->s->next_elt, 1e-20); + } + //double charge_balance + ec.set_charge_balance(charge); + //cxxNameDouble totals; + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + ec.set_totals(elt_list, count_elts); + + // add to comp list + this->exchComps.push_back(ec); + } + } } + cxxExchange::~cxxExchange() { } -bool cxxExchange::get_related_phases() -{ - for (std::list::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if (it->get_phase_name() == NULL) continue; - return(true); - } - return(false); -} - -bool cxxExchange::get_related_rate() -{ - for (std::list::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if (it->get_rate_name() == NULL) continue; - return(true); - } - return(false); -} - -struct exchange *cxxExchange::cxxExchange2exchange() - // - // Builds a exchange structure from instance of cxxExchange - // +bool +cxxExchange::get_related_phases() { - struct exchange *exchange_ptr = exchange_alloc(); - - exchange_ptr->description = this->get_description(); - exchange_ptr->n_user = this->n_user; - exchange_ptr->n_user_end = this->n_user_end; - exchange_ptr->new_def = FALSE; - exchange_ptr->solution_equilibria = FALSE; - exchange_ptr->n_solution = -2; - exchange_ptr->related_phases = (int) this->get_related_phases(); - exchange_ptr->related_rate = (int) this->get_related_rate(); - exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; - exchange_ptr->count_comps = (int) this->exchComps.size(); - exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps); - exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); - return(exchange_ptr); + for (std::list < cxxExchComp >::const_iterator it = + this->exchComps.begin(); it != this->exchComps.end(); ++it) + { + if (it->get_phase_name() == NULL) + continue; + return (true); + } + return (false); } -void cxxExchange::dump_xml(std::ostream& s_oss, unsigned int indent)const +bool +cxxExchange::get_related_rate() { - //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); - - // Exchange element and attributes - s_oss << indent0; - s_oss << "pitzer_exchange_gammas << "\"" << std::endl; - - // components - s_oss << indent1; - s_oss << "::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } - - return; + for (std::list < cxxExchComp >::const_iterator it = + this->exchComps.begin(); it != this->exchComps.end(); ++it) + { + if (it->get_rate_name() == NULL) + continue; + return (true); + } + return (false); } -void cxxExchange::dump_raw(std::ostream& s_oss, unsigned int indent)const +struct exchange * +cxxExchange::cxxExchange2exchange() + // + // Builds a exchange structure from instance of cxxExchange + // { - //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + struct exchange *exchange_ptr = exchange_alloc(); - // Exchange element and attributes - s_oss << indent0; - s_oss << "EXCHANGE_RAW " << this->n_user << " " << this->description << std::endl; - - s_oss << indent1; - s_oss << "-pitzer_exchange_gammas " << this->pitzer_exchange_gammas << std::endl; - - // exchComps structures - for (std::list::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { - s_oss << indent1; - s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); - } - - return; + exchange_ptr->description = this->get_description(); + exchange_ptr->n_user = this->n_user; + exchange_ptr->n_user_end = this->n_user_end; + exchange_ptr->new_def = FALSE; + exchange_ptr->solution_equilibria = FALSE; + exchange_ptr->n_solution = -2; + exchange_ptr->related_phases = (int) this->get_related_phases(); + exchange_ptr->related_rate = (int) this->get_related_rate(); + exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; + exchange_ptr->count_comps = (int) this->exchComps.size(); + exchange_ptr->comps = + (struct exch_comp *) free_check_null(exchange_ptr->comps); + exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); + return (exchange_ptr); } -void cxxExchange::read_raw(CParser& parser) +void +cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("pitzer_exchange_gammas"); // 0 - vopts.push_back("component"); // 1 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Read exchange number and description - this->read_number_description(parser); + // Exchange element and attributes + s_oss << indent0; + s_oss << " + pitzer_exchange_gammas << "\"" << std::endl; - for (;;) - { - int opt; - if (useLastLine == false) { - opt = parser.get_option(vopts, next_char); - } else { - opt = parser.getOptionFromLastLine(vopts, next_char); - } - 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 EXCH_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + // components + s_oss << indent1; + s_oss << "::const_iterator it = exchComps.begin(); + it != exchComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - case 0: // pitzer_exchange_gammas - if (!(parser.get_iss() >> this->pitzer_exchange_gammas)) - { - this->pitzer_exchange_gammas = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for pitzer_exchange_gammas.", CParser::OT_CONTINUE); - } - pitzer_exchange_gammas_defined = true; - useLastLine = false; - break; - case 1: // component - { - cxxExchComp ec; - ec.read_raw(parser); - this->exchComps.push_back(ec); - } - useLastLine = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (pitzer_exchange_gammas_defined == false) { - parser.incr_input_error(); - parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE); - } + return; } -void cxxExchange::add(const cxxExchange &addee, double extensive) - // - // Add existing exchange to "this" exchange - // + +void +cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //std::list exchComps; - // exchComps - if (extensive == 0.0) return; - for (std::list::const_iterator itadd = addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd) - { - bool found = false; - for (std::list::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) { - cxxExchComp exc = *itadd; - exc.multiply(extensive); - //exc.add(*itadd, extensive); - this->exchComps.push_back(exc); - } - } - //bool pitzer_exchange_gammas; - this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; + //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + // Exchange element and attributes + s_oss << indent0; + s_oss << "EXCHANGE_RAW " << this->n_user << " " << this-> + description << std::endl; + + s_oss << indent1; + s_oss << "-pitzer_exchange_gammas " << this-> + pitzer_exchange_gammas << std::endl; + + // exchComps structures + for (std::list < cxxExchComp >::const_iterator it = exchComps.begin(); + it != exchComps.end(); ++it) + { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } + + return; } + +void +cxxExchange::read_raw(CParser & parser) +{ + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("pitzer_exchange_gammas"); // 0 + vopts.push_back("component"); // 1 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read exchange number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool pitzer_exchange_gammas_defined(false); + + for (;;) + { + int opt; + if (useLastLine == false) + { + opt = parser.get_option(vopts, next_char); + } + else + { + opt = parser.getOptionFromLastLine(vopts, next_char); + } + 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 EXCH_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // pitzer_exchange_gammas + if (!(parser.get_iss() >> this->pitzer_exchange_gammas)) + { + this->pitzer_exchange_gammas = false; + parser.incr_input_error(); + parser. + error_msg + ("Expected boolean value for pitzer_exchange_gammas.", + CParser::OT_CONTINUE); + } + pitzer_exchange_gammas_defined = true; + useLastLine = false; + break; + case 1: // component + { + cxxExchComp ec; + ec.read_raw(parser); + this->exchComps.push_back(ec); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (pitzer_exchange_gammas_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", + CParser::OT_CONTINUE); + } +} +void +cxxExchange::add(const cxxExchange & addee, double extensive) + // + // Add existing exchange to "this" exchange + // +{ + //std::list exchComps; + // exchComps + if (extensive == 0.0) + return; + for (std::list < cxxExchComp >::const_iterator itadd = + addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd) + { + 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) + { + cxxExchComp exc = *itadd; + exc.multiply(extensive); + //exc.add(*itadd, extensive); + this->exchComps.push_back(exc); + } + } + //bool pitzer_exchange_gammas; + this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; +} + #ifdef USE_MPI /* ---------------------------------------------------------------------- */ -void cxxExchange::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxExchange::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ ints.push_back(this->n_user); - + ints.push_back((int) this->pitzer_exchange_gammas); ints.push_back((int) this->exchComps.size()); - for (std::list::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) { + for (std::list < cxxExchComp >::iterator it = this->exchComps.begin(); + it != this->exchComps.end(); it++) + { it->mpi_pack(ints, doubles); } } + /* ---------------------------------------------------------------------- */ -void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -386,11 +439,12 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->n_user_end = this->n_user; this->description = " "; - + this->pitzer_exchange_gammas = (ints[i++] == TRUE); int count = ints[i++]; this->exchComps.clear(); - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { cxxExchComp ec; ec.mpi_unpack(ints, &i, doubles, &d); this->exchComps.push_back(ec); @@ -399,14 +453,16 @@ void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif -void cxxExchange::totalize() +void +cxxExchange::totalize() { - this->totals.clear(); - // component structures - for (std::list::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) - { - this->totals.add_extensive(it->get_totals(), 1.0); - this->totals.add("Charge", it->get_charge_balance()); - } - return; + this->totals.clear(); + // component structures + for (std::list < cxxExchComp >::const_iterator it = exchComps.begin(); + it != exchComps.end(); ++it) + { + this->totals.add_extensive(it->get_totals(), 1.0); + this->totals.add("Charge", it->get_charge_balance()); + } + return; } diff --git a/GasPhase.cxx b/GasPhase.cxx index 4fb9a46c..4e79d49f 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -2,121 +2,140 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "GasPhase.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxGasPhase::cxxGasPhase() - // - // default constructor for cxxGasPhase - // -: cxxNumKeyword() + // + // default constructor for cxxGasPhase + // +: cxxNumKeyword() { - total_p = 0; - volume = 0; - gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; + total_p = 0; + volume = 0; + gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; } cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr) - // - // constructor for cxxGasPhase from struct gas_phase - // -: + // + // constructor for cxxGasPhase from struct gas_phase + // + : cxxNumKeyword() { - int i; + int i; - this->set_description(gas_phase_ptr->description); - n_user = gas_phase_ptr->n_user; - n_user_end = gas_phase_ptr->n_user_end; - if (gas_phase_ptr->type == PRESSURE) { - type = cxxGasPhase::GP_PRESSURE; - } else { - type = cxxGasPhase::GP_VOLUME; - } - total_p = gas_phase_ptr->total_p; - volume = gas_phase_ptr->volume; + this->set_description(gas_phase_ptr->description); + n_user = gas_phase_ptr->n_user; + n_user_end = gas_phase_ptr->n_user_end; + if (gas_phase_ptr->type == PRESSURE) + { + type = cxxGasPhase::GP_PRESSURE; + } + else + { + type = cxxGasPhase::GP_VOLUME; + } + total_p = gas_phase_ptr->total_p; + volume = gas_phase_ptr->volume; - // gas_phase components - for (i = 0; i < gas_phase_ptr->count_comps; i++) { - if (gas_phase_ptr->comps[i].name == NULL) continue; - gasPhaseComps[gas_phase_ptr->comps[i].name] = gas_phase_ptr->comps[i].moles; - } + // gas_phase components + for (i = 0; i < gas_phase_ptr->count_comps; i++) + { + if (gas_phase_ptr->comps[i].name == NULL) + continue; + gasPhaseComps[gas_phase_ptr->comps[i].name] = + gas_phase_ptr->comps[i].moles; + } } -cxxGasPhase::cxxGasPhase(const std::map &entities, cxxMix &mix, int n_user) -: +cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, + cxxMix & mix, int n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; - total_p = 0; - volume = 0; - bool first = true; + this->n_user = this->n_user_end = n_user; + gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; + total_p = 0; + volume = 0; + bool first = true; // // Mix // - //cxxNameDouble gasPhaseComps; - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxGasPhase *entity_ptr = &(entities.find(it->first)->second); - this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, it->second); - //GP_TYPE type; - //double total_p; - //double volume; - if (first) - { - this->type = entity_ptr->type; - this->total_p = entity_ptr->total_p * it->second; - this->volume = entity_ptr->volume * it->second; - first = false; - } else - { - if (this->type != entity_ptr->type) + //cxxNameDouble gasPhaseComps; + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) { - std::ostringstream oss; - oss << "Can not mix two gas_phases with differing types." ; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } + if (entities.find(it->first) != entities.end()) + { + const cxxGasPhase *entity_ptr = + &(entities.find(it->first)->second); + this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, + it->second); + //GP_TYPE type; + //double total_p; + //double volume; + if (first) + { + this->type = entity_ptr->type; + this->total_p = entity_ptr->total_p * it->second; + this->volume = entity_ptr->volume * it->second; + first = false; + } + else + { + if (this->type != entity_ptr->type) + { + std::ostringstream oss; + oss << "Can not mix two gas_phases with differing types."; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } - this->total_p += entity_ptr->total_p * it->second; - this->volume += entity_ptr->volume * it->second; - } - } - } + this->total_p += entity_ptr->total_p * it->second; + this->volume += entity_ptr->volume * it->second; + } + } + } } + cxxGasPhase::~cxxGasPhase() { } -struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp() +struct gas_comp * +cxxGasPhase::cxxGasPhaseComp2gas_comp() { //struct gas_comp *gas_comp_ptr(NULL); struct gas_comp *gas_comp_ptr = NULL; - if (this->gasPhaseComps.size() > 0) { + if (this->gasPhaseComps.size() > 0) + { int i = 0; int n; - gas_comp_ptr = (struct gas_comp *) PHRQ_malloc((size_t) (this->gasPhaseComps.size() * sizeof(struct gas_comp))); - if (gas_comp_ptr == NULL) malloc_error(); - for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { + gas_comp_ptr = + (struct gas_comp *) + PHRQ_malloc((size_t) + (this->gasPhaseComps.size() * + sizeof(struct gas_comp))); + if (gas_comp_ptr == NULL) + malloc_error(); + for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); + it != this->gasPhaseComps.end(); it++) + { gas_comp_ptr[i].name = it->first; gas_comp_ptr[i].phase = phase_bsearch(it->first, &n, TRUE); gas_comp_ptr[i].p_read = 0; @@ -125,225 +144,273 @@ struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp() i++; } } - return(gas_comp_ptr); + return (gas_comp_ptr); } -struct gas_phase *cxxGasPhase::cxxGasPhase2gas_phase() - // - // Builds a gas_phase structure from instance of cxxGasPhase - // +struct gas_phase * +cxxGasPhase::cxxGasPhase2gas_phase() + // + // Builds a gas_phase structure from instance of cxxGasPhase + // { - struct gas_phase *gas_phase_ptr = gas_phase_alloc(); - - gas_phase_ptr->description = this->get_description(); - gas_phase_ptr->n_user = this->n_user; - gas_phase_ptr->n_user_end = this->n_user_end; - gas_phase_ptr->new_def = FALSE; - gas_phase_ptr->solution_equilibria = FALSE; - gas_phase_ptr->n_solution = -2; - if (this->type == cxxGasPhase::GP_PRESSURE) { - gas_phase_ptr->type = PRESSURE; - } else { - gas_phase_ptr->type = VOLUME; + struct gas_phase *gas_phase_ptr = gas_phase_alloc(); + + gas_phase_ptr->description = this->get_description(); + gas_phase_ptr->n_user = this->n_user; + gas_phase_ptr->n_user_end = this->n_user_end; + gas_phase_ptr->new_def = FALSE; + gas_phase_ptr->solution_equilibria = FALSE; + gas_phase_ptr->n_solution = -2; + if (this->type == cxxGasPhase::GP_PRESSURE) + { + gas_phase_ptr->type = PRESSURE; } - gas_phase_ptr->total_p = this->total_p; - gas_phase_ptr->volume = this->volume; - gas_phase_ptr->temperature = 273.15; + else + { + gas_phase_ptr->type = VOLUME; + } + gas_phase_ptr->total_p = this->total_p; + gas_phase_ptr->volume = this->volume; + gas_phase_ptr->temperature = 273.15; - // comps - gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size(); - gas_phase_ptr->comps = (struct gas_comp *) free_check_null(gas_phase_ptr->comps); - gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(); + // comps + gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size(); + gas_phase_ptr->comps = + (struct gas_comp *) free_check_null(gas_phase_ptr->comps); + gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(); - return(gas_phase_ptr); + return (gas_phase_ptr); } #ifdef SKIP -void cxxGasPhase::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // GasPhase element and attributes - s_oss << indent0; - s_oss << "pitzer_gas_phase_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_gas_phase_gammas=\"" << this-> + pitzer_gas_phase_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = + gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxGasPhase::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // GasPhase element and attributes - s_oss << indent0; - s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this->description << std::endl; + // GasPhase element and attributes + s_oss << indent0; + s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this-> + description << std::endl; - s_oss << indent1; - s_oss << "-type " << this->type << std::endl; + s_oss << indent1; + s_oss << "-type " << this->type << std::endl; - s_oss << indent1; - s_oss << "-total_p " << this->total_p << std::endl; + s_oss << indent1; + s_oss << "-total_p " << this->total_p << std::endl; - s_oss << indent1; - s_oss << "-volume " << this->volume << std::endl; + s_oss << indent1; + s_oss << "-volume " << this->volume << std::endl; - // gasPhaseComps + // gasPhaseComps s_oss << indent1; s_oss << "-component" << std::endl; this->gasPhaseComps.dump_raw(s_oss, indent + 2); } -void cxxGasPhase::read_raw(CParser& parser) +void +cxxGasPhase::read_raw(CParser & parser) { int i; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("type"); //0 - vopts.push_back("total_p"); //1 - vopts.push_back("volume"); //2 - vopts.push_back("component"); //3 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("type"); //0 + vopts.push_back("total_p"); //1 + vopts.push_back("volume"); //2 + vopts.push_back("component"); //3 + } - // Read gas_phase number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; - bool type_defined(false); - bool total_p_defined(false); - bool volume_defined(false); + // Read gas_phase number and description + this->read_number_description(parser); - 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 GAS_PHASE_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; + bool type_defined(false); + bool total_p_defined(false); + bool volume_defined(false); - case 0: // type + 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 GAS_PHASE_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // type if (!(parser.get_iss() >> i)) - //if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type)) - { - this->type = cxxGasPhase::GP_PRESSURE; - parser.incr_input_error(); - parser.error_msg("Expected enum for type.", CParser::OT_CONTINUE); - } else { + //if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type)) + { + this->type = cxxGasPhase::GP_PRESSURE; + parser.incr_input_error(); + parser.error_msg("Expected enum for type.", + CParser::OT_CONTINUE); + } + else + { this->type = (cxxGasPhase::GP_TYPE) i; } - type_defined = true; - useLastLine = false; - break; + type_defined = true; + useLastLine = false; + break; - case 1: // total_p - if (!(parser.get_iss() >> this->total_p)) - { - this->total_p = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for total_p.", CParser::OT_CONTINUE); - } - total_p_defined = true; - useLastLine = false; - break; + case 1: // total_p + if (!(parser.get_iss() >> this->total_p)) + { + this->total_p = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total_p.", + CParser::OT_CONTINUE); + } + total_p_defined = true; + useLastLine = false; + break; - case 2: // volume - if (!(parser.get_iss() >> this->volume)) - { - this->volume = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for volume.", CParser::OT_CONTINUE); - } - volume_defined = true; - useLastLine = false; - break; + case 2: // volume + if (!(parser.get_iss() >> this->volume)) + { + this->volume = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for volume.", + CParser::OT_CONTINUE); + } + volume_defined = true; + useLastLine = false; + break; - case 3: // component - if ( this->gasPhaseComps.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected gas component name and moles for gasPhaseComps.", CParser::OT_CONTINUE); - } - opt_save = 3; - useLastLine = false; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (type_defined == false) { - parser.incr_input_error(); - parser.error_msg("Type not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); - } - if (total_p_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); - } - if (volume_defined == false) { - parser.incr_input_error(); - parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); - } + case 3: // component + if (this->gasPhaseComps.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected gas component name and moles for gasPhaseComps.", + CParser::OT_CONTINUE); + } + opt_save = 3; + useLastLine = false; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Type not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (total_p_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (volume_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI -void cxxGasPhase::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxGasPhase::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { ints.push_back(this->n_user); this->gasPhaseComps.mpi_pack(ints, doubles); - if (this->type == cxxGasPhase::GP_PRESSURE) { + if (this->type == cxxGasPhase::GP_PRESSURE) + { ints.push_back(0); - } else { + } + else + { ints.push_back(1); } doubles.push_back(this->total_p); - doubles.push_back(this->volume); + doubles.push_back(this->volume); } -void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; @@ -352,33 +419,40 @@ void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->description = " "; this->gasPhaseComps.mpi_unpack(ints, &i, doubles, &d); int n = ints[i++]; - if (n == 0) { + if (n == 0) + { this->type = cxxGasPhase::GP_PRESSURE; - } else { + } + else + { this->type = cxxGasPhase::GP_VOLUME; } this->total_p = doubles[d++]; - this->volume = doubles[d++]; + this->volume = doubles[d++]; *ii = i; *dd = d; } #endif -void cxxGasPhase::totalize() +void +cxxGasPhase::totalize() { - this->totals.clear(); - // component structures - for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { - struct phase *phase_ptr; - int l; - phase_ptr = phase_bsearch(it->first, &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, it->second); - } else - { - assert(false); - } - } - return; + this->totals.clear(); + // component structures + for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin(); + it != this->gasPhaseComps.end(); it++) + { + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(it->first, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, it->second); + } + else + { + assert(false); + } + } + return; } diff --git a/ISolution.cxx b/ISolution.cxx index 65f68667..27bd9046 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -2,7 +2,7 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "ISolution.h" @@ -13,11 +13,11 @@ #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort #include #ifdef ORCHESTRA -extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); +extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -26,906 +26,1062 @@ extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); //static std::map ss_map; //std::map& cxxISolution::s_map = ss_map; -cxxISolution::cxxISolution() -: +cxxISolution::cxxISolution(): units("mMol/kgw") { - density = 1.0; - default_pe = -1; + density = 1.0; + default_pe = -1; pes = NULL; } -cxxISolution::cxxISolution(struct solution *solution_ptr) -: cxxSolution(solution_ptr) - //, pe(cxxPe_Data::alloc()) +cxxISolution::cxxISolution(struct solution *solution_ptr): +cxxSolution(solution_ptr) + //, pe(cxxPe_Data::alloc()) { - density = solution_ptr->density; - units = solution_ptr->units; - // totals - for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { - cxxISolutionComp c(&(solution_ptr->totals[i])); - //comps.insert(solution_ptr->totals[i].description, c); + density = solution_ptr->density; + units = solution_ptr->units; + // totals + for (int i = 0; solution_ptr->totals[i].description != NULL; i++) + { + cxxISolutionComp c(&(solution_ptr->totals[i])); + //comps.insert(solution_ptr->totals[i].description, c); comps[solution_ptr->totals[i].description] = c; - } - default_pe = solution_ptr->default_pe; - // pe_data - pes = pe_data_dup(solution_ptr->pe); + } + default_pe = solution_ptr->default_pe; + // pe_data + pes = pe_data_dup(solution_ptr->pe); } cxxISolution::~cxxISolution() { - pe_data_free(this->pes); + pe_data_free(this->pes); } -struct solution *cxxISolution::cxxISolution2solution() - // - // Builds a solution structure from instance of cxxISolution - // +struct solution * +cxxISolution::cxxISolution2solution() + // + // Builds a solution structure from instance of cxxISolution + // { - struct solution *soln_ptr = this->cxxSolution2solution(); - soln_ptr->new_def = TRUE; - soln_ptr->density = this->density; - soln_ptr->units = string_hsave(this->units.c_str()); - soln_ptr->default_pe = this->default_pe; - // pe - soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe); - soln_ptr->pe = pe_data_dup(this->pes); - // totals - soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); - soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(this->comps); - return(soln_ptr); + struct solution *soln_ptr = this->cxxSolution2solution(); + soln_ptr->new_def = TRUE; + soln_ptr->density = this->density; + soln_ptr->units = string_hsave(this->units.c_str()); + soln_ptr->default_pe = this->default_pe; + // pe + soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe); + soln_ptr->pe = pe_data_dup(this->pes); + // totals + soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); + soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(this->comps); + return (soln_ptr); } -void cxxISolution::ConvertUnits() + +void +cxxISolution::ConvertUnits() // // Converts from input units to moles per kilogram water // { - double sum_solutes = 0; - // foreach conc - std::map::iterator iter = this->comps.begin(); - for(; iter != this->comps.end(); ++iter) - { - struct master *master_ptr = master_bsearch (iter->first); - if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; - //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; - if (strcmp(iter->second.get_description(),"H(1)") == 0 || strcmp(iter->second.get_description(), "E")) continue; - if (iter->second.get_input_conc() <= 0.0) continue; + double sum_solutes = 0; + // foreach conc + std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); + for (; iter != this->comps.end(); ++iter) + { + struct master *master_ptr = master_bsearch(iter->first); + if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) + continue; + //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; + if (strcmp(iter->second.get_description(), "H(1)") == 0 + || strcmp(iter->second.get_description(), "E")) + continue; + if (iter->second.get_input_conc() <= 0.0) + continue; /* * Convert liters to kg solution */ - double moles = iter->second.get_input_conc(); - if (this->units.find("/l") != std::string::npos ) - { - moles /= this->density; - } + double moles = iter->second.get_input_conc(); + if (this->units.find("/l") != std::string::npos) + { + moles /= this->density; + } /* * Convert to moles */ - //set gfw for element - iter->second.set_gfw(); - // convert to moles - if (iter->second.get_units().find("g/") != std::string::npos) - { - if (iter->second.get_gfw() != 0) - { - moles /= iter->second.get_gfw(); - } - else - { - std::ostringstream oss; - oss << "Could not find gfw, " << iter->second.get_description(); - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - } - } + //set gfw for element + iter->second.set_gfw(); + // convert to moles + if (iter->second.get_units().find("g/") != std::string::npos) + { + if (iter->second.get_gfw() != 0) + { + moles /= iter->second.get_gfw(); + } + else + { + std::ostringstream oss; + oss << "Could not find gfw, " << iter->second. + get_description(); + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + } /* * Convert milli or micro */ - char c = iter->second.get_units().c_str()[0]; - if (c == 'm') - { - moles *= 1e-3; - } - else if (c == 'u') - { - moles *= 1e-6; - } - iter->second.set_moles(moles); + char c = iter->second.get_units().c_str()[0]; + if (c == 'm') + { + moles *= 1e-3; + } + else if (c == 'u') + { + moles *= 1e-6; + } + iter->second.set_moles(moles); /* * Sum grams of solute, convert from moles necessary */ - sum_solutes += moles * (iter->second.get_gfw()); - } + sum_solutes += moles * (iter->second.get_gfw()); + } /* * Convert /kgs to /kgw */ - double mass_water; - if ((this->units.find("kgs") != std::string::npos) || - (this->units.find("/l") != std::string::npos)) - { - mass_water = 1.0 - 1e-3 * sum_solutes; - for(; iter != this->comps.end(); ++iter) - { - iter->second.set_moles(iter->second.get_moles() / mass_water); - } - } + double mass_water; + if ((this->units.find("kgs") != std::string::npos) || + (this->units.find("/l") != std::string::npos)) + { + mass_water = 1.0 - 1e-3 * sum_solutes; + for (; iter != this->comps.end(); ++iter) + { + iter->second.set_moles(iter->second.get_moles() / mass_water); + } + } /* * Scale by mass of water in solution */ - mass_water = this->mass_water; - for(; iter != this->comps.end(); ++iter) - { - iter->second.set_moles(iter->second.get_moles() * mass_water); - } + mass_water = this->mass_water; + for (; iter != this->comps.end(); ++iter) + { + iter->second.set_moles(iter->second.get_moles() * mass_water); + } } + #ifdef SKIP -cxxISolution& cxxISolution::read(CParser& parser) +cxxISolution & cxxISolution::read(CParser & parser) { - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); + static + std::vector < + std::string > + vopts; + if (vopts.empty()) + { + vopts.reserve(11); + vopts.push_back("temp"); // 0 + vopts.push_back("temperature"); // 1 + vopts.push_back("dens"); // 2 + vopts.push_back("density"); // 3 + vopts.push_back("units"); // 4 + vopts.push_back("redox"); // 5 + vopts.push_back("ph"); // 6 + vopts.push_back("pe"); // 7 + vopts.push_back("unit"); // 8 + vopts.push_back("isotope"); // 9 + vopts.push_back("water"); // 10 + } + // const int count_opt_list = vopts.size(); - cxxISolution numkey; + cxxISolution + numkey; - // Read solution number and description - numkey.read_number_description(parser); + // Read solution number and description + numkey.read_number_description(parser); - // Malloc space for solution data - //// g_solution_map[numkey.n_user()] = numkey; - s_map[numkey.n_user()] = numkey; + // Malloc space for solution data + //// g_solution_map[numkey.n_user()] = numkey; + s_map[numkey.n_user()] = numkey; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - cxxISolution& sol = s_map[numkey.n_user()]; - int default_pe = 0; + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + CParser::TOKEN_TYPE j; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) { - opt = 9; - } - } + cxxISolution & sol = s_map[numkey.n_user()]; + int + default_pe = 0; - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - CParser::error_msg("Unknown input in SOLUTION keyword.", CParser::OT_CONTINUE); - CParser::error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int + opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPTION_DEFAULT) + { + ptr = next_char; + if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) + { + opt = 9; + } + } - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; + switch (opt) + { + case CParser::OPTION_EOF: + break; + case CParser::OPTION_KEYWORD: + break; + case CParser::OPTION_ERROR: + opt = CParser::OPTION_EOF; + CParser::error_msg("Unknown input in SOLUTION keyword.", + CParser::OT_CONTINUE); + CParser::error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; + case 0: // temp + case 1: // temperature + if (!(parser.get_iss() >> sol.tc)) + { + sol.tc = 25; + } + break; - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.check_units(token, false, false, sol.units, true) == CParser::OK) { - sol.units = token; - } else { - parser.incr_input_error(); - } - break; + case 2: // dens + case 3: // density + parser.get_iss() >> sol.density; + break; - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) break; - if (parser.parse_couple(token) == CParser::OK) { - default_pe = cxxPe_Data::store(sol.pe, token); - } else { - parser.incr_input_error(); - } - break; + case 4: // units + case 8: // unit + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) + break; + if (parser.check_units(token, false, false, sol.units, true) == + CParser::OK) + { + sol.units = token; + } + else + { + parser.incr_input_error(); + } + break; - case 6: // ph - { - cxxISolutionComp conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("H(1)"); - sol.add(conc); - } - break; + case 5: // redox + if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) + break; + if (parser.parse_couple(token) == CParser::OK) + { + default_pe = cxxPe_Data::store(sol.pe, token); + } + else + { + parser.incr_input_error(); + } + break; - case 7: // pe - { - cxxISolutionComp conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { - parser.incr_input_error(); - break; - } - sol.solution_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) { - break; - } - conc.set_description("E"); - sol.add(conc); - } - break; + case 6: // ph + { + cxxISolutionComp + conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) + { + parser.incr_input_error(); + break; + } + sol.ph = conc.get_input_conc(); + if (conc.get_equation_name().empty()) + { + break; + } + conc.set_description("H(1)"); + sol.add(conc); + } + break; - case 9: // isotope - { - cxxIsotope isotope; - if (isotope.read(parser) == cxxIsotope::OK) { - sol.add(isotope); - } - } - break; + case 7: // pe + { + cxxISolutionComp + conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) + { + parser.incr_input_error(); + break; + } + sol.solution_pe = conc.get_input_conc(); + if (conc.get_equation_name().empty()) + { + break; + } + conc.set_description("E"); + sol.add(conc); + } + break; - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - sol.mass_water = 1.0; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> sol.mass_water; - } - break; + case 9: // isotope + { + cxxIsotope + isotope; + if (isotope.read(parser) == cxxIsotope::OK) + { + sol.add(isotope); + } + } + break; - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxISolutionComp conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) { - parser.incr_input_error(); - } else { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; - } + case 10: // water + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) + { + sol.mass_water = 1.0; + } + else if (j != CParser::TT_DIGIT) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected numeric value for mass of water in solution.", + CParser::OT_CONTINUE); + } + else + { + std::istringstream(token) >> sol.mass_water; + } + break; + + case CParser::OPTION_DEFAULT: + { + // Read concentration + cxxISolutionComp + conc; + if (conc.read(parser, sol) == cxxISolutionComp::ERROR) + { + parser.incr_input_error(); + } + else + { + sol.add(conc); + } + } + break; + } + if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) + break; + } #ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); + // + // Sort totals by description + // + std::sort(sol.totals.begin(), sol.totals.end()); #endif - // - // fix up default units and default pe - // - std::string token1; - std::vector::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) { - (*iter).set_units(sol.units); - } else { - bool alk = false; - if (token.find("alk") == 0) alk = true; - token1 = (*iter).get_units(); - if (parser.check_units(token1, alk, true, sol.get_units(), true) == CParser::ERROR) { - parser.incr_input_error(); - } else { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; + // + // fix up default units and default pe + // + std::string token1; + std::vector < cxxISolutionComp >::iterator iter = sol.totals.begin(); + for (; iter != sol.totals.end(); ++iter) + { + token = (*iter).get_description(); + Utilities::str_tolower(token); + if ((*iter).get_units().empty()) + { + (*iter).set_units(sol.units); + } + else + { + bool + alk = false; + if (token.find("alk") == 0) + alk = true; + token1 = (*iter).get_units(); + if (parser. + check_units(token1, alk, true, sol.get_units(), + true) == CParser::ERROR) + { + parser.incr_input_error(); + } + else + { + (*iter).set_units(token1); + } + } + if ((*iter).get_n_pe() < 0) + { + (*iter).set_n_pe(default_pe); + } + } + sol.default_pe = default_pe; + return sol; } #endif #ifdef SKIP -void cxxISolution::dump_xml(std::ostream& os, unsigned int indent)const +void +cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const { - unsigned int i; + unsigned int i; - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "\n"; + for (i = 0; i < indent; ++i) + os << Utilities::INDENT; + os << "\n"; - cxxNumKeyword::dump_xml(os, indent); + cxxNumKeyword::dump_xml(os, indent); - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_tc() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_tc() << "" << "\n"; - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_ph() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_ph() << "" << "\n"; - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_solution_pe() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_solution_pe() << "" << "\n"; - assert(this->pe.size() > 0); - assert(this->default_pe >= 0); - assert(this->pe.size() > (unsigned int) this->default_pe); - //this->pe[this->default_pe].dump_xml(os, indent + 1); + assert(this->pe.size() > 0); + assert(this->default_pe >= 0); + assert(this->pe.size() > (unsigned int) this->default_pe); + //this->pe[this->default_pe].dump_xml(os, indent + 1); - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_units() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_units() << "" << "\n"; - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_density() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_density() << "" << "\n"; - // foreach conc - if (!this->totals.empty()) - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; + // foreach conc + if (!this->totals.empty()) + { + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "\n"; - std::vector::const_iterator iter = this->totals.begin(); - for(; iter != this->totals.end(); ++iter) - { - (*iter).dump_xml(*this, os, indent + 2); - } + std::vector < cxxISolutionComp >::const_iterator iter = + this->totals.begin(); + for (; iter != this->totals.end(); ++iter) + { + (*iter).dump_xml(*this, os, indent + 2); + } - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - } + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "\n"; + } - // foreach isotope - if (!this->isotopes.empty()) - { - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; + // foreach isotope + if (!this->isotopes.empty()) + { + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "\n"; - std::list::const_iterator iter = this->isotopes.begin(); - for(; iter != this->isotopes.end(); ++iter) - { - (*iter).dump_xml(os, indent + 2); - } + std::list < cxxIsotope >::const_iterator iter = + this->isotopes.begin(); + for (; iter != this->isotopes.end(); ++iter) + { + (*iter).dump_xml(os, indent + 2); + } - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "\n"; - } + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "\n"; + } - for(i = 0; i < indent + 1; ++i) os << Utilities::INDENT; - os << "" << this->get_mass_water() << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << Utilities::INDENT; + os << "" << this->get_mass_water() << "" << "\n"; - for(i = 0; i < indent; ++i) os << Utilities::INDENT; - os << "" << "\n"; + for (i = 0; i < indent; ++i) + os << Utilities::INDENT; + os << "" << "\n"; } #endif #ifdef ORCHESTRA -void cxxISolution::ORCH_write_chemistry(std::ostream &chemistry_dat) +void +cxxISolution::ORCH_write_chemistry(std::ostream & chemistry_dat) { - this->ORCH_write_chemistry_water(chemistry_dat); - this->ORCH_write_chemistry_primary(chemistry_dat); - this->ORCH_write_chemistry_total_O_H(chemistry_dat); - this->ORCH_write_chemistry_alkalinity(chemistry_dat); - ORCH_write_chemistry_species(chemistry_dat); - this->ORCH_write_chemistry_minerals(chemistry_dat); + this->ORCH_write_chemistry_water(chemistry_dat); + this->ORCH_write_chemistry_primary(chemistry_dat); + this->ORCH_write_chemistry_total_O_H(chemistry_dat); + this->ORCH_write_chemistry_alkalinity(chemistry_dat); + ORCH_write_chemistry_species(chemistry_dat); + this->ORCH_write_chemistry_minerals(chemistry_dat); } -void cxxISolution::ORCH_write_chemistry_water(std::ostream &chemistry_dat) +void +cxxISolution::ORCH_write_chemistry_water(std::ostream & chemistry_dat) { - // - // Write water entities - // - chemistry_dat << std::endl << "//********* The water entities" << std::endl; + // + // Write water entities + // + chemistry_dat << std::endl << "//********* The water entities" << std:: + endl; - // e- - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - if (this->comps.find("E") == this->comps.end() || this->comps.find("E")->second.get_equation_name() == NULL) - { - // fixed pe - chemistry_dat << "@Calc: (1, \"e-.act = 10^-pe\")" << std::endl; - - } else if (this->comps.find("E")->second.get_equation_name() == string_hsave("charge")) - { - // charge balance - chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; - chemistry_dat << "@solve (e-.act, 1e-6, log, 1, chargebalance, 1e-14)" << std::endl; - } else - { - // adjust to equilbirium with a phase - chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; - int n; - struct phase *phase_ptr = phase_bsearch(this->comps.find("E)")->second.get_equation_name(), &n, FALSE); - assert (phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@solve (e-.act, 1e-6, log, 1, " << phase_name.c_str() << ".si_raw, 1e-9)" << std::endl; - } - - // H+ - if (this->comps.find("H(1)") == this->comps.end() || this->comps.find("H(1)")->second.get_equation_name() == NULL) - { - // fixed pH - chemistry_dat << "@Calc: (1, \"H+.act = 10^-pH\")" << std::endl; - - } else if (this->comps.find("H(1)")->second.get_equation_name() == string_hsave("charge")) - { - // charge balance - chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; - chemistry_dat << "@solve (H+.act, 1e-6, log, 1, chargebalance, 1e-14)" << std::endl; - } else - { - // adjust to equilbirium with a phase - chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; - int n; - struct phase *phase_ptr = phase_bsearch(this->comps.find("H(1)")->second.get_equation_name(), &n, FALSE); - assert (phase_ptr != NULL); - chemistry_dat << "@solve (H+.act, 1e-6, log, 1, " << phase_ptr->name << ".si_raw, 1e-9)" << std::endl; - } - - // H2O - chemistry_dat << "@entity(" << s_h2o->name << ", diss, 55.506)" << std::endl; - chemistry_dat << std::endl; -} - -void cxxISolution::ORCH_write_chemistry_primary(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* The primary species" << std::endl; - // - // Write other master species definitions, i.e. primary entities - // - std::map::iterator iter = this->comps.begin(); - chemistry_dat << "@species(H+, 1)" << std::endl; - for(; iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->z << ")" << std::endl; - if (iter->second.get_equation_name() == NULL) - { - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr->name << ", 1e-9, diss, 1.0e-9)" << std::endl; - } else - { - std::string eqn(iter->second.get_equation_name()); - if (eqn == "charge") - { - // charge balance - chemistry_dat << "@solve (" << s_ptr->name << ".act, 1e-6, log, 1, chargebalance, 1e-9)" << std::endl; - } else - { - // adjust to phase equilibrium - int n; - struct phase *phase_ptr = phase_bsearch(eqn.c_str(), &n, FALSE); - assert (phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@solve (" << s_ptr->name << ".act, 1e-6, log, 1, " << phase_name << ".si_raw, 1e-9)" << std::endl; - } - } - } - chemistry_dat << std::endl; -} - -void cxxISolution::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl; - // Define total hydrogen, total oxygen, and difference - //chemistry_dat << "@var: total_diff 0" << std::endl; - //chemistry_dat << "@calc: (5, \"total_diff = total_hydrogen - 2*total_oxygen" << "\")" << std::endl; - - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - int i; - for (i = 0; i < count_s_x; i++) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - { - if (s_x[i]->h != 0) - { - chemistry_dat << "+"; - if (s_x[i]->h != 1) + // e- + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + if (this->comps.find("E") == this->comps.end() + || this->comps.find("E")->second.get_equation_name() == NULL) { - chemistry_dat << s_x[i]->h << "*"; + // fixed pe + chemistry_dat << "@Calc: (1, \"e-.act = 10^-pe\")" << std::endl; + + } + else if (this->comps.find("E")->second.get_equation_name() == + string_hsave("charge")) + { + // charge balance + chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; + chemistry_dat << + "@solve (e-.act, 1e-6, log, 1, chargebalance, 1e-14)" << std:: + endl; + } + else + { + // adjust to equilbirium with a phase + chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; + int n; + struct phase *phase_ptr = + phase_bsearch(this->comps.find("E)")->second.get_equation_name(), + &n, FALSE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@solve (e-.act, 1e-6, log, 1, " << phase_name. + c_str() << ".si_raw, 1e-9)" << std::endl; } - chemistry_dat << "{" << s_x[i]->name << ".diss}"; - } - } - } - chemistry_dat << "\")" << std::endl; - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->o != 0) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - { - chemistry_dat << "+"; - if (s_x[i]->o != 1) + // H+ + if (this->comps.find("H(1)") == this->comps.end() + || this->comps.find("H(1)")->second.get_equation_name() == NULL) { - chemistry_dat << s_x[i]->o << "*"; + // fixed pH + chemistry_dat << "@Calc: (1, \"H+.act = 10^-pH\")" << std::endl; + } - chemistry_dat << "{" << s_x[i]->name << ".diss}"; - } - } - } - chemistry_dat << "\")" << std::endl; - chemistry_dat << std::endl; -} -void cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* Alkalinity definitions" << std::endl; - // - // Define alkalinity - // - chemistry_dat << "@Var: Alkalinity 0" << std::endl; - chemistry_dat << "@calc: (5, \"Alkalinity = 0"; - for (int i = 0; i < count_s_x; i++) - { - if (s_x[i]->alk == 0) continue; - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - if (s_x[i]->alk < 0) - { - if (s_x[i]->alk != -1) + else if (this->comps.find("H(1)")->second.get_equation_name() == + string_hsave("charge")) { - chemistry_dat << s_x[i]->alk << "*{" << name << ".con}"; - } else - { - chemistry_dat << "-{" << name << ".con}"; + // charge balance + chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; + chemistry_dat << + "@solve (H+.act, 1e-6, log, 1, chargebalance, 1e-14)" << std:: + endl; } - } else if (s_x[i]->alk > 0) - { - if (s_x[i]->alk != 1) - { - chemistry_dat << "+" << s_x[i]->alk << "*{" << name << ".con}"; - } else - { - chemistry_dat << "+{" << name << ".con}"; - } - } - } - chemistry_dat << "\")" << std::endl; - // - // Alkalinity (or pH) equation - // - std::map::iterator iter = this->comps.begin(); - if ((iter = this->comps.find("Alkalinity")) != this->comps.end()) - { - if ((this->comps.find("C(4)") != this->comps.end()) || (this->comps.find("C") != this->comps.end())) - { - if (this->comps.find("H(1)") != this->comps.end() ) - { - std::ostringstream oss; - oss << "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - } - chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << std::endl; - chemistry_dat << std::endl; - } else - { - struct master *master_ptr = master_bsearch("Alkalinity"); - if (master_ptr == NULL) - { - std::ostringstream oss; - oss << "Could not find Alkalinity definition in database."; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - } - chemistry_dat << "@species(" << master_ptr->s->name << ", " << master_ptr->s->z << ")" << std::endl; - chemistry_dat << "@solve (" << master_ptr->s->name << ".act, 1e-6, log, 1, Alkalinity, 1e-9)" << std::endl; - chemistry_dat << std::endl; - } - } + else + { + // adjust to equilbirium with a phase + chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; + int n; + struct phase *phase_ptr = + phase_bsearch(this->comps.find("H(1)")->second. + get_equation_name(), &n, FALSE); + assert(phase_ptr != NULL); + chemistry_dat << "@solve (H+.act, 1e-6, log, 1, " << phase_ptr-> + name << ".si_raw, 1e-9)" << std::endl; + } + + // H2O + chemistry_dat << "@entity(" << s_h2o-> + name << ", diss, 55.506)" << std::endl; + chemistry_dat << std::endl; } -void cxxISolution::ORCH_write_chemistry_minerals(std::ostream &chemistry_dat) +void +cxxISolution::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) { - chemistry_dat << std::endl << "//********* Adjustments to mineral equilibrium" << std::endl; + chemistry_dat << std::endl << "//********* The primary species" << std:: + endl; + // + // Write other master species definitions, i.e. primary entities + // + std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); + chemistry_dat << "@species(H+, 1)" << std::endl; + for (; iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") + continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> + z << ")" << std::endl; + if (iter->second.get_equation_name() == NULL) + { + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr-> + name << ", 1e-9, diss, 1.0e-9)" << std::endl; + } + else + { + std::string eqn(iter->second.get_equation_name()); + if (eqn == "charge") + { + // charge balance + chemistry_dat << "@solve (" << s_ptr-> + name << ".act, 1e-6, log, 1, chargebalance, 1e-9)" << + std::endl; + } + else + { + // adjust to phase equilibrium + int n; + struct phase *phase_ptr = + phase_bsearch(eqn.c_str(), &n, FALSE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@solve (" << s_ptr-> + name << ".act, 1e-6, log, 1, " << phase_name << + ".si_raw, 1e-9)" << std::endl; + } + } + } + chemistry_dat << std::endl; +} + +void +cxxISolution::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) +{ + chemistry_dat << std:: + endl << "//********* Define total hydrogen and oxygen" << std::endl; + // Define total hydrogen, total oxygen, and difference + //chemistry_dat << "@var: total_diff 0" << std::endl; + //chemistry_dat << "@calc: (5, \"total_diff = total_hydrogen - 2*total_oxygen" << "\")" << std::endl; + + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + int i; + for (i = 0; i < count_s_x; i++) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) + { + if (s_x[i]->h != 0) + { + chemistry_dat << "+"; + if (s_x[i]->h != 1) + { + chemistry_dat << s_x[i]->h << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".diss}"; + } + } + } + chemistry_dat << "\")" << std::endl; + + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->o != 0) + { + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + { + chemistry_dat << "+"; + if (s_x[i]->o != 1) + { + chemistry_dat << s_x[i]->o << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".diss}"; + } + } + } + chemistry_dat << "\")" << std::endl; + chemistry_dat << std::endl; +} + +void +cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat) +{ + chemistry_dat << std:: + endl << "//********* Alkalinity definitions" << std::endl; + // + // Define alkalinity + // + chemistry_dat << "@Var: Alkalinity 0" << std::endl; + chemistry_dat << "@calc: (5, \"Alkalinity = 0"; + for (int i = 0; i < count_s_x; i++) + { + if (s_x[i]->alk == 0) + continue; + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + if (s_x[i]->alk < 0) + { + if (s_x[i]->alk != -1) + { + chemistry_dat << s_x[i]->alk << "*{" << name << ".con}"; + } + else + { + chemistry_dat << "-{" << name << ".con}"; + } + } + else if (s_x[i]->alk > 0) + { + if (s_x[i]->alk != 1) + { + chemistry_dat << "+" << s_x[i]-> + alk << "*{" << name << ".con}"; + } + else + { + chemistry_dat << "+{" << name << ".con}"; + } + } + } + chemistry_dat << "\")" << std::endl; + // + // Alkalinity (or pH) equation + // + std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); + if ((iter = this->comps.find("Alkalinity")) != this->comps.end()) + { + if ((this->comps.find("C(4)") != this->comps.end()) + || (this->comps.find("C") != this->comps.end())) + { + if (this->comps.find("H(1)") != this->comps.end()) + { + std::ostringstream oss; + oss << + "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << + std::endl; + chemistry_dat << std::endl; + } + else + { + struct master *master_ptr = master_bsearch("Alkalinity"); + if (master_ptr == NULL) + { + std::ostringstream oss; + oss << "Could not find Alkalinity definition in database."; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + } + chemistry_dat << "@species(" << master_ptr->s-> + name << ", " << master_ptr->s->z << ")" << std::endl; + chemistry_dat << "@solve (" << master_ptr->s-> + name << ".act, 1e-6, log, 1, Alkalinity, 1e-9)" << std::endl; + chemistry_dat << std::endl; + } + } +} + +void +cxxISolution::ORCH_write_chemistry_minerals(std::ostream & chemistry_dat) +{ + chemistry_dat << std:: + endl << "//********* Adjustments to mineral equilibrium" << std::endl; // // Write minerals // - std::map::iterator iter = this->comps.begin(); - for(iter = this->comps.begin(); iter != this->comps.end(); ++iter) - { - if (iter->second.get_equation_name() != NULL) - { - std::string name(iter->second.get_equation_name()); - if (name != "charge") - { - struct phase *phase_ptr; - int n; - phase_ptr = phase_bsearch(name.c_str(), &n, FALSE); - assert (phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@si_mineral(" << phase_name << ")" << std::endl; - chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, -phase_ptr->lk); - struct rxn_token *next_token = phase_ptr->rxn_x->token; - next_token++; - while (next_token->s != NULL || next_token->name != NULL) + std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); + for (iter = this->comps.begin(); iter != this->comps.end(); ++iter) { - chemistry_dat << ", " << next_token->coef; - if (next_token->s != NULL) - { - chemistry_dat << ", " << next_token->s->name; - } else { - chemistry_dat << ", " << next_token->name; - } - next_token++; + if (iter->second.get_equation_name() != NULL) + { + std::string name(iter->second.get_equation_name()); + if (name != "charge") + { + struct phase *phase_ptr; + int n; + phase_ptr = phase_bsearch(name.c_str(), &n, FALSE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@si_mineral(" << phase_name << ")" << std:: + endl; + chemistry_dat << "@reaction(" << phase_name << ", " << + pow(10.0, -phase_ptr->lk); + struct rxn_token *next_token = phase_ptr->rxn_x->token; + next_token++; + while (next_token->s != NULL || next_token->name != NULL) + { + chemistry_dat << ", " << next_token->coef; + if (next_token->s != NULL) + { + chemistry_dat << ", " << next_token->s->name; + } + else + { + chemistry_dat << ", " << next_token->name; + } + next_token++; + } + chemistry_dat << ")" << std::endl; + } + } } - chemistry_dat << ")" << std::endl; - } - } - } - //chemistry_dat << "@mineral(Quartz)" << std::endl; - //chemistry_dat << "@sreaction(Quartz, 10139.1138573668, -2.0, H2O, 1.0, H4SiO4)" << std::endl; + //chemistry_dat << "@mineral(Quartz)" << std::endl; + //chemistry_dat << "@sreaction(Quartz, 10139.1138573668, -2.0, H2O, 1.0, H4SiO4)" << std::endl; } -void cxxISolution::ORCH_write_input(std::ostream &input_dat) +void +cxxISolution::ORCH_write_input(std::ostream & input_dat) { // // Write orchestra input file info // - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; - // Solution element and attributes + // Solution element and attributes - //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; - //s_oss << "-temp " << this->tc << std::endl; - headings << "tempc\t"; - data << this->tc << "\t"; + //s_oss << "-temp " << this->tc << std::endl; + headings << "tempc\t"; + data << this->tc << "\t"; - //s_oss << "-pH " << this->ph << std::endl; - headings << "pH\t"; - data << this->ph << "\t"; + //s_oss << "-pH " << this->ph << std::endl; + headings << "pH\t"; + data << this->ph << "\t"; - //s_oss << "-pe " << this->pe << std::endl; - headings << "pe\t"; - data << this->pe << "\t"; + //s_oss << "-pe " << this->pe << std::endl; + headings << "pe\t"; + data << this->pe << "\t"; - //s_oss << "-mu " << this->mu << std::endl; + //s_oss << "-mu " << this->mu << std::endl; - //s_oss << "-ah2o " << this->ah2o << std::endl; - headings << "H2O.act\t"; - data << 1 << "\t"; - //s_oss << "-total_h " << this->total_h << std::endl; + //s_oss << "-ah2o " << this->ah2o << std::endl; + headings << "H2O.act\t"; + data << 1 << "\t"; + //s_oss << "-total_h " << this->total_h << std::endl; - //s_oss << "-total_o " << this->total_o << std::endl; + //s_oss << "-total_o " << this->total_o << std::endl; - //s_oss << "-cb " << this->cb << std::endl; + //s_oss << "-cb " << this->cb << std::endl; - //s_oss << "-mass_water " << this->mass_water << std::endl; + //s_oss << "-mass_water " << this->mass_water << std::endl; - //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - // soln_total conc structures - //this->totals.dump_raw(s_oss, indent + 2); - //this->totals.write_orchestra(headings, s_oss); + // soln_total conc structures + //this->totals.dump_raw(s_oss, indent + 2); + //this->totals.write_orchestra(headings, s_oss); - std::map::iterator iter = this->comps.begin(); - for (; iter != this->comps.end(); ++iter) - { - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch (iter->first); - assert (master_ptr != NULL); - std::string ename(iter->first); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - { - coef = 1; - } - if (ename != "Alkalinity") - { - ename = master_ptr->s->name; - ename.append(".diss"); - } + std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); + for (; iter != this->comps.end(); ++iter) + { + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch(iter->first); + assert(master_ptr != NULL); + std::string ename(iter->first); + double coef = master_ptr->coef; + if (master_ptr->coef == 0) + { + coef = 1; + } + if (ename != "Alkalinity") + { + ename = master_ptr->s->name; + ename.append(".diss"); + } - if (iter->second.get_equation_name() == NULL) - { - headings << ename << "\t"; - data << (this->totals.find(iter->first))->second / coef << "\t"; - } else - { - std::string name(iter->second.get_equation_name()); - if (name == "charge") - { - headings << ename << "\t"; - data << (this->totals.find(iter->first))->second /coef << "\t"; - } else - { - int n; - struct phase *phase_ptr = phase_bsearch(name.c_str(),&n, TRUE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - headings << phase_name << ".si_raw" << "\t"; - data << iter->second.get_phase_si() << "\t"; - } - } - // activity estimate - if (ename == "Alkalinity") - { - if ((this->comps.find("C") == this->comps.end()) && (this->comps.find("C(4)") == this->comps.end())) - { - headings << master_ptr->s->name << ".act\t"; - data << iter->second.get_moles()*1e-3 << "\t"; - } - } - else - { - headings << master_ptr->s->name << ".act\t"; - data << iter->second.get_moles()*1e-3 << "\t"; - } - } - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ + if (iter->second.get_equation_name() == NULL) + { + headings << ename << "\t"; + data << (this->totals.find(iter->first))->second / coef << "\t"; + } + else + { + std::string name(iter->second.get_equation_name()); + if (name == "charge") + { + headings << ename << "\t"; + data << (this->totals.find(iter->first))->second / + coef << "\t"; + } + else + { + int n; + struct phase *phase_ptr = + phase_bsearch(name.c_str(), &n, TRUE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + headings << phase_name << ".si_raw" << "\t"; + data << iter->second.get_phase_si() << "\t"; + } + } + // activity estimate + if (ename == "Alkalinity") + { + if ((this->comps.find("C") == this->comps.end()) + && (this->comps.find("C(4)") == this->comps.end())) + { + headings << master_ptr->s->name << ".act\t"; + data << iter->second.get_moles() * 1e-3 << "\t"; + } + } + else + { + headings << master_ptr->s->name << ".act\t"; + data << iter->second.get_moles() * 1e-3 << "\t"; + } + } + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ - // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; - return; + return; } -void cxxISolution::ORCH_write_output_vars(std::ostream &outstream) +void +cxxISolution::ORCH_write_output_vars(std::ostream & outstream) { - outstream << "Var:"; - outstream << "\tnr_iter"; - // - // Serialize solution - // - outstream << "\tstart_solution"; - //tc - outstream << "\ttempc"; - //pH - outstream << "\tpH"; - //pe - outstream << "\tpe"; - //mu - outstream << "\tI"; - //ah2o - outstream << "\tH2O.act"; - //total_h; - outstream << "\ttotal_hydrogen"; - //total_o; - outstream << "\ttotal_oxygen"; - //cb - outstream << "\tchargebalance"; - //mass_water; - outstream << "\tH2O.con"; - //total_alkalinity; - outstream << "\tAlkalinity"; - //orchestra master variables - outstream << "\tH+.diss"; - outstream << "\te-.diss"; - outstream << "\tH2O.diss"; - //totals - for(std::map::iterator iter = this->comps.begin(); iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - outstream << "\t" << s_ptr->name << ".diss"; - } - outstream << "\tend_totals"; - for(std::map::iterator iter = this->comps.begin(); iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - outstream << "\t" << s_ptr->name << ".act"; - } - outstream << "\tend_master_activities"; - // - // Write all species activities and concentrations - // - int i; - for (i = 0; i < count_s_x; i++) { - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; - } - outstream << "\tend_species"; - outstream << std::endl; - return; + outstream << "Var:"; + outstream << "\tnr_iter"; + // + // Serialize solution + // + outstream << "\tstart_solution"; + //tc + outstream << "\ttempc"; + //pH + outstream << "\tpH"; + //pe + outstream << "\tpe"; + //mu + outstream << "\tI"; + //ah2o + outstream << "\tH2O.act"; + //total_h; + outstream << "\ttotal_hydrogen"; + //total_o; + outstream << "\ttotal_oxygen"; + //cb + outstream << "\tchargebalance"; + //mass_water; + outstream << "\tH2O.con"; + //total_alkalinity; + outstream << "\tAlkalinity"; + //orchestra master variables + outstream << "\tH+.diss"; + outstream << "\te-.diss"; + outstream << "\tH2O.diss"; + //totals + for (std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") + continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + outstream << "\t" << s_ptr->name << ".diss"; + } + outstream << "\tend_totals"; + for (std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + this->comps.begin(); iter != this->comps.end(); ++iter) + { + std::string name(iter->second.get_description()); + if (name == "H(1)" || name == "E" || name == "Alkalinity") + continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + outstream << "\t" << s_ptr->name << ".act"; + } + outstream << "\tend_master_activities"; + // + // Write all species activities and concentrations + // + int i; + for (i = 0; i < count_s_x; i++) + { + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + outstream << "\t" << name.c_str() << ".act" << "\t" << name. + c_str() << ".con"; + } + outstream << "\tend_species"; + outstream << std::endl; + return; } -void cxxISolution::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) + +void +cxxISolution::ORCH_write(std::ostream & chemistry_dat, + std::ostream & input_dat, std::ostream & output_dat) { - // - // Write orchestra chemistry file definition - // - chemistry_dat << std::endl << "// Write ORCHESTRA chemistry definitions" << std::endl; - // mark for Orchestra include - chemistry_dat << std::endl << "@class: species_reactions () {" << std::endl; - this->ORCH_write_chemistry(chemistry_dat); - // end orchestra include block - chemistry_dat << std::endl << "}" << std::endl; - // - // Write orchestra input file definition - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - this->ORCH_write_input(input_dat); - input_dat << std::endl << "}" << std::endl; + // + // Write orchestra chemistry file definition + // + chemistry_dat << std:: + endl << "// Write ORCHESTRA chemistry definitions" << std::endl; + // mark for Orchestra include + chemistry_dat << std::endl << "@class: species_reactions () {" << std:: + endl; + this->ORCH_write_chemistry(chemistry_dat); + // end orchestra include block + chemistry_dat << std::endl << "}" << std::endl; + // + // Write orchestra input file definition + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + this->ORCH_write_input(input_dat); + input_dat << std::endl << "}" << std::endl; - // - // Write orchestra output file definition - // - output_dat << std::endl << "Output_every: 1" << std::endl; - this->ORCH_write_output_vars(output_dat); + // + // Write orchestra output file definition + // + output_dat << std::endl << "Output_every: 1" << std::endl; + this->ORCH_write_output_vars(output_dat); - //write data to stderr - //std::cerr << chemistry_dat.str() << input_dat.str() << output_dat.str(); + //write data to stderr + //std::cerr << chemistry_dat.str() << input_dat.str() << output_dat.str(); -} +} #endif diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 69c45d1d..af851ae1 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -1,5 +1,5 @@ #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "ISolutionComp.h" @@ -12,38 +12,32 @@ #include "phqalloc.h" #include "output.h" -cxxISolutionComp::cxxISolutionComp(void) -: description(NULL) -, moles(0.0) -, input_conc(0.0) -, units(NULL) -, equation_name(NULL) -, phase_si(0.0) -, n_pe(-1) -, as(NULL) -, gfw(0.0) - //, skip(0); - //, phase(NULL) +cxxISolutionComp::cxxISolutionComp(void):description(NULL), moles(0.0), input_conc(0.0), units(NULL), +equation_name(NULL), phase_si(0.0), n_pe(-1), as(NULL), +gfw(0.0) + //, skip(0); + //, phase(NULL) { } cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr) { - description = conc_ptr->description; - moles = conc_ptr->moles; - input_conc = conc_ptr->input_conc; - units = conc_ptr->units; - equation_name = conc_ptr->equation_name; - phase_si = conc_ptr->phase_si; - n_pe = conc_ptr->n_pe; - as = conc_ptr->as; - gfw = conc_ptr->gfw; - //skip = conc_ptr->skip; - //phase = conc_ptr->phase; + description = conc_ptr->description; + moles = conc_ptr->moles; + input_conc = conc_ptr->input_conc; + units = conc_ptr->units; + equation_name = conc_ptr->equation_name; + phase_si = conc_ptr->phase_si; + n_pe = conc_ptr->n_pe; + as = conc_ptr->as; + gfw = conc_ptr->gfw; + //skip = conc_ptr->skip; + //phase = conc_ptr->phase; } cxxISolutionComp::~cxxISolutionComp(void) { } + /* struct conc *cxxISolutionComp::concarray(std::map &totals) // for Solutions, not ISolutions @@ -72,205 +66,253 @@ struct conc *cxxISolutionComp::concarray(std::map &totals) - // for ISolutions - // takes a std::vector cxxISolutionComp structures - // returns list of conc structures +struct conc * +cxxISolutionComp::cxxISolutionComp2conc(const std::map < char *, + cxxISolutionComp, + CHARSTAR_LESS > &totals) + // for ISolutions + // takes a std::vector cxxISolutionComp structures + // returns list of conc structures { - struct conc *c; - c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); - if (c == NULL) malloc_error(); - int i = 0; - for (std::map::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = it->second.description; - c[i].moles = it->second.moles; - c[i].input_conc = it->second.input_conc; - c[i].units = it->second.units; - c[i].equation_name = it->second.equation_name; - c[i].phase_si = it->second.phase_si; - c[i].n_pe = it->second.n_pe; - c[i].as = it->second.as; - c[i].gfw = it->second.gfw; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return(c); + struct conc *c; + c = (struct conc *) + PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); + if (c == NULL) + malloc_error(); + int i = 0; + for (std::map < char *, cxxISolutionComp, + CHARSTAR_LESS >::const_iterator it = totals.begin(); + it != totals.end(); ++it) + { + c[i].description = it->second.description; + c[i].moles = it->second.moles; + c[i].input_conc = it->second.input_conc; + c[i].units = it->second.units; + c[i].equation_name = it->second.equation_name; + c[i].phase_si = it->second.phase_si; + c[i].n_pe = it->second.n_pe; + c[i].as = it->second.as; + c[i].gfw = it->second.gfw; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return (c); } -void cxxISolutionComp::set_gfw() +void +cxxISolutionComp::set_gfw() { // return gfw - if (this->gfw > 0.0) return; + if (this->gfw > 0.0) + return; // calculate gfw from as or from master species gfw - if (this->as != NULL) - { - /* use given chemical formula to calculate gfw */ - double gfw; - if (compute_gfw (this->as, &gfw) == ERROR) - { - std::ostringstream oss; - oss << "Could not compute gfw, " << this->as; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } - //if (this->description == "Alkalinity" && this->as == "CaCO3") - if (strcmp(this->description,"Alkalinity") == 0 && strcmp(this->as, "CaCO3")) - { - gfw /= 2.; - } - this->gfw = gfw; - return; - } - /* use gfw of master species */ - std::string str(this->description); - struct master *master_ptr = master_bsearch (str.c_str()); - if (master_ptr != NULL) - { - /* use gfw for element redox state */ - this->gfw = master_ptr->gfw; - return; - } - std::ostringstream oss; - oss << "Could not find gfw, " << this->description; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; + if (this->as != NULL) + { + /* use given chemical formula to calculate gfw */ + double gfw; + if (compute_gfw(this->as, &gfw) == ERROR) + { + std::ostringstream oss; + oss << "Could not compute gfw, " << this->as; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + //if (this->description == "Alkalinity" && this->as == "CaCO3") + if (strcmp(this->description, "Alkalinity") == 0 + && strcmp(this->as, "CaCO3")) + { + gfw /= 2.; + } + this->gfw = gfw; + return; + } + /* use gfw of master species */ + std::string str(this->description); + struct master *master_ptr = master_bsearch(str.c_str()); + if (master_ptr != NULL) + { + /* use gfw for element redox state */ + this->gfw = master_ptr->gfw; + return; + } + std::ostringstream oss; + oss << "Could not find gfw, " << this->description; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; } #ifdef SKIP -cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser& parser, cxxISolution& solution) +cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, + cxxISolution & solution) { - // std::string& str = parser.line(); - std::string str = parser.line(); + // std::string& str = parser.line(); + std::string str = parser.line(); - // defaults set in ctor + // defaults set in ctor - // Remove space between "kg" and "solution" or "water" in units - Utilities::replace("Kg", "kg", str); - Utilities::replace("KG", "kg", str); - while (Utilities::replace("kg ", "kg", str)); + // Remove space between "kg" and "solution" or "water" in units + Utilities::replace("Kg", "kg", str); + Utilities::replace("KG", "kg", str); + while (Utilities::replace("kg ", "kg", str)); - std::istream::pos_type ptr = 0; + std::istream::pos_type ptr = 0; - // - // Read master species list for mass balance equation - // - std::string token; - std::string token1; - int count_redox_states = 0; - CParser::TOKEN_TYPE j; - while ( ((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER ) || - ( token[0] == '[' ) || - ( Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0 ) || - ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) ) - { - ++count_redox_states; - Utilities::replace("(+", "(", token); - if (count_redox_states > 1) token1 += " "; - token1 += token; - } - if (count_redox_states == 0) { - parser.incr_input_error(); - parser.error_msg("No element or master species given for concentration input.", CParser::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - description = token1; + // + // Read master species list for mass balance equation + // + std::string token; + std::string token1; + int + count_redox_states = 0; + CParser::TOKEN_TYPE j; + while (((j = parser.copy_token(token, ptr)) == CParser::TT_UPPER) || + (token[0] == '[') || + (Utilities::strcmp_nocase_arg1(token.c_str(), "ph") == 0) || + (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0)) + { + ++count_redox_states; + Utilities::replace("(+", "(", token); + if (count_redox_states > 1) + token1 += " "; + token1 += token; + } + if (count_redox_states == 0) + { + parser.incr_input_error(); + parser. + error_msg + ("No element or master species given for concentration input.", + CParser::OT_CONTINUE); + return cxxISolutionComp::ERROR; + } + description = token1; - // Determine if reading alkalinity, allow equivalents for units - Utilities::str_tolower(token1); - bool alk = false; - if (token1.find("alk") == 0) { - alk = true; - } + // Determine if reading alkalinity, allow equivalents for units + Utilities::str_tolower(token1); + bool + alk = false; + if (token1.find("alk") == 0) + { + alk = true; + } - // Read concentration - if (!(std::istringstream(token) >> this->input_conc)) { - std::ostringstream err; - err << "Concentration data error for " << token1 << " in solution input."; - parser.error_msg(err, CParser::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; + // Read concentration + if (!(std::istringstream(token) >> this->input_conc)) + { + std::ostringstream err; + err << "Concentration data error for " << token1 << + " in solution input."; + parser.error_msg(err, CParser::OT_CONTINUE); + return cxxISolutionComp::ERROR; + } + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; - // Read optional data - token1 = token; - - // Check for units info - if (parser.check_units(token1, alk, false, solution.get_units(), false) == CParser::OK) { - if (parser.check_units(token1, alk, false, solution.get_units(), true) == CParser::OK) { - this->units = token1; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; - } else { - return cxxISolutionComp::ERROR; - } - } + // Read optional data + token1 = token; - // Check for "as" followed by formula to be used for gfw - token1 = token; - Utilities::str_tolower(token1); - if (token1.compare("as") == 0) - { - parser.copy_token(token, ptr); - this->as = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; - } - // Check for "gfw" followed by gram formula weight - else if (token1.compare("gfw") == 0) - { - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { - parser.error_msg("Expecting gram formula weight.", CParser::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } else { - parser.get_iss() >> this->gfw; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; - } - } + // Check for units info + if (parser.check_units(token1, alk, false, solution.get_units(), false) == + CParser::OK) + { + if (parser. + check_units(token1, alk, false, solution.get_units(), + true) == CParser::OK) + { + this->units = token1; + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + } + else + { + return cxxISolutionComp::ERROR; + } + } - // Check for redox couple for pe - if ( Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0 ) { - this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; - } else if (token.find("/") != std::string::npos) { - if (parser.parse_couple(token) == CParser::OK) { - this->n_pe = cxxPe_Data::store(solution.pe, token); - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; - } else { - return cxxISolutionComp::ERROR; - } - } + // Check for "as" followed by formula to be used for gfw + token1 = token; + Utilities::str_tolower(token1); + if (token1.compare("as") == 0) + { + parser.copy_token(token, ptr); + this->as = token; + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + } + // Check for "gfw" followed by gram formula weight + else if (token1.compare("gfw") == 0) + { + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) + { + parser.error_msg("Expecting gram formula weight.", + CParser::OT_CONTINUE); + return cxxISolutionComp::ERROR; + } + else + { + parser.get_iss() >> this->gfw; + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + } + } - // Must have phase - this->equation_name = token; - if ( (j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) return cxxISolutionComp::OK; + // Check for redox couple for pe + if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) + { + this->n_pe = cxxPe_Data::store(solution.pe, token); + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + } + else if (token.find("/") != std::string::npos) + { + if (parser.parse_couple(token) == CParser::OK) + { + this->n_pe = cxxPe_Data::store(solution.pe, token); + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + } + else + { + return cxxISolutionComp::ERROR; + } + } - // Check for saturation index - if (!(std::istringstream(token) >> this->phase_si)) - { - parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); - return cxxISolutionComp::ERROR; - } - return cxxISolutionComp::OK; + // Must have phase + this->equation_name = token; + if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) + return cxxISolutionComp::OK; + + // Check for saturation index + if (!(std::istringstream(token) >> this->phase_si)) + { + parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); + return cxxISolutionComp::ERROR; + } + return cxxISolutionComp::OK; } #endif #ifdef SKIP -void cxxISolutionComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - unsigned int i; - std::string indent0(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + unsigned int i; + std::string indent0(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); - s_oss << indent0; - s_oss << "description << "\"" ; + s_oss << " conc_desc=\"" << this->description << "\""; - s_oss << " conc_moles=\"" << this->moles << "\"" ; + s_oss << " conc_moles=\"" << this->moles << "\""; - s_oss << "\">" << std::endl; + s_oss << "\">" << std::endl; } #endif diff --git a/KineticsComp.cxx b/KineticsComp.cxx index c93f5d30..45da3f67 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -2,330 +2,394 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "KineticsComp.h" #include "Dictionary.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxKineticsComp::cxxKineticsComp() - // - // default constructor for cxxKineticsComp - // + // + // default constructor for cxxKineticsComp + // { - rate_name = NULL; - tol = 1e-8; - m = 0.0; - m0 = 0.0; - moles = 0.0; - namecoef.type = cxxNameDouble::ND_NAME_COEF; + rate_name = NULL; + tol = 1e-8; + m = 0.0; + m0 = 0.0; + moles = 0.0; + namecoef.type = cxxNameDouble::ND_NAME_COEF; } cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr) - // - // constructor for cxxKineticsComp from struct kinetics_comp - // -: + // + // constructor for cxxKineticsComp from struct kinetics_comp + // + : namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) { - rate_name = kinetics_comp_ptr->rate_name; - tol = kinetics_comp_ptr->tol; - m = kinetics_comp_ptr->m; - m0 = kinetics_comp_ptr->m0; - moles = kinetics_comp_ptr->moles; - for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++) { - this->d_params.push_back(kinetics_comp_ptr->d_params[i]); - } + rate_name = kinetics_comp_ptr->rate_name; + tol = kinetics_comp_ptr->tol; + m = kinetics_comp_ptr->m; + m0 = kinetics_comp_ptr->m0; + moles = kinetics_comp_ptr->moles; + for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++) + { + this->d_params.push_back(kinetics_comp_ptr->d_params[i]); + } } cxxKineticsComp::~cxxKineticsComp() { } -struct kinetics_comp *cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list& el) - // - // Builds kinetics_comp structure from of cxxKineticsComp - // +struct kinetics_comp * +cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > + &el) + // + // Builds kinetics_comp structure from of cxxKineticsComp + // { - struct kinetics_comp *kinetics_comp_ptr = (struct kinetics_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); - if (kinetics_comp_ptr == NULL) malloc_error(); + struct kinetics_comp *kinetics_comp_ptr = + (struct kinetics_comp *) + PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); + if (kinetics_comp_ptr == NULL) + malloc_error(); - int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - kinetics_comp_ptr[i].rate_name = it->rate_name; - kinetics_comp_ptr[i].list = it->namecoef.name_coef(); - kinetics_comp_ptr[i].count_list = (int) it->namecoef.size(); - kinetics_comp_ptr[i].tol = it->tol; - kinetics_comp_ptr[i].m = it->m; - kinetics_comp_ptr[i].initial_moles = 0.; - kinetics_comp_ptr[i].m0 = it->m0; - kinetics_comp_ptr[i].moles = it->moles; - kinetics_comp_ptr[i].count_c_params = 0; - kinetics_comp_ptr[i].c_params = NULL; + int i = 0; + for (std::list < cxxKineticsComp >::iterator it = el.begin(); + it != el.end(); ++it) + { + kinetics_comp_ptr[i].rate_name = it->rate_name; + kinetics_comp_ptr[i].list = it->namecoef.name_coef(); + kinetics_comp_ptr[i].count_list = (int) it->namecoef.size(); + kinetics_comp_ptr[i].tol = it->tol; + kinetics_comp_ptr[i].m = it->m; + kinetics_comp_ptr[i].initial_moles = 0.; + kinetics_comp_ptr[i].m0 = it->m0; + kinetics_comp_ptr[i].moles = it->moles; + kinetics_comp_ptr[i].count_c_params = 0; + kinetics_comp_ptr[i].c_params = NULL; /* kinetics_comp_ptr[i].count_d_params = 0; kinetics_comp_ptr[i].d_params = NULL; */ - kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size(); - kinetics_comp_ptr[i].d_params = NULL; - if (it->d_params.size() > 0) { - kinetics_comp_ptr[i].d_params = (double *) PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double))); - if (kinetics_comp_ptr[i].d_params == NULL) malloc_error(); - std::copy(it->d_params.begin(), it->d_params.end(), kinetics_comp_ptr[i].d_params); - } + kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size(); + kinetics_comp_ptr[i].d_params = NULL; + if (it->d_params.size() > 0) + { + kinetics_comp_ptr[i].d_params = + (double *) + PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double))); + if (kinetics_comp_ptr[i].d_params == NULL) + malloc_error(); + std::copy(it->d_params.begin(), it->d_params.end(), + kinetics_comp_ptr[i].d_params); + } i++; - } - return(kinetics_comp_ptr); + } + return (kinetics_comp_ptr); } + #ifdef SKIP -void cxxKineticsComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Kinetics_Comp element and attributes + // Kinetics_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; - s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; - if (this->phase_name != NULL) { - s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; - } - if (this->rate_name != NULL) { - s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; - } - s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this-> + charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) + { + s_oss << indent0 << "phase_name=\"" << this-> + phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) + { + s_oss << indent0 << "rate_name=\"" << this-> + rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this-> + phase_proportion << "\"" << std::endl; - // totals - s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); } #endif -void cxxKineticsComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Kinetics_Comp element and attributes + // Kinetics_Comp element and attributes - s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; - s_oss << indent0 << "-tol " << this->tol << std::endl; - s_oss << indent0 << "-m " << this->m << std::endl; - s_oss << indent0 << "-m0 " << this->m0 << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-rate_name " << this-> + rate_name << std::endl; + s_oss << indent0 << "-tol " << this->tol << std::endl; + s_oss << indent0 << "-m " << this->m << std::endl; + s_oss << indent0 << "-m0 " << this->m0 << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; - // namecoef - s_oss << indent0; - s_oss << "-namecoef" << std::endl; - this->namecoef.dump_raw(s_oss, indent + 1); + // namecoef + s_oss << indent0; + s_oss << "-namecoef" << std::endl; + this->namecoef.dump_raw(s_oss, indent + 1); - // d_params - s_oss << indent0; - s_oss << "-d_params" << std::endl; - { - int i = 0; - s_oss << indent1; - for (std::vector::const_iterator it = d_params.begin(); it != d_params.end(); it++) { - if (i++ == 5) { - s_oss << std::endl; - s_oss << indent1; - i = 0; - } - s_oss << *it << " "; - } - s_oss << std::endl; - } + // d_params + s_oss << indent0; + s_oss << "-d_params" << std::endl; + { + int i = 0; + s_oss << indent1; + for (std::vector < double >::const_iterator it = d_params.begin(); + it != d_params.end(); it++) + { + if (i++ == 5) + { + s_oss << std::endl; + s_oss << indent1; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } } -void cxxKineticsComp::read_raw(CParser& parser) +void +cxxKineticsComp::read_raw(CParser & parser) { - std::string str; - double d; + std::string str; + double d; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("rate_name"); // 0 - vopts.push_back("tol"); // 1 - vopts.push_back("m"); // 2 - vopts.push_back("m0"); // 3 - vopts.push_back("moles"); // 4 - vopts.push_back("namecoef"); // 5 - vopts.push_back("d_params"); // 6 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("rate_name"); // 0 + vopts.push_back("tol"); // 1 + vopts.push_back("m"); // 2 + vopts.push_back("m0"); // 3 + vopts.push_back("moles"); // 4 + vopts.push_back("namecoef"); // 5 + vopts.push_back("d_params"); // 6 + } - opt_save = CParser::OPT_ERROR; - bool rate_name_defined(false); - bool tol_defined(false); - bool m_defined(false); - bool m0_defined(false); - bool moles_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool rate_name_defined(false); + bool tol_defined(false); + bool m_defined(false); + bool m0_defined(false); + bool moles_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Kinetics for more processing - //parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // rate_name - if (!(parser.get_iss() >> str)) - { - this->rate_name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); - } else { - this->rate_name = string_hsave(str.c_str()); - } - rate_name_defined = true; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Kinetics for more processing + //parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 1: // tol - if (!(parser.get_iss() >> this->tol)) - { - this->tol = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for tol.", CParser::OT_CONTINUE); - } - tol_defined = true; - break; + case 0: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", + CParser::OT_CONTINUE); + } + else + { + this->rate_name = string_hsave(str.c_str()); + } + rate_name_defined = true; + break; - case 2: // m - if (!(parser.get_iss() >> this->m)) - { - this->m = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for m.", CParser::OT_CONTINUE); - } - m_defined = true; - break; + case 1: // tol + if (!(parser.get_iss() >> this->tol)) + { + this->tol = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for tol.", + CParser::OT_CONTINUE); + } + tol_defined = true; + break; - case 3: // m0 - if (!(parser.get_iss() >> this->m0)) - { - this->m0 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for m0.", CParser::OT_CONTINUE); - } - m0_defined = true; - break; + case 2: // m + if (!(parser.get_iss() >> this->m)) + { + this->m = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for m.", + CParser::OT_CONTINUE); + } + m_defined = true; + break; + + case 3: // m0 + if (!(parser.get_iss() >> this->m0)) + { + this->m0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for m0.", + CParser::OT_CONTINUE); + } + m0_defined = true; + break; - case 4: // moles - if (!(parser.get_iss() >> this->moles)) - { - this->moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); - } - moles_defined = true; - break; + case 4: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + CParser::OT_CONTINUE); + } + moles_defined = true; + break; - case 5: // namecoef - if ( this->namecoef.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for namecoef.", CParser::OT_CONTINUE); - } - opt_save = 5; - break; + case 5: // namecoef + if (this->namecoef.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for namecoef.", + CParser::OT_CONTINUE); + } + opt_save = 5; + break; - case 6: // d_params - while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - sscanf(token.c_str(), "%lf", &d); - this->d_params.push_back(d); - } - opt_save = 6; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (rate_name_defined == false) { - parser.incr_input_error(); - parser.error_msg("Rate_name not defined for KineticsComp input.", CParser::OT_CONTINUE); - } - if (tol_defined == false) { - parser.incr_input_error(); - parser.error_msg("Tol not defined for KineticsComp input.", CParser::OT_CONTINUE); - } - if (m_defined == false) { - parser.incr_input_error(); - parser.error_msg("M not defined for KineticsComp input.", CParser::OT_CONTINUE); - } - if (m0_defined == false) { - parser.incr_input_error(); - parser.error_msg("M0 not defined for KineticsComp input.", CParser::OT_CONTINUE); - } - if (moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE); - } + case 6: // d_params + while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) + { + sscanf(token.c_str(), "%lf", &d); + this->d_params.push_back(d); + } + opt_save = 6; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (rate_name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rate_name not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (tol_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Tol not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (m_defined == false) + { + parser.incr_input_error(); + parser.error_msg("M not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (m0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("M0 not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI -void cxxKineticsComp::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxKineticsComp::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->rate_name)); this->namecoef.mpi_pack(ints, doubles); doubles.push_back(this->tol); - doubles.push_back(this->m); - doubles.push_back(this->m0); - doubles.push_back(this->moles); + doubles.push_back(this->m); + doubles.push_back(this->m0); + doubles.push_back(this->moles); ints.push_back((int) this->d_params.size()); - for (std::vector::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) { + for (std::vector < double >::iterator it = this->d_params.begin(); + it != this->d_params.end(); it++) + { doubles.push_back(*it); } } -void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -333,50 +397,56 @@ void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->rate_name = dictionary.int2char(ints[i++]); this->namecoef.mpi_unpack(ints, &i, doubles, &d); this->tol = doubles[d++]; - this->m = doubles[d++]; - this->m0 = doubles[d++]; - this->moles = doubles[d++]; + this->m = doubles[d++]; + this->m0 = doubles[d++]; + this->moles = doubles[d++]; int n = ints[i++]; this->d_params.clear(); - for (int j = 0; j < n; j++) { + for (int j = 0; j < n; j++) + { this->d_params.push_back(doubles[d++]); } *ii = i; *dd = d; } #endif -void cxxKineticsComp::add(const cxxKineticsComp &addee, double extensive) +void +cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive) { - if (extensive == 0.0) return; - if (addee.rate_name == NULL) return; - // this and addee must have same name - // otherwise generate a new KineticsComp with multiply - if (this->rate_name == NULL && addee.rate_name == NULL) { - return; - } - //char * rate_name; - assert (this->rate_name == addee.rate_name); - //cxxNameDouble namecoef; - //double tol; - //double m; - this->m += addee.m * extensive; - //double m0; - this->m0 += addee.m0 * extensive; - //double moles; - this->moles += addee.moles * extensive; - //std::vector d_params; + if (extensive == 0.0) + return; + if (addee.rate_name == NULL) + return; + // this and addee must have same name + // otherwise generate a new KineticsComp with multiply + if (this->rate_name == NULL && addee.rate_name == NULL) + { + return; + } + //char * rate_name; + assert(this->rate_name == addee.rate_name); + //cxxNameDouble namecoef; + //double tol; + //double m; + this->m += addee.m * extensive; + //double m0; + this->m0 += addee.m0 * extensive; + //double moles; + this->moles += addee.moles * extensive; + //std::vector d_params; } -void cxxKineticsComp::multiply(double extensive) +void +cxxKineticsComp::multiply(double extensive) { - //char * rate_name; - //cxxNameDouble namecoef; - //double tol; - //double m; - this->m *= extensive; - //double m0; - this->m0 *= extensive; - //double moles; - this->moles *= extensive; - //std::vector d_params; + //char * rate_name; + //cxxNameDouble namecoef; + //double tol; + //double m; + this->m *= extensive; + //double m0; + this->m0 *= extensive; + //double moles; + this->moles *= extensive; + //std::vector d_params; } diff --git a/NameDouble.cxx b/NameDouble.cxx index d9cc422a..6f337e14 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -2,11 +2,11 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // std::cout std::cerr -#include "Utils.h" // define first +#include // std::cout std::cerr +#include "Utils.h" // define first #include "NameDouble.h" #include "Dictionary.h" #define EXTERNAL extern @@ -14,415 +14,511 @@ #include "output.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort -#include // std::sort +#include // assert +#include // std::sort +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxNameDouble::cxxNameDouble() - // - // default constructor for cxxNameDouble - // +cxxNameDouble::cxxNameDouble() + // + // default constructor for cxxNameDouble + // { } cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr) - // - // constructor for cxxNameDouble from list of elt_list - // + // + // constructor for cxxNameDouble from list of elt_list + // { - int i; - if (elt_list_ptr != NULL) { - for (i = 0; elt_list_ptr[i].elt != NULL; i++) { - (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; - } - } - this->type = ND_ELT_MOLES; + int i; + if (elt_list_ptr != NULL) + { + for (i = 0; elt_list_ptr[i].elt != NULL; i++) + { + (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; + } + } + this->type = ND_ELT_MOLES; } cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count) - // - // constructor for cxxNameDouble from list of elt_list with known count - // + // + // constructor for cxxNameDouble from list of elt_list with known count + // { - int i; - if (elt_list_ptr != NULL) { - for (i = 0; i < count; i++) - { - (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; - } - } - this->type = ND_ELT_MOLES; + int i; + if (elt_list_ptr != NULL) + { + for (i = 0; i < count; i++) + { + (*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef; + } + } + this->type = ND_ELT_MOLES; } -cxxNameDouble::cxxNameDouble(const cxxNameDouble &old, double factor) - // - // constructor for cxxNameDouble from list of elt_list - // +cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, double factor) + // + // constructor for cxxNameDouble from list of elt_list + // { - for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); it++) { - if (old.type == ND_ELT_MOLES) { - if (it->second * factor > 0) { + for (cxxNameDouble::const_iterator it = old.begin(); it != old.end(); + it++) + { + if (old.type == ND_ELT_MOLES) + { + if (it->second * factor > 0) + { (*this)[(it->first)] = it->second * factor; } - } else { + } + else + { (*this)[(it->first)] = it->second * factor; } - } + } this->type = old.type; } cxxNameDouble::cxxNameDouble(struct conc *tots) - // - // constructor for cxxNameDouble from list of elt_list - // + // + // constructor for cxxNameDouble from list of elt_list + // { - int i; - for (i = 0; tots[i].description != NULL; i++) { - (*this)[tots[i].description] = tots[i].moles; - } - this->type = ND_ELT_MOLES; + int i; + for (i = 0; tots[i].description != NULL; i++) + { + (*this)[tots[i].description] = tots[i].moles; + } + this->type = ND_ELT_MOLES; } -cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE type) - // - // constructor for cxxNameDouble from list of elt_list - // +cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, + cxxNameDouble::ND_TYPE type) + // + // constructor for cxxNameDouble from list of elt_list + // { - int i; - for (i = 0; i < count; i++) { - if (ma[i].description == NULL) continue; - (*this)[ma[i].description] = ma[i].la; - } - this->type = type; + int i; + for (i = 0; i < count; i++) + { + if (ma[i].description == NULL) + continue; + (*this)[ma[i].description] = ma[i].la; + } + this->type = type; } cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) - // - // constructor for cxxNameDouble from list of elt_list - // + // + // constructor for cxxNameDouble from list of elt_list + // { - int i; - for (i = 0; i < count; i++) { - if (nc[i].name == NULL) continue; - (*this)[nc[i].name] = nc[i].coef; - } - this->type = ND_NAME_COEF; + int i; + for (i = 0; i < count; i++) + { + if (nc[i].name == NULL) + continue; + (*this)[nc[i].name] = nc[i].coef; + } + this->type = ND_NAME_COEF; } + cxxNameDouble::~cxxNameDouble() { } -struct elt_list *cxxNameDouble::elt_list() - // - // Builds a exch_comp structure from instance of cxxNameDouble - // +struct elt_list * +cxxNameDouble::elt_list() + // + // Builds a exch_comp structure from instance of cxxNameDouble + // { - assert (this->type == cxxNameDouble::ND_ELT_MOLES); - struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((size_t)((this->size() + 1) *sizeof(struct elt_list))); - if (elt_list_ptr == NULL) malloc_error(); - int i = 0; - for (iterator it = this->begin(); it != this->end(); ++it) { - elt_list_ptr[i].elt = element_store(it->first); - elt_list_ptr[i].coef = it->second; - i++; - } - elt_list_ptr[i].elt = NULL; - elt_list_ptr[i].coef = 0; - return(elt_list_ptr); + assert(this->type == cxxNameDouble::ND_ELT_MOLES); + struct elt_list *elt_list_ptr = + (struct elt_list *) + PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list))); + if (elt_list_ptr == NULL) + malloc_error(); + int i = 0; + for (iterator it = this->begin(); it != this->end(); ++it) + { + elt_list_ptr[i].elt = element_store(it->first); + elt_list_ptr[i].coef = it->second; + i++; + } + elt_list_ptr[i].elt = NULL; + elt_list_ptr[i].coef = 0; + return (elt_list_ptr); } -struct master_activity *cxxNameDouble::master_activity()const - // - // Builds a list of master_activity structures from instance of cxxNameDouble - // +struct master_activity * +cxxNameDouble::master_activity() const const + // + // Builds a list of master_activity structures from instance of cxxNameDouble + // { - int i = 0; - assert (this->type == cxxNameDouble::ND_SPECIES_LA || this->type == cxxNameDouble::ND_SPECIES_GAMMA); - struct master_activity *master_activity_ptr = NULL; - switch ((*this).type) { - case cxxNameDouble::ND_SPECIES_LA: - { - master_activity_ptr= (struct master_activity *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct master_activity))); - if (master_activity_ptr == NULL) malloc_error(); - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = (char *)it->first; - master_activity_ptr[i].la = it->second; - i++; - } - } - master_activity_ptr[i].description = NULL; - break; - case cxxNameDouble::ND_SPECIES_GAMMA: - { - if ((*this).size() > 0) { - master_activity_ptr = (struct master_activity *) PHRQ_malloc((size_t) (((*this).size()) * sizeof(struct master_activity))); - if (master_activity_ptr == NULL) malloc_error(); - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = (char *)it->first; - master_activity_ptr[i].la = it->second; - i++; - } - } - } - break; - case cxxNameDouble::ND_ELT_MOLES: - case cxxNameDouble::ND_NAME_COEF: - break; - } - return(master_activity_ptr); -} - -struct conc *cxxNameDouble::conc()const - // for Solutions, not ISolutions - // takes a map of (elt name, moles) - // returns list of conc structures -{ - struct conc *c; - assert (this->type == cxxNameDouble::ND_ELT_MOLES); - c = (struct conc *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); - if (c == NULL) malloc_error(); - int i = 0; - for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - c[i].description = (char *)it->first; - c[i].moles = it->second; - c[i].input_conc = it->second; - c[i].units = NULL; - c[i].equation_name = NULL; - c[i].phase_si = 0.0; - c[i].n_pe = 0; - c[i].as = NULL; - c[i].gfw = 0.0; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return(c); -} - -struct name_coef *cxxNameDouble::name_coef()const - // - // Builds a name_coef structure from instance of cxxNameDouble - // -{ - assert (this->type == cxxNameDouble::ND_NAME_COEF); - struct name_coef *name_coef_ptr = (struct name_coef *) PHRQ_malloc((size_t)((this->size()) *sizeof(struct name_coef))); - if (name_coef_ptr == NULL) malloc_error(); - int i = 0; - for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - name_coef_ptr[i].name = it->first; - name_coef_ptr[i].coef = it->second; - i++; - } - return(name_coef_ptr); -} - -void cxxNameDouble::dump_xml(std::ostream& s_oss, unsigned int indent)const -{ - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - std::string xmlElement, xmlAtt1, xmlAtt2; - - switch ((*this).type) { - case cxxNameDouble::ND_SPECIES_LA: - xmlElement = "type == cxxNameDouble::ND_SPECIES_LA + || this->type == cxxNameDouble::ND_SPECIES_GAMMA); + struct master_activity *master_activity_ptr = NULL; + switch ((*this).type) + { + case cxxNameDouble::ND_SPECIES_LA: + { + master_activity_ptr = + (struct master_activity *) + PHRQ_malloc((size_t) + (((*this).size() + + 1) * sizeof(struct master_activity))); + if (master_activity_ptr == NULL) + malloc_error(); + for (const_iterator it = (*this).begin(); it != (*this).end(); + it++) + { + master_activity_ptr[i].description = (char *) it->first; + master_activity_ptr[i].la = it->second; + i++; + } + } + master_activity_ptr[i].description = NULL; break; - } - - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - s_oss << indent0; - s_oss << xmlElement << xmlAtt1 << it->first << xmlAtt2 << it->second << "/>" << std::endl; - } + case cxxNameDouble::ND_SPECIES_GAMMA: + { + if ((*this).size() > 0) + { + master_activity_ptr = + (struct master_activity *) + PHRQ_malloc((size_t) + (((*this).size()) * + sizeof(struct master_activity))); + if (master_activity_ptr == NULL) + malloc_error(); + for (const_iterator it = (*this).begin(); it != (*this).end(); + it++) + { + master_activity_ptr[i].description = (char *) it->first; + master_activity_ptr[i].la = it->second; + i++; + } + } + } + break; + case cxxNameDouble::ND_ELT_MOLES: + case cxxNameDouble::ND_NAME_COEF: + break; + } + return (master_activity_ptr); } -void cxxNameDouble::dump_raw(std::ostream& s_oss, unsigned int indent)const +struct conc * +cxxNameDouble::conc() const const + // for Solutions, not ISolutions + // takes a map of (elt name, moles) + // returns list of conc structures { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - s_oss << indent0; - s_oss << it->first << " " << it->second << std::endl; - } + struct conc *c; + assert(this->type == cxxNameDouble::ND_ELT_MOLES); + c = (struct conc *) + PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); + if (c == NULL) + malloc_error(); + int i = 0; + for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) + { + c[i].description = (char *) it->first; + c[i].moles = it->second; + c[i].input_conc = it->second; + c[i].units = NULL; + c[i].equation_name = NULL; + c[i].phase_si = 0.0; + c[i].n_pe = 0; + c[i].as = NULL; + c[i].gfw = 0.0; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return (c); } -CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser& parser, std::istream::pos_type& pos) + +struct name_coef * +cxxNameDouble::name_coef() const const + // + // Builds a name_coef structure from instance of cxxNameDouble + // { - std::string token; - char * ctoken; - double d; - - CParser::TOKEN_TYPE j; - - //m_line_iss.seekg(pos); - - j = parser.copy_token(token, pos); - - if (j == CParser::TT_EMPTY) return CParser::PARSER_OK; - - if( !(parser.get_iss() >> d)) { - return CParser::PARSER_ERROR; - } - ctoken = string_hsave(token.c_str()); - (*this)[ctoken] = d; - return CParser::PARSER_OK; + assert(this->type == cxxNameDouble::ND_NAME_COEF); + struct name_coef *name_coef_ptr = + (struct name_coef *) + PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef))); + if (name_coef_ptr == NULL) + malloc_error(); + int i = 0; + for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) + { + name_coef_ptr[i].name = it->first; + name_coef_ptr[i].coef = it->second; + i++; + } + return (name_coef_ptr); } -void cxxNameDouble::add_extensive(const cxxNameDouble &addee, double factor) +void +cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + std::string xmlElement, xmlAtt1, xmlAtt2; + + switch ((*this).type) + { + case cxxNameDouble::ND_SPECIES_LA: + xmlElement = "first << xmlAtt2 << it-> + second << "/>" << std::endl; + } +} + +void +cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) + { + s_oss << indent0; + s_oss << it->first << " " << it->second << std::endl; + } +} + +CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, + std::istream::pos_type & pos) +{ + std::string token; + char * + ctoken; + double + d; + + CParser::TOKEN_TYPE j; + + //m_line_iss.seekg(pos); + + j = parser.copy_token(token, pos); + + if (j == CParser::TT_EMPTY) + return CParser::PARSER_OK; + + if (!(parser.get_iss() >> d)) + { + return CParser::PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + (*this)[ctoken] = d; + return CParser::PARSER_OK; +} + +void +cxxNameDouble::add_extensive(const cxxNameDouble & addee, double factor) // // Sums two name doubles, this + factor*nd2 // { - if (factor == 0) return; - assert (factor > 0.0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - (*this)[it->first] = current->second + it->second * factor; - } else { - (*this)[it->first] = it->second * factor; - } - } + if (factor == 0) + return; + assert(factor > 0.0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); + it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = current->second + it->second * factor; + } + else + { + (*this)[it->first] = it->second * factor; + } + } } -void cxxNameDouble::add_intensive(const cxxNameDouble &addee, double f1, double f2) +void +cxxNameDouble::add_intensive(const cxxNameDouble & addee, double f1, + double f2) // // Sums two name doubles, this*f1 + f2*nd2 // { - assert(f1 >= 0 && f2 >= 0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - (*this)[it->first] = f1*current->second + f2*it->second; - } else { - (*this)[it->first] = f2 * it->second; - } - } + assert(f1 >= 0 && f2 >= 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); + it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + (*this)[it->first] = f1 * current->second + f2 * it->second; + } + else + { + (*this)[it->first] = f2 * it->second; + } + } } -void cxxNameDouble::add_log_activities(const cxxNameDouble &addee, double f1, double f2) +void +cxxNameDouble::add_log_activities(const cxxNameDouble & addee, double f1, + double f2) // // Sums two name doubles, this*f1 + f2*nd2, assuming log values // { - assert (f1 >= 0 && f2 >= 0); - for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) - { - cxxNameDouble::iterator current = (*this).find(it->first); - if (current != (*this).end()) - { - double a1 = pow(10., current->second); - double a2 = pow(10., it->second); - (*this)[it->first] = log10(f1*a1 + f2*a2); - } else { - //double a2 = pow(10. it->second); - //(*this)[it->first] = log10(f2 * a2); - (*this)[it->first] = it->second + log10(f2); - } - } + assert(f1 >= 0 && f2 >= 0); + for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); + it++) + { + cxxNameDouble::iterator current = (*this).find(it->first); + if (current != (*this).end()) + { + double a1 = pow(10., current->second); + double a2 = pow(10., it->second); + (*this)[it->first] = log10(f1 * a1 + f2 * a2); + } + else + { + //double a2 = pow(10. it->second); + //(*this)[it->first] = log10(f2 * a2); + (*this)[it->first] = it->second + log10(f2); + } + } } -void cxxNameDouble::add(const char * token, double total) +void +cxxNameDouble::add(const char *token, double total) // // add to total for a specified element // { - char key[MAX_LENGTH]; - strcpy(key, token); + char key[MAX_LENGTH]; + strcpy(key, token); - cxxNameDouble::iterator current = (*this).find(key); - if (current != (*this).end()) { - (*this)[key] = current->second + total; - } else { - (*this)[key] = total; - } + cxxNameDouble::iterator current = (*this).find(key); + if (current != (*this).end()) + { + (*this)[key] = current->second + total; + } + else + { + (*this)[key] = total; + } } -void cxxNameDouble::multiply(double extensive) +void +cxxNameDouble::multiply(double extensive) { // // Multiplies by extensive // - for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++) - { - it->second *= extensive; - } + for (cxxNameDouble::iterator it = this->begin(); it != this->end(); it++) + { + it->second *= extensive; + } } + #ifdef USE_MPI -void cxxNameDouble::mpi_pack(std::vector& ints, std::vector& doubles) { +void +cxxNameDouble::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) +{ extern cxxDictionary dictionary; - ints.push_back( (int) (*this).size() ); - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { + ints.push_back((int) (*this).size()); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) + { assert(it->first != NULL); int n = dictionary.string2int(it->first); ints.push_back(n); doubles.push_back(it->second); - } + } } -void cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) +void +cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; extern cxxDictionary dictionary; //ints.push_back( (*this).size() ); ints[i++] = (int) this->size(); - for (const_iterator it = this->begin(); it != this->end(); it++) { + for (const_iterator it = this->begin(); it != this->end(); it++) + { int n = dictionary.string2int(it->first); - if (n < 0) { + if (n < 0) + { std::cerr << it->first << std::endl; - error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); + error_msg("Name in NameDouble was not defined in dictionary?\n", + STOP); } //ints.push_back(n); ints[i++] = n; //doubles.push_back(it->second); doubles[d++] = it->second; - } + } *ii = i; *dd = d; } -void cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; extern cxxDictionary dictionary; this->clear(); int count = ints[i++]; - for (int j = 0; j < count; j++) { + for (int j = 0; j < count; j++) + { int n = ints[i++]; assert(n >= 0); - std::string *str = dictionary.int2string(n); - if (str != NULL) { + std::string * str = dictionary.int2string(n); + if (str != NULL) + { char *cstr = string_hsave(str->c_str()); (*this)[cstr] = doubles[d++]; } - } + } *ii = i; *dd = d; } diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 32cb2f15..3c0dd39a 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -1,5 +1,5 @@ #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif // NumKeyword.cxx: implementation of the cxxNumKeyword class. // @@ -21,120 +21,131 @@ cxxNumKeyword::~cxxNumKeyword() { } -void cxxNumKeyword::dump_xml(std::ostream& os, unsigned int indent)const +void +cxxNumKeyword::dump_xml(std::ostream & os, unsigned int indent) const const { - unsigned int i; + unsigned int i; - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->n_user << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << " "; + os << "" << this->n_user << "" << "\n"; - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->n_user_end << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << " "; + os << "" << this->n_user_end << "" << "\n"; - for(i = 0; i < indent + 1; ++i) os << " "; - os << "" << this->description << "" << "\n"; + for (i = 0; i < indent + 1; ++i) + os << " "; + os << "" << this->description << "" << "\n"; } -void cxxNumKeyword::read_number_description(CParser& parser) +void +cxxNumKeyword::read_number_description(CParser & parser) { - std::string keyword; - std::istream::pos_type ptr; + std::string keyword; + std::istream::pos_type ptr; - // skip keyword - parser.copy_token(keyword, ptr); + // skip keyword + parser.copy_token(keyword, ptr); - std::istream::pos_type ptr1 = ptr; - std::string::size_type pos; - std::string token; - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) - { - this->n_user = 1; - this->n_user_end = 1; - } else { - std::istringstream iss(token); - iss >> this->n_user; - this->n_user_end = this->n_user; - std::string token1; - iss >> token1; - if ( (pos = token1.find_first_of("-")) != std::string::npos ) { - token1.replace(pos, 1, " "); - std::istringstream iss1(token1); - iss1 >> this->n_user_end; - // ptr1 = ptr; - } - } - /* - else if ( (pos = token.find_first_of("-")) != std::string::npos ) - { - token.replace(pos, 1, " "); - std::istringstream iss(token); - if (!(iss >> this->n_user >> this->n_user_end)) - { - std::ostringstream err_oss; - if (parser.next_keyword() >= 0) - { - err_oss << "Reading number range for " << keyword << "."; - } - else - { - err_oss << "Reading number range for keyword."; - } - parser.error_msg(err_oss, CParser::OT_CONTINUE); - parser.incr_input_error(); - } - ptr1 = ptr; - } - else - { - std::istringstream iss(token); - iss >> this->n_user; - this->n_user_end = this->n_user; - ptr1 = ptr; - } - */ - // reset get position - //parser.get_iss().seekg(ptr1); + std::istream::pos_type ptr1 = ptr; + std::string::size_type pos; + std::string token; + if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) + { + this->n_user = 1; + this->n_user_end = 1; + } + else + { + std::istringstream iss(token); + iss >> this->n_user; + this->n_user_end = this->n_user; + std::string token1; + iss >> token1; + if ((pos = token1.find_first_of("-")) != std::string::npos) + { + token1.replace(pos, 1, " "); + std::istringstream iss1(token1); + iss1 >> this->n_user_end; + // ptr1 = ptr; + } + } + /* + else if ( (pos = token.find_first_of("-")) != std::string::npos ) + { + token.replace(pos, 1, " "); + std::istringstream iss(token); + if (!(iss >> this->n_user >> this->n_user_end)) + { + std::ostringstream err_oss; + if (parser.next_keyword() >= 0) + { + err_oss << "Reading number range for " << keyword << "."; + } + else + { + err_oss << "Reading number range for keyword."; + } + parser.error_msg(err_oss, CParser::OT_CONTINUE); + parser.incr_input_error(); + } + ptr1 = ptr; + } + else + { + std::istringstream iss(token); + iss >> this->n_user; + this->n_user_end = this->n_user; + ptr1 = ptr; + } + */ + // reset get position + //parser.get_iss().seekg(ptr1); - // skip whitespace - while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore(); + // skip whitespace + while (::isspace(parser.get_iss().peek())) + parser.get_iss().ignore(); - // copy description - std::getline(parser.get_iss(), this->description); + // copy description + std::getline(parser.get_iss(), this->description); } -void cxxNumKeyword::read_number_description(std::istream& is) +void +cxxNumKeyword::read_number_description(std::istream & is) { - // KEYWORD [[1[-20]] [This is the description]] + // KEYWORD [[1[-20]] [This is the description]] - // eat keyword - std::string token; - is >> token; + // eat keyword + std::string token; + is >> token; - // skip whitespace - while (::isspace(is.peek())) is.ignore(); + // skip whitespace + while (::isspace(is.peek())) + is.ignore(); - if (::isdigit(is.peek())) - { - is >> this->n_user; - char ch = is.peek(); - if (ch == '-') - { - is >> ch; // eat '-' - is >> this->n_user_end; - } - else - { - this->n_user_end = this->n_user; - } - } - else - { - this->n_user = this->n_user_end = 1; - } + if (::isdigit(is.peek())) + { + is >> this->n_user; + char ch = is.peek(); + if (ch == '-') + { + is >> ch; // eat '-' + is >> this->n_user_end; + } + else + { + this->n_user_end = this->n_user; + } + } + else + { + this->n_user = this->n_user_end = 1; + } - while (::isspace(is.peek())) is.ignore(); + while (::isspace(is.peek())) + is.ignore(); - std::getline(is, this->description); + std::getline(is, this->description); } - diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 77082818..7c200cce 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -2,227 +2,268 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "PPassemblage.h" #include "PPassemblageComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxPPassemblage::cxxPPassemblage() - // - // default constructor for cxxPPassemblage - // -: cxxNumKeyword() + // + // default constructor for cxxPPassemblage + // +: cxxNumKeyword() { - eltList.type = cxxNameDouble::ND_ELT_MOLES; + eltList.type = cxxNameDouble::ND_ELT_MOLES; } cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr) - // - // constructor for cxxPPassemblage from struct PPassemblage - // -: + // + // constructor for cxxPPassemblage from struct PPassemblage + // + : cxxNumKeyword(), eltList(pp_assemblage_ptr->next_elt) { - int i; + int i; - this->set_description(pp_assemblage_ptr->description); - n_user = pp_assemblage_ptr->n_user; - n_user_end = pp_assemblage_ptr->n_user_end; - for (i = 0; i < pp_assemblage_ptr->count_comps; i++) { - cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i])); - ppAssemblageComps.push_back(ppComp); - } + this->set_description(pp_assemblage_ptr->description); + n_user = pp_assemblage_ptr->n_user; + n_user_end = pp_assemblage_ptr->n_user_end; + for (i = 0; i < pp_assemblage_ptr->count_comps; i++) + { + cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i])); + ppAssemblageComps.push_back(ppComp); + } } -cxxPPassemblage::cxxPPassemblage(const std::map &entities, cxxMix &mix, int n_user) -: +cxxPPassemblage::cxxPPassemblage(const std::map < int, + cxxPPassemblage > &entities, cxxMix & mix, + int n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - eltList.type = cxxNameDouble::ND_ELT_MOLES; + this->n_user = this->n_user_end = n_user; + eltList.type = cxxNameDouble::ND_ELT_MOLES; // // Mix // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxPPassemblage *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); - } - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxPPassemblage *entity_ptr = + &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } } + cxxPPassemblage::~cxxPPassemblage() { } -struct pp_assemblage *cxxPPassemblage::cxxPPassemblage2pp_assemblage() - // - // Builds a pp_assemblage structure from instance of cxxPPassemblage - // +struct pp_assemblage * +cxxPPassemblage::cxxPPassemblage2pp_assemblage() + // + // Builds a pp_assemblage structure from instance of cxxPPassemblage + // { - struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); - - pp_assemblage_ptr->description = this->get_description(); - pp_assemblage_ptr->n_user = this->n_user; - pp_assemblage_ptr->n_user_end = this->n_user_end; - pp_assemblage_ptr->new_def = FALSE; - pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size(); - pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); - pp_assemblage_ptr->pure_phases = cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps); - pp_assemblage_ptr->next_elt = this->eltList.elt_list(); - return(pp_assemblage_ptr); + struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); + + pp_assemblage_ptr->description = this->get_description(); + pp_assemblage_ptr->n_user = this->n_user; + pp_assemblage_ptr->n_user_end = this->n_user_end; + pp_assemblage_ptr->new_def = FALSE; + pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size(); + pp_assemblage_ptr->pure_phases = + (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); + pp_assemblage_ptr->pure_phases = + cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this-> + ppAssemblageComps); + pp_assemblage_ptr->next_elt = this->eltList.elt_list(); + return (pp_assemblage_ptr); } -void cxxPPassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // PPassemblage element and attributes - s_oss << indent0; - s_oss << "eltList.dump_xml(s_oss, indent + 1); + // eltList + this->eltList.dump_xml(s_oss, indent + 1); - // ppAssemblageComps - s_oss << indent1; - s_oss << "::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // ppAssemblageComps + s_oss << indent1; + s_oss << "::const_iterator it = + ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } } -void cxxPPassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // PPassemblage element and attributes - s_oss << indent0; - s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this->description << std::endl; + // PPassemblage element and attributes + s_oss << indent0; + s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this-> + description << std::endl; - // eltList - - s_oss << indent1; - s_oss << "-eltList " << std::endl; - this->eltList.dump_raw(s_oss, indent + 2); + // eltList - // ppAssemblagComps - for (std::list::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { - s_oss << indent1; - s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); - } + s_oss << indent1; + s_oss << "-eltList " << std::endl; + this->eltList.dump_raw(s_oss, indent + 2); + + // ppAssemblagComps + for (std::list < cxxPPassemblageComp >::const_iterator it = + ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } } -void cxxPPassemblage::read_raw(CParser& parser) +void +cxxPPassemblage::read_raw(CParser & parser) { - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("eltlist"); // 0 - vopts.push_back("component"); // 1 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("eltlist"); // 0 + vopts.push_back("component"); // 1 + } - // Read PPassemblage number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; + // Read PPassemblage number and description + this->read_number_description(parser); - 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 EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; - case 0: // eltList - if ( this->eltList.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and moles for totals.", CParser::OT_CONTINUE); - } - opt_save = 0; - break; + 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 EQUILIBRIUM_PHASES_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; - case 1: // component - { - cxxPPassemblageComp ppComp; - ppComp.read_raw(parser); - this->ppAssemblageComps.push_back(ppComp); - } - useLastLine = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined + case 0: // eltList + if (this->eltList.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg("Expected element name and moles for totals.", + CParser::OT_CONTINUE); + } + opt_save = 0; + break; + + case 1: // component + { + cxxPPassemblageComp ppComp; + ppComp.read_raw(parser); + this->ppAssemblageComps.push_back(ppComp); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined } + #ifdef USE_MPI /* ---------------------------------------------------------------------- */ -void cxxPPassemblage::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxPPassemblage::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->ppAssemblageComps.size()); - for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) { + for (std::list < cxxPPassemblageComp >::iterator it = + this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); + it++) + { it->mpi_pack(ints, doubles); } this->eltList.mpi_pack(ints, doubles); } + /* ---------------------------------------------------------------------- */ -void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -234,7 +275,8 @@ void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) int count = ints[i++]; this->ppAssemblageComps.clear(); - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { cxxPPassemblageComp ppc; ppc.mpi_unpack(ints, &i, doubles, &d); this->ppAssemblageComps.push_back(ppc); @@ -245,119 +287,145 @@ void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif -void cxxPPassemblage::totalize() +void +cxxPPassemblage::totalize() { - this->totals.clear(); - // component structures - for (std::list::iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) - { - it->totalize(); - this->totals.add_extensive(it->get_totals(), 1.0); - } - return; + this->totals.clear(); + // component structures + for (std::list < cxxPPassemblageComp >::iterator it = + ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + { + it->totalize(); + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; } -void cxxPPassemblage::add(const cxxPPassemblage &addee, double extensive) - // - // Add to existing ppassemblage to "this" ppassemblage - // +void +cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // { - if (extensive == 0.0) return; - //std::list ppAssemblageComps; - for (std::list::const_iterator itadd = addee.ppAssemblageComps.begin(); itadd != addee.ppAssemblageComps.end(); ++itadd) - { - bool found = false; - for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) - { - if (it->get_name() == itadd->get_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) { - cxxPPassemblageComp entity = *itadd; - entity.multiply(extensive); - this->ppAssemblageComps.push_back(entity); - } - } - //cxxNameDouble eltList; - this->eltList.add_extensive(addee.eltList, extensive); + if (extensive == 0.0) + return; + //std::list ppAssemblageComps; + for (std::list < cxxPPassemblageComp >::const_iterator itadd = + addee.ppAssemblageComps.begin(); + itadd != addee.ppAssemblageComps.end(); ++itadd) + { + bool found = false; + for (std::list < cxxPPassemblageComp >::iterator it = + this->ppAssemblageComps.begin(); + it != this->ppAssemblageComps.end(); ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) + { + cxxPPassemblageComp entity = *itadd; + entity.multiply(extensive); + this->ppAssemblageComps.push_back(entity); + } + } + //cxxNameDouble eltList; + this->eltList.add_extensive(addee.eltList, extensive); } + #ifdef ORCHESTRA -void cxxPPassemblage::ORCH_write_chemistry(std::ostream &chemistry_dat) +void +cxxPPassemblage::ORCH_write_chemistry(std::ostream & chemistry_dat) { - chemistry_dat << std::endl << "//********* Mineral equilibria" << std::endl; + chemistry_dat << std::endl << "//********* Mineral equilibria" << std:: + endl; // // Write minerals // - for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) - { - struct phase *phase_ptr; - int n; - phase_ptr = phase_bsearch(it->get_name(), &n, FALSE); - assert (phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@mineral(" << phase_name << ")" << std::endl; - chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, -phase_ptr->lk); - struct rxn_token *next_token = phase_ptr->rxn_x->token; - next_token++; - while (next_token->s != NULL || next_token->name != NULL) - { - chemistry_dat << ", " << next_token->coef; - if (next_token->s != NULL) - { - chemistry_dat << ", " << next_token->s->name; - } else { - chemistry_dat << ", " << next_token->name; - } - next_token++; - } - chemistry_dat << ")" << std::endl; - } + for (std::list < cxxPPassemblageComp >::iterator it = + this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); + ++it) + { + struct phase *phase_ptr; + int n; + phase_ptr = phase_bsearch(it->get_name(), &n, FALSE); + assert(phase_ptr != NULL); + std::string phase_name(phase_ptr->name); + std::replace(phase_name.begin(), phase_name.end(), '(', '['); + std::replace(phase_name.begin(), phase_name.end(), ')', ']'); + chemistry_dat << "@mineral(" << phase_name << ")" << std::endl; + chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, + -phase_ptr-> + lk); + struct rxn_token *next_token = phase_ptr->rxn_x->token; + next_token++; + while (next_token->s != NULL || next_token->name != NULL) + { + chemistry_dat << ", " << next_token->coef; + if (next_token->s != NULL) + { + chemistry_dat << ", " << next_token->s->name; + } + else + { + chemistry_dat << ", " << next_token->name; + } + next_token++; + } + chemistry_dat << ")" << std::endl; + } } -void cxxPPassemblage::ORCH_write_output_vars(std::ostream &outstream) +void +cxxPPassemblage::ORCH_write_output_vars(std::ostream & outstream) { - // - // Write ppassemblage output variables - // - outstream << "\tstart_ppassemblage"; - for (std::list::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) - { - outstream << "\t" << it->get_name() << ".min"; - } - outstream << "\tend_ppassemblage"; + // + // Write ppassemblage output variables + // + outstream << "\tstart_ppassemblage"; + for (std::list < cxxPPassemblageComp >::iterator it = + this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); + ++it) + { + outstream << "\t" << it->get_name() << ".min"; + } + outstream << "\tend_ppassemblage"; } -void cxxPPassemblage::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) +void +cxxPPassemblage::ORCH_read(std::vector < std::pair < std::string, + double >>output_vector, + std::vector < std::pair < std::string, + double >>::iterator & it) { - while (it->first.compare("end_ppassemblage") != 0) - { - it++; - } + while (it->first.compare("end_ppassemblage") != 0) + { + it++; + } } -void cxxPPassemblage::ORCH_store_global(std::map < std::string, double > output_map) +void +cxxPPassemblage::ORCH_store_global(std::map < std::string, double >output_map) { - int i; - std::map < std::string, double >::iterator it; - for (i = 0; i < count_unknowns; i++) - { - // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O - switch (x[i]->type) - { - case PP: - std::string name(x[i]->phase->name); - name.append(".min"); - it = output_map.find(name); - assert (it != output_map.end()); - x[i]->moles = it->second; - break; - } - } + int i; + std::map < std::string, double >::iterator it; + for (i = 0; i < count_unknowns; i++) + { + // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O + switch (x[i]->type) + { + case PP: + std::string name(x[i]->phase->name); + name.append(".min"); + it = output_map.find(name); + assert(it != output_map.end()); + x[i]->moles = it->second; + break; + } + } } #endif diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 4d2e77b0..6b84ecac 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -2,10 +2,10 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "PPassemblageComp.h" #include "Dictionary.h" #define EXTERNAL extern @@ -13,294 +13,356 @@ #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxPPassemblageComp::cxxPPassemblageComp() - // - // default constructor for cxxPPassemblageComp - // + // + // default constructor for cxxPPassemblageComp + // { - name = NULL; - add_formula = NULL; - si = 0; - moles = 0; - delta = 0; - initial_moles = 0; - force_equality = false; - dissolve_only = false; + name = NULL; + add_formula = NULL; + si = 0; + moles = 0; + delta = 0; + initial_moles = 0; + force_equality = false; + dissolve_only = false; } -cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase *pure_phase_ptr) - // - // constructor for cxxPPassemblageComp from struct pure_phase - // - +cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr) + // + // constructor for cxxPPassemblageComp from struct pure_phase + // { - name = pure_phase_ptr->name; - add_formula = pure_phase_ptr->add_formula; - si = pure_phase_ptr->si; - moles = pure_phase_ptr->moles; - delta = pure_phase_ptr->delta; - initial_moles = pure_phase_ptr->initial_moles; - force_equality = ( pure_phase_ptr->force_equality == TRUE); - dissolve_only = ( pure_phase_ptr->dissolve_only == TRUE); + name = pure_phase_ptr->name; + add_formula = pure_phase_ptr->add_formula; + si = pure_phase_ptr->si; + moles = pure_phase_ptr->moles; + delta = pure_phase_ptr->delta; + initial_moles = pure_phase_ptr->initial_moles; + force_equality = (pure_phase_ptr->force_equality == TRUE); + dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); } cxxPPassemblageComp::~cxxPPassemblageComp() { } -struct phase *cxxPPassemblageComp::get_phase() { - int i; - return phase_bsearch(this->name, &i, FALSE); +struct phase * +cxxPPassemblageComp::get_phase() +{ + int i; + return phase_bsearch(this->name, &i, FALSE); } -struct pure_phase *cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list& el) - // - // Builds pure_phase structure from of cxxPPassemblageComp - // +struct pure_phase * +cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list < + cxxPPassemblageComp > &el) + // + // Builds pure_phase structure from of cxxPPassemblageComp + // { - struct pure_phase *pure_phase_ptr = (struct pure_phase *) PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); - if (pure_phase_ptr == NULL) malloc_error(); + struct pure_phase *pure_phase_ptr = + (struct pure_phase *) + PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); + if (pure_phase_ptr == NULL) + malloc_error(); - int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - pure_phase_ptr[i].phase = it->get_phase(); - pure_phase_ptr[i].name = it->name; - pure_phase_ptr[i].add_formula = it->add_formula; - pure_phase_ptr[i].si = it->si; - pure_phase_ptr[i].moles = it->moles; - pure_phase_ptr[i].delta = it->delta; - pure_phase_ptr[i].initial_moles = it->initial_moles; - pure_phase_ptr[i].force_equality = (int) it->force_equality; - pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; - i++; - } - return(pure_phase_ptr); + int i = 0; + for (std::list < cxxPPassemblageComp >::iterator it = el.begin(); + it != el.end(); ++it) + { + pure_phase_ptr[i].phase = it->get_phase(); + pure_phase_ptr[i].name = it->name; + pure_phase_ptr[i].add_formula = it->add_formula; + pure_phase_ptr[i].si = it->si; + pure_phase_ptr[i].moles = it->moles; + pure_phase_ptr[i].delta = it->delta; + pure_phase_ptr[i].initial_moles = it->initial_moles; + pure_phase_ptr[i].force_equality = (int) it->force_equality; + pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; + i++; + } + return (pure_phase_ptr); } -void cxxPPassemblageComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Pure_Phase element and attributes + // Pure_Phase element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; - s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl; - s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; - s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl; - s_oss << indent0 << "force_equality=\"" << this->force_equality << "\"" << std::endl; - s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "add_formula=\"" << this-> + add_formula << "\"" << std::endl; + s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + s_oss << indent0 << "initial_moles=\"" << this-> + initial_moles << "\"" << std::endl; + s_oss << indent0 << "force_equality=\"" << this-> + force_equality << "\"" << std::endl; + s_oss << indent0 << "dissolve_only=\"" << this-> + dissolve_only << "\"" << std::endl; } -void cxxPPassemblageComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Pure_Phase element and attributes + // Pure_Phase element and attributes - if (this->name != NULL) s_oss << indent0 << "-name " << this->name << std::endl; - if (this->add_formula != NULL) s_oss << indent0 << "-add_formula " << this->add_formula << std::endl; - s_oss << indent0 << "-si " << this->si << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-delta " << this->delta << std::endl; - s_oss << indent0 << "-initial_moles " << this->initial_moles << std::endl; - s_oss << indent0 << "-force_equality " << this->force_equality << std::endl; - s_oss << indent0 << "-dissolve_only " << this->dissolve_only << std::endl; + if (this->name != NULL) + s_oss << indent0 << "-name " << this-> + name << std::endl; + if (this->add_formula != NULL) + s_oss << indent0 << "-add_formula " << this-> + add_formula << std::endl; + s_oss << indent0 << "-si " << this->si << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-delta " << this->delta << std::endl; + s_oss << indent0 << "-initial_moles " << this-> + initial_moles << std::endl; + s_oss << indent0 << "-force_equality " << this-> + force_equality << std::endl; + s_oss << indent0 << "-dissolve_only " << this-> + dissolve_only << std::endl; } -void cxxPPassemblageComp::read_raw(CParser& parser) +void +cxxPPassemblageComp::read_raw(CParser & parser) { - std::string str; - - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("name"); // 0 - vopts.push_back("add_formula"); // 1 - vopts.push_back("si"); // 2 - vopts.push_back("moles"); // 3 - vopts.push_back("delta"); // 4 - vopts.push_back("initial_moles"); // 5 - vopts.push_back("dissolve_only"); // 6 - vopts.push_back("force_equality"); // 7 - } + std::string str; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("add_formula"); // 1 + vopts.push_back("si"); // 2 + vopts.push_back("moles"); // 3 + vopts.push_back("delta"); // 4 + vopts.push_back("initial_moles"); // 5 + vopts.push_back("dissolve_only"); // 6 + vopts.push_back("force_equality"); // 7 + } - opt_save = CParser::OPT_ERROR; - bool name_defined(false); - bool si_defined(false); - bool moles_defined(false); - bool delta_defined(false); - bool initial_moles_defined(false); - bool dissolve_only_defined(false); - bool force_equality_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + bool si_defined(false); + bool moles_defined(false); + bool delta_defined(false); + bool initial_moles_defined(false); + bool dissolve_only_defined(false); + bool force_equality_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); - } else { - this->name = string_hsave(str.c_str()); - } - name_defined = true; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 1: // add_formula - if (!(parser.get_iss() >> str)) - { - this->add_formula = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for add_formula.", CParser::OT_CONTINUE); - } else { - this->add_formula = string_hsave(str.c_str()); - } - break; + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", + CParser::OT_CONTINUE); + } + else + { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + break; - case 2: // si - if (!(parser.get_iss() >> this->si)) - { - this->si = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for si.", CParser::OT_CONTINUE); - } - si_defined = true; - break; + case 1: // add_formula + if (!(parser.get_iss() >> str)) + { + this->add_formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for add_formula.", + CParser::OT_CONTINUE); + } + else + { + this->add_formula = string_hsave(str.c_str()); + } + break; - case 3: // moles - if (!(parser.get_iss() >> this->moles)) - { - this->moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); - } - moles_defined = true; - break; + case 2: // si + if (!(parser.get_iss() >> this->si)) + { + this->si = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for si.", + CParser::OT_CONTINUE); + } + si_defined = true; + break; - case 4: // delta - if (!(parser.get_iss() >> this->delta)) - { - this->delta = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for delta.", CParser::OT_CONTINUE); - } - delta_defined = true; - break; + case 3: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + CParser::OT_CONTINUE); + } + moles_defined = true; + break; - case 5: // initial_moles - if (!(parser.get_iss() >> this->initial_moles)) - { - this->initial_moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for initial_moles.", CParser::OT_CONTINUE); - } - initial_moles_defined = true; - break; + case 4: // delta + if (!(parser.get_iss() >> this->delta)) + { + this->delta = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for delta.", + CParser::OT_CONTINUE); + } + delta_defined = true; + break; + + case 5: // initial_moles + if (!(parser.get_iss() >> this->initial_moles)) + { + this->initial_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial_moles.", + CParser::OT_CONTINUE); + } + initial_moles_defined = true; + break; - case 6: // dissolve_only - if (!(parser.get_iss() >> this->dissolve_only)) - { - this->dissolve_only = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for dissolve_only.", CParser::OT_CONTINUE); - } - dissolve_only_defined = true; - break; + case 6: // dissolve_only + if (!(parser.get_iss() >> this->dissolve_only)) + { + this->dissolve_only = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for dissolve_only.", + CParser::OT_CONTINUE); + } + dissolve_only_defined = true; + break; - case 7: // force_equality - if (!(parser.get_iss() >> this->force_equality)) - { - this->force_equality = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for force_equality.", CParser::OT_CONTINUE); - } - force_equality_defined = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (name_defined == false) { - parser.incr_input_error(); - parser.error_msg("Name not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (si_defined == false) { - parser.incr_input_error(); - parser.error_msg("Si not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (delta_defined == false) { - parser.incr_input_error(); - parser.error_msg("Delta not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (initial_moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Initial_moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (dissolve_only_defined == false) { - parser.incr_input_error(); - parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } - if (force_equality_defined == false) { - parser.incr_input_error(); - parser.error_msg("Force_equality not defined for PPassemblageComp input.", CParser::OT_CONTINUE); - } + case 7: // force_equality + if (!(parser.get_iss() >> this->force_equality)) + { + this->force_equality = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for force_equality.", + CParser::OT_CONTINUE); + } + force_equality_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (si_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Si not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (delta_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Delta not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (initial_moles_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Initial_moles not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (dissolve_only_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Dissolve_only not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (force_equality_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Force_equality not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } } #ifdef USE_MPI -void cxxPPassemblageComp::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; @@ -313,7 +375,9 @@ void cxxPPassemblageComp::mpi_pack(std::vector& ints, std::vector& ints.push_back((int) this->force_equality); ints.push_back((int) this->dissolve_only); } -void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -330,82 +394,96 @@ void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *d *dd = d; } #endif - -void cxxPPassemblageComp::totalize() + +void +cxxPPassemblageComp::totalize() { - this->totals.clear(); - // component structures - if (this->add_formula != NULL) return; - struct phase *phase_ptr; - int l; - phase_ptr = phase_bsearch(this->name, &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, this->moles); - } else - { - assert(false); - } - return; + this->totals.clear(); + // component structures + if (this->add_formula != NULL) + return; + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(this->name, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, this->moles); + } + else + { + assert(false); + } + return; } -void cxxPPassemblageComp::add(const cxxPPassemblageComp &addee, double extensive) +void +cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) { - double ext1, ext2, f1, f2; - if (extensive == 0.0) return; - if (addee.name == NULL) return; - // this and addee must have same name - // otherwise generate a new PPassemblagComp with multiply + double ext1, ext2, f1, f2; + if (extensive == 0.0) + return; + if (addee.name == NULL) + return; + // this and addee must have same name + // otherwise generate a new PPassemblagComp with multiply - ext1 = this->moles; - ext2 = addee.moles * extensive; - if (ext1 + ext2 != 0) { - f1 = ext1/(ext1 + ext2); - f2 = ext2/(ext1 + ext2); - } else { - f1 = 0.5; - f2 = 0.5; - } - //char * name; - //char *add_formula; + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } + //char * name; + //char *add_formula; - if (this->name == NULL && addee.name == NULL) { - return; - } - assert (this->name == addee.name); - if (this->add_formula != addee.add_formula) { - std::ostringstream oss; - oss << "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } - //double si; - this->si = this->si * f1 + addee.si * f2; - //double moles; - this->moles += addee.moles * extensive; - //double delta; - this->delta += addee.delta * extensive; - //double initial_moles; - this->initial_moles += addee.initial_moles * extensive; - //bool force_equality; - //bool dissolve_only; + if (this->name == NULL && addee.name == NULL) + { + return; + } + assert(this->name == addee.name); + if (this->add_formula != addee.add_formula) + { + std::ostringstream oss; + oss << + "Can not mix two Equilibrium_phases with differing add_formulae., " + << this->name; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + //double si; + this->si = this->si * f1 + addee.si * f2; + //double moles; + this->moles += addee.moles * extensive; + //double delta; + this->delta += addee.delta * extensive; + //double initial_moles; + this->initial_moles += addee.initial_moles * extensive; + //bool force_equality; + //bool dissolve_only; } -void cxxPPassemblageComp::multiply(double extensive) +void +cxxPPassemblageComp::multiply(double extensive) { - //char * name; - //char *add_formula; - //double si; - //double moles; - this->moles *= extensive; - //double delta; - this->delta *= extensive; - //double initial_moles; - this->initial_moles *= extensive; - //bool force_equality; - //bool dissolve_only; + //char * name; + //char *add_formula; + //double si; + //double moles; + this->moles *= extensive; + //double delta; + this->delta *= extensive; + //double initial_moles; + this->initial_moles *= extensive; + //bool force_equality; + //bool dissolve_only; } diff --git a/Parser.cxx b/Parser.cxx index fb94842c..ed3cf4cd 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -2,49 +2,49 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "Parser.h" #include "Utils.h" #include "output.h" -#include // std::transform -#include // std::map -#include // assert -#include // std::cout std::cerr +#include // std::transform +#include // std::map +#include // assert +#include // std::cout std::cerr #include "char_star.h" -extern char *string_hsave (const char *str); +extern char *string_hsave(const char *str); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CParser::CParser(std::istream& input) -: m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr) -, m_input_error(0), m_next_keyword(KT_NONE) +CParser::CParser(std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), +m_input_error(0), +m_next_keyword(KT_NONE) { - m_line_save.reserve(80); - m_line.reserve(80); + m_line_save.reserve(80); + m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; } -CParser::CParser(std::istream& input, std::ostream& output) -: m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr) -, m_input_error(0), m_next_keyword(KT_NONE) +CParser::CParser(std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), +m_input_error(0), +m_next_keyword(KT_NONE) { - m_line_save.reserve(80); - m_line.reserve(80); + m_line_save.reserve(80); + m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; } -CParser::CParser(std::istream& input, std::ostream& output, std::ostream& error) -: m_input_stream(input), m_output_stream(output), m_error_stream(error) -, m_input_error(0), m_next_keyword(KT_NONE) +CParser::CParser(std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), +m_input_error(0), +m_next_keyword(KT_NONE) { - m_line_save.reserve(80); - m_line.reserve(80); + m_line_save.reserve(80); + m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; } @@ -53,173 +53,181 @@ CParser::~CParser() { } -CParser::LINE_TYPE CParser::check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print) +CParser::LINE_TYPE CParser::check_line(const std::string & str, + bool allow_empty, bool allow_eof, + bool allow_keyword, bool print) { - LINE_TYPE i; + LINE_TYPE + i; - // Get line - do { - i = get_line(); - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); + // Get line + do + { + i = get_line(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); // output for stream - switch (this->echo_stream) + switch (this->echo_stream) { case EO_NONE: - break; + break; case EO_ALL: - if (i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; case EO_KEYWORDS: - if (i == LT_KEYWORD) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; } // output for file - switch (this->echo_file) + switch (this->echo_file) { case EO_NONE: - break; + break; case EO_ALL: - if (i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; case EO_KEYWORDS: - if (i == LT_KEYWORD) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; } - } while (i == LT_EMPTY && allow_empty == false); + } + while (i == LT_EMPTY && allow_empty == false); - // Check eof - if (i == LT_EOF && allow_eof == false) - { - std::ostringstream msg; - msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; - error_msg(msg, OT_STOP); - } + // Check eof + if (i == LT_EOF && allow_eof == false) + { + std::ostringstream msg; + msg << "Unexpected eof while reading " << str << + "\nExecution terminated.\n"; + error_msg(msg, OT_STOP); + } - // Check keyword - if (i == LT_KEYWORD && allow_keyword == false) - { - std::ostringstream msg; - msg << "Expected data for " << str << ", but got a keyword ending data block."; - error_msg(msg, OT_CONTINUE); - incr_input_error(); - } - m_line_type = i; - return i; + // Check keyword + if (i == LT_KEYWORD && allow_keyword == false) + { + std::ostringstream msg; + msg << "Expected data for " << str << + ", but got a keyword ending data block."; + error_msg(msg, OT_CONTINUE); + incr_input_error(); + } + m_line_type = i; + return i; } CParser::LINE_TYPE CParser::get_line() { - CParser::LINE_TYPE return_value = LT_EMPTY; - while (return_value == LT_EMPTY) - { - // - // Eliminate all characters after # sign as a comment - // + CParser::LINE_TYPE return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + // + // Eliminate all characters after # sign as a comment + // - // - // Get line, check for eof - // - if (get_logical_line() == LT_EOF) - { - if (!m_input_stream.eof()) - { - error_msg("Reading input file.", OT_CONTINUE); - error_msg("istream::get() returned an error.", OT_STOP); - } - else - { - //{{MOD - m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); - //}}MOD - m_next_keyword = KT_EOF; - return LT_EOF; - } - } + // + // Get line, check for eof + // + if (get_logical_line() == LT_EOF) + { + if (!m_input_stream.eof()) + { + error_msg("Reading input file.", OT_CONTINUE); + error_msg("istream::get() returned an error.", OT_STOP); + } + else + { + //{{MOD + m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + //}}MOD + m_next_keyword = KT_EOF; + return LT_EOF; + } + } - // - // Get long lines - // - bool empty = true; - m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); - for (unsigned int i = 0; i < m_line.size(); ++i) - { - if (!::isspace(m_line[i])) - { - empty = false; - break; - } - } + // + // Get long lines + // + bool + empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } - // - // New line character encountered - // - return_value = (empty ? LT_EMPTY : LT_OK); - } + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + } - // - // Determine return_value - // - if (return_value == LT_OK) - { - if (check_key(m_line.begin(), m_line.end())) - { - return_value = LT_KEYWORD; - } - else - { - std::string::iterator beg = m_line.begin(); - std::string::iterator end = m_line.end(); - std::string token; - copy_token(token, beg, end); + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + copy_token(token, beg, end); - if (token.size() > 1 && token[0] == '-' && ::isalpha(token[1])) - { - return_value = LT_OPTION; - } - } - } - return return_value; + if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + return return_value; } /** @@ -232,89 +240,131 @@ CParser::LINE_TYPE CParser::get_line() */ CParser::LINE_TYPE CParser::get_logical_line() { - int j; - unsigned int pos; - char c; + int + j; + unsigned int + pos; + char + c; - m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); - while ((j = m_input_stream.get()) != std::char_traits::eof()) { - c = (char) j; - if (c == '#') { - // ignore all chars after # until newline - do { - c = (char) j; - if (c == '\n') { - break; - } - m_line_save += c; - } while ((j = m_input_stream.get()) != std::char_traits::eof()); - } - if (c == ';') break; - if (c == '\n') { - break; - } - if (c == '\\') { - pos = (int) m_line_save.size(); - m_line_save += c; - while ((j = m_input_stream.get()) != std::char_traits::eof()) { - c = (char) j; - if (c == '\\') { - pos = (int) m_line_save.size(); - m_line_save += c; - continue; - } - if (c == '\n') { - // remove '\\' - for (; pos < m_line_save.size(); pos++) { - m_line_save[pos] = m_line_save[pos+1]; - } - m_line_save.erase(m_line_save.size() - 1, 1); - break; - } - m_line_save += c; - if (!::isspace(j)) break; - } - } else { - m_line_save += c; - } - } - if (j == std::char_traits::eof() && m_line_save.size() == 0) { - return(LT_EOF); - } - return(LT_OK); + while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '#') + { + // ignore all chars after # until newline + do + { + c = (char) j; + if (c == '\n') + { + break; + } + m_line_save += c; + } + while ((j = + m_input_stream.get()) != std::char_traits < + char >::eof()); + } + if (c == ';') + break; + if (c == '\n') + { + break; + } + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + while ((j = + m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') + { + // remove '\\' + for (; pos < m_line_save.size(); pos++) + { + m_line_save[pos] = m_line_save[pos + 1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) + break; + } + } + else + { + m_line_save += c; + } + } + if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) + { + return (LT_EOF); + } + return (LT_OK); } //bool CParser::check_key(const std::string::iterator ptr) -bool CParser::check_key(std::string::iterator begin, std::string::iterator end) +bool +CParser::check_key(std::string::iterator begin, std::string::iterator end) { - static std::map s_keyword_map; - if (s_keyword_map.size() == 0) - { - s_keyword_map.insert(std::map::value_type("solution_raw", KT_SOLUTION_RAW)); - s_keyword_map.insert(std::map::value_type("exchange_raw", KT_EXCHANGE_RAW)); - s_keyword_map.insert(std::map::value_type("gas_phase_raw", KT_GASPHASE_RAW)); - s_keyword_map.insert(std::map::value_type("kinetics_raw", KT_KINETICS_RAW)); - s_keyword_map.insert(std::map::value_type("equilibrium_phases_raw", KT_PPASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map::value_type("solid_solutions_raw", KT_SSASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map::value_type("surface_raw", KT_SURFACE_RAW)); - } + static std::map < std::string, KEY_TYPE > s_keyword_map; + if (s_keyword_map.size() == 0) + { + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("solution_raw", + KT_SOLUTION_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("exchange_raw", + KT_EXCHANGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("gas_phase_raw", + KT_GASPHASE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("kinetics_raw", + KT_KINETICS_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("equilibrium_phases_raw", + KT_PPASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("solid_solutions_raw", + KT_SSASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("surface_raw", + KT_SURFACE_RAW)); + } - std::string lowercase; - copy_token(lowercase, begin, end); - std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); + std::string lowercase; + copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), + tolower); - m_next_keyword = KT_NONE; - std::map::iterator map_iter = s_keyword_map.find(lowercase); - if (map_iter == s_keyword_map.end()) - return false; - m_next_keyword = (*map_iter).second; - return true; + m_next_keyword = KT_NONE; + std::map < std::string, KEY_TYPE >::iterator map_iter = + s_keyword_map.find(lowercase); + if (map_iter == s_keyword_map.end()) + return false; + m_next_keyword = (*map_iter).second; + return true; } -CParser::STATUS_TYPE CParser::check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, - const std::string& default_units, bool print) +CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, + bool alkalinity, + bool check_compatibility, + const std::string & default_units, + bool print) { /* * Check if legitimate units @@ -327,369 +377,418 @@ CParser::STATUS_TYPE CParser::check_units(std::string& tot_units, bool alkalinit * Output: * tot_units standard form for unit */ - using Utilities::str_tolower; - using Utilities::replace; - using Utilities::squeeze_white; + using + Utilities::str_tolower; + using + Utilities::replace; + using + Utilities::squeeze_white; - static const char *units[] = { - "Mol/l", /* 0 */ - "mMol/l", /* 1 */ - "uMol/l", /* 2 */ - "g/l", /* 3 */ - "mg/l", /* 4 */ - "ug/l", /* 5 */ - "Mol/kgs", /* 6 */ - "mMol/kgs", /* 7 */ - "uMol/kgs", /* 8 */ - "g/kgs", /* 9 = ppt */ - "mg/kgs", /* 10 = ppm */ - "ug/kgs", /* 11 = ppb */ - "Mol/kgw", /* 12 = mol/kg H2O */ - "mMol/kgw", /* 13 = mmol/kg H2O */ - "uMol/kgw", /* 14 = umol/kg H2O */ - "g/kgw", /* 15 = mol/kg H2O */ - "mg/kgw", /* 16 = mmol/kg H2O */ - "ug/kgw", /* 17 = umol/kg H2O */ - "eq/l", /* 18 */ - "meq/l", /* 19 */ - "ueq/l", /* 20 */ - "eq/kgs", /* 21 */ - "meq/kgs", /* 22 */ - "ueq/kgs", /* 23 */ - "eq/kgw", /* 24 */ - "meq/kgw", /* 25 */ - "ueq/kgw", /* 26 */ - }; + static const char * + units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; - squeeze_white(tot_units); - str_tolower(tot_units); - replace("milli", "m", tot_units); - replace("micro", "u", tot_units); - replace("grams", "g", tot_units); - replace("gram", "g", tot_units); - replace("moles", "Mol", tot_units); - replace("mole", "Mol", tot_units); - replace("mol", "Mol", tot_units); - replace("liter", "l", tot_units); - replace("kgh", "kgw", tot_units); - replace("ppt", "g/kgs", tot_units); - replace("ppm", "mg/kgs", tot_units); - replace("ppb", "ug/kgs", tot_units); - replace("equivalents", "eq", tot_units); - replace("equivalent", "eq", tot_units); - replace("equiv", "eq", tot_units); + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); - std::string::size_type end; - if ((end = tot_units.find("/l")) != std::string::npos) { - tot_units.resize(end + 2); - } - if ((end = tot_units.find("/kgs")) != std::string::npos) { - tot_units.resize(end + 4); - } - if ((end = tot_units.find("/kgw")) != std::string::npos) { - tot_units.resize(end + 4); - } + std::string::size_type end; + if ((end = tot_units.find("/l")) != std::string::npos) + { + tot_units.resize(end + 2); + } + if ((end = tot_units.find("/kgs")) != std::string::npos) + { + tot_units.resize(end + 4); + } + if ((end = tot_units.find("/kgw")) != std::string::npos) + { + tot_units.resize(end + 4); + } - // - // Check if unit in list - // - bool found = false; - for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) { - if (tot_units.compare(units[i]) == 0) { - found = true; - break; - } - } - if (!found) { - if (print) { - std::ostringstream err; - err << "Unknown unit, " << tot_units; - error_msg(err, OT_CONTINUE); - } - return PARSER_ERROR; - } + // + // Check if unit in list + // + bool + found = false; + for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) + { + if (tot_units.compare(units[i]) == 0) + { + found = true; + break; + } + } + if (!found) + { + if (print) + { + std::ostringstream err; + err << "Unknown unit, " << tot_units; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; + } - // - // Check if units are compatible with default_units - // - if (check_compatibility == false) return PARSER_OK; + // + // Check if units are compatible with default_units + // + if (check_compatibility == false) + return PARSER_OK; - // - // Special cases for alkalinity - // - if (alkalinity == true && tot_units.find("Mol") != std::string::npos) { - if (print) { - warning_msg("Alkalinity given in moles, assumed to be equivalents."); - } - replace("Mol", "eq", tot_units); - } - if (alkalinity == false && tot_units.find("eq") != std::string::npos) { - if (print) { - error_msg("Only alkalinity can be entered in equivalents.", OT_CONTINUE); - } - return PARSER_ERROR; - } + // + // Special cases for alkalinity + // + if (alkalinity == true && tot_units.find("Mol") != std::string::npos) + { + if (print) + { + warning_msg + ("Alkalinity given in moles, assumed to be equivalents."); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == false && tot_units.find("eq") != std::string::npos) + { + if (print) + { + error_msg("Only alkalinity can be entered in equivalents.", + OT_CONTINUE); + } + return PARSER_ERROR; + } - // - // See if default_units are compatible with tot_units - // - if (default_units.find("/l") != std::string::npos && tot_units.find("/l") != std::string::npos) return PARSER_OK; - if (default_units.find("/kgs") != std::string::npos && tot_units.find("/kgs") != std::string::npos) return PARSER_OK; - if (default_units.find("/kgw") != std::string::npos && tot_units.find("/kgw") != std::string::npos) return PARSER_OK; + // + // See if default_units are compatible with tot_units + // + if (default_units.find("/l") != std::string::npos + && tot_units.find("/l") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgs") != std::string::npos + && tot_units.find("/kgs") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgw") != std::string::npos + && tot_units.find("/kgw") != std::string::npos) + return PARSER_OK; - std::string str = default_units; - replace("kgs", "kg solution", str); - replace("kgs", "kg solution", tot_units); - replace("kgw", "kg water", str); - replace("kgw", "kg water", tot_units); - replace("/l", "/L", str); - replace("Mol", "mol", str); - replace("/l", "/L", tot_units); - replace("Mol", "mol", tot_units); + std::string str = default_units; + replace("kgs", "kg solution", str); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", str); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", str); + replace("Mol", "mol", str); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); - if (print) { - std::ostringstream err; - err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; - error_msg(err, OT_CONTINUE); - } - return PARSER_ERROR; + if (print) + { + std::ostringstream err; + err << "Units for master species, " << tot_units << + ", are not compatible with default units, " << str << "."; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; } -CParser::TOKEN_TYPE CParser::token_type(const std::string& token) +CParser::TOKEN_TYPE CParser::token_type(const std::string & token) { - if (!token.empty()) { - if (::isupper(token[0])) { - return CParser::TT_UPPER; - } else if (::islower(token[0])) { - return CParser::TT_LOWER; - } else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') { - return CParser::TT_DIGIT; - } else { - assert(!::isspace(token[0])); - return CParser::TT_UNKNOWN; - } - } - else { - return CParser::TT_EMPTY; - } + if (!token.empty()) + { + if (::isupper(token[0])) + { + return CParser::TT_UPPER; + } + else if (::islower(token[0])) + { + return CParser::TT_LOWER; + } + else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') + { + return CParser::TT_DIGIT; + } + else + { + assert(!::isspace(token[0])); + return CParser::TT_UNKNOWN; + } + } + else + { + return CParser::TT_EMPTY; + } } CParser::TOKEN_TYPE CParser::peek_token() { - std::istringstream::pos_type pos = m_line_iss.tellg(); - std::string token; - m_line_iss >> token; - m_line_iss.seekg(pos); - return token_type(token); + std::istringstream::pos_type pos = m_line_iss.tellg(); + std::string token; + m_line_iss >> token; + m_line_iss.seekg(pos); + return token_type(token); } -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end) +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) { - if (begin != end) - { - std::string::iterator b = begin; - for (; b < end && ::isspace(*b); ++b); + if (begin != end) + { + std::string::iterator b = begin; + for (; b < end &&::isspace(*b); ++b); - begin = b; - for (; begin < end && !::isspace(*begin); ++begin); + begin = b; + for (; begin < end && !::isspace(*begin); ++begin); - token.assign(b, begin); - } - else - { - token.resize(0); - } + token.assign(b, begin); + } + else + { + token.resize(0); + } - return token_type(token); + return token_type(token); } -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream& is) +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::istream & is) { - is >> token; - return token_type(token); + is >> token; + return token_type(token); } -CParser::TOKEN_TYPE CParser::copy_token(std::string& token, std::istream::pos_type& pos) +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::istream::pos_type & pos) { - m_line_iss.seekg(pos); - // m_line_iss >> token; - if( !(m_line_iss >> token)) { - token.erase(token.begin(), token.end()); // token.clear(); - } - pos = m_line_iss.tellg(); - return token_type(token); + m_line_iss.seekg(pos); + // m_line_iss >> token; + if (!(m_line_iss >> token)) + { + token.erase(token.begin(), token.end()); // token.clear(); + } + pos = m_line_iss.tellg(); + return token_type(token); } -CParser::FIND_TYPE CParser::find_option(const std::string& item, int *n, const std::vector& list, bool exact) +CParser::FIND_TYPE CParser::find_option(const std::string & item, int *n, + const std::vector < std::string > + &list, bool exact) { - std::string token(item); - std::transform(token.begin(), token.end(), token.begin(), tolower); - for (unsigned int i = 0; i < list.size(); i++) - { - if (exact == true) - { - if (list[i].compare(token) == 0) - { - *n = i; - return FT_OK; - } - } - else - { - if(list[i].find(token) == 0) - { - *n = i; - return FT_OK; - } - } - } + std::string token(item); + std::transform(token.begin(), token.end(), token.begin(), tolower); + for (unsigned int i = 0; i < list.size(); i++) + { + if (exact == true) + { + if (list[i].compare(token) == 0) + { + *n = i; + return FT_OK; + } + } + else + { + if (list[i].find(token) == 0) + { + *n = i; + return FT_OK; + } + } + } - *n = -1; - return FT_ERROR; + *n = -1; + return FT_ERROR; } // OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) // OPTION_TYPE CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) -int CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +int +CParser::get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char) { - // - // Read a line and check for options - // - int j; - int /* opt_l, */ opt; - //char *opt_ptr; - std::string::iterator opt_ptr; + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; - // char option[MAX_LENGTH]; - std::string option; + // char option[MAX_LENGTH]; + std::string option; fprintf(stderr, "Did not think this get_option was called\n"); - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) - { - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - next_char = opt_ptr; - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; - j = OPT_ERROR; - next_char = m_line.begin(); - } - } - else - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_char = opt_ptr; - } - else - { - j = OPT_DEFAULT; - next_char = m_line.begin(); - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - std::cout << "\t" << m_line_save << "\n"; - } - } - } - return (j); + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); } -int CParser::get_option(const std::vector& opt_list, std::istream::pos_type& next_pos) +int +CParser::get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos) { - // - // Read a line and check for options - // - int j; - int opt; - std::istream::pos_type pos_ptr; - std::string option; + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - std::string::iterator opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) - { - // replace -option with option - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); - pos_ptr = 0; - copy_token(option, pos_ptr); - next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} /* if (true) // pr.echo_input == TRUE { @@ -699,36 +798,36 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: } } */ - } - else - { + } + else + { /* if (true) // (database_file == NULL) { get_output() << "\t" << m_line_save << "\n"; } */ - //error_msg("Unknown option.", OT_CONTINUE); - //error_msg(m_line_save.c_str(), OT_CONTINUE); - //incr_input_error(); - j = OPT_ERROR; - next_pos = pos_ptr; - } - } - else - { - pos_ptr = 0; - copy_token(option, pos_ptr); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_pos = pos_ptr; - } - else - { - j = OPT_DEFAULT; - next_pos = 0; - } + //error_msg("Unknown option.", OT_CONTINUE); + //error_msg(m_line_save.c_str(), OT_CONTINUE); + //incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } /* if (true) // pr.echo_input == TRUE { @@ -739,404 +838,463 @@ int CParser::get_option(const std::vector& opt_list, std::istream:: } } */ - } - return (j); + } + return (j); } -int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) +int +CParser::error_msg(const char *err_str, ONERROR_TYPE ot) { - ::error_msg(err_str, (int)ot); - m_error_stream << "ERROR: " << err_str << "\n"; - m_error_stream.flush(); + ::error_msg(err_str, (int) ot); + m_error_stream << "ERROR: " << err_str << "\n"; + m_error_stream.flush(); - m_output_stream << "ERROR: " << err_str << "\n"; - m_output_stream.flush(); + m_output_stream << "ERROR: " << err_str << "\n"; + m_output_stream.flush(); - if (ot == OT_STOP) - { - exit(1); - } - return 0; + if (ot == OT_STOP) + { + exit(1); + } + return 0; } -int CParser::warning_msg(const char *err_str) +int +CParser::warning_msg(const char *err_str) { - m_error_stream << "WARNING: " << err_str << "\n"; - m_error_stream.flush(); + m_error_stream << "WARNING: " << err_str << "\n"; + m_error_stream.flush(); - m_output_stream << "WARNING: " << err_str << "\n"; - m_output_stream.flush(); + m_output_stream << "WARNING: " << err_str << "\n"; + m_output_stream.flush(); - return 0; + return 0; } -CParser::STATUS_TYPE CParser::get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element) +CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element) { - element.erase(element.begin(), element.end()); // element.clear(); + element.erase(element.begin(), element.end()); // element.clear(); - if (begin == end) { - error_msg("Empty string in get_elt. Expected an element name.", OT_CONTINUE); - return PARSER_ERROR; - } + if (begin == end) + { + error_msg("Empty string in get_elt. Expected an element name.", + OT_CONTINUE); + return PARSER_ERROR; + } - // - // Load name into char array element - // - char c = *begin; - ++begin; - element.insert(element.end(), c); // element.push_back(c); - if (c == '[') { - while ( (c = *begin) != ']' ) { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if ( (c = *begin) == ']' ) { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - break; - } else if (begin == end) { - error_msg("No ending bracket (]) for element name", OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } - } - while (::islower(c = *begin) || c == '_') { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) break; - } - } else { - while (::islower(c = *begin) || c == '_') { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) break; - } - } - return PARSER_OK; + // + // Load name into char array element + // + char + c = *begin; + ++begin; + element.insert(element.end(), c); // element.push_back(c); + if (c == '[') + { + while ((c = *begin) != ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if ((c = *begin) == ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + break; + } + else if (begin == end) + { + error_msg("No ending bracket (]) for element name", + OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + } + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + else + { + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + return PARSER_OK; } -CParser::STATUS_TYPE CParser::parse_couple(std::string& token) +CParser::STATUS_TYPE CParser::parse_couple(std::string & token) { - // Parse couple puts redox couples in standard form - // "+" is removed and couples are rewritten in sort - // order. + // Parse couple puts redox couples in standard form + // "+" is removed and couples are rewritten in sort + // order. - if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) { - Utilities::str_tolower(token); - return PARSER_OK; - } + if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) + { + Utilities::str_tolower(token); + return PARSER_OK; + } - while ( Utilities::replace("+", "", token) ); + while (Utilities::replace("+", "", token)); - std::string::iterator ptr = token.begin(); - std::string elt1; - get_elt(ptr, token.end(), elt1); + std::string::iterator ptr = token.begin(); + std::string elt1; + get_elt(ptr, token.end(), elt1); - if (*ptr != '(') { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " << - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " << + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } - int paren_count = 1; - std::string paren1 = "("; - while ( ptr != token.end() ) { - ++ptr; - if (*ptr == '/' || ptr == token.end()) { - std::ostringstream err_msg; - err_msg << "End of line or ""/"" encountered before end of parentheses, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - paren1.insert(paren1.end(), *ptr); // element.push_back(c); - if (*ptr == '(') ++paren_count; - if (*ptr == ')') --paren_count; - if (paren_count == 0) break; - } + int + paren_count = 1; + std::string paren1 = "("; + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren1.insert(paren1.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } - ++ptr; - if (ptr == token.end() || *ptr != '/') { - std::ostringstream err_msg; - err_msg << " ""/"" must follow parentheses " << - "ending first half of redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - ++ptr; - std::string elt2; - get_elt(ptr, token.end(), elt2); - if (elt1.compare(elt2) != 0) { - std::ostringstream err_msg; - err_msg << "Redox couple must be two redox states " << - "of the same element, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - if (*ptr != '(') { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } - std::string paren2 = "("; - paren_count = 1; + ++ptr; + if (ptr == token.end() || *ptr != '/') + { + std::ostringstream err_msg; + err_msg << " " "/" " must follow parentheses " << + "ending first half of redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + ++ptr; + std::string elt2; + get_elt(ptr, token.end(), elt2); + if (elt1.compare(elt2) != 0) + { + std::ostringstream err_msg; + err_msg << "Redox couple must be two redox states " << + "of the same element, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + std::string paren2 = "("; + paren_count = 1; - while ( ptr != token.end() ) { - ++ptr; - if (*ptr == '/' || ptr == token.end()) { - std::ostringstream err_msg; - err_msg << "End of line or ""/"" encountered before end of parentheses, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - paren2.insert(paren2.end(), *ptr); // element.push_back(c); - if (*ptr == '(') ++paren_count; - if (*ptr == ')') --paren_count; - if (paren_count == 0) break; - } - if (paren1.compare(paren2) < 0) { - token = elt1 + paren1 + std::string("/") + elt2 + paren2; - } else if (paren1.compare(paren2) > 0) { - token = elt2 + paren2 + std::string("/") + elt1 + paren1; - } else { - std::ostringstream err_msg; - err_msg << "Both parts of redox couple are the same, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - return PARSER_OK; + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren2.insert(paren2.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } + if (paren1.compare(paren2) < 0) + { + token = elt1 + paren1 + std::string("/") + elt2 + paren2; + } + else if (paren1.compare(paren2) > 0) + { + token = elt2 + paren2 + std::string("/") + elt1 + paren1; + } + else + { + std::ostringstream err_msg; + err_msg << "Both parts of redox couple are the same, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + return PARSER_OK; } -CParser::STATUS_TYPE CParser::addPair(std::map &totals, std::istream::pos_type& pos) +CParser::STATUS_TYPE CParser::addPair(std::map < char *, double, + CHARSTAR_LESS > &totals, + std::istream::pos_type & pos) { - std::string token; - char * ctoken; - double d; + std::string token; + char * + ctoken; + double + d; - CParser::TOKEN_TYPE j; + CParser::TOKEN_TYPE j; - m_line_iss.seekg(pos); + m_line_iss.seekg(pos); - j = copy_token(token, pos); + j = copy_token(token, pos); - if (j == TT_EMPTY) return PARSER_OK; + if (j == TT_EMPTY) + return PARSER_OK; - if( !(m_line_iss >> d)) { - return PARSER_ERROR; - } - ctoken = string_hsave(token.c_str()); - totals[ctoken] = d; - return PARSER_OK; + if (!(m_line_iss >> d)) + { + return PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + totals[ctoken] = d; + return PARSER_OK; } -CParser::STATUS_TYPE CParser::addPair(std::map &totals, std::istream::pos_type& pos) +CParser::STATUS_TYPE CParser::addPair(std::map < char *, double >&totals, + std::istream::pos_type & pos) { - std::string token; - char * ctoken; - double d; - CParser::TOKEN_TYPE j; + std::string token; + char * + ctoken; + double + d; + CParser::TOKEN_TYPE j; - m_line_iss.seekg(pos); + m_line_iss.seekg(pos); - j = copy_token(token, pos); + j = copy_token(token, pos); - if (j == TT_EMPTY) return PARSER_OK; + if (j == TT_EMPTY) + return PARSER_OK; - if( !(m_line_iss >> d)) { - return PARSER_ERROR; - } - ctoken = string_hsave(token.c_str()); - totals[ctoken] = d; - return PARSER_OK; + if (!(m_line_iss >> d)) + { + return PARSER_ERROR; + } + ctoken = string_hsave(token.c_str()); + totals[ctoken] = d; + return PARSER_OK; } -int CParser::getOptionFromLastLine(const std::vector& opt_list, std::string::iterator& next_char) + +int +CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char) { - // - // Read a line and check for options - // - int j; - int /* opt_l, */ opt; - //char *opt_ptr; - std::string::iterator opt_ptr; + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; - // char option[MAX_LENGTH]; - std::string option; + // char option[MAX_LENGTH]; + std::string option; - // - // Read line - // - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) - { - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - next_char = opt_ptr; - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); + // + // Read line + // + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; - j = OPT_ERROR; - next_char = m_line.begin(); - } - } - else - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_char = opt_ptr; - } - else - { - j = OPT_DEFAULT; - next_char = m_line.begin(); - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - std::cout << "\t" << m_line_save << "\n"; - } - } - } - return (j); + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); } -int CParser::getOptionFromLastLine(const std::vector& opt_list, std::istream::pos_type& next_pos) + +int +CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos) { - // - // Read a line and check for options - // - int j; - int opt; - std::istream::pos_type pos_ptr; - std::string option; + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; - // - // Read line - // - //LINE_TYPE lt = check_line("get_option", false, true, true, false); - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - std::string::iterator opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) - { - // replace -option with option - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + // + // Read line + // + //LINE_TYPE lt = check_line("get_option", false, true, true, false); + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); - pos_ptr = 0; - copy_token(option, pos_ptr); - next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - error_msg("Unknown option.", OT_CONTINUE); - error_msg(m_line_save.c_str(), OT_CONTINUE); - incr_input_error(); - j = OPT_ERROR; - next_pos = pos_ptr; - } - } - else - { - pos_ptr = 0; - copy_token(option, pos_ptr); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_pos = pos_ptr; - } - else - { - j = OPT_DEFAULT; - next_pos = 0; - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - return (j); + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + error_msg("Unknown option.", OT_CONTINUE); + error_msg(m_line_save.c_str(), OT_CONTINUE); + incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + return (j); } diff --git a/Reaction.cxx b/Reaction.cxx index 7b2e3c2a..044a0245 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -2,63 +2,68 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "Reaction.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxReaction::cxxReaction() - // - // default constructor for cxxReaction - // -: cxxNumKeyword() + // + // default constructor for cxxReaction + // +: cxxNumKeyword() { - units = string_hsave("Mol"); - countSteps = 0; - equalIncrements = false; - reactantList.type = cxxNameDouble::ND_NAME_COEF; - elementList.type = cxxNameDouble::ND_ELT_MOLES; + units = string_hsave("Mol"); + countSteps = 0; + equalIncrements = false; + reactantList.type = cxxNameDouble::ND_NAME_COEF; + elementList.type = cxxNameDouble::ND_ELT_MOLES; } cxxReaction::cxxReaction(struct irrev *irrev_ptr) - // - // constructor for cxxReaction from struct irrev - // -: + // + // constructor for cxxReaction from struct irrev + // + : cxxNumKeyword(), reactantList(irrev_ptr->list, irrev_ptr->count_list), elementList(irrev_ptr->elts) { - int i; + int i; - this->set_description(irrev_ptr->description); - this->n_user = irrev_ptr->n_user; - this->n_user_end = irrev_ptr->n_user_end; - this->units = irrev_ptr->units; + this->set_description(irrev_ptr->description); + this->n_user = irrev_ptr->n_user; + this->n_user_end = irrev_ptr->n_user_end; + this->units = irrev_ptr->units; // steps - if (irrev_ptr->count_steps < 0) { - for (i = 0; i < 1; i++) { + if (irrev_ptr->count_steps < 0) + { + for (i = 0; i < 1; i++) + { this->steps.push_back(irrev_ptr->steps[i]); } - this->countSteps = -irrev_ptr->count_steps; - this->equalIncrements = true; - } else { - for (i = 0; i < irrev_ptr->count_steps; i++) { + this->countSteps = -irrev_ptr->count_steps; + this->equalIncrements = true; + } + else + { + for (i = 0; i < irrev_ptr->count_steps; i++) + { this->steps.push_back(irrev_ptr->steps[i]); } - this->countSteps = irrev_ptr->count_steps; - this->equalIncrements = false; + this->countSteps = irrev_ptr->count_steps; + this->equalIncrements = false; } } @@ -67,257 +72,314 @@ cxxReaction::~cxxReaction() } -struct irrev *cxxReaction::cxxReaction2irrev() - // - // Builds a irrev structure from instance of cxxReaction - // +struct irrev * +cxxReaction::cxxReaction2irrev() + // + // Builds a irrev structure from instance of cxxReaction + // { - struct irrev *irrev_ptr; - irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof (struct irrev)); - if (irrev_ptr == NULL) malloc_error(); + struct irrev *irrev_ptr; + irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof(struct irrev)); + if (irrev_ptr == NULL) + malloc_error(); - irrev_ptr->description = this->get_description(); - irrev_ptr->n_user = this->n_user; - irrev_ptr->n_user_end = this->n_user_end; + irrev_ptr->description = this->get_description(); + irrev_ptr->n_user = this->n_user; + irrev_ptr->n_user_end = this->n_user_end; - irrev_ptr->list = this->reactantList.name_coef(); - irrev_ptr->count_list = (int) this->reactantList.size(); - if (this->elementList.size() > 0) { - irrev_ptr->elts = this->elementList.elt_list(); - } else { + irrev_ptr->list = this->reactantList.name_coef(); + irrev_ptr->count_list = (int) this->reactantList.size(); + if (this->elementList.size() > 0) + { + irrev_ptr->elts = this->elementList.elt_list(); + } + else + { // NULL value causes reaction stoichiometry to be calculated - irrev_ptr->elts = NULL; + irrev_ptr->elts = NULL; } // steps irrev_ptr->steps = NULL; - if (this->steps.size() > 0) { - irrev_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); - if (irrev_ptr->steps == NULL) malloc_error(); - std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); - } - if (this->equalIncrements) { - irrev_ptr->count_steps = -this->countSteps; - } else { - irrev_ptr->count_steps = (int) this->steps.size(); + if (this->steps.size() > 0) + { + irrev_ptr->steps = + (double *) + PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + if (irrev_ptr->steps == NULL) + malloc_error(); + std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); } - irrev_ptr->units = this->units; - return(irrev_ptr); + if (this->equalIncrements) + { + irrev_ptr->count_steps = -this->countSteps; + } + else + { + irrev_ptr->count_steps = (int) this->steps.size(); + } + irrev_ptr->units = this->units; + return (irrev_ptr); } #ifdef SKIP -void cxxReaction::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Reaction element and attributes - s_oss << indent0; - s_oss << "pitzer_irrev_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_irrev_gammas=\"" << this-> + pitzer_irrev_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = irrevComps.begin(); it != irrevComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = + irrevComps.begin(); it != irrevComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxReaction::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Reaction element and attributes - s_oss << indent0; - s_oss << "REACTION_RAW " << this->n_user << " " << this->description << std::endl; + // Reaction element and attributes + s_oss << indent0; + s_oss << "REACTION_RAW " << this->n_user << " " << this-> + description << std::endl; - s_oss << indent1; - s_oss << "-units " << this->units << std::endl; + s_oss << indent1; + s_oss << "-units " << this->units << std::endl; - s_oss << indent1; - s_oss << "-reactant_list " << std::endl; + s_oss << indent1; + s_oss << "-reactant_list " << std::endl; this->reactantList.dump_raw(s_oss, indent + 2); - s_oss << indent1; - s_oss << "-element_list " << std::endl; + s_oss << indent1; + s_oss << "-element_list " << std::endl; this->elementList.dump_raw(s_oss, indent + 2); - s_oss << indent1; - s_oss << "-steps " << std::endl; - { - int i = 0; - s_oss << indent2; - for (std::vector::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { - if (i++ == 5) { - s_oss << std::endl; - s_oss << indent2; - i = 0; - } - s_oss << *it << " "; - } - s_oss << std::endl; - } + s_oss << indent1; + s_oss << "-steps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector < double >::const_iterator it = this->steps.begin(); + it != this->steps.end(); it++) + { + if (i++ == 5) + { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } - s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; - s_oss << indent1; - s_oss << "-count_steps " << this->countSteps << std::endl; + s_oss << indent1; + s_oss << "-count_steps " << this->countSteps << std::endl; } -void cxxReaction::read_raw(CParser& parser) +void +cxxReaction::read_raw(CParser & parser) { int j; - double d; + double d; CParser::TOKEN_TYPE k; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("units"); //0 - vopts.push_back("reactant_list"); //1 - vopts.push_back("element_list"); //2 - vopts.push_back("steps"); //3 - vopts.push_back("equal_increments"); //4 - vopts.push_back("count_steps"); //5 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("units"); //0 + vopts.push_back("reactant_list"); //1 + vopts.push_back("element_list"); //2 + vopts.push_back("steps"); //3 + vopts.push_back("equal_increments"); //4 + vopts.push_back("count_steps"); //5 + } - // Read irrev number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; - bool units_defined(false); - bool equalIncrements_defined(false); - bool countSteps_defined(false); + // Read irrev number and description + this->read_number_description(parser); - 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 IRREV_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; + bool units_defined(false); + bool equalIncrements_defined(false); + bool countSteps_defined(false); - case 0: // units + 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 IRREV_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // units j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) break; + if (j == CParser::TT_EMPTY) + break; this->units = string_hsave(token.c_str()); - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - units_defined = true; - break; + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + units_defined = true; + break; - case 1: // reactant_list - if ( this->reactantList.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected reactant formula and coefficient.", CParser::OT_CONTINUE); - } - opt_save = 1; - useLastLine = false; - break; + case 1: // reactant_list + if (this->reactantList.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser.error_msg("Expected reactant formula and coefficient.", + CParser::OT_CONTINUE); + } + opt_save = 1; + useLastLine = false; + break; - case 2: // element_list - if ( this->elementList.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element formula and coefficient.", CParser::OT_CONTINUE); - } - opt_save = 2; - useLastLine = false; - break; + case 2: // element_list + if (this->elementList.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser.error_msg("Expected element formula and coefficient.", + CParser::OT_CONTINUE); + } + opt_save = 2; + useLastLine = false; + break; - case 3: // steps - while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { + case 3: // steps + while ((k = + parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + { std::istringstream iss(token); - if (!(iss >> d)) { + if (!(iss >> d)) + { parser.incr_input_error(); - parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE); - } else { + parser.error_msg("Expected numeric value for steps.", + CParser::OT_CONTINUE); + } + else + { this->steps.push_back(d); } - } - opt_save = 3; - useLastLine = false; - break; + } + opt_save = 3; + useLastLine = false; + break; - case 4: // equal_increments - if (!(parser.get_iss() >> this->equalIncrements)) - { - this->equalIncrements = 0; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); - } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - equalIncrements_defined = true; - break; + case 4: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser. + error_msg("Expected boolean value for equalIncrements.", + CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; - case 5: // countSteps - if (!(parser.get_iss() >> this->countSteps)) - { - this->countSteps = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for countSteps.", CParser::OT_CONTINUE); - } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - countSteps_defined = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (units_defined == false) { - parser.incr_input_error(); - parser.error_msg("Units not defined for REACTION_RAW input.", CParser::OT_CONTINUE); - } - if (equalIncrements_defined == false) { - parser.incr_input_error(); - parser.error_msg("Equal_increments not defined for REACTION_RAW input.", CParser::OT_CONTINUE); - } - if (countSteps_defined == false) { - parser.incr_input_error(); - parser.error_msg("Count_steps not defined for REACTION_RAW input.", CParser::OT_CONTINUE); - } + case 5: // countSteps + if (!(parser.get_iss() >> this->countSteps)) + { + this->countSteps = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for countSteps.", + CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + countSteps_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (units_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Units not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Equal_increments not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } + if (countSteps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Count_steps not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } } diff --git a/ReadClass.cxx b/ReadClass.cxx index 82a81274..9bcb7930 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1,5 +1,5 @@ #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "Parser.h" #include "Solution.h" @@ -20,12 +20,13 @@ #include -extern int reading_database (void); -extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, - int print); +extern int reading_database(void); +extern int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); /* ---------------------------------------------------------------------- */ -int read_solution_raw (void) +int +read_solution_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -54,10 +55,12 @@ int read_solution_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("solution_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("solution_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -68,16 +71,17 @@ int read_solution_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -91,24 +95,31 @@ int read_solution_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) { + if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) + { solution_free(solution[n]); solution[n] = soln_ptr; - } else { - n=count_solution++; - if (count_solution >= max_solution) { - space ((void **) ((void *) &(solution)), count_solution, &max_solution, sizeof (struct solution *) ); + } + else + { + n = count_solution++; + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); } solution[n] = soln_ptr; - solution_sort (); + solution_sort(); } // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_exchange_raw (void) +int +read_exchange_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -137,10 +148,12 @@ int read_exchange_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("exchange_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("exchange_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -151,16 +164,17 @@ int read_exchange_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -173,26 +187,33 @@ int read_exchange_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) { + if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) + { exchange_free(&exchange[n]); exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); - } else { - n=count_exchange++; - if (count_exchange >= max_exchange) { - space ((void **) ((void *) &(exchange)), count_exchange, &max_exchange, sizeof (struct exchange *) ); + } + else + { + n = count_exchange++; + if (count_exchange >= max_exchange) + { + space((void **) ((void *) &(exchange)), count_exchange, + &max_exchange, sizeof(struct exchange *)); } exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); - exchange_sort (); + exchange_sort(); } exchange_free(exchange_ptr); free_check_null(exchange_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_surface_raw (void) +int +read_surface_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -221,10 +242,12 @@ int read_surface_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("surface_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("surface_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -235,16 +258,17 @@ int read_surface_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -257,26 +281,33 @@ int read_surface_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (surface_bsearch(surface_ptr->n_user, &n) != NULL) { + if (surface_bsearch(surface_ptr->n_user, &n) != NULL) + { surface_free(&surface[n]); surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); - } else { - n=count_surface++; - if (count_surface >= max_surface) { - space ((void **) ((void *) &(surface)), count_surface, &max_surface, sizeof (struct surface *) ); + } + else + { + n = count_surface++; + if (count_surface >= max_surface) + { + space((void **) ((void *) &(surface)), count_surface, + &max_surface, sizeof(struct surface *)); } surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); - surface_sort (); + surface_sort(); } surface_free(surface_ptr); free_check_null(surface_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_equilibrium_phases_raw (void) +int +read_equilibrium_phases_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -305,10 +336,13 @@ int read_equilibrium_phases_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("equilibrium_phases_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = + check_line("equilibrium_phases_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -319,48 +353,59 @@ int read_equilibrium_phases_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); cxxPPassemblage ex; ex.read_raw(parser); - struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(); + struct pp_assemblage *pp_assemblage_ptr = + ex.cxxPPassemblage2pp_assemblage(); int n; /* * This is not quite right, may not produce sort order, forced sort */ - if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) { + if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) + { pp_assemblage_free(&pp_assemblage[n]); - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); - } else { - n=count_pp_assemblage++; - if (count_pp_assemblage >= max_pp_assemblage) { - space ((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, &max_pp_assemblage, sizeof (struct pp_assemblage *) ); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], + pp_assemblage_ptr->n_user); + } + else + { + n = count_pp_assemblage++; + if (count_pp_assemblage >= max_pp_assemblage) + { + space((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage *)); } - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); - pp_assemblage_sort (); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], + pp_assemblage_ptr->n_user); + pp_assemblage_sort(); } pp_assemblage_free(pp_assemblage_ptr); free_check_null(pp_assemblage_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_kinetics_raw (void) +int +read_kinetics_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -389,10 +434,12 @@ int read_kinetics_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("kinetics_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("kinetics_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -403,16 +450,17 @@ int read_kinetics_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -425,26 +473,33 @@ int read_kinetics_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) { + if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) + { kinetics_free(&kinetics[n]); kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); - } else { - n=count_kinetics++; - if (count_kinetics >= max_kinetics) { - space ((void **) ((void *) &(kinetics)), count_kinetics, &max_kinetics, sizeof (struct kinetics *) ); + } + else + { + n = count_kinetics++; + if (count_kinetics >= max_kinetics) + { + space((void **) ((void *) &(kinetics)), count_kinetics, + &max_kinetics, sizeof(struct kinetics *)); } kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); - kinetics_sort (); + kinetics_sort(); } kinetics_free(kinetics_ptr); free_check_null(kinetics_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_solid_solutions_raw (void) +int +read_solid_solutions_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -473,10 +528,13 @@ int read_solid_solutions_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("solid_solution_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = + check_line("solid_solution_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -487,48 +545,60 @@ int read_solid_solutions_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); cxxSSassemblage ex; ex.read_raw(parser); - struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(); + struct s_s_assemblage *s_s_assemblage_ptr = + ex.cxxSSassemblage2s_s_assemblage(); int n; /* * This is not quite right, may not produce sort order, forced sort */ - if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) { + if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) + { s_s_assemblage_free(&s_s_assemblage[n]); - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); - } else { - n=count_s_s_assemblage++; - if (count_s_s_assemblage >= max_s_s_assemblage) { - space ((void **) ((void *) &(s_s_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, sizeof (struct s_s_assemblage *) ); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], + s_s_assemblage_ptr->n_user); + } + else + { + n = count_s_s_assemblage++; + if (count_s_s_assemblage >= max_s_s_assemblage) + { + space((void **) ((void *) &(s_s_assemblage)), + count_s_s_assemblage, &max_s_s_assemblage, + sizeof(struct s_s_assemblage *)); } - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); - s_s_assemblage_sort (); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], + s_s_assemblage_ptr->n_user); + s_s_assemblage_sort(); } s_s_assemblage_free(s_s_assemblage_ptr); free_check_null(s_s_assemblage_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_gas_phase_raw (void) +int +read_gas_phase_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -557,10 +627,12 @@ int read_gas_phase_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("gas_phase_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("gas_phase_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -571,16 +643,17 @@ int read_gas_phase_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -593,26 +666,33 @@ int read_gas_phase_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) { + if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) + { gas_phase_free(&gas_phase[n]); gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); - } else { - n=count_gas_phase++; - if (count_gas_phase >= max_gas_phase) { - space ((void **) ((void *) &(gas_phase)), count_gas_phase, &max_gas_phase, sizeof (struct gas_phase *) ); + } + else + { + n = count_gas_phase++; + if (count_gas_phase >= max_gas_phase) + { + space((void **) ((void *) &(gas_phase)), count_gas_phase, + &max_gas_phase, sizeof(struct gas_phase *)); } gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); - gas_phase_sort (); + gas_phase_sort(); } gas_phase_free(gas_phase_ptr); free_check_null(gas_phase_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_reaction_raw (void) +int +read_reaction_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -641,10 +721,12 @@ int read_reaction_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("reaction_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("reaction_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -655,16 +737,17 @@ int read_reaction_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -677,25 +760,34 @@ int read_reaction_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) { + if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) + { irrev_free(&irrev[n]); irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); - } else { - n=count_irrev++; - irrev = (struct irrev *) PHRQ_realloc(irrev, (size_t) count_irrev * sizeof (struct irrev)); - if (irrev == NULL) malloc_error(); + } + else + { + n = count_irrev++; + irrev = + (struct irrev *) PHRQ_realloc(irrev, + (size_t) count_irrev * + sizeof(struct irrev)); + if (irrev == NULL) + malloc_error(); irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); - irrev_sort (); + irrev_sort(); } irrev_free(irrev_ptr); free_check_null(irrev_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_mix_raw (void) +int +read_mix_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -724,10 +816,12 @@ int read_mix_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("mix_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("mix_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -738,16 +832,17 @@ int read_mix_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -760,25 +855,34 @@ int read_mix_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (mix_bsearch(mix_ptr->n_user, &n) != NULL) { + if (mix_bsearch(mix_ptr->n_user, &n) != NULL) + { mix_free(&mix[n]); mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); - } else { - n=count_mix++; - mix = (struct mix *) PHRQ_realloc(mix, (size_t) count_mix * sizeof (struct mix)); - if (mix == NULL) malloc_error(); + } + else + { + n = count_mix++; + mix = + (struct mix *) PHRQ_realloc(mix, + (size_t) count_mix * + sizeof(struct mix)); + if (mix == NULL) + malloc_error(); mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); - mix_sort (); + mix_sort(); } mix_free(mix_ptr); free_check_null(mix_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } + /* ---------------------------------------------------------------------- */ -int read_temperature_raw (void) +int +read_temperature_raw(void) /* ---------------------------------------------------------------------- */ { /* @@ -807,10 +911,12 @@ int read_temperature_raw (void) */ int save_echo_input = pr.echo_input; pr.echo_input = FALSE; - for (;;) { - return_value = check_line("temperature_raw",TRUE,TRUE,TRUE,FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD ) break; + for (;;) + { + return_value = check_line("temperature_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; keywordLines.append(line); keywordLines.append("\n"); } @@ -821,16 +927,17 @@ int read_temperature_raw (void) std::ostringstream oss_err; CParser parser(iss_in, oss_out, oss_err); - assert (!reading_database ()); - if (pr.echo_input == FALSE) + assert(!reading_database()); + if (pr.echo_input == FALSE) { - parser.set_echo_file(CParser::EO_NONE); - } else + parser.set_echo_file(CParser::EO_NONE); + } + else { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; parser.get_option(vopts, next_char); @@ -843,20 +950,29 @@ int read_temperature_raw (void) * This is not quite right, may not produce sort order, forced sort */ - if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) { + if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) + { temperature_free(&temperature[n]); - temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); - } else { - n=count_temperature++; - temperature = (struct temperature *) PHRQ_realloc(temperature, (size_t) count_temperature * sizeof (struct temperature)); - if (temperature == NULL) malloc_error(); - temperature_copy(temperature_ptr, &temperature[n], temperature_ptr->n_user); - temperature_sort (); + temperature_copy(temperature_ptr, &temperature[n], + temperature_ptr->n_user); + } + else + { + n = count_temperature++; + temperature = + (struct temperature *) PHRQ_realloc(temperature, + (size_t) count_temperature * + sizeof(struct temperature)); + if (temperature == NULL) + malloc_error(); + temperature_copy(temperature_ptr, &temperature[n], + temperature_ptr->n_user); + temperature_sort(); } temperature_free(temperature_ptr); free_check_null(temperature_ptr); // Need to output the next keyword - output_msg (OUTPUT_CHECKLINE, "\t%s\n", line); - return(return_value); + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } diff --git a/SAXPhreeqc.cxx b/SAXPhreeqc.cxx index d3010c9d..b561fa9b 100644 --- a/SAXPhreeqc.cxx +++ b/SAXPhreeqc.cxx @@ -1,16 +1,16 @@ // SAXPhreeqc.cpp #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // DBL_DIG -#include // sprintf -#include // iswspace +#include // DBL_DIG +#include // sprintf +#include // iswspace -#include // assert +#include // assert //#include // std::ostrstream #include -#include // std::cerr +#include // std::cerr #ifdef SKIP #endif #ifdef _DEBUG @@ -27,318 +27,431 @@ #include //#include // SAXParser -#include // AttributeList -#include // Unicode definitions -#include // MemBufInputSource +#include // AttributeList +#include // Unicode definitions +#include // MemBufInputSource #include #include -#include // XMLPlatformUtils::getCurrentMillis +#include // XMLPlatformUtils::getCurrentMillis #include #include #include -#include "SAXPhreeqc.h" // SAX_ functions -#include "SaxPhreeqcHandlers.h" // SaxPhreeqcHandlers +#include "SAXPhreeqc.h" // SAX_ functions +#include "SaxPhreeqcHandlers.h" // SaxPhreeqcHandlers //XERCES_CPP_NAMESPACE_USE #define xns XERCES_CPP_NAMESPACE ///static char buffer[300000]; ///static std::ostrstream s_oss(buffer, 300000); // must never go out of scope -static std::ostringstream s_oss; // must never go out of scope -static bool s_bSysIsOpen = false; // must never go out of scope +static + std::ostringstream + s_oss; // must never go out of scope +static bool + s_bSysIsOpen = false; // must never go out of scope #include // extern routines - #include "phqalloc.h" - #include "global.h" +#include "phqalloc.h" +#include "global.h" #include "phrqproto.h" #include "output.h" #ifdef SKIP - int conc_init(struct conc *conc_ptr); - void *free_check_null(void *ptr); - int pe_data_store (struct pe_data **pe, const char *token); - struct phase *phase_bsearch (char *ptr, int *j, int print); - struct solution *solution_alloc(void); - struct solution *solution_bsearch(int k, int *n, int print); - int solution_free (struct solution *solution_ptr); - void space (void **ptr, int i, int *max, int struct_size); - char * string_duplicate (const char *token); - char *string_hsave (const char *str); - int error_msg (const char *err_str, const int stop); - struct master *master_bsearch (const char *ptr); - void malloc_error(void); +int +conc_init(struct conc *conc_ptr); +void * +free_check_null(void *ptr); +int +pe_data_store(struct pe_data **pe, const char *token); +struct phase * +phase_bsearch(char *ptr, int *j, int print); +struct solution * +solution_alloc(void); +struct solution * +solution_bsearch(int k, int *n, int print); +int +solution_free(struct solution *solution_ptr); +void +space(void **ptr, int i, int *max, int struct_size); +char * +string_duplicate(const char *token); +char * +string_hsave(const char *str); +int +error_msg(const char *err_str, const int stop); +struct master * +master_bsearch(const char *ptr); +void +malloc_error(void); #endif //} -class Initializer +class + Initializer { -public: - Initializer(){ -#if defined(_DEBUG) - int tmpDbgFlag; + public: + Initializer() + { +#if defined(_DEBUG) + int + tmpDbgFlag; - /* - * Set the debug-heap flag to keep freed blocks in the - * heap's linked list - This will allow us to catch any - * inadvertent use of freed memory - */ - tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; - //tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; - _CrtSetDbgFlag(tmpDbgFlag); -#endif + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= + _CRTDBG_LEAK_CHECK_DF; + //tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); +#endif - xns::XMLPlatformUtils::Initialize(); - } + xns::XMLPlatformUtils::Initialize(); + } }; -static Initializer sInit; // initialize xerces once -static SaxPhreeqcHandlers s_handler; // one and only instance +static Initializer + sInit; // initialize xerces once +static SaxPhreeqcHandlers + s_handler; // one and only instance -void SAX_StartSystem() +void +SAX_StartSystem() { - assert(!s_bSysIsOpen); // system already open and has not been closed + assert(!s_bSysIsOpen); // system already open and has not been closed - // init stream - //s_oss.freeze(false); - s_oss.seekp(0); - - // write stream - // s_oss << ""; - s_oss << ""; - s_oss << ""; - s_oss << " "; - s_bSysIsOpen = true; + // init stream + //s_oss.freeze(false); + s_oss.seekp(0); + + // write stream + // s_oss << ""; + s_oss << ""; + s_oss << ""; + s_oss << " "; + s_bSysIsOpen = true; } -char * stringify_null(char * string) { - if (string == NULL) return(string_hsave("")); - return(string); +char * +stringify_null(char *string) +{ + if (string == NULL) + return (string_hsave("")); + return (string); } -int SAX_AddSolution(struct solution* solution_ptr) + +int +SAX_AddSolution(struct solution *solution_ptr) { //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; - int i, newd; - assert(s_bSysIsOpen); // must call SAX_StartSystem first + int + i, + newd; + assert(s_bSysIsOpen); // must call SAX_StartSystem first s_oss.precision(DBL_DIG - 1); // Solution element and attributes - newd = solution_ptr->new_def; + newd = solution_ptr->new_def; s_oss << " new_def << "\"" << std::endl; - s_oss << " soln_n_user=\"" << solution_ptr->n_user << "\" " << std::endl; - s_oss << " soln_n_user_end=\"" << solution_ptr->n_user_end << "\"" << std::endl; - s_oss << " soln_description=\"" << solution_ptr->description << "\"" << std::endl; + s_oss << " soln_new_def=\"" << solution_ptr-> + new_def << "\"" << std::endl; + s_oss << " soln_n_user=\"" << solution_ptr-> + n_user << "\" " << std::endl; + s_oss << " soln_n_user_end=\"" << solution_ptr-> + n_user_end << "\"" << std::endl; + s_oss << " soln_description=\"" << solution_ptr-> + description << "\"" << std::endl; s_oss << " soln_tc=\"" << solution_ptr->tc << "\"" << std::endl; s_oss << " soln_ph=\"" << solution_ptr->ph << "\"" << std::endl; - s_oss << " soln_solution_pe=\"" << solution_ptr->solution_pe << "\"" << std::endl; + s_oss << " soln_solution_pe=\"" << solution_ptr-> + solution_pe << "\"" << std::endl; s_oss << " soln_mu=\"" << solution_ptr->mu << "\"" << std::endl; - s_oss << " soln_ah2o=\"" << solution_ptr->ah2o << "\"" << std::endl; - s_oss << " soln_density=\"" << solution_ptr->density << "\"" << std::endl; - s_oss << " soln_total_h=\"" << solution_ptr->total_h << "\"" << std::endl; - s_oss << " soln_total_o=\"" << solution_ptr->total_o << "\"" << std::endl; + s_oss << " soln_ah2o=\"" << solution_ptr->ah2o << "\"" << std::endl; + s_oss << " soln_density=\"" << solution_ptr-> + density << "\"" << std::endl; + s_oss << " soln_total_h=\"" << solution_ptr-> + total_h << "\"" << std::endl; + s_oss << " soln_total_o=\"" << solution_ptr-> + total_o << "\"" << std::endl; s_oss << " soln_cb=\"" << solution_ptr->cb << "\"" << std::endl; - s_oss << " soln_mass_water=\"" << solution_ptr->mass_water << "\"" << std::endl; - s_oss << " soln_total_alkalinity=\"" << solution_ptr->total_alkalinity << "\"" << std::endl; + s_oss << " soln_mass_water=\"" << solution_ptr-> + mass_water << "\"" << std::endl; + s_oss << " soln_total_alkalinity=\"" << solution_ptr-> + total_alkalinity << "\"" << std::endl; //s_oss << " soln_total_co2=\"" << solution_ptr->total_co2 << "\"" << std::endl; s_oss << " soln_units=\"" << solution_ptr->units << "\"" << std::endl; - s_oss << " soln_default_pe=\"" << solution_ptr->default_pe << "\"" << std::endl; - s_oss << " soln_count_master_activity=\"" << solution_ptr->count_master_activity << "\"" << std::endl; - s_oss << " soln_count_isotopes=\"" << solution_ptr->count_isotopes << "\"" << std::endl; - s_oss << " soln_count_species_gamma=\"" << solution_ptr->count_species_gamma << "\">" << std::endl; + s_oss << " soln_default_pe=\"" << solution_ptr-> + default_pe << "\"" << std::endl; + s_oss << " soln_count_master_activity=\"" << solution_ptr-> + count_master_activity << "\"" << std::endl; + s_oss << " soln_count_isotopes=\"" << solution_ptr-> + count_isotopes << "\"" << std::endl; + s_oss << " soln_count_species_gamma=\"" << solution_ptr-> + count_species_gamma << "\">" << std::endl; // end of solution attributes // pe structures - for (i=0; solution_ptr->pe[i].name != NULL; i++) { - s_oss << " pe[i].name << "\"/>"<< std::endl; + for (i = 0; solution_ptr->pe[i].name != NULL; i++) + { + s_oss << " pe[i]. + name << "\"/>" << std::endl; } // soln_total conc structures - for (i=0; solution_ptr->totals[i].description != NULL; i++) { - struct conc *c = &(solution_ptr->totals[i]); + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + struct conc * + c = &(solution_ptr->totals[i]); s_oss << " description << "\"" << std::endl; s_oss << " conc_moles=\"" << c->moles << "\"" << std::endl; - if (newd == TRUE) { - s_oss << " conc_input_conc=\"" << c->input_conc << "\"" << std::endl; - if (c->units != NULL) s_oss << " conc_units=\"" << c->units << "\"" << std::endl; - if (c->equation_name != NULL) { - s_oss << " conc_equation_name=\"" << stringify_null(c->equation_name) << "\"" << std::endl; - s_oss << " conc_phase_si=\"" << c->phase_si << "\"" << std::endl; + if (newd == TRUE) + { + s_oss << " conc_input_conc=\"" << c-> + input_conc << "\"" << std::endl; + if (c->units != NULL) + s_oss << " conc_units=\"" << c-> + units << "\"" << std::endl; + if (c->equation_name != NULL) + { + s_oss << " conc_equation_name=\"" << stringify_null(c-> + equation_name) + << "\"" << std::endl; + s_oss << " conc_phase_si=\"" << c-> + phase_si << "\"" << std::endl; } - if (c->as != NULL) s_oss << " conc_as=\"" << stringify_null(c->as) << "\"" << std::endl; + if (c->as != NULL) + s_oss << " conc_as=\"" << stringify_null(c-> + as) << "\"" << + std::endl; s_oss << " conc_gfw=\"" << c->gfw << "\"" << std::endl; } s_oss << " conc_n_pe=\"" << c->n_pe << "\"" << std::endl; - s_oss << " />" << std::endl; + s_oss << " />" << std::endl; } // master_activity, master_activity structure - - for (i=0; i < solution_ptr->count_master_activity; i++) { - s_oss << " master_activity[i].description) << "\" m_a_la=\"" << solution_ptr->master_activity[i].la << "\"/>" << std::endl; + + for (i = 0; i < solution_ptr->count_master_activity; i++) + { + s_oss << " + master_activity + [i]. + description) << + "\" m_a_la=\"" << solution_ptr->master_activity[i]. + la << "\"/>" << std::endl; } /* - if (solution_ptr->count_master_activity > 0) { - s_oss << " count_master_activity; i++) { - if (solution_ptr->master_activity[i].description != NULL) { - s_oss << stringify_null(solution_ptr->master_activity[i].description) << " "; - s_oss << solution_ptr->master_activity[i].la << std::endl; - } else { - s_oss << "null 0.0" << std::endl; - } - } - s_oss << "\"/>" << std::endl; - } - */ + if (solution_ptr->count_master_activity > 0) { + s_oss << " count_master_activity; i++) { + if (solution_ptr->master_activity[i].description != NULL) { + s_oss << stringify_null(solution_ptr->master_activity[i].description) << " "; + s_oss << solution_ptr->master_activity[i].la << std::endl; + } else { + s_oss << "null 0.0" << std::endl; + } + } + s_oss << "\"/>" << std::endl; + } + */ // species_gamma, mater_activity structure - for (i=0; i < solution_ptr->count_species_gamma; i++) { - s_oss << " species_gamma[i].description) << "\" m_a_la=\"" << solution_ptr->species_gamma[i].la << "\"/>" << std::endl; + for (i = 0; i < solution_ptr->count_species_gamma; i++) + { + s_oss << " + species_gamma + [i]. + description) << + "\" m_a_la=\"" << solution_ptr->species_gamma[i]. + la << "\"/>" << std::endl; } // isotopes, isotope structure - for (i=0; solution_ptr->count_isotopes; i++) { + for (i = 0; solution_ptr->count_isotopes; i++) + { s_oss << " isotopes[i].isotope_number << "\"" << std::endl; - s_oss << " iso_elt_name=\"" << solution_ptr->isotopes[i].elt_name << "\"" << std::endl; - s_oss << " iso_isotope_name=\"" << solution_ptr->isotopes[i].isotope_name << "\"" << std::endl; - s_oss << " iso_total=\"" << solution_ptr->isotopes[i].total << "\"" << std::endl; - s_oss << " iso_ratio=\"" << solution_ptr->isotopes[i].ratio << "\"" << std::endl; - s_oss << " iso_ratio_uncertainty=\"" << solution_ptr->isotopes[i].ratio_uncertainty << "\"" << std::endl; - s_oss << " iso_coef=\"" << solution_ptr->isotopes[i].coef << "\"" << std::endl; + s_oss << " iso_isotope_number=\"" << solution_ptr->isotopes[i]. + isotope_number << "\"" << std::endl; + s_oss << " iso_elt_name=\"" << solution_ptr->isotopes[i]. + elt_name << "\"" << std::endl; + s_oss << " iso_isotope_name=\"" << solution_ptr->isotopes[i]. + isotope_name << "\"" << std::endl; + s_oss << " iso_total=\"" << solution_ptr->isotopes[i]. + total << "\"" << std::endl; + s_oss << " iso_ratio=\"" << solution_ptr->isotopes[i]. + ratio << "\"" << std::endl; + s_oss << " iso_ratio_uncertainty=\"" << solution_ptr->isotopes[i]. + ratio_uncertainty << "\"" << std::endl; + s_oss << " iso_coef=\"" << solution_ptr->isotopes[i]. + coef << "\"" << std::endl; } // End of solution s_oss << " " << std::endl; - return(OK); + return (OK); } -void SAX_EndSystem() +void +SAX_EndSystem() { - assert(s_bSysIsOpen); // must call SAX_StartSystem first + assert(s_bSysIsOpen); // must call SAX_StartSystem first - s_oss << " " << std::endl; - s_oss << "" << std::endl; - s_oss << '\0'; - - s_bSysIsOpen = false; - //delete[] s_handler; - return; + s_oss << " " << std::endl; + s_oss << "" << std::endl; + s_oss << '\0'; + + s_bSysIsOpen = false; + //delete[] s_handler; + return; } -int SAX_GetXMLLength() +int +SAX_GetXMLLength() { - assert(!s_bSysIsOpen); // must call SAX_EndSystem first - //return s_oss.pcount(); - return s_oss.str().size(); + assert(!s_bSysIsOpen); // must call SAX_EndSystem first + //return s_oss.pcount(); + return s_oss.str().size(); } -const char* SAX_GetXMLStr() +const char * +SAX_GetXMLStr() { - assert(!s_bSysIsOpen); // must call SAX_EndSystem first - return s_oss.str().c_str(); + assert(!s_bSysIsOpen); // must call SAX_EndSystem first + return s_oss.str().c_str(); } -void SAX_cleanup() +void +SAX_cleanup() { - //delete s_handler; - //s_oss.freeze(false); -} + //delete s_handler; + //s_oss.freeze(false); +} // utility routines -int XMLCh2Int(const XMLCh* const attValue) { - char *string = xns::XMLString::transcode(attValue); - int i = strtol(string, NULL, 10); - xns::XMLString::release(&string); - return i; - //return (xns::XMLString::parseInt(attValue)); -} -double XMLCh2Double(const XMLCh* const attValue) { - char *string = xns::XMLString::transcode(attValue); - double d = strtod(string, NULL); - xns::XMLString::release(&string); - return d; -} -char * XMLCh2String(const XMLCh* const attValue) { - char *string = xns::XMLString::transcode(attValue); - char *s = string_duplicate(string); - xns::XMLString::release(&string); - return s; -} -char * XMLCh_hsave(const XMLCh* const attValue, bool allow_null) { - char *string = xns::XMLString::transcode(attValue); - char *s = string_hsave(string); - if (allow_null && strlen(s) == 0) s = NULL; - xns::XMLString::release(&string); - return s; -} - - -int SAX_UnpackSolutions(void* pvBuffer, int buf_size) +int +XMLCh2Int(const XMLCh * const attValue) { - // Create MemBufferInputSource from the buffer containing the XML - // statements. - xns::MemBufInputSource memBufIS((const XMLByte*)pvBuffer, buf_size, "solution_id", false); - fprintf(stderr,"%s", (char *) pvBuffer); + char * + string = xns::XMLString::transcode(attValue); + int + i = strtol(string, NULL, 10); + xns::XMLString::release(&string); + return i; + //return (xns::XMLString::parseInt(attValue)); +} + +double +XMLCh2Double(const XMLCh * const attValue) +{ + char * + string = xns::XMLString::transcode(attValue); + double + d = strtod(string, NULL); + xns::XMLString::release(&string); + return d; +} + +char * +XMLCh2String(const XMLCh * const attValue) +{ + char * + string = xns::XMLString::transcode(attValue); + char * + s = string_duplicate(string); + xns::XMLString::release(&string); + return s; +} + +char * +XMLCh_hsave(const XMLCh * const attValue, bool allow_null) +{ + char * + string = xns::XMLString::transcode(attValue); + char * + s = string_hsave(string); + if (allow_null && strlen(s) == 0) + s = NULL; + xns::XMLString::release(&string); + return s; +} + + +int +SAX_UnpackSolutions(void *pvBuffer, int buf_size) +{ + // Create MemBufferInputSource from the buffer containing the XML + // statements. + xns::MemBufInputSource memBufIS((const XMLByte *) pvBuffer, buf_size, + "solution_id", false); + fprintf(stderr, "%s", (char *) pvBuffer); return 0; - // - // Create a SAX2 parser object. - // + // + // Create a SAX2 parser object. + // xns::SAX2XMLReader * parser = xns::XMLReaderFactory::createXMLReader(); parser->setFeature(xns::XMLUni::fgXercesSchemaFullChecking, false); parser->setFeature(xns::XMLUni::fgSAX2CoreNameSpaces, false); parser->setFeature(xns::XMLUni::fgXercesSchema, false); - parser->setFeature(xns::XMLUni::fgXercesIdentityConstraintChecking, false); - // - // Create the handler object and install it as the document and error - // handler for the parser. Then parse the MemBufferInputSource and - // catch any exceptions that propogate out - // - try - { - unsigned long duration = 0; - parser->setContentHandler(&s_handler); - parser->setErrorHandler(&s_handler); - int t = 0; - for (; t < 1000; ++t) + parser->setFeature(xns::XMLUni::fgXercesIdentityConstraintChecking, + false); + // + // Create the handler object and install it as the document and error + // handler for the parser. Then parse the MemBufferInputSource and + // catch any exceptions that propogate out + // + try { - const unsigned long startMillis = xns::XMLPlatformUtils::getCurrentMillis(); - parser->parse(memBufIS); - const unsigned long endMillis = xns::XMLPlatformUtils::getCurrentMillis(); - duration += endMillis - startMillis; + unsigned long + duration = 0; + parser->setContentHandler(&s_handler); + parser->setErrorHandler(&s_handler); + int + t = 0; + for (; t < 1000; ++t) + { + const unsigned long + startMillis = xns::XMLPlatformUtils::getCurrentMillis(); + parser->parse(memBufIS); + const unsigned long + endMillis = xns::XMLPlatformUtils::getCurrentMillis(); + duration += endMillis - startMillis; + } + std::cerr << "\nSaxParse time = " << duration << " millis\n"; + } + catch(const xns::SAXException & toCatch) + { + char * + psz = xns::XMLString::transcode(toCatch.getMessage()); + input_error++; + sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&psz); + return ERROR; + } + catch(const xns::XMLException & toCatch) + { + char * + psz = xns::XMLString::transcode(toCatch.getMessage()); + input_error++; + sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&psz); + return ERROR; + } + catch(...) + { + input_error++; + sprintf(error_string, "SAX_UnpackSolutions: %s\n", + "Unknown error occured."); + error_msg(error_string, CONTINUE); + return ERROR; } - std::cerr << "\nSaxParse time = " << duration << " millis\n"; - } - catch (const xns::SAXException& toCatch) - { - char* psz = xns::XMLString::transcode(toCatch.getMessage()); - input_error++; - sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&psz); - return ERROR; - } - catch (const xns::XMLException& toCatch) - { - char* psz = xns::XMLString::transcode(toCatch.getMessage()); - input_error++; - sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&psz); - return ERROR; - } - catch (...) - { - input_error++; - sprintf(error_string,"SAX_UnpackSolutions: %s\n", "Unknown error occured."); - error_msg(error_string, CONTINUE); - return ERROR; - } - return(OK); + return (OK); } @@ -348,15 +461,31 @@ int SAX_UnpackSolutions(void* pvBuffer, int buf_size) // element names -SaxPhreeqcHandlers::SaxPhreeqcHandlers() - : eltType(typeNULL), attType(attNULL), totals(), acts(), solution_ptr(NULL) +SaxPhreeqcHandlers::SaxPhreeqcHandlers():eltType(typeNULL), attType(attNULL), totals(), acts(), +solution_ptr(NULL) { - int i; + int + i; - int count_elementInfo, count_attributeInfo; - struct mapElementInfo {char *key; enum elementType type;}; - struct mapAttributeInfo {enum attributeType type; char *key;}; - struct mapElementInfo elementInfo[] = { + int + count_elementInfo, + count_attributeInfo; + struct mapElementInfo + { + char * + key; + enum elementType + type; + }; + struct mapAttributeInfo + { + enum attributeType + type; + char * + key; + }; + struct mapElementInfo + elementInfo[] = { {"phast_state", typePHAST_STATE}, {"system", typeSYSTEM}, {"solution", typeSOLUTION}, @@ -366,65 +495,73 @@ SaxPhreeqcHandlers::SaxPhreeqcHandlers() {"soln_isotope", typeSOLN_ISOTOPE}, {"soln_s_g", typeSOLN_SPECIES_GAMMA} }; - count_elementInfo = sizeof(elementInfo)/sizeof(struct mapElementInfo); - struct mapAttributeInfo attributeInfo[] = { + count_elementInfo = sizeof(elementInfo) / sizeof(struct mapElementInfo); + struct mapAttributeInfo + attributeInfo[] = { // Solution structure - {attSOLN_new_def, "soln_new_def"}, - {attSOLN_n_user, "soln_n_user"}, - {attSOLN_n_user_end, "soln_n_user_end"}, - {attSOLN_description, "soln_description"}, - {attSOLN_tc, "soln_tc"}, - {attSOLN_ph, "soln_ph"}, - {attSOLN_solution_pe, "soln_solution_pe"}, - {attSOLN_mu, "soln_mu"}, - {attSOLN_ah2o, "soln_ah2o"}, - {attSOLN_density, "soln_density"}, - {attSOLN_total_h, "soln_total_h"}, - {attSOLN_total_o, "soln_total_o"}, - {attSOLN_cb, "soln_cb"}, - {attSOLN_mass_water, "soln_mass_water"}, - {attSOLN_total_alkalinity, "soln_total_alkalinity"}, - {attSOLN_total_co2, "soln_total_co2"}, - {attSOLN_units, "soln_units"}, - {attSOLN_default_pe, "soln_default_pe"}, - {attSOLN_count_master_activity, "soln_count_master_activity"}, - {attSOLN_count_isotopes, "soln_count_isotopes"}, - {attSOLN_count_species_gamma, "soln_count_species_gamma"}, - {attSOLN_PE_name, "soln_pe_name"}, + {attSOLN_new_def, "soln_new_def"}, + {attSOLN_n_user, "soln_n_user"}, + {attSOLN_n_user_end, "soln_n_user_end"}, + {attSOLN_description, "soln_description"}, + {attSOLN_tc, "soln_tc"}, + {attSOLN_ph, "soln_ph"}, + {attSOLN_solution_pe, "soln_solution_pe"}, + {attSOLN_mu, "soln_mu"}, + {attSOLN_ah2o, "soln_ah2o"}, + {attSOLN_density, "soln_density"}, + {attSOLN_total_h, "soln_total_h"}, + {attSOLN_total_o, "soln_total_o"}, + {attSOLN_cb, "soln_cb"}, + {attSOLN_mass_water, "soln_mass_water"}, + {attSOLN_total_alkalinity, "soln_total_alkalinity"}, + {attSOLN_total_co2, "soln_total_co2"}, + {attSOLN_units, "soln_units"}, + {attSOLN_default_pe, "soln_default_pe"}, + {attSOLN_count_master_activity, "soln_count_master_activity"}, + {attSOLN_count_isotopes, "soln_count_isotopes"}, + {attSOLN_count_species_gamma, "soln_count_species_gamma"}, + {attSOLN_PE_name, "soln_pe_name"}, // master_activity structure - {attM_A_description, "m_a_desc"}, - {attM_A_la, "m_a_la"}, - {attM_A_list, "m_a_list"}, + {attM_A_description, "m_a_desc"}, + {attM_A_la, "m_a_la"}, + {attM_A_list, "m_a_list"}, // isotope structure - {attISO_isotope_number, "iso_isotope_number"}, - {attISO_elt_name, "iso_elt_name"}, - {attISO_isotope_name, "iso_isotope_name"}, - {attISO_total, "iso_total"}, - {attISO_ratio, "iso_ratio"}, - {attISO_ratio_uncertainty, "iso_ratio_uncertainty"}, - {attISO_x_ratio_uncertainty, "iso_x_ratio_uncertainty"}, - {attISO_coef, "iso_coef"}, + {attISO_isotope_number, "iso_isotope_number"}, + {attISO_elt_name, "iso_elt_name"}, + {attISO_isotope_name, "iso_isotope_name"}, + {attISO_total, "iso_total"}, + {attISO_ratio, "iso_ratio"}, + {attISO_ratio_uncertainty, "iso_ratio_uncertainty"}, + {attISO_x_ratio_uncertainty, "iso_x_ratio_uncertainty"}, + {attISO_coef, "iso_coef"}, // conc structure - {attCONC_description, "conc_desc"}, - {attCONC_moles, "conc_moles"}, - {attCONC_input_conc, "conc_input_conc"}, - {attCONC_units, "conc_units"}, - {attCONC_equation_name, "conc_equation_name"}, - {attCONC_phase_si, "conc_phase_si"}, - {attCONC_n_pe, "conc_n_pe"}, - {attCONC_as, "conc_as"}, - {attCONC_gfw, "conc_gfw"}, + {attCONC_description, "conc_desc"}, + {attCONC_moles, "conc_moles"}, + {attCONC_input_conc, "conc_input_conc"}, + {attCONC_units, "conc_units"}, + {attCONC_equation_name, "conc_equation_name"}, + {attCONC_phase_si, "conc_phase_si"}, + {attCONC_n_pe, "conc_n_pe"}, + {attCONC_as, "conc_as"}, + {attCONC_gfw, "conc_gfw"}, }; - count_attributeInfo = sizeof(attributeInfo)/sizeof(struct mapAttributeInfo); - for (i = 0; i < count_elementInfo; i++) { + count_attributeInfo = + sizeof(attributeInfo) / sizeof(struct mapAttributeInfo); + for (i = 0; i < count_elementInfo; i++) + { // memory freed in destructor - this->mapXMLCh2Type[xns::XMLString::transcode(elementInfo[i].key)] = elementInfo[i].type; + this->mapXMLCh2Type[xns::XMLString::transcode(elementInfo[i].key)] = + elementInfo[i].type; } - for (i = 0; i < count_attributeInfo; i++) { + for (i = 0; i < count_attributeInfo; i++) + { // memory freed in destructor - this->mapXMLCh2AttType[xns::XMLString::transcode(attributeInfo[i].key)] = attributeInfo[i].type; + this-> + mapXMLCh2AttType[xns::XMLString:: + transcode(attributeInfo[i].key)] = + attributeInfo[i].type; } this->totals.reserve(50); @@ -433,17 +570,19 @@ SaxPhreeqcHandlers::SaxPhreeqcHandlers() SaxPhreeqcHandlers::~SaxPhreeqcHandlers() { - std::map::iterator it = this->mapXMLCh2Type.begin(); + std::map < const XMLCh *, elementType, XMLCH_LESS >::iterator it = + this->mapXMLCh2Type.begin(); for (; it != this->mapXMLCh2Type.end(); ++it) { - XMLCh* p = (XMLCh*)it->first; + XMLCh *p = (XMLCh *) it->first; xns::XMLString::release(&p); } this->mapXMLCh2Type.clear(); - std::map::iterator ita = this->mapXMLCh2AttType.begin(); + std::map < const XMLCh *, attributeType, XMLCH_LESS >::iterator ita = + this->mapXMLCh2AttType.begin(); for (; ita != this->mapXMLCh2AttType.end(); ++ita) { - XMLCh* p = (XMLCh*)ita->first; + XMLCh *p = (XMLCh *) ita->first; xns::XMLString::release(&p); } this->mapXMLCh2AttType.clear(); @@ -454,50 +593,97 @@ SaxPhreeqcHandlers::~SaxPhreeqcHandlers() // Implementations of the SAX DocumentHandler interface // ----------------------------------------------------------------------- -void SaxPhreeqcHandlers::endDocument() +void +SaxPhreeqcHandlers::endDocument() { } -void SaxPhreeqcHandlers::endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname) +void +SaxPhreeqcHandlers::endElement(const XMLCh * const uri, + const XMLCh * const name, + const XMLCh * const qname) { - switch (this->mapXMLCh2Type[name]) - { + switch (this->mapXMLCh2Type[name]) + { case typeSOLUTION: // solution is finished now copy into solutions array { int n; // copy vector of conc's to solution - this->solution_ptr->totals = (struct conc*) PHRQ_realloc(this->solution_ptr->totals, (size_t) (this->totals.size() + 1) * sizeof(struct conc)); - std::copy(this->totals.begin(), this->totals.end(), this->solution_ptr->totals); - this->solution_ptr->totals[this->totals.size()].description=NULL; + this->solution_ptr->totals = + (struct conc *) PHRQ_realloc(this->solution_ptr->totals, + (size_t) (this->totals.size() + + 1) * + sizeof(struct conc)); + std::copy(this->totals.begin(), this->totals.end(), + this->solution_ptr->totals); + this->solution_ptr->totals[this->totals.size()].description = + NULL; this->totals.clear(); assert(this->totals.size() == 0); // copy vector of master_activities's to solution - this->solution_ptr->master_activity = (struct master_activity *) free_check_null(this->solution_ptr->master_activity); - if (this->acts.size() > 0) { - this->solution_ptr->master_activity = (struct master_activity *) PHRQ_realloc(this->solution_ptr->master_activity, (size_t) (this->acts.size()) * sizeof(struct master_activity)); - std::copy(this->acts.begin(), this->acts.end(), this->solution_ptr->master_activity); + this->solution_ptr->master_activity = + (struct master_activity *) free_check_null(this-> + solution_ptr-> + master_activity); + if (this->acts.size() > 0) + { + this->solution_ptr->master_activity = + (struct master_activity *) PHRQ_realloc(this-> + solution_ptr-> + master_activity, + (size_t) (this-> + acts. + size()) + * + sizeof(struct + master_activity)); + std::copy(this->acts.begin(), this->acts.end(), + this->solution_ptr->master_activity); } this->solution_ptr->count_master_activity = this->acts.size(); this->acts.clear(); assert(this->acts.size() == 0); // copy vector of s_gamma's to solution - this->solution_ptr->species_gamma = (struct master_activity *) free_check_null(this->solution_ptr->species_gamma); - if (this->s_gammas.size() > 0) { - this->solution_ptr->species_gamma = (struct master_activity *) PHRQ_realloc(this->solution_ptr->species_gamma, (size_t) (this->s_gammas.size()) * sizeof(struct master_activity)); - std::copy(this->s_gammas.begin(), this->s_gammas.end(), this->solution_ptr->species_gamma); + this->solution_ptr->species_gamma = + (struct master_activity *) free_check_null(this-> + solution_ptr-> + species_gamma); + if (this->s_gammas.size() > 0) + { + this->solution_ptr->species_gamma = + (struct master_activity *) PHRQ_realloc(this-> + solution_ptr-> + species_gamma, + (size_t) (this-> + s_gammas. + size()) + * + sizeof(struct + master_activity)); + std::copy(this->s_gammas.begin(), this->s_gammas.end(), + this->solution_ptr->species_gamma); } this->solution_ptr->count_species_gamma = this->s_gammas.size(); this->s_gammas.clear(); assert(this->s_gammas.size() == 0); // copy vector of isotopes's to solution - this->solution_ptr->isotopes = (struct isotope *) free_check_null(this->solution_ptr->isotopes); - if (this->isotopes.size() > 0) { - this->solution_ptr->isotopes = (struct isotope *) PHRQ_realloc(this->solution_ptr->isotopes, (size_t) (this->isotopes.size()) * sizeof(struct isotope)); - std::copy(this->isotopes.begin(), this->isotopes.end(), this->solution_ptr->isotopes); + this->solution_ptr->isotopes = + (struct isotope *) free_check_null(this->solution_ptr-> + isotopes); + if (this->isotopes.size() > 0) + { + this->solution_ptr->isotopes = + (struct isotope *) PHRQ_realloc(this->solution_ptr-> + isotopes, + (size_t) (this->isotopes. + size()) * + sizeof(struct isotope)); + std::copy(this->isotopes.begin(), this->isotopes.end(), + this->solution_ptr->isotopes); } this->solution_ptr->count_isotopes = this->isotopes.size(); this->isotopes.clear(); @@ -505,28 +691,35 @@ void SaxPhreeqcHandlers::endElement(const XMLCh* const uri, const XMLCh* const n // store solution for now - if (solution_bsearch(this->solution_ptr->n_user, &n, FALSE) != NULL) { + if (solution_bsearch(this->solution_ptr->n_user, &n, FALSE) != + NULL) + { solution_free(solution[n]); solution[n] = this->solution_ptr; - } else { + } + else + { n = count_solution++; if (count_solution >= max_solution) { - space ((void **) &(solution), count_solution, &max_solution, sizeof (struct solution *) ); + space((void **) &(solution), count_solution, + &max_solution, sizeof(struct solution *)); } solution[n] = this->solution_ptr; } this->solution_ptr = NULL; } break; - default: - break; - } + default: + break; + } } -void SaxPhreeqcHandlers::characters(const XMLCh* const chars, const unsigned int length) +void +SaxPhreeqcHandlers::characters(const XMLCh * const chars, + const unsigned int length) { - // skip whitespace + // skip whitespace //XMLCh* pChar = (XMLCh*)chars; //while(pChar && iswspace(*pChar)) ++pChar; @@ -552,61 +745,77 @@ void SaxPhreeqcHandlers::characters(const XMLCh* const chars, const unsigned int } -void SaxPhreeqcHandlers::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) +void +SaxPhreeqcHandlers::ignorableWhitespace(const XMLCh * const chars, + const unsigned int length) { } -void SaxPhreeqcHandlers::processingInstruction(const XMLCh* const target, const XMLCh* const data) +void +SaxPhreeqcHandlers::processingInstruction(const XMLCh * const target, + const XMLCh * const data) { } -void SaxPhreeqcHandlers::startDocument() +void +SaxPhreeqcHandlers::startDocument() { } -void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname, const xns::Attributes& attributes) +void +SaxPhreeqcHandlers::startElement(const XMLCh * const uri, + const XMLCh * const name, + const XMLCh * const qname, + const xns::Attributes & attributes) { //const char ERR_MSG[] = "Unpacking solution message: %s, element not found\n"; - char *string; + char *string; - int i; + int i; - string = xns::XMLString::transcode(name); - this->eltType = this->mapXMLCh2Type[name]; - xns::XMLString::release(&string); - switch (this->eltType) - { - case typePHAST_STATE: - XMLCh *x; + string = xns::XMLString::transcode(name); + this->eltType = this->mapXMLCh2Type[name]; + xns::XMLString::release(&string); + switch (this->eltType) + { + case typePHAST_STATE: + XMLCh * x; x = xns::XMLString::transcode("nx"); i = XMLCh2Int(attributes.getValue(x)); xns::XMLString::release(&x); break; - case typeSOLUTION: - assert(this->solution_ptr == NULL); - assert(this->totals.size() == 0); - assert(this->acts.size() == 0); - - // allocate space for solution - this->solution_ptr = solution_alloc(); - - // process attributes for solution - processSolutionAttributes(attributes); - break; - case typeSOLN_PE: + case typeSOLUTION: + assert(this->solution_ptr == NULL); + assert(this->totals.size() == 0); + assert(this->acts.size() == 0); + + // allocate space for solution + this->solution_ptr = solution_alloc(); + + // process attributes for solution + processSolutionAttributes(attributes); + break; + case typeSOLN_PE: assert(this->solution_ptr->pe != NULL); // store pe, no need to clean up at end of solution - if ((attributes.getLength() >= 1) && (this->mapXMLCh2AttType[attributes.getLocalName(0)] == attSOLN_PE_name)){ - string = xns::XMLString::transcode(attributes.getValue((unsigned int) 0)); + if ((attributes.getLength() >= 1) + && (this->mapXMLCh2AttType[attributes.getLocalName(0)] == + attSOLN_PE_name)) + { + string = + xns::XMLString::transcode(attributes. + getValue((unsigned int) 0)); pe_data_store(&(this->solution_ptr->pe), string); xns::XMLString::release(&string); - } else { + } + else + { ++input_error; sprintf(error_string, "No attribute data for SOLN_PE.\n"); error_msg(error_string, CONTINUE); } break; - case typeSOLN_TOTAL: + case typeSOLN_TOTAL: { // store in c, push_back on totals // need to copy and clean up at end of @@ -614,8 +823,8 @@ void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const processSolutionTotalAttributes(attributes, &c); this->totals.push_back(c); } - break; - case typeSOLN_MASTER_ACTIVITY: + break; + case typeSOLN_MASTER_ACTIVITY: { // store in ma, push_back on acts // need to copy and clean up at end of @@ -625,7 +834,7 @@ void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const //processMasterActivityAttributes(attributes, &this->acts); } break; - case typeSOLN_SPECIES_GAMMA: + case typeSOLN_SPECIES_GAMMA: { // store in ma, push_back on s_gammas // need to copy and clean up at end of @@ -634,7 +843,7 @@ void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const this->s_gammas.push_back(ma); } break; - case typeSOLN_ISOTOPE: + case typeSOLN_ISOTOPE: { // store in iso, push_back on isotopes // need to copy and clean up at end of @@ -642,15 +851,18 @@ void SaxPhreeqcHandlers::startElement(const XMLCh* const uri, const XMLCh* const processIsotopeAttributes(attributes, &iso); this->isotopes.push_back(iso); } - break; + break; - default: - break; - } + default: + break; + } } -int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attributes) +int +SaxPhreeqcHandlers::processSolutionAttributes(const xns:: + Attributes & attributes) { - const char ERR_MSG[] = "Unpacking solution attributes: %s, attribute not found\n"; + const char ERR_MSG[] = + "Unpacking solution attributes: %s, attribute not found\n"; unsigned int i; char *string; attributeType attType; @@ -659,9 +871,11 @@ int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attribu // Get attribute name, map to attribute type, process - for (i = 0; i < attributes.getLength(); i++) { + for (i = 0; i < attributes.getLength(); i++) + { attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) { + switch (attType) + { case attSOLN_new_def: this->solution_ptr->new_def = XMLCh2Int(attributes.getValue(i)); break; @@ -669,10 +883,12 @@ int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attribu this->solution_ptr->n_user = XMLCh2Int(attributes.getValue(i)); break; case attSOLN_n_user_end: - this->solution_ptr->n_user_end = XMLCh2Int(attributes.getValue(i)); + this->solution_ptr->n_user_end = + XMLCh2Int(attributes.getValue(i)); break; case attSOLN_description: - this->solution_ptr->description = XMLCh2String(attributes.getValue(i)); + this->solution_ptr->description = + XMLCh2String(attributes.getValue(i)); break; case attSOLN_tc: this->solution_ptr->tc = XMLCh2Double(attributes.getValue(i)); @@ -681,7 +897,8 @@ int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attribu this->solution_ptr->ph = XMLCh2Double(attributes.getValue(i)); break; case attSOLN_solution_pe: - this->solution_ptr->solution_pe = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->solution_pe = + XMLCh2Double(attributes.getValue(i)); break; case attSOLN_mu: this->solution_ptr->mu = XMLCh2Double(attributes.getValue(i)); @@ -690,40 +907,50 @@ int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attribu this->solution_ptr->ah2o = XMLCh2Double(attributes.getValue(i)); break; case attSOLN_density: - this->solution_ptr->density = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->density = + XMLCh2Double(attributes.getValue(i)); break; case attSOLN_total_h: - this->solution_ptr->total_h = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->total_h = + XMLCh2Double(attributes.getValue(i)); break; case attSOLN_total_o: - this->solution_ptr->total_o = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->total_o = + XMLCh2Double(attributes.getValue(i)); break; case attSOLN_cb: this->solution_ptr->cb = XMLCh2Double(attributes.getValue(i)); break; case attSOLN_mass_water: - this->solution_ptr->mass_water = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->mass_water = + XMLCh2Double(attributes.getValue(i)); break; case attSOLN_total_alkalinity: - this->solution_ptr->total_alkalinity = XMLCh2Double(attributes.getValue(i)); + this->solution_ptr->total_alkalinity = + XMLCh2Double(attributes.getValue(i)); break; //case attSOLN_total_co2: //this->solution_ptr->total_co2 = XMLCh2Double(attributes.getValue(i)); //break; case attSOLN_units: - this->solution_ptr->units = XMLCh_hsave(attributes.getValue(i), TRUE); + this->solution_ptr->units = + XMLCh_hsave(attributes.getValue(i), TRUE); break; case attSOLN_default_pe: - this->solution_ptr->default_pe = XMLCh2Int(attributes.getValue(i)); + this->solution_ptr->default_pe = + XMLCh2Int(attributes.getValue(i)); break; case attSOLN_count_master_activity: - this->solution_ptr->count_master_activity = XMLCh2Int(attributes.getValue(i)); + this->solution_ptr->count_master_activity = + XMLCh2Int(attributes.getValue(i)); break; case attSOLN_count_isotopes: - this->solution_ptr->count_isotopes = XMLCh2Int(attributes.getValue(i)); + this->solution_ptr->count_isotopes = + XMLCh2Int(attributes.getValue(i)); break; case attSOLN_count_species_gamma: - this->solution_ptr->count_species_gamma = XMLCh2Int(attributes.getValue(i)); + this->solution_ptr->count_species_gamma = + XMLCh2Int(attributes.getValue(i)); break; default: ++input_error; @@ -736,9 +963,14 @@ int SaxPhreeqcHandlers::processSolutionAttributes(const xns::Attributes& attribu } return 0; } -int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& attributes, struct conc *c) + +int +SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns:: + Attributes & attributes, + struct conc *c) { - const char ERR_MSG[] = "Unpacking solution totals attributes: %s, attribute not found\n"; + const char ERR_MSG[] = + "Unpacking solution totals attributes: %s, attribute not found\n"; unsigned int i; char *string; conc_init(c); @@ -748,9 +980,11 @@ int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& at // Get attribute name, map to attribute type, process - for (i = 0; i < attributes.getLength(); i++) { + for (i = 0; i < attributes.getLength(); i++) + { attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) { + switch (attType) + { case attCONC_description: c->description = XMLCh_hsave(attributes.getValue(i), TRUE); break; @@ -759,17 +993,17 @@ int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& at break; case attCONC_input_conc: c->input_conc = XMLCh2Double(attributes.getValue(i)); - break; + break; case attCONC_units: c->units = XMLCh_hsave(attributes.getValue(i), TRUE); - break; + break; case attCONC_equation_name: c->equation_name = XMLCh_hsave(attributes.getValue(i), TRUE); c->phase = NULL; break; case attCONC_phase_si: c->phase_si = XMLCh2Double(attributes.getValue(i)); - break; + break; case attCONC_n_pe: c->n_pe = XMLCh2Int(attributes.getValue(i)); break; @@ -778,8 +1012,8 @@ int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& at break; case attCONC_gfw: c->gfw = XMLCh2Double(attributes.getValue(i)); - break; - + break; + default: ++input_error; string = xns::XMLString::transcode(attributes.getLocalName(i)); @@ -789,100 +1023,114 @@ int SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns::Attributes& at break; } } - return(OK); + return (OK); } -int SaxPhreeqcHandlers::processMasterActivityAttributes(const xns::Attributes& attributes, struct master_activity *ma) + +int +SaxPhreeqcHandlers::processMasterActivityAttributes(const xns:: + Attributes & attributes, + struct master_activity + *ma) //int SaxPhreeqcHandlers::processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v) { int i; char *string; - const char ERR_MSG[] = "Unpacking master activity attributes: %s, attribute not found\n"; + const char ERR_MSG[] = + "Unpacking master activity attributes: %s, attribute not found\n"; ma->description = NULL; ma->la = 0.0; attributeType attType; - for (i = 0; i < (int) attributes.getLength(); i++) { + for (i = 0; i < (int) attributes.getLength(); i++) + { attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) { + switch (attType) + { - case attM_A_description: - ma->description = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attM_A_la: - ma->la = XMLCh2Double(attributes.getValue(i)); - break; + case attM_A_description: + ma->description = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attM_A_la: + ma->la = XMLCh2Double(attributes.getValue(i)); + break; /* - case attM_A_list: - { - struct master_activity ma; - xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(attributes.getValue((unsigned int) 0)); - - for ( i = 0; i < arg->size(); i+=2 ) { - ma.description = XMLCh_hsave( arg->elementAt(i), TRUE); - if (strcmp(ma.description, "null") == 0) { - ma.description = NULL; - } - ma.la = XMLCh2Double( arg->elementAt(i+1)); - //this->acts.push_back(ma); - (*v).push_back(ma); - } - } - break; - */ - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } + case attM_A_list: + { + struct master_activity ma; + xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(attributes.getValue((unsigned int) 0)); + + for ( i = 0; i < arg->size(); i+=2 ) { + ma.description = XMLCh_hsave( arg->elementAt(i), TRUE); + if (strcmp(ma.description, "null") == 0) { + ma.description = NULL; + } + ma.la = XMLCh2Double( arg->elementAt(i+1)); + //this->acts.push_back(ma); + (*v).push_back(ma); + } + } + break; + */ + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } } return (OK); } -int SaxPhreeqcHandlers::processIsotopeAttributes(const xns::Attributes& attributes, struct isotope *iso) + +int +SaxPhreeqcHandlers::processIsotopeAttributes(const xns:: + Attributes & attributes, + struct isotope *iso) { int i; char *string; - const char ERR_MSG[] = "Unpacking isotope attributes: %s, attribute not found\n"; + const char ERR_MSG[] = + "Unpacking isotope attributes: %s, attribute not found\n"; iso->primary = iso->master = NULL; iso->elt_name = iso->isotope_name = NULL; attributeType attType; - for (i = 0; i < (int) attributes.getLength(); i++) { + for (i = 0; i < (int) attributes.getLength(); i++) + { attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) { - case attISO_isotope_number: - iso->isotope_number = XMLCh2Int(attributes.getValue(i)); - break; - case attISO_elt_name: - iso->elt_name = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attISO_isotope_name: - iso->isotope_name = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attISO_total: - iso->total = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_ratio: - iso->ratio = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_ratio_uncertainty: - iso->ratio_uncertainty = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_coef: - iso->coef = XMLCh2Double(attributes.getValue(i)); - break; + switch (attType) + { + case attISO_isotope_number: + iso->isotope_number = XMLCh2Int(attributes.getValue(i)); + break; + case attISO_elt_name: + iso->elt_name = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attISO_isotope_name: + iso->isotope_name = XMLCh_hsave(attributes.getValue(i), TRUE); + break; + case attISO_total: + iso->total = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_ratio: + iso->ratio = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_ratio_uncertainty: + iso->ratio_uncertainty = XMLCh2Double(attributes.getValue(i)); + break; + case attISO_coef: + iso->coef = XMLCh2Double(attributes.getValue(i)); + break; - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } + default: + ++input_error; + string = xns::XMLString::transcode(attributes.getLocalName(i)); + sprintf(error_string, ERR_MSG, string); + error_msg(error_string, CONTINUE); + xns::XMLString::release(&string); + break; + } } return (OK); } - diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 4d2144fe..2115b7f8 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -2,206 +2,241 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "SSassemblage.h" #include "SSassemblageSS.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSSassemblage::cxxSSassemblage() - // - // default constructor for cxxSSassemblage - // -: cxxNumKeyword() + // + // default constructor for cxxSSassemblage + // +: cxxNumKeyword() { } -cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage *s_s_assemblage_ptr) - // - // constructor for cxxSSassemblage from struct SSassemblage - // -: -cxxNumKeyword() -{ - int i; - this->set_description(s_s_assemblage_ptr->description); - n_user = s_s_assemblage_ptr->n_user; - n_user_end = s_s_assemblage_ptr->n_user_end; - for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i])); - ssAssemblageSSs.push_back(ssSS); - } -} -cxxSSassemblage::cxxSSassemblage(const std::map &entities, cxxMix &mix, int n_user) +cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr) + // + // constructor for cxxSSassemblage from struct SSassemblage + // : cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - //std::list ssAssemblageSSs; + int i; + this->set_description(s_s_assemblage_ptr->description); + n_user = s_s_assemblage_ptr->n_user; + n_user_end = s_s_assemblage_ptr->n_user_end; + for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) + { + cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i])); + ssAssemblageSSs.push_back(ssSS); + } +} +cxxSSassemblage::cxxSSassemblage(const std::map < int, + cxxSSassemblage > &entities, cxxMix & mix, + int n_user): +cxxNumKeyword() +{ + this->n_user = this->n_user_end = n_user; + //std::list ssAssemblageSSs; // // Mix // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxSSassemblage *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); - } - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxSSassemblage *entity_ptr = + &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } } + cxxSSassemblage::~cxxSSassemblage() { } -struct s_s_assemblage *cxxSSassemblage::cxxSSassemblage2s_s_assemblage() - // - // Builds a s_s_assemblage structure from instance of cxxSSassemblage - // +struct s_s_assemblage * +cxxSSassemblage::cxxSSassemblage2s_s_assemblage() + // + // Builds a s_s_assemblage structure from instance of cxxSSassemblage + // { - struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc(); - - s_s_assemblage_ptr->description = this->get_description(); - s_s_assemblage_ptr->n_user = this->n_user; - s_s_assemblage_ptr->n_user_end = this->n_user_end; - s_s_assemblage_ptr->new_def = FALSE; - s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size(); - s_s_assemblage_ptr->s_s = cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs); - return(s_s_assemblage_ptr); + struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc(); + + s_s_assemblage_ptr->description = this->get_description(); + s_s_assemblage_ptr->n_user = this->n_user; + s_s_assemblage_ptr->n_user_end = this->n_user_end; + s_s_assemblage_ptr->new_def = FALSE; + s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size(); + s_s_assemblage_ptr->s_s = + cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs); + return (s_s_assemblage_ptr); } #ifdef SKIP -void cxxSSassemblage::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // SSassemblage element and attributes - s_oss << indent0; - s_oss << "eltList.dump_xml(s_oss, indent + 1); + // eltList + this->eltList.dump_xml(s_oss, indent + 1); - // ssAssemblageSSs - s_oss << indent1; - s_oss << "::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // ssAssemblageSSs + s_oss << indent1; + s_oss << "::const_iterator it = + ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } } #endif -void cxxSSassemblage::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // SSassemblage element and attributes - s_oss << indent0; - s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this->description << std::endl; + // SSassemblage element and attributes + s_oss << indent0; + s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this-> + description << std::endl; - // ssAssemblageSSs - for (std::list::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { - s_oss << indent1; - s_oss << "-solid_solution" << std::endl; - it->dump_raw(s_oss, indent + 2); - } + // ssAssemblageSSs + for (std::list < cxxSSassemblageSS >::const_iterator it = + ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + { + s_oss << indent1; + s_oss << "-solid_solution" << std::endl; + it->dump_raw(s_oss, indent + 2); + } } -void cxxSSassemblage::read_raw(CParser& parser) +void +cxxSSassemblage::read_raw(CParser & parser) { - static std::vector 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); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("solid_solution"); // 0 + } - // Read SSassemblage number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; + // Read SSassemblage number and description + this->read_number_description(parser); - 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 EQUILIBRIUM_PHASES_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; - case 0: // solid_solution - { - cxxSSassemblageSS ssSS; - ssSS.read_raw(parser); - this->ssAssemblageSSs.push_back(ssSS); - } - useLastLine = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } + 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 EQUILIBRIUM_PHASES_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // solid_solution + { + cxxSSassemblageSS ssSS; + ssSS.read_raw(parser); + this->ssAssemblageSSs.push_back(ssSS); + } + useLastLine = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } } + #ifdef USE_MPI /* ---------------------------------------------------------------------- */ -void cxxSSassemblage::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSSassemblage::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->ssAssemblageSSs.size()); - for (std::list::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) { + for (std::list < cxxSSassemblageSS >::iterator it = + this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); + it++) + { it->mpi_pack(ints, doubles); } } + /* ---------------------------------------------------------------------- */ -void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -213,7 +248,8 @@ void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) int count = ints[i++]; this->ssAssemblageSSs.clear(); - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { cxxSSassemblageSS ssc; ssc.mpi_unpack(ints, &i, doubles, &d); this->ssAssemblageSSs.push_back(ssc); @@ -222,43 +258,51 @@ void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif - -void cxxSSassemblage::totalize() + +void +cxxSSassemblage::totalize() { - this->totals.clear(); - // component structures - for (std::list::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) - { - it->totalize(); - this->totals.add_extensive(it->get_totals(), 1.0); - } - return; + this->totals.clear(); + // component structures + for (std::list < cxxSSassemblageSS >::iterator it = + ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + { + it->totalize(); + this->totals.add_extensive(it->get_totals(), 1.0); + } + return; } -void cxxSSassemblage::add(const cxxSSassemblage &addee, double extensive) - // - // Add to existing ssassemblage to "this" ssassemblage - // +void +cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) + // + // Add to existing ssassemblage to "this" ssassemblage + // { - if (extensive == 0.0) return; + if (extensive == 0.0) + return; - for (std::list::const_iterator itadd = addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); ++itadd) - { - bool found = false; - for (std::list::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); ++it) - { - if (it->get_name() == itadd->get_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) { - cxxSSassemblageSS entity = *itadd; - entity.multiply(extensive); - this->ssAssemblageSSs.push_back(entity); - } - } + for (std::list < cxxSSassemblageSS >::const_iterator itadd = + addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); + ++itadd) + { + bool found = false; + for (std::list < cxxSSassemblageSS >::iterator it = + this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); + ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) + { + cxxSSassemblageSS entity = *itadd; + entity.multiply(extensive); + this->ssAssemblageSSs.push_back(entity); + } + } } - diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index daa9a9cc..c11d4888 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -2,10 +2,10 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "SSassemblageSS.h" #include "NameDouble.h" #include "Dictionary.h" @@ -13,437 +13,492 @@ #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSSassemblageSS::cxxSSassemblageSS() - // - // default constructor for cxxSSassemblageSS - // + // + // default constructor for cxxSSassemblageSS + // { - name = NULL; - //total_moles = 0; - a0 = 0; - a1 = 0; - ag0 = 0; - ag1 = 0; - miscibility = false; - //spinodal = false; - //tk = 25.; - xb1 = 0; - xb2 = 0; - //SS_PARAMETER_TYPE type = SS_PARM_NONE; - //double p[4]; + name = NULL; + //total_moles = 0; + a0 = 0; + a1 = 0; + ag0 = 0; + ag1 = 0; + miscibility = false; + //spinodal = false; + //tk = 25.; + xb1 = 0; + xb2 = 0; + //SS_PARAMETER_TYPE type = SS_PARM_NONE; + //double p[4]; } cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr) - // - // constructor for cxxSSassemblageSS from struct s_s - // - + // + // constructor for cxxSSassemblageSS from struct s_s + // { - name = s_s_ptr->name; - //total_moles = s_s_ptr->total_moles; - a0 = s_s_ptr->a0; - a1 = s_s_ptr->a1; - ag0 = s_s_ptr->ag0; - ag1 = s_s_ptr->ag1; - miscibility = (s_s_ptr->miscibility == TRUE); - //spinodal = (s_s_ptr->spinodal == TRUE); - //tk = s_s_ptr->tk; - xb1 = s_s_ptr->xb1; - xb2 = s_s_ptr->xb2; - //type = s_s_ptr->input_case; - /* - for (i = 0; i < 4; i++) { - p[i] = s_s_ptr->p[i]; - } - */ - int i; - for (i = 0; i < s_s_ptr->count_comps; i++) { - comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles; - } + name = s_s_ptr->name; + //total_moles = s_s_ptr->total_moles; + a0 = s_s_ptr->a0; + a1 = s_s_ptr->a1; + ag0 = s_s_ptr->ag0; + ag1 = s_s_ptr->ag1; + miscibility = (s_s_ptr->miscibility == TRUE); + //spinodal = (s_s_ptr->spinodal == TRUE); + //tk = s_s_ptr->tk; + xb1 = s_s_ptr->xb1; + xb2 = s_s_ptr->xb2; + //type = s_s_ptr->input_case; + /* + for (i = 0; i < 4; i++) { + p[i] = s_s_ptr->p[i]; + } + */ + int i; + for (i = 0; i < s_s_ptr->count_comps; i++) + { + comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles; + } } cxxSSassemblageSS::~cxxSSassemblageSS() { } -struct s_s *cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list& el) - // - // Builds s_s structure from of cxxSSassemblageSS - // +struct s_s * +cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > &el) + // + // Builds s_s structure from of cxxSSassemblageSS + // { - // - // generate s_s structures - // - struct s_s *s_s_ptr = (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); - if (s_s_ptr == NULL) malloc_error(); - int j = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - s_s_ptr[j].name = it->name; - //s_s_ptr[j].total_moles = it->total_moles; - s_s_ptr[j].total_moles = 0; - s_s_ptr[j].dn = 0; - s_s_ptr[j].a0 = it->a0; - s_s_ptr[j].a1 = it->a1; - s_s_ptr[j].ag0 = it->ag0; - s_s_ptr[j].ag1 = it->ag1; - //s_s_ptr[j].ag0 = 0; - //s_s_ptr[j].ag1 = 0; - s_s_ptr[j].s_s_in = TRUE; - s_s_ptr[j].miscibility = it->miscibility; - //s_s_ptr[j].spinodal = it->spinodal; - s_s_ptr[j].spinodal = FALSE; - //s_s_ptr[j].tk = it->tk; - s_s_ptr[j].tk = 273.15; - s_s_ptr[j].xb1 = it->xb1; - s_s_ptr[j].xb2 = it->xb2; - s_s_ptr[j].input_case = 0; - s_s_ptr[j].p[0] = 0; - s_s_ptr[j].p[1] = 0; - s_s_ptr[j].p[2] = 0; - s_s_ptr[j].p[3] = 0; - // - // generate s_s_comp structures - // - s_s_ptr[j].count_comps = (int) it->comps.size(); - s_s_ptr[j].comps = NULL; - if (it->comps.size() > 0) { - int i = 0; - int n; - struct s_s_comp *s_s_comp_ptr = (struct s_s_comp *) PHRQ_malloc((size_t) (it->comps.size() * sizeof(struct s_s_comp))); - if (s_s_comp_ptr == NULL) malloc_error(); - for (cxxNameDouble::iterator itc = it->comps.begin(); itc != it->comps.end(); ++ itc) { - s_s_comp_ptr[i].name = itc->first; - s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE); - s_s_comp_ptr[i].initial_moles = 0; - s_s_comp_ptr[i].moles = itc->second; - s_s_comp_ptr[i].init_moles = 0; - s_s_comp_ptr[i].delta = 0; - s_s_comp_ptr[i].fraction_x = 0; - s_s_comp_ptr[i].log10_lambda = 0; - s_s_comp_ptr[i].log10_fraction_x = 0; - s_s_comp_ptr[i].dn = 0; - s_s_comp_ptr[i].dnc = 0; - s_s_comp_ptr[i].dnb = 0; - i++; - } - s_s_ptr[j].comps = s_s_comp_ptr; - } - j++; - } - return(s_s_ptr); + // + // generate s_s structures + // + struct s_s *s_s_ptr = + (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); + if (s_s_ptr == NULL) + malloc_error(); + int j = 0; + for (std::list < cxxSSassemblageSS >::iterator it = el.begin(); + it != el.end(); ++it) + { + s_s_ptr[j].name = it->name; + //s_s_ptr[j].total_moles = it->total_moles; + s_s_ptr[j].total_moles = 0; + s_s_ptr[j].dn = 0; + s_s_ptr[j].a0 = it->a0; + s_s_ptr[j].a1 = it->a1; + s_s_ptr[j].ag0 = it->ag0; + s_s_ptr[j].ag1 = it->ag1; + //s_s_ptr[j].ag0 = 0; + //s_s_ptr[j].ag1 = 0; + s_s_ptr[j].s_s_in = TRUE; + s_s_ptr[j].miscibility = it->miscibility; + //s_s_ptr[j].spinodal = it->spinodal; + s_s_ptr[j].spinodal = FALSE; + //s_s_ptr[j].tk = it->tk; + s_s_ptr[j].tk = 273.15; + s_s_ptr[j].xb1 = it->xb1; + s_s_ptr[j].xb2 = it->xb2; + s_s_ptr[j].input_case = 0; + s_s_ptr[j].p[0] = 0; + s_s_ptr[j].p[1] = 0; + s_s_ptr[j].p[2] = 0; + s_s_ptr[j].p[3] = 0; + // + // generate s_s_comp structures + // + s_s_ptr[j].count_comps = (int) it->comps.size(); + s_s_ptr[j].comps = NULL; + if (it->comps.size() > 0) + { + int i = 0; + int n; + struct s_s_comp *s_s_comp_ptr = + (struct s_s_comp *) + PHRQ_malloc((size_t) + (it->comps.size() * sizeof(struct s_s_comp))); + if (s_s_comp_ptr == NULL) + malloc_error(); + for (cxxNameDouble::iterator itc = it->comps.begin(); + itc != it->comps.end(); ++itc) + { + s_s_comp_ptr[i].name = itc->first; + s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE); + s_s_comp_ptr[i].initial_moles = 0; + s_s_comp_ptr[i].moles = itc->second; + s_s_comp_ptr[i].init_moles = 0; + s_s_comp_ptr[i].delta = 0; + s_s_comp_ptr[i].fraction_x = 0; + s_s_comp_ptr[i].log10_lambda = 0; + s_s_comp_ptr[i].log10_fraction_x = 0; + s_s_comp_ptr[i].dn = 0; + s_s_comp_ptr[i].dnc = 0; + s_s_comp_ptr[i].dnb = 0; + i++; + } + s_s_ptr[j].comps = s_s_comp_ptr; + } + j++; + } + return (s_s_ptr); } #ifdef SKIP -void cxxSSassemblageSS::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // S_S element and attributes + // S_S element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; - s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << std::endl; - s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; - s_oss << indent0 << "initial_moles=\"" << this->initial_moles << "\"" << std::endl; - s_oss << indent0 << "dissolve_only=\"" << this->dissolve_only << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "add_formula=\"" << this-> + add_formula << "\"" << std::endl; + s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + s_oss << indent0 << "initial_moles=\"" << this-> + initial_moles << "\"" << std::endl; + s_oss << indent0 << "dissolve_only=\"" << this-> + dissolve_only << "\"" << std::endl; } #endif -void cxxSSassemblageSS::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); - // S_S element and attributes + // S_S element and attributes - s_oss << indent0 << "-name " << this->name << std::endl; - //s_oss << indent0 << "-total_moles " << this->total_moles << std::endl; - s_oss << indent0 << "-a0 " << this->a0 << std::endl; - s_oss << indent0 << "-a1 " << this->a1 << std::endl; - s_oss << indent0 << "-ag0 " << this->ag0 << std::endl; - s_oss << indent0 << "-ag1 " << this->ag1 << std::endl; - s_oss << indent0 << "-miscibility " << this->miscibility << std::endl; - //s_oss << indent0 << "-spinodal " << this->spinodal << std::endl; - //s_oss << indent0 << "-tk " << this->tk << std::endl; - s_oss << indent0 << "-xb1 " << this->xb1 << std::endl; - s_oss << indent0 << "-xb2 " << this->xb2 << std::endl; - s_oss << indent0 << "-component " << std::endl; - this->comps.dump_raw(s_oss, indent + 1); + s_oss << indent0 << "-name " << this->name << std::endl; + //s_oss << indent0 << "-total_moles " << this->total_moles << std::endl; + s_oss << indent0 << "-a0 " << this->a0 << std::endl; + s_oss << indent0 << "-a1 " << this->a1 << std::endl; + s_oss << indent0 << "-ag0 " << this->ag0 << std::endl; + s_oss << indent0 << "-ag1 " << this->ag1 << std::endl; + s_oss << indent0 << "-miscibility " << this-> + miscibility << std::endl; + //s_oss << indent0 << "-spinodal " << this->spinodal << std::endl; + //s_oss << indent0 << "-tk " << this->tk << std::endl; + s_oss << indent0 << "-xb1 " << this->xb1 << std::endl; + s_oss << indent0 << "-xb2 " << this->xb2 << std::endl; + s_oss << indent0 << "-component " << std::endl; + this->comps.dump_raw(s_oss, indent + 1); } -void cxxSSassemblageSS::read_raw(CParser& parser) +void +cxxSSassemblageSS::read_raw(CParser & parser) { - std::string str; - - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("name"); // 0 - vopts.push_back("total_moles"); // 1 - vopts.push_back("a0"); // 2 - vopts.push_back("a1"); // 3 - vopts.push_back("components"); // 4 - vopts.push_back("miscibility"); // 5 - vopts.push_back("spinodal"); // 6 - vopts.push_back("tk"); // 7 - vopts.push_back("xb1"); // 8 - vopts.push_back("xb2"); // 9 - vopts.push_back("ag0"); // 10 - vopts.push_back("ag1"); // 11 - } + std::string str; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("total_moles"); // 1 + vopts.push_back("a0"); // 2 + vopts.push_back("a1"); // 3 + vopts.push_back("components"); // 4 + vopts.push_back("miscibility"); // 5 + vopts.push_back("spinodal"); // 6 + vopts.push_back("tk"); // 7 + vopts.push_back("xb1"); // 8 + vopts.push_back("xb2"); // 9 + vopts.push_back("ag0"); // 10 + vopts.push_back("ag1"); // 11 + } - opt_save = CParser::OPT_ERROR; - bool name_defined(false); - //bool total_moles_defined(false); - bool a0_defined(false); - bool a1_defined(false); - bool ag0_defined(false); - bool ag1_defined(false); - bool miscibility_defined(false); - //bool spinodal_defined(false); - //bool tk_defined(false); - bool xb1_defined(false); - bool xb2_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + //bool total_moles_defined(false); + bool a0_defined(false); + bool a1_defined(false); + bool ag0_defined(false); + bool ag1_defined(false); + bool miscibility_defined(false); + //bool spinodal_defined(false); + //bool tk_defined(false); + bool xb1_defined(false); + bool xb2_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); - } else { - this->name = string_hsave(str.c_str()); - } - name_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + 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.", CParser::OT_CONTINUE); - } - total_moles_defined = true; - */ - opt_save = CParser::OPT_DEFAULT; - break; + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", + CParser::OT_CONTINUE); + } + else + { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; - case 2: // a0 - if (!(parser.get_iss() >> this->a0)) - { - this->a0 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for a0.", CParser::OT_CONTINUE); - } - a0_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 3: // a1 - if (!(parser.get_iss() >> this->a1)) - { - this->a1 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for a1.", CParser::OT_CONTINUE); - } - a1_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 4: // components - if ( this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected phase name and moles for comps.", CParser::OT_CONTINUE); - } - opt_save = 4; - break; - - case 5: // miscibility - if (!(parser.get_iss() >> this->miscibility)) - { - this->miscibility = 0; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for miscibility.", CParser::OT_CONTINUE); - } - miscibility_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 6: // spinodal + case 1: // total_moles /* - if (!(parser.get_iss() >> this->spinodal)) - { - this->spinodal = 0; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for spinodal.", CParser::OT_CONTINUE); - } - spinodal_defined = true; - */ - opt_save = CParser::OPT_DEFAULT; - break; + if (!(parser.get_iss() >> this->total_moles)) + { + this->total_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total_moles.", CParser::OT_CONTINUE); + } + total_moles_defined = true; + */ + opt_save = CParser::OPT_DEFAULT; + break; - case 7: // tk + case 2: // a0 + if (!(parser.get_iss() >> this->a0)) + { + this->a0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for a0.", + CParser::OT_CONTINUE); + } + a0_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 3: // a1 + if (!(parser.get_iss() >> this->a1)) + { + this->a1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for a1.", + CParser::OT_CONTINUE); + } + a1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 4: // components + if (this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser.error_msg("Expected phase name and moles for comps.", + CParser::OT_CONTINUE); + } + opt_save = 4; + break; + + case 5: // miscibility + if (!(parser.get_iss() >> this->miscibility)) + { + this->miscibility = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for miscibility.", + CParser::OT_CONTINUE); + } + miscibility_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 6: // spinodal /* - if (!(parser.get_iss() >> this->tk)) - { - this->tk = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for tk.", CParser::OT_CONTINUE); - } - tk_defined = true; - */ - opt_save = CParser::OPT_DEFAULT; - break; + if (!(parser.get_iss() >> this->spinodal)) + { + this->spinodal = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for spinodal.", CParser::OT_CONTINUE); + } + spinodal_defined = true; + */ + opt_save = CParser::OPT_DEFAULT; + break; - case 8: // xb1 - if (!(parser.get_iss() >> this->xb1)) - { - this->xb1 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for xb1.", CParser::OT_CONTINUE); - } - xb1_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.", CParser::OT_CONTINUE); + } + tk_defined = true; + */ + opt_save = CParser::OPT_DEFAULT; + break; - case 9: // xb2 - if (!(parser.get_iss() >> this->xb2)) - { - this->xb2 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for xb2.", CParser::OT_CONTINUE); - } - xb2_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; + case 8: // xb1 + if (!(parser.get_iss() >> this->xb1)) + { + this->xb1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for xb1.", + CParser::OT_CONTINUE); + } + xb1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; - case 10: // ag0 - if (!(parser.get_iss() >> this->ag0)) - { - this->ag0 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for ag0.", CParser::OT_CONTINUE); - } - ag0_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; + case 9: // xb2 + if (!(parser.get_iss() >> this->xb2)) + { + this->xb2 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for xb2.", + CParser::OT_CONTINUE); + } + xb2_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; - case 11: // ag1 - if (!(parser.get_iss() >> this->ag1)) - { - this->ag1 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for ag1.", CParser::OT_CONTINUE); - } - ag1_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; + case 10: // ag0 + if (!(parser.get_iss() >> this->ag0)) + { + this->ag0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ag0.", + CParser::OT_CONTINUE); + } + ag0_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 11: // ag1 + if (!(parser.get_iss() >> this->ag1)) + { + this->ag1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ag1.", + CParser::OT_CONTINUE); + } + ag1_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (name_defined == false) { - parser.incr_input_error(); - parser.error_msg("Name not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - /* - if (total_moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - */ - if (a0_defined == false) { - parser.incr_input_error(); - parser.error_msg("A0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (a1_defined == false) { - parser.incr_input_error(); - parser.error_msg("A1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (ag0_defined == false) { - parser.incr_input_error(); - parser.error_msg("Ag0 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (ag1_defined == false) { - parser.incr_input_error(); - parser.error_msg("Ag1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (miscibility_defined == false) { - parser.incr_input_error(); - parser.error_msg("Miscibility not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } /* - if (spinodal_defined == false) { - parser.incr_input_error(); - parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (tk_defined == false) { - parser.incr_input_error(); - parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - */ - if (xb1_defined == false) { - parser.incr_input_error(); - parser.error_msg("Xb1 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (xb2_defined == false) { - parser.incr_input_error(); - parser.error_msg("Xb2 not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } + if (total_moles_defined == false) { + parser.incr_input_error(); + parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (a0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("A0 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (a1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("A1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (ag0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ag0 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (ag1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ag1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (miscibility_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Miscibility not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + /* + if (spinodal_defined == false) { + parser.incr_input_error(); + parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (tk_defined == false) { + parser.incr_input_error(); + parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (xb1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Xb1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (xb2_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Xb2 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } } #ifdef USE_MPI -void cxxSSassemblageSS::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSSassemblageSS::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->name)); @@ -456,7 +511,9 @@ void cxxSSassemblageSS::mpi_pack(std::vector& ints, std::vector& do doubles.push_back(this->xb1); doubles.push_back(this->xb2); } -void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -475,50 +532,57 @@ void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif -void cxxSSassemblageSS::totalize() +void +cxxSSassemblageSS::totalize() { - this->totals.clear(); - // component structures - for (cxxNameDouble::const_iterator it = this->comps.begin(); it != this->comps.end(); it++) { - struct phase *phase_ptr; - int l; - phase_ptr = phase_bsearch(it->first, &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, it->second); - } else - { - assert(false); - } - } - return; + this->totals.clear(); + // component structures + for (cxxNameDouble::const_iterator it = this->comps.begin(); + it != this->comps.end(); it++) + { + struct phase *phase_ptr; + int l; + phase_ptr = phase_bsearch(it->first, &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, it->second); + } + else + { + assert(false); + } + } + return; } -void cxxSSassemblageSS::add(const cxxSSassemblageSS &addee, double extensive) +void +cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive) { - if (extensive == 0.0) return; - if (addee.name == NULL) return; - // this and addee must have same name - // otherwise generate a new PPassemblagComp with multiply + if (extensive == 0.0) + return; + if (addee.name == NULL) + return; + // this and addee must have same name + // otherwise generate a new PPassemblagComp with multiply - //char *name; - //cxxNameDouble comps; - this->comps.add_extensive(addee.comps, extensive); - //double a0, a1; - //double ag0, ag1; - //bool miscibility; - //double xb1, xb2; + //char *name; + //cxxNameDouble comps; + this->comps.add_extensive(addee.comps, extensive); + //double a0, a1; + //double ag0, ag1; + //bool miscibility; + //double xb1, xb2; } -void cxxSSassemblageSS::multiply(double extensive) +void +cxxSSassemblageSS::multiply(double extensive) { - //char *name; - //cxxNameDouble comps; - this->comps.multiply(extensive); - //double a0, a1; - //double ag0, ag1; - //bool miscibility; - //double xb1, xb2; + //char *name; + //cxxNameDouble comps; + this->comps.multiply(extensive); + //double a0, a1; + //double ag0, ag1; + //bool miscibility; + //double xb1, xb2; } - diff --git a/Solution.cxx b/Solution.cxx index 00b22849..16ede052 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -2,21 +2,21 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #ifdef USE_MPI //MPICH seems to require mpi.h to be first - #include +#include #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "Solution.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// @@ -25,1074 +25,1217 @@ cxxSolution::cxxSolution() - // - // default constructor for cxxSolution - // -: cxxNumKeyword() + // + // default constructor for cxxSolution + // +: cxxNumKeyword() { - this->tc = 25.0; - this->ph = 7.0; - this->pe = 4.0; - this->mu = 1e-7; - this->ah2o = 1.0; - this->total_h = 111.1; - this->total_o = 55.55; - this->cb = 0.0; - this->mass_water = 1.0; - this->total_alkalinity = 0.0; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + this->tc = 25.0; + this->ph = 7.0; + this->pe = 4.0; + this->mu = 1e-7; + this->ah2o = 1.0; + this->total_h = 111.1; + this->total_o = 55.55; + this->cb = 0.0; + this->mass_water = 1.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } -cxxSolution::cxxSolution(struct solution *solution_ptr) - // - // constructor for cxxSolution from struct solution - // -: + +cxxSolution::cxxSolution(struct solution * solution_ptr) + // + // constructor for cxxSolution from struct solution + // +: cxxNumKeyword(), totals(solution_ptr->totals), -master_activity(solution_ptr->master_activity, solution_ptr->count_master_activity, cxxNameDouble::ND_SPECIES_LA), -species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA), -isotopes(solution_ptr) +master_activity(solution_ptr->master_activity, + solution_ptr->count_master_activity, + cxxNameDouble::ND_SPECIES_LA), +species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, + cxxNameDouble::ND_SPECIES_GAMMA), isotopes(solution_ptr) { - this->set_description(solution_ptr->description); - this->n_user = solution_ptr->n_user; - this->n_user_end = solution_ptr->n_user_end; - this->tc = solution_ptr->tc; - this->ph = solution_ptr->ph; - this->pe = solution_ptr->solution_pe; - this->mu = solution_ptr->mu; - this->ah2o = solution_ptr->ah2o; - this->total_h = solution_ptr->total_h; - this->total_o = solution_ptr->total_o; - this->cb = solution_ptr->cb; - this->mass_water = solution_ptr->mass_water; - this->total_alkalinity = solution_ptr->total_alkalinity; + this->set_description(solution_ptr->description); + this->n_user = solution_ptr->n_user; + this->n_user_end = solution_ptr->n_user_end; + this->tc = solution_ptr->tc; + this->ph = solution_ptr->ph; + this->pe = solution_ptr->solution_pe; + this->mu = solution_ptr->mu; + this->ah2o = solution_ptr->ah2o; + this->total_h = solution_ptr->total_h; + this->total_o = solution_ptr->total_o; + this->cb = solution_ptr->cb; + this->mass_water = solution_ptr->mass_water; + this->total_alkalinity = solution_ptr->total_alkalinity; - // Totals filled in constructor, just save description and moles + // Totals filled in constructor, just save description and moles - // Isotopes + // Isotopes /* - for (i = 0; i < solution_ptr->count_isotopes; i++) { - cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); - isotopes.push_back(iso); - } - */ - // Master_activity in constructor - // Species_gamma in constructor + for (i = 0; i < solution_ptr->count_isotopes; i++) { + cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); + isotopes.push_back(iso); + } + */ + // Master_activity in constructor + // Species_gamma in constructor } -cxxSolution::cxxSolution( const std::map& solutions, cxxMix &mix, int n_user) +cxxSolution::cxxSolution(const std::map < int, cxxSolution > &solutions, + cxxMix & mix, int n_user) // // constructor for cxxSolution from mixture of solutions // -: + : cxxNumKeyword() { // // Zero out solution data // - this->zero(); - this->n_user = this->n_user_end = n_user; + this->zero(); + this->n_user = this->n_user_end = n_user; // // Mix solutions // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - std::map::const_iterator sol = solutions.find(it->first); - if (sol == solutions.end()) - { - sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); - error_msg(error_string, CONTINUE); - input_error++; - } else - { - const cxxSolution *cxxsoln_ptr1 = &(sol->second); - this->add(*cxxsoln_ptr1, it->second); - } - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + std::map < int, cxxSolution >::const_iterator sol = + solutions.find(it->first); + if (sol == solutions.end()) + { + sprintf(error_string, + "Solution %d not found in mix_cxxSolutions.", it->first); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + const cxxSolution *cxxsoln_ptr1 = &(sol->second); + this->add(*cxxsoln_ptr1, it->second); + } + } } cxxSolution::cxxSolution(int n_user) - // - // constructor for cxxSolution from results of calculation - // does not work in phast because phast uses only the total molalities - // of elements in buffer, not individual redox states. -: + // + // constructor for cxxSolution from results of calculation + // does not work in phast because phast uses only the total molalities + // of elements in buffer, not individual redox states. + : cxxNumKeyword() { - //this->set_description none; - this->n_user = n_user; - this->n_user_end = n_user; - this->tc = tc_x; - this->ph = ph_x; - this->pe = solution_pe_x; - this->mu = mu_x; - this->ah2o = ah2o_x; - this->total_h = total_h_x; - this->total_o = total_o_x; - this->cb = cb_x; - this->mass_water = mass_water_aq_x; - this->total_alkalinity = ::total_alkalinity; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; - /* - * Add in minor isotopes if initial solution calculation - */ - int i; - if (initial_solution_isotopes == TRUE) - { - struct master *master_ptr, *master_i_ptr; - for (i = 0; i < count_master_isotope; i++) - { - if (master_isotope[i]->moles > 0) - { - master_i_ptr = master_bsearch (master_isotope[i]->name); - master_ptr = master_isotope[i]->elt->master; - if (master_isotope[i]->minor_isotope == TRUE) + //this->set_description none; + this->n_user = n_user; + this->n_user_end = n_user; + this->tc = tc_x; + this->ph = ph_x; + this->pe = solution_pe_x; + this->mu = mu_x; + this->ah2o = ah2o_x; + this->total_h = total_h_x; + this->total_o = total_o_x; + this->cb = cb_x; + this->mass_water = mass_water_aq_x; + this->total_alkalinity =::total_alkalinity; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + /* + * Add in minor isotopes if initial solution calculation + */ + int i; + if (initial_solution_isotopes == TRUE) { - master_i_ptr->total = master_isotope[i]->moles; - if (master_ptr->total > 0) - { - master_i_ptr->s->la = - master_ptr->s->la + - log10 (master_i_ptr->total / master_ptr->total); - } - else - { - master_i_ptr->s->la = master_ptr->s->la; - } + struct master *master_ptr, *master_i_ptr; + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->moles > 0) + { + master_i_ptr = master_bsearch(master_isotope[i]->name); + master_ptr = master_isotope[i]->elt->master; + if (master_isotope[i]->minor_isotope == TRUE) + { + master_i_ptr->total = master_isotope[i]->moles; + if (master_ptr->total > 0) + { + master_i_ptr->s->la = + master_ptr->s->la + + log10(master_i_ptr->total / master_ptr->total); + } + else + { + master_i_ptr->s->la = master_ptr->s->la; + } + } + else if (master_isotope[i]->minor_isotope == FALSE + && master_ptr->s != s_hplus + && master_ptr->s != s_h2o) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr->s->secondary->total = + master_isotope[i]->moles; + } + else + { + master_ptr->s->primary->total = + master_isotope[i]->moles; + } + } + } + } } - else if (master_isotope[i]->minor_isotope == FALSE - && master_ptr->s != s_hplus && master_ptr->s != s_h2o) - { - if (master_ptr->s->secondary != NULL) - { - master_ptr->s->secondary->total = master_isotope[i]->moles; - } - else - { - master_ptr->s->primary->total = master_isotope[i]->moles; - } - } - } - } - } - /* - cxxNameDouble totals; - cxxNameDouble master_activity; - cxxNameDouble species_gamma; - cxxSolutionIsotopeList isotopes; - */ + /* + cxxNameDouble totals; + cxxNameDouble master_activity; + cxxNameDouble species_gamma; + cxxSolutionIsotopeList isotopes; + */ // totals and master_activity - for (i = 0; i < count_master; i++) - { - if (master[i]->s->type == EX || - master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) - continue; - if (master[i]->s == s_hplus) continue; - if (master[i]->s == s_h2o) continue; - if (master[i]->in != FALSE) - { - this->master_activity[master[i]->elt->name] = master[i]->s->la; - } - if (master[i]->total <= MIN_TOTAL) - { - master[i]->total = 0.0; - master[i]->total_primary = 0.0; - continue; - } - this->totals[master[i]->elt->name] = master[i]->total; - } + for (i = 0; i < count_master; i++) + { + if (master[i]->s->type == EX || + master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + continue; + if (master[i]->s == s_hplus) + continue; + if (master[i]->s == s_h2o) + continue; + if (master[i]->in != FALSE) + { + this->master_activity[master[i]->elt->name] = master[i]->s->la; + } + if (master[i]->total <= MIN_TOTAL) + { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + continue; + } + this->totals[master[i]->elt->name] = master[i]->total; + } // species_gammas for Pitzer - if (pitzer_model == TRUE) - { - int j; - for (j = 0; j < count_s; j++) - { - if (s[j]->lg != 0.0) - { - this->species_gamma[s[j]->name] = s[j]->lg; - } - } - } + if (pitzer_model == TRUE) + { + int j; + for (j = 0; j < count_s; j++) + { + if (s[j]->lg != 0.0) + { + this->species_gamma[s[j]->name] = s[j]->lg; + } + } + } // Save isotope data - if (count_isotopes_x > 0) - { - for (i = 0; i < count_isotopes_x; i++) - { - cxxSolutionIsotope cxxiso; - cxxiso.set_isotope_number (isotopes_x[i].isotope_number); - cxxiso.set_elt_name (isotopes_x[i].elt_name); - cxxiso.set_isotope_name (isotopes_x[i].isotope_name); - cxxiso.set_total (isotopes_x[i].master->total); - if (isotopes_x[i].master == s_hplus->secondary) - { - cxxiso.set_total (2 * mass_water_aq_x / gfw_water); - } - if (isotopes_x[i].master == s_h2o->secondary) - { - cxxiso.set_total (mass_water_aq_x / gfw_water); - } - // cxxiso.ratio - // cxxiso.ratio_uncertainty - // cxxiso.ratio_uncertainty_defined - this->isotopes.push_back(cxxiso); - } - } + if (count_isotopes_x > 0) + { + for (i = 0; i < count_isotopes_x; i++) + { + cxxSolutionIsotope cxxiso; + cxxiso.set_isotope_number(isotopes_x[i].isotope_number); + cxxiso.set_elt_name(isotopes_x[i].elt_name); + cxxiso.set_isotope_name(isotopes_x[i].isotope_name); + cxxiso.set_total(isotopes_x[i].master->total); + if (isotopes_x[i].master == s_hplus->secondary) + { + cxxiso.set_total(2 * mass_water_aq_x / gfw_water); + } + if (isotopes_x[i].master == s_h2o->secondary) + { + cxxiso.set_total(mass_water_aq_x / gfw_water); + } + // cxxiso.ratio + // cxxiso.ratio_uncertainty + // cxxiso.ratio_uncertainty_defined + this->isotopes.push_back(cxxiso); + } + } } + cxxSolution::~cxxSolution() { } -struct solution *cxxSolution::cxxSolution2solution() - // - // Builds a solution structure from instance of cxxSolution - // +struct solution * +cxxSolution::cxxSolution2solution() + // + // Builds a solution structure from instance of cxxSolution + // { - struct solution *solution_ptr = solution_alloc(); - - solution_ptr->description = this->get_description(); - solution_ptr->n_user = this->n_user; - solution_ptr->n_user_end = this->n_user_end; - solution_ptr->new_def = FALSE; - solution_ptr->tc = this->tc; - solution_ptr->ph = this->ph; - solution_ptr->solution_pe = this->pe; - solution_ptr->mu = this->mu; - solution_ptr->ah2o = this->ah2o; - solution_ptr->total_h = this->total_h; - solution_ptr->total_o = this->total_o; - solution_ptr->cb = this->cb; - solution_ptr->mass_water = this->mass_water; - solution_ptr->total_alkalinity = this->total_alkalinity; - solution_ptr->density = 1.0; - solution_ptr->units = moles_per_kilogram_string; - solution_ptr->default_pe = 0; - // pe_data + struct solution *solution_ptr = solution_alloc(); - // totals - solution_ptr->totals = (struct conc *) free_check_null(solution_ptr->totals); - solution_ptr->totals = this->totals.conc(); + solution_ptr->description = this->get_description(); + solution_ptr->n_user = this->n_user; + solution_ptr->n_user_end = this->n_user_end; + solution_ptr->new_def = FALSE; + solution_ptr->tc = this->tc; + solution_ptr->ph = this->ph; + solution_ptr->solution_pe = this->pe; + solution_ptr->mu = this->mu; + solution_ptr->ah2o = this->ah2o; + solution_ptr->total_h = this->total_h; + solution_ptr->total_o = this->total_o; + solution_ptr->cb = this->cb; + solution_ptr->mass_water = this->mass_water; + solution_ptr->total_alkalinity = this->total_alkalinity; + solution_ptr->density = 1.0; + solution_ptr->units = moles_per_kilogram_string; + solution_ptr->default_pe = 0; + // pe_data - // master_activity - solution_ptr->master_activity = (struct master_activity *) free_check_null(solution_ptr->master_activity); - solution_ptr->master_activity = this->master_activity.master_activity(); - solution_ptr->count_master_activity = (int) this->master_activity.size() + 1; + // totals + solution_ptr->totals = + (struct conc *) free_check_null(solution_ptr->totals); + solution_ptr->totals = this->totals.conc(); - // species_gamma - solution_ptr->species_gamma = this->species_gamma.master_activity(); - solution_ptr->count_species_gamma = (int) this->species_gamma.size(); + // master_activity + solution_ptr->master_activity = + (struct master_activity *) free_check_null(solution_ptr-> + master_activity); + solution_ptr->master_activity = this->master_activity.master_activity(); + solution_ptr->count_master_activity = + (int) this->master_activity.size() + 1; - // isotopes - solution_ptr->isotopes = (struct isotope *) free_check_null(solution_ptr->isotopes); - //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); + // species_gamma + solution_ptr->species_gamma = this->species_gamma.master_activity(); + solution_ptr->count_species_gamma = (int) this->species_gamma.size(); + + // isotopes + solution_ptr->isotopes = + (struct isotope *) free_check_null(solution_ptr->isotopes); + //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(); - solution_ptr->count_isotopes = (int) this->isotopes.size(); + solution_ptr->count_isotopes = (int) this->isotopes.size(); - return(solution_ptr); + return (solution_ptr); } -void cxxSolution::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); - // Solution element and attributes - s_oss << indent0; - s_oss << "new_def << "\"" << std::endl; + //s_oss << indent1; + //s_oss << "soln_new_def=\"" << this->new_def << "\"" << std::endl; - s_oss << indent1; - s_oss << "soln_n_user=\"" << this->n_user << "\" " << std::endl; - - s_oss << indent1; - s_oss << "soln_description=\"" << this->description << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_tc=\"" << this->tc << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_ph=\"" << this->ph << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_solution_pe=\"" << this->pe << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_mu=\"" << this->mu << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_ah2o=\"" << this->ah2o << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_total_h=\"" << this->total_h << "\"" << std::endl; - - s_oss << indent1; - s_oss << "soln_total_o=\"" << this->total_o << "\"" << std::endl; - s_oss << indent1; - s_oss << "soln_cb=\"" << this->cb << "\"" << std::endl; + s_oss << "soln_n_user=\"" << this->n_user << "\" " << std::endl; - s_oss << indent1; - s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << std::endl; + s_oss << indent1; + s_oss << "soln_description=\"" << this->description << "\"" << std::endl; - s_oss << indent1; - s_oss << "soln_total_alkalinity=\"" << this->total_alkalinity << "\"" << std::endl; + s_oss << indent1; + s_oss << "soln_tc=\"" << this->tc << "\"" << std::endl; - s_oss << indent1; - s_oss << "\">" << std::endl; + s_oss << indent1; + s_oss << "soln_ph=\"" << this->ph << "\"" << std::endl; - // soln_total conc structures - this->totals.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\""; - s_oss << " conc_moles=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; - } - } - */ - // master_activity map - this->master_activity.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\"" ; - s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; - } - } - */ - // species_gamma map - this->species_gamma.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\"" ; - s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; - } - } - */ + s_oss << indent1; + s_oss << "soln_solution_pe=\"" << this->pe << "\"" << std::endl; - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_xml(s_oss, indent + 1); - } + s_oss << indent1; + s_oss << "soln_mu=\"" << this->mu << "\"" << std::endl; - // End of solution - s_oss << indent0; - s_oss << "" << std::endl; + s_oss << indent1; + s_oss << "soln_ah2o=\"" << this->ah2o << "\"" << std::endl; - return; -} + s_oss << indent1; + s_oss << "soln_total_h=\"" << this->total_h << "\"" << std::endl; -void cxxSolution::dump_raw(std::ostream& s_oss, unsigned int indent)const -{ - //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + s_oss << indent1; + s_oss << "soln_total_o=\"" << this->total_o << "\"" << std::endl; - // Solution element and attributes - s_oss << indent0; - s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + s_oss << indent1; + s_oss << "soln_cb=\"" << this->cb << "\"" << std::endl; - s_oss << indent1; - s_oss << "-temp " << this->tc << std::endl; + s_oss << indent1; + s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << std::endl; - s_oss << indent1; - s_oss << "-pH " << this->ph << std::endl; + s_oss << indent1; + s_oss << "soln_total_alkalinity=\"" << this-> + total_alkalinity << "\"" << std::endl; - s_oss << indent1; - s_oss << "-pe " << this->pe << std::endl; + s_oss << indent1; + s_oss << "\">" << std::endl; - // new identifier - s_oss << indent1; - s_oss << "-mu " << this->mu << std::endl; + // soln_total conc structures + this->totals.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\""; + s_oss << " conc_moles=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ + // master_activity map + this->master_activity.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\"" ; + s_oss << " m_a_la=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ + // species_gamma map + this->species_gamma.dump_xml(s_oss, indent + 1); + /* + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent1; + s_oss << "first << "\"" ; + s_oss << " m_a_la=\"" << it->second << "\"" ; + s_oss << "\">" << std::endl; + } + } + */ - // new identifier - s_oss << indent1; - s_oss << "-ah2o " << this->ah2o << std::endl; + for (std::list < cxxSolutionIsotope >::const_iterator it = + this->isotopes.begin(); it != isotopes.end(); ++it) + { + it->dump_xml(s_oss, indent + 1); + } - // new identifier - s_oss << indent1; - s_oss << "-total_h " << this->total_h << std::endl; + // End of solution + s_oss << indent0; + s_oss << "" << std::endl; - // new identifier - s_oss << indent1; - s_oss << "-total_o " << this->total_o << std::endl; - - // new identifier - s_oss << indent1; - s_oss << "-cb " << this->cb << std::endl; - - // new identifier - s_oss << indent1; - s_oss << "-mass_water " << this->mass_water << std::endl; - - // new identifier - s_oss << indent1; - s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - - // soln_total conc structures - s_oss << indent1; - s_oss << "-totals" << std::endl; - this->totals.dump_raw(s_oss, indent + 2); - /* - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - */ - - // master_activity map - s_oss << indent1; - s_oss << "-activities" << std::endl; - this->master_activity.dump_raw(s_oss, indent + 2); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - */ - // species_gamma map - s_oss << indent1; - s_oss << "-gammas" << std::endl; - this->species_gamma.dump_raw(s_oss, indent + 2); - /* - { - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - } - */ - // Isotopes - s_oss << indent1; - s_oss << "-Isotopes" << std::endl; - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - - return; -} -void cxxSolution::read_raw(CParser& parser) -{ - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(21); - vopts.push_back("totals"); // 0 - vopts.push_back("activities"); // 1 - vopts.push_back("gammas"); // 2 - vopts.push_back("isotopes"); // 3 - vopts.push_back("temp"); // 4 - vopts.push_back("tc"); // 5 - vopts.push_back("temperature"); // 6 - vopts.push_back("ph"); // 7 - vopts.push_back("pe"); // 8 - vopts.push_back("mu"); // 9 - vopts.push_back("ionic_strength"); // 10 - vopts.push_back("ah2o"); // 11 - vopts.push_back("activity_water"); // 12 - vopts.push_back("total_h"); // 13 - vopts.push_back("total_o"); // 14 - vopts.push_back("mass_water"); // 15 - vopts.push_back("mass_h2o"); // 16 - vopts.push_back("total_alkalinity"); // 17 - vopts.push_back("total_alk"); // 18 - vopts.push_back("cb"); // 19 - vopts.push_back("charge_balance"); // 20 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - - // Read solution number and description - this->read_number_description(parser); - - opt_save = CParser::OPT_ERROR; - bool tc_defined(false); - bool ph_defined(false); - bool pe_defined(false); - bool mu_defined(false); - bool ah2o_defined(false); - bool total_h_defined(false); - bool total_o_defined(false); - bool cb_defined(false); - bool mass_water_defined(false); - bool total_alkalinity_defined(false); - - for (;;) - { - int opt = parser.get_option(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 SOLUTION_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - continue; - - case 0: // totals - if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and moles for totals.", CParser::OT_CONTINUE); - } - opt_save = 0; - break; - - case 1: // activities - if ( this->master_activity.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected species name and log activity for activities.", CParser::OT_CONTINUE); - } - opt_save = 1; - break; - - case 2: // gammas - if ( this->species_gamma.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected species name and activity coefficient for gammas.", CParser::OT_CONTINUE); - } - opt_save = 2; - break; - - case 3: // isotopes - { - cxxSolutionIsotope iso; - if ( iso.read_raw(parser) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected data for isotopes.", CParser::OT_CONTINUE); - } else { - if (iso.get_isotope_name() != NULL) { - this->isotopes.push_back(iso); - } - } - } - opt_save = 3; - break; - - case 4: // temp - case 5: // tc - case 6: // temperature - if (!(parser.get_iss() >> this->tc)) - { - this->tc = 25.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for temperature.", CParser::OT_CONTINUE); - } - tc_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 7: // ph - if (!(parser.get_iss() >> this->ph)) - { - this->ph = 7.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for pH.", CParser::OT_CONTINUE); - } - ph_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 8: // pe - if (!(parser.get_iss() >> this->pe)) - { - this->pe = 4.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for pe.", CParser::OT_CONTINUE); - } - pe_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 9: // mu - case 10: // ionic_strength - if (!(parser.get_iss() >> this->mu)) - { - this->mu = 1e-7; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for ionic strength.", CParser::OT_CONTINUE); - } - mu_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 11: // ah2o - case 12: // activity_water - if (!(parser.get_iss() >> this->ah2o)) - { - this->ah2o = 1.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for activity of water.", CParser::OT_CONTINUE); - } - ah2o_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 13: // total_h - if (!(parser.get_iss() >> this->total_h)) - { - this->total_h = 111.1; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for total hydrogen.", CParser::OT_CONTINUE); - } - total_h_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 14: // total_o - if (!(parser.get_iss() >> this->total_o)) - { - this->total_o = 55.55; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for total oxygen.", CParser::OT_CONTINUE); - } - total_o_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 15: // mass_water - case 16: // mass_h2o - if (!(parser.get_iss() >> this->mass_water)) - { - this->mass_water = 1.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water.", CParser::OT_CONTINUE); - } - mass_water_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 17: // total_alkalinity - case 18: // total_alk - if (!(parser.get_iss() >> this->total_alkalinity)) - { - this->total_alkalinity = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for total_alkalinity.", CParser::OT_CONTINUE); - } - total_alkalinity_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - case 19: // cb - case 20: // charge_balance - if (!(parser.get_iss() >> this->cb)) - { - this->cb = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for charge balance.", CParser::OT_CONTINUE); - } - cb_defined = true; - opt_save = CParser::OPT_DEFAULT; - break; - - } - - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // all members must be defined - if (tc_defined == false) { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (ph_defined == false) { - parser.incr_input_error(); - parser.error_msg("pH not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (pe_defined == false) { - parser.incr_input_error(); - parser.error_msg("pe not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (mu_defined == false) { - parser.incr_input_error(); - parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (ah2o_defined == false) { - parser.incr_input_error(); - parser.error_msg("Activity of water not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (total_h_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (total_o_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (cb_defined == false) { - parser.incr_input_error(); - parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (mass_water_defined == false) { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } - if (total_alkalinity_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total alkalinity not defined for SOLUTION_RAW input.", CParser::OT_CONTINUE); - } return; } -void cxxSolution::zero() +void +cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - this->tc = 0.0; - this->ph = 0.0; - this->pe = 0.0; - this->mu = 0.0; - this->ah2o = 0.0; - this->total_h = 0.0; - this->total_o = 0.0; - this->cb = 0.0; - this->mass_water = 0.0; - this->total_alkalinity = 0.0; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + // Solution element and attributes + s_oss << indent0; + s_oss << "SOLUTION_RAW " << this->n_user << " " << this-> + description << std::endl; + + s_oss << indent1; + s_oss << "-temp " << this->tc << std::endl; + + s_oss << indent1; + s_oss << "-pH " << this->ph << std::endl; + + s_oss << indent1; + s_oss << "-pe " << this->pe << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-mu " << this->mu << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-ah2o " << this->ah2o << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_h " << this->total_h << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_o " << this->total_o << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-cb " << this->cb << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-mass_water " << this->mass_water << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + + // soln_total conc structures + s_oss << indent1; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 2); + /* + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + */ + + // master_activity map + s_oss << indent1; + s_oss << "-activities" << std::endl; + this->master_activity.dump_raw(s_oss, indent + 2); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + */ + // species_gamma map + s_oss << indent1; + s_oss << "-gammas" << std::endl; + this->species_gamma.dump_raw(s_oss, indent + 2); + /* + { + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + } + */ + // Isotopes + s_oss << indent1; + s_oss << "-Isotopes" << std::endl; + { + for (std::list < cxxSolutionIsotope >::const_iterator it = + this->isotopes.begin(); it != isotopes.end(); ++it) + { + it->dump_raw(s_oss, indent + 2); + } + } + + return; } -void cxxSolution::add(const cxxSolution &addee, double extensive) - // - // Add existing solution to "this" solution - // +void +cxxSolution::read_raw(CParser & parser) { - if (extensive == 0.0) return; - double ext1 = this->mass_water; - double ext2 = addee.mass_water * extensive; - double f1 = ext1/(ext1 + ext2); - double f2 = ext2/(ext1 + ext2); - this->tc = f1*this->tc + f2*addee.tc; - this->ph = f1*this->ph + f2*addee.ph; - this->pe = f1*this->pe + f2*addee.pe; - this->mu = f1*this->mu + f2*addee.mu; - this->ah2o = f1*this->mu + f2*addee.ah2o; - this->total_h += addee.total_h * extensive; - this->total_o += addee.total_o * extensive; - this->cb += addee.cb * extensive; - this->mass_water += addee.mass_water * extensive; - this->total_alkalinity += addee.total_alkalinity * extensive; - this->totals.add_extensive(addee.totals, extensive); - this->master_activity.add_log_activities(addee.master_activity, f1, f2); - this->species_gamma.add_intensive(addee.species_gamma, f1, f2); - this->isotopes.add(addee.isotopes, f2, extensive); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(21); + vopts.push_back("totals"); // 0 + vopts.push_back("activities"); // 1 + vopts.push_back("gammas"); // 2 + vopts.push_back("isotopes"); // 3 + vopts.push_back("temp"); // 4 + vopts.push_back("tc"); // 5 + vopts.push_back("temperature"); // 6 + vopts.push_back("ph"); // 7 + vopts.push_back("pe"); // 8 + vopts.push_back("mu"); // 9 + vopts.push_back("ionic_strength"); // 10 + vopts.push_back("ah2o"); // 11 + vopts.push_back("activity_water"); // 12 + vopts.push_back("total_h"); // 13 + vopts.push_back("total_o"); // 14 + vopts.push_back("mass_water"); // 15 + vopts.push_back("mass_h2o"); // 16 + vopts.push_back("total_alkalinity"); // 17 + vopts.push_back("total_alk"); // 18 + vopts.push_back("cb"); // 19 + vopts.push_back("charge_balance"); // 20 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + // Read solution number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool tc_defined(false); + bool ph_defined(false); + bool pe_defined(false); + bool mu_defined(false); + bool ah2o_defined(false); + bool total_h_defined(false); + bool total_o_defined(false); + bool cb_defined(false); + bool mass_water_defined(false); + bool total_alkalinity_defined(false); + + for (;;) + { + int opt = parser.get_option(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 SOLUTION_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + continue; + + case 0: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg("Expected element name and moles for totals.", + CParser::OT_CONTINUE); + } + opt_save = 0; + break; + + case 1: // activities + if (this->master_activity.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected species name and log activity for activities.", + CParser::OT_CONTINUE); + } + opt_save = 1; + break; + + case 2: // gammas + if (this->species_gamma.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected species name and activity coefficient for gammas.", + CParser::OT_CONTINUE); + } + opt_save = 2; + break; + + case 3: // isotopes + { + cxxSolutionIsotope iso; + if (iso.read_raw(parser) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser.error_msg("Expected data for isotopes.", + CParser::OT_CONTINUE); + } + else + { + if (iso.get_isotope_name() != NULL) + { + this->isotopes.push_back(iso); + } + } + } + opt_save = 3; + break; + + case 4: // temp + case 5: // tc + case 6: // temperature + if (!(parser.get_iss() >> this->tc)) + { + this->tc = 25.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for temperature.", + CParser::OT_CONTINUE); + } + tc_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 7: // ph + if (!(parser.get_iss() >> this->ph)) + { + this->ph = 7.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pH.", + CParser::OT_CONTINUE); + } + ph_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 8: // pe + if (!(parser.get_iss() >> this->pe)) + { + this->pe = 4.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pe.", + CParser::OT_CONTINUE); + } + pe_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 9: // mu + case 10: // ionic_strength + if (!(parser.get_iss() >> this->mu)) + { + this->mu = 1e-7; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ionic strength.", + CParser::OT_CONTINUE); + } + mu_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 11: // ah2o + case 12: // activity_water + if (!(parser.get_iss() >> this->ah2o)) + { + this->ah2o = 1.0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for activity of water.", + CParser::OT_CONTINUE); + } + ah2o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 13: // total_h + if (!(parser.get_iss() >> this->total_h)) + { + this->total_h = 111.1; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total hydrogen.", + CParser::OT_CONTINUE); + } + total_h_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 14: // total_o + if (!(parser.get_iss() >> this->total_o)) + { + this->total_o = 55.55; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total oxygen.", + CParser::OT_CONTINUE); + } + total_o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 15: // mass_water + case 16: // mass_h2o + if (!(parser.get_iss() >> this->mass_water)) + { + this->mass_water = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water.", + CParser::OT_CONTINUE); + } + mass_water_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 17: // total_alkalinity + case 18: // total_alk + if (!(parser.get_iss() >> this->total_alkalinity)) + { + this->total_alkalinity = 0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for total_alkalinity.", + CParser::OT_CONTINUE); + } + total_alkalinity_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 19: // cb + case 20: // charge_balance + if (!(parser.get_iss() >> this->cb)) + { + this->cb = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge balance.", + CParser::OT_CONTINUE); + } + cb_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // all members must be defined + if (tc_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ph_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pH not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (pe_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pe not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mu_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ah2o_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Activity of water not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_h_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_o_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (cb_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_alkalinity_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Total alkalinity not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + return; } -void cxxSolution::multiply(double extensive) - // - // Multiply existing solution by extensive - // + +void +cxxSolution::zero() { - if (extensive == 0.0 || extensive == 1.0) return; - this->total_h *= extensive; - this->total_o *= extensive; - this->cb *= extensive; - this->mass_water *= extensive; - this->total_alkalinity *= extensive; - this->totals.multiply(extensive); - this->isotopes.multiply(extensive); + this->tc = 0.0; + this->ph = 0.0; + this->pe = 0.0; + this->mu = 0.0; + this->ah2o = 0.0; + this->total_h = 0.0; + this->total_o = 0.0; + this->cb = 0.0; + this->mass_water = 0.0; + this->total_alkalinity = 0.0; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; + this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } -double cxxSolution::get_total(char *string)const + +void +cxxSolution::add(const cxxSolution & addee, double extensive) + // + // Add existing solution to "this" solution + // +{ + if (extensive == 0.0) + return; + double ext1 = this->mass_water; + double ext2 = addee.mass_water * extensive; + double f1 = ext1 / (ext1 + ext2); + double f2 = ext2 / (ext1 + ext2); + this->tc = f1 * this->tc + f2 * addee.tc; + this->ph = f1 * this->ph + f2 * addee.ph; + this->pe = f1 * this->pe + f2 * addee.pe; + this->mu = f1 * this->mu + f2 * addee.mu; + this->ah2o = f1 * this->mu + f2 * addee.ah2o; + this->total_h += addee.total_h * extensive; + this->total_o += addee.total_o * extensive; + this->cb += addee.cb * extensive; + this->mass_water += addee.mass_water * extensive; + this->total_alkalinity += addee.total_alkalinity * extensive; + this->totals.add_extensive(addee.totals, extensive); + this->master_activity.add_log_activities(addee.master_activity, f1, f2); + this->species_gamma.add_intensive(addee.species_gamma, f1, f2); + this->isotopes.add(addee.isotopes, f2, extensive); +} + +void +cxxSolution::multiply(double extensive) + // + // Multiply existing solution by extensive + // +{ + if (extensive == 0.0 || extensive == 1.0) + return; + this->total_h *= extensive; + this->total_o *= extensive; + this->cb *= extensive; + this->mass_water *= extensive; + this->total_alkalinity *= extensive; + this->totals.multiply(extensive); + this->isotopes.multiply(extensive); +} + +double +cxxSolution::get_total(char *string) const const { cxxNameDouble::const_iterator it = this->totals.find(string); - if (it == this->totals.end()) { - return(0.0); - } else { - return(it->second); + if (it == this->totals.end()) + { + return (0.0); + } + else + { + return (it->second); } } -double cxxSolution::get_total_element(char *string)const +double +cxxSolution::get_total_element(char *string) const const { - cxxNameDouble::const_iterator it; - double d = 0.0; - for (it = this->totals.begin(); it != this->totals.end(); ++it) - { - char token[MAX_LENGTH]; - if (it->first[0] == string[0]) - { - strcpy(token, it->first); - replace("(", "\0", token); - if (strcmp(token, string) == 0) - { - d += it->second; - } - } + cxxNameDouble::const_iterator it; + double d = 0.0; + for (it = this->totals.begin(); it != this->totals.end(); ++it) + { + char token[MAX_LENGTH]; + if (it->first[0] == string[0]) + { + strcpy(token, it->first); + replace("(", "\0", token); + if (strcmp(token, string) == 0) + { + d += it->second; + } + } #ifdef SKIP - // C++ way to do it - std::string ename(string); - std::string current_ename(it->first); - std::basic_string ::size_type indexCh; - indexCh = current_ename.find("("); - if (indexCh != std::string::npos) - { - current_ename = current_ename.substr(0, indexCh); - } - if (current_ename == ename) - { - d += it->second; - } + // C++ way to do it + std::string ename(string); + std::string current_ename(it->first); + std::basic_string < char >::size_type indexCh; + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + if (current_ename == ename) + { + d += it->second; + } #endif - } - return(d); + } + return (d); } -void cxxSolution::set_total(char *string, double d) + +void +cxxSolution::set_total(char *string, double d) { this->totals[string] = d; } -double cxxSolution::get_master_activity(char *string)const +double +cxxSolution::get_master_activity(char *string) const const { cxxNameDouble::const_iterator it = this->master_activity.find(string); - if (it == this->master_activity.end()) { - return(0.0); - } else { - return(it->second); + if (it == this->master_activity.end()) + { + return (0.0); + } + else + { + return (it->second); } } #ifdef ORCHESTRA -void cxxSolution::ORCH_write(std::ostream& headings, std::ostream& data)const +void +cxxSolution::ORCH_write(std::ostream & headings, std::ostream & data) const const { - data.precision(DBL_DIG - 1); + data.precision(DBL_DIG - 1); - // Solution element and attributes + // Solution element and attributes - //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; + //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; - //s_oss << "-temp " << this->tc << std::endl; + //s_oss << "-temp " << this->tc << std::endl; - //s_oss << "-pH " << this->ph << std::endl; - headings << "pH\t"; - data << this->ph << "\t"; + //s_oss << "-pH " << this->ph << std::endl; + headings << "pH\t"; + data << this->ph << "\t"; - //s_oss << "-pe " << this->pe << std::endl; - headings << "pe\t"; - data << this->pe << "\t"; + //s_oss << "-pe " << this->pe << std::endl; + headings << "pe\t"; + data << this->pe << "\t"; - //s_oss << "-mu " << this->mu << std::endl; + //s_oss << "-mu " << this->mu << std::endl; - //s_oss << "-ah2o " << this->ah2o << std::endl; - headings << "H2O.act\t"; - data << 1 << "\t"; - //s_oss << "-total_h " << this->total_h << std::endl; + //s_oss << "-ah2o " << this->ah2o << std::endl; + headings << "H2O.act\t"; + data << 1 << "\t"; + //s_oss << "-total_h " << this->total_h << std::endl; - //s_oss << "-total_o " << this->total_o << std::endl; + //s_oss << "-total_o " << this->total_o << std::endl; - //s_oss << "-cb " << this->cb << std::endl; + //s_oss << "-cb " << this->cb << std::endl; - //s_oss << "-mass_water " << this->mass_water << std::endl; + //s_oss << "-mass_water " << this->mass_water << std::endl; - //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - // soln_total conc structures - //this->totals.dump_raw(s_oss, indent + 2); - //this->totals.write_orchestra(headings, s_oss); - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) - { - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch (it->first); - if (master_ptr != NULL) - { - //headings << it->first << ".tot" << "\t"; - headings << master_ptr->s->name << ".diss" << "\t"; - data << it->second << "\t"; - } else - { - assert(false); - } - } + // soln_total conc structures + //this->totals.dump_raw(s_oss, indent + 2); + //this->totals.write_orchestra(headings, s_oss); + for (std::map < char *, double, CHARSTAR_LESS >::const_iterator it = + totals.begin(); it != totals.end(); ++it) + { + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch(it->first); + if (master_ptr != NULL) + { + //headings << it->first << ".tot" << "\t"; + headings << master_ptr->s->name << ".diss" << "\t"; + data << it->second << "\t"; + } + else + { + assert(false); + } + } - // master_activity map - //this->master_activity.dump_raw(s_oss, indent + 2); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - */ - // species_gamma map - //this->species_gamma.dump_raw(s_oss, indent + 2); - /* - { - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - } - */ - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ + // master_activity map + //this->master_activity.dump_raw(s_oss, indent + 2); + /* + { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + */ + // species_gamma map + //this->species_gamma.dump_raw(s_oss, indent + 2); + /* + { + { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + } + } + */ + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ - return; + return; } -void cxxSolution::ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it) +void +cxxSolution::ORCH_read(std::vector < std::pair < std::string, + double >>output_vector, + std::vector < std::pair < std::string, + double >>::iterator & it) { - this->tc = it->second; it++; - this->ph = it->second; it++; - this->pe = it->second; it++; - this->mu = it->second; it++; - this->ah2o = it->second; it++; - this->total_h = it->second; it++; - this->total_o = it->second; it++; - this->cb = it->second; it++; - this->mass_water = it->second * gfw_water; it++; - this->mass_water = 1.0; - this->total_alkalinity = it->second; it++; - it++; //orch total H+ - it++; //orch total e- - it++; //orch total H2O - //cxxNameDouble totals; - char token[MAX_LENGTH]; - while (it->first.compare("end_totals") != 0) - { - strcpy(token, it->first.c_str()); - replace(".diss","",token); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); - if (s_ptr->secondary != NULL) - { - this->totals[s_ptr->secondary->elt->name] = it->second; - } else if (s_ptr->primary != NULL) - { - this->totals[s_ptr->primary->elt->name] = it->second; - } else - { - error_msg("Species not secondary or primary master species in orchestra read", STOP); - } - it++; - } - //cxxNameDouble master_activity; - it++; - while (it->first.compare("end_master_activities") != 0) - { - strcpy(token, it->first.c_str()); - replace(".act","",token); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); - if (s_ptr->secondary != NULL) - { - this->master_activity[s_ptr->secondary->elt->name] = log10(it->second); - } else if (s_ptr->primary != NULL) - { - this->master_activity[s_ptr->primary->elt->name] = log10(it->second); - } else - { - error_msg("Species not secondary or primary master species in orchestra read", STOP); - } - it++; - } - //cxxNameDouble species_gamma; - //cxxSolutionIsotopeList isotopes; - // - // Also process aqueous species data - // - it++; - while (it->first.compare("end_species") != 0) - { - strcpy(token, it->first.c_str()); - replace(".act","",token); - while (replace("[","(", token)); - while (replace("]",")", token)); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) error_msg("Species not found in orchestra read", STOP); - s_ptr->la = log10(it->second); it++; - s_ptr->moles = it->second * this->mass_water; - s_ptr->lm = log10(it->second); it++; - s_ptr->lg = s_ptr->la - s_ptr->lm; - } + this->tc = it->second; + it++; + this->ph = it->second; + it++; + this->pe = it->second; + it++; + this->mu = it->second; + it++; + this->ah2o = it->second; + it++; + this->total_h = it->second; + it++; + this->total_o = it->second; + it++; + this->cb = it->second; + it++; + this->mass_water = it->second * gfw_water; + it++; + this->mass_water = 1.0; + this->total_alkalinity = it->second; + it++; + it++; //orch total H+ + it++; //orch total e- + it++; //orch total H2O + //cxxNameDouble totals; + char token[MAX_LENGTH]; + while (it->first.compare("end_totals") != 0) + { + strcpy(token, it->first.c_str()); + replace(".diss", "", token); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) + error_msg("Species not found in orchestra read", STOP); + if (s_ptr->secondary != NULL) + { + this->totals[s_ptr->secondary->elt->name] = it->second; + } + else if (s_ptr->primary != NULL) + { + this->totals[s_ptr->primary->elt->name] = it->second; + } + else + { + error_msg + ("Species not secondary or primary master species in orchestra read", + STOP); + } + it++; + } + //cxxNameDouble master_activity; + it++; + while (it->first.compare("end_master_activities") != 0) + { + strcpy(token, it->first.c_str()); + replace(".act", "", token); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) + error_msg("Species not found in orchestra read", STOP); + if (s_ptr->secondary != NULL) + { + this->master_activity[s_ptr->secondary->elt->name] = + log10(it->second); + } + else if (s_ptr->primary != NULL) + { + this->master_activity[s_ptr->primary->elt->name] = + log10(it->second); + } + else + { + error_msg + ("Species not secondary or primary master species in orchestra read", + STOP); + } + it++; + } + //cxxNameDouble species_gamma; + //cxxSolutionIsotopeList isotopes; + // + // Also process aqueous species data + // + it++; + while (it->first.compare("end_species") != 0) + { + strcpy(token, it->first.c_str()); + replace(".act", "", token); + while (replace("[", "(", token)); + while (replace("]", ")", token)); + struct species *s_ptr = s_search(token); + if (s_ptr == NULL) + error_msg("Species not found in orchestra read", STOP); + s_ptr->la = log10(it->second); + it++; + s_ptr->moles = it->second * this->mass_water; + s_ptr->lm = log10(it->second); + it++; + s_ptr->lg = s_ptr->la - s_ptr->lm; + } } -void cxxSolution::ORCH_store_global(std::map < std::string, double > output_map) +void +cxxSolution::ORCH_store_global(std::map < std::string, double >output_map) { - int i; - tc_x = this->tc; - mass_water_aq_x = this->mass_water; - mu_x = this->mu; - s_h2o->moles = output_map["H2O.con"]; - s_h2o->la = log10(output_map["H2O.act"]); - s_h2o->lm = s_h2o->la; - s_h2o->lg = 0; - for (i = 0; i < count_unknowns; i++) - { - residual[i] = 0; - // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O - switch (x[i]->type) - { - case MB: - case CB: - case SOLUTION_PHASE_BOUNDARY: - x[i]->sum = this->totals[x[i]->description]*mass_water_aq_x; - break; - case ALK: - x[i]->f = this->total_alkalinity*mass_water_aq_x; - break; - } - } + int i; + tc_x = this->tc; + mass_water_aq_x = this->mass_water; + mu_x = this->mu; + s_h2o->moles = output_map["H2O.con"]; + s_h2o->la = log10(output_map["H2O.act"]); + s_h2o->lm = s_h2o->la; + s_h2o->lg = 0; + for (i = 0; i < count_unknowns; i++) + { + residual[i] = 0; + // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O + switch (x[i]->type) + { + case MB: + case CB: + case SOLUTION_PHASE_BOUNDARY: + x[i]->sum = this->totals[x[i]->description] * mass_water_aq_x; + break; + case ALK: + x[i]->f = this->total_alkalinity * mass_water_aq_x; + break; + } + } } #endif #ifdef USE_MPI /* ---------------------------------------------------------------------- */ -void cxxSolution::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSolution::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ { /* @@ -1125,29 +1268,31 @@ void cxxSolution::mpi_pack(std::vector& ints, std::vector& doubles) this->species_gamma.mpi_pack(ints, doubles); /* - position = 0; - int i = ints.size(); - int int_array[i]; - int d = doubles.size(); - double double_array[d]; - for (int j = 0; j < i; j++) { - int_array[j] = ints[j]; - } - for (int j = 0; j < d; j++) { - double_array[j] = ints[j]; - } - MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); - MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); + position = 0; + int i = ints.size(); + int int_array[i]; + int d = doubles.size(); + double double_array[d]; + for (int j = 0; j < i; j++) { + int_array[j] = ints[j]; + } + for (int j = 0; j < d; j++) { + double_array[j] = ints[j]; + } + MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); + MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); - buffer = (void *) free_check_null(buffer); - */ + buffer = (void *) free_check_null(buffer); + */ } + /* ---------------------------------------------------------------------- */ -void cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -1181,8 +1326,10 @@ void cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *ii = i; *dd = d; } + /* ---------------------------------------------------------------------- */ -void cxxSolution::mpi_send(int task_number) +void +cxxSolution::mpi_send(int task_number) /* ---------------------------------------------------------------------- */ { //int count_totals, count_totals_position, count_activity, count_activity_position; @@ -1190,16 +1337,16 @@ void cxxSolution::mpi_send(int task_number) //int ints[MESSAGE_MAX_NUMBERS]; //double doubles[MESSAGE_MAX_NUMBERS]; void *buffer; - std::vector ints; - std::vector doubles; + std::vector < int >ints; + std::vector < double >doubles; /* * Make list of list of ints and doubles from solution structure * This list is not the complete structure, but only enough * for batch-reaction, advection, and transport calculations */ ints.push_back(this->n_user); - /* int n_user_end; */ - /* char *description; */ + /* int n_user_end; */ + /* char *description; */ doubles.push_back(this->tc); doubles.push_back(this->ph); doubles.push_back(this->pe); @@ -1223,9 +1370,10 @@ void cxxSolution::mpi_send(int task_number) */ this->species_gamma.mpi_pack(ints, doubles); - /* int count_isotopes; */ - /* struct isotope *isotopes; */ - if (input_error > 0) { + /* int count_isotopes; */ + /* struct isotope *isotopes; */ + if (input_error > 0) + { std::string errstr("Stopping due to errors\n"); error_msg(errstr.c_str(), STOP); } @@ -1237,10 +1385,12 @@ void cxxSolution::mpi_send(int task_number) MPI_Pack_size((int) ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); max_size += member_size; //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_DOUBLE, MPI_COMM_WORLD, &member_size); - MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, + &member_size); max_size += member_size + 10; buffer = PHRQ_malloc(max_size); - if (buffer == NULL) malloc_error(); + if (buffer == NULL) + malloc_error(); /* * Send message to processor */ @@ -1249,26 +1399,32 @@ void cxxSolution::mpi_send(int task_number) int *int_array = new int[i]; int d = (int) doubles.size(); double *double_array = new double[d]; - for (int j = 0; j < i; j++) { + for (int j = 0; j < i; j++) + { int_array[j] = ints[j]; } - for (int j = 0; j < d; j++) { + for (int j = 0; j < d; j++) + { double_array[j] = doubles[j]; } MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, + MPI_COMM_WORLD); MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, + MPI_COMM_WORLD); MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); - delete[] int_array; - delete[] double_array; + delete[]int_array; + delete[]double_array; } + /* ---------------------------------------------------------------------- */ -void cxxSolution::mpi_recv(int task_number) +void +cxxSolution::mpi_recv(int task_number) /* ---------------------------------------------------------------------- */ { MPI_Status mpi_status; @@ -1276,30 +1432,37 @@ void cxxSolution::mpi_recv(int task_number) * Malloc space for a buffer */ int max_size; - // buffer size + // buffer size - MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); + MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, + &mpi_status); void *buffer = PHRQ_malloc(max_size); - if (buffer == NULL) malloc_error(); + if (buffer == NULL) + malloc_error(); /* * Recieve solution */ - MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status); - int position = 0; + MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, + &mpi_status); + int position = 0; int msg_size; - MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); + MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); /* Unpack ints */ int count_ints; - MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, + MPI_COMM_WORLD); int *ints = new int[count_ints]; - MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, + MPI_COMM_WORLD); /* Unpack doubles */ int count_doubles; - MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, + MPI_COMM_WORLD); double *doubles = new double[count_doubles]; - MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, + MPI_DOUBLE, MPI_COMM_WORLD); buffer = free_check_null(buffer); /* * Make list of list of ints and doubles from solution structure @@ -1308,14 +1471,14 @@ void cxxSolution::mpi_recv(int task_number) */ int i = 0; int d = 0; - /* int new_def; */ + /* int new_def; */ /* solution_ptr->new_def = FALSE; */ - /* int n_user; */ + /* int n_user; */ this->n_user = ints[i++]; - /* int n_user_end; */ + /* int n_user_end; */ this->n_user_end = this->n_user; - /*debugging*/ + /*debugging */ //this->description = (char *) free_check_null(this->description); //this->description = string_duplicate(" "); this->description = " "; @@ -1341,11 +1504,12 @@ void cxxSolution::mpi_recv(int task_number) * struct master_activity *species_gamma; */ this->species_gamma.mpi_unpack(ints, &i, doubles, &d); - delete[] ints; - delete[] doubles; + delete[]ints; + delete[]doubles; } #endif -void cxxSolution::set_master_activity(char *string, double d) +void +cxxSolution::set_master_activity(char *string, double d) { this->master_activity[string] = d; } @@ -1361,162 +1525,178 @@ void cxxSolution::set_master_activity(char *string, double d) #include "Temperature.h" #include "StorageBin.h" #include "NumKeyword.h" -#include // std::cout std::cerr +#include // std::cout std::cerr //#include #include #include -void test_classes(void) +void +test_classes(void) { - - int i; + + int i; /* - std::map Solutions; - cxxSolution soln(solution[0]); - Solutions[solution[0]->n_user] = soln; - bool b = Utilities::exists(Solutions, 1); - */ + std::map Solutions; + cxxSolution soln(solution[0]); + Solutions[solution[0]->n_user] = soln; + bool b = Utilities::exists(Solutions, 1); + */ /* - cxxEntityMap x; - cxxSolution soln(solution[0]); - cxxNumKeyword nk; - x[solution[0]->n_user] = soln; - */ + cxxEntityMap x; + cxxSolution soln(solution[0]); + cxxNumKeyword nk; + x[solution[0]->n_user] = soln; + */ std::ostringstream msg; status_on = FALSE; std::cout << std::endl << "TEST CLASSES" << std::endl; - for (i=0; i < count_solution; i++) { - if (solution[i]->new_def == TRUE) { - std::cout << "Solution new_def " << solution[i]->n_user << std::endl; - cxxISolution sol(solution[i]); - solution_free(solution[i]); - solution[i] = NULL; - solution[i] = sol.cxxISolution2solution(); - struct solution *soln_ptr; - soln_ptr = solution[i]; - soln_ptr = solution[i]; - } else { + for (i = 0; i < count_solution; i++) + { + if (solution[i]->new_def == TRUE) + { + std::cout << "Solution new_def " << solution[i]-> + n_user << std::endl; + cxxISolution sol(solution[i]); + solution_free(solution[i]); + solution[i] = NULL; + solution[i] = sol.cxxISolution2solution(); + struct solution *soln_ptr; + soln_ptr = solution[i]; + soln_ptr = solution[i]; + } + else + { std::cout << "Solution " << solution[i]->n_user << std::endl; - std::ostringstream oss; - cxxSolution sol(solution[i]); - solution_free(solution[i]); - solution[i] = NULL; - sol.dump_raw(oss, 0); + std::ostringstream oss; + cxxSolution sol(solution[i]); + solution_free(solution[i]); + solution[i] = NULL; + sol.dump_raw(oss, 0); - //std::fstream myfile("t"); - //CParser cparser(myfile, std::cout, std::cerr); - cxxSolution sol1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); + //std::fstream myfile("t"); + //CParser cparser(myfile, std::cout, std::cerr); + cxxSolution sol1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); - sol1.read_raw(cparser); + sol1.read_raw(cparser); - solution[i] = sol1.cxxSolution2solution(); - } - } - for (i=0; i < count_exchange; i++) { - if (exchange[i].new_def != TRUE) { + solution[i] = sol1.cxxSolution2solution(); + } + } + for (i = 0; i < count_exchange; i++) + { + if (exchange[i].new_def != TRUE) + { std::cout << "Exchange " << exchange[i].n_user << std::endl; - std::ostringstream oss; - cxxExchange ex(&(exchange[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); + std::ostringstream oss; + cxxExchange ex(&(exchange[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); - cxxExchange ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); + cxxExchange ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); - ex1.read_raw(cparser); + ex1.read_raw(cparser); - struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); - exchange_free(&exchange[i]); - exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); - exchange_free(exchange_ptr); - free_check_null(exchange_ptr); - } - } - for (i=0; i < count_surface; i++) { - if (surface[i].new_def != TRUE) { + struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); + exchange_free(&exchange[i]); + exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); + exchange_free(exchange_ptr); + free_check_null(exchange_ptr); + } + } + for (i = 0; i < count_surface; i++) + { + if (surface[i].new_def != TRUE) + { std::cout << "Surface " << surface[i].n_user << std::endl; - std::ostringstream oss; - cxxSurface ex(&(surface[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); + std::ostringstream oss; + cxxSurface ex(&(surface[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); - cxxSurface ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); + cxxSurface ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); - ex1.read_raw(cparser); + ex1.read_raw(cparser); - struct surface *surface_ptr = ex1.cxxSurface2surface(); - surface_free(&surface[i]); - surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); - surface_free(surface_ptr); - free_check_null(surface_ptr); + struct surface *surface_ptr = ex1.cxxSurface2surface(); + surface_free(&surface[i]); + surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); + surface_free(surface_ptr); + free_check_null(surface_ptr); - } + } - } - for (i=0; i < count_pp_assemblage; i++) { - if (pp_assemblage[i].new_def != TRUE) { - std::cout << "PPassemblage " << pp_assemblage[i].n_user << std::endl; - std::ostringstream oss; - cxxPPassemblage ex(&(pp_assemblage[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); + } + for (i = 0; i < count_pp_assemblage; i++) + { + if (pp_assemblage[i].new_def != TRUE) + { + std::cout << "PPassemblage " << pp_assemblage[i]. + n_user << std::endl; + std::ostringstream oss; + cxxPPassemblage ex(&(pp_assemblage[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); - cxxPPassemblage ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); + cxxPPassemblage ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); - ex1.read_raw(cparser); + ex1.read_raw(cparser); - struct pp_assemblage *pp_assemblage_ptr = ex1.cxxPPassemblage2pp_assemblage(); - pp_assemblage_free(&pp_assemblage[i]); - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], pp_assemblage_ptr->n_user); - pp_assemblage_free(pp_assemblage_ptr); - free_check_null(pp_assemblage_ptr); + struct pp_assemblage *pp_assemblage_ptr = + ex1.cxxPPassemblage2pp_assemblage(); + pp_assemblage_free(&pp_assemblage[i]); + pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], + pp_assemblage_ptr->n_user); + pp_assemblage_free(pp_assemblage_ptr); + free_check_null(pp_assemblage_ptr); - } + } - } - for (i=0; i < count_kinetics; i++) { + } + for (i = 0; i < count_kinetics; i++) + { std::cout << "Kinetics " << kinetics[i].n_user << std::endl; std::ostringstream oss; cxxKinetics ex(&(kinetics[i])); ex.dump_raw(oss, 0); //std::cerr << oss.str(); - + cxxKinetics ex1; std::string keyInput = oss.str(); @@ -1524,7 +1704,7 @@ void test_classes(void) CParser cparser(iss, oss, std::cerr); //For testing, need to read line to get started - std::vector vopts; + std::vector < std::string > vopts; std::istream::pos_type next_char; cparser.get_option(vopts, next_char); @@ -1536,179 +1716,191 @@ void test_classes(void) kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); kinetics_free(kinetics_ptr); free_check_null(kinetics_ptr); - } - for (i=0; i < count_s_s_assemblage; i++) { - if (s_s_assemblage[i].new_def != TRUE) { - std::cout << "Solid solution " << s_s_assemblage[i].n_user << std::endl; - std::ostringstream oss; - cxxSSassemblage ex(&(s_s_assemblage[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxSSassemblage ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct s_s_assemblage *s_s_assemblage_ptr = ex1.cxxSSassemblage2s_s_assemblage(); - s_s_assemblage_free(&s_s_assemblage[i]); - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], s_s_assemblage_ptr->n_user); - s_s_assemblage_free(s_s_assemblage_ptr); - free_check_null(s_s_assemblage_ptr); - - } - - } - for (i=0; i < count_gas_phase; i++) { - if (gas_phase[i].new_def != TRUE) { - std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; - std::ostringstream oss; - cxxGasPhase ex(&(gas_phase[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxGasPhase ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); - gas_phase_free(&gas_phase[i]); - gas_phase_copy(gas_phase_ptr, &gas_phase[i], gas_phase_ptr->n_user); - gas_phase_free(gas_phase_ptr); - free_check_null(gas_phase_ptr); - - } - - } - for (i=0; i < count_irrev; i++) { - std::cout << "Reaction " << irrev[i].n_user << std::endl; - std::ostringstream oss; - cxxReaction ex(&(irrev[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxReaction ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); - - irrev_free(&irrev[i]); - irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); - - irrev_free(irrev_ptr); - free_check_null(irrev_ptr); - - } - for (i=0; i < count_mix; i++) { - std::cout << "Mix " << mix[i].n_user << std::endl; - std::ostringstream oss; - cxxMix ex(&(mix[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxMix ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct mix *mix_ptr = ex1.cxxMix2mix(); - - mix_free(&mix[i]); - mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); - - mix_free(mix_ptr); - free_check_null(mix_ptr); - - } - for (i=0; i < count_temperature; i++) { - std::cout << "Temperature " << temperature[i].n_user << std::endl; - std::ostringstream oss; - cxxTemperature ex(&(temperature[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxTemperature ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct temperature *temperature_ptr = ex1.cxxTemperature2temperature(); - - temperature_free(&temperature[i]); - temperature_copy(temperature_ptr, &temperature[i], temperature_ptr->n_user); - - temperature_free(temperature_ptr); - free_check_null(temperature_ptr); - - } - /* - { - // get all c storage - cxxStorageBin cstorage; - cstorage.import_phreeqc(); - //std::ostringstream oss; - //cstorage.dump_raw(oss, 0); - //write it out - std::fstream myfile; - myfile.open("tfile", std::ios_base::out); - cstorage.dump_raw(myfile, 0); - myfile.close(); } + for (i = 0; i < count_s_s_assemblage; i++) { - // empty storage bin - cxxStorageBin cstorage; - // fstream - std::fstream myfile; - myfile.open("tfile", std::ios_base::in); - // ostream + if (s_s_assemblage[i].new_def != TRUE) + { + std::cout << "Solid solution " << s_s_assemblage[i]. + n_user << std::endl; + std::ostringstream oss; + cxxSSassemblage ex(&(s_s_assemblage[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); + + + cxxSSassemblage ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct s_s_assemblage *s_s_assemblage_ptr = + ex1.cxxSSassemblage2s_s_assemblage(); + s_s_assemblage_free(&s_s_assemblage[i]); + s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], + s_s_assemblage_ptr->n_user); + s_s_assemblage_free(s_s_assemblage_ptr); + free_check_null(s_s_assemblage_ptr); + + } + + } + for (i = 0; i < count_gas_phase; i++) + { + if (gas_phase[i].new_def != TRUE) + { + std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; + std::ostringstream oss; + cxxGasPhase ex(&(gas_phase[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); + + + cxxGasPhase ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + + struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); + gas_phase_free(&gas_phase[i]); + gas_phase_copy(gas_phase_ptr, &gas_phase[i], + gas_phase_ptr->n_user); + gas_phase_free(gas_phase_ptr); + free_check_null(gas_phase_ptr); + + } + + } + for (i = 0; i < count_irrev; i++) + { + std::cout << "Reaction " << irrev[i].n_user << std::endl; std::ostringstream oss; - // parser - CParser cparser(myfile, oss, std::cerr); - cstorage.read_raw(cparser); + cxxReaction ex(&(irrev[i])); + ex.dump_raw(oss, 0); //std::cerr << oss.str(); - // read it back - } - */ -} + cxxReaction ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); + + irrev_free(&irrev[i]); + irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); + + irrev_free(irrev_ptr); + free_check_null(irrev_ptr); + + } + for (i = 0; i < count_mix; i++) + { + std::cout << "Mix " << mix[i].n_user << std::endl; + std::ostringstream oss; + cxxMix ex(&(mix[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); + + + cxxMix ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct mix *mix_ptr = ex1.cxxMix2mix(); + + mix_free(&mix[i]); + mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); + + mix_free(mix_ptr); + free_check_null(mix_ptr); + + } + for (i = 0; i < count_temperature; i++) + { + std::cout << "Temperature " << temperature[i].n_user << std::endl; + std::ostringstream oss; + cxxTemperature ex(&(temperature[i])); + ex.dump_raw(oss, 0); + //std::cerr << oss.str(); + + + cxxTemperature ex1; + std::string keyInput = oss.str(); + std::istringstream iss(keyInput); + + CParser cparser(iss, oss, std::cerr); + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + cparser.get_option(vopts, next_char); + + ex1.read_raw(cparser); + struct temperature *temperature_ptr = + ex1.cxxTemperature2temperature(); + + temperature_free(&temperature[i]); + temperature_copy(temperature_ptr, &temperature[i], + temperature_ptr->n_user); + + temperature_free(temperature_ptr); + free_check_null(temperature_ptr); + + } + /* + { + // get all c storage + cxxStorageBin cstorage; + cstorage.import_phreeqc(); + //std::ostringstream oss; + //cstorage.dump_raw(oss, 0); + //write it out + std::fstream myfile; + myfile.open("tfile", std::ios_base::out); + cstorage.dump_raw(myfile, 0); + myfile.close(); + } + { + // empty storage bin + cxxStorageBin cstorage; + // fstream + std::fstream myfile; + myfile.open("tfile", std::ios_base::in); + // ostream + std::ostringstream oss; + // parser + CParser cparser(myfile, oss, std::cerr); + cstorage.read_raw(cparser); + //std::cerr << oss.str(); + + // read it back + } + */ +} diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 771645c2..ed7e6384 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -1,5 +1,5 @@ #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "SolutionIsotope.h" #include "Utils.h" @@ -9,21 +9,21 @@ #include "phqalloc.h" #include "phrqproto.h" #include -#include // std::ostrstream +#include // std::ostrstream -cxxSolutionIsotope::cxxSolutionIsotope(void) -: isotope_number(0.0) +cxxSolutionIsotope::cxxSolutionIsotope(void): +isotope_number(0.0) { } cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) { - isotope_number = isotope_ptr->isotope_number; - elt_name = isotope_ptr->elt_name; - isotope_name = isotope_ptr->isotope_name; - total = isotope_ptr->total; - ratio = isotope_ptr->ratio; - ratio_uncertainty = isotope_ptr->ratio_uncertainty; + isotope_number = isotope_ptr->isotope_number; + elt_name = isotope_ptr->elt_name; + isotope_name = isotope_ptr->isotope_name; + total = isotope_ptr->total; + ratio = isotope_ptr->ratio; + ratio_uncertainty = isotope_ptr->ratio_uncertainty; } @@ -31,227 +31,280 @@ cxxSolutionIsotope::~cxxSolutionIsotope(void) { } -struct isotope *cxxSolutionIsotope::list2isotope(std::list &isolist) - // takes a std::list of cxxSolutionIsotope structures - // returns array of isotope structures +struct isotope * +cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist) + // takes a std::list of cxxSolutionIsotope structures + // returns array of isotope structures { - struct isotope *iso; - if (isolist.size() <= 0) { - return NULL; - } else { - iso = (struct isotope *) PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); - if (iso == NULL) malloc_error(); - int i = 0; - for (std::list ::iterator it = isolist.begin(); it != isolist.end(); ++it) { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); - i++; - } - } - return(iso); + struct isotope *iso; + if (isolist.size() <= 0) + { + return NULL; + } + else + { + iso = + (struct isotope *) + PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); + if (iso == NULL) + malloc_error(); + int i = 0; + for (std::list < cxxSolutionIsotope >::iterator it = isolist.begin(); + it != isolist.end(); ++it) + { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return (iso); } #ifdef SKIP -std::string cxxSolutionIsotope::get_name()const +std::string cxxSolutionIsotope::get_name() constconst { - std::ostringstream oss; - //std::ostrstream oss; - oss << this->isotope_number << this->elt_name; - return oss.str(); + std::ostringstream oss; + //std::ostrstream oss; + oss << this->isotope_number << this->elt_name; + return oss.str(); } #endif -void cxxSolutionIsotope::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - unsigned int i; + unsigned int i; - std::string indent0(""), indent1(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); + std::string indent0(""), indent1(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); - s_oss << indent0; - s_oss << "isotope_number << "\"" << std::endl; + s_oss << indent1; + s_oss << "iso_isotope_number=\"" << this-> + isotope_number << "\"" << std::endl; - s_oss << indent1; - s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl; + s_oss << indent1; + s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl; - s_oss << indent1; - s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl; + s_oss << indent1; + s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl; - s_oss << indent1; - s_oss << "iso_total=\"" << this->total << "\"" << std::endl; + s_oss << indent1; + s_oss << "iso_total=\"" << this->total << "\"" << std::endl; - s_oss << indent1; - s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl; + s_oss << indent1; + s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl; - if (this->ratio_uncertainty != NAN) { - s_oss << indent1; - s_oss << "iso_ratio_uncertainty=\"" << this->ratio_uncertainty << "\"" << std::endl; - } - s_oss << indent0; - s_oss << "\">" << std::endl; + if (this->ratio_uncertainty != NAN) + { + s_oss << indent1; + s_oss << "iso_ratio_uncertainty=\"" << this-> + ratio_uncertainty << "\"" << std::endl; + } + s_oss << indent0; + s_oss << "\">" << std::endl; } -void cxxSolutionIsotope::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - unsigned int i; + unsigned int i; - std::string indent0(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + std::string indent0(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); - s_oss << indent0; - s_oss << this->isotope_name << " "; - s_oss << this->isotope_number << " "; - s_oss << this->elt_name << " "; - s_oss << this->total << " "; - s_oss << this->ratio << " "; - if (this->ratio_uncertainty != NAN) { - s_oss << this->ratio_uncertainty << " "; - } - s_oss << std::endl; + s_oss << indent0; + s_oss << this->isotope_name << " "; + s_oss << this->isotope_number << " "; + s_oss << this->elt_name << " "; + s_oss << this->total << " "; + s_oss << this->ratio << " "; + if (this->ratio_uncertainty != NAN) + { + s_oss << this->ratio_uncertainty << " "; + } + s_oss << std::endl; } -CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser& parser) +CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) { - std::string token; - std::istream::pos_type next_char; - CParser::TOKEN_TYPE j; + std::string token; + std::istream::pos_type next_char; + CParser::TOKEN_TYPE j; - // isotope_name - j = parser.copy_token(token, next_char); + // isotope_name + j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - this->isotope_name = NULL; - return(CParser::PARSER_OK); - } - this->isotope_name = string_hsave(token.c_str()); + if (j == CParser::TT_EMPTY) + { + this->isotope_name = NULL; + return (CParser::PARSER_OK); + } + this->isotope_name = string_hsave(token.c_str()); - // isotope_number - if( !(parser.get_iss() >> isotope_number)) { - return CParser::PARSER_ERROR; - } + // isotope_number + if (!(parser.get_iss() >> isotope_number)) + { + return CParser::PARSER_ERROR; + } - // elt_name - if( !(parser.get_iss() >> token)) { - return CParser::PARSER_ERROR; - } - this->elt_name = string_hsave(token.c_str()); + // elt_name + if (!(parser.get_iss() >> token)) + { + return CParser::PARSER_ERROR; + } + this->elt_name = string_hsave(token.c_str()); - // total - if( !(parser.get_iss() >> this->total)) { - return CParser::PARSER_ERROR; - } + // total + if (!(parser.get_iss() >> this->total)) + { + return CParser::PARSER_ERROR; + } - // ratio - if( !(parser.get_iss() >> this->ratio)) { - return CParser::PARSER_ERROR; - } + // ratio + if (!(parser.get_iss() >> this->ratio)) + { + return CParser::PARSER_ERROR; + } - // ratio_uncertainty - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) { - this->ratio_uncertainty = NAN; - } else if (j != CParser::TT_DIGIT) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass of water in solution.", CParser::OT_CONTINUE); - } else { - std::istringstream(token) >> this->ratio_uncertainty; - } + // ratio_uncertainty + j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY) + { + this->ratio_uncertainty = NAN; + } + else if (j != CParser::TT_DIGIT) + { + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for mass of water in solution.", + CParser::OT_CONTINUE); + } + else + { + std::istringstream(token) >> this->ratio_uncertainty; + } - return CParser::PARSER_OK; + return CParser::PARSER_OK; } -bool cxxSolutionIsotope::operator<(const cxxSolutionIsotope& isotope)const +bool +cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const const { - int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); - if (i != 0) return (i < 0); - return ( this->isotope_number < isotope.isotope_number ); + int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); + if (i != 0) + return (i < 0); + return (this->isotope_number < isotope.isotope_number); } -struct master *cxxSolutionIsotope::master(void) +struct master * +cxxSolutionIsotope::master(void) { - return (master_bsearch(this->elt_name)); + return (master_bsearch(this->elt_name)); } -struct master *cxxSolutionIsotope::primary(void) +struct master * +cxxSolutionIsotope::primary(void) { - return (master_bsearch_primary(this->elt_name)); + return (master_bsearch_primary(this->elt_name)); } -void cxxSolutionIsotope::add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive) +void +cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr, + double intensive, double extensive) { - if ((this->isotope_number == isotope_ptr.isotope_number) && - (this->elt_name == isotope_ptr.elt_name) && - (this->isotope_name == isotope_ptr.isotope_name)) { - this->total += isotope_ptr.total * extensive; - this->ratio += isotope_ptr.ratio * intensive; - this->ratio_uncertainty += isotope_ptr.ratio_uncertainty * intensive; - this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined || isotope_ptr.ratio_uncertainty_defined); + if ((this->isotope_number == isotope_ptr.isotope_number) && + (this->elt_name == isotope_ptr.elt_name) && + (this->isotope_name == isotope_ptr.isotope_name)) + { + this->total += isotope_ptr.total * extensive; + this->ratio += isotope_ptr.ratio * intensive; + this->ratio_uncertainty += isotope_ptr.ratio_uncertainty * intensive; + this->ratio_uncertainty_defined = (this->ratio_uncertainty_defined + || isotope_ptr. + ratio_uncertainty_defined); } } -void cxxSolutionIsotope::multiply(double extensive) +void +cxxSolutionIsotope::multiply(double extensive) { - this->total *= extensive; + this->total *= extensive; } #ifdef SKIP -cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser& parser) +cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) { - if ( !(parser.get_iss() >> this->isotope_number) ) { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected isotope name to" - " begin with an isotopic number.", CParser::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); + if (!(parser.get_iss() >> this->isotope_number)) + { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected isotope name to" + " begin with an isotopic number.", + CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); - // read and save element name - std::istringstream::int_type c = parser.get_iss().peek(); - if ( c == std::char_traits::eof() || !(::isupper(c)) ) { - parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - parser.incr_input_error(); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - if ( !(parser.get_iss() >> this->elt_name) ) { - // should never get here - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - assert(!this->elt_name.empty() && ::isupper(this->elt_name[0])); + // read and save element name + std::istringstream::int_type c = parser.get_iss().peek(); + if (c == std::char_traits < char >::eof() || !(::isupper(c))) + { + parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + parser.incr_input_error(); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + if (!(parser.get_iss() >> this->elt_name)) + { + // should never get here + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + assert(!this->elt_name.empty() &&::isupper(this->elt_name[0])); - // read and store isotope ratio - if ( !(parser.get_iss() >> this->ratio) ) { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected numeric value for isotope ratio.", CParser::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); + // read and store isotope ratio + if (!(parser.get_iss() >> this->ratio)) + { + assert(parser.get_iss().fail()); + parser.incr_input_error(); + parser.error_msg("Expected numeric value for isotope ratio.", + CParser::OT_CONTINUE); + return ERROR; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); - // read and store isotope ratio - this->ratio_uncertainty_defined = false; - if ( !(parser.get_iss() >> this->ratio_uncertainty)) { - if ( !parser.get_iss().eof() ) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for uncertainty in isotope ratio.", CParser::OT_CONTINUE); - return ERROR; - } - } else { - this->ratio_uncertainty_defined = true; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - return OK; + // read and store isotope ratio + this->ratio_uncertainty_defined = false; + if (!(parser.get_iss() >> this->ratio_uncertainty)) + { + if (!parser.get_iss().eof()) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected numeric value for uncertainty in isotope ratio.", + CParser::OT_CONTINUE); + return ERROR; + } + } + else + { + this->ratio_uncertainty_defined = true; + } + assert(parser.get_iss().good() || parser.get_iss().eof()); + return OK; } diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 97ddda62..150818f5 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -1,93 +1,111 @@ -#include "Utils.h" // define first +#include "Utils.h" // define first #include "SolutionIsotopeList.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort cxxSolutionIsotopeList::cxxSolutionIsotopeList(void) - // - // default constructor for cxxSolution - // + // + // default constructor for cxxSolution + // { } cxxSolutionIsotopeList::~cxxSolutionIsotopeList(void) - // - // default destructor for cxxSolution - // + // + // default destructor for cxxSolution + // { } cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) { int i; - // Isotopes - for (i = 0; i < solution_ptr->count_isotopes; i++) { - //cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); - (*this).push_back(&solution_ptr->isotopes[i]); - } -} -void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) -{ - for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) { - //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) - { - //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) + // Isotopes + for (i = 0; i < solution_ptr->count_isotopes; i++) { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined || itold->ratio_uncertainty_defined); - found = true; - break; + //cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); + (*this).push_back(&solution_ptr->isotopes[i]); } - } - if (!found) - { - cxxSolutionIsotope iso; - iso.total = itold->total * extensive; - iso.ratio = itold->ratio * intensive; - iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; - iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; - this->push_back(iso); - } - } } -void cxxSolutionIsotopeList::multiply(double extensive) +void +cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, + double extensive) { - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) - { - it->total *= extensive; - } + for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); + itold != old.end(); ++itold) + { + //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { + bool found = false; + for (cxxSolutionIsotopeList::iterator it = this->begin(); + it != this->end(); ++it) + { + //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { + if ((it->isotope_number == itold->isotope_number) && + (it->elt_name == itold->elt_name) && + (it->isotope_name == itold->isotope_name)) + { + it->total += itold->total * extensive; + it->ratio += itold->ratio * intensive; + it->ratio_uncertainty += itold->ratio_uncertainty * intensive; + it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined + || itold-> + ratio_uncertainty_defined); + found = true; + break; + } + } + if (!found) + { + cxxSolutionIsotope iso; + iso.total = itold->total * extensive; + iso.ratio = itold->ratio * intensive; + iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; + iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; + this->push_back(iso); + } + } } -struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() +void +cxxSolutionIsotopeList::multiply(double extensive) { - struct isotope *iso; - if (this->size() <= 0) { - return NULL; - } else { - iso = (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); - if (iso == NULL) malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); - i++; - } - } - return(iso); + for (cxxSolutionIsotopeList::iterator it = this->begin(); + it != this->end(); ++it) + { + it->total *= extensive; + } +} +struct isotope * +cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() +{ + struct isotope *iso; + if (this->size() <= 0) + { + return NULL; + } + else + { + iso = + (struct isotope *) + PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + if (iso == NULL) + malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::iterator it = this->begin(); + it != this->end(); ++it) + { + iso[i].isotope_number = it->isotope_number; + iso[i].elt_name = it->elt_name; + iso[i].total = it->total; + iso[i].ratio = it->ratio; + iso[i].ratio_uncertainty = it->ratio_uncertainty; + iso[i].master = it->master(); + iso[i].primary = it->primary(); + i++; + } + } + return (iso); } - diff --git a/StorageBin.cxx b/StorageBin.cxx index 409cb60b..cd4c5aa1 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -2,16 +2,16 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #ifdef USE_MPI //MPICH seems to require mpi.h to be first - #include +#include #endif #include -#include // std::cout std::cerr -#include "Utils.h" // define first +#include // std::cout std::cerr +#include "Utils.h" // define first #include "StorageBin.h" #include "System.h" #define EXTERNAL extern @@ -19,181 +19,203 @@ #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxStorageBin::cxxStorageBin() { - // default constructor for cxxStorageBin + // default constructor for cxxStorageBin } cxxStorageBin::cxxStorageBin(struct Use *use_ptr) { - //Construct from use pointer + //Construct from use pointer - // Solution - if (use_ptr->solution_ptr != NULL) - { - cxxSolution entity(use_ptr->solution_ptr); - this->setSolution(use_ptr->n_solution_user, &entity); - } - // Exchange - if (use_ptr->exchange_ptr != NULL) - { - cxxExchange entity(use_ptr->exchange_ptr); - this->setExchange(use_ptr->n_exchange_user, &entity); - } - // gas_phase - if (use_ptr->gas_phase_ptr != NULL) - { - cxxGasPhase entity(use_ptr->gas_phase_ptr); - this->setGasPhase(use_ptr->n_gas_phase_user, &entity); - } - // kinetics - if (use_ptr->kinetics_ptr != NULL) - { - cxxKinetics entity(use_ptr->kinetics_ptr); - this->setKinetics(use_ptr->n_kinetics_user, &entity); - } - // pp_assemblage - if (use_ptr->pp_assemblage_ptr != NULL) - { - cxxPPassemblage entity(use_ptr->pp_assemblage_ptr); - this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); - } - // s_s_assemblage - if (use_ptr->s_s_assemblage_ptr != NULL) - { - cxxSSassemblage entity(use_ptr->s_s_assemblage_ptr); - this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); - } - // surface - if (use_ptr->surface_ptr != NULL) - { - cxxSurface entity(use_ptr->surface_ptr); - this->setSurface(use_ptr->n_surface_user, &entity); - } - // mix - if (use_ptr->mix_ptr != NULL) - { - cxxMix entity(use_ptr->mix_ptr); - this->setMix(use_ptr->n_mix_user, &entity); - } - // reaction - if (use_ptr->irrev_ptr != NULL) - { - cxxReaction entity(use_ptr->irrev_ptr); - this->setReaction(use_ptr->n_irrev_user, &entity); - } - // reaction temperature - if (use_ptr->temperature_ptr != NULL) - { - cxxTemperature entity(use_ptr->temperature_ptr); - this->setTemperature(use_ptr->n_temperature_user, &entity); - } - // set system - this->setSystem(use_ptr); + // Solution + if (use_ptr->solution_ptr != NULL) + { + cxxSolution entity(use_ptr->solution_ptr); + this->setSolution(use_ptr->n_solution_user, &entity); + } + // Exchange + if (use_ptr->exchange_ptr != NULL) + { + cxxExchange entity(use_ptr->exchange_ptr); + this->setExchange(use_ptr->n_exchange_user, &entity); + } + // gas_phase + if (use_ptr->gas_phase_ptr != NULL) + { + cxxGasPhase entity(use_ptr->gas_phase_ptr); + this->setGasPhase(use_ptr->n_gas_phase_user, &entity); + } + // kinetics + if (use_ptr->kinetics_ptr != NULL) + { + cxxKinetics entity(use_ptr->kinetics_ptr); + this->setKinetics(use_ptr->n_kinetics_user, &entity); + } + // pp_assemblage + if (use_ptr->pp_assemblage_ptr != NULL) + { + cxxPPassemblage entity(use_ptr->pp_assemblage_ptr); + this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); + } + // s_s_assemblage + if (use_ptr->s_s_assemblage_ptr != NULL) + { + cxxSSassemblage entity(use_ptr->s_s_assemblage_ptr); + this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); + } + // surface + if (use_ptr->surface_ptr != NULL) + { + cxxSurface entity(use_ptr->surface_ptr); + this->setSurface(use_ptr->n_surface_user, &entity); + } + // mix + if (use_ptr->mix_ptr != NULL) + { + cxxMix entity(use_ptr->mix_ptr); + this->setMix(use_ptr->n_mix_user, &entity); + } + // reaction + if (use_ptr->irrev_ptr != NULL) + { + cxxReaction entity(use_ptr->irrev_ptr); + this->setReaction(use_ptr->n_irrev_user, &entity); + } + // reaction temperature + if (use_ptr->temperature_ptr != NULL) + { + cxxTemperature entity(use_ptr->temperature_ptr); + this->setTemperature(use_ptr->n_temperature_user, &entity); + } + // set system + this->setSystem(use_ptr); } + cxxStorageBin::~cxxStorageBin() { } -void cxxStorageBin::import_phreeqc(void) - // +void +cxxStorageBin::import_phreeqc(void) + // // pull data out of c storage - // + // { int i; // Solutions - for (i = 0; i < count_solution; i++) { + for (i = 0; i < count_solution; i++) + { Solutions[solution[i]->n_user] = cxxSolution(solution[i]); } // Exchangers - for (i = 0; i < count_exchange; i++) { + for (i = 0; i < count_exchange; i++) + { Exchangers[exchange[i].n_user] = cxxExchange(&exchange[i]); } // GasPhases - for (i = 0; i < count_gas_phase; i++) { + for (i = 0; i < count_gas_phase; i++) + { GasPhases[gas_phase[i].n_user] = cxxGasPhase(&gas_phase[i]); } // Kinetics - for (i = 0; i < count_kinetics; i++) { + for (i = 0; i < count_kinetics; i++) + { Kinetics[kinetics[i].n_user] = cxxKinetics(&kinetics[i]); } // PPassemblages - for (i = 0; i < count_pp_assemblage; i++) { - PPassemblages[pp_assemblage[i].n_user] = cxxPPassemblage(&pp_assemblage[i]); + for (i = 0; i < count_pp_assemblage; i++) + { + PPassemblages[pp_assemblage[i].n_user] = + cxxPPassemblage(&pp_assemblage[i]); } // SSassemblages - for (i = 0; i < count_s_s_assemblage; i++) { - SSassemblages[s_s_assemblage[i].n_user] = cxxSSassemblage(&s_s_assemblage[i]); + for (i = 0; i < count_s_s_assemblage; i++) + { + SSassemblages[s_s_assemblage[i].n_user] = + cxxSSassemblage(&s_s_assemblage[i]); } // Surfaces - for (i = 0; i < count_surface; i++) { + for (i = 0; i < count_surface; i++) + { Surfaces[surface[i].n_user] = cxxSurface(&surface[i]); } // Mixes - for (i = 0; i < count_mix; i++) { + for (i = 0; i < count_mix; i++) + { Mixes[mix[i].n_user] = cxxMix(&mix[i]); } // Reactions - for (i = 0; i < count_irrev; i++) { + for (i = 0; i < count_irrev; i++) + { Reactions[irrev[i].n_user] = cxxReaction(&irrev[i]); } // Temperatures - for (i = 0; i < count_temperature; i++) { + for (i = 0; i < count_temperature; i++) + { Temperatures[temperature[i].n_user] = cxxTemperature(&temperature[i]); } } #ifdef SKIP -void cxxStorageBin::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // StorageBin element and attributes - s_oss << indent0; - s_oss << "pitzer_mix_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_mix_gammas=\"" << this-> + pitzer_mix_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = + mixComps.begin(); it != mixComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const const { // Dump all data - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; - s_oss.precision(DBL_DIG - 1); + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + s_oss.precision(DBL_DIG - 1); // Solutions Utilities::dump_raw(Solutions, s_oss, indent); @@ -216,74 +238,88 @@ void cxxStorageBin::dump_raw(std::ostream& s_oss, unsigned int indent)const // Surface Utilities::dump_raw(Surfaces, s_oss, indent); } -void cxxStorageBin::dump_raw(std::ostream& s_oss, int n, unsigned int indent) + +void +cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent) { // Dump one user number - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; - s_oss.precision(DBL_DIG - 1); + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + s_oss.precision(DBL_DIG - 1); // Solutions - if (this->getSolution(n) != NULL) { + if (this->getSolution(n) != NULL) + { this->getSolution(n)->dump_raw(s_oss, indent); } // Exchange - if (this->getExchange(n) != NULL) { + if (this->getExchange(n) != NULL) + { this->getExchange(n)->dump_raw(s_oss, indent); } // Gas Phases - if (this->getGasPhase(n) != NULL) { + if (this->getGasPhase(n) != NULL) + { this->getGasPhase(n)->dump_raw(s_oss, indent); } // Kinetics - if (this->getKinetics(n) != NULL) { + if (this->getKinetics(n) != NULL) + { this->getKinetics(n)->dump_raw(s_oss, indent); } // PPassemblage - if (this->getPPassemblage(n) != NULL) { + if (this->getPPassemblage(n) != NULL) + { this->getPPassemblage(n)->dump_raw(s_oss, indent); } // SSassemblage - if (this->getSSassemblage(n) != NULL) { + if (this->getSSassemblage(n) != NULL) + { this->getSSassemblage(n)->dump_raw(s_oss, indent); } // Surface - if (this->getSurface(n) != NULL) { + if (this->getSurface(n) != NULL) + { this->getSurface(n)->dump_raw(s_oss, indent); } } -void cxxStorageBin::read_raw(CParser& parser) +void +cxxStorageBin::read_raw(CParser & parser) { CParser::LINE_TYPE i; - while ((i = parser.check_line("StorageBin read_raw", false, true, true, true)) != CParser::LT_KEYWORD) + while ((i = + parser.check_line("StorageBin read_raw", false, true, true, + true)) != CParser::LT_KEYWORD) { - if (i == CParser::LT_EOF) return; // CParser::LT_EOF; + if (i == CParser::LT_EOF) + return; // CParser::LT_EOF; } - for (;;) { - switch(parser.next_keyword()) + for (;;) + { + switch (parser.next_keyword()) { - case CParser::KT_END: + case CParser::KT_END: case CParser::KT_EOF: case CParser::KT_NONE: goto END_OF_SIMULATION_INPUT; break; - /* - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 - */ + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ case CParser::KT_SOLUTION_RAW: { cxxSolution entity; @@ -345,243 +381,285 @@ void cxxStorageBin::read_raw(CParser& parser) } } -END_OF_SIMULATION_INPUT: - return; //CParser::LT_OK; + END_OF_SIMULATION_INPUT: + return; //CParser::LT_OK; } -int cxxStorageBin::read_raw_keyword(CParser& parser) + +int +cxxStorageBin::read_raw_keyword(CParser & parser) { - CParser::LINE_TYPE i; - int entity_number = -999; + CParser::LINE_TYPE i; + int entity_number = -999; - switch(parser.next_keyword()) - { - case CParser::KT_NONE: - case CParser::KT_END: - while ((i = parser.check_line("StorageBin read_raw_keyword", false, true, true, true)) != CParser::LT_KEYWORD) - { - if (i == CParser::LT_EOF) break; // CParser::LT_EOF; - } - break; - case CParser::KT_EOF: - break; - /* - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 - */ - case CParser::KT_SOLUTION_RAW: - { - cxxSolution entity; - entity.read_raw(parser); - Solutions[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + switch (parser.next_keyword()) + { + case CParser::KT_NONE: + case CParser::KT_END: + while ((i = + parser.check_line("StorageBin read_raw_keyword", false, true, + true, true)) != CParser::LT_KEYWORD) + { + if (i == CParser::LT_EOF) + break; // CParser::LT_EOF; + } + break; + case CParser::KT_EOF: + break; + /* + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + */ + case CParser::KT_SOLUTION_RAW: + { + cxxSolution entity; + entity.read_raw(parser); + Solutions[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_EXCHANGE_RAW: - { - cxxExchange entity; - entity.read_raw(parser); - Exchangers[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_EXCHANGE_RAW: + { + cxxExchange entity; + entity.read_raw(parser); + Exchangers[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_GASPHASE_RAW: - { - cxxGasPhase entity; - entity.read_raw(parser); - GasPhases[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_GASPHASE_RAW: + { + cxxGasPhase entity; + entity.read_raw(parser); + GasPhases[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_KINETICS_RAW: - { - cxxKinetics entity; - entity.read_raw(parser); - Kinetics[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_KINETICS_RAW: + { + cxxKinetics entity; + entity.read_raw(parser); + Kinetics[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_PPASSEMBLAGE_RAW: - { - cxxPPassemblage entity; - entity.read_raw(parser); - PPassemblages[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_PPASSEMBLAGE_RAW: + { + cxxPPassemblage entity; + entity.read_raw(parser); + PPassemblages[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_SSASSEMBLAGE_RAW: - { - cxxSSassemblage entity; - entity.read_raw(parser); - SSassemblages[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_SSASSEMBLAGE_RAW: + { + cxxSSassemblage entity; + entity.read_raw(parser); + SSassemblages[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - case CParser::KT_SURFACE_RAW: - { - cxxSurface entity; - entity.read_raw(parser); - Surfaces[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); - } - break; + case CParser::KT_SURFACE_RAW: + { + cxxSurface entity; + entity.read_raw(parser); + Surfaces[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; - default: - break; - } - return(entity_number); //CParser::LT_OK; + default: + break; + } + return (entity_number); //CParser::LT_OK; } -void cxxStorageBin::add(struct system * system_ptr) - // - // add data from a system structure - // + +void +cxxStorageBin::add(struct system *system_ptr) + // + // add data from a system structure + // { // Solutions - if (system_ptr->solution != NULL) { - this->Solutions[system_ptr->solution->n_user] = cxxSolution(system_ptr->solution); + if (system_ptr->solution != NULL) + { + this->Solutions[system_ptr->solution->n_user] = + cxxSolution(system_ptr->solution); } // Exchangers - if (system_ptr->exchange != NULL) { - this->Exchangers[system_ptr->exchange->n_user] = cxxExchange(system_ptr->exchange); + if (system_ptr->exchange != NULL) + { + this->Exchangers[system_ptr->exchange->n_user] = + cxxExchange(system_ptr->exchange); } // GasPhases - if (system_ptr->gas_phase != NULL) { - this->GasPhases[system_ptr->gas_phase->n_user] = cxxGasPhase(system_ptr->gas_phase); + if (system_ptr->gas_phase != NULL) + { + this->GasPhases[system_ptr->gas_phase->n_user] = + cxxGasPhase(system_ptr->gas_phase); } // Kinetics - if (system_ptr->kinetics != NULL) { - this->Kinetics[system_ptr->kinetics->n_user] = cxxKinetics(system_ptr->kinetics); + if (system_ptr->kinetics != NULL) + { + this->Kinetics[system_ptr->kinetics->n_user] = + cxxKinetics(system_ptr->kinetics); } // PPassemblages - if (system_ptr->pp_assemblage != NULL) { - this->PPassemblages[system_ptr->pp_assemblage->n_user] = cxxPPassemblage(system_ptr->pp_assemblage); + if (system_ptr->pp_assemblage != NULL) + { + this->PPassemblages[system_ptr->pp_assemblage->n_user] = + cxxPPassemblage(system_ptr->pp_assemblage); } // SSassemblages - if (system_ptr->s_s_assemblage != NULL) { - this->SSassemblages[system_ptr->s_s_assemblage->n_user] = cxxSSassemblage(system_ptr->s_s_assemblage); + if (system_ptr->s_s_assemblage != NULL) + { + this->SSassemblages[system_ptr->s_s_assemblage->n_user] = + cxxSSassemblage(system_ptr->s_s_assemblage); } // Surfaces - if (system_ptr->surface != NULL) { - this->Surfaces[system_ptr->surface->n_user] = cxxSurface(system_ptr->surface); + if (system_ptr->surface != NULL) + { + this->Surfaces[system_ptr->surface->n_user] = + cxxSurface(system_ptr->surface); } } -void cxxStorageBin::cxxStorageBin2phreeqc(int n) - // - // copy data fromphreeqc storage to storage bin - // +void +cxxStorageBin::cxxStorageBin2phreeqc(int n) + // + // copy data fromphreeqc storage to storage bin + // { //std::ostringstream oss; // Solutions { - - std::map ::iterator it = this->Solutions.find(n); - if (it != this->Solutions.end()){ + + std::map < int, cxxSolution >::iterator it = this->Solutions.find(n); + if (it != this->Solutions.end()) + { solution[0] = (it->second).cxxSolution2solution(); solution[0]->n_user = n; solution[0]->n_user_end = n; count_solution++; - } else { + } + else + { error_msg("cxxSolution not found in system2phreeqc", STOP); } } // Exchangers { - std::map ::iterator it = this->Exchangers.find(n); - if ( it != this->Exchangers.end()) { - struct exchange *exchange_ptr = (it->second).cxxExchange2exchange(); + std::map < int, cxxExchange >::iterator it = this->Exchangers.find(n); + if (it != this->Exchangers.end()) + { + struct exchange *exchange_ptr = + (it->second).cxxExchange2exchange(); exchange_copy(exchange_ptr, &exchange[0], n); count_exchange++; exchange_free(exchange_ptr); exchange_ptr = (struct exchange *) free_check_null(exchange_ptr); - } + } } // GasPhases { - std::map ::iterator it = this->GasPhases.find(n); - if ( it != this->GasPhases.end()) { - struct gas_phase *gas_phase_ptr = (it->second).cxxGasPhase2gas_phase(); + std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(n); + if (it != this->GasPhases.end()) + { + struct gas_phase *gas_phase_ptr = + (it->second).cxxGasPhase2gas_phase(); gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); count_gas_phase++; gas_phase_free(gas_phase_ptr); - gas_phase_ptr = (struct gas_phase *) free_check_null(gas_phase_ptr); - } + gas_phase_ptr = + (struct gas_phase *) free_check_null(gas_phase_ptr); + } } // Kinetics { - std::map ::iterator it = this->Kinetics.find(n); - if ( it != this->Kinetics.end()) { - struct kinetics *kinetics_ptr = (it->second).cxxKinetics2kinetics(); + std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(n); + if (it != this->Kinetics.end()) + { + struct kinetics *kinetics_ptr = + (it->second).cxxKinetics2kinetics(); kinetics_copy(kinetics_ptr, &kinetics[0], n); count_kinetics++; kinetics_free(kinetics_ptr); kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); - } + } } // PPassemblages { - std::map ::iterator it = this->PPassemblages.find(n); - if ( it != this->PPassemblages.end()) { - struct pp_assemblage *pp_assemblage_ptr = (it->second).cxxPPassemblage2pp_assemblage(); + std::map < int, cxxPPassemblage >::iterator it = + this->PPassemblages.find(n); + if (it != this->PPassemblages.end()) + { + struct pp_assemblage *pp_assemblage_ptr = + (it->second).cxxPPassemblage2pp_assemblage(); pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); count_pp_assemblage++; pp_assemblage_free(pp_assemblage_ptr); - pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); - } + pp_assemblage_ptr = + (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); + } } // SSassemblages { - std::map ::iterator it = this->SSassemblages.find(n); - if ( it != this->SSassemblages.end()) { - struct s_s_assemblage *s_s_assemblage_ptr = (it->second).cxxSSassemblage2s_s_assemblage(); + std::map < int, cxxSSassemblage >::iterator it = + this->SSassemblages.find(n); + if (it != this->SSassemblages.end()) + { + struct s_s_assemblage *s_s_assemblage_ptr = + (it->second).cxxSSassemblage2s_s_assemblage(); s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); count_s_s_assemblage++; s_s_assemblage_free(s_s_assemblage_ptr); - s_s_assemblage_ptr = (struct s_s_assemblage *) free_check_null(s_s_assemblage_ptr); - } + s_s_assemblage_ptr = + (struct s_s_assemblage *) free_check_null(s_s_assemblage_ptr); + } } // Surfaces { - std::map ::iterator it = this->Surfaces.find(n); - if ( it != this->Surfaces.end()) { + std::map < int, cxxSurface >::iterator it = this->Surfaces.find(n); + if (it != this->Surfaces.end()) + { struct surface *surface_ptr = (it->second).cxxSurface2surface(); surface_copy(surface_ptr, &surface[0], n); count_surface++; surface_free(surface_ptr); surface_ptr = (struct surface *) free_check_null(surface_ptr); - } + } } //std::cerr << oss.str(); } -void cxxStorageBin::phreeqc2cxxStorageBin(int n) - // - // copy data fromphreeqc storage to storage bin - // +void +cxxStorageBin::phreeqc2cxxStorageBin(int n) + // + // copy data fromphreeqc storage to storage bin + // { int pos; @@ -593,48 +671,55 @@ void cxxStorageBin::phreeqc2cxxStorageBin(int n) // Exchangers { - if (exchange_bsearch(n, &pos) != NULL) { + if (exchange_bsearch(n, &pos) != NULL) + { this->Exchangers[n] = cxxExchange(&(exchange[pos])); } } // GasPhases { - if (gas_phase_bsearch(n, &pos) != NULL) { + if (gas_phase_bsearch(n, &pos) != NULL) + { this->GasPhases[n] = cxxGasPhase(&(gas_phase[pos])); } } // Kinetics { - if (kinetics_bsearch(n, &pos) != NULL) { + if (kinetics_bsearch(n, &pos) != NULL) + { this->Kinetics[n] = cxxKinetics(&(kinetics[pos])); } } // PPassemblages { - if (pp_assemblage_bsearch(n, &pos) != NULL) { + if (pp_assemblage_bsearch(n, &pos) != NULL) + { this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos])); } } // SSassemblages { - if (s_s_assemblage_bsearch(n, &pos) != NULL) { + if (s_s_assemblage_bsearch(n, &pos) != NULL) + { this->SSassemblages[n] = cxxSSassemblage(&(s_s_assemblage[pos])); } } // Surfaces { - if (surface_bsearch(n, &pos) != NULL) { + if (surface_bsearch(n, &pos) != NULL) + { this->Surfaces[n] = cxxSurface(&(surface[pos])); } } } -void cxxStorageBin::remove(int n) +void +cxxStorageBin::remove(int n) { // Solution this->Solutions.erase(n); @@ -657,9 +742,10 @@ void cxxStorageBin::remove(int n) // Surface this->Surfaces.erase(n); } -#ifdef SKIP -cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) +#ifdef SKIP +cxxSolution * +cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) { /* * mixes solutions based on cxxMix structure, returns new solution @@ -673,159 +759,213 @@ cxxSolution *cxxStorageBin::mix_cxxSolutions(cxxMix &mixmap) cxxsoln_ptr = new cxxSolution(0.0); /* * Determine sum of mixing fractions - */ + */ extensive = 0.0; - - std::map *mixcomps = mixmap.comps(); - - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) { + + std::map < int, double >*mixcomps = mixmap.comps(); + + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { extensive += it->second; } /* * Add solutions - */ - for (it = mixcomps->begin(); it != mixcomps->end(); it++) { + */ + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { cxxsoln_ptr1 = &((this->Solutions.find(it->first))->second); - if (cxxsoln_ptr1 == NULL) { - sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); + if (cxxsoln_ptr1 == NULL) + { + sprintf(error_string, + "Solution %d not found in mix_cxxSolutions.", it->first); error_msg(error_string, CONTINUE); input_error++; - return(NULL); - } - intensive = it->second/extensive; + return (NULL); + } + intensive = it->second / extensive; cxxsoln_ptr->add(*cxxsoln_ptr1, intensive, it->second); - } - return(cxxsoln_ptr); + } + return (cxxsoln_ptr); } #endif -struct system *cxxStorageBin::cxxStorageBin2system(int n) - // - // make a system from storagebin - // +struct system * +cxxStorageBin::cxxStorageBin2system(int n) + // + // make a system from storagebin + // { - struct system *system_ptr = (struct system *) PHRQ_malloc(sizeof(struct system)); - if (system_ptr == NULL) malloc_error(); + struct system *system_ptr = + (struct system *) PHRQ_malloc(sizeof(struct system)); + if (system_ptr == NULL) + malloc_error(); // Solutions - - if (this->getSolution(n) != NULL) { + + if (this->getSolution(n) != NULL) + { system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(); - } else { + } + else + { system_ptr->solution = NULL; } // Exchangers - if (this->getExchange(n) != NULL) { + if (this->getExchange(n) != NULL) + { system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(); - } else { + } + else + { system_ptr->exchange = NULL; } // GasPhases - if (this->getGasPhase(n) != NULL) { - system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(); - } else { + if (this->getGasPhase(n) != NULL) + { + system_ptr->gas_phase = + (this->getGasPhase(n))->cxxGasPhase2gas_phase(); + } + else + { system_ptr->gas_phase = NULL; } // Kinetics - if (this->getKinetics(n) != NULL) { + if (this->getKinetics(n) != NULL) + { system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(); - } else { + } + else + { system_ptr->kinetics = NULL; } // PPassemblages - if (this->getPPassemblage(n) != NULL) { - system_ptr->pp_assemblage = (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(); - } else { + if (this->getPPassemblage(n) != NULL) + { + system_ptr->pp_assemblage = + (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(); + } + else + { system_ptr->pp_assemblage = NULL; } // SSassemblages - if (this->getSSassemblage(n) != NULL) { - system_ptr->s_s_assemblage = (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(); - } else { + if (this->getSSassemblage(n) != NULL) + { + system_ptr->s_s_assemblage = + (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(); + } + else + { system_ptr->s_s_assemblage = NULL; } // Surfaces - if (this->getSurface(n) != NULL) { + if (this->getSurface(n) != NULL) + { system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(); - } else { + } + else + { system_ptr->surface = NULL; } return system_ptr; } + #ifdef USE_MPI -void cxxStorageBin::mpi_send(int n, int task_number) +void +cxxStorageBin::mpi_send(int n, int task_number) { - // - // Send data for system n to task_number - // - std::vector ints; - std::vector doubles; - + // + // Send data for system n to task_number + // + std::vector < int >ints; + std::vector < double >doubles; + // Solution - if (this->getSolution(n) != NULL) { + if (this->getSolution(n) != NULL) + { ints.push_back(1); this->getSolution(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed Solution" << std::endl; // Exchanger - if (this->getExchange(n) != NULL) { + if (this->getExchange(n) != NULL) + { ints.push_back(1); this->getExchange(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed Exchange" << std::endl; // GasPhase - if (this->getGasPhase(n) != NULL) { + if (this->getGasPhase(n) != NULL) + { ints.push_back(1); this->getGasPhase(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed GasPhase" << std::endl; // Kinetics - if (this->getKinetics(n) != NULL) { + if (this->getKinetics(n) != NULL) + { ints.push_back(1); this->getKinetics(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed Kinetics" << std::endl; // PPassemblages - if (this->getPPassemblage(n) != NULL) { + if (this->getPPassemblage(n) != NULL) + { ints.push_back(1); this->getPPassemblage(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed PPassemblage" << std::endl; // SSassemblages - if (this->getSSassemblage(n) != NULL) { + if (this->getSSassemblage(n) != NULL) + { ints.push_back(1); this->getSSassemblage(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed SSassemblage" << std::endl; // Surfaces - if (this->getSurface(n) != NULL) { + if (this->getSurface(n) != NULL) + { ints.push_back(1); this->getSurface(n)->mpi_pack(ints, doubles); - } else { + } + else + { ints.push_back(0); } //std::cerr << "Packed Surface" << std::endl; @@ -833,28 +973,31 @@ void cxxStorageBin::mpi_send(int n, int task_number) // Pack data int max_size = 0; int member_size = 0; - MPI_Pack_size((int) ints.size() + 10, MPI_INT, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) ints.size() + 10, MPI_INT, MPI_COMM_WORLD, + &member_size); max_size += member_size; - MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); + MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, + &member_size); max_size += member_size + 10; void *buffer = PHRQ_malloc(max_size); - if (buffer == NULL) malloc_error(); - + if (buffer == NULL) + malloc_error(); + // Convert to arrays int i = (int) ints.size(); //int int_array[i]; int d = (int) doubles.size(); //double double_array[d]; /* - for (int j = 0; j < i; j++) { - int_array[j] = ints[j]; - //std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl; - } - for (int j = 0; j < d; j++) { - double_array[j] = doubles[j]; - //std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl; - } - */ + for (int j = 0; j < i; j++) { + int_array[j] = ints[j]; + //std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl; + } + for (int j = 0; j < d; j++) { + double_array[j] = doubles[j]; + //std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl; + } + */ /* * Send message to processor */ @@ -862,18 +1005,23 @@ void cxxStorageBin::mpi_send(int n, int task_number) MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); //MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); + MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, + MPI_COMM_WORLD); MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); //MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); - if (d > 0) { - MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); + if (d > 0) + { + MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, + &position, MPI_COMM_WORLD); } MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); buffer = (void *) free_check_null(buffer); } + /* ---------------------------------------------------------------------- */ -void cxxStorageBin::mpi_recv(int task_number) +void +cxxStorageBin::mpi_recv(int task_number) /* ---------------------------------------------------------------------- */ { MPI_Status mpi_status; @@ -881,39 +1029,52 @@ void cxxStorageBin::mpi_recv(int task_number) * Malloc space for a buffer */ int max_size; - // buffer size + // buffer size - MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); + MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, + &mpi_status); void *buffer = PHRQ_malloc(max_size); - if (buffer == NULL) malloc_error(); + if (buffer == NULL) + malloc_error(); /* * Recieve system */ - MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status); - int position = 0; + MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, + &mpi_status); + int position = 0; int msg_size; - MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); + MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); /* Unpack ints */ int count_ints; - MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, + MPI_COMM_WORLD); int *ints = new int[count_ints]; - MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, + MPI_COMM_WORLD); /* Unpack doubles */ int count_doubles; - MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, + MPI_COMM_WORLD); double *doubles = new double[count_doubles]; - if (count_doubles > 0) { - MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); + if (count_doubles > 0) + { + MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, + MPI_DOUBLE, MPI_COMM_WORLD); } buffer = free_check_null(buffer); #ifdef SKIP - for (int j = 0; j < count_ints; j++) { - std::cerr << "Recving ints " << j << " value " << ints[j] << std::endl; + for (int j = 0; j < count_ints; j++) + { + std::cerr << "Recving ints " << j << " value " << ints[j] << std:: + endl; } - for (int j = 0; j < count_doubles; j++) { - std::cerr << "Recving doubles " << j << " value " << doubles[j] << std::endl; + for (int j = 0; j < count_doubles; j++) + { + std:: + cerr << "Recving doubles " << j << " value " << doubles[j] << + std::endl; } #endif /* @@ -925,15 +1086,17 @@ void cxxStorageBin::mpi_recv(int task_number) int d = 0; // Solution - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxSolution entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setSolution(entity.get_n_user(), &entity); } //std::cerr << "Unpacked Solution" << std::endl; - + // Exchanger - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxExchange entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setExchange(entity.get_n_user(), &entity); @@ -941,7 +1104,8 @@ void cxxStorageBin::mpi_recv(int task_number) //std::cerr << "Unpacked Exchange" << std::endl; // GasPhase - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxGasPhase entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setGasPhase(entity.get_n_user(), &entity); @@ -949,7 +1113,8 @@ void cxxStorageBin::mpi_recv(int task_number) //std::cerr << "Unpacked GasPhase" << std::endl; // Kinetics - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxKinetics entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setKinetics(entity.get_n_user(), &entity); @@ -957,7 +1122,8 @@ void cxxStorageBin::mpi_recv(int task_number) //std::cerr << "Unpacked Kinetics" << std::endl; // PPassemblage - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxPPassemblage entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setPPassemblage(entity.get_n_user(), &entity); @@ -965,7 +1131,8 @@ void cxxStorageBin::mpi_recv(int task_number) //std::cerr << "Unpacked PPassemblage" << std::endl; // SSassemblage - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxSSassemblage entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setSSassemblage(entity.get_n_user(), &entity); @@ -973,20 +1140,21 @@ void cxxStorageBin::mpi_recv(int task_number) //std::cerr << "Unpacked SSassemblage" << std::endl; // Surfaces - if (ints[i++] != 0) { + if (ints[i++] != 0) + { cxxSurface entity; entity.mpi_unpack(ints, &i, doubles, &d); this->setSurface(entity.get_n_user(), &entity); } //std::cerr << "Unpacked Surface" << std::endl; - delete[] ints; - delete[] doubles; + delete[]ints; + delete[]doubles; } #endif #ifdef SKIP -cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) - +cxxExchange * +cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) { /* * mixes exchangers based on cxxMix structure, returns new exchanger @@ -998,60 +1166,72 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) */ new_exch_ptr = new cxxExchange(); - std::map::const_iterator it_mix; - std::map *mixcomps = mixmap.comps(); + std::map < int, double >::const_iterator it_mix; + std::map < int, double >*mixcomps = mixmap.comps(); // Pitzer_exchange_gammas it_mix = mixcomps->begin(); old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); - if (old_exch_ptr == NULL) { - sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); + if (old_exch_ptr == NULL) + { + sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", + it_mix->first); error_msg(error_string, CONTINUE); input_error++; - return(NULL); - } - new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr->get_pitzer_exchange_gammas()); + return (NULL); + } + new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr-> + get_pitzer_exchange_gammas()); /* * Make list of ExchComps - */ - std::vector ec_vector; - std::vector f_vector; + */ + std::vector < cxxExchComp > ec_vector; + std::vector < double >f_vector; // // make list of all exchange components and their mix fractions // - for (it_mix = mixcomps->begin(); it_mix != mixcomps->end(); it_mix++) { + for (it_mix = mixcomps->begin(); it_mix != mixcomps->end(); it_mix++) + { old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); - if (old_exch_ptr == NULL) { - sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); + if (old_exch_ptr == NULL) + { + sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", + it_mix->first); error_msg(error_string, CONTINUE); input_error++; - return(NULL); - } + return (NULL); + } // Add exchange components to vector ec_vector - std::list::const_iterator it_ec; - std::list &eclist = old_exch_ptr->get_exchComps(); - for (it_ec = eclist.begin(); it_ec != eclist.end(); it_ec++) { + std::list < cxxExchComp >::const_iterator it_ec; + std::list < cxxExchComp > &eclist = old_exch_ptr->get_exchComps(); + for (it_ec = eclist.begin(); it_ec != eclist.end(); it_ec++) + { f_vector.push_back(it_mix->second); //cxxExchComp ec = *it_ec; //ec_vector.push_back(ec); ec_vector.push_back(*it_ec); } - } + } // // Process list to make mixture // char *current_formula = ec_vector.begin()->get_formula(); - while (current_formula != NULL) { - - std::vector ec_subvector; - std::vector f_subvector; - std::vector::iterator it_ec = ec_vector.begin(); - std::vector::iterator it_f = f_vector.begin(); + while (current_formula != NULL) + { + + std::vector < cxxExchComp > ec_subvector; + std::vector < double >f_subvector; + std::vector < cxxExchComp >::iterator it_ec = ec_vector.begin(); + std::vector < double >::iterator it_f = f_vector.begin(); current_formula = NULL; - for ( ; it_ec != ec_vector.end(); it_ec++) { - if (*it_f != 0) { - if (current_formula == NULL) current_formula = it_ec->get_formula(); - if (it_ec->get_formula() == current_formula) { + for (; it_ec != ec_vector.end(); it_ec++) + { + if (*it_f != 0) + { + if (current_formula == NULL) + current_formula = it_ec->get_formula(); + if (it_ec->get_formula() == current_formula) + { ec_subvector.push_back(*it_ec); f_subvector.push_back(*it_f); *it_f = 0; @@ -1065,122 +1245,136 @@ cxxExchange *cxxStorageBin::mix_cxxExchange(cxxMix &mixmap) // mix ec_subvector to make // one exchange component // - if (current_formula != NULL) { + if (current_formula != NULL) + { cxxExchComp new_comp(ec_subvector, f_subvector); new_exch_ptr->get_exchComps().push_back(new_comp); } } /* - std::ostringstream oss; - new_exch_ptr->dump_raw(oss, 0); - std::cerr << oss.str(); - */ - return(new_exch_ptr); + std::ostringstream oss; + new_exch_ptr->dump_raw(oss, 0); + std::cerr << oss.str(); + */ + return (new_exch_ptr); } #endif #ifdef ORCHESTRA -void cxxStorageBin::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) +void +cxxStorageBin::ORCH_write(std::ostream & chemistry_dat, + std::ostream & input_dat, std::ostream & output_dat) { - //std::ostringstream oss; + //std::ostringstream oss; - // Liter concentrations - this->system.ORCH_write(chemistry_dat, input_dat, output_dat); + // Liter concentrations + this->system.ORCH_write(chemistry_dat, input_dat, output_dat); } #endif -void cxxStorageBin::setSystem(struct Use *use_ptr) +void +cxxStorageBin::setSystem(struct Use *use_ptr) { - // Initialize - this->system.Initialize(); - // Solution - if (use_ptr->solution_ptr != NULL) - { - std::map ::iterator it = this->Solutions.find(use_ptr->n_solution_user); - if (it != this->Solutions.end()) - { - this->system.setSolution(&(it->second)); - } - } - // Exchange - if (use_ptr->exchange_ptr != NULL) - { - std::map ::iterator it = this->Exchangers.find(use_ptr->n_exchange_user); - if (it != this->Exchangers.end()) - { - this->system.setExchange(&(it->second)); - } - } - // gas_phase - if (use_ptr->gas_phase_ptr != NULL) - { - std::map ::iterator it = this->GasPhases.find(use_ptr->n_gas_phase_user); - if (it != this->GasPhases.end()) - { - this->system.setGasPhase(&(it->second)); - } - } - // kinetics - if (use_ptr->kinetics_ptr != NULL) - { - std::map ::iterator it = this->Kinetics.find(use_ptr->n_kinetics_user); - if (it != this->Kinetics.end()) - { - this->system.setKinetics(&(it->second)); - } - } - // pp_assemblage - if (use_ptr->pp_assemblage_ptr != NULL) - { - std::map ::iterator it = this->PPassemblages.find(use_ptr->n_pp_assemblage_user); - if (it != this->PPassemblages.end()) - { - this->system.setPPassemblage(&(it->second)); - } - } - // s_s_assemblage - if (use_ptr->s_s_assemblage_ptr != NULL) - { - std::map ::iterator it = this->SSassemblages.find(use_ptr->n_s_s_assemblage_user); - if (it != this->SSassemblages.end()) - { - this->system.setSSassemblage(&(it->second)); - } - } - // surface - if (use_ptr->surface_ptr != NULL) - { - std::map ::iterator it = this->Surfaces.find(use_ptr->n_surface_user); - if (it != this->Surfaces.end()) - { - this->system.setSurface(&(it->second)); - } - } - // mix - if (use_ptr->mix_ptr != NULL) - { - std::map ::iterator it = this->Mixes.find(use_ptr->n_mix_user); - if (it != this->Mixes.end()) - { - this->system.setMix(&(it->second)); - } - } - // reaction - if (use_ptr->irrev_ptr != NULL) - { - std::map ::iterator it = this->Reactions.find(use_ptr->n_irrev_user); - if (it != this->Reactions.end()) - { - this->system.setReaction(&(it->second)); - } - } - // reaction temperature - if (use_ptr->temperature_ptr != NULL) - { - std::map ::iterator it = this->Temperatures.find(use_ptr->n_temperature_user); - if (it != this->Temperatures.end()) - { - this->system.setTemperature(&(it->second)); - } - } + // Initialize + this->system.Initialize(); + // Solution + if (use_ptr->solution_ptr != NULL) + { + std::map < int, cxxSolution >::iterator it = + this->Solutions.find(use_ptr->n_solution_user); + if (it != this->Solutions.end()) + { + this->system.setSolution(&(it->second)); + } + } + // Exchange + if (use_ptr->exchange_ptr != NULL) + { + std::map < int, cxxExchange >::iterator it = + this->Exchangers.find(use_ptr->n_exchange_user); + if (it != this->Exchangers.end()) + { + this->system.setExchange(&(it->second)); + } + } + // gas_phase + if (use_ptr->gas_phase_ptr != NULL) + { + std::map < int, cxxGasPhase >::iterator it = + this->GasPhases.find(use_ptr->n_gas_phase_user); + if (it != this->GasPhases.end()) + { + this->system.setGasPhase(&(it->second)); + } + } + // kinetics + if (use_ptr->kinetics_ptr != NULL) + { + std::map < int, cxxKinetics >::iterator it = + this->Kinetics.find(use_ptr->n_kinetics_user); + if (it != this->Kinetics.end()) + { + this->system.setKinetics(&(it->second)); + } + } + // pp_assemblage + if (use_ptr->pp_assemblage_ptr != NULL) + { + std::map < int, cxxPPassemblage >::iterator it = + this->PPassemblages.find(use_ptr->n_pp_assemblage_user); + if (it != this->PPassemblages.end()) + { + this->system.setPPassemblage(&(it->second)); + } + } + // s_s_assemblage + if (use_ptr->s_s_assemblage_ptr != NULL) + { + std::map < int, cxxSSassemblage >::iterator it = + this->SSassemblages.find(use_ptr->n_s_s_assemblage_user); + if (it != this->SSassemblages.end()) + { + this->system.setSSassemblage(&(it->second)); + } + } + // surface + if (use_ptr->surface_ptr != NULL) + { + std::map < int, cxxSurface >::iterator it = + this->Surfaces.find(use_ptr->n_surface_user); + if (it != this->Surfaces.end()) + { + this->system.setSurface(&(it->second)); + } + } + // mix + if (use_ptr->mix_ptr != NULL) + { + std::map < int, cxxMix >::iterator it = + this->Mixes.find(use_ptr->n_mix_user); + if (it != this->Mixes.end()) + { + this->system.setMix(&(it->second)); + } + } + // reaction + if (use_ptr->irrev_ptr != NULL) + { + std::map < int, cxxReaction >::iterator it = + this->Reactions.find(use_ptr->n_irrev_user); + if (it != this->Reactions.end()) + { + this->system.setReaction(&(it->second)); + } + } + // reaction temperature + if (use_ptr->temperature_ptr != NULL) + { + std::map < int, cxxTemperature >::iterator it = + this->Temperatures.find(use_ptr->n_temperature_user); + if (it != this->Temperatures.end()) + { + this->system.setTemperature(&(it->second)); + } + } } diff --git a/Surface.cxx b/Surface.cxx index ab3bf3d9..085aef13 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -2,357 +2,401 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "Surface.h" #include "SurfaceComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSurface::cxxSurface() - // - // default constructor for cxxSurface - // -: cxxNumKeyword() + // + // default constructor for cxxSurface + // +: cxxNumKeyword() { - type = DDL; - dl_type = NO_DL; - sites_units = SITES_ABSOLUTE; - //diffuse_layer = false; - //edl = false; - only_counter_ions = false; - //donnan = false; - thickness = 1e-8; - debye_lengths = 0.0; - DDL_viscosity = 1.0; - DDL_limit = 0.8; - transport = false; + type = DDL; + dl_type = NO_DL; + sites_units = SITES_ABSOLUTE; + //diffuse_layer = false; + //edl = false; + only_counter_ions = false; + //donnan = false; + thickness = 1e-8; + debye_lengths = 0.0; + DDL_viscosity = 1.0; + DDL_limit = 0.8; + transport = false; } cxxSurface::cxxSurface(struct surface *surface_ptr) - // - // constructor for cxxSurface from struct surface - // -: + // + // constructor for cxxSurface from struct surface + // + : cxxNumKeyword() - { - int i; + int i; - this->set_description(surface_ptr->description); - n_user = surface_ptr->n_user; - n_user_end = surface_ptr->n_user_end; - type = surface_ptr->type; - dl_type = surface_ptr->dl_type; - sites_units = surface_ptr->sites_units; - //diffuse_layer = (surface_ptr->diffuse_layer == TRUE); - //edl = (surface_ptr->edl == TRUE); - only_counter_ions = (surface_ptr->only_counter_ions == TRUE); - //donnan = (surface_ptr->donnan == TRUE); - thickness = surface_ptr->thickness; - debye_lengths = surface_ptr->debye_lengths; - DDL_viscosity = surface_ptr->DDL_viscosity; - DDL_limit = surface_ptr->DDL_limit; - transport = (surface_ptr->transport == TRUE); - // Surface components - for (i = 0; i < surface_ptr->count_comps; i++) { - cxxSurfaceComp ec(&(surface_ptr->comps[i])); - surfaceComps.push_back(ec); - } - // Surface charge - for (i = 0; i < surface_ptr->count_charge; i++) { - cxxSurfaceCharge ec(&(surface_ptr->charge[i])); - surfaceCharges.push_back(ec); - } + this->set_description(surface_ptr->description); + n_user = surface_ptr->n_user; + n_user_end = surface_ptr->n_user_end; + type = surface_ptr->type; + dl_type = surface_ptr->dl_type; + sites_units = surface_ptr->sites_units; + //diffuse_layer = (surface_ptr->diffuse_layer == TRUE); + //edl = (surface_ptr->edl == TRUE); + only_counter_ions = (surface_ptr->only_counter_ions == TRUE); + //donnan = (surface_ptr->donnan == TRUE); + thickness = surface_ptr->thickness; + debye_lengths = surface_ptr->debye_lengths; + DDL_viscosity = surface_ptr->DDL_viscosity; + DDL_limit = surface_ptr->DDL_limit; + transport = (surface_ptr->transport == TRUE); + // Surface components + for (i = 0; i < surface_ptr->count_comps; i++) + { + cxxSurfaceComp ec(&(surface_ptr->comps[i])); + surfaceComps.push_back(ec); + } + // Surface charge + for (i = 0; i < surface_ptr->count_charge; i++) + { + cxxSurfaceCharge ec(&(surface_ptr->charge[i])); + surfaceCharges.push_back(ec); + } } -cxxSurface::cxxSurface(const std::map &entities, cxxMix &mix, int n_user) -: +cxxSurface::cxxSurface(const std::map < int, cxxSurface > &entities, + cxxMix & mix, int n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - type = DDL; - dl_type = NO_DL; - sites_units = SITES_ABSOLUTE; - only_counter_ions = false; - thickness = 1e-8; - debye_lengths = 0.0; - DDL_viscosity = 1.0; - DDL_limit = 0.8; - transport = false; + this->n_user = this->n_user_end = n_user; + type = DDL; + dl_type = NO_DL; + sites_units = SITES_ABSOLUTE; + only_counter_ions = false; + thickness = 1e-8; + debye_lengths = 0.0; + DDL_viscosity = 1.0; + DDL_limit = 0.8; + transport = false; // // Mix exchangers // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxSurface *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); - } - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxSurface *entity_ptr = + &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } } cxxSurface::~cxxSurface() { } -bool cxxSurface::get_related_phases() -{ - for (std::list::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if (it->get_phase_name() == NULL) continue; - return(true); - } - return(false); -} - -bool cxxSurface::get_related_rate() -{ - for (std::list::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if (it->get_rate_name() == NULL) continue; - return(true); - } - return(false); -} - -struct surface *cxxSurface::cxxSurface2surface() - // - // Builds a surface structure from instance of cxxSurface - // +bool +cxxSurface::get_related_phases() { - struct surface *surface_ptr = surface_alloc(); - - surface_ptr->description = this->get_description(); - surface_ptr->n_user = this->n_user; - surface_ptr->n_user_end = this->n_user_end; - surface_ptr->new_def = FALSE; - surface_ptr->type = this->type; - surface_ptr->dl_type = this->dl_type; - surface_ptr->sites_units = this->sites_units; - //surface_ptr->diffuse_layer = this->diffuse_layer; - //surface_ptr->edl = this->edl; - surface_ptr->only_counter_ions = this->only_counter_ions; - //surface_ptr->donnan = this->donnan; - surface_ptr->thickness = this->thickness; - surface_ptr->debye_lengths = 1.0; - surface_ptr->solution_equilibria = FALSE; - surface_ptr->n_solution = -2; - surface_ptr->related_phases = (int) this->get_related_phases(); - surface_ptr->related_rate = (int) this->get_related_rate(); - surface_ptr->transport = this->transport; - surface_ptr->debye_lengths = this->debye_lengths; - surface_ptr->DDL_viscosity = this->DDL_viscosity; - surface_ptr->DDL_limit = this->DDL_limit; + for (std::list < cxxSurfaceComp >::const_iterator it = + this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + { + if (it->get_phase_name() == NULL) + continue; + return (true); + } + return (false); +} - // Surface comps - surface_ptr->count_comps = (int) this->surfaceComps.size(); - surface_ptr->comps = (struct surface_comp *) free_check_null(surface_ptr->comps); - surface_ptr->comps = cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); +bool +cxxSurface::get_related_rate() +{ + for (std::list < cxxSurfaceComp >::const_iterator it = + this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + { + if (it->get_rate_name() == NULL) + continue; + return (true); + } + return (false); +} - // Surface charge - surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge); +struct surface * +cxxSurface::cxxSurface2surface() + // + // Builds a surface structure from instance of cxxSurface + // +{ + struct surface *surface_ptr = surface_alloc(); + + surface_ptr->description = this->get_description(); + surface_ptr->n_user = this->n_user; + surface_ptr->n_user_end = this->n_user_end; + surface_ptr->new_def = FALSE; + surface_ptr->type = this->type; + surface_ptr->dl_type = this->dl_type; + surface_ptr->sites_units = this->sites_units; + //surface_ptr->diffuse_layer = this->diffuse_layer; + //surface_ptr->edl = this->edl; + surface_ptr->only_counter_ions = this->only_counter_ions; + //surface_ptr->donnan = this->donnan; + surface_ptr->thickness = this->thickness; + surface_ptr->debye_lengths = 1.0; + surface_ptr->solution_equilibria = FALSE; + surface_ptr->n_solution = -2; + surface_ptr->related_phases = (int) this->get_related_phases(); + surface_ptr->related_rate = (int) this->get_related_rate(); + surface_ptr->transport = this->transport; + surface_ptr->debye_lengths = this->debye_lengths; + surface_ptr->DDL_viscosity = this->DDL_viscosity; + surface_ptr->DDL_limit = this->DDL_limit; + + // Surface comps + surface_ptr->count_comps = (int) this->surfaceComps.size(); + surface_ptr->comps = + (struct surface_comp *) free_check_null(surface_ptr->comps); + surface_ptr->comps = + cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); + + // Surface charge + surface_ptr->charge = + (struct surface_charge *) free_check_null(surface_ptr->charge); //if (surface_ptr->edl == TRUE) { - if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) { + if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + { surface_ptr->count_charge = (int) this->surfaceCharges.size(); - surface_ptr->charge = cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); - } else { + surface_ptr->charge = + cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this-> + surfaceCharges); + } + else + { surface_ptr->count_charge = 0; } // Need to fill in charge (number) in comps list if (surface_ptr->type != NO_EDL) { - int i,j; - for (i = 0; i < surface_ptr->count_comps; i++) { - char *charge_name = cxxSurfaceComp::get_charge_name(surface_ptr->comps[i].formula); - for (j = 0; j < surface_ptr->count_charge; j++) { - if (charge_name == surface_ptr->charge[j].name) { - surface_ptr->comps[i].charge = j; - break; - } - } - assert(j < surface_ptr->count_charge); - } + int i, j; + for (i = 0; i < surface_ptr->count_comps; i++) + { + char *charge_name = + cxxSurfaceComp::get_charge_name(surface_ptr->comps[i]. + formula); + for (j = 0; j < surface_ptr->count_charge; j++) + { + if (charge_name == surface_ptr->charge[j].name) + { + surface_ptr->comps[i].charge = j; + break; + } + } + assert(j < surface_ptr->count_charge); + } } - return(surface_ptr); + return (surface_ptr); } -void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surface element and attributes - s_oss << indent0; - s_oss << "diffuse_layer << "\"" << std::endl; - s_oss << "surface_type=\"" << this->type << "\"" << std::endl; + s_oss << indent1; + //s_oss << "diffuse_layer=\"" << this->diffuse_layer << "\"" << std::endl; + s_oss << "surface_type=\"" << this->type << "\"" << std::endl; - s_oss << indent1; - //s_oss << "edl=\"" << this->edl << "\"" << std::endl; + s_oss << indent1; + //s_oss << "edl=\"" << this->edl << "\"" << std::endl; s_oss << "dl_type=\"" << this->dl_type << "\"" << std::endl; - s_oss << indent1; + s_oss << indent1; s_oss << "sites_units=\"" << this->sites_units << "\"" << std::endl; - s_oss << indent1; - s_oss << "only_counter_ions=\"" << this->only_counter_ions << "\"" << std::endl; + s_oss << indent1; + s_oss << "only_counter_ions=\"" << this-> + only_counter_ions << "\"" << std::endl; - //s_oss << indent1; - //s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; + //s_oss << indent1; + //s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; - s_oss << indent1; - s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; + s_oss << indent1; + s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; - s_oss << indent1; - s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << std::endl; + s_oss << indent1; + s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << std::endl; - s_oss << indent1; - s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << std::endl; + s_oss << indent1; + s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << std::endl; - s_oss << indent1; - s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << std::endl; + s_oss << indent1; + s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << std::endl; - s_oss << indent1; - s_oss << "transport=\"" << this->transport << "\"" << std::endl; + s_oss << indent1; + s_oss << "transport=\"" << this->transport << "\"" << std::endl; - // surface component structures - s_oss << indent1; - s_oss << "::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } - } - // surface charge structures - s_oss << indent1; - s_oss << "::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // surface component structures + s_oss << indent1; + s_oss << "::const_iterator it = + this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } + } + // surface charge structures + s_oss << indent1; + s_oss << "::const_iterator it = + surfaceCharges.begin(); it != surfaceCharges.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } -void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surface element and attributes - s_oss << indent0; - s_oss << "SURFACE_RAW " << this->n_user << " " << this->description << std::endl; + // Surface element and attributes + s_oss << indent0; + s_oss << "SURFACE_RAW " << this->n_user << " " << this-> + description << std::endl; - s_oss << indent1; - //s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; - s_oss << "-type " << this->type << std::endl; + s_oss << indent1; + //s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; + s_oss << "-type " << this->type << std::endl; - s_oss << indent1; - //s_oss << "-edl " << this->edl << std::endl; + s_oss << indent1; + //s_oss << "-edl " << this->edl << std::endl; s_oss << "-dl_type " << this->dl_type << std::endl; - s_oss << indent1; + s_oss << indent1; s_oss << "-sites_units " << this->sites_units << std::endl; - s_oss << indent1; - s_oss << "-only_counter_ions " << this->only_counter_ions << std::endl; + s_oss << indent1; + s_oss << "-only_counter_ions " << this->only_counter_ions << std::endl; - //s_oss << indent1; - //s_oss << "-donnan " << this->donnan << std::endl; + //s_oss << indent1; + //s_oss << "-donnan " << this->donnan << std::endl; - s_oss << indent1; - s_oss << "-thickness " << this->thickness << std::endl; + s_oss << indent1; + s_oss << "-thickness " << this->thickness << std::endl; - s_oss << indent1; - s_oss << "-debye_lengths " << this->debye_lengths << std::endl; + s_oss << indent1; + s_oss << "-debye_lengths " << this->debye_lengths << std::endl; - s_oss << indent1; - s_oss << "-DDL_viscosity " << this->DDL_viscosity << std::endl; + s_oss << indent1; + s_oss << "-DDL_viscosity " << this->DDL_viscosity << std::endl; - s_oss << indent1; - s_oss << "-DDL_limit " << this->DDL_limit << std::endl; + s_oss << indent1; + s_oss << "-DDL_limit " << this->DDL_limit << std::endl; - s_oss << indent1; - s_oss << "-transport " << this->transport << std::endl; + s_oss << indent1; + s_oss << "-transport " << this->transport << std::endl; - // surfaceComps structures - for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { - s_oss << indent1; - s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); - } - // surface charge structures - { - for (std::list::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { - s_oss << indent1; - s_oss << "-charge_component " << std::endl; - it->dump_raw(s_oss, indent + 2); - } - } + // surfaceComps structures + for (std::list < cxxSurfaceComp >::const_iterator it = + surfaceComps.begin(); it != surfaceComps.end(); ++it) + { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } + // surface charge structures + { + for (std::list < cxxSurfaceCharge >::const_iterator it = + surfaceCharges.begin(); it != surfaceCharges.end(); ++it) + { + s_oss << indent1; + s_oss << "-charge_component " << std::endl; + it->dump_raw(s_oss, indent + 2); + } + } - return; + return; } -void cxxSurface::read_raw(CParser& parser) +void +cxxSurface::read_raw(CParser & parser) { - static std::vector vopts; + static std::vector < std::string > vopts; int i = 0; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("diffuse_layer"); // 0 - vopts.push_back("edl"); // 1 - vopts.push_back("only_counter_ions"); // 2 - vopts.push_back("donnan"); // 3 - vopts.push_back("thickness"); // 4 - vopts.push_back("component"); // 5 - vopts.push_back("charge_component"); // 6 - vopts.push_back("type "); // 7 - vopts.push_back("dl_type"); // 8 - vopts.push_back("sites_units"); // 9 - vopts.push_back("debye_lengths"); // 10 - vopts.push_back("ddl_viscosity"); // 11 - vopts.push_back("ddl_limit"); // 12 - vopts.push_back("transport"); // 13 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("diffuse_layer"); // 0 + vopts.push_back("edl"); // 1 + vopts.push_back("only_counter_ions"); // 2 + vopts.push_back("donnan"); // 3 + vopts.push_back("thickness"); // 4 + vopts.push_back("component"); // 5 + vopts.push_back("charge_component"); // 6 + vopts.push_back("type "); // 7 + vopts.push_back("dl_type"); // 8 + vopts.push_back("sites_units"); // 9 + vopts.push_back("debye_lengths"); // 10 + vopts.push_back("ddl_viscosity"); // 11 + vopts.push_back("ddl_limit"); // 12 + vopts.push_back("transport"); // 13 + } - // Read surface number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; - //bool diffuse_layer_defined(false); - //bool edl_defined(false); - bool only_counter_ions_defined(false); - //bool donnan_defined(false); - bool thickness_defined(false); + // Read surface number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + //bool diffuse_layer_defined(false); + //bool edl_defined(false); + bool only_counter_ions_defined(false); + //bool donnan_defined(false); + bool thickness_defined(false); bool type_defined(false); bool dl_type_defined(false); bool sites_units_defined(false); @@ -361,263 +405,306 @@ void cxxSurface::read_raw(CParser& parser) bool DDL_limit_defined(false); bool transport_defined(false); - for (;;) - { - int opt; - if (useLastLine == false) { - opt = parser.get_option(vopts, next_char); - } else { - opt = parser.getOptionFromLastLine(vopts, next_char); - } - 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 SURFACE keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + for (;;) + { + int opt; + if (useLastLine == false) + { + opt = parser.get_option(vopts, next_char); + } + else + { + opt = parser.getOptionFromLastLine(vopts, next_char); + } + 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 SURFACE keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; - case 0: // diffuse_layer + case 0: // diffuse_layer parser.incr_input_error(); - parser.error_msg("Diffuse layer is obsolete, use -type.", CParser::OT_CONTINUE); + parser.error_msg("Diffuse layer is obsolete, use -type.", + CParser::OT_CONTINUE); /* - if (!(parser.get_iss() >> this->diffuse_layer)) - { - this->diffuse_layer = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for diffuse_layer.", CParser::OT_CONTINUE); - } - diffuse_layer_defined = true; - */ - useLastLine = false; - break; + if (!(parser.get_iss() >> this->diffuse_layer)) + { + this->diffuse_layer = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for diffuse_layer.", CParser::OT_CONTINUE); + } + diffuse_layer_defined = true; + */ + useLastLine = false; + break; - case 1: // edl + case 1: // edl parser.incr_input_error(); - parser.error_msg("-edl is obsolete, use -type.", CParser::OT_CONTINUE); + parser.error_msg("-edl is obsolete, use -type.", + CParser::OT_CONTINUE); /* - if (!(parser.get_iss() >> this->edl)) - { - this->edl = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for edl.", CParser::OT_CONTINUE); - } - edl_defined = true; - */ - useLastLine = false; - break; + if (!(parser.get_iss() >> this->edl)) + { + this->edl = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for edl.", CParser::OT_CONTINUE); + } + edl_defined = true; + */ + useLastLine = false; + break; - case 2: // only_counter_ions - if (!(parser.get_iss() >> this->only_counter_ions)) - { - this->only_counter_ions = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for only_counter_ions.", CParser::OT_CONTINUE); - } - only_counter_ions_defined = true; - useLastLine = false; - break; + case 2: // only_counter_ions + if (!(parser.get_iss() >> this->only_counter_ions)) + { + this->only_counter_ions = false; + parser.incr_input_error(); + parser. + error_msg("Expected boolean value for only_counter_ions.", + CParser::OT_CONTINUE); + } + only_counter_ions_defined = true; + useLastLine = false; + break; - case 3: // donnan + case 3: // donnan parser.incr_input_error(); - parser.error_msg("-Donnan is obsolete, use -dl_type.", CParser::OT_CONTINUE); + parser.error_msg("-Donnan is obsolete, use -dl_type.", + CParser::OT_CONTINUE); /* - if (!(parser.get_iss() >> this->donnan)) - { - this->donnan = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for donnan.", CParser::OT_CONTINUE); - } - donnan_defined = true; - */ - useLastLine = false; - break; + if (!(parser.get_iss() >> this->donnan)) + { + this->donnan = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for donnan.", CParser::OT_CONTINUE); + } + donnan_defined = true; + */ + useLastLine = false; + break; - case 4: // thickness - if (!(parser.get_iss() >> this->thickness)) - { - this->thickness = 0.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for thickness.", CParser::OT_CONTINUE); - } - thickness_defined = true; - useLastLine = false; - break; + case 4: // thickness + if (!(parser.get_iss() >> this->thickness)) + { + this->thickness = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for thickness.", + CParser::OT_CONTINUE); + } + thickness_defined = true; + useLastLine = false; + break; - case 5: // component - { - cxxSurfaceComp ec; - ec.read_raw(parser); - this->surfaceComps.push_back(ec); - } - useLastLine = true; - break; + case 5: // component + { + cxxSurfaceComp ec; + ec.read_raw(parser); + this->surfaceComps.push_back(ec); + } + useLastLine = true; + break; - case 6: // charge_component - { - cxxSurfaceCharge ec; - ec.read_raw(parser); - this->surfaceCharges.push_back(ec); - } - useLastLine = true; - break; - case 7: // type + case 6: // charge_component + { + cxxSurfaceCharge ec; + ec.read_raw(parser); + this->surfaceCharges.push_back(ec); + } + useLastLine = true; + break; + case 7: // type i = 0; - if (!(parser.get_iss() >> i)) - { - this->type = NO_EDL; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for type.", CParser::OT_CONTINUE); - } + if (!(parser.get_iss() >> i)) + { + this->type = NO_EDL; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for type.", + CParser::OT_CONTINUE); + } this->type = (SURFACE_TYPE) i; - type_defined = true; - useLastLine = false; - break; - case 8: // dl_type + type_defined = true; + useLastLine = false; + break; + case 8: // dl_type i = 0; if (!(parser.get_iss() >> i)) { this->dl_type = NO_DL; parser.incr_input_error(); - parser.error_msg("Expected numeric value for dl_type.", CParser::OT_CONTINUE); + parser.error_msg("Expected numeric value for dl_type.", + CParser::OT_CONTINUE); } this->dl_type = (DIFFUSE_LAYER_TYPE) i; - dl_type_defined = true; - useLastLine = false; - break; - case 9: // sites_units + dl_type_defined = true; + useLastLine = false; + break; + case 9: // sites_units i = 0; - if (!(parser.get_iss() >> i)) - { - this->sites_units = SITES_ABSOLUTE; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for sites_units.", CParser::OT_CONTINUE); - } + if (!(parser.get_iss() >> i)) + { + this->sites_units = SITES_ABSOLUTE; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sites_units.", + CParser::OT_CONTINUE); + } this->sites_units = (SITES_UNITS) i; - sites_units_defined = true; - useLastLine = false; - break; + sites_units_defined = true; + useLastLine = false; + break; - case 10: // debye_lengths - if (!(parser.get_iss() >> this->debye_lengths)) - { - this->debye_lengths = 0.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for debye_lengths.", CParser::OT_CONTINUE); - } - debye_lengths_defined = true; - useLastLine = false; - break; + case 10: // debye_lengths + if (!(parser.get_iss() >> this->debye_lengths)) + { + this->debye_lengths = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for debye_lengths.", + CParser::OT_CONTINUE); + } + debye_lengths_defined = true; + useLastLine = false; + break; - case 11: // DDL_viscosity - if (!(parser.get_iss() >> this->DDL_viscosity)) - { - this->DDL_viscosity = 0.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for DDL_viscosity.", CParser::OT_CONTINUE); - } - DDL_viscosity_defined = true; - useLastLine = false; - break; + case 11: // DDL_viscosity + if (!(parser.get_iss() >> this->DDL_viscosity)) + { + this->DDL_viscosity = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for DDL_viscosity.", + CParser::OT_CONTINUE); + } + DDL_viscosity_defined = true; + useLastLine = false; + break; - case 12: // DDL_limit - if (!(parser.get_iss() >> this->DDL_limit)) - { - this->DDL_limit = 0.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for DDL_limit.", CParser::OT_CONTINUE); - } - DDL_limit_defined = true; - useLastLine = false; - break; + case 12: // DDL_limit + if (!(parser.get_iss() >> this->DDL_limit)) + { + this->DDL_limit = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for DDL_limit.", + CParser::OT_CONTINUE); + } + DDL_limit_defined = true; + useLastLine = false; + break; - case 13: // transport - if (!(parser.get_iss() >> this->transport)) - { - this->transport = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for transport.", CParser::OT_CONTINUE); - } - transport_defined = true; - useLastLine = false; - break; - } + case 13: // transport + if (!(parser.get_iss() >> this->transport)) + { + this->transport = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for transport.", + CParser::OT_CONTINUE); + } + transport_defined = true; + useLastLine = false; + break; + } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined /* - if (diffuse_layer_defined == false) { - parser.incr_input_error(); - parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (edl_defined == false) { - parser.incr_input_error(); - parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (only_counter_ions_defined == false) { - parser.incr_input_error(); - parser.error_msg("Only_counter_ions not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } + if (diffuse_layer_defined == false) { + parser.incr_input_error(); + parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (edl_defined == false) { + parser.incr_input_error(); + parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (only_counter_ions_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Only_counter_ions not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } /* - if (donnan_defined == false) { - parser.incr_input_error(); - parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (thickness_defined == false) { - parser.incr_input_error(); - parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (type_defined == false) { - parser.incr_input_error(); - parser.error_msg("Surface type not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (dl_type_defined == false) { - parser.incr_input_error(); - parser.error_msg("Dl_type not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (sites_units_defined == false) { - parser.incr_input_error(); - parser.error_msg("Sites_units not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (debye_lengths_defined == false) { - parser.incr_input_error(); - parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (DDL_viscosity_defined == false) { - parser.incr_input_error(); - parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (DDL_limit_defined == false) { - parser.incr_input_error(); - parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (transport_defined == false) { - parser.incr_input_error(); - parser.error_msg("Transport not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } + if (donnan_defined == false) { + parser.incr_input_error(); + parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (thickness_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Thickness not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Surface type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (dl_type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Dl_type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (sites_units_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Sites_units not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (debye_lengths_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_viscosity_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_limit_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (transport_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Transport not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI /* ---------------------------------------------------------------------- */ -void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->surfaceComps.size()); - for (std::list::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) { + for (std::list < cxxSurfaceComp >::iterator it = + this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) + { it->mpi_pack(ints, doubles); } ints.push_back((int) this->surfaceCharges.size()); - for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) { + for (std::list < cxxSurfaceCharge >::iterator it = + this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) + { it->mpi_pack(ints, doubles); } //ints.push_back((int) this->diffuse_layer); @@ -625,7 +712,7 @@ void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) ints.push_back((int) this->type); ints.push_back((int) this->dl_type); ints.push_back((int) this->sites_units); - + ints.push_back((int) this->only_counter_ions); //ints.push_back((int) this->donnan); doubles.push_back(this->thickness); @@ -634,8 +721,10 @@ void cxxSurface::mpi_pack(std::vector& ints, std::vector& doubles) doubles.push_back(this->DDL_limit); ints.push_back((int) this->transport); } + /* ---------------------------------------------------------------------- */ -void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +void +cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -647,14 +736,16 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) int count = ints[i++]; this->surfaceComps.clear(); - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { cxxSurfaceComp sc; sc.mpi_unpack(ints, &i, doubles, &d); this->surfaceComps.push_back(sc); } count = ints[i++]; this->surfaceCharges.clear(); - for (int n = 0; n < count; n++) { + for (int n = 0; n < count; n++) + { cxxSurfaceCharge sc; sc.mpi_unpack(ints, &i, doubles, &d); this->surfaceCharges.push_back(sc); @@ -676,97 +767,109 @@ void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif -void cxxSurface::totalize() +void +cxxSurface::totalize() { - this->totals.clear(); - // component structures - for (std::list::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) - { - this->totals.add_extensive(it->get_totals(), 1.0); - this->totals.add("Charge", it->get_charge_balance()); - } - return; + this->totals.clear(); + // component structures + for (std::list < cxxSurfaceComp >::const_iterator it = + surfaceComps.begin(); it != surfaceComps.end(); ++it) + { + this->totals.add_extensive(it->get_totals(), 1.0); + this->totals.add("Charge", it->get_charge_balance()); + } + return; } -void cxxSurface::add(const cxxSurface &addee, double extensive) - // - // Add surface to "this" exchange - // +void +cxxSurface::add(const cxxSurface & addee, double extensive) + // + // Add surface to "this" exchange + // { - //std::list surfaceComps; - //std::list surfaceCharges; - //enum SURFACE_TYPE type; - //enum DIFFUSE_LAYER_TYPE dl_type; - //enum SITES_UNITS sites_units; - //bool only_counter_ions; - //double thickness; - //double debye_lengths; - //double DDL_viscosity; - //double DDL_limit; - //bool transport; - if (extensive == 0.0) return; - if (this->surfaceComps.size() == 0) - { - //enum SURFACE_TYPE type; - this->type = addee.type; - //enum DIFFUSE_LAYER_TYPE dl_type; - this->dl_type = addee.dl_type; - //enum SITES_UNITS sites_units; - this->sites_units = addee.sites_units; - //bool only_counter_ions; - this->only_counter_ions = addee.only_counter_ions; - //double thickness; - this->thickness = addee.thickness; - //double debye_lengths; - this->debye_lengths = addee.debye_lengths; - //double DDL_viscosity; - this->DDL_viscosity = addee.DDL_viscosity; - //double DDL_limit; - this->DDL_limit = addee.DDL_limit; - //bool transport; - this->transport = addee.transport; - } - //std::list surfaceComps; + //std::list surfaceComps; + //std::list surfaceCharges; + //enum SURFACE_TYPE type; + //enum DIFFUSE_LAYER_TYPE dl_type; + //enum SITES_UNITS sites_units; + //bool only_counter_ions; + //double thickness; + //double debye_lengths; + //double DDL_viscosity; + //double DDL_limit; + //bool transport; + if (extensive == 0.0) + return; + if (this->surfaceComps.size() == 0) + { + //enum SURFACE_TYPE type; + this->type = addee.type; + //enum DIFFUSE_LAYER_TYPE dl_type; + this->dl_type = addee.dl_type; + //enum SITES_UNITS sites_units; + this->sites_units = addee.sites_units; + //bool only_counter_ions; + this->only_counter_ions = addee.only_counter_ions; + //double thickness; + this->thickness = addee.thickness; + //double debye_lengths; + this->debye_lengths = addee.debye_lengths; + //double DDL_viscosity; + this->DDL_viscosity = addee.DDL_viscosity; + //double DDL_limit; + this->DDL_limit = addee.DDL_limit; + //bool transport; + this->transport = addee.transport; + } + //std::list surfaceComps; - for (std::list::const_iterator itadd = addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); ++itadd) - { - bool found = false; - for (std::list::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) - { - if (it->get_formula() == itadd->get_formula()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) { - cxxSurfaceComp entity = *itadd; - entity.multiply(extensive); - //exc.add(*itadd, extensive); - this->surfaceComps.push_back(entity); - } - } - //std::list surfaceCharges; - for (std::list::const_iterator itadd = addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); ++itadd) - { - bool found = false; - for (std::list::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); ++it) - { - if (it->get_name() == itadd->get_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) { - cxxSurfaceCharge entity = *itadd; - entity.multiply(extensive); - //exc.add(*itadd, extensive); - this->surfaceCharges.push_back(entity); - } - } + for (std::list < cxxSurfaceComp >::const_iterator itadd = + addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); + ++itadd) + { + bool found = false; + for (std::list < cxxSurfaceComp >::iterator it = + this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + { + if (it->get_formula() == itadd->get_formula()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) + { + cxxSurfaceComp entity = *itadd; + entity.multiply(extensive); + //exc.add(*itadd, extensive); + this->surfaceComps.push_back(entity); + } + } + //std::list surfaceCharges; + for (std::list < cxxSurfaceCharge >::const_iterator itadd = + addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); + ++itadd) + { + bool found = false; + for (std::list < cxxSurfaceCharge >::iterator it = + this->surfaceCharges.begin(); it != this->surfaceCharges.end(); + ++it) + { + if (it->get_name() == itadd->get_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) + { + cxxSurfaceCharge entity = *itadd; + entity.multiply(extensive); + //exc.add(*itadd, extensive); + this->surfaceCharges.push_back(entity); + } + } } - diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 13bd836a..886c427c 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -2,10 +2,10 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "SurfaceCharge.h" #include "Dictionary.h" #define EXTERNAL extern @@ -13,397 +13,474 @@ #include "output.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSurfaceCharge::cxxSurfaceCharge() - // - // default constructor for cxxSurfaceCharge - // + // + // default constructor for cxxSurfaceCharge + // { - name = NULL; - specific_area = 0.0; - grams = 0.0; - charge_balance = 0.0; - mass_water = 0.0; - la_psi = 0.0; - la_psi1 = 0.0; - la_psi2 = 0.0; - capacitance[0] = 1.0; - capacitance[1] = 5.0; - diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; + name = NULL; + specific_area = 0.0; + grams = 0.0; + charge_balance = 0.0; + mass_water = 0.0; + la_psi = 0.0; + la_psi1 = 0.0; + la_psi2 = 0.0; + capacitance[0] = 1.0; + capacitance[1] = 5.0; + diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; } cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr) - // - // constructor for cxxSurfaceCharge from struct surface_charge - // -: + // + // constructor for cxxSurfaceCharge from struct surface_charge + // + : diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) { - name = surf_charge_ptr->name; - specific_area = surf_charge_ptr->specific_area; - grams = surf_charge_ptr->grams; - charge_balance = surf_charge_ptr->charge_balance; - mass_water = surf_charge_ptr->mass_water; - la_psi = surf_charge_ptr->la_psi; - la_psi1 = surf_charge_ptr->la_psi1; - la_psi2 = surf_charge_ptr->la_psi2; - capacitance[0] = surf_charge_ptr->capacitance[0]; - capacitance[1] = surf_charge_ptr->capacitance[1]; + name = surf_charge_ptr->name; + specific_area = surf_charge_ptr->specific_area; + grams = surf_charge_ptr->grams; + charge_balance = surf_charge_ptr->charge_balance; + mass_water = surf_charge_ptr->mass_water; + la_psi = surf_charge_ptr->la_psi; + la_psi1 = surf_charge_ptr->la_psi1; + la_psi2 = surf_charge_ptr->la_psi2; + capacitance[0] = surf_charge_ptr->capacitance[0]; + capacitance[1] = surf_charge_ptr->capacitance[1]; } cxxSurfaceCharge::~cxxSurfaceCharge() { } -struct master *cxxSurfaceCharge::get_psi_master() -{ - struct master *master_ptr = NULL; - std::string str = this->name; +struct master * +cxxSurfaceCharge::get_psi_master() +{ + struct master *master_ptr = NULL; + std::string str = this->name; - str.append("_psi"); - master_ptr = master_bsearch(str.c_str()); - if (master_ptr == NULL) { - std::ostringstream error_oss; - error_oss << "Surface charge psi_master not found." << this->name << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); + str.append("_psi"); + master_ptr = master_bsearch(str.c_str()); + if (master_ptr == NULL) + { + std::ostringstream error_oss; + error_oss << "Surface charge psi_master not found." << this-> + name << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); error_msg(error_oss.str().c_str(), CONTINUE); - } - return(master_ptr); + } + return (master_ptr); } -struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list& el) - // - // Builds surface_charge structure from of cxxSurfaceCharge - // +struct surface_charge * +cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list < + cxxSurfaceCharge > &el) + // + // Builds surface_charge structure from of cxxSurfaceCharge + // { - struct surface_charge *surf_charge_ptr = (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); - if (surf_charge_ptr == NULL) malloc_error(); + struct surface_charge *surf_charge_ptr = + (struct surface_charge *) + PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); + if (surf_charge_ptr == NULL) + malloc_error(); - int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - surf_charge_ptr[i].name = it->name; - surf_charge_ptr[i].specific_area = it->specific_area; - surf_charge_ptr[i].grams = it->grams; - surf_charge_ptr[i].charge_balance = it->charge_balance; - surf_charge_ptr[i].mass_water = it->mass_water; - surf_charge_ptr[i].la_psi = it->la_psi; - surf_charge_ptr[i].la_psi1 = it->la_psi1; - surf_charge_ptr[i].la_psi2 = it->la_psi2; - surf_charge_ptr[i].capacitance[0] = it->capacitance[0]; - surf_charge_ptr[i].capacitance[1] = it->capacitance[1]; - surf_charge_ptr[i].sigma0 = 0; - surf_charge_ptr[i].sigma1 = 0; - surf_charge_ptr[i].sigma2 = 0; - surf_charge_ptr[i].sigmaddl = 0; - surf_charge_ptr[i].diffuse_layer_totals = it->diffuse_layer_totals.elt_list(); - //surf_charge_ptr[i].psi_master = it->get_psi_master(); - surf_charge_ptr[i].count_g = 0; - surf_charge_ptr[i].g = NULL; - i++; - } - return(surf_charge_ptr); + int i = 0; + for (std::list < cxxSurfaceCharge >::iterator it = el.begin(); + it != el.end(); ++it) + { + surf_charge_ptr[i].name = it->name; + surf_charge_ptr[i].specific_area = it->specific_area; + surf_charge_ptr[i].grams = it->grams; + surf_charge_ptr[i].charge_balance = it->charge_balance; + surf_charge_ptr[i].mass_water = it->mass_water; + surf_charge_ptr[i].la_psi = it->la_psi; + surf_charge_ptr[i].la_psi1 = it->la_psi1; + surf_charge_ptr[i].la_psi2 = it->la_psi2; + surf_charge_ptr[i].capacitance[0] = it->capacitance[0]; + surf_charge_ptr[i].capacitance[1] = it->capacitance[1]; + surf_charge_ptr[i].sigma0 = 0; + surf_charge_ptr[i].sigma1 = 0; + surf_charge_ptr[i].sigma2 = 0; + surf_charge_ptr[i].sigmaddl = 0; + surf_charge_ptr[i].diffuse_layer_totals = + it->diffuse_layer_totals.elt_list(); + //surf_charge_ptr[i].psi_master = it->get_psi_master(); + surf_charge_ptr[i].count_g = 0; + surf_charge_ptr[i].g = NULL; + i++; + } + return (surf_charge_ptr); } -void cxxSurfaceCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surf_Charge element and attributes + // Surf_Charge element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; - s_oss << indent0 << "specific_area=\"" << this->specific_area << "\"" << std::endl; - s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl; - s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; - s_oss << indent0 << "mass_water=\"" << this->mass_water << "\"" << std::endl; - s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl; - s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl; - s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl; - s_oss << indent0 << "capacitance=\"" << this->capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "specific_area=\"" << this-> + specific_area << "\"" << std::endl; + s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this-> + charge_balance << "\"" << std::endl; + s_oss << indent0 << "mass_water=\"" << this-> + mass_water << "\"" << std::endl; + s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl; + s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl; + s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl; + s_oss << indent0 << "capacitance=\"" << this-> + capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl; - // totals - s_oss << indent0; - s_oss << "diffuse_layer_totals.dump_xml(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "diffuse_layer_totals.dump_xml(s_oss, indent + 1); } -void cxxSurfaceCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surf_Charge element and attributes + // Surf_Charge element and attributes - s_oss << indent0 << "-name " << this->name << std::endl; - s_oss << indent0 << "-specific_area " << this->specific_area << std::endl; - s_oss << indent0 << "-grams " << this->grams << std::endl; - s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; - s_oss << indent0 << "-mass_water " << this->mass_water << std::endl; - s_oss << indent0 << "-la_psi " << this->la_psi << std::endl; - s_oss << indent0 << "-la_psi1 " << this->la_psi1 << std::endl; - s_oss << indent0 << "-la_psi2 " << this->la_psi2 << std::endl; - s_oss << indent0 << "-capacitance0 " << this->capacitance[0] << std::endl; - s_oss << indent0 << "-capacitance1 " << this->capacitance[1] << std::endl; + s_oss << indent0 << "-name " << this->name << std::endl; + s_oss << indent0 << "-specific_area " << this-> + specific_area << std::endl; + s_oss << indent0 << "-grams " << this->grams << std::endl; + s_oss << indent0 << "-charge_balance " << this-> + charge_balance << std::endl; + s_oss << indent0 << "-mass_water " << this-> + mass_water << std::endl; + s_oss << indent0 << "-la_psi " << this-> + la_psi << std::endl; + s_oss << indent0 << "-la_psi1 " << this-> + la_psi1 << std::endl; + s_oss << indent0 << "-la_psi2 " << this-> + la_psi2 << std::endl; + s_oss << indent0 << "-capacitance0 " << this-> + capacitance[0] << std::endl; + s_oss << indent0 << "-capacitance1 " << this-> + capacitance[1] << std::endl; - // totals - s_oss << indent0; - s_oss << "-diffuse_layer_totals" << std::endl; - this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "-diffuse_layer_totals" << std::endl; + this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); } -void cxxSurfaceCharge::read_raw(CParser& parser) +void +cxxSurfaceCharge::read_raw(CParser & parser) { - std::string str; - - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("name"); // 0 - vopts.push_back("specific_area"); // 1 - vopts.push_back("grams"); // 2 - vopts.push_back("charge_balance"); // 3 - vopts.push_back("mass_water"); // 4 - vopts.push_back("la_psi"); // 5 - vopts.push_back("diffuse_layer_totals"); // 6 - vopts.push_back("la_psi1"); // 7 - vopts.push_back("la_psi2"); // 8 - vopts.push_back("capacitance0"); // 9 - vopts.push_back("capacitance1"); // 10 - } + std::string str; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("specific_area"); // 1 + vopts.push_back("grams"); // 2 + vopts.push_back("charge_balance"); // 3 + vopts.push_back("mass_water"); // 4 + vopts.push_back("la_psi"); // 5 + vopts.push_back("diffuse_layer_totals"); // 6 + vopts.push_back("la_psi1"); // 7 + vopts.push_back("la_psi2"); // 8 + vopts.push_back("capacitance0"); // 9 + vopts.push_back("capacitance1"); // 10 + } - opt_save = CParser::OPT_ERROR; - bool name_defined(false); - bool specific_area_defined(false); - bool grams_defined(false); - bool charge_balance_defined(false); - bool mass_water_defined(false); - bool la_psi_defined(false); - bool la_psi1_defined(false); - bool la_psi2_defined(false); - bool capacitance0_defined(false); - bool capacitance1_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + bool specific_area_defined(false); + bool grams_defined(false); + bool charge_balance_defined(false); + bool mass_water_defined(false); + bool la_psi_defined(false); + bool la_psi1_defined(false); + bool la_psi2_defined(false); + bool capacitance0_defined(false); + bool capacitance1_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); - } else { - this->name = string_hsave(str.c_str()); - } - name_defined = true; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Surface for more processing + //parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 1: // specific_area - if (!(parser.get_iss() >> this->specific_area)) - { - this->specific_area = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for specific_area.", CParser::OT_CONTINUE); - } - specific_area_defined = true; - break; + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", + CParser::OT_CONTINUE); + } + else + { + this->name = string_hsave(str.c_str()); + } + name_defined = true; + break; - case 2: // grams - if (!(parser.get_iss() >> this->grams)) - { - this->grams = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for grams.", CParser::OT_CONTINUE); - } - grams_defined = true; - break; + case 1: // specific_area + if (!(parser.get_iss() >> this->specific_area)) + { + this->specific_area = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for specific_area.", + CParser::OT_CONTINUE); + } + specific_area_defined = true; + break; + + case 2: // grams + if (!(parser.get_iss() >> this->grams)) + { + this->grams = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for grams.", + CParser::OT_CONTINUE); + } + grams_defined = true; + break; - case 3: // charge_balance - if (!(parser.get_iss() >> this->charge_balance)) - { - this->charge_balance = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); - } - charge_balance_defined = true; - break; + case 3: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", + CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; - case 4: // mass_water - if (!(parser.get_iss() >> this->mass_water)) - { - this->mass_water = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for mass_water.", CParser::OT_CONTINUE); - } - mass_water_defined = true; - break; + case 4: // mass_water + if (!(parser.get_iss() >> this->mass_water)) + { + this->mass_water = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass_water.", + CParser::OT_CONTINUE); + } + mass_water_defined = true; + break; - case 5: // la_psi - if (!(parser.get_iss() >> this->la_psi)) - { - this->la_psi = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE); - } - la_psi_defined = true; - break; + case 5: // la_psi + if (!(parser.get_iss() >> this->la_psi)) + { + this->la_psi = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi.", + CParser::OT_CONTINUE); + } + la_psi_defined = true; + break; - case 6: // diffuse_layer_totals - if ( this->diffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", CParser::OT_CONTINUE); - } - opt_save = 6; - break; + case 6: // diffuse_layer_totals + if (this->diffuse_layer_totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", + CParser::OT_CONTINUE); + } + opt_save = 6; + break; - case 7: // la_psi1 - if (!(parser.get_iss() >> this->la_psi1)) - { - this->la_psi1 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la_psi1.", CParser::OT_CONTINUE); - } - la_psi1_defined = true; - break; + case 7: // la_psi1 + if (!(parser.get_iss() >> this->la_psi1)) + { + this->la_psi1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi1.", + CParser::OT_CONTINUE); + } + la_psi1_defined = true; + break; - case 8: // la_psi2 - if (!(parser.get_iss() >> this->la_psi2)) - { - this->la_psi2 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la_psi.", CParser::OT_CONTINUE); - } - la_psi2_defined = true; - break; + case 8: // la_psi2 + if (!(parser.get_iss() >> this->la_psi2)) + { + this->la_psi2 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la_psi.", + CParser::OT_CONTINUE); + } + la_psi2_defined = true; + break; - case 9: // capacitance0 - if (!(parser.get_iss() >> this->capacitance[0])) - { - this->capacitance[0] = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for capacitance0.", CParser::OT_CONTINUE); - } - capacitance0_defined = true; - break; + case 9: // capacitance0 + if (!(parser.get_iss() >> this->capacitance[0])) + { + this->capacitance[0] = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for capacitance0.", + CParser::OT_CONTINUE); + } + capacitance0_defined = true; + break; - case 10: // capacitance1 - if (!(parser.get_iss() >> this->capacitance[1])) - { - this->capacitance[1] = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for capacitance1.", CParser::OT_CONTINUE); - } - capacitance1_defined = true; - break; + case 10: // capacitance1 + if (!(parser.get_iss() >> this->capacitance[1])) + { + this->capacitance[1] = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for capacitance1.", + CParser::OT_CONTINUE); + } + capacitance1_defined = true; + break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (name_defined == false) { - parser.incr_input_error(); - parser.error_msg("Name not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (specific_area_defined == false) { - parser.incr_input_error(); - parser.error_msg("Specific_area not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (grams_defined == false) { - parser.incr_input_error(); - parser.error_msg("Grams not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (charge_balance_defined == false) { - parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (mass_water_defined == false) { - parser.incr_input_error(); - parser.error_msg("Mass_water not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (la_psi_defined == false) { - parser.incr_input_error(); - parser.error_msg("La_psi not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (la_psi1_defined == false) { - parser.incr_input_error(); - parser.error_msg("La_psi1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (la_psi2_defined == false) { - parser.incr_input_error(); - parser.error_msg("La_psi2 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (capacitance0_defined == false) { - parser.incr_input_error(); - parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } - if (capacitance1_defined == false) { - parser.incr_input_error(); - parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", CParser::OT_CONTINUE); - } + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (specific_area_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Specific_area not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (grams_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Grams not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Charge_balance not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Mass_water not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi1 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi2_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi2 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (capacitance0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (capacitance1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI -void cxxSurfaceCharge::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSurfaceCharge::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->name)); doubles.push_back(this->specific_area); doubles.push_back(this->grams); - doubles.push_back(this->charge_balance); - doubles.push_back(this->mass_water); - doubles.push_back(this->la_psi); - doubles.push_back(this->la_psi1); - doubles.push_back(this->la_psi2); - doubles.push_back(this->capacitance[0]); - doubles.push_back(this->capacitance[1]); + doubles.push_back(this->charge_balance); + doubles.push_back(this->mass_water); + doubles.push_back(this->la_psi); + doubles.push_back(this->la_psi1); + doubles.push_back(this->la_psi2); + doubles.push_back(this->capacitance[0]); + doubles.push_back(this->capacitance[1]); this->diffuse_layer_totals.mpi_pack(ints, doubles); } -void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -423,62 +500,72 @@ void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif -void cxxSurfaceCharge::add(const cxxSurfaceCharge &addee, double extensive) +void +cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) { - if (extensive == 0.0) return; - //char * name; - //double specific_area; - //double grams; - //double charge_balance; - //double mass_water; - //double la_psi, la_psi1, la_psi2; - //double capacitance[2]; + if (extensive == 0.0) + return; + //char * name; + //double specific_area; + //double grams; + //double charge_balance; + //double mass_water; + //double la_psi, la_psi1, la_psi2; + //double capacitance[2]; - //char * name; - if (this->name == NULL && addee.name == NULL) { - return; - } - assert (this->name == addee.name); - - double ext1, ext2, f1, f2; - ext1 = this->specific_area * this->grams; - ext2 = addee.specific_area * addee.grams * extensive; - if (ext1 + ext2 != 0) { - f1 = ext1/(ext1 + ext2); - f2 = ext2/(ext1 + ext2); - } else { - f1 = 0.5; - f2 = 0.5; - } + //char * name; + if (this->name == NULL && addee.name == NULL) + { + return; + } + assert(this->name == addee.name); - //double specific_area; - this->specific_area = f1*this->specific_area + f2*addee.specific_area; - //double grams; - this->grams += addee.grams * extensive; - //double charge_balance; - this->charge_balance += addee.charge_balance * extensive; - //double mass_water; - this->mass_water += addee.mass_water * extensive; - //double la_psi, la_psi1, la_psi2; - this->la_psi = this->la_psi*f1 + addee.la_psi*f2; - this->la_psi1 = this->la_psi1*f1 + addee.la_psi1*f2; - this->la_psi2 = this->la_psi2*f1 + addee.la_psi2*f2; - //double capacitance[2]; - this->capacitance[0] = this->capacitance[0]*f1 + this->capacitance[0]*f2; - this->capacitance[1] = this->capacitance[1]*f1 + this->capacitance[1]*f2; + double ext1, ext2, f1, f2; + ext1 = this->specific_area * this->grams; + ext2 = addee.specific_area * addee.grams * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } + + //double specific_area; + this->specific_area = f1 * this->specific_area + f2 * addee.specific_area; + //double grams; + this->grams += addee.grams * extensive; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //double mass_water; + this->mass_water += addee.mass_water * extensive; + //double la_psi, la_psi1, la_psi2; + this->la_psi = this->la_psi * f1 + addee.la_psi * f2; + this->la_psi1 = this->la_psi1 * f1 + addee.la_psi1 * f2; + this->la_psi2 = this->la_psi2 * f1 + addee.la_psi2 * f2; + //double capacitance[2]; + this->capacitance[0] = + this->capacitance[0] * f1 + this->capacitance[0] * f2; + this->capacitance[1] = + this->capacitance[1] * f1 + this->capacitance[1] * f2; } -void cxxSurfaceCharge::multiply(double extensive) + +void +cxxSurfaceCharge::multiply(double extensive) { - //char * name; - //double specific_area; - //double grams; - this->grams *= extensive; - //double charge_balance; - this->charge_balance *= extensive; - //double mass_water; - this->mass_water *= extensive; - //double la_psi, la_psi1, la_psi2; - //double capacitance[2]; - //cxxNameDouble diffuse_layer_totals; - this->diffuse_layer_totals.multiply(extensive); + //char * name; + //double specific_area; + //double grams; + this->grams *= extensive; + //double charge_balance; + this->charge_balance *= extensive; + //double mass_water; + this->mass_water *= extensive; + //double la_psi, la_psi1, la_psi2; + //double capacitance[2]; + //cxxNameDouble diffuse_layer_totals; + this->diffuse_layer_totals.multiply(extensive); } diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index b7c9d747..52007db0 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -2,10 +2,10 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "SurfaceComp.h" #include "Dictionary.h" #define EXTERNAL extern @@ -13,403 +13,488 @@ #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSurfaceComp::cxxSurfaceComp() - // - // default constructor for cxxSurfaceComp - // + // + // default constructor for cxxSurfaceComp + // { - formula = NULL; - formula_totals.type = cxxNameDouble::ND_ELT_MOLES; - formula_z = 0.0; - moles = 0.0; - totals.type = cxxNameDouble::ND_ELT_MOLES; - la = 0.0; - //charge_number = -99; - charge_balance = 0; - phase_name = NULL; - phase_proportion = 0.0; - rate_name = NULL; - Dw = 0.0; + formula = NULL; + formula_totals.type = cxxNameDouble::ND_ELT_MOLES; + formula_z = 0.0; + moles = 0.0; + totals.type = cxxNameDouble::ND_ELT_MOLES; + la = 0.0; + //charge_number = -99; + charge_balance = 0; + phase_name = NULL; + phase_proportion = 0.0; + rate_name = NULL; + Dw = 0.0; } cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) - // - // constructor for cxxSurfaceComp from struct surface_comp - // -: + // + // constructor for cxxSurfaceComp from struct surface_comp + // + : formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { - formula = surf_comp_ptr->formula; - formula_z = surf_comp_ptr->formula_z; - moles = surf_comp_ptr->moles; - la = surf_comp_ptr->la; - //charge_number = surf_comp_ptr->charge; - charge_balance = surf_comp_ptr->cb; - phase_name = surf_comp_ptr->phase_name; - phase_proportion = surf_comp_ptr->phase_proportion; - rate_name = surf_comp_ptr->rate_name; - Dw = surf_comp_ptr->Dw; + formula = surf_comp_ptr->formula; + formula_z = surf_comp_ptr->formula_z; + moles = surf_comp_ptr->moles; + la = surf_comp_ptr->la; + //charge_number = surf_comp_ptr->charge; + charge_balance = surf_comp_ptr->cb; + phase_name = surf_comp_ptr->phase_name; + phase_proportion = surf_comp_ptr->phase_proportion; + rate_name = surf_comp_ptr->rate_name; + Dw = surf_comp_ptr->Dw; } cxxSurfaceComp::~cxxSurfaceComp() { } -struct master *cxxSurfaceComp::get_master() -{ - struct master *master_ptr = NULL; - //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { - for (cxxNameDouble::iterator it = this->totals.begin(); it != this->totals.end(); it++) { - /* Find master species */ - char *eltName = it->first; - struct element *elt_ptr = element_store(eltName); - if (elt_ptr->master == NULL) { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); +struct master * +cxxSurfaceComp::get_master() +{ + struct master *master_ptr = NULL; + //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { + for (cxxNameDouble::iterator it = this->totals.begin(); + it != this->totals.end(); it++) + { + /* Find master species */ + char *eltName = it->first; + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) + { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr-> + name << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); error_msg(error_oss.str().c_str(), CONTINUE); - return(NULL); - } - if (elt_ptr->master->type != SURF) continue; - master_ptr = elt_ptr->master; - break; - } - if (master_ptr == NULL) { - std::ostringstream error_oss; - error_oss << "Surface formula does not contain an surface master species, " << this->formula << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); + return (NULL); + } + if (elt_ptr->master->type != SURF) + continue; + master_ptr = elt_ptr->master; + break; } - return(master_ptr); + if (master_ptr == NULL) + { + std::ostringstream error_oss; + error_oss << + "Surface formula does not contain an surface master species, " << + this->formula << std::endl; + //Utilities::error_msg(error_oss.str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); + } + return (master_ptr); } -struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list& el) - // - // Builds surface_comp structure from of cxxSurfaceComp - // +struct surface_comp * +cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list < cxxSurfaceComp > &el) + // + // Builds surface_comp structure from of cxxSurfaceComp + // { - struct surface_comp *surf_comp_ptr = (struct surface_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); - if (surf_comp_ptr == NULL) malloc_error(); + struct surface_comp *surf_comp_ptr = + (struct surface_comp *) + PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); + if (surf_comp_ptr == NULL) + malloc_error(); - int i = 0; - for (std::list::iterator it = el.begin(); it != el.end(); ++it) { - surf_comp_ptr[i].formula = it->formula; - surf_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); - surf_comp_ptr[i].formula_z = it->formula_z; - surf_comp_ptr[i].moles = it->moles; - surf_comp_ptr[i].master = it->get_master(); - surf_comp_ptr[i].totals = it->totals.elt_list(); - surf_comp_ptr[i].la = it->la; - //surf_comp_ptr[i].charge = it->charge_number; - surf_comp_ptr[i].cb = it->charge_balance; - surf_comp_ptr[i].phase_name = it->phase_name; - surf_comp_ptr[i].phase_proportion = it->phase_proportion; - surf_comp_ptr[i].rate_name = it->rate_name; - surf_comp_ptr[i].Dw = it->Dw; - surf_comp_ptr[i].master = it->get_master(); - i++; - } - return(surf_comp_ptr); + int i = 0; + for (std::list < cxxSurfaceComp >::iterator it = el.begin(); + it != el.end(); ++it) + { + surf_comp_ptr[i].formula = it->formula; + surf_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); + surf_comp_ptr[i].formula_z = it->formula_z; + surf_comp_ptr[i].moles = it->moles; + surf_comp_ptr[i].master = it->get_master(); + surf_comp_ptr[i].totals = it->totals.elt_list(); + surf_comp_ptr[i].la = it->la; + //surf_comp_ptr[i].charge = it->charge_number; + surf_comp_ptr[i].cb = it->charge_balance; + surf_comp_ptr[i].phase_name = it->phase_name; + surf_comp_ptr[i].phase_proportion = it->phase_proportion; + surf_comp_ptr[i].rate_name = it->rate_name; + surf_comp_ptr[i].Dw = it->Dw; + surf_comp_ptr[i].master = it->get_master(); + i++; + } + return (surf_comp_ptr); } -void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surf_Comp element and attributes + // Surf_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; - s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; - //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; - s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << std::endl; - if (this->phase_name != NULL) { - s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; - } - if (this->rate_name != NULL) { - s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << std::endl; - } - s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << std::endl; - s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula_z=\"" << this-> + formula_z << "\"" << std::endl; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; + s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; + s_oss << indent0 << "charge_balance=\"" << this-> + charge_balance << "\"" << std::endl; + if (this->phase_name != NULL) + { + s_oss << indent0 << "phase_name=\"" << this-> + phase_name << "\"" << std::endl; + } + if (this->rate_name != NULL) + { + s_oss << indent0 << "rate_name=\"" << this-> + rate_name << "\"" << std::endl; + } + s_oss << indent0 << "phase_proportion=\"" << this-> + phase_proportion << "\"" << std::endl; + s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << std::endl; - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); + // formula_totals + s_oss << indent0; + s_oss << "formula_totals.dump_xml(s_oss, indent + 1); - // totals - s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "totals.dump_xml(s_oss, indent + 1); } -void cxxSurfaceComp::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Surf_Comp element and attributes + // Surf_Comp element and attributes - s_oss << indent0 << "-formula " << this->formula << std::endl; - s_oss << indent0 << "-formula_z " << this->formula_z << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-la " << this->la << std::endl; - //s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; - s_oss << indent0 << "-charge_balance " << this->charge_balance << std::endl; - if (this->phase_name != NULL) { - s_oss << indent0 << "-phase_name " << this->phase_name << std::endl; - } - if (this->rate_name != NULL) { - s_oss << indent0 << "-rate_name " << this->rate_name << std::endl; - } - s_oss << indent0 << "-phase_proportion " << this->phase_proportion << std::endl; + s_oss << indent0 << "-formula " << this-> + formula << std::endl; + s_oss << indent0 << "-formula_z " << this-> + formula_z << std::endl; + s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent0 << "-la " << this->la << std::endl; + //s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; + s_oss << indent0 << "-charge_balance " << this-> + charge_balance << std::endl; + if (this->phase_name != NULL) + { + s_oss << indent0 << "-phase_name " << this-> + phase_name << std::endl; + } + if (this->rate_name != NULL) + { + s_oss << indent0 << "-rate_name " << this-> + rate_name << std::endl; + } + s_oss << indent0 << "-phase_proportion " << this-> + phase_proportion << std::endl; s_oss << indent0 << "-Dw " << this->Dw << std::endl; - // formula_totals - s_oss << indent0; - s_oss << "-formula_totals" << std::endl; - this->formula_totals.dump_raw(s_oss, indent + 1); + // formula_totals + s_oss << indent0; + s_oss << "-formula_totals" << std::endl; + this->formula_totals.dump_raw(s_oss, indent + 1); - // totals - s_oss << indent0; - s_oss << "-totals" << std::endl; - this->totals.dump_raw(s_oss, indent + 1); + // totals + s_oss << indent0; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 1); } -void cxxSurfaceComp::read_raw(CParser& parser) +void +cxxSurfaceComp::read_raw(CParser & parser) { - std::string str; - - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(10); - vopts.push_back("formula"); // 0 - vopts.push_back("moles"); // 1 - vopts.push_back("la"); // 2 - vopts.push_back("charge_number"); // 3 - vopts.push_back("charge_balance"); // 4 - vopts.push_back("phase_name"); // 5 - vopts.push_back("rate_name"); // 6 - vopts.push_back("phase_proportion"); // 7 - vopts.push_back("totals"); // 8 - vopts.push_back("formula_z"); // 9 - vopts.push_back("formula_totals"); // 10 - vopts.push_back("dw"); // 11 - } + std::string str; - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("formula"); // 0 + vopts.push_back("moles"); // 1 + vopts.push_back("la"); // 2 + vopts.push_back("charge_number"); // 3 + vopts.push_back("charge_balance"); // 4 + vopts.push_back("phase_name"); // 5 + vopts.push_back("rate_name"); // 6 + vopts.push_back("phase_proportion"); // 7 + vopts.push_back("totals"); // 8 + vopts.push_back("formula_z"); // 9 + vopts.push_back("formula_totals"); // 10 + vopts.push_back("dw"); // 11 + } - opt_save = CParser::OPT_ERROR; - bool formula_defined(false); - bool moles_defined(false); - bool la_defined(false); - //bool charge_number_defined(false); - bool charge_balance_defined(false); - bool formula_z_defined(false); - bool Dw_defined(false); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; - for (;;) - { - int opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } + opt_save = CParser::OPT_ERROR; + bool formula_defined(false); + bool moles_defined(false); + bool la_defined(false); + //bool charge_number_defined(false); + bool charge_balance_defined(false); + bool formula_z_defined(false); + bool Dw_defined(false); - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_KEYWORD; - // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - break; + for (;;) + { + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } - case 0: // formula - if (!(parser.get_iss() >> str)) - { - this->formula = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); - } else { - this->formula = string_hsave(str.c_str()); - } - formula_defined = true; - break; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_KEYWORD; + // Allow return to Surface for more processing + //parser.error_msg("Unknown input in SURF_COMP read.", CParser::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + break; - case 1: // moles - if (!(parser.get_iss() >> this->moles)) - { - this->moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for moles.", CParser::OT_CONTINUE); - } - moles_defined = true; - break; + case 0: // formula + if (!(parser.get_iss() >> str)) + { + this->formula = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for formula.", + CParser::OT_CONTINUE); + } + else + { + this->formula = string_hsave(str.c_str()); + } + formula_defined = true; + break; - case 2: // la - if (!(parser.get_iss() >> this->la)) - { - this->la = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la.", CParser::OT_CONTINUE); - } - la_defined = true; - break; + case 1: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + CParser::OT_CONTINUE); + } + moles_defined = true; + break; + + case 2: // la + if (!(parser.get_iss() >> this->la)) + { + this->la = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for la.", + CParser::OT_CONTINUE); + } + la_defined = true; + break; #ifdef SKIP - case 3: // charge_number - if (!(parser.get_iss() >> this->charge_number)) - { - this->charge_number = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for charge_number.", CParser::OT_CONTINUE); - } - charge_number_defined = true; - break; -#endif - case 4: // charge_balance - if (!(parser.get_iss() >> this->charge_balance)) - { - this->charge_balance = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for charge_balance.", CParser::OT_CONTINUE); - } - charge_balance_defined = true; - break; - - case 5: // phase_name - if (!(parser.get_iss() >> str)) - { - this->phase_name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); - } else { - this->phase_name = string_hsave(str.c_str()); - } - break; - - case 6: // rate_name - if (!(parser.get_iss() >> str)) - { - this->rate_name = NULL; - parser.incr_input_error(); - parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); - } else { - this->rate_name = string_hsave(str.c_str()); - } - break; - - case 7: // phase_proportion - if (!(parser.get_iss() >> this->phase_proportion)) - { - this->phase_proportion = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for phase_proportion.", CParser::OT_CONTINUE); - } - break; - - case 8: // totals - if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for SurfaceComp totals.", CParser::OT_CONTINUE); - } - opt_save = 8; - break; - - case 9: // formula_z - if (!(parser.get_iss() >> this->formula_z)) - { - this->formula_z = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for formula_z.", CParser::OT_CONTINUE); - } - formula_z_defined = true; - break; - - case 10: // formula_totals - if ( this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for SurfaceComp formula totals.", CParser::OT_CONTINUE); - } - opt_save = 10; - break; - - case 11: // Dw - if (!(parser.get_iss() >> this->Dw)) - { - this->Dw = 0.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for Dw.", CParser::OT_CONTINUE); - } - Dw_defined = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (formula_defined == false) { - parser.incr_input_error(); - parser.error_msg("Formula not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } - if (formula_z_defined == false) { - parser.incr_input_error(); - parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE); - } - if (moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Moles not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } - if (la_defined == false) { - parser.incr_input_error(); - parser.error_msg("La not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } -#ifdef SKIP - if (charge_number_defined == false) { - parser.incr_input_error(); - parser.error_msg("Charge_number not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } + case 3: // charge_number + if (!(parser.get_iss() >> this->charge_number)) + { + this->charge_number = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for charge_number.", + CParser::OT_CONTINUE); + } + charge_number_defined = true; + break; #endif - if (charge_balance_defined == false) { - parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } - if (Dw_defined == false) { - parser.incr_input_error(); - parser.error_msg("Dw not defined for SurfaceComp input.", CParser::OT_CONTINUE); - } + case 4: // charge_balance + if (!(parser.get_iss() >> this->charge_balance)) + { + this->charge_balance = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge_balance.", + CParser::OT_CONTINUE); + } + charge_balance_defined = true; + break; + + case 5: // phase_name + if (!(parser.get_iss() >> str)) + { + this->phase_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for phase_name.", + CParser::OT_CONTINUE); + } + else + { + this->phase_name = string_hsave(str.c_str()); + } + break; + + case 6: // rate_name + if (!(parser.get_iss() >> str)) + { + this->rate_name = NULL; + parser.incr_input_error(); + parser.error_msg("Expected string value for rate_name.", + CParser::OT_CONTINUE); + } + else + { + this->rate_name = string_hsave(str.c_str()); + } + break; + + case 7: // phase_proportion + if (!(parser.get_iss() >> this->phase_proportion)) + { + this->phase_proportion = 0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for phase_proportion.", + CParser::OT_CONTINUE); + } + break; + + case 8: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for SurfaceComp totals.", + CParser::OT_CONTINUE); + } + opt_save = 8; + break; + + case 9: // formula_z + if (!(parser.get_iss() >> this->formula_z)) + { + this->formula_z = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for formula_z.", + CParser::OT_CONTINUE); + } + formula_z_defined = true; + break; + + case 10: // formula_totals + if (this->formula_totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for SurfaceComp formula totals.", + CParser::OT_CONTINUE); + } + opt_save = 10; + break; + + case 11: // Dw + if (!(parser.get_iss() >> this->Dw)) + { + this->Dw = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for Dw.", + CParser::OT_CONTINUE); + } + Dw_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (formula_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (formula_z_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (la_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } +#ifdef SKIP + if (charge_number_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_number not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } +#endif + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (Dw_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Dw not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI -void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxSurfaceComp::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { extern cxxDictionary dictionary; @@ -420,13 +505,15 @@ void cxxSurfaceComp::mpi_pack(std::vector& ints, std::vector& doubl this->totals.mpi_pack(ints, doubles); doubles.push_back(this->la); //ints.push_back(charge_number); - doubles.push_back(this->charge_balance); + doubles.push_back(this->charge_balance); ints.push_back(dictionary.string2int(this->phase_name)); doubles.push_back(this->phase_proportion); ints.push_back(dictionary.string2int(this->rate_name)); doubles.push_back(this->Dw); } -void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -438,105 +525,128 @@ void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; //this->charge_number = ints[i++]; - this->charge_balance = doubles[d++]; + this->charge_balance = doubles[d++]; this->phase_name = dictionary.int2char(ints[i++]); - this->phase_proportion = doubles[d++]; + this->phase_proportion = doubles[d++]; this->rate_name = dictionary.int2char(ints[i++]); - this->Dw = doubles[d++]; + this->Dw = doubles[d++]; *ii = i; *dd = d; } #endif -void cxxSurfaceComp::add(const cxxSurfaceComp &addee, double extensive) +void +cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) { - if (extensive == 0.0) return; - if (addee.formula == NULL) return; + if (extensive == 0.0) + return; + if (addee.formula == NULL) + return; - //char * formula; - //cxxNameDouble formula_totals; - if (this->formula == NULL && addee.formula == NULL) { - return; - } - assert (this->formula == addee.formula); - assert (this->formula_z == addee.formula_z); - if (this->formula == NULL && addee.formula != NULL) { - this->formula = addee.formula; - this->formula_totals = addee.formula_totals; - } + //char * formula; + //cxxNameDouble formula_totals; + if (this->formula == NULL && addee.formula == NULL) + { + return; + } + assert(this->formula == addee.formula); + assert(this->formula_z == addee.formula_z); + if (this->formula == NULL && addee.formula != NULL) + { + this->formula = addee.formula; + this->formula_totals = addee.formula_totals; + } - // this and addee must have same formula - // otherwise generate a new exchcomp with multiply - double ext1, ext2, f1, f2; - ext1 = this->moles; - ext2 = addee.moles * extensive; - if (ext1 + ext2 != 0) { - f1 = ext1/(ext1 + ext2); - f2 = ext2/(ext1 + ext2); - } else { - f1 = 0.5; - f2 = 0.5; - } - //double formula_z; + // this and addee must have same formula + // otherwise generate a new exchcomp with multiply + double ext1, ext2, f1, f2; + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } + //double formula_z; - //double moles; - this->moles += addee.moles * extensive; - //cxxNameDouble totals; - this->totals.add_extensive(addee.totals, extensive); - //double la; - this->la = f1*this->la + f2*addee.la; - //int charge_number; - //double charge_balance; - this->charge_balance += addee.charge_balance * extensive; - //char *phase_name; + //double moles; + this->moles += addee.moles * extensive; + //cxxNameDouble totals; + this->totals.add_extensive(addee.totals, extensive); + //double la; + this->la = f1 * this->la + f2 * addee.la; + //int charge_number; + //double charge_balance; + this->charge_balance += addee.charge_balance * extensive; + //char *phase_name; - if (this->phase_name != addee.phase_name) { - std::ostringstream oss; - oss << "Can not mix two Surface components with same formula and different related phases, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } else if (this->phase_name != NULL) { - this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; - } + if (this->phase_name != addee.phase_name) + { + std::ostringstream oss; + oss << + "Can not mix two Surface components with same formula and different related phases, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + else if (this->phase_name != NULL) + { + this->phase_proportion = + this->phase_proportion * f1 + addee.phase_proportion * f2; + } - //char *rate_name; - if (this->rate_name != addee.rate_name) { - std::ostringstream oss; - oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } else if (this->rate_name != NULL) { - //double phase_proportion; - this->phase_proportion = this->phase_proportion*f1 + addee.phase_proportion*f2; - } - if ((this->rate_name != NULL && addee.phase_name != NULL) || - (this->phase_name != NULL && addee.rate_name != NULL) ) - { - std::ostringstream oss; - oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - return; - } - //double Dw; + //char *rate_name; + if (this->rate_name != addee.rate_name) + { + std::ostringstream oss; + oss << + "Can not mix two exchange components with same formula and different related kinetics, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + else if (this->rate_name != NULL) + { + //double phase_proportion; + this->phase_proportion = + this->phase_proportion * f1 + addee.phase_proportion * f2; + } + if ((this->rate_name != NULL && addee.phase_name != NULL) || + (this->phase_name != NULL && addee.rate_name != NULL)) + { + std::ostringstream oss; + oss << + "Can not mix exchange components related to phase with exchange components related to kinetics, " + << this->formula; + error_msg(oss.str().c_str(), CONTINUE); + input_error++; + return; + } + //double Dw; } -void cxxSurfaceComp::multiply(double extensive) +void +cxxSurfaceComp::multiply(double extensive) { - //char * formula; - //cxxNameDouble formula_totals; - //double formula_z; - //double moles; - this->moles *= extensive; - //cxxNameDouble totals; - this->totals.multiply(extensive); - //double la; - //int charge_number; - //double charge_balance; - this->charge_balance *= extensive; - //char *phase_name; - //double phase_proportion; - //char *rate_name; - //double Dw; + //char * formula; + //cxxNameDouble formula_totals; + //double formula_z; + //double moles; + this->moles *= extensive; + //cxxNameDouble totals; + this->totals.multiply(extensive); + //double la; + //int charge_number; + //double charge_balance; + this->charge_balance *= extensive; + //char *phase_name; + //double phase_proportion; + //char *rate_name; + //double Dw; } diff --git a/System.cxx b/System.cxx index efa912c4..4a0355ff 100644 --- a/System.cxx +++ b/System.cxx @@ -1,436 +1,520 @@ #include "System.h" -#include // std::replace -extern void ORCH_write_chemistry_species(std::ostream &chemistry_dat); -cxxSystem::cxxSystem(void) -{ - this->solution = NULL; - this->exchange = NULL; - this->ppassemblage = NULL; - this->gasphase = NULL; - this->ssassemblage = NULL; - this->kinetics = NULL; - this->surface = NULL; - this->mix = NULL; - this->reaction = NULL; - this->temperature = NULL; -} +#include // std::replace +extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); + cxxSystem::cxxSystem(void) +{ + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; + } cxxSystem::~cxxSystem(void) +{ + } void +cxxSystem::Initialize(void) +{ + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; + } void +cxxSystem::totalize(void) +{ + + //initialize + this->totals.clear(); + + //add solution + if (this->solution != NULL) + + { + char token[MAX_LENGTH]; + strcpy(token, "O"); + this->totals[token] = this->solution->get_total_o(); + strcpy(token, "H"); + this->totals[token] = this->solution->get_total_h(); + strcpy(token, "Charge"); + this->totals[token] = this->solution->get_cb(); + this->totals.add_extensive(this->solution->get_totals(), 1.0); + } + if (this->exchange != NULL) + + { + this->exchange->totalize(); + this->totals.add_extensive(this->exchange->get_totals(), 1.0); + } + if (this->ppassemblage != NULL) + + { + this->ppassemblage->totalize(); + this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + } + if (this->gasphase != NULL) + + { + this->gasphase->totalize(); + this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + } + if (this->ssassemblage != NULL) + + { + this->ssassemblage->totalize(); + this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + } + if (this->surface != NULL) + + { + this->ssassemblage->totalize(); + this->totals.add_extensive(this->surface->get_totals(), 1.0); + } + + //Need to handle the following 3 reactions: + // + //this->kinetics = NULL; + //this->mix = NULL; + //this->reaction = NULL; + //this->temperature = NULL; + //this->totals.dump_raw(std::cerr, 1); + return; + } + -cxxSystem::~cxxSystem(void) -{ -} - -void cxxSystem::Initialize(void) -{ - this->solution = NULL; - this->exchange = NULL; - this->ppassemblage = NULL; - this->gasphase = NULL; - this->ssassemblage = NULL; - this->kinetics = NULL; - this->surface = NULL; - this->mix = NULL; - this->reaction = NULL; - this->temperature = NULL; -} -void cxxSystem::totalize(void) -{ - //initialize - this->totals.clear(); - //add solution - if (this->solution != NULL) - { - char token[MAX_LENGTH]; - strcpy(token, "O"); - this->totals[token] = this->solution->get_total_o(); - strcpy(token, "H"); - this->totals[token] = this->solution->get_total_h(); - strcpy(token, "Charge"); - this->totals[token] = this->solution->get_cb(); - this->totals.add_extensive(this->solution->get_totals(), 1.0); - } - if (this->exchange != NULL) - { - this->exchange->totalize(); - this->totals.add_extensive(this->exchange->get_totals(), 1.0); - } - if (this->ppassemblage != NULL) - { - this->ppassemblage->totalize(); - this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); - } - if (this->gasphase != NULL) - { - this->gasphase->totalize(); - this->totals.add_extensive(this->gasphase->get_totals(), 1.0); - } - if (this->ssassemblage != NULL) - { - this->ssassemblage->totalize(); - this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); - } - if (this->surface != NULL) - { - this->ssassemblage->totalize(); - this->totals.add_extensive(this->surface->get_totals(), 1.0); - } - - //Need to handle the following 3 reactions: - // - //this->kinetics = NULL; - //this->mix = NULL; - //this->reaction = NULL; - //this->temperature = NULL; - //this->totals.dump_raw(std::cerr, 1); - return; -} #ifdef ORCHESTRA -void cxxSystem::ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat) -{ - // - // chemistry file - // - this->totalize(); - // calculate orchestra components from PHREEQC totals - this->ORCH_components(); - // write definitions for chemistry - chemistry_dat << std::endl << "@class: species_reactions () {" << std::endl; - this->ORCH_write_chemistry_water(chemistry_dat); - this->ORCH_write_chemistry_primary(chemistry_dat); - this->ORCH_write_chemistry_total_O_H(chemistry_dat); - ORCH_write_chemistry_species(chemistry_dat); - - // add definitions for pure phases - if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - - // add definitions for other PHREEQC entities here - - // finish up - chemistry_dat << std::endl << "}" << std::endl; - // - // input file - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - this->ORCH_write_input(input_dat); - input_dat << std::endl << "}" << std::endl; - // - // output file - // - output_dat << std::endl << "Output_every: 1" << std::endl; - output_dat << "Var:"; - this->ORCH_write_output_vars(output_dat); - // add definitions for pure phases - if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_output_vars(output_dat); - - //finish up - output_dat << std::endl; -}; - -void cxxSystem::ORCH_write_chemistry_water(std::ostream &chemistry_dat) -{ - // - // Write water entities - // - chemistry_dat << std::endl << "//********* The water entities" << std::endl; - - // e-, total hydrogen - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std::endl; - - // H+, charge balance - chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std::endl; - - // H2O - chemistry_dat << "@entity(" << s_h2o->name << ", diss, 55.506)" << std::endl; - chemistry_dat << std::endl; -} - -void cxxSystem::ORCH_write_chemistry_primary(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* The primary species" << std::endl; - // - // Write other master species definitions, i.e. primary entities - // - chemistry_dat << "@species(H+, 1)" << std::endl; - for(cxxNameDouble::iterator iter = this->totals.begin() ; iter != this->totals.end(); ++iter) - { - std::string name(iter->first); - if (name == "H(1)" || name == "E" || name == "H" || name == "O" || name == "Charge") continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr->z << ")" << std::endl; - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr->name << ", 1e-9, liter, 1.0e-9)" << std::endl; - } - chemistry_dat << std::endl; -} - -void cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat) -{ - chemistry_dat << std::endl << "//********* Define total hydrogen and oxygen" << std::endl; - - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - int i; - for (i = 0; i < count_s_x; i++) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - { - if (s_x[i]->h != 0) - { - chemistry_dat << "+"; - if (s_x[i]->h != 1) - { - chemistry_dat << s_x[i]->h << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->o != 0) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - { - chemistry_dat << "+"; - if (s_x[i]->o != 1) - { - chemistry_dat << s_x[i]->o << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - chemistry_dat << std::endl; -} -void cxxSystem::ORCH_write_input(std::ostream &input_dat) -{ - - + void +cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat) +{ + + // + // chemistry file + // + this->totalize(); + + // calculate orchestra components from PHREEQC totals + this->ORCH_components(); + + // write definitions for chemistry + chemistry_dat << std:: + endl << "@class: species_reactions () {" << std::endl; + this->ORCH_write_chemistry_water(chemistry_dat); + this->ORCH_write_chemistry_primary(chemistry_dat); + this->ORCH_write_chemistry_total_O_H(chemistry_dat); + ORCH_write_chemistry_species(chemistry_dat); + + // add definitions for pure phases + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_chemistry(chemistry_dat); + + // add definitions for other PHREEQC entities here + + // finish up + chemistry_dat << std::endl << "}" << std::endl; + + // + // input file + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + this->ORCH_write_input(input_dat); + input_dat << std::endl << "}" << std::endl; + + // + // output file + // + output_dat << std::endl << "Output_every: 1" << std::endl; + output_dat << "Var:"; + this->ORCH_write_output_vars(output_dat); + + // add definitions for pure phases + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_output_vars(output_dat); + + //finish up + output_dat << std::endl; + }; + void +cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) +{ + + // + // Write water entities + // + chemistry_dat << std:: + endl << "//********* The water entities" << std::endl; + + // e-, total hydrogen + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; + chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: + endl; + + // H+, charge balance + chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; + chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: + endl; + + // H2O + chemistry_dat << "@entity(" << s_h2o-> + name << ", diss, 55.506)" << std::endl; + chemistry_dat << std::endl; + } void + +cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) +{ + chemistry_dat << std::endl << "//********* The primary species" << std:: + endl; + + // + // Write other master species definitions, i.e. primary entities + // + chemistry_dat << "@species(H+, 1)" << std::endl; + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + std::string name(iter->first); + if (name == "H(1)" || name == "E" || name == "H" || name == "O" + || name == "Charge") + continue; + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> + z << ")" << std::endl; + + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr-> + name << ", 1e-9, liter, 1.0e-9)" << std::endl; + } chemistry_dat << std::endl; + } void + +cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) +{ + chemistry_dat << std:: + endl << "//********* Define total hydrogen and oxygen" << std::endl; + + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + int i; + for (i = 0; i < count_s_x; i++) + + { + + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + if (s_x[i]->h != 0) + + { + chemistry_dat << "+"; + if (s_x[i]->h != 1) + + { + chemistry_dat << s_x[i]->h << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + for (i = 0; i < count_s_x; i++) + + { + if (s_x[i]->o != 0) + + { + + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + chemistry_dat << "+"; + if (s_x[i]->o != 1) + + { + chemistry_dat << s_x[i]->o << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + chemistry_dat << std::endl; + } + void +cxxSystem::ORCH_write_input(std::ostream & input_dat) +{ + // // Write orchestra input file info // - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; + headings << "tempc\t"; + data << this->solution->get_tc() << "\t"; + headings << "pH\t"; + data << this->solution->get_ph() << "\t"; + headings << "pe\t"; + data << this->solution->get_pe() << "\t"; + headings << "H2O.act\t"; + data << 1 << "\t"; + headings << "I\t"; + data << this->solution->get_mu() << "\t"; + for (cxxNameDouble::iterator iter = this->orch_totals.begin(); + iter != this->orch_totals.end(); ++iter) + + { + headings << iter->first << ".liter" << "\t"; + data << iter->second << "\t"; + } + + // activity estimate + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + if (iter->first == "O" || iter->first == "Charge") + continue; + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch(iter->first); + assert(master_ptr != NULL); + cxxNameDouble ma = this->solution->get_master_activity(); + cxxNameDouble::iterator it = ma.find(iter->first); + if (it == ma.end()) + + { + it = ma.find(master_ptr->s->secondary->elt->name); + } + headings << master_ptr->s->name << ".act\t"; + if (it != ma.end()) + + { + data << pow(10., it->second) << "\t"; + } + else + + { + data << 1e-9 << "\t"; + } + } + + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; + return; + } + void +cxxSystem::ORCH_components(void) +{ + + // translate from H, O, charge to H+tot, e-tot, and H2Otot + cxxNameDouble::iterator it; + cxxNameDouble temp_totals; + + // + // Set names in orch_totals to master species names + // + this->orch_totals.clear(); + temp_totals = this->totals; + temp_totals.erase("H"); + temp_totals.erase("O"); + temp_totals.erase("Charge"); + + //temp_totals.dump_raw(std::cerr, 1); + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + assert(elt_ptr != NULL); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + assert(master_ptr != NULL); + double coef = master_ptr->coef; + if (master_ptr->coef == 0) + + { + coef = 1; + } + this->orch_totals[master_ptr->s->name] = it->second / coef; + } + + // + // Calculate h2otot + // + it = this->totals.find("O"); + assert(it != this->totals.end()); + double h2otot = it->second; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + h2otot -= it->second * master_ptr->s->o; + } + // + // Calculate htot + // + it = this->totals.find("H"); + assert(it != this->totals.end()); + double htot = it->second - 2 * h2otot; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + htot -= it->second * master_ptr->s->h; + } + // + // Calculate etot + // + it = this->totals.find("Charge"); + assert(it != this->totals.end()); + double etot = -it->second + htot; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + etot += it->second * master_ptr->s->z; + } + // + // store h2otot, htot, etot in orch_totals + // + this->orch_totals["H2O"] = h2otot; + this->orch_totals["H+"] = htot; + this->orch_totals["e-"] = etot; + this->orch_totals.dump_raw(std::cerr, 1); + } void + +cxxSystem::ORCH_write_output_vars(std::ostream & outstream) +{ + outstream << "\tnr_iter"; + + // + // Serialize solution + // + outstream << "\tstart_solution"; + + //tc + outstream << "\ttempc"; + + //pH + outstream << "\tpH"; + + //pe + outstream << "\tpe"; + + //mu + outstream << "\tI"; + + //ah2o + outstream << "\tH2O.act"; + + //total_h; + outstream << "\ttotal_hydrogen"; + + //total_o; + outstream << "\ttotal_oxygen"; + + //cb + outstream << "\tchargebalance"; + + //mass_water; + outstream << "\tH2O.con"; + + //total_alkalinity; + outstream << "\tAlkalinity"; + + //orchestra master variables + outstream << "\tH+.diss"; + outstream << "\te-.diss"; + outstream << "\tH2O.diss"; + + // + // Write totals + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + outstream << "\t" << it->first << ".diss"; + } + outstream << "\tend_totals"; + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + outstream << "\t" << it->first << ".act"; + } + outstream << "\tend_master_activities"; + + // + // Write all species activities and concentrations + // + int i; + for (i = 0; i < count_s_x; i++) + { + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + outstream << "\t" << name.c_str() << ".act" << "\t" << name. + c_str() << ".con"; + } + outstream << "\tend_species"; + } + - headings << "tempc\t"; - data << this->solution->get_tc() << "\t"; - - headings << "pH\t"; - data << this->solution->get_ph() << "\t"; - - headings << "pe\t"; - data << this->solution->get_pe() << "\t"; - - headings << "H2O.act\t"; - data << 1 << "\t"; - - headings << "I\t"; - data << this->solution->get_mu() << "\t"; - - for (cxxNameDouble::iterator iter = this->orch_totals.begin(); iter != this->orch_totals.end(); ++iter) - { - headings << iter->first << ".liter" << "\t"; - data << iter->second << "\t"; - } - - // activity estimate - for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) - { - if (iter->first == "O" || iter->first == "Charge") continue; - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch (iter->first); - assert (master_ptr != NULL); - - cxxNameDouble ma = this->solution->get_master_activity(); - cxxNameDouble::iterator it = ma.find(iter->first); - if (it == ma.end()) - { - it = ma.find(master_ptr->s->secondary->elt->name); - } - headings << master_ptr->s->name << ".act\t"; - if (it != ma.end()) - { - data << pow(10., it->second) << "\t"; - } else - { - data << 1e-9 << "\t"; - } - } - - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; - - return; -} - -void cxxSystem::ORCH_components(void) -{ - // translate from H, O, charge to H+tot, e-tot, and H2Otot - cxxNameDouble::iterator it; - cxxNameDouble temp_totals; - // - // Set names in orch_totals to master species names - // - this->orch_totals.clear(); - temp_totals = this->totals; - temp_totals.erase("H"); - temp_totals.erase("O"); - temp_totals.erase("Charge"); - //temp_totals.dump_raw(std::cerr, 1); - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - assert(elt_ptr != NULL); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - assert(master_ptr != NULL); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - { - coef = 1; - } - this->orch_totals[master_ptr->s->name] = it->second / coef; - } - // - // Calculate h2otot - // - it = this->totals.find("O"); - assert (it != this->totals.end()); - double h2otot = it->second; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - h2otot -= it->second * master_ptr->s->o; - } - // - // Calculate htot - // - it = this->totals.find("H"); - assert (it != this->totals.end()); - double htot = it->second - 2*h2otot; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - htot -= it->second * master_ptr->s->h; - } - // - // Calculate etot - // - it = this->totals.find("Charge"); - assert (it != this->totals.end()); - double etot = -it->second + htot; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - etot += it->second * master_ptr->s->z; - } - // - // store h2otot, htot, etot in orch_totals - // - this->orch_totals["H2O"] = h2otot; - this->orch_totals["H+"] = htot; - this->orch_totals["e-"] = etot; - this->orch_totals.dump_raw(std::cerr, 1); -} -void cxxSystem::ORCH_write_output_vars(std::ostream &outstream) -{ - outstream << "\tnr_iter"; - // - // Serialize solution - // - outstream << "\tstart_solution"; - //tc - outstream << "\ttempc"; - //pH - outstream << "\tpH"; - //pe - outstream << "\tpe"; - //mu - outstream << "\tI"; - //ah2o - outstream << "\tH2O.act"; - //total_h; - outstream << "\ttotal_hydrogen"; - //total_o; - outstream << "\ttotal_oxygen"; - //cb - outstream << "\tchargebalance"; - //mass_water; - outstream << "\tH2O.con"; - //total_alkalinity; - outstream << "\tAlkalinity"; - //orchestra master variables - outstream << "\tH+.diss"; - outstream << "\te-.diss"; - outstream << "\tH2O.diss"; - // - // Write totals - for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) - { - if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - outstream << "\t" << it->first << ".diss"; - } - outstream << "\tend_totals"; - for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) - { - if ( it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - outstream << "\t" << it->first << ".act"; - } - outstream << "\tend_master_activities"; - // - // Write all species activities and concentrations - // - int i; - for (i = 0; i < count_s_x; i++) { - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - outstream << "\t" << name.c_str() << ".act" << "\t" << name.c_str() << ".con"; - } - outstream << "\tend_species"; -} -#endif +#endif /* */ diff --git a/Temperature.cxx b/Temperature.cxx index 7d5b9e34..6c2c759c 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -2,57 +2,62 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "Temperature.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxTemperature::cxxTemperature() - // - // default constructor for cxxTemperature - // -: cxxNumKeyword() + // + // default constructor for cxxTemperature + // +: cxxNumKeyword() { - countTemps = 0; - equalIncrements = false; + countTemps = 0; + equalIncrements = false; } cxxTemperature::cxxTemperature(struct temperature *temperature_ptr) - // - // constructor for cxxTemperature from struct temperature - // -: + // + // constructor for cxxTemperature from struct temperature + // + : cxxNumKeyword() { - int i; + int i; - this->set_description(temperature_ptr->description); - this->n_user = temperature_ptr->n_user; - this->n_user_end = temperature_ptr->n_user_end; + this->set_description(temperature_ptr->description); + this->n_user = temperature_ptr->n_user; + this->n_user_end = temperature_ptr->n_user_end; // temps - if (temperature_ptr->count_t < 0) { - for (i = 0; i < 2; i++) { + if (temperature_ptr->count_t < 0) + { + for (i = 0; i < 2; i++) + { this->temps.push_back(temperature_ptr->t[i]); } - this->countTemps = -temperature_ptr->count_t; - this->equalIncrements = true; - } else { - for (i = 0; i < temperature_ptr->count_t; i++) { + this->countTemps = -temperature_ptr->count_t; + this->equalIncrements = true; + } + else + { + for (i = 0; i < temperature_ptr->count_t; i++) + { this->temps.push_back(temperature_ptr->t[i]); } - this->countTemps = temperature_ptr->count_t; - this->equalIncrements = false; + this->countTemps = temperature_ptr->count_t; + this->equalIncrements = false; } } @@ -61,201 +66,250 @@ cxxTemperature::~cxxTemperature() } -struct temperature *cxxTemperature::cxxTemperature2temperature() - // - // Builds a temperature structure from instance of cxxTemperature - // +struct temperature * +cxxTemperature::cxxTemperature2temperature() + // + // Builds a temperature structure from instance of cxxTemperature + // { - struct temperature *temperature_ptr; - temperature_ptr = (struct temperature *) PHRQ_malloc(sizeof (struct temperature)); - if (temperature_ptr == NULL) malloc_error(); + struct temperature *temperature_ptr; + temperature_ptr = + (struct temperature *) PHRQ_malloc(sizeof(struct temperature)); + if (temperature_ptr == NULL) + malloc_error(); - temperature_ptr->description = this->get_description(); - temperature_ptr->n_user = this->n_user; - temperature_ptr->n_user_end = this->n_user_end; + temperature_ptr->description = this->get_description(); + temperature_ptr->n_user = this->n_user; + temperature_ptr->n_user_end = this->n_user_end; // temps temperature_ptr->t = NULL; - if (this->temps.size() > 0) { - temperature_ptr->t = (double *) PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); - if (temperature_ptr->t == NULL) malloc_error(); - std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); - } - if (this->equalIncrements) { - temperature_ptr->count_t = - (int) this->countTemps; - } else { - temperature_ptr->count_t = (int) this->temps.size(); + if (this->temps.size() > 0) + { + temperature_ptr->t = + (double *) + PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); + if (temperature_ptr->t == NULL) + malloc_error(); + std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); } - return(temperature_ptr); + if (this->equalIncrements) + { + temperature_ptr->count_t = -(int) this->countTemps; + } + else + { + temperature_ptr->count_t = (int) this->temps.size(); + } + return (temperature_ptr); } #ifdef SKIP -void cxxTemperature::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Temperature element and attributes - s_oss << indent0; - s_oss << "pitzer_temperature_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_temperature_gammas=\"" << this-> + pitzer_temperature_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = temperatureComps.begin(); it != temperatureComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = + temperatureComps.begin(); it != temperatureComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxTemperature::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Temperature element and attributes - s_oss << indent0; - s_oss << "REACTION_TEMPERATURE_RAW " << this->n_user << " " << this->description << std::endl; + // Temperature element and attributes + s_oss << indent0; + s_oss << "REACTION_TEMPERATURE_RAW " << this-> + n_user << " " << this->description << std::endl; - s_oss << indent1; - s_oss << "-temps " << std::endl; - { - int i = 0; - s_oss << indent2; - for (std::vector::const_iterator it = this->temps.begin(); it != this->temps.end(); it++) { - if (i++ == 5) { - s_oss << std::endl; - s_oss << indent2; - i = 0; - } - s_oss << *it << " "; - } - s_oss << std::endl; - } + s_oss << indent1; + s_oss << "-temps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector < double >::const_iterator it = this->temps.begin(); + it != this->temps.end(); it++) + { + if (i++ == 5) + { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } - s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; - s_oss << indent1; - s_oss << "-count_temps " << this->countTemps << std::endl; + s_oss << indent1; + s_oss << "-count_temps " << this->countTemps << std::endl; } -void cxxTemperature::read_raw(CParser& parser) +void +cxxTemperature::read_raw(CParser & parser) { - double d; + double d; CParser::TOKEN_TYPE k; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("temps"); //0 - vopts.push_back("equal_increments"); //1 - vopts.push_back("count_temps"); //2 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("temps"); //0 + vopts.push_back("equal_increments"); //1 + vopts.push_back("count_temps"); //2 + } - // Read temperature number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; - bool equalIncrements_defined(false); - bool countTemps_defined(false); + // Read temperature number and description + this->read_number_description(parser); - 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 TEMPERATURE_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; + bool equalIncrements_defined(false); + bool countTemps_defined(false); - case 0: // temps - while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { + 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 TEMPERATURE_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // temps + while ((k = + parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + { std::istringstream iss(token); - if (!(iss >> d)) { + if (!(iss >> d)) + { parser.incr_input_error(); - parser.error_msg("Expected numeric value for temps.", CParser::OT_CONTINUE); - } else { + parser.error_msg("Expected numeric value for temps.", + CParser::OT_CONTINUE); + } + else + { this->temps.push_back(d); } - } - opt_save = 0; - useLastLine = false; - break; + } + opt_save = 0; + useLastLine = false; + break; - case 1: // equal_increments - if (!(parser.get_iss() >> this->equalIncrements)) - { - this->equalIncrements = 0; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); - } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - equalIncrements_defined = true; - break; + case 1: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser. + error_msg("Expected boolean value for equalIncrements.", + CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; - case 2: // countTemps - if (!(parser.get_iss() >> this->countTemps)) - { - this->countTemps = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for countTemps.", CParser::OT_CONTINUE); - } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - countTemps_defined = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (equalIncrements_defined == false) { - parser.incr_input_error(); - parser.error_msg("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE); - } - if (countTemps_defined == false) { - parser.incr_input_error(); - parser.error_msg("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", CParser::OT_CONTINUE); - } + case 2: // countTemps + if (!(parser.get_iss() >> this->countTemps)) + { + this->countTemps = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for countTemps.", + CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + countTemps_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", + CParser::OT_CONTINUE); + } + if (countTemps_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", + CParser::OT_CONTINUE); + } } diff --git a/Utils.cxx b/Utils.cxx index 81efd109..1a3f6ff7 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -1,79 +1,94 @@ #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // ::tolower -#include // ::tolower -#include //std::transform -#include // std::cout std::cerr +#include // ::tolower +#include // ::tolower +#include //std::transform +#include // std::cout std::cerr #include "Utils.h" #include "Parser.h" #include "output.h" //////////////////////////////////////////////////////////////////////////// -int Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) +int +Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) //////////////////////////////////////////////////////////////////////////// { - // - // Compare two strings disregarding case - // - int c1, c2; - while ((c1 = ::tolower(*str1++)) == (c2 = *str2++)) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 =::tolower(*str1++)) == (c2 = *str2++)) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); } //////////////////////////////////////////////////////////////////////////// -int Utilities::strcmp_nocase(const char *str1, const char *str2) +int +Utilities::strcmp_nocase(const char *str1, const char *str2) //////////////////////////////////////////////////////////////////////////// { - // - // Compare two strings disregarding case - // - int c1, c2; - while ((c1 = ::tolower(*str1++)) == (c2 = ::tolower(*str2++))) { - if (c1 == '\0') return(0); - } - if (c1 < c2) return(-1); - return(1); + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 =::tolower(*str1++)) == (c2 =::tolower(*str2++))) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); } //////////////////////////////////////////////////////////////////////////// -void Utilities::str_tolower(std::string& str) +void +Utilities::str_tolower(std::string & str) //////////////////////////////////////////////////////////////////////////// { - std::transform(str.begin(), str.end(), str.begin(), tolower); + std::transform(str.begin(), str.end(), str.begin(), tolower); } //////////////////////////////////////////////////////////////////////////// -bool Utilities::replace(const char* str1, const char* str2, std::string& str) +bool +Utilities::replace(const char *str1, const char *str2, std::string & str) //////////////////////////////////////////////////////////////////////////// { - std::string::size_type n = str.find(str1, 0); - if (n == std::string::npos) return false; + std::string::size_type n = str.find(str1, 0); + if (n == std::string::npos) + return false; - str.replace(n, ::strlen(str1), str2); - return true; + str.replace(n,::strlen(str1), str2); + return true; } + //////////////////////////////////////////////////////////////////////////// -void Utilities::squeeze_white(std::string& s_l) +void +Utilities::squeeze_white(std::string & s_l) //////////////////////////////////////////////////////////////////////////// { - std::string str; - std::string::iterator beg = s_l.begin(); - std::string::iterator end = s_l.end(); - CParser::copy_token(str, beg, end); - s_l = str; + std::string str; + std::string::iterator beg = s_l.begin(); + std::string::iterator end = s_l.end(); + CParser::copy_token(str, beg, end); + s_l = str; } + #ifdef SKIP //////////////////////////////////////////////////////////////////////////// -void Utilities::error_msg (const std::string& err_str, const int stop) +void +Utilities::error_msg(const std::string & err_str, const int stop) //////////////////////////////////////////////////////////////////////////// { - //std::cerr << err_str << std::endl; - output_message(OUTPUT_ERROR, err_str, stop, "", args); + //std::cerr << err_str << std::endl; + output_message(OUTPUT_ERROR, err_str, stop, "", args); } #endif diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 184937af..8c815156 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -2,433 +2,504 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "cxxKinetics.h" #include "KineticsComp.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxKinetics::cxxKinetics() - // - // default constructor for cxxKinetics - // -: cxxNumKeyword() + // + // default constructor for cxxKinetics + // +: cxxNumKeyword() { - step_divide = 1.0; - rk = 3; - bad_step_max = 500; - use_cvode = false; - cvode_steps = 100; - cvode_order = 5; - totals.type = cxxNameDouble::ND_ELT_MOLES; + step_divide = 1.0; + rk = 3; + bad_step_max = 500; + use_cvode = false; + cvode_steps = 100; + cvode_order = 5; + totals.type = cxxNameDouble::ND_ELT_MOLES; } cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr) - // - // constructor for cxxKinetics from struct kinetics - // -: + // + // constructor for cxxKinetics from struct kinetics + // + : cxxNumKeyword(), totals(kinetics_ptr->totals) { - int i; + int i; - this->set_description(kinetics_ptr->description); - n_user = kinetics_ptr->n_user; - n_user_end = kinetics_ptr->n_user_end; - step_divide = kinetics_ptr->step_divide; - rk = kinetics_ptr->rk; - bad_step_max = kinetics_ptr->bad_step_max; - use_cvode = (kinetics_ptr->use_cvode == TRUE); - cvode_steps = kinetics_ptr->cvode_steps; - cvode_order = kinetics_ptr->cvode_order; + this->set_description(kinetics_ptr->description); + n_user = kinetics_ptr->n_user; + n_user_end = kinetics_ptr->n_user_end; + step_divide = kinetics_ptr->step_divide; + rk = kinetics_ptr->rk; + bad_step_max = kinetics_ptr->bad_step_max; + use_cvode = (kinetics_ptr->use_cvode == TRUE); + cvode_steps = kinetics_ptr->cvode_steps; + cvode_order = kinetics_ptr->cvode_order; - // kinetics components - for (i = 0; i < kinetics_ptr->count_comps; i++) { - cxxKineticsComp ec(&(kinetics_ptr->comps[i])); - this->kineticsComps.push_back(ec); - } + // kinetics components + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + cxxKineticsComp ec(&(kinetics_ptr->comps[i])); + this->kineticsComps.push_back(ec); + } - // steps - for (i = 0; i < kinetics_ptr->count_steps; i++) { - this->steps.push_back(kinetics_ptr->steps[i]); - } + // steps + for (i = 0; i < kinetics_ptr->count_steps; i++) + { + this->steps.push_back(kinetics_ptr->steps[i]); + } } -cxxKinetics::cxxKinetics(const std::map &entities, cxxMix &mix, int n_user) -: +cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, + cxxMix & mix, int n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; - step_divide = 1.0; - rk = 3; - bad_step_max = 500; - use_cvode = false; - cvode_steps = 100; - cvode_order = 5; - totals.type = cxxNameDouble::ND_ELT_MOLES; + this->n_user = this->n_user_end = n_user; + step_divide = 1.0; + rk = 3; + bad_step_max = 500; + use_cvode = false; + cvode_steps = 100; + cvode_order = 5; + totals.type = cxxNameDouble::ND_ELT_MOLES; // // Mix // - std::map *mixcomps = mix.comps(); - std::map::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) - { - if (entities.find(it->first) != entities.end()) - { - const cxxKinetics *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); - } - } + std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps->begin(); it != mixcomps->end(); it++) + { + if (entities.find(it->first) != entities.end()) + { + const cxxKinetics *entity_ptr = + &(entities.find(it->first)->second); + this->add(*entity_ptr, it->second); + } + } } + cxxKinetics::~cxxKinetics() { } -struct kinetics *cxxKinetics::cxxKinetics2kinetics() - // - // Builds a kinetics structure from instance of cxxKinetics - // +struct kinetics * +cxxKinetics::cxxKinetics2kinetics() + // + // Builds a kinetics structure from instance of cxxKinetics + // { - struct kinetics *kinetics_ptr = kinetics_alloc(); - - kinetics_ptr->description = this->get_description(); - kinetics_ptr->n_user = this->n_user; - kinetics_ptr->n_user_end = this->n_user_end; - kinetics_ptr->step_divide = this->step_divide; - kinetics_ptr->rk = this->rk; - kinetics_ptr->bad_step_max = this->bad_step_max; - kinetics_ptr->use_cvode = (int) this->use_cvode; - kinetics_ptr->cvode_steps = this->cvode_steps; - kinetics_ptr->cvode_order = this->cvode_order; + struct kinetics *kinetics_ptr = kinetics_alloc(); - // totals - kinetics_ptr->totals = this->totals.elt_list(); + kinetics_ptr->description = this->get_description(); + kinetics_ptr->n_user = this->n_user; + kinetics_ptr->n_user_end = this->n_user_end; + kinetics_ptr->step_divide = this->step_divide; + kinetics_ptr->rk = this->rk; + kinetics_ptr->bad_step_max = this->bad_step_max; + kinetics_ptr->use_cvode = (int) this->use_cvode; + kinetics_ptr->cvode_steps = this->cvode_steps; + kinetics_ptr->cvode_order = this->cvode_order; - // comps - kinetics_ptr->count_comps = (int) this->kineticsComps.size(); - kinetics_ptr->comps = (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); - kinetics_ptr->comps = cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps); + // totals + kinetics_ptr->totals = this->totals.elt_list(); - // steps - kinetics_ptr->count_steps = (int) this->steps.size(); - kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps); - if (this->steps.size() > 0) { - kinetics_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); - if (kinetics_ptr->steps == NULL) malloc_error(); - std::copy(this->steps.begin(), this->steps.end(), kinetics_ptr->steps); - /* - int i = 0; - for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { - kinetics_ptr->steps[i] = *it; - } - */ - } - return(kinetics_ptr); + // comps + kinetics_ptr->count_comps = (int) this->kineticsComps.size(); + kinetics_ptr->comps = + (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); + kinetics_ptr->comps = + cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps); + + // steps + kinetics_ptr->count_steps = (int) this->steps.size(); + kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps); + if (this->steps.size() > 0) + { + kinetics_ptr->steps = + (double *) + PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + if (kinetics_ptr->steps == NULL) + malloc_error(); + std::copy(this->steps.begin(), this->steps.end(), + kinetics_ptr->steps); + /* + int i = 0; + for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { + kinetics_ptr->steps[i] = *it; + } + */ + } + return (kinetics_ptr); } #ifdef SKIP -void cxxKinetics::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Kinetics element and attributes - s_oss << indent0; - s_oss << "pitzer_kinetics_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_kinetics_gammas=\"" << this-> + pitzer_kinetics_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = + kineticsComps.begin(); it != kineticsComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxKinetics::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Kinetics element and attributes - s_oss << indent0; - s_oss << "KINETICS_RAW " << this->n_user << " " << this->description << std::endl; + // Kinetics element and attributes + s_oss << indent0; + s_oss << "KINETICS_RAW " << this->n_user << " " << this-> + description << std::endl; - s_oss << indent1; - s_oss << "-step_divide " << this->step_divide << std::endl; + s_oss << indent1; + s_oss << "-step_divide " << this->step_divide << std::endl; - s_oss << indent1; - s_oss << "-rk " << this->rk << std::endl; + s_oss << indent1; + s_oss << "-rk " << this->rk << std::endl; - s_oss << indent1; - s_oss << "-bad_step_max " << this->bad_step_max << std::endl; + s_oss << indent1; + s_oss << "-bad_step_max " << this->bad_step_max << std::endl; - s_oss << indent1; - s_oss << "-use_cvode " << this->use_cvode << std::endl; + s_oss << indent1; + s_oss << "-use_cvode " << this->use_cvode << std::endl; - s_oss << indent1; - s_oss << "-cvode_steps " << this->cvode_steps << std::endl; + s_oss << indent1; + s_oss << "-cvode_steps " << this->cvode_steps << std::endl; - s_oss << indent1; - s_oss << "-cvode_order " << this->cvode_order << std::endl; + s_oss << indent1; + s_oss << "-cvode_order " << this->cvode_order << std::endl; // kineticsComps structures - for (std::list::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { - s_oss << indent1; - s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); - } + for (std::list < cxxKineticsComp >::const_iterator it = + kineticsComps.begin(); it != kineticsComps.end(); ++it) + { + s_oss << indent1; + s_oss << "-component" << std::endl; + it->dump_raw(s_oss, indent + 2); + } - // totals - s_oss << indent1; - s_oss << "-totals " << std::endl; - this->totals.dump_raw(s_oss, indent + 2); + // totals + s_oss << indent1; + s_oss << "-totals " << std::endl; + this->totals.dump_raw(s_oss, indent + 2); - // steps - s_oss << indent1; - s_oss << "-steps " << std::endl; - { - int i = 0; - s_oss << indent2; - for (std::vector::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { - if (i++ == 5) { - s_oss << std::endl; - s_oss << indent2; - i = 0; - } - s_oss << *it << " "; - } - s_oss << std::endl; - } - return; + // steps + s_oss << indent1; + s_oss << "-steps " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector < double >::const_iterator it = this->steps.begin(); + it != this->steps.end(); it++) + { + if (i++ == 5) + { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } + return; } -void cxxKinetics::read_raw(CParser& parser) +void +cxxKinetics::read_raw(CParser & parser) { - double d; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - vopts.push_back("step_divide"); - vopts.push_back("rk"); - vopts.push_back("bad_step_max"); - vopts.push_back("use_cvode"); - vopts.push_back("component"); - vopts.push_back("totals"); - vopts.push_back("steps"); - vopts.push_back("cvode_steps"); - vopts.push_back("cvode_order"); - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + double d; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("step_divide"); + vopts.push_back("rk"); + vopts.push_back("bad_step_max"); + vopts.push_back("use_cvode"); + vopts.push_back("component"); + vopts.push_back("totals"); + vopts.push_back("steps"); + vopts.push_back("cvode_steps"); + vopts.push_back("cvode_order"); + } - // Read kinetics number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_ERROR; - bool step_divide_defined(false); - bool rk_defined(false); - bool bad_step_max_defined(false); - bool use_cvode_defined(false); - bool cvode_steps_defined(false); - bool cvode_order_defined(false); + // Read kinetics number and description + this->read_number_description(parser); - 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 KINETICS_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_ERROR; + bool step_divide_defined(false); + bool rk_defined(false); + bool bad_step_max_defined(false); + bool use_cvode_defined(false); + bool cvode_steps_defined(false); + bool cvode_order_defined(false); - case 0: // step_divide - if (!(parser.get_iss() >> this->step_divide)) - { - this->step_divide = 1.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for step_divide.", CParser::OT_CONTINUE); - } - step_divide_defined = true; - useLastLine = false; - break; - - case 1: // rk - if (!(parser.get_iss() >> this->rk)) - { - this->rk = 3; - parser.incr_input_error(); - parser.error_msg("Expected integer value for rk.", CParser::OT_CONTINUE); - } - rk_defined = true; - useLastLine = false; - break; - - case 2: // bad_step_max - if (!(parser.get_iss() >> this->bad_step_max)) - { - this->bad_step_max = 500; - parser.incr_input_error(); - parser.error_msg("Expected integer value for bad_step_max.", CParser::OT_CONTINUE); - } - bad_step_max_defined = true; - useLastLine = false; - break; - - case 3: // use_cvode - if (!(parser.get_iss() >> this->use_cvode)) - { - this->use_cvode = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for use_cvode.", CParser::OT_CONTINUE); - } - use_cvode_defined = true; - useLastLine = false; - break; - - case 4: // component - { - cxxKineticsComp kc; - kc.read_raw(parser); - this->kineticsComps.push_back(kc); - } - useLastLine = true; - break; - - case 5: // totals - if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected element name and molality for KineticsComp totals.", CParser::OT_CONTINUE); - } - opt_save = 5; - useLastLine = false; + 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 KINETICS_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; break; - case 6: // steps - while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - //sscanf(token.c_str(), "%lf", &d); - //this->steps.push_back(d); + case 0: // step_divide + if (!(parser.get_iss() >> this->step_divide)) + { + this->step_divide = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for step_divide.", + CParser::OT_CONTINUE); + } + step_divide_defined = true; + useLastLine = false; + break; + + case 1: // rk + if (!(parser.get_iss() >> this->rk)) + { + this->rk = 3; + parser.incr_input_error(); + parser.error_msg("Expected integer value for rk.", + CParser::OT_CONTINUE); + } + rk_defined = true; + useLastLine = false; + break; + + case 2: // bad_step_max + if (!(parser.get_iss() >> this->bad_step_max)) + { + this->bad_step_max = 500; + parser.incr_input_error(); + parser.error_msg("Expected integer value for bad_step_max.", + CParser::OT_CONTINUE); + } + bad_step_max_defined = true; + useLastLine = false; + break; + + case 3: // use_cvode + if (!(parser.get_iss() >> this->use_cvode)) + { + this->use_cvode = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for use_cvode.", + CParser::OT_CONTINUE); + } + use_cvode_defined = true; + useLastLine = false; + break; + + case 4: // component + { + cxxKineticsComp kc; + kc.read_raw(parser); + this->kineticsComps.push_back(kc); + } + useLastLine = true; + break; + + case 5: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for KineticsComp totals.", + CParser::OT_CONTINUE); + } + opt_save = 5; + useLastLine = false; + break; + + case 6: // steps + while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) + { + //sscanf(token.c_str(), "%lf", &d); + //this->steps.push_back(d); std::istringstream iss(token); - if (!(iss >> d)) { + if (!(iss >> d)) + { parser.incr_input_error(); - parser.error_msg("Expected numeric value for steps.", CParser::OT_CONTINUE); - } else { + parser.error_msg("Expected numeric value for steps.", + CParser::OT_CONTINUE); + } + else + { this->steps.push_back(d); } - } - opt_save = 6; - useLastLine = false; + } + opt_save = 6; + useLastLine = false; break; - case 7: // cvode_steps - if (!(parser.get_iss() >> this->cvode_steps)) - { - this->cvode_steps = 100; - parser.incr_input_error(); - parser.error_msg("Expected integer value for cvode_steps.", CParser::OT_CONTINUE); - } - cvode_steps_defined = true; - useLastLine = false; - break; + case 7: // cvode_steps + if (!(parser.get_iss() >> this->cvode_steps)) + { + this->cvode_steps = 100; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_steps.", + CParser::OT_CONTINUE); + } + cvode_steps_defined = true; + useLastLine = false; + break; - case 8: // cvode_order - if (!(parser.get_iss() >> this->cvode_order)) - { - this->cvode_order = 5; - parser.incr_input_error(); - parser.error_msg("Expected integer value for cvode_order.", CParser::OT_CONTINUE); - } - cvode_order_defined = true; - useLastLine = false; - break; + case 8: // cvode_order + if (!(parser.get_iss() >> this->cvode_order)) + { + this->cvode_order = 5; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_order.", + CParser::OT_CONTINUE); + } + cvode_order_defined = true; + useLastLine = false; + break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined - if (step_divide_defined == false) { - parser.incr_input_error(); - parser.error_msg("Step_divide not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } - if (rk_defined == false) { - parser.incr_input_error(); - parser.error_msg("Rk not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } - if (bad_step_max_defined == false) { - parser.incr_input_error(); - parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } - if (use_cvode_defined == false) { - parser.incr_input_error(); - parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } - if (cvode_steps_defined == false) { - parser.incr_input_error(); - parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } - if (cvode_order_defined == false) { - parser.incr_input_error(); - parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); - } + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (step_divide_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Step_divide not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (rk_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rk not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (bad_step_max_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (use_cvode_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_steps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_order_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } } + #ifdef USE_MPI -void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) +void +cxxKinetics::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) { ints.push_back(this->n_user); ints.push_back((int) this->kineticsComps.size()); - for (std::list::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { + for (std::list < cxxKineticsComp >::iterator it = + this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) + { it->mpi_pack(ints, doubles); } ints.push_back((int) this->steps.size()); - for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { + for (std::vector < double >::iterator it = this->steps.begin(); + it != this->steps.end(); it++) + { doubles.push_back(*it); } doubles.push_back(this->step_divide); @@ -438,7 +509,9 @@ void cxxKinetics::mpi_pack(std::vector& ints, std::vector& doubles) ints.push_back(this->cvode_steps); ints.push_back(this->cvode_order); } -void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) + +void +cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; @@ -448,14 +521,16 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) int n = ints[i++]; this->kineticsComps.clear(); - for (int j = 0; j < n; j++) { + for (int j = 0; j < n; j++) + { cxxKineticsComp kc; kc.mpi_unpack(ints, &i, doubles, &d); this->kineticsComps.push_back(kc); } n = ints[i++]; this->steps.clear(); - for (int j = 0; j < n; j++) { + for (int j = 0; j < n; j++) + { this->steps.push_back(doubles[d++]); } this->step_divide = doubles[d++]; @@ -468,42 +543,49 @@ void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif -void cxxKinetics::add(const cxxKinetics &addee, double extensive) - // - // Add to existing ppassemblage to "this" ppassemblage - // +void +cxxKinetics::add(const cxxKinetics & addee, double extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // { - if (extensive == 0.0) return; - //std::list kineticsComps; - for (std::list::const_iterator itadd = addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); ++itadd) - { - bool found = false; - for (std::list::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); ++it) - { - if (it->get_rate_name() == itadd->get_rate_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) { - cxxKineticsComp entity = *itadd; - entity.multiply(extensive); - this->kineticsComps.push_back(entity); - } - } - //std::vector steps; - this->steps = addee.steps; - //cxxNameDouble totals; - //double step_divide; - this->step_divide = addee.step_divide; - //int rk; - this->rk = addee.rk; - //int bad_step_max; - this->bad_step_max = addee.bad_step_max; - //bool use_cvode; - this->use_cvode = addee.use_cvode; - this->cvode_steps = addee.cvode_steps; - this->cvode_order = addee.cvode_order; + if (extensive == 0.0) + return; + //std::list kineticsComps; + for (std::list < cxxKineticsComp >::const_iterator itadd = + addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); + ++itadd) + { + bool found = false; + for (std::list < cxxKineticsComp >::iterator it = + this->kineticsComps.begin(); it != this->kineticsComps.end(); + ++it) + { + if (it->get_rate_name() == itadd->get_rate_name()) + { + it->add((*itadd), extensive); + found = true; + break; + } + } + if (!found) + { + cxxKineticsComp entity = *itadd; + entity.multiply(extensive); + this->kineticsComps.push_back(entity); + } + } + //std::vector steps; + this->steps = addee.steps; + //cxxNameDouble totals; + //double step_divide; + this->step_divide = addee.step_divide; + //int rk; + this->rk = addee.rk; + //int bad_step_max; + this->bad_step_max = addee.bad_step_max; + //bool use_cvode; + this->use_cvode = addee.use_cvode; + this->cvode_steps = addee.cvode_steps; + this->cvode_order = addee.cvode_order; } diff --git a/cxxMix.cxx b/cxxMix.cxx index 4a1665c6..641e5427 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -2,48 +2,51 @@ // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Utils.h" // define first +#include "Utils.h" // define first #include "cxxMix.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort +#include // assert +#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxMix::cxxMix() - // - // default constructor for cxxMix - // -: cxxNumKeyword() + // + // default constructor for cxxMix + // +: cxxNumKeyword() { } cxxMix::cxxMix(struct mix *mix_ptr) - // - // constructor for cxxMix from struct mix - // -: + // + // constructor for cxxMix from struct mix + // + : cxxNumKeyword() { - int i; + int i; - this->set_description(mix_ptr->description); - this->n_user = mix_ptr->n_user; - this->n_user_end = mix_ptr->n_user_end; + this->set_description(mix_ptr->description); + this->n_user = mix_ptr->n_user; + this->n_user_end = mix_ptr->n_user_end; // comps - if (mix_ptr->count_comps > 0) { - for (i = 0; i < mix_ptr->count_comps; i++) { - this->mixComps[mix_ptr->comps[i].n_solution] = mix_ptr->comps[i].fraction; + if (mix_ptr->count_comps > 0) + { + for (i = 0; i < mix_ptr->count_comps; i++) + { + this->mixComps[mix_ptr->comps[i].n_solution] = + mix_ptr->comps[i].fraction; } - } + } } cxxMix::~cxxMix() @@ -51,150 +54,187 @@ cxxMix::~cxxMix() } -struct mix *cxxMix::cxxMix2mix() - // - // Builds a mix structure from instance of cxxMix - // +struct mix * +cxxMix::cxxMix2mix() + // + // Builds a mix structure from instance of cxxMix + // { - struct mix *mix_ptr; - mix_ptr = (struct mix *) PHRQ_malloc(sizeof (struct mix)); - if (mix_ptr == NULL) malloc_error(); + struct mix *mix_ptr; + mix_ptr = (struct mix *) PHRQ_malloc(sizeof(struct mix)); + if (mix_ptr == NULL) + malloc_error(); - mix_ptr->description = this->get_description(); - mix_ptr->n_user = this->n_user; - mix_ptr->n_user_end = this->n_user_end; + mix_ptr->description = this->get_description(); + mix_ptr->n_user = this->n_user; + mix_ptr->n_user_end = this->n_user_end; // comps mix_ptr->comps = NULL; - if (this->mixComps.size() > 0) { + if (this->mixComps.size() > 0) + { int i = 0; - mix_ptr->comps = (struct mix_comp *) PHRQ_malloc((size_t) (this->mixComps.size() * sizeof(struct mix_comp))); - if (mix_ptr->comps == NULL) malloc_error(); - for (std::map::iterator it = mixComps.begin(); it != mixComps.end(); it++) { + mix_ptr->comps = + (struct mix_comp *) + PHRQ_malloc((size_t) + (this->mixComps.size() * sizeof(struct mix_comp))); + if (mix_ptr->comps == NULL) + malloc_error(); + for (std::map < int, double >::iterator it = mixComps.begin(); + it != mixComps.end(); it++) + { mix_ptr->comps[i].n_solution = it->first; mix_ptr->comps[i].fraction = it->second; i++; } } mix_ptr->count_comps = (int) this->mixComps.size(); - return(mix_ptr); + return (mix_ptr); } #ifdef SKIP -void cxxMix::dump_xml(std::ostream& s_oss, unsigned int indent)const +void +cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Mix element and attributes - s_oss << indent0; - s_oss << "pitzer_mix_gammas << "\"" << std::endl; + s_oss << indent1; + s_oss << "pitzer_mix_gammas=\"" << this-> + pitzer_mix_gammas << "\"" << std::endl; - // components - s_oss << indent1; - s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); - } + // components + s_oss << indent1; + s_oss << "::const_iterator it = mixComps.begin(); + it != mixComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } - return; + return; } #endif -void cxxMix::dump_raw(std::ostream& s_oss, unsigned int indent)const +void +cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; - unsigned int i; - s_oss.precision(DBL_DIG - 1); - std::string indent0(""), indent1(""), indent2(""); - for(i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - for(i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - for(i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); + //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); - // Mix element and attributes - s_oss << indent0; - s_oss << "MIX " << this->n_user << " " << this->description << std::endl; + // Mix element and attributes + s_oss << indent0; + s_oss << "MIX " << this->n_user << " " << this-> + description << std::endl; - for (std::map::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { + for (std::map < int, double >::const_iterator it = this->mixComps.begin(); + it != this->mixComps.end(); it++) + { s_oss << indent1 << it->first << " " << it->second << std::endl; } } -void cxxMix::read_raw(CParser& parser) +void +cxxMix::read_raw(CParser & parser) { int i; - double d; - static std::vector vopts; - if (vopts.empty()) { - vopts.reserve(15); - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); + double d; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + } - // Read mix number and description - this->read_number_description(parser); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); - opt_save = CParser::OPT_DEFAULT; + // Read mix number and description + this->read_number_description(parser); - 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_ERROR: - opt = CParser::OPT_EOF; - parser.error_msg("Unknown input in MIX_COMP_RAW keyword.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + opt_save = CParser::OPT_DEFAULT; - case CParser::OPT_DEFAULT: // solution number, mix fraction - if (parser.copy_token(token, next_char) != CParser::TT_EMPTY) { + 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_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input in MIX_COMP_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case CParser::OPT_DEFAULT: // solution number, mix fraction + if (parser.copy_token(token, next_char) != CParser::TT_EMPTY) + { std::istringstream iss(token); if (!(iss >> i)) - { - parser.incr_input_error(); - parser.error_msg("Expected integer value for solution number.", CParser::OT_CONTINUE); - break; - } + { + parser.incr_input_error(); + parser. + error_msg + ("Expected integer value for solution number.", + CParser::OT_CONTINUE); + break; + } if (!(parser.get_iss() >> d)) - { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for solution fraction.", CParser::OT_CONTINUE); - break; - } + { + parser.incr_input_error(); + parser. + error_msg + ("Expected numeric value for solution fraction.", + CParser::OT_CONTINUE); + break; + } this->mixComps[i] = d; } - opt_save = CParser::OPT_DEFAULT; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; - } - // members that must be defined + opt_save = CParser::OPT_DEFAULT; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined } From d37ed2c6ae99e235a5b68293db18638f400f2a2d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 31 Oct 2008 15:32:53 +0000 Subject: [PATCH 0084/1077] indented header files. removed ^M from System.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3169 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.h | 35 ++--- ExchComp.h | 179 ++++++++++++++++-------- Exchange.h | 64 +++++---- GasPhase.h | 64 ++++----- ISolution.h | 93 +++++++------ ISolutionComp.h | 139 +++++++++++++------ KineticsComp.h | 59 ++++---- NameDouble.h | 108 +++++++++------ NumKeyword.h | 67 ++++++--- PPassemblage.h | 64 +++++---- PPassemblageComp.h | 61 +++++---- Parser.h | 286 ++++++++++++++++++++++---------------- Reaction.h | 40 +++--- SAXPhreeqc.h | 15 +- SSassemblage.h | 51 +++---- SSassemblageSS.h | 83 +++++------ SaxPhreeqcHandlers.h | 244 ++++++++++++++++++++------------- Solution.h | 223 ++++++++++++++++++++---------- SolutionIsotope.h | 120 ++++++++++------ SolutionIsotopeList.h | 34 +++-- StorageBin.h | 310 ++++++++++++++++++++++++++---------------- Surface.h | 73 +++++----- SurfaceCharge.h | 63 +++++---- SurfaceComp.h | 123 ++++++++++------- System.h | 151 ++++++++++---------- Temperature.h | 36 ++--- Utils.h | 83 +++++------ char_star.h | 13 +- cxxKinetics.h | 63 ++++----- cxxMix.h | 59 ++++---- 30 files changed, 1776 insertions(+), 1227 deletions(-) diff --git a/Dictionary.h b/Dictionary.h index 98c0914e..8d3f96af 100644 --- a/Dictionary.h +++ b/Dictionary.h @@ -1,44 +1,45 @@ #if !defined(DICTIONARY_H_INCLUDED) #define DICTIONARY_H_INCLUDED -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "Solution.h" #include "NameDouble.h" class cxxDictionary { -public: - cxxDictionary(); + public: + cxxDictionary(); - ~cxxDictionary(); + ~cxxDictionary(); - void add_phreeqc(); + void add_phreeqc(); - int size() { + int size() + { return (int) stringkey.size(); } int putString(std::string str); - int putString(char * str); + int putString(char *str); int string2int(std::string str); - int string2int(char * str); + int string2int(char *str); - std::string *int2string(int i); + std::string * int2string(int i); char *int2char(int i); -protected: - std::map stringkey; - std::map intkey; + protected: + std::map < std::string, int >stringkey; + std::map < int, std::string > intkey; -public: + public: }; diff --git a/ExchComp.h b/ExchComp.h index 640872d2..353b496a 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -4,88 +4,149 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" class cxxExchComp { -public: - cxxExchComp(); - cxxExchComp(struct exch_comp *); - ~cxxExchComp(); + public: + cxxExchComp(); + cxxExchComp(struct exch_comp *); + ~cxxExchComp(); - struct master *get_master(); + struct master *get_master(); - static struct exch_comp *cxxExchComp2exch_comp(std::list& el); + static struct exch_comp *cxxExchComp2exch_comp(std::list < cxxExchComp > + &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); - char * get_formula()const { return this->formula;} - void set_formula(char * cstring) { this->formula = cstring;} - double get_moles()const { return this->moles;} - void set_moles(double d) { this->moles = d;} - double get_la()const { return this->la;} - void set_la(double d) { this->la = d;} - double get_charge_balance()const { return this->charge_balance;} - void set_charge_balance(double d) { this->charge_balance = d;} - char * get_phase_name()const { return this->phase_name;} - void set_phase_name(char * cstring) { this->phase_name = cstring;} - double get_phase_proportion()const { return this->phase_proportion;} - void set_phase_proportion(double d) { this->phase_proportion = d;} - char * get_rate_name()const { return this->rate_name;} - void set_rate_name(char * cstring) { this->rate_name = cstring;} - double get_formula_z()const { return this->formula_z;} - void set_formula_z(double d) { this->formula_z = d;} - void set_totals(struct elt_list *e_l, int count) - {this->totals = cxxNameDouble(e_l, count);} - void set_totals(struct elt_list *e_l) - {this->totals = cxxNameDouble(e_l);} - void set_totals(cxxNameDouble nd) - {this->totals = nd;} - void set_formula_totals(struct elt_list *e_l, int count) - {this->formula_totals = cxxNameDouble(e_l, count);} - void set_formula_totals(struct elt_list *e_l) - {this->formula_totals = cxxNameDouble(e_l);} - void set_formula_totals(cxxNameDouble nd) - {this->formula_totals = nd;} - - const cxxNameDouble &get_totals()const + char *get_formula() const { - return (this->totals); + return this->formula; + } + void set_formula(char *cstring) + { + this->formula = cstring; + } + double get_moles() const + { + return this->moles; + } + void set_moles(double d) + { + this->moles = d; + } + double get_la() const + { + return this->la; + } + void set_la(double d) + { + this->la = d; + } + double get_charge_balance() const + { + return this->charge_balance; + } + void set_charge_balance(double d) + { + this->charge_balance = d; + } + char *get_phase_name() const + { + return this->phase_name; + } + void set_phase_name(char *cstring) + { + this->phase_name = cstring; + } + double get_phase_proportion() const + { + return this->phase_proportion; + } + void set_phase_proportion(double d) + { + this->phase_proportion = d; + } + char *get_rate_name() const + { + return this->rate_name; + } + void set_rate_name(char *cstring) + { + this->rate_name = cstring; + } + double get_formula_z() const + { + return this->formula_z; + } + void set_formula_z(double d) + { + this->formula_z = d; + } + void set_totals(struct elt_list *e_l, int count) + { + this->totals = cxxNameDouble(e_l, count); + } + void set_totals(struct elt_list *e_l) + { + this->totals = cxxNameDouble(e_l); + } + void set_totals(cxxNameDouble nd) + { + this->totals = nd; + } + void set_formula_totals(struct elt_list *e_l, int count) + { + this->formula_totals = cxxNameDouble(e_l, count); + } + void set_formula_totals(struct elt_list *e_l) + { + this->formula_totals = cxxNameDouble(e_l); + } + void set_formula_totals(cxxNameDouble nd) + { + this->formula_totals = nd; + } + + const cxxNameDouble & get_totals() const + { + return (this->totals); }; - void add(const cxxExchComp &comp, double extensive); + void add(const cxxExchComp & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -protected: - char * formula; - double moles; - cxxNameDouble formula_totals; - cxxNameDouble totals; - double la; - double charge_balance; - char *phase_name; - double phase_proportion; - char *rate_name; - double formula_z; // charge on formula + protected: + char *formula; + double moles; + cxxNameDouble formula_totals; + cxxNameDouble totals; + double la; + double charge_balance; + char *phase_name; + double phase_proportion; + char *rate_name; + double formula_z; // charge on formula -public: + public: }; diff --git a/Exchange.h b/Exchange.h index bd93feca..9a234578 100644 --- a/Exchange.h +++ b/Exchange.h @@ -3,67 +3,71 @@ #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list +#include // assert +#include // std::map +#include // std::string +#include // std::list #include "ExchComp.h" #include "cxxMix.h" -class cxxExchange : public cxxNumKeyword +class cxxExchange:public cxxNumKeyword { -public: - cxxExchange(); + public: + cxxExchange(); cxxExchange(int n_user); - cxxExchange(struct exchange *); - cxxExchange(const std::map &exchange_map, cxxMix &mx, int n_user); - ~cxxExchange(); + cxxExchange(struct exchange *); + cxxExchange(const std::map < int, cxxExchange > &exchange_map, + cxxMix & mx, int n_user); + ~cxxExchange(); - struct exchange *cxxExchange2exchange(); + struct exchange *cxxExchange2exchange(); - struct exch_comp *cxxExchComp2exch_comp(); + struct exch_comp *cxxExchComp2exch_comp(); - 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 get_related_phases(void); + bool get_related_phases(void); - bool get_related_rate(void); + bool get_related_rate(void); - bool get_pitzer_exchange_gammas() { + bool get_pitzer_exchange_gammas() + { return this->pitzer_exchange_gammas; } - void set_pitzer_exchange_gammas(bool b) { + void set_pitzer_exchange_gammas(bool b) + { this->pitzer_exchange_gammas = b; } - std::list &get_exchComps(void) { - return(this->exchComps); + std::list < cxxExchComp > &get_exchComps(void) + { + return (this->exchComps); } void totalize(); - const cxxNameDouble& get_totals()const + const cxxNameDouble & get_totals() const { - return totals; + return totals; }; #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -private: - void add(const cxxExchange &addee, double extensive); + private: + void add(const cxxExchange & addee, double extensive); // not written - void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void dump_xml(std::ostream & os, unsigned int indent = 0) const; -protected: - std::list exchComps; - bool pitzer_exchange_gammas; + protected: + std::list < cxxExchComp > exchComps; + bool pitzer_exchange_gammas; cxxNameDouble totals; -public: + public: }; diff --git a/GasPhase.h b/GasPhase.h index 24188b85..4b6a86ce 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -5,63 +5,65 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" #include "cxxMix.h" -class cxxGasPhase : public cxxNumKeyword +class cxxGasPhase:public cxxNumKeyword { -public: - cxxGasPhase(); - cxxGasPhase(struct gas_phase *); - cxxGasPhase(const std::map &entity_map, cxxMix &mx, int n_user); - ~cxxGasPhase(); + public: + cxxGasPhase(); + cxxGasPhase(struct gas_phase *); + cxxGasPhase(const std::map < int, cxxGasPhase > &entity_map, + cxxMix & mx, int n_user); + ~cxxGasPhase(); - enum GP_TYPE { - GP_PRESSURE = 0, - GP_VOLUME = 1 - }; + enum GP_TYPE + { + GP_PRESSURE = 0, + GP_VOLUME = 1 + }; - struct gas_phase *cxxGasPhase2gas_phase(); + struct gas_phase *cxxGasPhase2gas_phase(); - struct gas_comp *cxxGasPhaseComp2gas_comp(); + struct gas_comp *cxxGasPhaseComp2gas_comp(); - //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); #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif void totalize(); - const cxxNameDouble& get_totals()const + const cxxNameDouble & get_totals() const { - return this->totals; + return this->totals; }; -private: - void add(const cxxGasPhase &addee, double extensive); + private: + void add(const cxxGasPhase & addee, double extensive); -protected: - cxxNameDouble gasPhaseComps; + protected: + cxxNameDouble gasPhaseComps; GP_TYPE type; - double total_p; - double volume; + double total_p; + double volume; cxxNameDouble totals; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/ISolution.h b/ISolution.h index 6d578d72..51fcb8ed 100644 --- a/ISolution.h +++ b/ISolution.h @@ -6,65 +6,78 @@ #include "NumKeyword.h" #include "Solution.h" //#include "Isotope.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector -#include // std::set +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector +#include // std::set #include #include #include -class cxxISolution : public cxxSolution +class cxxISolution:public cxxSolution { -public: - cxxISolution(); - cxxISolution(struct solution *); - //cxxISolution(const cxxISolution&); - ~cxxISolution(); + public: + cxxISolution(); + cxxISolution(struct solution *); + //cxxISolution(const cxxISolution&); + ~cxxISolution(); - //static cxxISolution& read(CParser& parser); + //static cxxISolution& read(CParser& parser); - //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } + //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - struct solution *cxxISolution2solution(); + struct solution *cxxISolution2solution(); - double get_density()const {return this->density;} - void set_density(double density) {this->density = density;} + double get_density() const + { + return this->density; + } + void set_density(double density) + { + this->density = density; + } - std::string get_units()const {return units;} - void set_units(std::string units) {units = units;} + std::string get_units() const + { + return units; + } + void set_units(std::string units) + { + units = units; + } - //char * get_redox()const {return this->pe[this->default_pe].get_name();} + //char * get_redox()const {return this->pe[this->default_pe].get_name();} - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void ConvertUnits(); #ifdef ORCHESTRA - void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); - void ORCH_write_chemistry(std::ostream &chemistry_dat); - void ORCH_write_input(std::ostream &input_dat); - void ORCH_write_output_vars(std::ostream &input_dat); -private: - void ORCH_write_chemistry_water(std::ostream &chemistry_dat); - void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); - void ORCH_write_chemistry_alkalinity(std::ostream &chemistry_dat); - void ORCH_write_chemistry_minerals(std::ostream &chemistry_dat); + void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat); + void ORCH_write_chemistry(std::ostream & chemistry_dat); + void ORCH_write_input(std::ostream & input_dat); + void ORCH_write_output_vars(std::ostream & input_dat); + private: + void ORCH_write_chemistry_water(std::ostream & chemistry_dat); + void ORCH_write_chemistry_primary(std::ostream & chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); + void ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat); + void ORCH_write_chemistry_minerals(std::ostream & chemistry_dat); #endif -protected: - friend class cxxISolutionComp; // for this->pe access - double density; - std::string units; - std::map comps; - struct pe_data *pes; - int default_pe; + protected: + friend class cxxISolutionComp; // for this->pe access + double density; + std::string units; + std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps; + struct pe_data *pes; + int default_pe; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/ISolutionComp.h b/ISolutionComp.h index 7b48063b..b2c3221b 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -9,70 +9,129 @@ #include "phrqproto.h" #include -#include // std::map +#include // std::map #include #include #include "char_star.h" // forward declarations -class cxxISolution; // reqd for read and dump_xml +class cxxISolution; // reqd for read and dump_xml class cxxISolutionComp { -public: - cxxISolutionComp(void); - cxxISolutionComp(struct conc *conc_ptr); - ~cxxISolutionComp(void); + public: + cxxISolutionComp(void); + cxxISolutionComp(struct conc *conc_ptr); + ~cxxISolutionComp(void); -public: + public: - //STATUS_TYPE read(CParser& parser, CSolution& sol); + //STATUS_TYPE read(CParser& parser, CSolution& sol); - void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void dump_xml(std::ostream & os, unsigned int indent = 0) const; - char * get_description()const {return this->description;} - void set_description(char * description) {this->description = description;} + char *get_description() const + { + return this->description; + } + void set_description(char *description) + { + this->description = description; + } - double get_moles()const {return this->moles;} - void set_moles(double moles) {this->moles = moles;} + double get_moles() const + { + return this->moles; + } + void set_moles(double moles) + { + this->moles = moles; + } - double get_input_conc()const {return this->input_conc;} - void set_input_conc(double input_conc) {this->input_conc = input_conc;} + double get_input_conc() const + { + return this->input_conc; + } + void set_input_conc(double input_conc) + { + this->input_conc = input_conc; + } - std::string get_units()const {return this->units;} - void set_units(char * units) {this->units = units;} + std::string get_units()const + { + return this->units; + } + void set_units(char *units) + { + this->units = units; + } - char * get_equation_name()const {return this->equation_name;} - void set_equation_name(char * equation_name) {this->equation_name = equation_name;} + char *get_equation_name() const + { + return this->equation_name; + } + void set_equation_name(char *equation_name) + { + this->equation_name = equation_name; + } - double get_phase_si()const {return this->phase_si;} - void set_phase_si(int phase_si) {this->phase_si = phase_si;} + double get_phase_si() const + { + return this->phase_si; + } + void set_phase_si(int phase_si) + { + this->phase_si = phase_si; + } - int get_n_pe()const {return this->n_pe;} - void set_n_pe(int n_pe) {this->n_pe = n_pe;} + int get_n_pe() const + { + return this->n_pe; + } + void set_n_pe(int n_pe) + { + this->n_pe = n_pe; + } - char *get_as()const {return this->as;} - void set_as(char *as) {this->as = as;} + char *get_as() const + { + return this->as; + } + void set_as(char *as) + { + this->as = as; + } - //double get_gfw()const {return this->gfw;} - double get_gfw()const {return this->gfw;}; - void set_gfw(double gfw) {this->gfw = gfw;} + //double get_gfw()const {return this->gfw;} + double get_gfw() const + { + return this->gfw; + }; + void set_gfw(double gfw) + { + this->gfw = gfw; + } void set_gfw(); - bool operator<(const cxxISolutionComp& conc)const { return ::strcmp(this->description, conc.description) < 0; } + bool operator<(const cxxISolutionComp & conc) const + { + return::strcmp(this->description, conc.description) < 0; + } - static struct conc * cxxISolutionComp2conc(const std::map &t ); + static struct conc *cxxISolutionComp2conc(const std::map < char *, + cxxISolutionComp, + CHARSTAR_LESS > &t); -private: - char * description; - double moles; - double input_conc; - char * units; - char * equation_name; - double phase_si; - int n_pe; - char * as; - double gfw; + private: + char *description; + double moles; + double input_conc; + char *units; + char *equation_name; + double phase_si; + int n_pe; + char *as; + double gfw; }; #endif // ISOLUTIONCOMP_H_INCLUDED diff --git a/KineticsComp.h b/KineticsComp.h index 7097f34a..c51a62b1 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -4,49 +4,54 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxKineticsComp +class cxxKineticsComp { -public: - cxxKineticsComp(); - cxxKineticsComp(struct kinetics_comp *); - ~cxxKineticsComp(); + public: + cxxKineticsComp(); + cxxKineticsComp(struct kinetics_comp *); + ~cxxKineticsComp(); - static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::list& el); + static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::list < + cxxKineticsComp + > &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); - - char *get_rate_name()const {return this->rate_name;} + void read_raw(CParser & parser); + + char *get_rate_name() const + { + return this->rate_name; + } #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); #endif - void add(const cxxKineticsComp &comp, double extensive); + void add(const cxxKineticsComp & comp, double extensive); void multiply(double extensive); -protected: - char * rate_name; - cxxNameDouble namecoef; //stoichiometry of reaction - double tol; - double m; - double m0; - double moles; - std::vector d_params; + protected: + char *rate_name; + cxxNameDouble namecoef; //stoichiometry of reaction + double tol; + double m; + double m0; + double moles; + std::vector < double >d_params; -public: + public: }; diff --git a/NameDouble.h b/NameDouble.h index 43130853..0ce531aa 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -2,73 +2,95 @@ #define NAMEDOUBLE_H_INCLUDED //#define EXTERNAL extern -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector //#include "global.h" #include "char_star.h" #include "Parser.h" -class cxxNameDouble : public std::map +class cxxNameDouble:public +std::map < char *, double, + CHARSTAR_LESS > { -public: - enum ND_TYPE { - ND_ELT_MOLES = 1, - ND_SPECIES_LA = 2, - ND_SPECIES_GAMMA = 3, - ND_NAME_COEF = 4 - }; + public: + enum ND_TYPE + { + ND_ELT_MOLES = 1, + ND_SPECIES_LA = 2, + ND_SPECIES_GAMMA = 3, + ND_NAME_COEF = 4 + }; - cxxNameDouble(); - cxxNameDouble(struct elt_list *); - cxxNameDouble(struct elt_list *, int count); - cxxNameDouble(struct conc *); - cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); - cxxNameDouble(struct name_coef *nc, int count); - cxxNameDouble(const cxxNameDouble &old, double factor); - ~cxxNameDouble(); + cxxNameDouble(); + cxxNameDouble(struct elt_list *); + cxxNameDouble(struct elt_list *, int count); + cxxNameDouble(struct conc *); + cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); + cxxNameDouble(struct name_coef *nc, int count); + cxxNameDouble(const cxxNameDouble & old, double factor); + ~ + cxxNameDouble(); - struct elt_list *elt_list(); + struct elt_list * + elt_list(); - struct master_activity *master_activity()const; + struct master_activity * + master_activity() const; - struct conc *conc()const; + struct conc * + conc() const; - struct name_coef *name_coef()const; + struct name_coef * + name_coef() const; - void dump_xml(std::ostream& s_oss, unsigned int indent)const; + void + dump_xml(std::ostream & s_oss, unsigned int indent) const; - void dump_raw(std::ostream& s_oss, unsigned int indent)const; + void + dump_raw(std::ostream & s_oss, unsigned int indent) const; - CParser::STATUS_TYPE read_raw(CParser& parser, std::istream::pos_type& pos); + CParser::STATUS_TYPE + read_raw(CParser & parser, std::istream::pos_type & pos); - void add_extensive(const cxxNameDouble &old, double factor); - void add_intensive(const cxxNameDouble &addee, double fthis, double f2); - void add_log_activities(const cxxNameDouble &addee, double fthis, double f2); - void add(const char * key, double total); - void multiply(double factor); + void + add_extensive(const cxxNameDouble & old, double factor); + void + add_intensive(const cxxNameDouble & addee, double fthis, double f2); + void + add_log_activities(const cxxNameDouble & addee, double fthis, double f2); + void + add(const char *key, double total); + void + multiply(double factor); - void insert(char *str, double d) { + void + insert(char *str, double d) + { (*this)[str] = d; } - void mpi_pack(std::vector& ints, std::vector& doubles); - void mpi_pack(int *ints, int *ii, double *doubles, int *dd); + void + mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void + mpi_pack(int *ints, int *ii, double *doubles, int *dd); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void + mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - enum ND_TYPE type; - -protected: + enum ND_TYPE + type; - //std::map totals; + protected: + + //std::map totals; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/NumKeyword.h b/NumKeyword.h index 55298566..9c31fb69 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -2,8 +2,8 @@ #define NUMKEYWORD_H_INCLUDED #include "Parser.h" -#include // std::ostream -#include // std::string +#include // std::ostream +#include // std::string //#define EXTERNAL extern //#include "global.h" //#include "phrqproto.h" @@ -11,33 +11,58 @@ extern char *string_duplicate(const char *); class cxxNumKeyword { -public: - cxxNumKeyword(); - virtual ~cxxNumKeyword(); + public: + cxxNumKeyword(); + virtual ~ cxxNumKeyword(); - char * get_description()const { return string_duplicate(this->description.c_str()); } - void set_description(std::string str) { this->description = str; } - void set_description(char * str) { if (str != NULL) this->description = str; } + char *get_description() const + { + return string_duplicate(this->description.c_str()); + } + void set_description(std::string str) + { + this->description = str; + } + void set_description(char *str) + { + if (str != NULL) + this->description = str; + } - int get_n_user()const { return this->n_user; } - void set_n_user(int user) { this->n_user = user; } + int get_n_user() const + { + return this->n_user; + } + void set_n_user(int user) + { + this->n_user = user; + } - int get_n_user_end()const { return this->n_user_end; } - void set_n_user_end(int user_end) { this->n_user_end = user_end; } + int get_n_user_end() const + { + return this->n_user_end; + } + void set_n_user_end(int user_end) + { + this->n_user_end = user_end; + } - bool operator<(const cxxNumKeyword& key)const { return (this->n_user < key.n_user); } + bool operator<(const cxxNumKeyword & key) const + { + return (this->n_user < key.n_user); + } - virtual void dump_xml(std::ostream& os, unsigned int indent = 0)const; + virtual void dump_xml(std::ostream & os, unsigned int indent = 0) const; - void read_number_description(CParser& parser); + void read_number_description(CParser & parser); -protected: - int n_user; - int n_user_end; - std::string description; + protected: + int n_user; + int n_user_end; + std::string description; -private: - void read_number_description(std::istream& is); + private: + void read_number_description(std::istream & is); }; #endif // !defined(NUMKEYWORD_H_INCLUDED) diff --git a/PPassemblage.h b/PPassemblage.h index ff2e3f44..b47d5654 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -4,63 +4,67 @@ #include "NumKeyword.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" #include "PPassemblageComp.h" #include "cxxMix.h" -class cxxPPassemblage : public cxxNumKeyword +class cxxPPassemblage:public cxxNumKeyword { -public: - cxxPPassemblage(); - cxxPPassemblage(struct pp_assemblage *); - cxxPPassemblage(const std::map &entity_map, cxxMix &mx, int n_user); - ~cxxPPassemblage(); + public: + cxxPPassemblage(); + cxxPPassemblage(struct pp_assemblage *); + cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map, + cxxMix & mx, int n_user); + ~cxxPPassemblage(); - struct pp_assemblage *cxxPPassemblage2pp_assemblage(); + struct pp_assemblage *cxxPPassemblage2pp_assemblage(); - struct pure_phase *cxxPPassemblageComp2pure_phase(); + struct pure_phase *cxxPPassemblageComp2pure_phase(); - 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); - const cxxNameDouble& get_totals()const + const cxxNameDouble & get_totals() const { - return this->totals; + return this->totals; }; #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif void totalize(); #ifdef ORCHESTRA - void ORCH_write_chemistry(std::ostream &chemistry_dat); - void ORCH_write_output_vars(std::ostream &outstream); - void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); - void ORCH_store_global(std::map < std::string, double > output_map); + void ORCH_write_chemistry(std::ostream & chemistry_dat); + void ORCH_write_output_vars(std::ostream & outstream); + void ORCH_read(std::vector < std::pair < std::string, + double >>output_vector, + std::vector < std::pair < std::string, + double >>::iterator & it); + void ORCH_store_global(std::map < std::string, double >output_map); #endif -private: - void add(const cxxPPassemblage &addee, double extensive); + private: + void add(const cxxPPassemblage & addee, double extensive); // not written - void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void dump_xml(std::ostream & os, unsigned int indent = 0) const; -protected: - std::list ppAssemblageComps; - cxxNameDouble eltList; + protected: + std::list < cxxPPassemblageComp > ppAssemblageComps; + cxxNameDouble eltList; cxxNameDouble totals; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/PPassemblageComp.h b/PPassemblageComp.h index fbb6aa72..b64096ee 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -4,60 +4,65 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" class cxxPPassemblageComp { -public: - cxxPPassemblageComp(); - cxxPPassemblageComp(struct pure_phase *); - ~cxxPPassemblageComp(); + public: + cxxPPassemblageComp(); + cxxPPassemblageComp(struct pure_phase *); + ~cxxPPassemblageComp(); - static struct pure_phase *cxxPPassemblageComp2pure_phase(std::list& el); + static struct pure_phase *cxxPPassemblageComp2pure_phase(std::list < + cxxPPassemblageComp + > &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); - char *get_name()const {return this->name;} + char *get_name() const + { + return this->name; + } - struct phase *get_phase(); + struct phase *get_phase(); void totalize(); - const cxxNameDouble &get_totals()const + const cxxNameDouble & get_totals() const { - return (this->totals); + return (this->totals); }; - void add(const cxxPPassemblageComp &comp, double extensive); + void add(const cxxPPassemblageComp & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -protected: - char *name; - char *add_formula; - double si; - double moles; - double delta; - double initial_moles; + protected: + char *name; + char *add_formula; + double si; + double moles; + double delta; + double initial_moles; bool force_equality; - bool dissolve_only; + bool dissolve_only; cxxNameDouble totals; -public: + public: }; diff --git a/Parser.h b/Parser.h index 335d552c..4a433053 100644 --- a/Parser.h +++ b/Parser.h @@ -2,84 +2,92 @@ #define PARSER_H_INCLUDED extern int input_error; -#include // std::string -#include // std::map -#include // std::vector -#include // std::istringstream std::ostringstream -#include // std::ostream -#include // std::istream +#include // std::string +#include // std::map +#include // std::vector +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream #include "char_star.h" class CParser { -public: - CParser(std::istream& input); - CParser(std::istream& input, std::ostream& output); - CParser(std::istream& input, std::ostream& output, std::ostream& error); + public: + CParser(std::istream & input); + CParser(std::istream & input, std::ostream & output); + CParser(std::istream & input, std::ostream & output, + std::ostream & error); - virtual ~CParser(); + virtual ~ CParser(); - enum LINE_TYPE { - LT_EOF = -1, - LT_OK = 1, - LT_EMPTY = 2, - LT_KEYWORD = 3, - LT_OPTION = 8 - }; + enum LINE_TYPE + { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; - enum TOKEN_TYPE { - TT_EMPTY = 2, - TT_UPPER = 4, - TT_LOWER = 5, - TT_DIGIT = 6, - TT_UNKNOWN = 7 - }; + enum TOKEN_TYPE + { + TT_EMPTY = 2, + TT_UPPER = 4, + TT_LOWER = 5, + TT_DIGIT = 6, + TT_UNKNOWN = 7 + }; - enum FIND_TYPE { - FT_OK = 0, - FT_ERROR = 1 - }; + enum FIND_TYPE + { + FT_OK = 0, + FT_ERROR = 1 + }; - enum KEY_TYPE { - KT_NONE = -1, - KT_END = 0, - KT_EOF = 1, - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 + enum KEY_TYPE + { + KT_NONE = -1, + KT_END = 0, + KT_EOF = 1, + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11 + }; - }; + enum OPT_TYPE + { + OPT_DEFAULT = -4, + OPT_ERROR = -3, + OPT_KEYWORD = -2, + OPT_EOF = -1 + }; - enum OPT_TYPE { - OPT_DEFAULT = -4, - OPT_ERROR = -3, - OPT_KEYWORD = -2, - OPT_EOF = -1 - }; + enum ONERROR_TYPE + { + OT_CONTINUE = 0, + OT_STOP = 1 + }; - enum ONERROR_TYPE { - OT_CONTINUE = 0, - OT_STOP = 1 - }; - - enum ECHO_OPTION { - EO_NONE = 0, - EO_ALL = 1, - EO_KEYWORDS = 2, - EO_NOKEYWORDS = 3 - }; + enum ECHO_OPTION + { + EO_NONE = 0, + EO_ALL = 1, + EO_KEYWORDS = 2, + EO_NOKEYWORDS = 3 + }; - enum STATUS_TYPE { - PARSER_ERROR = 0, - PARSER_OK = 1 - }; + enum STATUS_TYPE + { + PARSER_ERROR = 0, + PARSER_OK = 1 + }; - /** + /** Function gets a new line and checks for empty, eof, and keywords. Arguments: @@ -98,9 +106,10 @@ public: Terminates if EOF and allow_eof == false. */ - LINE_TYPE check_line(const std::string& str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print); + LINE_TYPE check_line(const std::string & str, bool allow_empty, + bool allow_eof, bool allow_keyword, bool print); - /** + /** Read a line from input file put in "line". Copy of input line is stored in "line_save". Characters after # are discarded in line but retained in "line_save" @@ -114,30 +123,54 @@ public: LT_OK, LT_OPTION */ - LINE_TYPE get_line(); + LINE_TYPE get_line(); - // bool check_key(const std::string::iterator ptr); - bool check_key(std::string::iterator begin, std::string::iterator end); + // bool check_key(const std::string::iterator ptr); + bool check_key(std::string::iterator begin, std::string::iterator end); - STATUS_TYPE check_units(std::string& tot_units, bool alkalinity, bool check_compatibility, - const std::string& default_units, bool print); + STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, + bool check_compatibility, + const std::string & default_units, bool print); - KEY_TYPE next_keyword()const { return m_next_keyword; } - int get_option(const std::vector& opt_list, std::string::iterator& next_char); - int get_option(const std::vector& opt_list, std::istream::pos_type& next_pos); - int getOptionFromLastLine(const std::vector& opt_list, std::string::iterator& next_char); - int getOptionFromLastLine(const std::vector& opt_list, std::istream::pos_type& next_pos); + KEY_TYPE next_keyword() const + { + return m_next_keyword; + } + int get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char); + int get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos); - std::string& line() {return m_line;} - std::istringstream& get_iss() {return m_line_iss;} - int incr_input_error() {++::input_error; return ++m_input_error;} - std::ostream& get_output() {return m_output_stream;} - int get_input_error() {return m_input_error;} + std::string & line() + { + return m_line; + } + std::istringstream & get_iss() + { + return m_line_iss; + } + int incr_input_error() + { + ++::input_error; + return ++m_input_error; + } + std::ostream & get_output() + { + return m_output_stream; + } + int get_input_error() + { + return m_input_error; + } - /** + /** Copies from begin to token until first space is encountered. Arguments: @@ -152,13 +185,15 @@ public: TT_DIGIT TT_UNKNOWN */ - static TOKEN_TYPE copy_token(std::string& token, std::string::iterator& begin, std::string::iterator& end); - static TOKEN_TYPE token_type(const std::string& token); - static TOKEN_TYPE copy_token(std::string& token, std::istream& is); - TOKEN_TYPE copy_token(std::string& token, std::istream::pos_type& pos); - CParser::TOKEN_TYPE peek_token(); + static TOKEN_TYPE copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); + static TOKEN_TYPE token_type(const std::string & token); + static TOKEN_TYPE copy_token(std::string & token, std::istream & is); + TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); + CParser::TOKEN_TYPE peek_token(); - /** + /** Function reads an element name out of the equation string. An element name is composed of a capital letter followed by any number of lower case characters. @@ -170,10 +205,12 @@ public: end input, points to last position in the equation element input pointer to place to return element character string */ - STATUS_TYPE get_elt(std::string::iterator& begin, const std::string::iterator end, std::string& element); + STATUS_TYPE get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element); - /** + /** Compares a string value to match beginning letters of a list of options Arguments: @@ -189,39 +226,58 @@ public: n -1 item not matched i position of match in list */ - static FIND_TYPE find_option(const std::string& item, int *n, const std::vector& list, bool exact); + static FIND_TYPE find_option(const std::string & item, int *n, + const std::vector < std::string > &list, + bool exact); - int error_msg(const std::ostringstream& err_str, ONERROR_TYPE stop) {return error_msg(err_str.str().c_str(), stop);} - int error_msg(const char *err_str, ONERROR_TYPE stop); - int warning_msg(const char *err_str); - - void set_echo_file(ECHO_OPTION opt) {echo_file = opt;} - ECHO_OPTION get_echo_file() {return this->echo_file;}; + int error_msg(const std::ostringstream & err_str, ONERROR_TYPE stop) + { + return error_msg(err_str.str().c_str(), stop); + } + int error_msg(const char *err_str, ONERROR_TYPE stop); + int warning_msg(const char *err_str); - void set_echo_stream(ECHO_OPTION opt) {echo_stream = opt;} - ECHO_OPTION get_echo_stream() {return this->echo_stream;}; + void set_echo_file(ECHO_OPTION opt) + { + echo_file = opt; + } + ECHO_OPTION get_echo_file() + { + return this->echo_file; + }; - STATUS_TYPE parse_couple(std::string& token); + void set_echo_stream(ECHO_OPTION opt) + { + echo_stream = opt; + } + ECHO_OPTION get_echo_stream() + { + return this->echo_stream; + }; - STATUS_TYPE addPair(std::map &totals, std::istream::pos_type& pos); - STATUS_TYPE addPair(std::map &totals, std::istream::pos_type& pos); + STATUS_TYPE parse_couple(std::string & token); -protected: - LINE_TYPE get_logical_line(); + STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, + std::istream::pos_type & pos); + STATUS_TYPE addPair(std::map < char *, double >&totals, + std::istream::pos_type & pos); -private: - std::istream& m_input_stream; - std::ostream& m_output_stream; - std::ostream& m_error_stream; - int m_input_error; - KEY_TYPE m_next_keyword; - std::string m_line; - std::string m_line_save; - std::istringstream m_line_iss; - LINE_TYPE m_line_type; - ECHO_OPTION echo_stream; - ECHO_OPTION echo_file; + protected: + LINE_TYPE get_logical_line(); + + private: + std::istream & m_input_stream; + std::ostream & m_output_stream; + std::ostream & m_error_stream; + int m_input_error; + KEY_TYPE m_next_keyword; + std::string m_line; + std::string m_line_save; + std::istringstream m_line_iss; + LINE_TYPE m_line_type; + ECHO_OPTION echo_stream; + ECHO_OPTION echo_file; }; #endif // PARSER_H_INCLUDED diff --git a/Reaction.h b/Reaction.h index 8c5e6dd0..7705302e 100644 --- a/Reaction.h +++ b/Reaction.h @@ -5,40 +5,40 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxReaction : public cxxNumKeyword +class cxxReaction:public cxxNumKeyword { -public: - cxxReaction(); - cxxReaction(struct irrev *); - ~cxxReaction(); + public: + cxxReaction(); + cxxReaction(struct irrev *); + ~cxxReaction(); - struct irrev *cxxReaction2irrev(); + struct irrev *cxxReaction2irrev(); - //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); -protected: - cxxNameDouble reactantList; - cxxNameDouble elementList; - std::vector steps; + protected: + cxxNameDouble reactantList; + cxxNameDouble elementList; + std::vector < double >steps; int countSteps; bool equalIncrements; char *units; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/SAXPhreeqc.h b/SAXPhreeqc.h index 68a1f587..62b0da05 100644 --- a/SAXPhreeqc.h +++ b/SAXPhreeqc.h @@ -2,15 +2,16 @@ #define _INC_SAXPHREEQC_H #if defined(__cplusplus) | defined(_CPP) -extern "C" { +extern "C" +{ #endif -void SAX_StartSystem (); -int SAX_AddSolution (struct solution* solution_ptr); -void SAX_EndSystem (); -int SAX_GetXMLLength (); -const char* SAX_GetXMLStr (); -int SAX_UnpackSolutions(void* pvBuffer, int buf_size); + void SAX_StartSystem(); + int SAX_AddSolution(struct solution *solution_ptr); + void SAX_EndSystem(); + int SAX_GetXMLLength(); + const char *SAX_GetXMLStr(); + int SAX_UnpackSolutions(void *pvBuffer, int buf_size); #if defined(__cplusplus) | defined(_CPP) diff --git a/SSassemblage.h b/SSassemblage.h index 00c5f99d..c3255ec3 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -4,56 +4,57 @@ #include "NumKeyword.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" #include "SSassemblageSS.h" #include "cxxMix.h" -class cxxSSassemblage : public cxxNumKeyword +class cxxSSassemblage:public cxxNumKeyword { -public: - cxxSSassemblage(); - cxxSSassemblage(struct s_s_assemblage *); - cxxSSassemblage(const std::map &entity_map, cxxMix &mx, int n_user); - ~cxxSSassemblage(); + public: + cxxSSassemblage(); + cxxSSassemblage(struct s_s_assemblage *); + cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, + cxxMix & mx, int n_user); + ~cxxSSassemblage(); - struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); + struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); - struct s_s *cxxSSassemblageComp2s_s(); + struct s_s *cxxSSassemblageComp2s_s(); - //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); #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif void totalize(); - const cxxNameDouble& get_totals()const + const cxxNameDouble & get_totals() const { - return this->totals; + return this->totals; }; -private: - void add(const cxxSSassemblage &addee, double extensive); + private: + void add(const cxxSSassemblage & addee, double extensive); -protected: - std::list ssAssemblageSSs; + protected: + std::list < cxxSSassemblageSS > ssAssemblageSSs; cxxNameDouble totals; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/SSassemblageSS.h b/SSassemblageSS.h index ca23b2e4..c999d104 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -4,70 +4,75 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxSSassemblageSS +class cxxSSassemblageSS { -public: - cxxSSassemblageSS(); - cxxSSassemblageSS(struct s_s *); - ~cxxSSassemblageSS(); + public: + cxxSSassemblageSS(); + cxxSSassemblageSS(struct s_s *); + ~cxxSSassemblageSS(); - enum SS_PARAMETER_TYPE { - SS_PARM_NONE = -1, - SS_PARM_A0_A1 = 0, - SS_PARM_GAMMAS = 1, - SS_PARM_DIST_COEF = 2, - SS_PARM_MISCIBILITY = 3, - SS_PARM_SPINODAL = 4, - SS_PARM_CRITICAL = 5, - SS_PARM_ALYOTROPIC = 6, - SS_PARM_DIM_GUGG = 7, - SS_PARM_WALDBAUM = 8, - SS_PARM_MARGULES = 9 - }; + enum SS_PARAMETER_TYPE + { + SS_PARM_NONE = -1, + SS_PARM_A0_A1 = 0, + SS_PARM_GAMMAS = 1, + SS_PARM_DIST_COEF = 2, + SS_PARM_MISCIBILITY = 3, + SS_PARM_SPINODAL = 4, + SS_PARM_CRITICAL = 5, + SS_PARM_ALYOTROPIC = 6, + SS_PARM_DIM_GUGG = 7, + SS_PARM_WALDBAUM = 8, + SS_PARM_MARGULES = 9 + }; - static struct s_s *cxxSSassemblageSS2s_s(std::list& el); + static struct s_s *cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > + &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); - - char *get_name()const {return this->name;} + void read_raw(CParser & parser); + + char *get_name() const + { + return this->name; + } void totalize(); - const cxxNameDouble &get_totals()const + const cxxNameDouble & get_totals() const { - return (this->totals); + return (this->totals); }; #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - void add(const cxxSSassemblageSS &comp, double extensive); + void add(const cxxSSassemblageSS & comp, double extensive); void multiply(double extensive); -protected: - char *name; + protected: + char *name; cxxNameDouble comps; - double a0, a1; - double ag0, ag1; - bool miscibility; + double a0, a1; + double ag0, ag1; + bool miscibility; double xb1, xb2; cxxNameDouble totals; -public: + public: }; diff --git a/SaxPhreeqcHandlers.h b/SaxPhreeqcHandlers.h index 2eb590a7..eb247ed9 100644 --- a/SaxPhreeqcHandlers.h +++ b/SaxPhreeqcHandlers.h @@ -9,8 +9,8 @@ #pragma once #endif // _MSC_VER > 1000 -#include // iswspace sprintf -#include // SAX2XMLReader +#include // iswspace sprintf +#include // SAX2XMLReader /** #include **/ @@ -25,10 +25,17 @@ #define LDBLE double #endif -struct XMLCH_LESS : std::binary_function { -bool operator()(const XMLCh* _X, const XMLCh* _Y) const +struct XMLCH_LESS: +std::binary_function < const XMLCh *, const XMLCh *, + bool > { - return xns::XMLString::compareString( _X, _Y) < 0;} + bool + operator() (const XMLCh * _X, const XMLCh * _Y) const + { + return + xns::XMLString::compareString(_X, _Y) < + 0; + } }; #include @@ -41,114 +48,159 @@ bool operator()(const XMLCh* _X, const XMLCh* _Y) const //} -class Cconc : public conc +class + Cconc: + public + conc { -public: - Cconc() { conc_init(this); } - ~Cconc() { ; } + public: + Cconc() + { + conc_init(this); + } + ~ + Cconc() + {; + } }; -class SaxPhreeqcHandlers : public xns::DefaultHandler +class + SaxPhreeqcHandlers: + public + xns::DefaultHandler { -public: - SaxPhreeqcHandlers(); - virtual ~SaxPhreeqcHandlers(); + public: + SaxPhreeqcHandlers(); + virtual ~ + SaxPhreeqcHandlers(); - // ----------------------------------------------------------------------- - // Implementations of the SAX DocumentHandler interface - // ----------------------------------------------------------------------- - void endDocument(); + // ----------------------------------------------------------------------- + // Implementations of the SAX DocumentHandler interface + // ----------------------------------------------------------------------- + void + endDocument(); - void endElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname); + void + endElement(const XMLCh * const uri, const XMLCh * const name, + const XMLCh * const qname); - void characters(const XMLCh* const chars, const unsigned int length); + void + characters(const XMLCh * const chars, const unsigned int length); - void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); + void + ignorableWhitespace(const XMLCh * const chars, const unsigned int length); - void processingInstruction(const XMLCh* const target, const XMLCh* const data); + void + processingInstruction(const XMLCh * const target, + const XMLCh * const data); - void startDocument(); + void + startDocument(); - void startElement(const XMLCh* const uri, const XMLCh* const name, const XMLCh* const qname, const xns::Attributes& attributes); + void + startElement(const XMLCh * const uri, const XMLCh * const name, + const XMLCh * const qname, + const xns::Attributes & attributes); - // element types - enum elementType - { - typeNULL, - typePHAST_STATE, - typeSYSTEM, - typeSOLUTION, - typeSOLN_PE, - typeSOLN_TOTAL, - typeSOLN_MASTER_ACTIVITY, - typeSOLN_ISOTOPE, - typeSOLN_SPECIES_GAMMA - } eltType; - // attribute types - enum attributeType - { - attNULL, - attSOLN_new_def, - attSOLN_n_user, - attSOLN_n_user_end, - attSOLN_description, - attSOLN_tc, - attSOLN_ph, - attSOLN_solution_pe, - attSOLN_mu, - attSOLN_ah2o, - attSOLN_density, - attSOLN_total_h, - attSOLN_total_o, - attSOLN_cb, - attSOLN_mass_water, - attSOLN_total_alkalinity, - attSOLN_total_co2, - attSOLN_units, - attSOLN_default_pe, - attSOLN_count_master_activity, - attSOLN_count_isotopes, - attSOLN_count_species_gamma, - attSOLN_PE_name, - attM_A_description, - attM_A_la, - attM_A_list, - attISO_isotope_number, - attISO_elt_name, - attISO_isotope_name, - attISO_total, - attISO_ratio, - attISO_ratio_uncertainty, - attISO_x_ratio_uncertainty, - attISO_coef, - attCONC_description, - attCONC_moles, - attCONC_input_conc, - attCONC_units, - attCONC_equation_name, - attCONC_phase_si, - attCONC_n_pe, - attCONC_as, - attCONC_gfw, - } attType; + // element types + enum elementType + { + typeNULL, + typePHAST_STATE, + typeSYSTEM, + typeSOLUTION, + typeSOLN_PE, + typeSOLN_TOTAL, + typeSOLN_MASTER_ACTIVITY, + typeSOLN_ISOTOPE, + typeSOLN_SPECIES_GAMMA + } eltType; + // attribute types + enum attributeType + { + attNULL, + attSOLN_new_def, + attSOLN_n_user, + attSOLN_n_user_end, + attSOLN_description, + attSOLN_tc, + attSOLN_ph, + attSOLN_solution_pe, + attSOLN_mu, + attSOLN_ah2o, + attSOLN_density, + attSOLN_total_h, + attSOLN_total_o, + attSOLN_cb, + attSOLN_mass_water, + attSOLN_total_alkalinity, + attSOLN_total_co2, + attSOLN_units, + attSOLN_default_pe, + attSOLN_count_master_activity, + attSOLN_count_isotopes, + attSOLN_count_species_gamma, + attSOLN_PE_name, + attM_A_description, + attM_A_la, + attM_A_list, + attISO_isotope_number, + attISO_elt_name, + attISO_isotope_name, + attISO_total, + attISO_ratio, + attISO_ratio_uncertainty, + attISO_x_ratio_uncertainty, + attISO_coef, + attCONC_description, + attCONC_moles, + attCONC_input_conc, + attCONC_units, + attCONC_equation_name, + attCONC_phase_si, + attCONC_n_pe, + attCONC_as, + attCONC_gfw, + } attType; - int processSolutionAttributes(const xns::Attributes& attributes); - int processSolutionTotalAttributes(const xns::Attributes& attributes, struct conc *c); - int processMasterActivityAttributes(const xns::Attributes& attributes, struct master_activity *ma); - //int processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v); - int processIsotopeAttributes(const xns::Attributes& attributes, struct isotope *iso); + int + processSolutionAttributes(const xns::Attributes & attributes); + int + processSolutionTotalAttributes(const xns::Attributes & attributes, + struct conc *c); + int + processMasterActivityAttributes(const xns::Attributes & attributes, + struct master_activity *ma); + //int processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v); + int + processIsotopeAttributes(const xns::Attributes & attributes, + struct isotope *iso); -protected: - std::vector totals; - std::vector acts, s_gammas; - std::vector isotopes; - std::map< const XMLCh*, elementType, XMLCH_LESS > mapXMLCh2Type; - std::map< const XMLCh*, attributeType, XMLCH_LESS > mapXMLCh2AttType; - /** + protected: + std::vector < + conc > + totals; + std::vector < + master_activity > + acts, + s_gammas; + std::vector < + isotope > + isotopes; + std::map < const XMLCh *, + elementType, + XMLCH_LESS > + mapXMLCh2Type; + std::map < const XMLCh *, + attributeType, + XMLCH_LESS > + mapXMLCh2AttType; + /** std::hash_map, XMLCH_EQUALS> m_hashmapXMLCh2Type; **/ - struct solution* solution_ptr; + struct solution * + solution_ptr; }; #endif // !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_) diff --git a/Solution.h b/Solution.h index 04261ee8..8804d8d5 100644 --- a/Solution.h +++ b/Solution.h @@ -8,116 +8,193 @@ //#define EXTERNAL extern //#include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::vector #include #include "char_star.h" -class cxxSolution : public cxxNumKeyword +class cxxSolution:public cxxNumKeyword { -public: - cxxSolution(); - cxxSolution(struct solution *); - cxxSolution(int n_user); - cxxSolution(const std::map &solution_map, cxxMix &mx, int n_user); - ~cxxSolution(); + public: + cxxSolution(); + cxxSolution(struct solution *); + cxxSolution(int n_user); + cxxSolution(const std::map < int, cxxSolution > &solution_map, + cxxMix & mx, int n_user); + ~cxxSolution(); - //static cxxSolution& read(CParser& parser); + //static cxxSolution& read(CParser& parser); - double get_tc()const {return this->tc;} - void set_tc(double tc) {this->tc = tc;} + double get_tc() const + { + return this->tc; + } + void set_tc(double tc) + { + this->tc = tc; + } - double get_ph()const {return this->ph;} - void set_ph(double pH) {this->ph = pH;} + double get_ph() const + { + return this->ph; + } + void set_ph(double pH) + { + this->ph = pH; + } - double get_pe()const {return this->pe;} - void set_pe(double pe) {this->pe =pe;} + double get_pe() const + { + return this->pe; + } + void set_pe(double pe) + { + this->pe = pe; + } - double get_mu()const {return this->mu;} - void set_mu(double mu) {this->mu = mu;} + double get_mu() const + { + return this->mu; + } + void set_mu(double mu) + { + this->mu = mu; + } - double get_ah2o()const {return this->ah2o;} - void set_ah2o(double ah2o) {this->ah2o = ah2o;} + double get_ah2o() const + { + return this->ah2o; + } + void set_ah2o(double ah2o) + { + this->ah2o = ah2o; + } - double get_total_h()const {return this->total_h;} - void set_total_h(double total_h) {this->total_h = total_h;} + double get_total_h() const + { + return this->total_h; + } + void set_total_h(double total_h) + { + this->total_h = total_h; + } - double get_total_o()const {return this->total_o;} - void set_total_o(double total_o) {this->total_o = total_o;} + double get_total_o() const + { + return this->total_o; + } + void set_total_o(double total_o) + { + this->total_o = total_o; + } - double get_cb()const {return this->cb;} - void set_cb(double cb) {this->cb = cb;} + double get_cb() const + { + return this->cb; + } + void set_cb(double cb) + { + this->cb = cb; + } - double get_mass_water()const {return this->mass_water;} - void set_mass_water(long double mass_water) {this->mass_water = mass_water;} + double get_mass_water() const + { + return this->mass_water; + } + void set_mass_water(long double mass_water) + { + this->mass_water = mass_water; + } - double get_total_alkalinity()const {return this->total_alkalinity;} - void set_total_alkalinity(double total_alkalinity) {this->total_alkalinity = total_alkalinity;} + double get_total_alkalinity() const + { + return this->total_alkalinity; + } + void set_total_alkalinity(double total_alkalinity) + { + this->total_alkalinity = total_alkalinity; + } - double get_total(char *string)const; - double get_total_element(char *string)const; + double get_total(char *string) const; + double get_total_element(char *string) const; void set_total(char *string, double value); - const cxxNameDouble& get_totals(void)const {return this->totals;} - void set_totals(cxxNameDouble &nd) {this->totals = nd; this->totals.type = cxxNameDouble::ND_ELT_MOLES;} - void clear_totals() {this->totals.clear();} + const cxxNameDouble & get_totals(void) const + { + return this->totals; + } + void set_totals(cxxNameDouble & nd) + { + this->totals = nd; + this->totals.type = cxxNameDouble::ND_ELT_MOLES; + } + void clear_totals() + { + this->totals.clear(); + } - const cxxNameDouble& get_master_activity(void)const {return this->master_activity;} - double get_master_activity(char *string)const; + const cxxNameDouble & get_master_activity(void) const + { + return this->master_activity; + } + double get_master_activity(char *string) const; void set_master_activity(char *string, double value); /* - double get_species_gamma(char *string)const; - void set_species_gamma(char *string, double value); + double get_species_gamma(char *string)const; + void set_species_gamma(char *string, double value); - double get_isotope(char *string)const; - void set_isotope(char *string, double value); - */ + double get_isotope(char *string)const; + void set_isotope(char *string, double value); + */ - struct solution *cxxSolution2solution(); + struct solution *cxxSolution2solution(); - 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); void multiply(double extensive); #ifdef ORCHESTRA - void ORCH_write(std::ostream& headings, std::ostream& input_data)const; - void ORCH_read(std::vector > output_vector, std::vector < std::pair < std::string, double > >::iterator &it); - void ORCH_store_global(std::map < std::string, double > output_map); + void ORCH_write(std::ostream & headings, std::ostream & input_data) const; + void ORCH_read(std::vector < std::pair < std::string, + double >>output_vector, + std::vector < std::pair < std::string, + double >>::iterator & it); + void ORCH_store_global(std::map < std::string, double >output_map); #endif #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void mpi_send(int task_number); - void mpi_recv(int task_number); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_send(int task_number); + void mpi_recv(int task_number); #endif -private: - void zero(); - void add(const cxxSolution &addee, double extensive); + private: + void zero(); + void add(const cxxSolution & addee, double extensive); // not checked - void dump_xml(std::ostream& os, unsigned int indent = 0)const; + void dump_xml(std::ostream & os, unsigned int indent = 0) const; -protected: - double tc; - double ph; - double pe; - double mu; - double ah2o; - double total_h; - double total_o; - double cb; - double mass_water; - double total_alkalinity; - cxxNameDouble totals; - //std::list isotopes; - cxxNameDouble master_activity; - cxxNameDouble species_gamma; + protected: + double tc; + double ph; + double pe; + double mu; + double ah2o; + double total_h; + double total_o; + double cb; + double mass_water; + double total_alkalinity; + cxxNameDouble totals; + //std::list isotopes; + cxxNameDouble master_activity; + cxxNameDouble species_gamma; cxxSolutionIsotopeList isotopes; }; diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 50c40eaf..6ccce2fb 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -2,64 +2,98 @@ #define SOLUTIONISOTOPE_H_INCLUDED #include "Parser.h" -#include // std::ostream -#include // std::string -#include // std::list +#include // std::ostream +#include // std::string +#include // std::list class cxxSolutionIsotope { -public: - cxxSolutionIsotope(void); - cxxSolutionIsotope(struct isotope *isotope_ptr); - ~cxxSolutionIsotope(void); + public: + cxxSolutionIsotope(void); + cxxSolutionIsotope(struct isotope *isotope_ptr); + ~cxxSolutionIsotope(void); /* - enum STATUS { - ERROR = 0, - OK = 1 - }; - */ - //cxxSolutionIsotope::STATUS read(CParser& parser); - static struct isotope * list2isotope(std::list &t); + enum STATUS { + ERROR = 0, + OK = 1 + }; + */ + //cxxSolutionIsotope::STATUS read(CParser& parser); + static struct isotope *list2isotope(std::list < cxxSolutionIsotope > &t); - void dump_xml(std::ostream& os, unsigned int indent)const; - void dump_raw(std::ostream& os, unsigned int indent)const; + void dump_xml(std::ostream & os, unsigned int indent) const; + void dump_raw(std::ostream & os, unsigned int indent) const; - CParser::STATUS_TYPE read_raw(CParser& parser); + CParser::STATUS_TYPE read_raw(CParser & parser); - double get_isotope_number()const { return this->isotope_number;} - void set_isotope_number(double d) { this->isotope_number = d;} - char * get_elt_name()const { return this->elt_name;} - void set_elt_name(char * cstring) { this->elt_name = cstring;} - char * get_isotope_name()const { return this->isotope_name;} - void set_isotope_name(char * cstring) { this->isotope_name = cstring;} - double get_total()const { return this->total;} - void set_total(double d) { this->total = d;} + double get_isotope_number() const + { + return this->isotope_number; + } + void set_isotope_number(double d) + { + this->isotope_number = d; + } + char *get_elt_name() const + { + return this->elt_name; + } + void set_elt_name(char *cstring) + { + this->elt_name = cstring; + } + char *get_isotope_name() const + { + return this->isotope_name; + } + void set_isotope_name(char *cstring) + { + this->isotope_name = cstring; + } + double get_total() const + { + return this->total; + } + void set_total(double d) + { + this->total = d; + } - double get_ratio()const { return this->ratio; } + double get_ratio() const + { + return this->ratio; + } - double get_ratio_uncertainty()const { return this->ratio_uncertainty; } + double get_ratio_uncertainty() const + { + return this->ratio_uncertainty; + } - bool get_ratio_uncertainty_defined()const { return this->ratio_uncertainty_defined; } + bool get_ratio_uncertainty_defined() const + { + return this->ratio_uncertainty_defined; + } - bool operator<(const cxxSolutionIsotope& conc)const; - - struct master *master(void); - struct master *primary(void); + bool operator<(const cxxSolutionIsotope & conc) const; - void add(const cxxSolutionIsotope &isotope_ptr, double intensive, double extensive); + struct master *master(void); + struct master *primary(void); + + void add(const cxxSolutionIsotope & isotope_ptr, double intensive, + double extensive); void multiply(double extensive); -protected: + protected: friend class cxxSolutionIsotopeList; - double isotope_number; - char * elt_name; - char * isotope_name; - double total; - double ratio; - double ratio_uncertainty; - //struct master *master; - //struct master *primary; - bool ratio_uncertainty_defined; + double isotope_number; + char *elt_name; + char *isotope_name; + double total; + double ratio; + double ratio_uncertainty; + //struct master *master; + //struct master *primary; + bool ratio_uncertainty_defined; }; #endif // SOLUTIONISOTOPE_H_INCLUDED diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 21a40d8a..02e22f3e 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -4,32 +4,38 @@ //#define EXTERNAL extern #include "SolutionIsotope.h" //#include "global.h" -#include // assert -#include // std::string -#include // std::list +#include // assert +#include // std::string +#include // std::list #include "char_star.h" #include "Parser.h" -class cxxSolutionIsotopeList : public std::list +class cxxSolutionIsotopeList:public + std::list < + cxxSolutionIsotope > { -public: - cxxSolutionIsotopeList(); + public: + cxxSolutionIsotopeList(); - cxxSolutionIsotopeList(struct solution *solution_ptr); + cxxSolutionIsotopeList(struct solution *solution_ptr); - ~cxxSolutionIsotopeList(); + ~ + cxxSolutionIsotopeList(); - struct isotope *cxxSolutionIsotopeList2isotope(); + struct isotope * + cxxSolutionIsotopeList2isotope(); - void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); - void multiply(double extensive); - -protected: + void + add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); + void + multiply(double extensive); + + protected: -public: + public: }; diff --git a/StorageBin.h b/StorageBin.h index f806e08b..5803a832 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -15,21 +15,21 @@ #include "Reaction.h" #include "Temperature.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector -class cxxStorageBin +class cxxStorageBin { -public: - cxxStorageBin(); - cxxStorageBin(struct Use *use_ptr); - ~cxxStorageBin(); + public: + cxxStorageBin(); + cxxStorageBin(struct Use *use_ptr); + ~cxxStorageBin(); - void import_phreeqc(void); + void import_phreeqc(void); void cxxStorageBin2phreeqc(int n); @@ -37,200 +37,270 @@ public: void remove(int n); - cxxSolution *getSolution(int n_user) { - if (this->Solutions.find(n_user) != this->Solutions.end()) { - return(&(this->Solutions.find(n_user)->second)); - } + cxxSolution *getSolution(int n_user) + { + if (this->Solutions.find(n_user) != this->Solutions.end()) + { + return (&(this->Solutions.find(n_user)->second)); + } return (NULL); } - void setSolution(int n_user, cxxSolution *entity) { - if (entity == NULL) return; + void setSolution(int n_user, cxxSolution * entity) + { + if (entity == NULL) + return; Solutions[n_user] = *entity; } - void removeSolution(int n_user) { + void removeSolution(int n_user) + { Solutions.erase(n_user); } - cxxExchange *getExchange(int n_user) { - if (this->Exchangers.find(n_user) != this->Exchangers.end()) { - return(&(this->Exchangers.find(n_user)->second)); - } + cxxExchange *getExchange(int n_user) + { + if (this->Exchangers.find(n_user) != this->Exchangers.end()) + { + return (&(this->Exchangers.find(n_user)->second)); + } return (NULL); } - void setExchange(int n_user, cxxExchange *entity) { - if (entity == NULL) return; - Exchangers[n_user] = *entity; + void setExchange(int n_user, cxxExchange * entity) + { + if (entity == NULL) + return; + Exchangers[n_user] = *entity; } - void removeExchange(int n_user) { + void removeExchange(int n_user) + { Exchangers.erase(n_user); } - cxxPPassemblage *getPPassemblage(int n_user) { - if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) { - return(&(this->PPassemblages.find(n_user)->second)); - } + cxxPPassemblage *getPPassemblage(int n_user) + { + if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) + { + return (&(this->PPassemblages.find(n_user)->second)); + } return (NULL); } - void setPPassemblage(int n_user, cxxPPassemblage *entity) { - if (entity == NULL) return; + void setPPassemblage(int n_user, cxxPPassemblage * entity) + { + if (entity == NULL) + return; PPassemblages[n_user] = *entity; } - void removePPassemblage(int n_user) { + void removePPassemblage(int n_user) + { PPassemblages.erase(n_user); } - cxxGasPhase *getGasPhase(int n_user) { - if (this->GasPhases.find(n_user) != this->GasPhases.end()) { - return(&(this->GasPhases.find(n_user)->second)); - } + cxxGasPhase *getGasPhase(int n_user) + { + if (this->GasPhases.find(n_user) != this->GasPhases.end()) + { + return (&(this->GasPhases.find(n_user)->second)); + } return (NULL); } - void setGasPhase(int n_user, cxxGasPhase *entity) { - if (entity == NULL) return; - GasPhases[n_user] = *entity; + void setGasPhase(int n_user, cxxGasPhase * entity) + { + if (entity == NULL) + return; + GasPhases[n_user] = *entity; } - void removeGasPhase(int n_user) { + void removeGasPhase(int n_user) + { GasPhases.erase(n_user); } - cxxSSassemblage *getSSassemblage(int n_user) { - if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) { - return(&(this->SSassemblages.find(n_user)->second)); - } + cxxSSassemblage *getSSassemblage(int n_user) + { + if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) + { + return (&(this->SSassemblages.find(n_user)->second)); + } return (NULL); } - void setSSassemblage(int n_user, cxxSSassemblage *entity) { - if (entity == NULL) return; - SSassemblages[n_user] = *entity; + void setSSassemblage(int n_user, cxxSSassemblage * entity) + { + if (entity == NULL) + return; + SSassemblages[n_user] = *entity; } - void removeSSassemblage(int n_user) { + void removeSSassemblage(int n_user) + { SSassemblages.erase(n_user); } - cxxKinetics *getKinetics(int n_user) { - if (this->Kinetics.find(n_user) != this->Kinetics.end()) { - return(&(this->Kinetics.find(n_user)->second)); - } + cxxKinetics *getKinetics(int n_user) + { + if (this->Kinetics.find(n_user) != this->Kinetics.end()) + { + return (&(this->Kinetics.find(n_user)->second)); + } return (NULL); } - void setKinetics(int n_user, cxxKinetics *entity) { - if (entity == NULL) return; - Kinetics[n_user] = *entity; + void setKinetics(int n_user, cxxKinetics * entity) + { + if (entity == NULL) + return; + Kinetics[n_user] = *entity; } - void removeKinetics(int n_user) { + void removeKinetics(int n_user) + { Kinetics.erase(n_user); } - cxxSurface *getSurface(int n_user) - { - if (this->Surfaces.find(n_user) != this->Surfaces.end()) - { - return(&(this->Surfaces.find(n_user)->second)); - } - return (NULL); + cxxSurface *getSurface(int n_user) + { + if (this->Surfaces.find(n_user) != this->Surfaces.end()) + { + return (&(this->Surfaces.find(n_user)->second)); + } + return (NULL); } - void setSurface(int n_user, cxxSurface *entity) { - if (entity == NULL) return; - Surfaces[n_user] = *entity; + void setSurface(int n_user, cxxSurface * entity) + { + if (entity == NULL) + return; + Surfaces[n_user] = *entity; } - void removeSurface(int n_user) { + void removeSurface(int n_user) + { Surfaces.erase(n_user); } - cxxMix *getMix(int n_user) { - if (this->Mixes.find(n_user) != this->Mixes.end()) { - return(&(this->Mixes.find(n_user)->second)); - } + cxxMix *getMix(int n_user) + { + if (this->Mixes.find(n_user) != this->Mixes.end()) + { + return (&(this->Mixes.find(n_user)->second)); + } return (NULL); } - void setMix(int n_user, cxxMix *entity) { - if (entity == NULL) return; - Mixes[n_user] = *entity; + void setMix(int n_user, cxxMix * entity) + { + if (entity == NULL) + return; + Mixes[n_user] = *entity; } - void removeMix(int n_user) { + void removeMix(int n_user) + { Mixes.erase(n_user); } - cxxReaction *getReaction(int n_user) { - if (this->Reactions.find(n_user) != this->Reactions.end()) { - return(&(this->Reactions.find(n_user)->second)); - } + cxxReaction *getReaction(int n_user) + { + if (this->Reactions.find(n_user) != this->Reactions.end()) + { + return (&(this->Reactions.find(n_user)->second)); + } return (NULL); } - void setReaction(int n_user, cxxReaction *entity) { - if (entity == NULL) return; - Reactions[n_user] = *entity; + void setReaction(int n_user, cxxReaction * entity) + { + if (entity == NULL) + return; + Reactions[n_user] = *entity; } - void removeReaction(int n_user) { + void removeReaction(int n_user) + { Reactions.erase(n_user); } - cxxTemperature *getTemperature(int n_user) { - if (this->Temperatures.find(n_user) != this->Temperatures.end()) { - return(&(this->Temperatures.find(n_user)->second)); - } + cxxTemperature *getTemperature(int n_user) + { + if (this->Temperatures.find(n_user) != this->Temperatures.end()) + { + return (&(this->Temperatures.find(n_user)->second)); + } return (NULL); } - void setTemperature(int n_user, cxxTemperature *entity) { - if (entity == NULL) return; - Temperatures[n_user] = *entity; + void setTemperature(int n_user, cxxTemperature * entity) + { + if (entity == NULL) + return; + Temperatures[n_user] = *entity; } - void removeTemperature(int n_user) { + void removeTemperature(int n_user) + { Temperatures.erase(n_user); } - void setSystem(struct Use *use_ptr); + void setSystem(struct Use *use_ptr); - void dump_raw(std::ostream& s_oss, unsigned int indent)const; + void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void dump_raw(std::ostream& s_oss, int i, unsigned int indent); + void dump_raw(std::ostream & s_oss, int i, unsigned int indent); - void read_raw(CParser& parser); - int read_raw_keyword(CParser& parser); + void read_raw(CParser & parser); + int read_raw_keyword(CParser & parser); void add(struct system *sys_ptr); struct system *cxxStorageBin2system(int i); //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); - cxxExchange *mix_cxxExchange(cxxMix &mixmap); + cxxExchange *mix_cxxExchange(cxxMix & mixmap); - const std::map& getSolutions()const {return this->Solutions;}; - const std::map& getExchangers()const {return this->Exchangers;}; - const std::map& getGasPhases()const {return this->GasPhases;}; - const std::map& getKinetics()const {return this->Kinetics;}; - const std::map& getPPassemblages()const {return this->PPassemblages;}; - const std::map& getSSassemblages()const {return this->SSassemblages;}; - const std::map& getSurfaces()const {return this->Surfaces;}; + const std::map < int, cxxSolution > &getSolutions() const + { + return this->Solutions; + }; + const std::map < int, cxxExchange > &getExchangers() const + { + return this->Exchangers; + }; + const std::map < int, cxxGasPhase > &getGasPhases() const + { + return this->GasPhases; + }; + const std::map < int, cxxKinetics > &getKinetics() const + { + return this->Kinetics; + }; + const std::map < int, cxxPPassemblage > &getPPassemblages() const + { + return this->PPassemblages; + }; + const std::map < int, cxxSSassemblage > &getSSassemblages() const + { + return this->SSassemblages; + }; + const std::map < int, cxxSurface > &getSurfaces() const + { + return this->Surfaces; + }; #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); #endif #ifdef ORCHESTRA - void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); + void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat); #endif -protected: + protected: // Tidied classes - std::map Solutions; - std::map Exchangers; - std::map GasPhases; - std::map Kinetics; - std::map PPassemblages; - std::map SSassemblages; - std::map Surfaces; + std::map < int, cxxSolution > Solutions; + std::map < int, cxxExchange > Exchangers; + std::map < int, cxxGasPhase > GasPhases; + std::map < int, cxxKinetics > Kinetics; + std::map < int, cxxPPassemblage > PPassemblages; + std::map < int, cxxSSassemblage > SSassemblages; + std::map < int, cxxSurface > Surfaces; //bool b = exists (Solutions, 5); // Initial classes //std::map ISolutions; // Reaction classes - std::map Mixes; - std::map Reactions; - std::map Temperatures; - cxxSystem system; -public: - //static std::map& map; + std::map < int, cxxMix > Mixes; + std::map < int, cxxReaction > Reactions; + std::map < int, cxxTemperature > Temperatures; + cxxSystem system; + public: + //static std::map& map; }; diff --git a/Surface.h b/Surface.h index f14d2d91..b9d94fba 100644 --- a/Surface.h +++ b/Surface.h @@ -4,74 +4,75 @@ #include "NumKeyword.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" #include "SurfaceComp.h" #include "SurfaceCharge.h" #include "cxxMix.h" -class cxxSurface : public cxxNumKeyword +class cxxSurface:public cxxNumKeyword { -public: - cxxSurface(); - cxxSurface(struct surface *); - cxxSurface(const std::map &entity_map, cxxMix &mx, int n_user); - ~cxxSurface(); + public: + cxxSurface(); + cxxSurface(struct surface *); + cxxSurface(const std::map < int, cxxSurface > &entity_map, cxxMix & mx, + int n_user); + ~cxxSurface(); - //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; - //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; - //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; + //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; + //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; + //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; - struct surface *cxxSurface2surface(); + struct surface *cxxSurface2surface(); - struct surf_comp *cxxSurfaceComp2surf_comp(); + struct surf_comp *cxxSurfaceComp2surf_comp(); - 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 get_related_phases(void); + bool get_related_phases(void); + + bool get_related_rate(void); - bool get_related_rate(void); - void totalize(); - const cxxNameDouble& get_totals()const + const cxxNameDouble & get_totals() const { - return this->totals; + return this->totals; }; #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -private: - void add(const cxxSurface &addee, double extensive); + private: + void add(const cxxSurface & addee, double extensive); -protected: - std::list surfaceComps; - std::list surfaceCharges; + protected: + std::list < cxxSurfaceComp > surfaceComps; + std::list < cxxSurfaceCharge > surfaceCharges; enum SURFACE_TYPE type; enum DIFFUSE_LAYER_TYPE dl_type; enum SITES_UNITS sites_units; - bool only_counter_ions; - double thickness; - double debye_lengths; + bool only_counter_ions; + double thickness; + double debye_lengths; double DDL_viscosity; double DDL_limit; - bool transport; + bool transport; cxxNameDouble totals; -public: - //static std::map& map; + public: + //static std::map& map; }; #endif // !defined(SURFACE_H_INCLUDED) diff --git a/SurfaceCharge.h b/SurfaceCharge.h index a5d68890..c2e434ec 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -4,57 +4,62 @@ #include "NameDouble.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxSurfaceCharge +class cxxSurfaceCharge { -public: + public: - cxxSurfaceCharge(); - cxxSurfaceCharge(struct surface_charge *); - ~cxxSurfaceCharge(); + cxxSurfaceCharge(); + cxxSurfaceCharge(struct surface_charge *); + ~cxxSurfaceCharge(); - struct master *get_psi_master(); + struct master *get_psi_master(); - static struct surface_charge *cxxSurfaceCharge2surface_charge(std::list& el); + static struct surface_charge *cxxSurfaceCharge2surface_charge(std::list < + cxxSurfaceCharge + > &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); - char *get_name()const {return this->name;} + char *get_name() const + { + return this->name; + } - void add(const cxxSurfaceCharge &comp, double extensive); + void add(const cxxSurfaceCharge & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -protected: - char * name; - double specific_area; - double grams; - double charge_balance; - double mass_water; - double la_psi, la_psi1, la_psi2; + protected: + char *name; + double specific_area; + double grams; + double charge_balance; + double mass_water; + double la_psi, la_psi1, la_psi2; double capacitance[2]; - //std::map g; - //char * psi_master_name; - cxxNameDouble diffuse_layer_totals; + //std::map g; + //char * psi_master_name; + cxxNameDouble diffuse_layer_totals; -public: + public: }; diff --git a/SurfaceComp.h b/SurfaceComp.h index 67a4cce0..4c462536 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -5,81 +5,102 @@ #define EXTERNAL extern #include "global.h" #include "phrqproto.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" class cxxSurfaceComp { -public: + public: - cxxSurfaceComp(); - cxxSurfaceComp(struct surface_comp *); - ~cxxSurfaceComp(); + cxxSurfaceComp(); + cxxSurfaceComp(struct surface_comp *); + ~cxxSurfaceComp(); - struct master *get_master(); - char *get_phase_name()const {return this->phase_name;} - char *get_rate_name()const {return this->rate_name;} - char *get_formula()const {return this->formula;} - double get_charge_balance()const { return this->charge_balance;} - void set_charge_balance(double d) { this->charge_balance = d;} - - static struct surface_comp *cxxSurfaceComp2surface_comp(std::list& el); - - void dump_xml(std::ostream& os, unsigned int indent = 0)const; - - void dump_raw(std::ostream& s_oss, unsigned int indent)const; - - void read_raw(CParser& parser); - const cxxNameDouble &get_totals()const + struct master *get_master(); + char *get_phase_name() const { - return (this->totals); + return this->phase_name; + } + char *get_rate_name() const + { + return this->rate_name; + } + char *get_formula() const + { + return this->formula; + } + double get_charge_balance() const + { + return this->charge_balance; + } + void set_charge_balance(double d) + { + this->charge_balance = d; + } + + static struct surface_comp *cxxSurfaceComp2surface_comp(std::list < + cxxSurfaceComp > + &el); + + void dump_xml(std::ostream & os, unsigned int indent = 0) const; + + void dump_raw(std::ostream & s_oss, unsigned int indent) const; + + void read_raw(CParser & parser); + const cxxNameDouble & get_totals() const + { + return (this->totals); }; - void add(const cxxSurfaceComp &comp, double extensive); + void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - char *charge_name() {return(get_charge_name(this->formula));}; + char *charge_name() + { + return (get_charge_name(this->formula)); + }; - static char *get_charge_name(char * token) { - char name[100]; - int l; - char *ptr1 = token; - get_elt (&ptr1, name, &l); - ptr1 = strchr (name, '_'); - if (ptr1 != NULL) - { - ptr1[0] = '\0'; - } - return(string_hsave(name)); + static char *get_charge_name(char *token) + { + char name[100]; + int l; + char *ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + { + ptr1[0] = '\0'; + } + return (string_hsave(name)); }; #ifdef USE_MPI - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -protected: - char * formula; - cxxNameDouble formula_totals; + protected: + char *formula; + cxxNameDouble formula_totals; double formula_z; - double moles; - cxxNameDouble totals; - double la; - //int charge_number; - double charge_balance; - char *phase_name; - double phase_proportion; - char *rate_name; + double moles; + cxxNameDouble totals; + double la; + //int charge_number; + double charge_balance; + char *phase_name; + double phase_proportion; + char *rate_name; double Dw; -public: + public: }; diff --git a/System.h b/System.h index f3439283..4fb27500 100644 --- a/System.h +++ b/System.h @@ -1,75 +1,76 @@ -#if !defined(SYSTEM_H_INCLUDED) -#define SYSTEM_H_INCLUDED -#include "Solution.h" -#include "Exchange.h" -#include "GasPhase.h" -#include "cxxKinetics.h" -#include "PPassemblage.h" -#include "SSassemblage.h" -#include "Surface.h" -#include "cxxMix.h" -#include "Reaction.h" -#include "Temperature.h" -class cxxSystem -{ -public: - cxxSystem(void); -public: - ~cxxSystem(void); - void Initialize(void); - void setSolution(cxxSolution *entity) { - this->solution = entity; - } - void setExchange(cxxExchange *entity) { - this->exchange = entity; - } - void setPPassemblage(cxxPPassemblage *entity) { - this->ppassemblage = entity; - } - void setGasPhase(cxxGasPhase *entity) { - this->gasphase = entity; - } - void setSSassemblage(cxxSSassemblage *entity) { - this->ssassemblage = entity; - } - void setKinetics(cxxKinetics *entity) { - this->kinetics = entity; - } - void setSurface(cxxSurface *entity) { - this->surface = entity; - } - void setMix(cxxMix *entity) { - this->mix = entity; - } - void setReaction(cxxReaction *entity) { - this->reaction = entity; - } - void setTemperature(cxxTemperature *entity) { - this->temperature = entity; - } - void totalize(); -#ifdef ORCHESTRA - void ORCH_components(); - void ORCH_write(std::ostream &chemistry_dat, std::ostream &input_dat, std::ostream &output_dat); - void ORCH_write_chemistry_water(std::ostream &chemistry_dat); - void ORCH_write_chemistry_primary(std::ostream &chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostream &chemistry_dat); - void ORCH_write_output_vars(std::ostream &outstream); - void ORCH_write_input(std::ostream &input_dat); -#endif - -private: - cxxSolution *solution; - cxxExchange *exchange; - cxxPPassemblage *ppassemblage; - cxxGasPhase *gasphase; - cxxSSassemblage *ssassemblage; - cxxKinetics *kinetics; - cxxSurface *surface; - cxxMix *mix; - cxxReaction *reaction; - cxxTemperature *temperature; - cxxNameDouble totals; - cxxNameDouble orch_totals; -}; -#endif // !defined(SYSTEM_H_INCLUDED) +#if !defined(SYSTEM_H_INCLUDED) +#define SYSTEM_H_INCLUDED +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" +#include "cxxMix.h" +#include "Reaction.h" +#include "Temperature.h" +class cxxSystem +{ + public:cxxSystem(void); + public: ~cxxSystem(void); + void Initialize(void); + void setSolution(cxxSolution * entity) + { + this->solution = entity; + } void setExchange(cxxExchange * entity) + { + this->exchange = entity; + } void setPPassemblage(cxxPPassemblage * entity) + { + this->ppassemblage = entity; + } void setGasPhase(cxxGasPhase * entity) + { + this->gasphase = entity; + } void setSSassemblage(cxxSSassemblage * entity) + { + this->ssassemblage = entity; + } void setKinetics(cxxKinetics * entity) + { + this->kinetics = entity; + } void setSurface(cxxSurface * entity) + { + this->surface = entity; + } void setMix(cxxMix * entity) + { + this->mix = entity; + } void setReaction(cxxReaction * entity) + { + this->reaction = entity; + } void setTemperature(cxxTemperature * entity) + { + this->temperature = entity; + } void totalize(); + +#ifdef ORCHESTRA + void ORCH_components(); + void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat); + void ORCH_write_chemistry_water(std::ostream & chemistry_dat); + void ORCH_write_chemistry_primary(std::ostream & chemistry_dat); + void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); + void ORCH_write_output_vars(std::ostream & outstream); + void ORCH_write_input(std::ostream & input_dat); + +#endif /* */ + private:cxxSolution * solution; + cxxExchange * exchange; + cxxPPassemblage * ppassemblage; + cxxGasPhase * gasphase; + cxxSSassemblage * ssassemblage; + cxxKinetics * kinetics; + cxxSurface * surface; + cxxMix * mix; + cxxReaction * reaction; + cxxTemperature * temperature; + cxxNameDouble totals; + cxxNameDouble orch_totals; +}; + + +#endif // !defined(SYSTEM_H_INCLUDED) diff --git a/Temperature.h b/Temperature.h index d0ea2f90..3997903a 100644 --- a/Temperature.h +++ b/Temperature.h @@ -4,37 +4,37 @@ #include "NumKeyword.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxTemperature : public cxxNumKeyword +class cxxTemperature:public cxxNumKeyword { -public: - cxxTemperature(); - cxxTemperature(struct temperature *); - ~cxxTemperature(); + public: + cxxTemperature(); + cxxTemperature(struct temperature *); + ~cxxTemperature(); - struct temperature *cxxTemperature2temperature(); + struct temperature *cxxTemperature2temperature(); - //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); -protected: - std::vector temps; + protected: + std::vector < double >temps; int countTemps; bool equalIncrements; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/Utils.h b/Utils.h index 23f25776..2bed81de 100644 --- a/Utils.h +++ b/Utils.h @@ -2,65 +2,72 @@ #define UTILITIES_H_INCLUDED #include -#include // std::istringstream std::ostringstream -#include // std::ostream -#include // std::istream -#include // std::map +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include // std::map #include "char_star.h" -namespace Utilities { +namespace Utilities +{ - const char INDENT[] = " "; + const char INDENT[] = " "; - enum STATUS_TYPE { - OK = 0, - ERROR = 1 - }; + enum STATUS_TYPE + { + OK = 0, + ERROR = 1 + }; - STATUS_TYPE parse_couple(std::string& token); + STATUS_TYPE parse_couple(std::string & token); - int strcmp_nocase(const char *str1, const char *str2); + int strcmp_nocase(const char *str1, const char *str2); - int strcmp_nocase_arg1(const char *str1, const char *str2); + int strcmp_nocase_arg1(const char *str1, const char *str2); - void str_tolower(std::string& str); + void str_tolower(std::string & str); - bool replace(const char* str1, const char* str2, std::string& str); + bool replace(const char *str1, const char *str2, std::string & str); - void squeeze_white(std::string& s_l); + void squeeze_white(std::string & s_l); - //void error_msg(const std::string&, const int stopflag); + //void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) - template - void dump_raw (const T &b, std::ostream& s_oss, unsigned int indent) + template < typename T > + void dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) + { + //std :: map < int, T > :: const_iterator it; + typename T::const_iterator it; + for (it = b.begin(); it != b.end(); ++it) { - //std :: map < int, T > :: const_iterator it; - typename T::const_iterator it; - for (it = b.begin(); it != b.end(); ++it) { - it->second.dump_raw(s_oss, indent); - } - return; + it->second.dump_raw(s_oss, indent); } - template - bool exists (const T &b, int i){ - return (b.find(i) != b.end());} + return; + } + template < typename T > bool exists(const T & b, int i) + { + return (b.find(i) != b.end()); + } - template - T *get_entity(std::map b, int i) { - if (b.find(i) != b.end()) { - return(&(b.find(i)->second)); - } else { + template < typename T > T * get_entity(std::map < int, T > b, int i) + { + if (b.find(i) != b.end()) + { + return (&(b.find(i)->second)); + } + else + { return (NULL); } } - + /* - template - bool exists (std::map b, int i){ - return (b.find(i) != b.end());} - */ + template + bool exists (std::map b, int i){ + return (b.find(i) != b.end());} + */ } diff --git a/char_star.h b/char_star.h index 9d5b65f5..24fdbdf7 100644 --- a/char_star.h +++ b/char_star.h @@ -1,11 +1,16 @@ #if !defined(CHARSTAR_H_INCLUDED) #define CHARSTAR_H_INCLUDED -struct CHARSTAR_LESS : std::binary_function { -bool operator()(const char* _X, const char* _Y) const +struct CHARSTAR_LESS: +std::binary_function < const char *, const char *, + bool > { - return ::strcmp( _X, _Y) < 0;} + bool + operator() (const char *_X, const char *_Y) const + { + return::strcmp(_X, _Y) < + 0; + } }; #endif - diff --git a/cxxKinetics.h b/cxxKinetics.h index 595695ea..aa5f3edc 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -4,58 +4,59 @@ #include "NumKeyword.h" #define EXTERNAL extern #include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" #include "KineticsComp.h" #include "cxxMix.h" -class cxxKinetics : public cxxNumKeyword +class cxxKinetics:public cxxNumKeyword { -public: - cxxKinetics(); - cxxKinetics(struct kinetics *); - cxxKinetics(const std::map &entity_map, cxxMix &mx, int n_user); - ~cxxKinetics(); + public: + cxxKinetics(); + cxxKinetics(struct kinetics *); + cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, + int n_user); + ~cxxKinetics(); - struct kinetics *cxxKinetics2kinetics(); + struct kinetics *cxxKinetics2kinetics(); - struct kinetics_comp *cxxKineticsComp2kinetics_comp(); + struct kinetics_comp *cxxKineticsComp2kinetics_comp(); - //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 get_related_phases(void); + bool get_related_phases(void); - bool get_related_rate(void); + bool get_related_rate(void); #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void mpi_pack(std::vector& ints, std::vector& doubles); + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); #endif -private: - void add(const cxxKinetics &addee, double extensive); + private: + void add(const cxxKinetics & addee, double extensive); -protected: - std::list kineticsComps; - std::vector steps; - cxxNameDouble totals; - double step_divide; - int rk; - int bad_step_max; - bool use_cvode; + protected: + std::list < cxxKineticsComp > kineticsComps; + std::vector < double >steps; + cxxNameDouble totals; + double step_divide; + int rk; + int bad_step_max; + bool use_cvode; int cvode_steps; int cvode_order; -public: - //static std::map& map; + public: + //static std::map& map; }; diff --git a/cxxMix.h b/cxxMix.h index 0131d937..05fb92e6 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -4,48 +4,53 @@ #include "NumKeyword.h" //#define EXTERNAL extern //#include "global.h" -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector #include "char_star.h" -class cxxMix : public cxxNumKeyword +class cxxMix:public cxxNumKeyword { -public: - cxxMix(); - cxxMix(struct mix *); - ~cxxMix(); + public: + cxxMix(); + cxxMix(struct mix *); + ~cxxMix(); - struct mix *cxxMix2mix(); + struct mix *cxxMix2mix(); - //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); - void add(int n, double f) { - if (this->mixComps.find(n) != this->mixComps.end()) - { - mixComps[n] += f; - } else - { - mixComps[n] = f; - } + void add(int n, double f) + { + if (this->mixComps.find(n) != this->mixComps.end()) + { + mixComps[n] += f; + } + else + { + mixComps[n] = f; + } }; - std::map *comps() {return &mixComps;} + std::map < int, double >*comps() + { + return &mixComps; + } -protected: + protected: friend class cxxStorageBin; - std::map mixComps; + std::map < int, double >mixComps; -public: - //static std::map& map; + public: + //static std::map& map; }; From cefe071f17276407ee94f591a6086c2664744984 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 31 Oct 2008 19:09:45 +0000 Subject: [PATCH 0085/1077] Reindented, fixed errors, ran test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3176 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 4 ++-- Exchange.cxx | 4 ++-- GasPhase.cxx | 2 +- KineticsComp.cxx | 2 +- NameDouble.cxx | 10 +++++----- NumKeyword.cxx | 2 +- PPassemblage.cxx | 4 ++-- PPassemblageComp.cxx | 4 ++-- Reaction.cxx | 2 +- SSassemblage.cxx | 2 +- SSassemblageSS.cxx | 2 +- Solution.cxx | 10 +++++----- SolutionIsotope.cxx | 6 +++--- StorageBin.cxx | 2 +- Surface.cxx | 4 ++-- SurfaceCharge.cxx | 4 ++-- SurfaceComp.cxx | 4 ++-- Temperature.cxx | 2 +- cxxKinetics.cxx | 2 +- cxxMix.cxx | 2 +- 20 files changed, 37 insertions(+), 37 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 9abde51e..5e40a254 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -220,7 +220,7 @@ cxxExchComp::cxxExchComp2exch_comp(std::list < cxxExchComp > &el) } void -cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; @@ -267,7 +267,7 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; diff --git a/Exchange.cxx b/Exchange.cxx index d47ba542..0ada85d1 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -220,7 +220,7 @@ cxxExchange::cxxExchange2exchange() } void -cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; unsigned int i; @@ -254,7 +254,7 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; unsigned int i; diff --git a/GasPhase.cxx b/GasPhase.cxx index 4e79d49f..2036bc67 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -219,7 +219,7 @@ cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; unsigned int i; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 45da3f67..2d5a3eab 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -150,7 +150,7 @@ cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const } #endif void -cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; unsigned int i; diff --git a/NameDouble.cxx b/NameDouble.cxx index 6f337e14..2585194b 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -154,7 +154,7 @@ cxxNameDouble::elt_list() } struct master_activity * -cxxNameDouble::master_activity() const const +cxxNameDouble::master_activity() const // // Builds a list of master_activity structures from instance of cxxNameDouble // @@ -213,7 +213,7 @@ cxxNameDouble::master_activity() const const } struct conc * -cxxNameDouble::conc() const const +cxxNameDouble::conc() const // for Solutions, not ISolutions // takes a map of (elt name, moles) // returns list of conc structures @@ -245,7 +245,7 @@ cxxNameDouble::conc() const const } struct name_coef * -cxxNameDouble::name_coef() const const +cxxNameDouble::name_coef() const // // Builds a name_coef structure from instance of cxxNameDouble // @@ -267,7 +267,7 @@ cxxNameDouble::name_coef() const const } void -cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; @@ -312,7 +312,7 @@ cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 3c0dd39a..34926f66 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -22,7 +22,7 @@ cxxNumKeyword::~cxxNumKeyword() } void -cxxNumKeyword::dump_xml(std::ostream & os, unsigned int indent) const const +cxxNumKeyword::dump_xml(std::ostream & os, unsigned int indent) const { unsigned int i; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 7c200cce..776b36ab 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -97,7 +97,7 @@ cxxPPassemblage::cxxPPassemblage2pp_assemblage() } void -cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; unsigned int i; @@ -128,7 +128,7 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; unsigned int i; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 6b84ecac..e649370b 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -93,7 +93,7 @@ cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list < } void -cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; unsigned int i; @@ -124,7 +124,7 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const c } void -cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; unsigned int i; diff --git a/Reaction.cxx b/Reaction.cxx index 044a0245..91748dd6 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -158,7 +158,7 @@ cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; unsigned int i; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 2115b7f8..a5dd5251 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -122,7 +122,7 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const } #endif void -cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; unsigned int i; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index c11d4888..918c80c3 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -184,7 +184,7 @@ cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const con } #endif void -cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; diff --git a/Solution.cxx b/Solution.cxx index 16ede052..47564806 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -324,7 +324,7 @@ cxxSolution::cxxSolution2solution() } void -cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; unsigned int i; @@ -436,7 +436,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; unsigned int i; @@ -936,7 +936,7 @@ cxxSolution::multiply(double extensive) } double -cxxSolution::get_total(char *string) const const +cxxSolution::get_total(char *string) const { cxxNameDouble::const_iterator it = this->totals.find(string); if (it == this->totals.end()) @@ -949,7 +949,7 @@ cxxSolution::get_total(char *string) const const } } double -cxxSolution::get_total_element(char *string) const const +cxxSolution::get_total_element(char *string) const { cxxNameDouble::const_iterator it; double d = 0.0; @@ -991,7 +991,7 @@ cxxSolution::set_total(char *string, double d) } double -cxxSolution::get_master_activity(char *string) const const +cxxSolution::get_master_activity(char *string) const { cxxNameDouble::const_iterator it = this->master_activity.find(string); if (it == this->master_activity.end()) diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index ed7e6384..c8a62387 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -76,7 +76,7 @@ std::string cxxSolutionIsotope::get_name() constconst #endif void -cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const { unsigned int i; @@ -116,7 +116,7 @@ cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const co } void -cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const { unsigned int i; @@ -200,7 +200,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) } bool -cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const const +cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const { int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); if (i != 0) diff --git a/StorageBin.cxx b/StorageBin.cxx index cd4c5aa1..91580250 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -210,7 +210,7 @@ cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const { // Dump all data diff --git a/Surface.cxx b/Surface.cxx index 085aef13..b4eb8150 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -213,7 +213,7 @@ cxxSurface::cxxSurface2surface() } void -cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; unsigned int i; @@ -286,7 +286,7 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; unsigned int i; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 886c427c..de98f183 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -122,7 +122,7 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list < } void -cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; unsigned int i; @@ -159,7 +159,7 @@ cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const cons } void -cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; unsigned int i; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 52007db0..829e4c3f 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -136,7 +136,7 @@ cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list < cxxSurfaceComp > &el) } void -cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; unsigned int i; @@ -186,7 +186,7 @@ cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const } void -cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; unsigned int i; diff --git a/Temperature.cxx b/Temperature.cxx index 6c2c759c..2ceeb196 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -141,7 +141,7 @@ cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 8c815156..49392e43 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -186,7 +186,7 @@ cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; unsigned int i; diff --git a/cxxMix.cxx b/cxxMix.cxx index 641e5427..8f7145be 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -129,7 +129,7 @@ cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const const +cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; unsigned int i; From e398c418f069f36a334a6bc8cba081642e91d40e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 24 Nov 2008 17:44:38 +0000 Subject: [PATCH 0086/1077] Updated PHREEQCPP to have precipitate_only option for pp_assemblage. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3200 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblageComp.cxx | 38 ++++++++++++++++++++++++++++++++++++++ PPassemblageComp.h | 1 + 2 files changed, 39 insertions(+) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index e649370b..0f09f363 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -33,6 +33,7 @@ cxxPPassemblageComp::cxxPPassemblageComp() initial_moles = 0; force_equality = false; dissolve_only = false; + precipitate_only = false; } cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr) @@ -87,6 +88,7 @@ cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list < pure_phase_ptr[i].initial_moles = it->initial_moles; pure_phase_ptr[i].force_equality = (int) it->force_equality; pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; + pure_phase_ptr[i].precipitate_only = (int) it->precipitate_only; i++; } return (pure_phase_ptr); @@ -120,6 +122,8 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const force_equality << "\"" << std::endl; s_oss << indent0 << "dissolve_only=\"" << this-> dissolve_only << "\"" << std::endl; + s_oss << indent0 << "precipitate_only=\"" << this-> + precipitate_only << "\"" << std::endl; } @@ -154,6 +158,8 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const force_equality << std::endl; s_oss << indent0 << "-dissolve_only " << this-> dissolve_only << std::endl; + s_oss << indent0 << "-precipitate_only " << this-> + precipitate_only << std::endl; } void @@ -173,6 +179,7 @@ cxxPPassemblageComp::read_raw(CParser & parser) vopts.push_back("initial_moles"); // 5 vopts.push_back("dissolve_only"); // 6 vopts.push_back("force_equality"); // 7 + vopts.push_back("precipitate_only"); // 8 } std::istream::pos_type ptr; @@ -188,6 +195,7 @@ cxxPPassemblageComp::read_raw(CParser & parser) bool initial_moles_defined(false); bool dissolve_only_defined(false); bool force_equality_defined(false); + bool precipitate_only_defined(false); for (;;) { @@ -294,6 +302,10 @@ cxxPPassemblageComp::read_raw(CParser & parser) CParser::OT_CONTINUE); } dissolve_only_defined = true; + if (this->dissolve_only) + { + this->precipitate_only = false; + } break; case 7: // force_equality @@ -306,6 +318,21 @@ cxxPPassemblageComp::read_raw(CParser & parser) } force_equality_defined = true; break; + + case 8: // precipitate_only + if (!(parser.get_iss() >> this->precipitate_only)) + { + this->precipitate_only = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for precipitate_only.", + CParser::OT_CONTINUE); + } + precipitate_only_defined = true; + if (this->precipitate_only) + { + this->dissolve_only = false; + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -349,6 +376,15 @@ cxxPPassemblageComp::read_raw(CParser & parser) error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } + /* don't check to maintain backward compatibility + if (precipitate_only_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Precipitate_only not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + */ if (force_equality_defined == false) { parser.incr_input_error(); @@ -374,6 +410,7 @@ cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, doubles.push_back(this->initial_moles); ints.push_back((int) this->force_equality); ints.push_back((int) this->dissolve_only); + ints.push_back((int) this->precipitate_only); } void @@ -390,6 +427,7 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->initial_moles = doubles[d++]; this->force_equality = (ints[i++] != 0); this->dissolve_only = (ints[i++] != 0); + this->precipitate_only = (ints[i++] != 0); *ii = i; *dd = d; } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index b64096ee..4694e97c 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -60,6 +60,7 @@ class cxxPPassemblageComp double initial_moles; bool force_equality; bool dissolve_only; + bool precipitate_only; cxxNameDouble totals; public: From ff282a405f9307fe8f95d48e57ac8a5b6017a754 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 Dec 2008 22:39:51 +0000 Subject: [PATCH 0087/1077] Missed one line for struct to class conversion of ppassemblage for precipitate_only. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3227 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblageComp.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0f09f363..8c7526e0 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -49,6 +49,7 @@ cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr) initial_moles = pure_phase_ptr->initial_moles; force_equality = (pure_phase_ptr->force_equality == TRUE); dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); + precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); } cxxPPassemblageComp::~cxxPPassemblageComp() From 45d120f629190320a2e3267e4f1aae1a5be2abec Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 20 Apr 2009 20:40:12 +0000 Subject: [PATCH 0088/1077] Fixed bug with reallocation for Read_raw for storage bin. Was allocating space for a pointer array instead of structure arrays for exchange, surface, etc. ReadClass.cxx. Commented delay_free for debugging in main.c down and dirty dump for transport using dump_raw StorageBin. (readtr.c) Changed definitions for sit.c to use variables in pitzer.c. Defined with extern in sit.c. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3459 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 9bcb7930..5960f973 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -198,7 +198,7 @@ read_exchange_raw(void) if (count_exchange >= max_exchange) { space((void **) ((void *) &(exchange)), count_exchange, - &max_exchange, sizeof(struct exchange *)); + &max_exchange, sizeof(struct exchange)); } exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); exchange_sort(); @@ -292,7 +292,7 @@ read_surface_raw(void) if (count_surface >= max_surface) { space((void **) ((void *) &(surface)), count_surface, - &max_surface, sizeof(struct surface *)); + &max_surface, sizeof(struct surface)); } surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); surface_sort(); @@ -389,7 +389,7 @@ read_equilibrium_phases_raw(void) if (count_pp_assemblage >= max_pp_assemblage) { space((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage *)); + &max_pp_assemblage, sizeof(struct pp_assemblage)); } pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], pp_assemblage_ptr->n_user); @@ -484,7 +484,7 @@ read_kinetics_raw(void) if (count_kinetics >= max_kinetics) { space((void **) ((void *) &(kinetics)), count_kinetics, - &max_kinetics, sizeof(struct kinetics *)); + &max_kinetics, sizeof(struct kinetics)); } kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); kinetics_sort(); @@ -582,7 +582,7 @@ read_solid_solutions_raw(void) { space((void **) ((void *) &(s_s_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, - sizeof(struct s_s_assemblage *)); + sizeof(struct s_s_assemblage)); } s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], s_s_assemblage_ptr->n_user); @@ -677,7 +677,7 @@ read_gas_phase_raw(void) if (count_gas_phase >= max_gas_phase) { space((void **) ((void *) &(gas_phase)), count_gas_phase, - &max_gas_phase, sizeof(struct gas_phase *)); + &max_gas_phase, sizeof(struct gas_phase)); } gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); gas_phase_sort(); From ccd310298d75de3ab6ad144d57a11fc8a7a1ad8f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 12 Aug 2009 16:55:42 +0000 Subject: [PATCH 0089/1077] SOLUTION_RAW: c++ version used in PHAST misinterpreted the element Tc as the temperature identifier and crashed when additional elements followed in -totals or -activity_coefficients. Removed "tc" as an identifier for temperature. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3613 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 47564806..68774f7a 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -554,7 +554,7 @@ cxxSolution::read_raw(CParser & parser) vopts.push_back("gammas"); // 2 vopts.push_back("isotopes"); // 3 vopts.push_back("temp"); // 4 - vopts.push_back("tc"); // 5 + vopts.push_back("tc_avoid_conflict_with_technetium"); // 5 vopts.push_back("temperature"); // 6 vopts.push_back("ph"); // 7 vopts.push_back("pe"); // 8 @@ -673,7 +673,7 @@ cxxSolution::read_raw(CParser & parser) break; case 4: // temp - case 5: // tc + case 5: // tc_avoid_conflict_with_technetium case 6: // temperature if (!(parser.get_iss() >> this->tc)) { From a81cd945b333a65e9b3f95e925da4bfd13c6352b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 6 Oct 2009 22:55:15 +0000 Subject: [PATCH 0090/1077] Added dump datablock for phreeqcpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3700 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 18 +++ ReadClass.cxx | 362 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 378 insertions(+), 2 deletions(-) diff --git a/Parser.h b/Parser.h index 4a433053..ce6472a6 100644 --- a/Parser.h +++ b/Parser.h @@ -280,4 +280,22 @@ class CParser ECHO_OPTION echo_file; }; +// Global functions +inline std::string trim_right(const std::string &source , const std::string& t = " \t") +{ + std::string str = source; + return str.erase( str.find_last_not_of(t) + 1); +} + +inline std::string trim_left( const std::string& source, const std::string& t = " \t") +{ + std::string str = source; + return str.erase(0 , source.find_first_not_of(t) ); +} + +inline std::string trim(const std::string& source, const std::string& t = " \t") +{ + std::string str = source; + return trim_left( trim_right( str , t) , t ); +} #endif // PARSER_H_INCLUDED diff --git a/ReadClass.cxx b/ReadClass.cxx index 5960f973..26e2a96e 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -12,18 +12,21 @@ #include "Reaction.h" #include "cxxMix.h" #include "Temperature.h" +#include "dumper.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" #include "output.h" #include "phrqproto.h" #include +#include +#include - +static int streamify_to_next_keyword(std::istringstream & lines); extern int reading_database(void); extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); - +dumper dump_info; /* ---------------------------------------------------------------------- */ int read_solution_raw(void) @@ -928,6 +931,7 @@ read_temperature_raw(void) CParser parser(iss_in, oss_out, oss_err); assert(!reading_database()); + if (pr.echo_input == FALSE) { parser.set_echo_file(CParser::EO_NONE); @@ -976,3 +980,357 @@ read_temperature_raw(void) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } +/* ---------------------------------------------------------------------- */ +int +read_dump(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads DUMP data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + dumper dmp(parser); + dump_info = dmp; + + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int +streamify_to_next_keyword(std::istringstream & lines) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads to next keyword or eof + * + * Returns: + * KEYWORD + * OPTION + * EOF + */ + const char *opt_list[] = { + "none" + }; + int count_opt_list = 0; + int opt; + char *next_char; + + // Handle echo + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; + + std::string accumulate(line); + accumulate.append("\n"); + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_EOF) + { /* end of file */ + break; + } + else if (opt == OPTION_KEYWORD) + { /* keyword */ + break; + } + else + { + accumulate.append(line); + accumulate.append("\n"); + } + } + pr.echo_input = save_echo_input; + lines.str(accumulate); + return (opt); +} +#endif +/* ---------------------------------------------------------------------- */ +int +streamify_to_next_keyword(std::istringstream & lines) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads to next keyword or eof + * + * Returns: + * OPTION_KEYWORD + * OPTION_EOF + * + */ + // Handle echo + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; + + std::string accumulate(line); + accumulate.append("\n"); + int j; + for (;;) + { + j = check_line("Streamify", FALSE, TRUE, TRUE, FALSE); + if (j == EOF) + { /* end of file */ + break; + } + else if (j == KEYWORD) + { /* keyword */ + break; + } + else + { + accumulate.append(line); + accumulate.append("\n"); + } + } + + lines.str(accumulate); + //std::cerr << accumulate; + pr.echo_input = save_echo_input; + if (j == EOF) return (OPTION_EOF); + if (j == KEYWORD) return (OPTION_KEYWORD); + + + return (OPTION_ERROR); +} +/* ---------------------------------------------------------------------- */ +int +dump_entities(void) +/* ---------------------------------------------------------------------- */ +{ + int i, n, return_value; + return_value = OK; + + + + std::ofstream dump_stream; + if (dump_info.get_append()) + { + //dump_stream.open(dump_info.get_file_name(), std::ios_base::app); + dump_stream.open(dump_info.get_file_name().c_str(), std::ios_base::app); + } + else + { + dump_stream.open(dump_info.get_file_name().c_str()); + } + // solutions + if (dump_info.get_dump_solution()) + { + if (dump_info.get_solution().size() == 0) + { + for (i = 0; i < count_solution; i++) + { + cxxSolution cxxsoln(solution[i]); + cxxsoln.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_solution().begin(); it != dump_info.get_solution().end(); it++) + { + if (solution_bsearch(*it, &n, FALSE) != NULL) + { + cxxSolution cxxsoln(solution[n]); + cxxsoln.dump_raw(dump_stream,0); + } + } + } + } + + // pp_assemblages + if (dump_info.get_dump_pp_assemblage()) + { + if (dump_info.get_pp_assemblage().size() == 0) + { + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage cxxentity(&pp_assemblage[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_pp_assemblage().begin(); it != dump_info.get_pp_assemblage().end(); it++) + { + + if (pp_assemblage_bsearch(*it, &n) != NULL) + { + cxxPPassemblage cxxentity(&pp_assemblage[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + // exchanges + if (dump_info.get_dump_exchange()) + { + if (dump_info.get_exchange().size() == 0) + { + for (i = 0; i < count_exchange; i++) + { + cxxExchange cxxentity(&exchange[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_exchange().begin(); it != dump_info.get_exchange().end(); it++) + { + + if (exchange_bsearch(*it, &n) != NULL) + { + cxxExchange cxxentity(&exchange[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + // surfaces + if (dump_info.get_dump_surface()) + { + if (dump_info.get_surface().size() == 0) + { + for (i = 0; i < count_surface; i++) + { + cxxSurface cxxentity(&surface[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_surface().begin(); it != dump_info.get_surface().end(); it++) + { + + if (surface_bsearch(*it, &n) != NULL) + { + cxxSurface cxxentity(&surface[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + // s_s_assemblages + if (dump_info.get_dump_s_s_assemblage()) + { + if (dump_info.get_s_s_assemblage().size() == 0) + { + for (i = 0; i < count_s_s_assemblage; i++) + { + cxxSSassemblage cxxentity(&s_s_assemblage[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_s_s_assemblage().begin(); it != dump_info.get_s_s_assemblage().end(); it++) + { + + if (s_s_assemblage_bsearch(*it, &n) != NULL) + { + cxxSSassemblage cxxentity(&s_s_assemblage[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + // gas_phases + if (dump_info.get_dump_gas_phase()) + { + if (dump_info.get_gas_phase().size() == 0) + { + for (i = 0; i < count_gas_phase; i++) + { + cxxGasPhase cxxentity(&gas_phase[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_gas_phase().begin(); it != dump_info.get_gas_phase().end(); it++) + { + + if (gas_phase_bsearch(*it, &n) != NULL) + { + cxxGasPhase cxxentity(&gas_phase[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + // kineticss + if (dump_info.get_dump_kinetics()) + { + if (dump_info.get_kinetics().size() == 0) + { + for (i = 0; i < count_kinetics; i++) + { + cxxKinetics cxxentity(&kinetics[i]); + cxxentity.dump_raw(dump_stream,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.get_kinetics().begin(); it != dump_info.get_kinetics().end(); it++) + { + + if (kinetics_bsearch(*it, &n) != NULL) + { + cxxKinetics cxxentity(&kinetics[n]); + cxxentity.dump_raw(dump_stream,0); + } + } + } + } + + dump_info.DumpAll(false); + + + return (OK); +} From 4d71795183bd340554e08cd00b30c1d550cf57f0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 6 Oct 2009 23:00:51 +0000 Subject: [PATCH 0091/1077] Added dump files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3701 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dumper.cpp | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ dumper.h | 53 +++++++++++ 2 files changed, 327 insertions(+) create mode 100644 dumper.cpp create mode 100644 dumper.h diff --git a/dumper.cpp b/dumper.cpp new file mode 100644 index 00000000..923ad49f --- /dev/null +++ b/dumper.cpp @@ -0,0 +1,274 @@ +#include "dumper.h" +#include // std::replace + +dumper::dumper(void) +{ + this->file_name = "dump.out"; + this->append = false; + this->dump_solution = false; + this->dump_pp_assemblage = false; + this->dump_exchange = false; + this->dump_surface = false; + this->dump_s_s_assemblage = false; + this->dump_gas_phase = false; + this->dump_kinetics = false; +} +dumper::dumper(CParser & parser) +{ + this->file_name = "dump.out"; + this->append = false; + + this->dump_solution = false; + this->dump_pp_assemblage = false; + this->dump_exchange = false; + this->dump_surface = false; + this->dump_s_s_assemblage = false; + this->dump_gas_phase = false; + this->dump_kinetics = false; + this->Read(parser); +} + +dumper::~dumper(void) +{ +} + +void dumper::DumpAll(bool tf) +{ + this->solution.clear(); + this->pp_assemblage.clear(); + this->exchange.clear(); + this->surface.clear(); + this->s_s_assemblage.clear(); + this->gas_phase.clear(); + this->kinetics.clear(); + + if (tf) + { + this->dump_solution = true; + this->dump_pp_assemblage = true; + this->dump_exchange = true; + this->dump_surface = true; + this->dump_s_s_assemblage = true; + this->dump_gas_phase = true; + this->dump_kinetics = true; + } + else + { + this->dump_solution = false; + this->dump_pp_assemblage = false; + this->dump_exchange = false; + this->dump_surface = false; + this->dump_s_s_assemblage = false; + this->dump_gas_phase = false; + this->dump_kinetics = false; + } +} +bool dumper::Read(CParser & parser) +{ + + bool return_value(true); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("solution"); + vopts.push_back("pp_assemblage"); + vopts.push_back("equilibrium_phases"); + vopts.push_back("exchange"); + vopts.push_back("surface"); + vopts.push_back("s_s_assemblage"); + vopts.push_back("gas_phase"); + vopts.push_back("kinetics"); + vopts.push_back("file"); + vopts.push_back("append"); + vopts.push_back("all"); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read mix number and description + //this->read_number_description(parser); + + opt_save = CParser::OPT_DEFAULT; + + 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; + } + else + { + opt_save = opt; + } + std::set < int > accumulator; + + // Read list of numbers or number ranges for line + if (opt >= 0 && opt <= 7) + { + for (;;) + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + std::set < int > temp_set; + int i; + if (j == CParser::TT_EMPTY) + { + break; + } + else if (j == CParser::TT_DIGIT) + { + std::replace(token.begin(), token.end(), '-', ' '); + //if (token.find_last_of("-") != token.end()) + //{ + // token.replace(token.find_last_of("-"), token.find_last_of("-") + 1, " "); + //} + + std::istringstream iss(token); + if (iss >> i) + { + temp_set.insert(i); + if (iss >> i) + { + temp_set.insert(i); + } + } + if (temp_set.size() == 1) + { + accumulator.insert(*(temp_set.begin())); + } + else if (temp_set.size() == 2) + { + int i1, i2; + std::set ::iterator it; + it = temp_set.begin(); + i1 = *it; + it++; + i2 = *it; + for (i = i1; i <= i2; i++) + { + accumulator.insert(i); + } + } + else + { + parser.error_msg("Expected positive integers for dump range.", + CParser::OT_CONTINUE); + } + } + else + { + parser.error_msg("Expected single number or range of numbers.", + CParser::OT_CONTINUE); + } + } + } + + // Process identifiers + std::set < int >::iterator it; + 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 reading DUMP definition.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + return_value = false; + break; + case 0: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->solution.insert(*it); + } + this->dump_solution = true; + break; + case 1: + case 2: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->pp_assemblage.insert(*it); + } + this->dump_pp_assemblage = true; + break; + case 3: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->exchange.insert(*it); + } + this->dump_exchange = true; + break; + case 4: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->surface.insert(*it); + } + this->dump_surface = true; + break; + case 5: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->s_s_assemblage.insert(*it); + } this->dump_s_s_assemblage = true; + break; + case 6: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->gas_phase.insert(*it); + } this->dump_gas_phase = true; + break; + case 7: + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + this->kinetics.insert(*it); + } + this->dump_kinetics = true; + break; + case 8: //file + std::getline(parser.get_iss(), this->file_name); + this->file_name = trim(this->file_name, " \t"); + if (this->file_name.size() == 0) + { + this->file_name = "dump.out"; + } + + break; + case 9: //append + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + //if (!(parser.get_iss() >> this->append)) + this->append = true; + if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') + { + this->append = false; + } + } + break; + case 10: //all + this->DumpAll(true); + break; + } + + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + return(return_value); +} diff --git a/dumper.h b/dumper.h new file mode 100644 index 00000000..e68426aa --- /dev/null +++ b/dumper.h @@ -0,0 +1,53 @@ +#if !defined(DUMPER_H_INCLUDED) +#define DUMPER_H_INCLUDED +#include // std::set +#include // std::string +#include // std::list +#include // std::vector +#include "Parser.h" +class dumper +{ +public: + dumper(void); + dumper(CParser & parser); + ~dumper(void); + bool Read(CParser & parser); + void DumpAll(bool tf); + std::string get_file_name(void) { return(this->file_name); }; + bool get_append(void) { return(this->append); }; + bool get_dump_solution(void) { return(this->dump_solution); }; + bool get_dump_pp_assemblage(void) { return(this->dump_pp_assemblage); }; + bool get_dump_exchange(void) { return(this->dump_exchange); }; + bool get_dump_surface(void) { return(this->dump_surface); }; + bool get_dump_s_s_assemblage(void) { return(this->dump_s_s_assemblage); }; + bool get_dump_gas_phase(void) { return(this->dump_gas_phase); }; + bool get_dump_kinetics(void) { return(this->dump_kinetics); }; + + std::set < int > & get_solution(void) { return(this->solution); }; + std::set < int > & get_pp_assemblage(void) { return(this->pp_assemblage); }; + std::set < int > & get_exchange(void) { return(this->exchange); }; + std::set < int > & get_surface(void) { return(this->surface); }; + std::set < int > & get_s_s_assemblage(void) { return(this->s_s_assemblage); }; + std::set < int > & get_gas_phase(void) { return(this->gas_phase); }; + std::set < int > & get_kinetics(void) { return(this->kinetics); }; +protected: + std::string file_name; + bool append; + bool dump_solution; + bool dump_pp_assemblage; + bool dump_exchange; + bool dump_surface; + bool dump_s_s_assemblage; + bool dump_gas_phase; + bool dump_kinetics; + + std::set < int > solution; + std::set < int > pp_assemblage; + std::set < int > exchange; + std::set < int > surface; + std::set < int > s_s_assemblage; + std::set < int > gas_phase; + std::set < int > kinetics; +}; + +#endif // !defined(DUMPER_H_INCLUDED) \ No newline at end of file From c3d4c1c4620b16bdad169d52b2261719df48f2bd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Oct 2009 16:19:39 +0000 Subject: [PATCH 0092/1077] Subsequent simulation wiped out dump file even though there was no dump. Check to see if dump file is needed before opening file in dump_entities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3705 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 26e2a96e..cdc760fd 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1135,7 +1135,16 @@ dump_entities(void) { int i, n, return_value; return_value = OK; - + if (!dump_info.get_dump_solution() && + !dump_info.get_dump_pp_assemblage() && + !dump_info.get_dump_exchange() && + !dump_info.get_dump_surface() && + !dump_info.get_dump_s_s_assemblage() && + !dump_info.get_dump_gas_phase() && + !dump_info.get_dump_kinetics()) + { + return(OK); + } std::ofstream dump_stream; From 6ca3a6d3b24357c50cbc964bc1e7aa2bc72b70bd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Oct 2009 19:40:43 +0000 Subject: [PATCH 0093/1077] Added the suite of modify keywords: SOLUTION_MODIFY EQUILIBRIUM_PHASES_MODIFY EXCHANGE_MODIFY SURFACE_MODIFY SOLID_SOLUTIONS_MODIFY GAS_PHASE_MODIFY KINETICS_MODIFY May now revisit dump to add a delete capability. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3714 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 17 +- Exchange.h | 2 +- GasPhase.cxx | 39 +-- GasPhase.h | 2 +- PPassemblage.cxx | 2 +- PPassemblage.h | 2 +- ReadClass.cxx | 636 +++++++++++++++++++++++++++++++++++++++++++---- SSassemblage.cxx | 2 +- SSassemblage.h | 2 +- Solution.cxx | 127 +++++----- Solution.h | 2 +- Surface.cxx | 139 ++++++----- Surface.h | 2 +- Utils.cxx | 10 + Utils.h | 2 + cxxKinetics.cxx | 75 +++--- cxxKinetics.h | 2 +- dumper.cpp | 72 +++--- dumper.h | 28 +-- 19 files changed, 863 insertions(+), 300 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 0ada85d1..c16043a7 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -289,7 +289,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchange::read_raw(CParser & parser) +cxxExchange::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -363,13 +363,16 @@ cxxExchange::read_raw(CParser & parser) break; } // members that must be defined - if (pitzer_exchange_gammas_defined == false) + if (check) { - parser.incr_input_error(); - parser. - error_msg - ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", - CParser::OT_CONTINUE); + if (pitzer_exchange_gammas_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", + CParser::OT_CONTINUE); + } } } void diff --git a/Exchange.h b/Exchange.h index 9a234578..af23f7af 100644 --- a/Exchange.h +++ b/Exchange.h @@ -28,7 +28,7 @@ class cxxExchange:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/GasPhase.cxx b/GasPhase.cxx index 2036bc67..1cc1e184 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -253,7 +253,7 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxGasPhase::read_raw(CParser & parser) +cxxGasPhase::read_raw(CParser & parser, bool check) { int i; @@ -369,24 +369,27 @@ cxxGasPhase::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (type_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Type not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); - } - if (total_p_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); - } - if (volume_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + // members that must be defined + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Type not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (total_p_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } + if (volume_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/GasPhase.h b/GasPhase.h index 4b6a86ce..8b40b860 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -38,7 +38,7 @@ class cxxGasPhase:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 776b36ab..02ef3ead 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -163,7 +163,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxPPassemblage::read_raw(CParser & parser) +cxxPPassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/PPassemblage.h b/PPassemblage.h index b47d5654..096edadb 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -30,7 +30,7 @@ class cxxPPassemblage:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); const cxxNameDouble & get_totals() const { diff --git a/ReadClass.cxx b/ReadClass.cxx index cdc760fd..541b3648 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1032,55 +1032,589 @@ read_dump(void) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } -#ifdef SKIP +/* /* ---------------------------------------------------------------------- */ int -streamify_to_next_keyword(std::istringstream & lines) +read_solution_modify(void) /* ---------------------------------------------------------------------- */ { /* - * Reads to next keyword or eof + * Reads solution_modify data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data * - * Returns: - * KEYWORD - * OPTION - * EOF */ - const char *opt_list[] = { - "none" - }; - int count_opt_list = 0; - int opt; - char *next_char; + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); - // Handle echo - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); - std::string accumulate(line); - accumulate.append("\n"); - for (;;) + if (pr.echo_input == FALSE) { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_EOF) - { /* end of file */ - break; - } - else if (opt == OPTION_KEYWORD) - { /* keyword */ - break; - } - else - { - accumulate.append(line); - accumulate.append("\n"); - } + parser.set_echo_file(CParser::EO_NONE); } - pr.echo_input = save_echo_input; - lines.str(accumulate); - return (opt); + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find solution 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 solution number following SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (solution_bsearch(n_user, &n, FALSE) == NULL) + { + input_error++; + sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + cxxSolution sol(solution[n]); + sol.read_raw(parser, false); + + struct solution *soln_ptr = sol.cxxSolution2solution(); + + /* + * This is not quite right, may not produce sort order, forced sort + */ + + solution_free(solution[n]); + solution[n] = soln_ptr; + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_equilibrium_phases_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads equilibrium_phases_modify data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find equilibrium_phases 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 equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (pp_assemblage_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxPPassemblage entity(&(pp_assemblage[n])); + entity.read_raw(parser, false); + + // save entity + struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(); + pp_assemblage_free(&(pp_assemblage[n])); + pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); + pp_assemblage_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_exchange_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads EXCHANGE_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + 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) + { + input_error++; + sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxExchange entity(&(exchange[n])); + entity.read_raw(parser, false); + + // save entity + struct exchange *entity_ptr = entity.cxxExchange2exchange(); + exchange_free(&(exchange[n])); + exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); + exchange_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_surface_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SURFACE_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find surface 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 surface number following SURFACE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (surface_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxSurface entity(&(surface[n])); + entity.read_raw(parser, false); + + // save entity + struct surface *entity_ptr = entity.cxxSurface2surface(); + surface_free(&(surface[n])); + surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); + surface_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_solid_solutions_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads SOLID_SOLUTIONS_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find solid_solutions 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 solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (s_s_assemblage_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxSSassemblage entity(&(s_s_assemblage[n])); + entity.read_raw(parser, false); + + // save entity + struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(); + s_s_assemblage_free(&(s_s_assemblage[n])); + s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); + s_s_assemblage_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_gas_phase_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads GAS_PHASE_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find gas_phase 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 gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (gas_phase_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxGasPhase entity(&(gas_phase[n])); + entity.read_raw(parser, false); + // save entity + struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(); + gas_phase_free(&(gas_phase[n])); + gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); + gas_phase_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_kinetics_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads KINETICS_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + // find kinetics 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 kinetics number following KINETICS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + if (kinetics_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxKinetics entity(&(kinetics[n])); + entity.read_raw(parser, false); + + // save entity + struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(); + kinetics_free(&(kinetics[n])); + kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); + kinetics_free(entity_ptr); + + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); } -#endif /* ---------------------------------------------------------------------- */ int streamify_to_next_keyword(std::istringstream & lines) @@ -1135,13 +1669,13 @@ dump_entities(void) { int i, n, return_value; return_value = OK; - if (!dump_info.get_dump_solution() && - !dump_info.get_dump_pp_assemblage() && - !dump_info.get_dump_exchange() && - !dump_info.get_dump_surface() && - !dump_info.get_dump_s_s_assemblage() && - !dump_info.get_dump_gas_phase() && - !dump_info.get_dump_kinetics()) + if (!dump_info.get_bool_solution() && + !dump_info.get_bool_pp_assemblage() && + !dump_info.get_bool_exchange() && + !dump_info.get_bool_surface() && + !dump_info.get_bool_s_s_assemblage() && + !dump_info.get_bool_gas_phase() && + !dump_info.get_bool_kinetics()) { return(OK); } @@ -1158,7 +1692,7 @@ dump_entities(void) dump_stream.open(dump_info.get_file_name().c_str()); } // solutions - if (dump_info.get_dump_solution()) + if (dump_info.get_bool_solution()) { if (dump_info.get_solution().size() == 0) { @@ -1183,7 +1717,7 @@ dump_entities(void) } // pp_assemblages - if (dump_info.get_dump_pp_assemblage()) + if (dump_info.get_bool_pp_assemblage()) { if (dump_info.get_pp_assemblage().size() == 0) { @@ -1209,7 +1743,7 @@ dump_entities(void) } // exchanges - if (dump_info.get_dump_exchange()) + if (dump_info.get_bool_exchange()) { if (dump_info.get_exchange().size() == 0) { @@ -1235,7 +1769,7 @@ dump_entities(void) } // surfaces - if (dump_info.get_dump_surface()) + if (dump_info.get_bool_surface()) { if (dump_info.get_surface().size() == 0) { @@ -1261,7 +1795,7 @@ dump_entities(void) } // s_s_assemblages - if (dump_info.get_dump_s_s_assemblage()) + if (dump_info.get_bool_s_s_assemblage()) { if (dump_info.get_s_s_assemblage().size() == 0) { @@ -1287,7 +1821,7 @@ dump_entities(void) } // gas_phases - if (dump_info.get_dump_gas_phase()) + if (dump_info.get_bool_gas_phase()) { if (dump_info.get_gas_phase().size() == 0) { @@ -1313,7 +1847,7 @@ dump_entities(void) } // kineticss - if (dump_info.get_dump_kinetics()) + if (dump_info.get_bool_kinetics()) { if (dump_info.get_kinetics().size() == 0) { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index a5dd5251..724426f3 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -151,7 +151,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblage::read_raw(CParser & parser) +cxxSSassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/SSassemblage.h b/SSassemblage.h index c3255ec3..d3784752 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -32,7 +32,7 @@ class cxxSSassemblage:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/Solution.cxx b/Solution.cxx index 68774f7a..1a5fe63f 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -543,7 +543,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSolution::read_raw(CParser & parser) +cxxSolution::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -806,68 +806,71 @@ cxxSolution::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // all members must be defined - if (tc_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (ph_defined == false) - { - parser.incr_input_error(); - parser.error_msg("pH not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (pe_defined == false) - { - parser.incr_input_error(); - parser.error_msg("pe not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (mu_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (ah2o_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Activity of water not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_h_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_o_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (cb_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (mass_water_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); - } - if (total_alkalinity_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Total alkalinity not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + // all members must be defined + if (tc_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ph_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pH not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (pe_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pe not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mu_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (ah2o_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Activity of water not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_h_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_o_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (cb_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } + if (total_alkalinity_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Total alkalinity not defined for SOLUTION_RAW input.", + CParser::OT_CONTINUE); + } } return; } diff --git a/Solution.h b/Solution.h index 8804d8d5..2f45095b 100644 --- a/Solution.h +++ b/Solution.h @@ -156,7 +156,7 @@ class cxxSolution:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); void multiply(double extensive); #ifdef ORCHESTRA void ORCH_write(std::ostream & headings, std::ostream & input_data) const; diff --git a/Surface.cxx b/Surface.cxx index b4eb8150..4023d439 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -359,7 +359,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurface::read_raw(CParser & parser) +cxxSurface::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; int i = 0; @@ -613,77 +613,80 @@ cxxSurface::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - /* - if (diffuse_layer_defined == false) { - parser.incr_input_error(); - parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - if (edl_defined == false) { - parser.incr_input_error(); - parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (only_counter_ions_defined == false) + if (check) { + // members that must be defined + /* + if (diffuse_layer_defined == false) { parser.incr_input_error(); - parser. - error_msg("Only_counter_ions not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - /* - if (donnan_defined == false) { - parser.incr_input_error(); - parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); - } - */ - if (thickness_defined == false) - { + parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + if (edl_defined == false) { parser.incr_input_error(); - parser.error_msg("Thickness not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (type_defined == false) - { + parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (only_counter_ions_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Only_counter_ions not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + /* + if (donnan_defined == false) { parser.incr_input_error(); - parser.error_msg("Surface type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (dl_type_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Dl_type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (sites_units_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Sites_units not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (debye_lengths_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (DDL_viscosity_defined == false) - { - parser.incr_input_error(); - parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (DDL_limit_defined == false) - { - parser.incr_input_error(); - parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); - } - if (transport_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Transport not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + } + */ + if (thickness_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Thickness not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Surface type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (dl_type_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Dl_type not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (sites_units_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Sites_units not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (debye_lengths_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_viscosity_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (DDL_limit_defined == false) + { + parser.incr_input_error(); + parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } + if (transport_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Transport not defined for SURFACE_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/Surface.h b/Surface.h index b9d94fba..9ad68f5a 100644 --- a/Surface.h +++ b/Surface.h @@ -37,7 +37,7 @@ class cxxSurface:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/Utils.cxx b/Utils.cxx index 1a3f6ff7..f11f3416 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -92,3 +92,13 @@ Utilities::error_msg(const std::string & err_str, const int stop) output_message(OUTPUT_ERROR, err_str, stop, "", args); } #endif + +//+NAN double: 7ff8000000000000 +//-NAN double: fff8000000000000 +double Utilities::get_nan(void) +{ + unsigned long long raw = 0x7ff0000000000000; + double d = *( double* )&raw; + return(d); + +} diff --git a/Utils.h b/Utils.h index 2bed81de..4696d4e2 100644 --- a/Utils.h +++ b/Utils.h @@ -31,6 +31,8 @@ namespace Utilities void squeeze_white(std::string & s_l); + double get_nan(void); + //void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 49392e43..3fb83d62 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -259,7 +259,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKinetics::read_raw(CParser & parser) +cxxKinetics::read_raw(CParser & parser, bool check) { double d; @@ -445,42 +445,45 @@ cxxKinetics::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (step_divide_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Step_divide not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (rk_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Rk not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (bad_step_max_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (use_cvode_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (cvode_steps_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } - if (cvode_order_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + // members that must be defined + if (step_divide_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Step_divide not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (rk_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rk not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (bad_step_max_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (use_cvode_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_steps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } + if (cvode_order_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/cxxKinetics.h b/cxxKinetics.h index aa5f3edc..8f42b3e7 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -32,7 +32,7 @@ class cxxKinetics:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/dumper.cpp b/dumper.cpp index 923ad49f..0b9738f4 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -5,26 +5,26 @@ dumper::dumper(void) { this->file_name = "dump.out"; this->append = false; - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; } dumper::dumper(CParser & parser) { this->file_name = "dump.out"; this->append = false; - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; this->Read(parser); } @@ -44,23 +44,23 @@ void dumper::DumpAll(bool tf) if (tf) { - this->dump_solution = true; - this->dump_pp_assemblage = true; - this->dump_exchange = true; - this->dump_surface = true; - this->dump_s_s_assemblage = true; - this->dump_gas_phase = true; - this->dump_kinetics = true; + this->bool_solution = true; + this->bool_pp_assemblage = true; + this->bool_exchange = true; + this->bool_surface = true; + this->bool_s_s_assemblage = true; + this->bool_gas_phase = true; + this->bool_kinetics = true; } else { - this->dump_solution = false; - this->dump_pp_assemblage = false; - this->dump_exchange = false; - this->dump_surface = false; - this->dump_s_s_assemblage = false; - this->dump_gas_phase = false; - this->dump_kinetics = false; + this->bool_solution = false; + this->bool_pp_assemblage = false; + this->bool_exchange = false; + this->bool_surface = false; + this->bool_s_s_assemblage = false; + this->bool_gas_phase = false; + this->bool_kinetics = false; } } bool dumper::Read(CParser & parser) @@ -198,7 +198,7 @@ bool dumper::Read(CParser & parser) { this->solution.insert(*it); } - this->dump_solution = true; + this->bool_solution = true; break; case 1: case 2: @@ -206,40 +206,42 @@ bool dumper::Read(CParser & parser) { this->pp_assemblage.insert(*it); } - this->dump_pp_assemblage = true; + this->bool_pp_assemblage = true; break; case 3: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->exchange.insert(*it); } - this->dump_exchange = true; + this->bool_exchange = true; break; case 4: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->surface.insert(*it); } - this->dump_surface = true; + this->bool_surface = true; break; case 5: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->s_s_assemblage.insert(*it); - } this->dump_s_s_assemblage = true; + } + this->bool_s_s_assemblage = true; break; case 6: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->gas_phase.insert(*it); - } this->dump_gas_phase = true; + } + this->bool_gas_phase = true; break; case 7: for (it = accumulator.begin(); it != accumulator.end(); it++) { this->kinetics.insert(*it); } - this->dump_kinetics = true; + this->bool_kinetics = true; break; case 8: //file std::getline(parser.get_iss(), this->file_name); diff --git a/dumper.h b/dumper.h index e68426aa..50247795 100644 --- a/dumper.h +++ b/dumper.h @@ -15,13 +15,13 @@ public: void DumpAll(bool tf); std::string get_file_name(void) { return(this->file_name); }; bool get_append(void) { return(this->append); }; - bool get_dump_solution(void) { return(this->dump_solution); }; - bool get_dump_pp_assemblage(void) { return(this->dump_pp_assemblage); }; - bool get_dump_exchange(void) { return(this->dump_exchange); }; - bool get_dump_surface(void) { return(this->dump_surface); }; - bool get_dump_s_s_assemblage(void) { return(this->dump_s_s_assemblage); }; - bool get_dump_gas_phase(void) { return(this->dump_gas_phase); }; - bool get_dump_kinetics(void) { return(this->dump_kinetics); }; + bool get_bool_solution(void) { return(this->bool_solution); }; + bool get_bool_pp_assemblage(void) { return(this->bool_pp_assemblage); }; + bool get_bool_exchange(void) { return(this->bool_exchange); }; + bool get_bool_surface(void) { return(this->bool_surface); }; + bool get_bool_s_s_assemblage(void) { return(this->bool_s_s_assemblage); }; + bool get_bool_gas_phase(void) { return(this->bool_gas_phase); }; + bool get_bool_kinetics(void) { return(this->bool_kinetics); }; std::set < int > & get_solution(void) { return(this->solution); }; std::set < int > & get_pp_assemblage(void) { return(this->pp_assemblage); }; @@ -33,13 +33,13 @@ public: protected: std::string file_name; bool append; - bool dump_solution; - bool dump_pp_assemblage; - bool dump_exchange; - bool dump_surface; - bool dump_s_s_assemblage; - bool dump_gas_phase; - bool dump_kinetics; + bool bool_solution; + bool bool_pp_assemblage; + bool bool_exchange; + bool bool_surface; + bool bool_s_s_assemblage; + bool bool_gas_phase; + bool bool_kinetics; std::set < int > solution; std::set < int > pp_assemblage; From 79092e94b4bf743bcb6260f91f6d717b3abc173c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Oct 2009 19:24:31 +0000 Subject: [PATCH 0094/1077] Have added delete, but parser is not working correctly. Am going back to 3705 to see if it worked correctly then. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3716 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 366 +++++++++++++++++++++++++++++++++++++++++++++----- dumper.cpp | 202 ++++++++++++++++++++++------ dumper.h | 50 +++---- 3 files changed, 513 insertions(+), 105 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 541b3648..e0b15206 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -27,6 +27,7 @@ extern int reading_database(void); extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); dumper dump_info; +StorageBinList delete_info; /* ---------------------------------------------------------------------- */ int read_solution_raw(void) @@ -1028,6 +1029,58 @@ read_dump(void) dump_info = dmp; + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_delete(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads DELETE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + StorageBinList deleter(parser); + delete_info = deleter; + + // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); @@ -1669,13 +1722,13 @@ dump_entities(void) { int i, n, return_value; return_value = OK; - if (!dump_info.get_bool_solution() && - !dump_info.get_bool_pp_assemblage() && - !dump_info.get_bool_exchange() && - !dump_info.get_bool_surface() && - !dump_info.get_bool_s_s_assemblage() && - !dump_info.get_bool_gas_phase() && - !dump_info.get_bool_kinetics()) + if (!dump_info.Get_bool_solution() && + !dump_info.Get_bool_pp_assemblage() && + !dump_info.Get_bool_exchange() && + !dump_info.Get_bool_surface() && + !dump_info.Get_bool_s_s_assemblage() && + !dump_info.Get_bool_gas_phase() && + !dump_info.Get_bool_kinetics()) { return(OK); } @@ -1692,9 +1745,9 @@ dump_entities(void) dump_stream.open(dump_info.get_file_name().c_str()); } // solutions - if (dump_info.get_bool_solution()) + if (dump_info.Get_bool_solution()) { - if (dump_info.get_solution().size() == 0) + if (dump_info.Get_solution().size() == 0) { for (i = 0; i < count_solution; i++) { @@ -1705,7 +1758,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_solution().begin(); it != dump_info.get_solution().end(); it++) + for (it = dump_info.Get_solution().begin(); it != dump_info.Get_solution().end(); it++) { if (solution_bsearch(*it, &n, FALSE) != NULL) { @@ -1717,9 +1770,9 @@ dump_entities(void) } // pp_assemblages - if (dump_info.get_bool_pp_assemblage()) + if (dump_info.Get_bool_pp_assemblage()) { - if (dump_info.get_pp_assemblage().size() == 0) + if (dump_info.Get_pp_assemblage().size() == 0) { for (i = 0; i < count_pp_assemblage; i++) { @@ -1730,7 +1783,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_pp_assemblage().begin(); it != dump_info.get_pp_assemblage().end(); it++) + for (it = dump_info.Get_pp_assemblage().begin(); it != dump_info.Get_pp_assemblage().end(); it++) { if (pp_assemblage_bsearch(*it, &n) != NULL) @@ -1743,9 +1796,9 @@ dump_entities(void) } // exchanges - if (dump_info.get_bool_exchange()) + if (dump_info.Get_bool_exchange()) { - if (dump_info.get_exchange().size() == 0) + if (dump_info.Get_exchange().size() == 0) { for (i = 0; i < count_exchange; i++) { @@ -1756,7 +1809,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_exchange().begin(); it != dump_info.get_exchange().end(); it++) + for (it = dump_info.Get_exchange().begin(); it != dump_info.Get_exchange().end(); it++) { if (exchange_bsearch(*it, &n) != NULL) @@ -1769,9 +1822,9 @@ dump_entities(void) } // surfaces - if (dump_info.get_bool_surface()) + if (dump_info.Get_bool_surface()) { - if (dump_info.get_surface().size() == 0) + if (dump_info.Get_surface().size() == 0) { for (i = 0; i < count_surface; i++) { @@ -1782,7 +1835,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_surface().begin(); it != dump_info.get_surface().end(); it++) + for (it = dump_info.Get_surface().begin(); it != dump_info.Get_surface().end(); it++) { if (surface_bsearch(*it, &n) != NULL) @@ -1795,9 +1848,9 @@ dump_entities(void) } // s_s_assemblages - if (dump_info.get_bool_s_s_assemblage()) + if (dump_info.Get_bool_s_s_assemblage()) { - if (dump_info.get_s_s_assemblage().size() == 0) + if (dump_info.Get_s_s_assemblage().size() == 0) { for (i = 0; i < count_s_s_assemblage; i++) { @@ -1808,7 +1861,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_s_s_assemblage().begin(); it != dump_info.get_s_s_assemblage().end(); it++) + for (it = dump_info.Get_s_s_assemblage().begin(); it != dump_info.Get_s_s_assemblage().end(); it++) { if (s_s_assemblage_bsearch(*it, &n) != NULL) @@ -1821,9 +1874,9 @@ dump_entities(void) } // gas_phases - if (dump_info.get_bool_gas_phase()) + if (dump_info.Get_bool_gas_phase()) { - if (dump_info.get_gas_phase().size() == 0) + if (dump_info.Get_gas_phase().size() == 0) { for (i = 0; i < count_gas_phase; i++) { @@ -1834,7 +1887,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_gas_phase().begin(); it != dump_info.get_gas_phase().end(); it++) + for (it = dump_info.Get_gas_phase().begin(); it != dump_info.Get_gas_phase().end(); it++) { if (gas_phase_bsearch(*it, &n) != NULL) @@ -1847,9 +1900,9 @@ dump_entities(void) } // kineticss - if (dump_info.get_bool_kinetics()) + if (dump_info.Get_bool_kinetics()) { - if (dump_info.get_kinetics().size() == 0) + if (dump_info.Get_kinetics().size() == 0) { for (i = 0; i < count_kinetics; i++) { @@ -1860,7 +1913,7 @@ dump_entities(void) else { std::set < int >::iterator it; - for (it = dump_info.get_kinetics().begin(); it != dump_info.get_kinetics().end(); it++) + for (it = dump_info.Get_kinetics().begin(); it != dump_info.Get_kinetics().end(); it++) { if (kinetics_bsearch(*it, &n) != NULL) @@ -1872,8 +1925,259 @@ dump_entities(void) } } - dump_info.DumpAll(false); - - + // Turn off dump until next read + dump_info.SetAll(false); return (OK); } +/* ---------------------------------------------------------------------- */ +int +delete_entities(void) +/* ---------------------------------------------------------------------- */ +{ + int i, n, return_value; + return_value = OK; + if (!delete_info.Get_solution().Get_defined() && + !delete_info.Get_pp_assemblage().Get_defined() && + !delete_info.Get_exchange().Get_defined() && + !delete_info.Get_surface().Get_defined() && + !delete_info.Get_s_s_assemblage().Get_defined() && + !delete_info.Get_gas_phase().Get_defined() && + !delete_info.Get_kinetics().Get_defined() && + !delete_info.Get_mix().Get_defined() && + !delete_info.Get_reaction().Get_defined() && + !delete_info.Get_temperature().Get_defined() ) + { + return(OK); + } + + // solutions + if (delete_info.Get_solution().Get_defined()) + { + if (delete_info.Get_solution().Get_numbers().size() == 0) + { + for (i = 0; i < count_solution; i++) + { + solution_delete_n(i); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_solution().Get_numbers().begin(); it != delete_info.Get_solution().Get_numbers().end(); it++) + { + if (solution_bsearch(*it, &n, FALSE) != NULL) + { + solution_delete_n(n); + } + } + } + } + + // pp_assemblages + if (delete_info.Get_pp_assemblage().Get_defined()) + { + if (delete_info.Get_pp_assemblage().Get_numbers().size() == 0) + { + for (i = 0; i < count_pp_assemblage; i++) + { + pp_assemblage_delete(pp_assemblage[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_pp_assemblage().Get_numbers().begin(); it != delete_info.Get_pp_assemblage().Get_numbers().end(); it++) + { + + if (pp_assemblage_bsearch(*it, &n) != NULL) + { + pp_assemblage_delete(*it); + } + } + } + } + + // exchangers + if (delete_info.Get_exchange().Get_defined()) + { + if (delete_info.Get_exchange().Get_numbers().size() == 0) + { + for (i = 0; i < count_exchange; i++) + { + exchange_delete(exchange[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_exchange().Get_numbers().begin(); it != delete_info.Get_exchange().Get_numbers().end(); it++) + { + if (exchange_bsearch(*it, &n) != NULL) + { + exchange_delete(*it); + } + } + } + } + + // surfaces + if (delete_info.Get_surface().Get_defined()) + { + if (delete_info.Get_surface().Get_numbers().size() == 0) + { + for (i = 0; i < count_surface; i++) + { + surface_delete(surface[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_surface().Get_numbers().begin(); it != delete_info.Get_surface().Get_numbers().end(); it++) + { + if (surface_bsearch(*it, &n) != NULL) + { + surface_delete(*it); + } + } + } + } + + // s_s_assemblages + if (delete_info.Get_s_s_assemblage().Get_defined()) + { + if (delete_info.Get_s_s_assemblage().Get_numbers().size() == 0) + { + for (i = 0; i < count_s_s_assemblage; i++) + { + s_s_assemblage_delete(s_s_assemblage[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_s_s_assemblage().Get_numbers().begin(); it != delete_info.Get_s_s_assemblage().Get_numbers().end(); it++) + { + if (s_s_assemblage_bsearch(*it, &n) != NULL) + { + s_s_assemblage_delete(*it); + } + } + } + } + + // gas_phases + if (delete_info.Get_gas_phase().Get_defined()) + { + if (delete_info.Get_gas_phase().Get_numbers().size() == 0) + { + for (i = 0; i < count_gas_phase; i++) + { + gas_phase_delete(gas_phase[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_gas_phase().Get_numbers().begin(); it != delete_info.Get_gas_phase().Get_numbers().end(); it++) + { + if (gas_phase_bsearch(*it, &n) != NULL) + { + gas_phase_delete(*it); + } + } + } + } + + // kineticss + if (delete_info.Get_kinetics().Get_defined()) + { + if (delete_info.Get_kinetics().Get_numbers().size() == 0) + { + for (i = 0; i < count_kinetics; i++) + { + kinetics_delete(kinetics[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_kinetics().Get_numbers().begin(); it != delete_info.Get_kinetics().Get_numbers().end(); it++) + { + if (kinetics_bsearch(*it, &n) != NULL) + { + kinetics_delete(*it); + } + } + } + } + // mixes + if (delete_info.Get_mix().Get_defined()) + { + if (delete_info.Get_mix().Get_numbers().size() == 0) + { + for (i = 0; i < count_mix; i++) + { + mix_delete(mix[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_mix().Get_numbers().begin(); it != delete_info.Get_mix().Get_numbers().end(); it++) + { + if (mix_bsearch(*it, &n) != NULL) + { + mix_delete(*it); + } + } + } + } + // reactions + if (delete_info.Get_reaction().Get_defined()) + { + if (delete_info.Get_reaction().Get_numbers().size() == 0) + { + for (i = 0; i < count_irrev; i++) + { + irrev_delete(irrev[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_reaction().Get_numbers().begin(); it != delete_info.Get_reaction().Get_numbers().end(); it++) + { + if (irrev_bsearch(*it, &n) != NULL) + { + irrev_delete(*it); + } + } + } + } + // temperatures + if (delete_info.Get_temperature().Get_defined()) + { + if (delete_info.Get_temperature().Get_numbers().size() == 0) + { + for (i = 0; i < count_temperature; i++) + { + temperature_delete(temperature[i].n_user); + } + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_temperature().Get_numbers().begin(); it != delete_info.Get_temperature().Get_numbers().end(); it++) + { + if (temperature_bsearch(*it, &n) != NULL) + { + temperature_delete(*it); + } + } + } + } + // Turn off delete until next read + delete_info.SetAll(false); + return (OK); +} \ No newline at end of file diff --git a/dumper.cpp b/dumper.cpp index 0b9738f4..865a0a92 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -5,26 +5,12 @@ dumper::dumper(void) { this->file_name = "dump.out"; this->append = false; - this->bool_solution = false; - this->bool_pp_assemblage = false; - this->bool_exchange = false; - this->bool_surface = false; - this->bool_s_s_assemblage = false; - this->bool_gas_phase = false; - this->bool_kinetics = false; + this->on = false; } dumper::dumper(CParser & parser) { this->file_name = "dump.out"; this->append = false; - - this->bool_solution = false; - this->bool_pp_assemblage = false; - this->bool_exchange = false; - this->bool_surface = false; - this->bool_s_s_assemblage = false; - this->bool_gas_phase = false; - this->bool_kinetics = false; this->Read(parser); } @@ -32,37 +18,12 @@ dumper::~dumper(void) { } -void dumper::DumpAll(bool tf) +void dumper::SetAll(bool tf) { - this->solution.clear(); - this->pp_assemblage.clear(); - this->exchange.clear(); - this->surface.clear(); - this->s_s_assemblage.clear(); - this->gas_phase.clear(); - this->kinetics.clear(); + this->binList.SetAll(tf); - if (tf) - { - this->bool_solution = true; - this->bool_pp_assemblage = true; - this->bool_exchange = true; - this->bool_surface = true; - this->bool_s_s_assemblage = true; - this->bool_gas_phase = true; - this->bool_kinetics = true; - } - else - { - this->bool_solution = false; - this->bool_pp_assemblage = false; - this->bool_exchange = false; - this->bool_surface = false; - this->bool_s_s_assemblage = false; - this->bool_gas_phase = false; - this->bool_kinetics = false; - } } +#ifdef SKIP bool dumper::Read(CParser & parser) { @@ -269,6 +230,161 @@ bool dumper::Read(CParser & parser) } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + return(return_value); +} +#endif +bool dumper::Read(CParser & parser) +{ + + bool return_value(true); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("solution"); + vopts.push_back("pp_assemblage"); + vopts.push_back("equilibrium_phases"); + vopts.push_back("exchange"); + vopts.push_back("surface"); + vopts.push_back("s_s_assemblage"); + vopts.push_back("gas_phase"); + vopts.push_back("kinetics"); + vopts.push_back("file"); + vopts.push_back("append"); + vopts.push_back("all"); + vopts.push_back("on"); + vopts.push_back("off"); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read mix number and description + //this->read_number_description(parser); + + opt_save = CParser::OPT_DEFAULT; + + for (;;) + { + int opt; + opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + else + { + opt_save = opt; + } + + // Select StorageBinListItem + StorageBinListItem &item(binList.Get_solution()); + switch (opt) + { + case 0: + item = this->binList.Get_solution(); + break; + case 1: + case 2: + item = this->binList.Get_pp_assemblage(); + break; + case 3: + item = this->binList.Get_exchange(); + break; + case 4: + item = this->binList.Get_surface(); + break; + case 5: + item = this->binList.Get_s_s_assemblage(); + break; + case 6: + item = this->binList.Get_gas_phase(); + break; + case 7: + item = this->binList.Get_kinetics(); + break; + default: + break; + } + + // Read dump entity list of numbers or number ranges for line, store in item + if (opt >= 0 && opt <= 7) + { + for (;;) + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + if (j == CParser::TT_EMPTY || j == CParser::TT_DIGIT) + { + item.Augment(token); + } + else + { + parser.error_msg("Expected single number or range of numbers.", + CParser::OT_CONTINUE); + } + } + } + + // Process other identifiers + std::set < int >::iterator it; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + break; + case 8: //file + std::getline(parser.get_iss(), this->file_name); + this->file_name = trim(this->file_name, " \t"); + if (this->file_name.size() == 0) + { + this->file_name = "dump.out"; + } + + break; + case 9: //append + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + //if (!(parser.get_iss() >> this->append)) + this->append = true; + if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') + { + this->append = false; + } + } + break; + case 10: //all + this->SetAll(true); + break; + default: + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input reading DUMP definition.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + return_value = false; + break; + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } diff --git a/dumper.h b/dumper.h index 50247795..dde23e84 100644 --- a/dumper.h +++ b/dumper.h @@ -5,49 +5,37 @@ #include // std::list #include // std::vector #include "Parser.h" -class dumper +#include "StorageBinList.h" +class dumper { public: dumper(void); dumper(CParser & parser); ~dumper(void); bool Read(CParser & parser); - void DumpAll(bool tf); + void SetAll(bool tf); std::string get_file_name(void) { return(this->file_name); }; bool get_append(void) { return(this->append); }; - bool get_bool_solution(void) { return(this->bool_solution); }; - bool get_bool_pp_assemblage(void) { return(this->bool_pp_assemblage); }; - bool get_bool_exchange(void) { return(this->bool_exchange); }; - bool get_bool_surface(void) { return(this->bool_surface); }; - bool get_bool_s_s_assemblage(void) { return(this->bool_s_s_assemblage); }; - bool get_bool_gas_phase(void) { return(this->bool_gas_phase); }; - bool get_bool_kinetics(void) { return(this->bool_kinetics); }; + bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; + bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; + bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; + bool Get_bool_surface(void) { return(this->binList.Get_surface().Get_defined()); }; + bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; + bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; + bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; - std::set < int > & get_solution(void) { return(this->solution); }; - std::set < int > & get_pp_assemblage(void) { return(this->pp_assemblage); }; - std::set < int > & get_exchange(void) { return(this->exchange); }; - std::set < int > & get_surface(void) { return(this->surface); }; - std::set < int > & get_s_s_assemblage(void) { return(this->s_s_assemblage); }; - std::set < int > & get_gas_phase(void) { return(this->gas_phase); }; - std::set < int > & get_kinetics(void) { return(this->kinetics); }; + std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; + std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; + std::set < int > & Get_exchange(void) { return(this->binList.Get_exchange().Get_numbers()); }; + std::set < int > & Get_surface(void) { return(this->binList.Get_surface().Get_numbers()); }; + std::set < int > & Get_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_numbers()); }; + std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; + std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; protected: std::string file_name; bool append; - bool bool_solution; - bool bool_pp_assemblage; - bool bool_exchange; - bool bool_surface; - bool bool_s_s_assemblage; - bool bool_gas_phase; - bool bool_kinetics; - - std::set < int > solution; - std::set < int > pp_assemblage; - std::set < int > exchange; - std::set < int > surface; - std::set < int > s_s_assemblage; - std::set < int > gas_phase; - std::set < int > kinetics; + bool on; + StorageBinList binList; }; #endif // !defined(DUMPER_H_INCLUDED) \ No newline at end of file From 74bb0bc5d05a221d7115702c829d76022a887e88 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Oct 2009 19:26:38 +0000 Subject: [PATCH 0095/1077] For dump and delete, added StorageBinList git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3718 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 243 +++++++++++++++++++++++++++++++++++++++++++++ StorageBinList.h | 55 ++++++++++ 2 files changed, 298 insertions(+) create mode 100644 StorageBinList.cpp create mode 100644 StorageBinList.h diff --git a/StorageBinList.cpp b/StorageBinList.cpp new file mode 100644 index 00000000..617d7197 --- /dev/null +++ b/StorageBinList.cpp @@ -0,0 +1,243 @@ +#include "StorageBinList.h" +#include // std::replace +StorageBinListItem::StorageBinListItem(void) +{ + this->defined = false; +}; + +StorageBinListItem::~StorageBinListItem(void) +{ +}; +void StorageBinListItem::Augment(std::string token) +{ + this->defined = true; + if (token.size() == 0) return; + + // split string accounting for possible negative numbers + int pos; + if ((pos = token.find("--")) != std::string::npos) + { + token.replace(pos,2," &"); + } + std::replace(token.begin() + 1, token.end(), '-', ' '); + std::replace(token.begin() + 1, token.end(), '&', '-'); + + // parse string into 1 or 2 numbers + std::istringstream iss(token); + std::set < int > temp_set; + int i; + if (iss >> i) + { + // add first + temp_set.insert(i); + if (iss >> i) + { + // add second if defined + temp_set.insert(i); + } + } + + // add single number or range to StorageBinListItem + if (temp_set.size() == 1) + { + this->numbers.insert(*(temp_set.begin())); + } + else if (temp_set.size() == 2) + { + int i1, i2; + std::set ::iterator it; + it = temp_set.begin(); + i1 = *it; + it++; + i2 = *it; + for (i = i1; i <= i2; i++) + { + this->numbers.insert(i); + } + } +}; +StorageBinList::StorageBinList(void) +{ +} +StorageBinList::StorageBinList(CParser & parser) +{ + this->Read(parser); +} +StorageBinList::~StorageBinList(void) +{ +} + +void StorageBinList::SetAll(bool tf) +{ + this->solution.Clear(); + this->pp_assemblage.Clear(); + this->exchange.Clear(); + this->surface.Clear(); + this->s_s_assemblage.Clear(); + this->gas_phase.Clear(); + this->kinetics.Clear(); + this->mix.Clear(); + this->reaction.Clear(); + this->temperature.Clear(); + + this->solution.Set_defined(tf); + this->pp_assemblage.Set_defined(tf); + this->exchange.Set_defined(tf); + this->surface.Set_defined(tf); + this->s_s_assemblage.Set_defined(tf); + this->gas_phase.Set_defined(tf); + this->kinetics.Set_defined(tf); + this->mix.Set_defined(tf); + this->reaction.Set_defined(tf); + this->temperature.Set_defined(tf); +} + +bool StorageBinList::Read(CParser & parser) +{ + bool return_value(true); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("solution"); + vopts.push_back("pp_assemblage"); + vopts.push_back("equilibrium_phases"); + vopts.push_back("exchange"); + vopts.push_back("surface"); + vopts.push_back("s_s_assemblage"); + vopts.push_back("solid_solution"); + vopts.push_back("solid_solutions"); + vopts.push_back("gas_phase"); + vopts.push_back("kinetics"); + vopts.push_back("mix"); + vopts.push_back("reaction"); + vopts.push_back("temperature"); + vopts.push_back("all"); + } + + std::istream::pos_type next_char; + std::string token; + int opt_save; + + bool useLastLine(false); + opt_save = CParser::OPT_DEFAULT; + + for (;;) + { + int opt; + opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + else + { + opt_save = opt; + } + + // Select StorageBinListItem + StorageBinListItem *item; + switch (opt) + { + case 0: + item = &(this->Get_solution()); + break; + case 1: + case 2: + item = &(this->Get_pp_assemblage()); + break; + case 3: + item = &(this->Get_exchange()); + break; + case 4: + item = &(this->Get_surface()); + break; + case 5: + case 6: + case 7: + item = &(this->Get_s_s_assemblage()); + break; + case 8: + item = &(this->Get_gas_phase()); + break; + case 9: + item = &(this->Get_kinetics()); + break; + case 10: + item = &(this->Get_mix()); + break; + case 11: + item = &(this->Get_reaction()); + break; + case 12: + item = &(this->Get_temperature()); + break; + default: + break; + } + + // Read dump entity list of numbers or number ranges for line, store in item + if (opt >= 0 && opt <= 12) + { + for (;;) + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + if (j == CParser::TT_DIGIT) + { + item->Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + item->Augment(token); + break; + } + else + { + parser.error_msg("Expected single number or range of numbers.", + CParser::OT_CONTINUE); + break; + } + } + } + + // Process other identifiers + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + break; + case 13: //all + this->SetAll(true); + break; + default: + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input reading DELETE definition.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + return_value = false; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + return(return_value); +} \ No newline at end of file diff --git a/StorageBinList.h b/StorageBinList.h new file mode 100644 index 00000000..66fc52e7 --- /dev/null +++ b/StorageBinList.h @@ -0,0 +1,55 @@ +#if !defined(STORAGEBINLIST_H_INCLUDED) +#define STORAGEBINLIST_H_INCLUDED +#include // std::set +#include // std::string +#include // std::list +#include // std::vector +#include "Parser.h" +class StorageBinListItem +{ +public: + StorageBinListItem(void); + ~StorageBinListItem(void); + void Set_defined(bool tf) { this->defined = tf; }; + bool Get_defined(void) { return(this->defined); }; + void Augment(std::string token); + std::set < int > &Get_numbers(void) { return(this->numbers); }; + void Clear(void) { this->numbers.clear(); }; +protected: + std::set < int > numbers; + bool defined; +}; +class StorageBinList +{ +public: + StorageBinList(void); + StorageBinList(CParser & parser); + ~StorageBinList(void); + bool Read(CParser & parser); + void SetAll(bool tf); + + StorageBinListItem & Get_solution(void) { return(this->solution); }; + StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; + StorageBinListItem & Get_exchange(void) { return(this->exchange); }; + StorageBinListItem & Get_surface(void) { return(this->surface); }; + StorageBinListItem & Get_s_s_assemblage(void) { return(this->s_s_assemblage); }; + StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; + StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; + StorageBinListItem & Get_mix(void) { return(this->mix); }; + StorageBinListItem & Get_reaction(void) { return(this->reaction); }; + StorageBinListItem & Get_temperature(void) { return(this->temperature); }; +protected: + StorageBinListItem solution; + StorageBinListItem pp_assemblage; + StorageBinListItem exchange; + StorageBinListItem surface; + StorageBinListItem s_s_assemblage; + StorageBinListItem gas_phase; + StorageBinListItem kinetics; + StorageBinListItem mix; + StorageBinListItem reaction; + StorageBinListItem temperature; +}; + + +#endif // !defined(STORAGEBINLIST_H_INCLUDED) \ No newline at end of file From 2fd35ce463f10bcdab152cabd717aa03eac4b0b6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 23 Oct 2009 00:03:23 +0000 Subject: [PATCH 0096/1077] Delete, Dump seem to work. SOLUTION_MODIFY seems to work, but need to check all features. EQUILIBRIUM_PHASES_MODIFY fails. Need to use maps to allow update I think. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3719 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.h | 2 +- Parser.cxx | 25 +++++++++++++++--- ReadClass.cxx | 71 ++++++++++++++++++++++++++------------------------ dumper.cpp | 63 +++++++++++++++++++++++++++++--------------- 4 files changed, 101 insertions(+), 60 deletions(-) diff --git a/PPassemblage.h b/PPassemblage.h index 096edadb..c8099174 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -59,7 +59,7 @@ class cxxPPassemblage:public cxxNumKeyword void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: - std::list < cxxPPassemblageComp > ppAssemblageComps; + std::list < cxxPPassemblageComp > ppAssemblageComps; cxxNameDouble eltList; cxxNameDouble totals; diff --git a/Parser.cxx b/Parser.cxx index ed3cf4cd..b4a4f08d 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -816,17 +816,34 @@ CParser::get_option(const std::vector < std::string > &opt_list, } else { - pos_ptr = 0; - copy_token(option, pos_ptr); + //pos_ptr = 0; + //copy_token(option, pos_ptr); + //if (find_option(option, &opt, opt_list, true) == FT_OK) + //{ + // j = opt; + // next_pos = pos_ptr; + //} + //else + //{ + // j = OPT_DEFAULT; + // next_pos = 0; + //} + + //std::istringstream m_line_iss_copy = m_line_iss; + pos_ptr = m_line_iss.tellg(); + m_line_iss >> option; if (find_option(option, &opt, opt_list, true) == FT_OK) { j = opt; - next_pos = pos_ptr; + next_pos = m_line_iss.tellg(); } else { j = OPT_DEFAULT; - next_pos = 0; + m_line_iss.seekg(pos_ptr); + m_line_iss.clear(); + next_pos = pos_ptr; + //m_line_iss >> option; } /* if (true) // pr.echo_input == TRUE diff --git a/ReadClass.cxx b/ReadClass.cxx index e0b15206..d0450ff5 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1105,6 +1105,24 @@ read_solution_modify(void) * */ int return_value; + + // find solution 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 solution number following SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1130,23 +1148,7 @@ read_solution_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find solution 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 solution number following SOLUTION_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } + if (solution_bsearch(n_user, &n, FALSE) == NULL) { input_error++; @@ -1190,6 +1192,24 @@ read_equilibrium_phases_modify(void) * */ int return_value; + + // find equilibrium_phases 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 equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1215,23 +1235,6 @@ read_equilibrium_phases_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find equilibrium_phases 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 equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } if (pp_assemblage_bsearch(n_user, &n) == NULL) { input_error++; diff --git a/dumper.cpp b/dumper.cpp index 865a0a92..e3caf53e 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -243,20 +243,24 @@ bool dumper::Read(CParser & parser) static std::vector < std::string > vopts; if (vopts.empty()) { - vopts.reserve(15); + vopts.reserve(20); vopts.push_back("solution"); + vopts.push_back("solutions"); vopts.push_back("pp_assemblage"); + vopts.push_back("pp_assemblages"); + vopts.push_back("equilibrium_phase"); vopts.push_back("equilibrium_phases"); vopts.push_back("exchange"); vopts.push_back("surface"); vopts.push_back("s_s_assemblage"); + vopts.push_back("solid_solution"); + vopts.push_back("solid_solutions"); vopts.push_back("gas_phase"); + vopts.push_back("gas_phases"); vopts.push_back("kinetics"); vopts.push_back("file"); vopts.push_back("append"); vopts.push_back("all"); - vopts.push_back("on"); - vopts.push_back("off"); } std::istream::pos_type ptr; @@ -284,44 +288,55 @@ bool dumper::Read(CParser & parser) } // Select StorageBinListItem - StorageBinListItem &item(binList.Get_solution()); + StorageBinListItem *item; switch (opt) { case 0: - item = this->binList.Get_solution(); - break; case 1: + item = &(this->binList.Get_solution()); + break; case 2: - item = this->binList.Get_pp_assemblage(); - break; case 3: - item = this->binList.Get_exchange(); - break; case 4: - item = this->binList.Get_surface(); - break; case 5: - item = this->binList.Get_s_s_assemblage(); + item = &(this->binList.Get_pp_assemblage()); break; case 6: - item = this->binList.Get_gas_phase(); + item = &(this->binList.Get_exchange()); break; case 7: - item = this->binList.Get_kinetics(); + item = &(this->binList.Get_surface()); + break; + case 8: + case 9: + case 10: + item = &(this->binList.Get_s_s_assemblage()); + break; + case 11: + case 12: + item = &(this->binList.Get_gas_phase()); + break; + case 13: + item = &(this->binList.Get_kinetics()); break; default: break; } // Read dump entity list of numbers or number ranges for line, store in item - if (opt >= 0 && opt <= 7) + if (opt >= 0 && opt <= 13) { for (;;) { CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY || j == CParser::TT_DIGIT) + if (j == CParser::TT_DIGIT) { - item.Augment(token); + item->Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + item->Augment(token); + break; } else { @@ -348,8 +363,14 @@ bool dumper::Read(CParser & parser) case 5: case 6: case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: break; - case 8: //file + case 14: //file std::getline(parser.get_iss(), this->file_name); this->file_name = trim(this->file_name, " \t"); if (this->file_name.size() == 0) @@ -358,7 +379,7 @@ bool dumper::Read(CParser & parser) } break; - case 9: //append + case 15: //append { CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); //if (!(parser.get_iss() >> this->append)) @@ -369,7 +390,7 @@ bool dumper::Read(CParser & parser) } } break; - case 10: //all + case 16: //all this->SetAll(true); break; default: From cbfb76838106fb72ff4badaa4f78cbfddae31b4e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Oct 2009 16:38:25 +0000 Subject: [PATCH 0097/1077] Initial testing of SOLUTION_MODIFY and EQUILIBRIUM_PHASES_MODIFY. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3721 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.cxx | 58 +++++++++++------ PPassemblage.h | 3 +- PPassemblageComp.cxx | 152 +++++++++++++++++++++---------------------- PPassemblageComp.h | 6 +- Parser.h | 12 ++++ ReadClass.cxx | 1 + Solution.cxx | 73 +++++++++++---------- 7 files changed, 171 insertions(+), 134 deletions(-) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 02ef3ead..d33096a6 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -44,7 +44,9 @@ eltList(pp_assemblage_ptr->next_elt) for (i = 0; i < pp_assemblage_ptr->count_comps; i++) { cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i])); - ppAssemblageComps.push_back(ppComp); + //ppAssemblageComps.push_back(ppComp); + std::string str(ppComp.get_name()); + this->ppAssemblageComps[str] = ppComp; } } cxxPPassemblage::cxxPPassemblage(const std::map < int, @@ -90,8 +92,7 @@ cxxPPassemblage::cxxPPassemblage2pp_assemblage() pp_assemblage_ptr->pure_phases = (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); pp_assemblage_ptr->pure_phases = - cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this-> - ppAssemblageComps); + cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps); pp_assemblage_ptr->next_elt = this->eltList.elt_list(); return (pp_assemblage_ptr); } @@ -120,10 +121,10 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const // ppAssemblageComps s_oss << indent1; s_oss << "::const_iterator it = + for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); + (*it).second.dump_xml(s_oss, indent + 2); } } @@ -153,12 +154,12 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const this->eltList.dump_raw(s_oss, indent + 2); // ppAssemblagComps - for (std::list < cxxPPassemblageComp >::const_iterator it = + for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } } @@ -229,9 +230,28 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) case 1: // component { + std::istream::pos_type pos = parser.tellg(); cxxPPassemblageComp ppComp; - ppComp.read_raw(parser); - this->ppAssemblageComps.push_back(ppComp); + ppComp.read_raw(parser, false); + + + if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end()) + { + cxxPPassemblageComp & comp = ppAssemblageComps.find(ppComp.get_name())->second; + parser.seekg(pos).clear(); + parser.seekg(pos); + comp.read_raw(parser, false); + int i=1; + } + else + { + parser.seekg(pos).clear(); + parser.seekg(pos); + cxxPPassemblageComp ppComp1; + ppComp1.read_raw(parser, false); + std::string str(ppComp1.get_name()); + this->ppAssemblageComps[str] = ppComp1; + } } useLastLine = true; break; @@ -292,11 +312,11 @@ cxxPPassemblage::totalize() { this->totals.clear(); // component structures - for (std::list < cxxPPassemblageComp >::iterator it = + for (std::map < std::string, cxxPPassemblageComp >::iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { - it->totalize(); - this->totals.add_extensive(it->get_totals(), 1.0); + (*it).second.totalize(); + this->totals.add_extensive((*it).second.get_totals(), 1.0); } return; } @@ -310,27 +330,27 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) if (extensive == 0.0) return; //std::list ppAssemblageComps; - for (std::list < cxxPPassemblageComp >::const_iterator itadd = - addee.ppAssemblageComps.begin(); + for (std::map < std::string, cxxPPassemblageComp >::const_iterator itadd = addee.ppAssemblageComps.begin(); itadd != addee.ppAssemblageComps.end(); ++itadd) { bool found = false; - for (std::list < cxxPPassemblageComp >::iterator it = + for (std::map < std::string, cxxPPassemblageComp >::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) { - if (it->get_name() == itadd->get_name()) + if ((*it).second.get_name() == itadd->second.get_name()) { - it->add((*itadd), extensive); + (*it).second.add((*itadd).second, extensive); found = true; break; } } if (!found) { - cxxPPassemblageComp entity = *itadd; + cxxPPassemblageComp entity = (*itadd).second; entity.multiply(extensive); - this->ppAssemblageComps.push_back(entity); + std::string str(entity.get_name()); + this->ppAssemblageComps[str] = entity; } } //cxxNameDouble eltList; diff --git a/PPassemblage.h b/PPassemblage.h index c8099174..c44c7aac 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -59,7 +59,8 @@ class cxxPPassemblage:public cxxNumKeyword void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: - std::list < cxxPPassemblageComp > ppAssemblageComps; + //std::list < cxxPPassemblageComp > ppAssemblageComps; + std::map ppAssemblageComps; cxxNameDouble eltList; cxxNameDouble totals; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 8c7526e0..3ef2bf53 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -64,8 +64,7 @@ cxxPPassemblageComp::get_phase() } struct pure_phase * -cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list < - cxxPPassemblageComp > &el) + cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::map < std::string, cxxPPassemblageComp > &el) // // Builds pure_phase structure from of cxxPPassemblageComp // @@ -77,19 +76,19 @@ cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::list < malloc_error(); int i = 0; - for (std::list < cxxPPassemblageComp >::iterator it = el.begin(); + for (std::map < std::string, cxxPPassemblageComp >::iterator it = el.begin(); it != el.end(); ++it) { - pure_phase_ptr[i].phase = it->get_phase(); - pure_phase_ptr[i].name = it->name; - pure_phase_ptr[i].add_formula = it->add_formula; - pure_phase_ptr[i].si = it->si; - pure_phase_ptr[i].moles = it->moles; - pure_phase_ptr[i].delta = it->delta; - pure_phase_ptr[i].initial_moles = it->initial_moles; - pure_phase_ptr[i].force_equality = (int) it->force_equality; - pure_phase_ptr[i].dissolve_only = (int) it->dissolve_only; - pure_phase_ptr[i].precipitate_only = (int) it->precipitate_only; + pure_phase_ptr[i].phase = (*it).second.get_phase(); + pure_phase_ptr[i].name = (*it).second.name; + pure_phase_ptr[i].add_formula = (*it).second.add_formula; + pure_phase_ptr[i].si = (*it).second.si; + pure_phase_ptr[i].moles = (*it).second.moles; + pure_phase_ptr[i].delta = (*it).second.delta; + pure_phase_ptr[i].initial_moles = (*it).second.initial_moles; + pure_phase_ptr[i].force_equality = (int) (*it).second.force_equality; + pure_phase_ptr[i].dissolve_only = (int) (*it).second.dissolve_only; + pure_phase_ptr[i].precipitate_only = (int) (*it).second.precipitate_only; i++; } return (pure_phase_ptr); @@ -148,23 +147,19 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "-name " << this-> name << std::endl; if (this->add_formula != NULL) - s_oss << indent0 << "-add_formula " << this-> + s_oss << indent1 << "-add_formula " << this-> add_formula << std::endl; - s_oss << indent0 << "-si " << this->si << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-delta " << this->delta << std::endl; - s_oss << indent0 << "-initial_moles " << this-> - initial_moles << std::endl; - s_oss << indent0 << "-force_equality " << this-> - force_equality << std::endl; - s_oss << indent0 << "-dissolve_only " << this-> - dissolve_only << std::endl; - s_oss << indent0 << "-precipitate_only " << this-> - precipitate_only << std::endl; + s_oss << indent1 << "-si " << this->si << std::endl; + s_oss << indent1 << "-moles " << this->moles << std::endl; + s_oss << indent1 << "-delta " << this->delta << std::endl; + s_oss << indent1 << "-initial_moles " << this->initial_moles << std::endl; + s_oss << indent1 << "-force_equality " << this->force_equality << std::endl; + s_oss << indent1 << "-dissolve_only " << this->dissolve_only << std::endl; + s_oss << indent1 << "-precipitate_only " << this->precipitate_only << std::endl; } void -cxxPPassemblageComp::read_raw(CParser & parser) +cxxPPassemblageComp::read_raw(CParser & parser, bool check) { std::string str; @@ -339,60 +334,63 @@ cxxPPassemblageComp::read_raw(CParser & parser) break; } // members that must be defined - if (name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Name not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - if (si_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Si not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - if (delta_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Delta not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - if (initial_moles_defined == false) + if (check) { + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (si_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Si not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (delta_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Delta not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (initial_moles_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Initial_moles not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + if (dissolve_only_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Dissolve_only not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + /* don't check to maintain backward compatibility + if (precipitate_only_defined == false) + { parser.incr_input_error(); parser. - error_msg("Initial_moles not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - if (dissolve_only_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Dissolve_only not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - /* don't check to maintain backward compatibility - if (precipitate_only_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Precipitate_only not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); - } - */ - if (force_equality_defined == false) - { - parser.incr_input_error(); - parser. - error_msg - ("Force_equality not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + error_msg("Precipitate_only not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } + */ + if (force_equality_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Force_equality not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } } } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 4694e97c..cc764885 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -21,15 +21,13 @@ class cxxPPassemblageComp ~cxxPPassemblageComp(); - static struct pure_phase *cxxPPassemblageComp2pure_phase(std::list < - cxxPPassemblageComp - > &el); + static struct pure_phase *cxxPPassemblageComp2pure_phase(std::map < std::string, cxxPPassemblageComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) 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_name() const { diff --git a/Parser.h b/Parser.h index ce6472a6..7a12b608 100644 --- a/Parser.h +++ b/Parser.h @@ -169,6 +169,17 @@ class CParser return m_input_error; } + std::istream::pos_type tellg() + { + return m_input_stream.tellg(); + } + std::istream& seekg(std::istream::pos_type p) + { + return m_input_stream.seekg(p); + } + + + /** Copies from begin to token until first space is encountered. @@ -298,4 +309,5 @@ inline std::string trim(const std::string& source, const std::string& t = " \t") std::string str = source; return trim_left( trim_right( str , t) , t ); } + #endif // PARSER_H_INCLUDED diff --git a/ReadClass.cxx b/ReadClass.cxx index d0450ff5..87ea75a6 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1252,6 +1252,7 @@ read_equilibrium_phases_modify(void) pp_assemblage_free(&(pp_assemblage[n])); pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); pp_assemblage_free(entity_ptr); + free_check_null(entity_ptr); // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); diff --git a/Solution.cxx b/Solution.cxx index 1a5fe63f..9cb70ca5 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -454,9 +454,49 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "SOLUTION_RAW " << this->n_user << " " << this-> description << std::endl; + s_oss << "# Critical values" << std::endl; + s_oss << indent1; s_oss << "-temp " << this->tc << std::endl; + // new identifier + s_oss << indent1; + s_oss << "-total_h " << this->total_h << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-total_o " << this->total_o << std::endl; + + // new identifier + s_oss << indent1; + s_oss << "-cb " << this->cb << std::endl; + + // soln_total conc structures + s_oss << indent1; + s_oss << "-totals" << std::endl; + this->totals.dump_raw(s_oss, indent + 2); + + s_oss << "# Optional critical values" << std::endl; + + // Isotopes + s_oss << indent1; + s_oss << "-Isotopes" << std::endl; + { + for (std::list < cxxSolutionIsotope >::const_iterator it = + this->isotopes.begin(); it != isotopes.end(); ++it) + { + it->dump_raw(s_oss, indent + 2); + } + } + /* + for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { + s_oss << indent2; + s_oss << it->first << " " << it->second << std::endl; + } + */ + + s_oss << "# Non-critical values" << std::endl; + s_oss << indent1; s_oss << "-pH " << this->ph << std::endl; @@ -471,18 +511,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "-ah2o " << this->ah2o << std::endl; - // new identifier - s_oss << indent1; - s_oss << "-total_h " << this->total_h << std::endl; - - // new identifier - s_oss << indent1; - s_oss << "-total_o " << this->total_o << std::endl; - - // new identifier - s_oss << indent1; - s_oss << "-cb " << this->cb << std::endl; - // new identifier s_oss << indent1; s_oss << "-mass_water " << this->mass_water << std::endl; @@ -491,17 +519,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - // soln_total conc structures - s_oss << indent1; - s_oss << "-totals" << std::endl; - this->totals.dump_raw(s_oss, indent + 2); - /* - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - */ - // master_activity map s_oss << indent1; s_oss << "-activities" << std::endl; @@ -528,16 +545,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const } } */ - // Isotopes - s_oss << indent1; - s_oss << "-Isotopes" << std::endl; - { - for (std::list < cxxSolutionIsotope >::const_iterator it = - this->isotopes.begin(); it != isotopes.end(); ++it) - { - it->dump_raw(s_oss, indent + 2); - } - } return; } From b9e38f4da8e239ef4410e2ec4d0b32e5787b5d86 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Oct 2009 20:29:04 +0000 Subject: [PATCH 0098/1077] Updated phreeqcpp to have examples from phreeqc. equilibrium_phases_read_raw has duplicate lines. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3724 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 49 ++++++++++++++++++++++++++++++++++------------ PPassemblage.cxx | 5 +++-- ReadClass.cxx | 17 ++++++++-------- StorageBinList.cpp | 13 ++++++------ StorageBinList.h | 2 +- Utils.cxx | 3 +++ dumper.cpp | 2 +- dumper.h | 2 +- 8 files changed, 60 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index dbc52345..ec0ea045 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ debug: # ============================================================================= #SRC = ../phreeqc -.SUFFIXES : .o .c .cxx +.SUFFIXES : .o .c .cxx .cpp # compilers @@ -70,6 +70,9 @@ debug: .cxx.o : ${CXX} ${CXXFLAGS} -c -o $@ $< +.cpp.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< + # ----------------------------------------------------------------------------- #hdf options #HDF5_ROOT=$(HOME)/../../usr @@ -149,6 +152,7 @@ COMMON_COBJS = \ print.o \ read.o \ readtr.o \ + sit.o \ smalldense.o \ spread.o \ step.o \ @@ -160,6 +164,7 @@ COMMON_COBJS = \ utilities.o COMMON_CXXOBJS = \ + dumper.o \ Exchange.o \ ExchComp.o \ GasPhase.o \ @@ -181,6 +186,7 @@ COMMON_CXXOBJS = \ SSassemblage.o \ SSassemblageSS.o \ StorageBin.o \ + StorageBinList.o \ Surface.o \ SurfaceCharge.o \ SurfaceComp.o \ @@ -220,7 +226,9 @@ Exchange.o: ../Exchange.cxx ../Utils.h ../char_star.h ../Exchange.h \ ../phreeqc/phrqproto.h ../phreeqc/output.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../char_star.h ../ExchComp.h \ ../NameDouble.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../char_star.h ../GasPhase.h \ ../NumKeyword.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../cxxMix.h ../phreeqc/phqalloc.h \ @@ -237,18 +245,23 @@ ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ ../NameDouble.h ../cxxMix.h ../phreeqc/output.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../char_star.h \ ../KineticsComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../char_star.h ../NameDouble.h \ - ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Parser.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/output.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ ../char_star.h Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ ../phreeqc/output.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../char_star.h \ ../PPassemblageComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../char_star.h \ ../PPassemblage.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ ../phreeqc/phrqtype.h ../PPassemblageComp.h ../NameDouble.h ../cxxMix.h \ @@ -263,7 +276,8 @@ ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ ../phreeqc/phrqproto.h ../SurfaceCharge.h ../PPassemblage.h \ ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ ../SSassemblage.h ../SSassemblageSS.h ../GasPhase.h ../Reaction.h \ - ../Temperature.h ../phreeqc/phqalloc.h ../phreeqc/output.h + ../Temperature.h ../dumper.h ../StorageBinList.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h SAXPhreeqc.o: ../SAXPhreeqc.cxx ../SAXPhreeqc.h ../SaxPhreeqcHandlers.h \ ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h @@ -289,7 +303,9 @@ SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../char_star.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../char_star.h \ ../SSassemblageSS.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../char_star.h ../StorageBin.h \ ../Parser.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../Exchange.h \ @@ -301,11 +317,14 @@ StorageBin.o: ../StorageBin.cxx ../Utils.h ../char_star.h ../StorageBin.h \ ../phreeqc/output.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../char_star.h \ ../SurfaceCharge.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/output.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../char_star.h \ ../SurfaceComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../cxxMix.h ../phreeqc/phqalloc.h \ ../phreeqc/output.h Surface.o: ../Surface.cxx ../Utils.h ../char_star.h ../Surface.h \ ../NumKeyword.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ @@ -324,6 +343,10 @@ Temperature.o: ../Temperature.cxx ../Utils.h ../char_star.h \ ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Utils.o: ../Utils.cxx ../Utils.h ../char_star.h ../Parser.h \ ../phreeqc/output.h +dumper.o: ../dumper.cpp ../dumper.h ../Parser.h ../char_star.h \ + ../StorageBinList.h +StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h ../Parser.h \ + ../char_star.h # # PHREEQC files # @@ -435,7 +458,7 @@ clean: dependencies: mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx + cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index d33096a6..884672e0 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -232,8 +232,10 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) { std::istream::pos_type pos = parser.tellg(); cxxPPassemblageComp ppComp; + CParser::ECHO_OPTION eo = parser.get_echo_stream(); + parser.set_echo_stream(CParser::EO_NONE); ppComp.read_raw(parser, false); - + parser.set_echo_stream(eo); if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end()) { @@ -241,7 +243,6 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) parser.seekg(pos).clear(); parser.seekg(pos); comp.read_raw(parser, false); - int i=1; } else { diff --git a/ReadClass.cxx b/ReadClass.cxx index 87ea75a6..5f248eae 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1085,7 +1085,6 @@ read_delete(void) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } -/* /* ---------------------------------------------------------------------- */ int read_solution_modify(void) @@ -1152,7 +1151,7 @@ read_solution_modify(void) if (solution_bsearch(n_user, &n, FALSE) == NULL) { input_error++; - sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1238,7 +1237,7 @@ read_equilibrium_phases_modify(void) if (pp_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1322,7 +1321,7 @@ read_exchange_modify(void) if (exchange_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1405,7 +1404,7 @@ read_surface_modify(void) if (surface_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1488,7 +1487,7 @@ read_solid_solutions_modify(void) if (s_s_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1571,7 +1570,7 @@ read_gas_phase_modify(void) if (gas_phase_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1653,7 +1652,7 @@ read_kinetics_modify(void) if (kinetics_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n%s\n", line_save); + sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n%s\n", n_user, line_save); error_msg(error_string, CONTINUE); return (ERROR); } @@ -2184,4 +2183,4 @@ delete_entities(void) // Turn off delete until next read delete_info.SetAll(false); return (OK); -} \ No newline at end of file +} diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 617d7197..d65f8bf0 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -3,18 +3,18 @@ StorageBinListItem::StorageBinListItem(void) { this->defined = false; -}; +} StorageBinListItem::~StorageBinListItem(void) { -}; +} void StorageBinListItem::Augment(std::string token) { this->defined = true; if (token.size() == 0) return; // split string accounting for possible negative numbers - int pos; + unsigned int pos; if ((pos = token.find("--")) != std::string::npos) { token.replace(pos,2," &"); @@ -55,7 +55,7 @@ void StorageBinListItem::Augment(std::string token) this->numbers.insert(i); } } -}; +} StorageBinList::StorageBinList(void) { } @@ -136,7 +136,7 @@ bool StorageBinList::Read(CParser & parser) } // Select StorageBinListItem - StorageBinListItem *item; + StorageBinListItem *item = NULL; switch (opt) { case 0: @@ -240,4 +240,5 @@ bool StorageBinList::Read(CParser & parser) break; } return(return_value); -} \ No newline at end of file +} + diff --git a/StorageBinList.h b/StorageBinList.h index 66fc52e7..5f0d6db9 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -52,4 +52,4 @@ protected: }; -#endif // !defined(STORAGEBINLIST_H_INCLUDED) \ No newline at end of file +#endif // !defined(STORAGEBINLIST_H_INCLUDED) diff --git a/Utils.cxx b/Utils.cxx index f11f3416..230523c3 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -95,6 +95,7 @@ Utilities::error_msg(const std::string & err_str, const int stop) //+NAN double: 7ff8000000000000 //-NAN double: fff8000000000000 +/* double Utilities::get_nan(void) { unsigned long long raw = 0x7ff0000000000000; @@ -102,3 +103,5 @@ double Utilities::get_nan(void) return(d); } +*/ + diff --git a/dumper.cpp b/dumper.cpp index e3caf53e..7d2d9628 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -288,7 +288,7 @@ bool dumper::Read(CParser & parser) } // Select StorageBinListItem - StorageBinListItem *item; + StorageBinListItem *item = NULL; switch (opt) { case 0: diff --git a/dumper.h b/dumper.h index dde23e84..f951aa96 100644 --- a/dumper.h +++ b/dumper.h @@ -38,4 +38,4 @@ protected: StorageBinList binList; }; -#endif // !defined(DUMPER_H_INCLUDED) \ No newline at end of file +#endif // !defined(DUMPER_H_INCLUDED) From f015759286b56643980076b384518046e407c23a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Oct 2009 22:57:49 +0000 Subject: [PATCH 0099/1077] 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 --- ExchComp.cxx | 132 ++++++++++++++++++++++++----------------------- ExchComp.h | 4 +- Exchange.cxx | 104 ++++++++++++++++++++++++++++++------- Exchange.h | 4 +- PPassemblage.cxx | 13 +++-- ReadClass.cxx | 45 +++++++++------- Solution.cxx | 6 +-- 7 files changed, 196 insertions(+), 112 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 5e40a254..959837ad 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -188,7 +188,7 @@ cxxExchComp::get_master() } 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 // @@ -200,20 +200,20 @@ cxxExchComp::cxxExchComp2exch_comp(std::list < cxxExchComp > &el) malloc_error(); 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) { - exch_comp_ptr[i].formula = it->formula; - exch_comp_ptr[i].formula_z = it->formula_z; - exch_comp_ptr[i].totals = it->totals.elt_list(); - exch_comp_ptr[i].moles = it->moles; - exch_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); - exch_comp_ptr[i].la = it->la; - exch_comp_ptr[i].charge_balance = it->charge_balance; - exch_comp_ptr[i].phase_name = it->phase_name; - exch_comp_ptr[i].phase_proportion = it->phase_proportion; - exch_comp_ptr[i].rate_name = it->rate_name; - exch_comp_ptr[i].master = it->get_master(); + exch_comp_ptr[i].formula = (*it).second.formula; + exch_comp_ptr[i].formula_z = (*it).second.formula_z; + exch_comp_ptr[i].totals = (*it).second.totals.elt_list(); + exch_comp_ptr[i].moles = (*it).second.moles; + exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); + exch_comp_ptr[i].la = (*it).second.la; + exch_comp_ptr[i].charge_balance = (*it).second.charge_balance; + exch_comp_ptr[i].phase_name = (*it).second.phase_name; + exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; + exch_comp_ptr[i].rate_name = (*it).second.rate_name; + exch_comp_ptr[i].master = (*it).second.get_master(); i++; } return (exch_comp_ptr); @@ -282,40 +282,41 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Exch_Comp element and attributes - s_oss << indent0 << "-formula " << this-> - formula << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-la " << this->la << std::endl; - s_oss << indent0 << "-charge_balance " << this-> - charge_balance << std::endl; + s_oss << indent0 << "-formula " << this->formula << std::endl; + + //s_oss << indent1 << "# critical values" << std::endl; + + // totals + 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) { - s_oss << indent0 << "-phase_name " << this-> - phase_name << std::endl; + s_oss << indent1 << "-phase_name " << this->phase_name << std::endl; } if (this->rate_name != NULL) { - s_oss << indent0 << "-rate_name " << this-> - rate_name << std::endl; + s_oss << indent1 << "-rate_name " << this->rate_name << std::endl; } - s_oss << indent0 << "-phase_proportion " << this-> - phase_proportion << 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); + s_oss << indent1 << "-phase_proportion " << this->phase_proportion << std::endl; + s_oss << indent1 << "-formula_z " << this->formula_z << std::endl; // formula_totals - s_oss << indent0; + s_oss << indent1; 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 -cxxExchComp::read_raw(CParser & parser) +cxxExchComp::read_raw(CParser & parser, bool check) { std::string str; @@ -496,36 +497,39 @@ cxxExchComp::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (formula_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Formula not defined for ExchComp input.", - CParser::OT_CONTINUE); - } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for ExchComp input.", - CParser::OT_CONTINUE); - } - if (la_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La not defined for ExchComp input.", - CParser::OT_CONTINUE); - } - if (charge_balance_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for ExchComp input.", - CParser::OT_CONTINUE); - } - if (formula_z_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Formula_z not defined for ExchComp input.", - CParser::OT_CONTINUE); + // members that must be defined + if (formula_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (la_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (formula_z_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", + CParser::OT_CONTINUE); + } } } void diff --git a/ExchComp.h b/ExchComp.h index 353b496a..2cb543d8 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -22,14 +22,14 @@ class cxxExchComp 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); void dump_xml(std::ostream & os, unsigned int indent = 0) 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 { diff --git a/Exchange.cxx b/Exchange.cxx index c16043a7..e16f6ecc 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -46,7 +46,8 @@ cxxNumKeyword() for (i = 0; i < exchange_ptr->count_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); // 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 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) { - if (it->get_phase_name() == NULL) + if ((*it).second.get_phase_name() == NULL) continue; return (true); } @@ -185,10 +187,10 @@ cxxExchange::get_related_phases() bool 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) { - if (it->get_rate_name() == NULL) + if ((*it).second.get_rate_name() == NULL) continue; return (true); } @@ -213,8 +215,7 @@ cxxExchange::cxxExchange2exchange() exchange_ptr->related_rate = (int) this->get_related_rate(); exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; exchange_ptr->count_comps = (int) this->exchComps.size(); - exchange_ptr->comps = - (struct exch_comp *) free_check_null(exchange_ptr->comps); + exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps); exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); return (exchange_ptr); } @@ -244,10 +245,10 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const // components s_oss << indent1; s_oss << "::const_iterator it = exchComps.begin(); + for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); + (*it).second.dump_xml(s_oss, indent + 2); } return; @@ -277,12 +278,12 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const pitzer_exchange_gammas << std::endl; // 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) { s_oss << indent1; s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } return; @@ -353,8 +354,33 @@ cxxExchange::read_raw(CParser & parser, bool check) case 1: // component { 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; break; @@ -375,6 +401,7 @@ cxxExchange::read_raw(CParser & parser, bool check) } } } +#ifdef SKIP void cxxExchange::add(const cxxExchange & addee, double extensive) // @@ -410,7 +437,48 @@ cxxExchange::add(const cxxExchange & addee, double extensive) //bool 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 /* ---------------------------------------------------------------------- */ void @@ -461,11 +529,11 @@ cxxExchange::totalize() { this->totals.clear(); // 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) { - this->totals.add_extensive(it->get_totals(), 1.0); - this->totals.add("Charge", it->get_charge_balance()); + this->totals.add_extensive((*it).second.get_totals(), 1.0); + this->totals.add("Charge", (*it).second.get_charge_balance()); } return; } diff --git a/Exchange.h b/Exchange.h index af23f7af..eab812e0 100644 --- a/Exchange.h +++ b/Exchange.h @@ -43,7 +43,7 @@ class cxxExchange:public cxxNumKeyword this->pitzer_exchange_gammas = b; } - std::list < cxxExchComp > &get_exchComps(void) + std::map < std::string, cxxExchComp > &get_exchComps(void) { return (this->exchComps); } @@ -64,7 +64,7 @@ class cxxExchange:public cxxNumKeyword void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: - std::list < cxxExchComp > exchComps; + std::map < std::string, cxxExchComp > exchComps; bool pitzer_exchange_gammas; cxxNameDouble totals; public: diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 884672e0..4417c2a0 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -230,16 +230,21 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) case 1: // component { - std::istream::pos_type pos = parser.tellg(); 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); 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()) { - cxxPPassemblageComp & comp = ppAssemblageComps.find(ppComp.get_name())->second; + cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ppComp.get_name())->second; parser.seekg(pos).clear(); parser.seekg(pos); comp.read_raw(parser, false); diff --git a/ReadClass.cxx b/ReadClass.cxx index 5f248eae..bb45031b 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -373,8 +373,7 @@ read_equilibrium_phases_raw(void) cxxPPassemblage ex; ex.read_raw(parser); - struct pp_assemblage *pp_assemblage_ptr = - ex.cxxPPassemblage2pp_assemblage(); + struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(); int n; /* @@ -1250,6 +1249,8 @@ read_equilibrium_phases_modify(void) struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(); pp_assemblage_free(&(pp_assemblage[n])); 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); free_check_null(entity_ptr); @@ -1276,6 +1277,25 @@ read_exchange_modify(void) * */ 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 */ @@ -1301,23 +1321,6 @@ read_exchange_modify(void) 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) { input_error++; @@ -1334,7 +1337,11 @@ read_exchange_modify(void) struct exchange *entity_ptr = entity.cxxExchange2exchange(); exchange_free(&(exchange[n])); 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); + free_check_null(entity_ptr); + // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); diff --git a/Solution.cxx b/Solution.cxx index 9cb70ca5..4ee96859 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -454,7 +454,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "SOLUTION_RAW " << this->n_user << " " << this-> description << std::endl; - s_oss << "# Critical values" << std::endl; + //s_oss << "# Critical values" << std::endl; s_oss << indent1; 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; this->totals.dump_raw(s_oss, indent + 2); - s_oss << "# Optional critical values" << std::endl; + //s_oss << "# Optional critical values" << std::endl; // Isotopes 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 << "-pH " << this->ph << std::endl; From d54c04039a344c724947c0dcae7b8c2b7a04ab78 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 28 Oct 2009 19:15:17 +0000 Subject: [PATCH 0100/1077] Have converted std::list to std::map for all entities. surface is completed but needs testing. SS and kinetics need to have reread of components implemented for MODIFY option. gas_phase may be done, needs to be tested. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3726 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.h | 2 +- KineticsComp.cxx | 29 ++++---- KineticsComp.h | 10 ++- ReadClass.cxx | 35 ++++----- SSassemblage.cxx | 48 ++++++++++--- SSassemblage.h | 16 ++--- SSassemblageSS.cxx | 30 ++++---- SSassemblageSS.h | 2 +- Surface.cxx | 164 +++++++++++++++++++++++++++++++++++------- Surface.h | 4 +- SurfaceCharge.cxx | 175 +++++++++++++++++++++++---------------------- SurfaceCharge.h | 6 +- SurfaceComp.cxx | 143 ++++++++++++++++++------------------ SurfaceComp.h | 6 +- cxxKinetics.cxx | 52 ++++++++++++-- cxxKinetics.h | 4 +- 16 files changed, 458 insertions(+), 268 deletions(-) diff --git a/GasPhase.h b/GasPhase.h index 8b40b860..2fa6e96b 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -56,7 +56,7 @@ class cxxGasPhase:public cxxNumKeyword void add(const cxxGasPhase & addee, double extensive); protected: - cxxNameDouble gasPhaseComps; + cxxNameDouble gasPhaseComps; GP_TYPE type; double total_p; double volume; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 2d5a3eab..61461cbf 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -55,7 +55,7 @@ cxxKineticsComp::~cxxKineticsComp() } struct kinetics_comp * -cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > + cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::map < std::string, cxxKineticsComp > &el) // // Builds kinetics_comp structure from of cxxKineticsComp @@ -68,17 +68,17 @@ cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > malloc_error(); int i = 0; - for (std::list < cxxKineticsComp >::iterator it = el.begin(); + for (std::map < std::string, cxxKineticsComp >::iterator it = el.begin(); it != el.end(); ++it) { - kinetics_comp_ptr[i].rate_name = it->rate_name; - kinetics_comp_ptr[i].list = it->namecoef.name_coef(); - kinetics_comp_ptr[i].count_list = (int) it->namecoef.size(); - kinetics_comp_ptr[i].tol = it->tol; - kinetics_comp_ptr[i].m = it->m; + kinetics_comp_ptr[i].rate_name = (*it).second.rate_name; + kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef(); + kinetics_comp_ptr[i].count_list = (int) (*it).second.namecoef.size(); + kinetics_comp_ptr[i].tol = (*it).second.tol; + kinetics_comp_ptr[i].m = (*it).second.m; kinetics_comp_ptr[i].initial_moles = 0.; - kinetics_comp_ptr[i].m0 = it->m0; - kinetics_comp_ptr[i].moles = it->moles; + kinetics_comp_ptr[i].m0 = (*it).second.m0; + kinetics_comp_ptr[i].moles = (*it).second.moles; kinetics_comp_ptr[i].count_c_params = 0; kinetics_comp_ptr[i].c_params = NULL; /* @@ -86,16 +86,15 @@ cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > kinetics_comp_ptr[i].d_params = NULL; */ - kinetics_comp_ptr[i].count_d_params = (int) it->d_params.size(); + kinetics_comp_ptr[i].count_d_params = (int) (*it).second.d_params.size(); kinetics_comp_ptr[i].d_params = NULL; - if (it->d_params.size() > 0) + if ((*it).second.d_params.size() > 0) { - kinetics_comp_ptr[i].d_params = - (double *) - PHRQ_malloc((size_t) (it->d_params.size() * sizeof(double))); + kinetics_comp_ptr[i].d_params = (double *) + PHRQ_malloc((size_t) ((*it).second.d_params.size() * sizeof(double))); if (kinetics_comp_ptr[i].d_params == NULL) malloc_error(); - std::copy(it->d_params.begin(), it->d_params.end(), + std::copy((*it).second.d_params.begin(), (*it).second.d_params.end(), kinetics_comp_ptr[i].d_params); } i++; diff --git a/KineticsComp.h b/KineticsComp.h index c51a62b1..3cf86f58 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -15,14 +15,12 @@ class cxxKineticsComp { - public: +public: cxxKineticsComp(); cxxKineticsComp(struct kinetics_comp *); - ~cxxKineticsComp(); + ~cxxKineticsComp(); - static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::list < - cxxKineticsComp - > &el); + static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::map < std::string, cxxKineticsComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -49,7 +47,7 @@ class cxxKineticsComp double m; double m0; double moles; - std::vector < double >d_params; + std::vector < double >d_params; public: diff --git a/ReadClass.cxx b/ReadClass.cxx index bb45031b..ca860825 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1366,6 +1366,24 @@ read_surface_modify(void) * */ int return_value; + + // find surface 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 surface number following SURFACE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1391,23 +1409,6 @@ read_surface_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find surface 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 surface number following SURFACE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } if (surface_bsearch(n_user, &n) == NULL) { input_error++; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 724426f3..a62ee9de 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -41,7 +41,8 @@ cxxNumKeyword() for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i])); - ssAssemblageSSs.push_back(ssSS); + std::string str(ssSS.get_name()); + ssAssemblageSSs[str] = ssSS; } } cxxSSassemblage::cxxSSassemblage(const std::map < int, @@ -141,12 +142,12 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const description << std::endl; // ssAssemblageSSs - for (std::list < cxxSSassemblageSS >::const_iterator it = + for (std::map < std::string, cxxSSassemblageSS >::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { s_oss << indent1; s_oss << "-solid_solution" << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } } @@ -206,7 +207,8 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) { cxxSSassemblageSS ssSS; ssSS.read_raw(parser); - this->ssAssemblageSSs.push_back(ssSS); + std::string str(ssSS.get_name()); + this->ssAssemblageSSs[str] = ssSS; } useLastLine = true; break; @@ -264,15 +266,15 @@ cxxSSassemblage::totalize() { this->totals.clear(); // component structures - for (std::list < cxxSSassemblageSS >::iterator it = + for (std::map < std::string, cxxSSassemblageSS >::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { - it->totalize(); - this->totals.add_extensive(it->get_totals(), 1.0); + (*it).second.totalize(); + this->totals.add_extensive((*it).second.get_totals(), 1.0); } return; } - +#ifdef SKIP void cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) // @@ -306,3 +308,33 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) } } } +#endif +void +cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) + // + // Add to existing ssassemblage to "this" ssassemblage + // +{ + if (extensive == 0.0) + return; + + for (std::map < std::string, cxxSSassemblageSS >::const_iterator itadd = + addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); + ++itadd) + { + std::map < std::string, cxxSSassemblageSS >::iterator it = + this->ssAssemblageSSs.find((*itadd).first); + if (it != this->ssAssemblageSSs.end()) + { + (*it).second.add((*itadd).second, extensive); + } + else + { + cxxSSassemblageSS entity = (*itadd).second; + entity.multiply(extensive); + std::string str(entity.get_name()); + this->ssAssemblageSSs[str] = entity; + } + } +} + diff --git a/SSassemblage.h b/SSassemblage.h index d3784752..a592c918 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -17,12 +17,12 @@ class cxxSSassemblage:public cxxNumKeyword { - public: +public: cxxSSassemblage(); cxxSSassemblage(struct s_s_assemblage *); - cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, - cxxMix & mx, int n_user); - ~cxxSSassemblage(); + cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, + cxxMix & mx, int n_user); + ~cxxSSassemblage(); struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); @@ -46,14 +46,14 @@ class cxxSSassemblage:public cxxNumKeyword }; - private: +private: void add(const cxxSSassemblage & addee, double extensive); - protected: - std::list < cxxSSassemblageSS > ssAssemblageSSs; +protected: + std::map < std::string, cxxSSassemblageSS > ssAssemblageSSs; cxxNameDouble totals; - public: +public: //static std::map& map; }; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 918c80c3..9a9d2cf7 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -74,7 +74,7 @@ cxxSSassemblageSS::~cxxSSassemblageSS() } struct s_s * -cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > &el) + cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > &el) // // Builds s_s structure from of cxxSSassemblageSS // @@ -88,27 +88,27 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > &el) if (s_s_ptr == NULL) malloc_error(); int j = 0; - for (std::list < cxxSSassemblageSS >::iterator it = el.begin(); + for (std::map < std::string, cxxSSassemblageSS >::iterator it = el.begin(); it != el.end(); ++it) { - s_s_ptr[j].name = it->name; + s_s_ptr[j].name = (*it).second.name; //s_s_ptr[j].total_moles = it->total_moles; s_s_ptr[j].total_moles = 0; s_s_ptr[j].dn = 0; - s_s_ptr[j].a0 = it->a0; - s_s_ptr[j].a1 = it->a1; - s_s_ptr[j].ag0 = it->ag0; - s_s_ptr[j].ag1 = it->ag1; + s_s_ptr[j].a0 = (*it).second.a0; + s_s_ptr[j].a1 = (*it).second.a1; + s_s_ptr[j].ag0 = (*it).second.ag0; + s_s_ptr[j].ag1 = (*it).second.ag1; //s_s_ptr[j].ag0 = 0; //s_s_ptr[j].ag1 = 0; s_s_ptr[j].s_s_in = TRUE; - s_s_ptr[j].miscibility = it->miscibility; + s_s_ptr[j].miscibility = (*it).second.miscibility; //s_s_ptr[j].spinodal = it->spinodal; s_s_ptr[j].spinodal = FALSE; //s_s_ptr[j].tk = it->tk; s_s_ptr[j].tk = 273.15; - s_s_ptr[j].xb1 = it->xb1; - s_s_ptr[j].xb2 = it->xb2; + s_s_ptr[j].xb1 = (*it).second.xb1; + s_s_ptr[j].xb2 = (*it).second.xb2; s_s_ptr[j].input_case = 0; s_s_ptr[j].p[0] = 0; s_s_ptr[j].p[1] = 0; @@ -117,20 +117,20 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > &el) // // generate s_s_comp structures // - s_s_ptr[j].count_comps = (int) it->comps.size(); + s_s_ptr[j].count_comps = (int) (*it).second.comps.size(); s_s_ptr[j].comps = NULL; - if (it->comps.size() > 0) + if ((*it).second.comps.size() > 0) { int i = 0; int n; struct s_s_comp *s_s_comp_ptr = (struct s_s_comp *) PHRQ_malloc((size_t) - (it->comps.size() * sizeof(struct s_s_comp))); + ((*it).second.comps.size() * sizeof(struct s_s_comp))); if (s_s_comp_ptr == NULL) malloc_error(); - for (cxxNameDouble::iterator itc = it->comps.begin(); - itc != it->comps.end(); ++itc) + for (cxxNameDouble::iterator itc = (*it).second.comps.begin(); + itc != (*it).second.comps.end(); ++itc) { s_s_comp_ptr[i].name = itc->first; s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE); diff --git a/SSassemblageSS.h b/SSassemblageSS.h index c999d104..73df9a3f 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -35,7 +35,7 @@ class cxxSSassemblageSS SS_PARM_MARGULES = 9 }; - static struct s_s *cxxSSassemblageSS2s_s(std::list < cxxSSassemblageSS > + static struct s_s *cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/Surface.cxx b/Surface.cxx index 4023d439..e1ed2f24 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -67,13 +67,15 @@ cxxNumKeyword() for (i = 0; i < surface_ptr->count_comps; i++) { cxxSurfaceComp ec(&(surface_ptr->comps[i])); - surfaceComps.push_back(ec); + std::string str(ec.get_formula()); + surfaceComps[str] = ec; } // Surface charge for (i = 0; i < surface_ptr->count_charge; i++) { cxxSurfaceCharge ec(&(surface_ptr->charge[i])); - surfaceCharges.push_back(ec); + std::string str(ec.get_name()); + surfaceCharges[str] = ec; } } cxxSurface::cxxSurface(const std::map < int, cxxSurface > &entities, @@ -113,10 +115,10 @@ cxxSurface::~cxxSurface() bool cxxSurface::get_related_phases() { - for (std::list < cxxSurfaceComp >::const_iterator it = + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if (it->get_phase_name() == NULL) + if ((*it).second.get_phase_name() == NULL) continue; return (true); } @@ -126,10 +128,10 @@ cxxSurface::get_related_phases() bool cxxSurface::get_related_rate() { - for (std::list < cxxSurfaceComp >::const_iterator it = + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if (it->get_rate_name() == NULL) + if ((*it).second.get_rate_name() == NULL) continue; return (true); } @@ -181,8 +183,7 @@ cxxSurface::cxxSurface2surface() { surface_ptr->count_charge = (int) this->surfaceCharges.size(); surface_ptr->charge = - cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this-> - surfaceCharges); + cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); } else { @@ -267,19 +268,19 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "::const_iterator it = + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - it->dump_xml(s_oss, indent + 2); + (*it).second.dump_xml(s_oss, indent + 2); } } // surface charge structures s_oss << indent1; s_oss << "::const_iterator it = + for (std::map < std::string, cxxSurfaceCharge >::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { - it->dump_xml(s_oss, indent + 2); + (*it).second.dump_xml(s_oss, indent + 2); } return; @@ -337,21 +338,21 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "-transport " << this->transport << std::endl; // surfaceComps structures - for (std::list < cxxSurfaceComp >::const_iterator it = + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } // surface charge structures { - for (std::list < cxxSurfaceCharge >::const_iterator it = + for (std::map < std::string, cxxSurfaceCharge >::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { s_oss << indent1; s_oss << "-charge_component " << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } } @@ -507,8 +508,31 @@ cxxSurface::read_raw(CParser & parser, bool check) case 5: // component { cxxSurfaceComp ec; - ec.read_raw(parser); - this->surfaceComps.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); + parser.seekg(pos).clear(); + parser.seekg(pos); + + if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) + { + cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; + comp.read_raw(parser, false); + } + else + { + cxxSurfaceComp ec1; + ec1.read_raw(parser, false); + std::string str(ec1.get_formula()); + this->surfaceComps[str] = ec1; + } } useLastLine = true; break; @@ -516,8 +540,31 @@ cxxSurface::read_raw(CParser & parser, bool check) case 6: // charge_component { cxxSurfaceCharge ec; - ec.read_raw(parser); - this->surfaceCharges.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); + parser.seekg(pos).clear(); + parser.seekg(pos); + + if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) + { + cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; + comp.read_raw(parser, false); + } + else + { + cxxSurfaceCharge ec1; + ec1.read_raw(parser, false); + std::string str(ec1.get_name()); + this->surfaceCharges[str] = ec1; + } } useLastLine = true; break; @@ -775,15 +822,15 @@ cxxSurface::totalize() { this->totals.clear(); // component structures - for (std::list < cxxSurfaceComp >::const_iterator it = + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { - this->totals.add_extensive(it->get_totals(), 1.0); - this->totals.add("Charge", it->get_charge_balance()); + this->totals.add_extensive((*it).second.get_totals(), 1.0); + this->totals.add("Charge", (*it).second.get_charge_balance()); } return; } - +#ifdef SKIP void cxxSurface::add(const cxxSurface & addee, double extensive) // @@ -876,3 +923,72 @@ cxxSurface::add(const cxxSurface & addee, double extensive) } } +#endif +void +cxxSurface::add(const cxxSurface & addee, double extensive) + // + // Add surface to "this" exchange + // +{ + if (extensive == 0.0) + return; + if (this->surfaceComps.size() == 0) + { + //enum SURFACE_TYPE type; + this->type = addee.type; + //enum DIFFUSE_LAYER_TYPE dl_type; + this->dl_type = addee.dl_type; + //enum SITES_UNITS sites_units; + this->sites_units = addee.sites_units; + //bool only_counter_ions; + this->only_counter_ions = addee.only_counter_ions; + //double thickness; + this->thickness = addee.thickness; + //double debye_lengths; + this->debye_lengths = addee.debye_lengths; + //double DDL_viscosity; + this->DDL_viscosity = addee.DDL_viscosity; + //double DDL_limit; + this->DDL_limit = addee.DDL_limit; + //bool transport; + this->transport = addee.transport; + } + + //std::map surfaceComps; + for (std::map < std::string, cxxSurfaceComp >::const_iterator itadd = + addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); + ++itadd) + { + std::map < std::string, cxxSurfaceComp >::iterator it = this->surfaceComps.find((*itadd).first); + if (it != this->surfaceComps.end()) + { + (*it).second.add( (*itadd).second, extensive); + } + else + { + cxxSurfaceComp entity = (*itadd).second; + entity.multiply(extensive); + std::string str(entity.get_formula()); + this->surfaceComps[str] = entity; + } + } + + //std::map < std::string, cxxSurfaceCharge > surfaceCharges; + for (std::map < std::string, cxxSurfaceCharge >::const_iterator itadd = + addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); + ++itadd) + { + std::map < std::string, cxxSurfaceCharge >::iterator it = this->surfaceCharges.find((*itadd).first); + if (it != this->surfaceCharges.end()) + { + (*it).second.add( (*itadd).second, extensive); + } + else + { + cxxSurfaceCharge entity = (*itadd).second; + entity.multiply(extensive); + std::string str(entity.get_name()); + this->surfaceCharges[str] = entity; + } + } +} diff --git a/Surface.h b/Surface.h index 9ad68f5a..983cd88f 100644 --- a/Surface.h +++ b/Surface.h @@ -58,8 +58,8 @@ class cxxSurface:public cxxNumKeyword void add(const cxxSurface & addee, double extensive); protected: - std::list < cxxSurfaceComp > surfaceComps; - std::list < cxxSurfaceCharge > surfaceCharges; + std::map < std::string, cxxSurfaceComp > surfaceComps; + std::map < std::string, cxxSurfaceCharge > surfaceCharges; enum SURFACE_TYPE type; enum DIFFUSE_LAYER_TYPE dl_type; enum SITES_UNITS sites_units; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index de98f183..f7529eaa 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -81,8 +81,7 @@ cxxSurfaceCharge::get_psi_master() } struct surface_charge * -cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list < - cxxSurfaceCharge > &el) + cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el) // // Builds surface_charge structure from of cxxSurfaceCharge // @@ -94,25 +93,24 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list < malloc_error(); int i = 0; - for (std::list < cxxSurfaceCharge >::iterator it = el.begin(); + for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin(); it != el.end(); ++it) { - surf_charge_ptr[i].name = it->name; - surf_charge_ptr[i].specific_area = it->specific_area; - surf_charge_ptr[i].grams = it->grams; - surf_charge_ptr[i].charge_balance = it->charge_balance; - surf_charge_ptr[i].mass_water = it->mass_water; - surf_charge_ptr[i].la_psi = it->la_psi; - surf_charge_ptr[i].la_psi1 = it->la_psi1; - surf_charge_ptr[i].la_psi2 = it->la_psi2; - surf_charge_ptr[i].capacitance[0] = it->capacitance[0]; - surf_charge_ptr[i].capacitance[1] = it->capacitance[1]; + surf_charge_ptr[i].name = (*it).second.name; + surf_charge_ptr[i].specific_area = (*it).second.specific_area; + surf_charge_ptr[i].grams = (*it).second.grams; + surf_charge_ptr[i].charge_balance = (*it).second.charge_balance; + surf_charge_ptr[i].mass_water = (*it).second.mass_water; + surf_charge_ptr[i].la_psi = (*it).second.la_psi; + surf_charge_ptr[i].la_psi1 = (*it).second.la_psi1; + surf_charge_ptr[i].la_psi2 = (*it).second.la_psi2; + surf_charge_ptr[i].capacitance[0] = (*it).second.capacitance[0]; + surf_charge_ptr[i].capacitance[1] = (*it).second.capacitance[1]; surf_charge_ptr[i].sigma0 = 0; surf_charge_ptr[i].sigma1 = 0; surf_charge_ptr[i].sigma2 = 0; surf_charge_ptr[i].sigmaddl = 0; - surf_charge_ptr[i].diffuse_layer_totals = - it->diffuse_layer_totals.elt_list(); + surf_charge_ptr[i].diffuse_layer_totals = (*it).second.diffuse_layer_totals.elt_list(); //surf_charge_ptr[i].psi_master = it->get_psi_master(); surf_charge_ptr[i].count_g = 0; surf_charge_ptr[i].g = NULL; @@ -175,33 +173,33 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const // Surf_Charge element and attributes s_oss << indent0 << "-name " << this->name << std::endl; - s_oss << indent0 << "-specific_area " << this-> + s_oss << indent1 << "-specific_area " << this-> specific_area << std::endl; - s_oss << indent0 << "-grams " << this->grams << std::endl; - s_oss << indent0 << "-charge_balance " << this-> + s_oss << indent1 << "-grams " << this->grams << std::endl; + s_oss << indent1 << "-charge_balance " << this-> charge_balance << std::endl; - s_oss << indent0 << "-mass_water " << this-> + s_oss << indent1 << "-mass_water " << this-> mass_water << std::endl; - s_oss << indent0 << "-la_psi " << this-> + s_oss << indent1 << "-la_psi " << this-> la_psi << std::endl; - s_oss << indent0 << "-la_psi1 " << this-> + s_oss << indent1 << "-la_psi1 " << this-> la_psi1 << std::endl; - s_oss << indent0 << "-la_psi2 " << this-> + s_oss << indent1 << "-la_psi2 " << this-> la_psi2 << std::endl; - s_oss << indent0 << "-capacitance0 " << this-> + s_oss << indent1 << "-capacitance0 " << this-> capacitance[0] << std::endl; - s_oss << indent0 << "-capacitance1 " << this-> + s_oss << indent1 << "-capacitance1 " << this-> capacitance[1] << std::endl; // totals - s_oss << indent0; + s_oss << indent1; s_oss << "-diffuse_layer_totals" << std::endl; - this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); + this->diffuse_layer_totals.dump_raw(s_oss, indent + 2); } void -cxxSurfaceCharge::read_raw(CParser & parser) +cxxSurfaceCharge::read_raw(CParser & parser, bool check) { std::string str; @@ -395,67 +393,70 @@ cxxSurfaceCharge::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (name_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Name not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (specific_area_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Specific_area not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (grams_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Grams not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (charge_balance_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Charge_balance not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (mass_water_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Mass_water not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (la_psi_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La_psi not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (la_psi1_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La_psi1 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (la_psi2_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La_psi2 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (capacitance0_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); - } - if (capacitance1_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + // members that must be defined + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (specific_area_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Specific_area not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (grams_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Grams not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Charge_balance not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Mass_water not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi1 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (la_psi2_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La_psi2 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (capacitance0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } + if (capacitance1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", + CParser::OT_CONTINUE); + } } } diff --git a/SurfaceCharge.h b/SurfaceCharge.h index c2e434ec..b1faa769 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -24,15 +24,13 @@ class cxxSurfaceCharge struct master *get_psi_master(); - static struct surface_charge *cxxSurfaceCharge2surface_charge(std::list < - cxxSurfaceCharge - > &el); + static struct surface_charge *cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) 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_name() const { diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 829e4c3f..28865cc8 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -101,7 +101,7 @@ cxxSurfaceComp::get_master() } struct surface_comp * -cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list < cxxSurfaceComp > &el) + cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el) // // Builds surface_comp structure from of cxxSurfaceComp // @@ -113,23 +113,23 @@ cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list < cxxSurfaceComp > &el) malloc_error(); int i = 0; - for (std::list < cxxSurfaceComp >::iterator it = el.begin(); + for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin(); it != el.end(); ++it) { - surf_comp_ptr[i].formula = it->formula; - surf_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); - surf_comp_ptr[i].formula_z = it->formula_z; - surf_comp_ptr[i].moles = it->moles; - surf_comp_ptr[i].master = it->get_master(); - surf_comp_ptr[i].totals = it->totals.elt_list(); - surf_comp_ptr[i].la = it->la; + surf_comp_ptr[i].formula = (*it).second.formula; + surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); + surf_comp_ptr[i].formula_z = (*it).second.formula_z; + surf_comp_ptr[i].moles = (*it).second.moles; + surf_comp_ptr[i].master = (*it).second.get_master(); + surf_comp_ptr[i].totals = (*it).second.totals.elt_list(); + surf_comp_ptr[i].la = (*it).second.la; //surf_comp_ptr[i].charge = it->charge_number; - surf_comp_ptr[i].cb = it->charge_balance; - surf_comp_ptr[i].phase_name = it->phase_name; - surf_comp_ptr[i].phase_proportion = it->phase_proportion; - surf_comp_ptr[i].rate_name = it->rate_name; - surf_comp_ptr[i].Dw = it->Dw; - surf_comp_ptr[i].master = it->get_master(); + surf_comp_ptr[i].cb = (*it).second.charge_balance; + surf_comp_ptr[i].phase_name = (*it).second.phase_name; + surf_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; + surf_comp_ptr[i].rate_name = (*it).second.rate_name; + surf_comp_ptr[i].Dw = (*it).second.Dw; + surf_comp_ptr[i].master = (*it).second.get_master(); i++; } return (surf_comp_ptr); @@ -203,41 +203,41 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "-formula " << this-> formula << std::endl; - s_oss << indent0 << "-formula_z " << this-> + s_oss << indent1 << "-formula_z " << this-> formula_z << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; - s_oss << indent0 << "-la " << this->la << std::endl; - //s_oss << indent0 << "-charge_number " << this->charge_number << std::endl; - s_oss << indent0 << "-charge_balance " << this-> + s_oss << indent1 << "-moles " << this->moles << std::endl; + s_oss << indent1 << "-la " << this->la << std::endl; + //s_oss << indent1 << "-charge_number " << this->charge_number << std::endl; + s_oss << indent1 << "-charge_balance " << this-> charge_balance << std::endl; if (this->phase_name != NULL) { - s_oss << indent0 << "-phase_name " << this-> + s_oss << indent1 << "-phase_name " << this-> phase_name << std::endl; } if (this->rate_name != NULL) { - s_oss << indent0 << "-rate_name " << this-> + s_oss << indent1 << "-rate_name " << this-> rate_name << std::endl; } - s_oss << indent0 << "-phase_proportion " << this-> + s_oss << indent1 << "-phase_proportion " << this-> phase_proportion << std::endl; - s_oss << indent0 << "-Dw " << this->Dw << std::endl; + s_oss << indent1 << "-Dw " << this->Dw << std::endl; // formula_totals - s_oss << indent0; + s_oss << indent1; s_oss << "-formula_totals" << std::endl; - this->formula_totals.dump_raw(s_oss, indent + 1); + this->formula_totals.dump_raw(s_oss, indent + 2); // totals - s_oss << indent0; + s_oss << indent1; s_oss << "-totals" << std::endl; - this->totals.dump_raw(s_oss, indent + 1); + this->totals.dump_raw(s_oss, indent + 2); } void -cxxSurfaceComp::read_raw(CParser & parser) +cxxSurfaceComp::read_raw(CParser & parser, bool check) { std::string str; @@ -444,50 +444,53 @@ cxxSurfaceComp::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (formula_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Formula not defined for SurfaceComp input.", - CParser::OT_CONTINUE); - } - if (formula_z_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Formula_z not defined for ExchComp input.", - CParser::OT_CONTINUE); - } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for SurfaceComp input.", - CParser::OT_CONTINUE); - } - if (la_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La not defined for SurfaceComp input.", - CParser::OT_CONTINUE); - } + // members that must be defined + if (formula_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (formula_z_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Formula_z not defined for ExchComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (la_defined == false) + { + parser.incr_input_error(); + parser.error_msg("La not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } #ifdef SKIP - if (charge_number_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge_number not defined for SurfaceComp input.", - CParser::OT_CONTINUE); - } + if (charge_number_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_number not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } #endif - if (charge_balance_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge_balance not defined for SurfaceComp input.", - CParser::OT_CONTINUE); - } - if (Dw_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Dw not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + if (charge_balance_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge_balance not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } + if (Dw_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Dw not defined for SurfaceComp input.", + CParser::OT_CONTINUE); + } } } diff --git a/SurfaceComp.h b/SurfaceComp.h index 4c462536..c968eb91 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -45,15 +45,13 @@ class cxxSurfaceComp this->charge_balance = d; } - static struct surface_comp *cxxSurfaceComp2surface_comp(std::list < - cxxSurfaceComp > - &el); + static struct surface_comp *cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) 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); const cxxNameDouble & get_totals() const { return (this->totals); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 3fb83d62..5f97d402 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -58,7 +58,8 @@ totals(kinetics_ptr->totals) for (i = 0; i < kinetics_ptr->count_comps; i++) { cxxKineticsComp ec(&(kinetics_ptr->comps[i])); - this->kineticsComps.push_back(ec); + std::string str(ec.get_rate_name()); + this->kineticsComps[str] = ec; } // steps @@ -223,12 +224,12 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "-cvode_order " << this->cvode_order << std::endl; // kineticsComps structures - for (std::list < cxxKineticsComp >::const_iterator it = + for (std::map < std::string, cxxKineticsComp >::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; - it->dump_raw(s_oss, indent + 2); + (*it).second.dump_raw(s_oss, indent + 2); } // totals @@ -377,7 +378,8 @@ cxxKinetics::read_raw(CParser & parser, bool check) { cxxKineticsComp kc; kc.read_raw(parser); - this->kineticsComps.push_back(kc); + std::string str(kc.get_rate_name()); + this->kineticsComps[str] = kc; } useLastLine = true; break; @@ -546,6 +548,7 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif +#ifdef SKIP void cxxKinetics::add(const cxxKinetics & addee, double extensive) // @@ -592,3 +595,44 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) this->cvode_steps = addee.cvode_steps; this->cvode_order = addee.cvode_order; } +#endif +void +cxxKinetics::add(const cxxKinetics & addee, double extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // +{ + if (extensive == 0.0) + return; + //std::map < std::string, cxxKineticsComp> kineticsComps; + for (std::map < std::string, cxxKineticsComp >::const_iterator itadd = + addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); + ++itadd) + { + std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.find((*itadd).first); + if (it != this->kineticsComps.end()) + { + (*it).second.add((*itadd).second, extensive); + } + else + { + cxxKineticsComp entity = (*itadd).second; + entity.multiply(extensive); + std::string str(entity.get_rate_name()); + this->kineticsComps[str] = entity; + } + } + //std::vector steps; + this->steps = addee.steps; + //cxxNameDouble totals; + //double step_divide; + this->step_divide = addee.step_divide; + //int rk; + this->rk = addee.rk; + //int bad_step_max; + this->bad_step_max = addee.bad_step_max; + //bool use_cvode; + this->use_cvode = addee.use_cvode; + this->cvode_steps = addee.cvode_steps; + this->cvode_order = addee.cvode_order; +} diff --git a/cxxKinetics.h b/cxxKinetics.h index 8f42b3e7..a38a4311 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -46,8 +46,8 @@ class cxxKinetics:public cxxNumKeyword void add(const cxxKinetics & addee, double extensive); protected: - std::list < cxxKineticsComp > kineticsComps; - std::vector < double >steps; + std::map < std::string, cxxKineticsComp > kineticsComps; + std::vector < double >steps; cxxNameDouble totals; double step_divide; int rk; From cd38a8036dcbdbf4332221cac9dec515b8124263 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Oct 2009 19:53:35 +0000 Subject: [PATCH 0101/1077] Have done preliminary testing with all MODIFY keywords. Added brief documentation in revisions. Fixed dump feature of TRANSPORT to work with dump_raw of C++. ppdump now has testing for DUMP, DELETE, and MODIFY. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3727 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 30 +++++---- KineticsComp.h | 2 +- ReadClass.cxx | 116 +++++++++++++++++++---------------- SSassemblage.cxx | 31 ++++++++-- SSassemblageSS.cxx | 149 +++++++++++++++++++++++---------------------- SSassemblageSS.h | 2 +- cxxKinetics.cxx | 39 ++++++++++-- 7 files changed, 223 insertions(+), 146 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 61461cbf..145f62e8 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -166,29 +166,29 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "-rate_name " << this-> rate_name << std::endl; - s_oss << indent0 << "-tol " << this->tol << std::endl; - s_oss << indent0 << "-m " << this->m << std::endl; - s_oss << indent0 << "-m0 " << this->m0 << std::endl; - s_oss << indent0 << "-moles " << this->moles << std::endl; + s_oss << indent1 << "-tol " << this->tol << std::endl; + s_oss << indent1 << "-m " << this->m << std::endl; + s_oss << indent1 << "-m0 " << this->m0 << std::endl; + s_oss << indent1 << "-moles " << this->moles << std::endl; // namecoef - s_oss << indent0; + s_oss << indent1; s_oss << "-namecoef" << std::endl; - this->namecoef.dump_raw(s_oss, indent + 1); + this->namecoef.dump_raw(s_oss, indent + 2); // d_params - s_oss << indent0; + s_oss << indent1; s_oss << "-d_params" << std::endl; { int i = 0; - s_oss << indent1; + s_oss << indent2; for (std::vector < double >::const_iterator it = d_params.begin(); it != d_params.end(); it++) { if (i++ == 5) { s_oss << std::endl; - s_oss << indent1; + s_oss << indent2; i = 0; } s_oss << *it << " "; @@ -198,7 +198,7 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKineticsComp::read_raw(CParser & parser) +cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; double d; @@ -221,12 +221,14 @@ cxxKineticsComp::read_raw(CParser & parser) std::string token; int opt_save; + std::vector < double > temp_d_params; opt_save = CParser::OPT_ERROR; bool rate_name_defined(false); bool tol_defined(false); bool m_defined(false); bool m0_defined(false); bool moles_defined(false); + bool d_params_defined(false); for (;;) { @@ -328,13 +330,19 @@ cxxKineticsComp::read_raw(CParser & parser) while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { sscanf(token.c_str(), "%lf", &d); - this->d_params.push_back(d); + temp_d_params.push_back(d); + d_params_defined = true; } opt_save = 6; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } + + if (d_params_defined) + { + this->d_params = temp_d_params; + } // members that must be defined if (rate_name_defined == false) { diff --git a/KineticsComp.h b/KineticsComp.h index 3cf86f58..80e9efe0 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -26,7 +26,7 @@ public: 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_rate_name() const { diff --git a/ReadClass.cxx b/ReadClass.cxx index ca860825..8b741413 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1425,7 +1425,10 @@ read_surface_modify(void) struct surface *entity_ptr = entity.cxxSurface2surface(); surface_free(&(surface[n])); surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); + free_check_null(surface[n].description); + surface[n].description = string_duplicate(entity_ptr->description); surface_free(entity_ptr); + free_check_null(entity_ptr); // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); @@ -1450,6 +1453,24 @@ read_solid_solutions_modify(void) * */ int return_value; + + // find solid_solutions 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 solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1475,23 +1496,6 @@ read_solid_solutions_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find solid_solutions 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 solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } if (s_s_assemblage_bsearch(n_user, &n) == NULL) { input_error++; @@ -1508,7 +1512,10 @@ read_solid_solutions_modify(void) struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(); s_s_assemblage_free(&(s_s_assemblage[n])); s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); + free_check_null(s_s_assemblage[n].description); + s_s_assemblage[n].description = string_duplicate(entity_ptr->description); s_s_assemblage_free(entity_ptr); + free_check_null(entity_ptr); // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); @@ -1533,6 +1540,23 @@ read_gas_phase_modify(void) * */ int return_value; + // find gas_phase 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 gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1558,23 +1582,6 @@ read_gas_phase_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find gas_phase 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 gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } if (gas_phase_bsearch(n_user, &n) == NULL) { input_error++; @@ -1590,7 +1597,10 @@ read_gas_phase_modify(void) struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(); gas_phase_free(&(gas_phase[n])); gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); + free_check_null(gas_phase[n].description); + gas_phase[n].description = string_duplicate(entity_ptr->description); gas_phase_free(entity_ptr); + free_check_null(entity_ptr); // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); @@ -1615,6 +1625,24 @@ read_kinetics_modify(void) * */ int return_value; + + // find kinetics 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 kinetics number following KINETICS_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } /* * Make parser */ @@ -1640,23 +1668,6 @@ read_kinetics_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - // find kinetics 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 kinetics number following KINETICS_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } if (kinetics_bsearch(n_user, &n) == NULL) { input_error++; @@ -1673,7 +1684,10 @@ read_kinetics_modify(void) struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(); kinetics_free(&(kinetics[n])); kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); + free_check_null(kinetics[n].description); + kinetics[n].description = string_duplicate(entity_ptr->description); kinetics_free(entity_ptr); + free_check_null(entity_ptr); // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index a62ee9de..bd101b4e 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -205,10 +205,33 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) case 0: // solid_solution { - cxxSSassemblageSS ssSS; - ssSS.read_raw(parser); - std::string str(ssSS.get_name()); - this->ssAssemblageSSs[str] = ssSS; + cxxSSassemblageSS 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); + parser.seekg(pos).clear(); + parser.seekg(pos); + + if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) + { + cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; + ec1.read_raw(parser, false); + } + else + { + cxxSSassemblageSS ec1; + ec1.read_raw(parser, false); + std::string str(ec1.get_name()); + this->ssAssemblageSSs[str] = ec1; + } + } useLastLine = true; break; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 9a9d2cf7..92ba8025 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -189,30 +189,30 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); - std::string indent0(""); + std::string indent0(""), indent1(""); for (i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); - + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); // S_S element and attributes s_oss << indent0 << "-name " << this->name << std::endl; //s_oss << indent0 << "-total_moles " << this->total_moles << std::endl; - s_oss << indent0 << "-a0 " << this->a0 << std::endl; - s_oss << indent0 << "-a1 " << this->a1 << std::endl; - s_oss << indent0 << "-ag0 " << this->ag0 << std::endl; - s_oss << indent0 << "-ag1 " << this->ag1 << std::endl; - s_oss << indent0 << "-miscibility " << this-> - miscibility << std::endl; + s_oss << indent1 << "-a0 " << this->a0 << std::endl; + s_oss << indent1 << "-a1 " << this->a1 << std::endl; + s_oss << indent1 << "-ag0 " << this->ag0 << std::endl; + s_oss << indent1 << "-ag1 " << this->ag1 << std::endl; + s_oss << indent1 << "-miscibility " << this->miscibility << std::endl; //s_oss << indent0 << "-spinodal " << this->spinodal << std::endl; //s_oss << indent0 << "-tk " << this->tk << std::endl; - s_oss << indent0 << "-xb1 " << this->xb1 << std::endl; - s_oss << indent0 << "-xb2 " << this->xb2 << std::endl; - s_oss << indent0 << "-component " << std::endl; - this->comps.dump_raw(s_oss, indent + 1); + s_oss << indent1 << "-xb1 " << this->xb1 << std::endl; + s_oss << indent1 << "-xb2 " << this->xb2 << std::endl; + s_oss << indent1 << "-component " << std::endl; + this->comps.dump_raw(s_oss, indent + 2); } void -cxxSSassemblageSS::read_raw(CParser & parser) +cxxSSassemblageSS::read_raw(CParser & parser, bool check) { std::string str; @@ -428,70 +428,73 @@ cxxSSassemblageSS::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (name_defined == false) + if (check) { + // members that must be defined + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + /* + if (total_moles_defined == false) { parser.incr_input_error(); - parser.error_msg("Name not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - /* - if (total_moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - */ - if (a0_defined == false) - { + parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (a0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("A0 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (a1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("A1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (ag0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ag0 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (ag1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ag1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (miscibility_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Miscibility not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + /* + if (spinodal_defined == false) { parser.incr_input_error(); - parser.error_msg("A0 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - if (a1_defined == false) - { + parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + if (tk_defined == false) { parser.incr_input_error(); - parser.error_msg("A1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - if (ag0_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Ag0 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - if (ag1_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Ag1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - if (miscibility_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Miscibility not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - /* - if (spinodal_defined == false) { - parser.incr_input_error(); - parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - if (tk_defined == false) { - parser.incr_input_error(); - parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); - } - */ - if (xb1_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Xb1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); - } - if (xb2_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Xb2 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + } + */ + if (xb1_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Xb1 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } + if (xb2_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Xb2 not defined for SSassemblageSS input.", + CParser::OT_CONTINUE); + } } } diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 73df9a3f..7e7e21bf 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -42,7 +42,7 @@ class cxxSSassemblageSS 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_name() const { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 5f97d402..e771e3eb 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -284,6 +284,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) std::string token; int opt_save; bool useLastLine(false); + std::vector < double > temp_steps; // Read kinetics number and description this->read_number_description(parser); @@ -295,6 +296,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) bool use_cvode_defined(false); bool cvode_steps_defined(false); bool cvode_order_defined(false); + bool steps_defined(false); for (;;) { @@ -376,10 +378,32 @@ cxxKinetics::read_raw(CParser & parser, bool check) case 4: // component { - cxxKineticsComp kc; - kc.read_raw(parser); - std::string str(kc.get_rate_name()); - this->kineticsComps[str] = kc; + cxxKineticsComp 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); + parser.seekg(pos).clear(); + parser.seekg(pos); + + if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) + { + cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; + comp.read_raw(parser, false); + } + else + { + cxxKineticsComp ec1; + ec1.read_raw(parser, false); + std::string str(ec1.get_rate_name()); + this->kineticsComps[str] = ec1; + } } useLastLine = true; break; @@ -412,7 +436,8 @@ cxxKinetics::read_raw(CParser & parser, bool check) } else { - this->steps.push_back(d); + temp_steps.push_back(d); + steps_defined = true; } } opt_save = 6; @@ -447,6 +472,10 @@ cxxKinetics::read_raw(CParser & parser, bool check) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } + if (steps_defined) + { + this->steps = temp_steps; + } if (check) { // members that must be defined From 5f9cf78f0104ffe358647d605aa99eecddca4ddf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Oct 2009 20:08:56 +0000 Subject: [PATCH 0102/1077] Modified for parallel version. Had some lists in the pack and unpack routines that now are maps. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3728 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 7 ++++--- PPassemblage.cxx | 7 ++++--- SSassemblage.cxx | 7 ++++--- StorageBinList.cpp | 2 +- Surface.cxx | 14 ++++++++------ cxxKinetics.cxx | 7 ++++--- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index e16f6ecc..6c851571 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -491,10 +491,10 @@ cxxExchange::mpi_pack(std::vector < int >&ints, ints.push_back((int) this->pitzer_exchange_gammas); ints.push_back((int) this->exchComps.size()); - for (std::list < cxxExchComp >::iterator it = this->exchComps.begin(); + for (std::map < std::string, cxxExchComp >::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } } @@ -518,7 +518,8 @@ cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxExchComp ec; ec.mpi_unpack(ints, &i, doubles, &d); - this->exchComps.push_back(ec); + std::string str(ec.get_formula()); + this->exchComps[str] = ec; } *ii = i; *dd = d; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 4417c2a0..b4b96f20 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -278,11 +278,11 @@ cxxPPassemblage::mpi_pack(std::vector < int >&ints, /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->ppAssemblageComps.size()); - for (std::list < cxxPPassemblageComp >::iterator it = + for (std::map < std::string, cxxPPassemblageComp >::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } this->eltList.mpi_pack(ints, doubles); } @@ -305,7 +305,8 @@ cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxPPassemblageComp ppc; ppc.mpi_unpack(ints, &i, doubles, &d); - this->ppAssemblageComps.push_back(ppc); + std::string str(ppc.get_name()); + this->ppAssemblageComps[str] = ppc; } this->eltList.mpi_unpack(ints, &i, doubles, &d); *ii = i; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index bd101b4e..101c7949 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -251,11 +251,11 @@ cxxSSassemblage::mpi_pack(std::vector < int >&ints, /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->ssAssemblageSSs.size()); - for (std::list < cxxSSassemblageSS >::iterator it = + for (std::map < std::string, cxxSSassemblageSS >::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } } @@ -277,7 +277,8 @@ cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxSSassemblageSS ssc; ssc.mpi_unpack(ints, &i, doubles, &d); - this->ssAssemblageSSs.push_back(ssc); + std::string str(ssc.get_name()); + this->ssAssemblageSSs[str] = ssc; } *ii = i; *dd = d; diff --git a/StorageBinList.cpp b/StorageBinList.cpp index d65f8bf0..3ccc64dc 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -14,7 +14,7 @@ void StorageBinListItem::Augment(std::string token) if (token.size() == 0) return; // split string accounting for possible negative numbers - unsigned int pos; + size_t pos; if ((pos = token.find("--")) != std::string::npos) { token.replace(pos,2," &"); diff --git a/Surface.cxx b/Surface.cxx index e1ed2f24..1d79498b 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -746,16 +746,16 @@ cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->surfaceComps.size()); - for (std::list < cxxSurfaceComp >::iterator it = + for (std::map < std::string, cxxSurfaceComp >::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } ints.push_back((int) this->surfaceCharges.size()); - for (std::list < cxxSurfaceCharge >::iterator it = + for (std::map < std::string, cxxSurfaceCharge >::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } //ints.push_back((int) this->diffuse_layer); //ints.push_back((int) this->edl); @@ -790,7 +790,8 @@ cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxSurfaceComp sc; sc.mpi_unpack(ints, &i, doubles, &d); - this->surfaceComps.push_back(sc); + std::string str(sc.get_formula()); + this->surfaceComps[str] = sc; } count = ints[i++]; this->surfaceCharges.clear(); @@ -798,7 +799,8 @@ cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxSurfaceCharge sc; sc.mpi_unpack(ints, &i, doubles, &d); - this->surfaceCharges.push_back(sc); + std::string str(sc.get_name()); + this->surfaceCharges[str] = sc; } //this->diffuse_layer = (bool) ints[i++]; //this->edl = (bool) ints[i++]; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index e771e3eb..4b8299ce 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -525,10 +525,10 @@ cxxKinetics::mpi_pack(std::vector < int >&ints, { ints.push_back(this->n_user); ints.push_back((int) this->kineticsComps.size()); - for (std::list < cxxKineticsComp >::iterator it = + for (std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { - it->mpi_pack(ints, doubles); + (*it).second.mpi_pack(ints, doubles); } ints.push_back((int) this->steps.size()); for (std::vector < double >::iterator it = this->steps.begin(); @@ -559,7 +559,8 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxKineticsComp kc; kc.mpi_unpack(ints, &i, doubles, &d); - this->kineticsComps.push_back(kc); + std::string str(kc.get_rate_name()); + this->kineticsComps[str] = kc; } n = ints[i++]; this->steps.clear(); From 259c0839f05d04ce7e3b56e50f0787432046b019 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 30 Oct 2009 22:27:43 +0000 Subject: [PATCH 0103/1077] Added new class runner. Finished new keyword RUN_CELLS. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3730 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 199 +++++++++++++++++++++++++++++++++++++++++++++ StorageBinList.cpp | 32 ++++++++ StorageBinList.h | 1 + 3 files changed, 232 insertions(+) diff --git a/ReadClass.cxx b/ReadClass.cxx index 8b741413..01d092b4 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -13,6 +13,7 @@ #include "cxxMix.h" #include "Temperature.h" #include "dumper.h" +#include "runner.h" #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -26,8 +27,12 @@ static int streamify_to_next_keyword(std::istringstream & lines); extern int reading_database(void); extern int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); +extern int set_use(void); +extern int copy_use(int i); dumper dump_info; StorageBinList delete_info; +runner run_info; + /* ---------------------------------------------------------------------- */ int read_solution_raw(void) @@ -1080,6 +1085,58 @@ read_delete(void) delete_info = deleter; + // Need to output the next keyword + output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int +read_run_cells(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads DELETE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + runner r(parser); + run_info = r; + + // Need to output the next keyword output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); @@ -2206,3 +2263,145 @@ delete_entities(void) delete_info.SetAll(false); return (OK); } +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int +run_as_cells(void) +/* ---------------------------------------------------------------------- */ +{ + int i, n; + LDBLE kin_time; +/* + * Calculate advection + */ + state = ADVECTION; +/* mass_water_switch = TRUE; */ +/* + * Check existence of all solutions + */ + if (run_info.Get_cells().Get_numbers().size() == 0 || + !(run_info.Get_cells().Get_defined())) return(OK); + + dup_print("Beginning of run as cells.", TRUE); + + std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); + last_model.force_prep = TRUE; + initial_total_time = run_info.Get_start_time(); + rate_sim_time_start = 0; + kin_time = run_info.Get_time_step(); + double advection_kin_time_save = advection_kin_time; + advection_kin_time = kin_time; + + for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) + { + i = *it; + if (i < 0) continue; + //if (solution_bsearch(i, &n, TRUE) == NULL) + //{ + // sprintf(error_string, + // "Solution %d is needed for RUN, but is not defined.", i); + // warning_msg(error_string); + // continue; + //} + /* + * Equilibrate and (or) mix + */ + set_initial_moles(i); + cell_no = i; + set_advection(i, TRUE, TRUE, i); + reactions(); + + //run_reactions(i, kin_time, TRUE, 1.0); + ////rate_sim_time = rate_sim_time_start + kin_time; + + //punch_all(); + //print_all(); + //save.n_solution_user = i; + //save.n_solution_user_end = i; + //struct save save_dbg = save; + saver(); + } + double advection_kin_time = advection_kin_time_save; + initial_total_time += rate_sim_time_start; + /* free_model_allocs(); */ + mass_water_switch = FALSE; + run_info.Get_cells().Set_defined(false); + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int +run_as_cells(void) +/* ---------------------------------------------------------------------- */ +{ + int count_steps, use_mix, m; + char token[2 * MAX_LENGTH]; + struct save save_data; + LDBLE kin_time; + struct kinetics *kinetics_ptr; + + state = REACTION; + if (run_info.Get_cells().Get_numbers().size() == 0 || + !(run_info.Get_cells().Get_defined())) return(OK); + + dup_print("Beginning of run as cells.", TRUE); + + std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); + last_model.force_prep = TRUE; + initial_total_time = run_info.Get_start_time(); + rate_sim_time_start = 0; + kin_time = run_info.Get_time_step(); + + for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) + { + int i = *it; + if (i < 0) continue; + + set_advection(i, TRUE, TRUE, i); + + save_data = save; + + /* last_model.force_prep = TRUE; */ + if (set_use() == FALSE) + return (OK); + + /* + * save data for saving solutions + */ + //memcpy(&save_data, &save, sizeof(struct save)); + /* + *Copy everything to -2 + */ + copy_use(-2); + rate_sim_time_start = 0; + rate_sim_time = 0; + + set_initial_moles(-2); + +/* + * Run reaction step + */ + run_reactions(-2, kin_time, TRUE, 1.0); + rate_sim_time = kin_time; + + punch_all(); + print_all(); + + /* saves back into -2 */ + save = save_data; + saver(); + } +/* + * save end of reaction + */ + //memcpy(&save, &save_data, sizeof(struct save)); + //if (use.kinetics_in == TRUE) + //{ + // kinetics_duplicate(-2, use.n_kinetics_user); + //} + //saver(); + run_info.Get_cells().Set_defined(false); + /* free_model_allocs(); */ + /* last_model.force_prep = TRUE; */ + return (OK); +} \ No newline at end of file diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 3ccc64dc..201528d0 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -8,6 +8,38 @@ StorageBinListItem::StorageBinListItem(void) StorageBinListItem::~StorageBinListItem(void) { } +StorageBinListItem::StorageBinListItem(CParser & parser) +{ + this->Clear(); + // Read list of numbers or number ranges + for (;;) + { + //read lines + CParser::LINE_TYPE l = parser.check_line("read StorageBinListLtem", false, true, true, true); + std::istream::pos_type next_char = 0; + if (l == CParser::LT_EOF) break; + for (;;) + { + std::string token; + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + if (j == CParser::TT_DIGIT) + { + this->Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + break; + } + else + { + // ignore characters like RUN + //parser.error_msg("Expected single number or range of numbers.", + // CParser::OT_CONTINUE); + //break; + } + } + } +} void StorageBinListItem::Augment(std::string token) { this->defined = true; diff --git a/StorageBinList.h b/StorageBinList.h index 5f0d6db9..10094d0a 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -9,6 +9,7 @@ class StorageBinListItem { public: StorageBinListItem(void); + StorageBinListItem(CParser & parser); ~StorageBinListItem(void); void Set_defined(bool tf) { this->defined = tf; }; bool Get_defined(void) { return(this->defined); }; From b3b22f3fd53bc295e4b9431b49e2af742b34182f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 2 Nov 2009 15:25:39 +0000 Subject: [PATCH 0104/1077] New class git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3735 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- runner.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++ runner.h | 23 ++++++++++ 2 files changed, 151 insertions(+) create mode 100644 runner.cpp create mode 100644 runner.h diff --git a/runner.cpp b/runner.cpp new file mode 100644 index 00000000..092cb8f3 --- /dev/null +++ b/runner.cpp @@ -0,0 +1,128 @@ +#include "runner.h" + +runner::runner(void) +{ + this->time_step = 0; + this->start_time = 0; +} +runner::runner(CParser & parser) +{ + this->time_step = 0; + this->start_time = 0; + this->Read(parser); +} + +runner::~runner(void) +{ +} +bool runner::Read(CParser & parser) +{ + + bool return_value(true); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(20); + vopts.push_back("cell"); + vopts.push_back("cells"); + vopts.push_back("start_time"); + vopts.push_back("time_step"); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + this->Get_cells().Set_defined(true); + opt_save = CParser::OPT_DEFAULT; + + StorageBinListItem item; + for (;;) + { + int opt; + opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + else + { + opt_save = opt; + } + + + + // Read dump entity list of numbers or number ranges for line, store in item + if (opt >= 0 && opt <= 1) + { + + } + + // Process other identifiers + std::set < int >::iterator it; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + + case 0: + case 1: + for (;;) + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + if (j == CParser::TT_DIGIT) + { + item.Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + item.Augment(token); + break; + } + else + { + parser.error_msg("Expected single number or range of numbers.", + CParser::OT_CONTINUE); + } + } + break; + case 2: //start_time + if (!(parser.get_iss() >> this->start_time)) + { + parser.error_msg("Expected start_time for RUN_CELLS.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + } + break; + case 3: //time_step + if (!(parser.get_iss() >> this->time_step)) + { + parser.error_msg("Expected time_step for RUN_CELLS.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + } + break; + default: + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input reading RUN_CELLS definition.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + return_value = false; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + if (item.Get_numbers().size() > 0) + { + this->cells = item; + } + return(return_value); +} diff --git a/runner.h b/runner.h new file mode 100644 index 00000000..0b35a4f7 --- /dev/null +++ b/runner.h @@ -0,0 +1,23 @@ +#if !defined(RUNNER_H_INCLUDED) +#define RUNNER_H_INCLUDED +#include // std::set +#include // std::string +#include "Parser.h" +#include "StorageBinList.h" +class runner +{ +public: + runner(void); + runner(CParser & parser); + virtual ~runner(void); + bool Read(CParser & parser); + StorageBinListItem & Get_cells(void) { return(this->cells); }; + double Get_time_step() { return(this->time_step); }; + double Get_start_time() { return(this->start_time); }; + +protected: + double time_step; + double start_time; + StorageBinListItem cells; +}; +#endif // !defined(RUNNER_H_INCLUDED) \ No newline at end of file From c73fc4b2e9304235fad96c9703e4bc6db7d78eb8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 2 Nov 2009 15:34:29 +0000 Subject: [PATCH 0105/1077] Modifications for Linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3736 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 1 + ReadClass.cxx | 5 +---- dumper.cpp | 2 +- runner.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ec0ea045..459029ad 100644 --- a/Makefile +++ b/Makefile @@ -180,6 +180,7 @@ COMMON_CXXOBJS = \ PPassemblage.o \ Reaction.o \ ReadClass.o \ + runner.o \ Solution.o \ SolutionIsotope.o \ SolutionIsotopeList.o \ diff --git a/ReadClass.cxx b/ReadClass.cxx index 01d092b4..6592682f 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -2334,11 +2334,8 @@ int run_as_cells(void) /* ---------------------------------------------------------------------- */ { - int count_steps, use_mix, m; - char token[2 * MAX_LENGTH]; struct save save_data; LDBLE kin_time; - struct kinetics *kinetics_ptr; state = REACTION; if (run_info.Get_cells().Get_numbers().size() == 0 || @@ -2404,4 +2401,4 @@ run_as_cells(void) /* free_model_allocs(); */ /* last_model.force_prep = TRUE; */ return (OK); -} \ No newline at end of file +} diff --git a/dumper.cpp b/dumper.cpp index 7d2d9628..2341296f 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -381,7 +381,7 @@ bool dumper::Read(CParser & parser) break; case 15: //append { - CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + parser.copy_token(token, next_char); //if (!(parser.get_iss() >> this->append)) this->append = true; if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') diff --git a/runner.h b/runner.h index 0b35a4f7..fb407ebd 100644 --- a/runner.h +++ b/runner.h @@ -20,4 +20,4 @@ protected: double start_time; StorageBinListItem cells; }; -#endif // !defined(RUNNER_H_INCLUDED) \ No newline at end of file +#endif // !defined(RUNNER_H_INCLUDED) From e35673205b0e40e56ac47af54aa64dae678ee6a8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 2 Nov 2009 20:43:37 +0000 Subject: [PATCH 0106/1077] Typo of file instead of stream for setting echo to file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3739 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 9 ++++----- PPassemblage.cxx | 2 +- SSassemblage.cxx | 2 +- Surface.cxx | 4 ++-- cxxKinetics.cxx | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 6c851571..3e57a383 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -363,19 +363,18 @@ cxxExchange::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ec.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); + parser.seekg(pos).clear(); + parser.seekg(pos); 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()); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index b4b96f20..5611b15d 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -240,7 +240,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ppComp.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end()) { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 101c7949..c46b3c41 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -215,7 +215,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ec.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); parser.seekg(pos).clear(); parser.seekg(pos); diff --git a/Surface.cxx b/Surface.cxx index 1d79498b..9c4293e8 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -517,7 +517,7 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ec.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); parser.seekg(pos).clear(); parser.seekg(pos); @@ -549,7 +549,7 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ec.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); parser.seekg(pos).clear(); parser.seekg(pos); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 4b8299ce..9bee131e 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -388,7 +388,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser.set_echo_stream(CParser::EO_NONE); ec.read_raw(parser, false); parser.set_echo_file(eo); - parser.set_echo_file(eo_s); + parser.set_echo_stream(eo_s); parser.seekg(pos).clear(); parser.seekg(pos); From ff19c86d654797754974ba5a38cb433d02e87a70 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Nov 2009 17:55:36 +0000 Subject: [PATCH 0107/1077] The tellg and seekg did not work for gz files because the methods are not implemented. Modified the parser to accumulate lines so that they could be turned into a stream and reread. Modified kinetics, exchange, ppassemblage, ssassemblage, and surface to use the new way to reread lines for component values. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3742 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 19 +++++++++++++++++++ PPassemblage.cxx | 22 +++++++++++++++++++++- Parser.cxx | 8 ++++++++ Parser.h | 14 ++++++++++++++ SSassemblage.cxx | 20 +++++++++++++++++++- Surface.cxx | 38 ++++++++++++++++++++++++++++++++++++++ cxxKinetics.cxx | 20 ++++++++++++++++++++ 7 files changed, 139 insertions(+), 2 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 3e57a383..d5d41243 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -356,6 +356,7 @@ cxxExchange::read_raw(CParser & parser, bool check) cxxExchComp ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -380,6 +381,24 @@ cxxExchange::read_raw(CParser & parser, bool check) std::string str(ec1.get_formula()); this->exchComps[str] = ec1; } +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) + { + cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; + comp.read_raw(reread, false); + } + else + { + cxxExchComp ec1; + ec1.read_raw(reread, false); + std::string str(ec1.get_formula()); + this->exchComps[str] = ec1; + } } useLastLine = true; break; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 5611b15d..92763491 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -230,9 +230,10 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) case 1: // component { - cxxPPassemblageComp ppComp; + cxxPPassemblageComp ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -258,6 +259,25 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) std::string str(ppComp1.get_name()); this->ppAssemblageComps[str] = ppComp1; } +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + + if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) + { + cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ec.get_name())->second; + comp.read_raw(reread, false); + } + else + { + cxxPPassemblageComp ppComp1; + ppComp1.read_raw(reread, false); + std::string str(ppComp1.get_name()); + this->ppAssemblageComps[str] = ppComp1; + } } useLastLine = true; break; diff --git a/Parser.cxx b/Parser.cxx index b4a4f08d..2552b242 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -27,6 +27,7 @@ m_next_keyword(KT_NONE) m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; + accumulate = false; } CParser::CParser(std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), @@ -37,6 +38,7 @@ m_next_keyword(KT_NONE) m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; + accumulate = false; } CParser::CParser(std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), @@ -47,6 +49,7 @@ m_next_keyword(KT_NONE) m_line.reserve(80); echo_file = EO_ALL; echo_stream = EO_NONE; + accumulate = false; } CParser::~CParser() @@ -199,6 +202,11 @@ CParser::LINE_TYPE CParser::get_line() } } + if (this->accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } // // New line character encountered // diff --git a/Parser.h b/Parser.h index 7a12b608..8d436ff6 100644 --- a/Parser.h +++ b/Parser.h @@ -151,6 +151,18 @@ class CParser { return m_line; } + std::string & get_accumulated() + { + return accumulated; + } + void set_accumulate(bool tf) + { + if (tf) + { + accumulated.clear(); + } + this->accumulate = tf; + } std::istringstream & get_iss() { return m_line_iss; @@ -289,6 +301,8 @@ class CParser LINE_TYPE m_line_type; ECHO_OPTION echo_stream; ECHO_OPTION echo_file; + std::string accumulated; + bool accumulate; }; // Global functions diff --git a/SSassemblage.cxx b/SSassemblage.cxx index c46b3c41..1a553059 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -208,6 +208,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) cxxSSassemblageSS ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -231,7 +232,24 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) std::string str(ec1.get_name()); this->ssAssemblageSSs[str] = ec1; } - +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) + { + cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; + ec1.read_raw(reread, false); + } + else + { + cxxSSassemblageSS ec1; + ec1.read_raw(reread, false); + std::string str(ec1.get_name()); + this->ssAssemblageSSs[str] = ec1; + } } useLastLine = true; break; diff --git a/Surface.cxx b/Surface.cxx index 9c4293e8..368788b6 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -510,6 +510,7 @@ cxxSurface::read_raw(CParser & parser, bool check) cxxSurfaceComp ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -533,6 +534,24 @@ cxxSurface::read_raw(CParser & parser, bool check) std::string str(ec1.get_formula()); this->surfaceComps[str] = ec1; } +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) + { + cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; + comp.read_raw(reread, false); + } + else + { + cxxSurfaceComp ec1; + ec1.read_raw(reread, false); + std::string str(ec1.get_formula()); + this->surfaceComps[str] = ec1; + } } useLastLine = true; break; @@ -542,6 +561,7 @@ cxxSurface::read_raw(CParser & parser, bool check) cxxSurfaceCharge ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -565,6 +585,24 @@ cxxSurface::read_raw(CParser & parser, bool check) std::string str(ec1.get_name()); this->surfaceCharges[str] = ec1; } +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) + { + cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; + comp.read_raw(reread, false); + } + else + { + cxxSurfaceCharge ec1; + ec1.read_raw(reread, false); + std::string str(ec1.get_name()); + this->surfaceCharges[str] = ec1; + } } useLastLine = true; break; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 9bee131e..bc2b8e5f 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -381,6 +381,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) cxxKineticsComp ec; // preliminary read +#ifdef SKIP std::istream::pos_type pos = parser.tellg(); CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); @@ -404,6 +405,25 @@ cxxKinetics::read_raw(CParser & parser, bool check) std::string str(ec1.get_rate_name()); this->kineticsComps[str] = ec1; } +#endif + parser.set_accumulate(true); + ec.read_raw(parser, false); + parser.set_accumulate(false); + std::istringstream is(parser.get_accumulated()); + CParser reread(is); + + if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) + { + cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; + comp.read_raw(reread, false); + } + else + { + cxxKineticsComp ec1; + ec1.read_raw(reread, false); + std::string str(ec1.get_rate_name()); + this->kineticsComps[str] = ec1; + } } useLastLine = true; break; From 5de5c6f307262915890c0cd575cc68bfdd889a2c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Nov 2009 19:41:47 +0000 Subject: [PATCH 0108/1077] Needed to turn of echo when rereading components. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3743 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 2 ++ PPassemblage.cxx | 3 ++- SSassemblage.cxx | 2 ++ Surface.cxx | 4 ++++ cxxKinetics.cxx | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Exchange.cxx b/Exchange.cxx index d5d41243..308a859b 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -387,6 +387,8 @@ cxxExchange::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) { cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 92763491..aa35f313 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -265,7 +265,8 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); - + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) { cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ec.get_name())->second; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 1a553059..cd4c7acc 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -238,6 +238,8 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) { cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; diff --git a/Surface.cxx b/Surface.cxx index 368788b6..1408aa9f 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -540,6 +540,8 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) { cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; @@ -591,6 +593,8 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) { cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index bc2b8e5f..f2709a33 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -411,6 +411,8 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); + reread.set_echo_file(CParser::EO_NONE); + reread.set_echo_stream(CParser::EO_NONE); if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) { From 303864120af3c85df1f33f25fdc9df4cae75bad6 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 3 Nov 2009 23:39:32 +0000 Subject: [PATCH 0109/1077] updated for COM object git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3749 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReadClass.cxx b/ReadClass.cxx index 6592682f..3d7f55de 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1826,6 +1826,11 @@ dump_entities(void) { dump_stream.open(dump_info.get_file_name().c_str()); } + if (!dump_stream.is_open()) + { + sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.get_file_name().c_str()); + error_msg(error_string, STOP); + } // solutions if (dump_info.Get_bool_solution()) { From 3fe2fcd3bba5fa50946ea1c51d0a4361235e1125 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 Dec 2009 15:45:49 +0000 Subject: [PATCH 0110/1077] Modified to run_cells if solution exists, even with no reactants. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3824 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 3d7f55de..48805ea0 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -2364,8 +2364,8 @@ run_as_cells(void) save_data = save; /* last_model.force_prep = TRUE; */ - if (set_use() == FALSE) - return (OK); + //if (set_use() == FALSE) + // return (OK); /* * save data for saving solutions From a4bac119dbcd07885780cf8574811d2f846f7144 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Dec 2009 00:54:28 +0000 Subject: [PATCH 0111/1077] eol for system.cxx git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3841 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- System.cxx | 1085 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 660 insertions(+), 425 deletions(-) diff --git a/System.cxx b/System.cxx index 4a0355ff..053551b8 100644 --- a/System.cxx +++ b/System.cxx @@ -1,84 +1,139 @@ #include "System.h" -#include // std::replace -extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); - cxxSystem::cxxSystem(void) -{ - this->solution = NULL; - this->exchange = NULL; - this->ppassemblage = NULL; - this->gasphase = NULL; - this->ssassemblage = NULL; - this->kinetics = NULL; - this->surface = NULL; - this->mix = NULL; - this->reaction = NULL; - this->temperature = NULL; - } cxxSystem::~cxxSystem(void) -{ - } void -cxxSystem::Initialize(void) -{ - this->solution = NULL; - this->exchange = NULL; - this->ppassemblage = NULL; - this->gasphase = NULL; - this->ssassemblage = NULL; - this->kinetics = NULL; - this->surface = NULL; - this->mix = NULL; - this->reaction = NULL; - this->temperature = NULL; - } void -cxxSystem::totalize(void) -{ - +#include // std::replace +extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); +cxxSystem::cxxSystem(void) +{ + +this->solution = NULL; + +this->exchange = NULL; + +this->ppassemblage = NULL; + +this->gasphase = NULL; + +this->ssassemblage = NULL; + +this->kinetics = NULL; + +this->surface = NULL; + +this->mix = NULL; + +this->reaction = NULL; + +this->temperature = NULL; +} + +cxxSystem::~cxxSystem(void) +{ +} + +void +cxxSystem::Initialize(void) +{ + +this->solution = NULL; + +this->exchange = NULL; + +this->ppassemblage = NULL; + +this->gasphase = NULL; + +this->ssassemblage = NULL; + +this->kinetics = NULL; + +this->surface = NULL; + +this->mix = NULL; + +this->reaction = NULL; + +this->temperature = NULL; +} +void +cxxSystem::totalize(void) +{ + //initialize - this->totals.clear(); - + this->totals.clear(); + //add solution - if (this->solution != NULL) - - { - char token[MAX_LENGTH]; - strcpy(token, "O"); - this->totals[token] = this->solution->get_total_o(); - strcpy(token, "H"); - this->totals[token] = this->solution->get_total_h(); - strcpy(token, "Charge"); - this->totals[token] = this->solution->get_cb(); - this->totals.add_extensive(this->solution->get_totals(), 1.0); - } - if (this->exchange != NULL) - - { - this->exchange->totalize(); - this->totals.add_extensive(this->exchange->get_totals(), 1.0); - } - if (this->ppassemblage != NULL) - - { - this->ppassemblage->totalize(); - this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); - } - if (this->gasphase != NULL) - - { - this->gasphase->totalize(); - this->totals.add_extensive(this->gasphase->get_totals(), 1.0); - } - if (this->ssassemblage != NULL) - - { - this->ssassemblage->totalize(); - this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); - } - if (this->surface != NULL) - - { - this->ssassemblage->totalize(); - this->totals.add_extensive(this->surface->get_totals(), 1.0); - } - + if (this->solution != NULL) + + { + +char token[MAX_LENGTH]; + +strcpy(token, "O"); + +this->totals[token] = this->solution->get_total_o(); + +strcpy(token, "H"); + +this->totals[token] = this->solution->get_total_h(); + +strcpy(token, "Charge"); + +this->totals[token] = this->solution->get_cb(); + +this->totals.add_extensive(this->solution->get_totals(), 1.0); + +} + +if (this->exchange != NULL) + + { + +this->exchange->totalize(); + +this->totals.add_extensive(this->exchange->get_totals(), 1.0); + +} + +if (this->ppassemblage != NULL) + + { + +this->ppassemblage->totalize(); + +this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + +} + +if (this->gasphase != NULL) + + { + +this->gasphase->totalize(); + +this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + +} + +if (this->ssassemblage != NULL) + + { + +this->ssassemblage->totalize(); + +this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + +} + +if (this->surface != NULL) + + { + +this->ssassemblage->totalize(); + +this->totals.add_extensive(this->surface->get_totals(), 1.0); + +} + + //Need to handle the following 3 reactions: // //this->kinetics = NULL; @@ -86,245 +141,356 @@ cxxSystem::totalize(void) //this->reaction = NULL; //this->temperature = NULL; //this->totals.dump_raw(std::cerr, 1); - return; - } - + return; +} + #ifdef ORCHESTRA - void -cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat) -{ - + void +cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat) +{ + // // chemistry file // - this->totalize(); - + this->totalize(); + // calculate orchestra components from PHREEQC totals - this->ORCH_components(); - + this->ORCH_components(); + // write definitions for chemistry - chemistry_dat << std:: - endl << "@class: species_reactions () {" << std::endl; - this->ORCH_write_chemistry_water(chemistry_dat); - this->ORCH_write_chemistry_primary(chemistry_dat); - this->ORCH_write_chemistry_total_O_H(chemistry_dat); - ORCH_write_chemistry_species(chemistry_dat); - + chemistry_dat << std:: + endl << "@class: species_reactions () {" << std::endl; + +this->ORCH_write_chemistry_water(chemistry_dat); + +this->ORCH_write_chemistry_primary(chemistry_dat); + +this->ORCH_write_chemistry_total_O_H(chemistry_dat); + +ORCH_write_chemistry_species(chemistry_dat); + + // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_chemistry(chemistry_dat); + + // add definitions for other PHREEQC entities here - + // finish up - chemistry_dat << std::endl << "}" << std::endl; - + chemistry_dat << std::endl << "}" << std::endl; + // // input file // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - this->ORCH_write_input(input_dat); - input_dat << std::endl << "}" << std::endl; - + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + +this->ORCH_write_input(input_dat); + +input_dat << std::endl << "}" << std::endl; + // // output file // - output_dat << std::endl << "Output_every: 1" << std::endl; - output_dat << "Var:"; - this->ORCH_write_output_vars(output_dat); - + output_dat << std::endl << "Output_every: 1" << std::endl; + +output_dat << "Var:"; + +this->ORCH_write_output_vars(output_dat); + // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_output_vars(output_dat); - + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_output_vars(output_dat); + + //finish up - output_dat << std::endl; - }; - void -cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) -{ - + output_dat << std::endl; +}; + +void +cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) +{ + // // Write water entities // - chemistry_dat << std:: - endl << "//********* The water entities" << std::endl; - + chemistry_dat << std:: + endl << "//********* The water entities" << std::endl; + + // e-, total hydrogen - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: - endl; - + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + +chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; + +chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: + endl; + + // H+, charge balance - chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: - endl; - + chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; + +chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: + endl; + + // H2O - chemistry_dat << "@entity(" << s_h2o-> - name << ", diss, 55.506)" << std::endl; - chemistry_dat << std::endl; - } void - -cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) -{ - chemistry_dat << std::endl << "//********* The primary species" << std:: - endl; - + chemistry_dat << "@entity(" << s_h2o-> + name << ", diss, 55.506)" << std::endl; + +chemistry_dat << std::endl; +} + +void + +cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) +{ + +chemistry_dat << std::endl << "//********* The primary species" << std:: + endl; + // // Write other master species definitions, i.e. primary entities // - chemistry_dat << "@species(H+, 1)" << std::endl; - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - - { - std::string name(iter->first); - if (name == "H(1)" || name == "E" || name == "H" || name == "O" - || name == "Charge") - continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> - z << ")" << std::endl; - + chemistry_dat << "@species(H+, 1)" << std::endl; + +for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + +std::string name(iter->first); + +if (name == "H(1)" || name == "E" || name == "H" || name == "O" + || name == "Charge") + continue; + +struct element *elt; + +char *element_name = string_hsave(name.c_str()); + +elt = element_store(element_name); + +assert(elt != NULL); + +struct species *s_ptr; + +s_ptr = elt->master->s; + +assert(s_ptr != NULL); + +chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> + z << ")" << std::endl; + // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr-> - name << ", 1e-9, liter, 1.0e-9)" << std::endl; - } chemistry_dat << std::endl; - } void - -cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) -{ - chemistry_dat << std:: - endl << "//********* Define total hydrogen and oxygen" << std::endl; - + chemistry_dat << "@primary_entity(" << s_ptr-> + name << ", 1e-9, liter, 1.0e-9)" << std::endl; + +} +chemistry_dat << std::endl; +} + +void + +cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) +{ + +chemistry_dat << std:: + endl << "//********* Define total hydrogen and oxygen" << std::endl; + + // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - int i; - for (i = 0; i < count_s_x; i++) - - { - + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + +chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + +int i; + +for (i = 0; i < count_s_x; i++) + + { + // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - if (s_x[i]->h != 0) - - { - chemistry_dat << "+"; - if (s_x[i]->h != 1) - - { - chemistry_dat << s_x[i]->h << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + +if (s_x[i]->h != 0) + + { + +chemistry_dat << "+"; + +if (s_x[i]->h != 1) + + { + +chemistry_dat << s_x[i]->h << "*"; + +} + +chemistry_dat << "{" << s_x[i]->name << ".liter}"; + +} + +} + +} + +chemistry_dat << "\")" << std::endl; + + // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - for (i = 0; i < count_s_x; i++) - - { - if (s_x[i]->o != 0) - - { - + chemistry_dat << "@var: total_oxygen 0" << std::endl; + +chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + +for (i = 0; i < count_s_x; i++) + + { + +if (s_x[i]->o != 0) + + { + // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - chemistry_dat << "+"; - if (s_x[i]->o != 1) - - { - chemistry_dat << s_x[i]->o << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - chemistry_dat << std::endl; - } - void -cxxSystem::ORCH_write_input(std::ostream & input_dat) -{ - + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + +chemistry_dat << "+"; + +if (s_x[i]->o != 1) + + { + +chemistry_dat << s_x[i]->o << "*"; + +} + +chemistry_dat << "{" << s_x[i]->name << ".liter}"; + +} + +} + +} + +chemistry_dat << "\")" << std::endl; + +chemistry_dat << std::endl; +} +void +cxxSystem::ORCH_write_input(std::ostream & input_dat) +{ + + + // // Write orchestra input file info // - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; - headings << "tempc\t"; - data << this->solution->get_tc() << "\t"; - headings << "pH\t"; - data << this->solution->get_ph() << "\t"; - headings << "pe\t"; - data << this->solution->get_pe() << "\t"; - headings << "H2O.act\t"; - data << 1 << "\t"; - headings << "I\t"; - data << this->solution->get_mu() << "\t"; - for (cxxNameDouble::iterator iter = this->orch_totals.begin(); - iter != this->orch_totals.end(); ++iter) - - { - headings << iter->first << ".liter" << "\t"; - data << iter->second << "\t"; - } - + std::ostringstream headings, data; + +data.precision(DBL_DIG - 1); + +headings << "var: "; + +data << "data: "; + + +headings << "tempc\t"; + +data << this->solution->get_tc() << "\t"; + + +headings << "pH\t"; + +data << this->solution->get_ph() << "\t"; + + +headings << "pe\t"; + +data << this->solution->get_pe() << "\t"; + + +headings << "H2O.act\t"; + +data << 1 << "\t"; + + +headings << "I\t"; + +data << this->solution->get_mu() << "\t"; + + +for (cxxNameDouble::iterator iter = this->orch_totals.begin(); + iter != this->orch_totals.end(); ++iter) + + { + +headings << iter->first << ".liter" << "\t"; + +data << iter->second << "\t"; + +} + + // activity estimate - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - - { - if (iter->first == "O" || iter->first == "Charge") - continue; - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch(iter->first); - assert(master_ptr != NULL); - cxxNameDouble ma = this->solution->get_master_activity(); - cxxNameDouble::iterator it = ma.find(iter->first); - if (it == ma.end()) - - { - it = ma.find(master_ptr->s->secondary->elt->name); - } - headings << master_ptr->s->name << ".act\t"; - if (it != ma.end()) - - { - data << pow(10., it->second) << "\t"; - } - else - - { - data << 1e-9 << "\t"; - } - } - + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + +if (iter->first == "O" || iter->first == "Charge") + continue; + +std::string master_name; + +struct master *master_ptr; + +master_ptr = master_bsearch(iter->first); + +assert(master_ptr != NULL); + + +cxxNameDouble ma = this->solution->get_master_activity(); + +cxxNameDouble::iterator it = ma.find(iter->first); + +if (it == ma.end()) + + { + +it = ma.find(master_ptr->s->secondary->elt->name); + +} + +headings << master_ptr->s->name << ".act\t"; + +if (it != ma.end()) + + { + +data << pow(10., it->second) << "\t"; + +} + else + + { + +data << 1e-9 << "\t"; + +} + +} + + // Isotopes //s_oss << "-Isotopes" << std::endl; /* @@ -333,188 +499,257 @@ cxxSystem::ORCH_write_input(std::ostream & input_dat) it->dump_raw(s_oss, indent + 2); } } - */ - + */ + // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; - return; - } - void -cxxSystem::ORCH_components(void) -{ - + input_dat << headings.str() << std::endl; + +input_dat << data.str() << std::endl; + + +return; +} + +void +cxxSystem::ORCH_components(void) +{ + // translate from H, O, charge to H+tot, e-tot, and H2Otot - cxxNameDouble::iterator it; - cxxNameDouble temp_totals; - + cxxNameDouble::iterator it; + +cxxNameDouble temp_totals; + // // Set names in orch_totals to master species names // - this->orch_totals.clear(); - temp_totals = this->totals; - temp_totals.erase("H"); - temp_totals.erase("O"); - temp_totals.erase("Charge"); - + this->orch_totals.clear(); + +temp_totals = this->totals; + +temp_totals.erase("H"); + +temp_totals.erase("O"); + +temp_totals.erase("Charge"); + //temp_totals.dump_raw(std::cerr, 1); - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - assert(elt_ptr != NULL); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - assert(master_ptr != NULL); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - - { - coef = 1; - } - this->orch_totals[master_ptr->s->name] = it->second / coef; - } - + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +assert(elt_ptr != NULL); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +assert(master_ptr != NULL); + +double coef = master_ptr->coef; + +if (master_ptr->coef == 0) + + { + +coef = 1; + +} + +this->orch_totals[master_ptr->s->name] = it->second / coef; + +} + // // Calculate h2otot // - it = this->totals.find("O"); - assert(it != this->totals.end()); - double h2otot = it->second; - + it = this->totals.find("O"); + +assert(it != this->totals.end()); + +double h2otot = it->second; + // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - h2otot -= it->second * master_ptr->s->o; - } + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +h2otot -= it->second * master_ptr->s->o; + +} // // Calculate htot // - it = this->totals.find("H"); - assert(it != this->totals.end()); - double htot = it->second - 2 * h2otot; - + it = this->totals.find("H"); + +assert(it != this->totals.end()); + +double htot = it->second - 2 * h2otot; + // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - htot -= it->second * master_ptr->s->h; - } + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +htot -= it->second * master_ptr->s->h; + +} // // Calculate etot // - it = this->totals.find("Charge"); - assert(it != this->totals.end()); - double etot = -it->second + htot; - + it = this->totals.find("Charge"); + +assert(it != this->totals.end()); + +double etot = -it->second + htot; + // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - etot += it->second * master_ptr->s->z; - } + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +etot += it->second * master_ptr->s->z; + +} // // store h2otot, htot, etot in orch_totals // - this->orch_totals["H2O"] = h2otot; - this->orch_totals["H+"] = htot; - this->orch_totals["e-"] = etot; - this->orch_totals.dump_raw(std::cerr, 1); - } void - -cxxSystem::ORCH_write_output_vars(std::ostream & outstream) -{ - outstream << "\tnr_iter"; - + this->orch_totals["H2O"] = h2otot; + +this->orch_totals["H+"] = htot; + +this->orch_totals["e-"] = etot; + +this->orch_totals.dump_raw(std::cerr, 1); +} +void + +cxxSystem::ORCH_write_output_vars(std::ostream & outstream) +{ + +outstream << "\tnr_iter"; + // // Serialize solution // - outstream << "\tstart_solution"; - + outstream << "\tstart_solution"; + //tc - outstream << "\ttempc"; - + outstream << "\ttempc"; + //pH - outstream << "\tpH"; - + outstream << "\tpH"; + //pe - outstream << "\tpe"; - + outstream << "\tpe"; + //mu - outstream << "\tI"; - + outstream << "\tI"; + //ah2o - outstream << "\tH2O.act"; - + outstream << "\tH2O.act"; + //total_h; - outstream << "\ttotal_hydrogen"; - + outstream << "\ttotal_hydrogen"; + //total_o; - outstream << "\ttotal_oxygen"; - + outstream << "\ttotal_oxygen"; + //cb - outstream << "\tchargebalance"; - + outstream << "\tchargebalance"; + //mass_water; - outstream << "\tH2O.con"; - + outstream << "\tH2O.con"; + //total_alkalinity; - outstream << "\tAlkalinity"; - + outstream << "\tAlkalinity"; + //orchestra master variables - outstream << "\tH+.diss"; - outstream << "\te-.diss"; - outstream << "\tH2O.diss"; - + outstream << "\tH+.diss"; + +outstream << "\te-.diss"; + +outstream << "\tH2O.diss"; + // // Write totals - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - - { - if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - outstream << "\t" << it->first << ".diss"; - } - outstream << "\tend_totals"; - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - - { - if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - outstream << "\t" << it->first << ".act"; - } - outstream << "\tend_master_activities"; - + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + +if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + +outstream << "\t" << it->first << ".diss"; + +} + +outstream << "\tend_totals"; + +for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + +if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + +outstream << "\t" << it->first << ".act"; + +} + +outstream << "\tend_master_activities"; + // // Write all species activities and concentrations // - int i; - for (i = 0; i < count_s_x; i++) - { - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - outstream << "\t" << name.c_str() << ".act" << "\t" << name. - c_str() << ".con"; - } - outstream << "\tend_species"; - } - + int i; -#endif /* */ +for (i = 0; i < count_s_x; i++) + { + +std::string name(s_x[i]->name); + +std::replace(name.begin(), name.end(), '(', '['); + +std::replace(name.begin(), name.end(), ')', ']'); + +outstream << "\t" << name.c_str() << ".act" << "\t" << name. + c_str() << ".con"; + +} + +outstream << "\tend_species"; +} + + +#endif /* + */ From 9f7e982ffee5028fd1dd9527976ad603c7b2c2ee Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Dec 2009 00:56:22 +0000 Subject: [PATCH 0112/1077] eol git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3842 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 308a859b..4785e784 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -23,7 +23,7 @@ cxxExchange::cxxExchange() // - // default constructor for cxxExchange + // default constructor for cxxExchange // : cxxNumKeyword() { @@ -127,7 +127,7 @@ cxxNumKeyword() ec.set_phase_proportion(x[i]->exch_comp->phase_proportion); //char *rate_name; ec.set_rate_name(x[i]->exch_comp->rate_name); - //double formula_z; + //double formula_z; ec.set_formula_z(x[i]->exch_comp->formula_z); // calculate charge and totals @@ -200,7 +200,7 @@ cxxExchange::get_related_rate() struct exchange * cxxExchange::cxxExchange2exchange() // - // Builds a exchange structure from instance of cxxExchange + // Builds a exchange structure from instance of cxxExchange // { struct exchange *exchange_ptr = exchange_alloc(); @@ -486,7 +486,7 @@ cxxExchange::add(const cxxExchange & addee, double extensive) // } //} /*if (!found)*/ - + } else { From 51183867e444f190e816eaac19b16871f4db3228 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Dec 2009 01:06:34 +0000 Subject: [PATCH 0113/1077] eol git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3844 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- System.cxx | 1510 ++++++++++++++++++++++++++-------------------------- phast.xsd | 196 +++---- test.xml | 140 ++--- 3 files changed, 923 insertions(+), 923 deletions(-) diff --git a/System.cxx b/System.cxx index 053551b8..79d1a839 100644 --- a/System.cxx +++ b/System.cxx @@ -1,755 +1,755 @@ -#include "System.h" -#include // std::replace -extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); -cxxSystem::cxxSystem(void) -{ - -this->solution = NULL; - -this->exchange = NULL; - -this->ppassemblage = NULL; - -this->gasphase = NULL; - -this->ssassemblage = NULL; - -this->kinetics = NULL; - -this->surface = NULL; - -this->mix = NULL; - -this->reaction = NULL; - -this->temperature = NULL; -} - -cxxSystem::~cxxSystem(void) -{ -} - -void -cxxSystem::Initialize(void) -{ - -this->solution = NULL; - -this->exchange = NULL; - -this->ppassemblage = NULL; - -this->gasphase = NULL; - -this->ssassemblage = NULL; - -this->kinetics = NULL; - -this->surface = NULL; - -this->mix = NULL; - -this->reaction = NULL; - -this->temperature = NULL; -} -void -cxxSystem::totalize(void) -{ - - //initialize - this->totals.clear(); - - //add solution - if (this->solution != NULL) - - { - -char token[MAX_LENGTH]; - -strcpy(token, "O"); - -this->totals[token] = this->solution->get_total_o(); - -strcpy(token, "H"); - -this->totals[token] = this->solution->get_total_h(); - -strcpy(token, "Charge"); - -this->totals[token] = this->solution->get_cb(); - -this->totals.add_extensive(this->solution->get_totals(), 1.0); - -} - -if (this->exchange != NULL) - - { - -this->exchange->totalize(); - -this->totals.add_extensive(this->exchange->get_totals(), 1.0); - -} - -if (this->ppassemblage != NULL) - - { - -this->ppassemblage->totalize(); - -this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); - -} - -if (this->gasphase != NULL) - - { - -this->gasphase->totalize(); - -this->totals.add_extensive(this->gasphase->get_totals(), 1.0); - -} - -if (this->ssassemblage != NULL) - - { - -this->ssassemblage->totalize(); - -this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); - -} - -if (this->surface != NULL) - - { - -this->ssassemblage->totalize(); - -this->totals.add_extensive(this->surface->get_totals(), 1.0); - -} - - - //Need to handle the following 3 reactions: - // - //this->kinetics = NULL; - //this->mix = NULL; - //this->reaction = NULL; - //this->temperature = NULL; - //this->totals.dump_raw(std::cerr, 1); - return; -} - - -#ifdef ORCHESTRA - void -cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat) -{ - - // - // chemistry file - // - this->totalize(); - - // calculate orchestra components from PHREEQC totals - this->ORCH_components(); - - // write definitions for chemistry - chemistry_dat << std:: - endl << "@class: species_reactions () {" << std::endl; - -this->ORCH_write_chemistry_water(chemistry_dat); - -this->ORCH_write_chemistry_primary(chemistry_dat); - -this->ORCH_write_chemistry_total_O_H(chemistry_dat); - -ORCH_write_chemistry_species(chemistry_dat); - - - // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - - - // add definitions for other PHREEQC entities here - - // finish up - chemistry_dat << std::endl << "}" << std::endl; - - // - // input file - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - -this->ORCH_write_input(input_dat); - -input_dat << std::endl << "}" << std::endl; - - // - // output file - // - output_dat << std::endl << "Output_every: 1" << std::endl; - -output_dat << "Var:"; - -this->ORCH_write_output_vars(output_dat); - - // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_output_vars(output_dat); - - - //finish up - output_dat << std::endl; -}; - -void -cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) -{ - - // - // Write water entities - // - chemistry_dat << std:: - endl << "//********* The water entities" << std::endl; - - - // e-, total hydrogen - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - -chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - -chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: - endl; - - - // H+, charge balance - chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - -chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: - endl; - - - // H2O - chemistry_dat << "@entity(" << s_h2o-> - name << ", diss, 55.506)" << std::endl; - -chemistry_dat << std::endl; -} - -void - -cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) -{ - -chemistry_dat << std::endl << "//********* The primary species" << std:: - endl; - - // - // Write other master species definitions, i.e. primary entities - // - chemistry_dat << "@species(H+, 1)" << std::endl; - -for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - - { - -std::string name(iter->first); - -if (name == "H(1)" || name == "E" || name == "H" || name == "O" - || name == "Charge") - continue; - -struct element *elt; - -char *element_name = string_hsave(name.c_str()); - -elt = element_store(element_name); - -assert(elt != NULL); - -struct species *s_ptr; - -s_ptr = elt->master->s; - -assert(s_ptr != NULL); - -chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> - z << ")" << std::endl; - - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr-> - name << ", 1e-9, liter, 1.0e-9)" << std::endl; - -} -chemistry_dat << std::endl; -} - -void - -cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) -{ - -chemistry_dat << std:: - endl << "//********* Define total hydrogen and oxygen" << std::endl; - - - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - -chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - -int i; - -for (i = 0; i < count_s_x; i++) - - { - - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - -if (s_x[i]->h != 0) - - { - -chemistry_dat << "+"; - -if (s_x[i]->h != 1) - - { - -chemistry_dat << s_x[i]->h << "*"; - -} - -chemistry_dat << "{" << s_x[i]->name << ".liter}"; - -} - -} - -} - -chemistry_dat << "\")" << std::endl; - - - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - -chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - -for (i = 0; i < count_s_x; i++) - - { - -if (s_x[i]->o != 0) - - { - - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - -chemistry_dat << "+"; - -if (s_x[i]->o != 1) - - { - -chemistry_dat << s_x[i]->o << "*"; - -} - -chemistry_dat << "{" << s_x[i]->name << ".liter}"; - -} - -} - -} - -chemistry_dat << "\")" << std::endl; - -chemistry_dat << std::endl; -} -void -cxxSystem::ORCH_write_input(std::ostream & input_dat) -{ - - - -// -// Write orchestra input file info -// - std::ostringstream headings, data; - -data.precision(DBL_DIG - 1); - -headings << "var: "; - -data << "data: "; - - -headings << "tempc\t"; - -data << this->solution->get_tc() << "\t"; - - -headings << "pH\t"; - -data << this->solution->get_ph() << "\t"; - - -headings << "pe\t"; - -data << this->solution->get_pe() << "\t"; - - -headings << "H2O.act\t"; - -data << 1 << "\t"; - - -headings << "I\t"; - -data << this->solution->get_mu() << "\t"; - - -for (cxxNameDouble::iterator iter = this->orch_totals.begin(); - iter != this->orch_totals.end(); ++iter) - - { - -headings << iter->first << ".liter" << "\t"; - -data << iter->second << "\t"; - -} - - - // activity estimate - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - - { - -if (iter->first == "O" || iter->first == "Charge") - continue; - -std::string master_name; - -struct master *master_ptr; - -master_ptr = master_bsearch(iter->first); - -assert(master_ptr != NULL); - - -cxxNameDouble ma = this->solution->get_master_activity(); - -cxxNameDouble::iterator it = ma.find(iter->first); - -if (it == ma.end()) - - { - -it = ma.find(master_ptr->s->secondary->elt->name); - -} - -headings << master_ptr->s->name << ".act\t"; - -if (it != ma.end()) - - { - -data << pow(10., it->second) << "\t"; - -} - else - - { - -data << 1e-9 << "\t"; - -} - -} - - - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - // Write data to string - input_dat << headings.str() << std::endl; - -input_dat << data.str() << std::endl; - - -return; -} - -void -cxxSystem::ORCH_components(void) -{ - - // translate from H, O, charge to H+tot, e-tot, and H2Otot - cxxNameDouble::iterator it; - -cxxNameDouble temp_totals; - - // - // Set names in orch_totals to master species names - // - this->orch_totals.clear(); - -temp_totals = this->totals; - -temp_totals.erase("H"); - -temp_totals.erase("O"); - -temp_totals.erase("Charge"); - - //temp_totals.dump_raw(std::cerr, 1); - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -assert(elt_ptr != NULL); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -assert(master_ptr != NULL); - -double coef = master_ptr->coef; - -if (master_ptr->coef == 0) - - { - -coef = 1; - -} - -this->orch_totals[master_ptr->s->name] = it->second / coef; - -} - - // - // Calculate h2otot - // - it = this->totals.find("O"); - -assert(it != this->totals.end()); - -double h2otot = it->second; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -h2otot -= it->second * master_ptr->s->o; - -} - // - // Calculate htot - // - it = this->totals.find("H"); - -assert(it != this->totals.end()); - -double htot = it->second - 2 * h2otot; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -htot -= it->second * master_ptr->s->h; - -} - // - // Calculate etot - // - it = this->totals.find("Charge"); - -assert(it != this->totals.end()); - -double etot = -it->second + htot; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - - { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -etot += it->second * master_ptr->s->z; - -} - // - // store h2otot, htot, etot in orch_totals - // - this->orch_totals["H2O"] = h2otot; - -this->orch_totals["H+"] = htot; - -this->orch_totals["e-"] = etot; - -this->orch_totals.dump_raw(std::cerr, 1); -} -void - -cxxSystem::ORCH_write_output_vars(std::ostream & outstream) -{ - -outstream << "\tnr_iter"; - - // - // Serialize solution - // - outstream << "\tstart_solution"; - - //tc - outstream << "\ttempc"; - - //pH - outstream << "\tpH"; - - //pe - outstream << "\tpe"; - - //mu - outstream << "\tI"; - - //ah2o - outstream << "\tH2O.act"; - - //total_h; - outstream << "\ttotal_hydrogen"; - - //total_o; - outstream << "\ttotal_oxygen"; - - //cb - outstream << "\tchargebalance"; - - //mass_water; - outstream << "\tH2O.con"; - - //total_alkalinity; - outstream << "\tAlkalinity"; - - //orchestra master variables - outstream << "\tH+.diss"; - -outstream << "\te-.diss"; - -outstream << "\tH2O.diss"; - - // - // Write totals - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - - { - -if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - -outstream << "\t" << it->first << ".diss"; - -} - -outstream << "\tend_totals"; - -for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - - { - -if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - -outstream << "\t" << it->first << ".act"; - -} - -outstream << "\tend_master_activities"; - - // - // Write all species activities and concentrations - // - int i; - -for (i = 0; i < count_s_x; i++) - { - -std::string name(s_x[i]->name); - -std::replace(name.begin(), name.end(), '(', '['); - -std::replace(name.begin(), name.end(), ')', ']'); - -outstream << "\t" << name.c_str() << ".act" << "\t" << name. - c_str() << ".con"; - -} - -outstream << "\tend_species"; -} - - -#endif /* - */ +#include "System.h" +#include // std::replace +extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); +cxxSystem::cxxSystem(void) +{ + +this->solution = NULL; + +this->exchange = NULL; + +this->ppassemblage = NULL; + +this->gasphase = NULL; + +this->ssassemblage = NULL; + +this->kinetics = NULL; + +this->surface = NULL; + +this->mix = NULL; + +this->reaction = NULL; + +this->temperature = NULL; +} + +cxxSystem::~cxxSystem(void) +{ +} + +void +cxxSystem::Initialize(void) +{ + +this->solution = NULL; + +this->exchange = NULL; + +this->ppassemblage = NULL; + +this->gasphase = NULL; + +this->ssassemblage = NULL; + +this->kinetics = NULL; + +this->surface = NULL; + +this->mix = NULL; + +this->reaction = NULL; + +this->temperature = NULL; +} +void +cxxSystem::totalize(void) +{ + + //initialize + this->totals.clear(); + + //add solution + if (this->solution != NULL) + + { + +char token[MAX_LENGTH]; + +strcpy(token, "O"); + +this->totals[token] = this->solution->get_total_o(); + +strcpy(token, "H"); + +this->totals[token] = this->solution->get_total_h(); + +strcpy(token, "Charge"); + +this->totals[token] = this->solution->get_cb(); + +this->totals.add_extensive(this->solution->get_totals(), 1.0); + +} + +if (this->exchange != NULL) + + { + +this->exchange->totalize(); + +this->totals.add_extensive(this->exchange->get_totals(), 1.0); + +} + +if (this->ppassemblage != NULL) + + { + +this->ppassemblage->totalize(); + +this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + +} + +if (this->gasphase != NULL) + + { + +this->gasphase->totalize(); + +this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + +} + +if (this->ssassemblage != NULL) + + { + +this->ssassemblage->totalize(); + +this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + +} + +if (this->surface != NULL) + + { + +this->ssassemblage->totalize(); + +this->totals.add_extensive(this->surface->get_totals(), 1.0); + +} + + + //Need to handle the following 3 reactions: + // + //this->kinetics = NULL; + //this->mix = NULL; + //this->reaction = NULL; + //this->temperature = NULL; + //this->totals.dump_raw(std::cerr, 1); + return; +} + + +#ifdef ORCHESTRA + void +cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, + std::ostream & output_dat) +{ + + // + // chemistry file + // + this->totalize(); + + // calculate orchestra components from PHREEQC totals + this->ORCH_components(); + + // write definitions for chemistry + chemistry_dat << std:: + endl << "@class: species_reactions () {" << std::endl; + +this->ORCH_write_chemistry_water(chemistry_dat); + +this->ORCH_write_chemistry_primary(chemistry_dat); + +this->ORCH_write_chemistry_total_O_H(chemistry_dat); + +ORCH_write_chemistry_species(chemistry_dat); + + + // add definitions for pure phases + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_chemistry(chemistry_dat); + + + // add definitions for other PHREEQC entities here + + // finish up + chemistry_dat << std::endl << "}" << std::endl; + + // + // input file + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + +this->ORCH_write_input(input_dat); + +input_dat << std::endl << "}" << std::endl; + + // + // output file + // + output_dat << std::endl << "Output_every: 1" << std::endl; + +output_dat << "Var:"; + +this->ORCH_write_output_vars(output_dat); + + // add definitions for pure phases + if (this->ppassemblage != NULL) + this->ppassemblage->ORCH_write_output_vars(output_dat); + + + //finish up + output_dat << std::endl; +}; + +void +cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) +{ + + // + // Write water entities + // + chemistry_dat << std:: + endl << "//********* The water entities" << std::endl; + + + // e-, total hydrogen + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + +chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; + +chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: + endl; + + + // H+, charge balance + chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; + +chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: + endl; + + + // H2O + chemistry_dat << "@entity(" << s_h2o-> + name << ", diss, 55.506)" << std::endl; + +chemistry_dat << std::endl; +} + +void + +cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) +{ + +chemistry_dat << std::endl << "//********* The primary species" << std:: + endl; + + // + // Write other master species definitions, i.e. primary entities + // + chemistry_dat << "@species(H+, 1)" << std::endl; + +for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + +std::string name(iter->first); + +if (name == "H(1)" || name == "E" || name == "H" || name == "O" + || name == "Charge") + continue; + +struct element *elt; + +char *element_name = string_hsave(name.c_str()); + +elt = element_store(element_name); + +assert(elt != NULL); + +struct species *s_ptr; + +s_ptr = elt->master->s; + +assert(s_ptr != NULL); + +chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> + z << ")" << std::endl; + + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr-> + name << ", 1e-9, liter, 1.0e-9)" << std::endl; + +} +chemistry_dat << std::endl; +} + +void + +cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) +{ + +chemistry_dat << std:: + endl << "//********* Define total hydrogen and oxygen" << std::endl; + + + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + +chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + +int i; + +for (i = 0; i < count_s_x; i++) + + { + + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + +if (s_x[i]->h != 0) + + { + +chemistry_dat << "+"; + +if (s_x[i]->h != 1) + + { + +chemistry_dat << s_x[i]->h << "*"; + +} + +chemistry_dat << "{" << s_x[i]->name << ".liter}"; + +} + +} + +} + +chemistry_dat << "\")" << std::endl; + + + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + +chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + +for (i = 0; i < count_s_x; i++) + + { + +if (s_x[i]->o != 0) + + { + + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + + { + +chemistry_dat << "+"; + +if (s_x[i]->o != 1) + + { + +chemistry_dat << s_x[i]->o << "*"; + +} + +chemistry_dat << "{" << s_x[i]->name << ".liter}"; + +} + +} + +} + +chemistry_dat << "\")" << std::endl; + +chemistry_dat << std::endl; +} +void +cxxSystem::ORCH_write_input(std::ostream & input_dat) +{ + + + +// +// Write orchestra input file info +// + std::ostringstream headings, data; + +data.precision(DBL_DIG - 1); + +headings << "var: "; + +data << "data: "; + + +headings << "tempc\t"; + +data << this->solution->get_tc() << "\t"; + + +headings << "pH\t"; + +data << this->solution->get_ph() << "\t"; + + +headings << "pe\t"; + +data << this->solution->get_pe() << "\t"; + + +headings << "H2O.act\t"; + +data << 1 << "\t"; + + +headings << "I\t"; + +data << this->solution->get_mu() << "\t"; + + +for (cxxNameDouble::iterator iter = this->orch_totals.begin(); + iter != this->orch_totals.end(); ++iter) + + { + +headings << iter->first << ".liter" << "\t"; + +data << iter->second << "\t"; + +} + + + // activity estimate + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) + + { + +if (iter->first == "O" || iter->first == "Charge") + continue; + +std::string master_name; + +struct master *master_ptr; + +master_ptr = master_bsearch(iter->first); + +assert(master_ptr != NULL); + + +cxxNameDouble ma = this->solution->get_master_activity(); + +cxxNameDouble::iterator it = ma.find(iter->first); + +if (it == ma.end()) + + { + +it = ma.find(master_ptr->s->secondary->elt->name); + +} + +headings << master_ptr->s->name << ".act\t"; + +if (it != ma.end()) + + { + +data << pow(10., it->second) << "\t"; + +} + else + + { + +data << 1e-9 << "\t"; + +} + +} + + + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + + // Write data to string + input_dat << headings.str() << std::endl; + +input_dat << data.str() << std::endl; + + +return; +} + +void +cxxSystem::ORCH_components(void) +{ + + // translate from H, O, charge to H+tot, e-tot, and H2Otot + cxxNameDouble::iterator it; + +cxxNameDouble temp_totals; + + // + // Set names in orch_totals to master species names + // + this->orch_totals.clear(); + +temp_totals = this->totals; + +temp_totals.erase("H"); + +temp_totals.erase("O"); + +temp_totals.erase("Charge"); + + //temp_totals.dump_raw(std::cerr, 1); + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +assert(elt_ptr != NULL); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +assert(master_ptr != NULL); + +double coef = master_ptr->coef; + +if (master_ptr->coef == 0) + + { + +coef = 1; + +} + +this->orch_totals[master_ptr->s->name] = it->second / coef; + +} + + // + // Calculate h2otot + // + it = this->totals.find("O"); + +assert(it != this->totals.end()); + +double h2otot = it->second; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +h2otot -= it->second * master_ptr->s->o; + +} + // + // Calculate htot + // + it = this->totals.find("H"); + +assert(it != this->totals.end()); + +double htot = it->second - 2 * h2otot; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +htot -= it->second * master_ptr->s->h; + +} + // + // Calculate etot + // + it = this->totals.find("Charge"); + +assert(it != this->totals.end()); + +double etot = -it->second + htot; + + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) + + { + +struct element *elt_ptr; + +elt_ptr = element_store(it->first); + +struct master *master_ptr; + +master_ptr = elt_ptr->primary; + +etot += it->second * master_ptr->s->z; + +} + // + // store h2otot, htot, etot in orch_totals + // + this->orch_totals["H2O"] = h2otot; + +this->orch_totals["H+"] = htot; + +this->orch_totals["e-"] = etot; + +this->orch_totals.dump_raw(std::cerr, 1); +} +void + +cxxSystem::ORCH_write_output_vars(std::ostream & outstream) +{ + +outstream << "\tnr_iter"; + + // + // Serialize solution + // + outstream << "\tstart_solution"; + + //tc + outstream << "\ttempc"; + + //pH + outstream << "\tpH"; + + //pe + outstream << "\tpe"; + + //mu + outstream << "\tI"; + + //ah2o + outstream << "\tH2O.act"; + + //total_h; + outstream << "\ttotal_hydrogen"; + + //total_o; + outstream << "\ttotal_oxygen"; + + //cb + outstream << "\tchargebalance"; + + //mass_water; + outstream << "\tH2O.con"; + + //total_alkalinity; + outstream << "\tAlkalinity"; + + //orchestra master variables + outstream << "\tH+.diss"; + +outstream << "\te-.diss"; + +outstream << "\tH2O.diss"; + + // + // Write totals + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + +if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + +outstream << "\t" << it->first << ".diss"; + +} + +outstream << "\tend_totals"; + +for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) + + { + +if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + continue; + +outstream << "\t" << it->first << ".act"; + +} + +outstream << "\tend_master_activities"; + + // + // Write all species activities and concentrations + // + int i; + +for (i = 0; i < count_s_x; i++) + { + +std::string name(s_x[i]->name); + +std::replace(name.begin(), name.end(), '(', '['); + +std::replace(name.begin(), name.end(), ')', ']'); + +outstream << "\t" << name.c_str() << ".act" << "\t" << name. + c_str() << ".con"; + +} + +outstream << "\tend_species"; +} + + +#endif /* + */ diff --git a/phast.xsd b/phast.xsd index e2b59f7d..1e6c660e 100644 --- a/phast.xsd +++ b/phast.xsd @@ -1,98 +1,98 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test.xml b/test.xml index 72bbd502..ed476808 100644 --- a/test.xml +++ b/test.xml @@ -1,70 +1,70 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + From dd1c83edecf4da8a338490ef20fe5c5af6dc4d83 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Dec 2009 01:14:07 +0000 Subject: [PATCH 0114/1077] eol git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3846 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- System.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/System.h b/System.h index 4fb27500..92e9ca36 100644 --- a/System.h +++ b/System.h @@ -10,7 +10,7 @@ #include "cxxMix.h" #include "Reaction.h" #include "Temperature.h" -class cxxSystem +class cxxSystem { public:cxxSystem(void); public: ~cxxSystem(void); @@ -46,7 +46,7 @@ class cxxSystem { this->temperature = entity; } void totalize(); - + #ifdef ORCHESTRA void ORCH_components(); void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, @@ -56,7 +56,7 @@ class cxxSystem void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); void ORCH_write_output_vars(std::ostream & outstream); void ORCH_write_input(std::ostream & input_dat); - + #endif /* */ private:cxxSolution * solution; cxxExchange * exchange; From 07d5fa74136e49cb6e632a4122cb094f0aade661 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 3 Dec 2009 01:49:56 +0000 Subject: [PATCH 0115/1077] merged 3750-3846 of plusify; system.cxx and system.h need to be formated removed char * and used std::string's and std::map's git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3847 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cxx | 19 ++ Dictionary.h | 1 + ExchComp.cxx | 78 ++--- ExchComp.h | 29 +- Exchange.cxx | 4 +- Exchange.h | 8 +- GasPhase.cxx | 7 +- GasPhase.h | 7 +- ISolution.cxx | 15 +- ISolution.h | 10 +- ISolutionComp.cxx | 38 +-- ISolutionComp.h | 52 ++-- KineticsComp.cxx | 18 +- KineticsComp.h | 25 +- NameDouble.cxx | 40 ++- NameDouble.h | 5 +- PPassemblage.h | 9 +- PPassemblageComp.cxx | 48 ++-- PPassemblageComp.h | 31 +- Parser.cxx | 68 ++--- Parser.h | 7 +- Reaction.cxx | 11 +- Reaction.h | 20 +- SSassemblage.h | 1 - SSassemblageSS.cxx | 21 +- SSassemblageSS.h | 17 +- Solution.cxx | 4 +- Solution.h | 2 - SolutionIsotope.cxx | 19 +- SolutionIsotope.h | 24 +- SolutionIsotopeList.cxx | 2 +- SolutionIsotopeList.h | 18 +- Surface.cxx | 8 +- Surface.h | 11 +- SurfaceCharge.cxx | 14 +- SurfaceCharge.h | 18 +- SurfaceComp.cxx | 65 +++-- SurfaceComp.h | 76 +++-- System.cxx | 623 ++++++++++++++++++++-------------------- System.h | 9 +- Temperature.h | 8 +- Utils.h | 1 - 42 files changed, 829 insertions(+), 662 deletions(-) diff --git a/Dictionary.cxx b/Dictionary.cxx index 4566fa55..a2e64ac3 100644 --- a/Dictionary.cxx +++ b/Dictionary.cxx @@ -55,6 +55,9 @@ cxxDictionary::add_phreeqc() } } } + this->putString(std::string("")); + + } int @@ -123,6 +126,21 @@ std::string * cxxDictionary::int2string(int i) } } +std::string & cxxDictionary::int2stdstring(int i) +{ + std::map < int, + std::string >::iterator + it = intkey.find(i); + if (it != intkey.end()) + { + return (it->second); + } + else + { + exit(4); + } +} + char * cxxDictionary::int2char(int i) { @@ -136,3 +154,4 @@ cxxDictionary::int2char(int i) return (NULL); } } + diff --git a/Dictionary.h b/Dictionary.h index 8d3f96af..43ad36b3 100644 --- a/Dictionary.h +++ b/Dictionary.h @@ -32,6 +32,7 @@ class cxxDictionary int string2int(char *str); std::string * int2string(int i); + std::string & int2stdstring(int i); char *int2char(int i); diff --git a/ExchComp.cxx b/ExchComp.cxx index 959837ad..15c1b178 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -30,9 +30,9 @@ cxxExchComp::cxxExchComp() totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; charge_balance = 0.0; - phase_name = NULL; + //phase_name = NULL; phase_proportion = 0.0; - rate_name = NULL; + //rate_name = NULL; formula_z = 0.0; } @@ -43,15 +43,15 @@ cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr) : formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) { - formula = exch_comp_ptr->formula; + this->set_formula(exch_comp_ptr->formula); moles = exch_comp_ptr->moles; // totals in constructor //formula_totals in constructor la = exch_comp_ptr->la; charge_balance = exch_comp_ptr->charge_balance; - phase_name = exch_comp_ptr->phase_name; + this->set_phase_name(exch_comp_ptr->phase_name); phase_proportion = exch_comp_ptr->phase_proportion; - rate_name = exch_comp_ptr->rate_name; + this->set_rate_name(exch_comp_ptr->rate_name); formula_z = exch_comp_ptr->formula_z; } @@ -125,12 +125,13 @@ struct master * cxxExchComp::get_master() { struct master *master_ptr = NULL; - for (std::map < char *, double, CHARSTAR_LESS >::iterator it = + for (std::map < std::string, double >::iterator it = totals.begin(); it != totals.end(); it++) { /* Find master species */ - char *eltName = it->first; + char *eltName = string_hsave(it->first.c_str()); + assert(it->first.size() != 0); struct element *elt_ptr = element_store(eltName); if (elt_ptr->master == NULL) { @@ -148,12 +149,13 @@ cxxExchComp::get_master() } if (master_ptr == NULL) { - for (std::map < char *, double, CHARSTAR_LESS >::iterator it = + for (std::map < std::string, double >::iterator it = this->formula_totals.begin(); it != formula_totals.end(); it++) { /* Find master species */ - char *eltName = it->first; + char *eltName = string_hsave(it->first.c_str()); + assert(it->first.size() != 0); struct element *elt_ptr = element_store(eltName); if (elt_ptr->master == NULL) { @@ -203,16 +205,25 @@ struct exch_comp * for (std::map < std::string, cxxExchComp >::iterator it = el.begin(); it != el.end(); ++it) { - exch_comp_ptr[i].formula = (*it).second.formula; + if ((*it).second.formula.size() == 0) + exch_comp_ptr[i].formula = NULL; + else + exch_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str()); exch_comp_ptr[i].formula_z = (*it).second.formula_z; exch_comp_ptr[i].totals = (*it).second.totals.elt_list(); exch_comp_ptr[i].moles = (*it).second.moles; exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); exch_comp_ptr[i].la = (*it).second.la; exch_comp_ptr[i].charge_balance = (*it).second.charge_balance; - exch_comp_ptr[i].phase_name = (*it).second.phase_name; + if ((*it).second.phase_name.size() == 0) + exch_comp_ptr[i].phase_name = NULL; + else + exch_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str()); exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; - exch_comp_ptr[i].rate_name = (*it).second.rate_name; + if ((*it).second.rate_name.size() == 0) + exch_comp_ptr[i].rate_name = NULL; + else + exch_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); exch_comp_ptr[i].master = (*it).second.get_master(); i++; } @@ -242,12 +253,11 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; s_oss << indent0 << "charge_balance=\"" << this-> charge_balance << "\"" << std::endl; - if (this->phase_name != NULL) + if (this->phase_name.size() != 0) { - s_oss << indent0 << "phase_name=\"" << this-> - phase_name << "\"" << std::endl; + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; } - if (this->rate_name != NULL) + if (this->rate_name.size() != 0) { s_oss << indent0 << "rate_name=\"" << this-> rate_name << "\"" << std::endl; @@ -297,11 +307,11 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const 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.size() != 0) { s_oss << indent1 << "-phase_name " << this->phase_name << std::endl; } - if (this->rate_name != NULL) + if (this->rate_name.size() != 0) { s_oss << indent1 << "-rate_name " << this->rate_name << std::endl; } @@ -373,14 +383,14 @@ cxxExchComp::read_raw(CParser & parser, bool check) case 0: // formula if (!(parser.get_iss() >> str)) { - this->formula = NULL; + this->formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); } else { - this->formula = string_hsave(str.c_str()); + this->formula = str; } formula_defined = true; break; @@ -421,28 +431,28 @@ cxxExchComp::read_raw(CParser & parser, bool check) case 4: // phase_name if (!(parser.get_iss() >> str)) { - this->phase_name = NULL; + this->phase_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); } else { - this->phase_name = string_hsave(str.c_str()); + this->phase_name = str; } break; case 5: // rate_name if (!(parser.get_iss() >> str)) { - this->rate_name = NULL; + this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); } else { - this->rate_name = string_hsave(str.c_str()); + this->rate_name = str; } break; @@ -538,7 +548,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) double ext1, ext2, f1, f2; if (extensive == 0.0) return; - if (addee.formula == NULL) + if (addee.formula.size() == 0) return; // this and addee must have same formula // otherwise generate a new exchcomp with multiply @@ -558,13 +568,13 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) //char * formula; //cxxNameDouble formula_totals; - if (this->formula == NULL && addee.formula == NULL) + if (this->formula.size() == 0 && addee.formula.size() == 0) { return; } assert(this->formula == addee.formula); assert(this->formula_z == addee.formula_z); - if (this->formula == NULL && addee.formula != NULL) + if (this->formula.size() == 0 && addee.formula.size() != 0) { this->formula = addee.formula; this->formula_totals = addee.formula_totals; @@ -589,7 +599,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) input_error++; return; } - else if (this->phase_name != NULL) + else if (this->phase_name.size() != 0) { this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; @@ -605,14 +615,14 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) input_error++; return; } - else if (this->rate_name != NULL) + else if (this->rate_name.size() != 0) { //double phase_proportion; this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } - if ((this->rate_name != NULL && addee.phase_name != NULL) || - (this->phase_name != NULL && addee.rate_name != NULL)) + if ((this->rate_name.size() != 0 && addee.phase_name.size() != 0) || + (this->phase_name.size() != 0 && addee.rate_name.size() != 0)) { std::ostringstream oss; oss << @@ -665,15 +675,15 @@ cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->formula = dictionary.int2char(ints[i++]); + this->formula = dictionary.int2stdstring(ints[i++]); this->moles = doubles[d++]; this->formula_totals.mpi_unpack(ints, &i, doubles, &d); this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; this->charge_balance = doubles[d++]; - this->phase_name = dictionary.int2char(ints[i++]); + this->phase_name = dictionary.int2stdstring(ints[i++]); this->phase_proportion = doubles[d++]; - this->rate_name = dictionary.int2char(ints[i++]); + this->rate_name = dictionary.int2stdstring(ints[i++]); this->formula_z = doubles[d++]; *ii = i; *dd = d; diff --git a/ExchComp.h b/ExchComp.h index 2cb543d8..6f0797d8 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxExchComp { @@ -31,13 +29,16 @@ class cxxExchComp void read_raw(CParser & parser, bool check=true); - char *get_formula() const + const std::string &get_formula() const { return this->formula; } void set_formula(char *cstring) { - this->formula = cstring; + if (cstring != NULL) + this->formula = std::string(cstring); + else + this->formula.clear(); } double get_moles() const { @@ -63,13 +64,16 @@ class cxxExchComp { this->charge_balance = d; } - char *get_phase_name() const + const std::string &get_phase_name() const { return this->phase_name; } void set_phase_name(char *cstring) { - this->phase_name = cstring; + if (cstring != NULL) + this->phase_name = std::string(cstring); + else + this->phase_name.clear(); } double get_phase_proportion() const { @@ -79,13 +83,16 @@ class cxxExchComp { this->phase_proportion = d; } - char *get_rate_name() const + const std::string &get_rate_name() const { return this->rate_name; } void set_rate_name(char *cstring) { - this->rate_name = cstring; + if (cstring != NULL) + this->rate_name = std::string(cstring); + else + this->rate_name.clear(); } double get_formula_z() const { @@ -135,15 +142,15 @@ class cxxExchComp void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif protected: - char *formula; + std::string formula; double moles; cxxNameDouble formula_totals; cxxNameDouble totals; double la; double charge_balance; - char *phase_name; + std::string phase_name; double phase_proportion; - char *rate_name; + std::string rate_name; double formula_z; // charge on formula public: diff --git a/Exchange.cxx b/Exchange.cxx index 4785e784..07c909e1 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -177,7 +177,7 @@ cxxExchange::get_related_phases() for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if ((*it).second.get_phase_name() == NULL) + if ((*it).second.get_phase_name().size() == 0) continue; return (true); } @@ -190,7 +190,7 @@ cxxExchange::get_related_rate() for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if ((*it).second.get_rate_name() == NULL) + if ((*it).second.get_rate_name().size() == 0) continue; return (true); } diff --git a/Exchange.h b/Exchange.h index eab812e0..e474762e 100644 --- a/Exchange.h +++ b/Exchange.h @@ -58,16 +58,16 @@ class cxxExchange:public cxxNumKeyword void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - private: +private: void add(const cxxExchange & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; - protected: - std::map < std::string, cxxExchComp > exchComps; +protected: + std::map < std::string, cxxExchComp > exchComps; bool pitzer_exchange_gammas; cxxNameDouble totals; - public: +public: }; diff --git a/GasPhase.cxx b/GasPhase.cxx index 1cc1e184..c8df508c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -136,8 +136,9 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp() for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { - gas_comp_ptr[i].name = it->first; - gas_comp_ptr[i].phase = phase_bsearch(it->first, &n, TRUE); + gas_comp_ptr[i].name = string_hsave(it->first.c_str()); + assert(it->first.size() != 0); + gas_comp_ptr[i].phase = phase_bsearch(it->first.c_str(), &n, TRUE); gas_comp_ptr[i].p_read = 0; gas_comp_ptr[i].moles = it->second; gas_comp_ptr[i].initial_moles = 0; @@ -446,7 +447,7 @@ cxxGasPhase::totalize() { struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(it->first, &l, FALSE); + phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/GasPhase.h b/GasPhase.h index 2fa6e96b..5d3363cf 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -11,7 +11,6 @@ #include // std::list #include // std::vector -#include "char_star.h" #include "cxxMix.h" class cxxGasPhase:public cxxNumKeyword @@ -52,17 +51,17 @@ class cxxGasPhase:public cxxNumKeyword return this->totals; }; - private: +private: void add(const cxxGasPhase & addee, double extensive); - protected: +protected: cxxNameDouble gasPhaseComps; GP_TYPE type; double total_p; double volume; cxxNameDouble totals; - public: +public: //static std::map& map; }; diff --git a/ISolution.cxx b/ISolution.cxx index 27bd9046..78355274 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -39,7 +39,7 @@ cxxSolution(solution_ptr) //, pe(cxxPe_Data::alloc()) { density = solution_ptr->density; - units = solution_ptr->units; + this->set_units(solution_ptr->units); // totals for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { @@ -66,7 +66,10 @@ cxxISolution::cxxISolution2solution() struct solution *soln_ptr = this->cxxSolution2solution(); soln_ptr->new_def = TRUE; soln_ptr->density = this->density; - soln_ptr->units = string_hsave(this->units.c_str()); + if (this->units.size() == 0) + soln_ptr->units = NULL; + else + soln_ptr->units = string_hsave(this->units.c_str()); soln_ptr->default_pe = this->default_pe; // pe soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe); @@ -85,16 +88,16 @@ cxxISolution::ConvertUnits() { double sum_solutes = 0; // foreach conc - std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = + std::map < std::string, cxxISolutionComp >::iterator iter = this->comps.begin(); for (; iter != this->comps.end(); ++iter) { - struct master *master_ptr = master_bsearch(iter->first); + struct master *master_ptr = master_bsearch(iter->first.c_str()); if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; - if (strcmp(iter->second.get_description(), "H(1)") == 0 - || strcmp(iter->second.get_description(), "E")) + if (strcmp(iter->second.get_description().c_str(), "H(1)") == 0 + || strcmp(iter->second.get_description().c_str(), "E")) continue; if (iter->second.get_input_conc() <= 0.0) continue; diff --git a/ISolution.h b/ISolution.h index 51fcb8ed..cdb505b0 100644 --- a/ISolution.h +++ b/ISolution.h @@ -47,6 +47,13 @@ class cxxISolution:public cxxSolution { units = units; } + void set_units(char * units) + { + if (units != NULL) + this->units = std::string(units); + else + this->units.clear(); + } //char * get_redox()const {return this->pe[this->default_pe].get_name();} @@ -72,7 +79,8 @@ class cxxISolution:public cxxSolution friend class cxxISolutionComp; // for this->pe access double density; std::string units; - std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps; + //std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps; + std::map < std::string, cxxISolutionComp > comps; struct pe_data *pes; int default_pe; diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index af851ae1..fd0c6020 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -21,14 +21,14 @@ gfw(0.0) } cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr) { - description = conc_ptr->description; + this->set_description(conc_ptr->description); moles = conc_ptr->moles; input_conc = conc_ptr->input_conc; - units = conc_ptr->units; - equation_name = conc_ptr->equation_name; + this->set_units(conc_ptr->units); + this->set_equation_name(conc_ptr->equation_name); phase_si = conc_ptr->phase_si; n_pe = conc_ptr->n_pe; - as = conc_ptr->as; + this->set_as(conc_ptr->as); gfw = conc_ptr->gfw; //skip = conc_ptr->skip; //phase = conc_ptr->phase; @@ -67,9 +67,8 @@ struct conc *cxxISolutionComp::concarray(std::map &totals) + cxxISolutionComp::cxxISolutionComp2conc(const std::map < std::string, + cxxISolutionComp > &totals) // for ISolutions // takes a std::vector cxxISolutionComp structures // returns list of conc structures @@ -80,18 +79,23 @@ cxxISolutionComp::cxxISolutionComp2conc(const std::map < char *, if (c == NULL) malloc_error(); int i = 0; - for (std::map < char *, cxxISolutionComp, - CHARSTAR_LESS >::const_iterator it = totals.begin(); + for (std::map < std::string, cxxISolutionComp >::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = it->second.description; + c[i].description = string_duplicate(it->second.description.c_str()); c[i].moles = it->second.moles; c[i].input_conc = it->second.input_conc; - c[i].units = it->second.units; - c[i].equation_name = it->second.equation_name; + if (it->second.units.size() == 0) + c[i].units = NULL; + else + c[i].units = string_hsave(it->second.units.c_str()); + if (it->second.equation_name.size() == 0) + c[i].equation_name = NULL; + else + c[i].equation_name = string_hsave(it->second.equation_name.c_str()); c[i].phase_si = it->second.phase_si; c[i].n_pe = it->second.n_pe; - c[i].as = it->second.as; + c[i].as = string_hsave(it->second.as.c_str()); c[i].gfw = it->second.gfw; //c[i].skip = 0; c[i].phase = NULL; @@ -108,11 +112,11 @@ cxxISolutionComp::set_gfw() if (this->gfw > 0.0) return; // calculate gfw from as or from master species gfw - if (this->as != NULL) + if (this->as.size() != 0) { /* use given chemical formula to calculate gfw */ double gfw; - if (compute_gfw(this->as, &gfw) == ERROR) + if (compute_gfw(this->as.c_str(), &gfw) == ERROR) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; @@ -121,8 +125,8 @@ cxxISolutionComp::set_gfw() return; } //if (this->description == "Alkalinity" && this->as == "CaCO3") - if (strcmp(this->description, "Alkalinity") == 0 - && strcmp(this->as, "CaCO3")) + if (strcmp(this->description.c_str(), "Alkalinity") == 0 + && strcmp(this->as.c_str(), "CaCO3")) { gfw /= 2.; } diff --git a/ISolutionComp.h b/ISolutionComp.h index b2c3221b..28d24c21 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -12,7 +12,6 @@ #include // std::map #include #include -#include "char_star.h" // forward declarations class cxxISolution; // reqd for read and dump_xml @@ -30,13 +29,16 @@ class cxxISolutionComp void dump_xml(std::ostream & os, unsigned int indent = 0) const; - char *get_description() const + const std::string &get_description() const { return this->description; } void set_description(char *description) { - this->description = description; + if (description != NULL) + this->description = std::string(description); + else + this->description.clear(); } double get_moles() const @@ -63,16 +65,23 @@ class cxxISolutionComp } void set_units(char *units) { - this->units = units; + if (units != NULL) + this->units = std::string(units); + else + this->units.clear(); } - char *get_equation_name() const + const std::string &get_equation_name() const { return this->equation_name; } void set_equation_name(char *equation_name) { - this->equation_name = equation_name; + if (equation_name != NULL) + this->equation_name = std::string(equation_name); + else + this->equation_name.clear(); + } double get_phase_si() const @@ -93,13 +102,16 @@ class cxxISolutionComp this->n_pe = n_pe; } - char *get_as() const + const std::string &get_as() const { return this->as; } void set_as(char *as) { - this->as = as; + if (as != NULL) + this->as = std::string(as); + else + this->as.clear(); } //double get_gfw()const {return this->gfw;} @@ -115,23 +127,21 @@ class cxxISolutionComp bool operator<(const cxxISolutionComp & conc) const { - return::strcmp(this->description, conc.description) < 0; + return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0; } - static struct conc *cxxISolutionComp2conc(const std::map < char *, - cxxISolutionComp, - CHARSTAR_LESS > &t); + static struct conc *cxxISolutionComp2conc(const std::map < std::string, cxxISolutionComp > &t); private: - char *description; - double moles; - double input_conc; - char *units; - char *equation_name; - double phase_si; - int n_pe; - char *as; - double gfw; + std::string description; + double moles; + double input_conc; + std::string units; + std::string equation_name; + double phase_si; + int n_pe; + std::string as; + double gfw; }; #endif // ISOLUTIONCOMP_H_INCLUDED diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 145f62e8..5c6dcef5 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -24,7 +24,6 @@ cxxKineticsComp::cxxKineticsComp() // default constructor for cxxKineticsComp // { - rate_name = NULL; tol = 1e-8; m = 0.0; m0 = 0.0; @@ -39,7 +38,7 @@ cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr) : namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) { - rate_name = kinetics_comp_ptr->rate_name; + this->set_rate_name(kinetics_comp_ptr->rate_name); tol = kinetics_comp_ptr->tol; m = kinetics_comp_ptr->m; m0 = kinetics_comp_ptr->m0; @@ -71,7 +70,10 @@ struct kinetics_comp * for (std::map < std::string, cxxKineticsComp >::iterator it = el.begin(); it != el.end(); ++it) { - kinetics_comp_ptr[i].rate_name = (*it).second.rate_name; + if ((*it).second.rate_name.size() == 0) + kinetics_comp_ptr[i].rate_name = NULL; + else + kinetics_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef(); kinetics_comp_ptr[i].count_list = (int) (*it).second.namecoef.size(); kinetics_comp_ptr[i].tol = (*it).second.tol; @@ -255,14 +257,14 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case 0: // rate_name if (!(parser.get_iss() >> str)) { - this->rate_name = NULL; + this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); } else { - this->rate_name = string_hsave(str.c_str()); + this->rate_name = str; } rate_name_defined = true; break; @@ -401,7 +403,7 @@ cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->rate_name = dictionary.int2char(ints[i++]); + this->rate_name = dictionary.int2stdstring(ints[i++]); this->namecoef.mpi_unpack(ints, &i, doubles, &d); this->tol = doubles[d++]; this->m = doubles[d++]; @@ -422,11 +424,11 @@ cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive) { if (extensive == 0.0) return; - if (addee.rate_name == NULL) + if (addee.rate_name.size() == 0) return; // this and addee must have same name // otherwise generate a new KineticsComp with multiply - if (this->rate_name == NULL && addee.rate_name == NULL) + if (this->rate_name.size() == 0 && addee.rate_name.size() == 0) { return; } diff --git a/KineticsComp.h b/KineticsComp.h index 80e9efe0..17d96930 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxKineticsComp { @@ -28,10 +26,17 @@ public: void read_raw(CParser & parser, bool check = true); - char *get_rate_name() const + const std::string &get_rate_name() const { return this->rate_name; } + void set_rate_name(char * s) + { + if (s != NULL) + this->rate_name = std::string(s); + else + this->rate_name.clear(); + } #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); @@ -41,13 +46,13 @@ public: void multiply(double extensive); protected: - char *rate_name; - cxxNameDouble namecoef; //stoichiometry of reaction - double tol; - double m; - double m0; - double moles; - std::vector < double >d_params; + std::string rate_name; + cxxNameDouble namecoef; //stoichiometry of reaction + double tol; + double m; + double m0; + double moles; + std::vector < double >d_params; public: diff --git a/NameDouble.cxx b/NameDouble.cxx index 2585194b..cd729ea6 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -144,7 +144,7 @@ cxxNameDouble::elt_list() int i = 0; for (iterator it = this->begin(); it != this->end(); ++it) { - elt_list_ptr[i].elt = element_store(it->first); + elt_list_ptr[i].elt = element_store(it->first.c_str()); elt_list_ptr[i].coef = it->second; i++; } @@ -177,7 +177,7 @@ cxxNameDouble::master_activity() const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = (char *) it->first; + master_activity_ptr[i].description = string_hsave(it->first.c_str()); master_activity_ptr[i].la = it->second; i++; } @@ -198,7 +198,7 @@ cxxNameDouble::master_activity() const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = (char *) it->first; + master_activity_ptr[i].description = string_hsave(it->first.c_str()); master_activity_ptr[i].la = it->second; i++; } @@ -227,7 +227,7 @@ cxxNameDouble::conc() const int i = 0; for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - c[i].description = (char *) it->first; + c[i].description = string_hsave(it->first.c_str()); c[i].moles = it->second; c[i].input_conc = it->second; c[i].units = NULL; @@ -259,7 +259,7 @@ cxxNameDouble::name_coef() const int i = 0; for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - name_coef_ptr[i].name = it->first; + name_coef_ptr[i].name = string_hsave(it->first.c_str()); name_coef_ptr[i].coef = it->second; i++; } @@ -468,7 +468,6 @@ cxxNameDouble::mpi_pack(std::vector < int >&ints, ints.push_back((int) (*this).size()); for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - assert(it->first != NULL); int n = dictionary.string2int(it->first); ints.push_back(n); doubles.push_back(it->second); @@ -500,6 +499,28 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } +//void +//cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +//{ +// int i = *ii; +// int d = *dd; +// extern cxxDictionary dictionary; +// this->clear(); +// int count = ints[i++]; +// for (int j = 0; j < count; j++) +// { +// int n = ints[i++]; +// assert(n >= 0); +// std::string * str = dictionary.int2string(n); +// if (str != NULL) +// { +// char *cstr = string_hsave(str->c_str()); +// (*this)[cstr] = doubles[d++]; +// } +// } +// *ii = i; +// *dd = d; +//} void cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { @@ -512,11 +533,10 @@ cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { int n = ints[i++]; assert(n >= 0); - std::string * str = dictionary.int2string(n); - if (str != NULL) + std::string str = dictionary.int2stdstring(n); + if (str.size() != 0) { - char *cstr = string_hsave(str->c_str()); - (*this)[cstr] = doubles[d++]; + (*this)[str] = doubles[d++]; } } *ii = i; diff --git a/NameDouble.h b/NameDouble.h index 0ce531aa..883f6756 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -8,12 +8,9 @@ #include // std::list #include // std::vector -//#include "global.h" -#include "char_star.h" #include "Parser.h" class cxxNameDouble:public -std::map < char *, double, - CHARSTAR_LESS > + std::map < std::string, double > { public: diff --git a/PPassemblage.h b/PPassemblage.h index c44c7aac..af9cdc75 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -10,7 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" #include "PPassemblageComp.h" #include "cxxMix.h" @@ -53,18 +52,18 @@ class cxxPPassemblage:public cxxNumKeyword void ORCH_store_global(std::map < std::string, double >output_map); #endif - private: +private: void add(const cxxPPassemblage & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; - protected: +protected: //std::list < cxxPPassemblageComp > ppAssemblageComps; - std::map ppAssemblageComps; + std::map ppAssemblageComps; cxxNameDouble eltList; cxxNameDouble totals; - public: +public: //static std::map& map; }; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 3ef2bf53..4801c633 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -25,8 +25,6 @@ cxxPPassemblageComp::cxxPPassemblageComp() // default constructor for cxxPPassemblageComp // { - name = NULL; - add_formula = NULL; si = 0; moles = 0; delta = 0; @@ -41,8 +39,8 @@ cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr) // constructor for cxxPPassemblageComp from struct pure_phase // { - name = pure_phase_ptr->name; - add_formula = pure_phase_ptr->add_formula; + this->set_name(pure_phase_ptr->name); + this->set_add_formula(pure_phase_ptr->add_formula); si = pure_phase_ptr->si; moles = pure_phase_ptr->moles; delta = pure_phase_ptr->delta; @@ -60,7 +58,7 @@ struct phase * cxxPPassemblageComp::get_phase() { int i; - return phase_bsearch(this->name, &i, FALSE); + return phase_bsearch(this->name.c_str(), &i, FALSE); } struct pure_phase * @@ -80,8 +78,14 @@ struct pure_phase * it != el.end(); ++it) { pure_phase_ptr[i].phase = (*it).second.get_phase(); - pure_phase_ptr[i].name = (*it).second.name; - pure_phase_ptr[i].add_formula = (*it).second.add_formula; + if ((*it).second.name.size() == 0) + pure_phase_ptr[i].name = NULL; + else + pure_phase_ptr[i].name = string_hsave((*it).second.name.c_str()); + if ((*it).second.add_formula.size() == 0) + pure_phase_ptr[i].add_formula = NULL; + else + pure_phase_ptr[i].add_formula = string_hsave((*it).second.add_formula.c_str()); pure_phase_ptr[i].si = (*it).second.si; pure_phase_ptr[i].moles = (*it).second.moles; pure_phase_ptr[i].delta = (*it).second.delta; @@ -143,12 +147,10 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Pure_Phase element and attributes - if (this->name != NULL) - s_oss << indent0 << "-name " << this-> - name << std::endl; - if (this->add_formula != NULL) - s_oss << indent1 << "-add_formula " << this-> - add_formula << std::endl; + if (this->name.size() != 0) + s_oss << indent0 << "-name " << this->name << std::endl; + if (this->add_formula.size() != 0) + s_oss << indent1 << "-add_formula " << this->add_formula << std::endl; s_oss << indent1 << "-si " << this->si << std::endl; s_oss << indent1 << "-moles " << this->moles << std::endl; s_oss << indent1 << "-delta " << this->delta << std::endl; @@ -218,14 +220,14 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) case 0: // name if (!(parser.get_iss() >> str)) { - this->name = NULL; + this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); } else { - this->name = string_hsave(str.c_str()); + this->name = str; } name_defined = true; break; @@ -233,14 +235,14 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) case 1: // add_formula if (!(parser.get_iss() >> str)) { - this->add_formula = NULL; + this->add_formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for add_formula.", CParser::OT_CONTINUE); } else { - this->add_formula = string_hsave(str.c_str()); + this->add_formula = str; } break; @@ -418,8 +420,8 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->name = dictionary.int2char(ints[i++]); - this->add_formula = dictionary.int2char(ints[i++]); + this->name = dictionary.int2stdstring(ints[i++]); + this->add_formula = dictionary.int2stdstring(ints[i++]); this->si = doubles[d++]; this->moles = doubles[d++]; this->delta = doubles[d++]; @@ -437,11 +439,11 @@ cxxPPassemblageComp::totalize() { this->totals.clear(); // component structures - if (this->add_formula != NULL) + if (this->add_formula.size() != 0) return; struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(this->name, &l, FALSE); + phase_ptr = phase_bsearch(this->name.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); @@ -461,7 +463,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) double ext1, ext2, f1, f2; if (extensive == 0.0) return; - if (addee.name == NULL) + if (addee.name.size() == 0) return; // this and addee must have same name // otherwise generate a new PPassemblagComp with multiply @@ -481,7 +483,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) //char * name; //char *add_formula; - if (this->name == NULL && addee.name == NULL) + if (this->name.size() == 0 && addee.name.size() == 0) { return; } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index cc764885..e88a35c7 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxPPassemblageComp { @@ -29,11 +27,28 @@ class cxxPPassemblageComp void read_raw(CParser & parser, bool check = true); - char *get_name() const + const std::string &get_name() const { return this->name; } - + void set_name(char * s) + { + if(s != NULL) + this->name = std::string(s); + else + this->name.clear(); + } + const std::string &get_add_formula() const + { + return this->add_formula; + } + void set_add_formula(char * s) + { + if(s != NULL) + this->add_formula = std::string(s); + else + this->add_formula.clear(); + } struct phase *get_phase(); void totalize(); @@ -49,9 +64,9 @@ class cxxPPassemblageComp void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - protected: - char *name; - char *add_formula; +protected: + std::string name; + std::string add_formula; double si; double moles; double delta; @@ -61,7 +76,7 @@ class cxxPPassemblageComp bool precipitate_only; cxxNameDouble totals; - public: +public: }; diff --git a/Parser.cxx b/Parser.cxx index 2552b242..6cd6a312 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -12,7 +12,7 @@ #include // std::map #include // assert #include // std::cout std::cerr -#include "char_star.h" + extern char *string_hsave(const char *str); ////////////////////////////////////////////////////////////////////// @@ -1078,40 +1078,39 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) return PARSER_OK; } -CParser::STATUS_TYPE CParser::addPair(std::map < char *, double, - CHARSTAR_LESS > &totals, +//CParser::STATUS_TYPE CParser::addPair(std::map < char *, double, +// CHARSTAR_LESS > &totals, +// std::istream::pos_type & pos) +//{ +// std::string token; +// char * +// ctoken; +// double +// d; +// +// CParser::TOKEN_TYPE j; +// +// m_line_iss.seekg(pos); +// +// j = copy_token(token, pos); +// +// if (j == TT_EMPTY) +// return PARSER_OK; +// +// if (!(m_line_iss >> d)) +// { +// return PARSER_ERROR; +// } +// ctoken = string_hsave(token.c_str()); +// totals[ctoken] = d; +// return PARSER_OK; +//} + +CParser::STATUS_TYPE CParser::addPair(std::map < std::string, double >&totals, std::istream::pos_type & pos) { std::string token; - char * - ctoken; - double - d; - - CParser::TOKEN_TYPE j; - - m_line_iss.seekg(pos); - - j = copy_token(token, pos); - - if (j == TT_EMPTY) - return PARSER_OK; - - if (!(m_line_iss >> d)) - { - return PARSER_ERROR; - } - ctoken = string_hsave(token.c_str()); - totals[ctoken] = d; - return PARSER_OK; -} - -CParser::STATUS_TYPE CParser::addPair(std::map < char *, double >&totals, - std::istream::pos_type & pos) -{ - std::string token; - char * - ctoken; + //char * ctoken; double d; CParser::TOKEN_TYPE j; @@ -1127,8 +1126,9 @@ CParser::STATUS_TYPE CParser::addPair(std::map < char *, double >&totals, { return PARSER_ERROR; } - ctoken = string_hsave(token.c_str()); - totals[ctoken] = d; + //ctoken = string_hsave(token.c_str()); + //totals[ctoken] = d; + totals[token] = d; return PARSER_OK; } diff --git a/Parser.h b/Parser.h index 8d436ff6..83e67e96 100644 --- a/Parser.h +++ b/Parser.h @@ -8,7 +8,6 @@ extern int input_error; #include // std::istringstream std::ostringstream #include // std::ostream #include // std::istream -#include "char_star.h" class CParser { @@ -281,9 +280,9 @@ class CParser STATUS_TYPE parse_couple(std::string & token); - STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, - std::istream::pos_type & pos); - STATUS_TYPE addPair(std::map < char *, double >&totals, + //STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, + // std::istream::pos_type & pos); + STATUS_TYPE addPair(std::map < std::string, double >&totals, std::istream::pos_type & pos); protected: diff --git a/Reaction.cxx b/Reaction.cxx index 91748dd6..b40b194f 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -24,7 +24,7 @@ cxxReaction::cxxReaction() // : cxxNumKeyword() { - units = string_hsave("Mol"); + this->set_units("Mol"); countSteps = 0; equalIncrements = false; reactantList.type = cxxNameDouble::ND_NAME_COEF; @@ -45,7 +45,7 @@ elementList(irrev_ptr->elts) this->set_description(irrev_ptr->description); this->n_user = irrev_ptr->n_user; this->n_user_end = irrev_ptr->n_user_end; - this->units = irrev_ptr->units; + this->set_units(irrev_ptr->units); // steps if (irrev_ptr->count_steps < 0) { @@ -117,7 +117,10 @@ cxxReaction::cxxReaction2irrev() { irrev_ptr->count_steps = (int) this->steps.size(); } - irrev_ptr->units = this->units; + if (this->units.size() == 0) + irrev_ptr->units = NULL; + else + irrev_ptr->units = string_hsave(this->units.c_str()); return (irrev_ptr); } @@ -282,7 +285,7 @@ cxxReaction::read_raw(CParser & parser) j = parser.copy_token(token, next_char); if (j == CParser::TT_EMPTY) break; - this->units = string_hsave(token.c_str()); + this->set_units(token.c_str()); opt_save = CParser::OPT_DEFAULT; useLastLine = false; units_defined = true; diff --git a/Reaction.h b/Reaction.h index 7705302e..ae6d8dd2 100644 --- a/Reaction.h +++ b/Reaction.h @@ -11,8 +11,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxReaction:public cxxNumKeyword { @@ -29,15 +27,23 @@ class cxxReaction:public cxxNumKeyword void read_raw(CParser & parser); - protected: - cxxNameDouble reactantList; + void set_units(const char * s) + { + if (s != NULL) + this->units = std::string(s); + else + this->units.clear(); + } + +protected: + cxxNameDouble reactantList; cxxNameDouble elementList; - std::vector < double >steps; + std::vector < double >steps; int countSteps; bool equalIncrements; - char *units; + std::string units; - public: +public: //static std::map& map; }; diff --git a/SSassemblage.h b/SSassemblage.h index a592c918..0db532b3 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -10,7 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" #include "SSassemblageSS.h" #include "cxxMix.h" diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 92ba8025..47e3ce37 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -25,7 +25,6 @@ cxxSSassemblageSS::cxxSSassemblageSS() // default constructor for cxxSSassemblageSS // { - name = NULL; //total_moles = 0; a0 = 0; a1 = 0; @@ -45,7 +44,7 @@ cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr) // constructor for cxxSSassemblageSS from struct s_s // { - name = s_s_ptr->name; + this->set_name(s_s_ptr->name); //total_moles = s_s_ptr->total_moles; a0 = s_s_ptr->a0; a1 = s_s_ptr->a1; @@ -91,7 +90,8 @@ struct s_s * for (std::map < std::string, cxxSSassemblageSS >::iterator it = el.begin(); it != el.end(); ++it) { - s_s_ptr[j].name = (*it).second.name; + s_s_ptr[j].name = string_hsave((*it).second.name.c_str()); + assert((*it).second.name.size() > 0); //s_s_ptr[j].total_moles = it->total_moles; s_s_ptr[j].total_moles = 0; s_s_ptr[j].dn = 0; @@ -132,8 +132,9 @@ struct s_s * for (cxxNameDouble::iterator itc = (*it).second.comps.begin(); itc != (*it).second.comps.end(); ++itc) { - s_s_comp_ptr[i].name = itc->first; - s_s_comp_ptr[i].phase = phase_bsearch(itc->first, &n, TRUE); + s_s_comp_ptr[i].name = string_hsave(itc->first.c_str()); + assert(itc->first.size() > 0); + s_s_comp_ptr[i].phase = phase_bsearch(itc->first.c_str(), &n, TRUE); s_s_comp_ptr[i].initial_moles = 0; s_s_comp_ptr[i].moles = itc->second; s_s_comp_ptr[i].init_moles = 0; @@ -277,14 +278,14 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) case 0: // name if (!(parser.get_iss() >> str)) { - this->name = NULL; + this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); } else { - this->name = string_hsave(str.c_str()); + this->name = str; } name_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -521,7 +522,7 @@ cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->name = dictionary.int2char(ints[i++]); + this->name = dictionary.int2stdstring(ints[i++]); this->comps.mpi_unpack(ints, &i, doubles, &d); this->a0 = doubles[d++]; this->a1 = doubles[d++]; @@ -545,7 +546,7 @@ cxxSSassemblageSS::totalize() { struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(it->first, &l, FALSE); + phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); @@ -564,7 +565,7 @@ cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive) { if (extensive == 0.0) return; - if (addee.name == NULL) + if (addee.name.size() == 0) return; // this and addee must have same name // otherwise generate a new PPassemblagComp with multiply diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 7e7e21bf..81bba9ce 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxSSassemblageSS { @@ -44,10 +42,17 @@ class cxxSSassemblageSS void read_raw(CParser & parser, bool check = true); - char *get_name() const + const std::string &get_name() const { return this->name; } + void set_name (const char * s) + { + if (s != NULL) + this->name = std::string(s); + else + this->name.clear(); + } void totalize(); const cxxNameDouble & get_totals() const @@ -63,8 +68,8 @@ class cxxSSassemblageSS void add(const cxxSSassemblageSS & comp, double extensive); void multiply(double extensive); - protected: - char *name; +protected: + std::string name; cxxNameDouble comps; double a0, a1; double ag0, ag1; @@ -72,7 +77,7 @@ class cxxSSassemblageSS double xb1, xb2; cxxNameDouble totals; - public: +public: }; diff --git a/Solution.cxx b/Solution.cxx index 4ee96859..193591df 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -670,7 +670,7 @@ cxxSolution::read_raw(CParser & parser, bool check) } else { - if (iso.get_isotope_name() != NULL) + if (iso.get_isotope_name().size() != 0) { this->isotopes.push_back(iso); } @@ -968,7 +968,7 @@ cxxSolution::get_total_element(char *string) const char token[MAX_LENGTH]; if (it->first[0] == string[0]) { - strcpy(token, it->first); + strcpy(token, it->first.c_str()); replace("(", "\0", token); if (strcmp(token, string) == 0) { diff --git a/Solution.h b/Solution.h index 2f45095b..96a03533 100644 --- a/Solution.h +++ b/Solution.h @@ -14,8 +14,6 @@ #include // std::vector #include -#include "char_star.h" - class cxxSolution:public cxxNumKeyword { diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index c8a62387..baff944c 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -19,8 +19,8 @@ isotope_number(0.0) cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) { isotope_number = isotope_ptr->isotope_number; - elt_name = isotope_ptr->elt_name; - isotope_name = isotope_ptr->isotope_name; + this->set_elt_name(isotope_ptr->elt_name); + this->set_isotope_name(isotope_ptr->isotope_name); total = isotope_ptr->total; ratio = isotope_ptr->ratio; ratio_uncertainty = isotope_ptr->ratio_uncertainty; @@ -53,7 +53,7 @@ cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist) it != isolist.end(); ++it) { iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; + iso[i].elt_name = string_hsave(it->elt_name.c_str()); iso[i].total = it->total; iso[i].ratio = it->ratio; iso[i].ratio_uncertainty = it->ratio_uncertainty; @@ -148,10 +148,10 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) if (j == CParser::TT_EMPTY) { - this->isotope_name = NULL; + this->isotope_name.clear(); return (CParser::PARSER_OK); } - this->isotope_name = string_hsave(token.c_str()); + this->set_isotope_name(token.c_str()); // isotope_number if (!(parser.get_iss() >> isotope_number)) @@ -164,7 +164,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) { return CParser::PARSER_ERROR; } - this->elt_name = string_hsave(token.c_str()); + this->set_elt_name(token.c_str()); // total if (!(parser.get_iss() >> this->total)) @@ -202,7 +202,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) bool cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const { - int i = Utilities::strcmp_nocase(this->elt_name, isotope.elt_name); + int i = Utilities::strcmp_nocase(this->elt_name.c_str(), isotope.elt_name.c_str()); if (i != 0) return (i < 0); return (this->isotope_number < isotope.isotope_number); @@ -211,13 +211,14 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const struct master * cxxSolutionIsotope::master(void) { - return (master_bsearch(this->elt_name)); + return (master_bsearch(this->elt_name.c_str())); } struct master * cxxSolutionIsotope::primary(void) { - return (master_bsearch_primary(this->elt_name)); + char * str = string_hsave(this->elt_name.c_str()); + return (master_bsearch_primary(str)); } void diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 6ccce2fb..32fc066f 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -35,21 +35,27 @@ class cxxSolutionIsotope { this->isotope_number = d; } - char *get_elt_name() const + const std::string &get_elt_name() const { return this->elt_name; } - void set_elt_name(char *cstring) + void set_elt_name(const char *cstring) { - this->elt_name = cstring; + if (cstring != NULL) + this->elt_name = std::string(cstring); + else + this->elt_name.clear(); } - char *get_isotope_name() const + const std::string &get_isotope_name() const { return this->isotope_name; } - void set_isotope_name(char *cstring) + void set_isotope_name(const char *cstring) { - this->isotope_name = cstring; + if (cstring != NULL) + this->isotope_name = std::string(cstring); + else + this->isotope_name.clear(); } double get_total() const { @@ -87,13 +93,11 @@ class cxxSolutionIsotope protected: friend class cxxSolutionIsotopeList; double isotope_number; - char *elt_name; - char *isotope_name; + std::string elt_name; + std::string isotope_name; double total; double ratio; double ratio_uncertainty; - //struct master *master; - //struct master *primary; bool ratio_uncertainty_defined; }; #endif // SOLUTIONISOTOPE_H_INCLUDED diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 150818f5..2989d788 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -98,7 +98,7 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() it != this->end(); ++it) { iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = it->elt_name; + iso[i].elt_name = string_hsave(it->elt_name.c_str()); iso[i].total = it->total; iso[i].ratio = it->ratio; iso[i].ratio_uncertainty = it->ratio_uncertainty; diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 02e22f3e..efc9f192 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -8,7 +8,6 @@ #include // std::string #include // std::list -#include "char_star.h" #include "Parser.h" class cxxSolutionIsotopeList:public @@ -16,23 +15,18 @@ class cxxSolutionIsotopeList:public cxxSolutionIsotope > { - public: +public: cxxSolutionIsotopeList(); cxxSolutionIsotopeList(struct solution *solution_ptr); - ~ - cxxSolutionIsotopeList(); + ~cxxSolutionIsotopeList(); - struct isotope * - cxxSolutionIsotopeList2isotope(); + struct isotope * cxxSolutionIsotopeList2isotope(); + void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); + void multiply(double extensive); - void - add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); - void - multiply(double extensive); - - protected: +protected: public: diff --git a/Surface.cxx b/Surface.cxx index 1408aa9f..a48bd0c7 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -118,7 +118,7 @@ cxxSurface::get_related_phases() for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if ((*it).second.get_phase_name() == NULL) + if ((*it).second.get_phase_name().size() == 0) continue; return (true); } @@ -131,7 +131,7 @@ cxxSurface::get_related_rate() for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if ((*it).second.get_rate_name() == NULL) + if ((*it).second.get_rate_name().size() == 0) continue; return (true); } @@ -195,9 +195,9 @@ cxxSurface::cxxSurface2surface() int i, j; for (i = 0; i < surface_ptr->count_comps; i++) { - char *charge_name = + char *charge_name = string_hsave( cxxSurfaceComp::get_charge_name(surface_ptr->comps[i]. - formula); + formula).c_str()); for (j = 0; j < surface_ptr->count_charge; j++) { if (charge_name == surface_ptr->charge[j].name) diff --git a/Surface.h b/Surface.h index 983cd88f..461f7520 100644 --- a/Surface.h +++ b/Surface.h @@ -10,7 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" #include "SurfaceComp.h" #include "SurfaceCharge.h" #include "cxxMix.h" @@ -54,12 +53,12 @@ class cxxSurface:public cxxNumKeyword void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - private: +private: void add(const cxxSurface & addee, double extensive); - protected: - std::map < std::string, cxxSurfaceComp > surfaceComps; - std::map < std::string, cxxSurfaceCharge > surfaceCharges; +protected: + std::map < std::string, cxxSurfaceComp > surfaceComps; + std::map < std::string, cxxSurfaceCharge > surfaceCharges; enum SURFACE_TYPE type; enum DIFFUSE_LAYER_TYPE dl_type; enum SITES_UNITS sites_units; @@ -71,7 +70,7 @@ class cxxSurface:public cxxNumKeyword bool transport; cxxNameDouble totals; - public: +public: //static std::map& map; }; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index f7529eaa..8e22a6b4 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -25,7 +25,6 @@ cxxSurfaceCharge::cxxSurfaceCharge() // default constructor for cxxSurfaceCharge // { - name = NULL; specific_area = 0.0; grams = 0.0; charge_balance = 0.0; @@ -45,7 +44,7 @@ cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr) : diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) { - name = surf_charge_ptr->name; + this->set_name(surf_charge_ptr->name); specific_area = surf_charge_ptr->specific_area; grams = surf_charge_ptr->grams; charge_balance = surf_charge_ptr->charge_balance; @@ -96,7 +95,8 @@ struct surface_charge * for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin(); it != el.end(); ++it) { - surf_charge_ptr[i].name = (*it).second.name; + surf_charge_ptr[i].name = string_hsave((*it).second.name.c_str()); + assert((*it).second.name.size() > 0); surf_charge_ptr[i].specific_area = (*it).second.specific_area; surf_charge_ptr[i].grams = (*it).second.grams; surf_charge_ptr[i].charge_balance = (*it).second.charge_balance; @@ -262,14 +262,14 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) case 0: // name if (!(parser.get_iss() >> str)) { - this->name = NULL; + this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", CParser::OT_CONTINUE); } else { - this->name = string_hsave(str.c_str()); + this->name = str; } name_defined = true; break; @@ -486,7 +486,7 @@ cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->name = dictionary.int2char(ints[i++]); + this->name = dictionary.int2stdstring(ints[i++]); this->specific_area = doubles[d++]; this->grams = doubles[d++]; this->charge_balance = doubles[d++]; @@ -515,7 +515,7 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) //double capacitance[2]; //char * name; - if (this->name == NULL && addee.name == NULL) + if (this->name.size() == 0 && addee.name.size() == 0) { return; } diff --git a/SurfaceCharge.h b/SurfaceCharge.h index b1faa769..a5841a3f 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxSurfaceCharge { @@ -32,11 +30,19 @@ class cxxSurfaceCharge void read_raw(CParser & parser, bool check = true); - char *get_name() const + const std::string &get_name() const { return this->name; } + void set_name(const char * s) + { + if (s != NULL) + this->name = std::string(s); + else + this->name.clear(); + + } void add(const cxxSurfaceCharge & comp, double extensive); void multiply(double extensive); @@ -45,8 +51,8 @@ class cxxSurfaceCharge void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - protected: - char *name; +protected: + std::string name; double specific_area; double grams; double charge_balance; @@ -57,7 +63,7 @@ class cxxSurfaceCharge //char * psi_master_name; cxxNameDouble diffuse_layer_totals; - public: +public: }; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 28865cc8..bab9bb65 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -25,7 +25,6 @@ cxxSurfaceComp::cxxSurfaceComp() // default constructor for cxxSurfaceComp // { - formula = NULL; formula_totals.type = cxxNameDouble::ND_ELT_MOLES; formula_z = 0.0; moles = 0.0; @@ -33,9 +32,7 @@ cxxSurfaceComp::cxxSurfaceComp() la = 0.0; //charge_number = -99; charge_balance = 0; - phase_name = NULL; phase_proportion = 0.0; - rate_name = NULL; Dw = 0.0; } @@ -47,15 +44,15 @@ cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { - formula = surf_comp_ptr->formula; + this->set_formula(surf_comp_ptr->formula); formula_z = surf_comp_ptr->formula_z; moles = surf_comp_ptr->moles; la = surf_comp_ptr->la; //charge_number = surf_comp_ptr->charge; charge_balance = surf_comp_ptr->cb; - phase_name = surf_comp_ptr->phase_name; + this->set_phase_name(surf_comp_ptr->phase_name); phase_proportion = surf_comp_ptr->phase_proportion; - rate_name = surf_comp_ptr->rate_name; + this->set_rate_name(surf_comp_ptr->rate_name); Dw = surf_comp_ptr->Dw; } @@ -72,7 +69,8 @@ cxxSurfaceComp::get_master() it != this->totals.end(); it++) { /* Find master species */ - char *eltName = it->first; + char *eltName = string_hsave(it->first.c_str()); + assert(it->first.size() > 0); struct element *elt_ptr = element_store(eltName); if (elt_ptr->master == NULL) { @@ -116,7 +114,8 @@ struct surface_comp * for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin(); it != el.end(); ++it) { - surf_comp_ptr[i].formula = (*it).second.formula; + surf_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str()); + assert((*it).second.formula.size() > 0); surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); surf_comp_ptr[i].formula_z = (*it).second.formula_z; surf_comp_ptr[i].moles = (*it).second.moles; @@ -125,9 +124,15 @@ struct surface_comp * surf_comp_ptr[i].la = (*it).second.la; //surf_comp_ptr[i].charge = it->charge_number; surf_comp_ptr[i].cb = (*it).second.charge_balance; - surf_comp_ptr[i].phase_name = (*it).second.phase_name; + if ((*it).second.phase_name.size() == 0) + surf_comp_ptr[i].phase_name = NULL; + else + surf_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str()); surf_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; - surf_comp_ptr[i].rate_name = (*it).second.rate_name; + if ((*it).second.rate_name.size() == 0) + surf_comp_ptr[i].rate_name = NULL; + else + surf_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); surf_comp_ptr[i].Dw = (*it).second.Dw; surf_comp_ptr[i].master = (*it).second.get_master(); i++; @@ -159,12 +164,12 @@ cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; s_oss << indent0 << "charge_balance=\"" << this-> charge_balance << "\"" << std::endl; - if (this->phase_name != NULL) + if (this->phase_name.size() != 0) { s_oss << indent0 << "phase_name=\"" << this-> phase_name << "\"" << std::endl; } - if (this->rate_name != NULL) + if (this->rate_name.size() != 0) { s_oss << indent0 << "rate_name=\"" << this-> rate_name << "\"" << std::endl; @@ -210,12 +215,12 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const //s_oss << indent1 << "-charge_number " << this->charge_number << std::endl; s_oss << indent1 << "-charge_balance " << this-> charge_balance << std::endl; - if (this->phase_name != NULL) + if (this->phase_name.size() != 0) { s_oss << indent1 << "-phase_name " << this-> phase_name << std::endl; } - if (this->rate_name != NULL) + if (this->rate_name.size() != 0) { s_oss << indent1 << "-rate_name " << this-> rate_name << std::endl; @@ -298,14 +303,14 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) case 0: // formula if (!(parser.get_iss() >> str)) { - this->formula = NULL; + this->formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for formula.", CParser::OT_CONTINUE); } else { - this->formula = string_hsave(str.c_str()); + this->formula = str; } formula_defined = true; break; @@ -357,28 +362,28 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) case 5: // phase_name if (!(parser.get_iss() >> str)) { - this->phase_name = NULL; + this->phase_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for phase_name.", CParser::OT_CONTINUE); } else { - this->phase_name = string_hsave(str.c_str()); + this->phase_name = str; } break; case 6: // rate_name if (!(parser.get_iss() >> str)) { - this->rate_name = NULL; + this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", CParser::OT_CONTINUE); } else { - this->rate_name = string_hsave(str.c_str()); + this->rate_name = str; } break; @@ -521,7 +526,7 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) extern cxxDictionary dictionary; int i = *ii; int d = *dd; - this->formula = dictionary.int2char(ints[i++]); + this->formula = dictionary.int2stdstring(ints[i++]); this->formula_z = doubles[d++]; this->formula_totals.mpi_unpack(ints, &i, doubles, &d); this->moles = doubles[d++]; @@ -529,9 +534,9 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->la = doubles[d++]; //this->charge_number = ints[i++]; this->charge_balance = doubles[d++]; - this->phase_name = dictionary.int2char(ints[i++]); + this->phase_name = dictionary.int2stdstring(ints[i++]); this->phase_proportion = doubles[d++]; - this->rate_name = dictionary.int2char(ints[i++]); + this->rate_name = dictionary.int2stdstring(ints[i++]); this->Dw = doubles[d++]; *ii = i; *dd = d; @@ -542,18 +547,18 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) { if (extensive == 0.0) return; - if (addee.formula == NULL) + if (addee.formula.size() == 0) return; //char * formula; //cxxNameDouble formula_totals; - if (this->formula == NULL && addee.formula == NULL) + if (this->formula.size() == 0 && addee.formula.size() == 0) { return; } assert(this->formula == addee.formula); assert(this->formula_z == addee.formula_z); - if (this->formula == NULL && addee.formula != NULL) + if (this->formula.size() == 0 && addee.formula.size() != 0) { this->formula = addee.formula; this->formula_totals = addee.formula_totals; @@ -597,7 +602,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) input_error++; return; } - else if (this->phase_name != NULL) + else if (this->phase_name.size() != 0) { this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; @@ -614,14 +619,14 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) input_error++; return; } - else if (this->rate_name != NULL) + else if (this->rate_name.size() != 0) { //double phase_proportion; this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } - if ((this->rate_name != NULL && addee.phase_name != NULL) || - (this->phase_name != NULL && addee.rate_name != NULL)) + if ((this->rate_name.size() != 0 && addee.phase_name.size() != 0) || + (this->phase_name.size() != 0 && addee.rate_name.size() != 0)) { std::ostringstream oss; oss << diff --git a/SurfaceComp.h b/SurfaceComp.h index c968eb91..c1c43eb8 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -11,8 +11,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxSurfaceComp { @@ -24,18 +22,39 @@ class cxxSurfaceComp struct master *get_master(); - char *get_phase_name() const + const std::string &get_phase_name() const { return this->phase_name; } - char *get_rate_name() const + void set_phase_name(char * f) + { + if (f != NULL) + this->phase_name = std::string(f); + else + this->phase_name.clear(); + } + const std::string &get_rate_name() const { return this->rate_name; } - char *get_formula() const + void set_rate_name(char * f) + { + if (f != NULL) + this->rate_name = std::string(f); + else + this->rate_name.clear(); + } + const std::string &get_formula() const { return this->formula; } + void set_formula(char * f) + { + if (f != NULL) + this->formula = std::string(f); + else + this->formula.clear(); + } double get_charge_balance() const { return this->charge_balance; @@ -61,12 +80,26 @@ class cxxSurfaceComp void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - char *charge_name() + std::string charge_name() { - return (get_charge_name(this->formula)); + char * str = string_hsave(this->formula.c_str()); + return (get_charge_name(str)); }; - static char *get_charge_name(char *token) + //static std::string &get_charge_name(char *token) + //{ + // char name[100]; + // int l; + // char *ptr1 = token; + // get_elt(&ptr1, name, &l); + // ptr1 = strchr(name, '_'); + // if (ptr1 != NULL) + // { + // ptr1[0] = '\0'; + // } + // return (string_hsave(name)); + //}; + static std::string get_charge_name(char *token) { char name[100]; int l; @@ -77,27 +110,26 @@ class cxxSurfaceComp { ptr1[0] = '\0'; } - return (string_hsave(name)); + return (std::string(name)); }; - #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif protected: - char *formula; - cxxNameDouble formula_totals; - double formula_z; - double moles; - cxxNameDouble totals; - double la; - //int charge_number; - double charge_balance; - char *phase_name; - double phase_proportion; - char *rate_name; - double Dw; + std::string formula; + cxxNameDouble formula_totals; + double formula_z; + double moles; + cxxNameDouble totals; + double la; + //int charge_number; + double charge_balance; + std::string phase_name; + double phase_proportion; + std::string rate_name; + double Dw; public: }; diff --git a/System.cxx b/System.cxx index 79d1a839..380c64ba 100644 --- a/System.cxx +++ b/System.cxx @@ -1,138 +1,142 @@ #include "System.h" -#include // std::replace +#include // std::replace extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); -cxxSystem::cxxSystem(void) -{ +cxxSystem::cxxSystem(void) +{ + this->solution = NULL; - + this->exchange = NULL; - + this->ppassemblage = NULL; - + this->gasphase = NULL; - + this->ssassemblage = NULL; - + this->kinetics = NULL; - + this->surface = NULL; - + this->mix = NULL; - + this->reaction = NULL; - + this->temperature = NULL; -} -cxxSystem::~cxxSystem(void) +} + +cxxSystem::~cxxSystem(void) { -} + +} void -cxxSystem::Initialize(void) +cxxSystem::Initialize(void) { - + this->solution = NULL; - + this->exchange = NULL; - + this->ppassemblage = NULL; - + this->gasphase = NULL; - + this->ssassemblage = NULL; - + this->kinetics = NULL; - + this->surface = NULL; - + this->mix = NULL; - + this->reaction = NULL; - + this->temperature = NULL; -} -void -cxxSystem::totalize(void) -{ +} +void +cxxSystem::totalize(void) +{ + //initialize this->totals.clear(); - + //add solution if (this->solution != NULL) - + { - + char token[MAX_LENGTH]; - + strcpy(token, "O"); - + this->totals[token] = this->solution->get_total_o(); - + strcpy(token, "H"); - + this->totals[token] = this->solution->get_total_h(); - + strcpy(token, "Charge"); - + this->totals[token] = this->solution->get_cb(); - + this->totals.add_extensive(this->solution->get_totals(), 1.0); - + } - + if (this->exchange != NULL) - + { - + this->exchange->totalize(); - + this->totals.add_extensive(this->exchange->get_totals(), 1.0); - + } - + if (this->ppassemblage != NULL) - + { - + this->ppassemblage->totalize(); - + this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); - + } - + if (this->gasphase != NULL) - + { - + this->gasphase->totalize(); - + this->totals.add_extensive(this->gasphase->get_totals(), 1.0); - + } - + if (this->ssassemblage != NULL) - + { - + this->ssassemblage->totalize(); - + this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); - + } - + if (this->surface != NULL) - + { - + this->ssassemblage->totalize(); - + this->totals.add_extensive(this->surface->get_totals(), 1.0); - + } - + //Need to handle the following 3 reactions: // @@ -142,354 +146,361 @@ this->totals.add_extensive(this->surface->get_totals(), 1.0); //this->temperature = NULL; //this->totals.dump_raw(std::cerr, 1); return; + } #ifdef ORCHESTRA void cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat) + std::ostream & output_dat) { - + // // chemistry file // this->totalize(); - + // calculate orchestra components from PHREEQC totals this->ORCH_components(); - + // write definitions for chemistry chemistry_dat << std:: endl << "@class: species_reactions () {" << std::endl; - + this->ORCH_write_chemistry_water(chemistry_dat); - + this->ORCH_write_chemistry_primary(chemistry_dat); - + this->ORCH_write_chemistry_total_O_H(chemistry_dat); - + ORCH_write_chemistry_species(chemistry_dat); - + // add definitions for pure phases if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - + // add definitions for other PHREEQC entities here - + // finish up chemistry_dat << std::endl << "}" << std::endl; - + // // input file // input_dat << std::endl << "@class: input_file_data () {" << std::endl; - + this->ORCH_write_input(input_dat); - + input_dat << std::endl << "}" << std::endl; - + // // output file // output_dat << std::endl << "Output_every: 1" << std::endl; - + output_dat << "Var:"; - + this->ORCH_write_output_vars(output_dat); - + // add definitions for pure phases if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_output_vars(output_dat); - + //finish up output_dat << std::endl; + }; -void -cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) -{ +void +cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) +{ + // // Write water entities // chemistry_dat << std:: endl << "//********* The water entities" << std::endl; - + // e-, total hydrogen chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - + chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - + chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: endl; - + // H+, charge balance chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - + chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: endl; - + // H2O chemistry_dat << "@entity(" << s_h2o-> name << ", diss, 55.506)" << std::endl; - + chemistry_dat << std::endl; -} + +} void -cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) +cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) { - + chemistry_dat << std::endl << "//********* The primary species" << std:: endl; - + // // Write other master species definitions, i.e. primary entities // chemistry_dat << "@species(H+, 1)" << std::endl; - + for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) - + { - + std::string name(iter->first); - + if (name == "H(1)" || name == "E" || name == "H" || name == "O" || name == "Charge") continue; - + struct element *elt; - + char *element_name = string_hsave(name.c_str()); - + elt = element_store(element_name); - + assert(elt != NULL); - + struct species *s_ptr; - + s_ptr = elt->master->s; - + assert(s_ptr != NULL); - + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> z << ")" << std::endl; - + // regular mole balance chemistry_dat << "@primary_entity(" << s_ptr-> name << ", 1e-9, liter, 1.0e-9)" << std::endl; - -} + +} chemistry_dat << std::endl; -} + +} void -cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) +cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) { - + chemistry_dat << std:: endl << "//********* Define total hydrogen and oxygen" << std::endl; - + // Write H total equation chemistry_dat << "@var: total_hydrogen 0" << std::endl; - + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - + int i; - + for (i = 0; i < count_s_x; i++) - + { - + // write in terms of orchestra components if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - + { - + if (s_x[i]->h != 0) - + { - + chemistry_dat << "+"; - + if (s_x[i]->h != 1) - + { - + chemistry_dat << s_x[i]->h << "*"; - + } - + chemistry_dat << "{" << s_x[i]->name << ".liter}"; - + } - + } - + } - + chemistry_dat << "\")" << std::endl; - + // Write O total equation chemistry_dat << "@var: total_oxygen 0" << std::endl; - + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - + for (i = 0; i < count_s_x; i++) - + { - + if (s_x[i]->o != 0) - + { - + // write in terms of orchestra components if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - + { - + chemistry_dat << "+"; - + if (s_x[i]->o != 1) - + { - + chemistry_dat << s_x[i]->o << "*"; - + } - + chemistry_dat << "{" << s_x[i]->name << ".liter}"; - + } - + } - + } - + chemistry_dat << "\")" << std::endl; - + chemistry_dat << std::endl; -} -void -cxxSystem::ORCH_write_input(std::ostream & input_dat) -{ +} + +void +cxxSystem::ORCH_write_input(std::ostream & input_dat) +{ + // // Write orchestra input file info // std::ostringstream headings, data; - + data.precision(DBL_DIG - 1); - + headings << "var: "; - + data << "data: "; - + headings << "tempc\t"; - + data << this->solution->get_tc() << "\t"; - + headings << "pH\t"; - + data << this->solution->get_ph() << "\t"; - + headings << "pe\t"; - + data << this->solution->get_pe() << "\t"; - + headings << "H2O.act\t"; - + data << 1 << "\t"; - + headings << "I\t"; - + data << this->solution->get_mu() << "\t"; - + for (cxxNameDouble::iterator iter = this->orch_totals.begin(); iter != this->orch_totals.end(); ++iter) - + { - + headings << iter->first << ".liter" << "\t"; - + data << iter->second << "\t"; - + } - + // activity estimate for (cxxNameDouble::iterator iter = this->totals.begin(); iter != this->totals.end(); ++iter) - + { - + if (iter->first == "O" || iter->first == "Charge") continue; - + std::string master_name; - + struct master *master_ptr; - + master_ptr = master_bsearch(iter->first); - + assert(master_ptr != NULL); - + cxxNameDouble ma = this->solution->get_master_activity(); - + cxxNameDouble::iterator it = ma.find(iter->first); - + if (it == ma.end()) - + { - + it = ma.find(master_ptr->s->secondary->elt->name); - + } - + headings << master_ptr->s->name << ".act\t"; - + if (it != ma.end()) - + { - + data << pow(10., it->second) << "\t"; - + } else - + { - + data << 1e-9 << "\t"; - + } - + } - + // Isotopes //s_oss << "-Isotopes" << std::endl; @@ -499,257 +510,261 @@ data << 1e-9 << "\t"; it->dump_raw(s_oss, indent + 2); } } - */ - + */ + // Write data to string input_dat << headings.str() << std::endl; - + input_dat << data.str() << std::endl; - + return; + } -void -cxxSystem::ORCH_components(void) -{ +void +cxxSystem::ORCH_components(void) +{ + // translate from H, O, charge to H+tot, e-tot, and H2Otot cxxNameDouble::iterator it; - + cxxNameDouble temp_totals; - + // // Set names in orch_totals to master species names // this->orch_totals.clear(); - + temp_totals = this->totals; - + temp_totals.erase("H"); - + temp_totals.erase("O"); - + temp_totals.erase("Charge"); - + //temp_totals.dump_raw(std::cerr, 1); for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + { - + struct element *elt_ptr; - + elt_ptr = element_store(it->first); - + assert(elt_ptr != NULL); - + struct master *master_ptr; - + master_ptr = elt_ptr->primary; - + assert(master_ptr != NULL); - + double coef = master_ptr->coef; - + if (master_ptr->coef == 0) - + { - + coef = 1; - + } - + this->orch_totals[master_ptr->s->name] = it->second / coef; - + } - + // // Calculate h2otot // it = this->totals.find("O"); - + assert(it != this->totals.end()); - + double h2otot = it->second; - + // subtract O in master species for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + { - + struct element *elt_ptr; - + elt_ptr = element_store(it->first); - + struct master *master_ptr; - + master_ptr = elt_ptr->primary; - + h2otot -= it->second * master_ptr->s->o; - -} + +} // // Calculate htot // it = this->totals.find("H"); - + assert(it != this->totals.end()); - + double htot = it->second - 2 * h2otot; - + // subtract O in master species for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + { - + struct element *elt_ptr; - + elt_ptr = element_store(it->first); - + struct master *master_ptr; - + master_ptr = elt_ptr->primary; - + htot -= it->second * master_ptr->s->h; - -} + +} // // Calculate etot // it = this->totals.find("Charge"); - + assert(it != this->totals.end()); - + double etot = -it->second + htot; - + // subtract O in master species for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + { - + struct element *elt_ptr; - + elt_ptr = element_store(it->first); - + struct master *master_ptr; - + master_ptr = elt_ptr->primary; - + etot += it->second * master_ptr->s->z; - -} + +} // // store h2otot, htot, etot in orch_totals // this->orch_totals["H2O"] = h2otot; - + this->orch_totals["H+"] = htot; - + this->orch_totals["e-"] = etot; - + this->orch_totals.dump_raw(std::cerr, 1); -} + +} void -cxxSystem::ORCH_write_output_vars(std::ostream & outstream) +cxxSystem::ORCH_write_output_vars(std::ostream & outstream) { - + outstream << "\tnr_iter"; - + // // Serialize solution // outstream << "\tstart_solution"; - + //tc outstream << "\ttempc"; - + //pH outstream << "\tpH"; - + //pe outstream << "\tpe"; - + //mu outstream << "\tI"; - + //ah2o outstream << "\tH2O.act"; - + //total_h; outstream << "\ttotal_hydrogen"; - + //total_o; outstream << "\ttotal_oxygen"; - + //cb outstream << "\tchargebalance"; - + //mass_water; outstream << "\tH2O.con"; - + //total_alkalinity; outstream << "\tAlkalinity"; - + //orchestra master variables outstream << "\tH+.diss"; - + outstream << "\te-.diss"; - + outstream << "\tH2O.diss"; - + // // Write totals for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) - + { - + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - + outstream << "\t" << it->first << ".diss"; - + } - + outstream << "\tend_totals"; - + for (cxxNameDouble::iterator it = this->orch_totals.begin(); it != this->orch_totals.end(); it++) - + { - + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - + outstream << "\t" << it->first << ".act"; - + } - + outstream << "\tend_master_activities"; - + // // Write all species activities and concentrations // int i; - + for (i = 0; i < count_s_x; i++) { - + std::string name(s_x[i]->name); - + std::replace(name.begin(), name.end(), '(', '['); - + std::replace(name.begin(), name.end(), ')', ']'); - + outstream << "\t" << name.c_str() << ".act" << "\t" << name. c_str() << ".con"; - + } - + outstream << "\tend_species"; + } -#endif /* +#endif /* */ diff --git a/System.h b/System.h index 92e9ca36..c27c4eb5 100644 --- a/System.h +++ b/System.h @@ -10,7 +10,7 @@ #include "cxxMix.h" #include "Reaction.h" #include "Temperature.h" -class cxxSystem +class cxxSystem { public:cxxSystem(void); public: ~cxxSystem(void); @@ -46,7 +46,7 @@ class cxxSystem { this->temperature = entity; } void totalize(); - + #ifdef ORCHESTRA void ORCH_components(); void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, @@ -56,9 +56,10 @@ class cxxSystem void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); void ORCH_write_output_vars(std::ostream & outstream); void ORCH_write_input(std::ostream & input_dat); - + #endif /* */ - private:cxxSolution * solution; +private: + cxxSolution * solution; cxxExchange * exchange; cxxPPassemblage * ppassemblage; cxxGasPhase * gasphase; diff --git a/Temperature.h b/Temperature.h index 3997903a..ef7cf2a5 100644 --- a/Temperature.h +++ b/Temperature.h @@ -10,8 +10,6 @@ #include // std::list #include // std::vector -#include "char_star.h" - class cxxTemperature:public cxxNumKeyword { @@ -28,12 +26,12 @@ class cxxTemperature:public cxxNumKeyword void read_raw(CParser & parser); - protected: - std::vector < double >temps; +protected: + std::vector < double >temps; int countTemps; bool equalIncrements; - public: +public: //static std::map& map; }; diff --git a/Utils.h b/Utils.h index 4696d4e2..455258ef 100644 --- a/Utils.h +++ b/Utils.h @@ -6,7 +6,6 @@ #include // std::ostream #include // std::istream #include // std::map -#include "char_star.h" namespace Utilities { From b33830cc5c152e6b7cccc82864100a20e3869159 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Dec 2009 19:24:14 +0000 Subject: [PATCH 0116/1077] Moving class_main, phreeqc.cpp and phreeqc.h into phreeqcpp.sln Making a new configuration for compilation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3850 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 387 ++++++++++++++ Phreeqc.h | 1340 ++++++++++++++++++++++++++++++++++++++++++++++++ System.cxx | 1035 +++++++++++++------------------------ class_main.cpp | 191 +++++++ 4 files changed, 2273 insertions(+), 680 deletions(-) create mode 100644 Phreeqc.cpp create mode 100644 Phreeqc.h create mode 100644 class_main.cpp diff --git a/Phreeqc.cpp b/Phreeqc.cpp new file mode 100644 index 00000000..81259b91 --- /dev/null +++ b/Phreeqc.cpp @@ -0,0 +1,387 @@ +#include "Phreeqc.h" +//class Phreeqc +//{ +// Phreeqc(void); +// ~Phreeqc(void); +//}; +#include // std::replace + +Phreeqc::Phreeqc(void) +{ + s_pTail = NULL; + user_database = NULL; + output = NULL; + log_file = NULL; + punch_file = NULL; + dump_file = NULL; + error_file = NULL; + rates = NULL; + tally_table = NULL; + spec = NULL; + cations = NULL; + anions = NULL; + neutrals = NULL; + IPRSNT = NULL; + M = NULL; + LGAMMA = NULL; + sit_params = NULL; + sit_LGAMMA = NULL; + sit_IPRSNT = NULL; + sit_M = NULL; + + struct const_iso + { + const char *name; + LDBLE value; + LDBLE uncertainty; + }; + + + struct const_iso temp_iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} + }; + int temp_count_iso_defaults = + (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); + + count_iso_defaults = temp_count_iso_defaults; + iso_defaults = new iso[count_iso_defaults]; + + int i; + for (i = 0; i < temp_count_iso_defaults; i++) + { + iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); + iso_defaults[i].value = temp_iso_defaults[i].value; + iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; + } + + + struct const_key keyword_temp[] = { + {"eof", 0}, + {"end", 0}, + {"solution_species", 0}, + {"solution_master_species", 0}, + {"solution", 0}, + {"phases", 0}, + {"pure_phases", 0}, + {"reaction", 0}, + {"mix", 0}, + {"use", 0}, + {"save", 0}, + {"exchange_species", 0}, + {"exchange_master_species", 0}, + {"exchange", 0}, + {"surface_species", 0}, + {"surface_master_species", 0}, + {"surface", 0}, + {"reaction_temperature", 0}, + {"inverse_modeling", 0}, + {"gas_phase", 0}, + {"transport", 0}, + {"debug", 0}, + {"selected_output", 0}, + {"select_output", 0}, + {"knobs", 0}, + {"print", 0}, + {"equilibrium_phases", 0}, + {"equilibria", 0}, + {"equilibrium", 0}, + {"pure", 0}, + {"title", 0}, + {"comment", 0}, + {"advection", 0}, + {"kinetics", 0}, + {"incremental_reactions", 0}, + {"incremental", 0}, + {"rates", 0}, + {"solution_s", 0}, + {"user_print", 0}, + {"user_punch", 0}, + {"solid_solutions", 0}, + {"solid_solution", 0}, + {"solution_spread", 0}, + {"spread_solution", 0}, + {"selected_out", 0}, + {"select_out", 0}, + {"user_graph", 0}, + {"llnl_aqueous_model_parameters", 0}, + {"llnl_aqueous_model", 0}, + {"database", 0}, + {"named_analytical_expression", 0}, + {"named_analytical_expressions", 0}, + {"named_expressions", 0}, + {"named_log_k", 0}, + {"isotopes", 0}, + {"calculate_values", 0}, + {"isotope_ratios", 0}, + {"isotope_alphas", 0}, + {"copy", 0}, + {"pitzer", 0}, + {"sit", 0} +#ifdef PHREEQC_CPP + , + {"solution_raw", 0}, + {"exchange_raw", 0}, + {"surface_raw", 0}, + {"equilibrium_phases_raw", 0}, + {"kinetics_raw", 0}, + {"solid_solutions_raw", 0}, + {"gas_phase_raw", 0}, + {"reaction_raw", 0}, + {"mix_raw", 0}, + {"reaction_temperature_raw", 0}, + {"dump", 0}, + {"solution_modify", 0}, + {"equilibrium_phases_modify", 0}, + {"exchange_modify", 0}, + {"surface_modify", 0}, + {"solid_solutions_modify", 0}, + {"gas_phase_modify", 0}, + {"kinetics_modify", 0}, + {"delete", 0}, + {"run_cells", 0} +#endif + }; + NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ + + + //keyword = (struct const_key *) PHRQ_malloc((size_t) (NKEYS * sizeof(const_key))); + keyword = new const_key[NKEYS]; + for (i = 0; i < NKEYS; i++) + { + keyword[i].name = string_duplicate(keyword_temp[i].name); + keyword[i].keycount = 0; + } + + // basic.c + struct const_key command_temp[] = { + {"and", tokand}, + {"or", tokor}, + {"xor", tokxor}, + {"not", toknot}, + {"mod", tokmod}, + {"sqr", toksqr}, + {"sqrt", toksqrt}, + {"sin", toksin}, + {"cos", tokcos}, + {"tan", toktan}, + {"arctan", tokarctan}, + {"log", toklog}, + {"exp", tokexp}, + {"abs", tokabs}, + {"sgn", toksgn}, + {"str$", tokstr_}, + {"val", tokval}, + {"chr$", tokchr_}, + {"asc", tokasc}, + {"len", toklen}, + {"mid$", tokmid_}, + {"peek", tokpeek}, + {"let", toklet}, + {"print", tokprint}, + {"punch", tokpunch}, +#ifdef PHREEQ98 + {"graph_x", tokgraph_x}, + {"graph_y", tokgraph_y}, + {"graph_sy", tokgraph_sy}, +#endif + {"input", tokinput}, + {"goto", tokgoto}, + {"go to", tokgoto}, + {"if", tokif}, + {"end", tokend}, + {"stop", tokstop}, + {"for", tokfor}, + {"next", toknext}, + {"while", tokwhile}, + {"wend", tokwend}, + {"gosub", tokgosub}, + {"return", tokreturn}, + {"read", tokread}, + {"data", tokdata}, + {"restore", tokrestore}, + {"gotoxy", tokgotoxy}, + {"on", tokon}, + {"dim", tokdim}, + {"poke", tokpoke}, + {"list", toklist}, + {"run", tokrun}, + {"new", toknew}, + {"load", tokload}, + {"merge", tokmerge}, + {"save", toksave}, + {"bye", tokbye}, + {"quit", tokbye}, + {"del", tokdel}, + {"renum", tokrenum}, + {"then", tokthen}, + {"else", tokelse}, + {"to", tokto}, + {"step", tokstep}, + {"tc", toktc}, + {"tk", toktk}, + {"time", toktime}, + {"sim_time", toksim_time}, + {"total_time", toktotal_time}, + {"m0", tokm0}, + {"m", tokm}, + {"parm", tokparm}, + {"act", tokact}, + {"edl", tokedl}, + {"surf", toksurf}, + {"equi", tokequi}, + {"kin", tokkin}, + {"gas", tokgas}, + {"s_s", toks_s}, + {"misc1", tokmisc1}, + {"misc2", tokmisc2}, + {"mu", tokmu}, + {"osmotic", tokosmotic}, + {"alk", tokalk}, + {"lk_species", toklk_species}, + {"lk_named", toklk_named}, + {"lk_phase", toklk_phase}, + {"sum_species", toksum_species}, + {"sum_gas", toksum_gas}, + {"sum_s_s", toksum_s_s}, + {"calc_value", tokcalc_value}, + {"description", tokdescription}, + {"sys", toksys}, + {"instr", tokinstr}, + {"ltrim", tokltrim}, + {"rtrim", tokrtrim}, + {"trim", toktrim}, + {"pad", tokpad}, + {"rxn", tokrxn}, + {"dist", tokdist}, + {"mol", tokmol}, + {"la", tokla}, + {"lm", toklm}, + {"sr", toksr}, + {"si", toksi}, + {"step_no", tokstep_no}, + {"cell_no", tokcell_no}, + {"sim_no", toksim_no}, + {"tot", toktot}, + {"log10", toklog10}, + {"charge_balance", tokcharge_balance}, + {"percent_error", tokpercent_error}, + {"put", tokput}, + {"get", tokget}, + {"exists", tokexists}, + {"rem", tokrem}, + {"change_por", tokchange_por}, + {"get_por", tokget_por}, + {"change_surf", tokchange_surf}, + {"porevolume", tokporevolume}, + {"sc", toksc}, + {"gamma", tokgamma}, + /* VP: Density Start */ + {"lg", toklg}, + {"rho", tokrho} + /* VP: Density End */ + }; + NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); + command = new const_key[NCMDS]; + for (i = 0; i < NCMDS; i++) + { + command[i].name = string_duplicate(command_temp[i].name); + command[i].keycount = command_temp[i].keycount; + } + + //cl1.c + x_arg = NULL, res_arg = NULL, scratch = NULL; + x_arg_max = 0, res_arg_max = 0, scratch_max = 0; + + // dw.c + GASCON = 0.461522e0; + TZ = 647.073e0; + AA = 1.e0; + G1 = 11.e0; + G2 = 44.333333333333e0; + GF = 3.5e0; + + // model.c + min_value = 1e-10; + normal = NULL; + ineq_array = NULL; + res = NULL; + cu = NULL; + zero = NULL; + delta1 = NULL; + iu = NULL; + is = NULL; + back_eq = NULL; + normal_max = 0; + ineq_array_max = 0; + res_max = 0; + cu_max = 0; + zero_max = 0; + delta1_max = 0; + iu_max = 0; + is_max = 0; + back_eq_max = 0; + + // output.c + output_callbacks = new Phreeqc::output_callback[MAX_CALLBACKS]; + count_output_callback = 0; + forward_output_to_log = 0; + + // phqalloc.c + //s_pTail = NULL; + + // transport.c + J_ij = NULL; + J_ij_il = NULL; + m_s = NULL; + + default_data_base = string_duplicate("phreeqc.dat"); + +//FILE *input_file = NULL; +//FILE *database_file = NULL; +//FILE *output = NULL; /* OUTPUT_MESSAGE */ +//FILE *log_file = NULL; /* OUTPUT_LOG */ +//FILE *punch_file = NULL; /* OUTPUT_PUNCH */ +//FILE *error_file = NULL; /* OUTPUT_ERROR */ +//FILE *dump_file = NULL; /* OUTPUT_DUMP */ +} + +Phreeqc::~Phreeqc(void) +{ + + clean_up(); + close_input_files(); + close_output_files(); + + int i; + for (i = 0; i < count_iso_defaults; i++) + { + iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); + } + for (i = 0; i < NKEYS; i++) + { + keyword[i].name = (char *) free_check_null((void *) keyword[i].name); + } + delete[] keyword; + for (i = 0; i < NCMDS; i++) + { + command[i].name = (char *) free_check_null((void *) command[i].name); + } + delete[] command; + + free_check_null(default_data_base); + + PHRQ_free_all(); +} +void Phreeqc::set_phast(int tf) +{ + this->phast = tf; +} diff --git a/Phreeqc.h b/Phreeqc.h new file mode 100644 index 00000000..0b74e8a5 --- /dev/null +++ b/Phreeqc.h @@ -0,0 +1,1340 @@ +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +/* ---------------------------------------------------------------------- + * INCLUDE FILES + * ---------------------------------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "cvdense.h" +#include "nvector_serial.h" /* definitions of type N_Vector and macro */ + /* NV_Ith_S, prototypes for N_VNew, N_VFree */ +#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM */ +#include "nvector.h" + +#define STATIC +#define EXTERNAL +#define CLASS_QUALIFIER Phreeqc:: +#define CLASS_STATIC static +#define extern +#include "p2c.h" +#undef extern + +class Phreeqc +{ +public: + Phreeqc(void); + ~Phreeqc(void); + + +private: + +struct _generic_N_Vector; +struct calculate_value; +struct conc; +struct CVodeMemRec; +struct element; +struct exchange; +struct exch_comp; +struct elt_list; +struct gas_phase; +struct gas_comp; +struct inverse; +struct inv_elts; +struct inv_phases; +struct inv_isotope; +struct irrev; +struct isotope; +struct kinetics; +struct kinetics_comp; +struct LOC_exec; +struct master; +struct master_activity; +struct master_isotope; +struct mix; +struct mix_comp; +struct name_coef; +struct pe_data; +struct phase; +struct PHRQMemHeader; +struct pitz_param; +struct pp_assemblage; +struct pure_phase; +struct reaction; +struct reaction_temp; +struct rxn_token; +struct rxn_token_temp; +struct solution; +struct species; +struct s_s; +struct s_s_assemblage; +struct s_s_comp; +struct species_diff_layer; +struct surface; +struct surface_comp; +struct surface_charge; +struct surface_diff_layer; +struct theta_param; +struct tokenrec; +struct varrec; +struct unknown; + +#define PITZER_EXTERNAL +#include "pitzer.h" +#include "input.h" +#define KINETICS_EXTERNAL +#include "sundialstypes.h" /* definitions of types realtype and */ + /* integertype, and the constant FALSE */ +public: +#include "output.h" +private: +#include "global.h" + +/* + All functions are included as methods here +*/ +#define _INC_PHRQPROTO_H + +// advection.c ------------------------------- + +int advection(void); + +// basic.c ------------------------------- + +int basic_main(char *commands); +void cmd_initialize(void); +void cmd_free(void); +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +int basic_init(void); +#ifdef PHREEQ98 +void GridChar(char *s, char *a); +#endif +int sget_logical_line(char **ptr, int *l, char *return_line); +int free_dim_stringvar(varrec *varbase); +void exec(void); +int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); +void restoredata(void); +void clearloops(void); +void clearvar(varrec * v); +void clearvars(void); +Char * numtostr(Char * Result, LDBLE n); +void parse(Char * inbuf, tokenrec ** buf); +void listtokens(FILE * f, tokenrec * buf); +void disposetokens(tokenrec ** tok); +void parseinput(tokenrec ** buf); +void errormsg(const Char * s); +void snerr(const Char * s); +void tmerr(const Char * s); +void badsubscr(void); +LDBLE realfactor(struct LOC_exec *LINK); +Char * strfactor(struct LOC_exec * LINK); +Char *stringfactor(Char * Result, struct LOC_exec *LINK); +long intfactor(struct LOC_exec *LINK); +LDBLE realexpr(struct LOC_exec *LINK); +Char * strexpr(struct LOC_exec * LINK); +Char * stringexpr(Char * Result, struct LOC_exec * LINK); +long intexpr(struct LOC_exec *LINK); +void require(int k, struct LOC_exec *LINK); +void skipparen(struct LOC_exec *LINK); +varrec * findvar(struct LOC_exec *LINK); +valrec factor(struct LOC_exec *LINK); +valrec upexpr(struct LOC_exec * LINK); +valrec term(struct LOC_exec * LINK); +valrec sexpr(struct LOC_exec * LINK); +valrec relexpr(struct LOC_exec * LINK); +valrec andexpr(struct LOC_exec * LINK); +valrec expr(struct LOC_exec *LINK); +void checkextra(struct LOC_exec *LINK); +boolean iseos(struct LOC_exec *LINK); +void skiptoeos(struct LOC_exec *LINK); +linerec * findline(long n); +linerec * mustfindline(long n); +void cmdend(struct LOC_exec *LINK); +void cmdnew(struct LOC_exec *LINK); +void cmdlist(struct LOC_exec *LINK); +void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); +void cmdrun(struct LOC_exec *LINK); +void cmdsave(struct LOC_exec *LINK); +void cmdput(struct LOC_exec *LINK); +void cmdchange_por(struct LOC_exec *LINK); +void cmdchange_surf(struct LOC_exec *LINK); +void cmdbye(void); +void cmddel(struct LOC_exec *LINK); +void cmdrenum(struct LOC_exec *LINK); +void cmdprint(struct LOC_exec *LINK); +void cmdpunch(struct LOC_exec *LINK); +#ifdef PHREEQ98 +void cmdgraph_x(struct LOC_exec *LINK); +void cmdgraph_y(struct LOC_exec *LINK); +void cmdgraph_sy(struct LOC_exec *LINK); +#endif +void cmdlet(boolean implied, struct LOC_exec *LINK); +void cmdgoto(struct LOC_exec *LINK); +void cmdif(struct LOC_exec *LINK); +void cmdelse(struct LOC_exec *LINK); +boolean skiploop(int up, int dn, struct LOC_exec *LINK); +void cmdfor(struct LOC_exec *LINK); +void cmdnext(struct LOC_exec *LINK); +void cmdwhile(struct LOC_exec *LINK); +void cmdwend(struct LOC_exec *LINK); +void cmdgosub(struct LOC_exec *LINK); +void cmdreturn(struct LOC_exec *LINK); +void cmdread(struct LOC_exec *LINK); +void cmddata(struct LOC_exec *LINK); +void cmdrestore(struct LOC_exec *LINK); +void cmdgotoxy(struct LOC_exec *LINK); +void cmdon(struct LOC_exec *LINK); +void cmddim(struct LOC_exec *LINK); +void cmdpoke(struct LOC_exec *LINK); + +// basicsubs.c ------------------------------- + +LDBLE activity(const char *species_name); +LDBLE activity_coefficient(const char *species_name); +LDBLE log_activity_coefficient(const char *species_name); +LDBLE calc_SC(void); +/* VP: Density Start */ +LDBLE calc_dens(void); +/* VP: Density End */ +LDBLE calc_logk_n(const char *name); +LDBLE calc_logk_p(const char *name); +LDBLE calc_logk_s(const char *name); +LDBLE calc_surface_charge(const char *surface_name); +LDBLE diff_layer_total(const char *total_name, const char *surface_name); +LDBLE equi_phase(const char *phase_name); +LDBLE find_gas_comp(const char *gas_comp_name); +LDBLE find_misc1(const char *s_s_name); +LDBLE find_misc2(const char *s_s_name); +LDBLE find_s_s_comp(const char *s_s_comp_name); +LDBLE get_calculate_value(const char *name); +LDBLE kinetics_moles(const char *kinetics_name); +LDBLE log_activity(const char *species_name); +LDBLE log_molality(const char *species_name); +LDBLE molality(const char *species_name); +LDBLE saturation_ratio(const char *phase_name); +int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); +LDBLE solution_sum_secondary(const char *total_name); +LDBLE sum_match_gases(const char *stemplate, const char *name); +LDBLE sum_match_species(const char *stemplate, const char *name); +LDBLE sum_match_s_s(const char *stemplate, const char *name); +int match_elts_in_species(const char *name, const char *stemplate); +int extract_bracket(char **string, char *bracket_string); +LDBLE surf_total(const char *total_name, const char *surface_name); +CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); +LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); +int system_total_elements(void); +int system_total_si(void); +int system_total_aq(void); +int system_total_ex(void); +int system_total_surf(void); +int system_total_gas(void); +int system_total_s_s(void); +int system_total_elt(const char *total_name); +int system_total_elt_secondary(const char *total_name); +LDBLE total(const char *total_name); +int system_total_solids(struct exchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr); + +static LDBLE f_rho(LDBLE rho_old, void *cookie); + +// cl1.c ------------------------------- +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); +void cl1_space(int check, int n2d, int klm, int nklmd); + +// cl1mp.c ------------------------------- +int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + +// class_main.c ------------------------------- +#ifdef DOS +int write_banner(void); +#endif + +/* default.c */ +int close_input_files(void); +int close_output_files(void); +CLASS_STATIC int getc_callback(void *cookie); +int process_file_names(int argc, char *argv[], void **db_cookie, + void **input_cookie, int log); + +// dw.c ------------------------------- +int BB(LDBLE T); +LDBLE PS(LDBLE T); +LDBLE VLEST(LDBLE T); +int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); +int QQ(LDBLE T, LDBLE D); +LDBLE BASE(LDBLE D); + +// input.c ------------------------------- + +int reading_database(void); +struct read_callback s_read_callback; +int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + +// integrate.c ------------------------------- + +int calc_all_g(void); +int calc_init_g(void); +int initial_surface_water(void); +int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); +int calc_all_donnan(void); +int calc_init_donnan(void); +LDBLE g_function(LDBLE x_value); +LDBLE midpnt(LDBLE x1, LDBLE x2, int n); +void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); +LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); +LDBLE calc_psi_avg(LDBLE surf_chrg_eq); +int calc_all_donnan_music(void); +int calc_init_donnan_music(void); + +// inverse.c ------------------------------- + +int inverse_models(void); +int add_to_file(const char *filename, char *string); +int bit_print(unsigned long bits, int l); +int carbon_derivs(struct inverse *inv_ptr); +int check_isotopes(struct inverse *inv_ptr); +int check_solns(struct inverse *inv_ptr); +int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); +struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); +struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); +int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); +int post_mortem(void); +unsigned long get_bits(unsigned long bits, int position, int number); +unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); +void dump_netpath(struct inverse *inv_ptr); +int dump_netpath_pat(struct inverse *inv_ptr); +int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); +int phase_isotope_inequalities(struct inverse *inv_ptr); +int print_model(struct inverse *inv_ptr); +int punch_model_heading(struct inverse *inv_ptr); +int punch_model(struct inverse *inv_ptr); +void print_isotope(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); +void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); +int range(struct inverse *inv_ptr, unsigned long cur_bits); +int save_bad(unsigned long bits); +int save_good(unsigned long bits); +int save_minimal(unsigned long bits); +unsigned long set_bit(unsigned long bits, int position, int value); +int setup_inverse(struct inverse *inv_ptr); +int set_initial_solution(int n_user_old, int n_user_new); +int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *soln_ptr_orig, + int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); +int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); +int solve_inverse(struct inverse *inv_ptr); +int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); +int subset_bad(unsigned long bits); +int subset_minimal(unsigned long bits); +int superset_minimal(unsigned long bits); +int write_optimize_names(struct inverse *inv_ptr); + +// isotopes.c ------------------------------- + +int add_isotopes(struct solution *solution_ptr); +int calculate_values(void); +int calculate_isotope_moles(struct element *elt_ptr, + struct solution *solution_ptr, LDBLE total_moles); +LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); +int from_pcil(struct master_isotope *master_isotope_ptr); +int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_tu(struct master_isotope *master_isotope_ptr); +struct calculate_value *calculate_value_alloc(void); +int calculate_value_free(struct calculate_value *calculate_value_ptr); +struct calculate_value *calculate_value_search(const char *name); +struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); +struct isotope_alpha *isotope_alpha_alloc(void); +struct isotope_alpha *isotope_alpha_search(const char *name); +struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); +struct isotope_ratio *isotope_ratio_alloc(void); +struct isotope_ratio *isotope_ratio_search(const char *name); +struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_alloc(void); +struct master_isotope *master_isotope_search(const char *name); +int print_initial_solution_isotopes(void); +int print_isotope_ratios(void); +int print_isotope_alphas(void); +int punch_isotopes(void); +int punch_calculate_values(void); +int read_calculate_values(void); +int read_isotopes(void); +int read_isotope_ratios(void); +int read_isotope_alphas(void); +int calculate_value_init(struct calculate_value *calculate_value_ptr); +int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); +int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); +int master_isotope_init(struct master_isotope *master_isotope_ptr); + +// kinetics.c ------------------------------- + +void cvode_init(void); +int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); +int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_advection(int i, int use_mix, int use_kinetics, int nsaver); +int free_cvode(void); +public: +static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + +private: +int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); +int calc_kinetic_reaction(struct kinetics *kinetics_ptr, + LDBLE time_step); +int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); +int set_reaction(int i, int use_mix, int use_kinetics); +int set_transport(int i, int use_mix, int use_kinetics, int nsaver); +int store_get_equi_reactants(int k, int kin_end); + +// mainsubs ------------------------------- + +FILE *file_open(char *query, char *default_name, const char *status, + int batch); +int copy_entities(void); +void initialize(void); +int initial_exchangers(int print); +int initial_gas_phases(int print); +int initial_solutions(int print); +int step_save_exch(int n_user); +int step_save_surf(int n_user); +int initial_surfaces(int print); +int reactions(void); +int saver(void); +int xsolution_save(int k_user); +int xexchange_save(int n_user); +int xgas_save(int n_user); +int xpp_assemblage_save(int n_user); +int xs_s_assemblage_save(int n_user); +int xsurface_save(int n_user); +int do_initialize(void); +int do_status(void); + +int copy_use(int i); +int set_use(void); + +// model.c ------------------------------- + +int check_residuals(void); +int free_model_allocs(void); +int ineq(int kode); +int model(void); +int jacobian_sums(void); +int mb_gases(void); +int mb_s_s(void); +int mb_sums(void); +int molalities(int allow_overflow); +int reset(void); +int residuals(void); +int set(int initial); +int sum_species(void); +int surface_model(void); + +LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); +LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); +LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); +int numerical_jacobian(void); +void set_inert_moles(void); +void unset_inert_moles(void); +#ifdef SLNQ +int add_trivial_eqns(int rows, int cols, LDBLE * matrix); +int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif +int calc_gas_pressures(void); +int calc_s_s_fractions(void); +int gammas(LDBLE mu); +int initial_guesses(void); +int revise_guesses(void); +int s_s_binary(struct s_s *s_s_ptr); +int s_s_ideal(struct s_s *s_s_ptr); +int remove_unstable_phases; +int gas_in; +void ineq_init(int max_row_count, int max_column_count); + +// output.c ------------------------------- + +int output_message(const int type, const char *err_str, const int stop, + const char *format, va_list args); + +// parse.c ------------------------------- + +int check_eqn(int association); +int get_charge(char *charge, LDBLE * z); +int get_elt(char **t_ptr, char *element, int *i); +int get_elts_in_species(char **t_ptr, LDBLE coef); +int get_num(char **t_ptr, LDBLE * num); +int get_secondary_in_species(char **t_ptr, LDBLE coef); +int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + +int get_coef(LDBLE * coef, char **eqnaddr); +int get_secondary(char **t_ptr, char *element, int *i); +int get_species(char **ptr); + +// phqalloc.c ------------------------------- + +public: +#if !defined(NDEBUG) +void *PHRQ_malloc(size_t, const char *, int); +void *PHRQ_calloc(size_t, size_t, const char *, int); +void *PHRQ_realloc(void *, size_t, const char *, int); +#else +void *PHRQ_malloc(size_t); +void *PHRQ_calloc(size_t, size_t); +void *PHRQ_realloc(void *, size_t); +#endif +void PHRQ_free(void *ptr); +private: +void PHRQ_free_all(void); + +// phreeqc_files.c ------------------------------- + +#ifdef PHREEQ98 +void check_line_breaks(char *s); +char *prefix_database_dir(char *s); +void show_progress(const int type, char *s); +#endif +int fileop_handler(const int type, int (*PFN) (FILE *)); +int open_handler(const int type, const char *file_name); +int output_handler(const int type, const char *err_str, + const int stop, void *cookie, const char *format, + va_list args); +static int rewind_wrapper(FILE * file_ptr); +Void PASCAL_MAIN(int argc, Char **argv); +long my_labs(long x); +Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); +Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); +int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); +Anyptr my_memset(Anyptr d, int c, size_t n); +int my_toupper(int c); +int my_tolower(int c); +long ipow(long a, long b); +char * strsub(register char *ret, register char *s, register int pos, + register int len); +int strpos2(char *s, register char *pat, register int pos); +int strcicmp(register char *s1, register char *s2); +char * strltrim(register char *s); +char * strrtrim(register char *s); +void strmove(register int len, register char *s, register int spos, + register char *d, register int dpos); +void strinsert(register char *src, register char *dst, register int pos); +int P_peek(FILE * f); +int P_eof(void); +int P_eoln(FILE * f); +Void P_readpaoc(FILE * f, char *s, int len); +Void P_readlnpaoc(FILE * f, char *s, int len); +long P_maxpos(FILE * f); +Char * P_trimname(register Char * fn, register int len); +long memavail(void); +long maxavail(void); +long * P_setunion(register long *d, register long *s1, register long *s2); +long * P_setint(register long *d, register long *s1, register long *s2); +long * P_setdiff(register long *d, register long *s1, register long *s2); +long * P_setxor(register long *d, register long *s1, register long *s2); +long * P_addset(register long *s, register unsigned val); +long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); +long * P_remset(register long *s, register unsigned val); +int P_setequal(register long *s1, register long *s2); +int P_subset(register long *s1, register long *s2); +long * P_setcpy(register long *d, register long *s); +long * P_expset(register long *d, register long s); +long P_packset(register long *s); +int _OutMem(void); +int _CaseCheck(void); +int _NilCheck(void); +static char * _ShowEscape(char *buf, int code, int ior, char *prefix); +int _Escape(int code); +int _EscIO(int code); + +// pitzer.c ------------------------------- + +int gammas_pz(void); +int model_pz(void); +int pitzer(void); +int pitzer_clean_up(void); +int pitzer_init(void); +int pitzer_tidy(void); +int read_pitzer(void); +int set_pz(int initial); + +int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_pz(void); +int ISPEC(char *name); +LDBLE G(LDBLE Y); +LDBLE GP(LDBLE Y); +int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); +int BDK(LDBLE X); +int pitzer_initial_guesses(void); +int pitzer_revise_guesses(void); +int pitzer_remove_unstable_phases; +int PTEMP(LDBLE TK); +LDBLE JAY(LDBLE X); +LDBLE JPRIME(LDBLE Y); +int jacobian_pz(void); + +// pitzer_structures.c ------------------------------- + +struct pitz_param *pitz_param_alloc(void); +int pitz_param_init(struct pitz_param *pitz_param_ptr); +struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); +int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + +// pitzer_structures.c ------------------------------- + +int add_potential_factor(void); +int add_cd_music_factors(int n); +int add_surface_charge_balance(void); +int add_cd_music_charge_balances(int i); +int build_gas_phase(void); +int build_jacobian_sums(int k); +int build_mb_sums(void); +int build_min_exch(void); +int build_model(void); +int build_pure_phases(void); +int build_s_s_assemblage(void); +int build_solution_phase_boundaries(void); +int build_species_list(int n); +int build_min_surface(void); +int change_hydrogen_in_elt_list(LDBLE charge); +int clear(void); +int convert_units(struct solution *solution_ptr); +struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); +struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); +int inout(void); +int is_special(struct species *spec); +int mb_for_species_aq(int n); +int mb_for_species_ex(int n); +int mb_for_species_surf(int n); +int quick_setup(void); +int resetup_master(void); +int save_model(void); +int setup_exchange(void); +int setup_gas_phase(void); +int setup_master_rxn(struct master **master_ptr_list, + struct reaction **pe_rxn); +int setup_pure_phases(void); +int setup_related_surface(void); +int setup_s_s_assemblage(void); +int setup_solution(void); +int setup_surface(void); +int setup_unknowns(void); +int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); +int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); +int store_jacob0(int row, int column, LDBLE coef); +int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); +int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); +int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); +int tidy_redox(void); +struct master **unknown_alloc_master(void); +int write_mb_eqn_x(void); +int write_mb_for_species_list(int n); +int write_mass_action_eqn_x(int stop); + +/* prep.c */ + +int check_same_model(void); +int k_temp(LDBLE tc); +LDBLE k_calc(LDBLE * logk, LDBLE tempk); +int prep(void); +int reprep(void); +int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); +int switch_bases(void); +int write_phase_sys_total(int n); + +// print.c ------------------------------- + +int fpunchf(const char *name, const char *format, ...); +int fpunchf_user(int user_index, const char *format, ...); +char *sformatf(const char *format, ...); +int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); +int print_all(void); +int print_exchange(void); +int print_gas_phase(void); +int print_master_reactions(void); +int print_reaction(struct reaction *rxn_ptr); +int print_species(void); +int print_surface(void); +int print_user_print(void); +int punch_all(void); + +int print_alkalinity(void); +int print_diffuse_layer(struct surface_charge *surface_charge_ptr); +int print_eh(void); +int print_irrev(void); +int print_kinetics(void); +int print_mix(void); +int print_pp_assemblage(void); +int print_s_s_assemblage(void); +int print_saturation_indices(void); +int print_surface_cd_music(void); +int print_totals(void); +int print_using(void); +/*int print_user_print(void);*/ +int punch_gas_phase(void); +int punch_identifiers(void); +int punch_kinetics(void); +int punch_molalities(void); +int punch_activities(void); +int punch_pp_assemblage(void); +int punch_s_s_assemblage(void); +int punch_saturation_indices(void); +int punch_totals(void); +int punch_user_punch(void); +#ifdef PHREEQ98 +int punch_user_graph(void); +#endif + +// read.c ------------------------------- + +int read_input(void); +int read_conc(int n, int count_mass_balance, char *str); +int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); +int read_log_k_only(char *ptr, LDBLE * log_k); +int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description); +int check_key(char *str); +int check_units(char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print); +int find_option(char *item, int *n, const char **list, int count_list, + int exact); +int get_option(const char **opt_list, int count_opt_list, char **next_char); +int get_true_false(char *string, int default_value); + +int add_psi_master_species(char *token); +int read_advection(void); +int read_analytical_expression_only(char *ptr, LDBLE * log_k); +/* VP: Density Start */ +int read_millero_abcdef (char *ptr, LDBLE * abcdef); +/* VP: Density End */ +int read_copy(void); +int read_debug(void); +int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); +int read_llnl_aqueous_model_parameters(void); +int read_exchange(void); +int read_exchange_master_species(void); +int read_exchange_species(void); +int read_gas_phase(void); +int read_incremental_reactions(void); +int read_inverse(void); +int read_inv_balances(struct inverse *inverse_ptr, char *next_char); +int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); +int read_inv_phases(struct inverse *inverse_ptr, char *next_char); +int read_kinetics(void); +int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); +int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); +LDBLE *read_list_doubles(char **ptr, int *count_doubles); +int *read_list_ints(char **ptr, int *count_ints, int positive); +int *read_list_t_f(char **ptr, int *count_ints); +int read_master_species(void); +int read_mix(void); +int read_named_logk(void); +int read_phases(void); +int read_print(void); +int read_pure_phases(void); +int read_rates(void); +int read_reaction(void); +int read_reaction_reactants(struct irrev *irrev_ptr); +int read_reaction_steps(struct irrev *irrev_ptr); +int read_solid_solutions(void); +int read_temperature(void); +int read_reaction_temps(struct temperature *temperature_ptr); +int read_save(void); +int read_selected_output(void); +int read_solution(void); +int read_species(void); +int read_surf(void); +int read_surface_master_species(void); +int read_surface_species(void); +int read_use(void); +int read_title(void); +int read_user_print(void); +int read_user_punch(void); +#ifdef PHREEQ98 +int read_user_graph(void); +int copy_title(char *token_ptr, char **ptr, int *length); +int OpenCSVFile(char file_name[MAX_LENGTH]); +void GridHeadings(char *s, int i); +void SetAxisTitles(char *s, int i); +void SetAxisScale(char *a, int c, char *v, int l); +void SetChartTitle(char *s); +#endif +int next_keyword_or_option(const char **opt_list, int count_opt_list); + +// readtr.c ------------------------------- + +int read_transport(void); +int dump(void); +int dump_exchange(int k); +int dump_gas_phase(int k); +int dump_kinetics(int k); +int dump_mix(int k); +int dump_pp_assemblage(int k); +int dump_reaction(int k); +int dump_s_s_assemblage(int k); +int dump_solution(int k); +int dump_surface(int k); + +int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + +// sit.c ------------------------------- + +int gammas_sit(void); +int model_sit(void); +int sit(void); +int sit_clean_up(void); +int sit_init(void); +int sit_tidy(void); +int read_sit(void); +int set_sit(int initial); + +int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_sit(void); +int sit_ISPEC(char *name); +/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ +int sit_initial_guesses(void); +int sit_revise_guesses(void); +int sit_remove_unstable_phases; +int PTEMP_SIT(LDBLE tk); +int jacobian_sit(void); + +// spread.c ------------------------------- + +int read_solution_spread(void); + +int copy_token_tab(char *token_ptr, char **ptr, int *length); +int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); +int spread_row_free(struct spread_row *spread_row_ptr); +int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); +struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI +void add_row(struct spread_row *spread_row_ptr); +void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); +void free_spread(void); +struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + +// step.c ------------------------------- + +int step(LDBLE step_fraction); +int xsolution_zero(void); +int add_exchange(struct exchange *exchange_ptr); +int add_gas_phase(struct gas_phase *gas_phase_ptr); +int add_kinetics(struct kinetics *kinetics_ptr); +int add_mix(struct mix *mix_ptr); +int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int add_reaction(struct irrev *irrev_ptr, int step_number, + LDBLE step_fraction); +int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); +int add_solution(struct solution *solution_ptr, LDBLE extensive, + LDBLE intensive); +int add_surface(struct surface *surface_ptr); +int add_temperature(struct temperature *temperature_ptr, int step_number); + +int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int gas_phase_check(struct gas_phase *gas_phase_ptr); +int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); +int reaction_calc(struct irrev *irrev_ptr); +int solution_check(void); +int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); + +// structures.c ------------------------------- + +int clean_up(void); +int reinitialize(void); +int copier_add(struct copier *copier_ptr, int n_user, int start, int end); +int copier_free(struct copier *copier_ptr); +int copier_init(struct copier *copier_ptr); +CLASS_STATIC int element_compare(const void *ptr1, const void *ptr2); +struct element *element_store(const char *element); +int elt_list_combine(void); +CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); +struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); +int elt_list_print(struct elt_list *elt_list_ptr); +struct elt_list *elt_list_save(void); +struct exchange *exchange_alloc(void); +struct exchange *exchange_bsearch(int k, int *n); +int exchange_comp_compare(const void *ptr1, const void *ptr2); +void exchange_comp_init(struct exch_comp *exch_comp_ptr); +int exchange_copy(struct exchange *exchange_old_ptr, + struct exchange *exchange_new_ptr, int n_user_new); +CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); +int exchange_copy_to_last(int n, int n_user); +int exchange_delete(int n_user_old); +int exchange_duplicate(int n_user_old, int n_user_new); +int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, + const char *description); +int exchange_free(struct exchange *exchange_ptr); +int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); +struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, + int n_user_new); +struct exchange *exchange_search(int n_user, int *n, int print); +int exchange_sort(void); +CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); +struct gas_phase *gas_phase_alloc(void); +struct gas_phase *gas_phase_bsearch(int k, int *n); +CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); +int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new); +int gas_phase_copy_to_last(int n, int n_user); +int gas_phase_delete(int n_user_old); +int gas_phase_duplicate(int n_user_old, int n_user_new); +int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, + int n_user_end, char *description); +int gas_phase_free(struct gas_phase *gas_phase_ptr); +int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, + int n_user_new); +struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, + int n_user_new); +struct gas_phase *gas_phase_search(int n_user, int *n); +int gas_phase_sort(void); +enum entity_type get_entity_enum(char *name); +struct inverse *inverse_alloc(void); +int inverse_delete(int i); +CLASS_STATIC int inverse_isotope_compare(const void *ptr1, const void *ptr2); +struct inverse *inverse_search(int n_user, int *n); +int inverse_sort(void); +struct irrev *irrev_bsearch(int k, int *n); +int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, + int n_user_new); +int irrev_delete(int n_user_old); +int irrev_duplicate(int n_user_old, int n_user_new); +int irrev_free(struct irrev *irrev_ptr); +struct irrev *irrev_search(int n_user, int *n); +int irrev_sort(void); +struct kinetics *kinetics_alloc(void); +struct kinetics *kinetics_bsearch(int k, int *n); +int kinetics_delete(int n_user_old); +int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, + struct kinetics_comp *kinetics_comp_old_ptr); +CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); +int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new); +int kinetics_copy_to_last(int n, int n_user); +int kinetics_duplicate(int n_user_old, int n_user_new); +int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, + char *description); +int kinetics_free(struct kinetics *kinetics_ptr); +int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); +struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, + int n_user_new); +struct kinetics *kinetics_search(int n_user, int *n, int print); +int kinetics_sort(void); +struct logk *logk_alloc(void); +int logk_copy2orig(struct logk *logk_ptr); +struct logk *logk_store(char *name, int replace_if_found); +struct logk *logk_search(char *name); +struct master *master_alloc(void); +CLASS_STATIC int master_compare(const void *ptr1, const void *ptr2); +int master_delete(char *ptr); +struct master *master_bsearch(const char *ptr); +struct master *master_bsearch_primary(char *ptr); +struct master *master_search(char *ptr, int *n); +struct mix *mix_bsearch(int k, int *n); +int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new); +int mix_delete(int n_user_old); +int mix_duplicate(int n_user_old, int n_user_new); +int mix_free(struct mix *mix_ptr); +struct mix *mix_search(int n_user, int *n, int print); +int mix_sort(void); +struct pe_data *pe_data_alloc(void); +struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); +struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +int pe_data_store(struct pe_data **pe, const char *token); +struct phase *phase_bsearch(const char *ptr, int *j, int print); +CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); +int phase_delete(int i); +struct phase *phase_store(char *name); +struct pp_assemblage *pp_assemblage_alloc(void); +struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); +CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); +int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, + int n_user_new); +int pp_assemblage_copy_to_last(int n, int n_user); +int pp_assemblage_delete(int n_user_old); +int pp_assemblage_duplicate(int n_user_old, int n_user_new); +int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); +int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, + int n_user_end, char *description); +int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, + int n_user_new); +struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage + *pp_assemblage_old_ptr, + int n_user_new); +struct pp_assemblage *pp_assemblage_search(int n_user, int *n); +int pp_assemblage_sort(void); +CLASS_STATIC int pure_phase_compare(const void *ptr1, const void *ptr2); +struct rate *rate_bsearch(char *ptr, int *j); +int rate_free(struct rate *rate_ptr); +struct rate *rate_search(char *name, int *n); +int rate_sort(void); +struct reaction *rxn_alloc(int ntokens); +struct reaction *rxn_dup(struct reaction *rxn_ptr_old); +LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); +int rxn_free(struct reaction *rxn_ptr); +int rxn_print(struct reaction *rxn_ptr); +CLASS_STATIC int s_compare(const void *ptr1, const void *ptr2); +int s_delete(int i); +struct species *s_search(const char *name); +struct species *s_store(char *name, LDBLE z, int replace_if_found); +struct s_s_assemblage *s_s_assemblage_alloc(void); +struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); +CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); + +int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, + struct s_s_assemblage *s_s_assemblage_new_ptr, + int n_user_new); +int s_s_assemblage_copy_to_last(int n, int n_user); +int s_s_assemblage_duplicate(int n_user_old, int n_user_new); +int s_s_assemblage_delete(int n_user_old); +int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); +int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, + int n_user, int n_user_end, char *description); +int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage + *s_s_assemblage_old_ptr, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); +int s_s_assemblage_sort(void); +CLASS_STATIC int s_s_compare(const void *ptr1, const void *ptr2); +struct save_values *save_values_bsearch(struct save_values *k, int *n); +CLASS_STATIC int save_values_compare(const void *ptr1, const void *ptr2); +int save_values_sort(void); +int save_values_store(struct save_values *s_v); +CLASS_STATIC int conc_compare(const void *ptr1, const void *ptr2); +int conc_init(struct conc *conc_ptr); +CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); +struct solution *solution_alloc(void); +struct solution *solution_bsearch(int k, int *n, int print); +struct solution *solution_copy(struct solution *solution_old_ptr, + int n_user_new); +int solution_copy_to_last(int n, int n_user_new); +int solution_duplicate(int n_user_old, int n_user_new); +int solution_delete(int n_user_old); +int solution_delete_n(int n); +int solution_free(struct solution *solution_ptr); +int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); +struct solution *solution_replicate(struct solution *solution_old_ptr, + int n_user_new); +int solution_sort(void); +CLASS_STATIC int species_list_compare_alk(const void *ptr1, const void *ptr2); +CLASS_STATIC int species_list_compare_master(const void *ptr1, const void *ptr2); +int species_list_sort(void); +struct Change_Surf *change_surf_alloc(int count); +struct surface *surface_alloc(void); +struct surface *surface_bsearch(int k, int *n); +struct master *surface_get_psi_master(const char *name, int plane); +CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); +CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); +struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); +int surface_charge_free(struct surface_charge *charge); +CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); +int surface_copy(struct surface *surface_old_ptr, + struct surface *surface_new_ptr, int n_user_new); +int surface_copy_to_last(int n, int n_user); +int surface_delete(int n_user_old); +int surface_duplicate(int n_user_old, int n_user_new); +int surface_free(struct surface *surface_ptr); +int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, + char *description); +int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); +struct surface *surface_replicate(struct surface *surface_old_ptr, + int n_user_new); +struct surface *surface_search(int n_user, int *n, int print); +int surface_sort(void); +int system_duplicate(int i, int save_old); +struct temperature *temperature_bsearch(int k, int *n); +int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new); +int temperature_delete(int n_user_old); +int temperature_duplicate(int n_user_old, int n_user_new); +int temperature_free(struct temperature *temperature_ptr); +struct temperature *temperature_search(int n_user, int *n); +int temperature_sort(void); +int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_combine(void); +int trxn_copy(struct reaction *rxn_ptr); +LDBLE trxn_find_coef(const char *str, int start); +int trxn_print(void); +int trxn_reverse_k(void); +int trxn_sort(void); +int trxn_swap(const char *token); +struct unknown *unknown_alloc(void); +int unknown_delete(int i); +int unknown_free(struct unknown *unknown_ptr); +int entity_exists(char *name, int n_user); + +static int exchange_compare_int(const void *ptr1, const void *ptr2); +static int gas_phase_compare_int(const void *ptr1, const void *ptr2); +static int inverse_compare(const void *ptr1, const void *ptr2); +int inverse_free(struct inverse *inverse_ptr); +static int irrev_compare(const void *ptr1, const void *ptr2); +static int irrev_compare_int(const void *ptr1, const void *ptr2); +static int kinetics_compare_int(const void *ptr1, const void *ptr2); +int logk_init(struct logk *logk_ptr); +static int master_compare_string(const void *ptr1, const void *ptr2); +int master_free(struct master *master_ptr); +static int mix_compare(const void *ptr1, const void *ptr2); +static int mix_compare_int(const void *ptr1, const void *ptr2); +struct phase *phase_alloc(void); +static int phase_compare_string(const void *ptr1, const void *ptr2); +int phase_free(struct phase *phase_ptr); +int phase_init(struct phase *phase_ptr); +static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int rate_compare(const void *ptr1, const void *ptr2); +static int rate_compare_string(const void *ptr1, const void *ptr2); +struct species *s_alloc(void); +int s_free(struct species *s_ptr); +int s_init(struct species *s_ptr); +static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int solution_compare(const void *ptr1, const void *ptr2); +static int solution_compare_int(const void *ptr1, const void *ptr2); +static int species_list_compare(const void *ptr1, const void *ptr2); +static int surface_compare_int(const void *ptr1, const void *ptr2); +static int temperature_compare(const void *ptr1, const void *ptr2); +static int temperature_compare_int(const void *ptr1, const void *ptr2); +static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); +int trxn_multiply(LDBLE coef); +#ifdef PHREEQCI_GUI +extern void free_spread(void); +#endif +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern void MergeFinalize(void); +#endif + +/* tally.c */ + +void add_all_components_tally(void); +int build_tally_table(void); +int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); +int diff_tally_table(void); +int extend_tally_table(void); +int free_tally_table(void); +int fill_tally_table(int *n_user, int index_conservative, int n_buffer); +int get_tally_table_rows_columns(int *rows, int *columns); +int get_tally_table_column_heading(int column, int *type, char *string); +int get_tally_table_row_heading(int column, char *string); +int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); +int zero_tally_table(void); + +int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); +int get_all_components(void); +int print_tally_table(void); +int set_reaction_moles(int n_user, LDBLE moles); +int set_reaction_temperature(int n_user, LDBLE tc); +int set_kinetics_time(int n_user, LDBLE step); + +// tidy.c ------------------------------- + +int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); +int add_logks(struct logk *logk_ptr, int repeats); +LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); +int replace_solids_gases(void); +int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); +int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); +int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +int tidy_punch(void); +int tidy_model(void); + +int check_species_input(void); +LDBLE coef_in_master(struct master *master_ptr); +int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); +int reset_last_model(void); +int rewrite_eqn_to_primary(void); +int rewrite_eqn_to_secondary(void); +int species_rxn_to_trxn(struct species *s_ptr); +int tidy_logk(void); +int tidy_exchange(void); +int tidy_min_exchange(void); +int tidy_kin_exchange(void); +int tidy_gas_phase(void); +int tidy_inverse(void); +int tidy_isotopes(void); +int tidy_isotope_ratios(void); +int tidy_isotope_alphas(void); +int tidy_kin_surface(void); +int tidy_master_isotope(void); +int tidy_min_surface(void); +int tidy_phases(void); +int tidy_pp_assemblage(void); +int tidy_solutions(void); +int tidy_s_s_assemblage(void); +int tidy_species(void); +int tidy_surface(void); +int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); +static LDBLE f_spinodal(LDBLE x, void *); +int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); +int s_s_calc_a0_a1(struct s_s *s_s_ptr); + +// transport.c ------------------------------- + +int transport(void); +int set_initial_moles(int i); +int sum_surface_comp(struct surface *source1, LDBLE f1, + struct surface *source2, int k, LDBLE f2, + struct surface *target, LDBLE new_Dw); +int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, + LDBLE new_Dw, int cell); + +int multi_D(LDBLE DDt, int mobile_cell, int stagnant); +int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); +int fill_spec(int cell_no); +int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); +static int sort_species_name(const void *ptr1, const void *ptr2); +int disp_surf(LDBLE stagkin_time); +int diff_stag_surf(int mobile_cell); +int check_surfaces(struct surface *surface_ptr1, + struct surface *surface_ptr2); +int mobile_surface_copy(struct surface *surface_old_ptr, + struct surface *surf_ptr1, int n_user_new, + int move_old); +int init_mix(void); +int init_heat_mix(int nmix); +int heat_mix(int heat_nmix); +int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + +// utilities.c ------------------------------- + +int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); +int backspace_screen(int spaces); +LDBLE calc_alk(struct reaction *rxn_ptr); +int compute_gfw(const char *string, LDBLE * gfw); +int copy_token(char *token_ptr, char **ptr, int *length); +int dup_print(const char *ptr, int emphasis); +int equal(LDBLE a, LDBLE b, LDBLE eps); +void *free_check_null(void *ptr); +void free_hash_strings(HashTable * Table); +int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); +int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); +void hdestroy_multi(HashTable * HashTable_ptr); +ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); +int islegit(const char c); +void malloc_error(void); +int parse_couple(char *token); +int print_centered(const char *string); +int replace(const char *str1, const char *str2, char *str); +void space(void **ptr, int i, int *max, int struct_size); +void squeeze_white(char *s_l); +int status(int count, const char *str); +void str_tolower(char *str); +void str_toupper(char *str); +CLASS_STATIC int strcmp_nocase(const char *str1, const char *str2); +int strcmp_nocase_arg1(const char *str1, const char *str2); +char *string_duplicate(const char *token); +char *string_hsave(const char *str); +char *string_pad(char *str, int i); +int string_trim(char *str); +int string_trim_right(char *str); +int string_trim_left(char *str); +CLASS_STATIC LDBLE under(LDBLE xval); +void zero_double(LDBLE * target, int n); + +#ifdef PHREEQ98 +void AddToCEntry(char *a, int l, int i); +void ApplicationProcessMessages(void); +int copy_title(char *token_ptr, char **ptr, int *length); +extern int clean_up_null(void); +#endif +int isamong(char c, const char *s_l); +Address Hash_multi(HashTable * Table, char *Key); +void ExpandTable_multi(HashTable * Table); + +#if defined(SWIG_SHARED_OBJ) +int EndRow(void); +void AddSelectedOutput(const char *name, const char *format, + va_list argptr); +#endif + + + +public: // public methods for PHREEQC_CLASS + int main_method(int argc, char *argv[]); + void set_phast(int); + +}; +#endif /* _INC_PHREEQC_H */ + diff --git a/System.cxx b/System.cxx index 380c64ba..b22ef153 100644 --- a/System.cxx +++ b/System.cxx @@ -1,770 +1,445 @@ #include "System.h" #include // std::replace extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); - cxxSystem::cxxSystem(void) { - -this->solution = NULL; - -this->exchange = NULL; - -this->ppassemblage = NULL; - -this->gasphase = NULL; - -this->ssassemblage = NULL; - -this->kinetics = NULL; - -this->surface = NULL; - -this->mix = NULL; - -this->reaction = NULL; - -this->temperature = NULL; - + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; } - cxxSystem::~cxxSystem(void) { - } - void cxxSystem::Initialize(void) { - -this->solution = NULL; - -this->exchange = NULL; - -this->ppassemblage = NULL; - -this->gasphase = NULL; - -this->ssassemblage = NULL; - -this->kinetics = NULL; - -this->surface = NULL; - -this->mix = NULL; - -this->reaction = NULL; - -this->temperature = NULL; - + this->solution = NULL; + this->exchange = NULL; + this->ppassemblage = NULL; + this->gasphase = NULL; + this->ssassemblage = NULL; + this->kinetics = NULL; + this->surface = NULL; + this->mix = NULL; + this->reaction = NULL; + this->temperature = NULL; } void cxxSystem::totalize(void) { - - //initialize - this->totals.clear(); - - //add solution - if (this->solution != NULL) - + //initialize + this->totals.clear(); + //add solution + if (this->solution != NULL) { - -char token[MAX_LENGTH]; - -strcpy(token, "O"); - -this->totals[token] = this->solution->get_total_o(); - -strcpy(token, "H"); - -this->totals[token] = this->solution->get_total_h(); - -strcpy(token, "Charge"); - -this->totals[token] = this->solution->get_cb(); - -this->totals.add_extensive(this->solution->get_totals(), 1.0); - -} - -if (this->exchange != NULL) - + char token[MAX_LENGTH]; + strcpy(token, "O"); + this->totals[token] = this->solution->get_total_o(); + strcpy(token, "H"); + this->totals[token] = this->solution->get_total_h(); + strcpy(token, "Charge"); + this->totals[token] = this->solution->get_cb(); + this->totals.add_extensive(this->solution->get_totals(), 1.0); + } + if (this->exchange != NULL) { - -this->exchange->totalize(); - -this->totals.add_extensive(this->exchange->get_totals(), 1.0); - -} - -if (this->ppassemblage != NULL) - + this->exchange->totalize(); + this->totals.add_extensive(this->exchange->get_totals(), 1.0); + } + if (this->ppassemblage != NULL) { - -this->ppassemblage->totalize(); - -this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); - -} - -if (this->gasphase != NULL) - + this->ppassemblage->totalize(); + this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + } + if (this->gasphase != NULL) { - -this->gasphase->totalize(); - -this->totals.add_extensive(this->gasphase->get_totals(), 1.0); - -} - -if (this->ssassemblage != NULL) - + this->gasphase->totalize(); + this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + } + if (this->ssassemblage != NULL) { - -this->ssassemblage->totalize(); - -this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); - -} - -if (this->surface != NULL) - + this->ssassemblage->totalize(); + this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + } + if (this->surface != NULL) { - -this->ssassemblage->totalize(); - -this->totals.add_extensive(this->surface->get_totals(), 1.0); - + this->ssassemblage->totalize(); + this->totals.add_extensive(this->surface->get_totals(), 1.0); + } + //Need to handle the following 3 reactions: + // + //this->kinetics = NULL; + //this->mix = NULL; + //this->reaction = NULL; + //this->temperature = NULL; + //this->totals.dump_raw(std::cerr, 1); + return; } - - - //Need to handle the following 3 reactions: - // - //this->kinetics = NULL; - //this->mix = NULL; - //this->reaction = NULL; - //this->temperature = NULL; - //this->totals.dump_raw(std::cerr, 1); - return; - -} - - #ifdef ORCHESTRA - void +void cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, std::ostream & output_dat) { - - // - // chemistry file - // - this->totalize(); - - // calculate orchestra components from PHREEQC totals - this->ORCH_components(); - - // write definitions for chemistry - chemistry_dat << std:: + // + // chemistry file + // + this->totalize(); + // calculate orchestra components from PHREEQC totals + this->ORCH_components(); + // write definitions for chemistry + chemistry_dat << std:: endl << "@class: species_reactions () {" << std::endl; - -this->ORCH_write_chemistry_water(chemistry_dat); - -this->ORCH_write_chemistry_primary(chemistry_dat); - -this->ORCH_write_chemistry_total_O_H(chemistry_dat); - -ORCH_write_chemistry_species(chemistry_dat); - - - // add definitions for pure phases - if (this->ppassemblage != NULL) + this->ORCH_write_chemistry_water(chemistry_dat); + this->ORCH_write_chemistry_primary(chemistry_dat); + this->ORCH_write_chemistry_total_O_H(chemistry_dat); + ORCH_write_chemistry_species(chemistry_dat); + // add definitions for pure phases + if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - - - // add definitions for other PHREEQC entities here - - // finish up - chemistry_dat << std::endl << "}" << std::endl; - - // - // input file - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - -this->ORCH_write_input(input_dat); - -input_dat << std::endl << "}" << std::endl; - - // - // output file - // - output_dat << std::endl << "Output_every: 1" << std::endl; - -output_dat << "Var:"; - -this->ORCH_write_output_vars(output_dat); - - // add definitions for pure phases - if (this->ppassemblage != NULL) + // add definitions for other PHREEQC entities here + // finish up + chemistry_dat << std::endl << "}" << std::endl; + // + // input file + // + input_dat << std::endl << "@class: input_file_data () {" << std::endl; + this->ORCH_write_input(input_dat); + input_dat << std::endl << "}" << std::endl; + // + // output file + // + output_dat << std::endl << "Output_every: 1" << std::endl; + output_dat << "Var:"; + this->ORCH_write_output_vars(output_dat); + // add definitions for pure phases + if (this->ppassemblage != NULL) this->ppassemblage->ORCH_write_output_vars(output_dat); - - - //finish up - output_dat << std::endl; - + //finish up + output_dat << std::endl; }; - - void cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) { - - // - // Write water entities - // - chemistry_dat << std:: + // + // Write water entities + // + chemistry_dat << std:: endl << "//********* The water entities" << std::endl; - - - // e-, total hydrogen - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - -chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - -chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: + // e-, total hydrogen + chemistry_dat << "@entity(e-, diss, 0)" << std::endl; + chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; + chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: endl; - - - // H+, charge balance - chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - -chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: + // H+, charge balance + chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; + chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: endl; - - - // H2O - chemistry_dat << "@entity(" << s_h2o-> + // H2O + chemistry_dat << "@entity(" << s_h2o-> name << ", diss, 55.506)" << std::endl; - -chemistry_dat << std::endl; - + chemistry_dat << std::endl; } - void - cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) { - -chemistry_dat << std::endl << "//********* The primary species" << std:: + chemistry_dat << std::endl << "//********* The primary species" << std:: endl; - - // - // Write other master species definitions, i.e. primary entities - // - chemistry_dat << "@species(H+, 1)" << std::endl; - -for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - + // + // Write other master species definitions, i.e. primary entities + // + chemistry_dat << "@species(H+, 1)" << std::endl; + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) { - -std::string name(iter->first); - -if (name == "H(1)" || name == "E" || name == "H" || name == "O" - || name == "Charge") + std::string name(iter->first); + if (name == "H(1)" || name == "E" || name == "H" || name == "O" + || name == "Charge") continue; - -struct element *elt; - -char *element_name = string_hsave(name.c_str()); - -elt = element_store(element_name); - -assert(elt != NULL); - -struct species *s_ptr; - -s_ptr = elt->master->s; - -assert(s_ptr != NULL); - -chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> + struct element *elt; + char *element_name = string_hsave(name.c_str()); + elt = element_store(element_name); + assert(elt != NULL); + struct species *s_ptr; + s_ptr = elt->master->s; + assert(s_ptr != NULL); + chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> z << ")" << std::endl; - - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr-> + // regular mole balance + chemistry_dat << "@primary_entity(" << s_ptr-> name << ", 1e-9, liter, 1.0e-9)" << std::endl; - + } + chemistry_dat << std::endl; } -chemistry_dat << std::endl; - -} - void - cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) { - -chemistry_dat << std:: + chemistry_dat << std:: endl << "//********* Define total hydrogen and oxygen" << std::endl; - - - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - -chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - -int i; - -for (i = 0; i < count_s_x; i++) - + // Write H total equation + chemistry_dat << "@var: total_hydrogen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; + int i; + for (i = 0; i < count_s_x; i++) { - + // write in terms of orchestra components + if (s_x[i]->primary != NULL + || (s_x[i]->secondary != NULL + && s_x[i]->secondary->in == TRUE)) + { + if (s_x[i]->h != 0) + { + chemistry_dat << "+"; + if (s_x[i]->h != 1) + { + chemistry_dat << s_x[i]->h << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + // Write O total equation + chemistry_dat << "@var: total_oxygen 0" << std::endl; + chemistry_dat << "@calc: (5, \"total_oxygen = 0"; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->o != 0) + { // write in terms of orchestra components if (s_x[i]->primary != NULL || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - -if (s_x[i]->h != 0) - + && s_x[i]->secondary->in == TRUE)) { - -chemistry_dat << "+"; - -if (s_x[i]->h != 1) - + chemistry_dat << "+"; + if (s_x[i]->o != 1) { - -chemistry_dat << s_x[i]->h << "*"; - + chemistry_dat << s_x[i]->o << "*"; + } + chemistry_dat << "{" << s_x[i]->name << ".liter}"; + } + } + } + chemistry_dat << "\")" << std::endl; + chemistry_dat << std::endl; } - -chemistry_dat << "{" << s_x[i]->name << ".liter}"; - -} - -} - -} - -chemistry_dat << "\")" << std::endl; - - - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - -chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - -for (i = 0; i < count_s_x; i++) - - { - -if (s_x[i]->o != 0) - - { - - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - - { - -chemistry_dat << "+"; - -if (s_x[i]->o != 1) - - { - -chemistry_dat << s_x[i]->o << "*"; - -} - -chemistry_dat << "{" << s_x[i]->name << ".liter}"; - -} - -} - -} - -chemistry_dat << "\")" << std::endl; - -chemistry_dat << std::endl; - -} - void cxxSystem::ORCH_write_input(std::ostream & input_dat) { - - - -// -// Write orchestra input file info -// - std::ostringstream headings, data; - -data.precision(DBL_DIG - 1); - -headings << "var: "; - -data << "data: "; - - -headings << "tempc\t"; - -data << this->solution->get_tc() << "\t"; - - -headings << "pH\t"; - -data << this->solution->get_ph() << "\t"; - - -headings << "pe\t"; - -data << this->solution->get_pe() << "\t"; - - -headings << "H2O.act\t"; - -data << 1 << "\t"; - - -headings << "I\t"; - -data << this->solution->get_mu() << "\t"; - - -for (cxxNameDouble::iterator iter = this->orch_totals.begin(); - iter != this->orch_totals.end(); ++iter) - + // + // Write orchestra input file info + // + std::ostringstream headings, data; + data.precision(DBL_DIG - 1); + headings << "var: "; + data << "data: "; + headings << "tempc\t"; + data << this->solution->get_tc() << "\t"; + headings << "pH\t"; + data << this->solution->get_ph() << "\t"; + headings << "pe\t"; + data << this->solution->get_pe() << "\t"; + headings << "H2O.act\t"; + data << 1 << "\t"; + headings << "I\t"; + data << this->solution->get_mu() << "\t"; + for (cxxNameDouble::iterator iter = this->orch_totals.begin(); + iter != this->orch_totals.end(); ++iter) { - -headings << iter->first << ".liter" << "\t"; - -data << iter->second << "\t"; - -} - - - // activity estimate - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - + headings << iter->first << ".liter" << "\t"; + data << iter->second << "\t"; + } + // activity estimate + for (cxxNameDouble::iterator iter = this->totals.begin(); + iter != this->totals.end(); ++iter) { - -if (iter->first == "O" || iter->first == "Charge") + if (iter->first == "O" || iter->first == "Charge") continue; - -std::string master_name; - -struct master *master_ptr; - -master_ptr = master_bsearch(iter->first); - -assert(master_ptr != NULL); - - -cxxNameDouble ma = this->solution->get_master_activity(); - -cxxNameDouble::iterator it = ma.find(iter->first); - -if (it == ma.end()) - + std::string master_name; + struct master *master_ptr; + master_ptr = master_bsearch(iter->first); + assert(master_ptr != NULL); + cxxNameDouble ma = this->solution->get_master_activity(); + cxxNameDouble::iterator it = ma.find(iter->first); + if (it == ma.end()) { - -it = ma.find(master_ptr->s->secondary->elt->name); - -} - -headings << master_ptr->s->name << ".act\t"; - -if (it != ma.end()) - + it = ma.find(master_ptr->s->secondary->elt->name); + } + headings << master_ptr->s->name << ".act\t"; + if (it != ma.end()) { - -data << pow(10., it->second) << "\t"; - -} + data << pow(10., it->second) << "\t"; + } else - { - -data << 1e-9 << "\t"; - + data << 1e-9 << "\t"; + } + } + // Isotopes + //s_oss << "-Isotopes" << std::endl; + /* + { + for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { + it->dump_raw(s_oss, indent + 2); + } + } + */ + // Write data to string + input_dat << headings.str() << std::endl; + input_dat << data.str() << std::endl; + return; } - -} - - - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - // Write data to string - input_dat << headings.str() << std::endl; - -input_dat << data.str() << std::endl; - - -return; - -} - - void cxxSystem::ORCH_components(void) { - - // translate from H, O, charge to H+tot, e-tot, and H2Otot - cxxNameDouble::iterator it; - -cxxNameDouble temp_totals; - - // - // Set names in orch_totals to master species names - // - this->orch_totals.clear(); - -temp_totals = this->totals; - -temp_totals.erase("H"); - -temp_totals.erase("O"); - -temp_totals.erase("Charge"); - - //temp_totals.dump_raw(std::cerr, 1); - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + // translate from H, O, charge to H+tot, e-tot, and H2Otot + cxxNameDouble::iterator it; + cxxNameDouble temp_totals; + // + // Set names in orch_totals to master species names + // + this->orch_totals.clear(); + temp_totals = this->totals; + temp_totals.erase("H"); + temp_totals.erase("O"); + temp_totals.erase("Charge"); + //temp_totals.dump_raw(std::cerr, 1); + for (it = temp_totals.begin(); it != temp_totals.end(); it++) { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -assert(elt_ptr != NULL); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -assert(master_ptr != NULL); - -double coef = master_ptr->coef; - -if (master_ptr->coef == 0) - + struct element *elt_ptr; + elt_ptr = element_store(it->first); + assert(elt_ptr != NULL); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + assert(master_ptr != NULL); + double coef = master_ptr->coef; + if (master_ptr->coef == 0) { - -coef = 1; - -} - -this->orch_totals[master_ptr->s->name] = it->second / coef; - -} - - // - // Calculate h2otot - // - it = this->totals.find("O"); - -assert(it != this->totals.end()); - -double h2otot = it->second; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + coef = 1; + } + this->orch_totals[master_ptr->s->name] = it->second / coef; + } + // + // Calculate h2otot + // + it = this->totals.find("O"); + assert(it != this->totals.end()); + double h2otot = it->second; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -h2otot -= it->second * master_ptr->s->o; - -} - // - // Calculate htot - // - it = this->totals.find("H"); - -assert(it != this->totals.end()); - -double htot = it->second - 2 * h2otot; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + h2otot -= it->second * master_ptr->s->o; + } + // + // Calculate htot + // + it = this->totals.find("H"); + assert(it != this->totals.end()); + double htot = it->second - 2 * h2otot; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -htot -= it->second * master_ptr->s->h; - -} - // - // Calculate etot - // - it = this->totals.find("Charge"); - -assert(it != this->totals.end()); - -double etot = -it->second + htot; - - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + htot -= it->second * master_ptr->s->h; + } + // + // Calculate etot + // + it = this->totals.find("Charge"); + assert(it != this->totals.end()); + double etot = -it->second + htot; + // subtract O in master species + for (it = temp_totals.begin(); it != temp_totals.end(); it++) { - -struct element *elt_ptr; - -elt_ptr = element_store(it->first); - -struct master *master_ptr; - -master_ptr = elt_ptr->primary; - -etot += it->second * master_ptr->s->z; - -} - // - // store h2otot, htot, etot in orch_totals - // - this->orch_totals["H2O"] = h2otot; - -this->orch_totals["H+"] = htot; - -this->orch_totals["e-"] = etot; - -this->orch_totals.dump_raw(std::cerr, 1); - + struct element *elt_ptr; + elt_ptr = element_store(it->first); + struct master *master_ptr; + master_ptr = elt_ptr->primary; + etot += it->second * master_ptr->s->z; + } + // + // store h2otot, htot, etot in orch_totals + // + this->orch_totals["H2O"] = h2otot; + this->orch_totals["H+"] = htot; + this->orch_totals["e-"] = etot; + this->orch_totals.dump_raw(std::cerr, 1); } void - cxxSystem::ORCH_write_output_vars(std::ostream & outstream) { - -outstream << "\tnr_iter"; - - // - // Serialize solution - // - outstream << "\tstart_solution"; - - //tc - outstream << "\ttempc"; - - //pH - outstream << "\tpH"; - - //pe - outstream << "\tpe"; - - //mu - outstream << "\tI"; - - //ah2o - outstream << "\tH2O.act"; - - //total_h; - outstream << "\ttotal_hydrogen"; - - //total_o; - outstream << "\ttotal_oxygen"; - - //cb - outstream << "\tchargebalance"; - - //mass_water; - outstream << "\tH2O.con"; - - //total_alkalinity; - outstream << "\tAlkalinity"; - - //orchestra master variables - outstream << "\tH+.diss"; - -outstream << "\te-.diss"; - -outstream << "\tH2O.diss"; - - // - // Write totals - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - + outstream << "\tnr_iter"; + // + // Serialize solution + // + outstream << "\tstart_solution"; + //tc + outstream << "\ttempc"; + //pH + outstream << "\tpH"; + //pe + outstream << "\tpe"; + //mu + outstream << "\tI"; + //ah2o + outstream << "\tH2O.act"; + //total_h; + outstream << "\ttotal_hydrogen"; + //total_o; + outstream << "\ttotal_oxygen"; + //cb + outstream << "\tchargebalance"; + //mass_water; + outstream << "\tH2O.con"; + //total_alkalinity; + outstream << "\tAlkalinity"; + //orchestra master variables + outstream << "\tH+.diss"; + outstream << "\te-.diss"; + outstream << "\tH2O.diss"; + // + // Write totals + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) { - -if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - -outstream << "\t" << it->first << ".diss"; - -} - -outstream << "\tend_totals"; - -for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - + outstream << "\t" << it->first << ".diss"; + } + outstream << "\tend_totals"; + for (cxxNameDouble::iterator it = this->orch_totals.begin(); + it != this->orch_totals.end(); it++) { - -if (it->first == "H+" || it->first == "H2O" || it->first == "e-") + if (it->first == "H+" || it->first == "H2O" || it->first == "e-") continue; - -outstream << "\t" << it->first << ".act"; - -} - -outstream << "\tend_master_activities"; - - // - // Write all species activities and concentrations - // + outstream << "\t" << it->first << ".act"; + } + outstream << "\tend_master_activities"; + // + // Write all species activities and concentrations + // int i; - -for (i = 0; i < count_s_x; i++) + for (i = 0; i < count_s_x; i++) { - -std::string name(s_x[i]->name); - -std::replace(name.begin(), name.end(), '(', '['); - -std::replace(name.begin(), name.end(), ')', ']'); - -outstream << "\t" << name.c_str() << ".act" << "\t" << name. + std::string name(s_x[i]->name); + std::replace(name.begin(), name.end(), '(', '['); + std::replace(name.begin(), name.end(), ')', ']'); + outstream << "\t" << name.c_str() << ".act" << "\t" << name. c_str() << ".con"; - + } + outstream << "\tend_species"; } - -outstream << "\tend_species"; - -} - - -#endif /* - */ +#endif /* */ diff --git a/class_main.cpp b/class_main.cpp new file mode 100644 index 00000000..0cbca6ed --- /dev/null +++ b/class_main.cpp @@ -0,0 +1,191 @@ +#include "Phreeqc.h" +#include "output.h" +#include "phrqproto.h" +#include "input.h" + + + +/* ---------------------------------------------------------------------- + * MAIN + * ---------------------------------------------------------------------- */ +int +main(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + + //int errors; +#if defined(WIN32_MEMORY_DEBUG) + int tmpDbgFlag; + + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); + //_crtBreakAlloc = 9482; +#endif + + /*if (svnid == NULL) + fprintf(stderr, " ");*/ + + + Phreeqc phreeqc_instance; + phreeqc_instance.main_method(argc, argv); + +} + + +int CLASS_QUALIFIER +main_method(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + + int errors; + void *db_cookie = NULL; + void *input_cookie = NULL; +#if defined(WIN32_MEMORY_DEBUG) + int tmpDbgFlag; + + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); + //_crtBreakAlloc = 9482; +#endif + + //if (svnid == NULL) + // fprintf(stderr, " "); + phast = FALSE; +/* + * Add callbacks for error_msg and warning_msg + */ + if (add_output_callback(phreeqc_handler, this) != OK) + { + fprintf(stderr, "ERROR: %s\n", + "NULL pointer returned from malloc or realloc."); + fprintf(stderr, "ERROR: %s\n", "Program terminating."); + return -1; + } + +/* + * Open input/output files + */ + errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); + if (errors != 0) + { + //clean_up(); + return errors; + } +#ifdef DOS + write_banner(); +#endif + +/* + * Initialize arrays + */ + errors = do_initialize(); + if (errors != 0) + { + //clean_up(); + return errors; + } +/* + * Load database into memory + */ + errors = read_database(getc_callback, db_cookie); + if (errors != 0) + { + //clean_up(); + return errors; + } + +/* + * Read input data for simulation + */ + errors = run_simulations(getc_callback, input_cookie); + if (errors != 0) + { + //clean_up(); + return errors; + } + + +/* + * Display successful status + */ + errors = do_status(); + if (errors != 0) + { + //clean_up(); + return errors; + } + + + //clean_up(); + //close_input_files(); + //close_output_files(); + + return 0; +} + + +#ifdef DOS +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER +write_banner(void) +/* ---------------------------------------------------------------------- */ +{ + char buffer[80]; + int len, indent; + output_msg(OUTPUT_SCREEN, + " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + + /* version */ + len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, + " º º\n"); + output_msg(OUTPUT_SCREEN, + " º A hydrogeochemical transport model º\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + output_msg(OUTPUT_SCREEN, + " º by º\n"); + output_msg(OUTPUT_SCREEN, + " º D.L. Parkhurst and C.A.J. Appelo º\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + + + /* date */ + len = sprintf(buffer, "%s", "@VER_DATE@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, + " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); + + return 0; +} +#endif From 0a91aa5bec53c2f755c378bd9715421fa8062793 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 4 Dec 2009 22:47:55 +0000 Subject: [PATCH 0117/1077] phreeqcpp (nonclass) compiles. SSassemblage.cxx compiles, but need to work on header files. Need to fix header files throughout. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3865 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 103 ++++++++++++++++++++++++----------------------- SSassemblage.cxx | 13 ++++-- SSassemblage.h | 6 ++- SSassemblageSS.h | 2 - StorageBin.h | 7 +++- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 0b74e8a5..6fa0e30a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -31,6 +31,7 @@ #define extern #include "p2c.h" #undef extern +#include "global_structures.h" class Phreeqc { @@ -39,57 +40,57 @@ public: ~Phreeqc(void); -private: - -struct _generic_N_Vector; -struct calculate_value; -struct conc; -struct CVodeMemRec; -struct element; -struct exchange; -struct exch_comp; -struct elt_list; -struct gas_phase; -struct gas_comp; -struct inverse; -struct inv_elts; -struct inv_phases; -struct inv_isotope; -struct irrev; -struct isotope; -struct kinetics; -struct kinetics_comp; -struct LOC_exec; -struct master; -struct master_activity; -struct master_isotope; -struct mix; -struct mix_comp; -struct name_coef; -struct pe_data; -struct phase; -struct PHRQMemHeader; -struct pitz_param; -struct pp_assemblage; -struct pure_phase; -struct reaction; -struct reaction_temp; -struct rxn_token; -struct rxn_token_temp; -struct solution; -struct species; -struct s_s; -struct s_s_assemblage; -struct s_s_comp; -struct species_diff_layer; -struct surface; -struct surface_comp; -struct surface_charge; -struct surface_diff_layer; -struct theta_param; -struct tokenrec; -struct varrec; -struct unknown; +//private: +// +//struct _generic_N_Vector; +//struct calculate_value; +//struct conc; +//struct CVodeMemRec; +//struct element; +//struct exchange; +//struct exch_comp; +//struct elt_list; +//struct gas_phase; +//struct gas_comp; +//struct inverse; +//struct inv_elts; +//struct inv_phases; +//struct inv_isotope; +//struct irrev; +//struct isotope; +//struct kinetics; +//struct kinetics_comp; +//struct LOC_exec; +//struct master; +//struct master_activity; +//struct master_isotope; +//struct mix; +//struct mix_comp; +//struct name_coef; +//struct pe_data; +//struct phase; +//struct PHRQMemHeader; +//struct pitz_param; +//struct pp_assemblage; +//struct pure_phase; +//struct reaction; +//struct reaction_temp; +//struct rxn_token; +//struct rxn_token_temp; +//struct solution; +//struct species; +//struct s_s; +//struct s_s_assemblage; +//struct s_s_comp; +//struct species_diff_layer; +//struct surface; +//struct surface_comp; +//struct surface_charge; +//struct surface_diff_layer; +//struct theta_param; +//struct tokenrec; +//struct varrec; +//struct unknown; #define PITZER_EXTERNAL #include "pitzer.h" diff --git a/SSassemblage.cxx b/SSassemblage.cxx index cd4c7acc..de9b9b87 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -4,16 +4,21 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include +#include // assert +#include // std::sort #include "Utils.h" // define first #include "SSassemblage.h" #include "SSassemblageSS.h" -#define EXTERNAL extern -#include "global.h" +#include "cxxMix.h" +#if defined(PHREEQC_CLASS) +#define CLASS_STATIC static +#endif +#include "global_structures.h" #include "phqalloc.h" #include "phrqproto.h" -#include // assert -#include // std::sort + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SSassemblage.h b/SSassemblage.h index 0db532b3..a90811b0 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -2,8 +2,6 @@ #define SSASSEMBLAGE_H_INCLUDED #include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string @@ -11,7 +9,11 @@ #include // std::vector #include "SSassemblageSS.h" +//#include "NameDouble.h" +//class cxxSSassemblageSS; + #include "cxxMix.h" +//class cxxMix; class cxxSSassemblage:public cxxNumKeyword { diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 81bba9ce..8c601e52 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -2,8 +2,6 @@ #define SSASSEMBLAGESS_H_INCLUDED #include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string diff --git a/StorageBin.h b/StorageBin.h index 5803a832..ad63e815 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -8,10 +8,13 @@ #include "GasPhase.h" #include "cxxKinetics.h" #include "PPassemblage.h" -#include "SSassemblage.h" +//#include "SSassemblage.h" +class NameDouble; +class cxxSSassemblageSS; #include "Surface.h" #include "System.h" -#include "cxxMix.h" +//#include "cxxMix.h" +class cxxMix; #include "Reaction.h" #include "Temperature.h" From e65ab2ea734f81df25623db601ba73a94ae818a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 4 Dec 2009 23:30:03 +0000 Subject: [PATCH 0118/1077] cleaned up storagebin headers. cleaned up ssassemblage.h headers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3867 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SSassemblage.h | 10 +- StorageBin.cxx | 269 ++++++++++++++++++++++++++++++++++++++++++++++- StorageBin.h | 278 +++++++++---------------------------------------- 3 files changed, 325 insertions(+), 232 deletions(-) diff --git a/SSassemblage.h b/SSassemblage.h index a90811b0..40cbb185 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -8,12 +8,12 @@ #include // std::list #include // std::vector -#include "SSassemblageSS.h" -//#include "NameDouble.h" -//class cxxSSassemblageSS; +//#include "SSassemblageSS.h" +#include "NameDouble.h" +class cxxSSassemblageSS; -#include "cxxMix.h" -//class cxxMix; +//#include "cxxMix.h" +class cxxMix; class cxxSSassemblage:public cxxNumKeyword { diff --git a/StorageBin.cxx b/StorageBin.cxx index 91580250..cb965b6d 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -12,8 +12,21 @@ #include #include // std::cout std::cerr #include "Utils.h" // define first +#include "NameDouble.h" #include "StorageBin.h" -#include "System.h" +#include "SSassemblage.h" +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblageSS.h" +#include "SSassemblage.h" +#include "Surface.h" +#include "cxxMix.h" +#include "Reaction.h" +#include "Temperature.h" + #define EXTERNAL extern #include "global.h" #include "phqalloc.h" @@ -100,7 +113,261 @@ cxxStorageBin::cxxStorageBin(struct Use *use_ptr) cxxStorageBin::~cxxStorageBin() { } +cxxSolution * +cxxStorageBin::getSolution(int n_user) +{ + if (this->Solutions.find(n_user) != this->Solutions.end()) + { + return (&(this->Solutions.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setSolution(int n_user, cxxSolution * entity) +{ + if (entity == NULL) + return; + Solutions[n_user] = *entity; +} +void +cxxStorageBin::removeSolution(int n_user) +{ + Solutions.erase(n_user); +} +cxxExchange * +cxxStorageBin::getExchange(int n_user) +{ + if (this->Exchangers.find(n_user) != this->Exchangers.end()) + { + return (&(this->Exchangers.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setExchange(int n_user, cxxExchange * entity) +{ + if (entity == NULL) + return; + Exchangers[n_user] = *entity; +} +void +cxxStorageBin::removeExchange(int n_user) +{ + Exchangers.erase(n_user); +} + +cxxPPassemblage * +cxxStorageBin::getPPassemblage(int n_user) +{ + if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) + { + return (&(this->PPassemblages.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setPPassemblage(int n_user, cxxPPassemblage * entity) +{ + if (entity == NULL) + return; + PPassemblages[n_user] = *entity; +} +void +cxxStorageBin::removePPassemblage(int n_user) +{ + PPassemblages.erase(n_user); +} + +cxxGasPhase * +cxxStorageBin::getGasPhase(int n_user) +{ + if (this->GasPhases.find(n_user) != this->GasPhases.end()) + { + return (&(this->GasPhases.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setGasPhase(int n_user, cxxGasPhase * entity) +{ + if (entity == NULL) + return; + GasPhases[n_user] = *entity; +} +void +cxxStorageBin::removeGasPhase(int n_user) +{ + GasPhases.erase(n_user); +} + +cxxSSassemblage * +cxxStorageBin::getSSassemblage(int n_user) +{ + if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) + { + return (&(this->SSassemblages.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setSSassemblage(int n_user, cxxSSassemblage * entity) +{ + if (entity == NULL) + return; + SSassemblages[n_user] = *entity; +} +void +cxxStorageBin::removeSSassemblage(int n_user) +{ + SSassemblages.erase(n_user); +} + +cxxKinetics * +cxxStorageBin::getKinetics(int n_user) +{ + if (this->Kinetics.find(n_user) != this->Kinetics.end()) + { + return (&(this->Kinetics.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setKinetics(int n_user, cxxKinetics * entity) +{ + if (entity == NULL) + return; + Kinetics[n_user] = *entity; +} +void +cxxStorageBin::removeKinetics(int n_user) +{ + Kinetics.erase(n_user); +} + +cxxSurface * +cxxStorageBin::getSurface(int n_user) +{ + if (this->Surfaces.find(n_user) != this->Surfaces.end()) + { + return (&(this->Surfaces.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setSurface(int n_user, cxxSurface * entity) +{ + if (entity == NULL) + return; + Surfaces[n_user] = *entity; +} +void +cxxStorageBin::removeSurface(int n_user) +{ + Surfaces.erase(n_user); +} + +cxxMix * +cxxStorageBin::getMix(int n_user) +{ + if (this->Mixes.find(n_user) != this->Mixes.end()) + { + return (&(this->Mixes.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setMix(int n_user, cxxMix * entity) +{ + if (entity == NULL) + return; + Mixes[n_user] = *entity; +} +void +cxxStorageBin::removeMix(int n_user) +{ + Mixes.erase(n_user); +} + +cxxReaction * +cxxStorageBin::getReaction(int n_user) +{ + if (this->Reactions.find(n_user) != this->Reactions.end()) + { + return (&(this->Reactions.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setReaction(int n_user, cxxReaction * entity) +{ + if (entity == NULL) + return; + Reactions[n_user] = *entity; +} +void +cxxStorageBin::removeReaction(int n_user) +{ + Reactions.erase(n_user); +} + +cxxTemperature * +cxxStorageBin::getTemperature(int n_user) +{ + if (this->Temperatures.find(n_user) != this->Temperatures.end()) + { + return (&(this->Temperatures.find(n_user)->second)); + } + return (NULL); +} +void +cxxStorageBin::setTemperature(int n_user, cxxTemperature * entity) +{ + if (entity == NULL) + return; + Temperatures[n_user] = *entity; +} +void +cxxStorageBin::removeTemperature(int n_user) +{ + Temperatures.erase(n_user); +} + +const std::map < int, cxxSolution > & +cxxStorageBin::getSolutions() const +{ + return this->Solutions; +}; +const std::map < int, cxxExchange > & +cxxStorageBin::getExchangers() const +{ + return this->Exchangers; +}; +const std::map < int, cxxGasPhase > & +cxxStorageBin::getGasPhases() const +{ + return this->GasPhases; +}; +const std::map < int, cxxKinetics > & +cxxStorageBin::getKinetics() const +{ + return this->Kinetics; +}; +const std::map < int, cxxPPassemblage > & +cxxStorageBin::getPPassemblages() const +{ + return this->PPassemblages; +}; +const std::map < int, cxxSSassemblage > & +cxxStorageBin::getSSassemblages() const +{ + return this->SSassemblages; +}; +const std::map < int, cxxSurface > & +cxxStorageBin::getSurfaces() const +{ + return this->Surfaces; +}; void cxxStorageBin::import_phreeqc(void) // diff --git a/StorageBin.h b/StorageBin.h index ad63e815..44ff84fd 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -1,29 +1,26 @@ #if !defined(STORAGEBIN_H_INCLUDED) #define STORAGEBIN_H_INCLUDED - -#include "Utils.h" -#include "Parser.h" -#include "Solution.h" -#include "Exchange.h" -#include "GasPhase.h" -#include "cxxKinetics.h" -#include "PPassemblage.h" -//#include "SSassemblage.h" -class NameDouble; -class cxxSSassemblageSS; -#include "Surface.h" -#include "System.h" -//#include "cxxMix.h" -class cxxMix; -#include "Reaction.h" -#include "Temperature.h" - #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +//#include "Utils.h" +//#include "Parser.h" + +class cxxSolution; +class cxxExchange; +class cxxGasPhase; +class cxxKinetics; +class cxxPPassemblage; +class cxxSSassemblage; +class cxxSurface; +#include "System.h" +class cxxReaction; +class cxxTemperature; + + class cxxStorageBin { @@ -40,195 +37,45 @@ class cxxStorageBin void remove(int n); - cxxSolution *getSolution(int n_user) - { - if (this->Solutions.find(n_user) != this->Solutions.end()) - { - return (&(this->Solutions.find(n_user)->second)); - } - return (NULL); - } - void setSolution(int n_user, cxxSolution * entity) - { - if (entity == NULL) - return; - Solutions[n_user] = *entity; - } - void removeSolution(int n_user) - { - Solutions.erase(n_user); - } + cxxSolution *getSolution(int n_user); + void setSolution(int n_user, cxxSolution * entity); + void removeSolution(int n_user); - cxxExchange *getExchange(int n_user) - { - if (this->Exchangers.find(n_user) != this->Exchangers.end()) - { - return (&(this->Exchangers.find(n_user)->second)); - } - return (NULL); - } - void setExchange(int n_user, cxxExchange * entity) - { - if (entity == NULL) - return; - Exchangers[n_user] = *entity; - } - void removeExchange(int n_user) - { - Exchangers.erase(n_user); - } + cxxExchange *getExchange(int n_user); + void setExchange(int n_user, cxxExchange * entity); + void removeExchange(int n_user); - cxxPPassemblage *getPPassemblage(int n_user) - { - if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) - { - return (&(this->PPassemblages.find(n_user)->second)); - } - return (NULL); - } - void setPPassemblage(int n_user, cxxPPassemblage * entity) - { - if (entity == NULL) - return; - PPassemblages[n_user] = *entity; - } - void removePPassemblage(int n_user) - { - PPassemblages.erase(n_user); - } + cxxPPassemblage *getPPassemblage(int n_user); + void setPPassemblage(int n_user, cxxPPassemblage * entity); + void removePPassemblage(int n_user); - cxxGasPhase *getGasPhase(int n_user) - { - if (this->GasPhases.find(n_user) != this->GasPhases.end()) - { - return (&(this->GasPhases.find(n_user)->second)); - } - return (NULL); - } - void setGasPhase(int n_user, cxxGasPhase * entity) - { - if (entity == NULL) - return; - GasPhases[n_user] = *entity; - } - void removeGasPhase(int n_user) - { - GasPhases.erase(n_user); - } + cxxGasPhase *getGasPhase(int n_user); + void setGasPhase(int n_user, cxxGasPhase * entity); + void removeGasPhase(int n_user); - cxxSSassemblage *getSSassemblage(int n_user) - { - if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) - { - return (&(this->SSassemblages.find(n_user)->second)); - } - return (NULL); - } - void setSSassemblage(int n_user, cxxSSassemblage * entity) - { - if (entity == NULL) - return; - SSassemblages[n_user] = *entity; - } - void removeSSassemblage(int n_user) - { - SSassemblages.erase(n_user); - } + cxxSSassemblage *getSSassemblage(int n_user); + void setSSassemblage(int n_user, cxxSSassemblage * entity); + void removeSSassemblage(int n_user); - cxxKinetics *getKinetics(int n_user) - { - if (this->Kinetics.find(n_user) != this->Kinetics.end()) - { - return (&(this->Kinetics.find(n_user)->second)); - } - return (NULL); - } - void setKinetics(int n_user, cxxKinetics * entity) - { - if (entity == NULL) - return; - Kinetics[n_user] = *entity; - } - void removeKinetics(int n_user) - { - Kinetics.erase(n_user); - } + cxxKinetics *getKinetics(int n_user); + void setKinetics(int n_user, cxxKinetics * entity); + void removeKinetics(int n_user); - cxxSurface *getSurface(int n_user) - { - if (this->Surfaces.find(n_user) != this->Surfaces.end()) - { - return (&(this->Surfaces.find(n_user)->second)); - } - return (NULL); - } - void setSurface(int n_user, cxxSurface * entity) - { - if (entity == NULL) - return; - Surfaces[n_user] = *entity; - } - void removeSurface(int n_user) - { - Surfaces.erase(n_user); - } + cxxSurface *getSurface(int n_user); + void setSurface(int n_user, cxxSurface * entity); + void removeSurface(int n_user); - cxxMix *getMix(int n_user) - { - if (this->Mixes.find(n_user) != this->Mixes.end()) - { - return (&(this->Mixes.find(n_user)->second)); - } - return (NULL); - } - void setMix(int n_user, cxxMix * entity) - { - if (entity == NULL) - return; - Mixes[n_user] = *entity; - } - void removeMix(int n_user) - { - Mixes.erase(n_user); - } + cxxMix *getMix(int n_user); + void setMix(int n_user, cxxMix * entity); + void removeMix(int n_user); - cxxReaction *getReaction(int n_user) - { - if (this->Reactions.find(n_user) != this->Reactions.end()) - { - return (&(this->Reactions.find(n_user)->second)); - } - return (NULL); - } - void setReaction(int n_user, cxxReaction * entity) - { - if (entity == NULL) - return; - Reactions[n_user] = *entity; - } - void removeReaction(int n_user) - { - Reactions.erase(n_user); - } + cxxReaction *getReaction(int n_user); + void setReaction(int n_user, cxxReaction * entity); + void removeReaction(int n_user); - cxxTemperature *getTemperature(int n_user) - { - if (this->Temperatures.find(n_user) != this->Temperatures.end()) - { - return (&(this->Temperatures.find(n_user)->second)); - } - return (NULL); - } - void setTemperature(int n_user, cxxTemperature * entity) - { - if (entity == NULL) - return; - Temperatures[n_user] = *entity; - } - void removeTemperature(int n_user) - { - Temperatures.erase(n_user); - } + cxxTemperature *getTemperature(int n_user); + void setTemperature(int n_user, cxxTemperature * entity); + void removeTemperature(int n_user); void setSystem(struct Use *use_ptr); @@ -246,34 +93,13 @@ class cxxStorageBin //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); - const std::map < int, cxxSolution > &getSolutions() const - { - return this->Solutions; - }; - const std::map < int, cxxExchange > &getExchangers() const - { - return this->Exchangers; - }; - const std::map < int, cxxGasPhase > &getGasPhases() const - { - return this->GasPhases; - }; - const std::map < int, cxxKinetics > &getKinetics() const - { - return this->Kinetics; - }; - const std::map < int, cxxPPassemblage > &getPPassemblages() const - { - return this->PPassemblages; - }; - const std::map < int, cxxSSassemblage > &getSSassemblages() const - { - return this->SSassemblages; - }; - const std::map < int, cxxSurface > &getSurfaces() const - { - return this->Surfaces; - }; + const std::map < int, cxxSolution > &getSolutions() const; + const std::map < int, cxxExchange > &getExchangers() const; + const std::map < int, cxxGasPhase > &getGasPhases() const; + const std::map < int, cxxKinetics > &getKinetics() const; + const std::map < int, cxxPPassemblage > &getPPassemblages() const; + const std::map < int, cxxSSassemblage > &getSSassemblages() const; + const std::map < int, cxxSurface > &getSurfaces() const; #ifdef USE_MPI void mpi_send(int n, int task_number); From 2b76f04a8bd97cc731c8e69ff6976fa8dc0e404a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Dec 2009 19:49:38 +0000 Subject: [PATCH 0119/1077] Cleaned up header files to remove unnecessary includes of .h files. Moved includes to source code where possible. Moved some methods for .h to source files to avoid need for includes. Debug and Release compile. Still need to get class version working. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3868 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 15 +++-- ExchComp.h | 5 +- Exchange.cxx | 39 +++++++++--- Exchange.h | 37 ++++------- GasPhase.cxx | 13 +++- GasPhase.h | 8 +-- ISolution.cxx | 14 +++-- ISolution.h | 10 +-- ISolutionComp.cxx | 11 ++-- ISolutionComp.h | 7 --- KineticsComp.cxx | 21 ++++--- KineticsComp.h | 5 +- NameDouble.cxx | 23 ++++--- NameDouble.h | 1 + NumKeyword.cxx | 1 + NumKeyword.h | 7 +-- PPassemblage.cxx | 20 +++--- PPassemblage.h | 6 +- PPassemblageComp.cxx | 22 ++++--- PPassemblageComp.h | 5 +- Reaction.cxx | 18 +++--- Reaction.h | 7 +-- ReadClass.cxx | 18 ++++-- SSassemblage.cxx | 11 ++-- SSassemblage.h | 4 +- SSassemblageSS.cxx | 22 ++++--- SSassemblageSS.h | 3 +- Solution.cxx | 13 +++- Solution.h | 12 ++-- SolutionIsotope.cxx | 18 +++--- SolutionIsotope.h | 2 +- SolutionIsotopeList.cxx | 16 +++-- SolutionIsotopeList.h | 10 +-- StorageBin.cxx | 19 +++--- StorageBin.h | 6 +- StorageBinList.cpp | 4 +- StorageBinList.h | 4 +- Surface.cxx | 20 +++--- Surface.h | 6 +- SurfaceCharge.cxx | 68 ++++++++++---------- SurfaceCharge.h | 9 ++- SurfaceComp.cxx | 136 +++++++++++++++++++++++++++++++--------- SurfaceComp.h | 134 +++++++++------------------------------ System.cxx | 23 ++++++- System.h | 32 +++++++--- Temperature.cxx | 20 +++--- Temperature.h | 5 +- cxxKinetics.cxx | 23 ++++--- cxxKinetics.h | 7 +-- cxxMix.cxx | 20 +++--- cxxMix.h | 5 +- dumper.cpp | 4 +- dumper.h | 3 +- runner.cpp | 2 +- runner.h | 4 +- 55 files changed, 549 insertions(+), 429 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 15c1b178..536c190f 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -5,16 +5,23 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include // std::cout std::cerr +#include // assert +#include // std::sort +#include + #include "Utils.h" // define first -#include "ExchComp.h" -#include "Dictionary.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "ExchComp.h" +#include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ExchComp.h b/ExchComp.h index 6f0797d8..68d21791 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -1,15 +1,14 @@ #if !defined(EXCHCOMP_H_INCLUDED) #define EXCHCOMP_H_INCLUDED -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxExchComp { diff --git a/Exchange.cxx b/Exchange.cxx index 07c909e1..fd48ed16 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -4,18 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - #include // std::cout std::cerr -#include "Utils.h" // define first -#include "Exchange.h" -#include "ExchComp.h" +#include // assert +#include // std::sort + +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "cxxMix.h" +#include "Exchange.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -551,10 +555,31 @@ cxxExchange::totalize() this->totals.clear(); // component structures for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); - it != exchComps.end(); ++it) + it != exchComps.end(); ++it) { this->totals.add_extensive((*it).second.get_totals(), 1.0); this->totals.add("Charge", (*it).second.get_charge_balance()); } return; } +bool +cxxExchange::get_pitzer_exchange_gammas() +{ + return this->pitzer_exchange_gammas; +} +void +cxxExchange::set_pitzer_exchange_gammas(bool b) +{ + this->pitzer_exchange_gammas = b; +} + +std::map < std::string, cxxExchComp > & +cxxExchange::get_exchComps(void) +{ + return (this->exchComps); +} +const cxxNameDouble & +cxxExchange::get_totals() const +{ + return totals; +}; \ No newline at end of file diff --git a/Exchange.h b/Exchange.h index e474762e..c3b0660d 100644 --- a/Exchange.h +++ b/Exchange.h @@ -1,26 +1,25 @@ #if !defined(EXCHANGE_H_INCLUDED) #define EXCHANGE_H_INCLUDED -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list - +#include "NumKeyword.h" #include "ExchComp.h" -#include "cxxMix.h" +#include "NameDouble.h" +class cxxMix; class cxxExchange:public cxxNumKeyword { - public: +public: cxxExchange(); cxxExchange(int n_user); - cxxExchange(struct exchange *); - cxxExchange(const std::map < int, cxxExchange > &exchange_map, - cxxMix & mx, int n_user); - ~cxxExchange(); + cxxExchange(struct exchange *); + cxxExchange(const std::map < int, cxxExchange > &exchange_map, + cxxMix & mx, int n_user); + ~cxxExchange(); struct exchange *cxxExchange2exchange(); @@ -34,25 +33,13 @@ class cxxExchange:public cxxNumKeyword bool get_related_rate(void); - bool get_pitzer_exchange_gammas() - { - return this->pitzer_exchange_gammas; - } - void set_pitzer_exchange_gammas(bool b) - { - this->pitzer_exchange_gammas = b; - } + bool get_pitzer_exchange_gammas(); + void set_pitzer_exchange_gammas(bool b); - std::map < std::string, cxxExchComp > &get_exchComps(void) - { - return (this->exchComps); - } + std::map < std::string, cxxExchComp > &get_exchComps(void); void totalize(); - const cxxNameDouble & get_totals() const - { - return totals; - }; + const cxxNameDouble & get_totals() const; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/GasPhase.cxx b/GasPhase.cxx index c8df508c..5315b838 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -4,16 +4,23 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // assert +#include // std::sort +#include #include "Utils.h" // define first -#include "GasPhase.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "GasPhase.h" +#include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/GasPhase.h b/GasPhase.h index 5d3363cf..8cfe5759 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -1,17 +1,15 @@ #if !defined(GASPHASE_H_INCLUDED) #define GASPHASE_H_INCLUDED -#include "NumKeyword.h" -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector -#include "cxxMix.h" +#include "NumKeyword.h" +#include "NameDouble.h" +class cxxMix; class cxxGasPhase:public cxxNumKeyword { diff --git a/ISolution.cxx b/ISolution.cxx index 78355274..2b5e4745 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -4,18 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // assert +#include // std::sort +#include -#include "ISolution.h" -#include "ISolutionComp.h" +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "ISolution.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort -#include #ifdef ORCHESTRA extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); #endif diff --git a/ISolution.h b/ISolution.h index cdb505b0..2c9db096 100644 --- a/ISolution.h +++ b/ISolution.h @@ -1,11 +1,6 @@ #if !defined(ISOLUTION_H_INCLUDED) #define ISOLUTION_H_INCLUDED -//#include "Parser.h" -#include "ISolutionComp.h" -#include "NumKeyword.h" -#include "Solution.h" -//#include "Isotope.h" #include // assert #include // std::map #include // std::string @@ -15,6 +10,11 @@ #include #include #include + +#include "ISolutionComp.h" +#include "NumKeyword.h" +#include "Solution.h" + class cxxISolution:public cxxSolution { diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index fd0c6020..52fbf1c0 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -1,13 +1,16 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "ISolutionComp.h" -#include "ISolution.h" -#include "Utils.h" #include + +#include "Utils.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "ISolutionComp.h" #include "phrqproto.h" #include "phqalloc.h" #include "output.h" diff --git a/ISolutionComp.h b/ISolutionComp.h index 28d24c21..2e045b7d 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -1,13 +1,6 @@ #if !defined(ISOLUTIONCOMP_H_INCLUDED) #define ISOLUTIONCOMP_H_INCLUDED -//#include "Parser.h" -#include "Utils.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" - #include #include // std::map #include diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 5c6dcef5..959ab182 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -4,17 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "KineticsComp.h" -#include "Dictionary.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "KineticsComp.h" +#include "Dictionary.h" +#include "phqalloc.h" +#include "phrqproto.h" + + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/KineticsComp.h b/KineticsComp.h index 17d96930..d66bccdb 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -1,15 +1,14 @@ #if !defined(KINETICSCOMP_H_INCLUDED) #define KINETICSCOMP_H_INCLUDED -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxKineticsComp { diff --git a/NameDouble.cxx b/NameDouble.cxx index cd729ea6..428db5d5 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -4,19 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include // std::cout std::cerr -#include "Utils.h" // define first -#include "NameDouble.h" -#include "Dictionary.h" -#define EXTERNAL extern -#include "global.h" -#include "output.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort #include // std::sort +#include // std::cout std::cerr + +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "NameDouble.h" +#include "Dictionary.h" +#include "phqalloc.h" +#include "phrqproto.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/NameDouble.h b/NameDouble.h index 883f6756..68ef7b69 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -9,6 +9,7 @@ #include // std::vector #include "Parser.h" + class cxxNameDouble:public std::map < std::string, double > { diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 34926f66..dedee506 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -6,6 +6,7 @@ ////////////////////////////////////////////////////////////////////// #include "NumKeyword.h" +#include "Parser.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/NumKeyword.h b/NumKeyword.h index 9c31fb69..4fa31211 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -1,12 +1,11 @@ #if !defined(NUMKEYWORD_H_INCLUDED) #define NUMKEYWORD_H_INCLUDED -#include "Parser.h" +//#include "Parser.h" #include // std::ostream #include // std::string -//#define EXTERNAL extern -//#include "global.h" -//#include "phrqproto.h" +class CParser; + extern char *string_duplicate(const char *); class cxxNumKeyword diff --git a/PPassemblage.cxx b/PPassemblage.cxx index aa35f313..a4c9f8d7 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -4,17 +4,21 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "PPassemblage.h" -#include "PPassemblageComp.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "PPassemblage.h" +#include "cxxMix.h" +#include "phqalloc.h" +#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/PPassemblage.h b/PPassemblage.h index af9cdc75..50a93c0b 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -1,17 +1,15 @@ #if !defined(PPASSEMBLAGE_H_INCLUDED) #define PPASSEMBLAGE_H_INCLUDED -#include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NumKeyword.h" #include "PPassemblageComp.h" -#include "cxxMix.h" +class cxxMix; class cxxPPassemblage:public cxxNumKeyword { diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 4801c633..9af0b3e9 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -4,17 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // assert +#include // std::sort #include "Utils.h" // define first -#include "PPassemblageComp.h" -#include "Dictionary.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "PPassemblageComp.h" +#include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort + ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -365,15 +370,13 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) if (initial_moles_defined == false) { parser.incr_input_error(); - parser. - error_msg("Initial_moles not defined for PPassemblageComp input.", + parser.error_msg("Initial_moles not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } if (dissolve_only_defined == false) { parser.incr_input_error(); - parser. - error_msg("Dissolve_only not defined for PPassemblageComp input.", + parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } /* don't check to maintain backward compatibility @@ -388,8 +391,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) if (force_equality_defined == false) { parser.incr_input_error(); - parser. - error_msg + parser.error_msg ("Force_equality not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index e88a35c7..a220d31e 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -1,15 +1,14 @@ #if !defined(PPASSEMBLAGECOMP_H_INCLUDED) #define PPASSEMBLAGECOMP_H_INCLUDED -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxPPassemblageComp { diff --git a/Reaction.cxx b/Reaction.cxx index b40b194f..9dd9fb0b 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -4,16 +4,20 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "Reaction.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "Reaction.h" +#include "phqalloc.h" +#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/Reaction.h b/Reaction.h index ae6d8dd2..e3c24594 100644 --- a/Reaction.h +++ b/Reaction.h @@ -1,16 +1,15 @@ #if !defined(REACTION_H_INCLUDED) #define REACTION_H_INCLUDED -#include "NumKeyword.h" -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NumKeyword.h" +#include "NameDouble.h" + class cxxReaction:public cxxNumKeyword { diff --git a/ReadClass.cxx b/ReadClass.cxx index 48805ea0..398436bd 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1,6 +1,16 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include +#include +#include + +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif #include "Parser.h" #include "Solution.h" #include "Exchange.h" @@ -14,14 +24,10 @@ #include "Temperature.h" #include "dumper.h" #include "runner.h" -#define EXTERNAL extern -#include "global.h" +#include "cxxMix.h" #include "phqalloc.h" -#include "output.h" #include "phrqproto.h" -#include -#include -#include +#include "output.h" static int streamify_to_next_keyword(std::istringstream & lines); extern int reading_database(void); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index de9b9b87..95909e95 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -9,17 +9,18 @@ #include // std::sort #include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif #include "SSassemblage.h" #include "SSassemblageSS.h" #include "cxxMix.h" -#if defined(PHREEQC_CLASS) -#define CLASS_STATIC static -#endif -#include "global_structures.h" #include "phqalloc.h" #include "phrqproto.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/SSassemblage.h b/SSassemblage.h index 40cbb185..b81b8475 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -1,14 +1,14 @@ #if !defined(SSASSEMBLAGE_H_INCLUDED) #define SSASSEMBLAGE_H_INCLUDED -#include "NumKeyword.h" + #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector -//#include "SSassemblageSS.h" +#include "NumKeyword.h" #include "NameDouble.h" class cxxSSassemblageSS; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 47e3ce37..b1e96f29 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -4,18 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "SSassemblageSS.h" -#include "NameDouble.h" -#include "Dictionary.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "SSassemblageSS.h" +#include "Dictionary.h" +#include "phqalloc.h" +#include "phrqproto.h" + + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 8c601e52..af148c50 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -1,13 +1,14 @@ #if !defined(SSASSEMBLAGESS_H_INCLUDED) #define SSASSEMBLAGESS_H_INCLUDED -#include "NameDouble.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxSSassemblageSS { diff --git a/Solution.cxx b/Solution.cxx index 193591df..3b0f5a98 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -4,19 +4,26 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // assert +#include // std::sort + #ifdef USE_MPI //MPICH seems to require mpi.h to be first #include #endif #include "Utils.h" // define first -#include "Solution.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "Solution.h" +#include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort + ////////////////////////////////////////////////////////////////////// diff --git a/Solution.h b/Solution.h index 96a03533..90b9bcae 100644 --- a/Solution.h +++ b/Solution.h @@ -1,19 +1,17 @@ #if !defined(SOLUTION_H_INCLUDED) #define SOLUTION_H_INCLUDED -#include "NumKeyword.h" -#include "SolutionIsotopeList.h" -#include "NameDouble.h" -#include "cxxMix.h" - -//#define EXTERNAL extern -//#include "global.h" #include // assert #include // std::map #include // std::string #include // std::vector #include +#include "NumKeyword.h" +#include "SolutionIsotopeList.h" +#include "NameDouble.h" +class cxxMix; + class cxxSolution:public cxxNumKeyword { diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index baff944c..510e1563 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -1,16 +1,20 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "SolutionIsotope.h" -#include "Utils.h" -#include "Parser.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include #include // std::ostrstream +#include "Utils.h" +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "SolutionIsotope.h" +#include "phqalloc.h" +#include "phrqproto.h" + cxxSolutionIsotope::cxxSolutionIsotope(void): isotope_number(0.0) { diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 32fc066f..e3589470 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -1,10 +1,10 @@ #if !defined(SOLUTIONISOTOPE_H_INCLUDED) #define SOLUTIONISOTOPE_H_INCLUDED -#include "Parser.h" #include // std::ostream #include // std::string #include // std::list +#include "Parser.h" class cxxSolutionIsotope { diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 2989d788..b1910b63 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -1,12 +1,18 @@ #include "Utils.h" // define first -#include "SolutionIsotopeList.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "SolutionIsotopeList.h" +#include "phqalloc.h" +#include "phrqproto.h" + + cxxSolutionIsotopeList::cxxSolutionIsotopeList(void) // // default constructor for cxxSolution diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index efc9f192..e2862ec2 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -1,18 +1,14 @@ #if !defined(SOLUTIONISOTOPELIST_H_INCLUDED) #define SOLUTIONISOTOPELIST_H_INCLUDED -//#define EXTERNAL extern -#include "SolutionIsotope.h" -//#include "global.h" #include // assert #include // std::string #include // std::list -#include "Parser.h" +#include "SolutionIsotope.h" class cxxSolutionIsotopeList:public - std::list < - cxxSolutionIsotope > + std::list < cxxSolutionIsotope > { public: @@ -29,7 +25,7 @@ public: protected: - public: +public: }; diff --git a/StorageBin.cxx b/StorageBin.cxx index cb965b6d..6a210f30 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -4,14 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include +#include // std::cout std::cerr +#include // assert +#include // std::sort + #ifdef USE_MPI //MPICH seems to require mpi.h to be first #include #endif - -#include -#include // std::cout std::cerr #include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif #include "NameDouble.h" #include "StorageBin.h" #include "SSassemblage.h" @@ -26,14 +34,9 @@ #include "cxxMix.h" #include "Reaction.h" #include "Temperature.h" - -#define EXTERNAL extern -#include "global.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/StorageBin.h b/StorageBin.h index 44ff84fd..ba0750c5 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -6,9 +6,7 @@ #include // std::list #include // std::vector -//#include "Utils.h" -//#include "Parser.h" - +#include "System.h" class cxxSolution; class cxxExchange; class cxxGasPhase; @@ -16,11 +14,9 @@ class cxxKinetics; class cxxPPassemblage; class cxxSSassemblage; class cxxSurface; -#include "System.h" class cxxReaction; class cxxTemperature; - class cxxStorageBin { diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 201528d0..cbbdf385 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -1,5 +1,7 @@ -#include "StorageBinList.h" #include // std::replace +#include "StorageBinList.h" +#include "Parser.h" + StorageBinListItem::StorageBinListItem(void) { this->defined = false; diff --git a/StorageBinList.h b/StorageBinList.h index 10094d0a..4656f817 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -4,7 +4,9 @@ #include // std::string #include // std::list #include // std::vector -#include "Parser.h" + +class CParser; + class StorageBinListItem { public: diff --git a/Surface.cxx b/Surface.cxx index a48bd0c7..129e4570 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -4,17 +4,21 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "Surface.h" -#include "SurfaceComp.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "Surface.h" +#include "cxxMix.h" +#include "phqalloc.h" +#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/Surface.h b/Surface.h index 461f7520..86828a74 100644 --- a/Surface.h +++ b/Surface.h @@ -1,18 +1,16 @@ #if !defined(SURFACE_H_INCLUDED) #define SURFACE_H_INCLUDED -#include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NumKeyword.h" #include "SurfaceComp.h" #include "SurfaceCharge.h" -#include "cxxMix.h" +class cxxMix; class cxxSurface:public cxxNumKeyword { diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 8e22a6b4..f6ffa348 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -4,26 +4,30 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "SurfaceCharge.h" -#include "Dictionary.h" -#define EXTERNAL extern -#include "global.h" -#include "output.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "SurfaceCharge.h" +#include "Dictionary.h" +#include "phqalloc.h" +#include "phrqproto.h" +#include "output.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSurfaceCharge::cxxSurfaceCharge() - // - // default constructor for cxxSurfaceCharge - // +// +// default constructor for cxxSurfaceCharge +// { specific_area = 0.0; grams = 0.0; @@ -38,10 +42,10 @@ cxxSurfaceCharge::cxxSurfaceCharge() } cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr) - // - // constructor for cxxSurfaceCharge from struct surface_charge - // - : +// +// constructor for cxxSurfaceCharge from struct surface_charge +// +: diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) { this->set_name(surf_charge_ptr->name); @@ -61,7 +65,7 @@ cxxSurfaceCharge::~cxxSurfaceCharge() } struct master * -cxxSurfaceCharge::get_psi_master() + cxxSurfaceCharge::get_psi_master() { struct master *master_ptr = NULL; std::string str = this->name; @@ -81,9 +85,9 @@ cxxSurfaceCharge::get_psi_master() struct surface_charge * cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el) - // - // Builds surface_charge structure from of cxxSurfaceCharge - // + // + // Builds surface_charge structure from of cxxSurfaceCharge + // { struct surface_charge *surf_charge_ptr = (struct surface_charge *) @@ -93,7 +97,7 @@ struct surface_charge * int i = 0; for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin(); - it != el.end(); ++it) + it != el.end(); ++it) { surf_charge_ptr[i].name = string_hsave((*it).second.name.c_str()); assert((*it).second.name.size() > 0); @@ -265,7 +269,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } else { @@ -280,7 +284,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->specific_area = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for specific_area.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } specific_area_defined = true; break; @@ -291,7 +295,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->grams = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for grams.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } grams_defined = true; break; @@ -303,7 +307,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->charge_balance = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge_balance.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } charge_balance_defined = true; break; @@ -314,7 +318,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->mass_water = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for mass_water.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } mass_water_defined = true; break; @@ -326,7 +330,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } la_psi_defined = true; break; @@ -340,7 +344,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } opt_save = 6; break; @@ -351,7 +355,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi1 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi1.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } la_psi1_defined = true; break; @@ -362,7 +366,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi2 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } la_psi2_defined = true; break; @@ -373,7 +377,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->capacitance[0] = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for capacitance0.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } capacitance0_defined = true; break; @@ -384,7 +388,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->capacitance[1] = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for capacitance1.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } capacitance1_defined = true; break; diff --git a/SurfaceCharge.h b/SurfaceCharge.h index a5841a3f..bb24db33 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -1,23 +1,22 @@ #if !defined(SURFACECHARGE_H_INCLUDED) #define SURFACECHARGE_H_INCLUDED -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxSurfaceCharge { - public: +public: cxxSurfaceCharge(); cxxSurfaceCharge(struct surface_charge *); - ~cxxSurfaceCharge(); + ~cxxSurfaceCharge(); struct master *get_psi_master(); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index bab9bb65..5e7fc69d 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -4,26 +4,30 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#include // assert +#include // std::sort #include "Utils.h" // define first -#include "SurfaceComp.h" -#include "Dictionary.h" +#if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "SurfaceComp.h" +#include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include // assert -#include // std::sort ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// cxxSurfaceComp::cxxSurfaceComp() - // - // default constructor for cxxSurfaceComp - // +// +// default constructor for cxxSurfaceComp +// { formula_totals.type = cxxNameDouble::ND_ELT_MOLES; formula_z = 0.0; @@ -37,10 +41,10 @@ cxxSurfaceComp::cxxSurfaceComp() } cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) - // - // constructor for cxxSurfaceComp from struct surface_comp - // - : +// +// constructor for cxxSurfaceComp from struct surface_comp +// +: formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { @@ -61,12 +65,12 @@ cxxSurfaceComp::~cxxSurfaceComp() } struct master * -cxxSurfaceComp::get_master() + cxxSurfaceComp::get_master() { struct master *master_ptr = NULL; //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { for (cxxNameDouble::iterator it = this->totals.begin(); - it != this->totals.end(); it++) + it != this->totals.end(); it++) { /* Find master species */ char *eltName = string_hsave(it->first.c_str()); @@ -100,9 +104,9 @@ cxxSurfaceComp::get_master() struct surface_comp * cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el) - // - // Builds surface_comp structure from of cxxSurfaceComp - // + // + // Builds surface_comp structure from of cxxSurfaceComp + // { struct surface_comp *surf_comp_ptr = (struct surface_comp *) @@ -112,7 +116,7 @@ struct surface_comp * int i = 0; for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin(); - it != el.end(); ++it) + it != el.end(); ++it) { surf_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str()); assert((*it).second.formula.size() > 0); @@ -306,7 +310,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for formula.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } else { @@ -321,7 +325,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for moles.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } moles_defined = true; break; @@ -332,7 +336,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->la = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } la_defined = true; break; @@ -343,7 +347,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->charge_number = 0; parser.incr_input_error(); parser.error_msg("Expected integer value for charge_number.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } charge_number_defined = true; break; @@ -354,7 +358,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->charge_balance = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge_balance.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } charge_balance_defined = true; break; @@ -365,7 +369,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->phase_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for phase_name.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } else { @@ -379,7 +383,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } else { @@ -394,7 +398,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected numeric value for phase_proportion.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } break; @@ -406,7 +410,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceComp totals.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } opt_save = 8; break; @@ -417,7 +421,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->formula_z = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for formula_z.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } formula_z_defined = true; break; @@ -430,7 +434,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceComp formula totals.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } opt_save = 10; break; @@ -441,7 +445,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->Dw = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for Dw.", - CParser::OT_CONTINUE); + CParser::OT_CONTINUE); } Dw_defined = true; break; @@ -658,3 +662,77 @@ cxxSurfaceComp::multiply(double extensive) //char *rate_name; //double Dw; } +const std::string & +cxxSurfaceComp::get_phase_name() const +{ + return this->phase_name; +} +void +cxxSurfaceComp::set_phase_name(char * f) +{ + if (f != NULL) + this->phase_name = std::string(f); + else + this->phase_name.clear(); +} +const std::string & +cxxSurfaceComp::get_rate_name() const +{ + return this->rate_name; +} +void +cxxSurfaceComp::set_rate_name(char * f) +{ + if (f != NULL) + this->rate_name = std::string(f); + else + this->rate_name.clear(); +} +const std::string & +cxxSurfaceComp::get_formula() const +{ + return this->formula; +} +void +cxxSurfaceComp::set_formula(char * f) +{ + if (f != NULL) + this->formula = std::string(f); + else + this->formula.clear(); +} +double +cxxSurfaceComp::get_charge_balance() const +{ + return this->charge_balance; +} +void +cxxSurfaceComp::set_charge_balance(double d) +{ + this->charge_balance = d; +} +const cxxNameDouble & +cxxSurfaceComp::get_totals() const +{ + return (this->totals); +}; +std::string +cxxSurfaceComp::charge_name() +{ + char * str = string_hsave(this->formula.c_str()); + return (get_charge_name(str)); +}; +std::string +cxxSurfaceComp::get_charge_name(char *token) +{ + char name[100]; + int l; + char *ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + { + ptr1[0] = '\0'; + } + return (std::string(name)); +}; \ No newline at end of file diff --git a/SurfaceComp.h b/SurfaceComp.h index c1c43eb8..f0e28241 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -1,136 +1,60 @@ #if !defined(SURFACECOMP_H_INCLUDED) #define SURFACECOMP_H_INCLUDED -#include "NameDouble.h" -#define EXTERNAL extern -#include "global.h" -#include "phrqproto.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NameDouble.h" + class cxxSurfaceComp { - public: +public: cxxSurfaceComp(); cxxSurfaceComp(struct surface_comp *); - ~cxxSurfaceComp(); - + ~cxxSurfaceComp(); struct master *get_master(); - const std::string &get_phase_name() const - { - return this->phase_name; - } - void set_phase_name(char * f) - { - if (f != NULL) - this->phase_name = std::string(f); - else - this->phase_name.clear(); - } - const std::string &get_rate_name() const - { - return this->rate_name; - } - void set_rate_name(char * f) - { - if (f != NULL) - this->rate_name = std::string(f); - else - this->rate_name.clear(); - } - const std::string &get_formula() const - { - return this->formula; - } - void set_formula(char * f) - { - if (f != NULL) - this->formula = std::string(f); - else - this->formula.clear(); - } - double get_charge_balance() const - { - return this->charge_balance; - } - void set_charge_balance(double d) - { - this->charge_balance = d; - } - + const std::string &get_phase_name() const; + void set_phase_name(char * f); + const std::string &get_rate_name() const; + void set_rate_name(char * f); + const std::string &get_formula() const; + void set_formula(char * f); + double get_charge_balance() const; + void set_charge_balance(double d); static struct surface_comp *cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; - void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); - const cxxNameDouble & get_totals() const - { - return (this->totals); - }; - - + const cxxNameDouble & get_totals() const; void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - - std::string charge_name() - { - char * str = string_hsave(this->formula.c_str()); - return (get_charge_name(str)); - }; - - //static std::string &get_charge_name(char *token) - //{ - // char name[100]; - // int l; - // char *ptr1 = token; - // get_elt(&ptr1, name, &l); - // ptr1 = strchr(name, '_'); - // if (ptr1 != NULL) - // { - // ptr1[0] = '\0'; - // } - // return (string_hsave(name)); - //}; - static std::string get_charge_name(char *token) - { - char name[100]; - int l; - char *ptr1 = token; - get_elt(&ptr1, name, &l); - ptr1 = strchr(name, '_'); - if (ptr1 != NULL) - { - ptr1[0] = '\0'; - } - return (std::string(name)); - }; + std::string charge_name(); + static std::string get_charge_name(char *token); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - protected: - std::string formula; - cxxNameDouble formula_totals; - double formula_z; - double moles; - cxxNameDouble totals; - double la; - //int charge_number; - double charge_balance; - std::string phase_name; - double phase_proportion; - std::string rate_name; - double Dw; - public: +protected: + std::string formula; + cxxNameDouble formula_totals; + double formula_z; + double moles; + cxxNameDouble totals; + double la; + //int charge_number; + double charge_balance; + std::string phase_name; + double phase_proportion; + std::string rate_name; + double Dw; +public: }; diff --git a/System.cxx b/System.cxx index b22ef153..f9f46ce0 100644 --- a/System.cxx +++ b/System.cxx @@ -1,5 +1,26 @@ -#include "System.h" #include // std::replace + +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "System.h" +#include "SSassemblage.h" +#include "Solution.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblageSS.h" +#include "SSassemblage.h" +#include "Surface.h" +#include "cxxMix.h" +#include "Reaction.h" +#include "Temperature.h" + + extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); cxxSystem::cxxSystem(void) { diff --git a/System.h b/System.h index c27c4eb5..a5c0cca3 100644 --- a/System.h +++ b/System.h @@ -1,15 +1,27 @@ #if !defined(SYSTEM_H_INCLUDED) #define SYSTEM_H_INCLUDED -#include "Solution.h" -#include "Exchange.h" -#include "GasPhase.h" -#include "cxxKinetics.h" -#include "PPassemblage.h" -#include "SSassemblage.h" -#include "Surface.h" -#include "cxxMix.h" -#include "Reaction.h" -#include "Temperature.h" +//#include "Solution.h" +//#include "Exchange.h" +//#include "GasPhase.h" +//#include "cxxKinetics.h" +//#include "PPassemblage.h" +//#include "SSassemblage.h" +//#include "Surface.h" +//#include "cxxMix.h" +//#include "Reaction.h" +//#include "Temperature.h" +#include "NameDouble.h" +class cxxSolution; +class cxxExchange; +class cxxGasPhase; +class cxxKinetics; +class cxxPPassemblage; +class cxxSSassemblage; +class cxxSurface; +class cxxReaction; +class cxxTemperature; +class cxxMix; + class cxxSystem { public:cxxSystem(void); diff --git a/Temperature.cxx b/Temperature.cxx index 2ceeb196..86dce37b 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -4,16 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "Temperature.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#include "Parser.h" +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "Temperature.h" +#include "phqalloc.h" +#include "phrqproto.h" + + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/Temperature.h b/Temperature.h index ef7cf2a5..a34818f6 100644 --- a/Temperature.h +++ b/Temperature.h @@ -1,15 +1,14 @@ #if !defined(TEMPERATURE_H_INCLUDED) #define TEMPERATURE_H_INCLUDED -#include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector +#include "NumKeyword.h" + class cxxTemperature:public cxxNumKeyword { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index f2709a33..f140fd77 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -4,17 +4,24 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "cxxKinetics.h" -#include "KineticsComp.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif + +#include "cxxKinetics.h" +#include "cxxMix.h" + +#include "phqalloc.h" +#include "phrqproto.h" + + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/cxxKinetics.h b/cxxKinetics.h index a38a4311..bef2abab 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -1,18 +1,15 @@ #if !defined(CXXKINETICS_H_INCLUDED) #define CXXKINETICS_H_INCLUDED -#include "NumKeyword.h" -#define EXTERNAL extern -#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector -#include "char_star.h" +#include "NumKeyword.h" #include "KineticsComp.h" -#include "cxxMix.h" +class cxxMix; class cxxKinetics:public cxxNumKeyword { diff --git a/cxxMix.cxx b/cxxMix.cxx index 8f7145be..79c9895c 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -4,16 +4,22 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#include "Utils.h" // define first -#include "cxxMix.h" -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" #include // assert #include // std::sort +#include "Utils.h" // define first +#include "Parser.h" +#if !defined(PHREEQC_CLASS) +#define EXTERNAL extern +#include "global.h" +#else +#include "Phreeqc.h" +#endif +#include "cxxMix.h" +#include "phqalloc.h" +#include "phrqproto.h" + + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// diff --git a/cxxMix.h b/cxxMix.h index 05fb92e6..3117af5b 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -1,16 +1,13 @@ #if !defined(CXXMIX_H_INCLUDED) #define CXXMIX_H_INCLUDED -#include "NumKeyword.h" -//#define EXTERNAL extern -//#include "global.h" #include // assert #include // std::map #include // std::string #include // std::list #include // std::vector -#include "char_star.h" +#include "NumKeyword.h" class cxxMix:public cxxNumKeyword { diff --git a/dumper.cpp b/dumper.cpp index 2341296f..bea4ebb4 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -1,6 +1,8 @@ -#include "dumper.h" #include // std::replace +#include "dumper.h" +#include "Parser.h" + dumper::dumper(void) { this->file_name = "dump.out"; diff --git a/dumper.h b/dumper.h index f951aa96..d5ee1c0f 100644 --- a/dumper.h +++ b/dumper.h @@ -4,8 +4,9 @@ #include // std::string #include // std::list #include // std::vector -#include "Parser.h" #include "StorageBinList.h" +class CParser; + class dumper { public: diff --git a/runner.cpp b/runner.cpp index 092cb8f3..1a8952bf 100644 --- a/runner.cpp +++ b/runner.cpp @@ -1,5 +1,5 @@ #include "runner.h" - +#include "Parser.h" runner::runner(void) { this->time_step = 0; diff --git a/runner.h b/runner.h index fb407ebd..11073164 100644 --- a/runner.h +++ b/runner.h @@ -2,8 +2,10 @@ #define RUNNER_H_INCLUDED #include // std::set #include // std::string -#include "Parser.h" + #include "StorageBinList.h" +class CParser; + class runner { public: From 6859605bc2df64094e3199c4fb1d9a2a5b5686af Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Dec 2009 21:33:07 +0000 Subject: [PATCH 0120/1077] Debug and release compile. Rearranged pitaer.h creating pitzer_structures.h. Need to figure out conversion routines from C++ classes to C structures. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3869 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 31 +++++++++++++++++++++++++++++- ReadClass.cxx | 48 +++++++++++++++++++++++----------------------- SSassemblageSS.cxx | 2 +- SurfaceCharge.cxx | 4 ++-- 4 files changed, 57 insertions(+), 28 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 6fa0e30a..ede46152 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -7,6 +7,9 @@ * INCLUDE FILES * ---------------------------------------------------------------------- */ +#include +#include +#include #include #include #include @@ -32,7 +35,7 @@ #include "p2c.h" #undef extern #include "global_structures.h" - +#include "pitzer_structures.h" class Phreeqc { public: @@ -831,6 +834,32 @@ void SetChartTitle(char *s); #endif int next_keyword_or_option(const char **opt_list, int count_opt_list); +// ReadClass.cxx + int read_solution_raw(void); + int read_exchange_raw(void); + int read_surface_raw(void); + int read_equilibrium_phases_raw(void); + int read_kinetics_raw(void); + int read_solid_solutions_raw(void); + int read_gas_phase_raw(void); + int read_reaction_raw(void); + int read_mix_raw(void); + int read_temperature_raw(void); + int read_dump(void); + int read_solution_modify(void); + int read_equilibrium_phases_modify(void); + int read_exchange_modify(void); + int read_surface_modify(void); + int read_solid_solutions_modify(void); + int read_gas_phase_modify(void); + int read_kinetics_modify(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + // readtr.c ------------------------------- int read_transport(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 398436bd..af43738c 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -40,7 +40,7 @@ StorageBinList delete_info; runner run_info; /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_solution_raw(void) /* ---------------------------------------------------------------------- */ { @@ -133,7 +133,7 @@ read_solution_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_exchange_raw(void) /* ---------------------------------------------------------------------- */ { @@ -227,7 +227,7 @@ read_exchange_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_surface_raw(void) /* ---------------------------------------------------------------------- */ { @@ -321,7 +321,7 @@ read_surface_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_equilibrium_phases_raw(void) /* ---------------------------------------------------------------------- */ { @@ -418,7 +418,7 @@ read_equilibrium_phases_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_kinetics_raw(void) /* ---------------------------------------------------------------------- */ { @@ -512,7 +512,7 @@ read_kinetics_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_solid_solutions_raw(void) /* ---------------------------------------------------------------------- */ { @@ -611,7 +611,7 @@ read_solid_solutions_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_gas_phase_raw(void) /* ---------------------------------------------------------------------- */ { @@ -705,7 +705,7 @@ read_gas_phase_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_reaction_raw(void) /* ---------------------------------------------------------------------- */ { @@ -800,7 +800,7 @@ read_reaction_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_mix_raw(void) /* ---------------------------------------------------------------------- */ { @@ -895,7 +895,7 @@ read_mix_raw(void) } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_temperature_raw(void) /* ---------------------------------------------------------------------- */ { @@ -992,7 +992,7 @@ read_temperature_raw(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_dump(void) /* ---------------------------------------------------------------------- */ { @@ -1044,7 +1044,7 @@ read_dump(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_delete(void) /* ---------------------------------------------------------------------- */ { @@ -1096,7 +1096,7 @@ read_delete(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_run_cells(void) /* ---------------------------------------------------------------------- */ { @@ -1148,7 +1148,7 @@ read_run_cells(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_solution_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1235,7 +1235,7 @@ read_solution_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_equilibrium_phases_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1322,7 +1322,7 @@ read_equilibrium_phases_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_exchange_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1411,7 +1411,7 @@ read_exchange_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_surface_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1498,7 +1498,7 @@ read_surface_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_solid_solutions_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1585,7 +1585,7 @@ read_solid_solutions_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_gas_phase_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1670,7 +1670,7 @@ read_gas_phase_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER read_kinetics_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1757,7 +1757,7 @@ read_kinetics_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER streamify_to_next_keyword(std::istringstream & lines) /* ---------------------------------------------------------------------- */ { @@ -1804,7 +1804,7 @@ streamify_to_next_keyword(std::istringstream & lines) return (OPTION_ERROR); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER dump_entities(void) /* ---------------------------------------------------------------------- */ { @@ -2023,7 +2023,7 @@ dump_entities(void) return (OK); } /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER delete_entities(void) /* ---------------------------------------------------------------------- */ { @@ -2341,7 +2341,7 @@ run_as_cells(void) } #endif /* ---------------------------------------------------------------------- */ -int +int CLASS_QUALIFIER run_as_cells(void) /* ---------------------------------------------------------------------- */ { diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index b1e96f29..72ef5f26 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -77,7 +77,7 @@ cxxSSassemblageSS::~cxxSSassemblageSS() } struct s_s * - cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > &el) +cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > &el) // // Builds s_s structure from of cxxSSassemblageSS // diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index f6ffa348..97cd7754 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -65,7 +65,7 @@ cxxSurfaceCharge::~cxxSurfaceCharge() } struct master * - cxxSurfaceCharge::get_psi_master() +cxxSurfaceCharge::get_psi_master() { struct master *master_ptr = NULL; std::string str = this->name; @@ -84,7 +84,7 @@ struct master * } struct surface_charge * - cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el) +cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el) // // Builds surface_charge structure from of cxxSurfaceCharge // From 157e5cc729089d3770fe85b7c82e3e461535542f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Dec 2009 00:56:50 +0000 Subject: [PATCH 0121/1077] Slowly adding arguments and qualifiers to pass phreeqc class instance to routines that need it. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3873 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.cxx | 26 +- ISolutionComp.h | 6 +- NameDouble.cxx | 8 +- NameDouble.h | 4 +- Parser.h | 1 + Phreeqc.h | 45 +- Reaction.cxx | 10 +- Reaction.h | 2 +- SSassemblage.cxx | 10 +- SSassemblage.h | 3 +- SSassemblageSS.cxx | 16 +- SSassemblageSS.h | 5 +- Solution.cxx | 898 ++++++++++++++++++++-------------------- Solution.h | 8 +- SolutionIsotope.cxx | 20 +- SolutionIsotope.h | 7 +- SolutionIsotopeList.cxx | 10 +- SolutionIsotopeList.h | 3 +- Surface.cxx | 14 +- Surface.h | 4 +- SurfaceCharge.cxx | 44 +- SurfaceCharge.h | 3 +- SurfaceComp.cxx | 10 +- SurfaceComp.h | 2 +- Temperature.cxx | 8 +- Temperature.h | 3 +- phreeqc_class.h | 15 + 27 files changed, 612 insertions(+), 573 deletions(-) create mode 100644 phreeqc_class.h diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 52fbf1c0..1a8d9c07 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -70,7 +70,7 @@ struct conc *cxxISolutionComp::concarray(std::map &totals) // for ISolutions // takes a std::vector cxxISolutionComp structures @@ -80,25 +80,25 @@ struct conc * c = (struct conc *) PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); if (c == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxISolutionComp >::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = string_duplicate(it->second.description.c_str()); + c[i].description = P_INSTANCE_POINTER string_duplicate(it->second.description.c_str()); c[i].moles = it->second.moles; c[i].input_conc = it->second.input_conc; if (it->second.units.size() == 0) c[i].units = NULL; else - c[i].units = string_hsave(it->second.units.c_str()); + c[i].units = P_INSTANCE_POINTER string_hsave(it->second.units.c_str()); if (it->second.equation_name.size() == 0) c[i].equation_name = NULL; else - c[i].equation_name = string_hsave(it->second.equation_name.c_str()); + c[i].equation_name = P_INSTANCE_POINTER string_hsave(it->second.equation_name.c_str()); c[i].phase_si = it->second.phase_si; c[i].n_pe = it->second.n_pe; - c[i].as = string_hsave(it->second.as.c_str()); + c[i].as = P_INSTANCE_POINTER string_hsave(it->second.as.c_str()); c[i].gfw = it->second.gfw; //c[i].skip = 0; c[i].phase = NULL; @@ -109,7 +109,7 @@ struct conc * } void -cxxISolutionComp::set_gfw() +cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) { // return gfw if (this->gfw > 0.0) @@ -119,12 +119,12 @@ cxxISolutionComp::set_gfw() { /* use given chemical formula to calculate gfw */ double gfw; - if (compute_gfw(this->as.c_str(), &gfw) == ERROR) + if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &gfw) == ERROR) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER input_error++; return; } //if (this->description == "Alkalinity" && this->as == "CaCO3") @@ -138,7 +138,7 @@ cxxISolutionComp::set_gfw() } /* use gfw of master species */ std::string str(this->description); - struct master *master_ptr = master_bsearch(str.c_str()); + struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(str.c_str()); if (master_ptr != NULL) { /* use gfw for element redox state */ @@ -147,8 +147,8 @@ cxxISolutionComp::set_gfw() } std::ostringstream oss; oss << "Could not find gfw, " << this->description; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER input_error++; return; } diff --git a/ISolutionComp.h b/ISolutionComp.h index 2e045b7d..c6f63ed5 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -5,7 +5,7 @@ #include // std::map #include #include - +#include "Phreeqc_class.h" // forward declarations class cxxISolution; // reqd for read and dump_xml @@ -116,14 +116,14 @@ class cxxISolutionComp { this->gfw = gfw; } - void set_gfw(); + void set_gfw(PHREEQC_PTR_ARG); bool operator<(const cxxISolutionComp & conc) const { return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0; } - static struct conc *cxxISolutionComp2conc(const std::map < std::string, cxxISolutionComp > &t); + static struct conc *cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < std::string, cxxISolutionComp > &t); private: std::string description; diff --git a/NameDouble.cxx b/NameDouble.cxx index 428db5d5..9f0f8760 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -133,7 +133,7 @@ cxxNameDouble::~cxxNameDouble() } struct elt_list * -cxxNameDouble::elt_list() +cxxNameDouble::elt_list(PHREEQC_PTR_ARG) // // Builds a exch_comp structure from instance of cxxNameDouble // @@ -143,11 +143,11 @@ cxxNameDouble::elt_list() (struct elt_list *) PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list))); if (elt_list_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (iterator it = this->begin(); it != this->end(); ++it) { - elt_list_ptr[i].elt = element_store(it->first.c_str()); + elt_list_ptr[i].elt = P_INSTANCE_POINTER element_store(it->first.c_str()); elt_list_ptr[i].coef = it->second; i++; } @@ -176,7 +176,7 @@ cxxNameDouble::master_activity() const (((*this).size() + 1) * sizeof(struct master_activity))); if (master_activity_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { diff --git a/NameDouble.h b/NameDouble.h index 68ef7b69..2fee9087 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -7,7 +7,7 @@ #include // std::string #include // std::list #include // std::vector - +#include "Phreeqc_class.h" #include "Parser.h" class cxxNameDouble:public @@ -34,7 +34,7 @@ class cxxNameDouble:public cxxNameDouble(); struct elt_list * - elt_list(); + elt_list(PHREEQC_PTR_ARG); struct master_activity * master_activity() const; diff --git a/Parser.h b/Parser.h index 83e67e96..63ff0841 100644 --- a/Parser.h +++ b/Parser.h @@ -302,6 +302,7 @@ class CParser ECHO_OPTION echo_file; std::string accumulated; bool accumulate; + //int const &input_error_parser; }; // Global functions diff --git a/Phreeqc.h b/Phreeqc.h index ede46152..bea8d45c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include "phrqtype.h" #include "sundialstypes.h" @@ -103,9 +102,8 @@ public: /* integertype, and the constant FALSE */ public: #include "output.h" -private: +public: #include "global.h" - /* All functions are included as methods here */ @@ -437,7 +435,6 @@ static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, realtype uround, void *jac_data, long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); -private: int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); int calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step); @@ -534,7 +531,6 @@ int get_secondary(char **t_ptr, char *element, int *i); int get_species(char **ptr); // phqalloc.c ------------------------------- - public: #if !defined(NDEBUG) void *PHRQ_malloc(size_t, const char *, int); @@ -546,8 +542,9 @@ void *PHRQ_calloc(size_t, size_t); void *PHRQ_realloc(void *, size_t); #endif void PHRQ_free(void *ptr); -private: + void PHRQ_free_all(void); +private: // phreeqc_files.c ------------------------------- @@ -1032,8 +1029,10 @@ struct logk *logk_search(char *name); struct master *master_alloc(void); CLASS_STATIC int master_compare(const void *ptr1, const void *ptr2); int master_delete(char *ptr); +public: struct master *master_bsearch(const char *ptr); struct master *master_bsearch_primary(char *ptr); +private: struct master *master_search(char *ptr, int *n); struct mix *mix_bsearch(int k, int *n); int mix_copy(struct mix *mix_old_ptr, @@ -1047,7 +1046,9 @@ struct pe_data *pe_data_alloc(void); struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); int pe_data_store(struct pe_data **pe, const char *token); +public: struct phase *phase_bsearch(const char *ptr, int *j, int print); +private: CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); int phase_delete(int i); struct phase *phase_store(char *name); @@ -1084,7 +1085,9 @@ CLASS_STATIC int s_compare(const void *ptr1, const void *ptr2); int s_delete(int i); struct species *s_search(const char *name); struct species *s_store(char *name, LDBLE z, int replace_if_found); -struct s_s_assemblage *s_s_assemblage_alloc(void); +public: + struct s_s_assemblage *s_s_assemblage_alloc(void); +private: struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); @@ -1112,7 +1115,9 @@ int save_values_store(struct save_values *s_v); CLASS_STATIC int conc_compare(const void *ptr1, const void *ptr2); int conc_init(struct conc *conc_ptr); CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); -struct solution *solution_alloc(void); +public: + struct solution *solution_alloc(void); +private: struct solution *solution_bsearch(int k, int *n, int print); struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); @@ -1129,7 +1134,9 @@ CLASS_STATIC int species_list_compare_alk(const void *ptr1, const void *ptr2); CLASS_STATIC int species_list_compare_master(const void *ptr1, const void *ptr2); int species_list_sort(void); struct Change_Surf *change_surf_alloc(int count); -struct surface *surface_alloc(void); +public: + struct surface *surface_alloc(void); +private: struct surface *surface_bsearch(int k, int *n); struct master *surface_get_psi_master(const char *name, int plane); CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); @@ -1312,21 +1319,29 @@ int mix_stag(int i, LDBLE stagkin_time, int punch, int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); -int compute_gfw(const char *string, LDBLE * gfw); +public: + int compute_gfw(const char *string, LDBLE * gfw); +private: int copy_token(char *token_ptr, char **ptr, int *length); int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); -void *free_check_null(void *ptr); +public: + void *free_check_null(void *ptr); +private: void free_hash_strings(HashTable * Table); int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); void hdestroy_multi(HashTable * HashTable_ptr); ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); int islegit(const char c); +public: void malloc_error(void); +private: int parse_couple(char *token); int print_centered(const char *string); -int replace(const char *str1, const char *str2, char *str); +public: +CLASS_STATIC int replace(const char *str1, const char *str2, char *str); +private: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); int status(int count, const char *str); @@ -1334,8 +1349,10 @@ void str_tolower(char *str); void str_toupper(char *str); CLASS_STATIC int strcmp_nocase(const char *str1, const char *str2); int strcmp_nocase_arg1(const char *str1, const char *str2); -char *string_duplicate(const char *token); -char *string_hsave(const char *str); +public: + char *string_duplicate(const char *token); + char *string_hsave(const char *str); +private: char *string_pad(char *str, int i); int string_trim(char *str); int string_trim_right(char *str); diff --git a/Reaction.cxx b/Reaction.cxx index 9dd9fb0b..8449ee7a 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -77,7 +77,7 @@ cxxReaction::~cxxReaction() struct irrev * -cxxReaction::cxxReaction2irrev() +cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) // // Builds a irrev structure from instance of cxxReaction // @@ -85,7 +85,7 @@ cxxReaction::cxxReaction2irrev() struct irrev *irrev_ptr; irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof(struct irrev)); if (irrev_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); irrev_ptr->description = this->get_description(); irrev_ptr->n_user = this->n_user; @@ -95,7 +95,7 @@ cxxReaction::cxxReaction2irrev() irrev_ptr->count_list = (int) this->reactantList.size(); if (this->elementList.size() > 0) { - irrev_ptr->elts = this->elementList.elt_list(); + irrev_ptr->elts = this->elementList.elt_list(P_INSTANCE); } else { @@ -110,7 +110,7 @@ cxxReaction::cxxReaction2irrev() (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (irrev_ptr->steps == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); } if (this->equalIncrements) @@ -124,7 +124,7 @@ cxxReaction::cxxReaction2irrev() if (this->units.size() == 0) irrev_ptr->units = NULL; else - irrev_ptr->units = string_hsave(this->units.c_str()); + irrev_ptr->units = P_INSTANCE_POINTER string_hsave(this->units.c_str()); return (irrev_ptr); } diff --git a/Reaction.h b/Reaction.h index e3c24594..8c011c35 100644 --- a/Reaction.h +++ b/Reaction.h @@ -18,7 +18,7 @@ class cxxReaction:public cxxNumKeyword cxxReaction(struct irrev *); ~cxxReaction(); - struct irrev *cxxReaction2irrev(); + struct irrev *cxxReaction2irrev(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 95909e95..fddebdd5 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -79,12 +79,12 @@ cxxSSassemblage::~cxxSSassemblage() } struct s_s_assemblage * -cxxSSassemblage::cxxSSassemblage2s_s_assemblage() +cxxSSassemblage::cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG) // // Builds a s_s_assemblage structure from instance of cxxSSassemblage // { - struct s_s_assemblage *s_s_assemblage_ptr = s_s_assemblage_alloc(); + struct s_s_assemblage *s_s_assemblage_ptr = P_INSTANCE_POINTER s_s_assemblage_alloc(); s_s_assemblage_ptr->description = this->get_description(); s_s_assemblage_ptr->n_user = this->n_user; @@ -92,7 +92,7 @@ cxxSSassemblage::cxxSSassemblage2s_s_assemblage() s_s_assemblage_ptr->new_def = FALSE; s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size(); s_s_assemblage_ptr->s_s = - cxxSSassemblageSS::cxxSSassemblageSS2s_s(this->ssAssemblageSSs); + cxxSSassemblageSS::cxxSSassemblageSS2s_s(P_INSTANCE_COMMA this->ssAssemblageSSs); return (s_s_assemblage_ptr); } @@ -312,14 +312,14 @@ cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void -cxxSSassemblage::totalize() +cxxSSassemblage::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures for (std::map < std::string, cxxSSassemblageSS >::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { - (*it).second.totalize(); + (*it).second.totalize(P_INSTANCE); this->totals.add_extensive((*it).second.get_totals(), 1.0); } return; diff --git a/SSassemblage.h b/SSassemblage.h index b81b8475..fcd48461 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -8,6 +8,7 @@ #include // std::list #include // std::vector +#include "Phreeqc_class.h" #include "NumKeyword.h" #include "NameDouble.h" class cxxSSassemblageSS; @@ -25,7 +26,7 @@ public: cxxMix & mx, int n_user); ~cxxSSassemblage(); - struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(); + struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG); struct s_s *cxxSSassemblageComp2s_s(); diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 72ef5f26..86cee5d9 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -77,7 +77,7 @@ cxxSSassemblageSS::~cxxSSassemblageSS() } struct s_s * -cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > &el) +cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > &el) // // Builds s_s structure from of cxxSSassemblageSS // @@ -89,12 +89,12 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblage struct s_s *s_s_ptr = (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); if (s_s_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int j = 0; for (std::map < std::string, cxxSSassemblageSS >::iterator it = el.begin(); it != el.end(); ++it) { - s_s_ptr[j].name = string_hsave((*it).second.name.c_str()); + s_s_ptr[j].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); assert((*it).second.name.size() > 0); //s_s_ptr[j].total_moles = it->total_moles; s_s_ptr[j].total_moles = 0; @@ -132,13 +132,13 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblage PHRQ_malloc((size_t) ((*it).second.comps.size() * sizeof(struct s_s_comp))); if (s_s_comp_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); for (cxxNameDouble::iterator itc = (*it).second.comps.begin(); itc != (*it).second.comps.end(); ++itc) { - s_s_comp_ptr[i].name = string_hsave(itc->first.c_str()); + s_s_comp_ptr[i].name = P_INSTANCE_POINTER string_hsave(itc->first.c_str()); assert(itc->first.size() > 0); - s_s_comp_ptr[i].phase = phase_bsearch(itc->first.c_str(), &n, TRUE); + s_s_comp_ptr[i].phase = P_INSTANCE_POINTER phase_bsearch(itc->first.c_str(), &n, TRUE); s_s_comp_ptr[i].initial_moles = 0; s_s_comp_ptr[i].moles = itc->second; s_s_comp_ptr[i].init_moles = 0; @@ -541,7 +541,7 @@ cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void -cxxSSassemblageSS::totalize() +cxxSSassemblageSS::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures @@ -550,7 +550,7 @@ cxxSSassemblageSS::totalize() { struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + phase_ptr = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/SSassemblageSS.h b/SSassemblageSS.h index af148c50..b72e1d8b 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -8,6 +8,7 @@ #include // std::vector #include "NameDouble.h" +#include "Phreeqc_class.h" class cxxSSassemblageSS { @@ -32,7 +33,7 @@ class cxxSSassemblageSS SS_PARM_MARGULES = 9 }; - static struct s_s *cxxSSassemblageSS2s_s(std::map < std::string, cxxSSassemblageSS > + static struct s_s *cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -53,7 +54,7 @@ class cxxSSassemblageSS this->name.clear(); } - void totalize(); + void totalize(PHREEQC_PTR_ARG); const cxxNameDouble & get_totals() const { return (this->totals); diff --git a/Solution.cxx b/Solution.cxx index 3b0f5a98..ac8c57f5 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -94,7 +94,7 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, } -cxxSolution::cxxSolution(const std::map < int, cxxSolution > &solutions, +cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solutions, cxxMix & mix, int n_user) // // constructor for cxxSolution from mixture of solutions @@ -119,9 +119,9 @@ cxxNumKeyword() solutions.find(it->first); if (sol == solutions.end()) { - sprintf(error_string, + sprintf(P_INSTANCE_POINTER error_string, "Solution %d not found in mix_cxxSolutions.", it->first); - error_msg(error_string, CONTINUE); + P_INSTANCE_POINTER error_msg(P_INSTANCE_POINTER error_string, CONTINUE); input_error++; } else @@ -132,7 +132,7 @@ cxxNumKeyword() } } -cxxSolution::cxxSolution(int n_user) +cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user) // // constructor for cxxSolution from results of calculation // does not work in phast because phast uses only the total molalities @@ -144,16 +144,16 @@ cxxNumKeyword() //this->set_description none; this->n_user = n_user; this->n_user_end = n_user; - this->tc = tc_x; - this->ph = ph_x; - this->pe = solution_pe_x; - this->mu = mu_x; - this->ah2o = ah2o_x; - this->total_h = total_h_x; - this->total_o = total_o_x; - this->cb = cb_x; - this->mass_water = mass_water_aq_x; - this->total_alkalinity =::total_alkalinity; + this->tc = P_INSTANCE_POINTER tc_x; + this->ph = P_INSTANCE_POINTER ph_x; + this->pe = P_INSTANCE_POINTER solution_pe_x; + this->mu = P_INSTANCE_POINTER mu_x; + this->ah2o = P_INSTANCE_POINTER ah2o_x; + this->total_h = P_INSTANCE_POINTER total_h_x; + this->total_o = P_INSTANCE_POINTER total_o_x; + this->cb = P_INSTANCE_POINTER cb_x; + this->mass_water = P_INSTANCE_POINTER mass_water_aq_x; + this->total_alkalinity = P_INSTANCE_POINTER total_alkalinity; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; @@ -161,18 +161,18 @@ cxxNumKeyword() * Add in minor isotopes if initial solution calculation */ int i; - if (initial_solution_isotopes == TRUE) + if (P_INSTANCE_POINTER initial_solution_isotopes == TRUE) { struct master *master_ptr, *master_i_ptr; - for (i = 0; i < count_master_isotope; i++) + for (i = 0; i < P_INSTANCE_POINTER count_master_isotope; i++) { - if (master_isotope[i]->moles > 0) + if (P_INSTANCE_POINTER master_isotope[i]->moles > 0) { - master_i_ptr = master_bsearch(master_isotope[i]->name); - master_ptr = master_isotope[i]->elt->master; - if (master_isotope[i]->minor_isotope == TRUE) + master_i_ptr = P_INSTANCE_POINTER master_bsearch(P_INSTANCE_POINTER master_isotope[i]->name); + master_ptr = P_INSTANCE_POINTER master_isotope[i]->elt->master; + if (P_INSTANCE_POINTER master_isotope[i]->minor_isotope == TRUE) { - master_i_ptr->total = master_isotope[i]->moles; + master_i_ptr->total = P_INSTANCE_POINTER master_isotope[i]->moles; if (master_ptr->total > 0) { master_i_ptr->s->la = @@ -184,19 +184,19 @@ cxxNumKeyword() master_i_ptr->s->la = master_ptr->s->la; } } - else if (master_isotope[i]->minor_isotope == FALSE - && master_ptr->s != s_hplus - && master_ptr->s != s_h2o) + else if (P_INSTANCE_POINTER master_isotope[i]->minor_isotope == FALSE + && master_ptr->s != P_INSTANCE_POINTER s_hplus + && master_ptr->s != P_INSTANCE_POINTER s_h2o) { if (master_ptr->s->secondary != NULL) { master_ptr->s->secondary->total = - master_isotope[i]->moles; + P_INSTANCE_POINTER master_isotope[i]->moles; } else { master_ptr->s->primary->total = - master_isotope[i]->moles; + P_INSTANCE_POINTER master_isotope[i]->moles; } } } @@ -210,59 +210,59 @@ cxxNumKeyword() */ // totals and master_activity - for (i = 0; i < count_master; i++) + for (i = 0; i < P_INSTANCE_POINTER count_master; i++) { - if (master[i]->s->type == EX || - master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + if (P_INSTANCE_POINTER master[i]->s->type == EX || + P_INSTANCE_POINTER master[i]->s->type == SURF || P_INSTANCE_POINTER master[i]->s->type == SURF_PSI) continue; - if (master[i]->s == s_hplus) + if (P_INSTANCE_POINTER master[i]->s == P_INSTANCE_POINTER s_hplus) continue; - if (master[i]->s == s_h2o) + if (P_INSTANCE_POINTER master[i]->s == P_INSTANCE_POINTER s_h2o) continue; - if (master[i]->in != FALSE) + if (P_INSTANCE_POINTER master[i]->in != FALSE) { - this->master_activity[master[i]->elt->name] = master[i]->s->la; + this->master_activity[P_INSTANCE_POINTER master[i]->elt->name] = P_INSTANCE_POINTER master[i]->s->la; } - if (master[i]->total <= MIN_TOTAL) + if (P_INSTANCE_POINTER master[i]->total <= MIN_TOTAL) { - master[i]->total = 0.0; - master[i]->total_primary = 0.0; + P_INSTANCE_POINTER master[i]->total = 0.0; + P_INSTANCE_POINTER master[i]->total_primary = 0.0; continue; } - this->totals[master[i]->elt->name] = master[i]->total; + this->totals[P_INSTANCE_POINTER master[i]->elt->name] = P_INSTANCE_POINTER master[i]->total; } // species_gammas for Pitzer - if (pitzer_model == TRUE) + if (P_INSTANCE_POINTER pitzer_model == TRUE) { int j; - for (j = 0; j < count_s; j++) + for (j = 0; j < P_INSTANCE_POINTER count_s; j++) { - if (s[j]->lg != 0.0) + if (P_INSTANCE_POINTER s[j]->lg != 0.0) { - this->species_gamma[s[j]->name] = s[j]->lg; + this->species_gamma[P_INSTANCE_POINTER s[j]->name] = P_INSTANCE_POINTER s[j]->lg; } } } // Save isotope data - if (count_isotopes_x > 0) + if (P_INSTANCE_POINTER count_isotopes_x > 0) { - for (i = 0; i < count_isotopes_x; i++) + for (i = 0; i < P_INSTANCE_POINTER count_isotopes_x; i++) { cxxSolutionIsotope cxxiso; - cxxiso.set_isotope_number(isotopes_x[i].isotope_number); - cxxiso.set_elt_name(isotopes_x[i].elt_name); - cxxiso.set_isotope_name(isotopes_x[i].isotope_name); - cxxiso.set_total(isotopes_x[i].master->total); - if (isotopes_x[i].master == s_hplus->secondary) + cxxiso.set_isotope_number(P_INSTANCE_POINTER isotopes_x[i].isotope_number); + cxxiso.set_elt_name(P_INSTANCE_POINTER isotopes_x[i].elt_name); + cxxiso.set_isotope_name(P_INSTANCE_POINTER isotopes_x[i].isotope_name); + cxxiso.set_total(P_INSTANCE_POINTER isotopes_x[i].master->total); + if (P_INSTANCE_POINTER isotopes_x[i].master == P_INSTANCE_POINTER s_hplus->secondary) { - cxxiso.set_total(2 * mass_water_aq_x / gfw_water); + cxxiso.set_total(2 * P_INSTANCE_POINTER mass_water_aq_x / P_INSTANCE_POINTER gfw_water); } - if (isotopes_x[i].master == s_h2o->secondary) + if (P_INSTANCE_POINTER isotopes_x[i].master == P_INSTANCE_POINTER s_h2o->secondary) { - cxxiso.set_total(mass_water_aq_x / gfw_water); + cxxiso.set_total(P_INSTANCE_POINTER mass_water_aq_x / P_INSTANCE_POINTER gfw_water); } // cxxiso.ratio // cxxiso.ratio_uncertainty @@ -276,13 +276,13 @@ cxxSolution::~cxxSolution() { } struct solution * -cxxSolution::cxxSolution2solution() +cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) // // Builds a solution structure from instance of cxxSolution // { - struct solution *solution_ptr = solution_alloc(); + struct solution *solution_ptr = P_INSTANCE_POINTER solution_alloc(); solution_ptr->description = this->get_description(); solution_ptr->n_user = this->n_user; @@ -299,18 +299,18 @@ cxxSolution::cxxSolution2solution() solution_ptr->mass_water = this->mass_water; solution_ptr->total_alkalinity = this->total_alkalinity; solution_ptr->density = 1.0; - solution_ptr->units = moles_per_kilogram_string; + solution_ptr->units = P_INSTANCE_POINTER moles_per_kilogram_string; solution_ptr->default_pe = 0; // pe_data // totals solution_ptr->totals = - (struct conc *) free_check_null(solution_ptr->totals); + (struct conc *) P_INSTANCE_POINTER free_check_null(solution_ptr->totals); solution_ptr->totals = this->totals.conc(); // master_activity solution_ptr->master_activity = - (struct master_activity *) free_check_null(solution_ptr-> + (struct master_activity *) P_INSTANCE_POINTER free_check_null(solution_ptr-> master_activity); solution_ptr->master_activity = this->master_activity.master_activity(); solution_ptr->count_master_activity = @@ -322,9 +322,9 @@ cxxSolution::cxxSolution2solution() // isotopes solution_ptr->isotopes = - (struct isotope *) free_check_null(solution_ptr->isotopes); + (struct isotope *) P_INSTANCE_POINTER free_check_null(solution_ptr->isotopes); //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); - solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(); + solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(P_INSTANCE); solution_ptr->count_isotopes = (int) this->isotopes.size(); return (solution_ptr); @@ -976,7 +976,7 @@ cxxSolution::get_total_element(char *string) const if (it->first[0] == string[0]) { strcpy(token, it->first.c_str()); - replace("(", "\0", token); + CLASS_QUALIFIER replace("(", "\0", token); if (strcmp(token, string) == 0) { d += it->second; @@ -1531,393 +1531,393 @@ cxxSolution::set_master_activity(char *string, double d) this->master_activity[string] = d; } -#include "ISolution.h" -#include "Exchange.h" -#include "Surface.h" -#include "PPassemblage.h" -#include "cxxKinetics.h" -#include "SSassemblage.h" -#include "GasPhase.h" -#include "Reaction.h" -#include "Temperature.h" -#include "StorageBin.h" -#include "NumKeyword.h" -#include // std::cout std::cerr -//#include -#include -#include -void -test_classes(void) -{ - - - - - int i; - /* - std::map Solutions; - cxxSolution soln(solution[0]); - Solutions[solution[0]->n_user] = soln; - bool b = Utilities::exists(Solutions, 1); - */ - /* - cxxEntityMap x; - cxxSolution soln(solution[0]); - cxxNumKeyword nk; - x[solution[0]->n_user] = soln; - */ - std::ostringstream msg; - status_on = FALSE; - std::cout << std::endl << "TEST CLASSES" << std::endl; - for (i = 0; i < count_solution; i++) - { - if (solution[i]->new_def == TRUE) - { - std::cout << "Solution new_def " << solution[i]-> - n_user << std::endl; - cxxISolution sol(solution[i]); - solution_free(solution[i]); - solution[i] = NULL; - solution[i] = sol.cxxISolution2solution(); - struct solution *soln_ptr; - soln_ptr = solution[i]; - soln_ptr = solution[i]; - } - else - { - std::cout << "Solution " << solution[i]->n_user << std::endl; - std::ostringstream oss; - cxxSolution sol(solution[i]); - solution_free(solution[i]); - solution[i] = NULL; - sol.dump_raw(oss, 0); - - //std::fstream myfile("t"); - //CParser cparser(myfile, std::cout, std::cerr); - cxxSolution sol1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - - sol1.read_raw(cparser); - - solution[i] = sol1.cxxSolution2solution(); - } - } - for (i = 0; i < count_exchange; i++) - { - if (exchange[i].new_def != TRUE) - { - std::cout << "Exchange " << exchange[i].n_user << std::endl; - std::ostringstream oss; - cxxExchange ex(&(exchange[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - cxxExchange ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); - exchange_free(&exchange[i]); - exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); - exchange_free(exchange_ptr); - free_check_null(exchange_ptr); - } - } - for (i = 0; i < count_surface; i++) - { - if (surface[i].new_def != TRUE) - { - std::cout << "Surface " << surface[i].n_user << std::endl; - std::ostringstream oss; - cxxSurface ex(&(surface[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxSurface ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct surface *surface_ptr = ex1.cxxSurface2surface(); - surface_free(&surface[i]); - surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); - surface_free(surface_ptr); - free_check_null(surface_ptr); - - } - - } - for (i = 0; i < count_pp_assemblage; i++) - { - if (pp_assemblage[i].new_def != TRUE) - { - std::cout << "PPassemblage " << pp_assemblage[i]. - n_user << std::endl; - std::ostringstream oss; - cxxPPassemblage ex(&(pp_assemblage[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxPPassemblage ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct pp_assemblage *pp_assemblage_ptr = - ex1.cxxPPassemblage2pp_assemblage(); - pp_assemblage_free(&pp_assemblage[i]); - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], - pp_assemblage_ptr->n_user); - pp_assemblage_free(pp_assemblage_ptr); - free_check_null(pp_assemblage_ptr); - - } - - } - for (i = 0; i < count_kinetics; i++) - { - std::cout << "Kinetics " << kinetics[i].n_user << std::endl; - std::ostringstream oss; - cxxKinetics ex(&(kinetics[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxKinetics ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - - ex1.read_raw(cparser); - - struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); - kinetics_free(&kinetics[i]); - kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); - kinetics_free(kinetics_ptr); - free_check_null(kinetics_ptr); - } - for (i = 0; i < count_s_s_assemblage; i++) - { - if (s_s_assemblage[i].new_def != TRUE) - { - std::cout << "Solid solution " << s_s_assemblage[i]. - n_user << std::endl; - std::ostringstream oss; - cxxSSassemblage ex(&(s_s_assemblage[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxSSassemblage ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct s_s_assemblage *s_s_assemblage_ptr = - ex1.cxxSSassemblage2s_s_assemblage(); - s_s_assemblage_free(&s_s_assemblage[i]); - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], - s_s_assemblage_ptr->n_user); - s_s_assemblage_free(s_s_assemblage_ptr); - free_check_null(s_s_assemblage_ptr); - - } - - } - for (i = 0; i < count_gas_phase; i++) - { - if (gas_phase[i].new_def != TRUE) - { - std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; - std::ostringstream oss; - cxxGasPhase ex(&(gas_phase[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxGasPhase ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - - struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); - gas_phase_free(&gas_phase[i]); - gas_phase_copy(gas_phase_ptr, &gas_phase[i], - gas_phase_ptr->n_user); - gas_phase_free(gas_phase_ptr); - free_check_null(gas_phase_ptr); - - } - - } - for (i = 0; i < count_irrev; i++) - { - std::cout << "Reaction " << irrev[i].n_user << std::endl; - std::ostringstream oss; - cxxReaction ex(&(irrev[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxReaction ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); - - irrev_free(&irrev[i]); - irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); - - irrev_free(irrev_ptr); - free_check_null(irrev_ptr); - - } - for (i = 0; i < count_mix; i++) - { - std::cout << "Mix " << mix[i].n_user << std::endl; - std::ostringstream oss; - cxxMix ex(&(mix[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxMix ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct mix *mix_ptr = ex1.cxxMix2mix(); - - mix_free(&mix[i]); - mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); - - mix_free(mix_ptr); - free_check_null(mix_ptr); - - } - for (i = 0; i < count_temperature; i++) - { - std::cout << "Temperature " << temperature[i].n_user << std::endl; - std::ostringstream oss; - cxxTemperature ex(&(temperature[i])); - ex.dump_raw(oss, 0); - //std::cerr << oss.str(); - - - cxxTemperature ex1; - std::string keyInput = oss.str(); - std::istringstream iss(keyInput); - - CParser cparser(iss, oss, std::cerr); - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - cparser.get_option(vopts, next_char); - - ex1.read_raw(cparser); - struct temperature *temperature_ptr = - ex1.cxxTemperature2temperature(); - - temperature_free(&temperature[i]); - temperature_copy(temperature_ptr, &temperature[i], - temperature_ptr->n_user); - - temperature_free(temperature_ptr); - free_check_null(temperature_ptr); - - } - /* - { - // get all c storage - cxxStorageBin cstorage; - cstorage.import_phreeqc(); - //std::ostringstream oss; - //cstorage.dump_raw(oss, 0); - //write it out - std::fstream myfile; - myfile.open("tfile", std::ios_base::out); - cstorage.dump_raw(myfile, 0); - myfile.close(); - } - { - // empty storage bin - cxxStorageBin cstorage; - // fstream - std::fstream myfile; - myfile.open("tfile", std::ios_base::in); - // ostream - std::ostringstream oss; - // parser - CParser cparser(myfile, oss, std::cerr); - cstorage.read_raw(cparser); - //std::cerr << oss.str(); - - // read it back - } - */ -} +//#include "ISolution.h" +//#include "Exchange.h" +//#include "Surface.h" +//#include "PPassemblage.h" +//#include "cxxKinetics.h" +//#include "SSassemblage.h" +//#include "GasPhase.h" +//#include "Reaction.h" +//#include "Temperature.h" +//#include "StorageBin.h" +//#include "NumKeyword.h" +//#include // std::cout std::cerr +////#include +//#include +//#include +//void +//test_classes(void) +//{ +// +// +// +// +// int i; +// /* +// std::map Solutions; +// cxxSolution soln(solution[0]); +// Solutions[solution[0]->n_user] = soln; +// bool b = Utilities::exists(Solutions, 1); +// */ +// /* +// cxxEntityMap x; +// cxxSolution soln(solution[0]); +// cxxNumKeyword nk; +// x[solution[0]->n_user] = soln; +// */ +// std::ostringstream msg; +// status_on = FALSE; +// std::cout << std::endl << "TEST CLASSES" << std::endl; +// for (i = 0; i < count_solution; i++) +// { +// if (solution[i]->new_def == TRUE) +// { +// std::cout << "Solution new_def " << solution[i]-> +// n_user << std::endl; +// cxxISolution sol(solution[i]); +// solution_free(solution[i]); +// solution[i] = NULL; +// solution[i] = sol.cxxISolution2solution(); +// struct solution *soln_ptr; +// soln_ptr = solution[i]; +// soln_ptr = solution[i]; +// } +// else +// { +// std::cout << "Solution " << solution[i]->n_user << std::endl; +// std::ostringstream oss; +// cxxSolution sol(solution[i]); +// solution_free(solution[i]); +// solution[i] = NULL; +// sol.dump_raw(oss, 0); +// +// //std::fstream myfile("t"); +// //CParser cparser(myfile, std::cout, std::cerr); +// cxxSolution sol1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// +// sol1.read_raw(cparser); +// +// solution[i] = sol1.cxxSolution2solution(); +// } +// } +// for (i = 0; i < count_exchange; i++) +// { +// if (exchange[i].new_def != TRUE) +// { +// std::cout << "Exchange " << exchange[i].n_user << std::endl; +// std::ostringstream oss; +// cxxExchange ex(&(exchange[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// cxxExchange ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// +// struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); +// exchange_free(&exchange[i]); +// exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); +// exchange_free(exchange_ptr); +// free_check_null(exchange_ptr); +// } +// } +// for (i = 0; i < count_surface; i++) +// { +// if (surface[i].new_def != TRUE) +// { +// std::cout << "Surface " << surface[i].n_user << std::endl; +// std::ostringstream oss; +// cxxSurface ex(&(surface[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxSurface ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// +// struct surface *surface_ptr = ex1.cxxSurface2surface(); +// surface_free(&surface[i]); +// surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); +// surface_free(surface_ptr); +// free_check_null(surface_ptr); +// +// } +// +// } +// for (i = 0; i < count_pp_assemblage; i++) +// { +// if (pp_assemblage[i].new_def != TRUE) +// { +// std::cout << "PPassemblage " << pp_assemblage[i]. +// n_user << std::endl; +// std::ostringstream oss; +// cxxPPassemblage ex(&(pp_assemblage[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxPPassemblage ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// +// struct pp_assemblage *pp_assemblage_ptr = +// ex1.cxxPPassemblage2pp_assemblage(); +// pp_assemblage_free(&pp_assemblage[i]); +// pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], +// pp_assemblage_ptr->n_user); +// pp_assemblage_free(pp_assemblage_ptr); +// free_check_null(pp_assemblage_ptr); +// +// } +// +// } +// for (i = 0; i < count_kinetics; i++) +// { +// std::cout << "Kinetics " << kinetics[i].n_user << std::endl; +// std::ostringstream oss; +// cxxKinetics ex(&(kinetics[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxKinetics ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// +// ex1.read_raw(cparser); +// +// struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); +// kinetics_free(&kinetics[i]); +// kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); +// kinetics_free(kinetics_ptr); +// free_check_null(kinetics_ptr); +// } +// for (i = 0; i < count_s_s_assemblage; i++) +// { +// if (s_s_assemblage[i].new_def != TRUE) +// { +// std::cout << "Solid solution " << s_s_assemblage[i]. +// n_user << std::endl; +// std::ostringstream oss; +// cxxSSassemblage ex(&(s_s_assemblage[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxSSassemblage ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// +// struct s_s_assemblage *s_s_assemblage_ptr = +// ex1.cxxSSassemblage2s_s_assemblage(); +// s_s_assemblage_free(&s_s_assemblage[i]); +// s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], +// s_s_assemblage_ptr->n_user); +// s_s_assemblage_free(s_s_assemblage_ptr); +// free_check_null(s_s_assemblage_ptr); +// +// } +// +// } +// for (i = 0; i < count_gas_phase; i++) +// { +// if (gas_phase[i].new_def != TRUE) +// { +// std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; +// std::ostringstream oss; +// cxxGasPhase ex(&(gas_phase[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxGasPhase ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// +// struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); +// gas_phase_free(&gas_phase[i]); +// gas_phase_copy(gas_phase_ptr, &gas_phase[i], +// gas_phase_ptr->n_user); +// gas_phase_free(gas_phase_ptr); +// free_check_null(gas_phase_ptr); +// +// } +// +// } +// for (i = 0; i < count_irrev; i++) +// { +// std::cout << "Reaction " << irrev[i].n_user << std::endl; +// std::ostringstream oss; +// cxxReaction ex(&(irrev[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxReaction ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); +// +// irrev_free(&irrev[i]); +// irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); +// +// irrev_free(irrev_ptr); +// free_check_null(irrev_ptr); +// +// } +// for (i = 0; i < count_mix; i++) +// { +// std::cout << "Mix " << mix[i].n_user << std::endl; +// std::ostringstream oss; +// cxxMix ex(&(mix[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxMix ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// struct mix *mix_ptr = ex1.cxxMix2mix(); +// +// mix_free(&mix[i]); +// mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); +// +// mix_free(mix_ptr); +// free_check_null(mix_ptr); +// +// } +// for (i = 0; i < count_temperature; i++) +// { +// std::cout << "Temperature " << temperature[i].n_user << std::endl; +// std::ostringstream oss; +// cxxTemperature ex(&(temperature[i])); +// ex.dump_raw(oss, 0); +// //std::cerr << oss.str(); +// +// +// cxxTemperature ex1; +// std::string keyInput = oss.str(); +// std::istringstream iss(keyInput); +// +// CParser cparser(iss, oss, std::cerr); +// //For testing, need to read line to get started +// std::vector < std::string > vopts; +// std::istream::pos_type next_char; +// cparser.get_option(vopts, next_char); +// +// ex1.read_raw(cparser); +// struct temperature *temperature_ptr = +// ex1.cxxTemperature2temperature(); +// +// temperature_free(&temperature[i]); +// temperature_copy(temperature_ptr, &temperature[i], +// temperature_ptr->n_user); +// +// temperature_free(temperature_ptr); +// free_check_null(temperature_ptr); +// +// } +// /* +// { +// // get all c storage +// cxxStorageBin cstorage; +// cstorage.import_phreeqc(); +// //std::ostringstream oss; +// //cstorage.dump_raw(oss, 0); +// //write it out +// std::fstream myfile; +// myfile.open("tfile", std::ios_base::out); +// cstorage.dump_raw(myfile, 0); +// myfile.close(); +// } +// { +// // empty storage bin +// cxxStorageBin cstorage; +// // fstream +// std::fstream myfile; +// myfile.open("tfile", std::ios_base::in); +// // ostream +// std::ostringstream oss; +// // parser +// CParser cparser(myfile, oss, std::cerr); +// cstorage.read_raw(cparser); +// //std::cerr << oss.str(); +// +// // read it back +// } +// */ +//} diff --git a/Solution.h b/Solution.h index 90b9bcae..c7b4cd0f 100644 --- a/Solution.h +++ b/Solution.h @@ -6,7 +6,7 @@ #include // std::string #include // std::vector #include - +#include "Phreeqc_class.h" #include "NumKeyword.h" #include "SolutionIsotopeList.h" #include "NameDouble.h" @@ -18,8 +18,8 @@ class cxxSolution:public cxxNumKeyword public: cxxSolution(); cxxSolution(struct solution *); - cxxSolution(int n_user); - cxxSolution(const std::map < int, cxxSolution > &solution_map, + cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user); + cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solution_map, cxxMix & mx, int n_user); ~cxxSolution(); @@ -148,7 +148,7 @@ class cxxSolution:public cxxNumKeyword void set_isotope(char *string, double value); */ - struct solution *cxxSolution2solution(); + struct solution *cxxSolution2solution(PHREEQC_PTR_ARG); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 510e1563..bef1e969 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -36,7 +36,7 @@ cxxSolutionIsotope::~cxxSolutionIsotope(void) } struct isotope * -cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist) +cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &isolist) // takes a std::list of cxxSolutionIsotope structures // returns array of isotope structures { @@ -51,18 +51,18 @@ cxxSolutionIsotope::list2isotope(std::list < cxxSolutionIsotope > &isolist) (struct isotope *) PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); if (iso == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::list < cxxSolutionIsotope >::iterator it = isolist.begin(); it != isolist.end(); ++it) { iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = string_hsave(it->elt_name.c_str()); + iso[i].elt_name = P_INSTANCE_POINTER string_hsave(it->elt_name.c_str()); iso[i].total = it->total; iso[i].ratio = it->ratio; iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); + iso[i].master = it->master(P_INSTANCE); + iso[i].primary = it->primary(P_INSTANCE); i++; } } @@ -213,16 +213,16 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const } struct master * -cxxSolutionIsotope::master(void) +cxxSolutionIsotope::master(PHREEQC_PTR_ARG) { - return (master_bsearch(this->elt_name.c_str())); + return (P_INSTANCE_POINTER master_bsearch(this->elt_name.c_str())); } struct master * -cxxSolutionIsotope::primary(void) +cxxSolutionIsotope::primary(PHREEQC_PTR_ARG) { - char * str = string_hsave(this->elt_name.c_str()); - return (master_bsearch_primary(str)); + char * str = P_INSTANCE_POINTER string_hsave(this->elt_name.c_str()); + return (P_INSTANCE_POINTER master_bsearch_primary(str)); } void diff --git a/SolutionIsotope.h b/SolutionIsotope.h index e3589470..5a11e8de 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -5,6 +5,7 @@ #include // std::string #include // std::list #include "Parser.h" +#include "Phreeqc_class.h" class cxxSolutionIsotope { @@ -20,7 +21,7 @@ class cxxSolutionIsotope }; */ //cxxSolutionIsotope::STATUS read(CParser& parser); - static struct isotope *list2isotope(std::list < cxxSolutionIsotope > &t); + static struct isotope *list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &t); void dump_xml(std::ostream & os, unsigned int indent) const; void dump_raw(std::ostream & os, unsigned int indent) const; @@ -83,8 +84,8 @@ class cxxSolutionIsotope bool operator<(const cxxSolutionIsotope & conc) const; - struct master *master(void); - struct master *primary(void); + struct master *master(PHREEQC_PTR_ARG); + struct master *primary(PHREEQC_PTR_ARG); void add(const cxxSolutionIsotope & isotope_ptr, double intensive, double extensive); diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index b1910b63..02f92b94 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -85,7 +85,7 @@ cxxSolutionIsotopeList::multiply(double extensive) } } struct isotope * -cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() +cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG) { struct isotope *iso; if (this->size() <= 0) @@ -98,18 +98,18 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope() (struct isotope *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); if (iso == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) { iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = string_hsave(it->elt_name.c_str()); + iso[i].elt_name = P_INSTANCE_POINTER string_hsave(it->elt_name.c_str()); iso[i].total = it->total; iso[i].ratio = it->ratio; iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(); - iso[i].primary = it->primary(); + iso[i].master = it->master(P_INSTANCE); + iso[i].primary = it->primary(P_INSTANCE); i++; } } diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index e2862ec2..6d8483c8 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -6,6 +6,7 @@ #include // std::list #include "SolutionIsotope.h" +#include "Phreeqc_class.h" class cxxSolutionIsotopeList:public std::list < cxxSolutionIsotope > @@ -18,7 +19,7 @@ public: ~cxxSolutionIsotopeList(); - struct isotope * cxxSolutionIsotopeList2isotope(); + struct isotope * cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG); void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); void multiply(double extensive); diff --git a/Surface.cxx b/Surface.cxx index 129e4570..1bdaa3b8 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -6,7 +6,7 @@ #endif #include // assert #include // std::sort - +#include "Phreeqc_class.h" #include "Utils.h" // define first #if !defined(PHREEQC_CLASS) #define EXTERNAL extern @@ -143,12 +143,12 @@ cxxSurface::get_related_rate() } struct surface * -cxxSurface::cxxSurface2surface() +cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) // // Builds a surface structure from instance of cxxSurface // { - struct surface *surface_ptr = surface_alloc(); + struct surface *surface_ptr = P_INSTANCE_POINTER surface_alloc(); surface_ptr->description = this->get_description(); surface_ptr->n_user = this->n_user; @@ -175,19 +175,19 @@ cxxSurface::cxxSurface2surface() // Surface comps surface_ptr->count_comps = (int) this->surfaceComps.size(); surface_ptr->comps = - (struct surface_comp *) free_check_null(surface_ptr->comps); + (struct surface_comp *) P_INSTANCE_POINTER free_check_null(surface_ptr->comps); surface_ptr->comps = cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); // Surface charge surface_ptr->charge = - (struct surface_charge *) free_check_null(surface_ptr->charge); + (struct surface_charge *) P_INSTANCE_POINTER free_check_null(surface_ptr->charge); //if (surface_ptr->edl == TRUE) { if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) { surface_ptr->count_charge = (int) this->surfaceCharges.size(); surface_ptr->charge = - cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges); + cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(P_INSTANCE_COMMA this->surfaceCharges); } else { @@ -199,7 +199,7 @@ cxxSurface::cxxSurface2surface() int i, j; for (i = 0; i < surface_ptr->count_comps; i++) { - char *charge_name = string_hsave( + char *charge_name = P_INSTANCE_POINTER string_hsave( cxxSurfaceComp::get_charge_name(surface_ptr->comps[i]. formula).c_str()); for (j = 0; j < surface_ptr->count_charge; j++) diff --git a/Surface.h b/Surface.h index 86828a74..be710554 100644 --- a/Surface.h +++ b/Surface.h @@ -26,9 +26,9 @@ class cxxSurface:public cxxNumKeyword //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; - struct surface *cxxSurface2surface(); + struct surface *cxxSurface2surface(PHREEQC_PTR_ARG); - struct surf_comp *cxxSurfaceComp2surf_comp(); + struct surf_comp *cxxSurfaceComp2surf_comp(PHREEQC_PTR_ARG); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 97cd7754..013894b7 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -64,27 +64,27 @@ cxxSurfaceCharge::~cxxSurfaceCharge() { } -struct master * -cxxSurfaceCharge::get_psi_master() -{ - struct master *master_ptr = NULL; - std::string str = this->name; - - str.append("_psi"); - master_ptr = master_bsearch(str.c_str()); - if (master_ptr == NULL) - { - std::ostringstream error_oss; - error_oss << "Surface charge psi_master not found." << this-> - name << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); - } - return (master_ptr); -} +//struct master * +//cxxSurfaceCharge::get_psi_master() +//{ +// struct master *master_ptr = NULL; +// std::string str = this->name; +// +// str.append("_psi"); +// master_ptr = master_bsearch(str.c_str()); +// if (master_ptr == NULL) +// { +// std::ostringstream error_oss; +// error_oss << "Surface charge psi_master not found." << this-> +// name << std::endl; +// //Utilities::error_msg(error_oss.str(), CONTINUE); +// error_msg(error_oss.str().c_str(), CONTINUE); +// } +// return (master_ptr); +//} struct surface_charge * -cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el) +cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el) // // Builds surface_charge structure from of cxxSurfaceCharge // @@ -93,13 +93,13 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSur (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); if (surf_charge_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin(); it != el.end(); ++it) { - surf_charge_ptr[i].name = string_hsave((*it).second.name.c_str()); + surf_charge_ptr[i].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); assert((*it).second.name.size() > 0); surf_charge_ptr[i].specific_area = (*it).second.specific_area; surf_charge_ptr[i].grams = (*it).second.grams; @@ -114,7 +114,7 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSur surf_charge_ptr[i].sigma1 = 0; surf_charge_ptr[i].sigma2 = 0; surf_charge_ptr[i].sigmaddl = 0; - surf_charge_ptr[i].diffuse_layer_totals = (*it).second.diffuse_layer_totals.elt_list(); + surf_charge_ptr[i].diffuse_layer_totals = (*it).second.diffuse_layer_totals.elt_list(P_INSTANCE); //surf_charge_ptr[i].psi_master = it->get_psi_master(); surf_charge_ptr[i].count_g = 0; surf_charge_ptr[i].g = NULL; diff --git a/SurfaceCharge.h b/SurfaceCharge.h index bb24db33..37da563b 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -8,6 +8,7 @@ #include // std::vector #include "NameDouble.h" +#include "Phreeqc_class.h" class cxxSurfaceCharge { @@ -21,7 +22,7 @@ public: struct master *get_psi_master(); - static struct surface_charge *cxxSurfaceCharge2surface_charge(std::map < std::string, cxxSurfaceCharge > &el); + static struct surface_charge *cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 5e7fc69d..a0059c18 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -65,7 +65,7 @@ cxxSurfaceComp::~cxxSurfaceComp() } struct master * - cxxSurfaceComp::get_master() + cxxSurfaceComp::get_master(PHREEQC_PTR_ARG) { struct master *master_ptr = NULL; //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { @@ -73,16 +73,16 @@ struct master * it != this->totals.end(); it++) { /* Find master species */ - char *eltName = string_hsave(it->first.c_str()); + char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); assert(it->first.size() > 0); - struct element *elt_ptr = element_store(eltName); + struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); if (elt_ptr->master == NULL) { std::ostringstream error_oss; error_oss << "Master species not in data base for " << elt_ptr-> name << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != SURF) @@ -97,7 +97,7 @@ struct master * "Surface formula does not contain an surface master species, " << this->formula << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); } return (master_ptr); } diff --git a/SurfaceComp.h b/SurfaceComp.h index f0e28241..f445f76a 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -18,7 +18,7 @@ public: cxxSurfaceComp(struct surface_comp *); ~cxxSurfaceComp(); - struct master *get_master(); + struct master *get_master(PHREEQC_PTR_ARG); const std::string &get_phase_name() const; void set_phase_name(char * f); const std::string &get_rate_name() const; diff --git a/Temperature.cxx b/Temperature.cxx index 86dce37b..7aa223e0 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -73,16 +73,16 @@ cxxTemperature::~cxxTemperature() struct temperature * -cxxTemperature::cxxTemperature2temperature() +cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) // // Builds a temperature structure from instance of cxxTemperature // { struct temperature *temperature_ptr; temperature_ptr = - (struct temperature *) PHRQ_malloc(sizeof(struct temperature)); + (struct temperature *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct temperature)); if (temperature_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); temperature_ptr->description = this->get_description(); temperature_ptr->n_user = this->n_user; @@ -96,7 +96,7 @@ cxxTemperature::cxxTemperature2temperature() (double *) PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); if (temperature_ptr->t == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); } if (this->equalIncrements) diff --git a/Temperature.h b/Temperature.h index a34818f6..b87a1079 100644 --- a/Temperature.h +++ b/Temperature.h @@ -8,6 +8,7 @@ #include // std::vector #include "NumKeyword.h" +#include "Phreeqc_class.h" class cxxTemperature:public cxxNumKeyword { @@ -17,7 +18,7 @@ class cxxTemperature:public cxxNumKeyword cxxTemperature(struct temperature *); ~cxxTemperature(); - struct temperature *cxxTemperature2temperature(); + struct temperature *cxxTemperature2temperature(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; diff --git a/phreeqc_class.h b/phreeqc_class.h new file mode 100644 index 00000000..d4fc1a7e --- /dev/null +++ b/phreeqc_class.h @@ -0,0 +1,15 @@ +#if !defined PHREEQC_CLASS +#define P_INSTANCE +#define P_INSTANCE_COMMA +#define P_INSTANCE_POINTER +#define PHREEQC_PTR_ARG +#define PHREEQC_PTR_ARG_COMMA +#else +#define P_INSTANCE p_instance +#define P_INSTANCE_COMMA p_instance, +#define P_INSTANCE_POINTER p_instance-> +#define PHREEQC_PTR_ARG Phreeqc *p_instance +#define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance, +#endif + +//#include "Phreeqc_class.h" \ No newline at end of file From 9f4eefd21493fad48e5b92904330d7af1a4fa2bb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Dec 2009 18:09:39 +0000 Subject: [PATCH 0122/1077] Made all the changes to add phreeqc pointer as argument to Phreeqcpp class methods. Still compiles on Debug and Release, but problem with phrq_malloc in cvdense and cvode. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3876 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 46 +++++----- ExchComp.h | 8 +- Exchange.cxx | 74 ++++++++-------- Exchange.h | 10 +-- GasPhase.cxx | 28 +++--- GasPhase.h | 10 +-- ISolution.cxx | 28 +++--- ISolution.h | 6 +- KineticsComp.cxx | 14 +-- KineticsComp.h | 4 +- NameDouble.cxx | 24 +++--- NameDouble.h | 9 +- PPassemblage.cxx | 26 +++--- PPassemblage.h | 10 +-- PPassemblageComp.cxx | 22 ++--- PPassemblageComp.h | 8 +- Phreeqc.h | 85 +++++++++++++------ Reaction.cxx | 8 +- Reaction.h | 2 +- ReadClass.cxx | 66 +++++++-------- SSassemblage.cxx | 8 +- SSassemblage.h | 4 +- SSassemblageSS.cxx | 4 +- SSassemblageSS.h | 2 +- Solution.cxx | 14 +-- Solution.h | 2 +- StorageBin.cxx | 198 +++++++++++++++++++++---------------------- StorageBin.h | 12 +-- Surface.cxx | 27 +++--- Surface.h | 6 +- SurfaceCharge.cxx | 4 +- SurfaceCharge.h | 2 +- SurfaceComp.cxx | 48 +++++------ SurfaceComp.h | 12 +-- System.cxx | 10 +-- System.h | 39 ++++++--- cxxKinetics.cxx | 24 +++--- cxxKinetics.h | 4 +- cxxMix.cxx | 6 +- cxxMix.h | 4 +- phreeqc_class.h | 8 +- 41 files changed, 490 insertions(+), 436 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 536c190f..75f4bb02 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -129,7 +129,7 @@ cxxExchComp::~cxxExchComp() } struct master * -cxxExchComp::get_master() +cxxExchComp::get_master(PHREEQC_PTR_ARG) { struct master *master_ptr = NULL; for (std::map < std::string, double >::iterator it = @@ -137,16 +137,16 @@ cxxExchComp::get_master() { /* Find master species */ - char *eltName = string_hsave(it->first.c_str()); + char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); assert(it->first.size() != 0); - struct element *elt_ptr = element_store(eltName); + struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); if (elt_ptr->master == NULL) { std::ostringstream error_oss; error_oss << "Master species not in data base for " << elt_ptr-> name << std::endl; //Utilities::error_msg(error_oss.str(), STOP); - error_msg(error_oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != EX) @@ -161,16 +161,16 @@ cxxExchComp::get_master() { /* Find master species */ - char *eltName = string_hsave(it->first.c_str()); + char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); assert(it->first.size() != 0); - struct element *elt_ptr = element_store(eltName); + struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); if (elt_ptr->master == NULL) { std::ostringstream error_oss; error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; //Utilities::error_msg(error_oss.str(), STOP); - error_msg(error_oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != EX) @@ -186,7 +186,7 @@ cxxExchComp::get_master() "Exchange formula does not contain an exchange master species, " << this->formula << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); std::ostringstream oss; this->dump_raw(oss, 0); @@ -197,7 +197,7 @@ cxxExchComp::get_master() } struct exch_comp * - cxxExchComp::cxxExchComp2exch_comp(std::map < std::string, cxxExchComp > &el) + cxxExchComp::cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > &el) // // Builds exch_comp structure from of cxxExchComp // @@ -206,7 +206,7 @@ struct exch_comp * (struct exch_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); if (exch_comp_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxExchComp >::iterator it = el.begin(); it != el.end(); @@ -215,23 +215,23 @@ struct exch_comp * if ((*it).second.formula.size() == 0) exch_comp_ptr[i].formula = NULL; else - exch_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str()); + exch_comp_ptr[i].formula = P_INSTANCE_POINTER string_hsave((*it).second.formula.c_str()); exch_comp_ptr[i].formula_z = (*it).second.formula_z; - exch_comp_ptr[i].totals = (*it).second.totals.elt_list(); + exch_comp_ptr[i].totals = (*it).second.totals.elt_list(P_INSTANCE); exch_comp_ptr[i].moles = (*it).second.moles; - exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); + exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(P_INSTANCE); exch_comp_ptr[i].la = (*it).second.la; exch_comp_ptr[i].charge_balance = (*it).second.charge_balance; if ((*it).second.phase_name.size() == 0) exch_comp_ptr[i].phase_name = NULL; else - exch_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str()); + exch_comp_ptr[i].phase_name = P_INSTANCE_POINTER string_hsave((*it).second.phase_name.c_str()); exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; if ((*it).second.rate_name.size() == 0) exch_comp_ptr[i].rate_name = NULL; else - exch_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); - exch_comp_ptr[i].master = (*it).second.get_master(); + exch_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); + exch_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); i++; } return (exch_comp_ptr); @@ -333,7 +333,7 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchComp::read_raw(CParser & parser, bool check) +cxxExchComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { std::string str; @@ -486,7 +486,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) break; case 8: // totals - if (this->totals.read_raw(parser, next_char) != + if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -499,7 +499,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) break; case 9: // formula_totals - if (this->formula_totals.read_raw(parser, next_char) != + if (this->formula_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -550,7 +550,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) } } void -cxxExchComp::add(const cxxExchComp & addee, double extensive) +cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensive) { double ext1, ext2, f1, f2; if (extensive == 0.0) @@ -602,7 +602,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) oss << "Can not mix two exchange components with same formula and different related phases, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; return; } @@ -618,7 +618,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; return; } @@ -635,7 +635,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; return; } diff --git a/ExchComp.h b/ExchComp.h index 68d21791..c0d28193 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -17,16 +17,16 @@ class cxxExchComp cxxExchComp(struct exch_comp *); ~cxxExchComp(); - struct master *get_master(); + struct master *get_master(PHREEQC_PTR_ARG); - static struct exch_comp *cxxExchComp2exch_comp(std::map < std::string, cxxExchComp > + static struct exch_comp *cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check=true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check=true); const std::string &get_formula() const { @@ -132,7 +132,7 @@ class cxxExchComp }; - void add(const cxxExchComp & comp, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & comp, double extensive); void multiply(double extensive); diff --git a/Exchange.cxx b/Exchange.cxx index fd48ed16..5a953873 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -58,7 +58,7 @@ cxxNumKeyword() } -cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities, +cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, cxxMix & mix, int n_user): cxxNumKeyword() { @@ -75,7 +75,7 @@ cxxNumKeyword() { const cxxExchange *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); + this->add(P_INSTANCE_COMMA *entity_ptr, it->second); this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; } #ifdef SKIP @@ -92,7 +92,7 @@ cxxNumKeyword() } } -cxxExchange::cxxExchange(int n_user) +cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user) // // constructor for cxxExchange from reaction calculation // equivalent of xexchange_save @@ -108,61 +108,61 @@ cxxNumKeyword() this->n_user = n_user; this->n_user_end = n_user; this->pitzer_exchange_gammas = - (use.exchange_ptr->pitzer_exchange_gammas == TRUE); + (P_INSTANCE_POINTER use.exchange_ptr->pitzer_exchange_gammas == TRUE); this->totals.type = cxxNameDouble::ND_ELT_MOLES; - for (i = 0; i < count_unknowns; i++) + for (i = 0; i < P_INSTANCE_POINTER count_unknowns; i++) { - if (x[i]->type == EXCH) + if (P_INSTANCE_POINTER x[i]->type == EXCH) { cxxExchComp ec; //char * formula; - ec.set_formula(x[i]->exch_comp->formula); + ec.set_formula(P_INSTANCE_POINTER x[i]->exch_comp->formula); //double moles; ec.set_moles(0.0); //cxxNameDouble formula_totals; - ec.set_formula_totals(x[i]->exch_comp->formula_totals); + ec.set_formula_totals(P_INSTANCE_POINTER x[i]->exch_comp->formula_totals); //cxxNameDouble totals; see below //double la; - ec.set_la(x[i]->master[0]->s->la); + ec.set_la(P_INSTANCE_POINTER x[i]->master[0]->s->la); //double charge_balance; see below //char *phase_name; - ec.set_phase_name(x[i]->exch_comp->phase_name); + ec.set_phase_name(P_INSTANCE_POINTER x[i]->exch_comp->phase_name); //double phase_proportion; - ec.set_phase_proportion(x[i]->exch_comp->phase_proportion); + ec.set_phase_proportion(P_INSTANCE_POINTER x[i]->exch_comp->phase_proportion); //char *rate_name; - ec.set_rate_name(x[i]->exch_comp->rate_name); + ec.set_rate_name(P_INSTANCE_POINTER x[i]->exch_comp->rate_name); //double formula_z; - ec.set_formula_z(x[i]->exch_comp->formula_z); + ec.set_formula_z(P_INSTANCE_POINTER x[i]->exch_comp->formula_z); // calculate charge and totals - count_elts = 0; - paren_count = 0; + P_INSTANCE_POINTER count_elts = 0; + P_INSTANCE_POINTER paren_count = 0; double charge = 0.0; int j; - for (j = 0; j < count_species_list; j++) + for (j = 0; j < P_INSTANCE_POINTER count_species_list; j++) { - if (species_list[j].master_s == x[i]->master[0]->s) + if (P_INSTANCE_POINTER species_list[j].master_s == P_INSTANCE_POINTER x[i]->master[0]->s) { - add_elt_list(species_list[j].s->next_elt, - species_list[j].s->moles); - charge += species_list[j].s->moles * species_list[j].s->z; + P_INSTANCE_POINTER add_elt_list(P_INSTANCE_POINTER species_list[j].s->next_elt, + P_INSTANCE_POINTER species_list[j].s->moles); + charge += P_INSTANCE_POINTER species_list[j].s->moles * P_INSTANCE_POINTER species_list[j].s->z; } } // Keep exchanger related to phase even if none currently in solution - if (x[i]->exch_comp->phase_name != NULL && count_elts == 0) + if (P_INSTANCE_POINTER x[i]->exch_comp->phase_name != NULL && P_INSTANCE_POINTER count_elts == 0) { - add_elt_list(x[i]->master[0]->s->next_elt, 1e-20); + P_INSTANCE_POINTER add_elt_list(P_INSTANCE_POINTER x[i]->master[0]->s->next_elt, 1e-20); } //double charge_balance ec.set_charge_balance(charge); //cxxNameDouble totals; - if (count_elts > 0) + if (P_INSTANCE_POINTER count_elts > 0) { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); + qsort(P_INSTANCE_POINTER elt_list, (size_t) P_INSTANCE_POINTER count_elts, + (size_t) sizeof(struct elt_list), P_INSTANCE_POINTER elt_list_compare); + P_INSTANCE_POINTER elt_list_combine(); } - ec.set_totals(elt_list, count_elts); + ec.set_totals(P_INSTANCE_POINTER elt_list, P_INSTANCE_POINTER count_elts); // add to comp list std::string str(ec.get_formula()); @@ -202,12 +202,12 @@ cxxExchange::get_related_rate() } struct exchange * -cxxExchange::cxxExchange2exchange() +cxxExchange::cxxExchange2exchange(PHREEQC_PTR_ARG) // // Builds a exchange structure from instance of cxxExchange // { - struct exchange *exchange_ptr = exchange_alloc(); + struct exchange *exchange_ptr = P_INSTANCE_POINTER exchange_alloc(); exchange_ptr->description = this->get_description(); exchange_ptr->n_user = this->n_user; @@ -219,8 +219,8 @@ cxxExchange::cxxExchange2exchange() exchange_ptr->related_rate = (int) this->get_related_rate(); exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; exchange_ptr->count_comps = (int) this->exchComps.size(); - exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps); - exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); + exchange_ptr->comps = (struct exch_comp *) P_INSTANCE_POINTER free_check_null(exchange_ptr->comps); + exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(P_INSTANCE_COMMA this->exchComps); return (exchange_ptr); } @@ -294,7 +294,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchange::read_raw(CParser & parser, bool check) +cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -387,7 +387,7 @@ cxxExchange::read_raw(CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(parser, false); + ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); @@ -396,12 +396,12 @@ cxxExchange::read_raw(CParser & parser, bool check) if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) { cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; - comp.read_raw(reread, false); + comp.read_raw(P_INSTANCE_COMMA reread, false); } else { cxxExchComp ec1; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_formula()); this->exchComps[str] = ec1; } @@ -463,7 +463,7 @@ cxxExchange::add(const cxxExchange & addee, double extensive) } #endif void -cxxExchange::add(const cxxExchange & addee, double extensive) +cxxExchange::add(PHREEQC_PTR_ARG_COMMA const cxxExchange & addee, double extensive) // // Add existing exchange to "this" exchange // @@ -477,7 +477,7 @@ cxxExchange::add(const cxxExchange & addee, double extensive) std::map < std::string, cxxExchComp >::iterator it = this->exchComps.find((*itadd).first); if (it != this->exchComps.end()) { - (*it).second.add((*itadd).second, extensive); + (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); //bool found = false; //for (std::list < cxxExchComp >::iterator it = this->exchComps.begin(); // it != this->exchComps.end(); ++it) diff --git a/Exchange.h b/Exchange.h index c3b0660d..3c47415f 100644 --- a/Exchange.h +++ b/Exchange.h @@ -15,19 +15,19 @@ class cxxExchange:public cxxNumKeyword public: cxxExchange(); - cxxExchange(int n_user); + cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user); cxxExchange(struct exchange *); - cxxExchange(const std::map < int, cxxExchange > &exchange_map, + cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &exchange_map, cxxMix & mx, int n_user); ~cxxExchange(); - struct exchange *cxxExchange2exchange(); + struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); struct exch_comp *cxxExchComp2exch_comp(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); bool get_related_phases(void); @@ -46,7 +46,7 @@ public: void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif private: - void add(const cxxExchange & addee, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxExchange & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/GasPhase.cxx b/GasPhase.cxx index 5315b838..b54ed69d 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -69,7 +69,7 @@ cxxNumKeyword() gas_phase_ptr->comps[i].moles; } } -cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, +cxxGasPhase::cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entities, cxxMix & mix, int n_user): cxxNumKeyword() { @@ -108,7 +108,7 @@ cxxNumKeyword() { std::ostringstream oss; oss << "Can not mix two gas_phases with differing types."; - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; return; } @@ -125,7 +125,7 @@ cxxGasPhase::~cxxGasPhase() } struct gas_comp * -cxxGasPhase::cxxGasPhaseComp2gas_comp() +cxxGasPhase::cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG) { //struct gas_comp *gas_comp_ptr(NULL); struct gas_comp *gas_comp_ptr = NULL; @@ -139,13 +139,13 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp() (this->gasPhaseComps.size() * sizeof(struct gas_comp))); if (gas_comp_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); it != this->gasPhaseComps.end(); it++) { - gas_comp_ptr[i].name = string_hsave(it->first.c_str()); + gas_comp_ptr[i].name = P_INSTANCE_POINTER string_hsave(it->first.c_str()); assert(it->first.size() != 0); - gas_comp_ptr[i].phase = phase_bsearch(it->first.c_str(), &n, TRUE); + gas_comp_ptr[i].phase = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &n, TRUE); gas_comp_ptr[i].p_read = 0; gas_comp_ptr[i].moles = it->second; gas_comp_ptr[i].initial_moles = 0; @@ -156,12 +156,12 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp() } struct gas_phase * -cxxGasPhase::cxxGasPhase2gas_phase() +cxxGasPhase::cxxGasPhase2gas_phase(PHREEQC_PTR_ARG) // // Builds a gas_phase structure from instance of cxxGasPhase // { - struct gas_phase *gas_phase_ptr = gas_phase_alloc(); + struct gas_phase *gas_phase_ptr = P_INSTANCE_POINTER gas_phase_alloc(); gas_phase_ptr->description = this->get_description(); gas_phase_ptr->n_user = this->n_user; @@ -184,8 +184,8 @@ cxxGasPhase::cxxGasPhase2gas_phase() // comps gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size(); gas_phase_ptr->comps = - (struct gas_comp *) free_check_null(gas_phase_ptr->comps); - gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(); + (struct gas_comp *) P_INSTANCE_POINTER free_check_null(gas_phase_ptr->comps); + gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(P_INSTANCE); return (gas_phase_ptr); } @@ -261,7 +261,7 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxGasPhase::read_raw(CParser & parser, bool check) +cxxGasPhase::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { int i; @@ -361,7 +361,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) break; case 3: // component - if (this->gasPhaseComps.read_raw(parser, next_char) != + if (this->gasPhaseComps.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -445,7 +445,7 @@ cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxGasPhase::totalize() +cxxGasPhase::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures @@ -454,7 +454,7 @@ cxxGasPhase::totalize() { struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + phase_ptr = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/GasPhase.h b/GasPhase.h index 8cfe5759..3aa5a430 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -17,7 +17,7 @@ class cxxGasPhase:public cxxNumKeyword public: cxxGasPhase(); cxxGasPhase(struct gas_phase *); - cxxGasPhase(const std::map < int, cxxGasPhase > &entity_map, + cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entity_map, cxxMix & mx, int n_user); ~cxxGasPhase(); @@ -27,22 +27,22 @@ class cxxGasPhase:public cxxNumKeyword GP_VOLUME = 1 }; - struct gas_phase *cxxGasPhase2gas_phase(); + struct gas_phase *cxxGasPhase2gas_phase(PHREEQC_PTR_ARG); - struct gas_comp *cxxGasPhaseComp2gas_comp(); + struct gas_comp *cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - void totalize(); + void totalize(PHREEQC_PTR_ARG); const cxxNameDouble & get_totals() const { diff --git a/ISolution.cxx b/ISolution.cxx index 2b5e4745..d3e67075 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -38,7 +38,7 @@ units("mMol/kgw") pes = NULL; } -cxxISolution::cxxISolution(struct solution *solution_ptr): +cxxISolution::cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *solution_ptr): cxxSolution(solution_ptr) //, pe(cxxPe_Data::alloc()) { @@ -53,39 +53,39 @@ cxxSolution(solution_ptr) } default_pe = solution_ptr->default_pe; // pe_data - pes = pe_data_dup(solution_ptr->pe); + pes = P_INSTANCE_POINTER pe_data_dup(solution_ptr->pe); } cxxISolution::~cxxISolution() { - pe_data_free(this->pes); + //// ToDo //pe_data_free(this->pes); } struct solution * -cxxISolution::cxxISolution2solution() +cxxISolution::cxxISolution2solution(PHREEQC_PTR_ARG) // // Builds a solution structure from instance of cxxISolution // { - struct solution *soln_ptr = this->cxxSolution2solution(); + struct solution *soln_ptr = this->cxxSolution2solution(P_INSTANCE); soln_ptr->new_def = TRUE; soln_ptr->density = this->density; if (this->units.size() == 0) soln_ptr->units = NULL; else - soln_ptr->units = string_hsave(this->units.c_str()); + soln_ptr->units = P_INSTANCE_POINTER string_hsave(this->units.c_str()); soln_ptr->default_pe = this->default_pe; // pe - soln_ptr->pe = (struct pe_data *) pe_data_free(soln_ptr->pe); - soln_ptr->pe = pe_data_dup(this->pes); + soln_ptr->pe = (struct pe_data *) P_INSTANCE_POINTER pe_data_free(soln_ptr->pe); + soln_ptr->pe = P_INSTANCE_POINTER pe_data_dup(this->pes); // totals - soln_ptr->totals = (struct conc *) free_check_null(soln_ptr->totals); - soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(this->comps); + soln_ptr->totals = (struct conc *) P_INSTANCE_POINTER free_check_null(soln_ptr->totals); + soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(P_INSTANCE_COMMA this->comps); return (soln_ptr); } void -cxxISolution::ConvertUnits() +cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) // // Converts from input units to moles per kilogram water // @@ -96,7 +96,7 @@ cxxISolution::ConvertUnits() this->comps.begin(); for (; iter != this->comps.end(); ++iter) { - struct master *master_ptr = master_bsearch(iter->first.c_str()); + struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(iter->first.c_str()); if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; @@ -117,7 +117,7 @@ cxxISolution::ConvertUnits() * Convert to moles */ //set gfw for element - iter->second.set_gfw(); + iter->second.set_gfw(P_INSTANCE); // convert to moles if (iter->second.get_units().find("g/") != std::string::npos) { @@ -130,7 +130,7 @@ cxxISolution::ConvertUnits() std::ostringstream oss; oss << "Could not find gfw, " << iter->second. get_description(); - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; } } diff --git a/ISolution.h b/ISolution.h index 2c9db096..417708b0 100644 --- a/ISolution.h +++ b/ISolution.h @@ -20,7 +20,7 @@ class cxxISolution:public cxxSolution public: cxxISolution(); - cxxISolution(struct solution *); + cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *); //cxxISolution(const cxxISolution&); ~cxxISolution(); @@ -28,7 +28,7 @@ class cxxISolution:public cxxSolution //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - struct solution *cxxISolution2solution(); + struct solution *cxxISolution2solution(PHREEQC_PTR_ARG); double get_density() const { @@ -59,7 +59,7 @@ class cxxISolution:public cxxSolution //void dump_xml(std::ostream& os, unsigned int indent = 0)const; - void ConvertUnits(); + void ConvertUnits(PHREEQC_PTR_ARG); #ifdef ORCHESTRA void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 959ab182..607ad3ec 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -59,7 +59,7 @@ cxxKineticsComp::~cxxKineticsComp() } struct kinetics_comp * - cxxKineticsComp::cxxKineticsComp2kinetics_comp(std::map < std::string, cxxKineticsComp > + cxxKineticsComp::cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxKineticsComp > &el) // // Builds kinetics_comp structure from of cxxKineticsComp @@ -69,7 +69,7 @@ struct kinetics_comp * (struct kinetics_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); if (kinetics_comp_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxKineticsComp >::iterator it = el.begin(); @@ -78,8 +78,8 @@ struct kinetics_comp * if ((*it).second.rate_name.size() == 0) kinetics_comp_ptr[i].rate_name = NULL; else - kinetics_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); - kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef(); + kinetics_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); + kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef(P_INSTANCE); kinetics_comp_ptr[i].count_list = (int) (*it).second.namecoef.size(); kinetics_comp_ptr[i].tol = (*it).second.tol; kinetics_comp_ptr[i].m = (*it).second.m; @@ -100,7 +100,7 @@ struct kinetics_comp * kinetics_comp_ptr[i].d_params = (double *) PHRQ_malloc((size_t) ((*it).second.d_params.size() * sizeof(double))); if (kinetics_comp_ptr[i].d_params == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); std::copy((*it).second.d_params.begin(), (*it).second.d_params.end(), kinetics_comp_ptr[i].d_params); } @@ -205,7 +205,7 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKineticsComp::read_raw(CParser & parser, bool check) +cxxKineticsComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { std::string str; double d; @@ -321,7 +321,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case 5: // namecoef - if (this->namecoef.read_raw(parser, next_char) != + if (this->namecoef.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/KineticsComp.h b/KineticsComp.h index d66bccdb..754034d7 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -17,13 +17,13 @@ public: cxxKineticsComp(struct kinetics_comp *); ~cxxKineticsComp(); - static struct kinetics_comp *cxxKineticsComp2kinetics_comp(std::map < std::string, cxxKineticsComp > &el); + static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxKineticsComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); const std::string &get_rate_name() const { diff --git a/NameDouble.cxx b/NameDouble.cxx index 9f0f8760..5cc671f6 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -157,7 +157,7 @@ cxxNameDouble::elt_list(PHREEQC_PTR_ARG) } struct master_activity * -cxxNameDouble::master_activity() const +cxxNameDouble::master_activity(PHREEQC_PTR_ARG) const // // Builds a list of master_activity structures from instance of cxxNameDouble // @@ -180,7 +180,7 @@ cxxNameDouble::master_activity() const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = string_hsave(it->first.c_str()); + master_activity_ptr[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); master_activity_ptr[i].la = it->second; i++; } @@ -197,11 +197,11 @@ cxxNameDouble::master_activity() const (((*this).size()) * sizeof(struct master_activity))); if (master_activity_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { - master_activity_ptr[i].description = string_hsave(it->first.c_str()); + master_activity_ptr[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); master_activity_ptr[i].la = it->second; i++; } @@ -216,7 +216,7 @@ cxxNameDouble::master_activity() const } struct conc * -cxxNameDouble::conc() const +cxxNameDouble::conc(PHREEQC_PTR_ARG) const // for Solutions, not ISolutions // takes a map of (elt name, moles) // returns list of conc structures @@ -226,11 +226,11 @@ cxxNameDouble::conc() const c = (struct conc *) PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); if (c == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - c[i].description = string_hsave(it->first.c_str()); + c[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); c[i].moles = it->second; c[i].input_conc = it->second; c[i].units = NULL; @@ -248,7 +248,7 @@ cxxNameDouble::conc() const } struct name_coef * -cxxNameDouble::name_coef() const +cxxNameDouble::name_coef(PHREEQC_PTR_ARG) const // // Builds a name_coef structure from instance of cxxNameDouble // @@ -258,11 +258,11 @@ cxxNameDouble::name_coef() const (struct name_coef *) PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef))); if (name_coef_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) { - name_coef_ptr[i].name = string_hsave(it->first.c_str()); + name_coef_ptr[i].name = P_INSTANCE_POINTER string_hsave(it->first.c_str()); name_coef_ptr[i].coef = it->second; i++; } @@ -331,7 +331,7 @@ cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const } } -CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, +CParser::STATUS_TYPE cxxNameDouble::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, std::istream::pos_type & pos) { std::string token; @@ -353,7 +353,7 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, { return CParser::PARSER_ERROR; } - ctoken = string_hsave(token.c_str()); + ctoken = P_INSTANCE_POINTER string_hsave(token.c_str()); (*this)[ctoken] = d; return CParser::PARSER_OK; } diff --git a/NameDouble.h b/NameDouble.h index 2fee9087..470585d4 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -8,6 +8,7 @@ #include // std::list #include // std::vector #include "Phreeqc_class.h" +class Phreeqc; #include "Parser.h" class cxxNameDouble:public @@ -37,13 +38,13 @@ class cxxNameDouble:public elt_list(PHREEQC_PTR_ARG); struct master_activity * - master_activity() const; + master_activity(PHREEQC_PTR_ARG) const; struct conc * - conc() const; + conc(PHREEQC_PTR_ARG) const; struct name_coef * - name_coef() const; + name_coef(PHREEQC_PTR_ARG) const; void dump_xml(std::ostream & s_oss, unsigned int indent) const; @@ -52,7 +53,7 @@ class cxxNameDouble:public dump_raw(std::ostream & s_oss, unsigned int indent) const; CParser::STATUS_TYPE - read_raw(CParser & parser, std::istream::pos_type & pos); + read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, std::istream::pos_type & pos); void add_extensive(const cxxNameDouble & old, double factor); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index a4c9f8d7..9b99490c 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -53,7 +53,7 @@ eltList(pp_assemblage_ptr->next_elt) this->ppAssemblageComps[str] = ppComp; } } -cxxPPassemblage::cxxPPassemblage(const std::map < int, +cxxPPassemblage::cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, int n_user): cxxNumKeyword() @@ -71,7 +71,7 @@ cxxNumKeyword() { const cxxPPassemblage *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); + this->add(P_INSTANCE_COMMA *entity_ptr, it->second); } } } @@ -81,12 +81,12 @@ cxxPPassemblage::~cxxPPassemblage() } struct pp_assemblage * -cxxPPassemblage::cxxPPassemblage2pp_assemblage() +cxxPPassemblage::cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG) // // Builds a pp_assemblage structure from instance of cxxPPassemblage // { - struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); + struct pp_assemblage *pp_assemblage_ptr = P_INSTANCE_POINTER pp_assemblage_alloc(); pp_assemblage_ptr->description = this->get_description(); pp_assemblage_ptr->n_user = this->n_user; @@ -94,10 +94,10 @@ cxxPPassemblage::cxxPPassemblage2pp_assemblage() pp_assemblage_ptr->new_def = FALSE; pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size(); pp_assemblage_ptr->pure_phases = - (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); + (struct pure_phase *) P_INSTANCE_POINTER free_check_null(pp_assemblage_ptr->pure_phases); pp_assemblage_ptr->pure_phases = - cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(this->ppAssemblageComps); - pp_assemblage_ptr->next_elt = this->eltList.elt_list(); + cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(P_INSTANCE_COMMA this->ppAssemblageComps); + pp_assemblage_ptr->next_elt = this->eltList.elt_list(P_INSTANCE); return (pp_assemblage_ptr); } @@ -168,7 +168,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxPPassemblage::read_raw(CParser & parser, bool check) +cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -221,7 +221,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) break; case 0: // eltList - if (this->eltList.read_raw(parser, next_char) != + if (this->eltList.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -340,21 +340,21 @@ cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void -cxxPPassemblage::totalize() +cxxPPassemblage::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures for (std::map < std::string, cxxPPassemblageComp >::iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { - (*it).second.totalize(); + (*it).second.totalize(P_INSTANCE); this->totals.add_extensive((*it).second.get_totals(), 1.0); } return; } void -cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) +cxxPPassemblage::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double extensive) // // Add to existing ppassemblage to "this" ppassemblage // @@ -372,7 +372,7 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) { if ((*it).second.get_name() == itadd->second.get_name()) { - (*it).second.add((*itadd).second, extensive); + (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); found = true; break; } diff --git a/PPassemblage.h b/PPassemblage.h index 50a93c0b..39c5be94 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -17,17 +17,17 @@ class cxxPPassemblage:public cxxNumKeyword public: cxxPPassemblage(); cxxPPassemblage(struct pp_assemblage *); - cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map, + cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entity_map, cxxMix & mx, int n_user); ~cxxPPassemblage(); - struct pp_assemblage *cxxPPassemblage2pp_assemblage(); + struct pp_assemblage *cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG); struct pure_phase *cxxPPassemblageComp2pure_phase(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); const cxxNameDouble & get_totals() const { @@ -39,7 +39,7 @@ class cxxPPassemblage:public cxxNumKeyword void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - void totalize(); + void totalize(PHREEQC_PTR_ARG); #ifdef ORCHESTRA void ORCH_write_chemistry(std::ostream & chemistry_dat); void ORCH_write_output_vars(std::ostream & outstream); @@ -51,7 +51,7 @@ class cxxPPassemblage:public cxxNumKeyword #endif private: - void add(const cxxPPassemblage & addee, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 9af0b3e9..bacf9aee 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -60,14 +60,14 @@ cxxPPassemblageComp::~cxxPPassemblageComp() } struct phase * -cxxPPassemblageComp::get_phase() +cxxPPassemblageComp::get_phase(PHREEQC_PTR_ARG) { int i; - return phase_bsearch(this->name.c_str(), &i, FALSE); + return P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &i, FALSE); } struct pure_phase * - cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(std::map < std::string, cxxPPassemblageComp > &el) +cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxPPassemblageComp > &el) // // Builds pure_phase structure from of cxxPPassemblageComp // @@ -76,21 +76,21 @@ struct pure_phase * (struct pure_phase *) PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); if (pure_phase_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxPPassemblageComp >::iterator it = el.begin(); it != el.end(); ++it) { - pure_phase_ptr[i].phase = (*it).second.get_phase(); + pure_phase_ptr[i].phase = (*it).second.get_phase(P_INSTANCE); if ((*it).second.name.size() == 0) pure_phase_ptr[i].name = NULL; else - pure_phase_ptr[i].name = string_hsave((*it).second.name.c_str()); + pure_phase_ptr[i].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); if ((*it).second.add_formula.size() == 0) pure_phase_ptr[i].add_formula = NULL; else - pure_phase_ptr[i].add_formula = string_hsave((*it).second.add_formula.c_str()); + pure_phase_ptr[i].add_formula = P_INSTANCE_POINTER string_hsave((*it).second.add_formula.c_str()); pure_phase_ptr[i].si = (*it).second.si; pure_phase_ptr[i].moles = (*it).second.moles; pure_phase_ptr[i].delta = (*it).second.delta; @@ -437,7 +437,7 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void -cxxPPassemblageComp::totalize() +cxxPPassemblageComp::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures @@ -445,7 +445,7 @@ cxxPPassemblageComp::totalize() return; struct phase *phase_ptr; int l; - phase_ptr = phase_bsearch(this->name.c_str(), &l, FALSE); + phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); @@ -460,7 +460,7 @@ cxxPPassemblageComp::totalize() void -cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) +cxxPPassemblageComp::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & addee, double extensive) { double ext1, ext2, f1, f2; if (extensive == 0.0) @@ -496,7 +496,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) oss << "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; - error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); input_error++; return; } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index a220d31e..de4badcb 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -18,7 +18,7 @@ class cxxPPassemblageComp ~cxxPPassemblageComp(); - static struct pure_phase *cxxPPassemblageComp2pure_phase(std::map < std::string, cxxPPassemblageComp > &el); + static struct pure_phase *cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxPPassemblageComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -48,15 +48,15 @@ class cxxPPassemblageComp else this->add_formula.clear(); } - struct phase *get_phase(); + struct phase *get_phase(PHREEQC_PTR_ARG); - void totalize(); + void totalize(PHREEQC_PTR_ARG); const cxxNameDouble & get_totals() const { return (this->totals); }; - void add(const cxxPPassemblageComp & comp, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI diff --git a/Phreeqc.h b/Phreeqc.h index bea8d45c..7f13054e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -870,6 +870,7 @@ int dump_reaction(int k); int dump_s_s_assemblage(int k); int dump_solution(int k); int dump_surface(int k); +int dump_cpp(void); int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc); @@ -948,42 +949,56 @@ int copier_add(struct copier *copier_ptr, int n_user, int start, int end); int copier_free(struct copier *copier_ptr); int copier_init(struct copier *copier_ptr); CLASS_STATIC int element_compare(const void *ptr1, const void *ptr2); -struct element *element_store(const char *element); -int elt_list_combine(void); -CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); +private: struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); int elt_list_print(struct elt_list *elt_list_ptr); struct elt_list *elt_list_save(void); -struct exchange *exchange_alloc(void); -struct exchange *exchange_bsearch(int k, int *n); +public: + struct exchange *exchange_alloc(void); + struct exchange *exchange_bsearch(int k, int *n); +private: int exchange_comp_compare(const void *ptr1, const void *ptr2); void exchange_comp_init(struct exch_comp *exch_comp_ptr); -int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new); +public: + int exchange_copy(struct exchange *exchange_old_ptr, + struct exchange *exchange_new_ptr, int n_user_new); +private: CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); int exchange_copy_to_last(int n, int n_user); int exchange_delete(int n_user_old); int exchange_duplicate(int n_user_old, int n_user_new); int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, const char *description); -int exchange_free(struct exchange *exchange_ptr); +public: + int exchange_free(struct exchange *exchange_ptr); +private: int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new); struct exchange *exchange_search(int n_user, int *n, int print); int exchange_sort(void); CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); -struct gas_phase *gas_phase_alloc(void); -struct gas_phase *gas_phase_bsearch(int k, int *n); +public: + struct gas_phase *gas_phase_alloc(void); + struct gas_phase *gas_phase_bsearch(int k, int *n); +private: CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); +public: int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, struct gas_phase *gas_phase_new_ptr, int n_user_new); +private: int gas_phase_copy_to_last(int n, int n_user); int gas_phase_delete(int n_user_old); int gas_phase_duplicate(int n_user_old, int n_user_new); int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description); +public: int gas_phase_free(struct gas_phase *gas_phase_ptr); +private: int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new); struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, @@ -1004,19 +1019,25 @@ int irrev_duplicate(int n_user_old, int n_user_new); int irrev_free(struct irrev *irrev_ptr); struct irrev *irrev_search(int n_user, int *n); int irrev_sort(void); -struct kinetics *kinetics_alloc(void); -struct kinetics *kinetics_bsearch(int k, int *n); +public: + struct kinetics *kinetics_alloc(void); + struct kinetics *kinetics_bsearch(int k, int *n); +private: int kinetics_delete(int n_user_old); int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr); CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); +public: int kinetics_copy(struct kinetics *kinetics_old_ptr, struct kinetics *kinetics_new_ptr, int n_user_new); +private: int kinetics_copy_to_last(int n, int n_user); int kinetics_duplicate(int n_user_old, int n_user_new); int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description); +public: int kinetics_free(struct kinetics *kinetics_ptr); +private: int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new); @@ -1043,8 +1064,10 @@ int mix_free(struct mix *mix_ptr); struct mix *mix_search(int n_user, int *n, int print); int mix_sort(void); struct pe_data *pe_data_alloc(void); -struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); -struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +private: int pe_data_store(struct pe_data **pe, const char *token); public: struct phase *phase_bsearch(const char *ptr, int *j, int print); @@ -1052,16 +1075,22 @@ private: CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); int phase_delete(int i); struct phase *phase_store(char *name); +public: struct pp_assemblage *pp_assemblage_alloc(void); struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); +private: CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); +public: int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new); +private: int pp_assemblage_copy_to_last(int n, int n_user); int pp_assemblage_delete(int n_user_old); int pp_assemblage_duplicate(int n_user_old, int n_user_new); +public: int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); +private: int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description); int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, @@ -1087,17 +1116,20 @@ struct species *s_search(const char *name); struct species *s_store(char *name, LDBLE z, int replace_if_found); public: struct s_s_assemblage *s_s_assemblage_alloc(void); + struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); private: -struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); - -int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, +public: + int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new); +private: int s_s_assemblage_copy_to_last(int n, int n_user); int s_s_assemblage_duplicate(int n_user_old, int n_user_new); int s_s_assemblage_delete(int n_user_old); -int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); +public: + int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); +private: int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description); int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, @@ -1117,9 +1149,9 @@ int conc_init(struct conc *conc_ptr); CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); public: struct solution *solution_alloc(void); + struct solution *solution_bsearch(int k, int *n, int print); private: -struct solution *solution_bsearch(int k, int *n, int print); -struct solution *solution_copy(struct solution *solution_old_ptr, + struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); int solution_copy_to_last(int n, int n_user_new); int solution_duplicate(int n_user_old, int n_user_new); @@ -1136,20 +1168,24 @@ int species_list_sort(void); struct Change_Surf *change_surf_alloc(int count); public: struct surface *surface_alloc(void); + struct surface *surface_bsearch(int k, int *n); private: -struct surface *surface_bsearch(int k, int *n); struct master *surface_get_psi_master(const char *name, int plane); CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); int surface_charge_free(struct surface_charge *charge); CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); -int surface_copy(struct surface *surface_old_ptr, +public: + int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new); +private: int surface_copy_to_last(int n, int n_user); int surface_delete(int n_user_old); int surface_duplicate(int n_user_old, int n_user_new); -int surface_free(struct surface *surface_ptr); +public: + int surface_free(struct surface *surface_ptr); +private: int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description); int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); @@ -1315,8 +1351,9 @@ int mix_stag(int i, LDBLE stagkin_time, int punch, // utilities.c ------------------------------- - +public: int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); +private: int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: diff --git a/Reaction.cxx b/Reaction.cxx index 8449ee7a..e54bc249 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -91,7 +91,7 @@ cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) irrev_ptr->n_user = this->n_user; irrev_ptr->n_user_end = this->n_user_end; - irrev_ptr->list = this->reactantList.name_coef(); + irrev_ptr->list = this->reactantList.name_coef(P_INSTANCE); irrev_ptr->count_list = (int) this->reactantList.size(); if (this->elementList.size() > 0) { @@ -223,7 +223,7 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxReaction::read_raw(CParser & parser) +cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) { int j; @@ -296,7 +296,7 @@ cxxReaction::read_raw(CParser & parser) break; case 1: // reactant_list - if (this->reactantList.read_raw(parser, next_char) != + if (this->reactantList.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -308,7 +308,7 @@ cxxReaction::read_raw(CParser & parser) break; case 2: // element_list - if (this->elementList.read_raw(parser, next_char) != + if (this->elementList.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/Reaction.h b/Reaction.h index 8c011c35..46beb71d 100644 --- a/Reaction.h +++ b/Reaction.h @@ -24,7 +24,7 @@ class cxxReaction:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser); void set_units(const char * s) { diff --git a/ReadClass.cxx b/ReadClass.cxx index af43738c..ebd583ea 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -11,6 +11,7 @@ #else #include "Phreeqc.h" #endif +#include "Phreeqc_class.h" #include "Parser.h" #include "Solution.h" #include "Exchange.h" @@ -102,8 +103,8 @@ read_solution_raw(void) cxxSolution sol; - sol.read_raw(parser); - struct solution *soln_ptr = sol.cxxSolution2solution(); + sol.read_raw(PHREEQC_THIS_COMMA parser); + struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); int n; /* @@ -194,8 +195,8 @@ read_exchange_raw(void) parser.get_option(vopts, next_char); cxxExchange ex; - ex.read_raw(parser); - struct exchange *exchange_ptr = ex.cxxExchange2exchange(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); int n; /* @@ -288,8 +289,8 @@ read_surface_raw(void) parser.get_option(vopts, next_char); cxxSurface ex; - ex.read_raw(parser); - struct surface *surface_ptr = ex.cxxSurface2surface(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); int n; /* @@ -383,8 +384,8 @@ read_equilibrium_phases_raw(void) parser.get_option(vopts, next_char); cxxPPassemblage ex; - ex.read_raw(parser); - struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); int n; /* @@ -479,8 +480,8 @@ read_kinetics_raw(void) parser.get_option(vopts, next_char); cxxKinetics ex; - ex.read_raw(parser); - struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); int n; /* @@ -574,9 +575,8 @@ read_solid_solutions_raw(void) parser.get_option(vopts, next_char); cxxSSassemblage ex; - ex.read_raw(parser); - struct s_s_assemblage *s_s_assemblage_ptr = - ex.cxxSSassemblage2s_s_assemblage(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); int n; /* @@ -672,8 +672,8 @@ read_gas_phase_raw(void) parser.get_option(vopts, next_char); cxxGasPhase ex; - ex.read_raw(parser); - struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); int n; /* @@ -766,8 +766,8 @@ read_reaction_raw(void) parser.get_option(vopts, next_char); cxxReaction ex; - ex.read_raw(parser); - struct irrev *irrev_ptr = ex.cxxReaction2irrev(); + ex.read_raw(PHREEQC_THIS_COMMA parser); + struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); int n; /* @@ -862,7 +862,7 @@ read_mix_raw(void) cxxMix ex; ex.read_raw(parser); - struct mix *mix_ptr = ex.cxxMix2mix(); + struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); int n; /* @@ -958,7 +958,7 @@ read_temperature_raw(void) cxxTemperature ex; ex.read_raw(parser); - struct temperature *temperature_ptr = ex.cxxTemperature2temperature(); + struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); int n; /* @@ -1219,9 +1219,9 @@ read_solution_modify(void) } cxxSolution sol(solution[n]); - sol.read_raw(parser, false); + sol.read_raw(PHREEQC_THIS_COMMA parser, false); - struct solution *soln_ptr = sol.cxxSolution2solution(); + struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); /* * This is not quite right, may not produce sort order, forced sort @@ -1306,10 +1306,10 @@ read_equilibrium_phases_modify(void) // read entity cxxPPassemblage entity(&(pp_assemblage[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(); + struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); pp_assemblage_free(&(pp_assemblage[n])); pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); free_check_null(pp_assemblage[n].description); @@ -1394,10 +1394,10 @@ read_exchange_modify(void) // read entity cxxExchange entity(&(exchange[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct exchange *entity_ptr = entity.cxxExchange2exchange(); + struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); exchange_free(&(exchange[n])); exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); free_check_null(exchange[n].description); @@ -1482,10 +1482,10 @@ read_surface_modify(void) // read entity cxxSurface entity(&(surface[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct surface *entity_ptr = entity.cxxSurface2surface(); + struct surface *entity_ptr = entity.cxxSurface2surface(PHREEQC_THIS); surface_free(&(surface[n])); surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); free_check_null(surface[n].description); @@ -1569,10 +1569,10 @@ read_solid_solutions_modify(void) // read entity cxxSSassemblage entity(&(s_s_assemblage[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(); + struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); s_s_assemblage_free(&(s_s_assemblage[n])); s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); free_check_null(s_s_assemblage[n].description); @@ -1655,9 +1655,9 @@ read_gas_phase_modify(void) // read entity cxxGasPhase entity(&(gas_phase[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(); + struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); gas_phase_free(&(gas_phase[n])); gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); free_check_null(gas_phase[n].description); @@ -1741,10 +1741,10 @@ read_kinetics_modify(void) // read entity cxxKinetics entity(&(kinetics[n])); - entity.read_raw(parser, false); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity - struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(); + struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(PHREEQC_THIS); kinetics_free(&(kinetics[n])); kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); free_check_null(kinetics[n].description); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index fddebdd5..1655dbfa 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -158,7 +158,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblage::read_raw(CParser & parser, bool check) +cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -240,7 +240,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(parser, false); + ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); @@ -249,12 +249,12 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) { cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); } else { cxxSSassemblageSS ec1; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_name()); this->ssAssemblageSSs[str] = ec1; } diff --git a/SSassemblage.h b/SSassemblage.h index fcd48461..4eb03413 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -34,13 +34,13 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - void totalize(); + void totalize(PHREEQC_PTR_ARG); const cxxNameDouble & get_totals() const { diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 86cee5d9..f489bc35 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -217,7 +217,7 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblageSS::read_raw(CParser & parser, bool check) +cxxSSassemblageSS::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { std::string str; @@ -333,7 +333,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) break; case 4: // components - if (this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) + if (this->comps.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); parser.error_msg("Expected phase name and moles for comps.", diff --git a/SSassemblageSS.h b/SSassemblageSS.h index b72e1d8b..3831e995 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -40,7 +40,7 @@ class cxxSSassemblageSS void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); const std::string &get_name() const { diff --git a/Solution.cxx b/Solution.cxx index ac8c57f5..b97a1dba 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -306,18 +306,18 @@ cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) // totals solution_ptr->totals = (struct conc *) P_INSTANCE_POINTER free_check_null(solution_ptr->totals); - solution_ptr->totals = this->totals.conc(); + solution_ptr->totals = this->totals.conc(P_INSTANCE); // master_activity solution_ptr->master_activity = (struct master_activity *) P_INSTANCE_POINTER free_check_null(solution_ptr-> master_activity); - solution_ptr->master_activity = this->master_activity.master_activity(); + solution_ptr->master_activity = this->master_activity.master_activity(P_INSTANCE); solution_ptr->count_master_activity = (int) this->master_activity.size() + 1; // species_gamma - solution_ptr->species_gamma = this->species_gamma.master_activity(); + solution_ptr->species_gamma = this->species_gamma.master_activity(P_INSTANCE); solution_ptr->count_species_gamma = (int) this->species_gamma.size(); // isotopes @@ -557,7 +557,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSolution::read_raw(CParser & parser, bool check) +cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -629,7 +629,7 @@ cxxSolution::read_raw(CParser & parser, bool check) continue; case 0: // totals - if (this->totals.read_raw(parser, next_char) != + if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -641,7 +641,7 @@ cxxSolution::read_raw(CParser & parser, bool check) break; case 1: // activities - if (this->master_activity.read_raw(parser, next_char) != + if (this->master_activity.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -654,7 +654,7 @@ cxxSolution::read_raw(CParser & parser, bool check) break; case 2: // gammas - if (this->species_gamma.read_raw(parser, next_char) != + if (this->species_gamma.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/Solution.h b/Solution.h index c7b4cd0f..6b0be43f 100644 --- a/Solution.h +++ b/Solution.h @@ -152,7 +152,7 @@ class cxxSolution:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); void multiply(double extensive); #ifdef ORCHESTRA void ORCH_write(std::ostream & headings, std::ostream & input_data) const; diff --git a/StorageBin.cxx b/StorageBin.cxx index 6a210f30..ca429acc 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -372,7 +372,7 @@ cxxStorageBin::getSurfaces() const return this->Surfaces; }; void -cxxStorageBin::import_phreeqc(void) +cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // // pull data out of c storage // @@ -380,65 +380,65 @@ cxxStorageBin::import_phreeqc(void) int i; // Solutions - for (i = 0; i < count_solution; i++) + for (i = 0; i < P_INSTANCE_POINTER count_solution; i++) { - Solutions[solution[i]->n_user] = cxxSolution(solution[i]); + Solutions[P_INSTANCE_POINTER solution[i]->n_user] = cxxSolution(P_INSTANCE_POINTER solution[i]); } // Exchangers - for (i = 0; i < count_exchange; i++) + for (i = 0; i < P_INSTANCE_POINTER count_exchange; i++) { - Exchangers[exchange[i].n_user] = cxxExchange(&exchange[i]); + Exchangers[P_INSTANCE_POINTER exchange[i].n_user] = cxxExchange(&P_INSTANCE_POINTER exchange[i]); } // GasPhases - for (i = 0; i < count_gas_phase; i++) + for (i = 0; i < P_INSTANCE_POINTER count_gas_phase; i++) { - GasPhases[gas_phase[i].n_user] = cxxGasPhase(&gas_phase[i]); + GasPhases[P_INSTANCE_POINTER gas_phase[i].n_user] = cxxGasPhase(&P_INSTANCE_POINTER gas_phase[i]); } // Kinetics - for (i = 0; i < count_kinetics; i++) + for (i = 0; i < P_INSTANCE_POINTER count_kinetics; i++) { - Kinetics[kinetics[i].n_user] = cxxKinetics(&kinetics[i]); + Kinetics[P_INSTANCE_POINTER kinetics[i].n_user] = cxxKinetics(&P_INSTANCE_POINTER kinetics[i]); } // PPassemblages - for (i = 0; i < count_pp_assemblage; i++) + for (i = 0; i < P_INSTANCE_POINTER count_pp_assemblage; i++) { - PPassemblages[pp_assemblage[i].n_user] = - cxxPPassemblage(&pp_assemblage[i]); + PPassemblages[P_INSTANCE_POINTER pp_assemblage[i].n_user] = + cxxPPassemblage(&P_INSTANCE_POINTER pp_assemblage[i]); } // SSassemblages - for (i = 0; i < count_s_s_assemblage; i++) + for (i = 0; i < P_INSTANCE_POINTER count_s_s_assemblage; i++) { - SSassemblages[s_s_assemblage[i].n_user] = - cxxSSassemblage(&s_s_assemblage[i]); + SSassemblages[P_INSTANCE_POINTER s_s_assemblage[i].n_user] = + cxxSSassemblage(&P_INSTANCE_POINTER s_s_assemblage[i]); } // Surfaces - for (i = 0; i < count_surface; i++) + for (i = 0; i < P_INSTANCE_POINTER count_surface; i++) { - Surfaces[surface[i].n_user] = cxxSurface(&surface[i]); + Surfaces[P_INSTANCE_POINTER surface[i].n_user] = cxxSurface(&P_INSTANCE_POINTER surface[i]); } // Mixes - for (i = 0; i < count_mix; i++) + for (i = 0; i < P_INSTANCE_POINTER count_mix; i++) { - Mixes[mix[i].n_user] = cxxMix(&mix[i]); + Mixes[P_INSTANCE_POINTER mix[i].n_user] = cxxMix(&P_INSTANCE_POINTER mix[i]); } // Reactions - for (i = 0; i < count_irrev; i++) + for (i = 0; i < P_INSTANCE_POINTER count_irrev; i++) { - Reactions[irrev[i].n_user] = cxxReaction(&irrev[i]); + Reactions[P_INSTANCE_POINTER irrev[i].n_user] = cxxReaction(&P_INSTANCE_POINTER irrev[i]); } // Temperatures - for (i = 0; i < count_temperature; i++) + for (i = 0; i < P_INSTANCE_POINTER count_temperature; i++) { - Temperatures[temperature[i].n_user] = cxxTemperature(&temperature[i]); + Temperatures[P_INSTANCE_POINTER temperature[i].n_user] = cxxTemperature(&P_INSTANCE_POINTER temperature[i]); } } @@ -561,7 +561,7 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent) } void -cxxStorageBin::read_raw(CParser & parser) +cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) { CParser::LINE_TYPE i; while ((i = @@ -593,7 +593,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_SOLUTION_RAW: { cxxSolution entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Solutions[entity.get_n_user()] = entity; } break; @@ -601,7 +601,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_EXCHANGE_RAW: { cxxExchange entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Exchangers[entity.get_n_user()] = entity; } break; @@ -609,7 +609,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_GASPHASE_RAW: { cxxGasPhase entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); GasPhases[entity.get_n_user()] = entity; } break; @@ -617,7 +617,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_KINETICS_RAW: { cxxKinetics entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Kinetics[entity.get_n_user()] = entity; } break; @@ -625,7 +625,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { cxxPPassemblage entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); PPassemblages[entity.get_n_user()] = entity; } break; @@ -633,7 +633,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_SSASSEMBLAGE_RAW: { cxxSSassemblage entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); SSassemblages[entity.get_n_user()] = entity; } break; @@ -641,7 +641,7 @@ cxxStorageBin::read_raw(CParser & parser) case CParser::KT_SURFACE_RAW: { cxxSurface entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Surfaces[entity.get_n_user()] = entity; } break; @@ -656,7 +656,7 @@ cxxStorageBin::read_raw(CParser & parser) } int -cxxStorageBin::read_raw_keyword(CParser & parser) +cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) { CParser::LINE_TYPE i; int entity_number = -999; @@ -687,7 +687,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_SOLUTION_RAW: { cxxSolution entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Solutions[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -696,7 +696,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_EXCHANGE_RAW: { cxxExchange entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Exchangers[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -705,7 +705,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_GASPHASE_RAW: { cxxGasPhase entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); GasPhases[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -714,7 +714,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_KINETICS_RAW: { cxxKinetics entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Kinetics[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -723,7 +723,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { cxxPPassemblage entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); PPassemblages[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -732,7 +732,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_SSASSEMBLAGE_RAW: { cxxSSassemblage entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); SSassemblages[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -741,7 +741,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case CParser::KT_SURFACE_RAW: { cxxSurface entity; - entity.read_raw(parser); + entity.read_raw(P_INSTANCE_COMMA parser); Surfaces[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -811,7 +811,7 @@ cxxStorageBin::add(struct system *system_ptr) } void -cxxStorageBin::cxxStorageBin2phreeqc(int n) +cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) // // copy data fromphreeqc storage to storage bin // @@ -824,14 +824,14 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) std::map < int, cxxSolution >::iterator it = this->Solutions.find(n); if (it != this->Solutions.end()) { - solution[0] = (it->second).cxxSolution2solution(); - solution[0]->n_user = n; - solution[0]->n_user_end = n; - count_solution++; + P_INSTANCE_POINTER solution[0] = (it->second).cxxSolution2solution(P_INSTANCE); + P_INSTANCE_POINTER solution[0]->n_user = n; + P_INSTANCE_POINTER solution[0]->n_user_end = n; + P_INSTANCE_POINTER count_solution++; } else { - error_msg("cxxSolution not found in system2phreeqc", STOP); + P_INSTANCE_POINTER error_msg("cxxSolution not found in system2phreeqc", STOP); } } @@ -841,11 +841,11 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) if (it != this->Exchangers.end()) { struct exchange *exchange_ptr = - (it->second).cxxExchange2exchange(); - exchange_copy(exchange_ptr, &exchange[0], n); - count_exchange++; - exchange_free(exchange_ptr); - exchange_ptr = (struct exchange *) free_check_null(exchange_ptr); + (it->second).cxxExchange2exchange(P_INSTANCE); + P_INSTANCE_POINTER exchange_copy(exchange_ptr, &P_INSTANCE_POINTER exchange[0], n); + P_INSTANCE_POINTER count_exchange++; + P_INSTANCE_POINTER exchange_free(exchange_ptr); + exchange_ptr = (struct exchange *) P_INSTANCE_POINTER free_check_null(exchange_ptr); } } @@ -855,12 +855,12 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) if (it != this->GasPhases.end()) { struct gas_phase *gas_phase_ptr = - (it->second).cxxGasPhase2gas_phase(); - gas_phase_copy(gas_phase_ptr, &gas_phase[0], n); - count_gas_phase++; - gas_phase_free(gas_phase_ptr); + (it->second).cxxGasPhase2gas_phase(P_INSTANCE); + P_INSTANCE_POINTER gas_phase_copy(gas_phase_ptr, &P_INSTANCE_POINTER gas_phase[0], n); + P_INSTANCE_POINTER count_gas_phase++; + P_INSTANCE_POINTER gas_phase_free(gas_phase_ptr); gas_phase_ptr = - (struct gas_phase *) free_check_null(gas_phase_ptr); + (struct gas_phase *) P_INSTANCE_POINTER free_check_null(gas_phase_ptr); } } @@ -870,11 +870,11 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) if (it != this->Kinetics.end()) { struct kinetics *kinetics_ptr = - (it->second).cxxKinetics2kinetics(); - kinetics_copy(kinetics_ptr, &kinetics[0], n); - count_kinetics++; - kinetics_free(kinetics_ptr); - kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); + (it->second).cxxKinetics2kinetics(P_INSTANCE); + P_INSTANCE_POINTER kinetics_copy(kinetics_ptr, &P_INSTANCE_POINTER kinetics[0], n); + P_INSTANCE_POINTER count_kinetics++; + P_INSTANCE_POINTER kinetics_free(kinetics_ptr); + kinetics_ptr = (struct kinetics *) P_INSTANCE_POINTER free_check_null(kinetics_ptr); } } @@ -885,12 +885,12 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) if (it != this->PPassemblages.end()) { struct pp_assemblage *pp_assemblage_ptr = - (it->second).cxxPPassemblage2pp_assemblage(); - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[0], n); - count_pp_assemblage++; - pp_assemblage_free(pp_assemblage_ptr); + (it->second).cxxPPassemblage2pp_assemblage(P_INSTANCE); + P_INSTANCE_POINTER pp_assemblage_copy(pp_assemblage_ptr, &P_INSTANCE_POINTER pp_assemblage[0], n); + P_INSTANCE_POINTER count_pp_assemblage++; + P_INSTANCE_POINTER pp_assemblage_free(pp_assemblage_ptr); pp_assemblage_ptr = - (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); + (struct pp_assemblage *) P_INSTANCE_POINTER free_check_null(pp_assemblage_ptr); } } @@ -901,12 +901,12 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) if (it != this->SSassemblages.end()) { struct s_s_assemblage *s_s_assemblage_ptr = - (it->second).cxxSSassemblage2s_s_assemblage(); - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[0], n); - count_s_s_assemblage++; - s_s_assemblage_free(s_s_assemblage_ptr); + (it->second).cxxSSassemblage2s_s_assemblage(P_INSTANCE); + P_INSTANCE_POINTER s_s_assemblage_copy(s_s_assemblage_ptr, &P_INSTANCE_POINTER s_s_assemblage[0], n); + P_INSTANCE_POINTER count_s_s_assemblage++; + P_INSTANCE_POINTER s_s_assemblage_free(s_s_assemblage_ptr); s_s_assemblage_ptr = - (struct s_s_assemblage *) free_check_null(s_s_assemblage_ptr); + (struct s_s_assemblage *) P_INSTANCE_POINTER free_check_null(s_s_assemblage_ptr); } } @@ -915,18 +915,18 @@ cxxStorageBin::cxxStorageBin2phreeqc(int n) std::map < int, cxxSurface >::iterator it = this->Surfaces.find(n); if (it != this->Surfaces.end()) { - struct surface *surface_ptr = (it->second).cxxSurface2surface(); - surface_copy(surface_ptr, &surface[0], n); - count_surface++; - surface_free(surface_ptr); - surface_ptr = (struct surface *) free_check_null(surface_ptr); + struct surface *surface_ptr = (it->second).cxxSurface2surface(P_INSTANCE); + P_INSTANCE_POINTER surface_copy(surface_ptr, &P_INSTANCE_POINTER surface[0], n); + P_INSTANCE_POINTER count_surface++; + P_INSTANCE_POINTER surface_free(surface_ptr); + surface_ptr = (struct surface *) P_INSTANCE_POINTER free_check_null(surface_ptr); } } //std::cerr << oss.str(); } void -cxxStorageBin::phreeqc2cxxStorageBin(int n) +cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) // // copy data fromphreeqc storage to storage bin // @@ -935,55 +935,55 @@ cxxStorageBin::phreeqc2cxxStorageBin(int n) // Solutions { - solution_bsearch(n, &pos, TRUE); - this->Solutions[n] = cxxSolution(solution[pos]); + P_INSTANCE_POINTER solution_bsearch(n, &pos, TRUE); + this->Solutions[n] = cxxSolution(P_INSTANCE_POINTER solution[pos]); } // Exchangers { - if (exchange_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER exchange_bsearch(n, &pos) != NULL) { - this->Exchangers[n] = cxxExchange(&(exchange[pos])); + this->Exchangers[n] = cxxExchange(&(P_INSTANCE_POINTER exchange[pos])); } } // GasPhases { - if (gas_phase_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER gas_phase_bsearch(n, &pos) != NULL) { - this->GasPhases[n] = cxxGasPhase(&(gas_phase[pos])); + this->GasPhases[n] = cxxGasPhase(&(P_INSTANCE_POINTER gas_phase[pos])); } } // Kinetics { - if (kinetics_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER kinetics_bsearch(n, &pos) != NULL) { - this->Kinetics[n] = cxxKinetics(&(kinetics[pos])); + this->Kinetics[n] = cxxKinetics(&(P_INSTANCE_POINTER kinetics[pos])); } } // PPassemblages { - if (pp_assemblage_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER pp_assemblage_bsearch(n, &pos) != NULL) { - this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos])); + this->PPassemblages[n] = cxxPPassemblage(&(P_INSTANCE_POINTER pp_assemblage[pos])); } } // SSassemblages { - if (s_s_assemblage_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER s_s_assemblage_bsearch(n, &pos) != NULL) { - this->SSassemblages[n] = cxxSSassemblage(&(s_s_assemblage[pos])); + this->SSassemblages[n] = cxxSSassemblage(&(P_INSTANCE_POINTER s_s_assemblage[pos])); } } // Surfaces { - if (surface_bsearch(n, &pos) != NULL) + if (P_INSTANCE_POINTER surface_bsearch(n, &pos) != NULL) { - this->Surfaces[n] = cxxSurface(&(surface[pos])); + this->Surfaces[n] = cxxSurface(&(P_INSTANCE_POINTER surface[pos])); } } } @@ -1060,7 +1060,7 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) } #endif struct system * -cxxStorageBin::cxxStorageBin2system(int n) +cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // // make a system from storagebin // @@ -1068,13 +1068,13 @@ cxxStorageBin::cxxStorageBin2system(int n) struct system *system_ptr = (struct system *) PHRQ_malloc(sizeof(struct system)); if (system_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); // Solutions if (this->getSolution(n) != NULL) { - system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(); + system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(P_INSTANCE); } else { @@ -1084,7 +1084,7 @@ cxxStorageBin::cxxStorageBin2system(int n) // Exchangers if (this->getExchange(n) != NULL) { - system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(); + system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(P_INSTANCE); } else { @@ -1095,7 +1095,7 @@ cxxStorageBin::cxxStorageBin2system(int n) if (this->getGasPhase(n) != NULL) { system_ptr->gas_phase = - (this->getGasPhase(n))->cxxGasPhase2gas_phase(); + (this->getGasPhase(n))->cxxGasPhase2gas_phase(P_INSTANCE); } else { @@ -1105,7 +1105,7 @@ cxxStorageBin::cxxStorageBin2system(int n) // Kinetics if (this->getKinetics(n) != NULL) { - system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(); + system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(P_INSTANCE); } else { @@ -1116,7 +1116,7 @@ cxxStorageBin::cxxStorageBin2system(int n) if (this->getPPassemblage(n) != NULL) { system_ptr->pp_assemblage = - (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(); + (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(P_INSTANCE); } else { @@ -1127,7 +1127,7 @@ cxxStorageBin::cxxStorageBin2system(int n) if (this->getSSassemblage(n) != NULL) { system_ptr->s_s_assemblage = - (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(); + (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(P_INSTANCE); } else { @@ -1137,7 +1137,7 @@ cxxStorageBin::cxxStorageBin2system(int n) // Surfaces if (this->getSurface(n) != NULL) { - system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(); + system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(P_INSTANCE); } else { diff --git a/StorageBin.h b/StorageBin.h index ba0750c5..d72814d8 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -25,11 +25,11 @@ class cxxStorageBin cxxStorageBin(struct Use *use_ptr); ~cxxStorageBin(); - void import_phreeqc(void); + void import_phreeqc(PHREEQC_PTR_ARG); - void cxxStorageBin2phreeqc(int n); + void cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n); - void phreeqc2cxxStorageBin(int n); + void phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n); void remove(int n); @@ -79,12 +79,12 @@ class cxxStorageBin void dump_raw(std::ostream & s_oss, int i, unsigned int indent); - void read_raw(CParser & parser); - int read_raw_keyword(CParser & parser); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser); + int read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser); void add(struct system *sys_ptr); - struct system *cxxStorageBin2system(int i); + struct system *cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int i); //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); diff --git a/Surface.cxx b/Surface.cxx index 1bdaa3b8..e803088a 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -82,7 +82,7 @@ cxxNumKeyword() surfaceCharges[str] = ec; } } -cxxSurface::cxxSurface(const std::map < int, cxxSurface > &entities, +cxxSurface::cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entities, cxxMix & mix, int n_user): cxxNumKeyword() { @@ -107,7 +107,7 @@ cxxNumKeyword() { const cxxSurface *entity_ptr = &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); + this->add(P_INSTANCE_COMMA *entity_ptr, it->second); } } } @@ -177,7 +177,7 @@ cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) surface_ptr->comps = (struct surface_comp *) P_INSTANCE_POINTER free_check_null(surface_ptr->comps); surface_ptr->comps = - cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps); + cxxSurfaceComp::cxxSurfaceComp2surface_comp(P_INSTANCE_COMMA this->surfaceComps); // Surface charge surface_ptr->charge = @@ -200,8 +200,7 @@ cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) for (i = 0; i < surface_ptr->count_comps; i++) { char *charge_name = P_INSTANCE_POINTER string_hsave( - cxxSurfaceComp::get_charge_name(surface_ptr->comps[i]. - formula).c_str()); + cxxSurfaceComp::get_charge_name(P_INSTANCE_COMMA surface_ptr->comps[i].formula).c_str()); for (j = 0; j < surface_ptr->count_charge; j++) { if (charge_name == surface_ptr->charge[j].name) @@ -364,7 +363,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurface::read_raw(CParser & parser, bool check) +cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { static std::vector < std::string > vopts; int i = 0; @@ -540,7 +539,7 @@ cxxSurface::read_raw(CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(parser, false); + ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); @@ -549,12 +548,12 @@ cxxSurface::read_raw(CParser & parser, bool check) if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) { cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; - comp.read_raw(reread, false); + comp.read_raw(P_INSTANCE_COMMA reread, false); } else { cxxSurfaceComp ec1; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_formula()); this->surfaceComps[str] = ec1; } @@ -593,7 +592,7 @@ cxxSurface::read_raw(CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(parser, false); + ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); @@ -602,12 +601,12 @@ cxxSurface::read_raw(CParser & parser, bool check) if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) { cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; - comp.read_raw(reread, false); + comp.read_raw(P_INSTANCE_COMMA reread, false); } else { cxxSurfaceCharge ec1; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_name()); this->surfaceCharges[str] = ec1; } @@ -973,7 +972,7 @@ cxxSurface::add(const cxxSurface & addee, double extensive) } #endif void -cxxSurface::add(const cxxSurface & addee, double extensive) +cxxSurface::add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive) // // Add surface to "this" exchange // @@ -1010,7 +1009,7 @@ cxxSurface::add(const cxxSurface & addee, double extensive) std::map < std::string, cxxSurfaceComp >::iterator it = this->surfaceComps.find((*itadd).first); if (it != this->surfaceComps.end()) { - (*it).second.add( (*itadd).second, extensive); + (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); } else { diff --git a/Surface.h b/Surface.h index be710554..fdb9205d 100644 --- a/Surface.h +++ b/Surface.h @@ -18,7 +18,7 @@ class cxxSurface:public cxxNumKeyword public: cxxSurface(); cxxSurface(struct surface *); - cxxSurface(const std::map < int, cxxSurface > &entity_map, cxxMix & mx, + cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entity_map, cxxMix & mx, int n_user); ~cxxSurface(); @@ -34,7 +34,7 @@ class cxxSurface:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); bool get_related_phases(void); @@ -52,7 +52,7 @@ class cxxSurface:public cxxNumKeyword void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif private: - void add(const cxxSurface & addee, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive); protected: std::map < std::string, cxxSurfaceComp > surfaceComps; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 013894b7..cc3396d7 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -203,7 +203,7 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurfaceCharge::read_raw(CParser & parser, bool check) +cxxSurfaceCharge::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { std::string str; @@ -337,7 +337,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) case 6: // diffuse_layer_totals - if (this->diffuse_layer_totals.read_raw(parser, next_char) != + if (this->diffuse_layer_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 37da563b..3ffff40d 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -28,7 +28,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); const std::string &get_name() const { diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index a0059c18..95811d58 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -103,7 +103,7 @@ struct master * } struct surface_comp * - cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el) + cxxSurfaceComp::cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el) // // Builds surface_comp structure from of cxxSurfaceComp // @@ -112,33 +112,33 @@ struct surface_comp * (struct surface_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); if (surf_comp_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); int i = 0; for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin(); it != el.end(); ++it) { - surf_comp_ptr[i].formula = string_hsave((*it).second.formula.c_str()); + surf_comp_ptr[i].formula = P_INSTANCE_POINTER string_hsave((*it).second.formula.c_str()); assert((*it).second.formula.size() > 0); - surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(); + surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(P_INSTANCE); surf_comp_ptr[i].formula_z = (*it).second.formula_z; surf_comp_ptr[i].moles = (*it).second.moles; - surf_comp_ptr[i].master = (*it).second.get_master(); - surf_comp_ptr[i].totals = (*it).second.totals.elt_list(); + surf_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); + surf_comp_ptr[i].totals = (*it).second.totals.elt_list(P_INSTANCE); surf_comp_ptr[i].la = (*it).second.la; //surf_comp_ptr[i].charge = it->charge_number; surf_comp_ptr[i].cb = (*it).second.charge_balance; if ((*it).second.phase_name.size() == 0) surf_comp_ptr[i].phase_name = NULL; else - surf_comp_ptr[i].phase_name = string_hsave((*it).second.phase_name.c_str()); + surf_comp_ptr[i].phase_name = P_INSTANCE_POINTER string_hsave((*it).second.phase_name.c_str()); surf_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; if ((*it).second.rate_name.size() == 0) surf_comp_ptr[i].rate_name = NULL; else - surf_comp_ptr[i].rate_name = string_hsave((*it).second.rate_name.c_str()); + surf_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); surf_comp_ptr[i].Dw = (*it).second.Dw; - surf_comp_ptr[i].master = (*it).second.get_master(); + surf_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); i++; } return (surf_comp_ptr); @@ -246,7 +246,7 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurfaceComp::read_raw(CParser & parser, bool check) +cxxSurfaceComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { std::string str; @@ -403,7 +403,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) break; case 8: // totals - if (this->totals.read_raw(parser, next_char) != + if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -427,7 +427,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) break; case 10: // formula_totals - if (this->formula_totals.read_raw(parser, next_char) != + if (this->formula_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -547,7 +547,7 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) +cxxSurfaceComp::add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & addee, double extensive) { if (extensive == 0.0) return; @@ -602,8 +602,8 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) oss << "Can not mix two Surface components with same formula and different related phases, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER input_error++; return; } else if (this->phase_name.size() != 0) @@ -619,8 +619,8 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER input_error++; return; } else if (this->rate_name.size() != 0) @@ -636,8 +636,8 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); + P_INSTANCE_POINTER input_error++; return; } //double Dw; @@ -717,18 +717,18 @@ cxxSurfaceComp::get_totals() const return (this->totals); }; std::string -cxxSurfaceComp::charge_name() +cxxSurfaceComp::charge_name(PHREEQC_PTR_ARG) { - char * str = string_hsave(this->formula.c_str()); - return (get_charge_name(str)); + char * str = P_INSTANCE_POINTER string_hsave(this->formula.c_str()); + return (get_charge_name(P_INSTANCE_COMMA str)); }; std::string -cxxSurfaceComp::get_charge_name(char *token) +cxxSurfaceComp::get_charge_name(PHREEQC_PTR_ARG_COMMA char *token) { char name[100]; int l; char *ptr1 = token; - get_elt(&ptr1, name, &l); + P_INSTANCE_POINTER get_elt(&ptr1, name, &l); ptr1 = strchr(name, '_'); if (ptr1 != NULL) { diff --git a/SurfaceComp.h b/SurfaceComp.h index f445f76a..34317da6 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -6,7 +6,7 @@ #include // std::string #include // std::list #include // std::vector - +#include "Phreeqc_class.h" #include "NameDouble.h" class cxxSurfaceComp @@ -27,15 +27,15 @@ public: void set_formula(char * f); double get_charge_balance() const; void set_charge_balance(double d); - static struct surface_comp *cxxSurfaceComp2surface_comp(std::map < std::string, cxxSurfaceComp > &el); + static struct surface_comp *cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); const cxxNameDouble & get_totals() const; - void add(const cxxSurfaceComp & comp, double extensive); + void add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - std::string charge_name(); - static std::string get_charge_name(char *token); + std::string charge_name(PHREEQC_PTR_ARG); + static std::string get_charge_name(PHREEQC_PTR_ARG_COMMA char *token); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/System.cxx b/System.cxx index f9f46ce0..0cd99eea 100644 --- a/System.cxx +++ b/System.cxx @@ -53,7 +53,7 @@ cxxSystem::Initialize(void) this->temperature = NULL; } void -cxxSystem::totalize(void) +cxxSystem::totalize(PHREEQC_PTR_ARG) { //initialize this->totals.clear(); @@ -76,22 +76,22 @@ cxxSystem::totalize(void) } if (this->ppassemblage != NULL) { - this->ppassemblage->totalize(); + this->ppassemblage->totalize(P_INSTANCE); this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); } if (this->gasphase != NULL) { - this->gasphase->totalize(); + this->gasphase->totalize(P_INSTANCE); this->totals.add_extensive(this->gasphase->get_totals(), 1.0); } if (this->ssassemblage != NULL) { - this->ssassemblage->totalize(); + this->ssassemblage->totalize(P_INSTANCE); this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); } if (this->surface != NULL) { - this->ssassemblage->totalize(); + this->ssassemblage->totalize(P_INSTANCE); this->totals.add_extensive(this->surface->get_totals(), 1.0); } //Need to handle the following 3 reactions: diff --git a/System.h b/System.h index a5c0cca3..34243f39 100644 --- a/System.h +++ b/System.h @@ -24,40 +24,51 @@ class cxxMix; class cxxSystem { - public:cxxSystem(void); - public: ~cxxSystem(void); - void Initialize(void); - void setSolution(cxxSolution * entity) +public: + cxxSystem(void); + ~cxxSystem(void); + void Initialize(void); + void setSolution(cxxSolution * entity) { this->solution = entity; - } void setExchange(cxxExchange * entity) + } + void setExchange(cxxExchange * entity) { this->exchange = entity; - } void setPPassemblage(cxxPPassemblage * entity) + } + void setPPassemblage(cxxPPassemblage * entity) { this->ppassemblage = entity; - } void setGasPhase(cxxGasPhase * entity) + } + void setGasPhase(cxxGasPhase * entity) { this->gasphase = entity; - } void setSSassemblage(cxxSSassemblage * entity) + } + void setSSassemblage(cxxSSassemblage * entity) { this->ssassemblage = entity; - } void setKinetics(cxxKinetics * entity) + } + void setKinetics(cxxKinetics * entity) { this->kinetics = entity; - } void setSurface(cxxSurface * entity) + } + void setSurface(cxxSurface * entity) { this->surface = entity; - } void setMix(cxxMix * entity) + } + void setMix(cxxMix * entity) { this->mix = entity; - } void setReaction(cxxReaction * entity) + } + void setReaction(cxxReaction * entity) { this->reaction = entity; - } void setTemperature(cxxTemperature * entity) + } + void setTemperature(cxxTemperature * entity) { this->temperature = entity; - } void totalize(); + } + void totalize(PHREEQC_PTR_ARG); #ifdef ORCHESTRA void ORCH_components(); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index f140fd77..e6e92f11 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -108,12 +108,12 @@ cxxKinetics::~cxxKinetics() } struct kinetics * -cxxKinetics::cxxKinetics2kinetics() +cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) // // Builds a kinetics structure from instance of cxxKinetics // { - struct kinetics *kinetics_ptr = kinetics_alloc(); + struct kinetics *kinetics_ptr = P_INSTANCE_POINTER kinetics_alloc(); kinetics_ptr->description = this->get_description(); kinetics_ptr->n_user = this->n_user; @@ -126,25 +126,25 @@ cxxKinetics::cxxKinetics2kinetics() kinetics_ptr->cvode_order = this->cvode_order; // totals - kinetics_ptr->totals = this->totals.elt_list(); + kinetics_ptr->totals = this->totals.elt_list(P_INSTANCE); // comps kinetics_ptr->count_comps = (int) this->kineticsComps.size(); kinetics_ptr->comps = - (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); + (struct kinetics_comp *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->comps); kinetics_ptr->comps = - cxxKineticsComp::cxxKineticsComp2kinetics_comp(this->kineticsComps); + cxxKineticsComp::cxxKineticsComp2kinetics_comp(P_INSTANCE_COMMA this->kineticsComps); // steps kinetics_ptr->count_steps = (int) this->steps.size(); - kinetics_ptr->steps = (double *) free_check_null(kinetics_ptr->steps); + kinetics_ptr->steps = (double *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->steps); if (this->steps.size() > 0) { kinetics_ptr->steps = (double *) PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (kinetics_ptr->steps == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); std::copy(this->steps.begin(), this->steps.end(), kinetics_ptr->steps); /* @@ -267,7 +267,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKinetics::read_raw(CParser & parser, bool check) +cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { double d; @@ -414,7 +414,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(parser, false); + ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); CParser reread(is); @@ -424,12 +424,12 @@ cxxKinetics::read_raw(CParser & parser, bool check) if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) { cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; - comp.read_raw(reread, false); + comp.read_raw(P_INSTANCE_COMMA reread, false); } else { cxxKineticsComp ec1; - ec1.read_raw(reread, false); + ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_rate_name()); this->kineticsComps[str] = ec1; } @@ -438,7 +438,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) break; case 5: // totals - if (this->totals.read_raw(parser, next_char) != + if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/cxxKinetics.h b/cxxKinetics.h index bef2abab..750b4d03 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -21,7 +21,7 @@ class cxxKinetics:public cxxNumKeyword int n_user); ~cxxKinetics(); - struct kinetics *cxxKinetics2kinetics(); + struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); struct kinetics_comp *cxxKineticsComp2kinetics_comp(); @@ -29,7 +29,7 @@ class cxxKinetics:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/cxxMix.cxx b/cxxMix.cxx index 79c9895c..9e5a51e7 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -61,7 +61,7 @@ cxxMix::~cxxMix() struct mix * -cxxMix::cxxMix2mix() +cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) // // Builds a mix structure from instance of cxxMix // @@ -69,7 +69,7 @@ cxxMix::cxxMix2mix() struct mix *mix_ptr; mix_ptr = (struct mix *) PHRQ_malloc(sizeof(struct mix)); if (mix_ptr == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); mix_ptr->description = this->get_description(); mix_ptr->n_user = this->n_user; @@ -85,7 +85,7 @@ cxxMix::cxxMix2mix() PHRQ_malloc((size_t) (this->mixComps.size() * sizeof(struct mix_comp))); if (mix_ptr->comps == NULL) - malloc_error(); + P_INSTANCE_POINTER malloc_error(); for (std::map < int, double >::iterator it = mixComps.begin(); it != mixComps.end(); it++) { diff --git a/cxxMix.h b/cxxMix.h index 3117af5b..107471ae 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -6,7 +6,7 @@ #include // std::string #include // std::list #include // std::vector - +#include "Phreeqc_class.h" #include "NumKeyword.h" class cxxMix:public cxxNumKeyword @@ -17,7 +17,7 @@ class cxxMix:public cxxNumKeyword cxxMix(struct mix *); ~cxxMix(); - struct mix *cxxMix2mix(); + struct mix *cxxMix2mix(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; diff --git a/phreeqc_class.h b/phreeqc_class.h index d4fc1a7e..ff524d5d 100644 --- a/phreeqc_class.h +++ b/phreeqc_class.h @@ -1,15 +1,21 @@ +#ifndef _INC_PHREEQC_CLASS_H +#define _INC_PHREEQC_CLASS_H #if !defined PHREEQC_CLASS #define P_INSTANCE #define P_INSTANCE_COMMA #define P_INSTANCE_POINTER #define PHREEQC_PTR_ARG #define PHREEQC_PTR_ARG_COMMA +#define PHREEQC_THIS +#define PHREEQC_THIS_COMMA #else #define P_INSTANCE p_instance #define P_INSTANCE_COMMA p_instance, #define P_INSTANCE_POINTER p_instance-> #define PHREEQC_PTR_ARG Phreeqc *p_instance #define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance, +#define PHREEQC_THIS this +#define PHREEQC_THIS_COMMA this, #endif - +#endif /* _INC_PHREEQC_CLASS_H */ //#include "Phreeqc_class.h" \ No newline at end of file From 3131740cfb31a72d5065d51dde3f753fdf559c57 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Dec 2009 22:12:42 +0000 Subject: [PATCH 0123/1077] Compiles as class, debug, and Release. Requires recompilation of the entire solution for some reason. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3878 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 8 ++++---- Exchange.cxx | 4 ++-- GasPhase.cxx | 6 +++--- ISolution.cxx | 4 ++-- ISolutionComp.cxx | 4 ++-- KineticsComp.cxx | 4 ++-- NameDouble.cxx | 10 +++++----- NumKeyword.h | 13 ++++++++----- PPassemblage.cxx | 4 ++-- PPassemblageComp.cxx | 4 ++-- Parser.cxx | 31 ++++++++++++++++++++----------- Parser.h | 29 +++++++++++++++++++---------- Reaction.cxx | 6 +++--- ReadClass.cxx | 40 ++++++++++++++++++++-------------------- SSassemblage.cxx | 4 ++-- SSassemblageSS.cxx | 4 ++-- Solution.cxx | 10 +++++----- SolutionIsotope.cxx | 2 +- SolutionIsotopeList.cxx | 2 +- StorageBin.cxx | 12 ++++++------ Surface.cxx | 6 +++--- SurfaceCharge.cxx | 2 +- SurfaceComp.cxx | 2 +- Temperature.cxx | 4 ++-- cxxKinetics.cxx | 6 +++--- cxxMix.cxx | 6 +++--- phreeqc_class.h | 2 ++ 27 files changed, 126 insertions(+), 103 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 75f4bb02..08caba6a 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -204,7 +204,7 @@ struct exch_comp * { struct exch_comp *exch_comp_ptr = (struct exch_comp *) - PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); if (exch_comp_ptr == NULL) P_INSTANCE_POINTER malloc_error(); @@ -603,7 +603,7 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi "Can not mix two exchange components with same formula and different related phases, " << this->formula; P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return; } else if (this->phase_name.size() != 0) @@ -619,7 +619,7 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return; } else if (this->rate_name.size() != 0) @@ -636,7 +636,7 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return; } } diff --git a/Exchange.cxx b/Exchange.cxx index 5a953873..b1b6f545 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -209,7 +209,7 @@ cxxExchange::cxxExchange2exchange(PHREEQC_PTR_ARG) { struct exchange *exchange_ptr = P_INSTANCE_POINTER exchange_alloc(); - exchange_ptr->description = this->get_description(); + exchange_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); exchange_ptr->n_user = this->n_user; exchange_ptr->n_user_end = this->n_user_end; exchange_ptr->new_def = FALSE; @@ -390,7 +390,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) diff --git a/GasPhase.cxx b/GasPhase.cxx index b54ed69d..4deae732 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -109,7 +109,7 @@ cxxNumKeyword() std::ostringstream oss; oss << "Can not mix two gas_phases with differing types."; P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return; } @@ -135,7 +135,7 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG) int n; gas_comp_ptr = (struct gas_comp *) - PHRQ_malloc((size_t) + P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->gasPhaseComps.size() * sizeof(struct gas_comp))); if (gas_comp_ptr == NULL) @@ -163,7 +163,7 @@ cxxGasPhase::cxxGasPhase2gas_phase(PHREEQC_PTR_ARG) { struct gas_phase *gas_phase_ptr = P_INSTANCE_POINTER gas_phase_alloc(); - gas_phase_ptr->description = this->get_description(); + gas_phase_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); gas_phase_ptr->n_user = this->n_user; gas_phase_ptr->n_user_end = this->n_user_end; gas_phase_ptr->new_def = FALSE; diff --git a/ISolution.cxx b/ISolution.cxx index d3e67075..afcab7be 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -131,7 +131,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) oss << "Could not find gfw, " << iter->second. get_description(); P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; } } /* @@ -772,7 +772,7 @@ cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat) oss << "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; } chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << std::endl; diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 1a8d9c07..7d66be83 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -48,7 +48,7 @@ struct conc *cxxISolutionComp::concarray(std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { @@ -78,7 +78,7 @@ cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < s { struct conc *c; c = (struct conc *) - PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); if (c == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 607ad3ec..f777a0c9 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -67,7 +67,7 @@ struct kinetics_comp * { struct kinetics_comp *kinetics_comp_ptr = (struct kinetics_comp *) - PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); if (kinetics_comp_ptr == NULL) P_INSTANCE_POINTER malloc_error(); @@ -98,7 +98,7 @@ struct kinetics_comp * if ((*it).second.d_params.size() > 0) { kinetics_comp_ptr[i].d_params = (double *) - PHRQ_malloc((size_t) ((*it).second.d_params.size() * sizeof(double))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).second.d_params.size() * sizeof(double))); if (kinetics_comp_ptr[i].d_params == NULL) P_INSTANCE_POINTER malloc_error(); std::copy((*it).second.d_params.begin(), (*it).second.d_params.end(), diff --git a/NameDouble.cxx b/NameDouble.cxx index 5cc671f6..530174a1 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -141,7 +141,7 @@ cxxNameDouble::elt_list(PHREEQC_PTR_ARG) assert(this->type == cxxNameDouble::ND_ELT_MOLES); struct elt_list *elt_list_ptr = (struct elt_list *) - PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list))); if (elt_list_ptr == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; @@ -172,7 +172,7 @@ cxxNameDouble::master_activity(PHREEQC_PTR_ARG) const { master_activity_ptr = (struct master_activity *) - PHRQ_malloc((size_t) + P_INSTANCE_POINTER PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct master_activity))); if (master_activity_ptr == NULL) @@ -193,7 +193,7 @@ cxxNameDouble::master_activity(PHREEQC_PTR_ARG) const { master_activity_ptr = (struct master_activity *) - PHRQ_malloc((size_t) + P_INSTANCE_POINTER PHRQ_malloc((size_t) (((*this).size()) * sizeof(struct master_activity))); if (master_activity_ptr == NULL) @@ -224,7 +224,7 @@ cxxNameDouble::conc(PHREEQC_PTR_ARG) const struct conc *c; assert(this->type == cxxNameDouble::ND_ELT_MOLES); c = (struct conc *) - PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); if (c == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; @@ -256,7 +256,7 @@ cxxNameDouble::name_coef(PHREEQC_PTR_ARG) const assert(this->type == cxxNameDouble::ND_NAME_COEF); struct name_coef *name_coef_ptr = (struct name_coef *) - PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef))); if (name_coef_ptr == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; diff --git a/NumKeyword.h b/NumKeyword.h index 4fa31211..ef17dd35 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -6,19 +6,22 @@ #include // std::string class CParser; -extern char *string_duplicate(const char *); +//extern char *string_duplicate(const char *); class cxxNumKeyword { public: cxxNumKeyword(); virtual ~ cxxNumKeyword(); - - - char *get_description() const + const std::string &get_description() const { - return string_duplicate(this->description.c_str()); + return this->description; } + + //char *get_description() const + //{ + // return string_duplicate(this->description.c_str()); + //} void set_description(std::string str) { this->description = str; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 9b99490c..08f77070 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -88,7 +88,7 @@ cxxPPassemblage::cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG) { struct pp_assemblage *pp_assemblage_ptr = P_INSTANCE_POINTER pp_assemblage_alloc(); - pp_assemblage_ptr->description = this->get_description(); + pp_assemblage_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); pp_assemblage_ptr->n_user = this->n_user; pp_assemblage_ptr->n_user_end = this->n_user_end; pp_assemblage_ptr->new_def = FALSE; @@ -268,7 +268,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index bacf9aee..1f264995 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -74,7 +74,7 @@ cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::m { struct pure_phase *pure_phase_ptr = (struct pure_phase *) - PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); if (pure_phase_ptr == NULL) P_INSTANCE_POINTER malloc_error(); @@ -497,7 +497,7 @@ cxxPPassemblageComp::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & addee "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return; } //double si; diff --git a/Parser.cxx b/Parser.cxx index 6cd6a312..334d2050 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -5,21 +5,24 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include "Parser.h" -#include "Utils.h" -#include "output.h" #include // std::transform #include // std::map #include // assert #include // std::cout std::cerr +#include "Utils.h" +#if defined (PHREEQC_CLASS) +#include "Phreeqc.h" +#endif +#include "Parser.h" +#include "output.h" -extern char *string_hsave(const char *str); +//extern char *string_hsave(const char *str); ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CParser::CParser(std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), m_input_error(0), m_next_keyword(KT_NONE) { @@ -30,7 +33,7 @@ m_next_keyword(KT_NONE) accumulate = false; } -CParser::CParser(std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), m_input_error(0), m_next_keyword(KT_NONE) { @@ -41,7 +44,7 @@ m_next_keyword(KT_NONE) accumulate = false; } -CParser::CParser(std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), m_input_error(0), m_next_keyword(KT_NONE) { @@ -112,7 +115,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); } break; case EO_KEYWORDS: @@ -120,7 +123,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); } break; @@ -129,7 +132,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - output_msg(OUTPUT_MESSAGE, "%s", msg.str().c_str()); + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); } break; } @@ -870,7 +873,7 @@ CParser::get_option(const std::vector < std::string > &opt_list, int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) { - ::error_msg(err_str, (int) ot); + ERROR_MESSAGE_QUALIFIER error_msg(err_str, (int) ot); m_error_stream << "ERROR: " << err_str << "\n"; m_error_stream.flush(); @@ -1323,3 +1326,9 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, } return (j); } +int CParser:: +incr_input_error() +{ + ++ ERROR_MESSAGE_QUALIFIER input_error; + return ++m_input_error; +} \ No newline at end of file diff --git a/Parser.h b/Parser.h index 63ff0841..5fca6cd8 100644 --- a/Parser.h +++ b/Parser.h @@ -1,20 +1,31 @@ #if !defined(PARSER_H_INCLUDED) #define PARSER_H_INCLUDED -extern int input_error; #include // std::string #include // std::map #include // std::vector #include // std::istringstream std::ostringstream #include // std::ostream #include // std::istream +#include "Phreeqc_class.h" +#if defined (PHREEQC_CLASS) +class Phreeqc; +#define PHREEQC_NAME_SPACE Phreeqc:: +#define PHREEQC_COOKIE this->p_instance-> +#define ERROR_MESSAGE_QUALIFIER this->p_instance-> +#else +#define PHREEQC_NAME_SPACE :: +#define PHREEQC_COOKIE +#define ERROR_MESSAGE_QUALIFIER :: +extern int input_error; +#endif class CParser { public: - CParser(std::istream & input); - CParser(std::istream & input, std::ostream & output); - CParser(std::istream & input, std::ostream & output, + CParser(PHREEQC_PTR_ARG_COMMA std::istream & input); + CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output); + CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error); virtual ~ CParser(); @@ -166,11 +177,7 @@ class CParser { return m_line_iss; } - int incr_input_error() - { - ++::input_error; - return ++m_input_error; - } + int incr_input_error(); std::ostream & get_output() { return m_output_stream; @@ -302,7 +309,9 @@ class CParser ECHO_OPTION echo_file; std::string accumulated; bool accumulate; - //int const &input_error_parser; +#if defined(PHREEQC_CLASS) + Phreeqc * p_instance; +#endif }; // Global functions diff --git a/Reaction.cxx b/Reaction.cxx index e54bc249..efe4ca9d 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -83,11 +83,11 @@ cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) // { struct irrev *irrev_ptr; - irrev_ptr = (struct irrev *) PHRQ_malloc(sizeof(struct irrev)); + irrev_ptr = (struct irrev *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct irrev)); if (irrev_ptr == NULL) P_INSTANCE_POINTER malloc_error(); - irrev_ptr->description = this->get_description(); + irrev_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); irrev_ptr->n_user = this->n_user; irrev_ptr->n_user_end = this->n_user_end; @@ -108,7 +108,7 @@ cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) { irrev_ptr->steps = (double *) - PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (irrev_ptr->steps == NULL) P_INSTANCE_POINTER malloc_error(); std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); diff --git a/ReadClass.cxx b/ReadClass.cxx index ebd583ea..c6055cb1 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -86,7 +86,7 @@ read_solution_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -179,7 +179,7 @@ read_exchange_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -273,7 +273,7 @@ read_surface_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -368,7 +368,7 @@ read_equilibrium_phases_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -464,7 +464,7 @@ read_kinetics_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -559,7 +559,7 @@ read_solid_solutions_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -656,7 +656,7 @@ read_gas_phase_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -750,7 +750,7 @@ read_reaction_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -845,7 +845,7 @@ read_mix_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -940,7 +940,7 @@ read_temperature_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); if (pr.echo_input == FALSE) @@ -1017,7 +1017,7 @@ read_dump(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1069,7 +1069,7 @@ read_delete(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1121,7 +1121,7 @@ read_run_cells(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1191,7 +1191,7 @@ read_solution_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1278,7 +1278,7 @@ read_equilibrium_phases_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1366,7 +1366,7 @@ read_exchange_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1454,7 +1454,7 @@ read_surface_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1541,7 +1541,7 @@ read_solid_solutions_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1627,7 +1627,7 @@ read_gas_phase_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started @@ -1713,7 +1713,7 @@ read_kinetics_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); //For testing, need to read line to get started diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 1655dbfa..ea64ba22 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -86,7 +86,7 @@ cxxSSassemblage::cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG) { struct s_s_assemblage *s_s_assemblage_ptr = P_INSTANCE_POINTER s_s_assemblage_alloc(); - s_s_assemblage_ptr->description = this->get_description(); + s_s_assemblage_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); s_s_assemblage_ptr->n_user = this->n_user; s_s_assemblage_ptr->n_user_end = this->n_user_end; s_s_assemblage_ptr->new_def = FALSE; @@ -243,7 +243,7 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index f489bc35..e46ceecb 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -87,7 +87,7 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::s // generate s_s structures // struct s_s *s_s_ptr = - (struct s_s *) PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); + (struct s_s *) P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); if (s_s_ptr == NULL) P_INSTANCE_POINTER malloc_error(); int j = 0; @@ -129,7 +129,7 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::s int n; struct s_s_comp *s_s_comp_ptr = (struct s_s_comp *) - PHRQ_malloc((size_t) + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).second.comps.size() * sizeof(struct s_s_comp))); if (s_s_comp_ptr == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/Solution.cxx b/Solution.cxx index b97a1dba..2bb47169 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -122,7 +122,7 @@ cxxNumKeyword() sprintf(P_INSTANCE_POINTER error_string, "Solution %d not found in mix_cxxSolutions.", it->first); P_INSTANCE_POINTER error_msg(P_INSTANCE_POINTER error_string, CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; } else { @@ -284,7 +284,7 @@ cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) struct solution *solution_ptr = P_INSTANCE_POINTER solution_alloc(); - solution_ptr->description = this->get_description(); + solution_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); solution_ptr->n_user = this->n_user; solution_ptr->n_user_end = this->n_user_end; solution_ptr->new_def = FALSE; @@ -1389,7 +1389,7 @@ cxxSolution::mpi_send(int task_number) /* int count_isotopes; */ /* struct isotope *isotopes; */ - if (input_error > 0) + if (P_INSTANCE_POINTER input_error > 0) { std::string errstr("Stopping due to errors\n"); error_msg(errstr.c_str(), STOP); @@ -1405,7 +1405,7 @@ cxxSolution::mpi_send(int task_number) MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; - buffer = PHRQ_malloc(max_size); + buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* @@ -1453,7 +1453,7 @@ cxxSolution::mpi_recv(int task_number) MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); - void *buffer = PHRQ_malloc(max_size); + void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index bef1e969..d6eb64c1 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -49,7 +49,7 @@ cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIs { iso = (struct isotope *) - PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); if (iso == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 02f92b94..0e6cb878 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -96,7 +96,7 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG) { iso = (struct isotope *) - PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); if (iso == NULL) P_INSTANCE_POINTER malloc_error(); int i = 0; diff --git a/StorageBin.cxx b/StorageBin.cxx index ca429acc..7d3bb216 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1050,7 +1050,7 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) sprintf(error_string, "Solution %d not found in mix_cxxSolutions.", it->first); error_msg(error_string, CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return (NULL); } intensive = it->second / extensive; @@ -1066,7 +1066,7 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // { struct system *system_ptr = - (struct system *) PHRQ_malloc(sizeof(struct system)); + (struct system *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct system)); if (system_ptr == NULL) P_INSTANCE_POINTER malloc_error(); @@ -1249,7 +1249,7 @@ cxxStorageBin::mpi_send(int n, int task_number) MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; - void *buffer = PHRQ_malloc(max_size); + void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); @@ -1303,7 +1303,7 @@ cxxStorageBin::mpi_recv(int task_number) MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); - void *buffer = PHRQ_malloc(max_size); + void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* @@ -1447,7 +1447,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return (NULL); } new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr-> @@ -1468,7 +1468,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); - input_error++; + P_INSTANCE_POINTER input_error++; return (NULL); } // Add exchange components to vector ec_vector diff --git a/Surface.cxx b/Surface.cxx index e803088a..8a114144 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -150,7 +150,7 @@ cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) { struct surface *surface_ptr = P_INSTANCE_POINTER surface_alloc(); - surface_ptr->description = this->get_description(); + surface_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); surface_ptr->n_user = this->n_user; surface_ptr->n_user_end = this->n_user_end; surface_ptr->new_def = FALSE; @@ -542,7 +542,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) @@ -595,7 +595,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index cc3396d7..6791835b 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -91,7 +91,7 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map { struct surface_charge *surf_charge_ptr = (struct surface_charge *) - PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); if (surf_charge_ptr == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 95811d58..fc11b865 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -110,7 +110,7 @@ struct surface_comp * { struct surface_comp *surf_comp_ptr = (struct surface_comp *) - PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); if (surf_comp_ptr == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/Temperature.cxx b/Temperature.cxx index 7aa223e0..fff10e46 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -84,7 +84,7 @@ cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) if (temperature_ptr == NULL) P_INSTANCE_POINTER malloc_error(); - temperature_ptr->description = this->get_description(); + temperature_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); temperature_ptr->n_user = this->n_user; temperature_ptr->n_user_end = this->n_user_end; @@ -94,7 +94,7 @@ cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) { temperature_ptr->t = (double *) - PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); if (temperature_ptr->t == NULL) P_INSTANCE_POINTER malloc_error(); std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index e6e92f11..02d50055 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -115,7 +115,7 @@ cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) { struct kinetics *kinetics_ptr = P_INSTANCE_POINTER kinetics_alloc(); - kinetics_ptr->description = this->get_description(); + kinetics_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); kinetics_ptr->n_user = this->n_user; kinetics_ptr->n_user_end = this->n_user_end; kinetics_ptr->step_divide = this->step_divide; @@ -142,7 +142,7 @@ cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) { kinetics_ptr->steps = (double *) - PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (kinetics_ptr->steps == NULL) P_INSTANCE_POINTER malloc_error(); std::copy(this->steps.begin(), this->steps.end(), @@ -417,7 +417,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(is); + CParser reread(P_INSTANCE_COMMA is); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); diff --git a/cxxMix.cxx b/cxxMix.cxx index 9e5a51e7..473ba2fa 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -67,11 +67,11 @@ cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) // { struct mix *mix_ptr; - mix_ptr = (struct mix *) PHRQ_malloc(sizeof(struct mix)); + mix_ptr = (struct mix *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct mix)); if (mix_ptr == NULL) P_INSTANCE_POINTER malloc_error(); - mix_ptr->description = this->get_description(); + mix_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); mix_ptr->n_user = this->n_user; mix_ptr->n_user_end = this->n_user_end; @@ -82,7 +82,7 @@ cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) int i = 0; mix_ptr->comps = (struct mix_comp *) - PHRQ_malloc((size_t) + P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->mixComps.size() * sizeof(struct mix_comp))); if (mix_ptr->comps == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/phreeqc_class.h b/phreeqc_class.h index ff524d5d..5c374017 100644 --- a/phreeqc_class.h +++ b/phreeqc_class.h @@ -8,6 +8,7 @@ #define PHREEQC_PTR_ARG_COMMA #define PHREEQC_THIS #define PHREEQC_THIS_COMMA +#define PHREEQC_NAME_SPACE :: #else #define P_INSTANCE p_instance #define P_INSTANCE_COMMA p_instance, @@ -16,6 +17,7 @@ #define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance, #define PHREEQC_THIS this #define PHREEQC_THIS_COMMA this, +#define PHREEQC_NAME_SPACE Phreeqc:: #endif #endif /* _INC_PHREEQC_CLASS_H */ //#include "Phreeqc_class.h" \ No newline at end of file From 65ff0a9456960ba2d5e2cd28fa9741ef1f25f095 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Dec 2009 23:58:06 +0000 Subject: [PATCH 0124/1077] Fixed Makefile on Linux to make class version. Added eol and other changes for linux. Had statics in ReadClass.cxx, removed. Problems with .dmp files. May be because of statics. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3879 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 2 +- Makefile | 458 +++++++++++++++++------------ Parser.cxx | 2 +- Phreeqc.h | 3 + phreeqc_class.h => Phreeqc_class.h | 2 +- ReadClass.cxx | 3 + StorageBin.cxx | 14 +- SurfaceComp.cxx | 6 +- class_main.cpp | 1 - 9 files changed, 295 insertions(+), 196 deletions(-) rename phreeqc_class.h => Phreeqc_class.h (95%) diff --git a/Exchange.cxx b/Exchange.cxx index b1b6f545..c23a4f9f 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -582,4 +582,4 @@ const cxxNameDouble & cxxExchange::get_totals() const { return totals; -}; \ No newline at end of file +} diff --git a/Makefile b/Makefile index 459029ad..7e91819a 100644 --- a/Makefile +++ b/Makefile @@ -28,9 +28,14 @@ Release: release Debug: debug +Class_debug: class_debug + +Class_release: class_release RELEASE_DIR = Release DEBUG_DIR = Debug +CLASS_DEBUG_DIR = Class_debug +CLASS_DIR = Class_release MAKEFILE = Makefile # ----------------------------------------------------------------------------- @@ -51,6 +56,16 @@ debug: mkdir -p $(DEBUG_DIR) cd $(DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG $(PROGRAM) +.PHONY : Class_debug +class_debug: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) + +.PHONY : Class_release +class_release: + mkdir -p $(CLASS_DIR) + cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) + # Recursive make begins here # # ============================================================================= @@ -105,7 +120,7 @@ ifeq ($(CFG), RELEASE) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + OBJECT_FILES = $(MAIN_FILE) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif @@ -115,7 +130,27 @@ ifeq ($(CFG), DEBUG) INCLUDES = -I../phreeqc CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + OBJECT_FILES = $(MAIN_FILE) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_DEBUG) + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE) + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif @@ -136,7 +171,6 @@ COMMON_COBJS = \ inverse.o \ isotopes.o \ kinetics.o \ - main.o \ mainsubs.o \ model.o \ nvector.o \ @@ -163,6 +197,13 @@ COMMON_COBJS = \ transport.o \ utilities.o +MAIN_FILE = main.o + +CLASS_FILES = \ + class_main.o \ + Phreeqc.o + + COMMON_CXXOBJS = \ dumper.o \ Exchange.o \ @@ -209,157 +250,188 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../char_star.h \ - ../cxxKinetics.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../KineticsComp.h ../NameDouble.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../char_star.h ../cxxMix.h \ - ../NumKeyword.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ +cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../cxxKinetics.h \ + ../NumKeyword.h ../KineticsComp.h ../NameDouble.h ../Phreeqc_class.h \ + ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../cxxMix.h ../NumKeyword.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Dictionary.o: ../Dictionary.cxx ../Dictionary.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +Exchange.o: ../Exchange.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../cxxMix.h \ + ../Phreeqc_class.h ../NumKeyword.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h +ExchComp.o: ../ExchComp.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ExchComp.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ ../phreeqc/output.h -Exchange.o: ../Exchange.cxx ../Utils.h ../char_star.h ../Exchange.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../NameDouble.h \ - ../Parser.h ../cxxMix.h ../NumKeyword.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../char_star.h ../ExchComp.h \ - ../NameDouble.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../char_star.h ../GasPhase.h \ - ../NumKeyword.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -ISolutionComp.o: ../ISolutionComp.cxx ../ISolutionComp.h ../Utils.h \ - ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../ISolution.h \ - ../NumKeyword.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/output.h -ISolution.o: ../ISolution.cxx ../ISolution.h ../ISolutionComp.h \ - ../Utils.h ../char_star.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../NumKeyword.h \ - ../Parser.h ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../NameDouble.h ../cxxMix.h ../phreeqc/output.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../char_star.h \ - ../KineticsComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../char_star.h ../NameDouble.h \ - ../Parser.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/output.h \ +GasPhase.o: ../GasPhase.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../GasPhase.h \ + ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h +ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ISolutionComp.h \ + ../Phreeqc_class.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h +ISolution.o: ../ISolution.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ISolution.h \ + ../ISolutionComp.h ../Phreeqc_class.h ../NumKeyword.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../KineticsComp.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ - ../char_star.h -Parser.o: ../Parser.cxx ../Parser.h ../char_star.h ../Utils.h \ + ../Phreeqc_class.h +Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ ../phreeqc/output.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../char_star.h \ - ../PPassemblageComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../char_star.h \ - ../PPassemblage.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../PPassemblageComp.h ../NameDouble.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Reaction.o: ../Reaction.cxx ../Utils.h ../char_star.h ../Reaction.h \ - ../NumKeyword.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -ReadClass.o: ../ReadClass.cxx ../Parser.h ../char_star.h ../Solution.h \ +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../PPassemblageComp.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../NameDouble.h ../cxxMix.h ../Exchange.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ - ../phreeqc/phrqproto.h ../SurfaceCharge.h ../PPassemblage.h \ - ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../SSassemblageSS.h ../GasPhase.h ../Reaction.h \ - ../Temperature.h ../dumper.h ../StorageBinList.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h -SAXPhreeqc.o: ../SAXPhreeqc.cxx ../SAXPhreeqc.h ../SaxPhreeqcHandlers.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h -Solution.o: ../Solution.cxx ../Utils.h ../char_star.h ../Solution.h \ - ../NumKeyword.h ../Parser.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h ../ISolution.h ../ISolutionComp.h ../Exchange.h \ - ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../PPassemblage.h ../PPassemblageComp.h ../cxxKinetics.h \ - ../KineticsComp.h ../SSassemblage.h ../SSassemblageSS.h ../GasPhase.h \ - ../Reaction.h ../Temperature.h ../StorageBin.h ../System.h -SolutionIsotope.o: ../SolutionIsotope.cxx ../SolutionIsotope.h \ - ../Parser.h ../char_star.h ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ - ../char_star.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../PPassemblage.h \ + ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +Reaction.o: ../Reaction.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../Reaction.h \ + ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../char_star.h \ - ../SSassemblage.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../SSassemblageSS.h ../NameDouble.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../char_star.h \ - ../SSassemblageSS.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../char_star.h ../StorageBin.h \ - ../Parser.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../Exchange.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../GasPhase.h \ - ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ - ../Surface.h ../SurfaceComp.h ../phreeqc/phrqproto.h ../SurfaceCharge.h \ - ../System.h ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h -SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../char_star.h \ - ../SurfaceCharge.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../phreeqc/output.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../char_star.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phrqproto.h ../Dictionary.h \ +ReadClass.o: ../ReadClass.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../Phreeqc_class.h ../Parser.h \ ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ + ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ + ../Temperature.h ../dumper.h ../StorageBinList.h ../runner.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +SAXPhreeqc.o: ../SAXPhreeqc.cxx ../SAXPhreeqc.h ../SaxPhreeqcHandlers.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/phrqproto.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h +Solution.o: ../Solution.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../Solution.h \ + ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h +SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SSassemblage.h \ + ../Phreeqc_class.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ + ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h +SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../SSassemblageSS.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../StorageBin.h ../System.h \ + ../SSassemblage.h ../NumKeyword.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h \ + ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h +SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SurfaceCharge.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ ../phreeqc/output.h -Surface.o: ../Surface.cxx ../Utils.h ../char_star.h ../Surface.h \ - ../NumKeyword.h ../Parser.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../SurfaceComp.h ../NameDouble.h ../phreeqc/phrqproto.h \ - ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h -System.o: ../System.cxx ../System.h ../Solution.h ../NumKeyword.h \ - ../Parser.h ../char_star.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../cxxMix.h ../Exchange.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../ExchComp.h ../GasPhase.h \ - ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ - ../Surface.h ../SurfaceComp.h ../phreeqc/phrqproto.h ../SurfaceCharge.h \ - ../Reaction.h ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../char_star.h \ - ../Temperature.h ../NumKeyword.h ../Parser.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Utils.o: ../Utils.cxx ../Utils.h ../char_star.h ../Parser.h \ +SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SurfaceComp.h \ + ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ ../phreeqc/output.h -dumper.o: ../dumper.cpp ../dumper.h ../Parser.h ../char_star.h \ - ../StorageBinList.h +Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h \ + ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../Surface.h ../NumKeyword.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +System.o: ../System.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../System.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../SSassemblage.h ../NumKeyword.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../cxxKinetics.h \ + ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../cxxMix.h ../Reaction.h ../Temperature.h +Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h \ + ../Phreeqc_class.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../Temperature.h ../NumKeyword.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h +Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/output.h +class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/sundialstypes.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../phreeqc/nvector_serial.h ../phreeqc/dense.h ../phreeqc/p2c.h \ + ../phreeqc/global_structures.h ../phreeqc/pitzer_structures.h \ + ../phreeqc/pitzer.h ../phreeqc/input.h ../phreeqc/output.h \ + ../phreeqc/global.h ../phreeqc/global_structures.h \ + ../phreeqc/phrqproto.h +dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../Parser.h \ + ../Phreeqc_class.h +Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/sundialstypes.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../phreeqc/nvector_serial.h ../phreeqc/dense.h ../phreeqc/p2c.h \ + ../phreeqc/global_structures.h ../phreeqc/pitzer_structures.h \ + ../phreeqc/pitzer.h ../phreeqc/input.h ../phreeqc/output.h \ + ../phreeqc/global.h ../phreeqc/global_structures.h +runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../Parser.h \ + ../Phreeqc_class.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h ../Parser.h \ - ../char_star.h + ../Phreeqc_class.h # # PHREEQC files # advection.o: ../phreeqc/advection.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h basic.o: ../phreeqc/basic.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/p2c.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/p2c.h \ + ../phreeqc/basic.h basicsubs.o: ../phreeqc/basicsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h cl1.o: ../phreeqc/cl1.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ ../phreeqc/phrqtype.h cl1mp.o: ../phreeqc/cl1mp.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ @@ -375,83 +447,105 @@ dense.o: ../phreeqc/dense.c ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../phreeqc/output.h ../phreeqc/phqalloc.h dw.o: ../phreeqc/dw.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h ../phreeqc/pitzer.h input.o: ../phreeqc/input.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/input.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/input.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h inverse.o: ../phreeqc/inverse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h isotopes.o: ../phreeqc/isotopes.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h -kinetics.o: ../phreeqc/kinetics.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/sundialstypes.h ../phreeqc/cvode.h \ - ../phreeqc/nvector.h ../phreeqc/cvdense.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../phreeqc/nvector_serial.h \ - ../phreeqc/kinetics.h -main.o: ../phreeqc/main.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/input.h -mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/input.h -model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h +kinetics.o: ../phreeqc/kinetics.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/sundialstypes.h ../phreeqc/cvode.h ../phreeqc/nvector.h \ + ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../phreeqc/nvector_serial.h ../phreeqc/kinetics.h +main.o: ../phreeqc/main.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/input.h +mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/input.h +model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ ../phreeqc/nvector.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h output.o: ../phreeqc/output.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h p2clib.o: ../phreeqc/p2clib.c ../phreeqc/p2c.h ../phreeqc/output.h parse.o: ../phreeqc/parse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h phqalloc.o: ../phreeqc/phqalloc.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/output.h phreeqc_files.o: ../phreeqc/phreeqc_files.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/input.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/input.h pitzer.o: ../phreeqc/pitzer.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h pitzer_structures.o: ../phreeqc/pitzer_structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/pitzer.h -prep.o: ../phreeqc/prep.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -print.o: ../phreeqc/print.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer.h + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h +prep.o: ../phreeqc/prep.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h +print.o: ../phreeqc/print.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/pitzer.h read.o: ../phreeqc/read.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h readtr.o: ../phreeqc/readtr.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h +sit.o: ../phreeqc/sit.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h smalldense.o: ../phreeqc/smalldense.c ../phreeqc/smalldense.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h spread.o: ../phreeqc/spread.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h step.o: ../phreeqc/step.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h structures.o: ../phreeqc/structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h sundialsmath.o: ../phreeqc/sundialsmath.c ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h tally.o: ../phreeqc/tally.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h tidy.o: ../phreeqc/tidy.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h transport.o: ../phreeqc/transport.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h # ----------------------------------------------------------------------------- clean: @@ -459,7 +553,7 @@ clean: dependencies: mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp + cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.c tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/Parser.cxx b/Parser.cxx index 334d2050..b1e09846 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1331,4 +1331,4 @@ incr_input_error() { ++ ERROR_MESSAGE_QUALIFIER input_error; return ++m_input_error; -} \ No newline at end of file +} diff --git a/Phreeqc.h b/Phreeqc.h index 7f13054e..52ade92d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -25,6 +25,9 @@ /* NV_Ith_S, prototypes for N_VNew, N_VFree */ #include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM */ #include "nvector.h" +#include "runner.h" +#include "dumper.h" +#include "StorageBinList.h" #define STATIC #define EXTERNAL diff --git a/phreeqc_class.h b/Phreeqc_class.h similarity index 95% rename from phreeqc_class.h rename to Phreeqc_class.h index 5c374017..b5d95d0f 100644 --- a/phreeqc_class.h +++ b/Phreeqc_class.h @@ -20,4 +20,4 @@ #define PHREEQC_NAME_SPACE Phreeqc:: #endif #endif /* _INC_PHREEQC_CLASS_H */ -//#include "Phreeqc_class.h" \ No newline at end of file +//#include "Phreeqc_class.h" diff --git a/ReadClass.cxx b/ReadClass.cxx index c6055cb1..633a65b9 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -30,6 +30,8 @@ #include "phrqproto.h" #include "output.h" + +#if !defined(PHREEQC_CLASS) static int streamify_to_next_keyword(std::istringstream & lines); extern int reading_database(void); extern int check_line(const char *string, int allow_empty, int allow_eof, @@ -39,6 +41,7 @@ extern int copy_use(int i); dumper dump_info; StorageBinList delete_info; runner run_info; +#endif /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER diff --git a/StorageBin.cxx b/StorageBin.cxx index 7d3bb216..c2229da8 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -340,37 +340,37 @@ const std::map < int, cxxSolution > & cxxStorageBin::getSolutions() const { return this->Solutions; -}; +} const std::map < int, cxxExchange > & cxxStorageBin::getExchangers() const { return this->Exchangers; -}; +} const std::map < int, cxxGasPhase > & cxxStorageBin::getGasPhases() const { return this->GasPhases; -}; +} const std::map < int, cxxKinetics > & cxxStorageBin::getKinetics() const { return this->Kinetics; -}; +} const std::map < int, cxxPPassemblage > & cxxStorageBin::getPPassemblages() const { return this->PPassemblages; -}; +} const std::map < int, cxxSSassemblage > & cxxStorageBin::getSSassemblages() const { return this->SSassemblages; -}; +} const std::map < int, cxxSurface > & cxxStorageBin::getSurfaces() const { return this->Surfaces; -}; +} void cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index fc11b865..30d650ab 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -715,13 +715,13 @@ const cxxNameDouble & cxxSurfaceComp::get_totals() const { return (this->totals); -}; +} std::string cxxSurfaceComp::charge_name(PHREEQC_PTR_ARG) { char * str = P_INSTANCE_POINTER string_hsave(this->formula.c_str()); return (get_charge_name(P_INSTANCE_COMMA str)); -}; +} std::string cxxSurfaceComp::get_charge_name(PHREEQC_PTR_ARG_COMMA char *token) { @@ -735,4 +735,4 @@ cxxSurfaceComp::get_charge_name(PHREEQC_PTR_ARG_COMMA char *token) ptr1[0] = '\0'; } return (std::string(name)); -}; \ No newline at end of file +} diff --git a/class_main.cpp b/class_main.cpp index 0cbca6ed..a5749bf8 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -4,7 +4,6 @@ #include "input.h" - /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ From b454429379eaeaa90618e026de5641943b938bc6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Dec 2009 01:03:21 +0000 Subject: [PATCH 0125/1077] Fixed error with callback. Had not saved the phreeqc pointer in the parser constructor. Fixed project, directories for versions were all messed up. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3881 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Parser.cxx b/Parser.cxx index b1e09846..4f76f32e 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -31,6 +31,9 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance; +#endif } CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), @@ -42,6 +45,9 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance; +#endif } CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), @@ -53,6 +59,9 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance; +#endif } CParser::~CParser() From 7dbc8d063280d7cb8d8e000d538374f58276046f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Dec 2009 16:28:52 +0000 Subject: [PATCH 0126/1077] PHREEQC runs as class. Have fixed bugs with dump_cpp. Checking in Release results for test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3884 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7e91819a..ae5c643a 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ else SPOOL2= endif -all: release debug +all: release debug class_release class_debug Release: release @@ -243,7 +243,7 @@ COMMON_CXXOBJS = \ ${PROGRAM} : ${OBJECT_FILES} ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} - @echo; echo Done making for phast + @echo; echo Done making for phreeqcpp # ----------------------------------------------------------------------------- # Module dependency list # ----------------------------------------------------------------------------- From d8506413365bccb3a030a62256d0f4f6b15a61a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Dec 2009 17:35:19 +0000 Subject: [PATCH 0127/1077] mpi.h needs to be defined first because of a conflict with stdio (SEEK_SET ifdef). output.h is needed for NameDouble mpi version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3886 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 5 +++-- NameDouble.h | 2 +- Solution.cxx | 5 +++-- StorageBin.cxx | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 530174a1..c36fead0 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -20,6 +20,7 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" +#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -477,7 +478,7 @@ cxxNameDouble::mpi_pack(std::vector < int >&ints, } } void -cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) +cxxNameDouble::mpi_pack(PHREEQC_PTR_ARG_COMMA int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; @@ -490,7 +491,7 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) if (n < 0) { std::cerr << it->first << std::endl; - error_msg("Name in NameDouble was not defined in dictionary?\n", + P_INSTANCE_POINTER error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); } //ints.push_back(n); diff --git a/NameDouble.h b/NameDouble.h index 470585d4..09e0f541 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -73,7 +73,7 @@ class cxxNameDouble:public } void - mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + mpi_pack(PHREEQC_PTR_ARG_COMMA std::vector < int >&ints, std::vector < double >&doubles); void mpi_pack(int *ints, int *ii, double *doubles, int *dd); diff --git a/Solution.cxx b/Solution.cxx index 2bb47169..0eecc1c3 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -4,13 +4,14 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#include // assert -#include // std::sort + #ifdef USE_MPI //MPICH seems to require mpi.h to be first #include #endif +#include // assert +#include // std::sort #include "Utils.h" // define first #if !defined(PHREEQC_CLASS) #define EXTERNAL extern diff --git a/StorageBin.cxx b/StorageBin.cxx index c2229da8..74164a10 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -4,15 +4,15 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif +#ifdef USE_MPI +//MPICH seems to require mpi.h to be first +#include +#endif #include #include // std::cout std::cerr #include // assert #include // std::sort -#ifdef USE_MPI -//MPICH seems to require mpi.h to be first -#include -#endif #include "Utils.h" // define first #if !defined(PHREEQC_CLASS) #define EXTERNAL extern From 490fd2be41dab1165a38130e4a98a0618be6c7cb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 21 Dec 2009 20:36:36 +0000 Subject: [PATCH 0128/1077] Added options to the UNITS keyword to allow moles of solid reactants to be interpreted as moles per liter of WATER or moles per liter of ROCK: UNITS -equilibrium_phases ROCK -exchange ROCK -surface WATER -solid_solution WATER -kinetics WATER -gas_phase WATER By default, the number of moles of solid reactants are interpreted as per liter of water. Using the ROCK option, PHAST interprets the number of moles of solid reactants obtained from the initial PHREEQC calculation as per liter of rock. Note that an initial PHREEQC calculation is made at the beginning of a PHAST run. During this calculation all reaction calculations interpret the concentration of solid reactants as simply moles. (When a solution is reacted with the solids, the solution contains a mass of water, which is usually 1 kg, but not necessarily.) It is only when initial conditions are subsequently distributed in the PHAST calculation that solid reactants are scaled. If the units are WATER, t here is no scaling and the number of moles of solids is the number of moles per liter of water. If the units are ROCK, the number of moles of a solid reactant is multiplied by (1-phi)/phi, where phi is the porosity in the cell receiving the initial condition, to arrive at the number of moles of solid reactant per liter of water. The addition of the ROCK option is motivated by the possibility of a domain with a distribution of porosities. In this case, the number of moles of solid reactants per liter of water-- the units used by PHAST--also vary spatially. By using the ROCK option, a constant rock composition can be defined and the factor (1-phi)/phi is used to scale the number of moles of solid reactant to obtain the number of moles per liter of water in each cell. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3902 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxMix.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cxxMix.h b/cxxMix.h index 107471ae..7660209d 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -36,6 +36,14 @@ class cxxMix:public cxxNumKeyword mixComps[n] = f; } }; + void multiply(double f) + { + for (std::map < int, double >::iterator it = this->mixComps.begin(); + it != this->mixComps.end(); it++) + { + it->second *= f; + } + }; std::map < int, double >*comps() { From 694c07488e9acaa7cdb7de383d4aa5d0c56a38c6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 14 Jan 2010 16:26:14 +0000 Subject: [PATCH 0129/1077] Bugs with kinetics in PHAST. The formula was not correct when converted to a phreeqcpp class, only the last instance of an element was kept and the rest were lost. Modified NameDouble to accumulate the sum of coefficients for each element when converting from a PHREEQC structure. The order of the kinetics components was not maintained when converted to a phreeqcpp class. Components were in alphabetical order. This posed a problem with get and put statements because the gets could end up before the puts. Changed from map of components to list of components, which should maintain the order correctly. Problems with modify solution and redox elements. Laurin pointed out that adding N may leave all the N(x) in place, which increases the total N. Revised read_solution to merge the valence states. If N defined, then all N(x) are removed. If N() defined, then N is removed. Still need to test. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3927 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 28 +++++++-------- KineticsComp.h | 2 +- NameDouble.cxx | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ NameDouble.h | 3 ++ Solution.cxx | 26 ++++++++++---- cxxKinetics.cxx | 66 +++++++++++++++++++++++++++++------- cxxKinetics.h | 3 +- 7 files changed, 182 insertions(+), 34 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index f777a0c9..0d015b8b 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -59,7 +59,7 @@ cxxKineticsComp::~cxxKineticsComp() } struct kinetics_comp * - cxxKineticsComp::cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxKineticsComp > + cxxKineticsComp::cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el) // // Builds kinetics_comp structure from of cxxKineticsComp @@ -72,20 +72,20 @@ struct kinetics_comp * P_INSTANCE_POINTER malloc_error(); int i = 0; - for (std::map < std::string, cxxKineticsComp >::iterator it = el.begin(); + for (std::list < cxxKineticsComp >::iterator it = el.begin(); it != el.end(); ++it) { - if ((*it).second.rate_name.size() == 0) + if ((*it).rate_name.size() == 0) kinetics_comp_ptr[i].rate_name = NULL; else - kinetics_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); - kinetics_comp_ptr[i].list = (*it).second.namecoef.name_coef(P_INSTANCE); - kinetics_comp_ptr[i].count_list = (int) (*it).second.namecoef.size(); - kinetics_comp_ptr[i].tol = (*it).second.tol; - kinetics_comp_ptr[i].m = (*it).second.m; + kinetics_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).rate_name.c_str()); + kinetics_comp_ptr[i].list = (*it).namecoef.name_coef(P_INSTANCE); + kinetics_comp_ptr[i].count_list = (int) (*it).namecoef.size(); + kinetics_comp_ptr[i].tol = (*it).tol; + kinetics_comp_ptr[i].m = (*it).m; kinetics_comp_ptr[i].initial_moles = 0.; - kinetics_comp_ptr[i].m0 = (*it).second.m0; - kinetics_comp_ptr[i].moles = (*it).second.moles; + kinetics_comp_ptr[i].m0 = (*it).m0; + kinetics_comp_ptr[i].moles = (*it).moles; kinetics_comp_ptr[i].count_c_params = 0; kinetics_comp_ptr[i].c_params = NULL; /* @@ -93,15 +93,15 @@ struct kinetics_comp * kinetics_comp_ptr[i].d_params = NULL; */ - kinetics_comp_ptr[i].count_d_params = (int) (*it).second.d_params.size(); + kinetics_comp_ptr[i].count_d_params = (int) (*it).d_params.size(); kinetics_comp_ptr[i].d_params = NULL; - if ((*it).second.d_params.size() > 0) + if ((*it).d_params.size() > 0) { kinetics_comp_ptr[i].d_params = (double *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).second.d_params.size() * sizeof(double))); + P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).d_params.size() * sizeof(double))); if (kinetics_comp_ptr[i].d_params == NULL) P_INSTANCE_POINTER malloc_error(); - std::copy((*it).second.d_params.begin(), (*it).second.d_params.end(), + std::copy((*it).d_params.begin(), (*it).d_params.end(), kinetics_comp_ptr[i].d_params); } i++; diff --git a/KineticsComp.h b/KineticsComp.h index 754034d7..acecc8c7 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -17,7 +17,7 @@ public: cxxKineticsComp(struct kinetics_comp *); ~cxxKineticsComp(); - static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxKineticsComp > &el); + static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/NameDouble.cxx b/NameDouble.cxx index c36fead0..2c16de98 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -114,6 +114,7 @@ cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, } this->type = type; } +/* cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) // // constructor for cxxNameDouble from list of elt_list @@ -128,6 +129,30 @@ cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) } this->type = ND_NAME_COEF; } +*/ +cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) + // + // constructor for cxxNameDouble from list of elt_list + // +{ + int i; + for (i = 0; i < count; i++) + { + if (nc[i].name == NULL) + continue; + + if ((*this).find(nc[i].name) == (*this).end()) + { + (*this)[nc[i].name] = nc[i].coef; + } + else + { + (*this)[nc[i].name] = (*this).find(nc[i].name)->second + nc[i].coef; + } + + } + this->type = ND_NAME_COEF; +} cxxNameDouble::~cxxNameDouble() { @@ -462,7 +487,70 @@ cxxNameDouble::multiply(double extensive) it->second *= extensive; } } +void +cxxNameDouble::merge_redox(const cxxNameDouble & source) +// +// Merges source into this +// Accounts for possible conflicts between redox state and +// totals +// +{ + for (cxxNameDouble::const_iterator sit = source.begin(); sit != source.end(); sit++) + { + + std::string redox_name = sit->first; + std::string elt_name; + size_t pos = redox_name.find("("); + bool redox; + if (pos != std::string::npos) + { + redox = true; + elt_name = redox_name.substr(0, pos - 1); + } + else + { + redox = false; + elt_name = redox_name; + } + if (redox) + { + // Remove elt_name, if present + if ((*this).find(elt_name) != (*this).end()) + { + (*this).erase((*this).find(elt_name)); + } + // Put in redox name + (*this)[redox_name] = sit->second; + } + else + { + std::string substring; + substring.append(elt_name); + substring.append("("); + + // Remove all redox + bool deleted = true; + while (deleted) + { + deleted = false; + cxxNameDouble::iterator current = (*this).begin(); + for ( ; current != (*this).end(); current++) + { + if (current->first.find(substring) == 0) + { + (*this).erase(current); + deleted = true; + break; + } + } + } + // Put in elt name + (*this)[elt_name] = sit->second; + } + + } +} #ifdef USE_MPI void cxxNameDouble::mpi_pack(std::vector < int >&ints, diff --git a/NameDouble.h b/NameDouble.h index 09e0f541..e94c533e 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -66,6 +66,9 @@ class cxxNameDouble:public void multiply(double factor); + void + merge_redox(const cxxNameDouble & source); + void insert(char *str, double d) { diff --git a/Solution.cxx b/Solution.cxx index 0eecc1c3..f5a15ba5 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -630,13 +630,27 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) continue; case 0: // totals - if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != - CParser::PARSER_OK) + //if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + // CParser::PARSER_OK) + //{ + // parser.incr_input_error(); + // parser. + // error_msg("Expected element name and moles for totals.", + // CParser::OT_CONTINUE); + //} { - parser.incr_input_error(); - parser. - error_msg("Expected element name and moles for totals.", - CParser::OT_CONTINUE); + cxxNameDouble temp_totals; + if (temp_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg("Expected element name and moles for totals.", + CParser::OT_CONTINUE); + } + else + { + this->totals.merge_redox(temp_totals); + } } opt_save = 0; break; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 02d50055..9856cd8b 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -66,7 +66,8 @@ totals(kinetics_ptr->totals) { cxxKineticsComp ec(&(kinetics_ptr->comps[i])); std::string str(ec.get_rate_name()); - this->kineticsComps[str] = ec; + //this->kineticsComps[str] = ec; + this->kineticsComps.push_back(ec); } // steps @@ -231,12 +232,12 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "-cvode_order " << this->cvode_order << std::endl; // kineticsComps structures - for (std::map < std::string, cxxKineticsComp >::const_iterator it = + for (std::list < cxxKineticsComp >::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { s_oss << indent1; s_oss << "-component" << std::endl; - (*it).second.dump_raw(s_oss, indent + 2); + (*it).dump_raw(s_oss, indent + 2); } // totals @@ -421,6 +422,28 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); + std::list < cxxKineticsComp >::iterator kit; + bool found = false; + for (kit = this->kineticsComps.begin(); kit != this->kineticsComps.end(); kit++) + { + if (kit->get_rate_name() == ec.get_rate_name()) + { + found = true; + break; + } + } + if (found) + { + kit->read_raw(P_INSTANCE_COMMA reread, false); + } + else + { + cxxKineticsComp ec1; + ec1.read_raw(P_INSTANCE_COMMA reread, false); + std::string str(ec1.get_rate_name()); + this->kineticsComps.push_back(ec1); + } + /* if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) { cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; @@ -433,6 +456,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) std::string str(ec1.get_rate_name()); this->kineticsComps[str] = ec1; } + */ } useLastLine = true; break; @@ -554,11 +578,18 @@ cxxKinetics::mpi_pack(std::vector < int >&ints, { ints.push_back(this->n_user); ints.push_back((int) this->kineticsComps.size()); + std::list < cxxKineticsComp >::iterator it; + for (it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) + { + (*it).mpi_pack(ints, doubles); + } + /* for (std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { (*it).second.mpi_pack(ints, doubles); } + */ ints.push_back((int) this->steps.size()); for (std::vector < double >::iterator it = this->steps.begin(); it != this->steps.end(); it++) @@ -588,8 +619,9 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { cxxKineticsComp kc; kc.mpi_unpack(ints, &i, doubles, &d); - std::string str(kc.get_rate_name()); - this->kineticsComps[str] = kc; + //std::string str(kc.get_rate_name()); + //this->kineticsComps[str] = kc; + this->kineticsComps.push_back(kc); } n = ints[i++]; this->steps.clear(); @@ -664,21 +696,31 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) if (extensive == 0.0) return; //std::map < std::string, cxxKineticsComp> kineticsComps; - for (std::map < std::string, cxxKineticsComp >::const_iterator itadd = + for (std::list < cxxKineticsComp >::const_iterator itadd = addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); ++itadd) { - std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.find((*itadd).first); - if (it != this->kineticsComps.end()) + bool found(false); + std::list < cxxKineticsComp >::iterator it; + for (it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { - (*it).second.add((*itadd).second, extensive); + if ((*it).get_rate_name() == (*itadd).get_rate_name()) + { + found = true; + break; + } + } + + //std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.find((*itadd).first); + if (found) + { + (*it).add((*itadd), extensive); } else { - cxxKineticsComp entity = (*itadd).second; + cxxKineticsComp entity = (*itadd); entity.multiply(extensive); - std::string str(entity.get_rate_name()); - this->kineticsComps[str] = entity; + this->kineticsComps.push_back(entity); } } //std::vector steps; diff --git a/cxxKinetics.h b/cxxKinetics.h index 750b4d03..014b911d 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -43,7 +43,8 @@ class cxxKinetics:public cxxNumKeyword void add(const cxxKinetics & addee, double extensive); protected: - std::map < std::string, cxxKineticsComp > kineticsComps; + //std::map < std::string, cxxKineticsComp > kineticsComps; + std::list < cxxKineticsComp > kineticsComps; std::vector < double >steps; cxxNameDouble totals; double step_divide; From ef46b2f30e5bb0c4297cfc40c8c4acca65ced548 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Feb 2010 22:59:19 +0000 Subject: [PATCH 0130/1077] Fixed remove_unstable_phases for class git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3988 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index 52ade92d..28dc2cac 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -510,7 +510,7 @@ int initial_guesses(void); int revise_guesses(void); int s_s_binary(struct s_s *s_s_ptr); int s_s_ideal(struct s_s *s_s_ptr); -int remove_unstable_phases; +//int remove_unstable_phases; int gas_in; void ineq_init(int max_row_count, int max_column_count); From 7b777201e20a20c0d21bee7a9d83cecb374c7a57 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Feb 2010 20:03:02 +0000 Subject: [PATCH 0131/1077] Added viscosity function for SC at temperature. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4007 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 28dc2cac..88acfcb7 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1333,6 +1333,7 @@ int sum_surface_comp(struct surface *source1, LDBLE f1, struct surface *target, LDBLE new_Dw); int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, LDBLE new_Dw, int cell); +LDBLE viscosity(void); int multi_D(LDBLE DDt, int mobile_cell, int stagnant); int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); From 5e23f440df528abd64aeb31776dc54ab9e149e45 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 5 Feb 2010 17:11:16 +0000 Subject: [PATCH 0132/1077] Made pressurs a synonym of total_p in gas_phase_modify. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4011 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GasPhase.cxx b/GasPhase.cxx index 4deae732..cfba99be 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -273,6 +273,7 @@ cxxGasPhase::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) vopts.push_back("total_p"); //1 vopts.push_back("volume"); //2 vopts.push_back("component"); //3 + vopts.push_back("pressure"); //4 } std::istream::pos_type ptr; @@ -337,6 +338,7 @@ cxxGasPhase::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 1: // total_p + case 4: // pressure if (!(parser.get_iss() >> this->total_p)) { this->total_p = 0; From ef4a5b530e8cf9371f5a106ecbfaa2d699008736 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Feb 2010 21:04:30 +0000 Subject: [PATCH 0133/1077] Before modification to use standard database files, shorten run times, and limit output. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4038 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae5c643a..025b37b7 100644 --- a/Makefile +++ b/Makefile @@ -549,7 +549,7 @@ utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ # ----------------------------------------------------------------------------- clean: - rm -rf Release Debug + rm -rf Release Debug Class_release Class_debug dependencies: mkdir -p $(DEBUG_DIR) From 81717e1878474d96d738e06df01b056304957899 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 Feb 2010 22:47:02 +0000 Subject: [PATCH 0134/1077] Removing zero editing. Adding all files from phreeqc using ../database git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4039 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 025b37b7..18abe510 100644 --- a/Makefile +++ b/Makefile @@ -556,8 +556,10 @@ dependencies: cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.c tester: - cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) +# cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) +# cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) + cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples From 4ddc83581ce96ff72e416d388002162aeec291b1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 23 Feb 2010 19:32:06 +0000 Subject: [PATCH 0135/1077] Added equilibrium_phase keyword to Phreeqc.cpp constructor git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4116 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 81259b91..8e0d816a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -125,7 +125,8 @@ Phreeqc::Phreeqc(void) {"isotope_alphas", 0}, {"copy", 0}, {"pitzer", 0}, - {"sit", 0} + {"sit", 0}, + {"equilibrium_phase"} #ifdef PHREEQC_CPP , {"solution_raw", 0}, From e245f8afa073d151d156203545a7339ab8f366fc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 5 Mar 2010 21:20:09 +0000 Subject: [PATCH 0136/1077] Updated for IPhreeqc to use PHREEQC_CPP and PHREEQC_CLASS. Currently doesn't include gmp. MemDebug project still needs work. Needs to be tested on linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4145 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 3 +++ Phreeqc.h | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 8e0d816a..757db500 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -8,6 +8,7 @@ Phreeqc::Phreeqc(void) { + phast = FALSE; s_pTail = NULL; user_database = NULL; output = NULL; @@ -15,6 +16,8 @@ Phreeqc::Phreeqc(void) punch_file = NULL; dump_file = NULL; error_file = NULL; + database_file = NULL; + input_file = NULL; rates = NULL; tally_table = NULL; spec = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 88acfcb7..e3213536 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -547,7 +547,7 @@ void *PHRQ_realloc(void *, size_t); void PHRQ_free(void *ptr); void PHRQ_free_all(void); -private: +protected: // phreeqc_files.c ------------------------------- @@ -1188,7 +1188,7 @@ int surface_delete(int n_user_old); int surface_duplicate(int n_user_old, int n_user_new); public: int surface_free(struct surface *surface_ptr); -private: +protected: int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description); int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); @@ -1362,7 +1362,7 @@ int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: int compute_gfw(const char *string, LDBLE * gfw); -private: +protected: int copy_token(char *token_ptr, char **ptr, int *length); int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); @@ -1412,9 +1412,8 @@ Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); #if defined(SWIG_SHARED_OBJ) -int EndRow(void); -void AddSelectedOutput(const char *name, const char *format, - va_list argptr); +public: +virtual int EndRow(void); #endif From 9ed87e33add949ab03ba30360709be2372275ac2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 5 Mar 2010 23:00:20 +0000 Subject: [PATCH 0137/1077] std header files added. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4146 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 1 + Utils.cxx | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Parser.cxx b/Parser.cxx index 4f76f32e..c3e792df 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -10,6 +10,7 @@ #include // assert #include // std::cout std::cerr #include "Utils.h" +#include #if defined (PHREEQC_CLASS) #include "Phreeqc.h" #endif diff --git a/Utils.cxx b/Utils.cxx index 230523c3..858ee069 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -5,6 +5,7 @@ #include // ::tolower #include //std::transform #include // std::cout std::cerr +#include #include "Utils.h" #include "Parser.h" @@ -66,7 +67,7 @@ Utilities::replace(const char *str1, const char *str2, std::string & str) if (n == std::string::npos) return false; - str.replace(n,::strlen(str1), str2); + str.replace(n, ::strlen(str1), str2); return true; } From a22a6db09712caf84cbdcfc108866f5c77db0cec Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 03:21:45 +0000 Subject: [PATCH 0138/1077] need to test on linux git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4165 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 + ReadClass.cxx | 385 +++++++++++++++++++++++++------------------------- dumper.cpp | 13 ++ dumper.h | 1 + 4 files changed, 211 insertions(+), 190 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index e3213536..f5ac5700 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -859,6 +859,8 @@ int next_keyword_or_option(const char **opt_list, int count_opt_list); int dump_entities(void); int delete_entities(void); int run_as_cells(void); + void dump_ostream(std::ostream& os); + // readtr.c ------------------------------- diff --git a/ReadClass.cxx b/ReadClass.cxx index 633a65b9..22abedba 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1811,20 +1811,13 @@ int CLASS_QUALIFIER dump_entities(void) /* ---------------------------------------------------------------------- */ { - int i, n, return_value; + int return_value; return_value = OK; - if (!dump_info.Get_bool_solution() && - !dump_info.Get_bool_pp_assemblage() && - !dump_info.Get_bool_exchange() && - !dump_info.Get_bool_surface() && - !dump_info.Get_bool_s_s_assemblage() && - !dump_info.Get_bool_gas_phase() && - !dump_info.Get_bool_kinetics()) + if (!dump_info.Get_bool_any()) { return(OK); } - std::ofstream dump_stream; if (dump_info.get_append()) { @@ -1840,189 +1833,9 @@ dump_entities(void) sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.get_file_name().c_str()); error_msg(error_string, STOP); } - // solutions - if (dump_info.Get_bool_solution()) - { - if (dump_info.Get_solution().size() == 0) - { - for (i = 0; i < count_solution; i++) - { - cxxSolution cxxsoln(solution[i]); - cxxsoln.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_solution().begin(); it != dump_info.Get_solution().end(); it++) - { - if (solution_bsearch(*it, &n, FALSE) != NULL) - { - cxxSolution cxxsoln(solution[n]); - cxxsoln.dump_raw(dump_stream,0); - } - } - } - } - // pp_assemblages - if (dump_info.Get_bool_pp_assemblage()) - { - if (dump_info.Get_pp_assemblage().size() == 0) - { - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage cxxentity(&pp_assemblage[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_pp_assemblage().begin(); it != dump_info.Get_pp_assemblage().end(); it++) - { + dump_ostream(dump_stream); - if (pp_assemblage_bsearch(*it, &n) != NULL) - { - cxxPPassemblage cxxentity(&pp_assemblage[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // exchanges - if (dump_info.Get_bool_exchange()) - { - if (dump_info.Get_exchange().size() == 0) - { - for (i = 0; i < count_exchange; i++) - { - cxxExchange cxxentity(&exchange[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_exchange().begin(); it != dump_info.Get_exchange().end(); it++) - { - - if (exchange_bsearch(*it, &n) != NULL) - { - cxxExchange cxxentity(&exchange[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // surfaces - if (dump_info.Get_bool_surface()) - { - if (dump_info.Get_surface().size() == 0) - { - for (i = 0; i < count_surface; i++) - { - cxxSurface cxxentity(&surface[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_surface().begin(); it != dump_info.Get_surface().end(); it++) - { - - if (surface_bsearch(*it, &n) != NULL) - { - cxxSurface cxxentity(&surface[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // s_s_assemblages - if (dump_info.Get_bool_s_s_assemblage()) - { - if (dump_info.Get_s_s_assemblage().size() == 0) - { - for (i = 0; i < count_s_s_assemblage; i++) - { - cxxSSassemblage cxxentity(&s_s_assemblage[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_s_s_assemblage().begin(); it != dump_info.Get_s_s_assemblage().end(); it++) - { - - if (s_s_assemblage_bsearch(*it, &n) != NULL) - { - cxxSSassemblage cxxentity(&s_s_assemblage[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // gas_phases - if (dump_info.Get_bool_gas_phase()) - { - if (dump_info.Get_gas_phase().size() == 0) - { - for (i = 0; i < count_gas_phase; i++) - { - cxxGasPhase cxxentity(&gas_phase[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_gas_phase().begin(); it != dump_info.Get_gas_phase().end(); it++) - { - - if (gas_phase_bsearch(*it, &n) != NULL) - { - cxxGasPhase cxxentity(&gas_phase[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // kineticss - if (dump_info.Get_bool_kinetics()) - { - if (dump_info.Get_kinetics().size() == 0) - { - for (i = 0; i < count_kinetics; i++) - { - cxxKinetics cxxentity(&kinetics[i]); - cxxentity.dump_raw(dump_stream,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_kinetics().begin(); it != dump_info.Get_kinetics().end(); it++) - { - - if (kinetics_bsearch(*it, &n) != NULL) - { - cxxKinetics cxxentity(&kinetics[n]); - cxxentity.dump_raw(dump_stream,0); - } - } - } - } - - // Turn off dump until next read - dump_info.SetAll(false); return (OK); } /* ---------------------------------------------------------------------- */ @@ -2416,3 +2229,195 @@ run_as_cells(void) /* last_model.force_prep = TRUE; */ return (OK); } + +/* ---------------------------------------------------------------------- */ +void CLASS_QUALIFIER +dump_ostream(std::ostream& os) +/* ---------------------------------------------------------------------- */ +{ + int i, n; + + // solutions + if (dump_info.Get_bool_solution()) + { + if (dump_info.Get_solution().size() == 0) + { + for (i = 0; i < count_solution; i++) + { + cxxSolution cxxsoln(solution[i]); + cxxsoln.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_solution().begin(); it != dump_info.Get_solution().end(); it++) + { + if (solution_bsearch(*it, &n, FALSE) != NULL) + { + cxxSolution cxxsoln(solution[n]); + cxxsoln.dump_raw(os,0); + } + } + } + } + + // pp_assemblages + if (dump_info.Get_bool_pp_assemblage()) + { + if (dump_info.Get_pp_assemblage().size() == 0) + { + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage cxxentity(&pp_assemblage[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_pp_assemblage().begin(); it != dump_info.Get_pp_assemblage().end(); it++) + { + + if (pp_assemblage_bsearch(*it, &n) != NULL) + { + cxxPPassemblage cxxentity(&pp_assemblage[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // exchanges + if (dump_info.Get_bool_exchange()) + { + if (dump_info.Get_exchange().size() == 0) + { + for (i = 0; i < count_exchange; i++) + { + cxxExchange cxxentity(&exchange[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_exchange().begin(); it != dump_info.Get_exchange().end(); it++) + { + + if (exchange_bsearch(*it, &n) != NULL) + { + cxxExchange cxxentity(&exchange[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // surfaces + if (dump_info.Get_bool_surface()) + { + if (dump_info.Get_surface().size() == 0) + { + for (i = 0; i < count_surface; i++) + { + cxxSurface cxxentity(&surface[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_surface().begin(); it != dump_info.Get_surface().end(); it++) + { + + if (surface_bsearch(*it, &n) != NULL) + { + cxxSurface cxxentity(&surface[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // s_s_assemblages + if (dump_info.Get_bool_s_s_assemblage()) + { + if (dump_info.Get_s_s_assemblage().size() == 0) + { + for (i = 0; i < count_s_s_assemblage; i++) + { + cxxSSassemblage cxxentity(&s_s_assemblage[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_s_s_assemblage().begin(); it != dump_info.Get_s_s_assemblage().end(); it++) + { + + if (s_s_assemblage_bsearch(*it, &n) != NULL) + { + cxxSSassemblage cxxentity(&s_s_assemblage[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // gas_phases + if (dump_info.Get_bool_gas_phase()) + { + if (dump_info.Get_gas_phase().size() == 0) + { + for (i = 0; i < count_gas_phase; i++) + { + cxxGasPhase cxxentity(&gas_phase[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_gas_phase().begin(); it != dump_info.Get_gas_phase().end(); it++) + { + + if (gas_phase_bsearch(*it, &n) != NULL) + { + cxxGasPhase cxxentity(&gas_phase[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // kineticss + if (dump_info.Get_bool_kinetics()) + { + if (dump_info.Get_kinetics().size() == 0) + { + for (i = 0; i < count_kinetics; i++) + { + cxxKinetics cxxentity(&kinetics[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_kinetics().begin(); it != dump_info.Get_kinetics().end(); it++) + { + + if (kinetics_bsearch(*it, &n) != NULL) + { + cxxKinetics cxxentity(&kinetics[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // Turn off dump until next read + dump_info.SetAll(false); +} diff --git a/dumper.cpp b/dumper.cpp index bea4ebb4..2e273b11 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -413,3 +413,16 @@ bool dumper::Read(CParser & parser) } return(return_value); } + +bool dumper::Get_bool_any(void) +{ + return ( + Get_bool_solution() || + Get_bool_pp_assemblage() || + Get_bool_exchange() || + Get_bool_surface() || + Get_bool_s_s_assemblage() || + Get_bool_gas_phase() || + Get_bool_kinetics() + ); +} diff --git a/dumper.h b/dumper.h index d5ee1c0f..95a3db22 100644 --- a/dumper.h +++ b/dumper.h @@ -24,6 +24,7 @@ public: bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; + bool Get_bool_any(void); std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; From 4eb0dbc99b283236ed1c592bf293a4c6e444995e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 18 Mar 2010 20:48:39 +0000 Subject: [PATCH 0139/1077] list_components method to extract complete list of elements in all solutions, equilibrium_phases, etc that are currently defined within the object. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4171 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.h | 4 ++ Phreeqc.h | 2 +- Reaction.h | 4 ++ class_main.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++++++- cxxKinetics.cxx | 4 ++ cxxKinetics.h | 4 ++ 6 files changed, 121 insertions(+), 2 deletions(-) diff --git a/PPassemblage.h b/PPassemblage.h index 39c5be94..3a569781 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -33,6 +33,10 @@ class cxxPPassemblage:public cxxNumKeyword { return this->totals; }; + const cxxNameDouble & get_eltList() const + { + return this->eltList; + }; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/Phreeqc.h b/Phreeqc.h index f5ac5700..b96ca827 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1423,7 +1423,7 @@ virtual int EndRow(void); public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); - + size_t list_components(std::list &list_c); }; #endif /* _INC_PHREEQC_H */ diff --git a/Reaction.h b/Reaction.h index 46beb71d..79b68c07 100644 --- a/Reaction.h +++ b/Reaction.h @@ -25,6 +25,10 @@ class cxxReaction:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser); + cxxNameDouble &get_elementList(void) + { + return this->elementList; + } void set_units(const char * s) { diff --git a/class_main.cpp b/class_main.cpp index a5749bf8..29a339f1 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -2,6 +2,15 @@ #include "output.h" #include "phrqproto.h" #include "input.h" +#include "NameDouble.h" +#include "Solution.h" +#include "Reaction.h" +#include "PPassemblage.h" +#include "Exchange.h" +#include "Surface.h" +#include "GasPhase.h" +#include "SSassemblage.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- @@ -37,7 +46,14 @@ main(int argc, char *argv[]) Phreeqc phreeqc_instance; phreeqc_instance.main_method(argc, argv); - + std::list components; + phreeqc_instance.list_components(components); + std::list::iterator it; + std::cout << "Number of components: " << components.size() << std::endl; + for (it = components.begin(); it != components.end(); it++) + { + std::cout << " " << *it << std::endl; + } } @@ -188,3 +204,90 @@ write_banner(void) return 0; } #endif +size_t CLASS_QUALIFIER +list_components(std::list &list_c) +/* + * Find all elements in any class definition + */ +{ + cxxNameDouble accumulator; + accumulator.add("H", 1); + accumulator.add("O", 1); + + int i; + + // solutions + for (i = 0; i < count_solution; i++) + { + cxxSolution entity(solution[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // irreversible reactions + for (i = 0; i < count_irrev; i++) + { + reaction_calc(&irrev[i]); + cxxReaction entity(&irrev[i]); + accumulator.add_extensive(entity.get_elementList(), 1.0); + } + + // pure phases + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage entity(&pp_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // exchangers + for (i = 0; i < count_exchange; i++) + { + cxxExchange entity(&exchange[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // surfaces + for (i = 0; i < count_surface; i++) + { + cxxSurface entity(&surface[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // gas phases + for (i = 0; i < count_gas_phase; i++) + { + cxxGasPhase entity(&gas_phase[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // solid-solutions + for (i = 0; i < count_s_s_assemblage; i++) + { + cxxSSassemblage entity(&s_s_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // kinetics + for (i = 0; i < count_kinetics; i++) + { + calc_dummy_kinetic_reaction_tally(&kinetics[i]); + cxxKinetics entity(&kinetics[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // print list + cxxNameDouble::iterator it; + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + struct master *master_ptr = master_bsearch(it->first.c_str()); + if (master_ptr == NULL) continue; + if (master_ptr->type != AQ) continue; + if (master_ptr->primary == 0) continue; + list_c.push_back(it->first); + } + return(accumulator.size()); +} \ No newline at end of file diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 9856cd8b..510e2e5f 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -737,3 +737,7 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) this->cvode_steps = addee.cvode_steps; this->cvode_order = addee.cvode_order; } +//cxxNameDouble & cxxKinetics::get_totals(void) +//{ +// return this->totals; +//} \ No newline at end of file diff --git a/cxxKinetics.h b/cxxKinetics.h index 014b911d..15a834b5 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -35,6 +35,10 @@ class cxxKinetics:public cxxNumKeyword bool get_related_rate(void); + cxxNameDouble & get_totals(void) + { + return this->totals; + } #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); From ffb8ee86be37e1c44f57c2f82d5b5173493872c3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 18 Mar 2010 23:57:42 +0000 Subject: [PATCH 0140/1077] moved list_components from class_main.cpp to Phreeqc.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4173 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ class_main.cpp | 87 --------------------------------------------- 2 files changed, 96 insertions(+), 87 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 757db500..f46410b6 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -6,6 +6,16 @@ //}; #include // std::replace +#include "NameDouble.h" +#include "Solution.h" +#include "Reaction.h" +#include "PPassemblage.h" +#include "Exchange.h" +#include "Surface.h" +#include "GasPhase.h" +#include "SSassemblage.h" +#include "cxxKinetics.h" + Phreeqc::Phreeqc(void) { phast = FALSE; @@ -389,3 +399,89 @@ void Phreeqc::set_phast(int tf) { this->phast = tf; } +size_t Phreeqc::list_components(std::list &list_c) +/* + * Find all elements in any class definition + */ +{ + cxxNameDouble accumulator; + accumulator.add("H", 1); + accumulator.add("O", 1); + + int i; + + // solutions + for (i = 0; i < count_solution; i++) + { + cxxSolution entity(solution[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // irreversible reactions + for (i = 0; i < count_irrev; i++) + { + reaction_calc(&irrev[i]); + cxxReaction entity(&irrev[i]); + accumulator.add_extensive(entity.get_elementList(), 1.0); + } + + // pure phases + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage entity(&pp_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // exchangers + for (i = 0; i < count_exchange; i++) + { + cxxExchange entity(&exchange[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // surfaces + for (i = 0; i < count_surface; i++) + { + cxxSurface entity(&surface[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // gas phases + for (i = 0; i < count_gas_phase; i++) + { + cxxGasPhase entity(&gas_phase[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // solid-solutions + for (i = 0; i < count_s_s_assemblage; i++) + { + cxxSSassemblage entity(&s_s_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // kinetics + for (i = 0; i < count_kinetics; i++) + { + calc_dummy_kinetic_reaction_tally(&kinetics[i]); + cxxKinetics entity(&kinetics[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // print list + cxxNameDouble::iterator it; + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + struct master *master_ptr = master_bsearch(it->first.c_str()); + if (master_ptr == NULL) continue; + if (master_ptr->type != AQ) continue; + if (master_ptr->primary == 0) continue; + list_c.push_back(it->first); + } + return(list_c.size()); +} \ No newline at end of file diff --git a/class_main.cpp b/class_main.cpp index 29a339f1..f3748de5 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -204,90 +204,3 @@ write_banner(void) return 0; } #endif -size_t CLASS_QUALIFIER -list_components(std::list &list_c) -/* - * Find all elements in any class definition - */ -{ - cxxNameDouble accumulator; - accumulator.add("H", 1); - accumulator.add("O", 1); - - int i; - - // solutions - for (i = 0; i < count_solution; i++) - { - cxxSolution entity(solution[i]); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // irreversible reactions - for (i = 0; i < count_irrev; i++) - { - reaction_calc(&irrev[i]); - cxxReaction entity(&irrev[i]); - accumulator.add_extensive(entity.get_elementList(), 1.0); - } - - // pure phases - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage entity(&pp_assemblage[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // exchangers - for (i = 0; i < count_exchange; i++) - { - cxxExchange entity(&exchange[i]); - entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // surfaces - for (i = 0; i < count_surface; i++) - { - cxxSurface entity(&surface[i]); - entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // gas phases - for (i = 0; i < count_gas_phase; i++) - { - cxxGasPhase entity(&gas_phase[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // solid-solutions - for (i = 0; i < count_s_s_assemblage; i++) - { - cxxSSassemblage entity(&s_s_assemblage[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // kinetics - for (i = 0; i < count_kinetics; i++) - { - calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i]); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // print list - cxxNameDouble::iterator it; - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - struct master *master_ptr = master_bsearch(it->first.c_str()); - if (master_ptr == NULL) continue; - if (master_ptr->type != AQ) continue; - if (master_ptr->primary == 0) continue; - list_c.push_back(it->first); - } - return(accumulator.size()); -} \ No newline at end of file From 7e52b0c345e53c1d58dc7595a0c526ab8becb49f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 19 Mar 2010 01:00:01 +0000 Subject: [PATCH 0141/1077] Did not pick up redox species from solution. Do not include H and O here. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4175 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index f46410b6..a22a1fa8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -405,8 +405,8 @@ size_t Phreeqc::list_components(std::list &list_c) */ { cxxNameDouble accumulator; - accumulator.add("H", 1); - accumulator.add("O", 1); + //accumulator.add("H", 1); + //accumulator.add("O", 1); int i; @@ -473,14 +473,30 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(entity.get_totals(), 1.0); } - // print list + // Put in all primaries cxxNameDouble::iterator it; for (it = accumulator.begin(); it != accumulator.end(); it++) + { + if (it->first == "Charge") continue; + char string[MAX_LENGTH]; + strcpy(string, it->first.c_str()); + struct master *master_ptr = master_bsearch_primary(string); + if (master_ptr == NULL) continue; + if (master_ptr->type != AQ) continue; + //std::string name(master_ptr->elt->name); + //char + accumulator.add(master_ptr->elt->name, 1); + } + // print list + for (it = accumulator.begin(); it != accumulator.end(); it++) { struct master *master_ptr = master_bsearch(it->first.c_str()); if (master_ptr == NULL) continue; if (master_ptr->type != AQ) continue; if (master_ptr->primary == 0) continue; + if (it->first == "Charge") continue; + if (it->first == "O") continue; + if (it->first == "H") continue; list_c.push_back(it->first); } return(list_c.size()); From 4d050487e4fb7c7082a6e43ae172e24129374b4d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 29 Mar 2010 21:56:51 +0000 Subject: [PATCH 0142/1077] added prototypes for dump routines; added ostream header git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4197 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReadClass.cxx b/ReadClass.cxx index 22abedba..596ddb0e 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -41,6 +41,11 @@ extern int copy_use(int i); dumper dump_info; StorageBinList delete_info; runner run_info; + +int dump_entities(void); +void dump_ostream(std::ostream& os); +int delete_entities(void); +int run_as_cells(void); #endif /* ---------------------------------------------------------------------- */ From 8db3c1ac28c4f3340023832cda66af366fe09262 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Mar 2010 22:15:30 +0000 Subject: [PATCH 0143/1077] Added prototypes to class for Basic functions: total_mole iso_value iso_unit git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4198 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index b96ca827..2a6a6da7 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -225,6 +225,8 @@ LDBLE find_misc1(const char *s_s_name); LDBLE find_misc2(const char *s_s_name); LDBLE find_s_s_comp(const char *s_s_comp_name); LDBLE get_calculate_value(const char *name); +char * iso_unit(const char *total_name); +LDBLE iso_value(const char *total_name); LDBLE kinetics_moles(const char *kinetics_name); LDBLE log_activity(const char *species_name); LDBLE log_molality(const char *species_name); @@ -251,6 +253,7 @@ int system_total_s_s(void); int system_total_elt(const char *total_name); int system_total_elt_secondary(const char *total_name); LDBLE total(const char *total_name); +LDBLE total_mole(const char *total_name); int system_total_solids(struct exchange *exchange_ptr, struct pp_assemblage *pp_assemblage_ptr, struct gas_phase *gas_phase_ptr, From adcd44474bbb71edc4627e4d30b384d91baf4256 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 2 Apr 2010 00:14:16 +0000 Subject: [PATCH 0144/1077] passes all tests on win32; before changing to multiple instances git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4201 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 481 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Phreeqc.h | 7 +- 2 files changed, 487 insertions(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index a22a1fa8..63057d8a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -366,6 +366,7 @@ Phreeqc::Phreeqc(void) //FILE *punch_file = NULL; /* OUTPUT_PUNCH */ //FILE *error_file = NULL; /* OUTPUT_ERROR */ //FILE *dump_file = NULL; /* OUTPUT_DUMP */ + init(); } Phreeqc::~Phreeqc(void) @@ -500,4 +501,484 @@ size_t Phreeqc::list_components(std::list &list_c) list_c.push_back(it->first); } return(list_c.size()); +} +void Phreeqc::init(void) +{ + int i; + + moles_per_kilogram_string = 0; + pe_string = 0; + + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + itmax = 100; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif + convergence_tolerance = 1e-8; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; + negative_concentrations = FALSE; + + LOG_10 = log(10.0); + + max_solution = MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; + + count_solution = 0; + count_pp_assemblage = 0; + count_exchange = 0; + count_surface = 0; + count_gas_phase = 0; + count_kinetics = 0; + count_s_s_assemblage = 0; + + count_elements = 0; + count_irrev = 0; + count_master = 0; + count_mix = 0; + count_phases = 0; + count_s = 0; + count_temperature = 0; + count_logk = 0; + count_master_isotope = 0; +/* + * Initialize advection + */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + + advection_punch = 0; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = 0; + advection_warnings = TRUE; +/* + * Initialize transport + */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + interlayer_tortf = 100.0; + interlayer_Dpor = 0.1; +/* !!!! count_stag = 0; */ + mcd_substeps = 1.0; + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; + + pp_assemblage = 0; + exchange = 0; + surface = 0; + gas_phase = 0; + kinetics = 0; + s_s_assemblage = 0; + cell_data = 0; + elements = 0; + elt_list = 0; + + + inverse = 0; + count_inverse = 0; + + irrev = 0; + + line = 0; + line_save = 0; + + master = 0; + + mb_unknowns = 0; + + mix = 0; + count_mix = 0; +/* !!!! */ + stag_data = 0; + + phases = 0; + + trxn.token = 0; + + s = 0; + + logk = 0; + + master_isotope = 0; + + solution = 0; + + temperature = 0; + + title_x = NULL; + pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; + + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; + + isotopes_x = 0; + + x = NULL; + max_unknowns = 0; + + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + + logk_hash_table = 0; + master_isotope_hash_table = 0; + strings_hash_table = 0; + elements_hash_table = 0; + species_hash_table = 0; + phases_hash_table = 0; + keyword_hash_table = 0; +/* + * Initialize use pointers + */ + use.solution_in = FALSE; + use.pp_assemblage_in = FALSE; + use.mix_in = FALSE; + use.irrev_in = FALSE; +/* + * Initialize punch + */ + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; + punch.count_molalities = 0; + + punch.molalities = 0; + punch.count_activities = 0; + + punch.activities = 0; + punch.count_pure_phases = 0; + + punch.pure_phases = 0; + punch.count_si = 0; + + punch.si = 0; + punch.count_gases = 0; + + punch.gases = 0; + punch.count_s_s = 0; + punch.s_s = 0; + + punch.count_kinetics = 0; + punch.kinetics = 0; + + punch.count_isotopes = 0; + punch.isotopes = 0; + + punch.count_calculate_values = 0; + punch.calculate_values = 0; + + count_save_values = 0; + save_values = 0; + + + punch.inverse = TRUE; + + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; +/* + * last model + */ + last_model.exchange = NULL; + last_model.gas_phase = NULL; + last_model.s_s_assemblage = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; + last_model.surface_charge = NULL; +/* + * Update hash table + */ + keyword_hash = 0; +/* + * rates + */ + rates = 0; + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_p = NULL; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + +/* + * user_print, user_punch + */ + user_print = 0; + user_punch = 0; + user_punch_headings = 0; + user_punch_count_headings = 0; +#ifdef PHREEQ98 +/* + * user_graph + */ + user_graph = 0; + user_graph_headings = 0 + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = 0; + llnl_count_temp = 0; + + llnl_adh = 0; + llnl_count_adh = 0; + + llnl_bdh = 0; + llnl_count_bdh = 0; + + llnl_bdot = 0; + llnl_count_bdot = 0; + + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; +/* + * + */ + command_hash_table = 0; + + change_surf = 0; + change_surf_count = 0; + + +#if defined(WINDOWS) || defined(_WINDOWS) + /* SRC pr.status = FALSE; */ +#endif + /* Initialize print here, not in global.h */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + if (phast == TRUE) + { + pr.status = FALSE; + } + else + { + pr.status = TRUE; + } + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + + species_list = NULL; + + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; + selected_output_file_name = NULL; + dump_file_name = NULL; + + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + + calculate_value = 0; + calculate_value_hash_table = 0; + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + isotope_ratio = 0; + isotope_ratio_hash_table = 0; + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + isotope_alpha = 0; + isotope_alpha_hash_table = 0; + + phreeqc_mpi_myself = 0; + + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + + set_forward_output_to_log(FALSE); + simulation = 0; + /* + * cvode + */ + + cvode_init(); + /* + * Pitzer + */ + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + use_etheta = TRUE; + pitz_params = 0; + + max_theta_param = 100; + count_theta_param = 0; + theta_params = 0; + + ICON = TRUE; + OTEMP = 0.0; + for (i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } + pitzer_pe = FALSE; + + + /* + * SIT + */ + sit_model = FALSE; + max_sit_param = 100; + count_sit_param = 0; + sit_params = 0; + + /* + * to facilitate debuging + */ + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; + dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + + zeros = 0; + zeros_max = 1; + + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + + charge_group = NULL; + print_density = 0; + + return; } \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index 2a6a6da7..2f9c0a62 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -285,6 +285,7 @@ int write_banner(void); #endif /* default.c */ +public: int close_input_files(void); int close_output_files(void); CLASS_STATIC int getc_callback(void *cookie); @@ -559,6 +560,7 @@ void check_line_breaks(char *s); char *prefix_database_dir(char *s); void show_progress(const int type, char *s); #endif +public: int fileop_handler(const int type, int (*PFN) (FILE *)); int open_handler(const int type, const char *file_name); int output_handler(const int type, const char *err_str, @@ -716,6 +718,7 @@ int write_phase_sys_total(int n); int fpunchf(const char *name, const char *format, ...); int fpunchf_user(int user_index, const char *format, ...); +int fpunchf_end_row(const char *format, ...); char *sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); @@ -1295,6 +1298,7 @@ int replace_solids_gases(void); int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: int tidy_punch(void); int tidy_model(void); @@ -1367,7 +1371,6 @@ int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: int compute_gfw(const char *string, LDBLE * gfw); -protected: int copy_token(char *token_ptr, char **ptr, int *length); int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); @@ -1427,6 +1430,8 @@ public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); +protected: + void init(void); }; #endif /* _INC_PHREEQC_H */ From 7ca9917f8d1288a641a39994701a25c249c28664 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Apr 2010 20:56:38 +0000 Subject: [PATCH 0145/1077] Remove from unit: TestInterface.cpp TestInterface.h IPhreeqc.hpp IPhreeqc.h IPhreeqc.cpp module_output.cpp module_files.cpp fwrap.cpp fwrap2.cpp fwrap3.cpp IPhreeqc.cpp CVar.hxx ErrorReporter.hxx OutputFiles.hxx Phreeqc.hxx PhreeqcParser.hxx SelectedOutput.hxx Var.h Remove from IPhreeqc IPhreeqc.cpp IPhreeqc.h IPhreeqc.hpp module_output.cpp module_files.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4213 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 2f9c0a62..3b54cbff 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1419,13 +1419,6 @@ int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); -#if defined(SWIG_SHARED_OBJ) -public: -virtual int EndRow(void); -#endif - - - public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); From 0833d79ec164206af88b91005ab1a17c20aa8105 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 21 Apr 2010 05:29:27 +0000 Subject: [PATCH 0146/1077] changed svn:eol-style to native for many files git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4276 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1966 ++++++++++++++++----------------- Phreeqc.h | 2860 ++++++++++++++++++++++++------------------------ class_main.cpp | 412 +++---- 3 files changed, 2619 insertions(+), 2619 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 63057d8a..c5eb4098 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1,984 +1,984 @@ -#include "Phreeqc.h" -//class Phreeqc -//{ -// Phreeqc(void); -// ~Phreeqc(void); -//}; -#include // std::replace - -#include "NameDouble.h" -#include "Solution.h" -#include "Reaction.h" -#include "PPassemblage.h" -#include "Exchange.h" -#include "Surface.h" -#include "GasPhase.h" -#include "SSassemblage.h" -#include "cxxKinetics.h" - -Phreeqc::Phreeqc(void) -{ - phast = FALSE; - s_pTail = NULL; - user_database = NULL; - output = NULL; - log_file = NULL; - punch_file = NULL; - dump_file = NULL; - error_file = NULL; - database_file = NULL; - input_file = NULL; - rates = NULL; - tally_table = NULL; - spec = NULL; - cations = NULL; - anions = NULL; - neutrals = NULL; - IPRSNT = NULL; - M = NULL; - LGAMMA = NULL; - sit_params = NULL; - sit_LGAMMA = NULL; - sit_IPRSNT = NULL; - sit_M = NULL; - - struct const_iso - { - const char *name; - LDBLE value; - LDBLE uncertainty; - }; - - - struct const_iso temp_iso_defaults[] = { - {"13C", -10, 1}, - {"13C(4)", -10, 1}, - {"13C(-4)", -50, 5}, - {"34S", 10, 1}, - {"34S(6)", 10, 1}, - {"34S(-2)", -30, 5}, - {"2H", -28, 1}, - {"18O", -5, .1}, - {"87Sr", .71, .01}, - {"11B", 20, 5} - }; - int temp_count_iso_defaults = - (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); - - count_iso_defaults = temp_count_iso_defaults; - iso_defaults = new iso[count_iso_defaults]; - - int i; - for (i = 0; i < temp_count_iso_defaults; i++) - { - iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); - iso_defaults[i].value = temp_iso_defaults[i].value; - iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; - } - - - struct const_key keyword_temp[] = { - {"eof", 0}, - {"end", 0}, - {"solution_species", 0}, - {"solution_master_species", 0}, - {"solution", 0}, - {"phases", 0}, - {"pure_phases", 0}, - {"reaction", 0}, - {"mix", 0}, - {"use", 0}, - {"save", 0}, - {"exchange_species", 0}, - {"exchange_master_species", 0}, - {"exchange", 0}, - {"surface_species", 0}, - {"surface_master_species", 0}, - {"surface", 0}, - {"reaction_temperature", 0}, - {"inverse_modeling", 0}, - {"gas_phase", 0}, - {"transport", 0}, - {"debug", 0}, - {"selected_output", 0}, - {"select_output", 0}, - {"knobs", 0}, - {"print", 0}, - {"equilibrium_phases", 0}, - {"equilibria", 0}, - {"equilibrium", 0}, - {"pure", 0}, - {"title", 0}, - {"comment", 0}, - {"advection", 0}, - {"kinetics", 0}, - {"incremental_reactions", 0}, - {"incremental", 0}, - {"rates", 0}, - {"solution_s", 0}, - {"user_print", 0}, - {"user_punch", 0}, - {"solid_solutions", 0}, - {"solid_solution", 0}, - {"solution_spread", 0}, - {"spread_solution", 0}, - {"selected_out", 0}, - {"select_out", 0}, - {"user_graph", 0}, - {"llnl_aqueous_model_parameters", 0}, - {"llnl_aqueous_model", 0}, - {"database", 0}, - {"named_analytical_expression", 0}, - {"named_analytical_expressions", 0}, - {"named_expressions", 0}, - {"named_log_k", 0}, - {"isotopes", 0}, - {"calculate_values", 0}, - {"isotope_ratios", 0}, - {"isotope_alphas", 0}, - {"copy", 0}, - {"pitzer", 0}, - {"sit", 0}, - {"equilibrium_phase"} -#ifdef PHREEQC_CPP - , - {"solution_raw", 0}, - {"exchange_raw", 0}, - {"surface_raw", 0}, - {"equilibrium_phases_raw", 0}, - {"kinetics_raw", 0}, - {"solid_solutions_raw", 0}, - {"gas_phase_raw", 0}, - {"reaction_raw", 0}, - {"mix_raw", 0}, - {"reaction_temperature_raw", 0}, - {"dump", 0}, - {"solution_modify", 0}, - {"equilibrium_phases_modify", 0}, - {"exchange_modify", 0}, - {"surface_modify", 0}, - {"solid_solutions_modify", 0}, - {"gas_phase_modify", 0}, - {"kinetics_modify", 0}, - {"delete", 0}, - {"run_cells", 0} -#endif - }; - NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ - - - //keyword = (struct const_key *) PHRQ_malloc((size_t) (NKEYS * sizeof(const_key))); - keyword = new const_key[NKEYS]; - for (i = 0; i < NKEYS; i++) - { - keyword[i].name = string_duplicate(keyword_temp[i].name); - keyword[i].keycount = 0; - } - - // basic.c - struct const_key command_temp[] = { - {"and", tokand}, - {"or", tokor}, - {"xor", tokxor}, - {"not", toknot}, - {"mod", tokmod}, - {"sqr", toksqr}, - {"sqrt", toksqrt}, - {"sin", toksin}, - {"cos", tokcos}, - {"tan", toktan}, - {"arctan", tokarctan}, - {"log", toklog}, - {"exp", tokexp}, - {"abs", tokabs}, - {"sgn", toksgn}, - {"str$", tokstr_}, - {"val", tokval}, - {"chr$", tokchr_}, - {"asc", tokasc}, - {"len", toklen}, - {"mid$", tokmid_}, - {"peek", tokpeek}, - {"let", toklet}, - {"print", tokprint}, - {"punch", tokpunch}, -#ifdef PHREEQ98 - {"graph_x", tokgraph_x}, - {"graph_y", tokgraph_y}, - {"graph_sy", tokgraph_sy}, -#endif - {"input", tokinput}, - {"goto", tokgoto}, - {"go to", tokgoto}, - {"if", tokif}, - {"end", tokend}, - {"stop", tokstop}, - {"for", tokfor}, - {"next", toknext}, - {"while", tokwhile}, - {"wend", tokwend}, - {"gosub", tokgosub}, - {"return", tokreturn}, - {"read", tokread}, - {"data", tokdata}, - {"restore", tokrestore}, - {"gotoxy", tokgotoxy}, - {"on", tokon}, - {"dim", tokdim}, - {"poke", tokpoke}, - {"list", toklist}, - {"run", tokrun}, - {"new", toknew}, - {"load", tokload}, - {"merge", tokmerge}, - {"save", toksave}, - {"bye", tokbye}, - {"quit", tokbye}, - {"del", tokdel}, - {"renum", tokrenum}, - {"then", tokthen}, - {"else", tokelse}, - {"to", tokto}, - {"step", tokstep}, - {"tc", toktc}, - {"tk", toktk}, - {"time", toktime}, - {"sim_time", toksim_time}, - {"total_time", toktotal_time}, - {"m0", tokm0}, - {"m", tokm}, - {"parm", tokparm}, - {"act", tokact}, - {"edl", tokedl}, - {"surf", toksurf}, - {"equi", tokequi}, - {"kin", tokkin}, - {"gas", tokgas}, - {"s_s", toks_s}, - {"misc1", tokmisc1}, - {"misc2", tokmisc2}, - {"mu", tokmu}, - {"osmotic", tokosmotic}, - {"alk", tokalk}, - {"lk_species", toklk_species}, - {"lk_named", toklk_named}, - {"lk_phase", toklk_phase}, - {"sum_species", toksum_species}, - {"sum_gas", toksum_gas}, - {"sum_s_s", toksum_s_s}, - {"calc_value", tokcalc_value}, - {"description", tokdescription}, - {"sys", toksys}, - {"instr", tokinstr}, - {"ltrim", tokltrim}, - {"rtrim", tokrtrim}, - {"trim", toktrim}, - {"pad", tokpad}, - {"rxn", tokrxn}, - {"dist", tokdist}, - {"mol", tokmol}, - {"la", tokla}, - {"lm", toklm}, - {"sr", toksr}, - {"si", toksi}, - {"step_no", tokstep_no}, - {"cell_no", tokcell_no}, - {"sim_no", toksim_no}, - {"tot", toktot}, - {"log10", toklog10}, - {"charge_balance", tokcharge_balance}, - {"percent_error", tokpercent_error}, - {"put", tokput}, - {"get", tokget}, - {"exists", tokexists}, - {"rem", tokrem}, - {"change_por", tokchange_por}, - {"get_por", tokget_por}, - {"change_surf", tokchange_surf}, - {"porevolume", tokporevolume}, - {"sc", toksc}, - {"gamma", tokgamma}, - /* VP: Density Start */ - {"lg", toklg}, - {"rho", tokrho} - /* VP: Density End */ - }; - NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); - command = new const_key[NCMDS]; - for (i = 0; i < NCMDS; i++) - { - command[i].name = string_duplicate(command_temp[i].name); - command[i].keycount = command_temp[i].keycount; - } - - //cl1.c - x_arg = NULL, res_arg = NULL, scratch = NULL; - x_arg_max = 0, res_arg_max = 0, scratch_max = 0; - - // dw.c - GASCON = 0.461522e0; - TZ = 647.073e0; - AA = 1.e0; - G1 = 11.e0; - G2 = 44.333333333333e0; - GF = 3.5e0; - - // model.c - min_value = 1e-10; - normal = NULL; - ineq_array = NULL; - res = NULL; - cu = NULL; - zero = NULL; - delta1 = NULL; - iu = NULL; - is = NULL; - back_eq = NULL; - normal_max = 0; - ineq_array_max = 0; - res_max = 0; - cu_max = 0; - zero_max = 0; - delta1_max = 0; - iu_max = 0; - is_max = 0; - back_eq_max = 0; - - // output.c - output_callbacks = new Phreeqc::output_callback[MAX_CALLBACKS]; - count_output_callback = 0; - forward_output_to_log = 0; - - // phqalloc.c - //s_pTail = NULL; - - // transport.c - J_ij = NULL; - J_ij_il = NULL; - m_s = NULL; - - default_data_base = string_duplicate("phreeqc.dat"); - -//FILE *input_file = NULL; -//FILE *database_file = NULL; -//FILE *output = NULL; /* OUTPUT_MESSAGE */ -//FILE *log_file = NULL; /* OUTPUT_LOG */ -//FILE *punch_file = NULL; /* OUTPUT_PUNCH */ -//FILE *error_file = NULL; /* OUTPUT_ERROR */ -//FILE *dump_file = NULL; /* OUTPUT_DUMP */ - init(); -} - -Phreeqc::~Phreeqc(void) -{ - - clean_up(); - close_input_files(); - close_output_files(); - - int i; - for (i = 0; i < count_iso_defaults; i++) - { - iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); - } - for (i = 0; i < NKEYS; i++) - { - keyword[i].name = (char *) free_check_null((void *) keyword[i].name); - } - delete[] keyword; - for (i = 0; i < NCMDS; i++) - { - command[i].name = (char *) free_check_null((void *) command[i].name); - } - delete[] command; - - free_check_null(default_data_base); - - PHRQ_free_all(); -} -void Phreeqc::set_phast(int tf) -{ - this->phast = tf; -} -size_t Phreeqc::list_components(std::list &list_c) -/* - * Find all elements in any class definition - */ -{ - cxxNameDouble accumulator; - //accumulator.add("H", 1); - //accumulator.add("O", 1); - - int i; - - // solutions - for (i = 0; i < count_solution; i++) - { - cxxSolution entity(solution[i]); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // irreversible reactions - for (i = 0; i < count_irrev; i++) - { - reaction_calc(&irrev[i]); - cxxReaction entity(&irrev[i]); - accumulator.add_extensive(entity.get_elementList(), 1.0); - } - - // pure phases - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage entity(&pp_assemblage[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // exchangers - for (i = 0; i < count_exchange; i++) - { - cxxExchange entity(&exchange[i]); - entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // surfaces - for (i = 0; i < count_surface; i++) - { - cxxSurface entity(&surface[i]); - entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // gas phases - for (i = 0; i < count_gas_phase; i++) - { - cxxGasPhase entity(&gas_phase[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // solid-solutions - for (i = 0; i < count_s_s_assemblage; i++) - { - cxxSSassemblage entity(&s_s_assemblage[i]); - entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // kinetics - for (i = 0; i < count_kinetics; i++) - { - calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i]); - accumulator.add_extensive(entity.get_totals(), 1.0); - } - - // Put in all primaries - cxxNameDouble::iterator it; - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - if (it->first == "Charge") continue; - char string[MAX_LENGTH]; - strcpy(string, it->first.c_str()); - struct master *master_ptr = master_bsearch_primary(string); - if (master_ptr == NULL) continue; - if (master_ptr->type != AQ) continue; - //std::string name(master_ptr->elt->name); - //char - accumulator.add(master_ptr->elt->name, 1); - } - // print list - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - struct master *master_ptr = master_bsearch(it->first.c_str()); - if (master_ptr == NULL) continue; - if (master_ptr->type != AQ) continue; - if (master_ptr->primary == 0) continue; - if (it->first == "Charge") continue; - if (it->first == "O") continue; - if (it->first == "H") continue; - list_c.push_back(it->first); - } - return(list_c.size()); -} -void Phreeqc::init(void) -{ - int i; - - moles_per_kilogram_string = 0; - pe_string = 0; - - debug_model = FALSE; - debug_prep = FALSE; - debug_set = FALSE; - debug_diffuse_layer = FALSE; - debug_inverse = FALSE; - itmax = 100; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#else - ineq_tol = pow((double) 10, (double) -DBL_DIG); -#endif - convergence_tolerance = 1e-8; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -#else - inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -#endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; - negative_concentrations = FALSE; - - LOG_10 = log(10.0); - - max_solution = MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; - max_s_s_assemblage = MAX_PP_ASSEMBLAGE; - - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_strings = MAX_STRINGS; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; - - count_solution = 0; - count_pp_assemblage = 0; - count_exchange = 0; - count_surface = 0; - count_gas_phase = 0; - count_kinetics = 0; - count_s_s_assemblage = 0; - - count_elements = 0; - count_irrev = 0; - count_master = 0; - count_mix = 0; - count_phases = 0; - count_s = 0; - count_temperature = 0; - count_logk = 0; - count_master_isotope = 0; -/* - * Initialize advection - */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - - advection_punch = 0; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = 0; - advection_warnings = TRUE; -/* - * Initialize transport - */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; -/* !!!! count_stag = 0; */ - mcd_substeps = 1.0; - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; - - pp_assemblage = 0; - exchange = 0; - surface = 0; - gas_phase = 0; - kinetics = 0; - s_s_assemblage = 0; - cell_data = 0; - elements = 0; - elt_list = 0; - - - inverse = 0; - count_inverse = 0; - - irrev = 0; - - line = 0; - line_save = 0; - - master = 0; - - mb_unknowns = 0; - - mix = 0; - count_mix = 0; -/* !!!! */ - stag_data = 0; - - phases = 0; - - trxn.token = 0; - - s = 0; - - logk = 0; - - master_isotope = 0; - - solution = 0; - - temperature = 0; - - title_x = NULL; - pe_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; - - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; - - isotopes_x = 0; - - x = NULL; - max_unknowns = 0; - - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; - - logk_hash_table = 0; - master_isotope_hash_table = 0; - strings_hash_table = 0; - elements_hash_table = 0; - species_hash_table = 0; - phases_hash_table = 0; - keyword_hash_table = 0; -/* - * Initialize use pointers - */ - use.solution_in = FALSE; - use.pp_assemblage_in = FALSE; - use.mix_in = FALSE; - use.irrev_in = FALSE; -/* - * Initialize punch - */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; - punch.count_molalities = 0; - - punch.molalities = 0; - punch.count_activities = 0; - - punch.activities = 0; - punch.count_pure_phases = 0; - - punch.pure_phases = 0; - punch.count_si = 0; - - punch.si = 0; - punch.count_gases = 0; - - punch.gases = 0; - punch.count_s_s = 0; - punch.s_s = 0; - - punch.count_kinetics = 0; - punch.kinetics = 0; - - punch.count_isotopes = 0; - punch.isotopes = 0; - - punch.count_calculate_values = 0; - punch.calculate_values = 0; - - count_save_values = 0; - save_values = 0; - - - punch.inverse = TRUE; - - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -/* - * last model - */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; - last_model.s_s_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; - last_model.surface_charge = NULL; -/* - * Update hash table - */ - keyword_hash = 0; -/* - * rates - */ - rates = 0; - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - rate_p = NULL; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; - initial_total_time = 0; - -/* - * user_print, user_punch - */ - user_print = 0; - user_punch = 0; - user_punch_headings = 0; - user_punch_count_headings = 0; -#ifdef PHREEQ98 -/* - * user_graph - */ - user_graph = 0; - user_graph_headings = 0 - user_graph_count_headings = 0; -#endif - /* - Initialize llnl aqueous model parameters - */ - llnl_temp = 0; - llnl_count_temp = 0; - - llnl_adh = 0; - llnl_count_adh = 0; - - llnl_bdh = 0; - llnl_count_bdh = 0; - - llnl_bdot = 0; - llnl_count_bdot = 0; - - llnl_co2_coefs = 0; - llnl_count_co2_coefs = 0; -/* - * - */ - command_hash_table = 0; - - change_surf = 0; - change_surf_count = 0; - - -#if defined(WINDOWS) || defined(_WINDOWS) - /* SRC pr.status = FALSE; */ -#endif - /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; - if (phast == TRUE) - { - pr.status = FALSE; - } - else - { - pr.status = TRUE; - } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - - species_list = NULL; - - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; - selected_output_file_name = NULL; - dump_file_name = NULL; - - /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - - calculate_value = 0; - calculate_value_hash_table = 0; - - /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - isotope_ratio = 0; - isotope_ratio_hash_table = 0; - - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - isotope_alpha = 0; - isotope_alpha_hash_table = 0; - - phreeqc_mpi_myself = 0; - - copy_solution.n_user = copy_solution.start = copy_solution.end = 0; - copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; - copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; - copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; - copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; - copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; - copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; - copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; - - set_forward_output_to_log(FALSE); - simulation = 0; - /* - * cvode - */ - - cvode_init(); - /* - * Pitzer - */ - pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; - use_etheta = TRUE; - pitz_params = 0; - - max_theta_param = 100; - count_theta_param = 0; - theta_params = 0; - - ICON = TRUE; - OTEMP = 0.0; - for (i = 0; i < 23; i++) - { - BK[i] = 0.0; - DK[i] = 0.0; - } - pitzer_pe = FALSE; - - - /* - * SIT - */ - sit_model = FALSE; - max_sit_param = 100; - count_sit_param = 0; - sit_params = 0; - - /* - * to facilitate debuging - */ - dbg_use = &use; - dbg_solution = solution; - dbg_exchange = exchange; - dbg_surface = surface; - dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; - dbg_irrev = irrev; - dbg_mix = mix; - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; - - zeros = 0; - zeros_max = 1; - - cell_pore_volume = 0; - cell_volume = 0; - cell_porosity = 0; - cell_saturation = 0; - - charge_group = NULL; - print_density = 0; - - return; +#include "Phreeqc.h" +//class Phreeqc +//{ +// Phreeqc(void); +// ~Phreeqc(void); +//}; +#include // std::replace + +#include "NameDouble.h" +#include "Solution.h" +#include "Reaction.h" +#include "PPassemblage.h" +#include "Exchange.h" +#include "Surface.h" +#include "GasPhase.h" +#include "SSassemblage.h" +#include "cxxKinetics.h" + +Phreeqc::Phreeqc(void) +{ + phast = FALSE; + s_pTail = NULL; + user_database = NULL; + output = NULL; + log_file = NULL; + punch_file = NULL; + dump_file = NULL; + error_file = NULL; + database_file = NULL; + input_file = NULL; + rates = NULL; + tally_table = NULL; + spec = NULL; + cations = NULL; + anions = NULL; + neutrals = NULL; + IPRSNT = NULL; + M = NULL; + LGAMMA = NULL; + sit_params = NULL; + sit_LGAMMA = NULL; + sit_IPRSNT = NULL; + sit_M = NULL; + + struct const_iso + { + const char *name; + LDBLE value; + LDBLE uncertainty; + }; + + + struct const_iso temp_iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} + }; + int temp_count_iso_defaults = + (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); + + count_iso_defaults = temp_count_iso_defaults; + iso_defaults = new iso[count_iso_defaults]; + + int i; + for (i = 0; i < temp_count_iso_defaults; i++) + { + iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); + iso_defaults[i].value = temp_iso_defaults[i].value; + iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; + } + + + struct const_key keyword_temp[] = { + {"eof", 0}, + {"end", 0}, + {"solution_species", 0}, + {"solution_master_species", 0}, + {"solution", 0}, + {"phases", 0}, + {"pure_phases", 0}, + {"reaction", 0}, + {"mix", 0}, + {"use", 0}, + {"save", 0}, + {"exchange_species", 0}, + {"exchange_master_species", 0}, + {"exchange", 0}, + {"surface_species", 0}, + {"surface_master_species", 0}, + {"surface", 0}, + {"reaction_temperature", 0}, + {"inverse_modeling", 0}, + {"gas_phase", 0}, + {"transport", 0}, + {"debug", 0}, + {"selected_output", 0}, + {"select_output", 0}, + {"knobs", 0}, + {"print", 0}, + {"equilibrium_phases", 0}, + {"equilibria", 0}, + {"equilibrium", 0}, + {"pure", 0}, + {"title", 0}, + {"comment", 0}, + {"advection", 0}, + {"kinetics", 0}, + {"incremental_reactions", 0}, + {"incremental", 0}, + {"rates", 0}, + {"solution_s", 0}, + {"user_print", 0}, + {"user_punch", 0}, + {"solid_solutions", 0}, + {"solid_solution", 0}, + {"solution_spread", 0}, + {"spread_solution", 0}, + {"selected_out", 0}, + {"select_out", 0}, + {"user_graph", 0}, + {"llnl_aqueous_model_parameters", 0}, + {"llnl_aqueous_model", 0}, + {"database", 0}, + {"named_analytical_expression", 0}, + {"named_analytical_expressions", 0}, + {"named_expressions", 0}, + {"named_log_k", 0}, + {"isotopes", 0}, + {"calculate_values", 0}, + {"isotope_ratios", 0}, + {"isotope_alphas", 0}, + {"copy", 0}, + {"pitzer", 0}, + {"sit", 0}, + {"equilibrium_phase"} +#ifdef PHREEQC_CPP + , + {"solution_raw", 0}, + {"exchange_raw", 0}, + {"surface_raw", 0}, + {"equilibrium_phases_raw", 0}, + {"kinetics_raw", 0}, + {"solid_solutions_raw", 0}, + {"gas_phase_raw", 0}, + {"reaction_raw", 0}, + {"mix_raw", 0}, + {"reaction_temperature_raw", 0}, + {"dump", 0}, + {"solution_modify", 0}, + {"equilibrium_phases_modify", 0}, + {"exchange_modify", 0}, + {"surface_modify", 0}, + {"solid_solutions_modify", 0}, + {"gas_phase_modify", 0}, + {"kinetics_modify", 0}, + {"delete", 0}, + {"run_cells", 0} +#endif + }; + NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ + + + //keyword = (struct const_key *) PHRQ_malloc((size_t) (NKEYS * sizeof(const_key))); + keyword = new const_key[NKEYS]; + for (i = 0; i < NKEYS; i++) + { + keyword[i].name = string_duplicate(keyword_temp[i].name); + keyword[i].keycount = 0; + } + + // basic.c + struct const_key command_temp[] = { + {"and", tokand}, + {"or", tokor}, + {"xor", tokxor}, + {"not", toknot}, + {"mod", tokmod}, + {"sqr", toksqr}, + {"sqrt", toksqrt}, + {"sin", toksin}, + {"cos", tokcos}, + {"tan", toktan}, + {"arctan", tokarctan}, + {"log", toklog}, + {"exp", tokexp}, + {"abs", tokabs}, + {"sgn", toksgn}, + {"str$", tokstr_}, + {"val", tokval}, + {"chr$", tokchr_}, + {"asc", tokasc}, + {"len", toklen}, + {"mid$", tokmid_}, + {"peek", tokpeek}, + {"let", toklet}, + {"print", tokprint}, + {"punch", tokpunch}, +#ifdef PHREEQ98 + {"graph_x", tokgraph_x}, + {"graph_y", tokgraph_y}, + {"graph_sy", tokgraph_sy}, +#endif + {"input", tokinput}, + {"goto", tokgoto}, + {"go to", tokgoto}, + {"if", tokif}, + {"end", tokend}, + {"stop", tokstop}, + {"for", tokfor}, + {"next", toknext}, + {"while", tokwhile}, + {"wend", tokwend}, + {"gosub", tokgosub}, + {"return", tokreturn}, + {"read", tokread}, + {"data", tokdata}, + {"restore", tokrestore}, + {"gotoxy", tokgotoxy}, + {"on", tokon}, + {"dim", tokdim}, + {"poke", tokpoke}, + {"list", toklist}, + {"run", tokrun}, + {"new", toknew}, + {"load", tokload}, + {"merge", tokmerge}, + {"save", toksave}, + {"bye", tokbye}, + {"quit", tokbye}, + {"del", tokdel}, + {"renum", tokrenum}, + {"then", tokthen}, + {"else", tokelse}, + {"to", tokto}, + {"step", tokstep}, + {"tc", toktc}, + {"tk", toktk}, + {"time", toktime}, + {"sim_time", toksim_time}, + {"total_time", toktotal_time}, + {"m0", tokm0}, + {"m", tokm}, + {"parm", tokparm}, + {"act", tokact}, + {"edl", tokedl}, + {"surf", toksurf}, + {"equi", tokequi}, + {"kin", tokkin}, + {"gas", tokgas}, + {"s_s", toks_s}, + {"misc1", tokmisc1}, + {"misc2", tokmisc2}, + {"mu", tokmu}, + {"osmotic", tokosmotic}, + {"alk", tokalk}, + {"lk_species", toklk_species}, + {"lk_named", toklk_named}, + {"lk_phase", toklk_phase}, + {"sum_species", toksum_species}, + {"sum_gas", toksum_gas}, + {"sum_s_s", toksum_s_s}, + {"calc_value", tokcalc_value}, + {"description", tokdescription}, + {"sys", toksys}, + {"instr", tokinstr}, + {"ltrim", tokltrim}, + {"rtrim", tokrtrim}, + {"trim", toktrim}, + {"pad", tokpad}, + {"rxn", tokrxn}, + {"dist", tokdist}, + {"mol", tokmol}, + {"la", tokla}, + {"lm", toklm}, + {"sr", toksr}, + {"si", toksi}, + {"step_no", tokstep_no}, + {"cell_no", tokcell_no}, + {"sim_no", toksim_no}, + {"tot", toktot}, + {"log10", toklog10}, + {"charge_balance", tokcharge_balance}, + {"percent_error", tokpercent_error}, + {"put", tokput}, + {"get", tokget}, + {"exists", tokexists}, + {"rem", tokrem}, + {"change_por", tokchange_por}, + {"get_por", tokget_por}, + {"change_surf", tokchange_surf}, + {"porevolume", tokporevolume}, + {"sc", toksc}, + {"gamma", tokgamma}, + /* VP: Density Start */ + {"lg", toklg}, + {"rho", tokrho} + /* VP: Density End */ + }; + NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); + command = new const_key[NCMDS]; + for (i = 0; i < NCMDS; i++) + { + command[i].name = string_duplicate(command_temp[i].name); + command[i].keycount = command_temp[i].keycount; + } + + //cl1.c + x_arg = NULL, res_arg = NULL, scratch = NULL; + x_arg_max = 0, res_arg_max = 0, scratch_max = 0; + + // dw.c + GASCON = 0.461522e0; + TZ = 647.073e0; + AA = 1.e0; + G1 = 11.e0; + G2 = 44.333333333333e0; + GF = 3.5e0; + + // model.c + min_value = 1e-10; + normal = NULL; + ineq_array = NULL; + res = NULL; + cu = NULL; + zero = NULL; + delta1 = NULL; + iu = NULL; + is = NULL; + back_eq = NULL; + normal_max = 0; + ineq_array_max = 0; + res_max = 0; + cu_max = 0; + zero_max = 0; + delta1_max = 0; + iu_max = 0; + is_max = 0; + back_eq_max = 0; + + // output.c + output_callbacks = new Phreeqc::output_callback[MAX_CALLBACKS]; + count_output_callback = 0; + forward_output_to_log = 0; + + // phqalloc.c + //s_pTail = NULL; + + // transport.c + J_ij = NULL; + J_ij_il = NULL; + m_s = NULL; + + default_data_base = string_duplicate("phreeqc.dat"); + +//FILE *input_file = NULL; +//FILE *database_file = NULL; +//FILE *output = NULL; /* OUTPUT_MESSAGE */ +//FILE *log_file = NULL; /* OUTPUT_LOG */ +//FILE *punch_file = NULL; /* OUTPUT_PUNCH */ +//FILE *error_file = NULL; /* OUTPUT_ERROR */ +//FILE *dump_file = NULL; /* OUTPUT_DUMP */ + init(); +} + +Phreeqc::~Phreeqc(void) +{ + + clean_up(); + close_input_files(); + close_output_files(); + + int i; + for (i = 0; i < count_iso_defaults; i++) + { + iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); + } + for (i = 0; i < NKEYS; i++) + { + keyword[i].name = (char *) free_check_null((void *) keyword[i].name); + } + delete[] keyword; + for (i = 0; i < NCMDS; i++) + { + command[i].name = (char *) free_check_null((void *) command[i].name); + } + delete[] command; + + free_check_null(default_data_base); + + PHRQ_free_all(); +} +void Phreeqc::set_phast(int tf) +{ + this->phast = tf; +} +size_t Phreeqc::list_components(std::list &list_c) +/* + * Find all elements in any class definition + */ +{ + cxxNameDouble accumulator; + //accumulator.add("H", 1); + //accumulator.add("O", 1); + + int i; + + // solutions + for (i = 0; i < count_solution; i++) + { + cxxSolution entity(solution[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // irreversible reactions + for (i = 0; i < count_irrev; i++) + { + reaction_calc(&irrev[i]); + cxxReaction entity(&irrev[i]); + accumulator.add_extensive(entity.get_elementList(), 1.0); + } + + // pure phases + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage entity(&pp_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // exchangers + for (i = 0; i < count_exchange; i++) + { + cxxExchange entity(&exchange[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // surfaces + for (i = 0; i < count_surface; i++) + { + cxxSurface entity(&surface[i]); + entity.totalize(); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // gas phases + for (i = 0; i < count_gas_phase; i++) + { + cxxGasPhase entity(&gas_phase[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // solid-solutions + for (i = 0; i < count_s_s_assemblage; i++) + { + cxxSSassemblage entity(&s_s_assemblage[i]); + entity.totalize(this); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // kinetics + for (i = 0; i < count_kinetics; i++) + { + calc_dummy_kinetic_reaction_tally(&kinetics[i]); + cxxKinetics entity(&kinetics[i]); + accumulator.add_extensive(entity.get_totals(), 1.0); + } + + // Put in all primaries + cxxNameDouble::iterator it; + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + if (it->first == "Charge") continue; + char string[MAX_LENGTH]; + strcpy(string, it->first.c_str()); + struct master *master_ptr = master_bsearch_primary(string); + if (master_ptr == NULL) continue; + if (master_ptr->type != AQ) continue; + //std::string name(master_ptr->elt->name); + //char + accumulator.add(master_ptr->elt->name, 1); + } + // print list + for (it = accumulator.begin(); it != accumulator.end(); it++) + { + struct master *master_ptr = master_bsearch(it->first.c_str()); + if (master_ptr == NULL) continue; + if (master_ptr->type != AQ) continue; + if (master_ptr->primary == 0) continue; + if (it->first == "Charge") continue; + if (it->first == "O") continue; + if (it->first == "H") continue; + list_c.push_back(it->first); + } + return(list_c.size()); +} +void Phreeqc::init(void) +{ + int i; + + moles_per_kilogram_string = 0; + pe_string = 0; + + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + itmax = 100; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif + convergence_tolerance = 1e-8; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; + negative_concentrations = FALSE; + + LOG_10 = log(10.0); + + max_solution = MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; + + count_solution = 0; + count_pp_assemblage = 0; + count_exchange = 0; + count_surface = 0; + count_gas_phase = 0; + count_kinetics = 0; + count_s_s_assemblage = 0; + + count_elements = 0; + count_irrev = 0; + count_master = 0; + count_mix = 0; + count_phases = 0; + count_s = 0; + count_temperature = 0; + count_logk = 0; + count_master_isotope = 0; +/* + * Initialize advection + */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + + advection_punch = 0; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = 0; + advection_warnings = TRUE; +/* + * Initialize transport + */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + interlayer_tortf = 100.0; + interlayer_Dpor = 0.1; +/* !!!! count_stag = 0; */ + mcd_substeps = 1.0; + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; + + pp_assemblage = 0; + exchange = 0; + surface = 0; + gas_phase = 0; + kinetics = 0; + s_s_assemblage = 0; + cell_data = 0; + elements = 0; + elt_list = 0; + + + inverse = 0; + count_inverse = 0; + + irrev = 0; + + line = 0; + line_save = 0; + + master = 0; + + mb_unknowns = 0; + + mix = 0; + count_mix = 0; +/* !!!! */ + stag_data = 0; + + phases = 0; + + trxn.token = 0; + + s = 0; + + logk = 0; + + master_isotope = 0; + + solution = 0; + + temperature = 0; + + title_x = NULL; + pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; + + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; + + isotopes_x = 0; + + x = NULL; + max_unknowns = 0; + + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + + logk_hash_table = 0; + master_isotope_hash_table = 0; + strings_hash_table = 0; + elements_hash_table = 0; + species_hash_table = 0; + phases_hash_table = 0; + keyword_hash_table = 0; +/* + * Initialize use pointers + */ + use.solution_in = FALSE; + use.pp_assemblage_in = FALSE; + use.mix_in = FALSE; + use.irrev_in = FALSE; +/* + * Initialize punch + */ + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; + punch.count_molalities = 0; + + punch.molalities = 0; + punch.count_activities = 0; + + punch.activities = 0; + punch.count_pure_phases = 0; + + punch.pure_phases = 0; + punch.count_si = 0; + + punch.si = 0; + punch.count_gases = 0; + + punch.gases = 0; + punch.count_s_s = 0; + punch.s_s = 0; + + punch.count_kinetics = 0; + punch.kinetics = 0; + + punch.count_isotopes = 0; + punch.isotopes = 0; + + punch.count_calculate_values = 0; + punch.calculate_values = 0; + + count_save_values = 0; + save_values = 0; + + + punch.inverse = TRUE; + + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; +/* + * last model + */ + last_model.exchange = NULL; + last_model.gas_phase = NULL; + last_model.s_s_assemblage = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; + last_model.surface_charge = NULL; +/* + * Update hash table + */ + keyword_hash = 0; +/* + * rates + */ + rates = 0; + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_p = NULL; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + +/* + * user_print, user_punch + */ + user_print = 0; + user_punch = 0; + user_punch_headings = 0; + user_punch_count_headings = 0; +#ifdef PHREEQ98 +/* + * user_graph + */ + user_graph = 0; + user_graph_headings = 0 + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = 0; + llnl_count_temp = 0; + + llnl_adh = 0; + llnl_count_adh = 0; + + llnl_bdh = 0; + llnl_count_bdh = 0; + + llnl_bdot = 0; + llnl_count_bdot = 0; + + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; +/* + * + */ + command_hash_table = 0; + + change_surf = 0; + change_surf_count = 0; + + +#if defined(WINDOWS) || defined(_WINDOWS) + /* SRC pr.status = FALSE; */ +#endif + /* Initialize print here, not in global.h */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + if (phast == TRUE) + { + pr.status = FALSE; + } + else + { + pr.status = TRUE; + } + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + + species_list = NULL; + + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; + selected_output_file_name = NULL; + dump_file_name = NULL; + + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + + calculate_value = 0; + calculate_value_hash_table = 0; + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + isotope_ratio = 0; + isotope_ratio_hash_table = 0; + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + isotope_alpha = 0; + isotope_alpha_hash_table = 0; + + phreeqc_mpi_myself = 0; + + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + + set_forward_output_to_log(FALSE); + simulation = 0; + /* + * cvode + */ + + cvode_init(); + /* + * Pitzer + */ + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + use_etheta = TRUE; + pitz_params = 0; + + max_theta_param = 100; + count_theta_param = 0; + theta_params = 0; + + ICON = TRUE; + OTEMP = 0.0; + for (i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } + pitzer_pe = FALSE; + + + /* + * SIT + */ + sit_model = FALSE; + max_sit_param = 100; + count_sit_param = 0; + sit_params = 0; + + /* + * to facilitate debuging + */ + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; + dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + + zeros = 0; + zeros_max = 1; + + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + + charge_group = NULL; + print_density = 0; + + return; } \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index 3b54cbff..d3017bb2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1,1430 +1,1430 @@ -#ifndef _INC_PHREEQC_H -#define _INC_PHREEQC_H -#if defined(WIN32) -#include -#endif -/* ---------------------------------------------------------------------- - * INCLUDE FILES - * ---------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "sundialstypes.h" -#include "nvector.h" -#include "cvdense.h" -#include "nvector_serial.h" /* definitions of type N_Vector and macro */ - /* NV_Ith_S, prototypes for N_VNew, N_VFree */ -#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM */ -#include "nvector.h" -#include "runner.h" -#include "dumper.h" -#include "StorageBinList.h" - -#define STATIC -#define EXTERNAL -#define CLASS_QUALIFIER Phreeqc:: -#define CLASS_STATIC static -#define extern -#include "p2c.h" -#undef extern -#include "global_structures.h" -#include "pitzer_structures.h" -class Phreeqc -{ -public: - Phreeqc(void); - ~Phreeqc(void); - - -//private: -// -//struct _generic_N_Vector; -//struct calculate_value; -//struct conc; -//struct CVodeMemRec; -//struct element; -//struct exchange; -//struct exch_comp; -//struct elt_list; -//struct gas_phase; -//struct gas_comp; -//struct inverse; -//struct inv_elts; -//struct inv_phases; -//struct inv_isotope; -//struct irrev; -//struct isotope; -//struct kinetics; -//struct kinetics_comp; -//struct LOC_exec; -//struct master; -//struct master_activity; -//struct master_isotope; -//struct mix; -//struct mix_comp; -//struct name_coef; -//struct pe_data; -//struct phase; -//struct PHRQMemHeader; -//struct pitz_param; -//struct pp_assemblage; -//struct pure_phase; -//struct reaction; -//struct reaction_temp; -//struct rxn_token; -//struct rxn_token_temp; -//struct solution; -//struct species; -//struct s_s; -//struct s_s_assemblage; -//struct s_s_comp; -//struct species_diff_layer; -//struct surface; -//struct surface_comp; -//struct surface_charge; -//struct surface_diff_layer; -//struct theta_param; -//struct tokenrec; -//struct varrec; -//struct unknown; - -#define PITZER_EXTERNAL -#include "pitzer.h" -#include "input.h" -#define KINETICS_EXTERNAL -#include "sundialstypes.h" /* definitions of types realtype and */ - /* integertype, and the constant FALSE */ -public: -#include "output.h" -public: -#include "global.h" -/* - All functions are included as methods here -*/ -#define _INC_PHRQPROTO_H - -// advection.c ------------------------------- - -int advection(void); - -// basic.c ------------------------------- - -int basic_main(char *commands); -void cmd_initialize(void); -void cmd_free(void); -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -int basic_init(void); -#ifdef PHREEQ98 -void GridChar(char *s, char *a); -#endif -int sget_logical_line(char **ptr, int *l, char *return_line); -int free_dim_stringvar(varrec *varbase); -void exec(void); -int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); -void restoredata(void); -void clearloops(void); -void clearvar(varrec * v); -void clearvars(void); -Char * numtostr(Char * Result, LDBLE n); -void parse(Char * inbuf, tokenrec ** buf); -void listtokens(FILE * f, tokenrec * buf); -void disposetokens(tokenrec ** tok); -void parseinput(tokenrec ** buf); -void errormsg(const Char * s); -void snerr(const Char * s); -void tmerr(const Char * s); -void badsubscr(void); -LDBLE realfactor(struct LOC_exec *LINK); -Char * strfactor(struct LOC_exec * LINK); -Char *stringfactor(Char * Result, struct LOC_exec *LINK); -long intfactor(struct LOC_exec *LINK); -LDBLE realexpr(struct LOC_exec *LINK); -Char * strexpr(struct LOC_exec * LINK); -Char * stringexpr(Char * Result, struct LOC_exec * LINK); -long intexpr(struct LOC_exec *LINK); -void require(int k, struct LOC_exec *LINK); -void skipparen(struct LOC_exec *LINK); -varrec * findvar(struct LOC_exec *LINK); -valrec factor(struct LOC_exec *LINK); -valrec upexpr(struct LOC_exec * LINK); -valrec term(struct LOC_exec * LINK); -valrec sexpr(struct LOC_exec * LINK); -valrec relexpr(struct LOC_exec * LINK); -valrec andexpr(struct LOC_exec * LINK); -valrec expr(struct LOC_exec *LINK); -void checkextra(struct LOC_exec *LINK); -boolean iseos(struct LOC_exec *LINK); -void skiptoeos(struct LOC_exec *LINK); -linerec * findline(long n); -linerec * mustfindline(long n); -void cmdend(struct LOC_exec *LINK); -void cmdnew(struct LOC_exec *LINK); -void cmdlist(struct LOC_exec *LINK); -void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); -void cmdrun(struct LOC_exec *LINK); -void cmdsave(struct LOC_exec *LINK); -void cmdput(struct LOC_exec *LINK); -void cmdchange_por(struct LOC_exec *LINK); -void cmdchange_surf(struct LOC_exec *LINK); -void cmdbye(void); -void cmddel(struct LOC_exec *LINK); -void cmdrenum(struct LOC_exec *LINK); -void cmdprint(struct LOC_exec *LINK); -void cmdpunch(struct LOC_exec *LINK); -#ifdef PHREEQ98 -void cmdgraph_x(struct LOC_exec *LINK); -void cmdgraph_y(struct LOC_exec *LINK); -void cmdgraph_sy(struct LOC_exec *LINK); -#endif -void cmdlet(boolean implied, struct LOC_exec *LINK); -void cmdgoto(struct LOC_exec *LINK); -void cmdif(struct LOC_exec *LINK); -void cmdelse(struct LOC_exec *LINK); -boolean skiploop(int up, int dn, struct LOC_exec *LINK); -void cmdfor(struct LOC_exec *LINK); -void cmdnext(struct LOC_exec *LINK); -void cmdwhile(struct LOC_exec *LINK); -void cmdwend(struct LOC_exec *LINK); -void cmdgosub(struct LOC_exec *LINK); -void cmdreturn(struct LOC_exec *LINK); -void cmdread(struct LOC_exec *LINK); -void cmddata(struct LOC_exec *LINK); -void cmdrestore(struct LOC_exec *LINK); -void cmdgotoxy(struct LOC_exec *LINK); -void cmdon(struct LOC_exec *LINK); -void cmddim(struct LOC_exec *LINK); -void cmdpoke(struct LOC_exec *LINK); - -// basicsubs.c ------------------------------- - -LDBLE activity(const char *species_name); -LDBLE activity_coefficient(const char *species_name); -LDBLE log_activity_coefficient(const char *species_name); -LDBLE calc_SC(void); -/* VP: Density Start */ -LDBLE calc_dens(void); -/* VP: Density End */ -LDBLE calc_logk_n(const char *name); -LDBLE calc_logk_p(const char *name); -LDBLE calc_logk_s(const char *name); -LDBLE calc_surface_charge(const char *surface_name); -LDBLE diff_layer_total(const char *total_name, const char *surface_name); -LDBLE equi_phase(const char *phase_name); -LDBLE find_gas_comp(const char *gas_comp_name); -LDBLE find_misc1(const char *s_s_name); -LDBLE find_misc2(const char *s_s_name); -LDBLE find_s_s_comp(const char *s_s_comp_name); -LDBLE get_calculate_value(const char *name); -char * iso_unit(const char *total_name); -LDBLE iso_value(const char *total_name); -LDBLE kinetics_moles(const char *kinetics_name); -LDBLE log_activity(const char *species_name); -LDBLE log_molality(const char *species_name); -LDBLE molality(const char *species_name); -LDBLE saturation_ratio(const char *phase_name); -int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); -LDBLE solution_sum_secondary(const char *total_name); -LDBLE sum_match_gases(const char *stemplate, const char *name); -LDBLE sum_match_species(const char *stemplate, const char *name); -LDBLE sum_match_s_s(const char *stemplate, const char *name); -int match_elts_in_species(const char *name, const char *stemplate); -int extract_bracket(char **string, char *bracket_string); -LDBLE surf_total(const char *total_name, const char *surface_name); -CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); -LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); -int system_total_elements(void); -int system_total_si(void); -int system_total_aq(void); -int system_total_ex(void); -int system_total_surf(void); -int system_total_gas(void); -int system_total_s_s(void); -int system_total_elt(const char *total_name); -int system_total_elt_secondary(const char *total_name); -LDBLE total(const char *total_name); -LDBLE total_mole(const char *total_name); -int system_total_solids(struct exchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, - struct surface *surface_ptr); - -static LDBLE f_rho(LDBLE rho_old, void *cookie); - -// cl1.c ------------------------------- -int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q, - int *kode, LDBLE toler, - int *iter, LDBLE * x, LDBLE * res, LDBLE * error, - LDBLE * cu, int *iu, int *s, int check); -void cl1_space(int check, int n2d, int klm, int nklmd); - -// cl1mp.c ------------------------------- -int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - -// class_main.c ------------------------------- -#ifdef DOS -int write_banner(void); -#endif - -/* default.c */ -public: -int close_input_files(void); -int close_output_files(void); -CLASS_STATIC int getc_callback(void *cookie); -int process_file_names(int argc, char *argv[], void **db_cookie, - void **input_cookie, int log); - -// dw.c ------------------------------- -int BB(LDBLE T); -LDBLE PS(LDBLE T); -LDBLE VLEST(LDBLE T); -int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); -int QQ(LDBLE T, LDBLE D); -LDBLE BASE(LDBLE D); - -// input.c ------------------------------- - -int reading_database(void); -struct read_callback s_read_callback; -int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); - -// integrate.c ------------------------------- - -int calc_all_g(void); -int calc_init_g(void); -int initial_surface_water(void); -int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); -int calc_all_donnan(void); -int calc_init_donnan(void); -LDBLE g_function(LDBLE x_value); -LDBLE midpnt(LDBLE x1, LDBLE x2, int n); -void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); -LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); -LDBLE calc_psi_avg(LDBLE surf_chrg_eq); -int calc_all_donnan_music(void); -int calc_init_donnan_music(void); - -// inverse.c ------------------------------- - -int inverse_models(void); -int add_to_file(const char *filename, char *string); -int bit_print(unsigned long bits, int l); -int carbon_derivs(struct inverse *inv_ptr); -int check_isotopes(struct inverse *inv_ptr); -int check_solns(struct inverse *inv_ptr); -int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); -struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); -struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); -int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); -int post_mortem(void); -unsigned long get_bits(unsigned long bits, int position, int number); -unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); -void dump_netpath(struct inverse *inv_ptr); -int dump_netpath_pat(struct inverse *inv_ptr); -int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); -int phase_isotope_inequalities(struct inverse *inv_ptr); -int print_model(struct inverse *inv_ptr); -int punch_model_heading(struct inverse *inv_ptr); -int punch_model(struct inverse *inv_ptr); -void print_isotope(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); -void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); -int range(struct inverse *inv_ptr, unsigned long cur_bits); -int save_bad(unsigned long bits); -int save_good(unsigned long bits); -int save_minimal(unsigned long bits); -unsigned long set_bit(unsigned long bits, int position, int value); -int setup_inverse(struct inverse *inv_ptr); -int set_initial_solution(int n_user_old, int n_user_new); -int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *soln_ptr_orig, - int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); -int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); -int solve_inverse(struct inverse *inv_ptr); -int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); -int subset_bad(unsigned long bits); -int subset_minimal(unsigned long bits); -int superset_minimal(unsigned long bits); -int write_optimize_names(struct inverse *inv_ptr); - -// isotopes.c ------------------------------- - -int add_isotopes(struct solution *solution_ptr); -int calculate_values(void); -int calculate_isotope_moles(struct element *elt_ptr, - struct solution *solution_ptr, LDBLE total_moles); -LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); -int from_pcil(struct master_isotope *master_isotope_ptr); -int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_tu(struct master_isotope *master_isotope_ptr); -struct calculate_value *calculate_value_alloc(void); -int calculate_value_free(struct calculate_value *calculate_value_ptr); -struct calculate_value *calculate_value_search(const char *name); -struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); -struct isotope_alpha *isotope_alpha_alloc(void); -struct isotope_alpha *isotope_alpha_search(const char *name); -struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); -struct isotope_ratio *isotope_ratio_alloc(void); -struct isotope_ratio *isotope_ratio_search(const char *name); -struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_alloc(void); -struct master_isotope *master_isotope_search(const char *name); -int print_initial_solution_isotopes(void); -int print_isotope_ratios(void); -int print_isotope_alphas(void); -int punch_isotopes(void); -int punch_calculate_values(void); -int read_calculate_values(void); -int read_isotopes(void); -int read_isotope_ratios(void); -int read_isotope_alphas(void); -int calculate_value_init(struct calculate_value *calculate_value_ptr); -int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); -int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); -int master_isotope_init(struct master_isotope *master_isotope_ptr); - -// kinetics.c ------------------------------- - -void cvode_init(void); -int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); -int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_advection(int i, int use_mix, int use_kinetics, int nsaver); -int free_cvode(void); -public: -static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - -int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); -int calc_kinetic_reaction(struct kinetics *kinetics_ptr, - LDBLE time_step); -int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); -int set_reaction(int i, int use_mix, int use_kinetics); -int set_transport(int i, int use_mix, int use_kinetics, int nsaver); -int store_get_equi_reactants(int k, int kin_end); - -// mainsubs ------------------------------- - -FILE *file_open(char *query, char *default_name, const char *status, - int batch); -int copy_entities(void); -void initialize(void); -int initial_exchangers(int print); -int initial_gas_phases(int print); -int initial_solutions(int print); -int step_save_exch(int n_user); -int step_save_surf(int n_user); -int initial_surfaces(int print); -int reactions(void); -int saver(void); -int xsolution_save(int k_user); -int xexchange_save(int n_user); -int xgas_save(int n_user); -int xpp_assemblage_save(int n_user); -int xs_s_assemblage_save(int n_user); -int xsurface_save(int n_user); -int do_initialize(void); -int do_status(void); - -int copy_use(int i); -int set_use(void); - -// model.c ------------------------------- - -int check_residuals(void); -int free_model_allocs(void); -int ineq(int kode); -int model(void); -int jacobian_sums(void); -int mb_gases(void); -int mb_s_s(void); -int mb_sums(void); -int molalities(int allow_overflow); -int reset(void); -int residuals(void); -int set(int initial); -int sum_species(void); -int surface_model(void); - -LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); -LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); -LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); -int numerical_jacobian(void); -void set_inert_moles(void); -void unset_inert_moles(void); -#ifdef SLNQ -int add_trivial_eqns(int rows, int cols, LDBLE * matrix); -int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -#endif -int calc_gas_pressures(void); -int calc_s_s_fractions(void); -int gammas(LDBLE mu); -int initial_guesses(void); -int revise_guesses(void); -int s_s_binary(struct s_s *s_s_ptr); -int s_s_ideal(struct s_s *s_s_ptr); -//int remove_unstable_phases; -int gas_in; -void ineq_init(int max_row_count, int max_column_count); - -// output.c ------------------------------- - -int output_message(const int type, const char *err_str, const int stop, - const char *format, va_list args); - -// parse.c ------------------------------- - -int check_eqn(int association); -int get_charge(char *charge, LDBLE * z); -int get_elt(char **t_ptr, char *element, int *i); -int get_elts_in_species(char **t_ptr, LDBLE coef); -int get_num(char **t_ptr, LDBLE * num); -int get_secondary_in_species(char **t_ptr, LDBLE coef); -int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - -int get_coef(LDBLE * coef, char **eqnaddr); -int get_secondary(char **t_ptr, char *element, int *i); -int get_species(char **ptr); - -// phqalloc.c ------------------------------- -public: -#if !defined(NDEBUG) -void *PHRQ_malloc(size_t, const char *, int); -void *PHRQ_calloc(size_t, size_t, const char *, int); -void *PHRQ_realloc(void *, size_t, const char *, int); -#else -void *PHRQ_malloc(size_t); -void *PHRQ_calloc(size_t, size_t); -void *PHRQ_realloc(void *, size_t); -#endif -void PHRQ_free(void *ptr); - -void PHRQ_free_all(void); -protected: - -// phreeqc_files.c ------------------------------- - -#ifdef PHREEQ98 -void check_line_breaks(char *s); -char *prefix_database_dir(char *s); -void show_progress(const int type, char *s); -#endif -public: -int fileop_handler(const int type, int (*PFN) (FILE *)); -int open_handler(const int type, const char *file_name); -int output_handler(const int type, const char *err_str, - const int stop, void *cookie, const char *format, - va_list args); -static int rewind_wrapper(FILE * file_ptr); -Void PASCAL_MAIN(int argc, Char **argv); -long my_labs(long x); -Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); -Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); -int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); -Anyptr my_memset(Anyptr d, int c, size_t n); -int my_toupper(int c); -int my_tolower(int c); -long ipow(long a, long b); -char * strsub(register char *ret, register char *s, register int pos, - register int len); -int strpos2(char *s, register char *pat, register int pos); -int strcicmp(register char *s1, register char *s2); -char * strltrim(register char *s); -char * strrtrim(register char *s); -void strmove(register int len, register char *s, register int spos, - register char *d, register int dpos); -void strinsert(register char *src, register char *dst, register int pos); -int P_peek(FILE * f); -int P_eof(void); -int P_eoln(FILE * f); -Void P_readpaoc(FILE * f, char *s, int len); -Void P_readlnpaoc(FILE * f, char *s, int len); -long P_maxpos(FILE * f); -Char * P_trimname(register Char * fn, register int len); -long memavail(void); -long maxavail(void); -long * P_setunion(register long *d, register long *s1, register long *s2); -long * P_setint(register long *d, register long *s1, register long *s2); -long * P_setdiff(register long *d, register long *s1, register long *s2); -long * P_setxor(register long *d, register long *s1, register long *s2); -long * P_addset(register long *s, register unsigned val); -long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); -long * P_remset(register long *s, register unsigned val); -int P_setequal(register long *s1, register long *s2); -int P_subset(register long *s1, register long *s2); -long * P_setcpy(register long *d, register long *s); -long * P_expset(register long *d, register long s); -long P_packset(register long *s); -int _OutMem(void); -int _CaseCheck(void); -int _NilCheck(void); -static char * _ShowEscape(char *buf, int code, int ior, char *prefix); -int _Escape(int code); -int _EscIO(int code); - -// pitzer.c ------------------------------- - -int gammas_pz(void); -int model_pz(void); -int pitzer(void); -int pitzer_clean_up(void); -int pitzer_init(void); -int pitzer_tidy(void); -int read_pitzer(void); -int set_pz(int initial); - -int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_pz(void); -int ISPEC(char *name); -LDBLE G(LDBLE Y); -LDBLE GP(LDBLE Y); -int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); -int BDK(LDBLE X); -int pitzer_initial_guesses(void); -int pitzer_revise_guesses(void); -int pitzer_remove_unstable_phases; -int PTEMP(LDBLE TK); -LDBLE JAY(LDBLE X); -LDBLE JPRIME(LDBLE Y); -int jacobian_pz(void); - -// pitzer_structures.c ------------------------------- - -struct pitz_param *pitz_param_alloc(void); -int pitz_param_init(struct pitz_param *pitz_param_ptr); -struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); -int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); - -// pitzer_structures.c ------------------------------- - -int add_potential_factor(void); -int add_cd_music_factors(int n); -int add_surface_charge_balance(void); -int add_cd_music_charge_balances(int i); -int build_gas_phase(void); -int build_jacobian_sums(int k); -int build_mb_sums(void); -int build_min_exch(void); -int build_model(void); -int build_pure_phases(void); -int build_s_s_assemblage(void); -int build_solution_phase_boundaries(void); -int build_species_list(int n); -int build_min_surface(void); -int change_hydrogen_in_elt_list(LDBLE charge); -int clear(void); -int convert_units(struct solution *solution_ptr); -struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); -struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); -int inout(void); -int is_special(struct species *spec); -int mb_for_species_aq(int n); -int mb_for_species_ex(int n); -int mb_for_species_surf(int n); -int quick_setup(void); -int resetup_master(void); -int save_model(void); -int setup_exchange(void); -int setup_gas_phase(void); -int setup_master_rxn(struct master **master_ptr_list, - struct reaction **pe_rxn); -int setup_pure_phases(void); -int setup_related_surface(void); -int setup_s_s_assemblage(void); -int setup_solution(void); -int setup_surface(void); -int setup_unknowns(void); -int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); -int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); -int store_jacob0(int row, int column, LDBLE coef); -int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); -int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); -int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); -int tidy_redox(void); -struct master **unknown_alloc_master(void); -int write_mb_eqn_x(void); -int write_mb_for_species_list(int n); -int write_mass_action_eqn_x(int stop); - -/* prep.c */ - -int check_same_model(void); -int k_temp(LDBLE tc); -LDBLE k_calc(LDBLE * logk, LDBLE tempk); -int prep(void); -int reprep(void); -int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); -int switch_bases(void); -int write_phase_sys_total(int n); - -// print.c ------------------------------- - -int fpunchf(const char *name, const char *format, ...); -int fpunchf_user(int user_index, const char *format, ...); -int fpunchf_end_row(const char *format, ...); -char *sformatf(const char *format, ...); -int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); -int print_all(void); -int print_exchange(void); -int print_gas_phase(void); -int print_master_reactions(void); -int print_reaction(struct reaction *rxn_ptr); -int print_species(void); -int print_surface(void); -int print_user_print(void); -int punch_all(void); - -int print_alkalinity(void); -int print_diffuse_layer(struct surface_charge *surface_charge_ptr); -int print_eh(void); -int print_irrev(void); -int print_kinetics(void); -int print_mix(void); -int print_pp_assemblage(void); -int print_s_s_assemblage(void); -int print_saturation_indices(void); -int print_surface_cd_music(void); -int print_totals(void); -int print_using(void); -/*int print_user_print(void);*/ -int punch_gas_phase(void); -int punch_identifiers(void); -int punch_kinetics(void); -int punch_molalities(void); -int punch_activities(void); -int punch_pp_assemblage(void); -int punch_s_s_assemblage(void); -int punch_saturation_indices(void); -int punch_totals(void); -int punch_user_punch(void); -#ifdef PHREEQ98 -int punch_user_graph(void); -#endif - -// read.c ------------------------------- - -int read_input(void); -int read_conc(int n, int count_mass_balance, char *str); -int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); -int read_log_k_only(char *ptr, LDBLE * log_k); -int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description); -int check_key(char *str); -int check_units(char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print); -int find_option(char *item, int *n, const char **list, int count_list, - int exact); -int get_option(const char **opt_list, int count_opt_list, char **next_char); -int get_true_false(char *string, int default_value); - -int add_psi_master_species(char *token); -int read_advection(void); -int read_analytical_expression_only(char *ptr, LDBLE * log_k); -/* VP: Density Start */ -int read_millero_abcdef (char *ptr, LDBLE * abcdef); -/* VP: Density End */ -int read_copy(void); -int read_debug(void); -int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); -int read_llnl_aqueous_model_parameters(void); -int read_exchange(void); -int read_exchange_master_species(void); -int read_exchange_species(void); -int read_gas_phase(void); -int read_incremental_reactions(void); -int read_inverse(void); -int read_inv_balances(struct inverse *inverse_ptr, char *next_char); -int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); -int read_inv_phases(struct inverse *inverse_ptr, char *next_char); -int read_kinetics(void); -int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); -int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); -LDBLE *read_list_doubles(char **ptr, int *count_doubles); -int *read_list_ints(char **ptr, int *count_ints, int positive); -int *read_list_t_f(char **ptr, int *count_ints); -int read_master_species(void); -int read_mix(void); -int read_named_logk(void); -int read_phases(void); -int read_print(void); -int read_pure_phases(void); -int read_rates(void); -int read_reaction(void); -int read_reaction_reactants(struct irrev *irrev_ptr); -int read_reaction_steps(struct irrev *irrev_ptr); -int read_solid_solutions(void); -int read_temperature(void); -int read_reaction_temps(struct temperature *temperature_ptr); -int read_save(void); -int read_selected_output(void); -int read_solution(void); -int read_species(void); -int read_surf(void); -int read_surface_master_species(void); -int read_surface_species(void); -int read_use(void); -int read_title(void); -int read_user_print(void); -int read_user_punch(void); -#ifdef PHREEQ98 -int read_user_graph(void); -int copy_title(char *token_ptr, char **ptr, int *length); -int OpenCSVFile(char file_name[MAX_LENGTH]); -void GridHeadings(char *s, int i); -void SetAxisTitles(char *s, int i); -void SetAxisScale(char *a, int c, char *v, int l); -void SetChartTitle(char *s); -#endif -int next_keyword_or_option(const char **opt_list, int count_opt_list); - -// ReadClass.cxx - int read_solution_raw(void); - int read_exchange_raw(void); - int read_surface_raw(void); - int read_equilibrium_phases_raw(void); - int read_kinetics_raw(void); - int read_solid_solutions_raw(void); - int read_gas_phase_raw(void); - int read_reaction_raw(void); - int read_mix_raw(void); - int read_temperature_raw(void); - int read_dump(void); - int read_solution_modify(void); - int read_equilibrium_phases_modify(void); - int read_exchange_modify(void); - int read_surface_modify(void); - int read_solid_solutions_modify(void); - int read_gas_phase_modify(void); - int read_kinetics_modify(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); - - -// readtr.c ------------------------------- - -int read_transport(void); -int dump(void); -int dump_exchange(int k); -int dump_gas_phase(int k); -int dump_kinetics(int k); -int dump_mix(int k); -int dump_pp_assemblage(int k); -int dump_reaction(int k); -int dump_s_s_assemblage(int k); -int dump_solution(int k); -int dump_surface(int k); -int dump_cpp(void); - -int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - -// sit.c ------------------------------- - -int gammas_sit(void); -int model_sit(void); -int sit(void); -int sit_clean_up(void); -int sit_init(void); -int sit_tidy(void); -int read_sit(void); -int set_sit(int initial); - -int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_sit(void); -int sit_ISPEC(char *name); -/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ -int sit_initial_guesses(void); -int sit_revise_guesses(void); -int sit_remove_unstable_phases; -int PTEMP_SIT(LDBLE tk); -int jacobian_sit(void); - -// spread.c ------------------------------- - -int read_solution_spread(void); - -int copy_token_tab(char *token_ptr, char **ptr, int *length); -int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); -int spread_row_free(struct spread_row *spread_row_ptr); -int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); -struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI -void add_row(struct spread_row *spread_row_ptr); -void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); -void free_spread(void); -struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - -// step.c ------------------------------- - -int step(LDBLE step_fraction); -int xsolution_zero(void); -int add_exchange(struct exchange *exchange_ptr); -int add_gas_phase(struct gas_phase *gas_phase_ptr); -int add_kinetics(struct kinetics *kinetics_ptr); -int add_mix(struct mix *mix_ptr); -int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int add_reaction(struct irrev *irrev_ptr, int step_number, - LDBLE step_fraction); -int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); -int add_solution(struct solution *solution_ptr, LDBLE extensive, - LDBLE intensive); -int add_surface(struct surface *surface_ptr); -int add_temperature(struct temperature *temperature_ptr, int step_number); - -int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int gas_phase_check(struct gas_phase *gas_phase_ptr); -int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); -int reaction_calc(struct irrev *irrev_ptr); -int solution_check(void); -int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); - -// structures.c ------------------------------- - -int clean_up(void); -int reinitialize(void); -int copier_add(struct copier *copier_ptr, int n_user, int start, int end); -int copier_free(struct copier *copier_ptr); -int copier_init(struct copier *copier_ptr); -CLASS_STATIC int element_compare(const void *ptr1, const void *ptr2); -public: - struct element *element_store(const char *element); - int elt_list_combine(void); - CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); -private: -struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); -int elt_list_print(struct elt_list *elt_list_ptr); -struct elt_list *elt_list_save(void); -public: - struct exchange *exchange_alloc(void); - struct exchange *exchange_bsearch(int k, int *n); -private: -int exchange_comp_compare(const void *ptr1, const void *ptr2); -void exchange_comp_init(struct exch_comp *exch_comp_ptr); -public: - int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new); -private: -CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); -int exchange_copy_to_last(int n, int n_user); -int exchange_delete(int n_user_old); -int exchange_duplicate(int n_user_old, int n_user_new); -int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, - const char *description); -public: - int exchange_free(struct exchange *exchange_ptr); -private: -int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); -struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, - int n_user_new); -struct exchange *exchange_search(int n_user, int *n, int print); -int exchange_sort(void); -CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); -public: - struct gas_phase *gas_phase_alloc(void); - struct gas_phase *gas_phase_bsearch(int k, int *n); -private: -CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); -public: -int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new); -private: -int gas_phase_copy_to_last(int n, int n_user); -int gas_phase_delete(int n_user_old); -int gas_phase_duplicate(int n_user_old, int n_user_new); -int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, - int n_user_end, char *description); -public: -int gas_phase_free(struct gas_phase *gas_phase_ptr); -private: -int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, - int n_user_new); -struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, - int n_user_new); -struct gas_phase *gas_phase_search(int n_user, int *n); -int gas_phase_sort(void); -enum entity_type get_entity_enum(char *name); -struct inverse *inverse_alloc(void); -int inverse_delete(int i); -CLASS_STATIC int inverse_isotope_compare(const void *ptr1, const void *ptr2); -struct inverse *inverse_search(int n_user, int *n); -int inverse_sort(void); -struct irrev *irrev_bsearch(int k, int *n); -int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, - int n_user_new); -int irrev_delete(int n_user_old); -int irrev_duplicate(int n_user_old, int n_user_new); -int irrev_free(struct irrev *irrev_ptr); -struct irrev *irrev_search(int n_user, int *n); -int irrev_sort(void); -public: - struct kinetics *kinetics_alloc(void); - struct kinetics *kinetics_bsearch(int k, int *n); -private: -int kinetics_delete(int n_user_old); -int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, - struct kinetics_comp *kinetics_comp_old_ptr); -CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); -public: -int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new); -private: -int kinetics_copy_to_last(int n, int n_user); -int kinetics_duplicate(int n_user_old, int n_user_new); -int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, - char *description); -public: -int kinetics_free(struct kinetics *kinetics_ptr); -private: -int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); -struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, - int n_user_new); -struct kinetics *kinetics_search(int n_user, int *n, int print); -int kinetics_sort(void); -struct logk *logk_alloc(void); -int logk_copy2orig(struct logk *logk_ptr); -struct logk *logk_store(char *name, int replace_if_found); -struct logk *logk_search(char *name); -struct master *master_alloc(void); -CLASS_STATIC int master_compare(const void *ptr1, const void *ptr2); -int master_delete(char *ptr); -public: -struct master *master_bsearch(const char *ptr); -struct master *master_bsearch_primary(char *ptr); -private: -struct master *master_search(char *ptr, int *n); -struct mix *mix_bsearch(int k, int *n); -int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new); -int mix_delete(int n_user_old); -int mix_duplicate(int n_user_old, int n_user_new); -int mix_free(struct mix *mix_ptr); -struct mix *mix_search(int n_user, int *n, int print); -int mix_sort(void); -struct pe_data *pe_data_alloc(void); -public: - struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); - struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -private: -int pe_data_store(struct pe_data **pe, const char *token); -public: -struct phase *phase_bsearch(const char *ptr, int *j, int print); -private: -CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); -int phase_delete(int i); -struct phase *phase_store(char *name); -public: -struct pp_assemblage *pp_assemblage_alloc(void); -struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); -private: -CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); -public: -int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, - int n_user_new); -private: -int pp_assemblage_copy_to_last(int n, int n_user); -int pp_assemblage_delete(int n_user_old); -int pp_assemblage_duplicate(int n_user_old, int n_user_new); -public: -int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); -private: -int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, - int n_user_end, char *description); -int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, - int n_user_new); -struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage - *pp_assemblage_old_ptr, - int n_user_new); -struct pp_assemblage *pp_assemblage_search(int n_user, int *n); -int pp_assemblage_sort(void); -CLASS_STATIC int pure_phase_compare(const void *ptr1, const void *ptr2); -struct rate *rate_bsearch(char *ptr, int *j); -int rate_free(struct rate *rate_ptr); -struct rate *rate_search(char *name, int *n); -int rate_sort(void); -struct reaction *rxn_alloc(int ntokens); -struct reaction *rxn_dup(struct reaction *rxn_ptr_old); -LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); -int rxn_free(struct reaction *rxn_ptr); -int rxn_print(struct reaction *rxn_ptr); -CLASS_STATIC int s_compare(const void *ptr1, const void *ptr2); -int s_delete(int i); -struct species *s_search(const char *name); -struct species *s_store(char *name, LDBLE z, int replace_if_found); -public: - struct s_s_assemblage *s_s_assemblage_alloc(void); - struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); -private: -CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); -public: - int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, - int n_user_new); -private: -int s_s_assemblage_copy_to_last(int n, int n_user); -int s_s_assemblage_duplicate(int n_user_old, int n_user_new); -int s_s_assemblage_delete(int n_user_old); -public: - int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); -private: -int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, - int n_user, int n_user_end, char *description); -int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage - *s_s_assemblage_old_ptr, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); -int s_s_assemblage_sort(void); -CLASS_STATIC int s_s_compare(const void *ptr1, const void *ptr2); -struct save_values *save_values_bsearch(struct save_values *k, int *n); -CLASS_STATIC int save_values_compare(const void *ptr1, const void *ptr2); -int save_values_sort(void); -int save_values_store(struct save_values *s_v); -CLASS_STATIC int conc_compare(const void *ptr1, const void *ptr2); -int conc_init(struct conc *conc_ptr); -CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); -public: - struct solution *solution_alloc(void); - struct solution *solution_bsearch(int k, int *n, int print); -private: - struct solution *solution_copy(struct solution *solution_old_ptr, - int n_user_new); -int solution_copy_to_last(int n, int n_user_new); -int solution_duplicate(int n_user_old, int n_user_new); -int solution_delete(int n_user_old); -int solution_delete_n(int n); -int solution_free(struct solution *solution_ptr); -int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); -struct solution *solution_replicate(struct solution *solution_old_ptr, - int n_user_new); -int solution_sort(void); -CLASS_STATIC int species_list_compare_alk(const void *ptr1, const void *ptr2); -CLASS_STATIC int species_list_compare_master(const void *ptr1, const void *ptr2); -int species_list_sort(void); -struct Change_Surf *change_surf_alloc(int count); -public: - struct surface *surface_alloc(void); - struct surface *surface_bsearch(int k, int *n); -private: -struct master *surface_get_psi_master(const char *name, int plane); -CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); -CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); -struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); -int surface_charge_free(struct surface_charge *charge); -CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); -public: - int surface_copy(struct surface *surface_old_ptr, - struct surface *surface_new_ptr, int n_user_new); -private: -int surface_copy_to_last(int n, int n_user); -int surface_delete(int n_user_old); -int surface_duplicate(int n_user_old, int n_user_new); -public: - int surface_free(struct surface *surface_ptr); -protected: -int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, - char *description); -int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); -struct surface *surface_replicate(struct surface *surface_old_ptr, - int n_user_new); -struct surface *surface_search(int n_user, int *n, int print); -int surface_sort(void); -int system_duplicate(int i, int save_old); -struct temperature *temperature_bsearch(int k, int *n); -int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new); -int temperature_delete(int n_user_old); -int temperature_duplicate(int n_user_old, int n_user_new); -int temperature_free(struct temperature *temperature_ptr); -struct temperature *temperature_search(int n_user, int *n); -int temperature_sort(void); -int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_combine(void); -int trxn_copy(struct reaction *rxn_ptr); -LDBLE trxn_find_coef(const char *str, int start); -int trxn_print(void); -int trxn_reverse_k(void); -int trxn_sort(void); -int trxn_swap(const char *token); -struct unknown *unknown_alloc(void); -int unknown_delete(int i); -int unknown_free(struct unknown *unknown_ptr); -int entity_exists(char *name, int n_user); - -static int exchange_compare_int(const void *ptr1, const void *ptr2); -static int gas_phase_compare_int(const void *ptr1, const void *ptr2); -static int inverse_compare(const void *ptr1, const void *ptr2); -int inverse_free(struct inverse *inverse_ptr); -static int irrev_compare(const void *ptr1, const void *ptr2); -static int irrev_compare_int(const void *ptr1, const void *ptr2); -static int kinetics_compare_int(const void *ptr1, const void *ptr2); -int logk_init(struct logk *logk_ptr); -static int master_compare_string(const void *ptr1, const void *ptr2); -int master_free(struct master *master_ptr); -static int mix_compare(const void *ptr1, const void *ptr2); -static int mix_compare_int(const void *ptr1, const void *ptr2); -struct phase *phase_alloc(void); -static int phase_compare_string(const void *ptr1, const void *ptr2); -int phase_free(struct phase *phase_ptr); -int phase_init(struct phase *phase_ptr); -static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int rate_compare(const void *ptr1, const void *ptr2); -static int rate_compare_string(const void *ptr1, const void *ptr2); -struct species *s_alloc(void); -int s_free(struct species *s_ptr); -int s_init(struct species *s_ptr); -static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int solution_compare(const void *ptr1, const void *ptr2); -static int solution_compare_int(const void *ptr1, const void *ptr2); -static int species_list_compare(const void *ptr1, const void *ptr2); -static int surface_compare_int(const void *ptr1, const void *ptr2); -static int temperature_compare(const void *ptr1, const void *ptr2); -static int temperature_compare_int(const void *ptr1, const void *ptr2); -static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); -int trxn_multiply(LDBLE coef); -#ifdef PHREEQCI_GUI -extern void free_spread(void); -#endif -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern void MergeFinalize(void); -#endif - -/* tally.c */ - -void add_all_components_tally(void); -int build_tally_table(void); -int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); -int diff_tally_table(void); -int extend_tally_table(void); -int free_tally_table(void); -int fill_tally_table(int *n_user, int index_conservative, int n_buffer); -int get_tally_table_rows_columns(int *rows, int *columns); -int get_tally_table_column_heading(int column, int *type, char *string); -int get_tally_table_row_heading(int column, char *string); -int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); -int zero_tally_table(void); - -int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); -int get_all_components(void); -int print_tally_table(void); -int set_reaction_moles(int n_user, LDBLE moles); -int set_reaction_temperature(int n_user, LDBLE tc); -int set_kinetics_time(int n_user, LDBLE step); - -// tidy.c ------------------------------- - -int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); -int add_logks(struct logk *logk_ptr, int repeats); -LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); -int replace_solids_gases(void); -int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); -int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); -int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -public: -int tidy_punch(void); -int tidy_model(void); - -int check_species_input(void); -LDBLE coef_in_master(struct master *master_ptr); -int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); -int reset_last_model(void); -int rewrite_eqn_to_primary(void); -int rewrite_eqn_to_secondary(void); -int species_rxn_to_trxn(struct species *s_ptr); -int tidy_logk(void); -int tidy_exchange(void); -int tidy_min_exchange(void); -int tidy_kin_exchange(void); -int tidy_gas_phase(void); -int tidy_inverse(void); -int tidy_isotopes(void); -int tidy_isotope_ratios(void); -int tidy_isotope_alphas(void); -int tidy_kin_surface(void); -int tidy_master_isotope(void); -int tidy_min_surface(void); -int tidy_phases(void); -int tidy_pp_assemblage(void); -int tidy_solutions(void); -int tidy_s_s_assemblage(void); -int tidy_species(void); -int tidy_surface(void); -int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); -static LDBLE f_spinodal(LDBLE x, void *); -int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); -int s_s_calc_a0_a1(struct s_s *s_s_ptr); - -// transport.c ------------------------------- - -int transport(void); -int set_initial_moles(int i); -int sum_surface_comp(struct surface *source1, LDBLE f1, - struct surface *source2, int k, LDBLE f2, - struct surface *target, LDBLE new_Dw); -int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, - LDBLE new_Dw, int cell); -LDBLE viscosity(void); - -int multi_D(LDBLE DDt, int mobile_cell, int stagnant); -int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); -int fill_spec(int cell_no); -int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); -static int sort_species_name(const void *ptr1, const void *ptr2); -int disp_surf(LDBLE stagkin_time); -int diff_stag_surf(int mobile_cell); -int check_surfaces(struct surface *surface_ptr1, - struct surface *surface_ptr2); -int mobile_surface_copy(struct surface *surface_old_ptr, - struct surface *surf_ptr1, int n_user_new, - int move_old); -int init_mix(void); -int init_heat_mix(int nmix); -int heat_mix(int heat_nmix); -int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); - - -// utilities.c ------------------------------- -public: -int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); -private: -int backspace_screen(int spaces); -LDBLE calc_alk(struct reaction *rxn_ptr); -public: - int compute_gfw(const char *string, LDBLE * gfw); -int copy_token(char *token_ptr, char **ptr, int *length); -int dup_print(const char *ptr, int emphasis); -int equal(LDBLE a, LDBLE b, LDBLE eps); -public: - void *free_check_null(void *ptr); -private: -void free_hash_strings(HashTable * Table); -int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); -int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); -void hdestroy_multi(HashTable * HashTable_ptr); -ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); -int islegit(const char c); -public: -void malloc_error(void); -private: -int parse_couple(char *token); -int print_centered(const char *string); -public: -CLASS_STATIC int replace(const char *str1, const char *str2, char *str); -private: -void space(void **ptr, int i, int *max, int struct_size); -void squeeze_white(char *s_l); -int status(int count, const char *str); -void str_tolower(char *str); -void str_toupper(char *str); -CLASS_STATIC int strcmp_nocase(const char *str1, const char *str2); -int strcmp_nocase_arg1(const char *str1, const char *str2); -public: - char *string_duplicate(const char *token); - char *string_hsave(const char *str); -private: -char *string_pad(char *str, int i); -int string_trim(char *str); -int string_trim_right(char *str); -int string_trim_left(char *str); -CLASS_STATIC LDBLE under(LDBLE xval); -void zero_double(LDBLE * target, int n); - -#ifdef PHREEQ98 -void AddToCEntry(char *a, int l, int i); -void ApplicationProcessMessages(void); -int copy_title(char *token_ptr, char **ptr, int *length); -extern int clean_up_null(void); -#endif -int isamong(char c, const char *s_l); -Address Hash_multi(HashTable * Table, char *Key); -void ExpandTable_multi(HashTable * Table); - -public: // public methods for PHREEQC_CLASS - int main_method(int argc, char *argv[]); - void set_phast(int); - size_t list_components(std::list &list_c); -protected: - void init(void); -}; -#endif /* _INC_PHREEQC_H */ - +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +/* ---------------------------------------------------------------------- + * INCLUDE FILES + * ---------------------------------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "cvdense.h" +#include "nvector_serial.h" /* definitions of type N_Vector and macro */ + /* NV_Ith_S, prototypes for N_VNew, N_VFree */ +#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM */ +#include "nvector.h" +#include "runner.h" +#include "dumper.h" +#include "StorageBinList.h" + +#define STATIC +#define EXTERNAL +#define CLASS_QUALIFIER Phreeqc:: +#define CLASS_STATIC static +#define extern +#include "p2c.h" +#undef extern +#include "global_structures.h" +#include "pitzer_structures.h" +class Phreeqc +{ +public: + Phreeqc(void); + ~Phreeqc(void); + + +//private: +// +//struct _generic_N_Vector; +//struct calculate_value; +//struct conc; +//struct CVodeMemRec; +//struct element; +//struct exchange; +//struct exch_comp; +//struct elt_list; +//struct gas_phase; +//struct gas_comp; +//struct inverse; +//struct inv_elts; +//struct inv_phases; +//struct inv_isotope; +//struct irrev; +//struct isotope; +//struct kinetics; +//struct kinetics_comp; +//struct LOC_exec; +//struct master; +//struct master_activity; +//struct master_isotope; +//struct mix; +//struct mix_comp; +//struct name_coef; +//struct pe_data; +//struct phase; +//struct PHRQMemHeader; +//struct pitz_param; +//struct pp_assemblage; +//struct pure_phase; +//struct reaction; +//struct reaction_temp; +//struct rxn_token; +//struct rxn_token_temp; +//struct solution; +//struct species; +//struct s_s; +//struct s_s_assemblage; +//struct s_s_comp; +//struct species_diff_layer; +//struct surface; +//struct surface_comp; +//struct surface_charge; +//struct surface_diff_layer; +//struct theta_param; +//struct tokenrec; +//struct varrec; +//struct unknown; + +#define PITZER_EXTERNAL +#include "pitzer.h" +#include "input.h" +#define KINETICS_EXTERNAL +#include "sundialstypes.h" /* definitions of types realtype and */ + /* integertype, and the constant FALSE */ +public: +#include "output.h" +public: +#include "global.h" +/* + All functions are included as methods here +*/ +#define _INC_PHRQPROTO_H + +// advection.c ------------------------------- + +int advection(void); + +// basic.c ------------------------------- + +int basic_main(char *commands); +void cmd_initialize(void); +void cmd_free(void); +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +int basic_init(void); +#ifdef PHREEQ98 +void GridChar(char *s, char *a); +#endif +int sget_logical_line(char **ptr, int *l, char *return_line); +int free_dim_stringvar(varrec *varbase); +void exec(void); +int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); +void restoredata(void); +void clearloops(void); +void clearvar(varrec * v); +void clearvars(void); +Char * numtostr(Char * Result, LDBLE n); +void parse(Char * inbuf, tokenrec ** buf); +void listtokens(FILE * f, tokenrec * buf); +void disposetokens(tokenrec ** tok); +void parseinput(tokenrec ** buf); +void errormsg(const Char * s); +void snerr(const Char * s); +void tmerr(const Char * s); +void badsubscr(void); +LDBLE realfactor(struct LOC_exec *LINK); +Char * strfactor(struct LOC_exec * LINK); +Char *stringfactor(Char * Result, struct LOC_exec *LINK); +long intfactor(struct LOC_exec *LINK); +LDBLE realexpr(struct LOC_exec *LINK); +Char * strexpr(struct LOC_exec * LINK); +Char * stringexpr(Char * Result, struct LOC_exec * LINK); +long intexpr(struct LOC_exec *LINK); +void require(int k, struct LOC_exec *LINK); +void skipparen(struct LOC_exec *LINK); +varrec * findvar(struct LOC_exec *LINK); +valrec factor(struct LOC_exec *LINK); +valrec upexpr(struct LOC_exec * LINK); +valrec term(struct LOC_exec * LINK); +valrec sexpr(struct LOC_exec * LINK); +valrec relexpr(struct LOC_exec * LINK); +valrec andexpr(struct LOC_exec * LINK); +valrec expr(struct LOC_exec *LINK); +void checkextra(struct LOC_exec *LINK); +boolean iseos(struct LOC_exec *LINK); +void skiptoeos(struct LOC_exec *LINK); +linerec * findline(long n); +linerec * mustfindline(long n); +void cmdend(struct LOC_exec *LINK); +void cmdnew(struct LOC_exec *LINK); +void cmdlist(struct LOC_exec *LINK); +void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); +void cmdrun(struct LOC_exec *LINK); +void cmdsave(struct LOC_exec *LINK); +void cmdput(struct LOC_exec *LINK); +void cmdchange_por(struct LOC_exec *LINK); +void cmdchange_surf(struct LOC_exec *LINK); +void cmdbye(void); +void cmddel(struct LOC_exec *LINK); +void cmdrenum(struct LOC_exec *LINK); +void cmdprint(struct LOC_exec *LINK); +void cmdpunch(struct LOC_exec *LINK); +#ifdef PHREEQ98 +void cmdgraph_x(struct LOC_exec *LINK); +void cmdgraph_y(struct LOC_exec *LINK); +void cmdgraph_sy(struct LOC_exec *LINK); +#endif +void cmdlet(boolean implied, struct LOC_exec *LINK); +void cmdgoto(struct LOC_exec *LINK); +void cmdif(struct LOC_exec *LINK); +void cmdelse(struct LOC_exec *LINK); +boolean skiploop(int up, int dn, struct LOC_exec *LINK); +void cmdfor(struct LOC_exec *LINK); +void cmdnext(struct LOC_exec *LINK); +void cmdwhile(struct LOC_exec *LINK); +void cmdwend(struct LOC_exec *LINK); +void cmdgosub(struct LOC_exec *LINK); +void cmdreturn(struct LOC_exec *LINK); +void cmdread(struct LOC_exec *LINK); +void cmddata(struct LOC_exec *LINK); +void cmdrestore(struct LOC_exec *LINK); +void cmdgotoxy(struct LOC_exec *LINK); +void cmdon(struct LOC_exec *LINK); +void cmddim(struct LOC_exec *LINK); +void cmdpoke(struct LOC_exec *LINK); + +// basicsubs.c ------------------------------- + +LDBLE activity(const char *species_name); +LDBLE activity_coefficient(const char *species_name); +LDBLE log_activity_coefficient(const char *species_name); +LDBLE calc_SC(void); +/* VP: Density Start */ +LDBLE calc_dens(void); +/* VP: Density End */ +LDBLE calc_logk_n(const char *name); +LDBLE calc_logk_p(const char *name); +LDBLE calc_logk_s(const char *name); +LDBLE calc_surface_charge(const char *surface_name); +LDBLE diff_layer_total(const char *total_name, const char *surface_name); +LDBLE equi_phase(const char *phase_name); +LDBLE find_gas_comp(const char *gas_comp_name); +LDBLE find_misc1(const char *s_s_name); +LDBLE find_misc2(const char *s_s_name); +LDBLE find_s_s_comp(const char *s_s_comp_name); +LDBLE get_calculate_value(const char *name); +char * iso_unit(const char *total_name); +LDBLE iso_value(const char *total_name); +LDBLE kinetics_moles(const char *kinetics_name); +LDBLE log_activity(const char *species_name); +LDBLE log_molality(const char *species_name); +LDBLE molality(const char *species_name); +LDBLE saturation_ratio(const char *phase_name); +int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); +LDBLE solution_sum_secondary(const char *total_name); +LDBLE sum_match_gases(const char *stemplate, const char *name); +LDBLE sum_match_species(const char *stemplate, const char *name); +LDBLE sum_match_s_s(const char *stemplate, const char *name); +int match_elts_in_species(const char *name, const char *stemplate); +int extract_bracket(char **string, char *bracket_string); +LDBLE surf_total(const char *total_name, const char *surface_name); +CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); +LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); +int system_total_elements(void); +int system_total_si(void); +int system_total_aq(void); +int system_total_ex(void); +int system_total_surf(void); +int system_total_gas(void); +int system_total_s_s(void); +int system_total_elt(const char *total_name); +int system_total_elt_secondary(const char *total_name); +LDBLE total(const char *total_name); +LDBLE total_mole(const char *total_name); +int system_total_solids(struct exchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr); + +static LDBLE f_rho(LDBLE rho_old, void *cookie); + +// cl1.c ------------------------------- +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); +void cl1_space(int check, int n2d, int klm, int nklmd); + +// cl1mp.c ------------------------------- +int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + +// class_main.c ------------------------------- +#ifdef DOS +int write_banner(void); +#endif + +/* default.c */ +public: +int close_input_files(void); +int close_output_files(void); +CLASS_STATIC int getc_callback(void *cookie); +int process_file_names(int argc, char *argv[], void **db_cookie, + void **input_cookie, int log); + +// dw.c ------------------------------- +int BB(LDBLE T); +LDBLE PS(LDBLE T); +LDBLE VLEST(LDBLE T); +int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); +int QQ(LDBLE T, LDBLE D); +LDBLE BASE(LDBLE D); + +// input.c ------------------------------- + +int reading_database(void); +struct read_callback s_read_callback; +int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + +// integrate.c ------------------------------- + +int calc_all_g(void); +int calc_init_g(void); +int initial_surface_water(void); +int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); +int calc_all_donnan(void); +int calc_init_donnan(void); +LDBLE g_function(LDBLE x_value); +LDBLE midpnt(LDBLE x1, LDBLE x2, int n); +void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); +LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); +LDBLE calc_psi_avg(LDBLE surf_chrg_eq); +int calc_all_donnan_music(void); +int calc_init_donnan_music(void); + +// inverse.c ------------------------------- + +int inverse_models(void); +int add_to_file(const char *filename, char *string); +int bit_print(unsigned long bits, int l); +int carbon_derivs(struct inverse *inv_ptr); +int check_isotopes(struct inverse *inv_ptr); +int check_solns(struct inverse *inv_ptr); +int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); +struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); +struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); +int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); +int post_mortem(void); +unsigned long get_bits(unsigned long bits, int position, int number); +unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); +void dump_netpath(struct inverse *inv_ptr); +int dump_netpath_pat(struct inverse *inv_ptr); +int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); +int phase_isotope_inequalities(struct inverse *inv_ptr); +int print_model(struct inverse *inv_ptr); +int punch_model_heading(struct inverse *inv_ptr); +int punch_model(struct inverse *inv_ptr); +void print_isotope(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); +void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); +int range(struct inverse *inv_ptr, unsigned long cur_bits); +int save_bad(unsigned long bits); +int save_good(unsigned long bits); +int save_minimal(unsigned long bits); +unsigned long set_bit(unsigned long bits, int position, int value); +int setup_inverse(struct inverse *inv_ptr); +int set_initial_solution(int n_user_old, int n_user_new); +int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *soln_ptr_orig, + int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); +int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); +int solve_inverse(struct inverse *inv_ptr); +int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); +int subset_bad(unsigned long bits); +int subset_minimal(unsigned long bits); +int superset_minimal(unsigned long bits); +int write_optimize_names(struct inverse *inv_ptr); + +// isotopes.c ------------------------------- + +int add_isotopes(struct solution *solution_ptr); +int calculate_values(void); +int calculate_isotope_moles(struct element *elt_ptr, + struct solution *solution_ptr, LDBLE total_moles); +LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); +int from_pcil(struct master_isotope *master_isotope_ptr); +int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_tu(struct master_isotope *master_isotope_ptr); +struct calculate_value *calculate_value_alloc(void); +int calculate_value_free(struct calculate_value *calculate_value_ptr); +struct calculate_value *calculate_value_search(const char *name); +struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); +struct isotope_alpha *isotope_alpha_alloc(void); +struct isotope_alpha *isotope_alpha_search(const char *name); +struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); +struct isotope_ratio *isotope_ratio_alloc(void); +struct isotope_ratio *isotope_ratio_search(const char *name); +struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_alloc(void); +struct master_isotope *master_isotope_search(const char *name); +int print_initial_solution_isotopes(void); +int print_isotope_ratios(void); +int print_isotope_alphas(void); +int punch_isotopes(void); +int punch_calculate_values(void); +int read_calculate_values(void); +int read_isotopes(void); +int read_isotope_ratios(void); +int read_isotope_alphas(void); +int calculate_value_init(struct calculate_value *calculate_value_ptr); +int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); +int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); +int master_isotope_init(struct master_isotope *master_isotope_ptr); + +// kinetics.c ------------------------------- + +void cvode_init(void); +int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); +int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_advection(int i, int use_mix, int use_kinetics, int nsaver); +int free_cvode(void); +public: +static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + +int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); +int calc_kinetic_reaction(struct kinetics *kinetics_ptr, + LDBLE time_step); +int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); +int set_reaction(int i, int use_mix, int use_kinetics); +int set_transport(int i, int use_mix, int use_kinetics, int nsaver); +int store_get_equi_reactants(int k, int kin_end); + +// mainsubs ------------------------------- + +FILE *file_open(char *query, char *default_name, const char *status, + int batch); +int copy_entities(void); +void initialize(void); +int initial_exchangers(int print); +int initial_gas_phases(int print); +int initial_solutions(int print); +int step_save_exch(int n_user); +int step_save_surf(int n_user); +int initial_surfaces(int print); +int reactions(void); +int saver(void); +int xsolution_save(int k_user); +int xexchange_save(int n_user); +int xgas_save(int n_user); +int xpp_assemblage_save(int n_user); +int xs_s_assemblage_save(int n_user); +int xsurface_save(int n_user); +int do_initialize(void); +int do_status(void); + +int copy_use(int i); +int set_use(void); + +// model.c ------------------------------- + +int check_residuals(void); +int free_model_allocs(void); +int ineq(int kode); +int model(void); +int jacobian_sums(void); +int mb_gases(void); +int mb_s_s(void); +int mb_sums(void); +int molalities(int allow_overflow); +int reset(void); +int residuals(void); +int set(int initial); +int sum_species(void); +int surface_model(void); + +LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); +LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); +LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); +int numerical_jacobian(void); +void set_inert_moles(void); +void unset_inert_moles(void); +#ifdef SLNQ +int add_trivial_eqns(int rows, int cols, LDBLE * matrix); +int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif +int calc_gas_pressures(void); +int calc_s_s_fractions(void); +int gammas(LDBLE mu); +int initial_guesses(void); +int revise_guesses(void); +int s_s_binary(struct s_s *s_s_ptr); +int s_s_ideal(struct s_s *s_s_ptr); +//int remove_unstable_phases; +int gas_in; +void ineq_init(int max_row_count, int max_column_count); + +// output.c ------------------------------- + +int output_message(const int type, const char *err_str, const int stop, + const char *format, va_list args); + +// parse.c ------------------------------- + +int check_eqn(int association); +int get_charge(char *charge, LDBLE * z); +int get_elt(char **t_ptr, char *element, int *i); +int get_elts_in_species(char **t_ptr, LDBLE coef); +int get_num(char **t_ptr, LDBLE * num); +int get_secondary_in_species(char **t_ptr, LDBLE coef); +int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + +int get_coef(LDBLE * coef, char **eqnaddr); +int get_secondary(char **t_ptr, char *element, int *i); +int get_species(char **ptr); + +// phqalloc.c ------------------------------- +public: +#if !defined(NDEBUG) +void *PHRQ_malloc(size_t, const char *, int); +void *PHRQ_calloc(size_t, size_t, const char *, int); +void *PHRQ_realloc(void *, size_t, const char *, int); +#else +void *PHRQ_malloc(size_t); +void *PHRQ_calloc(size_t, size_t); +void *PHRQ_realloc(void *, size_t); +#endif +void PHRQ_free(void *ptr); + +void PHRQ_free_all(void); +protected: + +// phreeqc_files.c ------------------------------- + +#ifdef PHREEQ98 +void check_line_breaks(char *s); +char *prefix_database_dir(char *s); +void show_progress(const int type, char *s); +#endif +public: +int fileop_handler(const int type, int (*PFN) (FILE *)); +int open_handler(const int type, const char *file_name); +int output_handler(const int type, const char *err_str, + const int stop, void *cookie, const char *format, + va_list args); +static int rewind_wrapper(FILE * file_ptr); +Void PASCAL_MAIN(int argc, Char **argv); +long my_labs(long x); +Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); +Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); +int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); +Anyptr my_memset(Anyptr d, int c, size_t n); +int my_toupper(int c); +int my_tolower(int c); +long ipow(long a, long b); +char * strsub(register char *ret, register char *s, register int pos, + register int len); +int strpos2(char *s, register char *pat, register int pos); +int strcicmp(register char *s1, register char *s2); +char * strltrim(register char *s); +char * strrtrim(register char *s); +void strmove(register int len, register char *s, register int spos, + register char *d, register int dpos); +void strinsert(register char *src, register char *dst, register int pos); +int P_peek(FILE * f); +int P_eof(void); +int P_eoln(FILE * f); +Void P_readpaoc(FILE * f, char *s, int len); +Void P_readlnpaoc(FILE * f, char *s, int len); +long P_maxpos(FILE * f); +Char * P_trimname(register Char * fn, register int len); +long memavail(void); +long maxavail(void); +long * P_setunion(register long *d, register long *s1, register long *s2); +long * P_setint(register long *d, register long *s1, register long *s2); +long * P_setdiff(register long *d, register long *s1, register long *s2); +long * P_setxor(register long *d, register long *s1, register long *s2); +long * P_addset(register long *s, register unsigned val); +long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); +long * P_remset(register long *s, register unsigned val); +int P_setequal(register long *s1, register long *s2); +int P_subset(register long *s1, register long *s2); +long * P_setcpy(register long *d, register long *s); +long * P_expset(register long *d, register long s); +long P_packset(register long *s); +int _OutMem(void); +int _CaseCheck(void); +int _NilCheck(void); +static char * _ShowEscape(char *buf, int code, int ior, char *prefix); +int _Escape(int code); +int _EscIO(int code); + +// pitzer.c ------------------------------- + +int gammas_pz(void); +int model_pz(void); +int pitzer(void); +int pitzer_clean_up(void); +int pitzer_init(void); +int pitzer_tidy(void); +int read_pitzer(void); +int set_pz(int initial); + +int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_pz(void); +int ISPEC(char *name); +LDBLE G(LDBLE Y); +LDBLE GP(LDBLE Y); +int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); +int BDK(LDBLE X); +int pitzer_initial_guesses(void); +int pitzer_revise_guesses(void); +int pitzer_remove_unstable_phases; +int PTEMP(LDBLE TK); +LDBLE JAY(LDBLE X); +LDBLE JPRIME(LDBLE Y); +int jacobian_pz(void); + +// pitzer_structures.c ------------------------------- + +struct pitz_param *pitz_param_alloc(void); +int pitz_param_init(struct pitz_param *pitz_param_ptr); +struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); +int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + +// pitzer_structures.c ------------------------------- + +int add_potential_factor(void); +int add_cd_music_factors(int n); +int add_surface_charge_balance(void); +int add_cd_music_charge_balances(int i); +int build_gas_phase(void); +int build_jacobian_sums(int k); +int build_mb_sums(void); +int build_min_exch(void); +int build_model(void); +int build_pure_phases(void); +int build_s_s_assemblage(void); +int build_solution_phase_boundaries(void); +int build_species_list(int n); +int build_min_surface(void); +int change_hydrogen_in_elt_list(LDBLE charge); +int clear(void); +int convert_units(struct solution *solution_ptr); +struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); +struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); +int inout(void); +int is_special(struct species *spec); +int mb_for_species_aq(int n); +int mb_for_species_ex(int n); +int mb_for_species_surf(int n); +int quick_setup(void); +int resetup_master(void); +int save_model(void); +int setup_exchange(void); +int setup_gas_phase(void); +int setup_master_rxn(struct master **master_ptr_list, + struct reaction **pe_rxn); +int setup_pure_phases(void); +int setup_related_surface(void); +int setup_s_s_assemblage(void); +int setup_solution(void); +int setup_surface(void); +int setup_unknowns(void); +int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); +int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); +int store_jacob0(int row, int column, LDBLE coef); +int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); +int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); +int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); +int tidy_redox(void); +struct master **unknown_alloc_master(void); +int write_mb_eqn_x(void); +int write_mb_for_species_list(int n); +int write_mass_action_eqn_x(int stop); + +/* prep.c */ + +int check_same_model(void); +int k_temp(LDBLE tc); +LDBLE k_calc(LDBLE * logk, LDBLE tempk); +int prep(void); +int reprep(void); +int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); +int switch_bases(void); +int write_phase_sys_total(int n); + +// print.c ------------------------------- + +int fpunchf(const char *name, const char *format, ...); +int fpunchf_user(int user_index, const char *format, ...); +int fpunchf_end_row(const char *format, ...); +char *sformatf(const char *format, ...); +int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); +int print_all(void); +int print_exchange(void); +int print_gas_phase(void); +int print_master_reactions(void); +int print_reaction(struct reaction *rxn_ptr); +int print_species(void); +int print_surface(void); +int print_user_print(void); +int punch_all(void); + +int print_alkalinity(void); +int print_diffuse_layer(struct surface_charge *surface_charge_ptr); +int print_eh(void); +int print_irrev(void); +int print_kinetics(void); +int print_mix(void); +int print_pp_assemblage(void); +int print_s_s_assemblage(void); +int print_saturation_indices(void); +int print_surface_cd_music(void); +int print_totals(void); +int print_using(void); +/*int print_user_print(void);*/ +int punch_gas_phase(void); +int punch_identifiers(void); +int punch_kinetics(void); +int punch_molalities(void); +int punch_activities(void); +int punch_pp_assemblage(void); +int punch_s_s_assemblage(void); +int punch_saturation_indices(void); +int punch_totals(void); +int punch_user_punch(void); +#ifdef PHREEQ98 +int punch_user_graph(void); +#endif + +// read.c ------------------------------- + +int read_input(void); +int read_conc(int n, int count_mass_balance, char *str); +int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); +int read_log_k_only(char *ptr, LDBLE * log_k); +int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description); +int check_key(char *str); +int check_units(char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print); +int find_option(char *item, int *n, const char **list, int count_list, + int exact); +int get_option(const char **opt_list, int count_opt_list, char **next_char); +int get_true_false(char *string, int default_value); + +int add_psi_master_species(char *token); +int read_advection(void); +int read_analytical_expression_only(char *ptr, LDBLE * log_k); +/* VP: Density Start */ +int read_millero_abcdef (char *ptr, LDBLE * abcdef); +/* VP: Density End */ +int read_copy(void); +int read_debug(void); +int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); +int read_llnl_aqueous_model_parameters(void); +int read_exchange(void); +int read_exchange_master_species(void); +int read_exchange_species(void); +int read_gas_phase(void); +int read_incremental_reactions(void); +int read_inverse(void); +int read_inv_balances(struct inverse *inverse_ptr, char *next_char); +int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); +int read_inv_phases(struct inverse *inverse_ptr, char *next_char); +int read_kinetics(void); +int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); +int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); +LDBLE *read_list_doubles(char **ptr, int *count_doubles); +int *read_list_ints(char **ptr, int *count_ints, int positive); +int *read_list_t_f(char **ptr, int *count_ints); +int read_master_species(void); +int read_mix(void); +int read_named_logk(void); +int read_phases(void); +int read_print(void); +int read_pure_phases(void); +int read_rates(void); +int read_reaction(void); +int read_reaction_reactants(struct irrev *irrev_ptr); +int read_reaction_steps(struct irrev *irrev_ptr); +int read_solid_solutions(void); +int read_temperature(void); +int read_reaction_temps(struct temperature *temperature_ptr); +int read_save(void); +int read_selected_output(void); +int read_solution(void); +int read_species(void); +int read_surf(void); +int read_surface_master_species(void); +int read_surface_species(void); +int read_use(void); +int read_title(void); +int read_user_print(void); +int read_user_punch(void); +#ifdef PHREEQ98 +int read_user_graph(void); +int copy_title(char *token_ptr, char **ptr, int *length); +int OpenCSVFile(char file_name[MAX_LENGTH]); +void GridHeadings(char *s, int i); +void SetAxisTitles(char *s, int i); +void SetAxisScale(char *a, int c, char *v, int l); +void SetChartTitle(char *s); +#endif +int next_keyword_or_option(const char **opt_list, int count_opt_list); + +// ReadClass.cxx + int read_solution_raw(void); + int read_exchange_raw(void); + int read_surface_raw(void); + int read_equilibrium_phases_raw(void); + int read_kinetics_raw(void); + int read_solid_solutions_raw(void); + int read_gas_phase_raw(void); + int read_reaction_raw(void); + int read_mix_raw(void); + int read_temperature_raw(void); + int read_dump(void); + int read_solution_modify(void); + int read_equilibrium_phases_modify(void); + int read_exchange_modify(void); + int read_surface_modify(void); + int read_solid_solutions_modify(void); + int read_gas_phase_modify(void); + int read_kinetics_modify(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); + + +// readtr.c ------------------------------- + +int read_transport(void); +int dump(void); +int dump_exchange(int k); +int dump_gas_phase(int k); +int dump_kinetics(int k); +int dump_mix(int k); +int dump_pp_assemblage(int k); +int dump_reaction(int k); +int dump_s_s_assemblage(int k); +int dump_solution(int k); +int dump_surface(int k); +int dump_cpp(void); + +int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + +// sit.c ------------------------------- + +int gammas_sit(void); +int model_sit(void); +int sit(void); +int sit_clean_up(void); +int sit_init(void); +int sit_tidy(void); +int read_sit(void); +int set_sit(int initial); + +int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_sit(void); +int sit_ISPEC(char *name); +/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ +int sit_initial_guesses(void); +int sit_revise_guesses(void); +int sit_remove_unstable_phases; +int PTEMP_SIT(LDBLE tk); +int jacobian_sit(void); + +// spread.c ------------------------------- + +int read_solution_spread(void); + +int copy_token_tab(char *token_ptr, char **ptr, int *length); +int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); +int spread_row_free(struct spread_row *spread_row_ptr); +int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); +struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI +void add_row(struct spread_row *spread_row_ptr); +void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); +void free_spread(void); +struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + +// step.c ------------------------------- + +int step(LDBLE step_fraction); +int xsolution_zero(void); +int add_exchange(struct exchange *exchange_ptr); +int add_gas_phase(struct gas_phase *gas_phase_ptr); +int add_kinetics(struct kinetics *kinetics_ptr); +int add_mix(struct mix *mix_ptr); +int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int add_reaction(struct irrev *irrev_ptr, int step_number, + LDBLE step_fraction); +int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); +int add_solution(struct solution *solution_ptr, LDBLE extensive, + LDBLE intensive); +int add_surface(struct surface *surface_ptr); +int add_temperature(struct temperature *temperature_ptr, int step_number); + +int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int gas_phase_check(struct gas_phase *gas_phase_ptr); +int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); +int reaction_calc(struct irrev *irrev_ptr); +int solution_check(void); +int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); + +// structures.c ------------------------------- + +int clean_up(void); +int reinitialize(void); +int copier_add(struct copier *copier_ptr, int n_user, int start, int end); +int copier_free(struct copier *copier_ptr); +int copier_init(struct copier *copier_ptr); +CLASS_STATIC int element_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); +private: +struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); +int elt_list_print(struct elt_list *elt_list_ptr); +struct elt_list *elt_list_save(void); +public: + struct exchange *exchange_alloc(void); + struct exchange *exchange_bsearch(int k, int *n); +private: +int exchange_comp_compare(const void *ptr1, const void *ptr2); +void exchange_comp_init(struct exch_comp *exch_comp_ptr); +public: + int exchange_copy(struct exchange *exchange_old_ptr, + struct exchange *exchange_new_ptr, int n_user_new); +private: +CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); +int exchange_copy_to_last(int n, int n_user); +int exchange_delete(int n_user_old); +int exchange_duplicate(int n_user_old, int n_user_new); +int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, + const char *description); +public: + int exchange_free(struct exchange *exchange_ptr); +private: +int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); +struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, + int n_user_new); +struct exchange *exchange_search(int n_user, int *n, int print); +int exchange_sort(void); +CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); +public: + struct gas_phase *gas_phase_alloc(void); + struct gas_phase *gas_phase_bsearch(int k, int *n); +private: +CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); +public: +int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new); +private: +int gas_phase_copy_to_last(int n, int n_user); +int gas_phase_delete(int n_user_old); +int gas_phase_duplicate(int n_user_old, int n_user_new); +int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, + int n_user_end, char *description); +public: +int gas_phase_free(struct gas_phase *gas_phase_ptr); +private: +int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, + int n_user_new); +struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, + int n_user_new); +struct gas_phase *gas_phase_search(int n_user, int *n); +int gas_phase_sort(void); +enum entity_type get_entity_enum(char *name); +struct inverse *inverse_alloc(void); +int inverse_delete(int i); +CLASS_STATIC int inverse_isotope_compare(const void *ptr1, const void *ptr2); +struct inverse *inverse_search(int n_user, int *n); +int inverse_sort(void); +struct irrev *irrev_bsearch(int k, int *n); +int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, + int n_user_new); +int irrev_delete(int n_user_old); +int irrev_duplicate(int n_user_old, int n_user_new); +int irrev_free(struct irrev *irrev_ptr); +struct irrev *irrev_search(int n_user, int *n); +int irrev_sort(void); +public: + struct kinetics *kinetics_alloc(void); + struct kinetics *kinetics_bsearch(int k, int *n); +private: +int kinetics_delete(int n_user_old); +int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, + struct kinetics_comp *kinetics_comp_old_ptr); +CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); +public: +int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new); +private: +int kinetics_copy_to_last(int n, int n_user); +int kinetics_duplicate(int n_user_old, int n_user_new); +int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, + char *description); +public: +int kinetics_free(struct kinetics *kinetics_ptr); +private: +int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); +struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, + int n_user_new); +struct kinetics *kinetics_search(int n_user, int *n, int print); +int kinetics_sort(void); +struct logk *logk_alloc(void); +int logk_copy2orig(struct logk *logk_ptr); +struct logk *logk_store(char *name, int replace_if_found); +struct logk *logk_search(char *name); +struct master *master_alloc(void); +CLASS_STATIC int master_compare(const void *ptr1, const void *ptr2); +int master_delete(char *ptr); +public: +struct master *master_bsearch(const char *ptr); +struct master *master_bsearch_primary(char *ptr); +private: +struct master *master_search(char *ptr, int *n); +struct mix *mix_bsearch(int k, int *n); +int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new); +int mix_delete(int n_user_old); +int mix_duplicate(int n_user_old, int n_user_new); +int mix_free(struct mix *mix_ptr); +struct mix *mix_search(int n_user, int *n, int print); +int mix_sort(void); +struct pe_data *pe_data_alloc(void); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +private: +int pe_data_store(struct pe_data **pe, const char *token); +public: +struct phase *phase_bsearch(const char *ptr, int *j, int print); +private: +CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); +int phase_delete(int i); +struct phase *phase_store(char *name); +public: +struct pp_assemblage *pp_assemblage_alloc(void); +struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); +private: +CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); +public: +int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, + int n_user_new); +private: +int pp_assemblage_copy_to_last(int n, int n_user); +int pp_assemblage_delete(int n_user_old); +int pp_assemblage_duplicate(int n_user_old, int n_user_new); +public: +int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); +private: +int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, + int n_user_end, char *description); +int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, + int n_user_new); +struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage + *pp_assemblage_old_ptr, + int n_user_new); +struct pp_assemblage *pp_assemblage_search(int n_user, int *n); +int pp_assemblage_sort(void); +CLASS_STATIC int pure_phase_compare(const void *ptr1, const void *ptr2); +struct rate *rate_bsearch(char *ptr, int *j); +int rate_free(struct rate *rate_ptr); +struct rate *rate_search(char *name, int *n); +int rate_sort(void); +struct reaction *rxn_alloc(int ntokens); +struct reaction *rxn_dup(struct reaction *rxn_ptr_old); +LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); +int rxn_free(struct reaction *rxn_ptr); +int rxn_print(struct reaction *rxn_ptr); +CLASS_STATIC int s_compare(const void *ptr1, const void *ptr2); +int s_delete(int i); +struct species *s_search(const char *name); +struct species *s_store(char *name, LDBLE z, int replace_if_found); +public: + struct s_s_assemblage *s_s_assemblage_alloc(void); + struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); +private: +CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); +public: + int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, + struct s_s_assemblage *s_s_assemblage_new_ptr, + int n_user_new); +private: +int s_s_assemblage_copy_to_last(int n, int n_user); +int s_s_assemblage_duplicate(int n_user_old, int n_user_new); +int s_s_assemblage_delete(int n_user_old); +public: + int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); +private: +int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, + int n_user, int n_user_end, char *description); +int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage + *s_s_assemblage_old_ptr, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); +int s_s_assemblage_sort(void); +CLASS_STATIC int s_s_compare(const void *ptr1, const void *ptr2); +struct save_values *save_values_bsearch(struct save_values *k, int *n); +CLASS_STATIC int save_values_compare(const void *ptr1, const void *ptr2); +int save_values_sort(void); +int save_values_store(struct save_values *s_v); +CLASS_STATIC int conc_compare(const void *ptr1, const void *ptr2); +int conc_init(struct conc *conc_ptr); +CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); +public: + struct solution *solution_alloc(void); + struct solution *solution_bsearch(int k, int *n, int print); +private: + struct solution *solution_copy(struct solution *solution_old_ptr, + int n_user_new); +int solution_copy_to_last(int n, int n_user_new); +int solution_duplicate(int n_user_old, int n_user_new); +int solution_delete(int n_user_old); +int solution_delete_n(int n); +int solution_free(struct solution *solution_ptr); +int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); +struct solution *solution_replicate(struct solution *solution_old_ptr, + int n_user_new); +int solution_sort(void); +CLASS_STATIC int species_list_compare_alk(const void *ptr1, const void *ptr2); +CLASS_STATIC int species_list_compare_master(const void *ptr1, const void *ptr2); +int species_list_sort(void); +struct Change_Surf *change_surf_alloc(int count); +public: + struct surface *surface_alloc(void); + struct surface *surface_bsearch(int k, int *n); +private: +struct master *surface_get_psi_master(const char *name, int plane); +CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); +CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); +struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); +int surface_charge_free(struct surface_charge *charge); +CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); +public: + int surface_copy(struct surface *surface_old_ptr, + struct surface *surface_new_ptr, int n_user_new); +private: +int surface_copy_to_last(int n, int n_user); +int surface_delete(int n_user_old); +int surface_duplicate(int n_user_old, int n_user_new); +public: + int surface_free(struct surface *surface_ptr); +protected: +int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, + char *description); +int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); +struct surface *surface_replicate(struct surface *surface_old_ptr, + int n_user_new); +struct surface *surface_search(int n_user, int *n, int print); +int surface_sort(void); +int system_duplicate(int i, int save_old); +struct temperature *temperature_bsearch(int k, int *n); +int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new); +int temperature_delete(int n_user_old); +int temperature_duplicate(int n_user_old, int n_user_new); +int temperature_free(struct temperature *temperature_ptr); +struct temperature *temperature_search(int n_user, int *n); +int temperature_sort(void); +int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_combine(void); +int trxn_copy(struct reaction *rxn_ptr); +LDBLE trxn_find_coef(const char *str, int start); +int trxn_print(void); +int trxn_reverse_k(void); +int trxn_sort(void); +int trxn_swap(const char *token); +struct unknown *unknown_alloc(void); +int unknown_delete(int i); +int unknown_free(struct unknown *unknown_ptr); +int entity_exists(char *name, int n_user); + +static int exchange_compare_int(const void *ptr1, const void *ptr2); +static int gas_phase_compare_int(const void *ptr1, const void *ptr2); +static int inverse_compare(const void *ptr1, const void *ptr2); +int inverse_free(struct inverse *inverse_ptr); +static int irrev_compare(const void *ptr1, const void *ptr2); +static int irrev_compare_int(const void *ptr1, const void *ptr2); +static int kinetics_compare_int(const void *ptr1, const void *ptr2); +int logk_init(struct logk *logk_ptr); +static int master_compare_string(const void *ptr1, const void *ptr2); +int master_free(struct master *master_ptr); +static int mix_compare(const void *ptr1, const void *ptr2); +static int mix_compare_int(const void *ptr1, const void *ptr2); +struct phase *phase_alloc(void); +static int phase_compare_string(const void *ptr1, const void *ptr2); +int phase_free(struct phase *phase_ptr); +int phase_init(struct phase *phase_ptr); +static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int rate_compare(const void *ptr1, const void *ptr2); +static int rate_compare_string(const void *ptr1, const void *ptr2); +struct species *s_alloc(void); +int s_free(struct species *s_ptr); +int s_init(struct species *s_ptr); +static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int solution_compare(const void *ptr1, const void *ptr2); +static int solution_compare_int(const void *ptr1, const void *ptr2); +static int species_list_compare(const void *ptr1, const void *ptr2); +static int surface_compare_int(const void *ptr1, const void *ptr2); +static int temperature_compare(const void *ptr1, const void *ptr2); +static int temperature_compare_int(const void *ptr1, const void *ptr2); +static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); +int trxn_multiply(LDBLE coef); +#ifdef PHREEQCI_GUI +extern void free_spread(void); +#endif +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern void MergeFinalize(void); +#endif + +/* tally.c */ + +void add_all_components_tally(void); +int build_tally_table(void); +int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); +int diff_tally_table(void); +int extend_tally_table(void); +int free_tally_table(void); +int fill_tally_table(int *n_user, int index_conservative, int n_buffer); +int get_tally_table_rows_columns(int *rows, int *columns); +int get_tally_table_column_heading(int column, int *type, char *string); +int get_tally_table_row_heading(int column, char *string); +int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); +int zero_tally_table(void); + +int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); +int get_all_components(void); +int print_tally_table(void); +int set_reaction_moles(int n_user, LDBLE moles); +int set_reaction_temperature(int n_user, LDBLE tc); +int set_kinetics_time(int n_user, LDBLE step); + +// tidy.c ------------------------------- + +int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); +int add_logks(struct logk *logk_ptr, int repeats); +LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); +int replace_solids_gases(void); +int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); +int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); +int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: +int tidy_punch(void); +int tidy_model(void); + +int check_species_input(void); +LDBLE coef_in_master(struct master *master_ptr); +int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); +int reset_last_model(void); +int rewrite_eqn_to_primary(void); +int rewrite_eqn_to_secondary(void); +int species_rxn_to_trxn(struct species *s_ptr); +int tidy_logk(void); +int tidy_exchange(void); +int tidy_min_exchange(void); +int tidy_kin_exchange(void); +int tidy_gas_phase(void); +int tidy_inverse(void); +int tidy_isotopes(void); +int tidy_isotope_ratios(void); +int tidy_isotope_alphas(void); +int tidy_kin_surface(void); +int tidy_master_isotope(void); +int tidy_min_surface(void); +int tidy_phases(void); +int tidy_pp_assemblage(void); +int tidy_solutions(void); +int tidy_s_s_assemblage(void); +int tidy_species(void); +int tidy_surface(void); +int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); +static LDBLE f_spinodal(LDBLE x, void *); +int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); +int s_s_calc_a0_a1(struct s_s *s_s_ptr); + +// transport.c ------------------------------- + +int transport(void); +int set_initial_moles(int i); +int sum_surface_comp(struct surface *source1, LDBLE f1, + struct surface *source2, int k, LDBLE f2, + struct surface *target, LDBLE new_Dw); +int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, + LDBLE new_Dw, int cell); +LDBLE viscosity(void); + +int multi_D(LDBLE DDt, int mobile_cell, int stagnant); +int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); +int fill_spec(int cell_no); +int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); +static int sort_species_name(const void *ptr1, const void *ptr2); +int disp_surf(LDBLE stagkin_time); +int diff_stag_surf(int mobile_cell); +int check_surfaces(struct surface *surface_ptr1, + struct surface *surface_ptr2); +int mobile_surface_copy(struct surface *surface_old_ptr, + struct surface *surf_ptr1, int n_user_new, + int move_old); +int init_mix(void); +int init_heat_mix(int nmix); +int heat_mix(int heat_nmix); +int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + +// utilities.c ------------------------------- +public: +int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); +private: +int backspace_screen(int spaces); +LDBLE calc_alk(struct reaction *rxn_ptr); +public: + int compute_gfw(const char *string, LDBLE * gfw); +int copy_token(char *token_ptr, char **ptr, int *length); +int dup_print(const char *ptr, int emphasis); +int equal(LDBLE a, LDBLE b, LDBLE eps); +public: + void *free_check_null(void *ptr); +private: +void free_hash_strings(HashTable * Table); +int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); +int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); +void hdestroy_multi(HashTable * HashTable_ptr); +ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); +int islegit(const char c); +public: +void malloc_error(void); +private: +int parse_couple(char *token); +int print_centered(const char *string); +public: +CLASS_STATIC int replace(const char *str1, const char *str2, char *str); +private: +void space(void **ptr, int i, int *max, int struct_size); +void squeeze_white(char *s_l); +int status(int count, const char *str); +void str_tolower(char *str); +void str_toupper(char *str); +CLASS_STATIC int strcmp_nocase(const char *str1, const char *str2); +int strcmp_nocase_arg1(const char *str1, const char *str2); +public: + char *string_duplicate(const char *token); + char *string_hsave(const char *str); +private: +char *string_pad(char *str, int i); +int string_trim(char *str); +int string_trim_right(char *str); +int string_trim_left(char *str); +CLASS_STATIC LDBLE under(LDBLE xval); +void zero_double(LDBLE * target, int n); + +#ifdef PHREEQ98 +void AddToCEntry(char *a, int l, int i); +void ApplicationProcessMessages(void); +int copy_title(char *token_ptr, char **ptr, int *length); +extern int clean_up_null(void); +#endif +int isamong(char c, const char *s_l); +Address Hash_multi(HashTable * Table, char *Key); +void ExpandTable_multi(HashTable * Table); + +public: // public methods for PHREEQC_CLASS + int main_method(int argc, char *argv[]); + void set_phast(int); + size_t list_components(std::list &list_c); +protected: + void init(void); +}; +#endif /* _INC_PHREEQC_H */ + diff --git a/class_main.cpp b/class_main.cpp index f3748de5..832ff43b 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,206 +1,206 @@ -#include "Phreeqc.h" -#include "output.h" -#include "phrqproto.h" -#include "input.h" -#include "NameDouble.h" -#include "Solution.h" -#include "Reaction.h" -#include "PPassemblage.h" -#include "Exchange.h" -#include "Surface.h" -#include "GasPhase.h" -#include "SSassemblage.h" -#include "cxxKinetics.h" - - -/* ---------------------------------------------------------------------- - * MAIN - * ---------------------------------------------------------------------- */ -int -main(int argc, char *argv[]) -/* - * Main program for PHREEQC - */ -{ - - //int errors; -#if defined(WIN32_MEMORY_DEBUG) - int tmpDbgFlag; - - /* - * Set the debug-heap flag to keep freed blocks in the - * heap's linked list - This will allow us to catch any - * inadvertent use of freed memory - */ - tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; - ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; - _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 9482; -#endif - - /*if (svnid == NULL) - fprintf(stderr, " ");*/ - - - Phreeqc phreeqc_instance; - phreeqc_instance.main_method(argc, argv); - std::list components; - phreeqc_instance.list_components(components); - std::list::iterator it; - std::cout << "Number of components: " << components.size() << std::endl; - for (it = components.begin(); it != components.end(); it++) - { - std::cout << " " << *it << std::endl; - } -} - - -int CLASS_QUALIFIER -main_method(int argc, char *argv[]) -/* - * Main program for PHREEQC - */ -{ - - int errors; - void *db_cookie = NULL; - void *input_cookie = NULL; -#if defined(WIN32_MEMORY_DEBUG) - int tmpDbgFlag; - - /* - * Set the debug-heap flag to keep freed blocks in the - * heap's linked list - This will allow us to catch any - * inadvertent use of freed memory - */ - tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; - ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; - _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 9482; -#endif - - //if (svnid == NULL) - // fprintf(stderr, " "); - phast = FALSE; -/* - * Add callbacks for error_msg and warning_msg - */ - if (add_output_callback(phreeqc_handler, this) != OK) - { - fprintf(stderr, "ERROR: %s\n", - "NULL pointer returned from malloc or realloc."); - fprintf(stderr, "ERROR: %s\n", "Program terminating."); - return -1; - } - -/* - * Open input/output files - */ - errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); - if (errors != 0) - { - //clean_up(); - return errors; - } -#ifdef DOS - write_banner(); -#endif - -/* - * Initialize arrays - */ - errors = do_initialize(); - if (errors != 0) - { - //clean_up(); - return errors; - } -/* - * Load database into memory - */ - errors = read_database(getc_callback, db_cookie); - if (errors != 0) - { - //clean_up(); - return errors; - } - -/* - * Read input data for simulation - */ - errors = run_simulations(getc_callback, input_cookie); - if (errors != 0) - { - //clean_up(); - return errors; - } - - -/* - * Display successful status - */ - errors = do_status(); - if (errors != 0) - { - //clean_up(); - return errors; - } - - - //clean_up(); - //close_input_files(); - //close_output_files(); - - return 0; -} - - -#ifdef DOS -/* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER -write_banner(void) -/* ---------------------------------------------------------------------- */ -{ - char buffer[80]; - int len, indent; - output_msg(OUTPUT_SCREEN, - " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); - output_msg(OUTPUT_SCREEN, - " º º\n"); - - /* version */ - len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); - indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); - - output_msg(OUTPUT_SCREEN, - " º º\n"); - output_msg(OUTPUT_SCREEN, - " º A hydrogeochemical transport model º\n"); - output_msg(OUTPUT_SCREEN, - " º º\n"); - output_msg(OUTPUT_SCREEN, - " º by º\n"); - output_msg(OUTPUT_SCREEN, - " º D.L. Parkhurst and C.A.J. Appelo º\n"); - output_msg(OUTPUT_SCREEN, - " º º\n"); - - - /* date */ - len = sprintf(buffer, "%s", "@VER_DATE@"); - indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); - - output_msg(OUTPUT_SCREEN, - " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); - - return 0; -} -#endif +#include "Phreeqc.h" +#include "output.h" +#include "phrqproto.h" +#include "input.h" +#include "NameDouble.h" +#include "Solution.h" +#include "Reaction.h" +#include "PPassemblage.h" +#include "Exchange.h" +#include "Surface.h" +#include "GasPhase.h" +#include "SSassemblage.h" +#include "cxxKinetics.h" + + +/* ---------------------------------------------------------------------- + * MAIN + * ---------------------------------------------------------------------- */ +int +main(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + + //int errors; +#if defined(WIN32_MEMORY_DEBUG) + int tmpDbgFlag; + + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); + //_crtBreakAlloc = 9482; +#endif + + /*if (svnid == NULL) + fprintf(stderr, " ");*/ + + + Phreeqc phreeqc_instance; + phreeqc_instance.main_method(argc, argv); + std::list components; + phreeqc_instance.list_components(components); + std::list::iterator it; + std::cout << "Number of components: " << components.size() << std::endl; + for (it = components.begin(); it != components.end(); it++) + { + std::cout << " " << *it << std::endl; + } +} + + +int CLASS_QUALIFIER +main_method(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + + int errors; + void *db_cookie = NULL; + void *input_cookie = NULL; +#if defined(WIN32_MEMORY_DEBUG) + int tmpDbgFlag; + + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); + //_crtBreakAlloc = 9482; +#endif + + //if (svnid == NULL) + // fprintf(stderr, " "); + phast = FALSE; +/* + * Add callbacks for error_msg and warning_msg + */ + if (add_output_callback(phreeqc_handler, this) != OK) + { + fprintf(stderr, "ERROR: %s\n", + "NULL pointer returned from malloc or realloc."); + fprintf(stderr, "ERROR: %s\n", "Program terminating."); + return -1; + } + +/* + * Open input/output files + */ + errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); + if (errors != 0) + { + //clean_up(); + return errors; + } +#ifdef DOS + write_banner(); +#endif + +/* + * Initialize arrays + */ + errors = do_initialize(); + if (errors != 0) + { + //clean_up(); + return errors; + } +/* + * Load database into memory + */ + errors = read_database(getc_callback, db_cookie); + if (errors != 0) + { + //clean_up(); + return errors; + } + +/* + * Read input data for simulation + */ + errors = run_simulations(getc_callback, input_cookie); + if (errors != 0) + { + //clean_up(); + return errors; + } + + +/* + * Display successful status + */ + errors = do_status(); + if (errors != 0) + { + //clean_up(); + return errors; + } + + + //clean_up(); + //close_input_files(); + //close_output_files(); + + return 0; +} + + +#ifdef DOS +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER +write_banner(void) +/* ---------------------------------------------------------------------- */ +{ + char buffer[80]; + int len, indent; + output_msg(OUTPUT_SCREEN, + " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + + /* version */ + len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, + " º º\n"); + output_msg(OUTPUT_SCREEN, + " º A hydrogeochemical transport model º\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + output_msg(OUTPUT_SCREEN, + " º by º\n"); + output_msg(OUTPUT_SCREEN, + " º D.L. Parkhurst and C.A.J. Appelo º\n"); + output_msg(OUTPUT_SCREEN, + " º º\n"); + + + /* date */ + len = sprintf(buffer, "%s", "@VER_DATE@"); + indent = (44 - len) / 2; + output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' '); + + output_msg(OUTPUT_SCREEN, + " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); + + return 0; +} +#endif From e3888e1f0cd50170e5cd02b91954276ada8c4c9b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 22 Apr 2010 22:13:47 +0000 Subject: [PATCH 0147/1077] added newline at end of files git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4296 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- cxxKinetics.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c5eb4098..75a0c39e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -981,4 +981,4 @@ void Phreeqc::init(void) print_density = 0; return; -} \ No newline at end of file +} diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 510e2e5f..1b552149 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -740,4 +740,4 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) //cxxNameDouble & cxxKinetics::get_totals(void) //{ // return this->totals; -//} \ No newline at end of file +//} From cba7d11b4c76302dfcfba460387b6613cea9eebf Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 23 Apr 2010 10:42:07 +0000 Subject: [PATCH 0148/1077] modified Makefile.am's to handle each src dir independently git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4299 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Makefile.am diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..be1ec626 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,83 @@ +#AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp -I$(top_srcdir)/src/phreeqcpp/phreeqc +AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp/phreeqc + +SUBDIRS=phreeqc + +noinst_LTLIBRARIES=libphreeqcpp.la + +##{{ +##libphreeqcpp_la_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp/phreeqc +##libphreeqcpp_la_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp -I$(top_srcdir)/src/phreeqcpp/phreeqc +##}} + +# library sources +libphreeqcpp_la_SOURCES=\ + char_star.h\ + cxxKinetics.cxx\ + cxxKinetics.h\ + cxxMix.cxx\ + cxxMix.h\ + Dictionary.h\ + dumper.cpp\ + dumper.h\ + Exchange.cxx\ + Exchange.h\ + ExchComp.cxx\ + ExchComp.h\ + GasPhase.cxx\ + GasPhase.h\ + ISolution.cxx\ + ISolution.h\ + ISolutionComp.cxx\ + ISolutionComp.h\ + KineticsComp.cxx\ + KineticsComp.h\ + NameDouble.cxx\ + NameDouble.h\ + NumKeyword.cxx\ + NumKeyword.h\ + Parser.cxx\ + Parser.h\ + Phreeqc.cpp\ + Phreeqc.h\ + Phreeqc_class.h\ + PPassemblage.cxx\ + PPassemblage.h\ + PPassemblageComp.cxx\ + PPassemblageComp.h\ + Reaction.cxx\ + Reaction.h\ + ReadClass.cxx\ + runner.cpp\ + runner.h\ + SAXPhreeqc.h\ + SaxPhreeqcHandlers.h\ + Solution.cxx\ + Solution.h\ + SolutionIsotope.cxx\ + SolutionIsotope.h\ + SolutionIsotopeList.cxx\ + SolutionIsotopeList.h\ + SSassemblage.cxx\ + SSassemblage.h\ + SSassemblageSS.cxx\ + SSassemblageSS.h\ + StorageBin.cxx\ + StorageBin.h\ + StorageBinList.cpp\ + StorageBinList.h\ + Surface.cxx\ + Surface.h\ + SurfaceCharge.cxx\ + SurfaceCharge.h\ + SurfaceComp.cxx\ + SurfaceComp.h\ + System.cxx\ + System.h\ + Temperature.cxx\ + Temperature.h\ + Utils.cxx\ + Utils.h + +##COMPILE = $(CXXCOMPILE) +##LTCOMPILE = $(LTCXXCOMPILE) From 4940d97f422d8e36dd851b6709ea6971ff38f00d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 27 Apr 2010 22:26:25 +0000 Subject: [PATCH 0149/1077] combined src/Makefile.am src/phreeqcpp/Makefile.am src/phreecpp/phreeqc/Makefile.am into one file git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4318 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 83 ----------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 Makefile.am diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index be1ec626..00000000 --- a/Makefile.am +++ /dev/null @@ -1,83 +0,0 @@ -#AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp -I$(top_srcdir)/src/phreeqcpp/phreeqc -AM_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp/phreeqc - -SUBDIRS=phreeqc - -noinst_LTLIBRARIES=libphreeqcpp.la - -##{{ -##libphreeqcpp_la_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp/phreeqc -##libphreeqcpp_la_CPPFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqcpp -I$(top_srcdir)/src/phreeqcpp/phreeqc -##}} - -# library sources -libphreeqcpp_la_SOURCES=\ - char_star.h\ - cxxKinetics.cxx\ - cxxKinetics.h\ - cxxMix.cxx\ - cxxMix.h\ - Dictionary.h\ - dumper.cpp\ - dumper.h\ - Exchange.cxx\ - Exchange.h\ - ExchComp.cxx\ - ExchComp.h\ - GasPhase.cxx\ - GasPhase.h\ - ISolution.cxx\ - ISolution.h\ - ISolutionComp.cxx\ - ISolutionComp.h\ - KineticsComp.cxx\ - KineticsComp.h\ - NameDouble.cxx\ - NameDouble.h\ - NumKeyword.cxx\ - NumKeyword.h\ - Parser.cxx\ - Parser.h\ - Phreeqc.cpp\ - Phreeqc.h\ - Phreeqc_class.h\ - PPassemblage.cxx\ - PPassemblage.h\ - PPassemblageComp.cxx\ - PPassemblageComp.h\ - Reaction.cxx\ - Reaction.h\ - ReadClass.cxx\ - runner.cpp\ - runner.h\ - SAXPhreeqc.h\ - SaxPhreeqcHandlers.h\ - Solution.cxx\ - Solution.h\ - SolutionIsotope.cxx\ - SolutionIsotope.h\ - SolutionIsotopeList.cxx\ - SolutionIsotopeList.h\ - SSassemblage.cxx\ - SSassemblage.h\ - SSassemblageSS.cxx\ - SSassemblageSS.h\ - StorageBin.cxx\ - StorageBin.h\ - StorageBinList.cpp\ - StorageBinList.h\ - Surface.cxx\ - Surface.h\ - SurfaceCharge.cxx\ - SurfaceCharge.h\ - SurfaceComp.cxx\ - SurfaceComp.h\ - System.cxx\ - System.h\ - Temperature.cxx\ - Temperature.h\ - Utils.cxx\ - Utils.h - -##COMPILE = $(CXXCOMPILE) -##LTCOMPILE = $(LTCXXCOMPILE) From 09bf8787f8d1ca75f4c3b48215274823ca7911fb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 11 May 2010 22:48:52 +0000 Subject: [PATCH 0150/1077] deleted unused variables sit_remove_unstable_phases and pitzer_remove_unstable_phases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4380 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index d3017bb2..480ab9c2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -634,7 +634,6 @@ int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, int BDK(LDBLE X); int pitzer_initial_guesses(void); int pitzer_revise_guesses(void); -int pitzer_remove_unstable_phases; int PTEMP(LDBLE TK); LDBLE JAY(LDBLE X); LDBLE JPRIME(LDBLE Y); @@ -903,7 +902,6 @@ int sit_ISPEC(char *name); /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ int sit_initial_guesses(void); int sit_revise_guesses(void); -int sit_remove_unstable_phases; int PTEMP_SIT(LDBLE tk); int jacobian_sit(void); From e1b52e15f2711a0b0fdcfe456fffa13733e05d87 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 12 May 2010 23:40:05 +0000 Subject: [PATCH 0151/1077] reworking output_message prototype git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4386 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 480ab9c2..6bb1965a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -520,8 +520,10 @@ void ineq_init(int max_row_count, int max_column_count); // output.c ------------------------------- +#if 0 int output_message(const int type, const char *err_str, const int stop, const char *format, va_list args); +#endif // parse.c ------------------------------- From 5b8e7fdfbd30096dc2e50077616d2bfa422b93f2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 13 May 2010 00:19:31 +0000 Subject: [PATCH 0152/1077] added output_message prototype to output.h removed prototype from phreeqcpp/Phreeqc.h and phreeqcpp/phreeqc/print.c git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4388 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 6bb1965a..5ab0327b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -520,11 +520,6 @@ void ineq_init(int max_row_count, int max_column_count); // output.c ------------------------------- -#if 0 -int output_message(const int type, const char *err_str, const int stop, - const char *format, va_list args); -#endif - // parse.c ------------------------------- int check_eqn(int association); From 0b4092e13ba77a68f5350d8009ad6b1d2be7fe47 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 17 Jun 2010 20:17:08 +0000 Subject: [PATCH 0153/1077] Still need to work on Form1 to pass a phreeqc instance. Removed Void definition in p2c, and changed all references to just void. Moved all structures, globals, and prototypes to global_structures.h, global.h, and Phreeqc.h. Initialized chart variables in Phreeqc.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4552 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Phreeqc.h | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 75a0c39e..f633f546 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -311,6 +311,59 @@ Phreeqc::Phreeqc(void) command[i].keycount = command_temp[i].keycount; } +// chart.cpp ------------------------------- +#ifdef CHART + update_time_chart = 150; /* milliseconds, maybe read */ + PanelHeight = 510; + PanelWidth = 640; + + axis_titles[0] = string_duplicate("X-axis"); + axis_titles[1] = string_duplicate("Y-axis"); + axis_titles[2] = string_duplicate("Y2-axis"); + + /* min, max, major tic, minor tic, log */ + for (i = 0; i < 5; i++) + { + axis_scale_x[i] = NA; + axis_scale_y[i] = NA; + axis_scale_y2[i] = NA; + } + + chart_title = string_duplicate(""); + + chart_type = 0; /* default: plot vs distance. If chart_type = 1, plot vs time */ + graph_initial_solutions = 0; /* false */ + connect_simulations = 1; /* same curve properties in new simulations */ + rownr = -1; + colnr = 0; /* row and col no defined in basic.c for GridChar and Plot_XY */ + RowOffset = 0; /* = 1 if new simulations should add points to the same curve */ + ColumnOffset = 0; /* sets column offset, from CSV plot, and from new USER_GRAPH */ + prev_advection_step = 0; + prev_transport_step = 0; /* not used in chart, for compatibility with PfW */ + AddSeries = 1; /* new curve properties in new simulation (does the same, but opposite of connect_simulation) */ + + end_timer = false; /* in mainsubs.c, stops the update timer in form1.h */ + + for (i = 0; i < 3; i++) + { + ncurves_changed[i] = 0; /* for updating the chart: */ + } /* 0 or 1 (if curves have changed), previous no, new no of curves with points*/ + + char *SymbolList_init[11] = {"Square", "Diamond", "Triangle", "Circle", "XCross", "Plus", "Star", + "TriangleDown", "HDash", "VDash", "None"}; + for (i = 1; i < 11; i++) + { + SymbolList[i] = string_duplicate(SymbolList_init[i]); + } + /*ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; // defined in Form1.h as cli */ + /* or any color from System::Drawing::Color */ + + nCSV_headers = 0; /* no of CSV curves, also defines ColumnOffset if connect_simulations = 1 */ + FirstCallToUSER_GRAPH = 1; + new_ug = false; /* in case USER_GRAPH is redefined */ + u_g = false; +#endif // CHART + //cl1.c x_arg = NULL, res_arg = NULL, scratch = NULL; x_arg_max = 0, res_arg_max = 0, scratch_max = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 5ab0327b..88c59306 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -96,6 +96,7 @@ public: //struct tokenrec; //struct varrec; //struct unknown; +//struct Curves_c; #define PITZER_EXTERNAL #include "pitzer.h" @@ -181,11 +182,14 @@ void cmddel(struct LOC_exec *LINK); void cmdrenum(struct LOC_exec *LINK); void cmdprint(struct LOC_exec *LINK); void cmdpunch(struct LOC_exec *LINK); -#ifdef PHREEQ98 +#if defined PHREEQ98 || defined CHART void cmdgraph_x(struct LOC_exec *LINK); void cmdgraph_y(struct LOC_exec *LINK); void cmdgraph_sy(struct LOC_exec *LINK); #endif +#ifdef CHART +void cmdplot_xy(struct LOC_exec *LINK); +#endif void cmdlet(boolean implied, struct LOC_exec *LINK); void cmdgoto(struct LOC_exec *LINK); void cmdif(struct LOC_exec *LINK); @@ -262,6 +266,21 @@ int system_total_solids(struct exchange *exchange_ptr, static LDBLE f_rho(LDBLE rho_old, void *cookie); +// chart.cpp +#if defined PHREEQ98 || defined CHART +void DeleteCurves(void); +void ExtractCurveInfo(char *line, int curvenr); +void GridChar(char *s, char *a); +void MallocCurves(int nc, int ncxy); +int OpenCSVFile(char file_name[MAX_LENGTH]); +void PlotXY(char *x, char *y); +void ReallocCurves(int new_nc); +void ReallocCurveXY(int i); +void SetAxisScale(char *a, int j, char *token, int true_); +void SetAxisTitles(char *s, int i); +void SetChartTitle(char *s); +void start_chart(bool end); +#endif // cl1.c ------------------------------- int cl1(int k, int l, int m, int n, int nklmd, int n2d, @@ -279,6 +298,8 @@ int cl1mp(int k, int l, int m, int n, int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + + // class_main.c ------------------------------- #ifdef DOS int write_banner(void); @@ -564,7 +585,7 @@ int output_handler(const int type, const char *err_str, const int stop, void *cookie, const char *format, va_list args); static int rewind_wrapper(FILE * file_ptr); -Void PASCAL_MAIN(int argc, Char **argv); +void PASCAL_MAIN(int argc, Char **argv); long my_labs(long x); Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); @@ -585,8 +606,8 @@ void strinsert(register char *src, register char *dst, register int pos); int P_peek(FILE * f); int P_eof(void); int P_eoln(FILE * f); -Void P_readpaoc(FILE * f, char *s, int len); -Void P_readlnpaoc(FILE * f, char *s, int len); +void P_readpaoc(FILE * f, char *s, int len); +void P_readlnpaoc(FILE * f, char *s, int len); long P_maxpos(FILE * f); Char * P_trimname(register Char * fn, register int len); long memavail(void); @@ -751,7 +772,7 @@ int punch_s_s_assemblage(void); int punch_saturation_indices(void); int punch_totals(void); int punch_user_punch(void); -#ifdef PHREEQ98 +#if defined PHREEQ98 || defined CHART int punch_user_graph(void); #endif @@ -825,14 +846,8 @@ int read_use(void); int read_title(void); int read_user_print(void); int read_user_punch(void); -#ifdef PHREEQ98 +#if defined PHREEQ98 || defined CHART int read_user_graph(void); -int copy_title(char *token_ptr, char **ptr, int *length); -int OpenCSVFile(char file_name[MAX_LENGTH]); -void GridHeadings(char *s, int i); -void SetAxisTitles(char *s, int i); -void SetAxisScale(char *a, int c, char *v, int l); -void SetChartTitle(char *s); #endif int next_keyword_or_option(const char **opt_list, int count_opt_list); @@ -1366,6 +1381,9 @@ int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: int compute_gfw(const char *string, LDBLE * gfw); + #if defined PHREEQ98 || defined CHART + int copy_title(char *token_ptr, char **ptr, int *length); + #endif int copy_token(char *token_ptr, char **ptr, int *length); int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); From 31eafb92e76fc469e60f4863617c8df0c806ef4b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 18 Jun 2010 00:04:28 +0000 Subject: [PATCH 0154/1077] Sortof works on class clr version, but need to be able to detect when chart thread ends. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4553 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 36 ++++++++++++++++++++++++++++++------ class_main.cpp | 22 ++++++++++++++-------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index f633f546..8eb122b8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -177,6 +177,21 @@ Phreeqc::Phreeqc(void) // basic.c struct const_key command_temp[] = { + {"+", tokplus}, + {"-", tokminus}, + {"*", toktimes}, + {"/", tokdiv}, + {"^", tokup}, + {"( or [", toklp}, + {") or ]", tokrp}, + {",", tokcomma}, + {";", toksemi}, + {":", tokcolon}, + {"=", tokeq}, + {"<", toklt}, + {"<=", tokle}, + {">", tokgt}, + {">=", tokge}, {"and", tokand}, {"or", tokor}, {"xor", tokxor}, @@ -202,11 +217,14 @@ Phreeqc::Phreeqc(void) {"let", toklet}, {"print", tokprint}, {"punch", tokpunch}, -#ifdef PHREEQ98 + #if defined PHREEQ98 || defined CHART {"graph_x", tokgraph_x}, {"graph_y", tokgraph_y}, {"graph_sy", tokgraph_sy}, -#endif + #endif + #ifdef CHART + {"plot_xy", tokplot_xy}, + #endif {"input", tokinput}, {"goto", tokgoto}, {"go to", tokgoto}, @@ -298,11 +316,17 @@ Phreeqc::Phreeqc(void) {"porevolume", tokporevolume}, {"sc", toksc}, {"gamma", tokgamma}, - /* VP: Density Start */ + /* VP: Density Start */ {"lg", toklg}, - {"rho", tokrho} - /* VP: Density End */ - }; + {"rho", tokrho}, + /* VP: Density End */ + {"cell_volume", tokcell_volume}, + {"cell_pore_volume", tokcell_pore_volume}, + {"cell_porosity", tokcell_porosity}, + {"cell_saturation", tokcell_saturation}, + {"totmole", toktotmole}, + {"iso", tokiso}, + {"iso_unit", tokiso_unit} }; NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); command = new const_key[NCMDS]; for (i = 0; i < NCMDS; i++) diff --git a/class_main.cpp b/class_main.cpp index 832ff43b..f8b18a3b 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -44,16 +44,22 @@ main(int argc, char *argv[]) fprintf(stderr, " ");*/ - Phreeqc phreeqc_instance; - phreeqc_instance.main_method(argc, argv); - std::list components; - phreeqc_instance.list_components(components); - std::list::iterator it; - std::cout << "Number of components: " << components.size() << std::endl; - for (it = components.begin(); it != components.end(); it++) + Phreeqc *phreeqc_instance = new Phreeqc; + phreeqc_instance->main_method(argc, argv); + if (phreeqc_instance->u_g) { - std::cout << " " << *it << std::endl; + double a; + //phreeqc_instance->start_chart(true); } + //std::list components; + //phreeqc_instance.list_components(components); + //std::list::iterator it; + //std::cout << "Number of components: " << components.size() << std::endl; + //for (it = components.begin(); it != components.end(); it++) + //{ + // std::cout << " " << *it << std::endl; + //} + delete phreeqc_instance; } From 24f5a295a7cc54de9ecb58d1ebfbbfb8220a28c0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 18 Jun 2010 02:19:00 +0000 Subject: [PATCH 0155/1077] Added code to allow phreeqc_instance to stay in scope until the thread count drops to 8. Don't know if this will always work. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4555 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index f8b18a3b..20c538aa 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -44,13 +44,21 @@ main(int argc, char *argv[]) fprintf(stderr, " ");*/ - Phreeqc *phreeqc_instance = new Phreeqc; - phreeqc_instance->main_method(argc, argv); - if (phreeqc_instance->u_g) + Phreeqc phreeqc_instance; + phreeqc_instance.main_method(argc, argv); +#ifdef CHART + if (phreeqc_instance.u_g) { - double a; - //phreeqc_instance->start_chart(true); + System::Diagnostics::Process^ currentProcess = System::Diagnostics::Process::GetCurrentProcess(); + //System::Console::WriteLine(currentProcess->Threads->Count); + while (currentProcess->Threads->Count > 8) + { + currentProcess->Refresh(); + //System::Console::WriteLine(currentProcess->Threads->Count); + System::Threading::Thread::CurrentThread->Sleep(100); + } } +#endif //std::list components; //phreeqc_instance.list_components(components); //std::list::iterator it; @@ -59,7 +67,6 @@ main(int argc, char *argv[]) //{ // std::cout << " " << *it << std::endl; //} - delete phreeqc_instance; } From 98e6f469b740679142abd792c0ae722bf4019fad Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 18 Jun 2010 21:19:44 +0000 Subject: [PATCH 0156/1077] Modified class version to detect end of USER_GRAPH thread. Seems to work. Scott's way failed the first couple times I ran it, but don't really know why. ran fiona with all configurations (run without debugging). git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4559 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + class_main.cpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 8eb122b8..3629881a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -386,6 +386,7 @@ Phreeqc::Phreeqc(void) FirstCallToUSER_GRAPH = 1; new_ug = false; /* in case USER_GRAPH is redefined */ u_g = false; + u_g_active = false; #endif // CHART //cl1.c diff --git a/class_main.cpp b/class_main.cpp index 20c538aa..55c4c7ba 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -46,7 +46,7 @@ main(int argc, char *argv[]) Phreeqc phreeqc_instance; phreeqc_instance.main_method(argc, argv); -#ifdef CHART +#ifdef CHARTxxx if (phreeqc_instance.u_g) { System::Diagnostics::Process^ currentProcess = System::Diagnostics::Process::GetCurrentProcess(); @@ -59,14 +59,12 @@ main(int argc, char *argv[]) } } #endif - //std::list components; - //phreeqc_instance.list_components(components); - //std::list::iterator it; - //std::cout << "Number of components: " << components.size() << std::endl; - //for (it = components.begin(); it != components.end(); it++) - //{ - // std::cout << " " << *it << std::endl; - //} +#ifdef CHART + while (phreeqc_instance.u_g_active) + { + Sleep(100); + } +#endif } From 1e9f6e5760e08a7e64c7fa3091aefe9574544741 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Jun 2010 00:39:34 +0000 Subject: [PATCH 0157/1077] Fixed up charting changes for class version. Left SKIPped 2 digit exponents in mainsubs.c. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4595 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 88c59306..f3d7abcb 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -273,6 +273,7 @@ void ExtractCurveInfo(char *line, int curvenr); void GridChar(char *s, char *a); void MallocCurves(int nc, int ncxy); int OpenCSVFile(char file_name[MAX_LENGTH]); +void SaveCurvesToFile(char file_name[MAX_LENGTH]); void PlotXY(char *x, char *y); void ReallocCurves(int new_nc); void ReallocCurveXY(int i); From bf1e9bfff68bbde487f429c8a723b7a8b6b8c9c4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 15 Jul 2010 21:53:09 +0000 Subject: [PATCH 0158/1077] fixed hiding variables git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4640 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.h | 36 ++++++++++++++++++------------------ Surface.cxx | 4 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Solution.h b/Solution.h index 6b0be43f..2d11efe4 100644 --- a/Solution.h +++ b/Solution.h @@ -29,9 +29,9 @@ class cxxSolution:public cxxNumKeyword { return this->tc; } - void set_tc(double tc) + void set_tc(double tc1) { - this->tc = tc; + this->tc = tc1; } double get_ph() const @@ -47,72 +47,72 @@ class cxxSolution:public cxxNumKeyword { return this->pe; } - void set_pe(double pe) + void set_pe(double pe1) { - this->pe = pe; + this->pe = pe1; } double get_mu() const { return this->mu; } - void set_mu(double mu) + void set_mu(double mu1) { - this->mu = mu; + this->mu = mu1; } double get_ah2o() const { return this->ah2o; } - void set_ah2o(double ah2o) + void set_ah2o(double ah2o1) { - this->ah2o = ah2o; + this->ah2o = ah2o1; } double get_total_h() const { return this->total_h; } - void set_total_h(double total_h) + void set_total_h(double total_h1) { - this->total_h = total_h; + this->total_h = total_h1; } double get_total_o() const { return this->total_o; } - void set_total_o(double total_o) + void set_total_o(double total_o1) { - this->total_o = total_o; + this->total_o = total_o1; } double get_cb() const { return this->cb; } - void set_cb(double cb) + void set_cb(double cb1) { - this->cb = cb; + this->cb = cb1; } double get_mass_water() const { return this->mass_water; } - void set_mass_water(long double mass_water) + void set_mass_water(long double mass_water1) { - this->mass_water = mass_water; + this->mass_water = mass_water1; } double get_total_alkalinity() const { return this->total_alkalinity; } - void set_total_alkalinity(double total_alkalinity) + void set_total_alkalinity(double total_alkalinity1) { - this->total_alkalinity = total_alkalinity; + this->total_alkalinity = total_alkalinity1; } double get_total(char *string) const; diff --git a/Surface.cxx b/Surface.cxx index 8a114144..8cc22d31 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -83,10 +83,10 @@ cxxNumKeyword() } } cxxSurface::cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entities, - cxxMix & mix, int n_user): + cxxMix & mix, int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; type = DDL; dl_type = NO_DL; sites_units = SITES_ABSOLUTE; From ba762e6dde95ce2e0301aec8f63a775640795a44 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 15 Jul 2010 23:11:54 +0000 Subject: [PATCH 0159/1077] fixed hiding variables git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4641 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ISolutionComp.h b/ISolutionComp.h index c6f63ed5..58c528bb 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -38,28 +38,28 @@ class cxxISolutionComp { return this->moles; } - void set_moles(double moles) + void set_moles(double moles1) { - this->moles = moles; + this->moles = moles1; } double get_input_conc() const { return this->input_conc; } - void set_input_conc(double input_conc) + void set_input_conc(double input_conc1) { - this->input_conc = input_conc; + this->input_conc = input_conc1; } std::string get_units()const { return this->units; } - void set_units(char *units) + void set_units(char *units1) { - if (units != NULL) - this->units = std::string(units); + if (units1 != NULL) + this->units = std::string(units1); else this->units.clear(); } @@ -68,10 +68,10 @@ class cxxISolutionComp { return this->equation_name; } - void set_equation_name(char *equation_name) + void set_equation_name(char *equation_name1) { - if (equation_name != NULL) - this->equation_name = std::string(equation_name); + if (equation_name1 != NULL) + this->equation_name = std::string(equation_name1); else this->equation_name.clear(); @@ -81,28 +81,28 @@ class cxxISolutionComp { return this->phase_si; } - void set_phase_si(int phase_si) + void set_phase_si(int phase_si1) { - this->phase_si = phase_si; + this->phase_si = phase_si1; } int get_n_pe() const { return this->n_pe; } - void set_n_pe(int n_pe) + void set_n_pe(int n_pe1) { - this->n_pe = n_pe; + this->n_pe = n_pe1; } const std::string &get_as() const { return this->as; } - void set_as(char *as) + void set_as(char *as1) { - if (as != NULL) - this->as = std::string(as); + if (as1 != NULL) + this->as = std::string(as1); else this->as.clear(); } @@ -112,9 +112,9 @@ class cxxISolutionComp { return this->gfw; }; - void set_gfw(double gfw) + void set_gfw(double gfw1) { - this->gfw = gfw; + this->gfw = gfw1; } void set_gfw(PHREEQC_PTR_ARG); From 778c7b05bc8682f61d41560a37876ed86de999b1 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 15 Jul 2010 23:27:37 +0000 Subject: [PATCH 0160/1077] changed p_instance to p_instance1 hiding variables git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4642 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc_class.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Phreeqc_class.h b/Phreeqc_class.h index b5d95d0f..779c673a 100644 --- a/Phreeqc_class.h +++ b/Phreeqc_class.h @@ -10,11 +10,11 @@ #define PHREEQC_THIS_COMMA #define PHREEQC_NAME_SPACE :: #else -#define P_INSTANCE p_instance -#define P_INSTANCE_COMMA p_instance, -#define P_INSTANCE_POINTER p_instance-> -#define PHREEQC_PTR_ARG Phreeqc *p_instance -#define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance, +#define P_INSTANCE p_instance1 +#define P_INSTANCE_COMMA p_instance1, +#define P_INSTANCE_POINTER p_instance1-> +#define PHREEQC_PTR_ARG Phreeqc *p_instance1 +#define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance1, #define PHREEQC_THIS this #define PHREEQC_THIS_COMMA this, #define PHREEQC_NAME_SPACE Phreeqc:: From 261bc0113ac08f347b07040a75faa46bd4cc3464 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 16 Jul 2010 01:04:30 +0000 Subject: [PATCH 0161/1077] fixed p_instance bug for raw and ppdump git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4650 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index c3e792df..2733f65b 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -33,7 +33,7 @@ m_next_keyword(KT_NONE) echo_stream = EO_NONE; accumulate = false; #if defined(PHREEQC_CLASS) - this->p_instance = p_instance; + this->p_instance = p_instance1; #endif } @@ -47,7 +47,7 @@ m_next_keyword(KT_NONE) echo_stream = EO_NONE; accumulate = false; #if defined(PHREEQC_CLASS) - this->p_instance = p_instance; + this->p_instance = p_instance1; #endif } @@ -61,7 +61,7 @@ m_next_keyword(KT_NONE) echo_stream = EO_NONE; accumulate = false; #if defined(PHREEQC_CLASS) - this->p_instance = p_instance; + this->p_instance = p_instance1; #endif } From 579a2837478ec4084d81a1793b09a06bab71f52b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 16 Jul 2010 20:45:26 +0000 Subject: [PATCH 0162/1077] Fixing hidden variables in M src/cxxKinetics.cxx M src/NameDouble.cxx M src/Exchange.cxx M src/ISolution.cxx M src/ISolutionComp.cxx M src/ISolutionComp.h M src/SSassemblage.cxx M src/Solution.cxx M src/GasPhase.cxx M src/PPassemblage.cxx M src/ISolution.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4654 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 10 +++++----- GasPhase.cxx | 4 ++-- ISolution.cxx | 10 +++++----- ISolution.h | 14 +++++++------- ISolutionComp.cxx | 8 ++++---- ISolutionComp.h | 6 +++--- NameDouble.cxx | 4 ++-- PPassemblage.cxx | 4 ++-- SSassemblage.cxx | 4 ++-- Solution.cxx | 10 +++++----- cxxKinetics.cxx | 4 ++-- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index c23a4f9f..75b6a68b 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -59,10 +59,10 @@ cxxNumKeyword() } cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, - cxxMix & mix, int n_user): + cxxMix & mix, int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; this->pitzer_exchange_gammas = false; // // Mix exchangers @@ -92,7 +92,7 @@ cxxNumKeyword() } } -cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user) +cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user1) // // constructor for cxxExchange from reaction calculation // equivalent of xexchange_save @@ -105,8 +105,8 @@ cxxNumKeyword() int i; //this->set_description(exchange_ptr->description); - this->n_user = n_user; - this->n_user_end = n_user; + this->n_user = n_user1; + this->n_user_end = n_user1; this->pitzer_exchange_gammas = (P_INSTANCE_POINTER use.exchange_ptr->pitzer_exchange_gammas == TRUE); this->totals.type = cxxNameDouble::ND_ELT_MOLES; diff --git a/GasPhase.cxx b/GasPhase.cxx index cfba99be..957514d7 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -70,10 +70,10 @@ cxxNumKeyword() } } cxxGasPhase::cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entities, - cxxMix & mix, int n_user): + cxxMix & mix, int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; total_p = 0; volume = 0; diff --git a/ISolution.cxx b/ISolution.cxx index afcab7be..beaebde1 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -155,23 +155,23 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) /* * Convert /kgs to /kgw */ - double mass_water; + double mass_water1; if ((this->units.find("kgs") != std::string::npos) || (this->units.find("/l") != std::string::npos)) { - mass_water = 1.0 - 1e-3 * sum_solutes; + mass_water1 = 1.0 - 1e-3 * sum_solutes; for (; iter != this->comps.end(); ++iter) { - iter->second.set_moles(iter->second.get_moles() / mass_water); + iter->second.set_moles(iter->second.get_moles() / mass_water1); } } /* * Scale by mass of water in solution */ - mass_water = this->mass_water; + mass_water1 = this->mass_water; for (; iter != this->comps.end(); ++iter) { - iter->second.set_moles(iter->second.get_moles() * mass_water); + iter->second.set_moles(iter->second.get_moles() * mass_water1); } } diff --git a/ISolution.h b/ISolution.h index 417708b0..0eab5d38 100644 --- a/ISolution.h +++ b/ISolution.h @@ -34,23 +34,23 @@ class cxxISolution:public cxxSolution { return this->density; } - void set_density(double density) + void set_density(double density1) { - this->density = density; + this->density = density1; } std::string get_units() const { return units; } - void set_units(std::string units) + void set_units(std::string units1) { - units = units; + units = units1; } - void set_units(char * units) + void set_units(char * units1) { - if (units != NULL) - this->units = std::string(units); + if (units1 != NULL) + this->units = std::string(units1); else this->units.clear(); } diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 7d66be83..0e55f5e5 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -118,8 +118,8 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) if (this->as.size() != 0) { /* use given chemical formula to calculate gfw */ - double gfw; - if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &gfw) == ERROR) + double gfw1; + if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &gfw1) == ERROR) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; @@ -131,9 +131,9 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) if (strcmp(this->description.c_str(), "Alkalinity") == 0 && strcmp(this->as.c_str(), "CaCO3")) { - gfw /= 2.; + gfw1 /= 2.; } - this->gfw = gfw; + this->gfw = gfw1; return; } /* use gfw of master species */ diff --git a/ISolutionComp.h b/ISolutionComp.h index 58c528bb..e6ed7e3f 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -26,10 +26,10 @@ class cxxISolutionComp { return this->description; } - void set_description(char *description) + void set_description(char *description1) { - if (description != NULL) - this->description = std::string(description); + if (description1 != NULL) + this->description = std::string(description1); else this->description.clear(); } diff --git a/NameDouble.cxx b/NameDouble.cxx index 2c16de98..e4d75f2c 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -100,7 +100,7 @@ cxxNameDouble::cxxNameDouble(struct conc *tots) this->type = ND_ELT_MOLES; } cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, - cxxNameDouble::ND_TYPE type) + cxxNameDouble::ND_TYPE type1) // // constructor for cxxNameDouble from list of elt_list // @@ -112,7 +112,7 @@ cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, continue; (*this)[ma[i].description] = ma[i].la; } - this->type = type; + this->type = type1; } /* cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 08f77070..8e0a118d 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -55,10 +55,10 @@ eltList(pp_assemblage_ptr->next_elt) } cxxPPassemblage::cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, - int n_user): + int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; eltList.type = cxxNameDouble::ND_ELT_MOLES; // // Mix diff --git a/SSassemblage.cxx b/SSassemblage.cxx index ea64ba22..f7c7b210 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -53,10 +53,10 @@ cxxNumKeyword() } cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxSSassemblage > &entities, cxxMix & mix, - int n_user): + int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; //std::list ssAssemblageSSs; // // Mix diff --git a/Solution.cxx b/Solution.cxx index f5a15ba5..f7f9466e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -96,7 +96,7 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solutions, - cxxMix & mix, int n_user) + cxxMix & mix, int n_user1) // // constructor for cxxSolution from mixture of solutions // @@ -108,7 +108,7 @@ cxxNumKeyword() // Zero out solution data // this->zero(); - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; // // Mix solutions // @@ -133,7 +133,7 @@ cxxNumKeyword() } } -cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user) +cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user1) // // constructor for cxxSolution from results of calculation // does not work in phast because phast uses only the total molalities @@ -143,8 +143,8 @@ cxxNumKeyword() { //this->set_description none; - this->n_user = n_user; - this->n_user_end = n_user; + this->n_user = n_user1; + this->n_user_end = n_user1; this->tc = P_INSTANCE_POINTER tc_x; this->ph = P_INSTANCE_POINTER ph_x; this->pe = P_INSTANCE_POINTER solution_pe_x; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 1b552149..af972752 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -77,10 +77,10 @@ totals(kinetics_ptr->totals) } } cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, - cxxMix & mix, int n_user): + cxxMix & mix, int n_user1): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user; + this->n_user = this->n_user_end = n_user1; step_divide = 1.0; rk = 3; bad_step_max = 500; From 053c817df85e39d0fce73546631c86634200ecc0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 20 Jul 2010 05:43:08 +0000 Subject: [PATCH 0163/1077] added stdlib.h for exit prototype on SunOS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4667 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Parser.cxx b/Parser.cxx index 2733f65b..1a1f6858 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -11,6 +11,7 @@ #include // std::cout std::cerr #include "Utils.h" #include +#include #if defined (PHREEQC_CLASS) #include "Phreeqc.h" #endif From 4b31197710e7afedb189e2bc1107adf1fbf65d0e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Jul 2010 00:18:01 +0000 Subject: [PATCH 0164/1077] Redid modifications for hidden variables using l_ prefix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4674 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 10 +++++----- GasPhase.cxx | 4 ++-- ISolution.cxx | 10 +++++----- ISolution.h | 14 +++++++------- ISolutionComp.cxx | 8 ++++---- ISolutionComp.h | 44 ++++++++++++++++++++++---------------------- NameDouble.cxx | 4 ++-- PPassemblage.cxx | 4 ++-- Parser.cxx | 3 +-- SSassemblage.cxx | 4 ++-- Solution.cxx | 10 +++++----- Solution.h | 36 ++++++++++++++++++------------------ Surface.cxx | 4 ++-- cxxKinetics.cxx | 4 ++-- 14 files changed, 79 insertions(+), 80 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 75b6a68b..fad22031 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -59,10 +59,10 @@ cxxNumKeyword() } cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, - cxxMix & mix, int n_user1): + cxxMix & mix, int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; this->pitzer_exchange_gammas = false; // // Mix exchangers @@ -92,7 +92,7 @@ cxxNumKeyword() } } -cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user1) +cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user) // // constructor for cxxExchange from reaction calculation // equivalent of xexchange_save @@ -105,8 +105,8 @@ cxxNumKeyword() int i; //this->set_description(exchange_ptr->description); - this->n_user = n_user1; - this->n_user_end = n_user1; + this->n_user = l_n_user; + this->n_user_end = l_n_user; this->pitzer_exchange_gammas = (P_INSTANCE_POINTER use.exchange_ptr->pitzer_exchange_gammas == TRUE); this->totals.type = cxxNameDouble::ND_ELT_MOLES; diff --git a/GasPhase.cxx b/GasPhase.cxx index 957514d7..ee43c1ba 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -70,10 +70,10 @@ cxxNumKeyword() } } cxxGasPhase::cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entities, - cxxMix & mix, int n_user1): + cxxMix & mix, int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; total_p = 0; volume = 0; diff --git a/ISolution.cxx b/ISolution.cxx index beaebde1..0cdb319a 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -155,23 +155,23 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) /* * Convert /kgs to /kgw */ - double mass_water1; + double l_mass_water; if ((this->units.find("kgs") != std::string::npos) || (this->units.find("/l") != std::string::npos)) { - mass_water1 = 1.0 - 1e-3 * sum_solutes; + l_mass_water = 1.0 - 1e-3 * sum_solutes; for (; iter != this->comps.end(); ++iter) { - iter->second.set_moles(iter->second.get_moles() / mass_water1); + iter->second.set_moles(iter->second.get_moles() / l_mass_water); } } /* * Scale by mass of water in solution */ - mass_water1 = this->mass_water; + l_mass_water = this->mass_water; for (; iter != this->comps.end(); ++iter) { - iter->second.set_moles(iter->second.get_moles() * mass_water1); + iter->second.set_moles(iter->second.get_moles() * l_mass_water); } } diff --git a/ISolution.h b/ISolution.h index 0eab5d38..14db0810 100644 --- a/ISolution.h +++ b/ISolution.h @@ -34,23 +34,23 @@ class cxxISolution:public cxxSolution { return this->density; } - void set_density(double density1) + void set_density(double l_density) { - this->density = density1; + this->density = l_density; } std::string get_units() const { return units; } - void set_units(std::string units1) + void set_units(std::string l_units) { - units = units1; + units = l_units; } - void set_units(char * units1) + void set_units(char * l_units) { - if (units1 != NULL) - this->units = std::string(units1); + if (l_units != NULL) + this->units = std::string(l_units); else this->units.clear(); } diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 0e55f5e5..f5fa7a9e 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -118,8 +118,8 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) if (this->as.size() != 0) { /* use given chemical formula to calculate gfw */ - double gfw1; - if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &gfw1) == ERROR) + double l_gfw; + if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &l_gfw) == ERROR) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; @@ -131,9 +131,9 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) if (strcmp(this->description.c_str(), "Alkalinity") == 0 && strcmp(this->as.c_str(), "CaCO3")) { - gfw1 /= 2.; + l_gfw /= 2.; } - this->gfw = gfw1; + this->gfw = l_gfw; return; } /* use gfw of master species */ diff --git a/ISolutionComp.h b/ISolutionComp.h index e6ed7e3f..4b12b4b4 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -26,10 +26,10 @@ class cxxISolutionComp { return this->description; } - void set_description(char *description1) + void set_description(char *l_description) { - if (description1 != NULL) - this->description = std::string(description1); + if (l_description != NULL) + this->description = std::string(l_description); else this->description.clear(); } @@ -38,28 +38,28 @@ class cxxISolutionComp { return this->moles; } - void set_moles(double moles1) + void set_moles(double l_moles) { - this->moles = moles1; + this->moles = l_moles; } double get_input_conc() const { return this->input_conc; } - void set_input_conc(double input_conc1) + void set_input_conc(double l_input_conc) { - this->input_conc = input_conc1; + this->input_conc = l_input_conc; } std::string get_units()const { return this->units; } - void set_units(char *units1) + void set_units(char *l_units) { - if (units1 != NULL) - this->units = std::string(units1); + if (l_units != NULL) + this->units = std::string(l_units); else this->units.clear(); } @@ -68,10 +68,10 @@ class cxxISolutionComp { return this->equation_name; } - void set_equation_name(char *equation_name1) + void set_equation_name(char *l_equation_name) { - if (equation_name1 != NULL) - this->equation_name = std::string(equation_name1); + if (l_equation_name != NULL) + this->equation_name = std::string(l_equation_name); else this->equation_name.clear(); @@ -81,28 +81,28 @@ class cxxISolutionComp { return this->phase_si; } - void set_phase_si(int phase_si1) + void set_phase_si(int l_phase_si) { - this->phase_si = phase_si1; + this->phase_si = l_phase_si; } int get_n_pe() const { return this->n_pe; } - void set_n_pe(int n_pe1) + void set_n_pe(int l_n_pe) { - this->n_pe = n_pe1; + this->n_pe = l_n_pe; } const std::string &get_as() const { return this->as; } - void set_as(char *as1) + void set_as(char *l_as) { - if (as1 != NULL) - this->as = std::string(as1); + if (l_as != NULL) + this->as = std::string(l_as); else this->as.clear(); } @@ -112,9 +112,9 @@ class cxxISolutionComp { return this->gfw; }; - void set_gfw(double gfw1) + void set_gfw(double l_gfw) { - this->gfw = gfw1; + this->gfw = l_gfw; } void set_gfw(PHREEQC_PTR_ARG); diff --git a/NameDouble.cxx b/NameDouble.cxx index e4d75f2c..d356891c 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -100,7 +100,7 @@ cxxNameDouble::cxxNameDouble(struct conc *tots) this->type = ND_ELT_MOLES; } cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, - cxxNameDouble::ND_TYPE type1) + cxxNameDouble::ND_TYPE l_type) // // constructor for cxxNameDouble from list of elt_list // @@ -112,7 +112,7 @@ cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, continue; (*this)[ma[i].description] = ma[i].la; } - this->type = type1; + this->type = l_type; } /* cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 8e0a118d..e71b3d87 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -55,10 +55,10 @@ eltList(pp_assemblage_ptr->next_elt) } cxxPPassemblage::cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, - int n_user1): + int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; eltList.type = cxxNameDouble::ND_ELT_MOLES; // // Mix diff --git a/Parser.cxx b/Parser.cxx index 1a1f6858..9f7afab1 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -11,7 +11,6 @@ #include // std::cout std::cerr #include "Utils.h" #include -#include #if defined (PHREEQC_CLASS) #include "Phreeqc.h" #endif @@ -62,7 +61,7 @@ m_next_keyword(KT_NONE) echo_stream = EO_NONE; accumulate = false; #if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; + this->p_instance = p_instance; #endif } diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f7c7b210..f917b0d4 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -53,10 +53,10 @@ cxxNumKeyword() } cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxSSassemblage > &entities, cxxMix & mix, - int n_user1): + int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; //std::list ssAssemblageSSs; // // Mix diff --git a/Solution.cxx b/Solution.cxx index f7f9466e..e98aa572 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -96,7 +96,7 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solutions, - cxxMix & mix, int n_user1) + cxxMix & mix, int l_n_user) // // constructor for cxxSolution from mixture of solutions // @@ -108,7 +108,7 @@ cxxNumKeyword() // Zero out solution data // this->zero(); - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; // // Mix solutions // @@ -133,7 +133,7 @@ cxxNumKeyword() } } -cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user1) +cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user) // // constructor for cxxSolution from results of calculation // does not work in phast because phast uses only the total molalities @@ -143,8 +143,8 @@ cxxNumKeyword() { //this->set_description none; - this->n_user = n_user1; - this->n_user_end = n_user1; + this->n_user = l_n_user; + this->n_user_end = l_n_user; this->tc = P_INSTANCE_POINTER tc_x; this->ph = P_INSTANCE_POINTER ph_x; this->pe = P_INSTANCE_POINTER solution_pe_x; diff --git a/Solution.h b/Solution.h index 2d11efe4..4b7235ba 100644 --- a/Solution.h +++ b/Solution.h @@ -29,9 +29,9 @@ class cxxSolution:public cxxNumKeyword { return this->tc; } - void set_tc(double tc1) + void set_tc(double l_tc) { - this->tc = tc1; + this->tc = l_tc; } double get_ph() const @@ -47,72 +47,72 @@ class cxxSolution:public cxxNumKeyword { return this->pe; } - void set_pe(double pe1) + void set_pe(double l_pe) { - this->pe = pe1; + this->pe = l_pe; } double get_mu() const { return this->mu; } - void set_mu(double mu1) + void set_mu(double l_mu) { - this->mu = mu1; + this->mu = l_mu; } double get_ah2o() const { return this->ah2o; } - void set_ah2o(double ah2o1) + void set_ah2o(double l_ah2o) { - this->ah2o = ah2o1; + this->ah2o = l_ah2o; } double get_total_h() const { return this->total_h; } - void set_total_h(double total_h1) + void set_total_h(double l_total_h) { - this->total_h = total_h1; + this->total_h = l_total_h; } double get_total_o() const { return this->total_o; } - void set_total_o(double total_o1) + void set_total_o(double l_total_o) { - this->total_o = total_o1; + this->total_o = l_total_o; } double get_cb() const { return this->cb; } - void set_cb(double cb1) + void set_cb(double l_cb) { - this->cb = cb1; + this->cb = l_cb; } double get_mass_water() const { return this->mass_water; } - void set_mass_water(long double mass_water1) + void set_mass_water(long double l_mass_water) { - this->mass_water = mass_water1; + this->mass_water = l_mass_water; } double get_total_alkalinity() const { return this->total_alkalinity; } - void set_total_alkalinity(double total_alkalinity1) + void set_total_alkalinity(double l_total_alkalinity) { - this->total_alkalinity = total_alkalinity1; + this->total_alkalinity = l_total_alkalinity; } double get_total(char *string) const; diff --git a/Surface.cxx b/Surface.cxx index 8cc22d31..be5b9e41 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -83,10 +83,10 @@ cxxNumKeyword() } } cxxSurface::cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entities, - cxxMix & mix, int n_user1): + cxxMix & mix, int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; type = DDL; dl_type = NO_DL; sites_units = SITES_ABSOLUTE; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index af972752..73b825f7 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -77,10 +77,10 @@ totals(kinetics_ptr->totals) } } cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, - cxxMix & mix, int n_user1): + cxxMix & mix, int l_n_user): cxxNumKeyword() { - this->n_user = this->n_user_end = n_user1; + this->n_user = this->n_user_end = l_n_user; step_divide = 1.0; rk = 3; bad_step_max = 500; From 89090c46eecc85e6f2eaa85a79500b9f7c3e4e9b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 21 Jul 2010 01:55:39 +0000 Subject: [PATCH 0165/1077] added stdlib.h for exit on SunOS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4675 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Parser.cxx b/Parser.cxx index 9f7afab1..84a4ada6 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -8,6 +8,7 @@ #include // std::transform #include // std::map #include // assert +#include #include // std::cout std::cerr #include "Utils.h" #include From 4de8e60e36c577b4fdc84f8e757748d0bc209c64 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Jul 2010 01:25:27 +0000 Subject: [PATCH 0166/1077] Changed phqalloc to allow 3 cases: USE_PHRQ_ALLOC + NDEBUG USE_PHRQ_ALLOC without NDEBUG and no USE_PHRQ_ALLOC Works with 6 configurations, but not clrClass_debug nor clrClass_release. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4679 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser.cxx b/Parser.cxx index 84a4ada6..526e09ed 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -62,7 +62,7 @@ m_next_keyword(KT_NONE) echo_stream = EO_NONE; accumulate = false; #if defined(PHREEQC_CLASS) - this->p_instance = p_instance; + this->p_instance = p_instance1; #endif } From 20cf5c40c2d68f75cf0f8ca01c53db5e801e5fc3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Aug 2010 23:20:42 +0000 Subject: [PATCH 0167/1077] Fixed uninitialized variable in V_M structure in transport.c, which caused sc7 to fail under Class_release configuration (NDEBUG). Fixed mytest/Makefile to use Class_release version. sit_redox now redefines some SIT parameters. Vendome.pat has O2(aq) concentration fix for Netpath. src/Makefile now uses -DNDEBUG git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4693 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 18abe510..d51a1300 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), RELEASE) - DEFINES = -DPHREEQC_CPP $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DNDEBUG $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ @@ -145,7 +145,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DNDEBUG -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ From 1b6f05cd4153fb3b54cd0a43e0220ad027494623 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Aug 2010 19:05:17 +0000 Subject: [PATCH 0168/1077] Works for class, need to split up initialization for static variables. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4695 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index f3d7abcb..b4361e63 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -495,6 +495,8 @@ int xs_s_assemblage_save(int n_user); int xsurface_save(int n_user); int do_initialize(void); int do_status(void); +void save_init(int i); +void use_init(void); int copy_use(int i); int set_use(void); From 2034b5000b7d91289e224a1e6c74c57639c94971 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Aug 2010 20:59:04 +0000 Subject: [PATCH 0169/1077] Moved some initialization from initialize to class. Moved variables that were static in the non-class version. static variables in the non-class version are now initialized in the definitions. Made project consistent: USE_PHRQ_ALLOC for all debug versions NDEBUG for all release versions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4697 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 3629881a..9ac7021a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1058,5 +1058,168 @@ void Phreeqc::init(void) charge_group = NULL; print_density = 0; + // + // Non-class statics + // + /* basic.c */ + n_user_punch_index = 0; + inbuf = NULL; + linebase = NULL; + varbase = NULL; + loopbase = NULL; + curline = 0; + stmtline = NULL; + dataline = NULL; + stmttok = NULL; + datatok = NULL; + buf = NULL; + exitflag = FALSE; + EXCP_LINE = 0; + /* dw.c */ + Q0 = 0; + Q5 = 0; + Z = 0; + DZ = 0; + Y = 0; + B1 = 0; + B2 = 0; + B1T = 0; + B2T = 0; + B1TT = 0; + B2TT = 0; + /* integrate.c */ + z = 0; + xd = 0; + alpha = 0; + surface_charge_ptr = NULL; + /* inverse.c */ + max_row_count = 50; + max_column_count = 50; + carbon = FALSE; + col_name = NULL; + row_name = NULL; + count_rows = 0; + count_optimize = 0; + col_phases = 0; + col_redox = 0; + col_epsilon = 0; + col_ph = 0; + col_water = 0; + col_isotopes = 0; + col_phase_isotopes = 0; + row_mb = 0; + row_fract = 0; + row_charge = 0; + row_carbon = 0; + row_isotopes = 0; + row_epsilon = 0; + row_isotope_epsilon = 0; + row_water = 0; + inv_zero = NULL; + array1 = 0; + inv_delta1 = NULL; + delta2 = NULL; + delta3 = NULL; + inv_cu = NULL; + delta_save = NULL; + min_delta = NULL; + max_delta = NULL; + klmd = 0; + nklmd = 0; + n2d = 0; + kode = 0; + iter = 0; + toler = 0; + error = 0; + max_pct = 0; + scaled_error = 0; + master_alk = NULL; + row_back = NULL; + col_back = NULL; + good = NULL; + bad = NULL; + minimal = NULL; + max_good = 0; + max_bad = 0; + max_minimal = 0; + count_good = 0; + count_bad = 0; + count_minimal = 0; + count_calls = 0; + soln_bits = 0; + phase_bits = 0; + current_bits = 0; + temp_bits = 0; + netpath_file = NULL; + count_inverse_models = 0; + count_pat_solutions = 0; + inv_res = NULL; + inv_iu = NULL; + inv_is = NULL; + /* kinetics.c */ + m_original = NULL; + m_temp = NULL; + /* p2clib.c */ + P_argc = 0; + P_argv = NULL; + P_escapecode = 0; + P_ioresult = 0; + /* pitzer.c */ + A0 = 0; + count_cations = 0; + count_anions = 0; + count_neutrals = 0; + MAXCATIONS = 0; + FIRSTANION = 0; + MAXNEUTRAL = 0; + mcb0 = NULL; + mcb1 = NULL; + mcc0 = NULL; + /* read.c */ + dummy = 0; + prev_next_char = NULL; + /* sit.c */ + sit_A0 = 0; + sit_count_cations = 0; + sit_count_anions = 0; + sit_count_neutrals = 0; + sit_MAXCATIONS = 0; + sit_FIRSTANION = 0; + sit_MAXNEUTRAL = 0; + /* tidy.c */ + a0 = 0; + a1 = 0; + kc = 0; + kb = 0; + /* tally.c */ + t_buffer = NULL; + tally_count_component = 0; + count_tally_table_columns = 0; + count_tally_table_rows = 0; + /* transport.c */ + sol_D = NULL; + sol_D_dbg = NULL; + J_ij_count_spec = 0; + count_m_s = 0; + tot1_h = 0; + tot1_o = 0; + tot2_h = 0; + tot2_o = 0; + diffc_max = 0; + diffc_tr = 0; + J_ij_sum = 0; + transp_surf = FALSE; + heat_mix_array = NULL; + temp1 = NULL; + temp2 = NULL; + nmix = 0; + heat_nmix = 0; + heat_mix_f_imm = 0; + heat_mix_f_m = 0; + warn_MCD_X = 0; + warn_fixed_Surf = 0; + /* model.c */ + gas_in = FALSE; + return; } From 8ff9cd7986be7413bde76c7dc080bd03edb108cf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Sep 2010 23:10:43 +0000 Subject: [PATCH 0170/1077] Fixed negative exponent problem. Added synonyms to TOTMOLE: TOTMOL, TOTMOLES Added test case negexp_totmol. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4770 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9ac7021a..d3778c8b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -325,6 +325,8 @@ Phreeqc::Phreeqc(void) {"cell_porosity", tokcell_porosity}, {"cell_saturation", tokcell_saturation}, {"totmole", toktotmole}, + {"totmol", toktotmol}, + {"totmoles", toktotmoles}, {"iso", tokiso}, {"iso_unit", tokiso_unit} }; NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); From b1fca87a572a43c971f32d0a854fef6ae66f8c4a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 8 Sep 2010 20:33:43 +0000 Subject: [PATCH 0171/1077] Added -mix, -reaction, -temperature, -cells to DUMP. Added warning for use of REACTION and kinetics. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4800 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 6 ++++ Parser.h | 4 ++- ReadClass.cxx | 85 +++++++++++++++++++++++++++++++++++++++++++++- StorageBin.cxx | 41 ++++++++++++++++++++-- StorageBinList.cpp | 24 +++++++++++++ StorageBinList.h | 2 ++ Temperature.cxx | 20 +++++------ dumper.cpp | 55 +++++++++++++++++++++++++----- dumper.h | 6 ++++ 9 files changed, 220 insertions(+), 23 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index 526e09ed..ba613a77 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -366,6 +366,12 @@ CParser::check_key(std::string::iterator begin, std::string::iterator end) s_keyword_map.insert(std::map < std::string, KEY_TYPE >::value_type("surface_raw", KT_SURFACE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("reaction_temperature_raw", + KT_TEMPERATURE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("reaction_raw", + KT_REACTION_RAW)); } std::string lowercase; diff --git a/Parser.h b/Parser.h index 5fca6cd8..08147419 100644 --- a/Parser.h +++ b/Parser.h @@ -65,7 +65,9 @@ class CParser KT_KINETICS_RAW = 8, KT_PPASSEMBLAGE_RAW = 9, KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 + KT_SURFACE_RAW = 11, + KT_TEMPERATURE_RAW = 12, + KT_REACTION_RAW = 13 }; enum OPT_TYPE diff --git a/ReadClass.cxx b/ReadClass.cxx index 596ddb0e..0925ded5 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -2397,7 +2397,7 @@ dump_ostream(std::ostream& os) } } - // kineticss + // kinetics if (dump_info.Get_bool_kinetics()) { if (dump_info.Get_kinetics().size() == 0) @@ -2423,6 +2423,89 @@ dump_ostream(std::ostream& os) } } + // mix + if (dump_info.Get_bool_mix()) + { + if (dump_info.Get_mix().size() == 0) + { + for (i = 0; i < count_mix; i++) + { + cxxMix cxxentity(&mix[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_mix().begin(); it != dump_info.Get_mix().end(); it++) + { + + if (mix_bsearch(*it, &n) != NULL) + { + cxxMix cxxentity(&mix[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // reaction + if (dump_info.Get_bool_reaction()) + { + if (dump_info.Get_reaction().size() == 0) + { + for (i = 0; i < count_irrev; i++) + { + cxxReaction cxxentity(&irrev[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_reaction().begin(); it != dump_info.Get_reaction().end(); it++) + { + + if (irrev_bsearch(*it, &n) != NULL) + { + cxxReaction cxxentity(&irrev[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // temperature + if (dump_info.Get_bool_temperature()) + { + if (dump_info.Get_temperature().size() == 0) + { + for (i = 0; i < count_temperature; i++) + { + cxxTemperature cxxentity(&temperature[i]); + cxxentity.dump_raw(os,0); + } + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_temperature().begin(); it != dump_info.Get_temperature().end(); it++) + { + + if (temperature_bsearch(*it, &n) != NULL) + { + cxxTemperature cxxentity(&temperature[n]); + cxxentity.dump_raw(os,0); + } + } + } + } + + // Turn off any reaction calculation + os << "USE mix none" << std::endl; + os << "USE reaction none" << std::endl; + os << "USE reaction_temperature none" << std::endl; + // Turn off dump until next read dump_info.SetAll(false); } diff --git a/StorageBin.cxx b/StorageBin.cxx index 74164a10..2af379b5 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -588,7 +588,9 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) KT_KINETICS_RAW = 8, KT_PPASSEMBLAGE_RAW = 9, KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 + KT_SURFACE_RAW = 11, + KT_TEMPERATURE_RAW = 12, + KT_REACTION_RAW = 13 */ case CParser::KT_SOLUTION_RAW: { @@ -646,6 +648,21 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) } break; + case CParser::KT_TEMPERATURE_RAW: + { + cxxTemperature entity; + entity.read_raw(parser); + Temperatures[entity.get_n_user()] = entity; + } + break; + + case CParser::KT_REACTION_RAW: + { + cxxReaction entity; + entity.read_raw(P_INSTANCE_COMMA parser); + Reactions[entity.get_n_user()] = entity; + } + break; default: break; } @@ -682,7 +699,9 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) KT_KINETICS_RAW = 8, KT_PPASSEMBLAGE_RAW = 9, KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11 + KT_SURFACE_RAW = 11, + KT_TEMPERATURE_RAW = 12, + KT_REACTION_RAW = 13 */ case CParser::KT_SOLUTION_RAW: { @@ -747,6 +766,24 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) } break; + case CParser::KT_TEMPERATURE_RAW: + { + cxxTemperature entity; + entity.read_raw(parser); + Temperatures[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + + case CParser::KT_REACTION_RAW: + { + cxxReaction entity; + entity.read_raw(P_INSTANCE_COMMA parser); + Reactions[entity.get_n_user()] = entity; + entity_number = entity.get_n_user(); + } + break; + default: break; } diff --git a/StorageBinList.cpp b/StorageBinList.cpp index cbbdf385..9b816891 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -90,6 +90,13 @@ void StorageBinListItem::Augment(std::string token) } } } +void StorageBinListItem::Augment(int i) +{ + // Skip if all are defined + if (this->defined == true && this->numbers.size() == 0) return; + this->defined = true; + this->numbers.insert(i); +} StorageBinList::StorageBinList(void) { } @@ -276,3 +283,20 @@ bool StorageBinList::Read(CParser & parser) return(return_value); } +void StorageBinList::TransferAll(StorageBinListItem &source) +{ + std::set < int >::iterator it; + for (it = source.Get_numbers().begin(); it != source.Get_numbers().end(); it++) + { + this->solution.Augment(*it); + this->pp_assemblage.Augment(*it); + this->exchange.Augment(*it); + this->surface.Augment(*it); + this->s_s_assemblage.Augment(*it); + this->gas_phase.Augment(*it); + this->kinetics.Augment(*it); + this->mix.Augment(*it); + this->reaction.Augment(*it); + this->temperature.Augment(*it); + } +} \ No newline at end of file diff --git a/StorageBinList.h b/StorageBinList.h index 4656f817..8da5fe83 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -16,6 +16,7 @@ public: void Set_defined(bool tf) { this->defined = tf; }; bool Get_defined(void) { return(this->defined); }; void Augment(std::string token); + void Augment(int i); std::set < int > &Get_numbers(void) { return(this->numbers); }; void Clear(void) { this->numbers.clear(); }; protected: @@ -30,6 +31,7 @@ public: ~StorageBinList(void); bool Read(CParser & parser); void SetAll(bool tf); + void TransferAll(StorageBinListItem &source); StorageBinListItem & Get_solution(void) { return(this->solution); }; StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; diff --git a/Temperature.cxx b/Temperature.cxx index fff10e46..67fd849b 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -160,10 +160,16 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const for (i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); - // Temperature element and attributes s_oss << indent0; - s_oss << "REACTION_TEMPERATURE_RAW " << this-> - n_user << " " << this->description << std::endl; + s_oss << "REACTION_TEMPERATURE_RAW " << this->n_user << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-count_temps " << this->countTemps << std::endl; + + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; + + // Temperature element and attributes s_oss << indent1; s_oss << "-temps " << std::endl; @@ -183,14 +189,6 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const } s_oss << std::endl; } - - s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; - - s_oss << indent1; - s_oss << "-count_temps " << this->countTemps << std::endl; - - } void diff --git a/dumper.cpp b/dumper.cpp index 2e273b11..9417ede4 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -263,6 +263,15 @@ bool dumper::Read(CParser & parser) vopts.push_back("file"); vopts.push_back("append"); vopts.push_back("all"); + vopts.push_back("cell"); + vopts.push_back("cells"); // 18 + vopts.push_back("mix"); // 19 + vopts.push_back("reaction"); // 20 + vopts.push_back("reactions"); // 21 + vopts.push_back("temperature"); // 22 + vopts.push_back("temperatures"); // 23 + + } std::istream::pos_type ptr; @@ -279,6 +288,7 @@ bool dumper::Read(CParser & parser) for (;;) { int opt; + StorageBinListItem cells; opt = parser.get_option(vopts, next_char); if (opt == CParser::OPT_DEFAULT) { @@ -321,12 +331,27 @@ bool dumper::Read(CParser & parser) case 13: item = &(this->binList.Get_kinetics()); break; + case 17: // cell + case 18: // cells + item = &cells; + break; + case 19: // mix + item = &(this->binList.Get_mix()); + break; + case 20: // reaction + case 21: // reactions + item = &(this->binList.Get_reaction()); + break; + case 22: // temperature + case 23: // temperatures + item = &(this->binList.Get_temperature()); + break; default: break; } // Read dump entity list of numbers or number ranges for line, store in item - if (opt >= 0 && opt <= 13) + if ((opt >= 0 && opt <= 13) || (opt >= 17 && opt <= 23)) { for (;;) { @@ -348,6 +373,10 @@ bool dumper::Read(CParser & parser) } } + if (opt == 17 || opt == 18) + { + this->binList.TransferAll(cells); + } // Process other identifiers std::set < int >::iterator it; switch (opt) @@ -371,6 +400,13 @@ bool dumper::Read(CParser & parser) case 11: case 12: case 13: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: break; case 14: //file std::getline(parser.get_iss(), this->file_name); @@ -417,12 +453,15 @@ bool dumper::Read(CParser & parser) bool dumper::Get_bool_any(void) { return ( - Get_bool_solution() || - Get_bool_pp_assemblage() || - Get_bool_exchange() || - Get_bool_surface() || - Get_bool_s_s_assemblage() || - Get_bool_gas_phase() || - Get_bool_kinetics() + Get_bool_solution() || + Get_bool_pp_assemblage() || + Get_bool_exchange() || + Get_bool_surface() || + Get_bool_s_s_assemblage() || + Get_bool_gas_phase() || + Get_bool_kinetics() || + Get_bool_mix() || + Get_bool_reaction() || + Get_bool_temperature() ); } diff --git a/dumper.h b/dumper.h index 95a3db22..312fae33 100644 --- a/dumper.h +++ b/dumper.h @@ -24,6 +24,9 @@ public: bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; + bool Get_bool_mix(void) { return(this->binList.Get_mix().Get_defined()); }; + bool Get_bool_reaction(void) { return(this->binList.Get_reaction().Get_defined()); }; + bool Get_bool_temperature(void) { return(this->binList.Get_temperature().Get_defined()); }; bool Get_bool_any(void); std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; @@ -33,6 +36,9 @@ public: std::set < int > & Get_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_numbers()); }; std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; + std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; + std::set < int > & Get_reaction(void) { return(this->binList.Get_reaction().Get_numbers()); }; + std::set < int > & Get_temperature(void) { return(this->binList.Get_temperature().Get_numbers()); }; protected: std::string file_name; bool append; From fd55082c6bed11fc5f14715ace07f36041029860 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 Sep 2010 20:23:22 +0000 Subject: [PATCH 0172/1077] wrote code to allow files to be included recursively in the main input file. Need to compile with MERGE_INCLUDE_FILES defined. creates a new input file with all include files merged. Syntax for include files is #include file_name (include may be upper or lower case). Want to make a temporary input file to avoid having to find a place to write. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4813 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index b4361e63..ddbdf656 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1435,6 +1435,12 @@ int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); +#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +public: + bool recursive_include(FILE * input_file, std::ofstream & accumulated_file); + int simple_get_line(FILE * input_file, std::string & l_line); +#endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ + public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); From 619dc25cde878de133b1c874f35203744325b4ea Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 Sep 2010 21:09:45 +0000 Subject: [PATCH 0173/1077] Modified merging #include files to use file pointer instead of stream. Now closes original input file and replaces cookie (file pointer) with the merged input file pointer, which is a temporary file. It should get closed at the end of the run and disappear. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4814 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index ddbdf656..8d2c9b15 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1437,7 +1437,7 @@ void ExpandTable_multi(HashTable * Table); #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) public: - bool recursive_include(FILE * input_file, std::ofstream & accumulated_file); + bool recursive_include(FILE * input_file, FILE * accumulated_file); int simple_get_line(FILE * input_file, std::string & l_line); #endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ From f41c9446bf94020e81166c7cfab8627599c9f249 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 Sep 2010 19:03:43 +0000 Subject: [PATCH 0174/1077] Redid capability to include input files using #include fn. Now process database and input files into streams in process_file_names. Uses alternate getc from streams to read the streams. I have not set the necessary #define MERGE_INCLUDE_FILES to implement the new capability. Also requires #define PHREEQC_CLASS. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4816 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 6 ++++-- class_main.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 8d2c9b15..abc1bf52 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -311,6 +311,9 @@ public: int close_input_files(void); int close_output_files(void); CLASS_STATIC int getc_callback(void *cookie); +#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +CLASS_STATIC int istream_getc(void *cookie); +#endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); @@ -1437,8 +1440,7 @@ void ExpandTable_multi(HashTable * Table); #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) public: - bool recursive_include(FILE * input_file, FILE * accumulated_file); - int simple_get_line(FILE * input_file, std::string & l_line); + bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); #endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ public: // public methods for PHREEQC_CLASS diff --git a/class_main.cpp b/class_main.cpp index 55c4c7ba..7e169d74 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -133,7 +133,11 @@ main_method(int argc, char *argv[]) /* * Load database into memory */ +#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) + errors = read_database(istream_getc, db_cookie); +#else errors = read_database(getc_callback, db_cookie); +#endif if (errors != 0) { //clean_up(); @@ -143,7 +147,11 @@ main_method(int argc, char *argv[]) /* * Read input data for simulation */ +#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) + errors = run_simulations(istream_getc, input_cookie); +#else errors = run_simulations(getc_callback, input_cookie); +#endif if (errors != 0) { //clean_up(); From d34b328b066ef883dfd3c0d3cb00610928a2165e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Sep 2010 21:39:00 +0000 Subject: [PATCH 0175/1077] Added -cell to dump, copy, delete. Selects anything with the specified user numbers. Fixed bug in read_class where end of file caused the last line of input to be repeated in the output. removed warning print from copy_entities, which is nicer for copy -cell and some reactants are not present. rewrote read_copy to include -cell, but also changed logic for selection of appropriate keywords. Now has list that are acceptable, whereas before it was a list of unacceptable. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4823 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 40 ++++++++++++++++++++-------------------- StorageBinList.cpp | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 0925ded5..5d97f9e1 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -137,7 +137,7 @@ read_solution_raw(void) } // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -231,7 +231,7 @@ read_exchange_raw(void) free_check_null(exchange_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -325,7 +325,7 @@ read_surface_raw(void) free_check_null(surface_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -422,7 +422,7 @@ read_equilibrium_phases_raw(void) free_check_null(pp_assemblage_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -516,7 +516,7 @@ read_kinetics_raw(void) free_check_null(kinetics_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -614,7 +614,7 @@ read_solid_solutions_raw(void) free_check_null(s_s_assemblage_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -708,7 +708,7 @@ read_gas_phase_raw(void) free_check_null(gas_phase_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -803,7 +803,7 @@ read_reaction_raw(void) free_check_null(irrev_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -898,7 +898,7 @@ read_mix_raw(void) free_check_null(mix_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -996,7 +996,7 @@ read_temperature_raw(void) free_check_null(temperature_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1048,7 +1048,7 @@ read_dump(void) // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1100,7 +1100,7 @@ read_delete(void) // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1152,7 +1152,7 @@ read_run_cells(void) // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1239,7 +1239,7 @@ read_solution_modify(void) solution[n] = soln_ptr; // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1326,7 +1326,7 @@ read_equilibrium_phases_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1415,7 +1415,7 @@ read_exchange_modify(void) // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1502,7 +1502,7 @@ read_surface_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1589,7 +1589,7 @@ read_solid_solutions_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1674,7 +1674,7 @@ read_gas_phase_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1761,7 +1761,7 @@ read_kinetics_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 9b816891..753d6fea 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -139,7 +139,7 @@ bool StorageBinList::Read(CParser & parser) static std::vector < std::string > vopts; if (vopts.empty()) { - vopts.reserve(15); + vopts.reserve(20); vopts.push_back("solution"); vopts.push_back("pp_assemblage"); vopts.push_back("equilibrium_phases"); @@ -154,6 +154,8 @@ bool StorageBinList::Read(CParser & parser) vopts.push_back("reaction"); vopts.push_back("temperature"); vopts.push_back("all"); + vopts.push_back("cell"); + vopts.push_back("cells"); // 15 } std::istream::pos_type next_char; @@ -178,6 +180,7 @@ bool StorageBinList::Read(CParser & parser) // Select StorageBinListItem StorageBinListItem *item = NULL; + StorageBinListItem cell_list; switch (opt) { case 0: @@ -213,12 +216,16 @@ bool StorageBinList::Read(CParser & parser) case 12: item = &(this->Get_temperature()); break; + case 14: + case 15: + item = &cell_list; + break; default: break; } // Read dump entity list of numbers or number ranges for line, store in item - if (opt >= 0 && opt <= 12) + if (opt >= 0 && opt <= 12 || opt >= 14 && opt <= 15) { for (;;) { @@ -266,6 +273,10 @@ bool StorageBinList::Read(CParser & parser) case 13: //all this->SetAll(true); break; + case 14: + case 15: + this->TransferAll(cell_list); + break; default: case CParser::OPT_DEFAULT: case CParser::OPT_ERROR: From aa5cafeadd32d9da557712c8f16862978c070e58 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 20 Sep 2010 16:04:46 +0000 Subject: [PATCH 0176/1077] Use OPTION_KEYWORD for stremify KEYWORD for check_line. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4827 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 5d97f9e1..c0cc605d 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -137,7 +137,7 @@ read_solution_raw(void) } // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -231,7 +231,7 @@ read_exchange_raw(void) free_check_null(exchange_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -325,7 +325,7 @@ read_surface_raw(void) free_check_null(surface_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -422,7 +422,7 @@ read_equilibrium_phases_raw(void) free_check_null(pp_assemblage_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -516,7 +516,7 @@ read_kinetics_raw(void) free_check_null(kinetics_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -614,7 +614,7 @@ read_solid_solutions_raw(void) free_check_null(s_s_assemblage_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -708,7 +708,7 @@ read_gas_phase_raw(void) free_check_null(gas_phase_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -803,7 +803,7 @@ read_reaction_raw(void) free_check_null(irrev_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -898,7 +898,7 @@ read_mix_raw(void) free_check_null(mix_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } @@ -996,7 +996,7 @@ read_temperature_raw(void) free_check_null(temperature_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } /* ---------------------------------------------------------------------- */ From 8e65d00c7521643570fc2069169bfe7d62b2469c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 20 Sep 2010 17:09:14 +0000 Subject: [PATCH 0177/1077] Fixed duplicate lines in echoing output at end of file Streamify checks for OPTION_KEYWORD; check_line is KEYWORD. basic_test.out, ppdump.out has warning for REACTION and KINETICS. ppdump.dmp has USE mix, reaction, reaction_temperature none now ppdump.dmp dumps reaction_raw, mix, react_temperature_raw cell_operations is now linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4828 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 753d6fea..4b61ad87 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -225,7 +225,7 @@ bool StorageBinList::Read(CParser & parser) } // Read dump entity list of numbers or number ranges for line, store in item - if (opt >= 0 && opt <= 12 || opt >= 14 && opt <= 15) + if ((opt >= 0 && opt <= 12) || (opt >= 14 && opt <= 15)) { for (;;) { @@ -310,4 +310,4 @@ void StorageBinList::TransferAll(StorageBinListItem &source) this->reaction.Augment(*it); this->temperature.Augment(*it); } -} \ No newline at end of file +} From 5aafb6d533e747547c3428d3b4e70d6a1cb1997b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 20 Sep 2010 22:59:32 +0000 Subject: [PATCH 0178/1077] Added some identifier synonyms for DUMP and DELETE. Moved comments on DUMP and DELETE to phreeqcpp revisions from phreeeqc revisions. Updated keywords through DUMP. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4829 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 2 ++ dumper.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 4b61ad87..3dcd1487 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -156,6 +156,7 @@ bool StorageBinList::Read(CParser & parser) vopts.push_back("all"); vopts.push_back("cell"); vopts.push_back("cells"); // 15 + vopts.push_back("reaction_temperature"); } std::istream::pos_type next_char; @@ -214,6 +215,7 @@ bool StorageBinList::Read(CParser & parser) item = &(this->Get_reaction()); break; case 12: + case 16: item = &(this->Get_temperature()); break; case 14: diff --git a/dumper.cpp b/dumper.cpp index 9417ede4..c0c169cd 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -269,9 +269,8 @@ bool dumper::Read(CParser & parser) vopts.push_back("reaction"); // 20 vopts.push_back("reactions"); // 21 vopts.push_back("temperature"); // 22 - vopts.push_back("temperatures"); // 23 - - + vopts.push_back("reaction_temperature"); // 23 + vopts.push_back("reaction_temperatures"); // 24 } std::istream::pos_type ptr; @@ -343,7 +342,8 @@ bool dumper::Read(CParser & parser) item = &(this->binList.Get_reaction()); break; case 22: // temperature - case 23: // temperatures + case 23: // reaction_temperature + case 24: // reaction_temperatures item = &(this->binList.Get_temperature()); break; default: From 11b0315dd8f64985f6847c4c699ef70e6e560154 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Sep 2010 20:58:42 +0000 Subject: [PATCH 0179/1077] Made pitzer_exchange_gammas true the default. Fixed up read_input to use correct keyword numbers. Updated tidy to tidy the appropriate data blocks when _modify blocks are read. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4830 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 4 ++-- ReadClass.cxx | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index fad22031..cfcad80f 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -31,7 +31,7 @@ cxxExchange::cxxExchange() // : cxxNumKeyword() { - pitzer_exchange_gammas = false; + pitzer_exchange_gammas = true; } cxxExchange::cxxExchange(struct exchange * exchange_ptr) @@ -63,7 +63,7 @@ cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange cxxNumKeyword() { this->n_user = this->n_user_end = l_n_user; - this->pitzer_exchange_gammas = false; + this->pitzer_exchange_gammas = true; // // Mix exchangers // diff --git a/ReadClass.cxx b/ReadClass.cxx index c0cc605d..eefa7144 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1322,6 +1322,8 @@ read_equilibrium_phases_modify(void) 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[n].new_def = TRUE; + pp_assemblage[n].n_user_end = pp_assemblage[n].n_user; pp_assemblage_free(entity_ptr); free_check_null(entity_ptr); From 3c280751649eb0bc0d6442c6ce9df76b343b65c0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 22 Sep 2010 17:17:38 +0000 Subject: [PATCH 0180/1077] exchange_modify, recalculate formula_totals after redefinition. changed pitzer_exchange_gammas to exchange_gammas. Fixed null pointer in prep.c Tidy equilibirium phases after equilibirium_phases_modify, but not other reactants. For equilibrium phases, recalculates an element list. input.fm throug exchange_modify. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4831 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 4 +++- ReadClass.cxx | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Exchange.cxx b/Exchange.cxx index cfcad80f..63d3baca 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -278,7 +278,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const description << std::endl; s_oss << indent1; - s_oss << "-pitzer_exchange_gammas " << this-> + s_oss << "-exchange_gammas " << this-> pitzer_exchange_gammas << std::endl; // exchComps structures @@ -302,6 +302,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) vopts.reserve(15); vopts.push_back("pitzer_exchange_gammas"); // 0 vopts.push_back("component"); // 1 + vopts.push_back("exchange_gammas"); // 2 } std::istream::pos_type ptr; @@ -343,6 +344,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 0: // pitzer_exchange_gammas + case 2: // exchange_gammas if (!(parser.get_iss() >> this->pitzer_exchange_gammas)) { this->pitzer_exchange_gammas = false; diff --git a/ReadClass.cxx b/ReadClass.cxx index eefa7144..edb8f213 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1324,6 +1324,7 @@ read_equilibrium_phases_modify(void) pp_assemblage[n].description = string_duplicate(entity_ptr->description); pp_assemblage[n].new_def = TRUE; pp_assemblage[n].n_user_end = pp_assemblage[n].n_user; + pp_assemblage_free(entity_ptr); free_check_null(entity_ptr); @@ -1410,8 +1411,26 @@ read_exchange_modify(void) struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); exchange_free(&(exchange[n])); exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); + + /* tidy description and n_user_end */ free_check_null(exchange[n].description); exchange[n].description = string_duplicate(entity_ptr->description); + exchange[n].n_user_end = exchange[n].n_user; + + /* recalculate formula_totals */ + int i; + for (i = 0; i < exchange[n].count_comps; i++) + { + count_elts = 0; + paren_count = 0; + char *ptr = exchange[n].comps[i].formula; + get_elts_in_species(&ptr, 1.0); + free_check_null(exchange[n].comps[i].formula_totals); + exchange[n].comps[i].formula_totals = elt_list_save(); + } + + + //exchange[n].new_def = TRUE; exchange_free(entity_ptr); free_check_null(entity_ptr); From 61580e1510d9304506c1ec571f8050bc3d5cf6aa Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Sep 2010 21:31:35 +0000 Subject: [PATCH 0181/1077] added equal_steps to cxxKinetics. Had not implemented the "in steps" option for the Kinetics class. Skipped checking in kinetics components when using kinetics_modify. Thru kinetics_raw. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4836 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 61 +++++++++++++++++++++++++----------------------- cxxKinetics.cxx | 45 +++++++++++++++++++++++++++++++++-- cxxKinetics.h | 1 + 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 0d015b8b..d7988c31 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -350,36 +350,39 @@ cxxKineticsComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) { this->d_params = temp_d_params; } - // members that must be defined - if (rate_name_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Rate_name not defined for KineticsComp input.", - CParser::OT_CONTINUE); - } - if (tol_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Tol not defined for KineticsComp input.", - CParser::OT_CONTINUE); - } - if (m_defined == false) - { - parser.incr_input_error(); - parser.error_msg("M not defined for KineticsComp input.", - CParser::OT_CONTINUE); - } - if (m0_defined == false) - { - parser.incr_input_error(); - parser.error_msg("M0 not defined for KineticsComp input.", - CParser::OT_CONTINUE); - } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for KineticsComp input.", - CParser::OT_CONTINUE); + // members that must be defined + if (rate_name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rate_name not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (tol_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Tol not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (m_defined == false) + { + parser.incr_input_error(); + parser.error_msg("M not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (m0_defined == false) + { + parser.incr_input_error(); + parser.error_msg("M0 not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for KineticsComp input.", + CParser::OT_CONTINUE); + } } } diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 73b825f7..3e02565d 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -39,6 +39,7 @@ cxxKinetics::cxxKinetics() cvode_steps = 100; cvode_order = 5; totals.type = cxxNameDouble::ND_ELT_MOLES; + equal_steps = 0; } cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr) @@ -71,7 +72,14 @@ totals(kinetics_ptr->totals) } // steps - for (i = 0; i < kinetics_ptr->count_steps; i++) + int n = kinetics_ptr->count_steps; + this->equal_steps = 0; + if (kinetics_ptr->count_steps < 0) + { + this->equal_steps = -kinetics_ptr->count_steps; + n = 1; + } + for (i = 0; i < n; i++) { this->steps.push_back(kinetics_ptr->steps[i]); } @@ -137,7 +145,14 @@ cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) cxxKineticsComp::cxxKineticsComp2kinetics_comp(P_INSTANCE_COMMA this->kineticsComps); // steps - kinetics_ptr->count_steps = (int) this->steps.size(); + if (this->equal_steps == 0) + { + kinetics_ptr->count_steps = (int) this->steps.size(); + } + else + { + kinetics_ptr->count_steps = -this->equal_steps; + } kinetics_ptr->steps = (double *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->steps); if (this->steps.size() > 0) { @@ -245,6 +260,10 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "-totals " << std::endl; this->totals.dump_raw(s_oss, indent + 2); + // equal_steps + s_oss << indent1; + s_oss << "-equal_steps " << this->equal_steps << std::endl; + // steps s_oss << indent1; s_oss << "-steps " << std::endl; @@ -285,6 +304,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) vopts.push_back("steps"); vopts.push_back("cvode_steps"); vopts.push_back("cvode_order"); + vopts.push_back("equal_steps"); } std::istream::pos_type ptr; @@ -305,6 +325,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) bool cvode_steps_defined(false); bool cvode_order_defined(false); bool steps_defined(false); + bool equal_steps_defined(false); for (;;) { @@ -520,6 +541,17 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) cvode_order_defined = true; useLastLine = false; break; + case 9: // equal steps + if (!(parser.get_iss() >> this->equal_steps)) + { + this->equal_steps = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for equal_steps.", + CParser::OT_CONTINUE); + } + equal_steps_defined = true; + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -568,6 +600,12 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); } + if (equal_steps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", + CParser::OT_CONTINUE); + } } } @@ -602,6 +640,7 @@ cxxKinetics::mpi_pack(std::vector < int >&ints, ints.push_back(this->use_cvode); ints.push_back(this->cvode_steps); ints.push_back(this->cvode_order); + ints.push_back(this->equal_steps); } void @@ -635,6 +674,7 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->use_cvode = (ints[i++] == TRUE); this->cvode_steps = ints[i++]; this->cvode_order = ints[i++]; + this->equal_steps = ints[i++]; *ii = i; *dd = d; } @@ -736,6 +776,7 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) this->use_cvode = addee.use_cvode; this->cvode_steps = addee.cvode_steps; this->cvode_order = addee.cvode_order; + this->equal_steps = addee.equal_steps; } //cxxNameDouble & cxxKinetics::get_totals(void) //{ diff --git a/cxxKinetics.h b/cxxKinetics.h index 15a834b5..be28b7ca 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -50,6 +50,7 @@ class cxxKinetics:public cxxNumKeyword //std::map < std::string, cxxKineticsComp > kineticsComps; std::list < cxxKineticsComp > kineticsComps; std::vector < double >steps; + int equal_steps; cxxNameDouble totals; double step_divide; int rk; From 8b69f05ff954f5f34db3bf5615f960f4b74cdef2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Sep 2010 17:18:03 +0000 Subject: [PATCH 0182/1077] Added missing -dw parameters for MgCO3, MgHCO3, and MgSO4 aqueous species. Changed indentation for llnl parameters in model.c Added capability to include files within the input file. Files included in include files are also included. Files are included verbatim and need not contain complete keyword datablocks; however, the combination of included files must result in a legal PHREEQC input file. #$include file_name Updated #$include to work with all configurations. Added MERGE_INCLUDE_FILES define to all configurations of phreeqcpp. Updated phreeqc and phreeqcpp revisions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4843 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 ++++---- class_main.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index abc1bf52..5c519364 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -311,9 +311,9 @@ public: int close_input_files(void); int close_output_files(void); CLASS_STATIC int getc_callback(void *cookie); -#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +#if defined(MERGE_INCLUDE_FILES) CLASS_STATIC int istream_getc(void *cookie); -#endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ +#endif /* #if defined(MERGE_INCLUDE_FILES) */ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); @@ -1438,10 +1438,10 @@ int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); -#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +#if defined(MERGE_INCLUDE_FILES) public: bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); -#endif /* #if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) */ +#endif /* #if defined(MERGE_INCLUDE_FILES) */ public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); diff --git a/class_main.cpp b/class_main.cpp index 7e169d74..5bf27068 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -133,7 +133,7 @@ main_method(int argc, char *argv[]) /* * Load database into memory */ -#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +#if defined(MERGE_INCLUDE_FILES) errors = read_database(istream_getc, db_cookie); #else errors = read_database(getc_callback, db_cookie); @@ -147,7 +147,7 @@ main_method(int argc, char *argv[]) /* * Read input data for simulation */ -#if defined(MERGE_INCLUDE_FILES) && defined(PHREEQC_CLASS) +#if defined(MERGE_INCLUDE_FILES) errors = run_simulations(istream_getc, input_cookie); #else errors = run_simulations(getc_callback, input_cookie); From 7a46255d8ac7101105ee8732f67a9e2d50e19c89 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 Sep 2010 00:05:59 +0000 Subject: [PATCH 0183/1077] Eliminated requirement for equal_steps in kinetics_raw read. Thought this would make it more backward compatible. Corrected spelling of Lambda in pitzer.dat. Added Lambda to pitzer.c identifiers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4848 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 3e02565d..4edc5f7c 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -600,12 +600,13 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", CParser::OT_CONTINUE); } - if (equal_steps_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); - } + // disable to remain backward compatible with PHAST restart files? + //if (equal_steps_defined == false) + //{ + // parser.incr_input_error(); + // parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", + // CParser::OT_CONTINUE); + //} } } From 75e0df6e1aefa8b5100a456f0c5abdfb5a31c7a5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Sep 2010 22:18:39 +0000 Subject: [PATCH 0184/1077] Through REACTION_MODIFY and REACTION_RAW. Added REACTION_MODIFY for completeness. Fixed bugs in ReadClass.cxx where alpha for id number caused an endless loop. Also fixed some error messages where line_save was no longer meaningful. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4857 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 + Reaction.cxx | 49 +++++++++++++-------- Reaction.h | 2 +- ReadClass.cxx | 117 +++++++++++++++++++++++++++++++++++++++++++++---- StorageBin.cxx | 4 +- 5 files changed, 144 insertions(+), 30 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 5c519364..eebe714c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -876,6 +876,8 @@ int next_keyword_or_option(const char **opt_list, int count_opt_list); int read_solid_solutions_modify(void); int read_gas_phase_modify(void); int read_kinetics_modify(void); + int read_reaction_modify(void); + int read_reaction_temperature_modify(void); int read_delete(void); int read_run_cells(void); int streamify_to_next_keyword(std::istringstream & lines); diff --git a/Reaction.cxx b/Reaction.cxx index efe4ca9d..1bbf24fd 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -223,7 +223,7 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) +cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, const bool check) { int j; @@ -241,6 +241,9 @@ cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) vopts.push_back("count_steps"); //5 } + // clear steps for modify operation, if steps are read + bool cleared_once = false; + std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -320,6 +323,11 @@ cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) break; case 3: // steps + if (!cleared_once) + { + this->steps.clear(); + cleared_once = true; + } while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { @@ -369,24 +377,27 @@ cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined - if (units_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Units not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); - } - if (equalIncrements_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Equal_increments not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); - } - if (countSteps_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Count_steps not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); + // members that must be defined + if (units_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Units not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Equal_increments not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } + if (countSteps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Count_steps not defined for REACTION_RAW input.", + CParser::OT_CONTINUE); + } } } diff --git a/Reaction.h b/Reaction.h index 79b68c07..3f5afeb4 100644 --- a/Reaction.h +++ b/Reaction.h @@ -24,7 +24,7 @@ class cxxReaction:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser); + void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check); cxxNameDouble &get_elementList(void) { return this->elementList; diff --git a/ReadClass.cxx b/ReadClass.cxx index edb8f213..e830e241 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -774,7 +774,7 @@ read_reaction_raw(void) parser.get_option(vopts, next_char); cxxReaction ex; - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(PHREEQC_THIS_COMMA parser, true); struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); int n; @@ -1186,6 +1186,8 @@ read_solution_modify(void) input_error++; sprintf(error_string, "Expected solution number following SOLUTION_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1221,7 +1223,7 @@ read_solution_modify(void) if (solution_bsearch(n_user, &n, FALSE) == NULL) { input_error++; - sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1273,6 +1275,8 @@ read_equilibrium_phases_modify(void) input_error++; sprintf(error_string, "Expected equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1307,7 +1311,7 @@ read_equilibrium_phases_modify(void) if (pp_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1363,6 +1367,8 @@ read_exchange_modify(void) input_error++; sprintf(error_string, "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1398,7 +1404,7 @@ read_exchange_modify(void) if (exchange_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1470,6 +1476,8 @@ read_surface_modify(void) input_error++; sprintf(error_string, "Expected surface number following SURFACE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1504,7 +1512,7 @@ read_surface_modify(void) if (surface_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1557,6 +1565,8 @@ read_solid_solutions_modify(void) input_error++; sprintf(error_string, "Expected solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1591,7 +1601,7 @@ read_solid_solutions_modify(void) if (s_s_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1643,6 +1653,8 @@ read_gas_phase_modify(void) input_error++; sprintf(error_string, "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1677,7 +1689,7 @@ read_gas_phase_modify(void) if (gas_phase_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1729,6 +1741,8 @@ read_kinetics_modify(void) input_error++; sprintf(error_string, "Expected kinetics number following KINETICS_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); return (ERROR); } else @@ -1763,7 +1777,7 @@ read_kinetics_modify(void) if (kinetics_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n%s\n", n_user, line_save); + sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1787,6 +1801,93 @@ read_kinetics_modify(void) } /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER +read_reaction_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads REACTION_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + // find gas_phase 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 reaction number following REACTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + if (irrev_bsearch(n_user, &n) == NULL) + { + input_error++; + sprintf(error_string, "Reaction %d not found for REACTION_MODIFY.\n", n_user); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + cxxReaction entity(&(irrev[n])); + entity.read_raw(PHREEQC_THIS_COMMA parser, false); + // save entity + struct irrev *entity_ptr = entity.cxxReaction2irrev(PHREEQC_THIS); + irrev_free(&(irrev[n])); + irrev_copy(entity_ptr, &(irrev[n]), entity_ptr->n_user); + free_check_null(irrev[n].description); + irrev[n].description = string_duplicate(entity_ptr->description); + irrev_free(entity_ptr); + free_check_null(entity_ptr); + + // Need to output the next keyword + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER streamify_to_next_keyword(std::istringstream & lines) /* ---------------------------------------------------------------------- */ { diff --git a/StorageBin.cxx b/StorageBin.cxx index 2af379b5..53ccdfa4 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -659,7 +659,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_REACTION_RAW: { cxxReaction entity; - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(P_INSTANCE_COMMA parser, true); Reactions[entity.get_n_user()] = entity; } break; @@ -778,7 +778,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_REACTION_RAW: { cxxReaction entity; - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(P_INSTANCE_COMMA parser, true); Reactions[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } From d6d3c223d238d1a6e51ba1d03945d3fefe119c64 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Oct 2010 18:21:52 +0000 Subject: [PATCH 0185/1077] Initialized solid solution in read.c Fixed error message in SSassemblage.cxx Trapped error in SSassemblage.cxx Through SOLID_SOLUTIONS_RAW. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4862 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SSassemblage.cxx | 2 +- SSassemblageSS.cxx | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f917b0d4..f25fb303 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -203,7 +203,7 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser. - error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.", + error_msg("Unknown input in SOLID_SOLUTIONS_RAW or SOLID_SOLUTIONS_MODIFY keyword.", CParser::OT_CONTINUE); parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); useLastLine = false; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index e46ceecb..329ffe6a 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -11,6 +11,7 @@ #if !defined(PHREEQC_CLASS) #define EXTERNAL extern #include "global.h" +#include "output.h" #else #include "Phreeqc.h" #endif @@ -95,6 +96,10 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::s it != el.end(); ++it) { s_s_ptr[j].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); + if ((*it).second.name.size() <= 0) + { + P_INSTANCE_POINTER error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); + } assert((*it).second.name.size() > 0); //s_s_ptr[j].total_moles = it->total_moles; s_s_ptr[j].total_moles = 0; @@ -212,7 +217,7 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const //s_oss << indent0 << "-tk " << this->tk << std::endl; s_oss << indent1 << "-xb1 " << this->xb1 << std::endl; s_oss << indent1 << "-xb2 " << this->xb2 << std::endl; - s_oss << indent1 << "-component " << std::endl; + s_oss << indent1 << "-components " << std::endl; this->comps.dump_raw(s_oss, indent + 2); } From 3e8e792778bdb717b1f23adcd57bcb8510fa711f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 26 Oct 2010 22:48:33 +0000 Subject: [PATCH 0186/1077] Some spec cond diffs. Some Linux/Dos diffs. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4911 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d51a1300..0cac0f39 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), RELEASE) - DEFINES = -DPHREEQC_CPP -DNDEBUG $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DNDEBUG -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ @@ -125,7 +125,7 @@ ifeq ($(CFG), RELEASE) endif ifeq ($(CFG), DEBUG) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ @@ -135,7 +135,7 @@ ifeq ($(CFG), DEBUG) endif ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -145,7 +145,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DPHREEQC_CPP -DNDEBUG -DPHREEQC_CLASS $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DNDEBUG -DPHREEQC_CLASS -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ From e0ed0a618fd40ca0b0c675b720da34797d6fb8a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Nov 2010 17:19:08 +0000 Subject: [PATCH 0187/1077] Updated project to include chart icon in managed resources. Fixed bug in initialization of charting symbols. Tony's changes to charting. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4944 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d3778c8b..1d2980fe 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -377,7 +377,7 @@ Phreeqc::Phreeqc(void) char *SymbolList_init[11] = {"Square", "Diamond", "Triangle", "Circle", "XCross", "Plus", "Star", "TriangleDown", "HDash", "VDash", "None"}; - for (i = 1; i < 11; i++) + for (i = 0; i < 11; i++) { SymbolList[i] = string_duplicate(SymbolList_init[i]); } From 6f9a13b1069ac127227266b9bc14c2e62ab6a9fd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Dec 2010 17:24:00 +0000 Subject: [PATCH 0188/1077] Redid include as include$. Have rewritten get_line, but need to redo the parser get_line. Works on include test case. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4987 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 33 +++++++++++++++++++++++++++++++++ Phreeqc.h | 8 ++++++++ class_main.cpp | 4 ++++ 3 files changed, 45 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1d2980fe..dc3470fd 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -476,6 +476,7 @@ Phreeqc::~Phreeqc(void) PHRQ_free_all(); } + void Phreeqc::set_phast(int tf) { this->phast = tf; @@ -1223,5 +1224,37 @@ void Phreeqc::init(void) /* model.c */ gas_in = FALSE; + this->clear_cookie(); + return; } +void * Phreeqc::get_cookie() +{ + if (cookie_list.size() > 0) + { + return this->cookie_list.front(); + } + else + { + return NULL; + } +} +void Phreeqc::set_cookie(std::istream * cookie) +{ + this->cookie_list.push_front(cookie); +} +void Phreeqc::clear_cookie(void) +{ + while (this->cookie_list.size() > 0) + { + this->pop_cookie(); + } +} +void Phreeqc::pop_cookie() +{ + if (cookie_list.size() > 0) + { + delete this->cookie_list.front(); + this->cookie_list.pop_front(); + } +} \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index eebe714c..aafe3662 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1449,8 +1449,16 @@ public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); + void *get_cookie(); + void pop_cookie(); + void set_cookie(std::istream * cookie); + void clear_cookie(void); protected: void init(void); +//Data + std::list cookie_list; + std::ifstream * in_stream; + std::ifstream * db_stream; }; #endif /* _INC_PHREEQC_H */ diff --git a/class_main.cpp b/class_main.cpp index 5bf27068..2d380018 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -134,7 +134,9 @@ main_method(int argc, char *argv[]) * Load database into memory */ #if defined(MERGE_INCLUDE_FILES) + this->set_cookie((std::ifstream *) db_cookie); errors = read_database(istream_getc, db_cookie); + this->clear_cookie(); #else errors = read_database(getc_callback, db_cookie); #endif @@ -148,7 +150,9 @@ main_method(int argc, char *argv[]) * Read input data for simulation */ #if defined(MERGE_INCLUDE_FILES) + this->set_cookie((std::ifstream *)input_cookie); errors = run_simulations(istream_getc, input_cookie); + this->clear_cookie(); #else errors = run_simulations(getc_callback, input_cookie); #endif From f3f50f021901effa370b78aec228183fe8ab758d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Dec 2010 18:34:39 +0000 Subject: [PATCH 0189/1077] Added EOL$ function. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4988 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index dc3470fd..1220bdb7 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -210,6 +210,7 @@ Phreeqc::Phreeqc(void) {"str$", tokstr_}, {"val", tokval}, {"chr$", tokchr_}, + {"eol$", tokeol_}, {"asc", tokasc}, {"len", toklen}, {"mid$", tokmid_}, From e2c2949e1db97c44d66f7d7b65f07754888ea70d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 22 Dec 2010 16:55:54 +0000 Subject: [PATCH 0190/1077] latest phreeqcpp modified calc_SC to 273.15 Makefile does not merge for nonclass versions git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4992 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0cac0f39..f84b78d6 100644 --- a/Makefile +++ b/Makefile @@ -115,7 +115,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), RELEASE) - DEFINES = -DPHREEQC_CPP -DNDEBUG -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DNDEBUG $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ @@ -125,7 +125,7 @@ ifeq ($(CFG), RELEASE) endif ifeq ($(CFG), DEBUG) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) + DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc CXX = g++ From e3ec792a65fcacef36c65f2859934b7346dcfdf8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 22 Dec 2010 17:39:28 +0000 Subject: [PATCH 0191/1077] Tony's changes. His read_csv does not work now because of the include changes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@4993 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 440 ++++++++++++++++++++++++++-------------------------- 1 file changed, 221 insertions(+), 219 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1220bdb7..3db1273e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -67,7 +67,7 @@ Phreeqc::Phreeqc(void) count_iso_defaults = temp_count_iso_defaults; iso_defaults = new iso[count_iso_defaults]; - + int i; for (i = 0; i < temp_count_iso_defaults; i++) { @@ -371,12 +371,13 @@ Phreeqc::Phreeqc(void) end_timer = false; /* in mainsubs.c, stops the update timer in form1.h */ + ncurves = 0; for (i = 0; i < 3; i++) { - ncurves_changed[i] = 0; /* for updating the chart: */ - } /* 0 or 1 (if curves have changed), previous no, new no of curves with points*/ + ncurves_changed[i] = 0; /* for updating the chart: */ + } /* 0 or 1 (if curves have changed), previous no, new no of curves with points*/ - char *SymbolList_init[11] = {"Square", "Diamond", "Triangle", "Circle", "XCross", "Plus", "Star", + char *SymbolList_init[11] = {"Square", "Diamond", "Triangle", "Circle", "XCross", "Plus", "Star", "TriangleDown", "HDash", "VDash", "None"}; for (i = 0; i < 11; i++) { @@ -387,7 +388,7 @@ Phreeqc::Phreeqc(void) nCSV_headers = 0; /* no of CSV curves, also defines ColumnOffset if connect_simulations = 1 */ FirstCallToUSER_GRAPH = 1; - new_ug = false; /* in case USER_GRAPH is redefined */ + new_ug = false; /* in case USER_GRAPH is redefined */ u_g = false; u_g_active = false; #endif // CHART @@ -400,7 +401,7 @@ Phreeqc::Phreeqc(void) GASCON = 0.461522e0; TZ = 647.073e0; AA = 1.e0; - G1 = 11.e0; + G1 = 11.e0; G2 = 44.333333333333e0; GF = 3.5e0; @@ -484,7 +485,7 @@ void Phreeqc::set_phast(int tf) } size_t Phreeqc::list_components(std::list &list_c) /* - * Find all elements in any class definition + * Find all elements in any class definition */ { cxxNameDouble accumulator; @@ -562,12 +563,12 @@ size_t Phreeqc::list_components(std::list &list_c) { if (it->first == "Charge") continue; char string[MAX_LENGTH]; - strcpy(string, it->first.c_str()); + strcpy(string, it->first.c_str()); struct master *master_ptr = master_bsearch_primary(string); if (master_ptr == NULL) continue; if (master_ptr->type != AQ) continue; //std::string name(master_ptr->elt->name); - //char + //char accumulator.add(master_ptr->elt->name, 1); } // print list @@ -610,106 +611,106 @@ void Phreeqc::init(void) #else inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); #endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; negative_concentrations = FALSE; LOG_10 = log(10.0); - max_solution = MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; + max_solution = MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; max_s_s_assemblage = MAX_PP_ASSEMBLAGE; - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_strings = MAX_STRINGS; - max_trxn = MAX_TRXN; - max_logk = MAX_S; + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; max_master_isotope = MAX_ELTS; - count_solution = 0; - count_pp_assemblage = 0; - count_exchange = 0; - count_surface = 0; - count_gas_phase = 0; - count_kinetics = 0; + count_solution = 0; + count_pp_assemblage = 0; + count_exchange = 0; + count_surface = 0; + count_gas_phase = 0; + count_kinetics = 0; count_s_s_assemblage = 0; - count_elements = 0; - count_irrev = 0; - count_master = 0; - count_mix = 0; - count_phases = 0; - count_s = 0; - count_temperature = 0; - count_logk = 0; + count_elements = 0; + count_irrev = 0; + count_master = 0; + count_mix = 0; + count_phases = 0; + count_s = 0; + count_temperature = 0; + count_logk = 0; count_master_isotope = 0; /* - * Initialize advection + * Initialize advection */ - count_ad_cells = 1; - count_ad_shifts = 1; + count_ad_cells = 1; + count_ad_shifts = 1; print_ad_modulus = 1; punch_ad_modulus = 1; - advection_punch = 0; - advection_kin_time = 0.0; + advection_punch = 0; + advection_kin_time = 0.0; advection_kin_time_defined = FALSE; - advection_print = 0; - advection_warnings = TRUE; + advection_print = 0; + advection_warnings = TRUE; /* - * Initialize transport + * Initialize transport */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; interlayer_Dflag = FALSE; interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; -/* !!!! count_stag = 0; */ - mcd_substeps = 1.0; - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; + interlayer_Dpor = 0.1; +/* !!!! count_stag = 0; */ + mcd_substeps = 1.0; + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; transport_warnings = TRUE; - pp_assemblage = 0; - exchange = 0; - surface = 0; - gas_phase = 0; - kinetics = 0; + pp_assemblage = 0; + exchange = 0; + surface = 0; + gas_phase = 0; + kinetics = 0; s_s_assemblage = 0; - cell_data = 0; - elements = 0; - elt_list = 0; + cell_data = 0; + elements = 0; + elt_list = 0; - inverse = 0; + inverse = 0; count_inverse = 0; irrev = 0; @@ -721,7 +722,7 @@ void Phreeqc::init(void) mb_unknowns = 0; - mix = 0; + mix = 0; count_mix = 0; /* !!!! */ stag_data = 0; @@ -740,70 +741,70 @@ void Phreeqc::init(void) temperature = 0; - title_x = NULL; - pe_x = NULL; + title_x = NULL; + pe_x = NULL; description_x = NULL; - units_x = NULL; - s_x = NULL; + units_x = NULL; + s_x = NULL; - sum_mb1 = NULL; - sum_mb2 = NULL; + sum_mb1 = NULL; + sum_mb2 = NULL; sum_jacob0 = NULL; sum_jacob1 = NULL; sum_jacob2 = NULL; - sum_delta = NULL; + sum_delta = NULL; isotopes_x = 0; - x = NULL; + x = NULL; max_unknowns = 0; - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; - logk_hash_table = 0; + logk_hash_table = 0; master_isotope_hash_table = 0; - strings_hash_table = 0; - elements_hash_table = 0; - species_hash_table = 0; - phases_hash_table = 0; - keyword_hash_table = 0; + strings_hash_table = 0; + elements_hash_table = 0; + species_hash_table = 0; + phases_hash_table = 0; + keyword_hash_table = 0; /* - * Initialize use pointers + * Initialize use pointers */ - use.solution_in = FALSE; + use.solution_in = FALSE; use.pp_assemblage_in = FALSE; - use.mix_in = FALSE; - use.irrev_in = FALSE; + use.mix_in = FALSE; + use.irrev_in = FALSE; /* - * Initialize punch + * Initialize punch */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; punch.count_molalities = 0; - punch.molalities = 0; + punch.molalities = 0; punch.count_activities = 0; - punch.activities = 0; + punch.activities = 0; punch.count_pure_phases = 0; punch.pure_phases = 0; - punch.count_si = 0; + punch.count_si = 0; - punch.si = 0; + punch.si = 0; punch.count_gases = 0; - punch.gases = 0; + punch.gases = 0; punch.count_s_s = 0; punch.s_s = 0; @@ -811,52 +812,52 @@ void Phreeqc::init(void) punch.kinetics = 0; punch.count_isotopes = 0; - punch.isotopes = 0; + punch.isotopes = 0; punch.count_calculate_values = 0; - punch.calculate_values = 0; + punch.calculate_values = 0; count_save_values = 0; - save_values = 0; + save_values = 0; punch.inverse = TRUE; - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; punch.high_precision = FALSE; - punch.user_punch = TRUE; + punch.user_punch = TRUE; punch.charge_balance = FALSE; - punch.percent_error = FALSE; + punch.percent_error = FALSE; /* - * last model + * last model */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; + last_model.exchange = NULL; + last_model.gas_phase = NULL; last_model.s_s_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; last_model.surface_charge = NULL; /* - * Update hash table + * Update hash table */ keyword_hash = 0; /* - * rates + * rates */ rates = 0; count_rates = 0; @@ -872,7 +873,7 @@ void Phreeqc::init(void) initial_total_time = 0; /* - * user_print, user_punch + * user_print, user_punch */ user_print = 0; user_punch = 0; @@ -880,14 +881,14 @@ void Phreeqc::init(void) user_punch_count_headings = 0; #ifdef PHREEQ98 /* - * user_graph + * user_graph */ - user_graph = 0; - user_graph_headings = 0 + user_graph = 0; + user_graph_headings = 0 user_graph_count_headings = 0; #endif /* - Initialize llnl aqueous model parameters + Initialize llnl aqueous model parameters */ llnl_temp = 0; llnl_count_temp = 0; @@ -908,7 +909,7 @@ void Phreeqc::init(void) */ command_hash_table = 0; - change_surf = 0; + change_surf = 0; change_surf_count = 0; @@ -916,26 +917,26 @@ void Phreeqc::init(void) /* SRC pr.status = FALSE; */ #endif /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; + pr.all = TRUE; + pr.initial_solutions = TRUE; pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; if (phast == TRUE) { pr.status = FALSE; @@ -944,27 +945,27 @@ void Phreeqc::init(void) { pr.status = TRUE; } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; species_list = NULL; - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; selected_output_file_name = NULL; - dump_file_name = NULL; + dump_file_name = NULL; /* calculate_value */ max_calculate_value = MAX_ELTS; @@ -987,26 +988,26 @@ void Phreeqc::init(void) phreeqc_mpi_myself = 0; - copy_solution.n_user = copy_solution.start = copy_solution.end = 0; - copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; - copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; - copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; - copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; - copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; - copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; - copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; set_forward_output_to_log(FALSE); simulation = 0; /* - * cvode + * cvode */ cvode_init(); /* - * Pitzer + * Pitzer */ pitzer_model = FALSE; max_pitz_param = 100; @@ -1029,41 +1030,41 @@ void Phreeqc::init(void) /* - * SIT + * SIT */ - sit_model = FALSE; - max_sit_param = 100; + sit_model = FALSE; + max_sit_param = 100; count_sit_param = 0; - sit_params = 0; + sit_params = 0; /* * to facilitate debuging */ - dbg_use = &use; - dbg_solution = solution; - dbg_exchange = exchange; - dbg_surface = surface; + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; - dbg_irrev = irrev; - dbg_mix = mix; - dbg_master = master; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + dbg_master = master; calculating_deriv = FALSE; - numerical_deriv = FALSE; + numerical_deriv = FALSE; - zeros = 0; + zeros = 0; zeros_max = 1; cell_pore_volume = 0; - cell_volume = 0; - cell_porosity = 0; - cell_saturation = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; charge_group = NULL; print_density = 0; - // - // Non-class statics + // + // Non-class statics // /* basic.c */ n_user_punch_index = 0; @@ -1258,4 +1259,5 @@ void Phreeqc::pop_cookie() delete this->cookie_list.front(); this->cookie_list.pop_front(); } -} \ No newline at end of file +} + From 5ac33b0f30c6a525194d2da8172ec562c998804f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 29 Dec 2010 01:33:27 +0000 Subject: [PATCH 0192/1077] Cleaned up some more memory leaks reported by Intel Inspector XE 2011 (Kinneburgh) git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5005 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 3db1273e..e62f5651 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -463,6 +463,7 @@ Phreeqc::~Phreeqc(void) { iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); } + delete[] iso_defaults; for (i = 0; i < NKEYS; i++) { keyword[i].name = (char *) free_check_null((void *) keyword[i].name); @@ -474,6 +475,8 @@ Phreeqc::~Phreeqc(void) } delete[] command; + delete[] output_callbacks; + free_check_null(default_data_base); PHRQ_free_all(); From 89f399c2c0d3154ca11d5f3750b92ed9b43b0ef6 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 29 Dec 2010 22:56:03 +0000 Subject: [PATCH 0193/1077] fixed uninitialized variables punch.new_def, status_timer, count_strings; Changed #include "time.h" to #include git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5013 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e62f5651..25724e0b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1229,6 +1229,8 @@ void Phreeqc::init(void) /* model.c */ gas_in = FALSE; + count_strings = 0; + this->clear_cookie(); return; From 8ad0987b85211fb6a7206ed6c0064074b7c7a3a6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 18 Feb 2011 01:17:54 +0000 Subject: [PATCH 0194/1077] Added ndiff option git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5144 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f84b78d6..24826648 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,8 @@ INVERSE_CL1MP=TRUE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o - CL1MP_LIB=-lgmp +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif # ----------------------------------------------------------------------------- @@ -556,8 +557,6 @@ dependencies: cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.c tester: -# cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) -# cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make zero; make diff $(SPOOL) diff.out $(SPOOL2) cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest From cb4073bbc49623052c56faa0c9d80dc3da75313b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 24 Feb 2011 00:41:37 +0000 Subject: [PATCH 0195/1077] Added Tony's ceil and floor Basic Functions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5171 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 25724e0b..3ca5f2a8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -199,6 +199,8 @@ Phreeqc::Phreeqc(void) {"mod", tokmod}, {"sqr", toksqr}, {"sqrt", toksqrt}, + {"ceil", tokceil}, + {"floor", tokfloor}, {"sin", toksin}, {"cos", tokcos}, {"tan", toktan}, From 4419cb427d88547301aaa9fa915ca7daa05948e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 22 Mar 2011 13:31:11 +0000 Subject: [PATCH 0196/1077] Changed output to output_file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5220 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 3ca5f2a8..6a018c81 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -21,7 +21,7 @@ Phreeqc::Phreeqc(void) phast = FALSE; s_pTail = NULL; user_database = NULL; - output = NULL; + output_file = NULL; log_file = NULL; punch_file = NULL; dump_file = NULL; From e746bb8e0769e70bdd1224d7f7fd7209ae04a56e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Mar 2011 19:21:36 +0000 Subject: [PATCH 0197/1077] Added code to adjust activities of master species in solution when totals are adjusted by SOLUTION_MODIFY. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5270 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + ReadClass.cxx | 100 +++++++++++++++++++++++++++++++++++++ Solution.cxx | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++ Solution.h | 5 ++ 4 files changed, 242 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index aafe3662..3acd0793 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1082,6 +1082,7 @@ int master_delete(char *ptr); public: struct master *master_bsearch(const char *ptr); struct master *master_bsearch_primary(char *ptr); +struct master *master_bsearch_secondary(char *ptr); private: struct master *master_search(char *ptr, int *n); struct mix *mix_bsearch(int k, int *n); diff --git a/ReadClass.cxx b/ReadClass.cxx index e830e241..6ccbea34 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1155,6 +1155,7 @@ read_run_cells(void) if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER read_solution_modify(void) @@ -1244,6 +1245,105 @@ read_solution_modify(void) if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } +#endif +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER +read_solution_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution_modify data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + + // find solution 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 solution number following SOLUTION_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + + if (solution_bsearch(n_user, &n, FALSE) == NULL) + { + input_error++; + sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n", n_user); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + cxxSolution sol(solution[n]); + + // Clear activities so we can know what was read + sol.clear_master_activity(); + + sol.read_raw(PHREEQC_THIS_COMMA parser, false); + + cxxSolution orig(solution[n]); + + sol.modify_activities(PHREEQC_THIS_COMMA orig); + + struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); + + /* + * This is not quite right, may not produce sort order, forced sort + */ + + solution_free(solution[n]); + solution[n] = soln_ptr; + + // Need to output the next keyword + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} + /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER read_equilibrium_phases_modify(void) diff --git a/Solution.cxx b/Solution.cxx index e98aa572..b722f6ab 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1545,7 +1545,143 @@ cxxSolution::set_master_activity(char *string, double d) { this->master_activity[string] = d; } +void +cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original) +// +// Estimate activities after solution_modify +// +{ + // Note: any master_activities in "this" have been read in SOLUTION_MODIFY + // to standardize, convert element to valence state if needed + // for original activity list (probably not needed) + cxxNameDouble orig_master_activity(original.get_master_activity()); + cxxNameDouble::const_iterator it; + bool redo=true; + while (redo) + { + redo = false; + for (it = orig_master_activity.begin(); it != orig_master_activity.end(); it++) + { + struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); + if (master_ptr != NULL) + { + if (master_ptr->primary == TRUE) + { + struct master *master_ptr_secondary = P_INSTANCE_POINTER master_bsearch_secondary(master_ptr->elt->name); + + // redox element erase and replace + if (master_ptr_secondary != master_ptr) + { + double d = it->second; + orig_master_activity.erase(orig_master_activity.find(master_ptr->elt->name)); + orig_master_activity[master_ptr_secondary->elt->name] = d; + redo = true; + break; + } + } + } + else + { + P_INSTANCE_POINTER error_msg("Could not find master species in modify_activities.", STOP); + } + } + } + + // also for modified activity list + cxxNameDouble mod_master_activity(this->master_activity); + redo=true; + while (redo) + { + redo = false; + for (it = mod_master_activity.begin(); it != mod_master_activity.end(); it++) + { + struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); + if (master_ptr != NULL) + { + if (master_ptr->primary == TRUE) + { + struct master *master_ptr_secondary = P_INSTANCE_POINTER master_bsearch_secondary(master_ptr->elt->name); + + // redox element erase and replace + if (master_ptr_secondary != master_ptr) + { + double d = it->second; + mod_master_activity.erase(mod_master_activity.find(master_ptr->elt->name)); + mod_master_activity[master_ptr_secondary->elt->name] = d; + redo = true; + break; + } + } + } + else + { + P_INSTANCE_POINTER error_msg("Could not find master species in modify_activities.", STOP); + } + } + } + + // go through totals + double d = 0.0; + for (it = this->totals.begin(); it != this->totals.end(); ++it) + { + // find element name + struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); + char * ename = master_ptr->elt->primary->elt->name; + char * secondary_name; + if (master_ptr->primary == TRUE) + { + struct master *m_ptr = P_INSTANCE_POINTER master_bsearch_secondary(ename); + secondary_name = m_ptr->elt->name; + } + else + { + secondary_name = master_ptr->elt->name; + } + + double d_mod, d_orig; + d_mod = this->get_total_element(ename); + if (d_mod <= 0) continue; + + d_orig = original.get_total_element(ename); + if (d_orig <= 0) + { + // add estimate for la based on concentration if not in list + if (mod_master_activity.find(secondary_name) == mod_master_activity.end()) + { + mod_master_activity[secondary_name] = log10(d_mod) - 2.0; + } + continue; + } + + // case where total for both orig and modified are greater than 0 + double lratio = log10(d_mod / d_orig); + + if (mod_master_activity.find(secondary_name) == mod_master_activity.end()) + { + cxxNameDouble::const_iterator it1; + it1 = orig_master_activity.find(secondary_name); + if (it1 != orig_master_activity.end()) + { + double d = it1->second; + mod_master_activity[secondary_name] = d + lratio; + } + else + // Has total, but no activity, should not happen + { + mod_master_activity[secondary_name] = log10(d_mod) - 2.0; + } + } + } + + // merge activities + this->master_activity = orig_master_activity; + + for (it = mod_master_activity.begin(); it != mod_master_activity.end(); it++) + { + this->master_activity[it->first] = it->second; + } +} //#include "ISolution.h" //#include "Exchange.h" //#include "Surface.h" diff --git a/Solution.h b/Solution.h index 4b7235ba..eb16c6f5 100644 --- a/Solution.h +++ b/Solution.h @@ -132,6 +132,10 @@ class cxxSolution:public cxxNumKeyword { this->totals.clear(); } + void clear_master_activity() + { + this->master_activity.clear(); + } const cxxNameDouble & get_master_activity(void) const { @@ -154,6 +158,7 @@ class cxxSolution:public cxxNumKeyword void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); void multiply(double extensive); + void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); #ifdef ORCHESTRA void ORCH_write(std::ostream & headings, std::ostream & input_data) const; void ORCH_read(std::vector < std::pair < std::string, From 1e8147c06eefc7781272f123ced1f2d0320eca73 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Mar 2011 20:11:50 +0000 Subject: [PATCH 0198/1077] Added note on automatic modification of activities after SOLUTION_MODIFY. Updating modifyact files for Linux. Unused variable in Solution.cxx. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5272 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index b722f6ab..fdc7ddc2 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1622,7 +1622,6 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina } // go through totals - double d = 0.0; for (it = this->totals.begin(); it != this->totals.end(); ++it) { // find element name From 16c2689a8a1c8c8918590b2d354df42082fd9d10 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 Mar 2011 17:15:59 +0000 Subject: [PATCH 0199/1077] Fixed adjustments of activities after solution_modify. Better treatment of redox states; bug in get_total_element. Rewrote error.inp printout. Rewrote cxxStorageBin constructor from use structure. Added reaction, temperature, and mix to StorageBin dump_raw. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5281 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 +- Solution.cxx | 54 ++++++++++++---------- StorageBin.cxx | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 3 +- 4 files changed, 153 insertions(+), 27 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 3acd0793..6e1adf21 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1027,7 +1027,6 @@ int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, int n_user_end, char *description); public: int gas_phase_free(struct gas_phase *gas_phase_ptr); -private: int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, int n_user_new); struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, @@ -1083,7 +1082,7 @@ public: struct master *master_bsearch(const char *ptr); struct master *master_bsearch_primary(char *ptr); struct master *master_bsearch_secondary(char *ptr); -private: +//private: struct master *master_search(char *ptr, int *n); struct mix *mix_bsearch(int k, int *n); int mix_copy(struct mix *mix_old_ptr, @@ -1215,7 +1214,6 @@ int surface_delete(int n_user_old); int surface_duplicate(int n_user_old, int n_user_new); public: int surface_free(struct surface *surface_ptr); -protected: int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, char *description); int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); diff --git a/Solution.cxx b/Solution.cxx index fdc7ddc2..33cdc1c6 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -987,17 +987,6 @@ cxxSolution::get_total_element(char *string) const double d = 0.0; for (it = this->totals.begin(); it != this->totals.end(); ++it) { - char token[MAX_LENGTH]; - if (it->first[0] == string[0]) - { - strcpy(token, it->first.c_str()); - CLASS_QUALIFIER replace("(", "\0", token); - if (strcmp(token, string) == 0) - { - d += it->second; - } - } -#ifdef SKIP // C++ way to do it std::string ename(string); std::string current_ename(it->first); @@ -1011,7 +1000,6 @@ cxxSolution::get_total_element(char *string) const { d += it->second; } -#endif } return (d); } @@ -1626,6 +1614,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina { // find element name struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); + struct master *master_primary_ptr = master_ptr->elt->primary; char * ename = master_ptr->elt->primary->elt->name; char * secondary_name; if (master_ptr->primary == TRUE) @@ -1637,6 +1626,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina { secondary_name = master_ptr->elt->name; } + if (strcmp(ename, "H") == 0 || strcmp(ename, "O") == 0) continue; double d_mod, d_orig; d_mod = this->get_total_element(ename); @@ -1656,19 +1646,37 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina // case where total for both orig and modified are greater than 0 double lratio = log10(d_mod / d_orig); - if (mod_master_activity.find(secondary_name) == mod_master_activity.end()) + int j; + j = master_primary_ptr->number; + int j_first = j + 1; + int j_last = P_INSTANCE_POINTER count_master; + + // non redox element + if ( (j+1 >= P_INSTANCE_POINTER count_master) || (P_INSTANCE_POINTER master[j+1]->elt->primary != master_primary_ptr) ) { - cxxNameDouble::const_iterator it1; - it1 = orig_master_activity.find(secondary_name); - if (it1 != orig_master_activity.end()) + j_first = j; + j_last = j+1; + } + + for (j = j_first ; j < j_last; j++) + { + if (P_INSTANCE_POINTER master[j]->elt->primary != master_primary_ptr) break; + + if (mod_master_activity.find(P_INSTANCE_POINTER master[j]->elt->name) == mod_master_activity.end()) { - double d = it1->second; - mod_master_activity[secondary_name] = d + lratio; - } - else - // Has total, but no activity, should not happen - { - mod_master_activity[secondary_name] = log10(d_mod) - 2.0; + // has not been defined in SOLUTION_MODIFY + cxxNameDouble::const_iterator it1; + it1 = orig_master_activity.find(P_INSTANCE_POINTER master[j]->elt->name); + if (it1 != orig_master_activity.end()) + { + double d = it1->second; + mod_master_activity[P_INSTANCE_POINTER master[j]->elt->name] = d + lratio; + } + else + // Has total, but no activity, should not happen + { + mod_master_activity[P_INSTANCE_POINTER master[j]->elt->name] = log10(d_mod) - 2.0; + } } } } diff --git a/StorageBin.cxx b/StorageBin.cxx index 53ccdfa4..f810091f 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -45,6 +45,7 @@ cxxStorageBin::cxxStorageBin() { // default constructor for cxxStorageBin } +#ifdef SKIP cxxStorageBin::cxxStorageBin(struct Use *use_ptr) { //Construct from use pointer @@ -112,6 +113,115 @@ cxxStorageBin::cxxStorageBin(struct Use *use_ptr) // set system this->setSystem(use_ptr); } +#endif +cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr) +{ + //Construct from use pointer + + int n; + if (use_ptr->mix_in == TRUE) + { + struct mix *struct_entity = P_INSTANCE_POINTER mix_bsearch(use_ptr->n_mix_user, &n); + if (struct_entity != NULL) + { + cxxMix entity(struct_entity); + this->setMix(use_ptr->n_mix_user, &entity); + + std::map c = *(this->getMix(use_ptr->n_mix_user)->comps()); + std::map::iterator it; + for (it = c.begin(); it != c.end(); it++) + { + struct solution *struct_entity1 = P_INSTANCE_POINTER solution_bsearch(it->first, &n, FALSE); + if (struct_entity1 != NULL) + { + cxxSolution entity1(struct_entity1); + this->setSolution(it->first, &entity1); + } + } + } + } + else if (use_ptr->solution_in == TRUE) + { + struct solution *struct_entity = P_INSTANCE_POINTER solution_bsearch(use_ptr->n_solution_user, &n, FALSE); + if (struct_entity != NULL) + { + cxxSolution entity(struct_entity); + this->setSolution(use_ptr->n_solution_user, &entity); + } + } + if (use_ptr->pp_assemblage_in == TRUE) + { + struct pp_assemblage *struct_entity = P_INSTANCE_POINTER pp_assemblage_bsearch(use_ptr->n_pp_assemblage_user, &n); + if (struct_entity != NULL) + { + cxxPPassemblage entity(struct_entity); + this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); + } + } + if (use_ptr->exchange_in == TRUE) + { + struct exchange *struct_entity = P_INSTANCE_POINTER exchange_bsearch(use_ptr->n_exchange_user, &n); + if (struct_entity != NULL) + { + cxxExchange entity(struct_entity); + this->setExchange(use_ptr->n_exchange_user, &entity); + } + } + if (use_ptr->surface_in == TRUE) + { + struct surface *struct_entity = P_INSTANCE_POINTER surface_bsearch(use_ptr->n_surface_user, &n); + if (struct_entity != NULL) + { + cxxSurface entity(struct_entity); + this->setSurface(use_ptr->n_surface_user, &entity); + } + } + if (use_ptr->gas_phase_in == TRUE) + { + struct gas_phase *struct_entity = P_INSTANCE_POINTER gas_phase_bsearch(use_ptr->n_gas_phase_user, &n); + if (struct_entity != NULL) + { + cxxGasPhase entity(struct_entity); + this->setGasPhase(use_ptr->n_gas_phase_user, &entity); + } + } + if (use_ptr->s_s_assemblage_in == TRUE) + { + struct s_s_assemblage *struct_entity = P_INSTANCE_POINTER s_s_assemblage_bsearch(use_ptr->n_s_s_assemblage_user, &n); + if (struct_entity != NULL) + { + cxxSSassemblage entity(struct_entity); + this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); + } + } + if (use_ptr->kinetics_in == TRUE) + { + struct kinetics *struct_entity = P_INSTANCE_POINTER kinetics_bsearch(use_ptr->n_kinetics_user, &n); + if (struct_entity != NULL) + { + cxxKinetics entity(struct_entity); + this->setKinetics(use_ptr->n_kinetics_user, &entity); + } + } + if (use_ptr->irrev_in == TRUE) + { + struct irrev *struct_entity = P_INSTANCE_POINTER irrev_bsearch(use_ptr->n_irrev_user, &n); + if (struct_entity != NULL) + { + cxxReaction entity(struct_entity); + this->setReaction(use_ptr->n_irrev_user, &entity); + } + } + if (use_ptr->temperature_in == TRUE) + { + struct temperature *struct_entity = P_INSTANCE_POINTER temperature_bsearch(use_ptr->n_temperature_user, &n); + if (struct_entity != NULL) + { + cxxTemperature entity(struct_entity); + this->setTemperature(use_ptr->n_temperature_user, &entity); + } + } +} cxxStorageBin::~cxxStorageBin() { @@ -507,6 +617,15 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const // Surface Utilities::dump_raw(Surfaces, s_oss, indent); + + // Mix + Utilities::dump_raw(Mixes, s_oss, indent); + + // Reactions + Utilities::dump_raw(Reactions, s_oss, indent); + + // Temperature + Utilities::dump_raw(Temperatures, s_oss, indent); } void diff --git a/StorageBin.h b/StorageBin.h index d72814d8..af1d3ada 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -22,7 +22,8 @@ class cxxStorageBin public: cxxStorageBin(); - cxxStorageBin(struct Use *use_ptr); + //cxxStorageBin(struct Use *use_ptr); + cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr); ~cxxStorageBin(); void import_phreeqc(PHREEQC_PTR_ARG); From 27bc1114fc9f53f3b007822be193f075e277d184 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 31 Mar 2011 22:10:25 +0000 Subject: [PATCH 0200/1077] removed old revisions from phreeqcpp/src git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5284 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- revisions | 1401 ----------------------------------------------------- 1 file changed, 1401 deletions(-) delete mode 100644 revisions diff --git a/revisions b/revisions deleted file mode 100644 index 821702ef..00000000 --- a/revisions +++ /dev/null @@ -1,1401 +0,0 @@ ------------------------------------------------------------- -Features not documented in WRIR 99-4259. ------------------------------------------------------------- - - svn 675: - Added PRINT option to print the species that contribute - to alkalinity. Alkalinity distribution is printed in - the output file following the distribution of species. - Default at program startup is false. - - PRINT - -alkalinity true - ------------------------------------------------------------- -Version 2.12: ------------------------------------------------------------- - -* Made aqueous activity coefficients the default activity - coefficients for exchange species when using the - Pitzer formulation. New option in EXCHANGE is - -pitzer_exchange_gammas T/F, default is true; - defining "false" sets exchange activity coefficients - to 1.0. Option has no effect for ion-association - model (non-Pitzer). - - -* Added multiplier format to REACTION steps and KINETICS steps, - which simplifies definition of multiple equal reaction increments. - - This definition: - - INCREMENTAL_REACTIONS true - REACTION - H2O 1 - -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles - - is equivalent to this definition: - - INCREMENTAL_REACTIONS true - REACTION - H2O 1 - -36 -4 -4 -4 -.25 -.25 -0.19 -0.1 -0.1 -0.1 - -0.1 -0.05 -0.05 -0.05 moles - - - -* Added Pitzer activity formulation. Use pitzer.dat database - to invoke the Pitzer model. Should have same capabilities - as ion-association model except explicit diffuse layer - calculation is not implemented with the Pitzer model. - New keyword is PITZER with following options: - - PITZER - -MacInnes T/F # uses MacInnes assumption or unscaled for - # individual activities and activity coefficients - -B0 - Na+ Cl- 0.0765 -777.03 -4.4706 0.008946 -3.3158E-6 - -B1 - Na+ Cl- 0.2664 0 0 6.1608E-5 1.0715E-6 - -B2 - Mg+2 SO4-2 -37.23 0 0 -0.253 - -C0 - Na+ Cl- 0.00127 33.317 0.09421 -4.655E-5 - -THETA - K+ Na+ -0.012 - -LAMDA - Na+ CO2 0.1 - -ZETA - H+ Cl- B(OH)3 -0.0102 - -PSI - Na+ K+ Cl- -0.0018 - - A five-term expression for temperature dependence is available - for all Pitzer parameter values: - P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3/(TK-TR) + - A4*(TK*TK - TR*TR), - where TK is Kelvin and TR is 298.15. - -* Cl1mp is a new multiple precision version of routine cl1, - a simplex-based optimization routine. Cl1mp was develeped - by using the Gnu Multiple Precision package (gmp). - Calculations are carried out to about 30 significant - digits. Cl1mp may help in some situations where roundoff - errors are a problem, but it is still possible that roundoff - errors will cause cl1mp to fail to find a solution to an - optimization problem. The mp version has the following - options in INVERSE_MODELING: - - -multiple_precision T/F--causes the mp version - to be used in inverse modeling calculations. - -mp_tolerance 1e-12--tolerance for mp version of - cl1. As in cl1, numbers less than the - tolerance are considered to be zero. - 1e-12 is the default. - -censor_mp 1e-20--as calculations occur in the - linear equation array, elements less - than this value are set to zero. Default - is 1e-20. A value of 0.0 causes no - censoring to occur. - ------------------------------------------------------------- -Version 2.11: ------------------------------------------------------------- - -* A new database, minteq.v4.dat, has been translated from - version 4.02 of MINTEQA2 and is included in all - distributions. The database minteq.dat from earlier - version of MINTEQA2 has been slightly revised and is - also included. - ------------------------------------------------------------- -Version 2.10: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.9: ------------------------------------------------------------- -* Added new keyword COPY that allows a data entity - to be copied from one index to a new index - or to a range of indicies. Format is - - COPY keyword index index_start[-index_end] - - where keyword may be SOLUTION - EQUILIBRIUM_PHASES - EXCHANGE - GAS_PHASE - KINETICS - MIX - REACTION - REACTION_TEMPERATURE - SOLID_SOLUTION - SURFACE - -* Added new Basic functions - b$ = PAD(a$, 20) pads a$ to a total of 20 characters - with spaces and stores result in b$. PAD returns - a copy of a$ if a$ is more than 20 characters. - i = INSTR(a$, b$) sets i to the character position of - string b$ in a$, 0 in not found. - b$ = LTRIM(a$) trims white space from beginning of - string a$ and stores result in b$. - b$ = RTRIM(a$) trims white space from end of string - a$ and stores result in b$. - b$ = TRIM(a$) trims white space from beginning and - end of string a$ and stores result in b$. - - -* Added new Basic function SYS that calculates the to - total amount of an element in all phases (solution, - equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase). KINETIC reactions are not included. - The function has two forms: (1) one element name as an - argument (variable names are user specified) - - 10 t = SYS("As") - - the function will return the total arsenic in the system. - (2) 5 argumens - - 10 t = SYS("As", count_species, names$, types$, moles) - - will return the total arsenic in the system to tot; count_species-- - the number of species that contain arsenic, including - solution, equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase species; names$--a character array that has the - name of each species; type$--a character array that specifies the - type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. - Diff refers to the amount of the element in the diffuse layer of - a surface when the explicit diffuse layer calculation is used; - moles--an array containing the number of moles of the element in - the species. The sum of moles(i) is equal to tot. - - SYS has several special arguments for the form - SYS("arg", count, names$, types$, values) - arg is one of the options listed below. - count is a single numeric value and is the number of elements - in the following arrays. - name$ is an array of string values. - type$ is an array of string values. - values is an array of numeric values. - - Values of arg: - - elt_name returns total number of moles of element in system. - count is the number of species for the element in - the system, including aqueous, exchange, surface, - equilibrium_phase, solid solution component, and - gas phase "species". - Arrays are filled for each "species"; values are moles. - "elements" returns total number of moles of dissolved elements other - than H and O. - count is number of elements, valence states, - exchangers, and surfaces. - Arrays are filled for each element and valence state, - type is "dis"; exchanger, type is "ex", - and surface, type is "surf". Values are moles. - "phases" returns maximum saturation index of all phases. - count is number of phases in system. - Arrays are filled for each phase; values are - saturation indexes. - "aq" returns sum of moles of all aqueous species. - count is number of aqueous species in system. - Arrays are filled with each aqueous species; - values are moles. - "ex" returns sum of moles of all exchange species. - count is number of exchange species in system. - Arrays are filled with each exchange species; - values are moles. - "surf" returns sum of moles of all surface species. - count is number of surface species in system. - Arrays are filled with each surface species; - values are moles. - "s_s" returns sum of moles of all solid solution components. - count is number of solid solution components in system. - Arrays are filled with each solid solution component; - values are moles. - "gas" returns sum of moles of all gas components. - count is number of gas components in system. - Arrays are filled with each gas component; - values are moles. - -* Added new Basic function, DESCRIPTION, that has the value - defined for the description field of the SOLUTION keyword line. - -* Added alternative ordinary differential equation solver - called CVODE, a set of C routines from the Lawrence - Livermore National Labs. CVODE is part of the SUNDIALS - package. CVODE is used in place of the Runge Kutta method - when "-cvode true" is used within a KINETICS data block. - - KINETICS - -cvode true - ------------------------------------------------------------- -Version 2.8: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.7: ------------------------------------------------------------- -Changed format of selected output file: - Removed quotations surrounding strings in headings. - Removed quotations surrounding strings in state variable. - All fields are 12 or 20 places depending on - -high_precision. - Headings are not truncated even if longer than - specified precision. - For isotopes, missing value is -9999.9 - Selected output is updated each simulation. - If a species or phase is defined - subsequent to the simulation where SELECTED_OUTPUT - was defined it will appear in the selected output - file in the simulation in which it is defined and - in subsequent simulations. - -Added strings for each file, which can be extracted from the - executable file with the "ident" command. - -Fixed null pointer for isotope_ratios if Basic routine - was undefined. - -Fixed problem in C++ if structure name is same as member name. - logk member of logk structure was renamed to log_k. - -Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, - SOLUTION_SPECIES, and SURFACE_SPECIES. - - -add_constant -0.301 - - log K is augmented by the specified constant. - - -Theory and implementation of isotopes in PHREEQC is documented in: - -Thorstenson, D.C., and Parkhurst, D.L., 2002, Calculation of -individual isotope equilibrium constants for implementation in -geochemical models: U.S. Geological Survey Water-Resources -Investigations Report 02-4172, 129 p. - -Added KEYWORDS: - -ISOTOPES - Element - -isotope isotope_name units standard_ratio - -total_is_major T/F (OPTION IS DISABLED!!) - -CALCULATE_VALUES - Name - -start - Basic statements, must have SAVE - -end - -ISOTOPE_RATIOS (for printing) - Name=Calculate_values_name Isotope_name - -ISOTOPE_ALPHAS (for printing) - Name=Calculate_values_name Named_logk=named_expression_name - -Basic functions: - calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES - lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS - lk_phase("name") log10(K) of definition in PHASES - lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES - sum_gas("template","element") Sum of element in gases with specified template - template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases - sum_species("template","element") Sum of element in aqueous, exchange, and surface species with - specified template - sum_s_s("s_s_name","element") Sum of element in a specified solid solution - -PRINT keyword: - -initial_isotopes T/F - -isotope_ratios T/F - -isotope_alphas T/F - -censor_species 1e-8 # omit species from Distribution of Species if less than - # relative minimum of an element or element redox state - # total concentration - -SELECTED_OUTPUT keyword: - -calculate_values name1 name2 ... - -isotopes minor_isotope1 minor_isotope2 .... - -Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic - interpreter. LK_SPECIES("CaHCO3+") returns the - log k for the association reaction for the ion pair - CaHCO3+ at the current temperature. The log K is - for the reaction as defined in the database or - input file. Similarly, - LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the - value for the log K at the current temperature using - expressions defined in NAMED_LOG_K data block; - LK_PHASE("Calcite") returns the value of log K - for calcite at the current temperature for the - dissociation reaction defined in the database or - input file. Values are "log10" values. -Example for Basic program: - 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") - 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") - 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 - -NAMED_EXPRESSION--New keyword data block. - - This data block was implemented to facilitate isotopic - calculations. It allows analytical expressions that - are functions of temperature to be defined. The purpose - is to separate the fractionation factors from the log - K, so that the fractionation factor or its temperature - dependence can be easily modified. The named expression - can be added to a log K for a species or phase by the - -add_logk identifier in SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data - block. Log K, Delta H, and analytical expressions for a - log K can be defined with identifiers -log_k, -delta_h, - and -analytical_expression as described in SOLUTION_SPECIES - in WRIR 99-4259. Fractionation factors are often defined - as 1000*ln(alpha). The identifier -ln_alpha1000 can be used - to enter data in this form. The analytical expression is the - same as defined in SOLUTION_SPECIES, but the result of the - expression is converted to log10(alpha) by dividing by - 1000*ln(10) before it is summed into log K values. - -NAMED_EXPRESSIONS - Log_K_calcite # CaCO3 + 2H3O+ = Ca+2 + 3H2O + CO2 - log_k 8.201 - delta_h -8.035 kcal - -analytic 292.29 0.015455 -24146.841 -94.16451 2248628.9 - - Log_alpha_18O_CO2(aq)/Calcite - -ln_alpha1000 3.8498 0.0 10.611e3 0.0 -1.8034e6 - - Log_alpha_13C_CO2(aq)/Calcite - -ln_alpha1000 2.72 0.0 0.0 0.0 -1.1877e6 - ------------------------------------------------------------- -Added identifier -add_logk to SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, and PHASES data - block. - - Allows a named expression to be added to the definition - of the log K for a species or phase. In the following - example, the log K for the phase Ca[14C][18O]3 is summed from - four parts, one defined with the log_k identifier and the - other three parts from expressions defined in NAMED_EXPRESSIONS. - The named expression is multiplied by the coefficient at the - end of the line before it is summed into the log K. A missing - coefficient is 1.0 by default. - -PHASES - Ca[13C][18O]3 - Ca[13C][18O]3 + 3CO2 + 2H3O+ = Ca+2 + 3H2O + 3CO[18O] + [13C]O2 - log_k 0.903089986991 # 3*log10(2) - -add_logk Log_K_calcite 1.0 - -add_logk Log_alpha_13C_CO2(aq)/Calcite 1.0 - -add_logk Log_alpha_18O_CO2(aq)/Calcite 3.0 - - -SOLUTION keyword: - At present, can only define isotopes in the units defined in ISOTOPES. - ------------------------------------------------------------- -Version 2.6: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.5: ------------------------------------------------------------- -Added the capability to use square brackets to define an - "element" name. The brackets act like quotation marks - in that any character string can be used within the - brackets as an element name. For example, [Fe3], [13C], - and [N5] are now legal "element" names. All element - names without brackets must begin with a capital letter, - followed by zero or more lower case letters and underscores. - -Added identifier -activity_water for a species in SOLUTION_SPECIES - data block. This identifier has been added for future updates - that will allow isotopic calculations. It is intended to be - used only for isotopic variations of H2O, like D2O or - H2[O18]. It forces the activity coefficient for the - species to be activity(water)/55.5. This effectively sets - the activity of the species to the mole fraction in - solution. - -Added identifier -bad_step_max to KINETICS data block. - An integer following -bad_step_max gives the maximum number - of times a rate integration may fail before execution of the - program is terminated. Default is 500. - ------------------------------------------------------------- -Version 2.4: ------------------------------------------------------------- - ------------------------------------------------------------- -Added identifier -warnings to PRINT keyword. - - An integer following -warnings gives the maximum number - of warnings to print into the output file. A negative - number allows all warnings to be printed. - - Example: -warnings 20 - ------------------------------------------------------------- -Changed the results of the function CELL_NO in Basic programs. - - Function cell_no in Basic now prints a number equivalent - to -solution in SELECTED_OUTPUT data block. It gives the - solution number for initial solution calculations and the - solution being used in batch reaction calculations. - Result is the same as previous versions for ADVECTION or - TRANSPORT calculations. - ------------------------------------------------------------- -Version 2.3: ------------------------------------------------------------- -DATABASE--New keyword data block - - It must be the first keyword in the input file. - The character string following the keyword is - the pathname for the database file to be used - in the calculation. The file that is specified - takes precedence over any default database - name, including environmental variable - PHREEQC_DATABASE and command line arguments. - -LLNL_AQUEOUS_MODEL_PARAMETERS--New keyword data block - - Added new keyword to make aqueous model similar to - EQ3/6 and Geochemists Workbench when using - llnl.dat as the database file. Values - of Debye-Huckel a and b and bdot (ionic strength - coefficient) are read at fixed temperatures. - Linear interpolation occurs between temperatures. - - New options for SOLUTION_SPECIES are - -llnl_gamma a , where a is the ion-size parameter. - -co2_llnl_gamma , indicates the temperature dependent - function for the bdot term given in - -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS - will be used. Applies to uncharged - species only. - -LLNL_AQUEOUS_MODEL_PARAMETERS --temperatures - 0.0100 25.0000 60.0000 100.0000 - 150.0000 200.0000 250.0000 300.0000 -#debye huckel a (adh) --dh_a - 0.4939 0.5114 0.5465 0.5995 - 0.6855 0.7994 0.9593 1.2180 -#debye huckel b (bdh) --dh_b - 0.3253 0.3288 0.3346 0.3421 - 0.3525 0.3639 0.3766 0.3925 --bdot - 0.0394 0.0410 0.0438 0.0460 - 0.0470 0.0470 0.0340 0.0000 -#cco2 (coefficients for the Drummond (1981) polynomial) --co2_coefs - -1.0312 0.0012806 - 255.9 0.4445 - -0.001606 - ------------------------------------------------------------- -Added function SURF to Basic. - - SURF("element", "surface") gives the amount of element - sorbed on "surface". "surface" should be the surface - name, not the surface-site name (that is, no underscore). - ------------------------------------------------------------- -Allow decimals in definition of secondary master species. - - Some redox states do not average to integers, - for convenience in identifying them, decimal numbers - may be used within the parentheses that define the - redox state, example S(0.3) could be used in the - MASTER_SPECIES data block for the valence state of - aqueous species S6-2. - ------------------------------------------------------------- -Eliminate echo of input file in PRINT data block. - - -echo_input T/F turns echoing on and off. - Default is true, initial value is true. - ------------------------------------------------------------- -Added option for an equilibrium-phase to dissolve only. - "dis" is added at the end of a line defining an equilibrium- - phase. No data fields may be omitted. Should not - be used when adding an alternative reaction. - Example: - EQUILIBRIUM_PHASES - Dolomite 0.0 0.001 dis - ------------------------------------------------------------- -Version 2.2: ------------------------------------------------------------- -Added function EDL to Basic. - EDL("element", "surface") gives the amount of - element in the diffuse layer for "surface", not - including sorbed species. "surface" should be - the surface name, not the surface-site name - (that is, no underscore). - - Special values for "element" include: - "charge" - gives surface charge, equivalents. - "sigma" - surface charge density, C/m**2. - "psi" - potential at the surface, Volts. - "water" - mass of water in the diffuse layer, kg. - ------------------------------------------------------------- -End of Features not documented in WRIR 99-4259. ------------------------------------------------------------- - ------------------------------------------------------------- -Revisions and bug fixes ------------------------------------------------------------- - svn 675: - Added PRINT option to print the species that contribute - to alkalinity. Alkalinity distribution is printed in - the output file following the distribution of species. - Default at program startup is false. - - PRINT - -alkalinity true - - svn 655: - IAP and log K printed in Phase assemblage data - block were calculated from reactions rewritten to - new master species. Now the original data base - reaction is used to calculate IAP and log K. - Also fixed check that ensured all elements of - phase in are in solution before SI is calculated. - - svn 631: - Fixed bug with alternate formula for equilibrium phase, - nothing happened if all other equations were satisfied - at beginning of reaction calculation. - - svn 603: - Link gmp library statically. - - svn 601: - Fixed statement on multiprecision. - - svn 581: - Fixed bug in PhreeqcI that did not reinitialize - Chebyschev parameters leading to incorrect results - with Pitzer activity coefficients. Results were - correct on first run, but erroneous on subsequent - runs. - - Added statement to identify multiprecision or - standard solver for inverse modeling. - - svn 578: - - Distribution changes. Fixed names in README file. - Modified Makefile to use specified version. Split - Linux and source distribution procedure. - -Version 2.12 Date: Wed September 28, 2005 - - Executables and output files for Sun operating systems - are no longer provided. - - Limited log activities of master species to be greater - than the smallest machine precision exponential number. - Avoids a matherr exception and allows trial of additional - parameter sets to attempt to solve the system of - equations. - - Made aqueous activity coefficients the default activity - coefficients for exchange species when using the - Pitzer formulation. New option in EXCHANGE is - -pitzer_exchange_gammas T/F, default is true; - defining "false" sets exchange activity coefficients - to 1.0. Option has no effect for ion-association - model (non-Pitzer). - - Edited phreeqc.dat to add -gamma expression for - CdX2 and PbX2. - - Replaced O2(g) log K in phreeqc.dat and wateq4f.dat - with data from llnl.dat, which appears to be better. - - Added multiplier format to REACTION increments, which - simplifies definition of multiple equal reaction increments. - - REACTION - H2O 1 - -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles - - Added Pitzer activity formulation. Use pizer.dat database - to invoke the Pitzer model. Should have same capabilities - as ion-association model except explicit diffuse layer - calculation is not implemented with the Pitzer model. - - - Fixed bug in surface sites related to mineral and exchange - sites related to mineral. Did not have complete logic to - handle redox valence states in formula for species. - - Modified to remove non standard usage of va_list. - - Removed exchange master species from SYS("ex",..) - list of species. This species is fictive and should - not be included in the list. - - Changed -redox in SOLUTION so that if one of the - redox states of a couple is not defined, then - redox defaults to pe. - - Fixed buffer overrun in PhreeqcI with SOLUTION_SPREAD, - caused segmenatation fault with lines greater than - 500 characters. - - Added bigger string for some error messages to avoid - access violation in cvode. - - Changed output_msg to warning_msg for combinations - of convergence parameters so that message would - be controlled by -warnings identifier. - - Carriage returns are now stripped from Basic program - statements. Switching files from Windows to Unix sometimes - leaves extra carriage returns at the ends of lines, which - caused a syntax error for some Basic commands. - - Two bugs were fixed in inverse modeling. (1) Potential - models are now checked for all equality and inequality - constraints. Previously some constraints were not checked. - (2) One loop of cl1 did not include the last row when - checking for the pivot element. Also printing of headers - was slightly modified for inverse modeling. - - A new multiple precision version of cl1 was develeped by - using the Gnu Multiple Precision package (gmp). Calculations - are carried out to about 30 significant digits. The mp - version may help in some situations where roundoff errors are - a problem, but it is still possible that roundoff errors will - cause cl1mp to fail to find a solution to the optimization - problem. The mp version has the following options in - INVERSE_MODELING: - -multiple_precision T/F--causes the mp version - to be used in inverse modeling calculations. - -mp_tolerance 1e-12--tolerance for mp version of - cl1. As in cl1, numbers less than the - tolerance are considered to be zero. - 1e-12 is the default. - -censor_mp 1e-20--as calculations occur in the - linear equation array, elements less - than this value are set to zero. Default - is 1e-20. A value of 0.0 causes no - censoring to occur. - -Version 2.11 Date: Mon February 7, 2005 - - Fixed error in selected output file with mixing reaction. - MIX number was written to two columns, should be one. - - Fixed memory leak with PAD function. - - New database minteq.v4.dat has been translated from version - 4.02 of MINTEQA2. An older version of the MINTEQA2 database is - retained in file minteq.dat. - - Switched version control to subversion. Simplified, - reorganized makefiles. - - Fixed bug with PRINT; -warnings n. Use of this option - generally eliminated all warning messages instead of - all messages after the nth. Default number of warning - messages printed in now 100 per simulation. - - Fixed memory leaks in cvode that caused phreeqci to crash. - Now uses PHRQ_malloc in case of other memory leaks. Also - fixed potential memory error with PAD Basic function. - - Saturation index phases that included water had wrong - value if distribution of species, exchange, or surface - not written also. - - Fixed error message in cvode, if max iterations exceeded - the error caused a segmentation fault. - - Made printing of parameter combination message a warning - message so that it could be turned off. - -Version 2.10 Date: Tue November 2, 2004 - - Rearranged i/o for PHREEQC and reorganized driver - subroutine. The object of these changes is to make - the program more functional as a module for other - programs (PHAST) and eventually to produce a callable - C and Fortran module. - - Fixed a problem with surface related to a phase, when - phase was not part of system (for example, Fe(OH)3a when - there is no iron in system. - - Added convergence parameter set that requires mineral - transfers to produce positive concentrations in the - event that negative concentrations have been produced in - the prior Newton-Raphson iteration. (Fluorite example). - - Fixed bug with kinetics formulas; did not account for - stoichiometric coefficient correctly when using - phase names. Generalized to allow multiple phase - names in the -formula definition. - -Version 2.9 Date: Wed September 15, 2004 - - In inverse modeling, program terminates if sum of initial - solutions and phases is > 32. - - Fixed bug with isotopes. Log activity estimate after initial - solution calculation was inf under some conditions. An initial - surface calculation failed when using D. - - Changed saturation index print out to use reaction and log K - defined in PHASES definition. Previously, reaction could be - rewritten to predominant redox species. - - Fixed incorrect print of elapsed time for kinetics in advection. - - Added phrqproto.h prototype file and phrqtype.h for - switching compilation to long double. - - Fixed incorrect printout of kinetics delta moles with - advection. - - Added convergence parameter set that skips mineral - equations for first 5 iterations. - - Added entity_exists for module. - - Tried to fix bug with mix index incorrect (-2) for - mixing with kinetics. - - Added new keyword COPY that allows a data entity - to be copied from one index to a new index - or to a range of indicies. Format is - - COPY keyword index index_start[-index_end] - - where keyword is one of the following: - SOLUTION - EQUILIBRIUM_PHASES - EXCHANGE - GAS_PHASE - KINETICS - MIX - REACTION - REACTION_TEMPERATURE - SOLID_SOLUTION - SURFACE - - Numerical method had a bug with ionic strength, if - mass of water was not approximately 1. Routine - revise_guesses did not divide by the mass of - water. Also changed check in routine molalities - to check by molality, not moles. - - Fixed a null pointer when surface was related to a - mineral and mineral was not in database. - - Added new Basic functions - i = INSTR(a$, b$) sets i to the character position of - string b$ in a$, 0 in not found. - b$ = LTRIM(a$) trims white space from beginning of - string a$ and stores result in b$. - b$ = RTRIM(a$) trims white space from end of string - a$ and stores result in b$. - b$ = LTRIM(a$) trims white space from beginning and - end of string a$ and stores result in b$. - - Added new Basic function SYS that calculates the to - total amount of an element in all phases (solution, - equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase). KINETIC reactions are not included. - The function has two forms: (1) one element name as an - argument (variable names are user specified) - - 10 t = SYS("As") - - the function will return the total arsenic in the system. - (2) 5 argumens - - 10 t = SYS("As", count_species, names$, types$, moles) - - will return the total arsenic in the system to tot; count_species-- - the number of species that contain arsenic, including - solution, equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase species; names$--a character array that has the - name of each species; type$--a character array that specifies the - type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. - Diff refers to the amount of the element in the diffuse layer of - a surface when the explicit diffuse layer calculation is used; - moles--an array containing the number of moles of the element in - the species. The sum of moles(i) is equal to tot. - - SYS has several special arguments for the form - SYS("arg", count, names$, types$, values) - arg is one of the options listed below. - count is a single numeric value and is the number of elements - in the following arrays. - name$ is an array of string values. - type$ is an array of string values. - values is an array of numeric values. - - Values of arg: - - elt_name returns total number of moles of element in system. - count is the number of species for the element in - the system, including aqueous, exchange, surface, - equilibrium_phase, solid solution component, and - gas phase "species". - Arrays are filled for each "species"; values are moles. - "elements" returns total number of moles of all elements, - valence states, exchangers, and surfaces. - count is number of elements, valence states, - exchangers, and surfaces. - Arrays are filled for each element, valence state, - exchanger, and surface; values are moles. - "phases" returns maximum saturation index of all phases. - count is number of phases in system. - Arrays are filled for each phase; values are - saturation indexes. - "aq" returns sum of moles of all aqueous species. - count is number of aqueous species in system. - Arrays are filled with each aqueous species; - values are moles. - "ex" returns sum of moles of all exchange species. - count is number of exchange species in system. - Arrays are filled with each exchange species; - values are moles. - "surf" returns sum of moles of all surface species. - count is number of surface species in system. - Arrays are filled with each surface species; - values are moles. - "surf" returns sum of moles of all solid solution components. - count is number of solid solution components in system. - Arrays are filled with each solid solution component; - values are moles. - "gas" returns sum of moles of all gas components. - count is number of gas components in system. - Arrays are filled with each gas component; - values are moles. - - Added new Basic function, DESCRIPTION, that has the value - defined for the description field of the SOLUTION keyword line. - - Added alternative ordinary differential equation solver - called CVODE, a set of C routines from the Lawrence - Livermore National Labs. CVODE is part of the SUNDIALS - package. CVODE is used in place of the Runge Kutta method - when "-cvode true" is used within a KINETICS data block. - - KINETICS - -cvode true - - Fixed error in SOLUTION_SPREAD, defining -redox - did not set the default redox for the solutions - that were defined; pe was always used as default. - - Modified code to allocate space differently for - pp_assemblage, exchange, surface, gas_phase, - kinetics, and s_s_assemblage. Enough space is allocated - at beginning of distribute_initial_conditions. - May speed up phast initialization and make better - use of available memory. - - Changed gfw of water to 18 if isotopes of water are - included. Solvent is [1H]2[16O]. - - Fixed a bug in surface integration where order of ions - in the list of g's was incorrect. - - Pyrite rate was not 0 if supersaturated in phreeqc.dat - and wateq4f.dat - - Segmentation error if a surface species was not - defined with an equation that contained another surface - species. In this case, the surface master species - had been redefined to be an aqueous species (SOLUTION_SPECIES). - -Version 2.8 Date: Tue April 15, 2003 - - Updated arsenic data in wateq4f.dat to be consistent with - Archer and Nordstrom (2002). - - Revised Basic interpreter to allow lines of any length - and character strings of any length. - - Renumbering basic statement that included the function - SURF in PhreeqcI caused SURF to be omitted and generated - a syntax error. SURF and other functions had not been - implemented in PhreeqcI. - - Fixed a bug in the Basic Interpreter. If elements of - a dimensioned variable (character or number) were used on - both sides of an equation, the result was erroneously - stored in the last element of the variable used on the - right-hand side instead of the element specified on the - left-hand side. - - Using comma in some fields caused an infinite loop. - - Fixed bug with SOLUTION_SPREAD, Phreeqc was not - calculating solution numbers for solution_spread - solutions without solution numbers. - - Fixed bug with stagnant zone calculations. If solutions - not defined for stagnant cells, PhreeqcI crashed. - - Added new state for calculations, PHAST. Previously - phast used the state TRANSPORT, which caused some - erroneous results with temperature when TRANSPORT was - used in the PHREEQC part of the calculation. - - Trying to define dump file in TRANSPORT caused a file - opening error. Fixed logic so now can open a file - and the name can include blanks. - -Version 2.7 Date: Fri February 14, 2003 - - Initialized gfw in elements structure. - - Fixed bug where "time" would be wrong for initial - solution calculation. Needed to initialize - rate variables for PhreeqcI. - - Added print of simulation number to error file for - phreeqci - - Limited printing of cell numbers to output file in advection - calculations. Cell numbers only printed if results - for cell are going to be printed. - - PhreeqcI captured status messages for kinetics, which - made a very large error file in some cases and - a long wait to view the output file in PhreeqcI. - Now PhreeqcI does not capture these intermediate - status messages. - - Removed old code related to redirecting error file - - - Corrected error in transport where wrong time step was used - for integration. - - Changes to speed up transport algorithm. - - Allow file names with spaces in selected_output file name and - dump_file name. - - Modifications to work with RC1 phast log file. - - Allow any characters in square brackets for element name. - - and + and perhaps others caused problems before. - - Fixed log molality of water in species printout, was - equal to log activity of water. Also fixed - basic function for LM. - - Changed solid solution prints to print 0 if solid solution - is not present. - - Fixed bug if no rate name was defined before options - in RATES. - - Fixed warning on Mac compilation in fpunchf. - - Fixed bug if isotopes were used but H and O isotopes - were not defined. - - Fixed bug where special initial solution calculations - were done at later calculation stages. - Needed to set initial_solution_isotopes = FALSE; - - Fixed problem in C++ if structure name is same as member name. - logk member of logk structure was renamed to log_k. - - Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, - SOLUTION_SPECIES, and SURFACE_SPECIES. - - -add_constant -0.301 - - log K is augmented by the specified constant. - - - Added punch_isotopes and punch_calculate_values to allow - printing isotope ratios and any CALCULATE_VALUES result. - - Added KEYWORDS: - - ISOTOPES - Element - -isotope isotope_name units standard_ratio - -total_is_major T/F (OPTION IS DISABLED!!) - - CALCULATE_VALUES - Name - -start - Basic statements, must have SAVE - -end - - ISOTOPE_RATIOS (for printing) - Name=Calculate_values_name Isotope_name - - ISOTOPE_ALPHAS (for printing) - Name=Calculate_values_name Named_logk=named_expression_name - - Basic functions: - calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES - lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS - lk_phase("name") log10(K) of definition in PHASES - lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES - sum_gas("template","element") Sum of element in gases with specified template - template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases - sum_species("template","element") Sum of element in aqueous, exchange, and surface species with - specified template - sum_s_s("s_s_name","element") Sum of element in a specified solid solution - - PRINT keyword: - -initial_isotopes T/F - -isotope_ratios T/F - -isotope_alphas T/F - -censor_species 1e-8 # Omits print of species if less than relative criterion - - SELECTED_OUTPUT keyword: - -calculate_values name1 name2 ... - -isotopes minor_isotope1 minor_isotope2 .... - - Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic - interpreter. LK_SPECIES("CaHCO3+") returns the - log k for the association reaction for the ion pair - CaHCO3+ at the current temperature. The log K is - for the reaction as defined in the database or - input file. Similarly, - LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the - value for the log K at the current temperature using - expressions defined in NAMED_LOG_K data block; - LK_PHASE("Calcite") returns the value of log K - for calcite at the current temperature for the - dissociation reaction defined in the database or - input file. Values are "log10" values. - Example for Basic program: - - 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") - 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") - 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 - - Added NAMED_EXPRESSIONS data block. This data block was - implemented to facilitate isotopic calculations. - It allows analytical expressions that are functions - of temperature to be defined. The purpose is to - separate the fractionation factors from the log K, - so that the fractionation factor or its temperature - dependence can be easily modified. The named - expression can be added to a log K for a species - or phase by the -add_logk identifier in SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data - block. - -Version 2.6 Date: Mon April 22, 2002 - - PhreeqcI released. - - All selected_output is routed through a single routine. - - Allow "_" inside square brackets, [A_bcd]. - - Fixed bug match_elts_in_species, check for "e-" was wrong. - - Modified minteq.dat to put CuS4S5-3, Cu(S4)2-3 in - in Cu(1) mole balance equations instead of - Cu(2). Before the change, the program would - not converge if Cu(2) were defined in an - initial solution. - - Made revisions hopefully to improve SOLID_SOLUTIONS - convergence with small numbers of moles of - solids. - - Made changes related to dump file and PhreeqcI. - - Iterations now sums iterations in all kinetics calculations - - Fixed bug with LA("H2O"), which was returning natural log - of activity of water. - - -Version 2.5 Date: Mon October 1, 2001 - In llnl.dat, fixed sign errors in RRE (rare earth elements) - for some redox reactions and removed some redundant - species, generally ReeO2- was retained and Ree(OH)4- - was removed. - - Added the capability to use square brackets to define an - "element" name. The brackets act like quotation marks - in that any character string can be used within the - brackets as an element name. This was introduced to - simplify expansion of the model to isotopic species. - [13C], [14C], and [18O] are legal element names. - - Added identifier -activity_water for a species in - SOLUTION_SPECIES data block. This identifier has been - added for future updates that will allow isotopic - calculations. It is intended to be used only for - isotopic variations of H2O, like D2O or H2[O18]. It - forces the activity coefficient for the species to be - activity(water)/55.5. This effectively sets the activity - of the species to the mole fraction in solution. - - Fixed bug in checking solid solutions for presence or - absence of elements in the system. Programming - error caused segmentation fault if an error - was detected under certain conditions. - - Changed return value of MOL to be molality of water - if argument is "H2O". Also changed return value - of LA to be activity of water if argument is - "H2O". - - Diffuse layer calculation was incorrect if aqueous phase did not - have 1 kilogram of water. Eq. 74 of manual has molality, - but code used moles. The code was corrected by adding - the mass of water to the formulation. - - Stagnant zones with first-order exchange approximation (1 stagnant - cell, exchange factor, and porosities defined) did not work - correctly if mobile and immobile cells did not have equal - volumes of water. The mixing factors were revised to account - for the masses of water in the stagnant and mobile zones. - - A fatal error was erroneously detected if the database file - had a DATABASE data block. DATABASE data block is - now ignored while reading the database file. - - Added identifier -bad_step_max to KINETICS data block. - An integer following -bad_step_max gives the maximum number - of times a rate integration may fail before execution of the - program is terminated. Default is 500. - -Version 2.4.2: Date: Fri June 15, 2001 - Fixed spreadsheet bug. Program was not ignoring columns - that could not be identified as either element - names or allowed data (ph, pe, number, description, - etc). Also, the program failed if a spreadsheet solution - number was negative. - -Version 2.4.1: Date: Mon June 4, 2001 - Fixed spreadsheet bugs with isotopes. - -Version 2.4: Date: Fri June 1, 2001 - - Added structure for spreadsheet for use by PhreeqcI. - - Isotope value initialized incorrectly if only an -uncertainty was - defined in SOLUTION_SPREAD. - - Fixed segmentation violation when primary and secondary master - species were defined improperly. - - Corrected enthalpies of reaction in llnl.dat. Previous release had - erroneously had enthalpies of formation in -delta_H - parameter; the values should be enthalpies of reaction. - Enthalpies of reaction were calculated from the - enthalpies of formation and these values are now included - in the -delta_H parameter. This change will have very - little impact on calculations because the analytical - expression has precedence over -delta_H in calculating - temperature dependence of log K, and nearly all species - and minerals have an analytical expression or lack both - an analytical expression and an enthalpy of reaction. - - Corrected bugs in punch of solid solution components that caused - both selected output and output file errors: moles - were incorrect in selected output, and total moles and - mole fraction were incorrect in output file. - - Added surface complexation constants for Fe+2; two complexes for - weak sites and one complex for strong sites. phreeqc.dat - and wateq4f.dat modified. - - Comment for units of parameters for calcite rate equation was - wrong. Rate equation now uses cm^2/L for area parameter. - Previously the correct units would have been 1/decimeter. - phreeqc.dat and wateq4f.dat modified. - - Fixed a bug when rates were equal within tolerance, but negative - concentrations occurred because of small initial - concentrations. - - Added -warnings to PRINT keyword for specification of maximum - number of warnings to print. Negative number allows - all warnings to be printed. - - Function CELL_NO in Basic now prints a number equivalent to - -solution in SELECTED_OUTPUT data block. This does not - change printing for ADVECTION or TRANSPORT calculations. - - Kinetics time is halved for advective part of reaction in - transport; time incorrectly accounted for before. - - -punch_ identifiers printed -1 instead of the correct solution - number for batch-reaction calculations. - - -high_precision is no longer reset to false with every - SELECTED_OUTPUT data block. - - SELECTED_OUTPUT file name stored for use by PhreeqcI. - - Alkalinity for NH3 corrected to 1.0 in llnl.dat. - - Fixed bug with USER_PRINT of kinetics. Did not find correct - kinetics information in some cases. - - Fixed bug in default values for SOLUTION_SPREAD. Cannot use phase - name and SI for pH or pe, and bug did not allow PHREEQC - to run. Now PHREEQC runs, but warns that this is not - allowed. - -Version 2.3: Date: Tue January 2, 2001 - - Added new keyword DATABASE. It must be the first keyword in - the input file. The character string following the - keyword is the pathname for the database file to - be used in the calculation. The file that is - specified takes precedence over any default - database name, including environmental variable - PHREEQC_DATABASE and command line arguments. - - Fixed bug in SOLUTION_SPREAD. If first heading in - the spread-sheet input was an identifier--pH, - pe, units, etc--then the headings were interpreted - as an identifier and bad things happened. - - Added new keyword to make aqueous model similar to - LLNL and Geochemists Workbench when using - llnl.dat as the database file. Values - of Debye-Huckel a and b and bdot (ionic strength - coefficient) are read at fixed temperatures. - Linear interpolation occurs between temperatures. - - New options for SOLUTION_SPECIES are - -llnl_gamma a , where a is the ion-size parameter. - -co2_llnl_gamma , indicates the temperature dependent - function for the bdot term given in - -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS - will be used. Applies to uncharged - species only. - -LLNL_AQUEOUS_MODEL_PARAMETERS --temperatures - 0.0100 25.0000 60.0000 100.0000 - 150.0000 200.0000 250.0000 300.0000 -#debye huckel a (adh) --dh_a - 0.4939 0.5114 0.5465 0.5995 - 0.6855 0.7994 0.9593 1.2180 -#debye huckel b (bdh) --dh_b - 0.3253 0.3288 0.3346 0.3421 - 0.3525 0.3639 0.3766 0.3925 --bdot - 0.0394 0.0410 0.0438 0.0460 - 0.0470 0.0470 0.0340 0.0000 -#cco2 (coefficients for the Drummond (1981) polynomial) --co2_coefs - -1.0312 0.0012806 - 255.9 0.4445 - -0.001606 - - - Fixed bug in basic interpreter. A number like "..524" would - cause an infinite loop. - - Added function SURF to Basic. - SURF("element", "surface") gives the amount of - element sorbed on "surface". "surface" - should be the surface name, not the - surface-site name (that is, no underscore). - - Fixed option to "runge_kutta" from "runge-kutta" to match - documentation for KINETICS. - - Fixed UO2+2 and Mn+2 reaction stoichiometry for Hfo surface complexation - in wateq4f.dat. - - Added option for an equilibrium-phase to dissolve only. - "dis" is added at the end of a line defining an equilibrium- - phase. No data fields may be omitted. Should not - be used when adding an alternative reaction. - Example: - EQUILIBRIUM_PHASES - Dolomite 0.0 0.001 dis - R-K integration failed when only the final rate generated - negative concentrations. - Allow decimals in definition of secondary master species, for - example S(0.3). - Fixed bug if description was more than about 85 characters; - now allows about 400 characters. - Fixed bug for surface/exchange sites related to phases. Was - checking internal copies of surfaces/exchange with negative - numbers. - Fixed bug in quick prep that did not set the correct pointer - for gas phases. - Fixed segmentation fault that occurred if all elements for - phase-boundary mineral were not in the solution. - Only applied to a phase used to define concentration - in an initial solution calculation. - Added option to eliminate echo of input file in PRINT - data block. -echo_input T/F turns echoing on - and off. Default is on. - - -Release 2.2: Date: Wed March 1, 2000 - - Fixed bug in MIX if no solutions are defined. - Changed printout for surface. - Only gives net surface charge for diffuse layer - calculation. - Prints correct value for the surface charge and - surface charge density for diffuse-layer - calculation. - - Added function EDL to Basic. - EDL("element", "surface") gives the amount of - element in the diffuse layer for "surface". - not including sorbed species. "surface" should - be the surface name, not the surface-site name - (that is, no underscore). - - Special values for "element" include: - "charge" - gives surface charge, equivalents. - "sigma" - surface charge density, C/m**2. - "psi" - potential at the surface, Volts. - "water" - mass of water in the diffuse layer, kg. - Changed distribution to be more consistent with other USGS - water-resources applications. - -Release 2.1: Date: Wed January 19, 2000 - - Added additional #ifdef's for PhreeqcI. - Fixed problem with formats for USER_PUNCH and - others with Microsoft C++ 3 digit - exponents. - -Initial Release 2.0: Date: Wed December 15, 1999 - -Version: C_54 = Version 2.0 - From 13910c9bf202ac9f273f4279bad8f45fcc87d289 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 31 Mar 2011 22:15:33 +0000 Subject: [PATCH 0201/1077] moved and renamed revisions to src/PHREEQCPP-RELEASE.txt git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5285 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHREEQCPP-RELEASE.txt | 645 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 PHREEQCPP-RELEASE.txt diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt new file mode 100644 index 00000000..da0fb194 --- /dev/null +++ b/PHREEQCPP-RELEASE.txt @@ -0,0 +1,645 @@ +File contains: + "Features in PHREEQC++ Not in PHREEQC" + "Revisions and Bug Fixes" + +************************************************************ +************************************************************ +* Features in PHREEQC++ Not in PHREEQC * +************************************************************ + + -------- + svn 4897 + -------- + Added capability to include files within the input + file. Files included in include files are also + included. Files are included verbatim and need not + contain complete keyword datablocks; however, the + combination of included files must result in a + legal PHREEQC input file. Files are included as + simulations are proceeding, so it is possible to + write a file at one point of a run that is included + later in the same run. Included files can contain + INCLUDE$ directives. + + SOLUTION + INCLUDE$ file_name + END + + where "file_name" contains: + EQUILIBRIUM_PHASES + Calcite 0 10 + + is the same as a single file with + SOLUTION + EQUILIBRIUM_PHASES + Calcite 0 10 + END + + + -------- + svn 4823 + -------- + Added -cells to DUMP and DELETE; cell option to COPY. + Example: + + COPY cell 1 4 + COPY cell 1 5-10 + DUMP + -cell 1 2-3 10 + DELETE + -cell 1-3 4 8-10 + + COPY cell n range + + The cell option of the COPY keyword causes all reactants + defined with identifying number n to be copied to a single + range of numbers. The range of numbers can be a single + number or a range of numbers given by an integer, a + hyphen, and an integer, with no intervening spaces. + + DUMP + -cell list + + The -cell option writes _RAW formatted output to a + specified file(see below for more details) for each + reactant that is defined in the list. + + DUMP + -cell list + The -cell deletes from memory all reactants that are + defined with identifying numbers in the list. + + The list of numbers for DUMP and DELETE are + more flexible than for COPY. A list of ranges can be + given for DUMP and DELETE, where each element of + the list can be a single number or a range of numbers + defined by an integer, a hyphen, and an ingeger, with + no intervening spaces. + + -------- + svn 4816 + -------- + Added compile capability to use #include file_name + in input and database files. PHREEQCPP process the + files at the start of the run, possibly following + multiple layers of include files, to produce a stream + that is then used as input. Compile define is + MERGE_INCLUDE_FILES; PHREEQC_CLASS also must be defined. + + Input file: + SOLUTION 1 + #INCLUDE t2 + #include t4 + END + + File t2: + REACTION + NaCl + 1 mmol + #include t3 + + File t3: + REACTION_TEMPERATURE + 10 20 30 + + File t4: + SAVE solution 1 + + When compiled with the include file #defines, the above + set of files produces the following input for PHREEQC: + + SOLUTION 1 + REACTION + NaCl + 1 mmol + REACTION_TEMPERATURE + 10 20 30 + SAVE solution 1 + END + + -------- + svn 4800 + -------- + + Added capability to dump REACTIONs, REACTION_TEMPERATUREs, + and MIXes. + + DUMP + -mix 1 4 6 + -reaction 1-5 + -reaction_temperature 1 3-9 + + List of numbers may be formatted as described for DUMP. + Data are written in a format suitable for an input file + to PHREEQCPP. + + Example of dumped keywords: + + MIX 1 + 1 0.33 + 2 0.33 + 3 0.34 + REACTION_RAW 1 + -units Mol + -reactant_list + Ba 1 + Br 2 + -element_list + -steps + 0.01 + -equal_increments 1 + -count_steps 2 + REACTION_TEMPERATURE_RAW 1 + -count_temps 3 + -equal_increments 1 + -temps + 25 45 + + -------- + + Added -cells option to DUMP. + + DUMP + -cells 1-19 20 + + This -cells option will dump any reactant with numbers + between 1 and 20, including SOLUTIONs, EXCHANGERs, + GAS_PHASEs, KINETICS, SOLID_SOLUTIONs, SURFACEs, REACTIONs, + REACTION_TEMPERATUREs, and MIXes. + + + -------- + svn 3730 + -------- + + Added keyword RUN_CELLS. + + RUN_CELLS + -cells 1 2 + 5-6 + 7 + -time_step 10000 + -start_time 100 + + + For each i listed in -cells + it is the equivalent of the following: + + USE solution i + USE equilibrium_phases i + USE exchange i + USE surface i + USE solid_solution i + USE gas_phase i + USE kinetics i + USE reaction i + USE reaction_temperature i + SAVE solution i + SAVE equilibrium_phases i + SAVE exchange i + SAVE surface i + SAVE solid_solution i + SAVE gas_phase i + + If MIX i is defined, it is used in place of USE solution i. + A MIX i or SOLUTION i must be defined to use RUN_CELLS; -cells i. + All other entities are used only if they are defined. + + -start_time and -time_step are needed if any kinetic reactions + are calculated. -start_time is the time at the start of the + calculation, and -time_step is the length of time over which + to integrate the kinetic reactions. + + -------- + svn 3727 + -------- + Added keywords to allow modification of each reactant. + A reactant must have been defined previously, but then + each data item of the reactant can be changed and new + components added. Data items read are changed, all + other data items remain the same. Input format is the + same as the RAW formats produced by DUMP. + + + New keywords are as follows: + + SOLUTION_MODIFY + EQUILIBRIUM_PHASES_MODIFY + EXCHANGE_MODIFY + SURFACE_MODIFY + SOLID_SOLUTIONS_MODIFY + GAS_PHASE_MODIFY + KINETICS_MODIFY + + The example below is indented to indicate which + information is necessary to change a data item. + Working back through the indention levels for + and item, each heading of a lower order is + necessary to define the data item. In the example + below, to change the number of moles of barite from + 10 to 5 in the equilibrium phase assemblage, it + is necessary to define EQUILIBRIUM_PHASES_MODIFY 1; + -component; -name Barite; -moles 5. + + Items identified by an asterisk are most likely to + consider for redefinition. Items with (*) are + marked to indicate that care is needed to maintain + charge balance relations. Unwanted redox and pH + reactions may result from incorrect redefinition + of these quantities. Items not marked are either + initial estimates of variables calculated in the + simulation, or are parameters thought not likely + to be changed. + + The MODIFY data blocks change the data in the + PHREEQC storage structures. They do not cause + any initial composition calculations. Neither + do they generate default reactions to be simulated. + USE statements are needed to specify explicitly + the desired reactions. + + +SOLUTION_MODIFY 1 + -temp 25 * + -total_h 111.01243359981 (*) + -total_o 55.506216800086 (*) + -cb -3.6579285790756e-010 (*) + -totals + Cl 0.0010000000000003 (*) + H(0) 1.4155655514601e-025 (*) + Na 0.0010000000000003 (*) + -Isotopes + -pH 7 + -pe 4 + -mu 0.0010001035690258 + -ah2o 0.99996599647757 + -mass_water 1 + -total_alkalinity 3.6579283856577e-010 + -activities + Cl -3.0155266404974 + E -4 + H(0) -25.15 + Na -3.0153891985103 + O(0) -42.080029535586 + -gammas +EQUILIBRIUM_PHASES_MODIFY 1 + -eltList + Ba 1 + O 4 + S 1 + -component * + -name Barite + -si 0 * + -moles 10 * + -delta 0 + -initial_moles 0 + -force_equality 0 + -dissolve_only 0 + -precipitate_only 0 +EXCHANGE_MODIFY 1 + -pitzer_exchange_gammas 1 + -component + -formula X + -totals + Na 1.0000000058717 (*) + X 1.0000000058717 (*) + -charge_balance 0 + -moles 0 + -la 3.0000000302372 + -phase_proportion 0 + -formula_z 0 + -formula_totals + X 1 +SURFACE_MODIFY 1 . + -type 2 + -dl_type 0 + -sites_units 0 + -only_counter_ions 0 + -thickness 1e-008 + -debye_lengths 0 + -DDL_viscosity 1 + -DDL_limit 0.8 + -transport 0 + -component + -formula Hfo_s + -formula_z 0 + -moles 0 + -la -0.11486188676541 + -charge_balance 3.7853465372651e-005 + -phase_proportion 0 + -Dw 0 + -formula_totals + Hfo_s 0.01 + -totals + H 0.01003785346547 (*) + Hfo_s 0.010000000000097 (*) + O 0.010000000000097 (*) + -charge_component + -name Hfo + -specific_area 600 + -grams 1 + -charge_balance 3.7853465372651e-005 (*) + -mass_water 0 + -la_psi 0.55146269389617 + -la_psi1 0 + -la_psi2 0 + -capacitance0 1 + -capacitance1 5 + -diffuse_layer_totals +SOLID_SOLUTIONS_MODIFY 1 + -solid_solution + -name Calcite + -a0 0 + -a1 0 + -ag0 0 + -ag1 0 + -miscibility 0 + -xb1 0.0 + -xb2 0.0 + -component + calcite 0.1 * + siderite 0.001 * +GAS_PHASE_MODIFY 1 + -type 0 + -total_p 1 + -volume 1 + -component + CO2(g) 1.4305508698401e-005 * +KINETICS_MODIFY 1 + -step_divide 1 + -rk 1 + -bad_step_max 500 + -use_cvode 0 + -cvode_steps 100 + -cvode_order 5 + -component + -rate_name Calcite + -tol 1e-008 + -m 0.9999999999991 * + -m0 1 + -moles 8.9805940461929e-013 + -namecoef + CaCO3 1 + -d_params + 1 1 1 1 * + -totals + C 8.9801193858101e-013 + Ca 8.9801193858101e-013 + O 2.694035815743e-012 + -steps + + -------- + svn 3719 + -------- + Added DELETE keyword to delete any numbered reactant, as + listed in the example below. A list of single numbers and + number ranges are used to define the reactants to delete + from PHREEQC memory. Lists may continue on subsequent + lines. Deletion occurs as the last step of simulation + calculations, after all other calculations (initial + compositions, reactions, transport, inverse modeling) and + COPYing have occurred. + + + DELETE + -solution 2 3 + -equilibrium_phases 2-3 + -exchange 2 + 3 + -surface + 2-3 + -solid_solution + 2 3 + -gas_phase 2-3 + -kinetics 3 2 + -mix 2 + -mix 3 + -reaction 2-3 + -temperature + 2 + 3 + -------- + svn 3704 + -------- + Added DUMP keyword. Writes complete data for solution, + equilibrium_phases, exchange, surface, solid solution, + gas phase, and kinetics classes. The format of the + output is suitable for data input to the C++ version + of PHREEQC. This feature allows the chemical state + of a simulation to be saved and read back in as + initial conditions for subsequent model runs. + + Examples: + DUMP + -all + -file myfile.dmp + END + DUMP + -file myfile.dmp + -append true + -solution 1-2 3 + -equi 3 1-2 + -exch 1 2 3 + -surf 1 + 2 + 3 + + -s_s 1 + 2-3 + -gas 1 + -gas 2 + -gas 3 + -kin 1-3 + END + + Explanation: + The first DUMP datablock will write the compositions at + the end of the simulation (after all simulation calculations, + TRANSPORTs, SAVEs, and COPYs are complete) for + every solution, equilibrium_phases, exchange, surface, + solid solution, gas phase, and kinetics entities that have + been defined or produced in the run. This write includes + internally saved entities (usually assigned negative numbers). + + The second DUMP data appends the compositions of items + numbered 1-3 to myfile.dmp, if they exist. The second example + shows multiple ways to define the entities to be dumped to + file. + + ------ + Begin + ------ + PHREEQC++ has classes that are equivalent to the PHREEQC C + structures. Each class has a method to "dump_raw" the + entire set of class data. The lines generated by dump_raw + can be read as keyword data blocks in an input file. The following + keywords are available in PHREEQC++: SOLUTION_RAW, + EQUILIBRIUM_PHASES_RAW, EXCHANGE_RAW, SURFACE_RAW, + SOLID_SOLUTIONS_RAW, GAS_PHASE_RAW, and KINETICS_RAW. + PHAST uses these classes and data blocks to dump the chemical + state of a simulation and read it back in as a starting + point for subsequent simulations. + + Examples of raw output are given below. Some of the fields + are required and some are not. + + SOLUTION_RAW 1 + -temp 25 + -pH 7 + -pe 4 + -mu 0.0010001035690258 + -ah2o 0.99996599647757 + -total_h 111.01243359981 + -total_o 55.506216800086 + -cb -3.6579285790756e-010 + -mass_water 1 + -total_alkalinity 3.6579283856577e-010 + -totals + Cl 0.0010000000000003 + H(0) 1.4155655514601e-025 + Na 0.0010000000000003 + -activities + Cl -3.0155266404974 + E -4 + H(0) -25.15 + Na -3.0153891985103 + O(0) -42.080029535586 + -gammas + -Isotopes + EQUILIBRIUM_PHASES_RAW 1 + -eltList + Ba 1 + O 4 + S 1 + -component + -name Barite + -si 0 + -moles 10 + -delta 0 + -initial_moles 0 + -force_equality 0 + -dissolve_only 0 + -precipitate_only 0 + EXCHANGE_RAW 1 Exchange assemblage after simulation 3. + -pitzer_exchange_gammas 1 + -component + -formula X + -moles 0 + -la 3.0000000302372 + -charge_balance 0 + -phase_proportion 0 + -formula_z 0 + -totals + Na 1.0000000058717 + X 1.0000000058717 + -formula_totals + X 1 + SURFACE_RAW 1 Surface assemblage after simulation 4. + -type 2 + -dl_type 0 + -sites_units 0 + -only_counter_ions 0 + -thickness 1e-008 + -debye_lengths 0 + -DDL_viscosity 1 + -DDL_limit 0.8 + -transport 0 + -component + -formula Hfo_s + -formula_z 0 + -moles 0 + -la -0.11486188676541 + -charge_balance 3.7853465372651e-005 + -phase_proportion 0 + -Dw 0 + -formula_totals + Hfo_s 0.01 + -totals + H 0.01003785346547 + Hfo_s 0.010000000000097 + O 0.010000000000097 + -charge_component + -name Hfo + -specific_area 600 + -grams 1 + -charge_balance 3.7853465372651e-005 + -mass_water 0 + -la_psi 0.55146269389617 + -la_psi1 0 + -la_psi2 0 + -capacitance0 1 + -capacitance1 5 + -diffuse_layer_totals + SOLID_SOLUTIONS_RAW 1 + -solid_solution + -name Calcite + -a0 0 + -a1 0 + -ag0 0 + -ag1 0 + -miscibility 0 + -xb1 -6.2774385622042e+066 + -xb2 -6.2774385622042e+066 + -component + calcite 0.1 + siderite 0.001 + GAS_PHASE_RAW 1 + -type 0 + -total_p 1 + -volume 1 + -component + CO2(g) 1.4305508698401e-005 + KINETICS_RAW 1 + -step_divide 1 + -rk 3 + -bad_step_max 500 + -use_cvode 0 + -cvode_steps 100 + -cvode_order 5 + -component + -rate_name Calcite + -tol 1e-008 + -m 1 + -m0 1 + -moles 0 + -namecoef + CaCO3 1 + -d_params + 1 1 1 1 + -totals + -steps + + + + +************************************************************ +************************************************************ +* Revisions and Bug Fixes * +************************************************************ +************************************************************ + -------- + svn 5270 + -------- + Added logic to update estimates of log activity when + modifying totals in SOLUTION_MODIFY. The initial + guesses for activities are adjusted proportionally + to the change in total moles of elements (as defined + by SOLUTION_MODIFY; -totals). + + This automatic adjustment is suggested rather than + explicit definition of the initial guesses through + SOLUTION_MODIFY; -activities. However, the -activities + identifier may be used and will supercede the automatic + adjustment. + + The adjustment of the initial guesses for activities + should reduce the number of iterations needed to solve + a given set of equations and, consequently, should + lessen the total CPU time for a simulation. + + -------- + svn 4856 + -------- + Revised logic of searching pitzer parameters so that + order of ions in a parameter definition does not + matter. From c5fc6befc2dcb50bec4526b9bd0b7a5f88ae2390 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 31 Mar 2011 23:17:32 +0000 Subject: [PATCH 0202/1077] Added version/date replacement strings git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5286 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHREEQCPP-RELEASE.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt index da0fb194..3d9d4a2d 100644 --- a/PHREEQCPP-RELEASE.txt +++ b/PHREEQCPP-RELEASE.txt @@ -6,6 +6,9 @@ File contains: ************************************************************ * Features in PHREEQC++ Not in PHREEQC * ************************************************************ +------------------------------------------------------------ +Version @PHREEQC_VER@: @PHREEQC_DATE@ +------------------------------------------------------------ -------- svn 4897 @@ -617,6 +620,10 @@ KINETICS_MODIFY 1 * Revisions and Bug Fixes * ************************************************************ ************************************************************ + +------------------------------------------------------------ +Version @PHREEQC_VER@: @PHREEQC_DATE@ +------------------------------------------------------------ -------- svn 5270 -------- From cd87eed340db82e7624accec2ca6d2226ab67f26 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 14 Apr 2011 21:22:09 +0000 Subject: [PATCH 0203/1077] Added some LDBLE, particularly for pow(). Added some methods, mostly getter methods. Was calculating maximup precipitation for mineral based on limiting element in step.c. Not sure if I will used this or not. Not checking in at this time. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5322 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.cxx | 2 +- KineticsComp.cxx | 2 +- PPassemblage.h | 5 ++- Phreeqc.h | 2 +- Reaction.cxx | 2 +- SSassemblage.h | 4 ++ SSassemblageSS.h | 4 ++ StorageBin.cxx | 109 ++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 5 +++ System.h | 4 ++ Temperature.cxx | 2 +- cxxKinetics.cxx | 4 +- 12 files changed, 137 insertions(+), 8 deletions(-) diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index f5fa7a9e..b07eb046 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -118,7 +118,7 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) if (this->as.size() != 0) { /* use given chemical formula to calculate gfw */ - double l_gfw; + LDBLE l_gfw; if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &l_gfw) == ERROR) { std::ostringstream oss; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index d7988c31..1e9aad30 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -97,7 +97,7 @@ struct kinetics_comp * kinetics_comp_ptr[i].d_params = NULL; if ((*it).d_params.size() > 0) { - kinetics_comp_ptr[i].d_params = (double *) + kinetics_comp_ptr[i].d_params = (LDBLE *) P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).d_params.size() * sizeof(double))); if (kinetics_comp_ptr[i].d_params == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/PPassemblage.h b/PPassemblage.h index 3a569781..91073d67 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -37,7 +37,10 @@ class cxxPPassemblage:public cxxNumKeyword { return this->eltList; }; - + std::map & get_ppAssemblageComps() + { + return this->ppAssemblageComps; + }; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/Phreeqc.h b/Phreeqc.h index 6e1adf21..ccc8bd52 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -532,7 +532,7 @@ void set_inert_moles(void); void unset_inert_moles(void); #ifdef SLNQ int add_trivial_eqns(int rows, int cols, LDBLE * matrix); -int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +//int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); #endif int calc_gas_pressures(void); int calc_s_s_fractions(void); diff --git a/Reaction.cxx b/Reaction.cxx index 1bbf24fd..87db1e96 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -107,7 +107,7 @@ cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) if (this->steps.size() > 0) { irrev_ptr->steps = - (double *) + (LDBLE *) P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (irrev_ptr->steps == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/SSassemblage.h b/SSassemblage.h index 4eb03413..9190035f 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -35,6 +35,10 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + std::map & get_ssAssemblageSSs() + { + return this->ssAssemblageSSs; + }; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 3831e995..b3f6cd77 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -59,6 +59,10 @@ class cxxSSassemblageSS { return (this->totals); }; + const cxxNameDouble & get_comps() const + { + return (this->comps); + }; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/StorageBin.cxx b/StorageBin.cxx index f810091f..206db92b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -243,6 +243,11 @@ cxxStorageBin::setSolution(int n_user, cxxSolution * entity) Solutions[n_user] = *entity; } void +cxxStorageBin::setSolution(int n_user, cxxSolution & entity) +{ + Solutions[n_user] = entity; +} +void cxxStorageBin::removeSolution(int n_user) { Solutions.erase(n_user); @@ -287,6 +292,11 @@ cxxStorageBin::setPPassemblage(int n_user, cxxPPassemblage * entity) PPassemblages[n_user] = *entity; } void +cxxStorageBin::setPPassemblage(int n_user, cxxPPassemblage & entity) +{ + PPassemblages[n_user] = entity; +} +void cxxStorageBin::removePPassemblage(int n_user) { PPassemblages.erase(n_user); @@ -331,6 +341,11 @@ cxxStorageBin::setSSassemblage(int n_user, cxxSSassemblage * entity) SSassemblages[n_user] = *entity; } void +cxxStorageBin::setSSassemblage(int n_user, cxxSSassemblage & entity) +{ + SSassemblages[n_user] = entity; +} +void cxxStorageBin::removeSSassemblage(int n_user) { SSassemblages.erase(n_user); @@ -1698,6 +1713,12 @@ cxxStorageBin::ORCH_write(std::ostream & chemistry_dat, } #endif +cxxSystem & +cxxStorageBin::getSystem(void) +{ + return this->system; +} + void cxxStorageBin::setSystem(struct Use *use_ptr) { @@ -1804,3 +1825,91 @@ cxxStorageBin::setSystem(struct Use *use_ptr) } } } +void +cxxStorageBin::setSystem(int i) +{ + // Initialize + this->system.Initialize(); + // Solution + { + std::map < int, cxxSolution >::iterator it = this->Solutions.find(i); + if (it != this->Solutions.end()) + { + this->system.setSolution(&(it->second)); + } + } + + // Exchange + { + std::map < int, cxxExchange >::iterator it = this->Exchangers.find(i); + if (it != this->Exchangers.end()) + { + this->system.setExchange(&(it->second)); + } + } + + // gas_phase + { + std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(i); + if (it != this->GasPhases.end()) + { + this->system.setGasPhase(&(it->second)); + } + } + // kinetics + { + std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(i); + if (it != this->Kinetics.end()) + { + this->system.setKinetics(&(it->second)); + } + } + // pp_assemblage + { + std::map < int, cxxPPassemblage >::iterator it = this->PPassemblages.find(i); + if (it != this->PPassemblages.end()) + { + this->system.setPPassemblage(&(it->second)); + } + } + // s_s_assemblage + { + std::map < int, cxxSSassemblage >::iterator it = this->SSassemblages.find(i); + if (it != this->SSassemblages.end()) + { + this->system.setSSassemblage(&(it->second)); + } + } + // surface + { + std::map < int, cxxSurface >::iterator it = this->Surfaces.find(i); + if (it != this->Surfaces.end()) + { + this->system.setSurface(&(it->second)); + } + } + // mix + { + std::map < int, cxxMix >::iterator it = this->Mixes.find(i); + if (it != this->Mixes.end()) + { + this->system.setMix(&(it->second)); + } + } + // reaction + { + std::map < int, cxxReaction >::iterator it = this->Reactions.find(i); + if (it != this->Reactions.end()) + { + this->system.setReaction(&(it->second)); + } + } + // reaction temperature + { + std::map < int, cxxTemperature >::iterator it = this->Temperatures.find(i); + if (it != this->Temperatures.end()) + { + this->system.setTemperature(&(it->second)); + } + } +} diff --git a/StorageBin.h b/StorageBin.h index af1d3ada..62a7d16a 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -36,6 +36,7 @@ class cxxStorageBin cxxSolution *getSolution(int n_user); void setSolution(int n_user, cxxSolution * entity); + void setSolution(int n_user, cxxSolution & entity); void removeSolution(int n_user); cxxExchange *getExchange(int n_user); @@ -44,6 +45,7 @@ class cxxStorageBin cxxPPassemblage *getPPassemblage(int n_user); void setPPassemblage(int n_user, cxxPPassemblage * entity); + void setPPassemblage(int n_user, cxxPPassemblage & entity); void removePPassemblage(int n_user); cxxGasPhase *getGasPhase(int n_user); @@ -52,6 +54,7 @@ class cxxStorageBin cxxSSassemblage *getSSassemblage(int n_user); void setSSassemblage(int n_user, cxxSSassemblage * entity); + void setSSassemblage(int n_user, cxxSSassemblage & entity); void removeSSassemblage(int n_user); cxxKinetics *getKinetics(int n_user); @@ -74,7 +77,9 @@ class cxxStorageBin void setTemperature(int n_user, cxxTemperature * entity); void removeTemperature(int n_user); + cxxSystem &getSystem(void); void setSystem(struct Use *use_ptr); + void setSystem(int i); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/System.h b/System.h index 34243f39..456b779f 100644 --- a/System.h +++ b/System.h @@ -69,6 +69,10 @@ public: this->temperature = entity; } void totalize(PHREEQC_PTR_ARG); + cxxNameDouble &getTotals(void) + { + return this->totals; + } #ifdef ORCHESTRA void ORCH_components(); diff --git a/Temperature.cxx b/Temperature.cxx index 67fd849b..d1a7abbd 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -93,7 +93,7 @@ cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) if (this->temps.size() > 0) { temperature_ptr->t = - (double *) + (LDBLE *) P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); if (temperature_ptr->t == NULL) P_INSTANCE_POINTER malloc_error(); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 4edc5f7c..1b42cb7c 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -153,11 +153,11 @@ cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) { kinetics_ptr->count_steps = -this->equal_steps; } - kinetics_ptr->steps = (double *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->steps); + kinetics_ptr->steps = (LDBLE *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->steps); if (this->steps.size() > 0) { kinetics_ptr->steps = - (double *) + (LDBLE *) P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); if (kinetics_ptr->steps == NULL) P_INSTANCE_POINTER malloc_error(); From eb2227ac279e6f0c15463cde821a9bebd20e6a35 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 25 Apr 2011 16:39:38 +0000 Subject: [PATCH 0204/1077] Before reloading from home. Adding new files for chart, curve, form2 git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5342 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 65 ++++ ChartHandler.h | 36 ++ ChartObject.cpp | 854 +++++++++++++++++++++++++++++++++++++++++++++++ ChartObject.h | 286 ++++++++++++++++ CurveObject.cpp | 36 ++ CurveObject.h | 90 +++++ 6 files changed, 1367 insertions(+) create mode 100644 ChartHandler.cpp create mode 100644 ChartHandler.h create mode 100644 ChartObject.cpp create mode 100644 ChartObject.h create mode 100644 CurveObject.cpp create mode 100644 CurveObject.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp new file mode 100644 index 00000000..6bdd2a78 --- /dev/null +++ b/ChartHandler.cpp @@ -0,0 +1,65 @@ +// ChartHandler.cpp: implementation of the ChartHandler class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "ChartHandler.h" +#include + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +ChartHandler::ChartHandler() + // + // default constructor for ChartHandler + // +{ + current_chart = NULL; + current_chart_n_user = -1000; + u_g_defined = false; +} + +ChartHandler::~ChartHandler() +{ +} + +bool +ChartHandler::Read(CParser &parser) +{ + int n_user; + std::string token; + + // reads line, next character is after keyword + parser.check_line("ChartHandler", true, false, true, false); + + std::istringstream iss(parser.line()); + // keyword + iss >> token; + // number + if (!(iss >> n_user)) + { + n_user = 1; + } + + // makes new ChartObject if necessary + std::map::iterator it = this->chart_map.find(n_user); + if (it == this->chart_map.end()) + { + ChartObject chart_obj; + chart_map[n_user] = chart_obj; + it = this->chart_map.find(n_user); + } + + // Read/update ChartObject + it->second.Read(parser); + current_chart_n_user = n_user; + current_chart = &it->second; + u_g_defined = true; + + return true; +} + + diff --git a/ChartHandler.h b/ChartHandler.h new file mode 100644 index 00000000..1901202f --- /dev/null +++ b/ChartHandler.h @@ -0,0 +1,36 @@ +#if !defined(CHARTHANDLER_H_INCLUDED) +#define CHARTHANDLER_H_INCLUDED +#include +#include +#include +#include "Parser.h" +#include "ChartObject.h" + +class ChartHandler +{ + +public: + ChartHandler(); + ~ChartHandler(); + + size_t Get_chart_count() + { + return this->chart_map.size(); + } + ChartObject * Get_current_chart() + { + return this->current_chart; + } + bool Read(CParser &parser); + +protected: + std::map chart_map; + int current_chart_n_user; + ChartObject * current_chart; + bool u_g_defined; + +public: + +}; + +#endif // !defined(CHARTHANDLER_H_INCLUDED) diff --git a/ChartObject.cpp b/ChartObject.cpp new file mode 100644 index 00000000..1bb5bd7b --- /dev/null +++ b/ChartObject.cpp @@ -0,0 +1,854 @@ +// ChartObject.cpp: implementation of the ChartObject class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#ifdef MULTICHART +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "Utils.h" +#include +#include "ChartObject.h" +#include "Parser.h" +#include +#include + +#ifdef PHREEQC_CLASS +#else +#include "phqalloc.h" +extern int error_msg(const char *err_str, const int stop, ...); +extern int warning_msg(const char *err_str, ...); +extern int rate_free(struct rate *rate_ptr); +#endif + +#include "Form2.h" +using namespace zdg_ui2; + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +ChartObject::ChartObject() + // + // default constructor for cxxExchComp + // +{ + new_ug = false; + FirstCallToUSER_GRAPH = true; + + update_time_chart = 150; + PanelHeight = 510; + PanelWidth = 640; + + Symbol_map["Square"] = 0; + Symbol_map["Diamond"] = 1; + Symbol_map["Triangle"] = 2; + Symbol_map["Circle"] = 3; + Symbol_map["XCross"] = 4; + Symbol_map["Plus"] = 5; + Symbol_map["Star"] = 6; + Symbol_map["TriangleDown"] = 7; + Symbol_map["HDash"] = 8; + Symbol_map["VDash"] = 9; + Symbol_map["None"] = 10; + + Color_vector.push_back("Red"); + Color_vector.push_back("Green"); + Color_vector.push_back("Blue"); + Color_vector.push_back("Orange"); + Color_vector.push_back("Magenta"); + Color_vector.push_back("Yellow"); + Color_vector.push_back("Black"); + + nCSV_headers = 0; + user_graph_headings.clear(); + chart_title.clear(); + axis_titles.clear(); + + int i; + for (i = 0; i < 5; i++) + { + axis_scale_x[i] = NA; + axis_scale_y[i] = NA; + axis_scale_y2[i] = NA; + } + + chart_type = 0; + graph_initial_solutions = false; + shifts_as_points = false; + rownr = -1; + colnr = 0; + RowOffset = 0; + ColumnOffset = 0; + prev_advection_step = 0; + prev_transport_step = 0; + AddSeries = true; + prev_sim_no = 0; + x_filled = false; + col_dwn = false; + y_filled.clear(); + x_value = NA; + bool all_points = false; + bool end_timer = false; + + graph_initial_solutions = true; + connect_simulations = true; + + ncurves_changed[0] = ncurves_changed[1] = ncurves_changed[2] = 0; + + user_graph.commands = NULL; + user_graph.name = NULL; + user_graph.new_def = 0; + user_graph.linebase = user_graph.loopbase = user_graph.varbase = NULL; + + default_symbol = 0; +} + +ChartObject::~ChartObject() +{ + // all data cleans itself up +} + +bool +ChartObject::Set_axis_scale(CParser & parser) +{ + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + double *scale_ptr = NULL; + std::vector string_vector; + size_t j = 0; + + // rereads option + parser.copy_token(token, next_char); + + // reads parameters + while ((j < 5) && (parser.copy_token(token, next_char)) != CParser::TT_EMPTY) + { + string_vector.push_back(token); + j++; + } + if (string_vector.size() == 0) + { + error_msg("No axis defined for scales", CParser::OT_CONTINUE); + return false; + } + std::string str = string_vector[0]; + std::string type; + // determine axis + switch (str[0]) + { + case 'X': + case 'x': + type = "x"; + scale_ptr = this->axis_scale_x; + break; + case 'Y': + case 'y': + type = "y"; + scale_ptr = this->axis_scale_y; + break; + case 'S': + case 's': + type = "sy"; + scale_ptr = this->axis_scale_y2; + break; + default: + std::ostringstream estream; + estream << "Found " << str; + estream << ", but expect axis type \'x\', \'y\', or \'sy\'."; + estream << std::endl; + error_msg("No axis defined for scales", CParser::OT_CONTINUE); + return false; + break; + } + + for (j = 1; j < string_vector.size() && j < 5; j++) + { + std::string s = string_vector[j]; + if (s[0] == 'a' || s[0] == 'A') + { + scale_ptr[j - 1] = NA; + } + else if (CParser::token_type(s) == CParser::TT_DIGIT) + { + scale_ptr[j - 1] = atof(s.c_str()); + } + else + { + std::ostringstream estream; + estream << "Found " << s; + estream << ", but expect number or 'a(uto)'."; + estream << std::endl; + error_msg(estream.str().c_str(), CONTINUE); + return false; + } + } + if (string_vector.size() == 5) + { + std::string s = string_vector[4]; + if (s[0] != 't' || s[0] != 'T') + { + scale_ptr[4] = 10.0; + if (((fabs(scale_ptr[0] - NA) > 1e-3) && scale_ptr[0] <=0) || + ((fabs(scale_ptr[1] - NA) > 1e-3) && scale_ptr[1] <=0)) + { + std::ostringstream estream; + estream << "MIN and MAX must be > 0 for log " << type << "-scale."; + estream << std::endl; + error_msg(estream.str().c_str(), CONTINUE); + return false; + } + + } + } + if ((fabs(scale_ptr[0] - NA) > 1e-3) && (fabs(scale_ptr[1] - NA) > 1e-3)) + { + if (scale_ptr[0] > scale_ptr[1]) + { + std::ostringstream estream; + estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl; + estream << "Switching values for MIN and MAX. " << std::endl; + warning_msg(estream.str().c_str()); + double t; + t = scale_ptr[0]; + scale_ptr[0] = scale_ptr[1]; + scale_ptr[1] = scale_ptr[0]; + return false; + } + } + return true; +} + +bool +ChartObject::Read(CParser & parser) +{ + + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("start"); // 0 + vopts.push_back("end"); // 1 + vopts.push_back("heading"); // 2 + vopts.push_back("headings"); // 3 + vopts.push_back("chart_title"); // 4 + vopts.push_back("axis_titles"); // 5 + vopts.push_back("axis_scale"); // 6 + vopts.push_back("initial_solutions"); // 7 + vopts.push_back("plot_concentration_vs"); // 8 + vopts.push_back("shifts_as_points"); // 9 + vopts.push_back("grid_offset"); // 10 + vopts.push_back("connect_simulations"); // 11 + vopts.push_back("plot_csv_file"); // 12 + } + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + if (this->Curves.size() > 0) + { + this->ncurves_changed[0] = 1; + this->ColumnOffset = ncurves_changed[2]; + this->new_ug = true; + } + + + // Read number and description + { + this->read_number_description(parser); + } + + opt_save = CParser::OPT_DEFAULT; + + 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_ERROR: + opt = CParser::OPT_EOF; + error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); + error_msg(parser.line().c_str(), CONTINUE); + useLastLine = false; + break; + case 0: /* start */ + opt_save = CParser::OPT_DEFAULT; + break; + case 1: /* end */ + opt_save = CParser::OPT_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading */ + while (parser.copy_token(token, next_char) != CParser::TT_EMPTY) + { + this->user_graph_headings.push_back(token); + } + break; + case 4: /* chart title */ + { + std::string l = parser.line(); + std::string tok; + std::string::iterator b = l.begin(); + std::string::iterator e = l.end(); + parser.copy_title(tok, b, e); + this->chart_title = tok; + } + break; + case 5: /* axis titles */ + { + std::string l; + parser.get_rest_of_line(l); + std::string tok; + std::string::iterator b = l.begin(); + std::string::iterator e = l.end(); + this->axis_titles.clear(); + while(parser.copy_title(tok, b, e) != CParser::TT_EMPTY) + { + this->axis_titles.push_back(tok); + } + } + break; + case 6: /* axis scales */ + { + this->Set_axis_scale(parser); + } + break; + case 7: /* initial_solutions */ + this->graph_initial_solutions = parser.get_true_false(next_char, FALSE); + break; + case 8: /* plot_concentration_vs */ + //prev_next_char = next_char; + parser.copy_token(token, next_char); + Utilities::str_tolower(token); + if (token[0] == 'x' || token[0] == 'd') + chart_type = 0; + else if (token[0] == 't') + chart_type = 1; + else + { + std::ostringstream estream; + estream << "Found " << token << ", but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time."; + error_msg(estream.str().c_str(), CONTINUE); + } + break; + case 9: /* shifts_as_points */ + this->shifts_as_points = parser.get_true_false(next_char, true); + if (this->shifts_as_points) + this->chart_type = 0; + else + this->chart_type = 1; + break; + case 10: /* grid_offset */ +#ifdef PHREEQ98 + /* + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &RowOffset); + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &ColumnOffset); + */ +#endif + break; + case 11: /* connect_simulations */ + this->connect_simulations = parser.get_true_false(next_char, true); + break; + case 12: /* plot_csv_file */ + { + std::string file_name; + parser.get_rest_of_line(file_name); + file_name = trim(file_name); + this->OpenCSVFile(file_name); + } + break; + /* End of modifications */ + case CParser::OPT_DEFAULT: // Read Basic commands + { + this->rate_new_def = true; + /* read command */ + std::string cmd(parser.line()); + std::string cmd_lower = cmd; + Utilities::str_tolower(cmd_lower); + if ((cmd_lower.find("graph_y") != std::string::npos) || + (cmd_lower.find("graph_sy") != std::string::npos)) + { + CurveInfonr++; + } + if (cmd_lower.find("plot_xy") != std::string::npos) + { + ExtractCurveInfo(cmd); // truncates cmd + CurveInfonr++; + } + this->rate_command_list.push_back(cmd); + } + opt_save = CParser::OPT_DEFAULT; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + + this->Set_rate_struct(); + return true; +} + +bool +ChartObject::OpenCSVFile(std::string file_name) +{ + std::string token; + + std::ifstream f_csv(file_name.c_str(), std::ifstream::in); + + if (!f_csv.is_open()) + { + std::ostringstream estream; + estream << "Could not open csv file for USER_GRAPH " << file_name; + error_msg(estream.str().c_str(), CONTINUE); + return false; + } + + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(f_csv, oss_out, oss_err); + + /* Get lines */ + int linenr = 0; + std::vector headings; + std::vector csv_curves; + while (parser.check_line("cvs file", false, true, true, false) != CParser::LT_EOF) + { + // Headings line + if (linenr == 0) + { + // Skip x in 1st column + parser.get_iss() >> token; + while (parser.get_iss() >> token) + { + headings.push_back(token); + } + nCSV_headers = (int) headings.size(); + this->ColumnOffset = nCSV_headers; + + // add new headers to beginning of list + std::vector old_headings = this->user_graph_headings; + this->user_graph_headings.clear(); + this->user_graph_headings = headings; + std::vector::iterator it = old_headings.begin(); + for (; it != old_headings.end(); it++) + { + this->user_graph_headings.push_back(*it); + } + + // add new curves + size_t i; + for (i = 0; i < headings.size(); i++) + { + CurveObject c; + c.Set_id(headings[i]); + csv_curves.push_back(c); + } + + linenr++; + continue; + } + + token = parser.line(); + std::string tok1; + CParser::TOKEN_TYPE tt = CParser::parse_delimited(token, tok1, "\t"); + + // Curve properties lines + if (linenr < 6 && tt != CParser::TT_DIGIT) + { + Utilities::str_tolower(tok1); + std::string tok2; + size_t i=0; + while (token.size() != 0 && i < csv_curves.size()) + { + CParser::parse_delimited(token, tok2, "\t"); + if (!strncmp(tok1.c_str(), "color", 5)) + { + csv_curves[i].Set_color(tok2); + } + else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) + && (strstr(tok1.c_str(), "-si") == NULL)) + { + csv_curves[i].Set_symbol(tok2); + } + else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) + { + csv_curves[i].Set_symbol_size(atof(tok2.c_str())); + } + else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) + { + csv_curves[i].Set_line_w(atof(tok2.c_str())); + } + else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) + { + csv_curves[i].Set_y_axis(atoi(tok2.c_str())); + } + i++; + } + linenr++; + continue; + } + + // Curve data + if (linenr < 6) linenr = 6; + if (tt != CParser::TT_DIGIT) + { + linenr++; + continue; + } + + // x value for all curves + double x_value = atof(tok1.c_str()); + + // y values for curves + std::string tok2; + size_t i=0; + while (token.size() != 0 && i < csv_curves.size()) + { + CParser::parse_delimited(token, tok2, "\t"); + Utilities::squeeze_white(tok2); + if (tok2.size() == 0) + { + csv_curves[i].Get_x().push_back(NA); + csv_curves[i].Get_x().push_back(NA); + } + else + { + csv_curves[i].Get_x().push_back(x_value); + csv_curves[i].Get_y().push_back(atof(tok2.c_str())); + } + i++; + } + linenr++; + } + + // Prepend new curves + std::vector old_curves = this->Curves; + this->Curves.clear(); + this->Curves = csv_curves; + + std::vector::iterator it = old_curves.begin(); + for (; it != old_curves.end(); it++) + { + this->Curves.push_back(*it); + } + return true; +} + +void +ChartObject::ExtractCurveInfo(std::string & cmd_line) +{ + /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ + + // Make copy of cmd_line + int curvenr = (int) this->Curves.size(); + std::string str_line = cmd_line; + + // find command part of cmd_line + Utilities::replace(",","#",cmd_line); + size_t pos = cmd_line.find(","); + if (pos != std::string::npos) + { + cmd_line = cmd_line.substr(0, pos); + Utilities::replace("#",",",cmd_line); + str_line.erase(0, pos + 1); + } + else + { + error_msg("Did not find x and y expressions for plot_xy command in USER_GRAPH", STOP); + } + + // new curve + CurveObject new_curve; + + // process plot_xy options + while (Utilities::replace(" ","#",str_line)); + while (Utilities::replace("\t","#",str_line)); + std::string tok; + std::string::iterator b = str_line.begin(); + std::string::iterator e = str_line.end(); + + while (CParser::copy_title(tok, b, e) != CParser::TT_EMPTY) + { + while (Utilities::replace("#"," ",tok)); + while (Utilities::replace("="," ",tok)); + std::string::iterator b1 = tok.begin(); + std::string::iterator e1 = tok.end(); + std::string tok1, tok2; + CParser::copy_token(tok1, b1, e1); + Utilities::str_tolower(tok1); + CParser::copy_token(tok2, b1, e1); + if (!strncmp(tok1.c_str(), "color", 5)) + { + //Curves[curvenr + ColumnOffset].Set_color(tok2); + new_curve.Set_color(tok2); + continue; + } + else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) + && (strstr(tok1.c_str(), "-si") == NULL)) + { + new_curve.Set_symbol(tok2); + continue; + } + else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) + { + new_curve.Set_symbol_size(atof(tok2.c_str())); + continue; + } + else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) + { + new_curve.Set_line_w(atof(tok2.c_str())); + continue; + } + else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) + { + new_curve.Set_y_axis(atoi(tok2.c_str())); + continue; + } + else + { + std::ostringstream estream; + estream << "Unknown input for plot_xy in USER_GRAPH " << tok << std::endl; + warning_msg(estream.str().c_str()); + continue; + } + } + + // Add new curve to chart + this->Curves.push_back(new_curve); +} +void +ChartObject::Set_rate_struct(void) +{ + rate_free(&user_graph); + + std::list::iterator it = rate_command_list.begin(); + std::ostringstream oss; + for (; it != rate_command_list.end(); it++) + { + oss << *it << std::endl; + } + this->user_graph.commands = (char *) PHRQ_malloc((strlen(oss.str().c_str()) + 2) * sizeof(char)); + ::strcpy(this->user_graph.commands, oss.str().c_str()); + this->user_graph.new_def = this->rate_new_def; + this->user_graph.loopbase = NULL; + this->user_graph.varbase = NULL; + this->user_graph.linebase = NULL; + this->user_graph.name = NULL; +} +ZedGraph::SymbolType +ChartObject::Return_SymbolType(const std::string sym) +{ + int i; + std::map::iterator it; + if (this->Symbol_map.find(sym) != this->Symbol_map.end()) + { + i = it->second; + } + else + { + i = default_symbol++; + default_symbol = default_symbol % this->Symbol_map.size(); + } + + switch (i) + { + case 0: + return SymbolType::Square; + break; + case 1: + return SymbolType::Diamond; + break; + case 2: + return SymbolType::Triangle; + break; + case 3: + return SymbolType::Circle; + break; + case 4: + return SymbolType::XCross; + break; + case 5: + return SymbolType::Plus; + break; + case 6: + return SymbolType::Star; + break; + case 7: + return SymbolType::TriangleDown; + break; + case 8: + return SymbolType::HDash; + break; + case 9: + return SymbolType::VDash; + break; + case 10: + return SymbolType::None; + break; + default: + return SymbolType::Default; + break; + } +} +void +ChartObject::SaveCurvesToFile(std::string &) +{ +} +void +ChartObject::PlotXY(std::string x, std::string y) +{ + /* Attribute values from *x and *y to Curves(*x, *y) */ + int curvenr = colnr + ColumnOffset; + +#ifdef SKIP + int i, i2, i3; + bool new_sim = false, new_trans = false; + if ((state == TRANSPORT && transport_step != prev_transport_step) || + (state == ADVECTION && advection_step != prev_advection_step)) + new_trans = true; + if (FirstCallToUSER_GRAPH && colnr == 0) + prev_sim_no = simulation; + else + if (!rownr && (simulation != prev_sim_no || new_trans)) + { + new_sim = true; + if (!connect_simulations) + AddSeries = TRUE; + } + prev_sim_no = simulation; + + int curvenr = colnr + ColumnOffset; + + if (curvenr >= ncurves) + ReallocCurves(0); + if (curvenr + 1 > ncurves_changed[2]) /* timer must recall DefineCurves in Form */ + { + ncurves_changed[0] = 1; + ncurves_changed[1] = ncurves_changed[2]; + ncurves_changed[2] = curvenr + 1; + } + if (x_filled && user_graph_count_headings > curvenr + ColumnOffset) + { + PHRQ_free(Curves[curvenr + ColumnOffset].id); + Curves[curvenr + ColumnOffset].id = + string_duplicate(user_graph_headings[curvenr + ColumnOffset]); + } + + /* If a new simulation, create new set of curves, + define identifiers, y axis from values set in ExtractCurveInfo... */ + if (rownr == 0 && colnr == 0) + { + if (new_sim && AddSeries && (!connect_simulations || new_ug)) + { /* step to new curveset... */ + if (Curves[ncurves - 1].npoints) + ReallocCurves(ncurves * 2); + for (i = curvenr; i < ncurves; i++) + { + if (Curves[i].npoints) + continue; + else + { + /* curve i is free... */ + i2 = i3 = ColumnOffset; + ColumnOffset = curvenr = i; + break; + } + } + if (new_trans && !new_ug) i3 = 0; + if (new_ug) i2 = 0; + /* fill in curve properties... */ + for (i = ColumnOffset; i < ColumnOffset + (ColumnOffset - i2); i++) + { + if (i >= ncurves) + ReallocCurves(0); + /* define the new curve... */ + if (i3 < user_graph_count_headings) + { + PHRQ_free(Curves[i].id); + Curves[i].id = string_duplicate(user_graph_headings[i3]); + } + //Curves[i].color = Curves[i3].color; + //Curves[i].line_w = Curves[i3].line_w; + //Curves[i].symbol = Curves[i3].symbol; + //Curves[i].symbol_size = Curves[i3].symbol_size; + Curves[i].y_axis = Curves[i3].y_axis; + i3++; + } + } + /* Or, add all to existing set... */ + else if (new_sim) + { + RowOffset = 1; + for (i = 0; i < ncurves; i++) Curves[i].prev_npoints = Curves[i].npoints; + } + new_ug = false; + } +#endif + /* return if x or y is a zero... */ + if (x.size() == 0 || y.size() == 0) return; + + /* fill in Curves(x, y)... */ + //if (Curves[curvenr].npoints >= Curves[curvenr].nxy) + // ReallocCurveXY(curvenr); + Curves[curvenr].Get_x().push_back(atof(x.c_str())); + Curves[curvenr].Get_y().push_back(atof(y.c_str())); + //Curves[curvenr].npoints++; + +} + + +bool +ChartObject::start_chart(void) +{ + //if (end) + // goto end_chart; + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(true); + +#if defined(PHREEQC_CLASS) + Thread ^t = gcnew Thread( + gcnew ParameterizedThreadStart(Form1::ThreadForm)); +#else + Thread ^t = gcnew Thread( + gcnew ParameterizedThreadStart(Form1::ThreadForm)); +#endif +//#else +// Thread ^t = gcnew Thread( gcnew ThreadStart( &Form1::ThreadForm)); +//#endif + t->SetApartmentState(ApartmentState::STA); + t->IsBackground = false; + t->Priority = ThreadPriority::Normal; +#if PHREEQC_CLASS + PhreeqcObj ^p = gcnew PhreeqcObj(this); + t->Start(p); +#else + t->Start(); +#endif + //Thread::Sleep( 1 ); /* this when debugging... */ + //_beginthread(void (Form1::ThreadForm), 0, NULL); + return true; +} +#endif // MULTICHART \ No newline at end of file diff --git a/ChartObject.h b/ChartObject.h new file mode 100644 index 00000000..dbc5013a --- /dev/null +++ b/ChartObject.h @@ -0,0 +1,286 @@ +#if !defined(CHARTOBJECT_H_INCLUDED) +#define CHARTOBJECT_H_INCLUDED +#include +#include +#include +#include +#include "CurveObject.h" +#include "global_structures.h" +#include "NumKeyword.h" +//#include "Parser.h" +#include + +//#define NA (float) -9.9999 /* NA = not available */ +class ChartObject:public cxxNumKeyword +{ + + public: + ChartObject(); + ChartObject(int i); + ~ChartObject(); + + // new_ug + bool Get_new_ug() + { + return this->new_ug; + } + void Set_new_ug(bool b) + { + this->new_ug = b; + } + // bool FirstCallToUSER_GRAPH; + void Set_FirstCallToUSER_GRAPH(bool b) + { + this->FirstCallToUSER_GRAPH = b; + } + bool Get_FirstCallToUSER_GRAPH() + { + return this->FirstCallToUSER_GRAPH; + } + // int update_time_chart; + int Get_update_time_chart() + { + return (this->update_time_chart); + } + // PanelHeight + int Get_PanelHeight() + { + return (this->PanelHeight); + } + // PanelWidth + int Get_PanelWidth() + { + return (this->PanelWidth); + } + // Symbol_map + // std::vector Color_vector; + // int nCSV_headers; + // std::vector user_graph_headings; + std::vector &Get_user_graph_headings() + { + return this->user_graph_headings; + } + // std::string chart_title; + std::string &Get_chart_title() + { + return this->chart_title; + } + // std::vector axis_titles; + std::vector &Get_axis_titles() + { + return this->axis_titles; + } + // double axis_scale_x[5]; + double *Get_axis_scale_x() + { + return this->axis_scale_x; + } + // double axis_scale_y[5]; + double *Get_axis_scale_y() + { + return this->axis_scale_y; + } + // double axis_scale_y2[5]; + double *Get_axis_scale_y2() + { + return this->axis_scale_y2; + } + // int chart_type; + int Get_chart_type() + { + return this->chart_type; + } + // bool graph_initial_solutions; + bool Get_graph_initial_solutions() + { + return this->graph_initial_solutions; + } + // bool connect_simulations; + bool Get_connect_simulations() + { + return this->connect_simulations; + } + // int shifts_as_points; + // int rownr; + void Set_rownr(int i) + { + this->rownr = i; + } + int Get_rownr() + { + return (this->rownr); + } + // int colnr; + void Set_colnr(int i) + { + this->colnr = i; + } + int Get_colnr() + { + return (this->colnr); + } + // int RowOffset; + // int ColumnOffset; + + // int prev_advection_step; + void Set_prev_advection_step(int i) + { + this->prev_advection_step = i; + } + int Get_prev_advection_step() + { + return (this->prev_advection_step); + } + // int prev_transport_step; + void Set_prev_transport_step(int i) + { + this->prev_transport_step = i; + } + int Get_prev_transport_step() + { + return (this->prev_transport_step); + } + // bool AddSeries; + void Set_AddSeries(bool b) + { + this->AddSeries = b; + } + bool Get_AddSeries(void) + { + return this->AddSeries; + } + // int prev_sim_no; + // bool x_filled; + // bool col_dwn; + // std::vector y_filled; + // double x_value; + // bool all_points; + void Set_all_points(bool tf) + { + this->all_points = tf; + } + bool Get_all_points() + { + return this->all_points; + } + // bool end_timer; + bool Get_end_timer() + { + return this->end_timer; + } + // std::vector Curves; + std::vector &Get_Curves() + { + return this->Curves; + } + // int ncurves_changed[3]; + int *Get_ncurves_changed() + { + return (this->ncurves_changed); + } + void Set_ncurves_changed_0(int i) + { + this->ncurves_changed[0] = i; + } + // int CurveInfonr; + + // struct rate user_graph; + struct rate *Get_user_graph() + { + return &this->user_graph; + } + // C++ for rate struct + // std::string rate_name; + // std::list rate_command_list; + std::list &Get_rate_command_list() + { + return this->rate_command_list; + } + // bool rate_new_def; + void Set_rate_new_def(bool tf) + { + this->rate_new_def = tf; + if (tf) + { + this->user_graph.new_def = 1; + } + else + { + this->user_graph.new_def = 0; + } + } + bool Get_rate_new_def() + { + return this->rate_new_def; + } + // int default_symbol; + + + + + bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); + bool Set_axis_scale(CParser & parser); + bool Read(CParser & parser); + bool OpenCSVFile(std::string fn); + void ExtractCurveInfo(std::string & str_line); + void Set_rate_struct(void); + void PlotXY(std::string x, std::string y); + bool start_chart(void); + ZedGraph::SymbolType Return_SymbolType(std::string); + void SaveCurvesToFile(std::string &); + protected: + + bool new_ug; + bool FirstCallToUSER_GRAPH; + + int update_time_chart; /* milliseconds, maybe read */ + int PanelHeight; + int PanelWidth; + std::map Symbol_map; + std::vector Color_vector; + int nCSV_headers; + std::vector user_graph_headings; + std::string chart_title; + std::vector axis_titles; + double axis_scale_x[5]; + double axis_scale_y[5]; + double axis_scale_y2[5]; + + int chart_type; + bool graph_initial_solutions; + bool connect_simulations; + int shifts_as_points; + int rownr; + int colnr; + int RowOffset; + int ColumnOffset; + + int prev_advection_step; + int prev_transport_step; + bool AddSeries; + + int prev_sim_no; + bool x_filled; + bool col_dwn; + std::vector y_filled; + double x_value; + bool all_points; + bool end_timer; + + std::vector Curves; + int ncurves_changed[3]; + int CurveInfonr; + + struct rate user_graph; + // C++ for rate struct + std::string rate_name; + std::list rate_command_list; + bool rate_new_def; + + int default_symbol; + + public: + +}; + +#endif // !defined(CHARTOBJECT_H_INCLUDED) diff --git a/CurveObject.cpp b/CurveObject.cpp new file mode 100644 index 00000000..37ff7fbd --- /dev/null +++ b/CurveObject.cpp @@ -0,0 +1,36 @@ +// CurveObject.cpp: implementation of the CurveObject class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "CurveObject.h" + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CurveObject::CurveObject() + // + // default constructor for cxxExchComp + // +{ + x.clear(); + y.clear(); + this->npoints_plot = 0; + this->npoints = 0; + this->nxy = 0; + this->prev_npoints = 0; + this->symbol = ""; + this->color = ""; + this->y_axis = 1; + this->line_w = 1.0; + this->symbol_size = 6.0; +} + + +CurveObject::~CurveObject() +{ +} + diff --git a/CurveObject.h b/CurveObject.h new file mode 100644 index 00000000..4f068692 --- /dev/null +++ b/CurveObject.h @@ -0,0 +1,90 @@ +#if !defined(CURVEOBJECT_H_INCLUDED) +#define CURVEOBJECT_H_INCLUDED +#include +#include + +class CurveObject +{ + +public: + CurveObject(); + ~CurveObject(); + void Set_id(std::string s) + { + this->id = s; + } + std::string &Get_id(void) + { + return this->id; + } + void Set_color(std::string s) + { + this->color = s; + } + std::string &Get_color(void) + { + return this->color; + } + void Set_symbol(std::string s) + { + this->symbol = s; + } + std::string &Get_symbol(void) + { + return this->symbol; + } + void Set_symbol_size(double f) + { + this->symbol_size = f; + } + double Get_symbol_size(void) + { + return this->symbol_size; + } + void Set_line_w(double f) + { + this->line_w = f; + } + double Get_line_w(void) + { + return this->line_w; + } + void Set_y_axis(int f) + { + this->y_axis = f; + } + std::vector & Get_x() + { + return this->x; + } + std::vector & Get_y() + { + return this->y; + } + int Get_y_axis() + { + return this->y_axis; + } + void Set_npoints_plot(int f) + { + this->npoints_plot = f; + } + int Get_npoints_plot(void) + { + return this->npoints_plot; + } + +protected: + //float *x, *y; + std::vector x, y; + int nxy, npoints, npoints_plot, prev_npoints; + + std::string id, color, symbol; + int y_axis; + double line_w, symbol_size; + +public: + +}; + +#endif // !defined(CURVEOBJECT_H_INCLUDED) From 8060c0654d75ba74952ddff8abcadab3e4acde4c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 May 2011 00:04:23 +0000 Subject: [PATCH 0205/1077] Removed chart files that were accidently checked in. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5364 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 65 ---- ChartHandler.h | 36 -- ChartObject.cpp | 854 ----------------------------------------------- ChartObject.h | 286 ---------------- CurveObject.cpp | 36 -- CurveObject.h | 90 ----- 6 files changed, 1367 deletions(-) delete mode 100644 ChartHandler.cpp delete mode 100644 ChartHandler.h delete mode 100644 ChartObject.cpp delete mode 100644 ChartObject.h delete mode 100644 CurveObject.cpp delete mode 100644 CurveObject.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp deleted file mode 100644 index 6bdd2a78..00000000 --- a/ChartHandler.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// ChartHandler.cpp: implementation of the ChartHandler class. -// -////////////////////////////////////////////////////////////////////// -#ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif -#include "ChartHandler.h" -#include - - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -ChartHandler::ChartHandler() - // - // default constructor for ChartHandler - // -{ - current_chart = NULL; - current_chart_n_user = -1000; - u_g_defined = false; -} - -ChartHandler::~ChartHandler() -{ -} - -bool -ChartHandler::Read(CParser &parser) -{ - int n_user; - std::string token; - - // reads line, next character is after keyword - parser.check_line("ChartHandler", true, false, true, false); - - std::istringstream iss(parser.line()); - // keyword - iss >> token; - // number - if (!(iss >> n_user)) - { - n_user = 1; - } - - // makes new ChartObject if necessary - std::map::iterator it = this->chart_map.find(n_user); - if (it == this->chart_map.end()) - { - ChartObject chart_obj; - chart_map[n_user] = chart_obj; - it = this->chart_map.find(n_user); - } - - // Read/update ChartObject - it->second.Read(parser); - current_chart_n_user = n_user; - current_chart = &it->second; - u_g_defined = true; - - return true; -} - - diff --git a/ChartHandler.h b/ChartHandler.h deleted file mode 100644 index 1901202f..00000000 --- a/ChartHandler.h +++ /dev/null @@ -1,36 +0,0 @@ -#if !defined(CHARTHANDLER_H_INCLUDED) -#define CHARTHANDLER_H_INCLUDED -#include -#include -#include -#include "Parser.h" -#include "ChartObject.h" - -class ChartHandler -{ - -public: - ChartHandler(); - ~ChartHandler(); - - size_t Get_chart_count() - { - return this->chart_map.size(); - } - ChartObject * Get_current_chart() - { - return this->current_chart; - } - bool Read(CParser &parser); - -protected: - std::map chart_map; - int current_chart_n_user; - ChartObject * current_chart; - bool u_g_defined; - -public: - -}; - -#endif // !defined(CHARTHANDLER_H_INCLUDED) diff --git a/ChartObject.cpp b/ChartObject.cpp deleted file mode 100644 index 1bb5bd7b..00000000 --- a/ChartObject.cpp +++ /dev/null @@ -1,854 +0,0 @@ -// ChartObject.cpp: implementation of the ChartObject class. -// -////////////////////////////////////////////////////////////////////// -#ifdef _DEBUG -#ifdef MULTICHART -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif -#include "Utils.h" -#include -#include "ChartObject.h" -#include "Parser.h" -#include -#include - -#ifdef PHREEQC_CLASS -#else -#include "phqalloc.h" -extern int error_msg(const char *err_str, const int stop, ...); -extern int warning_msg(const char *err_str, ...); -extern int rate_free(struct rate *rate_ptr); -#endif - -#include "Form2.h" -using namespace zdg_ui2; - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -ChartObject::ChartObject() - // - // default constructor for cxxExchComp - // -{ - new_ug = false; - FirstCallToUSER_GRAPH = true; - - update_time_chart = 150; - PanelHeight = 510; - PanelWidth = 640; - - Symbol_map["Square"] = 0; - Symbol_map["Diamond"] = 1; - Symbol_map["Triangle"] = 2; - Symbol_map["Circle"] = 3; - Symbol_map["XCross"] = 4; - Symbol_map["Plus"] = 5; - Symbol_map["Star"] = 6; - Symbol_map["TriangleDown"] = 7; - Symbol_map["HDash"] = 8; - Symbol_map["VDash"] = 9; - Symbol_map["None"] = 10; - - Color_vector.push_back("Red"); - Color_vector.push_back("Green"); - Color_vector.push_back("Blue"); - Color_vector.push_back("Orange"); - Color_vector.push_back("Magenta"); - Color_vector.push_back("Yellow"); - Color_vector.push_back("Black"); - - nCSV_headers = 0; - user_graph_headings.clear(); - chart_title.clear(); - axis_titles.clear(); - - int i; - for (i = 0; i < 5; i++) - { - axis_scale_x[i] = NA; - axis_scale_y[i] = NA; - axis_scale_y2[i] = NA; - } - - chart_type = 0; - graph_initial_solutions = false; - shifts_as_points = false; - rownr = -1; - colnr = 0; - RowOffset = 0; - ColumnOffset = 0; - prev_advection_step = 0; - prev_transport_step = 0; - AddSeries = true; - prev_sim_no = 0; - x_filled = false; - col_dwn = false; - y_filled.clear(); - x_value = NA; - bool all_points = false; - bool end_timer = false; - - graph_initial_solutions = true; - connect_simulations = true; - - ncurves_changed[0] = ncurves_changed[1] = ncurves_changed[2] = 0; - - user_graph.commands = NULL; - user_graph.name = NULL; - user_graph.new_def = 0; - user_graph.linebase = user_graph.loopbase = user_graph.varbase = NULL; - - default_symbol = 0; -} - -ChartObject::~ChartObject() -{ - // all data cleans itself up -} - -bool -ChartObject::Set_axis_scale(CParser & parser) -{ - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - double *scale_ptr = NULL; - std::vector string_vector; - size_t j = 0; - - // rereads option - parser.copy_token(token, next_char); - - // reads parameters - while ((j < 5) && (parser.copy_token(token, next_char)) != CParser::TT_EMPTY) - { - string_vector.push_back(token); - j++; - } - if (string_vector.size() == 0) - { - error_msg("No axis defined for scales", CParser::OT_CONTINUE); - return false; - } - std::string str = string_vector[0]; - std::string type; - // determine axis - switch (str[0]) - { - case 'X': - case 'x': - type = "x"; - scale_ptr = this->axis_scale_x; - break; - case 'Y': - case 'y': - type = "y"; - scale_ptr = this->axis_scale_y; - break; - case 'S': - case 's': - type = "sy"; - scale_ptr = this->axis_scale_y2; - break; - default: - std::ostringstream estream; - estream << "Found " << str; - estream << ", but expect axis type \'x\', \'y\', or \'sy\'."; - estream << std::endl; - error_msg("No axis defined for scales", CParser::OT_CONTINUE); - return false; - break; - } - - for (j = 1; j < string_vector.size() && j < 5; j++) - { - std::string s = string_vector[j]; - if (s[0] == 'a' || s[0] == 'A') - { - scale_ptr[j - 1] = NA; - } - else if (CParser::token_type(s) == CParser::TT_DIGIT) - { - scale_ptr[j - 1] = atof(s.c_str()); - } - else - { - std::ostringstream estream; - estream << "Found " << s; - estream << ", but expect number or 'a(uto)'."; - estream << std::endl; - error_msg(estream.str().c_str(), CONTINUE); - return false; - } - } - if (string_vector.size() == 5) - { - std::string s = string_vector[4]; - if (s[0] != 't' || s[0] != 'T') - { - scale_ptr[4] = 10.0; - if (((fabs(scale_ptr[0] - NA) > 1e-3) && scale_ptr[0] <=0) || - ((fabs(scale_ptr[1] - NA) > 1e-3) && scale_ptr[1] <=0)) - { - std::ostringstream estream; - estream << "MIN and MAX must be > 0 for log " << type << "-scale."; - estream << std::endl; - error_msg(estream.str().c_str(), CONTINUE); - return false; - } - - } - } - if ((fabs(scale_ptr[0] - NA) > 1e-3) && (fabs(scale_ptr[1] - NA) > 1e-3)) - { - if (scale_ptr[0] > scale_ptr[1]) - { - std::ostringstream estream; - estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl; - estream << "Switching values for MIN and MAX. " << std::endl; - warning_msg(estream.str().c_str()); - double t; - t = scale_ptr[0]; - scale_ptr[0] = scale_ptr[1]; - scale_ptr[1] = scale_ptr[0]; - return false; - } - } - return true; -} - -bool -ChartObject::Read(CParser & parser) -{ - - static std::vector < std::string > vopts; - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("start"); // 0 - vopts.push_back("end"); // 1 - vopts.push_back("heading"); // 2 - vopts.push_back("headings"); // 3 - vopts.push_back("chart_title"); // 4 - vopts.push_back("axis_titles"); // 5 - vopts.push_back("axis_scale"); // 6 - vopts.push_back("initial_solutions"); // 7 - vopts.push_back("plot_concentration_vs"); // 8 - vopts.push_back("shifts_as_points"); // 9 - vopts.push_back("grid_offset"); // 10 - vopts.push_back("connect_simulations"); // 11 - vopts.push_back("plot_csv_file"); // 12 - } - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); - if (this->Curves.size() > 0) - { - this->ncurves_changed[0] = 1; - this->ColumnOffset = ncurves_changed[2]; - this->new_ug = true; - } - - - // Read number and description - { - this->read_number_description(parser); - } - - opt_save = CParser::OPT_DEFAULT; - - 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_ERROR: - opt = CParser::OPT_EOF; - error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); - error_msg(parser.line().c_str(), CONTINUE); - useLastLine = false; - break; - case 0: /* start */ - opt_save = CParser::OPT_DEFAULT; - break; - case 1: /* end */ - opt_save = CParser::OPT_DEFAULT; - break; - case 2: /* headings */ - case 3: /* heading */ - while (parser.copy_token(token, next_char) != CParser::TT_EMPTY) - { - this->user_graph_headings.push_back(token); - } - break; - case 4: /* chart title */ - { - std::string l = parser.line(); - std::string tok; - std::string::iterator b = l.begin(); - std::string::iterator e = l.end(); - parser.copy_title(tok, b, e); - this->chart_title = tok; - } - break; - case 5: /* axis titles */ - { - std::string l; - parser.get_rest_of_line(l); - std::string tok; - std::string::iterator b = l.begin(); - std::string::iterator e = l.end(); - this->axis_titles.clear(); - while(parser.copy_title(tok, b, e) != CParser::TT_EMPTY) - { - this->axis_titles.push_back(tok); - } - } - break; - case 6: /* axis scales */ - { - this->Set_axis_scale(parser); - } - break; - case 7: /* initial_solutions */ - this->graph_initial_solutions = parser.get_true_false(next_char, FALSE); - break; - case 8: /* plot_concentration_vs */ - //prev_next_char = next_char; - parser.copy_token(token, next_char); - Utilities::str_tolower(token); - if (token[0] == 'x' || token[0] == 'd') - chart_type = 0; - else if (token[0] == 't') - chart_type = 1; - else - { - std::ostringstream estream; - estream << "Found " << token << ", but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time."; - error_msg(estream.str().c_str(), CONTINUE); - } - break; - case 9: /* shifts_as_points */ - this->shifts_as_points = parser.get_true_false(next_char, true); - if (this->shifts_as_points) - this->chart_type = 0; - else - this->chart_type = 1; - break; - case 10: /* grid_offset */ -#ifdef PHREEQ98 - /* - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &RowOffset); - i = copy_token(token, &next_char, &l); - str_tolower(token); - if (i == DIGIT) - sscanf(token, "%d", &ColumnOffset); - */ -#endif - break; - case 11: /* connect_simulations */ - this->connect_simulations = parser.get_true_false(next_char, true); - break; - case 12: /* plot_csv_file */ - { - std::string file_name; - parser.get_rest_of_line(file_name); - file_name = trim(file_name); - this->OpenCSVFile(file_name); - } - break; - /* End of modifications */ - case CParser::OPT_DEFAULT: // Read Basic commands - { - this->rate_new_def = true; - /* read command */ - std::string cmd(parser.line()); - std::string cmd_lower = cmd; - Utilities::str_tolower(cmd_lower); - if ((cmd_lower.find("graph_y") != std::string::npos) || - (cmd_lower.find("graph_sy") != std::string::npos)) - { - CurveInfonr++; - } - if (cmd_lower.find("plot_xy") != std::string::npos) - { - ExtractCurveInfo(cmd); // truncates cmd - CurveInfonr++; - } - this->rate_command_list.push_back(cmd); - } - opt_save = CParser::OPT_DEFAULT; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } - - this->Set_rate_struct(); - return true; -} - -bool -ChartObject::OpenCSVFile(std::string file_name) -{ - std::string token; - - std::ifstream f_csv(file_name.c_str(), std::ifstream::in); - - if (!f_csv.is_open()) - { - std::ostringstream estream; - estream << "Could not open csv file for USER_GRAPH " << file_name; - error_msg(estream.str().c_str(), CONTINUE); - return false; - } - - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(f_csv, oss_out, oss_err); - - /* Get lines */ - int linenr = 0; - std::vector headings; - std::vector csv_curves; - while (parser.check_line("cvs file", false, true, true, false) != CParser::LT_EOF) - { - // Headings line - if (linenr == 0) - { - // Skip x in 1st column - parser.get_iss() >> token; - while (parser.get_iss() >> token) - { - headings.push_back(token); - } - nCSV_headers = (int) headings.size(); - this->ColumnOffset = nCSV_headers; - - // add new headers to beginning of list - std::vector old_headings = this->user_graph_headings; - this->user_graph_headings.clear(); - this->user_graph_headings = headings; - std::vector::iterator it = old_headings.begin(); - for (; it != old_headings.end(); it++) - { - this->user_graph_headings.push_back(*it); - } - - // add new curves - size_t i; - for (i = 0; i < headings.size(); i++) - { - CurveObject c; - c.Set_id(headings[i]); - csv_curves.push_back(c); - } - - linenr++; - continue; - } - - token = parser.line(); - std::string tok1; - CParser::TOKEN_TYPE tt = CParser::parse_delimited(token, tok1, "\t"); - - // Curve properties lines - if (linenr < 6 && tt != CParser::TT_DIGIT) - { - Utilities::str_tolower(tok1); - std::string tok2; - size_t i=0; - while (token.size() != 0 && i < csv_curves.size()) - { - CParser::parse_delimited(token, tok2, "\t"); - if (!strncmp(tok1.c_str(), "color", 5)) - { - csv_curves[i].Set_color(tok2); - } - else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) - && (strstr(tok1.c_str(), "-si") == NULL)) - { - csv_curves[i].Set_symbol(tok2); - } - else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) - { - csv_curves[i].Set_symbol_size(atof(tok2.c_str())); - } - else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) - { - csv_curves[i].Set_line_w(atof(tok2.c_str())); - } - else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) - { - csv_curves[i].Set_y_axis(atoi(tok2.c_str())); - } - i++; - } - linenr++; - continue; - } - - // Curve data - if (linenr < 6) linenr = 6; - if (tt != CParser::TT_DIGIT) - { - linenr++; - continue; - } - - // x value for all curves - double x_value = atof(tok1.c_str()); - - // y values for curves - std::string tok2; - size_t i=0; - while (token.size() != 0 && i < csv_curves.size()) - { - CParser::parse_delimited(token, tok2, "\t"); - Utilities::squeeze_white(tok2); - if (tok2.size() == 0) - { - csv_curves[i].Get_x().push_back(NA); - csv_curves[i].Get_x().push_back(NA); - } - else - { - csv_curves[i].Get_x().push_back(x_value); - csv_curves[i].Get_y().push_back(atof(tok2.c_str())); - } - i++; - } - linenr++; - } - - // Prepend new curves - std::vector old_curves = this->Curves; - this->Curves.clear(); - this->Curves = csv_curves; - - std::vector::iterator it = old_curves.begin(); - for (; it != old_curves.end(); it++) - { - this->Curves.push_back(*it); - } - return true; -} - -void -ChartObject::ExtractCurveInfo(std::string & cmd_line) -{ - /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ - - // Make copy of cmd_line - int curvenr = (int) this->Curves.size(); - std::string str_line = cmd_line; - - // find command part of cmd_line - Utilities::replace(",","#",cmd_line); - size_t pos = cmd_line.find(","); - if (pos != std::string::npos) - { - cmd_line = cmd_line.substr(0, pos); - Utilities::replace("#",",",cmd_line); - str_line.erase(0, pos + 1); - } - else - { - error_msg("Did not find x and y expressions for plot_xy command in USER_GRAPH", STOP); - } - - // new curve - CurveObject new_curve; - - // process plot_xy options - while (Utilities::replace(" ","#",str_line)); - while (Utilities::replace("\t","#",str_line)); - std::string tok; - std::string::iterator b = str_line.begin(); - std::string::iterator e = str_line.end(); - - while (CParser::copy_title(tok, b, e) != CParser::TT_EMPTY) - { - while (Utilities::replace("#"," ",tok)); - while (Utilities::replace("="," ",tok)); - std::string::iterator b1 = tok.begin(); - std::string::iterator e1 = tok.end(); - std::string tok1, tok2; - CParser::copy_token(tok1, b1, e1); - Utilities::str_tolower(tok1); - CParser::copy_token(tok2, b1, e1); - if (!strncmp(tok1.c_str(), "color", 5)) - { - //Curves[curvenr + ColumnOffset].Set_color(tok2); - new_curve.Set_color(tok2); - continue; - } - else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) - && (strstr(tok1.c_str(), "-si") == NULL)) - { - new_curve.Set_symbol(tok2); - continue; - } - else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) - { - new_curve.Set_symbol_size(atof(tok2.c_str())); - continue; - } - else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) - { - new_curve.Set_line_w(atof(tok2.c_str())); - continue; - } - else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) - { - new_curve.Set_y_axis(atoi(tok2.c_str())); - continue; - } - else - { - std::ostringstream estream; - estream << "Unknown input for plot_xy in USER_GRAPH " << tok << std::endl; - warning_msg(estream.str().c_str()); - continue; - } - } - - // Add new curve to chart - this->Curves.push_back(new_curve); -} -void -ChartObject::Set_rate_struct(void) -{ - rate_free(&user_graph); - - std::list::iterator it = rate_command_list.begin(); - std::ostringstream oss; - for (; it != rate_command_list.end(); it++) - { - oss << *it << std::endl; - } - this->user_graph.commands = (char *) PHRQ_malloc((strlen(oss.str().c_str()) + 2) * sizeof(char)); - ::strcpy(this->user_graph.commands, oss.str().c_str()); - this->user_graph.new_def = this->rate_new_def; - this->user_graph.loopbase = NULL; - this->user_graph.varbase = NULL; - this->user_graph.linebase = NULL; - this->user_graph.name = NULL; -} -ZedGraph::SymbolType -ChartObject::Return_SymbolType(const std::string sym) -{ - int i; - std::map::iterator it; - if (this->Symbol_map.find(sym) != this->Symbol_map.end()) - { - i = it->second; - } - else - { - i = default_symbol++; - default_symbol = default_symbol % this->Symbol_map.size(); - } - - switch (i) - { - case 0: - return SymbolType::Square; - break; - case 1: - return SymbolType::Diamond; - break; - case 2: - return SymbolType::Triangle; - break; - case 3: - return SymbolType::Circle; - break; - case 4: - return SymbolType::XCross; - break; - case 5: - return SymbolType::Plus; - break; - case 6: - return SymbolType::Star; - break; - case 7: - return SymbolType::TriangleDown; - break; - case 8: - return SymbolType::HDash; - break; - case 9: - return SymbolType::VDash; - break; - case 10: - return SymbolType::None; - break; - default: - return SymbolType::Default; - break; - } -} -void -ChartObject::SaveCurvesToFile(std::string &) -{ -} -void -ChartObject::PlotXY(std::string x, std::string y) -{ - /* Attribute values from *x and *y to Curves(*x, *y) */ - int curvenr = colnr + ColumnOffset; - -#ifdef SKIP - int i, i2, i3; - bool new_sim = false, new_trans = false; - if ((state == TRANSPORT && transport_step != prev_transport_step) || - (state == ADVECTION && advection_step != prev_advection_step)) - new_trans = true; - if (FirstCallToUSER_GRAPH && colnr == 0) - prev_sim_no = simulation; - else - if (!rownr && (simulation != prev_sim_no || new_trans)) - { - new_sim = true; - if (!connect_simulations) - AddSeries = TRUE; - } - prev_sim_no = simulation; - - int curvenr = colnr + ColumnOffset; - - if (curvenr >= ncurves) - ReallocCurves(0); - if (curvenr + 1 > ncurves_changed[2]) /* timer must recall DefineCurves in Form */ - { - ncurves_changed[0] = 1; - ncurves_changed[1] = ncurves_changed[2]; - ncurves_changed[2] = curvenr + 1; - } - if (x_filled && user_graph_count_headings > curvenr + ColumnOffset) - { - PHRQ_free(Curves[curvenr + ColumnOffset].id); - Curves[curvenr + ColumnOffset].id = - string_duplicate(user_graph_headings[curvenr + ColumnOffset]); - } - - /* If a new simulation, create new set of curves, - define identifiers, y axis from values set in ExtractCurveInfo... */ - if (rownr == 0 && colnr == 0) - { - if (new_sim && AddSeries && (!connect_simulations || new_ug)) - { /* step to new curveset... */ - if (Curves[ncurves - 1].npoints) - ReallocCurves(ncurves * 2); - for (i = curvenr; i < ncurves; i++) - { - if (Curves[i].npoints) - continue; - else - { - /* curve i is free... */ - i2 = i3 = ColumnOffset; - ColumnOffset = curvenr = i; - break; - } - } - if (new_trans && !new_ug) i3 = 0; - if (new_ug) i2 = 0; - /* fill in curve properties... */ - for (i = ColumnOffset; i < ColumnOffset + (ColumnOffset - i2); i++) - { - if (i >= ncurves) - ReallocCurves(0); - /* define the new curve... */ - if (i3 < user_graph_count_headings) - { - PHRQ_free(Curves[i].id); - Curves[i].id = string_duplicate(user_graph_headings[i3]); - } - //Curves[i].color = Curves[i3].color; - //Curves[i].line_w = Curves[i3].line_w; - //Curves[i].symbol = Curves[i3].symbol; - //Curves[i].symbol_size = Curves[i3].symbol_size; - Curves[i].y_axis = Curves[i3].y_axis; - i3++; - } - } - /* Or, add all to existing set... */ - else if (new_sim) - { - RowOffset = 1; - for (i = 0; i < ncurves; i++) Curves[i].prev_npoints = Curves[i].npoints; - } - new_ug = false; - } -#endif - /* return if x or y is a zero... */ - if (x.size() == 0 || y.size() == 0) return; - - /* fill in Curves(x, y)... */ - //if (Curves[curvenr].npoints >= Curves[curvenr].nxy) - // ReallocCurveXY(curvenr); - Curves[curvenr].Get_x().push_back(atof(x.c_str())); - Curves[curvenr].Get_y().push_back(atof(y.c_str())); - //Curves[curvenr].npoints++; - -} - - -bool -ChartObject::start_chart(void) -{ - //if (end) - // goto end_chart; - Application::EnableVisualStyles(); - Application::SetCompatibleTextRenderingDefault(true); - -#if defined(PHREEQC_CLASS) - Thread ^t = gcnew Thread( - gcnew ParameterizedThreadStart(Form1::ThreadForm)); -#else - Thread ^t = gcnew Thread( - gcnew ParameterizedThreadStart(Form1::ThreadForm)); -#endif -//#else -// Thread ^t = gcnew Thread( gcnew ThreadStart( &Form1::ThreadForm)); -//#endif - t->SetApartmentState(ApartmentState::STA); - t->IsBackground = false; - t->Priority = ThreadPriority::Normal; -#if PHREEQC_CLASS - PhreeqcObj ^p = gcnew PhreeqcObj(this); - t->Start(p); -#else - t->Start(); -#endif - //Thread::Sleep( 1 ); /* this when debugging... */ - //_beginthread(void (Form1::ThreadForm), 0, NULL); - return true; -} -#endif // MULTICHART \ No newline at end of file diff --git a/ChartObject.h b/ChartObject.h deleted file mode 100644 index dbc5013a..00000000 --- a/ChartObject.h +++ /dev/null @@ -1,286 +0,0 @@ -#if !defined(CHARTOBJECT_H_INCLUDED) -#define CHARTOBJECT_H_INCLUDED -#include -#include -#include -#include -#include "CurveObject.h" -#include "global_structures.h" -#include "NumKeyword.h" -//#include "Parser.h" -#include - -//#define NA (float) -9.9999 /* NA = not available */ -class ChartObject:public cxxNumKeyword -{ - - public: - ChartObject(); - ChartObject(int i); - ~ChartObject(); - - // new_ug - bool Get_new_ug() - { - return this->new_ug; - } - void Set_new_ug(bool b) - { - this->new_ug = b; - } - // bool FirstCallToUSER_GRAPH; - void Set_FirstCallToUSER_GRAPH(bool b) - { - this->FirstCallToUSER_GRAPH = b; - } - bool Get_FirstCallToUSER_GRAPH() - { - return this->FirstCallToUSER_GRAPH; - } - // int update_time_chart; - int Get_update_time_chart() - { - return (this->update_time_chart); - } - // PanelHeight - int Get_PanelHeight() - { - return (this->PanelHeight); - } - // PanelWidth - int Get_PanelWidth() - { - return (this->PanelWidth); - } - // Symbol_map - // std::vector Color_vector; - // int nCSV_headers; - // std::vector user_graph_headings; - std::vector &Get_user_graph_headings() - { - return this->user_graph_headings; - } - // std::string chart_title; - std::string &Get_chart_title() - { - return this->chart_title; - } - // std::vector axis_titles; - std::vector &Get_axis_titles() - { - return this->axis_titles; - } - // double axis_scale_x[5]; - double *Get_axis_scale_x() - { - return this->axis_scale_x; - } - // double axis_scale_y[5]; - double *Get_axis_scale_y() - { - return this->axis_scale_y; - } - // double axis_scale_y2[5]; - double *Get_axis_scale_y2() - { - return this->axis_scale_y2; - } - // int chart_type; - int Get_chart_type() - { - return this->chart_type; - } - // bool graph_initial_solutions; - bool Get_graph_initial_solutions() - { - return this->graph_initial_solutions; - } - // bool connect_simulations; - bool Get_connect_simulations() - { - return this->connect_simulations; - } - // int shifts_as_points; - // int rownr; - void Set_rownr(int i) - { - this->rownr = i; - } - int Get_rownr() - { - return (this->rownr); - } - // int colnr; - void Set_colnr(int i) - { - this->colnr = i; - } - int Get_colnr() - { - return (this->colnr); - } - // int RowOffset; - // int ColumnOffset; - - // int prev_advection_step; - void Set_prev_advection_step(int i) - { - this->prev_advection_step = i; - } - int Get_prev_advection_step() - { - return (this->prev_advection_step); - } - // int prev_transport_step; - void Set_prev_transport_step(int i) - { - this->prev_transport_step = i; - } - int Get_prev_transport_step() - { - return (this->prev_transport_step); - } - // bool AddSeries; - void Set_AddSeries(bool b) - { - this->AddSeries = b; - } - bool Get_AddSeries(void) - { - return this->AddSeries; - } - // int prev_sim_no; - // bool x_filled; - // bool col_dwn; - // std::vector y_filled; - // double x_value; - // bool all_points; - void Set_all_points(bool tf) - { - this->all_points = tf; - } - bool Get_all_points() - { - return this->all_points; - } - // bool end_timer; - bool Get_end_timer() - { - return this->end_timer; - } - // std::vector Curves; - std::vector &Get_Curves() - { - return this->Curves; - } - // int ncurves_changed[3]; - int *Get_ncurves_changed() - { - return (this->ncurves_changed); - } - void Set_ncurves_changed_0(int i) - { - this->ncurves_changed[0] = i; - } - // int CurveInfonr; - - // struct rate user_graph; - struct rate *Get_user_graph() - { - return &this->user_graph; - } - // C++ for rate struct - // std::string rate_name; - // std::list rate_command_list; - std::list &Get_rate_command_list() - { - return this->rate_command_list; - } - // bool rate_new_def; - void Set_rate_new_def(bool tf) - { - this->rate_new_def = tf; - if (tf) - { - this->user_graph.new_def = 1; - } - else - { - this->user_graph.new_def = 0; - } - } - bool Get_rate_new_def() - { - return this->rate_new_def; - } - // int default_symbol; - - - - - bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); - bool Set_axis_scale(CParser & parser); - bool Read(CParser & parser); - bool OpenCSVFile(std::string fn); - void ExtractCurveInfo(std::string & str_line); - void Set_rate_struct(void); - void PlotXY(std::string x, std::string y); - bool start_chart(void); - ZedGraph::SymbolType Return_SymbolType(std::string); - void SaveCurvesToFile(std::string &); - protected: - - bool new_ug; - bool FirstCallToUSER_GRAPH; - - int update_time_chart; /* milliseconds, maybe read */ - int PanelHeight; - int PanelWidth; - std::map Symbol_map; - std::vector Color_vector; - int nCSV_headers; - std::vector user_graph_headings; - std::string chart_title; - std::vector axis_titles; - double axis_scale_x[5]; - double axis_scale_y[5]; - double axis_scale_y2[5]; - - int chart_type; - bool graph_initial_solutions; - bool connect_simulations; - int shifts_as_points; - int rownr; - int colnr; - int RowOffset; - int ColumnOffset; - - int prev_advection_step; - int prev_transport_step; - bool AddSeries; - - int prev_sim_no; - bool x_filled; - bool col_dwn; - std::vector y_filled; - double x_value; - bool all_points; - bool end_timer; - - std::vector Curves; - int ncurves_changed[3]; - int CurveInfonr; - - struct rate user_graph; - // C++ for rate struct - std::string rate_name; - std::list rate_command_list; - bool rate_new_def; - - int default_symbol; - - public: - -}; - -#endif // !defined(CHARTOBJECT_H_INCLUDED) diff --git a/CurveObject.cpp b/CurveObject.cpp deleted file mode 100644 index 37ff7fbd..00000000 --- a/CurveObject.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// CurveObject.cpp: implementation of the CurveObject class. -// -////////////////////////////////////////////////////////////////////// -#ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif -#include "CurveObject.h" - - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CurveObject::CurveObject() - // - // default constructor for cxxExchComp - // -{ - x.clear(); - y.clear(); - this->npoints_plot = 0; - this->npoints = 0; - this->nxy = 0; - this->prev_npoints = 0; - this->symbol = ""; - this->color = ""; - this->y_axis = 1; - this->line_w = 1.0; - this->symbol_size = 6.0; -} - - -CurveObject::~CurveObject() -{ -} - diff --git a/CurveObject.h b/CurveObject.h deleted file mode 100644 index 4f068692..00000000 --- a/CurveObject.h +++ /dev/null @@ -1,90 +0,0 @@ -#if !defined(CURVEOBJECT_H_INCLUDED) -#define CURVEOBJECT_H_INCLUDED -#include -#include - -class CurveObject -{ - -public: - CurveObject(); - ~CurveObject(); - void Set_id(std::string s) - { - this->id = s; - } - std::string &Get_id(void) - { - return this->id; - } - void Set_color(std::string s) - { - this->color = s; - } - std::string &Get_color(void) - { - return this->color; - } - void Set_symbol(std::string s) - { - this->symbol = s; - } - std::string &Get_symbol(void) - { - return this->symbol; - } - void Set_symbol_size(double f) - { - this->symbol_size = f; - } - double Get_symbol_size(void) - { - return this->symbol_size; - } - void Set_line_w(double f) - { - this->line_w = f; - } - double Get_line_w(void) - { - return this->line_w; - } - void Set_y_axis(int f) - { - this->y_axis = f; - } - std::vector & Get_x() - { - return this->x; - } - std::vector & Get_y() - { - return this->y; - } - int Get_y_axis() - { - return this->y_axis; - } - void Set_npoints_plot(int f) - { - this->npoints_plot = f; - } - int Get_npoints_plot(void) - { - return this->npoints_plot; - } - -protected: - //float *x, *y; - std::vector x, y; - int nxy, npoints, npoints_plot, prev_npoints; - - std::string id, color, symbol; - int y_axis; - double line_w, symbol_size; - -public: - -}; - -#endif // !defined(CURVEOBJECT_H_INCLUDED) From 2a491b71a40e4965377ff1690e99f25b610a0e47 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 May 2011 00:24:40 +0000 Subject: [PATCH 0206/1077] merged MULTICHART branch back to trunk git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5365 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 167 +++++++ ChartHandler.h | 44 ++ ChartObject.cpp | 968 +++++++++++++++++++++++++++++++++++ ChartObject.h | 380 ++++++++++++++ CurveObject.cpp | 37 ++ CurveObject.h | 90 ++++ Parser.cxx | 93 ++++ Parser.h | 11 +- Phreeqc.cpp | 4 +- Phreeqc.h | 12 +- Phreeqc_class.h | 2 +- ReadClass.cxx | 57 ++- SAXPhreeqc.cxx | 1136 ------------------------------------------ SAXPhreeqc.h | 21 - SaxPhreeqcHandlers.h | 206 -------- Utils.cxx | 15 +- char_star.h | 16 - 17 files changed, 1866 insertions(+), 1393 deletions(-) create mode 100644 ChartHandler.cpp create mode 100644 ChartHandler.h create mode 100644 ChartObject.cpp create mode 100644 ChartObject.h create mode 100644 CurveObject.cpp create mode 100644 CurveObject.h delete mode 100644 SAXPhreeqc.cxx delete mode 100644 SAXPhreeqc.h delete mode 100644 SaxPhreeqcHandlers.h delete mode 100644 char_star.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp new file mode 100644 index 00000000..7b8a60cd --- /dev/null +++ b/ChartHandler.cpp @@ -0,0 +1,167 @@ +// ChartHandler.cpp: implementation of the ChartHandler class. +// +////////////////////////////////////////////////////////////////////// +#if defined MULTICHART +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "ChartHandler.h" +#include "phreeqc_class.h" +#if defined PHREEQC_CLASS +#include "phreeqc.h" +#else +extern int punch_user_graph(void); +extern int error_msg(const char *err_str, const int stop, ...); +#endif +#include + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +ChartHandler::ChartHandler() + // + // default constructor for ChartHandler + // +{ + current_chart = NULL; + current_chart_n_user = -1000; + u_g_defined = false; + timer = true; +} + +ChartHandler::~ChartHandler() +{ + std::map::iterator it; + for (it = this->chart_map.begin(); it != chart_map.end(); it++) + { + it->second->Rate_free(); + delete it->second; + } +} +void +ChartHandler::Punch_user_graph(PHREEQC_PTR_ARG) +{ + std::map::iterator it = this->chart_map.begin(); + for ( ; it != chart_map.end(); it++) + { + if (it->second->Get_active()) + { + while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) + System::Threading::Thread::Sleep(1); + this->current_chart = it->second; + P_INSTANCE_POINTER punch_user_graph(); + System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + } + } +} + +bool +ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) +{ + int n_user; + std::string token; + + // reads line, next character is after keyword + parser.check_line("ChartHandler", true, false, true, false); + + std::istringstream iss(parser.line()); + // keyword + iss >> token; + // number + if (!(iss >> n_user)) + { + n_user = 1; + } + + // makes new ChartObject if necessary + std::map::iterator it = this->chart_map.find(n_user); + if (it == this->chart_map.end()) + { + chart_map[n_user] = new ChartObject(); + it = this->chart_map.find(n_user); +#ifdef PHREEQC_CLASS + it->second->Set_phreeqc(P_INSTANCE); +#endif + } + + // Read/update ChartObject + while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) + System::Threading::Thread::Sleep(1); + { + it->second->Read(parser); + current_chart_n_user = n_user; + current_chart = it->second; + u_g_defined = true; + } + + // if detached, set timer_end and free + if (it->second->Get_detach() && it->second->Get_form_started()) + { + it->second->Set_end_timer(true); + it->second->Rate_free(); + } + + // Release lock + System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + + // if detached, wait for thread to acknowledge and then erase chart + if (it->second->Get_detach()) + { + while (it->second->Get_form_started() && it->second->Get_done() != true) + { + System::Threading::Thread::Sleep(1); + } + delete it->second; + this->chart_map.erase(it); + } + return true; +} +bool +ChartHandler::End_timer(PHREEQC_PTR_ARG) +{ + + size_t max_tries = 1000; + std::map::iterator it = this->chart_map.begin(); + + for ( ; it != chart_map.end(); it++) + { + //{ + // std::vector::iterator cit = it->second->Get_Curves().begin(); + // size_t i; + // for (i = 0; i < it->second->Get_Curves().size(); i ++) + // { + // std::cerr << "Curve " << i << ", number of points " << it->second->Get_Curves()[i]->Get_x().size() << std::endl; + // } + //} + size_t i = 0; + if (it->second->Get_form_started()) + { + while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1) && i < max_tries) + { + i++; + System::Threading::Thread::Sleep(1); + } + it->second->Set_end_timer(true); + it->second->Rate_free(); + System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + + size_t i2 = 0; + while (it->second->Get_done() != true && i2 < max_tries) + { + i2++; + System::Threading::Thread::Sleep(1); + } + if (i >= max_tries || i2 >= max_tries) + { + P_INSTANCE_POINTER error_msg("Chart did not respond.", CONTINUE); + } + } + } + this->timer = false; + + return true; +} +#endif + diff --git a/ChartHandler.h b/ChartHandler.h new file mode 100644 index 00000000..40eb295e --- /dev/null +++ b/ChartHandler.h @@ -0,0 +1,44 @@ +#if !defined(CHARTHANDLER_H_INCLUDED) +#define CHARTHANDLER_H_INCLUDED +#if defined MULTICHART +#include +#include +#include +#include "Parser.h" +#include "ChartObject.h" + +class ChartHandler +{ + +public: + ChartHandler(); + ~ChartHandler(); + + size_t Get_chart_count() + { + return this->chart_map.size(); + } + ChartObject * Get_current_chart() + { + return this->current_chart; + } + bool Get_timer() + { + return timer; + } + bool Read(PHREEQC_PTR_ARG_COMMA CParser &parser); + void Punch_user_graph(PHREEQC_PTR_ARG); + bool End_timer(PHREEQC_PTR_ARG); + +protected: + std::map chart_map; + int current_chart_n_user; + ChartObject * current_chart; + bool u_g_defined; + bool timer; + +public: + +}; +#endif // MULTICHART +#endif // !defined(CHARTHANDLER_H_INCLUDED) diff --git a/ChartObject.cpp b/ChartObject.cpp new file mode 100644 index 00000000..d5906426 --- /dev/null +++ b/ChartObject.cpp @@ -0,0 +1,968 @@ +// ChartObject.cpp: implementation of the ChartObject class. +// +////////////////////////////////////////////////////////////////////// +#ifdef MULTICHART +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "Utils.h" +#include +#include "ChartObject.h" +#include "Parser.h" +#include +#include +#include +#ifdef PHREEQC_CLASS +#include "Phreeqc_class.h" +#include "Phreeqc.h" +#else +#include "phqalloc.h" +extern int error_msg(const char *err_str, const int stop, ...); +extern int warning_msg(const char *err_str, ...); +extern int rate_free(struct rate *rate_ptr); +extern int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +extern void * free_check_null(void *); +#endif +#include "phqalloc.h" +#include "phrqproto.h" +#include "output.h" +#include "Form2.h" +using namespace zdg_ui2; + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +ChartObject::ChartObject() + // + // default constructor for cxxExchComp + // +{ + new_ug = false; + FirstCallToUSER_GRAPH = true; + + update_time_chart = 150; + PanelHeight = 510; + PanelWidth = 640; + + Symbol_map["Square"] = 0; + Symbol_map["Diamond"] = 1; + Symbol_map["Triangle"] = 2; + Symbol_map["Circle"] = 3; + Symbol_map["XCross"] = 4; + Symbol_map["Plus"] = 5; + Symbol_map["Star"] = 6; + Symbol_map["TriangleDown"] = 7; + Symbol_map["HDash"] = 8; + Symbol_map["VDash"] = 9; + Symbol_map["None"] = 10; + + Color_vector.push_back("Red"); + Color_vector.push_back("Green"); + Color_vector.push_back("Blue"); + Color_vector.push_back("Orange"); + Color_vector.push_back("Magenta"); + Color_vector.push_back("Yellow"); + Color_vector.push_back("Black"); + + chart_title.clear(); + axis_titles.clear(); + + int i; + for (i = 0; i < 5; i++) + { + axis_scale_x[i] = NA; + axis_scale_y[i] = NA; + axis_scale_y2[i] = NA; + } + + chart_type = 0; + graph_initial_solutions = false; + shifts_as_points = false; + connect_simulations = true; + colnr = 0; + RowOffset = 0; + ColumnOffset = 0; + prev_advection_step = 0; + prev_transport_step = 0; + prev_sim_no = 0; + end_timer = false; + done = false; + + curve_added = false; + point_added = false; + + user_graph = new rate; + user_graph->commands = NULL; + user_graph->name = NULL; + user_graph->new_def = 0; + user_graph->linebase = user_graph->loopbase = user_graph->varbase = NULL; + + default_symbol = 0; + + graph_x = NA; + graph_y.clear(); + secondary_y.clear(); + + usingResource = 0; + form_started = false; + active = true; + detach = false; +} + +ChartObject::~ChartObject() +{ + delete this->user_graph; + + std::vector::iterator it; + for (it = this->CurvesCSV.begin(); it != CurvesCSV.end(); it++) + { + delete *it; + } + + for (it = this->Curves.begin(); it != Curves.end(); it++) + { + delete *it; + } +} + +bool +ChartObject::Set_axis_scale(CParser & parser) +{ + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + double *scale_ptr = NULL; + std::vector string_vector; + size_t j = 0; + + // rereads option + parser.copy_token(token, next_char); + + // reads parameters + while ((j < 6) && (parser.copy_token(token, next_char)) != CParser::TT_EMPTY) + { + string_vector.push_back(token); + j++; + } + if (string_vector.size() == 0) + { + P_INSTANCE_POINTER error_msg("No axis defined for scales", CParser::OT_CONTINUE); + return false; + } + std::string str = string_vector[0]; + std::string type; + Utilities::str_tolower(str); + if (str.substr(0,2) == "y2" || str.substr(0,1) == "s") + { + type = "sy"; + scale_ptr = this->axis_scale_y2; + } + else if (str.substr(0,1) == "y") + { + type = "y"; + scale_ptr = this->axis_scale_y; + } + else if (str.substr(0,1) == "x") + { + type = "x"; + scale_ptr = this->axis_scale_x; + } + else + { + std::ostringstream estream; + estream << "Found " << str; + estream << ", but expect axis type \'x\', \'y\', \'y2\'or \'sy\'."; + estream << std::endl; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CParser::OT_CONTINUE); + return false; + } + + for (j = 1; j < string_vector.size() && j < 5; j++) + { + std::string s = string_vector[j]; + if (s[0] == 'a' || s[0] == 'A') + { + scale_ptr[j - 1] = NA; + } + else if (CParser::token_type(s) == CParser::TT_DIGIT) + { + scale_ptr[j - 1] = atof(s.c_str()); + } + else + { + std::ostringstream estream; + estream << "Found " << s; + estream << ", but expect number or 'a(uto)'."; + estream << std::endl; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + return false; + } + } + if (string_vector.size() == 6) + { + std::string s = string_vector[5]; + if (s[0] != 't' || s[0] != 'T' || s[0] != 'l' || s[0] != 'L') + { + scale_ptr[4] = 10.0; + if (((fabs(scale_ptr[0] - NA) > 1e-3) && scale_ptr[0] <=0) || + ((fabs(scale_ptr[1] - NA) > 1e-3) && scale_ptr[1] <=0)) + { + std::ostringstream estream; + estream << "MIN and MAX must be > 0 for log " << type << "-scale."; + estream << std::endl; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + return false; + } + + } + } + if ((fabs(scale_ptr[0] - NA) > 1e-3) && (fabs(scale_ptr[1] - NA) > 1e-3)) + { + if (scale_ptr[0] > scale_ptr[1]) + { + std::ostringstream estream; + estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl; + estream << "Switching values for MIN and MAX. " << std::endl; + P_INSTANCE_POINTER warning_msg(estream.str().c_str()); + double t; + t = scale_ptr[0]; + scale_ptr[0] = scale_ptr[1]; + scale_ptr[1] = scale_ptr[0]; + return false; + } + } + return true; +} + +bool +ChartObject::Read(CParser & parser) +{ + + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("start"); // 0 + vopts.push_back("end"); // 1 + vopts.push_back("heading"); // 2 + vopts.push_back("headings"); // 3 + vopts.push_back("chart_title"); // 4 + vopts.push_back("axis_titles"); // 5 + vopts.push_back("axis_scale"); // 6 + vopts.push_back("initial_solutions"); // 7 + vopts.push_back("plot_concentration_vs"); // 8 + vopts.push_back("shifts_as_points"); // 9 + vopts.push_back("grid_offset"); // 10 + vopts.push_back("connect_simulations"); // 11 + vopts.push_back("plot_csv_file"); // 12 + vopts.push_back("clear"); // 13 + vopts.push_back("detach"); // 14 + } + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + bool new_command_lines(true); + if (this->FirstCallToUSER_GRAPH) + { + } + else + { + this->ColumnOffset = this->Curves.size(); + this->new_ug = true; + } + this->new_plotxy_curves.clear(); + //this->new_headings.clear(); + + // Read number and description + { + this->read_number_description(parser); + } + + opt_save = CParser::OPT_DEFAULT; + + 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_ERROR: + opt = CParser::OPT_EOF; + P_INSTANCE_POINTER error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); + P_INSTANCE_POINTER error_msg(parser.line().c_str(), CONTINUE); + useLastLine = false; + break; + case 0: /* start */ + opt_save = CParser::OPT_DEFAULT; + break; + case 1: /* end */ + opt_save = CParser::OPT_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading */ + while (parser.copy_token(token, next_char) != CParser::TT_EMPTY) + { + this->new_headings.push_back(token); + } + break; + case 4: /* chart title */ + { + std::string tok; + parser.get_rest_of_line(tok); + CParser::copy_title(this->chart_title, tok.begin(), tok.end()); + } + break; + case 5: /* axis titles */ + { + this->axis_titles.clear(); + std::string l; + parser.get_rest_of_line(l); + std::string tok; + std::string::iterator b = l.begin(); + std::string::iterator e = l.end(); + this->axis_titles.clear(); + while(parser.copy_title(tok, b, e) != CParser::TT_EMPTY) + { + this->axis_titles.push_back(tok); + } + } + while (this->axis_titles.size() < 3) this->axis_titles.push_back(""); + break; + case 6: /* axis scales */ + { + this->Set_axis_scale(parser); + } + break; + case 7: /* initial_solutions */ + this->graph_initial_solutions = parser.get_true_false(next_char, FALSE); + break; + case 8: /* plot_concentration_vs */ + parser.copy_token(token, next_char); + Utilities::str_tolower(token); + if (token[0] == 'x' || token[0] == 'd') + chart_type = 0; + else if (token[0] == 't') + chart_type = 1; + else + { + std::ostringstream estream; + estream << "Found " << token << ", but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time."; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + } + break; + case 9: /* shifts_as_points */ + this->shifts_as_points = parser.get_true_false(next_char, true); + if (this->shifts_as_points) + this->chart_type = 0; + else + this->chart_type = 1; + break; + case 10: /* grid_offset */ +#ifdef PHREEQ98 + /* + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &RowOffset); + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &ColumnOffset); + */ +#endif + break; + case 11: /* connect_simulations */ + this->connect_simulations = parser.get_true_false(next_char, true); + break; + case 12: /* plot_csv_file */ + { + std::string file_name; + parser.get_rest_of_line(file_name); + file_name = trim(file_name); + this->OpenCSVFile(file_name); + } + break; + case 13: /* clear */ + case 14: /* detach */ + this->detach = true; + break; + /* End of modifications */ + case CParser::OPT_DEFAULT: // Read Basic commands + { + if (new_command_lines) + { + this->rate_command_list.clear(); + new_command_lines = false; + } + this->rate_new_def = true; + /* read command */ + std::string cmd(parser.line()); + std::string cmd_lower = cmd; + Utilities::str_tolower(cmd_lower); + if ((cmd_lower.find("graph_y") != std::string::npos) || + (cmd_lower.find("graph_sy") != std::string::npos)) + { + //Number of curves not known here + //Curves are created in Basic cmds + } + if (cmd_lower.find("plot_xy") != std::string::npos) + { + //Curves are created in Basic cmds + ExtractCurveInfo(cmd); // truncates cmd + } + this->rate_command_list.push_back(cmd); + } + opt_save = CParser::OPT_DEFAULT; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + + // install new plotxy commands + this->Set_rate_struct(); + return true; +} +bool +ChartObject::OpenCSVFile(std::string file_name) +{ + std::string token; + + std::ifstream f_csv(file_name.c_str(), std::ifstream::in); + + if (!f_csv.is_open()) + { + std::ostringstream estream; + estream << "Could not open csv file for USER_GRAPH " << file_name; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + return false; + } + + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(P_INSTANCE_COMMA f_csv, oss_out, oss_err); + parser.set_echo_file(CParser::EO_NONE); + + /* Get lines */ + int linenr = 0; + + // temporary storage for new CSV curves + std::vector headings; + std::vector csv_curves; + + // Read file line by line into temporary curves + while (parser.check_line("cvs file", false, true, true, false) != CParser::LT_EOF) + { + // Headings line + if (linenr == 0) + { + // Skip x in 1st column + parser.get_iss() >> token; + + // Read rest of headings + while (parser.get_iss() >> token) + { + headings.push_back(token); + } + // add curves to temporary csv_curves + size_t i; + for (i = 0; i < headings.size(); i++) + { + CurveObject *c = new CurveObject; + c->Set_id(headings[i]); + c->Set_line_w(0); + std::string sym = ""; + this->Get_legal_symbol(sym); + c->Set_symbol(sym); + csv_curves.push_back(c); + } + + linenr++; + continue; + } + + token = parser.line(); + std::string tok1; + CParser::TOKEN_TYPE tt = CParser::parse_delimited(token, tok1, "\t"); + + // Curve properties lines + if (linenr < 6 && tt != CParser::TT_DIGIT) + { + Utilities::str_tolower(tok1); + std::string tok2; + size_t i=0; + while (token.size() != 0 && i < csv_curves.size()) + { + CParser::parse_delimited(token, tok2, "\t"); + tok2 = trim(tok2); + if (!strncmp(tok1.c_str(), "color", 5)) + { + csv_curves[i]->Set_color(tok2); + } + else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) + && (strstr(tok1.c_str(), "-si") == NULL)) + { + csv_curves[i]->Set_symbol(tok2); + } + else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) + { + csv_curves[i]->Set_symbol_size(atof(tok2.c_str())); + } + else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) + { + csv_curves[i]->Set_line_w(atof(tok2.c_str())); + } + else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) + { + csv_curves[i]->Set_y_axis(atoi(tok2.c_str())); + } + i++; + } + linenr++; + continue; + } + + // Curve data + if (linenr < 6) linenr = 6; + if (tt != CParser::TT_DIGIT) + { + linenr++; + continue; + } + + // x value for all curves + double x_value = atof(tok1.c_str()); + + // y values for curves + std::string tok2; + size_t i=0; + while (token.size() != 0 && i < csv_curves.size()) + { + CParser::parse_delimited(token, tok2, "\t"); + Utilities::squeeze_white(tok2); + if (tok2.size() == 0) + { + //csv_curves[i].Get_x().push_back(NA); + //csv_curves[i].Get_y().push_back(NA); + } + else + { + csv_curves[i]->Get_x().push_back(x_value); + csv_curves[i]->Get_y().push_back(atof(tok2.c_str())); + } + i++; + } + linenr++; + } + + // Append new curves + + std::vector::iterator it = csv_curves.begin(); + for (; it != csv_curves.end(); it++) + { + if ((*it)->Get_x().size() > 0) + { + this->CurvesCSV.push_back(*it); + this->Set_curve_added(true); + } + } + return true; +} + +void +ChartObject::ExtractCurveInfo(std::string & cmd_line) +{ + /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ + + // Make copy of cmd_line + int curvenr = (int) this->Curves.size(); + std::string str_line = cmd_line; + + // find command part of cmd_line + Utilities::replace(",","#",cmd_line); + size_t pos = cmd_line.find(","); + if (pos != std::string::npos) + { + cmd_line = cmd_line.substr(0, pos); + Utilities::replace("#",",",cmd_line); + str_line.erase(0, pos + 1); + } + else + { + P_INSTANCE_POINTER error_msg("Did not find x and y expressions for plot_xy command in USER_GRAPH", STOP); + } + + // new curve + CurveObject new_curve; + + while (Utilities::replace(","," ",str_line)); + while (Utilities::replace("="," ",str_line)); + std::string::iterator b = str_line.begin(); + std::string::iterator e = str_line.end(); + + //while (CParser::copy_title(tok, b, e) != CParser::TT_EMPTY) + for(;;) + { + std::string tok1, tok2; + if ((CParser::copy_token(tok1, b, e) == CParser::TT_EMPTY) || + (CParser::copy_token(tok2, b, e) == CParser::TT_EMPTY)) + break; + Utilities::str_tolower(tok1); + if (!strncmp(tok1.c_str(), "color", 5)) + { + new_curve.Set_color(tok2); + continue; + } + else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) + && (strstr(tok1.c_str(), "-si") == NULL)) + { + new_curve.Set_symbol(tok2); + continue; + } + else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) + { + new_curve.Set_symbol_size(atof(tok2.c_str())); + continue; + } + else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) + { + new_curve.Set_line_w(atof(tok2.c_str())); + continue; + } + else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) + { + new_curve.Set_y_axis(atoi(tok2.c_str())); + continue; + } + else + { + std::ostringstream estream; + estream << "Unknown input for plot_xy in USER_GRAPH " << str_line << std::endl; + P_INSTANCE_POINTER warning_msg(estream.str().c_str()); + continue; + } + } + + // Add to list of new plotxy curves + this->new_plotxy_curves.push_back(new_curve); +} +void +ChartObject::Set_rate_struct(void) +{ + + if (rate_command_list.size() == 0) return; + std::list::iterator it = rate_command_list.begin(); + std::ostringstream oss; + for (; it != rate_command_list.end(); it++) + { + oss << *it << std::endl; + } + this->Rate_free(); + this->user_graph->commands = (char *) P_INSTANCE_POINTER PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); + ::strcpy(this->user_graph->commands, oss.str().c_str()); + this->user_graph->new_def = this->rate_new_def; + this->user_graph->loopbase = NULL; + this->user_graph->varbase = NULL; + this->user_graph->linebase = NULL; + this->user_graph->name = NULL; +} +void +ChartObject::Get_legal_symbol(std::string &sym) +{ + std::map::iterator it; + if ((it = this->Symbol_map.find(sym)) == this->Symbol_map.end()) + { + sym = "Default"; + for (it = this->Symbol_map.begin(); it != this->Symbol_map.end(); it++) + { + if (default_symbol == it->second) + { + sym = it->first; + break; + } + } + default_symbol++; + default_symbol = default_symbol % this->Symbol_map.size(); + } + return; +} +ZedGraph::SymbolType +ChartObject::Return_SymbolType(const std::string sym) +{ + int i; + std::map::iterator it; + if ((it = this->Symbol_map.find(sym)) != this->Symbol_map.end()) + { + i = it->second; + } + else + { + i = default_symbol++; + default_symbol = default_symbol % this->Symbol_map.size(); + } + + switch (i) + { + case 0: + return SymbolType::Square; + break; + case 1: + return SymbolType::Diamond; + break; + case 2: + return SymbolType::Triangle; + break; + case 3: + return SymbolType::Circle; + break; + case 4: + return SymbolType::XCross; + break; + case 5: + return SymbolType::Plus; + break; + case 6: + return SymbolType::Star; + break; + case 7: + return SymbolType::TriangleDown; + break; + case 8: + return SymbolType::HDash; + break; + case 9: + return SymbolType::VDash; + break; + case 10: + return SymbolType::None; + break; + default: + return SymbolType::Default; + break; + } +} +void +ChartObject::SaveCurvesToFile(std::string &file_name) +{ + // reimplemented in Form + // This version not currently used + std::ofstream f_out(file_name.c_str(), std::ifstream::out); + + if (!f_out.is_open()) + { + std::ostringstream estream; + estream << "Could not open csv file for USER_GRAPH " << file_name; + P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + return; + } + + // list of curves + std::vector all_curves; + size_t i; + for (i = 0; i < this->CurvesCSV.size(); i++) + { + all_curves.push_back(this->CurvesCSV[i]); + } + for (i = 0; i < this->Curves.size(); i++) + { + all_curves.push_back(Curves[i]); + } + // write headings + size_t max_points = 0; + std::vector::iterator it = all_curves.begin(); + f_out.precision(4); + i = 0; + for ( ; it != all_curves.end(); it++) + { + f_out.width(12); + f_out << "x" << "\t"; + f_out.width(12); + if ((*it)->Get_id().size() > 0) + { + f_out << (*it)->Get_id() << "\t"; + } + else + { + f_out << "y" << "\t";; + } + if ((*it)->Get_x().size() > max_points) + max_points = (*it)->Get_x().size(); + } + f_out << std::endl; + + // write data + size_t i2 = 0; + f_out << std::scientific; + f_out.precision(4); + while (i2 < max_points) + { + for (it = all_curves.begin(); it != all_curves.end(); it++) + { + if (i2 < (*it)->Get_x().size()) + { + f_out.width(12); + f_out << (*it)->Get_x()[i2] << "\t"; + f_out.width(12); + f_out << (*it)->Get_y()[i2] << "\t"; + } + else if (i2 < max_points) + { + f_out.width(13); + f_out << "\t"; + f_out.width(13); + f_out << "\t"; + } + } + f_out << std::endl; + i2++; + } + f_out.close(); + return; +} +// file only used with MULTICHART +#if !defined PHREEQC_CLASS +bool +ChartObject::start_chart(void) +{ + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(true); + + // needed to send ChartObject pointer to thread + Thread ^t = gcnew Thread( + gcnew ParameterizedThreadStart(Form1::ThreadForm)); + + t->SetApartmentState(ApartmentState::STA); + t->IsBackground = false; + t->Priority = ThreadPriority::Normal; + + ChartObj ^p = gcnew ChartObj(this); + t->Start(p); + + //Thread::Sleep( 1 ); /* this when debugging... */ + //_beginthread(void (Form1::ThreadForm), 0, NULL); + return true; +} +#else +bool +ChartObject::start_chart(void) +{ + Application::EnableVisualStyles(); + Application::SetCompatibleTextRenderingDefault(true); + + // needed to send ChartObject pointer to thread + Thread ^t = gcnew Thread( + gcnew ParameterizedThreadStart(Form1::ThreadForm)); + + t->SetApartmentState(ApartmentState::STA); + t->IsBackground = false; + t->Priority = ThreadPriority::Normal; + + ChartObj ^p = gcnew ChartObj(this); + t->Start(p); + this->form_started = true; + + //Thread::Sleep( 1 ); /* this when debugging... */ + //_beginthread(void (Form1::ThreadForm), 0, NULL); + return true; +} +#endif +void +ChartObject::Rate_free(void) +{ + + + user_graph->commands = (char *) P_INSTANCE_POINTER free_check_null(user_graph->commands); + + if (user_graph->linebase != NULL) + { + char cmd[] = "new; quit"; + P_INSTANCE_POINTER basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase); + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + } +} +void ChartObject::Initialize_graph_pts(void) +{ + graph_x = NA; + graph_y.clear(); + secondary_y.clear(); +} + +void +ChartObject::Finalize_graph_pts(void) +{ + if (graph_x != NA) + { + std::map::iterator it; + for (it = graph_y.begin(); it != graph_y.end(); it++) + { + Curves[it->first]->Get_x().push_back(graph_x); + Curves[it->first]->Get_y().push_back(it->second); + } + } + if (graph_x != NA) + { + std::map::iterator it; + for (it = secondary_y.begin(); it != secondary_y.end(); it++) + { + Curves[it->first]->Set_y_axis(2); + } + } +} + +void +ChartObject::Add_curve(std::string id, + double line_width, + std::string symbol, + double symbol_size, + int y_axis, + std::string color) + +{ + CurveObject *c = new CurveObject; + c->Set_id(id); + c->Set_line_w(line_width); + this->Get_legal_symbol(symbol); + c->Set_symbol(symbol); + c->Set_symbol_size(symbol_size); + c->Set_y_axis(y_axis); + c->Set_color(color); + + this->Curves.push_back(c); +} +void +ChartObject::Set_rate_new_def(bool tf) +{ + this->rate_new_def = tf; + if (this->user_graph != NULL) + { + if (tf) + { + this->user_graph->new_def = 1; + } + else + { + this->user_graph->new_def = 0; + } + } +} +#endif // MULTICHART \ No newline at end of file diff --git a/ChartObject.h b/ChartObject.h new file mode 100644 index 00000000..21a7c8f7 --- /dev/null +++ b/ChartObject.h @@ -0,0 +1,380 @@ +#if !defined(CHARTOBJECT_H_INCLUDED) +#define CHARTOBJECT_H_INCLUDED +#if defined MULTICHART +#include +#include +#include +#include +#include "CurveObject.h" +#if defined PHREEQC_CLASS + +#else +#include "global_structures.h" +#endif +#include "NumKeyword.h" + +#include +class Phreeqc; + +class ChartObject:public cxxNumKeyword +{ + + public: + ChartObject(); + ChartObject(int i); + ~ChartObject(); + + // new_ug + bool Get_new_ug() + { + return this->new_ug; + } + void Set_new_ug(bool b) + { + this->new_ug = b; + } + // bool FirstCallToUSER_GRAPH; + void Set_FirstCallToUSER_GRAPH(bool b) + { + this->FirstCallToUSER_GRAPH = b; + } + bool Get_FirstCallToUSER_GRAPH() + { + return this->FirstCallToUSER_GRAPH; + } + // int update_time_chart; + int Get_update_time_chart() + { + return (this->update_time_chart); + } + // PanelHeight + int Get_PanelHeight() + { + return (this->PanelHeight); + } + // PanelWidth + int Get_PanelWidth() + { + return (this->PanelWidth); + } + // Symbol_map + // std::vector Color_vector; + + // std::string chart_title; + std::string &Get_chart_title() + { + return this->chart_title; + } + // std::vector axis_titles; + std::vector &Get_axis_titles() + { + return this->axis_titles; + } + // double axis_scale_x[5]; + double *Get_axis_scale_x() + { + return this->axis_scale_x; + } + // double axis_scale_y[5]; + double *Get_axis_scale_y() + { + return this->axis_scale_y; + } + // double axis_scale_y2[5]; + double *Get_axis_scale_y2() + { + return this->axis_scale_y2; + } + // int chart_type; + int Get_chart_type() + { + return this->chart_type; + } + // bool graph_initial_solutions; + bool Get_graph_initial_solutions() + { + return this->graph_initial_solutions; + } + // bool connect_simulations; + bool Get_connect_simulations() + { + return this->connect_simulations; + } + // int shifts_as_points; + + // int colnr; + void Set_colnr(int i) + { + this->colnr = i; + } + int Get_colnr() + { + return (this->colnr); + } + // int RowOffset; + void Set_RowOffset(int i) + { + this->RowOffset = i; + } + int Get_RowOffset() + { + return (this->RowOffset); + } + // int ColumnOffset; + void Set_ColumnOffset(int i) + { + this->ColumnOffset = i; + } + int Get_ColumnOffset() + { + return (this->ColumnOffset); + } + // int prev_advection_step; + void Set_prev_advection_step(int i) + { + this->prev_advection_step = i; + } + int Get_prev_advection_step() + { + return (this->prev_advection_step); + } + // int prev_transport_step; + void Set_prev_transport_step(int i) + { + this->prev_transport_step = i; + } + int Get_prev_transport_step() + { + return (this->prev_transport_step); + } + // int prev_sim_no; + void Set_prev_sim_no(int i) + { + this->prev_sim_no = i; + } + int Get_prev_sim_no(void) + { + return this->prev_sim_no; + } + // bool end_timer; + void Set_end_timer(bool b) + { + this->end_timer = b; + } + bool Get_end_timer() + { + return this->end_timer; + } + // bool end_timer; + void Set_done(bool b) + { + this->done = b; + } + bool Get_done() + { + return this->done; + } + // std::vector CurvesCSV; + std::vector &Get_CurvesCSV() + { + return this->CurvesCSV; + } + // std::vector Curves; + std::vector &Get_Curves() + { + return this->Curves; + } + // bool curve_added; + void Set_curve_added(bool tf) + { + this->curve_added = tf; + } + bool Get_curve_added() + { + return this->curve_added; + } + // bool point_added; + void Set_point_added(bool tf) + { + this->point_added = tf; + } + bool Get_point_added() + { + return this->point_added; + } + // struct rate user_graph; + struct rate *Get_user_graph() + { + return this->user_graph; + } + // C++ for rate struct + // std::string rate_name; + // std::list rate_command_list; + std::list &Get_rate_command_list() + { + return this->rate_command_list; + } + // bool rate_new_def; + void Set_rate_new_def(bool tf); + + bool Get_rate_new_def() + { + return this->rate_new_def; + } + // int default_symbol; + //double graph_x; + void Set_graph_x(double d) + { + this->graph_x = d; + } + double Get_graph_x() + { + return this->graph_x; + } + //std::map graph_y; + std::map &Get_graph_y() + { + return this->graph_y; + } + //std::map secondary_y; + std::map &Get_secondary_y() + { + return this->secondary_y; + } + //std::vector new_plotxy_curves; + std::vector &Get_new_plotxy_curves() + { + return this->new_plotxy_curves; + } + //std::vector new_headings; + std::vector &Get_new_headings() + { + return this->new_headings; + } + // bool active; + void Set_active(bool tf) + { + this->active = tf; + } + bool Get_active() + { + return this->active; + } + // bool detach; + void Set_detach(bool tf) + { + this->detach = tf; + } + bool Get_detach() + { + return this->detach; + } + // bool chart_started; + bool Get_form_started() + { + return this->form_started; + } +#if defined PHREEQC_CLASS + void Set_phreeqc(Phreeqc * ptr) + { + this->p_instance1 = ptr; + } + Phreeqc * Get_phreeqc() + { + return this->p_instance1; + } +#endif + + bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); + bool Set_axis_scale(CParser & parser); + bool Read(CParser & parser); + bool OpenCSVFile(std::string fn); + void ExtractCurveInfo(std::string & str_line); + void Set_rate_struct(void); + void PlotXY(std::string x, std::string y); + bool start_chart(void); + ZedGraph::SymbolType Return_SymbolType(std::string); + void SaveCurvesToFile(std::string &); + void Rate_free(void); + void Initialize_graph_pts(void); + void Finalize_graph_pts(void); + void Get_legal_symbol(std::string &sym); + //void Add_new_series(void); + void Add_curve(std::string id = "", + double line_width = 1.0, + std::string symbol = "", + double symbol_size = 6.0, + int y_axis = 1, + std::string color = ""); + protected: + + bool new_ug; + bool FirstCallToUSER_GRAPH; + + int update_time_chart; /* milliseconds, maybe read */ + int PanelHeight; + int PanelWidth; + std::map Symbol_map; + std::vector Color_vector; + std::string chart_title; + std::vector axis_titles; + double axis_scale_x[5]; + double axis_scale_y[5]; + double axis_scale_y2[5]; + + int chart_type; + bool graph_initial_solutions; + bool connect_simulations; + int shifts_as_points; + int colnr; + int RowOffset; + int ColumnOffset; + + int prev_advection_step; + int prev_transport_step; + + int prev_sim_no; + + bool end_timer; + bool done; + + std::vector CurvesCSV; + std::vector Curves; + bool curve_added; + bool point_added; + + struct rate *user_graph; + // C++ for rate struct + std::string rate_name; + std::list rate_command_list; + bool rate_new_def; + + int default_symbol; + + // temporary storage before stored graph_x/y/sy data are stored in curves + // Initialize_graph_pts and Finalize_graph_pts use this storage. + double graph_x; + std::map graph_y; + std::map secondary_y; + + // temporary plotxy curve definitions before stored in curves + // a plotxy curve is copied to Curves when cmdplotxy is encountered + // this keeps order correct between plotxy and graph_x/y/sy + std::vector new_plotxy_curves; + + // temporary headings until stored during basic_run + std::vector new_headings; + bool active; + bool detach; + bool form_started; +#if defined PHREEQC_CLASS + class Phreeqc * p_instance1; +#endif + + public: + int usingResource; + + +}; +#endif // MULTICHART +#endif // !defined(CHARTOBJECT_H_INCLUDED) diff --git a/CurveObject.cpp b/CurveObject.cpp new file mode 100644 index 00000000..6f3a1ead --- /dev/null +++ b/CurveObject.cpp @@ -0,0 +1,37 @@ +// CurveObject.cpp: implementation of the CurveObject class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include "CurveObject.h" + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +CurveObject::CurveObject() + // + // default constructor for cxxExchComp + // +{ + x.clear(); + y.clear(); + //this->npoints_plot = 0; + //this->npoints = 0; + //this->nxy = 0; + //this->prev_npoints = 0; + this->id = ""; + this->symbol = ""; + this->color = ""; + this->y_axis = 1; + this->line_w = 1.0; + this->symbol_size = 6.0; +} + + +CurveObject::~CurveObject() +{ +} + diff --git a/CurveObject.h b/CurveObject.h new file mode 100644 index 00000000..32392bd0 --- /dev/null +++ b/CurveObject.h @@ -0,0 +1,90 @@ +#if !defined(CURVEOBJECT_H_INCLUDED) +#define CURVEOBJECT_H_INCLUDED +#include +#include + +class CurveObject +{ + +public: + CurveObject(); + ~CurveObject(); + void Set_id(std::string s) + { + this->id = s; + } + std::string &Get_id(void) + { + return this->id; + } + void Set_color(std::string s) + { + this->color = s; + } + std::string &Get_color(void) + { + return this->color; + } + void Set_symbol(std::string s) + { + this->symbol = s; + } + std::string &Get_symbol(void) + { + return this->symbol; + } + void Set_symbol_size(double f) + { + this->symbol_size = f; + } + double Get_symbol_size(void) + { + return this->symbol_size; + } + void Set_line_w(double f) + { + this->line_w = f; + } + double Get_line_w(void) + { + return this->line_w; + } + void Set_y_axis(int f) + { + this->y_axis = f; + } + std::vector & Get_x() + { + return this->x; + } + std::vector & Get_y() + { + return this->y; + } + int Get_y_axis() + { + return this->y_axis; + } + //void Set_npoints_plot(int f) + //{ + // this->npoints_plot = f; + //} + //int Get_npoints_plot(void) + //{ + // return this->npoints_plot; + //} + +protected: + //float *x, *y; + std::vector x, y; + //int nxy, npoints, npoints_plot, prev_npoints; + + std::string id, color, symbol; + int y_axis; + double line_w, symbol_size; + +public: + +}; + +#endif // !defined(CURVEOBJECT_H_INCLUDED) diff --git a/Parser.cxx b/Parser.cxx index ba613a77..eaafa45e 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -372,6 +372,11 @@ CParser::check_key(std::string::iterator begin, std::string::iterator end) s_keyword_map.insert(std::map < std::string, KEY_TYPE >::value_type("reaction_raw", KT_REACTION_RAW)); +#if defined MULTICHART + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("user_graph", + KT_USER_GRAPH)); +#endif } std::string lowercase; @@ -1349,3 +1354,91 @@ incr_input_error() ++ ERROR_MESSAGE_QUALIFIER input_error; return ++m_input_error; } + +CParser::TOKEN_TYPE CParser::copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) +{ + if (begin != end) + { + std::string::iterator b = begin; + std::string::iterator e = end; + for (; b < end && (::isspace(*b) || (*b == ',')); ++b); + begin = b; + if (*begin == '"') + { + begin = ++b; + for (; begin != end && !(*begin == '"'); ++begin); + e = begin; + if (begin != end && *begin == '"') + { + e = begin++; + } + } + else + { + for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin); + e = begin; + } + token.assign(b, e); + } + else + { + token.resize(0); + } + token = trim(token); + return token_type(token); +} +bool CParser::get_true_false(std::istream::pos_type & pos, bool def) +{ + std::string token; + this->copy_token(token, pos); + std::string::iterator b = token.begin(); + for (; b != token.end() && (::isspace(*b)); ++b); + if (b != token.end()) + { + if (*b == 'f' || *b == 'F') + { + return false; + } + else if (*b == 't' || *b == 'T') + { + return true; + } + } + return def; +} +CParser::TOKEN_TYPE CParser::get_rest_of_line(std::string &token) +{ + token.clear(); + std::istringstream::pos_type pos = m_line_iss.tellg(); + int j; + while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) + { + char c = (char) j; + token += c; + } + token = trim(token); + return token_type(token); +} +CParser::TOKEN_TYPE CParser::parse_delimited(std::string & source, std::string & result, + const std::string& t = " \t") +{ + + size_t pos = source.find_first_of(t); + std::string temp; + if (pos != std::string::npos) + { + result = source.substr(0, pos); + temp = source.substr(pos+1); + source = temp; + } + else + { + result = source; + source.clear(); + } + std::string str = result; + + return token_type(trim_left(str)); +} \ No newline at end of file diff --git a/Parser.h b/Parser.h index 08147419..5b2be331 100644 --- a/Parser.h +++ b/Parser.h @@ -68,6 +68,9 @@ class CParser KT_SURFACE_RAW = 11, KT_TEMPERATURE_RAW = 12, KT_REACTION_RAW = 13 +#if defined MULTICHART + , KT_USER_GRAPH = 14 +#endif }; enum OPT_TYPE @@ -159,7 +162,7 @@ class CParser std::istream::pos_type & next_pos); - std::string & line() + std::string & line() { return m_line; } @@ -219,9 +222,15 @@ class CParser static TOKEN_TYPE copy_token(std::string & token, std::string::iterator & begin, std::string::iterator & end); + static CParser::TOKEN_TYPE copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); static TOKEN_TYPE token_type(const std::string & token); static TOKEN_TYPE copy_token(std::string & token, std::istream & is); TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); + bool get_true_false(std::istream::pos_type & pos, bool def); + TOKEN_TYPE get_rest_of_line(std::string &token); + static TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); CParser::TOKEN_TYPE peek_token(); /** diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6a018c81..6f592cd9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -220,12 +220,12 @@ Phreeqc::Phreeqc(void) {"let", toklet}, {"print", tokprint}, {"punch", tokpunch}, - #if defined PHREEQ98 || defined CHART + #if defined PHREEQ98 || defined CHART || defined MULTICHART {"graph_x", tokgraph_x}, {"graph_y", tokgraph_y}, {"graph_sy", tokgraph_sy}, #endif - #ifdef CHART + #if defined CHART || defined MULTICHART {"plot_xy", tokplot_xy}, #endif {"input", tokinput}, diff --git a/Phreeqc.h b/Phreeqc.h index ccc8bd52..135ca399 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -28,7 +28,7 @@ #include "runner.h" #include "dumper.h" #include "StorageBinList.h" - +#include "ChartHandler.h" #define STATIC #define EXTERNAL #define CLASS_QUALIFIER Phreeqc:: @@ -44,7 +44,6 @@ public: Phreeqc(void); ~Phreeqc(void); - //private: // //struct _generic_N_Vector; @@ -182,12 +181,12 @@ void cmddel(struct LOC_exec *LINK); void cmdrenum(struct LOC_exec *LINK); void cmdprint(struct LOC_exec *LINK); void cmdpunch(struct LOC_exec *LINK); -#if defined PHREEQ98 || defined CHART +#if defined PHREEQ98 || defined CHART || defined MULTICHART void cmdgraph_x(struct LOC_exec *LINK); void cmdgraph_y(struct LOC_exec *LINK); void cmdgraph_sy(struct LOC_exec *LINK); #endif -#ifdef CHART +#if defined CHART || defined MULTICHART void cmdplot_xy(struct LOC_exec *LINK); #endif void cmdlet(boolean implied, struct LOC_exec *LINK); @@ -778,7 +777,7 @@ int punch_s_s_assemblage(void); int punch_saturation_indices(void); int punch_totals(void); int punch_user_punch(void); -#if defined PHREEQ98 || defined CHART +#if defined PHREEQ98 || defined CHART || defined MULTICHART int punch_user_graph(void); #endif @@ -855,6 +854,9 @@ int read_user_punch(void); #if defined PHREEQ98 || defined CHART int read_user_graph(void); #endif +#if defined MULTICHART +int read_user_graph_handler(); +#endif int next_keyword_or_option(const char **opt_list, int count_opt_list); // ReadClass.cxx diff --git a/Phreeqc_class.h b/Phreeqc_class.h index 779c673a..3720b0eb 100644 --- a/Phreeqc_class.h +++ b/Phreeqc_class.h @@ -20,4 +20,4 @@ #define PHREEQC_NAME_SPACE Phreeqc:: #endif #endif /* _INC_PHREEQC_CLASS_H */ -//#include "Phreeqc_class.h" + diff --git a/ReadClass.cxx b/ReadClass.cxx index 6ccbea34..7a89eab0 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1854,8 +1854,8 @@ read_kinetics_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; + std::ostringstream oss_out; // ?? + std::ostringstream oss_err; // ?? CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); assert(!reading_database()); @@ -2731,3 +2731,56 @@ dump_ostream(std::ostream& os) // Turn off dump until next read dump_info.SetAll(false); } +#if defined MULTICHART +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER +read_user_graph_handler(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads USER_GRAPH_DATA_BLOCK data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + std::ostringstream oss_out; + std::ostringstream oss_err; + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + //parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + assert(!reading_database()); + + bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser); + + // Need to output the next keyword + if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + return (return_value); +} +#endif \ No newline at end of file diff --git a/SAXPhreeqc.cxx b/SAXPhreeqc.cxx deleted file mode 100644 index b561fa9b..00000000 --- a/SAXPhreeqc.cxx +++ /dev/null @@ -1,1136 +0,0 @@ -// SAXPhreeqc.cpp -#ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif - -#include // DBL_DIG -#include // sprintf -#include // iswspace - -#include // assert -//#include // std::ostrstream -#include -#include // std::cerr -#ifdef SKIP -#endif -#ifdef _DEBUG -#define _CRTDBG_MAP_ALLOC -#include -#endif - - -#include -#include -#include -#include -#include -#include - -//#include // SAXParser -#include // AttributeList -#include // Unicode definitions -#include // MemBufInputSource -#include -#include -#include // XMLPlatformUtils::getCurrentMillis -#include - -#include -#include - -#include "SAXPhreeqc.h" // SAX_ functions -#include "SaxPhreeqcHandlers.h" // SaxPhreeqcHandlers - -//XERCES_CPP_NAMESPACE_USE -#define xns XERCES_CPP_NAMESPACE - -///static char buffer[300000]; -///static std::ostrstream s_oss(buffer, 300000); // must never go out of scope -static - std::ostringstream - s_oss; // must never go out of scope -static bool - s_bSysIsOpen = false; // must never go out of scope - -#include -// extern routines -#include "phqalloc.h" -#include "global.h" -#include "phrqproto.h" -#include "output.h" -#ifdef SKIP -int -conc_init(struct conc *conc_ptr); -void * -free_check_null(void *ptr); -int -pe_data_store(struct pe_data **pe, const char *token); -struct phase * -phase_bsearch(char *ptr, int *j, int print); -struct solution * -solution_alloc(void); -struct solution * -solution_bsearch(int k, int *n, int print); -int -solution_free(struct solution *solution_ptr); -void -space(void **ptr, int i, int *max, int struct_size); -char * -string_duplicate(const char *token); -char * -string_hsave(const char *str); -int -error_msg(const char *err_str, const int stop); -struct master * -master_bsearch(const char *ptr); -void -malloc_error(void); -#endif -//} - - -class - Initializer -{ - public: - Initializer() - { -#if defined(_DEBUG) - int - tmpDbgFlag; - - /* - * Set the debug-heap flag to keep freed blocks in the - * heap's linked list - This will allow us to catch any - * inadvertent use of freed memory - */ - tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; - tmpDbgFlag |= - _CRTDBG_LEAK_CHECK_DF; - //tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; - _CrtSetDbgFlag(tmpDbgFlag); -#endif - - xns::XMLPlatformUtils::Initialize(); - } -}; - -static Initializer - sInit; // initialize xerces once -static SaxPhreeqcHandlers - s_handler; // one and only instance - -void -SAX_StartSystem() -{ - - assert(!s_bSysIsOpen); // system already open and has not been closed - - // init stream - //s_oss.freeze(false); - s_oss.seekp(0); - - // write stream - // s_oss << ""; - s_oss << ""; - s_oss << ""; - s_oss << " "; - s_bSysIsOpen = true; - -} - -char * -stringify_null(char *string) -{ - if (string == NULL) - return (string_hsave("")); - return (string); -} - -int -SAX_AddSolution(struct solution *solution_ptr) -{ - //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; - int - i, - newd; - assert(s_bSysIsOpen); // must call SAX_StartSystem first - s_oss.precision(DBL_DIG - 1); - // Solution element and attributes - newd = solution_ptr->new_def; - s_oss << " - new_def << "\"" << std::endl; - s_oss << " soln_n_user=\"" << solution_ptr-> - n_user << "\" " << std::endl; - s_oss << " soln_n_user_end=\"" << solution_ptr-> - n_user_end << "\"" << std::endl; - s_oss << " soln_description=\"" << solution_ptr-> - description << "\"" << std::endl; - s_oss << " soln_tc=\"" << solution_ptr->tc << "\"" << std::endl; - s_oss << " soln_ph=\"" << solution_ptr->ph << "\"" << std::endl; - s_oss << " soln_solution_pe=\"" << solution_ptr-> - solution_pe << "\"" << std::endl; - s_oss << " soln_mu=\"" << solution_ptr->mu << "\"" << std::endl; - s_oss << " soln_ah2o=\"" << solution_ptr->ah2o << "\"" << std::endl; - s_oss << " soln_density=\"" << solution_ptr-> - density << "\"" << std::endl; - s_oss << " soln_total_h=\"" << solution_ptr-> - total_h << "\"" << std::endl; - s_oss << " soln_total_o=\"" << solution_ptr-> - total_o << "\"" << std::endl; - s_oss << " soln_cb=\"" << solution_ptr->cb << "\"" << std::endl; - s_oss << " soln_mass_water=\"" << solution_ptr-> - mass_water << "\"" << std::endl; - s_oss << " soln_total_alkalinity=\"" << solution_ptr-> - total_alkalinity << "\"" << std::endl; - //s_oss << " soln_total_co2=\"" << solution_ptr->total_co2 << "\"" << std::endl; - s_oss << " soln_units=\"" << solution_ptr->units << "\"" << std::endl; - s_oss << " soln_default_pe=\"" << solution_ptr-> - default_pe << "\"" << std::endl; - s_oss << " soln_count_master_activity=\"" << solution_ptr-> - count_master_activity << "\"" << std::endl; - s_oss << " soln_count_isotopes=\"" << solution_ptr-> - count_isotopes << "\"" << std::endl; - s_oss << " soln_count_species_gamma=\"" << solution_ptr-> - count_species_gamma << "\">" << std::endl; - // end of solution attributes - // pe structures - for (i = 0; solution_ptr->pe[i].name != NULL; i++) - { - s_oss << " pe[i]. - name << "\"/>" << std::endl; - } - // soln_total conc structures - for (i = 0; solution_ptr->totals[i].description != NULL; i++) - { - struct conc * - c = &(solution_ptr->totals[i]); - s_oss << " description << "\"" << std::endl; - s_oss << " conc_moles=\"" << c->moles << "\"" << std::endl; - if (newd == TRUE) - { - s_oss << " conc_input_conc=\"" << c-> - input_conc << "\"" << std::endl; - if (c->units != NULL) - s_oss << " conc_units=\"" << c-> - units << "\"" << std::endl; - if (c->equation_name != NULL) - { - s_oss << " conc_equation_name=\"" << stringify_null(c-> - equation_name) - << "\"" << std::endl; - s_oss << " conc_phase_si=\"" << c-> - phase_si << "\"" << std::endl; - } - if (c->as != NULL) - s_oss << " conc_as=\"" << stringify_null(c-> - as) << "\"" << - std::endl; - s_oss << " conc_gfw=\"" << c->gfw << "\"" << std::endl; - } - s_oss << " conc_n_pe=\"" << c->n_pe << "\"" << std::endl; - s_oss << " />" << std::endl; - } - // master_activity, master_activity structure - - for (i = 0; i < solution_ptr->count_master_activity; i++) - { - s_oss << " - master_activity - [i]. - description) << - "\" m_a_la=\"" << solution_ptr->master_activity[i]. - la << "\"/>" << std::endl; - } - /* - if (solution_ptr->count_master_activity > 0) { - s_oss << " count_master_activity; i++) { - if (solution_ptr->master_activity[i].description != NULL) { - s_oss << stringify_null(solution_ptr->master_activity[i].description) << " "; - s_oss << solution_ptr->master_activity[i].la << std::endl; - } else { - s_oss << "null 0.0" << std::endl; - } - } - s_oss << "\"/>" << std::endl; - } - */ - // species_gamma, mater_activity structure - for (i = 0; i < solution_ptr->count_species_gamma; i++) - { - s_oss << " - species_gamma - [i]. - description) << - "\" m_a_la=\"" << solution_ptr->species_gamma[i]. - la << "\"/>" << std::endl; - } - // isotopes, isotope structure - for (i = 0; solution_ptr->count_isotopes; i++) - { - s_oss << " isotopes[i]. - isotope_number << "\"" << std::endl; - s_oss << " iso_elt_name=\"" << solution_ptr->isotopes[i]. - elt_name << "\"" << std::endl; - s_oss << " iso_isotope_name=\"" << solution_ptr->isotopes[i]. - isotope_name << "\"" << std::endl; - s_oss << " iso_total=\"" << solution_ptr->isotopes[i]. - total << "\"" << std::endl; - s_oss << " iso_ratio=\"" << solution_ptr->isotopes[i]. - ratio << "\"" << std::endl; - s_oss << " iso_ratio_uncertainty=\"" << solution_ptr->isotopes[i]. - ratio_uncertainty << "\"" << std::endl; - s_oss << " iso_coef=\"" << solution_ptr->isotopes[i]. - coef << "\"" << std::endl; - } - // End of solution - s_oss << " " << std::endl; - - return (OK); -} - -void -SAX_EndSystem() -{ - assert(s_bSysIsOpen); // must call SAX_StartSystem first - - s_oss << " " << std::endl; - s_oss << "" << std::endl; - s_oss << '\0'; - - s_bSysIsOpen = false; - //delete[] s_handler; - return; -} - -int -SAX_GetXMLLength() -{ - assert(!s_bSysIsOpen); // must call SAX_EndSystem first - //return s_oss.pcount(); - return s_oss.str().size(); -} - -const char * -SAX_GetXMLStr() -{ - assert(!s_bSysIsOpen); // must call SAX_EndSystem first - return s_oss.str().c_str(); -} - -void -SAX_cleanup() -{ - //delete s_handler; - //s_oss.freeze(false); -} - -// utility routines - -int -XMLCh2Int(const XMLCh * const attValue) -{ - char * - string = xns::XMLString::transcode(attValue); - int - i = strtol(string, NULL, 10); - xns::XMLString::release(&string); - return i; - //return (xns::XMLString::parseInt(attValue)); -} - -double -XMLCh2Double(const XMLCh * const attValue) -{ - char * - string = xns::XMLString::transcode(attValue); - double - d = strtod(string, NULL); - xns::XMLString::release(&string); - return d; -} - -char * -XMLCh2String(const XMLCh * const attValue) -{ - char * - string = xns::XMLString::transcode(attValue); - char * - s = string_duplicate(string); - xns::XMLString::release(&string); - return s; -} - -char * -XMLCh_hsave(const XMLCh * const attValue, bool allow_null) -{ - char * - string = xns::XMLString::transcode(attValue); - char * - s = string_hsave(string); - if (allow_null && strlen(s) == 0) - s = NULL; - xns::XMLString::release(&string); - return s; -} - - -int -SAX_UnpackSolutions(void *pvBuffer, int buf_size) -{ - // Create MemBufferInputSource from the buffer containing the XML - // statements. - xns::MemBufInputSource memBufIS((const XMLByte *) pvBuffer, buf_size, - "solution_id", false); - fprintf(stderr, "%s", (char *) pvBuffer); - return 0; - // - // Create a SAX2 parser object. - // - xns::SAX2XMLReader * parser = xns::XMLReaderFactory::createXMLReader(); - parser->setFeature(xns::XMLUni::fgXercesSchemaFullChecking, false); - parser->setFeature(xns::XMLUni::fgSAX2CoreNameSpaces, false); - parser->setFeature(xns::XMLUni::fgXercesSchema, false); - parser->setFeature(xns::XMLUni::fgXercesIdentityConstraintChecking, - false); - // - // Create the handler object and install it as the document and error - // handler for the parser. Then parse the MemBufferInputSource and - // catch any exceptions that propogate out - // - try - { - unsigned long - duration = 0; - parser->setContentHandler(&s_handler); - parser->setErrorHandler(&s_handler); - int - t = 0; - for (; t < 1000; ++t) - { - const unsigned long - startMillis = xns::XMLPlatformUtils::getCurrentMillis(); - parser->parse(memBufIS); - const unsigned long - endMillis = xns::XMLPlatformUtils::getCurrentMillis(); - duration += endMillis - startMillis; - } - std::cerr << "\nSaxParse time = " << duration << " millis\n"; - } - catch(const xns::SAXException & toCatch) - { - char * - psz = xns::XMLString::transcode(toCatch.getMessage()); - input_error++; - sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&psz); - return ERROR; - } - catch(const xns::XMLException & toCatch) - { - char * - psz = xns::XMLString::transcode(toCatch.getMessage()); - input_error++; - sprintf(error_string, "SAX_UnpackSolutions: %s\n", psz); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&psz); - return ERROR; - } - catch(...) - { - input_error++; - sprintf(error_string, "SAX_UnpackSolutions: %s\n", - "Unknown error occured."); - error_msg(error_string, CONTINUE); - return ERROR; - } - - return (OK); -} - - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -// element names - -SaxPhreeqcHandlers::SaxPhreeqcHandlers():eltType(typeNULL), attType(attNULL), totals(), acts(), -solution_ptr(NULL) -{ - int - i; - - int - count_elementInfo, - count_attributeInfo; - struct mapElementInfo - { - char * - key; - enum elementType - type; - }; - struct mapAttributeInfo - { - enum attributeType - type; - char * - key; - }; - struct mapElementInfo - elementInfo[] = { - {"phast_state", typePHAST_STATE}, - {"system", typeSYSTEM}, - {"solution", typeSOLUTION}, - {"soln_pe", typeSOLN_PE}, - {"soln_total", typeSOLN_TOTAL}, - {"soln_m_a", typeSOLN_MASTER_ACTIVITY}, - {"soln_isotope", typeSOLN_ISOTOPE}, - {"soln_s_g", typeSOLN_SPECIES_GAMMA} - }; - count_elementInfo = sizeof(elementInfo) / sizeof(struct mapElementInfo); - struct mapAttributeInfo - attributeInfo[] = { - // Solution structure - {attSOLN_new_def, "soln_new_def"}, - {attSOLN_n_user, "soln_n_user"}, - {attSOLN_n_user_end, "soln_n_user_end"}, - {attSOLN_description, "soln_description"}, - {attSOLN_tc, "soln_tc"}, - {attSOLN_ph, "soln_ph"}, - {attSOLN_solution_pe, "soln_solution_pe"}, - {attSOLN_mu, "soln_mu"}, - {attSOLN_ah2o, "soln_ah2o"}, - {attSOLN_density, "soln_density"}, - {attSOLN_total_h, "soln_total_h"}, - {attSOLN_total_o, "soln_total_o"}, - {attSOLN_cb, "soln_cb"}, - {attSOLN_mass_water, "soln_mass_water"}, - {attSOLN_total_alkalinity, "soln_total_alkalinity"}, - {attSOLN_total_co2, "soln_total_co2"}, - {attSOLN_units, "soln_units"}, - {attSOLN_default_pe, "soln_default_pe"}, - {attSOLN_count_master_activity, "soln_count_master_activity"}, - {attSOLN_count_isotopes, "soln_count_isotopes"}, - {attSOLN_count_species_gamma, "soln_count_species_gamma"}, - {attSOLN_PE_name, "soln_pe_name"}, - // master_activity structure - {attM_A_description, "m_a_desc"}, - {attM_A_la, "m_a_la"}, - {attM_A_list, "m_a_list"}, - // isotope structure - {attISO_isotope_number, "iso_isotope_number"}, - {attISO_elt_name, "iso_elt_name"}, - {attISO_isotope_name, "iso_isotope_name"}, - {attISO_total, "iso_total"}, - {attISO_ratio, "iso_ratio"}, - {attISO_ratio_uncertainty, "iso_ratio_uncertainty"}, - {attISO_x_ratio_uncertainty, "iso_x_ratio_uncertainty"}, - {attISO_coef, "iso_coef"}, - // conc structure - {attCONC_description, "conc_desc"}, - {attCONC_moles, "conc_moles"}, - {attCONC_input_conc, "conc_input_conc"}, - {attCONC_units, "conc_units"}, - {attCONC_equation_name, "conc_equation_name"}, - {attCONC_phase_si, "conc_phase_si"}, - {attCONC_n_pe, "conc_n_pe"}, - {attCONC_as, "conc_as"}, - {attCONC_gfw, "conc_gfw"}, - - }; - - count_attributeInfo = - sizeof(attributeInfo) / sizeof(struct mapAttributeInfo); - for (i = 0; i < count_elementInfo; i++) - { - // memory freed in destructor - this->mapXMLCh2Type[xns::XMLString::transcode(elementInfo[i].key)] = - elementInfo[i].type; - } - for (i = 0; i < count_attributeInfo; i++) - { - // memory freed in destructor - this-> - mapXMLCh2AttType[xns::XMLString:: - transcode(attributeInfo[i].key)] = - attributeInfo[i].type; - } - - this->totals.reserve(50); - this->acts.reserve(50); -} - -SaxPhreeqcHandlers::~SaxPhreeqcHandlers() -{ - std::map < const XMLCh *, elementType, XMLCH_LESS >::iterator it = - this->mapXMLCh2Type.begin(); - for (; it != this->mapXMLCh2Type.end(); ++it) - { - XMLCh *p = (XMLCh *) it->first; - xns::XMLString::release(&p); - } - this->mapXMLCh2Type.clear(); - std::map < const XMLCh *, attributeType, XMLCH_LESS >::iterator ita = - this->mapXMLCh2AttType.begin(); - for (; ita != this->mapXMLCh2AttType.end(); ++ita) - { - XMLCh *p = (XMLCh *) ita->first; - xns::XMLString::release(&p); - } - this->mapXMLCh2AttType.clear(); - -} - -// ----------------------------------------------------------------------- -// Implementations of the SAX DocumentHandler interface -// ----------------------------------------------------------------------- - -void -SaxPhreeqcHandlers::endDocument() -{ -} - -void -SaxPhreeqcHandlers::endElement(const XMLCh * const uri, - const XMLCh * const name, - const XMLCh * const qname) -{ - switch (this->mapXMLCh2Type[name]) - { - case typeSOLUTION: - // solution is finished now copy into solutions array - { - int n; - // copy vector of conc's to solution - this->solution_ptr->totals = - (struct conc *) PHRQ_realloc(this->solution_ptr->totals, - (size_t) (this->totals.size() + - 1) * - sizeof(struct conc)); - std::copy(this->totals.begin(), this->totals.end(), - this->solution_ptr->totals); - this->solution_ptr->totals[this->totals.size()].description = - NULL; - this->totals.clear(); - assert(this->totals.size() == 0); - - // copy vector of master_activities's to solution - this->solution_ptr->master_activity = - (struct master_activity *) free_check_null(this-> - solution_ptr-> - master_activity); - if (this->acts.size() > 0) - { - this->solution_ptr->master_activity = - (struct master_activity *) PHRQ_realloc(this-> - solution_ptr-> - master_activity, - (size_t) (this-> - acts. - size()) - * - sizeof(struct - master_activity)); - std::copy(this->acts.begin(), this->acts.end(), - this->solution_ptr->master_activity); - } - this->solution_ptr->count_master_activity = this->acts.size(); - this->acts.clear(); - assert(this->acts.size() == 0); - - // copy vector of s_gamma's to solution - this->solution_ptr->species_gamma = - (struct master_activity *) free_check_null(this-> - solution_ptr-> - species_gamma); - if (this->s_gammas.size() > 0) - { - this->solution_ptr->species_gamma = - (struct master_activity *) PHRQ_realloc(this-> - solution_ptr-> - species_gamma, - (size_t) (this-> - s_gammas. - size()) - * - sizeof(struct - master_activity)); - std::copy(this->s_gammas.begin(), this->s_gammas.end(), - this->solution_ptr->species_gamma); - } - this->solution_ptr->count_species_gamma = this->s_gammas.size(); - this->s_gammas.clear(); - assert(this->s_gammas.size() == 0); - - // copy vector of isotopes's to solution - this->solution_ptr->isotopes = - (struct isotope *) free_check_null(this->solution_ptr-> - isotopes); - if (this->isotopes.size() > 0) - { - this->solution_ptr->isotopes = - (struct isotope *) PHRQ_realloc(this->solution_ptr-> - isotopes, - (size_t) (this->isotopes. - size()) * - sizeof(struct isotope)); - std::copy(this->isotopes.begin(), this->isotopes.end(), - this->solution_ptr->isotopes); - } - this->solution_ptr->count_isotopes = this->isotopes.size(); - this->isotopes.clear(); - assert(this->isotopes.size() == 0); - - - // store solution for now - if (solution_bsearch(this->solution_ptr->n_user, &n, FALSE) != - NULL) - { - solution_free(solution[n]); - solution[n] = this->solution_ptr; - } - else - { - n = count_solution++; - if (count_solution >= max_solution) - { - space((void **) &(solution), count_solution, - &max_solution, sizeof(struct solution *)); - } - solution[n] = this->solution_ptr; - } - this->solution_ptr = NULL; - } - break; - default: - break; - } -} - -void -SaxPhreeqcHandlers::characters(const XMLCh * const chars, - const unsigned int length) -{ - // skip whitespace - - //XMLCh* pChar = (XMLCh*)chars; - //while(pChar && iswspace(*pChar)) ++pChar; - //if (*pChar) - // { -/* - switch(this->eltType) - { - case typeSOLN_MASTER_ACTIVITY: - //xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(chars); - for ( i = 0; i < arg->size() - 1; i+=2 ) { - struct master_activity *ma = new master_activity(); - ma->description = XMLCh_hsave( arg->elementAt(i), true); - ma->la = XMLCh2Double( arg->elementAt(i + 1)); - this->acts.push_back(*ma); - } - //struct master_activity *ma = new master_activity(); - //ma->description = NULL; - //this->acts.push_back(*ma); - break; - } - */ - -} - -void -SaxPhreeqcHandlers::ignorableWhitespace(const XMLCh * const chars, - const unsigned int length) -{ -} - -void -SaxPhreeqcHandlers::processingInstruction(const XMLCh * const target, - const XMLCh * const data) -{ -} - -void -SaxPhreeqcHandlers::startDocument() -{ -} - -void -SaxPhreeqcHandlers::startElement(const XMLCh * const uri, - const XMLCh * const name, - const XMLCh * const qname, - const xns::Attributes & attributes) -{ - //const char ERR_MSG[] = "Unpacking solution message: %s, element not found\n"; - char *string; - - int i; - - string = xns::XMLString::transcode(name); - this->eltType = this->mapXMLCh2Type[name]; - xns::XMLString::release(&string); - switch (this->eltType) - { - case typePHAST_STATE: - XMLCh * x; - x = xns::XMLString::transcode("nx"); - i = XMLCh2Int(attributes.getValue(x)); - xns::XMLString::release(&x); - break; - case typeSOLUTION: - assert(this->solution_ptr == NULL); - assert(this->totals.size() == 0); - assert(this->acts.size() == 0); - - // allocate space for solution - this->solution_ptr = solution_alloc(); - - // process attributes for solution - processSolutionAttributes(attributes); - break; - case typeSOLN_PE: - assert(this->solution_ptr->pe != NULL); - // store pe, no need to clean up at end of solution - if ((attributes.getLength() >= 1) - && (this->mapXMLCh2AttType[attributes.getLocalName(0)] == - attSOLN_PE_name)) - { - string = - xns::XMLString::transcode(attributes. - getValue((unsigned int) 0)); - pe_data_store(&(this->solution_ptr->pe), string); - xns::XMLString::release(&string); - } - else - { - ++input_error; - sprintf(error_string, "No attribute data for SOLN_PE.\n"); - error_msg(error_string, CONTINUE); - } - break; - case typeSOLN_TOTAL: - { - // store in c, push_back on totals - // need to copy and clean up at end of - struct conc c; - processSolutionTotalAttributes(attributes, &c); - this->totals.push_back(c); - } - break; - case typeSOLN_MASTER_ACTIVITY: - { - // store in ma, push_back on acts - // need to copy and clean up at end of - struct master_activity ma; - processMasterActivityAttributes(attributes, &ma); - this->acts.push_back(ma); - //processMasterActivityAttributes(attributes, &this->acts); - } - break; - case typeSOLN_SPECIES_GAMMA: - { - // store in ma, push_back on s_gammas - // need to copy and clean up at end of - struct master_activity ma; - processMasterActivityAttributes(attributes, &ma); - this->s_gammas.push_back(ma); - } - break; - case typeSOLN_ISOTOPE: - { - // store in iso, push_back on isotopes - // need to copy and clean up at end of - struct isotope iso; - processIsotopeAttributes(attributes, &iso); - this->isotopes.push_back(iso); - } - break; - - default: - break; - } -} -int -SaxPhreeqcHandlers::processSolutionAttributes(const xns:: - Attributes & attributes) -{ - const char ERR_MSG[] = - "Unpacking solution attributes: %s, attribute not found\n"; - unsigned int i; - char *string; - attributeType attType; - assert(this->eltType == typeSOLUTION); - assert(this->solution_ptr != NULL); - - // Get attribute name, map to attribute type, process - - for (i = 0; i < attributes.getLength(); i++) - { - attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) - { - case attSOLN_new_def: - this->solution_ptr->new_def = XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_n_user: - this->solution_ptr->n_user = XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_n_user_end: - this->solution_ptr->n_user_end = - XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_description: - this->solution_ptr->description = - XMLCh2String(attributes.getValue(i)); - break; - case attSOLN_tc: - this->solution_ptr->tc = XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_ph: - this->solution_ptr->ph = XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_solution_pe: - this->solution_ptr->solution_pe = - XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_mu: - this->solution_ptr->mu = XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_ah2o: - this->solution_ptr->ah2o = XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_density: - this->solution_ptr->density = - XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_total_h: - this->solution_ptr->total_h = - XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_total_o: - this->solution_ptr->total_o = - XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_cb: - this->solution_ptr->cb = XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_mass_water: - this->solution_ptr->mass_water = - XMLCh2Double(attributes.getValue(i)); - break; - case attSOLN_total_alkalinity: - this->solution_ptr->total_alkalinity = - XMLCh2Double(attributes.getValue(i)); - break; - //case attSOLN_total_co2: - //this->solution_ptr->total_co2 = XMLCh2Double(attributes.getValue(i)); - //break; - case attSOLN_units: - this->solution_ptr->units = - XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attSOLN_default_pe: - this->solution_ptr->default_pe = - XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_count_master_activity: - this->solution_ptr->count_master_activity = - XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_count_isotopes: - this->solution_ptr->count_isotopes = - XMLCh2Int(attributes.getValue(i)); - break; - case attSOLN_count_species_gamma: - this->solution_ptr->count_species_gamma = - XMLCh2Int(attributes.getValue(i)); - break; - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } - } - return 0; -} - -int -SaxPhreeqcHandlers::processSolutionTotalAttributes(const xns:: - Attributes & attributes, - struct conc *c) -{ - const char ERR_MSG[] = - "Unpacking solution totals attributes: %s, attribute not found\n"; - unsigned int i; - char *string; - conc_init(c); - attributeType attType; - assert(this->eltType == typeSOLN_TOTAL); - - - // Get attribute name, map to attribute type, process - - for (i = 0; i < attributes.getLength(); i++) - { - attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) - { - case attCONC_description: - c->description = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attCONC_moles: - c->moles = XMLCh2Double(attributes.getValue(i)); - break; - case attCONC_input_conc: - c->input_conc = XMLCh2Double(attributes.getValue(i)); - break; - case attCONC_units: - c->units = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attCONC_equation_name: - c->equation_name = XMLCh_hsave(attributes.getValue(i), TRUE); - c->phase = NULL; - break; - case attCONC_phase_si: - c->phase_si = XMLCh2Double(attributes.getValue(i)); - break; - case attCONC_n_pe: - c->n_pe = XMLCh2Int(attributes.getValue(i)); - break; - case attCONC_as: - c->as = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attCONC_gfw: - c->gfw = XMLCh2Double(attributes.getValue(i)); - break; - - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } - } - return (OK); -} - -int -SaxPhreeqcHandlers::processMasterActivityAttributes(const xns:: - Attributes & attributes, - struct master_activity - *ma) -//int SaxPhreeqcHandlers::processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v) -{ - int i; - char *string; - const char ERR_MSG[] = - "Unpacking master activity attributes: %s, attribute not found\n"; - ma->description = NULL; - ma->la = 0.0; - attributeType attType; - for (i = 0; i < (int) attributes.getLength(); i++) - { - attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - - switch (attType) - { - - case attM_A_description: - ma->description = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attM_A_la: - ma->la = XMLCh2Double(attributes.getValue(i)); - break; - /* - case attM_A_list: - { - struct master_activity ma; - xns::BaseRefVectorOf *arg = xns::XMLString::tokenizeString(attributes.getValue((unsigned int) 0)); - - for ( i = 0; i < arg->size(); i+=2 ) { - ma.description = XMLCh_hsave( arg->elementAt(i), TRUE); - if (strcmp(ma.description, "null") == 0) { - ma.description = NULL; - } - ma.la = XMLCh2Double( arg->elementAt(i+1)); - //this->acts.push_back(ma); - (*v).push_back(ma); - } - } - break; - */ - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } - } - return (OK); -} - -int -SaxPhreeqcHandlers::processIsotopeAttributes(const xns:: - Attributes & attributes, - struct isotope *iso) -{ - int i; - char *string; - const char ERR_MSG[] = - "Unpacking isotope attributes: %s, attribute not found\n"; - - iso->primary = iso->master = NULL; - iso->elt_name = iso->isotope_name = NULL; - attributeType attType; - for (i = 0; i < (int) attributes.getLength(); i++) - { - attType = this->mapXMLCh2AttType[attributes.getLocalName(i)]; - switch (attType) - { - case attISO_isotope_number: - iso->isotope_number = XMLCh2Int(attributes.getValue(i)); - break; - case attISO_elt_name: - iso->elt_name = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attISO_isotope_name: - iso->isotope_name = XMLCh_hsave(attributes.getValue(i), TRUE); - break; - case attISO_total: - iso->total = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_ratio: - iso->ratio = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_ratio_uncertainty: - iso->ratio_uncertainty = XMLCh2Double(attributes.getValue(i)); - break; - case attISO_coef: - iso->coef = XMLCh2Double(attributes.getValue(i)); - break; - - default: - ++input_error; - string = xns::XMLString::transcode(attributes.getLocalName(i)); - sprintf(error_string, ERR_MSG, string); - error_msg(error_string, CONTINUE); - xns::XMLString::release(&string); - break; - } - } - return (OK); -} diff --git a/SAXPhreeqc.h b/SAXPhreeqc.h deleted file mode 100644 index 62b0da05..00000000 --- a/SAXPhreeqc.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _INC_SAXPHREEQC_H -#define _INC_SAXPHREEQC_H - -#if defined(__cplusplus) | defined(_CPP) -extern "C" -{ -#endif - - void SAX_StartSystem(); - int SAX_AddSolution(struct solution *solution_ptr); - void SAX_EndSystem(); - int SAX_GetXMLLength(); - const char *SAX_GetXMLStr(); - int SAX_UnpackSolutions(void *pvBuffer, int buf_size); - - -#if defined(__cplusplus) | defined(_CPP) -} -#endif - -#endif diff --git a/SaxPhreeqcHandlers.h b/SaxPhreeqcHandlers.h deleted file mode 100644 index eb247ed9..00000000 --- a/SaxPhreeqcHandlers.h +++ /dev/null @@ -1,206 +0,0 @@ -// SaxPhreeqcHandlers.h: interface for the SaxPhreeqcHandlers class. -// -////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_) -#define AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_ - -#if _MSC_VER > 1000 -#pragma once -#endif // _MSC_VER > 1000 - -#include // iswspace sprintf -#include // SAX2XMLReader -/** -#include -**/ -#include -#include - -#define xns XERCES_CPP_NAMESPACE - -#ifdef USE_LONG_DOUBLE -#define LDBLE long double -#else -#define LDBLE double -#endif - -struct XMLCH_LESS: -std::binary_function < const XMLCh *, const XMLCh *, - bool > -{ - bool - operator() (const XMLCh * _X, const XMLCh * _Y) const - { - return - xns::XMLString::compareString(_X, _Y) < - 0; - } -}; - -#include -//extern "C" { -#define EXTERNAL extern -//#include "phqalloc.h" -#include "global.h" -#include "phrqproto.h" -// int conc_init(struct conc *conc_ptr); -//} - - -class - Cconc: - public - conc -{ - public: - Cconc() - { - conc_init(this); - } - ~ - Cconc() - {; - } -}; - - -class - SaxPhreeqcHandlers: - public - xns::DefaultHandler -{ - public: - SaxPhreeqcHandlers(); - virtual ~ - SaxPhreeqcHandlers(); - - // ----------------------------------------------------------------------- - // Implementations of the SAX DocumentHandler interface - // ----------------------------------------------------------------------- - void - endDocument(); - - void - endElement(const XMLCh * const uri, const XMLCh * const name, - const XMLCh * const qname); - - void - characters(const XMLCh * const chars, const unsigned int length); - - void - ignorableWhitespace(const XMLCh * const chars, const unsigned int length); - - void - processingInstruction(const XMLCh * const target, - const XMLCh * const data); - - void - startDocument(); - - void - startElement(const XMLCh * const uri, const XMLCh * const name, - const XMLCh * const qname, - const xns::Attributes & attributes); - - // element types - enum elementType - { - typeNULL, - typePHAST_STATE, - typeSYSTEM, - typeSOLUTION, - typeSOLN_PE, - typeSOLN_TOTAL, - typeSOLN_MASTER_ACTIVITY, - typeSOLN_ISOTOPE, - typeSOLN_SPECIES_GAMMA - } eltType; - // attribute types - enum attributeType - { - attNULL, - attSOLN_new_def, - attSOLN_n_user, - attSOLN_n_user_end, - attSOLN_description, - attSOLN_tc, - attSOLN_ph, - attSOLN_solution_pe, - attSOLN_mu, - attSOLN_ah2o, - attSOLN_density, - attSOLN_total_h, - attSOLN_total_o, - attSOLN_cb, - attSOLN_mass_water, - attSOLN_total_alkalinity, - attSOLN_total_co2, - attSOLN_units, - attSOLN_default_pe, - attSOLN_count_master_activity, - attSOLN_count_isotopes, - attSOLN_count_species_gamma, - attSOLN_PE_name, - attM_A_description, - attM_A_la, - attM_A_list, - attISO_isotope_number, - attISO_elt_name, - attISO_isotope_name, - attISO_total, - attISO_ratio, - attISO_ratio_uncertainty, - attISO_x_ratio_uncertainty, - attISO_coef, - attCONC_description, - attCONC_moles, - attCONC_input_conc, - attCONC_units, - attCONC_equation_name, - attCONC_phase_si, - attCONC_n_pe, - attCONC_as, - attCONC_gfw, - } attType; - - int - processSolutionAttributes(const xns::Attributes & attributes); - int - processSolutionTotalAttributes(const xns::Attributes & attributes, - struct conc *c); - int - processMasterActivityAttributes(const xns::Attributes & attributes, - struct master_activity *ma); - //int processMasterActivityAttributes(const xns::Attributes& attributes, std::vector *v); - int - processIsotopeAttributes(const xns::Attributes & attributes, - struct isotope *iso); - - protected: - std::vector < - conc > - totals; - std::vector < - master_activity > - acts, - s_gammas; - std::vector < - isotope > - isotopes; - std::map < const XMLCh *, - elementType, - XMLCH_LESS > - mapXMLCh2Type; - std::map < const XMLCh *, - attributeType, - XMLCH_LESS > - mapXMLCh2AttType; - /** - std::hash_map, XMLCH_EQUALS> m_hashmapXMLCh2Type; - **/ - struct solution * - solution_ptr; -}; - -#endif // !defined(AFX_SAXPHREEQCHANDLERS_H__4A69D5F5_2E57_4001_911D_4ABF6F2C0A0B__INCLUDED_) diff --git a/Utils.cxx b/Utils.cxx index 858ee069..6bd79662 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -79,7 +79,16 @@ Utilities::squeeze_white(std::string & s_l) std::string str; std::string::iterator beg = s_l.begin(); std::string::iterator end = s_l.end(); - CParser::copy_token(str, beg, end); + //CParser::copy_token(str, beg, end); + std::string::iterator pos; + for (pos = beg; pos != end; pos++) + { + int c = *pos; + if (!::isspace(c)) + { + str += c; + } + } s_l = str; } @@ -96,7 +105,7 @@ Utilities::error_msg(const std::string & err_str, const int stop) //+NAN double: 7ff8000000000000 //-NAN double: fff8000000000000 -/* + double Utilities::get_nan(void) { unsigned long long raw = 0x7ff0000000000000; @@ -104,5 +113,5 @@ double Utilities::get_nan(void) return(d); } -*/ + diff --git a/char_star.h b/char_star.h deleted file mode 100644 index 24fdbdf7..00000000 --- a/char_star.h +++ /dev/null @@ -1,16 +0,0 @@ -#if !defined(CHARSTAR_H_INCLUDED) -#define CHARSTAR_H_INCLUDED - -struct CHARSTAR_LESS: -std::binary_function < const char *, const char *, - bool > -{ - bool - operator() (const char *_X, const char *_Y) const - { - return::strcmp(_X, _Y) < - 0; - } -}; - -#endif From 99f7eab602f017195653468471732d58121fb12d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 May 2011 15:07:52 +0000 Subject: [PATCH 0207/1077] Had duplicate chart_start code. Memory bug, chart_start did not set form_start. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5366 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 1 - ChartObject.cpp | 26 ++------------------------ 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 7b8a60cd..43178879 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -36,7 +36,6 @@ ChartHandler::~ChartHandler() std::map::iterator it; for (it = this->chart_map.begin(); it != chart_map.end(); it++) { - it->second->Rate_free(); delete it->second; } } diff --git a/ChartObject.cpp b/ChartObject.cpp index d5906426..fa0e9b8d 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -112,6 +112,7 @@ ChartObject::ChartObject() ChartObject::~ChartObject() { + this->Rate_free(); delete this->user_graph; std::vector::iterator it; @@ -838,29 +839,6 @@ ChartObject::SaveCurvesToFile(std::string &file_name) return; } // file only used with MULTICHART -#if !defined PHREEQC_CLASS -bool -ChartObject::start_chart(void) -{ - Application::EnableVisualStyles(); - Application::SetCompatibleTextRenderingDefault(true); - - // needed to send ChartObject pointer to thread - Thread ^t = gcnew Thread( - gcnew ParameterizedThreadStart(Form1::ThreadForm)); - - t->SetApartmentState(ApartmentState::STA); - t->IsBackground = false; - t->Priority = ThreadPriority::Normal; - - ChartObj ^p = gcnew ChartObj(this); - t->Start(p); - - //Thread::Sleep( 1 ); /* this when debugging... */ - //_beginthread(void (Form1::ThreadForm), 0, NULL); - return true; -} -#else bool ChartObject::start_chart(void) { @@ -883,7 +861,7 @@ ChartObject::start_chart(void) //_beginthread(void (Form1::ThreadForm), 0, NULL); return true; } -#endif + void ChartObject::Rate_free(void) { From 5af51e0c96ed5b1aa11da745564cf33909c675e0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 May 2011 17:59:21 +0000 Subject: [PATCH 0208/1077] May need to free rate even if Form has not started. Revised ex8 to use two charts. Changed RXN to give value for ADVECTION and TRANSPORT states, in addition to REACTION state. Reset point_added to false in time1_Tick. Changed NA value to -98.765 to avoid conflict with -10 for axis scale. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5370 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 43178879..88d9362e 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -135,6 +135,7 @@ ChartHandler::End_timer(PHREEQC_PTR_ARG) // } //} size_t i = 0; + it->second->Rate_free(); if (it->second->Get_form_started()) { while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1) && i < max_tries) @@ -143,7 +144,6 @@ ChartHandler::End_timer(PHREEQC_PTR_ARG) System::Threading::Thread::Sleep(1); } it->second->Set_end_timer(true); - it->second->Rate_free(); System::Threading::Interlocked::Exchange(it->second->usingResource, 0); size_t i2 = 0; From 2d59bd8c296a0664fd5f512c932c141a1d36499b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 May 2011 16:55:57 +0000 Subject: [PATCH 0209/1077] Worked on logic for Tony. If headings are defined, don't remove Basic code. If no definitions in USER_GRAPH, remove Basic code. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5372 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index fa0e9b8d..7804c9c0 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -265,7 +265,8 @@ ChartObject::Read(CParser & parser) std::string token; int opt_save; bool useLastLine(false); - bool new_command_lines(true); + bool new_command_lines(false); + bool no_def(true); if (this->FirstCallToUSER_GRAPH) { } @@ -408,10 +409,10 @@ ChartObject::Read(CParser & parser) /* End of modifications */ case CParser::OPT_DEFAULT: // Read Basic commands { - if (new_command_lines) + if (!new_command_lines) { this->rate_command_list.clear(); - new_command_lines = false; + new_command_lines = true; } this->rate_new_def = true; /* read command */ @@ -436,10 +437,12 @@ ChartObject::Read(CParser & parser) } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; + no_def = false; } // install new plotxy commands - this->Set_rate_struct(); + // disable this user_graph if USER_GRAPH block is empty + if (new_command_lines || no_def) this->Set_rate_struct(); return true; } bool From f2fcaea1423af7ddce539a178237fe7c3fd751db Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 May 2011 20:05:13 +0000 Subject: [PATCH 0210/1077] Revised for Tony's comments. CSV colors have separate default_color_csv. Added -active. If csv for graph_y or graph_sy, no symbols. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5373 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++---- ChartObject.h | 8 ++++- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 7804c9c0..ef0c8b75 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -99,6 +99,9 @@ ChartObject::ChartObject() user_graph->linebase = user_graph->loopbase = user_graph->varbase = NULL; default_symbol = 0; + default_symbol_csv = 0; + default_color = 0; + default_color_csv = 0; graph_x = NA; graph_y.clear(); @@ -243,7 +246,7 @@ ChartObject::Read(CParser & parser) static std::vector < std::string > vopts; if (vopts.empty()) { - vopts.reserve(15); + vopts.reserve(20); vopts.push_back("start"); // 0 vopts.push_back("end"); // 1 vopts.push_back("heading"); // 2 @@ -259,6 +262,8 @@ ChartObject::Read(CParser & parser) vopts.push_back("plot_csv_file"); // 12 vopts.push_back("clear"); // 13 vopts.push_back("detach"); // 14 + vopts.push_back("active"); // 15 + } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -266,6 +271,7 @@ ChartObject::Read(CParser & parser) int opt_save; bool useLastLine(false); bool new_command_lines(false); + // if no definitions in USER_GRAPH data block, deactivate plot bool no_def(true); if (this->FirstCallToUSER_GRAPH) { @@ -407,6 +413,10 @@ ChartObject::Read(CParser & parser) this->detach = true; break; /* End of modifications */ + case 15: /* active */ + this->active = parser.get_true_false(next_char, true); + break; + /* End of modifications */ case CParser::OPT_DEFAULT: // Read Basic commands { if (!new_command_lines) @@ -442,7 +452,9 @@ ChartObject::Read(CParser & parser) // install new plotxy commands // disable this user_graph if USER_GRAPH block is empty - if (new_command_lines || no_def) this->Set_rate_struct(); + //if (new_command_lines || no_def) this->Set_rate_struct(); + if (new_command_lines) this->Set_rate_struct(); + if (no_def) this->Set_active(false); return true; } bool @@ -494,7 +506,7 @@ ChartObject::OpenCSVFile(std::string file_name) c->Set_id(headings[i]); c->Set_line_w(0); std::string sym = ""; - this->Get_legal_symbol(sym); + this->Get_legal_symbol_csv(sym); c->Set_symbol(sym); csv_curves.push_back(c); } @@ -528,7 +540,10 @@ ChartObject::OpenCSVFile(std::string file_name) } else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) { - csv_curves[i]->Set_symbol_size(atof(tok2.c_str())); + if (tok2.size() > 0) + { + csv_curves[i]->Set_symbol_size(atof(tok2.c_str())); + } } else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) { @@ -536,7 +551,10 @@ ChartObject::OpenCSVFile(std::string file_name) } else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) { - csv_curves[i]->Set_y_axis(atoi(tok2.c_str())); + if (tok2.size() > 0) + { + csv_curves[i]->Set_y_axis(atoi(tok2.c_str())); + } } i++; } @@ -584,6 +602,9 @@ ChartObject::OpenCSVFile(std::string file_name) { if ((*it)->Get_x().size() > 0) { + std::string col = (*it)->Get_color(); + this->Get_color_string_csv(col); + (*it)->Set_color(col); this->CurvesCSV.push_back(*it); this->Set_curve_added(true); } @@ -708,6 +729,48 @@ ChartObject::Get_legal_symbol(std::string &sym) } return; } +void +ChartObject::Get_legal_symbol_csv(std::string &sym) +{ + std::map::iterator it; + if ((it = this->Symbol_map.find(sym)) == this->Symbol_map.end()) + { + sym = "Default"; + for (it = this->Symbol_map.begin(); it != this->Symbol_map.end(); it++) + { + if (this->default_symbol_csv == it->second) + { + sym = it->first; + break; + } + } + default_symbol_csv++; + default_symbol_csv = default_symbol_csv % this->Symbol_map.size(); + } + return; +} +void +ChartObject::Get_color_string(std::string &color) +{ + if (color.size() == 0) + { + color = Color_vector[this->default_color]; + default_color++; + default_color = default_color % this->Color_vector.size(); + } + return; +} +void +ChartObject::Get_color_string_csv(std::string &color) +{ + if (color.size() == 0) + { + color = Color_vector[this->default_color_csv]; + default_color_csv++; + default_color_csv = default_color_csv % this->Color_vector.size(); + } + return; +} ZedGraph::SymbolType ChartObject::Return_SymbolType(const std::string sym) { @@ -911,7 +974,7 @@ ChartObject::Finalize_graph_pts(void) } void -ChartObject::Add_curve(std::string id, +ChartObject::Add_curve(bool plotxy, std::string id, double line_width, std::string symbol, double symbol_size, @@ -925,7 +988,12 @@ ChartObject::Add_curve(std::string id, this->Get_legal_symbol(symbol); c->Set_symbol(symbol); c->Set_symbol_size(symbol_size); + if (this->CurvesCSV.size() > 0 && !plotxy) + { + c->Set_symbol_size(0.0); + } c->Set_y_axis(y_axis); + this->Get_color_string(color); c->Set_color(color); this->Curves.push_back(c); diff --git a/ChartObject.h b/ChartObject.h index 21a7c8f7..28a3597f 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -299,8 +299,11 @@ class ChartObject:public cxxNumKeyword void Initialize_graph_pts(void); void Finalize_graph_pts(void); void Get_legal_symbol(std::string &sym); + void Get_legal_symbol_csv(std::string &sym); + void Get_color_string(std::string &color); + void Get_color_string_csv(std::string &color); //void Add_new_series(void); - void Add_curve(std::string id = "", + void Add_curve(bool plotxy, std::string id = "", double line_width = 1.0, std::string symbol = "", double symbol_size = 6.0, @@ -350,6 +353,9 @@ class ChartObject:public cxxNumKeyword bool rate_new_def; int default_symbol; + int default_symbol_csv; + int default_color; + int default_color_csv; // temporary storage before stored graph_x/y/sy data are stored in curves // Initialize_graph_pts and Finalize_graph_pts use this storage. From 1238db9163a0639ece63f361b28eedd28d4339ac Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 May 2011 22:58:45 +0000 Subject: [PATCH 0211/1077] Made fixes for Tony's 5/06/11 zedgraph tests. Fixed connect simulations. Not sure all logic is yet correct. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5375 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 166 +++++++++++++++++++++++++++++++++++++++++++++++- ChartObject.h | 12 +++- 2 files changed, 176 insertions(+), 2 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index ef0c8b75..c197cfed 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -275,6 +275,7 @@ ChartObject::Read(CParser & parser) bool no_def(true); if (this->FirstCallToUSER_GRAPH) { + this->new_ug = true; } else { @@ -621,6 +622,147 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) int curvenr = (int) this->Curves.size(); std::string str_line = cmd_line; + // Massage line + while (Utilities::replace(" ,",",",str_line)); + while (Utilities::replace("\t,",",",str_line)); + while (Utilities::replace(",","#",str_line)); + while (Utilities::replace("#",", ", str_line)); + + int sel; + std::string token, tok1, tok2; + std::string revised_line; + std::string::iterator b = str_line.begin(); + std::string::iterator e = str_line.end(); + // new curve + CurveObject new_curve; + + while (CParser::copy_token(token, b, e) != CParser::TT_EMPTY) + { + sel = -1; + std::string token_save = token; + Utilities::str_tolower(token); + tok1 = token; + if (!strncmp(tok1.c_str(), "color", 5)) + { + sel = 0; + } + else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) + && (strstr(tok1.c_str(), "-si") == NULL)) + { + sel = 1; + } + else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) + { + sel = 2; + } + else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) + { + sel = 3; + } + else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) + { + sel = 4; + } + + // Append to command line + if (sel < 0) + { + revised_line.append(token_save); + revised_line.append(" "); + } + // Parse plot_xy pair + else + { + // remove preceding comma + std::string comma = revised_line.substr(revised_line.size() - 2); + if (comma == ", ") + { + revised_line = revised_line.substr(0, revised_line.size() - 2); + revised_line.append(" "); + } + + size_t p1 = token.find("="); + std::string tok2; + // "=" found + if(p1 != std::string::npos) + { + if (p1 != token.size() - 1) + { + // color=Red + tok2 = token.substr(p1 + 1); + } + else + { + // color= Red + CParser::copy_token(tok2, b, e); + } + } + else + { + // no "=" found + CParser::copy_token(tok2, b, e); + p1 = tok2.find("="); + if (tok2 == "=") + { + // color = Red + CParser::copy_token(tok2, b, e); + } + else if (p1 != std::string::npos) + { + // color =Red + tok2 = tok2.substr(p1 + 1); + } + else + { + // color Red + tok2 = tok2; + } + + // remove any commas + while(Utilities::replace(",","",tok1)); + while(Utilities::replace(",","",tok2)); + + // tok1 is name, tok2 is value + + switch (sel) + { + case 0: + new_curve.Set_color(tok2); + break; + case 1: + new_curve.Set_symbol(tok2); + break; + case 2: + new_curve.Set_symbol_size(atof(tok2.c_str())); + break; + case 3: + new_curve.Set_line_w(atof(tok2.c_str())); + break; + case 4: + new_curve.Set_y_axis(atoi(tok2.c_str())); + break; + } + } + } + } + + // Add to list of new plotxy curves + this->new_plotxy_curves.push_back(new_curve); + //std::cerr << revised_line << std::endl; + cmd_line = revised_line; +} +#ifdef SKIP_OLD +void +ChartObject::ExtractCurveInfo(std::string & cmd_line) +{ + /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ + + // Make copy of cmd_line + int curvenr = (int) this->Curves.size(); + std::string str_line = cmd_line; + + + // find command part of cmd_line Utilities::replace(",","#",cmd_line); size_t pos = cmd_line.find(","); @@ -689,6 +831,7 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) // Add to list of new plotxy curves this->new_plotxy_curves.push_back(new_curve); } +#endif void ChartObject::Set_rate_struct(void) { @@ -961,6 +1104,9 @@ ChartObject::Finalize_graph_pts(void) { Curves[it->first]->Get_x().push_back(graph_x); Curves[it->first]->Get_y().push_back(it->second); + // Mark added curve for first point, might have been invisible in DefineCurves + if (Curves[it->first]->Get_x().size() == 1) + this->Set_curve_added(true); } } if (graph_x != NA) @@ -972,7 +1118,25 @@ ChartObject::Finalize_graph_pts(void) } } } - +void +ChartObject::Add_new_series(void) +{ + std::vector Curves; + size_t i; + size_t e = this->Curves.size(); + for (i = this->ColumnOffset; i < e; i++) + { + this->Add_curve(false, + this->Curves[i]->Get_id(), + this->Curves[i]->Get_line_w(), + "", + this->Curves[i]->Get_symbol_size(), + this->Curves[i]->Get_y_axis(), + ""); + } + this->ColumnOffset = (int) e; + this->curve_added = true; +} void ChartObject::Add_curve(bool plotxy, std::string id, double line_width, diff --git a/ChartObject.h b/ChartObject.h index 28a3597f..9db091b7 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -129,6 +129,15 @@ class ChartObject:public cxxNumKeyword { return (this->ColumnOffset); } + // bool AddSeries; + void Set_AddSeries(bool b) + { + this->AddSeries = b; + } + bool Get_AddSeries() + { + return this->AddSeries; + } // int prev_advection_step; void Set_prev_advection_step(int i) { @@ -302,7 +311,7 @@ class ChartObject:public cxxNumKeyword void Get_legal_symbol_csv(std::string &sym); void Get_color_string(std::string &color); void Get_color_string_csv(std::string &color); - //void Add_new_series(void); + void Add_new_series(void); void Add_curve(bool plotxy, std::string id = "", double line_width = 1.0, std::string symbol = "", @@ -332,6 +341,7 @@ class ChartObject:public cxxNumKeyword int colnr; int RowOffset; int ColumnOffset; + bool AddSeries; int prev_advection_step; int prev_transport_step; From 24eabcb5d79a3174ab73dc5299ff3a0bf33e5653 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 May 2011 16:33:25 +0000 Subject: [PATCH 0212/1077] Couple errors in parsing chart parameters. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5382 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index c197cfed..e43a08fe 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -681,6 +681,7 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) revised_line.append(" "); } + token = token_save; size_t p1 = token.find("="); std::string tok2; // "=" found @@ -717,31 +718,30 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) // color Red tok2 = tok2; } + } + // remove any commas + while(Utilities::replace(",","",tok1)); + while(Utilities::replace(",","",tok2)); - // remove any commas - while(Utilities::replace(",","",tok1)); - while(Utilities::replace(",","",tok2)); + // tok1 is name, tok2 is value - // tok1 is name, tok2 is value - - switch (sel) - { - case 0: - new_curve.Set_color(tok2); - break; - case 1: - new_curve.Set_symbol(tok2); - break; - case 2: - new_curve.Set_symbol_size(atof(tok2.c_str())); - break; - case 3: - new_curve.Set_line_w(atof(tok2.c_str())); - break; - case 4: - new_curve.Set_y_axis(atoi(tok2.c_str())); - break; - } + switch (sel) + { + case 0: + new_curve.Set_color(tok2); + break; + case 1: + new_curve.Set_symbol(tok2); + break; + case 2: + new_curve.Set_symbol_size(atof(tok2.c_str())); + break; + case 3: + new_curve.Set_line_w(atof(tok2.c_str())); + break; + case 4: + new_curve.Set_y_axis(atoi(tok2.c_str())); + break; } } } From 1ac4976fb6279d82efe9c45ce21ace700b021b81 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 May 2011 20:36:33 +0000 Subject: [PATCH 0213/1077] Latest output for test cases. Removed NaN routine to avoid Linux warning. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5385 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Utils.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Utils.cxx b/Utils.cxx index 6bd79662..3027776c 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -105,7 +105,7 @@ Utilities::error_msg(const std::string & err_str, const int stop) //+NAN double: 7ff8000000000000 //-NAN double: fff8000000000000 - +/* double Utilities::get_nan(void) { unsigned long long raw = 0x7ff0000000000000; @@ -113,5 +113,4 @@ double Utilities::get_nan(void) return(d); } - - +*/ From c323063457302020cdcc12e2d473080321dffd84 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 13 May 2011 20:48:13 +0000 Subject: [PATCH 0214/1077] Trying modification of logic of user_graph seems to work, but I have no idea why. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5389 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- ChartObject.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index e43a08fe..bdcd1277 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -81,7 +81,7 @@ ChartObject::ChartObject() shifts_as_points = false; connect_simulations = true; colnr = 0; - RowOffset = 0; + rownr = -1; ColumnOffset = 0; prev_advection_step = 0; prev_transport_step = 0; diff --git a/ChartObject.h b/ChartObject.h index 9db091b7..dfa72a6a 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -111,14 +111,14 @@ class ChartObject:public cxxNumKeyword { return (this->colnr); } - // int RowOffset; - void Set_RowOffset(int i) + // int rownr; + void Set_rownr(int i) { - this->RowOffset = i; + this->rownr = i; } - int Get_RowOffset() + int Get_rownr() { - return (this->RowOffset); + return (this->rownr); } // int ColumnOffset; void Set_ColumnOffset(int i) @@ -339,7 +339,7 @@ class ChartObject:public cxxNumKeyword bool connect_simulations; int shifts_as_points; int colnr; - int RowOffset; + int rownr; int ColumnOffset; bool AddSeries; From 72298ad6e31b498d171f03e9d434e3572ed4ab86 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 May 2011 15:30:31 +0000 Subject: [PATCH 0215/1077] Simplified logic, but left old commented. Next step will remove unused logic. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5405 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChartObject.cpp b/ChartObject.cpp index bdcd1277..6e153986 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -327,10 +327,12 @@ ChartObject::Read(CParser & parser) break; case 2: /* headings */ case 3: /* heading */ + this->new_headings.clear(); while (parser.copy_token(token, next_char) != CParser::TT_EMPTY) { this->new_headings.push_back(token); } + break; case 4: /* chart title */ { From db5f8e6a981b1895fcb6051cfb7c753e1cf3be4f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 May 2011 15:56:23 +0000 Subject: [PATCH 0216/1077] Removed dead code and dead logic for adding series. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5406 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 83 ------------------------------------------------- ChartObject.h | 10 ------ 2 files changed, 93 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 6e153986..d776b15d 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -81,7 +81,6 @@ ChartObject::ChartObject() shifts_as_points = false; connect_simulations = true; colnr = 0; - rownr = -1; ColumnOffset = 0; prev_advection_step = 0; prev_transport_step = 0; @@ -283,7 +282,6 @@ ChartObject::Read(CParser & parser) this->new_ug = true; } this->new_plotxy_curves.clear(); - //this->new_headings.clear(); // Read number and description { @@ -753,87 +751,6 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) //std::cerr << revised_line << std::endl; cmd_line = revised_line; } -#ifdef SKIP_OLD -void -ChartObject::ExtractCurveInfo(std::string & cmd_line) -{ - /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ - - // Make copy of cmd_line - int curvenr = (int) this->Curves.size(); - std::string str_line = cmd_line; - - - - // find command part of cmd_line - Utilities::replace(",","#",cmd_line); - size_t pos = cmd_line.find(","); - if (pos != std::string::npos) - { - cmd_line = cmd_line.substr(0, pos); - Utilities::replace("#",",",cmd_line); - str_line.erase(0, pos + 1); - } - else - { - P_INSTANCE_POINTER error_msg("Did not find x and y expressions for plot_xy command in USER_GRAPH", STOP); - } - - // new curve - CurveObject new_curve; - - while (Utilities::replace(","," ",str_line)); - while (Utilities::replace("="," ",str_line)); - std::string::iterator b = str_line.begin(); - std::string::iterator e = str_line.end(); - - //while (CParser::copy_title(tok, b, e) != CParser::TT_EMPTY) - for(;;) - { - std::string tok1, tok2; - if ((CParser::copy_token(tok1, b, e) == CParser::TT_EMPTY) || - (CParser::copy_token(tok2, b, e) == CParser::TT_EMPTY)) - break; - Utilities::str_tolower(tok1); - if (!strncmp(tok1.c_str(), "color", 5)) - { - new_curve.Set_color(tok2); - continue; - } - else if (!strncmp(tok1.c_str(), "symbol", 5) && (strstr(tok1.c_str(), "_si") == NULL) - && (strstr(tok1.c_str(), "-si") == NULL)) - { - new_curve.Set_symbol(tok2); - continue; - } - else if (!strncmp(tok1.c_str(), "symbol_size", 8) || !strncmp(tok1.c_str(), "symbol-size", 8)) - { - new_curve.Set_symbol_size(atof(tok2.c_str())); - continue; - } - else if (!strncmp(tok1.c_str(), "line_w", 5) || !strncmp(tok1.c_str(), "line-w", 5)) - { - new_curve.Set_line_w(atof(tok2.c_str())); - continue; - } - else if (!strncmp(tok1.c_str(), "y_axis", 5) || !strncmp(tok1.c_str(), "y-axis", 5)) - { - new_curve.Set_y_axis(atoi(tok2.c_str())); - continue; - } - else - { - std::ostringstream estream; - estream << "Unknown input for plot_xy in USER_GRAPH " << str_line << std::endl; - P_INSTANCE_POINTER warning_msg(estream.str().c_str()); - continue; - } - } - - // Add to list of new plotxy curves - this->new_plotxy_curves.push_back(new_curve); -} -#endif void ChartObject::Set_rate_struct(void) { diff --git a/ChartObject.h b/ChartObject.h index dfa72a6a..c890b759 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -111,15 +111,6 @@ class ChartObject:public cxxNumKeyword { return (this->colnr); } - // int rownr; - void Set_rownr(int i) - { - this->rownr = i; - } - int Get_rownr() - { - return (this->rownr); - } // int ColumnOffset; void Set_ColumnOffset(int i) { @@ -339,7 +330,6 @@ class ChartObject:public cxxNumKeyword bool connect_simulations; int shifts_as_points; int colnr; - int rownr; int ColumnOffset; bool AddSeries; From 41a6354f1ee98288217d9777650777e909be7eb5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 May 2011 19:02:35 +0000 Subject: [PATCH 0217/1077] Added example 20 to examples.fm. Added ex20 files to Version3/ex. Modified parser to accept " or ' for titles. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5412 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Parser.cxx b/Parser.cxx index eaafa45e..a9e7fd4b 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1375,6 +1375,16 @@ CParser::TOKEN_TYPE CParser::copy_title(std::string & token, e = begin++; } } + else if (*begin == '\'') + { + begin = ++b; + for (; begin != end && !(*begin == '\''); ++begin); + e = begin; + if (begin != end && *begin == '\'') + { + e = begin++; + } + } else { for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin); From 2b117727777211e3a97c1c16e231ef59b5fec58b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Jun 2011 22:00:46 +0000 Subject: [PATCH 0218/1077] Rewrote run_cells to do all of the calculations that would be done if a series of USE and SAVE. Modified the logic when time step is defined in run_cells. Equivalent to time_step in nmax steps, where nmax is max steps in kinetics, reaction, reaction_temperature. Wrote dump for chart and chart_handler. chart_handler calls dump for all user_graph. Fixed bug in chart_object with log definition. Had wrong logic when looking for t/T/l/L. initial_total_time initialized twice in mainsubs and twice in phreeqc.cpp. Fixed heading logic for mixing graph_x, graph_y, graph_sy with plot_xy. Moved NA to header file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5431 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 11 +++ ChartHandler.h | 2 +- ChartObject.cpp | 180 +++++++++++++++++++++++++++++++++++++++- ChartObject.h | 5 ++ Phreeqc.cpp | 1 - ReadClass.cxx | 209 +++++++++++++++++++++++++++++++++++++++++++++++ runner.cpp | 28 ++++--- runner.h | 3 + 8 files changed, 425 insertions(+), 14 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 88d9362e..36264e90 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -162,5 +162,16 @@ ChartHandler::End_timer(PHREEQC_PTR_ARG) return true; } +bool +ChartHandler::dump(std::ostream & oss, unsigned int indent) +{ + std::map::iterator it = this->chart_map.begin(); + for ( ; it != chart_map.end(); it++) + { + size_t i = 0; + it->second->dump(oss, indent); + } + return true; +} #endif diff --git a/ChartHandler.h b/ChartHandler.h index 40eb295e..14bca879 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -29,7 +29,7 @@ public: bool Read(PHREEQC_PTR_ARG_COMMA CParser &parser); void Punch_user_graph(PHREEQC_PTR_ARG); bool End_timer(PHREEQC_PTR_ARG); - + bool dump(std::ostream & oss, unsigned int indent); protected: std::map chart_map; int current_chart_n_user; diff --git a/ChartObject.cpp b/ChartObject.cpp index d776b15d..5a7a8823 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -205,7 +205,7 @@ ChartObject::Set_axis_scale(CParser & parser) if (string_vector.size() == 6) { std::string s = string_vector[5]; - if (s[0] != 't' || s[0] != 'T' || s[0] != 'l' || s[0] != 'L') + if (s[0] == 't' || s[0] == 'T' || s[0] == 'l' || s[0] == 'L') { scale_ptr[4] = 10.0; if (((fabs(scale_ptr[0] - NA) > 1e-3) && scale_ptr[0] <=0) || @@ -330,7 +330,7 @@ ChartObject::Read(CParser & parser) { this->new_headings.push_back(token); } - + this->headings_original = this->new_headings; break; case 4: /* chart title */ { @@ -407,6 +407,7 @@ ChartObject::Read(CParser & parser) parser.get_rest_of_line(file_name); file_name = trim(file_name); this->OpenCSVFile(file_name); + this->csv_file_names.push_back(file_name); } break; case 13: /* clear */ @@ -423,11 +424,13 @@ ChartObject::Read(CParser & parser) if (!new_command_lines) { this->rate_command_list.clear(); + this->rate_command_list_original.clear(); new_command_lines = true; } this->rate_new_def = true; /* read command */ std::string cmd(parser.line()); + this->rate_command_list_original.push_back(cmd); std::string cmd_lower = cmd; Utilities::str_tolower(cmd_lower); if ((cmd_lower.find("graph_y") != std::string::npos) || @@ -1097,4 +1100,177 @@ ChartObject::Set_rate_new_def(bool tf) } } } +void +ChartObject::dump(std::ostream & oss, unsigned int indent) +{ + size_t i; + oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + oss << indent0 << "USER_GRAPH " << this->n_user << " " << this->description << std::endl; + + // chart title + oss << indent1 << "-chart_title \"" << this->chart_title << "\"" << std::endl; + + // axis titles + if (this->axis_titles.size() > 0) + { + oss << indent1 << "-axis_titles "; + + for (i = 0; i < this->axis_titles.size(); i++) + { + oss << "\"" << axis_titles[i] << "\" "; + } + oss << std::endl; + } + + // axis_scale_x + double *scale_ptr = this->axis_scale_x; + { + oss << indent1 << "-axis_scale x_axis "; + for (i = 0; i < 4; i++) + { + if (scale_ptr[i] == NA) + { + oss << " auto"; + } + else + { + oss << " " << scale_ptr[i]; + } + } + if (scale_ptr[4] == 10.0) + { + oss << " log"; + } + oss << std::endl; + } + // axis_scale_y + scale_ptr = this->axis_scale_y; + { + oss << indent1 << "-axis_scale y_axis "; + for (i = 0; i < 4; i++) + { + if (scale_ptr[i] == NA) + { + oss << " auto"; + } + else + { + oss << " " << scale_ptr[i]; + } + } + if (scale_ptr[4] == 10.0) + { + oss << " log"; + } + oss << std::endl; + } + // axis_scale_sy + scale_ptr = this->axis_scale_y2; + { + oss << indent1 << "-axis_scale sy_axis "; + for (i = 0; i < 4; i++) + { + if (scale_ptr[i] == NA) + { + oss << " auto"; + } + else + { + oss << " " << scale_ptr[i]; + } + } + if (scale_ptr[4] == 10.0) + { + oss << " log"; + } + oss << std::endl; + } + // chart type + if (this->chart_type == 0) + { + oss << indent1 << "-plot_concentration_vs x" << std::endl; + } + else + { + oss << indent1 << "-plot_concentration_vs t" << std::endl; + } + // graph_initial_solutions + if (this->graph_initial_solutions) + { + oss << indent1 << "-initial_solutions true" << std::endl; + } + else + { + oss << indent1 << "-initial_solutions false" << std::endl; + } + // connect_simulations + if (this->connect_simulations) + { + oss << indent1 << "-connect_simulations true" << std::endl; + } + else + { + oss << indent1 << "-connect_simulations false" << std::endl; + } + // csv files + for (i = 0; i < this->csv_file_names.size(); i++) + { + oss << indent1 << "-plot_csv_file " << this->csv_file_names[i] << std::endl; + } + + // headings + if (this->headings_original.size() > 0) + { + oss << indent1 << "-headings "; + for (i = 0; i < this->headings_original.size(); i++) + { + oss << this->headings_original[i] << " "; + } + oss << std::endl; + } + + // commands + oss << indent1 << "-start" << std::endl; + std::list::iterator it = rate_command_list_original.begin(); + for (; it != rate_command_list_original.end(); it++) + { + oss << *it << std::endl; + } + oss << indent1 << "-end" << std::endl; + + /* + struct rate *user_graph; + // C++ for rate struct + std::string rate_name; + std::list rate_command_list; + bool rate_new_def; + + int default_symbol; + int default_symbol_csv; + int default_color; + int default_color_csv; + + // temporary storage before stored graph_x/y/sy data are stored in curves + // Initialize_graph_pts and Finalize_graph_pts use this storage. + double graph_x; + std::map graph_y; + std::map secondary_y; + + // temporary plotxy curve definitions before stored in curves + // a plotxy curve is copied to Curves when cmdplotxy is encountered + // this keeps order correct between plotxy and graph_x/y/sy + std::vector new_plotxy_curves; + + // temporary headings until stored during basic_run + std::vector new_headings; + bool active; + bool detach; + bool form_started; + */ +} #endif // MULTICHART \ No newline at end of file diff --git a/ChartObject.h b/ChartObject.h index c890b759..99d64554 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -309,6 +309,7 @@ class ChartObject:public cxxNumKeyword double symbol_size = 6.0, int y_axis = 1, std::string color = ""); + void dump(std::ostream & s_oss, unsigned int indent); protected: bool new_ug; @@ -341,6 +342,7 @@ class ChartObject:public cxxNumKeyword bool end_timer; bool done; + std::vector csv_file_names; std::vector CurvesCSV; std::vector Curves; bool curve_added; @@ -350,6 +352,7 @@ class ChartObject:public cxxNumKeyword // C++ for rate struct std::string rate_name; std::list rate_command_list; + std::list rate_command_list_original; bool rate_new_def; int default_symbol; @@ -370,6 +373,7 @@ class ChartObject:public cxxNumKeyword // temporary headings until stored during basic_run std::vector new_headings; + std::vector headings_original; bool active; bool detach; bool form_started; @@ -377,6 +381,7 @@ class ChartObject:public cxxNumKeyword class Phreeqc * p_instance1; #endif + public: int usingResource; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6f592cd9..7ae6e2c5 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -875,7 +875,6 @@ void Phreeqc::init(void) rate_sim_time_end = 0; rate_sim_time = 0; rate_moles = 0; - initial_total_time = 0; /* * user_print, user_punch diff --git a/ReadClass.cxx b/ReadClass.cxx index 7a89eab0..8a70cde2 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -2383,6 +2383,7 @@ run_as_cells(void) return (OK); } #endif +#ifdef SKIP2 /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER run_as_cells(void) @@ -2456,7 +2457,215 @@ run_as_cells(void) /* last_model.force_prep = TRUE; */ return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int CLASS_QUALIFIER +run_as_cells(void) +/* ---------------------------------------------------------------------- */ +{ + struct save save_data; + LDBLE kin_time; + int count_steps, use_mix, m; + char token[2 * MAX_LENGTH]; + struct kinetics *kinetics_ptr; + state = REACTION; + if (run_info.Get_cells().Get_numbers().size() == 0 || + !(run_info.Get_cells().Get_defined())) return(OK); + + // running cells + run_info.Set_run_cells(true); + + dup_print("Beginning of run as cells.", TRUE); + double initial_total_time_save; + if (run_info.Get_start_time() != NA) + { + initial_total_time_save = run_info.Get_start_time(); + } + else + { + initial_total_time_save = initial_total_time; + } + + std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); + + for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) + { + int i = *it; + if (i < 0) continue; + initial_total_time = initial_total_time_save; + set_advection(i, TRUE, TRUE, i); +/* + * Run reaction step + */ + /* + * Find maximum number of steps + */ + dup_print("Beginning of batch-reaction calculations.", TRUE); + count_steps = 1; + if (use.irrev_in == TRUE && use.irrev_ptr != NULL) + { + if (abs(use.irrev_ptr->count_steps) > count_steps) + count_steps = abs(use.irrev_ptr->count_steps); + } + if (use.kinetics_in == TRUE && use.kinetics_ptr != NULL) + { + if (abs(use.kinetics_ptr->count_steps) > count_steps) + count_steps = abs(use.kinetics_ptr->count_steps); + } + if (use.temperature_in == TRUE && use.temperature_ptr != NULL) + { + if (abs(use.temperature_ptr->count_t) > count_steps) + count_steps = abs(use.temperature_ptr->count_t); + } + count_total_steps = count_steps; + /* + * save data for saving solutions + */ + memcpy(&save_data, &save, sizeof(struct save)); + /* + *Copy everything to -2 + */ + copy_use(-2); + rate_sim_time_start = 0; + rate_sim_time = 0; + for (reaction_step = 1; reaction_step <= count_steps; reaction_step++) + { + sprintf(token, "Reaction step %d.", reaction_step); + if (reaction_step > 1 && incremental_reactions == FALSE) + { + copy_use(-2); + } + set_initial_moles(-2); + dup_print(token, FALSE); + /* + * Determine time step for kinetics + */ + kin_time = 0.0; + if (use.kinetics_in == TRUE) + { + // runner kin_time + // equivalent to kin_time in count_steps + if (run_info.Get_time_step() != NA) + { + if (incremental_reactions == FALSE) + { + /* not incremental reactions */ + kin_time = reaction_step * run_info.Get_time_step() / ((LDBLE) count_steps); + } + else + { + /* incremental reactions */ + kin_time = run_info.Get_time_step() / ((LDBLE) count_steps); + } + } + // runner kin_time not defined + else + { + kinetics_ptr = kinetics_bsearch(-2, &m); + if (incremental_reactions == FALSE) + { + if (kinetics_ptr->count_steps > 0) + { + if (reaction_step > kinetics_ptr->count_steps) + { + kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } + else + { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + kin_time = kinetics_ptr->steps[0]; + } + else + { + kin_time = reaction_step * kinetics_ptr->steps[0] / ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + else + { + /* incremental reactions */ + if (kinetics_ptr->count_steps > 0) + { + if (reaction_step > kinetics_ptr->count_steps) + { + kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } + else + { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + kin_time = 0; + } + else + { + kin_time = + kinetics_ptr->steps[0] / ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + } + } + if (incremental_reactions == FALSE || + (incremental_reactions == TRUE && reaction_step == 1)) + { + use_mix = TRUE; + } + else + { + use_mix = FALSE; + } + /* + * Run reaction step + */ + run_reactions(-2, kin_time, use_mix, 1.0); + if (incremental_reactions == TRUE) + { + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start; + } + else + { + rate_sim_time = kin_time; + } + if (state != ADVECTION) + { + punch_all(); + print_all(); + } + /* saves back into -2 */ + if (reaction_step < count_steps) + { + saver(); + } + } + /* + * save end of reaction + */ + memcpy(&save, &save_data, sizeof(struct save)); + if (use.kinetics_in == TRUE) + { + kinetics_duplicate(-2, use.n_kinetics_user); + } + saver(); + } + initial_total_time += rate_sim_time; + run_info.Get_cells().Set_defined(false); + // not running cells + run_info.Set_run_cells(false); + return (OK); +} /* ---------------------------------------------------------------------- */ void CLASS_QUALIFIER dump_ostream(std::ostream& os) diff --git a/runner.cpp b/runner.cpp index 1a8952bf..622e7063 100644 --- a/runner.cpp +++ b/runner.cpp @@ -1,14 +1,18 @@ #include "runner.h" #include "Parser.h" +#include "NA.h" runner::runner(void) { - this->time_step = 0; - this->start_time = 0; + this->time_step = NA; + this->start_time = NA; + this->run_cells = false; + } runner::runner(CParser & parser) { - this->time_step = 0; - this->start_time = 0; + this->time_step = NA; + this->start_time = NA; + this->run_cells = false; this->Read(parser); } @@ -27,6 +31,9 @@ bool runner::Read(CParser & parser) vopts.push_back("cells"); vopts.push_back("start_time"); vopts.push_back("time_step"); + vopts.push_back("time_steps"); + vopts.push_back("step"); + vopts.push_back("steps"); } std::istream::pos_type ptr; @@ -52,13 +59,11 @@ bool runner::Read(CParser & parser) opt_save = opt; } + //// Read dump entity list of numbers or number ranges for line, store in item + //if (opt >= 0 && opt <= 1) + //{ - - // Read dump entity list of numbers or number ranges for line, store in item - if (opt >= 0 && opt <= 1) - { - - } + //} // Process other identifiers std::set < int >::iterator it; @@ -99,6 +104,9 @@ bool runner::Read(CParser & parser) } break; case 3: //time_step + case 4: //time_steps + case 5: //step + case 6: //steps if (!(parser.get_iss() >> this->time_step)) { parser.error_msg("Expected time_step for RUN_CELLS.", diff --git a/runner.h b/runner.h index 11073164..033f659c 100644 --- a/runner.h +++ b/runner.h @@ -16,10 +16,13 @@ public: StorageBinListItem & Get_cells(void) { return(this->cells); }; double Get_time_step() { return(this->time_step); }; double Get_start_time() { return(this->start_time); }; + bool Get_run_cells() { return(this->run_cells); }; + void Set_run_cells(bool tf) { this->run_cells = tf; }; protected: double time_step; double start_time; StorageBinListItem cells; + bool run_cells; }; #endif // !defined(RUNNER_H_INCLUDED) From 67258ef6efae801a6d10c16594a2fa47db935d23 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Jun 2011 20:34:36 +0000 Subject: [PATCH 0219/1077] reading with parser differed from reading from stream, and did not handle missing id number correctly (NumKeyword.cxx) Revised ex5 and ex7 user_graph. Through example 7 in examples.fm. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5448 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.cxx | 57 +++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/NumKeyword.cxx b/NumKeyword.cxx index dedee506..94411661 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -49,6 +49,7 @@ cxxNumKeyword::read_number_description(CParser & parser) // skip keyword parser.copy_token(keyword, ptr); + /* std::istream::pos_type ptr1 = ptr; std::string::size_type pos; std::string token; @@ -72,37 +73,31 @@ cxxNumKeyword::read_number_description(CParser & parser) // ptr1 = ptr; } } - /* - else if ( (pos = token.find_first_of("-")) != std::string::npos ) - { - token.replace(pos, 1, " "); - std::istringstream iss(token); - if (!(iss >> this->n_user >> this->n_user_end)) - { - std::ostringstream err_oss; - if (parser.next_keyword() >= 0) - { - err_oss << "Reading number range for " << keyword << "."; - } - else - { - err_oss << "Reading number range for keyword."; - } - parser.error_msg(err_oss, CParser::OT_CONTINUE); - parser.incr_input_error(); - } - ptr1 = ptr; - } - else - { - std::istringstream iss(token); - iss >> this->n_user; - this->n_user_end = this->n_user; - ptr1 = ptr; - } - */ - // reset get position - //parser.get_iss().seekg(ptr1); + */ + + // skip whitespace + while (::isspace(parser.get_iss().peek())) + parser.get_iss().ignore(); + + // read number + if (::isdigit(parser.get_iss().peek())) + { + parser.get_iss() >> this->n_user; + char ch = parser.get_iss().peek(); + if (ch == '-') + { + parser.get_iss() >> ch; // eat '-' + parser.get_iss() >> this->n_user_end; + } + else + { + this->n_user_end = this->n_user; + } + } + else + { + this->n_user = this->n_user_end = 1; + } // skip whitespace while (::isspace(parser.get_iss().peek())) From a36a7924cdf5080bdaa4b4bb69cb7780b37f1e52 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Jun 2011 22:35:43 +0000 Subject: [PATCH 0220/1077] Worked on bug with DUMP and read_raw of isotopes. Also checked that dump/read/dump gave equivalent files for isotopes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5453 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 2 +- SolutionIsotope.cxx | 19 ++++++++++++++----- SolutionIsotope.h | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 33cdc1c6..7e5d08e2 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -684,7 +684,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 3: // isotopes { cxxSolutionIsotope iso; - if (iso.read_raw(parser) != CParser::PARSER_OK) + if (iso.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); parser.error_msg("Expected data for isotopes.", diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index d6eb64c1..27f90a7a 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -18,13 +18,22 @@ cxxSolutionIsotope::cxxSolutionIsotope(void): isotope_number(0.0) { + isotope_number = 0; + elt_name.clear(); + isotope_name.clear(); + total = 0; + ratio = -9999.9; + ratio_uncertainty = 1; + ratio_uncertainty_defined = false; } cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) { isotope_number = isotope_ptr->isotope_number; this->set_elt_name(isotope_ptr->elt_name); - this->set_isotope_name(isotope_ptr->isotope_name); + std::ostringstream name; + name << isotope_ptr->isotope_number << isotope_ptr->elt_name; + this->set_isotope_name(name.str().c_str()); total = isotope_ptr->total; ratio = isotope_ptr->ratio; ratio_uncertainty = isotope_ptr->ratio_uncertainty; @@ -141,10 +150,9 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << std::endl; } -CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) +CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream::pos_type next_char ) { std::string token; - std::istream::pos_type next_char; CParser::TOKEN_TYPE j; // isotope_name @@ -183,7 +191,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) } // ratio_uncertainty - j = parser.copy_token(token, next_char); + j = parser.peek_token(); if (j == CParser::TT_EMPTY) { this->ratio_uncertainty = NAN; @@ -197,7 +205,8 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser) } else { - std::istringstream(token) >> this->ratio_uncertainty; + parser.get_iss() >> this->ratio_uncertainty; + this->ratio_uncertainty_defined = true; } return CParser::PARSER_OK; diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 5a11e8de..a5c6cbab 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -26,7 +26,7 @@ class cxxSolutionIsotope void dump_xml(std::ostream & os, unsigned int indent) const; void dump_raw(std::ostream & os, unsigned int indent) const; - CParser::STATUS_TYPE read_raw(CParser & parser); + CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type next_char); double get_isotope_number() const { From 2c906a0653f2bac146e7f57b282b045bed6c932a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 24 Jun 2011 16:05:30 +0000 Subject: [PATCH 0221/1077] Fixed missing reaction_modify in Class version Added solid_solution_modify synonym. Added dialog for saving curve data. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5455 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 5 ++++- Phreeqc.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7ae6e2c5..13e0e8a8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -161,7 +161,10 @@ Phreeqc::Phreeqc(void) {"gas_phase_modify", 0}, {"kinetics_modify", 0}, {"delete", 0}, - {"run_cells", 0} + {"run_cells", 0}, + {"reaction_modify"}, + {"reaction_temperature_modify"}, + {"solid_solution_modify", 0} #endif }; NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ diff --git a/Phreeqc.h b/Phreeqc.h index 135ca399..0b0db1ad 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -879,7 +879,7 @@ int next_keyword_or_option(const char **opt_list, int count_opt_list); int read_gas_phase_modify(void); int read_kinetics_modify(void); int read_reaction_modify(void); - int read_reaction_temperature_modify(void); + //int read_reaction_temperature_modify(void); int read_delete(void); int read_run_cells(void); int streamify_to_next_keyword(std::istringstream & lines); From 646207fac8814b677f5872f6b4edada642f484e6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 Jul 2011 23:32:47 +0000 Subject: [PATCH 0222/1077] Added phase_formula function. Fixed some of the initializations for keywords, was missing the initial count. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5466 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 10 ++++++---- Phreeqc.h | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 13e0e8a8..2a5677d6 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -139,7 +139,7 @@ Phreeqc::Phreeqc(void) {"copy", 0}, {"pitzer", 0}, {"sit", 0}, - {"equilibrium_phase"} + {"equilibrium_phase", 0} #ifdef PHREEQC_CPP , {"solution_raw", 0}, @@ -162,8 +162,8 @@ Phreeqc::Phreeqc(void) {"kinetics_modify", 0}, {"delete", 0}, {"run_cells", 0}, - {"reaction_modify"}, - {"reaction_temperature_modify"}, + {"reaction_modify", 0}, + {"reaction_temperature_modify", 0}, {"solid_solution_modify", 0} #endif }; @@ -334,7 +334,9 @@ Phreeqc::Phreeqc(void) {"totmol", toktotmol}, {"totmoles", toktotmoles}, {"iso", tokiso}, - {"iso_unit", tokiso_unit} }; + {"iso_unit", tokiso_unit}, + {"phase_formula", tokphase_formula} + }; NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); command = new const_key[NCMDS]; for (i = 0; i < NCMDS; i++) diff --git a/Phreeqc.h b/Phreeqc.h index 0b0db1ad..2201c72f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -29,6 +29,7 @@ #include "dumper.h" #include "StorageBinList.h" #include "ChartHandler.h" +class cxxNameDouble; #define STATIC #define EXTERNAL #define CLASS_QUALIFIER Phreeqc:: @@ -246,6 +247,7 @@ LDBLE surf_total(const char *total_name, const char *surface_name); CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); +std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); int system_total_elements(void); int system_total_si(void); int system_total_aq(void); From 2da02dd00066b2ce1908365dadb2c6d1dcdb64c4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Jul 2011 19:52:07 +0000 Subject: [PATCH 0223/1077] Updated revisions for revisions and PHREEQCPP-RELEASE.txt Added list_s_s function to Basic. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5472 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHREEQCPP-RELEASE.txt | 119 ++++++++++++++++++++++++++++-------------- Phreeqc.cpp | 3 +- 2 files changed, 82 insertions(+), 40 deletions(-) diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt index 3d9d4a2d..095884fb 100644 --- a/PHREEQCPP-RELEASE.txt +++ b/PHREEQCPP-RELEASE.txt @@ -1,15 +1,85 @@ -File contains: - "Features in PHREEQC++ Not in PHREEQC" - "Revisions and Bug Fixes" - ************************************************************ ************************************************************ * Features in PHREEQC++ Not in PHREEQC * +* Revisions and Bug Fixes * +* PHREEQC++ is used only in IPhreeqc Modules * ************************************************************ ------------------------------------------------------------ Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------ + -------- + svn 5455 + -------- + REACTION_MODIFY keyword was added to the modules. Previously, + REACTION_MODIFY was not recognized as a keyword. + + -------- + svn 5453 + -------- + Fixed bug with in READ_SOLUTION_RAW. A read error occurred + when -isotopes was encountered. + + -------- + svn 5448 + -------- + Reading of default user number, but specified description + was in error under some conditions. + + -------- + svn 5431 + -------- + RUN_CELLS was rewritten to perform multiple calculations + if multiple steps are defined in REACTION, REACTION_TEMPERATURE, + or KINETICS. It now operates in the same way that a + series of USE and SAVES would operate. Previously, only + one step of a series of reaction steps was taken. If a + time step is provided in RUN_CELLS for kinetic reactions and + nmax is the maximum number of steps defined for REACTION, + REACTION_TEMPERATURE, and KINETICS, the time step is divided + into nmax equal increments. It is equivalent to the following + definition in kinetics: -step time_step in nmax steps. + + -------- + svn 5324 + -------- + Modified solution method for solid solutions so that + mole transfers were limited to the total amount + available in the system. + +------------------------------------------------------------ +Version 2.18.0: April 9, 2011 +------------------------------------------------------------ + -------- + svn 5281 + -------- + If SOLUTION_MODIFY is used to change a total for an element, + the activities for the master species of the element are + automatically updated by the ratio of the new total to the + old total, unless activities are specifically set for the + element with -activities. All valence states of redox elements + are adjusted. + + -------- + svn 5270 + -------- + Added logic to update estimates of log activity when + modifying totals in SOLUTION_MODIFY. The initial + guesses for activities are adjusted proportionally + to the change in total moles of elements (as defined + by SOLUTION_MODIFY; -totals). + + This automatic adjustment is suggested rather than + explicit definition of the initial guesses through + SOLUTION_MODIFY; -activities. However, the -activities + identifier may be used and will supercede the automatic + adjustment. + + The adjustment of the initial guesses for activities + should reduce the number of iterations needed to solve + a given set of equations and, consequently, should + lessen the total CPU time for a simulation. + -------- svn 4897 -------- @@ -38,6 +108,12 @@ Version @PHREEQC_VER@: @PHREEQC_DATE@ Calcite 0 10 END + -------- + svn 4856 + -------- + Revised logic of searching pitzer parameters so that + order of ions in a parameter definition does not + matter. -------- svn 4823 @@ -613,40 +689,5 @@ KINETICS_MODIFY 1 -steps - -************************************************************ -************************************************************ -* Revisions and Bug Fixes * -************************************************************ -************************************************************ ------------------------------------------------------------- -Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------- - -------- - svn 5270 - -------- - Added logic to update estimates of log activity when - modifying totals in SOLUTION_MODIFY. The initial - guesses for activities are adjusted proportionally - to the change in total moles of elements (as defined - by SOLUTION_MODIFY; -totals). - - This automatic adjustment is suggested rather than - explicit definition of the initial guesses through - SOLUTION_MODIFY; -activities. However, the -activities - identifier may be used and will supercede the automatic - adjustment. - - The adjustment of the initial guesses for activities - should reduce the number of iterations needed to solve - a given set of equations and, consequently, should - lessen the total CPU time for a simulation. - - -------- - svn 4856 - -------- - Revised logic of searching pitzer parameters so that - order of ions in a parameter definition does not - matter. diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 2a5677d6..c743cb43 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -335,7 +335,8 @@ Phreeqc::Phreeqc(void) {"totmoles", toktotmoles}, {"iso", tokiso}, {"iso_unit", tokiso_unit}, - {"phase_formula", tokphase_formula} + {"phase_formula", tokphase_formula}, + {"list_s_s", toklist_s_s} }; NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); command = new const_key[NCMDS]; From 865cdad9bb1ea440129969573d29a6eccb1773a8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Jul 2011 21:40:28 +0000 Subject: [PATCH 0224/1077] missed list_s_s prototype for class git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5473 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 2201c72f..f93b97a3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -248,6 +248,7 @@ CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); +LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); int system_total_elements(void); int system_total_si(void); int system_total_aq(void); From 4e02d925b8623013d4eb642966a02aff68cabbc4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Jul 2011 21:54:34 +0000 Subject: [PATCH 0225/1077] Guarded ChartHandler.h in Phreeqc.h. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5474 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index f93b97a3..7db8718e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -28,7 +28,9 @@ #include "runner.h" #include "dumper.h" #include "StorageBinList.h" +#ifdef MULTICHART #include "ChartHandler.h" +#endif class cxxNameDouble; #define STATIC #define EXTERNAL From cd41ca95669c148bf3f39635c701c9b32cbb6c42 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Jul 2011 23:28:36 +0000 Subject: [PATCH 0226/1077] Removed some header files from phreeqc.h. Moved one header to kinetics.c git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5475 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 64 +------------------------------------------------------ 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 7db8718e..5bc8df3b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -18,16 +18,9 @@ #include #include #include "phrqtype.h" -#include "sundialstypes.h" -#include "nvector.h" #include "cvdense.h" -#include "nvector_serial.h" /* definitions of type N_Vector and macro */ - /* NV_Ith_S, prototypes for N_VNew, N_VFree */ -#include "dense.h" /* definitions of type DenseMat, macro DENSE_ELEM */ -#include "nvector.h" #include "runner.h" #include "dumper.h" -#include "StorageBinList.h" #ifdef MULTICHART #include "ChartHandler.h" #endif @@ -47,65 +40,10 @@ public: Phreeqc(void); ~Phreeqc(void); -//private: -// -//struct _generic_N_Vector; -//struct calculate_value; -//struct conc; -//struct CVodeMemRec; -//struct element; -//struct exchange; -//struct exch_comp; -//struct elt_list; -//struct gas_phase; -//struct gas_comp; -//struct inverse; -//struct inv_elts; -//struct inv_phases; -//struct inv_isotope; -//struct irrev; -//struct isotope; -//struct kinetics; -//struct kinetics_comp; -//struct LOC_exec; -//struct master; -//struct master_activity; -//struct master_isotope; -//struct mix; -//struct mix_comp; -//struct name_coef; -//struct pe_data; -//struct phase; -//struct PHRQMemHeader; -//struct pitz_param; -//struct pp_assemblage; -//struct pure_phase; -//struct reaction; -//struct reaction_temp; -//struct rxn_token; -//struct rxn_token_temp; -//struct solution; -//struct species; -//struct s_s; -//struct s_s_assemblage; -//struct s_s_comp; -//struct species_diff_layer; -//struct surface; -//struct surface_comp; -//struct surface_charge; -//struct surface_diff_layer; -//struct theta_param; -//struct tokenrec; -//struct varrec; -//struct unknown; -//struct Curves_c; - #define PITZER_EXTERNAL #include "pitzer.h" #include "input.h" -#define KINETICS_EXTERNAL -#include "sundialstypes.h" /* definitions of types realtype and */ - /* integertype, and the constant FALSE */ + public: #include "output.h" public: From c9b1781f3723d1475a88b026b4ba7f0d4df9aa1a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 13 Jul 2011 19:11:43 +0000 Subject: [PATCH 0227/1077] new sit.dat database. unix versions. Makefile is not really right for all configurations. Need to build from scratch to make sure. Moved new Basic functions to phreeqcpp; don't work in phreeqc (non PHREEQC_CPP). git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5482 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 458 ++++++++++++++++++++++-------------------- PHREEQCPP-RELEASE.txt | 53 +++++ 2 files changed, 288 insertions(+), 223 deletions(-) diff --git a/Makefile b/Makefile index 24826648..0c95cf0e 100644 --- a/Makefile +++ b/Makefile @@ -252,301 +252,313 @@ ${PROGRAM} : ${OBJECT_FILES} # CXX files # cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../cxxKinetics.h \ - ../NumKeyword.h ../KineticsComp.h ../NameDouble.h ../Phreeqc_class.h \ - ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxKinetics.h ../NumKeyword.h ../KineticsComp.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../cxxMix.h ../NumKeyword.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../cxxMix.h ../NumKeyword.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h Dictionary.o: ../Dictionary.cxx ../Dictionary.h ../Solution.h \ - ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h + ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h Exchange.o: ../Exchange.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../cxxMix.h \ - ../Phreeqc_class.h ../NumKeyword.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Phreeqc_class.h ../NumKeyword.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ExchComp.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../ExchComp.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../GasPhase.h \ - ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h \ + ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ISolutionComp.h \ - ../Phreeqc_class.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../ISolutionComp.h ../Phreeqc_class.h ../phreeqc/phrqproto.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ISolution.o: ../ISolution.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../ISolution.h \ - ../ISolutionComp.h ../Phreeqc_class.h ../NumKeyword.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../ISolution.h ../ISolutionComp.h ../Phreeqc_class.h ../NumKeyword.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../KineticsComp.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../KineticsComp.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ - ../Phreeqc_class.h + ../Phreeqc_class.h Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/output.h + ../phreeqc/output.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../PPassemblageComp.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ + ../Parser.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h ../phreeqc/output.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../PPassemblage.h \ - ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../PPassemblage.h ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h Reaction.o: ../Reaction.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../Reaction.h \ - ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h \ + ../Parser.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ReadClass.o: ../ReadClass.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../Phreeqc_class.h ../Parser.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ - ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ - ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ - ../Temperature.h ../dumper.h ../StorageBinList.h ../runner.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h -SAXPhreeqc.o: ../SAXPhreeqc.cxx ../SAXPhreeqc.h ../SaxPhreeqcHandlers.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phrqproto.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc_class.h \ + ../Parser.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ + ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ + ../Temperature.h ../dumper.h ../StorageBinList.h ../runner.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h Solution.o: ../Solution.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../Solution.h \ - ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Solution.h ../Phreeqc_class.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ + ../NameDouble.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SSassemblage.h \ - ../Phreeqc_class.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ - ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SSassemblage.h ../Phreeqc_class.h ../NumKeyword.h ../NameDouble.h \ + ../Parser.h ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h \ + ../phreeqc/phrqproto.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../SSassemblageSS.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/output.h ../SSassemblageSS.h ../NameDouble.h \ + ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../StorageBin.h ../System.h \ - ../SSassemblage.h ../NumKeyword.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h \ - ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h \ - ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../StorageBin.h \ + ../System.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ + ../Temperature.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SurfaceCharge.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SurfaceCharge.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../SurfaceComp.h \ - ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../Dictionary.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ + ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../Surface.h ../NumKeyword.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../Surface.h ../NumKeyword.h ../SurfaceComp.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h System.o: ../System.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../System.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../SSassemblage.h ../NumKeyword.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../cxxKinetics.h \ - ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../cxxMix.h ../Reaction.h ../Temperature.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../System.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../SSassemblage.h \ + ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../cxxMix.h ../Reaction.h ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h \ - ../Phreeqc_class.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../Temperature.h ../NumKeyword.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h + ../Phreeqc_class.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Temperature.h \ + ../NumKeyword.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/output.h + ../phreeqc/output.h +ChartHandler.o: ../ChartHandler.cpp +ChartObject.o: ../ChartObject.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../phreeqc/nvector_serial.h ../phreeqc/dense.h ../phreeqc/p2c.h \ - ../phreeqc/global_structures.h ../phreeqc/pitzer_structures.h \ - ../phreeqc/pitzer.h ../phreeqc/input.h ../phreeqc/output.h \ - ../phreeqc/global.h ../phreeqc/global_structures.h \ - ../phreeqc/phrqproto.h + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h ../phreeqc/input.h \ + ../phreeqc/output.h ../phreeqc/global.h ../phreeqc/global_structures.h \ + ../phreeqc/phrqproto.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h \ + ../cxxKinetics.h ../KineticsComp.h +CurveObject.o: ../CurveObject.cpp ../CurveObject.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h + ../Phreeqc_class.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../phreeqc/nvector_serial.h ../phreeqc/dense.h ../phreeqc/p2c.h \ - ../phreeqc/global_structures.h ../phreeqc/pitzer_structures.h \ - ../phreeqc/pitzer.h ../phreeqc/input.h ../phreeqc/output.h \ - ../phreeqc/global.h ../phreeqc/global_structures.h + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h ../phreeqc/input.h \ + ../phreeqc/output.h ../phreeqc/global.h ../phreeqc/global_structures.h \ + ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ + ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h + ../Phreeqc_class.h ../phreeqc/NA.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h -# -# PHREEQC files -# + ../Phreeqc_class.h advection.o: ../phreeqc/advection.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h basic.o: ../phreeqc/basic.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/p2c.h \ - ../phreeqc/basic.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/p2c.h \ + ../phreeqc/../NameDouble.h ../phreeqc/../Phreeqc_class.h \ + ../phreeqc/../Parser.h ../phreeqc/basic.h basicsubs.o: ../phreeqc/basicsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/../NameDouble.h ../phreeqc/../Phreeqc_class.h \ + ../phreeqc/../Parser.h cl1.o: ../phreeqc/cl1.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqtype.h + ../phreeqc/phrqtype.h cl1mp.o: ../phreeqc/cl1mp.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqtype.h + ../phreeqc/phrqtype.h cvdense.o: ../phreeqc/cvdense.c ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ - ../phreeqc/output.h ../phreeqc/phqalloc.h + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ + ../phreeqc/output.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.c ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/sundialsmath.h \ - ../phreeqc/output.h ../phreeqc/kinetics.h ../phreeqc/phqalloc.h + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/sundialsmath.h \ + ../phreeqc/output.h ../phreeqc/kinetics.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.c ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../phreeqc/output.h ../phreeqc/phqalloc.h + ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../phreeqc/output.h ../phreeqc/phqalloc.h dw.o: ../phreeqc/dw.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phrqproto.h \ + ../phreeqc/output.h ../phreeqc/pitzer.h input.o: ../phreeqc/input.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/input.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/input.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h inverse.o: ../phreeqc/inverse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h isotopes.o: ../phreeqc/isotopes.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h kinetics.o: ../phreeqc/kinetics.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/sundialstypes.h ../phreeqc/cvode.h ../phreeqc/nvector.h \ - ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../phreeqc/nvector_serial.h ../phreeqc/kinetics.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/sundialstypes.h ../phreeqc/cvode.h ../phreeqc/nvector.h \ + ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../phreeqc/nvector_serial.h ../phreeqc/kinetics.h main.o: ../phreeqc/main.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/input.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/input.h mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/input.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/input.h model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ - ../phreeqc/nvector.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h + ../phreeqc/nvector.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h output.o: ../phreeqc/output.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/output.h \ + ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h p2clib.o: ../phreeqc/p2clib.c ../phreeqc/p2c.h ../phreeqc/output.h parse.o: ../phreeqc/parse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h phqalloc.o: ../phreeqc/phqalloc.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/output.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/output.h phreeqc_files.o: ../phreeqc/phreeqc_files.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/input.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/input.h pitzer.o: ../phreeqc/pitzer.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h pitzer_structures.o: ../phreeqc/pitzer_structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h prep.o: ../phreeqc/prep.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h print.o: ../phreeqc/print.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/pitzer.h read.o: ../phreeqc/read.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h readtr.o: ../phreeqc/readtr.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h sit.o: ../phreeqc/sit.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h \ + ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h smalldense.o: ../phreeqc/smalldense.c ../phreeqc/smalldense.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h spread.o: ../phreeqc/spread.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h step.o: ../phreeqc/step.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h structures.o: ../phreeqc/structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h sundialsmath.o: ../phreeqc/sundialsmath.c ../phreeqc/sundialsmath.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h tally.o: ../phreeqc/tally.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h tidy.o: ../phreeqc/tidy.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ + ../phreeqc/output.h ../phreeqc/phrqproto.h transport.o: ../phreeqc/transport.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h + # ----------------------------------------------------------------------------- clean: diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt index 095884fb..388c0164 100644 --- a/PHREEQCPP-RELEASE.txt +++ b/PHREEQCPP-RELEASE.txt @@ -7,6 +7,59 @@ ------------------------------------------------------------ Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------ + -------- + svn 5471 + -------- + Added PHASE_FORMULA and LIST_S_S Basic functions. + + PHASE_FORMULA returns a string value with the + chemical formula for the phase as defined in + PHASES data. If 4 arguments are provide, a list + of the elements and stoichiometric coefficients for + elements are returned. + + USER_PRINT + 10 min$ = "Calcite" + 20 form$ = PHASE_FORMULA(min$) + 30 print min$, form$ + 40 form$ = PHASE_FORMULA(min$, count, elts$, coefs) + 50 for i = 1 to count + 60 print " ", PAD(elts$[i], 20), coefs[i] + 70 next i + + This example produces the following output: + +Calcite CaCO3 + C 1 + Ca 1 + O 3 + + LIST_S_S returns the sum of moles of all components + in a specified solid solution. Lists of the components + and the number of moles of each component are also + returned. + + + SOLID_SOLUTIONS 1 + Calcite_s_s + -comp Calcite 0.01 + -comp Smithsonite 0.001 + -comp Strontianite 0.02 + USER_PRINT + 10 name$ = "Calcite_s_s" + 20 total = LIST_S_S(name$, count, comp$, moles) + 30 print PAD(name$, 20), total + 40 for i = 1 to count + 50 print " ", PAD(comp$[i], 20), moles[i], moles[i]/total + 60 next i + + This example produces the following output: + +Calcite_s_s 3.0876e-002 + Calcite 9.9316e-003 3.2166e-001 + Smithsonite 9.6666e-004 3.1308e-002 + Strontianite 1.9978e-002 6.4704e-001 + -------- svn 5455 -------- From 68b9c041de29e934ab22d9ca702c40c458c862cc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Jul 2011 18:12:24 +0000 Subject: [PATCH 0228/1077] Sorted results for list_s_s git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5513 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 14 ++++++++++++++ NameDouble.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/NameDouble.cxx b/NameDouble.cxx index d356891c..076c2ff2 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -551,6 +551,20 @@ cxxNameDouble::merge_redox(const cxxNameDouble & source) } } +struct DblCmp { + bool operator()(const std::pair &lhs, std::pair &rhs) + { + return lhs.second > rhs.second; + } +}; +std::vector> +cxxNameDouble::sort_second(void) +{ + std::vector> myvec(this->begin(), this->end()); + std::sort(myvec.begin(), myvec.end(), DblCmp()); + + return myvec; +} #ifdef USE_MPI void cxxNameDouble::mpi_pack(std::vector < int >&ints, diff --git a/NameDouble.h b/NameDouble.h index e94c533e..d22cac87 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -69,6 +69,9 @@ class cxxNameDouble:public void merge_redox(const cxxNameDouble & source); + std::vector> + sort_second(void); + void insert(char *str, double d) { From c43921fadf5fb3aa3b9b5eee95e3995157217ae9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 22 Jul 2011 04:40:59 +0000 Subject: [PATCH 0229/1077] fixed compile error in g++ 4.4.3 git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5526 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NameDouble.h b/NameDouble.h index d22cac87..f8701122 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -69,7 +69,7 @@ class cxxNameDouble:public void merge_redox(const cxxNameDouble & source); - std::vector> + std::vector< std::pair > sort_second(void); void From 7d523c89d5872d8ac1c9da01a4384b126ae68d70 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 22 Jul 2011 04:51:44 +0000 Subject: [PATCH 0230/1077] fixed compile error in g++ 4.4.3 git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5527 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 076c2ff2..5c3ecc43 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -557,10 +557,10 @@ struct DblCmp { return lhs.second > rhs.second; } }; -std::vector> +std::vector< std::pair > cxxNameDouble::sort_second(void) { - std::vector> myvec(this->begin(), this->end()); + std::vector< std::pair > myvec(this->begin(), this->end()); std::sort(myvec.begin(), myvec.end(), DblCmp()); return myvec; From 3d989d5f44c7d76066954d58b13c35dae7db8e18 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 22 Jul 2011 05:06:04 +0000 Subject: [PATCH 0231/1077] fixed compile error in g++ 4.4.3 git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5528 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 5c3ecc43..878fbac6 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -552,7 +552,7 @@ cxxNameDouble::merge_redox(const cxxNameDouble & source) } } struct DblCmp { - bool operator()(const std::pair &lhs, std::pair &rhs) + bool operator()(const std::pair &lhs, const std::pair &rhs) { return lhs.second > rhs.second; } From dc45fa365e51eee570d1ca603fa96f44b2a8ca5b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 2 Aug 2011 18:27:56 +0000 Subject: [PATCH 0232/1077] Tony changed csv symbols. Got a complete pdf with no errors Ready for review? git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5548 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 5a7a8823..ee4102c3 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -1066,7 +1066,6 @@ ChartObject::Add_curve(bool plotxy, std::string id, double symbol_size, int y_axis, std::string color) - { CurveObject *c = new CurveObject; c->Set_id(id); @@ -1074,7 +1073,7 @@ ChartObject::Add_curve(bool plotxy, std::string id, this->Get_legal_symbol(symbol); c->Set_symbol(symbol); c->Set_symbol_size(symbol_size); - if (this->CurvesCSV.size() > 0 && !plotxy) + if (this->CurvesCSV.size() > this->Curves.size() && !plotxy) { c->Set_symbol_size(0.0); } From ae170dc366d62413f892615b818fad1cdb660943 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 8 Aug 2011 16:09:57 +0000 Subject: [PATCH 0233/1077] Removing CHART compile option, replaced by MULTICHART. Removing Form1.h, chart.cpp. Will move Form2.h to form1.h. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5557 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 59 ++------------------------------------------------ Phreeqc.h | 12 +++++----- class_main.cpp | 6 ----- 3 files changed, 8 insertions(+), 69 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c743cb43..c7fb53d7 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -223,12 +223,12 @@ Phreeqc::Phreeqc(void) {"let", toklet}, {"print", tokprint}, {"punch", tokpunch}, - #if defined PHREEQ98 || defined CHART || defined MULTICHART + #if defined PHREEQ98 || defined MULTICHART {"graph_x", tokgraph_x}, {"graph_y", tokgraph_y}, {"graph_sy", tokgraph_sy}, #endif - #if defined CHART || defined MULTICHART + #if defined MULTICHART {"plot_xy", tokplot_xy}, #endif {"input", tokinput}, @@ -346,61 +346,6 @@ Phreeqc::Phreeqc(void) command[i].keycount = command_temp[i].keycount; } -// chart.cpp ------------------------------- -#ifdef CHART - update_time_chart = 150; /* milliseconds, maybe read */ - PanelHeight = 510; - PanelWidth = 640; - - axis_titles[0] = string_duplicate("X-axis"); - axis_titles[1] = string_duplicate("Y-axis"); - axis_titles[2] = string_duplicate("Y2-axis"); - - /* min, max, major tic, minor tic, log */ - for (i = 0; i < 5; i++) - { - axis_scale_x[i] = NA; - axis_scale_y[i] = NA; - axis_scale_y2[i] = NA; - } - - chart_title = string_duplicate(""); - - chart_type = 0; /* default: plot vs distance. If chart_type = 1, plot vs time */ - graph_initial_solutions = 0; /* false */ - connect_simulations = 1; /* same curve properties in new simulations */ - rownr = -1; - colnr = 0; /* row and col no defined in basic.c for GridChar and Plot_XY */ - RowOffset = 0; /* = 1 if new simulations should add points to the same curve */ - ColumnOffset = 0; /* sets column offset, from CSV plot, and from new USER_GRAPH */ - prev_advection_step = 0; - prev_transport_step = 0; /* not used in chart, for compatibility with PfW */ - AddSeries = 1; /* new curve properties in new simulation (does the same, but opposite of connect_simulation) */ - - end_timer = false; /* in mainsubs.c, stops the update timer in form1.h */ - - ncurves = 0; - for (i = 0; i < 3; i++) - { - ncurves_changed[i] = 0; /* for updating the chart: */ - } /* 0 or 1 (if curves have changed), previous no, new no of curves with points*/ - - char *SymbolList_init[11] = {"Square", "Diamond", "Triangle", "Circle", "XCross", "Plus", "Star", - "TriangleDown", "HDash", "VDash", "None"}; - for (i = 0; i < 11; i++) - { - SymbolList[i] = string_duplicate(SymbolList_init[i]); - } - /*ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; // defined in Form1.h as cli */ - /* or any color from System::Drawing::Color */ - - nCSV_headers = 0; /* no of CSV curves, also defines ColumnOffset if connect_simulations = 1 */ - FirstCallToUSER_GRAPH = 1; - new_ug = false; /* in case USER_GRAPH is redefined */ - u_g = false; - u_g_active = false; -#endif // CHART - //cl1.c x_arg = NULL, res_arg = NULL, scratch = NULL; x_arg_max = 0, res_arg_max = 0, scratch_max = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 5bc8df3b..2c7406a8 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -122,12 +122,12 @@ void cmddel(struct LOC_exec *LINK); void cmdrenum(struct LOC_exec *LINK); void cmdprint(struct LOC_exec *LINK); void cmdpunch(struct LOC_exec *LINK); -#if defined PHREEQ98 || defined CHART || defined MULTICHART +#if defined PHREEQ98 || defined MULTICHART void cmdgraph_x(struct LOC_exec *LINK); void cmdgraph_y(struct LOC_exec *LINK); void cmdgraph_sy(struct LOC_exec *LINK); #endif -#if defined CHART || defined MULTICHART +#if defined MULTICHART void cmdplot_xy(struct LOC_exec *LINK); #endif void cmdlet(boolean implied, struct LOC_exec *LINK); @@ -209,7 +209,7 @@ int system_total_solids(struct exchange *exchange_ptr, static LDBLE f_rho(LDBLE rho_old, void *cookie); // chart.cpp -#if defined PHREEQ98 || defined CHART +#if defined PHREEQ98 void DeleteCurves(void); void ExtractCurveInfo(char *line, int curvenr); void GridChar(char *s, char *a); @@ -720,7 +720,7 @@ int punch_s_s_assemblage(void); int punch_saturation_indices(void); int punch_totals(void); int punch_user_punch(void); -#if defined PHREEQ98 || defined CHART || defined MULTICHART +#if defined PHREEQ98 || defined MULTICHART int punch_user_graph(void); #endif @@ -794,7 +794,7 @@ int read_use(void); int read_title(void); int read_user_print(void); int read_user_punch(void); -#if defined PHREEQ98 || defined CHART +#if defined PHREEQ98 int read_user_graph(void); #endif #if defined MULTICHART @@ -1333,7 +1333,7 @@ int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: int compute_gfw(const char *string, LDBLE * gfw); - #if defined PHREEQ98 || defined CHART + #if defined PHREEQ98 int copy_title(char *token_ptr, char **ptr, int *length); #endif int copy_token(char *token_ptr, char **ptr, int *length); diff --git a/class_main.cpp b/class_main.cpp index 2d380018..d80aa328 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -59,12 +59,6 @@ main(int argc, char *argv[]) } } #endif -#ifdef CHART - while (phreeqc_instance.u_g_active) - { - Sleep(100); - } -#endif } From 3be93e8f78aa94a6dd6e2b1ff3a8ca4526ed3ec4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 8 Aug 2011 16:23:35 +0000 Subject: [PATCH 0234/1077] Renaming Form2 to Form1. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5558 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index ee4102c3..ac12b69a 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -26,7 +26,7 @@ extern void * free_check_null(void *); #include "phqalloc.h" #include "phrqproto.h" #include "output.h" -#include "Form2.h" +#include "Form1.h" using namespace zdg_ui2; ////////////////////////////////////////////////////////////////////// From 0043052431a8dbe951edc108e917d3a51395de25 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 11 Aug 2011 17:14:32 +0000 Subject: [PATCH 0235/1077] Modified for "+" sign; makes Fe(+3) synonymous with Fe(3), for example. Fixed up revisions and PHREEQCPP-RELEASE.txt for new release. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5570 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHREEQCPP-RELEASE.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt index 388c0164..546b59bb 100644 --- a/PHREEQCPP-RELEASE.txt +++ b/PHREEQCPP-RELEASE.txt @@ -7,6 +7,11 @@ ------------------------------------------------------------ Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------ + See PHREEQC release notes. + +------------------------------------------------------------ +Version 2.18.2: April 9, 2011 +------------------------------------------------------------ -------- -------- svn 5471 -------- From 978f151573332b227834d259a42f1e5242813dae Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 17 Aug 2011 14:25:58 +0000 Subject: [PATCH 0236/1077] Removed unnecessary header file ISolution.h Tony's fix for plotting CSV git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5582 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.h | 2 +- Parser.cxx | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ISolution.h b/ISolution.h index 14db0810..686ce74e 100644 --- a/ISolution.h +++ b/ISolution.h @@ -12,7 +12,7 @@ #include #include "ISolutionComp.h" -#include "NumKeyword.h" +//#include "NumKeyword.h" #include "Solution.h" class cxxISolution:public cxxSolution diff --git a/Parser.cxx b/Parser.cxx index a9e7fd4b..e87c83d4 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1443,6 +1443,12 @@ CParser::TOKEN_TYPE CParser::parse_delimited(std::string & source, std::string & temp = source.substr(pos+1); source = temp; } + else if (pos == 0) + { + temp = source.substr(pos+1); + source = temp; + return token_type(""); + } else { result = source; From 79e978a77364b542ae47448a06b6a118e1cc6dc8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 19 Aug 2011 14:00:51 +0000 Subject: [PATCH 0237/1077] reverting Tony's change. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5596 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index e87c83d4..a9e7fd4b 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1443,12 +1443,6 @@ CParser::TOKEN_TYPE CParser::parse_delimited(std::string & source, std::string & temp = source.substr(pos+1); source = temp; } - else if (pos == 0) - { - temp = source.substr(pos+1); - source = temp; - return token_type(""); - } else { result = source; From 70d290b5e4900b8e3379bea90b3f058a89baae38 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 24 Aug 2011 15:39:44 +0000 Subject: [PATCH 0238/1077] Removed headers from header files where possible. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@5602 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dictionary.h b/Dictionary.h index 43ad36b3..7043e6c8 100644 --- a/Dictionary.h +++ b/Dictionary.h @@ -6,8 +6,6 @@ #include // std::string #include // std::list #include // std::vector -#include "Solution.h" -#include "NameDouble.h" class cxxDictionary { From a57c89d7c745f7dbe9da0102f31b60d83be37a52 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 25 Aug 2011 22:01:25 +0000 Subject: [PATCH 0239/1077] New version of parser git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5611 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_Parser.cxx | 1454 +++++++++++++++++++++++++++++++++++++++++++++++ PHRQ_Parser.h | 347 +++++++++++ 2 files changed, 1801 insertions(+) create mode 100644 PHRQ_Parser.cxx create mode 100644 PHRQ_Parser.h diff --git a/PHRQ_Parser.cxx b/PHRQ_Parser.cxx new file mode 100644 index 00000000..511c9aa6 --- /dev/null +++ b/PHRQ_Parser.cxx @@ -0,0 +1,1454 @@ +// Parser.cpp: implementation of the PHRQ_Parser class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include // std::transform +#include // std::map +#include // assert +#include +#include // std::cout std::cerr +#include "Utils.h" +#include +#if defined (PHREEQC_CLASS) +#include "Phreeqc.h" +#endif +#include "PHRQ_Parser.h" +#include "output.h" + +//extern char *string_hsave(const char *str); + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), +m_input_error(0), +m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance1; +#endif +} + +PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), +m_input_error(0), +m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance1; +#endif +} + +PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), +m_input_error(0), +m_next_keyword(KT_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; +#if defined(PHREEQC_CLASS) + this->p_instance = p_instance1; +#endif +} + +PHRQ_Parser::~PHRQ_Parser() +{ +} + +PHRQ_Parser::LINE_TYPE PHRQ_Parser::check_line(const std::string & str, + bool allow_empty, bool allow_eof, + bool allow_keyword, bool print) +{ + LINE_TYPE + i; + + // Get line + do + { + i = get_line(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + // output for stream + switch (this->echo_stream) + { + case EO_NONE: + break; + case EO_ALL: + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; + case EO_KEYWORDS: + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; + case EO_NOKEYWORDS: + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + get_output() << msg; + } + break; + } + // output for file + switch (this->echo_file) + { + case EO_NONE: + break; + case EO_ALL: + if (i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; + case EO_KEYWORDS: + if (i == LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; + + case EO_NOKEYWORDS: + if (i != LT_KEYWORD && i != LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + } + break; + } + } + while (i == LT_EMPTY && allow_empty == false); + + // Check eof + if (i == LT_EOF && allow_eof == false) + { + std::ostringstream msg; + msg << "Unexpected eof while reading " << str << + "\nExecution terminated.\n"; + error_msg(msg, OT_STOP); + } + + // Check keyword + if (i == LT_KEYWORD && allow_keyword == false) + { + std::ostringstream msg; + msg << "Expected data for " << str << + ", but got a keyword ending data block."; + error_msg(msg, OT_CONTINUE); + incr_input_error(); + } + m_line_type = i; + return i; +} + +PHRQ_Parser::LINE_TYPE PHRQ_Parser::get_line() +{ + PHRQ_Parser::LINE_TYPE return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + // + // Eliminate all characters after # sign as a comment + // + + // + // Get line, check for eof + // + if (get_logical_line() == LT_EOF) + { + if (!m_input_stream.eof()) + { + error_msg("Reading input file.", OT_CONTINUE); + error_msg("istream::get() returned an error.", OT_STOP); + } + else + { + //{{MOD + m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + //}}MOD + m_next_keyword = KT_EOF; + return LT_EOF; + } + } + + // + // Get long lines + // + bool + empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + if (this->accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + } + + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + return return_value; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +PHRQ_Parser::LINE_TYPE PHRQ_Parser::get_logical_line() +{ + int + j; + unsigned int + pos; + char + c; + + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + + while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '#') + { + // ignore all chars after # until newline + do + { + c = (char) j; + if (c == '\n') + { + break; + } + m_line_save += c; + } + while ((j = + m_input_stream.get()) != std::char_traits < + char >::eof()); + } + if (c == ';') + break; + if (c == '\n') + { + break; + } + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + while ((j = + m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') + { + // remove '\\' + for (; pos < m_line_save.size(); pos++) + { + m_line_save[pos] = m_line_save[pos + 1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) + break; + } + } + else + { + m_line_save += c; + } + } + if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) + { + return (LT_EOF); + } + return (LT_OK); +} + + +//bool PHRQ_Parser::check_key(const std::string::iterator ptr) +bool +PHRQ_Parser::check_key(std::string::iterator begin, std::string::iterator end) +{ + static std::map < std::string, KEY_TYPE > s_keyword_map; + if (s_keyword_map.size() == 0) + { + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("solution_raw", + KT_SOLUTION_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("exchange_raw", + KT_EXCHANGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("gas_phase_raw", + KT_GASPHASE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("kinetics_raw", + KT_KINETICS_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("equilibrium_phases_raw", + KT_PPASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("solid_solutions_raw", + KT_SSASSEMBLAGE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("surface_raw", + KT_SURFACE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("reaction_temperature_raw", + KT_TEMPERATURE_RAW)); + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("reaction_raw", + KT_REACTION_RAW)); +#if defined MULTICHART + s_keyword_map.insert(std::map < std::string, + KEY_TYPE >::value_type("user_graph", + KT_USER_GRAPH)); +#endif + } + + std::string lowercase; + copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), + tolower); + + m_next_keyword = KT_NONE; + std::map < std::string, KEY_TYPE >::iterator map_iter = + s_keyword_map.find(lowercase); + if (map_iter == s_keyword_map.end()) + return false; + m_next_keyword = (*map_iter).second; + return true; +} + +PHRQ_Parser::STATUS_TYPE PHRQ_Parser::check_units(std::string & tot_units, + bool alkalinity, + bool check_compatibility, + const std::string & default_units, + bool print) +{ +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity true if alkalinity, false if any other total, + * check_compatibility true check alk and default units, false otherwise + * default_units character string of default units (check /L, /kg, etc) + * print true print warning messages + * Output: + * tot_units standard form for unit + */ + using + Utilities::str_tolower; + using + Utilities::replace; + using + Utilities::squeeze_white; + + static const char * + units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + + std::string::size_type end; + if ((end = tot_units.find("/l")) != std::string::npos) + { + tot_units.resize(end + 2); + } + if ((end = tot_units.find("/kgs")) != std::string::npos) + { + tot_units.resize(end + 4); + } + if ((end = tot_units.find("/kgw")) != std::string::npos) + { + tot_units.resize(end + 4); + } + + // + // Check if unit in list + // + bool + found = false; + for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) + { + if (tot_units.compare(units[i]) == 0) + { + found = true; + break; + } + } + if (!found) + { + if (print) + { + std::ostringstream err; + err << "Unknown unit, " << tot_units; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // Check if units are compatible with default_units + // + if (check_compatibility == false) + return PARSER_OK; + + // + // Special cases for alkalinity + // + if (alkalinity == true && tot_units.find("Mol") != std::string::npos) + { + if (print) + { + warning_msg + ("Alkalinity given in moles, assumed to be equivalents."); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == false && tot_units.find("eq") != std::string::npos) + { + if (print) + { + error_msg("Only alkalinity can be entered in equivalents.", + OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // See if default_units are compatible with tot_units + // + if (default_units.find("/l") != std::string::npos + && tot_units.find("/l") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgs") != std::string::npos + && tot_units.find("/kgs") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgw") != std::string::npos + && tot_units.find("/kgw") != std::string::npos) + return PARSER_OK; + + std::string str = default_units; + replace("kgs", "kg solution", str); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", str); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", str); + replace("Mol", "mol", str); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); + + if (print) + { + std::ostringstream err; + err << "Units for master species, " << tot_units << + ", are not compatible with default units, " << str << "."; + error_msg(err, OT_CONTINUE); + } + return PARSER_ERROR; +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::token_type(const std::string & token) +{ + if (!token.empty()) + { + if (::isupper(token[0])) + { + return PHRQ_Parser::TT_UPPER; + } + else if (::islower(token[0])) + { + return PHRQ_Parser::TT_LOWER; + } + else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') + { + return PHRQ_Parser::TT_DIGIT; + } + else + { + assert(!::isspace(token[0])); + return PHRQ_Parser::TT_UNKNOWN; + } + } + else + { + return PHRQ_Parser::TT_EMPTY; + } +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::peek_token() +{ + std::istringstream::pos_type pos = m_line_iss.tellg(); + std::string token; + m_line_iss >> token; + m_line_iss.seekg(pos); + return token_type(token); +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) +{ + if (begin != end) + { + std::string::iterator b = begin; + for (; b < end &&::isspace(*b); ++b); + + begin = b; + for (; begin < end && !::isspace(*begin); ++begin); + + token.assign(b, begin); + } + else + { + token.resize(0); + } + + return token_type(token); +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, + std::istream & is) +{ + is >> token; + return token_type(token); +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, + std::istream::pos_type & pos) +{ + m_line_iss.seekg(pos); + // m_line_iss >> token; + if (!(m_line_iss >> token)) + { + token.erase(token.begin(), token.end()); // token.clear(); + } + pos = m_line_iss.tellg(); + return token_type(token); +} + +PHRQ_Parser::FIND_TYPE PHRQ_Parser::find_option(const std::string & item, int *n, + const std::vector < std::string > + &list, bool exact) +{ + std::string token(item); + std::transform(token.begin(), token.end(), token.begin(), tolower); + for (unsigned int i = 0; i < list.size(); i++) + { + if (exact == true) + { + if (list[i].compare(token) == 0) + { + *n = i; + return FT_OK; + } + } + else + { + if (list[i].find(token) == 0) + { + *n = i; + return FT_OK; + } + } + } + + *n = -1; + return FT_ERROR; +} + +// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) +// OPTION_TYPE PHRQ_Parser::get_option(const std::vector& opt_list, std::string::iterator& next_char) +int +PHRQ_Parser::get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; + + // char option[MAX_LENGTH]; + std::string option; + + fprintf(stderr, "Did not think this get_option was called\n"); + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == PHRQ_Parser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); + + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; + + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int +PHRQ_Parser::get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} +/* + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } +*/ + } + else + { +/* + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } +*/ + //error_msg("Unknown option.", OT_CONTINUE); + //error_msg(m_line_save.c_str(), OT_CONTINUE); + //incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + //pos_ptr = 0; + //copy_token(option, pos_ptr); + //if (find_option(option, &opt, opt_list, true) == FT_OK) + //{ + // j = opt; + // next_pos = pos_ptr; + //} + //else + //{ + // j = OPT_DEFAULT; + // next_pos = 0; + //} + + //std::istringstream m_line_iss_copy = m_line_iss; + pos_ptr = m_line_iss.tellg(); + m_line_iss >> option; + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = m_line_iss.tellg(); + } + else + { + j = OPT_DEFAULT; + m_line_iss.seekg(pos_ptr); + m_line_iss.clear(); + next_pos = pos_ptr; + //m_line_iss >> option; + } +/* + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + fprintf(stderr, "Yikes 3\n"); + get_output() << "\t" << m_line_save << "\n"; + } + } +*/ + } + return (j); +} + +int +PHRQ_Parser::error_msg(const char *err_str, ONERROR_TYPE ot) +{ + ERROR_MESSAGE_QUALIFIER error_msg(err_str, (int) ot); + m_error_stream << "ERROR: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "ERROR: " << err_str << "\n"; + m_output_stream.flush(); + + if (ot == OT_STOP) + { + exit(1); + } + return 0; +} + +int +PHRQ_Parser::warning_msg(const char *err_str) +{ + m_error_stream << "WARNING: " << err_str << "\n"; + m_error_stream.flush(); + + m_output_stream << "WARNING: " << err_str << "\n"; + m_output_stream.flush(); + + return 0; +} + +PHRQ_Parser::STATUS_TYPE PHRQ_Parser::get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element) +{ + element.erase(element.begin(), element.end()); // element.clear(); + + if (begin == end) + { + error_msg("Empty string in get_elt. Expected an element name.", + OT_CONTINUE); + return PARSER_ERROR; + } + + // + // Load name into char array element + // + char + c = *begin; + ++begin; + element.insert(element.end(), c); // element.push_back(c); + if (c == '[') + { + while ((c = *begin) != ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if ((c = *begin) == ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + break; + } + else if (begin == end) + { + error_msg("No ending bracket (]) for element name", + OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + } + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + else + { + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + return PARSER_OK; +} + +PHRQ_Parser::STATUS_TYPE PHRQ_Parser::parse_couple(std::string & token) +{ + // Parse couple puts redox couples in standard form + // "+" is removed and couples are rewritten in sort + // order. + + if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) + { + Utilities::str_tolower(token); + return PARSER_OK; + } + + while (Utilities::replace("+", "", token)); + + std::string::iterator ptr = token.begin(); + std::string elt1; + get_elt(ptr, token.end(), elt1); + + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " << + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + + int + paren_count = 1; + std::string paren1 = "("; + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren1.insert(paren1.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } + + ++ptr; + if (ptr == token.end() || *ptr != '/') + { + std::ostringstream err_msg; + err_msg << " " "/" " must follow parentheses " << + "ending first half of redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + ++ptr; + std::string elt2; + get_elt(ptr, token.end(), elt2); + if (elt1.compare(elt2) != 0) + { + std::ostringstream err_msg; + err_msg << "Redox couple must be two redox states " << + "of the same element, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " + "parentheses in redox couple, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + std::string paren2 = "("; + paren_count = 1; + + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + paren2.insert(paren2.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } + if (paren1.compare(paren2) < 0) + { + token = elt1 + paren1 + std::string("/") + elt2 + paren2; + } + else if (paren1.compare(paren2) > 0) + { + token = elt2 + paren2 + std::string("/") + elt1 + paren1; + } + else + { + std::ostringstream err_msg; + err_msg << "Both parts of redox couple are the same, " << + token << "."; + error_msg(err_msg, OT_CONTINUE); + return PARSER_ERROR; + } + return PARSER_OK; +} + +//PHRQ_Parser::STATUS_TYPE PHRQ_Parser::addPair(std::map < char *, double, +// CHARSTAR_LESS > &totals, +// std::istream::pos_type & pos) +//{ +// std::string token; +// char * +// ctoken; +// double +// d; +// +// PHRQ_Parser::TOKEN_TYPE j; +// +// m_line_iss.seekg(pos); +// +// j = copy_token(token, pos); +// +// if (j == TT_EMPTY) +// return PARSER_OK; +// +// if (!(m_line_iss >> d)) +// { +// return PARSER_ERROR; +// } +// ctoken = string_hsave(token.c_str()); +// totals[ctoken] = d; +// return PARSER_OK; +//} + +PHRQ_Parser::STATUS_TYPE PHRQ_Parser::addPair(std::map < std::string, double >&totals, + std::istream::pos_type & pos) +{ + std::string token; + //char * ctoken; + double + d; + PHRQ_Parser::TOKEN_TYPE j; + + m_line_iss.seekg(pos); + + j = copy_token(token, pos); + + if (j == TT_EMPTY) + return PARSER_OK; + + if (!(m_line_iss >> d)) + { + return PARSER_ERROR; + } + //ctoken = string_hsave(token.c_str()); + //totals[ctoken] = d; + totals[token] = d; + return PARSER_OK; +} + +int +PHRQ_Parser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + //char *opt_ptr; + std::string::iterator opt_ptr; + + // char option[MAX_LENGTH]; + std::string option; + + // + // Read line + // + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == PHRQ_Parser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + //////std::istringstream err_msg; + //////err_msg << "Unknown option."; + //////err_msg << line_save; + //////error_msg(const std::string& msg, ONERROR_TYPE); + + // error_msg("Unknown option.", CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + std::cerr << "Unknown option." << "\n"; + std::cerr << m_line_save << "\n"; + + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::cout << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} + +int +PHRQ_Parser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + //LINE_TYPE lt = check_line("get_option", false, true, true, false); + LINE_TYPE lt = m_line_type; + if (lt == LT_EOF) + { + j = OPT_EOF; + } + else if (lt == LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //{{ + //// m_line_iss.clear(); + //}} + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + else + { + if (true) // (database_file == NULL) + { + get_output() << "\t" << m_line_save << "\n"; + } + error_msg("Unknown option.", OT_CONTINUE); + error_msg(m_line_save.c_str(), OT_CONTINUE); + incr_input_error(); + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + get_output() << "\t" << m_line_save << "\n"; + } + } + } + return (j); +} +int PHRQ_Parser:: +incr_input_error() +{ + ++ ERROR_MESSAGE_QUALIFIER input_error; + return ++m_input_error; +} + +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) +{ + if (begin != end) + { + std::string::iterator b = begin; + std::string::iterator e = end; + for (; b < end && (::isspace(*b) || (*b == ',')); ++b); + begin = b; + if (*begin == '"') + { + begin = ++b; + for (; begin != end && !(*begin == '"'); ++begin); + e = begin; + if (begin != end && *begin == '"') + { + e = begin++; + } + } + else if (*begin == '\'') + { + begin = ++b; + for (; begin != end && !(*begin == '\''); ++begin); + e = begin; + if (begin != end && *begin == '\'') + { + e = begin++; + } + } + else + { + for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin); + e = begin; + } + token.assign(b, e); + } + else + { + token.resize(0); + } + token = trim(token); + return token_type(token); +} +bool PHRQ_Parser::get_true_false(std::istream::pos_type & pos, bool def) +{ + std::string token; + this->copy_token(token, pos); + std::string::iterator b = token.begin(); + for (; b != token.end() && (::isspace(*b)); ++b); + if (b != token.end()) + { + if (*b == 'f' || *b == 'F') + { + return false; + } + else if (*b == 't' || *b == 'T') + { + return true; + } + } + return def; +} +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::get_rest_of_line(std::string &token) +{ + token.clear(); + std::istringstream::pos_type pos = m_line_iss.tellg(); + int j; + while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) + { + char c = (char) j; + token += c; + } + token = trim(token); + return token_type(token); +} +PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::parse_delimited(std::string & source, std::string & result, + const std::string& t = " \t") +{ + + size_t pos = source.find_first_of(t); + std::string temp; + if (pos != std::string::npos) + { + result = source.substr(0, pos); + temp = source.substr(pos+1); + source = temp; + } + else + { + result = source; + source.clear(); + } + std::string str = result; + + return token_type(trim_left(str)); +} \ No newline at end of file diff --git a/PHRQ_Parser.h b/PHRQ_Parser.h new file mode 100644 index 00000000..7b5ea694 --- /dev/null +++ b/PHRQ_Parser.h @@ -0,0 +1,347 @@ +#if !defined(PHRQ_PARSER_H_INCLUDED) +#define PHRQ_PARSER_H_INCLUDED + +#include // std::string +#include // std::map +#include // std::vector +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include "Phreeqc_class.h" +#if defined (PHREEQC_CLASS) +class Phreeqc; +#define PHREEQC_NAME_SPACE Phreeqc:: +#define PHREEQC_COOKIE this->p_instance-> +#define ERROR_MESSAGE_QUALIFIER this->p_instance-> +#else +#define PHREEQC_NAME_SPACE :: +#define PHREEQC_COOKIE +#define ERROR_MESSAGE_QUALIFIER :: +extern int input_error; +#endif + +class PHRQ_Parser +{ + public: + PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input); + PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output); + PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, + std::ostream & error); + + virtual ~ PHRQ_Parser(); + + enum LINE_TYPE + { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; + + enum TOKEN_TYPE + { + TT_EMPTY = 2, + TT_UPPER = 4, + TT_LOWER = 5, + TT_DIGIT = 6, + TT_UNKNOWN = 7 + }; + + enum FIND_TYPE + { + FT_OK = 0, + FT_ERROR = 1 + }; + + enum KEY_TYPE + { + KT_NONE = -1, + KT_END = 0, + KT_EOF = 1, + KT_SOLUTION_RAW = 5, + KT_EXCHANGE_RAW = 6, + KT_GASPHASE_RAW = 7, + KT_KINETICS_RAW = 8, + KT_PPASSEMBLAGE_RAW = 9, + KT_SSASSEMBLAGE_RAW = 10, + KT_SURFACE_RAW = 11, + KT_TEMPERATURE_RAW = 12, + KT_REACTION_RAW = 13 +#if defined MULTICHART + , KT_USER_GRAPH = 14 +#endif + }; + + enum OPT_TYPE + { + OPT_DEFAULT = -4, + OPT_ERROR = -3, + OPT_KEYWORD = -2, + OPT_EOF = -1 + }; + + enum ONERROR_TYPE + { + OT_CONTINUE = 0, + OT_STOP = 1 + }; + + enum ECHO_OPTION + { + EO_NONE = 0, + EO_ALL = 1, + EO_KEYWORDS = 2, + EO_NOKEYWORDS = 3 + }; + + enum STATUS_TYPE + { + PARSER_ERROR = 0, + PARSER_OK = 1 + }; + + + /** + Function gets a new line and checks for empty, eof, and keywords. + + Arguments: + string Input, character string used in printing error message + allow_empty Input, True or false, if a blank line is accepable + if false, another line is read + allow_eof Input, True or false, if EOF is acceptable + allow_keyword Input, True or false, if a keyword is acceptable + + Returns: + LT_EMPTY if empty line read and allow_empty == true + LT_KEYWORD if line begins with keyword + LT_EOF if eof and allow_eof == true + LT_OK otherwise + LT_OPTION if line begins with -[alpha] + + Terminates if EOF and allow_eof == false. + */ + LINE_TYPE check_line(const std::string & str, bool allow_empty, + bool allow_eof, bool allow_keyword, bool print); + + /** + Read a line from input file put in "line". + Copy of input line is stored in "line_save". + Characters after # are discarded in line but retained in "line_save" + + Arguments: + None + Returns: + LT_EMPTY, + LT_EOF, + LT_KEYWORD, + LT_OK, + LT_OPTION + */ + LINE_TYPE get_line(); + + // bool check_key(const std::string::iterator ptr); + bool check_key(std::string::iterator begin, std::string::iterator end); + + STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, + bool check_compatibility, + const std::string & default_units, bool print); + + + KEY_TYPE next_keyword() const + { + return m_next_keyword; + } + int get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char); + int get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos); + + + std::string & line() + { + return m_line; + } + std::string & get_accumulated() + { + return accumulated; + } + void set_accumulate(bool tf) + { + if (tf) + { + accumulated.clear(); + } + this->accumulate = tf; + } + std::istringstream & get_iss() + { + return m_line_iss; + } + int incr_input_error(); + std::ostream & get_output() + { + return m_output_stream; + } + int get_input_error() + { + return m_input_error; + } + + std::istream::pos_type tellg() + { + return m_input_stream.tellg(); + } + std::istream& seekg(std::istream::pos_type p) + { + return m_input_stream.seekg(p); + } + + + + + /** + Copies from begin to token until first space is encountered. + + Arguments: + token output, the token + begin input, begin iterator + end input, end iterator + + Returns: + TT_EMPTY + TT_UPPER + TT_LOWER + TT_DIGIT + TT_UNKNOWN + */ + static TOKEN_TYPE copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); + static PHRQ_Parser::TOKEN_TYPE copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); + static TOKEN_TYPE token_type(const std::string & token); + static TOKEN_TYPE copy_token(std::string & token, std::istream & is); + TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); + bool get_true_false(std::istream::pos_type & pos, bool def); + TOKEN_TYPE get_rest_of_line(std::string &token); + static TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); + PHRQ_Parser::TOKEN_TYPE peek_token(); + + /** + Function reads an element name out of the equation string. + An element name is composed of a capital letter followed by any number + of lower case characters. + + Arguments: + begin input, points to position in the equation to begin + output, points to next character of equation after + element name. + end input, points to last position in the equation + element input pointer to place to return element character string + */ + STATUS_TYPE get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element); + + + /** + Compares a string value to match beginning letters of a list of options + + Arguments: + item entry: pointer to string to compare + n exit: item in list that was matched + list entry: pointer to list of character values, assumed to + be lower case + count_list entry: number of character values in list + + Returns: + OK item matched + ERROR item not matched + n -1 item not matched + i position of match in list + */ + static FIND_TYPE find_option(const std::string & item, int *n, + const std::vector < std::string > &list, + bool exact); + + + int error_msg(const std::ostringstream & err_str, ONERROR_TYPE stop) + { + return error_msg(err_str.str().c_str(), stop); + } + int error_msg(const char *err_str, ONERROR_TYPE stop); + int warning_msg(const char *err_str); + + void set_echo_file(ECHO_OPTION opt) + { + echo_file = opt; + } + ECHO_OPTION get_echo_file() + { + return this->echo_file; + }; + + void set_echo_stream(ECHO_OPTION opt) + { + echo_stream = opt; + } + ECHO_OPTION get_echo_stream() + { + return this->echo_stream; + }; + + STATUS_TYPE parse_couple(std::string & token); + + //STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, + // std::istream::pos_type & pos); + STATUS_TYPE addPair(std::map < std::string, double >&totals, + std::istream::pos_type & pos); + + protected: + LINE_TYPE get_logical_line(); + + private: + std::istream & m_input_stream; + std::ostream & m_output_stream; + std::ostream & m_error_stream; + int m_input_error; + KEY_TYPE m_next_keyword; + std::string m_line; + std::string m_line_save; + std::istringstream m_line_iss; + LINE_TYPE m_line_type; + ECHO_OPTION echo_stream; + ECHO_OPTION echo_file; + std::string accumulated; + bool accumulate; +#if defined(PHREEQC_CLASS) + Phreeqc * p_instance; +#endif +}; + +//// Global functions +//inline std::string trim_right(const std::string &source , const std::string& t = " \t") +//{ +// std::string str = source; +// return str.erase( str.find_last_not_of(t) + 1); +//} +// +//inline std::string trim_left( const std::string& source, const std::string& t = " \t") +//{ +// std::string str = source; +// return str.erase(0 , source.find_first_not_of(t) ); +//} +// +//inline std::string trim(const std::string& source, const std::string& t = " \t") +//{ +// std::string str = source; +// return trim_left( trim_right( str , t) , t ); +//} + +#endif // PHRQ_PARSER_H_INCLUDED From 02797e6934ff100948362d24fd340c6e801a6660 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Sep 2011 23:07:14 +0000 Subject: [PATCH 0240/1077] Added PHRQ_base and PHRQ_io to project. PHRQ_base has not been added to the C++ classes yet. PHRQ_io is implemented enough to run. Need to work on reimplementing logic by moving some things that were in phreeqc_files.cpp (now implemented as PHRQ_io class) to PHRQ_io_output, which is derived from output.cpp. PHRQ_io_output has methods of Phreeqc class and knows the data in the phreeqc class. PHRQ_io does not know about the phreeqc class. The ifdef USE_OLD_IO should cause io to revert to the old way of doing it. I have only worked on ClrClass_debug to now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5627 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 63 ++++ PHRQ_base.h | 43 +++ PHRQ_io.cpp | 820 +++++++++++++++++++++++++++++++++++++++++++++++++ PHRQ_io.h | 112 +++++++ Phreeqc.cpp | 6 +- Phreeqc.h | 14 +- class_main.cpp | 6 +- 7 files changed, 1054 insertions(+), 10 deletions(-) create mode 100644 PHRQ_base.cxx create mode 100644 PHRQ_base.h create mode 100644 PHRQ_io.cpp create mode 100644 PHRQ_io.h diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx new file mode 100644 index 00000000..ea7e26d6 --- /dev/null +++ b/PHRQ_base.cxx @@ -0,0 +1,63 @@ +#include "PHRQ_base.h" +#include + +PHRQ_base:: +PHRQ_base(void) +{ + this->io = NULL; + error_count = 0; +} + +PHRQ_base:: +PHRQ_base(PHRQ_io * p_io) +{ + this->io = p_io; + error_count = 0; +} + +PHRQ_base:: +~PHRQ_base() +{ +} + +void PHRQ_base:: +error_msg(const std::string & stdstr) +{ + this->error_count++; + if (this->io) + { + //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_ERROR, stdstr, stop, "", args); + } + else + { + std::cerr << stdstr << std::endl; + std::cout << stdstr << std::endl; + } +} + +void PHRQ_base:: +warning_msg(const std::string & stdstr) +{ + if (this->io) + { + //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_WARNING, stdstr, stop, "", args); + } + else + { + std::cerr << stdstr << std::endl; + std::cout << stdstr << std::endl; + } +} + +void PHRQ_base:: +output_msg(const std::string & stdstr) +{ + if (this->io) + { + //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_MESSAGE, stdstr, stop, "", args); + } + else + { + std::cout << stdstr << std::endl; + } +} \ No newline at end of file diff --git a/PHRQ_base.h b/PHRQ_base.h new file mode 100644 index 00000000..15d93718 --- /dev/null +++ b/PHRQ_base.h @@ -0,0 +1,43 @@ +#ifndef _PHRQBASE_H +#define _PHRQBASE_H + +#include + +class PHRQ_io; +class PHRQ_base +{ +public: + // constructors + PHRQ_base(void); + PHRQ_base(PHRQ_io *); + virtual ~ PHRQ_base(); + + + // methods + void output_msg(const std::string &); + void error_msg(const std::string &); + void warning_msg(const std::string &); + + void Set_io(PHRQ_io * p_io) + { + this->io = p_io; + } + PHRQ_io * Get_io(void) + { + return this->io; + } + void Set_error_count(int i) + { + this->error_count = i; + } + int Get_error_count(void) + { + return this->error_count; + } + // data +private: + PHRQ_io * io; + int error_count; +}; + +#endif /* _PHRQBASE_H */ diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp new file mode 100644 index 00000000..c0927aea --- /dev/null +++ b/PHRQ_io.cpp @@ -0,0 +1,820 @@ +#include +#include "PHRQ_io.h" + +#if defined(MERGE_INCLUDE_FILES) +#include +#include +#include +#endif /* if defined(MERGE_INCLUDE_FILES) */ + +PHRQ_io:: +PHRQ_io(void) +{ + input_file = NULL; + database_file = NULL; + output_file = NULL; /* OUTPUT_MESSAGE */ + log_file = NULL; /* OUTPUT_LOG */ + punch_file = NULL; /* OUTPUT_PUNCH */ + error_file = NULL; /* OUTPUT_ERROR */ + dump_file = NULL; /* OUTPUT_DUMP */ + int error_count = 0; +} + +PHRQ_io:: +~PHRQ_io() +{ +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +phreeqc_handler(const int action, const int type, const char *err_str, + const bool stop, const char *format, + va_list args) +/* ---------------------------------------------------------------------- */ +{ + int i; + + switch (action) + { + case ACTION_OPEN: + return this->open_handler(type, err_str); + break; + case ACTION_OUTPUT: + return this->output_handler(type, err_str, stop, format, args); + break; + case ACTION_FLUSH: + return this->fileop_handler(type, fflush); + break; + case ACTION_REWIND: + return this->fileop_handler(type, &PHRQ_io::rewind_wrapper); + break; + case ACTION_CLOSE: + + i = this->fileop_handler(type, fclose); + switch (type) + { + case OUTPUT_ERROR: + this->error_file = NULL; + break; + + case OUTPUT_WARNING: + break; + + case OUTPUT_MESSAGE: + this->output_file = NULL; + break; + + case OUTPUT_PUNCH: + this->punch_file = NULL; + break; + + case OUTPUT_SCREEN: + break; + + case OUTPUT_LOG: + this->log_file = NULL; + break; + + case OUTPUT_STDERR: + break; + + case OUTPUT_DUMP: + this->dump_file = NULL; + break; + } + + + return (i); + break; + } + return false; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +close_input_files(void) +/* ---------------------------------------------------------------------- */ +{ + int i = 0; + if (database_file) + { + i |= fclose(database_file); + } + if (input_file) + { + i |= fclose(input_file); + } + input_file = database_file = NULL; + return (i); +} + +///* ---------------------------------------------------------------------- */ +//int PHRQ_io:: +//process_file_names(int argc, char *argv[], void **db_cookie, +// void **input_cookie, int log) +///* ---------------------------------------------------------------------- */ +//{ +// int l; +// char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; +// char query[2 * MAX_LENGTH]; +// char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; +// char *env_ptr; +// char *ptr; +// int errors; +// ENTRY item, *found_item; +// +///* +// * Prepare error handling +// */ +// errors = setjmp(mark); +// if (errors != 0) +// { +// return errors; +// } +// +///* +// * Prep for get_line +// */ +// max_line = MAX_LINE; +// space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); +// space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); +// hcreate_multi(5, &strings_hash_table); +// hcreate_multi(2, &keyword_hash_table); +// +///* +// * Initialize hash table +// */ +// keyword_hash = (struct key *) PHRQ_malloc(sizeof(struct key)); +// if (keyword_hash == NULL) +// { +// malloc_error(); +// } +// else +// { +// keyword_hash->name = string_hsave("database"); +// keyword_hash->keycount = 0; +// item.key = keyword_hash->name; +// item.data = keyword_hash; +// found_item = hsearch_multi(keyword_hash_table, item, ENTER); +// if (found_item == NULL) +// { +// sprintf(error_string, +// "Hash table error in keyword initialization."); +// error_msg(error_string, STOP); +// } +// } +// +// +///* +// * Open file for screen output +// */ +// if (argc > 4) +// { +// error_file = fopen(argv[4], "w"); +// if (error_file == NULL) +// { +//#ifdef PHREEQ98 +// error_file = NULL; /* We can not use stderr in BCB: this causes unexpected behaviour when reopening the input_file... */ +//#else +// error_file = stderr; +//#endif +// sprintf(error_string, "Error opening file, %s.", argv[4]); +// warning_msg(error_string); +// } +// } +// else +// { +//#ifdef PHREEQ98 +// error_file = NULL; /* We can not use stderr in BCB: this causes unexpected behaviour when reopening the input_file... */ +//#else +// error_file = stderr; +//#endif +// } +// +///* +// * Open user-input file +// */ +// strcpy(query, "Name of input file?"); +// if (argc <= 1) +// { +// default_name[0] = '\0'; +// input_file = file_open(query, default_name, "r", FALSE); +// } +// else +// { +// strcpy(default_name, argv[1]); +// input_file = file_open(query, default_name, "r", TRUE); +// } +// output_msg(OUTPUT_SCREEN, "Input file: %s\n\n", default_name); +// output_msg(OUTPUT_SEND_MESSAGE, "Input file: %s\r\n\r\n", default_name); +// strcpy(in_file, default_name); +///* +// * Open file for output +// */ +// strcpy(query, "Name of output file?"); +// +// ptr = default_name; +// copy_token(token, &ptr, &l); +// strcat(token, ".out"); +// if (argc <= 1) +// { +// output_file = file_open(query, token, "w", FALSE); +// } +// else if (argc == 2) +// { +// output_file = file_open(query, token, "w", TRUE); +// } +// else if (argc >= 3) +// { +// strcpy(token, argv[2]); +// output_file = file_open(query, token, "w", TRUE); +// } +// output_msg(OUTPUT_SCREEN, "Output file: %s\n\n", token); +// output_msg(OUTPUT_SEND_MESSAGE, "Output file: %s\r\n\r\n", token); +// strcpy(out_file, token); +///* +// * Open file for errors +// */ +// if (log == TRUE) +// { +//#ifdef PHREEQ98 +// if ((log_file = fopen(LogFileNameC, "w")) == NULL) +// { +//#else /* PHREEQ98 */ +// if ((log_file = fopen("phreeqc.log", "w")) == NULL) +// { +//#endif /* PHREEQ98 */ +// error_msg("Can't open log file, phreeqc.log.", STOP); +// } +// } +// /* +// * Read input file for DATABASE keyword +// */ +// std::ifstream * temp_input = new std::ifstream(in_file, std::ifstream::in); +// this->set_cookie(temp_input); +// if (get_line(istream_getc, temp_input) == KEYWORD) +// { +// ptr = line; +// copy_token(token, &ptr, &l); +// if (strcmp_nocase(token, "database") == 0) +// { +//#ifdef PHREEQ98 +// user_database = string_duplicate(prefix_database_dir(ptr)); +//#else +// user_database = string_duplicate(ptr); +//#endif +// if (string_trim(user_database) == EMPTY) +// { +// warning_msg +// ("DATABASE file name is missing; default database will be used."); +// user_database = (char *) free_check_null(user_database); +// } +// } +// } +// fclose(input_file); +// this->pop_cookie(); +// +// if ((input_file = fopen(in_file, "r")) == NULL) +// {; +// error_msg("Can't reopen input file.", STOP); +// } +///* +// * Open data base +// */ +// strcpy(query, "Name of database file?"); +// env_ptr = getenv("PHREEQC_DATABASE"); +// if (user_database != NULL) +// { +// strcpy(token, user_database); +// } +// else if (env_ptr != NULL) +// { +// strcpy(token, env_ptr); +// } +// else +// { +// strcpy(token, default_data_base); +// } +// if (argc <= 1) +// { +// database_file = file_open(query, token, "r", FALSE); +// } +// else if (argc < 4) +// { +// database_file = file_open(query, token, "r", TRUE); +// } +// else if (argc >= 4) +// { +// if (user_database == NULL) +// { +// strcpy(token, argv[3]); +// } +// else +// { +//#ifndef PHREEQCI_GUI +// warning_msg +// ("Database file from DATABASE keyword is used; command line argument ignored."); +//#endif +// } +// database_file = file_open(query, token, "r", TRUE); +// } +// output_msg(OUTPUT_SCREEN, "Database file: %s\n\n", token); +// output_msg(OUTPUT_SEND_MESSAGE, "Database file: %s\r\n\r\n", token); +// strcpy(db_file, token); +// +// output_msg(OUTPUT_MESSAGE, " Input file: %s\n", in_file); +// output_msg(OUTPUT_MESSAGE, " Output file: %s\n", out_file); +// output_msg(OUTPUT_MESSAGE, "Database file: %s\n\n", token); +///* +// * local cleanup +// */ +// user_database = (char *) free_check_null(user_database); +// line = (char *) free_check_null(line); +// line_save = (char *) free_check_null(line_save); +// +// hdestroy_multi(keyword_hash_table); +// keyword_hash = (struct key *) free_check_null(keyword_hash); +// keyword_hash_table = NULL; +// +// free_hash_strings(strings_hash_table); +// hdestroy_multi(strings_hash_table); +// strings_hash_table = NULL; +// +// *db_cookie = database_file; +// *input_cookie = input_file; +// +// this->db_stream = new std::ifstream(db_file, std::ifstream::in); +// this->in_stream = new std::ifstream(in_file, std::ifstream::in); +// *db_cookie = db_stream; +// *input_cookie = in_stream; +// +// return 0; +//} + +///* ---------------------------------------------------------------------- */ +//int PHRQ_io:: +//getc_callback(void *cookie) +///* ---------------------------------------------------------------------- */ +//{ +// int i; +// assert(cookie); +// i = getc((FILE *) cookie); +// +// return i; +//} + +//istream_getc is static *** +int PHRQ_io:: +istream_getc(void *cookie) +{ + if (cookie) + { + std::istream* is = (std::istream*)cookie; + int n = is->get(); + if (n == 13 && is->peek() == 10) + { + n = is->get(); + } + return n; + } + return EOF; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +output_handler(const int type, const char *err_str, const bool stop, + const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + int flush; + FILE *save_output = NULL; + + flush = 1; + + //if (get_forward_output_to_log()) + //{ + // save_output = output_file; + // output_file = log_file; + //} + + switch (type) + { + + case OUTPUT_ERROR: +// if (status_on == TRUE) +// { +// if (error_file != NULL) +// { +// fprintf(error_file, "\n"); +// } +//#ifndef DOS +// status_on = FALSE; +//#endif +// } + if (error_file != NULL) + { + fprintf(error_file, "ERROR: %s\n", err_str); + if (flush) + fflush(error_file); + } +#ifdef PHREEQ98 + sprintf(progress_str, "ERROR: %s\n", err_str); + show_progress(type, progress_str); +#endif /* PHREEQ98 */ + if (output_file != NULL) + { + fprintf(output_file, "ERROR: %s\n", err_str); +#ifdef PHREEQ98 + outputlinenr++; +#endif + if (flush) + fflush(output_file); + } + if (stop) + { + if (error_file != NULL) + { + fprintf(error_file, "Stopping.\n"); + fflush(error_file); + } +#ifdef PHREEQ98 + sprintf(progress_str, "Stopping.\n"); + show_progress(type, progress_str); +#endif /* PHREEQ98 */ + if (output_file != NULL) + { + fprintf(output_file, "Stopping.\n"); +#ifdef PHREEQ98 + outputlinenr++; +#endif + fflush(output_file); + } +//#if defined MULTICHART +// chart_handler.End_timer(PHREEQC_THIS); +//#endif + } + break; + + case OUTPUT_WARNING: + //if (pr.logfile == TRUE && log_file != NULL) + if (log_file != NULL) + { + fprintf(log_file, "WARNING: %s\n", err_str); + if (flush) + fflush(log_file); + } + //if (state == TRANSPORT && transport_warnings == FALSE) + // return (OK); + //if (state == ADVECTION && advection_warnings == FALSE) + // return (OK); +// if (pr.warnings >= 0) +// { +// if (count_warnings > pr.warnings) +// return (OK); +// } +// if (status_on == TRUE) +// { +// if (error_file != NULL) +// { +// fprintf(error_file, "\n"); +// } +//#ifndef DOS +// status_on = FALSE; +//#endif +// } + if (error_file != NULL) + { + fprintf(error_file, "WARNING: %s\n", err_str); + if (flush) + fflush(error_file); + } +#ifdef PHREEQ98 + sprintf(progress_str, "WARNING: %s\n", err_str); + show_progress(type, progress_str); +#endif /* PHREEQ98 */ + if (output_file != NULL) + { + fprintf(output_file, "WARNING: %s\n", err_str); +#ifdef PHREEQ98 + outputlinenr++; +#endif + if (flush) + fflush(output_file); + } + break; + case OUTPUT_CHECKLINE: + //if (pr.echo_input == TRUE) + { + if (output_file != NULL) + { + vfprintf(output_file, format, args); +#ifdef PHREEQ98 + check_line_breaks(format); +#endif + if (flush) + fflush(output_file); + } + } + break; + case OUTPUT_MESSAGE: + case OUTPUT_BASIC: + if (output_file != NULL) + { + vfprintf(output_file, format, args); +#ifdef PHREEQ98 + check_line_breaks(format); +#endif + if (flush) + fflush(output_file); + } + break; + case OUTPUT_PUNCH: + if (punch_file != NULL) + { + //if (pr.punch == TRUE && punch.in == TRUE) + { + vfprintf(punch_file, format, args); + if (flush) + fflush(punch_file); + } + } + break; + case OUTPUT_LOG: + //if (pr.logfile == TRUE && log_file != NULL) + if (log_file != NULL) + { + vfprintf(log_file, format, args); + if (flush) + fflush(log_file); + } + break; + case OUTPUT_SCREEN: + if (error_file != NULL) + { + vfprintf(error_file, format, args); + if (flush) + fflush(error_file); + } +#ifdef PHREEQ98 + vsprintf(progress_str, format, args); + show_progress(type, progress_str); +#endif /* PHREEQ98 */ + break; + case OUTPUT_STDERR: + case OUTPUT_CVODE: + if (stderr != NULL) + { + vfprintf(stderr, format, args); + fflush(stderr); + } + break; + case OUTPUT_DUMP: + if (dump_file != NULL) + { + vfprintf(dump_file, format, args); + if (flush) + fflush(dump_file); + } + break; + } + + //if (get_forward_output_to_log()) + //{ + // output_file = save_output; + //} + //return (OK); + return 1; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +close_output_files(void) +/* ---------------------------------------------------------------------- */ +{ + int ret = 0; + + if (output_file != NULL) + ret |= fclose(output_file); + if (log_file != NULL) + ret |= fclose(log_file); + if (punch_file != NULL) + ret |= fclose(punch_file); + if (dump_file != NULL) + ret |= fclose(dump_file); + if (error_file != NULL) + ret |= fclose(error_file); + error_file = NULL; + output_file = log_file = punch_file = dump_file = NULL; + return ret; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +open_handler(const int type, const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + + case OUTPUT_PUNCH: + if (punch_file != NULL) + { + fclose(punch_file); + punch_file = NULL; + } + if ((punch_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; + } + else + { + //free_check_null(selected_output_file_name); + //selected_output_file_name = string_duplicate(file_name); + } + break; + + case OUTPUT_DUMP: + if (dump_file != NULL) + { + fclose(dump_file); + dump_file = NULL; + } + if ((dump_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; + } + else + { + //free_check_null(dump_file_name); + //dump_file_name = string_duplicate(file_name); + } + break; + case OUTPUT_ERROR: + if (error_file != NULL && + error_file != stderr && + error_file != stdout) + { + fclose(error_file); + error_file = NULL; + } + if (file_name != NULL) + { + if ((error_file = fopen(file_name, "w")) == NULL) + { + error_file = stderr; + return 0; + } + } + else + { + error_file = stderr; + } + break; + case OUTPUT_LOG: + if (log_file != NULL && + log_file != stderr && + log_file != stdout) + { + fclose(log_file); + log_file = NULL; + } + if ((log_file = fopen(file_name, "w")) == NULL) + { + return 0; + } + break; + } + return 1; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +fileop_handler(const int type, int (*PFN) (FILE *)) +/* ---------------------------------------------------------------------- */ +{ + FILE *save_output = NULL; + + //int forward = get_forward_output_to_log(); + //if (forward) + //{ + // save_output = output_file; + // output_file = log_file; + //} + + switch (type) + { + case OUTPUT_ERROR: + if (error_file) + PFN(error_file); + break; + + case OUTPUT_WARNING: + if (error_file) + PFN(error_file); + if (output_file) + PFN(output_file); + break; + + case OUTPUT_MESSAGE: + case OUTPUT_CHECKLINE: + case OUTPUT_BASIC: + if (output_file) + PFN(output_file); + break; + + case OUTPUT_PUNCH: + if (punch_file) + PFN(punch_file); + break; + + case OUTPUT_SCREEN: + if (error_file) + PFN(error_file); + break; + + case OUTPUT_LOG: + if (log_file) + PFN(log_file); + break; + + case OUTPUT_CVODE: + case OUTPUT_STDERR: + if (stderr) + PFN(stderr); + break; + + case OUTPUT_DUMP: + if (dump_file) + PFN(dump_file); + break; + } + + //if (forward) + //{ + // output_file = save_output; + //} + //return (OK); + return 1; +} + +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +rewind_wrapper(FILE * file_ptr) +/* ---------------------------------------------------------------------- */ +{ + rewind(file_ptr); + //return (OK); + return 1; +} +//#if defined(MERGE_INCLUDE_FILES) +///* ---------------------------------------------------------------------- */ +//bool PHRQ_io:: +//recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream) +///* ---------------------------------------------------------------------- */ +//{ +// std::string myline; +// +// // input_file should be opened before calling recursive_include +// assert(input_stream.is_open()); +// +// while (std::getline(input_stream, myline)) +// { +// accumulated_stream << myline << std::endl; +// +// std::string copy_line = myline; +// // remove leading spaces +// copy_line.erase(0, copy_line.find_first_not_of(" \t") ); +// // get first 8 characters +// std::string token = copy_line.substr(0,9); +// // convert to lower case +// std::transform(token.begin(), token.end(), token.begin(), +// (int(*)(int)) std::tolower); +// // check for #include file_name +// if (token == "#$include") +// { +// // get file name without trailing spaces +// token = copy_line.substr(10, copy_line.length()); +// token.erase(0, token.find_first_not_of(" \t")); +// // remove leading, trailing spaces +// token = token.substr(0, token.find_last_not_of(" \t\n\0") + 1); +// // open stream +// std::ifstream next_stream(token.c_str(), std::ifstream::in); +// if (next_stream.is_open()) +// { +// recursive_include(next_stream, accumulated_stream); +// accumulated_stream << "#Done include " << token << std::endl; +// } +// else +// { +// // error opening file +// sprintf(error_string, "Could not open include file %s", token.c_str()); +// error_msg(error_string, STOP); +// } +// } +// } +// return true; +//} +//#endif /* defined(MERGE_INCLUDE_FILES) */ + diff --git a/PHRQ_io.h b/PHRQ_io.h new file mode 100644 index 00000000..e43f8e90 --- /dev/null +++ b/PHRQ_io.h @@ -0,0 +1,112 @@ +#ifndef _PHRQIO_H +#define _PHRQIO_H + +#include + +class PHRQ_io +{ +public: +typedef enum +{ + OUTPUT_ERROR, + OUTPUT_WARNING, + OUTPUT_MESSAGE, + OUTPUT_PUNCH, + OUTPUT_SCREEN, + OUTPUT_LOG, + OUTPUT_CHECKLINE, + OUTPUT_GUI_ERROR, + OUTPUT_BASIC, + OUTPUT_CVODE, + OUTPUT_DUMP, + OUTPUT_STDERR, + OUTPUT_SEND_MESSAGE, + OUTPUT_ECHO, + OUTPUT_PUNCH_END_ROW +} output_type; + +typedef enum +{ + ACTION_OPEN, + ACTION_OUTPUT, + ACTION_CLOSE, + ACTION_REWIND, + ACTION_FLUSH +} action_type; + + // constructors + PHRQ_io(void); + virtual ~ PHRQ_io(); + + // methods + + int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args); + int open_handler(const int type, const char *file_name); + + int fileop_handler(const int type, int (*PFN) (FILE *)); + int output_handler(const int type, const char *err_str, + const bool stop, const char *format, + va_list args); + static int rewind_wrapper(FILE * file_ptr); + + int close_input_files(void); + int close_output_files(void); + static int istream_getc(void *cookie); + + void Set_error_count(int i) + { + this->error_count = i; + } + int Get_error_count(void) + { + return this->error_count; + } + void Set_input_file(FILE * in) + { + if (this->input_file != NULL && + this->input_file != stderr && + this->input_file != stdout) + { + fclose(this->input_file); + } + this->input_file = in; + } + void Set_output_file(FILE * out) + { + if (this->output_file != NULL && + this->output_file != stderr && + this->output_file != stdout) + { + fclose(this->output_file); + } + this->output_file = out; + } + void Set_database_file(FILE * in) + { + if (this->database_file != NULL && + this->database_file != stdin) + { + fclose(this->database_file); + } + this->database_file = in; + } + void close_input(void) + { + if (input_file != stdin) + { + fclose(input_file); + } + } + // data +private: + FILE *input_file; + FILE *database_file; + FILE *output_file; /* OUTPUT_MESSAGE */ + FILE *log_file; /* OUTPUT_LOG */ + FILE *punch_file; /* OUTPUT_PUNCH */ + FILE *error_file; /* OUTPUT_ERROR */ + FILE *dump_file; /* OUTPUT_DUMP */ + int error_count; +}; + +#endif /* _PHRQIO_H */ diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c7fb53d7..794ce5f3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -21,6 +21,7 @@ Phreeqc::Phreeqc(void) phast = FALSE; s_pTail = NULL; user_database = NULL; +#ifdef USE_OLD_IO output_file = NULL; log_file = NULL; punch_file = NULL; @@ -28,6 +29,7 @@ Phreeqc::Phreeqc(void) error_file = NULL; database_file = NULL; input_file = NULL; +#endif rates = NULL; tally_table = NULL; spec = NULL; @@ -408,8 +410,8 @@ Phreeqc::~Phreeqc(void) { clean_up(); - close_input_files(); - close_output_files(); + this->phrq_io.close_input_files(); + this->phrq_io.close_output_files(); int i; for (i = 0; i < count_iso_defaults; i++) diff --git a/Phreeqc.h b/Phreeqc.h index 2c7406a8..177ba749 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -24,6 +24,7 @@ #ifdef MULTICHART #include "ChartHandler.h" #endif +#include "PHRQ_io.h" class cxxNameDouble; #define STATIC #define EXTERNAL @@ -527,12 +528,12 @@ char *prefix_database_dir(char *s); void show_progress(const int type, char *s); #endif public: -int fileop_handler(const int type, int (*PFN) (FILE *)); -int open_handler(const int type, const char *file_name); -int output_handler(const int type, const char *err_str, - const int stop, void *cookie, const char *format, - va_list args); -static int rewind_wrapper(FILE * file_ptr); +//int fileop_handler(const int type, int (*PFN) (FILE *)); +//int open_handler(const int type, const char *file_name); +//int output_handler(const int type, const char *err_str, +// const int stop, void *cookie, const char *format, +// va_list args); +//static int rewind_wrapper(FILE * file_ptr); void PASCAL_MAIN(int argc, Char **argv); long my_labs(long x); Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); @@ -1403,6 +1404,7 @@ protected: std::list cookie_list; std::ifstream * in_stream; std::ifstream * db_stream; + PHRQ_io phrq_io; }; #endif /* _INC_PHREEQC_H */ diff --git a/class_main.cpp b/class_main.cpp index d80aa328..5d69d605 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -94,6 +94,7 @@ main_method(int argc, char *argv[]) /* * Add callbacks for error_msg and warning_msg */ +#ifdef USE_OLD_IO if (add_output_callback(phreeqc_handler, this) != OK) { fprintf(stderr, "ERROR: %s\n", @@ -101,6 +102,7 @@ main_method(int argc, char *argv[]) fprintf(stderr, "ERROR: %s\n", "Program terminating."); return -1; } +#endif /* * Open input/output files @@ -129,7 +131,7 @@ main_method(int argc, char *argv[]) */ #if defined(MERGE_INCLUDE_FILES) this->set_cookie((std::ifstream *) db_cookie); - errors = read_database(istream_getc, db_cookie); + errors = read_database(PHRQ_io::istream_getc, db_cookie); this->clear_cookie(); #else errors = read_database(getc_callback, db_cookie); @@ -145,7 +147,7 @@ main_method(int argc, char *argv[]) */ #if defined(MERGE_INCLUDE_FILES) this->set_cookie((std::ifstream *)input_cookie); - errors = run_simulations(istream_getc, input_cookie); + errors = run_simulations(PHRQ_io::istream_getc, input_cookie); this->clear_cookie(); #else errors = run_simulations(getc_callback, input_cookie); From aba479648c23eb65ebf901c2f1bc64609e2bd1e3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Sep 2011 22:05:32 +0000 Subject: [PATCH 0241/1077] Added file_on variables to PHRQ_io. Set dump, log, and punch file_on variables whereever pr.dump, pr.log, and pr.punch were set in PHREEQC. Added base class to Solution, ISolution, and StorageBin. Required a PHRQ_io in the constructor to find all places they were constructed. Need to do the same to all other classes (Exchange, Surface, NameDouble, etc.) Then need to take PHREEQC instance out of parser and fix all places a parser is constructed. Need to move phreeqc2class constructors to phreeqc. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5628 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 9 +- ISolution.h | 4 +- PHRQ_io.cpp | 328 ++++--------------------------------------------- PHRQ_io.h | 48 +++++++- Phreeqc.cpp | 2 +- ReadClass.cxx | 10 +- Solution.cxx | 18 +-- Solution.h | 17 +-- StorageBin.cxx | 22 ++-- StorageBin.h | 8 +- 10 files changed, 120 insertions(+), 346 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 0cdb319a..10891553 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -30,7 +30,9 @@ extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); //static std::map ss_map; //std::map& cxxISolution::s_map = ss_map; -cxxISolution::cxxISolution(): +cxxISolution::cxxISolution(PHRQ_io *io) +: +cxxSolution(io), units("mMol/kgw") { density = 1.0; @@ -38,8 +40,9 @@ units("mMol/kgw") pes = NULL; } -cxxISolution::cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *solution_ptr): -cxxSolution(solution_ptr) +cxxISolution::cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *solution_ptr, PHRQ_io *io) +: +cxxSolution(solution_ptr, io) //, pe(cxxPe_Data::alloc()) { density = solution_ptr->density; diff --git a/ISolution.h b/ISolution.h index 686ce74e..2a3dae90 100644 --- a/ISolution.h +++ b/ISolution.h @@ -19,8 +19,8 @@ class cxxISolution:public cxxSolution { public: - cxxISolution(); - cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *); + cxxISolution(PHRQ_io *io); + cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *, PHRQ_io *io); //cxxISolution(const cxxISolution&); ~cxxISolution(); diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index c0927aea..33927319 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -18,6 +18,12 @@ PHRQ_io(void) error_file = NULL; /* OUTPUT_ERROR */ dump_file = NULL; /* OUTPUT_DUMP */ int error_count = 0; + + output_file_on = true; + log_file_on = false; + punch_file_on = true; + error_file_on = true; + dump_file_on = true; } PHRQ_io:: @@ -108,261 +114,6 @@ close_input_files(void) return (i); } -///* ---------------------------------------------------------------------- */ -//int PHRQ_io:: -//process_file_names(int argc, char *argv[], void **db_cookie, -// void **input_cookie, int log) -///* ---------------------------------------------------------------------- */ -//{ -// int l; -// char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; -// char query[2 * MAX_LENGTH]; -// char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; -// char *env_ptr; -// char *ptr; -// int errors; -// ENTRY item, *found_item; -// -///* -// * Prepare error handling -// */ -// errors = setjmp(mark); -// if (errors != 0) -// { -// return errors; -// } -// -///* -// * Prep for get_line -// */ -// max_line = MAX_LINE; -// space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); -// space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); -// hcreate_multi(5, &strings_hash_table); -// hcreate_multi(2, &keyword_hash_table); -// -///* -// * Initialize hash table -// */ -// keyword_hash = (struct key *) PHRQ_malloc(sizeof(struct key)); -// if (keyword_hash == NULL) -// { -// malloc_error(); -// } -// else -// { -// keyword_hash->name = string_hsave("database"); -// keyword_hash->keycount = 0; -// item.key = keyword_hash->name; -// item.data = keyword_hash; -// found_item = hsearch_multi(keyword_hash_table, item, ENTER); -// if (found_item == NULL) -// { -// sprintf(error_string, -// "Hash table error in keyword initialization."); -// error_msg(error_string, STOP); -// } -// } -// -// -///* -// * Open file for screen output -// */ -// if (argc > 4) -// { -// error_file = fopen(argv[4], "w"); -// if (error_file == NULL) -// { -//#ifdef PHREEQ98 -// error_file = NULL; /* We can not use stderr in BCB: this causes unexpected behaviour when reopening the input_file... */ -//#else -// error_file = stderr; -//#endif -// sprintf(error_string, "Error opening file, %s.", argv[4]); -// warning_msg(error_string); -// } -// } -// else -// { -//#ifdef PHREEQ98 -// error_file = NULL; /* We can not use stderr in BCB: this causes unexpected behaviour when reopening the input_file... */ -//#else -// error_file = stderr; -//#endif -// } -// -///* -// * Open user-input file -// */ -// strcpy(query, "Name of input file?"); -// if (argc <= 1) -// { -// default_name[0] = '\0'; -// input_file = file_open(query, default_name, "r", FALSE); -// } -// else -// { -// strcpy(default_name, argv[1]); -// input_file = file_open(query, default_name, "r", TRUE); -// } -// output_msg(OUTPUT_SCREEN, "Input file: %s\n\n", default_name); -// output_msg(OUTPUT_SEND_MESSAGE, "Input file: %s\r\n\r\n", default_name); -// strcpy(in_file, default_name); -///* -// * Open file for output -// */ -// strcpy(query, "Name of output file?"); -// -// ptr = default_name; -// copy_token(token, &ptr, &l); -// strcat(token, ".out"); -// if (argc <= 1) -// { -// output_file = file_open(query, token, "w", FALSE); -// } -// else if (argc == 2) -// { -// output_file = file_open(query, token, "w", TRUE); -// } -// else if (argc >= 3) -// { -// strcpy(token, argv[2]); -// output_file = file_open(query, token, "w", TRUE); -// } -// output_msg(OUTPUT_SCREEN, "Output file: %s\n\n", token); -// output_msg(OUTPUT_SEND_MESSAGE, "Output file: %s\r\n\r\n", token); -// strcpy(out_file, token); -///* -// * Open file for errors -// */ -// if (log == TRUE) -// { -//#ifdef PHREEQ98 -// if ((log_file = fopen(LogFileNameC, "w")) == NULL) -// { -//#else /* PHREEQ98 */ -// if ((log_file = fopen("phreeqc.log", "w")) == NULL) -// { -//#endif /* PHREEQ98 */ -// error_msg("Can't open log file, phreeqc.log.", STOP); -// } -// } -// /* -// * Read input file for DATABASE keyword -// */ -// std::ifstream * temp_input = new std::ifstream(in_file, std::ifstream::in); -// this->set_cookie(temp_input); -// if (get_line(istream_getc, temp_input) == KEYWORD) -// { -// ptr = line; -// copy_token(token, &ptr, &l); -// if (strcmp_nocase(token, "database") == 0) -// { -//#ifdef PHREEQ98 -// user_database = string_duplicate(prefix_database_dir(ptr)); -//#else -// user_database = string_duplicate(ptr); -//#endif -// if (string_trim(user_database) == EMPTY) -// { -// warning_msg -// ("DATABASE file name is missing; default database will be used."); -// user_database = (char *) free_check_null(user_database); -// } -// } -// } -// fclose(input_file); -// this->pop_cookie(); -// -// if ((input_file = fopen(in_file, "r")) == NULL) -// {; -// error_msg("Can't reopen input file.", STOP); -// } -///* -// * Open data base -// */ -// strcpy(query, "Name of database file?"); -// env_ptr = getenv("PHREEQC_DATABASE"); -// if (user_database != NULL) -// { -// strcpy(token, user_database); -// } -// else if (env_ptr != NULL) -// { -// strcpy(token, env_ptr); -// } -// else -// { -// strcpy(token, default_data_base); -// } -// if (argc <= 1) -// { -// database_file = file_open(query, token, "r", FALSE); -// } -// else if (argc < 4) -// { -// database_file = file_open(query, token, "r", TRUE); -// } -// else if (argc >= 4) -// { -// if (user_database == NULL) -// { -// strcpy(token, argv[3]); -// } -// else -// { -//#ifndef PHREEQCI_GUI -// warning_msg -// ("Database file from DATABASE keyword is used; command line argument ignored."); -//#endif -// } -// database_file = file_open(query, token, "r", TRUE); -// } -// output_msg(OUTPUT_SCREEN, "Database file: %s\n\n", token); -// output_msg(OUTPUT_SEND_MESSAGE, "Database file: %s\r\n\r\n", token); -// strcpy(db_file, token); -// -// output_msg(OUTPUT_MESSAGE, " Input file: %s\n", in_file); -// output_msg(OUTPUT_MESSAGE, " Output file: %s\n", out_file); -// output_msg(OUTPUT_MESSAGE, "Database file: %s\n\n", token); -///* -// * local cleanup -// */ -// user_database = (char *) free_check_null(user_database); -// line = (char *) free_check_null(line); -// line_save = (char *) free_check_null(line_save); -// -// hdestroy_multi(keyword_hash_table); -// keyword_hash = (struct key *) free_check_null(keyword_hash); -// keyword_hash_table = NULL; -// -// free_hash_strings(strings_hash_table); -// hdestroy_multi(strings_hash_table); -// strings_hash_table = NULL; -// -// *db_cookie = database_file; -// *input_cookie = input_file; -// -// this->db_stream = new std::ifstream(db_file, std::ifstream::in); -// this->in_stream = new std::ifstream(in_file, std::ifstream::in); -// *db_cookie = db_stream; -// *input_cookie = in_stream; -// -// return 0; -//} - -///* ---------------------------------------------------------------------- */ -//int PHRQ_io:: -//getc_callback(void *cookie) -///* ---------------------------------------------------------------------- */ -//{ -// int i; -// assert(cookie); -// i = getc((FILE *) cookie); -// -// return i; -//} - //istream_getc is static *** int PHRQ_io:: istream_getc(void *cookie) @@ -449,9 +200,9 @@ output_handler(const int type, const char *err_str, const bool stop, #endif fflush(output_file); } -//#if defined MULTICHART -// chart_handler.End_timer(PHREEQC_THIS); -//#endif +////#if defined MULTICHART +//// chart_handler.End_timer(PHREEQC_THIS); +////#endif } break; @@ -768,53 +519,16 @@ rewind_wrapper(FILE * file_ptr) //return (OK); return 1; } -//#if defined(MERGE_INCLUDE_FILES) -///* ---------------------------------------------------------------------- */ -//bool PHRQ_io:: -//recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream) -///* ---------------------------------------------------------------------- */ -//{ -// std::string myline; -// -// // input_file should be opened before calling recursive_include -// assert(input_stream.is_open()); -// -// while (std::getline(input_stream, myline)) -// { -// accumulated_stream << myline << std::endl; -// -// std::string copy_line = myline; -// // remove leading spaces -// copy_line.erase(0, copy_line.find_first_not_of(" \t") ); -// // get first 8 characters -// std::string token = copy_line.substr(0,9); -// // convert to lower case -// std::transform(token.begin(), token.end(), token.begin(), -// (int(*)(int)) std::tolower); -// // check for #include file_name -// if (token == "#$include") -// { -// // get file name without trailing spaces -// token = copy_line.substr(10, copy_line.length()); -// token.erase(0, token.find_first_not_of(" \t")); -// // remove leading, trailing spaces -// token = token.substr(0, token.find_last_not_of(" \t\n\0") + 1); -// // open stream -// std::ifstream next_stream(token.c_str(), std::ifstream::in); -// if (next_stream.is_open()) -// { -// recursive_include(next_stream, accumulated_stream); -// accumulated_stream << "#Done include " << token << std::endl; -// } -// else -// { -// // error opening file -// sprintf(error_string, "Could not open include file %s", token.c_str()); -// error_msg(error_string, STOP); -// } -// } -// } -// return true; -//} -//#endif /* defined(MERGE_INCLUDE_FILES) */ +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +safe_close(FILE * file_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (file_ptr != stderr && + file_ptr != stdout && + file_ptr != stdin) + { + fclose(file_ptr); + } +} diff --git a/PHRQ_io.h b/PHRQ_io.h index e43f8e90..ebeb5770 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -48,7 +48,7 @@ typedef enum const bool stop, const char *format, va_list args); static int rewind_wrapper(FILE * file_ptr); - + static void safe_close(FILE * file_ptr); int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); @@ -97,6 +97,46 @@ typedef enum fclose(input_file); } } + void Set_output_file_on(bool tf) + { + this->output_file_on = tf; + } + void Set_log_file_on(bool tf) + { + this->log_file_on = tf; + } + void Set_punch_file_on(bool tf) + { + this->punch_file_on = tf; + } + void Set_error_file_on(bool tf) + { + this->error_file_on = tf; + } + void Set_dump_file_on(bool tf) + { + this->dump_file_on = tf; + } + bool Get_output_file_on(void) + { + return this->output_file_on; + } + bool Get_log_file_on(void) + { + return this->log_file_on; + } + bool Get_punch_file_on(void) + { + return this->punch_file_on; + } + bool Get_error_file_on(void) + { + return this->error_file_on; + } + bool Get_dump_file_on(void) + { + return this->dump_file_on; + } // data private: FILE *input_file; @@ -107,6 +147,12 @@ private: FILE *error_file; /* OUTPUT_ERROR */ FILE *dump_file; /* OUTPUT_DUMP */ int error_count; + + bool output_file_on; + bool log_file_on; + bool punch_file_on; + bool error_file_on; + bool dump_file_on; }; #endif /* _PHRQIO_H */ diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 794ce5f3..695f069b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -455,7 +455,7 @@ size_t Phreeqc::list_components(std::list &list_c) // solutions for (i = 0; i < count_solution; i++) { - cxxSolution entity(solution[i]); + cxxSolution entity(solution[i], &this->phrq_io); accumulator.add_extensive(entity.get_totals(), 1.0); } diff --git a/ReadClass.cxx b/ReadClass.cxx index 8a70cde2..ef7fc431 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -110,7 +110,7 @@ read_solution_raw(void) parser.get_option(vopts, next_char); - cxxSolution sol; + cxxSolution sol(&this->phrq_io); sol.read_raw(PHREEQC_THIS_COMMA parser); struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); int n; @@ -1319,14 +1319,14 @@ read_solution_modify(void) return (ERROR); } - cxxSolution sol(solution[n]); + cxxSolution sol(solution[n], &this->phrq_io); // Clear activities so we can know what was read sol.clear_master_activity(); sol.read_raw(PHREEQC_THIS_COMMA parser, false); - cxxSolution orig(solution[n]); + cxxSolution orig(solution[n], &this->phrq_io ); sol.modify_activities(PHREEQC_THIS_COMMA orig); @@ -2680,7 +2680,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_solution; i++) { - cxxSolution cxxsoln(solution[i]); + cxxSolution cxxsoln(solution[i], &this->phrq_io); cxxsoln.dump_raw(os,0); } } @@ -2691,7 +2691,7 @@ dump_ostream(std::ostream& os) { if (solution_bsearch(*it, &n, FALSE) != NULL) { - cxxSolution cxxsoln(solution[n]); + cxxSolution cxxsoln(solution[n], &this->phrq_io); cxxsoln.dump_raw(os,0); } } diff --git a/Solution.cxx b/Solution.cxx index 7e5d08e2..28d20ab8 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -32,11 +32,12 @@ ////////////////////////////////////////////////////////////////////// -cxxSolution::cxxSolution() +cxxSolution::cxxSolution(PHRQ_io * io) // // default constructor for cxxSolution // -: cxxNumKeyword() +: cxxNumKeyword(), + PHRQ_base(io) { this->tc = 25.0; this->ph = 7.0; @@ -53,12 +54,13 @@ cxxSolution::cxxSolution() this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; } -cxxSolution::cxxSolution(struct solution * solution_ptr) +cxxSolution::cxxSolution(struct solution * solution_ptr, PHRQ_io * io) // // constructor for cxxSolution from struct solution // : cxxNumKeyword(), +PHRQ_base(io), totals(solution_ptr->totals), master_activity(solution_ptr->master_activity, solution_ptr->count_master_activity, @@ -96,12 +98,13 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solutions, - cxxMix & mix, int l_n_user) + cxxMix & mix, int l_n_user, PHRQ_io * io) // // constructor for cxxSolution from mixture of solutions // : -cxxNumKeyword() +cxxNumKeyword(), +PHRQ_base(io) { // @@ -133,13 +136,14 @@ cxxNumKeyword() } } -cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user) +cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io * io) // // constructor for cxxSolution from results of calculation // does not work in phast because phast uses only the total molalities // of elements in buffer, not individual redox states. : -cxxNumKeyword() +cxxNumKeyword(), +PHRQ_base(io) { //this->set_description none; diff --git a/Solution.h b/Solution.h index eb16c6f5..f519590b 100644 --- a/Solution.h +++ b/Solution.h @@ -6,22 +6,23 @@ #include // std::string #include // std::vector #include -#include "Phreeqc_class.h" #include "NumKeyword.h" #include "SolutionIsotopeList.h" #include "NameDouble.h" +#include "PHRQ_base.h" +#include "PHRQ_io.h" class cxxMix; -class cxxSolution:public cxxNumKeyword +class cxxSolution:public cxxNumKeyword, public PHRQ_base { public: - cxxSolution(); - cxxSolution(struct solution *); - cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user); - cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solution_map, - cxxMix & mx, int n_user); - ~cxxSolution(); + cxxSolution(PHRQ_io *io=NULL); + cxxSolution(struct solution *, PHRQ_io *io); + cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io); + cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solution_map, + cxxMix & mx, int n_user, PHRQ_io *io); + ~cxxSolution(); //static cxxSolution& read(CParser& parser); diff --git a/StorageBin.cxx b/StorageBin.cxx index 206db92b..6c2a4e19 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -41,7 +41,9 @@ ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxStorageBin::cxxStorageBin() +cxxStorageBin::cxxStorageBin(PHRQ_io *io) +: +PHRQ_base(io) { // default constructor for cxxStorageBin } @@ -114,7 +116,9 @@ cxxStorageBin::cxxStorageBin(struct Use *use_ptr) this->setSystem(use_ptr); } #endif -cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr) +cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io * io) +: +PHRQ_base(io) { //Construct from use pointer @@ -134,7 +138,7 @@ cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr) struct solution *struct_entity1 = P_INSTANCE_POINTER solution_bsearch(it->first, &n, FALSE); if (struct_entity1 != NULL) { - cxxSolution entity1(struct_entity1); + cxxSolution entity1(struct_entity1, this->Get_io()); this->setSolution(it->first, &entity1); } } @@ -145,7 +149,7 @@ cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr) struct solution *struct_entity = P_INSTANCE_POINTER solution_bsearch(use_ptr->n_solution_user, &n, FALSE); if (struct_entity != NULL) { - cxxSolution entity(struct_entity); + cxxSolution entity(struct_entity, this->Get_io()); this->setSolution(use_ptr->n_solution_user, &entity); } } @@ -507,7 +511,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Solutions for (i = 0; i < P_INSTANCE_POINTER count_solution; i++) { - Solutions[P_INSTANCE_POINTER solution[i]->n_user] = cxxSolution(P_INSTANCE_POINTER solution[i]); + Solutions[P_INSTANCE_POINTER solution[i]->n_user] = cxxSolution(P_INSTANCE_POINTER solution[i], this->Get_io()); } // Exchangers @@ -728,7 +732,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) */ case CParser::KT_SOLUTION_RAW: { - cxxSolution entity; + cxxSolution entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Solutions[entity.get_n_user()] = entity; } @@ -839,7 +843,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) */ case CParser::KT_SOLUTION_RAW: { - cxxSolution entity; + cxxSolution entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Solutions[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -935,7 +939,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->solution != NULL) { this->Solutions[system_ptr->solution->n_user] = - cxxSolution(system_ptr->solution); + cxxSolution(system_ptr->solution, this->Get_io()); } // Exchangers @@ -1107,7 +1111,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) // Solutions { P_INSTANCE_POINTER solution_bsearch(n, &pos, TRUE); - this->Solutions[n] = cxxSolution(P_INSTANCE_POINTER solution[pos]); + this->Solutions[n] = cxxSolution(P_INSTANCE_POINTER solution[pos], this->Get_io()); } // Exchangers diff --git a/StorageBin.h b/StorageBin.h index 62a7d16a..3e2d90b0 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -7,6 +7,8 @@ #include // std::vector #include "System.h" +#include "PHRQ_io.h" +#include "PHRQ_base.h" class cxxSolution; class cxxExchange; class cxxGasPhase; @@ -17,13 +19,13 @@ class cxxSurface; class cxxReaction; class cxxTemperature; -class cxxStorageBin +class cxxStorageBin: public PHRQ_base { public: - cxxStorageBin(); + cxxStorageBin(PHRQ_io *io); //cxxStorageBin(struct Use *use_ptr); - cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr); + cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io); ~cxxStorageBin(); void import_phreeqc(PHREEQC_PTR_ARG); From f6ed50af7e09e5ef397fe3ac506ccb18f3b66277 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Sep 2011 22:32:09 +0000 Subject: [PATCH 0242/1077] Added base to kinetics, mix, and exchange. Going in alphabetical order in src. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5629 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 20 ++++++++++++-------- Exchange.h | 11 ++++++----- Phreeqc.cpp | 4 ++-- ReadClass.cxx | 22 +++++++++++----------- StorageBin.cxx | 28 ++++++++++++++-------------- cxxKinetics.cxx | 14 +++++++++----- cxxKinetics.h | 9 +++++---- cxxMix.cxx | 10 ++++++---- cxxMix.h | 7 ++++--- 9 files changed, 69 insertions(+), 56 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 63d3baca..d4d89f65 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -25,21 +25,23 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxExchange::cxxExchange() +cxxExchange::cxxExchange(PHRQ_io *io) // // default constructor for cxxExchange // -: cxxNumKeyword() +: cxxNumKeyword(), +PHRQ_base(io) { pitzer_exchange_gammas = true; } -cxxExchange::cxxExchange(struct exchange * exchange_ptr) +cxxExchange::cxxExchange(struct exchange * exchange_ptr, PHRQ_io *io) // // constructor for cxxExchange from struct exchange // : -cxxNumKeyword() +cxxNumKeyword(), +PHRQ_base(io) { int i; @@ -59,8 +61,9 @@ cxxNumKeyword() } cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, - cxxMix & mix, int l_n_user): -cxxNumKeyword() + cxxMix & mix, int l_n_user, PHRQ_io *io): +cxxNumKeyword(), +PHRQ_base(io) { this->n_user = this->n_user_end = l_n_user; this->pitzer_exchange_gammas = true; @@ -92,7 +95,7 @@ cxxNumKeyword() } } -cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user) +cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io *io) // // constructor for cxxExchange from reaction calculation // equivalent of xexchange_save @@ -100,7 +103,8 @@ cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user) // bool pitzer_exchange_gammas; // cxxNameDouble totals; : -cxxNumKeyword() +cxxNumKeyword(), +PHRQ_base(io) { int i; diff --git a/Exchange.h b/Exchange.h index 3c47415f..ca333b5a 100644 --- a/Exchange.h +++ b/Exchange.h @@ -8,17 +8,18 @@ #include "NumKeyword.h" #include "ExchComp.h" #include "NameDouble.h" +#include "PHRQ_base.h" class cxxMix; -class cxxExchange:public cxxNumKeyword +class cxxExchange:public cxxNumKeyword, PHRQ_base { public: - cxxExchange(); - cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user); - cxxExchange(struct exchange *); + cxxExchange(PHRQ_io *io=NULL); + cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io); + cxxExchange(struct exchange *, PHRQ_io *io); cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &exchange_map, - cxxMix & mx, int n_user); + cxxMix & mx, int n_user, PHRQ_io *io); ~cxxExchange(); struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 695f069b..b2e7f25c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -478,7 +478,7 @@ size_t Phreeqc::list_components(std::list &list_c) // exchangers for (i = 0; i < count_exchange; i++) { - cxxExchange entity(&exchange[i]); + cxxExchange entity(&exchange[i], &this->phrq_io); entity.totalize(); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -511,7 +511,7 @@ size_t Phreeqc::list_components(std::list &list_c) for (i = 0; i < count_kinetics; i++) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i]); + cxxKinetics entity(&kinetics[i], &this->phrq_io); accumulator.add_extensive(entity.get_totals(), 1.0); } diff --git a/ReadClass.cxx b/ReadClass.cxx index ef7fc431..05a7a7ac 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -202,7 +202,7 @@ read_exchange_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxExchange ex; + cxxExchange ex(&this->phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); int n; @@ -487,7 +487,7 @@ read_kinetics_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxKinetics ex; + cxxKinetics ex(&this->phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); int n; @@ -868,7 +868,7 @@ read_mix_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxMix ex; + cxxMix ex(&this->phrq_io); ex.read_raw(parser); struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); int n; @@ -1510,7 +1510,7 @@ read_exchange_modify(void) } // read entity - cxxExchange entity(&(exchange[n])); + cxxExchange entity(&(exchange[n]), &this->phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1883,7 +1883,7 @@ read_kinetics_modify(void) } // read entity - cxxKinetics entity(&(kinetics[n])); + cxxKinetics entity(&(kinetics[n]), &this->phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -2731,7 +2731,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_exchange; i++) { - cxxExchange cxxentity(&exchange[i]); + cxxExchange cxxentity(&exchange[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2743,7 +2743,7 @@ dump_ostream(std::ostream& os) if (exchange_bsearch(*it, &n) != NULL) { - cxxExchange cxxentity(&exchange[n]); + cxxExchange cxxentity(&exchange[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2835,7 +2835,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_kinetics; i++) { - cxxKinetics cxxentity(&kinetics[i]); + cxxKinetics cxxentity(&kinetics[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2847,7 +2847,7 @@ dump_ostream(std::ostream& os) if (kinetics_bsearch(*it, &n) != NULL) { - cxxKinetics cxxentity(&kinetics[n]); + cxxKinetics cxxentity(&kinetics[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2861,7 +2861,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_mix; i++) { - cxxMix cxxentity(&mix[i]); + cxxMix cxxentity(&mix[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2873,7 +2873,7 @@ dump_ostream(std::ostream& os) if (mix_bsearch(*it, &n) != NULL) { - cxxMix cxxentity(&mix[n]); + cxxMix cxxentity(&mix[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } diff --git a/StorageBin.cxx b/StorageBin.cxx index 6c2a4e19..30609905 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -128,7 +128,7 @@ PHRQ_base(io) struct mix *struct_entity = P_INSTANCE_POINTER mix_bsearch(use_ptr->n_mix_user, &n); if (struct_entity != NULL) { - cxxMix entity(struct_entity); + cxxMix entity(struct_entity, this->Get_io()); this->setMix(use_ptr->n_mix_user, &entity); std::map c = *(this->getMix(use_ptr->n_mix_user)->comps()); @@ -167,7 +167,7 @@ PHRQ_base(io) struct exchange *struct_entity = P_INSTANCE_POINTER exchange_bsearch(use_ptr->n_exchange_user, &n); if (struct_entity != NULL) { - cxxExchange entity(struct_entity); + cxxExchange entity(struct_entity, this->Get_io()); this->setExchange(use_ptr->n_exchange_user, &entity); } } @@ -203,7 +203,7 @@ PHRQ_base(io) struct kinetics *struct_entity = P_INSTANCE_POINTER kinetics_bsearch(use_ptr->n_kinetics_user, &n); if (struct_entity != NULL) { - cxxKinetics entity(struct_entity); + cxxKinetics entity(struct_entity, this->Get_io()); this->setKinetics(use_ptr->n_kinetics_user, &entity); } } @@ -517,7 +517,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Exchangers for (i = 0; i < P_INSTANCE_POINTER count_exchange; i++) { - Exchangers[P_INSTANCE_POINTER exchange[i].n_user] = cxxExchange(&P_INSTANCE_POINTER exchange[i]); + Exchangers[P_INSTANCE_POINTER exchange[i].n_user] = cxxExchange(&P_INSTANCE_POINTER exchange[i], this->Get_io()); } // GasPhases @@ -529,7 +529,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Kinetics for (i = 0; i < P_INSTANCE_POINTER count_kinetics; i++) { - Kinetics[P_INSTANCE_POINTER kinetics[i].n_user] = cxxKinetics(&P_INSTANCE_POINTER kinetics[i]); + Kinetics[P_INSTANCE_POINTER kinetics[i].n_user] = cxxKinetics(&P_INSTANCE_POINTER kinetics[i], this->Get_io()); } // PPassemblages @@ -555,7 +555,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Mixes for (i = 0; i < P_INSTANCE_POINTER count_mix; i++) { - Mixes[P_INSTANCE_POINTER mix[i].n_user] = cxxMix(&P_INSTANCE_POINTER mix[i]); + Mixes[P_INSTANCE_POINTER mix[i].n_user] = cxxMix(&P_INSTANCE_POINTER mix[i], this->Get_io()); } // Reactions @@ -740,7 +740,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_EXCHANGE_RAW: { - cxxExchange entity; + cxxExchange entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Exchangers[entity.get_n_user()] = entity; } @@ -756,7 +756,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_KINETICS_RAW: { - cxxKinetics entity; + cxxKinetics entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Kinetics[entity.get_n_user()] = entity; } @@ -852,7 +852,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_EXCHANGE_RAW: { - cxxExchange entity; + cxxExchange entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Exchangers[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -870,7 +870,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_KINETICS_RAW: { - cxxKinetics entity; + cxxKinetics entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Kinetics[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -946,7 +946,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->exchange != NULL) { this->Exchangers[system_ptr->exchange->n_user] = - cxxExchange(system_ptr->exchange); + cxxExchange(system_ptr->exchange, this->Get_io()); } // GasPhases @@ -960,7 +960,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->kinetics != NULL) { this->Kinetics[system_ptr->kinetics->n_user] = - cxxKinetics(system_ptr->kinetics); + cxxKinetics(system_ptr->kinetics, this->Get_io()); } // PPassemblages @@ -1118,7 +1118,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) { if (P_INSTANCE_POINTER exchange_bsearch(n, &pos) != NULL) { - this->Exchangers[n] = cxxExchange(&(P_INSTANCE_POINTER exchange[pos])); + this->Exchangers[n] = cxxExchange(&(P_INSTANCE_POINTER exchange[pos]), this->Get_io()); } } @@ -1134,7 +1134,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) { if (P_INSTANCE_POINTER kinetics_bsearch(n, &pos) != NULL) { - this->Kinetics[n] = cxxKinetics(&(P_INSTANCE_POINTER kinetics[pos])); + this->Kinetics[n] = cxxKinetics(&(P_INSTANCE_POINTER kinetics[pos]), this->Get_io()); } } diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 1b42cb7c..b44bcc5a 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -20,17 +20,19 @@ #include "phqalloc.h" #include "phrqproto.h" +#include "PHRQ_io.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxKinetics::cxxKinetics() +cxxKinetics::cxxKinetics(PHRQ_io *io) // // default constructor for cxxKinetics // -: cxxNumKeyword() +: cxxNumKeyword(), + PHRQ_base(io) { step_divide = 1.0; rk = 3; @@ -42,12 +44,13 @@ cxxKinetics::cxxKinetics() equal_steps = 0; } -cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr) +cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr, PHRQ_io *io) // // constructor for cxxKinetics from struct kinetics // : cxxNumKeyword(), +PHRQ_base(io), totals(kinetics_ptr->totals) { int i; @@ -85,8 +88,9 @@ totals(kinetics_ptr->totals) } } cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, - cxxMix & mix, int l_n_user): -cxxNumKeyword() + cxxMix & mix, int l_n_user, PHRQ_io *io): +cxxNumKeyword(), +PHRQ_base(io) { this->n_user = this->n_user_end = l_n_user; step_divide = 1.0; diff --git a/cxxKinetics.h b/cxxKinetics.h index be28b7ca..b5a1cdb4 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -9,16 +9,17 @@ #include "NumKeyword.h" #include "KineticsComp.h" +#include "PHRQ_base.h" class cxxMix; -class cxxKinetics:public cxxNumKeyword +class cxxKinetics:public cxxNumKeyword, PHRQ_base { public: - cxxKinetics(); - cxxKinetics(struct kinetics *); + cxxKinetics(PHRQ_io *io = NULL); + cxxKinetics(struct kinetics *, PHRQ_io *io); cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, - int n_user); + int n_user, PHRQ_io *io); ~cxxKinetics(); struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); diff --git a/cxxMix.cxx b/cxxMix.cxx index 473ba2fa..85deaa00 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -24,20 +24,22 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxMix::cxxMix() +cxxMix::cxxMix(PHRQ_io *io) // // default constructor for cxxMix // -: cxxNumKeyword() +: cxxNumKeyword(), + PHRQ_base(io) { } -cxxMix::cxxMix(struct mix *mix_ptr) +cxxMix::cxxMix(struct mix *mix_ptr, PHRQ_io *io) // // constructor for cxxMix from struct mix // : -cxxNumKeyword() +cxxNumKeyword(), +PHRQ_base(io) { int i; diff --git a/cxxMix.h b/cxxMix.h index 7660209d..8a6acd48 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -8,13 +8,14 @@ #include // std::vector #include "Phreeqc_class.h" #include "NumKeyword.h" +#include "PHRQ_base.h" -class cxxMix:public cxxNumKeyword +class cxxMix:public cxxNumKeyword, PHRQ_base { public: - cxxMix(); - cxxMix(struct mix *); + cxxMix(PHRQ_io *io=NULL); + cxxMix(struct mix *, PHRQ_io *io); ~cxxMix(); struct mix *cxxMix2mix(PHREEQC_PTR_ARG); From 7eeeab456967928c1366651d06ef279b296cfac0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Sep 2011 20:05:43 +0000 Subject: [PATCH 0243/1077] all classes inherit from PHRQ_base, except NameDouble, StorageBinListItem. NumKeyword inherits from PHRQ_base, others inherit NumKeyword. ChartHandler and ChartObject inherit from PHRQ_base. CurveObject does not inherit from PHRQ_base. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5637 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 6 ++-- ChartHandler.h | 5 +-- ChartObject.cpp | 6 ++-- ChartObject.h | 4 +-- ExchComp.cxx | 6 ++-- ExchComp.h | 6 ++-- Exchange.cxx | 22 +++++------- Exchange.h | 8 ++--- GasPhase.cxx | 12 +++---- GasPhase.h | 6 ++-- ISolution.cxx | 2 +- ISolution.h | 4 +-- ISolutionComp.cxx | 17 ++++++--- ISolutionComp.h | 8 ++--- KineticsComp.cxx | 7 ++-- KineticsComp.h | 6 ++-- NumKeyword.cxx | 3 +- NumKeyword.h | 5 +-- PPassemblage.cxx | 20 +++++------ PPassemblage.h | 6 ++-- PPassemblageComp.cxx | 8 +++-- PPassemblageComp.h | 6 ++-- Parser.cxx | 20 +++++++++-- Parser.h | 9 ++--- Phreeqc.cpp | 9 +++-- Reaction.cxx | 9 +++-- Reaction.h | 4 +-- ReadClass.cxx | 80 ++++++++++++++++++++--------------------- SSassemblage.cxx | 20 +++++------ SSassemblage.h | 6 ++-- SSassemblageSS.cxx | 9 +++-- SSassemblageSS.h | 6 ++-- Solution.cxx | 27 +++++++------- Solution.h | 8 ++--- SolutionIsotope.cxx | 8 +++-- SolutionIsotope.h | 8 ++--- SolutionIsotopeList.cxx | 28 ++++++++------- SolutionIsotopeList.h | 6 ++-- StorageBin.cxx | 46 ++++++++++++------------ StorageBin.h | 4 +-- StorageBinList.cpp | 11 ++++-- StorageBinList.h | 8 ++--- Surface.cxx | 28 +++++++-------- Surface.h | 6 ++-- SurfaceCharge.cxx | 7 ++-- SurfaceCharge.h | 7 ++-- SurfaceComp.cxx | 7 ++-- SurfaceComp.h | 6 ++-- System.cxx | 4 ++- System.h | 5 +-- Temperature.cxx | 8 ++--- Temperature.h | 6 ++-- cxxKinetics.cxx | 17 ++++----- cxxKinetics.h | 8 ++--- cxxMix.cxx | 6 ++-- cxxMix.h | 4 +-- dumper.cpp | 8 +++-- dumper.h | 6 ++-- runner.cpp | 8 +++-- runner.h | 7 ++-- 60 files changed, 358 insertions(+), 289 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 36264e90..2830fb26 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -20,7 +20,9 @@ extern int error_msg(const char *err_str, const int stop, ...); // Construction/Destruction ////////////////////////////////////////////////////////////////////// -ChartHandler::ChartHandler() +ChartHandler::ChartHandler(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for ChartHandler // @@ -78,7 +80,7 @@ ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) std::map::iterator it = this->chart_map.find(n_user); if (it == this->chart_map.end()) { - chart_map[n_user] = new ChartObject(); + chart_map[n_user] = new ChartObject(this->Get_io()); it = this->chart_map.find(n_user); #ifdef PHREEQC_CLASS it->second->Set_phreeqc(P_INSTANCE); diff --git a/ChartHandler.h b/ChartHandler.h index 14bca879..8b81b215 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -6,12 +6,13 @@ #include #include "Parser.h" #include "ChartObject.h" +#include "PHRQ_base.h" -class ChartHandler +class ChartHandler: public PHRQ_base { public: - ChartHandler(); + ChartHandler(PHRQ_io *io = NULL); ~ChartHandler(); size_t Get_chart_count() diff --git a/ChartObject.cpp b/ChartObject.cpp index ac12b69a..0c2c7b25 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -33,10 +33,12 @@ using namespace zdg_ui2; // Construction/Destruction ////////////////////////////////////////////////////////////////////// -ChartObject::ChartObject() +ChartObject::ChartObject(PHRQ_io *io) // // default constructor for cxxExchComp // + : +cxxNumKeyword(io) { new_ug = false; FirstCallToUSER_GRAPH = true; @@ -478,7 +480,7 @@ ChartObject::OpenCSVFile(std::string file_name) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(P_INSTANCE_COMMA f_csv, oss_out, oss_err); + CParser parser(P_INSTANCE_COMMA f_csv, oss_out, oss_err, this->Get_io()); parser.set_echo_file(CParser::EO_NONE); /* Get lines */ diff --git a/ChartObject.h b/ChartObject.h index 99d64554..7eddaff9 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -20,8 +20,8 @@ class ChartObject:public cxxNumKeyword { public: - ChartObject(); - ChartObject(int i); + ChartObject(PHRQ_io *io=NULL); + ChartObject(int i, PHRQ_io *io=NULL); ~ChartObject(); // new_ug diff --git a/ExchComp.cxx b/ExchComp.cxx index 08caba6a..c41a1f64 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -27,10 +27,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxExchComp::cxxExchComp() +cxxExchComp::cxxExchComp(PHRQ_io *io) // // default constructor for cxxExchComp // + : PHRQ_base(io) { moles = 0.0; formula_totals.type = cxxNameDouble::ND_ELT_MOLES; @@ -43,11 +44,12 @@ cxxExchComp::cxxExchComp() formula_z = 0.0; } -cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr) +cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr, PHRQ_io *io) // // constructor for cxxExchComp from struct exch_comp // : +PHRQ_base(io), formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) { this->set_formula(exch_comp_ptr->formula); diff --git a/ExchComp.h b/ExchComp.h index c0d28193..30a7afcb 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -9,12 +9,12 @@ #include "NameDouble.h" -class cxxExchComp +class cxxExchComp: public PHRQ_base { public: - cxxExchComp(); - cxxExchComp(struct exch_comp *); + cxxExchComp(PHRQ_io *io=NULL); + cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); ~cxxExchComp(); struct master *get_master(PHREEQC_PTR_ARG); diff --git a/Exchange.cxx b/Exchange.cxx index d4d89f65..d6e7b590 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -29,8 +29,7 @@ cxxExchange::cxxExchange(PHRQ_io *io) // // default constructor for cxxExchange // -: cxxNumKeyword(), -PHRQ_base(io) +: cxxNumKeyword(io) { pitzer_exchange_gammas = true; } @@ -40,8 +39,7 @@ cxxExchange::cxxExchange(struct exchange * exchange_ptr, PHRQ_io *io) // constructor for cxxExchange from struct exchange // : -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io) { int i; @@ -51,7 +49,7 @@ PHRQ_base(io) pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); for (i = 0; i < exchange_ptr->count_comps; i++) { - cxxExchComp ec(&(exchange_ptr->comps[i])); + cxxExchComp ec(&(exchange_ptr->comps[i]), this->Get_io()); std::string str(ec.get_formula()); exchComps[str] = ec; } @@ -62,8 +60,7 @@ PHRQ_base(io) } cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; this->pitzer_exchange_gammas = true; @@ -103,8 +100,7 @@ cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io *io) // bool pitzer_exchange_gammas; // cxxNameDouble totals; : -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io) { int i; @@ -118,7 +114,7 @@ PHRQ_base(io) { if (P_INSTANCE_POINTER x[i]->type == EXCH) { - cxxExchComp ec; + cxxExchComp ec(this->Get_io()); //char * formula; ec.set_formula(P_INSTANCE_POINTER x[i]->exch_comp->formula); //double moles; @@ -363,7 +359,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 1: // component { - cxxExchComp ec; + cxxExchComp ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -396,7 +392,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) @@ -406,7 +402,7 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxExchComp ec1; + cxxExchComp ec1(this->Get_io()); ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_formula()); this->exchComps[str] = ec1; diff --git a/Exchange.h b/Exchange.h index ca333b5a..5224350a 100644 --- a/Exchange.h +++ b/Exchange.h @@ -11,15 +11,15 @@ #include "PHRQ_base.h" class cxxMix; -class cxxExchange:public cxxNumKeyword, PHRQ_base +class cxxExchange:public cxxNumKeyword { public: cxxExchange(PHRQ_io *io=NULL); - cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io); - cxxExchange(struct exchange *, PHRQ_io *io); + cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); + cxxExchange(struct exchange *, PHRQ_io *io=NULL); cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &exchange_map, - cxxMix & mx, int n_user, PHRQ_io *io); + cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); diff --git a/GasPhase.cxx b/GasPhase.cxx index ee43c1ba..0f2c4940 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -26,23 +26,23 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxGasPhase::cxxGasPhase() +cxxGasPhase::cxxGasPhase(PHRQ_io * io) // // default constructor for cxxGasPhase // -: cxxNumKeyword() +: cxxNumKeyword(io) { total_p = 0; volume = 0; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; } -cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr) +cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr, PHRQ_io * io) // // constructor for cxxGasPhase from struct gas_phase // : -cxxNumKeyword() +cxxNumKeyword(io) { int i; @@ -70,8 +70,8 @@ cxxNumKeyword() } } cxxGasPhase::cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entities, - cxxMix & mix, int l_n_user): -cxxNumKeyword() + cxxMix & mix, int l_n_user, PHRQ_io * io): +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; diff --git a/GasPhase.h b/GasPhase.h index 3aa5a430..2e4c6847 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -15,10 +15,10 @@ class cxxGasPhase:public cxxNumKeyword { public: - cxxGasPhase(); - cxxGasPhase(struct gas_phase *); + cxxGasPhase(PHRQ_io * io=NULL); + cxxGasPhase(struct gas_phase *, PHRQ_io * io=NULL); cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entity_map, - cxxMix & mx, int n_user); + cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxGasPhase(); enum GP_TYPE diff --git a/ISolution.cxx b/ISolution.cxx index 10891553..38533a17 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -50,7 +50,7 @@ cxxSolution(solution_ptr, io) // totals for (int i = 0; solution_ptr->totals[i].description != NULL; i++) { - cxxISolutionComp c(&(solution_ptr->totals[i])); + cxxISolutionComp c(&(solution_ptr->totals[i]), this->Get_io()); //comps.insert(solution_ptr->totals[i].description, c); comps[solution_ptr->totals[i].description] = c; } diff --git a/ISolution.h b/ISolution.h index 2a3dae90..37a962e2 100644 --- a/ISolution.h +++ b/ISolution.h @@ -19,8 +19,8 @@ class cxxISolution:public cxxSolution { public: - cxxISolution(PHRQ_io *io); - cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *, PHRQ_io *io); + cxxISolution(PHRQ_io *io=NULL); + cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *, PHRQ_io *io=NULL); //cxxISolution(const cxxISolution&); ~cxxISolution(); diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index b07eb046..c22dbf54 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -15,14 +15,21 @@ #include "phqalloc.h" #include "output.h" -cxxISolutionComp::cxxISolutionComp(void):description(NULL), moles(0.0), input_conc(0.0), units(NULL), -equation_name(NULL), phase_si(0.0), n_pe(-1), as(NULL), +cxxISolutionComp::cxxISolutionComp(PHRQ_io *io): +PHRQ_base(io), +description(NULL), +moles(0.0), +input_conc(0.0), +units(NULL), +equation_name(NULL), +phase_si(0.0), +n_pe(-1), +as(NULL), gfw(0.0) - //, skip(0); - //, phase(NULL) { } -cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr) +cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr, PHRQ_io *io) +: PHRQ_base(io) { this->set_description(conc_ptr->description); moles = conc_ptr->moles; diff --git a/ISolutionComp.h b/ISolutionComp.h index 4b12b4b4..295098bd 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -9,12 +9,12 @@ // forward declarations class cxxISolution; // reqd for read and dump_xml -class cxxISolutionComp +class cxxISolutionComp: public PHRQ_base { public: - cxxISolutionComp(void); - cxxISolutionComp(struct conc *conc_ptr); - ~cxxISolutionComp(void); + cxxISolutionComp(PHRQ_io *io=NULL); + cxxISolutionComp(struct conc *conc_ptr, PHRQ_io *io=NULL); + ~cxxISolutionComp(void); public: diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 1e9aad30..fb035f40 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -24,7 +24,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxKineticsComp::cxxKineticsComp() +cxxKineticsComp::cxxKineticsComp(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for cxxKineticsComp // @@ -36,11 +38,12 @@ cxxKineticsComp::cxxKineticsComp() namecoef.type = cxxNameDouble::ND_NAME_COEF; } -cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr) +cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr, PHRQ_io *io) // // constructor for cxxKineticsComp from struct kinetics_comp // : +PHRQ_base(io), namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) { this->set_rate_name(kinetics_comp_ptr->rate_name); diff --git a/KineticsComp.h b/KineticsComp.h index acecc8c7..35e671e4 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -9,12 +9,12 @@ #include "NameDouble.h" -class cxxKineticsComp +class cxxKineticsComp: public PHRQ_base { public: - cxxKineticsComp(); - cxxKineticsComp(struct kinetics_comp *); + cxxKineticsComp(PHRQ_io *io=NULL); + cxxKineticsComp(struct kinetics_comp *, PHRQ_io *io=NULL); ~cxxKineticsComp(); static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el); diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 94411661..241c14c8 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -12,10 +12,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxNumKeyword::cxxNumKeyword() +cxxNumKeyword::cxxNumKeyword(PHRQ_io *io) { this->n_user = 1; this->n_user_end = 1; + this->Set_io(io); } cxxNumKeyword::~cxxNumKeyword() diff --git a/NumKeyword.h b/NumKeyword.h index ef17dd35..ebe78407 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -4,14 +4,15 @@ //#include "Parser.h" #include // std::ostream #include // std::string +#include "PHRQ_base.h" class CParser; //extern char *string_duplicate(const char *); -class cxxNumKeyword +class cxxNumKeyword: public PHRQ_base { public: - cxxNumKeyword(); + cxxNumKeyword(PHRQ_io *io=NULL); virtual ~ cxxNumKeyword(); const std::string &get_description() const { diff --git a/PPassemblage.cxx b/PPassemblage.cxx index e71b3d87..4a02a710 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -23,21 +23,21 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxPPassemblage::cxxPPassemblage() +cxxPPassemblage::cxxPPassemblage(PHRQ_io * io) // // default constructor for cxxPPassemblage // -: cxxNumKeyword() +: cxxNumKeyword(io) { eltList.type = cxxNameDouble::ND_ELT_MOLES; } -cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr) +cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr, PHRQ_io * io) // // constructor for cxxPPassemblage from struct PPassemblage // : -cxxNumKeyword(), +cxxNumKeyword(io), eltList(pp_assemblage_ptr->next_elt) { int i; @@ -47,7 +47,7 @@ eltList(pp_assemblage_ptr->next_elt) n_user_end = pp_assemblage_ptr->n_user_end; for (i = 0; i < pp_assemblage_ptr->count_comps; i++) { - cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i])); + cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i]), this->Get_io()); //ppAssemblageComps.push_back(ppComp); std::string str(ppComp.get_name()); this->ppAssemblageComps[str] = ppComp; @@ -55,8 +55,8 @@ eltList(pp_assemblage_ptr->next_elt) } cxxPPassemblage::cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, - int l_n_user): -cxxNumKeyword() + int l_n_user, PHRQ_io * io): +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; eltList.type = cxxNameDouble::ND_ELT_MOLES; @@ -234,7 +234,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 1: // component { - cxxPPassemblageComp ec; + cxxPPassemblageComp ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -268,7 +268,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) @@ -278,7 +278,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxPPassemblageComp ppComp1; + cxxPPassemblageComp ppComp1(this->Get_io()); ppComp1.read_raw(reread, false); std::string str(ppComp1.get_name()); this->ppAssemblageComps[str] = ppComp1; diff --git a/PPassemblage.h b/PPassemblage.h index 91073d67..523dfc8a 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -15,10 +15,10 @@ class cxxPPassemblage:public cxxNumKeyword { public: - cxxPPassemblage(); - cxxPPassemblage(struct pp_assemblage *); + cxxPPassemblage(PHRQ_io * io=NULL); + cxxPPassemblage(struct pp_assemblage *, PHRQ_io * io=NULL); cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entity_map, - cxxMix & mx, int n_user); + cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxPPassemblage(); struct pp_assemblage *cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 1f264995..ff8d6f6e 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -25,7 +25,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxPPassemblageComp::cxxPPassemblageComp() +cxxPPassemblageComp::cxxPPassemblageComp(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for cxxPPassemblageComp // @@ -39,7 +41,9 @@ cxxPPassemblageComp::cxxPPassemblageComp() precipitate_only = false; } -cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr) +cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) +: +PHRQ_base(io) // // constructor for cxxPPassemblageComp from struct pure_phase // diff --git a/PPassemblageComp.h b/PPassemblageComp.h index de4badcb..9046d5e1 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -9,12 +9,12 @@ #include "NameDouble.h" -class cxxPPassemblageComp +class cxxPPassemblageComp: public PHRQ_base { public: - cxxPPassemblageComp(); - cxxPPassemblageComp(struct pure_phase *); + cxxPPassemblageComp(PHRQ_io *io=NULL); + cxxPPassemblageComp(struct pure_phase *, PHRQ_io *io=NULL); ~cxxPPassemblageComp(); diff --git a/Parser.cxx b/Parser.cxx index a9e7fd4b..f8e698c8 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -24,7 +24,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, PHRQ_io *io): +PHRQ_base(io), +m_input_stream(input), +m_output_stream(std::cout), +m_error_stream(std::cerr), m_input_error(0), m_next_keyword(KT_NONE) { @@ -38,7 +42,12 @@ m_next_keyword(KT_NONE) #endif } -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, PHRQ_io *io) +: +PHRQ_base(io), +m_input_stream(input), +m_output_stream(output), +m_error_stream(std::cerr), m_input_error(0), m_next_keyword(KT_NONE) { @@ -52,7 +61,12 @@ m_next_keyword(KT_NONE) #endif } -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), +CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error, PHRQ_io *io) +: +PHRQ_base(io), +m_input_stream(input), +m_output_stream(output), +m_error_stream(error), m_input_error(0), m_next_keyword(KT_NONE) { diff --git a/Parser.h b/Parser.h index 5b2be331..976bd39a 100644 --- a/Parser.h +++ b/Parser.h @@ -19,14 +19,15 @@ class Phreeqc; #define ERROR_MESSAGE_QUALIFIER :: extern int input_error; #endif +#include "PHRQ_base.h" -class CParser +class CParser: public PHRQ_base { public: - CParser(PHREEQC_PTR_ARG_COMMA std::istream & input); - CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output); + CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, PHRQ_io *io=NULL); + CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, PHRQ_io *io=NULL); CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, - std::ostream & error); + std::ostream & error, PHRQ_io *io=NULL); virtual ~ CParser(); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index b2e7f25c..e873a5eb 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -470,7 +470,7 @@ size_t Phreeqc::list_components(std::list &list_c) // pure phases for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage entity(&pp_assemblage[i]); + cxxPPassemblage entity(&pp_assemblage[i], &this->phrq_io); entity.totalize(this); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -486,7 +486,7 @@ size_t Phreeqc::list_components(std::list &list_c) // surfaces for (i = 0; i < count_surface; i++) { - cxxSurface entity(&surface[i]); + cxxSurface entity(&surface[i], &this->phrq_io); entity.totalize(); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -494,7 +494,7 @@ size_t Phreeqc::list_components(std::list &list_c) // gas phases for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase entity(&gas_phase[i]); + cxxGasPhase entity(&gas_phase[i], &this->phrq_io); entity.totalize(this); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -1185,6 +1185,9 @@ void Phreeqc::init(void) count_strings = 0; + chart_handler.Set_io(&this->phrq_io); + run_info.Set_io(&this->phrq_io); + this->clear_cookie(); return; diff --git a/Reaction.cxx b/Reaction.cxx index 87db1e96..ecdbf826 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -22,11 +22,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxReaction::cxxReaction() +cxxReaction::cxxReaction(PHRQ_io *io) // // default constructor for cxxReaction // -: cxxNumKeyword() +: cxxNumKeyword(io) { this->set_units("Mol"); countSteps = 0; @@ -34,13 +34,12 @@ cxxReaction::cxxReaction() reactantList.type = cxxNameDouble::ND_NAME_COEF; elementList.type = cxxNameDouble::ND_ELT_MOLES; } - -cxxReaction::cxxReaction(struct irrev *irrev_ptr) +cxxReaction::cxxReaction(struct irrev *irrev_ptr, PHRQ_io *io) // // constructor for cxxReaction from struct irrev // : -cxxNumKeyword(), +cxxNumKeyword(io), reactantList(irrev_ptr->list, irrev_ptr->count_list), elementList(irrev_ptr->elts) { diff --git a/Reaction.h b/Reaction.h index 3f5afeb4..1172ec44 100644 --- a/Reaction.h +++ b/Reaction.h @@ -14,8 +14,8 @@ class cxxReaction:public cxxNumKeyword { public: - cxxReaction(); - cxxReaction(struct irrev *); + cxxReaction(PHRQ_io *io = NULL); + cxxReaction(struct irrev *, PHRQ_io *io = NULL); ~cxxReaction(); struct irrev *cxxReaction2irrev(PHREEQC_PTR_ARG); diff --git a/ReadClass.cxx b/ReadClass.cxx index 05a7a7ac..c71b047e 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -94,7 +94,7 @@ read_solution_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -187,7 +187,7 @@ read_exchange_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -281,7 +281,7 @@ read_surface_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -296,7 +296,7 @@ read_surface_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxSurface ex; + cxxSurface ex(&this->phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); int n; @@ -376,7 +376,7 @@ read_equilibrium_phases_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -391,7 +391,7 @@ read_equilibrium_phases_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxPPassemblage ex; + cxxPPassemblage ex(&this->phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); int n; @@ -472,7 +472,7 @@ read_kinetics_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -567,7 +567,7 @@ read_solid_solutions_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -664,7 +664,7 @@ read_gas_phase_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -679,7 +679,7 @@ read_gas_phase_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxGasPhase ex; + cxxGasPhase ex(&this->phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); int n; @@ -758,7 +758,7 @@ read_reaction_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -853,7 +853,7 @@ read_mix_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -948,7 +948,7 @@ read_temperature_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) @@ -964,7 +964,7 @@ read_temperature_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxTemperature ex; + cxxTemperature ex(&this->phrq_io); ex.read_raw(parser); struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); int n; @@ -1025,7 +1025,7 @@ read_dump(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1043,7 +1043,7 @@ read_dump(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - dumper dmp(parser); + dumper dmp(parser, &this->phrq_io); dump_info = dmp; @@ -1077,7 +1077,7 @@ read_delete(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1095,7 +1095,7 @@ read_delete(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - StorageBinList deleter(parser); + StorageBinList deleter(parser, &this->phrq_io); delete_info = deleter; @@ -1129,7 +1129,7 @@ read_run_cells(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1147,7 +1147,7 @@ read_run_cells(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - runner r(parser); + runner r(parser, &this->phrq_io); run_info = r; @@ -1292,7 +1292,7 @@ read_solution_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1390,7 +1390,7 @@ read_equilibrium_phases_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1417,7 +1417,7 @@ read_equilibrium_phases_modify(void) } // read entity - cxxPPassemblage entity(&(pp_assemblage[n])); + cxxPPassemblage entity(&(pp_assemblage[n]), &this->phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1483,7 +1483,7 @@ read_exchange_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1591,7 +1591,7 @@ read_surface_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1618,7 +1618,7 @@ read_surface_modify(void) } // read entity - cxxSurface entity(&(surface[n])); + cxxSurface entity(&(surface[n]), &this->phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1680,7 +1680,7 @@ read_solid_solutions_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1768,7 +1768,7 @@ read_gas_phase_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1795,7 +1795,7 @@ read_gas_phase_modify(void) } // read entity - cxxGasPhase entity(&(gas_phase[n])); + cxxGasPhase entity(&(gas_phase[n]), &this->phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); @@ -1856,7 +1856,7 @@ read_kinetics_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; // ?? std::ostringstream oss_err; // ?? - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1944,7 +1944,7 @@ read_reaction_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -2705,7 +2705,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage cxxentity(&pp_assemblage[i]); + cxxPPassemblage cxxentity(&pp_assemblage[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2717,7 +2717,7 @@ dump_ostream(std::ostream& os) if (pp_assemblage_bsearch(*it, &n) != NULL) { - cxxPPassemblage cxxentity(&pp_assemblage[n]); + cxxPPassemblage cxxentity(&pp_assemblage[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2757,7 +2757,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_surface; i++) { - cxxSurface cxxentity(&surface[i]); + cxxSurface cxxentity(&surface[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2769,7 +2769,7 @@ dump_ostream(std::ostream& os) if (surface_bsearch(*it, &n) != NULL) { - cxxSurface cxxentity(&surface[n]); + cxxSurface cxxentity(&surface[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2809,7 +2809,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase cxxentity(&gas_phase[i]); + cxxGasPhase cxxentity(&gas_phase[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2821,7 +2821,7 @@ dump_ostream(std::ostream& os) if (gas_phase_bsearch(*it, &n) != NULL) { - cxxGasPhase cxxentity(&gas_phase[n]); + cxxGasPhase cxxentity(&gas_phase[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2913,7 +2913,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_temperature; i++) { - cxxTemperature cxxentity(&temperature[i]); + cxxTemperature cxxentity(&temperature[i], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2925,7 +2925,7 @@ dump_ostream(std::ostream& os) if (temperature_bsearch(*it, &n) != NULL) { - cxxTemperature cxxentity(&temperature[n]); + cxxTemperature cxxentity(&temperature[n], &this->phrq_io); cxxentity.dump_raw(os,0); } } @@ -2968,7 +2968,7 @@ read_user_graph_handler(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f25fb303..5b4121cc 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -25,20 +25,20 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSSassemblage::cxxSSassemblage() +cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) // // default constructor for cxxSSassemblage // -: cxxNumKeyword() +: cxxNumKeyword(io) { } -cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr) +cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr, PHRQ_io * io) // // constructor for cxxSSassemblage from struct SSassemblage // : -cxxNumKeyword() +cxxNumKeyword(io) { int i; this->set_description(s_s_assemblage_ptr->description); @@ -46,15 +46,15 @@ cxxNumKeyword() n_user_end = s_s_assemblage_ptr->n_user_end; for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i])); + cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i]), this->Get_io()); std::string str(ssSS.get_name()); ssAssemblageSSs[str] = ssSS; } } cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxSSassemblage > &entities, cxxMix & mix, - int l_n_user): -cxxNumKeyword() + int l_n_user, PHRQ_io * io): +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; //std::list ssAssemblageSSs; @@ -211,7 +211,7 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 0: // solid_solution { - cxxSSassemblageSS ec; + cxxSSassemblageSS ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -243,7 +243,7 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) @@ -253,7 +253,7 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxSSassemblageSS ec1; + cxxSSassemblageSS ec1(this->Get_io()); ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_name()); this->ssAssemblageSSs[str] = ec1; diff --git a/SSassemblage.h b/SSassemblage.h index 9190035f..ca772ebf 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -20,10 +20,10 @@ class cxxSSassemblage:public cxxNumKeyword { public: - cxxSSassemblage(); - cxxSSassemblage(struct s_s_assemblage *); + cxxSSassemblage(PHRQ_io * io = NULL); + cxxSSassemblage(struct s_s_assemblage *, PHRQ_io * io = NULL); cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, - cxxMix & mx, int n_user); + cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG); diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 329ffe6a..2c7b55cf 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -25,7 +25,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSSassemblageSS::cxxSSassemblageSS() +cxxSSassemblageSS::cxxSSassemblageSS(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for cxxSSassemblageSS // @@ -44,8 +46,9 @@ cxxSSassemblageSS::cxxSSassemblageSS() //double p[4]; } -cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr) - // +cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr, PHRQ_io *io) +: +PHRQ_base(io) // // constructor for cxxSSassemblageSS from struct s_s // { diff --git a/SSassemblageSS.h b/SSassemblageSS.h index b3f6cd77..2d562d42 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -10,12 +10,12 @@ #include "NameDouble.h" #include "Phreeqc_class.h" -class cxxSSassemblageSS +class cxxSSassemblageSS: public PHRQ_base { public: - cxxSSassemblageSS(); - cxxSSassemblageSS(struct s_s *); + cxxSSassemblageSS(PHRQ_io *io=NULL); + cxxSSassemblageSS(struct s_s *, PHRQ_io *io=NULL); ~cxxSSassemblageSS(); enum SS_PARAMETER_TYPE diff --git a/Solution.cxx b/Solution.cxx index 28d20ab8..509b82e3 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -36,8 +36,8 @@ cxxSolution::cxxSolution(PHRQ_io * io) // // default constructor for cxxSolution // -: cxxNumKeyword(), - PHRQ_base(io) +: cxxNumKeyword(io), +isotopes(io) { this->tc = 25.0; this->ph = 7.0; @@ -59,14 +59,13 @@ cxxSolution::cxxSolution(struct solution * solution_ptr, PHRQ_io * io) // constructor for cxxSolution from struct solution // : -cxxNumKeyword(), -PHRQ_base(io), +cxxNumKeyword(io), totals(solution_ptr->totals), master_activity(solution_ptr->master_activity, - solution_ptr->count_master_activity, - cxxNameDouble::ND_SPECIES_LA), -species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, - cxxNameDouble::ND_SPECIES_GAMMA), isotopes(solution_ptr) +solution_ptr->count_master_activity, +cxxNameDouble::ND_SPECIES_LA), +species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA), +isotopes(solution_ptr, io) { this->set_description(solution_ptr->description); @@ -103,8 +102,8 @@ cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution // constructor for cxxSolution from mixture of solutions // : -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io), +isotopes(io) { // @@ -142,8 +141,8 @@ cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io * io) // does not work in phast because phast uses only the total molalities // of elements in buffer, not individual redox states. : -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io), +isotopes(io) { //this->set_description none; @@ -256,7 +255,7 @@ PHRQ_base(io) { for (i = 0; i < P_INSTANCE_POINTER count_isotopes_x; i++) { - cxxSolutionIsotope cxxiso; + cxxSolutionIsotope cxxiso(this->Get_io()); cxxiso.set_isotope_number(P_INSTANCE_POINTER isotopes_x[i].isotope_number); cxxiso.set_elt_name(P_INSTANCE_POINTER isotopes_x[i].elt_name); cxxiso.set_isotope_name(P_INSTANCE_POINTER isotopes_x[i].isotope_name); @@ -687,7 +686,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 3: // isotopes { - cxxSolutionIsotope iso; + cxxSolutionIsotope iso(this->Get_io()); if (iso.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/Solution.h b/Solution.h index f519590b..c11ea4f4 100644 --- a/Solution.h +++ b/Solution.h @@ -13,15 +13,15 @@ #include "PHRQ_io.h" class cxxMix; -class cxxSolution:public cxxNumKeyword, public PHRQ_base +class cxxSolution:public cxxNumKeyword { public: cxxSolution(PHRQ_io *io=NULL); - cxxSolution(struct solution *, PHRQ_io *io); - cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io); + cxxSolution(struct solution *, PHRQ_io *io=NULL); + cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solution_map, - cxxMix & mx, int n_user, PHRQ_io *io); + cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSolution(); //static cxxSolution& read(CParser& parser); diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 27f90a7a..6dcbc3ac 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -15,7 +15,9 @@ #include "phqalloc.h" #include "phrqproto.h" -cxxSolutionIsotope::cxxSolutionIsotope(void): +cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io) +: +PHRQ_base(io), isotope_number(0.0) { isotope_number = 0; @@ -27,7 +29,9 @@ isotope_number(0.0) ratio_uncertainty_defined = false; } -cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr) +cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io) +: +PHRQ_base(io) { isotope_number = isotope_ptr->isotope_number; this->set_elt_name(isotope_ptr->elt_name); diff --git a/SolutionIsotope.h b/SolutionIsotope.h index a5c6cbab..f63b97b0 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -7,12 +7,12 @@ #include "Parser.h" #include "Phreeqc_class.h" -class cxxSolutionIsotope +class cxxSolutionIsotope: public PHRQ_base { public: - cxxSolutionIsotope(void); - cxxSolutionIsotope(struct isotope *isotope_ptr); - ~cxxSolutionIsotope(void); + cxxSolutionIsotope(PHRQ_io *io=NULL); + cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io=NULL); + ~cxxSolutionIsotope(void); /* enum STATUS { diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 0e6cb878..33f832f9 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -13,30 +13,34 @@ #include "phrqproto.h" -cxxSolutionIsotopeList::cxxSolutionIsotopeList(void) +cxxSolutionIsotopeList::cxxSolutionIsotopeList(PHRQ_io * io) +: +PHRQ_base(io) // // default constructor for cxxSolution // { } -cxxSolutionIsotopeList::~cxxSolutionIsotopeList(void) - // - // default destructor for cxxSolution - // -{ -} - -cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr) +cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr, PHRQ_io * io) +: +PHRQ_base(io) { int i; // Isotopes for (i = 0; i < solution_ptr->count_isotopes; i++) { - //cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); - (*this).push_back(&solution_ptr->isotopes[i]); + cxxSolutionIsotope iso(&solution_ptr->isotopes[i], this->Get_io()); + (*this).push_back(iso); } } + +cxxSolutionIsotopeList::~cxxSolutionIsotopeList() + // + // default destructor for cxxSolution + // +{ +} void cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, double extensive) @@ -66,7 +70,7 @@ cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, } if (!found) { - cxxSolutionIsotope iso; + cxxSolutionIsotope iso(this->Get_io()); iso.total = itold->total * extensive; iso.ratio = itold->ratio * intensive; iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 6d8483c8..d36db041 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -9,13 +9,13 @@ #include "Phreeqc_class.h" class cxxSolutionIsotopeList:public - std::list < cxxSolutionIsotope > + std::list < cxxSolutionIsotope >, public PHRQ_base { public: - cxxSolutionIsotopeList(); + cxxSolutionIsotopeList(PHRQ_io *io=NULL); - cxxSolutionIsotopeList(struct solution *solution_ptr); + cxxSolutionIsotopeList(struct solution *solution_ptr, PHRQ_io *io=NULL); ~cxxSolutionIsotopeList(); diff --git a/StorageBin.cxx b/StorageBin.cxx index 30609905..d7b58a4b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -46,6 +46,7 @@ cxxStorageBin::cxxStorageBin(PHRQ_io *io) PHRQ_base(io) { // default constructor for cxxStorageBin + this->system.Set_io(io); } #ifdef SKIP cxxStorageBin::cxxStorageBin(struct Use *use_ptr) @@ -123,6 +124,7 @@ PHRQ_base(io) //Construct from use pointer int n; + this->system.Set_io(io); if (use_ptr->mix_in == TRUE) { struct mix *struct_entity = P_INSTANCE_POINTER mix_bsearch(use_ptr->n_mix_user, &n); @@ -158,7 +160,7 @@ PHRQ_base(io) struct pp_assemblage *struct_entity = P_INSTANCE_POINTER pp_assemblage_bsearch(use_ptr->n_pp_assemblage_user, &n); if (struct_entity != NULL) { - cxxPPassemblage entity(struct_entity); + cxxPPassemblage entity(struct_entity, this->Get_io()); this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); } } @@ -176,7 +178,7 @@ PHRQ_base(io) struct surface *struct_entity = P_INSTANCE_POINTER surface_bsearch(use_ptr->n_surface_user, &n); if (struct_entity != NULL) { - cxxSurface entity(struct_entity); + cxxSurface entity(struct_entity, this->Get_io()); this->setSurface(use_ptr->n_surface_user, &entity); } } @@ -185,7 +187,7 @@ PHRQ_base(io) struct gas_phase *struct_entity = P_INSTANCE_POINTER gas_phase_bsearch(use_ptr->n_gas_phase_user, &n); if (struct_entity != NULL) { - cxxGasPhase entity(struct_entity); + cxxGasPhase entity(struct_entity, this->Get_io()); this->setGasPhase(use_ptr->n_gas_phase_user, &entity); } } @@ -221,7 +223,7 @@ PHRQ_base(io) struct temperature *struct_entity = P_INSTANCE_POINTER temperature_bsearch(use_ptr->n_temperature_user, &n); if (struct_entity != NULL) { - cxxTemperature entity(struct_entity); + cxxTemperature entity(struct_entity, this->Get_io()); this->setTemperature(use_ptr->n_temperature_user, &entity); } } @@ -523,7 +525,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // GasPhases for (i = 0; i < P_INSTANCE_POINTER count_gas_phase; i++) { - GasPhases[P_INSTANCE_POINTER gas_phase[i].n_user] = cxxGasPhase(&P_INSTANCE_POINTER gas_phase[i]); + GasPhases[P_INSTANCE_POINTER gas_phase[i].n_user] = cxxGasPhase(&P_INSTANCE_POINTER gas_phase[i], this->Get_io()); } // Kinetics @@ -536,7 +538,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) for (i = 0; i < P_INSTANCE_POINTER count_pp_assemblage; i++) { PPassemblages[P_INSTANCE_POINTER pp_assemblage[i].n_user] = - cxxPPassemblage(&P_INSTANCE_POINTER pp_assemblage[i]); + cxxPPassemblage(&P_INSTANCE_POINTER pp_assemblage[i], this->Get_io()); } // SSassemblages @@ -549,7 +551,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Surfaces for (i = 0; i < P_INSTANCE_POINTER count_surface; i++) { - Surfaces[P_INSTANCE_POINTER surface[i].n_user] = cxxSurface(&P_INSTANCE_POINTER surface[i]); + Surfaces[P_INSTANCE_POINTER surface[i].n_user] = cxxSurface(&P_INSTANCE_POINTER surface[i], this->Get_io()); } // Mixes @@ -567,7 +569,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // Temperatures for (i = 0; i < P_INSTANCE_POINTER count_temperature; i++) { - Temperatures[P_INSTANCE_POINTER temperature[i].n_user] = cxxTemperature(&P_INSTANCE_POINTER temperature[i]); + Temperatures[P_INSTANCE_POINTER temperature[i].n_user] = cxxTemperature(&P_INSTANCE_POINTER temperature[i], this->Get_io()); } } @@ -748,7 +750,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_GASPHASE_RAW: { - cxxGasPhase entity; + cxxGasPhase entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); GasPhases[entity.get_n_user()] = entity; } @@ -764,7 +766,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { - cxxPPassemblage entity; + cxxPPassemblage entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); PPassemblages[entity.get_n_user()] = entity; } @@ -780,7 +782,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SURFACE_RAW: { - cxxSurface entity; + cxxSurface entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Surfaces[entity.get_n_user()] = entity; } @@ -788,7 +790,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_TEMPERATURE_RAW: { - cxxTemperature entity; + cxxTemperature entity(this->Get_io()); entity.read_raw(parser); Temperatures[entity.get_n_user()] = entity; } @@ -861,7 +863,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_GASPHASE_RAW: { - cxxGasPhase entity; + cxxGasPhase entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); GasPhases[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -879,7 +881,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { - cxxPPassemblage entity; + cxxPPassemblage entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); PPassemblages[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -897,7 +899,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SURFACE_RAW: { - cxxSurface entity; + cxxSurface entity(this->Get_io()); entity.read_raw(P_INSTANCE_COMMA parser); Surfaces[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -906,7 +908,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_TEMPERATURE_RAW: { - cxxTemperature entity; + cxxTemperature entity(this->Get_io()); entity.read_raw(parser); Temperatures[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); @@ -953,7 +955,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->gas_phase != NULL) { this->GasPhases[system_ptr->gas_phase->n_user] = - cxxGasPhase(system_ptr->gas_phase); + cxxGasPhase(system_ptr->gas_phase, this->Get_io()); } // Kinetics @@ -967,7 +969,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->pp_assemblage != NULL) { this->PPassemblages[system_ptr->pp_assemblage->n_user] = - cxxPPassemblage(system_ptr->pp_assemblage); + cxxPPassemblage(system_ptr->pp_assemblage, this->Get_io()); } // SSassemblages @@ -981,7 +983,7 @@ cxxStorageBin::add(struct system *system_ptr) if (system_ptr->surface != NULL) { this->Surfaces[system_ptr->surface->n_user] = - cxxSurface(system_ptr->surface); + cxxSurface(system_ptr->surface, this->Get_io()); } } @@ -1126,7 +1128,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) { if (P_INSTANCE_POINTER gas_phase_bsearch(n, &pos) != NULL) { - this->GasPhases[n] = cxxGasPhase(&(P_INSTANCE_POINTER gas_phase[pos])); + this->GasPhases[n] = cxxGasPhase(&(P_INSTANCE_POINTER gas_phase[pos]), this->Get_io()); } } @@ -1142,7 +1144,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) { if (P_INSTANCE_POINTER pp_assemblage_bsearch(n, &pos) != NULL) { - this->PPassemblages[n] = cxxPPassemblage(&(P_INSTANCE_POINTER pp_assemblage[pos])); + this->PPassemblages[n] = cxxPPassemblage(&(P_INSTANCE_POINTER pp_assemblage[pos]), this->Get_io()); } } @@ -1158,7 +1160,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) { if (P_INSTANCE_POINTER surface_bsearch(n, &pos) != NULL) { - this->Surfaces[n] = cxxSurface(&(P_INSTANCE_POINTER surface[pos])); + this->Surfaces[n] = cxxSurface(&(P_INSTANCE_POINTER surface[pos]), this->Get_io()); } } } diff --git a/StorageBin.h b/StorageBin.h index 3e2d90b0..4d05e746 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -23,9 +23,9 @@ class cxxStorageBin: public PHRQ_base { public: - cxxStorageBin(PHRQ_io *io); + cxxStorageBin(PHRQ_io *io=NULL); //cxxStorageBin(struct Use *use_ptr); - cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io); + cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io=NULL); ~cxxStorageBin(); void import_phreeqc(PHREEQC_PTR_ARG); diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 3dcd1487..b6177895 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -97,10 +97,17 @@ void StorageBinListItem::Augment(int i) this->defined = true; this->numbers.insert(i); } -StorageBinList::StorageBinList(void) +// +//Class definitions for StorageBinList +// +StorageBinList::StorageBinList(PHRQ_io *io) +: +PHRQ_base(io) { } -StorageBinList::StorageBinList(CParser & parser) +StorageBinList::StorageBinList(CParser & parser, PHRQ_io *io) +: +PHRQ_base(io) { this->Read(parser); } diff --git a/StorageBinList.h b/StorageBinList.h index 8da5fe83..0bc05b4b 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -4,7 +4,7 @@ #include // std::string #include // std::list #include // std::vector - +#include "PHRQ_base.h" class CParser; class StorageBinListItem @@ -23,11 +23,11 @@ protected: std::set < int > numbers; bool defined; }; -class StorageBinList +class StorageBinList: public PHRQ_base { public: - StorageBinList(void); - StorageBinList(CParser & parser); + StorageBinList(PHRQ_io *io=NULL); + StorageBinList(CParser & parser, PHRQ_io *io=NULL); ~StorageBinList(void); bool Read(CParser & parser); void SetAll(bool tf); diff --git a/Surface.cxx b/Surface.cxx index be5b9e41..1e5d7d93 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -23,11 +23,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSurface::cxxSurface() +cxxSurface::cxxSurface(PHRQ_io *io) // // default constructor for cxxSurface // -: cxxNumKeyword() +: cxxNumKeyword(io) { type = DDL; dl_type = NO_DL; @@ -43,12 +43,12 @@ cxxSurface::cxxSurface() transport = false; } -cxxSurface::cxxSurface(struct surface *surface_ptr) +cxxSurface::cxxSurface(struct surface *surface_ptr, PHRQ_io *io) // // constructor for cxxSurface from struct surface // : -cxxNumKeyword() +cxxNumKeyword(io) { int i; @@ -70,21 +70,21 @@ cxxNumKeyword() // Surface components for (i = 0; i < surface_ptr->count_comps; i++) { - cxxSurfaceComp ec(&(surface_ptr->comps[i])); + cxxSurfaceComp ec(&(surface_ptr->comps[i]), this->Get_io()); std::string str(ec.get_formula()); surfaceComps[str] = ec; } // Surface charge for (i = 0; i < surface_ptr->count_charge; i++) { - cxxSurfaceCharge ec(&(surface_ptr->charge[i])); + cxxSurfaceCharge ec(&(surface_ptr->charge[i]), this->Get_io()); std::string str(ec.get_name()); surfaceCharges[str] = ec; } } cxxSurface::cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entities, - cxxMix & mix, int l_n_user): -cxxNumKeyword() + cxxMix & mix, int l_n_user, PHRQ_io *io): +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; type = DDL; @@ -510,7 +510,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 5: // component { - cxxSurfaceComp ec; + cxxSurfaceComp ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -542,7 +542,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) @@ -552,7 +552,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxSurfaceComp ec1; + cxxSurfaceComp ec1(this->Get_io()); ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_formula()); this->surfaceComps[str] = ec1; @@ -563,7 +563,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 6: // charge_component { - cxxSurfaceCharge ec; + cxxSurfaceCharge ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -595,7 +595,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) @@ -605,7 +605,7 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxSurfaceCharge ec1; + cxxSurfaceCharge ec1(this->Get_io()); ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_name()); this->surfaceCharges[str] = ec1; diff --git a/Surface.h b/Surface.h index fdb9205d..b2edb075 100644 --- a/Surface.h +++ b/Surface.h @@ -16,10 +16,10 @@ class cxxSurface:public cxxNumKeyword { public: - cxxSurface(); - cxxSurface(struct surface *); + cxxSurface(PHRQ_io *io=NULL); + cxxSurface(struct surface *, PHRQ_io *io=NULL); cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entity_map, cxxMix & mx, - int n_user); + int n_user, PHRQ_io *io=NULL); ~cxxSurface(); //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 6791835b..ab3ad998 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -24,7 +24,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSurfaceCharge::cxxSurfaceCharge() +cxxSurfaceCharge::cxxSurfaceCharge(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for cxxSurfaceCharge // @@ -41,11 +43,12 @@ cxxSurfaceCharge::cxxSurfaceCharge() diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; } -cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr) +cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr, PHRQ_io *io) // // constructor for cxxSurfaceCharge from struct surface_charge // : +PHRQ_base(io), diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) { this->set_name(surf_charge_ptr->name); diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 3ffff40d..d422226e 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -9,14 +9,15 @@ #include "NameDouble.h" #include "Phreeqc_class.h" +#include "PHRQ_base.h" -class cxxSurfaceCharge +class cxxSurfaceCharge: public PHRQ_base { public: - cxxSurfaceCharge(); - cxxSurfaceCharge(struct surface_charge *); + cxxSurfaceCharge(PHRQ_io *io=NULL); + cxxSurfaceCharge(struct surface_charge *, PHRQ_io *io=NULL); ~cxxSurfaceCharge(); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 30d650ab..25893164 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -24,7 +24,9 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSurfaceComp::cxxSurfaceComp() +cxxSurfaceComp::cxxSurfaceComp(PHRQ_io *io) +: +PHRQ_base(io) // // default constructor for cxxSurfaceComp // @@ -40,11 +42,12 @@ cxxSurfaceComp::cxxSurfaceComp() Dw = 0.0; } -cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr) +cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr, PHRQ_io *io) // // constructor for cxxSurfaceComp from struct surface_comp // : +PHRQ_base(io), formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { diff --git a/SurfaceComp.h b/SurfaceComp.h index 34317da6..f17ce9ba 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -9,13 +9,13 @@ #include "Phreeqc_class.h" #include "NameDouble.h" -class cxxSurfaceComp +class cxxSurfaceComp: public PHRQ_base { public: - cxxSurfaceComp(); - cxxSurfaceComp(struct surface_comp *); + cxxSurfaceComp(PHRQ_io *io=NULL); + cxxSurfaceComp(struct surface_comp *, PHRQ_io *io=NULL); ~cxxSurfaceComp(); struct master *get_master(PHREEQC_PTR_ARG); diff --git a/System.cxx b/System.cxx index 0cd99eea..bf0f0a5d 100644 --- a/System.cxx +++ b/System.cxx @@ -22,7 +22,9 @@ extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); -cxxSystem::cxxSystem(void) +cxxSystem::cxxSystem(PHRQ_io *io) +: +PHRQ_base(io) { this->solution = NULL; this->exchange = NULL; diff --git a/System.h b/System.h index 456b779f..a5a87d52 100644 --- a/System.h +++ b/System.h @@ -11,6 +11,7 @@ //#include "Reaction.h" //#include "Temperature.h" #include "NameDouble.h" +#include "PHRQ_base.h" class cxxSolution; class cxxExchange; class cxxGasPhase; @@ -22,10 +23,10 @@ class cxxReaction; class cxxTemperature; class cxxMix; -class cxxSystem +class cxxSystem: public PHRQ_base { public: - cxxSystem(void); + cxxSystem(PHRQ_io *io=NULL); ~cxxSystem(void); void Initialize(void); void setSolution(cxxSolution * entity) diff --git a/Temperature.cxx b/Temperature.cxx index d1a7abbd..d3edecda 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -24,22 +24,22 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxTemperature::cxxTemperature() +cxxTemperature::cxxTemperature(PHRQ_io *io) // // default constructor for cxxTemperature // -: cxxNumKeyword() +: cxxNumKeyword(io) { countTemps = 0; equalIncrements = false; } -cxxTemperature::cxxTemperature(struct temperature *temperature_ptr) +cxxTemperature::cxxTemperature(struct temperature *temperature_ptr, PHRQ_io *io) // // constructor for cxxTemperature from struct temperature // : -cxxNumKeyword() +cxxNumKeyword(io) { int i; diff --git a/Temperature.h b/Temperature.h index b87a1079..9d623aa7 100644 --- a/Temperature.h +++ b/Temperature.h @@ -14,9 +14,9 @@ class cxxTemperature:public cxxNumKeyword { public: - cxxTemperature(); - cxxTemperature(struct temperature *); - ~cxxTemperature(); + cxxTemperature(PHRQ_io *io=NULL); + cxxTemperature(struct temperature *, PHRQ_io *io=NULL); + ~cxxTemperature(); struct temperature *cxxTemperature2temperature(PHREEQC_PTR_ARG); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index b44bcc5a..12eeacc5 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -31,8 +31,7 @@ cxxKinetics::cxxKinetics(PHRQ_io *io) // // default constructor for cxxKinetics // -: cxxNumKeyword(), - PHRQ_base(io) +: cxxNumKeyword(io) { step_divide = 1.0; rk = 3; @@ -49,8 +48,7 @@ cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr, PHRQ_io *io) // constructor for cxxKinetics from struct kinetics // : -cxxNumKeyword(), -PHRQ_base(io), +cxxNumKeyword(io), totals(kinetics_ptr->totals) { int i; @@ -68,7 +66,7 @@ totals(kinetics_ptr->totals) // kinetics components for (i = 0; i < kinetics_ptr->count_comps; i++) { - cxxKineticsComp ec(&(kinetics_ptr->comps[i])); + cxxKineticsComp ec(&(kinetics_ptr->comps[i]), this->Get_io()); std::string str(ec.get_rate_name()); //this->kineticsComps[str] = ec; this->kineticsComps.push_back(ec); @@ -89,8 +87,7 @@ totals(kinetics_ptr->totals) } cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; step_divide = 1.0; @@ -411,7 +408,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 4: // component { - cxxKineticsComp ec; + cxxKineticsComp ec(this->Get_io()); // preliminary read #ifdef SKIP @@ -443,7 +440,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(P_INSTANCE_COMMA parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is); + CParser reread(P_INSTANCE_COMMA is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); @@ -463,7 +460,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } else { - cxxKineticsComp ec1; + cxxKineticsComp ec1(this->Get_io()); ec1.read_raw(P_INSTANCE_COMMA reread, false); std::string str(ec1.get_rate_name()); this->kineticsComps.push_back(ec1); diff --git a/cxxKinetics.h b/cxxKinetics.h index b5a1cdb4..fb8fc9c6 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -12,14 +12,14 @@ #include "PHRQ_base.h" class cxxMix; -class cxxKinetics:public cxxNumKeyword, PHRQ_base +class cxxKinetics:public cxxNumKeyword { public: - cxxKinetics(PHRQ_io *io = NULL); - cxxKinetics(struct kinetics *, PHRQ_io *io); + cxxKinetics(PHRQ_io *io=NULL); + cxxKinetics(struct kinetics *, PHRQ_io *io=NULL); cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, - int n_user, PHRQ_io *io); + int n_user, PHRQ_io *io=NULL); ~cxxKinetics(); struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); diff --git a/cxxMix.cxx b/cxxMix.cxx index 85deaa00..5623e043 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -28,8 +28,7 @@ cxxMix::cxxMix(PHRQ_io *io) // // default constructor for cxxMix // -: cxxNumKeyword(), - PHRQ_base(io) +: cxxNumKeyword(io) { } @@ -38,8 +37,7 @@ cxxMix::cxxMix(struct mix *mix_ptr, PHRQ_io *io) // constructor for cxxMix from struct mix // : -cxxNumKeyword(), -PHRQ_base(io) +cxxNumKeyword(io) { int i; diff --git a/cxxMix.h b/cxxMix.h index 8a6acd48..e4af2554 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -10,12 +10,12 @@ #include "NumKeyword.h" #include "PHRQ_base.h" -class cxxMix:public cxxNumKeyword, PHRQ_base +class cxxMix:public cxxNumKeyword { public: cxxMix(PHRQ_io *io=NULL); - cxxMix(struct mix *, PHRQ_io *io); + cxxMix(struct mix *, PHRQ_io *io=NULL); ~cxxMix(); struct mix *cxxMix2mix(PHREEQC_PTR_ARG); diff --git a/dumper.cpp b/dumper.cpp index c0c169cd..91379327 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -3,13 +3,17 @@ #include "dumper.h" #include "Parser.h" -dumper::dumper(void) +dumper::dumper(PHRQ_io *io) +: +PHRQ_base(io) { this->file_name = "dump.out"; this->append = false; this->on = false; } -dumper::dumper(CParser & parser) +dumper::dumper(CParser & parser, PHRQ_io *io) +: +PHRQ_base(io) { this->file_name = "dump.out"; this->append = false; diff --git a/dumper.h b/dumper.h index 312fae33..e3a79e22 100644 --- a/dumper.h +++ b/dumper.h @@ -7,11 +7,11 @@ #include "StorageBinList.h" class CParser; -class dumper +class dumper: public PHRQ_base { public: - dumper(void); - dumper(CParser & parser); + dumper(PHRQ_io *io=NULL); + dumper(CParser & parser, PHRQ_io *io=NULL); ~dumper(void); bool Read(CParser & parser); void SetAll(bool tf); diff --git a/runner.cpp b/runner.cpp index 622e7063..fb98feb2 100644 --- a/runner.cpp +++ b/runner.cpp @@ -1,14 +1,18 @@ #include "runner.h" #include "Parser.h" #include "NA.h" -runner::runner(void) +runner::runner(PHRQ_io *io) +: +PHRQ_base(io) { this->time_step = NA; this->start_time = NA; this->run_cells = false; } -runner::runner(CParser & parser) +runner::runner(CParser & parser, PHRQ_io *io) +: +PHRQ_base(io) { this->time_step = NA; this->start_time = NA; diff --git a/runner.h b/runner.h index 033f659c..60c71c2e 100644 --- a/runner.h +++ b/runner.h @@ -4,13 +4,14 @@ #include // std::string #include "StorageBinList.h" +#include "PHRQ_base.h" class CParser; -class runner +class runner: public PHRQ_base { public: - runner(void); - runner(CParser & parser); + runner(PHRQ_io *io=NULL); + runner(CParser & parser, PHRQ_io *io=NULL); virtual ~runner(void); bool Read(CParser & parser); StorageBinListItem & Get_cells(void) { return(this->cells); }; From 11da9fec8f9ec6378786edb6879ed05f03e62312 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Sep 2011 22:38:29 +0000 Subject: [PATCH 0244/1077] Worked on output. Added output_string to PHRQ_io. Rewrote output_msg in PHRQ_io_output.cpp to move phreeqc processing out of PHRQ_io. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5639 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ PHRQ_io.h | 2 +- Phreeqc.cpp | 3 ++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 33927319..4bf3b7eb 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -336,7 +336,82 @@ output_handler(const int type, const char *err_str, const bool stop, //return (OK); return 1; } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_string(const int type, std::string str) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + + case OUTPUT_ERROR: + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "%s", str.c_str()); + } + fflush(error_file); + break; + + case OUTPUT_WARNING: + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "%s", str.c_str()); + } + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "%s", str.c_str()); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "%s", str.c_str()); + } + break; + case OUTPUT_CHECKLINE: + case OUTPUT_MESSAGE: + case OUTPUT_BASIC: + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "%s", str.c_str()); + } + break; + case OUTPUT_PUNCH: + if (punch_file != NULL && punch_file_on) + { + fprintf(punch_file, "%s", str.c_str()); + } + break; + case OUTPUT_LOG: + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "%s", str.c_str()); + } + break; + case OUTPUT_SCREEN: + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "%s", str.c_str()); + fflush(error_file); + } + break; + case OUTPUT_STDERR: + case OUTPUT_CVODE: + if (stderr != NULL) + { + fprintf(stderr, "%s", str.c_str()); + fflush(stderr); + } + break; + case OUTPUT_DUMP: + if (dump_file != NULL && dump_file_on) + { + fprintf(dump_file, "%s", str.c_str()); + } + break; + } + return; +} /* ---------------------------------------------------------------------- */ int PHRQ_io:: close_output_files(void) diff --git a/PHRQ_io.h b/PHRQ_io.h index ebeb5770..38422c11 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -52,7 +52,7 @@ typedef enum int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); - + void output_string(const int type, std::string str); void Set_error_count(int i) { this->error_count = i; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e873a5eb..9c1f4dcd 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1184,8 +1184,9 @@ void Phreeqc::init(void) gas_in = FALSE; count_strings = 0; - +#ifdef MULTICHART chart_handler.Set_io(&this->phrq_io); +#endif run_info.Set_io(&this->phrq_io); this->clear_cookie(); From 50b369a29484e77780a474a1887c09b62186c90e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Sep 2011 00:08:29 +0000 Subject: [PATCH 0245/1077] Compiles all configurations of phreeqcpp.vcproj Does not use callbacks. Uses phrq_io instance of PHRQ_io. I am sure it will not compile as plain phreeqc without modification. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5640 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.h | 1 + PHRQ_base.cxx | 14 ++++-- PHRQ_base.h | 2 +- PHRQ_io.cpp | 5 ++ Parser.cxx | 10 ++-- Phreeqc.cpp | 76 +++++++++++++++--------------- Phreeqc.h | 4 +- ReadClass.cxx | 112 ++++++++++++++++++++++----------------------- SSassemblageSS.cxx | 5 ++ 9 files changed, 126 insertions(+), 103 deletions(-) diff --git a/ISolutionComp.h b/ISolutionComp.h index 295098bd..217b4469 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -6,6 +6,7 @@ #include #include #include "Phreeqc_class.h" +#include "PHRQ_base.h" // forward declarations class cxxISolution; // reqd for read and dump_xml diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index ea7e26d6..e64e1a13 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -1,6 +1,6 @@ #include "PHRQ_base.h" #include - +#include "PHRQ_io.h" PHRQ_base:: PHRQ_base(void) { @@ -21,18 +21,23 @@ PHRQ_base:: } void PHRQ_base:: -error_msg(const std::string & stdstr) +error_msg(const std::string & stdstr, int stop) { this->error_count++; if (this->io) { //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_ERROR, stdstr, stop, "", args); + this->io->output_string(PHRQ_io::OUTPUT_ERROR, stdstr); } else { std::cerr << stdstr << std::endl; std::cout << stdstr << std::endl; } + if (stop == 0) + { + throw "PHRQ_base error message"; + } } void PHRQ_base:: @@ -41,6 +46,7 @@ warning_msg(const std::string & stdstr) if (this->io) { //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_WARNING, stdstr, stop, "", args); + this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); } else { @@ -52,9 +58,11 @@ warning_msg(const std::string & stdstr) void PHRQ_base:: output_msg(const std::string & stdstr) { + bool stop = false; if (this->io) { - //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_MESSAGE, stdstr, stop, "", args); + //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr, stop, ""); + this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); } else { diff --git a/PHRQ_base.h b/PHRQ_base.h index 15d93718..af15b796 100644 --- a/PHRQ_base.h +++ b/PHRQ_base.h @@ -15,7 +15,7 @@ public: // methods void output_msg(const std::string &); - void error_msg(const std::string &); + void error_msg(const std::string &, int stop=0); void warning_msg(const std::string &); void Set_io(PHRQ_io * p_io) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 4bf3b7eb..803bfb3e 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -346,10 +346,15 @@ output_string(const int type, std::string str) { case OUTPUT_ERROR: + this->error_count++; if (error_file != NULL && error_file_on) { fprintf(error_file, "%s", str.c_str()); } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "%s", str.c_str()); + } fflush(error_file); break; diff --git a/Parser.cxx b/Parser.cxx index f8e698c8..892617aa 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -17,6 +17,7 @@ #endif #include "Parser.h" #include "output.h" +#include "PHRQ_io.h" //extern char *string_hsave(const char *str); @@ -140,7 +141,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; case EO_KEYWORDS: @@ -148,7 +150,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -157,7 +160,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; } diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9c1f4dcd..c4d0bac3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -455,7 +455,7 @@ size_t Phreeqc::list_components(std::list &list_c) // solutions for (i = 0; i < count_solution; i++) { - cxxSolution entity(solution[i], &this->phrq_io); + cxxSolution entity(solution[i], &phrq_io); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -470,7 +470,7 @@ size_t Phreeqc::list_components(std::list &list_c) // pure phases for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage entity(&pp_assemblage[i], &this->phrq_io); + cxxPPassemblage entity(&pp_assemblage[i], &phrq_io); entity.totalize(this); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -478,7 +478,7 @@ size_t Phreeqc::list_components(std::list &list_c) // exchangers for (i = 0; i < count_exchange; i++) { - cxxExchange entity(&exchange[i], &this->phrq_io); + cxxExchange entity(&exchange[i], &phrq_io); entity.totalize(); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -486,7 +486,7 @@ size_t Phreeqc::list_components(std::list &list_c) // surfaces for (i = 0; i < count_surface; i++) { - cxxSurface entity(&surface[i], &this->phrq_io); + cxxSurface entity(&surface[i], &phrq_io); entity.totalize(); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -494,7 +494,7 @@ size_t Phreeqc::list_components(std::list &list_c) // gas phases for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase entity(&gas_phase[i], &this->phrq_io); + cxxGasPhase entity(&gas_phase[i], &phrq_io); entity.totalize(this); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -511,7 +511,7 @@ size_t Phreeqc::list_components(std::list &list_c) for (i = 0; i < count_kinetics; i++) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i], &this->phrq_io); + cxxKinetics entity(&kinetics[i], &phrq_io); accumulator.add_extensive(entity.get_totals(), 1.0); } @@ -1185,42 +1185,42 @@ void Phreeqc::init(void) count_strings = 0; #ifdef MULTICHART - chart_handler.Set_io(&this->phrq_io); + chart_handler.Set_io(&phrq_io); #endif - run_info.Set_io(&this->phrq_io); + run_info.Set_io(&phrq_io); this->clear_cookie(); return; } -void * Phreeqc::get_cookie() -{ - if (cookie_list.size() > 0) - { - return this->cookie_list.front(); - } - else - { - return NULL; - } -} -void Phreeqc::set_cookie(std::istream * cookie) -{ - this->cookie_list.push_front(cookie); -} -void Phreeqc::clear_cookie(void) -{ - while (this->cookie_list.size() > 0) - { - this->pop_cookie(); - } -} -void Phreeqc::pop_cookie() -{ - if (cookie_list.size() > 0) - { - delete this->cookie_list.front(); - this->cookie_list.pop_front(); - } -} +//void * Phreeqc::get_cookie() +//{ +// if (cookie_list.size() > 0) +// { +// return this->cookie_list.front(); +// } +// else +// { +// return NULL; +// } +//} +//void Phreeqc::set_cookie(std::istream * cookie) +//{ +// this->cookie_list.push_front(cookie); +//} +//void Phreeqc::clear_cookie(void) +//{ +// while (this->cookie_list.size() > 0) +// { +// this->pop_cookie(); +// } +//} +//void Phreeqc::pop_cookie() +//{ +// if (cookie_list.size() > 0) +// { +// delete this->cookie_list.front(); +// this->cookie_list.pop_front(); +// } +//} diff --git a/Phreeqc.h b/Phreeqc.h index 177ba749..5ab75822 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -253,7 +253,7 @@ int write_banner(void); public: int close_input_files(void); int close_output_files(void); -CLASS_STATIC int getc_callback(void *cookie); +//CLASS_STATIC int getc_callback(void *cookie); #if defined(MERGE_INCLUDE_FILES) CLASS_STATIC int istream_getc(void *cookie); #endif /* #if defined(MERGE_INCLUDE_FILES) */ @@ -1404,7 +1404,7 @@ protected: std::list cookie_list; std::ifstream * in_stream; std::ifstream * db_stream; - PHRQ_io phrq_io; + }; #endif /* _INC_PHREEQC_H */ diff --git a/ReadClass.cxx b/ReadClass.cxx index c71b047e..c45c4405 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -94,7 +94,7 @@ read_solution_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -110,7 +110,7 @@ read_solution_raw(void) parser.get_option(vopts, next_char); - cxxSolution sol(&this->phrq_io); + cxxSolution sol(&phrq_io); sol.read_raw(PHREEQC_THIS_COMMA parser); struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); int n; @@ -187,7 +187,7 @@ read_exchange_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -202,7 +202,7 @@ read_exchange_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxExchange ex(&this->phrq_io); + cxxExchange ex(&phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); int n; @@ -281,7 +281,7 @@ read_surface_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -296,7 +296,7 @@ read_surface_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxSurface ex(&this->phrq_io); + cxxSurface ex(&phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); int n; @@ -376,7 +376,7 @@ read_equilibrium_phases_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -391,7 +391,7 @@ read_equilibrium_phases_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxPPassemblage ex(&this->phrq_io); + cxxPPassemblage ex(&phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); int n; @@ -472,7 +472,7 @@ read_kinetics_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -487,7 +487,7 @@ read_kinetics_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxKinetics ex(&this->phrq_io); + cxxKinetics ex(&phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); int n; @@ -567,7 +567,7 @@ read_solid_solutions_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -664,7 +664,7 @@ read_gas_phase_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -679,7 +679,7 @@ read_gas_phase_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxGasPhase ex(&this->phrq_io); + cxxGasPhase ex(&phrq_io); ex.read_raw(PHREEQC_THIS_COMMA parser); struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); int n; @@ -758,7 +758,7 @@ read_reaction_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -853,7 +853,7 @@ read_mix_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -868,7 +868,7 @@ read_mix_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxMix ex(&this->phrq_io); + cxxMix ex(&phrq_io); ex.read_raw(parser); struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); int n; @@ -948,7 +948,7 @@ read_temperature_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) @@ -964,7 +964,7 @@ read_temperature_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxTemperature ex(&this->phrq_io); + cxxTemperature ex(&phrq_io); ex.read_raw(parser); struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); int n; @@ -1025,7 +1025,7 @@ read_dump(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1043,7 +1043,7 @@ read_dump(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - dumper dmp(parser, &this->phrq_io); + dumper dmp(parser, &phrq_io); dump_info = dmp; @@ -1077,7 +1077,7 @@ read_delete(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1095,7 +1095,7 @@ read_delete(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - StorageBinList deleter(parser, &this->phrq_io); + StorageBinList deleter(parser, &phrq_io); delete_info = deleter; @@ -1129,7 +1129,7 @@ read_run_cells(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1147,7 +1147,7 @@ read_run_cells(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - runner r(parser, &this->phrq_io); + runner r(parser, &phrq_io); run_info = r; @@ -1292,7 +1292,7 @@ read_solution_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1319,14 +1319,14 @@ read_solution_modify(void) return (ERROR); } - cxxSolution sol(solution[n], &this->phrq_io); + cxxSolution sol(solution[n], &phrq_io); // Clear activities so we can know what was read sol.clear_master_activity(); sol.read_raw(PHREEQC_THIS_COMMA parser, false); - cxxSolution orig(solution[n], &this->phrq_io ); + cxxSolution orig(solution[n], &phrq_io ); sol.modify_activities(PHREEQC_THIS_COMMA orig); @@ -1390,7 +1390,7 @@ read_equilibrium_phases_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1417,7 +1417,7 @@ read_equilibrium_phases_modify(void) } // read entity - cxxPPassemblage entity(&(pp_assemblage[n]), &this->phrq_io); + cxxPPassemblage entity(&(pp_assemblage[n]), &phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1483,7 +1483,7 @@ read_exchange_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1510,7 +1510,7 @@ read_exchange_modify(void) } // read entity - cxxExchange entity(&(exchange[n]), &this->phrq_io); + cxxExchange entity(&(exchange[n]), &phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1591,7 +1591,7 @@ read_surface_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1618,7 +1618,7 @@ read_surface_modify(void) } // read entity - cxxSurface entity(&(surface[n]), &this->phrq_io); + cxxSurface entity(&(surface[n]), &phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1680,7 +1680,7 @@ read_solid_solutions_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1768,7 +1768,7 @@ read_gas_phase_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1795,7 +1795,7 @@ read_gas_phase_modify(void) } // read entity - cxxGasPhase entity(&(gas_phase[n]), &this->phrq_io); + cxxGasPhase entity(&(gas_phase[n]), &phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); @@ -1856,7 +1856,7 @@ read_kinetics_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; // ?? std::ostringstream oss_err; // ?? - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1883,7 +1883,7 @@ read_kinetics_modify(void) } // read entity - cxxKinetics entity(&(kinetics[n]), &this->phrq_io); + cxxKinetics entity(&(kinetics[n]), &phrq_io); entity.read_raw(PHREEQC_THIS_COMMA parser, false); // save entity @@ -1944,7 +1944,7 @@ read_reaction_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -2680,7 +2680,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_solution; i++) { - cxxSolution cxxsoln(solution[i], &this->phrq_io); + cxxSolution cxxsoln(solution[i], &phrq_io); cxxsoln.dump_raw(os,0); } } @@ -2691,7 +2691,7 @@ dump_ostream(std::ostream& os) { if (solution_bsearch(*it, &n, FALSE) != NULL) { - cxxSolution cxxsoln(solution[n], &this->phrq_io); + cxxSolution cxxsoln(solution[n], &phrq_io); cxxsoln.dump_raw(os,0); } } @@ -2705,7 +2705,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage cxxentity(&pp_assemblage[i], &this->phrq_io); + cxxPPassemblage cxxentity(&pp_assemblage[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2717,7 +2717,7 @@ dump_ostream(std::ostream& os) if (pp_assemblage_bsearch(*it, &n) != NULL) { - cxxPPassemblage cxxentity(&pp_assemblage[n], &this->phrq_io); + cxxPPassemblage cxxentity(&pp_assemblage[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2731,7 +2731,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_exchange; i++) { - cxxExchange cxxentity(&exchange[i], &this->phrq_io); + cxxExchange cxxentity(&exchange[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2743,7 +2743,7 @@ dump_ostream(std::ostream& os) if (exchange_bsearch(*it, &n) != NULL) { - cxxExchange cxxentity(&exchange[n], &this->phrq_io); + cxxExchange cxxentity(&exchange[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2757,7 +2757,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_surface; i++) { - cxxSurface cxxentity(&surface[i], &this->phrq_io); + cxxSurface cxxentity(&surface[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2769,7 +2769,7 @@ dump_ostream(std::ostream& os) if (surface_bsearch(*it, &n) != NULL) { - cxxSurface cxxentity(&surface[n], &this->phrq_io); + cxxSurface cxxentity(&surface[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2809,7 +2809,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase cxxentity(&gas_phase[i], &this->phrq_io); + cxxGasPhase cxxentity(&gas_phase[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2821,7 +2821,7 @@ dump_ostream(std::ostream& os) if (gas_phase_bsearch(*it, &n) != NULL) { - cxxGasPhase cxxentity(&gas_phase[n], &this->phrq_io); + cxxGasPhase cxxentity(&gas_phase[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2835,7 +2835,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_kinetics; i++) { - cxxKinetics cxxentity(&kinetics[i], &this->phrq_io); + cxxKinetics cxxentity(&kinetics[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2847,7 +2847,7 @@ dump_ostream(std::ostream& os) if (kinetics_bsearch(*it, &n) != NULL) { - cxxKinetics cxxentity(&kinetics[n], &this->phrq_io); + cxxKinetics cxxentity(&kinetics[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2861,7 +2861,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_mix; i++) { - cxxMix cxxentity(&mix[i], &this->phrq_io); + cxxMix cxxentity(&mix[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2873,7 +2873,7 @@ dump_ostream(std::ostream& os) if (mix_bsearch(*it, &n) != NULL) { - cxxMix cxxentity(&mix[n], &this->phrq_io); + cxxMix cxxentity(&mix[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2913,7 +2913,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_temperature; i++) { - cxxTemperature cxxentity(&temperature[i], &this->phrq_io); + cxxTemperature cxxentity(&temperature[i], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2925,7 +2925,7 @@ dump_ostream(std::ostream& os) if (temperature_bsearch(*it, &n) != NULL) { - cxxTemperature cxxentity(&temperature[n], &this->phrq_io); + cxxTemperature cxxentity(&temperature[n], &phrq_io); cxxentity.dump_raw(os,0); } } @@ -2968,7 +2968,7 @@ read_user_graph_handler(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &this->phrq_io); + CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 2c7b55cf..7d4a7e6e 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -101,7 +101,12 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::s s_s_ptr[j].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); if ((*it).second.name.size() <= 0) { +#ifdef PHREEQC_CLASS P_INSTANCE_POINTER error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); +#else + ::error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); +#endif + } assert((*it).second.name.size() > 0); //s_s_ptr[j].total_moles = it->total_moles; From 40bb6533207fde97d92b2241418569d0abc60b7c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Sep 2011 17:24:24 +0000 Subject: [PATCH 0246/1077] Fixed bugs with end of lines for status, warning msg count. Removed PHREEQC_IDENT ifdefs git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5641 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 803bfb3e..f2393938 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -162,7 +162,7 @@ output_handler(const int type, const char *err_str, const bool stop, // status_on = FALSE; //#endif // } - if (error_file != NULL) + if (error_file != NULL && error_file_on) { fprintf(error_file, "ERROR: %s\n", err_str); if (flush) @@ -172,7 +172,7 @@ output_handler(const int type, const char *err_str, const bool stop, sprintf(progress_str, "ERROR: %s\n", err_str); show_progress(type, progress_str); #endif /* PHREEQ98 */ - if (output_file != NULL) + if (output_file != NULL && output_file_on) { fprintf(output_file, "ERROR: %s\n", err_str); #ifdef PHREEQ98 @@ -183,7 +183,7 @@ output_handler(const int type, const char *err_str, const bool stop, } if (stop) { - if (error_file != NULL) + if (error_file != NULL && error_file_on) { fprintf(error_file, "Stopping.\n"); fflush(error_file); @@ -192,7 +192,7 @@ output_handler(const int type, const char *err_str, const bool stop, sprintf(progress_str, "Stopping.\n"); show_progress(type, progress_str); #endif /* PHREEQ98 */ - if (output_file != NULL) + if (output_file != NULL && output_file_on) { fprintf(output_file, "Stopping.\n"); #ifdef PHREEQ98 @@ -208,7 +208,7 @@ output_handler(const int type, const char *err_str, const bool stop, case OUTPUT_WARNING: //if (pr.logfile == TRUE && log_file != NULL) - if (log_file != NULL) + if (log_file != NULL && log_file_on) { fprintf(log_file, "WARNING: %s\n", err_str); if (flush) @@ -233,7 +233,7 @@ output_handler(const int type, const char *err_str, const bool stop, // status_on = FALSE; //#endif // } - if (error_file != NULL) + if (error_file != NULL && error_file_on) { fprintf(error_file, "WARNING: %s\n", err_str); if (flush) @@ -243,7 +243,7 @@ output_handler(const int type, const char *err_str, const bool stop, sprintf(progress_str, "WARNING: %s\n", err_str); show_progress(type, progress_str); #endif /* PHREEQ98 */ - if (output_file != NULL) + if (output_file != NULL && output_file_on) { fprintf(output_file, "WARNING: %s\n", err_str); #ifdef PHREEQ98 @@ -256,7 +256,7 @@ output_handler(const int type, const char *err_str, const bool stop, case OUTPUT_CHECKLINE: //if (pr.echo_input == TRUE) { - if (output_file != NULL) + if (output_file != NULL && output_file_on) { vfprintf(output_file, format, args); #ifdef PHREEQ98 @@ -269,7 +269,7 @@ output_handler(const int type, const char *err_str, const bool stop, break; case OUTPUT_MESSAGE: case OUTPUT_BASIC: - if (output_file != NULL) + if (output_file != NULL && output_file_on) { vfprintf(output_file, format, args); #ifdef PHREEQ98 @@ -280,7 +280,7 @@ output_handler(const int type, const char *err_str, const bool stop, } break; case OUTPUT_PUNCH: - if (punch_file != NULL) + if (punch_file != NULL && punch_file_on) { //if (pr.punch == TRUE && punch.in == TRUE) { @@ -292,7 +292,7 @@ output_handler(const int type, const char *err_str, const bool stop, break; case OUTPUT_LOG: //if (pr.logfile == TRUE && log_file != NULL) - if (log_file != NULL) + if (log_file != NULL && log_file_on) { vfprintf(log_file, format, args); if (flush) @@ -300,7 +300,7 @@ output_handler(const int type, const char *err_str, const bool stop, } break; case OUTPUT_SCREEN: - if (error_file != NULL) + if (error_file != NULL && error_file_on) { vfprintf(error_file, format, args); if (flush) @@ -320,7 +320,7 @@ output_handler(const int type, const char *err_str, const bool stop, } break; case OUTPUT_DUMP: - if (dump_file != NULL) + if (dump_file != NULL && dump_file_on) { vfprintf(dump_file, format, args); if (flush) From 0cf22bd9322b3bc7b0401df84f4631e248b6a334 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Sep 2011 23:44:37 +0000 Subject: [PATCH 0247/1077] Class_release and Release compare with phreeqcpp-trunk. Now need to rip out P_INSTANCES, where possible. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5642 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 60 +---------------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index f2393938..d774c491 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -137,31 +137,12 @@ output_handler(const int type, const char *err_str, const bool stop, const char *format, va_list args) /* ---------------------------------------------------------------------- */ { - int flush; - FILE *save_output = NULL; - - flush = 1; - - //if (get_forward_output_to_log()) - //{ - // save_output = output_file; - // output_file = log_file; - //} + int flush = 1; switch (type) { case OUTPUT_ERROR: -// if (status_on == TRUE) -// { -// if (error_file != NULL) -// { -// fprintf(error_file, "\n"); -// } -//#ifndef DOS -// status_on = FALSE; -//#endif -// } if (error_file != NULL && error_file_on) { fprintf(error_file, "ERROR: %s\n", err_str); @@ -200,9 +181,6 @@ output_handler(const int type, const char *err_str, const bool stop, #endif fflush(output_file); } -////#if defined MULTICHART -//// chart_handler.End_timer(PHREEQC_THIS); -////#endif } break; @@ -218,21 +196,6 @@ output_handler(const int type, const char *err_str, const bool stop, // return (OK); //if (state == ADVECTION && advection_warnings == FALSE) // return (OK); -// if (pr.warnings >= 0) -// { -// if (count_warnings > pr.warnings) -// return (OK); -// } -// if (status_on == TRUE) -// { -// if (error_file != NULL) -// { -// fprintf(error_file, "\n"); -// } -//#ifndef DOS -// status_on = FALSE; -//#endif -// } if (error_file != NULL && error_file_on) { fprintf(error_file, "WARNING: %s\n", err_str); @@ -329,11 +292,6 @@ output_handler(const int type, const char *err_str, const bool stop, break; } - //if (get_forward_output_to_log()) - //{ - // output_file = save_output; - //} - //return (OK); return 1; } /* ---------------------------------------------------------------------- */ @@ -351,10 +309,6 @@ output_string(const int type, std::string str) { fprintf(error_file, "%s", str.c_str()); } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "%s", str.c_str()); - } fflush(error_file); break; @@ -527,13 +481,6 @@ fileop_handler(const int type, int (*PFN) (FILE *)) { FILE *save_output = NULL; - //int forward = get_forward_output_to_log(); - //if (forward) - //{ - // save_output = output_file; - // output_file = log_file; - //} - switch (type) { case OUTPUT_ERROR: @@ -582,11 +529,6 @@ fileop_handler(const int type, int (*PFN) (FILE *)) break; } - //if (forward) - //{ - // output_file = save_output; - //} - //return (OK); return 1; } From b7729cf254142494b9fb05e67e4e41fc4ae6ba4f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 23 Sep 2011 22:33:19 +0000 Subject: [PATCH 0248/1077] Changed all check of input_error to get_input_errors for phreeqc. Started removing PHREEQC_PTR and P_INSTANCE. Redid all read_raw. Breaks some echoing or printing of output. Need to check why. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5646 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- ExchComp.cxx | 6 ++-- ExchComp.h | 2 +- Exchange.cxx | 10 +++--- Exchange.h | 2 +- GasPhase.cxx | 4 +-- GasPhase.h | 2 +- KineticsComp.cxx | 4 +-- KineticsComp.h | 2 +- NameDouble.cxx | 11 ++++--- NameDouble.h | 2 +- PHRQ_base.cxx | 20 ++++++------ PHRQ_base.h | 10 +++--- PHRQ_io.cpp | 7 +++-- PHRQ_io.h | 10 +++--- PPassemblage.cxx | 6 ++-- PPassemblage.h | 2 +- Parser.cxx | 49 +++++++++++++---------------- Parser.h | 21 +++---------- Phreeqc.h | 1 + Reaction.cxx | 6 ++-- Reaction.h | 2 +- ReadClass.cxx | 78 +++++++++++++++++++++++----------------------- SSassemblage.cxx | 10 +++--- SSassemblage.h | 2 +- SSassemblageSS.cxx | 4 +-- SSassemblageSS.h | 2 +- Solution.cxx | 10 +++--- Solution.h | 2 +- StorageBin.cxx | 36 ++++++++++----------- StorageBin.h | 4 +-- Surface.cxx | 18 +++++------ Surface.h | 2 +- SurfaceCharge.cxx | 4 +-- SurfaceCharge.h | 2 +- SurfaceComp.cxx | 6 ++-- SurfaceComp.h | 2 +- cxxKinetics.cxx | 16 +++++----- cxxKinetics.h | 2 +- 39 files changed, 182 insertions(+), 199 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 0c2c7b25..a44ff1e3 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -480,7 +480,7 @@ ChartObject::OpenCSVFile(std::string file_name) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(P_INSTANCE_COMMA f_csv, oss_out, oss_err, this->Get_io()); + CParser parser(f_csv, oss_out, oss_err, this->Get_io()); parser.set_echo_file(CParser::EO_NONE); /* Get lines */ diff --git a/ExchComp.cxx b/ExchComp.cxx index c41a1f64..290cff13 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -335,7 +335,7 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxExchComp::read_raw(CParser & parser, bool check) { std::string str; @@ -488,7 +488,7 @@ cxxExchComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 8: // totals - if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -501,7 +501,7 @@ cxxExchComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 9: // formula_totals - if (this->formula_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/ExchComp.h b/ExchComp.h index 30a7afcb..c1961b45 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -26,7 +26,7 @@ class cxxExchComp: public PHRQ_base void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check=true); + void read_raw(CParser & parser, bool check=true); const std::string &get_formula() const { diff --git a/Exchange.cxx b/Exchange.cxx index d6e7b590..5aabdac3 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -294,7 +294,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxExchange::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -389,21 +389,21 @@ cxxExchange::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(P_INSTANCE_COMMA parser, false); + ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) { cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; - comp.read_raw(P_INSTANCE_COMMA reread, false); + comp.read_raw(reread, false); } else { cxxExchComp ec1(this->Get_io()); - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_formula()); this->exchComps[str] = ec1; } diff --git a/Exchange.h b/Exchange.h index 5224350a..a96555a0 100644 --- a/Exchange.h +++ b/Exchange.h @@ -28,7 +28,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/GasPhase.cxx b/GasPhase.cxx index 0f2c4940..06c83c7b 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -261,7 +261,7 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxGasPhase::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxGasPhase::read_raw(CParser & parser, bool check) { int i; @@ -363,7 +363,7 @@ cxxGasPhase::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 3: // component - if (this->gasPhaseComps.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->gasPhaseComps.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/GasPhase.h b/GasPhase.h index 2e4c6847..56f62ef1 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -35,7 +35,7 @@ class cxxGasPhase:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/KineticsComp.cxx b/KineticsComp.cxx index fb035f40..d2710376 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -208,7 +208,7 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKineticsComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; double d; @@ -324,7 +324,7 @@ cxxKineticsComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 5: // namecoef - if (this->namecoef.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->namecoef.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/KineticsComp.h b/KineticsComp.h index 35e671e4..5fd5c5e4 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -23,7 +23,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); const std::string &get_rate_name() const { diff --git a/NameDouble.cxx b/NameDouble.cxx index 878fbac6..05d7fd9d 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -357,12 +357,12 @@ cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const } } -CParser::STATUS_TYPE cxxNameDouble::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, +CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, std::istream::pos_type & pos) { std::string token; - char * - ctoken; + //char * + // ctoken; double d; @@ -379,8 +379,9 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(PHREEQC_PTR_ARG_COMMA CParser & par { return CParser::PARSER_ERROR; } - ctoken = P_INSTANCE_POINTER string_hsave(token.c_str()); - (*this)[ctoken] = d; + //ctoken = P_INSTANCE_POINTER string_hsave(token.c_str()); + //(*this)[ctoken] = d; + (*this)[token.c_str()] = d; return CParser::PARSER_OK; } diff --git a/NameDouble.h b/NameDouble.h index f8701122..f3f0b743 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -53,7 +53,7 @@ class cxxNameDouble:public dump_raw(std::ostream & s_oss, unsigned int indent) const; CParser::STATUS_TYPE - read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, std::istream::pos_type & pos); + read_raw(CParser & parser, std::istream::pos_type & pos); void add_extensive(const cxxNameDouble & old, double factor); diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index e64e1a13..1e35d4bc 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -5,14 +5,14 @@ PHRQ_base:: PHRQ_base(void) { this->io = NULL; - error_count = 0; + base_error_count = 0; } PHRQ_base:: PHRQ_base(PHRQ_io * p_io) { this->io = p_io; - error_count = 0; + base_error_count = 0; } PHRQ_base:: @@ -23,18 +23,18 @@ PHRQ_base:: void PHRQ_base:: error_msg(const std::string & stdstr, int stop) { - this->error_count++; + this->base_error_count++; if (this->io) { - //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_ERROR, stdstr, stop, "", args); - this->io->output_string(PHRQ_io::OUTPUT_ERROR, stdstr); + this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_ERROR, stdstr.c_str(), stop!=0, "", NULL); + //this->io->output_string(PHRQ_io::OUTPUT_ERROR, stdstr); } else { std::cerr << stdstr << std::endl; std::cout << stdstr << std::endl; } - if (stop == 0) + if (stop != 0) { throw "PHRQ_base error message"; } @@ -45,8 +45,8 @@ warning_msg(const std::string & stdstr) { if (this->io) { - //this->io->phreeqc_handler(ACTION_OUTPUT, OUTPUT_WARNING, stdstr, stop, "", args); - this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); + this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_WARNING, stdstr.c_str(), false, "", NULL); + //this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); } else { @@ -61,8 +61,8 @@ output_msg(const std::string & stdstr) bool stop = false; if (this->io) { - //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr, stop, ""); - this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); + this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); + //this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); } else { diff --git a/PHRQ_base.h b/PHRQ_base.h index af15b796..5148eab6 100644 --- a/PHRQ_base.h +++ b/PHRQ_base.h @@ -26,18 +26,18 @@ public: { return this->io; } - void Set_error_count(int i) + void Set_base_error_count(int i) { - this->error_count = i; + this->base_error_count = i; } - int Get_error_count(void) + int Get_base_error_count(void) { - return this->error_count; + return this->base_error_count; } // data private: PHRQ_io * io; - int error_count; + int base_error_count; }; #endif /* _PHRQBASE_H */ diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index d774c491..0179b791 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -17,7 +17,7 @@ PHRQ_io(void) punch_file = NULL; /* OUTPUT_PUNCH */ error_file = NULL; /* OUTPUT_ERROR */ dump_file = NULL; /* OUTPUT_DUMP */ - int error_count = 0; + io_error_count = 0; output_file_on = true; log_file_on = false; @@ -137,12 +137,13 @@ output_handler(const int type, const char *err_str, const bool stop, const char *format, va_list args) /* ---------------------------------------------------------------------- */ { - int flush = 1; + int flush = 0; switch (type) { case OUTPUT_ERROR: + io_error_count++; if (error_file != NULL && error_file_on) { fprintf(error_file, "ERROR: %s\n", err_str); @@ -304,7 +305,7 @@ output_string(const int type, std::string str) { case OUTPUT_ERROR: - this->error_count++; + //this->io_error_count++; if (error_file != NULL && error_file_on) { fprintf(error_file, "%s", str.c_str()); diff --git a/PHRQ_io.h b/PHRQ_io.h index 38422c11..a1f34116 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -53,13 +53,13 @@ typedef enum int close_output_files(void); static int istream_getc(void *cookie); void output_string(const int type, std::string str); - void Set_error_count(int i) + void Set_io_error_count(int i) { - this->error_count = i; + this->io_error_count = i; } - int Get_error_count(void) + int Get_io_error_count(void) { - return this->error_count; + return this->io_error_count; } void Set_input_file(FILE * in) { @@ -146,7 +146,7 @@ private: FILE *punch_file; /* OUTPUT_PUNCH */ FILE *error_file; /* OUTPUT_ERROR */ FILE *dump_file; /* OUTPUT_DUMP */ - int error_count; + int io_error_count; bool output_file_on; bool log_file_on; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 4a02a710..ec8da3ef 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -168,7 +168,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxPPassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -221,7 +221,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 0: // eltList - if (this->eltList.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->eltList.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -268,7 +268,7 @@ cxxPPassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) diff --git a/PPassemblage.h b/PPassemblage.h index 523dfc8a..851224b3 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -27,7 +27,7 @@ class cxxPPassemblage:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); const cxxNameDouble & get_totals() const { diff --git a/Parser.cxx b/Parser.cxx index 892617aa..d15fceac 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -25,7 +25,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, PHRQ_io *io): +CParser::CParser(std::istream & input, PHRQ_io *io): PHRQ_base(io), m_input_stream(input), m_output_stream(std::cout), @@ -38,12 +38,9 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif } -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, PHRQ_io *io) +CParser::CParser(std::istream & input, std::ostream & output, PHRQ_io *io) : PHRQ_base(io), m_input_stream(input), @@ -57,12 +54,9 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif } -CParser::CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error, PHRQ_io *io) +CParser::CParser(std::istream & input, std::ostream & output, std::ostream & error, PHRQ_io *io) : PHRQ_base(io), m_input_stream(input), @@ -76,9 +70,6 @@ m_next_keyword(KT_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif } CParser::~CParser() @@ -142,7 +133,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(), false, "", NULL); + //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; case EO_KEYWORDS: @@ -151,7 +143,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(), false, "", NULL); + //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -161,7 +154,8 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(),false,"",NULL); + //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; } @@ -174,7 +168,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; - error_msg(msg, OT_STOP); + error_msg(msg.str().c_str(), OT_STOP); } // Check keyword @@ -183,7 +177,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "Expected data for " << str << ", but got a keyword ending data block."; - error_msg(msg, OT_CONTINUE); + error_msg(msg.str().c_str(), OT_CONTINUE); incr_input_error(); } m_line_type = i; @@ -517,7 +511,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, { std::ostringstream err; err << "Unknown unit, " << tot_units; - error_msg(err, OT_CONTINUE); + error_msg(err.str().c_str(), OT_CONTINUE); } return PARSER_ERROR; } @@ -578,7 +572,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, std::ostringstream err; err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; - error_msg(err, OT_CONTINUE); + error_msg(err.str().c_str(), OT_CONTINUE); } return PARSER_ERROR; } @@ -913,7 +907,7 @@ CParser::get_option(const std::vector < std::string > &opt_list, int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) { - ERROR_MESSAGE_QUALIFIER error_msg(err_str, (int) ot); + PHRQ_base::error_msg(err_str, (int) ot); m_error_stream << "ERROR: " << err_str << "\n"; m_error_stream.flush(); @@ -1023,7 +1017,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Element name must be followed by " << "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); incr_input_error(); return PARSER_ERROR; } @@ -1039,7 +1033,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "End of line or " "/" " encountered before end of parentheses, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); return PARSER_ERROR; } paren1.insert(paren1.end(), *ptr); // element.push_back(c); @@ -1057,7 +1051,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << " " "/" " must follow parentheses " << "ending first half of redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); return PARSER_ERROR; } ++ptr; @@ -1068,7 +1062,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Redox couple must be two redox states " << "of the same element, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); return PARSER_ERROR; } if (*ptr != '(') @@ -1076,7 +1070,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Element name must be followed by " "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); incr_input_error(); return PARSER_ERROR; } @@ -1091,7 +1085,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "End of line or " "/" " encountered before end of parentheses, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); return PARSER_ERROR; } paren2.insert(paren2.end(), *ptr); // element.push_back(c); @@ -1115,7 +1109,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Both parts of redox couple are the same, " << token << "."; - error_msg(err_msg, OT_CONTINUE); + error_msg(err_msg.str().c_str(), OT_CONTINUE); return PARSER_ERROR; } return PARSER_OK; @@ -1369,7 +1363,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, int CParser:: incr_input_error() { - ++ ERROR_MESSAGE_QUALIFIER input_error; return ++m_input_error; } diff --git a/Parser.h b/Parser.h index 976bd39a..0dc5ee11 100644 --- a/Parser.h +++ b/Parser.h @@ -8,25 +8,14 @@ #include // std::ostream #include // std::istream #include "Phreeqc_class.h" -#if defined (PHREEQC_CLASS) -class Phreeqc; -#define PHREEQC_NAME_SPACE Phreeqc:: -#define PHREEQC_COOKIE this->p_instance-> -#define ERROR_MESSAGE_QUALIFIER this->p_instance-> -#else -#define PHREEQC_NAME_SPACE :: -#define PHREEQC_COOKIE -#define ERROR_MESSAGE_QUALIFIER :: -extern int input_error; -#endif #include "PHRQ_base.h" class CParser: public PHRQ_base { public: - CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, PHRQ_io *io=NULL); - CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, PHRQ_io *io=NULL); - CParser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, + CParser(std::istream & input, PHRQ_io *io=NULL); + CParser(std::istream & input, std::ostream & output, PHRQ_io *io=NULL); + CParser(std::istream & input, std::ostream & output, std::ostream & error, PHRQ_io *io=NULL); virtual ~ CParser(); @@ -321,9 +310,7 @@ class CParser: public PHRQ_base ECHO_OPTION echo_file; std::string accumulated; bool accumulate; -#if defined(PHREEQC_CLASS) - Phreeqc * p_instance; -#endif + }; // Global functions diff --git a/Phreeqc.h b/Phreeqc.h index 5ab75822..aad9ee8a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1374,6 +1374,7 @@ int string_trim_right(char *str); int string_trim_left(char *str); CLASS_STATIC LDBLE under(LDBLE xval); void zero_double(LDBLE * target, int n); +int get_input_errors(void); #ifdef PHREEQ98 void AddToCEntry(char *a, int l, int i); diff --git a/Reaction.cxx b/Reaction.cxx index ecdbf826..daaa3c24 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -222,7 +222,7 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, const bool check) +cxxReaction::read_raw(CParser & parser, const bool check) { int j; @@ -298,7 +298,7 @@ cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, const bool check) break; case 1: // reactant_list - if (this->reactantList.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->reactantList.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -310,7 +310,7 @@ cxxReaction::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, const bool check) break; case 2: // element_list - if (this->elementList.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->elementList.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/Reaction.h b/Reaction.h index 1172ec44..9ae96e0d 100644 --- a/Reaction.h +++ b/Reaction.h @@ -24,7 +24,7 @@ class cxxReaction:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check); + void read_raw(CParser & parser, bool check); cxxNameDouble &get_elementList(void) { return this->elementList; diff --git a/ReadClass.cxx b/ReadClass.cxx index c45c4405..3d282f28 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -94,7 +94,7 @@ read_solution_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -111,7 +111,7 @@ read_solution_raw(void) cxxSolution sol(&phrq_io); - sol.read_raw(PHREEQC_THIS_COMMA parser); + sol.read_raw(parser); struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); int n; @@ -187,7 +187,7 @@ read_exchange_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -203,7 +203,7 @@ read_exchange_raw(void) parser.get_option(vopts, next_char); cxxExchange ex(&phrq_io); - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); int n; @@ -281,7 +281,7 @@ read_surface_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -297,7 +297,7 @@ read_surface_raw(void) parser.get_option(vopts, next_char); cxxSurface ex(&phrq_io); - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); int n; @@ -376,7 +376,7 @@ read_equilibrium_phases_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -392,7 +392,7 @@ read_equilibrium_phases_raw(void) parser.get_option(vopts, next_char); cxxPPassemblage ex(&phrq_io); - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); int n; @@ -472,7 +472,7 @@ read_kinetics_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -488,7 +488,7 @@ read_kinetics_raw(void) parser.get_option(vopts, next_char); cxxKinetics ex(&phrq_io); - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); int n; @@ -567,7 +567,7 @@ read_solid_solutions_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -583,7 +583,7 @@ read_solid_solutions_raw(void) parser.get_option(vopts, next_char); cxxSSassemblage ex; - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); int n; @@ -664,7 +664,7 @@ read_gas_phase_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -680,7 +680,7 @@ read_gas_phase_raw(void) parser.get_option(vopts, next_char); cxxGasPhase ex(&phrq_io); - ex.read_raw(PHREEQC_THIS_COMMA parser); + ex.read_raw(parser); struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); int n; @@ -758,7 +758,7 @@ read_reaction_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -774,7 +774,7 @@ read_reaction_raw(void) parser.get_option(vopts, next_char); cxxReaction ex; - ex.read_raw(PHREEQC_THIS_COMMA parser, true); + ex.read_raw(parser, true); struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); int n; @@ -853,7 +853,7 @@ read_mix_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -948,7 +948,7 @@ read_temperature_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) @@ -1025,7 +1025,7 @@ read_dump(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1077,7 +1077,7 @@ read_delete(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1129,7 +1129,7 @@ read_run_cells(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1230,7 +1230,7 @@ read_solution_modify(void) } cxxSolution sol(solution[n]); - sol.read_raw(PHREEQC_THIS_COMMA parser, false); + sol.read_raw(parser, false); struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); @@ -1292,7 +1292,7 @@ read_solution_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1324,7 +1324,7 @@ read_solution_modify(void) // Clear activities so we can know what was read sol.clear_master_activity(); - sol.read_raw(PHREEQC_THIS_COMMA parser, false); + sol.read_raw(parser, false); cxxSolution orig(solution[n], &phrq_io ); @@ -1390,7 +1390,7 @@ read_equilibrium_phases_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1418,7 +1418,7 @@ read_equilibrium_phases_modify(void) // read entity cxxPPassemblage entity(&(pp_assemblage[n]), &phrq_io); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); @@ -1483,7 +1483,7 @@ read_exchange_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1511,7 +1511,7 @@ read_exchange_modify(void) // read entity cxxExchange entity(&(exchange[n]), &phrq_io); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); @@ -1591,7 +1591,7 @@ read_surface_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1619,7 +1619,7 @@ read_surface_modify(void) // read entity cxxSurface entity(&(surface[n]), &phrq_io); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct surface *entity_ptr = entity.cxxSurface2surface(PHREEQC_THIS); @@ -1680,7 +1680,7 @@ read_solid_solutions_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1708,7 +1708,7 @@ read_solid_solutions_modify(void) // read entity cxxSSassemblage entity(&(s_s_assemblage[n])); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); @@ -1768,7 +1768,7 @@ read_gas_phase_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1796,7 +1796,7 @@ read_gas_phase_modify(void) // read entity cxxGasPhase entity(&(gas_phase[n]), &phrq_io); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); gas_phase_free(&(gas_phase[n])); @@ -1856,7 +1856,7 @@ read_kinetics_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; // ?? std::ostringstream oss_err; // ?? - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1884,7 +1884,7 @@ read_kinetics_modify(void) // read entity cxxKinetics entity(&(kinetics[n]), &phrq_io); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(PHREEQC_THIS); @@ -1944,7 +1944,7 @@ read_reaction_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1972,7 +1972,7 @@ read_reaction_modify(void) // read entity cxxReaction entity(&(irrev[n])); - entity.read_raw(PHREEQC_THIS_COMMA parser, false); + entity.read_raw(parser, false); // save entity struct irrev *entity_ptr = entity.cxxReaction2irrev(PHREEQC_THIS); irrev_free(&(irrev[n])); @@ -2968,7 +2968,7 @@ read_user_graph_handler(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, &phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 5b4121cc..897d7802 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -158,7 +158,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSSassemblage::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -240,21 +240,21 @@ cxxSSassemblage::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(P_INSTANCE_COMMA parser, false); + ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) { cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); } else { cxxSSassemblageSS ec1(this->Get_io()); - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_name()); this->ssAssemblageSSs[str] = ec1; } diff --git a/SSassemblage.h b/SSassemblage.h index ca772ebf..b891ffb5 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -34,7 +34,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); std::map & get_ssAssemblageSSs() { return this->ssAssemblageSSs; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 7d4a7e6e..ba9eac1c 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -230,7 +230,7 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblageSS::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSSassemblageSS::read_raw(CParser & parser, bool check) { std::string str; @@ -346,7 +346,7 @@ cxxSSassemblageSS::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 4: // components - if (this->comps.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) + if (this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); parser.error_msg("Expected phase name and moles for comps.", diff --git a/SSassemblageSS.h b/SSassemblageSS.h index 2d562d42..e0c1e1a0 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -40,7 +40,7 @@ class cxxSSassemblageSS: public PHRQ_base void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); const std::string &get_name() const { diff --git a/Solution.cxx b/Solution.cxx index 509b82e3..09337fd2 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -561,7 +561,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSolution::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; if (vopts.empty()) @@ -633,7 +633,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) continue; case 0: // totals - //if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + //if (this->totals.read_raw(parser, next_char) != // CParser::PARSER_OK) //{ // parser.incr_input_error(); @@ -643,7 +643,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) //} { cxxNameDouble temp_totals; - if (temp_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != CParser::PARSER_OK) + if (temp_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); parser. @@ -659,7 +659,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 1: // activities - if (this->master_activity.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->master_activity.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -672,7 +672,7 @@ cxxSolution::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 2: // gammas - if (this->species_gamma.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->species_gamma.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/Solution.h b/Solution.h index c11ea4f4..9d03dba3 100644 --- a/Solution.h +++ b/Solution.h @@ -157,7 +157,7 @@ class cxxSolution:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); void multiply(double extensive); void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); #ifdef ORCHESTRA diff --git a/StorageBin.cxx b/StorageBin.cxx index d7b58a4b..c86b93c8 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -701,7 +701,7 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent) } void -cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) +cxxStorageBin::read_raw(CParser & parser) { CParser::LINE_TYPE i; while ((i = @@ -735,7 +735,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Solutions[entity.get_n_user()] = entity; } break; @@ -743,7 +743,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_EXCHANGE_RAW: { cxxExchange entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Exchangers[entity.get_n_user()] = entity; } break; @@ -751,7 +751,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_GASPHASE_RAW: { cxxGasPhase entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); GasPhases[entity.get_n_user()] = entity; } break; @@ -759,7 +759,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_KINETICS_RAW: { cxxKinetics entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Kinetics[entity.get_n_user()] = entity; } break; @@ -767,7 +767,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { cxxPPassemblage entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); PPassemblages[entity.get_n_user()] = entity; } break; @@ -775,7 +775,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SSASSEMBLAGE_RAW: { cxxSSassemblage entity; - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); SSassemblages[entity.get_n_user()] = entity; } break; @@ -783,7 +783,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SURFACE_RAW: { cxxSurface entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Surfaces[entity.get_n_user()] = entity; } break; @@ -799,7 +799,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_REACTION_RAW: { cxxReaction entity; - entity.read_raw(P_INSTANCE_COMMA parser, true); + entity.read_raw(parser, true); Reactions[entity.get_n_user()] = entity; } break; @@ -813,7 +813,7 @@ cxxStorageBin::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser) } int -cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) +cxxStorageBin::read_raw_keyword(CParser & parser) { CParser::LINE_TYPE i; int entity_number = -999; @@ -846,7 +846,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Solutions[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -855,7 +855,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_EXCHANGE_RAW: { cxxExchange entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Exchangers[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -864,7 +864,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_GASPHASE_RAW: { cxxGasPhase entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); GasPhases[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -873,7 +873,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_KINETICS_RAW: { cxxKinetics entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Kinetics[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -882,7 +882,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_PPASSEMBLAGE_RAW: { cxxPPassemblage entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); PPassemblages[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -891,7 +891,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SSASSEMBLAGE_RAW: { cxxSSassemblage entity; - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); SSassemblages[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -900,7 +900,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_SURFACE_RAW: { cxxSurface entity(this->Get_io()); - entity.read_raw(P_INSTANCE_COMMA parser); + entity.read_raw(parser); Surfaces[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } @@ -918,7 +918,7 @@ cxxStorageBin::read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser) case CParser::KT_REACTION_RAW: { cxxReaction entity; - entity.read_raw(P_INSTANCE_COMMA parser, true); + entity.read_raw(parser, true); Reactions[entity.get_n_user()] = entity; entity_number = entity.get_n_user(); } diff --git a/StorageBin.h b/StorageBin.h index 4d05e746..842ccddb 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -87,8 +87,8 @@ class cxxStorageBin: public PHRQ_base void dump_raw(std::ostream & s_oss, int i, unsigned int indent); - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser); - int read_raw_keyword(PHREEQC_PTR_ARG_COMMA CParser & parser); + void read_raw(CParser & parser); + int read_raw_keyword(CParser & parser); void add(struct system *sys_ptr); diff --git a/Surface.cxx b/Surface.cxx index 1e5d7d93..3bd02419 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -363,7 +363,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSurface::read_raw(CParser & parser, bool check) { static std::vector < std::string > vopts; int i = 0; @@ -539,21 +539,21 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(P_INSTANCE_COMMA parser, false); + ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) { cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; - comp.read_raw(P_INSTANCE_COMMA reread, false); + comp.read_raw(reread, false); } else { cxxSurfaceComp ec1(this->Get_io()); - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_formula()); this->surfaceComps[str] = ec1; } @@ -592,21 +592,21 @@ cxxSurface::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(P_INSTANCE_COMMA parser, false); + ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) { cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; - comp.read_raw(P_INSTANCE_COMMA reread, false); + comp.read_raw(reread, false); } else { cxxSurfaceCharge ec1(this->Get_io()); - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_name()); this->surfaceCharges[str] = ec1; } diff --git a/Surface.h b/Surface.h index b2edb075..328c323f 100644 --- a/Surface.h +++ b/Surface.h @@ -34,7 +34,7 @@ class cxxSurface:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index ab3ad998..f2162a14 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -206,7 +206,7 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurfaceCharge::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSurfaceCharge::read_raw(CParser & parser, bool check) { std::string str; @@ -340,7 +340,7 @@ cxxSurfaceCharge::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) case 6: // diffuse_layer_totals - if (this->diffuse_layer_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->diffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/SurfaceCharge.h b/SurfaceCharge.h index d422226e..a409a584 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -29,7 +29,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); const std::string &get_name() const { diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 25893164..fedcdc32 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -249,7 +249,7 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSurfaceComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxSurfaceComp::read_raw(CParser & parser, bool check) { std::string str; @@ -406,7 +406,7 @@ cxxSurfaceComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 8: // totals - if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); @@ -430,7 +430,7 @@ cxxSurfaceComp::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 10: // formula_totals - if (this->formula_totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->formula_totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/SurfaceComp.h b/SurfaceComp.h index f17ce9ba..49b1d144 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -30,7 +30,7 @@ public: static struct surface_comp *cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); const cxxNameDouble & get_totals() const; void add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 12eeacc5..8671ce8c 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -288,7 +288,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) +cxxKinetics::read_raw(CParser & parser, bool check) { double d; @@ -437,10 +437,10 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } #endif parser.set_accumulate(true); - ec.read_raw(P_INSTANCE_COMMA parser, false); + ec.read_raw(parser, false); parser.set_accumulate(false); std::istringstream is(parser.get_accumulated()); - CParser reread(P_INSTANCE_COMMA is, this->Get_io()); + CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); @@ -456,12 +456,12 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) } if (found) { - kit->read_raw(P_INSTANCE_COMMA reread, false); + kit->read_raw(reread, false); } else { cxxKineticsComp ec1(this->Get_io()); - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_rate_name()); this->kineticsComps.push_back(ec1); } @@ -469,12 +469,12 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) { cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; - comp.read_raw(P_INSTANCE_COMMA reread, false); + comp.read_raw(reread, false); } else { cxxKineticsComp ec1; - ec1.read_raw(P_INSTANCE_COMMA reread, false); + ec1.read_raw(reread, false); std::string str(ec1.get_rate_name()); this->kineticsComps[str] = ec1; } @@ -484,7 +484,7 @@ cxxKinetics::read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check) break; case 5: // totals - if (this->totals.read_raw(P_INSTANCE_COMMA parser, next_char) != + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) { parser.incr_input_error(); diff --git a/cxxKinetics.h b/cxxKinetics.h index fb8fc9c6..3cd95379 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -30,7 +30,7 @@ class cxxKinetics:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(PHREEQC_PTR_ARG_COMMA CParser & parser, bool check = true); + void read_raw(CParser & parser, bool check = true); bool get_related_phases(void); From c2987e2d6b439773cf252f473906668220b43cd4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 26 Sep 2011 16:52:32 +0000 Subject: [PATCH 0249/1077] Think ErrorHandling reproduces original results. Need to keep stripping P_INSTANCE and PHREEQC_PTR from code. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5647 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 4 ++-- PHRQ_io.cpp | 2 +- Parser.cxx | 9 +++------ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 1e35d4bc..31b5d2fc 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -61,8 +61,8 @@ output_msg(const std::string & stdstr) bool stop = false; if (this->io) { - this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); - //this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); + //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); + this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); } else { diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 0179b791..f1088756 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -137,7 +137,7 @@ output_handler(const int type, const char *err_str, const bool stop, const char *format, va_list args) /* ---------------------------------------------------------------------- */ { - int flush = 0; + int flush = 1; switch (type) { diff --git a/Parser.cxx b/Parser.cxx index d15fceac..b91c5a4b 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -133,8 +133,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(), false, "", NULL); - //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; case EO_KEYWORDS: @@ -143,8 +142,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(), false, "", NULL); - //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -154,8 +152,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, std::ostringstream msg; msg << "\t" << m_line_save << "\n"; //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - this->Get_io()->output_handler(PHRQ_io::OUTPUT_MESSAGE, msg.str().c_str(),false,"",NULL); - //this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; } From 12d62e8e54e200bc435878db31c55df725a7a448 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 26 Sep 2011 20:24:17 +0000 Subject: [PATCH 0250/1077] Removed P_INSTANCE for error_msg, which removed entirely from some methods. Began moving xx2struct into phreeqc from class definitions. First moved was cxxMix2mix to structures.c. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5648 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 4 +- ChartHandler.h | 2 +- ChartObject.cpp | 20 +- ExchComp.cxx | 20 +- ExchComp.h | 2 +- Exchange.cxx | 10 +- Exchange.h | 2 +- GasPhase.cxx | 10 +- GasPhase.h | 2 +- ISolution.cxx | 6 +- ISolutionComp.cxx | 8 +- NameDouble.cxx | 4 +- PHRQ_Parser.cxx | 1454 ------------------------------------------ PHRQ_Parser.h | 347 ---------- PPassemblage.cxx | 6 +- PPassemblageComp.cxx | 6 +- PPassemblageComp.h | 2 +- Phreeqc.h | 4 + ReadClass.cxx | 3 +- SSassemblage.cxx | 4 +- Solution.cxx | 21 +- Solution.h | 2 +- StorageBin.cxx | 4 +- Surface.cxx | 6 +- SurfaceComp.cxx | 18 +- SurfaceComp.h | 2 +- cxxKinetics.cxx | 4 +- cxxMix.cxx | 3 +- cxxMix.h | 6 +- 29 files changed, 95 insertions(+), 1887 deletions(-) delete mode 100644 PHRQ_Parser.cxx delete mode 100644 PHRQ_Parser.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 2830fb26..9e7c47e6 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -120,7 +120,7 @@ ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) return true; } bool -ChartHandler::End_timer(PHREEQC_PTR_ARG) +ChartHandler::End_timer() { size_t max_tries = 1000; @@ -156,7 +156,7 @@ ChartHandler::End_timer(PHREEQC_PTR_ARG) } if (i >= max_tries || i2 >= max_tries) { - P_INSTANCE_POINTER error_msg("Chart did not respond.", CONTINUE); + error_msg("Chart did not respond.", CONTINUE); } } } diff --git a/ChartHandler.h b/ChartHandler.h index 8b81b215..9cd10d21 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -29,7 +29,7 @@ public: } bool Read(PHREEQC_PTR_ARG_COMMA CParser &parser); void Punch_user_graph(PHREEQC_PTR_ARG); - bool End_timer(PHREEQC_PTR_ARG); + bool End_timer(); bool dump(std::ostream & oss, unsigned int indent); protected: std::map chart_map; diff --git a/ChartObject.cpp b/ChartObject.cpp index a44ff1e3..b0bedbc9 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -152,7 +152,7 @@ ChartObject::Set_axis_scale(CParser & parser) } if (string_vector.size() == 0) { - P_INSTANCE_POINTER error_msg("No axis defined for scales", CParser::OT_CONTINUE); + error_msg("No axis defined for scales", CParser::OT_CONTINUE); return false; } std::string str = string_vector[0]; @@ -179,7 +179,7 @@ ChartObject::Set_axis_scale(CParser & parser) estream << "Found " << str; estream << ", but expect axis type \'x\', \'y\', \'y2\'or \'sy\'."; estream << std::endl; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CParser::OT_CONTINUE); + error_msg(estream.str().c_str(), CParser::OT_CONTINUE); return false; } @@ -200,7 +200,7 @@ ChartObject::Set_axis_scale(CParser & parser) estream << "Found " << s; estream << ", but expect number or 'a(uto)'."; estream << std::endl; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + error_msg(estream.str().c_str(), CONTINUE); return false; } } @@ -216,7 +216,7 @@ ChartObject::Set_axis_scale(CParser & parser) std::ostringstream estream; estream << "MIN and MAX must be > 0 for log " << type << "-scale."; estream << std::endl; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + error_msg(estream.str().c_str(), CONTINUE); return false; } @@ -229,7 +229,7 @@ ChartObject::Set_axis_scale(CParser & parser) std::ostringstream estream; estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl; estream << "Switching values for MIN and MAX. " << std::endl; - P_INSTANCE_POINTER warning_msg(estream.str().c_str()); + warning_msg(estream.str().c_str()); double t; t = scale_ptr[0]; scale_ptr[0] = scale_ptr[1]; @@ -315,8 +315,8 @@ ChartObject::Read(CParser & parser) break; case CParser::OPT_ERROR: opt = CParser::OPT_EOF; - P_INSTANCE_POINTER error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); - P_INSTANCE_POINTER error_msg(parser.line().c_str(), CONTINUE); + error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); + error_msg(parser.line().c_str(), CONTINUE); useLastLine = false; break; case 0: /* start */ @@ -376,7 +376,7 @@ ChartObject::Read(CParser & parser) { std::ostringstream estream; estream << "Found " << token << ", but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time."; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + error_msg(estream.str().c_str(), CONTINUE); } break; case 9: /* shifts_as_points */ @@ -474,7 +474,7 @@ ChartObject::OpenCSVFile(std::string file_name) { std::ostringstream estream; estream << "Could not open csv file for USER_GRAPH " << file_name; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + error_msg(estream.str().c_str(), CONTINUE); return false; } @@ -904,7 +904,7 @@ ChartObject::SaveCurvesToFile(std::string &file_name) { std::ostringstream estream; estream << "Could not open csv file for USER_GRAPH " << file_name; - P_INSTANCE_POINTER error_msg(estream.str().c_str(), CONTINUE); + error_msg(estream.str().c_str(), CONTINUE); return; } diff --git a/ExchComp.cxx b/ExchComp.cxx index 290cff13..03484602 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -148,7 +148,7 @@ cxxExchComp::get_master(PHREEQC_PTR_ARG) error_oss << "Master species not in data base for " << elt_ptr-> name << std::endl; //Utilities::error_msg(error_oss.str(), STOP); - P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != EX) @@ -172,7 +172,7 @@ cxxExchComp::get_master(PHREEQC_PTR_ARG) error_oss << "Master species not in data base for " << elt_ptr->name << std::endl; //Utilities::error_msg(error_oss.str(), STOP); - P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != EX) @@ -188,7 +188,7 @@ cxxExchComp::get_master(PHREEQC_PTR_ARG) "Exchange formula does not contain an exchange master species, " << this->formula << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); std::ostringstream oss; this->dump_raw(oss, 0); @@ -552,7 +552,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) } } void -cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensive) +cxxExchComp::add(const cxxExchComp & addee, double extensive) { double ext1, ext2, f1, f2; if (extensive == 0.0) @@ -604,8 +604,8 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi oss << "Can not mix two exchange components with same formula and different related phases, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //input_error++; return; } else if (this->phase_name.size() != 0) @@ -620,8 +620,8 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //input_error++; return; } else if (this->rate_name.size() != 0) @@ -637,8 +637,8 @@ cxxExchComp::add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & addee, double extensi oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //input_error++; return; } } diff --git a/ExchComp.h b/ExchComp.h index c1961b45..ccb2c352 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -132,7 +132,7 @@ class cxxExchComp: public PHRQ_base }; - void add(PHREEQC_PTR_ARG_COMMA const cxxExchComp & comp, double extensive); + void add(const cxxExchComp & comp, double extensive); void multiply(double extensive); diff --git a/Exchange.cxx b/Exchange.cxx index 5aabdac3..3d5520aa 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -67,15 +67,15 @@ cxxNumKeyword(io) // // Mix exchangers // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { const cxxExchange *entity_ptr = &(entities.find(it->first)->second); - this->add(P_INSTANCE_COMMA *entity_ptr, it->second); + this->add(*entity_ptr, it->second); this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; } #ifdef SKIP @@ -465,7 +465,7 @@ cxxExchange::add(const cxxExchange & addee, double extensive) } #endif void -cxxExchange::add(PHREEQC_PTR_ARG_COMMA const cxxExchange & addee, double extensive) +cxxExchange::add(const cxxExchange & addee, double extensive) // // Add existing exchange to "this" exchange // @@ -479,7 +479,7 @@ cxxExchange::add(PHREEQC_PTR_ARG_COMMA const cxxExchange & addee, double extensi std::map < std::string, cxxExchComp >::iterator it = this->exchComps.find((*itadd).first); if (it != this->exchComps.end()) { - (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); + (*it).second.add((*itadd).second, extensive); //bool found = false; //for (std::list < cxxExchComp >::iterator it = this->exchComps.begin(); // it != this->exchComps.end(); ++it) diff --git a/Exchange.h b/Exchange.h index a96555a0..6343c2aa 100644 --- a/Exchange.h +++ b/Exchange.h @@ -47,7 +47,7 @@ public: void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif private: - void add(PHREEQC_PTR_ARG_COMMA const cxxExchange & addee, double extensive); + void add(const cxxExchange & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/GasPhase.cxx b/GasPhase.cxx index 06c83c7b..0ab74987 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -69,7 +69,7 @@ cxxNumKeyword(io) gas_phase_ptr->comps[i].moles; } } -cxxGasPhase::cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entities, +cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): cxxNumKeyword(io) { @@ -82,9 +82,9 @@ cxxNumKeyword(io) // Mix // //cxxNameDouble gasPhaseComps; - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { @@ -108,8 +108,8 @@ cxxNumKeyword(io) { std::ostringstream oss; oss << "Can not mix two gas_phases with differing types."; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //input_error++; return; } diff --git a/GasPhase.h b/GasPhase.h index 56f62ef1..ed32bcc6 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -17,7 +17,7 @@ class cxxGasPhase:public cxxNumKeyword public: cxxGasPhase(PHRQ_io * io=NULL); cxxGasPhase(struct gas_phase *, PHRQ_io * io=NULL); - cxxGasPhase(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxGasPhase > &entity_map, + cxxGasPhase(const std::map < int, cxxGasPhase > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxGasPhase(); diff --git a/ISolution.cxx b/ISolution.cxx index 38533a17..fb840cf3 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -133,8 +133,8 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) std::ostringstream oss; oss << "Could not find gfw, " << iter->second. get_description(); - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; } } /* @@ -775,7 +775,7 @@ cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat) oss << "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + //P_INSTANCE_POINTER input_error++; } chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << std::endl; diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index c22dbf54..3d144ba1 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -130,8 +130,8 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } //if (this->description == "Alkalinity" && this->as == "CaCO3") @@ -154,8 +154,8 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) } std::ostringstream oss; oss << "Could not find gfw, " << this->description; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } diff --git a/NameDouble.cxx b/NameDouble.cxx index 05d7fd9d..a83bd01b 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -581,7 +581,7 @@ cxxNameDouble::mpi_pack(std::vector < int >&ints, } } void -cxxNameDouble::mpi_pack(PHREEQC_PTR_ARG_COMMA int *ints, int *ii, double *doubles, int *dd) +cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) { int i = *ii; int d = *dd; @@ -594,7 +594,7 @@ cxxNameDouble::mpi_pack(PHREEQC_PTR_ARG_COMMA int *ints, int *ii, double *double if (n < 0) { std::cerr << it->first << std::endl; - P_INSTANCE_POINTER error_msg("Name in NameDouble was not defined in dictionary?\n", + error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); } //ints.push_back(n); diff --git a/PHRQ_Parser.cxx b/PHRQ_Parser.cxx deleted file mode 100644 index 511c9aa6..00000000 --- a/PHRQ_Parser.cxx +++ /dev/null @@ -1,1454 +0,0 @@ -// Parser.cpp: implementation of the PHRQ_Parser class. -// -////////////////////////////////////////////////////////////////////// -#ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif - -#include // std::transform -#include // std::map -#include // assert -#include -#include // std::cout std::cerr -#include "Utils.h" -#include -#if defined (PHREEQC_CLASS) -#include "Phreeqc.h" -#endif -#include "PHRQ_Parser.h" -#include "output.h" - -//extern char *string_hsave(const char *str); - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input):m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), -m_input_error(0), -m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif -} - -PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output):m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), -m_input_error(0), -m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif -} - -PHRQ_Parser::PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, std::ostream & error):m_input_stream(input), m_output_stream(output), m_error_stream(error), -m_input_error(0), -m_next_keyword(KT_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; -#if defined(PHREEQC_CLASS) - this->p_instance = p_instance1; -#endif -} - -PHRQ_Parser::~PHRQ_Parser() -{ -} - -PHRQ_Parser::LINE_TYPE PHRQ_Parser::check_line(const std::string & str, - bool allow_empty, bool allow_eof, - bool allow_keyword, bool print) -{ - LINE_TYPE - i; - - // Get line - do - { - i = get_line(); - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - - // output for stream - switch (this->echo_stream) - { - case EO_NONE: - break; - case EO_ALL: - if (i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; - case EO_KEYWORDS: - if (i == LT_KEYWORD) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; - case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - get_output() << msg; - } - break; - } - // output for file - switch (this->echo_file) - { - case EO_NONE: - break; - case EO_ALL: - if (i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; - case EO_KEYWORDS: - if (i == LT_KEYWORD) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; - - case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) - { - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); - } - break; - } - } - while (i == LT_EMPTY && allow_empty == false); - - // Check eof - if (i == LT_EOF && allow_eof == false) - { - std::ostringstream msg; - msg << "Unexpected eof while reading " << str << - "\nExecution terminated.\n"; - error_msg(msg, OT_STOP); - } - - // Check keyword - if (i == LT_KEYWORD && allow_keyword == false) - { - std::ostringstream msg; - msg << "Expected data for " << str << - ", but got a keyword ending data block."; - error_msg(msg, OT_CONTINUE); - incr_input_error(); - } - m_line_type = i; - return i; -} - -PHRQ_Parser::LINE_TYPE PHRQ_Parser::get_line() -{ - PHRQ_Parser::LINE_TYPE return_value = LT_EMPTY; - while (return_value == LT_EMPTY) - { - // - // Eliminate all characters after # sign as a comment - // - - // - // Get line, check for eof - // - if (get_logical_line() == LT_EOF) - { - if (!m_input_stream.eof()) - { - error_msg("Reading input file.", OT_CONTINUE); - error_msg("istream::get() returned an error.", OT_STOP); - } - else - { - //{{MOD - m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); - //}}MOD - m_next_keyword = KT_EOF; - return LT_EOF; - } - } - - // - // Get long lines - // - bool - empty = true; - m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); - for (unsigned int i = 0; i < m_line.size(); ++i) - { - if (!::isspace(m_line[i])) - { - empty = false; - break; - } - } - - if (this->accumulate) - { - this->accumulated.append(m_line_save); - this->accumulated.append("\n"); - } - // - // New line character encountered - // - return_value = (empty ? LT_EMPTY : LT_OK); - } - - // - // Determine return_value - // - if (return_value == LT_OK) - { - if (check_key(m_line.begin(), m_line.end())) - { - return_value = LT_KEYWORD; - } - else - { - std::string::iterator beg = m_line.begin(); - std::string::iterator end = m_line.end(); - std::string token; - copy_token(token, beg, end); - - if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) - { - return_value = LT_OPTION; - } - } - } - return return_value; -} - -/** - Reads input stream until end of line, ";", or eof - stores characters in line_save - - returns: - EOF on empty line on end of file or - OK otherwise -*/ -PHRQ_Parser::LINE_TYPE PHRQ_Parser::get_logical_line() -{ - int - j; - unsigned int - pos; - char - c; - - m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); - - while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) - { - c = (char) j; - if (c == '#') - { - // ignore all chars after # until newline - do - { - c = (char) j; - if (c == '\n') - { - break; - } - m_line_save += c; - } - while ((j = - m_input_stream.get()) != std::char_traits < - char >::eof()); - } - if (c == ';') - break; - if (c == '\n') - { - break; - } - if (c == '\\') - { - pos = (int) m_line_save.size(); - m_line_save += c; - while ((j = - m_input_stream.get()) != std::char_traits < char >::eof()) - { - c = (char) j; - if (c == '\\') - { - pos = (int) m_line_save.size(); - m_line_save += c; - continue; - } - if (c == '\n') - { - // remove '\\' - for (; pos < m_line_save.size(); pos++) - { - m_line_save[pos] = m_line_save[pos + 1]; - } - m_line_save.erase(m_line_save.size() - 1, 1); - break; - } - m_line_save += c; - if (!::isspace(j)) - break; - } - } - else - { - m_line_save += c; - } - } - if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) - { - return (LT_EOF); - } - return (LT_OK); -} - - -//bool PHRQ_Parser::check_key(const std::string::iterator ptr) -bool -PHRQ_Parser::check_key(std::string::iterator begin, std::string::iterator end) -{ - static std::map < std::string, KEY_TYPE > s_keyword_map; - if (s_keyword_map.size() == 0) - { - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("solution_raw", - KT_SOLUTION_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("exchange_raw", - KT_EXCHANGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("gas_phase_raw", - KT_GASPHASE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("kinetics_raw", - KT_KINETICS_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("equilibrium_phases_raw", - KT_PPASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("solid_solutions_raw", - KT_SSASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("surface_raw", - KT_SURFACE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("reaction_temperature_raw", - KT_TEMPERATURE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("reaction_raw", - KT_REACTION_RAW)); -#if defined MULTICHART - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("user_graph", - KT_USER_GRAPH)); -#endif - } - - std::string lowercase; - copy_token(lowercase, begin, end); - std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), - tolower); - - m_next_keyword = KT_NONE; - std::map < std::string, KEY_TYPE >::iterator map_iter = - s_keyword_map.find(lowercase); - if (map_iter == s_keyword_map.end()) - return false; - m_next_keyword = (*map_iter).second; - return true; -} - -PHRQ_Parser::STATUS_TYPE PHRQ_Parser::check_units(std::string & tot_units, - bool alkalinity, - bool check_compatibility, - const std::string & default_units, - bool print) -{ -/* - * Check if legitimate units - * Input: - * tot_units character string to check, - * alkalinity true if alkalinity, false if any other total, - * check_compatibility true check alk and default units, false otherwise - * default_units character string of default units (check /L, /kg, etc) - * print true print warning messages - * Output: - * tot_units standard form for unit - */ - using - Utilities::str_tolower; - using - Utilities::replace; - using - Utilities::squeeze_white; - - static const char * - units[] = { - "Mol/l", /* 0 */ - "mMol/l", /* 1 */ - "uMol/l", /* 2 */ - "g/l", /* 3 */ - "mg/l", /* 4 */ - "ug/l", /* 5 */ - "Mol/kgs", /* 6 */ - "mMol/kgs", /* 7 */ - "uMol/kgs", /* 8 */ - "g/kgs", /* 9 = ppt */ - "mg/kgs", /* 10 = ppm */ - "ug/kgs", /* 11 = ppb */ - "Mol/kgw", /* 12 = mol/kg H2O */ - "mMol/kgw", /* 13 = mmol/kg H2O */ - "uMol/kgw", /* 14 = umol/kg H2O */ - "g/kgw", /* 15 = mol/kg H2O */ - "mg/kgw", /* 16 = mmol/kg H2O */ - "ug/kgw", /* 17 = umol/kg H2O */ - "eq/l", /* 18 */ - "meq/l", /* 19 */ - "ueq/l", /* 20 */ - "eq/kgs", /* 21 */ - "meq/kgs", /* 22 */ - "ueq/kgs", /* 23 */ - "eq/kgw", /* 24 */ - "meq/kgw", /* 25 */ - "ueq/kgw", /* 26 */ - }; - - squeeze_white(tot_units); - str_tolower(tot_units); - replace("milli", "m", tot_units); - replace("micro", "u", tot_units); - replace("grams", "g", tot_units); - replace("gram", "g", tot_units); - replace("moles", "Mol", tot_units); - replace("mole", "Mol", tot_units); - replace("mol", "Mol", tot_units); - replace("liter", "l", tot_units); - replace("kgh", "kgw", tot_units); - replace("ppt", "g/kgs", tot_units); - replace("ppm", "mg/kgs", tot_units); - replace("ppb", "ug/kgs", tot_units); - replace("equivalents", "eq", tot_units); - replace("equivalent", "eq", tot_units); - replace("equiv", "eq", tot_units); - - std::string::size_type end; - if ((end = tot_units.find("/l")) != std::string::npos) - { - tot_units.resize(end + 2); - } - if ((end = tot_units.find("/kgs")) != std::string::npos) - { - tot_units.resize(end + 4); - } - if ((end = tot_units.find("/kgw")) != std::string::npos) - { - tot_units.resize(end + 4); - } - - // - // Check if unit in list - // - bool - found = false; - for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) - { - if (tot_units.compare(units[i]) == 0) - { - found = true; - break; - } - } - if (!found) - { - if (print) - { - std::ostringstream err; - err << "Unknown unit, " << tot_units; - error_msg(err, OT_CONTINUE); - } - return PARSER_ERROR; - } - - // - // Check if units are compatible with default_units - // - if (check_compatibility == false) - return PARSER_OK; - - // - // Special cases for alkalinity - // - if (alkalinity == true && tot_units.find("Mol") != std::string::npos) - { - if (print) - { - warning_msg - ("Alkalinity given in moles, assumed to be equivalents."); - } - replace("Mol", "eq", tot_units); - } - if (alkalinity == false && tot_units.find("eq") != std::string::npos) - { - if (print) - { - error_msg("Only alkalinity can be entered in equivalents.", - OT_CONTINUE); - } - return PARSER_ERROR; - } - - // - // See if default_units are compatible with tot_units - // - if (default_units.find("/l") != std::string::npos - && tot_units.find("/l") != std::string::npos) - return PARSER_OK; - if (default_units.find("/kgs") != std::string::npos - && tot_units.find("/kgs") != std::string::npos) - return PARSER_OK; - if (default_units.find("/kgw") != std::string::npos - && tot_units.find("/kgw") != std::string::npos) - return PARSER_OK; - - std::string str = default_units; - replace("kgs", "kg solution", str); - replace("kgs", "kg solution", tot_units); - replace("kgw", "kg water", str); - replace("kgw", "kg water", tot_units); - replace("/l", "/L", str); - replace("Mol", "mol", str); - replace("/l", "/L", tot_units); - replace("Mol", "mol", tot_units); - - if (print) - { - std::ostringstream err; - err << "Units for master species, " << tot_units << - ", are not compatible with default units, " << str << "."; - error_msg(err, OT_CONTINUE); - } - return PARSER_ERROR; -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::token_type(const std::string & token) -{ - if (!token.empty()) - { - if (::isupper(token[0])) - { - return PHRQ_Parser::TT_UPPER; - } - else if (::islower(token[0])) - { - return PHRQ_Parser::TT_LOWER; - } - else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') - { - return PHRQ_Parser::TT_DIGIT; - } - else - { - assert(!::isspace(token[0])); - return PHRQ_Parser::TT_UNKNOWN; - } - } - else - { - return PHRQ_Parser::TT_EMPTY; - } -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::peek_token() -{ - std::istringstream::pos_type pos = m_line_iss.tellg(); - std::string token; - m_line_iss >> token; - m_line_iss.seekg(pos); - return token_type(token); -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, - std::string::iterator & begin, - std::string::iterator & end) -{ - if (begin != end) - { - std::string::iterator b = begin; - for (; b < end &&::isspace(*b); ++b); - - begin = b; - for (; begin < end && !::isspace(*begin); ++begin); - - token.assign(b, begin); - } - else - { - token.resize(0); - } - - return token_type(token); -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, - std::istream & is) -{ - is >> token; - return token_type(token); -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_token(std::string & token, - std::istream::pos_type & pos) -{ - m_line_iss.seekg(pos); - // m_line_iss >> token; - if (!(m_line_iss >> token)) - { - token.erase(token.begin(), token.end()); // token.clear(); - } - pos = m_line_iss.tellg(); - return token_type(token); -} - -PHRQ_Parser::FIND_TYPE PHRQ_Parser::find_option(const std::string & item, int *n, - const std::vector < std::string > - &list, bool exact) -{ - std::string token(item); - std::transform(token.begin(), token.end(), token.begin(), tolower); - for (unsigned int i = 0; i < list.size(); i++) - { - if (exact == true) - { - if (list[i].compare(token) == 0) - { - *n = i; - return FT_OK; - } - } - else - { - if (list[i].find(token) == 0) - { - *n = i; - return FT_OK; - } - } - } - - *n = -1; - return FT_ERROR; -} - -// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) -// OPTION_TYPE PHRQ_Parser::get_option(const std::vector& opt_list, std::string::iterator& next_char) -int -PHRQ_Parser::get_option(const std::vector < std::string > &opt_list, - std::string::iterator & next_char) -{ - // - // Read a line and check for options - // - int j; - int /* opt_l, */ opt; - //char *opt_ptr; - std::string::iterator opt_ptr; - - // char option[MAX_LENGTH]; - std::string option; - - fprintf(stderr, "Did not think this get_option was called\n"); - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, false) == PHRQ_Parser::FT_OK) - { - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), - opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - next_char = opt_ptr; - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); - - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; - - j = OPT_ERROR; - next_char = m_line.begin(); - } - } - else - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_char = opt_ptr; - } - else - { - j = OPT_DEFAULT; - next_char = m_line.begin(); - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - std::cout << "\t" << m_line_save << "\n"; - } - } - } - return (j); -} - -int -PHRQ_Parser::get_option(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos) -{ - // - // Read a line and check for options - // - int j; - int opt; - std::istream::pos_type pos_ptr; - std::string option; - - // - // Read line - // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - std::string::iterator opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) - { - // replace -option with option - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), - opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - - pos_ptr = 0; - copy_token(option, pos_ptr); - next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} -/* - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } -*/ - } - else - { -/* - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } -*/ - //error_msg("Unknown option.", OT_CONTINUE); - //error_msg(m_line_save.c_str(), OT_CONTINUE); - //incr_input_error(); - j = OPT_ERROR; - next_pos = pos_ptr; - } - } - else - { - //pos_ptr = 0; - //copy_token(option, pos_ptr); - //if (find_option(option, &opt, opt_list, true) == FT_OK) - //{ - // j = opt; - // next_pos = pos_ptr; - //} - //else - //{ - // j = OPT_DEFAULT; - // next_pos = 0; - //} - - //std::istringstream m_line_iss_copy = m_line_iss; - pos_ptr = m_line_iss.tellg(); - m_line_iss >> option; - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_pos = m_line_iss.tellg(); - } - else - { - j = OPT_DEFAULT; - m_line_iss.seekg(pos_ptr); - m_line_iss.clear(); - next_pos = pos_ptr; - //m_line_iss >> option; - } -/* - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - fprintf(stderr, "Yikes 3\n"); - get_output() << "\t" << m_line_save << "\n"; - } - } -*/ - } - return (j); -} - -int -PHRQ_Parser::error_msg(const char *err_str, ONERROR_TYPE ot) -{ - ERROR_MESSAGE_QUALIFIER error_msg(err_str, (int) ot); - m_error_stream << "ERROR: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "ERROR: " << err_str << "\n"; - m_output_stream.flush(); - - if (ot == OT_STOP) - { - exit(1); - } - return 0; -} - -int -PHRQ_Parser::warning_msg(const char *err_str) -{ - m_error_stream << "WARNING: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "WARNING: " << err_str << "\n"; - m_output_stream.flush(); - - return 0; -} - -PHRQ_Parser::STATUS_TYPE PHRQ_Parser::get_elt(std::string::iterator & begin, - const std::string::iterator end, - std::string & element) -{ - element.erase(element.begin(), element.end()); // element.clear(); - - if (begin == end) - { - error_msg("Empty string in get_elt. Expected an element name.", - OT_CONTINUE); - return PARSER_ERROR; - } - - // - // Load name into char array element - // - char - c = *begin; - ++begin; - element.insert(element.end(), c); // element.push_back(c); - if (c == '[') - { - while ((c = *begin) != ']') - { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if ((c = *begin) == ']') - { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - break; - } - else if (begin == end) - { - error_msg("No ending bracket (]) for element name", - OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } - } - while (::islower(c = *begin) || c == '_') - { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) - break; - } - } - else - { - while (::islower(c = *begin) || c == '_') - { - element.insert(element.end(), c); // element.push_back(c); - ++begin; - if (begin == end) - break; - } - } - return PARSER_OK; -} - -PHRQ_Parser::STATUS_TYPE PHRQ_Parser::parse_couple(std::string & token) -{ - // Parse couple puts redox couples in standard form - // "+" is removed and couples are rewritten in sort - // order. - - if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) - { - Utilities::str_tolower(token); - return PARSER_OK; - } - - while (Utilities::replace("+", "", token)); - - std::string::iterator ptr = token.begin(); - std::string elt1; - get_elt(ptr, token.end(), elt1); - - if (*ptr != '(') - { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " << - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } - - int - paren_count = 1; - std::string paren1 = "("; - while (ptr != token.end()) - { - ++ptr; - if (*ptr == '/' || ptr == token.end()) - { - std::ostringstream err_msg; - err_msg << "End of line or " "/" - " encountered before end of parentheses, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - paren1.insert(paren1.end(), *ptr); // element.push_back(c); - if (*ptr == '(') - ++paren_count; - if (*ptr == ')') - --paren_count; - if (paren_count == 0) - break; - } - - ++ptr; - if (ptr == token.end() || *ptr != '/') - { - std::ostringstream err_msg; - err_msg << " " "/" " must follow parentheses " << - "ending first half of redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - ++ptr; - std::string elt2; - get_elt(ptr, token.end(), elt2); - if (elt1.compare(elt2) != 0) - { - std::ostringstream err_msg; - err_msg << "Redox couple must be two redox states " << - "of the same element, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - if (*ptr != '(') - { - std::ostringstream err_msg; - err_msg << "Element name must be followed by " - "parentheses in redox couple, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - incr_input_error(); - return PARSER_ERROR; - } - std::string paren2 = "("; - paren_count = 1; - - while (ptr != token.end()) - { - ++ptr; - if (*ptr == '/' || ptr == token.end()) - { - std::ostringstream err_msg; - err_msg << "End of line or " "/" - " encountered before end of parentheses, " << token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - paren2.insert(paren2.end(), *ptr); // element.push_back(c); - if (*ptr == '(') - ++paren_count; - if (*ptr == ')') - --paren_count; - if (paren_count == 0) - break; - } - if (paren1.compare(paren2) < 0) - { - token = elt1 + paren1 + std::string("/") + elt2 + paren2; - } - else if (paren1.compare(paren2) > 0) - { - token = elt2 + paren2 + std::string("/") + elt1 + paren1; - } - else - { - std::ostringstream err_msg; - err_msg << "Both parts of redox couple are the same, " << - token << "."; - error_msg(err_msg, OT_CONTINUE); - return PARSER_ERROR; - } - return PARSER_OK; -} - -//PHRQ_Parser::STATUS_TYPE PHRQ_Parser::addPair(std::map < char *, double, -// CHARSTAR_LESS > &totals, -// std::istream::pos_type & pos) -//{ -// std::string token; -// char * -// ctoken; -// double -// d; -// -// PHRQ_Parser::TOKEN_TYPE j; -// -// m_line_iss.seekg(pos); -// -// j = copy_token(token, pos); -// -// if (j == TT_EMPTY) -// return PARSER_OK; -// -// if (!(m_line_iss >> d)) -// { -// return PARSER_ERROR; -// } -// ctoken = string_hsave(token.c_str()); -// totals[ctoken] = d; -// return PARSER_OK; -//} - -PHRQ_Parser::STATUS_TYPE PHRQ_Parser::addPair(std::map < std::string, double >&totals, - std::istream::pos_type & pos) -{ - std::string token; - //char * ctoken; - double - d; - PHRQ_Parser::TOKEN_TYPE j; - - m_line_iss.seekg(pos); - - j = copy_token(token, pos); - - if (j == TT_EMPTY) - return PARSER_OK; - - if (!(m_line_iss >> d)) - { - return PARSER_ERROR; - } - //ctoken = string_hsave(token.c_str()); - //totals[ctoken] = d; - totals[token] = d; - return PARSER_OK; -} - -int -PHRQ_Parser::getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::string::iterator & next_char) -{ - // - // Read a line and check for options - // - int j; - int /* opt_l, */ opt; - //char *opt_ptr; - std::string::iterator opt_ptr; - - // char option[MAX_LENGTH]; - std::string option; - - // - // Read line - // - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, false) == PHRQ_Parser::FT_OK) - { - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), - opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - next_char = opt_ptr; - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); - - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; - - j = OPT_ERROR; - next_char = m_line.begin(); - } - } - else - { - opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_char = opt_ptr; - } - else - { - j = OPT_DEFAULT; - next_char = m_line.begin(); - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - std::cout << "\t" << m_line_save << "\n"; - } - } - } - return (j); -} - -int -PHRQ_Parser::getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos) -{ - // - // Read a line and check for options - // - int j; - int opt; - std::istream::pos_type pos_ptr; - std::string option; - - // - // Read line - // - //LINE_TYPE lt = check_line("get_option", false, true, true, false); - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) - { - j = OPT_EOF; - } - else if (lt == LT_KEYWORD) - { - j = OPT_KEYWORD; - } - else if (lt == LT_OPTION) - { - std::string::iterator opt_ptr = m_line.begin(); - std::string::iterator end = m_line.end(); - copy_token(option, opt_ptr, end); - if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) - { - // replace -option with option - j = opt; - m_line_save.replace(m_line_save.find(option), option.size(), - opt_list[opt]); - m_line.replace(m_line.find(option), option.size(), opt_list[opt]); - - // reset iss - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - - pos_ptr = 0; - copy_token(option, pos_ptr); - next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - else - { - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } - error_msg("Unknown option.", OT_CONTINUE); - error_msg(m_line_save.c_str(), OT_CONTINUE); - incr_input_error(); - j = OPT_ERROR; - next_pos = pos_ptr; - } - } - else - { - pos_ptr = 0; - copy_token(option, pos_ptr); - if (find_option(option, &opt, opt_list, true) == FT_OK) - { - j = opt; - next_pos = pos_ptr; - } - else - { - j = OPT_DEFAULT; - next_pos = 0; - } - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } - } - return (j); -} -int PHRQ_Parser:: -incr_input_error() -{ - ++ ERROR_MESSAGE_QUALIFIER input_error; - return ++m_input_error; -} - -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::copy_title(std::string & token, - std::string::iterator & begin, - std::string::iterator & end) -{ - if (begin != end) - { - std::string::iterator b = begin; - std::string::iterator e = end; - for (; b < end && (::isspace(*b) || (*b == ',')); ++b); - begin = b; - if (*begin == '"') - { - begin = ++b; - for (; begin != end && !(*begin == '"'); ++begin); - e = begin; - if (begin != end && *begin == '"') - { - e = begin++; - } - } - else if (*begin == '\'') - { - begin = ++b; - for (; begin != end && !(*begin == '\''); ++begin); - e = begin; - if (begin != end && *begin == '\'') - { - e = begin++; - } - } - else - { - for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin); - e = begin; - } - token.assign(b, e); - } - else - { - token.resize(0); - } - token = trim(token); - return token_type(token); -} -bool PHRQ_Parser::get_true_false(std::istream::pos_type & pos, bool def) -{ - std::string token; - this->copy_token(token, pos); - std::string::iterator b = token.begin(); - for (; b != token.end() && (::isspace(*b)); ++b); - if (b != token.end()) - { - if (*b == 'f' || *b == 'F') - { - return false; - } - else if (*b == 't' || *b == 'T') - { - return true; - } - } - return def; -} -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::get_rest_of_line(std::string &token) -{ - token.clear(); - std::istringstream::pos_type pos = m_line_iss.tellg(); - int j; - while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) - { - char c = (char) j; - token += c; - } - token = trim(token); - return token_type(token); -} -PHRQ_Parser::TOKEN_TYPE PHRQ_Parser::parse_delimited(std::string & source, std::string & result, - const std::string& t = " \t") -{ - - size_t pos = source.find_first_of(t); - std::string temp; - if (pos != std::string::npos) - { - result = source.substr(0, pos); - temp = source.substr(pos+1); - source = temp; - } - else - { - result = source; - source.clear(); - } - std::string str = result; - - return token_type(trim_left(str)); -} \ No newline at end of file diff --git a/PHRQ_Parser.h b/PHRQ_Parser.h deleted file mode 100644 index 7b5ea694..00000000 --- a/PHRQ_Parser.h +++ /dev/null @@ -1,347 +0,0 @@ -#if !defined(PHRQ_PARSER_H_INCLUDED) -#define PHRQ_PARSER_H_INCLUDED - -#include // std::string -#include // std::map -#include // std::vector -#include // std::istringstream std::ostringstream -#include // std::ostream -#include // std::istream -#include "Phreeqc_class.h" -#if defined (PHREEQC_CLASS) -class Phreeqc; -#define PHREEQC_NAME_SPACE Phreeqc:: -#define PHREEQC_COOKIE this->p_instance-> -#define ERROR_MESSAGE_QUALIFIER this->p_instance-> -#else -#define PHREEQC_NAME_SPACE :: -#define PHREEQC_COOKIE -#define ERROR_MESSAGE_QUALIFIER :: -extern int input_error; -#endif - -class PHRQ_Parser -{ - public: - PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input); - PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output); - PHRQ_Parser(PHREEQC_PTR_ARG_COMMA std::istream & input, std::ostream & output, - std::ostream & error); - - virtual ~ PHRQ_Parser(); - - enum LINE_TYPE - { - LT_EOF = -1, - LT_OK = 1, - LT_EMPTY = 2, - LT_KEYWORD = 3, - LT_OPTION = 8 - }; - - enum TOKEN_TYPE - { - TT_EMPTY = 2, - TT_UPPER = 4, - TT_LOWER = 5, - TT_DIGIT = 6, - TT_UNKNOWN = 7 - }; - - enum FIND_TYPE - { - FT_OK = 0, - FT_ERROR = 1 - }; - - enum KEY_TYPE - { - KT_NONE = -1, - KT_END = 0, - KT_EOF = 1, - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11, - KT_TEMPERATURE_RAW = 12, - KT_REACTION_RAW = 13 -#if defined MULTICHART - , KT_USER_GRAPH = 14 -#endif - }; - - enum OPT_TYPE - { - OPT_DEFAULT = -4, - OPT_ERROR = -3, - OPT_KEYWORD = -2, - OPT_EOF = -1 - }; - - enum ONERROR_TYPE - { - OT_CONTINUE = 0, - OT_STOP = 1 - }; - - enum ECHO_OPTION - { - EO_NONE = 0, - EO_ALL = 1, - EO_KEYWORDS = 2, - EO_NOKEYWORDS = 3 - }; - - enum STATUS_TYPE - { - PARSER_ERROR = 0, - PARSER_OK = 1 - }; - - - /** - Function gets a new line and checks for empty, eof, and keywords. - - Arguments: - string Input, character string used in printing error message - allow_empty Input, True or false, if a blank line is accepable - if false, another line is read - allow_eof Input, True or false, if EOF is acceptable - allow_keyword Input, True or false, if a keyword is acceptable - - Returns: - LT_EMPTY if empty line read and allow_empty == true - LT_KEYWORD if line begins with keyword - LT_EOF if eof and allow_eof == true - LT_OK otherwise - LT_OPTION if line begins with -[alpha] - - Terminates if EOF and allow_eof == false. - */ - LINE_TYPE check_line(const std::string & str, bool allow_empty, - bool allow_eof, bool allow_keyword, bool print); - - /** - Read a line from input file put in "line". - Copy of input line is stored in "line_save". - Characters after # are discarded in line but retained in "line_save" - - Arguments: - None - Returns: - LT_EMPTY, - LT_EOF, - LT_KEYWORD, - LT_OK, - LT_OPTION - */ - LINE_TYPE get_line(); - - // bool check_key(const std::string::iterator ptr); - bool check_key(std::string::iterator begin, std::string::iterator end); - - STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, - bool check_compatibility, - const std::string & default_units, bool print); - - - KEY_TYPE next_keyword() const - { - return m_next_keyword; - } - int get_option(const std::vector < std::string > &opt_list, - std::string::iterator & next_char); - int get_option(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos); - int getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::string::iterator & next_char); - int getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos); - - - std::string & line() - { - return m_line; - } - std::string & get_accumulated() - { - return accumulated; - } - void set_accumulate(bool tf) - { - if (tf) - { - accumulated.clear(); - } - this->accumulate = tf; - } - std::istringstream & get_iss() - { - return m_line_iss; - } - int incr_input_error(); - std::ostream & get_output() - { - return m_output_stream; - } - int get_input_error() - { - return m_input_error; - } - - std::istream::pos_type tellg() - { - return m_input_stream.tellg(); - } - std::istream& seekg(std::istream::pos_type p) - { - return m_input_stream.seekg(p); - } - - - - - /** - Copies from begin to token until first space is encountered. - - Arguments: - token output, the token - begin input, begin iterator - end input, end iterator - - Returns: - TT_EMPTY - TT_UPPER - TT_LOWER - TT_DIGIT - TT_UNKNOWN - */ - static TOKEN_TYPE copy_token(std::string & token, - std::string::iterator & begin, - std::string::iterator & end); - static PHRQ_Parser::TOKEN_TYPE copy_title(std::string & token, - std::string::iterator & begin, - std::string::iterator & end); - static TOKEN_TYPE token_type(const std::string & token); - static TOKEN_TYPE copy_token(std::string & token, std::istream & is); - TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); - bool get_true_false(std::istream::pos_type & pos, bool def); - TOKEN_TYPE get_rest_of_line(std::string &token); - static TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); - PHRQ_Parser::TOKEN_TYPE peek_token(); - - /** - Function reads an element name out of the equation string. - An element name is composed of a capital letter followed by any number - of lower case characters. - - Arguments: - begin input, points to position in the equation to begin - output, points to next character of equation after - element name. - end input, points to last position in the equation - element input pointer to place to return element character string - */ - STATUS_TYPE get_elt(std::string::iterator & begin, - const std::string::iterator end, - std::string & element); - - - /** - Compares a string value to match beginning letters of a list of options - - Arguments: - item entry: pointer to string to compare - n exit: item in list that was matched - list entry: pointer to list of character values, assumed to - be lower case - count_list entry: number of character values in list - - Returns: - OK item matched - ERROR item not matched - n -1 item not matched - i position of match in list - */ - static FIND_TYPE find_option(const std::string & item, int *n, - const std::vector < std::string > &list, - bool exact); - - - int error_msg(const std::ostringstream & err_str, ONERROR_TYPE stop) - { - return error_msg(err_str.str().c_str(), stop); - } - int error_msg(const char *err_str, ONERROR_TYPE stop); - int warning_msg(const char *err_str); - - void set_echo_file(ECHO_OPTION opt) - { - echo_file = opt; - } - ECHO_OPTION get_echo_file() - { - return this->echo_file; - }; - - void set_echo_stream(ECHO_OPTION opt) - { - echo_stream = opt; - } - ECHO_OPTION get_echo_stream() - { - return this->echo_stream; - }; - - STATUS_TYPE parse_couple(std::string & token); - - //STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, - // std::istream::pos_type & pos); - STATUS_TYPE addPair(std::map < std::string, double >&totals, - std::istream::pos_type & pos); - - protected: - LINE_TYPE get_logical_line(); - - private: - std::istream & m_input_stream; - std::ostream & m_output_stream; - std::ostream & m_error_stream; - int m_input_error; - KEY_TYPE m_next_keyword; - std::string m_line; - std::string m_line_save; - std::istringstream m_line_iss; - LINE_TYPE m_line_type; - ECHO_OPTION echo_stream; - ECHO_OPTION echo_file; - std::string accumulated; - bool accumulate; -#if defined(PHREEQC_CLASS) - Phreeqc * p_instance; -#endif -}; - -//// Global functions -//inline std::string trim_right(const std::string &source , const std::string& t = " \t") -//{ -// std::string str = source; -// return str.erase( str.find_last_not_of(t) + 1); -//} -// -//inline std::string trim_left( const std::string& source, const std::string& t = " \t") -//{ -// std::string str = source; -// return str.erase(0 , source.find_first_not_of(t) ); -//} -// -//inline std::string trim(const std::string& source, const std::string& t = " \t") -//{ -// std::string str = source; -// return trim_left( trim_right( str , t) , t ); -//} - -#endif // PHRQ_PARSER_H_INCLUDED diff --git a/PPassemblage.cxx b/PPassemblage.cxx index ec8da3ef..289edc08 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -63,9 +63,9 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { @@ -372,7 +372,7 @@ cxxPPassemblage::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double { if ((*it).second.get_name() == itadd->second.get_name()) { - (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); + (*it).second.add((*itadd).second, extensive); found = true; break; } diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index ff8d6f6e..064d32ae 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -464,7 +464,7 @@ cxxPPassemblageComp::totalize(PHREEQC_PTR_ARG) void -cxxPPassemblageComp::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & addee, double extensive) +cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) { double ext1, ext2, f1, f2; if (extensive == 0.0) @@ -500,8 +500,8 @@ cxxPPassemblageComp::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & addee oss << "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } //double si; diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 9046d5e1..b4428c77 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -56,7 +56,7 @@ class cxxPPassemblageComp: public PHRQ_base return (this->totals); }; - void add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblageComp & comp, double extensive); + void add(const cxxPPassemblageComp & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI diff --git a/Phreeqc.h b/Phreeqc.h index aad9ee8a..68faee8a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -35,6 +35,7 @@ class cxxNameDouble; #undef extern #include "global_structures.h" #include "pitzer_structures.h" +class cxxMix; class Phreeqc { public: @@ -1228,6 +1229,9 @@ extern void free_spread(void); extern void MergeFinalize(void); #endif +// convert class to struct +struct mix * cxxMix2mix(cxxMix &mx); + /* tally.c */ void add_all_components_tally(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 3d282f28..b9442013 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -870,7 +870,8 @@ read_mix_raw(void) cxxMix ex(&phrq_io); ex.read_raw(parser); - struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); + //struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); + struct mix *mix_ptr = cxxMix2mix(ex); int n; /* diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 897d7802..65fb24ef 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -61,9 +61,9 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { diff --git a/Solution.cxx b/Solution.cxx index 09337fd2..f5fb4a5a 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -96,7 +96,7 @@ isotopes(solution_ptr, io) } -cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solutions, +cxxSolution::cxxSolution(const std::map < int, cxxSolution > &solutions, cxxMix & mix, int l_n_user, PHRQ_io * io) // // constructor for cxxSolution from mixture of solutions @@ -114,18 +114,21 @@ isotopes(io) // // Mix solutions // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { std::map < int, cxxSolution >::const_iterator sol = solutions.find(it->first); if (sol == solutions.end()) { - sprintf(P_INSTANCE_POINTER error_string, - "Solution %d not found in mix_cxxSolutions.", it->first); - P_INSTANCE_POINTER error_msg(P_INSTANCE_POINTER error_string, CONTINUE); - P_INSTANCE_POINTER input_error++; + //sprintf(P_INSTANCE_POINTER error_string, + // "Solution %d not found in mix_cxxSolutions.", it->first); + //error_msg(P_INSTANCE_POINTER error_string, CONTINUE); + //P_INSTANCE_POINTER input_error++; + std::ostringstream msg; + msg << "Solution " << it->first << " not found in mix_cxxSolutions."; + error_msg(msg.str(), CONTINUE); } else { @@ -1574,7 +1577,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina } else { - P_INSTANCE_POINTER error_msg("Could not find master species in modify_activities.", STOP); + error_msg("Could not find master species in modify_activities.", STOP); } } } @@ -1607,7 +1610,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina } else { - P_INSTANCE_POINTER error_msg("Could not find master species in modify_activities.", STOP); + error_msg("Could not find master species in modify_activities.", STOP); } } } diff --git a/Solution.h b/Solution.h index 9d03dba3..dfcdbefb 100644 --- a/Solution.h +++ b/Solution.h @@ -20,7 +20,7 @@ class cxxSolution:public cxxNumKeyword cxxSolution(PHRQ_io *io=NULL); cxxSolution(struct solution *, PHRQ_io *io=NULL); cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); - cxxSolution(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSolution > &solution_map, + cxxSolution( const std::map < int, cxxSolution > &solution_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSolution(); diff --git a/StorageBin.cxx b/StorageBin.cxx index c86b93c8..239d229a 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -133,7 +133,7 @@ PHRQ_base(io) cxxMix entity(struct_entity, this->Get_io()); this->setMix(use_ptr->n_mix_user, &entity); - std::map c = *(this->getMix(use_ptr->n_mix_user)->comps()); + std::map c = (this->getMix(use_ptr->n_mix_user)->Get_mixComps()); std::map::iterator it; for (it = c.begin(); it != c.end(); it++) { @@ -1008,7 +1008,7 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) } else { - P_INSTANCE_POINTER error_msg("cxxSolution not found in system2phreeqc", STOP); + error_msg("cxxSolution not found in system2phreeqc", STOP); } } diff --git a/Surface.cxx b/Surface.cxx index 3bd02419..2db4e675 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -99,9 +99,9 @@ cxxNumKeyword(io) // // Mix exchangers // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { @@ -1009,7 +1009,7 @@ cxxSurface::add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive std::map < std::string, cxxSurfaceComp >::iterator it = this->surfaceComps.find((*itadd).first); if (it != this->surfaceComps.end()) { - (*it).second.add(P_INSTANCE_COMMA (*itadd).second, extensive); + (*it).second.add((*itadd).second, extensive); } else { diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index fedcdc32..3f8b3a15 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -85,7 +85,7 @@ struct master * error_oss << "Master species not in data base for " << elt_ptr-> name << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); return (NULL); } if (elt_ptr->master->type != SURF) @@ -100,7 +100,7 @@ struct master * "Surface formula does not contain an surface master species, " << this->formula << std::endl; //Utilities::error_msg(error_oss.str(), CONTINUE); - P_INSTANCE_POINTER error_msg(error_oss.str().c_str(), CONTINUE); + error_msg(error_oss.str().c_str(), CONTINUE); } return (master_ptr); } @@ -550,7 +550,7 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxSurfaceComp::add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & addee, double extensive) +cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) { if (extensive == 0.0) return; @@ -605,8 +605,8 @@ cxxSurfaceComp::add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & addee, double e oss << "Can not mix two Surface components with same formula and different related phases, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } else if (this->phase_name.size() != 0) @@ -622,8 +622,8 @@ cxxSurfaceComp::add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & addee, double e oss << "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } else if (this->rate_name.size() != 0) @@ -639,8 +639,8 @@ cxxSurfaceComp::add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & addee, double e oss << "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; - P_INSTANCE_POINTER error_msg(oss.str().c_str(), CONTINUE); - P_INSTANCE_POINTER input_error++; + error_msg(oss.str().c_str(), CONTINUE); + //P_INSTANCE_POINTER input_error++; return; } //double Dw; diff --git a/SurfaceComp.h b/SurfaceComp.h index 49b1d144..a9783b7d 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -32,7 +32,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); const cxxNameDouble & get_totals() const; - void add(PHREEQC_PTR_ARG_COMMA const cxxSurfaceComp & comp, double extensive); + void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); std::string charge_name(PHREEQC_PTR_ARG); static std::string get_charge_name(PHREEQC_PTR_ARG_COMMA char *token); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 8671ce8c..401c8d06 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -100,9 +100,9 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >*mixcomps = mix.comps(); + std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; - for (it = mixcomps->begin(); it != mixcomps->end(); it++) + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) { diff --git a/cxxMix.cxx b/cxxMix.cxx index 5623e043..47db4b8e 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -59,7 +59,7 @@ cxxMix::~cxxMix() { } - +#ifdef MOVE_TO_STRUCTURES struct mix * cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) // @@ -97,6 +97,7 @@ cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) mix_ptr->count_comps = (int) this->mixComps.size(); return (mix_ptr); } +#endif #ifdef SKIP void diff --git a/cxxMix.h b/cxxMix.h index e4af2554..ec691c9d 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -18,7 +18,7 @@ class cxxMix:public cxxNumKeyword cxxMix(struct mix *, PHRQ_io *io=NULL); ~cxxMix(); - struct mix *cxxMix2mix(PHREEQC_PTR_ARG); + //struct mix *cxxMix2mix(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -46,9 +46,9 @@ class cxxMix:public cxxNumKeyword } }; - std::map < int, double >*comps() + std::map < int, double > & Get_mixComps() { - return &mixComps; + return mixComps; } protected: From 7c9913195aeba48c8ab9780ddecec1f6f8a4d5c6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 26 Sep 2011 22:56:22 +0000 Subject: [PATCH 0251/1077] Worked through kinetics to remove PHREEQC_PTR. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5649 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 4 +++- KineticsComp.h | 13 ++++++++++--- NameDouble.h | 9 +++------ Phreeqc.cpp | 2 +- Phreeqc.h | 10 +++++++++- ReadClass.cxx | 8 +++++--- StorageBin.cxx | 9 ++++++--- cxxKinetics.cxx | 11 ++++++----- cxxKinetics.h | 24 +++++++++++++++--------- 9 files changed, 58 insertions(+), 32 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index d2710376..dd513948 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -46,7 +46,7 @@ cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr, PHRQ_i PHRQ_base(io), namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) { - this->set_rate_name(kinetics_comp_ptr->rate_name); + this->Set_rate_name(kinetics_comp_ptr->rate_name); tol = kinetics_comp_ptr->tol; m = kinetics_comp_ptr->m; m0 = kinetics_comp_ptr->m0; @@ -61,6 +61,7 @@ cxxKineticsComp::~cxxKineticsComp() { } +#ifdef MOVE_TO_STRUCTURES struct kinetics_comp * cxxKineticsComp::cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el) @@ -111,6 +112,7 @@ struct kinetics_comp * } return (kinetics_comp_ptr); } +#endif #ifdef SKIP void diff --git a/KineticsComp.h b/KineticsComp.h index 5fd5c5e4..c34efc09 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -17,7 +17,7 @@ public: cxxKineticsComp(struct kinetics_comp *, PHRQ_io *io=NULL); ~cxxKineticsComp(); - static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el); + //static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -25,11 +25,11 @@ public: void read_raw(CParser & parser, bool check = true); - const std::string &get_rate_name() const + const std::string &Get_rate_name() const { return this->rate_name; } - void set_rate_name(char * s) + void Set_rate_name(char * s) { if (s != NULL) this->rate_name = std::string(s); @@ -37,6 +37,13 @@ public: this->rate_name.clear(); } + cxxNameDouble &Get_namecoef(void) {return namecoef;}; + double Get_tol(void) {return tol;}; + double Get_m(void) {return m;}; + double Get_m0(void) {return m0;}; + double Get_moles(void) {return moles;}; + std::vector < double > &Get_d_params(void) {return d_params;}; + #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/NameDouble.h b/NameDouble.h index f3f0b743..213b205d 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -34,17 +34,14 @@ class cxxNameDouble:public ~ cxxNameDouble(); - struct elt_list * - elt_list(PHREEQC_PTR_ARG); + struct elt_list * elt_list(PHREEQC_PTR_ARG); struct master_activity * master_activity(PHREEQC_PTR_ARG) const; - struct conc * - conc(PHREEQC_PTR_ARG) const; + struct conc * conc(PHREEQC_PTR_ARG) const; - struct name_coef * - name_coef(PHREEQC_PTR_ARG) const; + struct name_coef * name_coef(PHREEQC_PTR_ARG) const; void dump_xml(std::ostream & s_oss, unsigned int indent) const; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c4d0bac3..4d4738d1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -512,7 +512,7 @@ size_t Phreeqc::list_components(std::list &list_c) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); cxxKinetics entity(&kinetics[i], &phrq_io); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // Put in all primaries diff --git a/Phreeqc.h b/Phreeqc.h index 68faee8a..0a96a30d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -35,7 +35,9 @@ class cxxNameDouble; #undef extern #include "global_structures.h" #include "pitzer_structures.h" +class cxxKinetics; class cxxMix; +class cxxKineticsComp; class Phreeqc { public: @@ -1230,7 +1232,13 @@ extern void MergeFinalize(void); #endif // convert class to struct -struct mix * cxxMix2mix(cxxMix &mx); + +struct mix * cxxMix2mix(cxxMix *mx); +struct kinetics *cxxKinetics2kinetics(cxxKinetics * kin); +struct elt_list * cxxNameDouble2elt_list(cxxNameDouble * nd); +struct kinetics_comp * cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > * el); +struct name_coef * cxxNameDouble2name_coef(cxxNameDouble * nd); + /* tally.c */ diff --git a/ReadClass.cxx b/ReadClass.cxx index b9442013..36788a9f 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -489,7 +489,8 @@ read_kinetics_raw(void) cxxKinetics ex(&phrq_io); ex.read_raw(parser); - struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); + //struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); + struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&ex); int n; /* @@ -871,7 +872,7 @@ read_mix_raw(void) cxxMix ex(&phrq_io); ex.read_raw(parser); //struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); - struct mix *mix_ptr = cxxMix2mix(ex); + struct mix *mix_ptr = cxxMix2mix(&ex); int n; /* @@ -1888,7 +1889,8 @@ read_kinetics_modify(void) entity.read_raw(parser, false); // save entity - struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(PHREEQC_THIS); + //struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(PHREEQC_THIS); + struct kinetics *entity_ptr = cxxKinetics2kinetics(&entity); kinetics_free(&(kinetics[n])); kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); free_check_null(kinetics[n].description); diff --git a/StorageBin.cxx b/StorageBin.cxx index 239d229a..d8ef84ba 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1046,8 +1046,9 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(n); if (it != this->Kinetics.end()) { - struct kinetics *kinetics_ptr = - (it->second).cxxKinetics2kinetics(P_INSTANCE); + //struct kinetics *kinetics_ptr = + // (it->second).cxxKinetics2kinetics(P_INSTANCE); + struct kinetics *kinetics_ptr = P_INSTANCE_POINTER cxxKinetics2kinetics(&(it->second)); P_INSTANCE_POINTER kinetics_copy(kinetics_ptr, &P_INSTANCE_POINTER kinetics[0], n); P_INSTANCE_POINTER count_kinetics++; P_INSTANCE_POINTER kinetics_free(kinetics_ptr); @@ -1282,7 +1283,9 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Kinetics if (this->getKinetics(n) != NULL) { - system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(P_INSTANCE); + //system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(P_INSTANCE); + system_ptr->kinetics = P_INSTANCE_POINTER cxxKinetics2kinetics(this->getKinetics(n)); + } else { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 401c8d06..eaaef8c1 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -67,7 +67,7 @@ totals(kinetics_ptr->totals) for (i = 0; i < kinetics_ptr->count_comps; i++) { cxxKineticsComp ec(&(kinetics_ptr->comps[i]), this->Get_io()); - std::string str(ec.get_rate_name()); + std::string str(ec.Get_rate_name()); //this->kineticsComps[str] = ec; this->kineticsComps.push_back(ec); } @@ -117,6 +117,7 @@ cxxKinetics::~cxxKinetics() { } +#ifdef MOVE_TO_STRUCTURES struct kinetics * cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) // @@ -173,7 +174,7 @@ cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) } return (kinetics_ptr); } - +#endif #ifdef SKIP void cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -448,7 +449,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) bool found = false; for (kit = this->kineticsComps.begin(); kit != this->kineticsComps.end(); kit++) { - if (kit->get_rate_name() == ec.get_rate_name()) + if (kit->Get_rate_name() == ec.Get_rate_name()) { found = true; break; @@ -462,7 +463,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) { cxxKineticsComp ec1(this->Get_io()); ec1.read_raw(reread, false); - std::string str(ec1.get_rate_name()); + std::string str(ec1.Get_rate_name()); this->kineticsComps.push_back(ec1); } /* @@ -746,7 +747,7 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) std::list < cxxKineticsComp >::iterator it; for (it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) { - if ((*it).get_rate_name() == (*itadd).get_rate_name()) + if ((*it).Get_rate_name() == (*itadd).Get_rate_name()) { found = true; break; diff --git a/cxxKinetics.h b/cxxKinetics.h index 3cd95379..3ff4772a 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -22,9 +22,9 @@ class cxxKinetics:public cxxNumKeyword int n_user, PHRQ_io *io=NULL); ~cxxKinetics(); - struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); + //struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); - struct kinetics_comp *cxxKineticsComp2kinetics_comp(); + //struct kinetics_comp *cxxKineticsComp2kinetics_comp(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -32,14 +32,21 @@ class cxxKinetics:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - bool get_related_phases(void); + bool Get_related_phases(void); + bool Get_related_rate(void); + + std::vector < double > &Get_steps(void) {return steps;}; + double Get_step_divide(void) {return step_divide;}; + int Get_rk(void) {return rk;}; + int Get_bad_step_max(void) {return bad_step_max;}; + bool Get_use_cvode(void) {return use_cvode;}; + int Get_cvode_steps(void) {return cvode_steps;}; + int Get_cvode_order(void) {return cvode_order;}; + std::list < cxxKineticsComp > &Get_kineticsComps(void) {return kineticsComps;}; + cxxNameDouble & Get_totals(void) {return this->totals;}; + int Get_equal_steps(void) {return equal_steps;}; - bool get_related_rate(void); - cxxNameDouble & get_totals(void) - { - return this->totals; - } #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); @@ -48,7 +55,6 @@ class cxxKinetics:public cxxNumKeyword void add(const cxxKinetics & addee, double extensive); protected: - //std::map < std::string, cxxKineticsComp > kineticsComps; std::list < cxxKineticsComp > kineticsComps; std::vector < double >steps; int equal_steps; From 06f4e08ecf081cbb5001bf252c260874a8d91019 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 15:54:10 +0000 Subject: [PATCH 0252/1077] Finished with Exchange removing all P_INSTANCE I think. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5650 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 9 ++++---- ExchComp.h | 56 ++++++++++++++++++++++++-------------------------- Exchange.cxx | 44 +++++++++++++++++++++------------------ Exchange.h | 8 ++++---- Phreeqc.h | 12 ++++++++--- ReadClass.cxx | 6 ++++-- StorageBin.cxx | 9 +++++--- 7 files changed, 79 insertions(+), 65 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 03484602..3e687634 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -52,15 +52,15 @@ cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr, PHRQ_io *io) PHRQ_base(io), formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) { - this->set_formula(exch_comp_ptr->formula); + this->Set_formula(exch_comp_ptr->formula); moles = exch_comp_ptr->moles; // totals in constructor //formula_totals in constructor la = exch_comp_ptr->la; charge_balance = exch_comp_ptr->charge_balance; - this->set_phase_name(exch_comp_ptr->phase_name); + this->Set_phase_name(exch_comp_ptr->phase_name); phase_proportion = exch_comp_ptr->phase_proportion; - this->set_rate_name(exch_comp_ptr->rate_name); + this->Set_rate_name(exch_comp_ptr->rate_name); formula_z = exch_comp_ptr->formula_z; } @@ -129,7 +129,7 @@ cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, cxxExchComp::~cxxExchComp() { } - +#ifdef MOVE_TO_STRUCTURES struct master * cxxExchComp::get_master(PHREEQC_PTR_ARG) { @@ -238,6 +238,7 @@ struct exch_comp * } return (exch_comp_ptr); } +#endif void cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const diff --git a/ExchComp.h b/ExchComp.h index ccb2c352..0227b097 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -17,10 +17,10 @@ class cxxExchComp: public PHRQ_base cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); ~cxxExchComp(); - struct master *get_master(PHREEQC_PTR_ARG); + //struct master *Get_master(PHREEQC_PTR_ARG); - static struct exch_comp *cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > - &el); + //static struct exch_comp *cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > + // &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -28,108 +28,106 @@ class cxxExchComp: public PHRQ_base void read_raw(CParser & parser, bool check=true); - const std::string &get_formula() const + const std::string &Get_formula() const { return this->formula; } - void set_formula(char *cstring) + void Set_formula(char *cstring) { if (cstring != NULL) this->formula = std::string(cstring); else this->formula.clear(); } - double get_moles() const + double Get_moles() const { return this->moles; } - void set_moles(double d) + void Set_moles(double d) { this->moles = d; } - double get_la() const + double Get_la() const { return this->la; } - void set_la(double d) + void Set_la(double d) { this->la = d; } - double get_charge_balance() const + double Get_charge_balance() const { return this->charge_balance; } - void set_charge_balance(double d) + void Set_charge_balance(double d) { this->charge_balance = d; } - const std::string &get_phase_name() const + const std::string &Get_phase_name() const { return this->phase_name; } - void set_phase_name(char *cstring) + void Set_phase_name(char *cstring) { if (cstring != NULL) this->phase_name = std::string(cstring); else this->phase_name.clear(); } - double get_phase_proportion() const + double Get_phase_proportion() const { return this->phase_proportion; } - void set_phase_proportion(double d) + void Set_phase_proportion(double d) { this->phase_proportion = d; } - const std::string &get_rate_name() const + const std::string &Get_rate_name() const { return this->rate_name; } - void set_rate_name(char *cstring) + void Set_rate_name(char *cstring) { if (cstring != NULL) this->rate_name = std::string(cstring); else this->rate_name.clear(); } - double get_formula_z() const + double Get_formula_z() const { return this->formula_z; } - void set_formula_z(double d) + void Set_formula_z(double d) { this->formula_z = d; } - void set_totals(struct elt_list *e_l, int count) + void Set_totals(struct elt_list *e_l, int count) { this->totals = cxxNameDouble(e_l, count); } - void set_totals(struct elt_list *e_l) + void Set_totals(struct elt_list *e_l) { this->totals = cxxNameDouble(e_l); } - void set_totals(cxxNameDouble nd) + void Set_totals(cxxNameDouble nd) { this->totals = nd; } - void set_formula_totals(struct elt_list *e_l, int count) + void Set_formula_totals(struct elt_list *e_l, int count) { this->formula_totals = cxxNameDouble(e_l, count); } - void set_formula_totals(struct elt_list *e_l) + void Set_formula_totals(struct elt_list *e_l) { this->formula_totals = cxxNameDouble(e_l); } - void set_formula_totals(cxxNameDouble nd) + void Set_formula_totals(cxxNameDouble nd) { this->formula_totals = nd; } - const cxxNameDouble & get_totals() const - { - return (this->totals); - }; + const cxxNameDouble & Get_totals() const {return (this->totals);}; + const cxxNameDouble & Get_formula_totals(void) const {return this->formula_totals;}; void add(const cxxExchComp & comp, double extensive); diff --git a/Exchange.cxx b/Exchange.cxx index 3d5520aa..220624dc 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -50,7 +50,7 @@ cxxNumKeyword(io) for (i = 0; i < exchange_ptr->count_comps; i++) { cxxExchComp ec(&(exchange_ptr->comps[i]), this->Get_io()); - std::string str(ec.get_formula()); + std::string str(ec.Get_formula()); exchComps[str] = ec; } @@ -58,7 +58,7 @@ cxxNumKeyword(io) } -cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &entities, +cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) { @@ -92,6 +92,7 @@ cxxNumKeyword(io) } } +#ifdef SKIP_OR_MOVE_TO_STRUCTURES cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io *io) // // constructor for cxxExchange from reaction calculation @@ -116,23 +117,23 @@ cxxNumKeyword(io) { cxxExchComp ec(this->Get_io()); //char * formula; - ec.set_formula(P_INSTANCE_POINTER x[i]->exch_comp->formula); + ec.Set_formula(P_INSTANCE_POINTER x[i]->exch_comp->formula); //double moles; - ec.set_moles(0.0); + ec.Set_moles(0.0); //cxxNameDouble formula_totals; - ec.set_formula_totals(P_INSTANCE_POINTER x[i]->exch_comp->formula_totals); + ec.Set_formula_totals(P_INSTANCE_POINTER x[i]->exch_comp->formula_totals); //cxxNameDouble totals; see below //double la; - ec.set_la(P_INSTANCE_POINTER x[i]->master[0]->s->la); + ec.Set_la(P_INSTANCE_POINTER x[i]->master[0]->s->la); //double charge_balance; see below //char *phase_name; - ec.set_phase_name(P_INSTANCE_POINTER x[i]->exch_comp->phase_name); + ec.Set_phase_name(P_INSTANCE_POINTER x[i]->exch_comp->phase_name); //double phase_proportion; - ec.set_phase_proportion(P_INSTANCE_POINTER x[i]->exch_comp->phase_proportion); + ec.Set_phase_proportion(P_INSTANCE_POINTER x[i]->exch_comp->phase_proportion); //char *rate_name; - ec.set_rate_name(P_INSTANCE_POINTER x[i]->exch_comp->rate_name); + ec.Set_rate_name(P_INSTANCE_POINTER x[i]->exch_comp->rate_name); //double formula_z; - ec.set_formula_z(P_INSTANCE_POINTER x[i]->exch_comp->formula_z); + ec.Set_formula_z(P_INSTANCE_POINTER x[i]->exch_comp->formula_z); // calculate charge and totals P_INSTANCE_POINTER count_elts = 0; @@ -154,7 +155,7 @@ cxxNumKeyword(io) P_INSTANCE_POINTER add_elt_list(P_INSTANCE_POINTER x[i]->master[0]->s->next_elt, 1e-20); } //double charge_balance - ec.set_charge_balance(charge); + ec.Set_charge_balance(charge); //cxxNameDouble totals; if (P_INSTANCE_POINTER count_elts > 0) { @@ -162,14 +163,15 @@ cxxNumKeyword(io) (size_t) sizeof(struct elt_list), P_INSTANCE_POINTER elt_list_compare); P_INSTANCE_POINTER elt_list_combine(); } - ec.set_totals(P_INSTANCE_POINTER elt_list, P_INSTANCE_POINTER count_elts); + ec.Set_totals(P_INSTANCE_POINTER elt_list, P_INSTANCE_POINTER count_elts); // add to comp list - std::string str(ec.get_formula()); + std::string str(ec.Get_formula()); this->exchComps[str] = ec; } } } +#endif cxxExchange::~cxxExchange() { @@ -181,7 +183,7 @@ cxxExchange::get_related_phases() for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if ((*it).second.get_phase_name().size() == 0) + if ((*it).second.Get_phase_name().size() == 0) continue; return (true); } @@ -194,13 +196,14 @@ cxxExchange::get_related_rate() for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) { - if ((*it).second.get_rate_name().size() == 0) + if ((*it).second.Get_rate_name().size() == 0) continue; return (true); } return (false); } +#ifdef MOVE_TO_STRUCTURES struct exchange * cxxExchange::cxxExchange2exchange(PHREEQC_PTR_ARG) // @@ -223,6 +226,7 @@ cxxExchange::cxxExchange2exchange(PHREEQC_PTR_ARG) exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(P_INSTANCE_COMMA this->exchComps); return (exchange_ptr); } +#endif void cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const @@ -395,16 +399,16 @@ cxxExchange::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) + if (this->exchComps.find(ec.Get_formula()) != this->exchComps.end()) { - cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; + cxxExchComp & comp = this->exchComps.find(ec.Get_formula())->second; comp.read_raw(reread, false); } else { cxxExchComp ec1(this->Get_io()); ec1.read_raw(reread, false); - std::string str(ec1.get_formula()); + std::string str(ec1.Get_formula()); this->exchComps[str] = ec1; } } @@ -559,8 +563,8 @@ cxxExchange::totalize() for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { - this->totals.add_extensive((*it).second.get_totals(), 1.0); - this->totals.add("Charge", (*it).second.get_charge_balance()); + this->totals.add_extensive((*it).second.Get_totals(), 1.0); + this->totals.add("Charge", (*it).second.Get_charge_balance()); } return; } diff --git a/Exchange.h b/Exchange.h index 6343c2aa..d2adf8d6 100644 --- a/Exchange.h +++ b/Exchange.h @@ -16,15 +16,15 @@ class cxxExchange:public cxxNumKeyword public: cxxExchange(PHRQ_io *io=NULL); - cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); + //cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); cxxExchange(struct exchange *, PHRQ_io *io=NULL); - cxxExchange(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxExchange > &exchange_map, + cxxExchange(const std::map < int, cxxExchange > &exchange_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); - struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); + //struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); - struct exch_comp *cxxExchComp2exch_comp(); + //struct exch_comp *cxxExchComp2exch_comp(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/Phreeqc.h b/Phreeqc.h index 0a96a30d..b920c4d8 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,9 @@ class cxxNameDouble; class cxxKinetics; class cxxMix; class cxxKineticsComp; +class cxxExchange; +class cxxExchComp; + class Phreeqc { public: @@ -1235,10 +1239,12 @@ extern void MergeFinalize(void); struct mix * cxxMix2mix(cxxMix *mx); struct kinetics *cxxKinetics2kinetics(cxxKinetics * kin); -struct elt_list * cxxNameDouble2elt_list(cxxNameDouble * nd); +struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct kinetics_comp * cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > * el); -struct name_coef * cxxNameDouble2name_coef(cxxNameDouble * nd); - +struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); +struct exchange * cxxExchange2exchange(cxxExchange * ex); +struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); +struct master * Get_exch_master(const cxxExchComp * ec); /* tally.c */ diff --git a/ReadClass.cxx b/ReadClass.cxx index 36788a9f..7ce6f3e1 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -204,7 +204,8 @@ read_exchange_raw(void) cxxExchange ex(&phrq_io); ex.read_raw(parser); - struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); + //struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); + struct exchange *exchange_ptr = cxxExchange2exchange(&ex); int n; /* @@ -1516,7 +1517,8 @@ read_exchange_modify(void) entity.read_raw(parser, false); // save entity - struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); + //struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); + struct exchange *entity_ptr = cxxExchange2exchange(&entity); exchange_free(&(exchange[n])); exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); diff --git a/StorageBin.cxx b/StorageBin.cxx index d8ef84ba..9e5f7c44 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1017,8 +1017,10 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) std::map < int, cxxExchange >::iterator it = this->Exchangers.find(n); if (it != this->Exchangers.end()) { - struct exchange *exchange_ptr = - (it->second).cxxExchange2exchange(P_INSTANCE); + //struct exchange *exchange_ptr = + // (it->second).cxxExchange2exchange(P_INSTANCE); + struct exchange *exchange_ptr = P_INSTANCE_POINTER cxxExchange2exchange(&it->second); + P_INSTANCE_POINTER exchange_copy(exchange_ptr, &P_INSTANCE_POINTER exchange[0], n); P_INSTANCE_POINTER count_exchange++; P_INSTANCE_POINTER exchange_free(exchange_ptr); @@ -1262,7 +1264,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Exchangers if (this->getExchange(n) != NULL) { - system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(P_INSTANCE); + //system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(P_INSTANCE); + system_ptr->exchange = P_INSTANCE_POINTER cxxExchange2exchange(this->getExchange(n)); } else { From 2dab6f8ed85a04b1778e3add6504e52a41e01645 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 17:15:14 +0000 Subject: [PATCH 0253/1077] Removed PHREEQC_PTR_ARG from gas phase and temperature. Removed commented PHREEQC_PTR from some of the header files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5651 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.h | 5 ----- Exchange.h | 4 ---- GasPhase.cxx | 5 ++++- GasPhase.h | 9 +++++++-- Phreeqc.h | 6 +++++- ReadClass.cxx | 9 ++++++--- StorageBin.cxx | 9 +++++---- Temperature.cxx | 3 ++- Temperature.h | 6 +++++- cxxKinetics.h | 4 ---- cxxMix.h | 2 -- 11 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ExchComp.h b/ExchComp.h index 0227b097..55f9c9a2 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -17,11 +17,6 @@ class cxxExchComp: public PHRQ_base cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); ~cxxExchComp(); - //struct master *Get_master(PHREEQC_PTR_ARG); - - //static struct exch_comp *cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > - // &el); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/Exchange.h b/Exchange.h index d2adf8d6..5bd17bdc 100644 --- a/Exchange.h +++ b/Exchange.h @@ -22,10 +22,6 @@ public: cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); - //struct exchange *cxxExchange2exchange(PHREEQC_PTR_ARG); - - //struct exch_comp *cxxExchComp2exch_comp(); - void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); diff --git a/GasPhase.cxx b/GasPhase.cxx index 0ab74987..8efdfc59 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -123,7 +123,7 @@ cxxNumKeyword(io) cxxGasPhase::~cxxGasPhase() { } - +#ifdef MOVE_TO_STRUCTURES struct gas_comp * cxxGasPhase::cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG) { @@ -154,7 +154,9 @@ cxxGasPhase::cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG) } return (gas_comp_ptr); } +#endif +#ifdef MOVE_TO_STRUCTURES struct gas_phase * cxxGasPhase::cxxGasPhase2gas_phase(PHREEQC_PTR_ARG) // @@ -189,6 +191,7 @@ cxxGasPhase::cxxGasPhase2gas_phase(PHREEQC_PTR_ARG) return (gas_phase_ptr); } +#endif #ifdef SKIP void diff --git a/GasPhase.h b/GasPhase.h index ed32bcc6..54374508 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -27,9 +27,9 @@ class cxxGasPhase:public cxxNumKeyword GP_VOLUME = 1 }; - struct gas_phase *cxxGasPhase2gas_phase(PHREEQC_PTR_ARG); + // struct gas_phase *cxxGasPhase2gas_phase(PHREEQC_PTR_ARG); - struct gas_comp *cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG); + // struct gas_comp *cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -48,6 +48,11 @@ class cxxGasPhase:public cxxNumKeyword { return this->totals; }; + const cxxNameDouble & Get_gasPhaseComps(void) const {return gasPhaseComps;}; + GP_TYPE Get_type(void) const {return type;}; + double Get_total_p(void) const {return total_p;}; + double Get_volume(void) const {return volume;}; + cxxNameDouble & Get_totals(void) {return totals;}; private: void add(const cxxGasPhase & addee, double extensive); diff --git a/Phreeqc.h b/Phreeqc.h index b920c4d8..57df863d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -41,6 +41,8 @@ class cxxMix; class cxxKineticsComp; class cxxExchange; class cxxExchComp; +class cxxGasPhase; +class cxxTemperature; class Phreeqc { @@ -1245,7 +1247,9 @@ struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct exchange * cxxExchange2exchange(cxxExchange * ex); struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); struct master * Get_exch_master(const cxxExchComp * ec); - +struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); +struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); +struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); /* tally.c */ void add_all_components_tally(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 7ce6f3e1..7910b95c 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -683,7 +683,8 @@ read_gas_phase_raw(void) cxxGasPhase ex(&phrq_io); ex.read_raw(parser); - struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); + //struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); + struct gas_phase *gas_phase_ptr = cxxGasPhase2gas_phase(&ex); int n; /* @@ -969,7 +970,8 @@ read_temperature_raw(void) cxxTemperature ex(&phrq_io); ex.read_raw(parser); - struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); + //struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); + struct temperature *temperature_ptr = cxxTemperature2temperature(&ex); int n; /* @@ -1802,7 +1804,8 @@ read_gas_phase_modify(void) cxxGasPhase entity(&(gas_phase[n]), &phrq_io); entity.read_raw(parser, false); // save entity - struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); + //struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); + struct gas_phase *entity_ptr = cxxGasPhase2gas_phase(&entity); gas_phase_free(&(gas_phase[n])); gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); free_check_null(gas_phase[n].description); diff --git a/StorageBin.cxx b/StorageBin.cxx index 9e5f7c44..9fcf0a8b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1033,8 +1033,9 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(n); if (it != this->GasPhases.end()) { - struct gas_phase *gas_phase_ptr = - (it->second).cxxGasPhase2gas_phase(P_INSTANCE); + //struct gas_phase *gas_phase_ptr = + // (it->second).cxxGasPhase2gas_phase(P_INSTANCE); + struct gas_phase *gas_phase_ptr = P_INSTANCE_POINTER cxxGasPhase2gas_phase(&(it->second)); P_INSTANCE_POINTER gas_phase_copy(gas_phase_ptr, &P_INSTANCE_POINTER gas_phase[0], n); P_INSTANCE_POINTER count_gas_phase++; P_INSTANCE_POINTER gas_phase_free(gas_phase_ptr); @@ -1275,8 +1276,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // GasPhases if (this->getGasPhase(n) != NULL) { - system_ptr->gas_phase = - (this->getGasPhase(n))->cxxGasPhase2gas_phase(P_INSTANCE); + //system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(P_INSTANCE); + system_ptr->gas_phase = P_INSTANCE_POINTER cxxGasPhase2gas_phase(this->getGasPhase(n)); } else { diff --git a/Temperature.cxx b/Temperature.cxx index d3edecda..8500829b 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -71,7 +71,7 @@ cxxTemperature::~cxxTemperature() { } - +#ifdef MOVE_TO_STRUCTURES struct temperature * cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) // @@ -109,6 +109,7 @@ cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) } return (temperature_ptr); } +#endif #ifdef SKIP void diff --git a/Temperature.h b/Temperature.h index 9d623aa7..ee06f9a3 100644 --- a/Temperature.h +++ b/Temperature.h @@ -18,7 +18,7 @@ class cxxTemperature:public cxxNumKeyword cxxTemperature(struct temperature *, PHRQ_io *io=NULL); ~cxxTemperature(); - struct temperature *cxxTemperature2temperature(PHREEQC_PTR_ARG); + //struct temperature *cxxTemperature2temperature(PHREEQC_PTR_ARG); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -26,6 +26,10 @@ class cxxTemperature:public cxxNumKeyword void read_raw(CParser & parser); + const std::vector & Get_temps(void) const {return temps;}; + int Get_countTemps(void) const {return countTemps;}; + bool Get_equalIncrements(void) const {return equalIncrements;}; + protected: std::vector < double >temps; int countTemps; diff --git a/cxxKinetics.h b/cxxKinetics.h index 3ff4772a..72396a29 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -22,10 +22,6 @@ class cxxKinetics:public cxxNumKeyword int n_user, PHRQ_io *io=NULL); ~cxxKinetics(); - //struct kinetics *cxxKinetics2kinetics(PHREEQC_PTR_ARG); - - //struct kinetics_comp *cxxKineticsComp2kinetics_comp(); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/cxxMix.h b/cxxMix.h index ec691c9d..df7aba9d 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -18,8 +18,6 @@ class cxxMix:public cxxNumKeyword cxxMix(struct mix *, PHRQ_io *io=NULL); ~cxxMix(); - //struct mix *cxxMix2mix(PHREEQC_PTR_ARG); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; From 02ab5c208cabe1fd9356fb659adfdbaa0c2bd22d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 19:59:49 +0000 Subject: [PATCH 0254/1077] Finished PPassemblage and Reaction P_INSTANCE removal. Removed some commented PHREEQC_PTR_ARG from headers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5652 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.h | 1 - GasPhase.h | 4 ---- ISolution.cxx | 6 ++++++ ISolution.h | 25 +------------------------ ISolutionComp.cxx | 5 +++++ ISolutionComp.h | 4 +--- KineticsComp.h | 2 -- PPassemblage.cxx | 24 +++++++++++++----------- PPassemblage.h | 16 ++++++---------- PPassemblageComp.cxx | 14 ++++---------- PPassemblageComp.h | 25 +++++++++++++------------ Phreeqc.cpp | 4 ++-- Phreeqc.h | 7 +++++++ Reaction.cxx | 9 +++++---- Reaction.h | 14 +++++++------- ReadClass.cxx | 12 ++++++++---- StorageBin.cxx | 9 ++++++--- System.cxx | 2 +- Temperature.h | 2 -- 19 files changed, 85 insertions(+), 100 deletions(-) diff --git a/Exchange.h b/Exchange.h index 5bd17bdc..5fa3a923 100644 --- a/Exchange.h +++ b/Exchange.h @@ -16,7 +16,6 @@ class cxxExchange:public cxxNumKeyword public: cxxExchange(PHRQ_io *io=NULL); - //cxxExchange(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); cxxExchange(struct exchange *, PHRQ_io *io=NULL); cxxExchange(const std::map < int, cxxExchange > &exchange_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); diff --git a/GasPhase.h b/GasPhase.h index 54374508..4b3c4649 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -27,10 +27,6 @@ class cxxGasPhase:public cxxNumKeyword GP_VOLUME = 1 }; - // struct gas_phase *cxxGasPhase2gas_phase(PHREEQC_PTR_ARG); - - // struct gas_comp *cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/ISolution.cxx b/ISolution.cxx index fb840cf3..7add501b 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -40,6 +40,7 @@ units("mMol/kgw") pes = NULL; } +#ifdef SKIP_OR_MOVE_TO_STRUCTURES cxxISolution::cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *solution_ptr, PHRQ_io *io) : cxxSolution(solution_ptr, io) @@ -58,12 +59,14 @@ cxxSolution(solution_ptr, io) // pe_data pes = P_INSTANCE_POINTER pe_data_dup(solution_ptr->pe); } +#endif cxxISolution::~cxxISolution() { //// ToDo //pe_data_free(this->pes); } +#ifdef SKIP_OR_MOVE_TO_STRUCTURES struct solution * cxxISolution::cxxISolution2solution(PHREEQC_PTR_ARG) // @@ -86,7 +89,9 @@ cxxISolution::cxxISolution2solution(PHREEQC_PTR_ARG) soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(P_INSTANCE_COMMA this->comps); return (soln_ptr); } +#endif +#ifdef SKIP_OR_MOVE_TO_STRUCTURES void cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) // @@ -177,6 +182,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) iter->second.set_moles(iter->second.get_moles() * l_mass_water); } } +#endif #ifdef SKIP cxxISolution & cxxISolution::read(CParser & parser) diff --git a/ISolution.h b/ISolution.h index 37a962e2..973eabe8 100644 --- a/ISolution.h +++ b/ISolution.h @@ -20,16 +20,10 @@ class cxxISolution:public cxxSolution public: cxxISolution(PHRQ_io *io=NULL); - cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *, PHRQ_io *io=NULL); - //cxxISolution(const cxxISolution&); ~cxxISolution(); - //static cxxISolution& read(CParser& parser); - //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - struct solution *cxxISolution2solution(PHREEQC_PTR_ARG); - double get_density() const { return this->density; @@ -56,30 +50,13 @@ class cxxISolution:public cxxSolution } //char * get_redox()const {return this->pe[this->default_pe].get_name();} - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; - - void ConvertUnits(PHREEQC_PTR_ARG); - -#ifdef ORCHESTRA - void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat); - void ORCH_write_chemistry(std::ostream & chemistry_dat); - void ORCH_write_input(std::ostream & input_dat); - void ORCH_write_output_vars(std::ostream & input_dat); - private: - void ORCH_write_chemistry_water(std::ostream & chemistry_dat); - void ORCH_write_chemistry_primary(std::ostream & chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); - void ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat); - void ORCH_write_chemistry_minerals(std::ostream & chemistry_dat); -#endif + //void ConvertUnits(PHREEQC_PTR_ARG); protected: friend class cxxISolutionComp; // for this->pe access double density; std::string units; - //std::map < char *, cxxISolutionComp, CHARSTAR_LESS > comps; std::map < std::string, cxxISolutionComp > comps; struct pe_data *pes; int default_pe; diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 3d144ba1..44c28b5f 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -76,6 +76,8 @@ struct conc *cxxISolutionComp::concarray(std::map &totals) @@ -114,7 +116,9 @@ cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < s c[i].description = NULL; return (c); } +#endif +#ifdef SKIP_OR_MOVE_TO_STRUCTURES void cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) { @@ -158,6 +162,7 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) //P_INSTANCE_POINTER input_error++; return; } +#endif #ifdef SKIP diff --git a/ISolutionComp.h b/ISolutionComp.h index 217b4469..c1c7b067 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -117,15 +117,13 @@ class cxxISolutionComp: public PHRQ_base { this->gfw = l_gfw; } - void set_gfw(PHREEQC_PTR_ARG); + //void set_gfw(PHREEQC_PTR_ARG); bool operator<(const cxxISolutionComp & conc) const { return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0; } - static struct conc *cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < std::string, cxxISolutionComp > &t); - private: std::string description; double moles; diff --git a/KineticsComp.h b/KineticsComp.h index c34efc09..1c2ce704 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -17,8 +17,6 @@ public: cxxKineticsComp(struct kinetics_comp *, PHRQ_io *io=NULL); ~cxxKineticsComp(); - //static struct kinetics_comp *cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > &el); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 289edc08..90ceec91 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -49,11 +49,12 @@ eltList(pp_assemblage_ptr->next_elt) { cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i]), this->Get_io()); //ppAssemblageComps.push_back(ppComp); - std::string str(ppComp.get_name()); + std::string str(ppComp.Get_name()); this->ppAssemblageComps[str] = ppComp; } } -cxxPPassemblage::cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, + +cxxPPassemblage::cxxPPassemblage(const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): cxxNumKeyword(io) @@ -71,7 +72,7 @@ cxxNumKeyword(io) { const cxxPPassemblage *entity_ptr = &(entities.find(it->first)->second); - this->add(P_INSTANCE_COMMA *entity_ptr, it->second); + this->add(*entity_ptr, it->second); } } } @@ -80,6 +81,7 @@ cxxPPassemblage::~cxxPPassemblage() { } +#ifdef MOVE_TO_STRUCTURES struct pp_assemblage * cxxPPassemblage::cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG) // @@ -100,7 +102,7 @@ cxxPPassemblage::cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG) pp_assemblage_ptr->next_elt = this->eltList.elt_list(P_INSTANCE); return (pp_assemblage_ptr); } - +#endif void cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -271,16 +273,16 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->ppAssemblageComps.find(ec.get_name()) != this->ppAssemblageComps.end()) + if (this->ppAssemblageComps.find(ec.Get_name()) != this->ppAssemblageComps.end()) { - cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ec.get_name())->second; + cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ec.Get_name())->second; comp.read_raw(reread, false); } else { cxxPPassemblageComp ppComp1(this->Get_io()); ppComp1.read_raw(reread, false); - std::string str(ppComp1.get_name()); + std::string str(ppComp1.Get_name()); this->ppAssemblageComps[str] = ppComp1; } } @@ -348,13 +350,13 @@ cxxPPassemblage::totalize(PHREEQC_PTR_ARG) ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { (*it).second.totalize(P_INSTANCE); - this->totals.add_extensive((*it).second.get_totals(), 1.0); + this->totals.add_extensive((*it).second.Get_totals(), 1.0); } return; } void -cxxPPassemblage::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double extensive) +cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) // // Add to existing ppassemblage to "this" ppassemblage // @@ -370,7 +372,7 @@ cxxPPassemblage::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); ++it) { - if ((*it).second.get_name() == itadd->second.get_name()) + if ((*it).second.Get_name() == itadd->second.Get_name()) { (*it).second.add((*itadd).second, extensive); found = true; @@ -381,7 +383,7 @@ cxxPPassemblage::add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double { cxxPPassemblageComp entity = (*itadd).second; entity.multiply(extensive); - std::string str(entity.get_name()); + std::string str(entity.Get_name()); this->ppAssemblageComps[str] = entity; } } diff --git a/PPassemblage.h b/PPassemblage.h index 851224b3..bee4aaad 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -17,27 +17,23 @@ class cxxPPassemblage:public cxxNumKeyword public: cxxPPassemblage(PHRQ_io * io=NULL); cxxPPassemblage(struct pp_assemblage *, PHRQ_io * io=NULL); - cxxPPassemblage(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxPPassemblage > &entity_map, + cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io=NULL); - ~cxxPPassemblage(); - - struct pp_assemblage *cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG); - - struct pure_phase *cxxPPassemblageComp2pure_phase(); + ~cxxPPassemblage(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return this->totals; }; - const cxxNameDouble & get_eltList() const + const cxxNameDouble & Get_eltList() const { return this->eltList; }; - std::map & get_ppAssemblageComps() + const std::map & Get_ppAssemblageComps() const { return this->ppAssemblageComps; }; @@ -58,7 +54,7 @@ class cxxPPassemblage:public cxxNumKeyword #endif private: - void add(PHREEQC_PTR_ARG_COMMA const cxxPPassemblage & addee, double extensive); + void add(const cxxPPassemblage & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 064d32ae..74095a88 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -48,8 +48,8 @@ PHRQ_base(io) // constructor for cxxPPassemblageComp from struct pure_phase // { - this->set_name(pure_phase_ptr->name); - this->set_add_formula(pure_phase_ptr->add_formula); + this->Set_name(pure_phase_ptr->name); + this->Set_add_formula(pure_phase_ptr->add_formula); si = pure_phase_ptr->si; moles = pure_phase_ptr->moles; delta = pure_phase_ptr->delta; @@ -63,13 +63,7 @@ cxxPPassemblageComp::~cxxPPassemblageComp() { } -struct phase * -cxxPPassemblageComp::get_phase(PHREEQC_PTR_ARG) -{ - int i; - return P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &i, FALSE); -} - +#ifdef MOVE_TO_STRUCTURES struct pure_phase * cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxPPassemblageComp > &el) // @@ -106,7 +100,7 @@ cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::m } return (pure_phase_ptr); } - +#endif void cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { diff --git a/PPassemblageComp.h b/PPassemblageComp.h index b4428c77..529f9817 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -17,44 +17,45 @@ class cxxPPassemblageComp: public PHRQ_base cxxPPassemblageComp(struct pure_phase *, PHRQ_io *io=NULL); ~cxxPPassemblageComp(); - - static struct pure_phase *cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxPPassemblageComp > &el); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; - void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); - - const std::string &get_name() const + const std::string &Get_name() const { return this->name; } - void set_name(char * s) + void Set_name(char * s) { if(s != NULL) this->name = std::string(s); else this->name.clear(); } - const std::string &get_add_formula() const + const std::string &Get_add_formula() const { return this->add_formula; } - void set_add_formula(char * s) + void Set_add_formula(char * s) { if(s != NULL) this->add_formula = std::string(s); else this->add_formula.clear(); } - struct phase *get_phase(PHREEQC_PTR_ARG); void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return (this->totals); }; + double Get_si() const {return this->si;}; + double Get_moles() const {return this->moles;}; + double Get_delta() const {return this->delta;}; + double Get_initial_moles() const {return this->initial_moles;}; + bool Get_force_equality() const {return this->force_equality;}; + bool Get_dissolve_only() const {return this->dissolve_only;}; + bool Get_precipitate_only() const {return this->precipitate_only;}; + void add(const cxxPPassemblageComp & comp, double extensive); void multiply(double extensive); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 4d4738d1..6477a5ac 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -464,7 +464,7 @@ size_t Phreeqc::list_components(std::list &list_c) { reaction_calc(&irrev[i]); cxxReaction entity(&irrev[i]); - accumulator.add_extensive(entity.get_elementList(), 1.0); + accumulator.add_extensive(entity.Get_elementList(), 1.0); } // pure phases @@ -472,7 +472,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxPPassemblage entity(&pp_assemblage[i], &phrq_io); entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // exchangers diff --git a/Phreeqc.h b/Phreeqc.h index 57df863d..1a0ac2c9 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -43,6 +43,9 @@ class cxxExchange; class cxxExchComp; class cxxGasPhase; class cxxTemperature; +class cxxPPassemblage; +class cxxPPassemblageComp; +class cxxReaction; class Phreeqc { @@ -1250,6 +1253,10 @@ struct master * Get_exch_master(const cxxExchComp * ec); struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); +struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); +struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); +struct irrev * cxxReaction2irrev(const cxxReaction * rxn); + /* tally.c */ void add_all_components_tally(void); diff --git a/Reaction.cxx b/Reaction.cxx index daaa3c24..17453a47 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -28,7 +28,7 @@ cxxReaction::cxxReaction(PHRQ_io *io) // : cxxNumKeyword(io) { - this->set_units("Mol"); + this->Set_units("Mol"); countSteps = 0; equalIncrements = false; reactantList.type = cxxNameDouble::ND_NAME_COEF; @@ -48,7 +48,7 @@ elementList(irrev_ptr->elts) this->set_description(irrev_ptr->description); this->n_user = irrev_ptr->n_user; this->n_user_end = irrev_ptr->n_user_end; - this->set_units(irrev_ptr->units); + this->Set_units(irrev_ptr->units); // steps if (irrev_ptr->count_steps < 0) { @@ -74,7 +74,7 @@ cxxReaction::~cxxReaction() { } - +#ifdef MOVE_TO_STRUCTURES struct irrev * cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) // @@ -126,6 +126,7 @@ cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) irrev_ptr->units = P_INSTANCE_POINTER string_hsave(this->units.c_str()); return (irrev_ptr); } +#endif #ifdef SKIP void @@ -291,7 +292,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) j = parser.copy_token(token, next_char); if (j == CParser::TT_EMPTY) break; - this->set_units(token.c_str()); + this->Set_units(token.c_str()); opt_save = CParser::OPT_DEFAULT; useLastLine = false; units_defined = true; diff --git a/Reaction.h b/Reaction.h index 9ae96e0d..3786aa65 100644 --- a/Reaction.h +++ b/Reaction.h @@ -18,19 +18,19 @@ class cxxReaction:public cxxNumKeyword cxxReaction(struct irrev *, PHRQ_io *io = NULL); ~cxxReaction(); - struct irrev *cxxReaction2irrev(PHREEQC_PTR_ARG); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check); - cxxNameDouble &get_elementList(void) - { - return this->elementList; - } + const cxxNameDouble &Get_elementList(void) const {return this->elementList;}; + const cxxNameDouble &Get_reactantList(void) const {return this->reactantList;}; + const std::vector < double > &Get_steps(void) const {return this->steps;}; + int Get_countSteps(void) const {return this->countSteps;}; + bool Get_equalIncrements(void) const {return this->equalIncrements;}; + const std::string &Get_units(void) const {return this->units;}; - void set_units(const char * s) + void Set_units(const char * s) { if (s != NULL) this->units = std::string(s); diff --git a/ReadClass.cxx b/ReadClass.cxx index 7910b95c..3f948746 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -394,7 +394,8 @@ read_equilibrium_phases_raw(void) cxxPPassemblage ex(&phrq_io); ex.read_raw(parser); - struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); + //struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); + struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&ex); int n; /* @@ -778,7 +779,8 @@ read_reaction_raw(void) cxxReaction ex; ex.read_raw(parser, true); - struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); + //struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); + struct irrev *irrev_ptr = cxxReaction2irrev(&ex); int n; /* @@ -1426,7 +1428,8 @@ read_equilibrium_phases_modify(void) entity.read_raw(parser, false); // save entity - struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); + //struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); + struct pp_assemblage *entity_ptr = cxxPPassemblage2pp_assemblage(&entity); pp_assemblage_free(&(pp_assemblage[n])); pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); free_check_null(pp_assemblage[n].description); @@ -1982,7 +1985,8 @@ read_reaction_modify(void) cxxReaction entity(&(irrev[n])); entity.read_raw(parser, false); // save entity - struct irrev *entity_ptr = entity.cxxReaction2irrev(PHREEQC_THIS); + //struct irrev *entity_ptr = entity.cxxReaction2irrev(PHREEQC_THIS); + struct irrev *entity_ptr = cxxReaction2irrev(&entity); irrev_free(&(irrev[n])); irrev_copy(entity_ptr, &(irrev[n]), entity_ptr->n_user); free_check_null(irrev[n].description); diff --git a/StorageBin.cxx b/StorageBin.cxx index 9fcf0a8b..d25d43e2 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1065,8 +1065,9 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) this->PPassemblages.find(n); if (it != this->PPassemblages.end()) { - struct pp_assemblage *pp_assemblage_ptr = - (it->second).cxxPPassemblage2pp_assemblage(P_INSTANCE); + //struct pp_assemblage *pp_assemblage_ptr = + // (it->second).cxxPPassemblage2pp_assemblage(P_INSTANCE); + struct pp_assemblage *pp_assemblage_ptr = P_INSTANCE_POINTER cxxPPassemblage2pp_assemblage(&(it->second)); P_INSTANCE_POINTER pp_assemblage_copy(pp_assemblage_ptr, &P_INSTANCE_POINTER pp_assemblage[0], n); P_INSTANCE_POINTER count_pp_assemblage++; P_INSTANCE_POINTER pp_assemblage_free(pp_assemblage_ptr); @@ -1299,8 +1300,10 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // PPassemblages if (this->getPPassemblage(n) != NULL) { + //system_ptr->pp_assemblage = + // (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(P_INSTANCE); system_ptr->pp_assemblage = - (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(P_INSTANCE); + P_INSTANCE_POINTER cxxPPassemblage2pp_assemblage(this->getPPassemblage(n)); } else { diff --git a/System.cxx b/System.cxx index bf0f0a5d..37eaa577 100644 --- a/System.cxx +++ b/System.cxx @@ -79,7 +79,7 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) if (this->ppassemblage != NULL) { this->ppassemblage->totalize(P_INSTANCE); - this->totals.add_extensive(this->ppassemblage->get_totals(), 1.0); + this->totals.add_extensive(this->ppassemblage->Get_totals(), 1.0); } if (this->gasphase != NULL) { diff --git a/Temperature.h b/Temperature.h index ee06f9a3..28fddfa5 100644 --- a/Temperature.h +++ b/Temperature.h @@ -18,8 +18,6 @@ class cxxTemperature:public cxxNumKeyword cxxTemperature(struct temperature *, PHRQ_io *io=NULL); ~cxxTemperature(); - //struct temperature *cxxTemperature2temperature(PHREEQC_PTR_ARG); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; From 62a55134bec1aeb4daf3dacd80ac6837472d154d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 21:18:38 +0000 Subject: [PATCH 0255/1077] Worked through solution removing PHREEQC_PTR_ARG. More cleaning up to do. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5653 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 11 ++++++++--- ReadClass.cxx | 6 ++++-- Solution.cxx | 7 +++++-- Solution.h | 9 +++++++-- SolutionIsotopeList.cxx | 2 ++ StorageBin.cxx | 6 ++++-- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 1a0ac2c9..f598c1e6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -46,6 +46,8 @@ class cxxTemperature; class cxxPPassemblage; class cxxPPassemblageComp; class cxxReaction; +class cxxSolution; +class cxxSolutionIsotopeList; class Phreeqc { @@ -1244,9 +1246,7 @@ extern void MergeFinalize(void); struct mix * cxxMix2mix(cxxMix *mx); struct kinetics *cxxKinetics2kinetics(cxxKinetics * kin); -struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct kinetics_comp * cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > * el); -struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct exchange * cxxExchange2exchange(cxxExchange * ex); struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); struct master * Get_exch_master(const cxxExchComp * ec); @@ -1256,7 +1256,12 @@ struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); struct irrev * cxxReaction2irrev(const cxxReaction * rxn); - +struct solution * cxxSolution2solution(const cxxSolution * sol); +struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); +struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); +struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); +struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); +struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); /* tally.c */ void add_all_components_tally(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 3f948746..47bb1569 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -112,7 +112,8 @@ read_solution_raw(void) cxxSolution sol(&phrq_io); sol.read_raw(parser); - struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); + //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); + struct solution *soln_ptr = cxxSolution2solution(&sol); int n; /* @@ -1337,7 +1338,8 @@ read_solution_modify(void) sol.modify_activities(PHREEQC_THIS_COMMA orig); - struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); + //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); + struct solution *soln_ptr = cxxSolution2solution(&sol); /* * This is not quite right, may not produce sort order, forced sort diff --git a/Solution.cxx b/Solution.cxx index f5fb4a5a..eb4c4361 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -137,7 +137,7 @@ isotopes(io) } } } - +#ifdef SKIP_OR_MOVE_TO_STRUCTURES cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io * io) // // constructor for cxxSolution from results of calculation @@ -278,10 +278,12 @@ isotopes(io) } } } - +#endif cxxSolution::~cxxSolution() { } + +#ifdef MOVE_TO_STRUCTURES struct solution * cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) // @@ -336,6 +338,7 @@ cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) return (solution_ptr); } +#endif void cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const diff --git a/Solution.h b/Solution.h index dfcdbefb..493c9c47 100644 --- a/Solution.h +++ b/Solution.h @@ -19,7 +19,7 @@ class cxxSolution:public cxxNumKeyword public: cxxSolution(PHRQ_io *io=NULL); cxxSolution(struct solution *, PHRQ_io *io=NULL); - cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); + //cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); cxxSolution( const std::map < int, cxxSolution > &solution_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSolution(); @@ -142,8 +142,13 @@ class cxxSolution:public cxxNumKeyword { return this->master_activity; } + const cxxNameDouble & get_species_gamma(void) const + { + return this->species_gamma; + } double get_master_activity(char *string) const; void set_master_activity(char *string, double value); + const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; /* double get_species_gamma(char *string)const; @@ -153,7 +158,7 @@ class cxxSolution:public cxxNumKeyword void set_isotope(char *string, double value); */ - struct solution *cxxSolution2solution(PHREEQC_PTR_ARG); + //struct solution *cxxSolution2solution(PHREEQC_PTR_ARG); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 33f832f9..31a8f72a 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -88,6 +88,7 @@ cxxSolutionIsotopeList::multiply(double extensive) it->total *= extensive; } } +#ifdef MOVE_TO_STRUCTURES struct isotope * cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG) { @@ -119,3 +120,4 @@ cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG) } return (iso); } +#endif diff --git a/StorageBin.cxx b/StorageBin.cxx index d25d43e2..0b0ac6bb 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1001,7 +1001,8 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) std::map < int, cxxSolution >::iterator it = this->Solutions.find(n); if (it != this->Solutions.end()) { - P_INSTANCE_POINTER solution[0] = (it->second).cxxSolution2solution(P_INSTANCE); + //P_INSTANCE_POINTER solution[0] = (it->second).cxxSolution2solution(P_INSTANCE); + P_INSTANCE_POINTER solution[0] = P_INSTANCE_POINTER cxxSolution2solution(&(it->second)); P_INSTANCE_POINTER solution[0]->n_user = n; P_INSTANCE_POINTER solution[0]->n_user_end = n; P_INSTANCE_POINTER count_solution++; @@ -1256,7 +1257,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) if (this->getSolution(n) != NULL) { - system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(P_INSTANCE); + //system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(P_INSTANCE); + system_ptr->solution = P_INSTANCE_POINTER cxxSolution2solution(this->getSolution(n)); } else { From e42590e5816845816683a3d843428b7f11ca7a6c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 21:31:39 +0000 Subject: [PATCH 0256/1077] Cleaned up NameDouble, still need to remove elt_list. Commented out some unused PHREEQC_PTR_ARGS in headers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5654 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 2 ++ NameDouble.h | 7 +++---- SolutionIsotope.cxx | 9 ++++++--- SolutionIsotope.h | 6 +++--- SolutionIsotopeList.h | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index a83bd01b..ae4bde02 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -182,6 +182,7 @@ cxxNameDouble::elt_list(PHREEQC_PTR_ARG) return (elt_list_ptr); } +#ifdef MOVE_TO_STRUCTURES struct master_activity * cxxNameDouble::master_activity(PHREEQC_PTR_ARG) const // @@ -294,6 +295,7 @@ cxxNameDouble::name_coef(PHREEQC_PTR_ARG) const } return (name_coef_ptr); } +#endif void cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const diff --git a/NameDouble.h b/NameDouble.h index 213b205d..16c46001 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -36,12 +36,11 @@ class cxxNameDouble:public struct elt_list * elt_list(PHREEQC_PTR_ARG); - struct master_activity * - master_activity(PHREEQC_PTR_ARG) const; + //struct master_activity * master_activity(PHREEQC_PTR_ARG) const; - struct conc * conc(PHREEQC_PTR_ARG) const; + //struct conc * conc(PHREEQC_PTR_ARG) const; - struct name_coef * name_coef(PHREEQC_PTR_ARG) const; + //struct name_coef * name_coef(PHREEQC_PTR_ARG) const; void dump_xml(std::ostream & s_oss, unsigned int indent) const; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 6dcbc3ac..1583629f 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -48,6 +48,7 @@ cxxSolutionIsotope::~cxxSolutionIsotope(void) { } +#ifdef SKIP_OR_MOVE_TO_STRUCTURES struct isotope * cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &isolist) // takes a std::list of cxxSolutionIsotope structures @@ -81,6 +82,7 @@ cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIs } return (iso); } +#endif #ifdef SKIP std::string cxxSolutionIsotope::get_name() constconst @@ -224,20 +226,21 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const return (i < 0); return (this->isotope_number < isotope.isotope_number); } - +#ifdef SKIP_OR_MOVE_TO_STRUCTURES struct master * cxxSolutionIsotope::master(PHREEQC_PTR_ARG) { return (P_INSTANCE_POINTER master_bsearch(this->elt_name.c_str())); } - +#endif +#ifdef SKIP_OR_MOVE_TO_STRUCTURES struct master * cxxSolutionIsotope::primary(PHREEQC_PTR_ARG) { char * str = P_INSTANCE_POINTER string_hsave(this->elt_name.c_str()); return (P_INSTANCE_POINTER master_bsearch_primary(str)); } - +#endif void cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr, double intensive, double extensive) diff --git a/SolutionIsotope.h b/SolutionIsotope.h index f63b97b0..8e2edaa1 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -21,7 +21,7 @@ class cxxSolutionIsotope: public PHRQ_base }; */ //cxxSolutionIsotope::STATUS read(CParser& parser); - static struct isotope *list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &t); + //static struct isotope *list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &t); void dump_xml(std::ostream & os, unsigned int indent) const; void dump_raw(std::ostream & os, unsigned int indent) const; @@ -84,8 +84,8 @@ class cxxSolutionIsotope: public PHRQ_base bool operator<(const cxxSolutionIsotope & conc) const; - struct master *master(PHREEQC_PTR_ARG); - struct master *primary(PHREEQC_PTR_ARG); + //struct master *master(PHREEQC_PTR_ARG); + //struct master *primary(PHREEQC_PTR_ARG); void add(const cxxSolutionIsotope & isotope_ptr, double intensive, double extensive); diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index d36db041..06bdb60a 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -19,7 +19,7 @@ public: ~cxxSolutionIsotopeList(); - struct isotope * cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG); + //struct isotope * cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG); void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); void multiply(double extensive); From 9561576af79f058ce0812bc9613b0de8d5d2f912 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Sep 2011 23:36:52 +0000 Subject: [PATCH 0257/1077] Finished SSassemblage.cxx Cleaned up other files some. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5655 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.h | 1 + ChartObject.cpp | 4 +- ISolutionComp.h | 1 - Parser.h | 1 - Phreeqc.cpp | 2 +- Phreeqc.h | 4 + ReadClass.cxx | 6 +- SSassemblage.cxx | 14 +-- SSassemblage.h | 7 +- SSassemblageSS.cxx | 4 +- SSassemblageSS.h | 22 ++-- Solution.cxx | 245 ++---------------------------------------- Solution.h | 66 +++++------- SolutionIsotope.cxx | 8 +- SolutionIsotope.h | 23 ++-- SolutionIsotopeList.h | 1 - StorageBin.cxx | 9 +- System.cxx | 8 +- Temperature.h | 1 - cxxMix.h | 1 - 20 files changed, 104 insertions(+), 324 deletions(-) diff --git a/ChartHandler.h b/ChartHandler.h index 9cd10d21..53bfc4d2 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -7,6 +7,7 @@ #include "Parser.h" #include "ChartObject.h" #include "PHRQ_base.h" +#include "phreeqc_class.h" class ChartHandler: public PHRQ_base { diff --git a/ChartObject.cpp b/ChartObject.cpp index b0bedbc9..10500eef 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -12,8 +12,10 @@ #include #include #include -#ifdef PHREEQC_CLASS +#ifdef PHREEQC_CPP #include "Phreeqc_class.h" +#endif +#ifdef PHREEQC_CLASS #include "Phreeqc.h" #else #include "phqalloc.h" diff --git a/ISolutionComp.h b/ISolutionComp.h index c1c7b067..9d088d25 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -5,7 +5,6 @@ #include // std::map #include #include -#include "Phreeqc_class.h" #include "PHRQ_base.h" // forward declarations class cxxISolution; // reqd for read and dump_xml diff --git a/Parser.h b/Parser.h index 0dc5ee11..d45fab17 100644 --- a/Parser.h +++ b/Parser.h @@ -7,7 +7,6 @@ #include // std::istringstream std::ostringstream #include // std::ostream #include // std::istream -#include "Phreeqc_class.h" #include "PHRQ_base.h" class CParser: public PHRQ_base diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6477a5ac..5eca63e1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -456,7 +456,7 @@ size_t Phreeqc::list_components(std::list &list_c) for (i = 0; i < count_solution; i++) { cxxSolution entity(solution[i], &phrq_io); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // irreversible reactions diff --git a/Phreeqc.h b/Phreeqc.h index f598c1e6..0a4d6929 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -48,6 +48,8 @@ class cxxPPassemblageComp; class cxxReaction; class cxxSolution; class cxxSolutionIsotopeList; +class cxxSSassemblage; +class cxxSSassemblageSS; class Phreeqc { @@ -1258,6 +1260,8 @@ struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); +struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); +struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); diff --git a/ReadClass.cxx b/ReadClass.cxx index 47bb1569..8e331459 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -588,7 +588,8 @@ read_solid_solutions_raw(void) cxxSSassemblage ex; ex.read_raw(parser); - struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + //struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + struct s_s_assemblage *s_s_assemblage_ptr = cxxSSassemblage2s_s_assemblage(&ex); int n; /* @@ -1722,7 +1723,8 @@ read_solid_solutions_modify(void) entity.read_raw(parser, false); // save entity - struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + //struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + struct s_s_assemblage *entity_ptr = cxxSSassemblage2s_s_assemblage(&entity); s_s_assemblage_free(&(s_s_assemblage[n])); s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); free_check_null(s_s_assemblage[n].description); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 65fb24ef..c49aa641 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -47,7 +47,7 @@ cxxNumKeyword(io) for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i]), this->Get_io()); - std::string str(ssSS.get_name()); + std::string str(ssSS.Get_name()); ssAssemblageSSs[str] = ssSS; } } @@ -78,6 +78,7 @@ cxxSSassemblage::~cxxSSassemblage() { } +#ifdef MOVE_TO_STRUCTURES struct s_s_assemblage * cxxSSassemblage::cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG) // @@ -95,6 +96,7 @@ cxxSSassemblage::cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG) cxxSSassemblageSS::cxxSSassemblageSS2s_s(P_INSTANCE_COMMA this->ssAssemblageSSs); return (s_s_assemblage_ptr); } +#endif #ifdef SKIP void @@ -246,16 +248,16 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) + if (this->ssAssemblageSSs.find(ec.Get_name()) != this->ssAssemblageSSs.end()) { - cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; + cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.Get_name())->second; ec1.read_raw(reread, false); } else { cxxSSassemblageSS ec1(this->Get_io()); ec1.read_raw(reread, false); - std::string str(ec1.get_name()); + std::string str(ec1.Get_name()); this->ssAssemblageSSs[str] = ec1; } } @@ -320,7 +322,7 @@ cxxSSassemblage::totalize(PHREEQC_PTR_ARG) ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { (*it).second.totalize(P_INSTANCE); - this->totals.add_extensive((*it).second.get_totals(), 1.0); + this->totals.add_extensive((*it).second.Get_totals(), 1.0); } return; } @@ -382,7 +384,7 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) { cxxSSassemblageSS entity = (*itadd).second; entity.multiply(extensive); - std::string str(entity.get_name()); + std::string str(entity.Get_name()); this->ssAssemblageSSs[str] = entity; } } diff --git a/SSassemblage.h b/SSassemblage.h index b891ffb5..5cbe2563 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -8,7 +8,6 @@ #include // std::list #include // std::vector -#include "Phreeqc_class.h" #include "NumKeyword.h" #include "NameDouble.h" class cxxSSassemblageSS; @@ -26,16 +25,16 @@ public: cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); - struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG); + //struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG); - struct s_s *cxxSSassemblageComp2s_s(); + //struct s_s *cxxSSassemblageComp2s_s(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - std::map & get_ssAssemblageSSs() + const std::map & get_ssAssemblageSSs() const { return this->ssAssemblageSSs; }; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index ba9eac1c..aa3327dc 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -52,7 +52,7 @@ PHRQ_base(io) // // constructor for cxxSSassemblageSS from struct s_s // { - this->set_name(s_s_ptr->name); + this->Set_name(s_s_ptr->name); //total_moles = s_s_ptr->total_moles; a0 = s_s_ptr->a0; a1 = s_s_ptr->a1; @@ -80,6 +80,7 @@ cxxSSassemblageSS::~cxxSSassemblageSS() { } +#ifdef MOVE_TO_STRUCTURES struct s_s * cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > &el) // @@ -170,6 +171,7 @@ cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::s } return (s_s_ptr); } +#endif #ifdef SKIP void diff --git a/SSassemblageSS.h b/SSassemblageSS.h index e0c1e1a0..e0213c07 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -6,9 +6,7 @@ #include // std::string #include // std::list #include // std::vector - #include "NameDouble.h" -#include "Phreeqc_class.h" class cxxSSassemblageSS: public PHRQ_base { @@ -33,8 +31,8 @@ class cxxSSassemblageSS: public PHRQ_base SS_PARM_MARGULES = 9 }; - static struct s_s *cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > - &el); + //static struct s_s *cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > + // &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -42,11 +40,11 @@ class cxxSSassemblageSS: public PHRQ_base void read_raw(CParser & parser, bool check = true); - const std::string &get_name() const + const std::string &Get_name() const { return this->name; } - void set_name (const char * s) + void Set_name (const char * s) { if (s != NULL) this->name = std::string(s); @@ -55,11 +53,11 @@ class cxxSSassemblageSS: public PHRQ_base } void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return (this->totals); }; - const cxxNameDouble & get_comps() const + const cxxNameDouble & Get_comps() const { return (this->comps); }; @@ -71,7 +69,13 @@ class cxxSSassemblageSS: public PHRQ_base void add(const cxxSSassemblageSS & comp, double extensive); void multiply(double extensive); - + double Get_a0() const {return (this->a0);}; + double Get_a1() const {return (this->a1);}; + double Get_ag0() const {return (this->ag0);}; + double Get_ag1() const {return (this->ag1);}; + bool Get_miscibility() const {return (this->miscibility);}; + double Get_xb1() const {return (this->xb1);}; + double Get_xb2() const {return (this->xb2);}; protected: std::string name; cxxNameDouble comps; diff --git a/Solution.cxx b/Solution.cxx index eb4c4361..55e972c9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -701,7 +701,7 @@ cxxSolution::read_raw(CParser & parser, bool check) } else { - if (iso.get_isotope_name().size() != 0) + if (iso.Get_isotope_name().size() != 0) { this->isotopes.push_back(iso); } @@ -977,7 +977,7 @@ cxxSolution::multiply(double extensive) } double -cxxSolution::get_total(char *string) const +cxxSolution::Get_total(char *string) const { cxxNameDouble::const_iterator it = this->totals.find(string); if (it == this->totals.end()) @@ -990,7 +990,7 @@ cxxSolution::get_total(char *string) const } } double -cxxSolution::get_total_element(char *string) const +cxxSolution::Get_total_element(char *string) const { cxxNameDouble::const_iterator it; double d = 0.0; @@ -1014,13 +1014,13 @@ cxxSolution::get_total_element(char *string) const } void -cxxSolution::set_total(char *string, double d) +cxxSolution::Set_total(char *string, double d) { this->totals[string] = d; } double -cxxSolution::get_master_activity(char *string) const +cxxSolution::Get_master_activity(char *string) const { cxxNameDouble::const_iterator it = this->master_activity.find(string); if (it == this->master_activity.end()) @@ -1033,233 +1033,6 @@ cxxSolution::get_master_activity(char *string) const } } -#ifdef ORCHESTRA -void -cxxSolution::ORCH_write(std::ostream & headings, std::ostream & data) const const -{ - - data.precision(DBL_DIG - 1); - - // Solution element and attributes - - //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; - - //s_oss << "-temp " << this->tc << std::endl; - - //s_oss << "-pH " << this->ph << std::endl; - headings << "pH\t"; - data << this->ph << "\t"; - - //s_oss << "-pe " << this->pe << std::endl; - headings << "pe\t"; - data << this->pe << "\t"; - - //s_oss << "-mu " << this->mu << std::endl; - - //s_oss << "-ah2o " << this->ah2o << std::endl; - headings << "H2O.act\t"; - data << 1 << "\t"; - //s_oss << "-total_h " << this->total_h << std::endl; - - //s_oss << "-total_o " << this->total_o << std::endl; - - //s_oss << "-cb " << this->cb << std::endl; - - //s_oss << "-mass_water " << this->mass_water << std::endl; - - //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - - // soln_total conc structures - //this->totals.dump_raw(s_oss, indent + 2); - //this->totals.write_orchestra(headings, s_oss); - for (std::map < char *, double, CHARSTAR_LESS >::const_iterator it = - totals.begin(); it != totals.end(); ++it) - { - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch(it->first); - if (master_ptr != NULL) - { - //headings << it->first << ".tot" << "\t"; - headings << master_ptr->s->name << ".diss" << "\t"; - data << it->second << "\t"; - } - else - { - assert(false); - } - } - - // master_activity map - //this->master_activity.dump_raw(s_oss, indent + 2); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - */ - // species_gamma map - //this->species_gamma.dump_raw(s_oss, indent + 2); - /* - { - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - } - } - */ - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - return; -} - -void -cxxSolution::ORCH_read(std::vector < std::pair < std::string, - double >>output_vector, - std::vector < std::pair < std::string, - double >>::iterator & it) -{ - this->tc = it->second; - it++; - this->ph = it->second; - it++; - this->pe = it->second; - it++; - this->mu = it->second; - it++; - this->ah2o = it->second; - it++; - this->total_h = it->second; - it++; - this->total_o = it->second; - it++; - this->cb = it->second; - it++; - this->mass_water = it->second * gfw_water; - it++; - this->mass_water = 1.0; - this->total_alkalinity = it->second; - it++; - it++; //orch total H+ - it++; //orch total e- - it++; //orch total H2O - //cxxNameDouble totals; - char token[MAX_LENGTH]; - while (it->first.compare("end_totals") != 0) - { - strcpy(token, it->first.c_str()); - replace(".diss", "", token); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) - error_msg("Species not found in orchestra read", STOP); - if (s_ptr->secondary != NULL) - { - this->totals[s_ptr->secondary->elt->name] = it->second; - } - else if (s_ptr->primary != NULL) - { - this->totals[s_ptr->primary->elt->name] = it->second; - } - else - { - error_msg - ("Species not secondary or primary master species in orchestra read", - STOP); - } - it++; - } - //cxxNameDouble master_activity; - it++; - while (it->first.compare("end_master_activities") != 0) - { - strcpy(token, it->first.c_str()); - replace(".act", "", token); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) - error_msg("Species not found in orchestra read", STOP); - if (s_ptr->secondary != NULL) - { - this->master_activity[s_ptr->secondary->elt->name] = - log10(it->second); - } - else if (s_ptr->primary != NULL) - { - this->master_activity[s_ptr->primary->elt->name] = - log10(it->second); - } - else - { - error_msg - ("Species not secondary or primary master species in orchestra read", - STOP); - } - it++; - } - //cxxNameDouble species_gamma; - //cxxSolutionIsotopeList isotopes; - // - // Also process aqueous species data - // - it++; - while (it->first.compare("end_species") != 0) - { - strcpy(token, it->first.c_str()); - replace(".act", "", token); - while (replace("[", "(", token)); - while (replace("]", ")", token)); - struct species *s_ptr = s_search(token); - if (s_ptr == NULL) - error_msg("Species not found in orchestra read", STOP); - s_ptr->la = log10(it->second); - it++; - s_ptr->moles = it->second * this->mass_water; - s_ptr->lm = log10(it->second); - it++; - s_ptr->lg = s_ptr->la - s_ptr->lm; - } -} - -void -cxxSolution::ORCH_store_global(std::map < std::string, double >output_map) -{ - int i; - tc_x = this->tc; - mass_water_aq_x = this->mass_water; - mu_x = this->mu; - s_h2o->moles = output_map["H2O.con"]; - s_h2o->la = log10(output_map["H2O.act"]); - s_h2o->lm = s_h2o->la; - s_h2o->lg = 0; - for (i = 0; i < count_unknowns; i++) - { - residual[i] = 0; - // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O - switch (x[i]->type) - { - case MB: - case CB: - case SOLUTION_PHASE_BOUNDARY: - x[i]->sum = this->totals[x[i]->description] * mass_water_aq_x; - break; - case ALK: - x[i]->f = this->total_alkalinity * mass_water_aq_x; - break; - } - } -} -#endif #ifdef USE_MPI /* ---------------------------------------------------------------------- */ void @@ -1538,7 +1311,7 @@ cxxSolution::mpi_recv(int task_number) } #endif void -cxxSolution::set_master_activity(char *string, double d) +cxxSolution::Set_master_activity(char *string, double d) { this->master_activity[string] = d; } @@ -1552,7 +1325,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina // to standardize, convert element to valence state if needed // for original activity list (probably not needed) - cxxNameDouble orig_master_activity(original.get_master_activity()); + cxxNameDouble orig_master_activity(original.Get_master_activity()); cxxNameDouble::const_iterator it; bool redo=true; while (redo) @@ -1638,10 +1411,10 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina if (strcmp(ename, "H") == 0 || strcmp(ename, "O") == 0) continue; double d_mod, d_orig; - d_mod = this->get_total_element(ename); + d_mod = this->Get_total_element(ename); if (d_mod <= 0) continue; - d_orig = original.get_total_element(ename); + d_orig = original.Get_total_element(ename); if (d_orig <= 0) { // add estimate for la based on concentration if not in list diff --git a/Solution.h b/Solution.h index 493c9c47..5ec3f7c4 100644 --- a/Solution.h +++ b/Solution.h @@ -26,105 +26,105 @@ class cxxSolution:public cxxNumKeyword //static cxxSolution& read(CParser& parser); - double get_tc() const + double Get_tc() const { return this->tc; } - void set_tc(double l_tc) + void Set_tc(double l_tc) { this->tc = l_tc; } - double get_ph() const + double Get_ph() const { return this->ph; } - void set_ph(double pH) + void Set_ph(double pH) { this->ph = pH; } - double get_pe() const + double Get_pe() const { return this->pe; } - void set_pe(double l_pe) + void Set_pe(double l_pe) { this->pe = l_pe; } - double get_mu() const + double Get_mu() const { return this->mu; } - void set_mu(double l_mu) + void Set_mu(double l_mu) { this->mu = l_mu; } - double get_ah2o() const + double Get_ah2o() const { return this->ah2o; } - void set_ah2o(double l_ah2o) + void Set_ah2o(double l_ah2o) { this->ah2o = l_ah2o; } - double get_total_h() const + double Get_total_h() const { return this->total_h; } - void set_total_h(double l_total_h) + void Set_total_h(double l_total_h) { this->total_h = l_total_h; } - double get_total_o() const + double Get_total_o() const { return this->total_o; } - void set_total_o(double l_total_o) + void Set_total_o(double l_total_o) { this->total_o = l_total_o; } - double get_cb() const + double Get_cb() const { return this->cb; } - void set_cb(double l_cb) + void Set_cb(double l_cb) { this->cb = l_cb; } - double get_mass_water() const + double Get_mass_water() const { return this->mass_water; } - void set_mass_water(long double l_mass_water) + void Set_mass_water(long double l_mass_water) { this->mass_water = l_mass_water; } - double get_total_alkalinity() const + double Get_total_alkalinity() const { return this->total_alkalinity; } - void set_total_alkalinity(double l_total_alkalinity) + void Set_total_alkalinity(double l_total_alkalinity) { this->total_alkalinity = l_total_alkalinity; } - double get_total(char *string) const; - double get_total_element(char *string) const; - void set_total(char *string, double value); + double Get_total(char *string) const; + double Get_total_element(char *string) const; + void Set_total(char *string, double value); - const cxxNameDouble & get_totals(void) const + const cxxNameDouble & Get_totals(void) const { return this->totals; } - void set_totals(cxxNameDouble & nd) + void Set_totals(cxxNameDouble & nd) { this->totals = nd; this->totals.type = cxxNameDouble::ND_ELT_MOLES; @@ -138,26 +138,18 @@ class cxxSolution:public cxxNumKeyword this->master_activity.clear(); } - const cxxNameDouble & get_master_activity(void) const + const cxxNameDouble & Get_master_activity(void) const { return this->master_activity; } - const cxxNameDouble & get_species_gamma(void) const + const cxxNameDouble & Get_species_gamma(void) const { return this->species_gamma; } - double get_master_activity(char *string) const; - void set_master_activity(char *string, double value); + double Get_master_activity(char *string) const; + void Set_master_activity(char *string, double value); const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; - /* - double get_species_gamma(char *string)const; - void set_species_gamma(char *string, double value); - - double get_isotope(char *string)const; - void set_isotope(char *string, double value); - */ - //struct solution *cxxSolution2solution(PHREEQC_PTR_ARG); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 1583629f..6e8290ae 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -34,10 +34,10 @@ cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io) PHRQ_base(io) { isotope_number = isotope_ptr->isotope_number; - this->set_elt_name(isotope_ptr->elt_name); + this->Set_elt_name(isotope_ptr->elt_name); std::ostringstream name; name << isotope_ptr->isotope_number << isotope_ptr->elt_name; - this->set_isotope_name(name.str().c_str()); + this->Set_isotope_name(name.str().c_str()); total = isotope_ptr->total; ratio = isotope_ptr->ratio; ratio_uncertainty = isotope_ptr->ratio_uncertainty; @@ -169,7 +169,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream this->isotope_name.clear(); return (CParser::PARSER_OK); } - this->set_isotope_name(token.c_str()); + this->Set_isotope_name(token.c_str()); // isotope_number if (!(parser.get_iss() >> isotope_number)) @@ -182,7 +182,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream { return CParser::PARSER_ERROR; } - this->set_elt_name(token.c_str()); + this->Set_elt_name(token.c_str()); // total if (!(parser.get_iss() >> this->total)) diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 8e2edaa1..1aa1a063 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -5,7 +5,6 @@ #include // std::string #include // std::list #include "Parser.h" -#include "Phreeqc_class.h" class cxxSolutionIsotope: public PHRQ_base { @@ -28,56 +27,56 @@ class cxxSolutionIsotope: public PHRQ_base CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type next_char); - double get_isotope_number() const + double Get_isotope_number() const { return this->isotope_number; } - void set_isotope_number(double d) + void Set_isotope_number(double d) { this->isotope_number = d; } - const std::string &get_elt_name() const + const std::string &Get_elt_name() const { return this->elt_name; } - void set_elt_name(const char *cstring) + void Set_elt_name(const char *cstring) { if (cstring != NULL) this->elt_name = std::string(cstring); else this->elt_name.clear(); } - const std::string &get_isotope_name() const + const std::string &Get_isotope_name() const { return this->isotope_name; } - void set_isotope_name(const char *cstring) + void Set_isotope_name(const char *cstring) { if (cstring != NULL) this->isotope_name = std::string(cstring); else this->isotope_name.clear(); } - double get_total() const + double Get_total() const { return this->total; } - void set_total(double d) + void Set_total(double d) { this->total = d; } - double get_ratio() const + double Get_ratio() const { return this->ratio; } - double get_ratio_uncertainty() const + double Get_ratio_uncertainty() const { return this->ratio_uncertainty; } - bool get_ratio_uncertainty_defined() const + bool Get_ratio_uncertainty_defined() const { return this->ratio_uncertainty_defined; } diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 06bdb60a..b0ede907 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -6,7 +6,6 @@ #include // std::list #include "SolutionIsotope.h" -#include "Phreeqc_class.h" class cxxSolutionIsotopeList:public std::list < cxxSolutionIsotope >, public PHRQ_base diff --git a/StorageBin.cxx b/StorageBin.cxx index 0b0ac6bb..4a6304c4 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1083,8 +1083,11 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) this->SSassemblages.find(n); if (it != this->SSassemblages.end()) { + //struct s_s_assemblage *s_s_assemblage_ptr = + // (it->second).cxxSSassemblage2s_s_assemblage(P_INSTANCE); struct s_s_assemblage *s_s_assemblage_ptr = - (it->second).cxxSSassemblage2s_s_assemblage(P_INSTANCE); + P_INSTANCE_POINTER cxxSSassemblage2s_s_assemblage(&(it->second)); + P_INSTANCE_POINTER s_s_assemblage_copy(s_s_assemblage_ptr, &P_INSTANCE_POINTER s_s_assemblage[0], n); P_INSTANCE_POINTER count_s_s_assemblage++; P_INSTANCE_POINTER s_s_assemblage_free(s_s_assemblage_ptr); @@ -1315,8 +1318,10 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // SSassemblages if (this->getSSassemblage(n) != NULL) { + //system_ptr->s_s_assemblage = + // (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(P_INSTANCE); system_ptr->s_s_assemblage = - (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(P_INSTANCE); + P_INSTANCE_POINTER cxxSSassemblage2s_s_assemblage((this->getSSassemblage(n))); } else { diff --git a/System.cxx b/System.cxx index 37eaa577..abc49fde 100644 --- a/System.cxx +++ b/System.cxx @@ -64,12 +64,12 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) { char token[MAX_LENGTH]; strcpy(token, "O"); - this->totals[token] = this->solution->get_total_o(); + this->totals[token] = this->solution->Get_total_o(); strcpy(token, "H"); - this->totals[token] = this->solution->get_total_h(); + this->totals[token] = this->solution->Get_total_h(); strcpy(token, "Charge"); - this->totals[token] = this->solution->get_cb(); - this->totals.add_extensive(this->solution->get_totals(), 1.0); + this->totals[token] = this->solution->Get_cb(); + this->totals.add_extensive(this->solution->Get_totals(), 1.0); } if (this->exchange != NULL) { diff --git a/Temperature.h b/Temperature.h index 28fddfa5..f7c2416f 100644 --- a/Temperature.h +++ b/Temperature.h @@ -8,7 +8,6 @@ #include // std::vector #include "NumKeyword.h" -#include "Phreeqc_class.h" class cxxTemperature:public cxxNumKeyword { diff --git a/cxxMix.h b/cxxMix.h index df7aba9d..ee6a3d01 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -6,7 +6,6 @@ #include // std::string #include // std::list #include // std::vector -#include "Phreeqc_class.h" #include "NumKeyword.h" #include "PHRQ_base.h" From 9efcd6ecb830268d50c847daf70462c5983bdf63 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 28 Sep 2011 17:05:01 +0000 Subject: [PATCH 0258/1077] Finished all but loose ends with P_INSTANCEs. Did Surface, charge and comp. Now can clean up some more. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5656 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 1 - Phreeqc.cpp | 2 +- Phreeqc.h | 8 ++++++++ ReadClass.cxx | 6 ++++-- StorageBin.cxx | 6 ++++-- Surface.cxx | 41 ++++++++++++++++++++++------------------- Surface.h | 29 ++++++++++++++++++++--------- SurfaceCharge.cxx | 4 +++- SurfaceCharge.h | 22 +++++++++++++--------- SurfaceComp.cxx | 36 +++++++++++++++++++++++------------- SurfaceComp.h | 32 +++++++++++++++++++------------- System.cxx | 2 +- 12 files changed, 118 insertions(+), 71 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 10500eef..933fa32f 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -18,7 +18,6 @@ #ifdef PHREEQC_CLASS #include "Phreeqc.h" #else -#include "phqalloc.h" extern int error_msg(const char *err_str, const int stop, ...); extern int warning_msg(const char *err_str, ...); extern int rate_free(struct rate *rate_ptr); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 5eca63e1..d8f8b028 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -488,7 +488,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxSurface entity(&surface[i], &phrq_io); entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // gas phases diff --git a/Phreeqc.h b/Phreeqc.h index 0a4d6929..c77941a9 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -50,6 +50,9 @@ class cxxSolution; class cxxSolutionIsotopeList; class cxxSSassemblage; class cxxSSassemblageSS; +class cxxSurface; +class cxxSurfaceCharge; +class cxxSurfaceComp; class Phreeqc { @@ -1262,10 +1265,15 @@ struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); +struct surface * cxxSurface2surface(cxxSurface * surf); +struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); +struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); + struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); +struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); /* tally.c */ void add_all_components_tally(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 8e331459..76ff5252 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -300,7 +300,8 @@ read_surface_raw(void) cxxSurface ex(&phrq_io); ex.read_raw(parser); - struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); + //struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); + struct surface *surface_ptr = cxxSurface2surface(&ex); int n; /* @@ -1634,7 +1635,8 @@ read_surface_modify(void) entity.read_raw(parser, false); // save entity - struct surface *entity_ptr = entity.cxxSurface2surface(PHREEQC_THIS); + //struct surface *entity_ptr = entity.cxxSurface2surface(PHREEQC_THIS); + struct surface *entity_ptr = cxxSurface2surface(&entity); surface_free(&(surface[n])); surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); free_check_null(surface[n].description); diff --git a/StorageBin.cxx b/StorageBin.cxx index 4a6304c4..8f02947e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1101,7 +1101,8 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) std::map < int, cxxSurface >::iterator it = this->Surfaces.find(n); if (it != this->Surfaces.end()) { - struct surface *surface_ptr = (it->second).cxxSurface2surface(P_INSTANCE); + //struct surface *surface_ptr = (it->second).cxxSurface2surface(P_INSTANCE); + struct surface *surface_ptr = P_INSTANCE_POINTER cxxSurface2surface(&(it->second)); P_INSTANCE_POINTER surface_copy(surface_ptr, &P_INSTANCE_POINTER surface[0], n); P_INSTANCE_POINTER count_surface++; P_INSTANCE_POINTER surface_free(surface_ptr); @@ -1331,7 +1332,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Surfaces if (this->getSurface(n) != NULL) { - system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(P_INSTANCE); + //system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(P_INSTANCE); + system_ptr->surface = P_INSTANCE_POINTER cxxSurface2surface((this->getSurface(n))); } else { diff --git a/Surface.cxx b/Surface.cxx index 2db4e675..f65dc167 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -71,18 +71,19 @@ cxxNumKeyword(io) for (i = 0; i < surface_ptr->count_comps; i++) { cxxSurfaceComp ec(&(surface_ptr->comps[i]), this->Get_io()); - std::string str(ec.get_formula()); + std::string str(ec.Get_formula()); surfaceComps[str] = ec; } // Surface charge for (i = 0; i < surface_ptr->count_charge; i++) { cxxSurfaceCharge ec(&(surface_ptr->charge[i]), this->Get_io()); - std::string str(ec.get_name()); + std::string str(ec.Get_name()); surfaceCharges[str] = ec; } } -cxxSurface::cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entities, + +cxxSurface::cxxSurface(const std::map < int, cxxSurface > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) { @@ -107,7 +108,7 @@ cxxNumKeyword(io) { const cxxSurface *entity_ptr = &(entities.find(it->first)->second); - this->add(P_INSTANCE_COMMA *entity_ptr, it->second); + this->add(*entity_ptr, it->second); } } } @@ -117,12 +118,12 @@ cxxSurface::~cxxSurface() } bool -cxxSurface::get_related_phases() +cxxSurface::Get_related_phases() { for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if ((*it).second.get_phase_name().size() == 0) + if ((*it).second.Get_phase_name().size() == 0) continue; return (true); } @@ -130,18 +131,19 @@ cxxSurface::get_related_phases() } bool -cxxSurface::get_related_rate() +cxxSurface::Get_related_rate() { for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) { - if ((*it).second.get_rate_name().size() == 0) + if ((*it).second.Get_rate_name().size() == 0) continue; return (true); } return (false); } +#ifdef MOVE_TO_STRUCTURES struct surface * cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) // @@ -215,6 +217,7 @@ cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) return (surface_ptr); } +#endif void cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const @@ -545,16 +548,16 @@ cxxSurface::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) + if (this->surfaceComps.find(ec.Get_formula()) != this->surfaceComps.end()) { - cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; + cxxSurfaceComp & comp = this->surfaceComps.find(ec.Get_formula())->second; comp.read_raw(reread, false); } else { cxxSurfaceComp ec1(this->Get_io()); ec1.read_raw(reread, false); - std::string str(ec1.get_formula()); + std::string str(ec1.Get_formula()); this->surfaceComps[str] = ec1; } } @@ -598,16 +601,16 @@ cxxSurface::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) + if (this->surfaceCharges.find(ec.Get_name()) != this->surfaceCharges.end()) { - cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; + cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.Get_name())->second; comp.read_raw(reread, false); } else { cxxSurfaceCharge ec1(this->Get_io()); ec1.read_raw(reread, false); - std::string str(ec1.get_name()); + std::string str(ec1.Get_name()); this->surfaceCharges[str] = ec1; } } @@ -872,8 +875,8 @@ cxxSurface::totalize() for (std::map < std::string, cxxSurfaceComp >::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { - this->totals.add_extensive((*it).second.get_totals(), 1.0); - this->totals.add("Charge", (*it).second.get_charge_balance()); + this->totals.add_extensive((*it).second.Get_totals(), 1.0); + this->totals.add("Charge", (*it).second.Get_charge_balance()); } return; } @@ -972,7 +975,7 @@ cxxSurface::add(const cxxSurface & addee, double extensive) } #endif void -cxxSurface::add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive) +cxxSurface::add(const cxxSurface & addee, double extensive) // // Add surface to "this" exchange // @@ -1015,7 +1018,7 @@ cxxSurface::add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive { cxxSurfaceComp entity = (*itadd).second; entity.multiply(extensive); - std::string str(entity.get_formula()); + std::string str(entity.Get_formula()); this->surfaceComps[str] = entity; } } @@ -1034,7 +1037,7 @@ cxxSurface::add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive { cxxSurfaceCharge entity = (*itadd).second; entity.multiply(extensive); - std::string str(entity.get_name()); + std::string str(entity.Get_name()); this->surfaceCharges[str] = entity; } } diff --git a/Surface.h b/Surface.h index 328c323f..f97dcf69 100644 --- a/Surface.h +++ b/Surface.h @@ -18,17 +18,17 @@ class cxxSurface:public cxxNumKeyword public: cxxSurface(PHRQ_io *io=NULL); cxxSurface(struct surface *, PHRQ_io *io=NULL); - cxxSurface(PHREEQC_PTR_ARG_COMMA const std::map < int, cxxSurface > &entity_map, cxxMix & mx, + cxxSurface(const std::map < int, cxxSurface > &entity_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); - ~cxxSurface(); + ~cxxSurface(); //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; - struct surface *cxxSurface2surface(PHREEQC_PTR_ARG); + //struct surface *cxxSurface2surface(PHREEQC_PTR_ARG); - struct surf_comp *cxxSurfaceComp2surf_comp(PHREEQC_PTR_ARG); + //struct surf_comp *cxxSurfaceComp2surf_comp(PHREEQC_PTR_ARG); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -36,13 +36,13 @@ class cxxSurface:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - bool get_related_phases(void); + bool Get_related_phases(void); - bool get_related_rate(void); + bool Get_related_rate(void); void totalize(); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return this->totals; }; @@ -51,8 +51,19 @@ class cxxSurface:public cxxNumKeyword void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -private: - void add(PHREEQC_PTR_ARG_COMMA const cxxSurface & addee, double extensive); + + void add(const cxxSurface & addee, double extensive); + const std::map < std::string, cxxSurfaceComp > & Get_surfaceComps() const {return this->surfaceComps;}; + const std::map < std::string, cxxSurfaceCharge > & Get_surfaceCharges() const {return this->surfaceCharges;}; + SURFACE_TYPE Get_type(void) {return this->type;}; + DIFFUSE_LAYER_TYPE Get_dl_type(void) {return dl_type;}; + SITES_UNITS Get_sites_units(void) {return sites_units;}; + bool Get_only_counter_ions(void) {return only_counter_ions;}; + double Get_thickness(void) {return thickness;}; + double Get_debye_lengths(void) {return debye_lengths;}; + double Get_DDL_viscosity(void) {return DDL_viscosity;}; + double Get_DDL_limit(void) const {return DDL_limit;}; + bool Get_transport(void) {return transport;}; protected: std::map < std::string, cxxSurfaceComp > surfaceComps; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index f2162a14..ea0260e2 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -51,7 +51,7 @@ cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr, PHRQ_ PHRQ_base(io), diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) { - this->set_name(surf_charge_ptr->name); + this->Set_name(surf_charge_ptr->name); specific_area = surf_charge_ptr->specific_area; grams = surf_charge_ptr->grams; charge_balance = surf_charge_ptr->charge_balance; @@ -86,6 +86,7 @@ cxxSurfaceCharge::~cxxSurfaceCharge() // return (master_ptr); //} +#ifdef MOVE_TO_STRUCTURES struct surface_charge * cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el) // @@ -125,6 +126,7 @@ cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map } return (surf_charge_ptr); } +#endif void cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const diff --git a/SurfaceCharge.h b/SurfaceCharge.h index a409a584..b2cafbd9 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -23,7 +23,7 @@ public: struct master *get_psi_master(); - static struct surface_charge *cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el); + //static struct surface_charge *cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -31,18 +31,13 @@ public: void read_raw(CParser & parser, bool check = true); - const std::string &get_name() const - { - return this->name; - } - - void set_name(const char * s) + const std::string &Get_name() const {return this->name;}; + void Set_name(const char * s) { if (s != NULL) this->name = std::string(s); else this->name.clear(); - } void add(const cxxSurfaceCharge & comp, double extensive); void multiply(double extensive); @@ -51,7 +46,16 @@ public: void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - + double Get_specific_area() const {return this->specific_area;}; + double Get_grams() const {return this->grams;}; + double Get_charge_balance() const {return this->charge_balance;}; + double Get_mass_water() const {return this->mass_water;}; + double Get_la_psi() const {return this->la_psi;}; + double Get_la_psi1() const {return this->la_psi1;}; + double Get_la_psi2() const {return this->la_psi2;}; + double Get_capacitance0() const {return this->capacitance[0];}; + double Get_capacitance1() const {return this->capacitance[1];}; + const cxxNameDouble & Get_diffuse_layer_totals(void) const {return this->diffuse_layer_totals;}; protected: std::string name; double specific_area; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 3f8b3a15..3b0b0af3 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -51,22 +51,22 @@ PHRQ_base(io), formula_totals(surf_comp_ptr->formula_totals), totals(surf_comp_ptr->totals) { - this->set_formula(surf_comp_ptr->formula); + this->Set_formula(surf_comp_ptr->formula); formula_z = surf_comp_ptr->formula_z; moles = surf_comp_ptr->moles; la = surf_comp_ptr->la; //charge_number = surf_comp_ptr->charge; charge_balance = surf_comp_ptr->cb; - this->set_phase_name(surf_comp_ptr->phase_name); + this->Set_phase_name(surf_comp_ptr->phase_name); phase_proportion = surf_comp_ptr->phase_proportion; - this->set_rate_name(surf_comp_ptr->rate_name); + this->Set_rate_name(surf_comp_ptr->rate_name); Dw = surf_comp_ptr->Dw; } cxxSurfaceComp::~cxxSurfaceComp() { } - +#ifdef MOVE_TO_STRUCTURES struct master * cxxSurfaceComp::get_master(PHREEQC_PTR_ARG) { @@ -104,7 +104,9 @@ struct master * } return (master_ptr); } +#endif +#ifdef MOVE_TO_STRUCTURES struct surface_comp * cxxSurfaceComp::cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el) // @@ -146,6 +148,7 @@ struct surface_comp * } return (surf_comp_ptr); } +#endif void cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const @@ -666,12 +669,12 @@ cxxSurfaceComp::multiply(double extensive) //double Dw; } const std::string & -cxxSurfaceComp::get_phase_name() const +cxxSurfaceComp::Get_phase_name() const { return this->phase_name; } void -cxxSurfaceComp::set_phase_name(char * f) +cxxSurfaceComp::Set_phase_name(char * f) { if (f != NULL) this->phase_name = std::string(f); @@ -679,12 +682,12 @@ cxxSurfaceComp::set_phase_name(char * f) this->phase_name.clear(); } const std::string & -cxxSurfaceComp::get_rate_name() const +cxxSurfaceComp::Get_rate_name() const { return this->rate_name; } void -cxxSurfaceComp::set_rate_name(char * f) +cxxSurfaceComp::Set_rate_name(char * f) { if (f != NULL) this->rate_name = std::string(f); @@ -692,12 +695,12 @@ cxxSurfaceComp::set_rate_name(char * f) this->rate_name.clear(); } const std::string & -cxxSurfaceComp::get_formula() const +cxxSurfaceComp::Get_formula() const { return this->formula; } void -cxxSurfaceComp::set_formula(char * f) +cxxSurfaceComp::Set_formula(char * f) { if (f != NULL) this->formula = std::string(f); @@ -705,20 +708,26 @@ cxxSurfaceComp::set_formula(char * f) this->formula.clear(); } double -cxxSurfaceComp::get_charge_balance() const +cxxSurfaceComp::Get_charge_balance() const { return this->charge_balance; } void -cxxSurfaceComp::set_charge_balance(double d) +cxxSurfaceComp::Set_charge_balance(double d) { this->charge_balance = d; } const cxxNameDouble & -cxxSurfaceComp::get_totals() const +cxxSurfaceComp::Get_totals() const { return (this->totals); } +const cxxNameDouble & +cxxSurfaceComp::Get_formula_totals() const +{ + return (this->formula_totals); +} +#ifdef MOVE_TO_STRUCTURES std::string cxxSurfaceComp::charge_name(PHREEQC_PTR_ARG) { @@ -739,3 +748,4 @@ cxxSurfaceComp::get_charge_name(PHREEQC_PTR_ARG_COMMA char *token) } return (std::string(name)); } +#endif \ No newline at end of file diff --git a/SurfaceComp.h b/SurfaceComp.h index a9783b7d..cad1e064 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -18,24 +18,30 @@ public: cxxSurfaceComp(struct surface_comp *, PHRQ_io *io=NULL); ~cxxSurfaceComp(); - struct master *get_master(PHREEQC_PTR_ARG); - const std::string &get_phase_name() const; - void set_phase_name(char * f); - const std::string &get_rate_name() const; - void set_rate_name(char * f); - const std::string &get_formula() const; - void set_formula(char * f); - double get_charge_balance() const; - void set_charge_balance(double d); - static struct surface_comp *cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el); + //struct master *get_master(PHREEQC_PTR_ARG); + const std::string &Get_phase_name() const; + void Set_phase_name(char * f); + const std::string &Get_rate_name() const; + void Set_rate_name(char * f); + const std::string &Get_formula() const; + void Set_formula(char * f); + double Get_charge_balance() const; + void Set_charge_balance(double d); + //static struct surface_comp *cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - const cxxNameDouble & get_totals() const; + const cxxNameDouble & Get_totals() const; + const cxxNameDouble & Get_formula_totals() const; + double Get_formula_z(void) const {return formula_z;}; + double Get_moles(void) const {return moles;}; + double Get_la(void) const {return la;}; + double Get_phase_proportion(void) const {return phase_proportion;}; + double Get_Dw(void) const {return Dw;}; void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - std::string charge_name(PHREEQC_PTR_ARG); - static std::string get_charge_name(PHREEQC_PTR_ARG_COMMA char *token); + //std::string charge_name(PHREEQC_PTR_ARG); + //static std::string get_charge_name(PHREEQC_PTR_ARG_COMMA char *token); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/System.cxx b/System.cxx index abc49fde..524f3755 100644 --- a/System.cxx +++ b/System.cxx @@ -94,7 +94,7 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) if (this->surface != NULL) { this->ssassemblage->totalize(P_INSTANCE); - this->totals.add_extensive(this->surface->get_totals(), 1.0); + this->totals.add_extensive(this->surface->Get_totals(), 1.0); } //Need to handle the following 3 reactions: // From 4d728afcbe88099479341cd104fd17db28c04452 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 28 Sep 2011 20:25:20 +0000 Subject: [PATCH 0259/1077] Removed MOVE_TO_STRUCTURES ifdefs. Removed most SKIP ifdefs ran test cases OK. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5657 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 110 ------------------- Exchange.cxx | 113 ------------------- GasPhase.cxx | 69 ------------ ISolution.cxx | 53 --------- KineticsComp.cxx | 53 --------- NameDouble.cxx | 139 ------------------------ NameDouble.h | 14 +-- PPassemblage.cxx | 49 --------- PPassemblageComp.cxx | 38 ------- Reaction.cxx | 54 ---------- ReadClass.cxx | 232 ---------------------------------------- SSassemblage.cxx | 80 -------------- SSassemblage.h | 4 - SSassemblageSS.cxx | 93 ---------------- SSassemblageSS.h | 3 - Solution.cxx | 57 ---------- Solution.h | 6 -- SolutionIsotope.cxx | 26 +---- SolutionIsotope.h | 13 --- SolutionIsotopeList.cxx | 34 +----- SolutionIsotopeList.h | 1 - StorageBin.cxx | 81 -------------- Surface.cxx | 219 ------------------------------------- Surface.h | 8 -- SurfaceCharge.cxx | 42 -------- SurfaceCharge.h | 4 +- SurfaceComp.cxx | 105 ------------------ SurfaceComp.h | 5 +- Temperature.cxx | 40 ------- Utils.cxx | 11 -- cxxKinetics.cxx | 131 ----------------------- cxxMix.cxx | 40 ------- dumper.cpp | 212 ------------------------------------ 33 files changed, 5 insertions(+), 2134 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 3e687634..192d1f52 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -129,116 +129,6 @@ cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, cxxExchComp::~cxxExchComp() { } -#ifdef MOVE_TO_STRUCTURES -struct master * -cxxExchComp::get_master(PHREEQC_PTR_ARG) -{ - struct master *master_ptr = NULL; - for (std::map < std::string, double >::iterator it = - totals.begin(); it != totals.end(); it++) - { - - /* Find master species */ - char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - assert(it->first.size() != 0); - struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); - if (elt_ptr->master == NULL) - { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr-> - name << std::endl; - //Utilities::error_msg(error_oss.str(), STOP); - error_msg(error_oss.str().c_str(), CONTINUE); - return (NULL); - } - if (elt_ptr->master->type != EX) - continue; - master_ptr = elt_ptr->master; - break; - } - if (master_ptr == NULL) - { - for (std::map < std::string, double >::iterator it = - this->formula_totals.begin(); it != formula_totals.end(); it++) - { - - /* Find master species */ - char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - assert(it->first.size() != 0); - struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); - if (elt_ptr->master == NULL) - { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << - elt_ptr->name << std::endl; - //Utilities::error_msg(error_oss.str(), STOP); - error_msg(error_oss.str().c_str(), CONTINUE); - return (NULL); - } - if (elt_ptr->master->type != EX) - continue; - master_ptr = elt_ptr->master; - break; - } - } - if (master_ptr == NULL) - { - std::ostringstream error_oss; - error_oss << - "Exchange formula does not contain an exchange master species, " - << this->formula << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); - - std::ostringstream oss; - this->dump_raw(oss, 0); - std::cerr << oss.str(); - - } - return (master_ptr); -} - -struct exch_comp * - cxxExchComp::cxxExchComp2exch_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxExchComp > &el) - // - // Builds exch_comp structure from of cxxExchComp - // -{ - struct exch_comp *exch_comp_ptr = - (struct exch_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct exch_comp))); - if (exch_comp_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - int i = 0; - for (std::map < std::string, cxxExchComp >::iterator it = el.begin(); it != el.end(); - ++it) - { - if ((*it).second.formula.size() == 0) - exch_comp_ptr[i].formula = NULL; - else - exch_comp_ptr[i].formula = P_INSTANCE_POINTER string_hsave((*it).second.formula.c_str()); - exch_comp_ptr[i].formula_z = (*it).second.formula_z; - exch_comp_ptr[i].totals = (*it).second.totals.elt_list(P_INSTANCE); - exch_comp_ptr[i].moles = (*it).second.moles; - exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(P_INSTANCE); - exch_comp_ptr[i].la = (*it).second.la; - exch_comp_ptr[i].charge_balance = (*it).second.charge_balance; - if ((*it).second.phase_name.size() == 0) - exch_comp_ptr[i].phase_name = NULL; - else - exch_comp_ptr[i].phase_name = P_INSTANCE_POINTER string_hsave((*it).second.phase_name.c_str()); - exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; - if ((*it).second.rate_name.size() == 0) - exch_comp_ptr[i].rate_name = NULL; - else - exch_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); - exch_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); - i++; - } - return (exch_comp_ptr); -} -#endif void cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const diff --git a/Exchange.cxx b/Exchange.cxx index 220624dc..5809544e 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -78,17 +78,6 @@ cxxNumKeyword(io) this->add(*entity_ptr, it->second); this->pitzer_exchange_gammas = entity_ptr->pitzer_exchange_gammas; } -#ifdef SKIP - if (entity_ptr == NULL) - { - sprintf(error_string, "Exchange %d not found while mixing.", - it->first); - error_msg(error_string, CONTINUE); - input_error++; - return; - } -#endif - } } @@ -203,31 +192,6 @@ cxxExchange::get_related_rate() return (false); } -#ifdef MOVE_TO_STRUCTURES -struct exchange * -cxxExchange::cxxExchange2exchange(PHREEQC_PTR_ARG) - // - // Builds a exchange structure from instance of cxxExchange - // -{ - struct exchange *exchange_ptr = P_INSTANCE_POINTER exchange_alloc(); - - exchange_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - exchange_ptr->n_user = this->n_user; - exchange_ptr->n_user_end = this->n_user_end; - exchange_ptr->new_def = FALSE; - exchange_ptr->solution_equilibria = FALSE; - exchange_ptr->n_solution = -2; - exchange_ptr->related_phases = (int) this->get_related_phases(); - exchange_ptr->related_rate = (int) this->get_related_rate(); - exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; - exchange_ptr->count_comps = (int) this->exchComps.size(); - exchange_ptr->comps = (struct exch_comp *) P_INSTANCE_POINTER free_check_null(exchange_ptr->comps); - exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(P_INSTANCE_COMMA this->exchComps); - return (exchange_ptr); -} -#endif - void cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -366,32 +330,6 @@ cxxExchange::read_raw(CParser & parser, bool check) cxxExchComp ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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_stream(eo_s); - parser.seekg(pos).clear(); - parser.seekg(pos); - - if (this->exchComps.find(ec.get_formula()) != this->exchComps.end()) - { - cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second; - - comp.read_raw(parser, false); - } - else - { - cxxExchComp ec1; - ec1.read_raw(parser, false); - std::string str(ec1.get_formula()); - this->exchComps[str] = ec1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); @@ -431,43 +369,6 @@ cxxExchange::read_raw(CParser & parser, bool check) } } } -#ifdef SKIP -void -cxxExchange::add(const cxxExchange & addee, double extensive) - // - // Add existing exchange to "this" exchange - // -{ - //std::list exchComps; - // exchComps - if (extensive == 0.0) - return; - for (std::list < cxxExchComp >::const_iterator itadd = - addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd) - { - 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) - { - cxxExchComp exc = *itadd; - exc.multiply(extensive); - //exc.add(*itadd, extensive); - this->exchComps.push_back(exc); - } - } - //bool pitzer_exchange_gammas; - this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; -} -#endif void cxxExchange::add(const cxxExchange & addee, double extensive) // @@ -484,19 +385,6 @@ cxxExchange::add(const cxxExchange & addee, double extensive) 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 { @@ -506,7 +394,6 @@ cxxExchange::add(const cxxExchange & addee, double extensive) this->exchComps[(*itadd).first] = exc; } } - //bool pitzer_exchange_gammas; this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; } #ifdef USE_MPI diff --git a/GasPhase.cxx b/GasPhase.cxx index 8efdfc59..c9890fb4 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -123,75 +123,6 @@ cxxNumKeyword(io) cxxGasPhase::~cxxGasPhase() { } -#ifdef MOVE_TO_STRUCTURES -struct gas_comp * -cxxGasPhase::cxxGasPhaseComp2gas_comp(PHREEQC_PTR_ARG) -{ - //struct gas_comp *gas_comp_ptr(NULL); - struct gas_comp *gas_comp_ptr = NULL; - if (this->gasPhaseComps.size() > 0) - { - int i = 0; - int n; - gas_comp_ptr = - (struct gas_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) - (this->gasPhaseComps.size() * - sizeof(struct gas_comp))); - if (gas_comp_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - for (cxxNameDouble::iterator it = this->gasPhaseComps.begin(); - it != this->gasPhaseComps.end(); it++) - { - gas_comp_ptr[i].name = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - assert(it->first.size() != 0); - gas_comp_ptr[i].phase = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &n, TRUE); - gas_comp_ptr[i].p_read = 0; - gas_comp_ptr[i].moles = it->second; - gas_comp_ptr[i].initial_moles = 0; - i++; - } - } - return (gas_comp_ptr); -} -#endif - -#ifdef MOVE_TO_STRUCTURES -struct gas_phase * -cxxGasPhase::cxxGasPhase2gas_phase(PHREEQC_PTR_ARG) - // - // Builds a gas_phase structure from instance of cxxGasPhase - // -{ - struct gas_phase *gas_phase_ptr = P_INSTANCE_POINTER gas_phase_alloc(); - - gas_phase_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - gas_phase_ptr->n_user = this->n_user; - gas_phase_ptr->n_user_end = this->n_user_end; - gas_phase_ptr->new_def = FALSE; - gas_phase_ptr->solution_equilibria = FALSE; - gas_phase_ptr->n_solution = -2; - if (this->type == cxxGasPhase::GP_PRESSURE) - { - gas_phase_ptr->type = PRESSURE; - } - else - { - gas_phase_ptr->type = VOLUME; - } - gas_phase_ptr->total_p = this->total_p; - gas_phase_ptr->volume = this->volume; - gas_phase_ptr->temperature = 273.15; - - // comps - gas_phase_ptr->count_comps = (int) this->gasPhaseComps.size(); - gas_phase_ptr->comps = - (struct gas_comp *) P_INSTANCE_POINTER free_check_null(gas_phase_ptr->comps); - gas_phase_ptr->comps = this->cxxGasPhaseComp2gas_comp(P_INSTANCE); - - return (gas_phase_ptr); -} -#endif #ifdef SKIP void diff --git a/ISolution.cxx b/ISolution.cxx index 7add501b..42231990 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -40,57 +40,11 @@ units("mMol/kgw") pes = NULL; } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -cxxISolution::cxxISolution(PHREEQC_PTR_ARG_COMMA struct solution *solution_ptr, PHRQ_io *io) -: -cxxSolution(solution_ptr, io) - //, pe(cxxPe_Data::alloc()) -{ - density = solution_ptr->density; - this->set_units(solution_ptr->units); - // totals - for (int i = 0; solution_ptr->totals[i].description != NULL; i++) - { - cxxISolutionComp c(&(solution_ptr->totals[i]), this->Get_io()); - //comps.insert(solution_ptr->totals[i].description, c); - comps[solution_ptr->totals[i].description] = c; - } - default_pe = solution_ptr->default_pe; - // pe_data - pes = P_INSTANCE_POINTER pe_data_dup(solution_ptr->pe); -} -#endif - cxxISolution::~cxxISolution() { //// ToDo //pe_data_free(this->pes); } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct solution * -cxxISolution::cxxISolution2solution(PHREEQC_PTR_ARG) - // - // Builds a solution structure from instance of cxxISolution - // -{ - struct solution *soln_ptr = this->cxxSolution2solution(P_INSTANCE); - soln_ptr->new_def = TRUE; - soln_ptr->density = this->density; - if (this->units.size() == 0) - soln_ptr->units = NULL; - else - soln_ptr->units = P_INSTANCE_POINTER string_hsave(this->units.c_str()); - soln_ptr->default_pe = this->default_pe; - // pe - soln_ptr->pe = (struct pe_data *) P_INSTANCE_POINTER pe_data_free(soln_ptr->pe); - soln_ptr->pe = P_INSTANCE_POINTER pe_data_dup(this->pes); - // totals - soln_ptr->totals = (struct conc *) P_INSTANCE_POINTER free_check_null(soln_ptr->totals); - soln_ptr->totals = cxxISolutionComp::cxxISolutionComp2conc(P_INSTANCE_COMMA this->comps); - return (soln_ptr); -} -#endif - #ifdef SKIP_OR_MOVE_TO_STRUCTURES void cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) @@ -382,13 +336,6 @@ cxxISolution & cxxISolution::read(CParser & parser) if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) break; } -#ifdef SKIP - // - // Sort totals by description - // - std::sort(sol.totals.begin(), sol.totals.end()); -#endif - // // fix up default units and default pe // diff --git a/KineticsComp.cxx b/KineticsComp.cxx index dd513948..ad2f64f8 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -61,59 +61,6 @@ cxxKineticsComp::~cxxKineticsComp() { } -#ifdef MOVE_TO_STRUCTURES -struct kinetics_comp * - cxxKineticsComp::cxxKineticsComp2kinetics_comp(PHREEQC_PTR_ARG_COMMA std::list < cxxKineticsComp > - &el) - // - // Builds kinetics_comp structure from of cxxKineticsComp - // -{ - struct kinetics_comp *kinetics_comp_ptr = - (struct kinetics_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct kinetics_comp))); - if (kinetics_comp_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - int i = 0; - for (std::list < cxxKineticsComp >::iterator it = el.begin(); - it != el.end(); ++it) - { - if ((*it).rate_name.size() == 0) - kinetics_comp_ptr[i].rate_name = NULL; - else - kinetics_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).rate_name.c_str()); - kinetics_comp_ptr[i].list = (*it).namecoef.name_coef(P_INSTANCE); - kinetics_comp_ptr[i].count_list = (int) (*it).namecoef.size(); - kinetics_comp_ptr[i].tol = (*it).tol; - kinetics_comp_ptr[i].m = (*it).m; - kinetics_comp_ptr[i].initial_moles = 0.; - kinetics_comp_ptr[i].m0 = (*it).m0; - kinetics_comp_ptr[i].moles = (*it).moles; - kinetics_comp_ptr[i].count_c_params = 0; - kinetics_comp_ptr[i].c_params = NULL; -/* - kinetics_comp_ptr[i].count_d_params = 0; - kinetics_comp_ptr[i].d_params = NULL; -*/ - - kinetics_comp_ptr[i].count_d_params = (int) (*it).d_params.size(); - kinetics_comp_ptr[i].d_params = NULL; - if ((*it).d_params.size() > 0) - { - kinetics_comp_ptr[i].d_params = (LDBLE *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((*it).d_params.size() * sizeof(double))); - if (kinetics_comp_ptr[i].d_params == NULL) - P_INSTANCE_POINTER malloc_error(); - std::copy((*it).d_params.begin(), (*it).d_params.end(), - kinetics_comp_ptr[i].d_params); - } - i++; - } - return (kinetics_comp_ptr); -} -#endif - #ifdef SKIP void cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const diff --git a/NameDouble.cxx b/NameDouble.cxx index ae4bde02..8a1010a8 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -158,145 +158,6 @@ cxxNameDouble::~cxxNameDouble() { } -struct elt_list * -cxxNameDouble::elt_list(PHREEQC_PTR_ARG) - // - // Builds a exch_comp structure from instance of cxxNameDouble - // -{ - assert(this->type == cxxNameDouble::ND_ELT_MOLES); - struct elt_list *elt_list_ptr = - (struct elt_list *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size() + 1) * sizeof(struct elt_list))); - if (elt_list_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - int i = 0; - for (iterator it = this->begin(); it != this->end(); ++it) - { - elt_list_ptr[i].elt = P_INSTANCE_POINTER element_store(it->first.c_str()); - elt_list_ptr[i].coef = it->second; - i++; - } - elt_list_ptr[i].elt = NULL; - elt_list_ptr[i].coef = 0; - return (elt_list_ptr); -} - -#ifdef MOVE_TO_STRUCTURES -struct master_activity * -cxxNameDouble::master_activity(PHREEQC_PTR_ARG) const - // - // Builds a list of master_activity structures from instance of cxxNameDouble - // -{ - int i = 0; - assert(this->type == cxxNameDouble::ND_SPECIES_LA - || this->type == cxxNameDouble::ND_SPECIES_GAMMA); - struct master_activity *master_activity_ptr = NULL; - switch ((*this).type) - { - case cxxNameDouble::ND_SPECIES_LA: - { - master_activity_ptr = - (struct master_activity *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) - (((*this).size() + - 1) * sizeof(struct master_activity))); - if (master_activity_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - for (const_iterator it = (*this).begin(); it != (*this).end(); - it++) - { - master_activity_ptr[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - master_activity_ptr[i].la = it->second; - i++; - } - } - master_activity_ptr[i].description = NULL; - break; - case cxxNameDouble::ND_SPECIES_GAMMA: - { - if ((*this).size() > 0) - { - master_activity_ptr = - (struct master_activity *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) - (((*this).size()) * - sizeof(struct master_activity))); - if (master_activity_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - for (const_iterator it = (*this).begin(); it != (*this).end(); - it++) - { - master_activity_ptr[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - master_activity_ptr[i].la = it->second; - i++; - } - } - } - break; - case cxxNameDouble::ND_ELT_MOLES: - case cxxNameDouble::ND_NAME_COEF: - break; - } - return (master_activity_ptr); -} - -struct conc * -cxxNameDouble::conc(PHREEQC_PTR_ARG) const - // for Solutions, not ISolutions - // takes a map of (elt name, moles) - // returns list of conc structures -{ - struct conc *c; - assert(this->type == cxxNameDouble::ND_ELT_MOLES); - c = (struct conc *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (((*this).size() + 1) * sizeof(struct conc))); - if (c == NULL) - P_INSTANCE_POINTER malloc_error(); - int i = 0; - for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) - { - c[i].description = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - c[i].moles = it->second; - c[i].input_conc = it->second; - c[i].units = NULL; - c[i].equation_name = NULL; - c[i].phase_si = 0.0; - c[i].n_pe = 0; - c[i].as = NULL; - c[i].gfw = 0.0; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return (c); -} - -struct name_coef * -cxxNameDouble::name_coef(PHREEQC_PTR_ARG) const - // - // Builds a name_coef structure from instance of cxxNameDouble - // -{ - assert(this->type == cxxNameDouble::ND_NAME_COEF); - struct name_coef *name_coef_ptr = - (struct name_coef *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size()) * sizeof(struct name_coef))); - if (name_coef_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - int i = 0; - for (const_iterator it = (*this).begin(); it != (*this).end(); ++it) - { - name_coef_ptr[i].name = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - name_coef_ptr[i].coef = it->second; - i++; - } - return (name_coef_ptr); -} -#endif - void cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const { diff --git a/NameDouble.h b/NameDouble.h index 16c46001..5f63a892 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -34,23 +34,12 @@ class cxxNameDouble:public ~ cxxNameDouble(); - struct elt_list * elt_list(PHREEQC_PTR_ARG); - - //struct master_activity * master_activity(PHREEQC_PTR_ARG) const; - - //struct conc * conc(PHREEQC_PTR_ARG) const; - - //struct name_coef * name_coef(PHREEQC_PTR_ARG) const; - void dump_xml(std::ostream & s_oss, unsigned int indent) const; - void dump_raw(std::ostream & s_oss, unsigned int indent) const; - CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type & pos); - void add_extensive(const cxxNameDouble & old, double factor); void @@ -61,7 +50,6 @@ class cxxNameDouble:public add(const char *key, double total); void multiply(double factor); - void merge_redox(const cxxNameDouble & source); @@ -75,7 +63,7 @@ class cxxNameDouble:public } void - mpi_pack(PHREEQC_PTR_ARG_COMMA std::vector < int >&ints, std::vector < double >&doubles); + mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_pack(int *ints, int *ii, double *doubles, int *dd); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 90ceec91..27c2589c 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -81,28 +81,6 @@ cxxPPassemblage::~cxxPPassemblage() { } -#ifdef MOVE_TO_STRUCTURES -struct pp_assemblage * -cxxPPassemblage::cxxPPassemblage2pp_assemblage(PHREEQC_PTR_ARG) - // - // Builds a pp_assemblage structure from instance of cxxPPassemblage - // -{ - struct pp_assemblage *pp_assemblage_ptr = P_INSTANCE_POINTER pp_assemblage_alloc(); - - pp_assemblage_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - pp_assemblage_ptr->n_user = this->n_user; - pp_assemblage_ptr->n_user_end = this->n_user_end; - pp_assemblage_ptr->new_def = FALSE; - pp_assemblage_ptr->count_comps = (int) this->ppAssemblageComps.size(); - pp_assemblage_ptr->pure_phases = - (struct pure_phase *) P_INSTANCE_POINTER free_check_null(pp_assemblage_ptr->pure_phases); - pp_assemblage_ptr->pure_phases = - cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(P_INSTANCE_COMMA this->ppAssemblageComps); - pp_assemblage_ptr->next_elt = this->eltList.elt_list(P_INSTANCE); - return (pp_assemblage_ptr); -} -#endif void cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -239,33 +217,6 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) cxxPPassemblageComp ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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); - ppComp.read_raw(parser, false); - parser.set_echo_file(eo); - parser.set_echo_stream(eo_s); - - if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end()) - { - cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ppComp.get_name())->second; - parser.seekg(pos).clear(); - parser.seekg(pos); - comp.read_raw(parser, false); - } - else - { - parser.seekg(pos).clear(); - parser.seekg(pos); - cxxPPassemblageComp ppComp1; - ppComp1.read_raw(parser, false); - std::string str(ppComp1.get_name()); - this->ppAssemblageComps[str] = ppComp1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 74095a88..0aecbc03 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -63,44 +63,6 @@ cxxPPassemblageComp::~cxxPPassemblageComp() { } -#ifdef MOVE_TO_STRUCTURES -struct pure_phase * -cxxPPassemblageComp::cxxPPassemblageComp2pure_phase(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxPPassemblageComp > &el) - // - // Builds pure_phase structure from of cxxPPassemblageComp - // -{ - struct pure_phase *pure_phase_ptr = - (struct pure_phase *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct pure_phase))); - if (pure_phase_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - int i = 0; - for (std::map < std::string, cxxPPassemblageComp >::iterator it = el.begin(); - it != el.end(); ++it) - { - pure_phase_ptr[i].phase = (*it).second.get_phase(P_INSTANCE); - if ((*it).second.name.size() == 0) - pure_phase_ptr[i].name = NULL; - else - pure_phase_ptr[i].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); - if ((*it).second.add_formula.size() == 0) - pure_phase_ptr[i].add_formula = NULL; - else - pure_phase_ptr[i].add_formula = P_INSTANCE_POINTER string_hsave((*it).second.add_formula.c_str()); - pure_phase_ptr[i].si = (*it).second.si; - pure_phase_ptr[i].moles = (*it).second.moles; - pure_phase_ptr[i].delta = (*it).second.delta; - pure_phase_ptr[i].initial_moles = (*it).second.initial_moles; - pure_phase_ptr[i].force_equality = (int) (*it).second.force_equality; - pure_phase_ptr[i].dissolve_only = (int) (*it).second.dissolve_only; - pure_phase_ptr[i].precipitate_only = (int) (*it).second.precipitate_only; - i++; - } - return (pure_phase_ptr); -} -#endif void cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { diff --git a/Reaction.cxx b/Reaction.cxx index 17453a47..8e6ef4dc 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -74,60 +74,6 @@ cxxReaction::~cxxReaction() { } -#ifdef MOVE_TO_STRUCTURES -struct irrev * -cxxReaction::cxxReaction2irrev(PHREEQC_PTR_ARG) - // - // Builds a irrev structure from instance of cxxReaction - // -{ - struct irrev *irrev_ptr; - irrev_ptr = (struct irrev *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct irrev)); - if (irrev_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - irrev_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - irrev_ptr->n_user = this->n_user; - irrev_ptr->n_user_end = this->n_user_end; - - irrev_ptr->list = this->reactantList.name_coef(P_INSTANCE); - irrev_ptr->count_list = (int) this->reactantList.size(); - if (this->elementList.size() > 0) - { - irrev_ptr->elts = this->elementList.elt_list(P_INSTANCE); - } - else - { - // NULL value causes reaction stoichiometry to be calculated - irrev_ptr->elts = NULL; - } - // steps - irrev_ptr->steps = NULL; - if (this->steps.size() > 0) - { - irrev_ptr->steps = - (LDBLE *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); - if (irrev_ptr->steps == NULL) - P_INSTANCE_POINTER malloc_error(); - std::copy(this->steps.begin(), this->steps.end(), irrev_ptr->steps); - } - if (this->equalIncrements) - { - irrev_ptr->count_steps = -this->countSteps; - } - else - { - irrev_ptr->count_steps = (int) this->steps.size(); - } - if (this->units.size() == 0) - irrev_ptr->units = NULL; - else - irrev_ptr->units = P_INSTANCE_POINTER string_hsave(this->units.c_str()); - return (irrev_ptr); -} -#endif - #ifdef SKIP void cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const diff --git a/ReadClass.cxx b/ReadClass.cxx index 76ff5252..8aaa2c52 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1165,97 +1165,6 @@ read_run_cells(void) if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER -read_solution_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution_modify data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find solution 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 solution number following SOLUTION_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(PHREEQC_THIS_COMMA iss_in, oss_out, oss_err); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - - if (solution_bsearch(n_user, &n, FALSE) == NULL) - { - input_error++; - sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - cxxSolution sol(solution[n]); - sol.read_raw(parser, false); - - struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - solution_free(solution[n]); - solution[n] = soln_ptr; - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER read_solution_modify(void) @@ -2335,147 +2244,6 @@ delete_entities(void) delete_info.SetAll(false); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int -run_as_cells(void) -/* ---------------------------------------------------------------------- */ -{ - int i, n; - LDBLE kin_time; -/* - * Calculate advection - */ - state = ADVECTION; -/* mass_water_switch = TRUE; */ -/* - * Check existence of all solutions - */ - if (run_info.Get_cells().Get_numbers().size() == 0 || - !(run_info.Get_cells().Get_defined())) return(OK); - - dup_print("Beginning of run as cells.", TRUE); - - std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); - last_model.force_prep = TRUE; - initial_total_time = run_info.Get_start_time(); - rate_sim_time_start = 0; - kin_time = run_info.Get_time_step(); - double advection_kin_time_save = advection_kin_time; - advection_kin_time = kin_time; - - for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) - { - i = *it; - if (i < 0) continue; - //if (solution_bsearch(i, &n, TRUE) == NULL) - //{ - // sprintf(error_string, - // "Solution %d is needed for RUN, but is not defined.", i); - // warning_msg(error_string); - // continue; - //} - /* - * Equilibrate and (or) mix - */ - set_initial_moles(i); - cell_no = i; - set_advection(i, TRUE, TRUE, i); - reactions(); - - //run_reactions(i, kin_time, TRUE, 1.0); - ////rate_sim_time = rate_sim_time_start + kin_time; - - //punch_all(); - //print_all(); - //save.n_solution_user = i; - //save.n_solution_user_end = i; - //struct save save_dbg = save; - saver(); - } - double advection_kin_time = advection_kin_time_save; - initial_total_time += rate_sim_time_start; - /* free_model_allocs(); */ - mass_water_switch = FALSE; - run_info.Get_cells().Set_defined(false); - return (OK); -} -#endif -#ifdef SKIP2 -/* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER -run_as_cells(void) -/* ---------------------------------------------------------------------- */ -{ - struct save save_data; - LDBLE kin_time; - - state = REACTION; - if (run_info.Get_cells().Get_numbers().size() == 0 || - !(run_info.Get_cells().Get_defined())) return(OK); - - dup_print("Beginning of run as cells.", TRUE); - - std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); - last_model.force_prep = TRUE; - initial_total_time = run_info.Get_start_time(); - rate_sim_time_start = 0; - kin_time = run_info.Get_time_step(); - - for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) - { - int i = *it; - if (i < 0) continue; - - set_advection(i, TRUE, TRUE, i); - - save_data = save; - - /* last_model.force_prep = TRUE; */ - //if (set_use() == FALSE) - // return (OK); - - /* - * save data for saving solutions - */ - //memcpy(&save_data, &save, sizeof(struct save)); - /* - *Copy everything to -2 - */ - copy_use(-2); - rate_sim_time_start = 0; - rate_sim_time = 0; - - set_initial_moles(-2); - -/* - * Run reaction step - */ - run_reactions(-2, kin_time, TRUE, 1.0); - rate_sim_time = kin_time; - - punch_all(); - print_all(); - - /* saves back into -2 */ - save = save_data; - saver(); - } -/* - * save end of reaction - */ - //memcpy(&save, &save_data, sizeof(struct save)); - //if (use.kinetics_in == TRUE) - //{ - // kinetics_duplicate(-2, use.n_kinetics_user); - //} - //saver(); - run_info.Get_cells().Set_defined(false); - /* free_model_allocs(); */ - /* last_model.force_prep = TRUE; */ - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER run_as_cells(void) diff --git a/SSassemblage.cxx b/SSassemblage.cxx index c49aa641..b0881cbf 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -78,26 +78,6 @@ cxxSSassemblage::~cxxSSassemblage() { } -#ifdef MOVE_TO_STRUCTURES -struct s_s_assemblage * -cxxSSassemblage::cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG) - // - // Builds a s_s_assemblage structure from instance of cxxSSassemblage - // -{ - struct s_s_assemblage *s_s_assemblage_ptr = P_INSTANCE_POINTER s_s_assemblage_alloc(); - - s_s_assemblage_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - s_s_assemblage_ptr->n_user = this->n_user; - s_s_assemblage_ptr->n_user_end = this->n_user_end; - s_s_assemblage_ptr->new_def = FALSE; - s_s_assemblage_ptr->count_s_s = (int) this->ssAssemblageSSs.size(); - s_s_assemblage_ptr->s_s = - cxxSSassemblageSS::cxxSSassemblageSS2s_s(P_INSTANCE_COMMA this->ssAssemblageSSs); - return (s_s_assemblage_ptr); -} -#endif - #ifdef SKIP void cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -216,31 +196,6 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) cxxSSassemblageSS ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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_stream(eo_s); - parser.seekg(pos).clear(); - parser.seekg(pos); - - if (this->ssAssemblageSSs.find(ec.get_name()) != this->ssAssemblageSSs.end()) - { - cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.get_name())->second; - ec1.read_raw(parser, false); - } - else - { - cxxSSassemblageSS ec1; - ec1.read_raw(parser, false); - std::string str(ec1.get_name()); - this->ssAssemblageSSs[str] = ec1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); @@ -326,41 +281,6 @@ cxxSSassemblage::totalize(PHREEQC_PTR_ARG) } return; } -#ifdef SKIP -void -cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) - // - // Add to existing ssassemblage to "this" ssassemblage - // -{ - if (extensive == 0.0) - return; - - for (std::list < cxxSSassemblageSS >::const_iterator itadd = - addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); - ++itadd) - { - bool found = false; - for (std::list < cxxSSassemblageSS >::iterator it = - this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); - ++it) - { - if (it->get_name() == itadd->get_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) - { - cxxSSassemblageSS entity = *itadd; - entity.multiply(extensive); - this->ssAssemblageSSs.push_back(entity); - } - } -} -#endif void cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) // diff --git a/SSassemblage.h b/SSassemblage.h index 5cbe2563..5d3a5d76 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -25,10 +25,6 @@ public: cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); - //struct s_s_assemblage *cxxSSassemblage2s_s_assemblage(PHREEQC_PTR_ARG); - - //struct s_s *cxxSSassemblageComp2s_s(); - //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index aa3327dc..94f62222 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -80,99 +80,6 @@ cxxSSassemblageSS::~cxxSSassemblageSS() { } -#ifdef MOVE_TO_STRUCTURES -struct s_s * -cxxSSassemblageSS::cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > &el) - // - // Builds s_s structure from of cxxSSassemblageSS - // -{ - - // - // generate s_s structures - // - struct s_s *s_s_ptr = - (struct s_s *) P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct s_s))); - if (s_s_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - int j = 0; - for (std::map < std::string, cxxSSassemblageSS >::iterator it = el.begin(); - it != el.end(); ++it) - { - s_s_ptr[j].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); - if ((*it).second.name.size() <= 0) - { -#ifdef PHREEQC_CLASS - P_INSTANCE_POINTER error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); -#else - ::error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); -#endif - - } - assert((*it).second.name.size() > 0); - //s_s_ptr[j].total_moles = it->total_moles; - s_s_ptr[j].total_moles = 0; - s_s_ptr[j].dn = 0; - s_s_ptr[j].a0 = (*it).second.a0; - s_s_ptr[j].a1 = (*it).second.a1; - s_s_ptr[j].ag0 = (*it).second.ag0; - s_s_ptr[j].ag1 = (*it).second.ag1; - //s_s_ptr[j].ag0 = 0; - //s_s_ptr[j].ag1 = 0; - s_s_ptr[j].s_s_in = TRUE; - s_s_ptr[j].miscibility = (*it).second.miscibility; - //s_s_ptr[j].spinodal = it->spinodal; - s_s_ptr[j].spinodal = FALSE; - //s_s_ptr[j].tk = it->tk; - s_s_ptr[j].tk = 273.15; - s_s_ptr[j].xb1 = (*it).second.xb1; - s_s_ptr[j].xb2 = (*it).second.xb2; - s_s_ptr[j].input_case = 0; - s_s_ptr[j].p[0] = 0; - s_s_ptr[j].p[1] = 0; - s_s_ptr[j].p[2] = 0; - s_s_ptr[j].p[3] = 0; - // - // generate s_s_comp structures - // - s_s_ptr[j].count_comps = (int) (*it).second.comps.size(); - s_s_ptr[j].comps = NULL; - if ((*it).second.comps.size() > 0) - { - int i = 0; - int n; - struct s_s_comp *s_s_comp_ptr = - (struct s_s_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) - ((*it).second.comps.size() * sizeof(struct s_s_comp))); - if (s_s_comp_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - for (cxxNameDouble::iterator itc = (*it).second.comps.begin(); - itc != (*it).second.comps.end(); ++itc) - { - s_s_comp_ptr[i].name = P_INSTANCE_POINTER string_hsave(itc->first.c_str()); - assert(itc->first.size() > 0); - s_s_comp_ptr[i].phase = P_INSTANCE_POINTER phase_bsearch(itc->first.c_str(), &n, TRUE); - s_s_comp_ptr[i].initial_moles = 0; - s_s_comp_ptr[i].moles = itc->second; - s_s_comp_ptr[i].init_moles = 0; - s_s_comp_ptr[i].delta = 0; - s_s_comp_ptr[i].fraction_x = 0; - s_s_comp_ptr[i].log10_lambda = 0; - s_s_comp_ptr[i].log10_fraction_x = 0; - s_s_comp_ptr[i].dn = 0; - s_s_comp_ptr[i].dnc = 0; - s_s_comp_ptr[i].dnb = 0; - i++; - } - s_s_ptr[j].comps = s_s_comp_ptr; - } - j++; - } - return (s_s_ptr); -} -#endif - #ifdef SKIP void cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const diff --git a/SSassemblageSS.h b/SSassemblageSS.h index e0213c07..c1eb1c5d 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -31,9 +31,6 @@ class cxxSSassemblageSS: public PHRQ_base SS_PARM_MARGULES = 9 }; - //static struct s_s *cxxSSassemblageSS2s_s(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSSassemblageSS > - // &el); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/Solution.cxx b/Solution.cxx index 55e972c9..2b9f095b 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -283,63 +283,6 @@ cxxSolution::~cxxSolution() { } -#ifdef MOVE_TO_STRUCTURES -struct solution * -cxxSolution::cxxSolution2solution(PHREEQC_PTR_ARG) - // - // Builds a solution structure from instance of cxxSolution - // -{ - - struct solution *solution_ptr = P_INSTANCE_POINTER solution_alloc(); - - solution_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - solution_ptr->n_user = this->n_user; - solution_ptr->n_user_end = this->n_user_end; - solution_ptr->new_def = FALSE; - solution_ptr->tc = this->tc; - solution_ptr->ph = this->ph; - solution_ptr->solution_pe = this->pe; - solution_ptr->mu = this->mu; - solution_ptr->ah2o = this->ah2o; - solution_ptr->total_h = this->total_h; - solution_ptr->total_o = this->total_o; - solution_ptr->cb = this->cb; - solution_ptr->mass_water = this->mass_water; - solution_ptr->total_alkalinity = this->total_alkalinity; - solution_ptr->density = 1.0; - solution_ptr->units = P_INSTANCE_POINTER moles_per_kilogram_string; - solution_ptr->default_pe = 0; - // pe_data - - // totals - solution_ptr->totals = - (struct conc *) P_INSTANCE_POINTER free_check_null(solution_ptr->totals); - solution_ptr->totals = this->totals.conc(P_INSTANCE); - - // master_activity - solution_ptr->master_activity = - (struct master_activity *) P_INSTANCE_POINTER free_check_null(solution_ptr-> - master_activity); - solution_ptr->master_activity = this->master_activity.master_activity(P_INSTANCE); - solution_ptr->count_master_activity = - (int) this->master_activity.size() + 1; - - // species_gamma - solution_ptr->species_gamma = this->species_gamma.master_activity(P_INSTANCE); - solution_ptr->count_species_gamma = (int) this->species_gamma.size(); - - // isotopes - solution_ptr->isotopes = - (struct isotope *) P_INSTANCE_POINTER free_check_null(solution_ptr->isotopes); - //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); - solution_ptr->isotopes = this->isotopes.cxxSolutionIsotopeList2isotope(P_INSTANCE); - solution_ptr->count_isotopes = (int) this->isotopes.size(); - - return (solution_ptr); -} -#endif - void cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const { diff --git a/Solution.h b/Solution.h index 5ec3f7c4..44cbf5c4 100644 --- a/Solution.h +++ b/Solution.h @@ -19,13 +19,10 @@ class cxxSolution:public cxxNumKeyword public: cxxSolution(PHRQ_io *io=NULL); cxxSolution(struct solution *, PHRQ_io *io=NULL); - //cxxSolution(PHREEQC_PTR_ARG_COMMA int n_user, PHRQ_io *io=NULL); cxxSolution( const std::map < int, cxxSolution > &solution_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSolution(); - //static cxxSolution& read(CParser& parser); - double Get_tc() const { return this->tc; @@ -149,9 +146,6 @@ class cxxSolution:public cxxNumKeyword double Get_master_activity(char *string) const; void Set_master_activity(char *string, double value); const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; - - //struct solution *cxxSolution2solution(PHREEQC_PTR_ARG); - void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 6e8290ae..3a34bc19 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -84,16 +84,6 @@ cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIs } #endif -#ifdef SKIP -std::string cxxSolutionIsotope::get_name() constconst -{ - std::ostringstream oss; - //std::ostrstream oss; - oss << this->isotope_number << this->elt_name; - return oss.str(); -} -#endif - void cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -226,21 +216,7 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const return (i < 0); return (this->isotope_number < isotope.isotope_number); } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct master * -cxxSolutionIsotope::master(PHREEQC_PTR_ARG) -{ - return (P_INSTANCE_POINTER master_bsearch(this->elt_name.c_str())); -} -#endif -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct master * -cxxSolutionIsotope::primary(PHREEQC_PTR_ARG) -{ - char * str = P_INSTANCE_POINTER string_hsave(this->elt_name.c_str()); - return (P_INSTANCE_POINTER master_bsearch_primary(str)); -} -#endif + void cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr, double intensive, double extensive) diff --git a/SolutionIsotope.h b/SolutionIsotope.h index 1aa1a063..e21ac555 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -13,15 +13,6 @@ class cxxSolutionIsotope: public PHRQ_base cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io=NULL); ~cxxSolutionIsotope(void); - /* - enum STATUS { - ERROR = 0, - OK = 1 - }; - */ - //cxxSolutionIsotope::STATUS read(CParser& parser); - //static struct isotope *list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &t); - void dump_xml(std::ostream & os, unsigned int indent) const; void dump_raw(std::ostream & os, unsigned int indent) const; @@ -82,10 +73,6 @@ class cxxSolutionIsotope: public PHRQ_base } bool operator<(const cxxSolutionIsotope & conc) const; - - //struct master *master(PHREEQC_PTR_ARG); - //struct master *primary(PHREEQC_PTR_ARG); - void add(const cxxSolutionIsotope & isotope_ptr, double intensive, double extensive); void multiply(double extensive); diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 31a8f72a..468d8c20 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -88,36 +88,4 @@ cxxSolutionIsotopeList::multiply(double extensive) it->total *= extensive; } } -#ifdef MOVE_TO_STRUCTURES -struct isotope * -cxxSolutionIsotopeList::cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG) -{ - struct isotope *iso; - if (this->size() <= 0) - { - return NULL; - } - else - { - iso = - (struct isotope *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((this->size()) * sizeof(struct isotope))); - if (iso == NULL) - P_INSTANCE_POINTER malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::iterator it = this->begin(); - it != this->end(); ++it) - { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = P_INSTANCE_POINTER string_hsave(it->elt_name.c_str()); - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(P_INSTANCE); - iso[i].primary = it->primary(P_INSTANCE); - i++; - } - } - return (iso); -} -#endif + diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index b0ede907..6de61a5a 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -18,7 +18,6 @@ public: ~cxxSolutionIsotopeList(); - //struct isotope * cxxSolutionIsotopeList2isotope(PHREEQC_PTR_ARG); void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); void multiply(double extensive); diff --git a/StorageBin.cxx b/StorageBin.cxx index 8f02947e..2849d492 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -48,75 +48,7 @@ PHRQ_base(io) // default constructor for cxxStorageBin this->system.Set_io(io); } -#ifdef SKIP -cxxStorageBin::cxxStorageBin(struct Use *use_ptr) -{ - //Construct from use pointer - // Solution - if (use_ptr->solution_ptr != NULL) - { - cxxSolution entity(use_ptr->solution_ptr); - this->setSolution(use_ptr->n_solution_user, &entity); - } - // Exchange - if (use_ptr->exchange_ptr != NULL) - { - cxxExchange entity(use_ptr->exchange_ptr); - this->setExchange(use_ptr->n_exchange_user, &entity); - } - // gas_phase - if (use_ptr->gas_phase_ptr != NULL) - { - cxxGasPhase entity(use_ptr->gas_phase_ptr); - this->setGasPhase(use_ptr->n_gas_phase_user, &entity); - } - // kinetics - if (use_ptr->kinetics_ptr != NULL) - { - cxxKinetics entity(use_ptr->kinetics_ptr); - this->setKinetics(use_ptr->n_kinetics_user, &entity); - } - // pp_assemblage - if (use_ptr->pp_assemblage_ptr != NULL) - { - cxxPPassemblage entity(use_ptr->pp_assemblage_ptr); - this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); - } - // s_s_assemblage - if (use_ptr->s_s_assemblage_ptr != NULL) - { - cxxSSassemblage entity(use_ptr->s_s_assemblage_ptr); - this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); - } - // surface - if (use_ptr->surface_ptr != NULL) - { - cxxSurface entity(use_ptr->surface_ptr); - this->setSurface(use_ptr->n_surface_user, &entity); - } - // mix - if (use_ptr->mix_ptr != NULL) - { - cxxMix entity(use_ptr->mix_ptr); - this->setMix(use_ptr->n_mix_user, &entity); - } - // reaction - if (use_ptr->irrev_ptr != NULL) - { - cxxReaction entity(use_ptr->irrev_ptr); - this->setReaction(use_ptr->n_irrev_user, &entity); - } - // reaction temperature - if (use_ptr->temperature_ptr != NULL) - { - cxxTemperature entity(use_ptr->temperature_ptr); - this->setTemperature(use_ptr->n_temperature_user, &entity); - } - // set system - this->setSystem(use_ptr); -} -#endif cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io * io) : PHRQ_base(io) @@ -1530,19 +1462,6 @@ cxxStorageBin::mpi_recv(int task_number) MPI_DOUBLE, MPI_COMM_WORLD); } buffer = free_check_null(buffer); -#ifdef SKIP - for (int j = 0; j < count_ints; j++) - { - std::cerr << "Recving ints " << j << " value " << ints[j] << std:: - endl; - } - for (int j = 0; j < count_doubles; j++) - { - std:: - cerr << "Recving doubles " << j << " value " << doubles[j] << - std::endl; - } -#endif /* * Make list of list of ints and doubles from solution structure * This list is not the complete structure, but only enough diff --git a/Surface.cxx b/Surface.cxx index f65dc167..86d0e655 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -143,82 +143,6 @@ cxxSurface::Get_related_rate() return (false); } -#ifdef MOVE_TO_STRUCTURES -struct surface * -cxxSurface::cxxSurface2surface(PHREEQC_PTR_ARG) - // - // Builds a surface structure from instance of cxxSurface - // -{ - struct surface *surface_ptr = P_INSTANCE_POINTER surface_alloc(); - - surface_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - surface_ptr->n_user = this->n_user; - surface_ptr->n_user_end = this->n_user_end; - surface_ptr->new_def = FALSE; - surface_ptr->type = this->type; - surface_ptr->dl_type = this->dl_type; - surface_ptr->sites_units = this->sites_units; - //surface_ptr->diffuse_layer = this->diffuse_layer; - //surface_ptr->edl = this->edl; - surface_ptr->only_counter_ions = this->only_counter_ions; - //surface_ptr->donnan = this->donnan; - surface_ptr->thickness = this->thickness; - surface_ptr->debye_lengths = 1.0; - surface_ptr->solution_equilibria = FALSE; - surface_ptr->n_solution = -2; - surface_ptr->related_phases = (int) this->get_related_phases(); - surface_ptr->related_rate = (int) this->get_related_rate(); - surface_ptr->transport = this->transport; - surface_ptr->debye_lengths = this->debye_lengths; - surface_ptr->DDL_viscosity = this->DDL_viscosity; - surface_ptr->DDL_limit = this->DDL_limit; - - // Surface comps - surface_ptr->count_comps = (int) this->surfaceComps.size(); - surface_ptr->comps = - (struct surface_comp *) P_INSTANCE_POINTER free_check_null(surface_ptr->comps); - surface_ptr->comps = - cxxSurfaceComp::cxxSurfaceComp2surface_comp(P_INSTANCE_COMMA this->surfaceComps); - - // Surface charge - surface_ptr->charge = - (struct surface_charge *) P_INSTANCE_POINTER free_check_null(surface_ptr->charge); - //if (surface_ptr->edl == TRUE) { - if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) - { - surface_ptr->count_charge = (int) this->surfaceCharges.size(); - surface_ptr->charge = - cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(P_INSTANCE_COMMA this->surfaceCharges); - } - else - { - surface_ptr->count_charge = 0; - } - // Need to fill in charge (number) in comps list - if (surface_ptr->type != NO_EDL) - { - int i, j; - for (i = 0; i < surface_ptr->count_comps; i++) - { - char *charge_name = P_INSTANCE_POINTER string_hsave( - cxxSurfaceComp::get_charge_name(P_INSTANCE_COMMA surface_ptr->comps[i].formula).c_str()); - for (j = 0; j < surface_ptr->count_charge; j++) - { - if (charge_name == surface_ptr->charge[j].name) - { - surface_ptr->comps[i].charge = j; - break; - } - } - assert(j < surface_ptr->count_charge); - } - } - - return (surface_ptr); -} -#endif - void cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -516,31 +440,6 @@ cxxSurface::read_raw(CParser & parser, bool check) cxxSurfaceComp ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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_stream(eo_s); - parser.seekg(pos).clear(); - parser.seekg(pos); - - if (this->surfaceComps.find(ec.get_formula()) != this->surfaceComps.end()) - { - cxxSurfaceComp & comp = this->surfaceComps.find(ec.get_formula())->second; - comp.read_raw(parser, false); - } - else - { - cxxSurfaceComp ec1; - ec1.read_raw(parser, false); - std::string str(ec1.get_formula()); - this->surfaceComps[str] = ec1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); @@ -569,31 +468,6 @@ cxxSurface::read_raw(CParser & parser, bool check) cxxSurfaceCharge ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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_stream(eo_s); - parser.seekg(pos).clear(); - parser.seekg(pos); - - if (this->surfaceCharges.find(ec.get_name()) != this->surfaceCharges.end()) - { - cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.get_name())->second; - comp.read_raw(parser, false); - } - else - { - cxxSurfaceCharge ec1; - ec1.read_raw(parser, false); - std::string str(ec1.get_name()); - this->surfaceCharges[str] = ec1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); @@ -880,100 +754,7 @@ cxxSurface::totalize() } return; } -#ifdef SKIP -void -cxxSurface::add(const cxxSurface & addee, double extensive) - // - // Add surface to "this" exchange - // -{ - //std::list surfaceComps; - //std::list surfaceCharges; - //enum SURFACE_TYPE type; - //enum DIFFUSE_LAYER_TYPE dl_type; - //enum SITES_UNITS sites_units; - //bool only_counter_ions; - //double thickness; - //double debye_lengths; - //double DDL_viscosity; - //double DDL_limit; - //bool transport; - if (extensive == 0.0) - return; - if (this->surfaceComps.size() == 0) - { - //enum SURFACE_TYPE type; - this->type = addee.type; - //enum DIFFUSE_LAYER_TYPE dl_type; - this->dl_type = addee.dl_type; - //enum SITES_UNITS sites_units; - this->sites_units = addee.sites_units; - //bool only_counter_ions; - this->only_counter_ions = addee.only_counter_ions; - //double thickness; - this->thickness = addee.thickness; - //double debye_lengths; - this->debye_lengths = addee.debye_lengths; - //double DDL_viscosity; - this->DDL_viscosity = addee.DDL_viscosity; - //double DDL_limit; - this->DDL_limit = addee.DDL_limit; - //bool transport; - this->transport = addee.transport; - } - //std::list surfaceComps; - for (std::list < cxxSurfaceComp >::const_iterator itadd = - addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); - ++itadd) - { - bool found = false; - for (std::list < cxxSurfaceComp >::iterator it = - this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) - { - if (it->get_formula() == itadd->get_formula()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) - { - cxxSurfaceComp entity = *itadd; - entity.multiply(extensive); - //exc.add(*itadd, extensive); - this->surfaceComps.push_back(entity); - } - } - //std::list surfaceCharges; - for (std::list < cxxSurfaceCharge >::const_iterator itadd = - addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); - ++itadd) - { - bool found = false; - for (std::list < cxxSurfaceCharge >::iterator it = - this->surfaceCharges.begin(); it != this->surfaceCharges.end(); - ++it) - { - if (it->get_name() == itadd->get_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) - { - cxxSurfaceCharge entity = *itadd; - entity.multiply(extensive); - //exc.add(*itadd, extensive); - this->surfaceCharges.push_back(entity); - } - } - -} -#endif void cxxSurface::add(const cxxSurface & addee, double extensive) // diff --git a/Surface.h b/Surface.h index f97dcf69..aec54ad2 100644 --- a/Surface.h +++ b/Surface.h @@ -22,14 +22,6 @@ class cxxSurface:public cxxNumKeyword int n_user, PHRQ_io *io=NULL); ~cxxSurface(); - //enum SURFACE_STYPE { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC }; - //enum SURFACE_DL_TYPE { NO_DL, BORKOVEC_DL, DONNAN_DL } ; - //enum SURFACE_SITES_UNITS { SITES_ABSOLUTE, SITES_DENSITY } ; - - //struct surface *cxxSurface2surface(PHREEQC_PTR_ARG); - - //struct surf_comp *cxxSurfaceComp2surf_comp(PHREEQC_PTR_ARG); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index ea0260e2..a60de6de 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -86,48 +86,6 @@ cxxSurfaceCharge::~cxxSurfaceCharge() // return (master_ptr); //} -#ifdef MOVE_TO_STRUCTURES -struct surface_charge * -cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el) - // - // Builds surface_charge structure from of cxxSurfaceCharge - // -{ - struct surface_charge *surf_charge_ptr = - (struct surface_charge *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge))); - if (surf_charge_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - int i = 0; - for (std::map < std::string, cxxSurfaceCharge >::iterator it = el.begin(); - it != el.end(); ++it) - { - surf_charge_ptr[i].name = P_INSTANCE_POINTER string_hsave((*it).second.name.c_str()); - assert((*it).second.name.size() > 0); - surf_charge_ptr[i].specific_area = (*it).second.specific_area; - surf_charge_ptr[i].grams = (*it).second.grams; - surf_charge_ptr[i].charge_balance = (*it).second.charge_balance; - surf_charge_ptr[i].mass_water = (*it).second.mass_water; - surf_charge_ptr[i].la_psi = (*it).second.la_psi; - surf_charge_ptr[i].la_psi1 = (*it).second.la_psi1; - surf_charge_ptr[i].la_psi2 = (*it).second.la_psi2; - surf_charge_ptr[i].capacitance[0] = (*it).second.capacitance[0]; - surf_charge_ptr[i].capacitance[1] = (*it).second.capacitance[1]; - surf_charge_ptr[i].sigma0 = 0; - surf_charge_ptr[i].sigma1 = 0; - surf_charge_ptr[i].sigma2 = 0; - surf_charge_ptr[i].sigmaddl = 0; - surf_charge_ptr[i].diffuse_layer_totals = (*it).second.diffuse_layer_totals.elt_list(P_INSTANCE); - //surf_charge_ptr[i].psi_master = it->get_psi_master(); - surf_charge_ptr[i].count_g = 0; - surf_charge_ptr[i].g = NULL; - i++; - } - return (surf_charge_ptr); -} -#endif - void cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const { diff --git a/SurfaceCharge.h b/SurfaceCharge.h index b2cafbd9..116f2f6c 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -22,9 +22,7 @@ public: struct master *get_psi_master(); - - //static struct surface_charge *cxxSurfaceCharge2surface_charge(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceCharge > &el); - + void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 3b0b0af3..5f6439c8 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -66,89 +66,6 @@ totals(surf_comp_ptr->totals) cxxSurfaceComp::~cxxSurfaceComp() { } -#ifdef MOVE_TO_STRUCTURES -struct master * - cxxSurfaceComp::get_master(PHREEQC_PTR_ARG) -{ - struct master *master_ptr = NULL; - //for (std::map ::iterator it = totals.begin(); it != totals.end(); it++) { - for (cxxNameDouble::iterator it = this->totals.begin(); - it != this->totals.end(); it++) - { - /* Find master species */ - char *eltName = P_INSTANCE_POINTER string_hsave(it->first.c_str()); - assert(it->first.size() > 0); - struct element *elt_ptr = P_INSTANCE_POINTER element_store(eltName); - if (elt_ptr->master == NULL) - { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr-> - name << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); - return (NULL); - } - if (elt_ptr->master->type != SURF) - continue; - master_ptr = elt_ptr->master; - break; - } - if (master_ptr == NULL) - { - std::ostringstream error_oss; - error_oss << - "Surface formula does not contain an surface master species, " << - this->formula << std::endl; - //Utilities::error_msg(error_oss.str(), CONTINUE); - error_msg(error_oss.str().c_str(), CONTINUE); - } - return (master_ptr); -} -#endif - -#ifdef MOVE_TO_STRUCTURES -struct surface_comp * - cxxSurfaceComp::cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el) - // - // Builds surface_comp structure from of cxxSurfaceComp - // -{ - struct surface_comp *surf_comp_ptr = - (struct surface_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp))); - if (surf_comp_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - int i = 0; - for (std::map < std::string, cxxSurfaceComp >::iterator it = el.begin(); - it != el.end(); ++it) - { - surf_comp_ptr[i].formula = P_INSTANCE_POINTER string_hsave((*it).second.formula.c_str()); - assert((*it).second.formula.size() > 0); - surf_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list(P_INSTANCE); - surf_comp_ptr[i].formula_z = (*it).second.formula_z; - surf_comp_ptr[i].moles = (*it).second.moles; - surf_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); - surf_comp_ptr[i].totals = (*it).second.totals.elt_list(P_INSTANCE); - surf_comp_ptr[i].la = (*it).second.la; - //surf_comp_ptr[i].charge = it->charge_number; - surf_comp_ptr[i].cb = (*it).second.charge_balance; - if ((*it).second.phase_name.size() == 0) - surf_comp_ptr[i].phase_name = NULL; - else - surf_comp_ptr[i].phase_name = P_INSTANCE_POINTER string_hsave((*it).second.phase_name.c_str()); - surf_comp_ptr[i].phase_proportion = (*it).second.phase_proportion; - if ((*it).second.rate_name.size() == 0) - surf_comp_ptr[i].rate_name = NULL; - else - surf_comp_ptr[i].rate_name = P_INSTANCE_POINTER string_hsave((*it).second.rate_name.c_str()); - surf_comp_ptr[i].Dw = (*it).second.Dw; - surf_comp_ptr[i].master = (*it).second.get_master(P_INSTANCE); - i++; - } - return (surf_comp_ptr); -} -#endif void cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const @@ -727,25 +644,3 @@ cxxSurfaceComp::Get_formula_totals() const { return (this->formula_totals); } -#ifdef MOVE_TO_STRUCTURES -std::string -cxxSurfaceComp::charge_name(PHREEQC_PTR_ARG) -{ - char * str = P_INSTANCE_POINTER string_hsave(this->formula.c_str()); - return (get_charge_name(P_INSTANCE_COMMA str)); -} -std::string -cxxSurfaceComp::get_charge_name(PHREEQC_PTR_ARG_COMMA char *token) -{ - char name[100]; - int l; - char *ptr1 = token; - P_INSTANCE_POINTER get_elt(&ptr1, name, &l); - ptr1 = strchr(name, '_'); - if (ptr1 != NULL) - { - ptr1[0] = '\0'; - } - return (std::string(name)); -} -#endif \ No newline at end of file diff --git a/SurfaceComp.h b/SurfaceComp.h index cad1e064..0064c9f2 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -18,7 +18,6 @@ public: cxxSurfaceComp(struct surface_comp *, PHRQ_io *io=NULL); ~cxxSurfaceComp(); - //struct master *get_master(PHREEQC_PTR_ARG); const std::string &Get_phase_name() const; void Set_phase_name(char * f); const std::string &Get_rate_name() const; @@ -27,7 +26,6 @@ public: void Set_formula(char * f); double Get_charge_balance() const; void Set_charge_balance(double d); - //static struct surface_comp *cxxSurfaceComp2surface_comp(PHREEQC_PTR_ARG_COMMA std::map < std::string, cxxSurfaceComp > &el); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); @@ -40,8 +38,7 @@ public: double Get_Dw(void) const {return Dw;}; void add(const cxxSurfaceComp & comp, double extensive); void multiply(double extensive); - //std::string charge_name(PHREEQC_PTR_ARG); - //static std::string get_charge_name(PHREEQC_PTR_ARG_COMMA char *token); + #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/Temperature.cxx b/Temperature.cxx index 8500829b..d2161f16 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -71,46 +71,6 @@ cxxTemperature::~cxxTemperature() { } -#ifdef MOVE_TO_STRUCTURES -struct temperature * -cxxTemperature::cxxTemperature2temperature(PHREEQC_PTR_ARG) - // - // Builds a temperature structure from instance of cxxTemperature - // -{ - struct temperature *temperature_ptr; - temperature_ptr = - (struct temperature *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct temperature)); - if (temperature_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - temperature_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - temperature_ptr->n_user = this->n_user; - temperature_ptr->n_user_end = this->n_user_end; - - // temps - temperature_ptr->t = NULL; - if (this->temps.size() > 0) - { - temperature_ptr->t = - (LDBLE *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->temps.size() * sizeof(double))); - if (temperature_ptr->t == NULL) - P_INSTANCE_POINTER malloc_error(); - std::copy(this->temps.begin(), this->temps.end(), temperature_ptr->t); - } - if (this->equalIncrements) - { - temperature_ptr->count_t = -(int) this->countTemps; - } - else - { - temperature_ptr->count_t = (int) this->temps.size(); - } - return (temperature_ptr); -} -#endif - #ifdef SKIP void cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const diff --git a/Utils.cxx b/Utils.cxx index 3027776c..e3607b8a 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -92,17 +92,6 @@ Utilities::squeeze_white(std::string & s_l) s_l = str; } -#ifdef SKIP -//////////////////////////////////////////////////////////////////////////// -void -Utilities::error_msg(const std::string & err_str, const int stop) -//////////////////////////////////////////////////////////////////////////// -{ - //std::cerr << err_str << std::endl; - output_message(OUTPUT_ERROR, err_str, stop, "", args); -} -#endif - //+NAN double: 7ff8000000000000 //-NAN double: fff8000000000000 /* diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index eaaef8c1..cf0c9305 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -117,64 +117,6 @@ cxxKinetics::~cxxKinetics() { } -#ifdef MOVE_TO_STRUCTURES -struct kinetics * -cxxKinetics::cxxKinetics2kinetics(PHREEQC_PTR_ARG) - // - // Builds a kinetics structure from instance of cxxKinetics - // -{ - struct kinetics *kinetics_ptr = P_INSTANCE_POINTER kinetics_alloc(); - - kinetics_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - kinetics_ptr->n_user = this->n_user; - kinetics_ptr->n_user_end = this->n_user_end; - kinetics_ptr->step_divide = this->step_divide; - kinetics_ptr->rk = this->rk; - kinetics_ptr->bad_step_max = this->bad_step_max; - kinetics_ptr->use_cvode = (int) this->use_cvode; - kinetics_ptr->cvode_steps = this->cvode_steps; - kinetics_ptr->cvode_order = this->cvode_order; - - // totals - kinetics_ptr->totals = this->totals.elt_list(P_INSTANCE); - - // comps - kinetics_ptr->count_comps = (int) this->kineticsComps.size(); - kinetics_ptr->comps = - (struct kinetics_comp *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->comps); - kinetics_ptr->comps = - cxxKineticsComp::cxxKineticsComp2kinetics_comp(P_INSTANCE_COMMA this->kineticsComps); - - // steps - if (this->equal_steps == 0) - { - kinetics_ptr->count_steps = (int) this->steps.size(); - } - else - { - kinetics_ptr->count_steps = -this->equal_steps; - } - kinetics_ptr->steps = (LDBLE *) P_INSTANCE_POINTER free_check_null(kinetics_ptr->steps); - if (this->steps.size() > 0) - { - kinetics_ptr->steps = - (LDBLE *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) (this->steps.size() * sizeof(double))); - if (kinetics_ptr->steps == NULL) - P_INSTANCE_POINTER malloc_error(); - std::copy(this->steps.begin(), this->steps.end(), - kinetics_ptr->steps); - /* - int i = 0; - for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { - kinetics_ptr->steps[i] = *it; - } - */ - } - return (kinetics_ptr); -} -#endif #ifdef SKIP void cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -412,31 +354,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) cxxKineticsComp ec(this->Get_io()); // preliminary read -#ifdef SKIP - 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_stream(eo_s); - parser.seekg(pos).clear(); - parser.seekg(pos); - - if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) - { - cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; - comp.read_raw(parser, false); - } - else - { - cxxKineticsComp ec1; - ec1.read_raw(parser, false); - std::string str(ec1.get_rate_name()); - this->kineticsComps[str] = ec1; - } -#endif parser.set_accumulate(true); ec.read_raw(parser, false); parser.set_accumulate(false); @@ -682,54 +599,6 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) *dd = d; } #endif -#ifdef SKIP -void -cxxKinetics::add(const cxxKinetics & addee, double extensive) - // - // Add to existing ppassemblage to "this" ppassemblage - // -{ - if (extensive == 0.0) - return; - //std::list kineticsComps; - for (std::list < cxxKineticsComp >::const_iterator itadd = - addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); - ++itadd) - { - bool found = false; - for (std::list < cxxKineticsComp >::iterator it = - this->kineticsComps.begin(); it != this->kineticsComps.end(); - ++it) - { - if (it->get_rate_name() == itadd->get_rate_name()) - { - it->add((*itadd), extensive); - found = true; - break; - } - } - if (!found) - { - cxxKineticsComp entity = *itadd; - entity.multiply(extensive); - this->kineticsComps.push_back(entity); - } - } - //std::vector steps; - this->steps = addee.steps; - //cxxNameDouble totals; - //double step_divide; - this->step_divide = addee.step_divide; - //int rk; - this->rk = addee.rk; - //int bad_step_max; - this->bad_step_max = addee.bad_step_max; - //bool use_cvode; - this->use_cvode = addee.use_cvode; - this->cvode_steps = addee.cvode_steps; - this->cvode_order = addee.cvode_order; -} -#endif void cxxKinetics::add(const cxxKinetics & addee, double extensive) // diff --git a/cxxMix.cxx b/cxxMix.cxx index 47db4b8e..57be1b85 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -59,46 +59,6 @@ cxxMix::~cxxMix() { } -#ifdef MOVE_TO_STRUCTURES -struct mix * -cxxMix::cxxMix2mix(PHREEQC_PTR_ARG) - // - // Builds a mix structure from instance of cxxMix - // -{ - struct mix *mix_ptr; - mix_ptr = (struct mix *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct mix)); - if (mix_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); - - mix_ptr->description = P_INSTANCE_POINTER string_duplicate (this->get_description().c_str()); - mix_ptr->n_user = this->n_user; - mix_ptr->n_user_end = this->n_user_end; - - // comps - mix_ptr->comps = NULL; - if (this->mixComps.size() > 0) - { - int i = 0; - mix_ptr->comps = - (struct mix_comp *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) - (this->mixComps.size() * sizeof(struct mix_comp))); - if (mix_ptr->comps == NULL) - P_INSTANCE_POINTER malloc_error(); - for (std::map < int, double >::iterator it = mixComps.begin(); - it != mixComps.end(); it++) - { - mix_ptr->comps[i].n_solution = it->first; - mix_ptr->comps[i].fraction = it->second; - i++; - } - } - mix_ptr->count_comps = (int) this->mixComps.size(); - return (mix_ptr); -} -#endif - #ifdef SKIP void cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const diff --git a/dumper.cpp b/dumper.cpp index 91379327..b233426d 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -29,219 +29,7 @@ void dumper::SetAll(bool tf) this->binList.SetAll(tf); } -#ifdef SKIP -bool dumper::Read(CParser & parser) -{ - bool return_value(true); - static std::vector < std::string > vopts; - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("solution"); - vopts.push_back("pp_assemblage"); - vopts.push_back("equilibrium_phases"); - vopts.push_back("exchange"); - vopts.push_back("surface"); - vopts.push_back("s_s_assemblage"); - vopts.push_back("gas_phase"); - vopts.push_back("kinetics"); - vopts.push_back("file"); - vopts.push_back("append"); - vopts.push_back("all"); - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); - - // Read mix number and description - //this->read_number_description(parser); - - opt_save = CParser::OPT_DEFAULT; - - 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; - } - else - { - opt_save = opt; - } - std::set < int > accumulator; - - // Read list of numbers or number ranges for line - if (opt >= 0 && opt <= 7) - { - for (;;) - { - CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - std::set < int > temp_set; - int i; - if (j == CParser::TT_EMPTY) - { - break; - } - else if (j == CParser::TT_DIGIT) - { - std::replace(token.begin(), token.end(), '-', ' '); - //if (token.find_last_of("-") != token.end()) - //{ - // token.replace(token.find_last_of("-"), token.find_last_of("-") + 1, " "); - //} - - std::istringstream iss(token); - if (iss >> i) - { - temp_set.insert(i); - if (iss >> i) - { - temp_set.insert(i); - } - } - if (temp_set.size() == 1) - { - accumulator.insert(*(temp_set.begin())); - } - else if (temp_set.size() == 2) - { - int i1, i2; - std::set ::iterator it; - it = temp_set.begin(); - i1 = *it; - it++; - i2 = *it; - for (i = i1; i <= i2; i++) - { - accumulator.insert(i); - } - } - else - { - parser.error_msg("Expected positive integers for dump range.", - CParser::OT_CONTINUE); - } - } - else - { - parser.error_msg("Expected single number or range of numbers.", - CParser::OT_CONTINUE); - } - } - } - - // Process identifiers - std::set < int >::iterator it; - 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 reading DUMP definition.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - return_value = false; - break; - case 0: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->solution.insert(*it); - } - this->bool_solution = true; - break; - case 1: - case 2: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->pp_assemblage.insert(*it); - } - this->bool_pp_assemblage = true; - break; - case 3: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->exchange.insert(*it); - } - this->bool_exchange = true; - break; - case 4: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->surface.insert(*it); - } - this->bool_surface = true; - break; - case 5: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->s_s_assemblage.insert(*it); - } - this->bool_s_s_assemblage = true; - break; - case 6: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->gas_phase.insert(*it); - } - this->bool_gas_phase = true; - break; - case 7: - for (it = accumulator.begin(); it != accumulator.end(); it++) - { - this->kinetics.insert(*it); - } - this->bool_kinetics = true; - break; - case 8: //file - std::getline(parser.get_iss(), this->file_name); - this->file_name = trim(this->file_name, " \t"); - if (this->file_name.size() == 0) - { - this->file_name = "dump.out"; - } - - break; - case 9: //append - { - CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - //if (!(parser.get_iss() >> this->append)) - this->append = true; - if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') - { - this->append = false; - } - } - break; - case 10: //all - this->DumpAll(true); - break; - } - - - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } - return(return_value); -} -#endif bool dumper::Read(CParser & parser) { From 6acf05a1a0dadf5b4621d41a443aef12535ba289 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 28 Sep 2011 22:30:46 +0000 Subject: [PATCH 0260/1077] Removed ORCHESTRA git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5658 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.h | 1 + ISolution.cxx | 591 --------------------------------------------- NameDouble.h | 1 - PPassemblage.cxx | 92 ------- PPassemblage.h | 9 - PPassemblageComp.h | 1 + SSassemblage.h | 2 + SSassemblageSS.h | 1 + Solution.h | 9 +- StorageBin.cxx | 16 +- StorageBin.h | 4 - System.cxx | 370 ---------------------------- System.h | 13 +- 13 files changed, 9 insertions(+), 1101 deletions(-) diff --git a/GasPhase.h b/GasPhase.h index 4b3c4649..eb5f96dc 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -9,6 +9,7 @@ #include "NumKeyword.h" #include "NameDouble.h" +#include "phreeqc_class.h" class cxxMix; class cxxGasPhase:public cxxNumKeyword diff --git a/ISolution.cxx b/ISolution.cxx index 42231990..582776df 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -20,9 +20,6 @@ #include "phrqproto.h" #include "output.h" -#ifdef ORCHESTRA -extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); -#endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -460,591 +457,3 @@ cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const os << "" << "\n"; } #endif - -#ifdef ORCHESTRA -void -cxxISolution::ORCH_write_chemistry(std::ostream & chemistry_dat) -{ - this->ORCH_write_chemistry_water(chemistry_dat); - this->ORCH_write_chemistry_primary(chemistry_dat); - this->ORCH_write_chemistry_total_O_H(chemistry_dat); - this->ORCH_write_chemistry_alkalinity(chemistry_dat); - ORCH_write_chemistry_species(chemistry_dat); - this->ORCH_write_chemistry_minerals(chemistry_dat); -} - - -void -cxxISolution::ORCH_write_chemistry_water(std::ostream & chemistry_dat) -{ - // - // Write water entities - // - chemistry_dat << std::endl << "//********* The water entities" << std:: - endl; - - // e- - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - if (this->comps.find("E") == this->comps.end() - || this->comps.find("E")->second.get_equation_name() == NULL) - { - // fixed pe - chemistry_dat << "@Calc: (1, \"e-.act = 10^-pe\")" << std::endl; - - } - else if (this->comps.find("E")->second.get_equation_name() == - string_hsave("charge")) - { - // charge balance - chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; - chemistry_dat << - "@solve (e-.act, 1e-6, log, 1, chargebalance, 1e-14)" << std:: - endl; - } - else - { - // adjust to equilbirium with a phase - chemistry_dat << "@Calc: (1, \"pe = -log10({e-.act})\")" << std::endl; - int n; - struct phase *phase_ptr = - phase_bsearch(this->comps.find("E)")->second.get_equation_name(), - &n, FALSE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@solve (e-.act, 1e-6, log, 1, " << phase_name. - c_str() << ".si_raw, 1e-9)" << std::endl; - } - - // H+ - if (this->comps.find("H(1)") == this->comps.end() - || this->comps.find("H(1)")->second.get_equation_name() == NULL) - { - // fixed pH - chemistry_dat << "@Calc: (1, \"H+.act = 10^-pH\")" << std::endl; - - } - else if (this->comps.find("H(1)")->second.get_equation_name() == - string_hsave("charge")) - { - // charge balance - chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; - chemistry_dat << - "@solve (H+.act, 1e-6, log, 1, chargebalance, 1e-14)" << std:: - endl; - } - else - { - // adjust to equilbirium with a phase - chemistry_dat << "@Calc: (1, \"pH = -log10({H+.act})\")" << std::endl; - int n; - struct phase *phase_ptr = - phase_bsearch(this->comps.find("H(1)")->second. - get_equation_name(), &n, FALSE); - assert(phase_ptr != NULL); - chemistry_dat << "@solve (H+.act, 1e-6, log, 1, " << phase_ptr-> - name << ".si_raw, 1e-9)" << std::endl; - } - - // H2O - chemistry_dat << "@entity(" << s_h2o-> - name << ", diss, 55.506)" << std::endl; - chemistry_dat << std::endl; -} - -void -cxxISolution::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) -{ - chemistry_dat << std::endl << "//********* The primary species" << std:: - endl; - // - // Write other master species definitions, i.e. primary entities - // - std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); - chemistry_dat << "@species(H+, 1)" << std::endl; - for (; iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") - continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> - z << ")" << std::endl; - if (iter->second.get_equation_name() == NULL) - { - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr-> - name << ", 1e-9, diss, 1.0e-9)" << std::endl; - } - else - { - std::string eqn(iter->second.get_equation_name()); - if (eqn == "charge") - { - // charge balance - chemistry_dat << "@solve (" << s_ptr-> - name << ".act, 1e-6, log, 1, chargebalance, 1e-9)" << - std::endl; - } - else - { - // adjust to phase equilibrium - int n; - struct phase *phase_ptr = - phase_bsearch(eqn.c_str(), &n, FALSE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@solve (" << s_ptr-> - name << ".act, 1e-6, log, 1, " << phase_name << - ".si_raw, 1e-9)" << std::endl; - } - } - } - chemistry_dat << std::endl; -} - -void -cxxISolution::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) -{ - chemistry_dat << std:: - endl << "//********* Define total hydrogen and oxygen" << std::endl; - // Define total hydrogen, total oxygen, and difference - //chemistry_dat << "@var: total_diff 0" << std::endl; - //chemistry_dat << "@calc: (5, \"total_diff = total_hydrogen - 2*total_oxygen" << "\")" << std::endl; - - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - int i; - for (i = 0; i < count_s_x; i++) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL && s_x[i]->secondary->in == TRUE)) - { - if (s_x[i]->h != 0) - { - chemistry_dat << "+"; - if (s_x[i]->h != 1) - { - chemistry_dat << s_x[i]->h << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".diss}"; - } - } - } - chemistry_dat << "\")" << std::endl; - - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->o != 0) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - { - chemistry_dat << "+"; - if (s_x[i]->o != 1) - { - chemistry_dat << s_x[i]->o << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".diss}"; - } - } - } - chemistry_dat << "\")" << std::endl; - chemistry_dat << std::endl; -} - -void -cxxISolution::ORCH_write_chemistry_alkalinity(std::ostream & chemistry_dat) -{ - chemistry_dat << std:: - endl << "//********* Alkalinity definitions" << std::endl; - // - // Define alkalinity - // - chemistry_dat << "@Var: Alkalinity 0" << std::endl; - chemistry_dat << "@calc: (5, \"Alkalinity = 0"; - for (int i = 0; i < count_s_x; i++) - { - if (s_x[i]->alk == 0) - continue; - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - if (s_x[i]->alk < 0) - { - if (s_x[i]->alk != -1) - { - chemistry_dat << s_x[i]->alk << "*{" << name << ".con}"; - } - else - { - chemistry_dat << "-{" << name << ".con}"; - } - } - else if (s_x[i]->alk > 0) - { - if (s_x[i]->alk != 1) - { - chemistry_dat << "+" << s_x[i]-> - alk << "*{" << name << ".con}"; - } - else - { - chemistry_dat << "+{" << name << ".con}"; - } - } - } - chemistry_dat << "\")" << std::endl; - // - // Alkalinity (or pH) equation - // - std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); - if ((iter = this->comps.find("Alkalinity")) != this->comps.end()) - { - if ((this->comps.find("C(4)") != this->comps.end()) - || (this->comps.find("C") != this->comps.end())) - { - if (this->comps.find("H(1)") != this->comps.end()) - { - std::ostringstream oss; - oss << - "pH can not be adjusted to charge balance or phase equilibrium when specifying C or C(4) and Alkalinty."; - error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; - } - chemistry_dat << "@solve (pH, 1e-6, lin, 1, Alkalinity, 7)" << - std::endl; - chemistry_dat << std::endl; - } - else - { - struct master *master_ptr = master_bsearch("Alkalinity"); - if (master_ptr == NULL) - { - std::ostringstream oss; - oss << "Could not find Alkalinity definition in database."; - error_msg(oss.str().c_str(), CONTINUE); - input_error++; - } - chemistry_dat << "@species(" << master_ptr->s-> - name << ", " << master_ptr->s->z << ")" << std::endl; - chemistry_dat << "@solve (" << master_ptr->s-> - name << ".act, 1e-6, log, 1, Alkalinity, 1e-9)" << std::endl; - chemistry_dat << std::endl; - } - } -} - -void -cxxISolution::ORCH_write_chemistry_minerals(std::ostream & chemistry_dat) -{ - chemistry_dat << std:: - endl << "//********* Adjustments to mineral equilibrium" << std::endl; -// -// Write minerals -// - std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); - for (iter = this->comps.begin(); iter != this->comps.end(); ++iter) - { - if (iter->second.get_equation_name() != NULL) - { - std::string name(iter->second.get_equation_name()); - if (name != "charge") - { - struct phase *phase_ptr; - int n; - phase_ptr = phase_bsearch(name.c_str(), &n, FALSE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@si_mineral(" << phase_name << ")" << std:: - endl; - chemistry_dat << "@reaction(" << phase_name << ", " << - pow(10.0, -phase_ptr->lk); - struct rxn_token *next_token = phase_ptr->rxn_x->token; - next_token++; - while (next_token->s != NULL || next_token->name != NULL) - { - chemistry_dat << ", " << next_token->coef; - if (next_token->s != NULL) - { - chemistry_dat << ", " << next_token->s->name; - } - else - { - chemistry_dat << ", " << next_token->name; - } - next_token++; - } - chemistry_dat << ")" << std::endl; - } - } - } - //chemistry_dat << "@mineral(Quartz)" << std::endl; - //chemistry_dat << "@sreaction(Quartz, 10139.1138573668, -2.0, H2O, 1.0, H4SiO4)" << std::endl; -} -void -cxxISolution::ORCH_write_input(std::ostream & input_dat) -{ - - -// -// Write orchestra input file info -// - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; - - - // Solution element and attributes - - //s_oss << "SOLUTION_RAW " << this->n_user << " " << this->description << std::endl; - - //s_oss << "-temp " << this->tc << std::endl; - headings << "tempc\t"; - data << this->tc << "\t"; - - //s_oss << "-pH " << this->ph << std::endl; - headings << "pH\t"; - data << this->ph << "\t"; - - //s_oss << "-pe " << this->pe << std::endl; - headings << "pe\t"; - data << this->pe << "\t"; - - //s_oss << "-mu " << this->mu << std::endl; - - //s_oss << "-ah2o " << this->ah2o << std::endl; - headings << "H2O.act\t"; - data << 1 << "\t"; - //s_oss << "-total_h " << this->total_h << std::endl; - - //s_oss << "-total_o " << this->total_o << std::endl; - - //s_oss << "-cb " << this->cb << std::endl; - - //s_oss << "-mass_water " << this->mass_water << std::endl; - - //s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; - - // soln_total conc structures - //this->totals.dump_raw(s_oss, indent + 2); - //this->totals.write_orchestra(headings, s_oss); - - std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); - for (; iter != this->comps.end(); ++iter) - { - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch(iter->first); - assert(master_ptr != NULL); - std::string ename(iter->first); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - { - coef = 1; - } - if (ename != "Alkalinity") - { - ename = master_ptr->s->name; - ename.append(".diss"); - } - - if (iter->second.get_equation_name() == NULL) - { - headings << ename << "\t"; - data << (this->totals.find(iter->first))->second / coef << "\t"; - } - else - { - std::string name(iter->second.get_equation_name()); - if (name == "charge") - { - headings << ename << "\t"; - data << (this->totals.find(iter->first))->second / - coef << "\t"; - } - else - { - int n; - struct phase *phase_ptr = - phase_bsearch(name.c_str(), &n, TRUE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - headings << phase_name << ".si_raw" << "\t"; - data << iter->second.get_phase_si() << "\t"; - } - } - // activity estimate - if (ename == "Alkalinity") - { - if ((this->comps.find("C") == this->comps.end()) - && (this->comps.find("C(4)") == this->comps.end())) - { - headings << master_ptr->s->name << ".act\t"; - data << iter->second.get_moles() * 1e-3 << "\t"; - } - } - else - { - headings << master_ptr->s->name << ".act\t"; - data << iter->second.get_moles() * 1e-3 << "\t"; - } - } - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - - // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; - - return; -} - -void -cxxISolution::ORCH_write_output_vars(std::ostream & outstream) -{ - outstream << "Var:"; - outstream << "\tnr_iter"; - // - // Serialize solution - // - outstream << "\tstart_solution"; - //tc - outstream << "\ttempc"; - //pH - outstream << "\tpH"; - //pe - outstream << "\tpe"; - //mu - outstream << "\tI"; - //ah2o - outstream << "\tH2O.act"; - //total_h; - outstream << "\ttotal_hydrogen"; - //total_o; - outstream << "\ttotal_oxygen"; - //cb - outstream << "\tchargebalance"; - //mass_water; - outstream << "\tH2O.con"; - //total_alkalinity; - outstream << "\tAlkalinity"; - //orchestra master variables - outstream << "\tH+.diss"; - outstream << "\te-.diss"; - outstream << "\tH2O.diss"; - //totals - for (std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") - continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - outstream << "\t" << s_ptr->name << ".diss"; - } - outstream << "\tend_totals"; - for (std::map < char *, cxxISolutionComp, CHARSTAR_LESS >::iterator iter = - this->comps.begin(); iter != this->comps.end(); ++iter) - { - std::string name(iter->second.get_description()); - if (name == "H(1)" || name == "E" || name == "Alkalinity") - continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - outstream << "\t" << s_ptr->name << ".act"; - } - outstream << "\tend_master_activities"; - // - // Write all species activities and concentrations - // - int i; - for (i = 0; i < count_s_x; i++) - { - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - outstream << "\t" << name.c_str() << ".act" << "\t" << name. - c_str() << ".con"; - } - outstream << "\tend_species"; - outstream << std::endl; - return; -} - -void -cxxISolution::ORCH_write(std::ostream & chemistry_dat, - std::ostream & input_dat, std::ostream & output_dat) -{ - // - // Write orchestra chemistry file definition - // - chemistry_dat << std:: - endl << "// Write ORCHESTRA chemistry definitions" << std::endl; - // mark for Orchestra include - chemistry_dat << std::endl << "@class: species_reactions () {" << std:: - endl; - this->ORCH_write_chemistry(chemistry_dat); - // end orchestra include block - chemistry_dat << std::endl << "}" << std::endl; - // - // Write orchestra input file definition - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - this->ORCH_write_input(input_dat); - input_dat << std::endl << "}" << std::endl; - - // - // Write orchestra output file definition - // - output_dat << std::endl << "Output_every: 1" << std::endl; - this->ORCH_write_output_vars(output_dat); - - //write data to stderr - //std::cerr << chemistry_dat.str() << input_dat.str() << output_dat.str(); - -} -#endif diff --git a/NameDouble.h b/NameDouble.h index 5f63a892..81629823 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -7,7 +7,6 @@ #include // std::string #include // std::list #include // std::vector -#include "Phreeqc_class.h" class Phreeqc; #include "Parser.h" diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 27c2589c..356b7b03 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -342,95 +342,3 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) this->eltList.add_extensive(addee.eltList, extensive); } -#ifdef ORCHESTRA -void -cxxPPassemblage::ORCH_write_chemistry(std::ostream & chemistry_dat) -{ - chemistry_dat << std::endl << "//********* Mineral equilibria" << std:: - endl; -// -// Write minerals -// - for (std::list < cxxPPassemblageComp >::iterator it = - this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); - ++it) - { - struct phase *phase_ptr; - int n; - phase_ptr = phase_bsearch(it->get_name(), &n, FALSE); - assert(phase_ptr != NULL); - std::string phase_name(phase_ptr->name); - std::replace(phase_name.begin(), phase_name.end(), '(', '['); - std::replace(phase_name.begin(), phase_name.end(), ')', ']'); - chemistry_dat << "@mineral(" << phase_name << ")" << std::endl; - chemistry_dat << "@reaction(" << phase_name << ", " << pow(10.0, - -phase_ptr-> - lk); - struct rxn_token *next_token = phase_ptr->rxn_x->token; - next_token++; - while (next_token->s != NULL || next_token->name != NULL) - { - chemistry_dat << ", " << next_token->coef; - if (next_token->s != NULL) - { - chemistry_dat << ", " << next_token->s->name; - } - else - { - chemistry_dat << ", " << next_token->name; - } - next_token++; - } - chemistry_dat << ")" << std::endl; - } -} - -void -cxxPPassemblage::ORCH_write_output_vars(std::ostream & outstream) -{ - // - // Write ppassemblage output variables - // - outstream << "\tstart_ppassemblage"; - for (std::list < cxxPPassemblageComp >::iterator it = - this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); - ++it) - { - outstream << "\t" << it->get_name() << ".min"; - } - outstream << "\tend_ppassemblage"; -} - -void -cxxPPassemblage::ORCH_read(std::vector < std::pair < std::string, - double >>output_vector, - std::vector < std::pair < std::string, - double >>::iterator & it) -{ - while (it->first.compare("end_ppassemblage") != 0) - { - it++; - } -} - -void -cxxPPassemblage::ORCH_store_global(std::map < std::string, double >output_map) -{ - int i; - std::map < std::string, double >::iterator it; - for (i = 0; i < count_unknowns; i++) - { - // MB, ALK, CB, SOLUTION_PHASE_BOUNDARY, MU, AH2O - switch (x[i]->type) - { - case PP: - std::string name(x[i]->phase->name); - name.append(".min"); - it = output_map.find(name); - assert(it != output_map.end()); - x[i]->moles = it->second; - break; - } - } -} -#endif diff --git a/PPassemblage.h b/PPassemblage.h index bee4aaad..e9c85487 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -43,15 +43,6 @@ class cxxPPassemblage:public cxxNumKeyword #endif void totalize(PHREEQC_PTR_ARG); -#ifdef ORCHESTRA - void ORCH_write_chemistry(std::ostream & chemistry_dat); - void ORCH_write_output_vars(std::ostream & outstream); - void ORCH_read(std::vector < std::pair < std::string, - double >>output_vector, - std::vector < std::pair < std::string, - double >>::iterator & it); - void ORCH_store_global(std::map < std::string, double >output_map); -#endif private: void add(const cxxPPassemblage & addee, double extensive); diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 529f9817..c6173910 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -8,6 +8,7 @@ #include // std::vector #include "NameDouble.h" +#include "phreeqc_class.h" class cxxPPassemblageComp: public PHRQ_base { diff --git a/SSassemblage.h b/SSassemblage.h index 5d3a5d76..6dd48d66 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -10,6 +10,8 @@ #include "NumKeyword.h" #include "NameDouble.h" +#include "phreeqc_class.h" + class cxxSSassemblageSS; //#include "cxxMix.h" diff --git a/SSassemblageSS.h b/SSassemblageSS.h index c1eb1c5d..a6e1a10b 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -7,6 +7,7 @@ #include // std::list #include // std::vector #include "NameDouble.h" +#include "phreeqc_class.h" class cxxSSassemblageSS: public PHRQ_base { diff --git a/Solution.h b/Solution.h index 44cbf5c4..c5a1efcb 100644 --- a/Solution.h +++ b/Solution.h @@ -11,6 +11,7 @@ #include "NameDouble.h" #include "PHRQ_base.h" #include "PHRQ_io.h" +#include "phreeqc_class.h" class cxxMix; class cxxSolution:public cxxNumKeyword @@ -151,14 +152,6 @@ class cxxSolution:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); void multiply(double extensive); void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); -#ifdef ORCHESTRA - void ORCH_write(std::ostream & headings, std::ostream & input_data) const; - void ORCH_read(std::vector < std::pair < std::string, - double >>output_vector, - std::vector < std::pair < std::string, - double >>::iterator & it); - void ORCH_store_global(std::map < std::string, double >output_map); -#endif #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/StorageBin.cxx b/StorageBin.cxx index 2849d492..a5acf328 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -922,7 +922,7 @@ cxxStorageBin::add(struct system *system_ptr) void cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) // - // copy data fromphreeqc storage to storage bin + // copy data from phreeqc storage to storage bin // { //std::ostringstream oss; @@ -1047,7 +1047,7 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) void cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) // - // copy data fromphreeqc storage to storage bin + // copy data from phreeqc storage to storage bin // { int pos; @@ -1645,18 +1645,6 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) } #endif -#ifdef ORCHESTRA -void -cxxStorageBin::ORCH_write(std::ostream & chemistry_dat, - std::ostream & input_dat, std::ostream & output_dat) -{ - //std::ostringstream oss; - - // Liter concentrations - this->system.ORCH_write(chemistry_dat, input_dat, output_dat); - -} -#endif cxxSystem & cxxStorageBin::getSystem(void) { diff --git a/StorageBin.h b/StorageBin.h index 842ccddb..5fb9112e 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -108,10 +108,6 @@ class cxxStorageBin: public PHRQ_base #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); -#endif -#ifdef ORCHESTRA - void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat); #endif protected: // Tidied classes diff --git a/System.cxx b/System.cxx index 524f3755..cc0fa7b5 100644 --- a/System.cxx +++ b/System.cxx @@ -20,8 +20,6 @@ #include "Reaction.h" #include "Temperature.h" - -extern void ORCH_write_chemistry_species(std::ostream & chemistry_dat); cxxSystem::cxxSystem(PHRQ_io *io) : PHRQ_base(io) @@ -96,373 +94,5 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) this->ssassemblage->totalize(P_INSTANCE); this->totals.add_extensive(this->surface->Get_totals(), 1.0); } - //Need to handle the following 3 reactions: - // - //this->kinetics = NULL; - //this->mix = NULL; - //this->reaction = NULL; - //this->temperature = NULL; - //this->totals.dump_raw(std::cerr, 1); return; } -#ifdef ORCHESTRA -void -cxxSystem::ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat) -{ - // - // chemistry file - // - this->totalize(); - // calculate orchestra components from PHREEQC totals - this->ORCH_components(); - // write definitions for chemistry - chemistry_dat << std:: - endl << "@class: species_reactions () {" << std::endl; - this->ORCH_write_chemistry_water(chemistry_dat); - this->ORCH_write_chemistry_primary(chemistry_dat); - this->ORCH_write_chemistry_total_O_H(chemistry_dat); - ORCH_write_chemistry_species(chemistry_dat); - // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_chemistry(chemistry_dat); - // add definitions for other PHREEQC entities here - // finish up - chemistry_dat << std::endl << "}" << std::endl; - // - // input file - // - input_dat << std::endl << "@class: input_file_data () {" << std::endl; - this->ORCH_write_input(input_dat); - input_dat << std::endl << "}" << std::endl; - // - // output file - // - output_dat << std::endl << "Output_every: 1" << std::endl; - output_dat << "Var:"; - this->ORCH_write_output_vars(output_dat); - // add definitions for pure phases - if (this->ppassemblage != NULL) - this->ppassemblage->ORCH_write_output_vars(output_dat); - //finish up - output_dat << std::endl; -}; -void -cxxSystem::ORCH_write_chemistry_water(std::ostream & chemistry_dat) -{ - // - // Write water entities - // - chemistry_dat << std:: - endl << "//********* The water entities" << std::endl; - // e-, total hydrogen - chemistry_dat << "@entity(e-, diss, 0)" << std::endl; - chemistry_dat << "@Calc: (1, \"e-.act = 10.^(-pe)\")" << std::endl; - chemistry_dat << "@solve (pe, 1e-6, lin, 1, e-.liter, 1e-14)" << std:: - endl; - // H+, charge balance - chemistry_dat << "@Calc: (1, \"H+.act = 10.^(-pH)\")" << std::endl; - chemistry_dat << "@solve (pH, 1e-6, lin, 1, H+.liter, 1e-14)" << std:: - endl; - // H2O - chemistry_dat << "@entity(" << s_h2o-> - name << ", diss, 55.506)" << std::endl; - chemistry_dat << std::endl; -} -void -cxxSystem::ORCH_write_chemistry_primary(std::ostream & chemistry_dat) -{ - chemistry_dat << std::endl << "//********* The primary species" << std:: - endl; - // - // Write other master species definitions, i.e. primary entities - // - chemistry_dat << "@species(H+, 1)" << std::endl; - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - { - std::string name(iter->first); - if (name == "H(1)" || name == "E" || name == "H" || name == "O" - || name == "Charge") - continue; - struct element *elt; - char *element_name = string_hsave(name.c_str()); - elt = element_store(element_name); - assert(elt != NULL); - struct species *s_ptr; - s_ptr = elt->master->s; - assert(s_ptr != NULL); - chemistry_dat << "@species(" << s_ptr->name << ", " << s_ptr-> - z << ")" << std::endl; - // regular mole balance - chemistry_dat << "@primary_entity(" << s_ptr-> - name << ", 1e-9, liter, 1.0e-9)" << std::endl; - } - chemistry_dat << std::endl; -} -void -cxxSystem::ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat) -{ - chemistry_dat << std:: - endl << "//********* Define total hydrogen and oxygen" << std::endl; - // Write H total equation - chemistry_dat << "@var: total_hydrogen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_hydrogen = 0"; - int i; - for (i = 0; i < count_s_x; i++) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - { - if (s_x[i]->h != 0) - { - chemistry_dat << "+"; - if (s_x[i]->h != 1) - { - chemistry_dat << s_x[i]->h << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - // Write O total equation - chemistry_dat << "@var: total_oxygen 0" << std::endl; - chemistry_dat << "@calc: (5, \"total_oxygen = 0"; - for (i = 0; i < count_s_x; i++) - { - if (s_x[i]->o != 0) - { - // write in terms of orchestra components - if (s_x[i]->primary != NULL - || (s_x[i]->secondary != NULL - && s_x[i]->secondary->in == TRUE)) - { - chemistry_dat << "+"; - if (s_x[i]->o != 1) - { - chemistry_dat << s_x[i]->o << "*"; - } - chemistry_dat << "{" << s_x[i]->name << ".liter}"; - } - } - } - chemistry_dat << "\")" << std::endl; - chemistry_dat << std::endl; -} -void -cxxSystem::ORCH_write_input(std::ostream & input_dat) -{ - // - // Write orchestra input file info - // - std::ostringstream headings, data; - data.precision(DBL_DIG - 1); - headings << "var: "; - data << "data: "; - headings << "tempc\t"; - data << this->solution->get_tc() << "\t"; - headings << "pH\t"; - data << this->solution->get_ph() << "\t"; - headings << "pe\t"; - data << this->solution->get_pe() << "\t"; - headings << "H2O.act\t"; - data << 1 << "\t"; - headings << "I\t"; - data << this->solution->get_mu() << "\t"; - for (cxxNameDouble::iterator iter = this->orch_totals.begin(); - iter != this->orch_totals.end(); ++iter) - { - headings << iter->first << ".liter" << "\t"; - data << iter->second << "\t"; - } - // activity estimate - for (cxxNameDouble::iterator iter = this->totals.begin(); - iter != this->totals.end(); ++iter) - { - if (iter->first == "O" || iter->first == "Charge") - continue; - std::string master_name; - struct master *master_ptr; - master_ptr = master_bsearch(iter->first); - assert(master_ptr != NULL); - cxxNameDouble ma = this->solution->get_master_activity(); - cxxNameDouble::iterator it = ma.find(iter->first); - if (it == ma.end()) - { - it = ma.find(master_ptr->s->secondary->elt->name); - } - headings << master_ptr->s->name << ".act\t"; - if (it != ma.end()) - { - data << pow(10., it->second) << "\t"; - } - else - { - data << 1e-9 << "\t"; - } - } - // Isotopes - //s_oss << "-Isotopes" << std::endl; - /* - { - for (std::list::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); - } - } - */ - // Write data to string - input_dat << headings.str() << std::endl; - input_dat << data.str() << std::endl; - return; -} -void -cxxSystem::ORCH_components(void) -{ - // translate from H, O, charge to H+tot, e-tot, and H2Otot - cxxNameDouble::iterator it; - cxxNameDouble temp_totals; - // - // Set names in orch_totals to master species names - // - this->orch_totals.clear(); - temp_totals = this->totals; - temp_totals.erase("H"); - temp_totals.erase("O"); - temp_totals.erase("Charge"); - //temp_totals.dump_raw(std::cerr, 1); - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - assert(elt_ptr != NULL); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - assert(master_ptr != NULL); - double coef = master_ptr->coef; - if (master_ptr->coef == 0) - { - coef = 1; - } - this->orch_totals[master_ptr->s->name] = it->second / coef; - } - // - // Calculate h2otot - // - it = this->totals.find("O"); - assert(it != this->totals.end()); - double h2otot = it->second; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - h2otot -= it->second * master_ptr->s->o; - } - // - // Calculate htot - // - it = this->totals.find("H"); - assert(it != this->totals.end()); - double htot = it->second - 2 * h2otot; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - htot -= it->second * master_ptr->s->h; - } - // - // Calculate etot - // - it = this->totals.find("Charge"); - assert(it != this->totals.end()); - double etot = -it->second + htot; - // subtract O in master species - for (it = temp_totals.begin(); it != temp_totals.end(); it++) - { - struct element *elt_ptr; - elt_ptr = element_store(it->first); - struct master *master_ptr; - master_ptr = elt_ptr->primary; - etot += it->second * master_ptr->s->z; - } - // - // store h2otot, htot, etot in orch_totals - // - this->orch_totals["H2O"] = h2otot; - this->orch_totals["H+"] = htot; - this->orch_totals["e-"] = etot; - this->orch_totals.dump_raw(std::cerr, 1); -} -void -cxxSystem::ORCH_write_output_vars(std::ostream & outstream) -{ - outstream << "\tnr_iter"; - // - // Serialize solution - // - outstream << "\tstart_solution"; - //tc - outstream << "\ttempc"; - //pH - outstream << "\tpH"; - //pe - outstream << "\tpe"; - //mu - outstream << "\tI"; - //ah2o - outstream << "\tH2O.act"; - //total_h; - outstream << "\ttotal_hydrogen"; - //total_o; - outstream << "\ttotal_oxygen"; - //cb - outstream << "\tchargebalance"; - //mass_water; - outstream << "\tH2O.con"; - //total_alkalinity; - outstream << "\tAlkalinity"; - //orchestra master variables - outstream << "\tH+.diss"; - outstream << "\te-.diss"; - outstream << "\tH2O.diss"; - // - // Write totals - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - { - if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - outstream << "\t" << it->first << ".diss"; - } - outstream << "\tend_totals"; - for (cxxNameDouble::iterator it = this->orch_totals.begin(); - it != this->orch_totals.end(); it++) - { - if (it->first == "H+" || it->first == "H2O" || it->first == "e-") - continue; - outstream << "\t" << it->first << ".act"; - } - outstream << "\tend_master_activities"; - // - // Write all species activities and concentrations - // - int i; - for (i = 0; i < count_s_x; i++) - { - std::string name(s_x[i]->name); - std::replace(name.begin(), name.end(), '(', '['); - std::replace(name.begin(), name.end(), ')', ']'); - outstream << "\t" << name.c_str() << ".act" << "\t" << name. - c_str() << ".con"; - } - outstream << "\tend_species"; -} -#endif /* */ diff --git a/System.h b/System.h index a5a87d52..1a685e6b 100644 --- a/System.h +++ b/System.h @@ -12,6 +12,7 @@ //#include "Temperature.h" #include "NameDouble.h" #include "PHRQ_base.h" +#include "phreeqc_class.h" class cxxSolution; class cxxExchange; class cxxGasPhase; @@ -75,17 +76,6 @@ public: return this->totals; } -#ifdef ORCHESTRA - void ORCH_components(); - void ORCH_write(std::ostream & chemistry_dat, std::ostream & input_dat, - std::ostream & output_dat); - void ORCH_write_chemistry_water(std::ostream & chemistry_dat); - void ORCH_write_chemistry_primary(std::ostream & chemistry_dat); - void ORCH_write_chemistry_total_O_H(std::ostream & chemistry_dat); - void ORCH_write_output_vars(std::ostream & outstream); - void ORCH_write_input(std::ostream & input_dat); - -#endif /* */ private: cxxSolution * solution; cxxExchange * exchange; @@ -98,7 +88,6 @@ private: cxxReaction * reaction; cxxTemperature * temperature; cxxNameDouble totals; - cxxNameDouble orch_totals; }; From b18bda26b473ba7c58022248d5701497e416955f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Sep 2011 17:03:44 +0000 Subject: [PATCH 0261/1077] Working on StorageBin. Moved 3 routines to structures to eliminate P_INSTANCEs. Runs mytest OK. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5659 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 14 +++++++------- Exchange.h | 12 ++++++------ KineticsComp.h | 12 ++++++------ Phreeqc.cpp | 2 +- Phreeqc.h | 16 +++++++++++----- StorageBin.cxx | 12 ++++++++++-- StorageBin.h | 7 ++++--- Surface.cxx | 4 ++-- Surface.h | 20 ++++++++++---------- System.cxx | 2 +- cxxKinetics.h | 26 +++++++++++++------------- 11 files changed, 71 insertions(+), 56 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 5809544e..25567469 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -167,7 +167,7 @@ cxxExchange::~cxxExchange() } bool -cxxExchange::get_related_phases() +cxxExchange::Get_related_phases() const { for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) @@ -180,7 +180,7 @@ cxxExchange::get_related_phases() } bool -cxxExchange::get_related_rate() +cxxExchange::Get_related_rate() const { for (std::map < std::string, cxxExchComp >::const_iterator it = this->exchComps.begin(); it != this->exchComps.end(); ++it) @@ -456,23 +456,23 @@ cxxExchange::totalize() return; } bool -cxxExchange::get_pitzer_exchange_gammas() +cxxExchange::Get_pitzer_exchange_gammas() const { return this->pitzer_exchange_gammas; } void -cxxExchange::set_pitzer_exchange_gammas(bool b) +cxxExchange::Set_pitzer_exchange_gammas(bool b) { this->pitzer_exchange_gammas = b; } -std::map < std::string, cxxExchComp > & -cxxExchange::get_exchComps(void) +const std::map < std::string, cxxExchComp > & +cxxExchange::get_exchComps(void) const { return (this->exchComps); } const cxxNameDouble & -cxxExchange::get_totals() const +cxxExchange::Get_totals() const { return totals; } diff --git a/Exchange.h b/Exchange.h index 5fa3a923..f0c0b70e 100644 --- a/Exchange.h +++ b/Exchange.h @@ -25,17 +25,17 @@ public: void read_raw(CParser & parser, bool check = true); - bool get_related_phases(void); + bool Get_related_phases(void) const; - bool get_related_rate(void); + bool Get_related_rate(void) const; - bool get_pitzer_exchange_gammas(); - void set_pitzer_exchange_gammas(bool b); + bool Get_pitzer_exchange_gammas() const; + void Set_pitzer_exchange_gammas(bool b); - std::map < std::string, cxxExchComp > &get_exchComps(void); + const std::map < std::string, cxxExchComp > &get_exchComps(void) const; void totalize(); - const cxxNameDouble & get_totals() const; + const cxxNameDouble & Get_totals() const; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); diff --git a/KineticsComp.h b/KineticsComp.h index 1c2ce704..544b6207 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -35,12 +35,12 @@ public: this->rate_name.clear(); } - cxxNameDouble &Get_namecoef(void) {return namecoef;}; - double Get_tol(void) {return tol;}; - double Get_m(void) {return m;}; - double Get_m0(void) {return m0;}; - double Get_moles(void) {return moles;}; - std::vector < double > &Get_d_params(void) {return d_params;}; + const cxxNameDouble &Get_namecoef(void) const {return namecoef;}; + double Get_tol(void) const {return tol;}; + double Get_m(void) const {return m;}; + double Get_m0(void) const {return m0;}; + double Get_moles(void) const {return moles;}; + const std::vector < double > &Get_d_params(void) const {return d_params;}; #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d8f8b028..735f1d45 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -480,7 +480,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxExchange entity(&exchange[i], &phrq_io); entity.totalize(); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // surfaces diff --git a/Phreeqc.h b/Phreeqc.h index c77941a9..ebe73fbb 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -53,6 +53,7 @@ class cxxSSassemblageSS; class cxxSurface; class cxxSurfaceCharge; class cxxSurfaceComp; +class cxxStorageBin; class Phreeqc { @@ -1144,9 +1145,9 @@ CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); public: struct solution *solution_alloc(void); struct solution *solution_bsearch(int k, int *n, int print); -private: struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); +private: int solution_copy_to_last(int n, int n_user_new); int solution_duplicate(int n_user_old, int n_user_new); int solution_delete(int n_user_old); @@ -1250,9 +1251,9 @@ extern void MergeFinalize(void); // convert class to struct struct mix * cxxMix2mix(cxxMix *mx); -struct kinetics *cxxKinetics2kinetics(cxxKinetics * kin); -struct kinetics_comp * cxxKineticsComp2kinetics_comp(std::list < cxxKineticsComp > * el); -struct exchange * cxxExchange2exchange(cxxExchange * ex); +struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); +struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); +struct exchange * cxxExchange2exchange(const cxxExchange * ex); struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); struct master * Get_exch_master(const cxxExchComp * ec); struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); @@ -1265,7 +1266,7 @@ struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); -struct surface * cxxSurface2surface(cxxSurface * surf); +struct surface * cxxSurface2surface(const cxxSurface * surf); struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); @@ -1274,6 +1275,11 @@ struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + +void Use2cxxStorageBin(cxxStorageBin & sb); +void phreeqc2cxxStorageBin(cxxStorageBin & sb); +void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); + /* tally.c */ void add_all_components_tally(void); diff --git a/StorageBin.cxx b/StorageBin.cxx index a5acf328..1085e817 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -49,6 +49,7 @@ PHRQ_base(io) this->system.Set_io(io); } +#ifdef MOVE_TO_STRUCTURES cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io * io) : PHRQ_base(io) @@ -160,7 +161,7 @@ PHRQ_base(io) } } } - +#endif cxxStorageBin::~cxxStorageBin() { } @@ -434,6 +435,8 @@ cxxStorageBin::getSurfaces() const { return this->Surfaces; } + +#ifdef MOVE_TO_STRUCTURES void cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) // @@ -504,7 +507,7 @@ cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) Temperatures[P_INSTANCE_POINTER temperature[i].n_user] = cxxTemperature(&P_INSTANCE_POINTER temperature[i], this->Get_io()); } } - +#endif #ifdef SKIP void @@ -919,6 +922,7 @@ cxxStorageBin::add(struct system *system_ptr) } } +#ifdef MOVE_TO_STRUCTURES void cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) // @@ -1044,6 +1048,9 @@ cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) //std::cerr << oss.str(); } +#endif + +#ifdef MOVE_TO_STRUCTURES void cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) // @@ -1106,6 +1113,7 @@ cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) } } } +#endif void cxxStorageBin::remove(int n) diff --git a/StorageBin.h b/StorageBin.h index 5fb9112e..3e224fb3 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -25,12 +25,12 @@ class cxxStorageBin: public PHRQ_base public: cxxStorageBin(PHRQ_io *io=NULL); //cxxStorageBin(struct Use *use_ptr); - cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io=NULL); + //cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io=NULL); ~cxxStorageBin(); - void import_phreeqc(PHREEQC_PTR_ARG); + //void import_phreeqc(PHREEQC_PTR_ARG); - void cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n); + //void cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n); void phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n); @@ -105,6 +105,7 @@ class cxxStorageBin: public PHRQ_base const std::map < int, cxxSSassemblage > &getSSassemblages() const; const std::map < int, cxxSurface > &getSurfaces() const; + cxxSystem & Get_system(void) {return system;}; #ifdef USE_MPI void mpi_send(int n, int task_number); void mpi_recv(int task_number); diff --git a/Surface.cxx b/Surface.cxx index 86d0e655..4f3ca0eb 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -118,7 +118,7 @@ cxxSurface::~cxxSurface() } bool -cxxSurface::Get_related_phases() +cxxSurface::Get_related_phases() const { for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) @@ -131,7 +131,7 @@ cxxSurface::Get_related_phases() } bool -cxxSurface::Get_related_rate() +cxxSurface::Get_related_rate() const { for (std::map < std::string, cxxSurfaceComp >::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) diff --git a/Surface.h b/Surface.h index aec54ad2..45ee2771 100644 --- a/Surface.h +++ b/Surface.h @@ -28,9 +28,9 @@ class cxxSurface:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - bool Get_related_phases(void); + bool Get_related_phases(void) const; - bool Get_related_rate(void); + bool Get_related_rate(void) const; void totalize(); @@ -47,15 +47,15 @@ class cxxSurface:public cxxNumKeyword void add(const cxxSurface & addee, double extensive); const std::map < std::string, cxxSurfaceComp > & Get_surfaceComps() const {return this->surfaceComps;}; const std::map < std::string, cxxSurfaceCharge > & Get_surfaceCharges() const {return this->surfaceCharges;}; - SURFACE_TYPE Get_type(void) {return this->type;}; - DIFFUSE_LAYER_TYPE Get_dl_type(void) {return dl_type;}; - SITES_UNITS Get_sites_units(void) {return sites_units;}; - bool Get_only_counter_ions(void) {return only_counter_ions;}; - double Get_thickness(void) {return thickness;}; - double Get_debye_lengths(void) {return debye_lengths;}; - double Get_DDL_viscosity(void) {return DDL_viscosity;}; + SURFACE_TYPE Get_type(void) const {return this->type;}; + DIFFUSE_LAYER_TYPE Get_dl_type(void) const {return dl_type;}; + SITES_UNITS Get_sites_units(void) const {return sites_units;}; + bool Get_only_counter_ions(void) const {return only_counter_ions;}; + double Get_thickness(void) const {return thickness;}; + double Get_debye_lengths(void) const {return debye_lengths;}; + double Get_DDL_viscosity(void) const {return DDL_viscosity;}; double Get_DDL_limit(void) const {return DDL_limit;}; - bool Get_transport(void) {return transport;}; + bool Get_transport(void) const {return transport;}; protected: std::map < std::string, cxxSurfaceComp > surfaceComps; diff --git a/System.cxx b/System.cxx index cc0fa7b5..d7322297 100644 --- a/System.cxx +++ b/System.cxx @@ -72,7 +72,7 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) if (this->exchange != NULL) { this->exchange->totalize(); - this->totals.add_extensive(this->exchange->get_totals(), 1.0); + this->totals.add_extensive(this->exchange->Get_totals(), 1.0); } if (this->ppassemblage != NULL) { diff --git a/cxxKinetics.h b/cxxKinetics.h index 72396a29..4ceca450 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -20,7 +20,7 @@ class cxxKinetics:public cxxNumKeyword cxxKinetics(struct kinetics *, PHRQ_io *io=NULL); cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); - ~cxxKinetics(); + ~cxxKinetics(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -28,19 +28,19 @@ class cxxKinetics:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - bool Get_related_phases(void); - bool Get_related_rate(void); + //bool Get_related_phases(void) const; + //bool Get_related_rate(void) const; - std::vector < double > &Get_steps(void) {return steps;}; - double Get_step_divide(void) {return step_divide;}; - int Get_rk(void) {return rk;}; - int Get_bad_step_max(void) {return bad_step_max;}; - bool Get_use_cvode(void) {return use_cvode;}; - int Get_cvode_steps(void) {return cvode_steps;}; - int Get_cvode_order(void) {return cvode_order;}; - std::list < cxxKineticsComp > &Get_kineticsComps(void) {return kineticsComps;}; - cxxNameDouble & Get_totals(void) {return this->totals;}; - int Get_equal_steps(void) {return equal_steps;}; + const std::vector < double > &Get_steps(void) const {return steps;}; + double Get_step_divide(void) const {return step_divide;}; + int Get_rk(void) const {return rk;}; + int Get_bad_step_max(void) const {return bad_step_max;}; + bool Get_use_cvode(void) const {return use_cvode;}; + int Get_cvode_steps(void) const {return cvode_steps;}; + int Get_cvode_order(void) const {return cvode_order;}; + const std::list < cxxKineticsComp > &Get_kineticsComps(void) const {return kineticsComps;}; + const cxxNameDouble & Get_totals(void) const {return this->totals;}; + int Get_equal_steps(void) const {return equal_steps;}; #ifdef USE_MPI From bf84746d3e247423aa16fb08014f5ea673e60380 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Sep 2011 17:44:10 +0000 Subject: [PATCH 0262/1077] Converted last StorageBin to remove P_INSTANCE. Not sure about the cxx to system. Commented for now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5660 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 +++- StorageBin.cxx | 3 +++ StorageBin.h | 5 ++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index ebe73fbb..02a40780 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1278,7 +1278,9 @@ struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); void Use2cxxStorageBin(cxxStorageBin & sb); void phreeqc2cxxStorageBin(cxxStorageBin & sb); -void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); +void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); +void cxxStorageBin2phreeqc0(cxxStorageBin & sb, int n); + /* tally.c */ diff --git a/StorageBin.cxx b/StorageBin.cxx index 1085e817..69707a9e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1186,6 +1186,8 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) return (cxxsoln_ptr); } #endif + +#ifdef SKIP_OR_MOVE_TO_STRUCTURES struct system * cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // @@ -1281,6 +1283,7 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) } return system_ptr; } +#endif #ifdef USE_MPI void diff --git a/StorageBin.h b/StorageBin.h index 3e224fb3..a813931f 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -24,7 +24,6 @@ class cxxStorageBin: public PHRQ_base public: cxxStorageBin(PHRQ_io *io=NULL); - //cxxStorageBin(struct Use *use_ptr); //cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io=NULL); ~cxxStorageBin(); @@ -32,7 +31,7 @@ class cxxStorageBin: public PHRQ_base //void cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n); - void phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n); + //void phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n); void remove(int n); @@ -92,7 +91,7 @@ class cxxStorageBin: public PHRQ_base void add(struct system *sys_ptr); - struct system *cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int i); + //struct system *cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int i); //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); From 9fe532eaaf5ffdce6f43955ae5937a979b873b6f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Sep 2011 18:51:39 +0000 Subject: [PATCH 0263/1077] Cleaned up Get_ and Set_ except for parser. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5661 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 6 +- Exchange.h | 2 +- GasPhase.cxx | 2 +- GasPhase.h | 2 +- ISolution.cxx | 14 ++-- ISolution.h | 10 +-- ISolutionComp.cxx | 8 +- ISolutionComp.h | 38 ++++----- NumKeyword.h | 16 ++-- PPassemblage.cxx | 2 +- Phreeqc.cpp | 4 +- Reaction.cxx | 2 +- ReadClass.cxx | 8 +- SSassemblage.cxx | 2 +- SSassemblage.h | 4 +- Solution.cxx | 4 +- StorageBin.cxx | 202 +++++++++++++++++++++++----------------------- StorageBin.h | 75 ++++++++--------- Surface.cxx | 2 +- SurfaceCharge.h | 2 +- System.cxx | 4 +- System.h | 22 ++--- Temperature.cxx | 2 +- cxxKinetics.cxx | 2 +- cxxMix.cxx | 2 +- dumper.h | 4 +- 26 files changed, 217 insertions(+), 224 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 25567469..7448a976 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -43,7 +43,7 @@ cxxNumKeyword(io) { int i; - this->set_description(exchange_ptr->description); + this->Set_description(exchange_ptr->description); n_user = exchange_ptr->n_user; n_user_end = exchange_ptr->n_user_end; pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); @@ -94,7 +94,7 @@ cxxNumKeyword(io) { int i; - //this->set_description(exchange_ptr->description); + //this->Set_description(exchange_ptr->description); this->n_user = l_n_user; this->n_user_end = l_n_user; this->pitzer_exchange_gammas = @@ -467,7 +467,7 @@ cxxExchange::Set_pitzer_exchange_gammas(bool b) } const std::map < std::string, cxxExchComp > & -cxxExchange::get_exchComps(void) const +cxxExchange::Get_exchComps(void) const { return (this->exchComps); } diff --git a/Exchange.h b/Exchange.h index f0c0b70e..503f42ad 100644 --- a/Exchange.h +++ b/Exchange.h @@ -32,7 +32,7 @@ public: bool Get_pitzer_exchange_gammas() const; void Set_pitzer_exchange_gammas(bool b); - const std::map < std::string, cxxExchComp > &get_exchComps(void) const; + const std::map < std::string, cxxExchComp > &Get_exchComps(void) const; void totalize(); const cxxNameDouble & Get_totals() const; diff --git a/GasPhase.cxx b/GasPhase.cxx index c9890fb4..89620c3e 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -46,7 +46,7 @@ cxxNumKeyword(io) { int i; - this->set_description(gas_phase_ptr->description); + this->Set_description(gas_phase_ptr->description); n_user = gas_phase_ptr->n_user; n_user_end = gas_phase_ptr->n_user_end; if (gas_phase_ptr->type == PRESSURE) diff --git a/GasPhase.h b/GasPhase.h index eb5f96dc..f502e6d8 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -41,7 +41,7 @@ class cxxGasPhase:public cxxNumKeyword void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return this->totals; }; diff --git a/ISolution.cxx b/ISolution.cxx index 582776df..53b73d9b 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -58,9 +58,9 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(iter->first.c_str()); if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; - //if (iter->second.get_description() == "H(1)" || iter->second.get_description() == "E") continue; - if (strcmp(iter->second.get_description().c_str(), "H(1)") == 0 - || strcmp(iter->second.get_description().c_str(), "E")) + //if (iter->second.Get_description() == "H(1)" || iter->second.Get_description() == "E") continue; + if (strcmp(iter->second.Get_description().c_str(), "H(1)") == 0 + || strcmp(iter->second.Get_description().c_str(), "E")) continue; if (iter->second.get_input_conc() <= 0.0) continue; @@ -88,7 +88,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) { std::ostringstream oss; oss << "Could not find gfw, " << iter->second. - get_description(); + Get_description(); error_msg(oss.str().c_str(), CONTINUE); //P_INSTANCE_POINTER input_error++; } @@ -259,7 +259,7 @@ cxxISolution & cxxISolution::read(CParser & parser) { break; } - conc.set_description("H(1)"); + conc.Set_description("H(1)"); sol.add(conc); } break; @@ -278,7 +278,7 @@ cxxISolution & cxxISolution::read(CParser & parser) { break; } - conc.set_description("E"); + conc.Set_description("E"); sol.add(conc); } break; @@ -340,7 +340,7 @@ cxxISolution & cxxISolution::read(CParser & parser) std::vector < cxxISolutionComp >::iterator iter = sol.totals.begin(); for (; iter != sol.totals.end(); ++iter) { - token = (*iter).get_description(); + token = (*iter).Get_description(); Utilities::str_tolower(token); if ((*iter).get_units().empty()) { diff --git a/ISolution.h b/ISolution.h index 973eabe8..e97c7d56 100644 --- a/ISolution.h +++ b/ISolution.h @@ -24,24 +24,24 @@ class cxxISolution:public cxxSolution //static cxxISolution& read(CParser& parser); //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - double get_density() const + double Get_density() const { return this->density; } - void set_density(double l_density) + void Set_density(double l_density) { this->density = l_density; } - std::string get_units() const + std::string Get_units() const { return units; } - void set_units(std::string l_units) + void Set_units(std::string l_units) { units = l_units; } - void set_units(char * l_units) + void Set_units(char * l_units) { if (l_units != NULL) this->units = std::string(l_units); diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 44c28b5f..490529e4 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -31,14 +31,14 @@ gfw(0.0) cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr, PHRQ_io *io) : PHRQ_base(io) { - this->set_description(conc_ptr->description); + this->Set_description(conc_ptr->description); moles = conc_ptr->moles; input_conc = conc_ptr->input_conc; - this->set_units(conc_ptr->units); - this->set_equation_name(conc_ptr->equation_name); + this->Set_units(conc_ptr->units); + this->Set_equation_name(conc_ptr->equation_name); phase_si = conc_ptr->phase_si; n_pe = conc_ptr->n_pe; - this->set_as(conc_ptr->as); + this->Set_as(conc_ptr->as); gfw = conc_ptr->gfw; //skip = conc_ptr->skip; //phase = conc_ptr->phase; diff --git a/ISolutionComp.h b/ISolutionComp.h index 9d088d25..b30844aa 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -22,11 +22,11 @@ class cxxISolutionComp: public PHRQ_base void dump_xml(std::ostream & os, unsigned int indent = 0) const; - const std::string &get_description() const + const std::string &Get_description() const { return this->description; } - void set_description(char *l_description) + void Set_description(char *l_description) { if (l_description != NULL) this->description = std::string(l_description); @@ -34,29 +34,29 @@ class cxxISolutionComp: public PHRQ_base this->description.clear(); } - double get_moles() const + double Get_moles() const { return this->moles; } - void set_moles(double l_moles) + void Set_moles(double l_moles) { this->moles = l_moles; } - double get_input_conc() const + double Get_input_conc() const { return this->input_conc; } - void set_input_conc(double l_input_conc) + void Set_input_conc(double l_input_conc) { this->input_conc = l_input_conc; } - std::string get_units()const + std::string Get_units()const { return this->units; } - void set_units(char *l_units) + void Set_units(char *l_units) { if (l_units != NULL) this->units = std::string(l_units); @@ -64,11 +64,11 @@ class cxxISolutionComp: public PHRQ_base this->units.clear(); } - const std::string &get_equation_name() const + const std::string &Get_equation_name() const { return this->equation_name; } - void set_equation_name(char *l_equation_name) + void Set_equation_name(char *l_equation_name) { if (l_equation_name != NULL) this->equation_name = std::string(l_equation_name); @@ -77,29 +77,29 @@ class cxxISolutionComp: public PHRQ_base } - double get_phase_si() const + double Get_phase_si() const { return this->phase_si; } - void set_phase_si(int l_phase_si) + void Set_phase_si(int l_phase_si) { this->phase_si = l_phase_si; } - int get_n_pe() const + int Get_n_pe() const { return this->n_pe; } - void set_n_pe(int l_n_pe) + void Set_n_pe(int l_n_pe) { this->n_pe = l_n_pe; } - const std::string &get_as() const + const std::string &Get_as() const { return this->as; } - void set_as(char *l_as) + void Set_as(char *l_as) { if (l_as != NULL) this->as = std::string(l_as); @@ -108,15 +108,15 @@ class cxxISolutionComp: public PHRQ_base } //double get_gfw()const {return this->gfw;} - double get_gfw() const + double Get_gfw() const { return this->gfw; }; - void set_gfw(double l_gfw) + void Set_gfw(double l_gfw) { this->gfw = l_gfw; } - //void set_gfw(PHREEQC_PTR_ARG); + //void Set_gfw(PHREEQC_PTR_ARG); bool operator<(const cxxISolutionComp & conc) const { diff --git a/NumKeyword.h b/NumKeyword.h index ebe78407..a280a9ea 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -14,39 +14,39 @@ class cxxNumKeyword: public PHRQ_base public: cxxNumKeyword(PHRQ_io *io=NULL); virtual ~ cxxNumKeyword(); - const std::string &get_description() const + const std::string &Get_description() const { return this->description; } - //char *get_description() const + //char *Get_description() const //{ // return string_duplicate(this->description.c_str()); //} - void set_description(std::string str) + void Set_description(std::string str) { this->description = str; } - void set_description(char *str) + void Set_description(char *str) { if (str != NULL) this->description = str; } - int get_n_user() const + int Get_n_user() const { return this->n_user; } - void set_n_user(int user) + void Set_n_user(int user) { this->n_user = user; } - int get_n_user_end() const + int Get_n_user_end() const { return this->n_user_end; } - void set_n_user_end(int user_end) + void Set_n_user_end(int user_end) { this->n_user_end = user_end; } diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 356b7b03..1a8cf9be 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -42,7 +42,7 @@ eltList(pp_assemblage_ptr->next_elt) { int i; - this->set_description(pp_assemblage_ptr->description); + this->Set_description(pp_assemblage_ptr->description); n_user = pp_assemblage_ptr->n_user; n_user_end = pp_assemblage_ptr->n_user_end; for (i = 0; i < pp_assemblage_ptr->count_comps; i++) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 735f1d45..7e0ab29a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -496,7 +496,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxGasPhase entity(&gas_phase[i], &phrq_io); entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // solid-solutions @@ -504,7 +504,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxSSassemblage entity(&s_s_assemblage[i]); entity.totalize(this); - accumulator.add_extensive(entity.get_totals(), 1.0); + accumulator.add_extensive(entity.Get_totals(), 1.0); } // kinetics diff --git a/Reaction.cxx b/Reaction.cxx index 8e6ef4dc..177f7d8d 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -45,7 +45,7 @@ elementList(irrev_ptr->elts) { int i; - this->set_description(irrev_ptr->description); + this->Set_description(irrev_ptr->description); this->n_user = irrev_ptr->n_user; this->n_user_end = irrev_ptr->n_user_end; this->Set_units(irrev_ptr->units); diff --git a/ReadClass.cxx b/ReadClass.cxx index 8aaa2c52..809dfd21 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1973,18 +1973,18 @@ dump_entities(void) } std::ofstream dump_stream; - if (dump_info.get_append()) + if (dump_info.Get_append()) { //dump_stream.open(dump_info.get_file_name(), std::ios_base::app); - dump_stream.open(dump_info.get_file_name().c_str(), std::ios_base::app); + dump_stream.open(dump_info.Get_file_name().c_str(), std::ios_base::app); } else { - dump_stream.open(dump_info.get_file_name().c_str()); + dump_stream.open(dump_info.Get_file_name().c_str()); } if (!dump_stream.is_open()) { - sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.get_file_name().c_str()); + sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.Get_file_name().c_str()); error_msg(error_string, STOP); } diff --git a/SSassemblage.cxx b/SSassemblage.cxx index b0881cbf..92e0991c 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -41,7 +41,7 @@ cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr, PHR cxxNumKeyword(io) { int i; - this->set_description(s_s_assemblage_ptr->description); + this->Set_description(s_s_assemblage_ptr->description); n_user = s_s_assemblage_ptr->n_user; n_user_end = s_s_assemblage_ptr->n_user_end; for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) diff --git a/SSassemblage.h b/SSassemblage.h index 6dd48d66..bb7a6800 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -32,7 +32,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - const std::map & get_ssAssemblageSSs() const + const std::map & Get_ssAssemblageSSs() const { return this->ssAssemblageSSs; }; @@ -43,7 +43,7 @@ public: #endif void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & get_totals() const + const cxxNameDouble & Get_totals() const { return this->totals; }; diff --git a/Solution.cxx b/Solution.cxx index 2b9f095b..698d859c 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -68,7 +68,7 @@ species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cx isotopes(solution_ptr, io) { - this->set_description(solution_ptr->description); + this->Set_description(solution_ptr->description); this->n_user = solution_ptr->n_user; this->n_user_end = solution_ptr->n_user_end; this->tc = solution_ptr->tc; @@ -148,7 +148,7 @@ cxxNumKeyword(io), isotopes(io) { - //this->set_description none; + //this->Set_description none; this->n_user = l_n_user; this->n_user_end = l_n_user; this->tc = P_INSTANCE_POINTER tc_x; diff --git a/StorageBin.cxx b/StorageBin.cxx index 69707a9e..8163d7cf 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -166,7 +166,7 @@ cxxStorageBin::~cxxStorageBin() { } cxxSolution * -cxxStorageBin::getSolution(int n_user) +cxxStorageBin::Get_Solution(int n_user) { if (this->Solutions.find(n_user) != this->Solutions.end()) { @@ -175,14 +175,14 @@ cxxStorageBin::getSolution(int n_user) return (NULL); } void -cxxStorageBin::setSolution(int n_user, cxxSolution * entity) +cxxStorageBin::Set_Solution(int n_user, cxxSolution * entity) { if (entity == NULL) return; Solutions[n_user] = *entity; } void -cxxStorageBin::setSolution(int n_user, cxxSolution & entity) +cxxStorageBin::Set_Solution(int n_user, cxxSolution & entity) { Solutions[n_user] = entity; } @@ -193,7 +193,7 @@ cxxStorageBin::removeSolution(int n_user) } cxxExchange * -cxxStorageBin::getExchange(int n_user) +cxxStorageBin::Get_Exchange(int n_user) { if (this->Exchangers.find(n_user) != this->Exchangers.end()) { @@ -202,7 +202,7 @@ cxxStorageBin::getExchange(int n_user) return (NULL); } void -cxxStorageBin::setExchange(int n_user, cxxExchange * entity) +cxxStorageBin::Set_Exchange(int n_user, cxxExchange * entity) { if (entity == NULL) return; @@ -215,7 +215,7 @@ cxxStorageBin::removeExchange(int n_user) } cxxPPassemblage * -cxxStorageBin::getPPassemblage(int n_user) +cxxStorageBin::Get_PPassemblage(int n_user) { if (this->PPassemblages.find(n_user) != this->PPassemblages.end()) { @@ -224,14 +224,14 @@ cxxStorageBin::getPPassemblage(int n_user) return (NULL); } void -cxxStorageBin::setPPassemblage(int n_user, cxxPPassemblage * entity) +cxxStorageBin::Set_PPassemblage(int n_user, cxxPPassemblage * entity) { if (entity == NULL) return; PPassemblages[n_user] = *entity; } void -cxxStorageBin::setPPassemblage(int n_user, cxxPPassemblage & entity) +cxxStorageBin::Set_PPassemblage(int n_user, cxxPPassemblage & entity) { PPassemblages[n_user] = entity; } @@ -242,7 +242,7 @@ cxxStorageBin::removePPassemblage(int n_user) } cxxGasPhase * -cxxStorageBin::getGasPhase(int n_user) +cxxStorageBin::Get_GasPhase(int n_user) { if (this->GasPhases.find(n_user) != this->GasPhases.end()) { @@ -251,7 +251,7 @@ cxxStorageBin::getGasPhase(int n_user) return (NULL); } void -cxxStorageBin::setGasPhase(int n_user, cxxGasPhase * entity) +cxxStorageBin::Set_GasPhase(int n_user, cxxGasPhase * entity) { if (entity == NULL) return; @@ -264,7 +264,7 @@ cxxStorageBin::removeGasPhase(int n_user) } cxxSSassemblage * -cxxStorageBin::getSSassemblage(int n_user) +cxxStorageBin::Get_SSassemblage(int n_user) { if (this->SSassemblages.find(n_user) != this->SSassemblages.end()) { @@ -273,14 +273,14 @@ cxxStorageBin::getSSassemblage(int n_user) return (NULL); } void -cxxStorageBin::setSSassemblage(int n_user, cxxSSassemblage * entity) +cxxStorageBin::Set_SSassemblage(int n_user, cxxSSassemblage * entity) { if (entity == NULL) return; SSassemblages[n_user] = *entity; } void -cxxStorageBin::setSSassemblage(int n_user, cxxSSassemblage & entity) +cxxStorageBin::Set_SSassemblage(int n_user, cxxSSassemblage & entity) { SSassemblages[n_user] = entity; } @@ -291,7 +291,7 @@ cxxStorageBin::removeSSassemblage(int n_user) } cxxKinetics * -cxxStorageBin::getKinetics(int n_user) +cxxStorageBin::Get_Kinetics(int n_user) { if (this->Kinetics.find(n_user) != this->Kinetics.end()) { @@ -300,7 +300,7 @@ cxxStorageBin::getKinetics(int n_user) return (NULL); } void -cxxStorageBin::setKinetics(int n_user, cxxKinetics * entity) +cxxStorageBin::Set_Kinetics(int n_user, cxxKinetics * entity) { if (entity == NULL) return; @@ -313,7 +313,7 @@ cxxStorageBin::removeKinetics(int n_user) } cxxSurface * -cxxStorageBin::getSurface(int n_user) +cxxStorageBin::Get_Surface(int n_user) { if (this->Surfaces.find(n_user) != this->Surfaces.end()) { @@ -322,7 +322,7 @@ cxxStorageBin::getSurface(int n_user) return (NULL); } void -cxxStorageBin::setSurface(int n_user, cxxSurface * entity) +cxxStorageBin::Set_Surface(int n_user, cxxSurface * entity) { if (entity == NULL) return; @@ -335,7 +335,7 @@ cxxStorageBin::removeSurface(int n_user) } cxxMix * -cxxStorageBin::getMix(int n_user) +cxxStorageBin::Get_Mix(int n_user) { if (this->Mixes.find(n_user) != this->Mixes.end()) { @@ -344,7 +344,7 @@ cxxStorageBin::getMix(int n_user) return (NULL); } void -cxxStorageBin::setMix(int n_user, cxxMix * entity) +cxxStorageBin::Set_Mix(int n_user, cxxMix * entity) { if (entity == NULL) return; @@ -357,7 +357,7 @@ cxxStorageBin::removeMix(int n_user) } cxxReaction * -cxxStorageBin::getReaction(int n_user) +cxxStorageBin::Get_Reaction(int n_user) { if (this->Reactions.find(n_user) != this->Reactions.end()) { @@ -366,7 +366,7 @@ cxxStorageBin::getReaction(int n_user) return (NULL); } void -cxxStorageBin::setReaction(int n_user, cxxReaction * entity) +cxxStorageBin::Set_Reaction(int n_user, cxxReaction * entity) { if (entity == NULL) return; @@ -379,7 +379,7 @@ cxxStorageBin::removeReaction(int n_user) } cxxTemperature * -cxxStorageBin::getTemperature(int n_user) +cxxStorageBin::Get_Temperature(int n_user) { if (this->Temperatures.find(n_user) != this->Temperatures.end()) { @@ -388,7 +388,7 @@ cxxStorageBin::getTemperature(int n_user) return (NULL); } void -cxxStorageBin::setTemperature(int n_user, cxxTemperature * entity) +cxxStorageBin::Set_Temperature(int n_user, cxxTemperature * entity) { if (entity == NULL) return; @@ -401,37 +401,37 @@ cxxStorageBin::removeTemperature(int n_user) } const std::map < int, cxxSolution > & -cxxStorageBin::getSolutions() const +cxxStorageBin::Get_Solutions() const { return this->Solutions; } const std::map < int, cxxExchange > & -cxxStorageBin::getExchangers() const +cxxStorageBin::Get_Exchangers() const { return this->Exchangers; } const std::map < int, cxxGasPhase > & -cxxStorageBin::getGasPhases() const +cxxStorageBin::Get_GasPhases() const { return this->GasPhases; } const std::map < int, cxxKinetics > & -cxxStorageBin::getKinetics() const +cxxStorageBin::Get_Kinetics() const { return this->Kinetics; } const std::map < int, cxxPPassemblage > & -cxxStorageBin::getPPassemblages() const +cxxStorageBin::Get_PPassemblages() const { return this->PPassemblages; } const std::map < int, cxxSSassemblage > & -cxxStorageBin::getSSassemblages() const +cxxStorageBin::Get_SSassemblages() const { return this->SSassemblages; } const std::map < int, cxxSurface > & -cxxStorageBin::getSurfaces() const +cxxStorageBin::Get_Surfaces() const { return this->Surfaces; } @@ -593,45 +593,45 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent) s_oss.precision(DBL_DIG - 1); // Solutions - if (this->getSolution(n) != NULL) + if (this->Get_Solution(n) != NULL) { - this->getSolution(n)->dump_raw(s_oss, indent); + this->Get_Solution(n)->dump_raw(s_oss, indent); } // Exchange - if (this->getExchange(n) != NULL) + if (this->Get_Exchange(n) != NULL) { - this->getExchange(n)->dump_raw(s_oss, indent); + this->Get_Exchange(n)->dump_raw(s_oss, indent); } // Gas Phases - if (this->getGasPhase(n) != NULL) + if (this->Get_GasPhase(n) != NULL) { - this->getGasPhase(n)->dump_raw(s_oss, indent); + this->Get_GasPhase(n)->dump_raw(s_oss, indent); } // Kinetics - if (this->getKinetics(n) != NULL) + if (this->Get_Kinetics(n) != NULL) { - this->getKinetics(n)->dump_raw(s_oss, indent); + this->Get_Kinetics(n)->dump_raw(s_oss, indent); } // PPassemblage - if (this->getPPassemblage(n) != NULL) + if (this->Get_PPassemblage(n) != NULL) { - this->getPPassemblage(n)->dump_raw(s_oss, indent); + this->Get_PPassemblage(n)->dump_raw(s_oss, indent); } // SSassemblage - if (this->getSSassemblage(n) != NULL) + if (this->Get_SSassemblage(n) != NULL) { - this->getSSassemblage(n)->dump_raw(s_oss, indent); + this->Get_SSassemblage(n)->dump_raw(s_oss, indent); } // Surface - if (this->getSurface(n) != NULL) + if (this->Get_Surface(n) != NULL) { - this->getSurface(n)->dump_raw(s_oss, indent); + this->Get_Surface(n)->dump_raw(s_oss, indent); } } @@ -671,7 +671,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxSolution entity(this->Get_io()); entity.read_raw(parser); - Solutions[entity.get_n_user()] = entity; + Solutions[entity.Get_n_user()] = entity; } break; @@ -679,7 +679,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxExchange entity(this->Get_io()); entity.read_raw(parser); - Exchangers[entity.get_n_user()] = entity; + Exchangers[entity.Get_n_user()] = entity; } break; @@ -687,7 +687,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxGasPhase entity(this->Get_io()); entity.read_raw(parser); - GasPhases[entity.get_n_user()] = entity; + GasPhases[entity.Get_n_user()] = entity; } break; @@ -695,7 +695,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxKinetics entity(this->Get_io()); entity.read_raw(parser); - Kinetics[entity.get_n_user()] = entity; + Kinetics[entity.Get_n_user()] = entity; } break; @@ -703,7 +703,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxPPassemblage entity(this->Get_io()); entity.read_raw(parser); - PPassemblages[entity.get_n_user()] = entity; + PPassemblages[entity.Get_n_user()] = entity; } break; @@ -711,7 +711,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxSSassemblage entity; entity.read_raw(parser); - SSassemblages[entity.get_n_user()] = entity; + SSassemblages[entity.Get_n_user()] = entity; } break; @@ -719,7 +719,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxSurface entity(this->Get_io()); entity.read_raw(parser); - Surfaces[entity.get_n_user()] = entity; + Surfaces[entity.Get_n_user()] = entity; } break; @@ -727,7 +727,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxTemperature entity(this->Get_io()); entity.read_raw(parser); - Temperatures[entity.get_n_user()] = entity; + Temperatures[entity.Get_n_user()] = entity; } break; @@ -735,7 +735,7 @@ cxxStorageBin::read_raw(CParser & parser) { cxxReaction entity; entity.read_raw(parser, true); - Reactions[entity.get_n_user()] = entity; + Reactions[entity.Get_n_user()] = entity; } break; default: @@ -782,8 +782,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxSolution entity(this->Get_io()); entity.read_raw(parser); - Solutions[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Solutions[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -791,8 +791,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxExchange entity(this->Get_io()); entity.read_raw(parser); - Exchangers[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Exchangers[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -800,8 +800,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxGasPhase entity(this->Get_io()); entity.read_raw(parser); - GasPhases[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + GasPhases[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -809,8 +809,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxKinetics entity(this->Get_io()); entity.read_raw(parser); - Kinetics[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Kinetics[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -818,8 +818,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxPPassemblage entity(this->Get_io()); entity.read_raw(parser); - PPassemblages[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + PPassemblages[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -827,8 +827,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxSSassemblage entity; entity.read_raw(parser); - SSassemblages[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + SSassemblages[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -836,8 +836,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxSurface entity(this->Get_io()); entity.read_raw(parser); - Surfaces[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Surfaces[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -845,8 +845,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxTemperature entity(this->Get_io()); entity.read_raw(parser); - Temperatures[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Temperatures[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -854,8 +854,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) { cxxReaction entity; entity.read_raw(parser, true); - Reactions[entity.get_n_user()] = entity; - entity_number = entity.get_n_user(); + Reactions[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); } break; @@ -1486,7 +1486,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxSolution entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setSolution(entity.get_n_user(), &entity); + this->setSolution(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked Solution" << std::endl; @@ -1495,7 +1495,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxExchange entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setExchange(entity.get_n_user(), &entity); + this->setExchange(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked Exchange" << std::endl; @@ -1504,7 +1504,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxGasPhase entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setGasPhase(entity.get_n_user(), &entity); + this->setGasPhase(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked GasPhase" << std::endl; @@ -1513,7 +1513,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxKinetics entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setKinetics(entity.get_n_user(), &entity); + this->setKinetics(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked Kinetics" << std::endl; @@ -1522,7 +1522,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxPPassemblage entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setPPassemblage(entity.get_n_user(), &entity); + this->setPPassemblage(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked PPassemblage" << std::endl; @@ -1531,7 +1531,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxSSassemblage entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setSSassemblage(entity.get_n_user(), &entity); + this->setSSassemblage(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked SSassemblage" << std::endl; @@ -1540,7 +1540,7 @@ cxxStorageBin::mpi_recv(int task_number) { cxxSurface entity; entity.mpi_unpack(ints, &i, doubles, &d); - this->setSurface(entity.get_n_user(), &entity); + this->setSurface(entity.Get_n_user(), &entity); } //std::cerr << "Unpacked Surface" << std::endl; @@ -1657,13 +1657,13 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) #endif cxxSystem & -cxxStorageBin::getSystem(void) +cxxStorageBin::Get_System(void) { return this->system; } void -cxxStorageBin::setSystem(struct Use *use_ptr) +cxxStorageBin::Set_System(struct Use *use_ptr) { // Initialize this->system.Initialize(); @@ -1674,7 +1674,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Solutions.find(use_ptr->n_solution_user); if (it != this->Solutions.end()) { - this->system.setSolution(&(it->second)); + this->system.Set_Solution(&(it->second)); } } // Exchange @@ -1684,7 +1684,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Exchangers.find(use_ptr->n_exchange_user); if (it != this->Exchangers.end()) { - this->system.setExchange(&(it->second)); + this->system.Set_Exchange(&(it->second)); } } // gas_phase @@ -1694,7 +1694,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->GasPhases.find(use_ptr->n_gas_phase_user); if (it != this->GasPhases.end()) { - this->system.setGasPhase(&(it->second)); + this->system.Set_GasPhase(&(it->second)); } } // kinetics @@ -1704,7 +1704,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Kinetics.find(use_ptr->n_kinetics_user); if (it != this->Kinetics.end()) { - this->system.setKinetics(&(it->second)); + this->system.Set_Kinetics(&(it->second)); } } // pp_assemblage @@ -1714,7 +1714,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->PPassemblages.find(use_ptr->n_pp_assemblage_user); if (it != this->PPassemblages.end()) { - this->system.setPPassemblage(&(it->second)); + this->system.Set_PPassemblage(&(it->second)); } } // s_s_assemblage @@ -1724,7 +1724,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->SSassemblages.find(use_ptr->n_s_s_assemblage_user); if (it != this->SSassemblages.end()) { - this->system.setSSassemblage(&(it->second)); + this->system.Set_SSassemblage(&(it->second)); } } // surface @@ -1734,7 +1734,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Surfaces.find(use_ptr->n_surface_user); if (it != this->Surfaces.end()) { - this->system.setSurface(&(it->second)); + this->system.Set_Surface(&(it->second)); } } // mix @@ -1744,7 +1744,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Mixes.find(use_ptr->n_mix_user); if (it != this->Mixes.end()) { - this->system.setMix(&(it->second)); + this->system.Set_Mix(&(it->second)); } } // reaction @@ -1754,7 +1754,7 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Reactions.find(use_ptr->n_irrev_user); if (it != this->Reactions.end()) { - this->system.setReaction(&(it->second)); + this->system.Set_Reaction(&(it->second)); } } // reaction temperature @@ -1764,12 +1764,12 @@ cxxStorageBin::setSystem(struct Use *use_ptr) this->Temperatures.find(use_ptr->n_temperature_user); if (it != this->Temperatures.end()) { - this->system.setTemperature(&(it->second)); + this->system.Set_Temperature(&(it->second)); } } } void -cxxStorageBin::setSystem(int i) +cxxStorageBin::Set_System(int i) { // Initialize this->system.Initialize(); @@ -1778,7 +1778,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxSolution >::iterator it = this->Solutions.find(i); if (it != this->Solutions.end()) { - this->system.setSolution(&(it->second)); + this->system.Set_Solution(&(it->second)); } } @@ -1787,7 +1787,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxExchange >::iterator it = this->Exchangers.find(i); if (it != this->Exchangers.end()) { - this->system.setExchange(&(it->second)); + this->system.Set_Exchange(&(it->second)); } } @@ -1796,7 +1796,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(i); if (it != this->GasPhases.end()) { - this->system.setGasPhase(&(it->second)); + this->system.Set_GasPhase(&(it->second)); } } // kinetics @@ -1804,7 +1804,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(i); if (it != this->Kinetics.end()) { - this->system.setKinetics(&(it->second)); + this->system.Set_Kinetics(&(it->second)); } } // pp_assemblage @@ -1812,7 +1812,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxPPassemblage >::iterator it = this->PPassemblages.find(i); if (it != this->PPassemblages.end()) { - this->system.setPPassemblage(&(it->second)); + this->system.Set_PPassemblage(&(it->second)); } } // s_s_assemblage @@ -1820,7 +1820,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxSSassemblage >::iterator it = this->SSassemblages.find(i); if (it != this->SSassemblages.end()) { - this->system.setSSassemblage(&(it->second)); + this->system.Set_SSassemblage(&(it->second)); } } // surface @@ -1828,7 +1828,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxSurface >::iterator it = this->Surfaces.find(i); if (it != this->Surfaces.end()) { - this->system.setSurface(&(it->second)); + this->system.Set_Surface(&(it->second)); } } // mix @@ -1836,7 +1836,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxMix >::iterator it = this->Mixes.find(i); if (it != this->Mixes.end()) { - this->system.setMix(&(it->second)); + this->system.Set_Mix(&(it->second)); } } // reaction @@ -1844,7 +1844,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxReaction >::iterator it = this->Reactions.find(i); if (it != this->Reactions.end()) { - this->system.setReaction(&(it->second)); + this->system.Set_Reaction(&(it->second)); } } // reaction temperature @@ -1852,7 +1852,7 @@ cxxStorageBin::setSystem(int i) std::map < int, cxxTemperature >::iterator it = this->Temperatures.find(i); if (it != this->Temperatures.end()) { - this->system.setTemperature(&(it->second)); + this->system.Set_Temperature(&(it->second)); } } } diff --git a/StorageBin.h b/StorageBin.h index a813931f..757d2c4f 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -24,63 +24,56 @@ class cxxStorageBin: public PHRQ_base public: cxxStorageBin(PHRQ_io *io=NULL); - //cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io *io=NULL); - ~cxxStorageBin(); - - //void import_phreeqc(PHREEQC_PTR_ARG); - - //void cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n); - - //void phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n); + ~cxxStorageBin(); void remove(int n); - cxxSolution *getSolution(int n_user); - void setSolution(int n_user, cxxSolution * entity); - void setSolution(int n_user, cxxSolution & entity); + cxxSolution *Get_Solution(int n_user); + void Set_Solution(int n_user, cxxSolution * entity); + void Set_Solution(int n_user, cxxSolution & entity); void removeSolution(int n_user); - cxxExchange *getExchange(int n_user); - void setExchange(int n_user, cxxExchange * entity); + cxxExchange *Get_Exchange(int n_user); + void Set_Exchange(int n_user, cxxExchange * entity); void removeExchange(int n_user); - cxxPPassemblage *getPPassemblage(int n_user); - void setPPassemblage(int n_user, cxxPPassemblage * entity); - void setPPassemblage(int n_user, cxxPPassemblage & entity); + cxxPPassemblage *Get_PPassemblage(int n_user); + void Set_PPassemblage(int n_user, cxxPPassemblage * entity); + void Set_PPassemblage(int n_user, cxxPPassemblage & entity); void removePPassemblage(int n_user); - cxxGasPhase *getGasPhase(int n_user); - void setGasPhase(int n_user, cxxGasPhase * entity); + cxxGasPhase *Get_GasPhase(int n_user); + void Set_GasPhase(int n_user, cxxGasPhase * entity); void removeGasPhase(int n_user); - cxxSSassemblage *getSSassemblage(int n_user); - void setSSassemblage(int n_user, cxxSSassemblage * entity); - void setSSassemblage(int n_user, cxxSSassemblage & entity); + cxxSSassemblage *Get_SSassemblage(int n_user); + void Set_SSassemblage(int n_user, cxxSSassemblage * entity); + void Set_SSassemblage(int n_user, cxxSSassemblage & entity); void removeSSassemblage(int n_user); - cxxKinetics *getKinetics(int n_user); - void setKinetics(int n_user, cxxKinetics * entity); + cxxKinetics *Get_Kinetics(int n_user); + void Set_Kinetics(int n_user, cxxKinetics * entity); void removeKinetics(int n_user); - cxxSurface *getSurface(int n_user); - void setSurface(int n_user, cxxSurface * entity); + cxxSurface *Get_Surface(int n_user); + void Set_Surface(int n_user, cxxSurface * entity); void removeSurface(int n_user); - cxxMix *getMix(int n_user); - void setMix(int n_user, cxxMix * entity); + cxxMix *Get_Mix(int n_user); + void Set_Mix(int n_user, cxxMix * entity); void removeMix(int n_user); - cxxReaction *getReaction(int n_user); - void setReaction(int n_user, cxxReaction * entity); + cxxReaction *Get_Reaction(int n_user); + void Set_Reaction(int n_user, cxxReaction * entity); void removeReaction(int n_user); - cxxTemperature *getTemperature(int n_user); - void setTemperature(int n_user, cxxTemperature * entity); + cxxTemperature *Get_Temperature(int n_user); + void Set_Temperature(int n_user, cxxTemperature * entity); void removeTemperature(int n_user); - cxxSystem &getSystem(void); - void setSystem(struct Use *use_ptr); - void setSystem(int i); + cxxSystem &Get_System(void); + void Set_System(struct Use *use_ptr); + void Set_System(int i); void dump_raw(std::ostream & s_oss, unsigned int indent) const; @@ -96,13 +89,13 @@ class cxxStorageBin: public PHRQ_base //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); - const std::map < int, cxxSolution > &getSolutions() const; - const std::map < int, cxxExchange > &getExchangers() const; - const std::map < int, cxxGasPhase > &getGasPhases() const; - const std::map < int, cxxKinetics > &getKinetics() const; - const std::map < int, cxxPPassemblage > &getPPassemblages() const; - const std::map < int, cxxSSassemblage > &getSSassemblages() const; - const std::map < int, cxxSurface > &getSurfaces() const; + const std::map < int, cxxSolution > &Get_Solutions() const; + const std::map < int, cxxExchange > &Get_Exchangers() const; + const std::map < int, cxxGasPhase > &Get_GasPhases() const; + const std::map < int, cxxKinetics > &Get_Kinetics() const; + const std::map < int, cxxPPassemblage > &Get_PPassemblages() const; + const std::map < int, cxxSSassemblage > &Get_SSassemblages() const; + const std::map < int, cxxSurface > &Get_Surfaces() const; cxxSystem & Get_system(void) {return system;}; #ifdef USE_MPI diff --git a/Surface.cxx b/Surface.cxx index 4f3ca0eb..a1219f85 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -52,7 +52,7 @@ cxxNumKeyword(io) { int i; - this->set_description(surface_ptr->description); + this->Set_description(surface_ptr->description); n_user = surface_ptr->n_user; n_user_end = surface_ptr->n_user_end; type = surface_ptr->type; diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 116f2f6c..5dd746cf 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -21,7 +21,7 @@ public: ~cxxSurfaceCharge(); - struct master *get_psi_master(); + struct master *Get_psi_master(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/System.cxx b/System.cxx index d7322297..4f6487b9 100644 --- a/System.cxx +++ b/System.cxx @@ -82,12 +82,12 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) if (this->gasphase != NULL) { this->gasphase->totalize(P_INSTANCE); - this->totals.add_extensive(this->gasphase->get_totals(), 1.0); + this->totals.add_extensive(this->gasphase->Get_totals(), 1.0); } if (this->ssassemblage != NULL) { this->ssassemblage->totalize(P_INSTANCE); - this->totals.add_extensive(this->ssassemblage->get_totals(), 1.0); + this->totals.add_extensive(this->ssassemblage->Get_totals(), 1.0); } if (this->surface != NULL) { diff --git a/System.h b/System.h index 1a685e6b..194f4077 100644 --- a/System.h +++ b/System.h @@ -30,48 +30,48 @@ public: cxxSystem(PHRQ_io *io=NULL); ~cxxSystem(void); void Initialize(void); - void setSolution(cxxSolution * entity) + void Set_Solution(cxxSolution * entity) { this->solution = entity; } - void setExchange(cxxExchange * entity) + void Set_Exchange(cxxExchange * entity) { this->exchange = entity; } - void setPPassemblage(cxxPPassemblage * entity) + void Set_PPassemblage(cxxPPassemblage * entity) { this->ppassemblage = entity; } - void setGasPhase(cxxGasPhase * entity) + void Set_GasPhase(cxxGasPhase * entity) { this->gasphase = entity; } - void setSSassemblage(cxxSSassemblage * entity) + void Set_SSassemblage(cxxSSassemblage * entity) { this->ssassemblage = entity; } - void setKinetics(cxxKinetics * entity) + void Set_Kinetics(cxxKinetics * entity) { this->kinetics = entity; } - void setSurface(cxxSurface * entity) + void Set_Surface(cxxSurface * entity) { this->surface = entity; } - void setMix(cxxMix * entity) + void Set_Mix(cxxMix * entity) { this->mix = entity; } - void setReaction(cxxReaction * entity) + void Set_Reaction(cxxReaction * entity) { this->reaction = entity; } - void setTemperature(cxxTemperature * entity) + void Set_Temperature(cxxTemperature * entity) { this->temperature = entity; } void totalize(PHREEQC_PTR_ARG); - cxxNameDouble &getTotals(void) + cxxNameDouble &Get_Totals(void) { return this->totals; } diff --git a/Temperature.cxx b/Temperature.cxx index d2161f16..2078f4c5 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -43,7 +43,7 @@ cxxNumKeyword(io) { int i; - this->set_description(temperature_ptr->description); + this->Set_description(temperature_ptr->description); this->n_user = temperature_ptr->n_user; this->n_user_end = temperature_ptr->n_user_end; // temps diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index cf0c9305..dad2d947 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -53,7 +53,7 @@ totals(kinetics_ptr->totals) { int i; - this->set_description(kinetics_ptr->description); + this->Set_description(kinetics_ptr->description); n_user = kinetics_ptr->n_user; n_user_end = kinetics_ptr->n_user_end; step_divide = kinetics_ptr->step_divide; diff --git a/cxxMix.cxx b/cxxMix.cxx index 57be1b85..83f2b01d 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -41,7 +41,7 @@ cxxNumKeyword(io) { int i; - this->set_description(mix_ptr->description); + this->Set_description(mix_ptr->description); this->n_user = mix_ptr->n_user; this->n_user_end = mix_ptr->n_user_end; // comps diff --git a/dumper.h b/dumper.h index e3a79e22..44f57f96 100644 --- a/dumper.h +++ b/dumper.h @@ -15,8 +15,8 @@ public: ~dumper(void); bool Read(CParser & parser); void SetAll(bool tf); - std::string get_file_name(void) { return(this->file_name); }; - bool get_append(void) { return(this->append); }; + std::string Get_file_name(void) { return(this->file_name); }; + bool Get_append(void) { return(this->append); }; bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; From 9201846ce1f3542b2ebca1026885a423e7624891 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Sep 2011 20:32:05 +0000 Subject: [PATCH 0264/1077] Added isopen_handler git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5662 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ PHRQ_io.h | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index f1088756..6c3d144a 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -475,6 +475,49 @@ open_handler(const int type, const char *file_name) return 1; } +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_handler(const int type) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_ERROR: + return (error_file != NULL); + break; + case OUTPUT_WARNING: + return (error_file != NULL || output_file != NULL); + break; + case OUTPUT_MESSAGE: + return (output_file != NULL); + break; + case OUTPUT_PUNCH: + return (punch_file != NULL); + break; + case OUTPUT_SCREEN: + return (error_file != NULL); + break; + case OUTPUT_LOG: + return (log_file != NULL); + break; + case OUTPUT_DUMP: + return (dump_file != NULL); + break; + case OUTPUT_STDERR: + return (stderr != NULL); + break; + case OUTPUT_CHECKLINE: + case OUTPUT_GUI_ERROR: + case OUTPUT_BASIC: + case OUTPUT_CVODE: + case OUTPUT_SEND_MESSAGE: + case OUTPUT_ECHO: + case OUTPUT_PUNCH_END_ROW: + return (output_file != NULL); + break; + } + return false; +} /* ---------------------------------------------------------------------- */ int PHRQ_io:: fileop_handler(const int type, int (*PFN) (FILE *)) diff --git a/PHRQ_io.h b/PHRQ_io.h index a1f34116..2a716fbc 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -42,7 +42,7 @@ typedef enum int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args); int open_handler(const int type, const char *file_name); - + bool isopen_handler(const int type); int fileop_handler(const int type, int (*PFN) (FILE *)); int output_handler(const int type, const char *err_str, const bool stop, const char *format, From 4d3231479e869dbdc398065da3fc5931999bf3d8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Sep 2011 23:22:18 +0000 Subject: [PATCH 0265/1077] Changed longjmp to throw for PHREEQC_CLASS added some safe_close for PHRQ_io.cpp added isopen_handler git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5663 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 2 +- PHRQ_io.cpp | 37 ++++++++++++++++++------------------- PHRQ_io.h | 4 +++- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 31b5d2fc..dc409435 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -36,7 +36,7 @@ error_msg(const std::string & stdstr, int stop) } if (stop != 0) { - throw "PHRQ_base error message"; + throw PhreeqcStop(); } } diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 6c3d144a..3c385427 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -413,17 +413,23 @@ open_handler(const int type, const char *file_name) //return ERROR; return 0; } - else + break; + case OUTPUT_MESSAGE: + if (output_file != NULL) { - //free_check_null(selected_output_file_name); - //selected_output_file_name = string_duplicate(file_name); + safe_close(output_file); + output_file = NULL; + } + if ((output_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; } break; - case OUTPUT_DUMP: if (dump_file != NULL) { - fclose(dump_file); + safe_close(dump_file); dump_file = NULL; } if ((dump_file = fopen(file_name, "w")) == NULL) @@ -431,20 +437,14 @@ open_handler(const int type, const char *file_name) //return ERROR; return 0; } - else - { - //free_check_null(dump_file_name); - //dump_file_name = string_duplicate(file_name); - } break; case OUTPUT_ERROR: - if (error_file != NULL && - error_file != stderr && - error_file != stdout) + if (error_file != NULL) { - fclose(error_file); + safe_close(error_file); error_file = NULL; } + if (file_name != NULL) { if ((error_file = fopen(file_name, "w")) == NULL) @@ -459,11 +459,9 @@ open_handler(const int type, const char *file_name) } break; case OUTPUT_LOG: - if (log_file != NULL && - log_file != stderr && - log_file != stdout) + if (log_file != NULL) { - fclose(log_file); + safe_close(log_file); log_file = NULL; } if ((log_file = fopen(file_name, "w")) == NULL) @@ -592,7 +590,8 @@ safe_close(FILE * file_ptr) { if (file_ptr != stderr && file_ptr != stdout && - file_ptr != stdin) + file_ptr != stdin && + file_ptr != NULL) { fclose(file_ptr); } diff --git a/PHRQ_io.h b/PHRQ_io.h index 2a716fbc..d940ef4f 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -2,7 +2,9 @@ #define _PHRQIO_H #include - +class PhreeqcStop : std::exception +{ +}; class PHRQ_io { public: From 6fa41ac02eeaa9f75012b7c1918d9065ee7b5746 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 30 Sep 2011 18:36:28 +0000 Subject: [PATCH 0266/1077] Rewrote PHRQ_io. Removed handlers. Now 1-1 correspondence between phreeqc output methods and PHRQ_io output methods. Removed error_msg and output_msg from Parser. Moved prototype for fpnunchf, _user, _end_row, to output.h. Scott needs to finalize as interface. Next will remove dead code from PHRQ_io, PHRQ_io_output.cpp, and Parse.cxx. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5665 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 6 - PHRQ_base.cxx | 7 +- PHRQ_io.cpp | 490 ++++++++++++++++++++++++++++++++++++++++++++++-- PHRQ_io.h | 27 ++- Parser.cxx | 7 +- Parser.h | 4 +- Phreeqc.cpp | 201 +++++++------------- Phreeqc.h | 4 - 8 files changed, 574 insertions(+), 172 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 933fa32f..d74fb27a 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -17,12 +17,6 @@ #endif #ifdef PHREEQC_CLASS #include "Phreeqc.h" -#else -extern int error_msg(const char *err_str, const int stop, ...); -extern int warning_msg(const char *err_str, ...); -extern int rate_free(struct rate *rate_ptr); -extern int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -extern void * free_check_null(void *); #endif #include "phqalloc.h" #include "phrqproto.h" diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index dc409435..cb0b5ba5 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -26,8 +26,8 @@ error_msg(const std::string & stdstr, int stop) this->base_error_count++; if (this->io) { - this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_ERROR, stdstr.c_str(), stop!=0, "", NULL); - //this->io->output_string(PHRQ_io::OUTPUT_ERROR, stdstr); +// this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_ERROR, stdstr.c_str(), stop!=0, "", NULL); + this->io->error_msg(stdstr.c_str(), stop!=0); } else { @@ -45,8 +45,9 @@ warning_msg(const std::string & stdstr) { if (this->io) { - this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_WARNING, stdstr.c_str(), false, "", NULL); + //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_WARNING, stdstr.c_str(), false, "", NULL); //this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); + this->io->warning_msg(stdstr.c_str()); } else { diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 3c385427..dc72a0e3 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -30,7 +30,7 @@ PHRQ_io:: ~PHRQ_io() { } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int PHRQ_io:: phreeqc_handler(const int action, const int type, const char *err_str, @@ -95,7 +95,7 @@ phreeqc_handler(const int action, const int type, const char *err_str, } return false; } - +#endif /* ---------------------------------------------------------------------- */ int PHRQ_io:: close_input_files(void) @@ -130,7 +130,7 @@ istream_getc(void *cookie) } return EOF; } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int PHRQ_io:: output_handler(const int type, const char *err_str, const bool stop, @@ -295,6 +295,199 @@ output_handler(const int type, const char *err_str, const bool stop, return 1; } +#endif +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + + io_error_count++; + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "\nERROR: %s\n", err_str); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "ERROR: %s\n", err_str); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "ERROR: %s\n", err_str); + fflush(log_file); + } + if (stop) + { + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "Stopping.\n"); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "Stopping.\n"); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "Stopping.\n"); + fflush(log_file); + } + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "\nWARNING: %s\n", err_str); + fflush(error_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "WARNING: %s\n", err_str); + fflush(log_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "WARNING: %s\n", err_str); + fflush(output_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_msg(int type, const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + int flush = 1; + + switch (type) + { + + case OUTPUT_ERROR: + io_error_count++; + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "\nERROR: "); + vfprintf(error_file, format, args); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "\nERROR: "); + vfprintf(output_file, format, args); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "\nERROR: "); + vfprintf(log_file, format, args); + fflush(log_file); + } + break; + case OUTPUT_WARNING: + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "\nWARNING: "); + vfprintf(error_file, format, args); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "\nWARNING: "); + vfprintf(output_file, format, args); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "\nWARNING: "); + vfprintf(log_file, format, args); + fflush(log_file); + } + break; + case OUTPUT_CHECKLINE: + { + if (output_file != NULL && output_file_on) + { + vfprintf(output_file, format, args); + if (flush) + fflush(output_file); + } + } + break; + case OUTPUT_MESSAGE: + case OUTPUT_BASIC: + if (output_file != NULL && output_file_on) + { + vfprintf(output_file, format, args); + if (flush) + fflush(output_file); + } + break; + case OUTPUT_PUNCH: + if (punch_file != NULL && punch_file_on) + { + { + vfprintf(punch_file, format, args); + if (flush) + fflush(punch_file); + } + } + break; + case OUTPUT_LOG: + if (log_file != NULL && log_file_on) + { + vfprintf(log_file, format, args); + if (flush) + fflush(log_file); + } + break; + case OUTPUT_SCREEN: + if (error_file != NULL && error_file_on) + { + vfprintf(error_file, format, args); + if (flush) + fflush(error_file); + } + break; + case OUTPUT_STDERR: + case OUTPUT_CVODE: + if (stderr != NULL) + { + vfprintf(stderr, format, args); + fflush(stderr); + } + break; + case OUTPUT_DUMP: + if (dump_file != NULL && dump_file_on) + { + vfprintf(dump_file, format, args); + if (flush) + fflush(dump_file); + } + break; + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf(const char *name, const char *format, va_list args) +/* ---------------------------------------------------------------------- */ +{ + int flush = 1; + + if (punch_file != NULL && punch_file_on) + { + { + vfprintf(punch_file, format, args); + if (flush) + fflush(punch_file); + } + } +} /* ---------------------------------------------------------------------- */ void PHRQ_io:: output_string(const int type, std::string str) @@ -393,7 +586,7 @@ close_output_files(void) output_file = log_file = punch_file = dump_file = NULL; return ret; } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int PHRQ_io:: open_handler(const int type, const char *file_name) @@ -472,7 +665,86 @@ open_handler(const int type, const char *file_name) } return 1; } +#endif +/* ---------------------------------------------------------------------- */ +int PHRQ_io:: +output_open(int type, const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_PUNCH: + if (punch_file != NULL) + { + fclose(punch_file); + punch_file = NULL; + } + if ((punch_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; + } + break; + case OUTPUT_MESSAGE: + if (output_file != NULL) + { + safe_close(output_file); + output_file = NULL; + } + if ((output_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; + } + break; + case OUTPUT_DUMP: + if (dump_file != NULL) + { + safe_close(dump_file); + dump_file = NULL; + } + if ((dump_file = fopen(file_name, "w")) == NULL) + { + //return ERROR; + return 0; + } + break; + case OUTPUT_ERROR: + if (error_file != NULL) + { + safe_close(error_file); + error_file = NULL; + } + + if (file_name != NULL) + { + if ((error_file = fopen(file_name, "w")) == NULL) + { + error_file = stderr; + return 0; + } + } + else + { + error_file = stderr; + } + break; + case OUTPUT_LOG: + if (log_file != NULL) + { + safe_close(log_file); + log_file = NULL; + } + if ((log_file = fopen(file_name, "w")) == NULL) + { + return 0; + } + break; + } + return 1; +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ bool PHRQ_io:: isopen_handler(const int type) @@ -504,18 +776,53 @@ isopen_handler(const int type) case OUTPUT_STDERR: return (stderr != NULL); break; - case OUTPUT_CHECKLINE: - case OUTPUT_GUI_ERROR: - case OUTPUT_BASIC: - case OUTPUT_CVODE: - case OUTPUT_SEND_MESSAGE: - case OUTPUT_ECHO: - case OUTPUT_PUNCH_END_ROW: + default: + assert(false); return (output_file != NULL); break; } return false; } +#endif +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +output_isopen(const int type) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_ERROR: + return (error_file != NULL); + break; + case OUTPUT_WARNING: + return (error_file != NULL || output_file != NULL); + break; + case OUTPUT_MESSAGE: + return (output_file != NULL); + break; + case OUTPUT_PUNCH: + return (punch_file != NULL); + break; + case OUTPUT_SCREEN: + return (error_file != NULL); + break; + case OUTPUT_LOG: + return (log_file != NULL); + break; + case OUTPUT_DUMP: + return (dump_file != NULL); + break; + case OUTPUT_STDERR: + return (stderr != NULL); + break; + default: + assert(false); + return (output_file != NULL); + break; + } + return false; +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int PHRQ_io:: fileop_handler(const int type, int (*PFN) (FILE *)) @@ -573,7 +880,167 @@ fileop_handler(const int type, int (*PFN) (FILE *)) return 1; } +#endif +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_fflush(const int type) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_ERROR: + if (error_file) + fflush(error_file); + break; + case OUTPUT_WARNING: + if (error_file) + fflush(error_file); + if (output_file) + fflush(output_file); + break; + + case OUTPUT_MESSAGE: + case OUTPUT_CHECKLINE: + case OUTPUT_BASIC: + if (output_file) + fflush(output_file); + break; + + case OUTPUT_PUNCH: + if (punch_file) + fflush(punch_file); + break; + + case OUTPUT_SCREEN: + if (error_file) + fflush(error_file); + break; + + case OUTPUT_LOG: + if (log_file) + fflush(log_file); + break; + + case OUTPUT_CVODE: + case OUTPUT_STDERR: + if (stderr) + fflush(stderr); + break; + + case OUTPUT_DUMP: + if (dump_file) + fflush(dump_file); + break; + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_rewind(const int type) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_ERROR: + if (error_file) + rewind(error_file); + break; + + case OUTPUT_WARNING: + if (error_file) + rewind(error_file); + if (output_file) + rewind(output_file); + break; + + case OUTPUT_MESSAGE: + case OUTPUT_CHECKLINE: + case OUTPUT_BASIC: + if (output_file) + rewind(output_file); + break; + + case OUTPUT_PUNCH: + if (punch_file) + rewind(punch_file); + break; + + case OUTPUT_SCREEN: + if (error_file) + rewind(error_file); + break; + + case OUTPUT_LOG: + if (log_file) + rewind(log_file); + break; + + case OUTPUT_CVODE: + case OUTPUT_STDERR: + if (stderr) + rewind(stderr); + break; + + case OUTPUT_DUMP: + if (dump_file) + rewind(dump_file); + break; + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_close(const int type) +/* ---------------------------------------------------------------------- */ +{ + switch (type) + { + case OUTPUT_ERROR: + if (error_file) + safe_close(error_file); + break; + + case OUTPUT_WARNING: + if (error_file) + safe_close(error_file); + if (output_file) + safe_close(output_file); + break; + + case OUTPUT_MESSAGE: + case OUTPUT_CHECKLINE: + case OUTPUT_BASIC: + if (output_file) + safe_close(output_file); + break; + + case OUTPUT_PUNCH: + if (punch_file) + safe_close(punch_file); + break; + + case OUTPUT_SCREEN: + if (error_file) + safe_close(error_file); + break; + + case OUTPUT_LOG: + if (log_file) + safe_close(log_file); + break; + + case OUTPUT_CVODE: + case OUTPUT_STDERR: + if (stderr) + safe_close(stderr); + break; + + case OUTPUT_DUMP: + if (dump_file) + safe_close(dump_file); + break; + } +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int PHRQ_io:: rewind_wrapper(FILE * file_ptr) @@ -583,6 +1050,7 @@ rewind_wrapper(FILE * file_ptr) //return (OK); return 1; } +#endif /* ---------------------------------------------------------------------- */ void PHRQ_io:: safe_close(FILE * file_ptr) diff --git a/PHRQ_io.h b/PHRQ_io.h index d940ef4f..68407811 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -42,19 +42,30 @@ typedef enum // methods - int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args); - int open_handler(const int type, const char *file_name); - bool isopen_handler(const int type); - int fileop_handler(const int type, int (*PFN) (FILE *)); - int output_handler(const int type, const char *err_str, - const bool stop, const char *format, - va_list args); - static int rewind_wrapper(FILE * file_ptr); + //int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args); + //int open_handler(const int type, const char *file_name); + //bool isopen_handler(const int type); + //int fileop_handler(const int type, int (*PFN) (FILE *)); + //int output_handler(const int type, const char *err_str, + // const bool stop, const char *format, + // va_list args); + //static int rewind_wrapper(FILE * file_ptr); static void safe_close(FILE * file_ptr); int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); void output_string(const int type, std::string str); + + int output_open(int type, const char *file_name); + void error_msg(const char *err_str, bool stop); + void warning_msg(const char *err_str); + void output_msg(int type, const char *format, va_list args); + void output_fflush(int type); + void output_rewind(int type); + void output_close(int type); + bool output_isopen(int type); + void fpunchf(const char *name, const char *format, va_list args); + void Set_io_error_count(int i) { this->io_error_count = i; diff --git a/Parser.cxx b/Parser.cxx index b91c5a4b..317b8249 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -900,7 +900,7 @@ CParser::get_option(const std::vector < std::string > &opt_list, } return (j); } - +#ifdef SKIP_093011 int CParser::error_msg(const char *err_str, ONERROR_TYPE ot) { @@ -917,7 +917,8 @@ CParser::error_msg(const char *err_str, ONERROR_TYPE ot) } return 0; } - +#endif +#ifdef SKIP_093011 int CParser::warning_msg(const char *err_str) { @@ -929,7 +930,7 @@ CParser::warning_msg(const char *err_str) return 0; } - +#endif CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, const std::string::iterator end, std::string & element) diff --git a/Parser.h b/Parser.h index d45fab17..80b7d7ff 100644 --- a/Parser.h +++ b/Parser.h @@ -259,14 +259,14 @@ class CParser: public PHRQ_base const std::vector < std::string > &list, bool exact); - +#ifdef SKIP_093011 int error_msg(const std::ostringstream & err_str, ONERROR_TYPE stop) { return error_msg(err_str.str().c_str(), stop); } int error_msg(const char *err_str, ONERROR_TYPE stop); int warning_msg(const char *err_str); - +#endif void set_echo_file(ECHO_OPTION opt) { echo_file = opt; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7e0ab29a..a3ccdb0e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1,9 +1,4 @@ #include "Phreeqc.h" -//class Phreeqc -//{ -// Phreeqc(void); -// ~Phreeqc(void); -//}; #include // std::replace #include "NameDouble.h" @@ -21,15 +16,6 @@ Phreeqc::Phreeqc(void) phast = FALSE; s_pTail = NULL; user_database = NULL; -#ifdef USE_OLD_IO - output_file = NULL; - log_file = NULL; - punch_file = NULL; - dump_file = NULL; - error_file = NULL; - database_file = NULL; - input_file = NULL; -#endif rates = NULL; tally_table = NULL; spec = NULL; @@ -382,12 +368,9 @@ Phreeqc::Phreeqc(void) back_eq_max = 0; // output.c - output_callbacks = new Phreeqc::output_callback[MAX_CALLBACKS]; - count_output_callback = 0; forward_output_to_log = 0; // phqalloc.c - //s_pTail = NULL; // transport.c J_ij = NULL; @@ -396,13 +379,6 @@ Phreeqc::Phreeqc(void) default_data_base = string_duplicate("phreeqc.dat"); -//FILE *input_file = NULL; -//FILE *database_file = NULL; -//FILE *output = NULL; /* OUTPUT_MESSAGE */ -//FILE *log_file = NULL; /* OUTPUT_LOG */ -//FILE *punch_file = NULL; /* OUTPUT_PUNCH */ -//FILE *error_file = NULL; /* OUTPUT_ERROR */ -//FILE *dump_file = NULL; /* OUTPUT_DUMP */ init(); } @@ -430,8 +406,6 @@ Phreeqc::~Phreeqc(void) } delete[] command; - delete[] output_callbacks; - free_check_null(default_data_base); PHRQ_free_all(); @@ -836,14 +810,6 @@ void Phreeqc::init(void) user_punch = 0; user_punch_headings = 0; user_punch_count_headings = 0; -#ifdef PHREEQ98 -/* - * user_graph - */ - user_graph = 0; - user_graph_headings = 0 - user_graph_count_headings = 0; -#endif /* Initialize llnl aqueous model parameters */ @@ -869,60 +835,54 @@ void Phreeqc::init(void) change_surf = 0; change_surf_count = 0; - -#if defined(WINDOWS) || defined(_WINDOWS) - /* SRC pr.status = FALSE; */ -#endif /* Initialize print here, not in global.h */ - pr.all = TRUE; + pr.all = TRUE; pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.s_s_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; if (phast == TRUE) { - pr.status = FALSE; + pr.status = FALSE; } else { - pr.status = TRUE; + pr.status = TRUE; } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - - species_list = NULL; - - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + species_list = NULL; + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; selected_output_file_name = NULL; - dump_file_name = NULL; + dump_file_name = NULL; /* calculate_value */ max_calculate_value = MAX_ELTS; @@ -945,16 +905,16 @@ void Phreeqc::init(void) phreeqc_mpi_myself = 0; - copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; - copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; - copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; - copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; - copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; - copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; - copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; set_forward_output_to_log(FALSE); simulation = 0; @@ -997,28 +957,28 @@ void Phreeqc::init(void) /* * to facilitate debuging */ - dbg_use = &use; - dbg_solution = solution; - dbg_exchange = exchange; - dbg_surface = surface; - dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; - dbg_irrev = irrev; - dbg_mix = mix; - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; + dbg_use = &use; + dbg_solution = solution; + dbg_exchange = exchange; + dbg_surface = surface; + dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + dbg_irrev = irrev; + dbg_mix = mix; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; - zeros = 0; - zeros_max = 1; + zeros = 0; + zeros_max = 1; - cell_pore_volume = 0; + cell_pore_volume = 0; cell_volume = 0; cell_porosity = 0; - cell_saturation = 0; + cell_saturation = 0; - charge_group = NULL; - print_density = 0; + charge_group = NULL; + print_density = 0; // // Non-class statics @@ -1193,34 +1153,5 @@ void Phreeqc::init(void) return; } -//void * Phreeqc::get_cookie() -//{ -// if (cookie_list.size() > 0) -// { -// return this->cookie_list.front(); -// } -// else -// { -// return NULL; -// } -//} -//void Phreeqc::set_cookie(std::istream * cookie) -//{ -// this->cookie_list.push_front(cookie); -//} -//void Phreeqc::clear_cookie(void) -//{ -// while (this->cookie_list.size() > 0) -// { -// this->pop_cookie(); -// } -//} -//void Phreeqc::pop_cookie() -//{ -// if (cookie_list.size() > 0) -// { -// delete this->cookie_list.front(); -// this->cookie_list.pop_front(); -// } -//} + diff --git a/Phreeqc.h b/Phreeqc.h index 02a40780..fab494a4 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -701,10 +701,6 @@ int switch_bases(void); int write_phase_sys_total(int n); // print.c ------------------------------- - -int fpunchf(const char *name, const char *format, ...); -int fpunchf_user(int user_index, const char *format, ...); -int fpunchf_end_row(const char *format, ...); char *sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); From e89dd5938c6e783a303eab0920d1b40b0e9719e8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 30 Sep 2011 19:28:20 +0000 Subject: [PATCH 0267/1077] Removed SKIP code in PHRQ_io and Parser. removes old handler code from PHRQ_io.cpp remove error_msg, warning_msg from Parser. Removed commented lines. rewrote a couple places in parser that used cerr instead of error_msg. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5666 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 421 +--------------------------------------------------- PHRQ_io.h | 8 - Parser.cxx | 148 ++---------------- Parser.h | 8 - 4 files changed, 13 insertions(+), 572 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index dc72a0e3..8a9a22c1 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -30,72 +30,7 @@ PHRQ_io:: ~PHRQ_io() { } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -phreeqc_handler(const int action, const int type, const char *err_str, - const bool stop, const char *format, - va_list args) -/* ---------------------------------------------------------------------- */ -{ - int i; - switch (action) - { - case ACTION_OPEN: - return this->open_handler(type, err_str); - break; - case ACTION_OUTPUT: - return this->output_handler(type, err_str, stop, format, args); - break; - case ACTION_FLUSH: - return this->fileop_handler(type, fflush); - break; - case ACTION_REWIND: - return this->fileop_handler(type, &PHRQ_io::rewind_wrapper); - break; - case ACTION_CLOSE: - - i = this->fileop_handler(type, fclose); - switch (type) - { - case OUTPUT_ERROR: - this->error_file = NULL; - break; - - case OUTPUT_WARNING: - break; - - case OUTPUT_MESSAGE: - this->output_file = NULL; - break; - - case OUTPUT_PUNCH: - this->punch_file = NULL; - break; - - case OUTPUT_SCREEN: - break; - - case OUTPUT_LOG: - this->log_file = NULL; - break; - - case OUTPUT_STDERR: - break; - - case OUTPUT_DUMP: - this->dump_file = NULL; - break; - } - - - return (i); - break; - } - return false; -} -#endif /* ---------------------------------------------------------------------- */ int PHRQ_io:: close_input_files(void) @@ -130,172 +65,7 @@ istream_getc(void *cookie) } return EOF; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -output_handler(const int type, const char *err_str, const bool stop, - const char *format, va_list args) -/* ---------------------------------------------------------------------- */ -{ - int flush = 1; - switch (type) - { - - case OUTPUT_ERROR: - io_error_count++; - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "ERROR: %s\n", err_str); - if (flush) - fflush(error_file); - } -#ifdef PHREEQ98 - sprintf(progress_str, "ERROR: %s\n", err_str); - show_progress(type, progress_str); -#endif /* PHREEQ98 */ - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "ERROR: %s\n", err_str); -#ifdef PHREEQ98 - outputlinenr++; -#endif - if (flush) - fflush(output_file); - } - if (stop) - { - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "Stopping.\n"); - fflush(error_file); - } -#ifdef PHREEQ98 - sprintf(progress_str, "Stopping.\n"); - show_progress(type, progress_str); -#endif /* PHREEQ98 */ - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "Stopping.\n"); -#ifdef PHREEQ98 - outputlinenr++; -#endif - fflush(output_file); - } - } - break; - - case OUTPUT_WARNING: - //if (pr.logfile == TRUE && log_file != NULL) - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "WARNING: %s\n", err_str); - if (flush) - fflush(log_file); - } - //if (state == TRANSPORT && transport_warnings == FALSE) - // return (OK); - //if (state == ADVECTION && advection_warnings == FALSE) - // return (OK); - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "WARNING: %s\n", err_str); - if (flush) - fflush(error_file); - } -#ifdef PHREEQ98 - sprintf(progress_str, "WARNING: %s\n", err_str); - show_progress(type, progress_str); -#endif /* PHREEQ98 */ - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "WARNING: %s\n", err_str); -#ifdef PHREEQ98 - outputlinenr++; -#endif - if (flush) - fflush(output_file); - } - break; - case OUTPUT_CHECKLINE: - //if (pr.echo_input == TRUE) - { - if (output_file != NULL && output_file_on) - { - vfprintf(output_file, format, args); -#ifdef PHREEQ98 - check_line_breaks(format); -#endif - if (flush) - fflush(output_file); - } - } - break; - case OUTPUT_MESSAGE: - case OUTPUT_BASIC: - if (output_file != NULL && output_file_on) - { - vfprintf(output_file, format, args); -#ifdef PHREEQ98 - check_line_breaks(format); -#endif - if (flush) - fflush(output_file); - } - break; - case OUTPUT_PUNCH: - if (punch_file != NULL && punch_file_on) - { - //if (pr.punch == TRUE && punch.in == TRUE) - { - vfprintf(punch_file, format, args); - if (flush) - fflush(punch_file); - } - } - break; - case OUTPUT_LOG: - //if (pr.logfile == TRUE && log_file != NULL) - if (log_file != NULL && log_file_on) - { - vfprintf(log_file, format, args); - if (flush) - fflush(log_file); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL && error_file_on) - { - vfprintf(error_file, format, args); - if (flush) - fflush(error_file); - } -#ifdef PHREEQ98 - vsprintf(progress_str, format, args); - show_progress(type, progress_str); -#endif /* PHREEQ98 */ - break; - case OUTPUT_STDERR: - case OUTPUT_CVODE: - if (stderr != NULL) - { - vfprintf(stderr, format, args); - fflush(stderr); - } - break; - case OUTPUT_DUMP: - if (dump_file != NULL && dump_file_on) - { - vfprintf(dump_file, format, args); - if (flush) - fflush(dump_file); - } - break; - } - - return 1; -} -#endif /* ---------------------------------------------------------------------- */ void PHRQ_io:: error_msg(const char *err_str, bool stop) @@ -586,86 +356,7 @@ close_output_files(void) output_file = log_file = punch_file = dump_file = NULL; return ret; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -open_handler(const int type, const char *file_name) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - case OUTPUT_PUNCH: - if (punch_file != NULL) - { - fclose(punch_file); - punch_file = NULL; - } - if ((punch_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; - case OUTPUT_MESSAGE: - if (output_file != NULL) - { - safe_close(output_file); - output_file = NULL; - } - if ((output_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; - case OUTPUT_DUMP: - if (dump_file != NULL) - { - safe_close(dump_file); - dump_file = NULL; - } - if ((dump_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; - case OUTPUT_ERROR: - if (error_file != NULL) - { - safe_close(error_file); - error_file = NULL; - } - - if (file_name != NULL) - { - if ((error_file = fopen(file_name, "w")) == NULL) - { - error_file = stderr; - return 0; - } - } - else - { - error_file = stderr; - } - break; - case OUTPUT_LOG: - if (log_file != NULL) - { - safe_close(log_file); - log_file = NULL; - } - if ((log_file = fopen(file_name, "w")) == NULL) - { - return 0; - } - break; - } - return 1; -} -#endif /* ---------------------------------------------------------------------- */ int PHRQ_io:: output_open(int type, const char *file_name) @@ -744,46 +435,7 @@ output_open(int type, const char *file_name) } return 1; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -isopen_handler(const int type) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - case OUTPUT_ERROR: - return (error_file != NULL); - break; - case OUTPUT_WARNING: - return (error_file != NULL || output_file != NULL); - break; - case OUTPUT_MESSAGE: - return (output_file != NULL); - break; - case OUTPUT_PUNCH: - return (punch_file != NULL); - break; - case OUTPUT_SCREEN: - return (error_file != NULL); - break; - case OUTPUT_LOG: - return (log_file != NULL); - break; - case OUTPUT_DUMP: - return (dump_file != NULL); - break; - case OUTPUT_STDERR: - return (stderr != NULL); - break; - default: - assert(false); - return (output_file != NULL); - break; - } - return false; -} -#endif + /* ---------------------------------------------------------------------- */ bool PHRQ_io:: output_isopen(const int type) @@ -822,65 +474,7 @@ output_isopen(const int type) } return false; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -fileop_handler(const int type, int (*PFN) (FILE *)) -/* ---------------------------------------------------------------------- */ -{ - FILE *save_output = NULL; - switch (type) - { - case OUTPUT_ERROR: - if (error_file) - PFN(error_file); - break; - - case OUTPUT_WARNING: - if (error_file) - PFN(error_file); - if (output_file) - PFN(output_file); - break; - - case OUTPUT_MESSAGE: - case OUTPUT_CHECKLINE: - case OUTPUT_BASIC: - if (output_file) - PFN(output_file); - break; - - case OUTPUT_PUNCH: - if (punch_file) - PFN(punch_file); - break; - - case OUTPUT_SCREEN: - if (error_file) - PFN(error_file); - break; - - case OUTPUT_LOG: - if (log_file) - PFN(log_file); - break; - - case OUTPUT_CVODE: - case OUTPUT_STDERR: - if (stderr) - PFN(stderr); - break; - - case OUTPUT_DUMP: - if (dump_file) - PFN(dump_file); - break; - } - - return 1; -} -#endif /* ---------------------------------------------------------------------- */ void PHRQ_io:: output_fflush(const int type) @@ -1040,17 +634,8 @@ output_close(const int type) break; } } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -rewind_wrapper(FILE * file_ptr) -/* ---------------------------------------------------------------------- */ -{ - rewind(file_ptr); - //return (OK); - return 1; -} -#endif + +//safe_close is static method /* ---------------------------------------------------------------------- */ void PHRQ_io:: safe_close(FILE * file_ptr) diff --git a/PHRQ_io.h b/PHRQ_io.h index 68407811..2d69ee58 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -42,14 +42,6 @@ typedef enum // methods - //int phreeqc_handler(const int action, const int type, const char *err_str, const bool stop, const char *, va_list args); - //int open_handler(const int type, const char *file_name); - //bool isopen_handler(const int type); - //int fileop_handler(const int type, int (*PFN) (FILE *)); - //int output_handler(const int type, const char *err_str, - // const bool stop, const char *format, - // va_list args); - //static int rewind_wrapper(FILE * file_ptr); static void safe_close(FILE * file_ptr); int close_input_files(void); int close_output_files(void); diff --git a/Parser.cxx b/Parser.cxx index 317b8249..318ac101 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -19,8 +19,6 @@ #include "output.h" #include "PHRQ_io.h" -//extern char *string_hsave(const char *str); - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -132,7 +130,6 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -141,7 +138,6 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -151,7 +147,6 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - //PHREEQC_COOKIE output_msg(PHREEQC_NAME_SPACE OUTPUT_MESSAGE, "%s", msg.str().c_str()); this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); } break; @@ -346,8 +341,6 @@ CParser::LINE_TYPE CParser::get_logical_line() return (LT_OK); } - -//bool CParser::check_key(const std::string::iterator ptr) bool CParser::check_key(std::string::iterator begin, std::string::iterator end) { @@ -644,7 +637,6 @@ CParser::TOKEN_TYPE CParser::copy_token(std::string & token, std::istream::pos_type & pos) { m_line_iss.seekg(pos); - // m_line_iss >> token; if (!(m_line_iss >> token)) { token.erase(token.begin(), token.end()); // token.clear(); @@ -683,8 +675,6 @@ CParser::FIND_TYPE CParser::find_option(const std::string & item, int *n, return FT_ERROR; } -// OPTION_TYPE get_option(const char **opt_list, int count_opt_list, char **next_char) -// OPTION_TYPE CParser::get_option(const std::vector& opt_list, std::string::iterator& next_char) int CParser::get_option(const std::vector < std::string > &opt_list, std::string::iterator & next_char) @@ -742,16 +732,11 @@ CParser::get_option(const std::vector < std::string > &opt_list, { get_output() << "\t" << m_line_save << "\n"; } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; + std::ostringstream err; + err << "Unknown option." << "\n"; + err << m_line_save << "\n"; + error_msg(err.str().c_str()); j = OPT_ERROR; next_char = m_line.begin(); @@ -828,50 +813,15 @@ CParser::get_option(const std::vector < std::string > &opt_list, pos_ptr = 0; copy_token(option, pos_ptr); next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} -/* - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - get_output() << "\t" << m_line_save << "\n"; - } - } -*/ } else { -/* - if (true) // (database_file == NULL) - { - get_output() << "\t" << m_line_save << "\n"; - } -*/ - //error_msg("Unknown option.", OT_CONTINUE); - //error_msg(m_line_save.c_str(), OT_CONTINUE); - //incr_input_error(); j = OPT_ERROR; next_pos = pos_ptr; } } else { - //pos_ptr = 0; - //copy_token(option, pos_ptr); - //if (find_option(option, &opt, opt_list, true) == FT_OK) - //{ - // j = opt; - // next_pos = pos_ptr; - //} - //else - //{ - // j = OPT_DEFAULT; - // next_pos = 0; - //} - - //std::istringstream m_line_iss_copy = m_line_iss; pos_ptr = m_line_iss.tellg(); m_line_iss >> option; if (find_option(option, &opt, opt_list, true) == FT_OK) @@ -885,52 +835,10 @@ CParser::get_option(const std::vector < std::string > &opt_list, m_line_iss.seekg(pos_ptr); m_line_iss.clear(); next_pos = pos_ptr; - //m_line_iss >> option; } -/* - if (true) // pr.echo_input == TRUE - { - if (true) // database_file == NULL - { - fprintf(stderr, "Yikes 3\n"); - get_output() << "\t" << m_line_save << "\n"; - } - } -*/ } return (j); } -#ifdef SKIP_093011 -int -CParser::error_msg(const char *err_str, ONERROR_TYPE ot) -{ - PHRQ_base::error_msg(err_str, (int) ot); - m_error_stream << "ERROR: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "ERROR: " << err_str << "\n"; - m_output_stream.flush(); - - if (ot == OT_STOP) - { - exit(1); - } - return 0; -} -#endif -#ifdef SKIP_093011 -int -CParser::warning_msg(const char *err_str) -{ - m_error_stream << "WARNING: " << err_str << "\n"; - m_error_stream.flush(); - - m_output_stream << "WARNING: " << err_str << "\n"; - m_output_stream.flush(); - - return 0; -} -#endif CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, const std::string::iterator end, std::string & element) @@ -1113,34 +1021,6 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) return PARSER_OK; } -//CParser::STATUS_TYPE CParser::addPair(std::map < char *, double, -// CHARSTAR_LESS > &totals, -// std::istream::pos_type & pos) -//{ -// std::string token; -// char * -// ctoken; -// double -// d; -// -// CParser::TOKEN_TYPE j; -// -// m_line_iss.seekg(pos); -// -// j = copy_token(token, pos); -// -// if (j == TT_EMPTY) -// return PARSER_OK; -// -// if (!(m_line_iss >> d)) -// { -// return PARSER_ERROR; -// } -// ctoken = string_hsave(token.c_str()); -// totals[ctoken] = d; -// return PARSER_OK; -//} - CParser::STATUS_TYPE CParser::addPair(std::map < std::string, double >&totals, std::istream::pos_type & pos) { @@ -1223,16 +1103,12 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { get_output() << "\t" << m_line_save << "\n"; } - //////std::istringstream err_msg; - //////err_msg << "Unknown option."; - //////err_msg << line_save; - //////error_msg(const std::string& msg, ONERROR_TYPE); - - // error_msg("Unknown option.", CONTINUE); - // error_msg(line_save, CONTINUE); - // input_error++; - std::cerr << "Unknown option." << "\n"; - std::cerr << m_line_save << "\n"; + //std::cerr << "Unknown option." << "\n"; + //std::cerr << m_line_save << "\n"; + std::ostringstream err; + err << "Unknown option." << "\n"; + err << m_line_save << "\n"; + error_msg(err.str().c_str()); j = OPT_ERROR; next_char = m_line.begin(); @@ -1279,7 +1155,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, // // Read line // - //LINE_TYPE lt = check_line("get_option", false, true, true, false); LINE_TYPE lt = m_line_type; if (lt == LT_EOF) { @@ -1310,9 +1185,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, pos_ptr = 0; copy_token(option, pos_ptr); next_pos = pos_ptr; - //{{ - //// m_line_iss.clear(); - //}} if (true) // pr.echo_input == TRUE { if (true) // database_file == NULL diff --git a/Parser.h b/Parser.h index 80b7d7ff..28d79fe3 100644 --- a/Parser.h +++ b/Parser.h @@ -259,14 +259,6 @@ class CParser: public PHRQ_base const std::vector < std::string > &list, bool exact); -#ifdef SKIP_093011 - int error_msg(const std::ostringstream & err_str, ONERROR_TYPE stop) - { - return error_msg(err_str.str().c_str(), stop); - } - int error_msg(const char *err_str, ONERROR_TYPE stop); - int warning_msg(const char *err_str); -#endif void set_echo_file(ECHO_OPTION opt) { echo_file = opt; From d0075d7c4d2d694cd0a9052ffe6a43502e7caf29 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 30 Sep 2011 20:05:35 +0000 Subject: [PATCH 0268/1077] Converted phrq_io to pointer rather than an instance. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5667 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 23 ++++++----- ReadClass.cxx | 112 +++++++++++++++++++++++++------------------------- 2 files changed, 69 insertions(+), 66 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index a3ccdb0e..71011b08 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -13,6 +13,8 @@ Phreeqc::Phreeqc(void) { + phrq_io = new PHRQ_io; + phast = FALSE; s_pTail = NULL; user_database = NULL; @@ -386,8 +388,8 @@ Phreeqc::~Phreeqc(void) { clean_up(); - this->phrq_io.close_input_files(); - this->phrq_io.close_output_files(); + this->phrq_io->close_input_files(); + this->phrq_io->close_output_files(); int i; for (i = 0; i < count_iso_defaults; i++) @@ -409,6 +411,7 @@ Phreeqc::~Phreeqc(void) free_check_null(default_data_base); PHRQ_free_all(); + delete phrq_io; } void Phreeqc::set_phast(int tf) @@ -429,7 +432,7 @@ size_t Phreeqc::list_components(std::list &list_c) // solutions for (i = 0; i < count_solution; i++) { - cxxSolution entity(solution[i], &phrq_io); + cxxSolution entity(solution[i], phrq_io); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -444,7 +447,7 @@ size_t Phreeqc::list_components(std::list &list_c) // pure phases for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage entity(&pp_assemblage[i], &phrq_io); + cxxPPassemblage entity(&pp_assemblage[i], phrq_io); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -452,7 +455,7 @@ size_t Phreeqc::list_components(std::list &list_c) // exchangers for (i = 0; i < count_exchange; i++) { - cxxExchange entity(&exchange[i], &phrq_io); + cxxExchange entity(&exchange[i], phrq_io); entity.totalize(); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -460,7 +463,7 @@ size_t Phreeqc::list_components(std::list &list_c) // surfaces for (i = 0; i < count_surface; i++) { - cxxSurface entity(&surface[i], &phrq_io); + cxxSurface entity(&surface[i], phrq_io); entity.totalize(); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -468,7 +471,7 @@ size_t Phreeqc::list_components(std::list &list_c) // gas phases for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase entity(&gas_phase[i], &phrq_io); + cxxGasPhase entity(&gas_phase[i], phrq_io); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -485,7 +488,7 @@ size_t Phreeqc::list_components(std::list &list_c) for (i = 0; i < count_kinetics; i++) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i], &phrq_io); + cxxKinetics entity(&kinetics[i], phrq_io); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -1145,9 +1148,9 @@ void Phreeqc::init(void) count_strings = 0; #ifdef MULTICHART - chart_handler.Set_io(&phrq_io); + chart_handler.Set_io(phrq_io); #endif - run_info.Set_io(&phrq_io); + run_info.Set_io(phrq_io); this->clear_cookie(); diff --git a/ReadClass.cxx b/ReadClass.cxx index 809dfd21..49c67d5a 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -94,7 +94,7 @@ read_solution_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -110,7 +110,7 @@ read_solution_raw(void) parser.get_option(vopts, next_char); - cxxSolution sol(&phrq_io); + cxxSolution sol(phrq_io); sol.read_raw(parser); //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); struct solution *soln_ptr = cxxSolution2solution(&sol); @@ -188,7 +188,7 @@ read_exchange_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -203,7 +203,7 @@ read_exchange_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxExchange ex(&phrq_io); + cxxExchange ex(phrq_io); ex.read_raw(parser); //struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); struct exchange *exchange_ptr = cxxExchange2exchange(&ex); @@ -283,7 +283,7 @@ read_surface_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -298,7 +298,7 @@ read_surface_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxSurface ex(&phrq_io); + cxxSurface ex(phrq_io); ex.read_raw(parser); //struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); struct surface *surface_ptr = cxxSurface2surface(&ex); @@ -379,7 +379,7 @@ read_equilibrium_phases_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -394,7 +394,7 @@ read_equilibrium_phases_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxPPassemblage ex(&phrq_io); + cxxPPassemblage ex(phrq_io); ex.read_raw(parser); //struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&ex); @@ -476,7 +476,7 @@ read_kinetics_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -491,7 +491,7 @@ read_kinetics_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxKinetics ex(&phrq_io); + cxxKinetics ex(phrq_io); ex.read_raw(parser); //struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&ex); @@ -572,7 +572,7 @@ read_solid_solutions_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -670,7 +670,7 @@ read_gas_phase_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -685,7 +685,7 @@ read_gas_phase_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxGasPhase ex(&phrq_io); + cxxGasPhase ex(phrq_io); ex.read_raw(parser); //struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); struct gas_phase *gas_phase_ptr = cxxGasPhase2gas_phase(&ex); @@ -765,7 +765,7 @@ read_reaction_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -861,7 +861,7 @@ read_mix_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -876,7 +876,7 @@ read_mix_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxMix ex(&phrq_io); + cxxMix ex(phrq_io); ex.read_raw(parser); //struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); struct mix *mix_ptr = cxxMix2mix(&ex); @@ -957,7 +957,7 @@ read_temperature_raw(void) std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) @@ -973,7 +973,7 @@ read_temperature_raw(void) std::istream::pos_type next_char; parser.get_option(vopts, next_char); - cxxTemperature ex(&phrq_io); + cxxTemperature ex(phrq_io); ex.read_raw(parser); //struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); struct temperature *temperature_ptr = cxxTemperature2temperature(&ex); @@ -1035,7 +1035,7 @@ read_dump(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1053,7 +1053,7 @@ read_dump(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - dumper dmp(parser, &phrq_io); + dumper dmp(parser, phrq_io); dump_info = dmp; @@ -1087,7 +1087,7 @@ read_delete(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1105,7 +1105,7 @@ read_delete(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - StorageBinList deleter(parser, &phrq_io); + StorageBinList deleter(parser, phrq_io); delete_info = deleter; @@ -1139,7 +1139,7 @@ read_run_cells(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1157,7 +1157,7 @@ read_run_cells(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - runner r(parser, &phrq_io); + runner r(parser, phrq_io); run_info = r; @@ -1211,7 +1211,7 @@ read_solution_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1238,14 +1238,14 @@ read_solution_modify(void) return (ERROR); } - cxxSolution sol(solution[n], &phrq_io); + cxxSolution sol(solution[n], phrq_io); // Clear activities so we can know what was read sol.clear_master_activity(); sol.read_raw(parser, false); - cxxSolution orig(solution[n], &phrq_io ); + cxxSolution orig(solution[n], phrq_io ); sol.modify_activities(PHREEQC_THIS_COMMA orig); @@ -1310,7 +1310,7 @@ read_equilibrium_phases_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1337,7 +1337,7 @@ read_equilibrium_phases_modify(void) } // read entity - cxxPPassemblage entity(&(pp_assemblage[n]), &phrq_io); + cxxPPassemblage entity(&(pp_assemblage[n]), phrq_io); entity.read_raw(parser, false); // save entity @@ -1404,7 +1404,7 @@ read_exchange_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1431,7 +1431,7 @@ read_exchange_modify(void) } // read entity - cxxExchange entity(&(exchange[n]), &phrq_io); + cxxExchange entity(&(exchange[n]), phrq_io); entity.read_raw(parser, false); // save entity @@ -1513,7 +1513,7 @@ read_surface_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1540,7 +1540,7 @@ read_surface_modify(void) } // read entity - cxxSurface entity(&(surface[n]), &phrq_io); + cxxSurface entity(&(surface[n]), phrq_io); entity.read_raw(parser, false); // save entity @@ -1603,7 +1603,7 @@ read_solid_solutions_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1692,7 +1692,7 @@ read_gas_phase_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1719,7 +1719,7 @@ read_gas_phase_modify(void) } // read entity - cxxGasPhase entity(&(gas_phase[n]), &phrq_io); + cxxGasPhase entity(&(gas_phase[n]), phrq_io); entity.read_raw(parser, false); // save entity //struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); @@ -1781,7 +1781,7 @@ read_kinetics_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; // ?? std::ostringstream oss_err; // ?? - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1808,7 +1808,7 @@ read_kinetics_modify(void) } // read entity - cxxKinetics entity(&(kinetics[n]), &phrq_io); + cxxKinetics entity(&(kinetics[n]), phrq_io); entity.read_raw(parser, false); // save entity @@ -1870,7 +1870,7 @@ read_reaction_modify(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -2466,7 +2466,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_solution; i++) { - cxxSolution cxxsoln(solution[i], &phrq_io); + cxxSolution cxxsoln(solution[i], phrq_io); cxxsoln.dump_raw(os,0); } } @@ -2477,7 +2477,7 @@ dump_ostream(std::ostream& os) { if (solution_bsearch(*it, &n, FALSE) != NULL) { - cxxSolution cxxsoln(solution[n], &phrq_io); + cxxSolution cxxsoln(solution[n], phrq_io); cxxsoln.dump_raw(os,0); } } @@ -2491,7 +2491,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_pp_assemblage; i++) { - cxxPPassemblage cxxentity(&pp_assemblage[i], &phrq_io); + cxxPPassemblage cxxentity(&pp_assemblage[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2503,7 +2503,7 @@ dump_ostream(std::ostream& os) if (pp_assemblage_bsearch(*it, &n) != NULL) { - cxxPPassemblage cxxentity(&pp_assemblage[n], &phrq_io); + cxxPPassemblage cxxentity(&pp_assemblage[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2517,7 +2517,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_exchange; i++) { - cxxExchange cxxentity(&exchange[i], &phrq_io); + cxxExchange cxxentity(&exchange[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2529,7 +2529,7 @@ dump_ostream(std::ostream& os) if (exchange_bsearch(*it, &n) != NULL) { - cxxExchange cxxentity(&exchange[n], &phrq_io); + cxxExchange cxxentity(&exchange[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2543,7 +2543,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_surface; i++) { - cxxSurface cxxentity(&surface[i], &phrq_io); + cxxSurface cxxentity(&surface[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2555,7 +2555,7 @@ dump_ostream(std::ostream& os) if (surface_bsearch(*it, &n) != NULL) { - cxxSurface cxxentity(&surface[n], &phrq_io); + cxxSurface cxxentity(&surface[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2595,7 +2595,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_gas_phase; i++) { - cxxGasPhase cxxentity(&gas_phase[i], &phrq_io); + cxxGasPhase cxxentity(&gas_phase[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2607,7 +2607,7 @@ dump_ostream(std::ostream& os) if (gas_phase_bsearch(*it, &n) != NULL) { - cxxGasPhase cxxentity(&gas_phase[n], &phrq_io); + cxxGasPhase cxxentity(&gas_phase[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2621,7 +2621,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_kinetics; i++) { - cxxKinetics cxxentity(&kinetics[i], &phrq_io); + cxxKinetics cxxentity(&kinetics[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2633,7 +2633,7 @@ dump_ostream(std::ostream& os) if (kinetics_bsearch(*it, &n) != NULL) { - cxxKinetics cxxentity(&kinetics[n], &phrq_io); + cxxKinetics cxxentity(&kinetics[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2647,7 +2647,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_mix; i++) { - cxxMix cxxentity(&mix[i], &phrq_io); + cxxMix cxxentity(&mix[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2659,7 +2659,7 @@ dump_ostream(std::ostream& os) if (mix_bsearch(*it, &n) != NULL) { - cxxMix cxxentity(&mix[n], &phrq_io); + cxxMix cxxentity(&mix[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2699,7 +2699,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_temperature; i++) { - cxxTemperature cxxentity(&temperature[i], &phrq_io); + cxxTemperature cxxentity(&temperature[i], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2711,7 +2711,7 @@ dump_ostream(std::ostream& os) if (temperature_bsearch(*it, &n) != NULL) { - cxxTemperature cxxentity(&temperature[n], &phrq_io); + cxxTemperature cxxentity(&temperature[n], phrq_io); cxxentity.dump_raw(os,0); } } @@ -2754,7 +2754,7 @@ read_user_graph_handler(void) return_value = streamify_to_next_keyword(iss_in); std::ostringstream oss_out; std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, &phrq_io); + CParser parser(iss_in, oss_out, oss_err, phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; From a7aed179363893c8a66bf378e08ffb2660c99eb4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 3 Oct 2011 17:10:02 +0000 Subject: [PATCH 0269/1077] Fixed segv with GAS_PHASE that had gas component with element not in system. Changed to warning from error for missing element. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5669 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 8a1010a8..fa550f30 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -256,7 +256,7 @@ cxxNameDouble::add_extensive(const cxxNameDouble & addee, double factor) { if (factor == 0) return; - assert(factor > 0.0); + //assert(factor > 0.0); for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) { From 5b39b2f7cd5491738b5150d12f1afe62dd5a4511 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 3 Oct 2011 22:15:15 +0000 Subject: [PATCH 0270/1077] NumKeyword reads negative user numbers. Allow copy to negative numbers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5672 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.cxx | 6 +++++- Phreeqc.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 241c14c8..fb454e7c 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -81,7 +81,7 @@ cxxNumKeyword::read_number_description(CParser & parser) parser.get_iss().ignore(); // read number - if (::isdigit(parser.get_iss().peek())) + if (::isdigit(parser.get_iss().peek()) || parser.get_iss().peek() == '-') { parser.get_iss() >> this->n_user; char ch = parser.get_iss().peek(); @@ -89,6 +89,10 @@ cxxNumKeyword::read_number_description(CParser & parser) { parser.get_iss() >> ch; // eat '-' parser.get_iss() >> this->n_user_end; + if (this->n_user_end < this->n_user) + { + this->n_user_end = this->n_user; + } } else { diff --git a/Phreeqc.h b/Phreeqc.h index fab494a4..601be8b6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -749,7 +749,7 @@ int *read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list); int read_log_k_only(char *ptr, LDBLE * log_k); int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description); + char **description, int allow_negative=FALSE); int check_key(char *str); int check_units(char *tot_units, int alkalinity, int check_compatibility, const char *default_units, int print); From fe9f31443e2facdb51a1719b30e9d920fedff038 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 4 Oct 2011 21:32:25 +0000 Subject: [PATCH 0271/1077] Replaced modify_activities so that PHREEQC instance is not needed. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5677 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 3 +- ReadClass.cxx | 2 +- Solution.cxx | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++- Solution.h | 5 +-- 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/NameDouble.h b/NameDouble.h index 81629823..a6660920 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -56,11 +56,10 @@ class cxxNameDouble:public sort_second(void); void - insert(char *str, double d) + insert(const char *str, double d) { (*this)[str] = d; } - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void diff --git a/ReadClass.cxx b/ReadClass.cxx index 49c67d5a..7d93647f 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1247,7 +1247,7 @@ read_solution_modify(void) cxxSolution orig(solution[n], phrq_io ); - sol.modify_activities(PHREEQC_THIS_COMMA orig); + sol.modify_activities(orig); //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); struct solution *soln_ptr = cxxSolution2solution(&sol); diff --git a/Solution.cxx b/Solution.cxx index 698d859c..266dd0a7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -933,7 +933,7 @@ cxxSolution::Get_total(char *string) const } } double -cxxSolution::Get_total_element(char *string) const +cxxSolution::Get_total_element(const char *string) const { cxxNameDouble::const_iterator it; double d = 0.0; @@ -1258,6 +1258,7 @@ cxxSolution::Set_master_activity(char *string, double d) { this->master_activity[string] = d; } +#ifdef SKIP void cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original) // @@ -1414,6 +1415,98 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina this->master_activity[it->first] = it->second; } } +#endif +void +cxxSolution::modify_activities(const cxxSolution & original) +// +// Estimate activities after solution_modify +// +{ + // Note: any master_activities in "this" have been read in SOLUTION_MODIFY + //cxxNameDouble orig_master_activity(original.Get_master_activity()); + //cxxNameDouble orig_totals(original.Get_totals()); + cxxNameDouble factor; + cxxNameDouble updated_orig_activities(original.Get_master_activity()); + cxxNameDouble::const_iterator it; + cxxNameDouble::const_iterator orig_it; + + // Calculate a factor of log10(new tot/old tot) for each element or element redox state in current totals + for (it = this->totals.begin(); it != this->totals.end(); it++) + { + orig_it = original.Get_totals().find(it->first); + if (orig_it != original.Get_totals().end()) + { + // element or valence state in both + if (it->second > 0 && orig_it->second > 0) + { + factor[it->first] = log10(it->second / orig_it->second); + } + } + else + { + + std::string ename; + std::basic_string < char >::size_type indexCh; + indexCh = it->first.find("("); + if (indexCh != std::string::npos) + { + // valence in current and element in original + ename = it->first.substr(0, indexCh); + double orig_tot = original.Get_total_element(ename.c_str()); + double tot = this->Get_total_element(ename.c_str()); + if (tot > 0 && orig_tot > 0) + { + factor[ename] = log10(tot/orig_tot); + } + } + else + { + // element in current and valence in original + ename = it->first; + double orig_tot = original.Get_total_element(ename.c_str()); + if (it->second > 0 && orig_tot > 0) + { + factor[ename] = log10(it->second/orig_tot); + } + } + } + } + + // update original master_activities based using just computed factors + for (it = factor.begin(); it != factor.end(); it++) + { + orig_it = original.Get_master_activity().find(it->first); + if (orig_it != original.Get_master_activity().end()) + { + // Found exact match + double d = orig_it->second + it->second; + updated_orig_activities[it->first.c_str()] = d; + } + else + { + // no exact match, current is element name, need to find all valences + orig_it = original.Get_master_activity().begin(); + std::string v_name = it->first; + v_name.append("("); + for ( ; orig_it != original.Get_master_activity().end(); orig_it++) + { + if (strstr(orig_it->first.c_str(), v_name.c_str()) == orig_it->first.c_str()) + { + double d = orig_it->second + it->second; + updated_orig_activities[orig_it->first.c_str()] = d; + } + } + } + } + + // Merge any new master_activities, which overwrites updated originals + updated_orig_activities.merge_redox(this->Get_master_activity()); + + // Set activities to updated, merged activities + this->master_activity.clear(); + this->master_activity = updated_orig_activities; + +} //#include "ISolution.h" //#include "Exchange.h" //#include "Surface.h" diff --git a/Solution.h b/Solution.h index c5a1efcb..f8d6a381 100644 --- a/Solution.h +++ b/Solution.h @@ -115,7 +115,7 @@ class cxxSolution:public cxxNumKeyword } double Get_total(char *string) const; - double Get_total_element(char *string) const; + double Get_total_element(const char *string) const; void Set_total(char *string, double value); const cxxNameDouble & Get_totals(void) const @@ -151,7 +151,8 @@ class cxxSolution:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); void multiply(double extensive); - void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); + //void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); + void modify_activities(const cxxSolution & original); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); From 58c0e3f7c86a36f0aba055da911fa98b7d2ad569 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 5 Oct 2011 17:20:16 +0000 Subject: [PATCH 0272/1077] Added optional argument to dump_raw to a different user number. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5680 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 6 +++--- Exchange.h | 2 +- GasPhase.cxx | 6 +++--- GasPhase.h | 2 +- PPassemblage.cxx | 5 +++-- PPassemblage.h | 2 +- Reaction.cxx | 6 +++--- Reaction.h | 2 +- SSassemblage.cxx | 6 +++--- SSassemblage.h | 2 +- Solution.cxx | 6 +++--- Solution.h | 2 +- StorageBin.cxx | 20 ++++++++++---------- StorageBin.h | 2 +- Surface.cxx | 6 +++--- Surface.h | 2 +- Temperature.cxx | 5 +++-- Temperature.h | 2 +- cxxKinetics.cxx | 6 +++--- cxxKinetics.h | 2 +- cxxMix.cxx | 6 +++--- cxxMix.h | 2 +- 22 files changed, 51 insertions(+), 49 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 7448a976..c66bb380 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -227,7 +227,7 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const } void -cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; unsigned int i; @@ -242,8 +242,8 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const // Exchange element and attributes s_oss << indent0; - s_oss << "EXCHANGE_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; s_oss << "-exchange_gammas " << this-> diff --git a/Exchange.h b/Exchange.h index 503f42ad..c43610a6 100644 --- a/Exchange.h +++ b/Exchange.h @@ -21,7 +21,7 @@ public: cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); - void dump_raw(std::ostream & s_oss, unsigned int indent) const; + void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); diff --git a/GasPhase.cxx b/GasPhase.cxx index 89620c3e..7db36be7 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -161,7 +161,7 @@ cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; unsigned int i; @@ -176,8 +176,8 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent) const // GasPhase element and attributes s_oss << indent0; - s_oss << "GAS_PHASE_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "GAS_PHASE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; s_oss << "-type " << this->type << std::endl; diff --git a/GasPhase.h b/GasPhase.h index f502e6d8..aeff1cd0 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -30,7 +30,7 @@ class cxxGasPhase:public cxxNumKeyword //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, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 1a8cf9be..90e5ab0a 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -113,7 +113,7 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const } void -cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; unsigned int i; @@ -128,7 +128,8 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const // PPassemblage element and attributes s_oss << indent0; - s_oss << "EQUILIBRIUM_PHASES_RAW " << this->n_user << " " << this-> + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "EQUILIBRIUM_PHASES_RAW " << n_user_local << " " << this-> description << std::endl; // eltList diff --git a/PPassemblage.h b/PPassemblage.h index e9c85487..15711ad3 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -21,7 +21,7 @@ class cxxPPassemblage:public cxxNumKeyword cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxPPassemblage(); - void dump_raw(std::ostream & s_oss, unsigned int indent) const; + void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); diff --git a/Reaction.cxx b/Reaction.cxx index 177f7d8d..4bfdc0d1 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -111,7 +111,7 @@ cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; unsigned int i; @@ -126,8 +126,8 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent) const // Reaction element and attributes s_oss << indent0; - s_oss << "REACTION_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "REACTION_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; s_oss << "-units " << this->units << std::endl; diff --git a/Reaction.h b/Reaction.h index 3786aa65..7e292b4f 100644 --- a/Reaction.h +++ b/Reaction.h @@ -20,7 +20,7 @@ class cxxReaction:public cxxNumKeyword //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, int *n_out=NULL) const; void read_raw(CParser & parser, bool check); const cxxNameDouble &Get_elementList(void) const {return this->elementList;}; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 92e0991c..df020ea7 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -111,7 +111,7 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const } #endif void -cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; unsigned int i; @@ -126,8 +126,8 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent) const // SSassemblage element and attributes s_oss << indent0; - s_oss << "SOLID_SOLUTIONS_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << std::endl; // ssAssemblageSSs for (std::map < std::string, cxxSSassemblageSS >::const_iterator it = diff --git a/SSassemblage.h b/SSassemblage.h index bb7a6800..9cdd3912 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -29,7 +29,7 @@ public: //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, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); const std::map & Get_ssAssemblageSSs() const diff --git a/Solution.cxx b/Solution.cxx index 266dd0a7..f9e05a19 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -396,7 +396,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const } void -cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; unsigned int i; @@ -411,8 +411,8 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const // Solution element and attributes s_oss << indent0; - s_oss << "SOLUTION_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "SOLUTION_RAW " << n_user_local << " " << this->description << std::endl; //s_oss << "# Critical values" << std::endl; diff --git a/Solution.h b/Solution.h index f8d6a381..bed345d7 100644 --- a/Solution.h +++ b/Solution.h @@ -147,7 +147,7 @@ class cxxSolution:public cxxNumKeyword double Get_master_activity(char *string) const; void Set_master_activity(char *string, double value); const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; - void dump_raw(std::ostream & s_oss, unsigned int indent) const; + void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); void multiply(double extensive); diff --git a/StorageBin.cxx b/StorageBin.cxx index 8163d7cf..dd4edcfd 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -585,53 +585,53 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent) +cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent, int *n_out) { - // Dump one user number - + // Dump one user number, optionally change number from n to n_out + int n_user_local = (n_out != NULL) ? *n_out : n; //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; s_oss.precision(DBL_DIG - 1); // Solutions if (this->Get_Solution(n) != NULL) { - this->Get_Solution(n)->dump_raw(s_oss, indent); + this->Get_Solution(n)->dump_raw(s_oss, indent, &n_user_local); } // Exchange if (this->Get_Exchange(n) != NULL) { - this->Get_Exchange(n)->dump_raw(s_oss, indent); + this->Get_Exchange(n)->dump_raw(s_oss, indent, &n_user_local); } // Gas Phases if (this->Get_GasPhase(n) != NULL) { - this->Get_GasPhase(n)->dump_raw(s_oss, indent); + this->Get_GasPhase(n)->dump_raw(s_oss, indent, &n_user_local); } // Kinetics if (this->Get_Kinetics(n) != NULL) { - this->Get_Kinetics(n)->dump_raw(s_oss, indent); + this->Get_Kinetics(n)->dump_raw(s_oss, indent, &n_user_local); } // PPassemblage if (this->Get_PPassemblage(n) != NULL) { - this->Get_PPassemblage(n)->dump_raw(s_oss, indent); + this->Get_PPassemblage(n)->dump_raw(s_oss, indent, &n_user_local); } // SSassemblage if (this->Get_SSassemblage(n) != NULL) { - this->Get_SSassemblage(n)->dump_raw(s_oss, indent); + this->Get_SSassemblage(n)->dump_raw(s_oss, indent, &n_user_local); } // Surface if (this->Get_Surface(n) != NULL) { - this->Get_Surface(n)->dump_raw(s_oss, indent); + this->Get_Surface(n)->dump_raw(s_oss, indent, &n_user_local); } } diff --git a/StorageBin.h b/StorageBin.h index 757d2c4f..2dd1c79c 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -77,7 +77,7 @@ class cxxStorageBin: public PHRQ_base void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void dump_raw(std::ostream & s_oss, int i, unsigned int indent); + void dump_raw(std::ostream & s_oss, int i, unsigned int indent, int *n_out=NULL); void read_raw(CParser & parser); int read_raw_keyword(CParser & parser); diff --git a/Surface.cxx b/Surface.cxx index a1219f85..5f5eac4d 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -217,7 +217,7 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const } void -cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; unsigned int i; @@ -232,8 +232,8 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent) const // Surface element and attributes s_oss << indent0; - s_oss << "SURFACE_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; //s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; diff --git a/Surface.h b/Surface.h index 45ee2771..157b65d9 100644 --- a/Surface.h +++ b/Surface.h @@ -24,7 +24,7 @@ class cxxSurface:public cxxNumKeyword 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, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); diff --git a/Temperature.cxx b/Temperature.cxx index 2078f4c5..4704e0de 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -108,7 +108,7 @@ cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; @@ -122,7 +122,8 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); s_oss << indent0; - s_oss << "REACTION_TEMPERATURE_RAW " << this->n_user << " " << this->description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; s_oss << "-count_temps " << this->countTemps << std::endl; diff --git a/Temperature.h b/Temperature.h index f7c2416f..76f71ff2 100644 --- a/Temperature.h +++ b/Temperature.h @@ -19,7 +19,7 @@ class cxxTemperature:public cxxNumKeyword //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, int *n_out=NULL) const; void read_raw(CParser & parser); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index dad2d947..91c213cd 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -154,7 +154,7 @@ cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) const { //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; unsigned int i; @@ -169,8 +169,8 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent) const // Kinetics element and attributes s_oss << indent0; - s_oss << "KINETICS_RAW " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "KINETICS_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; s_oss << "-step_divide " << this->step_divide << std::endl; diff --git a/cxxKinetics.h b/cxxKinetics.h index 4ceca450..d1e3fd77 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -24,7 +24,7 @@ class cxxKinetics:public cxxNumKeyword //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, int * n_out=NULL) const; void read_raw(CParser & parser, bool check = true); diff --git a/cxxMix.cxx b/cxxMix.cxx index 83f2b01d..b6396d54 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -96,7 +96,7 @@ cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const #endif void -cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; unsigned int i; @@ -111,8 +111,8 @@ cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent) const // Mix element and attributes s_oss << indent0; - s_oss << "MIX " << this->n_user << " " << this-> - description << std::endl; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "MIX " << n_user_local << " " << this->description << std::endl; for (std::map < int, double >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) diff --git a/cxxMix.h b/cxxMix.h index ee6a3d01..d3d68e24 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -19,7 +19,7 @@ class cxxMix:public cxxNumKeyword //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, int *n_out=NULL) const; void read_raw(CParser & parser); From 7ccdb1613b4f24be372c561f96d8161e1b15c11d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 5 Oct 2011 19:32:29 +0000 Subject: [PATCH 0273/1077] removed dead code, mostly P_INSTANCE and PHREEQC_PTR git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5681 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 80 --------- ISolution.cxx | 1 - ISolutionComp.cxx | 2 - NameDouble.cxx | 2 - PPassemblageComp.cxx | 1 - Solution.cxx | 146 ----------------- StorageBin.cxx | 379 ------------------------------------------- StorageBin.h | 2 - SurfaceComp.cxx | 3 - 9 files changed, 616 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index c66bb380..95e056fb 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -81,86 +81,6 @@ cxxNumKeyword(io) } } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -cxxExchange::cxxExchange(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io *io) - // - // constructor for cxxExchange from reaction calculation - // equivalent of xexchange_save - // std::list exchComps; - // bool pitzer_exchange_gammas; - // cxxNameDouble totals; -: -cxxNumKeyword(io) -{ - int i; - - //this->Set_description(exchange_ptr->description); - this->n_user = l_n_user; - this->n_user_end = l_n_user; - this->pitzer_exchange_gammas = - (P_INSTANCE_POINTER use.exchange_ptr->pitzer_exchange_gammas == TRUE); - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - for (i = 0; i < P_INSTANCE_POINTER count_unknowns; i++) - { - if (P_INSTANCE_POINTER x[i]->type == EXCH) - { - cxxExchComp ec(this->Get_io()); - //char * formula; - ec.Set_formula(P_INSTANCE_POINTER x[i]->exch_comp->formula); - //double moles; - ec.Set_moles(0.0); - //cxxNameDouble formula_totals; - ec.Set_formula_totals(P_INSTANCE_POINTER x[i]->exch_comp->formula_totals); - //cxxNameDouble totals; see below - //double la; - ec.Set_la(P_INSTANCE_POINTER x[i]->master[0]->s->la); - //double charge_balance; see below - //char *phase_name; - ec.Set_phase_name(P_INSTANCE_POINTER x[i]->exch_comp->phase_name); - //double phase_proportion; - ec.Set_phase_proportion(P_INSTANCE_POINTER x[i]->exch_comp->phase_proportion); - //char *rate_name; - ec.Set_rate_name(P_INSTANCE_POINTER x[i]->exch_comp->rate_name); - //double formula_z; - ec.Set_formula_z(P_INSTANCE_POINTER x[i]->exch_comp->formula_z); - - // calculate charge and totals - P_INSTANCE_POINTER count_elts = 0; - P_INSTANCE_POINTER paren_count = 0; - double charge = 0.0; - int j; - for (j = 0; j < P_INSTANCE_POINTER count_species_list; j++) - { - if (P_INSTANCE_POINTER species_list[j].master_s == P_INSTANCE_POINTER x[i]->master[0]->s) - { - P_INSTANCE_POINTER add_elt_list(P_INSTANCE_POINTER species_list[j].s->next_elt, - P_INSTANCE_POINTER species_list[j].s->moles); - charge += P_INSTANCE_POINTER species_list[j].s->moles * P_INSTANCE_POINTER species_list[j].s->z; - } - } - // Keep exchanger related to phase even if none currently in solution - if (P_INSTANCE_POINTER x[i]->exch_comp->phase_name != NULL && P_INSTANCE_POINTER count_elts == 0) - { - P_INSTANCE_POINTER add_elt_list(P_INSTANCE_POINTER x[i]->master[0]->s->next_elt, 1e-20); - } - //double charge_balance - ec.Set_charge_balance(charge); - //cxxNameDouble totals; - if (P_INSTANCE_POINTER count_elts > 0) - { - qsort(P_INSTANCE_POINTER elt_list, (size_t) P_INSTANCE_POINTER count_elts, - (size_t) sizeof(struct elt_list), P_INSTANCE_POINTER elt_list_compare); - P_INSTANCE_POINTER elt_list_combine(); - } - ec.Set_totals(P_INSTANCE_POINTER elt_list, P_INSTANCE_POINTER count_elts); - - // add to comp list - std::string str(ec.Get_formula()); - this->exchComps[str] = ec; - } - } -} -#endif cxxExchange::~cxxExchange() { diff --git a/ISolution.cxx b/ISolution.cxx index 53b73d9b..c777edeb 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -90,7 +90,6 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) oss << "Could not find gfw, " << iter->second. Get_description(); error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; } } /* diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 490529e4..6aec744e 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -135,7 +135,6 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) std::ostringstream oss; oss << "Could not compute gfw, " << this->as; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } //if (this->description == "Alkalinity" && this->as == "CaCO3") @@ -159,7 +158,6 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) std::ostringstream oss; oss << "Could not find gfw, " << this->description; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } #endif diff --git a/NameDouble.cxx b/NameDouble.cxx index fa550f30..72b2ddc1 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -242,8 +242,6 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, { return CParser::PARSER_ERROR; } - //ctoken = P_INSTANCE_POINTER string_hsave(token.c_str()); - //(*this)[ctoken] = d; (*this)[token.c_str()] = d; return CParser::PARSER_OK; } diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0aecbc03..6cc2c793 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -457,7 +457,6 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) "Can not mix two Equilibrium_phases with differing add_formulae., " << this->name; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } //double si; diff --git a/Solution.cxx b/Solution.cxx index f9e05a19..0160e39c 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -122,10 +122,6 @@ isotopes(io) solutions.find(it->first); if (sol == solutions.end()) { - //sprintf(P_INSTANCE_POINTER error_string, - // "Solution %d not found in mix_cxxSolutions.", it->first); - //error_msg(P_INSTANCE_POINTER error_string, CONTINUE); - //P_INSTANCE_POINTER input_error++; std::ostringstream msg; msg << "Solution " << it->first << " not found in mix_cxxSolutions."; error_msg(msg.str(), CONTINUE); @@ -137,148 +133,6 @@ isotopes(io) } } } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -cxxSolution::cxxSolution(PHREEQC_PTR_ARG_COMMA int l_n_user, PHRQ_io * io) - // - // constructor for cxxSolution from results of calculation - // does not work in phast because phast uses only the total molalities - // of elements in buffer, not individual redox states. - : -cxxNumKeyword(io), -isotopes(io) -{ - - //this->Set_description none; - this->n_user = l_n_user; - this->n_user_end = l_n_user; - this->tc = P_INSTANCE_POINTER tc_x; - this->ph = P_INSTANCE_POINTER ph_x; - this->pe = P_INSTANCE_POINTER solution_pe_x; - this->mu = P_INSTANCE_POINTER mu_x; - this->ah2o = P_INSTANCE_POINTER ah2o_x; - this->total_h = P_INSTANCE_POINTER total_h_x; - this->total_o = P_INSTANCE_POINTER total_o_x; - this->cb = P_INSTANCE_POINTER cb_x; - this->mass_water = P_INSTANCE_POINTER mass_water_aq_x; - this->total_alkalinity = P_INSTANCE_POINTER total_alkalinity; - this->totals.type = cxxNameDouble::ND_ELT_MOLES; - this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; - this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; - /* - * Add in minor isotopes if initial solution calculation - */ - int i; - if (P_INSTANCE_POINTER initial_solution_isotopes == TRUE) - { - struct master *master_ptr, *master_i_ptr; - for (i = 0; i < P_INSTANCE_POINTER count_master_isotope; i++) - { - if (P_INSTANCE_POINTER master_isotope[i]->moles > 0) - { - master_i_ptr = P_INSTANCE_POINTER master_bsearch(P_INSTANCE_POINTER master_isotope[i]->name); - master_ptr = P_INSTANCE_POINTER master_isotope[i]->elt->master; - if (P_INSTANCE_POINTER master_isotope[i]->minor_isotope == TRUE) - { - master_i_ptr->total = P_INSTANCE_POINTER master_isotope[i]->moles; - if (master_ptr->total > 0) - { - master_i_ptr->s->la = - master_ptr->s->la + - log10(master_i_ptr->total / master_ptr->total); - } - else - { - master_i_ptr->s->la = master_ptr->s->la; - } - } - else if (P_INSTANCE_POINTER master_isotope[i]->minor_isotope == FALSE - && master_ptr->s != P_INSTANCE_POINTER s_hplus - && master_ptr->s != P_INSTANCE_POINTER s_h2o) - { - if (master_ptr->s->secondary != NULL) - { - master_ptr->s->secondary->total = - P_INSTANCE_POINTER master_isotope[i]->moles; - } - else - { - master_ptr->s->primary->total = - P_INSTANCE_POINTER master_isotope[i]->moles; - } - } - } - } - } - /* - cxxNameDouble totals; - cxxNameDouble master_activity; - cxxNameDouble species_gamma; - cxxSolutionIsotopeList isotopes; - */ - -// totals and master_activity - for (i = 0; i < P_INSTANCE_POINTER count_master; i++) - { - if (P_INSTANCE_POINTER master[i]->s->type == EX || - P_INSTANCE_POINTER master[i]->s->type == SURF || P_INSTANCE_POINTER master[i]->s->type == SURF_PSI) - continue; - if (P_INSTANCE_POINTER master[i]->s == P_INSTANCE_POINTER s_hplus) - continue; - if (P_INSTANCE_POINTER master[i]->s == P_INSTANCE_POINTER s_h2o) - continue; - if (P_INSTANCE_POINTER master[i]->in != FALSE) - { - this->master_activity[P_INSTANCE_POINTER master[i]->elt->name] = P_INSTANCE_POINTER master[i]->s->la; - } - if (P_INSTANCE_POINTER master[i]->total <= MIN_TOTAL) - { - P_INSTANCE_POINTER master[i]->total = 0.0; - P_INSTANCE_POINTER master[i]->total_primary = 0.0; - continue; - } - this->totals[P_INSTANCE_POINTER master[i]->elt->name] = P_INSTANCE_POINTER master[i]->total; - } - -// species_gammas for Pitzer - if (P_INSTANCE_POINTER pitzer_model == TRUE) - { - int j; - for (j = 0; j < P_INSTANCE_POINTER count_s; j++) - { - if (P_INSTANCE_POINTER s[j]->lg != 0.0) - { - this->species_gamma[P_INSTANCE_POINTER s[j]->name] = P_INSTANCE_POINTER s[j]->lg; - } - } - } - -// Save isotope data - - if (P_INSTANCE_POINTER count_isotopes_x > 0) - { - for (i = 0; i < P_INSTANCE_POINTER count_isotopes_x; i++) - { - cxxSolutionIsotope cxxiso(this->Get_io()); - cxxiso.set_isotope_number(P_INSTANCE_POINTER isotopes_x[i].isotope_number); - cxxiso.set_elt_name(P_INSTANCE_POINTER isotopes_x[i].elt_name); - cxxiso.set_isotope_name(P_INSTANCE_POINTER isotopes_x[i].isotope_name); - cxxiso.set_total(P_INSTANCE_POINTER isotopes_x[i].master->total); - if (P_INSTANCE_POINTER isotopes_x[i].master == P_INSTANCE_POINTER s_hplus->secondary) - { - cxxiso.set_total(2 * P_INSTANCE_POINTER mass_water_aq_x / P_INSTANCE_POINTER gfw_water); - } - if (P_INSTANCE_POINTER isotopes_x[i].master == P_INSTANCE_POINTER s_h2o->secondary) - { - cxxiso.set_total(P_INSTANCE_POINTER mass_water_aq_x / P_INSTANCE_POINTER gfw_water); - } - // cxxiso.ratio - // cxxiso.ratio_uncertainty - // cxxiso.ratio_uncertainty_defined - this->isotopes.push_back(cxxiso); - } - } -} -#endif cxxSolution::~cxxSolution() { } diff --git a/StorageBin.cxx b/StorageBin.cxx index dd4edcfd..f0fb0236 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -49,119 +49,6 @@ PHRQ_base(io) this->system.Set_io(io); } -#ifdef MOVE_TO_STRUCTURES -cxxStorageBin::cxxStorageBin(PHREEQC_PTR_ARG_COMMA struct Use *use_ptr, PHRQ_io * io) -: -PHRQ_base(io) -{ - //Construct from use pointer - - int n; - this->system.Set_io(io); - if (use_ptr->mix_in == TRUE) - { - struct mix *struct_entity = P_INSTANCE_POINTER mix_bsearch(use_ptr->n_mix_user, &n); - if (struct_entity != NULL) - { - cxxMix entity(struct_entity, this->Get_io()); - this->setMix(use_ptr->n_mix_user, &entity); - - std::map c = (this->getMix(use_ptr->n_mix_user)->Get_mixComps()); - std::map::iterator it; - for (it = c.begin(); it != c.end(); it++) - { - struct solution *struct_entity1 = P_INSTANCE_POINTER solution_bsearch(it->first, &n, FALSE); - if (struct_entity1 != NULL) - { - cxxSolution entity1(struct_entity1, this->Get_io()); - this->setSolution(it->first, &entity1); - } - } - } - } - else if (use_ptr->solution_in == TRUE) - { - struct solution *struct_entity = P_INSTANCE_POINTER solution_bsearch(use_ptr->n_solution_user, &n, FALSE); - if (struct_entity != NULL) - { - cxxSolution entity(struct_entity, this->Get_io()); - this->setSolution(use_ptr->n_solution_user, &entity); - } - } - if (use_ptr->pp_assemblage_in == TRUE) - { - struct pp_assemblage *struct_entity = P_INSTANCE_POINTER pp_assemblage_bsearch(use_ptr->n_pp_assemblage_user, &n); - if (struct_entity != NULL) - { - cxxPPassemblage entity(struct_entity, this->Get_io()); - this->setPPassemblage(use_ptr->n_pp_assemblage_user, &entity); - } - } - if (use_ptr->exchange_in == TRUE) - { - struct exchange *struct_entity = P_INSTANCE_POINTER exchange_bsearch(use_ptr->n_exchange_user, &n); - if (struct_entity != NULL) - { - cxxExchange entity(struct_entity, this->Get_io()); - this->setExchange(use_ptr->n_exchange_user, &entity); - } - } - if (use_ptr->surface_in == TRUE) - { - struct surface *struct_entity = P_INSTANCE_POINTER surface_bsearch(use_ptr->n_surface_user, &n); - if (struct_entity != NULL) - { - cxxSurface entity(struct_entity, this->Get_io()); - this->setSurface(use_ptr->n_surface_user, &entity); - } - } - if (use_ptr->gas_phase_in == TRUE) - { - struct gas_phase *struct_entity = P_INSTANCE_POINTER gas_phase_bsearch(use_ptr->n_gas_phase_user, &n); - if (struct_entity != NULL) - { - cxxGasPhase entity(struct_entity, this->Get_io()); - this->setGasPhase(use_ptr->n_gas_phase_user, &entity); - } - } - if (use_ptr->s_s_assemblage_in == TRUE) - { - struct s_s_assemblage *struct_entity = P_INSTANCE_POINTER s_s_assemblage_bsearch(use_ptr->n_s_s_assemblage_user, &n); - if (struct_entity != NULL) - { - cxxSSassemblage entity(struct_entity); - this->setSSassemblage(use_ptr->n_s_s_assemblage_user, &entity); - } - } - if (use_ptr->kinetics_in == TRUE) - { - struct kinetics *struct_entity = P_INSTANCE_POINTER kinetics_bsearch(use_ptr->n_kinetics_user, &n); - if (struct_entity != NULL) - { - cxxKinetics entity(struct_entity, this->Get_io()); - this->setKinetics(use_ptr->n_kinetics_user, &entity); - } - } - if (use_ptr->irrev_in == TRUE) - { - struct irrev *struct_entity = P_INSTANCE_POINTER irrev_bsearch(use_ptr->n_irrev_user, &n); - if (struct_entity != NULL) - { - cxxReaction entity(struct_entity); - this->setReaction(use_ptr->n_irrev_user, &entity); - } - } - if (use_ptr->temperature_in == TRUE) - { - struct temperature *struct_entity = P_INSTANCE_POINTER temperature_bsearch(use_ptr->n_temperature_user, &n); - if (struct_entity != NULL) - { - cxxTemperature entity(struct_entity, this->Get_io()); - this->setTemperature(use_ptr->n_temperature_user, &entity); - } - } -} -#endif cxxStorageBin::~cxxStorageBin() { } @@ -436,79 +323,6 @@ cxxStorageBin::Get_Surfaces() const return this->Surfaces; } -#ifdef MOVE_TO_STRUCTURES -void -cxxStorageBin::import_phreeqc(PHREEQC_PTR_ARG) - // - // pull data out of c storage - // -{ - int i; - - // Solutions - for (i = 0; i < P_INSTANCE_POINTER count_solution; i++) - { - Solutions[P_INSTANCE_POINTER solution[i]->n_user] = cxxSolution(P_INSTANCE_POINTER solution[i], this->Get_io()); - } - - // Exchangers - for (i = 0; i < P_INSTANCE_POINTER count_exchange; i++) - { - Exchangers[P_INSTANCE_POINTER exchange[i].n_user] = cxxExchange(&P_INSTANCE_POINTER exchange[i], this->Get_io()); - } - - // GasPhases - for (i = 0; i < P_INSTANCE_POINTER count_gas_phase; i++) - { - GasPhases[P_INSTANCE_POINTER gas_phase[i].n_user] = cxxGasPhase(&P_INSTANCE_POINTER gas_phase[i], this->Get_io()); - } - - // Kinetics - for (i = 0; i < P_INSTANCE_POINTER count_kinetics; i++) - { - Kinetics[P_INSTANCE_POINTER kinetics[i].n_user] = cxxKinetics(&P_INSTANCE_POINTER kinetics[i], this->Get_io()); - } - - // PPassemblages - for (i = 0; i < P_INSTANCE_POINTER count_pp_assemblage; i++) - { - PPassemblages[P_INSTANCE_POINTER pp_assemblage[i].n_user] = - cxxPPassemblage(&P_INSTANCE_POINTER pp_assemblage[i], this->Get_io()); - } - - // SSassemblages - for (i = 0; i < P_INSTANCE_POINTER count_s_s_assemblage; i++) - { - SSassemblages[P_INSTANCE_POINTER s_s_assemblage[i].n_user] = - cxxSSassemblage(&P_INSTANCE_POINTER s_s_assemblage[i]); - } - - // Surfaces - for (i = 0; i < P_INSTANCE_POINTER count_surface; i++) - { - Surfaces[P_INSTANCE_POINTER surface[i].n_user] = cxxSurface(&P_INSTANCE_POINTER surface[i], this->Get_io()); - } - - // Mixes - for (i = 0; i < P_INSTANCE_POINTER count_mix; i++) - { - Mixes[P_INSTANCE_POINTER mix[i].n_user] = cxxMix(&P_INSTANCE_POINTER mix[i], this->Get_io()); - } - - // Reactions - for (i = 0; i < P_INSTANCE_POINTER count_irrev; i++) - { - Reactions[P_INSTANCE_POINTER irrev[i].n_user] = cxxReaction(&P_INSTANCE_POINTER irrev[i]); - } - - // Temperatures - for (i = 0; i < P_INSTANCE_POINTER count_temperature; i++) - { - Temperatures[P_INSTANCE_POINTER temperature[i].n_user] = cxxTemperature(&P_INSTANCE_POINTER temperature[i], this->Get_io()); - } -} -#endif - #ifdef SKIP void cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -922,199 +736,6 @@ cxxStorageBin::add(struct system *system_ptr) } } -#ifdef MOVE_TO_STRUCTURES -void -cxxStorageBin::cxxStorageBin2phreeqc(PHREEQC_PTR_ARG_COMMA int n) - // - // copy data from phreeqc storage to storage bin - // -{ - //std::ostringstream oss; - - // Solutions - { - - std::map < int, cxxSolution >::iterator it = this->Solutions.find(n); - if (it != this->Solutions.end()) - { - //P_INSTANCE_POINTER solution[0] = (it->second).cxxSolution2solution(P_INSTANCE); - P_INSTANCE_POINTER solution[0] = P_INSTANCE_POINTER cxxSolution2solution(&(it->second)); - P_INSTANCE_POINTER solution[0]->n_user = n; - P_INSTANCE_POINTER solution[0]->n_user_end = n; - P_INSTANCE_POINTER count_solution++; - } - else - { - error_msg("cxxSolution not found in system2phreeqc", STOP); - } - } - - // Exchangers - { - std::map < int, cxxExchange >::iterator it = this->Exchangers.find(n); - if (it != this->Exchangers.end()) - { - //struct exchange *exchange_ptr = - // (it->second).cxxExchange2exchange(P_INSTANCE); - struct exchange *exchange_ptr = P_INSTANCE_POINTER cxxExchange2exchange(&it->second); - - P_INSTANCE_POINTER exchange_copy(exchange_ptr, &P_INSTANCE_POINTER exchange[0], n); - P_INSTANCE_POINTER count_exchange++; - P_INSTANCE_POINTER exchange_free(exchange_ptr); - exchange_ptr = (struct exchange *) P_INSTANCE_POINTER free_check_null(exchange_ptr); - } - } - - // GasPhases - { - std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(n); - if (it != this->GasPhases.end()) - { - //struct gas_phase *gas_phase_ptr = - // (it->second).cxxGasPhase2gas_phase(P_INSTANCE); - struct gas_phase *gas_phase_ptr = P_INSTANCE_POINTER cxxGasPhase2gas_phase(&(it->second)); - P_INSTANCE_POINTER gas_phase_copy(gas_phase_ptr, &P_INSTANCE_POINTER gas_phase[0], n); - P_INSTANCE_POINTER count_gas_phase++; - P_INSTANCE_POINTER gas_phase_free(gas_phase_ptr); - gas_phase_ptr = - (struct gas_phase *) P_INSTANCE_POINTER free_check_null(gas_phase_ptr); - } - } - - // Kinetics - { - std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(n); - if (it != this->Kinetics.end()) - { - //struct kinetics *kinetics_ptr = - // (it->second).cxxKinetics2kinetics(P_INSTANCE); - struct kinetics *kinetics_ptr = P_INSTANCE_POINTER cxxKinetics2kinetics(&(it->second)); - P_INSTANCE_POINTER kinetics_copy(kinetics_ptr, &P_INSTANCE_POINTER kinetics[0], n); - P_INSTANCE_POINTER count_kinetics++; - P_INSTANCE_POINTER kinetics_free(kinetics_ptr); - kinetics_ptr = (struct kinetics *) P_INSTANCE_POINTER free_check_null(kinetics_ptr); - } - } - - // PPassemblages - { - std::map < int, cxxPPassemblage >::iterator it = - this->PPassemblages.find(n); - if (it != this->PPassemblages.end()) - { - //struct pp_assemblage *pp_assemblage_ptr = - // (it->second).cxxPPassemblage2pp_assemblage(P_INSTANCE); - struct pp_assemblage *pp_assemblage_ptr = P_INSTANCE_POINTER cxxPPassemblage2pp_assemblage(&(it->second)); - P_INSTANCE_POINTER pp_assemblage_copy(pp_assemblage_ptr, &P_INSTANCE_POINTER pp_assemblage[0], n); - P_INSTANCE_POINTER count_pp_assemblage++; - P_INSTANCE_POINTER pp_assemblage_free(pp_assemblage_ptr); - pp_assemblage_ptr = - (struct pp_assemblage *) P_INSTANCE_POINTER free_check_null(pp_assemblage_ptr); - } - } - - // SSassemblages - { - std::map < int, cxxSSassemblage >::iterator it = - this->SSassemblages.find(n); - if (it != this->SSassemblages.end()) - { - //struct s_s_assemblage *s_s_assemblage_ptr = - // (it->second).cxxSSassemblage2s_s_assemblage(P_INSTANCE); - struct s_s_assemblage *s_s_assemblage_ptr = - P_INSTANCE_POINTER cxxSSassemblage2s_s_assemblage(&(it->second)); - - P_INSTANCE_POINTER s_s_assemblage_copy(s_s_assemblage_ptr, &P_INSTANCE_POINTER s_s_assemblage[0], n); - P_INSTANCE_POINTER count_s_s_assemblage++; - P_INSTANCE_POINTER s_s_assemblage_free(s_s_assemblage_ptr); - s_s_assemblage_ptr = - (struct s_s_assemblage *) P_INSTANCE_POINTER free_check_null(s_s_assemblage_ptr); - } - } - - // Surfaces - { - std::map < int, cxxSurface >::iterator it = this->Surfaces.find(n); - if (it != this->Surfaces.end()) - { - //struct surface *surface_ptr = (it->second).cxxSurface2surface(P_INSTANCE); - struct surface *surface_ptr = P_INSTANCE_POINTER cxxSurface2surface(&(it->second)); - P_INSTANCE_POINTER surface_copy(surface_ptr, &P_INSTANCE_POINTER surface[0], n); - P_INSTANCE_POINTER count_surface++; - P_INSTANCE_POINTER surface_free(surface_ptr); - surface_ptr = (struct surface *) P_INSTANCE_POINTER free_check_null(surface_ptr); - } - } - //std::cerr << oss.str(); - -} -#endif - -#ifdef MOVE_TO_STRUCTURES -void -cxxStorageBin::phreeqc2cxxStorageBin(PHREEQC_PTR_ARG_COMMA int n) - // - // copy data from phreeqc storage to storage bin - // -{ - int pos; - - // Solutions - { - P_INSTANCE_POINTER solution_bsearch(n, &pos, TRUE); - this->Solutions[n] = cxxSolution(P_INSTANCE_POINTER solution[pos], this->Get_io()); - } - - // Exchangers - { - if (P_INSTANCE_POINTER exchange_bsearch(n, &pos) != NULL) - { - this->Exchangers[n] = cxxExchange(&(P_INSTANCE_POINTER exchange[pos]), this->Get_io()); - } - } - - // GasPhases - { - if (P_INSTANCE_POINTER gas_phase_bsearch(n, &pos) != NULL) - { - this->GasPhases[n] = cxxGasPhase(&(P_INSTANCE_POINTER gas_phase[pos]), this->Get_io()); - } - } - - // Kinetics - { - if (P_INSTANCE_POINTER kinetics_bsearch(n, &pos) != NULL) - { - this->Kinetics[n] = cxxKinetics(&(P_INSTANCE_POINTER kinetics[pos]), this->Get_io()); - } - } - - // PPassemblages - { - if (P_INSTANCE_POINTER pp_assemblage_bsearch(n, &pos) != NULL) - { - this->PPassemblages[n] = cxxPPassemblage(&(P_INSTANCE_POINTER pp_assemblage[pos]), this->Get_io()); - } - } - - // SSassemblages - { - if (P_INSTANCE_POINTER s_s_assemblage_bsearch(n, &pos) != NULL) - { - this->SSassemblages[n] = cxxSSassemblage(&(P_INSTANCE_POINTER s_s_assemblage[pos])); - } - } - - // Surfaces - { - if (P_INSTANCE_POINTER surface_bsearch(n, &pos) != NULL) - { - this->Surfaces[n] = cxxSurface(&(P_INSTANCE_POINTER surface[pos]), this->Get_io()); - } - } -} -#endif - void cxxStorageBin::remove(int n) { diff --git a/StorageBin.h b/StorageBin.h index 2dd1c79c..ee21a78e 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -84,8 +84,6 @@ class cxxStorageBin: public PHRQ_base void add(struct system *sys_ptr); - //struct system *cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int i); - //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 5f6439c8..526ccd15 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -526,7 +526,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) "Can not mix two Surface components with same formula and different related phases, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } else if (this->phase_name.size() != 0) @@ -543,7 +542,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } else if (this->rate_name.size() != 0) @@ -560,7 +558,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //P_INSTANCE_POINTER input_error++; return; } //double Dw; From 03dcbf8eee4b89e7a893fbd7b54bd0a76ff3b560 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 13 Oct 2011 22:37:06 +0000 Subject: [PATCH 0274/1077] Added Simplify_totals method and Update method to aid in PHAST implementation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5687 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-- Solution.h | 2 + 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 0160e39c..843bb5f7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -10,6 +10,7 @@ //MPICH seems to require mpi.h to be first #include #endif +#include #include // assert #include // std::sort #include "Utils.h" // define first @@ -1277,8 +1278,6 @@ cxxSolution::modify_activities(const cxxSolution & original) // { // Note: any master_activities in "this" have been read in SOLUTION_MODIFY - //cxxNameDouble orig_master_activity(original.Get_master_activity()); - //cxxNameDouble orig_totals(original.Get_totals()); cxxNameDouble factor; cxxNameDouble updated_orig_activities(original.Get_master_activity()); cxxNameDouble::const_iterator it; @@ -1326,7 +1325,7 @@ cxxSolution::modify_activities(const cxxSolution & original) } } - // update original master_activities based using just computed factors + // update original master_activities using just computed factors for (it = factor.begin(); it != factor.end(); it++) { orig_it = original.Get_master_activity().find(it->first); @@ -1361,6 +1360,104 @@ cxxSolution::modify_activities(const cxxSolution & original) this->master_activity = updated_orig_activities; } +void +cxxSolution::Simplify_totals() +{ + // remove individual redox states from totals + std::set list_of_elements; + cxxNameDouble::iterator it; + for (it = this->totals.begin(); it != this->totals.end(); ++it) + { + std::string current_ename(it->first); + std::basic_string < char >::size_type indexCh; + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") + continue; + list_of_elements.insert(current_ename); + } + + cxxNameDouble new_totals; + new_totals.type = cxxNameDouble::ND_ELT_MOLES; + std::set::iterator nt_it = list_of_elements.begin(); + for( ; nt_it != list_of_elements.end(); nt_it++) + { + new_totals[(*nt_it).c_str()] = this->Get_total_element((*nt_it).c_str()); + } + this->totals = new_totals; +} +void +cxxSolution::Update(const cxxNameDouble &nd) +{ + // assumes + // nd has H, O, Charge, and totals, without any valence states + + // remove individual redox states from solution totals + this->Simplify_totals(); + + // process special cases and calculate factors + cxxNameDouble factor; + cxxNameDouble::const_iterator it; + for (it = nd.begin(); it != nd.end(); ++it) + { + if (it->first == "H") + { + this->total_h = it->second; + } + else if (it->first == "O") + { + this->total_o = it->second; + } + else if (it->first == "Charge") + { + this->cb = it->second; + } + else + { + cxxNameDouble::iterator sol_it = this->totals.find(it->first.c_str()); + if (sol_it != this->totals.end()) + { + if (it->second != 0 && sol_it->second != 0) + { + factor[it->first.c_str()] = log10(it->second/sol_it->second); + } + this->totals[it->first.c_str()] = it->second; + } + } + } + + // update original master_activities using just computed factors + + cxxNameDouble updated_activities(this->master_activity); + for (it = factor.begin(); it != factor.end(); it++) + { + std::string v_name = it->first; + v_name.append("("); + + cxxNameDouble::iterator sol_it = this->totals.begin(); + for ( ; sol_it != this->totals.end(); sol_it++) + { + // Exact match + if ( it->first == sol_it->first) + { + double d = sol_it->second + it->second; + updated_activities[it->first.c_str()] = d; + } + else if (strstr(v_name.c_str(), sol_it->first.c_str()) == sol_it->first.c_str()) + { + double d = sol_it->second + it->second; + updated_activities[sol_it->first.c_str()] = d; + } + } + } + // Set activities to updated, merged activities + this->master_activity.clear(); + this->master_activity = updated_activities; +} + //#include "ISolution.h" //#include "Exchange.h" //#include "Surface.h" diff --git a/Solution.h b/Solution.h index bed345d7..35e4e770 100644 --- a/Solution.h +++ b/Solution.h @@ -153,6 +153,8 @@ class cxxSolution:public cxxNumKeyword void multiply(double extensive); //void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); void modify_activities(const cxxSolution & original); + void Simplify_totals(); + void Update(const cxxNameDouble &nd); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); From 6e4445faf5b079cae7470c5a354d970ae1f35917 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 14 Oct 2011 15:44:52 +0000 Subject: [PATCH 0275/1077] Working on reaction module and RM_interface. Changed most declarations to protected: from private: git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5688 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.h | 2 +- GasPhase.h | 5 +---- ISolutionComp.h | 2 +- NumKeyword.h | 2 +- PHRQ_base.h | 2 +- PHRQ_io.h | 2 +- PPassemblage.h | 2 +- Parser.h | 2 +- Phreeqc.h | 51 ++++++++++++++++++++++++------------------------- SSassemblage.h | 2 +- Solution.h | 3 +-- System.h | 2 +- cxxKinetics.h | 2 +- 13 files changed, 37 insertions(+), 42 deletions(-) diff --git a/Exchange.h b/Exchange.h index c43610a6..962c63df 100644 --- a/Exchange.h +++ b/Exchange.h @@ -41,7 +41,7 @@ public: void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif -private: +protected: void add(const cxxExchange & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/GasPhase.h b/GasPhase.h index aeff1cd0..75039d87 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -51,7 +51,7 @@ class cxxGasPhase:public cxxNumKeyword double Get_volume(void) const {return volume;}; cxxNameDouble & Get_totals(void) {return totals;}; -private: +protected: void add(const cxxGasPhase & addee, double extensive); protected: @@ -61,9 +61,6 @@ protected: double volume; cxxNameDouble totals; -public: - //static std::map& map; - }; #endif // !defined(GASPHASE_H_INCLUDED) diff --git a/ISolutionComp.h b/ISolutionComp.h index b30844aa..5239c319 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -123,7 +123,7 @@ class cxxISolutionComp: public PHRQ_base return ::strcmp(this->description.c_str(), conc.description.c_str()) < 0; } - private: + protected: std::string description; double moles; double input_conc; diff --git a/NumKeyword.h b/NumKeyword.h index a280a9ea..08bae963 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -65,7 +65,7 @@ class cxxNumKeyword: public PHRQ_base int n_user_end; std::string description; - private: + protected: void read_number_description(std::istream & is); }; #endif // !defined(NUMKEYWORD_H_INCLUDED) diff --git a/PHRQ_base.h b/PHRQ_base.h index 5148eab6..c4c92ec8 100644 --- a/PHRQ_base.h +++ b/PHRQ_base.h @@ -35,7 +35,7 @@ public: return this->base_error_count; } // data -private: +protected: PHRQ_io * io; int base_error_count; }; diff --git a/PHRQ_io.h b/PHRQ_io.h index 2d69ee58..fad4128f 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -143,7 +143,7 @@ typedef enum return this->dump_file_on; } // data -private: +protected: FILE *input_file; FILE *database_file; FILE *output_file; /* OUTPUT_MESSAGE */ diff --git a/PPassemblage.h b/PPassemblage.h index 15711ad3..66ef12a1 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -44,7 +44,7 @@ class cxxPPassemblage:public cxxNumKeyword void totalize(PHREEQC_PTR_ARG); -private: +protected: void add(const cxxPPassemblage & addee, double extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/Parser.h b/Parser.h index 28d79fe3..b6423d3a 100644 --- a/Parser.h +++ b/Parser.h @@ -287,7 +287,7 @@ class CParser: public PHRQ_base protected: LINE_TYPE get_logical_line(); - private: + protected: std::istream & m_input_stream; std::ostream & m_output_stream; std::ostream & m_error_stream; diff --git a/Phreeqc.h b/Phreeqc.h index 601be8b6..38142c18 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -944,20 +944,20 @@ public: struct element *element_store(const char *element); int elt_list_combine(void); CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); -private: +protected: struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); int elt_list_print(struct elt_list *elt_list_ptr); struct elt_list *elt_list_save(void); public: struct exchange *exchange_alloc(void); struct exchange *exchange_bsearch(int k, int *n); -private: +protected: int exchange_comp_compare(const void *ptr1, const void *ptr2); void exchange_comp_init(struct exch_comp *exch_comp_ptr); public: int exchange_copy(struct exchange *exchange_old_ptr, struct exchange *exchange_new_ptr, int n_user_new); -private: +protected: CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); int exchange_copy_to_last(int n, int n_user); int exchange_delete(int n_user_old); @@ -966,7 +966,7 @@ int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, const char *description); public: int exchange_free(struct exchange *exchange_ptr); -private: +protected: int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new); @@ -976,12 +976,12 @@ CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); public: struct gas_phase *gas_phase_alloc(void); struct gas_phase *gas_phase_bsearch(int k, int *n); -private: +protected: CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); public: int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, struct gas_phase *gas_phase_new_ptr, int n_user_new); -private: +protected: int gas_phase_copy_to_last(int n, int n_user); int gas_phase_delete(int n_user_old); int gas_phase_duplicate(int n_user_old, int n_user_new); @@ -1012,7 +1012,7 @@ int irrev_sort(void); public: struct kinetics *kinetics_alloc(void); struct kinetics *kinetics_bsearch(int k, int *n); -private: +protected: int kinetics_delete(int n_user_old); int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr); @@ -1020,14 +1020,14 @@ CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); public: int kinetics_copy(struct kinetics *kinetics_old_ptr, struct kinetics *kinetics_new_ptr, int n_user_new); -private: +protected: int kinetics_copy_to_last(int n, int n_user); int kinetics_duplicate(int n_user_old, int n_user_new); int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, char *description); public: int kinetics_free(struct kinetics *kinetics_ptr); -private: +protected: int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new); @@ -1044,7 +1044,6 @@ public: struct master *master_bsearch(const char *ptr); struct master *master_bsearch_primary(char *ptr); struct master *master_bsearch_secondary(char *ptr); -//private: struct master *master_search(char *ptr, int *n); struct mix *mix_bsearch(int k, int *n); int mix_copy(struct mix *mix_old_ptr, @@ -1058,30 +1057,30 @@ struct pe_data *pe_data_alloc(void); public: struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -private: +protected: int pe_data_store(struct pe_data **pe, const char *token); public: struct phase *phase_bsearch(const char *ptr, int *j, int print); -private: +protected: CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); int phase_delete(int i); struct phase *phase_store(char *name); public: struct pp_assemblage *pp_assemblage_alloc(void); struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); -private: +protected: CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); public: int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, struct pp_assemblage *pp_assemblage_new_ptr, int n_user_new); -private: +protected: int pp_assemblage_copy_to_last(int n, int n_user); int pp_assemblage_delete(int n_user_old); int pp_assemblage_duplicate(int n_user_old, int n_user_new); public: int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); -private: +protected: int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, int n_user_end, char *description); int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, @@ -1108,19 +1107,19 @@ struct species *s_store(char *name, LDBLE z, int replace_if_found); public: struct s_s_assemblage *s_s_assemblage_alloc(void); struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); -private: +protected: CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); public: int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, struct s_s_assemblage *s_s_assemblage_new_ptr, int n_user_new); -private: +protected: int s_s_assemblage_copy_to_last(int n, int n_user); int s_s_assemblage_duplicate(int n_user_old, int n_user_new); int s_s_assemblage_delete(int n_user_old); public: int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); -private: +protected: int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description); int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, @@ -1143,7 +1142,7 @@ public: struct solution *solution_bsearch(int k, int *n, int print); struct solution *solution_copy(struct solution *solution_old_ptr, int n_user_new); -private: +protected: int solution_copy_to_last(int n, int n_user_new); int solution_duplicate(int n_user_old, int n_user_new); int solution_delete(int n_user_old); @@ -1160,7 +1159,7 @@ struct Change_Surf *change_surf_alloc(int count); public: struct surface *surface_alloc(void); struct surface *surface_bsearch(int k, int *n); -private: +protected: struct master *surface_get_psi_master(const char *name, int plane); CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); @@ -1170,7 +1169,7 @@ CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); public: int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new); -private: +protected: int surface_copy_to_last(int n, int n_user); int surface_delete(int n_user_old); int surface_duplicate(int n_user_old, int n_user_new); @@ -1379,7 +1378,7 @@ int mix_stag(int i, LDBLE stagkin_time, int punch, // utilities.c ------------------------------- public: int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); -private: +protected: int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: @@ -1392,7 +1391,7 @@ int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); public: void *free_check_null(void *ptr); -private: +protected: void free_hash_strings(HashTable * Table); int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); @@ -1401,12 +1400,12 @@ ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); int islegit(const char c); public: void malloc_error(void); -private: +protected: int parse_couple(char *token); int print_centered(const char *string); public: CLASS_STATIC int replace(const char *str1, const char *str2, char *str); -private: +protected: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); int status(int count, const char *str); @@ -1417,7 +1416,7 @@ int strcmp_nocase_arg1(const char *str1, const char *str2); public: char *string_duplicate(const char *token); char *string_hsave(const char *str); -private: +protected: char *string_pad(char *str, int i); int string_trim(char *str); int string_trim_right(char *str); diff --git a/SSassemblage.h b/SSassemblage.h index 9cdd3912..128c2167 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -49,7 +49,7 @@ public: }; -private: +protected: void add(const cxxSSassemblage & addee, double extensive); protected: diff --git a/Solution.h b/Solution.h index 35e4e770..d20fbd17 100644 --- a/Solution.h +++ b/Solution.h @@ -163,13 +163,12 @@ class cxxSolution:public cxxNumKeyword void mpi_recv(int task_number); #endif - private: + protected: void zero(); void add(const cxxSolution & addee, double extensive); // not checked void dump_xml(std::ostream & os, unsigned int indent = 0) const; - protected: double tc; double ph; double pe; diff --git a/System.h b/System.h index 194f4077..28623d0a 100644 --- a/System.h +++ b/System.h @@ -76,7 +76,7 @@ public: return this->totals; } -private: +protected: cxxSolution * solution; cxxExchange * exchange; cxxPPassemblage * ppassemblage; diff --git a/cxxKinetics.h b/cxxKinetics.h index d1e3fd77..c9e78349 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -47,7 +47,7 @@ class cxxKinetics:public cxxNumKeyword void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); #endif - private: + protected: void add(const cxxKinetics & addee, double extensive); protected: From ee9dcce40b93c6b5e8f100925f1f96a322100301 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sat, 15 Oct 2011 00:40:56 +0000 Subject: [PATCH 0276/1077] writing cxxStorageBin2phreeqc. clean up some consts. Adding methods for Mix, Reaction, Temperature. Need parallel method for exchange_ptr_to_user for mix, irrev, temperature. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5689 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 2 +- GasPhase.cxx | 2 +- PPassemblage.cxx | 2 +- Phreeqc.h | 4 ++-- SSassemblage.cxx | 2 +- Solution.cxx | 2 +- StorageBin.cxx | 15 +++++++++++++++ StorageBin.h | 3 +++ Surface.cxx | 2 +- cxxKinetics.cxx | 2 +- cxxMix.h | 2 +- 11 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 95e056fb..5f1b5e23 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -67,7 +67,7 @@ cxxNumKeyword(io) // // Mix exchangers // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/GasPhase.cxx b/GasPhase.cxx index 7db36be7..cb665f14 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -82,7 +82,7 @@ cxxNumKeyword(io) // Mix // //cxxNameDouble gasPhaseComps; - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double > & mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 90e5ab0a..0ed860cb 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -64,7 +64,7 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/Phreeqc.h b/Phreeqc.h index 38142c18..4651a617 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1245,7 +1245,7 @@ extern void MergeFinalize(void); // convert class to struct -struct mix * cxxMix2mix(cxxMix *mx); +struct mix * cxxMix2mix(const cxxMix *mx); struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); struct exchange * cxxExchange2exchange(const cxxExchange * ex); @@ -1275,7 +1275,7 @@ void Use2cxxStorageBin(cxxStorageBin & sb); void phreeqc2cxxStorageBin(cxxStorageBin & sb); void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); void cxxStorageBin2phreeqc0(cxxStorageBin & sb, int n); - +void cxxStorageBin2phreeqc(cxxStorageBin & sb); /* tally.c */ diff --git a/SSassemblage.cxx b/SSassemblage.cxx index df020ea7..0d783151 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -61,7 +61,7 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/Solution.cxx b/Solution.cxx index 843bb5f7..46c94209 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -115,7 +115,7 @@ isotopes(io) // // Mix solutions // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/StorageBin.cxx b/StorageBin.cxx index f0fb0236..5b38c538 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -322,6 +322,21 @@ cxxStorageBin::Get_Surfaces() const { return this->Surfaces; } +const std::map < int, cxxMix > & +cxxStorageBin::Get_Mixes() const +{ + return this->Mixes; +} +const std::map < int, cxxReaction > & +cxxStorageBin::Get_Reactions() const +{ + return this->Reactions; +} +const std::map < int, cxxTemperature > & +cxxStorageBin::Get_Temperatures() const +{ + return this->Temperatures; +} #ifdef SKIP void diff --git a/StorageBin.h b/StorageBin.h index ee21a78e..03b4adf3 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -94,6 +94,9 @@ class cxxStorageBin: public PHRQ_base const std::map < int, cxxPPassemblage > &Get_PPassemblages() const; const std::map < int, cxxSSassemblage > &Get_SSassemblages() const; const std::map < int, cxxSurface > &Get_Surfaces() const; + const std::map < int, cxxMix > &Get_Mixes() const; + const std::map < int, cxxReaction > &Get_Reactions() const; + const std::map < int, cxxTemperature > &Get_Temperatures() const; cxxSystem & Get_system(void) {return system;}; #ifdef USE_MPI diff --git a/Surface.cxx b/Surface.cxx index 5f5eac4d..bdf3e9b6 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -100,7 +100,7 @@ cxxNumKeyword(io) // // Mix exchangers // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 91c213cd..f37245bd 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -100,7 +100,7 @@ cxxNumKeyword(io) // // Mix // - std::map < int, double >&mixcomps = mix.Get_mixComps(); + const std::map < int, double >&mixcomps = mix.Get_mixComps(); std::map < int, double >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { diff --git a/cxxMix.h b/cxxMix.h index d3d68e24..1d71ca80 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -43,7 +43,7 @@ class cxxMix:public cxxNumKeyword } }; - std::map < int, double > & Get_mixComps() + const std::map < int, double > & Get_mixComps() const { return mixComps; } From cbc2c21020864408f79f42c34d1abe99b076a94e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sat, 15 Oct 2011 18:45:36 +0000 Subject: [PATCH 0277/1077] Added ptr_to_user for mix, irrev, and temperature. Removed cxxStorageBin2phreeqc0. Now writes reactants n from storage bin to phreeqc without restrictions with extra arg to cxxStorageBin2phreeqc. cxxStorageBin2phreeqc with just a storagebin copies all reactants into phreeqc. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5691 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index 4651a617..09508feb 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1008,6 +1008,7 @@ int irrev_delete(int n_user_old); int irrev_duplicate(int n_user_old, int n_user_new); int irrev_free(struct irrev *irrev_ptr); struct irrev *irrev_search(int n_user, int *n); +int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); int irrev_sort(void); public: struct kinetics *kinetics_alloc(void); @@ -1052,6 +1053,7 @@ int mix_delete(int n_user_old); int mix_duplicate(int n_user_old, int n_user_new); int mix_free(struct mix *mix_ptr); struct mix *mix_search(int n_user, int *n, int print); +int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); int mix_sort(void); struct pe_data *pe_data_alloc(void); public: @@ -1190,6 +1192,7 @@ int temperature_delete(int n_user_old); int temperature_duplicate(int n_user_old, int n_user_new); int temperature_free(struct temperature *temperature_ptr); struct temperature *temperature_search(int n_user, int *n); +int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); int temperature_sort(void); int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); @@ -1274,7 +1277,7 @@ struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); void Use2cxxStorageBin(cxxStorageBin & sb); void phreeqc2cxxStorageBin(cxxStorageBin & sb); void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); -void cxxStorageBin2phreeqc0(cxxStorageBin & sb, int n); +void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); void cxxStorageBin2phreeqc(cxxStorageBin & sb); /* tally.c */ From 79541da63121104608c9b4776cfbca19b9ec1b94 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sat, 15 Oct 2011 20:31:00 +0000 Subject: [PATCH 0278/1077] Removing struct system. Not used. Missing KT_MIX_RAW in Parser. Storage bin, renamed removeXxx to Remove_Xxx. Added missing mix, reaction, temperature to dump_raw. Added missing mix read_raw to storagebin read_raw. Removed storagebin add(struct system), not used. Added missing mix, reaction, temperature in storagebin remove. Added storagebin Clear to remove all data. Hopefully does not leak memory. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5692 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 5 +- StorageBin.cxx | 212 +++++++++++++++++++++++++++++++++---------------- StorageBin.h | 25 +++--- 3 files changed, 160 insertions(+), 82 deletions(-) diff --git a/Parser.h b/Parser.h index b6423d3a..a7395959 100644 --- a/Parser.h +++ b/Parser.h @@ -56,9 +56,10 @@ class CParser: public PHRQ_base KT_SSASSEMBLAGE_RAW = 10, KT_SURFACE_RAW = 11, KT_TEMPERATURE_RAW = 12, - KT_REACTION_RAW = 13 + KT_REACTION_RAW = 13, + KT_MIX_RAW = 14 #if defined MULTICHART - , KT_USER_GRAPH = 14 + , KT_USER_GRAPH = 15 #endif }; diff --git a/StorageBin.cxx b/StorageBin.cxx index 5b38c538..9ac8226e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -74,7 +74,7 @@ cxxStorageBin::Set_Solution(int n_user, cxxSolution & entity) Solutions[n_user] = entity; } void -cxxStorageBin::removeSolution(int n_user) +cxxStorageBin::Remove_Solution(int n_user) { Solutions.erase(n_user); } @@ -96,7 +96,7 @@ cxxStorageBin::Set_Exchange(int n_user, cxxExchange * entity) Exchangers[n_user] = *entity; } void -cxxStorageBin::removeExchange(int n_user) +cxxStorageBin::Remove_Exchange(int n_user) { Exchangers.erase(n_user); } @@ -123,7 +123,7 @@ cxxStorageBin::Set_PPassemblage(int n_user, cxxPPassemblage & entity) PPassemblages[n_user] = entity; } void -cxxStorageBin::removePPassemblage(int n_user) +cxxStorageBin::Remove_PPassemblage(int n_user) { PPassemblages.erase(n_user); } @@ -145,7 +145,7 @@ cxxStorageBin::Set_GasPhase(int n_user, cxxGasPhase * entity) GasPhases[n_user] = *entity; } void -cxxStorageBin::removeGasPhase(int n_user) +cxxStorageBin::Remove_GasPhase(int n_user) { GasPhases.erase(n_user); } @@ -172,7 +172,7 @@ cxxStorageBin::Set_SSassemblage(int n_user, cxxSSassemblage & entity) SSassemblages[n_user] = entity; } void -cxxStorageBin::removeSSassemblage(int n_user) +cxxStorageBin::Remove_SSassemblage(int n_user) { SSassemblages.erase(n_user); } @@ -194,7 +194,7 @@ cxxStorageBin::Set_Kinetics(int n_user, cxxKinetics * entity) Kinetics[n_user] = *entity; } void -cxxStorageBin::removeKinetics(int n_user) +cxxStorageBin::Remove_Kinetics(int n_user) { Kinetics.erase(n_user); } @@ -216,7 +216,7 @@ cxxStorageBin::Set_Surface(int n_user, cxxSurface * entity) Surfaces[n_user] = *entity; } void -cxxStorageBin::removeSurface(int n_user) +cxxStorageBin::Remove_Surface(int n_user) { Surfaces.erase(n_user); } @@ -238,7 +238,7 @@ cxxStorageBin::Set_Mix(int n_user, cxxMix * entity) Mixes[n_user] = *entity; } void -cxxStorageBin::removeMix(int n_user) +cxxStorageBin::Remove_Mix(int n_user) { Mixes.erase(n_user); } @@ -260,7 +260,7 @@ cxxStorageBin::Set_Reaction(int n_user, cxxReaction * entity) Reactions[n_user] = *entity; } void -cxxStorageBin::removeReaction(int n_user) +cxxStorageBin::Remove_Reaction(int n_user) { Reactions.erase(n_user); } @@ -282,7 +282,7 @@ cxxStorageBin::Set_Temperature(int n_user, cxxTemperature * entity) Temperatures[n_user] = *entity; } void -cxxStorageBin::removeTemperature(int n_user) +cxxStorageBin::Remove_Temperature(int n_user) { Temperatures.erase(n_user); } @@ -462,6 +462,24 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent, int *n { this->Get_Surface(n)->dump_raw(s_oss, indent, &n_user_local); } + + // Mix + if (this->Get_Mix(n) != NULL) + { + this->Get_Mix(n)->dump_raw(s_oss, indent, &n_user_local); + } + + // Reaction + if (this->Get_Reaction(n) != NULL) + { + this->Get_Reaction(n)->dump_raw(s_oss, indent, &n_user_local); + } + + // Temperature + if (this->Get_Temperature(n) != NULL) + { + this->Get_Temperature(n)->dump_raw(s_oss, indent, &n_user_local); + } } void @@ -567,6 +585,13 @@ cxxStorageBin::read_raw(CParser & parser) Reactions[entity.Get_n_user()] = entity; } break; + case CParser::KT_MIX_RAW: + { + cxxMix entity; + entity.read_raw(parser); + Mixes[entity.Get_n_user()] = entity; + } + break; default: break; } @@ -694,65 +719,73 @@ cxxStorageBin::read_raw_keyword(CParser & parser) return (entity_number); //CParser::LT_OK; } -void -cxxStorageBin::add(struct system *system_ptr) - // - // add data from a system structure - // -{ - - // Solutions - if (system_ptr->solution != NULL) - { - this->Solutions[system_ptr->solution->n_user] = - cxxSolution(system_ptr->solution, this->Get_io()); - } - - // Exchangers - if (system_ptr->exchange != NULL) - { - this->Exchangers[system_ptr->exchange->n_user] = - cxxExchange(system_ptr->exchange, this->Get_io()); - } - - // GasPhases - if (system_ptr->gas_phase != NULL) - { - this->GasPhases[system_ptr->gas_phase->n_user] = - cxxGasPhase(system_ptr->gas_phase, this->Get_io()); - } - - // Kinetics - if (system_ptr->kinetics != NULL) - { - this->Kinetics[system_ptr->kinetics->n_user] = - cxxKinetics(system_ptr->kinetics, this->Get_io()); - } - - // PPassemblages - if (system_ptr->pp_assemblage != NULL) - { - this->PPassemblages[system_ptr->pp_assemblage->n_user] = - cxxPPassemblage(system_ptr->pp_assemblage, this->Get_io()); - } - - // SSassemblages - if (system_ptr->s_s_assemblage != NULL) - { - this->SSassemblages[system_ptr->s_s_assemblage->n_user] = - cxxSSassemblage(system_ptr->s_s_assemblage); - } - - // Surfaces - if (system_ptr->surface != NULL) - { - this->Surfaces[system_ptr->surface->n_user] = - cxxSurface(system_ptr->surface, this->Get_io()); - } -} +//void +//cxxStorageBin::add(struct system *system_ptr) +// // +// // add data from a system structure +// // +//{ +// +// // Solutions +// if (system_ptr->solution != NULL) +// { +// this->Solutions[system_ptr->solution->n_user] = +// cxxSolution(system_ptr->solution, this->Get_io()); +// } +// +// // Exchangers +// if (system_ptr->exchange != NULL) +// { +// this->Exchangers[system_ptr->exchange->n_user] = +// cxxExchange(system_ptr->exchange, this->Get_io()); +// } +// +// // GasPhases +// if (system_ptr->gas_phase != NULL) +// { +// this->GasPhases[system_ptr->gas_phase->n_user] = +// cxxGasPhase(system_ptr->gas_phase, this->Get_io()); +// } +// +// // Kinetics +// if (system_ptr->kinetics != NULL) +// { +// this->Kinetics[system_ptr->kinetics->n_user] = +// cxxKinetics(system_ptr->kinetics, this->Get_io()); +// } +// +// // PPassemblages +// if (system_ptr->pp_assemblage != NULL) +// { +// this->PPassemblages[system_ptr->pp_assemblage->n_user] = +// cxxPPassemblage(system_ptr->pp_assemblage, this->Get_io()); +// } +// +// // SSassemblages +// if (system_ptr->s_s_assemblage != NULL) +// { +// this->SSassemblages[system_ptr->s_s_assemblage->n_user] = +// cxxSSassemblage(system_ptr->s_s_assemblage); +// } +// +// // Surfaces +// if (system_ptr->surface != NULL) +// { +// this->Surfaces[system_ptr->surface->n_user] = +// cxxSurface(system_ptr->surface, this->Get_io()); +// } +// +// // struct system not used +// //// Mixes +// //if (system_ptr->mix != NULL) +// //{ +// // this->Mixes[system_ptr->mix->n_user] = +// // cxxMix(system_ptr->mix, this->Get_io()); +// //} +//} void -cxxStorageBin::remove(int n) +cxxStorageBin::Remove(int n) { // Solution this->Solutions.erase(n); @@ -774,8 +807,51 @@ cxxStorageBin::remove(int n) // Surface this->Surfaces.erase(n); -} + // Mixes + this->Mixes.erase(n); + + // Reactions + this->Reactions.erase(n); + + // Temperature + this->Temperatures.erase(n); +} +void +cxxStorageBin::Clear(void) +{ + // Delete all data + + // Solutions + this->Solutions.clear(); + + // Exchange + this->Exchangers.clear(); + + // Gas Phases + this->GasPhases.clear(); + + // Kinetics + this->Kinetics.clear(); + + // PPassemblage + this->PPassemblages.clear(); + + this->SSassemblages.clear(); + + // Surface + this->Surfaces.clear(); + + // Mix + this->Mixes.clear(); + + // Reactions + this->Reactions.clear(); + + // Temperature + this->Temperatures.clear(); + +} #ifdef SKIP cxxSolution * cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) diff --git a/StorageBin.h b/StorageBin.h index 03b4adf3..7e090cae 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -26,50 +26,51 @@ class cxxStorageBin: public PHRQ_base cxxStorageBin(PHRQ_io *io=NULL); ~cxxStorageBin(); - void remove(int n); + void Remove(int n); + void Clear(void); cxxSolution *Get_Solution(int n_user); void Set_Solution(int n_user, cxxSolution * entity); void Set_Solution(int n_user, cxxSolution & entity); - void removeSolution(int n_user); + void Remove_Solution(int n_user); cxxExchange *Get_Exchange(int n_user); void Set_Exchange(int n_user, cxxExchange * entity); - void removeExchange(int n_user); + void Remove_Exchange(int n_user); cxxPPassemblage *Get_PPassemblage(int n_user); void Set_PPassemblage(int n_user, cxxPPassemblage * entity); void Set_PPassemblage(int n_user, cxxPPassemblage & entity); - void removePPassemblage(int n_user); + void Remove_PPassemblage(int n_user); cxxGasPhase *Get_GasPhase(int n_user); void Set_GasPhase(int n_user, cxxGasPhase * entity); - void removeGasPhase(int n_user); + void Remove_GasPhase(int n_user); cxxSSassemblage *Get_SSassemblage(int n_user); void Set_SSassemblage(int n_user, cxxSSassemblage * entity); void Set_SSassemblage(int n_user, cxxSSassemblage & entity); - void removeSSassemblage(int n_user); + void Remove_SSassemblage(int n_user); cxxKinetics *Get_Kinetics(int n_user); void Set_Kinetics(int n_user, cxxKinetics * entity); - void removeKinetics(int n_user); + void Remove_Kinetics(int n_user); cxxSurface *Get_Surface(int n_user); void Set_Surface(int n_user, cxxSurface * entity); - void removeSurface(int n_user); + void Remove_Surface(int n_user); cxxMix *Get_Mix(int n_user); void Set_Mix(int n_user, cxxMix * entity); - void removeMix(int n_user); + void Remove_Mix(int n_user); cxxReaction *Get_Reaction(int n_user); void Set_Reaction(int n_user, cxxReaction * entity); - void removeReaction(int n_user); + void Remove_Reaction(int n_user); cxxTemperature *Get_Temperature(int n_user); void Set_Temperature(int n_user, cxxTemperature * entity); - void removeTemperature(int n_user); + void Remove_Temperature(int n_user); cxxSystem &Get_System(void); void Set_System(struct Use *use_ptr); @@ -82,7 +83,7 @@ class cxxStorageBin: public PHRQ_base void read_raw(CParser & parser); int read_raw_keyword(CParser & parser); - void add(struct system *sys_ptr); + //void add(struct system *sys_ptr); //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); From 1fb2150c8238f3fc38660283eee8236ed717e0a6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Oct 2011 19:00:15 +0000 Subject: [PATCH 0279/1077] Removed OUTPUT_CVODE, OUTPUT_STDERR, OUTPUT_BASIC, and commented OUTPUT_SEND_MESSAGE. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5695 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 120 +++++++++++++++++++++++++++------------------------- PHRQ_io.h | 113 +++++++++++-------------------------------------- 2 files changed, 87 insertions(+), 146 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 8a9a22c1..81ecda02 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -30,7 +30,54 @@ PHRQ_io:: ~PHRQ_io() { } +void +PHRQ_io::Set_database_file(FILE * in) +{ + safe_close(this->database_file); + this->database_file = in; +} +void +PHRQ_io::Set_input_file(FILE * in) +{ + safe_close(this->input_file); + this->input_file = in; +} +void +PHRQ_io::Set_output_file(FILE * out) +{ + safe_close(this->output_file); + this->output_file = out; +} +void +PHRQ_io::Set_error_file(FILE * out) +{ + safe_close(this->error_file); + this->error_file = out; +} +void +PHRQ_io::Set_log_file(FILE * out) +{ + safe_close(this->log_file); + this->log_file = out; +} +void +PHRQ_io::Set_punch_file(FILE * out) +{ + safe_close(this->punch_file); + this->punch_file = out; +} +void +PHRQ_io::Set_dump_file(FILE * out) +{ + safe_close(this->dump_file); + this->dump_file = out; +} +void +PHRQ_io::close_input(void) +{ + safe_close(input_file); +} /* ---------------------------------------------------------------------- */ int PHRQ_io:: close_input_files(void) @@ -190,7 +237,6 @@ output_msg(int type, const char *format, va_list args) } break; case OUTPUT_MESSAGE: - case OUTPUT_BASIC: if (output_file != NULL && output_file_on) { vfprintf(output_file, format, args); @@ -224,14 +270,7 @@ output_msg(int type, const char *format, va_list args) fflush(error_file); } break; - case OUTPUT_STDERR: - case OUTPUT_CVODE: - if (stderr != NULL) - { - vfprintf(stderr, format, args); - fflush(stderr); - } - break; + case OUTPUT_DUMP: if (dump_file != NULL && dump_file_on) { @@ -293,7 +332,6 @@ output_string(const int type, std::string str) break; case OUTPUT_CHECKLINE: case OUTPUT_MESSAGE: - case OUTPUT_BASIC: if (output_file != NULL && output_file_on) { fprintf(output_file, "%s", str.c_str()); @@ -318,14 +356,7 @@ output_string(const int type, std::string str) fflush(error_file); } break; - case OUTPUT_STDERR: - case OUTPUT_CVODE: - if (stderr != NULL) - { - fprintf(stderr, "%s", str.c_str()); - fflush(stderr); - } - break; + case OUTPUT_DUMP: if (dump_file != NULL && dump_file_on) { @@ -464,9 +495,6 @@ output_isopen(const int type) case OUTPUT_DUMP: return (dump_file != NULL); break; - case OUTPUT_STDERR: - return (stderr != NULL); - break; default: assert(false); return (output_file != NULL); @@ -496,7 +524,6 @@ output_fflush(const int type) case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: - case OUTPUT_BASIC: if (output_file) fflush(output_file); break; @@ -516,12 +543,6 @@ output_fflush(const int type) fflush(log_file); break; - case OUTPUT_CVODE: - case OUTPUT_STDERR: - if (stderr) - fflush(stderr); - break; - case OUTPUT_DUMP: if (dump_file) fflush(dump_file); @@ -549,7 +570,6 @@ output_rewind(const int type) case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: - case OUTPUT_BASIC: if (output_file) rewind(output_file); break; @@ -569,12 +589,6 @@ output_rewind(const int type) rewind(log_file); break; - case OUTPUT_CVODE: - case OUTPUT_STDERR: - if (stderr) - rewind(stderr); - break; - case OUTPUT_DUMP: if (dump_file) rewind(dump_file); @@ -589,48 +603,37 @@ output_close(const int type) switch (type) { case OUTPUT_ERROR: - if (error_file) - safe_close(error_file); + safe_close(error_file); break; case OUTPUT_WARNING: - if (error_file) - safe_close(error_file); - if (output_file) - safe_close(output_file); + safe_close(error_file); + safe_close(output_file); break; case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: - case OUTPUT_BASIC: - if (output_file) - safe_close(output_file); + safe_close(output_file); break; case OUTPUT_PUNCH: - if (punch_file) - safe_close(punch_file); + safe_close(punch_file); break; case OUTPUT_SCREEN: - if (error_file) - safe_close(error_file); + safe_close(error_file); break; case OUTPUT_LOG: - if (log_file) - safe_close(log_file); - break; - - case OUTPUT_CVODE: - case OUTPUT_STDERR: - if (stderr) - safe_close(stderr); + safe_close(log_file); break; case OUTPUT_DUMP: - if (dump_file) - safe_close(dump_file); + safe_close(dump_file); + break; + + default: + assert(false); break; } } @@ -647,6 +650,7 @@ safe_close(FILE * file_ptr) file_ptr != NULL) { fclose(file_ptr); + file_ptr = NULL; } } diff --git a/PHRQ_io.h b/PHRQ_io.h index fad4128f..f49133eb 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -18,11 +18,8 @@ typedef enum OUTPUT_LOG, OUTPUT_CHECKLINE, OUTPUT_GUI_ERROR, - OUTPUT_BASIC, - OUTPUT_CVODE, OUTPUT_DUMP, - OUTPUT_STDERR, - OUTPUT_SEND_MESSAGE, + //OUTPUT_SEND_MESSAGE, OUTPUT_ECHO, OUTPUT_PUNCH_END_ROW } output_type; @@ -58,90 +55,30 @@ typedef enum bool output_isopen(int type); void fpunchf(const char *name, const char *format, va_list args); - void Set_io_error_count(int i) - { - this->io_error_count = i; - } - int Get_io_error_count(void) - { - return this->io_error_count; - } - void Set_input_file(FILE * in) - { - if (this->input_file != NULL && - this->input_file != stderr && - this->input_file != stdout) - { - fclose(this->input_file); - } - this->input_file = in; - } - void Set_output_file(FILE * out) - { - if (this->output_file != NULL && - this->output_file != stderr && - this->output_file != stdout) - { - fclose(this->output_file); - } - this->output_file = out; - } - void Set_database_file(FILE * in) - { - if (this->database_file != NULL && - this->database_file != stdin) - { - fclose(this->database_file); - } - this->database_file = in; - } - void close_input(void) - { - if (input_file != stdin) - { - fclose(input_file); - } - } - void Set_output_file_on(bool tf) - { - this->output_file_on = tf; - } - void Set_log_file_on(bool tf) - { - this->log_file_on = tf; - } - void Set_punch_file_on(bool tf) - { - this->punch_file_on = tf; - } - void Set_error_file_on(bool tf) - { - this->error_file_on = tf; - } - void Set_dump_file_on(bool tf) - { - this->dump_file_on = tf; - } - bool Get_output_file_on(void) - { - return this->output_file_on; - } - bool Get_log_file_on(void) - { - return this->log_file_on; - } - bool Get_punch_file_on(void) - { - return this->punch_file_on; - } - bool Get_error_file_on(void) - { - return this->error_file_on; - } - bool Get_dump_file_on(void) - { - return this->dump_file_on; - } + void Set_io_error_count(int i) {this->io_error_count = i;}; + int Get_io_error_count(void) {return this->io_error_count;}; + void Set_database_file(FILE * in); + void Set_input_file(FILE * in); + void Set_output_file(FILE * out); + void Set_error_file(FILE * out); + void Set_log_file(FILE * out); + void Set_punch_file(FILE * out); + void Set_dump_file(FILE * out); + + void PHRQ_io::close_input(void); + + void Set_output_file_on(bool tf) {this->output_file_on = tf;}; + void Set_log_file_on(bool tf) {this->log_file_on = tf;}; + void Set_punch_file_on(bool tf) {this->punch_file_on = tf;}; + void Set_error_file_on(bool tf) {this->error_file_on = tf;}; + void Set_dump_file_on(bool tf) {this->dump_file_on = tf;}; + + bool Get_output_file_on(void) {return this->output_file_on;}; + bool Get_log_file_on(void) {return this->log_file_on;}; + bool Get_punch_file_on(void) {return this->punch_file_on;}; + bool Get_error_file_on(void) {return this->error_file_on;}; + bool Get_dump_file_on(void) {return this->dump_file_on;}; + // data protected: FILE *input_file; From 534005377eee6796a3164aa23f0d0707adc3cded Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Oct 2011 19:27:52 +0000 Subject: [PATCH 0280/1077] Cleaned up kinetics.cpp. Changed io in Parser.cxx a little. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5696 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 2 +- Parser.cxx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index f49133eb..fbf6f932 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -43,12 +43,12 @@ typedef enum int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); - void output_string(const int type, std::string str); int output_open(int type, const char *file_name); void error_msg(const char *err_str, bool stop); void warning_msg(const char *err_str); void output_msg(int type, const char *format, va_list args); + void output_string(const int type, std::string str); void output_fflush(int type); void output_rewind(int type); void output_close(int type); diff --git a/Parser.cxx b/Parser.cxx index 318ac101..0a58fd22 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -130,7 +130,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->output_msg(msg.str()); } break; case EO_KEYWORDS: @@ -138,7 +138,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->output_msg(msg.str()); } break; @@ -147,7 +147,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->Get_io()->output_string(PHRQ_io::OUTPUT_MESSAGE, msg.str()); + this->output_msg(msg.str().c_str()); } break; } From ecd1d9c6208ce1d465ca3938d8d0867a221966eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Oct 2011 21:13:40 +0000 Subject: [PATCH 0281/1077] Working on interface for run_reactions. Added a PHRQ_io to RM_interface class for now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5697 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index fbf6f932..7a1b6d51 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -47,12 +47,12 @@ typedef enum int output_open(int type, const char *file_name); void error_msg(const char *err_str, bool stop); void warning_msg(const char *err_str); - void output_msg(int type, const char *format, va_list args); void output_string(const int type, std::string str); void output_fflush(int type); void output_rewind(int type); void output_close(int type); bool output_isopen(int type); + void output_msg(int type, const char *format, va_list args); void fpunchf(const char *name, const char *format, va_list args); void Set_io_error_count(int i) {this->io_error_count = i;}; From ab42554893ec9eebaaf0bf0a9669f757e8af869d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 15:37:39 +0000 Subject: [PATCH 0282/1077] Beginning to remove enum OUTPUT_MESSAGE, OUTPUT_ERROR, etc. Wrote individual methods for each file to open, close, rewind, flush, isopen. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5698 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++++ PHRQ_io.h | 31 ++++++ 2 files changed, 297 insertions(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 81ecda02..aa1afcd8 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -73,6 +73,272 @@ PHRQ_io::Set_dump_file(FILE * out) this->dump_file = out; } +// ---------------------------------------------------------------------- */ +// output file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +open_output(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + safe_close(output_file); + if ((output_file = fopen(file_name, "w")) == NULL) + { + return true; // error + } + return false; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fflush_output(void) +/* ---------------------------------------------------------------------- */ +{ + if (output_file && output_file_on) + { + fflush(output_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_output(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(output_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +rewind_output(void) +/* ---------------------------------------------------------------------- */ +{ + if (output_file && output_file_on) + { + rewind(output_file); + } +} +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_output(void) +/* ---------------------------------------------------------------------- */ +{ + if (output_file) + return true; // open + return false; +} +// ---------------------------------------------------------------------- */ +// log file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +open_log(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + safe_close(log_file); + if ((log_file = fopen(file_name, "w")) == NULL) + { + return true; // error + } + return false; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fflush_log(void) +/* ---------------------------------------------------------------------- */ +{ + if (log_file && log_file_on) + { + fflush(log_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_log(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(log_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +rewind_log(void) +/* ---------------------------------------------------------------------- */ +{ + if (log_file && log_file_on) + { + rewind(log_file); + } +} +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_log(void) +/* ---------------------------------------------------------------------- */ +{ + if (log_file) + return true; // open + return false; +} + +// ---------------------------------------------------------------------- */ +// punch file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +open_punch(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + safe_close(punch_file); + if ((punch_file = fopen(file_name, "w")) == NULL) + { + return true; // error + } + return false; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fflush_punch(void) +/* ---------------------------------------------------------------------- */ +{ + if (punch_file && punch_file_on) + { + fflush(punch_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_punch(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(punch_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +rewind_punch(void) +/* ---------------------------------------------------------------------- */ +{ + if (punch_file && punch_file_on) + { + rewind(punch_file); + } +} +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_punch(void) +/* ---------------------------------------------------------------------- */ +{ + if (punch_file) + return true; // open + return false; +} + +// ---------------------------------------------------------------------- */ +// error file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +open_error(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + safe_close(error_file); + if ((error_file = fopen(file_name, "w")) == NULL) + { + return true; // error + } + return false; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fflush_error(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_file && error_file_on) + { + fflush(error_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_error(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(error_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +rewind_error(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_file && error_file_on) + { + rewind(error_file); + } +} +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_error(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_file) + return true; // open + return false; +} + +// ---------------------------------------------------------------------- */ +// dump file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +open_dump(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + safe_close(dump_file); + if ((dump_file = fopen(file_name, "w")) == NULL) + { + return true; // error + } + return false; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fflush_dump(void) +/* ---------------------------------------------------------------------- */ +{ + if (dump_file && dump_file_on) + { + fflush(dump_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_dump(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(dump_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +rewind_dump(void) +/* ---------------------------------------------------------------------- */ +{ + if (dump_file && dump_file_on) + { + rewind(dump_file); + } +} +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +isopen_dump(void) +/* ---------------------------------------------------------------------- */ +{ + if (dump_file) + return true; // open + return false; +} + + + void PHRQ_io::close_input(void) { diff --git a/PHRQ_io.h b/PHRQ_io.h index 7a1b6d51..7bb382f2 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -43,6 +43,37 @@ typedef enum int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); + + // output_file + bool open_output(const char *file_name); + void fflush_output(void); + void close_output(void); + void rewind_output(void); + bool isopen_output(void); + // log_file + bool open_log(const char *file_name); + void fflush_log(void); + void close_log(void); + void rewind_log(void); + bool isopen_log(void); + // punch_file + bool open_punch(const char *file_name); + void fflush_punch(void); + void close_punch(void); + void rewind_punch(void); + bool isopen_punch(void); + // error_file + bool open_error(const char *file_name); + void fflush_error(void); + void close_error(void); + void rewind_error(void); + bool isopen_error(void); + // dump_file + bool open_dump(const char *file_name); + void fflush_dump(void); + void close_dump(void); + void rewind_dump(void); + bool isopen_dump(void); int output_open(int type, const char *file_name); void error_msg(const char *err_str, bool stop); From e2e3ba09b701104a1c8d9a7e98e80409513b3ba5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 16:10:45 +0000 Subject: [PATCH 0283/1077] Renamed methods and added _msg to output (_temp for now), punch, error, log, dump. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5699 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 261 +++++++++++++++++++++++++++++++--------------------- PHRQ_io.h | 78 +++++++++------- 2 files changed, 200 insertions(+), 139 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index aa1afcd8..ec10925f 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -16,7 +16,7 @@ PHRQ_io(void) log_file = NULL; /* OUTPUT_LOG */ punch_file = NULL; /* OUTPUT_PUNCH */ error_file = NULL; /* OUTPUT_ERROR */ - dump_file = NULL; /* OUTPUT_DUMP */ + dump_file = NULL; io_error_count = 0; output_file_on = true; @@ -79,7 +79,7 @@ PHRQ_io::Set_dump_file(FILE * out) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -open_output(const char *file_name) +output_open_temp(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(output_file); @@ -91,7 +91,7 @@ open_output(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -fflush_output(void) +output_fflush_temp(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -101,14 +101,14 @@ fflush_output(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_output(void) +output_close_temp(void) /* ---------------------------------------------------------------------- */ { safe_close(output_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -rewind_output(void) +output_rewind_temp(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -118,20 +118,30 @@ rewind_output(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -isopen_output(void) +output_isopen_temp(void) /* ---------------------------------------------------------------------- */ { if (output_file) return true; // open return false; } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_msg_temp(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "%s", str); + } +} // ---------------------------------------------------------------------- */ // log file methods // ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -open_log(const char *file_name) +log_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(log_file); @@ -143,7 +153,7 @@ open_log(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -fflush_log(void) +log_fflush(void) /* ---------------------------------------------------------------------- */ { if (log_file && log_file_on) @@ -153,14 +163,14 @@ fflush_log(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_log(void) +log_close(void) /* ---------------------------------------------------------------------- */ { safe_close(log_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -rewind_log(void) +log_rewind(void) /* ---------------------------------------------------------------------- */ { if (log_file && log_file_on) @@ -170,21 +180,30 @@ rewind_log(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -isopen_log(void) +log_isopen(void) /* ---------------------------------------------------------------------- */ { if (log_file) return true; // open return false; } - +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +log_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "%s", str); + } +} // ---------------------------------------------------------------------- */ // punch file methods // ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -open_punch(const char *file_name) +punch_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(punch_file); @@ -196,7 +215,7 @@ open_punch(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -fflush_punch(void) +punch_fflush(void) /* ---------------------------------------------------------------------- */ { if (punch_file && punch_file_on) @@ -206,14 +225,14 @@ fflush_punch(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_punch(void) +punch_close(void) /* ---------------------------------------------------------------------- */ { safe_close(punch_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -rewind_punch(void) +punch_rewind(void) /* ---------------------------------------------------------------------- */ { if (punch_file && punch_file_on) @@ -223,13 +242,23 @@ rewind_punch(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -isopen_punch(void) +punch_isopen(void) /* ---------------------------------------------------------------------- */ { if (punch_file) return true; // open return false; } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +punch_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (punch_file != NULL && punch_file_on) + { + fprintf(punch_file, "%s", str); + } +} // ---------------------------------------------------------------------- */ // error file methods @@ -237,7 +266,7 @@ isopen_punch(void) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -open_error(const char *file_name) +error_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(error_file); @@ -249,7 +278,7 @@ open_error(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -fflush_error(void) +error_fflush(void) /* ---------------------------------------------------------------------- */ { if (error_file && error_file_on) @@ -259,14 +288,14 @@ fflush_error(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_error(void) +error_close(void) /* ---------------------------------------------------------------------- */ { safe_close(error_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -rewind_error(void) +error_rewind(void) /* ---------------------------------------------------------------------- */ { if (error_file && error_file_on) @@ -276,13 +305,54 @@ rewind_error(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -isopen_error(void) +error_isopen(void) /* ---------------------------------------------------------------------- */ { if (error_file) return true; // open return false; } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + + io_error_count++; + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "\nERROR: %s\n", err_str); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "ERROR: %s\n", err_str); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "ERROR: %s\n", err_str); + fflush(log_file); + } + if (stop) + { + if (error_file != NULL && error_file_on) + { + fprintf(error_file, "Stopping.\n"); + fflush(error_file); + } + if (output_file != NULL && output_file_on) + { + fprintf(output_file, "Stopping.\n"); + fflush(output_file); + } + if (log_file != NULL && log_file_on) + { + fprintf(log_file, "Stopping.\n"); + fflush(log_file); + } + } +} // ---------------------------------------------------------------------- */ // dump file methods @@ -290,7 +360,7 @@ isopen_error(void) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -open_dump(const char *file_name) +dump_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(dump_file); @@ -302,7 +372,7 @@ open_dump(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -fflush_dump(void) +dump_fflush(void) /* ---------------------------------------------------------------------- */ { if (dump_file && dump_file_on) @@ -312,14 +382,14 @@ fflush_dump(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_dump(void) +dump_close(void) /* ---------------------------------------------------------------------- */ { safe_close(dump_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -rewind_dump(void) +dump_rewind(void) /* ---------------------------------------------------------------------- */ { if (dump_file && dump_file_on) @@ -329,13 +399,23 @@ rewind_dump(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -isopen_dump(void) +dump_isopen(void) /* ---------------------------------------------------------------------- */ { if (dump_file) return true; // open return false; } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +dump_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (dump_file != NULL && dump_file_on) + { + fprintf(dump_file, "%s", str); + } +} @@ -379,47 +459,7 @@ istream_getc(void *cookie) return EOF; } -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -error_msg(const char *err_str, bool stop) -/* ---------------------------------------------------------------------- */ -{ - io_error_count++; - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "\nERROR: %s\n", err_str); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "ERROR: %s\n", err_str); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "ERROR: %s\n", err_str); - fflush(log_file); - } - if (stop) - { - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "Stopping.\n"); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "Stopping.\n"); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "Stopping.\n"); - fflush(log_file); - } - } -} /* ---------------------------------------------------------------------- */ void PHRQ_io:: warning_msg(const char *err_str) @@ -537,13 +577,16 @@ output_msg(int type, const char *format, va_list args) } break; - case OUTPUT_DUMP: - if (dump_file != NULL && dump_file_on) - { - vfprintf(dump_file, format, args); - if (flush) - fflush(dump_file); - } + //case OUTPUT_DUMP: + // if (dump_file != NULL && dump_file_on) + // { + // vfprintf(dump_file, format, args); + // if (flush) + // fflush(dump_file); + // } + // break; + default: + assert(false); break; } } @@ -623,12 +666,14 @@ output_string(const int type, std::string str) } break; - case OUTPUT_DUMP: - if (dump_file != NULL && dump_file_on) - { - fprintf(dump_file, "%s", str.c_str()); - } - break; + //case OUTPUT_DUMP: + // if (dump_file != NULL && dump_file_on) + // { + // fprintf(dump_file, "%s", str.c_str()); + // } + // break; + default: + assert(false); } return; } @@ -686,18 +731,18 @@ output_open(int type, const char *file_name) return 0; } break; - case OUTPUT_DUMP: - if (dump_file != NULL) - { - safe_close(dump_file); - dump_file = NULL; - } - if ((dump_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; + //case OUTPUT_DUMP: + // if (dump_file != NULL) + // { + // safe_close(dump_file); + // dump_file = NULL; + // } + // if ((dump_file = fopen(file_name, "w")) == NULL) + // { + // //return ERROR; + // return 0; + // } + // break; case OUTPUT_ERROR: if (error_file != NULL) { @@ -729,6 +774,8 @@ output_open(int type, const char *file_name) return 0; } break; + default: + assert(false); } return 1; } @@ -758,9 +805,9 @@ output_isopen(const int type) case OUTPUT_LOG: return (log_file != NULL); break; - case OUTPUT_DUMP: - return (dump_file != NULL); - break; + //case OUTPUT_DUMP: + // return (dump_file != NULL); + // break; default: assert(false); return (output_file != NULL); @@ -809,9 +856,12 @@ output_fflush(const int type) fflush(log_file); break; - case OUTPUT_DUMP: - if (dump_file) - fflush(dump_file); + //case OUTPUT_DUMP: + // if (dump_file) + // fflush(dump_file); + // break; + default: + assert(false); break; } } @@ -855,9 +905,12 @@ output_rewind(const int type) rewind(log_file); break; - case OUTPUT_DUMP: - if (dump_file) - rewind(dump_file); + //case OUTPUT_DUMP: + // if (dump_file) + // rewind(dump_file); + // break; + default: + assert(false); break; } } @@ -894,9 +947,9 @@ output_close(const int type) safe_close(log_file); break; - case OUTPUT_DUMP: - safe_close(dump_file); - break; + //case OUTPUT_DUMP: + // safe_close(dump_file); + // break; default: assert(false); diff --git a/PHRQ_io.h b/PHRQ_io.h index 7bb382f2..6f175088 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -18,20 +18,20 @@ typedef enum OUTPUT_LOG, OUTPUT_CHECKLINE, OUTPUT_GUI_ERROR, - OUTPUT_DUMP, + //OUTPUT_DUMP, //OUTPUT_SEND_MESSAGE, OUTPUT_ECHO, OUTPUT_PUNCH_END_ROW } output_type; -typedef enum -{ - ACTION_OPEN, - ACTION_OUTPUT, - ACTION_CLOSE, - ACTION_REWIND, - ACTION_FLUSH -} action_type; +//typedef enum +//{ +// ACTION_OPEN, +// ACTION_OUTPUT, +// ACTION_CLOSE, +// ACTION_REWIND, +// ACTION_FLUSH +//} action_type; // constructors PHRQ_io(void); @@ -45,38 +45,46 @@ typedef enum static int istream_getc(void *cookie); // output_file - bool open_output(const char *file_name); - void fflush_output(void); - void close_output(void); - void rewind_output(void); - bool isopen_output(void); + bool output_open_temp(const char *file_name); + void output_fflush_temp(void); + void output_close_temp(void); + void output_rewind_temp(void); + bool output_isopen_temp(void); + void output_msg_temp(const char * str); + // log_file - bool open_log(const char *file_name); - void fflush_log(void); - void close_log(void); - void rewind_log(void); - bool isopen_log(void); + bool log_open(const char *file_name); + void log_fflush(void); + void log_close(void); + void log_rewind(void); + bool log_isopen(void); + void log_msg(const char * str); + // punch_file - bool open_punch(const char *file_name); - void fflush_punch(void); - void close_punch(void); - void rewind_punch(void); - bool isopen_punch(void); + bool punch_open(const char *file_name); + void punch_fflush(void); + void punch_close(void); + void punch_rewind(void); + bool punch_isopen(void); + void punch_msg(const char * str); + // error_file - bool open_error(const char *file_name); - void fflush_error(void); - void close_error(void); - void rewind_error(void); - bool isopen_error(void); + bool error_open(const char *file_name); + void error_fflush(void); + void error_close(void); + void error_rewind(void); + bool error_isopen(void); + void error_msg(const char * str, bool stop=false); + // dump_file - bool open_dump(const char *file_name); - void fflush_dump(void); - void close_dump(void); - void rewind_dump(void); - bool isopen_dump(void); + bool dump_open(const char *file_name); + void dump_fflush(void); + void dump_close(void); + void dump_rewind(void); + bool dump_isopen(void); + void dump_msg(const char * str); int output_open(int type, const char *file_name); - void error_msg(const char *err_str, bool stop); void warning_msg(const char *err_str); void output_string(const int type, std::string str); void output_fflush(int type); From c0cc6d8bbf7abf04372f802d951b79a40983daa8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 18:56:48 +0000 Subject: [PATCH 0284/1077] Removed OUTPUT_DUMP. Ran test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5700 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 4 ++-- Phreeqc.h | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index 6f175088..30667dd1 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -125,8 +125,8 @@ protected: FILE *output_file; /* OUTPUT_MESSAGE */ FILE *log_file; /* OUTPUT_LOG */ FILE *punch_file; /* OUTPUT_PUNCH */ - FILE *error_file; /* OUTPUT_ERROR */ - FILE *dump_file; /* OUTPUT_DUMP */ + FILE *error_file; + FILE *dump_file; int io_error_count; bool output_file_on; diff --git a/Phreeqc.h b/Phreeqc.h index 09508feb..188107d3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -280,6 +280,14 @@ CLASS_STATIC int istream_getc(void *cookie); int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); +/* PHRQ_io_output.cpp */ +// dump_file +bool dump_open(const char *file_name); +void dump_fflush(void); +void dump_close(void); +void dump_rewind(void); +bool dump_isopen(void); +void dump_msg(const char * str); // dw.c ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); @@ -701,7 +709,7 @@ int switch_bases(void); int write_phase_sys_total(int n); // print.c ------------------------------- -char *sformatf(const char *format, ...); +std::string sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); int print_all(void); From 3630733e093511994f37cd5dbd3b6c4f532c0fab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 19:32:47 +0000 Subject: [PATCH 0285/1077] Will not compile non-class versions! Removed OUTPUT_ERROR. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5701 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 141 ++++++++++++++++++++++++++++------------------------ PHRQ_io.h | 2 +- Phreeqc.h | 9 ++++ 3 files changed, 85 insertions(+), 67 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index ec10925f..f2b6cb5b 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -15,7 +15,7 @@ PHRQ_io(void) output_file = NULL; /* OUTPUT_MESSAGE */ log_file = NULL; /* OUTPUT_LOG */ punch_file = NULL; /* OUTPUT_PUNCH */ - error_file = NULL; /* OUTPUT_ERROR */ + error_file = NULL; dump_file = NULL; io_error_count = 0; @@ -270,11 +270,20 @@ error_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(error_file); - if ((error_file = fopen(file_name, "w")) == NULL) + + if (file_name != NULL) { - return true; // error + if ((error_file = fopen(file_name, "w")) == NULL) + { + error_file = stderr; + return false; + } } - return false; + else + { + error_file = stderr; + } + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -491,27 +500,27 @@ output_msg(int type, const char *format, va_list args) switch (type) { - case OUTPUT_ERROR: - io_error_count++; - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "\nERROR: "); - vfprintf(error_file, format, args); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "\nERROR: "); - vfprintf(output_file, format, args); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "\nERROR: "); - vfprintf(log_file, format, args); - fflush(log_file); - } - break; + //case OUTPUT_ERROR: + // io_error_count++; + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "\nERROR: "); + // vfprintf(error_file, format, args); + // fflush(error_file); + // } + // if (output_file != NULL && output_file_on) + // { + // fprintf(output_file, "\nERROR: "); + // vfprintf(output_file, format, args); + // fflush(output_file); + // } + // if (log_file != NULL && log_file_on) + // { + // fprintf(log_file, "\nERROR: "); + // vfprintf(log_file, format, args); + // fflush(log_file); + // } + // break; case OUTPUT_WARNING: if (error_file != NULL && error_file_on) { @@ -615,14 +624,14 @@ output_string(const int type, std::string str) switch (type) { - case OUTPUT_ERROR: - //this->io_error_count++; - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "%s", str.c_str()); - } - fflush(error_file); - break; + //case OUTPUT_ERROR: + // //this->io_error_count++; + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "%s", str.c_str()); + // } + // fflush(error_file); + // break; case OUTPUT_WARNING: if (log_file != NULL && log_file_on) @@ -743,26 +752,26 @@ output_open(int type, const char *file_name) // return 0; // } // break; - case OUTPUT_ERROR: - if (error_file != NULL) - { - safe_close(error_file); - error_file = NULL; - } + //case OUTPUT_ERROR: + // if (error_file != NULL) + // { + // safe_close(error_file); + // error_file = NULL; + // } - if (file_name != NULL) - { - if ((error_file = fopen(file_name, "w")) == NULL) - { - error_file = stderr; - return 0; - } - } - else - { - error_file = stderr; - } - break; + // if (file_name != NULL) + // { + // if ((error_file = fopen(file_name, "w")) == NULL) + // { + // error_file = stderr; + // return 0; + // } + // } + // else + // { + // error_file = stderr; + // } + // break; case OUTPUT_LOG: if (log_file != NULL) { @@ -787,9 +796,9 @@ output_isopen(const int type) { switch (type) { - case OUTPUT_ERROR: - return (error_file != NULL); - break; + //case OUTPUT_ERROR: + // return (error_file != NULL); + // break; case OUTPUT_WARNING: return (error_file != NULL || output_file != NULL); break; @@ -823,10 +832,10 @@ output_fflush(const int type) { switch (type) { - case OUTPUT_ERROR: - if (error_file) - fflush(error_file); - break; + //case OUTPUT_ERROR: + // if (error_file) + // fflush(error_file); + // break; case OUTPUT_WARNING: if (error_file) @@ -872,10 +881,10 @@ output_rewind(const int type) { switch (type) { - case OUTPUT_ERROR: - if (error_file) - rewind(error_file); - break; + //case OUTPUT_ERROR: + // if (error_file) + // rewind(error_file); + // break; case OUTPUT_WARNING: if (error_file) @@ -921,9 +930,9 @@ output_close(const int type) { switch (type) { - case OUTPUT_ERROR: - safe_close(error_file); - break; + //case OUTPUT_ERROR: + // safe_close(error_file); + // break; case OUTPUT_WARNING: safe_close(error_file); diff --git a/PHRQ_io.h b/PHRQ_io.h index 30667dd1..26aade64 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -10,7 +10,7 @@ class PHRQ_io public: typedef enum { - OUTPUT_ERROR, + //OUTPUT_ERROR, OUTPUT_WARNING, OUTPUT_MESSAGE, OUTPUT_PUNCH, diff --git a/Phreeqc.h b/Phreeqc.h index 188107d3..2331be91 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -288,6 +288,15 @@ void dump_close(void); void dump_rewind(void); bool dump_isopen(void); void dump_msg(const char * str); + +// error_file +bool error_open(const char *file_name); +void error_fflush(void); +void error_close(void); +void error_rewind(void); +bool error_isopen(void); +void error_msg(const char * str, bool stop=false); + // dw.c ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); From fbaa4906ffccc95937e150a1cc91c26971715be0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 20:20:29 +0000 Subject: [PATCH 0286/1077] Done with OUTPUT_WARNING git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5702 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 108 ++++++++++++++++++++++++++-------------------------- PHRQ_io.h | 2 +- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index f2b6cb5b..261b6354 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -521,26 +521,26 @@ output_msg(int type, const char *format, va_list args) // fflush(log_file); // } // break; - case OUTPUT_WARNING: - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "\nWARNING: "); - vfprintf(error_file, format, args); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "\nWARNING: "); - vfprintf(output_file, format, args); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "\nWARNING: "); - vfprintf(log_file, format, args); - fflush(log_file); - } - break; + //case OUTPUT_WARNING: + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "\nWARNING: "); + // vfprintf(error_file, format, args); + // fflush(error_file); + // } + // if (output_file != NULL && output_file_on) + // { + // fprintf(output_file, "\nWARNING: "); + // vfprintf(output_file, format, args); + // fflush(output_file); + // } + // if (log_file != NULL && log_file_on) + // { + // fprintf(log_file, "\nWARNING: "); + // vfprintf(log_file, format, args); + // fflush(log_file); + // } + // break; case OUTPUT_CHECKLINE: { if (output_file != NULL && output_file_on) @@ -633,21 +633,21 @@ output_string(const int type, std::string str) // fflush(error_file); // break; - case OUTPUT_WARNING: - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "%s", str.c_str()); - } - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "%s", str.c_str()); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "%s", str.c_str()); - } - break; + //case OUTPUT_WARNING: + // if (log_file != NULL && log_file_on) + // { + // fprintf(log_file, "%s", str.c_str()); + // } + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "%s", str.c_str()); + // fflush(error_file); + // } + // if (output_file != NULL && output_file_on) + // { + // fprintf(output_file, "%s", str.c_str()); + // } + // break; case OUTPUT_CHECKLINE: case OUTPUT_MESSAGE: if (output_file != NULL && output_file_on) @@ -799,9 +799,9 @@ output_isopen(const int type) //case OUTPUT_ERROR: // return (error_file != NULL); // break; - case OUTPUT_WARNING: - return (error_file != NULL || output_file != NULL); - break; + //case OUTPUT_WARNING: + // return (error_file != NULL || output_file != NULL); + // break; case OUTPUT_MESSAGE: return (output_file != NULL); break; @@ -837,12 +837,12 @@ output_fflush(const int type) // fflush(error_file); // break; - case OUTPUT_WARNING: - if (error_file) - fflush(error_file); - if (output_file) - fflush(output_file); - break; + //case OUTPUT_WARNING: + // if (error_file) + // fflush(error_file); + // if (output_file) + // fflush(output_file); + // break; case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: @@ -886,12 +886,12 @@ output_rewind(const int type) // rewind(error_file); // break; - case OUTPUT_WARNING: - if (error_file) - rewind(error_file); - if (output_file) - rewind(output_file); - break; + //case OUTPUT_WARNING: + // if (error_file) + // rewind(error_file); + // if (output_file) + // rewind(output_file); + // break; case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: @@ -934,10 +934,10 @@ output_close(const int type) // safe_close(error_file); // break; - case OUTPUT_WARNING: - safe_close(error_file); - safe_close(output_file); - break; + //case OUTPUT_WARNING: + // safe_close(error_file); + // safe_close(output_file); + // break; case OUTPUT_MESSAGE: case OUTPUT_CHECKLINE: diff --git a/PHRQ_io.h b/PHRQ_io.h index 26aade64..e8f5c83e 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -11,7 +11,7 @@ public: typedef enum { //OUTPUT_ERROR, - OUTPUT_WARNING, + //OUTPUT_WARNING, OUTPUT_MESSAGE, OUTPUT_PUNCH, OUTPUT_SCREEN, From efe04692ff6711c9fc9f71835decf6278a0b8269 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 21:48:09 +0000 Subject: [PATCH 0287/1077] OUTPUT_SCREEN and OUTPUT_LOG are done. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5703 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 2 - PHRQ_io.cpp | 154 ++++++++++++++++++++++++------------------------- PHRQ_io.h | 6 +- Phreeqc.h | 10 ++++ class_main.cpp | 26 ++++----- 5 files changed, 103 insertions(+), 95 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index cb0b5ba5..4a973661 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -45,8 +45,6 @@ warning_msg(const std::string & stdstr) { if (this->io) { - //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_WARNING, stdstr.c_str(), false, "", NULL); - //this->io->output_string(PHRQ_io::OUTPUT_WARNING, stdstr); this->io->warning_msg(stdstr.c_str()); } else diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 261b6354..85554ce1 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -13,7 +13,7 @@ PHRQ_io(void) input_file = NULL; database_file = NULL; output_file = NULL; /* OUTPUT_MESSAGE */ - log_file = NULL; /* OUTPUT_LOG */ + log_file = NULL; punch_file = NULL; /* OUTPUT_PUNCH */ error_file = NULL; dump_file = NULL; @@ -85,9 +85,9 @@ output_open_temp(const char *file_name) safe_close(output_file); if ((output_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -147,9 +147,9 @@ log_open(const char *file_name) safe_close(log_file); if ((log_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -209,9 +209,9 @@ punch_open(const char *file_name) safe_close(punch_file); if ((punch_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -375,9 +375,9 @@ dump_open(const char *file_name) safe_close(dump_file); if ((dump_file = fopen(file_name, "w")) == NULL) { - return true; // error + return false; // error } - return false; + return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -569,22 +569,22 @@ output_msg(int type, const char *format, va_list args) } } break; - case OUTPUT_LOG: - if (log_file != NULL && log_file_on) - { - vfprintf(log_file, format, args); - if (flush) - fflush(log_file); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL && error_file_on) - { - vfprintf(error_file, format, args); - if (flush) - fflush(error_file); - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL && log_file_on) + // { + // vfprintf(log_file, format, args); + // if (flush) + // fflush(log_file); + // } + // break; + //case OUTPUT_SCREEN: + // if (error_file != NULL && error_file_on) + // { + // vfprintf(error_file, format, args); + // if (flush) + // fflush(error_file); + // } + // break; //case OUTPUT_DUMP: // if (dump_file != NULL && dump_file_on) @@ -661,19 +661,19 @@ output_string(const int type, std::string str) fprintf(punch_file, "%s", str.c_str()); } break; - case OUTPUT_LOG: - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "%s", str.c_str()); - } - break; - case OUTPUT_SCREEN: - if (error_file != NULL && error_file_on) - { - fprintf(error_file, "%s", str.c_str()); - fflush(error_file); - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL && log_file_on) + // { + // fprintf(log_file, "%s", str.c_str()); + // } + // break; + //case OUTPUT_SCREEN: + // if (error_file != NULL && error_file_on) + // { + // fprintf(error_file, "%s", str.c_str()); + // fflush(error_file); + // } + // break; //case OUTPUT_DUMP: // if (dump_file != NULL && dump_file_on) @@ -772,17 +772,17 @@ output_open(int type, const char *file_name) // error_file = stderr; // } // break; - case OUTPUT_LOG: - if (log_file != NULL) - { - safe_close(log_file); - log_file = NULL; - } - if ((log_file = fopen(file_name, "w")) == NULL) - { - return 0; - } - break; + //case OUTPUT_LOG: + // if (log_file != NULL) + // { + // safe_close(log_file); + // log_file = NULL; + // } + // if ((log_file = fopen(file_name, "w")) == NULL) + // { + // return 0; + // } + // break; default: assert(false); } @@ -808,12 +808,12 @@ output_isopen(const int type) case OUTPUT_PUNCH: return (punch_file != NULL); break; - case OUTPUT_SCREEN: - return (error_file != NULL); - break; - case OUTPUT_LOG: - return (log_file != NULL); - break; + //case OUTPUT_SCREEN: + // return (error_file != NULL); + // break; + //case OUTPUT_LOG: + // return (log_file != NULL); + // break; //case OUTPUT_DUMP: // return (dump_file != NULL); // break; @@ -855,15 +855,15 @@ output_fflush(const int type) fflush(punch_file); break; - case OUTPUT_SCREEN: - if (error_file) - fflush(error_file); - break; + //case OUTPUT_SCREEN: + // if (error_file) + // fflush(error_file); + // break; - case OUTPUT_LOG: - if (log_file) - fflush(log_file); - break; + //case OUTPUT_LOG: + // if (log_file) + // fflush(log_file); + // break; //case OUTPUT_DUMP: // if (dump_file) @@ -904,15 +904,15 @@ output_rewind(const int type) rewind(punch_file); break; - case OUTPUT_SCREEN: - if (error_file) - rewind(error_file); - break; + //case OUTPUT_SCREEN: + // if (error_file) + // rewind(error_file); + // break; - case OUTPUT_LOG: - if (log_file) - rewind(log_file); - break; + //case OUTPUT_LOG: + // if (log_file) + // rewind(log_file); + // break; //case OUTPUT_DUMP: // if (dump_file) @@ -948,13 +948,13 @@ output_close(const int type) safe_close(punch_file); break; - case OUTPUT_SCREEN: - safe_close(error_file); - break; + //case OUTPUT_SCREEN: + // safe_close(error_file); + // break; - case OUTPUT_LOG: - safe_close(log_file); - break; + //case OUTPUT_LOG: + // safe_close(log_file); + // break; //case OUTPUT_DUMP: // safe_close(dump_file); diff --git a/PHRQ_io.h b/PHRQ_io.h index e8f5c83e..7591adda 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -14,8 +14,8 @@ typedef enum //OUTPUT_WARNING, OUTPUT_MESSAGE, OUTPUT_PUNCH, - OUTPUT_SCREEN, - OUTPUT_LOG, + //OUTPUT_SCREEN, + //OUTPUT_LOG, OUTPUT_CHECKLINE, OUTPUT_GUI_ERROR, //OUTPUT_DUMP, @@ -123,7 +123,7 @@ protected: FILE *input_file; FILE *database_file; FILE *output_file; /* OUTPUT_MESSAGE */ - FILE *log_file; /* OUTPUT_LOG */ + FILE *log_file; FILE *punch_file; /* OUTPUT_PUNCH */ FILE *error_file; FILE *dump_file; diff --git a/Phreeqc.h b/Phreeqc.h index 2331be91..12deb808 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -281,6 +281,8 @@ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); /* PHRQ_io_output.cpp */ +void screen_msg(const char *err_str); + // dump_file bool dump_open(const char *file_name); void dump_fflush(void); @@ -289,6 +291,14 @@ void dump_rewind(void); bool dump_isopen(void); void dump_msg(const char * str); +// log_file +bool log_open(const char *file_name); +void log_fflush(void); +void log_close(void); +void log_rewind(void); +bool log_isopen(void); +void log_msg(const char * str); + // error_file bool error_open(const char *file_name); void error_fflush(void); diff --git a/class_main.cpp b/class_main.cpp index 5d69d605..e64a072b 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -186,38 +186,38 @@ write_banner(void) { char buffer[80]; int len, indent; - output_msg(OUTPUT_SCREEN, + screen_msg( " ÛßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßÛ\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); /* version */ len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); + screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' ').c_str()); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º A hydrogeochemical transport model º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º by º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º D.L. Parkhurst and C.A.J. Appelo º\n"); - output_msg(OUTPUT_SCREEN, + screen_msg( " º º\n"); /* date */ len = sprintf(buffer, "%s", "@VER_DATE@"); indent = (44 - len) / 2; - output_msg(OUTPUT_SCREEN, "%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' '); + screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, + 44 - indent - len, ' ').c_str()); - output_msg(OUTPUT_SCREEN, + screen_msg( " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); return 0; From 92d8a3b98aa6b4f17373df42dee3a6ddae1c34cb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Oct 2011 22:13:03 +0000 Subject: [PATCH 0288/1077] OUTPUT_CHECKLINE and OUTPUT_ECHO done. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5704 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 28 ++++++++++++++-------------- PHRQ_io.h | 4 ++-- Phreeqc.h | 1 + ReadClass.cxx | 44 ++++++++++++++++++++++---------------------- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 85554ce1..01feafd7 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -541,16 +541,16 @@ output_msg(int type, const char *format, va_list args) // fflush(log_file); // } // break; - case OUTPUT_CHECKLINE: - { - if (output_file != NULL && output_file_on) - { - vfprintf(output_file, format, args); - if (flush) - fflush(output_file); - } - } - break; + //case OUTPUT_CHECKLINE: + // { + // if (output_file != NULL && output_file_on) + // { + // vfprintf(output_file, format, args); + // if (flush) + // fflush(output_file); + // } + // } + // break; case OUTPUT_MESSAGE: if (output_file != NULL && output_file_on) { @@ -648,7 +648,7 @@ output_string(const int type, std::string str) // fprintf(output_file, "%s", str.c_str()); // } // break; - case OUTPUT_CHECKLINE: + //case OUTPUT_CHECKLINE: case OUTPUT_MESSAGE: if (output_file != NULL && output_file_on) { @@ -845,7 +845,7 @@ output_fflush(const int type) // break; case OUTPUT_MESSAGE: - case OUTPUT_CHECKLINE: + //case OUTPUT_CHECKLINE: if (output_file) fflush(output_file); break; @@ -894,7 +894,7 @@ output_rewind(const int type) // break; case OUTPUT_MESSAGE: - case OUTPUT_CHECKLINE: + //case OUTPUT_CHECKLINE: if (output_file) rewind(output_file); break; @@ -940,7 +940,7 @@ output_close(const int type) // break; case OUTPUT_MESSAGE: - case OUTPUT_CHECKLINE: + //case OUTPUT_CHECKLINE: safe_close(output_file); break; diff --git a/PHRQ_io.h b/PHRQ_io.h index 7591adda..19755ab1 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -16,11 +16,11 @@ typedef enum OUTPUT_PUNCH, //OUTPUT_SCREEN, //OUTPUT_LOG, - OUTPUT_CHECKLINE, + //OUTPUT_CHECKLINE, OUTPUT_GUI_ERROR, //OUTPUT_DUMP, //OUTPUT_SEND_MESSAGE, - OUTPUT_ECHO, + //OUTPUT_ECHO, OUTPUT_PUNCH_END_ROW } output_type; diff --git a/Phreeqc.h b/Phreeqc.h index 12deb808..f4947cb3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -282,6 +282,7 @@ int process_file_names(int argc, char *argv[], void **db_cookie, /* PHRQ_io_output.cpp */ void screen_msg(const char *err_str); +void echo_msg(const char *err_str); // dump_file bool dump_open(const char *file_name); diff --git a/ReadClass.cxx b/ReadClass.cxx index 7d93647f..7e9cb4ad 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -138,7 +138,7 @@ read_solution_raw(void) } // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -233,7 +233,7 @@ read_exchange_raw(void) free_check_null(exchange_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -328,7 +328,7 @@ read_surface_raw(void) free_check_null(surface_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -426,7 +426,7 @@ read_equilibrium_phases_raw(void) free_check_null(pp_assemblage_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -521,7 +521,7 @@ read_kinetics_raw(void) free_check_null(kinetics_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -620,7 +620,7 @@ read_solid_solutions_raw(void) free_check_null(s_s_assemblage_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -715,7 +715,7 @@ read_gas_phase_raw(void) free_check_null(gas_phase_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -811,7 +811,7 @@ read_reaction_raw(void) free_check_null(irrev_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -907,7 +907,7 @@ read_mix_raw(void) free_check_null(mix_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -1006,7 +1006,7 @@ read_temperature_raw(void) free_check_null(temperature_ptr); // Need to output the next keyword - if (return_value == KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1058,7 +1058,7 @@ read_dump(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1110,7 +1110,7 @@ read_delete(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1162,7 +1162,7 @@ read_run_cells(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1260,7 +1260,7 @@ read_solution_modify(void) solution[n] = soln_ptr; // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } @@ -1354,7 +1354,7 @@ read_equilibrium_phases_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1464,7 +1464,7 @@ read_exchange_modify(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1554,7 +1554,7 @@ read_surface_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1644,7 +1644,7 @@ read_solid_solutions_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1732,7 +1732,7 @@ read_gas_phase_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1822,7 +1822,7 @@ read_kinetics_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1910,7 +1910,7 @@ read_reaction_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -2775,7 +2775,7 @@ read_user_graph_handler(void) bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line); return (return_value); } #endif \ No newline at end of file From d57af0535330ce7344ed2fa54d8543b9ce5884d6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 13:41:03 +0000 Subject: [PATCH 0289/1077] OUTPUT_MESSAGE removed, need to check a bit. sformatf now returns char *. Should be more efficient. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5706 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 2 +- PHRQ_io.h | 14 ++++++------ Phreeqc.cpp | 59 ++++++++++++++++++++++++++++---------------------- Phreeqc.h | 10 ++++++++- ReadClass.cxx | 44 ++++++++++++++++++------------------- class_main.cpp | 4 ++-- 6 files changed, 74 insertions(+), 59 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 4a973661..92254a05 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -61,7 +61,7 @@ output_msg(const std::string & stdstr) if (this->io) { //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); - this->io->output_string(PHRQ_io::OUTPUT_MESSAGE, stdstr); + this->io->output_temp_msg(stdstr.c_str()); } else { diff --git a/PHRQ_io.h b/PHRQ_io.h index 19755ab1..541f47db 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -12,7 +12,7 @@ typedef enum { //OUTPUT_ERROR, //OUTPUT_WARNING, - OUTPUT_MESSAGE, + //OUTPUT_MESSAGE, OUTPUT_PUNCH, //OUTPUT_SCREEN, //OUTPUT_LOG, @@ -45,12 +45,12 @@ typedef enum static int istream_getc(void *cookie); // output_file - bool output_open_temp(const char *file_name); - void output_fflush_temp(void); - void output_close_temp(void); - void output_rewind_temp(void); - bool output_isopen_temp(void); - void output_msg_temp(const char * str); + bool output_temp_open(const char *file_name); + void output_temp_fflush(void); + void output_temp_close(void); + void output_temp_rewind(void); + bool output_temp_isopen(void); + void output_temp_msg(const char * str); // log_file bool log_open(const char *file_name); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 71011b08..6c1b49a4 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -374,6 +374,12 @@ Phreeqc::Phreeqc(void) // phqalloc.c + // print.c + sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); + if (sformatf_buffer == NULL) + malloc_error(); + sformatf_buffer_size = 256; + // transport.c J_ij = NULL; J_ij_il = NULL; @@ -409,6 +415,7 @@ Phreeqc::~Phreeqc(void) delete[] command; free_check_null(default_data_base); + free_check_null(sformatf_buffer); PHRQ_free_all(); delete phrq_io; @@ -546,39 +553,39 @@ void Phreeqc::init(void) #else inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); #endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; negative_concentrations = FALSE; LOG_10 = log(10.0); - max_solution = MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; + max_solution = MAX_SOLUTION; + max_pp_assemblage = MAX_PP_ASSEMBLAGE; + max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; - max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_s_s_assemblage = MAX_PP_ASSEMBLAGE; - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; max_strings = MAX_STRINGS; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; count_solution = 0; count_pp_assemblage = 0; @@ -983,7 +990,7 @@ void Phreeqc::init(void) charge_group = NULL; print_density = 0; - // + // // Non-class statics // /* basic.c */ diff --git a/Phreeqc.h b/Phreeqc.h index f4947cb3..18f4b001 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -308,6 +308,14 @@ void error_rewind(void); bool error_isopen(void); void error_msg(const char * str, bool stop=false); +// output_temp_file +bool output_temp_open(const char *file_name); +void output_temp_fflush(void); +void output_temp_close(void); +void output_temp_rewind(void); +bool output_temp_isopen(void); +void output_temp_msg(const char * str); + // dw.c ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); @@ -729,7 +737,7 @@ int switch_bases(void); int write_phase_sys_total(int n); // print.c ------------------------------- -std::string sformatf(const char *format, ...); +char *sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); int print_all(void); diff --git a/ReadClass.cxx b/ReadClass.cxx index 7e9cb4ad..d45113ca 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -138,7 +138,7 @@ read_solution_raw(void) } // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -233,7 +233,7 @@ read_exchange_raw(void) free_check_null(exchange_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -328,7 +328,7 @@ read_surface_raw(void) free_check_null(surface_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -426,7 +426,7 @@ read_equilibrium_phases_raw(void) free_check_null(pp_assemblage_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -521,7 +521,7 @@ read_kinetics_raw(void) free_check_null(kinetics_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -620,7 +620,7 @@ read_solid_solutions_raw(void) free_check_null(s_s_assemblage_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -715,7 +715,7 @@ read_gas_phase_raw(void) free_check_null(gas_phase_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -811,7 +811,7 @@ read_reaction_raw(void) free_check_null(irrev_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -907,7 +907,7 @@ read_mix_raw(void) free_check_null(mix_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -1006,7 +1006,7 @@ read_temperature_raw(void) free_check_null(temperature_ptr); // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1058,7 +1058,7 @@ read_dump(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1110,7 +1110,7 @@ read_delete(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1162,7 +1162,7 @@ read_run_cells(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1260,7 +1260,7 @@ read_solution_modify(void) solution[n] = soln_ptr; // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } @@ -1354,7 +1354,7 @@ read_equilibrium_phases_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1464,7 +1464,7 @@ read_exchange_modify(void) // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1554,7 +1554,7 @@ read_surface_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1644,7 +1644,7 @@ read_solid_solutions_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1732,7 +1732,7 @@ read_gas_phase_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1822,7 +1822,7 @@ read_kinetics_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -1910,7 +1910,7 @@ read_reaction_modify(void) free_check_null(entity_ptr); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -2775,7 +2775,7 @@ read_user_graph_handler(void) bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); return (return_value); } #endif \ No newline at end of file diff --git a/class_main.cpp b/class_main.cpp index e64a072b..1cc34b4d 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -195,7 +195,7 @@ write_banner(void) len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); indent = (44 - len) / 2; screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' ').c_str()); + 44 - indent - len, ' ')); screen_msg( " º º\n"); @@ -215,7 +215,7 @@ write_banner(void) len = sprintf(buffer, "%s", "@VER_DATE@"); indent = (44 - len) / 2; screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, - 44 - indent - len, ' ').c_str()); + 44 - indent - len, ' ')); screen_msg( " ÛÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÛ\n\n"); From ccc051140d6c5f99e2c02cdcf3e5ce8a46ac57e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 13:47:31 +0000 Subject: [PATCH 0290/1077] Accidently had wrong PHRQ_io.cpp on checkin. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5707 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 100 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 01feafd7..2421b724 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -12,7 +12,7 @@ PHRQ_io(void) { input_file = NULL; database_file = NULL; - output_file = NULL; /* OUTPUT_MESSAGE */ + output_file = NULL; log_file = NULL; punch_file = NULL; /* OUTPUT_PUNCH */ error_file = NULL; @@ -79,7 +79,7 @@ PHRQ_io::Set_dump_file(FILE * out) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -output_open_temp(const char *file_name) +output_temp_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(output_file); @@ -91,7 +91,7 @@ output_open_temp(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_fflush_temp(void) +output_temp_fflush(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -101,14 +101,14 @@ output_fflush_temp(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_close_temp(void) +output_temp_close(void) /* ---------------------------------------------------------------------- */ { safe_close(output_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_rewind_temp(void) +output_temp_rewind(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -118,7 +118,7 @@ output_rewind_temp(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -output_isopen_temp(void) +output_temp_isopen(void) /* ---------------------------------------------------------------------- */ { if (output_file) @@ -127,7 +127,7 @@ output_isopen_temp(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_msg_temp(const char * str) +output_temp_msg(const char * str) /* ---------------------------------------------------------------------- */ { if (output_file != NULL && output_file_on) @@ -551,14 +551,14 @@ output_msg(int type, const char *format, va_list args) // } // } // break; - case OUTPUT_MESSAGE: - if (output_file != NULL && output_file_on) - { - vfprintf(output_file, format, args); - if (flush) - fflush(output_file); - } - break; + //case OUTPUT_MESSAGE: + // if (output_file != NULL && output_file_on) + // { + // vfprintf(output_file, format, args); + // if (flush) + // fflush(output_file); + // } + // break; case OUTPUT_PUNCH: if (punch_file != NULL && punch_file_on) { @@ -649,12 +649,12 @@ output_string(const int type, std::string str) // } // break; //case OUTPUT_CHECKLINE: - case OUTPUT_MESSAGE: - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "%s", str.c_str()); - } - break; + //case OUTPUT_MESSAGE: + // if (output_file != NULL && output_file_on) + // { + // fprintf(output_file, "%s", str.c_str()); + // } + // break; case OUTPUT_PUNCH: if (punch_file != NULL && punch_file_on) { @@ -728,18 +728,18 @@ output_open(int type, const char *file_name) return 0; } break; - case OUTPUT_MESSAGE: - if (output_file != NULL) - { - safe_close(output_file); - output_file = NULL; - } - if ((output_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; + //case OUTPUT_MESSAGE: + // if (output_file != NULL) + // { + // safe_close(output_file); + // output_file = NULL; + // } + // if ((output_file = fopen(file_name, "w")) == NULL) + // { + // //return ERROR; + // return 0; + // } + // break; //case OUTPUT_DUMP: // if (dump_file != NULL) // { @@ -802,9 +802,9 @@ output_isopen(const int type) //case OUTPUT_WARNING: // return (error_file != NULL || output_file != NULL); // break; - case OUTPUT_MESSAGE: - return (output_file != NULL); - break; + //case OUTPUT_MESSAGE: + // return (output_file != NULL); + // break; case OUTPUT_PUNCH: return (punch_file != NULL); break; @@ -844,11 +844,11 @@ output_fflush(const int type) // fflush(output_file); // break; - case OUTPUT_MESSAGE: - //case OUTPUT_CHECKLINE: - if (output_file) - fflush(output_file); - break; + //case OUTPUT_MESSAGE: + ////case OUTPUT_CHECKLINE: + // if (output_file) + // fflush(output_file); + // break; case OUTPUT_PUNCH: if (punch_file) @@ -893,11 +893,11 @@ output_rewind(const int type) // rewind(output_file); // break; - case OUTPUT_MESSAGE: - //case OUTPUT_CHECKLINE: - if (output_file) - rewind(output_file); - break; + //case OUTPUT_MESSAGE: + ////case OUTPUT_CHECKLINE: + // if (output_file) + // rewind(output_file); + // break; case OUTPUT_PUNCH: if (punch_file) @@ -939,10 +939,10 @@ output_close(const int type) // safe_close(output_file); // break; - case OUTPUT_MESSAGE: - //case OUTPUT_CHECKLINE: - safe_close(output_file); - break; + //case OUTPUT_MESSAGE: + ////case OUTPUT_CHECKLINE: + // safe_close(output_file); + // break; case OUTPUT_PUNCH: safe_close(punch_file); From 6c2f0b5bf22091b837034be4343506938704ab42 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 18:14:27 +0000 Subject: [PATCH 0291/1077] Did OUTPUT_PUNCH. The switch between user_punch and inverse modeling punch may not work exactly right. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5708 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 86 ++++++++++++++++++++++++++--------------------------- PHRQ_io.h | 6 ++-- Phreeqc.cpp | 1 + Phreeqc.h | 9 ++++++ 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 2421b724..b8e99ed4 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -14,7 +14,7 @@ PHRQ_io(void) database_file = NULL; output_file = NULL; log_file = NULL; - punch_file = NULL; /* OUTPUT_PUNCH */ + punch_file = NULL; error_file = NULL; dump_file = NULL; io_error_count = 0; @@ -559,16 +559,16 @@ output_msg(int type, const char *format, va_list args) // fflush(output_file); // } // break; - case OUTPUT_PUNCH: - if (punch_file != NULL && punch_file_on) - { - { - vfprintf(punch_file, format, args); - if (flush) - fflush(punch_file); - } - } - break; + //case OUTPUT_PUNCH: + // if (punch_file != NULL && punch_file_on) + // { + // { + // vfprintf(punch_file, format, args); + // if (flush) + // fflush(punch_file); + // } + // } + // break; //case OUTPUT_LOG: // if (log_file != NULL && log_file_on) // { @@ -655,12 +655,12 @@ output_string(const int type, std::string str) // fprintf(output_file, "%s", str.c_str()); // } // break; - case OUTPUT_PUNCH: - if (punch_file != NULL && punch_file_on) - { - fprintf(punch_file, "%s", str.c_str()); - } - break; + //case OUTPUT_PUNCH: + // if (punch_file != NULL && punch_file_on) + // { + // fprintf(punch_file, "%s", str.c_str()); + // } + // break; //case OUTPUT_LOG: // if (log_file != NULL && log_file_on) // { @@ -716,18 +716,18 @@ output_open(int type, const char *file_name) switch (type) { - case OUTPUT_PUNCH: - if (punch_file != NULL) - { - fclose(punch_file); - punch_file = NULL; - } - if ((punch_file = fopen(file_name, "w")) == NULL) - { - //return ERROR; - return 0; - } - break; + //case OUTPUT_PUNCH: + // if (punch_file != NULL) + // { + // fclose(punch_file); + // punch_file = NULL; + // } + // if ((punch_file = fopen(file_name, "w")) == NULL) + // { + // //return ERROR; + // return 0; + // } + // break; //case OUTPUT_MESSAGE: // if (output_file != NULL) // { @@ -805,9 +805,9 @@ output_isopen(const int type) //case OUTPUT_MESSAGE: // return (output_file != NULL); // break; - case OUTPUT_PUNCH: - return (punch_file != NULL); - break; + //case OUTPUT_PUNCH: + // return (punch_file != NULL); + // break; //case OUTPUT_SCREEN: // return (error_file != NULL); // break; @@ -850,10 +850,10 @@ output_fflush(const int type) // fflush(output_file); // break; - case OUTPUT_PUNCH: - if (punch_file) - fflush(punch_file); - break; + //case OUTPUT_PUNCH: + // if (punch_file) + // fflush(punch_file); + // break; //case OUTPUT_SCREEN: // if (error_file) @@ -899,10 +899,10 @@ output_rewind(const int type) // rewind(output_file); // break; - case OUTPUT_PUNCH: - if (punch_file) - rewind(punch_file); - break; + //case OUTPUT_PUNCH: + // if (punch_file) + // rewind(punch_file); + // break; //case OUTPUT_SCREEN: // if (error_file) @@ -944,9 +944,9 @@ output_close(const int type) // safe_close(output_file); // break; - case OUTPUT_PUNCH: - safe_close(punch_file); - break; + //case OUTPUT_PUNCH: + // safe_close(punch_file); + // break; //case OUTPUT_SCREEN: // safe_close(error_file); diff --git a/PHRQ_io.h b/PHRQ_io.h index 541f47db..aa6ccc44 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -13,7 +13,7 @@ typedef enum //OUTPUT_ERROR, //OUTPUT_WARNING, //OUTPUT_MESSAGE, - OUTPUT_PUNCH, + //OUTPUT_PUNCH, //OUTPUT_SCREEN, //OUTPUT_LOG, //OUTPUT_CHECKLINE, @@ -122,9 +122,9 @@ typedef enum protected: FILE *input_file; FILE *database_file; - FILE *output_file; /* OUTPUT_MESSAGE */ + FILE *output_file; FILE *log_file; - FILE *punch_file; /* OUTPUT_PUNCH */ + FILE *punch_file; FILE *error_file; FILE *dump_file; int io_error_count; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6c1b49a4..44e90f3b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -10,6 +10,7 @@ #include "GasPhase.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "phqalloc.h" Phreeqc::Phreeqc(void) { diff --git a/Phreeqc.h b/Phreeqc.h index 18f4b001..8f268943 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -316,6 +316,15 @@ void output_temp_rewind(void); bool output_temp_isopen(void); void output_temp_msg(const char * str); +// punch_file +bool punch_open(const char *file_name); +void punch_fflush(void); +void punch_close(void); +void punch_rewind(void); +bool punch_isopen(void); +void punch_msg(const char * str); + +void fpunchf_heading(const char *name); // dw.c ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); From 53a00d4a983a6c249eaacb19bfdd85be59bb1e4d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 19:02:39 +0000 Subject: [PATCH 0292/1077] Finished fpunchf. Old output_msg is commented. Seems to work. Ran all test cases. Time to clean up and make class-only versions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5709 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 904 +++++++++++++++++++++++++++------------------------- PHRQ_io.h | 19 +- Phreeqc.h | 8 + 3 files changed, 489 insertions(+), 442 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index b8e99ed4..754bf449 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -490,203 +490,239 @@ warning_msg(const char *err_str) fflush(output_file); } } +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//output_msg(int type, const char *format, va_list args) +///* ---------------------------------------------------------------------- */ +//{ +// int flush = 1; +// +// switch (type) +// { +// +// //case OUTPUT_ERROR: +// // io_error_count++; +// // if (error_file != NULL && error_file_on) +// // { +// // fprintf(error_file, "\nERROR: "); +// // vfprintf(error_file, format, args); +// // fflush(error_file); +// // } +// // if (output_file != NULL && output_file_on) +// // { +// // fprintf(output_file, "\nERROR: "); +// // vfprintf(output_file, format, args); +// // fflush(output_file); +// // } +// // if (log_file != NULL && log_file_on) +// // { +// // fprintf(log_file, "\nERROR: "); +// // vfprintf(log_file, format, args); +// // fflush(log_file); +// // } +// // break; +// //case OUTPUT_WARNING: +// // if (error_file != NULL && error_file_on) +// // { +// // fprintf(error_file, "\nWARNING: "); +// // vfprintf(error_file, format, args); +// // fflush(error_file); +// // } +// // if (output_file != NULL && output_file_on) +// // { +// // fprintf(output_file, "\nWARNING: "); +// // vfprintf(output_file, format, args); +// // fflush(output_file); +// // } +// // if (log_file != NULL && log_file_on) +// // { +// // fprintf(log_file, "\nWARNING: "); +// // vfprintf(log_file, format, args); +// // fflush(log_file); +// // } +// // break; +// //case OUTPUT_CHECKLINE: +// // { +// // if (output_file != NULL && output_file_on) +// // { +// // vfprintf(output_file, format, args); +// // if (flush) +// // fflush(output_file); +// // } +// // } +// // break; +// //case OUTPUT_MESSAGE: +// // if (output_file != NULL && output_file_on) +// // { +// // vfprintf(output_file, format, args); +// // if (flush) +// // fflush(output_file); +// // } +// // break; +// //case OUTPUT_PUNCH: +// // if (punch_file != NULL && punch_file_on) +// // { +// // { +// // vfprintf(punch_file, format, args); +// // if (flush) +// // fflush(punch_file); +// // } +// // } +// // break; +// //case OUTPUT_LOG: +// // if (log_file != NULL && log_file_on) +// // { +// // vfprintf(log_file, format, args); +// // if (flush) +// // fflush(log_file); +// // } +// // break; +// //case OUTPUT_SCREEN: +// // if (error_file != NULL && error_file_on) +// // { +// // vfprintf(error_file, format, args); +// // if (flush) +// // fflush(error_file); +// // } +// // break; +// +// //case OUTPUT_DUMP: +// // if (dump_file != NULL && dump_file_on) +// // { +// // vfprintf(dump_file, format, args); +// // if (flush) +// // fflush(dump_file); +// // } +// // break; +// default: +// assert(false); +// break; +// } +//} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//fpunchf(const char *name, const char *format, va_list args) +///* ---------------------------------------------------------------------- */ +//{ +// int flush = 1; +// +// if (punch_file != NULL && punch_file_on) +// { +// { +// vfprintf(punch_file, format, args); +// if (flush) +// fflush(punch_file); +// } +// } +//} /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_msg(int type, const char *format, va_list args) +fpunchf(const char *name, const char *format, double d) /* ---------------------------------------------------------------------- */ { - int flush = 1; - - switch (type) - { - - //case OUTPUT_ERROR: - // io_error_count++; - // if (error_file != NULL && error_file_on) - // { - // fprintf(error_file, "\nERROR: "); - // vfprintf(error_file, format, args); - // fflush(error_file); - // } - // if (output_file != NULL && output_file_on) - // { - // fprintf(output_file, "\nERROR: "); - // vfprintf(output_file, format, args); - // fflush(output_file); - // } - // if (log_file != NULL && log_file_on) - // { - // fprintf(log_file, "\nERROR: "); - // vfprintf(log_file, format, args); - // fflush(log_file); - // } - // break; - //case OUTPUT_WARNING: - // if (error_file != NULL && error_file_on) - // { - // fprintf(error_file, "\nWARNING: "); - // vfprintf(error_file, format, args); - // fflush(error_file); - // } - // if (output_file != NULL && output_file_on) - // { - // fprintf(output_file, "\nWARNING: "); - // vfprintf(output_file, format, args); - // fflush(output_file); - // } - // if (log_file != NULL && log_file_on) - // { - // fprintf(log_file, "\nWARNING: "); - // vfprintf(log_file, format, args); - // fflush(log_file); - // } - // break; - //case OUTPUT_CHECKLINE: - // { - // if (output_file != NULL && output_file_on) - // { - // vfprintf(output_file, format, args); - // if (flush) - // fflush(output_file); - // } - // } - // break; - //case OUTPUT_MESSAGE: - // if (output_file != NULL && output_file_on) - // { - // vfprintf(output_file, format, args); - // if (flush) - // fflush(output_file); - // } - // break; - //case OUTPUT_PUNCH: - // if (punch_file != NULL && punch_file_on) - // { - // { - // vfprintf(punch_file, format, args); - // if (flush) - // fflush(punch_file); - // } - // } - // break; - //case OUTPUT_LOG: - // if (log_file != NULL && log_file_on) - // { - // vfprintf(log_file, format, args); - // if (flush) - // fflush(log_file); - // } - // break; - //case OUTPUT_SCREEN: - // if (error_file != NULL && error_file_on) - // { - // vfprintf(error_file, format, args); - // if (flush) - // fflush(error_file); - // } - // break; - - //case OUTPUT_DUMP: - // if (dump_file != NULL && dump_file_on) - // { - // vfprintf(dump_file, format, args); - // if (flush) - // fflush(dump_file); - // } - // break; - default: - assert(false); - break; - } -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -fpunchf(const char *name, const char *format, va_list args) -/* ---------------------------------------------------------------------- */ -{ - int flush = 1; - if (punch_file != NULL && punch_file_on) { { - vfprintf(punch_file, format, args); - if (flush) - fflush(punch_file); + fprintf(punch_file, format, d); } } } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_string(const int type, std::string str) +fpunchf(const char *name, const char *format, char * s) /* ---------------------------------------------------------------------- */ { - - switch (type) + if (punch_file != NULL && punch_file_on) { - - //case OUTPUT_ERROR: - // //this->io_error_count++; - // if (error_file != NULL && error_file_on) - // { - // fprintf(error_file, "%s", str.c_str()); - // } - // fflush(error_file); - // break; - - //case OUTPUT_WARNING: - // if (log_file != NULL && log_file_on) - // { - // fprintf(log_file, "%s", str.c_str()); - // } - // if (error_file != NULL && error_file_on) - // { - // fprintf(error_file, "%s", str.c_str()); - // fflush(error_file); - // } - // if (output_file != NULL && output_file_on) - // { - // fprintf(output_file, "%s", str.c_str()); - // } - // break; - //case OUTPUT_CHECKLINE: - //case OUTPUT_MESSAGE: - // if (output_file != NULL && output_file_on) - // { - // fprintf(output_file, "%s", str.c_str()); - // } - // break; - //case OUTPUT_PUNCH: - // if (punch_file != NULL && punch_file_on) - // { - // fprintf(punch_file, "%s", str.c_str()); - // } - // break; - //case OUTPUT_LOG: - // if (log_file != NULL && log_file_on) - // { - // fprintf(log_file, "%s", str.c_str()); - // } - // break; - //case OUTPUT_SCREEN: - // if (error_file != NULL && error_file_on) - // { - // fprintf(error_file, "%s", str.c_str()); - // fflush(error_file); - // } - // break; - - //case OUTPUT_DUMP: - // if (dump_file != NULL && dump_file_on) - // { - // fprintf(dump_file, "%s", str.c_str()); - // } - // break; - default: - assert(false); + { + fprintf(punch_file, format, s); + } } - return; } /* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf(const char *name, const char *format, int d) +/* ---------------------------------------------------------------------- */ +{ + if (punch_file != NULL && punch_file_on) + { + { + fprintf(punch_file, format, d); + } + } +} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//output_string(const int type, std::string str) +///* ---------------------------------------------------------------------- */ +//{ +// +// switch (type) +// { +// +// //case OUTPUT_ERROR: +// // //this->io_error_count++; +// // if (error_file != NULL && error_file_on) +// // { +// // fprintf(error_file, "%s", str.c_str()); +// // } +// // fflush(error_file); +// // break; +// +// //case OUTPUT_WARNING: +// // if (log_file != NULL && log_file_on) +// // { +// // fprintf(log_file, "%s", str.c_str()); +// // } +// // if (error_file != NULL && error_file_on) +// // { +// // fprintf(error_file, "%s", str.c_str()); +// // fflush(error_file); +// // } +// // if (output_file != NULL && output_file_on) +// // { +// // fprintf(output_file, "%s", str.c_str()); +// // } +// // break; +// //case OUTPUT_CHECKLINE: +// //case OUTPUT_MESSAGE: +// // if (output_file != NULL && output_file_on) +// // { +// // fprintf(output_file, "%s", str.c_str()); +// // } +// // break; +// //case OUTPUT_PUNCH: +// // if (punch_file != NULL && punch_file_on) +// // { +// // fprintf(punch_file, "%s", str.c_str()); +// // } +// // break; +// //case OUTPUT_LOG: +// // if (log_file != NULL && log_file_on) +// // { +// // fprintf(log_file, "%s", str.c_str()); +// // } +// // break; +// //case OUTPUT_SCREEN: +// // if (error_file != NULL && error_file_on) +// // { +// // fprintf(error_file, "%s", str.c_str()); +// // fflush(error_file); +// // } +// // break; +// +// //case OUTPUT_DUMP: +// // if (dump_file != NULL && dump_file_on) +// // { +// // fprintf(dump_file, "%s", str.c_str()); +// // } +// // break; +// default: +// assert(false); +// } +// return; +//} +/* ---------------------------------------------------------------------- */ int PHRQ_io:: close_output_files(void) /* ---------------------------------------------------------------------- */ @@ -708,263 +744,263 @@ close_output_files(void) return ret; } -/* ---------------------------------------------------------------------- */ -int PHRQ_io:: -output_open(int type, const char *file_name) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { +///* ---------------------------------------------------------------------- */ +//int PHRQ_io:: +//output_open(int type, const char *file_name) +///* ---------------------------------------------------------------------- */ +//{ +// switch (type) +// { +// +// //case OUTPUT_PUNCH: +// // if (punch_file != NULL) +// // { +// // fclose(punch_file); +// // punch_file = NULL; +// // } +// // if ((punch_file = fopen(file_name, "w")) == NULL) +// // { +// // //return ERROR; +// // return 0; +// // } +// // break; +// //case OUTPUT_MESSAGE: +// // if (output_file != NULL) +// // { +// // safe_close(output_file); +// // output_file = NULL; +// // } +// // if ((output_file = fopen(file_name, "w")) == NULL) +// // { +// // //return ERROR; +// // return 0; +// // } +// // break; +// //case OUTPUT_DUMP: +// // if (dump_file != NULL) +// // { +// // safe_close(dump_file); +// // dump_file = NULL; +// // } +// // if ((dump_file = fopen(file_name, "w")) == NULL) +// // { +// // //return ERROR; +// // return 0; +// // } +// // break; +// //case OUTPUT_ERROR: +// // if (error_file != NULL) +// // { +// // safe_close(error_file); +// // error_file = NULL; +// // } +// +// // if (file_name != NULL) +// // { +// // if ((error_file = fopen(file_name, "w")) == NULL) +// // { +// // error_file = stderr; +// // return 0; +// // } +// // } +// // else +// // { +// // error_file = stderr; +// // } +// // break; +// //case OUTPUT_LOG: +// // if (log_file != NULL) +// // { +// // safe_close(log_file); +// // log_file = NULL; +// // } +// // if ((log_file = fopen(file_name, "w")) == NULL) +// // { +// // return 0; +// // } +// // break; +// default: +// assert(false); +// } +// return 1; +//} - //case OUTPUT_PUNCH: - // if (punch_file != NULL) - // { - // fclose(punch_file); - // punch_file = NULL; - // } - // if ((punch_file = fopen(file_name, "w")) == NULL) - // { - // //return ERROR; - // return 0; - // } - // break; - //case OUTPUT_MESSAGE: - // if (output_file != NULL) - // { - // safe_close(output_file); - // output_file = NULL; - // } - // if ((output_file = fopen(file_name, "w")) == NULL) - // { - // //return ERROR; - // return 0; - // } - // break; - //case OUTPUT_DUMP: - // if (dump_file != NULL) - // { - // safe_close(dump_file); - // dump_file = NULL; - // } - // if ((dump_file = fopen(file_name, "w")) == NULL) - // { - // //return ERROR; - // return 0; - // } - // break; - //case OUTPUT_ERROR: - // if (error_file != NULL) - // { - // safe_close(error_file); - // error_file = NULL; - // } +///* ---------------------------------------------------------------------- */ +//bool PHRQ_io:: +//output_isopen(const int type) +///* ---------------------------------------------------------------------- */ +//{ +// switch (type) +// { +// //case OUTPUT_ERROR: +// // return (error_file != NULL); +// // break; +// //case OUTPUT_WARNING: +// // return (error_file != NULL || output_file != NULL); +// // break; +// //case OUTPUT_MESSAGE: +// // return (output_file != NULL); +// // break; +// //case OUTPUT_PUNCH: +// // return (punch_file != NULL); +// // break; +// //case OUTPUT_SCREEN: +// // return (error_file != NULL); +// // break; +// //case OUTPUT_LOG: +// // return (log_file != NULL); +// // break; +// //case OUTPUT_DUMP: +// // return (dump_file != NULL); +// // break; +// default: +// assert(false); +// return (output_file != NULL); +// break; +// } +// return false; +//} - // if (file_name != NULL) - // { - // if ((error_file = fopen(file_name, "w")) == NULL) - // { - // error_file = stderr; - // return 0; - // } - // } - // else - // { - // error_file = stderr; - // } - // break; - //case OUTPUT_LOG: - // if (log_file != NULL) - // { - // safe_close(log_file); - // log_file = NULL; - // } - // if ((log_file = fopen(file_name, "w")) == NULL) - // { - // return 0; - // } - // break; - default: - assert(false); - } - return 1; -} - -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -output_isopen(const int type) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - //case OUTPUT_ERROR: - // return (error_file != NULL); - // break; - //case OUTPUT_WARNING: - // return (error_file != NULL || output_file != NULL); - // break; - //case OUTPUT_MESSAGE: - // return (output_file != NULL); - // break; - //case OUTPUT_PUNCH: - // return (punch_file != NULL); - // break; - //case OUTPUT_SCREEN: - // return (error_file != NULL); - // break; - //case OUTPUT_LOG: - // return (log_file != NULL); - // break; - //case OUTPUT_DUMP: - // return (dump_file != NULL); - // break; - default: - assert(false); - return (output_file != NULL); - break; - } - return false; -} - -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -output_fflush(const int type) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - //case OUTPUT_ERROR: - // if (error_file) - // fflush(error_file); - // break; - - //case OUTPUT_WARNING: - // if (error_file) - // fflush(error_file); - // if (output_file) - // fflush(output_file); - // break; - - //case OUTPUT_MESSAGE: - ////case OUTPUT_CHECKLINE: - // if (output_file) - // fflush(output_file); - // break; - - //case OUTPUT_PUNCH: - // if (punch_file) - // fflush(punch_file); - // break; - - //case OUTPUT_SCREEN: - // if (error_file) - // fflush(error_file); - // break; - - //case OUTPUT_LOG: - // if (log_file) - // fflush(log_file); - // break; - - //case OUTPUT_DUMP: - // if (dump_file) - // fflush(dump_file); - // break; - default: - assert(false); - break; - } -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -output_rewind(const int type) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - //case OUTPUT_ERROR: - // if (error_file) - // rewind(error_file); - // break; - - //case OUTPUT_WARNING: - // if (error_file) - // rewind(error_file); - // if (output_file) - // rewind(output_file); - // break; - - //case OUTPUT_MESSAGE: - ////case OUTPUT_CHECKLINE: - // if (output_file) - // rewind(output_file); - // break; - - //case OUTPUT_PUNCH: - // if (punch_file) - // rewind(punch_file); - // break; - - //case OUTPUT_SCREEN: - // if (error_file) - // rewind(error_file); - // break; - - //case OUTPUT_LOG: - // if (log_file) - // rewind(log_file); - // break; - - //case OUTPUT_DUMP: - // if (dump_file) - // rewind(dump_file); - // break; - default: - assert(false); - break; - } -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -output_close(const int type) -/* ---------------------------------------------------------------------- */ -{ - switch (type) - { - //case OUTPUT_ERROR: - // safe_close(error_file); - // break; - - //case OUTPUT_WARNING: - // safe_close(error_file); - // safe_close(output_file); - // break; - - //case OUTPUT_MESSAGE: - ////case OUTPUT_CHECKLINE: - // safe_close(output_file); - // break; - - //case OUTPUT_PUNCH: - // safe_close(punch_file); - // break; - - //case OUTPUT_SCREEN: - // safe_close(error_file); - // break; - - //case OUTPUT_LOG: - // safe_close(log_file); - // break; - - //case OUTPUT_DUMP: - // safe_close(dump_file); - // break; - - default: - assert(false); - break; - } -} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//output_fflush(const int type) +///* ---------------------------------------------------------------------- */ +//{ +// switch (type) +// { +// //case OUTPUT_ERROR: +// // if (error_file) +// // fflush(error_file); +// // break; +// +// //case OUTPUT_WARNING: +// // if (error_file) +// // fflush(error_file); +// // if (output_file) +// // fflush(output_file); +// // break; +// +// //case OUTPUT_MESSAGE: +// ////case OUTPUT_CHECKLINE: +// // if (output_file) +// // fflush(output_file); +// // break; +// +// //case OUTPUT_PUNCH: +// // if (punch_file) +// // fflush(punch_file); +// // break; +// +// //case OUTPUT_SCREEN: +// // if (error_file) +// // fflush(error_file); +// // break; +// +// //case OUTPUT_LOG: +// // if (log_file) +// // fflush(log_file); +// // break; +// +// //case OUTPUT_DUMP: +// // if (dump_file) +// // fflush(dump_file); +// // break; +// default: +// assert(false); +// break; +// } +//} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//output_rewind(const int type) +///* ---------------------------------------------------------------------- */ +//{ +// switch (type) +// { +// //case OUTPUT_ERROR: +// // if (error_file) +// // rewind(error_file); +// // break; +// +// //case OUTPUT_WARNING: +// // if (error_file) +// // rewind(error_file); +// // if (output_file) +// // rewind(output_file); +// // break; +// +// //case OUTPUT_MESSAGE: +// ////case OUTPUT_CHECKLINE: +// // if (output_file) +// // rewind(output_file); +// // break; +// +// //case OUTPUT_PUNCH: +// // if (punch_file) +// // rewind(punch_file); +// // break; +// +// //case OUTPUT_SCREEN: +// // if (error_file) +// // rewind(error_file); +// // break; +// +// //case OUTPUT_LOG: +// // if (log_file) +// // rewind(log_file); +// // break; +// +// //case OUTPUT_DUMP: +// // if (dump_file) +// // rewind(dump_file); +// // break; +// default: +// assert(false); +// break; +// } +//} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//output_close(const int type) +///* ---------------------------------------------------------------------- */ +//{ +// switch (type) +// { +// //case OUTPUT_ERROR: +// // safe_close(error_file); +// // break; +// +// //case OUTPUT_WARNING: +// // safe_close(error_file); +// // safe_close(output_file); +// // break; +// +// //case OUTPUT_MESSAGE: +// ////case OUTPUT_CHECKLINE: +// // safe_close(output_file); +// // break; +// +// //case OUTPUT_PUNCH: +// // safe_close(punch_file); +// // break; +// +// //case OUTPUT_SCREEN: +// // safe_close(error_file); +// // break; +// +// //case OUTPUT_LOG: +// // safe_close(log_file); +// // break; +// +// //case OUTPUT_DUMP: +// // safe_close(dump_file); +// // break; +// +// default: +// assert(false); +// break; +// } +//} //safe_close is static method /* ---------------------------------------------------------------------- */ diff --git a/PHRQ_io.h b/PHRQ_io.h index aa6ccc44..9758d368 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -84,15 +84,18 @@ typedef enum bool dump_isopen(void); void dump_msg(const char * str); - int output_open(int type, const char *file_name); + //int output_open(int type, const char *file_name); void warning_msg(const char *err_str); - void output_string(const int type, std::string str); - void output_fflush(int type); - void output_rewind(int type); - void output_close(int type); - bool output_isopen(int type); - void output_msg(int type, const char *format, va_list args); - void fpunchf(const char *name, const char *format, va_list args); + //void output_string(const int type, std::string str); + //void output_fflush(int type); + //void output_rewind(int type); + //void output_close(int type); + //bool output_isopen(int type); + //void output_msg(int type, const char *format, va_list args); + //void fpunchf(const char *name, const char *format, va_list args); + void fpunchf(const char *name, const char *format, double d); + void fpunchf(const char *name, const char *format, char * d); + void fpunchf(const char *name, const char *format, int d); void Set_io_error_count(int i) {this->io_error_count = i;}; int Get_io_error_count(void) {return this->io_error_count;}; diff --git a/Phreeqc.h b/Phreeqc.h index 8f268943..a27c8f26 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -283,6 +283,7 @@ int process_file_names(int argc, char *argv[], void **db_cookie, /* PHRQ_io_output.cpp */ void screen_msg(const char *err_str); void echo_msg(const char *err_str); +int warning_msg(const char *err_str); // dump_file bool dump_open(const char *file_name); @@ -325,6 +326,13 @@ bool punch_isopen(void); void punch_msg(const char * str); void fpunchf_heading(const char *name); +void fpunchf(const char *name, const char *format, double d); +void fpunchf(const char *name, const char *format, char * d); +void fpunchf(const char *name, const char *format, int d); +void fpunchf_user(int user_index, const char *format, double d); +void fpunchf_user(int user_index, const char *format, char * d); +int fpunchf_end_row(const char *format); + // dw.c ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); From 05495494ec1de59dfa4877e8f6e6e9cfbb415417 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 19:26:08 +0000 Subject: [PATCH 0293/1077] Removed output.h throughout. Will svn delete output.h, output.cpp, phreeqc_files.cpp, main.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5710 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 1 - PHRQ_io.cpp | 455 ---------------------------------------------- PHRQ_io.h | 47 +---- Phreeqc.h | 4 +- ReadClass.cxx | 4 +- StorageBin.cxx | 1 - SurfaceCharge.cxx | 1 - class_main.cpp | 1 - 8 files changed, 11 insertions(+), 503 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 192d1f52..79e9c3eb 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -20,7 +20,6 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 754bf449..06d6187f 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -490,131 +490,6 @@ warning_msg(const char *err_str) fflush(output_file); } } -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//output_msg(int type, const char *format, va_list args) -///* ---------------------------------------------------------------------- */ -//{ -// int flush = 1; -// -// switch (type) -// { -// -// //case OUTPUT_ERROR: -// // io_error_count++; -// // if (error_file != NULL && error_file_on) -// // { -// // fprintf(error_file, "\nERROR: "); -// // vfprintf(error_file, format, args); -// // fflush(error_file); -// // } -// // if (output_file != NULL && output_file_on) -// // { -// // fprintf(output_file, "\nERROR: "); -// // vfprintf(output_file, format, args); -// // fflush(output_file); -// // } -// // if (log_file != NULL && log_file_on) -// // { -// // fprintf(log_file, "\nERROR: "); -// // vfprintf(log_file, format, args); -// // fflush(log_file); -// // } -// // break; -// //case OUTPUT_WARNING: -// // if (error_file != NULL && error_file_on) -// // { -// // fprintf(error_file, "\nWARNING: "); -// // vfprintf(error_file, format, args); -// // fflush(error_file); -// // } -// // if (output_file != NULL && output_file_on) -// // { -// // fprintf(output_file, "\nWARNING: "); -// // vfprintf(output_file, format, args); -// // fflush(output_file); -// // } -// // if (log_file != NULL && log_file_on) -// // { -// // fprintf(log_file, "\nWARNING: "); -// // vfprintf(log_file, format, args); -// // fflush(log_file); -// // } -// // break; -// //case OUTPUT_CHECKLINE: -// // { -// // if (output_file != NULL && output_file_on) -// // { -// // vfprintf(output_file, format, args); -// // if (flush) -// // fflush(output_file); -// // } -// // } -// // break; -// //case OUTPUT_MESSAGE: -// // if (output_file != NULL && output_file_on) -// // { -// // vfprintf(output_file, format, args); -// // if (flush) -// // fflush(output_file); -// // } -// // break; -// //case OUTPUT_PUNCH: -// // if (punch_file != NULL && punch_file_on) -// // { -// // { -// // vfprintf(punch_file, format, args); -// // if (flush) -// // fflush(punch_file); -// // } -// // } -// // break; -// //case OUTPUT_LOG: -// // if (log_file != NULL && log_file_on) -// // { -// // vfprintf(log_file, format, args); -// // if (flush) -// // fflush(log_file); -// // } -// // break; -// //case OUTPUT_SCREEN: -// // if (error_file != NULL && error_file_on) -// // { -// // vfprintf(error_file, format, args); -// // if (flush) -// // fflush(error_file); -// // } -// // break; -// -// //case OUTPUT_DUMP: -// // if (dump_file != NULL && dump_file_on) -// // { -// // vfprintf(dump_file, format, args); -// // if (flush) -// // fflush(dump_file); -// // } -// // break; -// default: -// assert(false); -// break; -// } -//} -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//fpunchf(const char *name, const char *format, va_list args) -///* ---------------------------------------------------------------------- */ -//{ -// int flush = 1; -// -// if (punch_file != NULL && punch_file_on) -// { -// { -// vfprintf(punch_file, format, args); -// if (flush) -// fflush(punch_file); -// } -// } -//} /* ---------------------------------------------------------------------- */ void PHRQ_io:: fpunchf(const char *name, const char *format, double d) @@ -651,77 +526,6 @@ fpunchf(const char *name, const char *format, int d) } } } -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//output_string(const int type, std::string str) -///* ---------------------------------------------------------------------- */ -//{ -// -// switch (type) -// { -// -// //case OUTPUT_ERROR: -// // //this->io_error_count++; -// // if (error_file != NULL && error_file_on) -// // { -// // fprintf(error_file, "%s", str.c_str()); -// // } -// // fflush(error_file); -// // break; -// -// //case OUTPUT_WARNING: -// // if (log_file != NULL && log_file_on) -// // { -// // fprintf(log_file, "%s", str.c_str()); -// // } -// // if (error_file != NULL && error_file_on) -// // { -// // fprintf(error_file, "%s", str.c_str()); -// // fflush(error_file); -// // } -// // if (output_file != NULL && output_file_on) -// // { -// // fprintf(output_file, "%s", str.c_str()); -// // } -// // break; -// //case OUTPUT_CHECKLINE: -// //case OUTPUT_MESSAGE: -// // if (output_file != NULL && output_file_on) -// // { -// // fprintf(output_file, "%s", str.c_str()); -// // } -// // break; -// //case OUTPUT_PUNCH: -// // if (punch_file != NULL && punch_file_on) -// // { -// // fprintf(punch_file, "%s", str.c_str()); -// // } -// // break; -// //case OUTPUT_LOG: -// // if (log_file != NULL && log_file_on) -// // { -// // fprintf(log_file, "%s", str.c_str()); -// // } -// // break; -// //case OUTPUT_SCREEN: -// // if (error_file != NULL && error_file_on) -// // { -// // fprintf(error_file, "%s", str.c_str()); -// // fflush(error_file); -// // } -// // break; -// -// //case OUTPUT_DUMP: -// // if (dump_file != NULL && dump_file_on) -// // { -// // fprintf(dump_file, "%s", str.c_str()); -// // } -// // break; -// default: -// assert(false); -// } -// return; -//} /* ---------------------------------------------------------------------- */ int PHRQ_io:: close_output_files(void) @@ -743,265 +547,6 @@ close_output_files(void) output_file = log_file = punch_file = dump_file = NULL; return ret; } - -///* ---------------------------------------------------------------------- */ -//int PHRQ_io:: -//output_open(int type, const char *file_name) -///* ---------------------------------------------------------------------- */ -//{ -// switch (type) -// { -// -// //case OUTPUT_PUNCH: -// // if (punch_file != NULL) -// // { -// // fclose(punch_file); -// // punch_file = NULL; -// // } -// // if ((punch_file = fopen(file_name, "w")) == NULL) -// // { -// // //return ERROR; -// // return 0; -// // } -// // break; -// //case OUTPUT_MESSAGE: -// // if (output_file != NULL) -// // { -// // safe_close(output_file); -// // output_file = NULL; -// // } -// // if ((output_file = fopen(file_name, "w")) == NULL) -// // { -// // //return ERROR; -// // return 0; -// // } -// // break; -// //case OUTPUT_DUMP: -// // if (dump_file != NULL) -// // { -// // safe_close(dump_file); -// // dump_file = NULL; -// // } -// // if ((dump_file = fopen(file_name, "w")) == NULL) -// // { -// // //return ERROR; -// // return 0; -// // } -// // break; -// //case OUTPUT_ERROR: -// // if (error_file != NULL) -// // { -// // safe_close(error_file); -// // error_file = NULL; -// // } -// -// // if (file_name != NULL) -// // { -// // if ((error_file = fopen(file_name, "w")) == NULL) -// // { -// // error_file = stderr; -// // return 0; -// // } -// // } -// // else -// // { -// // error_file = stderr; -// // } -// // break; -// //case OUTPUT_LOG: -// // if (log_file != NULL) -// // { -// // safe_close(log_file); -// // log_file = NULL; -// // } -// // if ((log_file = fopen(file_name, "w")) == NULL) -// // { -// // return 0; -// // } -// // break; -// default: -// assert(false); -// } -// return 1; -//} - -///* ---------------------------------------------------------------------- */ -//bool PHRQ_io:: -//output_isopen(const int type) -///* ---------------------------------------------------------------------- */ -//{ -// switch (type) -// { -// //case OUTPUT_ERROR: -// // return (error_file != NULL); -// // break; -// //case OUTPUT_WARNING: -// // return (error_file != NULL || output_file != NULL); -// // break; -// //case OUTPUT_MESSAGE: -// // return (output_file != NULL); -// // break; -// //case OUTPUT_PUNCH: -// // return (punch_file != NULL); -// // break; -// //case OUTPUT_SCREEN: -// // return (error_file != NULL); -// // break; -// //case OUTPUT_LOG: -// // return (log_file != NULL); -// // break; -// //case OUTPUT_DUMP: -// // return (dump_file != NULL); -// // break; -// default: -// assert(false); -// return (output_file != NULL); -// break; -// } -// return false; -//} - -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//output_fflush(const int type) -///* ---------------------------------------------------------------------- */ -//{ -// switch (type) -// { -// //case OUTPUT_ERROR: -// // if (error_file) -// // fflush(error_file); -// // break; -// -// //case OUTPUT_WARNING: -// // if (error_file) -// // fflush(error_file); -// // if (output_file) -// // fflush(output_file); -// // break; -// -// //case OUTPUT_MESSAGE: -// ////case OUTPUT_CHECKLINE: -// // if (output_file) -// // fflush(output_file); -// // break; -// -// //case OUTPUT_PUNCH: -// // if (punch_file) -// // fflush(punch_file); -// // break; -// -// //case OUTPUT_SCREEN: -// // if (error_file) -// // fflush(error_file); -// // break; -// -// //case OUTPUT_LOG: -// // if (log_file) -// // fflush(log_file); -// // break; -// -// //case OUTPUT_DUMP: -// // if (dump_file) -// // fflush(dump_file); -// // break; -// default: -// assert(false); -// break; -// } -//} -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//output_rewind(const int type) -///* ---------------------------------------------------------------------- */ -//{ -// switch (type) -// { -// //case OUTPUT_ERROR: -// // if (error_file) -// // rewind(error_file); -// // break; -// -// //case OUTPUT_WARNING: -// // if (error_file) -// // rewind(error_file); -// // if (output_file) -// // rewind(output_file); -// // break; -// -// //case OUTPUT_MESSAGE: -// ////case OUTPUT_CHECKLINE: -// // if (output_file) -// // rewind(output_file); -// // break; -// -// //case OUTPUT_PUNCH: -// // if (punch_file) -// // rewind(punch_file); -// // break; -// -// //case OUTPUT_SCREEN: -// // if (error_file) -// // rewind(error_file); -// // break; -// -// //case OUTPUT_LOG: -// // if (log_file) -// // rewind(log_file); -// // break; -// -// //case OUTPUT_DUMP: -// // if (dump_file) -// // rewind(dump_file); -// // break; -// default: -// assert(false); -// break; -// } -//} -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//output_close(const int type) -///* ---------------------------------------------------------------------- */ -//{ -// switch (type) -// { -// //case OUTPUT_ERROR: -// // safe_close(error_file); -// // break; -// -// //case OUTPUT_WARNING: -// // safe_close(error_file); -// // safe_close(output_file); -// // break; -// -// //case OUTPUT_MESSAGE: -// ////case OUTPUT_CHECKLINE: -// // safe_close(output_file); -// // break; -// -// //case OUTPUT_PUNCH: -// // safe_close(punch_file); -// // break; -// -// //case OUTPUT_SCREEN: -// // safe_close(error_file); -// // break; -// -// //case OUTPUT_LOG: -// // safe_close(log_file); -// // break; -// -// //case OUTPUT_DUMP: -// // safe_close(dump_file); -// // break; -// -// default: -// assert(false); -// break; -// } -//} - //safe_close is static method /* ---------------------------------------------------------------------- */ void PHRQ_io:: diff --git a/PHRQ_io.h b/PHRQ_io.h index 9758d368..e241d01a 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -8,41 +8,16 @@ class PhreeqcStop : std::exception class PHRQ_io { public: -typedef enum -{ - //OUTPUT_ERROR, - //OUTPUT_WARNING, - //OUTPUT_MESSAGE, - //OUTPUT_PUNCH, - //OUTPUT_SCREEN, - //OUTPUT_LOG, - //OUTPUT_CHECKLINE, - OUTPUT_GUI_ERROR, - //OUTPUT_DUMP, - //OUTPUT_SEND_MESSAGE, - //OUTPUT_ECHO, - OUTPUT_PUNCH_END_ROW -} output_type; - -//typedef enum -//{ -// ACTION_OPEN, -// ACTION_OUTPUT, -// ACTION_CLOSE, -// ACTION_REWIND, -// ACTION_FLUSH -//} action_type; - - // constructors + // constructor/destructor PHRQ_io(void); virtual ~ PHRQ_io(); // methods - - static void safe_close(FILE * file_ptr); + static int istream_getc(void *cookie); + static void safe_close(FILE * file_ptr); + int close_input_files(void); int close_output_files(void); - static int istream_getc(void *cookie); // output_file bool output_temp_open(const char *file_name); @@ -75,6 +50,7 @@ typedef enum void error_rewind(void); bool error_isopen(void); void error_msg(const char * str, bool stop=false); + void warning_msg(const char *err_str); // dump_file bool dump_open(const char *file_name); @@ -83,16 +59,8 @@ typedef enum void dump_rewind(void); bool dump_isopen(void); void dump_msg(const char * str); + - //int output_open(int type, const char *file_name); - void warning_msg(const char *err_str); - //void output_string(const int type, std::string str); - //void output_fflush(int type); - //void output_rewind(int type); - //void output_close(int type); - //bool output_isopen(int type); - //void output_msg(int type, const char *format, va_list args); - //void fpunchf(const char *name, const char *format, va_list args); void fpunchf(const char *name, const char *format, double d); void fpunchf(const char *name, const char *format, char * d); void fpunchf(const char *name, const char *format, int d); @@ -107,7 +75,8 @@ typedef enum void Set_punch_file(FILE * out); void Set_dump_file(FILE * out); - void PHRQ_io::close_input(void); + // close input file + void close_input(void); void Set_output_file_on(bool tf) {this->output_file_on = tf;}; void Set_log_file_on(bool tf) {this->log_file_on = tf;}; diff --git a/Phreeqc.h b/Phreeqc.h index a27c8f26..70f13836 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -65,8 +65,6 @@ public: #include "pitzer.h" #include "input.h" -public: -#include "output.h" public: #include "global.h" /* @@ -284,6 +282,8 @@ int process_file_names(int argc, char *argv[], void **db_cookie, void screen_msg(const char *err_str); void echo_msg(const char *err_str); int warning_msg(const char *err_str); +void set_forward_output_to_log(int value); +int get_forward_output_to_log(void); // dump_file bool dump_open(const char *file_name); diff --git a/ReadClass.cxx b/ReadClass.cxx index d45113ca..d024374c 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -28,8 +28,6 @@ #include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" - #if !defined(PHREEQC_CLASS) static int streamify_to_next_keyword(std::istringstream & lines); @@ -2775,7 +2773,7 @@ read_user_graph_handler(void) bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser); // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line).c_str()); + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } #endif \ No newline at end of file diff --git a/StorageBin.cxx b/StorageBin.cxx index 9ac8226e..9689f928 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -36,7 +36,6 @@ #include "Temperature.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index a60de6de..9d2f06ab 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -18,7 +18,6 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/class_main.cpp b/class_main.cpp index 1cc34b4d..990c70ee 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,5 +1,4 @@ #include "Phreeqc.h" -#include "output.h" #include "phrqproto.h" #include "input.h" #include "NameDouble.h" From 601d8515b867afff48eeed0cfaada6c0b174ae25 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 20:06:32 +0000 Subject: [PATCH 0294/1077] Removed PHREEQC_CPP and some PHREEQC_CLASS. Will continue to remove PHREEQC_CLASS. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5711 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 5 ----- Exchange.cxx | 7 +------ GasPhase.cxx | 2 -- ISolution.cxx | 1 - ISolutionComp.cxx | 1 - NameDouble.cxx | 1 - PPassemblageComp.cxx | 2 -- Parser.cxx | 1 - Phreeqc.cpp | 2 -- Solution.cxx | 3 --- SurfaceComp.cxx | 1 - 11 files changed, 1 insertion(+), 25 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index d74fb27a..4035d8fa 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -12,15 +12,10 @@ #include #include #include -#ifdef PHREEQC_CPP #include "Phreeqc_class.h" -#endif -#ifdef PHREEQC_CLASS #include "Phreeqc.h" -#endif #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" #include "Form1.h" using namespace zdg_ui2; diff --git a/Exchange.cxx b/Exchange.cxx index 5f1b5e23..ac6d6b58 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -9,17 +9,12 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else + #include "Phreeqc.h" -#endif #include "cxxMix.h" #include "Exchange.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/GasPhase.cxx b/GasPhase.cxx index cb665f14..0be364ea 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -19,8 +19,6 @@ #include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ISolution.cxx b/ISolution.cxx index c777edeb..91e63a2f 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -18,7 +18,6 @@ #include "ISolution.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 6aec744e..f888c084 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -13,7 +13,6 @@ #include "ISolutionComp.h" #include "phrqproto.h" #include "phqalloc.h" -#include "output.h" cxxISolutionComp::cxxISolutionComp(PHRQ_io *io): PHRQ_base(io), diff --git a/NameDouble.cxx b/NameDouble.cxx index 72b2ddc1..dc0f594a 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -20,7 +20,6 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 6cc2c793..e9904e67 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -18,8 +18,6 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/Parser.cxx b/Parser.cxx index 0a58fd22..bfd26094 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -16,7 +16,6 @@ #include "Phreeqc.h" #endif #include "Parser.h" -#include "output.h" #include "PHRQ_io.h" ////////////////////////////////////////////////////////////////////// diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 44e90f3b..28c7856d 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -131,7 +131,6 @@ Phreeqc::Phreeqc(void) {"pitzer", 0}, {"sit", 0}, {"equilibrium_phase", 0} -#ifdef PHREEQC_CPP , {"solution_raw", 0}, {"exchange_raw", 0}, @@ -156,7 +155,6 @@ Phreeqc::Phreeqc(void) {"reaction_modify", 0}, {"reaction_temperature_modify", 0}, {"solid_solution_modify", 0} -#endif }; NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ diff --git a/Solution.cxx b/Solution.cxx index 46c94209..be4c191f 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -24,9 +24,6 @@ #include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" - - ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 526ccd15..da12058d 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -18,7 +18,6 @@ #include "Dictionary.h" #include "phqalloc.h" #include "phrqproto.h" -#include "output.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction From 7e26eec197c9934fdfa0eeb7e314ad3b0efcbee7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 21:14:33 +0000 Subject: [PATCH 0295/1077] Last checkin svn deleted obsolete files output.h, output.cpp, phreeqc_files, main.cpp. removed all PHREEQC_CLASS ifdefs Need to remove old_io ifdefs git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5712 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 7 ------- ChartObject.h | 10 ---------- ExchComp.cxx | 5 ----- GasPhase.cxx | 5 ----- ISolution.cxx | 5 ----- ISolutionComp.cxx | 5 ----- KineticsComp.cxx | 5 ----- NameDouble.cxx | 5 ----- PPassemblage.cxx | 5 ----- PPassemblageComp.cxx | 5 ----- Parser.cxx | 2 -- Phreeqc_class.h | 13 ++----------- Reaction.cxx | 5 ----- ReadClass.cxx | 21 --------------------- SSassemblage.cxx | 5 ----- SSassemblageSS.cxx | 6 ------ Solution.cxx | 5 ----- SolutionIsotope.cxx | 5 ----- SolutionIsotopeList.cxx | 5 ----- StorageBin.cxx | 5 ----- Surface.cxx | 5 ----- SurfaceCharge.cxx | 5 ----- SurfaceComp.cxx | 5 ----- System.cxx | 5 ----- Temperature.cxx | 5 ----- cxxKinetics.cxx | 5 ----- cxxMix.cxx | 5 ----- 27 files changed, 2 insertions(+), 162 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 9e7c47e6..8b40f322 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -7,12 +7,7 @@ #endif #include "ChartHandler.h" #include "phreeqc_class.h" -#if defined PHREEQC_CLASS #include "phreeqc.h" -#else -extern int punch_user_graph(void); -extern int error_msg(const char *err_str, const int stop, ...); -#endif #include @@ -82,9 +77,7 @@ ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) { chart_map[n_user] = new ChartObject(this->Get_io()); it = this->chart_map.find(n_user); -#ifdef PHREEQC_CLASS it->second->Set_phreeqc(P_INSTANCE); -#endif } // Read/update ChartObject diff --git a/ChartObject.h b/ChartObject.h index 7eddaff9..4ce210b4 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -6,11 +6,6 @@ #include #include #include "CurveObject.h" -#if defined PHREEQC_CLASS - -#else -#include "global_structures.h" -#endif #include "NumKeyword.h" #include @@ -274,7 +269,6 @@ class ChartObject:public cxxNumKeyword { return this->form_started; } -#if defined PHREEQC_CLASS void Set_phreeqc(Phreeqc * ptr) { this->p_instance1 = ptr; @@ -283,7 +277,6 @@ class ChartObject:public cxxNumKeyword { return this->p_instance1; } -#endif bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); bool Set_axis_scale(CParser & parser); @@ -377,10 +370,7 @@ class ChartObject:public cxxNumKeyword bool active; bool detach; bool form_started; -#if defined PHREEQC_CLASS class Phreeqc * p_instance1; -#endif - public: int usingResource; diff --git a/ExchComp.cxx b/ExchComp.cxx index 79e9c3eb..c40d6846 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -10,12 +10,7 @@ #include #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "ExchComp.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/GasPhase.cxx b/GasPhase.cxx index 0be364ea..7f868647 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -9,12 +9,7 @@ #include #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "GasPhase.h" #include "cxxMix.h" #include "phqalloc.h" diff --git a/ISolution.cxx b/ISolution.cxx index 91e63a2f..aa76ea7f 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -9,12 +9,7 @@ #include #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "ISolution.h" #include "phqalloc.h" #include "phrqproto.h" diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index f888c084..f9e57837 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -4,12 +4,7 @@ #include #include "Utils.h" -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "ISolutionComp.h" #include "phrqproto.h" #include "phqalloc.h" diff --git a/KineticsComp.cxx b/KineticsComp.cxx index ad2f64f8..70ad7773 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "KineticsComp.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/NameDouble.cxx b/NameDouble.cxx index dc0f594a..0c362d3d 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -10,12 +10,7 @@ #include // std::cout std::cerr #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "NameDouble.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 0ed860cb..fdb386a2 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "PPassemblage.h" #include "cxxMix.h" #include "phqalloc.h" diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index e9904e67..3957e7fe 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "PPassemblageComp.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/Parser.cxx b/Parser.cxx index bfd26094..ed6a7ea0 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -12,9 +12,7 @@ #include // std::cout std::cerr #include "Utils.h" #include -#if defined (PHREEQC_CLASS) #include "Phreeqc.h" -#endif #include "Parser.h" #include "PHRQ_io.h" diff --git a/Phreeqc_class.h b/Phreeqc_class.h index 3720b0eb..f1bac4b8 100644 --- a/Phreeqc_class.h +++ b/Phreeqc_class.h @@ -1,15 +1,6 @@ #ifndef _INC_PHREEQC_CLASS_H #define _INC_PHREEQC_CLASS_H -#if !defined PHREEQC_CLASS -#define P_INSTANCE -#define P_INSTANCE_COMMA -#define P_INSTANCE_POINTER -#define PHREEQC_PTR_ARG -#define PHREEQC_PTR_ARG_COMMA -#define PHREEQC_THIS -#define PHREEQC_THIS_COMMA -#define PHREEQC_NAME_SPACE :: -#else + #define P_INSTANCE p_instance1 #define P_INSTANCE_COMMA p_instance1, #define P_INSTANCE_POINTER p_instance1-> @@ -18,6 +9,6 @@ #define PHREEQC_THIS this #define PHREEQC_THIS_COMMA this, #define PHREEQC_NAME_SPACE Phreeqc:: -#endif + #endif /* _INC_PHREEQC_CLASS_H */ diff --git a/Reaction.cxx b/Reaction.cxx index 4bfdc0d1..0a5dd657 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "Reaction.h" #include "phqalloc.h" #include "phrqproto.h" diff --git a/ReadClass.cxx b/ReadClass.cxx index d024374c..4c22fbde 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -5,12 +5,7 @@ #include #include -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "Phreeqc_class.h" #include "Parser.h" #include "Solution.h" @@ -29,22 +24,6 @@ #include "phqalloc.h" #include "phrqproto.h" -#if !defined(PHREEQC_CLASS) -static int streamify_to_next_keyword(std::istringstream & lines); -extern int reading_database(void); -extern int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); -extern int set_use(void); -extern int copy_use(int i); -dumper dump_info; -StorageBinList delete_info; -runner run_info; - -int dump_entities(void); -void dump_ostream(std::ostream& os); -int delete_entities(void); -int run_as_cells(void); -#endif /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 0d783151..0e5ae1c4 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -9,12 +9,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "SSassemblage.h" #include "SSassemblageSS.h" #include "cxxMix.h" diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 94f62222..b261ab20 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -8,13 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#include "output.h" -#else #include "Phreeqc.h" -#endif #include "SSassemblageSS.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/Solution.cxx b/Solution.cxx index be4c191f..12d3d836 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -14,12 +14,7 @@ #include // assert #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "Solution.h" #include "cxxMix.h" #include "phqalloc.h" diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 3a34bc19..6701ffe0 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -5,12 +5,7 @@ #include // std::ostrstream #include "Utils.h" -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "SolutionIsotope.h" #include "phqalloc.h" #include "phrqproto.h" diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index 468d8c20..b1640d4c 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -2,12 +2,7 @@ #include // assert #include // std::sort -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "SolutionIsotopeList.h" #include "phqalloc.h" #include "phrqproto.h" diff --git a/StorageBin.cxx b/StorageBin.cxx index 9689f928..15273642 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -14,12 +14,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "NameDouble.h" #include "StorageBin.h" #include "SSassemblage.h" diff --git a/Surface.cxx b/Surface.cxx index bdf3e9b6..5606efa8 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Phreeqc_class.h" #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "Surface.h" #include "cxxMix.h" #include "phqalloc.h" diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 9d2f06ab..b13f17be 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "SurfaceCharge.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index da12058d..703cda8c 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "SurfaceComp.h" #include "Dictionary.h" #include "phqalloc.h" diff --git a/System.cxx b/System.cxx index 4f6487b9..897c6995 100644 --- a/System.cxx +++ b/System.cxx @@ -1,11 +1,6 @@ #include // std::replace -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "System.h" #include "SSassemblage.h" #include "Solution.h" diff --git a/Temperature.cxx b/Temperature.cxx index 4704e0de..51f54602 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -9,12 +9,7 @@ #include "Utils.h" // define first #include "Parser.h" -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "Temperature.h" #include "phqalloc.h" #include "phrqproto.h" diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index f37245bd..89341f7a 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -8,12 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "cxxKinetics.h" #include "cxxMix.h" diff --git a/cxxMix.cxx b/cxxMix.cxx index b6396d54..fd2d2e98 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -9,12 +9,7 @@ #include "Utils.h" // define first #include "Parser.h" -#if !defined(PHREEQC_CLASS) -#define EXTERNAL extern -#include "global.h" -#else #include "Phreeqc.h" -#endif #include "cxxMix.h" #include "phqalloc.h" #include "phrqproto.h" From f1e5f4c778924b008f83a7730676ba20db0bc789 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 21:26:47 +0000 Subject: [PATCH 0296/1077] About to do CLASS_QUALIFIER git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5713 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 990c70ee..ea1fa42d 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -39,25 +39,8 @@ main(int argc, char *argv[]) //_crtBreakAlloc = 9482; #endif - /*if (svnid == NULL) - fprintf(stderr, " ");*/ - - Phreeqc phreeqc_instance; phreeqc_instance.main_method(argc, argv); -#ifdef CHARTxxx - if (phreeqc_instance.u_g) - { - System::Diagnostics::Process^ currentProcess = System::Diagnostics::Process::GetCurrentProcess(); - //System::Console::WriteLine(currentProcess->Threads->Count); - while (currentProcess->Threads->Count > 8) - { - currentProcess->Refresh(); - //System::Console::WriteLine(currentProcess->Threads->Count); - System::Threading::Thread::CurrentThread->Sleep(100); - } - } -#endif } @@ -87,22 +70,7 @@ main_method(int argc, char *argv[]) //_crtBreakAlloc = 9482; #endif - //if (svnid == NULL) - // fprintf(stderr, " "); phast = FALSE; -/* - * Add callbacks for error_msg and warning_msg - */ -#ifdef USE_OLD_IO - if (add_output_callback(phreeqc_handler, this) != OK) - { - fprintf(stderr, "ERROR: %s\n", - "NULL pointer returned from malloc or realloc."); - fprintf(stderr, "ERROR: %s\n", "Program terminating."); - return -1; - } -#endif - /* * Open input/output files */ @@ -156,8 +124,6 @@ main_method(int argc, char *argv[]) //clean_up(); return errors; } - - /* * Display successful status */ @@ -176,7 +142,6 @@ main_method(int argc, char *argv[]) return 0; } - #ifdef DOS /* ---------------------------------------------------------------------- */ int CLASS_QUALIFIER From e0cbcff713fcaa3bfaa3f52accf9dbbe8c547e9b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 21:57:51 +0000 Subject: [PATCH 0297/1077] CLASS_QUALIFIER is gone, svnid gone removed dead code from PHRQ_io.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5714 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- ReadClass.cxx | 54 +++++++++++++++++++++++++------------------------- class_main.cpp | 4 ++-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 70f13836..61cbca80 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -29,7 +29,7 @@ class cxxNameDouble; #define STATIC #define EXTERNAL -#define CLASS_QUALIFIER Phreeqc:: +//#define Phreeqc:: Phreeqc:: #define CLASS_STATIC static #define extern #include "p2c.h" diff --git a/ReadClass.cxx b/ReadClass.cxx index 4c22fbde..6f3181bc 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -26,7 +26,7 @@ /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_solution_raw(void) /* ---------------------------------------------------------------------- */ { @@ -120,7 +120,7 @@ read_solution_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_exchange_raw(void) /* ---------------------------------------------------------------------- */ { @@ -215,7 +215,7 @@ read_exchange_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_surface_raw(void) /* ---------------------------------------------------------------------- */ { @@ -310,7 +310,7 @@ read_surface_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_equilibrium_phases_raw(void) /* ---------------------------------------------------------------------- */ { @@ -408,7 +408,7 @@ read_equilibrium_phases_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_kinetics_raw(void) /* ---------------------------------------------------------------------- */ { @@ -503,7 +503,7 @@ read_kinetics_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_solid_solutions_raw(void) /* ---------------------------------------------------------------------- */ { @@ -602,7 +602,7 @@ read_solid_solutions_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_gas_phase_raw(void) /* ---------------------------------------------------------------------- */ { @@ -697,7 +697,7 @@ read_gas_phase_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_reaction_raw(void) /* ---------------------------------------------------------------------- */ { @@ -793,7 +793,7 @@ read_reaction_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_mix_raw(void) /* ---------------------------------------------------------------------- */ { @@ -889,7 +889,7 @@ read_mix_raw(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_temperature_raw(void) /* ---------------------------------------------------------------------- */ { @@ -987,7 +987,7 @@ read_temperature_raw(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_dump(void) /* ---------------------------------------------------------------------- */ { @@ -1039,7 +1039,7 @@ read_dump(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_delete(void) /* ---------------------------------------------------------------------- */ { @@ -1091,7 +1091,7 @@ read_delete(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_run_cells(void) /* ---------------------------------------------------------------------- */ { @@ -1143,7 +1143,7 @@ read_run_cells(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_solution_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1242,7 +1242,7 @@ read_solution_modify(void) } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_equilibrium_phases_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1335,7 +1335,7 @@ read_equilibrium_phases_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_exchange_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1445,7 +1445,7 @@ read_exchange_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_surface_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1535,7 +1535,7 @@ read_surface_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_solid_solutions_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1625,7 +1625,7 @@ read_solid_solutions_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_gas_phase_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1713,7 +1713,7 @@ read_gas_phase_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_kinetics_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1803,7 +1803,7 @@ read_kinetics_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_reaction_modify(void) /* ---------------------------------------------------------------------- */ { @@ -1891,7 +1891,7 @@ read_reaction_modify(void) return (return_value); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: streamify_to_next_keyword(std::istringstream & lines) /* ---------------------------------------------------------------------- */ { @@ -1938,7 +1938,7 @@ streamify_to_next_keyword(std::istringstream & lines) return (OPTION_ERROR); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: dump_entities(void) /* ---------------------------------------------------------------------- */ { @@ -1970,7 +1970,7 @@ dump_entities(void) return (OK); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: delete_entities(void) /* ---------------------------------------------------------------------- */ { @@ -2222,7 +2222,7 @@ delete_entities(void) return (OK); } /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: run_as_cells(void) /* ---------------------------------------------------------------------- */ { @@ -2430,7 +2430,7 @@ run_as_cells(void) return (OK); } /* ---------------------------------------------------------------------- */ -void CLASS_QUALIFIER +void Phreeqc:: dump_ostream(std::ostream& os) /* ---------------------------------------------------------------------- */ { @@ -2705,7 +2705,7 @@ dump_ostream(std::ostream& os) } #if defined MULTICHART /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: read_user_graph_handler(void) /* ---------------------------------------------------------------------- */ { diff --git a/class_main.cpp b/class_main.cpp index ea1fa42d..e6a5e6e9 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -44,7 +44,7 @@ main(int argc, char *argv[]) } -int CLASS_QUALIFIER +int Phreeqc:: main_method(int argc, char *argv[]) /* * Main program for PHREEQC @@ -144,7 +144,7 @@ main_method(int argc, char *argv[]) #ifdef DOS /* ---------------------------------------------------------------------- */ -int CLASS_QUALIFIER +int Phreeqc:: write_banner(void) /* ---------------------------------------------------------------------- */ { From 9eb1ba4eec66010bfea15a648b8e83fe772fa905 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 22:18:25 +0000 Subject: [PATCH 0298/1077] Removed EXTERNAL, PITZER_EXTERNAL, and kinetics.h. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5715 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 2 +- Phreeqc.h | 3 --- Utils.cxx | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/NameDouble.h b/NameDouble.h index a6660920..0e590981 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -1,7 +1,7 @@ #if !defined(NAMEDOUBLE_H_INCLUDED) #define NAMEDOUBLE_H_INCLUDED -//#define EXTERNAL extern +//#define extern #include // assert #include // std::map #include // std::string diff --git a/Phreeqc.h b/Phreeqc.h index 61cbca80..73340659 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -28,8 +28,6 @@ #include "PHRQ_io.h" class cxxNameDouble; #define STATIC -#define EXTERNAL -//#define Phreeqc:: Phreeqc:: #define CLASS_STATIC static #define extern #include "p2c.h" @@ -61,7 +59,6 @@ public: Phreeqc(void); ~Phreeqc(void); -#define PITZER_EXTERNAL #include "pitzer.h" #include "input.h" diff --git a/Utils.cxx b/Utils.cxx index e3607b8a..407d24f2 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -9,7 +9,6 @@ #include "Utils.h" #include "Parser.h" -#include "output.h" //////////////////////////////////////////////////////////////////////////// int Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) From de377b66425553fd0cf568f2ed81054221cfe0c6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 22:26:47 +0000 Subject: [PATCH 0299/1077] CLASS_STATIC replaced with static STATIC replaced with empty git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5716 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 1 - Phreeqc.h | 59 ++++++++++++++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/NameDouble.h b/NameDouble.h index 0e590981..1a0d42ea 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -1,7 +1,6 @@ #if !defined(NAMEDOUBLE_H_INCLUDED) #define NAMEDOUBLE_H_INCLUDED -//#define extern #include // assert #include // std::map #include // std::string diff --git a/Phreeqc.h b/Phreeqc.h index 73340659..b717a26b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -27,8 +27,7 @@ #endif #include "PHRQ_io.h" class cxxNameDouble; -#define STATIC -#define CLASS_STATIC static +#define static static #define extern #include "p2c.h" #undef extern @@ -200,7 +199,7 @@ LDBLE sum_match_s_s(const char *stemplate, const char *name); int match_elts_in_species(const char *name, const char *stemplate); int extract_bracket(char **string, char *bracket_string); LDBLE surf_total(const char *total_name, const char *surface_name); -CLASS_STATIC int system_species_compare(const void *ptr1, const void *ptr2); +static int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); @@ -268,9 +267,9 @@ int write_banner(void); public: int close_input_files(void); int close_output_files(void); -//CLASS_STATIC int getc_callback(void *cookie); +//static int getc_callback(void *cookie); #if defined(MERGE_INCLUDE_FILES) -CLASS_STATIC int istream_getc(void *cookie); +static int istream_getc(void *cookie); #endif /* #if defined(MERGE_INCLUDE_FILES) */ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); @@ -989,11 +988,11 @@ int reinitialize(void); int copier_add(struct copier *copier_ptr, int n_user, int start, int end); int copier_free(struct copier *copier_ptr); int copier_init(struct copier *copier_ptr); -CLASS_STATIC int element_compare(const void *ptr1, const void *ptr2); +static int element_compare(const void *ptr1, const void *ptr2); public: struct element *element_store(const char *element); int elt_list_combine(void); - CLASS_STATIC int elt_list_compare(const void *ptr1, const void *ptr2); + static int elt_list_compare(const void *ptr1, const void *ptr2); protected: struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); int elt_list_print(struct elt_list *elt_list_ptr); @@ -1008,7 +1007,7 @@ public: int exchange_copy(struct exchange *exchange_old_ptr, struct exchange *exchange_new_ptr, int n_user_new); protected: -CLASS_STATIC int exchange_compare(const void *ptr1, const void *ptr2); +static int exchange_compare(const void *ptr1, const void *ptr2); int exchange_copy_to_last(int n, int n_user); int exchange_delete(int n_user_old); int exchange_duplicate(int n_user_old, int n_user_new); @@ -1022,12 +1021,12 @@ struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, int n_user_new); struct exchange *exchange_search(int n_user, int *n, int print); int exchange_sort(void); -CLASS_STATIC int gas_comp_compare(const void *ptr1, const void *ptr2); +static int gas_comp_compare(const void *ptr1, const void *ptr2); public: struct gas_phase *gas_phase_alloc(void); struct gas_phase *gas_phase_bsearch(int k, int *n); protected: -CLASS_STATIC int gas_phase_compare(const void *ptr1, const void *ptr2); +static int gas_phase_compare(const void *ptr1, const void *ptr2); public: int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, struct gas_phase *gas_phase_new_ptr, int n_user_new); @@ -1048,7 +1047,7 @@ int gas_phase_sort(void); enum entity_type get_entity_enum(char *name); struct inverse *inverse_alloc(void); int inverse_delete(int i); -CLASS_STATIC int inverse_isotope_compare(const void *ptr1, const void *ptr2); +static int inverse_isotope_compare(const void *ptr1, const void *ptr2); struct inverse *inverse_search(int n_user, int *n); int inverse_sort(void); struct irrev *irrev_bsearch(int k, int *n); @@ -1067,7 +1066,7 @@ protected: int kinetics_delete(int n_user_old); int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, struct kinetics_comp *kinetics_comp_old_ptr); -CLASS_STATIC int kinetics_compare(const void *ptr1, const void *ptr2); +static int kinetics_compare(const void *ptr1, const void *ptr2); public: int kinetics_copy(struct kinetics *kinetics_old_ptr, struct kinetics *kinetics_new_ptr, int n_user_new); @@ -1089,7 +1088,7 @@ int logk_copy2orig(struct logk *logk_ptr); struct logk *logk_store(char *name, int replace_if_found); struct logk *logk_search(char *name); struct master *master_alloc(void); -CLASS_STATIC int master_compare(const void *ptr1, const void *ptr2); +static int master_compare(const void *ptr1, const void *ptr2); int master_delete(char *ptr); public: struct master *master_bsearch(const char *ptr); @@ -1114,14 +1113,14 @@ int pe_data_store(struct pe_data **pe, const char *token); public: struct phase *phase_bsearch(const char *ptr, int *j, int print); protected: -CLASS_STATIC int phase_compare(const void *ptr1, const void *ptr2); +static int phase_compare(const void *ptr1, const void *ptr2); int phase_delete(int i); struct phase *phase_store(char *name); public: struct pp_assemblage *pp_assemblage_alloc(void); struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); protected: -CLASS_STATIC int pp_assemblage_compare(const void *ptr1, const void *ptr2); +static int pp_assemblage_compare(const void *ptr1, const void *ptr2); public: int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, struct pp_assemblage *pp_assemblage_new_ptr, @@ -1142,7 +1141,7 @@ struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage int n_user_new); struct pp_assemblage *pp_assemblage_search(int n_user, int *n); int pp_assemblage_sort(void); -CLASS_STATIC int pure_phase_compare(const void *ptr1, const void *ptr2); +static int pure_phase_compare(const void *ptr1, const void *ptr2); struct rate *rate_bsearch(char *ptr, int *j); int rate_free(struct rate *rate_ptr); struct rate *rate_search(char *name, int *n); @@ -1152,7 +1151,7 @@ struct reaction *rxn_dup(struct reaction *rxn_ptr_old); LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); int rxn_free(struct reaction *rxn_ptr); int rxn_print(struct reaction *rxn_ptr); -CLASS_STATIC int s_compare(const void *ptr1, const void *ptr2); +static int s_compare(const void *ptr1, const void *ptr2); int s_delete(int i); struct species *s_search(const char *name); struct species *s_store(char *name, LDBLE z, int replace_if_found); @@ -1160,7 +1159,7 @@ public: struct s_s_assemblage *s_s_assemblage_alloc(void); struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); protected: -CLASS_STATIC int s_s_assemblage_compare(const void *ptr1, const void *ptr2); +static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); public: int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, struct s_s_assemblage *s_s_assemblage_new_ptr, @@ -1181,14 +1180,14 @@ struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage int n_user_new); struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); int s_s_assemblage_sort(void); -CLASS_STATIC int s_s_compare(const void *ptr1, const void *ptr2); +static int s_s_compare(const void *ptr1, const void *ptr2); struct save_values *save_values_bsearch(struct save_values *k, int *n); -CLASS_STATIC int save_values_compare(const void *ptr1, const void *ptr2); +static int save_values_compare(const void *ptr1, const void *ptr2); int save_values_sort(void); int save_values_store(struct save_values *s_v); -CLASS_STATIC int conc_compare(const void *ptr1, const void *ptr2); +static int conc_compare(const void *ptr1, const void *ptr2); int conc_init(struct conc *conc_ptr); -CLASS_STATIC int isotope_compare(const void *ptr1, const void *ptr2); +static int isotope_compare(const void *ptr1, const void *ptr2); public: struct solution *solution_alloc(void); struct solution *solution_bsearch(int k, int *n, int print); @@ -1204,8 +1203,8 @@ int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); struct solution *solution_replicate(struct solution *solution_old_ptr, int n_user_new); int solution_sort(void); -CLASS_STATIC int species_list_compare_alk(const void *ptr1, const void *ptr2); -CLASS_STATIC int species_list_compare_master(const void *ptr1, const void *ptr2); +static int species_list_compare_alk(const void *ptr1, const void *ptr2); +static int species_list_compare_master(const void *ptr1, const void *ptr2); int species_list_sort(void); struct Change_Surf *change_surf_alloc(int count); public: @@ -1213,11 +1212,11 @@ public: struct surface *surface_bsearch(int k, int *n); protected: struct master *surface_get_psi_master(const char *name, int plane); -CLASS_STATIC int surface_comp_compare(const void *ptr1, const void *ptr2); -CLASS_STATIC int surface_charge_compare(const void *ptr1, const void *ptr2); +static int surface_comp_compare(const void *ptr1, const void *ptr2); +static int surface_charge_compare(const void *ptr1, const void *ptr2); struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); int surface_charge_free(struct surface_charge *charge); -CLASS_STATIC int surface_compare(const void *ptr1, const void *ptr2); +static int surface_compare(const void *ptr1, const void *ptr2); public: int surface_copy(struct surface *surface_old_ptr, struct surface *surface_new_ptr, int n_user_new); @@ -1457,14 +1456,14 @@ protected: int parse_couple(char *token); int print_centered(const char *string); public: -CLASS_STATIC int replace(const char *str1, const char *str2, char *str); +static int replace(const char *str1, const char *str2, char *str); protected: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); int status(int count, const char *str); void str_tolower(char *str); void str_toupper(char *str); -CLASS_STATIC int strcmp_nocase(const char *str1, const char *str2); +static int strcmp_nocase(const char *str1, const char *str2); int strcmp_nocase_arg1(const char *str1, const char *str2); public: char *string_duplicate(const char *token); @@ -1474,7 +1473,7 @@ char *string_pad(char *str, int i); int string_trim(char *str); int string_trim_right(char *str); int string_trim_left(char *str); -CLASS_STATIC LDBLE under(LDBLE xval); +static LDBLE under(LDBLE xval); void zero_double(LDBLE * target, int n); int get_input_errors(void); From be8d41f2a9a7d4ae325e443ff325ac47e9e03208 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 23:50:11 +0000 Subject: [PATCH 0300/1077] removed MERGE_INCLUDE_FILES some static and extern unused static maps git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5717 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.h | 3 --- ISolutionComp.cxx | 29 ----------------------------- NameDouble.h | 8 -------- NumKeyword.h | 2 -- PHRQ_io.cpp | 2 -- PPassemblage.h | 4 ---- Parser.h | 2 -- Phreeqc.h | 17 +++-------------- Reaction.h | 3 --- SSassemblage.h | 3 --- Solution.cxx | 20 +------------------- StorageBin.h | 2 -- Surface.h | 2 -- Temperature.cxx | 1 - Temperature.h | 3 --- class_main.cpp | 13 ++++--------- cxxKinetics.h | 2 -- cxxMix.h | 3 --- 18 files changed, 8 insertions(+), 111 deletions(-) diff --git a/ISolution.h b/ISolution.h index e97c7d56..694d0224 100644 --- a/ISolution.h +++ b/ISolution.h @@ -61,9 +61,6 @@ class cxxISolution:public cxxSolution struct pe_data *pes; int default_pe; - public: - //static std::map& map; - }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index f9e57837..973d9eda 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -42,35 +42,6 @@ cxxISolutionComp::~cxxISolutionComp(void) { } -/* -struct conc *cxxISolutionComp::concarray(std::map &totals) - // for Solutions, not ISolutions - // takes a map of (elt name, moles) - // returns list of conc structures -{ - struct conc *c; - c = (struct conc *) P_INSTANCE_POINTER PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); - if (c == NULL) malloc_error(); - int i = 0; - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = (char *)it->first; - c[i].moles = it->second; - c[i].input_conc = it->second; - c[i].units = NULL; - c[i].equation_name = NULL; - c[i].phase_si = 0.0; - c[i].n_pe = 0; - c[i].as = NULL; - c[i].gfw = 0.0; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return(c); -} -*/ - #ifdef SKIP_OR_MOVE_TO_STRUCTURES struct conc * cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < std::string, diff --git a/NameDouble.h b/NameDouble.h index 1a0d42ea..b1109481 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -70,14 +70,6 @@ class cxxNameDouble:public enum ND_TYPE type; - protected: - - //std::map totals; - - - public: - //static std::map& map; - }; #endif // !defined(NAMEDOUBLE_H_INCLUDED) diff --git a/NumKeyword.h b/NumKeyword.h index 08bae963..192abb99 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -7,8 +7,6 @@ #include "PHRQ_base.h" class CParser; -//extern char *string_duplicate(const char *); - class cxxNumKeyword: public PHRQ_base { public: diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 06d6187f..635f190e 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -1,11 +1,9 @@ #include #include "PHRQ_io.h" -#if defined(MERGE_INCLUDE_FILES) #include #include #include -#endif /* if defined(MERGE_INCLUDE_FILES) */ PHRQ_io:: PHRQ_io(void) diff --git a/PPassemblage.h b/PPassemblage.h index 66ef12a1..41e9d793 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -50,14 +50,10 @@ protected: void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: - //std::list < cxxPPassemblageComp > ppAssemblageComps; std::map ppAssemblageComps; cxxNameDouble eltList; cxxNameDouble totals; -public: - //static std::map& map; - }; #endif // !defined(PPASSEMBLAGE_H_INCLUDED) diff --git a/Parser.h b/Parser.h index a7395959..7b0cd924 100644 --- a/Parser.h +++ b/Parser.h @@ -280,8 +280,6 @@ class CParser: public PHRQ_base STATUS_TYPE parse_couple(std::string & token); - //STATUS_TYPE addPair(std::map < char *, double, CHARSTAR_LESS > &totals, - // std::istream::pos_type & pos); STATUS_TYPE addPair(std::map < std::string, double >&totals, std::istream::pos_type & pos); diff --git a/Phreeqc.h b/Phreeqc.h index b717a26b..29d4d2b3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -27,10 +27,7 @@ #endif #include "PHRQ_io.h" class cxxNameDouble; -#define static static -#define extern #include "p2c.h" -#undef extern #include "global_structures.h" #include "pitzer_structures.h" class cxxKinetics; @@ -267,10 +264,7 @@ int write_banner(void); public: int close_input_files(void); int close_output_files(void); -//static int getc_callback(void *cookie); -#if defined(MERGE_INCLUDE_FILES) static int istream_getc(void *cookie); -#endif /* #if defined(MERGE_INCLUDE_FILES) */ int process_file_names(int argc, char *argv[], void **db_cookie, void **input_cookie, int log); @@ -487,6 +481,8 @@ int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, int set_reaction(int i, int use_mix, int use_kinetics); int set_transport(int i, int use_mix, int use_kinetics, int nsaver); int store_get_equi_reactants(int k, int kin_end); +int count_pp, count_pg, count_s_s; +LDBLE *x0_moles; // mainsubs ------------------------------- @@ -597,12 +593,7 @@ char *prefix_database_dir(char *s); void show_progress(const int type, char *s); #endif public: -//int fileop_handler(const int type, int (*PFN) (FILE *)); -//int open_handler(const int type, const char *file_name); -//int output_handler(const int type, const char *err_str, -// const int stop, void *cookie, const char *format, -// va_list args); -//static int rewind_wrapper(FILE * file_ptr); + void PASCAL_MAIN(int argc, Char **argv); long my_labs(long x); Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); @@ -1487,10 +1478,8 @@ int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); -#if defined(MERGE_INCLUDE_FILES) public: bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); -#endif /* #if defined(MERGE_INCLUDE_FILES) */ public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); diff --git a/Reaction.h b/Reaction.h index 7e292b4f..75a783e7 100644 --- a/Reaction.h +++ b/Reaction.h @@ -46,9 +46,6 @@ protected: bool equalIncrements; std::string units; -public: - //static std::map& map; - }; #endif // !defined(REACTION_H_INCLUDED) diff --git a/SSassemblage.h b/SSassemblage.h index 128c2167..2e781fa7 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -56,9 +56,6 @@ protected: std::map < std::string, cxxSSassemblageSS > ssAssemblageSSs; cxxNameDouble totals; -public: - //static std::map& map; - }; #endif // !defined(SSASSEMBLAGE_H_INCLUDED) diff --git a/Solution.cxx b/Solution.cxx index 12d3d836..5f64b28e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -191,17 +191,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const // soln_total conc structures this->totals.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\""; - s_oss << " conc_moles=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; - } - } - */ + // master_activity map this->master_activity.dump_xml(s_oss, indent + 1); /* @@ -295,14 +285,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con it->dump_raw(s_oss, indent + 2); } } - /* - for (std::map ::const_iterator it = totals.begin(); it != totals.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; - } - */ - - //s_oss << "# Non-critical values" << std::endl; s_oss << indent1; s_oss << "-pH " << this->ph << std::endl; diff --git a/StorageBin.h b/StorageBin.h index 7e090cae..c03441c9 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -123,8 +123,6 @@ class cxxStorageBin: public PHRQ_base std::map < int, cxxReaction > Reactions; std::map < int, cxxTemperature > Temperatures; cxxSystem system; - public: - //static std::map& map; }; diff --git a/Surface.h b/Surface.h index 157b65d9..47d49695 100644 --- a/Surface.h +++ b/Surface.h @@ -71,8 +71,6 @@ protected: bool transport; cxxNameDouble totals; -public: - //static std::map& map; }; #endif // !defined(SURFACE_H_INCLUDED) diff --git a/Temperature.cxx b/Temperature.cxx index 51f54602..629bec9f 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -151,7 +151,6 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxTemperature::read_raw(CParser & parser) { - double d; CParser::TOKEN_TYPE k; static std::vector < std::string > vopts; diff --git a/Temperature.h b/Temperature.h index 76f71ff2..8b220d10 100644 --- a/Temperature.h +++ b/Temperature.h @@ -32,9 +32,6 @@ protected: int countTemps; bool equalIncrements; -public: - //static std::map& map; - }; #endif // !defined(TEMPERATURE_H_INCLUDED) diff --git a/class_main.cpp b/class_main.cpp index e6a5e6e9..ab0deb43 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,6 +1,6 @@ #include "Phreeqc.h" #include "phrqproto.h" -#include "input.h" +//#include "input.h" #include "NameDouble.h" #include "Solution.h" #include "Reaction.h" @@ -96,13 +96,10 @@ main_method(int argc, char *argv[]) /* * Load database into memory */ -#if defined(MERGE_INCLUDE_FILES) this->set_cookie((std::ifstream *) db_cookie); errors = read_database(PHRQ_io::istream_getc, db_cookie); this->clear_cookie(); -#else - errors = read_database(getc_callback, db_cookie); -#endif + if (errors != 0) { //clean_up(); @@ -112,13 +109,11 @@ main_method(int argc, char *argv[]) /* * Read input data for simulation */ -#if defined(MERGE_INCLUDE_FILES) + this->set_cookie((std::ifstream *)input_cookie); errors = run_simulations(PHRQ_io::istream_getc, input_cookie); this->clear_cookie(); -#else - errors = run_simulations(getc_callback, input_cookie); -#endif + if (errors != 0) { //clean_up(); diff --git a/cxxKinetics.h b/cxxKinetics.h index c9e78349..1657a0ee 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -61,8 +61,6 @@ class cxxKinetics:public cxxNumKeyword bool use_cvode; int cvode_steps; int cvode_order; - public: - //static std::map& map; }; diff --git a/cxxMix.h b/cxxMix.h index 1d71ca80..e3ffd4a8 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -52,9 +52,6 @@ class cxxMix:public cxxNumKeyword friend class cxxStorageBin; std::map < int, double >mixComps; - public: - //static std::map& map; - }; #endif // !defined(CXXMIX_H_INCLUDED) From 95aa3278de0158f797ea28ddfb2fa69e0ab9bda9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Oct 2011 23:53:44 +0000 Subject: [PATCH 0301/1077] Removed phrqproto.h from project and svn deleted. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5718 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- ExchComp.cxx | 2 +- Exchange.cxx | 2 +- GasPhase.cxx | 2 +- ISolution.cxx | 2 +- ISolutionComp.cxx | 2 +- KineticsComp.cxx | 2 +- NameDouble.cxx | 2 +- PPassemblage.cxx | 2 +- PPassemblageComp.cxx | 2 +- Reaction.cxx | 2 +- ReadClass.cxx | 2 +- SSassemblage.cxx | 2 +- SSassemblageSS.cxx | 2 +- Solution.cxx | 2 +- SolutionIsotope.cxx | 2 +- SolutionIsotopeList.cxx | 2 +- StorageBin.cxx | 2 +- Surface.cxx | 2 +- SurfaceCharge.cxx | 2 +- SurfaceComp.cxx | 2 +- Temperature.cxx | 2 +- class_main.cpp | 2 +- cxxKinetics.cxx | 2 +- cxxMix.cxx | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 4035d8fa..5ee168ff 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -15,7 +15,7 @@ #include "Phreeqc_class.h" #include "Phreeqc.h" #include "phqalloc.h" -#include "phrqproto.h" + #include "Form1.h" using namespace zdg_ui2; diff --git a/ExchComp.cxx b/ExchComp.cxx index c40d6846..65fd444b 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -14,7 +14,7 @@ #include "ExchComp.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// diff --git a/Exchange.cxx b/Exchange.cxx index ac6d6b58..a3328abc 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -14,7 +14,7 @@ #include "cxxMix.h" #include "Exchange.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/GasPhase.cxx b/GasPhase.cxx index 7f868647..bf10b345 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -13,7 +13,7 @@ #include "GasPhase.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ISolution.cxx b/ISolution.cxx index aa76ea7f..842ccc97 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -12,7 +12,7 @@ #include "Phreeqc.h" #include "ISolution.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 973d9eda..43f1fb72 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -6,7 +6,7 @@ #include "Utils.h" #include "Phreeqc.h" #include "ISolutionComp.h" -#include "phrqproto.h" + #include "phqalloc.h" cxxISolutionComp::cxxISolutionComp(PHRQ_io *io): diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 70ad7773..8144fc8d 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -12,7 +12,7 @@ #include "KineticsComp.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// diff --git a/NameDouble.cxx b/NameDouble.cxx index 0c362d3d..716c1a85 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -14,7 +14,7 @@ #include "NameDouble.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/PPassemblage.cxx b/PPassemblage.cxx index fdb386a2..05a1f136 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -12,7 +12,7 @@ #include "PPassemblage.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 3957e7fe..521474cf 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -12,7 +12,7 @@ #include "PPassemblageComp.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/Reaction.cxx b/Reaction.cxx index 0a5dd657..e57f71ed 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -11,7 +11,7 @@ #include "Phreeqc.h" #include "Reaction.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/ReadClass.cxx b/ReadClass.cxx index 6f3181bc..38d450db 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -22,7 +22,7 @@ #include "runner.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + /* ---------------------------------------------------------------------- */ diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 0e5ae1c4..aeb7480d 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -14,7 +14,7 @@ #include "SSassemblageSS.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index b261ab20..46cb1979 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -12,7 +12,7 @@ #include "SSassemblageSS.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// diff --git a/Solution.cxx b/Solution.cxx index 5f64b28e..4b5c1575 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -18,7 +18,7 @@ #include "Solution.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 6701ffe0..482ef502 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -8,7 +8,7 @@ #include "Phreeqc.h" #include "SolutionIsotope.h" #include "phqalloc.h" -#include "phrqproto.h" + cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io) : diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index b1640d4c..c1bf00d5 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -5,7 +5,7 @@ #include "Phreeqc.h" #include "SolutionIsotopeList.h" #include "phqalloc.h" -#include "phrqproto.h" + cxxSolutionIsotopeList::cxxSolutionIsotopeList(PHRQ_io * io) diff --git a/StorageBin.cxx b/StorageBin.cxx index 15273642..a12b660f 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -30,7 +30,7 @@ #include "Reaction.h" #include "Temperature.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/Surface.cxx b/Surface.cxx index 5606efa8..03a488ce 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -12,7 +12,7 @@ #include "Surface.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index b13f17be..bad34a5c 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -12,7 +12,7 @@ #include "SurfaceCharge.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 703cda8c..ebedc5f1 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -12,7 +12,7 @@ #include "SurfaceComp.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/Temperature.cxx b/Temperature.cxx index 629bec9f..078c4785 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -12,7 +12,7 @@ #include "Phreeqc.h" #include "Temperature.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// diff --git a/class_main.cpp b/class_main.cpp index ab0deb43..7ec155c5 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,5 +1,5 @@ #include "Phreeqc.h" -#include "phrqproto.h" + //#include "input.h" #include "NameDouble.h" #include "Solution.h" diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 89341f7a..377096d1 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -14,7 +14,7 @@ #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + #include "PHRQ_io.h" diff --git a/cxxMix.cxx b/cxxMix.cxx index fd2d2e98..2524d5e0 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -12,7 +12,7 @@ #include "Phreeqc.h" #include "cxxMix.h" #include "phqalloc.h" -#include "phrqproto.h" + ////////////////////////////////////////////////////////////////////// From 980e6802414b393e740cbf7d8a77e7072e396440 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Oct 2011 18:24:24 +0000 Subject: [PATCH 0302/1077] removed setjmp except in Basic. Starting to cleanup header files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5719 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.h | 1 - NumKeyword.h | 1 - Phreeqc.h | 1 - class_main.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/ISolution.h b/ISolution.h index 694d0224..2383d797 100644 --- a/ISolution.h +++ b/ISolution.h @@ -12,7 +12,6 @@ #include #include "ISolutionComp.h" -//#include "NumKeyword.h" #include "Solution.h" class cxxISolution:public cxxSolution diff --git a/NumKeyword.h b/NumKeyword.h index 192abb99..de028ee2 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -1,7 +1,6 @@ #if !defined(NUMKEYWORD_H_INCLUDED) #define NUMKEYWORD_H_INCLUDED -//#include "Parser.h" #include // std::ostream #include // std::string #include "PHRQ_base.h" diff --git a/Phreeqc.h b/Phreeqc.h index 29d4d2b3..21cf0d08 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -17,7 +17,6 @@ #include #include #include -#include #include "phrqtype.h" #include "cvdense.h" #include "runner.h" diff --git a/class_main.cpp b/class_main.cpp index 7ec155c5..928dcfcc 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,6 +1,5 @@ #include "Phreeqc.h" -//#include "input.h" #include "NameDouble.h" #include "Solution.h" #include "Reaction.h" From 3837362987c24b8809b252cdcf8c7baed931bfa6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Oct 2011 19:39:08 +0000 Subject: [PATCH 0303/1077] phreeqc_class header needed. Stripped Local and Static from basic.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5720 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.h | 1 + PPassemblageComp.cxx | 1 + 2 files changed, 2 insertions(+) diff --git a/PPassemblage.h b/PPassemblage.h index 41e9d793..b12ed407 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -9,6 +9,7 @@ #include "NumKeyword.h" #include "PPassemblageComp.h" +#include "phreeqc_class.h" class cxxMix; class cxxPPassemblage:public cxxNumKeyword diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 521474cf..c538ac72 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -12,6 +12,7 @@ #include "PPassemblageComp.h" #include "Dictionary.h" #include "phqalloc.h" +#include "phreeqc_class.h" ////////////////////////////////////////////////////////////////////// From 21da7bae55f736b97f7eb85072a9d02982fd2c3c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 23 Oct 2011 14:07:05 +0000 Subject: [PATCH 0304/1077] Renamed output_temp_ to output_. Guarded use of *phrq_io for NULL. Changed PHRQ_io error_msg to write only to error file. PHRQ_base error message writes to output, log, and error. PHRQ_io_output writes to output, log, and error. Just 4 configurations git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5721 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 14 +++++++++----- PHRQ_io.cpp | 35 ++++++++++++++++++----------------- PHRQ_io.h | 12 ++++++------ Phreeqc.h | 14 +++++++------- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 92254a05..2b3048de 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -24,15 +24,19 @@ void PHRQ_base:: error_msg(const std::string & stdstr, int stop) { this->base_error_count++; + std::ostringstream msg; + msg << "\nERROR: " << stdstr << std::endl; if (this->io) { -// this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_ERROR, stdstr.c_str(), stop!=0, "", NULL); - this->io->error_msg(stdstr.c_str(), stop!=0); + + this->io->output_msg(msg.str().c_str()); + this->io->log_msg(msg.str().c_str()); + this->io->error_msg(msg.str().c_str(), stop!=0); } else { - std::cerr << stdstr << std::endl; - std::cout << stdstr << std::endl; + std::cerr << msg.str().c_str() << std::endl; + std::cout << msg.str().c_str() << std::endl; } if (stop != 0) { @@ -61,7 +65,7 @@ output_msg(const std::string & stdstr) if (this->io) { //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); - this->io->output_temp_msg(stdstr.c_str()); + this->io->output_msg(stdstr.c_str()); } else { diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 635f190e..43606e77 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -77,7 +77,7 @@ PHRQ_io::Set_dump_file(FILE * out) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -output_temp_open(const char *file_name) +output_open(const char *file_name) /* ---------------------------------------------------------------------- */ { safe_close(output_file); @@ -89,7 +89,7 @@ output_temp_open(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_temp_fflush(void) +output_fflush(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -99,14 +99,14 @@ output_temp_fflush(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_temp_close(void) +output_close(void) /* ---------------------------------------------------------------------- */ { safe_close(output_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_temp_rewind(void) +output_rewind(void) /* ---------------------------------------------------------------------- */ { if (output_file && output_file_on) @@ -116,7 +116,7 @@ output_temp_rewind(void) } /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -output_temp_isopen(void) +output_isopen(void) /* ---------------------------------------------------------------------- */ { if (output_file) @@ -125,7 +125,7 @@ output_temp_isopen(void) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_temp_msg(const char * str) +output_msg(const char * str) /* ---------------------------------------------------------------------- */ { if (output_file != NULL && output_file_on) @@ -328,19 +328,20 @@ error_msg(const char *err_str, bool stop) io_error_count++; if (error_file != NULL && error_file_on) { - fprintf(error_file, "\nERROR: %s\n", err_str); + //fprintf(error_file, "\nERROR: %s\n", err_str); + fprintf(error_file, "%s", err_str); fflush(error_file); } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "ERROR: %s\n", err_str); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "ERROR: %s\n", err_str); - fflush(log_file); - } + //if (output_file != NULL && output_file_on) + //{ + // fprintf(output_file, "ERROR: %s\n", err_str); + // fflush(output_file); + //} + //if (log_file != NULL && log_file_on) + //{ + // fprintf(log_file, "ERROR: %s\n", err_str); + // fflush(log_file); + //} if (stop) { if (error_file != NULL && error_file_on) diff --git a/PHRQ_io.h b/PHRQ_io.h index e241d01a..ad3472c0 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -20,12 +20,12 @@ public: int close_output_files(void); // output_file - bool output_temp_open(const char *file_name); - void output_temp_fflush(void); - void output_temp_close(void); - void output_temp_rewind(void); - bool output_temp_isopen(void); - void output_temp_msg(const char * str); + bool output_open(const char *file_name); + void output_fflush(void); + void output_close(void); + void output_rewind(void); + bool output_isopen(void); + void output_msg(const char * str); // log_file bool log_open(const char *file_name); diff --git a/Phreeqc.h b/Phreeqc.h index 21cf0d08..7d87a8be 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -298,13 +298,13 @@ void error_rewind(void); bool error_isopen(void); void error_msg(const char * str, bool stop=false); -// output_temp_file -bool output_temp_open(const char *file_name); -void output_temp_fflush(void); -void output_temp_close(void); -void output_temp_rewind(void); -bool output_temp_isopen(void); -void output_temp_msg(const char * str); +// output_file +bool output_open(const char *file_name); +void output_fflush(void); +void output_close(void); +void output_rewind(void); +bool output_isopen(void); +void output_msg(const char * str); // punch_file bool punch_open(const char *file_name); From cc03f8d1b6e980f98d9d4e8d21c055b32ae603e2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 23 Oct 2011 14:10:44 +0000 Subject: [PATCH 0305/1077] QBasic git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5722 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- QBasic/Phreeqc.h | 1505 +++++++++ QBasic/QBasic.cpp | 6050 ++++++++++++++++++++++++++++++++++++ QBasic/QBasic.h | 486 +++ QBasic/global.h | 808 +++++ QBasic/global_structures.h | 1375 ++++++++ 5 files changed, 10224 insertions(+) create mode 100644 QBasic/Phreeqc.h create mode 100644 QBasic/QBasic.cpp create mode 100644 QBasic/QBasic.h create mode 100644 QBasic/global.h create mode 100644 QBasic/global_structures.h diff --git a/QBasic/Phreeqc.h b/QBasic/Phreeqc.h new file mode 100644 index 00000000..bcab34c0 --- /dev/null +++ b/QBasic/Phreeqc.h @@ -0,0 +1,1505 @@ +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +/* ---------------------------------------------------------------------- + * INCLUDE FILES + * ---------------------------------------------------------------------- */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "cvdense.h" +#include "runner.h" +#include "dumper.h" +#ifdef MULTICHART +#include "ChartHandler.h" +#endif +#include "PHRQ_io.h" +class cxxNameDouble; +//#include "p2c.h" +#include "global_structures.h" +#include "pitzer_structures.h" +class cxxKinetics; +class cxxMix; +class cxxKineticsComp; +class cxxExchange; +class cxxExchComp; +class cxxGasPhase; +class cxxTemperature; +class cxxPPassemblage; +class cxxPPassemblageComp; +class cxxReaction; +class cxxSolution; +class cxxSolutionIsotopeList; +class cxxSSassemblage; +class cxxSSassemblageSS; +class cxxSurface; +class cxxSurfaceCharge; +class cxxSurfaceComp; +class cxxStorageBin; + +class Phreeqc +{ +public: + Phreeqc(void); + ~Phreeqc(void); + +#include "pitzer.h" +#include "input.h" + +public: +#include "global.h" +/* + All functions are included as methods here +*/ +#define _INC_PHRQPROTO_H + +// advection.c ------------------------------- + +int advection(void); + +// basic.c ------------------------------- + +//int basic_main(char *commands); +//void cmd_initialize(void); +//void cmd_free(void); +//int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +//int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +//int basic_init(void); +//#ifdef PHREEQ98 +//void GridChar(char *s, char *a); +//#endif +//int sget_logical_line(char **ptr, int *l, char *return_line); +//int free_dim_stringvar(varrec *varbase); +//void exec(void); +//int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); +//void restoredata(void); +//void clearloops(void); +//void clearvar(varrec * v); +//void clearvars(void); +//Char * numtostr(Char * Result, LDBLE n); +//void parse(Char * inbuf, tokenrec ** buf); +//void listtokens(FILE * f, tokenrec * buf); +//void disposetokens(tokenrec ** tok); +//void parseinput(tokenrec ** buf); +//void errormsg(const Char * s); +//void snerr(const Char * s); +//void tmerr(const Char * s); +//void badsubscr(void); +//LDBLE realfactor(struct LOC_exec *LINK); +//Char * strfactor(struct LOC_exec * LINK); +//Char *stringfactor(Char * Result, struct LOC_exec *LINK); +//long intfactor(struct LOC_exec *LINK); +//LDBLE realexpr(struct LOC_exec *LINK); +//Char * strexpr(struct LOC_exec * LINK); +//Char * stringexpr(Char * Result, struct LOC_exec * LINK); +//long intexpr(struct LOC_exec *LINK); +//void require(int k, struct LOC_exec *LINK); +//void skipparen(struct LOC_exec *LINK); +//varrec * findvar(struct LOC_exec *LINK); +//valrec factor(struct LOC_exec *LINK); +//valrec upexpr(struct LOC_exec * LINK); +//valrec term(struct LOC_exec * LINK); +//valrec sexpr(struct LOC_exec * LINK); +//valrec relexpr(struct LOC_exec * LINK); +//valrec andexpr(struct LOC_exec * LINK); +//valrec expr(struct LOC_exec *LINK); +//void checkextra(struct LOC_exec *LINK); +//boolean iseos(struct LOC_exec *LINK); +//void skiptoeos(struct LOC_exec *LINK); +//linerec * findline(long n); +//linerec * mustfindline(long n); +//void cmdend(struct LOC_exec *LINK); +//void cmdnew(struct LOC_exec *LINK); +//void cmdlist(struct LOC_exec *LINK); +//void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); +//void cmdrun(struct LOC_exec *LINK); +//void cmdsave(struct LOC_exec *LINK); +//void cmdput(struct LOC_exec *LINK); +//void cmdchange_por(struct LOC_exec *LINK); +//void cmdchange_surf(struct LOC_exec *LINK); +//void cmdbye(void); +//void cmddel(struct LOC_exec *LINK); +//void cmdrenum(struct LOC_exec *LINK); +//void cmdprint(struct LOC_exec *LINK); +//void cmdpunch(struct LOC_exec *LINK); +//#if defined PHREEQ98 || defined MULTICHART +//void cmdgraph_x(struct LOC_exec *LINK); +//void cmdgraph_y(struct LOC_exec *LINK); +//void cmdgraph_sy(struct LOC_exec *LINK); +//#endif +//#if defined MULTICHART +//void cmdplot_xy(struct LOC_exec *LINK); +//#endif +//void cmdlet(boolean implied, struct LOC_exec *LINK); +//void cmdgoto(struct LOC_exec *LINK); +//void cmdif(struct LOC_exec *LINK); +//void cmdelse(struct LOC_exec *LINK); +//boolean skiploop(int up, int dn, struct LOC_exec *LINK); +//void cmdfor(struct LOC_exec *LINK); +//void cmdnext(struct LOC_exec *LINK); +//void cmdwhile(struct LOC_exec *LINK); +//void cmdwend(struct LOC_exec *LINK); +//void cmdgosub(struct LOC_exec *LINK); +//void cmdreturn(struct LOC_exec *LINK); +//void cmdread(struct LOC_exec *LINK); +//void cmddata(struct LOC_exec *LINK); +//void cmdrestore(struct LOC_exec *LINK); +//void cmdgotoxy(struct LOC_exec *LINK); +//void cmdon(struct LOC_exec *LINK); +//void cmddim(struct LOC_exec *LINK); +//void cmdpoke(struct LOC_exec *LINK); + +// basicsubs.c ------------------------------- + +LDBLE activity(const char *species_name); +LDBLE activity_coefficient(const char *species_name); +LDBLE log_activity_coefficient(const char *species_name); +LDBLE calc_SC(void); +/* VP: Density Start */ +LDBLE calc_dens(void); +/* VP: Density End */ +LDBLE calc_logk_n(const char *name); +LDBLE calc_logk_p(const char *name); +LDBLE calc_logk_s(const char *name); +LDBLE calc_surface_charge(const char *surface_name); +LDBLE diff_layer_total(const char *total_name, const char *surface_name); +LDBLE equi_phase(const char *phase_name); +LDBLE find_gas_comp(const char *gas_comp_name); +LDBLE find_misc1(const char *s_s_name); +LDBLE find_misc2(const char *s_s_name); +LDBLE find_s_s_comp(const char *s_s_comp_name); +LDBLE get_calculate_value(const char *name); +char * iso_unit(const char *total_name); +LDBLE iso_value(const char *total_name); +LDBLE kinetics_moles(const char *kinetics_name); +LDBLE log_activity(const char *species_name); +LDBLE log_molality(const char *species_name); +LDBLE molality(const char *species_name); +LDBLE saturation_ratio(const char *phase_name); +int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); +LDBLE solution_sum_secondary(const char *total_name); +LDBLE sum_match_gases(const char *stemplate, const char *name); +LDBLE sum_match_species(const char *stemplate, const char *name); +LDBLE sum_match_s_s(const char *stemplate, const char *name); +int match_elts_in_species(const char *name, const char *stemplate); +int extract_bracket(char **string, char *bracket_string); +LDBLE surf_total(const char *total_name, const char *surface_name); +static int system_species_compare(const void *ptr1, const void *ptr2); +LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); +std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); +LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); +int system_total_elements(void); +int system_total_si(void); +int system_total_aq(void); +int system_total_ex(void); +int system_total_surf(void); +int system_total_gas(void); +int system_total_s_s(void); +int system_total_elt(const char *total_name); +int system_total_elt_secondary(const char *total_name); +LDBLE total(const char *total_name); +LDBLE total_mole(const char *total_name); +int system_total_solids(struct exchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr); + +static LDBLE f_rho(LDBLE rho_old, void *cookie); + +// chart.cpp +#if defined PHREEQ98 +void DeleteCurves(void); +void ExtractCurveInfo(char *line, int curvenr); +void GridChar(char *s, char *a); +void MallocCurves(int nc, int ncxy); +int OpenCSVFile(char file_name[MAX_LENGTH]); +void SaveCurvesToFile(char file_name[MAX_LENGTH]); +void PlotXY(char *x, char *y); +void ReallocCurves(int new_nc); +void ReallocCurveXY(int i); +void SetAxisScale(char *a, int j, char *token, int true_); +void SetAxisTitles(char *s, int i); +void SetChartTitle(char *s); +void start_chart(bool end); +#endif +// cl1.c ------------------------------- +int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); +void cl1_space(int check, int n2d, int klm, int nklmd); + +// cl1mp.c ------------------------------- +int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + + + +// class_main.c ------------------------------- +#ifdef DOS +int write_banner(void); +#endif + +/* default.c */ +public: +int close_input_files(void); +int close_output_files(void); +static int istream_getc(void *cookie); +int process_file_names(int argc, char *argv[], void **db_cookie, + void **input_cookie, int log); + +/* PHRQ_io_output.cpp */ +void screen_msg(const char *err_str); +void echo_msg(const char *err_str); +int warning_msg(const char *err_str); +void set_forward_output_to_log(int value); +int get_forward_output_to_log(void); + +// dump_file +bool dump_open(const char *file_name); +void dump_fflush(void); +void dump_close(void); +void dump_rewind(void); +bool dump_isopen(void); +void dump_msg(const char * str); + +// log_file +bool log_open(const char *file_name); +void log_fflush(void); +void log_close(void); +void log_rewind(void); +bool log_isopen(void); +void log_msg(const char * str); + +// error_file +bool error_open(const char *file_name); +void error_fflush(void); +void error_close(void); +void error_rewind(void); +bool error_isopen(void); +void error_msg(const char * str, bool stop=false); + +// output_temp_file +bool output_temp_open(const char *file_name); +void output_temp_fflush(void); +void output_temp_close(void); +void output_temp_rewind(void); +bool output_temp_isopen(void); +void output_temp_msg(const char * str); + +// punch_file +bool punch_open(const char *file_name); +void punch_fflush(void); +void punch_close(void); +void punch_rewind(void); +bool punch_isopen(void); +void punch_msg(const char * str); + +void fpunchf_heading(const char *name); +void fpunchf(const char *name, const char *format, double d); +void fpunchf(const char *name, const char *format, char * d); +void fpunchf(const char *name, const char *format, int d); +void fpunchf_user(int user_index, const char *format, double d); +void fpunchf_user(int user_index, const char *format, char * d); +int fpunchf_end_row(const char *format); + +// dw.c ------------------------------- +int BB(LDBLE T); +LDBLE PS(LDBLE T); +LDBLE VLEST(LDBLE T); +int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); +int QQ(LDBLE T, LDBLE D); +LDBLE BASE(LDBLE D); + +// input.c ------------------------------- + +int reading_database(void); +struct read_callback s_read_callback; +int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + +// integrate.c ------------------------------- + +int calc_all_g(void); +int calc_init_g(void); +int initial_surface_water(void); +int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); +int calc_all_donnan(void); +int calc_init_donnan(void); +LDBLE g_function(LDBLE x_value); +LDBLE midpnt(LDBLE x1, LDBLE x2, int n); +void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); +LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); +LDBLE calc_psi_avg(LDBLE surf_chrg_eq); +int calc_all_donnan_music(void); +int calc_init_donnan_music(void); + +// inverse.c ------------------------------- + +int inverse_models(void); +int add_to_file(const char *filename, char *string); +int bit_print(unsigned long bits, int l); +int carbon_derivs(struct inverse *inv_ptr); +int check_isotopes(struct inverse *inv_ptr); +int check_solns(struct inverse *inv_ptr); +int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); +struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); +struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); +int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); +int post_mortem(void); +unsigned long get_bits(unsigned long bits, int position, int number); +unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); +void dump_netpath(struct inverse *inv_ptr); +int dump_netpath_pat(struct inverse *inv_ptr); +int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); +int phase_isotope_inequalities(struct inverse *inv_ptr); +int print_model(struct inverse *inv_ptr); +int punch_model_heading(struct inverse *inv_ptr); +int punch_model(struct inverse *inv_ptr); +void print_isotope(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); +void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); +void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); +int range(struct inverse *inv_ptr, unsigned long cur_bits); +int save_bad(unsigned long bits); +int save_good(unsigned long bits); +int save_minimal(unsigned long bits); +unsigned long set_bit(unsigned long bits, int position, int value); +int setup_inverse(struct inverse *inv_ptr); +int set_initial_solution(int n_user_old, int n_user_new); +int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *soln_ptr_orig, + int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); +int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); +int solve_inverse(struct inverse *inv_ptr); +int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); +int subset_bad(unsigned long bits); +int subset_minimal(unsigned long bits); +int superset_minimal(unsigned long bits); +int write_optimize_names(struct inverse *inv_ptr); + +// isotopes.c ------------------------------- + +int add_isotopes(struct solution *solution_ptr); +int calculate_values(void); +int calculate_isotope_moles(struct element *elt_ptr, + struct solution *solution_ptr, LDBLE total_moles); +LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); +int from_pcil(struct master_isotope *master_isotope_ptr); +int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); +int from_tu(struct master_isotope *master_isotope_ptr); +struct calculate_value *calculate_value_alloc(void); +int calculate_value_free(struct calculate_value *calculate_value_ptr); +struct calculate_value *calculate_value_search(const char *name); +struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); +struct isotope_alpha *isotope_alpha_alloc(void); +struct isotope_alpha *isotope_alpha_search(const char *name); +struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); +struct isotope_ratio *isotope_ratio_alloc(void); +struct isotope_ratio *isotope_ratio_search(const char *name); +struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); +struct master_isotope *master_isotope_alloc(void); +struct master_isotope *master_isotope_search(const char *name); +int print_initial_solution_isotopes(void); +int print_isotope_ratios(void); +int print_isotope_alphas(void); +int punch_isotopes(void); +int punch_calculate_values(void); +int read_calculate_values(void); +int read_isotopes(void); +int read_isotope_ratios(void); +int read_isotope_alphas(void); +int calculate_value_init(struct calculate_value *calculate_value_ptr); +int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); +int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); +int master_isotope_init(struct master_isotope *master_isotope_ptr); + +// kinetics.c ------------------------------- + +void cvode_init(void); +int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); +int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); +int set_advection(int i, int use_mix, int use_kinetics, int nsaver); +int free_cvode(void); +public: +static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + +int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); +int calc_kinetic_reaction(struct kinetics *kinetics_ptr, + LDBLE time_step); +int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); +int set_reaction(int i, int use_mix, int use_kinetics); +int set_transport(int i, int use_mix, int use_kinetics, int nsaver); +int store_get_equi_reactants(int k, int kin_end); +int count_pp, count_pg, count_s_s; +LDBLE *x0_moles; + +// mainsubs ------------------------------- + +FILE *file_open(char *query, char *default_name, const char *status, + int batch); +int copy_entities(void); +void initialize(void); +int initial_exchangers(int print); +int initial_gas_phases(int print); +int initial_solutions(int print); +int step_save_exch(int n_user); +int step_save_surf(int n_user); +int initial_surfaces(int print); +int reactions(void); +int saver(void); +int xsolution_save(int k_user); +int xexchange_save(int n_user); +int xgas_save(int n_user); +int xpp_assemblage_save(int n_user); +int xs_s_assemblage_save(int n_user); +int xsurface_save(int n_user); +int do_initialize(void); +int do_status(void); +void save_init(int i); +void use_init(void); + +int copy_use(int i); +int set_use(void); + +// model.c ------------------------------- + +int check_residuals(void); +int free_model_allocs(void); +int ineq(int kode); +int model(void); +int jacobian_sums(void); +int mb_gases(void); +int mb_s_s(void); +int mb_sums(void); +int molalities(int allow_overflow); +int reset(void); +int residuals(void); +int set(int initial); +int sum_species(void); +int surface_model(void); + +LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); +LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); +LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); +int numerical_jacobian(void); +void set_inert_moles(void); +void unset_inert_moles(void); +#ifdef SLNQ +int add_trivial_eqns(int rows, int cols, LDBLE * matrix); +//int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif +int calc_gas_pressures(void); +int calc_s_s_fractions(void); +int gammas(LDBLE mu); +int initial_guesses(void); +int revise_guesses(void); +int s_s_binary(struct s_s *s_s_ptr); +int s_s_ideal(struct s_s *s_s_ptr); +//int remove_unstable_phases; +int gas_in; +void ineq_init(int max_row_count, int max_column_count); + +// output.c ------------------------------- + +// parse.c ------------------------------- + +int check_eqn(int association); +int get_charge(char *charge, LDBLE * z); +int get_elt(char **t_ptr, char *element, int *i); +int get_elts_in_species(char **t_ptr, LDBLE coef); +int get_num(char **t_ptr, LDBLE * num); +int get_secondary_in_species(char **t_ptr, LDBLE coef); +int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + +int get_coef(LDBLE * coef, char **eqnaddr); +int get_secondary(char **t_ptr, char *element, int *i); +int get_species(char **ptr); + +// phqalloc.c ------------------------------- +public: +#if !defined(NDEBUG) +void *PHRQ_malloc(size_t, const char *, int); +void *PHRQ_calloc(size_t, size_t, const char *, int); +void *PHRQ_realloc(void *, size_t, const char *, int); +#else +void *PHRQ_malloc(size_t); +void *PHRQ_calloc(size_t, size_t); +void *PHRQ_realloc(void *, size_t); +#endif +void PHRQ_free(void *ptr); + +void PHRQ_free_all(void); +protected: + +// phreeqc_files.c ------------------------------- + +#ifdef PHREEQ98 +void check_line_breaks(char *s); +char *prefix_database_dir(char *s); +void show_progress(const int type, char *s); +#endif +public: + +//void PASCAL_MAIN(int argc, Char **argv); +//long my_labs(long x); +//Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); +//Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); +//int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); +//Anyptr my_memset(Anyptr d, int c, size_t n); +//int my_toupper(int c); +//int my_tolower(int c); +//long ipow(long a, long b); +//char * strsub(register char *ret, register char *s, register int pos, +// register int len); +//int strpos2(char *s, register char *pat, register int pos); +//int strcicmp(register char *s1, register char *s2); +//char * strltrim(register char *s); +//char * strrtrim(register char *s); +//void strmove(register int len, register char *s, register int spos, +// register char *d, register int dpos); +//void strinsert(register char *src, register char *dst, register int pos); +//int P_peek(FILE * f); +//int P_eof(void); +//int P_eoln(FILE * f); +//void P_readpaoc(FILE * f, char *s, int len); +//void P_readlnpaoc(FILE * f, char *s, int len); +//long P_maxpos(FILE * f); +//Char * P_trimname(register Char * fn, register int len); +//long memavail(void); +//long maxavail(void); +//long * P_setunion(register long *d, register long *s1, register long *s2); +//long * P_setint(register long *d, register long *s1, register long *s2); +//long * P_setdiff(register long *d, register long *s1, register long *s2); +//long * P_setxor(register long *d, register long *s1, register long *s2); +//long * P_addset(register long *s, register unsigned val); +//long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); +//long * P_remset(register long *s, register unsigned val); +//int P_setequal(register long *s1, register long *s2); +//int P_subset(register long *s1, register long *s2); +//long * P_setcpy(register long *d, register long *s); +//long * P_expset(register long *d, register long s); +//long P_packset(register long *s); +//int _OutMem(void); +//int _CaseCheck(void); +//int _NilCheck(void); +//static char * _ShowEscape(char *buf, int code, int ior, char *prefix); +//int _Escape(int code); +//int _EscIO(int code); + +// pitzer.c ------------------------------- + +int gammas_pz(void); +int model_pz(void); +int pitzer(void); +int pitzer_clean_up(void); +int pitzer_init(void); +int pitzer_tidy(void); +int read_pitzer(void); +int set_pz(int initial); + +int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_pz(void); +int ISPEC(char *name); +LDBLE G(LDBLE Y); +LDBLE GP(LDBLE Y); +int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); +int BDK(LDBLE X); +int pitzer_initial_guesses(void); +int pitzer_revise_guesses(void); +int PTEMP(LDBLE TK); +LDBLE JAY(LDBLE X); +LDBLE JPRIME(LDBLE Y); +int jacobian_pz(void); + +// pitzer_structures.c ------------------------------- + +struct pitz_param *pitz_param_alloc(void); +int pitz_param_init(struct pitz_param *pitz_param_ptr); +struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); +int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + +// pitzer_structures.c ------------------------------- + +int add_potential_factor(void); +int add_cd_music_factors(int n); +int add_surface_charge_balance(void); +int add_cd_music_charge_balances(int i); +int build_gas_phase(void); +int build_jacobian_sums(int k); +int build_mb_sums(void); +int build_min_exch(void); +int build_model(void); +int build_pure_phases(void); +int build_s_s_assemblage(void); +int build_solution_phase_boundaries(void); +int build_species_list(int n); +int build_min_surface(void); +int change_hydrogen_in_elt_list(LDBLE charge); +int clear(void); +int convert_units(struct solution *solution_ptr); +struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); +struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); +int inout(void); +int is_special(struct species *spec); +int mb_for_species_aq(int n); +int mb_for_species_ex(int n); +int mb_for_species_surf(int n); +int quick_setup(void); +int resetup_master(void); +int save_model(void); +int setup_exchange(void); +int setup_gas_phase(void); +int setup_master_rxn(struct master **master_ptr_list, + struct reaction **pe_rxn); +int setup_pure_phases(void); +int setup_related_surface(void); +int setup_s_s_assemblage(void); +int setup_solution(void); +int setup_surface(void); +int setup_unknowns(void); +int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); +int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); +int store_jacob0(int row, int column, LDBLE coef); +int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); +int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); +int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); +int tidy_redox(void); +struct master **unknown_alloc_master(void); +int write_mb_eqn_x(void); +int write_mb_for_species_list(int n); +int write_mass_action_eqn_x(int stop); + +/* prep.c */ + +int check_same_model(void); +int k_temp(LDBLE tc); +LDBLE k_calc(LDBLE * logk, LDBLE tempk); +int prep(void); +int reprep(void); +int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); +int switch_bases(void); +int write_phase_sys_total(int n); + +// print.c ------------------------------- +char *sformatf(const char *format, ...); +int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); +int print_all(void); +int print_exchange(void); +int print_gas_phase(void); +int print_master_reactions(void); +int print_reaction(struct reaction *rxn_ptr); +int print_species(void); +int print_surface(void); +int print_user_print(void); +int punch_all(void); + +int print_alkalinity(void); +int print_diffuse_layer(struct surface_charge *surface_charge_ptr); +int print_eh(void); +int print_irrev(void); +int print_kinetics(void); +int print_mix(void); +int print_pp_assemblage(void); +int print_s_s_assemblage(void); +int print_saturation_indices(void); +int print_surface_cd_music(void); +int print_totals(void); +int print_using(void); +/*int print_user_print(void);*/ +int punch_gas_phase(void); +int punch_identifiers(void); +int punch_kinetics(void); +int punch_molalities(void); +int punch_activities(void); +int punch_pp_assemblage(void); +int punch_s_s_assemblage(void); +int punch_saturation_indices(void); +int punch_totals(void); +int punch_user_punch(void); +#if defined PHREEQ98 || defined MULTICHART +int punch_user_graph(void); +#endif + +// read.c ------------------------------- + +int read_input(void); +int read_conc(int n, int count_mass_balance, char *str); +int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); +int read_log_k_only(char *ptr, LDBLE * log_k); +int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description, int allow_negative=FALSE); +int check_key(char *str); +int check_units(char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print); +int find_option(char *item, int *n, const char **list, int count_list, + int exact); +int get_option(const char **opt_list, int count_opt_list, char **next_char); +int get_true_false(char *string, int default_value); + +int add_psi_master_species(char *token); +int read_advection(void); +int read_analytical_expression_only(char *ptr, LDBLE * log_k); +/* VP: Density Start */ +int read_millero_abcdef (char *ptr, LDBLE * abcdef); +/* VP: Density End */ +int read_copy(void); +int read_debug(void); +int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); +int read_llnl_aqueous_model_parameters(void); +int read_exchange(void); +int read_exchange_master_species(void); +int read_exchange_species(void); +int read_gas_phase(void); +int read_incremental_reactions(void); +int read_inverse(void); +int read_inv_balances(struct inverse *inverse_ptr, char *next_char); +int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); +int read_inv_phases(struct inverse *inverse_ptr, char *next_char); +int read_kinetics(void); +int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); +int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); +LDBLE *read_list_doubles(char **ptr, int *count_doubles); +int *read_list_ints(char **ptr, int *count_ints, int positive); +int *read_list_t_f(char **ptr, int *count_ints); +int read_master_species(void); +int read_mix(void); +int read_named_logk(void); +int read_phases(void); +int read_print(void); +int read_pure_phases(void); +int read_rates(void); +int read_reaction(void); +int read_reaction_reactants(struct irrev *irrev_ptr); +int read_reaction_steps(struct irrev *irrev_ptr); +int read_solid_solutions(void); +int read_temperature(void); +int read_reaction_temps(struct temperature *temperature_ptr); +int read_save(void); +int read_selected_output(void); +int read_solution(void); +int read_species(void); +int read_surf(void); +int read_surface_master_species(void); +int read_surface_species(void); +int read_use(void); +int read_title(void); +int read_user_print(void); +int read_user_punch(void); +#if defined PHREEQ98 +int read_user_graph(void); +#endif +#if defined MULTICHART +int read_user_graph_handler(); +#endif +int next_keyword_or_option(const char **opt_list, int count_opt_list); + +// ReadClass.cxx + int read_solution_raw(void); + int read_exchange_raw(void); + int read_surface_raw(void); + int read_equilibrium_phases_raw(void); + int read_kinetics_raw(void); + int read_solid_solutions_raw(void); + int read_gas_phase_raw(void); + int read_reaction_raw(void); + int read_mix_raw(void); + int read_temperature_raw(void); + int read_dump(void); + int read_solution_modify(void); + int read_equilibrium_phases_modify(void); + int read_exchange_modify(void); + int read_surface_modify(void); + int read_solid_solutions_modify(void); + int read_gas_phase_modify(void); + int read_kinetics_modify(void); + int read_reaction_modify(void); + //int read_reaction_temperature_modify(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); + + +// readtr.c ------------------------------- + +int read_transport(void); +int dump(void); +int dump_exchange(int k); +int dump_gas_phase(int k); +int dump_kinetics(int k); +int dump_mix(int k); +int dump_pp_assemblage(int k); +int dump_reaction(int k); +int dump_s_s_assemblage(int k); +int dump_solution(int k); +int dump_surface(int k); +int dump_cpp(void); + +int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + +// sit.c ------------------------------- + +int gammas_sit(void); +int model_sit(void); +int sit(void); +int sit_clean_up(void); +int sit_init(void); +int sit_tidy(void); +int read_sit(void); +int set_sit(int initial); + +int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); +int check_gammas_sit(void); +int sit_ISPEC(char *name); +/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ +int sit_initial_guesses(void); +int sit_revise_guesses(void); +int PTEMP_SIT(LDBLE tk); +int jacobian_sit(void); + +// spread.c ------------------------------- + +int read_solution_spread(void); + +int copy_token_tab(char *token_ptr, char **ptr, int *length); +int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); +int spread_row_free(struct spread_row *spread_row_ptr); +int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); +struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI +void add_row(struct spread_row *spread_row_ptr); +void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); +void free_spread(void); +struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + +// step.c ------------------------------- + +int step(LDBLE step_fraction); +int xsolution_zero(void); +int add_exchange(struct exchange *exchange_ptr); +int add_gas_phase(struct gas_phase *gas_phase_ptr); +int add_kinetics(struct kinetics *kinetics_ptr); +int add_mix(struct mix *mix_ptr); +int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int add_reaction(struct irrev *irrev_ptr, int step_number, + LDBLE step_fraction); +int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); +int add_solution(struct solution *solution_ptr, LDBLE extensive, + LDBLE intensive); +int add_surface(struct surface *surface_ptr); +int add_temperature(struct temperature *temperature_ptr, int step_number); + +int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); +int gas_phase_check(struct gas_phase *gas_phase_ptr); +int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); +int reaction_calc(struct irrev *irrev_ptr); +int solution_check(void); +int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); + +// structures.c ------------------------------- + +int clean_up(void); +int reinitialize(void); +int copier_add(struct copier *copier_ptr, int n_user, int start, int end); +int copier_free(struct copier *copier_ptr); +int copier_init(struct copier *copier_ptr); +static int element_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + static int elt_list_compare(const void *ptr1, const void *ptr2); +protected: +struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); +int elt_list_print(struct elt_list *elt_list_ptr); +struct elt_list *elt_list_save(void); +public: + struct exchange *exchange_alloc(void); + struct exchange *exchange_bsearch(int k, int *n); +protected: +int exchange_comp_compare(const void *ptr1, const void *ptr2); +void exchange_comp_init(struct exch_comp *exch_comp_ptr); +public: + int exchange_copy(struct exchange *exchange_old_ptr, + struct exchange *exchange_new_ptr, int n_user_new); +protected: +static int exchange_compare(const void *ptr1, const void *ptr2); +int exchange_copy_to_last(int n, int n_user); +int exchange_delete(int n_user_old); +int exchange_duplicate(int n_user_old, int n_user_new); +int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, + const char *description); +public: + int exchange_free(struct exchange *exchange_ptr); +protected: +int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); +struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, + int n_user_new); +struct exchange *exchange_search(int n_user, int *n, int print); +int exchange_sort(void); +static int gas_comp_compare(const void *ptr1, const void *ptr2); +public: + struct gas_phase *gas_phase_alloc(void); + struct gas_phase *gas_phase_bsearch(int k, int *n); +protected: +static int gas_phase_compare(const void *ptr1, const void *ptr2); +public: +int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new); +protected: +int gas_phase_copy_to_last(int n, int n_user); +int gas_phase_delete(int n_user_old); +int gas_phase_duplicate(int n_user_old, int n_user_new); +int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, + int n_user_end, char *description); +public: +int gas_phase_free(struct gas_phase *gas_phase_ptr); +int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, + int n_user_new); +struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, + int n_user_new); +struct gas_phase *gas_phase_search(int n_user, int *n); +int gas_phase_sort(void); +enum entity_type get_entity_enum(char *name); +struct inverse *inverse_alloc(void); +int inverse_delete(int i); +static int inverse_isotope_compare(const void *ptr1, const void *ptr2); +struct inverse *inverse_search(int n_user, int *n); +int inverse_sort(void); +struct irrev *irrev_bsearch(int k, int *n); +int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, + int n_user_new); +int irrev_delete(int n_user_old); +int irrev_duplicate(int n_user_old, int n_user_new); +int irrev_free(struct irrev *irrev_ptr); +struct irrev *irrev_search(int n_user, int *n); +int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); +int irrev_sort(void); +public: + struct kinetics *kinetics_alloc(void); + struct kinetics *kinetics_bsearch(int k, int *n); +protected: +int kinetics_delete(int n_user_old); +int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, + struct kinetics_comp *kinetics_comp_old_ptr); +static int kinetics_compare(const void *ptr1, const void *ptr2); +public: +int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new); +protected: +int kinetics_copy_to_last(int n, int n_user); +int kinetics_duplicate(int n_user_old, int n_user_new); +int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, + char *description); +public: +int kinetics_free(struct kinetics *kinetics_ptr); +protected: +int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); +struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, + int n_user_new); +struct kinetics *kinetics_search(int n_user, int *n, int print); +int kinetics_sort(void); +struct logk *logk_alloc(void); +int logk_copy2orig(struct logk *logk_ptr); +struct logk *logk_store(char *name, int replace_if_found); +struct logk *logk_search(char *name); +struct master *master_alloc(void); +static int master_compare(const void *ptr1, const void *ptr2); +int master_delete(char *ptr); +public: +struct master *master_bsearch(const char *ptr); +struct master *master_bsearch_primary(char *ptr); +struct master *master_bsearch_secondary(char *ptr); +struct master *master_search(char *ptr, int *n); +struct mix *mix_bsearch(int k, int *n); +int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new); +int mix_delete(int n_user_old); +int mix_duplicate(int n_user_old, int n_user_new); +int mix_free(struct mix *mix_ptr); +struct mix *mix_search(int n_user, int *n, int print); +int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); +int mix_sort(void); +struct pe_data *pe_data_alloc(void); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +protected: +int pe_data_store(struct pe_data **pe, const char *token); +public: +struct phase *phase_bsearch(const char *ptr, int *j, int print); +protected: +static int phase_compare(const void *ptr1, const void *ptr2); +int phase_delete(int i); +struct phase *phase_store(char *name); +public: +struct pp_assemblage *pp_assemblage_alloc(void); +struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); +protected: +static int pp_assemblage_compare(const void *ptr1, const void *ptr2); +public: +int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, + int n_user_new); +protected: +int pp_assemblage_copy_to_last(int n, int n_user); +int pp_assemblage_delete(int n_user_old); +int pp_assemblage_duplicate(int n_user_old, int n_user_new); +public: +int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); +protected: +int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, + int n_user_end, char *description); +int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, + int n_user_new); +struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage + *pp_assemblage_old_ptr, + int n_user_new); +struct pp_assemblage *pp_assemblage_search(int n_user, int *n); +int pp_assemblage_sort(void); +static int pure_phase_compare(const void *ptr1, const void *ptr2); +struct rate *rate_bsearch(char *ptr, int *j); +int rate_free(struct rate *rate_ptr); +struct rate *rate_search(char *name, int *n); +int rate_sort(void); +struct reaction *rxn_alloc(int ntokens); +struct reaction *rxn_dup(struct reaction *rxn_ptr_old); +LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); +int rxn_free(struct reaction *rxn_ptr); +int rxn_print(struct reaction *rxn_ptr); +static int s_compare(const void *ptr1, const void *ptr2); +int s_delete(int i); +struct species *s_search(const char *name); +struct species *s_store(char *name, LDBLE z, int replace_if_found); +public: + struct s_s_assemblage *s_s_assemblage_alloc(void); + struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); +protected: +static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); +public: + int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, + struct s_s_assemblage *s_s_assemblage_new_ptr, + int n_user_new); +protected: +int s_s_assemblage_copy_to_last(int n, int n_user); +int s_s_assemblage_duplicate(int n_user_old, int n_user_new); +int s_s_assemblage_delete(int n_user_old); +public: + int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); +protected: +int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, + int n_user, int n_user_end, char *description); +int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage + *s_s_assemblage_old_ptr, + int n_user_new); +struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); +int s_s_assemblage_sort(void); +static int s_s_compare(const void *ptr1, const void *ptr2); +public: +struct save_values *save_values_bsearch(struct save_values *k, int *n); +static int save_values_compare(const void *ptr1, const void *ptr2); +int save_values_sort(void); +int save_values_store(struct save_values *s_v); +static int conc_compare(const void *ptr1, const void *ptr2); +int conc_init(struct conc *conc_ptr); +static int isotope_compare(const void *ptr1, const void *ptr2); +public: + struct solution *solution_alloc(void); + struct solution *solution_bsearch(int k, int *n, int print); + struct solution *solution_copy(struct solution *solution_old_ptr, + int n_user_new); +protected: +int solution_copy_to_last(int n, int n_user_new); +int solution_duplicate(int n_user_old, int n_user_new); +int solution_delete(int n_user_old); +int solution_delete_n(int n); +int solution_free(struct solution *solution_ptr); +int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); +struct solution *solution_replicate(struct solution *solution_old_ptr, + int n_user_new); +int solution_sort(void); +static int species_list_compare_alk(const void *ptr1, const void *ptr2); +static int species_list_compare_master(const void *ptr1, const void *ptr2); +int species_list_sort(void); +public: + struct Change_Surf *change_surf_alloc(int count); + struct surface *surface_alloc(void); + struct surface *surface_bsearch(int k, int *n); +protected: +struct master *surface_get_psi_master(const char *name, int plane); +static int surface_comp_compare(const void *ptr1, const void *ptr2); +static int surface_charge_compare(const void *ptr1, const void *ptr2); +struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); +int surface_charge_free(struct surface_charge *charge); +static int surface_compare(const void *ptr1, const void *ptr2); +public: + int surface_copy(struct surface *surface_old_ptr, + struct surface *surface_new_ptr, int n_user_new); +protected: +int surface_copy_to_last(int n, int n_user); +int surface_delete(int n_user_old); +int surface_duplicate(int n_user_old, int n_user_new); +public: + int surface_free(struct surface *surface_ptr); +int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, + char *description); +int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); +struct surface *surface_replicate(struct surface *surface_old_ptr, + int n_user_new); +struct surface *surface_search(int n_user, int *n, int print); +int surface_sort(void); +int system_duplicate(int i, int save_old); +struct temperature *temperature_bsearch(int k, int *n); +int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new); +int temperature_delete(int n_user_old); +int temperature_duplicate(int n_user_old, int n_user_new); +int temperature_free(struct temperature *temperature_ptr); +struct temperature *temperature_search(int n_user, int *n); +int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); +int temperature_sort(void); +int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); +int trxn_combine(void); +int trxn_copy(struct reaction *rxn_ptr); +LDBLE trxn_find_coef(const char *str, int start); +int trxn_print(void); +int trxn_reverse_k(void); +int trxn_sort(void); +int trxn_swap(const char *token); +struct unknown *unknown_alloc(void); +int unknown_delete(int i); +int unknown_free(struct unknown *unknown_ptr); +int entity_exists(char *name, int n_user); + +static int exchange_compare_int(const void *ptr1, const void *ptr2); +static int gas_phase_compare_int(const void *ptr1, const void *ptr2); +static int inverse_compare(const void *ptr1, const void *ptr2); +int inverse_free(struct inverse *inverse_ptr); +static int irrev_compare(const void *ptr1, const void *ptr2); +static int irrev_compare_int(const void *ptr1, const void *ptr2); +static int kinetics_compare_int(const void *ptr1, const void *ptr2); +int logk_init(struct logk *logk_ptr); +static int master_compare_string(const void *ptr1, const void *ptr2); +int master_free(struct master *master_ptr); +static int mix_compare(const void *ptr1, const void *ptr2); +static int mix_compare_int(const void *ptr1, const void *ptr2); +struct phase *phase_alloc(void); +static int phase_compare_string(const void *ptr1, const void *ptr2); +int phase_free(struct phase *phase_ptr); +int phase_init(struct phase *phase_ptr); +static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int rate_compare(const void *ptr1, const void *ptr2); +static int rate_compare_string(const void *ptr1, const void *ptr2); +struct species *s_alloc(void); +int s_free(struct species *s_ptr); +int s_init(struct species *s_ptr); +static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); +static int solution_compare(const void *ptr1, const void *ptr2); +static int solution_compare_int(const void *ptr1, const void *ptr2); +static int species_list_compare(const void *ptr1, const void *ptr2); +static int surface_compare_int(const void *ptr1, const void *ptr2); +static int temperature_compare(const void *ptr1, const void *ptr2); +static int temperature_compare_int(const void *ptr1, const void *ptr2); +static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); +int trxn_multiply(LDBLE coef); +#ifdef PHREEQCI_GUI +extern void free_spread(void); +#endif +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern void MergeFinalize(void); +#endif + +// convert class to struct + +struct mix * cxxMix2mix(const cxxMix *mx); +struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); +struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); +struct exchange * cxxExchange2exchange(const cxxExchange * ex); +struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); +struct master * Get_exch_master(const cxxExchComp * ec); +struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); +struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); +struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); +struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); +struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); +struct irrev * cxxReaction2irrev(const cxxReaction * rxn); +struct solution * cxxSolution2solution(const cxxSolution * sol); +struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); +struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); +struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); +struct surface * cxxSurface2surface(const cxxSurface * surf); +struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); +struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); + +struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); +struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); +struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); +struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); +struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + +void Use2cxxStorageBin(cxxStorageBin & sb); +void phreeqc2cxxStorageBin(cxxStorageBin & sb); +void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); +void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); +void cxxStorageBin2phreeqc(cxxStorageBin & sb); + +/* tally.c */ + +void add_all_components_tally(void); +int build_tally_table(void); +int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); +int diff_tally_table(void); +int extend_tally_table(void); +int free_tally_table(void); +int fill_tally_table(int *n_user, int index_conservative, int n_buffer); +int get_tally_table_rows_columns(int *rows, int *columns); +int get_tally_table_column_heading(int column, int *type, char *string); +int get_tally_table_row_heading(int column, char *string); +int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); +int zero_tally_table(void); + +int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); +int get_all_components(void); +int print_tally_table(void); +int set_reaction_moles(int n_user, LDBLE moles); +int set_reaction_temperature(int n_user, LDBLE tc); +int set_kinetics_time(int n_user, LDBLE step); + +// tidy.c ------------------------------- + +int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); +int add_logks(struct logk *logk_ptr, int repeats); +LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); +int replace_solids_gases(void); +int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); +int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); +int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: +int tidy_punch(void); +int tidy_model(void); + +int check_species_input(void); +LDBLE coef_in_master(struct master *master_ptr); +int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); +int reset_last_model(void); +int rewrite_eqn_to_primary(void); +int rewrite_eqn_to_secondary(void); +int species_rxn_to_trxn(struct species *s_ptr); +int tidy_logk(void); +int tidy_exchange(void); +int tidy_min_exchange(void); +int tidy_kin_exchange(void); +int tidy_gas_phase(void); +int tidy_inverse(void); +int tidy_isotopes(void); +int tidy_isotope_ratios(void); +int tidy_isotope_alphas(void); +int tidy_kin_surface(void); +int tidy_master_isotope(void); +int tidy_min_surface(void); +int tidy_phases(void); +int tidy_pp_assemblage(void); +int tidy_solutions(void); +int tidy_s_s_assemblage(void); +int tidy_species(void); +int tidy_surface(void); +int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); +static LDBLE f_spinodal(LDBLE x, void *); +int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); +int s_s_calc_a0_a1(struct s_s *s_s_ptr); + +// transport.c ------------------------------- + +int transport(void); +int set_initial_moles(int i); +int sum_surface_comp(struct surface *source1, LDBLE f1, + struct surface *source2, int k, LDBLE f2, + struct surface *target, LDBLE new_Dw); +int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, + LDBLE new_Dw, int cell); +LDBLE viscosity(void); + +int multi_D(LDBLE DDt, int mobile_cell, int stagnant); +int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); +int fill_spec(int cell_no); +int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); +static int sort_species_name(const void *ptr1, const void *ptr2); +int disp_surf(LDBLE stagkin_time); +int diff_stag_surf(int mobile_cell); +int check_surfaces(struct surface *surface_ptr1, + struct surface *surface_ptr2); +int mobile_surface_copy(struct surface *surface_old_ptr, + struct surface *surf_ptr1, int n_user_new, + int move_old); +int init_mix(void); +int init_heat_mix(int nmix); +int heat_mix(int heat_nmix); +int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + +// utilities.c ------------------------------- +public: +int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); +protected: +int backspace_screen(int spaces); +LDBLE calc_alk(struct reaction *rxn_ptr); +public: + int compute_gfw(const char *string, LDBLE * gfw); + #if defined PHREEQ98 + int copy_title(char *token_ptr, char **ptr, int *length); + #endif +int copy_token(char *token_ptr, char **ptr, int *length); +int dup_print(const char *ptr, int emphasis); +int equal(LDBLE a, LDBLE b, LDBLE eps); +public: + void *free_check_null(void *ptr); +protected: +void free_hash_strings(HashTable * Table); +int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); +public: +int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); +void hdestroy_multi(HashTable * HashTable_ptr); +ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); +protected: +int islegit(const char c); +public: +void malloc_error(void); +protected: +int parse_couple(char *token); +int print_centered(const char *string); +public: +static int replace(const char *str1, const char *str2, char *str); +protected: +void space(void **ptr, int i, int *max, int struct_size); +void squeeze_white(char *s_l); +int status(int count, const char *str); +public: +void str_tolower(char *str); +void str_toupper(char *str); +static int strcmp_nocase(const char *str1, const char *str2); +int strcmp_nocase_arg1(const char *str1, const char *str2); + + char *string_duplicate(const char *token); + char *string_hsave(const char *str); + +char *string_pad(char *str, int i); +int string_trim(char *str); +int string_trim_right(char *str); +int string_trim_left(char *str); +static LDBLE under(LDBLE xval); +protected: +void zero_double(LDBLE * target, int n); +int get_input_errors(void); + +#ifdef PHREEQ98 +void AddToCEntry(char *a, int l, int i); +void ApplicationProcessMessages(void); +int copy_title(char *token_ptr, char **ptr, int *length); +extern int clean_up_null(void); +#endif +int isamong(char c, const char *s_l); +Address Hash_multi(HashTable * Table, char *Key); +void ExpandTable_multi(HashTable * Table); + +public: + bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); + +public: // public methods for PHREEQC_CLASS + int main_method(int argc, char *argv[]); + void set_phast(int); + size_t list_components(std::list &list_c); + void *get_cookie(); + void pop_cookie(); + void set_cookie(std::istream * cookie); + void clear_cookie(void); +protected: + void init(void); +//Data + std::list cookie_list; + std::ifstream * in_stream; + std::ifstream * db_stream; + +}; +#endif /* _INC_PHREEQC_H */ + diff --git a/QBasic/QBasic.cpp b/QBasic/QBasic.cpp new file mode 100644 index 00000000..e76b876d --- /dev/null +++ b/QBasic/QBasic.cpp @@ -0,0 +1,6050 @@ +#if defined(WIN32) +#include +#endif + +/* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + +#include +#include "QBasic.h" + +#define STOP 1 +#define CONTINUE 0 + +#define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ + + + +/* Output from p2c, the Pascal-to-C translator */ +/* From input file "basic.p" */ + +typedef unsigned char boolean; +#include "phqalloc.h" +#include "NameDouble.h" +void QBasic:: +PASCAL_MAIN(int argc, char **argv) +{ + P_argc = argc; + P_argv = argv; + __top_jb = NULL; + P_escapecode = 0; + P_ioresult = 0; +} +/* ---------------------------------------------------------------------- */ +void QBasic:: +cmd_initialize(void) +/* ---------------------------------------------------------------------- */ +{ + ENTRY item, *found_item; + int i; + char *token; +/* + * create hash table + */ + PhreeqcPtr->hcreate_multi((unsigned) 2 * NCMDS, &command_hash_table); +/* + * fill with commands + */ + for (i = 0; i < NCMDS; i++) + { + token = PhreeqcPtr->string_hsave(command[i].name); + item.key = token; + item.data = (void *) &command[i]; + found_item = PhreeqcPtr->hsearch_multi(command_hash_table, item, ENTER); + if (found_item == NULL) + { + sprintf(PhreeqcPtr->error_string, + "Hash table error in basic commands initialization."); + PhreeqcPtr->error_msg(PhreeqcPtr->error_string, STOP); + } + } + return; +} + +/* ---------------------------------------------------------------------- */ +void QBasic:: +cmd_free(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * destroy hash table + */ + + PhreeqcPtr->hdestroy_multi(command_hash_table); + command_hash_table = NULL; + return; +} + +int QBasic:: +basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main */ + int l; + char *ptr; + + PASCAL_MAIN(0, NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do + { + TRY(try2); + ptr = commands; + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + PHRQ_free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + return (P_escapecode); +} + +int QBasic:: +basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main */ + int l, i; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do + { + TRY(try2); + i = 0; + ptr = commands; + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + i++; + if (i == 1) + { + strcpy(inbuf, "renum"); + } + else if (i == 2) + { + strcpy(inbuf, "list"); + } + else if (i == 3) + { + strcpy(inbuf, "new"); + } + else if (i == 4) + { + strcpy(inbuf, "bye"); + } + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + PHRQ_free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + + return (P_escapecode); +} + +int QBasic:: +basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) +{ /*main */ + int l; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + linebase = (linerec *) lnbase; + varbase = (varrec *) vbase; + loopbase = (looprec *) lpbase; + do + { + TRY(try2); + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + + /* exit(EXIT_SUCCESS); */ + PHRQ_free(inbuf); + return (P_escapecode); +} + +int QBasic:: +basic_main(char *commands) +{ /*main */ + int l; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; +#ifdef SKIP + printf("Chipmunk BASIC 1.0\n\n"); +#endif + exitflag = false; + ptr = commands; + do + { + TRY(try2); + do + { +#ifdef SKIP + putchar('>'); +#endif + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + return 1; +/* exit(EXIT_SUCCESS); */ +} + +/* End. */ +/* ---------------------------------------------------------------------- */ +int QBasic:: +sget_logical_line(char **ptr, int *l, char *return_line) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads file fp until end of line, ";", or eof + * stores characters in line_save + * reallocs line_save and line if more space is needed + * + * returns: + * EOF on empty line on end of file or + * OK otherwise + * *l returns length of line + */ + int i; + char c; + i = 0; + if (**ptr == '\0') + return (EOF); + for (;;) + { + c = **ptr; + if (c == '\0') + break; + (*ptr)++; + if (c == ';' || c == '\n') + break; + return_line[i++] = c; + } + return_line[i] = '\0'; + *l = i; + return (1); +} + void QBasic:: +restoredata(void) +{ + dataline = NULL; + datatok = NULL; +} + + + + void QBasic:: +clearloops(void) +{ + looprec *l; + + while (loopbase != NULL) + { + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + } +} + + + + void QBasic:: +clearvar(varrec * v) +{ + if (v->numdims != 0) + { + if (v->stringvar == 0) + { + PHRQ_free(v->UU.U0.arr); + v->UU.U0.arr = NULL; + } + else + { + free_dim_stringvar(v); + } + } + else if (v->stringvar && v->UU.U1.sv != NULL) + { + PHRQ_free(v->UU.U1.sv); + } + v->numdims = 0; + if (v->stringvar) + { + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } + else + { + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } +} + + + void QBasic:: +clearvars(void) +{ + varrec *v; + + v = varbase; + while (v != NULL) + { + clearvar(v); + v = v->next; + } +} + +char * QBasic:: +numtostr(char * Result, LDBLE n) +{ + /*string255 s; */ + char *l_s; + long i; + + l_s = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (l_s == NULL) + PhreeqcPtr->malloc_error(); + l_s[max_line - 1] = '\0'; +/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ + if (ceil(n) == floor(n)) + { + if (PhreeqcPtr->punch.high_precision == FALSE) + { + sprintf(l_s, "%12g", (double) n); + } + else + { + sprintf(l_s, "%19g", (double) n); + } + } + else + { + if (PhreeqcPtr->punch.high_precision == FALSE) + { + sprintf(l_s, "%12.4e", (double) n); + } + else + { + sprintf(l_s, "%20.12e", (double) n); + } + } + i = (int) strlen(l_s) + 1; + l_s[i - 1] = '\0'; +/* p2c: basic.p, line 237: + * Note: Modification of string length may translate incorrectly [146] */ + strcpy(Result, l_s); + PhreeqcPtr->free_check_null(l_s); + return (Result); +/* } else { + if (PhreeqcPtr->punch.high_precision == FALSE) sprintf(l_s, "%30.10f", n); + else sprintf(l_s, "%30.12f", n); + i = strlen(l_s) + 1; + do { + i--; + } while (l_s[i - 1] == '0'); + if (l_s[i - 1] == '.') + i--; + l_s[i] = '\0'; + * p2c: basic.p, line 248: + * Note: Modification of string length may translate incorrectly [146] * + return strcpy(Result, strltrim(l_s)); + } */ +} + +#define toklength 20 + + +typedef long chset[9]; + + + + + + void QBasic:: +parse(char * l_inbuf, tokenrec ** l_buf) +{ + long i, j, begin, len, m, lp, q; + char token[toklength + 1] = {0}; + tokenrec *t, *tptr; + varrec *v; + char ch; + ENTRY item, *found_item; + char *ptr; + + tptr = NULL; + *l_buf = NULL; + i = 1; + lp = q = 0; + do + { + ch = ' '; + while (i <= (int) strlen(l_inbuf) && (ch == ' ' || ch == '\t')) + { + ch = l_inbuf[i - 1]; + i++; + } + if (ch != ' ') + { + t = (tokenrec *) PHRQ_calloc(1, sizeof(tokenrec)); + if (t == NULL) + PhreeqcPtr->malloc_error(); + if (tptr == NULL) + *l_buf = t; + else + tptr->next = t; + tptr = t; + t->next = NULL; + switch (ch) + { + + case '"': + case '\'': + q += 1; + t->kind = tokstr; + j = 0; + len = (int) strlen(l_inbuf); + begin = i; + while (i <= len && l_inbuf[i - 1] != ch) + { + ++j; + ++i; + } + if (l_inbuf[i - 1] == ch) q -= 1; + m = 256; + if (j + 1 > m) + m = j + 1; + t->UU.sp = (char *) PHRQ_calloc(m, sizeof(char)); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + strncpy(t->UU.sp, l_inbuf + begin - 1, j); + t->UU.sp[j] = '\0'; +/* p2c: basic.p, line 415: + * Note: Modification of string length may translate incorrectly [146] */ + i++; + break; + + case '+': + t->kind = tokplus; + break; + + case '-': + t->kind = tokminus; + break; + + case '*': + t->kind = toktimes; + break; + + case '/': + t->kind = tokdiv; + break; + + case '^': + t->kind = tokup; + break; + + case '(': + case '[': + t->kind = toklp; + lp += 1; + break; + + case ')': + case ']': + t->kind = tokrp; + lp -= 1; + break; + + case ',': + t->kind = tokcomma; + break; + + case ';': + t->kind = toksemi; + break; + + case ':': + t->kind = tokcolon; + break; + + case '?': + t->kind = tokprint; + break; + + case '=': + t->kind = tokeq; + break; + + case '<': + if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') + { + t->kind = tokle; + i++; + } + else if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '>') + { + t->kind = tokne; + i++; + } + else + t->kind = toklt; + break; + + case '>': + if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') + { + t->kind = tokge; + i++; + } + else + t->kind = tokgt; + break; + + default: + if (isalpha((int) ch)) + { + i--; + j = 0; + token[toklength] = '\0'; + while (i <= (int) strlen(l_inbuf) && + (l_inbuf[i - 1] == '$' || l_inbuf[i - 1] == '_' || + isalnum((int) l_inbuf[i - 1]))) + { + if (j < toklength) + { + j++; + token[j - 1] = l_inbuf[i - 1]; + } + i++; + } + token[j] = '\0'; +/* p2c: basic.p, line 309: + * Note: Modification of string length may translate incorrectly [146] */ +#define INT +#ifdef INT +/* + * Search hash list + */ + PhreeqcPtr->str_tolower(token); + item.key = token; + item.data = NULL; + found_item = + PhreeqcPtr->hsearch_multi(command_hash_table, item, FIND); + if (found_item != NULL) + { + t->kind = + ((struct key *) (found_item->data))->keycount; + if (t->kind == tokrem) + { + m = (int) strlen(l_inbuf) + 1; + if (m < 256) + m = 256; + t->UU.sp = (char *) PHRQ_calloc(m, sizeof(char)); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int) (strlen(l_inbuf) - i + 1), + l_inbuf + i - 1); + i = (int) strlen(l_inbuf) + 1; + } +#endif +#ifdef LONG + if (!strcmp(token, "and")) + t->kind = tokand; + else if (!strcmp(token, "or")) + t->kind = tokor; + else if (!strcmp(token, "xor")) + t->kind = tokxor; + else if (!strcmp(token, "not")) + t->kind = toknot; + else if (!strcmp(token, "mod")) + t->kind = tokmod; + else if (!strcmp(token, "sqr")) + t->kind = toksqr; + else if (!strcmp(token, "sqrt")) + t->kind = toksqrt; + else if (!strcmp(token, "ceil")) + t->kind = tokceil; + else if (!strcmp(token, "floor")) + t->kind = tokfloor; + else if (!strcmp(token, "sin")) + t->kind = toksin; + else if (!strcmp(token, "cos")) + t->kind = tokcos; + else if (!strcmp(token, "tan")) + t->kind = toktan; + else if (!strcmp(token, "arctan")) + t->kind = tokarctan; + else if (!strcmp(token, "log")) + t->kind = toklog; + else if (!strcmp(token, "exp")) + t->kind = tokexp; + else if (!strcmp(token, "abs")) + t->kind = tokabs; + else if (!strcmp(token, "sgn")) + t->kind = toksgn; + else if (!strcmp(token, "str$")) + t->kind = tokstr_; + else if (!strcmp(token, "val")) + t->kind = tokval; + else if (!strcmp(token, "chr$")) + t->kind = tokchr_; + else if (!strcmp(token, "eol$")) + t->kind = tokeol_; + else if (!strcmp(token, "asc")) + t->kind = tokasc; + else if (!strcmp(token, "len")) + t->kind = toklen; + else if (!strcmp(token, "mid$")) + t->kind = tokmid_; + else if (!strcmp(token, "peek")) + t->kind = tokpeek; + else if (!strcmp(token, "let")) + t->kind = toklet; + else if (!strcmp(token, "print")) + t->kind = tokprint; + else if (!strcmp(token, "PhreeqcPtr->punch")) + t->kind = tokpunch; +#if defined PHREEQ98 + else if (!strcmp(token, "graph_x")) + t->kind = tokgraph_x; + else if (!strcmp(token, "graph_y")) + t->kind = tokgraph_y; + else if (!strcmp(token, "graph_sy")) + t->kind = tokgraph_sy; +#endif + else if (!strcmp(token, "input")) + t->kind = tokinput; + else if (!strcmp(token, "goto")) + t->kind = tokgoto; + else if (!strcmp(token, "go to")) + t->kind = tokgoto; + else if (!strcmp(token, "if")) + t->kind = tokif; + else if (!strcmp(token, "end")) + t->kind = tokend; + else if (!strcmp(token, "stop")) + t->kind = tokstop; + else if (!strcmp(token, "for")) + t->kind = tokfor; + else if (!strcmp(token, "next")) + t->kind = toknext; + else if (!strcmp(token, "while")) + t->kind = tokwhile; + else if (!strcmp(token, "wend")) + t->kind = tokwend; + else if (!strcmp(token, "gosub")) + t->kind = tokgosub; + else if (!strcmp(token, "return")) + t->kind = tokreturn; + else if (!strcmp(token, "read")) + t->kind = tokread; + else if (!strcmp(token, "data")) + t->kind = tokdata; + else if (!strcmp(token, "restore")) + t->kind = tokrestore; + else if (!strcmp(token, "gotoxy")) + t->kind = tokgotoxy; + else if (!strcmp(token, "on")) + t->kind = tokon; + else if (!strcmp(token, "dim")) + t->kind = tokdim; + else if (!strcmp(token, "poke")) + t->kind = tokpoke; + else if (!strcmp(token, "list")) + t->kind = toklist; + else if (!strcmp(token, "run")) + t->kind = tokrun; + else if (!strcmp(token, "new")) + t->kind = toknew; + else if (!strcmp(token, "load")) + t->kind = tokload; + else if (!strcmp(token, "merge")) + t->kind = tokmerge; + else if (!strcmp(token, "save")) + t->kind = toksave; + else if (!strcmp(token, "bye")) + t->kind = tokbye; + else if (!strcmp(token, "quit")) + t->kind = tokbye; + else if (!strcmp(token, "del")) + t->kind = tokdel; + else if (!strcmp(token, "renum")) + t->kind = tokrenum; + else if (!strcmp(token, "then")) + t->kind = tokthen; + else if (!strcmp(token, "else")) + t->kind = tokelse; + else if (!strcmp(token, "to")) + t->kind = tokto; + else if (!strcmp(token, "step")) + t->kind = tokstep; + /* + * dlp: added functions + */ + else if (!strcmp(token, "tc")) + t->kind = toktc; + else if (!strcmp(token, "tk")) + t->kind = toktk; + else if (!strcmp(token, "time")) + t->kind = toktime; + else if (!strcmp(token, "sim_time")) + t->kind = toksim_time; + else if (!strcmp(token, "total_time")) + t->kind = toktotal_time; + else if (!strcmp(token, "m0")) + t->kind = tokm0; + else if (!strcmp(token, "m")) + t->kind = tokm; + else if (!strcmp(token, "parm")) + t->kind = tokparm; + else if (!strcmp(token, "act")) + t->kind = tokact; + else if (!strcmp(token, "change_por")) + t->kind = tokchange_por; + else if (!strcmp(token, "get_por")) + t->kind = tokget_por; + else if (!strcmp(token, "change_surf")) + t->kind = tokchange_surf; + else if (!strcmp(token, "porevolume")) + t->kind = tokporevolume; + else if (!strcmp(token, "edl")) + t->kind = tokedl; + else if (!strcmp(token, "surf")) + t->kind = toksurf; + else if (!strcmp(token, "equi")) + t->kind = tokequi; + else if (!strcmp(token, "kin")) + t->kind = tokkin; + else if (!strcmp(token, "gas")) + t->kind = tokgas; + else if (!strcmp(token, "s_s")) + t->kind = toks_s; + else if (!strcmp(token, "misc1")) + t->kind = tokmisc1; + else if (!strcmp(token, "misc2")) + t->kind = tokmisc2; + else if (!strcmp(token, "mu")) + t->kind = tokmu; + else if (!strcmp(token, "osmotic")) + t->kind = tokosmotic; + else if (!strcmp(token, "alk")) + t->kind = tokalk; + else if (!strcmp(token, "lk_species")) + t->kind = toklk_species; + else if (!strcmp(token, "lk_named")) + t->kind = toklk_named; + else if (!strcmp(token, "lk_phase")) + t->kind = toklk_phase; + else if (!strcmp(token, "sum_species")) + t->kind = toksum_species; + else if (!strcmp(token, "sum_gas")) + t->kind = toksum_gas; + else if (!strcmp(token, "sum_s_s")) + t->kind = toksum_s_s; + else if (!strcmp(token, "calc_value")) + t->kind = tokcalc_value; + else if (!strcmp(token, "description")) + t->kind = tokdescription; + else if (!strcmp(token, "sys")) + t->kind = toksys; + else if (!strcmp(token, "instr")) + t->kind = tokinstr; + else if (!strcmp(token, "ltrim")) + t->kind = tokltrim; + else if (!strcmp(token, "rtrim")) + t->kind = tokrtrim; + else if (!strcmp(token, "trim")) + t->kind = toktrim; + else if (!strcmp(token, "pad")) + t->kind = tokpad; + else if (!strcmp(token, "rxn")) + t->kind = tokrxn; + else if (!strcmp(token, "dist")) + t->kind = tokdist; + else if (!strcmp(token, "mol")) + t->kind = tokmol; + else if (!strcmp(token, "la")) + t->kind = tokla; + else if (!strcmp(token, "lm")) + t->kind = toklm; + else if (!strcmp(token, "sr")) + t->kind = toksr; + else if (!strcmp(token, "step_no")) + t->kind = tokstep_no; + else if (!strcmp(token, "cell_no")) + t->kind = tokcell_no; + else if (!strcmp(token, "sim_no")) + t->kind = toksim_no; + else if (!strcmp(token, "si")) + t->kind = toksi; + else if (!strcmp(token, "tot")) + t->kind = toktot; + else if (!strcmp(token, "totmole")) + t->kind = toktotmole; + else if (!strcmp(token, "totmol")) + t->kind = toktotmole; + else if (!strcmp(token, "totmoles")) + t->kind = toktotmole; + else if (!strcmp(token, "log10")) + t->kind = toklog10; + else if (!strcmp(token, "put")) + t->kind = tokput; + else if (!strcmp(token, "get")) + t->kind = tokget; + else if (!strcmp(token, "exists")) + t->kind = tokexists; + else if (!strcmp(token, "charge_balance")) + t->kind = tokcharge_balance; + else if (!strcmp(token, "percent_error")) + t->kind = tokpercent_error; + else if (!strcmp(token, "SC")) + t->kind = tokspcond; + else if (!strcmp(token, "rem")) + { + t->kind = tokrem; + m = strlen(l_inbuf) + 1; + if (m < 256) + m = 256; + t->UU.sp = (char *) PHRQ_malloc(m); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int) (strlen(l_inbuf) - i + 1), + l_inbuf + i - 1); + i = strlen(l_inbuf) + 1; + } +#endif + } + else + { + t->kind = tokvar; + v = varbase; + while (v != NULL && strcmp(v->name, token)) + v = v->next; + if (v == NULL) + { + v = (varrec *) PHRQ_calloc(1, sizeof(varrec)); + if (v == NULL) + PhreeqcPtr->malloc_error(); + v->UU.U0.arr = NULL; + v->next = varbase; + varbase = v; + strcpy(v->name, token); + v->numdims = 0; + if (token[strlen(token) - 1] == '$') + { + v->stringvar = true; + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } + else + { + v->stringvar = false; + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } + } + t->UU.vp = v; + } + } + else if (isdigit((int) ch) || ch == '.') + { + t->kind = toknum; + i--; + t->UU.num = strtod(&l_inbuf[i - 1], &ptr); + if (&l_inbuf[i - 1] == ptr) + { + /* + Note: the following causes an infinite loop: + X = ..9 + */ + t->kind = toksnerr; + t->UU.snch = ch; + i++; + break; + } + i += (int) (ptr - &l_inbuf[i - 1]); + } + else + { + t->kind = toksnerr; + t->UU.snch = ch; + } + break; + } + } + } + while (i <= (int) strlen(l_inbuf)); + if (q) { + sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } + if (lp > 0) { + sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } + else if (lp < 0) { + sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } +} + +#undef toklength + + + + void QBasic:: +listtokens(FILE * f, tokenrec * l_buf) +{ + boolean ltr; + char STR1[256] = {0}; + char *string; + ltr = false; + while (l_buf != NULL) + { + if ((l_buf->kind >= (long) toknot && l_buf->kind <= (long) tokrenum) || + l_buf->kind == (long) toknum || l_buf->kind == (long) tokvar || + l_buf->kind >= (long) toktc) + { + if (ltr) + /*putc(' ', f); */ + output_temp_msg(" "); + ltr = (boolean) (l_buf->kind != toknot); + } + else + ltr = false; + switch (l_buf->kind) + { + + case tokvar: + /*fputs(l_buf->UU.vp->name, f); */ + PhreeqcPtr->output_temp_msg(PhreeqcPtr->sformatf("%s", l_buf->UU.vp->name)); + break; + + case toknum: + /*fputs(numtostr(STR1, l_buf->UU.num), f); */ + string = numtostr(STR1, l_buf->UU.num); + PhreeqcPtr->string_trim(string); + output_temp_msg(PhreeqcPtr->sformatf("%s", string)); + break; + + case tokstr: + output_temp_msg(PhreeqcPtr->sformatf("\"%s\"", l_buf->UU.sp)); + break; + + case toksnerr: + output_temp_msg(PhreeqcPtr->sformatf("{%c}", l_buf->UU.snch)); + break; + + case tokplus: + /*putc('+', f); */ + output_temp_msg("+"); + break; + + case tokminus: + /*putc('-', f); */ + output_temp_msg("-"); + break; + + case toktimes: + /*putc('*', f); */ + output_temp_msg("*"); + break; + + case tokdiv: + /*putc('/', f); */ + output_temp_msg("/"); + break; + + case tokup: + /*putc('^', f); */ + output_temp_msg("^"); + break; + + case toklp: + /*putc('(', f); */ + output_temp_msg("("); + break; + + case tokrp: + /*putc(')', f); */ + output_temp_msg(")"); + break; + + case tokcomma: + /*putc(',', f); */ + output_temp_msg(","); + break; + + case toksemi: + /*putc(';', f); */ + output_temp_msg(";"); + break; + + case tokcolon: + output_temp_msg(" : "); + break; + + case tokeq: + output_temp_msg(" = "); + break; + + case toklt: + output_temp_msg(" < "); + break; + + case tokgt: + output_temp_msg(" > "); + break; + + case tokle: + output_temp_msg(" <= "); + break; + + case tokge: + output_temp_msg(" >= "); + break; + + case tokne: + output_temp_msg(" <> "); + break; + + case tokand: + output_temp_msg(" AND "); + break; + + case tokor: + output_temp_msg(" OR "); + break; + + case tokxor: + output_temp_msg(" XOR "); + break; + + case tokmod: + output_temp_msg(" MOD "); + break; + + case toknot: + output_temp_msg("NOT "); + break; + + case toksqr: + output_temp_msg("SQR"); + break; + + case toksqrt: + output_temp_msg("SQRT"); + break; + + case tokceil: + output_temp_msg("CEIL"); + break; + + case tokfloor: + output_temp_msg("FLOOR"); + break; + + case toksin: + output_temp_msg("SIN"); + break; + + case tokcos: + output_temp_msg("COS"); + break; + + case toktan: + output_temp_msg("TAN"); + break; + + case tokarctan: + output_temp_msg("ARCTAN"); + break; + + case toklog: + output_temp_msg("LOG"); + break; + + case tokexp: + output_temp_msg("EXP"); + break; + + case tokabs: + output_temp_msg("ABS"); + break; + + case toksgn: + output_temp_msg("SGN"); + break; + + case tokstr_: + output_temp_msg("STR$"); + break; + + case tokval: + output_temp_msg("VAL"); + break; + + case tokchr_: + output_temp_msg("CHR$"); + break; + + case tokeol_: + output_temp_msg("EOL$"); + break; + + case tokasc: + output_temp_msg("ASC"); + break; + + case toklen: + output_temp_msg("LEN"); + break; + + case tokmid_: + output_temp_msg("MID$"); + break; + + case tokpeek: + output_temp_msg("PEEK"); + break; + + case tokrem: + output_temp_msg(PhreeqcPtr->sformatf("REM%s", l_buf->UU.sp)); + break; + + case toklet: + output_temp_msg("LET"); + break; + + case tokprint: + output_temp_msg("PRINT"); + break; + + case tokinput: + output_temp_msg("INPUT"); + break; + + case tokgoto: + output_temp_msg("GOTO"); + break; + + case tokif: + output_temp_msg("IF"); + break; + + case tokend: + output_temp_msg("END"); + break; + + case tokstop: + output_temp_msg("STOP"); + break; + + case tokfor: + output_temp_msg("FOR"); + break; + + case toknext: + output_temp_msg("NEXT"); + break; + + case tokwhile: + output_temp_msg("WHILE"); + break; + + case tokwend: + output_temp_msg("WEND"); + break; + + case tokgosub: + output_temp_msg("GOSUB"); + break; + + case tokreturn: + output_temp_msg("RETURN"); + break; + + case tokread: + output_temp_msg("READ"); + break; + + case tokdata: + output_temp_msg("DATA"); + break; + + case tokrestore: + output_temp_msg("RESTORE"); + break; + + case tokgotoxy: + output_temp_msg("GOTOXY"); + break; + + case tokon: + output_temp_msg("ON"); + break; + + case tokdim: + output_temp_msg("DIM"); + break; + + case tokpoke: + output_temp_msg("POKE"); + break; + + case toklist: + output_temp_msg("LIST"); + break; + + case tokrun: + output_temp_msg("RUN"); + break; + + case toknew: + output_temp_msg("NEW"); + break; + + case tokload: + output_temp_msg("LOAD"); + break; + + case tokmerge: + output_temp_msg("MERGE"); + break; + + case toksave: + output_temp_msg("SAVE"); + break; + + case tokbye: + output_temp_msg("BYE"); + break; + + case tokdel: + output_temp_msg("DEL"); + break; + + case tokrenum: + output_temp_msg("RENUM"); + break; + + case tokthen: + output_temp_msg(" THEN "); + break; + + case tokelse: + output_temp_msg(" ELSE "); + break; + + case tokto: + output_temp_msg(" TO "); + break; + + case tokstep: + output_temp_msg(" STEP "); + break; + + case toktc: + output_temp_msg("TC"); + break; + + case tokm0: + output_temp_msg("M0"); + break; + + case tokm: + output_temp_msg("M"); + break; + + case tokparm: + output_temp_msg("PARM"); + break; + + case tokact: + output_temp_msg("ACT"); + break; + + case tokchange_por: + output_temp_msg("CHANGE_POR"); + break; + + case tokget_por: + output_temp_msg("GET_POR"); + break; + + case tokchange_surf: + output_temp_msg("CHANGE_SURF"); + break; + + case tokporevolume: + output_temp_msg("POREVOLUME"); + break; + + case tokmol: + output_temp_msg("MOL"); + break; + + case tokla: + output_temp_msg("LA"); + break; + + case toklm: + output_temp_msg("LM"); + break; + + case toksr: + output_temp_msg("SR"); + break; + + case toksi: + output_temp_msg("SI"); + break; + + case toktot: + output_temp_msg("TOT"); + break; + + case toktotmole: + case toktotmol: + case toktotmoles: + output_temp_msg("TOTMOLE"); + break; + + case toktk: + output_temp_msg("TK"); + break; + + case toktime: + output_temp_msg("TIME"); + break; + + case toklog10: + output_temp_msg("LOG10"); + break; + + case toksim_time: + output_temp_msg("SIM_TIME"); + break; + + case tokequi: + output_temp_msg("EQUI"); + break; + + case tokgas: + output_temp_msg("GAS"); + break; + + case tokpunch: + output_temp_msg("PUNCH"); + break; + + case tokkin: + output_temp_msg("KIN"); + break; + + case toks_s: + output_temp_msg("S_S"); + break; + + case tokmu: + output_temp_msg("MU"); + break; + + case tokosmotic: + output_temp_msg("OSMOTIC"); + break; + + case tokalk: + output_temp_msg("ALK"); + break; + + case toklk_species: + output_temp_msg("LK_SPECIES"); + break; + + case toklk_named: + output_temp_msg("LK_NAMED"); + break; + + case toklk_phase: + output_temp_msg("LK_PHASE"); + break; + + case toksum_species: + output_temp_msg("SUM_SPECIES"); + break; + + case toksum_gas: + output_temp_msg("SUM_GAS"); + break; + + case toksum_s_s: + output_temp_msg("SUM_s_s"); + break; + + case tokcalc_value: + output_temp_msg("CALC_VALUE"); + break; + + case tokdescription: + output_temp_msg("DESCRIPTION"); + break; + + case toksys: + output_temp_msg("SYS"); + break; + + case tokinstr: + output_temp_msg("INSTR"); + break; + + case tokltrim: + output_temp_msg("LTRIM"); + break; + + case tokrtrim: + output_temp_msg("RTRIM"); + break; + + case toktrim: + output_temp_msg("TRIM"); + break; + + case tokpad: + output_temp_msg("PAD"); + break; + + case tokrxn: + output_temp_msg("RXN"); + break; + + case tokdist: + output_temp_msg("DIST"); + break; + + case tokmisc1: + output_temp_msg("MISC1"); + break; + + case tokmisc2: + output_temp_msg("MISC2"); + break; + + case tokedl: + output_temp_msg("EDL"); + break; + + case toksurf: + output_temp_msg("SURF"); + break; + + case tokstep_no: + output_temp_msg("STEP_NO"); + break; + + case toksim_no: + output_temp_msg("SIM_NO"); + break; + + case toktotal_time: + output_temp_msg("TOTAL_TIME"); + break; + + case tokput: + output_temp_msg("PUT"); + break; + + case tokget: + output_temp_msg("GET"); + break; + + case tokcharge_balance: + output_temp_msg("CHARGE_BALANCE"); + break; + + case tokpercent_error: + output_temp_msg("PERCENT_ERROR"); + break; + +#if defined PHREEQ98 || defined MULTICHART + case tokgraph_x: + output_temp_msg("GRAPH_X"); + break; + + case tokgraph_y: + output_temp_msg("GRAPH_Y"); + break; + + case tokgraph_sy: + output_temp_msg("GRAPH_SY"); + break; +#endif + +#if defined MULTICHART + case tokplot_xy: + output_temp_msg("PLOT_XY"); + break; +#endif + + case tokcell_no: + output_temp_msg("CELL_NO"); + break; + + case tokexists: + output_temp_msg("EXISTS"); + break; + + case toksc: + output_temp_msg("SC"); + break; + + case tokgamma: + output_temp_msg("GAMMA"); + break; + + case toklg: + output_temp_msg("LG"); + break; + +/* VP: Density Start */ + case tokrho: + output_temp_msg("RHO"); + break; +/* VP: Density End */ + case tokcell_volume: + output_temp_msg("CELL_VOLUME"); + break; + case tokcell_pore_volume: + output_temp_msg("CELL_PORE_VOLUME"); + break; + case tokcell_porosity: + output_temp_msg("CELL_POROSITY"); + break; + case tokcell_saturation: + output_temp_msg("CELL_SATURATION"); + break; + case tokiso: + output_temp_msg("ISO"); + break; + case tokiso_unit: + output_temp_msg("ISO_UNIT"); + break; + case tokphase_formula: + output_temp_msg("PHASE_FORMULA"); + break; + case toklist_s_s: + output_temp_msg("LIST_S_S"); + break; + } + l_buf = l_buf->next; + } +} + + + + void QBasic:: +disposetokens(tokenrec ** tok) +{ + tokenrec *tok1; + + while (*tok != NULL) + { + tok1 = (*tok)->next; + if ((*tok)->kind == (long) tokrem || (*tok)->kind == (long) tokstr) + { + (*tok)->UU.sp = (char *) PhreeqcPtr->free_check_null((*tok)->UU.sp); + } + *tok = (tokenrec *) PhreeqcPtr->free_check_null(*tok); + *tok = tok1; + } +} + + + + void QBasic:: +parseinput(tokenrec ** l_buf) +{ + linerec *l, *l0, *l1; + + while (PhreeqcPtr->replace("\t", " ", inbuf)); + while (PhreeqcPtr->replace("\r", " ", inbuf)); + PhreeqcPtr->string_trim(inbuf); + curline = 0; + while (*inbuf != '\0' && isdigit((int) inbuf[0])) + { + curline = curline * 10 + inbuf[0] - 48; + memmove(inbuf, inbuf + 1, strlen(inbuf)); + } + parse(inbuf, l_buf); + if (curline == 0) + return; + l = linebase; + l0 = NULL; + while (l != NULL && l->num < curline) + { + l0 = l; + l = l->next; + } + if (l != NULL && l->num == curline) + { + l1 = l; + l = l->next; + if (l0 == NULL) + linebase = l; + else + l0->next = l; + disposetokens(&l1->txt); + PHRQ_free(l1); + } + if (*l_buf != NULL) + { + l1 = (linerec *) PHRQ_calloc(1, sizeof(linerec)); + if (l1 == NULL) + PhreeqcPtr->malloc_error(); + l1->next = l; + if (l0 == NULL) + linebase = l1; + else + l0->next = l1; + l1->num = curline; + l1->txt = *l_buf; + strncpy(l1->inbuf, inbuf, MAX_LINE); + l1->inbuf[MAX_LINE-1] = '\0'; + } + clearloops(); + restoredata(); +} + + void QBasic:: +errormsg(const char * l_s) +{ + error_msg(l_s, CONTINUE); + _Escape(42); +} + + + void QBasic:: +snerr(const char * l_s) +{ + char str[MAX_LENGTH] = {0}; + strcpy(str, "Syntax_error "); + errormsg(strcat(str, l_s)); +} + + + void QBasic:: +tmerr(const char * l_s) +{ + char str[MAX_LENGTH] = {0}; + strcpy(str, "Type mismatch error"); + errormsg(strcat(str, l_s)); +} + + + void QBasic:: +badsubscr(void) +{ + errormsg("Bad subscript"); +} + + + LDBLE QBasic:: +realfactor(struct LOC_exec *LINK) +{ + valrec n; + + n = factor(LINK); + if (n.stringval) + tmerr(": found characters, not a number"); + return (n.UU.val); +} + + char * QBasic:: +strfactor(struct LOC_exec * LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + return (n.UU.sval); +} + + char * QBasic:: +stringfactor(char * Result, struct LOC_exec * LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + strcpy(Result, n.UU.sval); + PHRQ_free(n.UU.sval); + return Result; +} + + long QBasic:: +intfactor(struct LOC_exec *LINK) +{ + return ((long) floor(realfactor(LINK) + 0.5)); +} + + LDBLE QBasic:: +realexpr(struct LOC_exec *LINK) +{ + valrec n; + + n = expr(LINK); + if (n.stringval) + tmerr(": found characters, not a number"); + return (n.UU.val); +} + + char * QBasic:: +strexpr(struct LOC_exec * LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + return (n.UU.sval); +} + + char * QBasic:: +stringexpr(char * Result, struct LOC_exec * LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + strcpy(Result, n.UU.sval); + PHRQ_free(n.UU.sval); + return Result; +} + + long QBasic:: +intexpr(struct LOC_exec *LINK) +{ + return ((long) floor(realexpr(LINK) + 0.5)); +} + + + void QBasic:: +require(int k, struct LOC_exec *LINK) +{ + char str[MAX_LENGTH] = {0}; + int i; + if (LINK->t == NULL || LINK->t->kind != k) + { + for (i = 0; i < NCMDS; i++) + { + if (command[i].keycount == k) + break; + } + if (i == NCMDS) + snerr(": missing unknown command"); + else { + strcpy(str, ": missing "); + snerr(strcat(str, command[i].name)); + } + } + LINK->t = LINK->t->next; +} + + + void QBasic:: +skipparen(struct LOC_exec *LINK) +{ + do + { + if (LINK->t == NULL) + snerr(": parenthesis missing"); + if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) + goto _L1; + if (LINK->t->kind == toklp) + { + LINK->t = LINK->t->next; + skipparen(LINK); + } + LINK->t = LINK->t->next; + } + while (true); + _L1:; +} + + +QBasic::varrec * QBasic:: +findvar(struct LOC_exec *LINK) +{ + QBasic::varrec *v; + long i, j, k; + tokenrec *tok; + long FORLIM; + + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(": can't find variable"); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != toklp) + { + if (v->numdims != 0) + badsubscr(); + return v; + } + if (v->numdims == 0) + { + tok = LINK->t; + i = 0; + j = 1; + do + { + if (i >= maxdims) + badsubscr(); + LINK->t = LINK->t->next; + skipparen(LINK); + j *= 11; + i++; + v->dims[i - 1] = 11; + } + while (LINK->t->kind != tokrp); + v->numdims = (char) i; + if (v->stringvar) + { + v->UU.U1.sarr = (char **) PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + for (k = 0; k < j; k++) + v->UU.U1.sarr[k] = NULL; + } + else + { + v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); + if (v->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + for (k = 0; k < j; k++) + v->UU.U0.arr[k] = 0.0; + } + LINK->t = tok; + } + k = 0; + LINK->t = LINK->t->next; + FORLIM = v->numdims; + for (i = 1; i <= FORLIM; i++) + { + j = intexpr(LINK); + if ((unsigned long) j >= (unsigned long) v->dims[i - 1]) + badsubscr(); + k = k * v->dims[i - 1] + j; + if (i < v->numdims) + require(tokcomma, LINK); + } + require(tokrp, LINK); + if (v->stringvar) + v->UU.U1.sval = &v->UU.U1.sarr[k]; + else + v->UU.U0.val = &v->UU.U0.arr[k]; + return v; +} + + +QBasic::valrec QBasic:: +factor(struct LOC_exec * LINK) +{ + char string[MAX_LENGTH] = {0}; + struct solution *soln_ptr; + int nn; + varrec *v; + tokenrec *facttok; + valrec n; + long i, j, m; + tokenrec *tok, *tok1; + char *l_s; + LDBLE l_dummy; + int i_rate; + union + { + long i; + char *c; + } trick; + struct save_values s_v, *s_v_ptr; + int k; + LDBLE TEMP; + char STR1[256] = {0}, STR2[256] = {0}; + char *elt_name, *surface_name, *mytemplate, *name; + varrec *count_varrec = NULL, *names_varrec = NULL, *types_varrec = + NULL, *moles_varrec = NULL; + char **names_arg, **types_arg; + LDBLE *moles_arg; + int arg_num; + LDBLE count_species; + char *ptr, *string1, *string2; + + if (LINK->t == NULL) + snerr(": missing variable or command"); + facttok = LINK->t; + LINK->t = LINK->t->next; + n.stringval = false; + s_v.count_subscripts = 0; + /*s_v.subscripts = (int *) PHRQ_malloc (sizeof (int)); */ + s_v.subscripts = NULL; + switch (facttok->kind) + { + + case toknum: + n.UU.val = facttok->UU.num; + break; + + case tokstr: + n.stringval = true; + m = (int) strlen(facttok->UU.sp) + 1; + if (m < 256) + m = 256; + n.UU.sval = (char *) PHRQ_calloc(m, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, facttok->UU.sp); + break; + + case tokvar: + LINK->t = facttok; + v = findvar(LINK); + n.stringval = v->stringvar; + if (n.stringval) + { + if (*v->UU.U1.sval != NULL) + { + m = (int) strlen(*v->UU.U1.sval) + 1; + if (m < 256) + m = 256; + } + else + { + m = 256; + } + n.UU.sval = (char *) PHRQ_calloc(m, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + if (*v->UU.U1.sval != NULL) + { + strcpy(n.UU.sval, *v->UU.U1.sval); + } + + } + else + n.UU.val = *v->UU.U0.val; + break; + + case toklp: + n = expr(LINK); + require(tokrp, LINK); + break; + + case tokminus: + n.UU.val = -realfactor(LINK); + break; + + case tokplus: + n.UU.val = realfactor(LINK); + break; + + case toknot: + n.UU.val = ~intfactor(LINK); + break; + + case toksqr: + TEMP = realfactor(LINK); + n.UU.val = TEMP * TEMP; + break; + + case toksqrt: + n.UU.val = sqrt(realfactor(LINK)); + break; + + case tokceil: + n.UU.val = ceil(realfactor(LINK)); + break; + + case tokfloor: + n.UU.val = floor(realfactor(LINK)); + break; + + case toktc: + n.UU.val = PhreeqcPtr->tc_x; + break; + + case toktk: + n.UU.val = PhreeqcPtr->tc_x + 273.15; + break; + + case toktime: + n.UU.val = PhreeqcPtr->rate_time; + break; + + case toksim_time: + if (PhreeqcPtr->use.kinetics_in == FALSE) + { + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->rate_sim_time; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->transport_step * PhreeqcPtr->timest; + } + else if (PhreeqcPtr->state == ADVECTION) + { + if (PhreeqcPtr->advection_kin_time_defined == TRUE) + { + n.UU.val = PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; + } + else + { + n.UU.val = PhreeqcPtr->advection_step; + } + } + else + { + n.UU.val = 0; + } + } + else + { + n.UU.val = PhreeqcPtr->rate_sim_time; + } + break; + + case toktotal_time: + if (PhreeqcPtr->use.kinetics_in == FALSE) + { + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->rate_sim_time_end; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->transport_step * PhreeqcPtr->timest; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = + PhreeqcPtr->initial_total_time + PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; + } + else + { + n.UU.val = 0; + } + } + else + { + n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->rate_sim_time; + } + break; + + case tokm0: + n.UU.val = PhreeqcPtr->rate_m0; + break; + + case tokm: + n.UU.val = PhreeqcPtr->rate_m; + break; + + case tokparm: + i_rate = intfactor(LINK); + if (i_rate > PhreeqcPtr->count_rate_p || i_rate == 0) + { + errormsg("Parameter subscript out of range."); + } + n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; + break; + + case tokact: + n.UU.val = PhreeqcPtr->activity(stringfactor(STR1, LINK)); + break; + + case tokgamma: + n.UU.val = PhreeqcPtr->activity_coefficient(stringfactor(STR1, LINK)); + break; + + case toklg: + n.UU.val = PhreeqcPtr->log_activity_coefficient(stringfactor(STR1, LINK)); + break; + + case tokget_por: + i = intfactor(LINK); + if (PhreeqcPtr->phast != TRUE) + { + if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 + || i == PhreeqcPtr->count_cells + 1) + { + /* warning_msg("Note... no porosity for boundary solutions."); */ + n.UU.val = 0; + break; + } + else + n.UU.val = PhreeqcPtr->cell_data[i - 1].por; + break; + } + else + { + n.UU.val = PhreeqcPtr->cell_porosity; + break; + } + + case tokedl: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } + else + { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->diff_layer_total(elt_name, surface_name); + break; + + case toksurf: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } + else + { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->surf_total(elt_name, surface_name); + break; + + case tokequi: + n.UU.val = PhreeqcPtr->equi_phase(stringfactor(STR1, LINK)); + break; + + case tokkin: + n.UU.val = PhreeqcPtr->kinetics_moles(stringfactor(STR1, LINK)); + break; + + case tokgas: + n.UU.val = PhreeqcPtr->find_gas_comp(stringfactor(STR1, LINK)); + break; + + case toks_s: + n.UU.val = PhreeqcPtr->find_s_s_comp(stringfactor(STR1, LINK)); + break; + + case tokmisc1: + n.UU.val = PhreeqcPtr->find_misc1(stringfactor(STR1, LINK)); + break; + + case tokmisc2: + n.UU.val = PhreeqcPtr->find_misc2(stringfactor(STR1, LINK)); + break; + + case tokmu: + n.UU.val = PhreeqcPtr->mu_x; + break; + + case tokosmotic: + if (PhreeqcPtr->pitzer_model == TRUE || PhreeqcPtr->sit_model == TRUE) + { + n.UU.val = PhreeqcPtr->COSMOT; + } + else + { + n.UU.val = 0.0; + } + break; + + case tokalk: + n.UU.val = PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; + break; + + case toklk_species: + n.UU.val = PhreeqcPtr->calc_logk_s(stringfactor(STR1, LINK)); + break; + + case toklk_named: + n.UU.val = PhreeqcPtr->calc_logk_n(stringfactor(STR1, LINK)); + break; + + case toklk_phase: + n.UU.val = PhreeqcPtr->calc_logk_p(stringfactor(STR1, LINK)); + break; + + case toksum_species: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_species(mytemplate, elt_name); + break; + + case toksum_gas: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_gases(mytemplate, elt_name); + break; + + case toksum_s_s: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); + break; + + case tokcalc_value: + require(toklp, LINK); + name = stringfactor(STR1, LINK); + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->get_calculate_value(name); + break; + + case tokdescription: + n.stringval = true; + if (PhreeqcPtr->state == REACTION) + { + if (PhreeqcPtr->use.mix_in == TRUE) + { + sprintf(string, "Mix %d", PhreeqcPtr->use.n_mix_user); + n.UU.sval = PhreeqcPtr->string_duplicate(string); + } + else + { + soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.n_solution_user, &nn, TRUE); + if (soln_ptr != NULL) + { + n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->description); + } + else + { + n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); + } + } + } + else if (PhreeqcPtr->state == ADVECTION || PhreeqcPtr->state == TRANSPORT || PhreeqcPtr->state == PHAST) + { + sprintf(string, "Cell %d", PhreeqcPtr->cell_no); + n.UU.sval = PhreeqcPtr->string_duplicate(string); + } + else + { + if (PhreeqcPtr->use.solution_ptr != NULL) + { + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.solution_ptr->description); + } + else + { + n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); + } + } + while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); + break; + + case tokinstr: + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + string2 = stringfactor(STR2, LINK); + require(tokrp, LINK); + ptr = strstr(string1, string2); + if (ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = ((LDBLE) (ptr - string1)) + 1; + } + break; + + case tokltrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim_left(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case tokrtrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim_right(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case toktrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case tokiso: + n.UU.val = PhreeqcPtr->iso_value(stringfactor(STR1, LINK)); + break; + + case tokiso_unit: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim(string1); + n.UU.sval = PhreeqcPtr->iso_unit(string1); + break; + + case tokpad: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + require(tokrp, LINK); + n.UU.sval = PhreeqcPtr->string_pad(string1, i); + break; + + case toksys: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": can't find variable"); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) + snerr(": can't find name of species"); + + /* return number of types of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + types_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || types_varrec->stringvar != 1) + snerr(": can't find type of species"); + + /* return number of moles of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) + snerr(": can't find moles of species"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(names_varrec); + free_dim_stringvar(types_varrec); + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + /* + n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); + */ + n.UU.val = + PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), + &(types_arg), &(moles_arg)); + + /* + * fill in varrec structure + */ + if (arg_num > 1) + { + *count_varrec->UU.U0.val = count_species; + names_varrec->UU.U1.sarr = names_arg; + types_varrec->UU.U1.sarr = types_arg; + moles_varrec->UU.U0.arr = moles_arg; + + for (i = 0; i < maxdims; i++) + { + names_varrec->dims[i] = 0; + types_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + types_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + names_varrec->numdims = 1; + types_varrec->numdims = 1; + moles_varrec->numdims = 1; + } + else + { + for (i = 0; i < count_species + 1; i++) + { + PhreeqcPtr->free_check_null(names_arg[i]); + PhreeqcPtr->free_check_null(types_arg[i]); + } + PhreeqcPtr->free_check_null(names_arg); + PhreeqcPtr->free_check_null(types_arg); + PhreeqcPtr->free_check_null(moles_arg); + } + break; + + case toklist_s_s: + { + /* list_s_s("calcite", count, name$, moles) */ + /* return total moles */ + require(toklp, LINK); + std::string s_s_name(stringfactor(STR1, LINK)); + cxxNameDouble composition; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of components */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) + snerr(": Cannot find component string variable"); + + /* return number of moles of components */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) + snerr(": Cannot find moles of component variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + snerr(": Expected 4 arguments for list_s_s"); + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(names_varrec); + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + // return total moles + n.UU.val = PhreeqcPtr->list_s_s(s_s_name, composition); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = composition.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + names_varrec->UU.U1.sarr = (char **) PHRQ_malloc((count + 1) * sizeof(char *)); + if (names_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + moles_varrec->UU.U0.arr = (LDBLE *) PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (moles_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + names_varrec->UU.U1.sarr[0] = NULL; + moles_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + names_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + names_varrec->dims[0] = (long) (count + 1); + moles_varrec->dims[0] = (long) (count + 1); + names_varrec->numdims = 1; + moles_varrec->numdims = 1; + + // fill in arrays + i = 1; + + //for (cxxNameDouble::iterator it = composition.begin(); it != composition.end(); it++) + //{ + // names_varrec->UU.U1.sarr[i] = string_duplicate((it->first).c_str()); + // moles_varrec->UU.U0.arr[i] = it->second; + // i++; + //} + + std::vector< std::pair > sort_comp = composition.sort_second(); + size_t j; + for (j = 0; j != sort_comp.size(); j++) + { + names_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate(sort_comp[j].first.c_str()); + moles_varrec->UU.U0.arr[i] = sort_comp[j].second; + i++; + } + + } + break; + } + + case tokphase_formula: + { + require(toklp, LINK); + std::string phase_name(stringfactor(STR1, LINK)); + varrec *elts_varrec = NULL, *coef_varrec = NULL; + cxxNameDouble stoichiometry; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /* phase_formula("calcite", count, elt, coef) */ + /* return formula */ + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* struct varrec *count_varrec, *elt_varrec, *coef_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + std::string form = PhreeqcPtr->phase_formula(phase_name, stoichiometry); + + // put formula as return value + n.stringval = true; + n.UU.sval = PhreeqcPtr->string_duplicate(form.c_str()); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + + } + break; + } + + case tokrxn: + if (PhreeqcPtr->state == REACTION || + PhreeqcPtr->state == ADVECTION || + PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->step_x; + } + else + { + n.UU.val = 0.0; + } + break; + + case tokdist: + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = 0; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = (LDBLE) PhreeqcPtr->use.n_solution_user; + } + else + { + n.UU.val = 0; + } + break; + + case tokmol: + n.UU.val = PhreeqcPtr->molality(stringfactor(STR1, LINK)); + break; + + case tokla: + n.UU.val = PhreeqcPtr->log_activity(stringfactor(STR1, LINK)); + break; + + case toklm: + n.UU.val = PhreeqcPtr->log_molality(stringfactor(STR1, LINK)); + break; + + case toksr: + n.UU.val = PhreeqcPtr->saturation_ratio(stringfactor(STR1, LINK)); + break; + + case tokstep_no: + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = 0; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->transport_step; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = PhreeqcPtr->advection_step; + } + else if (PhreeqcPtr->state == REACTION) + { + n.UU.val = PhreeqcPtr->reaction_step; + } + else + { + n.UU.val = 0; + } + break; + + case tokcell_no: + if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state < REACTION) + { + n.UU.val = PhreeqcPtr->use.solution_ptr->n_user; + } + else + { + if (PhreeqcPtr->use.mix_in == TRUE) + { + n.UU.val = PhreeqcPtr->use.n_mix_user; + } + else + { + n.UU.val = PhreeqcPtr->use.n_solution_user; + } + } + break; + + case toksim_no: + n.UU.val = PhreeqcPtr->simulation; + break; + + case tokget: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) + { + i = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = s_v_ptr->value; + } + break; + + case tokexists: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) + { + i = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = 1; + } + break; + + case tokcharge_balance: + n.UU.val = PhreeqcPtr->cb_x; + break; + + case tokpercent_error: + n.UU.val = 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; + break; + + case toksi: + PhreeqcPtr->saturation_index(stringfactor(STR1, LINK), &l_dummy, &n.UU.val); + break; + + case toktot: + n.UU.val = PhreeqcPtr->total(stringfactor(STR1, LINK)); + break; + + case toktotmole: + case toktotmol: + case toktotmoles: + n.UU.val = PhreeqcPtr->total_mole(stringfactor(STR1, LINK)); + break; + + case tokcell_pore_volume: + case tokporevolume: + n.UU.val = PhreeqcPtr->cell_pore_volume; + break; + +/* VP : Density Start */ + case tokrho: + n.UU.val = PhreeqcPtr->calc_dens(); + break; +/* VP: Density End */ + case tokcell_volume: + n.UU.val = PhreeqcPtr->cell_volume; + break; + case tokcell_porosity: + n.UU.val = PhreeqcPtr->cell_porosity; + break; + case tokcell_saturation: + n.UU.val = PhreeqcPtr->cell_saturation; + break; + case toksc: + n.UU.val = PhreeqcPtr->calc_SC(); + break; + + case toklog10: + n.UU.val = log10(realfactor(LINK)); + break; + + case toksin: + n.UU.val = sin(realfactor(LINK)); + break; + + case tokcos: + n.UU.val = cos(realfactor(LINK)); + break; + + case toktan: + n.UU.val = realfactor(LINK); + n.UU.val = sin(n.UU.val) / cos(n.UU.val); + break; + + case tokarctan: + n.UU.val = atan(realfactor(LINK)); + break; + + case toklog: + n.UU.val = log(realfactor(LINK)); + break; + + case tokexp: + n.UU.val = exp(realfactor(LINK)); + break; + + case tokabs: + n.UU.val = fabs(realfactor(LINK)); + break; + + case toksgn: + n.UU.val = realfactor(LINK); + n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); + break; + + case tokstr_: + n.stringval = true; + n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + numtostr(n.UU.sval, realfactor(LINK)); + break; + + case tokval: + l_s = strfactor(LINK); + tok1 = LINK->t; + parse(l_s, &LINK->t); + tok = LINK->t; + if (tok == NULL) + n.UU.val = 0.0; + else + n = expr(LINK); + disposetokens(&tok); + LINK->t = tok1; + PHRQ_free(l_s); + break; + + case tokchr_: + n.stringval = true; + n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, " "); + n.UU.sval[0] = (char) intfactor(LINK); + break; + + case tokeol_: + n.stringval = true; + n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, "\n"); + break; + + case tokasc: + l_s = strfactor(LINK); + if (*l_s == '\0') + n.UU.val = 0.0; + else + n.UU.val = l_s[0]; + PHRQ_free(l_s); + break; + + case tokmid_: + n.stringval = true; + require(toklp, LINK); + n.UU.sval = strexpr(LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + if (i < 1) + i = 1; + /*j = 255; */ + j = (int) strlen(n.UU.sval); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + } + if (j > (int) strlen(n.UU.sval) - i + 1) + j = (int) strlen(n.UU.sval) - i + 1; + if (i > (int) strlen(n.UU.sval)) + *n.UU.sval = '\0'; + else + { + if (j + 1 > 256) + { + warning_msg("String too long in factor\n"); +/* + STR1 = (char *) PHRQ_realloc (STR1, j + 1); + if (STR1 == NULL) + PhreeqcPtr->malloc_error (); +*/ + } + sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); + strcpy(n.UU.sval, STR1); + } + require(tokrp, LINK); + break; + + case toklen: + l_s = strfactor(LINK); + n.UU.val = (double) strlen(l_s); + PHRQ_free(l_s); + break; + + case tokpeek: +/* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ + trick.i = intfactor(LINK); + n.UU.val = *trick.c; +/* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ + break; + + default: + snerr(": missing \" or ("); + break; + } + s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); + return n; +} + +QBasic::valrec QBasic:: +upexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + + n = factor(LINK); + while (LINK->t != NULL && LINK->t->kind == tokup) + { + if (n.stringval) + tmerr(": not a number before ^"); + LINK->t = LINK->t->next; + n2 = upexpr(LINK); + if (n2.stringval) + tmerr(": not a number after ^"); + if (n.UU.val >= 0) + { + if (n.UU.val > 0) + { + n.UU.val = exp(n2.UU.val * log(n.UU.val)); + } + continue; + } + if (n2.UU.val != (long) n2.UU.val) + { + tmerr(": negative number cannot be raised to a fractional power."); + } + else + { + n.UU.val = exp(n2.UU.val * log(-n.UU.val)); + if (((long) n2.UU.val) & 1) + n.UU.val = -n.UU.val; + } + } + return n; +} + +QBasic::valrec QBasic:: +term(struct LOC_exec * LINK) +{ + valrec n, n2; + int k; + + n = upexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & ((1L << ((long) toktimes)) | + (1L << ((long) tokdiv)) | (1L << + ((long) tokmod)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = QBasic::upexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(": found char, but need a number for * or /"); + if (k == tokmod) + { + /* n.UU.val = (long)floor(n.UU.val + 0.5) % (long)floor(n2.UU.val + 0.5); */ + if (n.UU.val != 0) + { + n.UU.val = + fabs(n.UU.val) / n.UU.val * fmod(fabs(n.UU.val) + + 1e-14, n2.UU.val); + } + else + { + n.UU.val = 0; + } +/* p2c: basic.p, line 1078: + * Note: Using % for possibly-negative arguments [317] */ + } + else if (k == toktimes) + n.UU.val *= n2.UU.val; + else if (n2.UU.val != 0) + { + n.UU.val /= n2.UU.val; + } + else + { + sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + n.UU.val = 0; + } + } + return n; +} + +QBasic::valrec QBasic:: +sexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + int k, m; + + n = term(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokplus)) | (1L << ((long) tokminus)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = term(LINK); + if (n.stringval != n2.stringval) + tmerr(": found char, but need a number for + or - "); + if (k == tokplus) + { + if (n.stringval) + { + m = (int) strlen(n.UU.sval) + (int) strlen(n2.UU.sval) + 1; + if (m < 256) + m = 256; + + n.UU.sval = (char *) PHRQ_realloc(n.UU.sval, (size_t) m * sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcat(n.UU.sval, n2.UU.sval); + PHRQ_free(n2.UU.sval); + } + else + n.UU.val += n2.UU.val; + } + else + { + if (n.stringval) + tmerr(": found char, but need a number for - "); + else + n.UU.val -= n2.UU.val; + } + } + return n; +} + +QBasic::valrec QBasic:: +relexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + boolean f; + int k; + + n = sexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokne + 1)) - (1L << ((long) tokeq)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = QBasic::sexpr(LINK); + if (n.stringval != n2.stringval) + tmerr(""); + if (n.stringval) + { + f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokeq)) | + (1L << ((long) tokge)) | (1L << + ((long) tokle)))) + != 0) || (strcmp(n.UU.sval, n2.UU.sval) < 0 + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) toklt)) | + (1L << ((long) tokle)) | (1L << + ((long) + tokne)))) + != 0) + || (strcmp(n.UU.sval, n2.UU.sval) > 0 + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokgt)) | + (1L << ((long) tokge)) | (1L << + ((long) + tokne)))) != + 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+1.00 seconds, 5000 tries on line 1518 [251] */ + PHRQ_free(n.UU.sval); + PHRQ_free(n2.UU.sval); + } + else + f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long) k < 32 && + ((1L << ((long) k)) & ((1L << ((long) tokeq)) | + (1L << ((long) tokge)) | + (1L << ((long) tokle)))) != + 0) || (n.UU.val < n2.UU.val + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) toklt)) | + (1L << ((long) tokle)) | (1L << + ((long) + tokne)))) + != 0) || (n.UU.val > n2.UU.val + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokgt)) | + (1L << ((long) tokge)) | (1L + << + ((long) tokne)))) != 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+2.00 seconds, 5000 tries on line 1532 [251] */ + n.stringval = false; + n.UU.val = f; + } + return n; +} + +QBasic::valrec QBasic:: +andexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + + n = relexpr(LINK); + while (LINK->t != NULL && LINK->t->kind == tokand) + { + LINK->t = LINK->t->next; + n2 = relexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(""); + n.UU.val = ((long) n.UU.val) & ((long) n2.UU.val); + } + return n; +} + +QBasic::valrec QBasic:: +expr(struct LOC_exec * LINK) +{ + valrec n, n2; + int k; + + n = andexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokor)) | (1L << ((long) tokxor)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = andexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(""); + if (k == tokor) + n.UU.val = ((long) n.UU.val) | ((long) n2.UU.val); + else + n.UU.val = ((long) n.UU.val) ^ ((long) n2.UU.val); + } + return n; +} + + + void QBasic:: +checkextra(struct LOC_exec *LINK) +{ + if (LINK->t != NULL) + errormsg("Extra information on line"); +} + + + boolean QBasic:: +iseos(struct LOC_exec *LINK) +{ + return ((boolean) (LINK->t == NULL || LINK->t->kind == (long) tokelse || + LINK->t->kind == (long) tokcolon)); +} + + + void QBasic:: +skiptoeos(struct LOC_exec *LINK) +{ + while (!iseos(LINK)) + LINK->t = LINK->t->next; +} + + +QBasic::linerec * QBasic:: +findline(long n) +{ + linerec *l; + + l = linebase; + while (l != NULL && l->num != n) + l = l->next; + return l; +} + +QBasic::linerec * QBasic:: +mustfindline(long n) +{ + linerec *l; + + l = findline(n); + if (l == NULL) { + sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); + errormsg(PhreeqcPtr->error_string); + } + return l; +} + + + void QBasic:: +cmdend(struct LOC_exec *LINK) +{ + stmtline = NULL; + LINK->t = NULL; +} + + + void QBasic:: +cmdnew(struct LOC_exec *LINK) +{ + void *p; + int i, k; + + cmdend(LINK); + clearloops(); + restoredata(); + while (linebase != NULL) + { + p = linebase->next; + disposetokens(&linebase->txt); + PHRQ_free(linebase); + linebase = (linerec *) p; + } + while (varbase != NULL) + { + p = varbase->next; + if (varbase->stringvar) + { + if (varbase->numdims > 0) + { + k = 1; + for (i = 0; i < varbase->numdims; i++) + { + k = k * (varbase->dims[i]); + } + for (i = 0; i < k; i++) + { + PhreeqcPtr->free_check_null(varbase->UU.U1.sarr[i]); + } + PhreeqcPtr->free_check_null(varbase->UU.U1.sarr); + } + else if (*varbase->UU.U1.sval != NULL) + { + *varbase->UU.U1.sval = + (char *) PhreeqcPtr->free_check_null(*varbase->UU.U1.sval); + } + + } + else + { + PhreeqcPtr->free_check_null(varbase->UU.U0.arr); + varbase->UU.U0.arr = NULL; + } + PHRQ_free(varbase); + varbase = (varrec *) p; + } +} + + + void QBasic:: +cmdlist(struct LOC_exec *LINK) +{ + linerec *l; + long n1, n2; + + do + { + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n1 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) + { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n2 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + } + else + n2 = LONG_MAX; + } + l = linebase; + while (l != NULL && l->num <= n2) + { + if (l->num >= n1) + { + /* printf("%ld ", l->num); */ + /* listtokens(stdout, l->txt); */ + /* putchar('\n'); */ + output_temp_msg(PhreeqcPtr->sformatf("%ld ", l->num)); + listtokens(NULL, l->txt); + output_temp_msg("\n"); + } + l = l->next; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void QBasic:: +cmdload(boolean merging, char * name, struct LOC_exec *LINK) +{ + FILE *f; + tokenrec *l_buf; + char STR1[256] = {0}; + char *TEMP; + + f = NULL; + if (!merging) + cmdnew(LINK); + if (f != NULL) + { + sprintf(STR1, "%s.TEXT", name); + f = freopen(STR1, "r", f); + } + else + { + sprintf(STR1, "%s.TEXT", name); + f = fopen(STR1, "r"); + } + if (f == NULL) + _EscIO(FileNotFound); + while (fgets(inbuf, 256, f) != NULL) + { + TEMP = strchr(inbuf, '\n'); + if (TEMP != NULL) + *TEMP = 0; + parseinput(&l_buf); + if (curline == 0) + { + printf("Bad line in file\n"); + disposetokens(&l_buf); + } + } + if (f != NULL) + fclose(f); + f = NULL; + if (f != NULL) + fclose(f); +} + + + void QBasic:: +cmdrun(struct LOC_exec *LINK) +{ + linerec *l; + long i; + /*string255 s; */ + char *l_s; + + l_s = (char *) PHRQ_calloc(max_line, sizeof(char)); + if (l_s == NULL) + PhreeqcPtr->malloc_error(); + + l = linebase; + if (!iseos(LINK)) + { + if (LINK->t->kind == toknum) + /*l = mustfindline(intexpr(LINK), LINK); */ + l = mustfindline(intexpr(LINK)); + else + { + stringexpr(l_s, LINK); + i = 0; + if (!iseos(LINK)) + { + require(tokcomma, LINK); + i = intexpr(LINK); + } + checkextra(LINK); + cmdload(false, l_s, LINK); + if (i == 0) + l = linebase; + else + l = mustfindline(i); + } + } + stmtline = l; + LINK->gotoflag = true; + clearvars(); + clearloops(); + restoredata(); + PhreeqcPtr->free_check_null(l_s); + return; +} + +/* PhreeqcPtr->replace basic save command with transport of rate back to calc_kinetic_rate */ + void QBasic:: +cmdsave(struct LOC_exec *LINK) +{ + valrec n; + while (!iseos(LINK)) + { + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { + snerr(": in SAVE command"); + } + else + { + PhreeqcPtr->rate_moles = n.UU.val; + } + } +} + void QBasic:: +cmdput(struct LOC_exec *LINK) +{ + int j; + struct save_values s_v; + + s_v.count_subscripts = 0; + s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); + + /* get parentheses */ + require(toklp, LINK); + + /* get first argumen */ + s_v.value = realexpr(LINK); + + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + s_v.count_subscripts++; + s_v.subscripts = + (int *) PHRQ_realloc(s_v.subscripts, + (size_t) s_v.count_subscripts * + sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts - 1] = j; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + + PhreeqcPtr->save_values_store(&s_v); + s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); +} + + void QBasic:: +cmdchange_por(struct LOC_exec *LINK) +{ + int j; + LDBLE TEMP; + require(toklp, LINK); + /* get new porosity */ + TEMP = realexpr(LINK); + require(tokcomma, LINK); + /* get cell_no */ + j = intexpr(LINK); + require(tokrp, LINK); + if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 + && j != PhreeqcPtr->count_cells + 1) + PhreeqcPtr->cell_data[j - 1].por = TEMP; +} + + void QBasic:: +cmdchange_surf(struct LOC_exec *LINK) +{ +/* + change_surf("Hfo", 0.3, "Sfo", 0, 5 ) + (old_name, fraction, new_name, new_Dw, cell_no) + */ + char *c1; + int count; + + PhreeqcPtr->change_surf_count += 1; + count = PhreeqcPtr->change_surf_count; + if (PhreeqcPtr->change_surf[count - 1].next == FALSE) + PhreeqcPtr->change_surf = PhreeqcPtr->change_surf_alloc(count + 1); + + require(toklp, LINK); + /* get surface component name (change affects all comps of the same charge structure) */ + c1 = strexpr(LINK); + PhreeqcPtr->change_surf[count - 1].comp_name = PhreeqcPtr->string_hsave(c1); + PHRQ_free(c1); + require(tokcomma, LINK); + /* get fraction of comp to change */ + PhreeqcPtr->change_surf[count - 1].fraction = realexpr(LINK); + require(tokcomma, LINK); + /* get new surface component name */ + c1 = strexpr(LINK); + PhreeqcPtr->change_surf[count - 1].new_comp_name = PhreeqcPtr->string_hsave(c1); + PHRQ_free(c1); + require(tokcomma, LINK); + /* get new Dw (no transport if 0) */ + PhreeqcPtr->change_surf[count - 1].new_Dw = realexpr(LINK); + require(tokcomma, LINK); + /* get cell_no */ + PhreeqcPtr->change_surf[count - 1].cell_no = intexpr(LINK); + require(tokrp, LINK); + + if (PhreeqcPtr->change_surf->cell_no == 0 || PhreeqcPtr->change_surf->cell_no == PhreeqcPtr->count_cells + 1) + PhreeqcPtr->change_surf[count - 1].cell_no = -99; +} + + void QBasic:: +cmdbye(void) +{ + exitflag = true; +} + + void QBasic:: +cmddel(struct LOC_exec *LINK) +{ + linerec *l, *l0, *l1; + long n1, n2; + + do + { + if (iseos(LINK)) + snerr(": no variable name after del"); + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n1 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) + { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n2 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + } + else + n2 = LONG_MAX; + } + l = linebase; + l0 = NULL; + while (l != NULL && l->num <= n2) + { + l1 = l->next; + if (l->num >= n1) + { + if (l == stmtline) + { + cmdend(LINK); + clearloops(); + restoredata(); + } + if (l0 == NULL) + linebase = l->next; + else + l0->next = l->next; + disposetokens(&l->txt); + PHRQ_free(l); + } + else + l0 = l; + l = l1; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void QBasic:: +cmdrenum(struct LOC_exec *LINK) +{ + linerec *l, *l1; + tokenrec *tok; + long lnum, step; + + lnum = 10; + step = 10; + if (!iseos(LINK)) + { + lnum = intexpr(LINK); + if (!iseos(LINK)) + { + require(tokcomma, LINK); + step = intexpr(LINK); + } + } + l = linebase; + if (l == NULL) + return; + while (l != NULL) + { + l->num2 = lnum; + lnum += step; + l = l->next; + } + l = linebase; + do + { + tok = l->txt; + do + { + if (tok->kind == (long) tokdel || tok->kind == (long) tokrestore + || tok->kind == (long) toklist || tok->kind == (long) tokrun + || tok->kind == (long) tokelse || tok->kind == (long) tokthen + || tok->kind == (long) tokgosub + || tok->kind == (long) tokgoto) + { + while (tok->next != NULL && tok->next->kind == toknum) + { + tok = tok->next; + lnum = (long) floor(tok->UU.num + 0.5); + l1 = linebase; + while (l1 != NULL && l1->num != lnum) + l1 = l1->next; + if (l1 == NULL) + printf("Undefined line %ld in line %ld\n", lnum, + l->num2); + else + tok->UU.num = l1->num2; + if (tok->next != NULL && tok->next->kind == tokcomma) + tok = tok->next; + } + } + tok = tok->next; + } + while (tok != NULL); + l = l->next; + } + while (l != NULL); + l = linebase; + while (l != NULL) + { + l->num = l->num2; + l = l->next; + } +} + + + void QBasic:: +cmdprint(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256] = {0}; + + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + output_temp_msg(PhreeqcPtr->sformatf("%s ", n.UU.sval)); + PHRQ_free(n.UU.sval); + } + else +/* printf("%s ", numtostr(STR1, n.UU.val)); */ + output_temp_msg(PhreeqcPtr->sformatf("%s ", numtostr(STR1, n.UU.val))); + } + if (!semiflag) +/* putchar('\n');*/ + output_temp_msg("\n"); +} + + void QBasic:: +cmdpunch(struct LOC_exec *LINK) +{ + valrec n; + /* char STR1[256]; */ + + while (!iseos(LINK)) + { + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + if (PhreeqcPtr->punch.high_precision == FALSE) + { + if (strlen(n.UU.sval) <= 12) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.12s\t", n.UU.sval); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); + } + } + else + { + if (strlen(n.UU.sval) <= 20) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.20s\t", n.UU.sval); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); + } + } + PHRQ_free(n.UU.sval); + } + else if (PhreeqcPtr->punch.high_precision == FALSE) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.12e\t", (double) n.UU.val); + } + ++PhreeqcPtr->n_user_punch_index; + } +} + +#if defined PHREEQ98 + void QBasic:: +cmdgraph_x(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "x"); + PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "x"); + colnr++; + } +} + + void QBasic:: +cmdgraph_y(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "y"); + PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "y"); + colnr++; + } +} + + void QBasic:: +cmdgraph_sy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "s"); + PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "s"); + colnr++; + } +} +#endif + + void QBasic:: +cmdlet(boolean implied, struct LOC_exec *LINK) +{ + varrec *v; + char *old, *mynew; + LDBLE d_value; + LDBLE *target; + char **starget; + target = NULL; + starget = NULL; + if (implied) + LINK->t = stmttok; + v = findvar(LINK); + if (v->stringvar) + { + starget = v->UU.U1.sval; + } + else + { + target = v->UU.U0.val; + } + require(tokeq, LINK); + if (!v->stringvar) + { + /* in case array is used on right hand side */ + d_value = realexpr(LINK); + v->UU.U0.val = target; + *v->UU.U0.val = d_value; + /* *v->UU.U0.val = realexpr(LINK); */ + return; + } + mynew = strexpr(LINK); + v->UU.U1.sval = starget; + old = *v->UU.U1.sval; + *v->UU.U1.sval = mynew; + if (old != NULL) + PHRQ_free(old); +} + + + void QBasic:: +cmdgoto(struct LOC_exec *LINK) +{ + stmtline = mustfindline(intexpr(LINK)); + LINK->t = NULL; + LINK->gotoflag = true; +} + + + void QBasic:: +cmdif(struct LOC_exec *LINK) +{ + LDBLE n; + long i; + + n = realexpr(LINK); + require(tokthen, LINK); + if (n == 0) + { + i = 0; + do + { + if (LINK->t != NULL) + { + if (LINK->t->kind == tokif) + i++; + if (LINK->t->kind == tokelse) + i--; + LINK->t = LINK->t->next; + } + } + while (LINK->t != NULL && i >= 0); + } + if (LINK->t != NULL && LINK->t->kind == toknum) + cmdgoto(LINK); + else + LINK->elseflag = true; +} + + + void QBasic:: +cmdelse(struct LOC_exec *LINK) +{ + LINK->t = NULL; +} + + + boolean QBasic:: +skiploop(int up, int dn, struct LOC_exec *LINK) +{ + boolean Result; + long i; + linerec *saveline; + + saveline = stmtline; + i = 0; + do + { + while (LINK->t == NULL) + { + if (stmtline == NULL || stmtline->next == NULL) + { + Result = false; + stmtline = saveline; + goto _L1; + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == up) + i++; + if (LINK->t->kind == dn) + i--; + LINK->t = LINK->t->next; + } + while (i >= 0); + Result = true; + _L1: + return Result; +} + + + void QBasic:: +cmdfor(struct LOC_exec *LINK) +{ + looprec *l, lr; + linerec *saveline; + long i, j; + + lr.UU.U0.vp = findvar(LINK); + if (lr.UU.U0.vp->stringvar) + snerr(": error in FOR command"); + require(tokeq, LINK); + *lr.UU.U0.vp->UU.U0.val = realexpr(LINK); + require(tokto, LINK); + lr.UU.U0.max = realexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokstep) + { + LINK->t = LINK->t->next; + lr.UU.U0.step = realexpr(LINK); + } + else + lr.UU.U0.step = 1.0; + lr.homeline = stmtline; + lr.hometok = LINK->t; + lr.kind = forloop; + lr.next = loopbase; + if ((lr.UU.U0.step >= 0 && *lr.UU.U0.vp->UU.U0.val > lr.UU.U0.max) || + (lr.UU.U0.step <= 0 && *lr.UU.U0.vp->UU.U0.val < lr.UU.U0.max)) + { + saveline = stmtline; + i = 0; + j = 0; + do + { + while (LINK->t == NULL) + { + if (stmtline == NULL || stmtline->next == NULL) + { + stmtline = saveline; + errormsg("FOR without NEXT"); + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == tokfor) + { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j++; + else + i++; + } + if (LINK->t->kind == toknext) + { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j--; + else + i--; + } + LINK->t = LINK->t->next; + } + while (i >= 0 && j >= 0); + skiptoeos(LINK); + return; + } + l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + *l = lr; + loopbase = l; +} + + + void QBasic:: +cmdnext(struct LOC_exec *LINK) +{ + varrec *v; + boolean found; + looprec *l, *WITH; + + if (!iseos(LINK)) + v = findvar(LINK); + else + v = NULL; + do + { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("NEXT without FOR"); + found = (boolean) (loopbase->kind == forloop && + (v == NULL || loopbase->UU.U0.vp == v)); + if (!found) + { + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + WITH = loopbase; + *WITH->UU.U0.vp->UU.U0.val += WITH->UU.U0.step; + if ((WITH->UU.U0.step < 0 + || *WITH->UU.U0.vp->UU.U0.val <= WITH->UU.U0.max) + && (WITH->UU.U0.step > 0 + || *WITH->UU.U0.vp->UU.U0.val >= WITH->UU.U0.max)) + { + stmtline = WITH->homeline; + LINK->t = WITH->hometok; + return; + } + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; +} + + + void QBasic:: +cmdwhile(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = whileloop; + l->homeline = stmtline; + l->hometok = LINK->t; + if (iseos(LINK)) + return; + if (realexpr(LINK) != 0) + return; + if (!skiploop(tokwhile, tokwend, LINK)) + errormsg("WHILE without WEND"); + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + + void QBasic:: +cmdwend(struct LOC_exec *LINK) +{ + tokenrec *tok; + linerec *tokline; + looprec *l; + boolean found; + + do + { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("WEND without WHILE"); + found = (boolean) (loopbase->kind == whileloop); + if (!found) + { + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + if (!iseos(LINK)) + { + if (realexpr(LINK) != 0) + found = false; + } + tok = LINK->t; + tokline = stmtline; + if (found) + { + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + if (!iseos(LINK)) + { + if (realexpr(LINK) == 0) + found = false; + } + } + if (found) + return; + LINK->t = tok; + stmtline = tokline; + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; +} + + + void QBasic:: +cmdgosub(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + cmdgoto(LINK); +} + + + void QBasic:: +cmdreturn(struct LOC_exec *LINK) +{ + looprec *l; + boolean found; + + do + { + if (loopbase == NULL) + errormsg("RETURN without GOSUB"); + found = (boolean) (loopbase->kind == gosubloop); + if (!found) + { + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + l = loopbase->next; + PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + + void QBasic:: +cmdread(struct LOC_exec *LINK) +{ + varrec *v; + tokenrec *tok; + boolean found; + + do + { + v = findvar(LINK); + tok = LINK->t; + LINK->t = datatok; + if (dataline == NULL) + { + dataline = linebase; + LINK->t = dataline->txt; + } + if (LINK->t == NULL || LINK->t->kind != tokcomma) + { + do + { + while (LINK->t == NULL) + { + if (dataline == NULL || dataline->next == NULL) + errormsg("Out of Data"); + dataline = dataline->next; + LINK->t = dataline->txt; + } + found = (boolean) (LINK->t->kind == tokdata); + LINK->t = LINK->t->next; + } + while (!found || iseos(LINK)); + } + else + LINK->t = LINK->t->next; + if (v->stringvar) + { + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = strexpr(LINK); + } + else + *v->UU.U0.val = realexpr(LINK); + datatok = LINK->t; + LINK->t = tok; + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void QBasic:: +cmddata(struct LOC_exec *LINK) +{ + skiptoeos(LINK); +} + + + void QBasic:: +cmdrestore(struct LOC_exec *LINK) +{ + if (iseos(LINK)) + restoredata(); + else + { + dataline = mustfindline(intexpr(LINK)); + datatok = dataline->txt; + } +} + + + void QBasic:: +cmdgotoxy(struct LOC_exec *LINK) +{ + intexpr(LINK); + require(tokcomma, LINK); +} + + + void QBasic:: +cmdon(struct LOC_exec *LINK) +{ + long i; + looprec *l; + + i = intexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokgosub) + { + l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + LINK->t = LINK->t->next; + } + else + require(tokgoto, LINK); + if (i < 1) + { + skiptoeos(LINK); + return; + } + while (i > 1 && !iseos(LINK)) + { + require(toknum, LINK); + if (!iseos(LINK)) + require(tokcomma, LINK); + i--; + } + if (!iseos(LINK)) + cmdgoto(LINK); +} + + + void QBasic:: +cmddim(struct LOC_exec *LINK) +{ + long i, j, k; + varrec *v; + boolean done; + + do + { + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(": error in DIM command"); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (v->numdims != 0) + errormsg("Array already dimensioned before"); + j = 1; + i = 0; + require(toklp, LINK); + do + { + k = intexpr(LINK) + 1; + if (k < 1) + badsubscr(); + if (i >= maxdims) + badsubscr(); + i++; + v->dims[i - 1] = k; + j *= k; + done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); + if (!done) + require(tokcomma, LINK); + } + while (!done); + LINK->t = LINK->t->next; + v->numdims = (char) i; + if (v->stringvar) + { + v->UU.U1.sarr = (char **) PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + for (i = 0; i < j; i++) + v->UU.U1.sarr[i] = NULL; + } + else + { + v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); + if (v->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + for (i = 0; i < j; i++) + v->UU.U0.arr[i] = 0.0; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + void QBasic:: +cmdpoke(struct LOC_exec *LINK) +{ + union + { + long i; + char *c; + } trick; + +/* p2c: basic.p, line 2073: Note: Range checking is OFF [216] */ + trick.i = intexpr(LINK); + require(tokcomma, LINK); + *trick.c = (char) intexpr(LINK); +/* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ +} + + void QBasic:: +exec(void) +{ + struct LOC_exec V; + char *ioerrmsg; + char STR1[256] = {0}; + + + TRY(try1); + do + { + do + { + V.gotoflag = false; + V.elseflag = false; + while (stmttok != NULL && stmttok->kind == tokcolon) + stmttok = stmttok->next; + V.t = stmttok; + if (V.t != NULL) + { + V.t = V.t->next; + switch (stmttok->kind) + { + + case tokrem: + /* blank case */ + break; + + case toklist: + cmdlist(&V); + break; + + case tokrun: + cmdrun(&V); + break; + + case toknew: + cmdnew(&V); + break; + + case tokload: + cmdload(false, stringexpr(STR1, &V), &V); + break; + + case tokmerge: + cmdload(true, stringexpr(STR1, &V), &V); + break; + + case toksave: + cmdsave(&V); + break; + + case tokbye: + cmdbye(); + break; + + case tokdel: + cmddel(&V); + break; + + case tokrenum: + cmdrenum(&V); + break; + + case toklet: + cmdlet(false, &V); + break; + + case tokvar: + cmdlet(true, &V); + break; + + case tokprint: + cmdprint(&V); + break; + + case tokpunch: + cmdpunch(&V); + break; + + case tokput: + cmdput(&V); + break; + + case tokchange_por: + cmdchange_por(&V); + break; + + case tokchange_surf: + cmdchange_surf(&V); + break; + +#if defined PHREEQ98 || defined MULTICHART + case tokgraph_x: + cmdgraph_x(&V); + break; + + case tokgraph_y: + cmdgraph_y(&V); + break; + + case tokgraph_sy: + cmdgraph_sy(&V); + break; +#endif +#if defined MULTICHART + case tokplot_xy: + cmdplot_xy(&V); + break; +#endif + + case tokinput: + error_msg + ("Basic command INPUT is not a legal command in PHREEQC.", + STOP); + break; + + case tokgoto: + cmdgoto(&V); + break; + + case tokif: + cmdif(&V); + break; + + case tokelse: + cmdelse(&V); + break; + + case tokend: + cmdend(&V); + break; + + case tokstop: + P_escapecode = -20; + goto _Ltry1; + + case tokfor: + cmdfor(&V); + break; + + case toknext: + cmdnext(&V); + break; + + case tokwhile: + cmdwhile(&V); + break; + + case tokwend: + cmdwend(&V); + break; + + case tokgosub: + cmdgosub(&V); + break; + + case tokreturn: + cmdreturn(&V); + break; + + case tokread: + cmdread(&V); + break; + + case tokdata: + cmddata(&V); + break; + + case tokrestore: + cmdrestore(&V); + break; + + case tokgotoxy: + cmdgotoxy(&V); + break; + + case tokon: + cmdon(&V); + break; + + case tokdim: + cmddim(&V); + break; + + case tokpoke: + cmdpoke(&V); + break; + + default: + errormsg("Illegal command"); + break; + } + } + if (!V.elseflag && !iseos(&V)) + checkextra(&V); + stmttok = V.t; + } + while (V.t != NULL); + if (stmtline != NULL) + { + if (!V.gotoflag) + stmtline = stmtline->next; + if (stmtline != NULL) + stmttok = stmtline->txt; + } + } + while (stmtline != NULL); + RECOVER2(try1, _Ltry1); + if (P_escapecode == -20) + warning_msg("Break"); + /* printf("Break"); */ + else if (P_escapecode != 42) + { + switch (P_escapecode) + { + + case -4: + sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -5: + sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -6: + sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -7: + sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -8: + case -19: + case -18: + case -17: + case -16: + case -15: + sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -10: + ioerrmsg = (char *) PHRQ_calloc(256, sizeof(char)); + if (ioerrmsg == NULL) + PhreeqcPtr->malloc_error(); + sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); + warning_msg(ioerrmsg); + PHRQ_free(ioerrmsg); + break; + + default: + if (EXCP_LINE != -1) + { + sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); + warning_msg(PhreeqcPtr->error_string); + } + _Escape(P_escapecode); + break; + } + } + if (stmtline != NULL) + { + sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + error_msg(PhreeqcPtr->error_string, CONTINUE); + } + ENDTRY(try1); +} /*exec */ +int QBasic:: +free_dim_stringvar(varrec *l_varbase) +{ + int i, k; + if (l_varbase->numdims > 0) + { + k = 1; + for (i = 0; i < l_varbase->numdims; i++) + { + k = k * (l_varbase->dims[i]); + } + for (i = 0; i < k; i++) + { + PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr[i]); + } + l_varbase->UU.U1.sarr = (char **) PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr); + } + return (OK); +} +#if defined MULTICHART + void QBasic:: +cmdplot_xy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n[2]; + char STR[2][256]; + int i = 0; + semiflag = false; + + while (!iseos(LINK) && i < 2) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + i++; + continue; + } + n[i] = expr(LINK); + if (n[i].stringval) + { + strcpy(STR[i], n[i].UU.sval); + PHRQ_free(n[i].UU.sval); + } + else + numtostr(STR[i], n[i].UU.val); + } + + ChartObject *chart = chart_handler.Get_current_chart(); + if (chart == NULL) return; + + std::string x_str(STR[0]), y_str(STR[1]); + +// Code formerly in PlotXY, included here + { + + bool new_sim = false, new_trans = false; + + if (chart->Get_FirstCallToUSER_GRAPH() && chart->Get_colnr() == 0) + chart->Set_prev_sim_no(simulation); + else + chart->Set_prev_sim_no(simulation); + + // Add a curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + std::string head(""); + if (chart->Get_new_headings().size() > 0) + { + head = chart->Get_new_headings()[0]; + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + if (chart->Get_new_plotxy_curves().size() > 0) + { + // find plotxy curve definitions + chart->Add_curve(true, head, + chart->Get_new_plotxy_curves()[0].Get_line_w(), + chart->Get_new_plotxy_curves()[0].Get_symbol(), + chart->Get_new_plotxy_curves()[0].Get_symbol_size(), + chart->Get_new_plotxy_curves()[0].Get_y_axis(), + chart->Get_new_plotxy_curves()[0].Get_color() + ); + // pop plotxy curve definition + chart->Get_new_plotxy_curves().erase(chart->Get_new_plotxy_curves().begin()); + } + else + { + chart->Add_curve(true, head); + } + chart->Set_curve_added(true); + } + + if (x_str.size() > 0 && y_str.size() > 0) + { + chart->Get_Curves()[chart->Get_colnr()]->Get_x().push_back(atof(x_str.c_str())); + chart->Get_Curves()[chart->Get_colnr()]->Get_y().push_back(atof(y_str.c_str())); + chart->Set_point_added(true); + + // Mark added curve for first point, might have been invisible in DefineCurves + if (chart->Get_Curves()[chart->Get_colnr()]->Get_x().size() == 1) + chart->Set_curve_added(true); + } + } + chart->Set_colnr(chart->Get_colnr() + 1); +} + void QBasic:: +cmdgraph_x(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Set_graph_x(atof(n.UU.sval)); + } + PHRQ_free(n.UU.sval); + } + else + chart->Set_graph_x(n.UU.val); + } + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + if (chart->Get_new_headings().size() > 0) + { + // remove x heading + //if (chart->Get_colnr() == chart->Get_ColumnOffset()) + { + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + } + } +} + + void QBasic:: +cmdgraph_y(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + // wait until x value is known before storing in curve + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); + } + PHRQ_free(n.UU.sval); + } + else + { + chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; + } + chart->Set_point_added(true); + + // Add a new curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + //if (chart->Get_new_headings().size() > 0) + //{ + // // remove x heading + // if (chart->Get_colnr() == chart->Get_ColumnOffset()) + // { + // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + // } + //} + if (chart->Get_new_headings().size() > 0) + { + chart->Add_curve(false, chart->Get_new_headings()[0]); + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + else + { + chart->Add_curve(false); + } + chart->Set_curve_added(true); + } + chart->Set_colnr(chart->Get_colnr() + 1); + } +} + + void QBasic:: +cmdgraph_sy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + chart->Get_secondary_y()[chart->Get_colnr()] = true; + + // wait until x value is known before storing in curve + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); + } + PHRQ_free(n.UU.sval); + } + else + chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; + chart->Set_point_added(true); + // Add a new curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + //if (chart->Get_new_headings().size() > 0) + //{ + // // remove x heading + // if (chart->Get_colnr() == chart->Get_ColumnOffset()) + // { + // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + // } + //} + if (chart->Get_new_headings().size() > 0) + { + chart->Add_curve(false, chart->Get_new_headings()[0]); + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + else + { + chart->Add_curve(false); + } + chart->Set_curve_added(true); + } + chart->Set_colnr(chart->Get_colnr() + 1); + } +} +#endif // MULTICHART + + + + +/* In case your system lacks these... */ + +long QBasic:: +my_labs(long l_x) +{ + return ((l_x > 0) ? l_x : -l_x); +} + + +/* #define __STDC__ */ /* PHREEQ98 */ + +QBasic::Anyptr QBasic:: +my_memmove(Anyptr d, Const Anyptr l_s, size_t n) +{ + register char *dd = (char *) d, *ss = (char *) l_s; + if (dd < ss || (unsigned int) (dd - ss) >= n) + { + memcpy(dd, ss, n); + } + else if (n > 0) + { + dd += n; + ss += n; + while (n-- > 0) + *--dd = *--ss; + } + return d; +} + + +QBasic::Anyptr QBasic:: +my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) +{ + register char *ss = (char *) l_s, *dd = (char *) d; + while (n-- > 0) + *dd++ = *ss++; + return d; +} + +int QBasic:: +my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) +{ + register char *a = (char *) s1, *b = (char *) s2; + register int i; + while (n-- > 0) + if ((i = (*a++) - (*b++)) != 0) + return i; + return 0; +} + +QBasic::Anyptr QBasic:: +my_memset(Anyptr d, int c, size_t n) +{ + register char *dd = (char *) d; + while (n-- > 0) + *dd++ = (char) c; + return d; +} + +int QBasic:: +my_toupper(int c) +{ + if (islower(c)) + return _toupper(c); + else + return c; +} + + +int QBasic:: +my_tolower(int c) +{ + if (isupper(c)) + return _tolower(c); + else + return c; +} + + + + +long QBasic:: +ipow(long a, long b) +{ + long v; + + if (a == 0 || a == 1) + return a; + if (a == -1) + return (b & 1) ? -1 : 1; + if (b < 0) + return 0; + if (a == 2) + return 1L << b; + v = (b & 1) ? a : 1; + while ((b >>= 1) > 0) + { + a *= a; + if (b & 1) + v *= a; + } + return v; +} + + + + +/* Common string functions: */ + +/* Store in "ret" the substring of length "len" starting from "pos" (1-based). + Store a shorter or null string if out-of-range. Return "ret". */ +char * QBasic:: +strsub(register char *ret, register char *l_s, register int pos, + register int len) +{ + register char *s2; + + if (--pos < 0 || len <= 0) + { + *ret = 0; + return ret; + } + while (pos > 0) + { + if (!*l_s++) + { + *ret = 0; + return ret; + } + pos--; + } + s2 = ret; + while (--len >= 0) + { + if (!(*s2++ = *l_s++)) + return ret; + } + *s2 = 0; + return ret; +} + + +/* Return the index of the first occurrence of "pat" as a substring of "s", + starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ + +int QBasic:: +strpos2(char *l_s, register char *pat, register int pos) +{ + register char *cp, ch; + register int slen; + + if (--pos < 0) + return 0; + slen = (int) strlen(l_s) - pos; + cp = l_s + pos; + if (!(ch = *pat++)) + return 0; + pos = (int) strlen(pat); + slen -= pos; + while (--slen >= 0) + { + if (*cp++ == ch && !strncmp(cp, pat, pos)) + return (int) (cp - l_s); + } + return 0; +} + + +/* Case-insensitive version of strcmp. */ +int QBasic:: +strcicmp(register char *s1, register char *s2) +{ + register unsigned char c1, c2; + + while (*s1) + { + if (*s1++ != *s2++) + { + if (!s2[-1]) + return 1; + c1 = (unsigned char) toupper(s1[-1]); + c2 = (unsigned char) toupper(s2[-1]); + if (c1 != c2) + return c1 - c2; + } + } + if (*s2) + return -1; + return 0; +} + + + + +/* HP and Turbo Pascal string functions: */ + +/* Trim blanks at left end of string. */ +char * QBasic:: +strltrim(register char *l_s) +{ + while (Isspace((int) *l_s++)); + return l_s - 1; +} + + +/* Trim blanks at right end of string. */ +char * QBasic:: +strrtrim(register char *l_s) +{ + register char *s2 = l_s; + + if (!*l_s) + return l_s; + while (*++s2); + while (s2 > l_s && Isspace((int) *--s2)) + *s2 = 0; + return l_s; +} + + +/* Store in "ret" string "s" with enough pad chars added to reach "size". */ + +/* Copy the substring of length "len" from index "spos" of "s" (1-based) + to index "dpos" of "d", lengthening "d" if necessary. Length and + indices must be in-range. */ +void QBasic:: +strmove(register int len, register char *l_s, register int spos, + register char *d, register int dpos) +{ + l_s += spos - 1; + d += dpos - 1; + while (*d && --len >= 0) + *d++ = *l_s++; + if (len > 0) + { + while (--len >= 0) + *d++ = *l_s++; + *d = 0; + } +} + +/* Insert string "src" at index "pos" of "dst". */ +void QBasic:: +strinsert(register char *src, register char *dst, register int pos) +{ + register int slen, dlen; + + if (--pos < 0) + return; + dlen = (int) strlen(dst); + dst += dlen; + dlen -= pos; + if (dlen <= 0) + { + strcpy(dst, src); + return; + } + slen = (int) strlen(src); + do + { + dst[slen] = *dst; + --dst; + } + while (--dlen >= 0); + dst++; + while (--slen >= 0) + *dst++ = *src++; +} + + + + +/* File functions */ + +/* Peek at next character of input stream; return EOF at end-of-file. */ +int QBasic:: +P_peek(FILE * f) +{ + int ch; + + ch = getc(f); + if (ch == EOF) + return EOF; + ungetc(ch, f); + return (ch == '\n') ? ' ' : ch; +} + + +/* Check if at end of file, using Pascal "eof" semantics. End-of-file for + stdin is broken; remove the special case for it to be broken in a + different way. */ +/*int P_eof(FILE *f)*/ +int QBasic:: +P_eof(void) +{ + return 0; +} + + +/* Check if at end of line (or end of entire file). */ +int QBasic:: +P_eoln(FILE * f) +{ + register int ch; + + ch = getc(f); + if (ch == EOF) + return 1; + ungetc(ch, f); + return (ch == '\n'); +} + + +/* Read a packed array of characters from a file. */ +void QBasic:: +P_readpaoc(FILE * f, char *l_s, int len) +{ + int ch; + + for (;;) + { + if (len <= 0) + return; + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + *l_s++ = (char) ch; + --len; + } + while (--len >= 0) + *l_s++ = ' '; + if (ch != EOF) + ungetc(ch, f); +} + +void QBasic:: +P_readlnpaoc(FILE * f, char *l_s, int len) +{ + int ch; + + for (;;) + { + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + if (len > 0) + { + *l_s++ = (char) ch; + --len; + } + } + while (--len >= 0) + *l_s++ = ' '; +} + + +/* Compute maximum legal "seek" index in file (0-based). */ +long QBasic:: +P_maxpos(FILE * f) +{ + long savepos = ftell(f); + long val; + + if (fseek(f, 0L, SEEK_END)) + return -1; + val = ftell(f); + if (fseek(f, savepos, SEEK_SET)) + return -1; + return val; +} + + +/* Use packed array of char for a file name. */ +char * QBasic:: +P_trimname(register char * fn, register int len) +{ + static char fnbuf[256]; + register char *cp = fnbuf; + + while (--len >= 0 && *fn && !isspace((int) *fn)) + *cp++ = *fn++; + *cp = 0; + return fnbuf; +} + + + + +/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. + We fix memory size as 10Meg as a reasonable compromise. */ + +long QBasic:: +memavail(void) +{ + return 10000000; /* worry about this later! */ +} + +long QBasic:: +maxavail(void) +{ + return memavail(); +} + + + + +/* Sets are stored as an array of longs. S[0] is the size of the set; + S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum + I such that S[I] is nonzero. S[0] is zero for an empty set. Within + each long, bits are packed from lsb to msb. The first bit of the + set is the element with ordinal value 0. (Thus, for a "set of 5..99", + the lowest five bits of the first long are unused and always zero.) */ + +/* (Sets with 32 or fewer elements are normally stored as plain longs.) */ +long * QBasic:: +P_setunion(register long *d, register long *s1, register long *s2) /* d := s1 + s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) + { + *d++ = *s1++ | *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + *dbase = (int) (d - dbase - 1); + return dbase; +} + +long * QBasic:: +P_setint(register long *d, register long *s1, register long *s2) /* d := s1 * s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & *s2++; + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * QBasic:: +P_setdiff(register long *d, register long *s1, register long *s2) /* d := s1 - s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & ~*s2++; + if (sz1 >= 0) + { + while (sz1-- >= 0) + *d++ = *s1++; + } + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * QBasic:: +P_setxor(register long *d, register long *s1, register long *s2) /* d := s1 / s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) + { + *d++ = *s1++ ^ *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * QBasic:: +P_addset(register long *l_s, register unsigned val) /* s := s + [val] */ +{ + register long *sbase = l_s; + register int bit, size; + bit = val % SETBITS; + val /= SETBITS; + size = *l_s; + if ((long) ++val > size) + { + l_s += size; + while ((long) val > size) + *++l_s = 0, size++; + *sbase = size; + } + else + l_s += val; + *l_s |= 1L << bit; + return sbase; +} + +long * QBasic:: +P_addsetr(register long *l_s, register unsigned v1, register unsigned v2) /* s := s + [v1..v2] */ +{ + register long *sbase = l_s; + register int b1, b2, size; + if ((int) v1 > (int) v2) + return sbase; + b1 = v1 % SETBITS; + v1 /= SETBITS; + b2 = v2 % SETBITS; + v2 /= SETBITS; + size = *l_s; + v1++; + if ((int) ++v2 > size) + { + while ((int) v2 > size) + l_s[++size] = 0; + l_s[v2] = 0; + *l_s = v2; + } + l_s += v1; + if (v1 == v2) + { + *l_s |= (~((-2L) << (b2 - b1))) << b1; + } + else + { + *l_s++ |= (-1L) << b1; + while (++v1 < v2) + *l_s++ = -1; + *l_s |= ~((-2L) << b2); + } + return sbase; +} + +long * QBasic:: +P_remset(register long *l_s, register unsigned val) /* s := s - [val] */ +{ + register int bit; + bit = val % SETBITS; + val /= SETBITS; + if ((long) ++val <= *l_s) + { + if (!(l_s[val] &= ~(1L << bit))) + while (*l_s && !l_s[*l_s]) + (*l_s)--; + } + return l_s; +} + +int QBasic:: +P_setequal(register long *s1, register long *s2) /* s1 = s2 */ +{ + register int size = *s1++; + if (*s2++ != size) + return 0; + while (--size >= 0) + { + if (*s1++ != *s2++) + return 0; + } + return 1; +} + +int QBasic:: +P_subset(register long *s1, register long *s2) /* s1 <= s2 */ +{ + register int sz1 = *s1++, sz2 = *s2++; + if (sz1 > sz2) + return 0; + while (--sz1 >= 0) + { + if (*s1++ & ~*s2++) + return 0; + } + return 1; +} + +long * QBasic:: +P_setcpy(register long *d, register long *l_s) /* d := s */ +{ + register long *save_d = d; + +#ifdef SETCPY_MEMCPY + memcpy(d, l_s, (*l_s + 1) * sizeof(long)); +#else + register int i = *l_s + 1; + while (--i >= 0) + *d++ = *l_s++; +#endif + return save_d; +} + + +/* s is a "smallset", i.e., a 32-bit or less set stored + directly in a long. */ +long * QBasic:: +P_expset(register long *d, register long l_s) /* d := s */ +{ + if (l_s) + { + d[1] = l_s; + *d = 1; + } + else + *d = 0; + return d; +} + +long QBasic:: +P_packset(register long *l_s) /* convert s to a small-set */ +{ + if (*l_s++) + return *l_s; + else + return 0; +} + +int QBasic:: +_OutMem(void) +{ + return _Escape(-2); +} + +int QBasic:: +_CaseCheck(void) +{ + return _Escape(-9); +} + +int QBasic:: +_NilCheck(void) +{ + return _Escape(-3); +} + + + + + +/* The following is suitable for the HP Pascal operating system. + It might want to be revised when emulating another system. */ + +char * QBasic:: +_ShowEscape(char *buf, int code, int ior, char *prefix) +{ + char *bufp; + + if (prefix && *prefix) + { + strcpy(buf, prefix); + strcat(buf, ": "); + bufp = buf + strlen(buf); + } + else + { + bufp = buf; + } + if (code == -10) + { + sprintf(bufp, "Pascal system I/O error %d", ior); + switch (ior) + { + case 3: + strcat(buf, " (illegal I/O request)"); + break; + case 7: + strcat(buf, " (bad file name)"); + break; + case FileNotFound: /*10 */ + strcat(buf, " (file not found)"); + break; + case FileNotOpen: /*13 */ + strcat(buf, " (file not open)"); + break; + case BadInputFormat: /*14 */ + strcat(buf, " (bad input format)"); + break; + case 24: + strcat(buf, " (not open for reading)"); + break; + case 25: + strcat(buf, " (not open for writing)"); + break; + case 26: + strcat(buf, " (not open for direct access)"); + break; + case 28: + strcat(buf, " (string subscript out of range)"); + break; + case EndOfFile: /*30 */ + strcat(buf, " (end-of-file)"); + break; + case FileWriteError: /*38 */ + strcat(buf, " (file write error)"); + break; + } + } + else + { + sprintf(bufp, "Pascal system error %d", code); + switch (code) + { + case -2: + strcat(buf, " (out of memory)"); + break; + case -3: + strcat(buf, " (reference to NIL pointer)"); + break; + case -4: + strcat(buf, " (integer overflow)"); + break; + case -5: + strcat(buf, " (divide by zero)"); + break; + case -6: + strcat(buf, " (real math overflow)"); + break; + case -8: + strcat(buf, " (value range error)"); + break; + case -9: + strcat(buf, " (CASE value range error)"); + break; + case -12: + strcat(buf, " (bus error)"); + break; + case -20: + strcat(buf, " (stopped by user)"); + break; + } + } + return buf; +} + +int QBasic:: +_Escape(int code) +{ + char l_buf[100]; + char token[200], empty[2] = { "\0" }; + + P_escapecode = code; + if (__top_jb) + { + __p2c_jmp_buf *jb = __top_jb; + __top_jb = jb->next; + longjmp(jb->jbuf, 1); + } + if (code == 0) + /* exit(EXIT_SUCCESS); */ + error_msg("Exit success in Basic", STOP); + if (code == -1) + { + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", + _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); + error_msg(token, STOP); + exit(EXIT_FAILURE); + } + /* fprintf(stderr, "%s\n", _ShowEscape(l_buf, P_escapecode, P_ioresult, "")); */ + /* exit(EXIT_FAILURE); */ + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); + error_msg(token, STOP); + return (1); +} + +int QBasic:: +_EscIO(int code) +{ + P_ioresult = code; + return _Escape(-10); +} + + + + +/* End. */ diff --git a/QBasic/QBasic.h b/QBasic/QBasic.h new file mode 100644 index 00000000..2154c0b5 --- /dev/null +++ b/QBasic/QBasic.h @@ -0,0 +1,486 @@ +#ifndef _INC_QBASIC_H +#define _INC_QBASIC_H + +#define forloop 0 +#define whileloop 1 +#define gosubloop 2 + +#define checking true +#define varnamelen 20 +#define maxdims 4 + +typedef char varnamestring[varnamelen + 1]; +typedef char string255[256]; + +/* Header file for code generated by "p2c", the Pascal-to-C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "PHRQ_io.h" +#include "Phreeqc.h" + +class QBasic: public PHRQ_io +{ +public: + QBasic(PHRQ_io *phrq_io=NULL); + ~QBasic(); +typedef struct __p2c_jmp_buf +{ + struct __p2c_jmp_buf *next; + jmp_buf jbuf; +} __p2c_jmp_buf; + + +/* Warning: The following will not work if setjmp is used simultaneously. + This also violates the ANSI restriction about using vars after longjmp, + but a typical implementation of longjmp will get it right anyway. */ + + +# define TRY(x) do { __p2c_jmp_buf __try_jb; \ + __try_jb.next = __top_jb; \ + if (!setjmp((__top_jb = &__try_jb)->jbuf)) { +# define RECOVER(x) __top_jb = __try_jb.next; } else { +# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ + { L: __top_jb = __try_jb.next; } +# define ENDTRY(x) } } while (0) + +#define SETBITS 32 + +#define Const + +#define P2PP(x) () +#define PV() () +typedef char *Anyptr; + + + + +#define Register register /* Register variables */ +#define char char /* Characters (not bytes) */ + + + + + +typedef struct varrec +{ + varnamestring name; + struct varrec *next; + long dims[maxdims]; + char numdims; + boolean stringvar; + union + { + struct + { + LDBLE *arr; + LDBLE *val, rv; + } U0; + struct + { + char **sarr; + char **sval, *sv; + } U1; + } UU; +} varrec; +typedef struct tokenrec +{ + struct tokenrec *next; + int kind; + union + { + struct varrec *vp; + LDBLE num; + char *sp; + char snch; + } UU; +#ifdef PHREEQCI_GUI + size_t n_sz; + char *sz_num; +#endif +} tokenrec; +typedef struct linerec +{ + long num, num2; + tokenrec *txt; + char inbuf[MAX_LINE]; + struct linerec *next; +} linerec; +typedef struct valrec +{ + boolean stringval; + union + { + LDBLE val; + char *sval; + } UU; +} valrec; + +typedef struct looprec +{ + struct looprec *next; + linerec *homeline; + tokenrec *hometok; + int kind; + union + { + struct + { + varrec *vp; + LDBLE max, step; + } U0; + } UU; +} looprec; + +/* variables for exec: */ +struct LOC_exec +{ + boolean gotoflag, elseflag; + tokenrec *t; +}; + // Methods + int free_dim_stringvar(varrec *varbase); + void exec(void); + int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); + void restoredata(void); + void clearloops(void); + void clearvar(varrec * v); + void clearvars(void); + char * numtostr(char * Result, LDBLE n); + void parse(char * inbuf, tokenrec ** buf); + void listtokens(FILE * f, tokenrec * buf); + void disposetokens(tokenrec ** tok); + void parseinput(tokenrec ** buf); + void errormsg(const char * s); + void snerr(const char * s); + void tmerr(const char * s); + void badsubscr(void); + LDBLE realfactor(struct LOC_exec *LINK); + char * strfactor(struct LOC_exec * LINK); + char *stringfactor(char * Result, struct LOC_exec *LINK); + long intfactor(struct LOC_exec *LINK); + LDBLE realexpr(struct LOC_exec *LINK); + char * strexpr(struct LOC_exec * LINK); + char * stringexpr(char * Result, struct LOC_exec * LINK); + long intexpr(struct LOC_exec *LINK); + void require(int k, struct LOC_exec *LINK); + void skipparen(struct LOC_exec *LINK); + QBasic::varrec * findvar(struct LOC_exec *LINK); + QBasic::valrec factor(struct LOC_exec *LINK); + QBasic::valrec upexpr(struct LOC_exec * LINK); + QBasic::valrec term(struct LOC_exec * LINK); + QBasic::valrec sexpr(struct LOC_exec * LINK); + QBasic::valrec relexpr(struct LOC_exec * LINK); + QBasic::valrec andexpr(struct LOC_exec * LINK); + valrec expr(struct LOC_exec *LINK); + void checkextra(struct LOC_exec *LINK); + boolean iseos(struct LOC_exec *LINK); + void skiptoeos(struct LOC_exec *LINK); + linerec * findline(long n); + linerec * mustfindline(long n); + void cmdend(struct LOC_exec *LINK); + void cmdnew(struct LOC_exec *LINK); + void cmdlist(struct LOC_exec *LINK); + void cmdload(boolean merging, char * name, struct LOC_exec *LINK); + void cmdrun(struct LOC_exec *LINK); + void cmdsave(struct LOC_exec *LINK); + void cmdput(struct LOC_exec *LINK); + void cmdchange_por(struct LOC_exec *LINK); + void cmdchange_surf(struct LOC_exec *LINK); + void cmdbye(void); + void cmddel(struct LOC_exec *LINK); + void cmdrenum(struct LOC_exec *LINK); + void cmdprint(struct LOC_exec *LINK); + void cmdpunch(struct LOC_exec *LINK); + #if defined PHREEQ98 || defined MULTICHART + void cmdgraph_x(struct LOC_exec *LINK); + void cmdgraph_y(struct LOC_exec *LINK); + void cmdgraph_sy(struct LOC_exec *LINK); + #endif + #if defined MULTICHART + void cmdplot_xy(struct LOC_exec *LINK); + #endif + void cmdlet(boolean implied, struct LOC_exec *LINK); + void cmdgoto(struct LOC_exec *LINK); + void cmdif(struct LOC_exec *LINK); + void cmdelse(struct LOC_exec *LINK); + boolean skiploop(int up, int dn, struct LOC_exec *LINK); + void cmdfor(struct LOC_exec *LINK); + void cmdnext(struct LOC_exec *LINK); + void cmdwhile(struct LOC_exec *LINK); + void cmdwend(struct LOC_exec *LINK); + void cmdgosub(struct LOC_exec *LINK); + void cmdreturn(struct LOC_exec *LINK); + void cmdread(struct LOC_exec *LINK); + void cmddata(struct LOC_exec *LINK); + void cmdrestore(struct LOC_exec *LINK); + void cmdgotoxy(struct LOC_exec *LINK); + void cmdon(struct LOC_exec *LINK); + void cmddim(struct LOC_exec *LINK); + void cmdpoke(struct LOC_exec *LINK); +int basic_main(char *commands); +void cmd_initialize(void); +void cmd_free(void); +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +int basic_init(void); +#ifdef PHREEQ98 +void GridChar(char *s, char *a); +#endif +int sget_logical_line(char **ptr, int *l, char *return_line); +void PASCAL_MAIN(int argc, char **argv); +long my_labs(long x); +Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); +Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); +int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); +Anyptr my_memset(Anyptr d, int c, size_t n); +int my_toupper(int c); +int my_tolower(int c); +long ipow(long a, long b); +char * strsub(register char *ret, register char *s, register int pos, + register int len); +int strpos2(char *s, register char *pat, register int pos); +int strcicmp(register char *s1, register char *s2); +char * strltrim(register char *s); +char * strrtrim(register char *s); +void strmove(register int len, register char *s, register int spos, + register char *d, register int dpos); +void strinsert(register char *src, register char *dst, register int pos); +int P_peek(FILE * f); +int P_eof(void); +int P_eoln(FILE * f); +void P_readpaoc(FILE * f, char *s, int len); +void P_readlnpaoc(FILE * f, char *s, int len); +long P_maxpos(FILE * f); +char * P_trimname(register char * fn, register int len); +long memavail(void); +long maxavail(void); +long * P_setunion(register long *d, register long *s1, register long *s2); +long * P_setint(register long *d, register long *s1, register long *s2); +long * P_setdiff(register long *d, register long *s1, register long *s2); +long * P_setxor(register long *d, register long *s1, register long *s2); +long * P_addset(register long *s, register unsigned val); +long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); +long * P_remset(register long *s, register unsigned val); +int P_setequal(register long *s1, register long *s2); +int P_subset(register long *s1, register long *s2); +long * P_setcpy(register long *d, register long *s); +long * P_expset(register long *d, register long s); +long P_packset(register long *s); +int _OutMem(void); +int _CaseCheck(void); +int _NilCheck(void); +static char * _ShowEscape(char *buf, int code, int ior, char *prefix); +int _Escape(int code); +int _EscIO(int code); + + +protected: + Phreeqc * PhreeqcPtr; + char *inbuf; + linerec *linebase; + varrec *varbase; + looprec *loopbase; + long curline; + linerec *stmtline, *dataline; + tokenrec *stmttok, *datatok, *buf; + boolean exitflag; + long EXCP_LINE; + HashTable *command_hash_table; + struct const_key *command; + int NCMDS; + Anyptr __MallocTemp__; + int P_argc; + char **P_argv; + int P_escapecode; + int P_ioresult; + __p2c_jmp_buf *__top_jb; + + int max_line; +}; + + +/* Following defines are suitable for the HP Pascal operating system */ +#define FileNotFound 10 +#define FileNotOpen 13 +#define FileWriteError 38 +#define BadInputFormat 14 +#define EndOfFile 30 + + + + + + +#define tokvar 0 +#define toknum 1 +#define tokstr 2 +#define toksnerr 3 +#define tokplus 4 +#define tokminus 5 +#define toktimes 6 +#define tokdiv 7 +#define tokup 8 +#define toklp 9 +#define tokrp 10 +#define tokcomma 11 +#define toksemi 12 +#define tokcolon 13 +#define tokeq 14 +#define toklt 15 +#define tokgt 16 +#define tokle 17 +#define tokge 18 +#define tokne 19 +#define tokand 20 +#define tokor 21 +#define tokxor 22 +#define tokmod 23 +#define toknot 24 +#define toksqr 25 +#define toksqrt 26 +#define toksin 27 +#define tokcos 28 +#define toktan 29 +#define tokarctan 30 +#define toklog 31 +#define tokexp 32 +#define tokabs 33 +#define toksgn 34 +#define tokstr_ 35 +#define tokval 36 +#define tokchr_ 37 +#define tokasc 38 +#define toklen 39 +#define tokmid_ 40 +#define tokpeek 41 +#define tokrem 42 +#define toklet 43 +#define tokprint 44 +#define tokinput 45 +#define tokgoto 46 +#define tokif 47 +#define tokend 48 +#define tokstop 49 +#define tokfor 50 +#define toknext 51 +#define tokwhile 52 +#define tokwend 53 +#define tokgosub 54 +#define tokreturn 55 +#define tokread 56 +#define tokdata 57 +#define tokrestore 58 +#define tokgotoxy 59 +#define tokon 60 +#define tokdim 61 +#define tokpoke 62 +#define toklist 63 +#define tokrun 64 +#define toknew 65 +#define tokload 66 +#define tokmerge 67 +#define toksave 68 +#define tokbye 69 +#define tokdel 70 +#define tokrenum 71 +#define tokthen 72 +#define tokelse 73 +#define tokto 74 +#define tokstep 75 +#define toktc 76 +#define tokm0 77 +#define tokm 78 +#define tokparm 79 +#define tokact 80 +#define tokmol 81 +#define tokla 82 +#define toklm 83 +#define toksr 84 +#define toksi 85 +#define toktot 86 +#define toktk 87 +#define toktime 88 +#define toklog10 89 +#define toksim_time 90 +#define tokequi 91 +#define tokgas 92 +#define tokpunch 93 +#define tokkin 94 +#define toks_s 95 +#define tokmu 96 +#define tokalk 97 +#define tokrxn 98 +#define tokdist 99 +#define tokmisc1 100 +#define tokmisc2 101 +#define tokedl 102 +#define tokstep_no 103 +#define toksim_no 104 +#define toktotal_time 105 +#define tokput 106 +#define tokget 107 +#define tokcharge_balance 109 +#define tokpercent_error 110 +#if defined PHREEQ98 || MULTICHART +#define tokgraph_x 111 +#define tokgraph_y 112 +#define tokgraph_sy 113 +#endif +#define tokcell_no 114 +#define tokexists 115 +#define toksurf 116 +#define toklk_species 117 +#define toklk_named 118 +#define toklk_phase 119 +#define toksum_species 120 +#define toksum_gas 121 +#define toksum_s_s 122 +#define tokcalc_value 123 +#define tokdescription 124 +#define toksys 125 +#define tokinstr 126 +#define tokltrim 127 +#define tokrtrim 128 +#define toktrim 129 +#define tokpad 130 +#define tokchange_por 131 +#define tokget_por 132 +#define tokosmotic 133 +#define tokchange_surf 134 +#define tokporevolume 135 +#define toksc 136 +#define tokgamma 137 +#define toklg 138 +/* VP: Density Start */ +#define tokrho 139 +/* VP: Density End */ +#define tokcell_volume 140 +#define tokcell_pore_volume 141 +#define tokcell_porosity 142 +#define tokcell_saturation 143 +#if defined MULTICHART +#define tokplot_xy 144 +#endif +#define toktotmole 145 +#define tokiso 146 +#define tokiso_unit 147 +#define toktotmol 148 +#define toktotmoles 149 +#define tokeol_ 150 +#define tokceil 151 +#define tokfloor 152 +#define tokphase_formula 153 +#define toklist_s_s 154 + +#endif /* _INC_QBASIC_H */ diff --git a/QBasic/global.h b/QBasic/global.h new file mode 100644 index 00000000..4e44db62 --- /dev/null +++ b/QBasic/global.h @@ -0,0 +1,808 @@ +#ifndef _INC_GLOBAL_H +#define _INC_GLOBAL_H + + PHRQ_io *phrq_io; + +/* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ + + struct model last_model; + int same_model; + int same_temperature; + struct punch punch; +/* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ + + struct temperature *temperature; + int count_temperature; +/* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + + int g_iterations; + LDBLE G_TOL; + struct surface *surface; + struct surface *dbg_surface; + int count_surface; + int max_surface; + struct Charge_Group *charge_group; + int change_surf_count; + struct Change_Surf *change_surf; + +/* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + + struct exchange *exchange; + struct exchange *dbg_exchange; + int count_exchange; + int max_exchange; +/* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + + struct kinetics *kinetics; + struct kinetics *dbg_kinetics; + int count_kinetics; + int max_kinetics; + + int count_save_values; + struct save_values *save_values; + +/*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + + struct save save; +/*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ + + struct Use use; + struct Use *dbg_use; +/*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ + + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_s_s_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_irrev; + struct copier copy_temperature; + + +/*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + struct inverse *inverse; + int count_inverse; + +/*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + + struct mix *mix; + struct mix *dbg_mix; + int count_mix; +/*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + + struct irrev *irrev; + struct irrev *dbg_irrev; + int count_irrev; +/*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + + int count_gas_phase; + int max_gas_phase; + struct gas_phase *gas_phase; +/*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + + int count_s_s_assemblage; + int max_s_s_assemblage; + struct s_s_assemblage *s_s_assemblage; +/*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + + int count_pp_assemblage; + int max_pp_assemblage; + struct pp_assemblage *pp_assemblage; + struct pp_assemblage *dbg_pp_assemblage; +/*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + + int count_species_list; + int max_species_list; + struct species_list *species_list; +/*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ +/*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + + struct solution **solution; + struct solution **dbg_solution; + int count_solution; + int max_solution; + +struct iso *iso_defaults; +int count_iso_defaults; + +/*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + struct pe_data *pe_x; + int count_isotopes_x; + struct isotope *isotopes_x; + int default_pe_x; +/* int diffuse_layer_x;*/ + enum DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; +/*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ + + int cell_no; +/*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; + +/*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ +struct const_key *keyword; +int NKEYS; + + struct key *keyword_hash; + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, + new_pitzer; +/*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; + +/*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; +/*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ + +/*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + + struct logk **logk; + int count_logk; + int max_logk; + + char *moles_per_kilogram_string; + char *pe_string; + + struct species **s; + int count_s; + int max_s; + + struct species **s_x; + int count_s_x; + int max_s_x; + + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; +/*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + + struct phase **phases; + int count_phases; + int max_phases; +/*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; +/*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + + struct unknown **x; + int count_unknowns; + int max_unknowns; + + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *s_s_unknown; +/*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; + + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; +/* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + + struct prints pr; + int status_on, status_interval; + float status_timer; + int count_warnings; + +/* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + int count_rate_p; +/* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + char **user_punch_headings; + int user_punch_count_headings; +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + ChartHandler chart_handler; +#endif + +/* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + char error_string[10 * MAX_LENGTH]; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; + + int count_strings; + int max_strings; + + LDBLE *array; + LDBLE *delta; + LDBLE *residual; + + int input_error; + + int next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; + + int max_line; + char *line; + char *line_save; + + LDBLE LOG_10; + + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; + + LDBLE inv_tol_default; + int itmax; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; + + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; + + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; + +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + +/* ---------------------------------------------------------------------- */ +/* + * Hash definitions + */ + + HashTable *strings_hash_table; + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *keyword_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ +/* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + struct name_coef match_tokens[50]; + int count_match_tokens; + + int count_master_isotope; + struct master_isotope **master_isotope; + int max_master_isotope; + int initial_solution_isotopes; + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPT_1 -5 + + + int count_calculate_value; + struct calculate_value **calculate_value; + int max_calculate_value; + HashTable *calculate_value_hash_table; + + + int count_isotope_ratio; + struct isotope_ratio **isotope_ratio; + int max_isotope_ratio; + HashTable *isotope_ratio_hash_table; + + int count_isotope_alpha; + struct isotope_alpha **isotope_alpha; + int max_isotope_alpha; + HashTable *isotope_alpha_hash_table; + + int phreeqc_mpi_myself; + + int first_read_input; + char *user_database; + int pitzer_model, sit_model, pitzer_pe; + int full_pitzer, always_full_pitzer, ICON, IC; + LDBLE COSMOT; + LDBLE AW; + int have_punch_name; +/* VP: Density Start */ + int print_density; +/* VP: Density End */ + + jmp_buf mark; + LDBLE *zeros; + int zeros_max; +#if defined(WIN32) +#include +#endif + +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif + + LDBLE cell_pore_volume; + LDBLE cell_porosity; + LDBLE cell_volume; + LDBLE cell_saturation; + + struct system_species *sys; + int count_sys, max_sys; + + LDBLE sys_tot; + LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE solution_mass, solution_volume; + LDBLE f_rho(LDBLE rho_old); + +/* phqalloc.c ------------------------------- */ + + PHRQMemHeader *s_pTail; +#include + std::stringstream merged_database_stream; + std::stringstream merged_input_stream; +/* Collect all statics for PHREEQC_CLASS */ + +/* basic.c ------------------------------- */ + +#ifdef PHREEQ98 +int colnr, rownr; +#endif + +int n_user_punch_index; +//Char *inbuf; +//linerec *linebase; +//varrec *varbase; +//looprec *loopbase; +//long curline; +//linerec *stmtline, *dataline; +//tokenrec *stmttok, *datatok, *buf; +//boolean exitflag; +//long EXCP_LINE; +//HashTable *command_hash_table; +//struct const_key *command; +//int NCMDS; + +/* cl1.c ------------------------------- */ + +LDBLE *x_arg, *res_arg, *scratch; +int x_arg_max, res_arg_max, scratch_max; + +/* dw.c ------------------------------- */ + +/* COMMON /QQQQ/ */ +LDBLE Q0, Q5; +LDBLE GASCON, TZ, AA; +LDBLE Z, DZ, Y; +LDBLE G1, G2, GF; +LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + +/* input.cpp ------------------------------- */ + +int check_line_return; + +/* integrate.cpp ------------------------------- */ + +LDBLE midpoint_sv; +LDBLE z, xd, alpha; +struct surface_charge *surface_charge_ptr; +int max_row_count, max_column_count; +int carbon; +char **col_name, **row_name; +int count_rows, count_optimize; +int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; +int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; +LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; +LDBLE *min_delta, *max_delta; +int *iu, *is; +int klmd, nklmd, n2d, kode, iter; +LDBLE toler, error, max_pct, scaled_error; +struct master *master_alk; +int *row_back, *col_back; +unsigned long *good, *bad, *minimal; +int max_good, max_bad, max_minimal; +int count_good, count_bad, count_minimal, count_calls; +unsigned long soln_bits, phase_bits, current_bits, temp_bits; + +/* inverse.c ------------------------------- */ + +FILE *netpath_file; +int count_inverse_models, count_pat_solutions; +int min_position[32], max_position[32], now[32]; + +/* kinetics.c ------------------------------- */ + +public: + void *cvode_kinetics_ptr; + int cvode_test; + int cvode_error; + int cvode_n_user; + int cvode_n_reactions; + realtype cvode_step_fraction; + realtype cvode_rate_sim_time; + realtype cvode_rate_sim_time_start; + realtype cvode_last_good_time; + realtype cvode_prev_good_time; + N_Vector cvode_last_good_y; + N_Vector cvode_prev_good_y; + M_Env kinetics_machEnv; + N_Vector kinetics_y, kinetics_abstol; + void *kinetics_cvode_mem; + struct pp_assemblage *cvode_pp_assemblage_save; + struct s_s_assemblage *cvode_s_s_assemblage_save; + LDBLE *m_original; + LDBLE *m_temp; + +/* model.c ------------------------------- */ + +LDBLE min_value; +/* LDBLE model_min_value; */ +LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; +int *inv_iu, *inv_is, *back_eq; +int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; + +/* phrq_io_output.c ------------------------------- */ +int forward_output_to_log; + +/* phreeqc_files.c ------------------------------- */ + +char *default_data_base; +#ifdef PHREEQ98 +int outputlinenr; +char *LogFileNameC; +char progress_str[512]; +#endif +//Anyptr __MallocTemp__; +//int P_argc; +//char **P_argv; +//int P_escapecode; +//int P_ioresult; +//__p2c_jmp_buf *__top_jb; + +/* pitzer.c ------------------------------- */ + +LDBLE A0; +struct species **spec, **cations, **anions, **neutrals; +int count_cations, count_anions, count_neutrals; +int MAXCATIONS, FIRSTANION, MAXNEUTRAL; +struct pitz_param *mcb0, *mcb1, *mcc0; +int *IPRSNT; +LDBLE *M, *LGAMMA; +LDBLE BK[23], DK[23]; +#ifdef PHREEQ98 +int connect_simulations, graph_initial_solutions; +int shifts_as_points; +int chart_type; +int ShowChart; +int RowOffset, ColumnOffset; +#endif +LDBLE dummy; + +/* print.c ------------------------------- */ + +#ifdef PHREEQ98 +int colnr, rownr; +int graph_initial_solutions; +int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ +/* int shifts_as_points; */ +int chart_type; +int AddSeries; +int FirstCallToUSER_GRAPH; +#endif +/* read.c */ +char *prev_next_char; +#if defined PHREEQ98 +int shifts_as_points; +#endif + +/* read_class.cxx */ +dumper dump_info; +StorageBinList delete_info; +runner run_info; +char * sformatf_buffer; +size_t sformatf_buffer_size; + +/* readtr.c */ + +std::string dump_file_name_cpp; + +/* sit.c ------------------------------- */ + +LDBLE sit_A0; +int sit_count_cations, sit_count_anions, sit_count_neutrals; +int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; +int *sit_IPRSNT; +LDBLE *sit_M, *sit_LGAMMA; + +/* tidy.c ------------------------------- */ + +LDBLE a0, a1, kc, kb; + +/* tally.c ------------------------------- */ + + +struct tally_buffer *t_buffer; +int tally_count_component; + +struct tally *tally_table; +int count_tally_table_columns; +int count_tally_table_rows; + +/* transport.c ------------------------------- */ + + +struct sol_D *sol_D; +struct sol_D *sol_D_dbg; +struct J_ij *J_ij, *J_ij_il; +int J_ij_count_spec; + +struct M_S *m_s; +int count_m_s; +LDBLE tot1_h, tot1_o, tot2_h, tot2_o; +LDBLE diffc_max, diffc_tr, J_ij_sum; +int transp_surf; +LDBLE *heat_mix_array; +LDBLE *temp1, *temp2; +int nmix, heat_nmix; +LDBLE heat_mix_f_imm, heat_mix_f_m; +int warn_MCD_X, warn_fixed_Surf; + +/* utilities.c ------------------------------- */ + +#ifdef PHREEQ98 +int AutoLoadOutputFile, CreateToC; +int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; +int outputlinenr; +int stop_calculations; +char err_str98[80]; +#endif + + +#endif /* _INC_GLOBAL_H */ + +/********************************* + isfinite handling + (Note: Should NOT be guarded) +**********************************/ + +#if defined (PHREEQ98) || defined (_MSC_VER) +# define HAVE_FINITE +# define finite _finite +#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ +# if defined(DJGPP) +# define HAVE_FINITE +# endif +#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ + +#if defined(HAVE_ISFINITE) +# define PHR_ISFINITE(x) isfinite(x) +#elif defined(HAVE_FINITE) +# define PHR_ISFINITE(x) finite(x) +#elif defined(HAVE_ISNAN) +# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) +#else +# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) +#endif diff --git a/QBasic/global_structures.h b/QBasic/global_structures.h new file mode 100644 index 00000000..74124408 --- /dev/null +++ b/QBasic/global_structures.h @@ -0,0 +1,1375 @@ +#ifndef _INC_GLOBAL_STRUCTURES_H +#define _INC_GLOBAL_STRUCTURES_H + +#include "phrqtype.h" +typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; +enum SURFACE_TYPE +{ UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC, CCM }; +enum DIFFUSE_LAYER_TYPE +{ NO_DL, BORKOVEK_DL, DONNAN_DL }; +enum SITES_UNITS +{ SITES_ABSOLUTE, SITES_DENSITY }; +enum entity_type +{ Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, + Kinetics, Mix, Temperature, UnKnown +}; +/* must be defined here and in cl.c */ +/* #include */ +#ifndef NAN +# define NAN -99999999 +#endif +#define MISSING -9999.999 +//#define NA -98.765 /* NA = not available */ +#include "NA.h" +/* search.h -- declarations for POSIX/SVID-compatible search functions */ + + + +/* ---------------------------------------------------------------------- + * DEFINITIONS + * ---------------------------------------------------------------------- */ +#define F_C_MOL 96493.5 /* C/mol or joule/volt-eq */ +#define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ +#define F_KCAL_V_EQ 23.0623 /* kcal/volt-eq */ +#define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ +#define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ +#define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ +#define EPSILON 78.5 /* dialectric constant, dimensionless */ +#define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ +#define JOULES_PER_CALORIE 4.1840 +#define AVOGADRO 6.02252e23 /* atoms / mole */ + + +#define TRUE 1 +#define FALSE 0 +#define OK 1 +#define ERROR 0 +#define STOP 1 +#define CONTINUE 0 + +#define DISP 2 +#define STAG 3 +#define NOMIX 4 + +#define CONVERGED 2 +#define MASS_BALANCE 3 +/* + #define OSCILLATE 4 + #define H2O_LIMITS 5 +*/ +#define REWRITE 2 +#define INIT -1 + +/* check_line values, plus EMPTY, EOF, OK */ +#define KEYWORD 3 + +/* copy_token values */ +#define EMPTY 2 +#define UPPER 4 +#define LOWER 5 +#define DIGIT 6 +#define UNKNOWN 7 +#define OPTION 8 + +/* species types */ +#define AQ 0 +#define HPLUS 1 +#define H2O 2 +#define EMINUS 3 +#define SOLID 4 +#define EX 5 +#define SURF 6 +#define SURF_PSI 7 +#define SURF_PSI1 8 +#define SURF_PSI2 9 + +/* unknown types */ +#define MB 10 +#define ALK 11 +#define CB 12 +#define SOLUTION_PHASE_BOUNDARY 13 +#define MU 14 +#define AH2O 15 +#define MH 16 +#define MH2O 17 +#define PP 18 +#define EXCH 19 +#define SURFACE 20 +#define SURFACE_CB 21 +#define SURFACE_CB1 22 +#define SURFACE_CB2 23 +#define GAS_MOLES 24 +#define S_S_MOLES 25 +#define PITZER_GAMMA 26 +/* state */ +#define INITIALIZE 0 +#define INITIAL_SOLUTION 1 +#define INITIAL_EXCHANGE 2 +#define INITIAL_SURFACE 3 +#define INITIAL_GAS_PHASE 4 +#define REACTION 5 +#define INVERSE 6 +#define ADVECTION 7 +#define TRANSPORT 8 +#define PHAST 9 + +/* constaints in mass balance */ +#define EITHER 0 +#define DISSOLVE 1 +#define PRECIPITATE -1 + +/* gas phase type */ +#define PRESSURE 1 +#define VOLUME 2 + +#define MAX_PP_ASSEMBLAGE 10 /* default estimate of the number of phase assemblages */ +#define MAX_ADD_EQUATIONS 20 /* maximum number of equations added together to reduce eqn to + master species */ +#define MAX_ELEMENTS 50 /* default estimate of the number of elements */ +#define MAX_LENGTH 256 /* maximum number of characters component name */ +#define MAX_LINE 4096 /* estimate of maximum line length */ +#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ +#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +#define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ +#define MAX_MASTER 50 /* default estimate of the number of master species */ +#define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in + an equation */ +#define MAX_PHASES 500 /* initial guess of number of phases defined */ +#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ +#define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ +#define MAX_STRINGS 3000 +#define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ +#define MAX_SUM_MB 500 /* list used to calculate mass balance sums */ +#define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ +#define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ +#define TOL 1e-9 /* tolerance for comparisons of double numbers */ +#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +#define MIN_TOTAL 1e-25 +#define MIN_TOTAL_SS MIN_TOTAL/100 +#define MIN_RELATED_SURFACE MIN_TOTAL*100 +#define MIN_RELATED_LOG_ACTIVITY -30 + + +/* + * Hash definitions + */ +/* +** Constants +*/ + +# define SegmentSize 256 +# define SegmentSizeShift 8 /* log2(SegmentSize) */ +# define DirectorySize 256 +# define DirectorySizeShift 8 /* log2(DirectorySize) */ +# define Prime1 37 +# define Prime2 1048583 +# define DefaultMaxLoadFactor 5 + +/* HSEARCH(3C) */ +typedef struct entry +{ + char *key; + void *data; +} ENTRY; +typedef enum +{ FIND, ENTER } ACTION; + +/* TSEARCH(3C) */ +typedef enum +{ preorder, postorder, endorder, leaf } VISIT; + +typedef struct Element +{ + /* + ** The user only sees the first two fields, + ** as we pretend to pass back only a pointer to ENTRY. + ** {S}he doesn't know what else is in here. + */ + char *Key; + char *Data; + struct Element *Next; /* secret from user */ +} Element, *Segment; + +typedef struct +{ + short p; /* Next bucket to be split */ + short maxp; /* upper bound on p during expansion */ + long KeyCount; /* current # keys */ + short SegmentCount; /* current # segments */ + short MinLoadFactor; + short MaxLoadFactor; + Segment *Directory[DirectorySize]; +} HashTable; + +typedef unsigned long Address; + +typedef struct PHRQMemHeader +{ + struct PHRQMemHeader *pNext; /* memory allocated just after this one */ + struct PHRQMemHeader *pPrev; /* memory allocated just prior to this one */ + size_t size; /* memory request + sizeof(PHRQMemHeader) */ +#if !defined(NDEBUG) + char *szFileName; /* file name */ + int nLine; /* line number */ + int dummy; /* alignment */ +#endif +} PHRQMemHeader; + +struct model +{ + int force_prep; + LDBLE temperature; + int count_exchange; + struct master **exchange; + + int count_kinetics; + struct kinetics *kinetics; + + int count_gas_phase; + struct phase **gas_phase; + + int count_s_s_assemblage; + char **s_s_assemblage; + + int count_pp_assemblage; + struct phase **pp_assemblage; + char **add_formula; + LDBLE *si; + + /*int diffuse_layer; */ + /*int edl; */ + enum DIFFUSE_LAYER_TYPE dl_type; + enum SURFACE_TYPE surface_type; + int only_counter_ions; + /*int donnan; */ + LDBLE thickness; + int count_surface_comp; + char **surface_comp; + int count_surface_charge; + char **surface_charge; +}; + +struct name_master +{ + char *name; + struct master *master; +}; +struct name_species +{ + char *name; + struct species *s; +}; +struct name_phase +{ + char *name; + struct phase *phase; +}; +struct punch +{ + int in; + int new_def; + struct name_master *totals; + int count_totals; + struct name_species *molalities; + int count_molalities; + struct name_species *activities; + int count_activities; + struct name_phase *pure_phases; + int count_pure_phases; + struct name_phase *si; + int count_si; + struct name_phase *gases; + int count_gases; + struct name_phase *s_s; + int count_s_s; + struct name_phase *kinetics; + int count_kinetics; + struct name_master *isotopes; + int count_isotopes; + struct name_master *calculate_values; + int count_calculate_values; + int inverse; + int sim; + int state; + int soln; + int dist; + int time; + int step; + int rxn; + int temp; + int ph; + int pe; + int alk; + int mu; + int water; + int high_precision; + int user_punch; + int charge_balance; + int percent_error; +}; +/* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ +struct temperature +{ + int n_user; + int n_user_end; + char *description; + LDBLE *t; + int count_t; +}; +/* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ +struct surface +{ + int n_user; + int n_user_end; + int new_def; + /*int diffuse_layer; */ + /*int edl; */ + int only_counter_ions; + /*int donnan; */ + enum DIFFUSE_LAYER_TYPE dl_type; + enum SURFACE_TYPE type; + enum SITES_UNITS sites_units; + LDBLE thickness; + LDBLE debye_lengths; + LDBLE DDL_viscosity; /* viscosity relative to pure water */ + LDBLE DDL_limit; /* limits DDL water to this fraction of bulk water */ + char *description; + int solution_equilibria; + int n_solution; + int count_comps; + struct surface_comp *comps; + int count_charge; + struct surface_charge *charge; + int related_phases; + int related_rate; + int transport; /* transports comp's and charges if true */ +}; +struct surface_comp +{ + char *formula; + struct elt_list *formula_totals; + LDBLE formula_z; + LDBLE moles; + struct master *master; + struct elt_list *totals; + LDBLE la; + int charge; + LDBLE cb; + char *phase_name; + LDBLE phase_proportion; + char *rate_name; + LDBLE Dw; /* diffusion coefficient in water, used in MCD. No transport if 0 */ +}; +struct surface_charge +{ + char *name; + LDBLE specific_area; + LDBLE grams; + LDBLE charge_balance; + LDBLE mass_water; + struct elt_list *diffuse_layer_totals; + int count_g; + struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ + LDBLE la_psi, la_psi1, la_psi2; + LDBLE psi, psi1, psi2; + LDBLE capacitance[2]; + LDBLE sigma0, sigma1, sigma2, sigmaddl; +}; +struct surface_diff_layer +{ + LDBLE charge; + LDBLE g; + LDBLE dg; + LDBLE psi_to_z; +}; + +struct Change_Surf +{ + char *comp_name; + LDBLE fraction; + char *new_comp_name; + LDBLE new_Dw; + int cell_no; + int next; +}; + +struct Charge_Group +{ + LDBLE z; + LDBLE eq; +}; +/* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ +struct exchange +{ + int n_user; + int n_user_end; + int new_def; + char *description; + int solution_equilibria; + int n_solution; + int count_comps; + struct exch_comp *comps; + int related_phases; + int related_rate; + int pitzer_exchange_gammas; +}; +struct exch_comp +{ + char *formula; + LDBLE formula_z; + struct elt_list *formula_totals; + LDBLE moles; + struct master *master; + struct elt_list *totals; + LDBLE la; + LDBLE charge_balance; + char *phase_name; + LDBLE phase_proportion; + char *rate_name; +}; +/* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ +struct kinetics +{ + int n_user; + int n_user_end; + char *description; + int count_comps; + struct kinetics_comp *comps; + int count_steps; + LDBLE *steps; + LDBLE step_divide; + /*char *units; */ + struct elt_list *totals; + int rk; + int bad_step_max; + int use_cvode; + int cvode_order; + int cvode_steps; +}; +struct kinetics_comp +{ + char *rate_name; + struct name_coef *list; + int count_list; + /* struct phase *phase; */ + LDBLE tol; + LDBLE m; + LDBLE initial_moles; + LDBLE m0; + LDBLE moles; + int count_c_params; + char **c_params; + int count_d_params; + LDBLE *d_params; +}; + +/*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ +struct save_values +{ + LDBLE value; + int count_subscripts; + int *subscripts; +}; + +struct save +{ + int solution; + int n_solution_user; + int n_solution_user_end; + int mix; + int n_mix_user; + int n_mix_user_end; + int irrev; + int n_irrev_user; + int n_irrev_user_end; + int pp_assemblage; + int n_pp_assemblage_user; + int n_pp_assemblage_user_end; + int exchange; + int n_exchange_user; + int n_exchange_user_end; + int kinetics; + int n_kinetics_user; + int n_kinetics_user_end; + int surface; + int n_surface_user; + int n_surface_user_end; + int gas_phase; + int n_gas_phase_user; + int n_gas_phase_user_end; + int s_s_assemblage; + int n_s_s_assemblage_user; + int n_s_s_assemblage_user_end; +}; +/*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ +struct Use +{ + int solution_in; + int n_solution_user; + int n_solution; + struct solution *solution_ptr; + + int pp_assemblage_in; + int n_pp_assemblage_user; + int n_pp_assemblage; + struct pp_assemblage *pp_assemblage_ptr; + + int mix_in; + int n_mix_user; + int n_mix; + struct mix *mix_ptr; + int n_mix_user_orig; + + int irrev_in; + int n_irrev_user; + int n_irrev; + struct irrev *irrev_ptr; + + int exchange_in; + int n_exchange_user; + int n_exchange; + struct exchange *exchange_ptr; + + int kinetics_in; + int n_kinetics_user; + int n_kinetics; + struct kinetics *kinetics_ptr; + + int surface_in; + int n_surface_user; + int n_surface; + struct surface *surface_ptr; + + int temperature_in; + int n_temperature_user; + int n_temperature; + struct temperature *temperature_ptr; + + int inverse_in; + int n_inverse_user; + int n_inverse; + struct inverse *inverse_ptr; + + int gas_phase_in; + int n_gas_phase_user; + int n_gas_phase; + struct gas_phase *gas_phase_ptr; + + int s_s_assemblage_in; + int n_s_s_assemblage_user; + int n_s_s_assemblage; + struct s_s_assemblage *s_s_assemblage_ptr; + + int trans_in; + int advect_in; +}; +/*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ +struct copier +{ + int count; + int max; + int *n_user; + int *start; + int *end; +}; + +/*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ +struct inverse +{ + int n_user; + char *description; + int new_def; + int minimal; + int range; + int mp; + LDBLE mp_censor; + LDBLE range_max; + LDBLE tolerance; + LDBLE mp_tolerance; + int count_uncertainties; + LDBLE *uncertainties; + int count_ph_uncertainties; + LDBLE *ph_uncertainties; + LDBLE water_uncertainty; + int mineral_water; + int carbon; + LDBLE *dalk_dph; + LDBLE *dalk_dc; + int count_solns; + int *solns; + int count_force_solns; + int *force_solns; + int count_elts; + struct inv_elts *elts; + int count_phases; + struct inv_phases *phases; + int count_master_list; + struct master **master_list; + int count_redox_rxns; + int count_isotopes; + struct inv_isotope *isotopes; + int count_i_u; + struct inv_isotope *i_u; + int count_isotope_unknowns; + struct isotope *isotope_unknowns; + char *netpath; + char *pat; +}; +struct inv_elts +{ + char *name; + struct master *master; + int row; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_isotope +{ + char *isotope_name; + LDBLE isotope_number; + char *elt_name; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_phases +{ + char *name; + struct phase *phase; + int column; + int constraint; + int force; + int count_isotopes; + struct isotope *isotopes; +}; + +/*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ +struct mix +{ + int n_user; + int n_user_end; + char *description; + int count_comps; + struct mix_comp *comps; +}; +struct mix_comp +{ + int n_solution; + LDBLE fraction; +}; + +/*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ +struct irrev +{ + int n_user; + int n_user_end; + char *description; + struct name_coef *list; + struct elt_list *elts; + LDBLE *steps; + char *units; + int count_steps; + int count_list; +}; +struct name_coef +{ + char *name; + LDBLE coef; +}; +/*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ +struct gas_phase +{ + int n_user; + int n_user_end; + char *description; + int new_def; + int solution_equilibria; + int n_solution; + int type; + LDBLE total_p; + LDBLE total_moles; + LDBLE volume; + LDBLE temperature; + int count_comps; + struct gas_comp *comps; +}; +struct gas_comp +{ + struct phase *phase; + char *name; + LDBLE p_read; + LDBLE moles; + LDBLE initial_moles; +}; + +/*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ +struct s_s_assemblage +{ + int n_user; + int n_user_end; + char *description; + int new_def; + /* int type; */ + /* int solution_equilibria; */ + /* int n_solution; */ + int count_s_s; + struct s_s *s_s; +}; +struct s_s +{ + char *name; + struct s_s_comp *comps; + int count_comps; + LDBLE total_moles; + LDBLE dn; + LDBLE a0, a1; + LDBLE ag0, ag1; + int s_s_in; + int miscibility; + int spinodal; + LDBLE tk, xb1, xb2; + int input_case; + LDBLE p[4]; +}; +struct s_s_comp +{ + char *name; + struct phase *phase; + LDBLE initial_moles; + LDBLE moles; + LDBLE init_moles; + LDBLE delta; + LDBLE fraction_x; + LDBLE log10_lambda; + LDBLE log10_fraction_x; + LDBLE dn, dnc, dnb; +}; + +/*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + struct pp_assemblage + { + int n_user; + int n_user_end; + char *description; + int new_def; + struct elt_list *next_elt; + int count_comps; + struct pure_phase *pure_phases; + }; + struct pure_phase + { + struct phase *phase; + char *name; + char *add_formula; + LDBLE si; + LDBLE moles; + LDBLE delta; + LDBLE initial_moles; + int force_equality; + int dissolve_only; + int precipitate_only; +}; + +/*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ +struct species_list +{ + struct species *master_s; + struct species *s; + LDBLE coef; +}; + +/*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ +struct list0 +{ + LDBLE *target; + LDBLE coef; +}; +struct list1 +{ + LDBLE *source; + LDBLE *target; +}; +struct list2 +{ + LDBLE *source; + LDBLE *target; + LDBLE coef; +}; + +/*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + struct solution + { + int new_def; + int n_user; + int n_user_end; + char *description; + LDBLE tc; + LDBLE ph; + LDBLE solution_pe; + LDBLE mu; + LDBLE ah2o; + LDBLE density; + LDBLE total_h; + LDBLE total_o; + LDBLE cb; + LDBLE mass_water; + LDBLE total_alkalinity; + char *units; + struct pe_data *pe; + int default_pe; + struct conc *totals; + struct master_activity *master_activity; + int count_master_activity; + int count_isotopes; + struct isotope *isotopes; + struct master_activity *species_gamma; + int count_species_gamma; + }; + struct master_activity + { + char *description; + LDBLE la; + }; + struct conc + { + char *description; + /*int skip; */ + LDBLE moles; + LDBLE input_conc; + char *units; + char *equation_name; + struct phase *phase; + LDBLE phase_si; + int n_pe; + char *as; + LDBLE gfw; + }; + struct pe_data + { + char *name; + struct reaction *rxn; + }; + struct isotope + { + LDBLE isotope_number; + char *elt_name; + char *isotope_name; + LDBLE total; + LDBLE ratio; + LDBLE ratio_uncertainty; + LDBLE x_ratio_uncertainty; + struct master *master; + struct master *primary; + LDBLE coef; /* coefficient of element in phase */ +}; +struct iso +{ + const char *name; + LDBLE value; + LDBLE uncertainty; +}; +/*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ +struct stag_data +{ + int count_stag; + LDBLE exch_f; + LDBLE th_m; + LDBLE th_im; +}; +struct cell_data +{ + LDBLE length; + LDBLE mid_cell_x; + LDBLE disp; + LDBLE temp; + LDBLE por; /* free (uncharged) porewater porosities */ + LDBLE por_il; /* interlayer water porosities */ + int punch; + int print; +}; + +/*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ + struct key + { + char *name; + int keycount; + }; + struct const_key + { + const char *name; + int keycount; +}; + +/*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ +struct element +{ + char *name; /* element name */ + /* int in; */ + struct master *master; + struct master *primary; + LDBLE gfw; +}; +/*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ +struct elt_list +{ /* list of name and number of elements in an equation */ + struct element *elt; /* pointer to element structure */ + LDBLE coef; /* number of element e's in eqn */ +}; +/*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ +struct reaction +{ + LDBLE logk[8]; + LDBLE dz[3]; + struct rxn_token *token; +}; +struct rxn_token +{ + struct species *s; + LDBLE coef; + char *name; +}; +/*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ +struct species +{ /* all data pertinent to an aqueous species */ + char *name; /* name of species */ + char *mole_balance; /* formula for mole balance */ + int in; /* species used in model if TRUE */ + int number; + struct master *primary; /* points to master species list, NULL if not primary master */ + struct master *secondary; /* points to master species list, NULL if not secondary master */ + LDBLE gfw; /* gram formula wt of species */ + LDBLE z; /* charge of species */ + LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */ + LDBLE erm_ddl; /* enrichment factor in DDL */ + LDBLE equiv; /* equivalents in exchange species */ + LDBLE alk; /* alkalinity of species, used for cec in exchange */ + LDBLE carbon; /* stoichiometric coefficient of carbon in species */ + LDBLE co2; /* stoichiometric coefficient of C(4) in species */ + LDBLE h; /* stoichiometric coefficient of H in species */ + LDBLE o; /* stoichiometric coefficient of O in species */ + LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ +/* VP: Density Start */ + LDBLE millero[6]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ +/* VP: Density End */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + struct name_coef *add_logk; + LDBLE lg; /* log10 activity coefficient, gamma */ + LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */ + LDBLE lm; /* log10 molality */ + LDBLE la; /* log10 activity */ + LDBLE dg; /* gamma term for jacobian */ + LDBLE dg_total_g; + LDBLE moles; /* moles in solution; moles/mass_water = molality */ + int type; /* flag indicating presence in model and types of equations */ + int gflag; /* flag for preferred activity coef eqn */ + int exch_gflag; /* flag for preferred activity coef eqn */ + struct elt_list *next_elt; /* pointer to next element */ + struct elt_list *next_secondary; + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ + LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ + struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each + surface */ + LDBLE cd_music[5]; + LDBLE dz[3]; +}; +struct logk +{ /* Named log K's */ + char *name; /* name of species */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE log_k[8]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + int done; + struct name_coef *add_logk; + LDBLE log_k_original[8]; /* log kt0, delh, 5 coefficients analalytical expression */ +}; +struct species_diff_layer +{ + struct surface_charge *charge; + int count_g; + LDBLE g_moles; + LDBLE dg_g_moles; /* g_moles*dgterm */ + LDBLE dx_moles; + LDBLE dh2o_moles; /* moles*g*Ws/Waq */ + LDBLE drelated_moles; /* for related phase */ +}; + +/*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ +struct phase +{ /* all data pertinent to a pure solid phase */ + char *name; /* name of species */ + char *formula; /* chemical formula */ + int in; /* species used in model if TRUE */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + struct name_coef *add_logk; + LDBLE moles_x; + LDBLE delta_max; + LDBLE p_soln_x; + LDBLE fraction_x; + LDBLE log10_lambda, log10_fraction_x; + LDBLE dn, dnb, dnc; + LDBLE gn, gntot; + LDBLE gn_n, gntot_n; + + int type; /* flag indicating presence in model and types of equations */ + struct elt_list *next_elt; /* pointer to list of elements in phase */ + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + int replaced; /* equation contains solids or gases */ + int in_system; +}; +/*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + struct master + { /* list of name and number of elements in an equation */ + int in; /* TRUE if in model, FALSE if out, REWRITE if other mb eq */ + int number; /* sequence number in list of masters */ + int last_model; /* saved to determine if model has changed */ + int type; /* AQ or EX */ + int primary; /* TRUE if master species is primary */ + LDBLE coef; /* coefficient of element in master species */ + LDBLE total; /* total concentration for element or valence state */ + LDBLE isotope_ratio; + LDBLE isotope_ratio_uncertainty; + int isotope; + LDBLE total_primary; + /* LDBLE la; */ /* initial guess of master species log activity */ + struct element *elt; /* element structure */ + LDBLE alk; /* alkalinity of species */ + LDBLE gfw; /* default gfw for species */ + char *gfw_formula; /* formula from which to calcuate gfw */ + struct unknown *unknown; /* pointer to unknown structure */ + struct species *s; /* pointer to species structure */ + struct reaction *rxn_primary; /* reaction writes master species in terms of primary + master species */ + struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary + master species */ + struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points + to location */ + int minor_isotope; +}; +/*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ +struct unknown +{ + int type; + LDBLE moles; + LDBLE ln_moles; + LDBLE f; + LDBLE sum; + LDBLE delta; + LDBLE la; + int number; + char *description; + struct master **master; + struct phase *phase; + LDBLE si; + struct gas_phase *gas_phase; + struct conc *total; + struct species *s; + struct exch_comp *exch_comp; + struct pure_phase *pure_phase; + struct s_s *s_s; + struct s_s_comp *s_s_comp; + int s_s_comp_number; + int s_s_in; + struct surface_comp *surface_comp; + LDBLE related_moles; + struct unknown *potential_unknown, *potential_unknown1, + *potential_unknown2; + int count_comp_unknowns; + struct unknown **comp_unknowns; /* list for CD_MUSIC of comps that contribute to 0 plane mass-balance term */ + struct unknown *phase_unknown; + struct surface_charge *surface_charge; + LDBLE mass_water; + int dissolve_only; + LDBLE inert_moles; +}; + +/*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ +struct reaction_temp +{ + LDBLE logk[8]; + LDBLE dz[3]; + struct rxn_token_temp *token; +}; +struct rxn_token_temp +{ /* data for equations, aq. species or minerals */ + char *name; /* pointer to a species name (formula) */ + LDBLE z; /* charge on species */ + struct species *s; + struct unknown *unknown; + LDBLE coef; /* coefficient of species name */ +}; +struct unknown_list +{ + struct unknown *unknown; + LDBLE *source; + LDBLE *gamma_source; + /* int row; */ + /* int col; */ + LDBLE coef; +}; +/* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ +struct prints +{ + int all; + int initial_solutions; + int initial_exchangers; + int reactions; + int gas_phase; + int s_s_assemblage; + int pp_assemblage; + int surface; + int exchange; + int kinetics; + int totals; + int eh; + int species; + int saturation_indices; + int irrev; + int mix; + int reaction; + int use; + int logfile; + int punch; + int status; + int inverse; + int dump; + int user_print; + int headings; + int user_graph; + int echo_input; + int warnings; + int initial_isotopes; + int isotope_ratios; + int isotope_alphas; + int hdf; + int alkalinity; +}; +/* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ +struct rate +{ + char *name; + char *commands; + int new_def; + void *linebase; + void *varbase; + void *loopbase; +}; +/* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ +struct spread_row +{ + int count; + int empty, string, number; + char **char_vector; + LDBLE *d_vector; + int *type_vector; +}; +struct defaults +{ + LDBLE temp; + LDBLE density; + char *units; + char *redox; + LDBLE ph; + LDBLE pe; + LDBLE water; + int count_iso; + struct iso *iso; +}; +struct spread_sheet +{ + struct spread_row *heading; + struct spread_row *units; + int count_rows; + struct spread_row **rows; + struct defaults defaults; +}; +/* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ +struct master_isotope +{ + char *name; + struct master *master; + struct element *elt; + char *units; + LDBLE standard; + LDBLE ratio; + LDBLE moles; + int total_is_major; + int minor_isotope; +}; +struct calculate_value +{ + char *name; + LDBLE value; + char *commands; + int new_def; + int calculated; + void *linebase; + void *varbase; + void *loopbase; +}; +struct isotope_ratio +{ + char *name; + char *isotope_name; + LDBLE ratio; + LDBLE converted_ratio; +}; +struct isotope_alpha +{ + char *name; + char *named_logk; + LDBLE value; +}; +struct system_species +{ + char *name; + char *type; + LDBLE moles; +}; + +/* tally.c ------------------------------- */ +struct tally_buffer +{ + char *name; + struct master *master; + LDBLE moles; + LDBLE gfw; +}; +struct tally +{ + char *name; + enum entity_type type; + char *add_formula; + LDBLE moles; + struct elt_list *formula; + /* + * first total is initial + * second total is final + * third total is difference (final - initial) + */ + struct tally_buffer *total[3]; +}; + +/* transport.c ------------------------------- */ +struct spec +{ + char *name; /* name of species */ + char *aq_name; /* name of aqueous species in EX species */ + int type; /* type: AQ or EX */ + LDBLE a; /* activity */ + LDBLE lm; /* log(concentration) */ + LDBLE lg; /* log(gamma) */ + LDBLE c; /* concentration for AQ, equivalent fraction for EX */ + LDBLE z; /* charge number */ + LDBLE Dwt; /* temperature corrected free water diffusion coefficient, m2/s */ + LDBLE erm_ddl; /* enrichment factor in ddl */ +}; +struct sol_D +{ + int count_spec; /* number of aqueous + exchange species */ + int count_exch_spec; /* number of exchange species */ + LDBLE exch_total; /* total moles of X- */ + struct spec *spec; +}; +struct J_ij +{ + char *name; + LDBLE tot1, tot2; +}; +struct M_S +{ + char *name; + LDBLE tot1, tot2; +}; +/* basic.c ------------------------------- */ +#ifdef PHREEQ98 +int colnr, rownr; +#endif + +#define checking true +#define varnamelen 20 +#define maxdims 4 + + +//#include "basic.h" + +#endif /* _INC_GLOBAL_STRUCTURES_H */ + From 7e0ae1503f3a649d1da5d6abe49d0f3ef285305f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 25 Oct 2011 00:10:30 +0000 Subject: [PATCH 0306/1077] Fixed up eol for error messaging. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5723 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 2b3048de..9551e08a 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -25,18 +25,18 @@ error_msg(const std::string & stdstr, int stop) { this->base_error_count++; std::ostringstream msg; - msg << "\nERROR: " << stdstr << std::endl; + msg << "ERROR: " << stdstr << std::endl; if (this->io) { - this->io->output_msg(msg.str().c_str()); this->io->log_msg(msg.str().c_str()); + this->io->error_msg("\n"); this->io->error_msg(msg.str().c_str(), stop!=0); } else { - std::cerr << msg.str().c_str() << std::endl; - std::cout << msg.str().c_str() << std::endl; + std::cerr << msg.str().c_str(); + std::cout << msg.str().c_str(); } if (stop != 0) { From 2efc1ee2c14c575c084556c2e80a98775284ab31 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 25 Oct 2011 18:40:30 +0000 Subject: [PATCH 0307/1077] Rearranged header files. Put almost everything into Phreeqc.h. SVN deleted global.h, input.h, pitzer.h, and pitzer_structures.h. Added basic_class.h in preparation for making Basic into a class. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5724 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1116 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 846 insertions(+), 270 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 7d87a8be..befcbf11 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -3,10 +3,13 @@ #if defined(WIN32) #include #endif +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif /* ---------------------------------------------------------------------- * INCLUDE FILES * ---------------------------------------------------------------------- */ - #include #include #include @@ -21,14 +24,14 @@ #include "cvdense.h" #include "runner.h" #include "dumper.h" +#include "PHRQ_io.h" #ifdef MULTICHART #include "ChartHandler.h" #endif -#include "PHRQ_io.h" -class cxxNameDouble; + #include "p2c.h" -#include "global_structures.h" -#include "pitzer_structures.h" + +class cxxNameDouble; class cxxKinetics; class cxxMix; class cxxKineticsComp; @@ -48,120 +51,27 @@ class cxxSurfaceCharge; class cxxSurfaceComp; class cxxStorageBin; +#include "global_structures.h" +#include "basic.h" + class Phreeqc { public: Phreeqc(void); ~Phreeqc(void); -#include "pitzer.h" -#include "input.h" - public: -#include "global.h" -/* - All functions are included as methods here -*/ -#define _INC_PHRQPROTO_H - -// advection.c ------------------------------- +// +// Phreeqc class methods +// +// advection.cpp ------------------------------- int advection(void); -// basic.c ------------------------------- - -int basic_main(char *commands); -void cmd_initialize(void); -void cmd_free(void); -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -int basic_init(void); -#ifdef PHREEQ98 -void GridChar(char *s, char *a); -#endif -int sget_logical_line(char **ptr, int *l, char *return_line); -int free_dim_stringvar(varrec *varbase); -void exec(void); -int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); -void restoredata(void); -void clearloops(void); -void clearvar(varrec * v); -void clearvars(void); -Char * numtostr(Char * Result, LDBLE n); -void parse(Char * inbuf, tokenrec ** buf); -void listtokens(FILE * f, tokenrec * buf); -void disposetokens(tokenrec ** tok); -void parseinput(tokenrec ** buf); -void errormsg(const Char * s); -void snerr(const Char * s); -void tmerr(const Char * s); -void badsubscr(void); -LDBLE realfactor(struct LOC_exec *LINK); -Char * strfactor(struct LOC_exec * LINK); -Char *stringfactor(Char * Result, struct LOC_exec *LINK); -long intfactor(struct LOC_exec *LINK); -LDBLE realexpr(struct LOC_exec *LINK); -Char * strexpr(struct LOC_exec * LINK); -Char * stringexpr(Char * Result, struct LOC_exec * LINK); -long intexpr(struct LOC_exec *LINK); -void require(int k, struct LOC_exec *LINK); -void skipparen(struct LOC_exec *LINK); -varrec * findvar(struct LOC_exec *LINK); -valrec factor(struct LOC_exec *LINK); -valrec upexpr(struct LOC_exec * LINK); -valrec term(struct LOC_exec * LINK); -valrec sexpr(struct LOC_exec * LINK); -valrec relexpr(struct LOC_exec * LINK); -valrec andexpr(struct LOC_exec * LINK); -valrec expr(struct LOC_exec *LINK); -void checkextra(struct LOC_exec *LINK); -boolean iseos(struct LOC_exec *LINK); -void skiptoeos(struct LOC_exec *LINK); -linerec * findline(long n); -linerec * mustfindline(long n); -void cmdend(struct LOC_exec *LINK); -void cmdnew(struct LOC_exec *LINK); -void cmdlist(struct LOC_exec *LINK); -void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); -void cmdrun(struct LOC_exec *LINK); -void cmdsave(struct LOC_exec *LINK); -void cmdput(struct LOC_exec *LINK); -void cmdchange_por(struct LOC_exec *LINK); -void cmdchange_surf(struct LOC_exec *LINK); -void cmdbye(void); -void cmddel(struct LOC_exec *LINK); -void cmdrenum(struct LOC_exec *LINK); -void cmdprint(struct LOC_exec *LINK); -void cmdpunch(struct LOC_exec *LINK); -#if defined PHREEQ98 || defined MULTICHART -void cmdgraph_x(struct LOC_exec *LINK); -void cmdgraph_y(struct LOC_exec *LINK); -void cmdgraph_sy(struct LOC_exec *LINK); -#endif -#if defined MULTICHART -void cmdplot_xy(struct LOC_exec *LINK); -#endif -void cmdlet(boolean implied, struct LOC_exec *LINK); -void cmdgoto(struct LOC_exec *LINK); -void cmdif(struct LOC_exec *LINK); -void cmdelse(struct LOC_exec *LINK); -boolean skiploop(int up, int dn, struct LOC_exec *LINK); -void cmdfor(struct LOC_exec *LINK); -void cmdnext(struct LOC_exec *LINK); -void cmdwhile(struct LOC_exec *LINK); -void cmdwend(struct LOC_exec *LINK); -void cmdgosub(struct LOC_exec *LINK); -void cmdreturn(struct LOC_exec *LINK); -void cmdread(struct LOC_exec *LINK); -void cmddata(struct LOC_exec *LINK); -void cmdrestore(struct LOC_exec *LINK); -void cmdgotoxy(struct LOC_exec *LINK); -void cmdon(struct LOC_exec *LINK); -void cmddim(struct LOC_exec *LINK); -void cmdpoke(struct LOC_exec *LINK); - -// basicsubs.c ------------------------------- +// basic.cpp +#include "basic_class.h" +// basicsubs.cpp ------------------------------- LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); @@ -235,7 +145,8 @@ void SetAxisTitles(char *s, int i); void SetChartTitle(char *s); void start_chart(bool end); #endif -// cl1.c ------------------------------- + +// cl1.cpp ------------------------------- int cl1(int k, int l, int m, int n, int nklmd, int n2d, LDBLE * q, @@ -244,7 +155,7 @@ int cl1(int k, int l, int m, int n, LDBLE * cu, int *iu, int *s, int check); void cl1_space(int check, int n2d, int klm, int nklmd); -// cl1mp.c ------------------------------- +// cl1mp.cpp ------------------------------- int cl1mp(int k, int l, int m, int n, int nklmd, int n2d, LDBLE * q_arg, @@ -252,14 +163,12 @@ int cl1mp(int k, int l, int m, int n, int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - - -// class_main.c ------------------------------- +// class_main.cpp ------------------------------- #ifdef DOS int write_banner(void); #endif -/* default.c */ +/* default.cpp */ public: int close_input_files(void); int close_output_files(void); @@ -322,7 +231,7 @@ void fpunchf_user(int user_index, const char *format, double d); void fpunchf_user(int user_index, const char *format, char * d); int fpunchf_end_row(const char *format); -// dw.c ------------------------------- +// dw.cpp ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); LDBLE VLEST(LDBLE T); @@ -330,15 +239,13 @@ int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); int QQ(LDBLE T, LDBLE D); LDBLE BASE(LDBLE D); -// input.c ------------------------------- - +// input.cpp ------------------------------- int reading_database(void); struct read_callback s_read_callback; int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); -// integrate.c ------------------------------- - +// integrate.cpp ------------------------------- int calc_all_g(void); int calc_init_g(void); int initial_surface_water(void); @@ -354,8 +261,7 @@ LDBLE calc_psi_avg(LDBLE surf_chrg_eq); int calc_all_donnan_music(void); int calc_init_donnan_music(void); -// inverse.c ------------------------------- - +// inverse.cpp ------------------------------- int inverse_models(void); int add_to_file(const char *filename, char *string); int bit_print(unsigned long bits, int l); @@ -412,8 +318,7 @@ int subset_minimal(unsigned long bits); int superset_minimal(unsigned long bits); int write_optimize_names(struct inverse *inv_ptr); -// isotopes.c ------------------------------- - +// isotopes.cpp ------------------------------- int add_isotopes(struct solution *solution_ptr); int calculate_values(void); int calculate_isotope_moles(struct element *elt_ptr, @@ -454,8 +359,7 @@ int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); int master_isotope_init(struct master_isotope *master_isotope_ptr); -// kinetics.c ------------------------------- - +// kinetics.cpp ------------------------------- void cvode_init(void); int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, @@ -483,8 +387,7 @@ int store_get_equi_reactants(int k, int kin_end); int count_pp, count_pg, count_s_s; LDBLE *x0_moles; -// mainsubs ------------------------------- - +// mainsubs.cpp ------------------------------- FILE *file_open(char *query, char *default_name, const char *status, int batch); int copy_entities(void); @@ -507,12 +410,10 @@ int do_initialize(void); int do_status(void); void save_init(int i); void use_init(void); - int copy_use(int i); int set_use(void); -// model.c ------------------------------- - +// model.cpp ------------------------------- int check_residuals(void); int free_model_allocs(void); int ineq(int kode); @@ -527,7 +428,6 @@ int residuals(void); int set(int initial); int sum_species(void); int surface_model(void); - LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, @@ -552,10 +452,7 @@ int s_s_ideal(struct s_s *s_s_ptr); int gas_in; void ineq_init(int max_row_count, int max_column_count); -// output.c ------------------------------- - -// parse.c ------------------------------- - +// parse.cpp ------------------------------- int check_eqn(int association); int get_charge(char *charge, LDBLE * z); int get_elt(char **t_ptr, char *element, int *i); @@ -563,12 +460,11 @@ int get_elts_in_species(char **t_ptr, LDBLE coef); int get_num(char **t_ptr, LDBLE * num); int get_secondary_in_species(char **t_ptr, LDBLE coef); int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - int get_coef(LDBLE * coef, char **eqnaddr); int get_secondary(char **t_ptr, char *element, int *i); int get_species(char **ptr); -// phqalloc.c ------------------------------- +// phqalloc.cpp ------------------------------- public: #if !defined(NDEBUG) void *PHRQ_malloc(size_t, const char *, int); @@ -580,67 +476,17 @@ void *PHRQ_calloc(size_t, size_t); void *PHRQ_realloc(void *, size_t); #endif void PHRQ_free(void *ptr); - void PHRQ_free_all(void); -protected: -// phreeqc_files.c ------------------------------- - -#ifdef PHREEQ98 -void check_line_breaks(char *s); -char *prefix_database_dir(char *s); -void show_progress(const int type, char *s); -#endif public: -void PASCAL_MAIN(int argc, Char **argv); -long my_labs(long x); -Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); -Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); -int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); -Anyptr my_memset(Anyptr d, int c, size_t n); -int my_toupper(int c); -int my_tolower(int c); -long ipow(long a, long b); -char * strsub(register char *ret, register char *s, register int pos, - register int len); -int strpos2(char *s, register char *pat, register int pos); -int strcicmp(register char *s1, register char *s2); -char * strltrim(register char *s); -char * strrtrim(register char *s); -void strmove(register int len, register char *s, register int spos, - register char *d, register int dpos); -void strinsert(register char *src, register char *dst, register int pos); -int P_peek(FILE * f); -int P_eof(void); -int P_eoln(FILE * f); -void P_readpaoc(FILE * f, char *s, int len); -void P_readlnpaoc(FILE * f, char *s, int len); -long P_maxpos(FILE * f); -Char * P_trimname(register Char * fn, register int len); -long memavail(void); -long maxavail(void); -long * P_setunion(register long *d, register long *s1, register long *s2); -long * P_setint(register long *d, register long *s1, register long *s2); -long * P_setdiff(register long *d, register long *s1, register long *s2); -long * P_setxor(register long *d, register long *s1, register long *s2); -long * P_addset(register long *s, register unsigned val); -long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); -long * P_remset(register long *s, register unsigned val); -int P_setequal(register long *s1, register long *s2); -int P_subset(register long *s1, register long *s2); -long * P_setcpy(register long *d, register long *s); -long * P_expset(register long *d, register long s); -long P_packset(register long *s); -int _OutMem(void); -int _CaseCheck(void); -int _NilCheck(void); -static char * _ShowEscape(char *buf, int code, int ior, char *prefix); -int _Escape(int code); -int _EscIO(int code); - -// pitzer.c ------------------------------- - +// pitzer.cpp ------------------------------- +struct pitz_param *pitz_param_read(char *string, int n); +int pitz_param_search(struct pitz_param *pzp_ptr); +int sit_param_search(struct pitz_param *pzp_ptr); +struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); +struct theta_param *theta_param_alloc(void); +int theta_param_init(struct theta_param *theta_param_ptr); int gammas_pz(void); int model_pz(void); int pitzer(void); @@ -649,7 +495,6 @@ int pitzer_init(void); int pitzer_tidy(void); int read_pitzer(void); int set_pz(int initial); - int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_pz(void); int ISPEC(char *name); @@ -665,16 +510,14 @@ LDBLE JAY(LDBLE X); LDBLE JPRIME(LDBLE Y); int jacobian_pz(void); -// pitzer_structures.c ------------------------------- - +// pitzer_structures.cpp ------------------------------- struct pitz_param *pitz_param_alloc(void); int pitz_param_init(struct pitz_param *pitz_param_ptr); struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); int pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr); -// pitzer_structures.c ------------------------------- - +// pitzer_structures.cpp ------------------------------- int add_potential_factor(void); int add_cd_music_factors(int n); int add_surface_charge_balance(void); @@ -727,8 +570,7 @@ int write_mb_eqn_x(void); int write_mb_for_species_list(int n); int write_mass_action_eqn_x(int stop); -/* prep.c */ - +/* prep.cpp */ int check_same_model(void); int k_temp(LDBLE tc); LDBLE k_calc(LDBLE * logk, LDBLE tempk); @@ -739,7 +581,7 @@ int rewrite_master_to_secondary(struct master *master_ptr1, int switch_bases(void); int write_phase_sys_total(int n); -// print.c ------------------------------- +// print.cpp ------------------------------- char *sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); @@ -752,7 +594,6 @@ int print_species(void); int print_surface(void); int print_user_print(void); int punch_all(void); - int print_alkalinity(void); int print_diffuse_layer(struct surface_charge *surface_charge_ptr); int print_eh(void); @@ -776,12 +617,11 @@ int punch_s_s_assemblage(void); int punch_saturation_indices(void); int punch_totals(void); int punch_user_punch(void); -#if defined PHREEQ98 || defined MULTICHART +#if defined MULTICHART int punch_user_graph(void); #endif -// read.c ------------------------------- - +// read.cpp ------------------------------- int read_input(void); int read_conc(int n, int count_mass_balance, char *str); int *read_list_ints_range(char **ptr, int *count_ints, int positive, @@ -859,37 +699,36 @@ int read_user_graph_handler(); int next_keyword_or_option(const char **opt_list, int count_opt_list); // ReadClass.cxx - int read_solution_raw(void); - int read_exchange_raw(void); - int read_surface_raw(void); - int read_equilibrium_phases_raw(void); - int read_kinetics_raw(void); - int read_solid_solutions_raw(void); - int read_gas_phase_raw(void); - int read_reaction_raw(void); - int read_mix_raw(void); - int read_temperature_raw(void); - int read_dump(void); - int read_solution_modify(void); - int read_equilibrium_phases_modify(void); - int read_exchange_modify(void); - int read_surface_modify(void); - int read_solid_solutions_modify(void); - int read_gas_phase_modify(void); - int read_kinetics_modify(void); - int read_reaction_modify(void); - //int read_reaction_temperature_modify(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); +int read_solution_raw(void); +int read_exchange_raw(void); +int read_surface_raw(void); +int read_equilibrium_phases_raw(void); +int read_kinetics_raw(void); +int read_solid_solutions_raw(void); +int read_gas_phase_raw(void); +int read_reaction_raw(void); +int read_mix_raw(void); +int read_temperature_raw(void); +int read_dump(void); +int read_solution_modify(void); +int read_equilibrium_phases_modify(void); +int read_exchange_modify(void); +int read_surface_modify(void); +int read_solid_solutions_modify(void); +int read_gas_phase_modify(void); +int read_kinetics_modify(void); +int read_reaction_modify(void); +//int read_reaction_temperature_modify(void); +int read_delete(void); +int read_run_cells(void); +int streamify_to_next_keyword(std::istringstream & lines); +int dump_entities(void); +int delete_entities(void); +int run_as_cells(void); +void dump_ostream(std::ostream& os); -// readtr.c ------------------------------- - +// readtr.cpp ------------------------------- int read_transport(void); int dump(void); int dump_exchange(int k); @@ -902,12 +741,10 @@ int dump_s_s_assemblage(int k); int dump_solution(int k); int dump_surface(int k); int dump_cpp(void); - int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc); -// sit.c ------------------------------- - +// sit.cpp ------------------------------- int gammas_sit(void); int model_sit(void); int sit(void); @@ -916,7 +753,6 @@ int sit_init(void); int sit_tidy(void); int read_sit(void); int set_sit(int initial); - int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_sit(void); int sit_ISPEC(char *name); @@ -926,10 +762,8 @@ int sit_revise_guesses(void); int PTEMP_SIT(LDBLE tk); int jacobian_sit(void); -// spread.c ------------------------------- - +// spread.cpp ------------------------------- int read_solution_spread(void); - int copy_token_tab(char *token_ptr, char **ptr, int *length); int get_option_string(const char **opt_list, int count_opt_list, char **next_char); @@ -947,8 +781,7 @@ void free_spread(void); struct spread_row *copy_row(struct spread_row *spread_row_ptr); #endif -// step.c ------------------------------- - +// step.cpp ------------------------------- int step(LDBLE step_fraction); int xsolution_zero(void); int add_exchange(struct exchange *exchange_ptr); @@ -963,7 +796,6 @@ int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); int add_temperature(struct temperature *temperature_ptr, int step_number); - int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); int gas_phase_check(struct gas_phase *gas_phase_ptr); int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); @@ -971,8 +803,7 @@ int reaction_calc(struct irrev *irrev_ptr); int solution_check(void); int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); -// structures.c ------------------------------- - +// structures.cpp ------------------------------- int clean_up(void); int reinitialize(void); int copier_add(struct copier *copier_ptr, int n_user, int start, int end); @@ -1285,8 +1116,7 @@ extern void free_spread(void); extern void MergeFinalize(void); #endif -// convert class to struct - +// convert class to struct (structures.cpp) struct mix * cxxMix2mix(const cxxMix *mx); struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); @@ -1319,8 +1149,7 @@ void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); void cxxStorageBin2phreeqc(cxxStorageBin & sb); -/* tally.c */ - +/* tally.cpp */ void add_all_components_tally(void); int build_tally_table(void); int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); @@ -1334,7 +1163,6 @@ int get_tally_table_row_heading(int column, char *string); int store_tally_table(LDBLE * array, int row_dim, int col_dim, LDBLE fill_factor); int zero_tally_table(void); - int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); int get_all_components(void); int print_tally_table(void); @@ -1342,8 +1170,7 @@ int set_reaction_moles(int n_user, LDBLE moles); int set_reaction_temperature(int n_user, LDBLE tc); int set_kinetics_time(int n_user, LDBLE step); -// tidy.c ------------------------------- - +// tidy.cpp ------------------------------- int add_other_logk(LDBLE * source_k, int count_add_logk, struct name_coef *add_logk); int add_logks(struct logk *logk_ptr, int repeats); @@ -1355,7 +1182,6 @@ int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); public: int tidy_punch(void); int tidy_model(void); - int check_species_input(void); LDBLE coef_in_master(struct master *master_ptr); int phase_rxn_to_trxn(struct phase *phase_ptr, @@ -1387,8 +1213,7 @@ static LDBLE f_spinodal(LDBLE x, void *); int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); int s_s_calc_a0_a1(struct s_s *s_s_ptr); -// transport.c ------------------------------- - +// transport.cpp ------------------------------- int transport(void); int set_initial_moles(int i); int sum_surface_comp(struct surface *source1, LDBLE f1, @@ -1397,7 +1222,6 @@ int sum_surface_comp(struct surface *source1, LDBLE f1, int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, LDBLE new_Dw, int cell); LDBLE viscosity(void); - int multi_D(LDBLE DDt, int mobile_cell, int stagnant); int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); int fill_spec(int cell_no); @@ -1416,8 +1240,7 @@ int heat_mix(int heat_nmix); int mix_stag(int i, LDBLE stagkin_time, int punch, LDBLE step_fraction_kin); - -// utilities.c ------------------------------- +// utilities.cpp ------------------------------- public: int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); protected: @@ -1466,7 +1289,6 @@ int string_trim_left(char *str); static LDBLE under(LDBLE xval); void zero_double(LDBLE * target, int n); int get_input_errors(void); - #ifdef PHREEQ98 void AddToCEntry(char *a, int l, int i); void ApplicationProcessMessages(void); @@ -1476,11 +1298,8 @@ extern int clean_up_null(void); int isamong(char c, const char *s_l); Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); - public: bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); - -public: // public methods for PHREEQC_CLASS int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); @@ -1490,11 +1309,768 @@ public: // public methods for PHREEQC_CLASS void clear_cookie(void); protected: void init(void); -//Data - std::list cookie_list; - std::ifstream * in_stream; - std::ifstream * db_stream; - -}; + +// +//Data members +// + +std::list cookie_list; +std::ifstream * in_stream; +std::ifstream * db_stream; + +PHRQ_io *phrq_io; + +/* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ + + struct model last_model; + int same_model; + int same_temperature; + struct punch punch; +/* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ + + struct temperature *temperature; + int count_temperature; +/* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + + int g_iterations; + LDBLE G_TOL; + struct surface *surface; + struct surface *dbg_surface; + int count_surface; + int max_surface; + struct Charge_Group *charge_group; + int change_surf_count; + struct Change_Surf *change_surf; + +/* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + + struct exchange *exchange; + struct exchange *dbg_exchange; + int count_exchange; + int max_exchange; +/* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + + struct kinetics *kinetics; + struct kinetics *dbg_kinetics; + int count_kinetics; + int max_kinetics; + + int count_save_values; + struct save_values *save_values; + +/*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + + struct save save; +/*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ + + struct Use use; + struct Use *dbg_use; +/*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ + + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_s_s_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_irrev; + struct copier copy_temperature; + +/*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + struct inverse *inverse; + int count_inverse; + +/*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + + struct mix *mix; + struct mix *dbg_mix; + int count_mix; +/*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + + struct irrev *irrev; + struct irrev *dbg_irrev; + int count_irrev; +/*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + + int count_gas_phase; + int max_gas_phase; + struct gas_phase *gas_phase; +/*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + + int count_s_s_assemblage; + int max_s_s_assemblage; + struct s_s_assemblage *s_s_assemblage; +/*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + + int count_pp_assemblage; + int max_pp_assemblage; + struct pp_assemblage *pp_assemblage; + struct pp_assemblage *dbg_pp_assemblage; +/*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + + int count_species_list; + int max_species_list; + struct species_list *species_list; +/*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ +/*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + + struct solution **solution; + struct solution **dbg_solution; + int count_solution; + int max_solution; + +struct iso *iso_defaults; +int count_iso_defaults; + +/*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + struct pe_data *pe_x; + int count_isotopes_x; + struct isotope *isotopes_x; + int default_pe_x; +/* int diffuse_layer_x;*/ + enum DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; +/*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ + + int cell_no; +/*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; + +/*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ +struct const_key *keyword; +int NKEYS; + + struct key *keyword_hash; + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, + new_pitzer; +/*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; + +/*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; +/*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ + +/*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + + struct logk **logk; + int count_logk; + int max_logk; + + char *moles_per_kilogram_string; + char *pe_string; + + struct species **s; + int count_s; + int max_s; + + struct species **s_x; + int count_s_x; + int max_s_x; + + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; +/*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + + struct phase **phases; + int count_phases; + int max_phases; +/*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; +/*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + + struct unknown **x; + int count_unknowns; + int max_unknowns; + + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *s_s_unknown; +/*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; + + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; +/* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + + struct prints pr; + int status_on, status_interval; + float status_timer; + int count_warnings; + +/* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + int count_rate_p; +/* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + char **user_punch_headings; + int user_punch_count_headings; + int n_user_punch_index; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + ChartHandler chart_handler; +#endif + +/* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + char error_string[10 * MAX_LENGTH]; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; + + int count_strings; + int max_strings; + + LDBLE *array; + LDBLE *delta; + LDBLE *residual; + + int input_error; + + int next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; + + int max_line; + char *line; + char *line_save; + + LDBLE LOG_10; + + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; + + LDBLE inv_tol_default; + int itmax; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; + + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; + + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; + +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + +/* ---------------------------------------------------------------------- */ +/* + * Hash definitions + */ + + HashTable *strings_hash_table; + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *keyword_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ +/* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ +struct name_coef match_tokens[50]; +int count_match_tokens; +int count_master_isotope; +struct master_isotope **master_isotope; +int max_master_isotope; +int initial_solution_isotopes; +int count_calculate_value; +struct calculate_value **calculate_value; +int max_calculate_value; +HashTable *calculate_value_hash_table; +int count_isotope_ratio; +struct isotope_ratio **isotope_ratio; +int max_isotope_ratio; +HashTable *isotope_ratio_hash_table; +int count_isotope_alpha; +struct isotope_alpha **isotope_alpha; +int max_isotope_alpha; +HashTable *isotope_alpha_hash_table; +int phreeqc_mpi_myself; +int first_read_input; +char *user_database; + +int have_punch_name; +/* VP: Density Start */ +int print_density; +/* VP: Density End */ + +LDBLE *zeros; +int zeros_max; + +LDBLE cell_pore_volume; +LDBLE cell_porosity; +LDBLE cell_volume; +LDBLE cell_saturation; +struct system_species *sys; +int count_sys, max_sys; +LDBLE sys_tot; +LDBLE AA_basic, BB_basic, CC, I_m, rho_0; +LDBLE solution_mass, solution_volume; +LDBLE f_rho(LDBLE rho_old); + +/* phqalloc.cpp ------------------------------- */ +PHRQMemHeader *s_pTail; +std::stringstream merged_database_stream; +std::stringstream merged_input_stream; + +/* cl1.cpp ------------------------------- */ +LDBLE *x_arg, *res_arg, *scratch; +int x_arg_max, res_arg_max, scratch_max; + +/* dw.cpp ------------------------------- */ +/* COMMON /QQQQ/ */ +LDBLE Q0, Q5; +LDBLE GASCON, TZ, AA; +LDBLE Z, DZ, Y; +LDBLE G1, G2, GF; +LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + +/* input.cpp ------------------------------- */ +int add_char_to_line(int *i, char c); +int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, + int allow_empty, int allow_eof, int allow_keyword, + int print); +int get_line(PFN_READ_CALLBACK pfn, void *cookie); +int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); +int read_database(PFN_READ_CALLBACK pfn, void *cookie); +int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); +int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); +int check_line_return; + +/* integrate.cpp ------------------------------- */ +LDBLE midpoint_sv; +LDBLE z, xd, alpha; +struct surface_charge *surface_charge_ptr; +int max_row_count, max_column_count; +int carbon; +char **col_name, **row_name; +int count_rows, count_optimize; +int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; +int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; +LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; +LDBLE *min_delta, *max_delta; +int *iu, *is; +int klmd, nklmd, n2d, kode, iter; +LDBLE toler, error, max_pct, scaled_error; +struct master *master_alk; +int *row_back, *col_back; +unsigned long *good, *bad, *minimal; +int max_good, max_bad, max_minimal; +int count_good, count_bad, count_minimal, count_calls; +unsigned long soln_bits, phase_bits, current_bits, temp_bits; + +/* inverse.cpp ------------------------------- */ +FILE *netpath_file; +int count_inverse_models, count_pat_solutions; +int min_position[32], max_position[32], now[32]; + +/* kinetics.cpp ------------------------------- */ +public: +void *cvode_kinetics_ptr; +int cvode_test; +int cvode_error; +int cvode_n_user; +int cvode_n_reactions; +realtype cvode_step_fraction; +realtype cvode_rate_sim_time; +realtype cvode_rate_sim_time_start; +realtype cvode_last_good_time; +realtype cvode_prev_good_time; +N_Vector cvode_last_good_y; +N_Vector cvode_prev_good_y; +M_Env kinetics_machEnv; +N_Vector kinetics_y, kinetics_abstol; +void *kinetics_cvode_mem; +struct pp_assemblage *cvode_pp_assemblage_save; +struct s_s_assemblage *cvode_s_s_assemblage_save; +LDBLE *m_original; +LDBLE *m_temp; + +/* model.cpp ------------------------------- */ +LDBLE min_value; +/* LDBLE model_min_value; */ +LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; +int *inv_iu, *inv_is, *back_eq; +int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; + +/* phrq_io_output.cpp ------------------------------- */ +int forward_output_to_log; + +/* phreeqc_files.cpp ------------------------------- */ +char *default_data_base; +#ifdef PHREEQ98 +int outputlinenr; +char *LogFileNameC; +char progress_str[512]; +#endif + +/* Pitzer */ +int pitzer_model, sit_model, pitzer_pe; +int full_pitzer, always_full_pitzer, ICON, IC; +LDBLE COSMOT; +LDBLE AW; +LDBLE VP, DW0; +struct pitz_param **pitz_params; +int count_pitz_param, max_pitz_param; +struct pitz_param **sit_params; +int count_sit_param, max_sit_param; +int DW(LDBLE T); +LDBLE DC(LDBLE T); +struct theta_param **theta_params; +int count_theta_param, max_theta_param; +int use_etheta; +LDBLE OTEMP; +LDBLE A0; +struct species **spec, **cations, **anions, **neutrals; +int count_cations, count_anions, count_neutrals; +int MAXCATIONS, FIRSTANION, MAXNEUTRAL; +struct pitz_param *mcb0, *mcb1, *mcc0; +int *IPRSNT; +LDBLE *M, *LGAMMA; +LDBLE BK[23], DK[23]; + +#ifdef PHREEQ98 +int connect_simulations, graph_initial_solutions; +int shifts_as_points; +int chart_type; +int ShowChart; +int RowOffset, ColumnOffset; +#endif +LDBLE dummy; + +/* print.cpp ------------------------------- */ +#ifdef PHREEQ98 +int colnr, rownr; +int graph_initial_solutions; +int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ +/* int shifts_as_points; */ +int chart_type; +int AddSeries; +int FirstCallToUSER_GRAPH; +#endif + +/* read.cpp */ +char *prev_next_char; +#if defined PHREEQ98 +int shifts_as_points; +#endif + +/* read_class.cxx */ +dumper dump_info; +StorageBinList delete_info; +runner run_info; +char * sformatf_buffer; +size_t sformatf_buffer_size; + +/* readtr.cpp */ +std::string dump_file_name_cpp; + +/* sit.cpp ------------------------------- */ +LDBLE sit_A0; +int sit_count_cations, sit_count_anions, sit_count_neutrals; +int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; +int *sit_IPRSNT; +LDBLE *sit_M, *sit_LGAMMA; + +/* tidy.cpp ------------------------------- */ +LDBLE a0, a1, kc, kb; + +/* tally.cpp ------------------------------- */ +struct tally_buffer *t_buffer; +int tally_count_component; +struct tally *tally_table; +int count_tally_table_columns; +int count_tally_table_rows; + +/* transport.cpp ------------------------------- */ +struct sol_D *sol_D; +struct sol_D *sol_D_dbg; +struct J_ij *J_ij, *J_ij_il; +int J_ij_count_spec; + +struct M_S *m_s; +int count_m_s; +LDBLE tot1_h, tot1_o, tot2_h, tot2_o; +LDBLE diffc_max, diffc_tr, J_ij_sum; +int transp_surf; +LDBLE *heat_mix_array; +LDBLE *temp1, *temp2; +int nmix, heat_nmix; +LDBLE heat_mix_f_imm, heat_mix_f_m; +int warn_MCD_X, warn_fixed_Surf; + +#ifdef PHREEQ98 +int AutoLoadOutputFile, CreateToC; +int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; +int outputlinenr; +int stop_calculations; +char err_str98[80]; +#endif + #endif /* _INC_PHREEQC_H */ +/********************************* + isfinite handling + (Note: Should NOT be guarded) +**********************************/ + +#if defined (PHREEQ98) || defined (_MSC_VER) +# define HAVE_FINITE +# define finite _finite +#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ +# if defined(DJGPP) +# define HAVE_FINITE +# endif +#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ + +#if defined(HAVE_ISFINITE) +# define PHR_ISFINITE(x) isfinite(x) +#elif defined(HAVE_FINITE) +# define PHR_ISFINITE(x) finite(x) +#elif defined(HAVE_ISNAN) +# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) +#else +# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) +#endif + +}; From fdd1cee2a2fe0753130be3954a4dba51363fcff2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 Nov 2011 18:44:50 +0000 Subject: [PATCH 0308/1077] Phreeqc_class.h case in #include statements. Fixed warnings and errors in Unix. Updated Makefile for class only versions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5728 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 1 - ChartHandler.h | 2 +- GasPhase.h | 2 +- Makefile | 837 +++++++++++++++++++++++++++---------------- PHRQ_base.cxx | 3 +- PPassemblage.h | 2 +- PPassemblageComp.cxx | 2 - PPassemblageComp.h | 2 +- SSassemblage.h | 2 +- SSassemblageSS.h | 2 +- Solution.h | 2 +- System.h | 2 +- 12 files changed, 534 insertions(+), 325 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 8b40f322..f83ceafa 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -6,7 +6,6 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif #include "ChartHandler.h" -#include "phreeqc_class.h" #include "phreeqc.h" #include diff --git a/ChartHandler.h b/ChartHandler.h index 53bfc4d2..331a3f6b 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -7,7 +7,7 @@ #include "Parser.h" #include "ChartObject.h" #include "PHRQ_base.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class ChartHandler: public PHRQ_base { diff --git a/GasPhase.h b/GasPhase.h index 75039d87..2a28a060 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -9,7 +9,7 @@ #include "NumKeyword.h" #include "NameDouble.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxMix; class cxxGasPhase:public cxxNumKeyword diff --git a/Makefile b/Makefile index 0c95cf0e..00fc698b 100644 --- a/Makefile +++ b/Makefile @@ -22,18 +22,17 @@ else SPOOL2= endif -all: release debug class_release class_debug - -Release: release - -Debug: debug +all: class_release class_debug +Debug: class_debug +debug: class_debug Class_debug: class_debug +Release: class_release +release: class_release Class_release: class_release -RELEASE_DIR = Release -DEBUG_DIR = Debug + CLASS_DEBUG_DIR = Class_debug CLASS_DIR = Class_release MAKEFILE = Makefile @@ -46,16 +45,6 @@ HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) ######################### #### Serial Versions #### ######################### -.PHONY : Release -release: - mkdir -p $(RELEASE_DIR) - cd $(RELEASE_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE $(PROGRAM) - -.PHONY : Debug -debug: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG $(PROGRAM) - .PHONY : Class_debug class_debug: mkdir -p $(CLASS_DEBUG_DIR) @@ -176,11 +165,10 @@ COMMON_COBJS = \ model.o \ nvector.o \ nvector_serial.o \ - output.o \ p2clib.o \ parse.o \ + PHRQ_io_output.o \ phqalloc.o \ - phreeqc_files.o \ pitzer.o \ pitzer_structures.o \ prep.o \ @@ -218,6 +206,8 @@ COMMON_CXXOBJS = \ NameDouble.o \ NumKeyword.o \ Parser.o \ + PHRQ_base.o \ + PHRQ_io.o \ PPassemblageComp.o \ PPassemblage.o \ Reaction.o \ @@ -251,322 +241,545 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../cxxKinetics.h ../NumKeyword.h ../KineticsComp.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../cxxMix.h ../NumKeyword.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -Dictionary.o: ../Dictionary.cxx ../Dictionary.h ../Solution.h \ - ../Phreeqc_class.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h -Exchange.o: ../Exchange.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../cxxMix.h ../Phreeqc_class.h ../NumKeyword.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../ExchComp.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h \ - ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../ISolutionComp.h ../Phreeqc_class.h ../phreeqc/phrqproto.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h -ISolution.o: ../ISolution.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../ISolution.h ../ISolutionComp.h ../Phreeqc_class.h ../NumKeyword.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../KineticsComp.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Dictionary.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../Parser.h \ - ../Phreeqc_class.h -Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/output.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ - ../Parser.h ../Dictionary.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h ../phreeqc/output.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../PPassemblage.h ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -Reaction.o: ../Reaction.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../Phreeqc_class.h \ - ../Parser.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -ReadClass.o: ../ReadClass.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc_class.h \ - ../Parser.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ - ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ - ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ - ../Temperature.h ../dumper.h ../StorageBinList.h ../runner.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h ../phreeqc/output.h -Solution.o: ../Solution.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Solution.h ../Phreeqc_class.h ../NumKeyword.h \ +cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxKinetics.h \ + ../NumKeyword.h ../KineticsComp.h ../NameDouble.h ../Parser.h \ + ../cxxMix.h ../phreeqc/phqalloc.h +cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxMix.h ../NumKeyword.h \ + ../phreeqc/phqalloc.h +Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxMix.h \ + ../NumKeyword.h ../Exchange.h ../ExchComp.h ../NameDouble.h ../Parser.h \ + ../phreeqc/phqalloc.h +ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../ExchComp.h ../NameDouble.h ../Parser.h ../Dictionary.h \ + ../phreeqc/phqalloc.h +GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ + ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h +ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../ISolutionComp.h \ + ../phreeqc/phqalloc.h +ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../ISolution.h \ + ../ISolutionComp.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../cxxMix.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SolutionIsotope.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SSassemblage.h ../Phreeqc_class.h ../NumKeyword.h ../NameDouble.h \ - ../Parser.h ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h \ - ../phreeqc/phrqproto.h -SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/output.h ../SSassemblageSS.h ../NameDouble.h \ - ../Phreeqc_class.h ../Parser.h ../Dictionary.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../StorageBin.h \ - ../System.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ - ../Temperature.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SurfaceCharge.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ - ../Dictionary.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h -Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h \ - ../phreeqc/global.h ../phreeqc/phrqtype.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../Surface.h ../NumKeyword.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -System.o: ../System.cxx ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../System.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../SSassemblage.h \ + ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../KineticsComp.h \ + ../NameDouble.h ../Parser.h ../Dictionary.h ../phreeqc/phqalloc.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../NameDouble.h ../Parser.h \ + ../Dictionary.h ../phreeqc/phqalloc.h +NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ + ../Parser.h +Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../Parser.h +PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../PPassemblageComp.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ + ../phreeqc/phqalloc.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../PPassemblage.h \ + ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h ../Parser.h \ + ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h +Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../Reaction.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ + ../phreeqc/phqalloc.h +ReadClass.o: ../ReadClass.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../Phreeqc_class.h ../Parser.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../NameDouble.h \ + ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../PPassemblage.h ../PPassemblageComp.h \ + ../cxxKinetics.h ../KineticsComp.h ../SSassemblage.h ../GasPhase.h \ + ../Reaction.h ../cxxMix.h ../Temperature.h ../phreeqc/phqalloc.h +Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../Phreeqc_class.h \ + ../cxxMix.h ../phreeqc/phqalloc.h +SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SolutionIsotope.h \ + ../Parser.h ../phreeqc/phqalloc.h +SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/phqalloc.h +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SSassemblage.h \ + ../NumKeyword.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h +SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SSassemblageSS.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ + ../phreeqc/phqalloc.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../NameDouble.h ../Parser.h \ + ../StorageBin.h ../System.h ../Phreeqc_class.h ../SSassemblage.h \ + ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../cxxMix.h ../Reaction.h ../Temperature.h \ + ../phreeqc/phqalloc.h +SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceCharge.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ + ../phreeqc/phqalloc.h +SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceComp.h \ + ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../Dictionary.h \ + ../phreeqc/phqalloc.h +Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../Surface.h ../NumKeyword.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../cxxMix.h ../phreeqc/phqalloc.h +System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../System.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../SSassemblage.h \ ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ ../SurfaceCharge.h ../cxxMix.h ../Reaction.h ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h \ - ../Phreeqc_class.h ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Temperature.h \ - ../NumKeyword.h ../phreeqc/phqalloc.h ../phreeqc/phrqproto.h -Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../Phreeqc_class.h \ - ../phreeqc/output.h +Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../Temperature.h \ + ../NumKeyword.h ../phreeqc/phqalloc.h +Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ChartHandler.o: ../ChartHandler.cpp ChartObject.o: ../ChartObject.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h ../phreeqc/input.h \ - ../phreeqc/output.h ../phreeqc/global.h ../phreeqc/global_structures.h \ - ../phreeqc/phrqproto.h ../NameDouble.h ../Phreeqc_class.h ../Parser.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h \ - ../cxxKinetics.h ../KineticsComp.h -CurveObject.o: ../CurveObject.cpp ../CurveObject.h -dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h -Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h ../phreeqc/input.h \ - ../phreeqc/output.h ../phreeqc/global.h ../phreeqc/global_structures.h \ - ../NameDouble.h ../Phreeqc_class.h ../Parser.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h -runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h ../phreeqc/NA.h -StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h ../Parser.h \ - ../Phreeqc_class.h -advection.o: ../phreeqc/advection.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -basic.o: ../phreeqc/basic.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/p2c.h \ - ../phreeqc/../NameDouble.h ../phreeqc/../Phreeqc_class.h \ - ../phreeqc/../Parser.h ../phreeqc/basic.h -basicsubs.o: ../phreeqc/basicsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/../NameDouble.h ../phreeqc/../Phreeqc_class.h \ - ../phreeqc/../Parser.h -cl1.o: ../phreeqc/cl1.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqtype.h -cl1mp.o: ../phreeqc/cl1mp.c ../phreeqc/phqalloc.h ../phreeqc/output.h \ - ../phreeqc/phrqtype.h -cvdense.o: ../phreeqc/cvdense.c ../phreeqc/cvdense.h ../phreeqc/cvode.h \ +CurveObject.o: ../CurveObject.cpp ../CurveObject.h +dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ + ../Parser.h +Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ + ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h \ + ../phreeqc/phqalloc.h +PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h +runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../Parser.h ../phreeqc/NA.h +StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ + ../PHRQ_base.h ../Parser.h +advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +basic.o: ../phreeqc/basic.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h ../phreeqc/p2c.h ../NameDouble.h ../Parser.h +basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ + ../phreeqc/../PHRQ_base.h +cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ - ../phreeqc/output.h ../phreeqc/phqalloc.h -cvode.o: ../phreeqc/cvode.c ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/sundialsmath.h \ - ../phreeqc/output.h ../phreeqc/kinetics.h ../phreeqc/phqalloc.h -dense.o: ../phreeqc/dense.c ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../phreeqc/output.h ../phreeqc/phqalloc.h -dw.o: ../phreeqc/dw.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phrqproto.h \ - ../phreeqc/output.h ../phreeqc/pitzer.h -input.o: ../phreeqc/input.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/input.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h -integrate.o: ../phreeqc/integrate.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -inverse.o: ../phreeqc/inverse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -isotopes.o: ../phreeqc/isotopes.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -kinetics.o: ../phreeqc/kinetics.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/sundialstypes.h ../phreeqc/cvode.h ../phreeqc/nvector.h \ + ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h +cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../phreeqc/nvector_serial.h ../phreeqc/kinetics.h -main.o: ../phreeqc/main.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/input.h -mainsubs.o: ../phreeqc/mainsubs.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/input.h -model.o: ../phreeqc/model.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -nvector.o: ../phreeqc/nvector.c ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h -nvector_serial.o: ../phreeqc/nvector_serial.c ../phreeqc/nvector_serial.h \ - ../phreeqc/nvector.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h -output.o: ../phreeqc/output.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/output.h \ - ../phreeqc/phrqproto.h ../phreeqc/phqalloc.h -p2clib.o: ../phreeqc/p2clib.c ../phreeqc/p2c.h ../phreeqc/output.h -parse.o: ../phreeqc/parse.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -phqalloc.o: ../phreeqc/phqalloc.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/output.h -phreeqc_files.o: ../phreeqc/phreeqc_files.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/input.h -pitzer.o: ../phreeqc/pitzer.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h -pitzer_structures.o: ../phreeqc/pitzer_structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h -prep.o: ../phreeqc/prep.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -print.o: ../phreeqc/print.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h ../phreeqc/pitzer.h -read.o: ../phreeqc/read.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -readtr.o: ../phreeqc/readtr.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -sit.o: ../phreeqc/sit.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h \ - ../phreeqc/pitzer_structures.h ../phreeqc/pitzer.h -smalldense.o: ../phreeqc/smalldense.c ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h +dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h +dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h +input.o: ../phreeqc/input.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +kinetics.o: ../phreeqc/kinetics.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ + ../Parser.h ../Phreeqc_class.h ../Reaction.h ../NumKeyword.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../SSassemblage.h ../Temperature.h ../phreeqc/nvector_serial.h +mainsubs.o: ../phreeqc/mainsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h +nvector_serial.o: ../phreeqc/nvector_serial.cpp \ + ../phreeqc/nvector_serial.h ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h ../phreeqc/output.h ../phreeqc/phqalloc.h -spread.o: ../phreeqc/spread.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -step.o: ../phreeqc/step.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -structures.o: ../phreeqc/structures.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -sundialsmath.o: ../phreeqc/sundialsmath.c ../phreeqc/sundialsmath.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/output.h -tally.o: ../phreeqc/tally.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -tidy.o: ../phreeqc/tidy.c ../phreeqc/global.h ../phreeqc/phrqtype.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/output.h ../phreeqc/phrqproto.h -transport.o: ../phreeqc/transport.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h -utilities.o: ../phreeqc/utilities.c ../phreeqc/global.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/output.h ../phreeqc/phrqproto.h - + ../phreeqc/sundialsmath.h +p2clib.o: ../phreeqc/p2clib.cpp ../phreeqc/p2c.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h +parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h +PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h +pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h +prep.o: ../phreeqc/prep.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +print.o: ../phreeqc/print.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +read.o: ../phreeqc/read.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ + ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ + ../phreeqc/../PHRQ_base.h ../phreeqc/../Phreeqc_class.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/../SSassemblageSS.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h +sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/sundialsmath.h +spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ + ../Parser.h ../Phreeqc_class.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ + ../NameDouble.h +structures.o: ../phreeqc/structures.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h \ + ../phreeqc/../cxxMix.h ../phreeqc/../NumKeyword.h \ + ../phreeqc/../PHRQ_base.h ../phreeqc/../Exchange.h \ + ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ + ../phreeqc/../Parser.h ../phreeqc/../GasPhase.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../cxxKinetics.h \ + ../phreeqc/../KineticsComp.h ../phreeqc/../PPassemblage.h \ + ../phreeqc/../PPassemblageComp.h ../phreeqc/../PPassemblageComp.h \ + ../phreeqc/../Reaction.h ../phreeqc/../Solution.h \ + ../phreeqc/../SolutionIsotopeList.h ../phreeqc/../SolutionIsotope.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/../SolutionIsotopeList.h \ + ../phreeqc/../SSassemblage.h ../phreeqc/../SSassemblageSS.h \ + ../phreeqc/../Surface.h ../phreeqc/../SurfaceComp.h \ + ../phreeqc/../SurfaceCharge.h ../phreeqc/../SurfaceComp.h \ + ../phreeqc/../SurfaceCharge.h ../phreeqc/../Temperature.h \ + ../phreeqc/../StorageBin.h ../phreeqc/../System.h +sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h +tally.o: ../phreeqc/tally.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +tidy.o: ../phreeqc/tidy.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +transport.o: ../phreeqc/transport.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h +utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../phreeqc/phqalloc.h # ----------------------------------------------------------------------------- - clean: - rm -rf Release Debug Class_release Class_debug + rm -rf Class_release Class_debug dependencies: mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); gcc -MM -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.c + cd $(DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 9551e08a..cd11ae38 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -61,7 +61,6 @@ warning_msg(const std::string & stdstr) void PHRQ_base:: output_msg(const std::string & stdstr) { - bool stop = false; if (this->io) { //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); @@ -71,4 +70,4 @@ output_msg(const std::string & stdstr) { std::cout << stdstr << std::endl; } -} \ No newline at end of file +} diff --git a/PPassemblage.h b/PPassemblage.h index b12ed407..f0d6c8eb 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -9,7 +9,7 @@ #include "NumKeyword.h" #include "PPassemblageComp.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxMix; class cxxPPassemblage:public cxxNumKeyword diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index c538ac72..43f6315e 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -12,8 +12,6 @@ #include "PPassemblageComp.h" #include "Dictionary.h" #include "phqalloc.h" -#include "phreeqc_class.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/PPassemblageComp.h b/PPassemblageComp.h index c6173910..d7e8c4bb 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -8,7 +8,7 @@ #include // std::vector #include "NameDouble.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxPPassemblageComp: public PHRQ_base { diff --git a/SSassemblage.h b/SSassemblage.h index 2e781fa7..4b20db5a 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -10,7 +10,7 @@ #include "NumKeyword.h" #include "NameDouble.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxSSassemblageSS; diff --git a/SSassemblageSS.h b/SSassemblageSS.h index a6e1a10b..7f7ef0e8 100644 --- a/SSassemblageSS.h +++ b/SSassemblageSS.h @@ -7,7 +7,7 @@ #include // std::list #include // std::vector #include "NameDouble.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxSSassemblageSS: public PHRQ_base { diff --git a/Solution.h b/Solution.h index d20fbd17..4ee8d1b4 100644 --- a/Solution.h +++ b/Solution.h @@ -11,7 +11,7 @@ #include "NameDouble.h" #include "PHRQ_base.h" #include "PHRQ_io.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxMix; class cxxSolution:public cxxNumKeyword diff --git a/System.h b/System.h index 28623d0a..defcaec7 100644 --- a/System.h +++ b/System.h @@ -12,7 +12,7 @@ //#include "Temperature.h" #include "NameDouble.h" #include "PHRQ_base.h" -#include "phreeqc_class.h" +#include "Phreeqc_class.h" class cxxSolution; class cxxExchange; class cxxGasPhase; From d2c28c17a4b3d33037dd6a4724fdadc5b0575a5b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 Nov 2011 23:54:22 +0000 Subject: [PATCH 0309/1077] safe_close now takes pointer to file pointer git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5729 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 50 +++++++++++++++++++++++++------------------------- PHRQ_io.h | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 43606e77..40554089 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -31,43 +31,43 @@ PHRQ_io:: void PHRQ_io::Set_database_file(FILE * in) { - safe_close(this->database_file); + safe_close(&this->database_file); this->database_file = in; } void PHRQ_io::Set_input_file(FILE * in) { - safe_close(this->input_file); + safe_close(&this->input_file); this->input_file = in; } void PHRQ_io::Set_output_file(FILE * out) { - safe_close(this->output_file); + safe_close(&this->output_file); this->output_file = out; } void PHRQ_io::Set_error_file(FILE * out) { - safe_close(this->error_file); + safe_close(&this->error_file); this->error_file = out; } void PHRQ_io::Set_log_file(FILE * out) { - safe_close(this->log_file); + safe_close(&this->log_file); this->log_file = out; } void PHRQ_io::Set_punch_file(FILE * out) { - safe_close(this->punch_file); + safe_close(&this->punch_file); this->punch_file = out; } void PHRQ_io::Set_dump_file(FILE * out) { - safe_close(this->dump_file); + safe_close(&this->dump_file); this->dump_file = out; } @@ -80,7 +80,7 @@ bool PHRQ_io:: output_open(const char *file_name) /* ---------------------------------------------------------------------- */ { - safe_close(output_file); + safe_close(&output_file); if ((output_file = fopen(file_name, "w")) == NULL) { return false; // error @@ -102,7 +102,7 @@ void PHRQ_io:: output_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(output_file); + safe_close(&output_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -142,7 +142,7 @@ bool PHRQ_io:: log_open(const char *file_name) /* ---------------------------------------------------------------------- */ { - safe_close(log_file); + safe_close(&log_file); if ((log_file = fopen(file_name, "w")) == NULL) { return false; // error @@ -164,7 +164,7 @@ void PHRQ_io:: log_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(log_file); + safe_close(&log_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -204,7 +204,7 @@ bool PHRQ_io:: punch_open(const char *file_name) /* ---------------------------------------------------------------------- */ { - safe_close(punch_file); + safe_close(&punch_file); if ((punch_file = fopen(file_name, "w")) == NULL) { return false; // error @@ -226,7 +226,7 @@ void PHRQ_io:: punch_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(punch_file); + safe_close(&punch_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -267,7 +267,7 @@ bool PHRQ_io:: error_open(const char *file_name) /* ---------------------------------------------------------------------- */ { - safe_close(error_file); + safe_close(&error_file); if (file_name != NULL) { @@ -298,7 +298,7 @@ void PHRQ_io:: error_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(error_file); + safe_close(&error_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -371,7 +371,7 @@ bool PHRQ_io:: dump_open(const char *file_name) /* ---------------------------------------------------------------------- */ { - safe_close(dump_file); + safe_close(&dump_file); if ((dump_file = fopen(file_name, "w")) == NULL) { return false; // error @@ -393,7 +393,7 @@ void PHRQ_io:: dump_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(dump_file); + safe_close(&dump_file); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -430,7 +430,7 @@ dump_msg(const char * str) void PHRQ_io::close_input(void) { - safe_close(input_file); + safe_close(&input_file); } /* ---------------------------------------------------------------------- */ int PHRQ_io:: @@ -549,16 +549,16 @@ close_output_files(void) //safe_close is static method /* ---------------------------------------------------------------------- */ void PHRQ_io:: -safe_close(FILE * file_ptr) +safe_close(FILE ** file_ptr) /* ---------------------------------------------------------------------- */ { - if (file_ptr != stderr && - file_ptr != stdout && - file_ptr != stdin && - file_ptr != NULL) + if (*file_ptr != stderr && + *file_ptr != stdout && + *file_ptr != stdin && + *file_ptr != NULL) { - fclose(file_ptr); - file_ptr = NULL; + fclose(*file_ptr); + *file_ptr = NULL; } } diff --git a/PHRQ_io.h b/PHRQ_io.h index ad3472c0..9f07a889 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -14,7 +14,7 @@ public: // methods static int istream_getc(void *cookie); - static void safe_close(FILE * file_ptr); + static void safe_close(FILE ** file_ptr); int close_input_files(void); int close_output_files(void); From f8887170b9f2fa9fc65f538d66657e2031a57069 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Nov 2011 18:02:02 +0000 Subject: [PATCH 0310/1077] Implemented Tony's Peng-Robinson changes. Need to run his test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5731 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 40 +++++++++++++++++++++++++++++++++++----- GasPhase.h | 2 ++ PHRQ_base.cxx | 1 - PPassemblageComp.cxx | 26 ++++++++++++++++++++++++++ PPassemblageComp.h | 2 ++ Phreeqc.cpp | 6 +++++- Phreeqc.h | 9 +++++++++ 7 files changed, 79 insertions(+), 7 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index bf10b345..39e49610 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -27,6 +27,7 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) { total_p = 0; volume = 0; + v_m = 0; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; } @@ -52,6 +53,7 @@ cxxNumKeyword(io) } total_p = gas_phase_ptr->total_p; volume = gas_phase_ptr->volume; + v_m = gas_phase_ptr->v_m; // gas_phase components for (i = 0; i < gas_phase_ptr->count_comps; i++) @@ -70,6 +72,7 @@ cxxNumKeyword(io) gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; total_p = 0; volume = 0; + v_m = 0; bool first = true; // // Mix @@ -93,6 +96,7 @@ cxxNumKeyword(io) this->type = entity_ptr->type; this->total_p = entity_ptr->total_p * it->second; this->volume = entity_ptr->volume * it->second; + this->v_m = entity_ptr->v_m * it->second; first = false; } else @@ -108,6 +112,7 @@ cxxNumKeyword(io) this->total_p += entity_ptr->total_p * it->second; this->volume += entity_ptr->volume * it->second; + this->v_m += entity_ptr->v_m * it->second; } } } @@ -181,6 +186,9 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1; s_oss << "-volume " << this->volume << std::endl; + s_oss << indent1; + s_oss << "-v_m " << this->v_m << std::endl; + // gasPhaseComps s_oss << indent1; s_oss << "-component" << std::endl; @@ -199,8 +207,9 @@ cxxGasPhase::read_raw(CParser & parser, bool check) vopts.push_back("type"); //0 vopts.push_back("total_p"); //1 vopts.push_back("volume"); //2 - vopts.push_back("component"); //3 - vopts.push_back("pressure"); //4 + vopts.push_back("v_m"); //3 + vopts.push_back("component"); //4 + vopts.push_back("pressure"); //5 } std::istream::pos_type ptr; @@ -216,6 +225,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) bool type_defined(false); bool total_p_defined(false); bool volume_defined(false); + bool v_m_defined(false); for (;;) { @@ -265,7 +275,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) break; case 1: // total_p - case 4: // pressure + case 5: // pressure if (!(parser.get_iss() >> this->total_p)) { this->total_p = 0; @@ -289,7 +299,19 @@ cxxGasPhase::read_raw(CParser & parser, bool check) useLastLine = false; break; - case 3: // component + case 3: // v_m + if (!(parser.get_iss() >> this->v_m)) + { + this->v_m = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for v_m.", + CParser::OT_CONTINUE); + } + v_m_defined = true; + useLastLine = false; + break; + + case 4: // component if (this->gasPhaseComps.read_raw(parser, next_char) != CParser::PARSER_OK) { @@ -299,7 +321,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) ("Expected gas component name and moles for gasPhaseComps.", CParser::OT_CONTINUE); } - opt_save = 3; + opt_save = 4; useLastLine = false; break; } @@ -327,6 +349,12 @@ cxxGasPhase::read_raw(CParser & parser, bool check) parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); } + if (v_m_defined == false) + { + parser.incr_input_error(); + parser.error_msg("V_m not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } } } @@ -347,6 +375,7 @@ cxxGasPhase::mpi_pack(std::vector < int >&ints, } doubles.push_back(this->total_p); doubles.push_back(this->volume); + doubles.push_back(this->v_m); } void @@ -369,6 +398,7 @@ cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } this->total_p = doubles[d++]; this->volume = doubles[d++]; + this->v_m = doubles[d++]; *ii = i; *dd = d; } diff --git a/GasPhase.h b/GasPhase.h index 2a28a060..d353954c 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -49,6 +49,7 @@ class cxxGasPhase:public cxxNumKeyword GP_TYPE Get_type(void) const {return type;}; double Get_total_p(void) const {return total_p;}; double Get_volume(void) const {return volume;}; + double Get_v_m(void) const {return v_m;}; cxxNameDouble & Get_totals(void) {return totals;}; protected: @@ -59,6 +60,7 @@ protected: GP_TYPE type; double total_p; double volume; + double v_m; cxxNameDouble totals; }; diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index cd11ae38..71dc39ce 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -63,7 +63,6 @@ output_msg(const std::string & stdstr) { if (this->io) { - //this->io->phreeqc_handler(PHRQ_io::ACTION_OUTPUT, PHRQ_io::OUTPUT_MESSAGE, stdstr.c_str(), stop!=0, "", NULL); this->io->output_msg(stdstr.c_str()); } else diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 43f6315e..478caa69 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -25,6 +25,7 @@ PHRQ_base(io) // { si = 0; + si_org = 0; moles = 0; delta = 0; initial_moles = 0; @@ -43,6 +44,7 @@ PHRQ_base(io) this->Set_name(pure_phase_ptr->name); this->Set_add_formula(pure_phase_ptr->add_formula); si = pure_phase_ptr->si; + si_org = pure_phase_ptr->si_org; moles = pure_phase_ptr->moles; delta = pure_phase_ptr->delta; initial_moles = pure_phase_ptr->initial_moles; @@ -75,6 +77,7 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "add_formula=\"" << this-> add_formula << "\"" << std::endl; s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; + s_oss << indent0 << "si_org=\"" << this->si_org << "\"" << std::endl; s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; s_oss << indent0 << "initial_moles=\"" << this-> @@ -109,6 +112,7 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const if (this->add_formula.size() != 0) s_oss << indent1 << "-add_formula " << this->add_formula << std::endl; s_oss << indent1 << "-si " << this->si << std::endl; + s_oss << indent1 << "-si_org " << this->si_org << std::endl; s_oss << indent1 << "-moles " << this->moles << std::endl; s_oss << indent1 << "-delta " << this->delta << std::endl; s_oss << indent1 << "-initial_moles " << this->initial_moles << std::endl; @@ -135,6 +139,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) vopts.push_back("dissolve_only"); // 6 vopts.push_back("force_equality"); // 7 vopts.push_back("precipitate_only"); // 8 + vopts.push_back("si_org"); // 9 } std::istream::pos_type ptr; @@ -145,6 +150,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) opt_save = CParser::OPT_ERROR; bool name_defined(false); bool si_defined(false); + bool si_org_defined(false); bool moles_defined(false); bool delta_defined(false); bool initial_moles_defined(false); @@ -288,6 +294,16 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->dissolve_only = false; } break; + case 9: // si_org + if (!(parser.get_iss() >> this->si_org)) + { + this->si_org = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for si_org.", + CParser::OT_CONTINUE); + } + si_org_defined = true; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -347,6 +363,12 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) ("Force_equality not defined for PPassemblageComp input.", CParser::OT_CONTINUE); } + if (si_org_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Si_org not defined for PPassemblageComp input.", + CParser::OT_CONTINUE); + } } } @@ -360,6 +382,7 @@ cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, ints.push_back(dictionary.string2int(this->name)); ints.push_back(dictionary.string2int(this->add_formula)); doubles.push_back(this->si); + doubles.push_back(this->si_org); doubles.push_back(this->moles); doubles.push_back(this->delta); doubles.push_back(this->initial_moles); @@ -377,6 +400,7 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->name = dictionary.int2stdstring(ints[i++]); this->add_formula = dictionary.int2stdstring(ints[i++]); this->si = doubles[d++]; + this->si_org = doubles[d++]; this->moles = doubles[d++]; this->delta = doubles[d++]; this->initial_moles = doubles[d++]; @@ -453,6 +477,8 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) } //double si; this->si = this->si * f1 + addee.si * f2; + //double si_org; + this->si_org = this->si_org * f1 + addee.si_org * f2; //double moles; this->moles += addee.moles * extensive; //double delta; diff --git a/PPassemblageComp.h b/PPassemblageComp.h index d7e8c4bb..1a2e2c36 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -50,6 +50,7 @@ class cxxPPassemblageComp: public PHRQ_base return (this->totals); }; double Get_si() const {return this->si;}; + double Get_si_org() const {return this->si_org;}; double Get_moles() const {return this->moles;}; double Get_delta() const {return this->delta;}; double Get_initial_moles() const {return this->initial_moles;}; @@ -69,6 +70,7 @@ protected: std::string name; std::string add_formula; double si; + double si_org; double moles; double delta; double initial_moles; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 28c7856d..7e4937fc 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -325,7 +325,11 @@ Phreeqc::Phreeqc(void) {"iso", tokiso}, {"iso_unit", tokiso_unit}, {"phase_formula", tokphase_formula}, - {"list_s_s", toklist_s_s} + {"list_s_s", toklist_s_s}, + {"pr_p", tokpr_p}, + {"pr_phi", tokpr_phi}, + {"gas_p", tokgas_p}, + {"gas_vm", tokgas_vm} }; NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); command = new const_key[NCMDS]; diff --git a/Phreeqc.h b/Phreeqc.h index befcbf11..ed820c51 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -86,6 +86,8 @@ LDBLE calc_surface_charge(const char *surface_name); LDBLE diff_layer_total(const char *total_name, const char *surface_name); LDBLE equi_phase(const char *phase_name); LDBLE find_gas_comp(const char *gas_comp_name); +LDBLE find_gas_p(void); +LDBLE find_gas_vm(void); LDBLE find_misc1(const char *s_s_name); LDBLE find_misc2(const char *s_s_name); LDBLE find_s_s_comp(const char *s_s_comp_name); @@ -96,6 +98,8 @@ LDBLE kinetics_moles(const char *kinetics_name); LDBLE log_activity(const char *species_name); LDBLE log_molality(const char *species_name); LDBLE molality(const char *species_name); +LDBLE pr_pressure(const char *phase_name); +LDBLE pr_phi(const char *phase_name); LDBLE saturation_ratio(const char *phase_name); int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); LDBLE solution_sum_secondary(const char *total_name); @@ -550,6 +554,7 @@ int setup_exchange(void); int setup_gas_phase(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); +LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); int setup_pure_phases(void); int setup_related_surface(void); int setup_s_s_assemblage(void); @@ -627,6 +632,10 @@ int read_conc(int n, int count_mass_balance, char *str); int *read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list); int read_log_k_only(char *ptr, LDBLE * log_k); +int read_t_c_only(char *ptr, LDBLE *t_c); +int read_p_c_only(char *ptr, LDBLE * p_c); +int read_omega_only(char *ptr, LDBLE *omega); +int read_delta_v_only(char *ptr, LDBLE * delta_v); int read_number_description(char *ptr, int *n_user, int *n_user_end, char **description, int allow_negative=FALSE); int check_key(char *str); From 7f18c67b25717edbeb17e8a30aa8083e5aa6ecb0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Nov 2011 21:01:02 +0000 Subject: [PATCH 0311/1077] fixed bug in phqalloc.cpp. Comment in Phreeqc.h for prep.c s_init initializes all variables. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5733 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index ed820c51..abd84a36 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -521,7 +521,7 @@ struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); int pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr); -// pitzer_structures.cpp ------------------------------- +// prep.cpp ------------------------------- int add_potential_factor(void); int add_cd_music_factors(int n); int add_surface_charge_balance(void); @@ -575,7 +575,6 @@ int write_mb_eqn_x(void); int write_mb_for_species_list(int n); int write_mass_action_eqn_x(int stop); -/* prep.cpp */ int check_same_model(void); int k_temp(LDBLE tc); LDBLE k_calc(LDBLE * logk, LDBLE tempk); From 516bd2ea1f8f59c08be038cc5420b929824e37a1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Nov 2011 20:09:14 +0000 Subject: [PATCH 0312/1077] Added PBasic with #ifdef PBASIC. Fixed one or two bugs with PR, copying or saving. (v_m in xgas_save. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5739 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 27 ++++++++++++++++++--------- Phreeqc.h | 21 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7e4937fc..66b75bf6 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -11,6 +11,9 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "phqalloc.h" +#if defined(PBASIC) +#include "PBasic.h" +#endif Phreeqc::Phreeqc(void) { @@ -168,6 +171,7 @@ Phreeqc::Phreeqc(void) } // basic.c +#if !defined(PBASIC) struct const_key command_temp[] = { {"+", tokplus}, {"-", tokminus}, @@ -338,6 +342,7 @@ Phreeqc::Phreeqc(void) command[i].name = string_duplicate(command_temp[i].name); command[i].keycount = command_temp[i].keycount; } +#endif //cl1.c x_arg = NULL, res_arg = NULL, scratch = NULL; @@ -411,11 +416,13 @@ Phreeqc::~Phreeqc(void) keyword[i].name = (char *) free_check_null((void *) keyword[i].name); } delete[] keyword; +#if !defined(PBASIC) for (i = 0; i < NCMDS; i++) { command[i].name = (char *) free_check_null((void *) command[i].name); } delete[] command; +#endif free_check_null(default_data_base); free_check_null(sformatf_buffer); @@ -840,10 +847,7 @@ void Phreeqc::init(void) llnl_co2_coefs = 0; llnl_count_co2_coefs = 0; -/* - * - */ - command_hash_table = 0; + change_surf = 0; change_surf_count = 0; @@ -997,6 +1001,8 @@ void Phreeqc::init(void) // Non-class statics // /* basic.c */ +#if !defined(PBASIC) + command_hash_table = 0; n_user_punch_index = 0; inbuf = NULL; linebase = NULL; @@ -1010,6 +1016,12 @@ void Phreeqc::init(void) buf = NULL; exitflag = FALSE; EXCP_LINE = 0; + /* p2clib.c */ + P_argc = 0; + P_argv = NULL; + P_escapecode = 0; + P_ioresult = 0; +#endif /* dw.c */ Q0 = 0; Q5 = 0; @@ -1022,6 +1034,7 @@ void Phreeqc::init(void) B2T = 0; B1TT = 0; B2TT = 0; + /* integrate.c */ z = 0; xd = 0; @@ -1094,11 +1107,7 @@ void Phreeqc::init(void) /* kinetics.c */ m_original = NULL; m_temp = NULL; - /* p2clib.c */ - P_argc = 0; - P_argv = NULL; - P_escapecode = 0; - P_ioresult = 0; + /* pitzer.c */ A0 = 0; count_cations = 0; diff --git a/Phreeqc.h b/Phreeqc.h index abd84a36..54925023 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -52,7 +52,11 @@ class cxxSurfaceComp; class cxxStorageBin; #include "global_structures.h" +#if defined(PBASIC) +class PBasic; +#else #include "basic.h" +#endif class Phreeqc { @@ -69,7 +73,13 @@ public: int advection(void); // basic.cpp +#if !defined(PBASIC) #include "basic_class.h" +#else +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +void cmd_free(void); +#endif // basicsubs.cpp ------------------------------- LDBLE activity(const char *species_name); @@ -1321,7 +1331,7 @@ protected: // //Data members // - +protected: std::list cookie_list; std::ifstream * in_stream; std::ifstream * db_stream; @@ -1856,6 +1866,10 @@ LDBLE f_rho(LDBLE rho_old); PHRQMemHeader *s_pTail; std::stringstream merged_database_stream; std::stringstream merged_input_stream; +/* Basic */ +#if defined(PBASIC) +PBasic * basic_instance; +#endif /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; @@ -2055,6 +2069,11 @@ int stop_calculations; char err_str98[80]; #endif +#if defined(PBASIC) +friend class PBasic; +#endif +friend class ChartObject; + #endif /* _INC_PHREEQC_H */ /********************************* From 40f0539ebee0423864cceac6f8c9f387e8ec4e35 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Nov 2011 20:11:56 +0000 Subject: [PATCH 0313/1077] PBasic files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5740 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 6276 ++++++++++++++++++++++++++++++++++++++++++++++++++++ PBasic.h | 488 ++++ 2 files changed, 6764 insertions(+) create mode 100644 PBasic.cpp create mode 100644 PBasic.h diff --git a/PBasic.cpp b/PBasic.cpp new file mode 100644 index 00000000..a418f5e5 --- /dev/null +++ b/PBasic.cpp @@ -0,0 +1,6276 @@ +#if defined(PBASIC) +#if defined(WIN32) +#include +#endif + +/* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + +#include +#include "PBasic.h" +#include "Phreeqc.h" + + +#define STOP 1 +#define CONTINUE 0 + +#define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ + + + +/* Output from p2c, the Pascal-to-C translator */ +/* From input file "basic.p" */ + +typedef unsigned char boolean; +#include "phqalloc.h" +#include "NameDouble.h" + +PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) + : PHRQ_base(phrq_io) +{ + if (ptr == NULL) + { + error_msg("No Phreeqc instance in PBasic constructor\n", 1); + } + PhreeqcPtr = ptr; + inbuf = NULL; + linebase = NULL; + varbase = NULL; + loopbase = NULL; + curline = 0; + stmtline = NULL; + dataline = NULL; + stmttok = NULL; + datatok = NULL; + buf = NULL; + exitflag = FALSE; + EXCP_LINE = 0; + P_argc = 0; + P_argv = NULL; + P_escapecode = 0; + P_ioresult = 0; + + struct const_key command_temp[] = { + {"+", tokplus}, + {"-", tokminus}, + {"*", toktimes}, + {"/", tokdiv}, + {"^", tokup}, + {"( or [", toklp}, + {") or ]", tokrp}, + {",", tokcomma}, + {";", toksemi}, + {":", tokcolon}, + {"=", tokeq}, + {"<", toklt}, + {"<=", tokle}, + {">", tokgt}, + {">=", tokge}, + {"and", tokand}, + {"or", tokor}, + {"xor", tokxor}, + {"not", toknot}, + {"mod", tokmod}, + {"sqr", toksqr}, + {"sqrt", toksqrt}, + {"ceil", tokceil}, + {"floor", tokfloor}, + {"sin", toksin}, + {"cos", tokcos}, + {"tan", toktan}, + {"arctan", tokarctan}, + {"log", toklog}, + {"exp", tokexp}, + {"abs", tokabs}, + {"sgn", toksgn}, + {"str$", tokstr_}, + {"val", tokval}, + {"chr$", tokchr_}, + {"eol$", tokeol_}, + {"asc", tokasc}, + {"len", toklen}, + {"mid$", tokmid_}, + {"peek", tokpeek}, + {"let", toklet}, + {"print", tokprint}, + {"punch", tokpunch}, + #if defined PHREEQ98 || defined MULTICHART + {"graph_x", tokgraph_x}, + {"graph_y", tokgraph_y}, + {"graph_sy", tokgraph_sy}, + #endif + #if defined MULTICHART + {"plot_xy", tokplot_xy}, + #endif + {"input", tokinput}, + {"goto", tokgoto}, + {"go to", tokgoto}, + {"if", tokif}, + {"end", tokend}, + {"stop", tokstop}, + {"for", tokfor}, + {"next", toknext}, + {"while", tokwhile}, + {"wend", tokwend}, + {"gosub", tokgosub}, + {"return", tokreturn}, + {"read", tokread}, + {"data", tokdata}, + {"restore", tokrestore}, + {"gotoxy", tokgotoxy}, + {"on", tokon}, + {"dim", tokdim}, + {"poke", tokpoke}, + {"list", toklist}, + {"run", tokrun}, + {"new", toknew}, + {"load", tokload}, + {"merge", tokmerge}, + {"save", toksave}, + {"bye", tokbye}, + {"quit", tokbye}, + {"del", tokdel}, + {"renum", tokrenum}, + {"then", tokthen}, + {"else", tokelse}, + {"to", tokto}, + {"step", tokstep}, + {"tc", toktc}, + {"tk", toktk}, + {"time", toktime}, + {"sim_time", toksim_time}, + {"total_time", toktotal_time}, + {"m0", tokm0}, + {"m", tokm}, + {"parm", tokparm}, + {"act", tokact}, + {"edl", tokedl}, + {"surf", toksurf}, + {"equi", tokequi}, + {"kin", tokkin}, + {"gas", tokgas}, + {"s_s", toks_s}, + {"misc1", tokmisc1}, + {"misc2", tokmisc2}, + {"mu", tokmu}, + {"osmotic", tokosmotic}, + {"alk", tokalk}, + {"lk_species", toklk_species}, + {"lk_named", toklk_named}, + {"lk_phase", toklk_phase}, + {"sum_species", toksum_species}, + {"sum_gas", toksum_gas}, + {"sum_s_s", toksum_s_s}, + {"calc_value", tokcalc_value}, + {"description", tokdescription}, + {"sys", toksys}, + {"instr", tokinstr}, + {"ltrim", tokltrim}, + {"rtrim", tokrtrim}, + {"trim", toktrim}, + {"pad", tokpad}, + {"rxn", tokrxn}, + {"dist", tokdist}, + {"mol", tokmol}, + {"la", tokla}, + {"lm", toklm}, + {"sr", toksr}, + {"si", toksi}, + {"step_no", tokstep_no}, + {"cell_no", tokcell_no}, + {"sim_no", toksim_no}, + {"tot", toktot}, + {"log10", toklog10}, + {"charge_balance", tokcharge_balance}, + {"percent_error", tokpercent_error}, + {"put", tokput}, + {"get", tokget}, + {"exists", tokexists}, + {"rem", tokrem}, + {"change_por", tokchange_por}, + {"get_por", tokget_por}, + {"change_surf", tokchange_surf}, + {"porevolume", tokporevolume}, + {"sc", toksc}, + {"gamma", tokgamma}, + /* VP: Density Start */ + {"lg", toklg}, + {"rho", tokrho}, + /* VP: Density End */ + {"cell_volume", tokcell_volume}, + {"cell_pore_volume", tokcell_pore_volume}, + {"cell_porosity", tokcell_porosity}, + {"cell_saturation", tokcell_saturation}, + {"totmole", toktotmole}, + {"totmol", toktotmol}, + {"totmoles", toktotmoles}, + {"iso", tokiso}, + {"iso_unit", tokiso_unit}, + {"phase_formula", tokphase_formula}, + {"list_s_s", toklist_s_s}, + {"pr_p", tokpr_p}, + {"pr_phi", tokpr_phi}, + {"gas_p", tokgas_p}, + {"gas_vm", tokgas_vm} + }; + NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); + command = new const_key[NCMDS]; + int i; + for (i = 0; i < NCMDS; i++) + { + command[i].name = PhreeqcPtr->string_duplicate(command_temp[i].name); + command[i].keycount = command_temp[i].keycount; + } + this->cmd_initialize(); +} +PBasic::~PBasic(void) +{ + this->cmd_free(); +} +void PBasic:: +PASCAL_MAIN(int argc, char **argv) +{ + P_argc = argc; + P_argv = argv; + __top_jb = NULL; + P_escapecode = 0; + P_ioresult = 0; +} +/* ---------------------------------------------------------------------- */ +void PBasic:: +cmd_initialize(void) +/* ---------------------------------------------------------------------- */ +{ + ENTRY item, *found_item; + int i; + char *token; +/* + * create hash table + */ + PhreeqcPtr->hcreate_multi((unsigned) 2 * NCMDS, &command_hash_table); +/* + * fill with commands + */ + for (i = 0; i < NCMDS; i++) + { + token = PhreeqcPtr->string_hsave(command[i].name); + item.key = token; + item.data = (void *) &command[i]; + found_item = PhreeqcPtr->hsearch_multi(command_hash_table, item, ENTER); + if (found_item == NULL) + { + sprintf(PhreeqcPtr->error_string, + "Hash table error in basic commands initialization."); + PhreeqcPtr->error_msg(PhreeqcPtr->error_string, STOP); + } + } + return; +} + +/* ---------------------------------------------------------------------- */ +void PBasic:: +cmd_free(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * destroy hash table + */ + + PhreeqcPtr->hdestroy_multi(command_hash_table); + command_hash_table = NULL; + return; +} + +int PBasic:: +basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main */ + int l; + char *ptr; + + PASCAL_MAIN(0, NULL); + inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do + { + TRY(try2); + ptr = commands; + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + PhreeqcPtr->PHRQ_free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + return (P_escapecode); +} + +int PBasic:: +basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) +{ /*main */ + int l, i; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + do + { + TRY(try2); + i = 0; + ptr = commands; + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + i++; + if (i == 1) + { + strcpy(inbuf, "renum"); + } + else if (i == 2) + { + strcpy(inbuf, "list"); + } + else if (i == 3) + { + strcpy(inbuf, "new"); + } + else if (i == 4) + { + strcpy(inbuf, "bye"); + } + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + /* exit(EXIT_SUCCESS); */ + PhreeqcPtr->PHRQ_free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + + return (P_escapecode); +} + +int PBasic:: +basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) +{ /*main */ + int l; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; + exitflag = false; + ptr = commands; + linebase = (linerec *) lnbase; + varbase = (varrec *) vbase; + loopbase = (looprec *) lpbase; + do + { + TRY(try2); + do + { + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + + /* exit(EXIT_SUCCESS); */ + PhreeqcPtr->PHRQ_free(inbuf); + return (P_escapecode); +} + +int PBasic:: +basic_main(char *commands) +{ /*main */ + int l; + char *ptr; + PASCAL_MAIN(0, NULL); + inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (inbuf == NULL) + PhreeqcPtr->malloc_error(); + linebase = NULL; + varbase = NULL; + loopbase = NULL; +#ifdef SKIP + printf("Chipmunk BASIC 1.0\n\n"); +#endif + exitflag = false; + ptr = commands; + do + { + TRY(try2); + do + { +#ifdef SKIP + putchar('>'); +#endif + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } + } + while (!(exitflag || P_eof())); + RECOVER(try2); + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } + ENDTRY(try2); + } + while (!(exitflag || P_eof())); + return 1; +/* exit(EXIT_SUCCESS); */ +} + +/* End. */ +/* ---------------------------------------------------------------------- */ +int PBasic:: +sget_logical_line(char **ptr, int *l, char *return_line) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads file fp until end of line, ";", or eof + * stores characters in line_save + * reallocs line_save and line if more space is needed + * + * returns: + * EOF on empty line on end of file or + * OK otherwise + * *l returns length of line + */ + int i; + char c; + i = 0; + if (**ptr == '\0') + return (EOF); + for (;;) + { + c = **ptr; + if (c == '\0') + break; + (*ptr)++; + if (c == ';' || c == '\n') + break; + return_line[i++] = c; + } + return_line[i] = '\0'; + *l = i; + return (1); +} + void PBasic:: +restoredata(void) +{ + dataline = NULL; + datatok = NULL; +} + + + + void PBasic:: +clearloops(void) +{ + looprec *l; + + while (loopbase != NULL) + { + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + } +} + + + + void PBasic:: +clearvar(varrec * v) +{ + if (v->numdims != 0) + { + if (v->stringvar == 0) + { + PhreeqcPtr->PHRQ_free(v->UU.U0.arr); + v->UU.U0.arr = NULL; + } + else + { + free_dim_stringvar(v); + } + } + else if (v->stringvar && v->UU.U1.sv != NULL) + { + PhreeqcPtr->PHRQ_free(v->UU.U1.sv); + } + v->numdims = 0; + if (v->stringvar) + { + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } + else + { + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } +} + + + void PBasic:: +clearvars(void) +{ + varrec *v; + + v = varbase; + while (v != NULL) + { + clearvar(v); + v = v->next; + } +} + +char * PBasic:: +numtostr(char * Result, LDBLE n) +{ + /*string255 s; */ + char *l_s; + long i; + + l_s = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (l_s == NULL) + PhreeqcPtr->malloc_error(); + l_s[PhreeqcPtr->max_line - 1] = '\0'; +/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ + if (ceil(n) == floor(n)) + { + if (PhreeqcPtr->punch.high_precision == FALSE) + { + sprintf(l_s, "%12g", (double) n); + } + else + { + sprintf(l_s, "%19g", (double) n); + } + } + else + { + if (PhreeqcPtr->punch.high_precision == FALSE) + { + sprintf(l_s, "%12.4e", (double) n); + } + else + { + sprintf(l_s, "%20.12e", (double) n); + } + } + i = (int) strlen(l_s) + 1; + l_s[i - 1] = '\0'; +/* p2c: basic.p, line 237: + * Note: Modification of string length may translate incorrectly [146] */ + strcpy(Result, l_s); + PhreeqcPtr->free_check_null(l_s); + return (Result); +/* } else { + if (PhreeqcPtr->punch.high_precision == FALSE) sprintf(l_s, "%30.10f", n); + else sprintf(l_s, "%30.12f", n); + i = strlen(l_s) + 1; + do { + i--; + } while (l_s[i - 1] == '0'); + if (l_s[i - 1] == '.') + i--; + l_s[i] = '\0'; + * p2c: basic.p, line 248: + * Note: Modification of string length may translate incorrectly [146] * + return strcpy(Result, strltrim(l_s)); + } */ +} + +#define toklength 20 + + +typedef long chset[9]; + + + + + + void PBasic:: +parse(char * l_inbuf, tokenrec ** l_buf) +{ + long i, j, begin, len, m, lp, q; + char token[toklength + 1] = {0}; + tokenrec *t, *tptr; + varrec *v; + char ch; + ENTRY item, *found_item; + char *ptr; + + tptr = NULL; + *l_buf = NULL; + i = 1; + lp = q = 0; + do + { + ch = ' '; + while (i <= (int) strlen(l_inbuf) && (ch == ' ' || ch == '\t')) + { + ch = l_inbuf[i - 1]; + i++; + } + if (ch != ' ') + { + t = (tokenrec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(tokenrec)); + if (t == NULL) + PhreeqcPtr->malloc_error(); + if (tptr == NULL) + *l_buf = t; + else + tptr->next = t; + tptr = t; + t->next = NULL; + switch (ch) + { + + case '"': + case '\'': + q += 1; + t->kind = tokstr; + j = 0; + len = (int) strlen(l_inbuf); + begin = i; + while (i <= len && l_inbuf[i - 1] != ch) + { + ++j; + ++i; + } + if (l_inbuf[i - 1] == ch) q -= 1; + m = 256; + if (j + 1 > m) + m = j + 1; + t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + strncpy(t->UU.sp, l_inbuf + begin - 1, j); + t->UU.sp[j] = '\0'; +/* p2c: basic.p, line 415: + * Note: Modification of string length may translate incorrectly [146] */ + i++; + break; + + case '+': + t->kind = tokplus; + break; + + case '-': + t->kind = tokminus; + break; + + case '*': + t->kind = toktimes; + break; + + case '/': + t->kind = tokdiv; + break; + + case '^': + t->kind = tokup; + break; + + case '(': + case '[': + t->kind = toklp; + lp += 1; + break; + + case ')': + case ']': + t->kind = tokrp; + lp -= 1; + break; + + case ',': + t->kind = tokcomma; + break; + + case ';': + t->kind = toksemi; + break; + + case ':': + t->kind = tokcolon; + break; + + case '?': + t->kind = tokprint; + break; + + case '=': + t->kind = tokeq; + break; + + case '<': + if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') + { + t->kind = tokle; + i++; + } + else if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '>') + { + t->kind = tokne; + i++; + } + else + t->kind = toklt; + break; + + case '>': + if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') + { + t->kind = tokge; + i++; + } + else + t->kind = tokgt; + break; + + default: + if (isalpha((int) ch)) + { + i--; + j = 0; + token[toklength] = '\0'; + while (i <= (int) strlen(l_inbuf) && + (l_inbuf[i - 1] == '$' || l_inbuf[i - 1] == '_' || + isalnum((int) l_inbuf[i - 1]))) + { + if (j < toklength) + { + j++; + token[j - 1] = l_inbuf[i - 1]; + } + i++; + } + token[j] = '\0'; +/* p2c: basic.p, line 309: + * Note: Modification of string length may translate incorrectly [146] */ +#define INT +#ifdef INT +/* + * Search hash list + */ + PhreeqcPtr->str_tolower(token); + item.key = token; + item.data = NULL; + found_item = + PhreeqcPtr->hsearch_multi(command_hash_table, item, FIND); + if (found_item != NULL) + { + t->kind = + ((struct key *) (found_item->data))->keycount; + if (t->kind == tokrem) + { + m = (int) strlen(l_inbuf) + 1; + if (m < 256) + m = 256; + t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int) (strlen(l_inbuf) - i + 1), + l_inbuf + i - 1); + i = (int) strlen(l_inbuf) + 1; + } +#endif +#ifdef LONG + if (!strcmp(token, "and")) + t->kind = tokand; + else if (!strcmp(token, "or")) + t->kind = tokor; + else if (!strcmp(token, "xor")) + t->kind = tokxor; + else if (!strcmp(token, "not")) + t->kind = toknot; + else if (!strcmp(token, "mod")) + t->kind = tokmod; + else if (!strcmp(token, "sqr")) + t->kind = toksqr; + else if (!strcmp(token, "sqrt")) + t->kind = toksqrt; + else if (!strcmp(token, "ceil")) + t->kind = tokceil; + else if (!strcmp(token, "floor")) + t->kind = tokfloor; + else if (!strcmp(token, "sin")) + t->kind = toksin; + else if (!strcmp(token, "cos")) + t->kind = tokcos; + else if (!strcmp(token, "tan")) + t->kind = toktan; + else if (!strcmp(token, "arctan")) + t->kind = tokarctan; + else if (!strcmp(token, "log")) + t->kind = toklog; + else if (!strcmp(token, "exp")) + t->kind = tokexp; + else if (!strcmp(token, "abs")) + t->kind = tokabs; + else if (!strcmp(token, "sgn")) + t->kind = toksgn; + else if (!strcmp(token, "str$")) + t->kind = tokstr_; + else if (!strcmp(token, "val")) + t->kind = tokval; + else if (!strcmp(token, "chr$")) + t->kind = tokchr_; + else if (!strcmp(token, "eol$")) + t->kind = tokeol_; + else if (!strcmp(token, "asc")) + t->kind = tokasc; + else if (!strcmp(token, "len")) + t->kind = toklen; + else if (!strcmp(token, "mid$")) + t->kind = tokmid_; + else if (!strcmp(token, "peek")) + t->kind = tokpeek; + else if (!strcmp(token, "let")) + t->kind = toklet; + else if (!strcmp(token, "print")) + t->kind = tokprint; + else if (!strcmp(token, "PhreeqcPtr->punch")) + t->kind = tokpunch; +#if defined PHREEQ98 + else if (!strcmp(token, "graph_x")) + t->kind = tokgraph_x; + else if (!strcmp(token, "graph_y")) + t->kind = tokgraph_y; + else if (!strcmp(token, "graph_sy")) + t->kind = tokgraph_sy; +#endif + else if (!strcmp(token, "input")) + t->kind = tokinput; + else if (!strcmp(token, "goto")) + t->kind = tokgoto; + else if (!strcmp(token, "go to")) + t->kind = tokgoto; + else if (!strcmp(token, "if")) + t->kind = tokif; + else if (!strcmp(token, "end")) + t->kind = tokend; + else if (!strcmp(token, "stop")) + t->kind = tokstop; + else if (!strcmp(token, "for")) + t->kind = tokfor; + else if (!strcmp(token, "next")) + t->kind = toknext; + else if (!strcmp(token, "while")) + t->kind = tokwhile; + else if (!strcmp(token, "wend")) + t->kind = tokwend; + else if (!strcmp(token, "gosub")) + t->kind = tokgosub; + else if (!strcmp(token, "return")) + t->kind = tokreturn; + else if (!strcmp(token, "read")) + t->kind = tokread; + else if (!strcmp(token, "data")) + t->kind = tokdata; + else if (!strcmp(token, "restore")) + t->kind = tokrestore; + else if (!strcmp(token, "gotoxy")) + t->kind = tokgotoxy; + else if (!strcmp(token, "on")) + t->kind = tokon; + else if (!strcmp(token, "dim")) + t->kind = tokdim; + else if (!strcmp(token, "poke")) + t->kind = tokpoke; + else if (!strcmp(token, "list")) + t->kind = toklist; + else if (!strcmp(token, "run")) + t->kind = tokrun; + else if (!strcmp(token, "new")) + t->kind = toknew; + else if (!strcmp(token, "load")) + t->kind = tokload; + else if (!strcmp(token, "merge")) + t->kind = tokmerge; + else if (!strcmp(token, "save")) + t->kind = toksave; + else if (!strcmp(token, "bye")) + t->kind = tokbye; + else if (!strcmp(token, "quit")) + t->kind = tokbye; + else if (!strcmp(token, "del")) + t->kind = tokdel; + else if (!strcmp(token, "renum")) + t->kind = tokrenum; + else if (!strcmp(token, "then")) + t->kind = tokthen; + else if (!strcmp(token, "else")) + t->kind = tokelse; + else if (!strcmp(token, "to")) + t->kind = tokto; + else if (!strcmp(token, "step")) + t->kind = tokstep; + /* + * dlp: added functions + */ + else if (!strcmp(token, "tc")) + t->kind = toktc; + else if (!strcmp(token, "tk")) + t->kind = toktk; + else if (!strcmp(token, "time")) + t->kind = toktime; + else if (!strcmp(token, "sim_time")) + t->kind = toksim_time; + else if (!strcmp(token, "total_time")) + t->kind = toktotal_time; + else if (!strcmp(token, "m0")) + t->kind = tokm0; + else if (!strcmp(token, "m")) + t->kind = tokm; + else if (!strcmp(token, "parm")) + t->kind = tokparm; + else if (!strcmp(token, "act")) + t->kind = tokact; + else if (!strcmp(token, "change_por")) + t->kind = tokchange_por; + else if (!strcmp(token, "get_por")) + t->kind = tokget_por; + else if (!strcmp(token, "change_surf")) + t->kind = tokchange_surf; + else if (!strcmp(token, "porevolume")) + t->kind = tokporevolume; + else if (!strcmp(token, "edl")) + t->kind = tokedl; + else if (!strcmp(token, "surf")) + t->kind = toksurf; + else if (!strcmp(token, "equi")) + t->kind = tokequi; + else if (!strcmp(token, "kin")) + t->kind = tokkin; + else if (!strcmp(token, "gas")) + t->kind = tokgas; + else if (!strcmp(token, "s_s")) + t->kind = toks_s; + else if (!strcmp(token, "misc1")) + t->kind = tokmisc1; + else if (!strcmp(token, "misc2")) + t->kind = tokmisc2; + else if (!strcmp(token, "mu")) + t->kind = tokmu; + else if (!strcmp(token, "osmotic")) + t->kind = tokosmotic; + else if (!strcmp(token, "alk")) + t->kind = tokalk; + else if (!strcmp(token, "lk_species")) + t->kind = toklk_species; + else if (!strcmp(token, "lk_named")) + t->kind = toklk_named; + else if (!strcmp(token, "lk_phase")) + t->kind = toklk_phase; + else if (!strcmp(token, "sum_species")) + t->kind = toksum_species; + else if (!strcmp(token, "sum_gas")) + t->kind = toksum_gas; + else if (!strcmp(token, "sum_s_s")) + t->kind = toksum_s_s; + else if (!strcmp(token, "calc_value")) + t->kind = tokcalc_value; + else if (!strcmp(token, "description")) + t->kind = tokdescription; + else if (!strcmp(token, "sys")) + t->kind = toksys; + else if (!strcmp(token, "instr")) + t->kind = tokinstr; + else if (!strcmp(token, "ltrim")) + t->kind = tokltrim; + else if (!strcmp(token, "rtrim")) + t->kind = tokrtrim; + else if (!strcmp(token, "trim")) + t->kind = toktrim; + else if (!strcmp(token, "pad")) + t->kind = tokpad; + else if (!strcmp(token, "rxn")) + t->kind = tokrxn; + else if (!strcmp(token, "dist")) + t->kind = tokdist; + else if (!strcmp(token, "mol")) + t->kind = tokmol; + else if (!strcmp(token, "la")) + t->kind = tokla; + else if (!strcmp(token, "lm")) + t->kind = toklm; + else if (!strcmp(token, "sr")) + t->kind = toksr; + else if (!strcmp(token, "step_no")) + t->kind = tokstep_no; + else if (!strcmp(token, "cell_no")) + t->kind = tokcell_no; + else if (!strcmp(token, "sim_no")) + t->kind = toksim_no; + else if (!strcmp(token, "si")) + t->kind = toksi; + else if (!strcmp(token, "tot")) + t->kind = toktot; + else if (!strcmp(token, "totmole")) + t->kind = toktotmole; + else if (!strcmp(token, "totmol")) + t->kind = toktotmole; + else if (!strcmp(token, "totmoles")) + t->kind = toktotmole; + else if (!strcmp(token, "log10")) + t->kind = toklog10; + else if (!strcmp(token, "put")) + t->kind = tokput; + else if (!strcmp(token, "get")) + t->kind = tokget; + else if (!strcmp(token, "exists")) + t->kind = tokexists; + else if (!strcmp(token, "charge_balance")) + t->kind = tokcharge_balance; + else if (!strcmp(token, "percent_error")) + t->kind = tokpercent_error; + else if (!strcmp(token, "SC")) + t->kind = tokspcond; + else if (!strcmp(token, "rem")) + { + t->kind = tokrem; + m = strlen(l_inbuf) + 1; + if (m < 256) + m = 256; + t->UU.sp = (char *) PhreeqcPtr->PhreeqcPtr->PHRQ_malloc(m); + if (t->UU.sp == NULL) + PhreeqcPtr->malloc_error(); + sprintf(t->UU.sp, "%.*s", + (int) (strlen(l_inbuf) - i + 1), + l_inbuf + i - 1); + i = strlen(l_inbuf) + 1; + } +#endif + } + else + { + t->kind = tokvar; + v = varbase; + while (v != NULL && strcmp(v->name, token)) + v = v->next; + if (v == NULL) + { + v = (varrec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(varrec)); + if (v == NULL) + PhreeqcPtr->malloc_error(); + v->UU.U0.arr = NULL; + v->next = varbase; + varbase = v; + strcpy(v->name, token); + v->numdims = 0; + if (token[strlen(token) - 1] == '$') + { + v->stringvar = true; + v->UU.U1.sv = NULL; + v->UU.U1.sval = &v->UU.U1.sv; + } + else + { + v->stringvar = false; + v->UU.U0.rv = 0.0; + v->UU.U0.val = &v->UU.U0.rv; + } + } + t->UU.vp = v; + } + } + else if (isdigit((int) ch) || ch == '.') + { + t->kind = toknum; + i--; + t->UU.num = strtod(&l_inbuf[i - 1], &ptr); + if (&l_inbuf[i - 1] == ptr) + { + /* + Note: the following causes an infinite loop: + X = ..9 + */ + t->kind = toksnerr; + t->UU.snch = ch; + i++; + break; + } + i += (int) (ptr - &l_inbuf[i - 1]); + } + else + { + t->kind = toksnerr; + t->UU.snch = ch; + } + break; + } + } + } + while (i <= (int) strlen(l_inbuf)); + if (q) { + sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } + if (lp > 0) { + sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } + else if (lp < 0) { + sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } +} + +#undef toklength + + + + void PBasic:: +listtokens(FILE * f, tokenrec * l_buf) +{ + boolean ltr; + char STR1[256] = {0}; + char *string; + ltr = false; + while (l_buf != NULL) + { + if ((l_buf->kind >= (long) toknot && l_buf->kind <= (long) tokrenum) || + l_buf->kind == (long) toknum || l_buf->kind == (long) tokvar || + l_buf->kind >= (long) toktc) + { + if (ltr) + /*putc(' ', f); */ + output_msg(" "); + ltr = (boolean) (l_buf->kind != toknot); + } + else + ltr = false; + switch (l_buf->kind) + { + + case tokvar: + /*fputs(l_buf->UU.vp->name, f); */ + PhreeqcPtr->output_msg(PhreeqcPtr->sformatf("%s", l_buf->UU.vp->name)); + break; + + case toknum: + /*fputs(numtostr(STR1, l_buf->UU.num), f); */ + string = numtostr(STR1, l_buf->UU.num); + PhreeqcPtr->string_trim(string); + output_msg(PhreeqcPtr->sformatf("%s", string)); + break; + + case tokstr: + output_msg(PhreeqcPtr->sformatf("\"%s\"", l_buf->UU.sp)); + break; + + case toksnerr: + output_msg(PhreeqcPtr->sformatf("{%c}", l_buf->UU.snch)); + break; + + case tokplus: + /*putc('+', f); */ + output_msg("+"); + break; + + case tokminus: + /*putc('-', f); */ + output_msg("-"); + break; + + case toktimes: + /*putc('*', f); */ + output_msg("*"); + break; + + case tokdiv: + /*putc('/', f); */ + output_msg("/"); + break; + + case tokup: + /*putc('^', f); */ + output_msg("^"); + break; + + case toklp: + /*putc('(', f); */ + output_msg("("); + break; + + case tokrp: + /*putc(')', f); */ + output_msg(")"); + break; + + case tokcomma: + /*putc(',', f); */ + output_msg(","); + break; + + case toksemi: + /*putc(';', f); */ + output_msg(";"); + break; + + case tokcolon: + output_msg(" : "); + break; + + case tokeq: + output_msg(" = "); + break; + + case toklt: + output_msg(" < "); + break; + + case tokgt: + output_msg(" > "); + break; + + case tokle: + output_msg(" <= "); + break; + + case tokge: + output_msg(" >= "); + break; + + case tokne: + output_msg(" <> "); + break; + + case tokand: + output_msg(" AND "); + break; + + case tokor: + output_msg(" OR "); + break; + + case tokxor: + output_msg(" XOR "); + break; + + case tokmod: + output_msg(" MOD "); + break; + + case toknot: + output_msg("NOT "); + break; + + case toksqr: + output_msg("SQR"); + break; + + case toksqrt: + output_msg("SQRT"); + break; + + case tokceil: + output_msg("CEIL"); + break; + + case tokfloor: + output_msg("FLOOR"); + break; + + case toksin: + output_msg("SIN"); + break; + + case tokcos: + output_msg("COS"); + break; + + case toktan: + output_msg("TAN"); + break; + + case tokarctan: + output_msg("ARCTAN"); + break; + + case toklog: + output_msg("LOG"); + break; + + case tokexp: + output_msg("EXP"); + break; + + case tokabs: + output_msg("ABS"); + break; + + case toksgn: + output_msg("SGN"); + break; + + case tokstr_: + output_msg("STR$"); + break; + + case tokval: + output_msg("VAL"); + break; + + case tokchr_: + output_msg("CHR$"); + break; + + case tokeol_: + output_msg("EOL$"); + break; + + case tokasc: + output_msg("ASC"); + break; + + case toklen: + output_msg("LEN"); + break; + + case tokmid_: + output_msg("MID$"); + break; + + case tokpeek: + output_msg("PEEK"); + break; + + case tokrem: + output_msg(PhreeqcPtr->sformatf("REM%s", l_buf->UU.sp)); + break; + + case toklet: + output_msg("LET"); + break; + + case tokprint: + output_msg("PRINT"); + break; + + case tokinput: + output_msg("INPUT"); + break; + + case tokgoto: + output_msg("GOTO"); + break; + + case tokif: + output_msg("IF"); + break; + + case tokend: + output_msg("END"); + break; + + case tokstop: + output_msg("STOP"); + break; + + case tokfor: + output_msg("FOR"); + break; + + case toknext: + output_msg("NEXT"); + break; + + case tokwhile: + output_msg("WHILE"); + break; + + case tokwend: + output_msg("WEND"); + break; + + case tokgosub: + output_msg("GOSUB"); + break; + + case tokreturn: + output_msg("RETURN"); + break; + + case tokread: + output_msg("READ"); + break; + + case tokdata: + output_msg("DATA"); + break; + + case tokrestore: + output_msg("RESTORE"); + break; + + case tokgotoxy: + output_msg("GOTOXY"); + break; + + case tokon: + output_msg("ON"); + break; + + case tokdim: + output_msg("DIM"); + break; + + case tokpoke: + output_msg("POKE"); + break; + + case toklist: + output_msg("LIST"); + break; + + case tokrun: + output_msg("RUN"); + break; + + case toknew: + output_msg("NEW"); + break; + + case tokload: + output_msg("LOAD"); + break; + + case tokmerge: + output_msg("MERGE"); + break; + + case toksave: + output_msg("SAVE"); + break; + + case tokbye: + output_msg("BYE"); + break; + + case tokdel: + output_msg("DEL"); + break; + + case tokrenum: + output_msg("RENUM"); + break; + + case tokthen: + output_msg(" THEN "); + break; + + case tokelse: + output_msg(" ELSE "); + break; + + case tokto: + output_msg(" TO "); + break; + + case tokstep: + output_msg(" STEP "); + break; + + case toktc: + output_msg("TC"); + break; + + case tokm0: + output_msg("M0"); + break; + + case tokm: + output_msg("M"); + break; + + case tokparm: + output_msg("PARM"); + break; + + case tokact: + output_msg("ACT"); + break; + + case tokchange_por: + output_msg("CHANGE_POR"); + break; + + case tokget_por: + output_msg("GET_POR"); + break; + + case tokchange_surf: + output_msg("CHANGE_SURF"); + break; + + case tokporevolume: + output_msg("POREVOLUME"); + break; + + case tokmol: + output_msg("MOL"); + break; + + case tokla: + output_msg("LA"); + break; + + case toklm: + output_msg("LM"); + break; + + case toksr: + output_msg("SR"); + break; + + case toksi: + output_msg("SI"); + break; + + case toktot: + output_msg("TOT"); + break; + + case toktotmole: + case toktotmol: + case toktotmoles: + output_msg("TOTMOLE"); + break; + + case toktk: + output_msg("TK"); + break; + + case toktime: + output_msg("TIME"); + break; + + case toklog10: + output_msg("LOG10"); + break; + + case toksim_time: + output_msg("SIM_TIME"); + break; + + case tokequi: + output_msg("EQUI"); + break; + + case tokgas: + output_msg("GAS"); + break; + + case tokpunch: + output_msg("PUNCH"); + break; + + case tokkin: + output_msg("KIN"); + break; + + case toks_s: + output_msg("S_S"); + break; + + case tokmu: + output_msg("MU"); + break; + + case tokosmotic: + output_msg("OSMOTIC"); + break; + + case tokalk: + output_msg("ALK"); + break; + + case toklk_species: + output_msg("LK_SPECIES"); + break; + + case toklk_named: + output_msg("LK_NAMED"); + break; + + case toklk_phase: + output_msg("LK_PHASE"); + break; + + case toksum_species: + output_msg("SUM_SPECIES"); + break; + + case toksum_gas: + output_msg("SUM_GAS"); + break; + + case toksum_s_s: + output_msg("SUM_s_s"); + break; + + case tokcalc_value: + output_msg("CALC_VALUE"); + break; + + case tokdescription: + output_msg("DESCRIPTION"); + break; + + case toksys: + output_msg("SYS"); + break; + + case tokinstr: + output_msg("INSTR"); + break; + + case tokltrim: + output_msg("LTRIM"); + break; + + case tokrtrim: + output_msg("RTRIM"); + break; + + case toktrim: + output_msg("TRIM"); + break; + + case tokpad: + output_msg("PAD"); + break; + + case tokrxn: + output_msg("RXN"); + break; + + case tokdist: + output_msg("DIST"); + break; + + case tokmisc1: + output_msg("MISC1"); + break; + + case tokmisc2: + output_msg("MISC2"); + break; + + case tokedl: + output_msg("EDL"); + break; + + case toksurf: + output_msg("SURF"); + break; + + case tokstep_no: + output_msg("STEP_NO"); + break; + + case toksim_no: + output_msg("SIM_NO"); + break; + + case toktotal_time: + output_msg("TOTAL_TIME"); + break; + + case tokput: + output_msg("PUT"); + break; + + case tokget: + output_msg("GET"); + break; + + case tokcharge_balance: + output_msg("CHARGE_BALANCE"); + break; + + case tokpercent_error: + output_msg("PERCENT_ERROR"); + break; + +#if defined PHREEQ98 || defined MULTICHART + case tokgraph_x: + output_msg("GRAPH_X"); + break; + + case tokgraph_y: + output_msg("GRAPH_Y"); + break; + + case tokgraph_sy: + output_msg("GRAPH_SY"); + break; +#endif + +#if defined MULTICHART + case tokplot_xy: + output_msg("PLOT_XY"); + break; +#endif + + case tokcell_no: + output_msg("CELL_NO"); + break; + + case tokexists: + output_msg("EXISTS"); + break; + + case toksc: + output_msg("SC"); + break; + + case tokgamma: + output_msg("GAMMA"); + break; + + case toklg: + output_msg("LG"); + break; + +/* VP: Density Start */ + case tokrho: + output_msg("RHO"); + break; +/* VP: Density End */ + case tokcell_volume: + output_msg("CELL_VOLUME"); + break; + case tokcell_pore_volume: + output_msg("CELL_PORE_VOLUME"); + break; + case tokcell_porosity: + output_msg("CELL_POROSITY"); + break; + case tokcell_saturation: + output_msg("CELL_SATURATION"); + break; + case tokiso: + output_msg("ISO"); + break; + case tokiso_unit: + output_msg("ISO_UNIT"); + break; + case tokphase_formula: + output_msg("PHASE_FORMULA"); + break; + case toklist_s_s: + output_msg("LIST_S_S"); + break; + case tokpr_p: + output_msg("PR_P"); + break; + case tokpr_phi: + output_msg("PR_PHI"); + break; + case tokgas_p: + output_msg("GAS_P"); + break; + case tokgas_vm: + output_msg("GAS_VM"); + break; + } + l_buf = l_buf->next; + } +} + + + + void PBasic:: +disposetokens(tokenrec ** tok) +{ + tokenrec *tok1; + + while (*tok != NULL) + { + tok1 = (*tok)->next; + if ((*tok)->kind == (long) tokrem || (*tok)->kind == (long) tokstr) + { + (*tok)->UU.sp = (char *) PhreeqcPtr->free_check_null((*tok)->UU.sp); + } + *tok = (tokenrec *) PhreeqcPtr->free_check_null(*tok); + *tok = tok1; + } +} + + + + void PBasic:: +parseinput(tokenrec ** l_buf) +{ + linerec *l, *l0, *l1; + + while (PhreeqcPtr->replace("\t", " ", inbuf)); + while (PhreeqcPtr->replace("\r", " ", inbuf)); + PhreeqcPtr->string_trim(inbuf); + curline = 0; + while (*inbuf != '\0' && isdigit((int) inbuf[0])) + { + curline = curline * 10 + inbuf[0] - 48; + memmove(inbuf, inbuf + 1, strlen(inbuf)); + } + parse(inbuf, l_buf); + if (curline == 0) + return; + l = linebase; + l0 = NULL; + while (l != NULL && l->num < curline) + { + l0 = l; + l = l->next; + } + if (l != NULL && l->num == curline) + { + l1 = l; + l = l->next; + if (l0 == NULL) + linebase = l; + else + l0->next = l; + disposetokens(&l1->txt); + PhreeqcPtr->PHRQ_free(l1); + } + if (*l_buf != NULL) + { + l1 = (linerec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(linerec)); + if (l1 == NULL) + PhreeqcPtr->malloc_error(); + l1->next = l; + if (l0 == NULL) + linebase = l1; + else + l0->next = l1; + l1->num = curline; + l1->txt = *l_buf; + strncpy(l1->inbuf, inbuf, MAX_LINE); + l1->inbuf[MAX_LINE-1] = '\0'; + } + clearloops(); + restoredata(); +} + + void PBasic:: +errormsg(const char * l_s) +{ + error_msg(l_s, CONTINUE); + _Escape(42); +} + + + void PBasic:: +snerr(const char * l_s) +{ + char str[MAX_LENGTH] = {0}; + strcpy(str, "Syntax_error "); + errormsg(strcat(str, l_s)); +} + + + void PBasic:: +tmerr(const char * l_s) +{ + char str[MAX_LENGTH] = {0}; + strcpy(str, "Type mismatch error"); + errormsg(strcat(str, l_s)); +} + + + void PBasic:: +badsubscr(void) +{ + errormsg("Bad subscript"); +} + + + LDBLE PBasic:: +realfactor(struct LOC_exec *LINK) +{ + valrec n; + + n = factor(LINK); + if (n.stringval) + tmerr(": found characters, not a number"); + return (n.UU.val); +} + + char * PBasic:: +strfactor(struct LOC_exec * LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + return (n.UU.sval); +} + + char * PBasic:: +stringfactor(char * Result, struct LOC_exec * LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + strcpy(Result, n.UU.sval); + PhreeqcPtr->PHRQ_free(n.UU.sval); + return Result; +} + + long PBasic:: +intfactor(struct LOC_exec *LINK) +{ + return ((long) floor(realfactor(LINK) + 0.5)); +} + + LDBLE PBasic:: +realexpr(struct LOC_exec *LINK) +{ + valrec n; + + n = expr(LINK); + if (n.stringval) + tmerr(": found characters, not a number"); + return (n.UU.val); +} + + char * PBasic:: +strexpr(struct LOC_exec * LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + return (n.UU.sval); +} + + char * PBasic:: +stringexpr(char * Result, struct LOC_exec * LINK) +{ + valrec n; + + n = expr(LINK); + if (!n.stringval) + tmerr(": chemical name is not enclosed in \" \"" ); + strcpy(Result, n.UU.sval); + PhreeqcPtr->PHRQ_free(n.UU.sval); + return Result; +} + + long PBasic:: +intexpr(struct LOC_exec *LINK) +{ + return ((long) floor(realexpr(LINK) + 0.5)); +} + + + void PBasic:: +require(int k, struct LOC_exec *LINK) +{ + char str[MAX_LENGTH] = {0}; + int i; + if (LINK->t == NULL || LINK->t->kind != k) + { + for (i = 0; i < NCMDS; i++) + { + if (command[i].keycount == k) + break; + } + if (i == NCMDS) + snerr(": missing unknown command"); + else { + strcpy(str, ": missing "); + snerr(strcat(str, command[i].name)); + } + } + LINK->t = LINK->t->next; +} + + + void PBasic:: +skipparen(struct LOC_exec *LINK) +{ + do + { + if (LINK->t == NULL) + snerr(": parenthesis missing"); + if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) + goto _L1; + if (LINK->t->kind == toklp) + { + LINK->t = LINK->t->next; + skipparen(LINK); + } + LINK->t = LINK->t->next; + } + while (true); + _L1:; +} + + +PBasic::varrec * PBasic:: +findvar(struct LOC_exec *LINK) +{ + PBasic::varrec *v; + long i, j, k; + tokenrec *tok; + long FORLIM; + + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(": can't find variable"); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != toklp) + { + if (v->numdims != 0) + badsubscr(); + return v; + } + if (v->numdims == 0) + { + tok = LINK->t; + i = 0; + j = 1; + do + { + if (i >= maxdims) + badsubscr(); + LINK->t = LINK->t->next; + skipparen(LINK); + j *= 11; + i++; + v->dims[i - 1] = 11; + } + while (LINK->t->kind != tokrp); + v->numdims = (char) i; + if (v->stringvar) + { + v->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + for (k = 0; k < j; k++) + v->UU.U1.sarr[k] = NULL; + } + else + { + v->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc(j * sizeof(LDBLE)); + if (v->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + for (k = 0; k < j; k++) + v->UU.U0.arr[k] = 0.0; + } + LINK->t = tok; + } + k = 0; + LINK->t = LINK->t->next; + FORLIM = v->numdims; + for (i = 1; i <= FORLIM; i++) + { + j = intexpr(LINK); + if ((unsigned long) j >= (unsigned long) v->dims[i - 1]) + badsubscr(); + k = k * v->dims[i - 1] + j; + if (i < v->numdims) + require(tokcomma, LINK); + } + require(tokrp, LINK); + if (v->stringvar) + v->UU.U1.sval = &v->UU.U1.sarr[k]; + else + v->UU.U0.val = &v->UU.U0.arr[k]; + return v; +} + + +PBasic::valrec PBasic:: +factor(struct LOC_exec * LINK) +{ + char string[MAX_LENGTH] = {0}; + struct solution *soln_ptr; + int nn; + varrec *v; + tokenrec *facttok; + valrec n; + long i, j, m; + tokenrec *tok, *tok1; + char *l_s; + LDBLE l_dummy; + int i_rate; + union + { + long i; + char *c; + } trick; + struct save_values s_v, *s_v_ptr; + int k; + LDBLE TEMP; + char STR1[256] = {0}, STR2[256] = {0}; + char *elt_name, *surface_name, *mytemplate, *name; + varrec *count_varrec = NULL, *names_varrec = NULL, *types_varrec = + NULL, *moles_varrec = NULL; + char **names_arg, **types_arg; + LDBLE *moles_arg; + int arg_num; + LDBLE count_species; + char *ptr, *string1, *string2; + + if (LINK->t == NULL) + snerr(": missing variable or command"); + facttok = LINK->t; + LINK->t = LINK->t->next; + n.stringval = false; + s_v.count_subscripts = 0; + /*s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc (sizeof (int)); */ + s_v.subscripts = NULL; + switch (facttok->kind) + { + + case toknum: + n.UU.val = facttok->UU.num; + break; + + case tokstr: + n.stringval = true; + m = (int) strlen(facttok->UU.sp) + 1; + if (m < 256) + m = 256; + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, facttok->UU.sp); + break; + + case tokvar: + LINK->t = facttok; + v = findvar(LINK); + n.stringval = v->stringvar; + if (n.stringval) + { + if (*v->UU.U1.sval != NULL) + { + m = (int) strlen(*v->UU.U1.sval) + 1; + if (m < 256) + m = 256; + } + else + { + m = 256; + } + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + if (*v->UU.U1.sval != NULL) + { + strcpy(n.UU.sval, *v->UU.U1.sval); + } + + } + else + n.UU.val = *v->UU.U0.val; + break; + + case toklp: + n = expr(LINK); + require(tokrp, LINK); + break; + + case tokminus: + n.UU.val = -realfactor(LINK); + break; + + case tokplus: + n.UU.val = realfactor(LINK); + break; + + case toknot: + n.UU.val = ~intfactor(LINK); + break; + + case toksqr: + TEMP = realfactor(LINK); + n.UU.val = TEMP * TEMP; + break; + + case toksqrt: + n.UU.val = sqrt(realfactor(LINK)); + break; + + case tokceil: + n.UU.val = ceil(realfactor(LINK)); + break; + + case tokfloor: + n.UU.val = floor(realfactor(LINK)); + break; + + case toktc: + n.UU.val = PhreeqcPtr->tc_x; + break; + + case toktk: + n.UU.val = PhreeqcPtr->tc_x + 273.15; + break; + + case toktime: + n.UU.val = PhreeqcPtr->rate_time; + break; + + case toksim_time: + if (PhreeqcPtr->use.kinetics_in == FALSE) + { + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->rate_sim_time; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->transport_step * PhreeqcPtr->timest; + } + else if (PhreeqcPtr->state == ADVECTION) + { + if (PhreeqcPtr->advection_kin_time_defined == TRUE) + { + n.UU.val = PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; + } + else + { + n.UU.val = PhreeqcPtr->advection_step; + } + } + else + { + n.UU.val = 0; + } + } + else + { + n.UU.val = PhreeqcPtr->rate_sim_time; + } + break; + + case toktotal_time: + if (PhreeqcPtr->use.kinetics_in == FALSE) + { + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->rate_sim_time_end; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->transport_step * PhreeqcPtr->timest; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = + PhreeqcPtr->initial_total_time + PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; + } + else + { + n.UU.val = 0; + } + } + else + { + n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->rate_sim_time; + } + break; + + case tokm0: + n.UU.val = PhreeqcPtr->rate_m0; + break; + + case tokm: + n.UU.val = PhreeqcPtr->rate_m; + break; + + case tokparm: + i_rate = intfactor(LINK); + if (i_rate > PhreeqcPtr->count_rate_p || i_rate == 0) + { + errormsg("Parameter subscript out of range."); + } + n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; + break; + + case tokact: + n.UU.val = PhreeqcPtr->activity(stringfactor(STR1, LINK)); + break; + + case tokgamma: + n.UU.val = PhreeqcPtr->activity_coefficient(stringfactor(STR1, LINK)); + break; + + case toklg: + n.UU.val = PhreeqcPtr->log_activity_coefficient(stringfactor(STR1, LINK)); + break; + + case tokget_por: + i = intfactor(LINK); + if (PhreeqcPtr->phast != TRUE) + { + if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 + || i == PhreeqcPtr->count_cells + 1) + { + /* warning_msg("Note... no porosity for boundary solutions."); */ + n.UU.val = 0; + break; + } + else + n.UU.val = PhreeqcPtr->cell_data[i - 1].por; + break; + } + else + { + n.UU.val = PhreeqcPtr->cell_porosity; + break; + } + + case tokedl: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } + else + { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->diff_layer_total(elt_name, surface_name); + break; + + case toksurf: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + surface_name = stringfactor(STR2, LINK); + } + else + { + surface_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->surf_total(elt_name, surface_name); + break; + + case tokequi: + n.UU.val = PhreeqcPtr->equi_phase(stringfactor(STR1, LINK)); + break; + + case tokkin: + n.UU.val = PhreeqcPtr->kinetics_moles(stringfactor(STR1, LINK)); + break; + + case tokgas: + n.UU.val = PhreeqcPtr->find_gas_comp(stringfactor(STR1, LINK)); + break; + + case toks_s: + n.UU.val = PhreeqcPtr->find_s_s_comp(stringfactor(STR1, LINK)); + break; + + case tokmisc1: + n.UU.val = PhreeqcPtr->find_misc1(stringfactor(STR1, LINK)); + break; + + case tokmisc2: + n.UU.val = PhreeqcPtr->find_misc2(stringfactor(STR1, LINK)); + break; + + case tokmu: + n.UU.val = PhreeqcPtr->mu_x; + break; + + case tokosmotic: + if (PhreeqcPtr->pitzer_model == TRUE || PhreeqcPtr->sit_model == TRUE) + { + n.UU.val = PhreeqcPtr->COSMOT; + } + else + { + n.UU.val = 0.0; + } + break; + + case tokalk: + n.UU.val = PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; + break; + + case toklk_species: + n.UU.val = PhreeqcPtr->calc_logk_s(stringfactor(STR1, LINK)); + break; + + case toklk_named: + n.UU.val = PhreeqcPtr->calc_logk_n(stringfactor(STR1, LINK)); + break; + + case toklk_phase: + n.UU.val = PhreeqcPtr->calc_logk_p(stringfactor(STR1, LINK)); + break; + + case toksum_species: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_species(mytemplate, elt_name); + break; + + case toksum_gas: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_gases(mytemplate, elt_name); + break; + + case toksum_s_s: + require(toklp, LINK); + mytemplate = stringfactor(STR1, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + elt_name = stringfactor(STR2, LINK); + } + else + { + elt_name = NULL; + } + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); + break; + + case tokcalc_value: + require(toklp, LINK); + name = stringfactor(STR1, LINK); + require(tokrp, LINK); + n.UU.val = PhreeqcPtr->get_calculate_value(name); + break; + + case tokdescription: + n.stringval = true; + if (PhreeqcPtr->state == REACTION) + { + if (PhreeqcPtr->use.mix_in == TRUE) + { + sprintf(string, "Mix %d", PhreeqcPtr->use.n_mix_user); + n.UU.sval = PhreeqcPtr->string_duplicate(string); + } + else + { + soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.n_solution_user, &nn, TRUE); + if (soln_ptr != NULL) + { + n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->description); + } + else + { + n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); + } + } + } + else if (PhreeqcPtr->state == ADVECTION || PhreeqcPtr->state == TRANSPORT || PhreeqcPtr->state == PHAST) + { + sprintf(string, "Cell %d", PhreeqcPtr->cell_no); + n.UU.sval = PhreeqcPtr->string_duplicate(string); + } + else + { + if (PhreeqcPtr->use.solution_ptr != NULL) + { + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.solution_ptr->description); + } + else + { + n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); + } + } + while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); + break; + + case tokinstr: + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + string2 = stringfactor(STR2, LINK); + require(tokrp, LINK); + ptr = strstr(string1, string2); + if (ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = ((LDBLE) (ptr - string1)) + 1; + } + break; + + case tokltrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim_left(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case tokrtrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim_right(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case toktrim: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(string1); + break; + + case tokiso: + n.UU.val = PhreeqcPtr->iso_value(stringfactor(STR1, LINK)); + break; + + case tokiso_unit: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokrp, LINK); + PhreeqcPtr->string_trim(string1); + n.UU.sval = PhreeqcPtr->iso_unit(string1); + break; + + case tokpad: + n.stringval = true; + require(toklp, LINK); + string1 = stringfactor(STR1, LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + require(tokrp, LINK); + n.UU.sval = PhreeqcPtr->string_pad(string1, i); + break; + + case toksys: + require(toklp, LINK); + elt_name = stringfactor(STR1, LINK); + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": can't find variable"); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) + snerr(": can't find name of species"); + + /* return number of types of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + types_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || types_varrec->stringvar != 1) + snerr(": can't find type of species"); + + /* return number of moles of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) + snerr(": can't find moles of species"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(names_varrec); + free_dim_stringvar(types_varrec); + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + /* + n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); + */ + n.UU.val = + PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), + &(types_arg), &(moles_arg)); + + /* + * fill in varrec structure + */ + if (arg_num > 1) + { + *count_varrec->UU.U0.val = count_species; + names_varrec->UU.U1.sarr = names_arg; + types_varrec->UU.U1.sarr = types_arg; + moles_varrec->UU.U0.arr = moles_arg; + + for (i = 0; i < maxdims; i++) + { + names_varrec->dims[i] = 0; + types_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + types_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + names_varrec->numdims = 1; + types_varrec->numdims = 1; + moles_varrec->numdims = 1; + } + else + { + for (i = 0; i < count_species + 1; i++) + { + PhreeqcPtr->free_check_null(names_arg[i]); + PhreeqcPtr->free_check_null(types_arg[i]); + } + PhreeqcPtr->free_check_null(names_arg); + PhreeqcPtr->free_check_null(types_arg); + PhreeqcPtr->free_check_null(moles_arg); + } + break; + + case toklist_s_s: + { + /* list_s_s("calcite", count, name$, moles) */ + /* return total moles */ + require(toklp, LINK); + std::string s_s_name(stringfactor(STR1, LINK)); + cxxNameDouble composition; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of components */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) + snerr(": Cannot find component string variable"); + + /* return number of moles of components */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) + snerr(": Cannot find moles of component variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + snerr(": Expected 4 arguments for list_s_s"); + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(names_varrec); + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + // return total moles + n.UU.val = PhreeqcPtr->list_s_s(s_s_name, composition); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = composition.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + names_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (names_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + moles_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (moles_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + names_varrec->UU.U1.sarr[0] = NULL; + moles_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + names_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + names_varrec->dims[0] = (long) (count + 1); + moles_varrec->dims[0] = (long) (count + 1); + names_varrec->numdims = 1; + moles_varrec->numdims = 1; + + // fill in arrays + i = 1; + + //for (cxxNameDouble::iterator it = composition.begin(); it != composition.end(); it++) + //{ + // names_varrec->UU.U1.sarr[i] = string_duplicate((it->first).c_str()); + // moles_varrec->UU.U0.arr[i] = it->second; + // i++; + //} + + std::vector< std::pair > sort_comp = composition.sort_second(); + size_t j; + for (j = 0; j != sort_comp.size(); j++) + { + names_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate(sort_comp[j].first.c_str()); + moles_varrec->UU.U0.arr[i] = sort_comp[j].second; + i++; + } + + } + break; + } + + case tokphase_formula: + { + require(toklp, LINK); + std::string phase_name(stringfactor(STR1, LINK)); + varrec *elts_varrec = NULL, *coef_varrec = NULL; + cxxNameDouble stoichiometry; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /* phase_formula("calcite", count, elt, coef) */ + /* return formula */ + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* struct varrec *count_varrec, *elt_varrec, *coef_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + std::string form = PhreeqcPtr->phase_formula(phase_name, stoichiometry); + + // put formula as return value + n.stringval = true; + n.UU.sval = PhreeqcPtr->string_duplicate(form.c_str()); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + + } + break; + } + + case tokrxn: + if (PhreeqcPtr->state == REACTION || + PhreeqcPtr->state == ADVECTION || + PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->step_x; + } + else + { + n.UU.val = 0.0; + } + break; + + case tokdist: + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = 0; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = (LDBLE) PhreeqcPtr->use.n_solution_user; + } + else + { + n.UU.val = 0; + } + break; + + case tokmol: + n.UU.val = PhreeqcPtr->molality(stringfactor(STR1, LINK)); + break; + + case tokla: + n.UU.val = PhreeqcPtr->log_activity(stringfactor(STR1, LINK)); + break; + + case toklm: + n.UU.val = PhreeqcPtr->log_molality(stringfactor(STR1, LINK)); + break; + + case toksr: + n.UU.val = PhreeqcPtr->saturation_ratio(stringfactor(STR1, LINK)); + break; + + case tokstep_no: + if (PhreeqcPtr->state == PHAST) + { + n.UU.val = 0; + } + else if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->transport_step; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = PhreeqcPtr->advection_step; + } + else if (PhreeqcPtr->state == REACTION) + { + n.UU.val = PhreeqcPtr->reaction_step; + } + else + { + n.UU.val = 0; + } + break; + + case tokcell_no: + if (PhreeqcPtr->state == TRANSPORT) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == PHAST) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == ADVECTION) + { + n.UU.val = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state < REACTION) + { + n.UU.val = PhreeqcPtr->use.solution_ptr->n_user; + } + else + { + if (PhreeqcPtr->use.mix_in == TRUE) + { + n.UU.val = PhreeqcPtr->use.n_mix_user; + } + else + { + n.UU.val = PhreeqcPtr->use.n_solution_user; + } + } + break; + + case toksim_no: + n.UU.val = PhreeqcPtr->simulation; + break; + + case tokget: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) + { + i = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = s_v_ptr->value; + } + break; + + case tokexists: + require(toklp, LINK); + + s_v.count_subscripts = 0; + /* get first subscript */ + if (LINK->t != NULL && LINK->t->kind != tokrp) + { + i = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } + + /* get other subscripts */ + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + if (s_v.subscripts == NULL) + { + s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + } + s_v.subscripts = + (int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + (size_t) (s_v.count_subscripts + + 1) * sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = 1; + } + break; + + case tokcharge_balance: + n.UU.val = PhreeqcPtr->cb_x; + break; + + case tokpercent_error: + n.UU.val = 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; + break; + + case toksi: + PhreeqcPtr->saturation_index(stringfactor(STR1, LINK), &l_dummy, &n.UU.val); + break; + + case toktot: + n.UU.val = PhreeqcPtr->total(stringfactor(STR1, LINK)); + break; + + case toktotmole: + case toktotmol: + case toktotmoles: + n.UU.val = PhreeqcPtr->total_mole(stringfactor(STR1, LINK)); + break; + + case tokcell_pore_volume: + case tokporevolume: + n.UU.val = PhreeqcPtr->cell_pore_volume; + break; + +/* VP : Density Start */ + case tokrho: + n.UU.val = PhreeqcPtr->calc_dens(); + break; +/* VP: Density End */ + case tokcell_volume: + n.UU.val = PhreeqcPtr->cell_volume; + break; + case tokcell_porosity: + n.UU.val = PhreeqcPtr->cell_porosity; + break; + case tokcell_saturation: + n.UU.val = PhreeqcPtr->cell_saturation; + break; + case toksc: + n.UU.val = PhreeqcPtr->calc_SC(); + break; + case tokpr_p: + n.UU.val = PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); + break; + case tokpr_phi: + n.UU.val = PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); + break; + case tokgas_p: + n.UU.val = PhreeqcPtr->find_gas_p(); + break; + case tokgas_vm: + n.UU.val = PhreeqcPtr->find_gas_vm(); + break; + case toklog10: + n.UU.val = log10(realfactor(LINK)); + break; + + case toksin: + n.UU.val = sin(realfactor(LINK)); + break; + + case tokcos: + n.UU.val = cos(realfactor(LINK)); + break; + + case toktan: + n.UU.val = realfactor(LINK); + n.UU.val = sin(n.UU.val) / cos(n.UU.val); + break; + + case tokarctan: + n.UU.val = atan(realfactor(LINK)); + break; + + case toklog: + n.UU.val = log(realfactor(LINK)); + break; + + case tokexp: + n.UU.val = exp(realfactor(LINK)); + break; + + case tokabs: + n.UU.val = fabs(realfactor(LINK)); + break; + + case toksgn: + n.UU.val = realfactor(LINK); + n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); + break; + + case tokstr_: + n.stringval = true; + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + numtostr(n.UU.sval, realfactor(LINK)); + break; + + case tokval: + l_s = strfactor(LINK); + tok1 = LINK->t; + parse(l_s, &LINK->t); + tok = LINK->t; + if (tok == NULL) + n.UU.val = 0.0; + else + n = expr(LINK); + disposetokens(&tok); + LINK->t = tok1; + PhreeqcPtr->PHRQ_free(l_s); + break; + + case tokchr_: + n.stringval = true; + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, " "); + n.UU.sval[0] = (char) intfactor(LINK); + break; + + case tokeol_: + n.stringval = true; + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, "\n"); + break; + + case tokasc: + l_s = strfactor(LINK); + if (*l_s == '\0') + n.UU.val = 0.0; + else + n.UU.val = l_s[0]; + PhreeqcPtr->PHRQ_free(l_s); + break; + + case tokmid_: + n.stringval = true; + require(toklp, LINK); + n.UU.sval = strexpr(LINK); + require(tokcomma, LINK); + i = intexpr(LINK); + if (i < 1) + i = 1; + /*j = 255; */ + j = (int) strlen(n.UU.sval); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + } + if (j > (int) strlen(n.UU.sval) - i + 1) + j = (int) strlen(n.UU.sval) - i + 1; + if (i > (int) strlen(n.UU.sval)) + *n.UU.sval = '\0'; + else + { + if (j + 1 > 256) + { + warning_msg("String too long in factor\n"); +/* + STR1 = (char *) PhreeqcPtr->PHRQ_realloc (STR1, j + 1); + if (STR1 == NULL) + PhreeqcPtr->malloc_error (); +*/ + } + sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); + strcpy(n.UU.sval, STR1); + } + require(tokrp, LINK); + break; + + case toklen: + l_s = strfactor(LINK); + n.UU.val = (double) strlen(l_s); + PhreeqcPtr->PHRQ_free(l_s); + break; + + case tokpeek: +/* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ + trick.i = intfactor(LINK); + n.UU.val = *trick.c; +/* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ + break; + + default: + snerr(": missing \" or ("); + break; + } + s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); + return n; +} + +PBasic::valrec PBasic:: +upexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + + n = factor(LINK); + while (LINK->t != NULL && LINK->t->kind == tokup) + { + if (n.stringval) + tmerr(": not a number before ^"); + LINK->t = LINK->t->next; + n2 = upexpr(LINK); + if (n2.stringval) + tmerr(": not a number after ^"); + if (n.UU.val >= 0) + { + if (n.UU.val > 0) + { + n.UU.val = exp(n2.UU.val * log(n.UU.val)); + } + continue; + } + if (n2.UU.val != (long) n2.UU.val) + { + tmerr(": negative number cannot be raised to a fractional power."); + } + else + { + n.UU.val = exp(n2.UU.val * log(-n.UU.val)); + if (((long) n2.UU.val) & 1) + n.UU.val = -n.UU.val; + } + } + return n; +} + +PBasic::valrec PBasic:: +term(struct LOC_exec * LINK) +{ + valrec n, n2; + int k; + + n = upexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & ((1L << ((long) toktimes)) | + (1L << ((long) tokdiv)) | (1L << + ((long) tokmod)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = PBasic::upexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(": found char, but need a number for * or /"); + if (k == tokmod) + { + /* n.UU.val = (long)floor(n.UU.val + 0.5) % (long)floor(n2.UU.val + 0.5); */ + if (n.UU.val != 0) + { + n.UU.val = + fabs(n.UU.val) / n.UU.val * fmod(fabs(n.UU.val) + + 1e-14, n2.UU.val); + } + else + { + n.UU.val = 0; + } +/* p2c: basic.p, line 1078: + * Note: Using % for possibly-negative arguments [317] */ + } + else if (k == toktimes) + n.UU.val *= n2.UU.val; + else if (n2.UU.val != 0) + { + n.UU.val /= n2.UU.val; + } + else + { + sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + n.UU.val = 0; + } + } + return n; +} + +PBasic::valrec PBasic:: +sexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + int k, m; + + n = term(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokplus)) | (1L << ((long) tokminus)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = term(LINK); + if (n.stringval != n2.stringval) + tmerr(": found char, but need a number for + or - "); + if (k == tokplus) + { + if (n.stringval) + { + m = (int) strlen(n.UU.sval) + (int) strlen(n2.UU.sval) + 1; + if (m < 256) + m = 256; + + n.UU.sval = (char *) PhreeqcPtr->PHRQ_realloc(n.UU.sval, (size_t) m * sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcat(n.UU.sval, n2.UU.sval); + PhreeqcPtr->PHRQ_free(n2.UU.sval); + } + else + n.UU.val += n2.UU.val; + } + else + { + if (n.stringval) + tmerr(": found char, but need a number for - "); + else + n.UU.val -= n2.UU.val; + } + } + return n; +} + +PBasic::valrec PBasic:: +relexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + boolean f; + int k; + + n = sexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokne + 1)) - (1L << ((long) tokeq)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = PBasic::sexpr(LINK); + if (n.stringval != n2.stringval) + tmerr(""); + if (n.stringval) + { + f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokeq)) | + (1L << ((long) tokge)) | (1L << + ((long) tokle)))) + != 0) || (strcmp(n.UU.sval, n2.UU.sval) < 0 + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) toklt)) | + (1L << ((long) tokle)) | (1L << + ((long) + tokne)))) + != 0) + || (strcmp(n.UU.sval, n2.UU.sval) > 0 + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokgt)) | + (1L << ((long) tokge)) | (1L << + ((long) + tokne)))) != + 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+1.00 seconds, 5000 tries on line 1518 [251] */ + PhreeqcPtr->PHRQ_free(n.UU.sval); + PhreeqcPtr->PHRQ_free(n2.UU.sval); + } + else + f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long) k < 32 && + ((1L << ((long) k)) & ((1L << ((long) tokeq)) | + (1L << ((long) tokge)) | + (1L << ((long) tokle)))) != + 0) || (n.UU.val < n2.UU.val + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) toklt)) | + (1L << ((long) tokle)) | (1L << + ((long) + tokne)))) + != 0) || (n.UU.val > n2.UU.val + && (unsigned long) k < 32 + && ((1L << ((long) k)) & + ((1L << ((long) tokgt)) | + (1L << ((long) tokge)) | (1L + << + ((long) tokne)))) != 0)); + /* p2c: basic.p, line 2175: Note: + * Line breaker spent 0.0+2.00 seconds, 5000 tries on line 1532 [251] */ + n.stringval = false; + n.UU.val = f; + } + return n; +} + +PBasic::valrec PBasic:: +andexpr(struct LOC_exec * LINK) +{ + valrec n, n2; + + n = relexpr(LINK); + while (LINK->t != NULL && LINK->t->kind == tokand) + { + LINK->t = LINK->t->next; + n2 = relexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(""); + n.UU.val = ((long) n.UU.val) & ((long) n2.UU.val); + } + return n; +} + +PBasic::valrec PBasic:: +expr(struct LOC_exec * LINK) +{ + valrec n, n2; + int k; + + n = andexpr(LINK); + while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) tokor)) | (1L << ((long) tokxor)))) != 0) + { + k = LINK->t->kind; + LINK->t = LINK->t->next; + n2 = andexpr(LINK); + if (n.stringval || n2.stringval) + tmerr(""); + if (k == tokor) + n.UU.val = ((long) n.UU.val) | ((long) n2.UU.val); + else + n.UU.val = ((long) n.UU.val) ^ ((long) n2.UU.val); + } + return n; +} + + + void PBasic:: +checkextra(struct LOC_exec *LINK) +{ + if (LINK->t != NULL) + errormsg("Extra information on line"); +} + + + boolean PBasic:: +iseos(struct LOC_exec *LINK) +{ + return ((boolean) (LINK->t == NULL || LINK->t->kind == (long) tokelse || + LINK->t->kind == (long) tokcolon)); +} + + + void PBasic:: +skiptoeos(struct LOC_exec *LINK) +{ + while (!iseos(LINK)) + LINK->t = LINK->t->next; +} + + +PBasic::linerec * PBasic:: +findline(long n) +{ + linerec *l; + + l = linebase; + while (l != NULL && l->num != n) + l = l->next; + return l; +} + +PBasic::linerec * PBasic:: +mustfindline(long n) +{ + linerec *l; + + l = findline(n); + if (l == NULL) { + sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); + errormsg(PhreeqcPtr->error_string); + } + return l; +} + + + void PBasic:: +cmdend(struct LOC_exec *LINK) +{ + stmtline = NULL; + LINK->t = NULL; +} + + + void PBasic:: +cmdnew(struct LOC_exec *LINK) +{ + void *p; + int i, k; + + cmdend(LINK); + clearloops(); + restoredata(); + while (linebase != NULL) + { + p = linebase->next; + disposetokens(&linebase->txt); + PhreeqcPtr->PHRQ_free(linebase); + linebase = (linerec *) p; + } + while (varbase != NULL) + { + p = varbase->next; + if (varbase->stringvar) + { + if (varbase->numdims > 0) + { + k = 1; + for (i = 0; i < varbase->numdims; i++) + { + k = k * (varbase->dims[i]); + } + for (i = 0; i < k; i++) + { + PhreeqcPtr->free_check_null(varbase->UU.U1.sarr[i]); + } + PhreeqcPtr->free_check_null(varbase->UU.U1.sarr); + } + else if (*varbase->UU.U1.sval != NULL) + { + *varbase->UU.U1.sval = + (char *) PhreeqcPtr->free_check_null(*varbase->UU.U1.sval); + } + + } + else + { + PhreeqcPtr->free_check_null(varbase->UU.U0.arr); + varbase->UU.U0.arr = NULL; + } + PhreeqcPtr->PHRQ_free(varbase); + varbase = (varrec *) p; + } +} + + + void PBasic:: +cmdlist(struct LOC_exec *LINK) +{ + linerec *l; + long n1, n2; + + do + { + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n1 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) + { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n2 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + } + else + n2 = LONG_MAX; + } + l = linebase; + while (l != NULL && l->num <= n2) + { + if (l->num >= n1) + { + /* printf("%ld ", l->num); */ + /* listtokens(stdout, l->txt); */ + /* putchar('\n'); */ + output_msg(PhreeqcPtr->sformatf("%ld ", l->num)); + listtokens(NULL, l->txt); + output_msg("\n"); + } + l = l->next; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void PBasic:: +cmdload(boolean merging, char * name, struct LOC_exec *LINK) +{ + FILE *f; + tokenrec *l_buf; + char STR1[256] = {0}; + char *TEMP; + + f = NULL; + if (!merging) + cmdnew(LINK); + if (f != NULL) + { + sprintf(STR1, "%s.TEXT", name); + f = freopen(STR1, "r", f); + } + else + { + sprintf(STR1, "%s.TEXT", name); + f = fopen(STR1, "r"); + } + if (f == NULL) + _EscIO(FileNotFound); + while (fgets(inbuf, 256, f) != NULL) + { + TEMP = strchr(inbuf, '\n'); + if (TEMP != NULL) + *TEMP = 0; + parseinput(&l_buf); + if (curline == 0) + { + printf("Bad line in file\n"); + disposetokens(&l_buf); + } + } + if (f != NULL) + fclose(f); + f = NULL; + if (f != NULL) + fclose(f); +} + + + void PBasic:: +cmdrun(struct LOC_exec *LINK) +{ + linerec *l; + long i; + /*string255 s; */ + char *l_s; + + l_s = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); + if (l_s == NULL) + PhreeqcPtr->malloc_error(); + + l = linebase; + if (!iseos(LINK)) + { + if (LINK->t->kind == toknum) + /*l = mustfindline(intexpr(LINK), LINK); */ + l = mustfindline(intexpr(LINK)); + else + { + stringexpr(l_s, LINK); + i = 0; + if (!iseos(LINK)) + { + require(tokcomma, LINK); + i = intexpr(LINK); + } + checkextra(LINK); + cmdload(false, l_s, LINK); + if (i == 0) + l = linebase; + else + l = mustfindline(i); + } + } + stmtline = l; + LINK->gotoflag = true; + clearvars(); + clearloops(); + restoredata(); + PhreeqcPtr->free_check_null(l_s); + return; +} + +/* PhreeqcPtr->replace basic save command with transport of rate back to calc_kinetic_rate */ + void PBasic:: +cmdsave(struct LOC_exec *LINK) +{ + valrec n; + while (!iseos(LINK)) + { + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { + snerr(": in SAVE command"); + } + else + { + PhreeqcPtr->rate_moles = n.UU.val; + } + } +} + void PBasic:: +cmdput(struct LOC_exec *LINK) +{ + int j; + struct save_values s_v; + + s_v.count_subscripts = 0; + s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int)); + + /* get parentheses */ + require(toklp, LINK); + + /* get first argumen */ + s_v.value = realexpr(LINK); + + for (;;) + { + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + j = intexpr(LINK); + s_v.count_subscripts++; + s_v.subscripts = + (int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + (size_t) s_v.count_subscripts * + sizeof(int)); + if (s_v.subscripts == NULL) + PhreeqcPtr->malloc_error(); + s_v.subscripts[s_v.count_subscripts - 1] = j; + } + else + { + /* get right parentheses */ + require(tokrp, LINK); + break; + } + } + + PhreeqcPtr->save_values_store(&s_v); + s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); +} + + void PBasic:: +cmdchange_por(struct LOC_exec *LINK) +{ + int j; + LDBLE TEMP; + require(toklp, LINK); + /* get new porosity */ + TEMP = realexpr(LINK); + require(tokcomma, LINK); + /* get cell_no */ + j = intexpr(LINK); + require(tokrp, LINK); + if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 + && j != PhreeqcPtr->count_cells + 1) + PhreeqcPtr->cell_data[j - 1].por = TEMP; +} + + void PBasic:: +cmdchange_surf(struct LOC_exec *LINK) +{ +/* + change_surf("Hfo", 0.3, "Sfo", 0, 5 ) + (old_name, fraction, new_name, new_Dw, cell_no) + */ + char *c1; + int count; + + PhreeqcPtr->change_surf_count += 1; + count = PhreeqcPtr->change_surf_count; + if (PhreeqcPtr->change_surf[count - 1].next == FALSE) + PhreeqcPtr->change_surf = PhreeqcPtr->change_surf_alloc(count + 1); + + require(toklp, LINK); + /* get surface component name (change affects all comps of the same charge structure) */ + c1 = strexpr(LINK); + PhreeqcPtr->change_surf[count - 1].comp_name = PhreeqcPtr->string_hsave(c1); + PhreeqcPtr->PHRQ_free(c1); + require(tokcomma, LINK); + /* get fraction of comp to change */ + PhreeqcPtr->change_surf[count - 1].fraction = realexpr(LINK); + require(tokcomma, LINK); + /* get new surface component name */ + c1 = strexpr(LINK); + PhreeqcPtr->change_surf[count - 1].new_comp_name = PhreeqcPtr->string_hsave(c1); + PhreeqcPtr->PHRQ_free(c1); + require(tokcomma, LINK); + /* get new Dw (no transport if 0) */ + PhreeqcPtr->change_surf[count - 1].new_Dw = realexpr(LINK); + require(tokcomma, LINK); + /* get cell_no */ + PhreeqcPtr->change_surf[count - 1].cell_no = intexpr(LINK); + require(tokrp, LINK); + + if (PhreeqcPtr->change_surf->cell_no == 0 || PhreeqcPtr->change_surf->cell_no == PhreeqcPtr->count_cells + 1) + PhreeqcPtr->change_surf[count - 1].cell_no = -99; +} + + void PBasic:: +cmdbye(void) +{ + exitflag = true; +} + + void PBasic:: +cmddel(struct LOC_exec *LINK) +{ + linerec *l, *l0, *l1; + long n1, n2; + + do + { + if (iseos(LINK)) + snerr(": no variable name after del"); + n1 = 0; + n2 = LONG_MAX; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n1 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokminus) + n2 = n1; + } + if (LINK->t != NULL && LINK->t->kind == tokminus) + { + LINK->t = LINK->t->next; + if (LINK->t != NULL && LINK->t->kind == toknum) + { + n2 = (long) LINK->t->UU.num; + LINK->t = LINK->t->next; + } + else + n2 = LONG_MAX; + } + l = linebase; + l0 = NULL; + while (l != NULL && l->num <= n2) + { + l1 = l->next; + if (l->num >= n1) + { + if (l == stmtline) + { + cmdend(LINK); + clearloops(); + restoredata(); + } + if (l0 == NULL) + linebase = l->next; + else + l0->next = l->next; + disposetokens(&l->txt); + PhreeqcPtr->PHRQ_free(l); + } + else + l0 = l; + l = l1; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void PBasic:: +cmdrenum(struct LOC_exec *LINK) +{ + linerec *l, *l1; + tokenrec *tok; + long lnum, step; + + lnum = 10; + step = 10; + if (!iseos(LINK)) + { + lnum = intexpr(LINK); + if (!iseos(LINK)) + { + require(tokcomma, LINK); + step = intexpr(LINK); + } + } + l = linebase; + if (l == NULL) + return; + while (l != NULL) + { + l->num2 = lnum; + lnum += step; + l = l->next; + } + l = linebase; + do + { + tok = l->txt; + do + { + if (tok->kind == (long) tokdel || tok->kind == (long) tokrestore + || tok->kind == (long) toklist || tok->kind == (long) tokrun + || tok->kind == (long) tokelse || tok->kind == (long) tokthen + || tok->kind == (long) tokgosub + || tok->kind == (long) tokgoto) + { + while (tok->next != NULL && tok->next->kind == toknum) + { + tok = tok->next; + lnum = (long) floor(tok->UU.num + 0.5); + l1 = linebase; + while (l1 != NULL && l1->num != lnum) + l1 = l1->next; + if (l1 == NULL) + printf("Undefined line %ld in line %ld\n", lnum, + l->num2); + else + tok->UU.num = l1->num2; + if (tok->next != NULL && tok->next->kind == tokcomma) + tok = tok->next; + } + } + tok = tok->next; + } + while (tok != NULL); + l = l->next; + } + while (l != NULL); + l = linebase; + while (l != NULL) + { + l->num = l->num2; + l = l->next; + } +} + + + void PBasic:: +cmdprint(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256] = {0}; + + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + output_msg(PhreeqcPtr->sformatf("%s ", n.UU.sval)); + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else +/* printf("%s ", numtostr(STR1, n.UU.val)); */ + output_msg(PhreeqcPtr->sformatf("%s ", numtostr(STR1, n.UU.val))); + } + if (!semiflag) +/* putchar('\n');*/ + output_msg("\n"); +} + + void PBasic:: +cmdpunch(struct LOC_exec *LINK) +{ + valrec n; + /* char STR1[256]; */ + + while (!iseos(LINK)) + { + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + if (PhreeqcPtr->punch.high_precision == FALSE) + { + if (strlen(n.UU.sval) <= 12) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.12s\t", n.UU.sval); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); + } + } + else + { + if (strlen(n.UU.sval) <= 20) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.20s\t", n.UU.sval); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); + } + } + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else if (PhreeqcPtr->punch.high_precision == FALSE) + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); + } + else + { + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.12e\t", (double) n.UU.val); + } + ++PhreeqcPtr->n_user_punch_index; + } +} + +#if defined PHREEQ98 + void PBasic:: +cmdgraph_x(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "x"); + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "x"); + colnr++; + } +} + + void PBasic:: +cmdgraph_y(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "y"); + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "y"); + colnr++; + } +} + + void PBasic:: +cmdgraph_sy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + char STR1[256]; + semiflag = false; + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + if (colnr == 0) + { + rownr++; + } + if (n.stringval) + { +/* fputs(n.UU.sval, stdout); */ + GridChar(n.UU.sval, "s"); + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + GridChar(numtostr(STR1, n.UU.val), "s"); + colnr++; + } +} +#endif + + void PBasic:: +cmdlet(boolean implied, struct LOC_exec *LINK) +{ + varrec *v; + char *old, *mynew; + LDBLE d_value; + LDBLE *target; + char **starget; + target = NULL; + starget = NULL; + if (implied) + LINK->t = stmttok; + v = findvar(LINK); + if (v->stringvar) + { + starget = v->UU.U1.sval; + } + else + { + target = v->UU.U0.val; + } + require(tokeq, LINK); + if (!v->stringvar) + { + /* in case array is used on right hand side */ + d_value = realexpr(LINK); + v->UU.U0.val = target; + *v->UU.U0.val = d_value; + /* *v->UU.U0.val = realexpr(LINK); */ + return; + } + mynew = strexpr(LINK); + v->UU.U1.sval = starget; + old = *v->UU.U1.sval; + *v->UU.U1.sval = mynew; + if (old != NULL) + PhreeqcPtr->PHRQ_free(old); +} + + + void PBasic:: +cmdgoto(struct LOC_exec *LINK) +{ + stmtline = mustfindline(intexpr(LINK)); + LINK->t = NULL; + LINK->gotoflag = true; +} + + + void PBasic:: +cmdif(struct LOC_exec *LINK) +{ + LDBLE n; + long i; + + n = realexpr(LINK); + require(tokthen, LINK); + if (n == 0) + { + i = 0; + do + { + if (LINK->t != NULL) + { + if (LINK->t->kind == tokif) + i++; + if (LINK->t->kind == tokelse) + i--; + LINK->t = LINK->t->next; + } + } + while (LINK->t != NULL && i >= 0); + } + if (LINK->t != NULL && LINK->t->kind == toknum) + cmdgoto(LINK); + else + LINK->elseflag = true; +} + + + void PBasic:: +cmdelse(struct LOC_exec *LINK) +{ + LINK->t = NULL; +} + + + boolean PBasic:: +skiploop(int up, int dn, struct LOC_exec *LINK) +{ + boolean Result; + long i; + linerec *saveline; + + saveline = stmtline; + i = 0; + do + { + while (LINK->t == NULL) + { + if (stmtline == NULL || stmtline->next == NULL) + { + Result = false; + stmtline = saveline; + goto _L1; + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == up) + i++; + if (LINK->t->kind == dn) + i--; + LINK->t = LINK->t->next; + } + while (i >= 0); + Result = true; + _L1: + return Result; +} + + + void PBasic:: +cmdfor(struct LOC_exec *LINK) +{ + looprec *l, lr; + linerec *saveline; + long i, j; + + lr.UU.U0.vp = findvar(LINK); + if (lr.UU.U0.vp->stringvar) + snerr(": error in FOR command"); + require(tokeq, LINK); + *lr.UU.U0.vp->UU.U0.val = realexpr(LINK); + require(tokto, LINK); + lr.UU.U0.max = realexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokstep) + { + LINK->t = LINK->t->next; + lr.UU.U0.step = realexpr(LINK); + } + else + lr.UU.U0.step = 1.0; + lr.homeline = stmtline; + lr.hometok = LINK->t; + lr.kind = forloop; + lr.next = loopbase; + if ((lr.UU.U0.step >= 0 && *lr.UU.U0.vp->UU.U0.val > lr.UU.U0.max) || + (lr.UU.U0.step <= 0 && *lr.UU.U0.vp->UU.U0.val < lr.UU.U0.max)) + { + saveline = stmtline; + i = 0; + j = 0; + do + { + while (LINK->t == NULL) + { + if (stmtline == NULL || stmtline->next == NULL) + { + stmtline = saveline; + errormsg("FOR without NEXT"); + } + stmtline = stmtline->next; + LINK->t = stmtline->txt; + } + if (LINK->t->kind == tokfor) + { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j++; + else + i++; + } + if (LINK->t->kind == toknext) + { + if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && + LINK->t->next->UU.vp == lr.UU.U0.vp) + j--; + else + i--; + } + LINK->t = LINK->t->next; + } + while (i >= 0 && j >= 0); + skiptoeos(LINK); + return; + } + l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + *l = lr; + loopbase = l; +} + + + void PBasic:: +cmdnext(struct LOC_exec *LINK) +{ + varrec *v; + boolean found; + looprec *l, *WITH; + + if (!iseos(LINK)) + v = findvar(LINK); + else + v = NULL; + do + { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("NEXT without FOR"); + found = (boolean) (loopbase->kind == forloop && + (v == NULL || loopbase->UU.U0.vp == v)); + if (!found) + { + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + WITH = loopbase; + *WITH->UU.U0.vp->UU.U0.val += WITH->UU.U0.step; + if ((WITH->UU.U0.step < 0 + || *WITH->UU.U0.vp->UU.U0.val <= WITH->UU.U0.max) + && (WITH->UU.U0.step > 0 + || *WITH->UU.U0.vp->UU.U0.val >= WITH->UU.U0.max)) + { + stmtline = WITH->homeline; + LINK->t = WITH->hometok; + return; + } + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; +} + + + void PBasic:: +cmdwhile(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = whileloop; + l->homeline = stmtline; + l->hometok = LINK->t; + if (iseos(LINK)) + return; + if (realexpr(LINK) != 0) + return; + if (!skiploop(tokwhile, tokwend, LINK)) + errormsg("WHILE without WEND"); + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + + void PBasic:: +cmdwend(struct LOC_exec *LINK) +{ + tokenrec *tok; + linerec *tokline; + looprec *l; + boolean found; + + do + { + if (loopbase == NULL || loopbase->kind == gosubloop) + errormsg("WEND without WHILE"); + found = (boolean) (loopbase->kind == whileloop); + if (!found) + { + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + if (!iseos(LINK)) + { + if (realexpr(LINK) != 0) + found = false; + } + tok = LINK->t; + tokline = stmtline; + if (found) + { + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + if (!iseos(LINK)) + { + if (realexpr(LINK) == 0) + found = false; + } + } + if (found) + return; + LINK->t = tok; + stmtline = tokline; + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; +} + + + void PBasic:: +cmdgosub(struct LOC_exec *LINK) +{ + looprec *l; + + l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + cmdgoto(LINK); +} + + + void PBasic:: +cmdreturn(struct LOC_exec *LINK) +{ + looprec *l; + boolean found; + + do + { + if (loopbase == NULL) + errormsg("RETURN without GOSUB"); + found = (boolean) (loopbase->kind == gosubloop); + if (!found) + { + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + } + } + while (!found); + stmtline = loopbase->homeline; + LINK->t = loopbase->hometok; + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); +} + + + void PBasic:: +cmdread(struct LOC_exec *LINK) +{ + varrec *v; + tokenrec *tok; + boolean found; + + do + { + v = findvar(LINK); + tok = LINK->t; + LINK->t = datatok; + if (dataline == NULL) + { + dataline = linebase; + LINK->t = dataline->txt; + } + if (LINK->t == NULL || LINK->t->kind != tokcomma) + { + do + { + while (LINK->t == NULL) + { + if (dataline == NULL || dataline->next == NULL) + errormsg("Out of Data"); + dataline = dataline->next; + LINK->t = dataline->txt; + } + found = (boolean) (LINK->t->kind == tokdata); + LINK->t = LINK->t->next; + } + while (!found || iseos(LINK)); + } + else + LINK->t = LINK->t->next; + if (v->stringvar) + { + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = strexpr(LINK); + } + else + *v->UU.U0.val = realexpr(LINK); + datatok = LINK->t; + LINK->t = tok; + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + + void PBasic:: +cmddata(struct LOC_exec *LINK) +{ + skiptoeos(LINK); +} + + + void PBasic:: +cmdrestore(struct LOC_exec *LINK) +{ + if (iseos(LINK)) + restoredata(); + else + { + dataline = mustfindline(intexpr(LINK)); + datatok = dataline->txt; + } +} + + + void PBasic:: +cmdgotoxy(struct LOC_exec *LINK) +{ + intexpr(LINK); + require(tokcomma, LINK); +} + + + void PBasic:: +cmdon(struct LOC_exec *LINK) +{ + long i; + looprec *l; + + i = intexpr(LINK); + if (LINK->t != NULL && LINK->t->kind == tokgosub) + { + l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); + if (l == NULL) + PhreeqcPtr->malloc_error(); + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + LINK->t = LINK->t->next; + } + else + require(tokgoto, LINK); + if (i < 1) + { + skiptoeos(LINK); + return; + } + while (i > 1 && !iseos(LINK)) + { + require(toknum, LINK); + if (!iseos(LINK)) + require(tokcomma, LINK); + i--; + } + if (!iseos(LINK)) + cmdgoto(LINK); +} + + + void PBasic:: +cmddim(struct LOC_exec *LINK) +{ + long i, j, k; + varrec *v; + boolean done; + + do + { + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(": error in DIM command"); + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (v->numdims != 0) + errormsg("Array already dimensioned before"); + j = 1; + i = 0; + require(toklp, LINK); + do + { + k = intexpr(LINK) + 1; + if (k < 1) + badsubscr(); + if (i >= maxdims) + badsubscr(); + i++; + v->dims[i - 1] = k; + j *= k; + done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); + if (!done) + require(tokcomma, LINK); + } + while (!done); + LINK->t = LINK->t->next; + v->numdims = (char) i; + if (v->stringvar) + { + v->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc(j * sizeof(char *)); + if (v->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + for (i = 0; i < j; i++) + v->UU.U1.sarr[i] = NULL; + } + else + { + v->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc(j * sizeof(LDBLE)); + if (v->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + for (i = 0; i < j; i++) + v->UU.U0.arr[i] = 0.0; + } + if (!iseos(LINK)) + require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + void PBasic:: +cmdpoke(struct LOC_exec *LINK) +{ + union + { + long i; + char *c; + } trick; + +/* p2c: basic.p, line 2073: Note: Range checking is OFF [216] */ + trick.i = intexpr(LINK); + require(tokcomma, LINK); + *trick.c = (char) intexpr(LINK); +/* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ +} + + void PBasic:: +exec(void) +{ + struct LOC_exec V; + char *ioerrmsg; + char STR1[256] = {0}; + + + TRY(try1); + do + { + do + { + V.gotoflag = false; + V.elseflag = false; + while (stmttok != NULL && stmttok->kind == tokcolon) + stmttok = stmttok->next; + V.t = stmttok; + if (V.t != NULL) + { + V.t = V.t->next; + switch (stmttok->kind) + { + + case tokrem: + /* blank case */ + break; + + case toklist: + cmdlist(&V); + break; + + case tokrun: + cmdrun(&V); + break; + + case toknew: + cmdnew(&V); + break; + + case tokload: + cmdload(false, stringexpr(STR1, &V), &V); + break; + + case tokmerge: + cmdload(true, stringexpr(STR1, &V), &V); + break; + + case toksave: + cmdsave(&V); + break; + + case tokbye: + cmdbye(); + break; + + case tokdel: + cmddel(&V); + break; + + case tokrenum: + cmdrenum(&V); + break; + + case toklet: + cmdlet(false, &V); + break; + + case tokvar: + cmdlet(true, &V); + break; + + case tokprint: + cmdprint(&V); + break; + + case tokpunch: + cmdpunch(&V); + break; + + case tokput: + cmdput(&V); + break; + + case tokchange_por: + cmdchange_por(&V); + break; + + case tokchange_surf: + cmdchange_surf(&V); + break; + +#if defined PHREEQ98 || defined MULTICHART + case tokgraph_x: + cmdgraph_x(&V); + break; + + case tokgraph_y: + cmdgraph_y(&V); + break; + + case tokgraph_sy: + cmdgraph_sy(&V); + break; +#endif +#if defined MULTICHART + case tokplot_xy: + cmdplot_xy(&V); + break; +#endif + + case tokinput: + error_msg + ("Basic command INPUT is not a legal command in PHREEQC.", + STOP); + break; + + case tokgoto: + cmdgoto(&V); + break; + + case tokif: + cmdif(&V); + break; + + case tokelse: + cmdelse(&V); + break; + + case tokend: + cmdend(&V); + break; + + case tokstop: + P_escapecode = -20; + goto _Ltry1; + + case tokfor: + cmdfor(&V); + break; + + case toknext: + cmdnext(&V); + break; + + case tokwhile: + cmdwhile(&V); + break; + + case tokwend: + cmdwend(&V); + break; + + case tokgosub: + cmdgosub(&V); + break; + + case tokreturn: + cmdreturn(&V); + break; + + case tokread: + cmdread(&V); + break; + + case tokdata: + cmddata(&V); + break; + + case tokrestore: + cmdrestore(&V); + break; + + case tokgotoxy: + cmdgotoxy(&V); + break; + + case tokon: + cmdon(&V); + break; + + case tokdim: + cmddim(&V); + break; + + case tokpoke: + cmdpoke(&V); + break; + + default: + errormsg("Illegal command"); + break; + } + } + if (!V.elseflag && !iseos(&V)) + checkextra(&V); + stmttok = V.t; + } + while (V.t != NULL); + if (stmtline != NULL) + { + if (!V.gotoflag) + stmtline = stmtline->next; + if (stmtline != NULL) + stmttok = stmtline->txt; + } + } + while (stmtline != NULL); + RECOVER2(try1, _Ltry1); + if (P_escapecode == -20) + warning_msg("Break"); + /* printf("Break"); */ + else if (P_escapecode != 42) + { + switch (P_escapecode) + { + + case -4: + sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -5: + sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -6: + sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -7: + sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -8: + case -19: + case -18: + case -17: + case -16: + case -15: + sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -10: + ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + if (ioerrmsg == NULL) + PhreeqcPtr->malloc_error(); + sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); + warning_msg(ioerrmsg); + PhreeqcPtr->PHRQ_free(ioerrmsg); + break; + + default: + if (EXCP_LINE != -1) + { + sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); + warning_msg(PhreeqcPtr->error_string); + } + _Escape(P_escapecode); + break; + } + } + if (stmtline != NULL) + { + sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + error_msg(PhreeqcPtr->error_string, CONTINUE); + } + ENDTRY(try1); +} /*exec */ +int PBasic:: +free_dim_stringvar(varrec *l_varbase) +{ + int i, k; + if (l_varbase->numdims > 0) + { + k = 1; + for (i = 0; i < l_varbase->numdims; i++) + { + k = k * (l_varbase->dims[i]); + } + for (i = 0; i < k; i++) + { + PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr[i]); + } + l_varbase->UU.U1.sarr = (char **) PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr); + } + return (OK); +} +#if defined MULTICHART + void PBasic:: +cmdplot_xy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n[2]; + char STR[2][256]; + int i = 0; + semiflag = false; + + while (!iseos(LINK) && i < 2) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + i++; + continue; + } + n[i] = expr(LINK); + if (n[i].stringval) + { + strcpy(STR[i], n[i].UU.sval); + PhreeqcPtr->PHRQ_free(n[i].UU.sval); + } + else + numtostr(STR[i], n[i].UU.val); + } + + ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); + if (chart == NULL) return; + + std::string x_str(STR[0]), y_str(STR[1]); + +// Code formerly in PlotXY, included here + { + + bool new_sim = false, new_trans = false; + + if (chart->Get_FirstCallToUSER_GRAPH() && chart->Get_colnr() == 0) + chart->Set_prev_sim_no(PhreeqcPtr->simulation); + else + chart->Set_prev_sim_no(PhreeqcPtr->simulation); + + // Add a curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + std::string head(""); + if (chart->Get_new_headings().size() > 0) + { + head = chart->Get_new_headings()[0]; + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + if (chart->Get_new_plotxy_curves().size() > 0) + { + // find plotxy curve definitions + chart->Add_curve(true, head, + chart->Get_new_plotxy_curves()[0].Get_line_w(), + chart->Get_new_plotxy_curves()[0].Get_symbol(), + chart->Get_new_plotxy_curves()[0].Get_symbol_size(), + chart->Get_new_plotxy_curves()[0].Get_y_axis(), + chart->Get_new_plotxy_curves()[0].Get_color() + ); + // pop plotxy curve definition + chart->Get_new_plotxy_curves().erase(chart->Get_new_plotxy_curves().begin()); + } + else + { + chart->Add_curve(true, head); + } + chart->Set_curve_added(true); + } + + if (x_str.size() > 0 && y_str.size() > 0) + { + chart->Get_Curves()[chart->Get_colnr()]->Get_x().push_back(atof(x_str.c_str())); + chart->Get_Curves()[chart->Get_colnr()]->Get_y().push_back(atof(y_str.c_str())); + chart->Set_point_added(true); + + // Mark added curve for first point, might have been invisible in DefineCurves + if (chart->Get_Curves()[chart->Get_colnr()]->Get_x().size() == 1) + chart->Set_curve_added(true); + } + } + chart->Set_colnr(chart->Get_colnr() + 1); +} + void PBasic:: +cmdgraph_x(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Set_graph_x(atof(n.UU.sval)); + } + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + chart->Set_graph_x(n.UU.val); + } + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + if (chart->Get_new_headings().size() > 0) + { + // remove x heading + //if (chart->Get_colnr() == chart->Get_ColumnOffset()) + { + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + } + } +} + + void PBasic:: +cmdgraph_y(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + // wait until x value is known before storing in curve + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); + } + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + { + chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; + } + chart->Set_point_added(true); + + // Add a new curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + //if (chart->Get_new_headings().size() > 0) + //{ + // // remove x heading + // if (chart->Get_colnr() == chart->Get_ColumnOffset()) + // { + // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + // } + //} + if (chart->Get_new_headings().size() > 0) + { + chart->Add_curve(false, chart->Get_new_headings()[0]); + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + else + { + chart->Add_curve(false); + } + chart->Set_curve_added(true); + } + chart->Set_colnr(chart->Get_colnr() + 1); + } +} + + void PBasic:: +cmdgraph_sy(struct LOC_exec *LINK) +{ + boolean semiflag; + valrec n; + semiflag = false; + + ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); + if (chart == NULL) return; + + while (!iseos(LINK)) + { + semiflag = false; + if ((unsigned long) LINK->t->kind < 32 && + ((1L << ((long) LINK->t->kind)) & + ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) + { + semiflag = true; + LINK->t = LINK->t->next; + continue; + } + n = expr(LINK); + + chart->Get_secondary_y()[chart->Get_colnr()] = true; + + // wait until x value is known before storing in curve + if (n.stringval) + { + if (strlen(n.UU.sval) > 0) + { + chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); + } + PhreeqcPtr->PHRQ_free(n.UU.sval); + } + else + chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; + chart->Set_point_added(true); + // Add a new curve if necessary + if ((int) chart->Get_Curves().size() == chart->Get_colnr()) + { + //if (chart->Get_new_headings().size() > 0) + //{ + // // remove x heading + // if (chart->Get_colnr() == chart->Get_ColumnOffset()) + // { + // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + // } + //} + if (chart->Get_new_headings().size() > 0) + { + chart->Add_curve(false, chart->Get_new_headings()[0]); + chart->Get_new_headings().erase(chart->Get_new_headings().begin()); + } + else + { + chart->Add_curve(false); + } + chart->Set_curve_added(true); + } + chart->Set_colnr(chart->Get_colnr() + 1); + } +} +#endif // MULTICHART + + + + +/* In case your system lacks these... */ + +long PBasic:: +my_labs(long l_x) +{ + return ((l_x > 0) ? l_x : -l_x); +} + + +/* #define __STDC__ */ /* PHREEQ98 */ + +PBasic::Anyptr PBasic:: +my_memmove(Anyptr d, Const Anyptr l_s, size_t n) +{ + register char *dd = (char *) d, *ss = (char *) l_s; + if (dd < ss || (unsigned int) (dd - ss) >= n) + { + memcpy(dd, ss, n); + } + else if (n > 0) + { + dd += n; + ss += n; + while (n-- > 0) + *--dd = *--ss; + } + return d; +} + + +PBasic::Anyptr PBasic:: +my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) +{ + register char *ss = (char *) l_s, *dd = (char *) d; + while (n-- > 0) + *dd++ = *ss++; + return d; +} + +int PBasic:: +my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) +{ + register char *a = (char *) s1, *b = (char *) s2; + register int i; + while (n-- > 0) + if ((i = (*a++) - (*b++)) != 0) + return i; + return 0; +} + +PBasic::Anyptr PBasic:: +my_memset(Anyptr d, int c, size_t n) +{ + register char *dd = (char *) d; + while (n-- > 0) + *dd++ = (char) c; + return d; +} + +int PBasic:: +my_toupper(int c) +{ + if (islower(c)) + return _toupper(c); + else + return c; +} + + +int PBasic:: +my_tolower(int c) +{ + if (isupper(c)) + return _tolower(c); + else + return c; +} + + + + +long PBasic:: +ipow(long a, long b) +{ + long v; + + if (a == 0 || a == 1) + return a; + if (a == -1) + return (b & 1) ? -1 : 1; + if (b < 0) + return 0; + if (a == 2) + return 1L << b; + v = (b & 1) ? a : 1; + while ((b >>= 1) > 0) + { + a *= a; + if (b & 1) + v *= a; + } + return v; +} + + + + +/* Common string functions: */ + +/* Store in "ret" the substring of length "len" starting from "pos" (1-based). + Store a shorter or null string if out-of-range. Return "ret". */ +char * PBasic:: +strsub(register char *ret, register char *l_s, register int pos, + register int len) +{ + register char *s2; + + if (--pos < 0 || len <= 0) + { + *ret = 0; + return ret; + } + while (pos > 0) + { + if (!*l_s++) + { + *ret = 0; + return ret; + } + pos--; + } + s2 = ret; + while (--len >= 0) + { + if (!(*s2++ = *l_s++)) + return ret; + } + *s2 = 0; + return ret; +} + + +/* Return the index of the first occurrence of "pat" as a substring of "s", + starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ + +int PBasic:: +strpos2(char *l_s, register char *pat, register int pos) +{ + register char *cp, ch; + register int slen; + + if (--pos < 0) + return 0; + slen = (int) strlen(l_s) - pos; + cp = l_s + pos; + if (!(ch = *pat++)) + return 0; + pos = (int) strlen(pat); + slen -= pos; + while (--slen >= 0) + { + if (*cp++ == ch && !strncmp(cp, pat, pos)) + return (int) (cp - l_s); + } + return 0; +} + + +/* Case-insensitive version of strcmp. */ +int PBasic:: +strcicmp(register char *s1, register char *s2) +{ + register unsigned char c1, c2; + + while (*s1) + { + if (*s1++ != *s2++) + { + if (!s2[-1]) + return 1; + c1 = (unsigned char) toupper(s1[-1]); + c2 = (unsigned char) toupper(s2[-1]); + if (c1 != c2) + return c1 - c2; + } + } + if (*s2) + return -1; + return 0; +} + + + + +/* HP and Turbo Pascal string functions: */ + +/* Trim blanks at left end of string. */ +char * PBasic:: +strltrim(register char *l_s) +{ + while (Isspace((int) *l_s++)); + return l_s - 1; +} + + +/* Trim blanks at right end of string. */ +char * PBasic:: +strrtrim(register char *l_s) +{ + register char *s2 = l_s; + + if (!*l_s) + return l_s; + while (*++s2); + while (s2 > l_s && Isspace((int) *--s2)) + *s2 = 0; + return l_s; +} + + +/* Store in "ret" string "s" with enough pad chars added to reach "size". */ + +/* Copy the substring of length "len" from index "spos" of "s" (1-based) + to index "dpos" of "d", lengthening "d" if necessary. Length and + indices must be in-range. */ +void PBasic:: +strmove(register int len, register char *l_s, register int spos, + register char *d, register int dpos) +{ + l_s += spos - 1; + d += dpos - 1; + while (*d && --len >= 0) + *d++ = *l_s++; + if (len > 0) + { + while (--len >= 0) + *d++ = *l_s++; + *d = 0; + } +} + +/* Insert string "src" at index "pos" of "dst". */ +void PBasic:: +strinsert(register char *src, register char *dst, register int pos) +{ + register int slen, dlen; + + if (--pos < 0) + return; + dlen = (int) strlen(dst); + dst += dlen; + dlen -= pos; + if (dlen <= 0) + { + strcpy(dst, src); + return; + } + slen = (int) strlen(src); + do + { + dst[slen] = *dst; + --dst; + } + while (--dlen >= 0); + dst++; + while (--slen >= 0) + *dst++ = *src++; +} + + + + +/* File functions */ + +/* Peek at next character of input stream; return EOF at end-of-file. */ +int PBasic:: +P_peek(FILE * f) +{ + int ch; + + ch = getc(f); + if (ch == EOF) + return EOF; + ungetc(ch, f); + return (ch == '\n') ? ' ' : ch; +} + + +/* Check if at end of file, using Pascal "eof" semantics. End-of-file for + stdin is broken; remove the special case for it to be broken in a + different way. */ +/*int P_eof(FILE *f)*/ +int PBasic:: +P_eof(void) +{ + return 0; +} + + +/* Check if at end of line (or end of entire file). */ +int PBasic:: +P_eoln(FILE * f) +{ + register int ch; + + ch = getc(f); + if (ch == EOF) + return 1; + ungetc(ch, f); + return (ch == '\n'); +} + + +/* Read a packed array of characters from a file. */ +void PBasic:: +P_readpaoc(FILE * f, char *l_s, int len) +{ + int ch; + + for (;;) + { + if (len <= 0) + return; + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + *l_s++ = (char) ch; + --len; + } + while (--len >= 0) + *l_s++ = ' '; + if (ch != EOF) + ungetc(ch, f); +} + +void PBasic:: +P_readlnpaoc(FILE * f, char *l_s, int len) +{ + int ch; + + for (;;) + { + ch = getc(f); + if (ch == EOF || ch == '\n') + break; + if (len > 0) + { + *l_s++ = (char) ch; + --len; + } + } + while (--len >= 0) + *l_s++ = ' '; +} + + +/* Compute maximum legal "seek" index in file (0-based). */ +long PBasic:: +P_maxpos(FILE * f) +{ + long savepos = ftell(f); + long val; + + if (fseek(f, 0L, SEEK_END)) + return -1; + val = ftell(f); + if (fseek(f, savepos, SEEK_SET)) + return -1; + return val; +} + + +/* Use packed array of char for a file name. */ +char * PBasic:: +P_trimname(register char * fn, register int len) +{ + static char fnbuf[256]; + register char *cp = fnbuf; + + while (--len >= 0 && *fn && !isspace((int) *fn)) + *cp++ = *fn++; + *cp = 0; + return fnbuf; +} + + + + +/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. + We fix memory size as 10Meg as a reasonable compromise. */ + +long PBasic:: +memavail(void) +{ + return 10000000; /* worry about this later! */ +} + +long PBasic:: +maxavail(void) +{ + return memavail(); +} + + + + +/* Sets are stored as an array of longs. S[0] is the size of the set; + S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum + I such that S[I] is nonzero. S[0] is zero for an empty set. Within + each long, bits are packed from lsb to msb. The first bit of the + set is the element with ordinal value 0. (Thus, for a "set of 5..99", + the lowest five bits of the first long are unused and always zero.) */ + +/* (Sets with 32 or fewer elements are normally stored as plain longs.) */ +long * PBasic:: +P_setunion(register long *d, register long *s1, register long *s2) /* d := s1 + s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) + { + *d++ = *s1++ | *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + *dbase = (int) (d - dbase - 1); + return dbase; +} + +long * PBasic:: +P_setint(register long *d, register long *s1, register long *s2) /* d := s1 * s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & *s2++; + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * PBasic:: +P_setdiff(register long *d, register long *s1, register long *s2) /* d := s1 - s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (--sz1 >= 0 && --sz2 >= 0) + *d++ = *s1++ & ~*s2++; + if (sz1 >= 0) + { + while (sz1-- >= 0) + *d++ = *s1++; + } + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * PBasic:: +P_setxor(register long *d, register long *s1, register long *s2) /* d := s1 / s2 */ +{ + long *dbase = d++; + register int sz1 = *s1++, sz2 = *s2++; + while (sz1 > 0 && sz2 > 0) + { + *d++ = *s1++ ^ *s2++; + sz1--, sz2--; + } + while (--sz1 >= 0) + *d++ = *s1++; + while (--sz2 >= 0) + *d++ = *s2++; + while (--d > dbase && !*d); + *dbase = (int) (d - dbase); + return dbase; +} + +long * PBasic:: +P_addset(register long *l_s, register unsigned val) /* s := s + [val] */ +{ + register long *sbase = l_s; + register int bit, size; + bit = val % SETBITS; + val /= SETBITS; + size = *l_s; + if ((long) ++val > size) + { + l_s += size; + while ((long) val > size) + *++l_s = 0, size++; + *sbase = size; + } + else + l_s += val; + *l_s |= 1L << bit; + return sbase; +} + +long * PBasic:: +P_addsetr(register long *l_s, register unsigned v1, register unsigned v2) /* s := s + [v1..v2] */ +{ + register long *sbase = l_s; + register int b1, b2, size; + if ((int) v1 > (int) v2) + return sbase; + b1 = v1 % SETBITS; + v1 /= SETBITS; + b2 = v2 % SETBITS; + v2 /= SETBITS; + size = *l_s; + v1++; + if ((int) ++v2 > size) + { + while ((int) v2 > size) + l_s[++size] = 0; + l_s[v2] = 0; + *l_s = v2; + } + l_s += v1; + if (v1 == v2) + { + *l_s |= (~((-2L) << (b2 - b1))) << b1; + } + else + { + *l_s++ |= (-1L) << b1; + while (++v1 < v2) + *l_s++ = -1; + *l_s |= ~((-2L) << b2); + } + return sbase; +} + +long * PBasic:: +P_remset(register long *l_s, register unsigned val) /* s := s - [val] */ +{ + register int bit; + bit = val % SETBITS; + val /= SETBITS; + if ((long) ++val <= *l_s) + { + if (!(l_s[val] &= ~(1L << bit))) + while (*l_s && !l_s[*l_s]) + (*l_s)--; + } + return l_s; +} + +int PBasic:: +P_setequal(register long *s1, register long *s2) /* s1 = s2 */ +{ + register int size = *s1++; + if (*s2++ != size) + return 0; + while (--size >= 0) + { + if (*s1++ != *s2++) + return 0; + } + return 1; +} + +int PBasic:: +P_subset(register long *s1, register long *s2) /* s1 <= s2 */ +{ + register int sz1 = *s1++, sz2 = *s2++; + if (sz1 > sz2) + return 0; + while (--sz1 >= 0) + { + if (*s1++ & ~*s2++) + return 0; + } + return 1; +} + +long * PBasic:: +P_setcpy(register long *d, register long *l_s) /* d := s */ +{ + register long *save_d = d; + +#ifdef SETCPY_MEMCPY + memcpy(d, l_s, (*l_s + 1) * sizeof(long)); +#else + register int i = *l_s + 1; + while (--i >= 0) + *d++ = *l_s++; +#endif + return save_d; +} + + +/* s is a "smallset", i.e., a 32-bit or less set stored + directly in a long. */ +long * PBasic:: +P_expset(register long *d, register long l_s) /* d := s */ +{ + if (l_s) + { + d[1] = l_s; + *d = 1; + } + else + *d = 0; + return d; +} + +long PBasic:: +P_packset(register long *l_s) /* convert s to a small-set */ +{ + if (*l_s++) + return *l_s; + else + return 0; +} + +int PBasic:: +_OutMem(void) +{ + return _Escape(-2); +} + +int PBasic:: +_CaseCheck(void) +{ + return _Escape(-9); +} + +int PBasic:: +_NilCheck(void) +{ + return _Escape(-3); +} + + + + + +/* The following is suitable for the HP Pascal operating system. + It might want to be revised when emulating another system. */ + +char * PBasic:: +_ShowEscape(char *buf, int code, int ior, char *prefix) +{ + char *bufp; + + if (prefix && *prefix) + { + strcpy(buf, prefix); + strcat(buf, ": "); + bufp = buf + strlen(buf); + } + else + { + bufp = buf; + } + if (code == -10) + { + sprintf(bufp, "Pascal system I/O error %d", ior); + switch (ior) + { + case 3: + strcat(buf, " (illegal I/O request)"); + break; + case 7: + strcat(buf, " (bad file name)"); + break; + case FileNotFound: /*10 */ + strcat(buf, " (file not found)"); + break; + case FileNotOpen: /*13 */ + strcat(buf, " (file not open)"); + break; + case BadInputFormat: /*14 */ + strcat(buf, " (bad input format)"); + break; + case 24: + strcat(buf, " (not open for reading)"); + break; + case 25: + strcat(buf, " (not open for writing)"); + break; + case 26: + strcat(buf, " (not open for direct access)"); + break; + case 28: + strcat(buf, " (string subscript out of range)"); + break; + case EndOfFile: /*30 */ + strcat(buf, " (end-of-file)"); + break; + case FileWriteError: /*38 */ + strcat(buf, " (file write error)"); + break; + } + } + else + { + sprintf(bufp, "Pascal system error %d", code); + switch (code) + { + case -2: + strcat(buf, " (out of memory)"); + break; + case -3: + strcat(buf, " (reference to NIL pointer)"); + break; + case -4: + strcat(buf, " (integer overflow)"); + break; + case -5: + strcat(buf, " (divide by zero)"); + break; + case -6: + strcat(buf, " (real math overflow)"); + break; + case -8: + strcat(buf, " (value range error)"); + break; + case -9: + strcat(buf, " (CASE value range error)"); + break; + case -12: + strcat(buf, " (bus error)"); + break; + case -20: + strcat(buf, " (stopped by user)"); + break; + } + } + return buf; +} + +int PBasic:: +_Escape(int code) +{ + char l_buf[100]; + char token[200], empty[2] = { "\0" }; + + P_escapecode = code; + if (__top_jb) + { + __p2c_jmp_buf *jb = __top_jb; + __top_jb = jb->next; + longjmp(jb->jbuf, 1); + } + if (code == 0) + /* exit(EXIT_SUCCESS); */ + error_msg("Exit success in Basic", STOP); + if (code == -1) + { + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", + _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); + error_msg(token, STOP); + exit(EXIT_FAILURE); + } + /* fprintf(stderr, "%s\n", _ShowEscape(l_buf, P_escapecode, P_ioresult, "")); */ + /* exit(EXIT_FAILURE); */ + error_msg("Fatal error in Basic interpreter.", CONTINUE); + sprintf(token, "%s", _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); + error_msg(token, STOP); + return (1); +} + +int PBasic:: +_EscIO(int code) +{ + P_ioresult = code; + return _Escape(-10); +} +/* End. */ +#endif /* PBASIC */ diff --git a/PBasic.h b/PBasic.h new file mode 100644 index 00000000..434f42f6 --- /dev/null +++ b/PBasic.h @@ -0,0 +1,488 @@ +#ifndef _INC_PBasic_H +#define _INC_PBasic_H +#if defined(PBASIC) +#define forloop 0 +#define whileloop 1 +#define gosubloop 2 + +#define checking true +#define varnamelen 20 +#define maxdims 4 + +typedef char varnamestring[varnamelen + 1]; +typedef char string255[256]; +#define MAX_LINE 4096 +#define FileNotFound 10 +#define FileNotOpen 13 +#define FileWriteError 38 +#define BadInputFormat 14 +#define EndOfFile 30 + +#define tokvar 0 +#define toknum 1 +#define tokstr 2 +#define toksnerr 3 +#define tokplus 4 +#define tokminus 5 +#define toktimes 6 +#define tokdiv 7 +#define tokup 8 +#define toklp 9 +#define tokrp 10 +#define tokcomma 11 +#define toksemi 12 +#define tokcolon 13 +#define tokeq 14 +#define toklt 15 +#define tokgt 16 +#define tokle 17 +#define tokge 18 +#define tokne 19 +#define tokand 20 +#define tokor 21 +#define tokxor 22 +#define tokmod 23 +#define toknot 24 +#define toksqr 25 +#define toksqrt 26 +#define toksin 27 +#define tokcos 28 +#define toktan 29 +#define tokarctan 30 +#define toklog 31 +#define tokexp 32 +#define tokabs 33 +#define toksgn 34 +#define tokstr_ 35 +#define tokval 36 +#define tokchr_ 37 +#define tokasc 38 +#define toklen 39 +#define tokmid_ 40 +#define tokpeek 41 +#define tokrem 42 +#define toklet 43 +#define tokprint 44 +#define tokinput 45 +#define tokgoto 46 +#define tokif 47 +#define tokend 48 +#define tokstop 49 +#define tokfor 50 +#define toknext 51 +#define tokwhile 52 +#define tokwend 53 +#define tokgosub 54 +#define tokreturn 55 +#define tokread 56 +#define tokdata 57 +#define tokrestore 58 +#define tokgotoxy 59 +#define tokon 60 +#define tokdim 61 +#define tokpoke 62 +#define toklist 63 +#define tokrun 64 +#define toknew 65 +#define tokload 66 +#define tokmerge 67 +#define toksave 68 +#define tokbye 69 +#define tokdel 70 +#define tokrenum 71 +#define tokthen 72 +#define tokelse 73 +#define tokto 74 +#define tokstep 75 +#define toktc 76 +#define tokm0 77 +#define tokm 78 +#define tokparm 79 +#define tokact 80 +#define tokmol 81 +#define tokla 82 +#define toklm 83 +#define toksr 84 +#define toksi 85 +#define toktot 86 +#define toktk 87 +#define toktime 88 +#define toklog10 89 +#define toksim_time 90 +#define tokequi 91 +#define tokgas 92 +#define tokpunch 93 +#define tokkin 94 +#define toks_s 95 +#define tokmu 96 +#define tokalk 97 +#define tokrxn 98 +#define tokdist 99 +#define tokmisc1 100 +#define tokmisc2 101 +#define tokedl 102 +#define tokstep_no 103 +#define toksim_no 104 +#define toktotal_time 105 +#define tokput 106 +#define tokget 107 +#define tokcharge_balance 109 +#define tokpercent_error 110 +#if defined PHREEQ98 || MULTICHART +#define tokgraph_x 111 +#define tokgraph_y 112 +#define tokgraph_sy 113 +#endif +#define tokcell_no 114 +#define tokexists 115 +#define toksurf 116 +#define toklk_species 117 +#define toklk_named 118 +#define toklk_phase 119 +#define toksum_species 120 +#define toksum_gas 121 +#define toksum_s_s 122 +#define tokcalc_value 123 +#define tokdescription 124 +#define toksys 125 +#define tokinstr 126 +#define tokltrim 127 +#define tokrtrim 128 +#define toktrim 129 +#define tokpad 130 +#define tokchange_por 131 +#define tokget_por 132 +#define tokosmotic 133 +#define tokchange_surf 134 +#define tokporevolume 135 +#define toksc 136 +#define tokgamma 137 +#define toklg 138 +/* VP: Density Start */ +#define tokrho 139 +/* VP: Density End */ +#define tokcell_volume 140 +#define tokcell_pore_volume 141 +#define tokcell_porosity 142 +#define tokcell_saturation 143 +#if defined MULTICHART +#define tokplot_xy 144 +#endif +#define toktotmole 145 +#define tokiso 146 +#define tokiso_unit 147 +#define toktotmol 148 +#define toktotmoles 149 +#define tokeol_ 150 +#define tokceil 151 +#define tokfloor 152 +#define tokphase_formula 153 +#define toklist_s_s 154 +#define tokpr_p 155 +#define tokpr_phi 156 +#define tokgas_p 157 +#define tokgas_vm 158 +/* Header file for code generated by "p2c", the Pascal-to-C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ + +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "PHRQ_base.h" +#include "global_structures.h" + +class Phreeqc; + +class PBasic: public PHRQ_base +{ +public: + PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); + ~PBasic(); +typedef struct __p2c_jmp_buf +{ + struct __p2c_jmp_buf *next; + jmp_buf jbuf; +} __p2c_jmp_buf; + + +/* Warning: The following will not work if setjmp is used simultaneously. + This also violates the ANSI restriction about using vars after longjmp, + but a typical implementation of longjmp will get it right anyway. */ + + +# define TRY(x) do { __p2c_jmp_buf __try_jb; \ + __try_jb.next = __top_jb; \ + if (!setjmp((__top_jb = &__try_jb)->jbuf)) { +# define RECOVER(x) __top_jb = __try_jb.next; } else { +# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ + { L: __top_jb = __try_jb.next; } +# define ENDTRY(x) } } while (0) + +#define SETBITS 32 + +#define Const + +#define P2PP(x) () +#define PV() () +typedef char *Anyptr; + + + + +#define Register register /* Register variables */ +#define char char /* Characters (not bytes) */ + + + + + +typedef struct varrec +{ + varnamestring name; + struct varrec *next; + long dims[maxdims]; + char numdims; + boolean stringvar; + union + { + struct + { + LDBLE *arr; + LDBLE *val, rv; + } U0; + struct + { + char **sarr; + char **sval, *sv; + } U1; + } UU; +} varrec; +typedef struct tokenrec +{ + struct tokenrec *next; + int kind; + union + { + struct varrec *vp; + LDBLE num; + char *sp; + char snch; + } UU; +#ifdef PHREEQCI_GUI + size_t n_sz; + char *sz_num; +#endif +} tokenrec; +typedef struct linerec +{ + long num, num2; + tokenrec *txt; + char inbuf[MAX_LINE]; + struct linerec *next; +} linerec; +typedef struct valrec +{ + boolean stringval; + union + { + LDBLE val; + char *sval; + } UU; +} valrec; + +typedef struct looprec +{ + struct looprec *next; + linerec *homeline; + tokenrec *hometok; + int kind; + union + { + struct + { + varrec *vp; + LDBLE max, step; + } U0; + } UU; +} looprec; + +/* variables for exec: */ +struct LOC_exec +{ + boolean gotoflag, elseflag; + tokenrec *t; +}; + // Methods + int free_dim_stringvar(varrec *varbase); + void exec(void); + int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); + void restoredata(void); + void clearloops(void); + void clearvar(varrec * v); + void clearvars(void); + char * numtostr(char * Result, LDBLE n); + void parse(char * inbuf, tokenrec ** buf); + void listtokens(FILE * f, tokenrec * buf); + void disposetokens(tokenrec ** tok); + void parseinput(tokenrec ** buf); + void errormsg(const char * s); + void snerr(const char * s); + void tmerr(const char * s); + void badsubscr(void); + LDBLE realfactor(struct LOC_exec *LINK); + char * strfactor(struct LOC_exec * LINK); + char *stringfactor(char * Result, struct LOC_exec *LINK); + long intfactor(struct LOC_exec *LINK); + LDBLE realexpr(struct LOC_exec *LINK); + char * strexpr(struct LOC_exec * LINK); + char * stringexpr(char * Result, struct LOC_exec * LINK); + long intexpr(struct LOC_exec *LINK); + void require(int k, struct LOC_exec *LINK); + void skipparen(struct LOC_exec *LINK); + PBasic::varrec * findvar(struct LOC_exec *LINK); + PBasic::valrec factor(struct LOC_exec *LINK); + PBasic::valrec upexpr(struct LOC_exec * LINK); + PBasic::valrec term(struct LOC_exec * LINK); + PBasic::valrec sexpr(struct LOC_exec * LINK); + PBasic::valrec relexpr(struct LOC_exec * LINK); + PBasic::valrec andexpr(struct LOC_exec * LINK); + valrec expr(struct LOC_exec *LINK); + void checkextra(struct LOC_exec *LINK); + boolean iseos(struct LOC_exec *LINK); + void skiptoeos(struct LOC_exec *LINK); + linerec * findline(long n); + linerec * mustfindline(long n); + void cmdend(struct LOC_exec *LINK); + void cmdnew(struct LOC_exec *LINK); + void cmdlist(struct LOC_exec *LINK); + void cmdload(boolean merging, char * name, struct LOC_exec *LINK); + void cmdrun(struct LOC_exec *LINK); + void cmdsave(struct LOC_exec *LINK); + void cmdput(struct LOC_exec *LINK); + void cmdchange_por(struct LOC_exec *LINK); + void cmdchange_surf(struct LOC_exec *LINK); + void cmdbye(void); + void cmddel(struct LOC_exec *LINK); + void cmdrenum(struct LOC_exec *LINK); + void cmdprint(struct LOC_exec *LINK); + void cmdpunch(struct LOC_exec *LINK); + #if defined PHREEQ98 || defined MULTICHART + void cmdgraph_x(struct LOC_exec *LINK); + void cmdgraph_y(struct LOC_exec *LINK); + void cmdgraph_sy(struct LOC_exec *LINK); + #endif + #if defined MULTICHART + void cmdplot_xy(struct LOC_exec *LINK); + #endif + void cmdlet(boolean implied, struct LOC_exec *LINK); + void cmdgoto(struct LOC_exec *LINK); + void cmdif(struct LOC_exec *LINK); + void cmdelse(struct LOC_exec *LINK); + boolean skiploop(int up, int dn, struct LOC_exec *LINK); + void cmdfor(struct LOC_exec *LINK); + void cmdnext(struct LOC_exec *LINK); + void cmdwhile(struct LOC_exec *LINK); + void cmdwend(struct LOC_exec *LINK); + void cmdgosub(struct LOC_exec *LINK); + void cmdreturn(struct LOC_exec *LINK); + void cmdread(struct LOC_exec *LINK); + void cmddata(struct LOC_exec *LINK); + void cmdrestore(struct LOC_exec *LINK); + void cmdgotoxy(struct LOC_exec *LINK); + void cmdon(struct LOC_exec *LINK); + void cmddim(struct LOC_exec *LINK); + void cmdpoke(struct LOC_exec *LINK); +int basic_main(char *commands); +void cmd_initialize(void); +void cmd_free(void); +int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); +int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); +int basic_init(void); +#ifdef PHREEQ98 +void GridChar(char *s, char *a); +#endif +int sget_logical_line(char **ptr, int *l, char *return_line); +void PASCAL_MAIN(int argc, char **argv); +long my_labs(long x); +Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); +Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); +int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); +Anyptr my_memset(Anyptr d, int c, size_t n); +int my_toupper(int c); +int my_tolower(int c); +long ipow(long a, long b); +char * strsub(register char *ret, register char *s, register int pos, + register int len); +int strpos2(char *s, register char *pat, register int pos); +int strcicmp(register char *s1, register char *s2); +char * strltrim(register char *s); +char * strrtrim(register char *s); +void strmove(register int len, register char *s, register int spos, + register char *d, register int dpos); +void strinsert(register char *src, register char *dst, register int pos); +int P_peek(FILE * f); +int P_eof(void); +int P_eoln(FILE * f); +void P_readpaoc(FILE * f, char *s, int len); +void P_readlnpaoc(FILE * f, char *s, int len); +long P_maxpos(FILE * f); +char * P_trimname(register char * fn, register int len); +long memavail(void); +long maxavail(void); +long * P_setunion(register long *d, register long *s1, register long *s2); +long * P_setint(register long *d, register long *s1, register long *s2); +long * P_setdiff(register long *d, register long *s1, register long *s2); +long * P_setxor(register long *d, register long *s1, register long *s2); +long * P_addset(register long *s, register unsigned val); +long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); +long * P_remset(register long *s, register unsigned val); +int P_setequal(register long *s1, register long *s2); +int P_subset(register long *s1, register long *s2); +long * P_setcpy(register long *d, register long *s); +long * P_expset(register long *d, register long s); +long P_packset(register long *s); +int _OutMem(void); +int _CaseCheck(void); +int _NilCheck(void); +static char * _ShowEscape(char *buf, int code, int ior, char *prefix); +int _Escape(int code); +int _EscIO(int code); + + +protected: + Phreeqc * PhreeqcPtr; + char *inbuf; + linerec *linebase; + varrec *varbase; + looprec *loopbase; + long curline; + linerec *stmtline, *dataline; + tokenrec *stmttok, *datatok, *buf; + boolean exitflag; + long EXCP_LINE; + HashTable *command_hash_table; + struct const_key *command; + int NCMDS; + Anyptr __MallocTemp__; + int P_argc; + char **P_argv; + int P_escapecode; + int P_ioresult; + __p2c_jmp_buf *__top_jb; + + //int max_line; +}; + + +/* Following defines are suitable for the HP Pascal operating system */ + +#endif /* PBASIC */ +#endif /* _INC_PBasic_H */ From 27168dbe3e5125b2b467b351afe6311cb9958cf0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Nov 2011 20:11:46 +0000 Subject: [PATCH 0314/1077] Has PR calculations. PBasic not used here. Will compare to this. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5748 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 2 +- KineticsComp.cxx | 2 +- Makefile | 46 ++++++++++++-------------------------------- NameDouble.cxx | 2 +- PPassemblageComp.cxx | 2 +- SSassemblageSS.cxx | 2 +- SurfaceCharge.cxx | 2 +- SurfaceComp.cxx | 2 +- 8 files changed, 19 insertions(+), 41 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 65fd444b..2c01520b 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -12,7 +12,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "ExchComp.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 8144fc8d..1a08fc9f 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "KineticsComp.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" diff --git a/Makefile b/Makefile index 00fc698b..887028a9 100644 --- a/Makefile +++ b/Makefile @@ -104,26 +104,6 @@ EFENCE_LIB=-L$(HOME)/packages/efence # ----------------------------------------------------------------------------- # 2 Versions # ----------------------------------------------------------------------------- -ifeq ($(CFG), RELEASE) - DEFINES = -DPHREEQC_CPP -DNDEBUG $(DEFINE_INVERSE_CL1MP) - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc - CXX = g++ - CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(MAIN_FILE) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -ifeq ($(CFG), DEBUG) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(MAIN_FILE) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - ifeq ($(CFG), CLASS_DEBUG) DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc @@ -140,6 +120,7 @@ ifeq ($(CFG), CLASS_RELEASE) INCLUDES = -I../phreeqc -I.. CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) +# CXXFLAGS = -Wall -pedantic -p $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif @@ -233,6 +214,7 @@ COMMON_CXXOBJS = \ # the current target.) ${PROGRAM} : ${OBJECT_FILES} +# ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} @echo; echo Done making for phreeqcpp # ----------------------------------------------------------------------------- @@ -272,8 +254,7 @@ ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ - ../ExchComp.h ../NameDouble.h ../Parser.h ../Dictionary.h \ - ../phreeqc/phqalloc.h + ../ExchComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -307,7 +288,7 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../KineticsComp.h \ - ../NameDouble.h ../Parser.h ../Dictionary.h ../phreeqc/phqalloc.h + ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -315,7 +296,7 @@ NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../NameDouble.h ../Parser.h \ - ../Dictionary.h ../phreeqc/phqalloc.h + ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ ../Parser.h Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -332,8 +313,7 @@ PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../PPassemblageComp.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ - ../phreeqc/phqalloc.h + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -404,8 +384,7 @@ SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../SSassemblageSS.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ - ../phreeqc/phqalloc.h + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -427,8 +406,7 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceCharge.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Dictionary.h \ - ../phreeqc/phqalloc.h + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -436,8 +414,7 @@ SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceComp.h \ - ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../Dictionary.h \ - ../phreeqc/phqalloc.h + ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -484,6 +461,7 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ CurveObject.o: ../CurveObject.cpp ../CurveObject.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ ../Parser.h +PBasic.o: ../PBasic.cpp Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -778,8 +756,8 @@ clean: rm -rf Class_release Class_debug dependencies: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/NameDouble.cxx b/NameDouble.cxx index 716c1a85..2cde532d 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -12,7 +12,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "NameDouble.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 478caa69..2b2e7f54 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "PPassemblageComp.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" ////////////////////////////////////////////////////////////////////// diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 46cb1979..7545b704 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SSassemblageSS.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index bad34a5c..4f971075 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SurfaceCharge.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index ebedc5f1..eff2fa6d 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SurfaceComp.h" -#include "Dictionary.h" +//#include "Dictionary.h" #include "phqalloc.h" From 579d5a3f05ad10ec806f55f8c82ef1298c10a396 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Nov 2011 23:53:07 +0000 Subject: [PATCH 0315/1077] Fixed up PBasic for Linux. Checked in test cases; PBasic gives same result as non-PBasic. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5750 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 5 +- PBasic.cpp | 157 ++++++++++++++++++++++++++--------------------------- PBasic.h | 100 ++++++++++++++++------------------ 3 files changed, 128 insertions(+), 134 deletions(-) diff --git a/Makefile b/Makefile index 887028a9..982ca3bd 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DPHREEQC_CPP -DUSE_PHRQ_ALLOC -DPHREEQC_CLASS -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) + DEFINES = -DUSE_PHRQ_ALLOC -DPBASIC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -115,7 +115,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DPHREEQC_CPP -DNDEBUG -DPHREEQC_CLASS -DMERGE_INCLUDE_FILES $(DEFINE_INVERSE_CL1MP) + DEFINES = -DNDEBUG -DPBASIC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -187,6 +187,7 @@ COMMON_CXXOBJS = \ NameDouble.o \ NumKeyword.o \ Parser.o \ + PBasic.o \ PHRQ_base.o \ PHRQ_io.o \ PPassemblageComp.o \ diff --git a/PBasic.cpp b/PBasic.cpp index a418f5e5..1bb031dc 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -26,7 +26,6 @@ /* Output from p2c, the Pascal-to-C translator */ /* From input file "basic.p" */ -typedef unsigned char boolean; #include "phqalloc.h" #include "NameDouble.h" @@ -569,7 +568,7 @@ sget_logical_line(char **ptr, int *l, char *return_line) *l = i; return (1); } - void PBasic:: +void PBasic:: restoredata(void) { dataline = NULL; @@ -578,7 +577,7 @@ restoredata(void) - void PBasic:: +void PBasic:: clearloops(void) { looprec *l; @@ -593,7 +592,7 @@ clearloops(void) - void PBasic:: +void PBasic:: clearvar(varrec * v) { if (v->numdims != 0) @@ -626,7 +625,7 @@ clearvar(varrec * v) } - void PBasic:: +void PBasic:: clearvars(void) { varrec *v; @@ -705,7 +704,7 @@ typedef long chset[9]; - void PBasic:: +void PBasic:: parse(char * l_inbuf, tokenrec ** l_buf) { long i, j, begin, len, m, lp, q; @@ -1239,7 +1238,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) - void PBasic:: +void PBasic:: listtokens(FILE * f, tokenrec * l_buf) { boolean ltr; @@ -1901,7 +1900,7 @@ listtokens(FILE * f, tokenrec * l_buf) - void PBasic:: +void PBasic:: disposetokens(tokenrec ** tok) { tokenrec *tok1; @@ -1920,7 +1919,7 @@ disposetokens(tokenrec ** tok) - void PBasic:: +void PBasic:: parseinput(tokenrec ** l_buf) { linerec *l, *l0, *l1; @@ -1974,7 +1973,7 @@ parseinput(tokenrec ** l_buf) restoredata(); } - void PBasic:: +void PBasic:: errormsg(const char * l_s) { error_msg(l_s, CONTINUE); @@ -1982,7 +1981,7 @@ errormsg(const char * l_s) } - void PBasic:: +void PBasic:: snerr(const char * l_s) { char str[MAX_LENGTH] = {0}; @@ -1991,7 +1990,7 @@ snerr(const char * l_s) } - void PBasic:: +void PBasic:: tmerr(const char * l_s) { char str[MAX_LENGTH] = {0}; @@ -2000,14 +1999,14 @@ tmerr(const char * l_s) } - void PBasic:: +void PBasic:: badsubscr(void) { errormsg("Bad subscript"); } - LDBLE PBasic:: +LDBLE PBasic:: realfactor(struct LOC_exec *LINK) { valrec n; @@ -2018,7 +2017,7 @@ realfactor(struct LOC_exec *LINK) return (n.UU.val); } - char * PBasic:: +char * PBasic:: strfactor(struct LOC_exec * LINK) { valrec n; @@ -2029,7 +2028,7 @@ strfactor(struct LOC_exec * LINK) return (n.UU.sval); } - char * PBasic:: +char * PBasic:: stringfactor(char * Result, struct LOC_exec * LINK) { valrec n; @@ -2042,13 +2041,13 @@ stringfactor(char * Result, struct LOC_exec * LINK) return Result; } - long PBasic:: +long PBasic:: intfactor(struct LOC_exec *LINK) { return ((long) floor(realfactor(LINK) + 0.5)); } - LDBLE PBasic:: +LDBLE PBasic:: realexpr(struct LOC_exec *LINK) { valrec n; @@ -2059,7 +2058,7 @@ realexpr(struct LOC_exec *LINK) return (n.UU.val); } - char * PBasic:: +char * PBasic:: strexpr(struct LOC_exec * LINK) { valrec n; @@ -2070,7 +2069,7 @@ strexpr(struct LOC_exec * LINK) return (n.UU.sval); } - char * PBasic:: +char * PBasic:: stringexpr(char * Result, struct LOC_exec * LINK) { valrec n; @@ -2083,14 +2082,14 @@ stringexpr(char * Result, struct LOC_exec * LINK) return Result; } - long PBasic:: +long PBasic:: intexpr(struct LOC_exec *LINK) { return ((long) floor(realexpr(LINK) + 0.5)); } - void PBasic:: +void PBasic:: require(int k, struct LOC_exec *LINK) { char str[MAX_LENGTH] = {0}; @@ -2113,7 +2112,7 @@ require(int k, struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: skipparen(struct LOC_exec *LINK) { do @@ -2134,10 +2133,10 @@ skipparen(struct LOC_exec *LINK) } -PBasic::varrec * PBasic:: +varrec * PBasic:: findvar(struct LOC_exec *LINK) { - PBasic::varrec *v; + varrec *v; long i, j, k; tokenrec *tok; long FORLIM; @@ -2208,7 +2207,7 @@ findvar(struct LOC_exec *LINK) } -PBasic::valrec PBasic:: +valrec PBasic:: factor(struct LOC_exec * LINK) { char string[MAX_LENGTH] = {0}; @@ -3445,7 +3444,7 @@ factor(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: upexpr(struct LOC_exec * LINK) { valrec n, n2; @@ -3481,7 +3480,7 @@ upexpr(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: term(struct LOC_exec * LINK) { valrec n, n2; @@ -3495,7 +3494,7 @@ term(struct LOC_exec * LINK) { k = LINK->t->kind; LINK->t = LINK->t->next; - n2 = PBasic::upexpr(LINK); + n2 = upexpr(LINK); if (n.stringval || n2.stringval) tmerr(": found char, but need a number for * or /"); if (k == tokmod) @@ -3530,7 +3529,7 @@ term(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: sexpr(struct LOC_exec * LINK) { valrec n, n2; @@ -3574,7 +3573,7 @@ sexpr(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: relexpr(struct LOC_exec * LINK) { valrec n, n2; @@ -3588,7 +3587,7 @@ relexpr(struct LOC_exec * LINK) { k = LINK->t->kind; LINK->t = LINK->t->next; - n2 = PBasic::sexpr(LINK); + n2 = sexpr(LINK); if (n.stringval != n2.stringval) tmerr(""); if (n.stringval) @@ -3647,7 +3646,7 @@ relexpr(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: andexpr(struct LOC_exec * LINK) { valrec n, n2; @@ -3664,7 +3663,7 @@ andexpr(struct LOC_exec * LINK) return n; } -PBasic::valrec PBasic:: +valrec PBasic:: expr(struct LOC_exec * LINK) { valrec n, n2; @@ -3689,7 +3688,7 @@ expr(struct LOC_exec * LINK) } - void PBasic:: +void PBasic:: checkextra(struct LOC_exec *LINK) { if (LINK->t != NULL) @@ -3697,7 +3696,7 @@ checkextra(struct LOC_exec *LINK) } - boolean PBasic:: +boolean PBasic:: iseos(struct LOC_exec *LINK) { return ((boolean) (LINK->t == NULL || LINK->t->kind == (long) tokelse || @@ -3705,7 +3704,7 @@ iseos(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: skiptoeos(struct LOC_exec *LINK) { while (!iseos(LINK)) @@ -3713,7 +3712,7 @@ skiptoeos(struct LOC_exec *LINK) } -PBasic::linerec * PBasic:: +linerec * PBasic:: findline(long n) { linerec *l; @@ -3724,7 +3723,7 @@ findline(long n) return l; } -PBasic::linerec * PBasic:: +linerec * PBasic:: mustfindline(long n) { linerec *l; @@ -3738,7 +3737,7 @@ mustfindline(long n) } - void PBasic:: +void PBasic:: cmdend(struct LOC_exec *LINK) { stmtline = NULL; @@ -3746,7 +3745,7 @@ cmdend(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdnew(struct LOC_exec *LINK) { void *p; @@ -3798,7 +3797,7 @@ cmdnew(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdlist(struct LOC_exec *LINK) { linerec *l; @@ -3847,7 +3846,7 @@ cmdlist(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdload(boolean merging, char * name, struct LOC_exec *LINK) { FILE *f; @@ -3890,7 +3889,7 @@ cmdload(boolean merging, char * name, struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdrun(struct LOC_exec *LINK) { linerec *l; @@ -3935,7 +3934,7 @@ cmdrun(struct LOC_exec *LINK) } /* PhreeqcPtr->replace basic save command with transport of rate back to calc_kinetic_rate */ - void PBasic:: +void PBasic:: cmdsave(struct LOC_exec *LINK) { valrec n; @@ -3959,7 +3958,7 @@ cmdsave(struct LOC_exec *LINK) } } } - void PBasic:: +void PBasic:: cmdput(struct LOC_exec *LINK) { int j; @@ -4001,7 +4000,7 @@ cmdput(struct LOC_exec *LINK) s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); } - void PBasic:: +void PBasic:: cmdchange_por(struct LOC_exec *LINK) { int j; @@ -4018,7 +4017,7 @@ cmdchange_por(struct LOC_exec *LINK) PhreeqcPtr->cell_data[j - 1].por = TEMP; } - void PBasic:: +void PBasic:: cmdchange_surf(struct LOC_exec *LINK) { /* @@ -4058,13 +4057,13 @@ cmdchange_surf(struct LOC_exec *LINK) PhreeqcPtr->change_surf[count - 1].cell_no = -99; } - void PBasic:: +void PBasic:: cmdbye(void) { exitflag = true; } - void PBasic:: +void PBasic:: cmddel(struct LOC_exec *LINK) { linerec *l, *l0, *l1; @@ -4125,7 +4124,7 @@ cmddel(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdrenum(struct LOC_exec *LINK) { linerec *l, *l1; @@ -4195,7 +4194,7 @@ cmdrenum(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdprint(struct LOC_exec *LINK) { boolean semiflag; @@ -4230,7 +4229,7 @@ cmdprint(struct LOC_exec *LINK) output_msg("\n"); } - void PBasic:: +void PBasic:: cmdpunch(struct LOC_exec *LINK) { valrec n; @@ -4286,7 +4285,7 @@ cmdpunch(struct LOC_exec *LINK) } #if defined PHREEQ98 - void PBasic:: +void PBasic:: cmdgraph_x(struct LOC_exec *LINK) { boolean semiflag; @@ -4321,7 +4320,7 @@ cmdgraph_x(struct LOC_exec *LINK) } } - void PBasic:: +void PBasic:: cmdgraph_y(struct LOC_exec *LINK) { boolean semiflag; @@ -4356,7 +4355,7 @@ cmdgraph_y(struct LOC_exec *LINK) } } - void PBasic:: +void PBasic:: cmdgraph_sy(struct LOC_exec *LINK) { boolean semiflag; @@ -4392,7 +4391,7 @@ cmdgraph_sy(struct LOC_exec *LINK) } #endif - void PBasic:: +void PBasic:: cmdlet(boolean implied, struct LOC_exec *LINK) { varrec *v; @@ -4432,7 +4431,7 @@ cmdlet(boolean implied, struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdgoto(struct LOC_exec *LINK) { stmtline = mustfindline(intexpr(LINK)); @@ -4441,7 +4440,7 @@ cmdgoto(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdif(struct LOC_exec *LINK) { LDBLE n; @@ -4472,14 +4471,14 @@ cmdif(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdelse(struct LOC_exec *LINK) { LINK->t = NULL; } - boolean PBasic:: +boolean PBasic:: skiploop(int up, int dn, struct LOC_exec *LINK) { boolean Result; @@ -4514,7 +4513,7 @@ skiploop(int up, int dn, struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdfor(struct LOC_exec *LINK) { looprec *l, lr; @@ -4587,7 +4586,7 @@ cmdfor(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdnext(struct LOC_exec *LINK) { varrec *v; @@ -4629,7 +4628,7 @@ cmdnext(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdwhile(struct LOC_exec *LINK) { looprec *l; @@ -4655,7 +4654,7 @@ cmdwhile(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdwend(struct LOC_exec *LINK) { tokenrec *tok; @@ -4703,7 +4702,7 @@ cmdwend(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdgosub(struct LOC_exec *LINK) { looprec *l; @@ -4720,7 +4719,7 @@ cmdgosub(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdreturn(struct LOC_exec *LINK) { looprec *l; @@ -4748,7 +4747,7 @@ cmdreturn(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdread(struct LOC_exec *LINK) { varrec *v; @@ -4800,14 +4799,14 @@ cmdread(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmddata(struct LOC_exec *LINK) { skiptoeos(LINK); } - void PBasic:: +void PBasic:: cmdrestore(struct LOC_exec *LINK) { if (iseos(LINK)) @@ -4820,7 +4819,7 @@ cmdrestore(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdgotoxy(struct LOC_exec *LINK) { intexpr(LINK); @@ -4828,7 +4827,7 @@ cmdgotoxy(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmdon(struct LOC_exec *LINK) { long i; @@ -4866,7 +4865,7 @@ cmdon(struct LOC_exec *LINK) } - void PBasic:: +void PBasic:: cmddim(struct LOC_exec *LINK) { long i, j, k; @@ -4923,7 +4922,7 @@ cmddim(struct LOC_exec *LINK) while (!iseos(LINK)); } - void PBasic:: +void PBasic:: cmdpoke(struct LOC_exec *LINK) { union @@ -4939,7 +4938,7 @@ cmdpoke(struct LOC_exec *LINK) /* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ } - void PBasic:: +void PBasic:: exec(void) { struct LOC_exec V; @@ -5232,7 +5231,7 @@ free_dim_stringvar(varrec *l_varbase) return (OK); } #if defined MULTICHART - void PBasic:: +void PBasic:: cmdplot_xy(struct LOC_exec *LINK) { boolean semiflag; @@ -5320,7 +5319,7 @@ cmdplot_xy(struct LOC_exec *LINK) } chart->Set_colnr(chart->Get_colnr() + 1); } - void PBasic:: +void PBasic:: cmdgraph_x(struct LOC_exec *LINK) { boolean semiflag; @@ -5367,7 +5366,7 @@ cmdgraph_x(struct LOC_exec *LINK) } } - void PBasic:: +void PBasic:: cmdgraph_y(struct LOC_exec *LINK) { boolean semiflag; @@ -5431,7 +5430,7 @@ cmdgraph_y(struct LOC_exec *LINK) } } - void PBasic:: +void PBasic:: cmdgraph_sy(struct LOC_exec *LINK) { boolean semiflag; diff --git a/PBasic.h b/PBasic.h index 434f42f6..84f012e1 100644 --- a/PBasic.h +++ b/PBasic.h @@ -9,6 +9,7 @@ #define varnamelen 20 #define maxdims 4 +typedef unsigned char boolean; typedef char varnamestring[varnamelen + 1]; typedef char string255[256]; #define MAX_LINE 4096 @@ -198,52 +199,6 @@ typedef char string255[256]; #include "phrqtype.h" #include "PHRQ_base.h" #include "global_structures.h" - -class Phreeqc; - -class PBasic: public PHRQ_base -{ -public: - PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); - ~PBasic(); -typedef struct __p2c_jmp_buf -{ - struct __p2c_jmp_buf *next; - jmp_buf jbuf; -} __p2c_jmp_buf; - - -/* Warning: The following will not work if setjmp is used simultaneously. - This also violates the ANSI restriction about using vars after longjmp, - but a typical implementation of longjmp will get it right anyway. */ - - -# define TRY(x) do { __p2c_jmp_buf __try_jb; \ - __try_jb.next = __top_jb; \ - if (!setjmp((__top_jb = &__try_jb)->jbuf)) { -# define RECOVER(x) __top_jb = __try_jb.next; } else { -# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ - { L: __top_jb = __try_jb.next; } -# define ENDTRY(x) } } while (0) - -#define SETBITS 32 - -#define Const - -#define P2PP(x) () -#define PV() () -typedef char *Anyptr; - - - - -#define Register register /* Register variables */ -#define char char /* Characters (not bytes) */ - - - - - typedef struct varrec { varnamestring name; @@ -320,6 +275,45 @@ struct LOC_exec boolean gotoflag, elseflag; tokenrec *t; }; + +class Phreeqc; + +class PBasic: public PHRQ_base +{ +public: + PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); + ~PBasic(); +typedef struct __p2c_jmp_buf +{ + struct __p2c_jmp_buf *next; + jmp_buf jbuf; +} __p2c_jmp_buf; + + +/* Warning: The following will not work if setjmp is used simultaneously. + This also violates the ANSI restriction about using vars after longjmp, + but a typical implementation of longjmp will get it right anyway. */ + + +# define TRY(x) do { __p2c_jmp_buf __try_jb; \ + __try_jb.next = __top_jb; \ + if (!setjmp((__top_jb = &__try_jb)->jbuf)) { +# define RECOVER(x) __top_jb = __try_jb.next; } else { +# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ + { L: __top_jb = __try_jb.next; } +# define ENDTRY(x) } } while (0) + +#define SETBITS 32 + +#define Const + +#define P2PP(x) () +#define PV() () +typedef char *Anyptr; + +#define Register register /* Register variables */ +#define char char /* Characters (not bytes) */ + // Methods int free_dim_stringvar(varrec *varbase); void exec(void); @@ -347,13 +341,13 @@ struct LOC_exec long intexpr(struct LOC_exec *LINK); void require(int k, struct LOC_exec *LINK); void skipparen(struct LOC_exec *LINK); - PBasic::varrec * findvar(struct LOC_exec *LINK); - PBasic::valrec factor(struct LOC_exec *LINK); - PBasic::valrec upexpr(struct LOC_exec * LINK); - PBasic::valrec term(struct LOC_exec * LINK); - PBasic::valrec sexpr(struct LOC_exec * LINK); - PBasic::valrec relexpr(struct LOC_exec * LINK); - PBasic::valrec andexpr(struct LOC_exec * LINK); + varrec * findvar(struct LOC_exec *LINK); + valrec factor(struct LOC_exec *LINK); + valrec upexpr(struct LOC_exec * LINK); + valrec term(struct LOC_exec * LINK); + valrec sexpr(struct LOC_exec * LINK); + valrec relexpr(struct LOC_exec * LINK); + valrec andexpr(struct LOC_exec * LINK); valrec expr(struct LOC_exec *LINK); void checkextra(struct LOC_exec *LINK); boolean iseos(struct LOC_exec *LINK); From 5930d762bc4aa891e5d854f49f22b8ee08cd01d9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2011 00:19:29 +0000 Subject: [PATCH 0316/1077] Changes to set_pz and set_sit. Avoids setting lg = 0 for the first attempt in set_and_run_wrapper, but then sets = 0 for additional attempts. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5752 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 54925023..e681ca54 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1946,6 +1946,7 @@ struct pp_assemblage *cvode_pp_assemblage_save; struct s_s_assemblage *cvode_s_s_assemblage_save; LDBLE *m_original; LDBLE *m_temp; +int set_and_run_attempt; /* model.cpp ------------------------------- */ LDBLE min_value; From ff2d48f1ad217971d8e90259564d9466bcecd5ef Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2011 15:50:24 +0000 Subject: [PATCH 0317/1077] Going with new PBasic. Removing basic.h, basic_class.h, basic.cpp, p2c.h, and p2clib.cpp. renamed to basic_interpreter. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5755 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 3 +- PBasic.h | 2 - Phreeqc.cpp | 206 +--------------------------------------------------- Phreeqc.h | 17 +---- 4 files changed, 4 insertions(+), 224 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 1bb031dc..afe01dec 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,4 +1,3 @@ -#if defined(PBASIC) #if defined(WIN32) #include #endif @@ -6272,4 +6271,4 @@ _EscIO(int code) return _Escape(-10); } /* End. */ -#endif /* PBASIC */ + diff --git a/PBasic.h b/PBasic.h index 84f012e1..74f3cc6b 100644 --- a/PBasic.h +++ b/PBasic.h @@ -1,6 +1,5 @@ #ifndef _INC_PBasic_H #define _INC_PBasic_H -#if defined(PBASIC) #define forloop 0 #define whileloop 1 #define gosubloop 2 @@ -478,5 +477,4 @@ protected: /* Following defines are suitable for the HP Pascal operating system */ -#endif /* PBASIC */ #endif /* _INC_PBasic_H */ diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 66b75bf6..f5aa4c93 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -11,9 +11,7 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "phqalloc.h" -#if defined(PBASIC) #include "PBasic.h" -#endif Phreeqc::Phreeqc(void) { @@ -171,178 +169,6 @@ Phreeqc::Phreeqc(void) } // basic.c -#if !defined(PBASIC) - struct const_key command_temp[] = { - {"+", tokplus}, - {"-", tokminus}, - {"*", toktimes}, - {"/", tokdiv}, - {"^", tokup}, - {"( or [", toklp}, - {") or ]", tokrp}, - {",", tokcomma}, - {";", toksemi}, - {":", tokcolon}, - {"=", tokeq}, - {"<", toklt}, - {"<=", tokle}, - {">", tokgt}, - {">=", tokge}, - {"and", tokand}, - {"or", tokor}, - {"xor", tokxor}, - {"not", toknot}, - {"mod", tokmod}, - {"sqr", toksqr}, - {"sqrt", toksqrt}, - {"ceil", tokceil}, - {"floor", tokfloor}, - {"sin", toksin}, - {"cos", tokcos}, - {"tan", toktan}, - {"arctan", tokarctan}, - {"log", toklog}, - {"exp", tokexp}, - {"abs", tokabs}, - {"sgn", toksgn}, - {"str$", tokstr_}, - {"val", tokval}, - {"chr$", tokchr_}, - {"eol$", tokeol_}, - {"asc", tokasc}, - {"len", toklen}, - {"mid$", tokmid_}, - {"peek", tokpeek}, - {"let", toklet}, - {"print", tokprint}, - {"punch", tokpunch}, - #if defined PHREEQ98 || defined MULTICHART - {"graph_x", tokgraph_x}, - {"graph_y", tokgraph_y}, - {"graph_sy", tokgraph_sy}, - #endif - #if defined MULTICHART - {"plot_xy", tokplot_xy}, - #endif - {"input", tokinput}, - {"goto", tokgoto}, - {"go to", tokgoto}, - {"if", tokif}, - {"end", tokend}, - {"stop", tokstop}, - {"for", tokfor}, - {"next", toknext}, - {"while", tokwhile}, - {"wend", tokwend}, - {"gosub", tokgosub}, - {"return", tokreturn}, - {"read", tokread}, - {"data", tokdata}, - {"restore", tokrestore}, - {"gotoxy", tokgotoxy}, - {"on", tokon}, - {"dim", tokdim}, - {"poke", tokpoke}, - {"list", toklist}, - {"run", tokrun}, - {"new", toknew}, - {"load", tokload}, - {"merge", tokmerge}, - {"save", toksave}, - {"bye", tokbye}, - {"quit", tokbye}, - {"del", tokdel}, - {"renum", tokrenum}, - {"then", tokthen}, - {"else", tokelse}, - {"to", tokto}, - {"step", tokstep}, - {"tc", toktc}, - {"tk", toktk}, - {"time", toktime}, - {"sim_time", toksim_time}, - {"total_time", toktotal_time}, - {"m0", tokm0}, - {"m", tokm}, - {"parm", tokparm}, - {"act", tokact}, - {"edl", tokedl}, - {"surf", toksurf}, - {"equi", tokequi}, - {"kin", tokkin}, - {"gas", tokgas}, - {"s_s", toks_s}, - {"misc1", tokmisc1}, - {"misc2", tokmisc2}, - {"mu", tokmu}, - {"osmotic", tokosmotic}, - {"alk", tokalk}, - {"lk_species", toklk_species}, - {"lk_named", toklk_named}, - {"lk_phase", toklk_phase}, - {"sum_species", toksum_species}, - {"sum_gas", toksum_gas}, - {"sum_s_s", toksum_s_s}, - {"calc_value", tokcalc_value}, - {"description", tokdescription}, - {"sys", toksys}, - {"instr", tokinstr}, - {"ltrim", tokltrim}, - {"rtrim", tokrtrim}, - {"trim", toktrim}, - {"pad", tokpad}, - {"rxn", tokrxn}, - {"dist", tokdist}, - {"mol", tokmol}, - {"la", tokla}, - {"lm", toklm}, - {"sr", toksr}, - {"si", toksi}, - {"step_no", tokstep_no}, - {"cell_no", tokcell_no}, - {"sim_no", toksim_no}, - {"tot", toktot}, - {"log10", toklog10}, - {"charge_balance", tokcharge_balance}, - {"percent_error", tokpercent_error}, - {"put", tokput}, - {"get", tokget}, - {"exists", tokexists}, - {"rem", tokrem}, - {"change_por", tokchange_por}, - {"get_por", tokget_por}, - {"change_surf", tokchange_surf}, - {"porevolume", tokporevolume}, - {"sc", toksc}, - {"gamma", tokgamma}, - /* VP: Density Start */ - {"lg", toklg}, - {"rho", tokrho}, - /* VP: Density End */ - {"cell_volume", tokcell_volume}, - {"cell_pore_volume", tokcell_pore_volume}, - {"cell_porosity", tokcell_porosity}, - {"cell_saturation", tokcell_saturation}, - {"totmole", toktotmole}, - {"totmol", toktotmol}, - {"totmoles", toktotmoles}, - {"iso", tokiso}, - {"iso_unit", tokiso_unit}, - {"phase_formula", tokphase_formula}, - {"list_s_s", toklist_s_s}, - {"pr_p", tokpr_p}, - {"pr_phi", tokpr_phi}, - {"gas_p", tokgas_p}, - {"gas_vm", tokgas_vm} - }; - NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); - command = new const_key[NCMDS]; - for (i = 0; i < NCMDS; i++) - { - command[i].name = string_duplicate(command_temp[i].name); - command[i].keycount = command_temp[i].keycount; - } -#endif //cl1.c x_arg = NULL, res_arg = NULL, scratch = NULL; @@ -416,13 +242,6 @@ Phreeqc::~Phreeqc(void) keyword[i].name = (char *) free_check_null((void *) keyword[i].name); } delete[] keyword; -#if !defined(PBASIC) - for (i = 0; i < NCMDS; i++) - { - command[i].name = (char *) free_check_null((void *) command[i].name); - } - delete[] command; -#endif free_check_null(default_data_base); free_check_null(sformatf_buffer); @@ -997,31 +816,8 @@ void Phreeqc::init(void) charge_group = NULL; print_density = 0; - // - // Non-class statics - // /* basic.c */ -#if !defined(PBASIC) - command_hash_table = 0; - n_user_punch_index = 0; - inbuf = NULL; - linebase = NULL; - varbase = NULL; - loopbase = NULL; - curline = 0; - stmtline = NULL; - dataline = NULL; - stmttok = NULL; - datatok = NULL; - buf = NULL; - exitflag = FALSE; - EXCP_LINE = 0; - /* p2clib.c */ - P_argc = 0; - P_argv = NULL; - P_escapecode = 0; - P_ioresult = 0; -#endif + /* dw.c */ Q0 = 0; Q5 = 0; diff --git a/Phreeqc.h b/Phreeqc.h index e681ca54..e3643a68 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -29,8 +29,6 @@ #include "ChartHandler.h" #endif -#include "p2c.h" - class cxxNameDouble; class cxxKinetics; class cxxMix; @@ -52,11 +50,7 @@ class cxxSurfaceComp; class cxxStorageBin; #include "global_structures.h" -#if defined(PBASIC) class PBasic; -#else -#include "basic.h" -#endif class Phreeqc { @@ -73,13 +67,9 @@ public: int advection(void); // basic.cpp -#if !defined(PBASIC) -#include "basic_class.h" -#else int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void cmd_free(void); -#endif // basicsubs.cpp ------------------------------- LDBLE activity(const char *species_name); @@ -1866,10 +1856,9 @@ LDBLE f_rho(LDBLE rho_old); PHRQMemHeader *s_pTail; std::stringstream merged_database_stream; std::stringstream merged_input_stream; + /* Basic */ -#if defined(PBASIC) -PBasic * basic_instance; -#endif +PBasic * basic_interpreter; /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; @@ -2070,9 +2059,7 @@ int stop_calculations; char err_str98[80]; #endif -#if defined(PBASIC) friend class PBasic; -#endif friend class ChartObject; #endif /* _INC_PHREEQC_H */ From f8d1baf077670dd63ff24e901a4618adc8082998 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2011 15:57:34 +0000 Subject: [PATCH 0318/1077] deleted obsolete QBasic directory git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5756 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- QBasic/Phreeqc.h | 1505 --------- QBasic/QBasic.cpp | 6050 ------------------------------------ QBasic/QBasic.h | 486 --- QBasic/global.h | 808 ----- QBasic/global_structures.h | 1375 -------- 5 files changed, 10224 deletions(-) delete mode 100644 QBasic/Phreeqc.h delete mode 100644 QBasic/QBasic.cpp delete mode 100644 QBasic/QBasic.h delete mode 100644 QBasic/global.h delete mode 100644 QBasic/global_structures.h diff --git a/QBasic/Phreeqc.h b/QBasic/Phreeqc.h deleted file mode 100644 index bcab34c0..00000000 --- a/QBasic/Phreeqc.h +++ /dev/null @@ -1,1505 +0,0 @@ -#ifndef _INC_PHREEQC_H -#define _INC_PHREEQC_H -#if defined(WIN32) -#include -#endif -/* ---------------------------------------------------------------------- - * INCLUDE FILES - * ---------------------------------------------------------------------- */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "cvdense.h" -#include "runner.h" -#include "dumper.h" -#ifdef MULTICHART -#include "ChartHandler.h" -#endif -#include "PHRQ_io.h" -class cxxNameDouble; -//#include "p2c.h" -#include "global_structures.h" -#include "pitzer_structures.h" -class cxxKinetics; -class cxxMix; -class cxxKineticsComp; -class cxxExchange; -class cxxExchComp; -class cxxGasPhase; -class cxxTemperature; -class cxxPPassemblage; -class cxxPPassemblageComp; -class cxxReaction; -class cxxSolution; -class cxxSolutionIsotopeList; -class cxxSSassemblage; -class cxxSSassemblageSS; -class cxxSurface; -class cxxSurfaceCharge; -class cxxSurfaceComp; -class cxxStorageBin; - -class Phreeqc -{ -public: - Phreeqc(void); - ~Phreeqc(void); - -#include "pitzer.h" -#include "input.h" - -public: -#include "global.h" -/* - All functions are included as methods here -*/ -#define _INC_PHRQPROTO_H - -// advection.c ------------------------------- - -int advection(void); - -// basic.c ------------------------------- - -//int basic_main(char *commands); -//void cmd_initialize(void); -//void cmd_free(void); -//int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -//int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -//int basic_init(void); -//#ifdef PHREEQ98 -//void GridChar(char *s, char *a); -//#endif -//int sget_logical_line(char **ptr, int *l, char *return_line); -//int free_dim_stringvar(varrec *varbase); -//void exec(void); -//int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); -//void restoredata(void); -//void clearloops(void); -//void clearvar(varrec * v); -//void clearvars(void); -//Char * numtostr(Char * Result, LDBLE n); -//void parse(Char * inbuf, tokenrec ** buf); -//void listtokens(FILE * f, tokenrec * buf); -//void disposetokens(tokenrec ** tok); -//void parseinput(tokenrec ** buf); -//void errormsg(const Char * s); -//void snerr(const Char * s); -//void tmerr(const Char * s); -//void badsubscr(void); -//LDBLE realfactor(struct LOC_exec *LINK); -//Char * strfactor(struct LOC_exec * LINK); -//Char *stringfactor(Char * Result, struct LOC_exec *LINK); -//long intfactor(struct LOC_exec *LINK); -//LDBLE realexpr(struct LOC_exec *LINK); -//Char * strexpr(struct LOC_exec * LINK); -//Char * stringexpr(Char * Result, struct LOC_exec * LINK); -//long intexpr(struct LOC_exec *LINK); -//void require(int k, struct LOC_exec *LINK); -//void skipparen(struct LOC_exec *LINK); -//varrec * findvar(struct LOC_exec *LINK); -//valrec factor(struct LOC_exec *LINK); -//valrec upexpr(struct LOC_exec * LINK); -//valrec term(struct LOC_exec * LINK); -//valrec sexpr(struct LOC_exec * LINK); -//valrec relexpr(struct LOC_exec * LINK); -//valrec andexpr(struct LOC_exec * LINK); -//valrec expr(struct LOC_exec *LINK); -//void checkextra(struct LOC_exec *LINK); -//boolean iseos(struct LOC_exec *LINK); -//void skiptoeos(struct LOC_exec *LINK); -//linerec * findline(long n); -//linerec * mustfindline(long n); -//void cmdend(struct LOC_exec *LINK); -//void cmdnew(struct LOC_exec *LINK); -//void cmdlist(struct LOC_exec *LINK); -//void cmdload(boolean merging, Char * name, struct LOC_exec *LINK); -//void cmdrun(struct LOC_exec *LINK); -//void cmdsave(struct LOC_exec *LINK); -//void cmdput(struct LOC_exec *LINK); -//void cmdchange_por(struct LOC_exec *LINK); -//void cmdchange_surf(struct LOC_exec *LINK); -//void cmdbye(void); -//void cmddel(struct LOC_exec *LINK); -//void cmdrenum(struct LOC_exec *LINK); -//void cmdprint(struct LOC_exec *LINK); -//void cmdpunch(struct LOC_exec *LINK); -//#if defined PHREEQ98 || defined MULTICHART -//void cmdgraph_x(struct LOC_exec *LINK); -//void cmdgraph_y(struct LOC_exec *LINK); -//void cmdgraph_sy(struct LOC_exec *LINK); -//#endif -//#if defined MULTICHART -//void cmdplot_xy(struct LOC_exec *LINK); -//#endif -//void cmdlet(boolean implied, struct LOC_exec *LINK); -//void cmdgoto(struct LOC_exec *LINK); -//void cmdif(struct LOC_exec *LINK); -//void cmdelse(struct LOC_exec *LINK); -//boolean skiploop(int up, int dn, struct LOC_exec *LINK); -//void cmdfor(struct LOC_exec *LINK); -//void cmdnext(struct LOC_exec *LINK); -//void cmdwhile(struct LOC_exec *LINK); -//void cmdwend(struct LOC_exec *LINK); -//void cmdgosub(struct LOC_exec *LINK); -//void cmdreturn(struct LOC_exec *LINK); -//void cmdread(struct LOC_exec *LINK); -//void cmddata(struct LOC_exec *LINK); -//void cmdrestore(struct LOC_exec *LINK); -//void cmdgotoxy(struct LOC_exec *LINK); -//void cmdon(struct LOC_exec *LINK); -//void cmddim(struct LOC_exec *LINK); -//void cmdpoke(struct LOC_exec *LINK); - -// basicsubs.c ------------------------------- - -LDBLE activity(const char *species_name); -LDBLE activity_coefficient(const char *species_name); -LDBLE log_activity_coefficient(const char *species_name); -LDBLE calc_SC(void); -/* VP: Density Start */ -LDBLE calc_dens(void); -/* VP: Density End */ -LDBLE calc_logk_n(const char *name); -LDBLE calc_logk_p(const char *name); -LDBLE calc_logk_s(const char *name); -LDBLE calc_surface_charge(const char *surface_name); -LDBLE diff_layer_total(const char *total_name, const char *surface_name); -LDBLE equi_phase(const char *phase_name); -LDBLE find_gas_comp(const char *gas_comp_name); -LDBLE find_misc1(const char *s_s_name); -LDBLE find_misc2(const char *s_s_name); -LDBLE find_s_s_comp(const char *s_s_comp_name); -LDBLE get_calculate_value(const char *name); -char * iso_unit(const char *total_name); -LDBLE iso_value(const char *total_name); -LDBLE kinetics_moles(const char *kinetics_name); -LDBLE log_activity(const char *species_name); -LDBLE log_molality(const char *species_name); -LDBLE molality(const char *species_name); -LDBLE saturation_ratio(const char *phase_name); -int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); -LDBLE solution_sum_secondary(const char *total_name); -LDBLE sum_match_gases(const char *stemplate, const char *name); -LDBLE sum_match_species(const char *stemplate, const char *name); -LDBLE sum_match_s_s(const char *stemplate, const char *name); -int match_elts_in_species(const char *name, const char *stemplate); -int extract_bracket(char **string, char *bracket_string); -LDBLE surf_total(const char *total_name, const char *surface_name); -static int system_species_compare(const void *ptr1, const void *ptr2); -LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); -std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); -LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); -int system_total_elements(void); -int system_total_si(void); -int system_total_aq(void); -int system_total_ex(void); -int system_total_surf(void); -int system_total_gas(void); -int system_total_s_s(void); -int system_total_elt(const char *total_name); -int system_total_elt_secondary(const char *total_name); -LDBLE total(const char *total_name); -LDBLE total_mole(const char *total_name); -int system_total_solids(struct exchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, - struct surface *surface_ptr); - -static LDBLE f_rho(LDBLE rho_old, void *cookie); - -// chart.cpp -#if defined PHREEQ98 -void DeleteCurves(void); -void ExtractCurveInfo(char *line, int curvenr); -void GridChar(char *s, char *a); -void MallocCurves(int nc, int ncxy); -int OpenCSVFile(char file_name[MAX_LENGTH]); -void SaveCurvesToFile(char file_name[MAX_LENGTH]); -void PlotXY(char *x, char *y); -void ReallocCurves(int new_nc); -void ReallocCurveXY(int i); -void SetAxisScale(char *a, int j, char *token, int true_); -void SetAxisTitles(char *s, int i); -void SetChartTitle(char *s); -void start_chart(bool end); -#endif -// cl1.c ------------------------------- -int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q, - int *kode, LDBLE toler, - int *iter, LDBLE * x, LDBLE * res, LDBLE * error, - LDBLE * cu, int *iu, int *s, int check); -void cl1_space(int check, int n2d, int klm, int nklmd); - -// cl1mp.c ------------------------------- -int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - - - -// class_main.c ------------------------------- -#ifdef DOS -int write_banner(void); -#endif - -/* default.c */ -public: -int close_input_files(void); -int close_output_files(void); -static int istream_getc(void *cookie); -int process_file_names(int argc, char *argv[], void **db_cookie, - void **input_cookie, int log); - -/* PHRQ_io_output.cpp */ -void screen_msg(const char *err_str); -void echo_msg(const char *err_str); -int warning_msg(const char *err_str); -void set_forward_output_to_log(int value); -int get_forward_output_to_log(void); - -// dump_file -bool dump_open(const char *file_name); -void dump_fflush(void); -void dump_close(void); -void dump_rewind(void); -bool dump_isopen(void); -void dump_msg(const char * str); - -// log_file -bool log_open(const char *file_name); -void log_fflush(void); -void log_close(void); -void log_rewind(void); -bool log_isopen(void); -void log_msg(const char * str); - -// error_file -bool error_open(const char *file_name); -void error_fflush(void); -void error_close(void); -void error_rewind(void); -bool error_isopen(void); -void error_msg(const char * str, bool stop=false); - -// output_temp_file -bool output_temp_open(const char *file_name); -void output_temp_fflush(void); -void output_temp_close(void); -void output_temp_rewind(void); -bool output_temp_isopen(void); -void output_temp_msg(const char * str); - -// punch_file -bool punch_open(const char *file_name); -void punch_fflush(void); -void punch_close(void); -void punch_rewind(void); -bool punch_isopen(void); -void punch_msg(const char * str); - -void fpunchf_heading(const char *name); -void fpunchf(const char *name, const char *format, double d); -void fpunchf(const char *name, const char *format, char * d); -void fpunchf(const char *name, const char *format, int d); -void fpunchf_user(int user_index, const char *format, double d); -void fpunchf_user(int user_index, const char *format, char * d); -int fpunchf_end_row(const char *format); - -// dw.c ------------------------------- -int BB(LDBLE T); -LDBLE PS(LDBLE T); -LDBLE VLEST(LDBLE T); -int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); -int QQ(LDBLE T, LDBLE D); -LDBLE BASE(LDBLE D); - -// input.c ------------------------------- - -int reading_database(void); -struct read_callback s_read_callback; -int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); - -// integrate.c ------------------------------- - -int calc_all_g(void); -int calc_init_g(void); -int initial_surface_water(void); -int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); -int calc_all_donnan(void); -int calc_init_donnan(void); -LDBLE g_function(LDBLE x_value); -LDBLE midpnt(LDBLE x1, LDBLE x2, int n); -void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); -LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); -LDBLE calc_psi_avg(LDBLE surf_chrg_eq); -int calc_all_donnan_music(void); -int calc_init_donnan_music(void); - -// inverse.c ------------------------------- - -int inverse_models(void); -int add_to_file(const char *filename, char *string); -int bit_print(unsigned long bits, int l); -int carbon_derivs(struct inverse *inv_ptr); -int check_isotopes(struct inverse *inv_ptr); -int check_solns(struct inverse *inv_ptr); -int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); -struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); -struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); -int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); -int post_mortem(void); -unsigned long get_bits(unsigned long bits, int position, int number); -unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); -void dump_netpath(struct inverse *inv_ptr); -int dump_netpath_pat(struct inverse *inv_ptr); -int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); -int phase_isotope_inequalities(struct inverse *inv_ptr); -int print_model(struct inverse *inv_ptr); -int punch_model_heading(struct inverse *inv_ptr); -int punch_model(struct inverse *inv_ptr); -void print_isotope(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); -void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); -int range(struct inverse *inv_ptr, unsigned long cur_bits); -int save_bad(unsigned long bits); -int save_good(unsigned long bits); -int save_minimal(unsigned long bits); -unsigned long set_bit(unsigned long bits, int position, int value); -int setup_inverse(struct inverse *inv_ptr); -int set_initial_solution(int n_user_old, int n_user_new); -int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *soln_ptr_orig, - int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); -int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); -int solve_inverse(struct inverse *inv_ptr); -int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); -int subset_bad(unsigned long bits); -int subset_minimal(unsigned long bits); -int superset_minimal(unsigned long bits); -int write_optimize_names(struct inverse *inv_ptr); - -// isotopes.c ------------------------------- - -int add_isotopes(struct solution *solution_ptr); -int calculate_values(void); -int calculate_isotope_moles(struct element *elt_ptr, - struct solution *solution_ptr, LDBLE total_moles); -LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); -int from_pcil(struct master_isotope *master_isotope_ptr); -int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_tu(struct master_isotope *master_isotope_ptr); -struct calculate_value *calculate_value_alloc(void); -int calculate_value_free(struct calculate_value *calculate_value_ptr); -struct calculate_value *calculate_value_search(const char *name); -struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); -struct isotope_alpha *isotope_alpha_alloc(void); -struct isotope_alpha *isotope_alpha_search(const char *name); -struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); -struct isotope_ratio *isotope_ratio_alloc(void); -struct isotope_ratio *isotope_ratio_search(const char *name); -struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_alloc(void); -struct master_isotope *master_isotope_search(const char *name); -int print_initial_solution_isotopes(void); -int print_isotope_ratios(void); -int print_isotope_alphas(void); -int punch_isotopes(void); -int punch_calculate_values(void); -int read_calculate_values(void); -int read_isotopes(void); -int read_isotope_ratios(void); -int read_isotope_alphas(void); -int calculate_value_init(struct calculate_value *calculate_value_ptr); -int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); -int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); -int master_isotope_init(struct master_isotope *master_isotope_ptr); - -// kinetics.c ------------------------------- - -void cvode_init(void); -int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); -int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_advection(int i, int use_mix, int use_kinetics, int nsaver); -int free_cvode(void); -public: -static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - -int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); -int calc_kinetic_reaction(struct kinetics *kinetics_ptr, - LDBLE time_step); -int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); -int set_reaction(int i, int use_mix, int use_kinetics); -int set_transport(int i, int use_mix, int use_kinetics, int nsaver); -int store_get_equi_reactants(int k, int kin_end); -int count_pp, count_pg, count_s_s; -LDBLE *x0_moles; - -// mainsubs ------------------------------- - -FILE *file_open(char *query, char *default_name, const char *status, - int batch); -int copy_entities(void); -void initialize(void); -int initial_exchangers(int print); -int initial_gas_phases(int print); -int initial_solutions(int print); -int step_save_exch(int n_user); -int step_save_surf(int n_user); -int initial_surfaces(int print); -int reactions(void); -int saver(void); -int xsolution_save(int k_user); -int xexchange_save(int n_user); -int xgas_save(int n_user); -int xpp_assemblage_save(int n_user); -int xs_s_assemblage_save(int n_user); -int xsurface_save(int n_user); -int do_initialize(void); -int do_status(void); -void save_init(int i); -void use_init(void); - -int copy_use(int i); -int set_use(void); - -// model.c ------------------------------- - -int check_residuals(void); -int free_model_allocs(void); -int ineq(int kode); -int model(void); -int jacobian_sums(void); -int mb_gases(void); -int mb_s_s(void); -int mb_sums(void); -int molalities(int allow_overflow); -int reset(void); -int residuals(void); -int set(int initial); -int sum_species(void); -int surface_model(void); - -LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); -LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); -LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); -int numerical_jacobian(void); -void set_inert_moles(void); -void unset_inert_moles(void); -#ifdef SLNQ -int add_trivial_eqns(int rows, int cols, LDBLE * matrix); -//int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -#endif -int calc_gas_pressures(void); -int calc_s_s_fractions(void); -int gammas(LDBLE mu); -int initial_guesses(void); -int revise_guesses(void); -int s_s_binary(struct s_s *s_s_ptr); -int s_s_ideal(struct s_s *s_s_ptr); -//int remove_unstable_phases; -int gas_in; -void ineq_init(int max_row_count, int max_column_count); - -// output.c ------------------------------- - -// parse.c ------------------------------- - -int check_eqn(int association); -int get_charge(char *charge, LDBLE * z); -int get_elt(char **t_ptr, char *element, int *i); -int get_elts_in_species(char **t_ptr, LDBLE coef); -int get_num(char **t_ptr, LDBLE * num); -int get_secondary_in_species(char **t_ptr, LDBLE coef); -int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - -int get_coef(LDBLE * coef, char **eqnaddr); -int get_secondary(char **t_ptr, char *element, int *i); -int get_species(char **ptr); - -// phqalloc.c ------------------------------- -public: -#if !defined(NDEBUG) -void *PHRQ_malloc(size_t, const char *, int); -void *PHRQ_calloc(size_t, size_t, const char *, int); -void *PHRQ_realloc(void *, size_t, const char *, int); -#else -void *PHRQ_malloc(size_t); -void *PHRQ_calloc(size_t, size_t); -void *PHRQ_realloc(void *, size_t); -#endif -void PHRQ_free(void *ptr); - -void PHRQ_free_all(void); -protected: - -// phreeqc_files.c ------------------------------- - -#ifdef PHREEQ98 -void check_line_breaks(char *s); -char *prefix_database_dir(char *s); -void show_progress(const int type, char *s); -#endif -public: - -//void PASCAL_MAIN(int argc, Char **argv); -//long my_labs(long x); -//Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); -//Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); -//int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); -//Anyptr my_memset(Anyptr d, int c, size_t n); -//int my_toupper(int c); -//int my_tolower(int c); -//long ipow(long a, long b); -//char * strsub(register char *ret, register char *s, register int pos, -// register int len); -//int strpos2(char *s, register char *pat, register int pos); -//int strcicmp(register char *s1, register char *s2); -//char * strltrim(register char *s); -//char * strrtrim(register char *s); -//void strmove(register int len, register char *s, register int spos, -// register char *d, register int dpos); -//void strinsert(register char *src, register char *dst, register int pos); -//int P_peek(FILE * f); -//int P_eof(void); -//int P_eoln(FILE * f); -//void P_readpaoc(FILE * f, char *s, int len); -//void P_readlnpaoc(FILE * f, char *s, int len); -//long P_maxpos(FILE * f); -//Char * P_trimname(register Char * fn, register int len); -//long memavail(void); -//long maxavail(void); -//long * P_setunion(register long *d, register long *s1, register long *s2); -//long * P_setint(register long *d, register long *s1, register long *s2); -//long * P_setdiff(register long *d, register long *s1, register long *s2); -//long * P_setxor(register long *d, register long *s1, register long *s2); -//long * P_addset(register long *s, register unsigned val); -//long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); -//long * P_remset(register long *s, register unsigned val); -//int P_setequal(register long *s1, register long *s2); -//int P_subset(register long *s1, register long *s2); -//long * P_setcpy(register long *d, register long *s); -//long * P_expset(register long *d, register long s); -//long P_packset(register long *s); -//int _OutMem(void); -//int _CaseCheck(void); -//int _NilCheck(void); -//static char * _ShowEscape(char *buf, int code, int ior, char *prefix); -//int _Escape(int code); -//int _EscIO(int code); - -// pitzer.c ------------------------------- - -int gammas_pz(void); -int model_pz(void); -int pitzer(void); -int pitzer_clean_up(void); -int pitzer_init(void); -int pitzer_tidy(void); -int read_pitzer(void); -int set_pz(int initial); - -int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_pz(void); -int ISPEC(char *name); -LDBLE G(LDBLE Y); -LDBLE GP(LDBLE Y); -int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); -int BDK(LDBLE X); -int pitzer_initial_guesses(void); -int pitzer_revise_guesses(void); -int PTEMP(LDBLE TK); -LDBLE JAY(LDBLE X); -LDBLE JPRIME(LDBLE Y); -int jacobian_pz(void); - -// pitzer_structures.c ------------------------------- - -struct pitz_param *pitz_param_alloc(void); -int pitz_param_init(struct pitz_param *pitz_param_ptr); -struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); -int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); - -// pitzer_structures.c ------------------------------- - -int add_potential_factor(void); -int add_cd_music_factors(int n); -int add_surface_charge_balance(void); -int add_cd_music_charge_balances(int i); -int build_gas_phase(void); -int build_jacobian_sums(int k); -int build_mb_sums(void); -int build_min_exch(void); -int build_model(void); -int build_pure_phases(void); -int build_s_s_assemblage(void); -int build_solution_phase_boundaries(void); -int build_species_list(int n); -int build_min_surface(void); -int change_hydrogen_in_elt_list(LDBLE charge); -int clear(void); -int convert_units(struct solution *solution_ptr); -struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); -struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); -int inout(void); -int is_special(struct species *spec); -int mb_for_species_aq(int n); -int mb_for_species_ex(int n); -int mb_for_species_surf(int n); -int quick_setup(void); -int resetup_master(void); -int save_model(void); -int setup_exchange(void); -int setup_gas_phase(void); -int setup_master_rxn(struct master **master_ptr_list, - struct reaction **pe_rxn); -int setup_pure_phases(void); -int setup_related_surface(void); -int setup_s_s_assemblage(void); -int setup_solution(void); -int setup_surface(void); -int setup_unknowns(void); -int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); -int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); -int store_jacob0(int row, int column, LDBLE coef); -int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); -int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); -int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); -int tidy_redox(void); -struct master **unknown_alloc_master(void); -int write_mb_eqn_x(void); -int write_mb_for_species_list(int n); -int write_mass_action_eqn_x(int stop); - -/* prep.c */ - -int check_same_model(void); -int k_temp(LDBLE tc); -LDBLE k_calc(LDBLE * logk, LDBLE tempk); -int prep(void); -int reprep(void); -int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); -int switch_bases(void); -int write_phase_sys_total(int n); - -// print.c ------------------------------- -char *sformatf(const char *format, ...); -int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); -int print_all(void); -int print_exchange(void); -int print_gas_phase(void); -int print_master_reactions(void); -int print_reaction(struct reaction *rxn_ptr); -int print_species(void); -int print_surface(void); -int print_user_print(void); -int punch_all(void); - -int print_alkalinity(void); -int print_diffuse_layer(struct surface_charge *surface_charge_ptr); -int print_eh(void); -int print_irrev(void); -int print_kinetics(void); -int print_mix(void); -int print_pp_assemblage(void); -int print_s_s_assemblage(void); -int print_saturation_indices(void); -int print_surface_cd_music(void); -int print_totals(void); -int print_using(void); -/*int print_user_print(void);*/ -int punch_gas_phase(void); -int punch_identifiers(void); -int punch_kinetics(void); -int punch_molalities(void); -int punch_activities(void); -int punch_pp_assemblage(void); -int punch_s_s_assemblage(void); -int punch_saturation_indices(void); -int punch_totals(void); -int punch_user_punch(void); -#if defined PHREEQ98 || defined MULTICHART -int punch_user_graph(void); -#endif - -// read.c ------------------------------- - -int read_input(void); -int read_conc(int n, int count_mass_balance, char *str); -int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); -int read_log_k_only(char *ptr, LDBLE * log_k); -int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description, int allow_negative=FALSE); -int check_key(char *str); -int check_units(char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print); -int find_option(char *item, int *n, const char **list, int count_list, - int exact); -int get_option(const char **opt_list, int count_opt_list, char **next_char); -int get_true_false(char *string, int default_value); - -int add_psi_master_species(char *token); -int read_advection(void); -int read_analytical_expression_only(char *ptr, LDBLE * log_k); -/* VP: Density Start */ -int read_millero_abcdef (char *ptr, LDBLE * abcdef); -/* VP: Density End */ -int read_copy(void); -int read_debug(void); -int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); -int read_llnl_aqueous_model_parameters(void); -int read_exchange(void); -int read_exchange_master_species(void); -int read_exchange_species(void); -int read_gas_phase(void); -int read_incremental_reactions(void); -int read_inverse(void); -int read_inv_balances(struct inverse *inverse_ptr, char *next_char); -int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); -int read_inv_phases(struct inverse *inverse_ptr, char *next_char); -int read_kinetics(void); -int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); -int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); -LDBLE *read_list_doubles(char **ptr, int *count_doubles); -int *read_list_ints(char **ptr, int *count_ints, int positive); -int *read_list_t_f(char **ptr, int *count_ints); -int read_master_species(void); -int read_mix(void); -int read_named_logk(void); -int read_phases(void); -int read_print(void); -int read_pure_phases(void); -int read_rates(void); -int read_reaction(void); -int read_reaction_reactants(struct irrev *irrev_ptr); -int read_reaction_steps(struct irrev *irrev_ptr); -int read_solid_solutions(void); -int read_temperature(void); -int read_reaction_temps(struct temperature *temperature_ptr); -int read_save(void); -int read_selected_output(void); -int read_solution(void); -int read_species(void); -int read_surf(void); -int read_surface_master_species(void); -int read_surface_species(void); -int read_use(void); -int read_title(void); -int read_user_print(void); -int read_user_punch(void); -#if defined PHREEQ98 -int read_user_graph(void); -#endif -#if defined MULTICHART -int read_user_graph_handler(); -#endif -int next_keyword_or_option(const char **opt_list, int count_opt_list); - -// ReadClass.cxx - int read_solution_raw(void); - int read_exchange_raw(void); - int read_surface_raw(void); - int read_equilibrium_phases_raw(void); - int read_kinetics_raw(void); - int read_solid_solutions_raw(void); - int read_gas_phase_raw(void); - int read_reaction_raw(void); - int read_mix_raw(void); - int read_temperature_raw(void); - int read_dump(void); - int read_solution_modify(void); - int read_equilibrium_phases_modify(void); - int read_exchange_modify(void); - int read_surface_modify(void); - int read_solid_solutions_modify(void); - int read_gas_phase_modify(void); - int read_kinetics_modify(void); - int read_reaction_modify(void); - //int read_reaction_temperature_modify(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); - - -// readtr.c ------------------------------- - -int read_transport(void); -int dump(void); -int dump_exchange(int k); -int dump_gas_phase(int k); -int dump_kinetics(int k); -int dump_mix(int k); -int dump_pp_assemblage(int k); -int dump_reaction(int k); -int dump_s_s_assemblage(int k); -int dump_solution(int k); -int dump_surface(int k); -int dump_cpp(void); - -int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - -// sit.c ------------------------------- - -int gammas_sit(void); -int model_sit(void); -int sit(void); -int sit_clean_up(void); -int sit_init(void); -int sit_tidy(void); -int read_sit(void); -int set_sit(int initial); - -int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_sit(void); -int sit_ISPEC(char *name); -/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ -int sit_initial_guesses(void); -int sit_revise_guesses(void); -int PTEMP_SIT(LDBLE tk); -int jacobian_sit(void); - -// spread.c ------------------------------- - -int read_solution_spread(void); - -int copy_token_tab(char *token_ptr, char **ptr, int *length); -int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); -int spread_row_free(struct spread_row *spread_row_ptr); -int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); -struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI -void add_row(struct spread_row *spread_row_ptr); -void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); -void free_spread(void); -struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - -// step.c ------------------------------- - -int step(LDBLE step_fraction); -int xsolution_zero(void); -int add_exchange(struct exchange *exchange_ptr); -int add_gas_phase(struct gas_phase *gas_phase_ptr); -int add_kinetics(struct kinetics *kinetics_ptr); -int add_mix(struct mix *mix_ptr); -int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int add_reaction(struct irrev *irrev_ptr, int step_number, - LDBLE step_fraction); -int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); -int add_solution(struct solution *solution_ptr, LDBLE extensive, - LDBLE intensive); -int add_surface(struct surface *surface_ptr); -int add_temperature(struct temperature *temperature_ptr, int step_number); - -int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int gas_phase_check(struct gas_phase *gas_phase_ptr); -int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); -int reaction_calc(struct irrev *irrev_ptr); -int solution_check(void); -int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); - -// structures.c ------------------------------- - -int clean_up(void); -int reinitialize(void); -int copier_add(struct copier *copier_ptr, int n_user, int start, int end); -int copier_free(struct copier *copier_ptr); -int copier_init(struct copier *copier_ptr); -static int element_compare(const void *ptr1, const void *ptr2); -public: - struct element *element_store(const char *element); - int elt_list_combine(void); - static int elt_list_compare(const void *ptr1, const void *ptr2); -protected: -struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); -int elt_list_print(struct elt_list *elt_list_ptr); -struct elt_list *elt_list_save(void); -public: - struct exchange *exchange_alloc(void); - struct exchange *exchange_bsearch(int k, int *n); -protected: -int exchange_comp_compare(const void *ptr1, const void *ptr2); -void exchange_comp_init(struct exch_comp *exch_comp_ptr); -public: - int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new); -protected: -static int exchange_compare(const void *ptr1, const void *ptr2); -int exchange_copy_to_last(int n, int n_user); -int exchange_delete(int n_user_old); -int exchange_duplicate(int n_user_old, int n_user_new); -int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, - const char *description); -public: - int exchange_free(struct exchange *exchange_ptr); -protected: -int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); -struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, - int n_user_new); -struct exchange *exchange_search(int n_user, int *n, int print); -int exchange_sort(void); -static int gas_comp_compare(const void *ptr1, const void *ptr2); -public: - struct gas_phase *gas_phase_alloc(void); - struct gas_phase *gas_phase_bsearch(int k, int *n); -protected: -static int gas_phase_compare(const void *ptr1, const void *ptr2); -public: -int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new); -protected: -int gas_phase_copy_to_last(int n, int n_user); -int gas_phase_delete(int n_user_old); -int gas_phase_duplicate(int n_user_old, int n_user_new); -int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, - int n_user_end, char *description); -public: -int gas_phase_free(struct gas_phase *gas_phase_ptr); -int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, - int n_user_new); -struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, - int n_user_new); -struct gas_phase *gas_phase_search(int n_user, int *n); -int gas_phase_sort(void); -enum entity_type get_entity_enum(char *name); -struct inverse *inverse_alloc(void); -int inverse_delete(int i); -static int inverse_isotope_compare(const void *ptr1, const void *ptr2); -struct inverse *inverse_search(int n_user, int *n); -int inverse_sort(void); -struct irrev *irrev_bsearch(int k, int *n); -int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, - int n_user_new); -int irrev_delete(int n_user_old); -int irrev_duplicate(int n_user_old, int n_user_new); -int irrev_free(struct irrev *irrev_ptr); -struct irrev *irrev_search(int n_user, int *n); -int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); -int irrev_sort(void); -public: - struct kinetics *kinetics_alloc(void); - struct kinetics *kinetics_bsearch(int k, int *n); -protected: -int kinetics_delete(int n_user_old); -int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, - struct kinetics_comp *kinetics_comp_old_ptr); -static int kinetics_compare(const void *ptr1, const void *ptr2); -public: -int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new); -protected: -int kinetics_copy_to_last(int n, int n_user); -int kinetics_duplicate(int n_user_old, int n_user_new); -int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, - char *description); -public: -int kinetics_free(struct kinetics *kinetics_ptr); -protected: -int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); -struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, - int n_user_new); -struct kinetics *kinetics_search(int n_user, int *n, int print); -int kinetics_sort(void); -struct logk *logk_alloc(void); -int logk_copy2orig(struct logk *logk_ptr); -struct logk *logk_store(char *name, int replace_if_found); -struct logk *logk_search(char *name); -struct master *master_alloc(void); -static int master_compare(const void *ptr1, const void *ptr2); -int master_delete(char *ptr); -public: -struct master *master_bsearch(const char *ptr); -struct master *master_bsearch_primary(char *ptr); -struct master *master_bsearch_secondary(char *ptr); -struct master *master_search(char *ptr, int *n); -struct mix *mix_bsearch(int k, int *n); -int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new); -int mix_delete(int n_user_old); -int mix_duplicate(int n_user_old, int n_user_new); -int mix_free(struct mix *mix_ptr); -struct mix *mix_search(int n_user, int *n, int print); -int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); -int mix_sort(void); -struct pe_data *pe_data_alloc(void); -public: - struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); - struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -protected: -int pe_data_store(struct pe_data **pe, const char *token); -public: -struct phase *phase_bsearch(const char *ptr, int *j, int print); -protected: -static int phase_compare(const void *ptr1, const void *ptr2); -int phase_delete(int i); -struct phase *phase_store(char *name); -public: -struct pp_assemblage *pp_assemblage_alloc(void); -struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); -protected: -static int pp_assemblage_compare(const void *ptr1, const void *ptr2); -public: -int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, - int n_user_new); -protected: -int pp_assemblage_copy_to_last(int n, int n_user); -int pp_assemblage_delete(int n_user_old); -int pp_assemblage_duplicate(int n_user_old, int n_user_new); -public: -int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); -protected: -int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, - int n_user_end, char *description); -int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, - int n_user_new); -struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage - *pp_assemblage_old_ptr, - int n_user_new); -struct pp_assemblage *pp_assemblage_search(int n_user, int *n); -int pp_assemblage_sort(void); -static int pure_phase_compare(const void *ptr1, const void *ptr2); -struct rate *rate_bsearch(char *ptr, int *j); -int rate_free(struct rate *rate_ptr); -struct rate *rate_search(char *name, int *n); -int rate_sort(void); -struct reaction *rxn_alloc(int ntokens); -struct reaction *rxn_dup(struct reaction *rxn_ptr_old); -LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); -int rxn_free(struct reaction *rxn_ptr); -int rxn_print(struct reaction *rxn_ptr); -static int s_compare(const void *ptr1, const void *ptr2); -int s_delete(int i); -struct species *s_search(const char *name); -struct species *s_store(char *name, LDBLE z, int replace_if_found); -public: - struct s_s_assemblage *s_s_assemblage_alloc(void); - struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); -protected: -static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); -public: - int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, - int n_user_new); -protected: -int s_s_assemblage_copy_to_last(int n, int n_user); -int s_s_assemblage_duplicate(int n_user_old, int n_user_new); -int s_s_assemblage_delete(int n_user_old); -public: - int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); -protected: -int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, - int n_user, int n_user_end, char *description); -int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage - *s_s_assemblage_old_ptr, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); -int s_s_assemblage_sort(void); -static int s_s_compare(const void *ptr1, const void *ptr2); -public: -struct save_values *save_values_bsearch(struct save_values *k, int *n); -static int save_values_compare(const void *ptr1, const void *ptr2); -int save_values_sort(void); -int save_values_store(struct save_values *s_v); -static int conc_compare(const void *ptr1, const void *ptr2); -int conc_init(struct conc *conc_ptr); -static int isotope_compare(const void *ptr1, const void *ptr2); -public: - struct solution *solution_alloc(void); - struct solution *solution_bsearch(int k, int *n, int print); - struct solution *solution_copy(struct solution *solution_old_ptr, - int n_user_new); -protected: -int solution_copy_to_last(int n, int n_user_new); -int solution_duplicate(int n_user_old, int n_user_new); -int solution_delete(int n_user_old); -int solution_delete_n(int n); -int solution_free(struct solution *solution_ptr); -int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); -struct solution *solution_replicate(struct solution *solution_old_ptr, - int n_user_new); -int solution_sort(void); -static int species_list_compare_alk(const void *ptr1, const void *ptr2); -static int species_list_compare_master(const void *ptr1, const void *ptr2); -int species_list_sort(void); -public: - struct Change_Surf *change_surf_alloc(int count); - struct surface *surface_alloc(void); - struct surface *surface_bsearch(int k, int *n); -protected: -struct master *surface_get_psi_master(const char *name, int plane); -static int surface_comp_compare(const void *ptr1, const void *ptr2); -static int surface_charge_compare(const void *ptr1, const void *ptr2); -struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); -int surface_charge_free(struct surface_charge *charge); -static int surface_compare(const void *ptr1, const void *ptr2); -public: - int surface_copy(struct surface *surface_old_ptr, - struct surface *surface_new_ptr, int n_user_new); -protected: -int surface_copy_to_last(int n, int n_user); -int surface_delete(int n_user_old); -int surface_duplicate(int n_user_old, int n_user_new); -public: - int surface_free(struct surface *surface_ptr); -int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, - char *description); -int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); -struct surface *surface_replicate(struct surface *surface_old_ptr, - int n_user_new); -struct surface *surface_search(int n_user, int *n, int print); -int surface_sort(void); -int system_duplicate(int i, int save_old); -struct temperature *temperature_bsearch(int k, int *n); -int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new); -int temperature_delete(int n_user_old); -int temperature_duplicate(int n_user_old, int n_user_new); -int temperature_free(struct temperature *temperature_ptr); -struct temperature *temperature_search(int n_user, int *n); -int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); -int temperature_sort(void); -int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_combine(void); -int trxn_copy(struct reaction *rxn_ptr); -LDBLE trxn_find_coef(const char *str, int start); -int trxn_print(void); -int trxn_reverse_k(void); -int trxn_sort(void); -int trxn_swap(const char *token); -struct unknown *unknown_alloc(void); -int unknown_delete(int i); -int unknown_free(struct unknown *unknown_ptr); -int entity_exists(char *name, int n_user); - -static int exchange_compare_int(const void *ptr1, const void *ptr2); -static int gas_phase_compare_int(const void *ptr1, const void *ptr2); -static int inverse_compare(const void *ptr1, const void *ptr2); -int inverse_free(struct inverse *inverse_ptr); -static int irrev_compare(const void *ptr1, const void *ptr2); -static int irrev_compare_int(const void *ptr1, const void *ptr2); -static int kinetics_compare_int(const void *ptr1, const void *ptr2); -int logk_init(struct logk *logk_ptr); -static int master_compare_string(const void *ptr1, const void *ptr2); -int master_free(struct master *master_ptr); -static int mix_compare(const void *ptr1, const void *ptr2); -static int mix_compare_int(const void *ptr1, const void *ptr2); -struct phase *phase_alloc(void); -static int phase_compare_string(const void *ptr1, const void *ptr2); -int phase_free(struct phase *phase_ptr); -int phase_init(struct phase *phase_ptr); -static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int rate_compare(const void *ptr1, const void *ptr2); -static int rate_compare_string(const void *ptr1, const void *ptr2); -struct species *s_alloc(void); -int s_free(struct species *s_ptr); -int s_init(struct species *s_ptr); -static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int solution_compare(const void *ptr1, const void *ptr2); -static int solution_compare_int(const void *ptr1, const void *ptr2); -static int species_list_compare(const void *ptr1, const void *ptr2); -static int surface_compare_int(const void *ptr1, const void *ptr2); -static int temperature_compare(const void *ptr1, const void *ptr2); -static int temperature_compare_int(const void *ptr1, const void *ptr2); -static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); -int trxn_multiply(LDBLE coef); -#ifdef PHREEQCI_GUI -extern void free_spread(void); -#endif -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern void MergeFinalize(void); -#endif - -// convert class to struct - -struct mix * cxxMix2mix(const cxxMix *mx); -struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); -struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); -struct exchange * cxxExchange2exchange(const cxxExchange * ex); -struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); -struct master * Get_exch_master(const cxxExchComp * ec); -struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); -struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); -struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); -struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); -struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); -struct irrev * cxxReaction2irrev(const cxxReaction * rxn); -struct solution * cxxSolution2solution(const cxxSolution * sol); -struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); -struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); -struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); -struct surface * cxxSurface2surface(const cxxSurface * surf); -struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); -struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); - -struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); -struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); -struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); -struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); -struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); - -void Use2cxxStorageBin(cxxStorageBin & sb); -void phreeqc2cxxStorageBin(cxxStorageBin & sb); -void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); -void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); -void cxxStorageBin2phreeqc(cxxStorageBin & sb); - -/* tally.c */ - -void add_all_components_tally(void); -int build_tally_table(void); -int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); -int diff_tally_table(void); -int extend_tally_table(void); -int free_tally_table(void); -int fill_tally_table(int *n_user, int index_conservative, int n_buffer); -int get_tally_table_rows_columns(int *rows, int *columns); -int get_tally_table_column_heading(int column, int *type, char *string); -int get_tally_table_row_heading(int column, char *string); -int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); -int zero_tally_table(void); - -int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); -int get_all_components(void); -int print_tally_table(void); -int set_reaction_moles(int n_user, LDBLE moles); -int set_reaction_temperature(int n_user, LDBLE tc); -int set_kinetics_time(int n_user, LDBLE step); - -// tidy.c ------------------------------- - -int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); -int add_logks(struct logk *logk_ptr, int repeats); -LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); -int replace_solids_gases(void); -int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); -int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); -int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -public: -int tidy_punch(void); -int tidy_model(void); - -int check_species_input(void); -LDBLE coef_in_master(struct master *master_ptr); -int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); -int reset_last_model(void); -int rewrite_eqn_to_primary(void); -int rewrite_eqn_to_secondary(void); -int species_rxn_to_trxn(struct species *s_ptr); -int tidy_logk(void); -int tidy_exchange(void); -int tidy_min_exchange(void); -int tidy_kin_exchange(void); -int tidy_gas_phase(void); -int tidy_inverse(void); -int tidy_isotopes(void); -int tidy_isotope_ratios(void); -int tidy_isotope_alphas(void); -int tidy_kin_surface(void); -int tidy_master_isotope(void); -int tidy_min_surface(void); -int tidy_phases(void); -int tidy_pp_assemblage(void); -int tidy_solutions(void); -int tidy_s_s_assemblage(void); -int tidy_species(void); -int tidy_surface(void); -int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); -static LDBLE f_spinodal(LDBLE x, void *); -int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); -int s_s_calc_a0_a1(struct s_s *s_s_ptr); - -// transport.c ------------------------------- - -int transport(void); -int set_initial_moles(int i); -int sum_surface_comp(struct surface *source1, LDBLE f1, - struct surface *source2, int k, LDBLE f2, - struct surface *target, LDBLE new_Dw); -int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, - LDBLE new_Dw, int cell); -LDBLE viscosity(void); - -int multi_D(LDBLE DDt, int mobile_cell, int stagnant); -int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); -int fill_spec(int cell_no); -int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); -static int sort_species_name(const void *ptr1, const void *ptr2); -int disp_surf(LDBLE stagkin_time); -int diff_stag_surf(int mobile_cell); -int check_surfaces(struct surface *surface_ptr1, - struct surface *surface_ptr2); -int mobile_surface_copy(struct surface *surface_old_ptr, - struct surface *surf_ptr1, int n_user_new, - int move_old); -int init_mix(void); -int init_heat_mix(int nmix); -int heat_mix(int heat_nmix); -int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); - - -// utilities.c ------------------------------- -public: -int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); -protected: -int backspace_screen(int spaces); -LDBLE calc_alk(struct reaction *rxn_ptr); -public: - int compute_gfw(const char *string, LDBLE * gfw); - #if defined PHREEQ98 - int copy_title(char *token_ptr, char **ptr, int *length); - #endif -int copy_token(char *token_ptr, char **ptr, int *length); -int dup_print(const char *ptr, int emphasis); -int equal(LDBLE a, LDBLE b, LDBLE eps); -public: - void *free_check_null(void *ptr); -protected: -void free_hash_strings(HashTable * Table); -int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); -public: -int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); -void hdestroy_multi(HashTable * HashTable_ptr); -ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); -protected: -int islegit(const char c); -public: -void malloc_error(void); -protected: -int parse_couple(char *token); -int print_centered(const char *string); -public: -static int replace(const char *str1, const char *str2, char *str); -protected: -void space(void **ptr, int i, int *max, int struct_size); -void squeeze_white(char *s_l); -int status(int count, const char *str); -public: -void str_tolower(char *str); -void str_toupper(char *str); -static int strcmp_nocase(const char *str1, const char *str2); -int strcmp_nocase_arg1(const char *str1, const char *str2); - - char *string_duplicate(const char *token); - char *string_hsave(const char *str); - -char *string_pad(char *str, int i); -int string_trim(char *str); -int string_trim_right(char *str); -int string_trim_left(char *str); -static LDBLE under(LDBLE xval); -protected: -void zero_double(LDBLE * target, int n); -int get_input_errors(void); - -#ifdef PHREEQ98 -void AddToCEntry(char *a, int l, int i); -void ApplicationProcessMessages(void); -int copy_title(char *token_ptr, char **ptr, int *length); -extern int clean_up_null(void); -#endif -int isamong(char c, const char *s_l); -Address Hash_multi(HashTable * Table, char *Key); -void ExpandTable_multi(HashTable * Table); - -public: - bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); - -public: // public methods for PHREEQC_CLASS - int main_method(int argc, char *argv[]); - void set_phast(int); - size_t list_components(std::list &list_c); - void *get_cookie(); - void pop_cookie(); - void set_cookie(std::istream * cookie); - void clear_cookie(void); -protected: - void init(void); -//Data - std::list cookie_list; - std::ifstream * in_stream; - std::ifstream * db_stream; - -}; -#endif /* _INC_PHREEQC_H */ - diff --git a/QBasic/QBasic.cpp b/QBasic/QBasic.cpp deleted file mode 100644 index e76b876d..00000000 --- a/QBasic/QBasic.cpp +++ /dev/null @@ -1,6050 +0,0 @@ -#if defined(WIN32) -#include -#endif - -/* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ - -/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. - * This file may be copied, modified, etc. in any way. It is not restricted - * by the licence agreement accompanying p2c itself. - */ - -#include -#include "QBasic.h" - -#define STOP 1 -#define CONTINUE 0 - -#define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ - - - -/* Output from p2c, the Pascal-to-C translator */ -/* From input file "basic.p" */ - -typedef unsigned char boolean; -#include "phqalloc.h" -#include "NameDouble.h" -void QBasic:: -PASCAL_MAIN(int argc, char **argv) -{ - P_argc = argc; - P_argv = argv; - __top_jb = NULL; - P_escapecode = 0; - P_ioresult = 0; -} -/* ---------------------------------------------------------------------- */ -void QBasic:: -cmd_initialize(void) -/* ---------------------------------------------------------------------- */ -{ - ENTRY item, *found_item; - int i; - char *token; -/* - * create hash table - */ - PhreeqcPtr->hcreate_multi((unsigned) 2 * NCMDS, &command_hash_table); -/* - * fill with commands - */ - for (i = 0; i < NCMDS; i++) - { - token = PhreeqcPtr->string_hsave(command[i].name); - item.key = token; - item.data = (void *) &command[i]; - found_item = PhreeqcPtr->hsearch_multi(command_hash_table, item, ENTER); - if (found_item == NULL) - { - sprintf(PhreeqcPtr->error_string, - "Hash table error in basic commands initialization."); - PhreeqcPtr->error_msg(PhreeqcPtr->error_string, STOP); - } - } - return; -} - -/* ---------------------------------------------------------------------- */ -void QBasic:: -cmd_free(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * destroy hash table - */ - - PhreeqcPtr->hdestroy_multi(command_hash_table); - command_hash_table = NULL; - return; -} - -int QBasic:: -basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) -{ /*main */ - int l; - char *ptr; - - PASCAL_MAIN(0, NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) - PhreeqcPtr->malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - do - { - TRY(try2); - ptr = commands; - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) - { - strcpy(inbuf, "bye"); - } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - ENDTRY(try2); - } - while (!(exitflag || P_eof())); - /* exit(EXIT_SUCCESS); */ - PHRQ_free(inbuf); - *lnbase = (void *) linebase; - *vbase = (void *) varbase; - *lpbase = (void *) loopbase; - return (P_escapecode); -} - -int QBasic:: -basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) -{ /*main */ - int l, i; - char *ptr; - PASCAL_MAIN(0, NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) - PhreeqcPtr->malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - do - { - TRY(try2); - i = 0; - ptr = commands; - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) - { - i++; - if (i == 1) - { - strcpy(inbuf, "renum"); - } - else if (i == 2) - { - strcpy(inbuf, "list"); - } - else if (i == 3) - { - strcpy(inbuf, "new"); - } - else if (i == 4) - { - strcpy(inbuf, "bye"); - } - } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - ENDTRY(try2); - } - while (!(exitflag || P_eof())); - /* exit(EXIT_SUCCESS); */ - PHRQ_free(inbuf); - *lnbase = (void *) linebase; - *vbase = (void *) varbase; - *lpbase = (void *) loopbase; - - return (P_escapecode); -} - -int QBasic:: -basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) -{ /*main */ - int l; - char *ptr; - PASCAL_MAIN(0, NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) - PhreeqcPtr->malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; - exitflag = false; - ptr = commands; - linebase = (linerec *) lnbase; - varbase = (varrec *) vbase; - loopbase = (looprec *) lpbase; - do - { - TRY(try2); - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) - { - strcpy(inbuf, "bye"); - } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - ENDTRY(try2); - } - while (!(exitflag || P_eof())); - - /* exit(EXIT_SUCCESS); */ - PHRQ_free(inbuf); - return (P_escapecode); -} - -int QBasic:: -basic_main(char *commands) -{ /*main */ - int l; - char *ptr; - PASCAL_MAIN(0, NULL); - inbuf = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (inbuf == NULL) - PhreeqcPtr->malloc_error(); - linebase = NULL; - varbase = NULL; - loopbase = NULL; -#ifdef SKIP - printf("Chipmunk BASIC 1.0\n\n"); -#endif - exitflag = false; - ptr = commands; - do - { - TRY(try2); - do - { -#ifdef SKIP - putchar('>'); -#endif - if (sget_logical_line(&ptr, &l, inbuf) == EOF) - { - strcpy(inbuf, "bye"); - } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); - RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - ENDTRY(try2); - } - while (!(exitflag || P_eof())); - return 1; -/* exit(EXIT_SUCCESS); */ -} - -/* End. */ -/* ---------------------------------------------------------------------- */ -int QBasic:: -sget_logical_line(char **ptr, int *l, char *return_line) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads file fp until end of line, ";", or eof - * stores characters in line_save - * reallocs line_save and line if more space is needed - * - * returns: - * EOF on empty line on end of file or - * OK otherwise - * *l returns length of line - */ - int i; - char c; - i = 0; - if (**ptr == '\0') - return (EOF); - for (;;) - { - c = **ptr; - if (c == '\0') - break; - (*ptr)++; - if (c == ';' || c == '\n') - break; - return_line[i++] = c; - } - return_line[i] = '\0'; - *l = i; - return (1); -} - void QBasic:: -restoredata(void) -{ - dataline = NULL; - datatok = NULL; -} - - - - void QBasic:: -clearloops(void) -{ - looprec *l; - - while (loopbase != NULL) - { - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - } -} - - - - void QBasic:: -clearvar(varrec * v) -{ - if (v->numdims != 0) - { - if (v->stringvar == 0) - { - PHRQ_free(v->UU.U0.arr); - v->UU.U0.arr = NULL; - } - else - { - free_dim_stringvar(v); - } - } - else if (v->stringvar && v->UU.U1.sv != NULL) - { - PHRQ_free(v->UU.U1.sv); - } - v->numdims = 0; - if (v->stringvar) - { - v->UU.U1.sv = NULL; - v->UU.U1.sval = &v->UU.U1.sv; - } - else - { - v->UU.U0.rv = 0.0; - v->UU.U0.val = &v->UU.U0.rv; - } -} - - - void QBasic:: -clearvars(void) -{ - varrec *v; - - v = varbase; - while (v != NULL) - { - clearvar(v); - v = v->next; - } -} - -char * QBasic:: -numtostr(char * Result, LDBLE n) -{ - /*string255 s; */ - char *l_s; - long i; - - l_s = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (l_s == NULL) - PhreeqcPtr->malloc_error(); - l_s[max_line - 1] = '\0'; -/* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ - if (ceil(n) == floor(n)) - { - if (PhreeqcPtr->punch.high_precision == FALSE) - { - sprintf(l_s, "%12g", (double) n); - } - else - { - sprintf(l_s, "%19g", (double) n); - } - } - else - { - if (PhreeqcPtr->punch.high_precision == FALSE) - { - sprintf(l_s, "%12.4e", (double) n); - } - else - { - sprintf(l_s, "%20.12e", (double) n); - } - } - i = (int) strlen(l_s) + 1; - l_s[i - 1] = '\0'; -/* p2c: basic.p, line 237: - * Note: Modification of string length may translate incorrectly [146] */ - strcpy(Result, l_s); - PhreeqcPtr->free_check_null(l_s); - return (Result); -/* } else { - if (PhreeqcPtr->punch.high_precision == FALSE) sprintf(l_s, "%30.10f", n); - else sprintf(l_s, "%30.12f", n); - i = strlen(l_s) + 1; - do { - i--; - } while (l_s[i - 1] == '0'); - if (l_s[i - 1] == '.') - i--; - l_s[i] = '\0'; - * p2c: basic.p, line 248: - * Note: Modification of string length may translate incorrectly [146] * - return strcpy(Result, strltrim(l_s)); - } */ -} - -#define toklength 20 - - -typedef long chset[9]; - - - - - - void QBasic:: -parse(char * l_inbuf, tokenrec ** l_buf) -{ - long i, j, begin, len, m, lp, q; - char token[toklength + 1] = {0}; - tokenrec *t, *tptr; - varrec *v; - char ch; - ENTRY item, *found_item; - char *ptr; - - tptr = NULL; - *l_buf = NULL; - i = 1; - lp = q = 0; - do - { - ch = ' '; - while (i <= (int) strlen(l_inbuf) && (ch == ' ' || ch == '\t')) - { - ch = l_inbuf[i - 1]; - i++; - } - if (ch != ' ') - { - t = (tokenrec *) PHRQ_calloc(1, sizeof(tokenrec)); - if (t == NULL) - PhreeqcPtr->malloc_error(); - if (tptr == NULL) - *l_buf = t; - else - tptr->next = t; - tptr = t; - t->next = NULL; - switch (ch) - { - - case '"': - case '\'': - q += 1; - t->kind = tokstr; - j = 0; - len = (int) strlen(l_inbuf); - begin = i; - while (i <= len && l_inbuf[i - 1] != ch) - { - ++j; - ++i; - } - if (l_inbuf[i - 1] == ch) q -= 1; - m = 256; - if (j + 1 > m) - m = j + 1; - t->UU.sp = (char *) PHRQ_calloc(m, sizeof(char)); - if (t->UU.sp == NULL) - PhreeqcPtr->malloc_error(); - strncpy(t->UU.sp, l_inbuf + begin - 1, j); - t->UU.sp[j] = '\0'; -/* p2c: basic.p, line 415: - * Note: Modification of string length may translate incorrectly [146] */ - i++; - break; - - case '+': - t->kind = tokplus; - break; - - case '-': - t->kind = tokminus; - break; - - case '*': - t->kind = toktimes; - break; - - case '/': - t->kind = tokdiv; - break; - - case '^': - t->kind = tokup; - break; - - case '(': - case '[': - t->kind = toklp; - lp += 1; - break; - - case ')': - case ']': - t->kind = tokrp; - lp -= 1; - break; - - case ',': - t->kind = tokcomma; - break; - - case ';': - t->kind = toksemi; - break; - - case ':': - t->kind = tokcolon; - break; - - case '?': - t->kind = tokprint; - break; - - case '=': - t->kind = tokeq; - break; - - case '<': - if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') - { - t->kind = tokle; - i++; - } - else if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '>') - { - t->kind = tokne; - i++; - } - else - t->kind = toklt; - break; - - case '>': - if (i <= (int) strlen(l_inbuf) && l_inbuf[i - 1] == '=') - { - t->kind = tokge; - i++; - } - else - t->kind = tokgt; - break; - - default: - if (isalpha((int) ch)) - { - i--; - j = 0; - token[toklength] = '\0'; - while (i <= (int) strlen(l_inbuf) && - (l_inbuf[i - 1] == '$' || l_inbuf[i - 1] == '_' || - isalnum((int) l_inbuf[i - 1]))) - { - if (j < toklength) - { - j++; - token[j - 1] = l_inbuf[i - 1]; - } - i++; - } - token[j] = '\0'; -/* p2c: basic.p, line 309: - * Note: Modification of string length may translate incorrectly [146] */ -#define INT -#ifdef INT -/* - * Search hash list - */ - PhreeqcPtr->str_tolower(token); - item.key = token; - item.data = NULL; - found_item = - PhreeqcPtr->hsearch_multi(command_hash_table, item, FIND); - if (found_item != NULL) - { - t->kind = - ((struct key *) (found_item->data))->keycount; - if (t->kind == tokrem) - { - m = (int) strlen(l_inbuf) + 1; - if (m < 256) - m = 256; - t->UU.sp = (char *) PHRQ_calloc(m, sizeof(char)); - if (t->UU.sp == NULL) - PhreeqcPtr->malloc_error(); - sprintf(t->UU.sp, "%.*s", - (int) (strlen(l_inbuf) - i + 1), - l_inbuf + i - 1); - i = (int) strlen(l_inbuf) + 1; - } -#endif -#ifdef LONG - if (!strcmp(token, "and")) - t->kind = tokand; - else if (!strcmp(token, "or")) - t->kind = tokor; - else if (!strcmp(token, "xor")) - t->kind = tokxor; - else if (!strcmp(token, "not")) - t->kind = toknot; - else if (!strcmp(token, "mod")) - t->kind = tokmod; - else if (!strcmp(token, "sqr")) - t->kind = toksqr; - else if (!strcmp(token, "sqrt")) - t->kind = toksqrt; - else if (!strcmp(token, "ceil")) - t->kind = tokceil; - else if (!strcmp(token, "floor")) - t->kind = tokfloor; - else if (!strcmp(token, "sin")) - t->kind = toksin; - else if (!strcmp(token, "cos")) - t->kind = tokcos; - else if (!strcmp(token, "tan")) - t->kind = toktan; - else if (!strcmp(token, "arctan")) - t->kind = tokarctan; - else if (!strcmp(token, "log")) - t->kind = toklog; - else if (!strcmp(token, "exp")) - t->kind = tokexp; - else if (!strcmp(token, "abs")) - t->kind = tokabs; - else if (!strcmp(token, "sgn")) - t->kind = toksgn; - else if (!strcmp(token, "str$")) - t->kind = tokstr_; - else if (!strcmp(token, "val")) - t->kind = tokval; - else if (!strcmp(token, "chr$")) - t->kind = tokchr_; - else if (!strcmp(token, "eol$")) - t->kind = tokeol_; - else if (!strcmp(token, "asc")) - t->kind = tokasc; - else if (!strcmp(token, "len")) - t->kind = toklen; - else if (!strcmp(token, "mid$")) - t->kind = tokmid_; - else if (!strcmp(token, "peek")) - t->kind = tokpeek; - else if (!strcmp(token, "let")) - t->kind = toklet; - else if (!strcmp(token, "print")) - t->kind = tokprint; - else if (!strcmp(token, "PhreeqcPtr->punch")) - t->kind = tokpunch; -#if defined PHREEQ98 - else if (!strcmp(token, "graph_x")) - t->kind = tokgraph_x; - else if (!strcmp(token, "graph_y")) - t->kind = tokgraph_y; - else if (!strcmp(token, "graph_sy")) - t->kind = tokgraph_sy; -#endif - else if (!strcmp(token, "input")) - t->kind = tokinput; - else if (!strcmp(token, "goto")) - t->kind = tokgoto; - else if (!strcmp(token, "go to")) - t->kind = tokgoto; - else if (!strcmp(token, "if")) - t->kind = tokif; - else if (!strcmp(token, "end")) - t->kind = tokend; - else if (!strcmp(token, "stop")) - t->kind = tokstop; - else if (!strcmp(token, "for")) - t->kind = tokfor; - else if (!strcmp(token, "next")) - t->kind = toknext; - else if (!strcmp(token, "while")) - t->kind = tokwhile; - else if (!strcmp(token, "wend")) - t->kind = tokwend; - else if (!strcmp(token, "gosub")) - t->kind = tokgosub; - else if (!strcmp(token, "return")) - t->kind = tokreturn; - else if (!strcmp(token, "read")) - t->kind = tokread; - else if (!strcmp(token, "data")) - t->kind = tokdata; - else if (!strcmp(token, "restore")) - t->kind = tokrestore; - else if (!strcmp(token, "gotoxy")) - t->kind = tokgotoxy; - else if (!strcmp(token, "on")) - t->kind = tokon; - else if (!strcmp(token, "dim")) - t->kind = tokdim; - else if (!strcmp(token, "poke")) - t->kind = tokpoke; - else if (!strcmp(token, "list")) - t->kind = toklist; - else if (!strcmp(token, "run")) - t->kind = tokrun; - else if (!strcmp(token, "new")) - t->kind = toknew; - else if (!strcmp(token, "load")) - t->kind = tokload; - else if (!strcmp(token, "merge")) - t->kind = tokmerge; - else if (!strcmp(token, "save")) - t->kind = toksave; - else if (!strcmp(token, "bye")) - t->kind = tokbye; - else if (!strcmp(token, "quit")) - t->kind = tokbye; - else if (!strcmp(token, "del")) - t->kind = tokdel; - else if (!strcmp(token, "renum")) - t->kind = tokrenum; - else if (!strcmp(token, "then")) - t->kind = tokthen; - else if (!strcmp(token, "else")) - t->kind = tokelse; - else if (!strcmp(token, "to")) - t->kind = tokto; - else if (!strcmp(token, "step")) - t->kind = tokstep; - /* - * dlp: added functions - */ - else if (!strcmp(token, "tc")) - t->kind = toktc; - else if (!strcmp(token, "tk")) - t->kind = toktk; - else if (!strcmp(token, "time")) - t->kind = toktime; - else if (!strcmp(token, "sim_time")) - t->kind = toksim_time; - else if (!strcmp(token, "total_time")) - t->kind = toktotal_time; - else if (!strcmp(token, "m0")) - t->kind = tokm0; - else if (!strcmp(token, "m")) - t->kind = tokm; - else if (!strcmp(token, "parm")) - t->kind = tokparm; - else if (!strcmp(token, "act")) - t->kind = tokact; - else if (!strcmp(token, "change_por")) - t->kind = tokchange_por; - else if (!strcmp(token, "get_por")) - t->kind = tokget_por; - else if (!strcmp(token, "change_surf")) - t->kind = tokchange_surf; - else if (!strcmp(token, "porevolume")) - t->kind = tokporevolume; - else if (!strcmp(token, "edl")) - t->kind = tokedl; - else if (!strcmp(token, "surf")) - t->kind = toksurf; - else if (!strcmp(token, "equi")) - t->kind = tokequi; - else if (!strcmp(token, "kin")) - t->kind = tokkin; - else if (!strcmp(token, "gas")) - t->kind = tokgas; - else if (!strcmp(token, "s_s")) - t->kind = toks_s; - else if (!strcmp(token, "misc1")) - t->kind = tokmisc1; - else if (!strcmp(token, "misc2")) - t->kind = tokmisc2; - else if (!strcmp(token, "mu")) - t->kind = tokmu; - else if (!strcmp(token, "osmotic")) - t->kind = tokosmotic; - else if (!strcmp(token, "alk")) - t->kind = tokalk; - else if (!strcmp(token, "lk_species")) - t->kind = toklk_species; - else if (!strcmp(token, "lk_named")) - t->kind = toklk_named; - else if (!strcmp(token, "lk_phase")) - t->kind = toklk_phase; - else if (!strcmp(token, "sum_species")) - t->kind = toksum_species; - else if (!strcmp(token, "sum_gas")) - t->kind = toksum_gas; - else if (!strcmp(token, "sum_s_s")) - t->kind = toksum_s_s; - else if (!strcmp(token, "calc_value")) - t->kind = tokcalc_value; - else if (!strcmp(token, "description")) - t->kind = tokdescription; - else if (!strcmp(token, "sys")) - t->kind = toksys; - else if (!strcmp(token, "instr")) - t->kind = tokinstr; - else if (!strcmp(token, "ltrim")) - t->kind = tokltrim; - else if (!strcmp(token, "rtrim")) - t->kind = tokrtrim; - else if (!strcmp(token, "trim")) - t->kind = toktrim; - else if (!strcmp(token, "pad")) - t->kind = tokpad; - else if (!strcmp(token, "rxn")) - t->kind = tokrxn; - else if (!strcmp(token, "dist")) - t->kind = tokdist; - else if (!strcmp(token, "mol")) - t->kind = tokmol; - else if (!strcmp(token, "la")) - t->kind = tokla; - else if (!strcmp(token, "lm")) - t->kind = toklm; - else if (!strcmp(token, "sr")) - t->kind = toksr; - else if (!strcmp(token, "step_no")) - t->kind = tokstep_no; - else if (!strcmp(token, "cell_no")) - t->kind = tokcell_no; - else if (!strcmp(token, "sim_no")) - t->kind = toksim_no; - else if (!strcmp(token, "si")) - t->kind = toksi; - else if (!strcmp(token, "tot")) - t->kind = toktot; - else if (!strcmp(token, "totmole")) - t->kind = toktotmole; - else if (!strcmp(token, "totmol")) - t->kind = toktotmole; - else if (!strcmp(token, "totmoles")) - t->kind = toktotmole; - else if (!strcmp(token, "log10")) - t->kind = toklog10; - else if (!strcmp(token, "put")) - t->kind = tokput; - else if (!strcmp(token, "get")) - t->kind = tokget; - else if (!strcmp(token, "exists")) - t->kind = tokexists; - else if (!strcmp(token, "charge_balance")) - t->kind = tokcharge_balance; - else if (!strcmp(token, "percent_error")) - t->kind = tokpercent_error; - else if (!strcmp(token, "SC")) - t->kind = tokspcond; - else if (!strcmp(token, "rem")) - { - t->kind = tokrem; - m = strlen(l_inbuf) + 1; - if (m < 256) - m = 256; - t->UU.sp = (char *) PHRQ_malloc(m); - if (t->UU.sp == NULL) - PhreeqcPtr->malloc_error(); - sprintf(t->UU.sp, "%.*s", - (int) (strlen(l_inbuf) - i + 1), - l_inbuf + i - 1); - i = strlen(l_inbuf) + 1; - } -#endif - } - else - { - t->kind = tokvar; - v = varbase; - while (v != NULL && strcmp(v->name, token)) - v = v->next; - if (v == NULL) - { - v = (varrec *) PHRQ_calloc(1, sizeof(varrec)); - if (v == NULL) - PhreeqcPtr->malloc_error(); - v->UU.U0.arr = NULL; - v->next = varbase; - varbase = v; - strcpy(v->name, token); - v->numdims = 0; - if (token[strlen(token) - 1] == '$') - { - v->stringvar = true; - v->UU.U1.sv = NULL; - v->UU.U1.sval = &v->UU.U1.sv; - } - else - { - v->stringvar = false; - v->UU.U0.rv = 0.0; - v->UU.U0.val = &v->UU.U0.rv; - } - } - t->UU.vp = v; - } - } - else if (isdigit((int) ch) || ch == '.') - { - t->kind = toknum; - i--; - t->UU.num = strtod(&l_inbuf[i - 1], &ptr); - if (&l_inbuf[i - 1] == ptr) - { - /* - Note: the following causes an infinite loop: - X = ..9 - */ - t->kind = toksnerr; - t->UU.snch = ch; - i++; - break; - } - i += (int) (ptr - &l_inbuf[i - 1]); - } - else - { - t->kind = toksnerr; - t->UU.snch = ch; - } - break; - } - } - } - while (i <= (int) strlen(l_inbuf)); - if (q) { - sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); - } - if (lp > 0) { - sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); - } - else if (lp < 0) { - sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); - } -} - -#undef toklength - - - - void QBasic:: -listtokens(FILE * f, tokenrec * l_buf) -{ - boolean ltr; - char STR1[256] = {0}; - char *string; - ltr = false; - while (l_buf != NULL) - { - if ((l_buf->kind >= (long) toknot && l_buf->kind <= (long) tokrenum) || - l_buf->kind == (long) toknum || l_buf->kind == (long) tokvar || - l_buf->kind >= (long) toktc) - { - if (ltr) - /*putc(' ', f); */ - output_temp_msg(" "); - ltr = (boolean) (l_buf->kind != toknot); - } - else - ltr = false; - switch (l_buf->kind) - { - - case tokvar: - /*fputs(l_buf->UU.vp->name, f); */ - PhreeqcPtr->output_temp_msg(PhreeqcPtr->sformatf("%s", l_buf->UU.vp->name)); - break; - - case toknum: - /*fputs(numtostr(STR1, l_buf->UU.num), f); */ - string = numtostr(STR1, l_buf->UU.num); - PhreeqcPtr->string_trim(string); - output_temp_msg(PhreeqcPtr->sformatf("%s", string)); - break; - - case tokstr: - output_temp_msg(PhreeqcPtr->sformatf("\"%s\"", l_buf->UU.sp)); - break; - - case toksnerr: - output_temp_msg(PhreeqcPtr->sformatf("{%c}", l_buf->UU.snch)); - break; - - case tokplus: - /*putc('+', f); */ - output_temp_msg("+"); - break; - - case tokminus: - /*putc('-', f); */ - output_temp_msg("-"); - break; - - case toktimes: - /*putc('*', f); */ - output_temp_msg("*"); - break; - - case tokdiv: - /*putc('/', f); */ - output_temp_msg("/"); - break; - - case tokup: - /*putc('^', f); */ - output_temp_msg("^"); - break; - - case toklp: - /*putc('(', f); */ - output_temp_msg("("); - break; - - case tokrp: - /*putc(')', f); */ - output_temp_msg(")"); - break; - - case tokcomma: - /*putc(',', f); */ - output_temp_msg(","); - break; - - case toksemi: - /*putc(';', f); */ - output_temp_msg(";"); - break; - - case tokcolon: - output_temp_msg(" : "); - break; - - case tokeq: - output_temp_msg(" = "); - break; - - case toklt: - output_temp_msg(" < "); - break; - - case tokgt: - output_temp_msg(" > "); - break; - - case tokle: - output_temp_msg(" <= "); - break; - - case tokge: - output_temp_msg(" >= "); - break; - - case tokne: - output_temp_msg(" <> "); - break; - - case tokand: - output_temp_msg(" AND "); - break; - - case tokor: - output_temp_msg(" OR "); - break; - - case tokxor: - output_temp_msg(" XOR "); - break; - - case tokmod: - output_temp_msg(" MOD "); - break; - - case toknot: - output_temp_msg("NOT "); - break; - - case toksqr: - output_temp_msg("SQR"); - break; - - case toksqrt: - output_temp_msg("SQRT"); - break; - - case tokceil: - output_temp_msg("CEIL"); - break; - - case tokfloor: - output_temp_msg("FLOOR"); - break; - - case toksin: - output_temp_msg("SIN"); - break; - - case tokcos: - output_temp_msg("COS"); - break; - - case toktan: - output_temp_msg("TAN"); - break; - - case tokarctan: - output_temp_msg("ARCTAN"); - break; - - case toklog: - output_temp_msg("LOG"); - break; - - case tokexp: - output_temp_msg("EXP"); - break; - - case tokabs: - output_temp_msg("ABS"); - break; - - case toksgn: - output_temp_msg("SGN"); - break; - - case tokstr_: - output_temp_msg("STR$"); - break; - - case tokval: - output_temp_msg("VAL"); - break; - - case tokchr_: - output_temp_msg("CHR$"); - break; - - case tokeol_: - output_temp_msg("EOL$"); - break; - - case tokasc: - output_temp_msg("ASC"); - break; - - case toklen: - output_temp_msg("LEN"); - break; - - case tokmid_: - output_temp_msg("MID$"); - break; - - case tokpeek: - output_temp_msg("PEEK"); - break; - - case tokrem: - output_temp_msg(PhreeqcPtr->sformatf("REM%s", l_buf->UU.sp)); - break; - - case toklet: - output_temp_msg("LET"); - break; - - case tokprint: - output_temp_msg("PRINT"); - break; - - case tokinput: - output_temp_msg("INPUT"); - break; - - case tokgoto: - output_temp_msg("GOTO"); - break; - - case tokif: - output_temp_msg("IF"); - break; - - case tokend: - output_temp_msg("END"); - break; - - case tokstop: - output_temp_msg("STOP"); - break; - - case tokfor: - output_temp_msg("FOR"); - break; - - case toknext: - output_temp_msg("NEXT"); - break; - - case tokwhile: - output_temp_msg("WHILE"); - break; - - case tokwend: - output_temp_msg("WEND"); - break; - - case tokgosub: - output_temp_msg("GOSUB"); - break; - - case tokreturn: - output_temp_msg("RETURN"); - break; - - case tokread: - output_temp_msg("READ"); - break; - - case tokdata: - output_temp_msg("DATA"); - break; - - case tokrestore: - output_temp_msg("RESTORE"); - break; - - case tokgotoxy: - output_temp_msg("GOTOXY"); - break; - - case tokon: - output_temp_msg("ON"); - break; - - case tokdim: - output_temp_msg("DIM"); - break; - - case tokpoke: - output_temp_msg("POKE"); - break; - - case toklist: - output_temp_msg("LIST"); - break; - - case tokrun: - output_temp_msg("RUN"); - break; - - case toknew: - output_temp_msg("NEW"); - break; - - case tokload: - output_temp_msg("LOAD"); - break; - - case tokmerge: - output_temp_msg("MERGE"); - break; - - case toksave: - output_temp_msg("SAVE"); - break; - - case tokbye: - output_temp_msg("BYE"); - break; - - case tokdel: - output_temp_msg("DEL"); - break; - - case tokrenum: - output_temp_msg("RENUM"); - break; - - case tokthen: - output_temp_msg(" THEN "); - break; - - case tokelse: - output_temp_msg(" ELSE "); - break; - - case tokto: - output_temp_msg(" TO "); - break; - - case tokstep: - output_temp_msg(" STEP "); - break; - - case toktc: - output_temp_msg("TC"); - break; - - case tokm0: - output_temp_msg("M0"); - break; - - case tokm: - output_temp_msg("M"); - break; - - case tokparm: - output_temp_msg("PARM"); - break; - - case tokact: - output_temp_msg("ACT"); - break; - - case tokchange_por: - output_temp_msg("CHANGE_POR"); - break; - - case tokget_por: - output_temp_msg("GET_POR"); - break; - - case tokchange_surf: - output_temp_msg("CHANGE_SURF"); - break; - - case tokporevolume: - output_temp_msg("POREVOLUME"); - break; - - case tokmol: - output_temp_msg("MOL"); - break; - - case tokla: - output_temp_msg("LA"); - break; - - case toklm: - output_temp_msg("LM"); - break; - - case toksr: - output_temp_msg("SR"); - break; - - case toksi: - output_temp_msg("SI"); - break; - - case toktot: - output_temp_msg("TOT"); - break; - - case toktotmole: - case toktotmol: - case toktotmoles: - output_temp_msg("TOTMOLE"); - break; - - case toktk: - output_temp_msg("TK"); - break; - - case toktime: - output_temp_msg("TIME"); - break; - - case toklog10: - output_temp_msg("LOG10"); - break; - - case toksim_time: - output_temp_msg("SIM_TIME"); - break; - - case tokequi: - output_temp_msg("EQUI"); - break; - - case tokgas: - output_temp_msg("GAS"); - break; - - case tokpunch: - output_temp_msg("PUNCH"); - break; - - case tokkin: - output_temp_msg("KIN"); - break; - - case toks_s: - output_temp_msg("S_S"); - break; - - case tokmu: - output_temp_msg("MU"); - break; - - case tokosmotic: - output_temp_msg("OSMOTIC"); - break; - - case tokalk: - output_temp_msg("ALK"); - break; - - case toklk_species: - output_temp_msg("LK_SPECIES"); - break; - - case toklk_named: - output_temp_msg("LK_NAMED"); - break; - - case toklk_phase: - output_temp_msg("LK_PHASE"); - break; - - case toksum_species: - output_temp_msg("SUM_SPECIES"); - break; - - case toksum_gas: - output_temp_msg("SUM_GAS"); - break; - - case toksum_s_s: - output_temp_msg("SUM_s_s"); - break; - - case tokcalc_value: - output_temp_msg("CALC_VALUE"); - break; - - case tokdescription: - output_temp_msg("DESCRIPTION"); - break; - - case toksys: - output_temp_msg("SYS"); - break; - - case tokinstr: - output_temp_msg("INSTR"); - break; - - case tokltrim: - output_temp_msg("LTRIM"); - break; - - case tokrtrim: - output_temp_msg("RTRIM"); - break; - - case toktrim: - output_temp_msg("TRIM"); - break; - - case tokpad: - output_temp_msg("PAD"); - break; - - case tokrxn: - output_temp_msg("RXN"); - break; - - case tokdist: - output_temp_msg("DIST"); - break; - - case tokmisc1: - output_temp_msg("MISC1"); - break; - - case tokmisc2: - output_temp_msg("MISC2"); - break; - - case tokedl: - output_temp_msg("EDL"); - break; - - case toksurf: - output_temp_msg("SURF"); - break; - - case tokstep_no: - output_temp_msg("STEP_NO"); - break; - - case toksim_no: - output_temp_msg("SIM_NO"); - break; - - case toktotal_time: - output_temp_msg("TOTAL_TIME"); - break; - - case tokput: - output_temp_msg("PUT"); - break; - - case tokget: - output_temp_msg("GET"); - break; - - case tokcharge_balance: - output_temp_msg("CHARGE_BALANCE"); - break; - - case tokpercent_error: - output_temp_msg("PERCENT_ERROR"); - break; - -#if defined PHREEQ98 || defined MULTICHART - case tokgraph_x: - output_temp_msg("GRAPH_X"); - break; - - case tokgraph_y: - output_temp_msg("GRAPH_Y"); - break; - - case tokgraph_sy: - output_temp_msg("GRAPH_SY"); - break; -#endif - -#if defined MULTICHART - case tokplot_xy: - output_temp_msg("PLOT_XY"); - break; -#endif - - case tokcell_no: - output_temp_msg("CELL_NO"); - break; - - case tokexists: - output_temp_msg("EXISTS"); - break; - - case toksc: - output_temp_msg("SC"); - break; - - case tokgamma: - output_temp_msg("GAMMA"); - break; - - case toklg: - output_temp_msg("LG"); - break; - -/* VP: Density Start */ - case tokrho: - output_temp_msg("RHO"); - break; -/* VP: Density End */ - case tokcell_volume: - output_temp_msg("CELL_VOLUME"); - break; - case tokcell_pore_volume: - output_temp_msg("CELL_PORE_VOLUME"); - break; - case tokcell_porosity: - output_temp_msg("CELL_POROSITY"); - break; - case tokcell_saturation: - output_temp_msg("CELL_SATURATION"); - break; - case tokiso: - output_temp_msg("ISO"); - break; - case tokiso_unit: - output_temp_msg("ISO_UNIT"); - break; - case tokphase_formula: - output_temp_msg("PHASE_FORMULA"); - break; - case toklist_s_s: - output_temp_msg("LIST_S_S"); - break; - } - l_buf = l_buf->next; - } -} - - - - void QBasic:: -disposetokens(tokenrec ** tok) -{ - tokenrec *tok1; - - while (*tok != NULL) - { - tok1 = (*tok)->next; - if ((*tok)->kind == (long) tokrem || (*tok)->kind == (long) tokstr) - { - (*tok)->UU.sp = (char *) PhreeqcPtr->free_check_null((*tok)->UU.sp); - } - *tok = (tokenrec *) PhreeqcPtr->free_check_null(*tok); - *tok = tok1; - } -} - - - - void QBasic:: -parseinput(tokenrec ** l_buf) -{ - linerec *l, *l0, *l1; - - while (PhreeqcPtr->replace("\t", " ", inbuf)); - while (PhreeqcPtr->replace("\r", " ", inbuf)); - PhreeqcPtr->string_trim(inbuf); - curline = 0; - while (*inbuf != '\0' && isdigit((int) inbuf[0])) - { - curline = curline * 10 + inbuf[0] - 48; - memmove(inbuf, inbuf + 1, strlen(inbuf)); - } - parse(inbuf, l_buf); - if (curline == 0) - return; - l = linebase; - l0 = NULL; - while (l != NULL && l->num < curline) - { - l0 = l; - l = l->next; - } - if (l != NULL && l->num == curline) - { - l1 = l; - l = l->next; - if (l0 == NULL) - linebase = l; - else - l0->next = l; - disposetokens(&l1->txt); - PHRQ_free(l1); - } - if (*l_buf != NULL) - { - l1 = (linerec *) PHRQ_calloc(1, sizeof(linerec)); - if (l1 == NULL) - PhreeqcPtr->malloc_error(); - l1->next = l; - if (l0 == NULL) - linebase = l1; - else - l0->next = l1; - l1->num = curline; - l1->txt = *l_buf; - strncpy(l1->inbuf, inbuf, MAX_LINE); - l1->inbuf[MAX_LINE-1] = '\0'; - } - clearloops(); - restoredata(); -} - - void QBasic:: -errormsg(const char * l_s) -{ - error_msg(l_s, CONTINUE); - _Escape(42); -} - - - void QBasic:: -snerr(const char * l_s) -{ - char str[MAX_LENGTH] = {0}; - strcpy(str, "Syntax_error "); - errormsg(strcat(str, l_s)); -} - - - void QBasic:: -tmerr(const char * l_s) -{ - char str[MAX_LENGTH] = {0}; - strcpy(str, "Type mismatch error"); - errormsg(strcat(str, l_s)); -} - - - void QBasic:: -badsubscr(void) -{ - errormsg("Bad subscript"); -} - - - LDBLE QBasic:: -realfactor(struct LOC_exec *LINK) -{ - valrec n; - - n = factor(LINK); - if (n.stringval) - tmerr(": found characters, not a number"); - return (n.UU.val); -} - - char * QBasic:: -strfactor(struct LOC_exec * LINK) -{ - valrec n; - - n = factor(LINK); - if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); - return (n.UU.sval); -} - - char * QBasic:: -stringfactor(char * Result, struct LOC_exec * LINK) -{ - valrec n; - - n = factor(LINK); - if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); - strcpy(Result, n.UU.sval); - PHRQ_free(n.UU.sval); - return Result; -} - - long QBasic:: -intfactor(struct LOC_exec *LINK) -{ - return ((long) floor(realfactor(LINK) + 0.5)); -} - - LDBLE QBasic:: -realexpr(struct LOC_exec *LINK) -{ - valrec n; - - n = expr(LINK); - if (n.stringval) - tmerr(": found characters, not a number"); - return (n.UU.val); -} - - char * QBasic:: -strexpr(struct LOC_exec * LINK) -{ - valrec n; - - n = expr(LINK); - if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); - return (n.UU.sval); -} - - char * QBasic:: -stringexpr(char * Result, struct LOC_exec * LINK) -{ - valrec n; - - n = expr(LINK); - if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); - strcpy(Result, n.UU.sval); - PHRQ_free(n.UU.sval); - return Result; -} - - long QBasic:: -intexpr(struct LOC_exec *LINK) -{ - return ((long) floor(realexpr(LINK) + 0.5)); -} - - - void QBasic:: -require(int k, struct LOC_exec *LINK) -{ - char str[MAX_LENGTH] = {0}; - int i; - if (LINK->t == NULL || LINK->t->kind != k) - { - for (i = 0; i < NCMDS; i++) - { - if (command[i].keycount == k) - break; - } - if (i == NCMDS) - snerr(": missing unknown command"); - else { - strcpy(str, ": missing "); - snerr(strcat(str, command[i].name)); - } - } - LINK->t = LINK->t->next; -} - - - void QBasic:: -skipparen(struct LOC_exec *LINK) -{ - do - { - if (LINK->t == NULL) - snerr(": parenthesis missing"); - if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) - goto _L1; - if (LINK->t->kind == toklp) - { - LINK->t = LINK->t->next; - skipparen(LINK); - } - LINK->t = LINK->t->next; - } - while (true); - _L1:; -} - - -QBasic::varrec * QBasic:: -findvar(struct LOC_exec *LINK) -{ - QBasic::varrec *v; - long i, j, k; - tokenrec *tok; - long FORLIM; - - if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(": can't find variable"); - v = LINK->t->UU.vp; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != toklp) - { - if (v->numdims != 0) - badsubscr(); - return v; - } - if (v->numdims == 0) - { - tok = LINK->t; - i = 0; - j = 1; - do - { - if (i >= maxdims) - badsubscr(); - LINK->t = LINK->t->next; - skipparen(LINK); - j *= 11; - i++; - v->dims[i - 1] = 11; - } - while (LINK->t->kind != tokrp); - v->numdims = (char) i; - if (v->stringvar) - { - v->UU.U1.sarr = (char **) PHRQ_malloc(j * sizeof(char *)); - if (v->UU.U1.sarr == NULL) - PhreeqcPtr->malloc_error(); - for (k = 0; k < j; k++) - v->UU.U1.sarr[k] = NULL; - } - else - { - v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); - if (v->UU.U0.arr == NULL) - PhreeqcPtr->malloc_error(); - for (k = 0; k < j; k++) - v->UU.U0.arr[k] = 0.0; - } - LINK->t = tok; - } - k = 0; - LINK->t = LINK->t->next; - FORLIM = v->numdims; - for (i = 1; i <= FORLIM; i++) - { - j = intexpr(LINK); - if ((unsigned long) j >= (unsigned long) v->dims[i - 1]) - badsubscr(); - k = k * v->dims[i - 1] + j; - if (i < v->numdims) - require(tokcomma, LINK); - } - require(tokrp, LINK); - if (v->stringvar) - v->UU.U1.sval = &v->UU.U1.sarr[k]; - else - v->UU.U0.val = &v->UU.U0.arr[k]; - return v; -} - - -QBasic::valrec QBasic:: -factor(struct LOC_exec * LINK) -{ - char string[MAX_LENGTH] = {0}; - struct solution *soln_ptr; - int nn; - varrec *v; - tokenrec *facttok; - valrec n; - long i, j, m; - tokenrec *tok, *tok1; - char *l_s; - LDBLE l_dummy; - int i_rate; - union - { - long i; - char *c; - } trick; - struct save_values s_v, *s_v_ptr; - int k; - LDBLE TEMP; - char STR1[256] = {0}, STR2[256] = {0}; - char *elt_name, *surface_name, *mytemplate, *name; - varrec *count_varrec = NULL, *names_varrec = NULL, *types_varrec = - NULL, *moles_varrec = NULL; - char **names_arg, **types_arg; - LDBLE *moles_arg; - int arg_num; - LDBLE count_species; - char *ptr, *string1, *string2; - - if (LINK->t == NULL) - snerr(": missing variable or command"); - facttok = LINK->t; - LINK->t = LINK->t->next; - n.stringval = false; - s_v.count_subscripts = 0; - /*s_v.subscripts = (int *) PHRQ_malloc (sizeof (int)); */ - s_v.subscripts = NULL; - switch (facttok->kind) - { - - case toknum: - n.UU.val = facttok->UU.num; - break; - - case tokstr: - n.stringval = true; - m = (int) strlen(facttok->UU.sp) + 1; - if (m < 256) - m = 256; - n.UU.sval = (char *) PHRQ_calloc(m, sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - strcpy(n.UU.sval, facttok->UU.sp); - break; - - case tokvar: - LINK->t = facttok; - v = findvar(LINK); - n.stringval = v->stringvar; - if (n.stringval) - { - if (*v->UU.U1.sval != NULL) - { - m = (int) strlen(*v->UU.U1.sval) + 1; - if (m < 256) - m = 256; - } - else - { - m = 256; - } - n.UU.sval = (char *) PHRQ_calloc(m, sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - if (*v->UU.U1.sval != NULL) - { - strcpy(n.UU.sval, *v->UU.U1.sval); - } - - } - else - n.UU.val = *v->UU.U0.val; - break; - - case toklp: - n = expr(LINK); - require(tokrp, LINK); - break; - - case tokminus: - n.UU.val = -realfactor(LINK); - break; - - case tokplus: - n.UU.val = realfactor(LINK); - break; - - case toknot: - n.UU.val = ~intfactor(LINK); - break; - - case toksqr: - TEMP = realfactor(LINK); - n.UU.val = TEMP * TEMP; - break; - - case toksqrt: - n.UU.val = sqrt(realfactor(LINK)); - break; - - case tokceil: - n.UU.val = ceil(realfactor(LINK)); - break; - - case tokfloor: - n.UU.val = floor(realfactor(LINK)); - break; - - case toktc: - n.UU.val = PhreeqcPtr->tc_x; - break; - - case toktk: - n.UU.val = PhreeqcPtr->tc_x + 273.15; - break; - - case toktime: - n.UU.val = PhreeqcPtr->rate_time; - break; - - case toksim_time: - if (PhreeqcPtr->use.kinetics_in == FALSE) - { - if (PhreeqcPtr->state == PHAST) - { - n.UU.val = PhreeqcPtr->rate_sim_time; - } - else if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->transport_step * PhreeqcPtr->timest; - } - else if (PhreeqcPtr->state == ADVECTION) - { - if (PhreeqcPtr->advection_kin_time_defined == TRUE) - { - n.UU.val = PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; - } - else - { - n.UU.val = PhreeqcPtr->advection_step; - } - } - else - { - n.UU.val = 0; - } - } - else - { - n.UU.val = PhreeqcPtr->rate_sim_time; - } - break; - - case toktotal_time: - if (PhreeqcPtr->use.kinetics_in == FALSE) - { - if (PhreeqcPtr->state == PHAST) - { - n.UU.val = PhreeqcPtr->rate_sim_time_end; - } - else if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->transport_step * PhreeqcPtr->timest; - } - else if (PhreeqcPtr->state == ADVECTION) - { - n.UU.val = - PhreeqcPtr->initial_total_time + PhreeqcPtr->advection_step * PhreeqcPtr->advection_kin_time; - } - else - { - n.UU.val = 0; - } - } - else - { - n.UU.val = PhreeqcPtr->initial_total_time + PhreeqcPtr->rate_sim_time; - } - break; - - case tokm0: - n.UU.val = PhreeqcPtr->rate_m0; - break; - - case tokm: - n.UU.val = PhreeqcPtr->rate_m; - break; - - case tokparm: - i_rate = intfactor(LINK); - if (i_rate > PhreeqcPtr->count_rate_p || i_rate == 0) - { - errormsg("Parameter subscript out of range."); - } - n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; - break; - - case tokact: - n.UU.val = PhreeqcPtr->activity(stringfactor(STR1, LINK)); - break; - - case tokgamma: - n.UU.val = PhreeqcPtr->activity_coefficient(stringfactor(STR1, LINK)); - break; - - case toklg: - n.UU.val = PhreeqcPtr->log_activity_coefficient(stringfactor(STR1, LINK)); - break; - - case tokget_por: - i = intfactor(LINK); - if (PhreeqcPtr->phast != TRUE) - { - if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 - || i == PhreeqcPtr->count_cells + 1) - { - /* warning_msg("Note... no porosity for boundary solutions."); */ - n.UU.val = 0; - break; - } - else - n.UU.val = PhreeqcPtr->cell_data[i - 1].por; - break; - } - else - { - n.UU.val = PhreeqcPtr->cell_porosity; - break; - } - - case tokedl: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - surface_name = stringfactor(STR2, LINK); - } - else - { - surface_name = NULL; - } - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->diff_layer_total(elt_name, surface_name); - break; - - case toksurf: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - surface_name = stringfactor(STR2, LINK); - } - else - { - surface_name = NULL; - } - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->surf_total(elt_name, surface_name); - break; - - case tokequi: - n.UU.val = PhreeqcPtr->equi_phase(stringfactor(STR1, LINK)); - break; - - case tokkin: - n.UU.val = PhreeqcPtr->kinetics_moles(stringfactor(STR1, LINK)); - break; - - case tokgas: - n.UU.val = PhreeqcPtr->find_gas_comp(stringfactor(STR1, LINK)); - break; - - case toks_s: - n.UU.val = PhreeqcPtr->find_s_s_comp(stringfactor(STR1, LINK)); - break; - - case tokmisc1: - n.UU.val = PhreeqcPtr->find_misc1(stringfactor(STR1, LINK)); - break; - - case tokmisc2: - n.UU.val = PhreeqcPtr->find_misc2(stringfactor(STR1, LINK)); - break; - - case tokmu: - n.UU.val = PhreeqcPtr->mu_x; - break; - - case tokosmotic: - if (PhreeqcPtr->pitzer_model == TRUE || PhreeqcPtr->sit_model == TRUE) - { - n.UU.val = PhreeqcPtr->COSMOT; - } - else - { - n.UU.val = 0.0; - } - break; - - case tokalk: - n.UU.val = PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; - break; - - case toklk_species: - n.UU.val = PhreeqcPtr->calc_logk_s(stringfactor(STR1, LINK)); - break; - - case toklk_named: - n.UU.val = PhreeqcPtr->calc_logk_n(stringfactor(STR1, LINK)); - break; - - case toklk_phase: - n.UU.val = PhreeqcPtr->calc_logk_p(stringfactor(STR1, LINK)); - break; - - case toksum_species: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } - else - { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_species(mytemplate, elt_name); - break; - - case toksum_gas: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } - else - { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_gases(mytemplate, elt_name); - break; - - case toksum_s_s: - require(toklp, LINK); - mytemplate = stringfactor(STR1, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - elt_name = stringfactor(STR2, LINK); - } - else - { - elt_name = NULL; - } - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); - break; - - case tokcalc_value: - require(toklp, LINK); - name = stringfactor(STR1, LINK); - require(tokrp, LINK); - n.UU.val = PhreeqcPtr->get_calculate_value(name); - break; - - case tokdescription: - n.stringval = true; - if (PhreeqcPtr->state == REACTION) - { - if (PhreeqcPtr->use.mix_in == TRUE) - { - sprintf(string, "Mix %d", PhreeqcPtr->use.n_mix_user); - n.UU.sval = PhreeqcPtr->string_duplicate(string); - } - else - { - soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.n_solution_user, &nn, TRUE); - if (soln_ptr != NULL) - { - n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->description); - } - else - { - n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); - } - } - } - else if (PhreeqcPtr->state == ADVECTION || PhreeqcPtr->state == TRANSPORT || PhreeqcPtr->state == PHAST) - { - sprintf(string, "Cell %d", PhreeqcPtr->cell_no); - n.UU.sval = PhreeqcPtr->string_duplicate(string); - } - else - { - if (PhreeqcPtr->use.solution_ptr != NULL) - { - n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.solution_ptr->description); - } - else - { - n.UU.sval = PhreeqcPtr->string_duplicate("Unknown"); - } - } - while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); - break; - - case tokinstr: - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokcomma, LINK); - string2 = stringfactor(STR2, LINK); - require(tokrp, LINK); - ptr = strstr(string1, string2); - if (ptr == NULL) - { - n.UU.val = 0; - } - else - { - n.UU.val = ((LDBLE) (ptr - string1)) + 1; - } - break; - - case tokltrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - PhreeqcPtr->string_trim_left(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); - break; - - case tokrtrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - PhreeqcPtr->string_trim_right(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); - break; - - case toktrim: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - PhreeqcPtr->string_trim(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); - break; - - case tokiso: - n.UU.val = PhreeqcPtr->iso_value(stringfactor(STR1, LINK)); - break; - - case tokiso_unit: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokrp, LINK); - PhreeqcPtr->string_trim(string1); - n.UU.sval = PhreeqcPtr->iso_unit(string1); - break; - - case tokpad: - n.stringval = true; - require(toklp, LINK); - string1 = stringfactor(STR1, LINK); - require(tokcomma, LINK); - i = intexpr(LINK); - require(tokrp, LINK); - n.UU.sval = PhreeqcPtr->string_pad(string1, i); - break; - - case toksys: - require(toklp, LINK); - elt_name = stringfactor(STR1, LINK); - /* - * Parse arguments - */ - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - /*int c; */ - /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ - /* return number of species */ - LINK->t = LINK->t->next; - count_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) - snerr(": can't find variable"); - - /* return number of names of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - names_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) - snerr(": can't find name of species"); - - /* return number of types of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - types_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || types_varrec->stringvar != 1) - snerr(": can't find type of species"); - - /* return number of moles of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - moles_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) - snerr(": can't find moles of species"); - LINK->t = LINK->t->next; - arg_num = 4; - } - else - { - arg_num = 1; - } - require(tokrp, LINK); - - if (arg_num > 1) - { - free_dim_stringvar(names_varrec); - free_dim_stringvar(types_varrec); - PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); - moles_varrec->UU.U0.arr = NULL; - } - /* - * Call subroutine - */ - /* - n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); - */ - n.UU.val = - PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), - &(types_arg), &(moles_arg)); - - /* - * fill in varrec structure - */ - if (arg_num > 1) - { - *count_varrec->UU.U0.val = count_species; - names_varrec->UU.U1.sarr = names_arg; - types_varrec->UU.U1.sarr = types_arg; - moles_varrec->UU.U0.arr = moles_arg; - - for (i = 0; i < maxdims; i++) - { - names_varrec->dims[i] = 0; - types_varrec->dims[i] = 0; - moles_varrec->dims[i] = 0; - } - names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - types_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; - names_varrec->numdims = 1; - types_varrec->numdims = 1; - moles_varrec->numdims = 1; - } - else - { - for (i = 0; i < count_species + 1; i++) - { - PhreeqcPtr->free_check_null(names_arg[i]); - PhreeqcPtr->free_check_null(types_arg[i]); - } - PhreeqcPtr->free_check_null(names_arg); - PhreeqcPtr->free_check_null(types_arg); - PhreeqcPtr->free_check_null(moles_arg); - } - break; - - case toklist_s_s: - { - /* list_s_s("calcite", count, name$, moles) */ - /* return total moles */ - require(toklp, LINK); - std::string s_s_name(stringfactor(STR1, LINK)); - cxxNameDouble composition; - /* - * Parse arguments - */ - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - count_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) - snerr(": Cannot find count variable"); - - /* return number of names of components */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - names_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) - snerr(": Cannot find component string variable"); - - /* return number of moles of components */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - moles_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) - snerr(": Cannot find moles of component variable"); - LINK->t = LINK->t->next; - arg_num = 4; - } - else - { - snerr(": Expected 4 arguments for list_s_s"); - } - require(tokrp, LINK); - - if (arg_num > 1) - { - free_dim_stringvar(names_varrec); - PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); - moles_varrec->UU.U0.arr = NULL; - } - /* - * Call subroutine - */ - // return total moles - n.UU.val = PhreeqcPtr->list_s_s(s_s_name, composition); - - /* - * fill in varrec structure - */ - - if (arg_num > 1) - { - size_t count = composition.size(); - *count_varrec->UU.U0.val = (LDBLE) count; - /* - * malloc space - */ - names_varrec->UU.U1.sarr = (char **) PHRQ_malloc((count + 1) * sizeof(char *)); - if (names_varrec->UU.U1.sarr == NULL) - PhreeqcPtr->malloc_error(); - moles_varrec->UU.U0.arr = (LDBLE *) PHRQ_malloc((count + 1) * sizeof(LDBLE)); - if (moles_varrec->UU.U0.arr == NULL) - PhreeqcPtr->malloc_error(); - - // first position not used - names_varrec->UU.U1.sarr[0] = NULL; - moles_varrec->UU.U0.arr[0] = 0; - - // set dims for Basic array - for (i = 0; i < maxdims; i++) - { - names_varrec->dims[i] = 0; - moles_varrec->dims[i] = 0; - } - // set dims for first dimension and number of dims - names_varrec->dims[0] = (long) (count + 1); - moles_varrec->dims[0] = (long) (count + 1); - names_varrec->numdims = 1; - moles_varrec->numdims = 1; - - // fill in arrays - i = 1; - - //for (cxxNameDouble::iterator it = composition.begin(); it != composition.end(); it++) - //{ - // names_varrec->UU.U1.sarr[i] = string_duplicate((it->first).c_str()); - // moles_varrec->UU.U0.arr[i] = it->second; - // i++; - //} - - std::vector< std::pair > sort_comp = composition.sort_second(); - size_t j; - for (j = 0; j != sort_comp.size(); j++) - { - names_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate(sort_comp[j].first.c_str()); - moles_varrec->UU.U0.arr[i] = sort_comp[j].second; - i++; - } - - } - break; - } - - case tokphase_formula: - { - require(toklp, LINK); - std::string phase_name(stringfactor(STR1, LINK)); - varrec *elts_varrec = NULL, *coef_varrec = NULL; - cxxNameDouble stoichiometry; - /* - * Parse arguments - */ - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - /* phase_formula("calcite", count, elt, coef) */ - /* return formula */ - /*int c; */ - /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ - /* struct varrec *count_varrec, *elt_varrec, *coef_varrec; */ - /* return number of species */ - LINK->t = LINK->t->next; - count_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) - snerr(": Cannot find count variable"); - - /* return number of names of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - elts_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) - snerr(": Cannot find element string variable"); - - /* return coefficients of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - coef_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) - snerr(": Cannot find coefficient variable"); - LINK->t = LINK->t->next; - arg_num = 4; - } - else - { - arg_num = 1; - } - require(tokrp, LINK); - - if (arg_num > 1) - { - free_dim_stringvar(elts_varrec); - PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); - coef_varrec->UU.U0.arr = NULL; - } - /* - * Call subroutine - */ - std::string form = PhreeqcPtr->phase_formula(phase_name, stoichiometry); - - // put formula as return value - n.stringval = true; - n.UU.sval = PhreeqcPtr->string_duplicate(form.c_str()); - - /* - * fill in varrec structure - */ - - if (arg_num > 1) - { - size_t count = stoichiometry.size(); - *count_varrec->UU.U0.val = (LDBLE) count; - /* - * malloc space - */ - elts_varrec->UU.U1.sarr = (char **) PHRQ_malloc((count + 1) * sizeof(char *)); - if (elts_varrec->UU.U1.sarr == NULL) - PhreeqcPtr->malloc_error(); - coef_varrec->UU.U0.arr = (LDBLE *) PHRQ_malloc((count + 1) * sizeof(LDBLE)); - if (coef_varrec->UU.U0.arr == NULL) - PhreeqcPtr->malloc_error(); - - // first position not used - elts_varrec->UU.U1.sarr[0] = NULL; - coef_varrec->UU.U0.arr[0] = 0; - - // set dims for Basic array - for (i = 0; i < maxdims; i++) - { - elts_varrec->dims[i] = 0; - coef_varrec->dims[i] = 0; - } - // set dims for first dimension and number of dims - elts_varrec->dims[0] = (long) (count + 1); - coef_varrec->dims[0] = (long) (count + 1); - elts_varrec->numdims = 1; - coef_varrec->numdims = 1; - - // fill in arrays - i = 1; - for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) - { - elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); - coef_varrec->UU.U0.arr[i] = it->second; - i++; - } - - } - break; - } - - case tokrxn: - if (PhreeqcPtr->state == REACTION || - PhreeqcPtr->state == ADVECTION || - PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->step_x; - } - else - { - n.UU.val = 0.0; - } - break; - - case tokdist: - if (PhreeqcPtr->state == PHAST) - { - n.UU.val = 0; - } - else if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; - } - else if (PhreeqcPtr->state == ADVECTION) - { - n.UU.val = (LDBLE) PhreeqcPtr->use.n_solution_user; - } - else - { - n.UU.val = 0; - } - break; - - case tokmol: - n.UU.val = PhreeqcPtr->molality(stringfactor(STR1, LINK)); - break; - - case tokla: - n.UU.val = PhreeqcPtr->log_activity(stringfactor(STR1, LINK)); - break; - - case toklm: - n.UU.val = PhreeqcPtr->log_molality(stringfactor(STR1, LINK)); - break; - - case toksr: - n.UU.val = PhreeqcPtr->saturation_ratio(stringfactor(STR1, LINK)); - break; - - case tokstep_no: - if (PhreeqcPtr->state == PHAST) - { - n.UU.val = 0; - } - else if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->transport_step; - } - else if (PhreeqcPtr->state == ADVECTION) - { - n.UU.val = PhreeqcPtr->advection_step; - } - else if (PhreeqcPtr->state == REACTION) - { - n.UU.val = PhreeqcPtr->reaction_step; - } - else - { - n.UU.val = 0; - } - break; - - case tokcell_no: - if (PhreeqcPtr->state == TRANSPORT) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state == PHAST) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state == ADVECTION) - { - n.UU.val = PhreeqcPtr->cell_no; - } - else if (PhreeqcPtr->state < REACTION) - { - n.UU.val = PhreeqcPtr->use.solution_ptr->n_user; - } - else - { - if (PhreeqcPtr->use.mix_in == TRUE) - { - n.UU.val = PhreeqcPtr->use.n_mix_user; - } - else - { - n.UU.val = PhreeqcPtr->use.n_solution_user; - } - } - break; - - case toksim_no: - n.UU.val = PhreeqcPtr->simulation; - break; - - case tokget: - require(toklp, LINK); - - s_v.count_subscripts = 0; - /* get first subscript */ - if (LINK->t != NULL && LINK->t->kind != tokrp) - { - i = intexpr(LINK); - if (s_v.subscripts == NULL) - { - s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - } - s_v.subscripts = - (int *) PHRQ_realloc(s_v.subscripts, - (size_t) (s_v.count_subscripts + - 1) * sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = i; - s_v.count_subscripts++; - } - - /* get other subscripts */ - for (;;) - { - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - j = intexpr(LINK); - if (s_v.subscripts == NULL) - { - s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - } - s_v.subscripts = - (int *) PHRQ_realloc(s_v.subscripts, - (size_t) (s_v.count_subscripts + - 1) * sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = j; - s_v.count_subscripts++; - } - else - { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); - if (s_v_ptr == NULL) - { - n.UU.val = 0; - } - else - { - n.UU.val = s_v_ptr->value; - } - break; - - case tokexists: - require(toklp, LINK); - - s_v.count_subscripts = 0; - /* get first subscript */ - if (LINK->t != NULL && LINK->t->kind != tokrp) - { - i = intexpr(LINK); - if (s_v.subscripts == NULL) - { - s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - } - s_v.subscripts = - (int *) PHRQ_realloc(s_v.subscripts, - (size_t) (s_v.count_subscripts + - 1) * sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = i; - s_v.count_subscripts++; - } - - /* get other subscripts */ - for (;;) - { - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - j = intexpr(LINK); - if (s_v.subscripts == NULL) - { - s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - } - s_v.subscripts = - (int *) PHRQ_realloc(s_v.subscripts, - (size_t) (s_v.count_subscripts + - 1) * sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = j; - s_v.count_subscripts++; - } - else - { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); - if (s_v_ptr == NULL) - { - n.UU.val = 0; - } - else - { - n.UU.val = 1; - } - break; - - case tokcharge_balance: - n.UU.val = PhreeqcPtr->cb_x; - break; - - case tokpercent_error: - n.UU.val = 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; - break; - - case toksi: - PhreeqcPtr->saturation_index(stringfactor(STR1, LINK), &l_dummy, &n.UU.val); - break; - - case toktot: - n.UU.val = PhreeqcPtr->total(stringfactor(STR1, LINK)); - break; - - case toktotmole: - case toktotmol: - case toktotmoles: - n.UU.val = PhreeqcPtr->total_mole(stringfactor(STR1, LINK)); - break; - - case tokcell_pore_volume: - case tokporevolume: - n.UU.val = PhreeqcPtr->cell_pore_volume; - break; - -/* VP : Density Start */ - case tokrho: - n.UU.val = PhreeqcPtr->calc_dens(); - break; -/* VP: Density End */ - case tokcell_volume: - n.UU.val = PhreeqcPtr->cell_volume; - break; - case tokcell_porosity: - n.UU.val = PhreeqcPtr->cell_porosity; - break; - case tokcell_saturation: - n.UU.val = PhreeqcPtr->cell_saturation; - break; - case toksc: - n.UU.val = PhreeqcPtr->calc_SC(); - break; - - case toklog10: - n.UU.val = log10(realfactor(LINK)); - break; - - case toksin: - n.UU.val = sin(realfactor(LINK)); - break; - - case tokcos: - n.UU.val = cos(realfactor(LINK)); - break; - - case toktan: - n.UU.val = realfactor(LINK); - n.UU.val = sin(n.UU.val) / cos(n.UU.val); - break; - - case tokarctan: - n.UU.val = atan(realfactor(LINK)); - break; - - case toklog: - n.UU.val = log(realfactor(LINK)); - break; - - case tokexp: - n.UU.val = exp(realfactor(LINK)); - break; - - case tokabs: - n.UU.val = fabs(realfactor(LINK)); - break; - - case toksgn: - n.UU.val = realfactor(LINK); - n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); - break; - - case tokstr_: - n.stringval = true; - n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - numtostr(n.UU.sval, realfactor(LINK)); - break; - - case tokval: - l_s = strfactor(LINK); - tok1 = LINK->t; - parse(l_s, &LINK->t); - tok = LINK->t; - if (tok == NULL) - n.UU.val = 0.0; - else - n = expr(LINK); - disposetokens(&tok); - LINK->t = tok1; - PHRQ_free(l_s); - break; - - case tokchr_: - n.stringval = true; - n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - strcpy(n.UU.sval, " "); - n.UU.sval[0] = (char) intfactor(LINK); - break; - - case tokeol_: - n.stringval = true; - n.UU.sval = (char *) PHRQ_calloc(256, sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - strcpy(n.UU.sval, "\n"); - break; - - case tokasc: - l_s = strfactor(LINK); - if (*l_s == '\0') - n.UU.val = 0.0; - else - n.UU.val = l_s[0]; - PHRQ_free(l_s); - break; - - case tokmid_: - n.stringval = true; - require(toklp, LINK); - n.UU.sval = strexpr(LINK); - require(tokcomma, LINK); - i = intexpr(LINK); - if (i < 1) - i = 1; - /*j = 255; */ - j = (int) strlen(n.UU.sval); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - j = intexpr(LINK); - } - if (j > (int) strlen(n.UU.sval) - i + 1) - j = (int) strlen(n.UU.sval) - i + 1; - if (i > (int) strlen(n.UU.sval)) - *n.UU.sval = '\0'; - else - { - if (j + 1 > 256) - { - warning_msg("String too long in factor\n"); -/* - STR1 = (char *) PHRQ_realloc (STR1, j + 1); - if (STR1 == NULL) - PhreeqcPtr->malloc_error (); -*/ - } - sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); - strcpy(n.UU.sval, STR1); - } - require(tokrp, LINK); - break; - - case toklen: - l_s = strfactor(LINK); - n.UU.val = (double) strlen(l_s); - PHRQ_free(l_s); - break; - - case tokpeek: -/* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ - trick.i = intfactor(LINK); - n.UU.val = *trick.c; -/* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ - break; - - default: - snerr(": missing \" or ("); - break; - } - s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); - return n; -} - -QBasic::valrec QBasic:: -upexpr(struct LOC_exec * LINK) -{ - valrec n, n2; - - n = factor(LINK); - while (LINK->t != NULL && LINK->t->kind == tokup) - { - if (n.stringval) - tmerr(": not a number before ^"); - LINK->t = LINK->t->next; - n2 = upexpr(LINK); - if (n2.stringval) - tmerr(": not a number after ^"); - if (n.UU.val >= 0) - { - if (n.UU.val > 0) - { - n.UU.val = exp(n2.UU.val * log(n.UU.val)); - } - continue; - } - if (n2.UU.val != (long) n2.UU.val) - { - tmerr(": negative number cannot be raised to a fractional power."); - } - else - { - n.UU.val = exp(n2.UU.val * log(-n.UU.val)); - if (((long) n2.UU.val) & 1) - n.UU.val = -n.UU.val; - } - } - return n; -} - -QBasic::valrec QBasic:: -term(struct LOC_exec * LINK) -{ - valrec n, n2; - int k; - - n = upexpr(LINK); - while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & ((1L << ((long) toktimes)) | - (1L << ((long) tokdiv)) | (1L << - ((long) tokmod)))) != 0) - { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = QBasic::upexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(": found char, but need a number for * or /"); - if (k == tokmod) - { - /* n.UU.val = (long)floor(n.UU.val + 0.5) % (long)floor(n2.UU.val + 0.5); */ - if (n.UU.val != 0) - { - n.UU.val = - fabs(n.UU.val) / n.UU.val * fmod(fabs(n.UU.val) + - 1e-14, n2.UU.val); - } - else - { - n.UU.val = 0; - } -/* p2c: basic.p, line 1078: - * Note: Using % for possibly-negative arguments [317] */ - } - else if (k == toktimes) - n.UU.val *= n2.UU.val; - else if (n2.UU.val != 0) - { - n.UU.val /= n2.UU.val; - } - else - { - sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - n.UU.val = 0; - } - } - return n; -} - -QBasic::valrec QBasic:: -sexpr(struct LOC_exec * LINK) -{ - valrec n, n2; - int k, m; - - n = term(LINK); - while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) tokplus)) | (1L << ((long) tokminus)))) != 0) - { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = term(LINK); - if (n.stringval != n2.stringval) - tmerr(": found char, but need a number for + or - "); - if (k == tokplus) - { - if (n.stringval) - { - m = (int) strlen(n.UU.sval) + (int) strlen(n2.UU.sval) + 1; - if (m < 256) - m = 256; - - n.UU.sval = (char *) PHRQ_realloc(n.UU.sval, (size_t) m * sizeof(char)); - if (n.UU.sval == NULL) - PhreeqcPtr->malloc_error(); - strcat(n.UU.sval, n2.UU.sval); - PHRQ_free(n2.UU.sval); - } - else - n.UU.val += n2.UU.val; - } - else - { - if (n.stringval) - tmerr(": found char, but need a number for - "); - else - n.UU.val -= n2.UU.val; - } - } - return n; -} - -QBasic::valrec QBasic:: -relexpr(struct LOC_exec * LINK) -{ - valrec n, n2; - boolean f; - int k; - - n = sexpr(LINK); - while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) tokne + 1)) - (1L << ((long) tokeq)))) != 0) - { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = QBasic::sexpr(LINK); - if (n.stringval != n2.stringval) - tmerr(""); - if (n.stringval) - { - f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) - && (unsigned long) k < 32 - && ((1L << ((long) k)) & - ((1L << ((long) tokeq)) | - (1L << ((long) tokge)) | (1L << - ((long) tokle)))) - != 0) || (strcmp(n.UU.sval, n2.UU.sval) < 0 - && (unsigned long) k < 32 - && ((1L << ((long) k)) & - ((1L << ((long) toklt)) | - (1L << ((long) tokle)) | (1L << - ((long) - tokne)))) - != 0) - || (strcmp(n.UU.sval, n2.UU.sval) > 0 - && (unsigned long) k < 32 - && ((1L << ((long) k)) & - ((1L << ((long) tokgt)) | - (1L << ((long) tokge)) | (1L << - ((long) - tokne)))) != - 0)); - /* p2c: basic.p, line 2175: Note: - * Line breaker spent 0.0+1.00 seconds, 5000 tries on line 1518 [251] */ - PHRQ_free(n.UU.sval); - PHRQ_free(n2.UU.sval); - } - else - f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long) k < 32 && - ((1L << ((long) k)) & ((1L << ((long) tokeq)) | - (1L << ((long) tokge)) | - (1L << ((long) tokle)))) != - 0) || (n.UU.val < n2.UU.val - && (unsigned long) k < 32 - && ((1L << ((long) k)) & - ((1L << ((long) toklt)) | - (1L << ((long) tokle)) | (1L << - ((long) - tokne)))) - != 0) || (n.UU.val > n2.UU.val - && (unsigned long) k < 32 - && ((1L << ((long) k)) & - ((1L << ((long) tokgt)) | - (1L << ((long) tokge)) | (1L - << - ((long) tokne)))) != 0)); - /* p2c: basic.p, line 2175: Note: - * Line breaker spent 0.0+2.00 seconds, 5000 tries on line 1532 [251] */ - n.stringval = false; - n.UU.val = f; - } - return n; -} - -QBasic::valrec QBasic:: -andexpr(struct LOC_exec * LINK) -{ - valrec n, n2; - - n = relexpr(LINK); - while (LINK->t != NULL && LINK->t->kind == tokand) - { - LINK->t = LINK->t->next; - n2 = relexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(""); - n.UU.val = ((long) n.UU.val) & ((long) n2.UU.val); - } - return n; -} - -QBasic::valrec QBasic:: -expr(struct LOC_exec * LINK) -{ - valrec n, n2; - int k; - - n = andexpr(LINK); - while (LINK->t != NULL && (unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) tokor)) | (1L << ((long) tokxor)))) != 0) - { - k = LINK->t->kind; - LINK->t = LINK->t->next; - n2 = andexpr(LINK); - if (n.stringval || n2.stringval) - tmerr(""); - if (k == tokor) - n.UU.val = ((long) n.UU.val) | ((long) n2.UU.val); - else - n.UU.val = ((long) n.UU.val) ^ ((long) n2.UU.val); - } - return n; -} - - - void QBasic:: -checkextra(struct LOC_exec *LINK) -{ - if (LINK->t != NULL) - errormsg("Extra information on line"); -} - - - boolean QBasic:: -iseos(struct LOC_exec *LINK) -{ - return ((boolean) (LINK->t == NULL || LINK->t->kind == (long) tokelse || - LINK->t->kind == (long) tokcolon)); -} - - - void QBasic:: -skiptoeos(struct LOC_exec *LINK) -{ - while (!iseos(LINK)) - LINK->t = LINK->t->next; -} - - -QBasic::linerec * QBasic:: -findline(long n) -{ - linerec *l; - - l = linebase; - while (l != NULL && l->num != n) - l = l->next; - return l; -} - -QBasic::linerec * QBasic:: -mustfindline(long n) -{ - linerec *l; - - l = findline(n); - if (l == NULL) { - sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); - errormsg(PhreeqcPtr->error_string); - } - return l; -} - - - void QBasic:: -cmdend(struct LOC_exec *LINK) -{ - stmtline = NULL; - LINK->t = NULL; -} - - - void QBasic:: -cmdnew(struct LOC_exec *LINK) -{ - void *p; - int i, k; - - cmdend(LINK); - clearloops(); - restoredata(); - while (linebase != NULL) - { - p = linebase->next; - disposetokens(&linebase->txt); - PHRQ_free(linebase); - linebase = (linerec *) p; - } - while (varbase != NULL) - { - p = varbase->next; - if (varbase->stringvar) - { - if (varbase->numdims > 0) - { - k = 1; - for (i = 0; i < varbase->numdims; i++) - { - k = k * (varbase->dims[i]); - } - for (i = 0; i < k; i++) - { - PhreeqcPtr->free_check_null(varbase->UU.U1.sarr[i]); - } - PhreeqcPtr->free_check_null(varbase->UU.U1.sarr); - } - else if (*varbase->UU.U1.sval != NULL) - { - *varbase->UU.U1.sval = - (char *) PhreeqcPtr->free_check_null(*varbase->UU.U1.sval); - } - - } - else - { - PhreeqcPtr->free_check_null(varbase->UU.U0.arr); - varbase->UU.U0.arr = NULL; - } - PHRQ_free(varbase); - varbase = (varrec *) p; - } -} - - - void QBasic:: -cmdlist(struct LOC_exec *LINK) -{ - linerec *l; - long n1, n2; - - do - { - n1 = 0; - n2 = LONG_MAX; - if (LINK->t != NULL && LINK->t->kind == toknum) - { - n1 = (long) LINK->t->UU.num; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != tokminus) - n2 = n1; - } - if (LINK->t != NULL && LINK->t->kind == tokminus) - { - LINK->t = LINK->t->next; - if (LINK->t != NULL && LINK->t->kind == toknum) - { - n2 = (long) LINK->t->UU.num; - LINK->t = LINK->t->next; - } - else - n2 = LONG_MAX; - } - l = linebase; - while (l != NULL && l->num <= n2) - { - if (l->num >= n1) - { - /* printf("%ld ", l->num); */ - /* listtokens(stdout, l->txt); */ - /* putchar('\n'); */ - output_temp_msg(PhreeqcPtr->sformatf("%ld ", l->num)); - listtokens(NULL, l->txt); - output_temp_msg("\n"); - } - l = l->next; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } - while (!iseos(LINK)); -} - - - void QBasic:: -cmdload(boolean merging, char * name, struct LOC_exec *LINK) -{ - FILE *f; - tokenrec *l_buf; - char STR1[256] = {0}; - char *TEMP; - - f = NULL; - if (!merging) - cmdnew(LINK); - if (f != NULL) - { - sprintf(STR1, "%s.TEXT", name); - f = freopen(STR1, "r", f); - } - else - { - sprintf(STR1, "%s.TEXT", name); - f = fopen(STR1, "r"); - } - if (f == NULL) - _EscIO(FileNotFound); - while (fgets(inbuf, 256, f) != NULL) - { - TEMP = strchr(inbuf, '\n'); - if (TEMP != NULL) - *TEMP = 0; - parseinput(&l_buf); - if (curline == 0) - { - printf("Bad line in file\n"); - disposetokens(&l_buf); - } - } - if (f != NULL) - fclose(f); - f = NULL; - if (f != NULL) - fclose(f); -} - - - void QBasic:: -cmdrun(struct LOC_exec *LINK) -{ - linerec *l; - long i; - /*string255 s; */ - char *l_s; - - l_s = (char *) PHRQ_calloc(max_line, sizeof(char)); - if (l_s == NULL) - PhreeqcPtr->malloc_error(); - - l = linebase; - if (!iseos(LINK)) - { - if (LINK->t->kind == toknum) - /*l = mustfindline(intexpr(LINK), LINK); */ - l = mustfindline(intexpr(LINK)); - else - { - stringexpr(l_s, LINK); - i = 0; - if (!iseos(LINK)) - { - require(tokcomma, LINK); - i = intexpr(LINK); - } - checkextra(LINK); - cmdload(false, l_s, LINK); - if (i == 0) - l = linebase; - else - l = mustfindline(i); - } - } - stmtline = l; - LINK->gotoflag = true; - clearvars(); - clearloops(); - restoredata(); - PhreeqcPtr->free_check_null(l_s); - return; -} - -/* PhreeqcPtr->replace basic save command with transport of rate back to calc_kinetic_rate */ - void QBasic:: -cmdsave(struct LOC_exec *LINK) -{ - valrec n; - while (!iseos(LINK)) - { - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) - { - snerr(": in SAVE command"); - } - else - { - PhreeqcPtr->rate_moles = n.UU.val; - } - } -} - void QBasic:: -cmdput(struct LOC_exec *LINK) -{ - int j; - struct save_values s_v; - - s_v.count_subscripts = 0; - s_v.subscripts = (int *) PHRQ_malloc(sizeof(int)); - - /* get parentheses */ - require(toklp, LINK); - - /* get first argumen */ - s_v.value = realexpr(LINK); - - for (;;) - { - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - j = intexpr(LINK); - s_v.count_subscripts++; - s_v.subscripts = - (int *) PHRQ_realloc(s_v.subscripts, - (size_t) s_v.count_subscripts * - sizeof(int)); - if (s_v.subscripts == NULL) - PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts - 1] = j; - } - else - { - /* get right parentheses */ - require(tokrp, LINK); - break; - } - } - - PhreeqcPtr->save_values_store(&s_v); - s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); -} - - void QBasic:: -cmdchange_por(struct LOC_exec *LINK) -{ - int j; - LDBLE TEMP; - require(toklp, LINK); - /* get new porosity */ - TEMP = realexpr(LINK); - require(tokcomma, LINK); - /* get cell_no */ - j = intexpr(LINK); - require(tokrp, LINK); - if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 - && j != PhreeqcPtr->count_cells + 1) - PhreeqcPtr->cell_data[j - 1].por = TEMP; -} - - void QBasic:: -cmdchange_surf(struct LOC_exec *LINK) -{ -/* - change_surf("Hfo", 0.3, "Sfo", 0, 5 ) - (old_name, fraction, new_name, new_Dw, cell_no) - */ - char *c1; - int count; - - PhreeqcPtr->change_surf_count += 1; - count = PhreeqcPtr->change_surf_count; - if (PhreeqcPtr->change_surf[count - 1].next == FALSE) - PhreeqcPtr->change_surf = PhreeqcPtr->change_surf_alloc(count + 1); - - require(toklp, LINK); - /* get surface component name (change affects all comps of the same charge structure) */ - c1 = strexpr(LINK); - PhreeqcPtr->change_surf[count - 1].comp_name = PhreeqcPtr->string_hsave(c1); - PHRQ_free(c1); - require(tokcomma, LINK); - /* get fraction of comp to change */ - PhreeqcPtr->change_surf[count - 1].fraction = realexpr(LINK); - require(tokcomma, LINK); - /* get new surface component name */ - c1 = strexpr(LINK); - PhreeqcPtr->change_surf[count - 1].new_comp_name = PhreeqcPtr->string_hsave(c1); - PHRQ_free(c1); - require(tokcomma, LINK); - /* get new Dw (no transport if 0) */ - PhreeqcPtr->change_surf[count - 1].new_Dw = realexpr(LINK); - require(tokcomma, LINK); - /* get cell_no */ - PhreeqcPtr->change_surf[count - 1].cell_no = intexpr(LINK); - require(tokrp, LINK); - - if (PhreeqcPtr->change_surf->cell_no == 0 || PhreeqcPtr->change_surf->cell_no == PhreeqcPtr->count_cells + 1) - PhreeqcPtr->change_surf[count - 1].cell_no = -99; -} - - void QBasic:: -cmdbye(void) -{ - exitflag = true; -} - - void QBasic:: -cmddel(struct LOC_exec *LINK) -{ - linerec *l, *l0, *l1; - long n1, n2; - - do - { - if (iseos(LINK)) - snerr(": no variable name after del"); - n1 = 0; - n2 = LONG_MAX; - if (LINK->t != NULL && LINK->t->kind == toknum) - { - n1 = (long) LINK->t->UU.num; - LINK->t = LINK->t->next; - if (LINK->t == NULL || LINK->t->kind != tokminus) - n2 = n1; - } - if (LINK->t != NULL && LINK->t->kind == tokminus) - { - LINK->t = LINK->t->next; - if (LINK->t != NULL && LINK->t->kind == toknum) - { - n2 = (long) LINK->t->UU.num; - LINK->t = LINK->t->next; - } - else - n2 = LONG_MAX; - } - l = linebase; - l0 = NULL; - while (l != NULL && l->num <= n2) - { - l1 = l->next; - if (l->num >= n1) - { - if (l == stmtline) - { - cmdend(LINK); - clearloops(); - restoredata(); - } - if (l0 == NULL) - linebase = l->next; - else - l0->next = l->next; - disposetokens(&l->txt); - PHRQ_free(l); - } - else - l0 = l; - l = l1; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } - while (!iseos(LINK)); -} - - - void QBasic:: -cmdrenum(struct LOC_exec *LINK) -{ - linerec *l, *l1; - tokenrec *tok; - long lnum, step; - - lnum = 10; - step = 10; - if (!iseos(LINK)) - { - lnum = intexpr(LINK); - if (!iseos(LINK)) - { - require(tokcomma, LINK); - step = intexpr(LINK); - } - } - l = linebase; - if (l == NULL) - return; - while (l != NULL) - { - l->num2 = lnum; - lnum += step; - l = l->next; - } - l = linebase; - do - { - tok = l->txt; - do - { - if (tok->kind == (long) tokdel || tok->kind == (long) tokrestore - || tok->kind == (long) toklist || tok->kind == (long) tokrun - || tok->kind == (long) tokelse || tok->kind == (long) tokthen - || tok->kind == (long) tokgosub - || tok->kind == (long) tokgoto) - { - while (tok->next != NULL && tok->next->kind == toknum) - { - tok = tok->next; - lnum = (long) floor(tok->UU.num + 0.5); - l1 = linebase; - while (l1 != NULL && l1->num != lnum) - l1 = l1->next; - if (l1 == NULL) - printf("Undefined line %ld in line %ld\n", lnum, - l->num2); - else - tok->UU.num = l1->num2; - if (tok->next != NULL && tok->next->kind == tokcomma) - tok = tok->next; - } - } - tok = tok->next; - } - while (tok != NULL); - l = l->next; - } - while (l != NULL); - l = linebase; - while (l != NULL) - { - l->num = l->num2; - l = l->next; - } -} - - - void QBasic:: -cmdprint(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - char STR1[256] = {0}; - - semiflag = false; - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) - { -/* fputs(n.UU.sval, stdout); */ - output_temp_msg(PhreeqcPtr->sformatf("%s ", n.UU.sval)); - PHRQ_free(n.UU.sval); - } - else -/* printf("%s ", numtostr(STR1, n.UU.val)); */ - output_temp_msg(PhreeqcPtr->sformatf("%s ", numtostr(STR1, n.UU.val))); - } - if (!semiflag) -/* putchar('\n');*/ - output_temp_msg("\n"); -} - - void QBasic:: -cmdpunch(struct LOC_exec *LINK) -{ - valrec n; - /* char STR1[256]; */ - - while (!iseos(LINK)) - { - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (n.stringval) - { -/* fputs(n.UU.sval, stdout); */ - if (PhreeqcPtr->punch.high_precision == FALSE) - { - if (strlen(n.UU.sval) <= 12) - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.12s\t", n.UU.sval); - } - else - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); - } - } - else - { - if (strlen(n.UU.sval) <= 20) - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.20s\t", n.UU.sval); - } - else - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%s\t", n.UU.sval); - } - } - PHRQ_free(n.UU.sval); - } - else if (PhreeqcPtr->punch.high_precision == FALSE) - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); - } - else - { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.12e\t", (double) n.UU.val); - } - ++PhreeqcPtr->n_user_punch_index; - } -} - -#if defined PHREEQ98 - void QBasic:: -cmdgraph_x(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - char STR1[256]; - semiflag = false; - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (colnr == 0) - { - rownr++; - } - if (n.stringval) - { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "x"); - PHRQ_free(n.UU.sval); - } - else - GridChar(numtostr(STR1, n.UU.val), "x"); - colnr++; - } -} - - void QBasic:: -cmdgraph_y(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - char STR1[256]; - semiflag = false; - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (colnr == 0) - { - rownr++; - } - if (n.stringval) - { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "y"); - PHRQ_free(n.UU.sval); - } - else - GridChar(numtostr(STR1, n.UU.val), "y"); - colnr++; - } -} - - void QBasic:: -cmdgraph_sy(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - char STR1[256]; - semiflag = false; - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - if (colnr == 0) - { - rownr++; - } - if (n.stringval) - { -/* fputs(n.UU.sval, stdout); */ - GridChar(n.UU.sval, "s"); - PHRQ_free(n.UU.sval); - } - else - GridChar(numtostr(STR1, n.UU.val), "s"); - colnr++; - } -} -#endif - - void QBasic:: -cmdlet(boolean implied, struct LOC_exec *LINK) -{ - varrec *v; - char *old, *mynew; - LDBLE d_value; - LDBLE *target; - char **starget; - target = NULL; - starget = NULL; - if (implied) - LINK->t = stmttok; - v = findvar(LINK); - if (v->stringvar) - { - starget = v->UU.U1.sval; - } - else - { - target = v->UU.U0.val; - } - require(tokeq, LINK); - if (!v->stringvar) - { - /* in case array is used on right hand side */ - d_value = realexpr(LINK); - v->UU.U0.val = target; - *v->UU.U0.val = d_value; - /* *v->UU.U0.val = realexpr(LINK); */ - return; - } - mynew = strexpr(LINK); - v->UU.U1.sval = starget; - old = *v->UU.U1.sval; - *v->UU.U1.sval = mynew; - if (old != NULL) - PHRQ_free(old); -} - - - void QBasic:: -cmdgoto(struct LOC_exec *LINK) -{ - stmtline = mustfindline(intexpr(LINK)); - LINK->t = NULL; - LINK->gotoflag = true; -} - - - void QBasic:: -cmdif(struct LOC_exec *LINK) -{ - LDBLE n; - long i; - - n = realexpr(LINK); - require(tokthen, LINK); - if (n == 0) - { - i = 0; - do - { - if (LINK->t != NULL) - { - if (LINK->t->kind == tokif) - i++; - if (LINK->t->kind == tokelse) - i--; - LINK->t = LINK->t->next; - } - } - while (LINK->t != NULL && i >= 0); - } - if (LINK->t != NULL && LINK->t->kind == toknum) - cmdgoto(LINK); - else - LINK->elseflag = true; -} - - - void QBasic:: -cmdelse(struct LOC_exec *LINK) -{ - LINK->t = NULL; -} - - - boolean QBasic:: -skiploop(int up, int dn, struct LOC_exec *LINK) -{ - boolean Result; - long i; - linerec *saveline; - - saveline = stmtline; - i = 0; - do - { - while (LINK->t == NULL) - { - if (stmtline == NULL || stmtline->next == NULL) - { - Result = false; - stmtline = saveline; - goto _L1; - } - stmtline = stmtline->next; - LINK->t = stmtline->txt; - } - if (LINK->t->kind == up) - i++; - if (LINK->t->kind == dn) - i--; - LINK->t = LINK->t->next; - } - while (i >= 0); - Result = true; - _L1: - return Result; -} - - - void QBasic:: -cmdfor(struct LOC_exec *LINK) -{ - looprec *l, lr; - linerec *saveline; - long i, j; - - lr.UU.U0.vp = findvar(LINK); - if (lr.UU.U0.vp->stringvar) - snerr(": error in FOR command"); - require(tokeq, LINK); - *lr.UU.U0.vp->UU.U0.val = realexpr(LINK); - require(tokto, LINK); - lr.UU.U0.max = realexpr(LINK); - if (LINK->t != NULL && LINK->t->kind == tokstep) - { - LINK->t = LINK->t->next; - lr.UU.U0.step = realexpr(LINK); - } - else - lr.UU.U0.step = 1.0; - lr.homeline = stmtline; - lr.hometok = LINK->t; - lr.kind = forloop; - lr.next = loopbase; - if ((lr.UU.U0.step >= 0 && *lr.UU.U0.vp->UU.U0.val > lr.UU.U0.max) || - (lr.UU.U0.step <= 0 && *lr.UU.U0.vp->UU.U0.val < lr.UU.U0.max)) - { - saveline = stmtline; - i = 0; - j = 0; - do - { - while (LINK->t == NULL) - { - if (stmtline == NULL || stmtline->next == NULL) - { - stmtline = saveline; - errormsg("FOR without NEXT"); - } - stmtline = stmtline->next; - LINK->t = stmtline->txt; - } - if (LINK->t->kind == tokfor) - { - if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && - LINK->t->next->UU.vp == lr.UU.U0.vp) - j++; - else - i++; - } - if (LINK->t->kind == toknext) - { - if (LINK->t->next != NULL && LINK->t->next->kind == tokvar && - LINK->t->next->UU.vp == lr.UU.U0.vp) - j--; - else - i--; - } - LINK->t = LINK->t->next; - } - while (i >= 0 && j >= 0); - skiptoeos(LINK); - return; - } - l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); - if (l == NULL) - PhreeqcPtr->malloc_error(); - *l = lr; - loopbase = l; -} - - - void QBasic:: -cmdnext(struct LOC_exec *LINK) -{ - varrec *v; - boolean found; - looprec *l, *WITH; - - if (!iseos(LINK)) - v = findvar(LINK); - else - v = NULL; - do - { - if (loopbase == NULL || loopbase->kind == gosubloop) - errormsg("NEXT without FOR"); - found = (boolean) (loopbase->kind == forloop && - (v == NULL || loopbase->UU.U0.vp == v)); - if (!found) - { - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - } - } - while (!found); - WITH = loopbase; - *WITH->UU.U0.vp->UU.U0.val += WITH->UU.U0.step; - if ((WITH->UU.U0.step < 0 - || *WITH->UU.U0.vp->UU.U0.val <= WITH->UU.U0.max) - && (WITH->UU.U0.step > 0 - || *WITH->UU.U0.vp->UU.U0.val >= WITH->UU.U0.max)) - { - stmtline = WITH->homeline; - LINK->t = WITH->hometok; - return; - } - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; -} - - - void QBasic:: -cmdwhile(struct LOC_exec *LINK) -{ - looprec *l; - - l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); - if (l == NULL) - PhreeqcPtr->malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = whileloop; - l->homeline = stmtline; - l->hometok = LINK->t; - if (iseos(LINK)) - return; - if (realexpr(LINK) != 0) - return; - if (!skiploop(tokwhile, tokwend, LINK)) - errormsg("WHILE without WEND"); - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - skiptoeos(LINK); -} - - - void QBasic:: -cmdwend(struct LOC_exec *LINK) -{ - tokenrec *tok; - linerec *tokline; - looprec *l; - boolean found; - - do - { - if (loopbase == NULL || loopbase->kind == gosubloop) - errormsg("WEND without WHILE"); - found = (boolean) (loopbase->kind == whileloop); - if (!found) - { - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - } - } - while (!found); - if (!iseos(LINK)) - { - if (realexpr(LINK) != 0) - found = false; - } - tok = LINK->t; - tokline = stmtline; - if (found) - { - stmtline = loopbase->homeline; - LINK->t = loopbase->hometok; - if (!iseos(LINK)) - { - if (realexpr(LINK) == 0) - found = false; - } - } - if (found) - return; - LINK->t = tok; - stmtline = tokline; - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; -} - - - void QBasic:: -cmdgosub(struct LOC_exec *LINK) -{ - looprec *l; - - l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); - if (l == NULL) - PhreeqcPtr->malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = gosubloop; - l->homeline = stmtline; - l->hometok = LINK->t; - cmdgoto(LINK); -} - - - void QBasic:: -cmdreturn(struct LOC_exec *LINK) -{ - looprec *l; - boolean found; - - do - { - if (loopbase == NULL) - errormsg("RETURN without GOSUB"); - found = (boolean) (loopbase->kind == gosubloop); - if (!found) - { - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - } - } - while (!found); - stmtline = loopbase->homeline; - LINK->t = loopbase->hometok; - l = loopbase->next; - PHRQ_free(loopbase); - loopbase = l; - skiptoeos(LINK); -} - - - void QBasic:: -cmdread(struct LOC_exec *LINK) -{ - varrec *v; - tokenrec *tok; - boolean found; - - do - { - v = findvar(LINK); - tok = LINK->t; - LINK->t = datatok; - if (dataline == NULL) - { - dataline = linebase; - LINK->t = dataline->txt; - } - if (LINK->t == NULL || LINK->t->kind != tokcomma) - { - do - { - while (LINK->t == NULL) - { - if (dataline == NULL || dataline->next == NULL) - errormsg("Out of Data"); - dataline = dataline->next; - LINK->t = dataline->txt; - } - found = (boolean) (LINK->t->kind == tokdata); - LINK->t = LINK->t->next; - } - while (!found || iseos(LINK)); - } - else - LINK->t = LINK->t->next; - if (v->stringvar) - { - if (*v->UU.U1.sval != NULL) - *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); - *v->UU.U1.sval = strexpr(LINK); - } - else - *v->UU.U0.val = realexpr(LINK); - datatok = LINK->t; - LINK->t = tok; - if (!iseos(LINK)) - require(tokcomma, LINK); - } - while (!iseos(LINK)); -} - - - void QBasic:: -cmddata(struct LOC_exec *LINK) -{ - skiptoeos(LINK); -} - - - void QBasic:: -cmdrestore(struct LOC_exec *LINK) -{ - if (iseos(LINK)) - restoredata(); - else - { - dataline = mustfindline(intexpr(LINK)); - datatok = dataline->txt; - } -} - - - void QBasic:: -cmdgotoxy(struct LOC_exec *LINK) -{ - intexpr(LINK); - require(tokcomma, LINK); -} - - - void QBasic:: -cmdon(struct LOC_exec *LINK) -{ - long i; - looprec *l; - - i = intexpr(LINK); - if (LINK->t != NULL && LINK->t->kind == tokgosub) - { - l = (looprec *) PHRQ_calloc(1, sizeof(looprec)); - if (l == NULL) - PhreeqcPtr->malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = gosubloop; - l->homeline = stmtline; - l->hometok = LINK->t; - LINK->t = LINK->t->next; - } - else - require(tokgoto, LINK); - if (i < 1) - { - skiptoeos(LINK); - return; - } - while (i > 1 && !iseos(LINK)) - { - require(toknum, LINK); - if (!iseos(LINK)) - require(tokcomma, LINK); - i--; - } - if (!iseos(LINK)) - cmdgoto(LINK); -} - - - void QBasic:: -cmddim(struct LOC_exec *LINK) -{ - long i, j, k; - varrec *v; - boolean done; - - do - { - if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(": error in DIM command"); - v = LINK->t->UU.vp; - LINK->t = LINK->t->next; - if (v->numdims != 0) - errormsg("Array already dimensioned before"); - j = 1; - i = 0; - require(toklp, LINK); - do - { - k = intexpr(LINK) + 1; - if (k < 1) - badsubscr(); - if (i >= maxdims) - badsubscr(); - i++; - v->dims[i - 1] = k; - j *= k; - done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); - if (!done) - require(tokcomma, LINK); - } - while (!done); - LINK->t = LINK->t->next; - v->numdims = (char) i; - if (v->stringvar) - { - v->UU.U1.sarr = (char **) PHRQ_malloc(j * sizeof(char *)); - if (v->UU.U1.sarr == NULL) - PhreeqcPtr->malloc_error(); - for (i = 0; i < j; i++) - v->UU.U1.sarr[i] = NULL; - } - else - { - v->UU.U0.arr = (LDBLE *) PHRQ_malloc(j * sizeof(LDBLE)); - if (v->UU.U0.arr == NULL) - PhreeqcPtr->malloc_error(); - for (i = 0; i < j; i++) - v->UU.U0.arr[i] = 0.0; - } - if (!iseos(LINK)) - require(tokcomma, LINK); - } - while (!iseos(LINK)); -} - - void QBasic:: -cmdpoke(struct LOC_exec *LINK) -{ - union - { - long i; - char *c; - } trick; - -/* p2c: basic.p, line 2073: Note: Range checking is OFF [216] */ - trick.i = intexpr(LINK); - require(tokcomma, LINK); - *trick.c = (char) intexpr(LINK); -/* p2c: basic.p, line 2077: Note: Range checking is ON [216] */ -} - - void QBasic:: -exec(void) -{ - struct LOC_exec V; - char *ioerrmsg; - char STR1[256] = {0}; - - - TRY(try1); - do - { - do - { - V.gotoflag = false; - V.elseflag = false; - while (stmttok != NULL && stmttok->kind == tokcolon) - stmttok = stmttok->next; - V.t = stmttok; - if (V.t != NULL) - { - V.t = V.t->next; - switch (stmttok->kind) - { - - case tokrem: - /* blank case */ - break; - - case toklist: - cmdlist(&V); - break; - - case tokrun: - cmdrun(&V); - break; - - case toknew: - cmdnew(&V); - break; - - case tokload: - cmdload(false, stringexpr(STR1, &V), &V); - break; - - case tokmerge: - cmdload(true, stringexpr(STR1, &V), &V); - break; - - case toksave: - cmdsave(&V); - break; - - case tokbye: - cmdbye(); - break; - - case tokdel: - cmddel(&V); - break; - - case tokrenum: - cmdrenum(&V); - break; - - case toklet: - cmdlet(false, &V); - break; - - case tokvar: - cmdlet(true, &V); - break; - - case tokprint: - cmdprint(&V); - break; - - case tokpunch: - cmdpunch(&V); - break; - - case tokput: - cmdput(&V); - break; - - case tokchange_por: - cmdchange_por(&V); - break; - - case tokchange_surf: - cmdchange_surf(&V); - break; - -#if defined PHREEQ98 || defined MULTICHART - case tokgraph_x: - cmdgraph_x(&V); - break; - - case tokgraph_y: - cmdgraph_y(&V); - break; - - case tokgraph_sy: - cmdgraph_sy(&V); - break; -#endif -#if defined MULTICHART - case tokplot_xy: - cmdplot_xy(&V); - break; -#endif - - case tokinput: - error_msg - ("Basic command INPUT is not a legal command in PHREEQC.", - STOP); - break; - - case tokgoto: - cmdgoto(&V); - break; - - case tokif: - cmdif(&V); - break; - - case tokelse: - cmdelse(&V); - break; - - case tokend: - cmdend(&V); - break; - - case tokstop: - P_escapecode = -20; - goto _Ltry1; - - case tokfor: - cmdfor(&V); - break; - - case toknext: - cmdnext(&V); - break; - - case tokwhile: - cmdwhile(&V); - break; - - case tokwend: - cmdwend(&V); - break; - - case tokgosub: - cmdgosub(&V); - break; - - case tokreturn: - cmdreturn(&V); - break; - - case tokread: - cmdread(&V); - break; - - case tokdata: - cmddata(&V); - break; - - case tokrestore: - cmdrestore(&V); - break; - - case tokgotoxy: - cmdgotoxy(&V); - break; - - case tokon: - cmdon(&V); - break; - - case tokdim: - cmddim(&V); - break; - - case tokpoke: - cmdpoke(&V); - break; - - default: - errormsg("Illegal command"); - break; - } - } - if (!V.elseflag && !iseos(&V)) - checkextra(&V); - stmttok = V.t; - } - while (V.t != NULL); - if (stmtline != NULL) - { - if (!V.gotoflag) - stmtline = stmtline->next; - if (stmtline != NULL) - stmttok = stmtline->txt; - } - } - while (stmtline != NULL); - RECOVER2(try1, _Ltry1); - if (P_escapecode == -20) - warning_msg("Break"); - /* printf("Break"); */ - else if (P_escapecode != 42) - { - switch (P_escapecode) - { - - case -4: - sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -5: - sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -6: - sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -7: - sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -8: - case -19: - case -18: - case -17: - case -16: - case -15: - sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -10: - ioerrmsg = (char *) PHRQ_calloc(256, sizeof(char)); - if (ioerrmsg == NULL) - PhreeqcPtr->malloc_error(); - sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); - warning_msg(ioerrmsg); - PHRQ_free(ioerrmsg); - break; - - default: - if (EXCP_LINE != -1) - { - sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); - warning_msg(PhreeqcPtr->error_string); - } - _Escape(P_escapecode); - break; - } - } - if (stmtline != NULL) - { - sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - error_msg(PhreeqcPtr->error_string, CONTINUE); - } - ENDTRY(try1); -} /*exec */ -int QBasic:: -free_dim_stringvar(varrec *l_varbase) -{ - int i, k; - if (l_varbase->numdims > 0) - { - k = 1; - for (i = 0; i < l_varbase->numdims; i++) - { - k = k * (l_varbase->dims[i]); - } - for (i = 0; i < k; i++) - { - PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr[i]); - } - l_varbase->UU.U1.sarr = (char **) PhreeqcPtr->free_check_null(l_varbase->UU.U1.sarr); - } - return (OK); -} -#if defined MULTICHART - void QBasic:: -cmdplot_xy(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n[2]; - char STR[2][256]; - int i = 0; - semiflag = false; - - while (!iseos(LINK) && i < 2) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - i++; - continue; - } - n[i] = expr(LINK); - if (n[i].stringval) - { - strcpy(STR[i], n[i].UU.sval); - PHRQ_free(n[i].UU.sval); - } - else - numtostr(STR[i], n[i].UU.val); - } - - ChartObject *chart = chart_handler.Get_current_chart(); - if (chart == NULL) return; - - std::string x_str(STR[0]), y_str(STR[1]); - -// Code formerly in PlotXY, included here - { - - bool new_sim = false, new_trans = false; - - if (chart->Get_FirstCallToUSER_GRAPH() && chart->Get_colnr() == 0) - chart->Set_prev_sim_no(simulation); - else - chart->Set_prev_sim_no(simulation); - - // Add a curve if necessary - if ((int) chart->Get_Curves().size() == chart->Get_colnr()) - { - std::string head(""); - if (chart->Get_new_headings().size() > 0) - { - head = chart->Get_new_headings()[0]; - chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - } - if (chart->Get_new_plotxy_curves().size() > 0) - { - // find plotxy curve definitions - chart->Add_curve(true, head, - chart->Get_new_plotxy_curves()[0].Get_line_w(), - chart->Get_new_plotxy_curves()[0].Get_symbol(), - chart->Get_new_plotxy_curves()[0].Get_symbol_size(), - chart->Get_new_plotxy_curves()[0].Get_y_axis(), - chart->Get_new_plotxy_curves()[0].Get_color() - ); - // pop plotxy curve definition - chart->Get_new_plotxy_curves().erase(chart->Get_new_plotxy_curves().begin()); - } - else - { - chart->Add_curve(true, head); - } - chart->Set_curve_added(true); - } - - if (x_str.size() > 0 && y_str.size() > 0) - { - chart->Get_Curves()[chart->Get_colnr()]->Get_x().push_back(atof(x_str.c_str())); - chart->Get_Curves()[chart->Get_colnr()]->Get_y().push_back(atof(y_str.c_str())); - chart->Set_point_added(true); - - // Mark added curve for first point, might have been invisible in DefineCurves - if (chart->Get_Curves()[chart->Get_colnr()]->Get_x().size() == 1) - chart->Set_curve_added(true); - } - } - chart->Set_colnr(chart->Get_colnr() + 1); -} - void QBasic:: -cmdgraph_x(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - semiflag = false; - - ChartObject *chart = chart_handler.Get_current_chart(); - if (chart == NULL) return; - - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - - if (n.stringval) - { - if (strlen(n.UU.sval) > 0) - { - chart->Set_graph_x(atof(n.UU.sval)); - } - PHRQ_free(n.UU.sval); - } - else - chart->Set_graph_x(n.UU.val); - } - if ((int) chart->Get_Curves().size() == chart->Get_colnr()) - { - if (chart->Get_new_headings().size() > 0) - { - // remove x heading - //if (chart->Get_colnr() == chart->Get_ColumnOffset()) - { - chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - } - } - } -} - - void QBasic:: -cmdgraph_y(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - semiflag = false; - - ChartObject *chart = chart_handler.Get_current_chart(); - if (chart == NULL) return; - - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - - // wait until x value is known before storing in curve - if (n.stringval) - { - if (strlen(n.UU.sval) > 0) - { - chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); - } - PHRQ_free(n.UU.sval); - } - else - { - chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; - } - chart->Set_point_added(true); - - // Add a new curve if necessary - if ((int) chart->Get_Curves().size() == chart->Get_colnr()) - { - //if (chart->Get_new_headings().size() > 0) - //{ - // // remove x heading - // if (chart->Get_colnr() == chart->Get_ColumnOffset()) - // { - // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - // } - //} - if (chart->Get_new_headings().size() > 0) - { - chart->Add_curve(false, chart->Get_new_headings()[0]); - chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - } - else - { - chart->Add_curve(false); - } - chart->Set_curve_added(true); - } - chart->Set_colnr(chart->Get_colnr() + 1); - } -} - - void QBasic:: -cmdgraph_sy(struct LOC_exec *LINK) -{ - boolean semiflag; - valrec n; - semiflag = false; - - ChartObject *chart = chart_handler.Get_current_chart(); - if (chart == NULL) return; - - while (!iseos(LINK)) - { - semiflag = false; - if ((unsigned long) LINK->t->kind < 32 && - ((1L << ((long) LINK->t->kind)) & - ((1L << ((long) toksemi)) | (1L << ((long) tokcomma)))) != 0) - { - semiflag = true; - LINK->t = LINK->t->next; - continue; - } - n = expr(LINK); - - chart->Get_secondary_y()[chart->Get_colnr()] = true; - - // wait until x value is known before storing in curve - if (n.stringval) - { - if (strlen(n.UU.sval) > 0) - { - chart->Get_graph_y()[chart->Get_colnr()] = atof(n.UU.sval); - } - PHRQ_free(n.UU.sval); - } - else - chart->Get_graph_y()[chart->Get_colnr()] = n.UU.val; - chart->Set_point_added(true); - // Add a new curve if necessary - if ((int) chart->Get_Curves().size() == chart->Get_colnr()) - { - //if (chart->Get_new_headings().size() > 0) - //{ - // // remove x heading - // if (chart->Get_colnr() == chart->Get_ColumnOffset()) - // { - // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - // } - //} - if (chart->Get_new_headings().size() > 0) - { - chart->Add_curve(false, chart->Get_new_headings()[0]); - chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - } - else - { - chart->Add_curve(false); - } - chart->Set_curve_added(true); - } - chart->Set_colnr(chart->Get_colnr() + 1); - } -} -#endif // MULTICHART - - - - -/* In case your system lacks these... */ - -long QBasic:: -my_labs(long l_x) -{ - return ((l_x > 0) ? l_x : -l_x); -} - - -/* #define __STDC__ */ /* PHREEQ98 */ - -QBasic::Anyptr QBasic:: -my_memmove(Anyptr d, Const Anyptr l_s, size_t n) -{ - register char *dd = (char *) d, *ss = (char *) l_s; - if (dd < ss || (unsigned int) (dd - ss) >= n) - { - memcpy(dd, ss, n); - } - else if (n > 0) - { - dd += n; - ss += n; - while (n-- > 0) - *--dd = *--ss; - } - return d; -} - - -QBasic::Anyptr QBasic:: -my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) -{ - register char *ss = (char *) l_s, *dd = (char *) d; - while (n-- > 0) - *dd++ = *ss++; - return d; -} - -int QBasic:: -my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) -{ - register char *a = (char *) s1, *b = (char *) s2; - register int i; - while (n-- > 0) - if ((i = (*a++) - (*b++)) != 0) - return i; - return 0; -} - -QBasic::Anyptr QBasic:: -my_memset(Anyptr d, int c, size_t n) -{ - register char *dd = (char *) d; - while (n-- > 0) - *dd++ = (char) c; - return d; -} - -int QBasic:: -my_toupper(int c) -{ - if (islower(c)) - return _toupper(c); - else - return c; -} - - -int QBasic:: -my_tolower(int c) -{ - if (isupper(c)) - return _tolower(c); - else - return c; -} - - - - -long QBasic:: -ipow(long a, long b) -{ - long v; - - if (a == 0 || a == 1) - return a; - if (a == -1) - return (b & 1) ? -1 : 1; - if (b < 0) - return 0; - if (a == 2) - return 1L << b; - v = (b & 1) ? a : 1; - while ((b >>= 1) > 0) - { - a *= a; - if (b & 1) - v *= a; - } - return v; -} - - - - -/* Common string functions: */ - -/* Store in "ret" the substring of length "len" starting from "pos" (1-based). - Store a shorter or null string if out-of-range. Return "ret". */ -char * QBasic:: -strsub(register char *ret, register char *l_s, register int pos, - register int len) -{ - register char *s2; - - if (--pos < 0 || len <= 0) - { - *ret = 0; - return ret; - } - while (pos > 0) - { - if (!*l_s++) - { - *ret = 0; - return ret; - } - pos--; - } - s2 = ret; - while (--len >= 0) - { - if (!(*s2++ = *l_s++)) - return ret; - } - *s2 = 0; - return ret; -} - - -/* Return the index of the first occurrence of "pat" as a substring of "s", - starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ - -int QBasic:: -strpos2(char *l_s, register char *pat, register int pos) -{ - register char *cp, ch; - register int slen; - - if (--pos < 0) - return 0; - slen = (int) strlen(l_s) - pos; - cp = l_s + pos; - if (!(ch = *pat++)) - return 0; - pos = (int) strlen(pat); - slen -= pos; - while (--slen >= 0) - { - if (*cp++ == ch && !strncmp(cp, pat, pos)) - return (int) (cp - l_s); - } - return 0; -} - - -/* Case-insensitive version of strcmp. */ -int QBasic:: -strcicmp(register char *s1, register char *s2) -{ - register unsigned char c1, c2; - - while (*s1) - { - if (*s1++ != *s2++) - { - if (!s2[-1]) - return 1; - c1 = (unsigned char) toupper(s1[-1]); - c2 = (unsigned char) toupper(s2[-1]); - if (c1 != c2) - return c1 - c2; - } - } - if (*s2) - return -1; - return 0; -} - - - - -/* HP and Turbo Pascal string functions: */ - -/* Trim blanks at left end of string. */ -char * QBasic:: -strltrim(register char *l_s) -{ - while (Isspace((int) *l_s++)); - return l_s - 1; -} - - -/* Trim blanks at right end of string. */ -char * QBasic:: -strrtrim(register char *l_s) -{ - register char *s2 = l_s; - - if (!*l_s) - return l_s; - while (*++s2); - while (s2 > l_s && Isspace((int) *--s2)) - *s2 = 0; - return l_s; -} - - -/* Store in "ret" string "s" with enough pad chars added to reach "size". */ - -/* Copy the substring of length "len" from index "spos" of "s" (1-based) - to index "dpos" of "d", lengthening "d" if necessary. Length and - indices must be in-range. */ -void QBasic:: -strmove(register int len, register char *l_s, register int spos, - register char *d, register int dpos) -{ - l_s += spos - 1; - d += dpos - 1; - while (*d && --len >= 0) - *d++ = *l_s++; - if (len > 0) - { - while (--len >= 0) - *d++ = *l_s++; - *d = 0; - } -} - -/* Insert string "src" at index "pos" of "dst". */ -void QBasic:: -strinsert(register char *src, register char *dst, register int pos) -{ - register int slen, dlen; - - if (--pos < 0) - return; - dlen = (int) strlen(dst); - dst += dlen; - dlen -= pos; - if (dlen <= 0) - { - strcpy(dst, src); - return; - } - slen = (int) strlen(src); - do - { - dst[slen] = *dst; - --dst; - } - while (--dlen >= 0); - dst++; - while (--slen >= 0) - *dst++ = *src++; -} - - - - -/* File functions */ - -/* Peek at next character of input stream; return EOF at end-of-file. */ -int QBasic:: -P_peek(FILE * f) -{ - int ch; - - ch = getc(f); - if (ch == EOF) - return EOF; - ungetc(ch, f); - return (ch == '\n') ? ' ' : ch; -} - - -/* Check if at end of file, using Pascal "eof" semantics. End-of-file for - stdin is broken; remove the special case for it to be broken in a - different way. */ -/*int P_eof(FILE *f)*/ -int QBasic:: -P_eof(void) -{ - return 0; -} - - -/* Check if at end of line (or end of entire file). */ -int QBasic:: -P_eoln(FILE * f) -{ - register int ch; - - ch = getc(f); - if (ch == EOF) - return 1; - ungetc(ch, f); - return (ch == '\n'); -} - - -/* Read a packed array of characters from a file. */ -void QBasic:: -P_readpaoc(FILE * f, char *l_s, int len) -{ - int ch; - - for (;;) - { - if (len <= 0) - return; - ch = getc(f); - if (ch == EOF || ch == '\n') - break; - *l_s++ = (char) ch; - --len; - } - while (--len >= 0) - *l_s++ = ' '; - if (ch != EOF) - ungetc(ch, f); -} - -void QBasic:: -P_readlnpaoc(FILE * f, char *l_s, int len) -{ - int ch; - - for (;;) - { - ch = getc(f); - if (ch == EOF || ch == '\n') - break; - if (len > 0) - { - *l_s++ = (char) ch; - --len; - } - } - while (--len >= 0) - *l_s++ = ' '; -} - - -/* Compute maximum legal "seek" index in file (0-based). */ -long QBasic:: -P_maxpos(FILE * f) -{ - long savepos = ftell(f); - long val; - - if (fseek(f, 0L, SEEK_END)) - return -1; - val = ftell(f); - if (fseek(f, savepos, SEEK_SET)) - return -1; - return val; -} - - -/* Use packed array of char for a file name. */ -char * QBasic:: -P_trimname(register char * fn, register int len) -{ - static char fnbuf[256]; - register char *cp = fnbuf; - - while (--len >= 0 && *fn && !isspace((int) *fn)) - *cp++ = *fn++; - *cp = 0; - return fnbuf; -} - - - - -/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. - We fix memory size as 10Meg as a reasonable compromise. */ - -long QBasic:: -memavail(void) -{ - return 10000000; /* worry about this later! */ -} - -long QBasic:: -maxavail(void) -{ - return memavail(); -} - - - - -/* Sets are stored as an array of longs. S[0] is the size of the set; - S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum - I such that S[I] is nonzero. S[0] is zero for an empty set. Within - each long, bits are packed from lsb to msb. The first bit of the - set is the element with ordinal value 0. (Thus, for a "set of 5..99", - the lowest five bits of the first long are unused and always zero.) */ - -/* (Sets with 32 or fewer elements are normally stored as plain longs.) */ -long * QBasic:: -P_setunion(register long *d, register long *s1, register long *s2) /* d := s1 + s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (sz1 > 0 && sz2 > 0) - { - *d++ = *s1++ | *s2++; - sz1--, sz2--; - } - while (--sz1 >= 0) - *d++ = *s1++; - while (--sz2 >= 0) - *d++ = *s2++; - *dbase = (int) (d - dbase - 1); - return dbase; -} - -long * QBasic:: -P_setint(register long *d, register long *s1, register long *s2) /* d := s1 * s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (--sz1 >= 0 && --sz2 >= 0) - *d++ = *s1++ & *s2++; - while (--d > dbase && !*d); - *dbase = (int) (d - dbase); - return dbase; -} - -long * QBasic:: -P_setdiff(register long *d, register long *s1, register long *s2) /* d := s1 - s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (--sz1 >= 0 && --sz2 >= 0) - *d++ = *s1++ & ~*s2++; - if (sz1 >= 0) - { - while (sz1-- >= 0) - *d++ = *s1++; - } - while (--d > dbase && !*d); - *dbase = (int) (d - dbase); - return dbase; -} - -long * QBasic:: -P_setxor(register long *d, register long *s1, register long *s2) /* d := s1 / s2 */ -{ - long *dbase = d++; - register int sz1 = *s1++, sz2 = *s2++; - while (sz1 > 0 && sz2 > 0) - { - *d++ = *s1++ ^ *s2++; - sz1--, sz2--; - } - while (--sz1 >= 0) - *d++ = *s1++; - while (--sz2 >= 0) - *d++ = *s2++; - while (--d > dbase && !*d); - *dbase = (int) (d - dbase); - return dbase; -} - -long * QBasic:: -P_addset(register long *l_s, register unsigned val) /* s := s + [val] */ -{ - register long *sbase = l_s; - register int bit, size; - bit = val % SETBITS; - val /= SETBITS; - size = *l_s; - if ((long) ++val > size) - { - l_s += size; - while ((long) val > size) - *++l_s = 0, size++; - *sbase = size; - } - else - l_s += val; - *l_s |= 1L << bit; - return sbase; -} - -long * QBasic:: -P_addsetr(register long *l_s, register unsigned v1, register unsigned v2) /* s := s + [v1..v2] */ -{ - register long *sbase = l_s; - register int b1, b2, size; - if ((int) v1 > (int) v2) - return sbase; - b1 = v1 % SETBITS; - v1 /= SETBITS; - b2 = v2 % SETBITS; - v2 /= SETBITS; - size = *l_s; - v1++; - if ((int) ++v2 > size) - { - while ((int) v2 > size) - l_s[++size] = 0; - l_s[v2] = 0; - *l_s = v2; - } - l_s += v1; - if (v1 == v2) - { - *l_s |= (~((-2L) << (b2 - b1))) << b1; - } - else - { - *l_s++ |= (-1L) << b1; - while (++v1 < v2) - *l_s++ = -1; - *l_s |= ~((-2L) << b2); - } - return sbase; -} - -long * QBasic:: -P_remset(register long *l_s, register unsigned val) /* s := s - [val] */ -{ - register int bit; - bit = val % SETBITS; - val /= SETBITS; - if ((long) ++val <= *l_s) - { - if (!(l_s[val] &= ~(1L << bit))) - while (*l_s && !l_s[*l_s]) - (*l_s)--; - } - return l_s; -} - -int QBasic:: -P_setequal(register long *s1, register long *s2) /* s1 = s2 */ -{ - register int size = *s1++; - if (*s2++ != size) - return 0; - while (--size >= 0) - { - if (*s1++ != *s2++) - return 0; - } - return 1; -} - -int QBasic:: -P_subset(register long *s1, register long *s2) /* s1 <= s2 */ -{ - register int sz1 = *s1++, sz2 = *s2++; - if (sz1 > sz2) - return 0; - while (--sz1 >= 0) - { - if (*s1++ & ~*s2++) - return 0; - } - return 1; -} - -long * QBasic:: -P_setcpy(register long *d, register long *l_s) /* d := s */ -{ - register long *save_d = d; - -#ifdef SETCPY_MEMCPY - memcpy(d, l_s, (*l_s + 1) * sizeof(long)); -#else - register int i = *l_s + 1; - while (--i >= 0) - *d++ = *l_s++; -#endif - return save_d; -} - - -/* s is a "smallset", i.e., a 32-bit or less set stored - directly in a long. */ -long * QBasic:: -P_expset(register long *d, register long l_s) /* d := s */ -{ - if (l_s) - { - d[1] = l_s; - *d = 1; - } - else - *d = 0; - return d; -} - -long QBasic:: -P_packset(register long *l_s) /* convert s to a small-set */ -{ - if (*l_s++) - return *l_s; - else - return 0; -} - -int QBasic:: -_OutMem(void) -{ - return _Escape(-2); -} - -int QBasic:: -_CaseCheck(void) -{ - return _Escape(-9); -} - -int QBasic:: -_NilCheck(void) -{ - return _Escape(-3); -} - - - - - -/* The following is suitable for the HP Pascal operating system. - It might want to be revised when emulating another system. */ - -char * QBasic:: -_ShowEscape(char *buf, int code, int ior, char *prefix) -{ - char *bufp; - - if (prefix && *prefix) - { - strcpy(buf, prefix); - strcat(buf, ": "); - bufp = buf + strlen(buf); - } - else - { - bufp = buf; - } - if (code == -10) - { - sprintf(bufp, "Pascal system I/O error %d", ior); - switch (ior) - { - case 3: - strcat(buf, " (illegal I/O request)"); - break; - case 7: - strcat(buf, " (bad file name)"); - break; - case FileNotFound: /*10 */ - strcat(buf, " (file not found)"); - break; - case FileNotOpen: /*13 */ - strcat(buf, " (file not open)"); - break; - case BadInputFormat: /*14 */ - strcat(buf, " (bad input format)"); - break; - case 24: - strcat(buf, " (not open for reading)"); - break; - case 25: - strcat(buf, " (not open for writing)"); - break; - case 26: - strcat(buf, " (not open for direct access)"); - break; - case 28: - strcat(buf, " (string subscript out of range)"); - break; - case EndOfFile: /*30 */ - strcat(buf, " (end-of-file)"); - break; - case FileWriteError: /*38 */ - strcat(buf, " (file write error)"); - break; - } - } - else - { - sprintf(bufp, "Pascal system error %d", code); - switch (code) - { - case -2: - strcat(buf, " (out of memory)"); - break; - case -3: - strcat(buf, " (reference to NIL pointer)"); - break; - case -4: - strcat(buf, " (integer overflow)"); - break; - case -5: - strcat(buf, " (divide by zero)"); - break; - case -6: - strcat(buf, " (real math overflow)"); - break; - case -8: - strcat(buf, " (value range error)"); - break; - case -9: - strcat(buf, " (CASE value range error)"); - break; - case -12: - strcat(buf, " (bus error)"); - break; - case -20: - strcat(buf, " (stopped by user)"); - break; - } - } - return buf; -} - -int QBasic:: -_Escape(int code) -{ - char l_buf[100]; - char token[200], empty[2] = { "\0" }; - - P_escapecode = code; - if (__top_jb) - { - __p2c_jmp_buf *jb = __top_jb; - __top_jb = jb->next; - longjmp(jb->jbuf, 1); - } - if (code == 0) - /* exit(EXIT_SUCCESS); */ - error_msg("Exit success in Basic", STOP); - if (code == -1) - { - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", - _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); - error_msg(token, STOP); - exit(EXIT_FAILURE); - } - /* fprintf(stderr, "%s\n", _ShowEscape(l_buf, P_escapecode, P_ioresult, "")); */ - /* exit(EXIT_FAILURE); */ - error_msg("Fatal error in Basic interpreter.", CONTINUE); - sprintf(token, "%s", _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); - error_msg(token, STOP); - return (1); -} - -int QBasic:: -_EscIO(int code) -{ - P_ioresult = code; - return _Escape(-10); -} - - - - -/* End. */ diff --git a/QBasic/QBasic.h b/QBasic/QBasic.h deleted file mode 100644 index 2154c0b5..00000000 --- a/QBasic/QBasic.h +++ /dev/null @@ -1,486 +0,0 @@ -#ifndef _INC_QBASIC_H -#define _INC_QBASIC_H - -#define forloop 0 -#define whileloop 1 -#define gosubloop 2 - -#define checking true -#define varnamelen 20 -#define maxdims 4 - -typedef char varnamestring[varnamelen + 1]; -typedef char string255[256]; - -/* Header file for code generated by "p2c", the Pascal-to-C translator */ - -/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. - * This file may be copied, modified, etc. in any way. It is not restricted - * by the licence agreement accompanying p2c itself. - */ - -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "PHRQ_io.h" -#include "Phreeqc.h" - -class QBasic: public PHRQ_io -{ -public: - QBasic(PHRQ_io *phrq_io=NULL); - ~QBasic(); -typedef struct __p2c_jmp_buf -{ - struct __p2c_jmp_buf *next; - jmp_buf jbuf; -} __p2c_jmp_buf; - - -/* Warning: The following will not work if setjmp is used simultaneously. - This also violates the ANSI restriction about using vars after longjmp, - but a typical implementation of longjmp will get it right anyway. */ - - -# define TRY(x) do { __p2c_jmp_buf __try_jb; \ - __try_jb.next = __top_jb; \ - if (!setjmp((__top_jb = &__try_jb)->jbuf)) { -# define RECOVER(x) __top_jb = __try_jb.next; } else { -# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ - { L: __top_jb = __try_jb.next; } -# define ENDTRY(x) } } while (0) - -#define SETBITS 32 - -#define Const - -#define P2PP(x) () -#define PV() () -typedef char *Anyptr; - - - - -#define Register register /* Register variables */ -#define char char /* Characters (not bytes) */ - - - - - -typedef struct varrec -{ - varnamestring name; - struct varrec *next; - long dims[maxdims]; - char numdims; - boolean stringvar; - union - { - struct - { - LDBLE *arr; - LDBLE *val, rv; - } U0; - struct - { - char **sarr; - char **sval, *sv; - } U1; - } UU; -} varrec; -typedef struct tokenrec -{ - struct tokenrec *next; - int kind; - union - { - struct varrec *vp; - LDBLE num; - char *sp; - char snch; - } UU; -#ifdef PHREEQCI_GUI - size_t n_sz; - char *sz_num; -#endif -} tokenrec; -typedef struct linerec -{ - long num, num2; - tokenrec *txt; - char inbuf[MAX_LINE]; - struct linerec *next; -} linerec; -typedef struct valrec -{ - boolean stringval; - union - { - LDBLE val; - char *sval; - } UU; -} valrec; - -typedef struct looprec -{ - struct looprec *next; - linerec *homeline; - tokenrec *hometok; - int kind; - union - { - struct - { - varrec *vp; - LDBLE max, step; - } U0; - } UU; -} looprec; - -/* variables for exec: */ -struct LOC_exec -{ - boolean gotoflag, elseflag; - tokenrec *t; -}; - // Methods - int free_dim_stringvar(varrec *varbase); - void exec(void); - int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); - void restoredata(void); - void clearloops(void); - void clearvar(varrec * v); - void clearvars(void); - char * numtostr(char * Result, LDBLE n); - void parse(char * inbuf, tokenrec ** buf); - void listtokens(FILE * f, tokenrec * buf); - void disposetokens(tokenrec ** tok); - void parseinput(tokenrec ** buf); - void errormsg(const char * s); - void snerr(const char * s); - void tmerr(const char * s); - void badsubscr(void); - LDBLE realfactor(struct LOC_exec *LINK); - char * strfactor(struct LOC_exec * LINK); - char *stringfactor(char * Result, struct LOC_exec *LINK); - long intfactor(struct LOC_exec *LINK); - LDBLE realexpr(struct LOC_exec *LINK); - char * strexpr(struct LOC_exec * LINK); - char * stringexpr(char * Result, struct LOC_exec * LINK); - long intexpr(struct LOC_exec *LINK); - void require(int k, struct LOC_exec *LINK); - void skipparen(struct LOC_exec *LINK); - QBasic::varrec * findvar(struct LOC_exec *LINK); - QBasic::valrec factor(struct LOC_exec *LINK); - QBasic::valrec upexpr(struct LOC_exec * LINK); - QBasic::valrec term(struct LOC_exec * LINK); - QBasic::valrec sexpr(struct LOC_exec * LINK); - QBasic::valrec relexpr(struct LOC_exec * LINK); - QBasic::valrec andexpr(struct LOC_exec * LINK); - valrec expr(struct LOC_exec *LINK); - void checkextra(struct LOC_exec *LINK); - boolean iseos(struct LOC_exec *LINK); - void skiptoeos(struct LOC_exec *LINK); - linerec * findline(long n); - linerec * mustfindline(long n); - void cmdend(struct LOC_exec *LINK); - void cmdnew(struct LOC_exec *LINK); - void cmdlist(struct LOC_exec *LINK); - void cmdload(boolean merging, char * name, struct LOC_exec *LINK); - void cmdrun(struct LOC_exec *LINK); - void cmdsave(struct LOC_exec *LINK); - void cmdput(struct LOC_exec *LINK); - void cmdchange_por(struct LOC_exec *LINK); - void cmdchange_surf(struct LOC_exec *LINK); - void cmdbye(void); - void cmddel(struct LOC_exec *LINK); - void cmdrenum(struct LOC_exec *LINK); - void cmdprint(struct LOC_exec *LINK); - void cmdpunch(struct LOC_exec *LINK); - #if defined PHREEQ98 || defined MULTICHART - void cmdgraph_x(struct LOC_exec *LINK); - void cmdgraph_y(struct LOC_exec *LINK); - void cmdgraph_sy(struct LOC_exec *LINK); - #endif - #if defined MULTICHART - void cmdplot_xy(struct LOC_exec *LINK); - #endif - void cmdlet(boolean implied, struct LOC_exec *LINK); - void cmdgoto(struct LOC_exec *LINK); - void cmdif(struct LOC_exec *LINK); - void cmdelse(struct LOC_exec *LINK); - boolean skiploop(int up, int dn, struct LOC_exec *LINK); - void cmdfor(struct LOC_exec *LINK); - void cmdnext(struct LOC_exec *LINK); - void cmdwhile(struct LOC_exec *LINK); - void cmdwend(struct LOC_exec *LINK); - void cmdgosub(struct LOC_exec *LINK); - void cmdreturn(struct LOC_exec *LINK); - void cmdread(struct LOC_exec *LINK); - void cmddata(struct LOC_exec *LINK); - void cmdrestore(struct LOC_exec *LINK); - void cmdgotoxy(struct LOC_exec *LINK); - void cmdon(struct LOC_exec *LINK); - void cmddim(struct LOC_exec *LINK); - void cmdpoke(struct LOC_exec *LINK); -int basic_main(char *commands); -void cmd_initialize(void); -void cmd_free(void); -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -int basic_init(void); -#ifdef PHREEQ98 -void GridChar(char *s, char *a); -#endif -int sget_logical_line(char **ptr, int *l, char *return_line); -void PASCAL_MAIN(int argc, char **argv); -long my_labs(long x); -Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); -Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); -int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); -Anyptr my_memset(Anyptr d, int c, size_t n); -int my_toupper(int c); -int my_tolower(int c); -long ipow(long a, long b); -char * strsub(register char *ret, register char *s, register int pos, - register int len); -int strpos2(char *s, register char *pat, register int pos); -int strcicmp(register char *s1, register char *s2); -char * strltrim(register char *s); -char * strrtrim(register char *s); -void strmove(register int len, register char *s, register int spos, - register char *d, register int dpos); -void strinsert(register char *src, register char *dst, register int pos); -int P_peek(FILE * f); -int P_eof(void); -int P_eoln(FILE * f); -void P_readpaoc(FILE * f, char *s, int len); -void P_readlnpaoc(FILE * f, char *s, int len); -long P_maxpos(FILE * f); -char * P_trimname(register char * fn, register int len); -long memavail(void); -long maxavail(void); -long * P_setunion(register long *d, register long *s1, register long *s2); -long * P_setint(register long *d, register long *s1, register long *s2); -long * P_setdiff(register long *d, register long *s1, register long *s2); -long * P_setxor(register long *d, register long *s1, register long *s2); -long * P_addset(register long *s, register unsigned val); -long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); -long * P_remset(register long *s, register unsigned val); -int P_setequal(register long *s1, register long *s2); -int P_subset(register long *s1, register long *s2); -long * P_setcpy(register long *d, register long *s); -long * P_expset(register long *d, register long s); -long P_packset(register long *s); -int _OutMem(void); -int _CaseCheck(void); -int _NilCheck(void); -static char * _ShowEscape(char *buf, int code, int ior, char *prefix); -int _Escape(int code); -int _EscIO(int code); - - -protected: - Phreeqc * PhreeqcPtr; - char *inbuf; - linerec *linebase; - varrec *varbase; - looprec *loopbase; - long curline; - linerec *stmtline, *dataline; - tokenrec *stmttok, *datatok, *buf; - boolean exitflag; - long EXCP_LINE; - HashTable *command_hash_table; - struct const_key *command; - int NCMDS; - Anyptr __MallocTemp__; - int P_argc; - char **P_argv; - int P_escapecode; - int P_ioresult; - __p2c_jmp_buf *__top_jb; - - int max_line; -}; - - -/* Following defines are suitable for the HP Pascal operating system */ -#define FileNotFound 10 -#define FileNotOpen 13 -#define FileWriteError 38 -#define BadInputFormat 14 -#define EndOfFile 30 - - - - - - -#define tokvar 0 -#define toknum 1 -#define tokstr 2 -#define toksnerr 3 -#define tokplus 4 -#define tokminus 5 -#define toktimes 6 -#define tokdiv 7 -#define tokup 8 -#define toklp 9 -#define tokrp 10 -#define tokcomma 11 -#define toksemi 12 -#define tokcolon 13 -#define tokeq 14 -#define toklt 15 -#define tokgt 16 -#define tokle 17 -#define tokge 18 -#define tokne 19 -#define tokand 20 -#define tokor 21 -#define tokxor 22 -#define tokmod 23 -#define toknot 24 -#define toksqr 25 -#define toksqrt 26 -#define toksin 27 -#define tokcos 28 -#define toktan 29 -#define tokarctan 30 -#define toklog 31 -#define tokexp 32 -#define tokabs 33 -#define toksgn 34 -#define tokstr_ 35 -#define tokval 36 -#define tokchr_ 37 -#define tokasc 38 -#define toklen 39 -#define tokmid_ 40 -#define tokpeek 41 -#define tokrem 42 -#define toklet 43 -#define tokprint 44 -#define tokinput 45 -#define tokgoto 46 -#define tokif 47 -#define tokend 48 -#define tokstop 49 -#define tokfor 50 -#define toknext 51 -#define tokwhile 52 -#define tokwend 53 -#define tokgosub 54 -#define tokreturn 55 -#define tokread 56 -#define tokdata 57 -#define tokrestore 58 -#define tokgotoxy 59 -#define tokon 60 -#define tokdim 61 -#define tokpoke 62 -#define toklist 63 -#define tokrun 64 -#define toknew 65 -#define tokload 66 -#define tokmerge 67 -#define toksave 68 -#define tokbye 69 -#define tokdel 70 -#define tokrenum 71 -#define tokthen 72 -#define tokelse 73 -#define tokto 74 -#define tokstep 75 -#define toktc 76 -#define tokm0 77 -#define tokm 78 -#define tokparm 79 -#define tokact 80 -#define tokmol 81 -#define tokla 82 -#define toklm 83 -#define toksr 84 -#define toksi 85 -#define toktot 86 -#define toktk 87 -#define toktime 88 -#define toklog10 89 -#define toksim_time 90 -#define tokequi 91 -#define tokgas 92 -#define tokpunch 93 -#define tokkin 94 -#define toks_s 95 -#define tokmu 96 -#define tokalk 97 -#define tokrxn 98 -#define tokdist 99 -#define tokmisc1 100 -#define tokmisc2 101 -#define tokedl 102 -#define tokstep_no 103 -#define toksim_no 104 -#define toktotal_time 105 -#define tokput 106 -#define tokget 107 -#define tokcharge_balance 109 -#define tokpercent_error 110 -#if defined PHREEQ98 || MULTICHART -#define tokgraph_x 111 -#define tokgraph_y 112 -#define tokgraph_sy 113 -#endif -#define tokcell_no 114 -#define tokexists 115 -#define toksurf 116 -#define toklk_species 117 -#define toklk_named 118 -#define toklk_phase 119 -#define toksum_species 120 -#define toksum_gas 121 -#define toksum_s_s 122 -#define tokcalc_value 123 -#define tokdescription 124 -#define toksys 125 -#define tokinstr 126 -#define tokltrim 127 -#define tokrtrim 128 -#define toktrim 129 -#define tokpad 130 -#define tokchange_por 131 -#define tokget_por 132 -#define tokosmotic 133 -#define tokchange_surf 134 -#define tokporevolume 135 -#define toksc 136 -#define tokgamma 137 -#define toklg 138 -/* VP: Density Start */ -#define tokrho 139 -/* VP: Density End */ -#define tokcell_volume 140 -#define tokcell_pore_volume 141 -#define tokcell_porosity 142 -#define tokcell_saturation 143 -#if defined MULTICHART -#define tokplot_xy 144 -#endif -#define toktotmole 145 -#define tokiso 146 -#define tokiso_unit 147 -#define toktotmol 148 -#define toktotmoles 149 -#define tokeol_ 150 -#define tokceil 151 -#define tokfloor 152 -#define tokphase_formula 153 -#define toklist_s_s 154 - -#endif /* _INC_QBASIC_H */ diff --git a/QBasic/global.h b/QBasic/global.h deleted file mode 100644 index 4e44db62..00000000 --- a/QBasic/global.h +++ /dev/null @@ -1,808 +0,0 @@ -#ifndef _INC_GLOBAL_H -#define _INC_GLOBAL_H - - PHRQ_io *phrq_io; - -/* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ - - struct model last_model; - int same_model; - int same_temperature; - struct punch punch; -/* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ - - struct temperature *temperature; - int count_temperature; -/* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ - - int g_iterations; - LDBLE G_TOL; - struct surface *surface; - struct surface *dbg_surface; - int count_surface; - int max_surface; - struct Charge_Group *charge_group; - int change_surf_count; - struct Change_Surf *change_surf; - -/* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ - - struct exchange *exchange; - struct exchange *dbg_exchange; - int count_exchange; - int max_exchange; -/* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ - - struct kinetics *kinetics; - struct kinetics *dbg_kinetics; - int count_kinetics; - int max_kinetics; - - int count_save_values; - struct save_values *save_values; - -/*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ - - struct save save; -/*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ - - struct Use use; - struct Use *dbg_use; -/*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ - - struct copier copy_solution; - struct copier copy_pp_assemblage; - struct copier copy_exchange; - struct copier copy_surface; - struct copier copy_s_s_assemblage; - struct copier copy_gas_phase; - struct copier copy_kinetics; - struct copier copy_mix; - struct copier copy_irrev; - struct copier copy_temperature; - - -/*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ - - struct inverse *inverse; - int count_inverse; - -/*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ - - struct mix *mix; - struct mix *dbg_mix; - int count_mix; -/*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ - - struct irrev *irrev; - struct irrev *dbg_irrev; - int count_irrev; -/*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ - - int count_gas_phase; - int max_gas_phase; - struct gas_phase *gas_phase; -/*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ - - int count_s_s_assemblage; - int max_s_s_assemblage; - struct s_s_assemblage *s_s_assemblage; -/*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - - int count_pp_assemblage; - int max_pp_assemblage; - struct pp_assemblage *pp_assemblage; - struct pp_assemblage *dbg_pp_assemblage; -/*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ - - int count_species_list; - int max_species_list; - struct species_list *species_list; -/*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ - - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ -/*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - - struct solution **solution; - struct solution **dbg_solution; - int count_solution; - int max_solution; - -struct iso *iso_defaults; -int count_iso_defaults; - -/*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ - char *title_x; - int new_x; - char *description_x; - LDBLE tc_x; - LDBLE tk_x; - LDBLE ph_x; - LDBLE solution_pe_x; - LDBLE mu_x; - LDBLE ah2o_x; - LDBLE density_x; - LDBLE total_h_x; - LDBLE total_o_x; - LDBLE cb_x; - LDBLE total_ions_x; - LDBLE mass_water_aq_x; - LDBLE mass_water_surfaces_x; - LDBLE mass_water_bulk_x; - char *units_x; - struct pe_data *pe_x; - int count_isotopes_x; - struct isotope *isotopes_x; - int default_pe_x; -/* int diffuse_layer_x;*/ - enum DIFFUSE_LAYER_TYPE dl_type_x; - LDBLE total_carbon; - LDBLE total_co2; - LDBLE total_alkalinity; - LDBLE gfw_water; - LDBLE step_x; - LDBLE kin_time_x; -/*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ - int count_cells; - int count_shifts; - int ishift; - int bcon_first; - int bcon_last; - int correct_disp; - LDBLE tempr; - LDBLE timest; - int simul_tr; - LDBLE diffc; - LDBLE heat_diffc; - int cell; - LDBLE mcd_substeps; - struct stag_data *stag_data; - int print_modulus; - int punch_modulus; - int dump_in; - int dump_modulus; - int transport_warnings; - struct cell_data *cell_data; - int multi_Dflag; /* signals calc'n of multicomponent diffusion */ - int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ - LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ - LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ - LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ - LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ - LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ - LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, - Dp = Dw * (multi_Dpor)^multi_Dn */ - LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, - Dpil = Dw / interlayer_tortf */ - - int cell_no; -/*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ - int count_ad_cells; - int count_ad_shifts; - int print_ad_modulus; - int punch_ad_modulus; - int *advection_punch, *advection_print; - LDBLE advection_kin_time; - LDBLE advection_kin_time_defined; - int advection_warnings; - -/*---------------------------------------------------------------------- - * Keywords - *---------------------------------------------------------------------- */ -struct const_key *keyword; -int NKEYS; - - struct key *keyword_hash; - int new_model, new_exchange, new_pp_assemblage, new_surface, - new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, - new_pitzer; -/*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ - - struct element **elements; - int count_elements; - int max_elements; - struct element *element_h_one; - -/*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ - - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ - int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; -/*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ - -/*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ - - struct logk **logk; - int count_logk; - int max_logk; - - char *moles_per_kilogram_string; - char *pe_string; - - struct species **s; - int count_s; - int max_s; - - struct species **s_x; - int count_s_x; - int max_s_x; - - struct species *s_h2o; - struct species *s_hplus; - struct species *s_h3oplus; - struct species *s_eminus; - struct species *s_co3; - struct species *s_h2; - struct species *s_o2; -/*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ - - struct phase **phases; - int count_phases; - int max_phases; -/*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ - - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; -/*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ - - struct unknown **x; - int count_unknowns; - int max_unknowns; - - struct unknown *ah2o_unknown; - struct unknown *alkalinity_unknown; - struct unknown *carbon_unknown; - struct unknown *charge_balance_unknown; - struct unknown *exchange_unknown; - struct unknown *mass_hydrogen_unknown; - struct unknown *mass_oxygen_unknown; - struct unknown *mb_unknown; - struct unknown *mu_unknown; - struct unknown *pe_unknown; - struct unknown *ph_unknown; - struct unknown *pure_phase_unknown; - struct unknown *solution_phase_boundary_unknown; - struct unknown *surface_unknown; - struct unknown *gas_unknown; - struct unknown *s_s_unknown; -/*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ - - struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; - - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; -/* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ - - struct prints pr; - int status_on, status_interval; - float status_timer; - int count_warnings; - -/* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ - - struct rate *rates; - int count_rates; - LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, - rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; - int count_rate_p; -/* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ - struct rate *user_print; - struct rate *user_punch; - char **user_punch_headings; - int user_punch_count_headings; -#if defined PHREEQ98 - struct rate *user_graph; - char **user_graph_headings; - int user_graph_count_headings; -#endif -#if defined MULTICHART - ChartHandler chart_handler; -#endif - -/* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ - char error_string[10 * MAX_LENGTH]; - int simulation; - int state; - int reaction_step; - int transport_step; - int transport_start; - int advection_step; - int stop_program; - int incremental_reactions; - - int count_strings; - int max_strings; - - LDBLE *array; - LDBLE *delta; - LDBLE *residual; - - int input_error; - - int next_keyword; - int parse_error; - int paren_count; - int iterations; - int gamma_iterations; - int run_reactions_iterations; - - int max_line; - char *line; - char *line_save; - - LDBLE LOG_10; - - int debug_model; - int debug_prep; - int debug_set; - int debug_diffuse_layer; - int debug_inverse; - - LDBLE inv_tol_default; - int itmax; - LDBLE ineq_tol; - LDBLE convergence_tolerance; - LDBLE step_size; - LDBLE pe_step_size; - LDBLE step_size_now; - LDBLE pe_step_size_now; - LDBLE pp_scale; - LDBLE pp_column_scale; - int diagonal_scale; /* 0 not used, 1 used */ - int mass_water_switch; - int delay_mass_water; - LDBLE censor; - int aqueous_only; - int negative_concentrations; - int calculating_deriv; - int numerical_deriv; - - int count_total_steps; - int phast; - LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; - int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, - llnl_count_co2_coefs; - - char *selected_output_file_name; - char *dump_file_name; - int remove_unstable_phases; - -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif - -/* ---------------------------------------------------------------------- */ -/* - * Hash definitions - */ - - HashTable *strings_hash_table; - HashTable *elements_hash_table; - HashTable *species_hash_table; - HashTable *phases_hash_table; - HashTable *keyword_hash_table; - HashTable *logk_hash_table; - HashTable *master_isotope_hash_table; - -#if defined(PHREEQCI_GUI) -#include "../../phreeqci_gui.h" -#endif /* defined(PHREEQCI_GUI) */ -/* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ - struct name_coef match_tokens[50]; - int count_match_tokens; - - int count_master_isotope; - struct master_isotope **master_isotope; - int max_master_isotope; - int initial_solution_isotopes; - -#define OPTION_EOF -1 -#define OPTION_KEYWORD -2 -#define OPTION_ERROR -3 -#define OPTION_DEFAULT -4 -#define OPT_1 -5 - - - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; - HashTable *calculate_value_hash_table; - - - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; - HashTable *isotope_ratio_hash_table; - - int count_isotope_alpha; - struct isotope_alpha **isotope_alpha; - int max_isotope_alpha; - HashTable *isotope_alpha_hash_table; - - int phreeqc_mpi_myself; - - int first_read_input; - char *user_database; - int pitzer_model, sit_model, pitzer_pe; - int full_pitzer, always_full_pitzer, ICON, IC; - LDBLE COSMOT; - LDBLE AW; - int have_punch_name; -/* VP: Density Start */ - int print_density; -/* VP: Density End */ - - jmp_buf mark; - LDBLE *zeros; - int zeros_max; -#if defined(WIN32) -#include -#endif - -#if defined(WIN32_MEMORY_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif - - LDBLE cell_pore_volume; - LDBLE cell_porosity; - LDBLE cell_volume; - LDBLE cell_saturation; - - struct system_species *sys; - int count_sys, max_sys; - - LDBLE sys_tot; - LDBLE AA_basic, BB_basic, CC, I_m, rho_0; - LDBLE solution_mass, solution_volume; - LDBLE f_rho(LDBLE rho_old); - -/* phqalloc.c ------------------------------- */ - - PHRQMemHeader *s_pTail; -#include - std::stringstream merged_database_stream; - std::stringstream merged_input_stream; -/* Collect all statics for PHREEQC_CLASS */ - -/* basic.c ------------------------------- */ - -#ifdef PHREEQ98 -int colnr, rownr; -#endif - -int n_user_punch_index; -//Char *inbuf; -//linerec *linebase; -//varrec *varbase; -//looprec *loopbase; -//long curline; -//linerec *stmtline, *dataline; -//tokenrec *stmttok, *datatok, *buf; -//boolean exitflag; -//long EXCP_LINE; -//HashTable *command_hash_table; -//struct const_key *command; -//int NCMDS; - -/* cl1.c ------------------------------- */ - -LDBLE *x_arg, *res_arg, *scratch; -int x_arg_max, res_arg_max, scratch_max; - -/* dw.c ------------------------------- */ - -/* COMMON /QQQQ/ */ -LDBLE Q0, Q5; -LDBLE GASCON, TZ, AA; -LDBLE Z, DZ, Y; -LDBLE G1, G2, GF; -LDBLE B1, B2, B1T, B2T, B1TT, B2TT; - -/* input.cpp ------------------------------- */ - -int check_line_return; - -/* integrate.cpp ------------------------------- */ - -LDBLE midpoint_sv; -LDBLE z, xd, alpha; -struct surface_charge *surface_charge_ptr; -int max_row_count, max_column_count; -int carbon; -char **col_name, **row_name; -int count_rows, count_optimize; -int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; -int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; -LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; -LDBLE *min_delta, *max_delta; -int *iu, *is; -int klmd, nklmd, n2d, kode, iter; -LDBLE toler, error, max_pct, scaled_error; -struct master *master_alk; -int *row_back, *col_back; -unsigned long *good, *bad, *minimal; -int max_good, max_bad, max_minimal; -int count_good, count_bad, count_minimal, count_calls; -unsigned long soln_bits, phase_bits, current_bits, temp_bits; - -/* inverse.c ------------------------------- */ - -FILE *netpath_file; -int count_inverse_models, count_pat_solutions; -int min_position[32], max_position[32], now[32]; - -/* kinetics.c ------------------------------- */ - -public: - void *cvode_kinetics_ptr; - int cvode_test; - int cvode_error; - int cvode_n_user; - int cvode_n_reactions; - realtype cvode_step_fraction; - realtype cvode_rate_sim_time; - realtype cvode_rate_sim_time_start; - realtype cvode_last_good_time; - realtype cvode_prev_good_time; - N_Vector cvode_last_good_y; - N_Vector cvode_prev_good_y; - M_Env kinetics_machEnv; - N_Vector kinetics_y, kinetics_abstol; - void *kinetics_cvode_mem; - struct pp_assemblage *cvode_pp_assemblage_save; - struct s_s_assemblage *cvode_s_s_assemblage_save; - LDBLE *m_original; - LDBLE *m_temp; - -/* model.c ------------------------------- */ - -LDBLE min_value; -/* LDBLE model_min_value; */ -LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; -int *inv_iu, *inv_is, *back_eq; -int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; - -/* phrq_io_output.c ------------------------------- */ -int forward_output_to_log; - -/* phreeqc_files.c ------------------------------- */ - -char *default_data_base; -#ifdef PHREEQ98 -int outputlinenr; -char *LogFileNameC; -char progress_str[512]; -#endif -//Anyptr __MallocTemp__; -//int P_argc; -//char **P_argv; -//int P_escapecode; -//int P_ioresult; -//__p2c_jmp_buf *__top_jb; - -/* pitzer.c ------------------------------- */ - -LDBLE A0; -struct species **spec, **cations, **anions, **neutrals; -int count_cations, count_anions, count_neutrals; -int MAXCATIONS, FIRSTANION, MAXNEUTRAL; -struct pitz_param *mcb0, *mcb1, *mcc0; -int *IPRSNT; -LDBLE *M, *LGAMMA; -LDBLE BK[23], DK[23]; -#ifdef PHREEQ98 -int connect_simulations, graph_initial_solutions; -int shifts_as_points; -int chart_type; -int ShowChart; -int RowOffset, ColumnOffset; -#endif -LDBLE dummy; - -/* print.c ------------------------------- */ - -#ifdef PHREEQ98 -int colnr, rownr; -int graph_initial_solutions; -int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ -/* int shifts_as_points; */ -int chart_type; -int AddSeries; -int FirstCallToUSER_GRAPH; -#endif -/* read.c */ -char *prev_next_char; -#if defined PHREEQ98 -int shifts_as_points; -#endif - -/* read_class.cxx */ -dumper dump_info; -StorageBinList delete_info; -runner run_info; -char * sformatf_buffer; -size_t sformatf_buffer_size; - -/* readtr.c */ - -std::string dump_file_name_cpp; - -/* sit.c ------------------------------- */ - -LDBLE sit_A0; -int sit_count_cations, sit_count_anions, sit_count_neutrals; -int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; -int *sit_IPRSNT; -LDBLE *sit_M, *sit_LGAMMA; - -/* tidy.c ------------------------------- */ - -LDBLE a0, a1, kc, kb; - -/* tally.c ------------------------------- */ - - -struct tally_buffer *t_buffer; -int tally_count_component; - -struct tally *tally_table; -int count_tally_table_columns; -int count_tally_table_rows; - -/* transport.c ------------------------------- */ - - -struct sol_D *sol_D; -struct sol_D *sol_D_dbg; -struct J_ij *J_ij, *J_ij_il; -int J_ij_count_spec; - -struct M_S *m_s; -int count_m_s; -LDBLE tot1_h, tot1_o, tot2_h, tot2_o; -LDBLE diffc_max, diffc_tr, J_ij_sum; -int transp_surf; -LDBLE *heat_mix_array; -LDBLE *temp1, *temp2; -int nmix, heat_nmix; -LDBLE heat_mix_f_imm, heat_mix_f_m; -int warn_MCD_X, warn_fixed_Surf; - -/* utilities.c ------------------------------- */ - -#ifdef PHREEQ98 -int AutoLoadOutputFile, CreateToC; -int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; -int outputlinenr; -int stop_calculations; -char err_str98[80]; -#endif - - -#endif /* _INC_GLOBAL_H */ - -/********************************* - isfinite handling - (Note: Should NOT be guarded) -**********************************/ - -#if defined (PHREEQ98) || defined (_MSC_VER) -# define HAVE_FINITE -# define finite _finite -#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ -# if defined(DJGPP) -# define HAVE_FINITE -# endif -#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ - -#if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) -#elif defined(HAVE_FINITE) -# define PHR_ISFINITE(x) finite(x) -#elif defined(HAVE_ISNAN) -# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) -#else -# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) -#endif diff --git a/QBasic/global_structures.h b/QBasic/global_structures.h deleted file mode 100644 index 74124408..00000000 --- a/QBasic/global_structures.h +++ /dev/null @@ -1,1375 +0,0 @@ -#ifndef _INC_GLOBAL_STRUCTURES_H -#define _INC_GLOBAL_STRUCTURES_H - -#include "phrqtype.h" -typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; -enum SURFACE_TYPE -{ UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC, CCM }; -enum DIFFUSE_LAYER_TYPE -{ NO_DL, BORKOVEK_DL, DONNAN_DL }; -enum SITES_UNITS -{ SITES_ABSOLUTE, SITES_DENSITY }; -enum entity_type -{ Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, - Kinetics, Mix, Temperature, UnKnown -}; -/* must be defined here and in cl.c */ -/* #include */ -#ifndef NAN -# define NAN -99999999 -#endif -#define MISSING -9999.999 -//#define NA -98.765 /* NA = not available */ -#include "NA.h" -/* search.h -- declarations for POSIX/SVID-compatible search functions */ - - - -/* ---------------------------------------------------------------------- - * DEFINITIONS - * ---------------------------------------------------------------------- */ -#define F_C_MOL 96493.5 /* C/mol or joule/volt-eq */ -#define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ -#define F_KCAL_V_EQ 23.0623 /* kcal/volt-eq */ -#define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ -#define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ -#define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ -#define EPSILON 78.5 /* dialectric constant, dimensionless */ -#define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ -#define JOULES_PER_CALORIE 4.1840 -#define AVOGADRO 6.02252e23 /* atoms / mole */ - - -#define TRUE 1 -#define FALSE 0 -#define OK 1 -#define ERROR 0 -#define STOP 1 -#define CONTINUE 0 - -#define DISP 2 -#define STAG 3 -#define NOMIX 4 - -#define CONVERGED 2 -#define MASS_BALANCE 3 -/* - #define OSCILLATE 4 - #define H2O_LIMITS 5 -*/ -#define REWRITE 2 -#define INIT -1 - -/* check_line values, plus EMPTY, EOF, OK */ -#define KEYWORD 3 - -/* copy_token values */ -#define EMPTY 2 -#define UPPER 4 -#define LOWER 5 -#define DIGIT 6 -#define UNKNOWN 7 -#define OPTION 8 - -/* species types */ -#define AQ 0 -#define HPLUS 1 -#define H2O 2 -#define EMINUS 3 -#define SOLID 4 -#define EX 5 -#define SURF 6 -#define SURF_PSI 7 -#define SURF_PSI1 8 -#define SURF_PSI2 9 - -/* unknown types */ -#define MB 10 -#define ALK 11 -#define CB 12 -#define SOLUTION_PHASE_BOUNDARY 13 -#define MU 14 -#define AH2O 15 -#define MH 16 -#define MH2O 17 -#define PP 18 -#define EXCH 19 -#define SURFACE 20 -#define SURFACE_CB 21 -#define SURFACE_CB1 22 -#define SURFACE_CB2 23 -#define GAS_MOLES 24 -#define S_S_MOLES 25 -#define PITZER_GAMMA 26 -/* state */ -#define INITIALIZE 0 -#define INITIAL_SOLUTION 1 -#define INITIAL_EXCHANGE 2 -#define INITIAL_SURFACE 3 -#define INITIAL_GAS_PHASE 4 -#define REACTION 5 -#define INVERSE 6 -#define ADVECTION 7 -#define TRANSPORT 8 -#define PHAST 9 - -/* constaints in mass balance */ -#define EITHER 0 -#define DISSOLVE 1 -#define PRECIPITATE -1 - -/* gas phase type */ -#define PRESSURE 1 -#define VOLUME 2 - -#define MAX_PP_ASSEMBLAGE 10 /* default estimate of the number of phase assemblages */ -#define MAX_ADD_EQUATIONS 20 /* maximum number of equations added together to reduce eqn to - master species */ -#define MAX_ELEMENTS 50 /* default estimate of the number of elements */ -#define MAX_LENGTH 256 /* maximum number of characters component name */ -#define MAX_LINE 4096 /* estimate of maximum line length */ -#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ -#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ -#define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ -#define MAX_MASTER 50 /* default estimate of the number of master species */ -#define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in - an equation */ -#define MAX_PHASES 500 /* initial guess of number of phases defined */ -#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ -#define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ -#define MAX_STRINGS 3000 -#define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ -#define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ -#define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ -#define MAX_SUM_MB 500 /* list used to calculate mass balance sums */ -#define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ -#define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ -#define TOL 1e-9 /* tolerance for comparisons of double numbers */ -#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-25 -#define MIN_TOTAL_SS MIN_TOTAL/100 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -30 - - -/* - * Hash definitions - */ -/* -** Constants -*/ - -# define SegmentSize 256 -# define SegmentSizeShift 8 /* log2(SegmentSize) */ -# define DirectorySize 256 -# define DirectorySizeShift 8 /* log2(DirectorySize) */ -# define Prime1 37 -# define Prime2 1048583 -# define DefaultMaxLoadFactor 5 - -/* HSEARCH(3C) */ -typedef struct entry -{ - char *key; - void *data; -} ENTRY; -typedef enum -{ FIND, ENTER } ACTION; - -/* TSEARCH(3C) */ -typedef enum -{ preorder, postorder, endorder, leaf } VISIT; - -typedef struct Element -{ - /* - ** The user only sees the first two fields, - ** as we pretend to pass back only a pointer to ENTRY. - ** {S}he doesn't know what else is in here. - */ - char *Key; - char *Data; - struct Element *Next; /* secret from user */ -} Element, *Segment; - -typedef struct -{ - short p; /* Next bucket to be split */ - short maxp; /* upper bound on p during expansion */ - long KeyCount; /* current # keys */ - short SegmentCount; /* current # segments */ - short MinLoadFactor; - short MaxLoadFactor; - Segment *Directory[DirectorySize]; -} HashTable; - -typedef unsigned long Address; - -typedef struct PHRQMemHeader -{ - struct PHRQMemHeader *pNext; /* memory allocated just after this one */ - struct PHRQMemHeader *pPrev; /* memory allocated just prior to this one */ - size_t size; /* memory request + sizeof(PHRQMemHeader) */ -#if !defined(NDEBUG) - char *szFileName; /* file name */ - int nLine; /* line number */ - int dummy; /* alignment */ -#endif -} PHRQMemHeader; - -struct model -{ - int force_prep; - LDBLE temperature; - int count_exchange; - struct master **exchange; - - int count_kinetics; - struct kinetics *kinetics; - - int count_gas_phase; - struct phase **gas_phase; - - int count_s_s_assemblage; - char **s_s_assemblage; - - int count_pp_assemblage; - struct phase **pp_assemblage; - char **add_formula; - LDBLE *si; - - /*int diffuse_layer; */ - /*int edl; */ - enum DIFFUSE_LAYER_TYPE dl_type; - enum SURFACE_TYPE surface_type; - int only_counter_ions; - /*int donnan; */ - LDBLE thickness; - int count_surface_comp; - char **surface_comp; - int count_surface_charge; - char **surface_charge; -}; - -struct name_master -{ - char *name; - struct master *master; -}; -struct name_species -{ - char *name; - struct species *s; -}; -struct name_phase -{ - char *name; - struct phase *phase; -}; -struct punch -{ - int in; - int new_def; - struct name_master *totals; - int count_totals; - struct name_species *molalities; - int count_molalities; - struct name_species *activities; - int count_activities; - struct name_phase *pure_phases; - int count_pure_phases; - struct name_phase *si; - int count_si; - struct name_phase *gases; - int count_gases; - struct name_phase *s_s; - int count_s_s; - struct name_phase *kinetics; - int count_kinetics; - struct name_master *isotopes; - int count_isotopes; - struct name_master *calculate_values; - int count_calculate_values; - int inverse; - int sim; - int state; - int soln; - int dist; - int time; - int step; - int rxn; - int temp; - int ph; - int pe; - int alk; - int mu; - int water; - int high_precision; - int user_punch; - int charge_balance; - int percent_error; -}; -/* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ -struct temperature -{ - int n_user; - int n_user_end; - char *description; - LDBLE *t; - int count_t; -}; -/* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ -struct surface -{ - int n_user; - int n_user_end; - int new_def; - /*int diffuse_layer; */ - /*int edl; */ - int only_counter_ions; - /*int donnan; */ - enum DIFFUSE_LAYER_TYPE dl_type; - enum SURFACE_TYPE type; - enum SITES_UNITS sites_units; - LDBLE thickness; - LDBLE debye_lengths; - LDBLE DDL_viscosity; /* viscosity relative to pure water */ - LDBLE DDL_limit; /* limits DDL water to this fraction of bulk water */ - char *description; - int solution_equilibria; - int n_solution; - int count_comps; - struct surface_comp *comps; - int count_charge; - struct surface_charge *charge; - int related_phases; - int related_rate; - int transport; /* transports comp's and charges if true */ -}; -struct surface_comp -{ - char *formula; - struct elt_list *formula_totals; - LDBLE formula_z; - LDBLE moles; - struct master *master; - struct elt_list *totals; - LDBLE la; - int charge; - LDBLE cb; - char *phase_name; - LDBLE phase_proportion; - char *rate_name; - LDBLE Dw; /* diffusion coefficient in water, used in MCD. No transport if 0 */ -}; -struct surface_charge -{ - char *name; - LDBLE specific_area; - LDBLE grams; - LDBLE charge_balance; - LDBLE mass_water; - struct elt_list *diffuse_layer_totals; - int count_g; - struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ - LDBLE la_psi, la_psi1, la_psi2; - LDBLE psi, psi1, psi2; - LDBLE capacitance[2]; - LDBLE sigma0, sigma1, sigma2, sigmaddl; -}; -struct surface_diff_layer -{ - LDBLE charge; - LDBLE g; - LDBLE dg; - LDBLE psi_to_z; -}; - -struct Change_Surf -{ - char *comp_name; - LDBLE fraction; - char *new_comp_name; - LDBLE new_Dw; - int cell_no; - int next; -}; - -struct Charge_Group -{ - LDBLE z; - LDBLE eq; -}; -/* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ -struct exchange -{ - int n_user; - int n_user_end; - int new_def; - char *description; - int solution_equilibria; - int n_solution; - int count_comps; - struct exch_comp *comps; - int related_phases; - int related_rate; - int pitzer_exchange_gammas; -}; -struct exch_comp -{ - char *formula; - LDBLE formula_z; - struct elt_list *formula_totals; - LDBLE moles; - struct master *master; - struct elt_list *totals; - LDBLE la; - LDBLE charge_balance; - char *phase_name; - LDBLE phase_proportion; - char *rate_name; -}; -/* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ -struct kinetics -{ - int n_user; - int n_user_end; - char *description; - int count_comps; - struct kinetics_comp *comps; - int count_steps; - LDBLE *steps; - LDBLE step_divide; - /*char *units; */ - struct elt_list *totals; - int rk; - int bad_step_max; - int use_cvode; - int cvode_order; - int cvode_steps; -}; -struct kinetics_comp -{ - char *rate_name; - struct name_coef *list; - int count_list; - /* struct phase *phase; */ - LDBLE tol; - LDBLE m; - LDBLE initial_moles; - LDBLE m0; - LDBLE moles; - int count_c_params; - char **c_params; - int count_d_params; - LDBLE *d_params; -}; - -/*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ -struct save_values -{ - LDBLE value; - int count_subscripts; - int *subscripts; -}; - -struct save -{ - int solution; - int n_solution_user; - int n_solution_user_end; - int mix; - int n_mix_user; - int n_mix_user_end; - int irrev; - int n_irrev_user; - int n_irrev_user_end; - int pp_assemblage; - int n_pp_assemblage_user; - int n_pp_assemblage_user_end; - int exchange; - int n_exchange_user; - int n_exchange_user_end; - int kinetics; - int n_kinetics_user; - int n_kinetics_user_end; - int surface; - int n_surface_user; - int n_surface_user_end; - int gas_phase; - int n_gas_phase_user; - int n_gas_phase_user_end; - int s_s_assemblage; - int n_s_s_assemblage_user; - int n_s_s_assemblage_user_end; -}; -/*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ -struct Use -{ - int solution_in; - int n_solution_user; - int n_solution; - struct solution *solution_ptr; - - int pp_assemblage_in; - int n_pp_assemblage_user; - int n_pp_assemblage; - struct pp_assemblage *pp_assemblage_ptr; - - int mix_in; - int n_mix_user; - int n_mix; - struct mix *mix_ptr; - int n_mix_user_orig; - - int irrev_in; - int n_irrev_user; - int n_irrev; - struct irrev *irrev_ptr; - - int exchange_in; - int n_exchange_user; - int n_exchange; - struct exchange *exchange_ptr; - - int kinetics_in; - int n_kinetics_user; - int n_kinetics; - struct kinetics *kinetics_ptr; - - int surface_in; - int n_surface_user; - int n_surface; - struct surface *surface_ptr; - - int temperature_in; - int n_temperature_user; - int n_temperature; - struct temperature *temperature_ptr; - - int inverse_in; - int n_inverse_user; - int n_inverse; - struct inverse *inverse_ptr; - - int gas_phase_in; - int n_gas_phase_user; - int n_gas_phase; - struct gas_phase *gas_phase_ptr; - - int s_s_assemblage_in; - int n_s_s_assemblage_user; - int n_s_s_assemblage; - struct s_s_assemblage *s_s_assemblage_ptr; - - int trans_in; - int advect_in; -}; -/*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ -struct copier -{ - int count; - int max; - int *n_user; - int *start; - int *end; -}; - -/*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ -struct inverse -{ - int n_user; - char *description; - int new_def; - int minimal; - int range; - int mp; - LDBLE mp_censor; - LDBLE range_max; - LDBLE tolerance; - LDBLE mp_tolerance; - int count_uncertainties; - LDBLE *uncertainties; - int count_ph_uncertainties; - LDBLE *ph_uncertainties; - LDBLE water_uncertainty; - int mineral_water; - int carbon; - LDBLE *dalk_dph; - LDBLE *dalk_dc; - int count_solns; - int *solns; - int count_force_solns; - int *force_solns; - int count_elts; - struct inv_elts *elts; - int count_phases; - struct inv_phases *phases; - int count_master_list; - struct master **master_list; - int count_redox_rxns; - int count_isotopes; - struct inv_isotope *isotopes; - int count_i_u; - struct inv_isotope *i_u; - int count_isotope_unknowns; - struct isotope *isotope_unknowns; - char *netpath; - char *pat; -}; -struct inv_elts -{ - char *name; - struct master *master; - int row; - int count_uncertainties; - LDBLE *uncertainties; -}; -struct inv_isotope -{ - char *isotope_name; - LDBLE isotope_number; - char *elt_name; - int count_uncertainties; - LDBLE *uncertainties; -}; -struct inv_phases -{ - char *name; - struct phase *phase; - int column; - int constraint; - int force; - int count_isotopes; - struct isotope *isotopes; -}; - -/*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ -struct mix -{ - int n_user; - int n_user_end; - char *description; - int count_comps; - struct mix_comp *comps; -}; -struct mix_comp -{ - int n_solution; - LDBLE fraction; -}; - -/*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ -struct irrev -{ - int n_user; - int n_user_end; - char *description; - struct name_coef *list; - struct elt_list *elts; - LDBLE *steps; - char *units; - int count_steps; - int count_list; -}; -struct name_coef -{ - char *name; - LDBLE coef; -}; -/*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ -struct gas_phase -{ - int n_user; - int n_user_end; - char *description; - int new_def; - int solution_equilibria; - int n_solution; - int type; - LDBLE total_p; - LDBLE total_moles; - LDBLE volume; - LDBLE temperature; - int count_comps; - struct gas_comp *comps; -}; -struct gas_comp -{ - struct phase *phase; - char *name; - LDBLE p_read; - LDBLE moles; - LDBLE initial_moles; -}; - -/*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ -struct s_s_assemblage -{ - int n_user; - int n_user_end; - char *description; - int new_def; - /* int type; */ - /* int solution_equilibria; */ - /* int n_solution; */ - int count_s_s; - struct s_s *s_s; -}; -struct s_s -{ - char *name; - struct s_s_comp *comps; - int count_comps; - LDBLE total_moles; - LDBLE dn; - LDBLE a0, a1; - LDBLE ag0, ag1; - int s_s_in; - int miscibility; - int spinodal; - LDBLE tk, xb1, xb2; - int input_case; - LDBLE p[4]; -}; -struct s_s_comp -{ - char *name; - struct phase *phase; - LDBLE initial_moles; - LDBLE moles; - LDBLE init_moles; - LDBLE delta; - LDBLE fraction_x; - LDBLE log10_lambda; - LDBLE log10_fraction_x; - LDBLE dn, dnc, dnb; -}; - -/*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - struct pp_assemblage - { - int n_user; - int n_user_end; - char *description; - int new_def; - struct elt_list *next_elt; - int count_comps; - struct pure_phase *pure_phases; - }; - struct pure_phase - { - struct phase *phase; - char *name; - char *add_formula; - LDBLE si; - LDBLE moles; - LDBLE delta; - LDBLE initial_moles; - int force_equality; - int dissolve_only; - int precipitate_only; -}; - -/*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ -struct species_list -{ - struct species *master_s; - struct species *s; - LDBLE coef; -}; - -/*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ -struct list0 -{ - LDBLE *target; - LDBLE coef; -}; -struct list1 -{ - LDBLE *source; - LDBLE *target; -}; -struct list2 -{ - LDBLE *source; - LDBLE *target; - LDBLE coef; -}; - -/*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - struct solution - { - int new_def; - int n_user; - int n_user_end; - char *description; - LDBLE tc; - LDBLE ph; - LDBLE solution_pe; - LDBLE mu; - LDBLE ah2o; - LDBLE density; - LDBLE total_h; - LDBLE total_o; - LDBLE cb; - LDBLE mass_water; - LDBLE total_alkalinity; - char *units; - struct pe_data *pe; - int default_pe; - struct conc *totals; - struct master_activity *master_activity; - int count_master_activity; - int count_isotopes; - struct isotope *isotopes; - struct master_activity *species_gamma; - int count_species_gamma; - }; - struct master_activity - { - char *description; - LDBLE la; - }; - struct conc - { - char *description; - /*int skip; */ - LDBLE moles; - LDBLE input_conc; - char *units; - char *equation_name; - struct phase *phase; - LDBLE phase_si; - int n_pe; - char *as; - LDBLE gfw; - }; - struct pe_data - { - char *name; - struct reaction *rxn; - }; - struct isotope - { - LDBLE isotope_number; - char *elt_name; - char *isotope_name; - LDBLE total; - LDBLE ratio; - LDBLE ratio_uncertainty; - LDBLE x_ratio_uncertainty; - struct master *master; - struct master *primary; - LDBLE coef; /* coefficient of element in phase */ -}; -struct iso -{ - const char *name; - LDBLE value; - LDBLE uncertainty; -}; -/*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ -struct stag_data -{ - int count_stag; - LDBLE exch_f; - LDBLE th_m; - LDBLE th_im; -}; -struct cell_data -{ - LDBLE length; - LDBLE mid_cell_x; - LDBLE disp; - LDBLE temp; - LDBLE por; /* free (uncharged) porewater porosities */ - LDBLE por_il; /* interlayer water porosities */ - int punch; - int print; -}; - -/*---------------------------------------------------------------------- - * Keywords - *---------------------------------------------------------------------- */ - struct key - { - char *name; - int keycount; - }; - struct const_key - { - const char *name; - int keycount; -}; - -/*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ -struct element -{ - char *name; /* element name */ - /* int in; */ - struct master *master; - struct master *primary; - LDBLE gfw; -}; -/*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ -struct elt_list -{ /* list of name and number of elements in an equation */ - struct element *elt; /* pointer to element structure */ - LDBLE coef; /* number of element e's in eqn */ -}; -/*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ -struct reaction -{ - LDBLE logk[8]; - LDBLE dz[3]; - struct rxn_token *token; -}; -struct rxn_token -{ - struct species *s; - LDBLE coef; - char *name; -}; -/*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ -struct species -{ /* all data pertinent to an aqueous species */ - char *name; /* name of species */ - char *mole_balance; /* formula for mole balance */ - int in; /* species used in model if TRUE */ - int number; - struct master *primary; /* points to master species list, NULL if not primary master */ - struct master *secondary; /* points to master species list, NULL if not secondary master */ - LDBLE gfw; /* gram formula wt of species */ - LDBLE z; /* charge of species */ - LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */ - LDBLE erm_ddl; /* enrichment factor in DDL */ - LDBLE equiv; /* equivalents in exchange species */ - LDBLE alk; /* alkalinity of species, used for cec in exchange */ - LDBLE carbon; /* stoichiometric coefficient of carbon in species */ - LDBLE co2; /* stoichiometric coefficient of C(4) in species */ - LDBLE h; /* stoichiometric coefficient of H in species */ - LDBLE o; /* stoichiometric coefficient of O in species */ - LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ -/* VP: Density Start */ - LDBLE millero[6]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ -/* VP: Density End */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ - int count_add_logk; - struct name_coef *add_logk; - LDBLE lg; /* log10 activity coefficient, gamma */ - LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */ - LDBLE lm; /* log10 molality */ - LDBLE la; /* log10 activity */ - LDBLE dg; /* gamma term for jacobian */ - LDBLE dg_total_g; - LDBLE moles; /* moles in solution; moles/mass_water = molality */ - int type; /* flag indicating presence in model and types of equations */ - int gflag; /* flag for preferred activity coef eqn */ - int exch_gflag; /* flag for preferred activity coef eqn */ - struct elt_list *next_elt; /* pointer to next element */ - struct elt_list *next_secondary; - struct elt_list *next_sys_total; - int check_equation; /* switch to check equation for charge and element balance */ - struct reaction *rxn; /* pointer to data base reaction */ - struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary - master species */ - struct reaction *rxn_x; /* reaction to be used in model */ - LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ - LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ - struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each - surface */ - LDBLE cd_music[5]; - LDBLE dz[3]; -}; -struct logk -{ /* Named log K's */ - char *name; /* name of species */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE log_k[8]; /* log kt0, delh, 6 coefficients analalytical expression */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ - int count_add_logk; - int done; - struct name_coef *add_logk; - LDBLE log_k_original[8]; /* log kt0, delh, 5 coefficients analalytical expression */ -}; -struct species_diff_layer -{ - struct surface_charge *charge; - int count_g; - LDBLE g_moles; - LDBLE dg_g_moles; /* g_moles*dgterm */ - LDBLE dx_moles; - LDBLE dh2o_moles; /* moles*g*Ws/Waq */ - LDBLE drelated_moles; /* for related phase */ -}; - -/*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ -struct phase -{ /* all data pertinent to a pure solid phase */ - char *name; /* name of species */ - char *formula; /* chemical formula */ - int in; /* species used in model if TRUE */ - LDBLE lk; /* log10 k at working temperature */ - LDBLE logk[8]; /* log kt0, delh, 6 coefficients analalytical expression */ - DELTA_H_UNIT original_units; /* enum with original delta H units */ - int count_add_logk; - struct name_coef *add_logk; - LDBLE moles_x; - LDBLE delta_max; - LDBLE p_soln_x; - LDBLE fraction_x; - LDBLE log10_lambda, log10_fraction_x; - LDBLE dn, dnb, dnc; - LDBLE gn, gntot; - LDBLE gn_n, gntot_n; - - int type; /* flag indicating presence in model and types of equations */ - struct elt_list *next_elt; /* pointer to list of elements in phase */ - struct elt_list *next_sys_total; - int check_equation; /* switch to check equation for charge and element balance */ - struct reaction *rxn; /* pointer to data base reaction */ - struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary - master species */ - struct reaction *rxn_x; /* reaction to be used in model */ - int replaced; /* equation contains solids or gases */ - int in_system; -}; -/*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ - struct master - { /* list of name and number of elements in an equation */ - int in; /* TRUE if in model, FALSE if out, REWRITE if other mb eq */ - int number; /* sequence number in list of masters */ - int last_model; /* saved to determine if model has changed */ - int type; /* AQ or EX */ - int primary; /* TRUE if master species is primary */ - LDBLE coef; /* coefficient of element in master species */ - LDBLE total; /* total concentration for element or valence state */ - LDBLE isotope_ratio; - LDBLE isotope_ratio_uncertainty; - int isotope; - LDBLE total_primary; - /* LDBLE la; */ /* initial guess of master species log activity */ - struct element *elt; /* element structure */ - LDBLE alk; /* alkalinity of species */ - LDBLE gfw; /* default gfw for species */ - char *gfw_formula; /* formula from which to calcuate gfw */ - struct unknown *unknown; /* pointer to unknown structure */ - struct species *s; /* pointer to species structure */ - struct reaction *rxn_primary; /* reaction writes master species in terms of primary - master species */ - struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary - master species */ - struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points - to location */ - int minor_isotope; -}; -/*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ -struct unknown -{ - int type; - LDBLE moles; - LDBLE ln_moles; - LDBLE f; - LDBLE sum; - LDBLE delta; - LDBLE la; - int number; - char *description; - struct master **master; - struct phase *phase; - LDBLE si; - struct gas_phase *gas_phase; - struct conc *total; - struct species *s; - struct exch_comp *exch_comp; - struct pure_phase *pure_phase; - struct s_s *s_s; - struct s_s_comp *s_s_comp; - int s_s_comp_number; - int s_s_in; - struct surface_comp *surface_comp; - LDBLE related_moles; - struct unknown *potential_unknown, *potential_unknown1, - *potential_unknown2; - int count_comp_unknowns; - struct unknown **comp_unknowns; /* list for CD_MUSIC of comps that contribute to 0 plane mass-balance term */ - struct unknown *phase_unknown; - struct surface_charge *surface_charge; - LDBLE mass_water; - int dissolve_only; - LDBLE inert_moles; -}; - -/*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ -struct reaction_temp -{ - LDBLE logk[8]; - LDBLE dz[3]; - struct rxn_token_temp *token; -}; -struct rxn_token_temp -{ /* data for equations, aq. species or minerals */ - char *name; /* pointer to a species name (formula) */ - LDBLE z; /* charge on species */ - struct species *s; - struct unknown *unknown; - LDBLE coef; /* coefficient of species name */ -}; -struct unknown_list -{ - struct unknown *unknown; - LDBLE *source; - LDBLE *gamma_source; - /* int row; */ - /* int col; */ - LDBLE coef; -}; -/* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ -struct prints -{ - int all; - int initial_solutions; - int initial_exchangers; - int reactions; - int gas_phase; - int s_s_assemblage; - int pp_assemblage; - int surface; - int exchange; - int kinetics; - int totals; - int eh; - int species; - int saturation_indices; - int irrev; - int mix; - int reaction; - int use; - int logfile; - int punch; - int status; - int inverse; - int dump; - int user_print; - int headings; - int user_graph; - int echo_input; - int warnings; - int initial_isotopes; - int isotope_ratios; - int isotope_alphas; - int hdf; - int alkalinity; -}; -/* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ -struct rate -{ - char *name; - char *commands; - int new_def; - void *linebase; - void *varbase; - void *loopbase; -}; -/* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ -struct spread_row -{ - int count; - int empty, string, number; - char **char_vector; - LDBLE *d_vector; - int *type_vector; -}; -struct defaults -{ - LDBLE temp; - LDBLE density; - char *units; - char *redox; - LDBLE ph; - LDBLE pe; - LDBLE water; - int count_iso; - struct iso *iso; -}; -struct spread_sheet -{ - struct spread_row *heading; - struct spread_row *units; - int count_rows; - struct spread_row **rows; - struct defaults defaults; -}; -/* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ -struct master_isotope -{ - char *name; - struct master *master; - struct element *elt; - char *units; - LDBLE standard; - LDBLE ratio; - LDBLE moles; - int total_is_major; - int minor_isotope; -}; -struct calculate_value -{ - char *name; - LDBLE value; - char *commands; - int new_def; - int calculated; - void *linebase; - void *varbase; - void *loopbase; -}; -struct isotope_ratio -{ - char *name; - char *isotope_name; - LDBLE ratio; - LDBLE converted_ratio; -}; -struct isotope_alpha -{ - char *name; - char *named_logk; - LDBLE value; -}; -struct system_species -{ - char *name; - char *type; - LDBLE moles; -}; - -/* tally.c ------------------------------- */ -struct tally_buffer -{ - char *name; - struct master *master; - LDBLE moles; - LDBLE gfw; -}; -struct tally -{ - char *name; - enum entity_type type; - char *add_formula; - LDBLE moles; - struct elt_list *formula; - /* - * first total is initial - * second total is final - * third total is difference (final - initial) - */ - struct tally_buffer *total[3]; -}; - -/* transport.c ------------------------------- */ -struct spec -{ - char *name; /* name of species */ - char *aq_name; /* name of aqueous species in EX species */ - int type; /* type: AQ or EX */ - LDBLE a; /* activity */ - LDBLE lm; /* log(concentration) */ - LDBLE lg; /* log(gamma) */ - LDBLE c; /* concentration for AQ, equivalent fraction for EX */ - LDBLE z; /* charge number */ - LDBLE Dwt; /* temperature corrected free water diffusion coefficient, m2/s */ - LDBLE erm_ddl; /* enrichment factor in ddl */ -}; -struct sol_D -{ - int count_spec; /* number of aqueous + exchange species */ - int count_exch_spec; /* number of exchange species */ - LDBLE exch_total; /* total moles of X- */ - struct spec *spec; -}; -struct J_ij -{ - char *name; - LDBLE tot1, tot2; -}; -struct M_S -{ - char *name; - LDBLE tot1, tot2; -}; -/* basic.c ------------------------------- */ -#ifdef PHREEQ98 -int colnr, rownr; -#endif - -#define checking true -#define varnamelen 20 -#define maxdims 4 - - -//#include "basic.h" - -#endif /* _INC_GLOBAL_STRUCTURES_H */ - From 122f2b87725ab21d7e217f81127e401172cf1d0b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2011 20:08:32 +0000 Subject: [PATCH 0319/1077] Cleaned up PBasic some. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5757 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 488 +++++++++++++++++++---------------------------------- PBasic.h | 340 ++++++++++++++++++------------------- Phreeqc.h | 5 +- 3 files changed, 338 insertions(+), 495 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index afe01dec..350afeda 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -14,14 +14,11 @@ #include "PBasic.h" #include "Phreeqc.h" - #define STOP 1 #define CONTINUE 0 #define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ - - /* Output from p2c, the Pascal-to-C translator */ /* From input file "basic.p" */ @@ -52,183 +49,166 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) P_argv = NULL; P_escapecode = 0; P_ioresult = 0; - - struct const_key command_temp[] = { - {"+", tokplus}, - {"-", tokminus}, - {"*", toktimes}, - {"/", tokdiv}, - {"^", tokup}, - {"( or [", toklp}, - {") or ]", tokrp}, - {",", tokcomma}, - {";", toksemi}, - {":", tokcolon}, - {"=", tokeq}, - {"<", toklt}, - {"<=", tokle}, - {">", tokgt}, - {">=", tokge}, - {"and", tokand}, - {"or", tokor}, - {"xor", tokxor}, - {"not", toknot}, - {"mod", tokmod}, - {"sqr", toksqr}, - {"sqrt", toksqrt}, - {"ceil", tokceil}, - {"floor", tokfloor}, - {"sin", toksin}, - {"cos", tokcos}, - {"tan", toktan}, - {"arctan", tokarctan}, - {"log", toklog}, - {"exp", tokexp}, - {"abs", tokabs}, - {"sgn", toksgn}, - {"str$", tokstr_}, - {"val", tokval}, - {"chr$", tokchr_}, - {"eol$", tokeol_}, - {"asc", tokasc}, - {"len", toklen}, - {"mid$", tokmid_}, - {"peek", tokpeek}, - {"let", toklet}, - {"print", tokprint}, - {"punch", tokpunch}, - #if defined PHREEQ98 || defined MULTICHART - {"graph_x", tokgraph_x}, - {"graph_y", tokgraph_y}, - {"graph_sy", tokgraph_sy}, - #endif - #if defined MULTICHART - {"plot_xy", tokplot_xy}, - #endif - {"input", tokinput}, - {"goto", tokgoto}, - {"go to", tokgoto}, - {"if", tokif}, - {"end", tokend}, - {"stop", tokstop}, - {"for", tokfor}, - {"next", toknext}, - {"while", tokwhile}, - {"wend", tokwend}, - {"gosub", tokgosub}, - {"return", tokreturn}, - {"read", tokread}, - {"data", tokdata}, - {"restore", tokrestore}, - {"gotoxy", tokgotoxy}, - {"on", tokon}, - {"dim", tokdim}, - {"poke", tokpoke}, - {"list", toklist}, - {"run", tokrun}, - {"new", toknew}, - {"load", tokload}, - {"merge", tokmerge}, - {"save", toksave}, - {"bye", tokbye}, - {"quit", tokbye}, - {"del", tokdel}, - {"renum", tokrenum}, - {"then", tokthen}, - {"else", tokelse}, - {"to", tokto}, - {"step", tokstep}, - {"tc", toktc}, - {"tk", toktk}, - {"time", toktime}, - {"sim_time", toksim_time}, - {"total_time", toktotal_time}, - {"m0", tokm0}, - {"m", tokm}, - {"parm", tokparm}, - {"act", tokact}, - {"edl", tokedl}, - {"surf", toksurf}, - {"equi", tokequi}, - {"kin", tokkin}, - {"gas", tokgas}, - {"s_s", toks_s}, - {"misc1", tokmisc1}, - {"misc2", tokmisc2}, - {"mu", tokmu}, - {"osmotic", tokosmotic}, - {"alk", tokalk}, - {"lk_species", toklk_species}, - {"lk_named", toklk_named}, - {"lk_phase", toklk_phase}, - {"sum_species", toksum_species}, - {"sum_gas", toksum_gas}, - {"sum_s_s", toksum_s_s}, - {"calc_value", tokcalc_value}, - {"description", tokdescription}, - {"sys", toksys}, - {"instr", tokinstr}, - {"ltrim", tokltrim}, - {"rtrim", tokrtrim}, - {"trim", toktrim}, - {"pad", tokpad}, - {"rxn", tokrxn}, - {"dist", tokdist}, - {"mol", tokmol}, - {"la", tokla}, - {"lm", toklm}, - {"sr", toksr}, - {"si", toksi}, - {"step_no", tokstep_no}, - {"cell_no", tokcell_no}, - {"sim_no", toksim_no}, - {"tot", toktot}, - {"log10", toklog10}, - {"charge_balance", tokcharge_balance}, - {"percent_error", tokpercent_error}, - {"put", tokput}, - {"get", tokget}, - {"exists", tokexists}, - {"rem", tokrem}, - {"change_por", tokchange_por}, - {"get_por", tokget_por}, - {"change_surf", tokchange_surf}, - {"porevolume", tokporevolume}, - {"sc", toksc}, - {"gamma", tokgamma}, - /* VP: Density Start */ - {"lg", toklg}, - {"rho", tokrho}, - /* VP: Density End */ - {"cell_volume", tokcell_volume}, - {"cell_pore_volume", tokcell_pore_volume}, - {"cell_porosity", tokcell_porosity}, - {"cell_saturation", tokcell_saturation}, - {"totmole", toktotmole}, - {"totmol", toktotmol}, - {"totmoles", toktotmoles}, - {"iso", tokiso}, - {"iso_unit", tokiso_unit}, - {"phase_formula", tokphase_formula}, - {"list_s_s", toklist_s_s}, - {"pr_p", tokpr_p}, - {"pr_phi", tokpr_phi}, - {"gas_p", tokgas_p}, - {"gas_vm", tokgas_vm} - }; - NCMDS = (sizeof(command_temp) / sizeof(struct const_key)); - command = new const_key[NCMDS]; - int i; - for (i = 0; i < NCMDS; i++) - { - command[i].name = PhreeqcPtr->string_duplicate(command_temp[i].name); - command[i].keycount = command_temp[i].keycount; - } - this->cmd_initialize(); + // initialize Basic commands + commands["+"] = tokplus; + commands["-"] = tokminus; + commands["*"] = toktimes; + commands["/"] = tokdiv; + commands["^"] = tokup; + commands["( or ["] = toklp; + commands[") or ]"] = tokrp; + commands["]"] = tokcomma; + commands[";"] = toksemi; + commands[":"] = tokcolon; + commands["="] = tokeq; + commands["<"] = toklt; + commands["<="] = tokle; + commands[">"] = tokgt; + commands[">="] = tokge; + commands["and"] = tokand; + commands["or"] = tokor; + commands["xor"] = tokxor; + commands["not"] = toknot; + commands["mod"] = tokmod; + commands["sqr"] = toksqr; + commands["sqrt"] = toksqrt; + commands["ceil"] = tokceil; + commands["floor"] = tokfloor; + commands["sin"] = toksin; + commands["cos"] = tokcos; + commands["tan"] = toktan; + commands["arctan"] = tokarctan; + commands["log"] = toklog; + commands["exp"] = tokexp; + commands["abs"] = tokabs; + commands["sgn"] = toksgn; + commands["str$"] = tokstr_; + commands["val"] = tokval; + commands["chr$"] = tokchr_; + commands["eol$"] = tokeol_; + commands["asc"] = tokasc; + commands["len"] = toklen; + commands["mid$"] = tokmid_; + commands["peek"] = tokpeek; + commands["let"] = toklet; + commands["print"] = tokprint; + commands["punch"] = tokpunch; + commands["graph_x"] = tokgraph_x; + commands["graph_y"] = tokgraph_y; + commands["graph_sy"] = tokgraph_sy; + commands["plot_xy"] = tokplot_xy; + commands["input"] = tokinput; + commands["goto"] = tokgoto; + commands["go to"] = tokgoto; + commands["if"] = tokif; + commands["end"] = tokend; + commands["stop"] = tokstop; + commands["for"] = tokfor; + commands["next"] = toknext; + commands["while"] = tokwhile; + commands["wend"] = tokwend; + commands["gosub"] = tokgosub; + commands["return"] = tokreturn; + commands["read"] = tokread; + commands["data"] = tokdata; + commands["restore"] = tokrestore; + commands["gotoxy"] = tokgotoxy; + commands["on"] = tokon; + commands["dim"] = tokdim; + commands["poke"] = tokpoke; + commands["list"] = toklist; + commands["run"] = tokrun; + commands["new"] = toknew; + commands["load"] = tokload; + commands["merge"] = tokmerge; + commands["save"] = toksave; + commands["bye"] = tokbye; + commands["quit"] = tokbye; + commands["del"] = tokdel; + commands["renum"] = tokrenum; + commands["then"] = tokthen; + commands["else"] = tokelse; + commands["to"] = tokto; + commands["step"] = tokstep; + commands["tc"] = toktc; + commands["tk"] = toktk; + commands["time"] = toktime; + commands["sim_time"] = toksim_time; + commands["total_time"] = toktotal_time; + commands["m0"] = tokm0; + commands["m"] = tokm; + commands["parm"] = tokparm; + commands["act"] = tokact; + commands["edl"] = tokedl; + commands["surf"] = toksurf; + commands["equi"] = tokequi; + commands["kin"] = tokkin; + commands["gas"] = tokgas; + commands["s_s"] = toks_s; + commands["misc1"] = tokmisc1; + commands["misc2"] = tokmisc2; + commands["mu"] = tokmu; + commands["osmotic"] = tokosmotic; + commands["alk"] = tokalk; + commands["lk_species"] = toklk_species; + commands["lk_named"] = toklk_named; + commands["lk_phase"] = toklk_phase; + commands["sum_species"] = toksum_species; + commands["sum_gas"] = toksum_gas; + commands["sum_s_s"] = toksum_s_s; + commands["calc_value"] = tokcalc_value; + commands["description"] = tokdescription; + commands["sys"] = toksys; + commands["instr"] = tokinstr; + commands["ltrim"] = tokltrim; + commands["rtrim"] = tokrtrim; + commands["trim"] = toktrim; + commands["pad"] = tokpad; + commands["rxn"] = tokrxn; + commands["dist"] = tokdist; + commands["mol"] = tokmol; + commands["la"] = tokla; + commands["lm"] = toklm; + commands["sr"] = toksr; + commands["si"] = toksi; + commands["step_no"] = tokstep_no; + commands["cell_no"] = tokcell_no; + commands["sim_no"] = toksim_no; + commands["tot"] = toktot; + commands["log10"] = toklog10; + commands["charge_balance"] = tokcharge_balance; + commands["percent_error"] = tokpercent_error; + commands["put"] = tokput; + commands["get"] = tokget; + commands["exists"] = tokexists; + commands["rem"] = tokrem; + commands["change_por"] = tokchange_por; + commands["get_por"] = tokget_por; + commands["change_surf"] = tokchange_surf; + commands["porevolume"] = tokporevolume; + commands["sc"] = toksc; + commands["gamma"] = tokgamma; + commands["lg"] = toklg; + commands["rho"] = tokrho; + commands["cell_volume"] = tokcell_volume; + commands["cell_pore_volume"] = tokcell_pore_volume; + commands["cell_porosity"] = tokcell_porosity; + commands["cell_saturation"] = tokcell_saturation; + commands["totmole"] = toktotmole; + commands["totmol"] = toktotmol; + commands["totmoles"] = toktotmoles; + commands["iso"] = tokiso; + commands["iso_unit"] = tokiso_unit; + commands["phase_formula"] = tokphase_formula; + commands["list_s_s"] = toklist_s_s; + commands["pr_p"] = tokpr_p; + commands["pr_phi"] = tokpr_phi; + commands["gas_p"] = tokgas_p; + commands["gas_vm"] = tokgas_vm; } PBasic::~PBasic(void) { - this->cmd_free(); + } void PBasic:: PASCAL_MAIN(int argc, char **argv) @@ -239,50 +219,6 @@ PASCAL_MAIN(int argc, char **argv) P_escapecode = 0; P_ioresult = 0; } -/* ---------------------------------------------------------------------- */ -void PBasic:: -cmd_initialize(void) -/* ---------------------------------------------------------------------- */ -{ - ENTRY item, *found_item; - int i; - char *token; -/* - * create hash table - */ - PhreeqcPtr->hcreate_multi((unsigned) 2 * NCMDS, &command_hash_table); -/* - * fill with commands - */ - for (i = 0; i < NCMDS; i++) - { - token = PhreeqcPtr->string_hsave(command[i].name); - item.key = token; - item.data = (void *) &command[i]; - found_item = PhreeqcPtr->hsearch_multi(command_hash_table, item, ENTER); - if (found_item == NULL) - { - sprintf(PhreeqcPtr->error_string, - "Hash table error in basic commands initialization."); - PhreeqcPtr->error_msg(PhreeqcPtr->error_string, STOP); - } - } - return; -} - -/* ---------------------------------------------------------------------- */ -void PBasic:: -cmd_free(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * destroy hash table - */ - - PhreeqcPtr->hdestroy_multi(command_hash_table); - command_hash_table = NULL; - return; -} int PBasic:: basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) @@ -574,8 +510,6 @@ restoredata(void) datatok = NULL; } - - void PBasic:: clearloops(void) { @@ -589,8 +523,6 @@ clearloops(void) } } - - void PBasic:: clearvar(varrec * v) { @@ -623,7 +555,6 @@ clearvar(varrec * v) } } - void PBasic:: clearvars(void) { @@ -711,7 +642,6 @@ parse(char * l_inbuf, tokenrec ** l_buf) tokenrec *t, *tptr; varrec *v; char ch; - ENTRY item, *found_item; char *ptr; tptr = NULL; @@ -869,14 +799,11 @@ parse(char * l_inbuf, tokenrec ** l_buf) * Search hash list */ PhreeqcPtr->str_tolower(token); - item.key = token; - item.data = NULL; - found_item = - PhreeqcPtr->hsearch_multi(command_hash_table, item, FIND); - if (found_item != NULL) + std::map::const_iterator item; + item = commands.find(token); + if (item != commands.end()) { - t->kind = - ((struct key *) (found_item->data))->keycount; + t->kind = item->second; if (t->kind == tokrem) { m = (int) strlen(l_inbuf) + 1; @@ -1235,8 +1162,6 @@ parse(char * l_inbuf, tokenrec ** l_buf) #undef toklength - - void PBasic:: listtokens(FILE * f, tokenrec * l_buf) { @@ -1897,8 +1822,6 @@ listtokens(FILE * f, tokenrec * l_buf) } } - - void PBasic:: disposetokens(tokenrec ** tok) { @@ -1916,8 +1839,6 @@ disposetokens(tokenrec ** tok) } } - - void PBasic:: parseinput(tokenrec ** l_buf) { @@ -1979,7 +1900,6 @@ errormsg(const char * l_s) _Escape(42); } - void PBasic:: snerr(const char * l_s) { @@ -1997,14 +1917,12 @@ tmerr(const char * l_s) errormsg(strcat(str, l_s)); } - void PBasic:: badsubscr(void) { errormsg("Bad subscript"); } - LDBLE PBasic:: realfactor(struct LOC_exec *LINK) { @@ -2087,24 +2005,24 @@ intexpr(struct LOC_exec *LINK) return ((long) floor(realexpr(LINK) + 0.5)); } - void PBasic:: require(int k, struct LOC_exec *LINK) { - char str[MAX_LENGTH] = {0}; - int i; + char str[MAX_LENGTH] = {0}; if (LINK->t == NULL || LINK->t->kind != k) { - for (i = 0; i < NCMDS; i++) + std::map::const_iterator item; + for (item = commands.begin(); item != commands.end(); item++) { - if (command[i].keycount == k) + if (item->second == k) break; } - if (i == NCMDS) + + if (item == commands.end()) snerr(": missing unknown command"); else { strcpy(str, ": missing "); - snerr(strcat(str, command[i].name)); + snerr(strcat(str, item->first.c_str())); } } LINK->t = LINK->t->next; @@ -2131,7 +2049,6 @@ skipparen(struct LOC_exec *LINK) _L1:; } - varrec * PBasic:: findvar(struct LOC_exec *LINK) { @@ -2205,7 +2122,6 @@ findvar(struct LOC_exec *LINK) return v; } - valrec PBasic:: factor(struct LOC_exec * LINK) { @@ -3686,7 +3602,6 @@ expr(struct LOC_exec * LINK) return n; } - void PBasic:: checkextra(struct LOC_exec *LINK) { @@ -3694,7 +3609,6 @@ checkextra(struct LOC_exec *LINK) errormsg("Extra information on line"); } - boolean PBasic:: iseos(struct LOC_exec *LINK) { @@ -3702,7 +3616,6 @@ iseos(struct LOC_exec *LINK) LINK->t->kind == (long) tokcolon)); } - void PBasic:: skiptoeos(struct LOC_exec *LINK) { @@ -3710,7 +3623,6 @@ skiptoeos(struct LOC_exec *LINK) LINK->t = LINK->t->next; } - linerec * PBasic:: findline(long n) { @@ -3735,7 +3647,6 @@ mustfindline(long n) return l; } - void PBasic:: cmdend(struct LOC_exec *LINK) { @@ -3743,7 +3654,6 @@ cmdend(struct LOC_exec *LINK) LINK->t = NULL; } - void PBasic:: cmdnew(struct LOC_exec *LINK) { @@ -3795,7 +3705,6 @@ cmdnew(struct LOC_exec *LINK) } } - void PBasic:: cmdlist(struct LOC_exec *LINK) { @@ -3844,7 +3753,6 @@ cmdlist(struct LOC_exec *LINK) while (!iseos(LINK)); } - void PBasic:: cmdload(boolean merging, char * name, struct LOC_exec *LINK) { @@ -3887,7 +3795,6 @@ cmdload(boolean merging, char * name, struct LOC_exec *LINK) fclose(f); } - void PBasic:: cmdrun(struct LOC_exec *LINK) { @@ -3957,6 +3864,7 @@ cmdsave(struct LOC_exec *LINK) } } } + void PBasic:: cmdput(struct LOC_exec *LINK) { @@ -4122,7 +4030,6 @@ cmddel(struct LOC_exec *LINK) while (!iseos(LINK)); } - void PBasic:: cmdrenum(struct LOC_exec *LINK) { @@ -4192,7 +4099,6 @@ cmdrenum(struct LOC_exec *LINK) } } - void PBasic:: cmdprint(struct LOC_exec *LINK) { @@ -4429,7 +4335,6 @@ cmdlet(boolean implied, struct LOC_exec *LINK) PhreeqcPtr->PHRQ_free(old); } - void PBasic:: cmdgoto(struct LOC_exec *LINK) { @@ -4438,7 +4343,6 @@ cmdgoto(struct LOC_exec *LINK) LINK->gotoflag = true; } - void PBasic:: cmdif(struct LOC_exec *LINK) { @@ -4469,14 +4373,12 @@ cmdif(struct LOC_exec *LINK) LINK->elseflag = true; } - void PBasic:: cmdelse(struct LOC_exec *LINK) { LINK->t = NULL; } - boolean PBasic:: skiploop(int up, int dn, struct LOC_exec *LINK) { @@ -4511,7 +4413,6 @@ skiploop(int up, int dn, struct LOC_exec *LINK) return Result; } - void PBasic:: cmdfor(struct LOC_exec *LINK) { @@ -4584,7 +4485,6 @@ cmdfor(struct LOC_exec *LINK) loopbase = l; } - void PBasic:: cmdnext(struct LOC_exec *LINK) { @@ -4626,7 +4526,6 @@ cmdnext(struct LOC_exec *LINK) loopbase = l; } - void PBasic:: cmdwhile(struct LOC_exec *LINK) { @@ -4652,7 +4551,6 @@ cmdwhile(struct LOC_exec *LINK) skiptoeos(LINK); } - void PBasic:: cmdwend(struct LOC_exec *LINK) { @@ -4700,7 +4598,6 @@ cmdwend(struct LOC_exec *LINK) loopbase = l; } - void PBasic:: cmdgosub(struct LOC_exec *LINK) { @@ -4717,7 +4614,6 @@ cmdgosub(struct LOC_exec *LINK) cmdgoto(LINK); } - void PBasic:: cmdreturn(struct LOC_exec *LINK) { @@ -4745,7 +4641,6 @@ cmdreturn(struct LOC_exec *LINK) skiptoeos(LINK); } - void PBasic:: cmdread(struct LOC_exec *LINK) { @@ -4797,14 +4692,12 @@ cmdread(struct LOC_exec *LINK) while (!iseos(LINK)); } - void PBasic:: cmddata(struct LOC_exec *LINK) { skiptoeos(LINK); } - void PBasic:: cmdrestore(struct LOC_exec *LINK) { @@ -4817,7 +4710,6 @@ cmdrestore(struct LOC_exec *LINK) } } - void PBasic:: cmdgotoxy(struct LOC_exec *LINK) { @@ -4825,7 +4717,6 @@ cmdgotoxy(struct LOC_exec *LINK) require(tokcomma, LINK); } - void PBasic:: cmdon(struct LOC_exec *LINK) { @@ -4863,7 +4754,6 @@ cmdon(struct LOC_exec *LINK) cmdgoto(LINK); } - void PBasic:: cmddim(struct LOC_exec *LINK) { @@ -5210,6 +5100,7 @@ exec(void) } ENDTRY(try1); } /*exec */ + int PBasic:: free_dim_stringvar(varrec *l_varbase) { @@ -5229,6 +5120,7 @@ free_dim_stringvar(varrec *l_varbase) } return (OK); } + #if defined MULTICHART void PBasic:: cmdplot_xy(struct LOC_exec *LINK) @@ -5318,6 +5210,7 @@ cmdplot_xy(struct LOC_exec *LINK) } chart->Set_colnr(chart->Get_colnr() + 1); } + void PBasic:: cmdgraph_x(struct LOC_exec *LINK) { @@ -5493,9 +5386,6 @@ cmdgraph_sy(struct LOC_exec *LINK) } #endif // MULTICHART - - - /* In case your system lacks these... */ long PBasic:: @@ -5525,7 +5415,6 @@ my_memmove(Anyptr d, Const Anyptr l_s, size_t n) return d; } - PBasic::Anyptr PBasic:: my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) { @@ -5564,7 +5453,6 @@ my_toupper(int c) return c; } - int PBasic:: my_tolower(int c) { @@ -5574,9 +5462,6 @@ my_tolower(int c) return c; } - - - long PBasic:: ipow(long a, long b) { @@ -5600,9 +5485,6 @@ ipow(long a, long b) return v; } - - - /* Common string functions: */ /* Store in "ret" the substring of length "len" starting from "pos" (1-based). @@ -5637,7 +5519,6 @@ strsub(register char *ret, register char *l_s, register int pos, return ret; } - /* Return the index of the first occurrence of "pat" as a substring of "s", starting at index "pos" (1-based). Result is 1-based, 0 if not found. */ @@ -5663,7 +5544,6 @@ strpos2(char *l_s, register char *pat, register int pos) return 0; } - /* Case-insensitive version of strcmp. */ int PBasic:: strcicmp(register char *s1, register char *s2) @@ -5687,9 +5567,6 @@ strcicmp(register char *s1, register char *s2) return 0; } - - - /* HP and Turbo Pascal string functions: */ /* Trim blanks at left end of string. */ @@ -5700,7 +5577,6 @@ strltrim(register char *l_s) return l_s - 1; } - /* Trim blanks at right end of string. */ char * PBasic:: strrtrim(register char *l_s) @@ -5715,7 +5591,6 @@ strrtrim(register char *l_s) return l_s; } - /* Store in "ret" string "s" with enough pad chars added to reach "size". */ /* Copy the substring of length "len" from index "spos" of "s" (1-based) @@ -5765,9 +5640,6 @@ strinsert(register char *src, register char *dst, register int pos) *dst++ = *src++; } - - - /* File functions */ /* Peek at next character of input stream; return EOF at end-of-file. */ @@ -5783,7 +5655,6 @@ P_peek(FILE * f) return (ch == '\n') ? ' ' : ch; } - /* Check if at end of file, using Pascal "eof" semantics. End-of-file for stdin is broken; remove the special case for it to be broken in a different way. */ @@ -5794,7 +5665,6 @@ P_eof(void) return 0; } - /* Check if at end of line (or end of entire file). */ int PBasic:: P_eoln(FILE * f) @@ -5808,7 +5678,6 @@ P_eoln(FILE * f) return (ch == '\n'); } - /* Read a packed array of characters from a file. */ void PBasic:: P_readpaoc(FILE * f, char *l_s, int len) @@ -5851,7 +5720,6 @@ P_readlnpaoc(FILE * f, char *l_s, int len) *l_s++ = ' '; } - /* Compute maximum legal "seek" index in file (0-based). */ long PBasic:: P_maxpos(FILE * f) @@ -5867,7 +5735,6 @@ P_maxpos(FILE * f) return val; } - /* Use packed array of char for a file name. */ char * PBasic:: P_trimname(register char * fn, register int len) @@ -5881,9 +5748,6 @@ P_trimname(register char * fn, register int len) return fnbuf; } - - - /* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. We fix memory size as 10Meg as a reasonable compromise. */ @@ -5899,9 +5763,6 @@ maxavail(void) return memavail(); } - - - /* Sets are stored as an array of longs. S[0] is the size of the set; S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum I such that S[I] is nonzero. S[0] is zero for an empty set. Within @@ -6090,7 +5951,6 @@ P_setcpy(register long *d, register long *l_s) /* d := s */ return save_d; } - /* s is a "smallset", i.e., a 32-bit or less set stored directly in a long. */ long * PBasic:: @@ -6133,10 +5993,6 @@ _NilCheck(void) return _Escape(-3); } - - - - /* The following is suitable for the HP Pascal operating system. It might want to be revised when emulating another system. */ diff --git a/PBasic.h b/PBasic.h index 74f3cc6b..0bc35423 100644 --- a/PBasic.h +++ b/PBasic.h @@ -1,5 +1,6 @@ #ifndef _INC_PBasic_H #define _INC_PBasic_H +#include #define forloop 0 #define whileloop 1 #define gosubloop 2 @@ -18,170 +19,6 @@ typedef char string255[256]; #define BadInputFormat 14 #define EndOfFile 30 -#define tokvar 0 -#define toknum 1 -#define tokstr 2 -#define toksnerr 3 -#define tokplus 4 -#define tokminus 5 -#define toktimes 6 -#define tokdiv 7 -#define tokup 8 -#define toklp 9 -#define tokrp 10 -#define tokcomma 11 -#define toksemi 12 -#define tokcolon 13 -#define tokeq 14 -#define toklt 15 -#define tokgt 16 -#define tokle 17 -#define tokge 18 -#define tokne 19 -#define tokand 20 -#define tokor 21 -#define tokxor 22 -#define tokmod 23 -#define toknot 24 -#define toksqr 25 -#define toksqrt 26 -#define toksin 27 -#define tokcos 28 -#define toktan 29 -#define tokarctan 30 -#define toklog 31 -#define tokexp 32 -#define tokabs 33 -#define toksgn 34 -#define tokstr_ 35 -#define tokval 36 -#define tokchr_ 37 -#define tokasc 38 -#define toklen 39 -#define tokmid_ 40 -#define tokpeek 41 -#define tokrem 42 -#define toklet 43 -#define tokprint 44 -#define tokinput 45 -#define tokgoto 46 -#define tokif 47 -#define tokend 48 -#define tokstop 49 -#define tokfor 50 -#define toknext 51 -#define tokwhile 52 -#define tokwend 53 -#define tokgosub 54 -#define tokreturn 55 -#define tokread 56 -#define tokdata 57 -#define tokrestore 58 -#define tokgotoxy 59 -#define tokon 60 -#define tokdim 61 -#define tokpoke 62 -#define toklist 63 -#define tokrun 64 -#define toknew 65 -#define tokload 66 -#define tokmerge 67 -#define toksave 68 -#define tokbye 69 -#define tokdel 70 -#define tokrenum 71 -#define tokthen 72 -#define tokelse 73 -#define tokto 74 -#define tokstep 75 -#define toktc 76 -#define tokm0 77 -#define tokm 78 -#define tokparm 79 -#define tokact 80 -#define tokmol 81 -#define tokla 82 -#define toklm 83 -#define toksr 84 -#define toksi 85 -#define toktot 86 -#define toktk 87 -#define toktime 88 -#define toklog10 89 -#define toksim_time 90 -#define tokequi 91 -#define tokgas 92 -#define tokpunch 93 -#define tokkin 94 -#define toks_s 95 -#define tokmu 96 -#define tokalk 97 -#define tokrxn 98 -#define tokdist 99 -#define tokmisc1 100 -#define tokmisc2 101 -#define tokedl 102 -#define tokstep_no 103 -#define toksim_no 104 -#define toktotal_time 105 -#define tokput 106 -#define tokget 107 -#define tokcharge_balance 109 -#define tokpercent_error 110 -#if defined PHREEQ98 || MULTICHART -#define tokgraph_x 111 -#define tokgraph_y 112 -#define tokgraph_sy 113 -#endif -#define tokcell_no 114 -#define tokexists 115 -#define toksurf 116 -#define toklk_species 117 -#define toklk_named 118 -#define toklk_phase 119 -#define toksum_species 120 -#define toksum_gas 121 -#define toksum_s_s 122 -#define tokcalc_value 123 -#define tokdescription 124 -#define toksys 125 -#define tokinstr 126 -#define tokltrim 127 -#define tokrtrim 128 -#define toktrim 129 -#define tokpad 130 -#define tokchange_por 131 -#define tokget_por 132 -#define tokosmotic 133 -#define tokchange_surf 134 -#define tokporevolume 135 -#define toksc 136 -#define tokgamma 137 -#define toklg 138 -/* VP: Density Start */ -#define tokrho 139 -/* VP: Density End */ -#define tokcell_volume 140 -#define tokcell_pore_volume 141 -#define tokcell_porosity 142 -#define tokcell_saturation 143 -#if defined MULTICHART -#define tokplot_xy 144 -#endif -#define toktotmole 145 -#define tokiso 146 -#define tokiso_unit 147 -#define toktotmol 148 -#define toktotmoles 149 -#define tokeol_ 150 -#define tokceil 151 -#define tokfloor 152 -#define tokphase_formula 153 -#define toklist_s_s 154 -#define tokpr_p 155 -#define tokpr_phi 156 -#define tokgas_p 157 -#define tokgas_vm 158 /* Header file for code generated by "p2c", the Pascal-to-C translator */ /* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. @@ -198,6 +35,7 @@ typedef char string255[256]; #include "phrqtype.h" #include "PHRQ_base.h" #include "global_structures.h" + typedef struct varrec { varnamestring name; @@ -312,7 +150,167 @@ typedef char *Anyptr; #define Register register /* Register variables */ #define char char /* Characters (not bytes) */ - + enum BASIC_TOKEN + { + tokvar, + toknum, + tokstr, + toksnerr, + tokplus, + tokminus, + toktimes, + tokdiv, + tokup, + toklp, + tokrp, + tokcomma, + toksemi, + tokcolon, + tokeq, + toklt, + tokgt, + tokle, + tokge, + tokne, + tokand, + tokor, + tokxor, + tokmod, + toknot, + toksqr, + toksqrt, + toksin, + tokcos, + toktan, + tokarctan, + toklog, + tokexp, + tokabs, + toksgn, + tokstr_, + tokval, + tokchr_, + tokasc, + toklen, + tokmid_, + tokpeek, + tokrem, + toklet, + tokprint, + tokinput, + tokgoto, + tokif, + tokend, + tokstop, + tokfor, + toknext, + tokwhile, + tokwend, + tokgosub, + tokreturn, + tokread, + tokdata, + tokrestore, + tokgotoxy, + tokon, + tokdim, + tokpoke, + toklist, + tokrun, + toknew, + tokload, + tokmerge, + toksave, + tokbye, + tokdel, + tokrenum, + tokthen, + tokelse, + tokto, + tokstep, + toktc, + tokm0, + tokm, + tokparm, + tokact, + tokmol, + tokla, + toklm, + toksr, + toksi, + toktot, + toktk, + toktime, + toklog10, + toksim_time, + tokequi, + tokgas, + tokpunch, + tokkin, + toks_s, + tokmu, + tokalk, + tokrxn, + tokdist, + tokmisc1, + tokmisc2, + tokedl, + tokstep_no, + toksim_no, + toktotal_time, + tokput, + tokget, + tokcharge_balance, + tokpercent_error, + tokgraph_x, + tokgraph_y, + tokgraph_sy, + tokcell_no, + tokexists, + toksurf, + toklk_species, + toklk_named, + toklk_phase, + toksum_species, + toksum_gas, + toksum_s_s, + tokcalc_value, + tokdescription, + toksys, + tokinstr, + tokltrim, + tokrtrim, + toktrim, + tokpad, + tokchange_por, + tokget_por, + tokosmotic, + tokchange_surf, + tokporevolume, + toksc, + tokgamma, + toklg, + tokrho, + tokcell_volume, + tokcell_pore_volume, + tokcell_porosity, + tokcell_saturation, + tokplot_xy, + toktotmole, + tokiso, + tokiso_unit, + toktotmol, + toktotmoles, + tokeol_, + tokceil, + tokfloor, + tokphase_formula, + toklist_s_s, + tokpr_p, + tokpr_phi, + tokgas_p, + tokgas_vm + }; // Methods int free_dim_stringvar(varrec *varbase); void exec(void); @@ -394,8 +392,6 @@ typedef char *Anyptr; void cmddim(struct LOC_exec *LINK); void cmdpoke(struct LOC_exec *LINK); int basic_main(char *commands); -void cmd_initialize(void); -void cmd_free(void); int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); int basic_init(void); @@ -449,7 +445,6 @@ static char * _ShowEscape(char *buf, int code, int ior, char *prefix); int _Escape(int code); int _EscIO(int code); - protected: Phreeqc * PhreeqcPtr; char *inbuf; @@ -461,20 +456,13 @@ protected: tokenrec *stmttok, *datatok, *buf; boolean exitflag; long EXCP_LINE; - HashTable *command_hash_table; - struct const_key *command; - int NCMDS; + std::map commands; Anyptr __MallocTemp__; int P_argc; char **P_argv; int P_escapecode; int P_ioresult; __p2c_jmp_buf *__top_jb; - - //int max_line; }; - -/* Following defines are suitable for the HP Pascal operating system */ - #endif /* _INC_PBasic_H */ diff --git a/Phreeqc.h b/Phreeqc.h index e3643a68..2e95cd90 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -66,12 +66,11 @@ public: // advection.cpp ------------------------------- int advection(void); -// basic.cpp +// basicsubs.cpp ------------------------------- int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -void cmd_free(void); +void basic_free(void); -// basicsubs.cpp ------------------------------- LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); From c20d3ca270df62cf43509bf1aecfa60f21d771a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2011 20:39:29 +0000 Subject: [PATCH 0320/1077] Latest version (5757) with fixed up PBasic (std::map). Checking in examples and mytest. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5758 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 228 +++++++++++++++++++------------------------------------ 1 file changed, 80 insertions(+), 148 deletions(-) diff --git a/Makefile b/Makefile index 982ca3bd..4d2060d2 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DUSE_PHRQ_ALLOC -DPBASIC $(DEFINE_INVERSE_CL1MP) + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -115,7 +115,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DNDEBUG -DPBASIC $(DEFINE_INVERSE_CL1MP) + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -130,7 +130,6 @@ endif COMMON_COBJS = \ advection.o \ - basic.o \ basicsubs.o \ cl1.o \ cvdense.o \ @@ -146,7 +145,6 @@ COMMON_COBJS = \ model.o \ nvector.o \ nvector_serial.o \ - p2clib.o \ parse.o \ PHRQ_io_output.o \ phqalloc.o \ @@ -229,8 +227,7 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxKinetics.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../cxxKinetics.h \ ../NumKeyword.h ../KineticsComp.h ../NameDouble.h ../Parser.h \ ../cxxMix.h ../phreeqc/phqalloc.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ @@ -238,30 +235,26 @@ cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxMix.h ../NumKeyword.h \ - ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../cxxMix.h \ + ../NumKeyword.h ../phreeqc/phqalloc.h Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../cxxMix.h \ - ../NumKeyword.h ../Exchange.h ../ExchComp.h ../NameDouble.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../NumKeyword.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../Parser.h ../phreeqc/phqalloc.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../ExchComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ @@ -269,16 +262,14 @@ ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../ISolutionComp.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../ISolutionComp.h \ ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../ISolution.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../ISolution.h \ ../ISolutionComp.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h @@ -287,57 +278,51 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../KineticsComp.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../KineticsComp.h \ ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../NameDouble.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../NameDouble.h \ + ../Parser.h ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ ../Parser.h Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../Parser.h + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../PPassemblageComp.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../PPassemblageComp.h \ ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../PPassemblage.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../PPassemblage.h \ ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h ../Parser.h \ ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Reaction.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ ../phreeqc/phqalloc.h ReadClass.o: ../ReadClass.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Phreeqc_class.h ../Parser.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../NameDouble.h \ ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ @@ -348,8 +333,7 @@ Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../Phreeqc_class.h \ ../cxxMix.h ../phreeqc/phqalloc.h @@ -358,24 +342,21 @@ SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SolutionIsotope.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SolutionIsotope.h \ ../Parser.h ../phreeqc/phqalloc.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SolutionIsotopeList.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Parser.h ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SSassemblage.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SSassemblage.h \ ../NumKeyword.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ @@ -383,18 +364,16 @@ SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SSassemblageSS.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SSassemblageSS.h \ ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../NameDouble.h ../Parser.h \ - ../StorageBin.h ../System.h ../Phreeqc_class.h ../SSassemblage.h \ - ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../NameDouble.h \ + ../Parser.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ + ../SSassemblage.h ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ @@ -405,34 +384,30 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SurfaceCharge.h \ ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../SurfaceComp.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../SurfaceComp.h \ ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../Surface.h ../NumKeyword.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../cxxMix.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Surface.h \ + ../NumKeyword.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h ../System.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../SSassemblage.h \ - ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../System.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../SSassemblage.h ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ @@ -442,8 +417,7 @@ Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../Temperature.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Temperature.h \ ../NumKeyword.h ../phreeqc/phqalloc.h Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ChartHandler.o: ../ChartHandler.cpp @@ -452,8 +426,7 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ @@ -462,19 +435,23 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ CurveObject.o: ../CurveObject.cpp ../CurveObject.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ ../Parser.h -PBasic.o: ../PBasic.cpp +PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../PHRQ_io.h ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h \ - ../phreeqc/phqalloc.h + ../phreeqc/phqalloc.h ../PBasic.h PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../Parser.h ../phreeqc/NA.h @@ -484,52 +461,39 @@ advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h -basic.o: ../phreeqc/basic.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ - ../phreeqc/phqalloc.h ../phreeqc/p2c.h ../NameDouble.h ../Parser.h basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h + ../phreeqc/../PHRQ_base.h ../phreeqc/../PBasic.h cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h @@ -537,42 +501,36 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h input.o: ../phreeqc/input.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h kinetics.o: ../phreeqc/kinetics.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ ../Parser.h ../Phreeqc_class.h ../Reaction.h ../NumKeyword.h \ ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ @@ -584,15 +542,13 @@ mainsubs.o: ../phreeqc/mainsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../PBasic.h model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h @@ -600,67 +556,52 @@ nvector_serial.o: ../phreeqc/nvector_serial.cpp \ ../phreeqc/nvector_serial.h ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h -p2clib.o: ../phreeqc/p2clib.cpp ../phreeqc/p2c.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h prep.o: ../phreeqc/prep.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h print.o: ../phreeqc/print.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h read.o: ../phreeqc/read.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ @@ -670,14 +611,12 @@ readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ @@ -686,15 +625,13 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ ../Parser.h ../Phreeqc_class.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../PPassemblage.h \ @@ -705,8 +642,7 @@ structures.o: ../phreeqc/structures.cpp ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/p2c.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/basic.h ../phreeqc/basic_class.h ../phreeqc/phqalloc.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ ../phreeqc/../cxxMix.h ../phreeqc/../NumKeyword.h \ ../phreeqc/../PHRQ_base.h ../phreeqc/../Exchange.h \ ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ @@ -728,29 +664,25 @@ tally.o: ../phreeqc/tally.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h tidy.o: ../phreeqc/tidy.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h transport.o: ../phreeqc/transport.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/p2c.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/basic.h ../phreeqc/basic_class.h \ + ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h # ----------------------------------------------------------------------------- clean: From 7271b9d5cbac19c1da1c4b2718f4a5c364cc1e2f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Nov 2011 15:30:43 +0000 Subject: [PATCH 0321/1077] Replaced TRY/RECOVER with try/catch Replaced boolean with bool. Tony's minor changes to basicsubs and ChartObject. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5760 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- PBasic.cpp | 160 ++++++++++++++++++++++++++++++------------------ PBasic.h | 62 +++++++++++-------- 3 files changed, 139 insertions(+), 85 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 5ee168ff..3ff9f01c 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -463,7 +463,7 @@ ChartObject::OpenCSVFile(std::string file_name) if (!f_csv.is_open()) { std::ostringstream estream; - estream << "Could not open csv file for USER_GRAPH " << file_name; + estream << "Could not open csv file for USER_GRAPH " << file_name << "\n Please, give the full path + filename."; error_msg(estream.str().c_str(), CONTINUE); return false; } diff --git a/PBasic.cpp b/PBasic.cpp index 350afeda..16e6278b 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -43,12 +43,14 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) stmttok = NULL; datatok = NULL; buf = NULL; - exitflag = FALSE; + exitflag = false; EXCP_LINE = 0; P_argc = 0; P_argv = NULL; P_escapecode = 0; P_ioresult = 0; + //__top_jb = NULL; + // initialize Basic commands commands["+"] = tokplus; commands["-"] = tokminus; @@ -93,10 +95,14 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) commands["let"] = toklet; commands["print"] = tokprint; commands["punch"] = tokpunch; +#if defined (PHREEQ98) || defined (MULTICHART) commands["graph_x"] = tokgraph_x; commands["graph_y"] = tokgraph_y; commands["graph_sy"] = tokgraph_sy; +#endif +#if defined MULTICHART commands["plot_xy"] = tokplot_xy; +#endif commands["input"] = tokinput; commands["goto"] = tokgoto; commands["go to"] = tokgoto; @@ -215,7 +221,7 @@ PASCAL_MAIN(int argc, char **argv) { P_argc = argc; P_argv = argv; - __top_jb = NULL; + //__top_jb = NULL; P_escapecode = 0; P_ioresult = 0; } @@ -237,7 +243,9 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) ptr = commands; do { - TRY(try2); + //TRY(try2); + try + { ptr = commands; do { @@ -256,7 +264,10 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } } while (!(exitflag || P_eof())); - RECOVER(try2); + } + catch (PBasicStop e) + { + //RECOVER(try2); if (P_escapecode != -20) { sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, @@ -267,7 +278,8 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) { putchar('\n'); } - ENDTRY(try2); + //ENDTRY(try2); + } } while (!(exitflag || P_eof())); /* exit(EXIT_SUCCESS); */ @@ -294,7 +306,9 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) ptr = commands; do { - TRY(try2); + //TRY(try2); + try + { i = 0; ptr = commands; do @@ -330,7 +344,10 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) } } while (!(exitflag || P_eof())); - RECOVER(try2); + } + catch (PBasicStop e) + { + //RECOVER(try2); if (P_escapecode != -20) { sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, @@ -341,7 +358,8 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) { putchar('\n'); } - ENDTRY(try2); + //ENDTRY(try2); + } } while (!(exitflag || P_eof())); /* exit(EXIT_SUCCESS); */ @@ -372,7 +390,9 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) loopbase = (looprec *) lpbase; do { - TRY(try2); + //TRY(try2); + try + { do { if (sget_logical_line(&ptr, &l, inbuf) == EOF) @@ -390,7 +410,10 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } } while (!(exitflag || P_eof())); - RECOVER(try2); + } + catch (PBasicStop e) + { + //RECOVER(try2); if (P_escapecode != -20) { sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, @@ -401,7 +424,8 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { putchar('\n'); } - ENDTRY(try2); + //ENDTRY(try2); + } } while (!(exitflag || P_eof())); @@ -429,7 +453,9 @@ basic_main(char *commands) ptr = commands; do { - TRY(try2); + //TRY(try2); + try + { do { #ifdef SKIP @@ -450,7 +476,10 @@ basic_main(char *commands) } } while (!(exitflag || P_eof())); - RECOVER(try2); + } + catch (PBasicStop e) + { + //RECOVER(try2); if (P_escapecode != -20) { sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, @@ -461,7 +490,8 @@ basic_main(char *commands) { putchar('\n'); } - ENDTRY(try2); + //ENDTRY(try2); + } } while (!(exitflag || P_eof())); return 1; @@ -1165,7 +1195,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) void PBasic:: listtokens(FILE * f, tokenrec * l_buf) { - boolean ltr; + bool ltr; char STR1[256] = {0}; char *string; ltr = false; @@ -1178,7 +1208,7 @@ listtokens(FILE * f, tokenrec * l_buf) if (ltr) /*putc(' ', f); */ output_msg(" "); - ltr = (boolean) (l_buf->kind != toknot); + ltr = (bool) (l_buf->kind != toknot); } else ltr = false; @@ -1913,7 +1943,7 @@ void PBasic:: tmerr(const char * l_s) { char str[MAX_LENGTH] = {0}; - strcpy(str, "Type mismatch error"); + strcpy(str, "Character/number type mismatch error"); errormsg(strcat(str, l_s)); } @@ -1941,7 +1971,8 @@ strfactor(struct LOC_exec * LINK) n = factor(LINK); if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); + //tmerr(": chemical name is not enclosed in \" \"" ); + tmerr(": Expected quoted string or character variable." ); return (n.UU.sval); } @@ -1952,7 +1983,8 @@ stringfactor(char * Result, struct LOC_exec * LINK) n = factor(LINK); if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); + //tmerr(": chemical name is not enclosed in \" \"" ); + tmerr(": Expected quoted string or character variable." ); strcpy(Result, n.UU.sval); PhreeqcPtr->PHRQ_free(n.UU.sval); return Result; @@ -1982,7 +2014,8 @@ strexpr(struct LOC_exec * LINK) n = expr(LINK); if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); + //tmerr(": chemical name is not enclosed in \" \"" ); + tmerr(": Expected quoted string or character variable." ); return (n.UU.sval); } @@ -1993,7 +2026,8 @@ stringexpr(char * Result, struct LOC_exec * LINK) n = expr(LINK); if (!n.stringval) - tmerr(": chemical name is not enclosed in \" \"" ); + //tmerr(": chemical name is not enclosed in \" \"" ); + tmerr(": Expected quoted string or character variable." ); strcpy(Result, n.UU.sval); PhreeqcPtr->PHRQ_free(n.UU.sval); return Result; @@ -3492,7 +3526,7 @@ valrec PBasic:: relexpr(struct LOC_exec * LINK) { valrec n, n2; - boolean f; + bool f; int k; n = sexpr(LINK); @@ -3507,7 +3541,7 @@ relexpr(struct LOC_exec * LINK) tmerr(""); if (n.stringval) { - f = (boolean) ((!strcmp(n.UU.sval, n2.UU.sval) + f = (bool) ((!strcmp(n.UU.sval, n2.UU.sval) && (unsigned long) k < 32 && ((1L << ((long) k)) & ((1L << ((long) tokeq)) | @@ -3535,7 +3569,7 @@ relexpr(struct LOC_exec * LINK) PhreeqcPtr->PHRQ_free(n2.UU.sval); } else - f = (boolean) ((n.UU.val == n2.UU.val && (unsigned long) k < 32 && + f = (bool) ((n.UU.val == n2.UU.val && (unsigned long) k < 32 && ((1L << ((long) k)) & ((1L << ((long) tokeq)) | (1L << ((long) tokge)) | (1L << ((long) tokle)))) != @@ -3609,10 +3643,10 @@ checkextra(struct LOC_exec *LINK) errormsg("Extra information on line"); } -boolean PBasic:: +bool PBasic:: iseos(struct LOC_exec *LINK) { - return ((boolean) (LINK->t == NULL || LINK->t->kind == (long) tokelse || + return ((bool) (LINK->t == NULL || LINK->t->kind == (long) tokelse || LINK->t->kind == (long) tokcolon)); } @@ -3754,7 +3788,7 @@ cmdlist(struct LOC_exec *LINK) } void PBasic:: -cmdload(boolean merging, char * name, struct LOC_exec *LINK) +cmdload(bool merging, char * name, struct LOC_exec *LINK) { FILE *f; tokenrec *l_buf; @@ -4102,7 +4136,7 @@ cmdrenum(struct LOC_exec *LINK) void PBasic:: cmdprint(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; char STR1[256] = {0}; @@ -4193,7 +4227,7 @@ cmdpunch(struct LOC_exec *LINK) void PBasic:: cmdgraph_x(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; char STR1[256]; semiflag = false; @@ -4228,7 +4262,7 @@ cmdgraph_x(struct LOC_exec *LINK) void PBasic:: cmdgraph_y(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; char STR1[256]; semiflag = false; @@ -4263,7 +4297,7 @@ cmdgraph_y(struct LOC_exec *LINK) void PBasic:: cmdgraph_sy(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; char STR1[256]; semiflag = false; @@ -4297,7 +4331,7 @@ cmdgraph_sy(struct LOC_exec *LINK) #endif void PBasic:: -cmdlet(boolean implied, struct LOC_exec *LINK) +cmdlet(bool implied, struct LOC_exec *LINK) { varrec *v; char *old, *mynew; @@ -4379,10 +4413,10 @@ cmdelse(struct LOC_exec *LINK) LINK->t = NULL; } -boolean PBasic:: +bool PBasic:: skiploop(int up, int dn, struct LOC_exec *LINK) { - boolean Result; + bool Result; long i; linerec *saveline; @@ -4489,7 +4523,7 @@ void PBasic:: cmdnext(struct LOC_exec *LINK) { varrec *v; - boolean found; + bool found; looprec *l, *WITH; if (!iseos(LINK)) @@ -4500,7 +4534,7 @@ cmdnext(struct LOC_exec *LINK) { if (loopbase == NULL || loopbase->kind == gosubloop) errormsg("NEXT without FOR"); - found = (boolean) (loopbase->kind == forloop && + found = (bool) (loopbase->kind == forloop && (v == NULL || loopbase->UU.U0.vp == v)); if (!found) { @@ -4557,13 +4591,13 @@ cmdwend(struct LOC_exec *LINK) tokenrec *tok; linerec *tokline; looprec *l; - boolean found; + bool found; do { if (loopbase == NULL || loopbase->kind == gosubloop) errormsg("WEND without WHILE"); - found = (boolean) (loopbase->kind == whileloop); + found = (bool) (loopbase->kind == whileloop); if (!found) { l = loopbase->next; @@ -4618,13 +4652,13 @@ void PBasic:: cmdreturn(struct LOC_exec *LINK) { looprec *l; - boolean found; + bool found; do { if (loopbase == NULL) errormsg("RETURN without GOSUB"); - found = (boolean) (loopbase->kind == gosubloop); + found = (bool) (loopbase->kind == gosubloop); if (!found) { l = loopbase->next; @@ -4646,7 +4680,7 @@ cmdread(struct LOC_exec *LINK) { varrec *v; tokenrec *tok; - boolean found; + bool found; do { @@ -4669,7 +4703,7 @@ cmdread(struct LOC_exec *LINK) dataline = dataline->next; LINK->t = dataline->txt; } - found = (boolean) (LINK->t->kind == tokdata); + found = (bool) (LINK->t->kind == tokdata); LINK->t = LINK->t->next; } while (!found || iseos(LINK)); @@ -4759,7 +4793,7 @@ cmddim(struct LOC_exec *LINK) { long i, j, k; varrec *v; - boolean done; + bool done; do { @@ -4782,7 +4816,7 @@ cmddim(struct LOC_exec *LINK) i++; v->dims[i - 1] = k; j *= k; - done = (boolean) (LINK->t != NULL && LINK->t->kind == tokrp); + done = (bool) (LINK->t != NULL && LINK->t->kind == tokrp); if (!done) require(tokcomma, LINK); } @@ -4835,7 +4869,9 @@ exec(void) char STR1[256] = {0}; - TRY(try1); + //TRY(try1); + try + { do { do @@ -4962,7 +4998,9 @@ exec(void) case tokstop: P_escapecode = -20; - goto _Ltry1; + throw PBasicStop(); + //goto _Ltry1; + break; case tokfor: cmdfor(&V); @@ -5035,7 +5073,11 @@ exec(void) } } while (stmtline != NULL); - RECOVER2(try1, _Ltry1); + //RECOVER2(try1, _Ltry1); + } + catch (PBasicStop e) + { + //_Ltry1: if (P_escapecode == -20) warning_msg("Break"); /* printf("Break"); */ @@ -5098,7 +5140,8 @@ exec(void) sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); error_msg(PhreeqcPtr->error_string, CONTINUE); } - ENDTRY(try1); + //ENDTRY(try1); + } // end catch } /*exec */ int PBasic:: @@ -5125,7 +5168,7 @@ free_dim_stringvar(varrec *l_varbase) void PBasic:: cmdplot_xy(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n[2]; char STR[2][256]; int i = 0; @@ -5214,7 +5257,7 @@ cmdplot_xy(struct LOC_exec *LINK) void PBasic:: cmdgraph_x(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; semiflag = false; @@ -5261,7 +5304,7 @@ cmdgraph_x(struct LOC_exec *LINK) void PBasic:: cmdgraph_y(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; semiflag = false; @@ -5325,7 +5368,7 @@ cmdgraph_y(struct LOC_exec *LINK) void PBasic:: cmdgraph_sy(struct LOC_exec *LINK) { - boolean semiflag; + bool semiflag; valrec n; semiflag = false; @@ -6095,12 +6138,13 @@ _Escape(int code) char token[200], empty[2] = { "\0" }; P_escapecode = code; - if (__top_jb) - { - __p2c_jmp_buf *jb = __top_jb; - __top_jb = jb->next; - longjmp(jb->jbuf, 1); - } + //if (__top_jb) + //{ + // __p2c_jmp_buf *jb = __top_jb; + // __top_jb = jb->next; + //longjmp(jb->jbuf, 1); + throw PBasicStop(); + //} if (code == 0) /* exit(EXIT_SUCCESS); */ error_msg("Exit success in Basic", STOP); diff --git a/PBasic.h b/PBasic.h index 0bc35423..94f36b28 100644 --- a/PBasic.h +++ b/PBasic.h @@ -1,6 +1,11 @@ #ifndef _INC_PBasic_H #define _INC_PBasic_H #include + +class PBasicStop : std::exception +{ +}; + #define forloop 0 #define whileloop 1 #define gosubloop 2 @@ -9,7 +14,8 @@ #define varnamelen 20 #define maxdims 4 -typedef unsigned char boolean; +//typedef unsigned char boolean; +//typedef bool boolean; typedef char varnamestring[varnamelen + 1]; typedef char string255[256]; #define MAX_LINE 4096 @@ -42,7 +48,7 @@ typedef struct varrec struct varrec *next; long dims[maxdims]; char numdims; - boolean stringvar; + bool stringvar; union { struct @@ -82,7 +88,7 @@ typedef struct linerec } linerec; typedef struct valrec { - boolean stringval; + bool stringval; union { LDBLE val; @@ -109,7 +115,7 @@ typedef struct looprec /* variables for exec: */ struct LOC_exec { - boolean gotoflag, elseflag; + bool gotoflag, elseflag; tokenrec *t; }; @@ -120,11 +126,11 @@ class PBasic: public PHRQ_base public: PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); ~PBasic(); -typedef struct __p2c_jmp_buf -{ - struct __p2c_jmp_buf *next; - jmp_buf jbuf; -} __p2c_jmp_buf; +//typedef struct __p2c_jmp_buf +//{ +// struct __p2c_jmp_buf *next; +// jmp_buf jbuf; +//} __p2c_jmp_buf; /* Warning: The following will not work if setjmp is used simultaneously. @@ -132,24 +138,24 @@ typedef struct __p2c_jmp_buf but a typical implementation of longjmp will get it right anyway. */ -# define TRY(x) do { __p2c_jmp_buf __try_jb; \ - __try_jb.next = __top_jb; \ - if (!setjmp((__top_jb = &__try_jb)->jbuf)) { -# define RECOVER(x) __top_jb = __try_jb.next; } else { -# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ - { L: __top_jb = __try_jb.next; } -# define ENDTRY(x) } } while (0) +//# define TRY(x) do { __p2c_jmp_buf __try_jb; \ +// __try_jb.next = __top_jb; \ +// if (!setjmp((__top_jb = &__try_jb)->jbuf)) { +//# define RECOVER(x) __top_jb = __try_jb.next; } else { +//# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ +// { L: __top_jb = __try_jb.next; } +//# define ENDTRY(x) } } while (0) #define SETBITS 32 #define Const -#define P2PP(x) () -#define PV() () +//#define P2PP(x) () +//#define PV() () typedef char *Anyptr; -#define Register register /* Register variables */ -#define char char /* Characters (not bytes) */ +//#define Register register /* Register variables */ +//#define char char /* Characters (not bytes) */ enum BASIC_TOKEN { tokvar, @@ -262,9 +268,11 @@ typedef char *Anyptr; tokget, tokcharge_balance, tokpercent_error, +#if defined (PHREEQ98) || defined (MULTICHART) tokgraph_x, tokgraph_y, tokgraph_sy, +#endif tokcell_no, tokexists, toksurf, @@ -295,7 +303,9 @@ typedef char *Anyptr; tokcell_pore_volume, tokcell_porosity, tokcell_saturation, +#if defined MULTICHART tokplot_xy, +#endif toktotmole, tokiso, tokiso_unit, @@ -347,14 +357,14 @@ typedef char *Anyptr; valrec andexpr(struct LOC_exec * LINK); valrec expr(struct LOC_exec *LINK); void checkextra(struct LOC_exec *LINK); - boolean iseos(struct LOC_exec *LINK); + bool iseos(struct LOC_exec *LINK); void skiptoeos(struct LOC_exec *LINK); linerec * findline(long n); linerec * mustfindline(long n); void cmdend(struct LOC_exec *LINK); void cmdnew(struct LOC_exec *LINK); void cmdlist(struct LOC_exec *LINK); - void cmdload(boolean merging, char * name, struct LOC_exec *LINK); + void cmdload(bool merging, char * name, struct LOC_exec *LINK); void cmdrun(struct LOC_exec *LINK); void cmdsave(struct LOC_exec *LINK); void cmdput(struct LOC_exec *LINK); @@ -373,11 +383,11 @@ typedef char *Anyptr; #if defined MULTICHART void cmdplot_xy(struct LOC_exec *LINK); #endif - void cmdlet(boolean implied, struct LOC_exec *LINK); + void cmdlet(bool implied, struct LOC_exec *LINK); void cmdgoto(struct LOC_exec *LINK); void cmdif(struct LOC_exec *LINK); void cmdelse(struct LOC_exec *LINK); - boolean skiploop(int up, int dn, struct LOC_exec *LINK); + bool skiploop(int up, int dn, struct LOC_exec *LINK); void cmdfor(struct LOC_exec *LINK); void cmdnext(struct LOC_exec *LINK); void cmdwhile(struct LOC_exec *LINK); @@ -454,7 +464,7 @@ protected: long curline; linerec *stmtline, *dataline; tokenrec *stmttok, *datatok, *buf; - boolean exitflag; + bool exitflag; long EXCP_LINE; std::map commands; Anyptr __MallocTemp__; @@ -462,7 +472,7 @@ protected: char **P_argv; int P_escapecode; int P_ioresult; - __p2c_jmp_buf *__top_jb; + //__p2c_jmp_buf *__top_jb; }; #endif /* _INC_PBasic_H */ From 29276b982bbff93ada367e5be222bde22a8d2714 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Nov 2011 16:10:01 +0000 Subject: [PATCH 0322/1077] More cleanup of PBasic.cpp Removed PASCAL_MAIN. Removed Anyptr. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5761 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 320 ++++++++++++++++++++++++----------------------------- PBasic.h | 210 +++++++++++++++-------------------- 2 files changed, 232 insertions(+), 298 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 16e6278b..eb7b9566 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,6 +1,11 @@ #if defined(WIN32) #include #endif +#include +#include "PBasic.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "NameDouble.h" /* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ @@ -10,21 +15,15 @@ * by the licence agreement accompanying p2c itself. */ -#include -#include "PBasic.h" -#include "Phreeqc.h" - #define STOP 1 #define CONTINUE 0 - #define Isspace(c) isspace(c) /* or "((c) == ' ')" if preferred */ +#define toklength 20 +typedef long chset[9]; /* Output from p2c, the Pascal-to-C translator */ /* From input file "basic.p" */ -#include "phqalloc.h" -#include "NameDouble.h" - PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) : PHRQ_base(phrq_io) { @@ -45,11 +44,8 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) buf = NULL; exitflag = false; EXCP_LINE = 0; - P_argc = 0; - P_argv = NULL; P_escapecode = 0; P_ioresult = 0; - //__top_jb = NULL; // initialize Basic commands commands["+"] = tokplus; @@ -216,15 +212,6 @@ PBasic::~PBasic(void) { } -void PBasic:: -PASCAL_MAIN(int argc, char **argv) -{ - P_argc = argc; - P_argv = argv; - //__top_jb = NULL; - P_escapecode = 0; - P_ioresult = 0; -} int PBasic:: basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) @@ -232,7 +219,8 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) int l; char *ptr; - PASCAL_MAIN(0, NULL); + P_escapecode = 0; + P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) PhreeqcPtr->malloc_error(); @@ -243,42 +231,39 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) ptr = commands; do { - //TRY(try2); try { - ptr = commands; - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) + ptr = commands; + do { - strcpy(inbuf, "bye"); + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); + while (!(exitflag || P_eof())); } catch (PBasicStop e) { - //RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - //ENDTRY(try2); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } } } while (!(exitflag || P_eof())); @@ -295,7 +280,9 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) { /*main */ int l, i; char *ptr; - PASCAL_MAIN(0, NULL); + + P_escapecode = 0; + P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) PhreeqcPtr->malloc_error(); @@ -306,59 +293,56 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) ptr = commands; do { - //TRY(try2); try { - i = 0; - ptr = commands; - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) + i = 0; + ptr = commands; + do { - i++; - if (i == 1) + if (sget_logical_line(&ptr, &l, inbuf) == EOF) { - strcpy(inbuf, "renum"); + i++; + if (i == 1) + { + strcpy(inbuf, "renum"); + } + else if (i == 2) + { + strcpy(inbuf, "list"); + } + else if (i == 3) + { + strcpy(inbuf, "new"); + } + else if (i == 4) + { + strcpy(inbuf, "bye"); + } } - else if (i == 2) + parseinput(&buf); + if (curline == 0) { - strcpy(inbuf, "list"); - } - else if (i == 3) - { - strcpy(inbuf, "new"); - } - else if (i == 4) - { - strcpy(inbuf, "bye"); + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); } } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); + while (!(exitflag || P_eof())); } catch (PBasicStop e) { - //RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - //ENDTRY(try2); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } } } while (!(exitflag || P_eof())); @@ -376,7 +360,9 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { /*main */ int l; char *ptr; - PASCAL_MAIN(0, NULL); + + P_escapecode = 0; + P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) PhreeqcPtr->malloc_error(); @@ -390,41 +376,38 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) loopbase = (looprec *) lpbase; do { - //TRY(try2); try { - do - { - if (sget_logical_line(&ptr, &l, inbuf) == EOF) + do { - strcpy(inbuf, "bye"); + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); + while (!(exitflag || P_eof())); } catch (PBasicStop e) { - //RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - //ENDTRY(try2); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } } } while (!(exitflag || P_eof())); @@ -439,7 +422,9 @@ basic_main(char *commands) { /*main */ int l; char *ptr; - PASCAL_MAIN(0, NULL); + + P_escapecode = 0; + P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) PhreeqcPtr->malloc_error(); @@ -453,44 +438,38 @@ basic_main(char *commands) ptr = commands; do { - //TRY(try2); try { - do - { -#ifdef SKIP - putchar('>'); -#endif - if (sget_logical_line(&ptr, &l, inbuf) == EOF) + do { - strcpy(inbuf, "bye"); + if (sget_logical_line(&ptr, &l, inbuf) == EOF) + { + strcpy(inbuf, "bye"); + } + parseinput(&buf); + if (curline == 0) + { + stmtline = NULL; + stmttok = buf; + if (stmttok != NULL) + exec(); + disposetokens(&buf); + } } - parseinput(&buf); - if (curline == 0) - { - stmtline = NULL; - stmttok = buf; - if (stmttok != NULL) - exec(); - disposetokens(&buf); - } - } - while (!(exitflag || P_eof())); + while (!(exitflag || P_eof())); } catch (PBasicStop e) { - //RECOVER(try2); - if (P_escapecode != -20) - { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + if (P_escapecode != -20) + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); - } - else - { - putchar('\n'); - } - //ENDTRY(try2); + warning_msg(PhreeqcPtr->error_string); + } + else + { + putchar('\n'); + } } } while (!(exitflag || P_eof())); @@ -498,7 +477,6 @@ basic_main(char *commands) /* exit(EXIT_SUCCESS); */ } -/* End. */ /* ---------------------------------------------------------------------- */ int PBasic:: sget_logical_line(char **ptr, int *l, char *return_line) @@ -655,15 +633,6 @@ numtostr(char * Result, LDBLE n) } */ } -#define toklength 20 - - -typedef long chset[9]; - - - - - void PBasic:: parse(char * l_inbuf, tokenrec ** l_buf) { @@ -1943,7 +1912,7 @@ void PBasic:: tmerr(const char * l_s) { char str[MAX_LENGTH] = {0}; - strcpy(str, "Character/number type mismatch error"); + strcpy(str, "Type mismatch error"); errormsg(strcat(str, l_s)); } @@ -5440,8 +5409,8 @@ my_labs(long l_x) /* #define __STDC__ */ /* PHREEQ98 */ -PBasic::Anyptr PBasic:: -my_memmove(Anyptr d, Const Anyptr l_s, size_t n) +void * PBasic:: +my_memmove(void * d, Const void * l_s, size_t n) { register char *dd = (char *) d, *ss = (char *) l_s; if (dd < ss || (unsigned int) (dd - ss) >= n) @@ -5458,8 +5427,8 @@ my_memmove(Anyptr d, Const Anyptr l_s, size_t n) return d; } -PBasic::Anyptr PBasic:: -my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) +void * PBasic:: +my_memcpy(void * d, Const void * l_s, size_t n) { register char *ss = (char *) l_s, *dd = (char *) d; while (n-- > 0) @@ -5468,7 +5437,7 @@ my_memcpy(Anyptr d, Const Anyptr l_s, size_t n) } int PBasic:: -my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) +my_memcmp(Const void * s1, Const void * s2, size_t n) { register char *a = (char *) s1, *b = (char *) s2; register int i; @@ -5478,8 +5447,8 @@ my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n) return 0; } -PBasic::Anyptr PBasic:: -my_memset(Anyptr d, int c, size_t n) +void * PBasic:: +my_memset(void * d, int c, size_t n) { register char *dd = (char *) d; while (n-- > 0) @@ -6134,17 +6103,13 @@ _ShowEscape(char *buf, int code, int ior, char *prefix) int PBasic:: _Escape(int code) { + P_escapecode = code; + throw PBasicStop(); + + // following not used +#ifdef SKIP char l_buf[100]; char token[200], empty[2] = { "\0" }; - - P_escapecode = code; - //if (__top_jb) - //{ - // __p2c_jmp_buf *jb = __top_jb; - // __top_jb = jb->next; - //longjmp(jb->jbuf, 1); - throw PBasicStop(); - //} if (code == 0) /* exit(EXIT_SUCCESS); */ error_msg("Exit success in Basic", STOP); @@ -6162,6 +6127,7 @@ _Escape(int code) sprintf(token, "%s", _ShowEscape(l_buf, P_escapecode, P_ioresult, empty)); error_msg(token, STOP); return (1); +#endif } int PBasic:: diff --git a/PBasic.h b/PBasic.h index 94f36b28..b2a019da 100644 --- a/PBasic.h +++ b/PBasic.h @@ -1,38 +1,6 @@ #ifndef _INC_PBasic_H #define _INC_PBasic_H #include - -class PBasicStop : std::exception -{ -}; - -#define forloop 0 -#define whileloop 1 -#define gosubloop 2 - -#define checking true -#define varnamelen 20 -#define maxdims 4 - -//typedef unsigned char boolean; -//typedef bool boolean; -typedef char varnamestring[varnamelen + 1]; -typedef char string255[256]; -#define MAX_LINE 4096 -#define FileNotFound 10 -#define FileNotOpen 13 -#define FileWriteError 38 -#define BadInputFormat 14 -#define EndOfFile 30 - -/* Header file for code generated by "p2c", the Pascal-to-C translator */ - -/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. - * This file may be copied, modified, etc. in any way. It is not restricted - * by the licence agreement accompanying p2c itself. - */ - #include #include #include @@ -41,6 +9,37 @@ typedef char string255[256]; #include "phrqtype.h" #include "PHRQ_base.h" #include "global_structures.h" +class Phreeqc; + +class PBasicStop : std::exception +{ +}; + +#define forloop 0 +#define whileloop 1 +#define gosubloop 2 +#define checking true +#define varnamelen 20 +#define maxdims 4 +#define MAX_LINE 4096 +#define FileNotFound 10 +#define FileNotOpen 13 +#define FileWriteError 38 +#define BadInputFormat 14 +#define EndOfFile 30 +#define SETBITS 32 +#define Const + +typedef char varnamestring[varnamelen + 1]; +typedef char string255[256]; + +/* Header file for code generated by "p2c", the Pascal-to-C translator */ + +/* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. + * This file may be copied, modified, etc. in any way. It is not restricted + * by the licence agreement accompanying p2c itself. + */ typedef struct varrec { @@ -63,6 +62,7 @@ typedef struct varrec } U1; } UU; } varrec; + typedef struct tokenrec { struct tokenrec *next; @@ -79,6 +79,7 @@ typedef struct tokenrec char *sz_num; #endif } tokenrec; + typedef struct linerec { long num, num2; @@ -86,6 +87,7 @@ typedef struct linerec char inbuf[MAX_LINE]; struct linerec *next; } linerec; + typedef struct valrec { bool stringval; @@ -119,43 +121,12 @@ struct LOC_exec tokenrec *t; }; -class Phreeqc; - class PBasic: public PHRQ_base { public: PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); ~PBasic(); -//typedef struct __p2c_jmp_buf -//{ -// struct __p2c_jmp_buf *next; -// jmp_buf jbuf; -//} __p2c_jmp_buf; - -/* Warning: The following will not work if setjmp is used simultaneously. - This also violates the ANSI restriction about using vars after longjmp, - but a typical implementation of longjmp will get it right anyway. */ - - -//# define TRY(x) do { __p2c_jmp_buf __try_jb; \ -// __try_jb.next = __top_jb; \ -// if (!setjmp((__top_jb = &__try_jb)->jbuf)) { -//# define RECOVER(x) __top_jb = __try_jb.next; } else { -//# define RECOVER2(x,L) __top_jb = __try_jb.next; } else { \ -// { L: __top_jb = __try_jb.next; } -//# define ENDTRY(x) } } while (0) - -#define SETBITS 32 - -#define Const - -//#define P2PP(x) () -//#define PV() () -typedef char *Anyptr; - -//#define Register register /* Register variables */ -//#define char char /* Characters (not bytes) */ enum BASIC_TOKEN { tokvar, @@ -321,6 +292,7 @@ typedef char *Anyptr; tokgas_p, tokgas_vm }; + // Methods int free_dim_stringvar(varrec *varbase); void exec(void); @@ -375,14 +347,14 @@ typedef char *Anyptr; void cmdrenum(struct LOC_exec *LINK); void cmdprint(struct LOC_exec *LINK); void cmdpunch(struct LOC_exec *LINK); - #if defined PHREEQ98 || defined MULTICHART +#if defined PHREEQ98 || defined MULTICHART void cmdgraph_x(struct LOC_exec *LINK); void cmdgraph_y(struct LOC_exec *LINK); void cmdgraph_sy(struct LOC_exec *LINK); - #endif - #if defined MULTICHART +#endif +#if defined MULTICHART void cmdplot_xy(struct LOC_exec *LINK); - #endif +#endif void cmdlet(bool implied, struct LOC_exec *LINK); void cmdgoto(struct LOC_exec *LINK); void cmdif(struct LOC_exec *LINK); @@ -401,60 +373,60 @@ typedef char *Anyptr; void cmdon(struct LOC_exec *LINK); void cmddim(struct LOC_exec *LINK); void cmdpoke(struct LOC_exec *LINK); -int basic_main(char *commands); -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -int basic_init(void); + int basic_main(char *commands); + int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); + int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); + int basic_init(void); #ifdef PHREEQ98 -void GridChar(char *s, char *a); + void GridChar(char *s, char *a); #endif -int sget_logical_line(char **ptr, int *l, char *return_line); -void PASCAL_MAIN(int argc, char **argv); -long my_labs(long x); -Anyptr my_memmove(Anyptr d, Const Anyptr s, size_t n); -Anyptr my_memcpy(Anyptr d, Const Anyptr s, size_t n); -int my_memcmp(Const Anyptr s1, Const Anyptr s2, size_t n); -Anyptr my_memset(Anyptr d, int c, size_t n); -int my_toupper(int c); -int my_tolower(int c); -long ipow(long a, long b); -char * strsub(register char *ret, register char *s, register int pos, - register int len); -int strpos2(char *s, register char *pat, register int pos); -int strcicmp(register char *s1, register char *s2); -char * strltrim(register char *s); -char * strrtrim(register char *s); -void strmove(register int len, register char *s, register int spos, + int sget_logical_line(char **ptr, int *l, char *return_line); + long my_labs(long x); + void * my_memmove(void * d, Const void * s, size_t n); + void * my_memcpy(void * d, Const void * s, size_t n); + int my_memcmp(Const void * s1, Const void * s2, size_t n); + void * my_memset(void * d, int c, size_t n); + int my_toupper(int c); + int my_tolower(int c); + long ipow(long a, long b); + char * strsub(register char *ret, register char *s, register int pos, + register int len); + int strpos2(char *s, register char *pat, register int pos); + int strcicmp(register char *s1, register char *s2); + char * strltrim(register char *s); + char * strrtrim(register char *s); + void strmove(register int len, register char *s, register int spos, register char *d, register int dpos); -void strinsert(register char *src, register char *dst, register int pos); -int P_peek(FILE * f); -int P_eof(void); -int P_eoln(FILE * f); -void P_readpaoc(FILE * f, char *s, int len); -void P_readlnpaoc(FILE * f, char *s, int len); -long P_maxpos(FILE * f); -char * P_trimname(register char * fn, register int len); -long memavail(void); -long maxavail(void); -long * P_setunion(register long *d, register long *s1, register long *s2); -long * P_setint(register long *d, register long *s1, register long *s2); -long * P_setdiff(register long *d, register long *s1, register long *s2); -long * P_setxor(register long *d, register long *s1, register long *s2); -long * P_addset(register long *s, register unsigned val); -long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); -long * P_remset(register long *s, register unsigned val); -int P_setequal(register long *s1, register long *s2); -int P_subset(register long *s1, register long *s2); -long * P_setcpy(register long *d, register long *s); -long * P_expset(register long *d, register long s); -long P_packset(register long *s); -int _OutMem(void); -int _CaseCheck(void); -int _NilCheck(void); -static char * _ShowEscape(char *buf, int code, int ior, char *prefix); -int _Escape(int code); -int _EscIO(int code); + void strinsert(register char *src, register char *dst, register int pos); + int P_peek(FILE * f); + int P_eof(void); + int P_eoln(FILE * f); + void P_readpaoc(FILE * f, char *s, int len); + void P_readlnpaoc(FILE * f, char *s, int len); + long P_maxpos(FILE * f); + char * P_trimname(register char * fn, register int len); + long memavail(void); + long maxavail(void); + long * P_setunion(register long *d, register long *s1, register long *s2); + long * P_setint(register long *d, register long *s1, register long *s2); + long * P_setdiff(register long *d, register long *s1, register long *s2); + long * P_setxor(register long *d, register long *s1, register long *s2); + long * P_addset(register long *s, register unsigned val); + long * P_addsetr(register long *s, register unsigned v1, register unsigned v2); + long * P_remset(register long *s, register unsigned val); + int P_setequal(register long *s1, register long *s2); + int P_subset(register long *s1, register long *s2); + long * P_setcpy(register long *d, register long *s); + long * P_expset(register long *d, register long s); + long P_packset(register long *s); + int _OutMem(void); + int _CaseCheck(void); + int _NilCheck(void); + static char * _ShowEscape(char *buf, int code, int ior, char *prefix); + int _Escape(int code); + int _EscIO(int code); + // data members protected: Phreeqc * PhreeqcPtr; char *inbuf; @@ -467,12 +439,8 @@ protected: bool exitflag; long EXCP_LINE; std::map commands; - Anyptr __MallocTemp__; - int P_argc; - char **P_argv; int P_escapecode; int P_ioresult; - //__p2c_jmp_buf *__top_jb; }; #endif /* _INC_PBasic_H */ From 4c938e63e7686b55c768c310631a25c5dadac555 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Nov 2011 22:25:58 +0000 Subject: [PATCH 0323/1077] Crapsi changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5770 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 2e95cd90..db8ba784 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -575,8 +575,8 @@ int write_mb_for_species_list(int n); int write_mass_action_eqn_x(int stop); int check_same_model(void); -int k_temp(LDBLE tc); -LDBLE k_calc(LDBLE * logk, LDBLE tempk); +int k_temp(LDBLE tc, LDBLE pa); +LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); int prep(void); int reprep(void); int rewrite_master_to_secondary(struct master *master_ptr1, @@ -654,6 +654,8 @@ int read_copy(void); int read_debug(void); int read_delta_h_only(char *ptr, LDBLE * delta_h, DELTA_H_UNIT * units); +int read_delta_v_only(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); int read_llnl_aqueous_model_parameters(void); int read_exchange(void); int read_exchange_master_species(void); @@ -1334,6 +1336,7 @@ PHRQ_io *phrq_io; struct model last_model; int same_model; int same_temperature; + int same_pressure; struct punch punch; /* ---------------------------------------------------------------------- * Temperatures @@ -1499,6 +1502,7 @@ int count_iso_defaults; char *description_x; LDBLE tc_x; LDBLE tk_x; + LDBLE patm_x; LDBLE ph_x; LDBLE solution_pe_x; LDBLE mu_x; From 9c73b964c586eece9b9c7ee2f1dc718a6b6fc854 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Nov 2011 22:47:54 +0000 Subject: [PATCH 0324/1077] Needed to merge two read_delta_v_only git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5771 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index db8ba784..2b2b15cf 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -633,7 +633,7 @@ int read_log_k_only(char *ptr, LDBLE * log_k); int read_t_c_only(char *ptr, LDBLE *t_c); int read_p_c_only(char *ptr, LDBLE * p_c); int read_omega_only(char *ptr, LDBLE *omega); -int read_delta_v_only(char *ptr, LDBLE * delta_v); +//int read_delta_v_only(char *ptr, LDBLE * delta_v); int read_number_description(char *ptr, int *n_user, int *n_user_end, char **description, int allow_negative=FALSE); int check_key(char *str); From 97caf60b9aadf4ce68a364c0ca0a49a59d09b1ac Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Nov 2011 23:07:59 +0000 Subject: [PATCH 0325/1077] Indented Phreeqc.h, read_delta_v_only git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5773 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3442 ++++++++++++++++++++++++++--------------------------- 1 file changed, 1721 insertions(+), 1721 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 2b2b15cf..9d73a068 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -8,8 +8,8 @@ #include #endif /* ---------------------------------------------------------------------- - * INCLUDE FILES - * ---------------------------------------------------------------------- */ +* INCLUDE FILES +* ---------------------------------------------------------------------- */ #include #include #include @@ -59,1254 +59,1254 @@ public: ~Phreeqc(void); public: -// -// Phreeqc class methods -// + // + // Phreeqc class methods + // -// advection.cpp ------------------------------- -int advection(void); + // advection.cpp ------------------------------- + int advection(void); -// basicsubs.cpp ------------------------------- -int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); -int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); -void basic_free(void); + // basicsubs.cpp ------------------------------- + int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); + int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); + void basic_free(void); -LDBLE activity(const char *species_name); -LDBLE activity_coefficient(const char *species_name); -LDBLE log_activity_coefficient(const char *species_name); -LDBLE calc_SC(void); -/* VP: Density Start */ -LDBLE calc_dens(void); -/* VP: Density End */ -LDBLE calc_logk_n(const char *name); -LDBLE calc_logk_p(const char *name); -LDBLE calc_logk_s(const char *name); -LDBLE calc_surface_charge(const char *surface_name); -LDBLE diff_layer_total(const char *total_name, const char *surface_name); -LDBLE equi_phase(const char *phase_name); -LDBLE find_gas_comp(const char *gas_comp_name); -LDBLE find_gas_p(void); -LDBLE find_gas_vm(void); -LDBLE find_misc1(const char *s_s_name); -LDBLE find_misc2(const char *s_s_name); -LDBLE find_s_s_comp(const char *s_s_comp_name); -LDBLE get_calculate_value(const char *name); -char * iso_unit(const char *total_name); -LDBLE iso_value(const char *total_name); -LDBLE kinetics_moles(const char *kinetics_name); -LDBLE log_activity(const char *species_name); -LDBLE log_molality(const char *species_name); -LDBLE molality(const char *species_name); -LDBLE pr_pressure(const char *phase_name); -LDBLE pr_phi(const char *phase_name); -LDBLE saturation_ratio(const char *phase_name); -int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); -LDBLE solution_sum_secondary(const char *total_name); -LDBLE sum_match_gases(const char *stemplate, const char *name); -LDBLE sum_match_species(const char *stemplate, const char *name); -LDBLE sum_match_s_s(const char *stemplate, const char *name); -int match_elts_in_species(const char *name, const char *stemplate); -int extract_bracket(char **string, char *bracket_string); -LDBLE surf_total(const char *total_name, const char *surface_name); -static int system_species_compare(const void *ptr1, const void *ptr2); -LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); -std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); -LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); -int system_total_elements(void); -int system_total_si(void); -int system_total_aq(void); -int system_total_ex(void); -int system_total_surf(void); -int system_total_gas(void); -int system_total_s_s(void); -int system_total_elt(const char *total_name); -int system_total_elt_secondary(const char *total_name); -LDBLE total(const char *total_name); -LDBLE total_mole(const char *total_name); -int system_total_solids(struct exchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, - struct surface *surface_ptr); + LDBLE activity(const char *species_name); + LDBLE activity_coefficient(const char *species_name); + LDBLE log_activity_coefficient(const char *species_name); + LDBLE calc_SC(void); + /* VP: Density Start */ + LDBLE calc_dens(void); + /* VP: Density End */ + LDBLE calc_logk_n(const char *name); + LDBLE calc_logk_p(const char *name); + LDBLE calc_logk_s(const char *name); + LDBLE calc_surface_charge(const char *surface_name); + LDBLE diff_layer_total(const char *total_name, const char *surface_name); + LDBLE equi_phase(const char *phase_name); + LDBLE find_gas_comp(const char *gas_comp_name); + LDBLE find_gas_p(void); + LDBLE find_gas_vm(void); + LDBLE find_misc1(const char *s_s_name); + LDBLE find_misc2(const char *s_s_name); + LDBLE find_s_s_comp(const char *s_s_comp_name); + LDBLE get_calculate_value(const char *name); + char * iso_unit(const char *total_name); + LDBLE iso_value(const char *total_name); + LDBLE kinetics_moles(const char *kinetics_name); + LDBLE log_activity(const char *species_name); + LDBLE log_molality(const char *species_name); + LDBLE molality(const char *species_name); + LDBLE pr_pressure(const char *phase_name); + LDBLE pr_phi(const char *phase_name); + LDBLE saturation_ratio(const char *phase_name); + int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); + LDBLE solution_sum_secondary(const char *total_name); + LDBLE sum_match_gases(const char *stemplate, const char *name); + LDBLE sum_match_species(const char *stemplate, const char *name); + LDBLE sum_match_s_s(const char *stemplate, const char *name); + int match_elts_in_species(const char *name, const char *stemplate); + int extract_bracket(char **string, char *bracket_string); + LDBLE surf_total(const char *total_name, const char *surface_name); + static int system_species_compare(const void *ptr1, const void *ptr2); + LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); + std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); + LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); + int system_total_elements(void); + int system_total_si(void); + int system_total_aq(void); + int system_total_ex(void); + int system_total_surf(void); + int system_total_gas(void); + int system_total_s_s(void); + int system_total_elt(const char *total_name); + int system_total_elt_secondary(const char *total_name); + LDBLE total(const char *total_name); + LDBLE total_mole(const char *total_name); + int system_total_solids(struct exchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr); -static LDBLE f_rho(LDBLE rho_old, void *cookie); + static LDBLE f_rho(LDBLE rho_old, void *cookie); -// chart.cpp + // chart.cpp #if defined PHREEQ98 -void DeleteCurves(void); -void ExtractCurveInfo(char *line, int curvenr); -void GridChar(char *s, char *a); -void MallocCurves(int nc, int ncxy); -int OpenCSVFile(char file_name[MAX_LENGTH]); -void SaveCurvesToFile(char file_name[MAX_LENGTH]); -void PlotXY(char *x, char *y); -void ReallocCurves(int new_nc); -void ReallocCurveXY(int i); -void SetAxisScale(char *a, int j, char *token, int true_); -void SetAxisTitles(char *s, int i); -void SetChartTitle(char *s); -void start_chart(bool end); + void DeleteCurves(void); + void ExtractCurveInfo(char *line, int curvenr); + void GridChar(char *s, char *a); + void MallocCurves(int nc, int ncxy); + int OpenCSVFile(char file_name[MAX_LENGTH]); + void SaveCurvesToFile(char file_name[MAX_LENGTH]); + void PlotXY(char *x, char *y); + void ReallocCurves(int new_nc); + void ReallocCurveXY(int i); + void SetAxisScale(char *a, int j, char *token, int true_); + void SetAxisTitles(char *s, int i); + void SetChartTitle(char *s); + void start_chart(bool end); #endif -// cl1.cpp ------------------------------- -int cl1(int k, int l, int m, int n, + // cl1.cpp ------------------------------- + int cl1(int k, int l, int m, int n, int nklmd, int n2d, LDBLE * q, int *kode, LDBLE toler, int *iter, LDBLE * x, LDBLE * res, LDBLE * error, LDBLE * cu, int *iu, int *s, int check); -void cl1_space(int check, int n2d, int klm, int nklmd); + void cl1_space(int check, int n2d, int klm, int nklmd); -// cl1mp.cpp ------------------------------- -int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + // cl1mp.cpp ------------------------------- + int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); -// class_main.cpp ------------------------------- + // class_main.cpp ------------------------------- #ifdef DOS -int write_banner(void); + int write_banner(void); #endif -/* default.cpp */ + /* default.cpp */ public: -int close_input_files(void); -int close_output_files(void); -static int istream_getc(void *cookie); -int process_file_names(int argc, char *argv[], void **db_cookie, - void **input_cookie, int log); + int close_input_files(void); + int close_output_files(void); + static int istream_getc(void *cookie); + int process_file_names(int argc, char *argv[], void **db_cookie, + void **input_cookie, int log); -/* PHRQ_io_output.cpp */ -void screen_msg(const char *err_str); -void echo_msg(const char *err_str); -int warning_msg(const char *err_str); -void set_forward_output_to_log(int value); -int get_forward_output_to_log(void); + /* PHRQ_io_output.cpp */ + void screen_msg(const char *err_str); + void echo_msg(const char *err_str); + int warning_msg(const char *err_str); + void set_forward_output_to_log(int value); + int get_forward_output_to_log(void); -// dump_file -bool dump_open(const char *file_name); -void dump_fflush(void); -void dump_close(void); -void dump_rewind(void); -bool dump_isopen(void); -void dump_msg(const char * str); + // dump_file + bool dump_open(const char *file_name); + void dump_fflush(void); + void dump_close(void); + void dump_rewind(void); + bool dump_isopen(void); + void dump_msg(const char * str); -// log_file -bool log_open(const char *file_name); -void log_fflush(void); -void log_close(void); -void log_rewind(void); -bool log_isopen(void); -void log_msg(const char * str); + // log_file + bool log_open(const char *file_name); + void log_fflush(void); + void log_close(void); + void log_rewind(void); + bool log_isopen(void); + void log_msg(const char * str); -// error_file -bool error_open(const char *file_name); -void error_fflush(void); -void error_close(void); -void error_rewind(void); -bool error_isopen(void); -void error_msg(const char * str, bool stop=false); + // error_file + bool error_open(const char *file_name); + void error_fflush(void); + void error_close(void); + void error_rewind(void); + bool error_isopen(void); + void error_msg(const char * str, bool stop=false); -// output_file -bool output_open(const char *file_name); -void output_fflush(void); -void output_close(void); -void output_rewind(void); -bool output_isopen(void); -void output_msg(const char * str); + // output_file + bool output_open(const char *file_name); + void output_fflush(void); + void output_close(void); + void output_rewind(void); + bool output_isopen(void); + void output_msg(const char * str); -// punch_file -bool punch_open(const char *file_name); -void punch_fflush(void); -void punch_close(void); -void punch_rewind(void); -bool punch_isopen(void); -void punch_msg(const char * str); + // punch_file + bool punch_open(const char *file_name); + void punch_fflush(void); + void punch_close(void); + void punch_rewind(void); + bool punch_isopen(void); + void punch_msg(const char * str); -void fpunchf_heading(const char *name); -void fpunchf(const char *name, const char *format, double d); -void fpunchf(const char *name, const char *format, char * d); -void fpunchf(const char *name, const char *format, int d); -void fpunchf_user(int user_index, const char *format, double d); -void fpunchf_user(int user_index, const char *format, char * d); -int fpunchf_end_row(const char *format); + void fpunchf_heading(const char *name); + void fpunchf(const char *name, const char *format, double d); + void fpunchf(const char *name, const char *format, char * d); + void fpunchf(const char *name, const char *format, int d); + void fpunchf_user(int user_index, const char *format, double d); + void fpunchf_user(int user_index, const char *format, char * d); + int fpunchf_end_row(const char *format); -// dw.cpp ------------------------------- -int BB(LDBLE T); -LDBLE PS(LDBLE T); -LDBLE VLEST(LDBLE T); -int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); -int QQ(LDBLE T, LDBLE D); -LDBLE BASE(LDBLE D); + // dw.cpp ------------------------------- + int BB(LDBLE T); + LDBLE PS(LDBLE T); + LDBLE VLEST(LDBLE T); + int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); + int QQ(LDBLE T, LDBLE D); + LDBLE BASE(LDBLE D); -// input.cpp ------------------------------- -int reading_database(void); -struct read_callback s_read_callback; -int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); + // input.cpp ------------------------------- + int reading_database(void); + struct read_callback s_read_callback; + int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); -// integrate.cpp ------------------------------- -int calc_all_g(void); -int calc_init_g(void); -int initial_surface_water(void); -int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); -int calc_all_donnan(void); -int calc_init_donnan(void); -LDBLE g_function(LDBLE x_value); -LDBLE midpnt(LDBLE x1, LDBLE x2, int n); -void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); -LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); -LDBLE calc_psi_avg(LDBLE surf_chrg_eq); -int calc_all_donnan_music(void); -int calc_init_donnan_music(void); + // integrate.cpp ------------------------------- + int calc_all_g(void); + int calc_init_g(void); + int initial_surface_water(void); + int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); + int calc_all_donnan(void); + int calc_init_donnan(void); + LDBLE g_function(LDBLE x_value); + LDBLE midpnt(LDBLE x1, LDBLE x2, int n); + void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); + LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); + LDBLE calc_psi_avg(LDBLE surf_chrg_eq); + int calc_all_donnan_music(void); + int calc_init_donnan_music(void); -// inverse.cpp ------------------------------- -int inverse_models(void); -int add_to_file(const char *filename, char *string); -int bit_print(unsigned long bits, int l); -int carbon_derivs(struct inverse *inv_ptr); -int check_isotopes(struct inverse *inv_ptr); -int check_solns(struct inverse *inv_ptr); -int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); -struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); -struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); -int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); -int post_mortem(void); -unsigned long get_bits(unsigned long bits, int position, int number); -unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); -void dump_netpath(struct inverse *inv_ptr); -int dump_netpath_pat(struct inverse *inv_ptr); -int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); -int phase_isotope_inequalities(struct inverse *inv_ptr); -int print_model(struct inverse *inv_ptr); -int punch_model_heading(struct inverse *inv_ptr); -int punch_model(struct inverse *inv_ptr); -void print_isotope(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total(FILE * netpath_file, struct solution *solution_ptr, - const char *elt, const char *string); -void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); -void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); -int range(struct inverse *inv_ptr, unsigned long cur_bits); -int save_bad(unsigned long bits); -int save_good(unsigned long bits); -int save_minimal(unsigned long bits); -unsigned long set_bit(unsigned long bits, int position, int value); -int setup_inverse(struct inverse *inv_ptr); -int set_initial_solution(int n_user_old, int n_user_new); -int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *soln_ptr_orig, - int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); -int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); -int solve_inverse(struct inverse *inv_ptr); -int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); -int subset_bad(unsigned long bits); -int subset_minimal(unsigned long bits); -int superset_minimal(unsigned long bits); -int write_optimize_names(struct inverse *inv_ptr); + // inverse.cpp ------------------------------- + int inverse_models(void); + int add_to_file(const char *filename, char *string); + int bit_print(unsigned long bits, int l); + int carbon_derivs(struct inverse *inv_ptr); + int check_isotopes(struct inverse *inv_ptr); + int check_solns(struct inverse *inv_ptr); + int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); + struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); + struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); + int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); + int post_mortem(void); + unsigned long get_bits(unsigned long bits, int position, int number); + unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); + void dump_netpath(struct inverse *inv_ptr); + int dump_netpath_pat(struct inverse *inv_ptr); + int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); + int phase_isotope_inequalities(struct inverse *inv_ptr); + int print_model(struct inverse *inv_ptr); + int punch_model_heading(struct inverse *inv_ptr); + int punch_model(struct inverse *inv_ptr); + void print_isotope(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); + void print_total(FILE * netpath_file, struct solution *solution_ptr, + const char *elt, const char *string); + void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); + void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); + int range(struct inverse *inv_ptr, unsigned long cur_bits); + int save_bad(unsigned long bits); + int save_good(unsigned long bits); + int save_minimal(unsigned long bits); + unsigned long set_bit(unsigned long bits, int position, int value); + int setup_inverse(struct inverse *inv_ptr); + int set_initial_solution(int n_user_old, int n_user_new); + int set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *soln_ptr_orig, + int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); + int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); + int solve_inverse(struct inverse *inv_ptr); + int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); + int subset_bad(unsigned long bits); + int subset_minimal(unsigned long bits); + int superset_minimal(unsigned long bits); + int write_optimize_names(struct inverse *inv_ptr); -// isotopes.cpp ------------------------------- -int add_isotopes(struct solution *solution_ptr); -int calculate_values(void); -int calculate_isotope_moles(struct element *elt_ptr, - struct solution *solution_ptr, LDBLE total_moles); -LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); -int from_pcil(struct master_isotope *master_isotope_ptr); -int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); -int from_tu(struct master_isotope *master_isotope_ptr); -struct calculate_value *calculate_value_alloc(void); -int calculate_value_free(struct calculate_value *calculate_value_ptr); -struct calculate_value *calculate_value_search(const char *name); -struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); -struct isotope_alpha *isotope_alpha_alloc(void); -struct isotope_alpha *isotope_alpha_search(const char *name); -struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); -struct isotope_ratio *isotope_ratio_alloc(void); -struct isotope_ratio *isotope_ratio_search(const char *name); -struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); -struct master_isotope *master_isotope_alloc(void); -struct master_isotope *master_isotope_search(const char *name); -int print_initial_solution_isotopes(void); -int print_isotope_ratios(void); -int print_isotope_alphas(void); -int punch_isotopes(void); -int punch_calculate_values(void); -int read_calculate_values(void); -int read_isotopes(void); -int read_isotope_ratios(void); -int read_isotope_alphas(void); -int calculate_value_init(struct calculate_value *calculate_value_ptr); -int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); -int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); -int master_isotope_init(struct master_isotope *master_isotope_ptr); + // isotopes.cpp ------------------------------- + int add_isotopes(struct solution *solution_ptr); + int calculate_values(void); + int calculate_isotope_moles(struct element *elt_ptr, + struct solution *solution_ptr, LDBLE total_moles); + LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); + int from_pcil(struct master_isotope *master_isotope_ptr); + int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_tu(struct master_isotope *master_isotope_ptr); + struct calculate_value *calculate_value_alloc(void); + int calculate_value_free(struct calculate_value *calculate_value_ptr); + struct calculate_value *calculate_value_search(const char *name); + struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); + struct isotope_alpha *isotope_alpha_alloc(void); + struct isotope_alpha *isotope_alpha_search(const char *name); + struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); + struct isotope_ratio *isotope_ratio_alloc(void); + struct isotope_ratio *isotope_ratio_search(const char *name); + struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_alloc(void); + struct master_isotope *master_isotope_search(const char *name); + int print_initial_solution_isotopes(void); + int print_isotope_ratios(void); + int print_isotope_alphas(void); + int punch_isotopes(void); + int punch_calculate_values(void); + int read_calculate_values(void); + int read_isotopes(void); + int read_isotope_ratios(void); + int read_isotope_alphas(void); + int calculate_value_init(struct calculate_value *calculate_value_ptr); + int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); + int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); + int master_isotope_init(struct master_isotope *master_isotope_ptr); -// kinetics.cpp ------------------------------- -void cvode_init(void); -int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); -int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); -int set_advection(int i, int use_mix, int use_kinetics, int nsaver); -int free_cvode(void); + // kinetics.cpp ------------------------------- + void cvode_init(void); + int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); + int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_advection(int i, int use_mix, int use_kinetics, int nsaver); + int free_cvode(void); public: -static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); -static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); + static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); -int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); -int calc_kinetic_reaction(struct kinetics *kinetics_ptr, - LDBLE time_step); -int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); -int set_reaction(int i, int use_mix, int use_kinetics); -int set_transport(int i, int use_mix, int use_kinetics, int nsaver); -int store_get_equi_reactants(int k, int kin_end); -int count_pp, count_pg, count_s_s; -LDBLE *x0_moles; + int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); + int calc_kinetic_reaction(struct kinetics *kinetics_ptr, + LDBLE time_step); + int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); + int set_reaction(int i, int use_mix, int use_kinetics); + int set_transport(int i, int use_mix, int use_kinetics, int nsaver); + int store_get_equi_reactants(int k, int kin_end); + int count_pp, count_pg, count_s_s; + LDBLE *x0_moles; -// mainsubs.cpp ------------------------------- -FILE *file_open(char *query, char *default_name, const char *status, - int batch); -int copy_entities(void); -void initialize(void); -int initial_exchangers(int print); -int initial_gas_phases(int print); -int initial_solutions(int print); -int step_save_exch(int n_user); -int step_save_surf(int n_user); -int initial_surfaces(int print); -int reactions(void); -int saver(void); -int xsolution_save(int k_user); -int xexchange_save(int n_user); -int xgas_save(int n_user); -int xpp_assemblage_save(int n_user); -int xs_s_assemblage_save(int n_user); -int xsurface_save(int n_user); -int do_initialize(void); -int do_status(void); -void save_init(int i); -void use_init(void); -int copy_use(int i); -int set_use(void); + // mainsubs.cpp ------------------------------- + FILE *file_open(char *query, char *default_name, const char *status, + int batch); + int copy_entities(void); + void initialize(void); + int initial_exchangers(int print); + int initial_gas_phases(int print); + int initial_solutions(int print); + int step_save_exch(int n_user); + int step_save_surf(int n_user); + int initial_surfaces(int print); + int reactions(void); + int saver(void); + int xsolution_save(int k_user); + int xexchange_save(int n_user); + int xgas_save(int n_user); + int xpp_assemblage_save(int n_user); + int xs_s_assemblage_save(int n_user); + int xsurface_save(int n_user); + int do_initialize(void); + int do_status(void); + void save_init(int i); + void use_init(void); + int copy_use(int i); + int set_use(void); -// model.cpp ------------------------------- -int check_residuals(void); -int free_model_allocs(void); -int ineq(int kode); -int model(void); -int jacobian_sums(void); -int mb_gases(void); -int mb_s_s(void); -int mb_sums(void); -int molalities(int allow_overflow); -int reset(void); -int residuals(void); -int set(int initial); -int sum_species(void); -int surface_model(void); -LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); -LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); -LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); -int numerical_jacobian(void); -void set_inert_moles(void); -void unset_inert_moles(void); + // model.cpp ------------------------------- + int check_residuals(void); + int free_model_allocs(void); + int ineq(int kode); + int model(void); + int jacobian_sums(void); + int mb_gases(void); + int mb_s_s(void); + int mb_sums(void); + int molalities(int allow_overflow); + int reset(void); + int residuals(void); + int set(int initial); + int sum_species(void); + int surface_model(void); + LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); + LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); + LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); + int numerical_jacobian(void); + void set_inert_moles(void); + void unset_inert_moles(void); #ifdef SLNQ -int add_trivial_eqns(int rows, int cols, LDBLE * matrix); -//int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); + int add_trivial_eqns(int rows, int cols, LDBLE * matrix); + //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); #endif -int calc_gas_pressures(void); -int calc_s_s_fractions(void); -int gammas(LDBLE mu); -int initial_guesses(void); -int revise_guesses(void); -int s_s_binary(struct s_s *s_s_ptr); -int s_s_ideal(struct s_s *s_s_ptr); -//int remove_unstable_phases; -int gas_in; -void ineq_init(int max_row_count, int max_column_count); + int calc_gas_pressures(void); + int calc_s_s_fractions(void); + int gammas(LDBLE mu); + int initial_guesses(void); + int revise_guesses(void); + int s_s_binary(struct s_s *s_s_ptr); + int s_s_ideal(struct s_s *s_s_ptr); + //int remove_unstable_phases; + int gas_in; + void ineq_init(int max_row_count, int max_column_count); -// parse.cpp ------------------------------- -int check_eqn(int association); -int get_charge(char *charge, LDBLE * z); -int get_elt(char **t_ptr, char *element, int *i); -int get_elts_in_species(char **t_ptr, LDBLE coef); -int get_num(char **t_ptr, LDBLE * num); -int get_secondary_in_species(char **t_ptr, LDBLE coef); -int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); -int get_coef(LDBLE * coef, char **eqnaddr); -int get_secondary(char **t_ptr, char *element, int *i); -int get_species(char **ptr); + // parse.cpp ------------------------------- + int check_eqn(int association); + int get_charge(char *charge, LDBLE * z); + int get_elt(char **t_ptr, char *element, int *i); + int get_elts_in_species(char **t_ptr, LDBLE coef); + int get_num(char **t_ptr, LDBLE * num); + int get_secondary_in_species(char **t_ptr, LDBLE coef); + int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + int get_coef(LDBLE * coef, char **eqnaddr); + int get_secondary(char **t_ptr, char *element, int *i); + int get_species(char **ptr); -// phqalloc.cpp ------------------------------- + // phqalloc.cpp ------------------------------- public: #if !defined(NDEBUG) -void *PHRQ_malloc(size_t, const char *, int); -void *PHRQ_calloc(size_t, size_t, const char *, int); -void *PHRQ_realloc(void *, size_t, const char *, int); + void *PHRQ_malloc(size_t, const char *, int); + void *PHRQ_calloc(size_t, size_t, const char *, int); + void *PHRQ_realloc(void *, size_t, const char *, int); #else -void *PHRQ_malloc(size_t); -void *PHRQ_calloc(size_t, size_t); -void *PHRQ_realloc(void *, size_t); + void *PHRQ_malloc(size_t); + void *PHRQ_calloc(size_t, size_t); + void *PHRQ_realloc(void *, size_t); #endif -void PHRQ_free(void *ptr); -void PHRQ_free_all(void); + void PHRQ_free(void *ptr); + void PHRQ_free_all(void); public: -// pitzer.cpp ------------------------------- -struct pitz_param *pitz_param_read(char *string, int n); -int pitz_param_search(struct pitz_param *pzp_ptr); -int sit_param_search(struct pitz_param *pzp_ptr); -struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); -struct theta_param *theta_param_alloc(void); -int theta_param_init(struct theta_param *theta_param_ptr); -int gammas_pz(void); -int model_pz(void); -int pitzer(void); -int pitzer_clean_up(void); -int pitzer_init(void); -int pitzer_tidy(void); -int read_pitzer(void); -int set_pz(int initial); -int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_pz(void); -int ISPEC(char *name); -LDBLE G(LDBLE Y); -LDBLE GP(LDBLE Y); -int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); -int BDK(LDBLE X); -int pitzer_initial_guesses(void); -int pitzer_revise_guesses(void); -int PTEMP(LDBLE TK); -LDBLE JAY(LDBLE X); -LDBLE JPRIME(LDBLE Y); -int jacobian_pz(void); + // pitzer.cpp ------------------------------- + struct pitz_param *pitz_param_read(char *string, int n); + int pitz_param_search(struct pitz_param *pzp_ptr); + int sit_param_search(struct pitz_param *pzp_ptr); + struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); + struct theta_param *theta_param_alloc(void); + int theta_param_init(struct theta_param *theta_param_ptr); + int gammas_pz(void); + int model_pz(void); + int pitzer(void); + int pitzer_clean_up(void); + int pitzer_init(void); + int pitzer_tidy(void); + int read_pitzer(void); + int set_pz(int initial); + int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_pz(void); + int ISPEC(char *name); + LDBLE G(LDBLE Y); + LDBLE GP(LDBLE Y); + int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); + int BDK(LDBLE X); + int pitzer_initial_guesses(void); + int pitzer_revise_guesses(void); + int PTEMP(LDBLE TK); + LDBLE JAY(LDBLE X); + LDBLE JPRIME(LDBLE Y); + int jacobian_pz(void); -// pitzer_structures.cpp ------------------------------- -struct pitz_param *pitz_param_alloc(void); -int pitz_param_init(struct pitz_param *pitz_param_ptr); -struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); -int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); + // pitzer_structures.cpp ------------------------------- + struct pitz_param *pitz_param_alloc(void); + int pitz_param_init(struct pitz_param *pitz_param_ptr); + struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); + int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); -// prep.cpp ------------------------------- -int add_potential_factor(void); -int add_cd_music_factors(int n); -int add_surface_charge_balance(void); -int add_cd_music_charge_balances(int i); -int build_gas_phase(void); -int build_jacobian_sums(int k); -int build_mb_sums(void); -int build_min_exch(void); -int build_model(void); -int build_pure_phases(void); -int build_s_s_assemblage(void); -int build_solution_phase_boundaries(void); -int build_species_list(int n); -int build_min_surface(void); -int change_hydrogen_in_elt_list(LDBLE charge); -int clear(void); -int convert_units(struct solution *solution_ptr); -struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); -struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); -int inout(void); -int is_special(struct species *spec); -int mb_for_species_aq(int n); -int mb_for_species_ex(int n); -int mb_for_species_surf(int n); -int quick_setup(void); -int resetup_master(void); -int save_model(void); -int setup_exchange(void); -int setup_gas_phase(void); -int setup_master_rxn(struct master **master_ptr_list, - struct reaction **pe_rxn); -LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); -int setup_pure_phases(void); -int setup_related_surface(void); -int setup_s_s_assemblage(void); -int setup_solution(void); -int setup_surface(void); -int setup_unknowns(void); -int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); -int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); -int store_jacob0(int row, int column, LDBLE coef); -int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); -int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); -int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); -int tidy_redox(void); -struct master **unknown_alloc_master(void); -int write_mb_eqn_x(void); -int write_mb_for_species_list(int n); -int write_mass_action_eqn_x(int stop); + // prep.cpp ------------------------------- + int add_potential_factor(void); + int add_cd_music_factors(int n); + int add_surface_charge_balance(void); + int add_cd_music_charge_balances(int i); + int build_gas_phase(void); + int build_jacobian_sums(int k); + int build_mb_sums(void); + int build_min_exch(void); + int build_model(void); + int build_pure_phases(void); + int build_s_s_assemblage(void); + int build_solution_phase_boundaries(void); + int build_species_list(int n); + int build_min_surface(void); + int change_hydrogen_in_elt_list(LDBLE charge); + int clear(void); + int convert_units(struct solution *solution_ptr); + struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); + struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); + int inout(void); + int is_special(struct species *spec); + int mb_for_species_aq(int n); + int mb_for_species_ex(int n); + int mb_for_species_surf(int n); + int quick_setup(void); + int resetup_master(void); + int save_model(void); + int setup_exchange(void); + int setup_gas_phase(void); + int setup_master_rxn(struct master **master_ptr_list, + struct reaction **pe_rxn); + LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); + int setup_pure_phases(void); + int setup_related_surface(void); + int setup_s_s_assemblage(void); + int setup_solution(void); + int setup_surface(void); + int setup_unknowns(void); + int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); + int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); + int store_jacob0(int row, int column, LDBLE coef); + int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); + int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); + int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); + int tidy_redox(void); + struct master **unknown_alloc_master(void); + int write_mb_eqn_x(void); + int write_mb_for_species_list(int n); + int write_mass_action_eqn_x(int stop); -int check_same_model(void); -int k_temp(LDBLE tc, LDBLE pa); -LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); -int prep(void); -int reprep(void); -int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); -int switch_bases(void); -int write_phase_sys_total(int n); + int check_same_model(void); + int k_temp(LDBLE tc, LDBLE pa); + LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); + int prep(void); + int reprep(void); + int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); + int switch_bases(void); + int write_phase_sys_total(int n); -// print.cpp ------------------------------- -char *sformatf(const char *format, ...); -int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); -int print_all(void); -int print_exchange(void); -int print_gas_phase(void); -int print_master_reactions(void); -int print_reaction(struct reaction *rxn_ptr); -int print_species(void); -int print_surface(void); -int print_user_print(void); -int punch_all(void); -int print_alkalinity(void); -int print_diffuse_layer(struct surface_charge *surface_charge_ptr); -int print_eh(void); -int print_irrev(void); -int print_kinetics(void); -int print_mix(void); -int print_pp_assemblage(void); -int print_s_s_assemblage(void); -int print_saturation_indices(void); -int print_surface_cd_music(void); -int print_totals(void); -int print_using(void); -/*int print_user_print(void);*/ -int punch_gas_phase(void); -int punch_identifiers(void); -int punch_kinetics(void); -int punch_molalities(void); -int punch_activities(void); -int punch_pp_assemblage(void); -int punch_s_s_assemblage(void); -int punch_saturation_indices(void); -int punch_totals(void); -int punch_user_punch(void); + // print.cpp ------------------------------- + char *sformatf(const char *format, ...); + int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); + int print_all(void); + int print_exchange(void); + int print_gas_phase(void); + int print_master_reactions(void); + int print_reaction(struct reaction *rxn_ptr); + int print_species(void); + int print_surface(void); + int print_user_print(void); + int punch_all(void); + int print_alkalinity(void); + int print_diffuse_layer(struct surface_charge *surface_charge_ptr); + int print_eh(void); + int print_irrev(void); + int print_kinetics(void); + int print_mix(void); + int print_pp_assemblage(void); + int print_s_s_assemblage(void); + int print_saturation_indices(void); + int print_surface_cd_music(void); + int print_totals(void); + int print_using(void); + /*int print_user_print(void);*/ + int punch_gas_phase(void); + int punch_identifiers(void); + int punch_kinetics(void); + int punch_molalities(void); + int punch_activities(void); + int punch_pp_assemblage(void); + int punch_s_s_assemblage(void); + int punch_saturation_indices(void); + int punch_totals(void); + int punch_user_punch(void); #if defined MULTICHART -int punch_user_graph(void); + int punch_user_graph(void); #endif -// read.cpp ------------------------------- -int read_input(void); -int read_conc(int n, int count_mass_balance, char *str); -int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); -int read_log_k_only(char *ptr, LDBLE * log_k); -int read_t_c_only(char *ptr, LDBLE *t_c); -int read_p_c_only(char *ptr, LDBLE * p_c); -int read_omega_only(char *ptr, LDBLE *omega); -//int read_delta_v_only(char *ptr, LDBLE * delta_v); -int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description, int allow_negative=FALSE); -int check_key(char *str); -int check_units(char *tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print); -int find_option(char *item, int *n, const char **list, int count_list, - int exact); -int get_option(const char **opt_list, int count_opt_list, char **next_char); -int get_true_false(char *string, int default_value); + // read.cpp ------------------------------- + int read_input(void); + int read_conc(int n, int count_mass_balance, char *str); + int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); + int read_log_k_only(char *ptr, LDBLE * log_k); + int read_t_c_only(char *ptr, LDBLE *t_c); + int read_p_c_only(char *ptr, LDBLE * p_c); + int read_omega_only(char *ptr, LDBLE *omega); + //int read_delta_v_only(char *ptr, LDBLE * delta_v); + int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description, int allow_negative=FALSE); + int check_key(char *str); + int check_units(char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print); + int find_option(char *item, int *n, const char **list, int count_list, + int exact); + int get_option(const char **opt_list, int count_opt_list, char **next_char); + int get_true_false(char *string, int default_value); -int add_psi_master_species(char *token); -int read_advection(void); -int read_analytical_expression_only(char *ptr, LDBLE * log_k); -/* VP: Density Start */ -int read_millero_abcdef (char *ptr, LDBLE * abcdef); -/* VP: Density End */ -int read_copy(void); -int read_debug(void); -int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); -int read_delta_v_only(char *ptr, LDBLE * delta_v, - DELTA_V_UNIT * units); -int read_llnl_aqueous_model_parameters(void); -int read_exchange(void); -int read_exchange_master_species(void); -int read_exchange_species(void); -int read_gas_phase(void); -int read_incremental_reactions(void); -int read_inverse(void); -int read_inv_balances(struct inverse *inverse_ptr, char *next_char); -int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); -int read_inv_phases(struct inverse *inverse_ptr, char *next_char); -int read_kinetics(void); -int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); -int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); -LDBLE *read_list_doubles(char **ptr, int *count_doubles); -int *read_list_ints(char **ptr, int *count_ints, int positive); -int *read_list_t_f(char **ptr, int *count_ints); -int read_master_species(void); -int read_mix(void); -int read_named_logk(void); -int read_phases(void); -int read_print(void); -int read_pure_phases(void); -int read_rates(void); -int read_reaction(void); -int read_reaction_reactants(struct irrev *irrev_ptr); -int read_reaction_steps(struct irrev *irrev_ptr); -int read_solid_solutions(void); -int read_temperature(void); -int read_reaction_temps(struct temperature *temperature_ptr); -int read_save(void); -int read_selected_output(void); -int read_solution(void); -int read_species(void); -int read_surf(void); -int read_surface_master_species(void); -int read_surface_species(void); -int read_use(void); -int read_title(void); -int read_user_print(void); -int read_user_punch(void); + int add_psi_master_species(char *token); + int read_advection(void); + int read_analytical_expression_only(char *ptr, LDBLE * log_k); + /* VP: Density Start */ + int read_millero_abcdef (char *ptr, LDBLE * abcdef); + /* VP: Density End */ + int read_copy(void); + int read_debug(void); + int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); + int read_delta_v_only(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); + int read_llnl_aqueous_model_parameters(void); + int read_exchange(void); + int read_exchange_master_species(void); + int read_exchange_species(void); + int read_gas_phase(void); + int read_incremental_reactions(void); + int read_inverse(void); + int read_inv_balances(struct inverse *inverse_ptr, char *next_char); + int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); + int read_inv_phases(struct inverse *inverse_ptr, char *next_char); + int read_kinetics(void); + int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); + LDBLE *read_list_doubles(char **ptr, int *count_doubles); + int *read_list_ints(char **ptr, int *count_ints, int positive); + int *read_list_t_f(char **ptr, int *count_ints); + int read_master_species(void); + int read_mix(void); + int read_named_logk(void); + int read_phases(void); + int read_print(void); + int read_pure_phases(void); + int read_rates(void); + int read_reaction(void); + int read_reaction_reactants(struct irrev *irrev_ptr); + int read_reaction_steps(struct irrev *irrev_ptr); + int read_solid_solutions(void); + int read_temperature(void); + int read_reaction_temps(struct temperature *temperature_ptr); + int read_save(void); + int read_selected_output(void); + int read_solution(void); + int read_species(void); + int read_surf(void); + int read_surface_master_species(void); + int read_surface_species(void); + int read_use(void); + int read_title(void); + int read_user_print(void); + int read_user_punch(void); #if defined PHREEQ98 -int read_user_graph(void); + int read_user_graph(void); #endif #if defined MULTICHART -int read_user_graph_handler(); + int read_user_graph_handler(); #endif -int next_keyword_or_option(const char **opt_list, int count_opt_list); + int next_keyword_or_option(const char **opt_list, int count_opt_list); -// ReadClass.cxx + // ReadClass.cxx -int read_solution_raw(void); -int read_exchange_raw(void); -int read_surface_raw(void); -int read_equilibrium_phases_raw(void); -int read_kinetics_raw(void); -int read_solid_solutions_raw(void); -int read_gas_phase_raw(void); -int read_reaction_raw(void); -int read_mix_raw(void); -int read_temperature_raw(void); -int read_dump(void); -int read_solution_modify(void); -int read_equilibrium_phases_modify(void); -int read_exchange_modify(void); -int read_surface_modify(void); -int read_solid_solutions_modify(void); -int read_gas_phase_modify(void); -int read_kinetics_modify(void); -int read_reaction_modify(void); -//int read_reaction_temperature_modify(void); -int read_delete(void); -int read_run_cells(void); -int streamify_to_next_keyword(std::istringstream & lines); -int dump_entities(void); -int delete_entities(void); -int run_as_cells(void); -void dump_ostream(std::ostream& os); + int read_solution_raw(void); + int read_exchange_raw(void); + int read_surface_raw(void); + int read_equilibrium_phases_raw(void); + int read_kinetics_raw(void); + int read_solid_solutions_raw(void); + int read_gas_phase_raw(void); + int read_reaction_raw(void); + int read_mix_raw(void); + int read_temperature_raw(void); + int read_dump(void); + int read_solution_modify(void); + int read_equilibrium_phases_modify(void); + int read_exchange_modify(void); + int read_surface_modify(void); + int read_solid_solutions_modify(void); + int read_gas_phase_modify(void); + int read_kinetics_modify(void); + int read_reaction_modify(void); + //int read_reaction_temperature_modify(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); -// readtr.cpp ------------------------------- -int read_transport(void); -int dump(void); -int dump_exchange(int k); -int dump_gas_phase(int k); -int dump_kinetics(int k); -int dump_mix(int k); -int dump_pp_assemblage(int k); -int dump_reaction(int k); -int dump_s_s_assemblage(int k); -int dump_solution(int k); -int dump_surface(int k); -int dump_cpp(void); -int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); + // readtr.cpp ------------------------------- + int read_transport(void); + int dump(void); + int dump_exchange(int k); + int dump_gas_phase(int k); + int dump_kinetics(int k); + int dump_mix(int k); + int dump_pp_assemblage(int k); + int dump_reaction(int k); + int dump_s_s_assemblage(int k); + int dump_solution(int k); + int dump_surface(int k); + int dump_cpp(void); + int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); -// sit.cpp ------------------------------- -int gammas_sit(void); -int model_sit(void); -int sit(void); -int sit_clean_up(void); -int sit_init(void); -int sit_tidy(void); -int read_sit(void); -int set_sit(int initial); -int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); -int check_gammas_sit(void); -int sit_ISPEC(char *name); -/*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ -int sit_initial_guesses(void); -int sit_revise_guesses(void); -int PTEMP_SIT(LDBLE tk); -int jacobian_sit(void); + // sit.cpp ------------------------------- + int gammas_sit(void); + int model_sit(void); + int sit(void); + int sit_clean_up(void); + int sit_init(void); + int sit_tidy(void); + int read_sit(void); + int set_sit(int initial); + int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_sit(void); + int sit_ISPEC(char *name); + /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ + int sit_initial_guesses(void); + int sit_revise_guesses(void); + int PTEMP_SIT(LDBLE tk); + int jacobian_sit(void); -// spread.cpp ------------------------------- -int read_solution_spread(void); -int copy_token_tab(char *token_ptr, char **ptr, int *length); -int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); -int spread_row_free(struct spread_row *spread_row_ptr); -int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); -struct spread_row *string_to_spread_row(char *string); + // spread.cpp ------------------------------- + int read_solution_spread(void); + int copy_token_tab(char *token_ptr, char **ptr, int *length); + int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); + int spread_row_free(struct spread_row *spread_row_ptr); + int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); + struct spread_row *string_to_spread_row(char *string); #ifdef PHREEQCI_GUI -void add_row(struct spread_row *spread_row_ptr); -void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); -void free_spread(void); -struct spread_row *copy_row(struct spread_row *spread_row_ptr); + void add_row(struct spread_row *spread_row_ptr); + void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); + void free_spread(void); + struct spread_row *copy_row(struct spread_row *spread_row_ptr); #endif -// step.cpp ------------------------------- -int step(LDBLE step_fraction); -int xsolution_zero(void); -int add_exchange(struct exchange *exchange_ptr); -int add_gas_phase(struct gas_phase *gas_phase_ptr); -int add_kinetics(struct kinetics *kinetics_ptr); -int add_mix(struct mix *mix_ptr); -int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int add_reaction(struct irrev *irrev_ptr, int step_number, - LDBLE step_fraction); -int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); -int add_solution(struct solution *solution_ptr, LDBLE extensive, - LDBLE intensive); -int add_surface(struct surface *surface_ptr); -int add_temperature(struct temperature *temperature_ptr, int step_number); -int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); -int gas_phase_check(struct gas_phase *gas_phase_ptr); -int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); -int reaction_calc(struct irrev *irrev_ptr); -int solution_check(void); -int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); + // step.cpp ------------------------------- + int step(LDBLE step_fraction); + int xsolution_zero(void); + int add_exchange(struct exchange *exchange_ptr); + int add_gas_phase(struct gas_phase *gas_phase_ptr); + int add_kinetics(struct kinetics *kinetics_ptr); + int add_mix(struct mix *mix_ptr); + int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + int add_reaction(struct irrev *irrev_ptr, int step_number, + LDBLE step_fraction); + int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); + int add_solution(struct solution *solution_ptr, LDBLE extensive, + LDBLE intensive); + int add_surface(struct surface *surface_ptr); + int add_temperature(struct temperature *temperature_ptr, int step_number); + int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + int gas_phase_check(struct gas_phase *gas_phase_ptr); + int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); + int reaction_calc(struct irrev *irrev_ptr); + int solution_check(void); + int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); -// structures.cpp ------------------------------- -int clean_up(void); -int reinitialize(void); -int copier_add(struct copier *copier_ptr, int n_user, int start, int end); -int copier_free(struct copier *copier_ptr); -int copier_init(struct copier *copier_ptr); -static int element_compare(const void *ptr1, const void *ptr2); + // structures.cpp ------------------------------- + int clean_up(void); + int reinitialize(void); + int copier_add(struct copier *copier_ptr, int n_user, int start, int end); + int copier_free(struct copier *copier_ptr); + int copier_init(struct copier *copier_ptr); + static int element_compare(const void *ptr1, const void *ptr2); public: struct element *element_store(const char *element); int elt_list_combine(void); static int elt_list_compare(const void *ptr1, const void *ptr2); protected: -struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); -int elt_list_print(struct elt_list *elt_list_ptr); -struct elt_list *elt_list_save(void); + struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); + int elt_list_print(struct elt_list *elt_list_ptr); + struct elt_list *elt_list_save(void); public: struct exchange *exchange_alloc(void); struct exchange *exchange_bsearch(int k, int *n); protected: -int exchange_comp_compare(const void *ptr1, const void *ptr2); -void exchange_comp_init(struct exch_comp *exch_comp_ptr); + int exchange_comp_compare(const void *ptr1, const void *ptr2); + void exchange_comp_init(struct exch_comp *exch_comp_ptr); public: int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new); + struct exchange *exchange_new_ptr, int n_user_new); protected: -static int exchange_compare(const void *ptr1, const void *ptr2); -int exchange_copy_to_last(int n, int n_user); -int exchange_delete(int n_user_old); -int exchange_duplicate(int n_user_old, int n_user_new); -int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, - const char *description); + static int exchange_compare(const void *ptr1, const void *ptr2); + int exchange_copy_to_last(int n, int n_user); + int exchange_delete(int n_user_old); + int exchange_duplicate(int n_user_old, int n_user_new); + int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, + const char *description); public: int exchange_free(struct exchange *exchange_ptr); protected: -int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); -struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, - int n_user_new); -struct exchange *exchange_search(int n_user, int *n, int print); -int exchange_sort(void); -static int gas_comp_compare(const void *ptr1, const void *ptr2); + int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); + struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, + int n_user_new); + struct exchange *exchange_search(int n_user, int *n, int print); + int exchange_sort(void); + static int gas_comp_compare(const void *ptr1, const void *ptr2); public: struct gas_phase *gas_phase_alloc(void); struct gas_phase *gas_phase_bsearch(int k, int *n); protected: -static int gas_phase_compare(const void *ptr1, const void *ptr2); + static int gas_phase_compare(const void *ptr1, const void *ptr2); public: -int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new); + int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, + struct gas_phase *gas_phase_new_ptr, int n_user_new); protected: -int gas_phase_copy_to_last(int n, int n_user); -int gas_phase_delete(int n_user_old); -int gas_phase_duplicate(int n_user_old, int n_user_new); -int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, - int n_user_end, char *description); + int gas_phase_copy_to_last(int n, int n_user); + int gas_phase_delete(int n_user_old); + int gas_phase_duplicate(int n_user_old, int n_user_new); + int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, + int n_user_end, char *description); public: -int gas_phase_free(struct gas_phase *gas_phase_ptr); -int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, - int n_user_new); -struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, - int n_user_new); -struct gas_phase *gas_phase_search(int n_user, int *n); -int gas_phase_sort(void); -enum entity_type get_entity_enum(char *name); -struct inverse *inverse_alloc(void); -int inverse_delete(int i); -static int inverse_isotope_compare(const void *ptr1, const void *ptr2); -struct inverse *inverse_search(int n_user, int *n); -int inverse_sort(void); -struct irrev *irrev_bsearch(int k, int *n); -int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, - int n_user_new); -int irrev_delete(int n_user_old); -int irrev_duplicate(int n_user_old, int n_user_new); -int irrev_free(struct irrev *irrev_ptr); -struct irrev *irrev_search(int n_user, int *n); -int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); -int irrev_sort(void); + int gas_phase_free(struct gas_phase *gas_phase_ptr); + int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, + int n_user_new); + struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, + int n_user_new); + struct gas_phase *gas_phase_search(int n_user, int *n); + int gas_phase_sort(void); + enum entity_type get_entity_enum(char *name); + struct inverse *inverse_alloc(void); + int inverse_delete(int i); + static int inverse_isotope_compare(const void *ptr1, const void *ptr2); + struct inverse *inverse_search(int n_user, int *n); + int inverse_sort(void); + struct irrev *irrev_bsearch(int k, int *n); + int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, + int n_user_new); + int irrev_delete(int n_user_old); + int irrev_duplicate(int n_user_old, int n_user_new); + int irrev_free(struct irrev *irrev_ptr); + struct irrev *irrev_search(int n_user, int *n); + int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); + int irrev_sort(void); public: struct kinetics *kinetics_alloc(void); struct kinetics *kinetics_bsearch(int k, int *n); protected: -int kinetics_delete(int n_user_old); -int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, - struct kinetics_comp *kinetics_comp_old_ptr); -static int kinetics_compare(const void *ptr1, const void *ptr2); + int kinetics_delete(int n_user_old); + int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, + struct kinetics_comp *kinetics_comp_old_ptr); + static int kinetics_compare(const void *ptr1, const void *ptr2); public: -int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new); + int kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new); protected: -int kinetics_copy_to_last(int n, int n_user); -int kinetics_duplicate(int n_user_old, int n_user_new); -int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, - char *description); + int kinetics_copy_to_last(int n, int n_user); + int kinetics_duplicate(int n_user_old, int n_user_new); + int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, + char *description); public: -int kinetics_free(struct kinetics *kinetics_ptr); + int kinetics_free(struct kinetics *kinetics_ptr); protected: -int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); -struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, - int n_user_new); -struct kinetics *kinetics_search(int n_user, int *n, int print); -int kinetics_sort(void); -struct logk *logk_alloc(void); -int logk_copy2orig(struct logk *logk_ptr); -struct logk *logk_store(char *name, int replace_if_found); -struct logk *logk_search(char *name); -struct master *master_alloc(void); -static int master_compare(const void *ptr1, const void *ptr2); -int master_delete(char *ptr); + int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); + struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, + int n_user_new); + struct kinetics *kinetics_search(int n_user, int *n, int print); + int kinetics_sort(void); + struct logk *logk_alloc(void); + int logk_copy2orig(struct logk *logk_ptr); + struct logk *logk_store(char *name, int replace_if_found); + struct logk *logk_search(char *name); + struct master *master_alloc(void); + static int master_compare(const void *ptr1, const void *ptr2); + int master_delete(char *ptr); public: -struct master *master_bsearch(const char *ptr); -struct master *master_bsearch_primary(char *ptr); -struct master *master_bsearch_secondary(char *ptr); -struct master *master_search(char *ptr, int *n); -struct mix *mix_bsearch(int k, int *n); -int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new); -int mix_delete(int n_user_old); -int mix_duplicate(int n_user_old, int n_user_new); -int mix_free(struct mix *mix_ptr); -struct mix *mix_search(int n_user, int *n, int print); -int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); -int mix_sort(void); -struct pe_data *pe_data_alloc(void); + struct master *master_bsearch(const char *ptr); + struct master *master_bsearch_primary(char *ptr); + struct master *master_bsearch_secondary(char *ptr); + struct master *master_search(char *ptr, int *n); + struct mix *mix_bsearch(int k, int *n); + int mix_copy(struct mix *mix_old_ptr, + struct mix *mix_new_ptr, int n_user_new); + int mix_delete(int n_user_old); + int mix_duplicate(int n_user_old, int n_user_new); + int mix_free(struct mix *mix_ptr); + struct mix *mix_search(int n_user, int *n, int print); + int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); + int mix_sort(void); + struct pe_data *pe_data_alloc(void); public: struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); protected: -int pe_data_store(struct pe_data **pe, const char *token); + int pe_data_store(struct pe_data **pe, const char *token); public: -struct phase *phase_bsearch(const char *ptr, int *j, int print); + struct phase *phase_bsearch(const char *ptr, int *j, int print); protected: -static int phase_compare(const void *ptr1, const void *ptr2); -int phase_delete(int i); -struct phase *phase_store(char *name); + static int phase_compare(const void *ptr1, const void *ptr2); + int phase_delete(int i); + struct phase *phase_store(char *name); public: -struct pp_assemblage *pp_assemblage_alloc(void); -struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); + struct pp_assemblage *pp_assemblage_alloc(void); + struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); protected: -static int pp_assemblage_compare(const void *ptr1, const void *ptr2); + static int pp_assemblage_compare(const void *ptr1, const void *ptr2); public: -int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, - int n_user_new); + int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, + int n_user_new); protected: -int pp_assemblage_copy_to_last(int n, int n_user); -int pp_assemblage_delete(int n_user_old); -int pp_assemblage_duplicate(int n_user_old, int n_user_new); + int pp_assemblage_copy_to_last(int n, int n_user); + int pp_assemblage_delete(int n_user_old); + int pp_assemblage_duplicate(int n_user_old, int n_user_new); public: -int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); + int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); protected: -int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, - int n_user_end, char *description); -int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, - int n_user_new); -struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage - *pp_assemblage_old_ptr, - int n_user_new); -struct pp_assemblage *pp_assemblage_search(int n_user, int *n); -int pp_assemblage_sort(void); -static int pure_phase_compare(const void *ptr1, const void *ptr2); -struct rate *rate_bsearch(char *ptr, int *j); -int rate_free(struct rate *rate_ptr); -struct rate *rate_search(char *name, int *n); -int rate_sort(void); -struct reaction *rxn_alloc(int ntokens); -struct reaction *rxn_dup(struct reaction *rxn_ptr_old); -LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); -int rxn_free(struct reaction *rxn_ptr); -int rxn_print(struct reaction *rxn_ptr); -static int s_compare(const void *ptr1, const void *ptr2); -int s_delete(int i); -struct species *s_search(const char *name); -struct species *s_store(char *name, LDBLE z, int replace_if_found); + int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, + int n_user_end, char *description); + int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, + int n_user_new); + struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage + *pp_assemblage_old_ptr, + int n_user_new); + struct pp_assemblage *pp_assemblage_search(int n_user, int *n); + int pp_assemblage_sort(void); + static int pure_phase_compare(const void *ptr1, const void *ptr2); + struct rate *rate_bsearch(char *ptr, int *j); + int rate_free(struct rate *rate_ptr); + struct rate *rate_search(char *name, int *n); + int rate_sort(void); + struct reaction *rxn_alloc(int ntokens); + struct reaction *rxn_dup(struct reaction *rxn_ptr_old); + LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); + int rxn_free(struct reaction *rxn_ptr); + int rxn_print(struct reaction *rxn_ptr); + static int s_compare(const void *ptr1, const void *ptr2); + int s_delete(int i); + struct species *s_search(const char *name); + struct species *s_store(char *name, LDBLE z, int replace_if_found); public: struct s_s_assemblage *s_s_assemblage_alloc(void); struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); protected: -static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); + static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); public: int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, - int n_user_new); + struct s_s_assemblage *s_s_assemblage_new_ptr, + int n_user_new); protected: -int s_s_assemblage_copy_to_last(int n, int n_user); -int s_s_assemblage_duplicate(int n_user_old, int n_user_new); -int s_s_assemblage_delete(int n_user_old); + int s_s_assemblage_copy_to_last(int n, int n_user); + int s_s_assemblage_duplicate(int n_user_old, int n_user_new); + int s_s_assemblage_delete(int n_user_old); public: int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); protected: -int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, - int n_user, int n_user_end, char *description); -int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage - *s_s_assemblage_old_ptr, - int n_user_new); -struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); -int s_s_assemblage_sort(void); -static int s_s_compare(const void *ptr1, const void *ptr2); -struct save_values *save_values_bsearch(struct save_values *k, int *n); -static int save_values_compare(const void *ptr1, const void *ptr2); -int save_values_sort(void); -int save_values_store(struct save_values *s_v); -static int conc_compare(const void *ptr1, const void *ptr2); -int conc_init(struct conc *conc_ptr); -static int isotope_compare(const void *ptr1, const void *ptr2); + int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, + int n_user, int n_user_end, char *description); + int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, + int n_user_new); + struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage + *s_s_assemblage_old_ptr, + int n_user_new); + struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); + int s_s_assemblage_sort(void); + static int s_s_compare(const void *ptr1, const void *ptr2); + struct save_values *save_values_bsearch(struct save_values *k, int *n); + static int save_values_compare(const void *ptr1, const void *ptr2); + int save_values_sort(void); + int save_values_store(struct save_values *s_v); + static int conc_compare(const void *ptr1, const void *ptr2); + int conc_init(struct conc *conc_ptr); + static int isotope_compare(const void *ptr1, const void *ptr2); public: struct solution *solution_alloc(void); struct solution *solution_bsearch(int k, int *n, int print); struct solution *solution_copy(struct solution *solution_old_ptr, - int n_user_new); + int n_user_new); protected: -int solution_copy_to_last(int n, int n_user_new); -int solution_duplicate(int n_user_old, int n_user_new); -int solution_delete(int n_user_old); -int solution_delete_n(int n); -int solution_free(struct solution *solution_ptr); -int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); -struct solution *solution_replicate(struct solution *solution_old_ptr, - int n_user_new); -int solution_sort(void); -static int species_list_compare_alk(const void *ptr1, const void *ptr2); -static int species_list_compare_master(const void *ptr1, const void *ptr2); -int species_list_sort(void); -struct Change_Surf *change_surf_alloc(int count); + int solution_copy_to_last(int n, int n_user_new); + int solution_duplicate(int n_user_old, int n_user_new); + int solution_delete(int n_user_old); + int solution_delete_n(int n); + int solution_free(struct solution *solution_ptr); + int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); + struct solution *solution_replicate(struct solution *solution_old_ptr, + int n_user_new); + int solution_sort(void); + static int species_list_compare_alk(const void *ptr1, const void *ptr2); + static int species_list_compare_master(const void *ptr1, const void *ptr2); + int species_list_sort(void); + struct Change_Surf *change_surf_alloc(int count); public: struct surface *surface_alloc(void); struct surface *surface_bsearch(int k, int *n); protected: -struct master *surface_get_psi_master(const char *name, int plane); -static int surface_comp_compare(const void *ptr1, const void *ptr2); -static int surface_charge_compare(const void *ptr1, const void *ptr2); -struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); -int surface_charge_free(struct surface_charge *charge); -static int surface_compare(const void *ptr1, const void *ptr2); + struct master *surface_get_psi_master(const char *name, int plane); + static int surface_comp_compare(const void *ptr1, const void *ptr2); + static int surface_charge_compare(const void *ptr1, const void *ptr2); + struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); + int surface_charge_free(struct surface_charge *charge); + static int surface_compare(const void *ptr1, const void *ptr2); public: int surface_copy(struct surface *surface_old_ptr, - struct surface *surface_new_ptr, int n_user_new); + struct surface *surface_new_ptr, int n_user_new); protected: -int surface_copy_to_last(int n, int n_user); -int surface_delete(int n_user_old); -int surface_duplicate(int n_user_old, int n_user_new); + int surface_copy_to_last(int n, int n_user); + int surface_delete(int n_user_old); + int surface_duplicate(int n_user_old, int n_user_new); public: int surface_free(struct surface *surface_ptr); -int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, - char *description); -int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); -struct surface *surface_replicate(struct surface *surface_old_ptr, - int n_user_new); -struct surface *surface_search(int n_user, int *n, int print); -int surface_sort(void); -int system_duplicate(int i, int save_old); -struct temperature *temperature_bsearch(int k, int *n); -int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new); -int temperature_delete(int n_user_old); -int temperature_duplicate(int n_user_old, int n_user_new); -int temperature_free(struct temperature *temperature_ptr); -struct temperature *temperature_search(int n_user, int *n); -int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); -int temperature_sort(void); -int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); -int trxn_combine(void); -int trxn_copy(struct reaction *rxn_ptr); -LDBLE trxn_find_coef(const char *str, int start); -int trxn_print(void); -int trxn_reverse_k(void); -int trxn_sort(void); -int trxn_swap(const char *token); -struct unknown *unknown_alloc(void); -int unknown_delete(int i); -int unknown_free(struct unknown *unknown_ptr); -int entity_exists(char *name, int n_user); + int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, + char *description); + int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); + struct surface *surface_replicate(struct surface *surface_old_ptr, + int n_user_new); + struct surface *surface_search(int n_user, int *n, int print); + int surface_sort(void); + int system_duplicate(int i, int save_old); + struct temperature *temperature_bsearch(int k, int *n); + int temperature_copy(struct temperature *temperature_old_ptr, + struct temperature *temperature_new_ptr, int n_user_new); + int temperature_delete(int n_user_old); + int temperature_duplicate(int n_user_old, int n_user_new); + int temperature_free(struct temperature *temperature_ptr); + struct temperature *temperature_search(int n_user, int *n); + int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); + int temperature_sort(void); + int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_combine(void); + int trxn_copy(struct reaction *rxn_ptr); + LDBLE trxn_find_coef(const char *str, int start); + int trxn_print(void); + int trxn_reverse_k(void); + int trxn_sort(void); + int trxn_swap(const char *token); + struct unknown *unknown_alloc(void); + int unknown_delete(int i); + int unknown_free(struct unknown *unknown_ptr); + int entity_exists(char *name, int n_user); -static int exchange_compare_int(const void *ptr1, const void *ptr2); -static int gas_phase_compare_int(const void *ptr1, const void *ptr2); -static int inverse_compare(const void *ptr1, const void *ptr2); -int inverse_free(struct inverse *inverse_ptr); -static int irrev_compare(const void *ptr1, const void *ptr2); -static int irrev_compare_int(const void *ptr1, const void *ptr2); -static int kinetics_compare_int(const void *ptr1, const void *ptr2); -int logk_init(struct logk *logk_ptr); -static int master_compare_string(const void *ptr1, const void *ptr2); -int master_free(struct master *master_ptr); -static int mix_compare(const void *ptr1, const void *ptr2); -static int mix_compare_int(const void *ptr1, const void *ptr2); -struct phase *phase_alloc(void); -static int phase_compare_string(const void *ptr1, const void *ptr2); -int phase_free(struct phase *phase_ptr); -int phase_init(struct phase *phase_ptr); -static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int rate_compare(const void *ptr1, const void *ptr2); -static int rate_compare_string(const void *ptr1, const void *ptr2); -struct species *s_alloc(void); -int s_free(struct species *s_ptr); -int s_init(struct species *s_ptr); -static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); -static int solution_compare(const void *ptr1, const void *ptr2); -static int solution_compare_int(const void *ptr1, const void *ptr2); -static int species_list_compare(const void *ptr1, const void *ptr2); -static int surface_compare_int(const void *ptr1, const void *ptr2); -static int temperature_compare(const void *ptr1, const void *ptr2); -static int temperature_compare_int(const void *ptr1, const void *ptr2); -static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); -int trxn_multiply(LDBLE coef); + static int exchange_compare_int(const void *ptr1, const void *ptr2); + static int gas_phase_compare_int(const void *ptr1, const void *ptr2); + static int inverse_compare(const void *ptr1, const void *ptr2); + int inverse_free(struct inverse *inverse_ptr); + static int irrev_compare(const void *ptr1, const void *ptr2); + static int irrev_compare_int(const void *ptr1, const void *ptr2); + static int kinetics_compare_int(const void *ptr1, const void *ptr2); + int logk_init(struct logk *logk_ptr); + static int master_compare_string(const void *ptr1, const void *ptr2); + int master_free(struct master *master_ptr); + static int mix_compare(const void *ptr1, const void *ptr2); + static int mix_compare_int(const void *ptr1, const void *ptr2); + struct phase *phase_alloc(void); + static int phase_compare_string(const void *ptr1, const void *ptr2); + int phase_free(struct phase *phase_ptr); + int phase_init(struct phase *phase_ptr); + static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int rate_compare(const void *ptr1, const void *ptr2); + static int rate_compare_string(const void *ptr1, const void *ptr2); + struct species *s_alloc(void); + int s_free(struct species *s_ptr); + int s_init(struct species *s_ptr); + static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int solution_compare(const void *ptr1, const void *ptr2); + static int solution_compare_int(const void *ptr1, const void *ptr2); + static int species_list_compare(const void *ptr1, const void *ptr2); + static int surface_compare_int(const void *ptr1, const void *ptr2); + static int temperature_compare(const void *ptr1, const void *ptr2); + static int temperature_compare_int(const void *ptr1, const void *ptr2); + static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); + int trxn_multiply(LDBLE coef); #ifdef PHREEQCI_GUI -extern void free_spread(void); + extern void free_spread(void); #endif #if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern void MergeFinalize(void); + extern void MergeFinalize(void); #endif -// convert class to struct (structures.cpp) -struct mix * cxxMix2mix(const cxxMix *mx); -struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); -struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); -struct exchange * cxxExchange2exchange(const cxxExchange * ex); -struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); -struct master * Get_exch_master(const cxxExchComp * ec); -struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); -struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); -struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); -struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); -struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); -struct irrev * cxxReaction2irrev(const cxxReaction * rxn); -struct solution * cxxSolution2solution(const cxxSolution * sol); -struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); -struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); -struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); -struct surface * cxxSurface2surface(const cxxSurface * surf); -struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); -struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); + // convert class to struct (structures.cpp) + struct mix * cxxMix2mix(const cxxMix *mx); + struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); + struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); + struct exchange * cxxExchange2exchange(const cxxExchange * ex); + struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); + struct master * Get_exch_master(const cxxExchComp * ec); + struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); + struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); + struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); + struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); + struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); + struct irrev * cxxReaction2irrev(const cxxReaction * rxn); + struct solution * cxxSolution2solution(const cxxSolution * sol); + struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); + struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); + struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); + struct surface * cxxSurface2surface(const cxxSurface * surf); + struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); + struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); -struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); -struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); -struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); -struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); -struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); + struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); + struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); + struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); + struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); -void Use2cxxStorageBin(cxxStorageBin & sb); -void phreeqc2cxxStorageBin(cxxStorageBin & sb); -void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); -void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); -void cxxStorageBin2phreeqc(cxxStorageBin & sb); + void Use2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb); -/* tally.cpp */ -void add_all_components_tally(void); -int build_tally_table(void); -int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); -int diff_tally_table(void); -int extend_tally_table(void); -int free_tally_table(void); -int fill_tally_table(int *n_user, int index_conservative, int n_buffer); -int get_tally_table_rows_columns(int *rows, int *columns); -int get_tally_table_column_heading(int column, int *type, char *string); -int get_tally_table_row_heading(int column, char *string); -int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); -int zero_tally_table(void); -int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); -int get_all_components(void); -int print_tally_table(void); -int set_reaction_moles(int n_user, LDBLE moles); -int set_reaction_temperature(int n_user, LDBLE tc); -int set_kinetics_time(int n_user, LDBLE step); + /* tally.cpp */ + void add_all_components_tally(void); + int build_tally_table(void); + int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); + int diff_tally_table(void); + int extend_tally_table(void); + int free_tally_table(void); + int fill_tally_table(int *n_user, int index_conservative, int n_buffer); + int get_tally_table_rows_columns(int *rows, int *columns); + int get_tally_table_column_heading(int column, int *type, char *string); + int get_tally_table_row_heading(int column, char *string); + int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); + int zero_tally_table(void); + int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); + int get_all_components(void); + int print_tally_table(void); + int set_reaction_moles(int n_user, LDBLE moles); + int set_reaction_temperature(int n_user, LDBLE tc); + int set_kinetics_time(int n_user, LDBLE step); -// tidy.cpp ------------------------------- -int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); -int add_logks(struct logk *logk_ptr, int repeats); -LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); -int replace_solids_gases(void); -int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); -int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); -int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); + // tidy.cpp ------------------------------- + int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); + int add_logks(struct logk *logk_ptr, int repeats); + LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); + int replace_solids_gases(void); + int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); + int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); + int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); public: -int tidy_punch(void); -int tidy_model(void); -int check_species_input(void); -LDBLE coef_in_master(struct master *master_ptr); -int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); -int reset_last_model(void); -int rewrite_eqn_to_primary(void); -int rewrite_eqn_to_secondary(void); -int species_rxn_to_trxn(struct species *s_ptr); -int tidy_logk(void); -int tidy_exchange(void); -int tidy_min_exchange(void); -int tidy_kin_exchange(void); -int tidy_gas_phase(void); -int tidy_inverse(void); -int tidy_isotopes(void); -int tidy_isotope_ratios(void); -int tidy_isotope_alphas(void); -int tidy_kin_surface(void); -int tidy_master_isotope(void); -int tidy_min_surface(void); -int tidy_phases(void); -int tidy_pp_assemblage(void); -int tidy_solutions(void); -int tidy_s_s_assemblage(void); -int tidy_species(void); -int tidy_surface(void); -int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); -static LDBLE f_spinodal(LDBLE x, void *); -int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); -int s_s_calc_a0_a1(struct s_s *s_s_ptr); + int tidy_punch(void); + int tidy_model(void); + int check_species_input(void); + LDBLE coef_in_master(struct master *master_ptr); + int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); + int reset_last_model(void); + int rewrite_eqn_to_primary(void); + int rewrite_eqn_to_secondary(void); + int species_rxn_to_trxn(struct species *s_ptr); + int tidy_logk(void); + int tidy_exchange(void); + int tidy_min_exchange(void); + int tidy_kin_exchange(void); + int tidy_gas_phase(void); + int tidy_inverse(void); + int tidy_isotopes(void); + int tidy_isotope_ratios(void); + int tidy_isotope_alphas(void); + int tidy_kin_surface(void); + int tidy_master_isotope(void); + int tidy_min_surface(void); + int tidy_phases(void); + int tidy_pp_assemblage(void); + int tidy_solutions(void); + int tidy_s_s_assemblage(void); + int tidy_species(void); + int tidy_surface(void); + int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); + static LDBLE f_spinodal(LDBLE x, void *); + int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); + int s_s_calc_a0_a1(struct s_s *s_s_ptr); -// transport.cpp ------------------------------- -int transport(void); -int set_initial_moles(int i); -int sum_surface_comp(struct surface *source1, LDBLE f1, - struct surface *source2, int k, LDBLE f2, - struct surface *target, LDBLE new_Dw); -int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, - LDBLE new_Dw, int cell); -LDBLE viscosity(void); -int multi_D(LDBLE DDt, int mobile_cell, int stagnant); -int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); -int fill_spec(int cell_no); -int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); -static int sort_species_name(const void *ptr1, const void *ptr2); -int disp_surf(LDBLE stagkin_time); -int diff_stag_surf(int mobile_cell); -int check_surfaces(struct surface *surface_ptr1, - struct surface *surface_ptr2); -int mobile_surface_copy(struct surface *surface_old_ptr, - struct surface *surf_ptr1, int n_user_new, - int move_old); -int init_mix(void); -int init_heat_mix(int nmix); -int heat_mix(int heat_nmix); -int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); + // transport.cpp ------------------------------- + int transport(void); + int set_initial_moles(int i); + int sum_surface_comp(struct surface *source1, LDBLE f1, + struct surface *source2, int k, LDBLE f2, + struct surface *target, LDBLE new_Dw); + int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, + LDBLE new_Dw, int cell); + LDBLE viscosity(void); + int multi_D(LDBLE DDt, int mobile_cell, int stagnant); + int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); + int fill_spec(int cell_no); + int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); + static int sort_species_name(const void *ptr1, const void *ptr2); + int disp_surf(LDBLE stagkin_time); + int diff_stag_surf(int mobile_cell); + int check_surfaces(struct surface *surface_ptr1, + struct surface *surface_ptr2); + int mobile_surface_copy(struct surface *surface_old_ptr, + struct surface *surf_ptr1, int n_user_new, + int move_old); + int init_mix(void); + int init_heat_mix(int nmix); + int heat_mix(int heat_nmix); + int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); -// utilities.cpp ------------------------------- + // utilities.cpp ------------------------------- public: -int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); protected: -int backspace_screen(int spaces); -LDBLE calc_alk(struct reaction *rxn_ptr); + int backspace_screen(int spaces); + LDBLE calc_alk(struct reaction *rxn_ptr); public: int compute_gfw(const char *string, LDBLE * gfw); - #if defined PHREEQ98 +#if defined PHREEQ98 int copy_title(char *token_ptr, char **ptr, int *length); - #endif -int copy_token(char *token_ptr, char **ptr, int *length); -int dup_print(const char *ptr, int emphasis); -int equal(LDBLE a, LDBLE b, LDBLE eps); +#endif + int copy_token(char *token_ptr, char **ptr, int *length); + int dup_print(const char *ptr, int emphasis); + int equal(LDBLE a, LDBLE b, LDBLE eps); public: void *free_check_null(void *ptr); protected: -void free_hash_strings(HashTable * Table); -int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); -int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); -void hdestroy_multi(HashTable * HashTable_ptr); -ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); -int islegit(const char c); + void free_hash_strings(HashTable * Table); + int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); + int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); + void hdestroy_multi(HashTable * HashTable_ptr); + ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); + int islegit(const char c); public: -void malloc_error(void); + void malloc_error(void); protected: -int parse_couple(char *token); -int print_centered(const char *string); + int parse_couple(char *token); + int print_centered(const char *string); public: -static int replace(const char *str1, const char *str2, char *str); + static int replace(const char *str1, const char *str2, char *str); protected: -void space(void **ptr, int i, int *max, int struct_size); -void squeeze_white(char *s_l); -int status(int count, const char *str); -void str_tolower(char *str); -void str_toupper(char *str); -static int strcmp_nocase(const char *str1, const char *str2); -int strcmp_nocase_arg1(const char *str1, const char *str2); + void space(void **ptr, int i, int *max, int struct_size); + void squeeze_white(char *s_l); + int status(int count, const char *str); + void str_tolower(char *str); + void str_toupper(char *str); + static int strcmp_nocase(const char *str1, const char *str2); + int strcmp_nocase_arg1(const char *str1, const char *str2); public: char *string_duplicate(const char *token); char *string_hsave(const char *str); protected: -char *string_pad(char *str, int i); -int string_trim(char *str); -int string_trim_right(char *str); -int string_trim_left(char *str); -static LDBLE under(LDBLE xval); -void zero_double(LDBLE * target, int n); -int get_input_errors(void); + char *string_pad(char *str, int i); + int string_trim(char *str); + int string_trim_right(char *str); + int string_trim_left(char *str); + static LDBLE under(LDBLE xval); + void zero_double(LDBLE * target, int n); + int get_input_errors(void); #ifdef PHREEQ98 -void AddToCEntry(char *a, int l, int i); -void ApplicationProcessMessages(void); -int copy_title(char *token_ptr, char **ptr, int *length); -extern int clean_up_null(void); + void AddToCEntry(char *a, int l, int i); + void ApplicationProcessMessages(void); + int copy_title(char *token_ptr, char **ptr, int *length); + extern int clean_up_null(void); #endif -int isamong(char c, const char *s_l); -Address Hash_multi(HashTable * Table, char *Key); -void ExpandTable_multi(HashTable * Table); + int isamong(char c, const char *s_l); + Address Hash_multi(HashTable * Table, char *Key); + void ExpandTable_multi(HashTable * Table); public: bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); @@ -1319,758 +1319,758 @@ public: protected: void init(void); -// -//Data members -// + // + //Data members + // protected: -std::list cookie_list; -std::ifstream * in_stream; -std::ifstream * db_stream; + std::list cookie_list; + std::ifstream * in_stream; + std::ifstream * db_stream; -PHRQ_io *phrq_io; + PHRQ_io *phrq_io; -/* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ - struct model last_model; - int same_model; - int same_temperature; - int same_pressure; - struct punch punch; -/* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ + struct model last_model; + int same_model; + int same_temperature; + int same_pressure; + struct punch punch; + /* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ - struct temperature *temperature; - int count_temperature; -/* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ + struct temperature *temperature; + int count_temperature; + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ - int g_iterations; - LDBLE G_TOL; - struct surface *surface; - struct surface *dbg_surface; - int count_surface; - int max_surface; - struct Charge_Group *charge_group; - int change_surf_count; - struct Change_Surf *change_surf; + int g_iterations; + LDBLE G_TOL; + struct surface *surface; + struct surface *dbg_surface; + int count_surface; + int max_surface; + struct Charge_Group *charge_group; + int change_surf_count; + struct Change_Surf *change_surf; -/* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ - struct exchange *exchange; - struct exchange *dbg_exchange; - int count_exchange; - int max_exchange; -/* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ + struct exchange *exchange; + struct exchange *dbg_exchange; + int count_exchange; + int max_exchange; + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ - struct kinetics *kinetics; - struct kinetics *dbg_kinetics; - int count_kinetics; - int max_kinetics; + struct kinetics *kinetics; + struct kinetics *dbg_kinetics; + int count_kinetics; + int max_kinetics; - int count_save_values; - struct save_values *save_values; + int count_save_values; + struct save_values *save_values; -/*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ - struct save save; -/*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ + struct save save; + /*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ - struct Use use; - struct Use *dbg_use; -/*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ + struct Use use; + struct Use *dbg_use; + /*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ - struct copier copy_solution; - struct copier copy_pp_assemblage; - struct copier copy_exchange; - struct copier copy_surface; - struct copier copy_s_s_assemblage; - struct copier copy_gas_phase; - struct copier copy_kinetics; - struct copier copy_mix; - struct copier copy_irrev; - struct copier copy_temperature; + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_s_s_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_irrev; + struct copier copy_temperature; -/*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ - struct inverse *inverse; - int count_inverse; + struct inverse *inverse; + int count_inverse; -/*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ - struct mix *mix; - struct mix *dbg_mix; - int count_mix; -/*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ + struct mix *mix; + struct mix *dbg_mix; + int count_mix; + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ - struct irrev *irrev; - struct irrev *dbg_irrev; - int count_irrev; -/*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ + struct irrev *irrev; + struct irrev *dbg_irrev; + int count_irrev; + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ - int count_gas_phase; - int max_gas_phase; - struct gas_phase *gas_phase; -/*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ + int count_gas_phase; + int max_gas_phase; + struct gas_phase *gas_phase; + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ - int count_s_s_assemblage; - int max_s_s_assemblage; - struct s_s_assemblage *s_s_assemblage; -/*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ + int count_s_s_assemblage; + int max_s_s_assemblage; + struct s_s_assemblage *s_s_assemblage; + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ - int count_pp_assemblage; - int max_pp_assemblage; - struct pp_assemblage *pp_assemblage; - struct pp_assemblage *dbg_pp_assemblage; -/*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ + int count_pp_assemblage; + int max_pp_assemblage; + struct pp_assemblage *pp_assemblage; + struct pp_assemblage *dbg_pp_assemblage; + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ - int count_species_list; - int max_species_list; - struct species_list *species_list; -/*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ + int count_species_list; + int max_species_list; + struct species_list *species_list; + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ -/*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ - struct solution **solution; - struct solution **dbg_solution; - int count_solution; - int max_solution; + struct solution **solution; + struct solution **dbg_solution; + int count_solution; + int max_solution; -struct iso *iso_defaults; -int count_iso_defaults; + struct iso *iso_defaults; + int count_iso_defaults; -/*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ - char *title_x; - int new_x; - char *description_x; - LDBLE tc_x; - LDBLE tk_x; - LDBLE patm_x; - LDBLE ph_x; - LDBLE solution_pe_x; - LDBLE mu_x; - LDBLE ah2o_x; - LDBLE density_x; - LDBLE total_h_x; - LDBLE total_o_x; - LDBLE cb_x; - LDBLE total_ions_x; - LDBLE mass_water_aq_x; - LDBLE mass_water_surfaces_x; - LDBLE mass_water_bulk_x; - char *units_x; - struct pe_data *pe_x; - int count_isotopes_x; - struct isotope *isotopes_x; - int default_pe_x; -/* int diffuse_layer_x;*/ - enum DIFFUSE_LAYER_TYPE dl_type_x; - LDBLE total_carbon; - LDBLE total_co2; - LDBLE total_alkalinity; - LDBLE gfw_water; - LDBLE step_x; - LDBLE kin_time_x; -/*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ - int count_cells; - int count_shifts; - int ishift; - int bcon_first; - int bcon_last; - int correct_disp; - LDBLE tempr; - LDBLE timest; - int simul_tr; - LDBLE diffc; - LDBLE heat_diffc; - int cell; - LDBLE mcd_substeps; - struct stag_data *stag_data; - int print_modulus; - int punch_modulus; - int dump_in; - int dump_modulus; - int transport_warnings; - struct cell_data *cell_data; - int multi_Dflag; /* signals calc'n of multicomponent diffusion */ - int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ - LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ - LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ - LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ - LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ - LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ - LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, - Dp = Dw * (multi_Dpor)^multi_Dn */ - LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, - Dpil = Dw / interlayer_tortf */ + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE patm_x; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + struct pe_data *pe_x; + int count_isotopes_x; + struct isotope *isotopes_x; + int default_pe_x; + /* int diffuse_layer_x;*/ + enum DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ - int cell_no; -/*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ - int count_ad_cells; - int count_ad_shifts; - int print_ad_modulus; - int punch_ad_modulus; - int *advection_punch, *advection_print; - LDBLE advection_kin_time; - LDBLE advection_kin_time_defined; - int advection_warnings; + int cell_no; + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; -/*---------------------------------------------------------------------- - * Keywords - *---------------------------------------------------------------------- */ -struct const_key *keyword; -int NKEYS; + /*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ + struct const_key *keyword; + int NKEYS; - struct key *keyword_hash; - int new_model, new_exchange, new_pp_assemblage, new_surface, - new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, - new_pitzer; -/*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ + struct key *keyword_hash; + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, + new_pitzer; + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ - struct element **elements; - int count_elements; - int max_elements; - struct element *element_h_one; + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; -/*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ - int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; -/*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; + /*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ -/*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ - struct logk **logk; - int count_logk; - int max_logk; + struct logk **logk; + int count_logk; + int max_logk; - char *moles_per_kilogram_string; - char *pe_string; + char *moles_per_kilogram_string; + char *pe_string; - struct species **s; - int count_s; - int max_s; + struct species **s; + int count_s; + int max_s; - struct species **s_x; - int count_s_x; - int max_s_x; + struct species **s_x; + int count_s_x; + int max_s_x; - struct species *s_h2o; - struct species *s_hplus; - struct species *s_h3oplus; - struct species *s_eminus; - struct species *s_co3; - struct species *s_h2; - struct species *s_o2; -/*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ - struct phase **phases; - int count_phases; - int max_phases; -/*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ + struct phase **phases; + int count_phases; + int max_phases; + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; -/*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ - struct unknown **x; - int count_unknowns; - int max_unknowns; + struct unknown **x; + int count_unknowns; + int max_unknowns; - struct unknown *ah2o_unknown; - struct unknown *alkalinity_unknown; - struct unknown *carbon_unknown; - struct unknown *charge_balance_unknown; - struct unknown *exchange_unknown; - struct unknown *mass_hydrogen_unknown; - struct unknown *mass_oxygen_unknown; - struct unknown *mb_unknown; - struct unknown *mu_unknown; - struct unknown *pe_unknown; - struct unknown *ph_unknown; - struct unknown *pure_phase_unknown; - struct unknown *solution_phase_boundary_unknown; - struct unknown *surface_unknown; - struct unknown *gas_unknown; - struct unknown *s_s_unknown; -/*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *s_s_unknown; + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ - struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; -/* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ - struct prints pr; - int status_on, status_interval; - float status_timer; - int count_warnings; + struct prints pr; + int status_on, status_interval; + float status_timer; + int count_warnings; -/* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ - struct rate *rates; - int count_rates; - LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, - rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; - int count_rate_p; -/* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ - struct rate *user_print; - struct rate *user_punch; - char **user_punch_headings; - int user_punch_count_headings; - int n_user_punch_index; + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + int count_rate_p; + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + char **user_punch_headings; + int user_punch_count_headings; + int n_user_punch_index; #if defined PHREEQ98 - struct rate *user_graph; - char **user_graph_headings; - int user_graph_count_headings; + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; #endif #if defined MULTICHART - ChartHandler chart_handler; + ChartHandler chart_handler; #endif -/* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ - char error_string[10 * MAX_LENGTH]; - int simulation; - int state; - int reaction_step; - int transport_step; - int transport_start; - int advection_step; - int stop_program; - int incremental_reactions; + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + char error_string[10 * MAX_LENGTH]; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; - int count_strings; - int max_strings; + int count_strings; + int max_strings; - LDBLE *array; - LDBLE *delta; - LDBLE *residual; + LDBLE *array; + LDBLE *delta; + LDBLE *residual; - int input_error; + int input_error; - int next_keyword; - int parse_error; - int paren_count; - int iterations; - int gamma_iterations; - int run_reactions_iterations; + int next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; - int max_line; - char *line; - char *line_save; + int max_line; + char *line; + char *line_save; - LDBLE LOG_10; + LDBLE LOG_10; - int debug_model; - int debug_prep; - int debug_set; - int debug_diffuse_layer; - int debug_inverse; + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; - LDBLE inv_tol_default; - int itmax; - LDBLE ineq_tol; - LDBLE convergence_tolerance; - LDBLE step_size; - LDBLE pe_step_size; - LDBLE step_size_now; - LDBLE pe_step_size_now; - LDBLE pp_scale; - LDBLE pp_column_scale; - int diagonal_scale; /* 0 not used, 1 used */ - int mass_water_switch; - int delay_mass_water; - LDBLE censor; - int aqueous_only; - int negative_concentrations; - int calculating_deriv; - int numerical_deriv; + LDBLE inv_tol_default; + int itmax; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; - int count_total_steps; - int phast; - LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; - int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, - llnl_count_co2_coefs; + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; - char *selected_output_file_name; - char *dump_file_name; - int remove_unstable_phases; + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; #ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; + struct spread_sheet g_spread_sheet; #endif -/* ---------------------------------------------------------------------- */ -/* - * Hash definitions - */ + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ - HashTable *strings_hash_table; - HashTable *elements_hash_table; - HashTable *species_hash_table; - HashTable *phases_hash_table; - HashTable *keyword_hash_table; - HashTable *logk_hash_table; - HashTable *master_isotope_hash_table; + HashTable *strings_hash_table; + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *keyword_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; #if defined(PHREEQCI_GUI) #include "../../phreeqci_gui.h" #endif /* defined(PHREEQCI_GUI) */ -/* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ -struct name_coef match_tokens[50]; -int count_match_tokens; -int count_master_isotope; -struct master_isotope **master_isotope; -int max_master_isotope; -int initial_solution_isotopes; -int count_calculate_value; -struct calculate_value **calculate_value; -int max_calculate_value; -HashTable *calculate_value_hash_table; -int count_isotope_ratio; -struct isotope_ratio **isotope_ratio; -int max_isotope_ratio; -HashTable *isotope_ratio_hash_table; -int count_isotope_alpha; -struct isotope_alpha **isotope_alpha; -int max_isotope_alpha; -HashTable *isotope_alpha_hash_table; -int phreeqc_mpi_myself; -int first_read_input; -char *user_database; + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + struct name_coef match_tokens[50]; + int count_match_tokens; + int count_master_isotope; + struct master_isotope **master_isotope; + int max_master_isotope; + int initial_solution_isotopes; + int count_calculate_value; + struct calculate_value **calculate_value; + int max_calculate_value; + HashTable *calculate_value_hash_table; + int count_isotope_ratio; + struct isotope_ratio **isotope_ratio; + int max_isotope_ratio; + HashTable *isotope_ratio_hash_table; + int count_isotope_alpha; + struct isotope_alpha **isotope_alpha; + int max_isotope_alpha; + HashTable *isotope_alpha_hash_table; + int phreeqc_mpi_myself; + int first_read_input; + char *user_database; -int have_punch_name; -/* VP: Density Start */ -int print_density; -/* VP: Density End */ + int have_punch_name; + /* VP: Density Start */ + int print_density; + /* VP: Density End */ -LDBLE *zeros; -int zeros_max; + LDBLE *zeros; + int zeros_max; -LDBLE cell_pore_volume; -LDBLE cell_porosity; -LDBLE cell_volume; -LDBLE cell_saturation; -struct system_species *sys; -int count_sys, max_sys; -LDBLE sys_tot; -LDBLE AA_basic, BB_basic, CC, I_m, rho_0; -LDBLE solution_mass, solution_volume; -LDBLE f_rho(LDBLE rho_old); + LDBLE cell_pore_volume; + LDBLE cell_porosity; + LDBLE cell_volume; + LDBLE cell_saturation; + struct system_species *sys; + int count_sys, max_sys; + LDBLE sys_tot; + LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE solution_mass, solution_volume; + LDBLE f_rho(LDBLE rho_old); -/* phqalloc.cpp ------------------------------- */ -PHRQMemHeader *s_pTail; -std::stringstream merged_database_stream; -std::stringstream merged_input_stream; + /* phqalloc.cpp ------------------------------- */ + PHRQMemHeader *s_pTail; + std::stringstream merged_database_stream; + std::stringstream merged_input_stream; -/* Basic */ -PBasic * basic_interpreter; + /* Basic */ + PBasic * basic_interpreter; -/* cl1.cpp ------------------------------- */ -LDBLE *x_arg, *res_arg, *scratch; -int x_arg_max, res_arg_max, scratch_max; + /* cl1.cpp ------------------------------- */ + LDBLE *x_arg, *res_arg, *scratch; + int x_arg_max, res_arg_max, scratch_max; -/* dw.cpp ------------------------------- */ -/* COMMON /QQQQ/ */ -LDBLE Q0, Q5; -LDBLE GASCON, TZ, AA; -LDBLE Z, DZ, Y; -LDBLE G1, G2, GF; -LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + LDBLE Q0, Q5; + LDBLE GASCON, TZ, AA; + LDBLE Z, DZ, Y; + LDBLE G1, G2, GF; + LDBLE B1, B2, B1T, B2T, B1TT, B2TT; -/* input.cpp ------------------------------- */ -int add_char_to_line(int *i, char c); -int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, - int allow_empty, int allow_eof, int allow_keyword, - int print); -int get_line(PFN_READ_CALLBACK pfn, void *cookie); -int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); -int read_database(PFN_READ_CALLBACK pfn, void *cookie); -int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); -int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); -int check_line_return; + /* input.cpp ------------------------------- */ + int add_char_to_line(int *i, char c); + int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, + int allow_empty, int allow_eof, int allow_keyword, + int print); + int get_line(PFN_READ_CALLBACK pfn, void *cookie); + int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); + int read_database(PFN_READ_CALLBACK pfn, void *cookie); + int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); + int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); + int check_line_return; -/* integrate.cpp ------------------------------- */ -LDBLE midpoint_sv; -LDBLE z, xd, alpha; -struct surface_charge *surface_charge_ptr; -int max_row_count, max_column_count; -int carbon; -char **col_name, **row_name; -int count_rows, count_optimize; -int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; -int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; -LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; -LDBLE *min_delta, *max_delta; -int *iu, *is; -int klmd, nklmd, n2d, kode, iter; -LDBLE toler, error, max_pct, scaled_error; -struct master *master_alk; -int *row_back, *col_back; -unsigned long *good, *bad, *minimal; -int max_good, max_bad, max_minimal; -int count_good, count_bad, count_minimal, count_calls; -unsigned long soln_bits, phase_bits, current_bits, temp_bits; + /* integrate.cpp ------------------------------- */ + LDBLE midpoint_sv; + LDBLE z, xd, alpha; + struct surface_charge *surface_charge_ptr; + int max_row_count, max_column_count; + int carbon; + char **col_name, **row_name; + int count_rows, count_optimize; + int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; + int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; + LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; + LDBLE *min_delta, *max_delta; + int *iu, *is; + int klmd, nklmd, n2d, kode, iter; + LDBLE toler, error, max_pct, scaled_error; + struct master *master_alk; + int *row_back, *col_back; + unsigned long *good, *bad, *minimal; + int max_good, max_bad, max_minimal; + int count_good, count_bad, count_minimal, count_calls; + unsigned long soln_bits, phase_bits, current_bits, temp_bits; -/* inverse.cpp ------------------------------- */ -FILE *netpath_file; -int count_inverse_models, count_pat_solutions; -int min_position[32], max_position[32], now[32]; + /* inverse.cpp ------------------------------- */ + FILE *netpath_file; + int count_inverse_models, count_pat_solutions; + int min_position[32], max_position[32], now[32]; -/* kinetics.cpp ------------------------------- */ + /* kinetics.cpp ------------------------------- */ public: -void *cvode_kinetics_ptr; -int cvode_test; -int cvode_error; -int cvode_n_user; -int cvode_n_reactions; -realtype cvode_step_fraction; -realtype cvode_rate_sim_time; -realtype cvode_rate_sim_time_start; -realtype cvode_last_good_time; -realtype cvode_prev_good_time; -N_Vector cvode_last_good_y; -N_Vector cvode_prev_good_y; -M_Env kinetics_machEnv; -N_Vector kinetics_y, kinetics_abstol; -void *kinetics_cvode_mem; -struct pp_assemblage *cvode_pp_assemblage_save; -struct s_s_assemblage *cvode_s_s_assemblage_save; -LDBLE *m_original; -LDBLE *m_temp; -int set_and_run_attempt; + void *cvode_kinetics_ptr; + int cvode_test; + int cvode_error; + int cvode_n_user; + int cvode_n_reactions; + realtype cvode_step_fraction; + realtype cvode_rate_sim_time; + realtype cvode_rate_sim_time_start; + realtype cvode_last_good_time; + realtype cvode_prev_good_time; + N_Vector cvode_last_good_y; + N_Vector cvode_prev_good_y; + M_Env kinetics_machEnv; + N_Vector kinetics_y, kinetics_abstol; + void *kinetics_cvode_mem; + struct pp_assemblage *cvode_pp_assemblage_save; + struct s_s_assemblage *cvode_s_s_assemblage_save; + LDBLE *m_original; + LDBLE *m_temp; + int set_and_run_attempt; -/* model.cpp ------------------------------- */ -LDBLE min_value; -/* LDBLE model_min_value; */ -LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; -int *inv_iu, *inv_is, *back_eq; -int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; + /* model.cpp ------------------------------- */ + LDBLE min_value; + /* LDBLE model_min_value; */ + LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; + int *inv_iu, *inv_is, *back_eq; + int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; -/* phrq_io_output.cpp ------------------------------- */ -int forward_output_to_log; + /* phrq_io_output.cpp ------------------------------- */ + int forward_output_to_log; -/* phreeqc_files.cpp ------------------------------- */ -char *default_data_base; + /* phreeqc_files.cpp ------------------------------- */ + char *default_data_base; #ifdef PHREEQ98 -int outputlinenr; -char *LogFileNameC; -char progress_str[512]; + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; #endif -/* Pitzer */ -int pitzer_model, sit_model, pitzer_pe; -int full_pitzer, always_full_pitzer, ICON, IC; -LDBLE COSMOT; -LDBLE AW; -LDBLE VP, DW0; -struct pitz_param **pitz_params; -int count_pitz_param, max_pitz_param; -struct pitz_param **sit_params; -int count_sit_param, max_sit_param; -int DW(LDBLE T); -LDBLE DC(LDBLE T); -struct theta_param **theta_params; -int count_theta_param, max_theta_param; -int use_etheta; -LDBLE OTEMP; -LDBLE A0; -struct species **spec, **cations, **anions, **neutrals; -int count_cations, count_anions, count_neutrals; -int MAXCATIONS, FIRSTANION, MAXNEUTRAL; -struct pitz_param *mcb0, *mcb1, *mcc0; -int *IPRSNT; -LDBLE *M, *LGAMMA; -LDBLE BK[23], DK[23]; + /* Pitzer */ + int pitzer_model, sit_model, pitzer_pe; + int full_pitzer, always_full_pitzer, ICON, IC; + LDBLE COSMOT; + LDBLE AW; + LDBLE VP, DW0; + struct pitz_param **pitz_params; + int count_pitz_param, max_pitz_param; + struct pitz_param **sit_params; + int count_sit_param, max_sit_param; + int DW(LDBLE T); + LDBLE DC(LDBLE T); + struct theta_param **theta_params; + int count_theta_param, max_theta_param; + int use_etheta; + LDBLE OTEMP; + LDBLE A0; + struct species **spec, **cations, **anions, **neutrals; + int count_cations, count_anions, count_neutrals; + int MAXCATIONS, FIRSTANION, MAXNEUTRAL; + struct pitz_param *mcb0, *mcb1, *mcc0; + int *IPRSNT; + LDBLE *M, *LGAMMA; + LDBLE BK[23], DK[23]; #ifdef PHREEQ98 -int connect_simulations, graph_initial_solutions; -int shifts_as_points; -int chart_type; -int ShowChart; -int RowOffset, ColumnOffset; + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; #endif -LDBLE dummy; + LDBLE dummy; -/* print.cpp ------------------------------- */ + /* print.cpp ------------------------------- */ #ifdef PHREEQ98 -int colnr, rownr; -int graph_initial_solutions; -int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ -/* int shifts_as_points; */ -int chart_type; -int AddSeries; -int FirstCallToUSER_GRAPH; + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; #endif -/* read.cpp */ -char *prev_next_char; + /* read.cpp */ + char *prev_next_char; #if defined PHREEQ98 -int shifts_as_points; + int shifts_as_points; #endif -/* read_class.cxx */ -dumper dump_info; -StorageBinList delete_info; -runner run_info; -char * sformatf_buffer; -size_t sformatf_buffer_size; + /* read_class.cxx */ + dumper dump_info; + StorageBinList delete_info; + runner run_info; + char * sformatf_buffer; + size_t sformatf_buffer_size; -/* readtr.cpp */ -std::string dump_file_name_cpp; + /* readtr.cpp */ + std::string dump_file_name_cpp; -/* sit.cpp ------------------------------- */ -LDBLE sit_A0; -int sit_count_cations, sit_count_anions, sit_count_neutrals; -int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; -int *sit_IPRSNT; -LDBLE *sit_M, *sit_LGAMMA; + /* sit.cpp ------------------------------- */ + LDBLE sit_A0; + int sit_count_cations, sit_count_anions, sit_count_neutrals; + int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; + int *sit_IPRSNT; + LDBLE *sit_M, *sit_LGAMMA; -/* tidy.cpp ------------------------------- */ -LDBLE a0, a1, kc, kb; + /* tidy.cpp ------------------------------- */ + LDBLE a0, a1, kc, kb; -/* tally.cpp ------------------------------- */ -struct tally_buffer *t_buffer; -int tally_count_component; -struct tally *tally_table; -int count_tally_table_columns; -int count_tally_table_rows; + /* tally.cpp ------------------------------- */ + struct tally_buffer *t_buffer; + int tally_count_component; + struct tally *tally_table; + int count_tally_table_columns; + int count_tally_table_rows; -/* transport.cpp ------------------------------- */ -struct sol_D *sol_D; -struct sol_D *sol_D_dbg; -struct J_ij *J_ij, *J_ij_il; -int J_ij_count_spec; + /* transport.cpp ------------------------------- */ + struct sol_D *sol_D; + struct sol_D *sol_D_dbg; + struct J_ij *J_ij, *J_ij_il; + int J_ij_count_spec; -struct M_S *m_s; -int count_m_s; -LDBLE tot1_h, tot1_o, tot2_h, tot2_o; -LDBLE diffc_max, diffc_tr, J_ij_sum; -int transp_surf; -LDBLE *heat_mix_array; -LDBLE *temp1, *temp2; -int nmix, heat_nmix; -LDBLE heat_mix_f_imm, heat_mix_f_m; -int warn_MCD_X, warn_fixed_Surf; + struct M_S *m_s; + int count_m_s; + LDBLE tot1_h, tot1_o, tot2_h, tot2_o; + LDBLE diffc_max, diffc_tr, J_ij_sum; + int transp_surf; + LDBLE *heat_mix_array; + LDBLE *temp1, *temp2; + int nmix, heat_nmix; + LDBLE heat_mix_f_imm, heat_mix_f_m; + int warn_MCD_X, warn_fixed_Surf; #ifdef PHREEQ98 -int AutoLoadOutputFile, CreateToC; -int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; -int outputlinenr; -int stop_calculations; -char err_str98[80]; + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; #endif -friend class PBasic; -friend class ChartObject; + friend class PBasic; + friend class ChartObject; #endif /* _INC_PHREEQC_H */ -/********************************* - isfinite handling - (Note: Should NOT be guarded) -**********************************/ + /********************************* + isfinite handling + (Note: Should NOT be guarded) + **********************************/ #if defined (PHREEQ98) || defined (_MSC_VER) # define HAVE_FINITE From eb2fab2efb95a2874541dd1c405b5b795b350138 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Nov 2011 18:55:47 +0000 Subject: [PATCH 0326/1077] Indented last try/catch. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5777 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 416 ++++++++++++++++++++++++++--------------------------- 1 file changed, 208 insertions(+), 208 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index eb7b9566..d1224d33 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -4840,276 +4840,276 @@ exec(void) //TRY(try1); try - { - do { do { - V.gotoflag = false; - V.elseflag = false; - while (stmttok != NULL && stmttok->kind == tokcolon) - stmttok = stmttok->next; - V.t = stmttok; - if (V.t != NULL) + do { - V.t = V.t->next; - switch (stmttok->kind) + V.gotoflag = false; + V.elseflag = false; + while (stmttok != NULL && stmttok->kind == tokcolon) + stmttok = stmttok->next; + V.t = stmttok; + if (V.t != NULL) { + V.t = V.t->next; + switch (stmttok->kind) + { - case tokrem: - /* blank case */ - break; + case tokrem: + /* blank case */ + break; - case toklist: - cmdlist(&V); - break; + case toklist: + cmdlist(&V); + break; - case tokrun: - cmdrun(&V); - break; + case tokrun: + cmdrun(&V); + break; - case toknew: - cmdnew(&V); - break; + case toknew: + cmdnew(&V); + break; - case tokload: - cmdload(false, stringexpr(STR1, &V), &V); - break; + case tokload: + cmdload(false, stringexpr(STR1, &V), &V); + break; - case tokmerge: - cmdload(true, stringexpr(STR1, &V), &V); - break; + case tokmerge: + cmdload(true, stringexpr(STR1, &V), &V); + break; - case toksave: - cmdsave(&V); - break; + case toksave: + cmdsave(&V); + break; - case tokbye: - cmdbye(); - break; + case tokbye: + cmdbye(); + break; - case tokdel: - cmddel(&V); - break; + case tokdel: + cmddel(&V); + break; - case tokrenum: - cmdrenum(&V); - break; + case tokrenum: + cmdrenum(&V); + break; - case toklet: - cmdlet(false, &V); - break; + case toklet: + cmdlet(false, &V); + break; - case tokvar: - cmdlet(true, &V); - break; + case tokvar: + cmdlet(true, &V); + break; - case tokprint: - cmdprint(&V); - break; + case tokprint: + cmdprint(&V); + break; - case tokpunch: - cmdpunch(&V); - break; + case tokpunch: + cmdpunch(&V); + break; - case tokput: - cmdput(&V); - break; + case tokput: + cmdput(&V); + break; - case tokchange_por: - cmdchange_por(&V); - break; + case tokchange_por: + cmdchange_por(&V); + break; - case tokchange_surf: - cmdchange_surf(&V); - break; + case tokchange_surf: + cmdchange_surf(&V); + break; #if defined PHREEQ98 || defined MULTICHART - case tokgraph_x: - cmdgraph_x(&V); - break; + case tokgraph_x: + cmdgraph_x(&V); + break; - case tokgraph_y: - cmdgraph_y(&V); - break; + case tokgraph_y: + cmdgraph_y(&V); + break; - case tokgraph_sy: - cmdgraph_sy(&V); - break; + case tokgraph_sy: + cmdgraph_sy(&V); + break; #endif #if defined MULTICHART - case tokplot_xy: - cmdplot_xy(&V); - break; + case tokplot_xy: + cmdplot_xy(&V); + break; #endif - case tokinput: - error_msg - ("Basic command INPUT is not a legal command in PHREEQC.", - STOP); - break; + case tokinput: + error_msg + ("Basic command INPUT is not a legal command in PHREEQC.", + STOP); + break; - case tokgoto: - cmdgoto(&V); - break; + case tokgoto: + cmdgoto(&V); + break; - case tokif: - cmdif(&V); - break; + case tokif: + cmdif(&V); + break; - case tokelse: - cmdelse(&V); - break; + case tokelse: + cmdelse(&V); + break; - case tokend: - cmdend(&V); - break; + case tokend: + cmdend(&V); + break; - case tokstop: - P_escapecode = -20; - throw PBasicStop(); - //goto _Ltry1; - break; + case tokstop: + P_escapecode = -20; + throw PBasicStop(); + //goto _Ltry1; + break; - case tokfor: - cmdfor(&V); - break; + case tokfor: + cmdfor(&V); + break; - case toknext: - cmdnext(&V); - break; + case toknext: + cmdnext(&V); + break; - case tokwhile: - cmdwhile(&V); - break; + case tokwhile: + cmdwhile(&V); + break; - case tokwend: - cmdwend(&V); - break; + case tokwend: + cmdwend(&V); + break; - case tokgosub: - cmdgosub(&V); - break; + case tokgosub: + cmdgosub(&V); + break; - case tokreturn: - cmdreturn(&V); - break; + case tokreturn: + cmdreturn(&V); + break; - case tokread: - cmdread(&V); - break; + case tokread: + cmdread(&V); + break; - case tokdata: - cmddata(&V); - break; + case tokdata: + cmddata(&V); + break; - case tokrestore: - cmdrestore(&V); - break; + case tokrestore: + cmdrestore(&V); + break; - case tokgotoxy: - cmdgotoxy(&V); - break; + case tokgotoxy: + cmdgotoxy(&V); + break; - case tokon: - cmdon(&V); - break; + case tokon: + cmdon(&V); + break; - case tokdim: - cmddim(&V); - break; + case tokdim: + cmddim(&V); + break; - case tokpoke: - cmdpoke(&V); - break; + case tokpoke: + cmdpoke(&V); + break; - default: - errormsg("Illegal command"); - break; + default: + errormsg("Illegal command"); + break; + } } + if (!V.elseflag && !iseos(&V)) + checkextra(&V); + stmttok = V.t; } - if (!V.elseflag && !iseos(&V)) - checkextra(&V); - stmttok = V.t; - } - while (V.t != NULL); - if (stmtline != NULL) - { - if (!V.gotoflag) - stmtline = stmtline->next; + while (V.t != NULL); if (stmtline != NULL) - stmttok = stmtline->txt; + { + if (!V.gotoflag) + stmtline = stmtline->next; + if (stmtline != NULL) + stmttok = stmtline->txt; + } } - } - while (stmtline != NULL); - //RECOVER2(try1, _Ltry1); + while (stmtline != NULL); + //RECOVER2(try1, _Ltry1); } catch (PBasicStop e) { //_Ltry1: - if (P_escapecode == -20) - warning_msg("Break"); - /* printf("Break"); */ - else if (P_escapecode != 42) - { - switch (P_escapecode) + if (P_escapecode == -20) + warning_msg("Break"); + /* printf("Break"); */ + else if (P_escapecode != 42) { - - case -4: - sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -5: - sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -6: - sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -7: - sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -8: - case -19: - case -18: - case -17: - case -16: - case -15: - sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); - break; - - case -10: - ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); - if (ioerrmsg == NULL) - PhreeqcPtr->malloc_error(); - sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); - warning_msg(ioerrmsg); - PhreeqcPtr->PHRQ_free(ioerrmsg); - break; - - default: - if (EXCP_LINE != -1) + switch (P_escapecode) { - sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); + + case -4: + sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); warning_msg(PhreeqcPtr->error_string); + break; + + case -5: + sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -6: + sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -7: + sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -8: + case -19: + case -18: + case -17: + case -16: + case -15: + sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + break; + + case -10: + ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + if (ioerrmsg == NULL) + PhreeqcPtr->malloc_error(); + sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); + warning_msg(ioerrmsg); + PhreeqcPtr->PHRQ_free(ioerrmsg); + break; + + default: + if (EXCP_LINE != -1) + { + sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); + warning_msg(PhreeqcPtr->error_string); + } + _Escape(P_escapecode); + break; } - _Escape(P_escapecode); - break; } - } - if (stmtline != NULL) - { - sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - error_msg(PhreeqcPtr->error_string, CONTINUE); - } - //ENDTRY(try1); + if (stmtline != NULL) + { + sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + error_msg(PhreeqcPtr->error_string, CONTINUE); + } + //ENDTRY(try1); } // end catch } /*exec */ From 46b50f49f1da79033fe62f1be2721d707526dcae Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Nov 2011 20:38:47 +0000 Subject: [PATCH 0327/1077] Made NameDouble use LDBLE git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5778 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 38 +++++++++++++++++++------------------- NameDouble.h | 25 +++++++++++++------------ 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 2cde532d..788ed6e7 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -59,7 +59,7 @@ cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count) this->type = ND_ELT_MOLES; } -cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, double factor) +cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, LDBLE factor) // // constructor for cxxNameDouble from list of elt_list // @@ -220,7 +220,7 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, std::string token; //char * // ctoken; - double + LDBLE d; CParser::TOKEN_TYPE j; @@ -241,7 +241,7 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, } void -cxxNameDouble::add_extensive(const cxxNameDouble & addee, double factor) +cxxNameDouble::add_extensive(const cxxNameDouble & addee, LDBLE factor) // // Sums two name doubles, this + factor*nd2 // @@ -264,8 +264,8 @@ cxxNameDouble::add_extensive(const cxxNameDouble & addee, double factor) } } void -cxxNameDouble::add_intensive(const cxxNameDouble & addee, double f1, - double f2) +cxxNameDouble::add_intensive(const cxxNameDouble & addee, LDBLE f1, + LDBLE f2) // // Sums two name doubles, this*f1 + f2*nd2 // @@ -286,8 +286,8 @@ cxxNameDouble::add_intensive(const cxxNameDouble & addee, double f1, } } void -cxxNameDouble::add_log_activities(const cxxNameDouble & addee, double f1, - double f2) +cxxNameDouble::add_log_activities(const cxxNameDouble & addee, LDBLE f1, + LDBLE f2) // // Sums two name doubles, this*f1 + f2*nd2, assuming log values // @@ -299,13 +299,13 @@ cxxNameDouble::add_log_activities(const cxxNameDouble & addee, double f1, cxxNameDouble::iterator current = (*this).find(it->first); if (current != (*this).end()) { - double a1 = pow(10., current->second); - double a2 = pow(10., it->second); + LDBLE a1 = pow((LDBLE) 10., current->second); + LDBLE a2 = pow((LDBLE) 10., it->second); (*this)[it->first] = log10(f1 * a1 + f2 * a2); } else { - //double a2 = pow(10. it->second); + //LDBLE a2 = pow(10. it->second); //(*this)[it->first] = log10(f2 * a2); (*this)[it->first] = it->second + log10(f2); } @@ -313,7 +313,7 @@ cxxNameDouble::add_log_activities(const cxxNameDouble & addee, double f1, } void -cxxNameDouble::add(const char *token, double total) +cxxNameDouble::add(const char *token, LDBLE total) // // add to total for a specified element // @@ -332,7 +332,7 @@ cxxNameDouble::add(const char *token, double total) } } void -cxxNameDouble::multiply(double extensive) +cxxNameDouble::multiply(LDBLE extensive) { // // Multiplies by extensive @@ -408,15 +408,15 @@ cxxNameDouble::merge_redox(const cxxNameDouble & source) } } struct DblCmp { - bool operator()(const std::pair &lhs, const std::pair &rhs) + bool operator()(const std::pair &lhs, const std::pair &rhs) { return lhs.second > rhs.second; } }; -std::vector< std::pair > +std::vector< std::pair > cxxNameDouble::sort_second(void) { - std::vector< std::pair > myvec(this->begin(), this->end()); + std::vector< std::pair > myvec(this->begin(), this->end()); std::sort(myvec.begin(), myvec.end(), DblCmp()); return myvec; @@ -424,7 +424,7 @@ cxxNameDouble::sort_second(void) #ifdef USE_MPI void cxxNameDouble::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; ints.push_back((int) (*this).size()); @@ -436,7 +436,7 @@ cxxNameDouble::mpi_pack(std::vector < int >&ints, } } void -cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) +cxxNameDouble::mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd) { int i = *ii; int d = *dd; @@ -462,7 +462,7 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) } //void -//cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +//cxxNameDouble::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) //{ // int i = *ii; // int d = *dd; @@ -484,7 +484,7 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd) // *dd = d; //} void -cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxNameDouble::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { int i = *ii; int d = *dd; diff --git a/NameDouble.h b/NameDouble.h index b1109481..096ff82e 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -8,9 +8,10 @@ #include // std::vector class Phreeqc; #include "Parser.h" +#include "phrqtype.h" class cxxNameDouble:public - std::map < std::string, double > + std::map < std::string, LDBLE > { public: @@ -28,7 +29,7 @@ class cxxNameDouble:public cxxNameDouble(struct conc *); cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); cxxNameDouble(struct name_coef *nc, int count); - cxxNameDouble(const cxxNameDouble & old, double factor); + cxxNameDouble(const cxxNameDouble & old, LDBLE factor); ~ cxxNameDouble(); @@ -39,33 +40,33 @@ class cxxNameDouble:public CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type & pos); void - add_extensive(const cxxNameDouble & old, double factor); + add_extensive(const cxxNameDouble & old, LDBLE factor); void - add_intensive(const cxxNameDouble & addee, double fthis, double f2); + add_intensive(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); void - add_log_activities(const cxxNameDouble & addee, double fthis, double f2); + add_log_activities(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); void - add(const char *key, double total); + add(const char *key, LDBLE total); void - multiply(double factor); + multiply(LDBLE factor); void merge_redox(const cxxNameDouble & source); - std::vector< std::pair > + std::vector< std::pair > sort_second(void); void - insert(const char *str, double d) + insert(const char *str, LDBLE d) { (*this)[str] = d; } void - mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void - mpi_pack(int *ints, int *ii, double *doubles, int *dd); + mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd); void - mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); enum ND_TYPE type; From 9d1dc096a03e0d567d6cc55ecbbc5a114edd313b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 16 Nov 2011 15:58:42 +0000 Subject: [PATCH 0328/1077] Made PBasic commands static, initialized only once. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5783 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 325 +++++++++++++++++++++++++++-------------------------- PBasic.h | 2 +- 2 files changed, 166 insertions(+), 161 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index d1224d33..abf4ce05 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -47,166 +47,7 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) P_escapecode = 0; P_ioresult = 0; - // initialize Basic commands - commands["+"] = tokplus; - commands["-"] = tokminus; - commands["*"] = toktimes; - commands["/"] = tokdiv; - commands["^"] = tokup; - commands["( or ["] = toklp; - commands[") or ]"] = tokrp; - commands["]"] = tokcomma; - commands[";"] = toksemi; - commands[":"] = tokcolon; - commands["="] = tokeq; - commands["<"] = toklt; - commands["<="] = tokle; - commands[">"] = tokgt; - commands[">="] = tokge; - commands["and"] = tokand; - commands["or"] = tokor; - commands["xor"] = tokxor; - commands["not"] = toknot; - commands["mod"] = tokmod; - commands["sqr"] = toksqr; - commands["sqrt"] = toksqrt; - commands["ceil"] = tokceil; - commands["floor"] = tokfloor; - commands["sin"] = toksin; - commands["cos"] = tokcos; - commands["tan"] = toktan; - commands["arctan"] = tokarctan; - commands["log"] = toklog; - commands["exp"] = tokexp; - commands["abs"] = tokabs; - commands["sgn"] = toksgn; - commands["str$"] = tokstr_; - commands["val"] = tokval; - commands["chr$"] = tokchr_; - commands["eol$"] = tokeol_; - commands["asc"] = tokasc; - commands["len"] = toklen; - commands["mid$"] = tokmid_; - commands["peek"] = tokpeek; - commands["let"] = toklet; - commands["print"] = tokprint; - commands["punch"] = tokpunch; -#if defined (PHREEQ98) || defined (MULTICHART) - commands["graph_x"] = tokgraph_x; - commands["graph_y"] = tokgraph_y; - commands["graph_sy"] = tokgraph_sy; -#endif -#if defined MULTICHART - commands["plot_xy"] = tokplot_xy; -#endif - commands["input"] = tokinput; - commands["goto"] = tokgoto; - commands["go to"] = tokgoto; - commands["if"] = tokif; - commands["end"] = tokend; - commands["stop"] = tokstop; - commands["for"] = tokfor; - commands["next"] = toknext; - commands["while"] = tokwhile; - commands["wend"] = tokwend; - commands["gosub"] = tokgosub; - commands["return"] = tokreturn; - commands["read"] = tokread; - commands["data"] = tokdata; - commands["restore"] = tokrestore; - commands["gotoxy"] = tokgotoxy; - commands["on"] = tokon; - commands["dim"] = tokdim; - commands["poke"] = tokpoke; - commands["list"] = toklist; - commands["run"] = tokrun; - commands["new"] = toknew; - commands["load"] = tokload; - commands["merge"] = tokmerge; - commands["save"] = toksave; - commands["bye"] = tokbye; - commands["quit"] = tokbye; - commands["del"] = tokdel; - commands["renum"] = tokrenum; - commands["then"] = tokthen; - commands["else"] = tokelse; - commands["to"] = tokto; - commands["step"] = tokstep; - commands["tc"] = toktc; - commands["tk"] = toktk; - commands["time"] = toktime; - commands["sim_time"] = toksim_time; - commands["total_time"] = toktotal_time; - commands["m0"] = tokm0; - commands["m"] = tokm; - commands["parm"] = tokparm; - commands["act"] = tokact; - commands["edl"] = tokedl; - commands["surf"] = toksurf; - commands["equi"] = tokequi; - commands["kin"] = tokkin; - commands["gas"] = tokgas; - commands["s_s"] = toks_s; - commands["misc1"] = tokmisc1; - commands["misc2"] = tokmisc2; - commands["mu"] = tokmu; - commands["osmotic"] = tokosmotic; - commands["alk"] = tokalk; - commands["lk_species"] = toklk_species; - commands["lk_named"] = toklk_named; - commands["lk_phase"] = toklk_phase; - commands["sum_species"] = toksum_species; - commands["sum_gas"] = toksum_gas; - commands["sum_s_s"] = toksum_s_s; - commands["calc_value"] = tokcalc_value; - commands["description"] = tokdescription; - commands["sys"] = toksys; - commands["instr"] = tokinstr; - commands["ltrim"] = tokltrim; - commands["rtrim"] = tokrtrim; - commands["trim"] = toktrim; - commands["pad"] = tokpad; - commands["rxn"] = tokrxn; - commands["dist"] = tokdist; - commands["mol"] = tokmol; - commands["la"] = tokla; - commands["lm"] = toklm; - commands["sr"] = toksr; - commands["si"] = toksi; - commands["step_no"] = tokstep_no; - commands["cell_no"] = tokcell_no; - commands["sim_no"] = toksim_no; - commands["tot"] = toktot; - commands["log10"] = toklog10; - commands["charge_balance"] = tokcharge_balance; - commands["percent_error"] = tokpercent_error; - commands["put"] = tokput; - commands["get"] = tokget; - commands["exists"] = tokexists; - commands["rem"] = tokrem; - commands["change_por"] = tokchange_por; - commands["get_por"] = tokget_por; - commands["change_surf"] = tokchange_surf; - commands["porevolume"] = tokporevolume; - commands["sc"] = toksc; - commands["gamma"] = tokgamma; - commands["lg"] = toklg; - commands["rho"] = tokrho; - commands["cell_volume"] = tokcell_volume; - commands["cell_pore_volume"] = tokcell_pore_volume; - commands["cell_porosity"] = tokcell_porosity; - commands["cell_saturation"] = tokcell_saturation; - commands["totmole"] = toktotmole; - commands["totmol"] = toktotmol; - commands["totmoles"] = toktotmoles; - commands["iso"] = tokiso; - commands["iso_unit"] = tokiso_unit; - commands["phase_formula"] = tokphase_formula; - commands["list_s_s"] = toklist_s_s; - commands["pr_p"] = tokpr_p; - commands["pr_phi"] = tokpr_phi; - commands["gas_p"] = tokgas_p; - commands["gas_vm"] = tokgas_vm; + // Basic commands initialized at bottom of file } PBasic::~PBasic(void) { @@ -6136,5 +5977,169 @@ _EscIO(int code) P_ioresult = code; return _Escape(-10); } + +const std::map::value_type temp_tokens[] = { + std::map::value_type("+", PBasic::tokplus), + std::map::value_type("-", PBasic::tokminus), + std::map::value_type("*", PBasic::toktimes), + std::map::value_type("/", PBasic::tokdiv), + std::map::value_type("^", PBasic::tokup), + std::map::value_type("( or [", PBasic::toklp), + std::map::value_type(") or ]", PBasic::tokrp), + std::map::value_type("]", PBasic::tokcomma), + std::map::value_type(";", PBasic::toksemi), + std::map::value_type(":", PBasic::tokcolon), + std::map::value_type("=", PBasic::tokeq), + std::map::value_type("<", PBasic::toklt), + std::map::value_type("<=", PBasic::tokle), + std::map::value_type(">", PBasic::tokgt), + std::map::value_type(">=", PBasic::tokge), + std::map::value_type("and", PBasic::tokand), + std::map::value_type("or", PBasic::tokor), + std::map::value_type("xor", PBasic::tokxor), + std::map::value_type("not", PBasic::toknot), + std::map::value_type("mod", PBasic::tokmod), + std::map::value_type("sqr", PBasic::toksqr), + std::map::value_type("sqrt", PBasic::toksqrt), + std::map::value_type("ceil", PBasic::tokceil), + std::map::value_type("floor", PBasic::tokfloor), + std::map::value_type("sin", PBasic::toksin), + std::map::value_type("cos", PBasic::tokcos), + std::map::value_type("tan", PBasic::toktan), + std::map::value_type("arctan", PBasic::tokarctan), + std::map::value_type("log", PBasic::toklog), + std::map::value_type("exp", PBasic::tokexp), + std::map::value_type("abs", PBasic::tokabs), + std::map::value_type("sgn", PBasic::toksgn), + std::map::value_type("str$", PBasic::tokstr_), + std::map::value_type("val", PBasic::tokval), + std::map::value_type("chr$", PBasic::tokchr_), + std::map::value_type("eol$", PBasic::tokeol_), + std::map::value_type("asc", PBasic::tokasc), + std::map::value_type("len", PBasic::toklen), + std::map::value_type("mid$", PBasic::tokmid_), + std::map::value_type("peek", PBasic::tokpeek), + std::map::value_type("let", PBasic::toklet), + std::map::value_type("print", PBasic::tokprint), + std::map::value_type("punch", PBasic::tokpunch), +#if defined (PHREEQ98) || defined (MULTICHART) + std::map::value_type("graph_x", PBasic::tokgraph_x), + std::map::value_type("graph_y", PBasic::tokgraph_y), + std::map::value_type("graph_sy", PBasic::tokgraph_sy), +#endif +#if defined MULTICHART + std::map::value_type("plot_xy", PBasic::tokplot_xy), +#endif + std::map::value_type("input", PBasic::tokinput), + std::map::value_type("goto", PBasic::tokgoto), + std::map::value_type("go to", PBasic::tokgoto), + std::map::value_type("if", PBasic::tokif), + std::map::value_type("end", PBasic::tokend), + std::map::value_type("stop", PBasic::tokstop), + std::map::value_type("for", PBasic::tokfor), + std::map::value_type("next", PBasic::toknext), + std::map::value_type("while", PBasic::tokwhile), + std::map::value_type("wend", PBasic::tokwend), + std::map::value_type("gosub", PBasic::tokgosub), + std::map::value_type("return", PBasic::tokreturn), + std::map::value_type("read", PBasic::tokread), + std::map::value_type("data", PBasic::tokdata), + std::map::value_type("restore", PBasic::tokrestore), + std::map::value_type("gotoxy", PBasic::tokgotoxy), + std::map::value_type("on", PBasic::tokon), + std::map::value_type("dim", PBasic::tokdim), + std::map::value_type("poke", PBasic::tokpoke), + std::map::value_type("list", PBasic::toklist), + std::map::value_type("run", PBasic::tokrun), + std::map::value_type("new", PBasic::toknew), + std::map::value_type("load", PBasic::tokload), + std::map::value_type("merge", PBasic::tokmerge), + std::map::value_type("save", PBasic::toksave), + std::map::value_type("bye", PBasic::tokbye), + std::map::value_type("quit", PBasic::tokbye), + std::map::value_type("del", PBasic::tokdel), + std::map::value_type("renum", PBasic::tokrenum), + std::map::value_type("then", PBasic::tokthen), + std::map::value_type("else", PBasic::tokelse), + std::map::value_type("to", PBasic::tokto), + std::map::value_type("step", PBasic::tokstep), + std::map::value_type("tc", PBasic::toktc), + std::map::value_type("tk", PBasic::toktk), + std::map::value_type("time", PBasic::toktime), + std::map::value_type("sim_time", PBasic::toksim_time), + std::map::value_type("total_time", PBasic::toktotal_time), + std::map::value_type("m0", PBasic::tokm0), + std::map::value_type("m", PBasic::tokm), + std::map::value_type("parm", PBasic::tokparm), + std::map::value_type("act", PBasic::tokact), + std::map::value_type("edl", PBasic::tokedl), + std::map::value_type("surf", PBasic::toksurf), + std::map::value_type("equi", PBasic::tokequi), + std::map::value_type("kin", PBasic::tokkin), + std::map::value_type("gas", PBasic::tokgas), + std::map::value_type("s_s", PBasic::toks_s), + std::map::value_type("misc1", PBasic::tokmisc1), + std::map::value_type("misc2", PBasic::tokmisc2), + std::map::value_type("mu", PBasic::tokmu), + std::map::value_type("osmotic", PBasic::tokosmotic), + std::map::value_type("alk", PBasic::tokalk), + std::map::value_type("lk_species", PBasic::toklk_species), + std::map::value_type("lk_named", PBasic::toklk_named), + std::map::value_type("lk_phase", PBasic::toklk_phase), + std::map::value_type("sum_species", PBasic::toksum_species), + std::map::value_type("sum_gas", PBasic::toksum_gas), + std::map::value_type("sum_s_s", PBasic::toksum_s_s), + std::map::value_type("calc_value", PBasic::tokcalc_value), + std::map::value_type("description", PBasic::tokdescription), + std::map::value_type("sys", PBasic::toksys), + std::map::value_type("instr", PBasic::tokinstr), + std::map::value_type("ltrim", PBasic::tokltrim), + std::map::value_type("rtrim", PBasic::tokrtrim), + std::map::value_type("trim", PBasic::toktrim), + std::map::value_type("pad", PBasic::tokpad), + std::map::value_type("rxn", PBasic::tokrxn), + std::map::value_type("dist", PBasic::tokdist), + std::map::value_type("mol", PBasic::tokmol), + std::map::value_type("la", PBasic::tokla), + std::map::value_type("lm", PBasic::toklm), + std::map::value_type("sr", PBasic::toksr), + std::map::value_type("si", PBasic::toksi), + std::map::value_type("step_no", PBasic::tokstep_no), + std::map::value_type("cell_no", PBasic::tokcell_no), + std::map::value_type("sim_no", PBasic::toksim_no), + std::map::value_type("tot", PBasic::toktot), + std::map::value_type("log10", PBasic::toklog10), + std::map::value_type("charge_balance", PBasic::tokcharge_balance), + std::map::value_type("percent_error", PBasic::tokpercent_error), + std::map::value_type("put", PBasic::tokput), + std::map::value_type("get", PBasic::tokget), + std::map::value_type("exists", PBasic::tokexists), + std::map::value_type("rem", PBasic::tokrem), + std::map::value_type("change_por", PBasic::tokchange_por), + std::map::value_type("get_por", PBasic::tokget_por), + std::map::value_type("change_surf", PBasic::tokchange_surf), + std::map::value_type("porevolume", PBasic::tokporevolume), + std::map::value_type("sc", PBasic::toksc), + std::map::value_type("gamma", PBasic::tokgamma), + std::map::value_type("lg", PBasic::toklg), + std::map::value_type("rho", PBasic::tokrho), + std::map::value_type("cell_volume", PBasic::tokcell_volume), + std::map::value_type("cell_pore_volume", PBasic::tokcell_pore_volume), + std::map::value_type("cell_porosity", PBasic::tokcell_porosity), + std::map::value_type("cell_saturation", PBasic::tokcell_saturation), + std::map::value_type("totmole", PBasic::toktotmole), + std::map::value_type("totmol", PBasic::toktotmol), + std::map::value_type("totmoles", PBasic::toktotmoles), + std::map::value_type("iso", PBasic::tokiso), + std::map::value_type("iso_unit", PBasic::tokiso_unit), + std::map::value_type("phase_formula", PBasic::tokphase_formula), + std::map::value_type("list_s_s", PBasic::toklist_s_s), + std::map::value_type("pr_p", PBasic::tokpr_p), + std::map::value_type("pr_phi", PBasic::tokpr_phi), + std::map::value_type("gas_p", PBasic::tokgas_p), + std::map::value_type("gas_vm", PBasic::tokgas_vm), +}; +std::map PBasic::commands(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); + /* End. */ diff --git a/PBasic.h b/PBasic.h index b2a019da..c978fb85 100644 --- a/PBasic.h +++ b/PBasic.h @@ -438,7 +438,7 @@ protected: tokenrec *stmttok, *datatok, *buf; bool exitflag; long EXCP_LINE; - std::map commands; + static std::map commands; int P_escapecode; int P_ioresult; }; From 2a8089a8b1978a37e49a98fea1765fd839d6d6b3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 16 Nov 2011 18:20:58 +0000 Subject: [PATCH 0329/1077] Merging Basic1 from PhreeqcI into Basic. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5784 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 284 +++++++++++++++++++++++++++++++++++++---------------- PBasic.h | 8 ++ 2 files changed, 209 insertions(+), 83 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index abf4ce05..72ae7557 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -46,7 +46,7 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) EXCP_LINE = 0; P_escapecode = 0; P_ioresult = 0; - + pqi_parse = false; // Basic commands initialized at bottom of file } PBasic::~PBasic(void) @@ -2169,46 +2169,70 @@ factor(struct LOC_exec * LINK) case tokparm: i_rate = intfactor(LINK); - if (i_rate > PhreeqcPtr->count_rate_p || i_rate == 0) + if (pqi_parse) { - errormsg("Parameter subscript out of range."); + n.UU.val = 1; } - n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; + else + { + if (i_rate > PhreeqcPtr->count_rate_p || i_rate == 0) + { + errormsg("Parameter subscript out of range."); + } + n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; + } + break; case tokact: - n.UU.val = PhreeqcPtr->activity(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->activity(str); + } break; case tokgamma: - n.UU.val = PhreeqcPtr->activity_coefficient(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->activity_coefficient(str); + } break; case toklg: - n.UU.val = PhreeqcPtr->log_activity_coefficient(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_activity_coefficient(str); + } break; case tokget_por: i = intfactor(LINK); - if (PhreeqcPtr->phast != TRUE) + if (pqi_parse) { - if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 - || i == PhreeqcPtr->count_cells + 1) - { - /* warning_msg("Note... no porosity for boundary solutions."); */ - n.UU.val = 0; - break; - } - else - n.UU.val = PhreeqcPtr->cell_data[i - 1].por; - break; + n.UU.val = 1; } else { - n.UU.val = PhreeqcPtr->cell_porosity; - break; + if (PhreeqcPtr->phast != TRUE) + { + if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 + || i == PhreeqcPtr->count_cells + 1) + { + /* warning_msg("Note... no porosity for boundary solutions."); */ + n.UU.val = 0; + break; + } + else + n.UU.val = PhreeqcPtr->cell_data[i - 1].por; + break; + } + else + { + n.UU.val = PhreeqcPtr->cell_porosity; + break; + } } - + break; case tokedl: require(toklp, LINK); elt_name = stringfactor(STR1, LINK); @@ -2222,7 +2246,7 @@ factor(struct LOC_exec * LINK) surface_name = NULL; } require(tokrp, LINK); - n.UU.val = PhreeqcPtr->diff_layer_total(elt_name, surface_name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->diff_layer_total(elt_name, surface_name); break; case toksurf: @@ -2238,31 +2262,49 @@ factor(struct LOC_exec * LINK) surface_name = NULL; } require(tokrp, LINK); - n.UU.val = PhreeqcPtr->surf_total(elt_name, surface_name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->surf_total(elt_name, surface_name); break; case tokequi: - n.UU.val = PhreeqcPtr->equi_phase(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->equi_phase(str); + } break; case tokkin: - n.UU.val = PhreeqcPtr->kinetics_moles(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->kinetics_moles(str); + } break; case tokgas: - n.UU.val = PhreeqcPtr->find_gas_comp(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_comp(str); + } break; case toks_s: - n.UU.val = PhreeqcPtr->find_s_s_comp(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_s_s_comp(str); + } break; case tokmisc1: - n.UU.val = PhreeqcPtr->find_misc1(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_misc1(str); + } break; case tokmisc2: - n.UU.val = PhreeqcPtr->find_misc2(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_misc2(str); + } break; case tokmu: @@ -2281,19 +2323,28 @@ factor(struct LOC_exec * LINK) break; case tokalk: - n.UU.val = PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; break; case toklk_species: - n.UU.val = PhreeqcPtr->calc_logk_s(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_s(str); + } break; case toklk_named: - n.UU.val = PhreeqcPtr->calc_logk_n(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_n(str); + } break; case toklk_phase: - n.UU.val = PhreeqcPtr->calc_logk_p(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_p(str); + } break; case toksum_species: @@ -2309,7 +2360,7 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_species(mytemplate, elt_name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_species(mytemplate, elt_name); break; case toksum_gas: @@ -2325,7 +2376,7 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_gases(mytemplate, elt_name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_gases(mytemplate, elt_name); break; case toksum_s_s: @@ -2341,14 +2392,14 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); break; case tokcalc_value: require(toklp, LINK); name = stringfactor(STR1, LINK); require(tokrp, LINK); - n.UU.val = PhreeqcPtr->get_calculate_value(name); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->get_calculate_value(name); break; case tokdescription: @@ -2437,7 +2488,10 @@ factor(struct LOC_exec * LINK) break; case tokiso: - n.UU.val = PhreeqcPtr->iso_value(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->iso_value(str); + } break; case tokiso_unit: @@ -2446,7 +2500,7 @@ factor(struct LOC_exec * LINK) string1 = stringfactor(STR1, LINK); require(tokrp, LINK); PhreeqcPtr->string_trim(string1); - n.UU.sval = PhreeqcPtr->iso_unit(string1); + n.UU.sval = (pqi_parse) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); break; case tokpad: @@ -2517,9 +2571,31 @@ factor(struct LOC_exec * LINK) /* n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); */ - n.UU.val = - PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), - &(types_arg), &(moles_arg)); + if (pqi_parse) + { + PhreeqcPtr->sys_tot = 0; + PhreeqcPtr->count_sys = 1000; + int count_sys = PhreeqcPtr->count_sys; + names_arg = (char **) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); + if (names_arg == NULL) + PhreeqcPtr->malloc_error(); + types_arg = (char **)PhreeqcPtr-> PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); + if (types_arg == NULL) + PhreeqcPtr->malloc_error(); + moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); + if (moles_arg == NULL) + PhreeqcPtr->malloc_error(); + names_arg[0] = NULL; + types_arg[0] = NULL; + moles_arg[0] = 0; + count_species = (LDBLE) count_sys; + n.UU.val = 0; + } + else + { + n.UU.val = PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), + &(types_arg), &(moles_arg)); + } /* * fill in varrec structure @@ -2606,7 +2682,8 @@ factor(struct LOC_exec * LINK) * Call subroutine */ // return total moles - n.UU.val = PhreeqcPtr->list_s_s(s_s_name, composition); + + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->list_s_s(s_s_name, composition); /* * fill in varrec structure @@ -2644,14 +2721,6 @@ factor(struct LOC_exec * LINK) // fill in arrays i = 1; - - //for (cxxNameDouble::iterator it = composition.begin(); it != composition.end(); it++) - //{ - // names_varrec->UU.U1.sarr[i] = string_duplicate((it->first).c_str()); - // moles_varrec->UU.U0.arr[i] = it->second; - // i++; - //} - std::vector< std::pair > sort_comp = composition.sort_second(); size_t j; for (j = 0; j != sort_comp.size(); j++) @@ -2804,19 +2873,31 @@ factor(struct LOC_exec * LINK) break; case tokmol: - n.UU.val = PhreeqcPtr->molality(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->molality(str); + } break; case tokla: - n.UU.val = PhreeqcPtr->log_activity(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_activity(str); + } break; case toklm: - n.UU.val = PhreeqcPtr->log_molality(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_molality(str); + } break; case toksr: - n.UU.val = PhreeqcPtr->saturation_ratio(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->saturation_ratio(str); + } break; case tokstep_no: @@ -2870,10 +2951,11 @@ factor(struct LOC_exec * LINK) n.UU.val = PhreeqcPtr->use.n_solution_user; } } + if (pqi_parse) n.UU.val = 1; break; case toksim_no: - n.UU.val = PhreeqcPtr->simulation; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->simulation; break; case tokget: @@ -2929,10 +3011,10 @@ factor(struct LOC_exec * LINK) break; } } - s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + s_v_ptr = (pqi_parse) ? NULL : PhreeqcPtr->save_values_bsearch(&s_v, &k); if (s_v_ptr == NULL) { - n.UU.val = 0; + n.UU.val = (pqi_parse) ? 1 : 0; } else { @@ -2993,72 +3075,95 @@ factor(struct LOC_exec * LINK) break; } } - s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); - if (s_v_ptr == NULL) + if (pqi_parse) { - n.UU.val = 0; + n.UU.val = 1; } else { - n.UU.val = 1; + s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k); + if (s_v_ptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = 1; + } } break; case tokcharge_balance: - n.UU.val = PhreeqcPtr->cb_x; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cb_x; break; case tokpercent_error: - n.UU.val = 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; + n.UU.val = (pqi_parse) ? 1 : 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; break; case toksi: - PhreeqcPtr->saturation_index(stringfactor(STR1, LINK), &l_dummy, &n.UU.val); + { + char * str = stringfactor(STR1, LINK); + if (pqi_parse) + { + n.UU.val = 1; + } + else + { + PhreeqcPtr->saturation_index(str, &l_dummy, &n.UU.val); + } + } break; case toktot: - n.UU.val = PhreeqcPtr->total(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total(str); + } break; case toktotmole: case toktotmol: case toktotmoles: - n.UU.val = PhreeqcPtr->total_mole(stringfactor(STR1, LINK)); + { + char * str = stringfactor(STR1, LINK); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total_mole(str); + } break; case tokcell_pore_volume: case tokporevolume: - n.UU.val = PhreeqcPtr->cell_pore_volume; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_pore_volume; break; /* VP : Density Start */ case tokrho: - n.UU.val = PhreeqcPtr->calc_dens(); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_dens(); break; /* VP: Density End */ case tokcell_volume: - n.UU.val = PhreeqcPtr->cell_volume; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_volume; break; case tokcell_porosity: - n.UU.val = PhreeqcPtr->cell_porosity; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_porosity; break; case tokcell_saturation: - n.UU.val = PhreeqcPtr->cell_saturation; + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_saturation; break; case toksc: - n.UU.val = PhreeqcPtr->calc_SC(); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_SC(); break; case tokpr_p: - n.UU.val = PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); break; case tokpr_phi: - n.UU.val = PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); break; case tokgas_p: - n.UU.val = PhreeqcPtr->find_gas_p(); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_p(); break; case tokgas_vm: - n.UU.val = PhreeqcPtr->find_gas_vm(); + n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_vm(); break; case toklog10: n.UU.val = log10(realfactor(LINK)); @@ -3190,8 +3295,16 @@ factor(struct LOC_exec * LINK) case tokpeek: /* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ - trick.i = intfactor(LINK); - n.UU.val = *trick.c; + if (pqi_parse) + { + intfactor(LINK); + n.UU.val = 1.0; + } + else + { + trick.i = intfactor(LINK); + n.UU.val = *trick.c; + } /* p2c: basic.p, line 1032: Note: Range checking is ON [216] */ break; @@ -3280,8 +3393,11 @@ term(struct LOC_exec * LINK) } else { - sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + if (!pqi_parse) + { + sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); + warning_msg(PhreeqcPtr->error_string); + } n.UU.val = 0; } } @@ -3746,8 +3862,10 @@ cmdput(struct LOC_exec *LINK) break; } } - - PhreeqcPtr->save_values_store(&s_v); + if (!pqi_parse) + { + PhreeqcPtr->save_values_store(&s_v); + } s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts); } diff --git a/PBasic.h b/PBasic.h index c978fb85..aa192d4d 100644 --- a/PBasic.h +++ b/PBasic.h @@ -294,6 +294,8 @@ public: }; // Methods + bool Get_pqi_parse(void) const {return pqi_parse;}; + void Set_pqi_parse(bool tf) {pqi_parse = tf;}; int free_dim_stringvar(varrec *varbase); void exec(void); int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); @@ -441,6 +443,12 @@ protected: static std::map commands; int P_escapecode; int P_ioresult; + + bool pqi_parse; /* true, most function values set to 1 for testing compilation */ + int parse_whole_program; + int s_hInfiniteLoop; + unsigned int g_nIDErrPrompt; + int g_nErrLineNumber; }; #endif /* _INC_PBasic_H */ From 4268bd931602b9faccb529283f3b9b352497cc19 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 16 Nov 2011 22:42:48 +0000 Subject: [PATCH 0330/1077] Merging Basic1. Need to fix IDS and handler. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5785 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 736 ++++++++++++++++++++++++++++------------------------- PBasic.h | 13 +- 2 files changed, 400 insertions(+), 349 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 72ae7557..d72bc3b6 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -47,6 +47,8 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) P_escapecode = 0; P_ioresult = 0; pqi_parse = false; + PHREEQCI_GUI = false; + parse_whole_program = true; // Basic commands initialized at bottom of file } PBasic::~PBasic(void) @@ -61,6 +63,10 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) char *ptr; P_escapecode = 0; + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + } P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) @@ -97,13 +103,27 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) { if (P_escapecode != -20) { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + if (PHREEQCI_GUI) + { + _ASSERTE(false); + } + else + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } } else { - putchar('\n'); + if (PHREEQCI_GUI) + { + _ASSERTE(false); + } + else + { + putchar('\n'); + } } } } @@ -201,7 +221,12 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { /*main */ int l; char *ptr; - + if (PHREEQCI_GUI) + { + _ASSERTE(s_hInfiniteLoop == 0); + //s_hInfiniteLoop = hInfiniteLoop; + //parse_whole_program = parse_whole_program_flag; + } P_escapecode = 0; P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); @@ -241,9 +266,16 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { if (P_escapecode != -20) { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, - (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + if (PHREEQCI_GUI) + { + _ASSERTE(FALSE); + } + else + { + sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + (int) P_ioresult); + warning_msg(PhreeqcPtr->error_string); + } } else { @@ -255,6 +287,10 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) /* exit(EXIT_SUCCESS); */ PhreeqcPtr->PHRQ_free(inbuf); + if (PHREEQCI_GUI) + { + s_hInfiniteLoop = 0; + } return (P_escapecode); } @@ -505,6 +541,11 @@ parse(char * l_inbuf, tokenrec ** l_buf) *l_buf = t; else tptr->next = t; + if (PHREEQCI_GUI) + { + t->n_sz = 0; + t->sz_num = 0; + } tptr = t; t->next = NULL; switch (ch) @@ -633,15 +674,14 @@ parse(char * l_inbuf, tokenrec ** l_buf) token[j] = '\0'; /* p2c: basic.p, line 309: * Note: Modification of string length may translate incorrectly [146] */ -#define INT -#ifdef INT + /* * Search hash list */ PhreeqcPtr->str_tolower(token); std::map::const_iterator item; - item = commands.find(token); - if (item != commands.end()) + item = command_tokens.find(token); + if (item != command_tokens.end()) { t->kind = item->second; if (t->kind == tokrem) @@ -657,274 +697,6 @@ parse(char * l_inbuf, tokenrec ** l_buf) l_inbuf + i - 1); i = (int) strlen(l_inbuf) + 1; } -#endif -#ifdef LONG - if (!strcmp(token, "and")) - t->kind = tokand; - else if (!strcmp(token, "or")) - t->kind = tokor; - else if (!strcmp(token, "xor")) - t->kind = tokxor; - else if (!strcmp(token, "not")) - t->kind = toknot; - else if (!strcmp(token, "mod")) - t->kind = tokmod; - else if (!strcmp(token, "sqr")) - t->kind = toksqr; - else if (!strcmp(token, "sqrt")) - t->kind = toksqrt; - else if (!strcmp(token, "ceil")) - t->kind = tokceil; - else if (!strcmp(token, "floor")) - t->kind = tokfloor; - else if (!strcmp(token, "sin")) - t->kind = toksin; - else if (!strcmp(token, "cos")) - t->kind = tokcos; - else if (!strcmp(token, "tan")) - t->kind = toktan; - else if (!strcmp(token, "arctan")) - t->kind = tokarctan; - else if (!strcmp(token, "log")) - t->kind = toklog; - else if (!strcmp(token, "exp")) - t->kind = tokexp; - else if (!strcmp(token, "abs")) - t->kind = tokabs; - else if (!strcmp(token, "sgn")) - t->kind = toksgn; - else if (!strcmp(token, "str$")) - t->kind = tokstr_; - else if (!strcmp(token, "val")) - t->kind = tokval; - else if (!strcmp(token, "chr$")) - t->kind = tokchr_; - else if (!strcmp(token, "eol$")) - t->kind = tokeol_; - else if (!strcmp(token, "asc")) - t->kind = tokasc; - else if (!strcmp(token, "len")) - t->kind = toklen; - else if (!strcmp(token, "mid$")) - t->kind = tokmid_; - else if (!strcmp(token, "peek")) - t->kind = tokpeek; - else if (!strcmp(token, "let")) - t->kind = toklet; - else if (!strcmp(token, "print")) - t->kind = tokprint; - else if (!strcmp(token, "PhreeqcPtr->punch")) - t->kind = tokpunch; -#if defined PHREEQ98 - else if (!strcmp(token, "graph_x")) - t->kind = tokgraph_x; - else if (!strcmp(token, "graph_y")) - t->kind = tokgraph_y; - else if (!strcmp(token, "graph_sy")) - t->kind = tokgraph_sy; -#endif - else if (!strcmp(token, "input")) - t->kind = tokinput; - else if (!strcmp(token, "goto")) - t->kind = tokgoto; - else if (!strcmp(token, "go to")) - t->kind = tokgoto; - else if (!strcmp(token, "if")) - t->kind = tokif; - else if (!strcmp(token, "end")) - t->kind = tokend; - else if (!strcmp(token, "stop")) - t->kind = tokstop; - else if (!strcmp(token, "for")) - t->kind = tokfor; - else if (!strcmp(token, "next")) - t->kind = toknext; - else if (!strcmp(token, "while")) - t->kind = tokwhile; - else if (!strcmp(token, "wend")) - t->kind = tokwend; - else if (!strcmp(token, "gosub")) - t->kind = tokgosub; - else if (!strcmp(token, "return")) - t->kind = tokreturn; - else if (!strcmp(token, "read")) - t->kind = tokread; - else if (!strcmp(token, "data")) - t->kind = tokdata; - else if (!strcmp(token, "restore")) - t->kind = tokrestore; - else if (!strcmp(token, "gotoxy")) - t->kind = tokgotoxy; - else if (!strcmp(token, "on")) - t->kind = tokon; - else if (!strcmp(token, "dim")) - t->kind = tokdim; - else if (!strcmp(token, "poke")) - t->kind = tokpoke; - else if (!strcmp(token, "list")) - t->kind = toklist; - else if (!strcmp(token, "run")) - t->kind = tokrun; - else if (!strcmp(token, "new")) - t->kind = toknew; - else if (!strcmp(token, "load")) - t->kind = tokload; - else if (!strcmp(token, "merge")) - t->kind = tokmerge; - else if (!strcmp(token, "save")) - t->kind = toksave; - else if (!strcmp(token, "bye")) - t->kind = tokbye; - else if (!strcmp(token, "quit")) - t->kind = tokbye; - else if (!strcmp(token, "del")) - t->kind = tokdel; - else if (!strcmp(token, "renum")) - t->kind = tokrenum; - else if (!strcmp(token, "then")) - t->kind = tokthen; - else if (!strcmp(token, "else")) - t->kind = tokelse; - else if (!strcmp(token, "to")) - t->kind = tokto; - else if (!strcmp(token, "step")) - t->kind = tokstep; - /* - * dlp: added functions - */ - else if (!strcmp(token, "tc")) - t->kind = toktc; - else if (!strcmp(token, "tk")) - t->kind = toktk; - else if (!strcmp(token, "time")) - t->kind = toktime; - else if (!strcmp(token, "sim_time")) - t->kind = toksim_time; - else if (!strcmp(token, "total_time")) - t->kind = toktotal_time; - else if (!strcmp(token, "m0")) - t->kind = tokm0; - else if (!strcmp(token, "m")) - t->kind = tokm; - else if (!strcmp(token, "parm")) - t->kind = tokparm; - else if (!strcmp(token, "act")) - t->kind = tokact; - else if (!strcmp(token, "change_por")) - t->kind = tokchange_por; - else if (!strcmp(token, "get_por")) - t->kind = tokget_por; - else if (!strcmp(token, "change_surf")) - t->kind = tokchange_surf; - else if (!strcmp(token, "porevolume")) - t->kind = tokporevolume; - else if (!strcmp(token, "edl")) - t->kind = tokedl; - else if (!strcmp(token, "surf")) - t->kind = toksurf; - else if (!strcmp(token, "equi")) - t->kind = tokequi; - else if (!strcmp(token, "kin")) - t->kind = tokkin; - else if (!strcmp(token, "gas")) - t->kind = tokgas; - else if (!strcmp(token, "s_s")) - t->kind = toks_s; - else if (!strcmp(token, "misc1")) - t->kind = tokmisc1; - else if (!strcmp(token, "misc2")) - t->kind = tokmisc2; - else if (!strcmp(token, "mu")) - t->kind = tokmu; - else if (!strcmp(token, "osmotic")) - t->kind = tokosmotic; - else if (!strcmp(token, "alk")) - t->kind = tokalk; - else if (!strcmp(token, "lk_species")) - t->kind = toklk_species; - else if (!strcmp(token, "lk_named")) - t->kind = toklk_named; - else if (!strcmp(token, "lk_phase")) - t->kind = toklk_phase; - else if (!strcmp(token, "sum_species")) - t->kind = toksum_species; - else if (!strcmp(token, "sum_gas")) - t->kind = toksum_gas; - else if (!strcmp(token, "sum_s_s")) - t->kind = toksum_s_s; - else if (!strcmp(token, "calc_value")) - t->kind = tokcalc_value; - else if (!strcmp(token, "description")) - t->kind = tokdescription; - else if (!strcmp(token, "sys")) - t->kind = toksys; - else if (!strcmp(token, "instr")) - t->kind = tokinstr; - else if (!strcmp(token, "ltrim")) - t->kind = tokltrim; - else if (!strcmp(token, "rtrim")) - t->kind = tokrtrim; - else if (!strcmp(token, "trim")) - t->kind = toktrim; - else if (!strcmp(token, "pad")) - t->kind = tokpad; - else if (!strcmp(token, "rxn")) - t->kind = tokrxn; - else if (!strcmp(token, "dist")) - t->kind = tokdist; - else if (!strcmp(token, "mol")) - t->kind = tokmol; - else if (!strcmp(token, "la")) - t->kind = tokla; - else if (!strcmp(token, "lm")) - t->kind = toklm; - else if (!strcmp(token, "sr")) - t->kind = toksr; - else if (!strcmp(token, "step_no")) - t->kind = tokstep_no; - else if (!strcmp(token, "cell_no")) - t->kind = tokcell_no; - else if (!strcmp(token, "sim_no")) - t->kind = toksim_no; - else if (!strcmp(token, "si")) - t->kind = toksi; - else if (!strcmp(token, "tot")) - t->kind = toktot; - else if (!strcmp(token, "totmole")) - t->kind = toktotmole; - else if (!strcmp(token, "totmol")) - t->kind = toktotmole; - else if (!strcmp(token, "totmoles")) - t->kind = toktotmole; - else if (!strcmp(token, "log10")) - t->kind = toklog10; - else if (!strcmp(token, "put")) - t->kind = tokput; - else if (!strcmp(token, "get")) - t->kind = tokget; - else if (!strcmp(token, "exists")) - t->kind = tokexists; - else if (!strcmp(token, "charge_balance")) - t->kind = tokcharge_balance; - else if (!strcmp(token, "percent_error")) - t->kind = tokpercent_error; - else if (!strcmp(token, "SC")) - t->kind = tokspcond; - else if (!strcmp(token, "rem")) - { - t->kind = tokrem; - m = strlen(l_inbuf) + 1; - if (m < 256) - m = 256; - t->UU.sp = (char *) PhreeqcPtr->PhreeqcPtr->PHRQ_malloc(m); - if (t->UU.sp == NULL) - PhreeqcPtr->malloc_error(); - sprintf(t->UU.sp, "%.*s", - (int) (strlen(l_inbuf) - i + 1), - l_inbuf + i - 1); - i = strlen(l_inbuf) + 1; - } -#endif } else { @@ -974,6 +746,26 @@ parse(char * l_inbuf, tokenrec ** l_buf) i++; break; } + if (PHREEQCI_GUI) + { + _ASSERTE(t->n_sz == 0); + _ASSERTE(t->sz_num == NULL); + t->n_sz = max(23, ptr - &inbuf[i - 1]); + t->sz_num = + (char *) PhreeqcPtr->PHRQ_calloc((t->n_sz + 1), sizeof(char)); + if (t->sz_num == NULL) + PhreeqcPtr->malloc_error(); + if (ptr > &inbuf[i - 1]) + { + strncpy(t->sz_num, &inbuf[i - 1], + (ptr - &inbuf[i - 1])); + t->sz_num[ptr - &inbuf[i - 1]] = '\0'; + } + else + { + t->sz_num[0] = '\0'; + } + } i += (int) (ptr - &l_inbuf[i - 1]); } else @@ -987,16 +779,49 @@ parse(char * l_inbuf, tokenrec ** l_buf) } while (i <= (int) strlen(l_inbuf)); if (q) { - sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(P_escapecode == 0); + //g_nIDErrPrompt = IDS_ERR_MISSING_Q; + P_escapecode = -20; + return; + } + else + { + sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } } if (lp > 0) { - sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(P_escapecode == 0); + //g_nIDErrPrompt = IDS_ERR_MISSING_RP; + P_escapecode = -20; + return; + } + else + { + sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } } else if (lp < 0) { - sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(P_escapecode == 0); + //g_nIDErrPrompt = IDS_ERR_MISSING_RP; + P_escapecode = -20; + return; + } + else + { + sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(PhreeqcPtr->error_string, STOP); + } } } @@ -1670,6 +1495,19 @@ disposetokens(tokenrec ** tok) while (*tok != NULL) { tok1 = (*tok)->next; + if (PHREEQCI_GUI) + { + if ((*tok)->kind == (long) toknum) + { + PhreeqcPtr->PHRQ_free((*tok)->sz_num); + } +#ifdef _DEBUG + else + { + _ASSERTE((*tok)->sz_num == NULL); + } +#endif /* _DEBUG */ + } if ((*tok)->kind == (long) tokrem || (*tok)->kind == (long) tokstr) { (*tok)->UU.sp = (char *) PhreeqcPtr->free_check_null((*tok)->UU.sp); @@ -1736,30 +1574,52 @@ parseinput(tokenrec ** l_buf) void PBasic:: errormsg(const char * l_s) { - error_msg(l_s, CONTINUE); + if (PHREEQCI_GUI) + { + /* set g_nIDErrPrompt before calling errormsg see snerr */ + _ASSERTE(g_nIDErrPrompt != 0); + } + else + { + error_msg(l_s, CONTINUE); + } _Escape(42); } void PBasic:: -snerr(const char * l_s) + snerr(const char * l_s) { - char str[MAX_LENGTH] = {0}; - strcpy(str, "Syntax_error "); - errormsg(strcat(str, l_s)); -} - - -void PBasic:: -tmerr(const char * l_s) -{ - char str[MAX_LENGTH] = {0}; - strcpy(str, "Type mismatch error"); - errormsg(strcat(str, l_s)); + char str[MAX_LENGTH] = {0}; + strcpy(str, "Syntax_error "); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_SYNTAX; + } + errormsg(strcat(str, l_s)); } void PBasic:: -badsubscr(void) + tmerr(const char * l_s) { + char str[MAX_LENGTH] = {0}; + strcpy(str, "Type mismatch error"); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_MISMATCH; + } + errormsg(strcat(str, l_s)); +} + +void PBasic:: + badsubscr(void) +{ + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_BAD_SUBSCRIPT; + } errormsg("Bad subscript"); } @@ -1856,13 +1716,13 @@ require(int k, struct LOC_exec *LINK) if (LINK->t == NULL || LINK->t->kind != k) { std::map::const_iterator item; - for (item = commands.begin(); item != commands.end(); item++) + for (item = command_tokens.begin(); item != command_tokens.end(); item++) { if (item->second == k) break; } - if (item == commands.end()) + if (item == command_tokens.end()) snerr(": missing unknown command"); else { strcpy(str, ": missing "); @@ -2579,7 +2439,7 @@ factor(struct LOC_exec * LINK) names_arg = (char **) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (names_arg == NULL) PhreeqcPtr->malloc_error(); - types_arg = (char **)PhreeqcPtr-> PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); + types_arg = (char **)PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (types_arg == NULL) PhreeqcPtr->malloc_error(); moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); @@ -3566,7 +3426,14 @@ void PBasic:: checkextra(struct LOC_exec *LINK) { if (LINK->t != NULL) + { + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_EXTRA; + } errormsg("Extra information on line"); + } } bool PBasic:: @@ -3593,20 +3460,50 @@ findline(long n) l = l->next; return l; } - +#ifdef SKIP linerec * PBasic:: mustfindline(long n) { linerec *l; l = findline(n); - if (l == NULL) { + if (l == NULL) + { sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); errormsg(PhreeqcPtr->error_string); } return l; } +#endif +linerec * PBasic:: +mustfindline(long n) +{ + linerec *l; + l = findline(n); + if (PHREEQCI_GUI) + { + if (parse_whole_program) + { + if (l == NULL) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_UNDEF_LINE; + sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); + errormsg(PhreeqcPtr->error_string); + } + } + } + else + { + if (l == NULL) + { + sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); + errormsg(PhreeqcPtr->error_string); + } + } + return l; +} void PBasic:: cmdend(struct LOC_exec *LINK) { @@ -4039,10 +3936,18 @@ cmdrenum(struct LOC_exec *LINK) while (l1 != NULL && l1->num != lnum) l1 = l1->next; if (l1 == NULL) + { printf("Undefined line %ld in line %ld\n", lnum, l->num2); + } else + { + if (PHREEQCI_GUI) + { + _snprintf(tok->sz_num, tok->n_sz, "%ld", l1->num2); + } tok->UU.num = l1->num2; + } if (tok->next != NULL && tok->next->kind == tokcomma) tok = tok->next; } @@ -4413,6 +4318,11 @@ cmdfor(struct LOC_exec *LINK) if (stmtline == NULL || stmtline->next == NULL) { stmtline = saveline; + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_FOR_WO_NEXT; + } errormsg("FOR without NEXT"); } stmtline = stmtline->next; @@ -4461,7 +4371,14 @@ cmdnext(struct LOC_exec *LINK) do { if (loopbase == NULL || loopbase->kind == gosubloop) + { + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_NEXT_WO_FOR; + } errormsg("NEXT without FOR"); + } found = (bool) (loopbase->kind == forloop && (v == NULL || loopbase->UU.U0.vp == v)); if (!found) @@ -4505,12 +4422,33 @@ cmdwhile(struct LOC_exec *LINK) return; if (realexpr(LINK) != 0) return; - if (!skiploop(tokwhile, tokwend, LINK)) - errormsg("WHILE without WEND"); - l = loopbase->next; - PhreeqcPtr->PHRQ_free(loopbase); - loopbase = l; - skiptoeos(LINK); + if (PHREEQCI_GUI) + { + if (parse_whole_program == TRUE) + { + if (!skiploop(tokwhile, tokwend, LINK)) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_WHILE_WO_WEND; + errormsg("WHILE without WEND"); + } + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); + } + } + else + { + if (!skiploop(tokwhile, tokwend, LINK)) + { + errormsg("WHILE without WEND"); + } + l = loopbase->next; + PhreeqcPtr->PHRQ_free(loopbase); + loopbase = l; + skiptoeos(LINK); + } } void PBasic:: @@ -4520,11 +4458,21 @@ cmdwend(struct LOC_exec *LINK) linerec *tokline; looprec *l; bool found; - + if (PHREEQCI_GUI && !parse_whole_program) + { + return; + } do { if (loopbase == NULL || loopbase->kind == gosubloop) + { + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_WEND_WO_WHILE; + } errormsg("WEND without WHILE"); + } found = (bool) (loopbase->kind == whileloop); if (!found) { @@ -4582,10 +4530,22 @@ cmdreturn(struct LOC_exec *LINK) looprec *l; bool found; + if (PHREEQCI_GUI && !parse_whole_program) + { + return; + } + do { if (loopbase == NULL) + { + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_RETURN_WO_GOSUB; + } errormsg("RETURN without GOSUB"); + } found = (bool) (loopbase->kind == gosubloop); if (!found) { @@ -4615,41 +4575,86 @@ cmdread(struct LOC_exec *LINK) v = findvar(LINK); tok = LINK->t; LINK->t = datatok; - if (dataline == NULL) + if (PHREEQCI_GUI) { - dataline = linebase; - LINK->t = dataline->txt; - } - if (LINK->t == NULL || LINK->t->kind != tokcomma) - { - do + if (parse_whole_program) { - while (LINK->t == NULL) + if (dataline == NULL) { - if (dataline == NULL || dataline->next == NULL) - errormsg("Out of Data"); - dataline = dataline->next; + dataline = linebase; LINK->t = dataline->txt; } - found = (bool) (LINK->t->kind == tokdata); - LINK->t = LINK->t->next; + if (LINK->t == NULL || LINK->t->kind != tokcomma) + { + do + { + while (LINK->t == NULL) + { + if (dataline == NULL || dataline->next == NULL) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_OUT_OF_DATA; + errormsg("Out of Data"); + } + dataline = dataline->next; + LINK->t = dataline->txt; + } + found = (bool) (LINK->t->kind == tokdata); + LINK->t = LINK->t->next; + } + while (!found || iseos(LINK)); + } + else + LINK->t = LINK->t->next; + if (v->stringvar) + { + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = strexpr(LINK); + } + else + *v->UU.U0.val = realexpr(LINK); } - while (!found || iseos(LINK)); } else - LINK->t = LINK->t->next; - if (v->stringvar) { - if (*v->UU.U1.sval != NULL) - *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); - *v->UU.U1.sval = strexpr(LINK); + if (dataline == NULL) + { + dataline = linebase; + LINK->t = dataline->txt; + } + if (LINK->t == NULL || LINK->t->kind != tokcomma) + { + do + { + while (LINK->t == NULL) + { + if (dataline == NULL || dataline->next == NULL) + errormsg("Out of Data"); + dataline = dataline->next; + LINK->t = dataline->txt; + } + found = (bool) (LINK->t->kind == tokdata); + LINK->t = LINK->t->next; + } + while (!found || iseos(LINK)); + } + else + LINK->t = LINK->t->next; + if (v->stringvar) + { + if (*v->UU.U1.sval != NULL) + *v->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*v->UU.U1.sval); + *v->UU.U1.sval = strexpr(LINK); + } + else + *v->UU.U0.val = realexpr(LINK); } - else - *v->UU.U0.val = realexpr(LINK); datatok = LINK->t; LINK->t = tok; if (!iseos(LINK)) require(tokcomma, LINK); + } while (!iseos(LINK)); } @@ -4668,7 +4673,17 @@ cmdrestore(struct LOC_exec *LINK) else { dataline = mustfindline(intexpr(LINK)); - datatok = dataline->txt; + if (PHREEQCI_GUI) + { + if (parse_whole_program) + { + datatok = dataline->txt; + } + } + else + { + datatok = dataline->txt; + } } } @@ -4730,7 +4745,14 @@ cmddim(struct LOC_exec *LINK) v = LINK->t->UU.vp; LINK->t = LINK->t->next; if (v->numdims != 0) + { + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_ARRAY_ALREADY; + } errormsg("Array already dimensioned before"); + } j = 1; i = 0; require(toklp, LINK); @@ -4796,8 +4818,6 @@ exec(void) char *ioerrmsg; char STR1[256] = {0}; - - //TRY(try1); try { do @@ -4812,6 +4832,14 @@ exec(void) if (V.t != NULL) { V.t = V.t->next; + if (PHREEQCI_GUI) + { + //if (WaitForSingleObject(s_hInfiniteLoop, 0) == WAIT_OBJECT_0) + { + //g_nIDErrPrompt = IDS_ERR_INFINITE_LOOP; + errormsg("Possible infinite loop"); + } + } switch (stmttok->kind) { @@ -4903,9 +4931,16 @@ exec(void) #endif case tokinput: - error_msg - ("Basic command INPUT is not a legal command in PHREEQC.", - STOP); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_INPUT_NOTLEGAL; + errormsg ("Basic command INPUT is not a legal command in PHREEQC."); + } + else + { + error_msg ("Basic command INPUT is not a legal command in PHREEQC.", STOP); + } break; case tokgoto: @@ -4983,6 +5018,11 @@ exec(void) break; default: + if (PHREEQCI_GUI) + { + _ASSERTE(g_nIDErrPrompt == 0); + //g_nIDErrPrompt = IDS_ERR_ILLEGAL; + } errormsg("Illegal command"); break; } @@ -5001,7 +5041,6 @@ exec(void) } } while (stmtline != NULL); - //RECOVER2(try1, _Ltry1); } catch (PBasicStop e) { @@ -5065,10 +5104,17 @@ exec(void) } if (stmtline != NULL) { - sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - error_msg(PhreeqcPtr->error_string, CONTINUE); + if (PHREEQCI_GUI) + { + _ASSERTE(g_nErrLineNumber == 0); + g_nErrLineNumber = stmtline->num; + } + else + { + sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + error_msg(PhreeqcPtr->error_string, CONTINUE); + } } - //ENDTRY(try1); } // end catch } /*exec */ @@ -6257,7 +6303,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("gas_p", PBasic::tokgas_p), std::map::value_type("gas_vm", PBasic::tokgas_vm), }; -std::map PBasic::commands(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); +std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); /* End. */ diff --git a/PBasic.h b/PBasic.h index aa192d4d..7663c562 100644 --- a/PBasic.h +++ b/PBasic.h @@ -74,10 +74,10 @@ typedef struct tokenrec char *sp; char snch; } UU; -#ifdef PHREEQCI_GUI +//#ifdef PHREEQCI_GUI size_t n_sz; char *sz_num; -#endif +//#endif } tokenrec; typedef struct linerec @@ -294,8 +294,12 @@ public: }; // Methods + bool Get_PHREEQCI_GUI(void) const {return PHREEQCI_GUI;}; + void Set_PHREEQCI_GUI(bool tf) {PHREEQCI_GUI = tf;}; bool Get_pqi_parse(void) const {return pqi_parse;}; void Set_pqi_parse(bool tf) {pqi_parse = tf;}; + bool Get_parse_whole_program(void) const {return parse_whole_program;}; + void Set_parse_whole_program(bool tf) {parse_whole_program = tf;}; int free_dim_stringvar(varrec *varbase); void exec(void); int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); @@ -440,12 +444,13 @@ protected: tokenrec *stmttok, *datatok, *buf; bool exitflag; long EXCP_LINE; - static std::map commands; + static std::map command_tokens; int P_escapecode; int P_ioresult; + bool PHREEQCI_GUI; bool pqi_parse; /* true, most function values set to 1 for testing compilation */ - int parse_whole_program; + bool parse_whole_program; int s_hInfiniteLoop; unsigned int g_nIDErrPrompt; int g_nErrLineNumber; From 79b256e44a250ee8ae1b136e5b8f5561355f54dd Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 17 Nov 2011 00:43:10 +0000 Subject: [PATCH 0331/1077] added code to handle IDS_* added code for HANDLE #ifdef'd the WaitForSingleObject git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5786 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 272 ++++++++++++++++++++++++++--------------------------- PBasic.h | 54 +++++++++-- 2 files changed, 178 insertions(+), 148 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index d72bc3b6..8489f6c6 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,5 +1,6 @@ -#if defined(WIN32) +#if defined(PHREEQCI_GUI) #include +#include "resource.h" #endif #include #include "PBasic.h" @@ -46,9 +47,14 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) EXCP_LINE = 0; P_escapecode = 0; P_ioresult = 0; - pqi_parse = false; - PHREEQCI_GUI = false; + parse_all = false; + phreeqci_gui = false; parse_whole_program = true; +#if defined(PHREEQCI_GUI) + hInfiniteLoop = 0; +#endif + nIDErrPrompt = (PBasic::IDErr)0; + nErrLineNumber = 0; // Basic commands initialized at bottom of file } PBasic::~PBasic(void) @@ -63,10 +69,6 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) char *ptr; P_escapecode = 0; - if (PHREEQCI_GUI) - { - _ASSERTE(g_nIDErrPrompt == 0); - } P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (inbuf == NULL) @@ -103,7 +105,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) { if (P_escapecode != -20) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { _ASSERTE(false); } @@ -116,7 +118,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } else { - if (PHREEQCI_GUI) + if (phreeqci_gui) { _ASSERTE(false); } @@ -221,12 +223,6 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { /*main */ int l; char *ptr; - if (PHREEQCI_GUI) - { - _ASSERTE(s_hInfiniteLoop == 0); - //s_hInfiniteLoop = hInfiniteLoop; - //parse_whole_program = parse_whole_program_flag; - } P_escapecode = 0; P_ioresult = 0; inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); @@ -266,7 +262,7 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { if (P_escapecode != -20) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { _ASSERTE(FALSE); } @@ -287,10 +283,6 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) /* exit(EXIT_SUCCESS); */ PhreeqcPtr->PHRQ_free(inbuf); - if (PHREEQCI_GUI) - { - s_hInfiniteLoop = 0; - } return (P_escapecode); } @@ -541,7 +533,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) *l_buf = t; else tptr->next = t; - if (PHREEQCI_GUI) + if (phreeqci_gui) { t->n_sz = 0; t->sz_num = 0; @@ -746,7 +738,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) i++; break; } - if (PHREEQCI_GUI) + if (phreeqci_gui) { _ASSERTE(t->n_sz == 0); _ASSERTE(t->sz_num == NULL); @@ -779,11 +771,11 @@ parse(char * l_inbuf, tokenrec ** l_buf) } while (i <= (int) strlen(l_inbuf)); if (q) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(nIDErrPrompt == 0); _ASSERTE(P_escapecode == 0); - //g_nIDErrPrompt = IDS_ERR_MISSING_Q; + nIDErrPrompt = IDS_ERR_MISSING_Q; P_escapecode = -20; return; } @@ -794,11 +786,11 @@ parse(char * l_inbuf, tokenrec ** l_buf) } } if (lp > 0) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(nIDErrPrompt == 0); _ASSERTE(P_escapecode == 0); - //g_nIDErrPrompt = IDS_ERR_MISSING_RP; + nIDErrPrompt = IDS_ERR_MISSING_RP; P_escapecode = -20; return; } @@ -809,11 +801,11 @@ parse(char * l_inbuf, tokenrec ** l_buf) } } else if (lp < 0) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); + _ASSERTE(nIDErrPrompt == 0); _ASSERTE(P_escapecode == 0); - //g_nIDErrPrompt = IDS_ERR_MISSING_RP; + nIDErrPrompt = IDS_ERR_MISSING_RP; P_escapecode = -20; return; } @@ -1495,7 +1487,7 @@ disposetokens(tokenrec ** tok) while (*tok != NULL) { tok1 = (*tok)->next; - if (PHREEQCI_GUI) + if (phreeqci_gui) { if ((*tok)->kind == (long) toknum) { @@ -1574,10 +1566,10 @@ parseinput(tokenrec ** l_buf) void PBasic:: errormsg(const char * l_s) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - /* set g_nIDErrPrompt before calling errormsg see snerr */ - _ASSERTE(g_nIDErrPrompt != 0); + /* set nIDErrPrompt before calling errormsg see snerr */ + _ASSERTE(nIDErrPrompt != 0); } else { @@ -1591,10 +1583,10 @@ void PBasic:: { char str[MAX_LENGTH] = {0}; strcpy(str, "Syntax_error "); - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_SYNTAX; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_SYNTAX; } errormsg(strcat(str, l_s)); } @@ -1604,10 +1596,10 @@ void PBasic:: { char str[MAX_LENGTH] = {0}; strcpy(str, "Type mismatch error"); - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_MISMATCH; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_MISMATCH; } errormsg(strcat(str, l_s)); } @@ -1615,10 +1607,10 @@ void PBasic:: void PBasic:: badsubscr(void) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_BAD_SUBSCRIPT; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_BAD_SUBSCRIPT; } errormsg("Bad subscript"); } @@ -2029,7 +2021,7 @@ factor(struct LOC_exec * LINK) case tokparm: i_rate = intfactor(LINK); - if (pqi_parse) + if (parse_all) { n.UU.val = 1; } @@ -2047,27 +2039,27 @@ factor(struct LOC_exec * LINK) case tokact: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->activity(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->activity(str); } break; case tokgamma: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->activity_coefficient(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->activity_coefficient(str); } break; case toklg: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_activity_coefficient(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_activity_coefficient(str); } break; case tokget_por: i = intfactor(LINK); - if (pqi_parse) + if (parse_all) { n.UU.val = 1; } @@ -2106,7 +2098,7 @@ factor(struct LOC_exec * LINK) surface_name = NULL; } require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->diff_layer_total(elt_name, surface_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->diff_layer_total(elt_name, surface_name); break; case toksurf: @@ -2122,48 +2114,48 @@ factor(struct LOC_exec * LINK) surface_name = NULL; } require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->surf_total(elt_name, surface_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->surf_total(elt_name, surface_name); break; case tokequi: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->equi_phase(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->equi_phase(str); } break; case tokkin: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->kinetics_moles(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->kinetics_moles(str); } break; case tokgas: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_comp(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_gas_comp(str); } break; case toks_s: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_s_s_comp(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_s_s_comp(str); } break; case tokmisc1: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_misc1(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_misc1(str); } break; case tokmisc2: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_misc2(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_misc2(str); } break; @@ -2183,27 +2175,27 @@ factor(struct LOC_exec * LINK) break; case tokalk: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->total_alkalinity / PhreeqcPtr->mass_water_aq_x; break; case toklk_species: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_s(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_s(str); } break; case toklk_named: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_n(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_n(str); } break; case toklk_phase: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_logk_p(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_p(str); } break; @@ -2220,7 +2212,7 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_species(mytemplate, elt_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sum_match_species(mytemplate, elt_name); break; case toksum_gas: @@ -2236,7 +2228,7 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_gases(mytemplate, elt_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sum_match_gases(mytemplate, elt_name); break; case toksum_s_s: @@ -2252,14 +2244,14 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); break; case tokcalc_value: require(toklp, LINK); name = stringfactor(STR1, LINK); require(tokrp, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->get_calculate_value(name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->get_calculate_value(name); break; case tokdescription: @@ -2350,7 +2342,7 @@ factor(struct LOC_exec * LINK) case tokiso: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->iso_value(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->iso_value(str); } break; @@ -2360,7 +2352,7 @@ factor(struct LOC_exec * LINK) string1 = stringfactor(STR1, LINK); require(tokrp, LINK); PhreeqcPtr->string_trim(string1); - n.UU.sval = (pqi_parse) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); + n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); break; case tokpad: @@ -2431,7 +2423,7 @@ factor(struct LOC_exec * LINK) /* n.UU.val = system_total(elt_name, count_varrec->UU.U0.val, &(names_varrec->UU.U1.sarr), &(types_varrec->UU.U1.sarr), &(moles_varrec->UU.U0.arr)); */ - if (pqi_parse) + if (parse_all) { PhreeqcPtr->sys_tot = 0; PhreeqcPtr->count_sys = 1000; @@ -2543,7 +2535,7 @@ factor(struct LOC_exec * LINK) */ // return total moles - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->list_s_s(s_s_name, composition); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->list_s_s(s_s_name, composition); /* * fill in varrec structure @@ -2735,28 +2727,28 @@ factor(struct LOC_exec * LINK) case tokmol: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->molality(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->molality(str); } break; case tokla: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_activity(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_activity(str); } break; case toklm: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->log_molality(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_molality(str); } break; case toksr: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->saturation_ratio(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->saturation_ratio(str); } break; @@ -2811,11 +2803,11 @@ factor(struct LOC_exec * LINK) n.UU.val = PhreeqcPtr->use.n_solution_user; } } - if (pqi_parse) n.UU.val = 1; + if (parse_all) n.UU.val = 1; break; case toksim_no: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->simulation; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->simulation; break; case tokget: @@ -2871,10 +2863,10 @@ factor(struct LOC_exec * LINK) break; } } - s_v_ptr = (pqi_parse) ? NULL : PhreeqcPtr->save_values_bsearch(&s_v, &k); + s_v_ptr = (parse_all) ? NULL : PhreeqcPtr->save_values_bsearch(&s_v, &k); if (s_v_ptr == NULL) { - n.UU.val = (pqi_parse) ? 1 : 0; + n.UU.val = (parse_all) ? 1 : 0; } else { @@ -2935,7 +2927,7 @@ factor(struct LOC_exec * LINK) break; } } - if (pqi_parse) + if (parse_all) { n.UU.val = 1; } @@ -2954,17 +2946,17 @@ factor(struct LOC_exec * LINK) break; case tokcharge_balance: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cb_x; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cb_x; break; case tokpercent_error: - n.UU.val = (pqi_parse) ? 1 : 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; + n.UU.val = (parse_all) ? 1 : 100 * PhreeqcPtr->cb_x / PhreeqcPtr->total_ions_x; break; case toksi: { char * str = stringfactor(STR1, LINK); - if (pqi_parse) + if (parse_all) { n.UU.val = 1; } @@ -2978,7 +2970,7 @@ factor(struct LOC_exec * LINK) case toktot: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->total(str); } break; @@ -2987,43 +2979,43 @@ factor(struct LOC_exec * LINK) case toktotmoles: { char * str = stringfactor(STR1, LINK); - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->total_mole(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->total_mole(str); } break; case tokcell_pore_volume: case tokporevolume: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_pore_volume; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_pore_volume; break; /* VP : Density Start */ case tokrho: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_dens(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_dens(); break; /* VP: Density End */ case tokcell_volume: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_volume; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_volume; break; case tokcell_porosity: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_porosity; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_porosity; break; case tokcell_saturation: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->cell_saturation; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_saturation; break; case toksc: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->calc_SC(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_SC(); break; case tokpr_p: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); break; case tokpr_phi: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); break; case tokgas_p: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_p(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_gas_p(); break; case tokgas_vm: - n.UU.val = (pqi_parse) ? 1 : PhreeqcPtr->find_gas_vm(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_gas_vm(); break; case toklog10: n.UU.val = log10(realfactor(LINK)); @@ -3155,7 +3147,7 @@ factor(struct LOC_exec * LINK) case tokpeek: /* p2c: basic.p, line 1029: Note: Range checking is OFF [216] */ - if (pqi_parse) + if (parse_all) { intfactor(LINK); n.UU.val = 1.0; @@ -3253,7 +3245,7 @@ term(struct LOC_exec * LINK) } else { - if (!pqi_parse) + if (!parse_all) { sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); warning_msg(PhreeqcPtr->error_string); @@ -3427,10 +3419,10 @@ checkextra(struct LOC_exec *LINK) { if (LINK->t != NULL) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_EXTRA; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_EXTRA; } errormsg("Extra information on line"); } @@ -3481,14 +3473,14 @@ mustfindline(long n) linerec *l; l = findline(n); - if (PHREEQCI_GUI) + if (phreeqci_gui) { if (parse_whole_program) { if (l == NULL) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_UNDEF_LINE; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_UNDEF_LINE; sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); errormsg(PhreeqcPtr->error_string); } @@ -3759,7 +3751,7 @@ cmdput(struct LOC_exec *LINK) break; } } - if (!pqi_parse) + if (!parse_all) { PhreeqcPtr->save_values_store(&s_v); } @@ -3942,7 +3934,7 @@ cmdrenum(struct LOC_exec *LINK) } else { - if (PHREEQCI_GUI) + if (phreeqci_gui) { _snprintf(tok->sz_num, tok->n_sz, "%ld", l1->num2); } @@ -4318,10 +4310,10 @@ cmdfor(struct LOC_exec *LINK) if (stmtline == NULL || stmtline->next == NULL) { stmtline = saveline; - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_FOR_WO_NEXT; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_FOR_WO_NEXT; } errormsg("FOR without NEXT"); } @@ -4372,10 +4364,10 @@ cmdnext(struct LOC_exec *LINK) { if (loopbase == NULL || loopbase->kind == gosubloop) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_NEXT_WO_FOR; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_NEXT_WO_FOR; } errormsg("NEXT without FOR"); } @@ -4422,14 +4414,14 @@ cmdwhile(struct LOC_exec *LINK) return; if (realexpr(LINK) != 0) return; - if (PHREEQCI_GUI) + if (phreeqci_gui) { if (parse_whole_program == TRUE) { if (!skiploop(tokwhile, tokwend, LINK)) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_WHILE_WO_WEND; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_WHILE_WO_WEND; errormsg("WHILE without WEND"); } l = loopbase->next; @@ -4458,7 +4450,7 @@ cmdwend(struct LOC_exec *LINK) linerec *tokline; looprec *l; bool found; - if (PHREEQCI_GUI && !parse_whole_program) + if (phreeqci_gui && !parse_whole_program) { return; } @@ -4466,10 +4458,10 @@ cmdwend(struct LOC_exec *LINK) { if (loopbase == NULL || loopbase->kind == gosubloop) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_WEND_WO_WHILE; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_WEND_WO_WHILE; } errormsg("WEND without WHILE"); } @@ -4530,7 +4522,7 @@ cmdreturn(struct LOC_exec *LINK) looprec *l; bool found; - if (PHREEQCI_GUI && !parse_whole_program) + if (phreeqci_gui && !parse_whole_program) { return; } @@ -4539,10 +4531,10 @@ cmdreturn(struct LOC_exec *LINK) { if (loopbase == NULL) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_RETURN_WO_GOSUB; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_RETURN_WO_GOSUB; } errormsg("RETURN without GOSUB"); } @@ -4575,7 +4567,7 @@ cmdread(struct LOC_exec *LINK) v = findvar(LINK); tok = LINK->t; LINK->t = datatok; - if (PHREEQCI_GUI) + if (phreeqci_gui) { if (parse_whole_program) { @@ -4592,8 +4584,8 @@ cmdread(struct LOC_exec *LINK) { if (dataline == NULL || dataline->next == NULL) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_OUT_OF_DATA; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_OUT_OF_DATA; errormsg("Out of Data"); } dataline = dataline->next; @@ -4673,7 +4665,7 @@ cmdrestore(struct LOC_exec *LINK) else { dataline = mustfindline(intexpr(LINK)); - if (PHREEQCI_GUI) + if (phreeqci_gui) { if (parse_whole_program) { @@ -4746,10 +4738,10 @@ cmddim(struct LOC_exec *LINK) LINK->t = LINK->t->next; if (v->numdims != 0) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_ARRAY_ALREADY; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_ARRAY_ALREADY; } errormsg("Array already dimensioned before"); } @@ -4832,14 +4824,16 @@ exec(void) if (V.t != NULL) { V.t = V.t->next; - if (PHREEQCI_GUI) +#if defined(PHREEQCI_GUI) + if (phreeqci_gui) { - //if (WaitForSingleObject(s_hInfiniteLoop, 0) == WAIT_OBJECT_0) + if (WaitForSingleObject(hInfiniteLoop, 0) == WAIT_OBJECT_0) { - //g_nIDErrPrompt = IDS_ERR_INFINITE_LOOP; + nIDErrPrompt = IDS_ERR_INFINITE_LOOP; errormsg("Possible infinite loop"); } } +#endif switch (stmttok->kind) { @@ -4931,10 +4925,10 @@ exec(void) #endif case tokinput: - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_INPUT_NOTLEGAL; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_INPUT_NOTLEGAL; errormsg ("Basic command INPUT is not a legal command in PHREEQC."); } else @@ -5018,10 +5012,10 @@ exec(void) break; default: - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nIDErrPrompt == 0); - //g_nIDErrPrompt = IDS_ERR_ILLEGAL; + _ASSERTE(nIDErrPrompt == 0); + nIDErrPrompt = IDS_ERR_ILLEGAL; } errormsg("Illegal command"); break; @@ -5104,10 +5098,10 @@ exec(void) } if (stmtline != NULL) { - if (PHREEQCI_GUI) + if (phreeqci_gui) { - _ASSERTE(g_nErrLineNumber == 0); - g_nErrLineNumber = stmtline->num; + _ASSERTE(nErrLineNumber == 0); + nErrLineNumber = stmtline->num; } else { diff --git a/PBasic.h b/PBasic.h index 7663c562..28c8d423 100644 --- a/PBasic.h +++ b/PBasic.h @@ -1,5 +1,8 @@ #ifndef _INC_PBasic_H #define _INC_PBasic_H +#if defined(PHREEQCI_GUI) +#include +#endif #include #include #include @@ -293,13 +296,42 @@ public: tokgas_vm }; +#if !defined(PHREEQCI_GUI) + enum IDErr + { + IDS_ERR_ARRAY_ALREADY, + IDS_ERR_BAD_SUBSCRIPT, + IDS_ERR_EXTRA, + IDS_ERR_FOR_WO_NEXT, + IDS_ERR_ILLEGAL, + IDS_ERR_INFINITE_LOOP, + IDS_ERR_INPUT_NOTLEGAL, + IDS_ERR_MISMATCH, + IDS_ERR_MISSING_Q, + IDS_ERR_MISSING_RP, + IDS_ERR_NEXT_WO_FOR, + IDS_ERR_OUT_OF_DATA, + IDS_ERR_RETURN_WO_GOSUB, + IDS_ERR_SYNTAX, + IDS_ERR_UNDEF_LINE, + IDS_ERR_WEND_WO_WHILE, + IDS_ERR_WHILE_WO_WEND + }; +#endif + // Methods - bool Get_PHREEQCI_GUI(void) const {return PHREEQCI_GUI;}; - void Set_PHREEQCI_GUI(bool tf) {PHREEQCI_GUI = tf;}; - bool Get_pqi_parse(void) const {return pqi_parse;}; - void Set_pqi_parse(bool tf) {pqi_parse = tf;}; + bool Get_phreeqci_gui(void) const {return phreeqci_gui;}; + void Set_phreeqci_gui(bool tf) {phreeqci_gui = tf;}; + bool Get_parse_all(void) const {return parse_all;}; + void Set_parse_all(bool tf) {parse_all = tf;}; bool Get_parse_whole_program(void) const {return parse_whole_program;}; void Set_parse_whole_program(bool tf) {parse_whole_program = tf;}; + int Get_nErrLineNumber(void) const {return nErrLineNumber;}; + void Set_nErrLineNumber(int i) {nErrLineNumber = i;}; +#if defined(PHREEQCI_GUI) + HANDLE Get_hInfiniteLoop(void) const {return hInfiniteLoop;}; + void Set_hInfiniteLoop(HANDLE h) {hInfiniteLoop = h;}; +#endif int free_dim_stringvar(varrec *varbase); void exec(void); int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); @@ -448,12 +480,16 @@ protected: int P_escapecode; int P_ioresult; - bool PHREEQCI_GUI; - bool pqi_parse; /* true, most function values set to 1 for testing compilation */ + bool phreeqci_gui; + bool parse_all; /* true, most function values set to 1 for testing compilation */ bool parse_whole_program; - int s_hInfiniteLoop; - unsigned int g_nIDErrPrompt; - int g_nErrLineNumber; +#if defined(PHREEQCI_GUI) + HANDLE hInfiniteLoop; + UINT nIDErrPrompt; +#else + IDErr nIDErrPrompt; +#endif + int nErrLineNumber; }; #endif /* _INC_PBasic_H */ From 06ef90e5291bf92022f5a8d0705209557ca2f505 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 17 Nov 2011 06:31:13 +0000 Subject: [PATCH 0332/1077] initialize basic_interpreter git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5788 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index f5aa4c93..93e86f1a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -169,6 +169,7 @@ Phreeqc::Phreeqc(void) } // basic.c + basic_interpreter = NULL; //cl1.c x_arg = NULL, res_arg = NULL, scratch = NULL; From b160c3dacd8356eae0f8495288ae2c72fd4eeae3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 17 Nov 2011 18:03:42 +0000 Subject: [PATCH 0333/1077] Header file change git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5789 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 8489f6c6..28fc9540 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,7 +1,9 @@ -#if defined(PHREEQCI_GUI) +#if defined(WIN32) #include +#if defined(PHREEQCI_GUI) #include "resource.h" #endif +#endif #include #include "PBasic.h" #include "Phreeqc.h" From 5ec591a0b0759cad57deff7d66f6c4f04b387a97 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 21 Nov 2011 16:22:43 +0000 Subject: [PATCH 0334/1077] Update to VS2010. Update to latest phreeqcpp ErrorHandling. Partially fixed Boost/VS2010 bug. Still need fix for resize. Using _ITERATOR_DEBUG_LEVEL=0 for debug version for now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5793 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBasic.h b/PBasic.h index 28c8d423..52eac64f 100644 --- a/PBasic.h +++ b/PBasic.h @@ -14,7 +14,7 @@ #include "global_structures.h" class Phreeqc; -class PBasicStop : std::exception +class PBasicStop : public std::exception { }; From aa77b78d401afaf994353b0ca288bb3a345a7f83 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 21 Nov 2011 19:06:24 +0000 Subject: [PATCH 0335/1077] Tony's changes to gases. Merges Crapsi changes with his changes. Some new test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5797 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 7 +++++++ PBasic.h | 3 ++- Phreeqc.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 28fc9540..5dc689b2 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1476,6 +1476,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokgas_vm: output_msg("GAS_VM"); break; + case tokpressure: + output_msg("PRESSURE"); + break; } l_buf = l_buf->next; } @@ -3010,6 +3013,9 @@ factor(struct LOC_exec * LINK) case tokpr_p: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->pr_pressure(stringfactor(STR1, LINK)); break; + case tokpressure: + n.UU.val = PhreeqcPtr->pressure(); + break; case tokpr_phi: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->pr_phi(stringfactor(STR1, LINK)); break; @@ -6298,6 +6304,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("pr_phi", PBasic::tokpr_phi), std::map::value_type("gas_p", PBasic::tokgas_p), std::map::value_type("gas_vm", PBasic::tokgas_vm), + std::map::value_type("pressure", PBasic::tokpressure) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 52eac64f..1a3d3f76 100644 --- a/PBasic.h +++ b/PBasic.h @@ -293,7 +293,8 @@ public: tokpr_p, tokpr_phi, tokgas_p, - tokgas_vm + tokgas_vm, + tokpressure }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 9d73a068..c460cf3c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -97,6 +97,7 @@ public: LDBLE log_activity(const char *species_name); LDBLE log_molality(const char *species_name); LDBLE molality(const char *species_name); + LDBLE pressure(void); LDBLE pr_pressure(const char *phase_name); LDBLE pr_phi(const char *phase_name); LDBLE saturation_ratio(const char *phase_name); From c5a5c33df90342b8541bd0a851d18280fe4c2d56 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 21 Nov 2011 19:32:51 +0000 Subject: [PATCH 0336/1077] printing out pressure in examples. Linux changes for gases. Note: examples from previous version are being checked in.. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5798 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PBasic.cpp b/PBasic.cpp index 5dc689b2..9305d6a3 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3,6 +3,8 @@ #if defined(PHREEQCI_GUI) #include "resource.h" #endif +#else +#define _ASSERTE assert #endif #include #include "PBasic.h" @@ -740,6 +742,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) i++; break; } +#if defined(PHREEQCI_GUI) if (phreeqci_gui) { _ASSERTE(t->n_sz == 0); @@ -760,6 +763,7 @@ parse(char * l_inbuf, tokenrec ** l_buf) t->sz_num[0] = '\0'; } } +#endif i += (int) (ptr - &l_inbuf[i - 1]); } else @@ -3942,10 +3946,12 @@ cmdrenum(struct LOC_exec *LINK) } else { +#if defined(PHREEQC_GUI) if (phreeqci_gui) { _snprintf(tok->sz_num, tok->n_sz, "%ld", l1->num2); } +#endif tok->UU.num = l1->num2; } if (tok->next != NULL && tok->next->kind == tokcomma) From 14ef22ef1519680c062dfe558f4da816ea5b0b84 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 22 Nov 2011 23:19:52 +0000 Subject: [PATCH 0337/1077] reordered calls to calc_PR in prep.c. eliminated call in tidy.c. and step.c. eliminated call to k_temp in step.c. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5807 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index c460cf3c..2e0faf38 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -556,9 +556,11 @@ public: struct reaction **pe_rxn); LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); int setup_pure_phases(void); + int adjust_setup_pure_phases(void); int setup_related_surface(void); int setup_s_s_assemblage(void); int setup_solution(void); + int adjust_setup_solution(void); int setup_surface(void); int setup_unknowns(void); int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, From c552aab892fa33f8bbce952f7d754740cb0133b3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 23 Nov 2011 00:18:43 +0000 Subject: [PATCH 0338/1077] updated reading for istream cookies removed PFN_READ_CALLBACK git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5808 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 5 ++++- Phreeqc.h | 31 +++++++++++++++---------------- class_main.cpp | 16 ++++++++-------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 93e86f1a..45f34f2a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -832,6 +832,9 @@ void Phreeqc::init(void) B1TT = 0; B2TT = 0; + /* input.c */ + reading_db = FALSE; + /* integrate.c */ z = 0; xd = 0; @@ -968,7 +971,7 @@ void Phreeqc::init(void) #endif run_info.Set_io(phrq_io); - this->clear_cookie(); + this->clear_istream(); return; } diff --git a/Phreeqc.h b/Phreeqc.h index 2e0faf38..d8692c12 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -177,8 +177,8 @@ public: int close_input_files(void); int close_output_files(void); static int istream_getc(void *cookie); - int process_file_names(int argc, char *argv[], void **db_cookie, - void **input_cookie, int log); + int process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log); /* PHRQ_io_output.cpp */ void screen_msg(const char *err_str); @@ -245,7 +245,7 @@ public: // input.cpp ------------------------------- int reading_database(void); - struct read_callback s_read_callback; + void set_reading_database(int reading_database); int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); @@ -1315,10 +1315,10 @@ public: int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); - void *get_cookie(); - void pop_cookie(); - void set_cookie(std::istream * cookie); - void clear_cookie(void); + std::istream *get_istream(); + void pop_istream(); + void push_istream(std::istream * cookie); + void clear_istream(void); protected: void init(void); @@ -1326,7 +1326,7 @@ protected: //Data members // protected: - std::list cookie_list; + std::list istream_list; std::ifstream * in_stream; std::ifstream * db_stream; @@ -1880,15 +1880,14 @@ protected: /* input.cpp ------------------------------- */ int add_char_to_line(int *i, char c); - int check_line_impl(PFN_READ_CALLBACK pfn, void *cookie, const char *string, - int allow_empty, int allow_eof, int allow_keyword, - int print); - int get_line(PFN_READ_CALLBACK pfn, void *cookie); - int get_logical_line(PFN_READ_CALLBACK pfn, void *cookie, int *l); - int read_database(PFN_READ_CALLBACK pfn, void *cookie); - int run_simulations(PFN_READ_CALLBACK pfn, void *cookie); - int set_read_callback(PFN_READ_CALLBACK pfn, void *cookie, int database); + int check_line_impl(const char *string, int allow_empty, + int allow_eof, int allow_keyword, int print); + int get_line(void); + int get_logical_line(void *cookie, int *l); + int read_database(void); + int run_simulations(void); int check_line_return; + int reading_db; /* integrate.cpp ------------------------------- */ LDBLE midpoint_sv; diff --git a/class_main.cpp b/class_main.cpp index 928dcfcc..df6bd751 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -51,8 +51,8 @@ main_method(int argc, char *argv[]) { int errors; - void *db_cookie = NULL; - void *input_cookie = NULL; + std::istream *db_cookie = NULL; + std::istream *input_cookie = NULL; #if defined(WIN32_MEMORY_DEBUG) int tmpDbgFlag; @@ -95,9 +95,9 @@ main_method(int argc, char *argv[]) /* * Load database into memory */ - this->set_cookie((std::ifstream *) db_cookie); - errors = read_database(PHRQ_io::istream_getc, db_cookie); - this->clear_cookie(); + this->push_istream(db_cookie); + errors = read_database(); + this->clear_istream(); if (errors != 0) { @@ -109,9 +109,9 @@ main_method(int argc, char *argv[]) * Read input data for simulation */ - this->set_cookie((std::ifstream *)input_cookie); - errors = run_simulations(PHRQ_io::istream_getc, input_cookie); - this->clear_cookie(); + this->push_istream(input_cookie); + errors = run_simulations(); + this->clear_istream(); if (errors != 0) { From 03bc3d384807b39091c970ff5a8b98527ae322d8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 23 Nov 2011 20:58:42 +0000 Subject: [PATCH 0339/1077] Going to try checking cl1 results for inverse modeling. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5818 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index d8692c12..babd0dc5 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -278,6 +278,7 @@ public: struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); int post_mortem(void); + bool test_cl1_solution(void); unsigned long get_bits(unsigned long bits, int position, int number); unsigned long minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits); From 02119ae8dbca8c94d3fa78fe18bc3f8bfa9ee9e4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 28 Nov 2011 19:52:27 +0000 Subject: [PATCH 0340/1077] Fixed but for David Kinniburg. Trim example overflowed allowed space (256?). Modified factor to use std::strings to avoid overwrite. Made string pad const char argument. Assert in check_line was incorrect for EOF. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5826 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 159 ++++++++++++++++++++++++++++++++++------------------- PBasic.h | 2 +- Phreeqc.h | 2 +- 3 files changed, 103 insertions(+), 60 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 9305d6a3..bbea3236 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -452,7 +452,6 @@ clearvars(void) char * PBasic:: numtostr(char * Result, LDBLE n) { - /*string255 s; */ char *l_s; long i; @@ -1661,6 +1660,20 @@ stringfactor(char * Result, struct LOC_exec * LINK) return Result; } +const char * PBasic:: +stringfactor(std::string & Result, struct LOC_exec * LINK) +{ + valrec n; + + n = factor(LINK); + if (!n.stringval) + //tmerr(": chemical name is not enclosed in \" \"" ); + tmerr(": Expected quoted string or character variable." ); + Result = n.UU.sval; + PhreeqcPtr->PHRQ_free(n.UU.sval); + return Result.c_str(); +} + long PBasic:: intfactor(struct LOC_exec *LINK) { @@ -1849,15 +1862,17 @@ factor(struct LOC_exec * LINK) struct save_values s_v, *s_v_ptr; int k; LDBLE TEMP; - char STR1[256] = {0}, STR2[256] = {0}; - char *elt_name, *surface_name, *mytemplate, *name; + //char STR1[256] = {0}, STR2[256] = {0}; + std::string STR1, STR2; + const char *elt_name, *surface_name, *mytemplate, *name; varrec *count_varrec = NULL, *names_varrec = NULL, *types_varrec = NULL, *moles_varrec = NULL; char **names_arg, **types_arg; LDBLE *moles_arg; int arg_num; LDBLE count_species; - char *ptr, *string1, *string2; + const char *string1, *string2; + //char *ptr; if (LINK->t == NULL) snerr(": missing variable or command"); @@ -2047,21 +2062,21 @@ factor(struct LOC_exec * LINK) case tokact: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->activity(str); } break; case tokgamma: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->activity_coefficient(str); } break; case toklg: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_activity_coefficient(str); } break; @@ -2128,42 +2143,42 @@ factor(struct LOC_exec * LINK) case tokequi: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->equi_phase(str); } break; case tokkin: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->kinetics_moles(str); } break; case tokgas: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_gas_comp(str); } break; case toks_s: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_s_s_comp(str); } break; case tokmisc1: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_misc1(str); } break; case tokmisc2: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_misc2(str); } break; @@ -2189,21 +2204,21 @@ factor(struct LOC_exec * LINK) case toklk_species: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_s(str); } break; case toklk_named: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_n(str); } break; case toklk_phase: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_logk_p(str); } break; @@ -2310,14 +2325,16 @@ factor(struct LOC_exec * LINK) require(tokcomma, LINK); string2 = stringfactor(STR2, LINK); require(tokrp, LINK); - ptr = strstr(string1, string2); - if (ptr == NULL) { - n.UU.val = 0; - } - else - { - n.UU.val = ((LDBLE) (ptr - string1)) + 1; + const char * cptr = strstr(string1, string2); + if (cptr == NULL) + { + n.UU.val = 0; + } + else + { + n.UU.val = ((LDBLE) (cptr - string1)) + 1; + } } break; @@ -2326,8 +2343,10 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - PhreeqcPtr->string_trim_left(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); + //PhreeqcPtr->string_trim_left(string1); + trim_left(STR1); + //n.UU.sval = PhreeqcPtr->string_duplicate(string1); + n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; case tokrtrim: @@ -2335,8 +2354,10 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - PhreeqcPtr->string_trim_right(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); + //PhreeqcPtr->string_trim_right(string1); + //n.UU.sval = PhreeqcPtr->string_duplicate(string1); + trim_right(STR1); + n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; case toktrim: @@ -2344,13 +2365,15 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - PhreeqcPtr->string_trim(string1); - n.UU.sval = PhreeqcPtr->string_duplicate(string1); + //PhreeqcPtr->string_trim(string1); + //n.UU.sval = PhreeqcPtr->string_duplicate(string1); + trim(STR1); + n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; case tokiso: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->iso_value(str); } break; @@ -2360,8 +2383,10 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - PhreeqcPtr->string_trim(string1); - n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); + //PhreeqcPtr->string_trim(string1); + //n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); + trim(STR1); + n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(STR1.c_str()); break; case tokpad: @@ -2735,28 +2760,28 @@ factor(struct LOC_exec * LINK) case tokmol: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->molality(str); } break; case tokla: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_activity(str); } break; case toklm: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->log_molality(str); } break; case toksr: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->saturation_ratio(str); } break; @@ -2964,7 +2989,7 @@ factor(struct LOC_exec * LINK) case toksi: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); if (parse_all) { n.UU.val = 1; @@ -2978,7 +3003,7 @@ factor(struct LOC_exec * LINK) case toktot: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->total(str); } break; @@ -2987,7 +3012,7 @@ factor(struct LOC_exec * LINK) case toktotmol: case toktotmoles: { - char * str = stringfactor(STR1, LINK); + const char * str = stringfactor(STR1, LINK); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->total_mole(str); } break; @@ -3115,6 +3140,40 @@ factor(struct LOC_exec * LINK) PhreeqcPtr->PHRQ_free(l_s); break; +// case tokmid_: +// n.stringval = true; +// require(toklp, LINK); +// n.UU.sval = strexpr(LINK); +// require(tokcomma, LINK); +// i = intexpr(LINK); +// if (i < 1) +// i = 1; +// j = (int) strlen(n.UU.sval); +// if (LINK->t != NULL && LINK->t->kind == tokcomma) +// { +// LINK->t = LINK->t->next; +// j = intexpr(LINK); +// } +// if (j > (int) strlen(n.UU.sval) - i + 1) +// j = (int) strlen(n.UU.sval) - i + 1; +// if (i > (int) strlen(n.UU.sval)) +// *n.UU.sval = '\0'; +// else +// { +// if (j + 1 > 256) +// { +// warning_msg("String too long in factor\n"); +///* +// STR1 = (char *) PhreeqcPtr->PHRQ_realloc (STR1, j + 1); +// if (STR1 == NULL) +// PhreeqcPtr->malloc_error (); +//*/ +// } +// sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); +// strcpy(n.UU.sval, STR1); +// } +// require(tokrp, LINK); +// break; case tokmid_: n.stringval = true; require(toklp, LINK); @@ -3123,34 +3182,19 @@ factor(struct LOC_exec * LINK) i = intexpr(LINK); if (i < 1) i = 1; - /*j = 255; */ j = (int) strlen(n.UU.sval); if (LINK->t != NULL && LINK->t->kind == tokcomma) { LINK->t = LINK->t->next; j = intexpr(LINK); } - if (j > (int) strlen(n.UU.sval) - i + 1) - j = (int) strlen(n.UU.sval) - i + 1; - if (i > (int) strlen(n.UU.sval)) - *n.UU.sval = '\0'; - else { - if (j + 1 > 256) - { - warning_msg("String too long in factor\n"); -/* - STR1 = (char *) PhreeqcPtr->PHRQ_realloc (STR1, j + 1); - if (STR1 == NULL) - PhreeqcPtr->malloc_error (); -*/ - } - sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); - strcpy(n.UU.sval, STR1); + std::string str = n.UU.sval; + str = str.substr(i - 1, j); + strcpy(n.UU.sval, str.c_str()); } require(tokrp, LINK); break; - case toklen: l_s = strfactor(LINK); n.UU.val = (double) strlen(l_s); @@ -3661,7 +3705,6 @@ cmdrun(struct LOC_exec *LINK) { linerec *l; long i; - /*string255 s; */ char *l_s; l_s = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); diff --git a/PBasic.h b/PBasic.h index 1a3d3f76..7f59f14f 100644 --- a/PBasic.h +++ b/PBasic.h @@ -34,7 +34,6 @@ class PBasicStop : public std::exception #define Const typedef char varnamestring[varnamelen + 1]; -typedef char string255[256]; /* Header file for code generated by "p2c", the Pascal-to-C translator */ @@ -352,6 +351,7 @@ public: LDBLE realfactor(struct LOC_exec *LINK); char * strfactor(struct LOC_exec * LINK); char *stringfactor(char * Result, struct LOC_exec *LINK); + const char *stringfactor(std::string & Result, struct LOC_exec * LINK); long intfactor(struct LOC_exec *LINK); LDBLE realexpr(struct LOC_exec *LINK); char * strexpr(struct LOC_exec * LINK); diff --git a/Phreeqc.h b/Phreeqc.h index babd0dc5..fdc18346 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1295,7 +1295,7 @@ public: char *string_duplicate(const char *token); char *string_hsave(const char *str); protected: - char *string_pad(char *str, int i); + char *string_pad(const char *str, int i); int string_trim(char *str); int string_trim_right(char *str); int string_trim_left(char *str); From 041db9914430dedd9655f580e00ba4ee26f81cdd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Nov 2011 23:05:26 +0000 Subject: [PATCH 0341/1077] Removed keyword hash. Added enum for unique keywords, static map of phreeqc keywords, map of keyword names. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5832 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 299 +++++++++++++++++++++++++++++++++------------------- Phreeqc.h | 90 ++++++++++++++-- 2 files changed, 275 insertions(+), 114 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 45f34f2a..6bddcf1c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -68,104 +68,10 @@ Phreeqc::Phreeqc(void) iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; } - - struct const_key keyword_temp[] = { - {"eof", 0}, - {"end", 0}, - {"solution_species", 0}, - {"solution_master_species", 0}, - {"solution", 0}, - {"phases", 0}, - {"pure_phases", 0}, - {"reaction", 0}, - {"mix", 0}, - {"use", 0}, - {"save", 0}, - {"exchange_species", 0}, - {"exchange_master_species", 0}, - {"exchange", 0}, - {"surface_species", 0}, - {"surface_master_species", 0}, - {"surface", 0}, - {"reaction_temperature", 0}, - {"inverse_modeling", 0}, - {"gas_phase", 0}, - {"transport", 0}, - {"debug", 0}, - {"selected_output", 0}, - {"select_output", 0}, - {"knobs", 0}, - {"print", 0}, - {"equilibrium_phases", 0}, - {"equilibria", 0}, - {"equilibrium", 0}, - {"pure", 0}, - {"title", 0}, - {"comment", 0}, - {"advection", 0}, - {"kinetics", 0}, - {"incremental_reactions", 0}, - {"incremental", 0}, - {"rates", 0}, - {"solution_s", 0}, - {"user_print", 0}, - {"user_punch", 0}, - {"solid_solutions", 0}, - {"solid_solution", 0}, - {"solution_spread", 0}, - {"spread_solution", 0}, - {"selected_out", 0}, - {"select_out", 0}, - {"user_graph", 0}, - {"llnl_aqueous_model_parameters", 0}, - {"llnl_aqueous_model", 0}, - {"database", 0}, - {"named_analytical_expression", 0}, - {"named_analytical_expressions", 0}, - {"named_expressions", 0}, - {"named_log_k", 0}, - {"isotopes", 0}, - {"calculate_values", 0}, - {"isotope_ratios", 0}, - {"isotope_alphas", 0}, - {"copy", 0}, - {"pitzer", 0}, - {"sit", 0}, - {"equilibrium_phase", 0} - , - {"solution_raw", 0}, - {"exchange_raw", 0}, - {"surface_raw", 0}, - {"equilibrium_phases_raw", 0}, - {"kinetics_raw", 0}, - {"solid_solutions_raw", 0}, - {"gas_phase_raw", 0}, - {"reaction_raw", 0}, - {"mix_raw", 0}, - {"reaction_temperature_raw", 0}, - {"dump", 0}, - {"solution_modify", 0}, - {"equilibrium_phases_modify", 0}, - {"exchange_modify", 0}, - {"surface_modify", 0}, - {"solid_solutions_modify", 0}, - {"gas_phase_modify", 0}, - {"kinetics_modify", 0}, - {"delete", 0}, - {"run_cells", 0}, - {"reaction_modify", 0}, - {"reaction_temperature_modify", 0}, - {"solid_solution_modify", 0} - }; - NKEYS = (sizeof(keyword_temp) / sizeof(struct const_key)); /* Number of valid keywords */ - - - //keyword = (struct const_key *) PHRQ_malloc((size_t) (NKEYS * sizeof(const_key))); - keyword = new const_key[NKEYS]; - for (i = 0; i < NKEYS; i++) + // counters for enum KEYWORDS + for (i = 0; i < KEY_COUNT_KEYWORDS; i++) { - keyword[i].name = string_duplicate(keyword_temp[i].name); - keyword[i].keycount = 0; + keycount.push_back(0); } // basic.c @@ -238,11 +144,6 @@ Phreeqc::~Phreeqc(void) iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); } delete[] iso_defaults; - for (i = 0; i < NKEYS; i++) - { - keyword[i].name = (char *) free_check_null((void *) keyword[i].name); - } - delete[] keyword; free_check_null(default_data_base); free_check_null(sformatf_buffer); @@ -548,7 +449,6 @@ void Phreeqc::init(void) elements_hash_table = 0; species_hash_table = 0; phases_hash_table = 0; - keyword_hash_table = 0; /* * Initialize use pointers */ @@ -624,10 +524,6 @@ void Phreeqc::init(void) last_model.si = NULL; last_model.surface_comp = NULL; last_model.surface_charge = NULL; -/* - * Update hash table - */ - keyword_hash = 0; /* * rates */ @@ -976,4 +872,193 @@ void Phreeqc::init(void) return; } +Phreeqc::KEYWORDS Phreeqc::Keyword_search(std::string key) +{ + std::map::const_iterator it; + it = phreeqc_keywords.find(key); + if (it != Phreeqc::phreeqc_keywords.end()) + { + return it->second; + } + return Phreeqc::KEY_NONE; +} +const std::string & Phreeqc::Keyword_name_search(Phreeqc::KEYWORDS key) +{ + std::map::const_iterator it; + it = phreeqc_keyword_names.find(key); + if (it != Phreeqc::phreeqc_keyword_names.end()) + { + return it->second; + } + it = phreeqc_keyword_names.find(KEY_NONE); + return it->second; +} + +const std::map::value_type temp_keywords[] = { +std::map::value_type("eof", Phreeqc::KEY_END), +std::map::value_type("end", Phreeqc::KEY_END), +std::map::value_type("solution_species", Phreeqc::KEY_SOLUTION_SPECIES), +std::map::value_type("solution_master_species", Phreeqc::KEY_SOLUTION_MASTER_SPECIES), +std::map::value_type("solution", Phreeqc::KEY_SOLUTION), +std::map::value_type("phases", Phreeqc::KEY_PHASES), +std::map::value_type("pure_phases", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("reaction", Phreeqc::KEY_REACTION), +std::map::value_type("mix", Phreeqc::KEY_MIX), +std::map::value_type("use", Phreeqc::KEY_USE), +std::map::value_type("save", Phreeqc::KEY_SAVE), +std::map::value_type("exchange_species", Phreeqc::KEY_EXCHANGE_SPECIES), +std::map::value_type("exchange_master_species", Phreeqc::KEY_EXCHANGE_MASTER_SPECIES), +std::map::value_type("exchange", Phreeqc::KEY_EXCHANGE), +std::map::value_type("surface_species", Phreeqc::KEY_SURFACE_SPECIES), +std::map::value_type("surface_master_species", Phreeqc::KEY_SURFACE_MASTER_SPECIES), +std::map::value_type("surface", Phreeqc::KEY_SURFACE), +std::map::value_type("reaction_temperature", Phreeqc::KEY_REACTION_TEMPERATURE), +std::map::value_type("inverse_modeling", Phreeqc::KEY_INVERSE_MODELING), +std::map::value_type("gas_phase", Phreeqc::KEY_GAS_PHASE), +std::map::value_type("transport", Phreeqc::KEY_TRANSPORT), +std::map::value_type("debug", Phreeqc::KEY_KNOBS), +std::map::value_type("selected_output", Phreeqc::KEY_SELECTED_OUTPUT), +std::map::value_type("select_output", Phreeqc::KEY_SELECTED_OUTPUT), +std::map::value_type("knobs", Phreeqc::KEY_KNOBS), +std::map::value_type("print", Phreeqc::KEY_PRINT), +std::map::value_type("equilibrium_phases", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("equilibria", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("equilibrium", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("pure", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("title", Phreeqc::KEY_TITLE), +std::map::value_type("comment", Phreeqc::KEY_TITLE), +std::map::value_type("advection", Phreeqc::KEY_ADVECTION), +std::map::value_type("kinetics", Phreeqc::KEY_KINETICS), +std::map::value_type("incremental_reactions", Phreeqc::KEY_INCREMENTAL_REACTIONS), +std::map::value_type("incremental", Phreeqc::KEY_INCREMENTAL_REACTIONS), +std::map::value_type("rates", Phreeqc::KEY_RATES), +std::map::value_type("solution_s", Phreeqc::KEY_SOLUTION_SPREAD), +std::map::value_type("user_print", Phreeqc::KEY_USER_PRINT), +std::map::value_type("user_punch", Phreeqc::KEY_USER_PUNCH), +std::map::value_type("solid_solutions", Phreeqc::KEY_SOLID_SOLUTIONS), +std::map::value_type("solid_solution", Phreeqc::KEY_SOLID_SOLUTIONS), +std::map::value_type("solution_spread", Phreeqc::KEY_SOLUTION_SPREAD), +std::map::value_type("spread_solution", Phreeqc::KEY_SOLUTION_SPREAD), +std::map::value_type("selected_out", Phreeqc::KEY_SELECTED_OUTPUT), +std::map::value_type("select_out", Phreeqc::KEY_SELECTED_OUTPUT), +std::map::value_type("user_graph", Phreeqc::KEY_USER_GRAPH), +std::map::value_type("llnl_aqueous_model_parameters", Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), +std::map::value_type("llnl_aqueous_model", Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), +std::map::value_type("database", Phreeqc::KEY_DATABASE), +std::map::value_type("named_analytical_expression", Phreeqc::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_analytical_expressions", Phreeqc::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_expressions", Phreeqc::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_log_k", Phreeqc::KEY_NAMED_EXPRESSIONS), +std::map::value_type("isotopes", Phreeqc::KEY_ISOTOPES), +std::map::value_type("calculate_values", Phreeqc::KEY_CALCULATE_VALUES), +std::map::value_type("isotope_ratios", Phreeqc::KEY_ISOTOPE_RATIOS), +std::map::value_type("isotope_alphas", Phreeqc::KEY_ISOTOPE_ALPHAS), +std::map::value_type("copy", Phreeqc::KEY_COPY), +std::map::value_type("pitzer", Phreeqc::KEY_PITZER), +std::map::value_type("sit", Phreeqc::KEY_SIT), +std::map::value_type("equilibrium_phase", Phreeqc::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("solution_raw", Phreeqc::KEY_SOLUTION_RAW), +std::map::value_type("exchange_raw", Phreeqc::KEY_EXCHANGE_RAW), +std::map::value_type("surface_raw", Phreeqc::KEY_SURFACE_RAW), +std::map::value_type("equilibrium_phases_raw", Phreeqc::KEY_EQUILIBRIUM_PHASES_RAW), +std::map::value_type("kinetics_raw", Phreeqc::KEY_KINETICS_RAW), +std::map::value_type("solid_solutions_raw", Phreeqc::KEY_SOLID_SOLUTIONS_RAW), +std::map::value_type("gas_phase_raw", Phreeqc::KEY_GAS_PHASE_RAW), +std::map::value_type("reaction_raw", Phreeqc::KEY_REACTION_RAW), +std::map::value_type("mix_raw", Phreeqc::KEY_MIX_RAW), +std::map::value_type("reaction_temperature_raw", Phreeqc::KEY_REACTION_TEMPERATURE_RAW), +std::map::value_type("dump", Phreeqc::KEY_DUMP), +std::map::value_type("solution_modify", Phreeqc::KEY_SOLUTION_MODIFY), +std::map::value_type("equilibrium_phases_modify", Phreeqc::KEY_EQUILIBRIUM_PHASES_MODIFY), +std::map::value_type("exchange_modify", Phreeqc::KEY_EXCHANGE_MODIFY), +std::map::value_type("surface_modify", Phreeqc::KEY_SURFACE_MODIFY), +std::map::value_type("solid_solutions_modify", Phreeqc::KEY_SOLID_SOLUTIONS_MODIFY), +std::map::value_type("gas_phase_modify", Phreeqc::KEY_GAS_PHASE_MODIFY), +std::map::value_type("kinetics_modify", Phreeqc::KEY_KINETICS_MODIFY), +std::map::value_type("delete", Phreeqc::KEY_DELETE), +std::map::value_type("run_cells", Phreeqc::KEY_RUN_CELLS), +std::map::value_type("reaction_modify", Phreeqc::KEY_REACTION_MODIFY), +std::map::value_type("reaction_temperature_modify", Phreeqc::KEY_REACTION_TEMPERATURE_MODIFY), +std::map::value_type("solid_solution_modify", Phreeqc::KEY_SOLID_SOLUTION_MODIFY), +std::map::value_type("reaction_pressure", Phreeqc::KEY_REACTION_PRESSURE), +std::map::value_type("reaction_pressures", Phreeqc::KEY_REACTION_PRESSURE), +std::map::value_type("reaction_pressure_raw", Phreeqc::KEY_REACTION_PRESSURE_RAW), +std::map::value_type("reaction_pressure_modify", Phreeqc::KEY_REACTION_PRESSURE_MODIFY) + +}; +std::map Phreeqc::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); + +const std::map::value_type temp_keyword_names[] = { +std::map::value_type(Phreeqc::KEY_NONE, "UNKNOWN"), +std::map::value_type(Phreeqc::KEY_END, "END"), +std::map::value_type(Phreeqc::KEY_SOLUTION_SPECIES, "SOLUTION_SPECIES"), +std::map::value_type(Phreeqc::KEY_SOLUTION_MASTER_SPECIES, "SOLUTION_MASTER_SPECIES"), +std::map::value_type(Phreeqc::KEY_SOLUTION, "SOLUTION"), +std::map::value_type(Phreeqc::KEY_PHASES, "PHASES"), +std::map::value_type(Phreeqc::KEY_REACTION, "REACTION"), +std::map::value_type(Phreeqc::KEY_MIX, "MIX"), +std::map::value_type(Phreeqc::KEY_USE, "USE"), +std::map::value_type(Phreeqc::KEY_SAVE, "SAVE"), +std::map::value_type(Phreeqc::KEY_EXCHANGE_SPECIES, "EXCHANGE_SPECIES"), +std::map::value_type(Phreeqc::KEY_EXCHANGE_MASTER_SPECIES, "EXCHANGE_MASTER_SPECIES"), +std::map::value_type(Phreeqc::KEY_EXCHANGE, "EXCHANGE"), +std::map::value_type(Phreeqc::KEY_SURFACE_SPECIES, "SURFACE_SPECIES"), +std::map::value_type(Phreeqc::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"), +std::map::value_type(Phreeqc::KEY_SURFACE, "SURFACE"), +std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE, "REACTION_TEMPERATURE"), +std::map::value_type(Phreeqc::KEY_INVERSE_MODELING, "INVERSE_MODELING"), +std::map::value_type(Phreeqc::KEY_GAS_PHASE, "GAS_PHASE"), +std::map::value_type(Phreeqc::KEY_TRANSPORT, "TRANSPORT"), +std::map::value_type(Phreeqc::KEY_SELECTED_OUTPUT, "SELECTED_OUTPUT"), +std::map::value_type(Phreeqc::KEY_KNOBS, "KNOBS"), +std::map::value_type(Phreeqc::KEY_PRINT, "PRINT"), +std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"), +std::map::value_type(Phreeqc::KEY_TITLE, "TITLE"), +std::map::value_type(Phreeqc::KEY_ADVECTION, "ADVECTION"), +std::map::value_type(Phreeqc::KEY_KINETICS, "KINETICS"), +std::map::value_type(Phreeqc::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"), +std::map::value_type(Phreeqc::KEY_RATES, "RATES"), +std::map::value_type(Phreeqc::KEY_USER_PRINT, "USER_PRINT"), +std::map::value_type(Phreeqc::KEY_USER_PUNCH, "USER_PUNCH"), +std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS, "SOLID_SOLUTIONS"), +std::map::value_type(Phreeqc::KEY_SOLUTION_SPREAD, "SOLUTION_SPREAD"), +std::map::value_type(Phreeqc::KEY_USER_GRAPH, "USER_GRAPH"), +std::map::value_type(Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, "LLNL_AQUEOUS_MODEL_PARAMETERS"), +std::map::value_type(Phreeqc::KEY_DATABASE, "DATABASE"), +std::map::value_type(Phreeqc::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"), +std::map::value_type(Phreeqc::KEY_ISOTOPES, "ISOTOPES"), +std::map::value_type(Phreeqc::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"), +std::map::value_type(Phreeqc::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"), +std::map::value_type(Phreeqc::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"), +std::map::value_type(Phreeqc::KEY_COPY, "COPY"), +std::map::value_type(Phreeqc::KEY_PITZER, "PITZER"), +std::map::value_type(Phreeqc::KEY_SIT, "SIT"), +std::map::value_type(Phreeqc::KEY_SOLUTION_RAW, "SOLUTION_RAW"), +std::map::value_type(Phreeqc::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"), +std::map::value_type(Phreeqc::KEY_SURFACE_RAW, "SURFACE_RAW"), +std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"), +std::map::value_type(Phreeqc::KEY_KINETICS_RAW, "KINETICS_RAW"), +std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"), +std::map::value_type(Phreeqc::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"), +std::map::value_type(Phreeqc::KEY_REACTION_RAW, "REACTION_RAW"), +std::map::value_type(Phreeqc::KEY_MIX_RAW, "MIX_RAW"), +std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"), +std::map::value_type(Phreeqc::KEY_DUMP, "DUMP"), +std::map::value_type(Phreeqc::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"), +std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"), +std::map::value_type(Phreeqc::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"), +std::map::value_type(Phreeqc::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"), +std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"), +std::map::value_type(Phreeqc::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"), +std::map::value_type(Phreeqc::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"), +std::map::value_type(Phreeqc::KEY_DELETE, "DELETE"), +std::map::value_type(Phreeqc::KEY_RUN_CELLS, "RUN_CELLS"), +std::map::value_type(Phreeqc::KEY_REACTION_MODIFY, "REACTION_MODIFY"), +std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), +std::map::value_type(Phreeqc::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), +std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), +std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), +std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") +}; +std::map Phreeqc::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index fdc18346..8c3aa4cc 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -58,10 +58,86 @@ public: Phreeqc(void); ~Phreeqc(void); + enum KEYWORDS + { + KEY_NONE, + KEY_END, + KEY_SOLUTION_SPECIES, + KEY_SOLUTION_MASTER_SPECIES, + KEY_SOLUTION, + KEY_PHASES, + KEY_REACTION, + KEY_MIX, + KEY_USE, + KEY_SAVE, + KEY_EXCHANGE_SPECIES, + KEY_EXCHANGE_MASTER_SPECIES, + KEY_EXCHANGE, + KEY_SURFACE_SPECIES, + KEY_SURFACE_MASTER_SPECIES, + KEY_SURFACE, + KEY_REACTION_TEMPERATURE, + KEY_INVERSE_MODELING, + KEY_GAS_PHASE, + KEY_TRANSPORT, + KEY_SELECTED_OUTPUT, + KEY_KNOBS, + KEY_PRINT, + KEY_EQUILIBRIUM_PHASES, + KEY_TITLE, + KEY_ADVECTION, + KEY_KINETICS, + KEY_INCREMENTAL_REACTIONS, + KEY_RATES, + KEY_USER_PRINT, + KEY_USER_PUNCH, + KEY_SOLID_SOLUTIONS, + KEY_SOLUTION_SPREAD, + KEY_USER_GRAPH, + KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, + KEY_DATABASE, + KEY_NAMED_EXPRESSIONS, + KEY_ISOTOPES, + KEY_CALCULATE_VALUES, + KEY_ISOTOPE_RATIOS, + KEY_ISOTOPE_ALPHAS, + KEY_COPY, + KEY_PITZER, + KEY_SIT, + KEY_SOLUTION_RAW, + KEY_EXCHANGE_RAW, + KEY_SURFACE_RAW, + KEY_EQUILIBRIUM_PHASES_RAW, + KEY_KINETICS_RAW, + KEY_SOLID_SOLUTIONS_RAW, + KEY_GAS_PHASE_RAW, + KEY_REACTION_RAW, + KEY_MIX_RAW, + KEY_REACTION_TEMPERATURE_RAW, + KEY_DUMP, + KEY_SOLUTION_MODIFY, + KEY_EQUILIBRIUM_PHASES_MODIFY, + KEY_EXCHANGE_MODIFY, + KEY_SURFACE_MODIFY, + KEY_SOLID_SOLUTIONS_MODIFY, + KEY_GAS_PHASE_MODIFY, + KEY_KINETICS_MODIFY, + KEY_DELETE, + KEY_RUN_CELLS, + KEY_REACTION_MODIFY, + KEY_REACTION_TEMPERATURE_MODIFY, + KEY_SOLID_SOLUTION_MODIFY, + KEY_REACTION_PRESSURE, + KEY_REACTION_PRESSURE_RAW, + KEY_REACTION_PRESSURE_MODIFY, + KEY_COUNT_KEYWORDS // must be last in list + }; public: // // Phreeqc class methods // + static Phreeqc::KEYWORDS Keyword_search(std::string key); + static const std::string & Phreeqc::Keyword_name_search(Phreeqc::KEYWORDS key); // advection.cpp ------------------------------- int advection(void); @@ -1581,16 +1657,13 @@ protected: int advection_warnings; /*---------------------------------------------------------------------- - * Keywords + * Tidy data *---------------------------------------------------------------------- */ - struct const_key *keyword; - int NKEYS; - - struct key *keyword_hash; int new_model, new_exchange, new_pp_assemblage, new_surface, new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, new_pitzer; + /*---------------------------------------------------------------------- * Elements *---------------------------------------------------------------------- */ @@ -1747,7 +1820,7 @@ protected: int input_error; - int next_keyword; + KEYWORDS next_keyword; int parse_error; int paren_count; int iterations; @@ -1808,7 +1881,6 @@ protected: HashTable *elements_hash_table; HashTable *species_hash_table; HashTable *phases_hash_table; - HashTable *keyword_hash_table; HashTable *logk_hash_table; HashTable *master_isotope_hash_table; @@ -2068,6 +2140,10 @@ public: friend class PBasic; friend class ChartObject; + std::vector keycount; // used to mark keywords that have been read + static std::map phreeqc_keywords; + static std::map phreeqc_keyword_names; + #endif /* _INC_PHREEQC_H */ /********************************* From 584b79bd5d6074ab0a02aaa04e4bc61fce3c2016 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Nov 2011 16:50:52 +0000 Subject: [PATCH 0342/1077] roughed in cxxPressure class. A lot more to do. Added screen_msg and echo_msg to PHRQ_base. Added screen_msg and echo_msg to PHRQ_io Added enum to direct echo to log or output. Switched back to 3 digit exponent in mainsubs.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5833 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 26 ++++ PHRQ_base.h | 3 + PHRQ_io.cpp | 31 +++++ PHRQ_io.h | 20 +++ Phreeqc.h | 10 +- Pressure.cxx | 351 ++++++++++++++++++++++++++++++++++++++++++++++++++ Pressure.h | 40 ++++++ 7 files changed, 480 insertions(+), 1 deletion(-) create mode 100644 Pressure.cxx create mode 100644 Pressure.h diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 71dc39ce..0c62e6e0 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -70,3 +70,29 @@ output_msg(const std::string & stdstr) std::cout << stdstr << std::endl; } } + +void PHRQ_base:: +screen_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->screen_msg(stdstr.c_str()); + } + else + { + std::cerr << stdstr << std::endl; + } +} + +void PHRQ_base:: +echo_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->echo_msg(stdstr.c_str()); + } + else + { + std::cout << stdstr << std::endl; + } +} \ No newline at end of file diff --git a/PHRQ_base.h b/PHRQ_base.h index c4c92ec8..4750cb13 100644 --- a/PHRQ_base.h +++ b/PHRQ_base.h @@ -17,6 +17,9 @@ public: void output_msg(const std::string &); void error_msg(const std::string &, int stop=0); void warning_msg(const std::string &); + void screen_msg(const std::string &); + void echo_msg(const std::string &); + void Set_io(PHRQ_io * p_io) { diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 40554089..ee3c5cb6 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -22,6 +22,9 @@ PHRQ_io(void) punch_file_on = true; error_file_on = true; dump_file_on = true; + screen_on = true; + echo_on = true; + echo_destination = ECHO_OUTPUT; } PHRQ_io:: @@ -562,3 +565,31 @@ safe_close(FILE ** file_ptr) } } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (screen_on) + { + fprintf(stderr, "%s", str); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +echo_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (echo_on) + { + switch (this->echo_destination) + { + case ECHO_LOG: + log_msg(str); + break; + case ECHO_OUTPUT: + output_msg(str); + break; + } + } +} \ No newline at end of file diff --git a/PHRQ_io.h b/PHRQ_io.h index 9f07a889..75c21a0b 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -90,6 +90,22 @@ public: bool Get_error_file_on(void) {return this->error_file_on;}; bool Get_dump_file_on(void) {return this->dump_file_on;}; + void screen_msg(const char * str); + void Set_screen_on(bool tf) {this->screen_on = tf;}; + bool Get_screen_on(void) {return this->screen_on;}; + + enum ECHO_OPTION + { + ECHO_LOG, + ECHO_OUTPUT + }; + void echo_msg(const char * str); + void Set_echo_on(bool tf) {this->echo_on = tf;}; + bool Get_echo_on(void) {return this->echo_on;}; + void Set_echo_destination(ECHO_OPTION eo) {this->echo_destination = eo;}; + ECHO_OPTION Get_echo_destination(void) {return this->echo_destination;}; + + // data protected: FILE *input_file; @@ -106,6 +122,10 @@ protected: bool punch_file_on; bool error_file_on; bool dump_file_on; + bool echo_on; + bool screen_on; + ECHO_OPTION echo_destination; + }; #endif /* _PHRQIO_H */ diff --git a/Phreeqc.h b/Phreeqc.h index 8c3aa4cc..e26d0bd2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -37,6 +37,7 @@ class cxxExchange; class cxxExchComp; class cxxGasPhase; class cxxTemperature; +class cxxPressure; class cxxPPassemblage; class cxxPPassemblageComp; class cxxReaction; @@ -767,6 +768,7 @@ public: int read_reaction_steps(struct irrev *irrev_ptr); int read_solid_solutions(void); int read_temperature(void); + int read_reaction_pressure(void); int read_reaction_temps(struct temperature *temperature_ptr); int read_save(void); int read_selected_output(void); @@ -1388,7 +1390,7 @@ protected: Address Hash_multi(HashTable * Table, char *Key); void ExpandTable_multi(HashTable * Table); public: - bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); + //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); @@ -1424,6 +1426,12 @@ protected: struct temperature *temperature; int count_temperature; + + /* ---------------------------------------------------------------------- + * Pressures + * ---------------------------------------------------------------------- */ + std::map Reaction_pressure_map; + /* ---------------------------------------------------------------------- * Surface * --------------------------------------------------------------------- */ diff --git a/Pressure.cxx b/Pressure.cxx new file mode 100644 index 00000000..8971e0ff --- /dev/null +++ b/Pressure.cxx @@ -0,0 +1,351 @@ +// Pressure.cxx: implementation of the cxxPressure class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include // assert +#include // std::sort + +#include "Utils.h" // define first +#include "Parser.h" +#include "Phreeqc.h" +#include "Pressure.h" +#include "phqalloc.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxPressure::cxxPressure(PHRQ_io *io) + // + // default constructor for cxxPressure + // +: cxxNumKeyword(io) +{ + count = 0; + equalIncrements = false; + pressures.push_back(1.0); +} + +cxxPressure::~cxxPressure() +{ +} +void +cxxPressure::read(CParser & parser) +{ + double d; + CParser::TOKEN_TYPE k; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(5); + vopts.push_back("pressures"); //0 + vopts.push_back("equal_increments"); //1 + vopts.push_back("count"); //2 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read reaction_pressure number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool equalIncrements_defined(false); + bool count_defined(false); + + 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 REACTION_PRESSURE_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // pressures + while ((k = + parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + { + std::istringstream iss(token); + if (!(iss >> d)) + { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pressures.", + CParser::OT_CONTINUE); + } + else + { + this->pressures.push_back(d); + } + } + opt_save = 0; + useLastLine = false; + break; + + case 1: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; + + case 2: // count + if (!(parser.get_iss() >> this->count)) + { + this->count = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for count.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + count_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", + CParser::OT_CONTINUE); + } + if (count_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", + CParser::OT_CONTINUE); + } +} + +void +cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const +{ + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + s_oss << indent0; + int n_user_local = (n_out != NULL) ? *n_out : this->n_user; + s_oss << "REACTION_PRESSURE_RAW " << n_user_local << " " << this->description << std::endl; + + s_oss << indent1; + s_oss << "-count " << this->count << std::endl; + + s_oss << indent1; + s_oss << "-equal_increments " << this->equalIncrements << std::endl; + + // Temperature element and attributes + + s_oss << indent1; + s_oss << "-pressures " << std::endl; + { + int i = 0; + s_oss << indent2; + for (std::vector < double >::const_iterator it = this->pressures.begin(); + it != this->pressures.end(); it++) + { + if (i++ == 5) + { + s_oss << std::endl; + s_oss << indent2; + i = 0; + } + s_oss << *it << " "; + } + s_oss << std::endl; + } +} + +void +cxxPressure::read_raw(CParser & parser) +{ + double d; + CParser::TOKEN_TYPE k; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(5); + vopts.push_back("pressures"); //0 + vopts.push_back("equal_increments"); //1 + vopts.push_back("count"); //2 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read reaction_pressure number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool equalIncrements_defined(false); + bool count_defined(false); + + 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 REACTION_PRESSURE_RAW keyword.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + break; + + case 0: // pressures + while ((k = + parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + { + std::istringstream iss(token); + if (!(iss >> d)) + { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pressures.", + CParser::OT_CONTINUE); + } + else + { + this->pressures.push_back(d); + } + } + opt_save = 0; + useLastLine = false; + break; + + case 1: // equal_increments + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->equalIncrements = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + equalIncrements_defined = true; + break; + + case 2: // count + if (!(parser.get_iss() >> this->count)) + { + this->count = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for count.", CParser::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + useLastLine = false; + count_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", + CParser::OT_CONTINUE); + } + if (count_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", + CParser::OT_CONTINUE); + } +} +#ifdef SKIP +void +cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const +{ + //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + // Temperature element and attributes + s_oss << indent0; + s_oss << " + pitzer_temperature_gammas << "\"" << std::endl; + + // components + s_oss << indent1; + s_oss << "::const_iterator it = + temperatureComps.begin(); it != temperatureComps.end(); ++it) + { + it->dump_xml(s_oss, indent + 2); + } + + return; +} +#endif \ No newline at end of file diff --git a/Pressure.h b/Pressure.h new file mode 100644 index 00000000..7adeb51a --- /dev/null +++ b/Pressure.h @@ -0,0 +1,40 @@ +#if !defined(PRESSURE_H_INCLUDED) +#define PRESSURE_H_INCLUDED + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "NumKeyword.h" + +class cxxPressure:public cxxNumKeyword +{ + + public: + cxxPressure(PHRQ_io *io=NULL); + cxxPressure(struct temperature *, PHRQ_io *io=NULL); + ~cxxPressure(); + + //void dump_xml(std::ostream& os, unsigned int indent = 0)const; + + void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; + + void read(CParser & parser); + void read_raw(CParser & parser); + + std::vector & Get_pressures(void) {return pressures;}; + int Get_count(void) const {return count;}; + void Set_count(int i) {count = i;}; + bool Get_equalIncrements(void) const {return equalIncrements;}; + void Set_equalIncrements(bool tf) {equalIncrements = tf;}; + +protected: + std::vector < double >pressures; + int count; + bool equalIncrements; + +}; + +#endif // !defined(PRESSURE_H_INCLUDED) From 17a4c8442d07bec5e1a90b7b2b319ee2a524cd4a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Nov 2011 18:30:51 +0000 Subject: [PATCH 0343/1077] Moved keywords to separate class git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5835 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 103 +++++++++++++------------- Parser.h | 49 +++++++------ Phreeqc.cpp | 192 +------------------------------------------------ Phreeqc.h | 80 +-------------------- StorageBin.cxx | 69 +++++++++++------- 5 files changed, 127 insertions(+), 366 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index ed6a7ea0..664d3e3c 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -12,8 +12,8 @@ #include // std::cout std::cerr #include "Utils.h" #include -#include "Phreeqc.h" #include "Parser.h" +#include "Phreeqc.h" #include "PHRQ_io.h" ////////////////////////////////////////////////////////////////////// @@ -26,7 +26,7 @@ m_input_stream(input), m_output_stream(std::cout), m_error_stream(std::cerr), m_input_error(0), -m_next_keyword(KT_NONE) +m_next_keyword(Keywords::KEY_NONE) { m_line_save.reserve(80); m_line.reserve(80); @@ -42,7 +42,7 @@ m_input_stream(input), m_output_stream(output), m_error_stream(std::cerr), m_input_error(0), -m_next_keyword(KT_NONE) +m_next_keyword(Keywords::KEY_NONE) { m_line_save.reserve(80); m_line.reserve(80); @@ -58,7 +58,7 @@ m_input_stream(input), m_output_stream(output), m_error_stream(error), m_input_error(0), -m_next_keyword(KT_NONE) +m_next_keyword(Keywords::KEY_NONE) { m_line_save.reserve(80); m_line.reserve(80); @@ -127,7 +127,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->output_msg(msg.str()); + this->echo_msg(msg.str()); } break; case EO_KEYWORDS: @@ -135,7 +135,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->output_msg(msg.str()); + this->echo_msg(msg.str()); } break; @@ -144,7 +144,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - this->output_msg(msg.str().c_str()); + this->echo_msg(msg.str().c_str()); } break; } @@ -197,7 +197,7 @@ CParser::LINE_TYPE CParser::get_line() //{{MOD m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); //}}MOD - m_next_keyword = KT_EOF; + m_next_keyword = Keywords::KEY_END; return LT_EOF; } } @@ -341,54 +341,59 @@ CParser::LINE_TYPE CParser::get_logical_line() bool CParser::check_key(std::string::iterator begin, std::string::iterator end) { - static std::map < std::string, KEY_TYPE > s_keyword_map; - if (s_keyword_map.size() == 0) - { - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("solution_raw", - KT_SOLUTION_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("exchange_raw", - KT_EXCHANGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("gas_phase_raw", - KT_GASPHASE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("kinetics_raw", - KT_KINETICS_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("equilibrium_phases_raw", - KT_PPASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("solid_solutions_raw", - KT_SSASSEMBLAGE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("surface_raw", - KT_SURFACE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("reaction_temperature_raw", - KT_TEMPERATURE_RAW)); - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("reaction_raw", - KT_REACTION_RAW)); -#if defined MULTICHART - s_keyword_map.insert(std::map < std::string, - KEY_TYPE >::value_type("user_graph", - KT_USER_GRAPH)); -#endif - } +// static std::map < std::string, KEY_TYPE > s_keyword_map; +// if (s_keyword_map.size() == 0) +// { +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("solution_raw", +// KT_SOLUTION_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("exchange_raw", +// KT_EXCHANGE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("gas_phase_raw", +// KT_GASPHASE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("kinetics_raw", +// KT_KINETICS_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("equilibrium_phases_raw", +// KT_PPASSEMBLAGE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("solid_solutions_raw", +// KT_SSASSEMBLAGE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("surface_raw", +// KT_SURFACE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("reaction_temperature_raw", +// KT_TEMPERATURE_RAW)); +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("reaction_raw", +// KT_REACTION_RAW)); +//#if defined MULTICHART +// s_keyword_map.insert(std::map < std::string, +// KEY_TYPE >::value_type("user_graph", +// KT_USER_GRAPH)); +//#endif +// } std::string lowercase; copy_token(lowercase, begin, end); std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); - m_next_keyword = KT_NONE; - std::map < std::string, KEY_TYPE >::iterator map_iter = - s_keyword_map.find(lowercase); - if (map_iter == s_keyword_map.end()) + //m_next_keyword = Keywords::KEY_NONE; + //std::map < std::string, KEY_TYPE >::iterator map_iter = + // s_keyword_map.find(lowercase); + //if (map_iter == s_keyword_map.end()) + // return false; + //m_next_keyword = (*map_iter).second; + m_next_keyword = Keywords::Keyword_search(lowercase); + if (m_next_keyword == Keywords::KEY_NONE) + { return false; - m_next_keyword = (*map_iter).second; + } return true; } diff --git a/Parser.h b/Parser.h index 7b0cd924..016bd2da 100644 --- a/Parser.h +++ b/Parser.h @@ -1,5 +1,8 @@ #if !defined(PARSER_H_INCLUDED) #define PARSER_H_INCLUDED +#if defined(WIN32) +#include +#endif #include // std::string #include // std::map @@ -8,6 +11,8 @@ #include // std::ostream #include // std::istream #include "PHRQ_base.h" +#include "Keywords.h" + class CParser: public PHRQ_base { @@ -43,25 +48,25 @@ class CParser: public PHRQ_base FT_ERROR = 1 }; - enum KEY_TYPE - { - KT_NONE = -1, - KT_END = 0, - KT_EOF = 1, - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11, - KT_TEMPERATURE_RAW = 12, - KT_REACTION_RAW = 13, - KT_MIX_RAW = 14 -#if defined MULTICHART - , KT_USER_GRAPH = 15 -#endif - }; +// enum KEY_TYPE +// { +// KT_NONE = -1, +// KT_END = 0, +// KT_EOF = 1, +// KT_SOLUTION_RAW = 5, +// KT_EXCHANGE_RAW = 6, +// KT_GASPHASE_RAW = 7, +// KT_KINETICS_RAW = 8, +// KT_PPASSEMBLAGE_RAW = 9, +// KT_SSASSEMBLAGE_RAW = 10, +// KT_SURFACE_RAW = 11, +// KT_TEMPERATURE_RAW = 12, +// KT_REACTION_RAW = 13, +// KT_MIX_RAW = 14 +//#if defined MULTICHART +// , KT_USER_GRAPH = 15 +//#endif +// }; enum OPT_TYPE { @@ -138,7 +143,8 @@ class CParser: public PHRQ_base const std::string & default_units, bool print); - KEY_TYPE next_keyword() const + //KEY_TYPE next_keyword() const + Keywords::KEYWORDS next_keyword() const { return m_next_keyword; } @@ -291,7 +297,8 @@ class CParser: public PHRQ_base std::ostream & m_output_stream; std::ostream & m_error_stream; int m_input_error; - KEY_TYPE m_next_keyword; + //KEY_TYPE m_next_keyword; + Keywords::KEYWORDS m_next_keyword; std::string m_line; std::string m_line_save; std::istringstream m_line_iss; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6bddcf1c..d38407f8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -69,7 +69,7 @@ Phreeqc::Phreeqc(void) } // counters for enum KEYWORDS - for (i = 0; i < KEY_COUNT_KEYWORDS; i++) + for (i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) { keycount.push_back(0); } @@ -872,193 +872,3 @@ void Phreeqc::init(void) return; } -Phreeqc::KEYWORDS Phreeqc::Keyword_search(std::string key) -{ - std::map::const_iterator it; - it = phreeqc_keywords.find(key); - if (it != Phreeqc::phreeqc_keywords.end()) - { - return it->second; - } - return Phreeqc::KEY_NONE; -} - -const std::string & Phreeqc::Keyword_name_search(Phreeqc::KEYWORDS key) -{ - std::map::const_iterator it; - it = phreeqc_keyword_names.find(key); - if (it != Phreeqc::phreeqc_keyword_names.end()) - { - return it->second; - } - it = phreeqc_keyword_names.find(KEY_NONE); - return it->second; -} - -const std::map::value_type temp_keywords[] = { -std::map::value_type("eof", Phreeqc::KEY_END), -std::map::value_type("end", Phreeqc::KEY_END), -std::map::value_type("solution_species", Phreeqc::KEY_SOLUTION_SPECIES), -std::map::value_type("solution_master_species", Phreeqc::KEY_SOLUTION_MASTER_SPECIES), -std::map::value_type("solution", Phreeqc::KEY_SOLUTION), -std::map::value_type("phases", Phreeqc::KEY_PHASES), -std::map::value_type("pure_phases", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("reaction", Phreeqc::KEY_REACTION), -std::map::value_type("mix", Phreeqc::KEY_MIX), -std::map::value_type("use", Phreeqc::KEY_USE), -std::map::value_type("save", Phreeqc::KEY_SAVE), -std::map::value_type("exchange_species", Phreeqc::KEY_EXCHANGE_SPECIES), -std::map::value_type("exchange_master_species", Phreeqc::KEY_EXCHANGE_MASTER_SPECIES), -std::map::value_type("exchange", Phreeqc::KEY_EXCHANGE), -std::map::value_type("surface_species", Phreeqc::KEY_SURFACE_SPECIES), -std::map::value_type("surface_master_species", Phreeqc::KEY_SURFACE_MASTER_SPECIES), -std::map::value_type("surface", Phreeqc::KEY_SURFACE), -std::map::value_type("reaction_temperature", Phreeqc::KEY_REACTION_TEMPERATURE), -std::map::value_type("inverse_modeling", Phreeqc::KEY_INVERSE_MODELING), -std::map::value_type("gas_phase", Phreeqc::KEY_GAS_PHASE), -std::map::value_type("transport", Phreeqc::KEY_TRANSPORT), -std::map::value_type("debug", Phreeqc::KEY_KNOBS), -std::map::value_type("selected_output", Phreeqc::KEY_SELECTED_OUTPUT), -std::map::value_type("select_output", Phreeqc::KEY_SELECTED_OUTPUT), -std::map::value_type("knobs", Phreeqc::KEY_KNOBS), -std::map::value_type("print", Phreeqc::KEY_PRINT), -std::map::value_type("equilibrium_phases", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("equilibria", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("equilibrium", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("pure", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("title", Phreeqc::KEY_TITLE), -std::map::value_type("comment", Phreeqc::KEY_TITLE), -std::map::value_type("advection", Phreeqc::KEY_ADVECTION), -std::map::value_type("kinetics", Phreeqc::KEY_KINETICS), -std::map::value_type("incremental_reactions", Phreeqc::KEY_INCREMENTAL_REACTIONS), -std::map::value_type("incremental", Phreeqc::KEY_INCREMENTAL_REACTIONS), -std::map::value_type("rates", Phreeqc::KEY_RATES), -std::map::value_type("solution_s", Phreeqc::KEY_SOLUTION_SPREAD), -std::map::value_type("user_print", Phreeqc::KEY_USER_PRINT), -std::map::value_type("user_punch", Phreeqc::KEY_USER_PUNCH), -std::map::value_type("solid_solutions", Phreeqc::KEY_SOLID_SOLUTIONS), -std::map::value_type("solid_solution", Phreeqc::KEY_SOLID_SOLUTIONS), -std::map::value_type("solution_spread", Phreeqc::KEY_SOLUTION_SPREAD), -std::map::value_type("spread_solution", Phreeqc::KEY_SOLUTION_SPREAD), -std::map::value_type("selected_out", Phreeqc::KEY_SELECTED_OUTPUT), -std::map::value_type("select_out", Phreeqc::KEY_SELECTED_OUTPUT), -std::map::value_type("user_graph", Phreeqc::KEY_USER_GRAPH), -std::map::value_type("llnl_aqueous_model_parameters", Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), -std::map::value_type("llnl_aqueous_model", Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), -std::map::value_type("database", Phreeqc::KEY_DATABASE), -std::map::value_type("named_analytical_expression", Phreeqc::KEY_NAMED_EXPRESSIONS), -std::map::value_type("named_analytical_expressions", Phreeqc::KEY_NAMED_EXPRESSIONS), -std::map::value_type("named_expressions", Phreeqc::KEY_NAMED_EXPRESSIONS), -std::map::value_type("named_log_k", Phreeqc::KEY_NAMED_EXPRESSIONS), -std::map::value_type("isotopes", Phreeqc::KEY_ISOTOPES), -std::map::value_type("calculate_values", Phreeqc::KEY_CALCULATE_VALUES), -std::map::value_type("isotope_ratios", Phreeqc::KEY_ISOTOPE_RATIOS), -std::map::value_type("isotope_alphas", Phreeqc::KEY_ISOTOPE_ALPHAS), -std::map::value_type("copy", Phreeqc::KEY_COPY), -std::map::value_type("pitzer", Phreeqc::KEY_PITZER), -std::map::value_type("sit", Phreeqc::KEY_SIT), -std::map::value_type("equilibrium_phase", Phreeqc::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("solution_raw", Phreeqc::KEY_SOLUTION_RAW), -std::map::value_type("exchange_raw", Phreeqc::KEY_EXCHANGE_RAW), -std::map::value_type("surface_raw", Phreeqc::KEY_SURFACE_RAW), -std::map::value_type("equilibrium_phases_raw", Phreeqc::KEY_EQUILIBRIUM_PHASES_RAW), -std::map::value_type("kinetics_raw", Phreeqc::KEY_KINETICS_RAW), -std::map::value_type("solid_solutions_raw", Phreeqc::KEY_SOLID_SOLUTIONS_RAW), -std::map::value_type("gas_phase_raw", Phreeqc::KEY_GAS_PHASE_RAW), -std::map::value_type("reaction_raw", Phreeqc::KEY_REACTION_RAW), -std::map::value_type("mix_raw", Phreeqc::KEY_MIX_RAW), -std::map::value_type("reaction_temperature_raw", Phreeqc::KEY_REACTION_TEMPERATURE_RAW), -std::map::value_type("dump", Phreeqc::KEY_DUMP), -std::map::value_type("solution_modify", Phreeqc::KEY_SOLUTION_MODIFY), -std::map::value_type("equilibrium_phases_modify", Phreeqc::KEY_EQUILIBRIUM_PHASES_MODIFY), -std::map::value_type("exchange_modify", Phreeqc::KEY_EXCHANGE_MODIFY), -std::map::value_type("surface_modify", Phreeqc::KEY_SURFACE_MODIFY), -std::map::value_type("solid_solutions_modify", Phreeqc::KEY_SOLID_SOLUTIONS_MODIFY), -std::map::value_type("gas_phase_modify", Phreeqc::KEY_GAS_PHASE_MODIFY), -std::map::value_type("kinetics_modify", Phreeqc::KEY_KINETICS_MODIFY), -std::map::value_type("delete", Phreeqc::KEY_DELETE), -std::map::value_type("run_cells", Phreeqc::KEY_RUN_CELLS), -std::map::value_type("reaction_modify", Phreeqc::KEY_REACTION_MODIFY), -std::map::value_type("reaction_temperature_modify", Phreeqc::KEY_REACTION_TEMPERATURE_MODIFY), -std::map::value_type("solid_solution_modify", Phreeqc::KEY_SOLID_SOLUTION_MODIFY), -std::map::value_type("reaction_pressure", Phreeqc::KEY_REACTION_PRESSURE), -std::map::value_type("reaction_pressures", Phreeqc::KEY_REACTION_PRESSURE), -std::map::value_type("reaction_pressure_raw", Phreeqc::KEY_REACTION_PRESSURE_RAW), -std::map::value_type("reaction_pressure_modify", Phreeqc::KEY_REACTION_PRESSURE_MODIFY) - -}; -std::map Phreeqc::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); - -const std::map::value_type temp_keyword_names[] = { -std::map::value_type(Phreeqc::KEY_NONE, "UNKNOWN"), -std::map::value_type(Phreeqc::KEY_END, "END"), -std::map::value_type(Phreeqc::KEY_SOLUTION_SPECIES, "SOLUTION_SPECIES"), -std::map::value_type(Phreeqc::KEY_SOLUTION_MASTER_SPECIES, "SOLUTION_MASTER_SPECIES"), -std::map::value_type(Phreeqc::KEY_SOLUTION, "SOLUTION"), -std::map::value_type(Phreeqc::KEY_PHASES, "PHASES"), -std::map::value_type(Phreeqc::KEY_REACTION, "REACTION"), -std::map::value_type(Phreeqc::KEY_MIX, "MIX"), -std::map::value_type(Phreeqc::KEY_USE, "USE"), -std::map::value_type(Phreeqc::KEY_SAVE, "SAVE"), -std::map::value_type(Phreeqc::KEY_EXCHANGE_SPECIES, "EXCHANGE_SPECIES"), -std::map::value_type(Phreeqc::KEY_EXCHANGE_MASTER_SPECIES, "EXCHANGE_MASTER_SPECIES"), -std::map::value_type(Phreeqc::KEY_EXCHANGE, "EXCHANGE"), -std::map::value_type(Phreeqc::KEY_SURFACE_SPECIES, "SURFACE_SPECIES"), -std::map::value_type(Phreeqc::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"), -std::map::value_type(Phreeqc::KEY_SURFACE, "SURFACE"), -std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE, "REACTION_TEMPERATURE"), -std::map::value_type(Phreeqc::KEY_INVERSE_MODELING, "INVERSE_MODELING"), -std::map::value_type(Phreeqc::KEY_GAS_PHASE, "GAS_PHASE"), -std::map::value_type(Phreeqc::KEY_TRANSPORT, "TRANSPORT"), -std::map::value_type(Phreeqc::KEY_SELECTED_OUTPUT, "SELECTED_OUTPUT"), -std::map::value_type(Phreeqc::KEY_KNOBS, "KNOBS"), -std::map::value_type(Phreeqc::KEY_PRINT, "PRINT"), -std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"), -std::map::value_type(Phreeqc::KEY_TITLE, "TITLE"), -std::map::value_type(Phreeqc::KEY_ADVECTION, "ADVECTION"), -std::map::value_type(Phreeqc::KEY_KINETICS, "KINETICS"), -std::map::value_type(Phreeqc::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"), -std::map::value_type(Phreeqc::KEY_RATES, "RATES"), -std::map::value_type(Phreeqc::KEY_USER_PRINT, "USER_PRINT"), -std::map::value_type(Phreeqc::KEY_USER_PUNCH, "USER_PUNCH"), -std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS, "SOLID_SOLUTIONS"), -std::map::value_type(Phreeqc::KEY_SOLUTION_SPREAD, "SOLUTION_SPREAD"), -std::map::value_type(Phreeqc::KEY_USER_GRAPH, "USER_GRAPH"), -std::map::value_type(Phreeqc::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, "LLNL_AQUEOUS_MODEL_PARAMETERS"), -std::map::value_type(Phreeqc::KEY_DATABASE, "DATABASE"), -std::map::value_type(Phreeqc::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"), -std::map::value_type(Phreeqc::KEY_ISOTOPES, "ISOTOPES"), -std::map::value_type(Phreeqc::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"), -std::map::value_type(Phreeqc::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"), -std::map::value_type(Phreeqc::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"), -std::map::value_type(Phreeqc::KEY_COPY, "COPY"), -std::map::value_type(Phreeqc::KEY_PITZER, "PITZER"), -std::map::value_type(Phreeqc::KEY_SIT, "SIT"), -std::map::value_type(Phreeqc::KEY_SOLUTION_RAW, "SOLUTION_RAW"), -std::map::value_type(Phreeqc::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"), -std::map::value_type(Phreeqc::KEY_SURFACE_RAW, "SURFACE_RAW"), -std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"), -std::map::value_type(Phreeqc::KEY_KINETICS_RAW, "KINETICS_RAW"), -std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"), -std::map::value_type(Phreeqc::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"), -std::map::value_type(Phreeqc::KEY_REACTION_RAW, "REACTION_RAW"), -std::map::value_type(Phreeqc::KEY_MIX_RAW, "MIX_RAW"), -std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"), -std::map::value_type(Phreeqc::KEY_DUMP, "DUMP"), -std::map::value_type(Phreeqc::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"), -std::map::value_type(Phreeqc::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"), -std::map::value_type(Phreeqc::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"), -std::map::value_type(Phreeqc::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"), -std::map::value_type(Phreeqc::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"), -std::map::value_type(Phreeqc::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"), -std::map::value_type(Phreeqc::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"), -std::map::value_type(Phreeqc::KEY_DELETE, "DELETE"), -std::map::value_type(Phreeqc::KEY_RUN_CELLS, "RUN_CELLS"), -std::map::value_type(Phreeqc::KEY_REACTION_MODIFY, "REACTION_MODIFY"), -std::map::value_type(Phreeqc::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), -std::map::value_type(Phreeqc::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), -std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), -std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), -std::map::value_type(Phreeqc::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") -}; -std::map Phreeqc::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index e26d0bd2..91d07f7b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -59,86 +59,10 @@ public: Phreeqc(void); ~Phreeqc(void); - enum KEYWORDS - { - KEY_NONE, - KEY_END, - KEY_SOLUTION_SPECIES, - KEY_SOLUTION_MASTER_SPECIES, - KEY_SOLUTION, - KEY_PHASES, - KEY_REACTION, - KEY_MIX, - KEY_USE, - KEY_SAVE, - KEY_EXCHANGE_SPECIES, - KEY_EXCHANGE_MASTER_SPECIES, - KEY_EXCHANGE, - KEY_SURFACE_SPECIES, - KEY_SURFACE_MASTER_SPECIES, - KEY_SURFACE, - KEY_REACTION_TEMPERATURE, - KEY_INVERSE_MODELING, - KEY_GAS_PHASE, - KEY_TRANSPORT, - KEY_SELECTED_OUTPUT, - KEY_KNOBS, - KEY_PRINT, - KEY_EQUILIBRIUM_PHASES, - KEY_TITLE, - KEY_ADVECTION, - KEY_KINETICS, - KEY_INCREMENTAL_REACTIONS, - KEY_RATES, - KEY_USER_PRINT, - KEY_USER_PUNCH, - KEY_SOLID_SOLUTIONS, - KEY_SOLUTION_SPREAD, - KEY_USER_GRAPH, - KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, - KEY_DATABASE, - KEY_NAMED_EXPRESSIONS, - KEY_ISOTOPES, - KEY_CALCULATE_VALUES, - KEY_ISOTOPE_RATIOS, - KEY_ISOTOPE_ALPHAS, - KEY_COPY, - KEY_PITZER, - KEY_SIT, - KEY_SOLUTION_RAW, - KEY_EXCHANGE_RAW, - KEY_SURFACE_RAW, - KEY_EQUILIBRIUM_PHASES_RAW, - KEY_KINETICS_RAW, - KEY_SOLID_SOLUTIONS_RAW, - KEY_GAS_PHASE_RAW, - KEY_REACTION_RAW, - KEY_MIX_RAW, - KEY_REACTION_TEMPERATURE_RAW, - KEY_DUMP, - KEY_SOLUTION_MODIFY, - KEY_EQUILIBRIUM_PHASES_MODIFY, - KEY_EXCHANGE_MODIFY, - KEY_SURFACE_MODIFY, - KEY_SOLID_SOLUTIONS_MODIFY, - KEY_GAS_PHASE_MODIFY, - KEY_KINETICS_MODIFY, - KEY_DELETE, - KEY_RUN_CELLS, - KEY_REACTION_MODIFY, - KEY_REACTION_TEMPERATURE_MODIFY, - KEY_SOLID_SOLUTION_MODIFY, - KEY_REACTION_PRESSURE, - KEY_REACTION_PRESSURE_RAW, - KEY_REACTION_PRESSURE_MODIFY, - KEY_COUNT_KEYWORDS // must be last in list - }; public: // // Phreeqc class methods // - static Phreeqc::KEYWORDS Keyword_search(std::string key); - static const std::string & Phreeqc::Keyword_name_search(Phreeqc::KEYWORDS key); // advection.cpp ------------------------------- int advection(void); @@ -1828,7 +1752,7 @@ protected: int input_error; - KEYWORDS next_keyword; + Keywords::KEYWORDS next_keyword; int parse_error; int paren_count; int iterations; @@ -2149,8 +2073,6 @@ public: friend class ChartObject; std::vector keycount; // used to mark keywords that have been read - static std::map phreeqc_keywords; - static std::map phreeqc_keyword_names; #endif /* _INC_PHREEQC_H */ diff --git a/StorageBin.cxx b/StorageBin.cxx index a12b660f..6cdc0e2a 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -492,9 +492,11 @@ cxxStorageBin::read_raw(CParser & parser) { switch (parser.next_keyword()) { - case CParser::KT_END: - case CParser::KT_EOF: - case CParser::KT_NONE: + //case CParser::KT_END: + //case CParser::KT_EOF: + //case CParser::KT_NONE: + case Keywords::KEY_END: + case Keywords::KEY_NONE: goto END_OF_SIMULATION_INPUT; break; /* @@ -508,7 +510,8 @@ cxxStorageBin::read_raw(CParser & parser) KT_TEMPERATURE_RAW = 12, KT_REACTION_RAW = 13 */ - case CParser::KT_SOLUTION_RAW: + //case CParser::KT_SOLUTION_RAW: + case Keywords::KEY_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); entity.read_raw(parser); @@ -516,7 +519,8 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_EXCHANGE_RAW: + //case CParser::KT_EXCHANGE_RAW: + case Keywords::KEY_EXCHANGE_RAW: { cxxExchange entity(this->Get_io()); entity.read_raw(parser); @@ -524,7 +528,8 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_GASPHASE_RAW: + //case CParser::KT_GASPHASE_RAW: + case Keywords::KEY_GAS_PHASE_RAW: { cxxGasPhase entity(this->Get_io()); entity.read_raw(parser); @@ -532,7 +537,8 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_KINETICS_RAW: + //case CParser::KT_KINETICS_RAW: + case Keywords::KEY_KINETICS_RAW: { cxxKinetics entity(this->Get_io()); entity.read_raw(parser); @@ -540,7 +546,7 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_PPASSEMBLAGE_RAW: + case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: { cxxPPassemblage entity(this->Get_io()); entity.read_raw(parser); @@ -548,7 +554,7 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_SSASSEMBLAGE_RAW: + case Keywords::KEY_SOLID_SOLUTIONS_RAW: { cxxSSassemblage entity; entity.read_raw(parser); @@ -556,7 +562,7 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_SURFACE_RAW: + case Keywords::KEY_SURFACE_RAW: { cxxSurface entity(this->Get_io()); entity.read_raw(parser); @@ -564,7 +570,7 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_TEMPERATURE_RAW: + case Keywords::KEY_REACTION_TEMPERATURE_RAW: { cxxTemperature entity(this->Get_io()); entity.read_raw(parser); @@ -572,14 +578,14 @@ cxxStorageBin::read_raw(CParser & parser) } break; - case CParser::KT_REACTION_RAW: + case Keywords::KEY_REACTION_RAW: { cxxReaction entity; entity.read_raw(parser, true); Reactions[entity.Get_n_user()] = entity; } break; - case CParser::KT_MIX_RAW: + case Keywords::KEY_MIX_RAW: { cxxMix entity; entity.read_raw(parser); @@ -603,8 +609,10 @@ cxxStorageBin::read_raw_keyword(CParser & parser) switch (parser.next_keyword()) { - case CParser::KT_NONE: - case CParser::KT_END: + //case CParser::KT_NONE: + //case CParser::KT_END: + case Keywords::KEY_NONE: + case Keywords::KEY_END: while ((i = parser.check_line("StorageBin read_raw_keyword", false, true, true, true)) != CParser::LT_KEYWORD) @@ -613,8 +621,8 @@ cxxStorageBin::read_raw_keyword(CParser & parser) break; // CParser::LT_EOF; } break; - case CParser::KT_EOF: - break; + /*case CParser::KT_EOF: + break;*/ /* KT_SOLUTION_RAW = 5, KT_EXCHANGE_RAW = 6, @@ -626,7 +634,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) KT_TEMPERATURE_RAW = 12, KT_REACTION_RAW = 13 */ - case CParser::KT_SOLUTION_RAW: + case Keywords::KEY_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); entity.read_raw(parser); @@ -635,7 +643,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_EXCHANGE_RAW: + case Keywords::KEY_EXCHANGE_RAW: { cxxExchange entity(this->Get_io()); entity.read_raw(parser); @@ -644,7 +652,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_GASPHASE_RAW: + case Keywords::KEY_GAS_PHASE_RAW: { cxxGasPhase entity(this->Get_io()); entity.read_raw(parser); @@ -653,7 +661,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_KINETICS_RAW: + case Keywords::KEY_KINETICS_RAW: { cxxKinetics entity(this->Get_io()); entity.read_raw(parser); @@ -662,7 +670,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_PPASSEMBLAGE_RAW: + case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: { cxxPPassemblage entity(this->Get_io()); entity.read_raw(parser); @@ -671,7 +679,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_SSASSEMBLAGE_RAW: + case Keywords::KEY_SOLID_SOLUTIONS_RAW: { cxxSSassemblage entity; entity.read_raw(parser); @@ -680,7 +688,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_SURFACE_RAW: + case Keywords::KEY_SURFACE_RAW: { cxxSurface entity(this->Get_io()); entity.read_raw(parser); @@ -689,7 +697,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_TEMPERATURE_RAW: + case Keywords::KEY_REACTION_TEMPERATURE_RAW: { cxxTemperature entity(this->Get_io()); entity.read_raw(parser); @@ -698,7 +706,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; - case CParser::KT_REACTION_RAW: + case Keywords::KEY_REACTION_RAW: { cxxReaction entity; entity.read_raw(parser, true); @@ -707,6 +715,15 @@ cxxStorageBin::read_raw_keyword(CParser & parser) } break; + case Keywords::KEY_MIX_RAW: + { + cxxMix entity; + entity.read_raw(parser); + Mixes[entity.Get_n_user()] = entity; + entity_number = entity.Get_n_user(); + } + break; + default: break; } From 278ce5a95298854e5a921ce8780099d7547c09d8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Nov 2011 18:32:55 +0000 Subject: [PATCH 0344/1077] New keywords files git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5836 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++ Keywords.h | 93 ++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100644 Keywords.cpp create mode 100644 Keywords.h diff --git a/Keywords.cpp b/Keywords.cpp new file mode 100644 index 00000000..af83f26b --- /dev/null +++ b/Keywords.cpp @@ -0,0 +1,202 @@ +#include "..\Keywords.h" + + +Keywords::Keywords(void) +{ +} + + +Keywords::~Keywords(void) +{ +} + +Keywords::KEYWORDS Keywords::Keyword_search(std::string key) +{ + std::map::const_iterator it; + it = phreeqc_keywords.find(key); + if (it != Keywords::phreeqc_keywords.end()) + { + return it->second; + } + return Keywords::KEY_NONE; +} + +const std::string & Keywords::Keyword_name_search(Keywords::KEYWORDS key) +{ + std::map::const_iterator it; + it = phreeqc_keyword_names.find(key); + if (it != Keywords::phreeqc_keyword_names.end()) + { + return it->second; + } + it = phreeqc_keyword_names.find(KEY_NONE); + return it->second; +} + +const std::map::value_type temp_keywords[] = { +std::map::value_type("eof", Keywords::KEY_END), +std::map::value_type("end", Keywords::KEY_END), +std::map::value_type("solution_species", Keywords::KEY_SOLUTION_SPECIES), +std::map::value_type("solution_master_species", Keywords::KEY_SOLUTION_MASTER_SPECIES), +std::map::value_type("solution", Keywords::KEY_SOLUTION), +std::map::value_type("phases", Keywords::KEY_PHASES), +std::map::value_type("pure_phases", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("reaction", Keywords::KEY_REACTION), +std::map::value_type("mix", Keywords::KEY_MIX), +std::map::value_type("use", Keywords::KEY_USE), +std::map::value_type("save", Keywords::KEY_SAVE), +std::map::value_type("exchange_species", Keywords::KEY_EXCHANGE_SPECIES), +std::map::value_type("exchange_master_species", Keywords::KEY_EXCHANGE_MASTER_SPECIES), +std::map::value_type("exchange", Keywords::KEY_EXCHANGE), +std::map::value_type("surface_species", Keywords::KEY_SURFACE_SPECIES), +std::map::value_type("surface_master_species", Keywords::KEY_SURFACE_MASTER_SPECIES), +std::map::value_type("surface", Keywords::KEY_SURFACE), +std::map::value_type("reaction_temperature", Keywords::KEY_REACTION_TEMPERATURE), +std::map::value_type("inverse_modeling", Keywords::KEY_INVERSE_MODELING), +std::map::value_type("gas_phase", Keywords::KEY_GAS_PHASE), +std::map::value_type("transport", Keywords::KEY_TRANSPORT), +std::map::value_type("debug", Keywords::KEY_KNOBS), +std::map::value_type("selected_output", Keywords::KEY_SELECTED_OUTPUT), +std::map::value_type("select_output", Keywords::KEY_SELECTED_OUTPUT), +std::map::value_type("knobs", Keywords::KEY_KNOBS), +std::map::value_type("print", Keywords::KEY_PRINT), +std::map::value_type("equilibrium_phases", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("equilibria", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("equilibrium", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("pure", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("title", Keywords::KEY_TITLE), +std::map::value_type("comment", Keywords::KEY_TITLE), +std::map::value_type("advection", Keywords::KEY_ADVECTION), +std::map::value_type("kinetics", Keywords::KEY_KINETICS), +std::map::value_type("incremental_reactions", Keywords::KEY_INCREMENTAL_REACTIONS), +std::map::value_type("incremental", Keywords::KEY_INCREMENTAL_REACTIONS), +std::map::value_type("rates", Keywords::KEY_RATES), +std::map::value_type("solution_s", Keywords::KEY_SOLUTION_SPREAD), +std::map::value_type("user_print", Keywords::KEY_USER_PRINT), +std::map::value_type("user_punch", Keywords::KEY_USER_PUNCH), +std::map::value_type("solid_solutions", Keywords::KEY_SOLID_SOLUTIONS), +std::map::value_type("solid_solution", Keywords::KEY_SOLID_SOLUTIONS), +std::map::value_type("solution_spread", Keywords::KEY_SOLUTION_SPREAD), +std::map::value_type("spread_solution", Keywords::KEY_SOLUTION_SPREAD), +std::map::value_type("selected_out", Keywords::KEY_SELECTED_OUTPUT), +std::map::value_type("select_out", Keywords::KEY_SELECTED_OUTPUT), +std::map::value_type("user_graph", Keywords::KEY_USER_GRAPH), +std::map::value_type("llnl_aqueous_model_parameters", Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), +std::map::value_type("llnl_aqueous_model", Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), +std::map::value_type("database", Keywords::KEY_DATABASE), +std::map::value_type("named_analytical_expression", Keywords::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_analytical_expressions", Keywords::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_expressions", Keywords::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_log_k", Keywords::KEY_NAMED_EXPRESSIONS), +std::map::value_type("isotopes", Keywords::KEY_ISOTOPES), +std::map::value_type("calculate_values", Keywords::KEY_CALCULATE_VALUES), +std::map::value_type("isotope_ratios", Keywords::KEY_ISOTOPE_RATIOS), +std::map::value_type("isotope_alphas", Keywords::KEY_ISOTOPE_ALPHAS), +std::map::value_type("copy", Keywords::KEY_COPY), +std::map::value_type("pitzer", Keywords::KEY_PITZER), +std::map::value_type("sit", Keywords::KEY_SIT), +std::map::value_type("equilibrium_phase", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("solution_raw", Keywords::KEY_SOLUTION_RAW), +std::map::value_type("exchange_raw", Keywords::KEY_EXCHANGE_RAW), +std::map::value_type("surface_raw", Keywords::KEY_SURFACE_RAW), +std::map::value_type("equilibrium_phases_raw", Keywords::KEY_EQUILIBRIUM_PHASES_RAW), +std::map::value_type("kinetics_raw", Keywords::KEY_KINETICS_RAW), +std::map::value_type("solid_solutions_raw", Keywords::KEY_SOLID_SOLUTIONS_RAW), +std::map::value_type("gas_phase_raw", Keywords::KEY_GAS_PHASE_RAW), +std::map::value_type("reaction_raw", Keywords::KEY_REACTION_RAW), +std::map::value_type("mix_raw", Keywords::KEY_MIX_RAW), +std::map::value_type("reaction_temperature_raw", Keywords::KEY_REACTION_TEMPERATURE_RAW), +std::map::value_type("dump", Keywords::KEY_DUMP), +std::map::value_type("solution_modify", Keywords::KEY_SOLUTION_MODIFY), +std::map::value_type("equilibrium_phases_modify", Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY), +std::map::value_type("exchange_modify", Keywords::KEY_EXCHANGE_MODIFY), +std::map::value_type("surface_modify", Keywords::KEY_SURFACE_MODIFY), +std::map::value_type("solid_solutions_modify", Keywords::KEY_SOLID_SOLUTIONS_MODIFY), +std::map::value_type("gas_phase_modify", Keywords::KEY_GAS_PHASE_MODIFY), +std::map::value_type("kinetics_modify", Keywords::KEY_KINETICS_MODIFY), +std::map::value_type("delete", Keywords::KEY_DELETE), +std::map::value_type("run_cells", Keywords::KEY_RUN_CELLS), +std::map::value_type("reaction_modify", Keywords::KEY_REACTION_MODIFY), +std::map::value_type("reaction_temperature_modify", Keywords::KEY_REACTION_TEMPERATURE_MODIFY), +std::map::value_type("solid_solution_modify", Keywords::KEY_SOLID_SOLUTION_MODIFY), +std::map::value_type("reaction_pressure", Keywords::KEY_REACTION_PRESSURE), +std::map::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE), +std::map::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW), +std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY) + +}; +std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); + +const std::map::value_type temp_keyword_names[] = { +std::map::value_type(Keywords::KEY_NONE, "UNKNOWN"), +std::map::value_type(Keywords::KEY_END, "END"), +std::map::value_type(Keywords::KEY_SOLUTION_SPECIES, "SOLUTION_SPECIES"), +std::map::value_type(Keywords::KEY_SOLUTION_MASTER_SPECIES, "SOLUTION_MASTER_SPECIES"), +std::map::value_type(Keywords::KEY_SOLUTION, "SOLUTION"), +std::map::value_type(Keywords::KEY_PHASES, "PHASES"), +std::map::value_type(Keywords::KEY_REACTION, "REACTION"), +std::map::value_type(Keywords::KEY_MIX, "MIX"), +std::map::value_type(Keywords::KEY_USE, "USE"), +std::map::value_type(Keywords::KEY_SAVE, "SAVE"), +std::map::value_type(Keywords::KEY_EXCHANGE_SPECIES, "EXCHANGE_SPECIES"), +std::map::value_type(Keywords::KEY_EXCHANGE_MASTER_SPECIES, "EXCHANGE_MASTER_SPECIES"), +std::map::value_type(Keywords::KEY_EXCHANGE, "EXCHANGE"), +std::map::value_type(Keywords::KEY_SURFACE_SPECIES, "SURFACE_SPECIES"), +std::map::value_type(Keywords::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"), +std::map::value_type(Keywords::KEY_SURFACE, "SURFACE"), +std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE, "REACTION_TEMPERATURE"), +std::map::value_type(Keywords::KEY_INVERSE_MODELING, "INVERSE_MODELING"), +std::map::value_type(Keywords::KEY_GAS_PHASE, "GAS_PHASE"), +std::map::value_type(Keywords::KEY_TRANSPORT, "TRANSPORT"), +std::map::value_type(Keywords::KEY_SELECTED_OUTPUT, "SELECTED_OUTPUT"), +std::map::value_type(Keywords::KEY_KNOBS, "KNOBS"), +std::map::value_type(Keywords::KEY_PRINT, "PRINT"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"), +std::map::value_type(Keywords::KEY_TITLE, "TITLE"), +std::map::value_type(Keywords::KEY_ADVECTION, "ADVECTION"), +std::map::value_type(Keywords::KEY_KINETICS, "KINETICS"), +std::map::value_type(Keywords::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"), +std::map::value_type(Keywords::KEY_RATES, "RATES"), +std::map::value_type(Keywords::KEY_USER_PRINT, "USER_PRINT"), +std::map::value_type(Keywords::KEY_USER_PUNCH, "USER_PUNCH"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS, "SOLID_SOLUTIONS"), +std::map::value_type(Keywords::KEY_SOLUTION_SPREAD, "SOLUTION_SPREAD"), +std::map::value_type(Keywords::KEY_USER_GRAPH, "USER_GRAPH"), +std::map::value_type(Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, "LLNL_AQUEOUS_MODEL_PARAMETERS"), +std::map::value_type(Keywords::KEY_DATABASE, "DATABASE"), +std::map::value_type(Keywords::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"), +std::map::value_type(Keywords::KEY_ISOTOPES, "ISOTOPES"), +std::map::value_type(Keywords::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"), +std::map::value_type(Keywords::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"), +std::map::value_type(Keywords::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"), +std::map::value_type(Keywords::KEY_COPY, "COPY"), +std::map::value_type(Keywords::KEY_PITZER, "PITZER"), +std::map::value_type(Keywords::KEY_SIT, "SIT"), +std::map::value_type(Keywords::KEY_SOLUTION_RAW, "SOLUTION_RAW"), +std::map::value_type(Keywords::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"), +std::map::value_type(Keywords::KEY_SURFACE_RAW, "SURFACE_RAW"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"), +std::map::value_type(Keywords::KEY_KINETICS_RAW, "KINETICS_RAW"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"), +std::map::value_type(Keywords::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"), +std::map::value_type(Keywords::KEY_REACTION_RAW, "REACTION_RAW"), +std::map::value_type(Keywords::KEY_MIX_RAW, "MIX_RAW"), +std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"), +std::map::value_type(Keywords::KEY_DUMP, "DUMP"), +std::map::value_type(Keywords::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"), +std::map::value_type(Keywords::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"), +std::map::value_type(Keywords::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"), +std::map::value_type(Keywords::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"), +std::map::value_type(Keywords::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"), +std::map::value_type(Keywords::KEY_DELETE, "DELETE"), +std::map::value_type(Keywords::KEY_RUN_CELLS, "RUN_CELLS"), +std::map::value_type(Keywords::KEY_REACTION_MODIFY, "REACTION_MODIFY"), +std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") +}; +std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); diff --git a/Keywords.h b/Keywords.h new file mode 100644 index 00000000..7077d712 --- /dev/null +++ b/Keywords.h @@ -0,0 +1,93 @@ +#ifndef _INC_KEYWORDS_H +#define _INC_KEYWORDS_H +#include +#include +class Keywords +{ +public: + enum KEYWORDS + { + KEY_NONE, + KEY_END, + KEY_SOLUTION_SPECIES, + KEY_SOLUTION_MASTER_SPECIES, + KEY_SOLUTION, + KEY_PHASES, + KEY_REACTION, + KEY_MIX, + KEY_USE, + KEY_SAVE, + KEY_EXCHANGE_SPECIES, + KEY_EXCHANGE_MASTER_SPECIES, + KEY_EXCHANGE, + KEY_SURFACE_SPECIES, + KEY_SURFACE_MASTER_SPECIES, + KEY_SURFACE, + KEY_REACTION_TEMPERATURE, + KEY_INVERSE_MODELING, + KEY_GAS_PHASE, + KEY_TRANSPORT, + KEY_SELECTED_OUTPUT, + KEY_KNOBS, + KEY_PRINT, + KEY_EQUILIBRIUM_PHASES, + KEY_TITLE, + KEY_ADVECTION, + KEY_KINETICS, + KEY_INCREMENTAL_REACTIONS, + KEY_RATES, + KEY_USER_PRINT, + KEY_USER_PUNCH, + KEY_SOLID_SOLUTIONS, + KEY_SOLUTION_SPREAD, + KEY_USER_GRAPH, + KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, + KEY_DATABASE, + KEY_NAMED_EXPRESSIONS, + KEY_ISOTOPES, + KEY_CALCULATE_VALUES, + KEY_ISOTOPE_RATIOS, + KEY_ISOTOPE_ALPHAS, + KEY_COPY, + KEY_PITZER, + KEY_SIT, + KEY_SOLUTION_RAW, + KEY_EXCHANGE_RAW, + KEY_SURFACE_RAW, + KEY_EQUILIBRIUM_PHASES_RAW, + KEY_KINETICS_RAW, + KEY_SOLID_SOLUTIONS_RAW, + KEY_GAS_PHASE_RAW, + KEY_REACTION_RAW, + KEY_MIX_RAW, + KEY_REACTION_TEMPERATURE_RAW, + KEY_DUMP, + KEY_SOLUTION_MODIFY, + KEY_EQUILIBRIUM_PHASES_MODIFY, + KEY_EXCHANGE_MODIFY, + KEY_SURFACE_MODIFY, + KEY_SOLID_SOLUTIONS_MODIFY, + KEY_GAS_PHASE_MODIFY, + KEY_KINETICS_MODIFY, + KEY_DELETE, + KEY_RUN_CELLS, + KEY_REACTION_MODIFY, + KEY_REACTION_TEMPERATURE_MODIFY, + KEY_SOLID_SOLUTION_MODIFY, + KEY_REACTION_PRESSURE, + KEY_REACTION_PRESSURE_RAW, + KEY_REACTION_PRESSURE_MODIFY, + KEY_COUNT_KEYWORDS // must be last in list + }; + + Keywords(void); + ~Keywords(void); + + static KEYWORDS Keyword_search(std::string key); + static const std::string & Keyword_name_search(KEYWORDS key); + + static std::map phreeqc_keywords; + static std::map phreeqc_keyword_names; +}; + +#endif // _INC_KEYWORDS_H \ No newline at end of file From 2c80bb5ff1e6ea8d02170fb60ac816cb3ebd0395 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Nov 2011 20:29:25 +0000 Subject: [PATCH 0345/1077] Needed header file on Linux? git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5837 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 91d07f7b..957bdae9 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -28,6 +28,7 @@ #ifdef MULTICHART #include "ChartHandler.h" #endif +#include "Keywords.h" class cxxNameDouble; class cxxKinetics; From 90f308452ae97dc30c40be54f9d25fe531c2f623 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Nov 2011 21:48:21 +0000 Subject: [PATCH 0346/1077] Added erase basic function. Some Kewords:: qualifiers were still missing. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5838 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 36 ++++++++++++++++++++++++++++++++++++ PBasic.h | 4 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index bbea3236..8af3380e 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1120,6 +1120,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("DIM"); break; + case tokerase: + output_msg("ERASE"); + break; + case tokpoke: output_msg("POKE"); break; @@ -4844,6 +4848,33 @@ cmddim(struct LOC_exec *LINK) while (!iseos(LINK)); } +void PBasic:: +cmderase(struct LOC_exec *LINK) +{ + varrec *v = NULL; + do + { + if (LINK->t == NULL || LINK->t->kind != tokvar) + snerr(": error in DIM command"); + + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + if (v->stringvar) + { + free_dim_stringvar(v); + } + else + { + PhreeqcPtr->free_check_null(v->UU.U0.arr); + v->UU.U0.arr = NULL; + } + v->numdims = 0; + if (!iseos(LINK)) require(tokcomma, LINK); + } + while (!iseos(LINK)); +} + + void PBasic:: cmdpoke(struct LOC_exec *LINK) { @@ -5064,6 +5095,10 @@ exec(void) cmddim(&V); break; + case tokerase: + cmderase(&V); + break; + case tokpoke: cmdpoke(&V); break; @@ -6263,6 +6298,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("gotoxy", PBasic::tokgotoxy), std::map::value_type("on", PBasic::tokon), std::map::value_type("dim", PBasic::tokdim), + std::map::value_type("erase", PBasic::tokerase), std::map::value_type("poke", PBasic::tokpoke), std::map::value_type("list", PBasic::toklist), std::map::value_type("run", PBasic::tokrun), diff --git a/PBasic.h b/PBasic.h index 7f59f14f..de6a5e1d 100644 --- a/PBasic.h +++ b/PBasic.h @@ -293,7 +293,8 @@ public: tokpr_phi, tokgas_p, tokgas_vm, - tokpressure + tokpressure, + tokerase }; #if !defined(PHREEQCI_GUI) @@ -411,6 +412,7 @@ public: void cmdgotoxy(struct LOC_exec *LINK); void cmdon(struct LOC_exec *LINK); void cmddim(struct LOC_exec *LINK); + void cmderase(struct LOC_exec *LINK); void cmdpoke(struct LOC_exec *LINK); int basic_main(char *commands); int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); From ae868f0a2015699681b1052d801a295401ceaf33 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Dec 2011 01:00:37 +0000 Subject: [PATCH 0347/1077] Got reader for reaction_pressure working. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5840 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 4 ++ Phreeqc.h | 2 +- Pressure.cxx | 194 +++++++++++++++++++++++++-------------------------- Pressure.h | 3 +- 4 files changed, 102 insertions(+), 101 deletions(-) diff --git a/Parser.h b/Parser.h index 016bd2da..59563312 100644 --- a/Parser.h +++ b/Parser.h @@ -162,6 +162,10 @@ class CParser: public PHRQ_base { return m_line; } + std::string & line_save() + { + return m_line_save; + } std::string & get_accumulated() { return accumulated; diff --git a/Phreeqc.h b/Phreeqc.h index 957bdae9..da8d62b2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -642,7 +642,7 @@ public: //int read_delta_v_only(char *ptr, LDBLE * delta_v); int read_number_description(char *ptr, int *n_user, int *n_user_end, char **description, int allow_negative=FALSE); - int check_key(char *str); + int check_key(const char *str); int check_units(char *tot_units, int alkalinity, int check_compatibility, const char *default_units, int print); int find_option(char *item, int *n, const char **list, int count_list, diff --git a/Pressure.cxx b/Pressure.cxx index 8971e0ff..13946b6f 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -25,129 +25,127 @@ cxxPressure::cxxPressure(PHRQ_io *io) { count = 0; equalIncrements = false; - pressures.push_back(1.0); } cxxPressure::~cxxPressure() { } -void +int cxxPressure::read(CParser & parser) { - double d; - CParser::TOKEN_TYPE k; - static std::vector < std::string > vopts; - if (vopts.empty()) - { - vopts.reserve(5); - vopts.push_back("pressures"); //0 - vopts.push_back("equal_increments"); //1 - vopts.push_back("count"); //2 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); - - // Read reaction_pressure number and description +/* + * Reads pressure data for reaction steps + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + // number and description this->read_number_description(parser); - - opt_save = CParser::OPT_ERROR; - bool equalIncrements_defined(false); - bool count_defined(false); - + CParser::LINE_TYPE lt; + bool done = false; 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 REACTION_PRESSURE_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); - useLastLine = false; - break; + // new line + //LINE_TYPE check_line(const std::string & str, bool allow_empty, + // bool allow_eof, bool allow_keyword, bool print); + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token, str; + lt = parser.check_line(str, false, true, true, true); - case 0: // pressures - while ((k = - parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + if (lt == CParser::LT_EMPTY || + lt == CParser::LT_KEYWORD || + lt == CParser::LT_EOF) + { + break; + } + if (lt == CParser::LT_OPTION) + { + this->error_msg("Expected numeric value for pressures.", CParser::OT_CONTINUE); + break; + } + + if (done) + { + this->error_msg("Unknown input following equal increment definition.", CParser::OT_CONTINUE); + continue; + } + + // LT_OK + + for (;;) + { + // new token + std::string token; + CParser::TOKEN_TYPE k = parser.copy_token(token, next_char); + + // need new line + if (k == CParser::TT_EMPTY) + { + break; + } + + // read a pressure + if (k == CParser::TT_DIGIT) { std::istringstream iss(token); + LDBLE d; if (!(iss >> d)) { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for pressures.", + this->error_msg("Expected numeric value for pressures.", CParser::OT_CONTINUE); } else { this->pressures.push_back(d); } + continue; } - opt_save = 0; - useLastLine = false; - break; - case 1: // equal_increments - if (!(parser.get_iss() >> this->equalIncrements)) + // non digit, must be "in" + if (k == CParser::TT_UPPER || k == CParser::TT_LOWER) { - this->equalIncrements = 0; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + if (this->pressures.size() != 2) + { + this->error_msg("To define equal increments, exactly two pressures should be defined.", CONTINUE); + } + else + { + int i = parser.copy_token(token, next_char); + if (i == EMPTY) + { + error_msg("To define equal increments, define 'in n steps'.", CONTINUE); + } + else + { + std::istringstream iss(token); + if ((iss >> i) && i > 0) + { + this->equalIncrements = true; + this->count = i; + } + else + { + error_msg("Unknown input for pressure steps.", CONTINUE); + } + } + done = true; + } + if (k == CParser::TT_UNKNOWN) + { + error_msg("Unknown input for pressure steps.", CONTINUE); + } } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - equalIncrements_defined = true; - break; - - case 2: // count - if (!(parser.get_iss() >> this->count)) - { - this->count = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for count.", CParser::OT_CONTINUE); - } - opt_save = CParser::OPT_DEFAULT; - useLastLine = false; - count_defined = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } - // members that must be defined - if (equalIncrements_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", - CParser::OT_CONTINUE); - } - if (count_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", - CParser::OT_CONTINUE); - } + } // tokens + } // lines + return lt; } void diff --git a/Pressure.h b/Pressure.h index 7adeb51a..3f120de0 100644 --- a/Pressure.h +++ b/Pressure.h @@ -14,14 +14,13 @@ class cxxPressure:public cxxNumKeyword public: cxxPressure(PHRQ_io *io=NULL); - cxxPressure(struct temperature *, PHRQ_io *io=NULL); ~cxxPressure(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; - void read(CParser & parser); + int read(CParser & parser); void read_raw(CParser & parser); std::vector & Get_pressures(void) {return pressures;}; From 0f6547cc32b05f48f8ba32310220b62e059fe1ba Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 1 Dec 2011 06:33:54 +0000 Subject: [PATCH 0348/1077] IPhreeqc passes all unit tests on VS2005 git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5841 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 8 +++++++- PHRQ_io.h | 20 ++++++++++---------- Phreeqc.cpp | 27 ++++++++++++++++++++++++--- Phreeqc.h | 12 ++++++++---- 4 files changed, 49 insertions(+), 18 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index ee3c5cb6..0030c12c 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -529,6 +529,12 @@ fpunchf(const char *name, const char *format, int d) } } /* ---------------------------------------------------------------------- */ +void PHRQ_io::fpunchf_end_row(const char *format) +/* ---------------------------------------------------------------------- */ +{ + //NOOP for Phreeqc +} +/* ---------------------------------------------------------------------- */ int PHRQ_io:: close_output_files(void) /* ---------------------------------------------------------------------- */ @@ -592,4 +598,4 @@ echo_msg(const char * str) break; } } -} \ No newline at end of file +} diff --git a/PHRQ_io.h b/PHRQ_io.h index 75c21a0b..112847f3 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -25,7 +25,7 @@ public: void output_close(void); void output_rewind(void); bool output_isopen(void); - void output_msg(const char * str); + virtual void output_msg(const char * str); // log_file bool log_open(const char *file_name); @@ -36,12 +36,12 @@ public: void log_msg(const char * str); // punch_file - bool punch_open(const char *file_name); + virtual bool punch_open(const char *file_name); void punch_fflush(void); void punch_close(void); void punch_rewind(void); bool punch_isopen(void); - void punch_msg(const char * str); + virtual void punch_msg(const char * str); // error_file bool error_open(const char *file_name); @@ -49,7 +49,7 @@ public: void error_close(void); void error_rewind(void); bool error_isopen(void); - void error_msg(const char * str, bool stop=false); + virtual void error_msg(const char * str, bool stop=false); void warning_msg(const char *err_str); // dump_file @@ -60,10 +60,10 @@ public: bool dump_isopen(void); void dump_msg(const char * str); - - void fpunchf(const char *name, const char *format, double d); - void fpunchf(const char *name, const char *format, char * d); - void fpunchf(const char *name, const char *format, int d); + virtual void fpunchf(const char *name, const char *format, double d); + virtual void fpunchf(const char *name, const char *format, char * d); + virtual void fpunchf(const char *name, const char *format, int d); + virtual void fpunchf_end_row(const char *format); void Set_io_error_count(int i) {this->io_error_count = i;}; int Get_io_error_count(void) {return this->io_error_count;}; @@ -90,7 +90,7 @@ public: bool Get_error_file_on(void) {return this->error_file_on;}; bool Get_dump_file_on(void) {return this->dump_file_on;}; - void screen_msg(const char * str); + virtual void screen_msg(const char * str); void Set_screen_on(bool tf) {this->screen_on = tf;}; bool Get_screen_on(void) {return this->screen_on;}; @@ -99,7 +99,7 @@ public: ECHO_LOG, ECHO_OUTPUT }; - void echo_msg(const char * str); + virtual void echo_msg(const char * str); void Set_echo_on(bool tf) {this->echo_on = tf;}; bool Get_echo_on(void) {return this->echo_on;}; void Set_echo_destination(ECHO_OPTION eo) {this->echo_destination = eo;}; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d38407f8..7a8f072f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -13,9 +13,18 @@ #include "phqalloc.h" #include "PBasic.h" -Phreeqc::Phreeqc(void) +Phreeqc::Phreeqc(PHRQ_io *io) { - phrq_io = new PHRQ_io; + if (io) + { + delete_phrq_io = false; + phrq_io = io; + } + else + { + delete_phrq_io = true; + phrq_io = new PHRQ_io; + } phast = FALSE; s_pTail = NULL; @@ -149,7 +158,10 @@ Phreeqc::~Phreeqc(void) free_check_null(sformatf_buffer); PHRQ_free_all(); - delete phrq_io; + if (this->phrq_io && this->delete_phrq_io) + { + delete this->phrq_io; + } } void Phreeqc::set_phast(int tf) @@ -872,3 +884,12 @@ void Phreeqc::init(void) return; } +void Phreeqc::set_io(PHRQ_io *io, bool auto_delete) +{ + if (this->phrq_io && this->delete_phrq_io) + { + delete this->phrq_io; + } + this->delete_phrq_io = auto_delete; + this->phrq_io = io; +} diff --git a/Phreeqc.h b/Phreeqc.h index da8d62b2..4739cb02 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -57,7 +57,7 @@ class PBasic; class Phreeqc { public: - Phreeqc(void); + Phreeqc(PHRQ_io *io = NULL); ~Phreeqc(void); public: @@ -1318,10 +1318,11 @@ public: //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); void set_phast(int); + void set_io(PHRQ_io *io, bool auto_delete = false); size_t list_components(std::list &list_c); std::istream *get_istream(); void pop_istream(); - void push_istream(std::istream * cookie); + void push_istream(std::istream * cookie, bool auto_delete = true); void clear_istream(void); protected: void init(void); @@ -1331,10 +1332,10 @@ protected: // protected: std::list istream_list; - std::ifstream * in_stream; - std::ifstream * db_stream; + std::list delete_istream_list; PHRQ_io *phrq_io; + bool delete_phrq_io; /* ---------------------------------------------------------------------- * STRUCTURES @@ -2072,6 +2073,9 @@ public: friend class PBasic; friend class ChartObject; + friend class IPhreeqc; + friend class TestIPhreeqc; + friend class TestSelectedOutput; std::vector keycount; // used to mark keywords that have been read From 99b8eac54d6371208a9b050cd88e1416d04622e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Dec 2011 20:03:56 +0000 Subject: [PATCH 0349/1077] Have read_reaction_pressure and read_reaction_pressure_raw working. Dump reaction_pressure raw also works. Started using templates in Utils.h for map manipulations. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5842 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 146 ++++++++++++++++++++++++------------------------ Phreeqc.h | 7 ++- Pressure.cxx | 21 ++++--- StorageBin.cxx | 20 +++---- Temperature.cxx | 8 +++ Utils.h | 31 +++++++--- 6 files changed, 132 insertions(+), 101 deletions(-) diff --git a/Keywords.cpp b/Keywords.cpp index af83f26b..4f290da1 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -36,23 +36,23 @@ const std::string & Keywords::Keyword_name_search(Keywords::KEYWORDS key) const std::map::value_type temp_keywords[] = { std::map::value_type("eof", Keywords::KEY_END), std::map::value_type("end", Keywords::KEY_END), -std::map::value_type("solution_species", Keywords::KEY_SOLUTION_SPECIES), +std::map::value_type("solution_species", Keywords::KEY_SOLUTION_SPECIES), std::map::value_type("solution_master_species", Keywords::KEY_SOLUTION_MASTER_SPECIES), -std::map::value_type("solution", Keywords::KEY_SOLUTION), +std::map::value_type("solution", Keywords::KEY_SOLUTION), std::map::value_type("phases", Keywords::KEY_PHASES), std::map::value_type("pure_phases", Keywords::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("reaction", Keywords::KEY_REACTION), +std::map::value_type("reaction", Keywords::KEY_REACTION), std::map::value_type("mix", Keywords::KEY_MIX), std::map::value_type("use", Keywords::KEY_USE), -std::map::value_type("save", Keywords::KEY_SAVE), -std::map::value_type("exchange_species", Keywords::KEY_EXCHANGE_SPECIES), +std::map::value_type("save", Keywords::KEY_SAVE), +std::map::value_type("exchange_species", Keywords::KEY_EXCHANGE_SPECIES), std::map::value_type("exchange_master_species", Keywords::KEY_EXCHANGE_MASTER_SPECIES), -std::map::value_type("exchange", Keywords::KEY_EXCHANGE), +std::map::value_type("exchange", Keywords::KEY_EXCHANGE), std::map::value_type("surface_species", Keywords::KEY_SURFACE_SPECIES), std::map::value_type("surface_master_species", Keywords::KEY_SURFACE_MASTER_SPECIES), std::map::value_type("surface", Keywords::KEY_SURFACE), -std::map::value_type("reaction_temperature", Keywords::KEY_REACTION_TEMPERATURE), -std::map::value_type("inverse_modeling", Keywords::KEY_INVERSE_MODELING), +std::map::value_type("reaction_temperature", Keywords::KEY_REACTION_TEMPERATURE), +std::map::value_type("inverse_modeling", Keywords::KEY_INVERSE_MODELING), std::map::value_type("gas_phase", Keywords::KEY_GAS_PHASE), std::map::value_type("transport", Keywords::KEY_TRANSPORT), std::map::value_type("debug", Keywords::KEY_KNOBS), @@ -63,11 +63,11 @@ std::map::value_type("print", Keywo std::map::value_type("equilibrium_phases", Keywords::KEY_EQUILIBRIUM_PHASES), std::map::value_type("equilibria", Keywords::KEY_EQUILIBRIUM_PHASES), std::map::value_type("equilibrium", Keywords::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("pure", Keywords::KEY_EQUILIBRIUM_PHASES), +std::map::value_type("pure", Keywords::KEY_EQUILIBRIUM_PHASES), std::map::value_type("title", Keywords::KEY_TITLE), std::map::value_type("comment", Keywords::KEY_TITLE), std::map::value_type("advection", Keywords::KEY_ADVECTION), -std::map::value_type("kinetics", Keywords::KEY_KINETICS), +std::map::value_type("kinetics", Keywords::KEY_KINETICS), std::map::value_type("incremental_reactions", Keywords::KEY_INCREMENTAL_REACTIONS), std::map::value_type("incremental", Keywords::KEY_INCREMENTAL_REACTIONS), std::map::value_type("rates", Keywords::KEY_RATES), @@ -78,41 +78,41 @@ std::map::value_type("solid_solutions", std::map::value_type("solid_solution", Keywords::KEY_SOLID_SOLUTIONS), std::map::value_type("solution_spread", Keywords::KEY_SOLUTION_SPREAD), std::map::value_type("spread_solution", Keywords::KEY_SOLUTION_SPREAD), -std::map::value_type("selected_out", Keywords::KEY_SELECTED_OUTPUT), +std::map::value_type("selected_out", Keywords::KEY_SELECTED_OUTPUT), std::map::value_type("select_out", Keywords::KEY_SELECTED_OUTPUT), std::map::value_type("user_graph", Keywords::KEY_USER_GRAPH), -std::map::value_type("llnl_aqueous_model_parameters", Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), +std::map::value_type("llnl_aqueous_model_parameters",Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), std::map::value_type("llnl_aqueous_model", Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS), std::map::value_type("database", Keywords::KEY_DATABASE), std::map::value_type("named_analytical_expression", Keywords::KEY_NAMED_EXPRESSIONS), -std::map::value_type("named_analytical_expressions", Keywords::KEY_NAMED_EXPRESSIONS), +std::map::value_type("named_analytical_expressions", Keywords::KEY_NAMED_EXPRESSIONS), std::map::value_type("named_expressions", Keywords::KEY_NAMED_EXPRESSIONS), std::map::value_type("named_log_k", Keywords::KEY_NAMED_EXPRESSIONS), -std::map::value_type("isotopes", Keywords::KEY_ISOTOPES), -std::map::value_type("calculate_values", Keywords::KEY_CALCULATE_VALUES), +std::map::value_type("isotopes", Keywords::KEY_ISOTOPES), +std::map::value_type("calculate_values", Keywords::KEY_CALCULATE_VALUES), std::map::value_type("isotope_ratios", Keywords::KEY_ISOTOPE_RATIOS), std::map::value_type("isotope_alphas", Keywords::KEY_ISOTOPE_ALPHAS), -std::map::value_type("copy", Keywords::KEY_COPY), +std::map::value_type("copy", Keywords::KEY_COPY), std::map::value_type("pitzer", Keywords::KEY_PITZER), std::map::value_type("sit", Keywords::KEY_SIT), std::map::value_type("equilibrium_phase", Keywords::KEY_EQUILIBRIUM_PHASES), -std::map::value_type("solution_raw", Keywords::KEY_SOLUTION_RAW), -std::map::value_type("exchange_raw", Keywords::KEY_EXCHANGE_RAW), +std::map::value_type("solution_raw", Keywords::KEY_SOLUTION_RAW), +std::map::value_type("exchange_raw", Keywords::KEY_EXCHANGE_RAW), std::map::value_type("surface_raw", Keywords::KEY_SURFACE_RAW), std::map::value_type("equilibrium_phases_raw", Keywords::KEY_EQUILIBRIUM_PHASES_RAW), -std::map::value_type("kinetics_raw", Keywords::KEY_KINETICS_RAW), +std::map::value_type("kinetics_raw", Keywords::KEY_KINETICS_RAW), std::map::value_type("solid_solutions_raw", Keywords::KEY_SOLID_SOLUTIONS_RAW), std::map::value_type("gas_phase_raw", Keywords::KEY_GAS_PHASE_RAW), -std::map::value_type("reaction_raw", Keywords::KEY_REACTION_RAW), +std::map::value_type("reaction_raw", Keywords::KEY_REACTION_RAW), std::map::value_type("mix_raw", Keywords::KEY_MIX_RAW), -std::map::value_type("reaction_temperature_raw", Keywords::KEY_REACTION_TEMPERATURE_RAW), -std::map::value_type("dump", Keywords::KEY_DUMP), +std::map::value_type("reaction_temperature_raw", Keywords::KEY_REACTION_TEMPERATURE_RAW), +std::map::value_type("dump", Keywords::KEY_DUMP), std::map::value_type("solution_modify", Keywords::KEY_SOLUTION_MODIFY), std::map::value_type("equilibrium_phases_modify", Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY), std::map::value_type("exchange_modify", Keywords::KEY_EXCHANGE_MODIFY), std::map::value_type("surface_modify", Keywords::KEY_SURFACE_MODIFY), std::map::value_type("solid_solutions_modify", Keywords::KEY_SOLID_SOLUTIONS_MODIFY), -std::map::value_type("gas_phase_modify", Keywords::KEY_GAS_PHASE_MODIFY), +std::map::value_type("gas_phase_modify", Keywords::KEY_GAS_PHASE_MODIFY), std::map::value_type("kinetics_modify", Keywords::KEY_KINETICS_MODIFY), std::map::value_type("delete", Keywords::KEY_DELETE), std::map::value_type("run_cells", Keywords::KEY_RUN_CELLS), @@ -122,7 +122,7 @@ std::map::value_type("solid_solution_modi std::map::value_type("reaction_pressure", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW), -std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY) +std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY) }; std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); @@ -133,7 +133,7 @@ std::map::value_type(Keywords::KEY_END, std::map::value_type(Keywords::KEY_SOLUTION_SPECIES, "SOLUTION_SPECIES"), std::map::value_type(Keywords::KEY_SOLUTION_MASTER_SPECIES, "SOLUTION_MASTER_SPECIES"), std::map::value_type(Keywords::KEY_SOLUTION, "SOLUTION"), -std::map::value_type(Keywords::KEY_PHASES, "PHASES"), +std::map::value_type(Keywords::KEY_PHASES, "PHASES"), std::map::value_type(Keywords::KEY_REACTION, "REACTION"), std::map::value_type(Keywords::KEY_MIX, "MIX"), std::map::value_type(Keywords::KEY_USE, "USE"), @@ -142,61 +142,61 @@ std::map::value_type(Keywords::KEY_EXCHAN std::map::value_type(Keywords::KEY_EXCHANGE_MASTER_SPECIES, "EXCHANGE_MASTER_SPECIES"), std::map::value_type(Keywords::KEY_EXCHANGE, "EXCHANGE"), std::map::value_type(Keywords::KEY_SURFACE_SPECIES, "SURFACE_SPECIES"), -std::map::value_type(Keywords::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"), +std::map::value_type(Keywords::KEY_SURFACE_MASTER_SPECIES, "SURFACE_MASTER_SPECIES"), std::map::value_type(Keywords::KEY_SURFACE, "SURFACE"), std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE, "REACTION_TEMPERATURE"), std::map::value_type(Keywords::KEY_INVERSE_MODELING, "INVERSE_MODELING"), -std::map::value_type(Keywords::KEY_GAS_PHASE, "GAS_PHASE"), -std::map::value_type(Keywords::KEY_TRANSPORT, "TRANSPORT"), +std::map::value_type(Keywords::KEY_GAS_PHASE, "GAS_PHASE"), +std::map::value_type(Keywords::KEY_TRANSPORT, "TRANSPORT"), std::map::value_type(Keywords::KEY_SELECTED_OUTPUT, "SELECTED_OUTPUT"), -std::map::value_type(Keywords::KEY_KNOBS, "KNOBS"), -std::map::value_type(Keywords::KEY_PRINT, "PRINT"), -std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"), -std::map::value_type(Keywords::KEY_TITLE, "TITLE"), -std::map::value_type(Keywords::KEY_ADVECTION, "ADVECTION"), +std::map::value_type(Keywords::KEY_KNOBS, "KNOBS"), +std::map::value_type(Keywords::KEY_PRINT, "PRINT"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES, "EQUILIBRIUM_PHASES"), +std::map::value_type(Keywords::KEY_TITLE, "TITLE"), +std::map::value_type(Keywords::KEY_ADVECTION, "ADVECTION"), std::map::value_type(Keywords::KEY_KINETICS, "KINETICS"), -std::map::value_type(Keywords::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"), -std::map::value_type(Keywords::KEY_RATES, "RATES"), -std::map::value_type(Keywords::KEY_USER_PRINT, "USER_PRINT"), -std::map::value_type(Keywords::KEY_USER_PUNCH, "USER_PUNCH"), +std::map::value_type(Keywords::KEY_INCREMENTAL_REACTIONS, "INCREMENTAL_REACTIONS"), +std::map::value_type(Keywords::KEY_RATES, "RATES"), +std::map::value_type(Keywords::KEY_USER_PRINT, "USER_PRINT"), +std::map::value_type(Keywords::KEY_USER_PUNCH, "USER_PUNCH"), std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS, "SOLID_SOLUTIONS"), std::map::value_type(Keywords::KEY_SOLUTION_SPREAD, "SOLUTION_SPREAD"), -std::map::value_type(Keywords::KEY_USER_GRAPH, "USER_GRAPH"), -std::map::value_type(Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS, "LLNL_AQUEOUS_MODEL_PARAMETERS"), +std::map::value_type(Keywords::KEY_USER_GRAPH, "USER_GRAPH"), +std::map::value_type(Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS,"LLNL_AQUEOUS_MODEL_PARAMETERS"), std::map::value_type(Keywords::KEY_DATABASE, "DATABASE"), -std::map::value_type(Keywords::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"), -std::map::value_type(Keywords::KEY_ISOTOPES, "ISOTOPES"), -std::map::value_type(Keywords::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"), -std::map::value_type(Keywords::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"), -std::map::value_type(Keywords::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"), -std::map::value_type(Keywords::KEY_COPY, "COPY"), -std::map::value_type(Keywords::KEY_PITZER, "PITZER"), -std::map::value_type(Keywords::KEY_SIT, "SIT"), -std::map::value_type(Keywords::KEY_SOLUTION_RAW, "SOLUTION_RAW"), -std::map::value_type(Keywords::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"), -std::map::value_type(Keywords::KEY_SURFACE_RAW, "SURFACE_RAW"), -std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"), -std::map::value_type(Keywords::KEY_KINETICS_RAW, "KINETICS_RAW"), -std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"), -std::map::value_type(Keywords::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"), -std::map::value_type(Keywords::KEY_REACTION_RAW, "REACTION_RAW"), -std::map::value_type(Keywords::KEY_MIX_RAW, "MIX_RAW"), -std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"), -std::map::value_type(Keywords::KEY_DUMP, "DUMP"), -std::map::value_type(Keywords::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"), -std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"), -std::map::value_type(Keywords::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"), -std::map::value_type(Keywords::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"), -std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"), -std::map::value_type(Keywords::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"), -std::map::value_type(Keywords::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"), -std::map::value_type(Keywords::KEY_DELETE, "DELETE"), -std::map::value_type(Keywords::KEY_RUN_CELLS, "RUN_CELLS"), -std::map::value_type(Keywords::KEY_REACTION_MODIFY, "REACTION_MODIFY"), -std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), -std::map::value_type(Keywords::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), -std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), -std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), -std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") +std::map::value_type(Keywords::KEY_NAMED_EXPRESSIONS, "NAMED_EXPRESSIONS"), +std::map::value_type(Keywords::KEY_ISOTOPES, "ISOTOPES"), +std::map::value_type(Keywords::KEY_CALCULATE_VALUES, "CALCULATE_VALUES"), +std::map::value_type(Keywords::KEY_ISOTOPE_RATIOS, "ISOTOPE_RATIOS"), +std::map::value_type(Keywords::KEY_ISOTOPE_ALPHAS, "ISOTOPE_ALPHAS"), +std::map::value_type(Keywords::KEY_COPY, "COPY"), +std::map::value_type(Keywords::KEY_PITZER, "PITZER"), +std::map::value_type(Keywords::KEY_SIT, "SIT"), +std::map::value_type(Keywords::KEY_SOLUTION_RAW, "SOLUTION_RAW"), +std::map::value_type(Keywords::KEY_EXCHANGE_RAW, "EXCHANGE_RAW"), +std::map::value_type(Keywords::KEY_SURFACE_RAW, "SURFACE_RAW"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_RAW, "EQUILIBRIUM_PHASES_RAW"), +std::map::value_type(Keywords::KEY_KINETICS_RAW, "KINETICS_RAW"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_RAW, "SOLID_SOLUTIONS_RAW"), +std::map::value_type(Keywords::KEY_GAS_PHASE_RAW, "GAS_PHASE_RAW"), +std::map::value_type(Keywords::KEY_REACTION_RAW, "REACTION_RAW"), +std::map::value_type(Keywords::KEY_MIX_RAW, "MIX_RAW"), +std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_RAW, "REACTION_TEMPERATURE_RAW"), +std::map::value_type(Keywords::KEY_DUMP, "DUMP"), +std::map::value_type(Keywords::KEY_SOLUTION_MODIFY, "SOLUTION_MODIFY"), +std::map::value_type(Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY, "EQUILIBRIUM_PHASES_MODIFY"), +std::map::value_type(Keywords::KEY_EXCHANGE_MODIFY, "EXCHANGE_MODIFY"), +std::map::value_type(Keywords::KEY_SURFACE_MODIFY, "SURFACE_MODIFY"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTIONS_MODIFY, "SOLID_SOLUTIONS_MODIFY"), +std::map::value_type(Keywords::KEY_GAS_PHASE_MODIFY, "GAS_PHASE_MODIFY"), +std::map::value_type(Keywords::KEY_KINETICS_MODIFY, "KINETICS_MODIFY"), +std::map::value_type(Keywords::KEY_DELETE, "DELETE"), +std::map::value_type(Keywords::KEY_RUN_CELLS, "RUN_CELLS"), +std::map::value_type(Keywords::KEY_REACTION_MODIFY, "REACTION_MODIFY"), +std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), +std::map::value_type(Keywords::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), +std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") }; std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); diff --git a/Phreeqc.h b/Phreeqc.h index 4739cb02..2e1622fd 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -29,6 +29,7 @@ #include "ChartHandler.h" #endif #include "Keywords.h" +#include "Pressure.h" class cxxNameDouble; class cxxKinetics; @@ -38,7 +39,6 @@ class cxxExchange; class cxxExchComp; class cxxGasPhase; class cxxTemperature; -class cxxPressure; class cxxPPassemblage; class cxxPPassemblageComp; class cxxReaction; @@ -693,8 +693,9 @@ public: int read_reaction_steps(struct irrev *irrev_ptr); int read_solid_solutions(void); int read_temperature(void); - int read_reaction_pressure(void); int read_reaction_temps(struct temperature *temperature_ptr); + int read_reaction_pressure(void); + int read_reaction_pressure_raw(void); int read_save(void); int read_selected_output(void); int read_solution(void); @@ -1356,7 +1357,7 @@ protected: /* ---------------------------------------------------------------------- * Pressures * ---------------------------------------------------------------------- */ - std::map Reaction_pressure_map; + std::map Reaction_pressure_map; /* ---------------------------------------------------------------------- * Surface diff --git a/Pressure.cxx b/Pressure.cxx index 13946b6f..3096006e 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -46,8 +46,8 @@ cxxPressure::read(CParser & parser) * ERROR if error occurred reading data * */ - // number and description - this->read_number_description(parser); + // Number and description set in read_reaction_pressure + CParser::LINE_TYPE lt; bool done = false; for (;;) @@ -56,7 +56,7 @@ cxxPressure::read(CParser & parser) //LINE_TYPE check_line(const std::string & str, bool allow_empty, // bool allow_eof, bool allow_keyword, bool print); std::istream::pos_type ptr; - std::istream::pos_type next_char; + std::istream::pos_type next_char = 0; std::string token, str; lt = parser.check_line(str, false, true, true, true); @@ -197,6 +197,8 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxPressure::read_raw(CParser & parser) { + // clear steps for modify operation, if pressures are read + bool cleared_once = false; double d; CParser::TOKEN_TYPE k; static std::vector < std::string > vopts; @@ -209,13 +211,12 @@ cxxPressure::read_raw(CParser & parser) } std::istream::pos_type ptr; - std::istream::pos_type next_char; + std::istream::pos_type next_char = 0; std::string token; int opt_save; bool useLastLine(false); - // Read reaction_pressure number and description - this->read_number_description(parser); + // Number and description set in read_reaction_pressure_raw opt_save = CParser::OPT_ERROR; bool equalIncrements_defined(false); @@ -252,8 +253,12 @@ cxxPressure::read_raw(CParser & parser) break; case 0: // pressures - while ((k = - parser.copy_token(token, next_char)) == CParser::TT_DIGIT) + if (!cleared_once) + { + this->pressures.clear(); + cleared_once = true; + } + while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { std::istringstream iss(token); if (!(iss >> d)) diff --git a/StorageBin.cxx b/StorageBin.cxx index 6cdc0e2a..b0b06ef3 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -377,34 +377,34 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss.precision(DBL_DIG - 1); // Solutions - Utilities::dump_raw(Solutions, s_oss, indent); + Utilities::Reactant_dump_map_raw(Solutions, s_oss, indent); // Exchange - Utilities::dump_raw(Exchangers, s_oss, indent); + Utilities::Reactant_dump_map_raw(Exchangers, s_oss, indent); // Gas Phases - Utilities::dump_raw(GasPhases, s_oss, indent); + Utilities::Reactant_dump_map_raw(GasPhases, s_oss, indent); // Kinetics - Utilities::dump_raw(Kinetics, s_oss, indent); + Utilities::Reactant_dump_map_raw(Kinetics, s_oss, indent); // PPassemblage - Utilities::dump_raw(PPassemblages, s_oss, indent); + Utilities::Reactant_dump_map_raw(PPassemblages, s_oss, indent); // SSassemblage - Utilities::dump_raw(SSassemblages, s_oss, indent); + Utilities::Reactant_dump_map_raw(SSassemblages, s_oss, indent); // Surface - Utilities::dump_raw(Surfaces, s_oss, indent); + Utilities::Reactant_dump_map_raw(Surfaces, s_oss, indent); // Mix - Utilities::dump_raw(Mixes, s_oss, indent); + Utilities::Reactant_dump_map_raw(Mixes, s_oss, indent); // Reactions - Utilities::dump_raw(Reactions, s_oss, indent); + Utilities::Reactant_dump_map_raw(Reactions, s_oss, indent); // Temperature - Utilities::dump_raw(Temperatures, s_oss, indent); + Utilities::Reactant_dump_map_raw(Temperatures, s_oss, indent); } void diff --git a/Temperature.cxx b/Temperature.cxx index 078c4785..03f3b53b 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -153,6 +153,9 @@ cxxTemperature::read_raw(CParser & parser) { double d; CParser::TOKEN_TYPE k; + // clear steps for modify operation, if pressures are read + bool cleared_once = false; + static std::vector < std::string > vopts; if (vopts.empty()) { @@ -206,6 +209,11 @@ cxxTemperature::read_raw(CParser & parser) break; case 0: // temps + if (!cleared_once) + { + this->temps.clear(); + cleared_once = true; + } while ((k = parser.copy_token(token, next_char)) == CParser::TT_DIGIT) { diff --git a/Utils.h b/Utils.h index 455258ef..796c068e 100644 --- a/Utils.h +++ b/Utils.h @@ -35,8 +35,8 @@ namespace Utilities //void error_msg(const std::string&, const int stopflag); // operations on maps of entities (Solution, Exchange, ...) - template < typename T > - void dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) + template < typename T > + void Reactant_dump_map_raw(const T & b, std::ostream & s_oss, unsigned int indent) { //std :: map < int, T > :: const_iterator it; typename T::const_iterator it; @@ -46,12 +46,12 @@ namespace Utilities } return; } - template < typename T > bool exists(const T & b, int i) - { - return (b.find(i) != b.end()); - } + //template < typename T > bool exists(const T & b, int i) + //{ + // return (b.find(i) != b.end()); + //} - template < typename T > T * get_entity(std::map < int, T > b, int i) + template < typename T > T * Reactant_find(std::map < int, T > &b, int i) { if (b.find(i) != b.end()) { @@ -63,6 +63,23 @@ namespace Utilities } } + template < typename T > T * Reactant_copy(std::map < int, T > &b, int i, int j) + { + std::map < int, T >::iterator it; + it = b.find(i); + if (it != b.end()) + { + b[j] = it->second; + it = b.find(j); + it->second.Set_n_user(j); + it->second.Set_n_user_end(j); + return &(it->second); + } + else + { + return (NULL); + } + } /* template From 8a678fa9e7bb2940f2787b911f839a33fdffac4b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 1 Dec 2011 21:52:33 +0000 Subject: [PATCH 0350/1077] removed ../ from include git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5843 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Keywords.cpp b/Keywords.cpp index 4f290da1..008ddc7e 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -1,4 +1,4 @@ -#include "..\Keywords.h" +#include "Keywords.h" Keywords::Keywords(void) From 4a7158c44b36b672d4613694010259a0d2a06eca Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Dec 2011 22:08:35 +0000 Subject: [PATCH 0351/1077] Getting there with adding REACTION_PRESSURE capabilities. Still need to look at copy, dump, and maybe others. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5844 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Pressure.cxx | 57 +++++++++++++++++++++++++++++++++++++++++++++++++- Pressure.h | 4 ++-- ReadClass.cxx | 8 +++++++ StorageBin.cxx | 48 +++++++++++++++++++++++++++++++++++++++++- StorageBin.h | 6 ++++++ System.cxx | 2 ++ System.h | 6 ++++++ 7 files changed, 127 insertions(+), 4 deletions(-) diff --git a/Pressure.cxx b/Pressure.cxx index 3096006e..3f1cdaf8 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -351,4 +351,59 @@ cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const return; } -#endif \ No newline at end of file +#endif +/* ---------------------------------------------------------------------- */ +LDBLE cxxPressure:: +Pressure_for_step(int step_number) +/* ---------------------------------------------------------------------- */ +{ +/* + * Determine pressure of reaction step + */ + LDBLE p_temp; + if (this->pressures.size() == 0) + { + p_temp = 1; + } + else if (this->equalIncrements) + { + if (this->pressures.size() != 2) + { + error_msg("Number of pressures not equal to 2 for equal increments.", 0); + } + if (step_number > this->count) + { + p_temp = this->pressures[1]; + } + else + { + LDBLE denom; + denom = (this->count <= 1) ? 1 : (LDBLE) (this->count - 1); + p_temp = this->pressures[0] + ( this->pressures[1] - this->pressures[0]) * + ((LDBLE) (step_number - 1)) / (denom); + } + } + else + { + if (step_number > (int) this->pressures.size()) + { + p_temp = this->pressures[this->pressures.size() - 1]; + } + else + { + p_temp = this->pressures[step_number - 1]; + } + + } + + return (p_temp); +} +int cxxPressure:: +Get_count(void) const +{ + if (equalIncrements) + { + return this->count; + } + return (int) this->pressures.size(); +} \ No newline at end of file diff --git a/Pressure.h b/Pressure.h index 3f120de0..4053fe1a 100644 --- a/Pressure.h +++ b/Pressure.h @@ -22,9 +22,9 @@ class cxxPressure:public cxxNumKeyword int read(CParser & parser); void read_raw(CParser & parser); - + LDBLE Pressure_for_step(int step_number); std::vector & Get_pressures(void) {return pressures;}; - int Get_count(void) const {return count;}; + int Get_count(void) const; void Set_count(int i) {count = i;}; bool Get_equalIncrements(void) const {return equalIncrements;}; void Set_equalIncrements(bool tf) {equalIncrements = tf;}; diff --git a/ReadClass.cxx b/ReadClass.cxx index 38d450db..df38cf27 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -2281,6 +2281,14 @@ run_as_cells(void) if (abs(use.temperature_ptr->count_t) > count_steps) count_steps = abs(use.temperature_ptr->count_t); } + if (use.pressure_in == TRUE && use.pressure_ptr != NULL) + { + int count = ((cxxPressure *) use.pressure_ptr)->Get_count(); + if (count > count_steps) + { + count_steps = count; + } + } count_total_steps = count_steps; /* * save data for saving solutions diff --git a/StorageBin.cxx b/StorageBin.cxx index b0b06ef3..e0c5725a 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -268,6 +268,7 @@ cxxStorageBin::Get_Temperature(int n_user) } return (NULL); } + void cxxStorageBin::Set_Temperature(int n_user, cxxTemperature * entity) { @@ -275,12 +276,33 @@ cxxStorageBin::Set_Temperature(int n_user, cxxTemperature * entity) return; Temperatures[n_user] = *entity; } + void cxxStorageBin::Remove_Temperature(int n_user) { Temperatures.erase(n_user); } +cxxPressure * +cxxStorageBin::Get_Pressure(int n_user) +{ + return Utilities::Reactant_find(this->Pressures, n_user); +} + +void +cxxStorageBin::Set_Pressure(int n_user, cxxPressure * entity) +{ + if (entity == NULL) + return; + Pressures[n_user] = *entity; +} +void + +cxxStorageBin::Remove_Pressure(int n_user) +{ + Pressures.erase(n_user); +} + const std::map < int, cxxSolution > & cxxStorageBin::Get_Solutions() const { @@ -331,7 +353,11 @@ cxxStorageBin::Get_Temperatures() const { return this->Temperatures; } - +const std::map < int, cxxPressure > & +cxxStorageBin::Get_Pressures() const +{ + return this->Pressures; +} #ifdef SKIP void cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -827,6 +853,9 @@ cxxStorageBin::Remove(int n) // Temperature this->Temperatures.erase(n); + + // Pressure + this->Pressures.erase(n); } void cxxStorageBin::Clear(void) @@ -862,6 +891,9 @@ cxxStorageBin::Clear(void) // Temperature this->Temperatures.clear(); + // Pressure + this->Pressures.clear(); + } #ifdef SKIP cxxSolution * @@ -1490,6 +1522,15 @@ cxxStorageBin::Set_System(struct Use *use_ptr) this->system.Set_Temperature(&(it->second)); } } + // reaction pressure + if (use_ptr->pressure_ptr != NULL) + { + cxxPressure * p = Utilities::Reactant_find(this->Pressures, use_ptr->n_pressure_user); + if (p != NULL) + { + this->system.Set_Pressure(p); + } + } } void cxxStorageBin::Set_System(int i) @@ -1578,4 +1619,9 @@ cxxStorageBin::Set_System(int i) this->system.Set_Temperature(&(it->second)); } } + + // reaction pressure + { + this->system.Set_Pressure(Utilities::Reactant_find(this->Pressures, i)); + } } diff --git a/StorageBin.h b/StorageBin.h index c03441c9..47175d27 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -72,6 +72,10 @@ class cxxStorageBin: public PHRQ_base void Set_Temperature(int n_user, cxxTemperature * entity); void Remove_Temperature(int n_user); + cxxPressure *Get_Pressure(int n_user); + void Set_Pressure(int n_user, cxxPressure * entity); + void Remove_Pressure(int n_user); + cxxSystem &Get_System(void); void Set_System(struct Use *use_ptr); void Set_System(int i); @@ -98,6 +102,7 @@ class cxxStorageBin: public PHRQ_base const std::map < int, cxxMix > &Get_Mixes() const; const std::map < int, cxxReaction > &Get_Reactions() const; const std::map < int, cxxTemperature > &Get_Temperatures() const; + const std::map < int, cxxPressure > &Get_Pressures() const; cxxSystem & Get_system(void) {return system;}; #ifdef USE_MPI @@ -122,6 +127,7 @@ class cxxStorageBin: public PHRQ_base std::map < int, cxxMix > Mixes; std::map < int, cxxReaction > Reactions; std::map < int, cxxTemperature > Temperatures; + std::map < int, cxxPressure > Pressures; cxxSystem system; }; diff --git a/System.cxx b/System.cxx index 897c6995..5aa91ac2 100644 --- a/System.cxx +++ b/System.cxx @@ -29,6 +29,7 @@ PHRQ_base(io) this->mix = NULL; this->reaction = NULL; this->temperature = NULL; + this->pressure = NULL; } cxxSystem::~cxxSystem(void) { @@ -46,6 +47,7 @@ cxxSystem::Initialize(void) this->mix = NULL; this->reaction = NULL; this->temperature = NULL; + this->pressure = NULL; } void cxxSystem::totalize(PHREEQC_PTR_ARG) diff --git a/System.h b/System.h index defcaec7..b1860f78 100644 --- a/System.h +++ b/System.h @@ -22,6 +22,7 @@ class cxxSSassemblage; class cxxSurface; class cxxReaction; class cxxTemperature; +class cxxPressure; class cxxMix; class cxxSystem: public PHRQ_base @@ -70,6 +71,10 @@ public: { this->temperature = entity; } + void Set_Pressure(cxxPressure * entity) + { + this->pressure = entity; + } void totalize(PHREEQC_PTR_ARG); cxxNameDouble &Get_Totals(void) { @@ -87,6 +92,7 @@ protected: cxxMix * mix; cxxReaction * reaction; cxxTemperature * temperature; + cxxPressure * pressure; cxxNameDouble totals; }; From 23a8009798269dd793d9ddf882cbf722d7da24bf Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 1 Dec 2011 22:42:19 +0000 Subject: [PATCH 0352/1077] updated for g++ git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5845 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Utils.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Utils.h b/Utils.h index 796c068e..01b57fef 100644 --- a/Utils.h +++ b/Utils.h @@ -51,7 +51,8 @@ namespace Utilities // return (b.find(i) != b.end()); //} - template < typename T > T * Reactant_find(std::map < int, T > &b, int i) + template < typename T > + T * Reactant_find(std::map < int, T > &b, int i) { if (b.find(i) != b.end()) { @@ -63,9 +64,10 @@ namespace Utilities } } - template < typename T > T * Reactant_copy(std::map < int, T > &b, int i, int j) + template < typename T > + T * Reactant_copy(std::map < int, T > &b, int i, int j) { - std::map < int, T >::iterator it; + typename std::map < int, T >::iterator it; it = b.find(i); if (it != b.end()) { @@ -82,7 +84,7 @@ namespace Utilities } /* - template + template bool exists (std::map b, int i){ return (b.find(i) != b.end());} */ From 0a98983f486de8cc7bbeeee0a96532f4dd07353f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 2 Dec 2011 00:07:18 +0000 Subject: [PATCH 0353/1077] Think reaction_pressure is done. worked on dumper and copy. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5846 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + Phreeqc.h | 1 + ReadClass.cxx | 23 +++++ StorageBinList.cpp | 16 ++- StorageBinList.h | 2 + dumper.cpp | 240 ++++++++++++++++++++++++++++++++++++++++++++- dumper.h | 2 + 7 files changed, 280 insertions(+), 5 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7a8f072f..94bd4c9d 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -660,6 +660,7 @@ void Phreeqc::init(void) copy_mix.n_user = copy_mix.start = copy_mix.end = 0; copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0; set_forward_output_to_log(FALSE); simulation = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 2e1622fd..e5a12014 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1418,6 +1418,7 @@ protected: struct copier copy_mix; struct copier copy_irrev; struct copier copy_temperature; + struct copier copy_pressure; /*---------------------------------------------------------------------- * Inverse diff --git a/ReadClass.cxx b/ReadClass.cxx index df38cf27..f492b3cc 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -5,6 +5,7 @@ #include #include +#include "Utils.h" #include "Phreeqc.h" #include "Phreeqc_class.h" #include "Parser.h" @@ -2703,10 +2704,32 @@ dump_ostream(std::ostream& os) } } + // pressure + if (dump_info.Get_bool_pressure()) + { + if (dump_info.Get_pressure().size() == 0) + { + Utilities::Reactant_dump_map_raw(Reaction_pressure_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_pressure().begin(); it != dump_info.Get_pressure().end(); it++) + { + cxxPressure *p = Utilities::Reactant_find(Reaction_pressure_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } // Turn off any reaction calculation os << "USE mix none" << std::endl; os << "USE reaction none" << std::endl; os << "USE reaction_temperature none" << std::endl; + os << "USE reaction_pressure none" << std::endl; // Turn off dump until next read dump_info.SetAll(false); diff --git a/StorageBinList.cpp b/StorageBinList.cpp index b6177895..53d4023b 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -127,6 +127,7 @@ void StorageBinList::SetAll(bool tf) this->mix.Clear(); this->reaction.Clear(); this->temperature.Clear(); + this->pressure.Clear(); this->solution.Set_defined(tf); this->pp_assemblage.Set_defined(tf); @@ -138,6 +139,7 @@ void StorageBinList::SetAll(bool tf) this->mix.Set_defined(tf); this->reaction.Set_defined(tf); this->temperature.Set_defined(tf); + this->pressure.Set_defined(tf); } bool StorageBinList::Read(CParser & parser) @@ -160,10 +162,12 @@ bool StorageBinList::Read(CParser & parser) vopts.push_back("mix"); vopts.push_back("reaction"); vopts.push_back("temperature"); - vopts.push_back("all"); + vopts.push_back("all"); // 13 vopts.push_back("cell"); vopts.push_back("cells"); // 15 vopts.push_back("reaction_temperature"); + vopts.push_back("pressure"); //17 + vopts.push_back("reaction_pressure"); //18 } std::istream::pos_type next_char; @@ -229,12 +233,16 @@ bool StorageBinList::Read(CParser & parser) case 15: item = &cell_list; break; + case 17: + case 18: + item = &(this->Get_pressure()); + break; default: break; } // Read dump entity list of numbers or number ranges for line, store in item - if ((opt >= 0 && opt <= 12) || (opt >= 14 && opt <= 15)) + if ((opt >= 0 && opt <= 12) || (opt >= 14)) { for (;;) { @@ -278,6 +286,9 @@ bool StorageBinList::Read(CParser & parser) case 10: case 11: case 12: + case 16: + case 17: + case 18: break; case 13: //all this->SetAll(true); @@ -318,5 +329,6 @@ void StorageBinList::TransferAll(StorageBinListItem &source) this->mix.Augment(*it); this->reaction.Augment(*it); this->temperature.Augment(*it); + this->pressure.Augment(*it); } } diff --git a/StorageBinList.h b/StorageBinList.h index 0bc05b4b..3101fa1a 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -43,6 +43,7 @@ public: StorageBinListItem & Get_mix(void) { return(this->mix); }; StorageBinListItem & Get_reaction(void) { return(this->reaction); }; StorageBinListItem & Get_temperature(void) { return(this->temperature); }; + StorageBinListItem & Get_pressure(void) { return(this->pressure); }; protected: StorageBinListItem solution; StorageBinListItem pp_assemblage; @@ -54,6 +55,7 @@ protected: StorageBinListItem mix; StorageBinListItem reaction; StorageBinListItem temperature; + StorageBinListItem pressure; }; diff --git a/dumper.cpp b/dumper.cpp index b233426d..d5473fc5 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -28,8 +28,229 @@ void dumper::SetAll(bool tf) { this->binList.SetAll(tf); +}bool dumper::Read(CParser & parser) +{ + bool return_value(true); + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(20); + vopts.push_back("file"); // 0 + vopts.push_back("append"); // 1 + vopts.push_back("all"); // 2 + vopts.push_back("cell"); // 3 + vopts.push_back("cells"); // 4 + vopts.push_back("solution"); // 5 + vopts.push_back("solutions"); // 6 + vopts.push_back("pp_assemblage"); + vopts.push_back("pp_assemblages"); + vopts.push_back("equilibrium_phase"); + vopts.push_back("equilibrium_phases"); // 10 + vopts.push_back("exchange"); + vopts.push_back("surface"); + vopts.push_back("s_s_assemblage"); + vopts.push_back("solid_solution"); + vopts.push_back("solid_solutions"); // 15 + vopts.push_back("gas_phase"); + vopts.push_back("gas_phases"); + vopts.push_back("kinetics"); // 18 + vopts.push_back("mix"); // 19 + vopts.push_back("reaction"); // 20 + vopts.push_back("reactions"); // 21 + vopts.push_back("temperature"); // 22 + vopts.push_back("reaction_temperature"); // 23 + vopts.push_back("reaction_temperatures"); // 24 + vopts.push_back("pressure"); // 25 + vopts.push_back("reaction_pressure"); // 26 + vopts.push_back("reaction_pressures"); // 27 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + + // Read mix number and description + //this->read_number_description(parser); + + opt_save = CParser::OPT_DEFAULT; + + for (;;) + { + int opt; + StorageBinListItem cells; + opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + else + { + opt_save = opt; + } + + // Select StorageBinListItem + StorageBinListItem *item = NULL; + switch (opt) + { + case 3: // cell + case 4: // cells + item = &cells; + break; + case 5: + case 6: + item = &(this->binList.Get_solution()); + break; + case 7: + case 8: + case 9: + case 10: + item = &(this->binList.Get_pp_assemblage()); + break; + case 11: + item = &(this->binList.Get_exchange()); + break; + case 12: + item = &(this->binList.Get_surface()); + break; + case 13: + case 14: + case 15: + item = &(this->binList.Get_s_s_assemblage()); + break; + case 16: + case 17: + item = &(this->binList.Get_gas_phase()); + break; + case 18: + item = &(this->binList.Get_kinetics()); + break; + + case 19: // mix + item = &(this->binList.Get_mix()); + break; + case 20: // reaction + case 21: // reactions + item = &(this->binList.Get_reaction()); + break; + case 22: // temperature + case 23: // reaction_temperature + case 24: // reaction_temperatures + item = &(this->binList.Get_temperature()); + break; + case 25: // pressure + case 26: // reaction_pressure + case 27: // reaction_pressures + item = &(this->binList.Get_pressure()); + break; + default: + break; + } + + // Read dump entity list of numbers or number ranges for line, store in item + if ((opt >= 4)) + { + for (;;) + { + CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); + if (j == CParser::TT_DIGIT) + { + item->Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + item->Augment(token); + break; + } + else + { + parser.error_msg("Expected single number or range of numbers.", + CParser::OT_CONTINUE); + } + } + } + + if (opt == 3 || opt == 4) + { + this->binList.TransferAll(cells); + } + // Process other identifiers + std::set < int >::iterator it; + switch (opt) + { + case CParser::OPT_EOF: + break; + case CParser::OPT_KEYWORD: + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + break; + case 0: //file + std::getline(parser.get_iss(), this->file_name); + this->file_name = trim(this->file_name, " \t"); + if (this->file_name.size() == 0) + { + this->file_name = "dump.out"; + } + + break; + case 1: //append + { + parser.copy_token(token, next_char); + //if (!(parser.get_iss() >> this->append)) + this->append = true; + if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') + { + this->append = false; + } + } + break; + case 2: //all + this->SetAll(true); + break; + default: + case CParser::OPT_DEFAULT: + case CParser::OPT_ERROR: + opt = CParser::OPT_EOF; + parser.error_msg("Unknown input reading DUMP definition.", + CParser::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + useLastLine = false; + return_value = false; + break; + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + return(return_value); } +#ifdef SKIP bool dumper::Read(CParser & parser) { @@ -63,6 +284,9 @@ bool dumper::Read(CParser & parser) vopts.push_back("temperature"); // 22 vopts.push_back("reaction_temperature"); // 23 vopts.push_back("reaction_temperatures"); // 24 + vopts.push_back("pressure"); // 25 + vopts.push_back("reaction_pressure"); // 26 + vopts.push_back("reaction_pressures"); // 27 } std::istream::pos_type ptr; @@ -138,12 +362,17 @@ bool dumper::Read(CParser & parser) case 24: // reaction_temperatures item = &(this->binList.Get_temperature()); break; + case 25: // pressure + case 26: // reaction_pressure + case 27: // reaction_pressures + item = &(this->binList.Get_pressure()); + break; default: break; } // Read dump entity list of numbers or number ranges for line, store in item - if ((opt >= 0 && opt <= 13) || (opt >= 17 && opt <= 23)) + if ((opt >= 0 && opt <= 13) || (opt >= 17 && opt <= 28)) { for (;;) { @@ -199,6 +428,10 @@ bool dumper::Read(CParser & parser) case 21: case 22: case 23: + case 24: + case 25: + case 26: + case 27: break; case 14: //file std::getline(parser.get_iss(), this->file_name); @@ -241,7 +474,7 @@ bool dumper::Read(CParser & parser) } return(return_value); } - +#endif bool dumper::Get_bool_any(void) { return ( @@ -254,6 +487,7 @@ bool dumper::Get_bool_any(void) Get_bool_kinetics() || Get_bool_mix() || Get_bool_reaction() || - Get_bool_temperature() + Get_bool_temperature() || + Get_bool_pressure() ); } diff --git a/dumper.h b/dumper.h index 44f57f96..3e9bd733 100644 --- a/dumper.h +++ b/dumper.h @@ -27,6 +27,7 @@ public: bool Get_bool_mix(void) { return(this->binList.Get_mix().Get_defined()); }; bool Get_bool_reaction(void) { return(this->binList.Get_reaction().Get_defined()); }; bool Get_bool_temperature(void) { return(this->binList.Get_temperature().Get_defined()); }; + bool Get_bool_pressure(void) { return(this->binList.Get_pressure().Get_defined()); }; bool Get_bool_any(void); std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; @@ -39,6 +40,7 @@ public: std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; std::set < int > & Get_reaction(void) { return(this->binList.Get_reaction().Get_numbers()); }; std::set < int > & Get_temperature(void) { return(this->binList.Get_temperature().Get_numbers()); }; + std::set < int > & Get_pressure(void) { return(this->binList.Get_pressure().Get_numbers()); }; protected: std::string file_name; bool append; From 2887acf828e7dabbde4c14c5b003ac28dd9bb631 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 2 Dec 2011 00:43:08 +0000 Subject: [PATCH 0354/1077] my bug in read dumper git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5848 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dumper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dumper.cpp b/dumper.cpp index d5473fc5..426d0228 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -149,7 +149,7 @@ void dumper::SetAll(bool tf) } // Read dump entity list of numbers or number ranges for line, store in item - if ((opt >= 4)) + if ((opt > 2)) { for (;;) { From e803c8dbc1282615b84dbb7bb69557be79359b4c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 2 Dec 2011 23:45:11 +0000 Subject: [PATCH 0355/1077] Fixed but in TRIM. Added routine to switch back to input stream after a parser. PHRQ_io_output error msg still needs a \n to make the screen paint correctly. See if change works for Scott. Need to move last line from parser to line. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5855 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 13 ++----------- Phreeqc.h | 1 + 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 8af3380e..2c86f090 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2371,7 +2371,7 @@ factor(struct LOC_exec * LINK) require(tokrp, LINK); //PhreeqcPtr->string_trim(string1); //n.UU.sval = PhreeqcPtr->string_duplicate(string1); - trim(STR1); + STR1 = trim(STR1); n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; @@ -4859,16 +4859,7 @@ cmderase(struct LOC_exec *LINK) v = LINK->t->UU.vp; LINK->t = LINK->t->next; - if (v->stringvar) - { - free_dim_stringvar(v); - } - else - { - PhreeqcPtr->free_check_null(v->UU.U0.arr); - v->UU.U0.arr = NULL; - } - v->numdims = 0; + clearvar(v); if (!iseos(LINK)) require(tokcomma, LINK); } while (!iseos(LINK)); diff --git a/Phreeqc.h b/Phreeqc.h index e5a12014..9ad6444e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -714,6 +714,7 @@ public: int read_user_graph_handler(); #endif int next_keyword_or_option(const char **opt_list, int count_opt_list); + int cleanup_after_parser(CParser &parser); // ReadClass.cxx From 2e64a171994cb89fad938696704fa73aa3a560eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 5 Dec 2011 16:46:43 +0000 Subject: [PATCH 0356/1077] Minor fix to REACTION_PRESSURE git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5858 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Pressure.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Pressure.cxx b/Pressure.cxx index 3f1cdaf8..71998ca9 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -82,6 +82,7 @@ cxxPressure::read(CParser & parser) for (;;) { + if (done) break; // new token std::string token; CParser::TOKEN_TYPE k = parser.copy_token(token, next_char); From 6bca210514b233b8c1cccc837d3298abe0ab5c6e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 5 Dec 2011 20:07:54 +0000 Subject: [PATCH 0357/1077] Linux version of all examples for version 3. Linux version of mytest with new gas.dat from Tony. Updated Makefile for compiling on Linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5861 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 357 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 192 insertions(+), 165 deletions(-) diff --git a/Makefile b/Makefile index 4d2060d2..b4614919 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,7 @@ COMMON_CXXOBJS = \ GasPhase.o \ ISolution.o \ ISolutionComp.o \ + Keywords.o \ KineticsComp.o \ cxxKinetics.o \ cxxMix.o \ @@ -190,6 +191,7 @@ COMMON_CXXOBJS = \ PHRQ_io.o \ PPassemblageComp.o \ PPassemblage.o \ + Pressure.o \ Reaction.o \ ReadClass.o \ runner.o \ @@ -227,11 +229,11 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../cxxKinetics.h \ - ../NumKeyword.h ../KineticsComp.h ../NameDouble.h ../Parser.h \ - ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxKinetics.h ../NumKeyword.h ../KineticsComp.h ../NameDouble.h \ + ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ @@ -241,36 +243,37 @@ Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../cxxMix.h ../NumKeyword.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../Parser.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../cxxMix.h ../NumKeyword.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../ExchComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../ExchComp.h ../NameDouble.h ../Parser.h \ + ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../GasPhase.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ - ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../GasPhase.h ../NumKeyword.h ../NameDouble.h \ + ../Parser.h ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../ISolutionComp.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../ISolutionComp.h ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../ISolution.h \ - ../ISolutionComp.h ../Solution.h ../NumKeyword.h \ + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../ISolution.h ../ISolutionComp.h ../Solution.h ../NumKeyword.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ @@ -278,63 +281,72 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../KineticsComp.h \ - ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../KineticsComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../NameDouble.h \ - ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h -Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h + ../Parser.h ../Keywords.h +Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../PPassemblageComp.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../PPassemblageComp.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../PPassemblage.h \ - ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h ../Parser.h \ - ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../PPassemblage.h ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ + ../Parser.h ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h +Pressure.o: ../Pressure.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Pressure.h \ + ../NumKeyword.h ../phreeqc/phqalloc.h Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Reaction.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../Reaction.h ../NumKeyword.h ../NameDouble.h \ + ../Parser.h ../phreeqc/phqalloc.h ReadClass.o: ../ReadClass.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Phreeqc_class.h ../Parser.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../NameDouble.h \ - ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../PPassemblage.h ../PPassemblageComp.h \ - ../cxxKinetics.h ../KineticsComp.h ../SSassemblage.h ../GasPhase.h \ - ../Reaction.h ../cxxMix.h ../Temperature.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../Phreeqc_class.h ../Parser.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../NameDouble.h ../Exchange.h ../ExchComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ + ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ + ../Temperature.h ../phreeqc/phqalloc.h Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../Phreeqc_class.h \ ../cxxMix.h ../phreeqc/phqalloc.h SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ @@ -342,158 +354,167 @@ SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SolutionIsotope.h \ - ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SolutionIsotope.h ../Parser.h ../phreeqc/phqalloc.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ + ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SSassemblage.h \ - ../NumKeyword.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ - ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SSassemblage.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ + ../Phreeqc_class.h ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SSassemblageSS.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SSassemblageSS.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../NameDouble.h \ - ../Parser.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ - ../SSassemblage.h ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../cxxMix.h ../Reaction.h ../Temperature.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Parser.h ../StorageBin.h ../System.h \ + ../Phreeqc_class.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ + ../Temperature.h ../phreeqc/phqalloc.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SurfaceCharge.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SurfaceCharge.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../SurfaceComp.h \ - ../Phreeqc_class.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ + ../phreeqc/phqalloc.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Surface.h \ - ../NumKeyword.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Surface.h ../NumKeyword.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../System.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ - ../SSassemblage.h ../NumKeyword.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../cxxMix.h ../Reaction.h ../Temperature.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../System.h ../NameDouble.h ../Parser.h \ + ../Phreeqc_class.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ + ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ + ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Temperature.h \ ../NumKeyword.h ../phreeqc/phqalloc.h -Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h -ChartHandler.o: ../ChartHandler.cpp -ChartObject.o: ../ChartObject.cpp +Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ../Keywords.h class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ - ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../NameDouble.h ../Parser.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h \ + ../KineticsComp.h CurveObject.o: ../CurveObject.cpp ../CurveObject.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h + ../Parser.h ../Keywords.h +Keywords.o: ../Keywords.cpp ../Keywords.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../PHRQ_io.h ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h + ../PHRQ_io.h ../Keywords.h ../phreeqc/phqalloc.h ../NameDouble.h \ + ../Parser.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Phreeqc_class.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ - ../ExchComp.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h \ - ../phreeqc/phqalloc.h ../PBasic.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../NameDouble.h ../Parser.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h \ + ../KineticsComp.h ../phreeqc/phqalloc.h ../PBasic.h PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../phreeqc/NA.h + ../Parser.h ../Keywords.h ../phreeqc/NA.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h + ../PHRQ_base.h ../Parser.h ../Keywords.h advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../PBasic.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h \ + ../phreeqc/../Parser.h ../phreeqc/../PHRQ_base.h \ + ../phreeqc/../Keywords.h ../phreeqc/../PBasic.h cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h @@ -501,39 +522,40 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h input.o: ../phreeqc/input.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h kinetics.o: ../phreeqc/kinetics.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ - ../Parser.h ../Phreeqc_class.h ../Reaction.h ../NumKeyword.h \ - ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h ../StorageBin.h ../System.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Reaction.h \ + ../NumKeyword.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ ../PPassemblage.h ../PPassemblageComp.h ../Surface.h ../SurfaceComp.h \ ../SurfaceCharge.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -542,14 +564,14 @@ mainsubs.o: ../phreeqc/mainsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../PBasic.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h ../PBasic.h model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h nvector_serial.o: ../phreeqc/nvector_serial.cpp \ @@ -560,64 +582,69 @@ parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h prep.o: ../phreeqc/prep.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h print.o: ../phreeqc/print.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h read.o: ../phreeqc/read.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h ../Pressure.h ../NumKeyword.h \ + ../Parser.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Phreeqc_class.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/../SSassemblageSS.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h ../phreeqc/phrqtype.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../PHRQ_io.h \ + ../phreeqc/../SSassemblageSS.h ../Phreeqc.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h @@ -625,28 +652,28 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ - ../Parser.h ../Phreeqc_class.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SSassemblageSS.h \ - ../NameDouble.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h ../StorageBin.h ../System.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Solution.h \ + ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SSassemblageSS.h ../NameDouble.h structures.o: ../phreeqc/structures.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h \ - ../phreeqc/../cxxMix.h ../phreeqc/../NumKeyword.h \ + ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/../cxxMix.h ../phreeqc/../NumKeyword.h \ ../phreeqc/../PHRQ_base.h ../phreeqc/../Exchange.h \ ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../Parser.h ../phreeqc/../GasPhase.h \ + ../phreeqc/../Parser.h ../phreeqc/../Keywords.h ../phreeqc/../GasPhase.h \ ../phreeqc/../Phreeqc_class.h ../phreeqc/../cxxKinetics.h \ ../phreeqc/../KineticsComp.h ../phreeqc/../PPassemblage.h \ ../phreeqc/../PPassemblageComp.h ../phreeqc/../PPassemblageComp.h \ @@ -664,26 +691,26 @@ tally.o: ../phreeqc/tally.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h tidy.o: ../phreeqc/tidy.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h transport.o: ../phreeqc/transport.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug From 23f209d9926a9aa4b3ee57ff6e04f8395583de35 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Dec 2011 00:49:59 +0000 Subject: [PATCH 0358/1077] added guards for phrq_io git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5863 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 94bd4c9d..9497012c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -144,8 +144,11 @@ Phreeqc::~Phreeqc(void) { clean_up(); - this->phrq_io->close_input_files(); - this->phrq_io->close_output_files(); + if (phrq_io) + { + this->phrq_io->close_input_files(); + this->phrq_io->close_output_files(); + } int i; for (i = 0; i < count_iso_defaults; i++) From 6fb5faa23b32a9b3aa750560995768d7cbbf10b9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Dec 2011 02:48:53 +0000 Subject: [PATCH 0359/1077] added PHRQ_io member git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5864 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 15 ++------------- Phreeqc.h | 4 ++-- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9497012c..b143a37c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -17,13 +17,11 @@ Phreeqc::Phreeqc(PHRQ_io *io) { if (io) { - delete_phrq_io = false; phrq_io = io; } else { - delete_phrq_io = true; - phrq_io = new PHRQ_io; + phrq_io = &this->ioInstance; } phast = FALSE; @@ -161,10 +159,6 @@ Phreeqc::~Phreeqc(void) free_check_null(sformatf_buffer); PHRQ_free_all(); - if (this->phrq_io && this->delete_phrq_io) - { - delete this->phrq_io; - } } void Phreeqc::set_phast(int tf) @@ -888,12 +882,7 @@ void Phreeqc::init(void) return; } -void Phreeqc::set_io(PHRQ_io *io, bool auto_delete) +void Phreeqc::set_io(PHRQ_io *io) { - if (this->phrq_io && this->delete_phrq_io) - { - delete this->phrq_io; - } - this->delete_phrq_io = auto_delete; this->phrq_io = io; } diff --git a/Phreeqc.h b/Phreeqc.h index 9ad6444e..954b9f12 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1320,7 +1320,7 @@ public: //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); void set_phast(int); - void set_io(PHRQ_io *io, bool auto_delete = false); + void set_io(PHRQ_io *io); size_t list_components(std::list &list_c); std::istream *get_istream(); void pop_istream(); @@ -1337,7 +1337,7 @@ protected: std::list delete_istream_list; PHRQ_io *phrq_io; - bool delete_phrq_io; + PHRQ_io ioInstance; /* ---------------------------------------------------------------------- * STRUCTURES From 1f7e4e16e92f849b3b796243c279d9262436c38d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Dec 2011 06:00:34 +0000 Subject: [PATCH 0360/1077] added IPQ_DLL_EXPORT for IPhreeqc dll versions git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5865 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index 112847f3..e513e48e 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -1,11 +1,18 @@ #ifndef _PHRQIO_H #define _PHRQIO_H +#if defined(_WINDLL) +#define IPQ_DLL_EXPORT __declspec(dllexport) +#else +#define IPQ_DLL_EXPORT +#endif + #include class PhreeqcStop : std::exception { }; -class PHRQ_io + +class IPQ_DLL_EXPORT PHRQ_io { public: // constructor/destructor From b260023bbf81d478db97c5a4d7d2f767dbd70c7d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Dec 2011 07:30:12 +0000 Subject: [PATCH 0361/1077] replaced dump_file with dump_ostream git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5867 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 49 ++++++++++++++++++++++++++++++------------------- PHRQ_io.h | 12 ++++++++---- ReadClass.cxx | 34 ++++++++++++++++------------------ 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 0030c12c..3e856105 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -14,7 +14,7 @@ PHRQ_io(void) log_file = NULL; punch_file = NULL; error_file = NULL; - dump_file = NULL; + dump_ostream = NULL; io_error_count = 0; output_file_on = true; @@ -68,10 +68,14 @@ PHRQ_io::Set_punch_file(FILE * out) this->punch_file = out; } void -PHRQ_io::Set_dump_file(FILE * out) +PHRQ_io::Set_dump_ostream(std::ostream *os) { - safe_close(&this->dump_file); - this->dump_file = out; + this->dump_ostream = os; +} +std::ostream * +PHRQ_io::Get_dump_ostream(void) +{ + return this->dump_ostream; } // ---------------------------------------------------------------------- */ @@ -371,11 +375,10 @@ error_msg(const char *err_str, bool stop) /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -dump_open(const char *file_name) +dump_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - safe_close(&dump_file); - if ((dump_file = fopen(file_name, "w")) == NULL) + if ((dump_ostream = new std::ofstream(file_name, mode)) == NULL) { return false; // error } @@ -386,9 +389,9 @@ void PHRQ_io:: dump_fflush(void) /* ---------------------------------------------------------------------- */ { - if (dump_file && dump_file_on) + if (dump_ostream && dump_file_on) { - fflush(dump_file); + dump_ostream->flush(); } } /* ---------------------------------------------------------------------- */ @@ -396,16 +399,17 @@ void PHRQ_io:: dump_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&dump_file); + delete dump_ostream; + dump_ostream = NULL; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: dump_rewind(void) /* ---------------------------------------------------------------------- */ { - if (dump_file && dump_file_on) + if (dump_ostream && dump_file_on) { - rewind(dump_file); + dump_ostream->seekp(0, std::ios_base::beg); } } /* ---------------------------------------------------------------------- */ @@ -413,8 +417,14 @@ bool PHRQ_io:: dump_isopen(void) /* ---------------------------------------------------------------------- */ { - if (dump_file) - return true; // open + if (dump_ostream) + { + if (std::ofstream *ofs = dynamic_cast(dump_ostream)) + { + return ofs->is_open(); + } + return true; + } return false; } /* ---------------------------------------------------------------------- */ @@ -422,9 +432,9 @@ void PHRQ_io:: dump_msg(const char * str) /* ---------------------------------------------------------------------- */ { - if (dump_file != NULL && dump_file_on) + if (dump_ostream != NULL && dump_file_on) { - fprintf(dump_file, "%s", str); + (*dump_ostream) << str; } } @@ -547,12 +557,13 @@ close_output_files(void) ret |= fclose(log_file); if (punch_file != NULL) ret |= fclose(punch_file); - if (dump_file != NULL) - ret |= fclose(dump_file); + if (dump_ostream != NULL) + delete dump_ostream; if (error_file != NULL) ret |= fclose(error_file); error_file = NULL; - output_file = log_file = punch_file = dump_file = NULL; + output_file = log_file = punch_file = NULL; + dump_ostream = NULL; return ret; } //safe_close is static method diff --git a/PHRQ_io.h b/PHRQ_io.h index e513e48e..f76a9bce 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -7,7 +7,10 @@ #define IPQ_DLL_EXPORT #endif -#include +#include +#include +#include + class PhreeqcStop : std::exception { }; @@ -60,7 +63,7 @@ public: void warning_msg(const char *err_str); // dump_file - bool dump_open(const char *file_name); + bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void dump_fflush(void); void dump_close(void); void dump_rewind(void); @@ -80,7 +83,8 @@ public: void Set_error_file(FILE * out); void Set_log_file(FILE * out); void Set_punch_file(FILE * out); - void Set_dump_file(FILE * out); + void Set_dump_ostream(std::ostream *dump_ostream); + std::ostream *Get_dump_ostream(void); // close input file void close_input(void); @@ -121,7 +125,7 @@ protected: FILE *log_file; FILE *punch_file; FILE *error_file; - FILE *dump_file; + std::ostream *dump_ostream; int io_error_count; bool output_file_on; diff --git a/ReadClass.cxx b/ReadClass.cxx index f492b3cc..ff0ebbcf 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1943,31 +1943,29 @@ int Phreeqc:: dump_entities(void) /* ---------------------------------------------------------------------- */ { - int return_value; - return_value = OK; if (!dump_info.Get_bool_any()) { return(OK); } - std::ofstream dump_stream; - if (dump_info.Get_append()) + if (this->phrq_io) { - //dump_stream.open(dump_info.get_file_name(), std::ios_base::app); - dump_stream.open(dump_info.Get_file_name().c_str(), std::ios_base::app); + std::ios_base::openmode mode = std::ios_base::out; + if (dump_info.Get_append()) + { + mode = std::ios_base::app; + } + if (this->phrq_io->dump_open(dump_info.Get_file_name().c_str(), mode)) + { + dump_ostream(*this->phrq_io->Get_dump_ostream()); + this->phrq_io->dump_close(); + } + else + { + sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.Get_file_name().c_str()); + error_msg(error_string, STOP); + } } - else - { - dump_stream.open(dump_info.Get_file_name().c_str()); - } - if (!dump_stream.is_open()) - { - sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.Get_file_name().c_str()); - error_msg(error_string, STOP); - } - - dump_ostream(dump_stream); - return (OK); } /* ---------------------------------------------------------------------- */ From 8cbaba8ea40ec07cd43b914f4f73de53eaeed4db Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 6 Dec 2011 23:28:12 +0000 Subject: [PATCH 0362/1077] Converted output to streams. Input streams are still in Phreeqc, not in PHRQ_io. Process_file_names and open_input_stream and open_output_stream are in PHRQ_io_output.cpp, maybe should be in PHRQ_io. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5869 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 499 +++++++++++++++++++--------------------------------- PHRQ_io.h | 134 +++++++------- Phreeqc.cpp | 6 +- Phreeqc.h | 40 +++-- 4 files changed, 270 insertions(+), 409 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 3e856105..ea091bf0 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -4,24 +4,26 @@ #include #include #include +#include +#include +#include PHRQ_io:: PHRQ_io(void) { - input_file = NULL; - database_file = NULL; - output_file = NULL; - log_file = NULL; - punch_file = NULL; - error_file = NULL; - dump_ostream = NULL; + output_ostream = NULL; + log_ostream = NULL; + punch_ostream = NULL; + error_ostream = NULL; + dump_ostream = NULL; + //screen_ostream = NULL; io_error_count = 0; - output_file_on = true; - log_file_on = false; - punch_file_on = true; - error_file_on = true; - dump_file_on = true; + output_on = true; + log_on = false; + punch_on = true; + error_on = true; + dump_on = true; screen_on = true; echo_on = true; echo_destination = ECHO_OUTPUT; @@ -31,64 +33,15 @@ PHRQ_io:: ~PHRQ_io() { } -void -PHRQ_io::Set_database_file(FILE * in) -{ - safe_close(&this->database_file); - this->database_file = in; -} -void -PHRQ_io::Set_input_file(FILE * in) -{ - safe_close(&this->input_file); - this->input_file = in; -} -void -PHRQ_io::Set_output_file(FILE * out) -{ - safe_close(&this->output_file); - this->output_file = out; -} -void -PHRQ_io::Set_error_file(FILE * out) -{ - safe_close(&this->error_file); - this->error_file = out; -} -void -PHRQ_io::Set_log_file(FILE * out) -{ - safe_close(&this->log_file); - this->log_file = out; -} -void -PHRQ_io::Set_punch_file(FILE * out) -{ - safe_close(&this->punch_file); - this->punch_file = out; -} -void -PHRQ_io::Set_dump_ostream(std::ostream *os) -{ - this->dump_ostream = os; -} -std::ostream * -PHRQ_io::Get_dump_ostream(void) -{ - return this->dump_ostream; -} - // ---------------------------------------------------------------------- */ -// output file methods +// output ostream methods // ---------------------------------------------------------------------- */ - /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -output_open(const char *file_name) +output_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - safe_close(&output_file); - if ((output_file = fopen(file_name, "w")) == NULL) + if ((output_ostream = new std::ofstream(file_name, mode)) == NULL) { return false; // error } @@ -96,12 +49,12 @@ output_open(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -output_fflush(void) +output_flush(void) /* ---------------------------------------------------------------------- */ { - if (output_file && output_file_on) + if (output_ostream) { - fflush(output_file); + output_ostream->flush(); } } /* ---------------------------------------------------------------------- */ @@ -109,48 +62,26 @@ void PHRQ_io:: output_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&output_file); -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -output_rewind(void) -/* ---------------------------------------------------------------------- */ -{ - if (output_file && output_file_on) - { - rewind(output_file); - } -} -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -output_isopen(void) -/* ---------------------------------------------------------------------- */ -{ - if (output_file) - return true; // open - return false; + safe_close(&log_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: output_msg(const char * str) /* ---------------------------------------------------------------------- */ { - if (output_file != NULL && output_file_on) + if (output_ostream != NULL && output_on) { - fprintf(output_file, "%s", str); + (*output_ostream) << str; } } // ---------------------------------------------------------------------- */ -// log file methods +// log ostream methods // ---------------------------------------------------------------------- */ - -/* ---------------------------------------------------------------------- */ bool PHRQ_io:: -log_open(const char *file_name) +log_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - safe_close(&log_file); - if ((log_file = fopen(file_name, "w")) == NULL) + if ((log_ostream = new std::ofstream(file_name, mode)) == NULL) { return false; // error } @@ -158,12 +89,12 @@ log_open(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -log_fflush(void) +log_flush(void) /* ---------------------------------------------------------------------- */ { - if (log_file && log_file_on) + if (log_ostream) { - fflush(log_file); + log_ostream->flush(); } } /* ---------------------------------------------------------------------- */ @@ -171,48 +102,26 @@ void PHRQ_io:: log_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&log_file); -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -log_rewind(void) -/* ---------------------------------------------------------------------- */ -{ - if (log_file && log_file_on) - { - rewind(log_file); - } -} -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -log_isopen(void) -/* ---------------------------------------------------------------------- */ -{ - if (log_file) - return true; // open - return false; + safe_close(&log_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: log_msg(const char * str) /* ---------------------------------------------------------------------- */ { - if (log_file != NULL && log_file_on) + if (log_ostream != NULL && log_on) { - fprintf(log_file, "%s", str); + (*log_ostream) << str; } } // ---------------------------------------------------------------------- */ -// punch file methods +// punch ostream methods // ---------------------------------------------------------------------- */ - -/* ---------------------------------------------------------------------- */ bool PHRQ_io:: -punch_open(const char *file_name) +punch_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - safe_close(&punch_file); - if ((punch_file = fopen(file_name, "w")) == NULL) + if ((punch_ostream = new std::ofstream(file_name, mode)) == NULL) { return false; // error } @@ -220,12 +129,12 @@ punch_open(const char *file_name) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -punch_fflush(void) +punch_flush(void) /* ---------------------------------------------------------------------- */ { - if (punch_file && punch_file_on) + if (punch_ostream) { - fflush(punch_file); + punch_ostream->flush(); } } /* ---------------------------------------------------------------------- */ @@ -233,71 +142,48 @@ void PHRQ_io:: punch_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&punch_file); -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -punch_rewind(void) -/* ---------------------------------------------------------------------- */ -{ - if (punch_file && punch_file_on) - { - rewind(punch_file); - } -} -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -punch_isopen(void) -/* ---------------------------------------------------------------------- */ -{ - if (punch_file) - return true; // open - return false; + safe_close(&punch_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: punch_msg(const char * str) /* ---------------------------------------------------------------------- */ { - if (punch_file != NULL && punch_file_on) + if (punch_ostream != NULL && punch_on) { - fprintf(punch_file, "%s", str); + (*punch_ostream) << str; } } - // ---------------------------------------------------------------------- */ // error file methods // ---------------------------------------------------------------------- */ - /* ---------------------------------------------------------------------- */ bool PHRQ_io:: -error_open(const char *file_name) +error_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - safe_close(&error_file); - if (file_name != NULL) { - if ((error_file = fopen(file_name, "w")) == NULL) + if ((error_ostream = new std::ofstream(file_name, mode)) == NULL) { - error_file = stderr; + error_ostream = &std::cerr; return false; } } else { - error_file = stderr; + error_ostream = &std::cerr; } return true; } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -error_fflush(void) +error_flush(void) /* ---------------------------------------------------------------------- */ { - if (error_file && error_file_on) + if (error_ostream) { - fflush(error_file); + error_ostream->flush(); } } /* ---------------------------------------------------------------------- */ @@ -305,26 +191,7 @@ void PHRQ_io:: error_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&error_file); -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -error_rewind(void) -/* ---------------------------------------------------------------------- */ -{ - if (error_file && error_file_on) - { - rewind(error_file); - } -} -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -error_isopen(void) -/* ---------------------------------------------------------------------- */ -{ - if (error_file) - return true; // open - return false; + safe_close(&error_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -333,46 +200,25 @@ error_msg(const char *err_str, bool stop) { io_error_count++; - if (error_file != NULL && error_file_on) + if (error_ostream != NULL && error_on) { - //fprintf(error_file, "\nERROR: %s\n", err_str); - fprintf(error_file, "%s", err_str); - fflush(error_file); + (*error_ostream) << err_str; + error_ostream->flush(); } - //if (output_file != NULL && output_file_on) - //{ - // fprintf(output_file, "ERROR: %s\n", err_str); - // fflush(output_file); - //} - //if (log_file != NULL && log_file_on) - //{ - // fprintf(log_file, "ERROR: %s\n", err_str); - // fflush(log_file); - //} if (stop) { - if (error_file != NULL && error_file_on) + if (error_ostream != NULL && error_on) { - fprintf(error_file, "Stopping.\n"); - fflush(error_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "Stopping.\n"); - fflush(output_file); - } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "Stopping.\n"); - fflush(log_file); + (*error_ostream) << "Stopping.\n"; + error_ostream->flush(); } + output_msg("Stopping.\n"); + log_msg("Stopping.\n"); } } - // ---------------------------------------------------------------------- */ -// dump file methods +// dump ostream methods // ---------------------------------------------------------------------- */ - /* ---------------------------------------------------------------------- */ bool PHRQ_io:: dump_open(const char *file_name, std::ios_base::openmode mode) @@ -386,10 +232,10 @@ dump_open(const char *file_name, std::ios_base::openmode mode) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -dump_fflush(void) +dump_flush(void) /* ---------------------------------------------------------------------- */ { - if (dump_ostream && dump_file_on) + if (dump_ostream) { dump_ostream->flush(); } @@ -399,73 +245,99 @@ void PHRQ_io:: dump_close(void) /* ---------------------------------------------------------------------- */ { - delete dump_ostream; - dump_ostream = NULL; -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -dump_rewind(void) -/* ---------------------------------------------------------------------- */ -{ - if (dump_ostream && dump_file_on) - { - dump_ostream->seekp(0, std::ios_base::beg); - } -} -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -dump_isopen(void) -/* ---------------------------------------------------------------------- */ -{ - if (dump_ostream) - { - if (std::ofstream *ofs = dynamic_cast(dump_ostream)) - { - return ofs->is_open(); - } - return true; - } - return false; + safe_close(&dump_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: dump_msg(const char * str) /* ---------------------------------------------------------------------- */ { - if (dump_ostream != NULL && dump_file_on) + if (dump_ostream != NULL && dump_on) { (*dump_ostream) << str; } } - - - -void -PHRQ_io::close_input(void) -{ - safe_close(&input_file); -} +///* ---------------------------------------------------------------------- */ +//void PHRQ_io:: +//dump_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (dump_ostream && dump_on) +// { +// dump_ostream->seekp(0, std::ios_base::beg); +// } +//} +///* ---------------------------------------------------------------------- */ +//bool PHRQ_io:: +//dump_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (dump_ostream) +// { +// if (std::ofstream *ofs = dynamic_cast(dump_ostream)) +// { +// return ofs->is_open(); +// } +// return true; +// } +// return false; +//} +#ifdef SKIP +// ---------------------------------------------------------------------- */ +// screen ostream methods +// ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */ -int PHRQ_io:: -close_input_files(void) +bool PHRQ_io:: +screen_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - int i = 0; - if (database_file) + if ((screen_ostream = new std::ofstream(file_name, mode)) == NULL) { - i |= fclose(database_file); + return false; // error } - if (input_file) + return true; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (screen_ostream) { - i |= fclose(input_file); + screen_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&screen_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (screen_ostream != NULL && screen_on) + { + (*screen_ostream) << str; + } +} +#endif +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (error_ostream != NULL && screen_on) + { + (*error_ostream) << str; } - input_file = database_file = NULL; - return (i); } -//istream_getc is static *** int PHRQ_io:: -istream_getc(void *cookie) +istream_getc(void *cookie) //istream_getc is *** static *** { if (cookie) { @@ -479,38 +351,36 @@ istream_getc(void *cookie) } return EOF; } - - /* ---------------------------------------------------------------------- */ void PHRQ_io:: warning_msg(const char *err_str) /* ---------------------------------------------------------------------- */ { - if (error_file != NULL && error_file_on) + std::ostringstream warn_str; + warn_str << "WARNING: " << err_str << std::endl; + + //screen_msg("\n"); + if (error_ostream != NULL && error_on) { - fprintf(error_file, "\nWARNING: %s\n", err_str); - fflush(error_file); + (*error_ostream) << "\nWARNING: " << err_str << std::endl; + error_ostream->flush(); } - if (log_file != NULL && log_file_on) - { - fprintf(log_file, "WARNING: %s\n", err_str); - fflush(log_file); - } - if (output_file != NULL && output_file_on) - { - fprintf(output_file, "WARNING: %s\n", err_str); - fflush(output_file); - } + log_msg(warn_str.str().c_str()); + log_flush(); + output_msg(warn_str.str().c_str()); + output_flush(); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: fpunchf(const char *name, const char *format, double d) /* ---------------------------------------------------------------------- */ { - if (punch_file != NULL && punch_file_on) + if (punch_ostream != NULL && punch_on) { { - fprintf(punch_file, format, d); + char token[256]; + sprintf(token, format, d); + (*punch_ostream) << token; } } } @@ -519,10 +389,12 @@ void PHRQ_io:: fpunchf(const char *name, const char *format, char * s) /* ---------------------------------------------------------------------- */ { - if (punch_file != NULL && punch_file_on) + if (punch_ostream != NULL && punch_on) { { - fprintf(punch_file, format, s); + char token[256]; + sprintf(token, format, s); + (*punch_ostream) << token; } } } @@ -531,10 +403,12 @@ void PHRQ_io:: fpunchf(const char *name, const char *format, int d) /* ---------------------------------------------------------------------- */ { - if (punch_file != NULL && punch_file_on) + if (punch_ostream != NULL && punch_on) { { - fprintf(punch_file, format, d); + char token[256]; + sprintf(token, format, d); + (*punch_ostream) << token; } } } @@ -545,53 +419,48 @@ void PHRQ_io::fpunchf_end_row(const char *format) //NOOP for Phreeqc } /* ---------------------------------------------------------------------- */ -int PHRQ_io:: -close_output_files(void) +void PHRQ_io:: +close_output_ostreams(void) /* ---------------------------------------------------------------------- */ { - int ret = 0; + std::set streams; - if (output_file != NULL) - ret |= fclose(output_file); - if (log_file != NULL) - ret |= fclose(log_file); - if (punch_file != NULL) - ret |= fclose(punch_file); - if (dump_ostream != NULL) - delete dump_ostream; - if (error_file != NULL) - ret |= fclose(error_file); - error_file = NULL; - output_file = log_file = punch_file = NULL; + streams.insert(output_ostream); + streams.insert(log_ostream); + streams.insert(punch_ostream); + streams.insert(error_ostream); + streams.insert(dump_ostream); + //streams.insert(screen_ostream); + + std::set::iterator it = streams.begin(); + for (; it != streams.end(); it++) + { + std::ostream * x = *it; + safe_close(&x); + } + + output_ostream = NULL; + log_ostream = NULL; + punch_ostream = NULL; + error_ostream = NULL; dump_ostream = NULL; - return ret; + //screen_ostream = NULL; } //safe_close is static method /* ---------------------------------------------------------------------- */ void PHRQ_io:: -safe_close(FILE ** file_ptr) +safe_close(std::ostream **stream_ptr) /* ---------------------------------------------------------------------- */ { - if (*file_ptr != stderr && - *file_ptr != stdout && - *file_ptr != stdin && - *file_ptr != NULL) + if (*stream_ptr != &std::cerr && + *stream_ptr != &std::cout && + *stream_ptr != NULL) { - fclose(*file_ptr); - *file_ptr = NULL; + delete *stream_ptr; + *stream_ptr = NULL; } } -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_msg(const char * str) -/* ---------------------------------------------------------------------- */ -{ - if (screen_on) - { - fprintf(stderr, "%s", str); - } -} /* ---------------------------------------------------------------------- */ void PHRQ_io:: echo_msg(const char * str) diff --git a/PHRQ_io.h b/PHRQ_io.h index f76a9bce..402c1a4c 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -24,119 +24,107 @@ public: // methods static int istream_getc(void *cookie); - static void safe_close(FILE ** file_ptr); + static void safe_close(std::ostream **stream_ptr); + void close_output_ostreams(void); + void Set_io_error_count(int i) {this->io_error_count = i;}; + int Get_io_error_count(void) {return this->io_error_count;}; - int close_input_files(void); - int close_output_files(void); - - // output_file - bool output_open(const char *file_name); - void output_fflush(void); + // output_ostream + bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void output_flush(void); void output_close(void); - void output_rewind(void); - bool output_isopen(void); virtual void output_msg(const char * str); + void Set_output_ostream(std::ostream * out) {this->output_ostream = out;}; + std::ostream *Get_output_ostream(void) {return this->output_ostream;}; + void Set_output_on(bool tf) {this->output_on = tf;}; + bool Get_output_on(void) {return this->output_on;}; - // log_file - bool log_open(const char *file_name); - void log_fflush(void); + // log_ostream + bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void log_flush(void); void log_close(void); - void log_rewind(void); - bool log_isopen(void); void log_msg(const char * str); + void Set_log_ostream(std::ostream * out) {this->log_ostream = out;}; + std::ostream *Get_log_ostream(void) {return this->log_ostream;}; + void Set_log_on(bool tf) {this->log_on = tf;}; + bool Get_log_on(void) {return this->log_on;}; - // punch_file - virtual bool punch_open(const char *file_name); - void punch_fflush(void); + // punch_ostream + virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void punch_flush(void); void punch_close(void); - void punch_rewind(void); - bool punch_isopen(void); virtual void punch_msg(const char * str); - - // error_file - bool error_open(const char *file_name); - void error_fflush(void); + void Set_punch_ostream(std::ostream * out) {this->punch_ostream = out;}; + std::ostream *Get_punch_ostream(void) {return this->punch_ostream;}; + void Set_punch_on(bool tf) {this->punch_on = tf;}; + bool Get_punch_on(void) {return this->punch_on;}; + + // error_ostream + bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void error_flush(void); void error_close(void); - void error_rewind(void); - bool error_isopen(void); virtual void error_msg(const char * str, bool stop=false); + void Set_error_ostream(std::ostream * out) {this->error_ostream = out;}; + std::ostream *Get_error_ostream(void) {return this->error_ostream;}; + void Set_error_on(bool tf) {this->error_on = tf;}; + bool Get_error_on(void) {return this->error_on;}; void warning_msg(const char *err_str); - // dump_file + // dump_ostream bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); - void dump_fflush(void); + void dump_flush(void); void dump_close(void); - void dump_rewind(void); - bool dump_isopen(void); void dump_msg(const char * str); + void Set_dump_ostream(std::ostream * out) {this->dump_ostream = out;}; + std::ostream *Get_dump_ostream(void) {return this->dump_ostream;}; + void Set_dump_on(bool tf) {this->dump_on = tf;}; + bool Get_dump_on(void) {return this->dump_on;}; + // fpunchf virtual void fpunchf(const char *name, const char *format, double d); virtual void fpunchf(const char *name, const char *format, char * d); virtual void fpunchf(const char *name, const char *format, int d); virtual void fpunchf_end_row(const char *format); - void Set_io_error_count(int i) {this->io_error_count = i;}; - int Get_io_error_count(void) {return this->io_error_count;}; - void Set_database_file(FILE * in); - void Set_input_file(FILE * in); - void Set_output_file(FILE * out); - void Set_error_file(FILE * out); - void Set_log_file(FILE * out); - void Set_punch_file(FILE * out); - void Set_dump_ostream(std::ostream *dump_ostream); - std::ostream *Get_dump_ostream(void); - - // close input file - void close_input(void); - - void Set_output_file_on(bool tf) {this->output_file_on = tf;}; - void Set_log_file_on(bool tf) {this->log_file_on = tf;}; - void Set_punch_file_on(bool tf) {this->punch_file_on = tf;}; - void Set_error_file_on(bool tf) {this->error_file_on = tf;}; - void Set_dump_file_on(bool tf) {this->dump_file_on = tf;}; - - bool Get_output_file_on(void) {return this->output_file_on;}; - bool Get_log_file_on(void) {return this->log_file_on;}; - bool Get_punch_file_on(void) {return this->punch_file_on;}; - bool Get_error_file_on(void) {return this->error_file_on;}; - bool Get_dump_file_on(void) {return this->dump_file_on;}; - + // screen_ostream + //bool screen_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + //void screen_flush(void); + //void screen_close(void); virtual void screen_msg(const char * str); - void Set_screen_on(bool tf) {this->screen_on = tf;}; - bool Get_screen_on(void) {return this->screen_on;}; + //void Set_screen_ostream(std::ostream * out) {this->screen_ostream = out;}; + //std::ostream *Get_screen_ostream(void) {return this->screen_ostream;}; + void Set_screen_on(bool tf) {this->screen_on = tf;}; + bool Get_screen_on(void) {return this->screen_on;}; + // echo enum ECHO_OPTION { ECHO_LOG, ECHO_OUTPUT }; virtual void echo_msg(const char * str); - void Set_echo_on(bool tf) {this->echo_on = tf;}; - bool Get_echo_on(void) {return this->echo_on;}; + void Set_echo_on(bool tf) {this->echo_on = tf;}; + bool Get_echo_on(void) {return this->echo_on;}; void Set_echo_destination(ECHO_OPTION eo) {this->echo_destination = eo;}; ECHO_OPTION Get_echo_destination(void) {return this->echo_destination;}; - // data protected: - FILE *input_file; - FILE *database_file; - FILE *output_file; - FILE *log_file; - FILE *punch_file; - FILE *error_file; + std::ostream *output_ostream; + std::ostream *log_ostream; + std::ostream *punch_ostream; + std::ostream *error_ostream; std::ostream *dump_ostream; + //std::ostream *screen_ostream; int io_error_count; - bool output_file_on; - bool log_file_on; - bool punch_file_on; - bool error_file_on; - bool dump_file_on; + bool output_on; + bool log_on; + bool punch_on; + bool error_on; + bool dump_on; bool echo_on; bool screen_on; ECHO_OPTION echo_destination; - }; - #endif /* _PHRQIO_H */ diff --git a/Phreeqc.cpp b/Phreeqc.cpp index b143a37c..d3cc6585 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -142,10 +142,10 @@ Phreeqc::~Phreeqc(void) { clean_up(); - if (phrq_io) + if (phrq_io == &ioInstance) { - this->phrq_io->close_input_files(); - this->phrq_io->close_output_files(); + //this->phrq_io->close_input_files(); + this->phrq_io->close_output_ostreams(); } int i; diff --git a/Phreeqc.h b/Phreeqc.h index 954b9f12..0cbe7740 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -183,7 +183,11 @@ public: std::istream **input_cookie, int log); /* PHRQ_io_output.cpp */ - void screen_msg(const char *err_str); + //bool screen_open(const char *file_name); + //void screen_flush(void); + //void screen_close(void); + void screen_msg(const char * str); + void echo_msg(const char *err_str); int warning_msg(const char *err_str); void set_forward_output_to_log(int value); @@ -191,42 +195,42 @@ public: // dump_file bool dump_open(const char *file_name); - void dump_fflush(void); + void dump_flush(void); void dump_close(void); - void dump_rewind(void); - bool dump_isopen(void); + //void dump_rewind(void); + //bool dump_isopen(void); void dump_msg(const char * str); // log_file bool log_open(const char *file_name); - void log_fflush(void); + void log_flush(void); void log_close(void); - void log_rewind(void); - bool log_isopen(void); + //void log_rewind(void); + //bool log_isopen(void); void log_msg(const char * str); // error_file bool error_open(const char *file_name); - void error_fflush(void); + void error_flush(void); void error_close(void); - void error_rewind(void); - bool error_isopen(void); + //void error_rewind(void); + //bool error_isopen(void); void error_msg(const char * str, bool stop=false); // output_file bool output_open(const char *file_name); - void output_fflush(void); + void output_flush(void); void output_close(void); - void output_rewind(void); - bool output_isopen(void); + //void output_rewind(void); + //bool output_isopen(void); void output_msg(const char * str); // punch_file bool punch_open(const char *file_name); - void punch_fflush(void); + void punch_flush(void); void punch_close(void); - void punch_rewind(void); - bool punch_isopen(void); + //void punch_rewind(void); + //bool punch_isopen(void); void punch_msg(const char * str); void fpunchf_heading(const char *name); @@ -395,8 +399,8 @@ public: LDBLE *x0_moles; // mainsubs.cpp ------------------------------- - FILE *file_open(char *query, char *default_name, const char *status, - int batch); + std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); int copy_entities(void); void initialize(void); int initial_exchangers(int print); From c3d019a01227f4fce4282dc4a2c289283296a160 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Dec 2011 17:36:26 +0000 Subject: [PATCH 0363/1077] Fixed action of dumper. Retains information until next read, only changes what is read. A DUMP keyword with no body will repeat current definitions. Fixed DELETE, which was missing pressures. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5871 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 28 ++++++++++++++++++++++++---- dumper.cpp | 11 +++++++---- dumper.h | 48 +++++++++++++++++++++++++----------------------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index ff0ebbcf..ad303e2b 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1031,9 +1031,7 @@ read_dump(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - dumper dmp(parser, phrq_io); - dump_info = dmp; - + dump_info.Read(parser); // Need to output the next keyword if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); @@ -1943,6 +1941,11 @@ int Phreeqc:: dump_entities(void) /* ---------------------------------------------------------------------- */ { + if (!dump_info.Get_on()) + { + return(OK); + } + dump_info.Set_on(false); if (!dump_info.Get_bool_any()) { return(OK); @@ -1984,7 +1987,8 @@ delete_entities(void) !delete_info.Get_kinetics().Get_defined() && !delete_info.Get_mix().Get_defined() && !delete_info.Get_reaction().Get_defined() && - !delete_info.Get_temperature().Get_defined() ) + !delete_info.Get_temperature().Get_defined() && + !delete_info.Get_pressure().Get_defined()) { return(OK); } @@ -2216,6 +2220,22 @@ delete_entities(void) } } } + // pressures + if (delete_info.Get_pressure().Get_defined()) + { + if (delete_info.Get_pressure().Get_numbers().size() == 0) + { + Reaction_pressure_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_pressure().Get_numbers().begin(); it != delete_info.Get_pressure().Get_numbers().end(); it++) + { + Reaction_pressure_map.erase(*it); + } + } + } // Turn off delete until next read delete_info.SetAll(false); return (OK); diff --git a/dumper.cpp b/dumper.cpp index 426d0228..b6838039 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -71,10 +71,9 @@ void dumper::SetAll(bool tf) int opt_save; bool useLastLine(false); - // Read mix number and description - //this->read_number_description(parser); - opt_save = CParser::OPT_DEFAULT; + bool cleared_once = false; + this->on = true; for (;;) { @@ -89,7 +88,11 @@ void dumper::SetAll(bool tf) { opt_save = opt; } - + if (opt > 1 && !cleared_once) + { + binList.SetAll(false); + cleared_once = true; + } // Select StorageBinListItem StorageBinListItem *item = NULL; switch (opt) diff --git a/dumper.h b/dumper.h index 3e9bd733..b2ee3c78 100644 --- a/dumper.h +++ b/dumper.h @@ -15,32 +15,34 @@ public: ~dumper(void); bool Read(CParser & parser); void SetAll(bool tf); - std::string Get_file_name(void) { return(this->file_name); }; - bool Get_append(void) { return(this->append); }; - bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; - bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; - bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; - bool Get_bool_surface(void) { return(this->binList.Get_surface().Get_defined()); }; - bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; - bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; - bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; - bool Get_bool_mix(void) { return(this->binList.Get_mix().Get_defined()); }; - bool Get_bool_reaction(void) { return(this->binList.Get_reaction().Get_defined()); }; - bool Get_bool_temperature(void) { return(this->binList.Get_temperature().Get_defined()); }; - bool Get_bool_pressure(void) { return(this->binList.Get_pressure().Get_defined()); }; + std::string Get_file_name(void) { return(this->file_name); }; + bool Get_append(void) { return(this->append); }; + bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; + bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; + bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; + bool Get_bool_surface(void) { return(this->binList.Get_surface().Get_defined()); }; + bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; + bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; + bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; + bool Get_bool_mix(void) { return(this->binList.Get_mix().Get_defined()); }; + bool Get_bool_reaction(void) { return(this->binList.Get_reaction().Get_defined()); }; + bool Get_bool_temperature(void) { return(this->binList.Get_temperature().Get_defined()); }; + bool Get_bool_pressure(void) { return(this->binList.Get_pressure().Get_defined()); }; bool Get_bool_any(void); - std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; - std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; - std::set < int > & Get_exchange(void) { return(this->binList.Get_exchange().Get_numbers()); }; - std::set < int > & Get_surface(void) { return(this->binList.Get_surface().Get_numbers()); }; + std::set < int > & Get_solution(void) { return(this->binList.Get_solution().Get_numbers()); }; + std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; + std::set < int > & Get_exchange(void) { return(this->binList.Get_exchange().Get_numbers()); }; + std::set < int > & Get_surface(void) { return(this->binList.Get_surface().Get_numbers()); }; std::set < int > & Get_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_numbers()); }; - std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; - std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; - std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; - std::set < int > & Get_reaction(void) { return(this->binList.Get_reaction().Get_numbers()); }; - std::set < int > & Get_temperature(void) { return(this->binList.Get_temperature().Get_numbers()); }; - std::set < int > & Get_pressure(void) { return(this->binList.Get_pressure().Get_numbers()); }; + std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; + std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; + std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; + std::set < int > & Get_reaction(void) { return(this->binList.Get_reaction().Get_numbers()); }; + std::set < int > & Get_temperature(void) { return(this->binList.Get_temperature().Get_numbers()); }; + std::set < int > & Get_pressure(void) { return(this->binList.Get_pressure().Get_numbers()); }; + bool Get_on(void) {return this->on;}; + void Set_on(bool tf) {this->on = tf;}; protected: std::string file_name; bool append; From a4c8e993d35bbb0d144f798c23e5f192aebad66f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 Dec 2011 06:16:03 +0000 Subject: [PATCH 0364/1077] moved istreams from Phreeqc class to PHRQ_io class changed modes std::ifstream:: to std::ios_base:: deleted some #ifdef SKIP git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5872 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- PHRQ_io.h | 20 +++++++++++++++----- Phreeqc.cpp | 11 +++-------- Phreeqc.h | 18 +++++------------- 4 files changed, 64 insertions(+), 27 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index ea091bf0..ba65854a 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -420,7 +420,7 @@ void PHRQ_io::fpunchf_end_row(const char *format) } /* ---------------------------------------------------------------------- */ void PHRQ_io:: -close_output_ostreams(void) +close_ostreams(void) /* ---------------------------------------------------------------------- */ { std::set streams; @@ -479,3 +479,43 @@ echo_msg(const char * str) } } } + +std::istream * PHRQ_io:: +get_istream() +{ + if (istream_list.size() > 0) + { + return istream_list.front(); + } + else + { + return NULL; + } +} +void PHRQ_io:: +push_istream(std::istream * cookie, bool auto_delete) +{ + istream_list.push_front(cookie); + delete_istream_list.push_front(auto_delete); +} +void PHRQ_io:: +clear_istream(void) +{ + while (istream_list.size() > 0) + { + pop_istream(); + } +} +void PHRQ_io:: +pop_istream() +{ + if (istream_list.size() > 0) + { + if (delete_istream_list.front()) + { + delete istream_list.front(); + } + istream_list.pop_front(); + delete_istream_list.pop_front(); + } +} \ No newline at end of file diff --git a/PHRQ_io.h b/PHRQ_io.h index 402c1a4c..680a5036 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -7,9 +7,9 @@ #define IPQ_DLL_EXPORT #endif -#include -#include +#include #include +#include class PhreeqcStop : std::exception { @@ -25,12 +25,19 @@ public: // methods static int istream_getc(void *cookie); static void safe_close(std::ostream **stream_ptr); - void close_output_ostreams(void); + void close_ostreams(void); void Set_io_error_count(int i) {this->io_error_count = i;}; int Get_io_error_count(void) {return this->io_error_count;}; + + // istreams + std::istream *get_istream(); + void pop_istream(); + void push_istream(std::istream * cookie, bool auto_delete = true); + void clear_istream(void); + // output_ostream - bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void output_flush(void); void output_close(void); virtual void output_msg(const char * str); @@ -68,7 +75,7 @@ public: std::ostream *Get_error_ostream(void) {return this->error_ostream;}; void Set_error_on(bool tf) {this->error_on = tf;}; bool Get_error_on(void) {return this->error_on;}; - void warning_msg(const char *err_str); + virtual void warning_msg(const char *err_str); // dump_ostream bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); @@ -126,5 +133,8 @@ protected: bool echo_on; bool screen_on; ECHO_OPTION echo_destination; + + std::list istream_list; + std::list delete_istream_list; }; #endif /* _PHRQIO_H */ diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d3cc6585..29edf9b5 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -144,8 +144,8 @@ Phreeqc::~Phreeqc(void) clean_up(); if (phrq_io == &ioInstance) { - //this->phrq_io->close_input_files(); - this->phrq_io->close_output_ostreams(); + this->phrq_io->clear_istream(); + this->phrq_io->close_ostreams(); } int i; @@ -877,12 +877,7 @@ void Phreeqc::init(void) #endif run_info.Set_io(phrq_io); - this->clear_istream(); + phrq_io->clear_istream(); return; } - -void Phreeqc::set_io(PHRQ_io *io) -{ - this->phrq_io = io; -} diff --git a/Phreeqc.h b/Phreeqc.h index 0cbe7740..4672c06a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -193,7 +193,7 @@ public: void set_forward_output_to_log(int value); int get_forward_output_to_log(void); - // dump_file + // dump_ostream bool dump_open(const char *file_name); void dump_flush(void); void dump_close(void); @@ -201,7 +201,7 @@ public: //bool dump_isopen(void); void dump_msg(const char * str); - // log_file + // log_ostream bool log_open(const char *file_name); void log_flush(void); void log_close(void); @@ -209,7 +209,7 @@ public: //bool log_isopen(void); void log_msg(const char * str); - // error_file + // error_ostream bool error_open(const char *file_name); void error_flush(void); void error_close(void); @@ -217,7 +217,7 @@ public: //bool error_isopen(void); void error_msg(const char * str, bool stop=false); - // output_file + // output_ostream bool output_open(const char *file_name); void output_flush(void); void output_close(void); @@ -225,7 +225,7 @@ public: //bool output_isopen(void); void output_msg(const char * str); - // punch_file + // punch_ostream bool punch_open(const char *file_name); void punch_flush(void); void punch_close(void); @@ -1324,12 +1324,7 @@ public: //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); void set_phast(int); - void set_io(PHRQ_io *io); size_t list_components(std::list &list_c); - std::istream *get_istream(); - void pop_istream(); - void push_istream(std::istream * cookie, bool auto_delete = true); - void clear_istream(void); protected: void init(void); @@ -1337,9 +1332,6 @@ protected: //Data members // protected: - std::list istream_list; - std::list delete_istream_list; - PHRQ_io *phrq_io; PHRQ_io ioInstance; From 2211621f2fd79f03b5bb4333c32cbc9c089fbe56 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Dec 2011 14:41:38 +0000 Subject: [PATCH 0365/1077] istreams moved to phrq_io git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5874 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index df6bd751..3a87f246 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -95,9 +95,9 @@ main_method(int argc, char *argv[]) /* * Load database into memory */ - this->push_istream(db_cookie); + this->phrq_io->push_istream(db_cookie); errors = read_database(); - this->clear_istream(); + this->phrq_io->clear_istream(); if (errors != 0) { @@ -109,9 +109,9 @@ main_method(int argc, char *argv[]) * Read input data for simulation */ - this->push_istream(input_cookie); + this->phrq_io->push_istream(input_cookie); errors = run_simulations(); - this->clear_istream(); + this->phrq_io->clear_istream(); if (errors != 0) { From 57620590863f608b379e72fe5619845250059272 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 10 Dec 2011 00:55:13 +0000 Subject: [PATCH 0366/1077] sync'd warning_msg with error_msg git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5878 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 12 +++++------- Phreeqc.cpp | 1 + 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index ba65854a..0dbe65da 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -202,8 +202,8 @@ error_msg(const char *err_str, bool stop) io_error_count++; if (error_ostream != NULL && error_on) { - (*error_ostream) << err_str; - error_ostream->flush(); + (*error_ostream) << err_str; + error_ostream->flush(); } if (stop) { @@ -356,15 +356,13 @@ void PHRQ_io:: warning_msg(const char *err_str) /* ---------------------------------------------------------------------- */ { - std::ostringstream warn_str; - warn_str << "WARNING: " << err_str << std::endl; - - //screen_msg("\n"); if (error_ostream != NULL && error_on) { - (*error_ostream) << "\nWARNING: " << err_str << std::endl; + (*error_ostream) << err_str << std::endl; error_ostream->flush(); } + std::ostringstream warn_str; + warn_str << err_str << std::endl; log_msg(warn_str.str().c_str()); log_flush(); output_msg(warn_str.str().c_str()); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 29edf9b5..5556f53e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -123,6 +123,7 @@ Phreeqc::Phreeqc(PHRQ_io *io) // phqalloc.c // print.c + status_on = FALSE; sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); if (sformatf_buffer == NULL) malloc_error(); From 88dc8b963378438e96e3d0123b26b9d3711dabb8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 12 Dec 2011 17:23:43 +0000 Subject: [PATCH 0367/1077] Changed activity of water equation to use tanh to allow activity of water to approach zero smoothly. Added a slack variable to equations, will see if it affects convergences. Had changed the mu equation to be limited at 50, but commented this out. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5879 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 4672c06a..78e9604d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -559,6 +559,7 @@ public: int save_model(void); int setup_exchange(void); int setup_gas_phase(void); + int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); @@ -1682,6 +1683,7 @@ protected: struct unknown *solution_phase_boundary_unknown; struct unknown *surface_unknown; struct unknown *gas_unknown; + struct unknown *slack_unknown; struct unknown *s_s_unknown; /*---------------------------------------------------------------------- * Reaction work space @@ -1785,6 +1787,7 @@ protected: int diagonal_scale; /* 0 not used, 1 used */ int mass_water_switch; int delay_mass_water; + bool dampen; LDBLE censor; int aqueous_only; int negative_concentrations; From 877f19e62af712634f2b7562fff329f8523519cb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 12 Dec 2011 21:59:38 +0000 Subject: [PATCH 0368/1077] define bool slack to allow a slack variable in array (default false). dampen for activity of water is true by default. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5884 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 78e9604d..9067925e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1788,6 +1788,7 @@ protected: int mass_water_switch; int delay_mass_water; bool dampen; + bool slack; LDBLE censor; int aqueous_only; int negative_concentrations; From 1715e7b4bb4621d5dc6e9ded54ac20e4c367cacd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 13 Dec 2011 19:47:47 +0000 Subject: [PATCH 0369/1077] Numerical derivatives with REVISED_GASES works with the P_Vm test case. Have to merge Tony's changes, and make it work without having to use -numerical_jacobian. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5891 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 9067925e..8bc8c702 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -563,6 +563,9 @@ public: int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); +#if defined(REVISED_GASES) + LDBLE calc_PR(); +#endif int setup_pure_phases(void); int adjust_setup_pure_phases(void); int setup_related_surface(void); @@ -1685,6 +1688,10 @@ protected: struct unknown *gas_unknown; struct unknown *slack_unknown; struct unknown *s_s_unknown; +#if defined(REVISED_GASES) + std::vector gas_unknowns; + struct unknown *gas_pressure_unknown; +#endif /*---------------------------------------------------------------------- * Reaction work space *---------------------------------------------------------------------- */ @@ -1776,6 +1783,7 @@ protected: LDBLE inv_tol_default; int itmax; + int max_tries; LDBLE ineq_tol; LDBLE convergence_tolerance; LDBLE step_size; From 36bf6b7fa146628f470ae6e071a0d88e75f68f79 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 13 Dec 2011 22:03:24 +0000 Subject: [PATCH 0370/1077] Compiles with and without REVISED_GASES. There is a bug, CO2_conc_PR_GP runs, but gives wrong answer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5893 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 8bc8c702..3b29be84 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -453,6 +453,9 @@ public: //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); #endif int calc_gas_pressures(void); +#if defined(REVISED_GASES) + int calc_fixed_volume_gas_pressures(void); +#endif int calc_s_s_fractions(void); int gammas(LDBLE mu); int initial_guesses(void); @@ -534,6 +537,9 @@ public: int add_surface_charge_balance(void); int add_cd_music_charge_balances(int i); int build_gas_phase(void); +#if defined(REVISED_GASES) + int build_fixed_volume_gas(void); +#endif int build_jacobian_sums(int k); int build_mb_sums(void); int build_min_exch(void); @@ -559,6 +565,9 @@ public: int save_model(void); int setup_exchange(void); int setup_gas_phase(void); +#if defined(REVISED_GASES) + int setup_fixed_volume_gas(void); +#endif int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); From 4ed743d04ed297ed4ebdd3944d15d0e1d6ce3642 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 15 Dec 2011 01:04:06 +0000 Subject: [PATCH 0371/1077] added Set_file_name method for use in IPhreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5898 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dumper.cpp | 3 ++- dumper.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dumper.cpp b/dumper.cpp index b6838039..4c93e5a0 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -28,7 +28,8 @@ void dumper::SetAll(bool tf) { this->binList.SetAll(tf); -}bool dumper::Read(CParser & parser) +} +bool dumper::Read(CParser & parser) { bool return_value(true); static std::vector < std::string > vopts; diff --git a/dumper.h b/dumper.h index b2ee3c78..bcaa4996 100644 --- a/dumper.h +++ b/dumper.h @@ -3,7 +3,7 @@ #include // std::set #include // std::string #include // std::list -#include // std::vector +#include // std::vector #include "StorageBinList.h" class CParser; @@ -16,6 +16,7 @@ public: bool Read(CParser & parser); void SetAll(bool tf); std::string Get_file_name(void) { return(this->file_name); }; + void Set_file_name(std::string fn) { this->file_name = fn; }; bool Get_append(void) { return(this->append); }; bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; From c46e48760e8f62789185fbf6ebe1c8a4a9ffe866 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 15 Dec 2011 16:40:03 +0000 Subject: [PATCH 0372/1077] Added pr_in to C++ gas_phase class. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5900 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 31 +++++++++++++++++++++++++++++++ GasPhase.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/GasPhase.cxx b/GasPhase.cxx index 39e49610..70b462a0 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -28,6 +28,7 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) total_p = 0; volume = 0; v_m = 0; + pr_in = false; gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; } @@ -54,6 +55,7 @@ cxxNumKeyword(io) total_p = gas_phase_ptr->total_p; volume = gas_phase_ptr->volume; v_m = gas_phase_ptr->v_m; + pr_in = gas_phase_ptr->pr_in; // gas_phase components for (i = 0; i < gas_phase_ptr->count_comps; i++) @@ -73,6 +75,7 @@ cxxNumKeyword(io) total_p = 0; volume = 0; v_m = 0; + pr_in = false; bool first = true; // // Mix @@ -97,6 +100,7 @@ cxxNumKeyword(io) this->total_p = entity_ptr->total_p * it->second; this->volume = entity_ptr->volume * it->second; this->v_m = entity_ptr->v_m * it->second; + this->pr_in = entity_ptr->pr_in; first = false; } else @@ -189,6 +193,9 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1; s_oss << "-v_m " << this->v_m << std::endl; + s_oss << indent1; + s_oss << "-pr_in " << (this->pr_in ? 1 : 0) << std::endl; + // gasPhaseComps s_oss << indent1; s_oss << "-component" << std::endl; @@ -210,6 +217,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) vopts.push_back("v_m"); //3 vopts.push_back("component"); //4 vopts.push_back("pressure"); //5 + vopts.push_back("pr_in"); //6 } std::istream::pos_type ptr; @@ -226,6 +234,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) bool total_p_defined(false); bool volume_defined(false); bool v_m_defined(false); + bool pr_in_defined(false); for (;;) { @@ -324,6 +333,19 @@ cxxGasPhase::read_raw(CParser & parser, bool check) opt_save = 4; useLastLine = false; break; + case 6: // pr_in + if (!(parser.get_iss() >> i)) + { + parser.incr_input_error(); + parser.error_msg("Expected 0/1 for pr_in.", CParser::OT_CONTINUE); + } + else + { + this->pr_in = (i == 0) ? false : true; + } + pr_in_defined = true; + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -355,6 +377,12 @@ cxxGasPhase::read_raw(CParser & parser, bool check) parser.error_msg("V_m not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE); } + if (pr_in_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Pr_in not defined for GAS_PHASE_RAW input.", + CParser::OT_CONTINUE); + } } } @@ -376,6 +404,7 @@ cxxGasPhase::mpi_pack(std::vector < int >&ints, doubles.push_back(this->total_p); doubles.push_back(this->volume); doubles.push_back(this->v_m); + ints.push_back((pr_in) ? 1 : 0); } void @@ -399,6 +428,8 @@ cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->total_p = doubles[d++]; this->volume = doubles[d++]; this->v_m = doubles[d++]; + n = ints[i++]; + this->pr_in = (n == 1) ? true : false; *ii = i; *dd = d; } diff --git a/GasPhase.h b/GasPhase.h index d353954c..080b3b50 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -50,6 +50,7 @@ class cxxGasPhase:public cxxNumKeyword double Get_total_p(void) const {return total_p;}; double Get_volume(void) const {return volume;}; double Get_v_m(void) const {return v_m;}; + bool Get_pr_in(void) const {return pr_in;}; cxxNameDouble & Get_totals(void) {return totals;}; protected: @@ -61,6 +62,7 @@ protected: double total_p; double volume; double v_m; + bool pr_in; cxxNameDouble totals; }; From 8a8547be79ff0bb4a3d7bfb27de4899c1de089ce Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 16 Dec 2011 01:04:53 +0000 Subject: [PATCH 0373/1077] Think fixed volume P-R gases are working correctly with numerical derivatives. There is a problem with CO2_conc_PR_EQ related to gas.dat. Am going to remove -reset false from some of the gas problems so that testing is better. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5902 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b4614919..f0bce295 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DREVISED_GASES VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -115,7 +115,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DREVISED_GASES VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -136,6 +136,7 @@ COMMON_COBJS = \ cvode.o \ dense.o \ dw.o \ + gases.o \ input.o \ integrate.o \ inverse.o \ @@ -711,13 +712,19 @@ utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ ../phreeqc/NA.h ../phreeqc/phqalloc.h +gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + cd $(CLASS_DEBUG_DIR); gcc -DREVISED_GASES -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From fe15de343798069acfbedf341693d32c4f57bd2e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 19 Dec 2011 17:00:27 +0000 Subject: [PATCH 0374/1077] Fixed long heading problem from Kinniburgh git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5906 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index 3b29be84..eeb600c5 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -662,7 +662,7 @@ public: int check_key(const char *str); int check_units(char *tot_units, int alkalinity, int check_compatibility, const char *default_units, int print); - int find_option(char *item, int *n, const char **list, int count_list, + int find_option(const char *item, int *n, const char **list, int count_list, int exact); int get_option(const char **opt_list, int count_opt_list, char **next_char); int get_true_false(char *string, int default_value); @@ -1287,6 +1287,7 @@ public: int copy_title(char *token_ptr, char **ptr, int *length); #endif int copy_token(char *token_ptr, char **ptr, int *length); + int copy_token(std::string &token, char **ptr); int dup_print(const char *ptr, int emphasis); int equal(LDBLE a, LDBLE b, LDBLE eps); public: @@ -1305,6 +1306,7 @@ protected: int print_centered(const char *string); public: static int replace(const char *str1, const char *str2, char *str); + static bool replace(const char *str1, const char *str2, std::string & str); protected: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); From 267b593431a2e71b8458f3e66dd06a4d81118684 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 19 Dec 2011 19:53:17 +0000 Subject: [PATCH 0375/1077] Incorporated Tony's changes for -vm Fixed bug with stdtoken. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5908 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index eeb600c5..8eaedf30 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -549,6 +549,8 @@ public: int build_solution_phase_boundaries(void); int build_species_list(int n); int build_min_surface(void); + LDBLE calc_delta_v(reaction * r_ptr, bool phase); + int calc_vm(); int change_hydrogen_in_elt_list(LDBLE charge); int clear(void); int convert_units(struct solution *solution_ptr); @@ -1282,6 +1284,7 @@ protected: int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: + LDBLE calc_dens0(void); int compute_gfw(const char *string, LDBLE * gfw); #if defined PHREEQ98 int copy_title(char *token_ptr, char **ptr, int *length); From 8107f787b7774e2c9542bb4a97c1c410b0155463 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Dec 2011 16:04:49 +0000 Subject: [PATCH 0376/1077] have old activity of water and correct tanh version of activity of water. switch is dampen_ah2o. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5919 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index 8eaedf30..536b110d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1809,7 +1809,7 @@ protected: int diagonal_scale; /* 0 not used, 1 used */ int mass_water_switch; int delay_mass_water; - bool dampen; + bool dampen_ah2o; bool slack; LDBLE censor; int aqueous_only; From f75189872d5f80ccf687b48fa4034e674444eb56 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Dec 2011 18:34:17 +0000 Subject: [PATCH 0377/1077] Modified to run all fixed volume calculations through REVISED_GASES code. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5920 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 536b110d..f0b476c0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -453,9 +453,7 @@ public: //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); #endif int calc_gas_pressures(void); -#if defined(REVISED_GASES) int calc_fixed_volume_gas_pressures(void); -#endif int calc_s_s_fractions(void); int gammas(LDBLE mu); int initial_guesses(void); @@ -537,9 +535,7 @@ public: int add_surface_charge_balance(void); int add_cd_music_charge_balances(int i); int build_gas_phase(void); -#if defined(REVISED_GASES) int build_fixed_volume_gas(void); -#endif int build_jacobian_sums(int k); int build_mb_sums(void); int build_min_exch(void); @@ -567,16 +563,12 @@ public: int save_model(void); int setup_exchange(void); int setup_gas_phase(void); -#if defined(REVISED_GASES) int setup_fixed_volume_gas(void); -#endif int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); -#if defined(REVISED_GASES) LDBLE calc_PR(); -#endif int setup_pure_phases(void); int adjust_setup_pure_phases(void); int setup_related_surface(void); @@ -1702,8 +1694,8 @@ protected: struct unknown *gas_unknown; struct unknown *slack_unknown; struct unknown *s_s_unknown; -#if defined(REVISED_GASES) std::vector gas_unknowns; +#if defined(REVISED_GASES) struct unknown *gas_pressure_unknown; #endif /*---------------------------------------------------------------------- From 9fa2b74b6c7bf29a70475e682a504ab338f1f7d5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Dec 2011 21:34:06 +0000 Subject: [PATCH 0378/1077] Removed gas_pressure unknown. Removed REVISED_GASES. numerical_fixed_volume is switch; can be read in knobs. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5921 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index f0b476c0..362e1893 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1526,6 +1526,7 @@ protected: LDBLE tc_x; LDBLE tk_x; LDBLE patm_x; + bool numerical_fixed_volume; LDBLE ph_x; LDBLE solution_pe_x; LDBLE mu_x; @@ -1695,9 +1696,6 @@ protected: struct unknown *slack_unknown; struct unknown *s_s_unknown; std::vector gas_unknowns; -#if defined(REVISED_GASES) - struct unknown *gas_pressure_unknown; -#endif /*---------------------------------------------------------------------- * Reaction work space *---------------------------------------------------------------------- */ From 28534b50e005b16c7060e82a0dbcc52ba4a3f67e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Dec 2011 22:51:58 +0000 Subject: [PATCH 0379/1077] removed REVISED_GASES from Makefile. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5925 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f0bce295..12ac7fc3 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DREVISED_GASES + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -115,7 +115,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DREVISED_GASES + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -724,7 +724,7 @@ clean: dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -DREVISED_GASES -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From 84644301c883b5e22ee3fdfa45712051f5a6f005 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 Dec 2011 23:06:43 +0000 Subject: [PATCH 0380/1077] added force_numerical_jacobian git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5927 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 362e1893..4b3d9acb 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1527,6 +1527,7 @@ protected: LDBLE tk_x; LDBLE patm_x; bool numerical_fixed_volume; + bool force_numerical_fixed_volume; LDBLE ph_x; LDBLE solution_pe_x; LDBLE mu_x; From 70eb5e272199ca74ec28c53223e905acfab14fd1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Dec 2011 15:42:50 +0000 Subject: [PATCH 0381/1077] Revisions from Tony. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5933 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 4b3d9acb..3dbadf9d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -545,8 +545,9 @@ public: int build_solution_phase_boundaries(void); int build_species_list(int n); int build_min_surface(void); + LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE P); LDBLE calc_delta_v(reaction * r_ptr, bool phase); - int calc_vm(); + int calc_vm(LDBLE tc); int change_hydrogen_in_elt_list(LDBLE charge); int clear(void); int convert_units(struct solution *solution_ptr); @@ -1276,7 +1277,7 @@ protected: int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); public: - LDBLE calc_dens0(void); + LDBLE calc_rho_0(LDBLE tc, LDBLE pa); int compute_gfw(const char *string, LDBLE * gfw); #if defined PHREEQ98 int copy_title(char *token_ptr, char **ptr, int *length); From e0ef4941f8cc06d2d589667462bb6e78bd71c666 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Dec 2011 18:07:01 +0000 Subject: [PATCH 0382/1077] changed error_string to const char *. works with sformatf to allow indefinite length strings. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5936 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 100 +++++++++++++++++++++++++++++-------------------- Phreeqc.h | 2 +- ReadClass.cxx | 34 ++++++++--------- StorageBin.cxx | 6 +-- 4 files changed, 80 insertions(+), 62 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 2c86f090..dfa19595 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -115,9 +115,12 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } else { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + //char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, + // (int) P_ioresult); + //warning_msg(error_string); + char * error_string = PhreeqcPtr->sformatf("%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + warning_msg(error_string); } } else @@ -202,9 +205,9 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) { if (P_escapecode != -20) { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + warning_msg(error_string); } else { @@ -272,9 +275,9 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } else { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + warning_msg(error_string); } } else @@ -335,9 +338,9 @@ basic_main(char *commands) { if (P_escapecode != -20) { - sprintf(PhreeqcPtr->error_string, "%d/%d", (int) P_escapecode, + char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(PhreeqcPtr->error_string); + warning_msg(error_string); } else { @@ -786,8 +789,8 @@ parse(char * l_inbuf, tokenrec ** l_buf) } else { - sprintf(PhreeqcPtr->error_string, " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + char * error_string = PhreeqcPtr->sformatf( " missing \" or \' in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(error_string, STOP); } } if (lp > 0) { @@ -801,8 +804,8 @@ parse(char * l_inbuf, tokenrec ** l_buf) } else { - sprintf(PhreeqcPtr->error_string, " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + char * error_string = PhreeqcPtr->sformatf( " missing ) or ] in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(error_string, STOP); } } else if (lp < 0) { @@ -816,8 +819,8 @@ parse(char * l_inbuf, tokenrec ** l_buf) } else { - sprintf(PhreeqcPtr->error_string, " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); - error_msg(PhreeqcPtr->error_string, STOP); + char * error_string = PhreeqcPtr->sformatf( " missing ( or [ in BASIC line\n %ld %s", curline, l_inbuf); + error_msg(error_string, STOP); } } } @@ -3307,8 +3310,8 @@ term(struct LOC_exec * LINK) { if (!parse_all) { - sprintf(PhreeqcPtr->error_string, "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + char * error_string = PhreeqcPtr->sformatf( "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); + warning_msg(error_string); } n.UU.val = 0; } @@ -3521,8 +3524,8 @@ mustfindline(long n) l = findline(n); if (l == NULL) { - sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); - errormsg(PhreeqcPtr->error_string); + char * error_string = PhreeqcPtr->sformatf( "Undefined line %ld", n); + errormsg(error_string); } return l; } @@ -3541,8 +3544,8 @@ mustfindline(long n) { _ASSERTE(nIDErrPrompt == 0); nIDErrPrompt = IDS_ERR_UNDEF_LINE; - sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); - errormsg(PhreeqcPtr->error_string); + char * error_string = PhreeqcPtr->sformatf( "Undefined line %ld", n); + errormsg(error_string); } } } @@ -3550,8 +3553,8 @@ mustfindline(long n) { if (l == NULL) { - sprintf(PhreeqcPtr->error_string, "Undefined line %ld", n); - errormsg(PhreeqcPtr->error_string); + char * error_string = PhreeqcPtr->sformatf( "Undefined line %ld", n); + errormsg(error_string); } } return l; @@ -5131,23 +5134,31 @@ exec(void) { case -4: - sprintf(PhreeqcPtr->error_string, "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + { + char * error_string = PhreeqcPtr->sformatf( "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(error_string); + } break; case -5: - sprintf(PhreeqcPtr->error_string, "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + { + char * error_string = PhreeqcPtr->sformatf( "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(error_string); + } break; case -6: - sprintf(PhreeqcPtr->error_string, "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + { + char * error_string = PhreeqcPtr->sformatf( "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(error_string); + } break; case -7: - sprintf(PhreeqcPtr->error_string, "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + { + char * error_string = PhreeqcPtr->sformatf( "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(error_string); + } break; case -8: @@ -5156,24 +5167,31 @@ exec(void) case -17: case -16: case -15: - sprintf(PhreeqcPtr->error_string, "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(PhreeqcPtr->error_string); + { + char * error_string = PhreeqcPtr->sformatf( "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + warning_msg(error_string); + } break; case -10: - ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); - if (ioerrmsg == NULL) - PhreeqcPtr->malloc_error(); - sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); - warning_msg(ioerrmsg); + //ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); + //if (ioerrmsg == NULL) + // PhreeqcPtr->malloc_error(); + //sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); + //warning_msg(ioerrmsg); + // + { + char * error_string = PhreeqcPtr->sformatf("I/O Error %d", (int) P_ioresult); + warning_msg(error_string); + } PhreeqcPtr->PHRQ_free(ioerrmsg); break; default: if (EXCP_LINE != -1) { - sprintf(PhreeqcPtr->error_string, "%12ld\n", EXCP_LINE); - warning_msg(PhreeqcPtr->error_string); + char * error_string = PhreeqcPtr->sformatf( "%12ld\n", EXCP_LINE); + warning_msg(error_string); } _Escape(P_escapecode); break; @@ -5188,8 +5206,8 @@ exec(void) } else { - sprintf(PhreeqcPtr->error_string, " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - error_msg(PhreeqcPtr->error_string, CONTINUE); + char * error_string = PhreeqcPtr->sformatf( " in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); + error_msg(error_string, CONTINUE); } } } // end catch diff --git a/Phreeqc.h b/Phreeqc.h index 3dbadf9d..54458fc6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1749,7 +1749,7 @@ protected: /* ---------------------------------------------------------------------- * GLOBAL DECLARATIONS * ---------------------------------------------------------------------- */ - char error_string[10 * MAX_LENGTH]; + const char * error_string; int simulation; int state; int reaction_step; diff --git a/ReadClass.cxx b/ReadClass.cxx index ad303e2b..cfbd2c9f 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1170,7 +1170,7 @@ read_solution_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected solution number following SOLUTION_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected solution number following SOLUTION_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1209,7 +1209,7 @@ read_solution_modify(void) if (solution_bsearch(n_user, &n, FALSE) == NULL) { input_error++; - sprintf(error_string, "Solution %d not found for SOLUTION_MODIFY.\n", n_user); + error_string = sformatf( "Solution %d not found for SOLUTION_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1269,7 +1269,7 @@ read_equilibrium_phases_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1307,7 +1307,7 @@ read_equilibrium_phases_modify(void) if (pp_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n", n_user); + error_string = sformatf( "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1362,7 +1362,7 @@ read_exchange_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1401,7 +1401,7 @@ read_exchange_modify(void) if (exchange_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); + error_string = sformatf( "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1472,7 +1472,7 @@ read_surface_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected surface number following SURFACE_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected surface number following SURFACE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1510,7 +1510,7 @@ read_surface_modify(void) if (surface_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Surface %d not found for SURFACE_MODIFY.\n", n_user); + error_string = sformatf( "Surface %d not found for SURFACE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1562,7 +1562,7 @@ read_solid_solutions_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1600,7 +1600,7 @@ read_solid_solutions_modify(void) if (s_s_assemblage_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n", n_user); + error_string = sformatf( "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1651,7 +1651,7 @@ read_gas_phase_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1689,7 +1689,7 @@ read_gas_phase_modify(void) if (gas_phase_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); + error_string = sformatf( "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1740,7 +1740,7 @@ read_kinetics_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected kinetics number following KINETICS_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected kinetics number following KINETICS_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1778,7 +1778,7 @@ read_kinetics_modify(void) if (kinetics_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Kinetics %d not found for KINETICS_MODIFY.\n", n_user); + error_string = sformatf( "Kinetics %d not found for KINETICS_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1829,7 +1829,7 @@ read_reaction_modify(void) if (copy_token(token, &next, &l) != DIGIT) { input_error++; - sprintf(error_string, "Expected reaction number following REACTION_MODIFY.\n%s\n", line_save); + error_string = sformatf( "Expected reaction number following REACTION_MODIFY.\n%s\n", line_save); error_msg(error_string, CONTINUE); std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); @@ -1867,7 +1867,7 @@ read_reaction_modify(void) if (irrev_bsearch(n_user, &n) == NULL) { input_error++; - sprintf(error_string, "Reaction %d not found for REACTION_MODIFY.\n", n_user); + error_string = sformatf( "Reaction %d not found for REACTION_MODIFY.\n", n_user); error_msg(error_string, CONTINUE); return (ERROR); } @@ -1965,7 +1965,7 @@ dump_entities(void) } else { - sprintf(error_string, "Unable to open dump file \"%s\"", dump_info.Get_file_name().c_str()); + error_string = sformatf( "Unable to open dump file \"%s\"", dump_info.Get_file_name().c_str()); error_msg(error_string, STOP); } } diff --git a/StorageBin.cxx b/StorageBin.cxx index e0c5725a..9d2b4d2b 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -929,7 +929,7 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) cxxsoln_ptr1 = &((this->Solutions.find(it->first))->second); if (cxxsoln_ptr1 == NULL) { - sprintf(error_string, + error_string = sformatf( "Solution %d not found in mix_cxxSolutions.", it->first); error_msg(error_string, CONTINUE); P_INSTANCE_POINTER input_error++; @@ -1325,7 +1325,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); if (old_exch_ptr == NULL) { - sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", + error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); P_INSTANCE_POINTER input_error++; @@ -1346,7 +1346,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) old_exch_ptr = &((this->Exchangers.find(it_mix->first))->second); if (old_exch_ptr == NULL) { - sprintf(error_string, "Exchange %d not found in mix_cxxExchange.", + error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); P_INSTANCE_POINTER input_error++; From 2095c5bf456a8e9a0e90b65ffac21f931586d586 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Dec 2011 20:26:46 +0000 Subject: [PATCH 0383/1077] Linux changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5938 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index dfa19595..9a4ffe34 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -4889,7 +4889,6 @@ void PBasic:: exec(void) { struct LOC_exec V; - char *ioerrmsg; char STR1[256] = {0}; try @@ -5174,17 +5173,10 @@ exec(void) break; case -10: - //ioerrmsg = (char *) PhreeqcPtr->PHRQ_calloc(256, sizeof(char)); - //if (ioerrmsg == NULL) - // PhreeqcPtr->malloc_error(); - //sprintf(ioerrmsg, "I/O Error %d", (int) P_ioresult); - //warning_msg(ioerrmsg); - // { char * error_string = PhreeqcPtr->sformatf("I/O Error %d", (int) P_ioresult); warning_msg(error_string); } - PhreeqcPtr->PHRQ_free(ioerrmsg); break; default: From a8ad82586f4323cb28409ca9c7930e72e04add2e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 21 Dec 2011 23:18:58 +0000 Subject: [PATCH 0384/1077] hsave_string returns const char *. all other changes follow from this. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5940 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.h | 6 +++--- ISolution.h | 2 +- ISolutionComp.h | 8 ++++---- KineticsComp.h | 2 +- PPassemblageComp.h | 4 ++-- Phreeqc.h | 26 +++++++++++++------------- ReadClass.cxx | 4 +++- SurfaceComp.cxx | 6 +++--- SurfaceComp.h | 6 +++--- 9 files changed, 33 insertions(+), 31 deletions(-) diff --git a/ExchComp.h b/ExchComp.h index 55f9c9a2..4f531433 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -27,7 +27,7 @@ class cxxExchComp: public PHRQ_base { return this->formula; } - void Set_formula(char *cstring) + void Set_formula(const char *cstring) { if (cstring != NULL) this->formula = std::string(cstring); @@ -62,7 +62,7 @@ class cxxExchComp: public PHRQ_base { return this->phase_name; } - void Set_phase_name(char *cstring) + void Set_phase_name(const char *cstring) { if (cstring != NULL) this->phase_name = std::string(cstring); @@ -81,7 +81,7 @@ class cxxExchComp: public PHRQ_base { return this->rate_name; } - void Set_rate_name(char *cstring) + void Set_rate_name(const char *cstring) { if (cstring != NULL) this->rate_name = std::string(cstring); diff --git a/ISolution.h b/ISolution.h index 2383d797..ec148918 100644 --- a/ISolution.h +++ b/ISolution.h @@ -40,7 +40,7 @@ class cxxISolution:public cxxSolution { units = l_units; } - void Set_units(char * l_units) + void Set_units(const char * l_units) { if (l_units != NULL) this->units = std::string(l_units); diff --git a/ISolutionComp.h b/ISolutionComp.h index 5239c319..6cf592c2 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -26,7 +26,7 @@ class cxxISolutionComp: public PHRQ_base { return this->description; } - void Set_description(char *l_description) + void Set_description(const char *l_description) { if (l_description != NULL) this->description = std::string(l_description); @@ -56,7 +56,7 @@ class cxxISolutionComp: public PHRQ_base { return this->units; } - void Set_units(char *l_units) + void Set_units(const char *l_units) { if (l_units != NULL) this->units = std::string(l_units); @@ -68,7 +68,7 @@ class cxxISolutionComp: public PHRQ_base { return this->equation_name; } - void Set_equation_name(char *l_equation_name) + void Set_equation_name(const char *l_equation_name) { if (l_equation_name != NULL) this->equation_name = std::string(l_equation_name); @@ -99,7 +99,7 @@ class cxxISolutionComp: public PHRQ_base { return this->as; } - void Set_as(char *l_as) + void Set_as(const char *l_as) { if (l_as != NULL) this->as = std::string(l_as); diff --git a/KineticsComp.h b/KineticsComp.h index 544b6207..33f335e5 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -27,7 +27,7 @@ public: { return this->rate_name; } - void Set_rate_name(char * s) + void Set_rate_name(const char * s) { if (s != NULL) this->rate_name = std::string(s); diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 1a2e2c36..0dbfd400 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -25,7 +25,7 @@ class cxxPPassemblageComp: public PHRQ_base { return this->name; } - void Set_name(char * s) + void Set_name(const char * s) { if(s != NULL) this->name = std::string(s); @@ -36,7 +36,7 @@ class cxxPPassemblageComp: public PHRQ_base { return this->add_formula; } - void Set_add_formula(char * s) + void Set_add_formula(const char * s) { if(s != NULL) this->add_formula = std::string(s); diff --git a/Phreeqc.h b/Phreeqc.h index 54458fc6..aa0275e6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -273,7 +273,7 @@ public: // inverse.cpp ------------------------------- int inverse_models(void); - int add_to_file(const char *filename, char *string); + int add_to_file(const char *filename, const char *string); int bit_print(unsigned long bits, int l); int carbon_derivs(struct inverse *inv_ptr); int check_isotopes(struct inverse *inv_ptr); @@ -509,7 +509,7 @@ public: int set_pz(int initial); int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_pz(void); - int ISPEC(char *name); + int ISPEC(const char *name); LDBLE G(LDBLE Y); LDBLE GP(LDBLE Y); int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, @@ -785,7 +785,7 @@ public: int set_sit(int initial); int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_sit(void); - int sit_ISPEC(char *name); + int sit_ISPEC(const char *name); /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ int sit_initial_guesses(void); int sit_revise_guesses(void); @@ -937,13 +937,13 @@ protected: struct logk *logk_alloc(void); int logk_copy2orig(struct logk *logk_ptr); struct logk *logk_store(char *name, int replace_if_found); - struct logk *logk_search(char *name); + struct logk *logk_search(const char *name); struct master *master_alloc(void); static int master_compare(const void *ptr1, const void *ptr2); int master_delete(char *ptr); public: struct master *master_bsearch(const char *ptr); - struct master *master_bsearch_primary(char *ptr); + struct master *master_bsearch_primary(const char *ptr); struct master *master_bsearch_secondary(char *ptr); struct master *master_search(char *ptr, int *n); struct mix *mix_bsearch(int k, int *n); @@ -966,7 +966,7 @@ public: protected: static int phase_compare(const void *ptr1, const void *ptr2); int phase_delete(int i); - struct phase *phase_store(char *name); + struct phase *phase_store(const char *name); public: struct pp_assemblage *pp_assemblage_alloc(void); struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); @@ -995,7 +995,7 @@ protected: static int pure_phase_compare(const void *ptr1, const void *ptr2); struct rate *rate_bsearch(char *ptr, int *j); int rate_free(struct rate *rate_ptr); - struct rate *rate_search(char *name, int *n); + struct rate *rate_search(const char *name, int *n); int rate_sort(void); struct reaction *rxn_alloc(int ntokens); struct reaction *rxn_dup(struct reaction *rxn_ptr_old); @@ -1005,7 +1005,7 @@ protected: static int s_compare(const void *ptr1, const void *ptr2); int s_delete(int i); struct species *s_search(const char *name); - struct species *s_store(char *name, LDBLE z, int replace_if_found); + struct species *s_store(const char *name, LDBLE z, int replace_if_found); public: struct s_s_assemblage *s_s_assemblage_alloc(void); struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); @@ -1249,7 +1249,7 @@ public: int sum_surface_comp(struct surface *source1, LDBLE f1, struct surface *source2, int k, LDBLE f2, struct surface *target, LDBLE new_Dw); - int reformat_surf(char *comp_name, LDBLE fraction, char *new_comp_name, + int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, LDBLE new_Dw, int cell); LDBLE viscosity(void); int multi_D(LDBLE DDt, int mobile_cell, int stagnant); @@ -1313,7 +1313,7 @@ protected: int strcmp_nocase_arg1(const char *str1, const char *str2); public: char *string_duplicate(const char *token); - char *string_hsave(const char *str); + const char *string_hsave(const char *str); protected: char *string_pad(const char *str, int i); int string_trim(char *str); @@ -1329,7 +1329,7 @@ protected: extern int clean_up_null(void); #endif int isamong(char c, const char *s_l); - Address Hash_multi(HashTable * Table, char *Key); + Address Hash_multi(HashTable * Table, const char *Key); void ExpandTable_multi(HashTable * Table); public: //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); @@ -1733,7 +1733,7 @@ protected: * ---------------------------------------------------------------------- */ struct rate *user_print; struct rate *user_punch; - char **user_punch_headings; + const char **user_punch_headings; int user_punch_count_headings; int n_user_punch_index; @@ -1919,7 +1919,7 @@ protected: struct surface_charge *surface_charge_ptr; int max_row_count, max_column_count; int carbon; - char **col_name, **row_name; + const char **col_name, **row_name; int count_rows, count_optimize; int col_phases, col_redox, col_epsilon, col_ph, col_water, col_isotopes, col_phase_isotopes; diff --git a/ReadClass.cxx b/ReadClass.cxx index cfbd2c9f..ae08c3d9 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1427,10 +1427,12 @@ read_exchange_modify(void) { count_elts = 0; paren_count = 0; - char *ptr = exchange[n].comps[i].formula; + char * temp_formula = string_duplicate(exchange[n].comps[i].formula); + char *ptr = temp_formula; get_elts_in_species(&ptr, 1.0); free_check_null(exchange[n].comps[i].formula_totals); exchange[n].comps[i].formula_totals = elt_list_save(); + free_check_null(temp_formula); } diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index eff2fa6d..2ec5e323 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -582,7 +582,7 @@ cxxSurfaceComp::Get_phase_name() const return this->phase_name; } void -cxxSurfaceComp::Set_phase_name(char * f) +cxxSurfaceComp::Set_phase_name(const char * f) { if (f != NULL) this->phase_name = std::string(f); @@ -595,7 +595,7 @@ cxxSurfaceComp::Get_rate_name() const return this->rate_name; } void -cxxSurfaceComp::Set_rate_name(char * f) +cxxSurfaceComp::Set_rate_name(const char * f) { if (f != NULL) this->rate_name = std::string(f); @@ -608,7 +608,7 @@ cxxSurfaceComp::Get_formula() const return this->formula; } void -cxxSurfaceComp::Set_formula(char * f) +cxxSurfaceComp::Set_formula(const char * f) { if (f != NULL) this->formula = std::string(f); diff --git a/SurfaceComp.h b/SurfaceComp.h index 0064c9f2..f7c7ee68 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -19,11 +19,11 @@ public: ~cxxSurfaceComp(); const std::string &Get_phase_name() const; - void Set_phase_name(char * f); + void Set_phase_name(const char * f); const std::string &Get_rate_name() const; - void Set_rate_name(char * f); + void Set_rate_name(const char * f); const std::string &Get_formula() const; - void Set_formula(char * f); + void Set_formula(const char * f); double Get_charge_balance() const; void Set_charge_balance(double d); void dump_xml(std::ostream & os, unsigned int indent = 0) const; From a05de5e5d0ae212fda4aeaabc84028c82a8f02cc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Dec 2011 00:02:20 +0000 Subject: [PATCH 0385/1077] Removed old hash for strings and replaced with standard map. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5941 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 - Phreeqc.h | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 5556f53e..3ad70c61 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -455,7 +455,6 @@ void Phreeqc::init(void) logk_hash_table = 0; master_isotope_hash_table = 0; - strings_hash_table = 0; elements_hash_table = 0; species_hash_table = 0; phases_hash_table = 0; diff --git a/Phreeqc.h b/Phreeqc.h index aa0275e6..7a6d758a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1314,6 +1314,7 @@ protected: public: char *string_duplicate(const char *token); const char *string_hsave(const char *str); + void strings_map_clear(); protected: char *string_pad(const char *str, int i); int string_trim(char *str); @@ -1828,7 +1829,7 @@ protected: * Hash definitions */ - HashTable *strings_hash_table; + std::map strings_map; HashTable *elements_hash_table; HashTable *species_hash_table; HashTable *phases_hash_table; From b5c652e25416847de1fea4d983b44d25dfe36169 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Dec 2011 23:13:07 +0000 Subject: [PATCH 0386/1077] Removed struct temperature. Uses only cxxTemperature. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5942 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 3 +- Phreeqc.h | 13 +-- ReadClass.cxx | 129 +++--------------------------- Temperature.cxx | 205 ++++++++++++++++++++++++++++++++++++++++-------- Temperature.h | 10 ++- 5 files changed, 190 insertions(+), 170 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 3ad70c61..10dc9807 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -12,6 +12,7 @@ #include "cxxKinetics.h" #include "phqalloc.h" #include "PBasic.h" +#include "Temperature.h" Phreeqc::Phreeqc(PHRQ_io *io) { @@ -342,7 +343,6 @@ void Phreeqc::init(void) count_mix = 0; count_phases = 0; count_s = 0; - count_temperature = 0; count_logk = 0; count_master_isotope = 0; /* @@ -422,7 +422,6 @@ void Phreeqc::init(void) solution = 0; - temperature = 0; title_x = NULL; pe_x = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 7a6d758a..6a6adf08 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -825,7 +825,6 @@ public: int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); - int add_temperature(struct temperature *temperature_ptr, int step_number); int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); int gas_phase_check(struct gas_phase *gas_phase_ptr); int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); @@ -1085,15 +1084,6 @@ public: struct surface *surface_search(int n_user, int *n, int print); int surface_sort(void); int system_duplicate(int i, int save_old); - struct temperature *temperature_bsearch(int k, int *n); - int temperature_copy(struct temperature *temperature_old_ptr, - struct temperature *temperature_new_ptr, int n_user_new); - int temperature_delete(int n_user_old); - int temperature_duplicate(int n_user_old, int n_user_new); - int temperature_free(struct temperature *temperature_ptr); - struct temperature *temperature_search(int n_user, int *n); - int temperature_ptr_to_user(struct temperature * temperature_ptr_old, int n_user_new); - int temperature_sort(void); int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); int trxn_combine(void); @@ -1360,8 +1350,7 @@ protected: * Temperatures * ---------------------------------------------------------------------- */ - struct temperature *temperature; - int count_temperature; + std::map Reaction_temperature_map; /* ---------------------------------------------------------------------- * Pressures diff --git a/ReadClass.cxx b/ReadClass.cxx index ae08c3d9..5842f3f6 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -888,105 +888,6 @@ read_mix_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_temperature_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads TEMPERATURE (_RAW) data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("temperature_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); - assert(!reading_database()); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxTemperature ex(phrq_io); - ex.read_raw(parser); - //struct temperature *temperature_ptr = ex.cxxTemperature2temperature(PHREEQC_THIS); - struct temperature *temperature_ptr = cxxTemperature2temperature(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (temperature_bsearch(temperature_ptr->n_user, &n) != NULL) - { - temperature_free(&temperature[n]); - temperature_copy(temperature_ptr, &temperature[n], - temperature_ptr->n_user); - } - else - { - n = count_temperature++; - temperature = - (struct temperature *) PHRQ_realloc(temperature, - (size_t) count_temperature * - sizeof(struct temperature)); - if (temperature == NULL) - malloc_error(); - temperature_copy(temperature_ptr, &temperature[n], - temperature_ptr->n_user); - temperature_sort(); - } - temperature_free(temperature_ptr); - free_check_null(temperature_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -2205,20 +2106,14 @@ delete_entities(void) { if (delete_info.Get_temperature().Get_numbers().size() == 0) { - for (i = 0; i < count_temperature; i++) - { - temperature_delete(temperature[i].n_user); - } + Reaction_temperature_map.clear(); } else { std::set < int >::iterator it; for (it = delete_info.Get_temperature().Get_numbers().begin(); it != delete_info.Get_temperature().Get_numbers().end(); it++) { - if (temperature_bsearch(*it, &n) != NULL) - { - temperature_delete(*it); - } + Reaction_temperature_map.erase(*it); } } } @@ -2299,8 +2194,11 @@ run_as_cells(void) } if (use.temperature_in == TRUE && use.temperature_ptr != NULL) { - if (abs(use.temperature_ptr->count_t) > count_steps) - count_steps = abs(use.temperature_ptr->count_t); + int count = ((cxxTemperature *) use.temperature_ptr)->Get_countTemps(); + if (count > count_steps) + { + count_steps = count; + } } if (use.pressure_in == TRUE && use.pressure_ptr != NULL) { @@ -2703,27 +2601,22 @@ dump_ostream(std::ostream& os) { if (dump_info.Get_temperature().size() == 0) { - for (i = 0; i < count_temperature; i++) - { - cxxTemperature cxxentity(&temperature[i], phrq_io); - cxxentity.dump_raw(os,0); - } + Utilities::Reactant_dump_map_raw(Reaction_temperature_map, os, 0); } else { std::set < int >::iterator it; for (it = dump_info.Get_temperature().begin(); it != dump_info.Get_temperature().end(); it++) { + cxxTemperature *p = Utilities::Reactant_find(Reaction_temperature_map, *it); - if (temperature_bsearch(*it, &n) != NULL) + if (p != NULL) { - cxxTemperature cxxentity(&temperature[n], phrq_io); - cxxentity.dump_raw(os,0); + p->dump_raw(os, 0); } } } } - // pressure if (dump_info.Get_bool_pressure()) { diff --git a/Temperature.cxx b/Temperature.cxx index 03f3b53b..84ab785e 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -28,40 +28,6 @@ cxxTemperature::cxxTemperature(PHRQ_io *io) countTemps = 0; equalIncrements = false; } - -cxxTemperature::cxxTemperature(struct temperature *temperature_ptr, PHRQ_io *io) - // - // constructor for cxxTemperature from struct temperature - // - : -cxxNumKeyword(io) -{ - int i; - - this->Set_description(temperature_ptr->description); - this->n_user = temperature_ptr->n_user; - this->n_user_end = temperature_ptr->n_user_end; - // temps - if (temperature_ptr->count_t < 0) - { - for (i = 0; i < 2; i++) - { - this->temps.push_back(temperature_ptr->t[i]); - } - this->countTemps = -temperature_ptr->count_t; - this->equalIncrements = true; - } - else - { - for (i = 0; i < temperature_ptr->count_t; i++) - { - this->temps.push_back(temperature_ptr->t[i]); - } - this->countTemps = temperature_ptr->count_t; - this->equalIncrements = false; - } -} - cxxTemperature::~cxxTemperature() { } @@ -102,6 +68,122 @@ cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const } #endif +int +cxxTemperature::read(CParser & parser) +{ +/* + * Reads temperature data for reaction steps + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + // Number and description set in read_reaction_temperature + + CParser::LINE_TYPE lt; + bool done = false; + for (;;) + { + std::istream::pos_type ptr; + std::istream::pos_type next_char = 0; + std::string token, str; + lt = parser.check_line(str, false, true, true, true); + + if (lt == CParser::LT_EMPTY || + lt == CParser::LT_KEYWORD || + lt == CParser::LT_EOF) + { + break; + } + if (lt == CParser::LT_OPTION) + { + this->error_msg("Expected numeric value for temperatures.", CParser::OT_CONTINUE); + break; + } + + if (done) + { + this->error_msg("Unknown input following equal increment definition.", CParser::OT_CONTINUE); + continue; + } + + // LT_OK + + for (;;) + { + if (done) break; + // new token + std::string token; + CParser::TOKEN_TYPE k = parser.copy_token(token, next_char); + + // need new line + if (k == CParser::TT_EMPTY) + { + break; + } + + // read a pressure + if (k == CParser::TT_DIGIT) + { + std::istringstream iss(token); + LDBLE d; + if (!(iss >> d)) + { + this->error_msg("Expected numeric value for temperatures.", + CParser::OT_CONTINUE); + } + else + { + this->temps.push_back(d); + } + continue; + } + + // non digit, must be "in" + if (k == CParser::TT_UPPER || k == CParser::TT_LOWER) + { + if (this->temps.size() != 2) + { + this->error_msg("To define equal increments, exactly two temperatures should be defined.", CONTINUE); + } + else + { + int i = parser.copy_token(token, next_char); + if (i == EMPTY) + { + error_msg("To define equal increments, define 'in n steps'.", CONTINUE); + } + else + { + std::istringstream iss(token); + if ((iss >> i) && i > 0) + { + this->equalIncrements = true; + this->countTemps = i; + } + else + { + error_msg("Unknown input for temperature steps.", CONTINUE); + } + } + done = true; + } + if (k == CParser::TT_UNKNOWN) + { + error_msg("Unknown input for temperature steps.", CONTINUE); + } + } + } // tokens + } // lines + return lt; +} + void cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { @@ -281,3 +363,58 @@ cxxTemperature::read_raw(CParser & parser) CParser::OT_CONTINUE); } } +/* ---------------------------------------------------------------------- */ +LDBLE cxxTemperature:: +Temperature_for_step(int step_number) +/* ---------------------------------------------------------------------- */ +{ +/* + * Determine pressure of reaction step + */ + LDBLE t_temp; + if (this->temps.size() == 0) + { + t_temp = 1; + } + else if (this->equalIncrements) + { + if (this->temps.size() != 2) + { + error_msg("Number of temperatures not equal to 2 for equal increments.", 0); + } + if (step_number > this->countTemps) + { + t_temp = this->temps[1]; + } + else + { + LDBLE denom; + denom = (this->countTemps <= 1) ? 1 : (LDBLE) (this->countTemps - 1); + t_temp = this->temps[0] + ( this->temps[1] - this->temps[0]) * + ((LDBLE) (step_number - 1)) / (denom); + } + } + else + { + if (step_number > (int) this->temps.size()) + { + t_temp = this->temps[this->temps.size() - 1]; + } + else + { + t_temp = this->temps[step_number - 1]; + } + + } + + return (t_temp); +} +int cxxTemperature:: +Get_countTemps(void) const +{ + if (equalIncrements) + { + return this->countTemps; + } + return (int) this->temps.size(); +} \ No newline at end of file diff --git a/Temperature.h b/Temperature.h index 8b220d10..fb7386cc 100644 --- a/Temperature.h +++ b/Temperature.h @@ -14,7 +14,6 @@ class cxxTemperature:public cxxNumKeyword public: cxxTemperature(PHRQ_io *io=NULL); - cxxTemperature(struct temperature *, PHRQ_io *io=NULL); ~cxxTemperature(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -22,10 +21,13 @@ class cxxTemperature:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser); - - const std::vector & Get_temps(void) const {return temps;}; - int Get_countTemps(void) const {return countTemps;}; + int read(CParser & parser); + LDBLE Temperature_for_step(int step_number); + std::vector & Get_temps(void) {return temps;}; + int Get_countTemps(void) const; + void Set_countTemps(int i) {countTemps = i;}; bool Get_equalIncrements(void) const {return equalIncrements;}; + void Set_equalIncrements(bool tf) {equalIncrements = tf;}; protected: std::vector < double >temps; From 4bb72929ed1f2fc3e83a87573b14348d8f29dbc8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 22 Dec 2011 23:46:40 +0000 Subject: [PATCH 0387/1077] Change count in dump_raw for temperature. Bugs in include.out and errorinp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5944 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Temperature.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Temperature.cxx b/Temperature.cxx index 84ab785e..a4417715 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -203,7 +203,7 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; - s_oss << "-count_temps " << this->countTemps << std::endl; + s_oss << "-count_temps " << this->Get_countTemps() << std::endl; s_oss << indent1; s_oss << "-equal_increments " << this->equalIncrements << std::endl; @@ -417,4 +417,4 @@ Get_countTemps(void) const return this->countTemps; } return (int) this->temps.size(); -} \ No newline at end of file +} From 02839d601d7f396ffff6bbcd7e4ec29566f379c1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 27 Dec 2011 18:41:46 +0000 Subject: [PATCH 0388/1077] Removed struct mix. Left old code commented. Will remove old code next svn revision. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5948 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 8 +++---- Phreeqc.h | 37 +++++++++++++++++-------------- ReadClass.cxx | 59 +++++++++++++++++++++++++++++++++++++++++--------- StorageBin.cxx | 26 +++++++++++----------- Utils.h | 6 ++--- cxxMix.cxx | 15 +++++++++++-- cxxMix.h | 15 +++++++------ 7 files changed, 111 insertions(+), 55 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 10dc9807..51defd91 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -340,7 +340,7 @@ void Phreeqc::init(void) count_elements = 0; count_irrev = 0; count_master = 0; - count_mix = 0; + //count_mix = 0; count_phases = 0; count_s = 0; count_logk = 0; @@ -405,8 +405,8 @@ void Phreeqc::init(void) mb_unknowns = 0; - mix = 0; - count_mix = 0; + //mix = 0; + //count_mix = 0; /* !!!! */ stag_data = 0; @@ -706,7 +706,7 @@ void Phreeqc::init(void) dbg_pp_assemblage = pp_assemblage; dbg_kinetics = kinetics; dbg_irrev = irrev; - dbg_mix = mix; + //dbg_mix = mix; dbg_master = master; calculating_deriv = FALSE; numerical_deriv = FALSE; diff --git a/Phreeqc.h b/Phreeqc.h index 6a6adf08..3b326b24 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -30,10 +30,11 @@ #endif #include "Keywords.h" #include "Pressure.h" +#include "cxxMix.h" class cxxNameDouble; class cxxKinetics; -class cxxMix; +//class cxxMix; class cxxKineticsComp; class cxxExchange; class cxxExchComp; @@ -817,7 +818,8 @@ public: int add_exchange(struct exchange *exchange_ptr); int add_gas_phase(struct gas_phase *gas_phase_ptr); int add_kinetics(struct kinetics *kinetics_ptr); - int add_mix(struct mix *mix_ptr); + //int add_mix(struct mix *mix_ptr); + int add_mix(cxxMix * mix_ptr); int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); int add_reaction(struct irrev *irrev_ptr, int step_number, LDBLE step_fraction); @@ -945,15 +947,15 @@ public: struct master *master_bsearch_primary(const char *ptr); struct master *master_bsearch_secondary(char *ptr); struct master *master_search(char *ptr, int *n); - struct mix *mix_bsearch(int k, int *n); - int mix_copy(struct mix *mix_old_ptr, - struct mix *mix_new_ptr, int n_user_new); - int mix_delete(int n_user_old); - int mix_duplicate(int n_user_old, int n_user_new); - int mix_free(struct mix *mix_ptr); - struct mix *mix_search(int n_user, int *n, int print); - int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); - int mix_sort(void); + //struct mix *mix_bsearch(int k, int *n); + //int mix_copy(struct mix *mix_old_ptr, + //struct mix *mix_new_ptr, int n_user_new); + //int mix_delete(int n_user_old); + //int mix_duplicate(int n_user_old, int n_user_new); + //int mix_free(struct mix *mix_ptr); + //struct mix *mix_search(int n_user, int *n, int print); + //int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); + //int mix_sort(void); struct pe_data *pe_data_alloc(void); public: struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); @@ -1350,12 +1352,12 @@ protected: * Temperatures * ---------------------------------------------------------------------- */ - std::map Reaction_temperature_map; + std::map Rxn_temperature_map; /* ---------------------------------------------------------------------- * Pressures * ---------------------------------------------------------------------- */ - std::map Reaction_pressure_map; + std::map Rxn_pressure_map; /* ---------------------------------------------------------------------- * Surface @@ -1428,10 +1430,13 @@ protected: /*---------------------------------------------------------------------- * Mix *---------------------------------------------------------------------- */ + std::map Rxn_mix_map; + std::map Dispersion_mix_map; + //std::map Stagnant_mix_map; - struct mix *mix; - struct mix *dbg_mix; - int count_mix; + //struct mix *mix; + //struct mix *dbg_mix; + //int count_mix; /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ diff --git a/ReadClass.cxx b/ReadClass.cxx index 5842f3f6..5cba07af 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -792,7 +792,7 @@ read_reaction_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_mix_raw(void) @@ -888,6 +888,7 @@ read_mix_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -2058,6 +2059,22 @@ delete_entities(void) } } // mixes + if (delete_info.Get_mix().Get_defined()) + { + if (delete_info.Get_mix().Get_numbers().size() == 0) + { + Rxn_mix_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_mix().Get_numbers().begin(); it != delete_info.Get_mix().Get_numbers().end(); it++) + { + Rxn_mix_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_mix().Get_defined()) { if (delete_info.Get_mix().Get_numbers().size() == 0) @@ -2079,6 +2096,7 @@ delete_entities(void) } } } +#endif // reactions if (delete_info.Get_reaction().Get_defined()) { @@ -2106,14 +2124,14 @@ delete_entities(void) { if (delete_info.Get_temperature().Get_numbers().size() == 0) { - Reaction_temperature_map.clear(); + Rxn_temperature_map.clear(); } else { std::set < int >::iterator it; for (it = delete_info.Get_temperature().Get_numbers().begin(); it != delete_info.Get_temperature().Get_numbers().end(); it++) { - Reaction_temperature_map.erase(*it); + Rxn_temperature_map.erase(*it); } } } @@ -2122,14 +2140,14 @@ delete_entities(void) { if (delete_info.Get_pressure().Get_numbers().size() == 0) { - Reaction_pressure_map.clear(); + Rxn_pressure_map.clear(); } else { std::set < int >::iterator it; for (it = delete_info.Get_pressure().Get_numbers().begin(); it != delete_info.Get_pressure().Get_numbers().end(); it++) { - Reaction_pressure_map.erase(*it); + Rxn_pressure_map.erase(*it); } } } @@ -2545,6 +2563,27 @@ dump_ostream(std::ostream& os) } // mix + if (dump_info.Get_bool_mix()) + { + if (dump_info.Get_mix().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_mix_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_mix().begin(); it != dump_info.Get_mix().end(); it++) + { + cxxMix *p = Utilities::Rxn_find(Rxn_mix_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_mix()) { if (dump_info.Get_mix().size() == 0) @@ -2569,7 +2608,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // reaction if (dump_info.Get_bool_reaction()) { @@ -2601,14 +2640,14 @@ dump_ostream(std::ostream& os) { if (dump_info.Get_temperature().size() == 0) { - Utilities::Reactant_dump_map_raw(Reaction_temperature_map, os, 0); + Utilities::Rxn_dump_raw(Rxn_temperature_map, os, 0); } else { std::set < int >::iterator it; for (it = dump_info.Get_temperature().begin(); it != dump_info.Get_temperature().end(); it++) { - cxxTemperature *p = Utilities::Reactant_find(Reaction_temperature_map, *it); + cxxTemperature *p = Utilities::Rxn_find(Rxn_temperature_map, *it); if (p != NULL) { @@ -2622,14 +2661,14 @@ dump_ostream(std::ostream& os) { if (dump_info.Get_pressure().size() == 0) { - Utilities::Reactant_dump_map_raw(Reaction_pressure_map, os, 0); + Utilities::Rxn_dump_raw(Rxn_pressure_map, os, 0); } else { std::set < int >::iterator it; for (it = dump_info.Get_pressure().begin(); it != dump_info.Get_pressure().end(); it++) { - cxxPressure *p = Utilities::Reactant_find(Reaction_pressure_map, *it); + cxxPressure *p = Utilities::Rxn_find(Rxn_pressure_map, *it); if (p != NULL) { diff --git a/StorageBin.cxx b/StorageBin.cxx index 9d2b4d2b..95f7c7b9 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -286,7 +286,7 @@ cxxStorageBin::Remove_Temperature(int n_user) cxxPressure * cxxStorageBin::Get_Pressure(int n_user) { - return Utilities::Reactant_find(this->Pressures, n_user); + return Utilities::Rxn_find(this->Pressures, n_user); } void @@ -403,34 +403,34 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss.precision(DBL_DIG - 1); // Solutions - Utilities::Reactant_dump_map_raw(Solutions, s_oss, indent); + Utilities::Rxn_dump_raw(Solutions, s_oss, indent); // Exchange - Utilities::Reactant_dump_map_raw(Exchangers, s_oss, indent); + Utilities::Rxn_dump_raw(Exchangers, s_oss, indent); // Gas Phases - Utilities::Reactant_dump_map_raw(GasPhases, s_oss, indent); + Utilities::Rxn_dump_raw(GasPhases, s_oss, indent); // Kinetics - Utilities::Reactant_dump_map_raw(Kinetics, s_oss, indent); + Utilities::Rxn_dump_raw(Kinetics, s_oss, indent); // PPassemblage - Utilities::Reactant_dump_map_raw(PPassemblages, s_oss, indent); + Utilities::Rxn_dump_raw(PPassemblages, s_oss, indent); // SSassemblage - Utilities::Reactant_dump_map_raw(SSassemblages, s_oss, indent); + Utilities::Rxn_dump_raw(SSassemblages, s_oss, indent); // Surface - Utilities::Reactant_dump_map_raw(Surfaces, s_oss, indent); + Utilities::Rxn_dump_raw(Surfaces, s_oss, indent); // Mix - Utilities::Reactant_dump_map_raw(Mixes, s_oss, indent); + Utilities::Rxn_dump_raw(Mixes, s_oss, indent); // Reactions - Utilities::Reactant_dump_map_raw(Reactions, s_oss, indent); + Utilities::Rxn_dump_raw(Reactions, s_oss, indent); // Temperature - Utilities::Reactant_dump_map_raw(Temperatures, s_oss, indent); + Utilities::Rxn_dump_raw(Temperatures, s_oss, indent); } void @@ -1525,7 +1525,7 @@ cxxStorageBin::Set_System(struct Use *use_ptr) // reaction pressure if (use_ptr->pressure_ptr != NULL) { - cxxPressure * p = Utilities::Reactant_find(this->Pressures, use_ptr->n_pressure_user); + cxxPressure * p = Utilities::Rxn_find(this->Pressures, use_ptr->n_pressure_user); if (p != NULL) { this->system.Set_Pressure(p); @@ -1622,6 +1622,6 @@ cxxStorageBin::Set_System(int i) // reaction pressure { - this->system.Set_Pressure(Utilities::Reactant_find(this->Pressures, i)); + this->system.Set_Pressure(Utilities::Rxn_find(this->Pressures, i)); } } diff --git a/Utils.h b/Utils.h index 01b57fef..e96c8831 100644 --- a/Utils.h +++ b/Utils.h @@ -36,7 +36,7 @@ namespace Utilities // operations on maps of entities (Solution, Exchange, ...) template < typename T > - void Reactant_dump_map_raw(const T & b, std::ostream & s_oss, unsigned int indent) + void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) { //std :: map < int, T > :: const_iterator it; typename T::const_iterator it; @@ -52,7 +52,7 @@ namespace Utilities //} template < typename T > - T * Reactant_find(std::map < int, T > &b, int i) + T * Rxn_find(std::map < int, T > &b, int i) { if (b.find(i) != b.end()) { @@ -65,7 +65,7 @@ namespace Utilities } template < typename T > - T * Reactant_copy(std::map < int, T > &b, int i, int j) + T * Rxn_copy(std::map < int, T > &b, int i, int j) { typename std::map < int, T >::iterator it; it = b.find(i); diff --git a/cxxMix.cxx b/cxxMix.cxx index 2524d5e0..bfc12a83 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -26,7 +26,7 @@ cxxMix::cxxMix(PHRQ_io *io) : cxxNumKeyword(io) { } - +#ifdef SKIP cxxMix::cxxMix(struct mix *mix_ptr, PHRQ_io *io) // // constructor for cxxMix from struct mix @@ -49,7 +49,7 @@ cxxNumKeyword(io) } } } - +#endif cxxMix::~cxxMix() { } @@ -200,3 +200,14 @@ cxxMix::read_raw(CParser & parser) } // members that must be defined } +void cxxMix::Vectorize(std::vector &n, std::vector &f) +{ + n.clear(); + f.clear(); + for (std::map < int, double >::const_iterator it = this->mixComps.begin(); + it != this->mixComps.end(); it++) + { + n.push_back(it->first); + f.push_back(it->second); + } +} \ No newline at end of file diff --git a/cxxMix.h b/cxxMix.h index e3ffd4a8..84418a45 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -8,13 +8,14 @@ #include // std::vector #include "NumKeyword.h" #include "PHRQ_base.h" +#include "phrqtype.h" class cxxMix:public cxxNumKeyword { public: cxxMix(PHRQ_io *io=NULL); - cxxMix(struct mix *, PHRQ_io *io=NULL); + //cxxMix(struct mix *, PHRQ_io *io=NULL); ~cxxMix(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; @@ -23,7 +24,7 @@ class cxxMix:public cxxNumKeyword void read_raw(CParser & parser); - void add(int n, double f) + void Add(int n, LDBLE f) { if (this->mixComps.find(n) != this->mixComps.end()) { @@ -34,23 +35,23 @@ class cxxMix:public cxxNumKeyword mixComps[n] = f; } }; - void multiply(double f) + void Multiply(LDBLE f) { - for (std::map < int, double >::iterator it = this->mixComps.begin(); + for (std::map < int, LDBLE >::iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { it->second *= f; } }; - const std::map < int, double > & Get_mixComps() const + const std::map < int, LDBLE > & Get_mixComps() const { return mixComps; } - + void Vectorize(std::vector &n, std::vector &f); protected: friend class cxxStorageBin; - std::map < int, double >mixComps; + std::map < int, LDBLE >mixComps; }; From b52ab4dfeaab0b4c7816e8a605348d23c24c0212 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Dec 2011 15:39:50 +0000 Subject: [PATCH 0389/1077] Exchange changes have been made, but need to debug. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5960 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 4 +-- ExchComp.h | 6 ++-- Exchange.cxx | 39 +++++++++++++++++++--- Exchange.h | 16 +++++++-- Phreeqc.cpp | 19 +++++++---- Phreeqc.h | 28 ++++++++++------ ReadClass.cxx | 90 ++++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 172 insertions(+), 30 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 2c01520b..3877e26b 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -37,7 +37,7 @@ cxxExchComp::cxxExchComp(PHRQ_io *io) //rate_name = NULL; formula_z = 0.0; } - +#ifdef SKIP cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr, PHRQ_io *io) // // constructor for cxxExchComp from struct exch_comp @@ -57,7 +57,7 @@ formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) this->Set_rate_name(exch_comp_ptr->rate_name); formula_z = exch_comp_ptr->formula_z; } - +#endif #ifdef SKIP cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, std::vector < double >&f_vector) diff --git a/ExchComp.h b/ExchComp.h index 4f531433..65bdbb9e 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -14,7 +14,7 @@ class cxxExchComp: public PHRQ_base public: cxxExchComp(PHRQ_io *io=NULL); - cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); + //cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); ~cxxExchComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -121,8 +121,8 @@ class cxxExchComp: public PHRQ_base this->formula_totals = nd; } - const cxxNameDouble & Get_totals() const {return (this->totals);}; - const cxxNameDouble & Get_formula_totals(void) const {return this->formula_totals;}; + cxxNameDouble & Get_totals() {return (this->totals);}; + cxxNameDouble & Get_formula_totals(void) {return this->formula_totals;}; void add(const cxxExchComp & comp, double extensive); diff --git a/Exchange.cxx b/Exchange.cxx index a3328abc..5e142dd6 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -26,9 +26,12 @@ cxxExchange::cxxExchange(PHRQ_io *io) // : cxxNumKeyword(io) { + new_def = false; + solution_equilibria = false; + n_solution = -999; pitzer_exchange_gammas = true; } - +#ifdef SKIP cxxExchange::cxxExchange(struct exchange * exchange_ptr, PHRQ_io *io) // // constructor for cxxExchange from struct exchange @@ -53,6 +56,7 @@ cxxNumKeyword(io) } +#endif cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) @@ -362,7 +366,7 @@ cxxExchange::totalize() { this->totals.clear(); // component structures - for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); + for (std::map < std::string, cxxExchComp >::iterator it = exchComps.begin(); it != exchComps.end(); ++it) { this->totals.add_extensive((*it).second.Get_totals(), 1.0); @@ -381,8 +385,8 @@ cxxExchange::Set_pitzer_exchange_gammas(bool b) this->pitzer_exchange_gammas = b; } -const std::map < std::string, cxxExchComp > & -cxxExchange::Get_exchComps(void) const +std::map < std::string, cxxExchComp > & +cxxExchange::Get_exchComps(void) { return (this->exchComps); } @@ -391,3 +395,30 @@ cxxExchange::Get_totals() const { return totals; } +cxxExchComp *cxxExchange::ExchComp_find(std::string s) +{ + std::map::iterator it = this->exchComps.begin(); + for ( ; it != this->exchComps.end(); it++) + { + cxxNameDouble nd(it->second.Get_totals()); + cxxNameDouble::iterator nd_it; + for (nd_it = nd.begin(); nd_it != nd.end(); nd_it++) + { + if(nd_it->first == s) + { + return (&it->second); + } + } + } + return NULL; +} +std::vector cxxExchange::Vectorize(void) +{ + std::vector vlist; + std::map::iterator it = exchComps.begin(); + for ( ; it != this->exchComps.end(); it++) + { + vlist.push_back(&it->second); + } + return vlist; +} \ No newline at end of file diff --git a/Exchange.h b/Exchange.h index 962c63df..510dd69f 100644 --- a/Exchange.h +++ b/Exchange.h @@ -16,7 +16,7 @@ class cxxExchange:public cxxNumKeyword public: cxxExchange(PHRQ_io *io=NULL); - cxxExchange(struct exchange *, PHRQ_io *io=NULL); + //cxxExchange(struct exchange *, PHRQ_io *io=NULL); cxxExchange(const std::map < int, cxxExchange > &exchange_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); @@ -32,10 +32,19 @@ public: bool Get_pitzer_exchange_gammas() const; void Set_pitzer_exchange_gammas(bool b); - const std::map < std::string, cxxExchComp > &Get_exchComps(void) const; + bool Get_new_def(void) const {return this->new_def;}; + void Set_new_def(bool tf) {this->new_def = tf;}; + bool Get_solution_equilibria(void) const {return this->solution_equilibria;}; + void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;}; + int Get_n_solution(void) const {return this->n_solution;}; + void Set_n_solution(int i) {this->n_solution = i;}; + cxxExchComp *ExchComp_find(std::string s); + + std::map < std::string, cxxExchComp > &Get_exchComps(void) ; void totalize(); const cxxNameDouble & Get_totals() const; + std::vector Vectorize(void); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); @@ -47,6 +56,9 @@ protected: void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: + bool new_def; + bool solution_equilibria; + int n_solution; std::map < std::string, cxxExchComp > exchComps; bool pitzer_exchange_gammas; cxxNameDouble totals; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 51defd91..fa87e366 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -202,9 +202,16 @@ size_t Phreeqc::list_components(std::list &list_c) } // exchangers - for (i = 0; i < count_exchange; i++) + //for (i = 0; i < count_exchange; i++) + //{ + // cxxExchange entity(&exchange[i], phrq_io); + // entity.totalize(); + // accumulator.add_extensive(entity.Get_totals(), 1.0); + //} + std::map::const_iterator cit = Rxn_exchange_map.begin(); + for (; cit != Rxn_exchange_map.end(); cit++) { - cxxExchange entity(&exchange[i], phrq_io); + cxxExchange entity = cit->second; entity.totalize(); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -311,7 +318,7 @@ void Phreeqc::init(void) max_solution = MAX_SOLUTION; max_pp_assemblage = MAX_PP_ASSEMBLAGE; - max_exchange = MAX_PP_ASSEMBLAGE; + //max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; max_gas_phase = MAX_PP_ASSEMBLAGE; max_kinetics = MAX_PP_ASSEMBLAGE; @@ -331,7 +338,7 @@ void Phreeqc::init(void) count_solution = 0; count_pp_assemblage = 0; - count_exchange = 0; + //count_exchange = 0; count_surface = 0; count_gas_phase = 0; count_kinetics = 0; @@ -383,7 +390,7 @@ void Phreeqc::init(void) transport_warnings = TRUE; pp_assemblage = 0; - exchange = 0; + //exchange = 0; surface = 0; gas_phase = 0; kinetics = 0; @@ -701,7 +708,7 @@ void Phreeqc::init(void) */ dbg_use = &use; dbg_solution = solution; - dbg_exchange = exchange; + //dbg_exchange = exchange; dbg_surface = surface; dbg_pp_assemblage = pp_assemblage; dbg_kinetics = kinetics; diff --git a/Phreeqc.h b/Phreeqc.h index 3b326b24..3885e728 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -128,11 +128,12 @@ public: int system_total_elt_secondary(const char *total_name); LDBLE total(const char *total_name); LDBLE total_mole(const char *total_name); - int system_total_solids(struct exchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, - struct surface *surface_ptr); + //int system_total_solids(struct exchange *exchange_ptr, + int system_total_solids(cxxExchange *exchange_ptr, + struct pp_assemblage *pp_assemblage_ptr, + struct gas_phase *gas_phase_ptr, + struct s_s_assemblage *s_s_assemblage_ptr, + struct surface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); @@ -815,7 +816,8 @@ public: // step.cpp ------------------------------- int step(LDBLE step_fraction); int xsolution_zero(void); - int add_exchange(struct exchange *exchange_ptr); + //int add_exchange(struct exchange *exchange_ptr); + int add_exchange(cxxExchange *exchange_ptr); int add_gas_phase(struct gas_phase *gas_phase_ptr); int add_kinetics(struct kinetics *kinetics_ptr); //int add_mix(struct mix *mix_ptr); @@ -849,6 +851,8 @@ protected: struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); int elt_list_print(struct elt_list *elt_list_ptr); struct elt_list *elt_list_save(void); + cxxNameDouble elt_list_NameDouble(void); +#ifdef SKIP public: struct exchange *exchange_alloc(void); struct exchange *exchange_bsearch(int k, int *n); @@ -873,6 +877,7 @@ protected: int n_user_new); struct exchange *exchange_search(int n_user, int *n, int print); int exchange_sort(void); +#endif static int gas_comp_compare(const void *ptr1, const void *ptr2); public: struct gas_phase *gas_phase_alloc(void); @@ -1142,8 +1147,8 @@ public: struct mix * cxxMix2mix(const cxxMix *mx); struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); - struct exchange * cxxExchange2exchange(const cxxExchange * ex); - struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); + //struct exchange * cxxExchange2exchange(const cxxExchange * ex); + //struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); struct master * Get_exch_master(const cxxExchComp * ec); struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); @@ -1265,6 +1270,7 @@ public: // utilities.cpp ------------------------------- public: int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list(const cxxNameDouble & nd, LDBLE coef); protected: int backspace_screen(int spaces); LDBLE calc_alk(struct reaction *rxn_ptr); @@ -1376,11 +1382,15 @@ protected: /* ---------------------------------------------------------------------- * Exchange * ---------------------------------------------------------------------- */ - +#ifdef SKIP struct exchange *exchange; struct exchange *dbg_exchange; int count_exchange; int max_exchange; +#endif + + std::map Rxn_exchange_map; + /* ---------------------------------------------------------------------- * Kinetics * ---------------------------------------------------------------------- */ diff --git a/ReadClass.cxx b/ReadClass.cxx index 5cba07af..3fc21c2a 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -183,6 +183,18 @@ read_exchange_raw(void) cxxExchange ex(phrq_io); ex.read_raw(parser); + int n_user = ex.Get_n_user(); + int n_user_end = ex.Get_n_user_end(); + ex.Set_n_user_end(n_user); + Rxn_exchange_map[n_user] = ex; + if (n_user_end > n_user) + { + for (int i = n_user + 1; i <= n_user_end; i++) + { + Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); + } + } +#ifdef SKIP //struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); struct exchange *exchange_ptr = cxxExchange2exchange(&ex); int n; @@ -209,6 +221,7 @@ read_exchange_raw(void) } exchange_free(exchange_ptr); free_check_null(exchange_ptr); +#endif // Need to output the next keyword if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); @@ -1258,7 +1271,7 @@ read_exchange_modify(void) // find exchange number char token[MAX_LENGTH]; char *next; - int l, n_user, n; + int l, n_user; next = line; copy_token(token, &next, &l); if (copy_token(token, &next, &l) != DIGIT) @@ -1300,6 +1313,38 @@ read_exchange_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } + cxxExchange * entity = Utilities::Rxn_find(Rxn_exchange_map, n_user); + if (entity == NULL) + { + input_error++; + error_string = sformatf( "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + entity->read_raw(parser, false); + + /* recalculate formula_totals */ + std::map::iterator cit = entity->Get_exchComps().begin(); + for ( ; cit != entity->Get_exchComps().end(); cit++) + { + char * temp_formula = string_duplicate(cit->second.Get_formula().c_str()); + char *ptr = temp_formula; + + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, 1.0); + + cxxNameDouble nd(elt_list_save()); + //exchange[n].comps[i].formula_totals = elt_list_save(); + //free_check_null(temp_formula); + cit->second.Set_formula_totals(elt_list_save()); + } + + + +#ifdef SKIP if (exchange_bsearch(n_user, &n) == NULL) { input_error++; @@ -1341,7 +1386,7 @@ read_exchange_modify(void) //exchange[n].new_def = TRUE; exchange_free(entity_ptr); free_check_null(entity_ptr); - +#endif // Need to output the next keyword if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); @@ -1945,6 +1990,22 @@ delete_entities(void) } // exchangers + if (delete_info.Get_exchange().Get_defined()) + { + if (delete_info.Get_exchange().Get_numbers().size() == 0) + { + Rxn_exchange_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_exchange().Get_numbers().begin(); it != delete_info.Get_exchange().Get_numbers().end(); it++) + { + Rxn_exchange_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_exchange().Get_defined()) { if (delete_info.Get_exchange().Get_numbers().size() == 0) @@ -1966,7 +2027,7 @@ delete_entities(void) } } } - +#endif // surfaces if (delete_info.Get_surface().Get_defined()) { @@ -2433,6 +2494,27 @@ dump_ostream(std::ostream& os) } // exchanges + if (dump_info.Get_bool_exchange()) + { + if (dump_info.Get_exchange().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_exchange_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_exchange().begin(); it != dump_info.Get_exchange().end(); it++) + { + cxxExchange *p = Utilities::Rxn_find(Rxn_exchange_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_exchange()) { if (dump_info.Get_exchange().size() == 0) @@ -2457,7 +2539,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // surfaces if (dump_info.Get_bool_surface()) { From 97a38235cbfb8b6c9cfed434b93fbe040097c913 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Dec 2011 17:37:14 +0000 Subject: [PATCH 0390/1077] Made const char * git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5962 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NumKeyword.h b/NumKeyword.h index de028ee2..3355f334 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -24,7 +24,7 @@ class cxxNumKeyword: public PHRQ_base { this->description = str; } - void Set_description(char *str) + void Set_description(const char *str) { if (str != NULL) this->description = str; From ddafdd170fb35ca55727e2c3d4ac14d0be7b74c8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Dec 2011 17:38:45 +0000 Subject: [PATCH 0391/1077] Added missing members to dump/read _raw git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5964 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 5e142dd6..659a271a 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -165,8 +165,16 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << std::endl; s_oss << indent1; - s_oss << "-exchange_gammas " << this-> - pitzer_exchange_gammas << std::endl; + s_oss << "-new_def " << this->new_def << std::endl; + + s_oss << indent1; + s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << std::endl; + + s_oss << indent1; + s_oss << "-solution_equilibria " << this->solution_equilibria << std::endl; + + s_oss << indent1; + s_oss << "-n_solution " << this->n_solution << std::endl; // exchComps structures for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); @@ -190,6 +198,9 @@ cxxExchange::read_raw(CParser & parser, bool check) vopts.push_back("pitzer_exchange_gammas"); // 0 vopts.push_back("component"); // 1 vopts.push_back("exchange_gammas"); // 2 + vopts.push_back("new_def"); // 3 + vopts.push_back("solution_equilibria"); // 4 + vopts.push_back("n_solution"); // 4 } std::istream::pos_type ptr; @@ -271,6 +282,42 @@ cxxExchange::read_raw(CParser & parser, bool check) } useLastLine = true; break; + case 3: // new_def + if (!(parser.get_iss() >> this->new_def)) + { + this->new_def = false; + parser.incr_input_error(); + parser. + error_msg + ("Expected boolean value for new_def.", + CParser::OT_CONTINUE); + } + useLastLine = false; + break; + case 4: // solution_equilibria + if (!(parser.get_iss() >> this->solution_equilibria)) + { + this->solution_equilibria = false; + parser.incr_input_error(); + parser. + error_msg + ("Expected boolean value for solution_equilibria.", + CParser::OT_CONTINUE); + } + useLastLine = false; + break; + case 5: // n_solution + if (!(parser.get_iss() >> this->n_solution)) + { + this->n_solution = -999; + parser.incr_input_error(); + parser. + error_msg + ("Expected integer value for n_solution.", + CParser::OT_CONTINUE); + } + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; From acf62c7881156b78f19cc7855a329592764469ca Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Jan 2012 16:07:40 +0000 Subject: [PATCH 0392/1077] gas_phase and irrev removed. get_line moved to PHRQ_io. Still debugging some. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5967 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 2 +- ChartObject.cpp | 65 +++---- ExchComp.cxx | 78 ++++---- ExchComp.h | 4 +- Exchange.cxx | 32 ++-- Exchange.h | 15 +- GasPhase.cxx | 307 +++++++++++++++++++++++-------- GasPhase.h | 44 ++++- ISolution.cxx | 6 +- ISolutionComp.cxx | 10 +- KineticsComp.cxx | 62 +++---- NameDouble.cxx | 6 +- PHRQ_base.cxx | 12 +- PHRQ_io.cpp | 271 ++++++++++++++++++++++++++- PHRQ_io.h | 42 +++++ PPassemblage.cxx | 16 +- PPassemblageComp.cxx | 82 ++++----- Parser.cxx | 217 ++++++++++++++-------- Parser.h | 80 ++++---- Phreeqc.cpp | 72 +++++--- Phreeqc.h | 95 ++++++---- Pressure.cxx | 49 ++--- Pressure.h | 8 +- Reaction.cxx | 56 +++--- Reaction.h | 21 ++- ReadClass.cxx | 422 +++++++++++++++++++++++++++++++++++-------- SSassemblage.cxx | 12 +- SSassemblageSS.cxx | 89 +++++---- Solution.cxx | 152 ++++++++-------- SolutionIsotope.cxx | 30 +-- StorageBin.cxx | 62 +++---- StorageBinList.cpp | 12 +- Surface.cxx | 118 ++++++------ SurfaceCharge.cxx | 90 ++++----- SurfaceComp.cxx | 90 ++++----- Temperature.cxx | 48 ++--- Temperature.h | 8 +- Utils.cxx | 1 + Utils.h | 86 ++++++++- cxxKinetics.cxx | 68 +++---- cxxMix.cxx | 18 +- cxxMix.h | 4 +- dumper.cpp | 13 +- runner.cpp | 14 +- 44 files changed, 1969 insertions(+), 1020 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index f83ceafa..03725a21 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -125,7 +125,7 @@ ChartHandler::End_timer() // size_t i; // for (i = 0; i < it->second->Get_Curves().size(); i ++) // { - // std::cerr << "Curve " << i << ", number of points " << it->second->Get_Curves()[i]->Get_x().size() << std::endl; + // std::cerr << "Curve " << i << ", number of points " << it->second->Get_Curves()[i]->Get_x().size() << "\n"; // } //} size_t i = 0; diff --git a/ChartObject.cpp b/ChartObject.cpp index 3ff9f01c..0d693080 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -142,7 +142,7 @@ ChartObject::Set_axis_scale(CParser & parser) } if (string_vector.size() == 0) { - error_msg("No axis defined for scales", CParser::OT_CONTINUE); + error_msg("No axis defined for scales", PHRQ_io::OT_CONTINUE); return false; } std::string str = string_vector[0]; @@ -168,8 +168,8 @@ ChartObject::Set_axis_scale(CParser & parser) std::ostringstream estream; estream << "Found " << str; estream << ", but expect axis type \'x\', \'y\', \'y2\'or \'sy\'."; - estream << std::endl; - error_msg(estream.str().c_str(), CParser::OT_CONTINUE); + estream << "\n"; + error_msg(estream.str().c_str(), PHRQ_io::OT_CONTINUE); return false; } @@ -189,7 +189,7 @@ ChartObject::Set_axis_scale(CParser & parser) std::ostringstream estream; estream << "Found " << s; estream << ", but expect number or 'a(uto)'."; - estream << std::endl; + estream << "\n"; error_msg(estream.str().c_str(), CONTINUE); return false; } @@ -205,7 +205,7 @@ ChartObject::Set_axis_scale(CParser & parser) { std::ostringstream estream; estream << "MIN and MAX must be > 0 for log " << type << "-scale."; - estream << std::endl; + estream << "\n"; error_msg(estream.str().c_str(), CONTINUE); return false; } @@ -217,8 +217,8 @@ ChartObject::Set_axis_scale(CParser & parser) if (scale_ptr[0] > scale_ptr[1]) { std::ostringstream estream; - estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << std::endl; - estream << "Switching values for MIN and MAX. " << std::endl; + estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << "\n"; + estream << "Switching values for MIN and MAX. " << "\n"; warning_msg(estream.str().c_str()); double t; t = scale_ptr[0]; @@ -468,9 +468,10 @@ ChartObject::OpenCSVFile(std::string file_name) return false; } - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(f_csv, oss_out, oss_err, this->Get_io()); + //std::ostringstream oss_out; + //std::ostringstream oss_err; + //CParser parser(f_csv, oss_out, oss_err, this->Get_io()); + CParser parser(f_csv, this->Get_io()); parser.set_echo_file(CParser::EO_NONE); /* Get lines */ @@ -481,7 +482,7 @@ ChartObject::OpenCSVFile(std::string file_name) std::vector csv_curves; // Read file line by line into temporary curves - while (parser.check_line("cvs file", false, true, true, false) != CParser::LT_EOF) + while (parser.check_line("cvs file", false, true, true, false) != PHRQ_io::LT_EOF) { // Headings line if (linenr == 0) @@ -743,7 +744,7 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) // Add to list of new plotxy curves this->new_plotxy_curves.push_back(new_curve); - //std::cerr << revised_line << std::endl; + //std::cerr << revised_line << "\n"; cmd_line = revised_line; } void @@ -755,7 +756,7 @@ ChartObject::Set_rate_struct(void) std::ostringstream oss; for (; it != rate_command_list.end(); it++) { - oss << *it << std::endl; + oss << *it << "\n"; } this->Rate_free(); this->user_graph->commands = (char *) P_INSTANCE_POINTER PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); @@ -930,7 +931,7 @@ ChartObject::SaveCurvesToFile(std::string &file_name) if ((*it)->Get_x().size() > max_points) max_points = (*it)->Get_x().size(); } - f_out << std::endl; + f_out << "\n"; // write data size_t i2 = 0; @@ -955,7 +956,7 @@ ChartObject::SaveCurvesToFile(std::string &file_name) f_out << "\t"; } } - f_out << std::endl; + f_out << "\n"; i2++; } f_out.close(); @@ -1101,10 +1102,10 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) indent0.append(Utilities::INDENT); for (i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - oss << indent0 << "USER_GRAPH " << this->n_user << " " << this->description << std::endl; + oss << indent0 << "USER_GRAPH " << this->n_user << " " << this->description << "\n"; // chart title - oss << indent1 << "-chart_title \"" << this->chart_title << "\"" << std::endl; + oss << indent1 << "-chart_title \"" << this->chart_title << "\"" << "\n"; // axis titles if (this->axis_titles.size() > 0) @@ -1115,7 +1116,7 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) { oss << "\"" << axis_titles[i] << "\" "; } - oss << std::endl; + oss << "\n"; } // axis_scale_x @@ -1137,7 +1138,7 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) { oss << " log"; } - oss << std::endl; + oss << "\n"; } // axis_scale_y scale_ptr = this->axis_scale_y; @@ -1158,7 +1159,7 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) { oss << " log"; } - oss << std::endl; + oss << "\n"; } // axis_scale_sy scale_ptr = this->axis_scale_y2; @@ -1179,39 +1180,39 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) { oss << " log"; } - oss << std::endl; + oss << "\n"; } // chart type if (this->chart_type == 0) { - oss << indent1 << "-plot_concentration_vs x" << std::endl; + oss << indent1 << "-plot_concentration_vs x" << "\n"; } else { - oss << indent1 << "-plot_concentration_vs t" << std::endl; + oss << indent1 << "-plot_concentration_vs t" << "\n"; } // graph_initial_solutions if (this->graph_initial_solutions) { - oss << indent1 << "-initial_solutions true" << std::endl; + oss << indent1 << "-initial_solutions true" << "\n"; } else { - oss << indent1 << "-initial_solutions false" << std::endl; + oss << indent1 << "-initial_solutions false" << "\n"; } // connect_simulations if (this->connect_simulations) { - oss << indent1 << "-connect_simulations true" << std::endl; + oss << indent1 << "-connect_simulations true" << "\n"; } else { - oss << indent1 << "-connect_simulations false" << std::endl; + oss << indent1 << "-connect_simulations false" << "\n"; } // csv files for (i = 0; i < this->csv_file_names.size(); i++) { - oss << indent1 << "-plot_csv_file " << this->csv_file_names[i] << std::endl; + oss << indent1 << "-plot_csv_file " << this->csv_file_names[i] << "\n"; } // headings @@ -1222,17 +1223,17 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) { oss << this->headings_original[i] << " "; } - oss << std::endl; + oss << "\n"; } // commands - oss << indent1 << "-start" << std::endl; + oss << indent1 << "-start" << "\n"; std::list::iterator it = rate_command_list_original.begin(); for (; it != rate_command_list_original.end(); it++) { - oss << *it << std::endl; + oss << *it << "\n"; } - oss << indent1 << "-end" << std::endl; + oss << indent1 << "-end" << "\n"; /* struct rate *user_graph; diff --git a/ExchComp.cxx b/ExchComp.cxx index 3877e26b..2a52469b 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -140,33 +140,33 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const // Exch_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; s_oss << indent0 << "formula_z=\"" << this-> - formula_z << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + formula_z << "\"" << "\n"; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; + s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << std::endl; + charge_balance << "\"" << "\n"; if (this->phase_name.size() != 0) { - s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << std::endl; + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << "\n"; } if (this->rate_name.size() != 0) { s_oss << indent0 << "rate_name=\"" << this-> - rate_name << "\"" << std::endl; + rate_name << "\"" << "\n"; } s_oss << indent0 << "phase_proportion=\"" << this-> - phase_proportion << "\"" << std::endl; + phase_proportion << "\"" << "\n"; // totals s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); // formula_totals s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); } @@ -186,35 +186,35 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Exch_Comp element and attributes - s_oss << indent0 << "-formula " << this->formula << std::endl; + s_oss << indent0 << "-formula " << this->formula << "\n"; - //s_oss << indent1 << "# critical values" << std::endl; + //s_oss << indent1 << "# critical values" << "\n"; // totals s_oss << indent1; - s_oss << "-totals" << std::endl; + s_oss << "-totals" << "\n"; this->totals.dump_raw(s_oss, indent + 2); - s_oss << indent1 << "-charge_balance " << this->charge_balance << std::endl; + s_oss << indent1 << "-charge_balance " << this->charge_balance << "\n"; - //s_oss << indent1 << "# Noncritical values" << std::endl; - s_oss << indent1 << "-moles " << this->moles << std::endl; - s_oss << indent1 << "-la " << this->la << std::endl; + //s_oss << indent1 << "# Noncritical values" << "\n"; + s_oss << indent1 << "-moles " << this->moles << "\n"; + s_oss << indent1 << "-la " << this->la << "\n"; if (this->phase_name.size() != 0) { - s_oss << indent1 << "-phase_name " << this->phase_name << std::endl; + s_oss << indent1 << "-phase_name " << this->phase_name << "\n"; } if (this->rate_name.size() != 0) { - s_oss << indent1 << "-rate_name " << this->rate_name << std::endl; + s_oss << indent1 << "-rate_name " << this->rate_name << "\n"; } - s_oss << indent1 << "-phase_proportion " << this->phase_proportion << std::endl; - s_oss << indent1 << "-formula_z " << this->formula_z << std::endl; + s_oss << indent1 << "-phase_proportion " << this->phase_proportion << "\n"; + s_oss << indent1 << "-formula_z " << this->formula_z << "\n"; // formula_totals s_oss << indent1; - s_oss << "-formula_totals" << std::endl; + s_oss << "-formula_totals" << "\n"; this->formula_totals.dump_raw(s_oss, indent + 2); } @@ -270,8 +270,8 @@ cxxExchComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in EXCH_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in EXCH_COMP read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // formula @@ -280,7 +280,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for formula.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -295,7 +295,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for moles.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } moles_defined = true; break; @@ -306,7 +306,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->la = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } la_defined = true; break; @@ -317,7 +317,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->charge_balance = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge_balance.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } charge_balance_defined = true; break; @@ -328,7 +328,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->phase_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for phase_name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -342,7 +342,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -356,7 +356,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) this->formula_z = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for formula_z.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } formula_z_defined = true; break; @@ -368,7 +368,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected numeric value for phase_proportion.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } break; @@ -380,7 +380,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for ExchComp totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 8; break; @@ -393,7 +393,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for ExchComp formula totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 9; break; @@ -408,31 +408,31 @@ cxxExchComp::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Formula not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (moles_defined == false) { parser.incr_input_error(); parser.error_msg("Moles not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (la_defined == false) { parser.incr_input_error(); parser.error_msg("La not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (charge_balance_defined == false) { parser.incr_input_error(); parser.error_msg("Charge_balance not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (formula_z_defined == false) { parser.incr_input_error(); parser.error_msg("Formula_z not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/ExchComp.h b/ExchComp.h index 65bdbb9e..e01202c6 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -121,8 +121,8 @@ class cxxExchComp: public PHRQ_base this->formula_totals = nd; } - cxxNameDouble & Get_totals() {return (this->totals);}; - cxxNameDouble & Get_formula_totals(void) {return this->formula_totals;}; + cxxNameDouble & Get_totals() {return (this->totals);} + cxxNameDouble & Get_formula_totals(void) {return this->formula_totals;} void add(const cxxExchComp & comp, double extensive); diff --git a/Exchange.cxx b/Exchange.cxx index 659a271a..21160896 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -127,15 +127,15 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const // Exchange element and attributes s_oss << indent0; - s_oss << " - pitzer_exchange_gammas << "\"" << std::endl; + pitzer_exchange_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { @@ -162,26 +162,26 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Exchange element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-new_def " << this->new_def << std::endl; + s_oss << "-new_def " << this->new_def << "\n"; s_oss << indent1; - s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << std::endl; + s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << "\n"; s_oss << indent1; - s_oss << "-solution_equilibria " << this->solution_equilibria << std::endl; + s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; s_oss << indent1; - s_oss << "-n_solution " << this->n_solution << std::endl; + s_oss << "-n_solution " << this->n_solution << "\n"; // exchComps structures for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); it != exchComps.end(); ++it) { s_oss << indent1; - s_oss << "-component" << std::endl; + s_oss << "-component" << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } @@ -236,8 +236,8 @@ cxxExchange::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in EXCH_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -250,7 +250,7 @@ cxxExchange::read_raw(CParser & parser, bool check) parser. error_msg ("Expected boolean value for pitzer_exchange_gammas.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } pitzer_exchange_gammas_defined = true; useLastLine = false; @@ -290,7 +290,7 @@ cxxExchange::read_raw(CParser & parser, bool check) parser. error_msg ("Expected boolean value for new_def.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } useLastLine = false; break; @@ -302,7 +302,7 @@ cxxExchange::read_raw(CParser & parser, bool check) parser. error_msg ("Expected boolean value for solution_equilibria.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } useLastLine = false; break; @@ -314,7 +314,7 @@ cxxExchange::read_raw(CParser & parser, bool check) parser. error_msg ("Expected integer value for n_solution.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } useLastLine = false; break; @@ -331,7 +331,7 @@ cxxExchange::read_raw(CParser & parser, bool check) parser. error_msg ("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/Exchange.h b/Exchange.h index 510dd69f..743a5154 100644 --- a/Exchange.h +++ b/Exchange.h @@ -32,15 +32,16 @@ public: bool Get_pitzer_exchange_gammas() const; void Set_pitzer_exchange_gammas(bool b); - bool Get_new_def(void) const {return this->new_def;}; - void Set_new_def(bool tf) {this->new_def = tf;}; - bool Get_solution_equilibria(void) const {return this->solution_equilibria;}; - void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;}; - int Get_n_solution(void) const {return this->n_solution;}; - void Set_n_solution(int i) {this->n_solution = i;}; + bool Get_new_def(void) const {return this->new_def;} + void Set_new_def(bool tf) {this->new_def = tf;} + bool Get_solution_equilibria(void) const {return this->solution_equilibria;} + void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;} + int Get_n_solution(void) const {return this->n_solution;} + void Set_n_solution(int i) {this->n_solution = i;} cxxExchComp *ExchComp_find(std::string s); - std::map < std::string, cxxExchComp > &Get_exchComps(void) ; + std::map < std::string, cxxExchComp > &Get_exchComps(void); + void totalize(); const cxxNameDouble & Get_totals() const; diff --git a/GasPhase.cxx b/GasPhase.cxx index 70b462a0..47c2cc1c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -25,47 +25,98 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) // : cxxNumKeyword(io) { + new_def = true; + solution_equilibria = false; + n_solution = -999; + type = cxxGasPhase::GP_PRESSURE; + total_p = 1.0; + volume = 1.0; + v_m = 0; + pr_in = false; + temperature = 298.15; +} + +cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, + cxxMix & mx, int l_n_user, PHRQ_io * io) +: cxxNumKeyword(io) +{ + this->n_user = this->n_user_end = l_n_user; total_p = 0; volume = 0; v_m = 0; pr_in = false; - gasPhaseComps.type = cxxNameDouble::ND_NAME_COEF; -} + bool first = true; +// +// Mix +// + // accumulate in map + std::map comp_map; + std::map::iterator comp_it; -cxxGasPhase::cxxGasPhase(struct gas_phase *gas_phase_ptr, PHRQ_io * io) - // - // constructor for cxxGasPhase from struct gas_phase - // - : -cxxNumKeyword(io) -{ - int i; - - this->Set_description(gas_phase_ptr->description); - n_user = gas_phase_ptr->n_user; - n_user_end = gas_phase_ptr->n_user_end; - if (gas_phase_ptr->type == PRESSURE) + const std::map < int, double > & mixcomps = mx.Get_mixComps(); + std::map < int, double >::const_iterator it; + for (it = mixcomps.begin(); it != mixcomps.end(); it++) { - type = cxxGasPhase::GP_PRESSURE; + const cxxGasPhase *entity_ptr = &(entity_map.find(it->first)->second); + if (first) + { + this->new_def = entity_ptr->new_def; + this->solution_equilibria = entity_ptr->solution_equilibria; + this->n_solution = entity_ptr->n_solution; + this->type = entity_ptr->type; + this->total_p = entity_ptr->total_p * it->second; + this->total_moles = entity_ptr->total_moles * it->second; + this->volume = entity_ptr->volume * it->second; + this->v_m = entity_ptr->v_m * it->second; + this->pr_in = entity_ptr->pr_in; + this->temperature = entity_ptr->temperature; + first = false; + } + else + { + if (this->type != entity_ptr->type) + { + std::ostringstream oss; + oss << "Can not mix two gas_phases with differing types."; + error_msg(oss.str().c_str(), CONTINUE); + return; + } + + this->total_p += entity_ptr->total_p * it->second; + this->volume += entity_ptr->volume * it->second; + this->v_m += entity_ptr->v_m * it->second; + } + cxxGasPhase *gas_phase_ptr = Utilities::Rxn_find(entity_map, it->first); + if (gas_phase_ptr) + { + std::vector add_comps = gas_phase_ptr->Get_gas_comps(); + for (size_t i = 0; i < add_comps.size(); i++) + { + comp_it = comp_map.find(add_comps[i].Get_phase_name()); + if (comp_it != comp_map.end()) + { + comp_it->second.add(add_comps[i], it->second); + } + else + { + cxxGasComp gc(add_comps[i]); + gc.multiply(it->second); + comp_map[add_comps[i].Get_phase_name()] = gc; + } + } + + } } - else - { - type = cxxGasPhase::GP_VOLUME; - } - total_p = gas_phase_ptr->total_p; - volume = gas_phase_ptr->volume; - v_m = gas_phase_ptr->v_m; - pr_in = gas_phase_ptr->pr_in; - // gas_phase components - for (i = 0; i < gas_phase_ptr->count_comps; i++) + // put map into vector + this->gas_comps.clear(); + std::vector gc; + for (comp_it = comp_map.begin(); comp_it != comp_map.end(); comp_it++) { - if (gas_phase_ptr->comps[i].name == NULL) - continue; - gasPhaseComps[gas_phase_ptr->comps[i].name] = - gas_phase_ptr->comps[i].moles; + this->gas_comps.push_back(comp_it->second); } } +#ifdef SKIP cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): cxxNumKeyword(io) @@ -121,7 +172,7 @@ cxxNumKeyword(io) } } } - +#endif cxxGasPhase::~cxxGasPhase() { } @@ -143,15 +194,15 @@ cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const // GasPhase element and attributes s_oss << indent0; - s_oss << " - pitzer_gas_phase_gammas << "\"" << std::endl; + pitzer_gas_phase_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = gas_phaseComps.begin(); it != gas_phaseComps.end(); ++it) { @@ -179,27 +230,36 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // GasPhase element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "GAS_PHASE_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "GAS_PHASE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-type " << this->type << std::endl; - + s_oss << "-new_def " << this->new_def << "\n"; s_oss << indent1; - s_oss << "-total_p " << this->total_p << std::endl; - + s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; s_oss << indent1; - s_oss << "-volume " << this->volume << std::endl; - + s_oss << "-n_solution " << this->n_solution << "\n"; s_oss << indent1; - s_oss << "-v_m " << this->v_m << std::endl; - + s_oss << "-type " << this->type << "\n"; s_oss << indent1; - s_oss << "-pr_in " << (this->pr_in ? 1 : 0) << std::endl; + s_oss << "-total_p " << this->total_p << "\n"; + s_oss << indent1; + s_oss << "-total_moles " << this->total_moles << "\n"; + s_oss << indent1; + s_oss << "-volume " << this->volume << "\n"; + s_oss << indent1; + s_oss << "-v_m " << this->v_m << "\n"; + s_oss << indent1; + s_oss << "-pr_in " << (this->pr_in ? 1 : 0) << "\n"; + s_oss << indent1; + s_oss << "-temperature " << this->temperature << "\n"; // gasPhaseComps - s_oss << indent1; - s_oss << "-component" << std::endl; - this->gasPhaseComps.dump_raw(s_oss, indent + 2); + for (size_t i = 0 ; i < this->gas_comps.size(); i++) + { + s_oss << indent1; + s_oss << "-component" << "\n"; + this->gas_comps[i].dump_raw(s_oss, indent + 2); + } } void @@ -211,13 +271,18 @@ cxxGasPhase::read_raw(CParser & parser, bool check) if (vopts.empty()) { vopts.reserve(15); - vopts.push_back("type"); //0 - vopts.push_back("total_p"); //1 - vopts.push_back("volume"); //2 - vopts.push_back("v_m"); //3 - vopts.push_back("component"); //4 - vopts.push_back("pressure"); //5 - vopts.push_back("pr_in"); //6 + vopts.push_back("type"); //0 + vopts.push_back("total_p"); //1 + vopts.push_back("volume"); //2 + vopts.push_back("v_m"); //3 + vopts.push_back("component"); //4 + vopts.push_back("pressure"); //5 + vopts.push_back("pr_in"); //6 + vopts.push_back("new_def"); //7 + vopts.push_back("solution_equilibria"); //8 + vopts.push_back("n_solution"); //9 + vopts.push_back("total_moles"); //10 + vopts.push_back("temperature"); //11 } std::istream::pos_type ptr; @@ -261,8 +326,8 @@ cxxGasPhase::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in GAS_PHASE_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -273,7 +338,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) this->type = cxxGasPhase::GP_PRESSURE; parser.incr_input_error(); parser.error_msg("Expected enum for type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -290,7 +355,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) this->total_p = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for total_p.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } total_p_defined = true; useLastLine = false; @@ -302,7 +367,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) this->volume = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for volume.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } volume_defined = true; useLastLine = false; @@ -314,30 +379,37 @@ cxxGasPhase::read_raw(CParser & parser, bool check) this->v_m = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for v_m.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } v_m_defined = true; useLastLine = false; break; case 4: // component - if (this->gasPhaseComps.read_raw(parser, next_char) != - CParser::PARSER_OK) { - parser.incr_input_error(); - parser. - error_msg - ("Expected gas component name and moles for gasPhaseComps.", - CParser::OT_CONTINUE); + cxxGasComp gc; + //bool tf = gc.read_raw(parser, next_char); + //if (!tf + if (!gc.read_raw(parser, next_char)) + { + parser.incr_input_error(); + parser.error_msg + ("Expected gas component information.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->gas_comps.push_back(gc); + } + //opt_save = 4; + useLastLine = true; } - opt_save = 4; - useLastLine = false; break; case 6: // pr_in if (!(parser.get_iss() >> i)) { parser.incr_input_error(); - parser.error_msg("Expected 0/1 for pr_in.", CParser::OT_CONTINUE); + parser.error_msg("Expected 0/1 for pr_in.", PHRQ_io::OT_CONTINUE); } else { @@ -346,6 +418,58 @@ cxxGasPhase::read_raw(CParser & parser, bool check) pr_in_defined = true; useLastLine = false; break; + case 7: // new_def + if (!(parser.get_iss() >> i)) + { + parser.incr_input_error(); + parser.error_msg("Expected 0/1 for new_def.", PHRQ_io::OT_CONTINUE); + } + else + { + this->new_def = (i == 0) ? false : true; + } + useLastLine = false; + break; + case 8: // solution_equilibria + if (!(parser.get_iss() >> i)) + { + parser.incr_input_error(); + parser.error_msg("Expected 0/1 for solution_equilibria.", PHRQ_io::OT_CONTINUE); + } + else + { + this->solution_equilibria = (i == 0) ? false : true; + } + useLastLine = false; + break; + case 9: // n_solution + if (!(parser.get_iss() >> this->n_solution)) + { + parser.incr_input_error(); + parser.error_msg("Expected integer for n_solution.", PHRQ_io::OT_CONTINUE); + } + useLastLine = false; + break; + case 10: // 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); + } + useLastLine = false; + break; + case 11: // temperature + if (!(parser.get_iss() >> this->temperature)) + { + this->temperature = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for temperature.", + PHRQ_io::OT_CONTINUE); + } + useLastLine = false; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -357,31 +481,31 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Type not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (total_p_defined == false) { parser.incr_input_error(); parser.error_msg("Total_p not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (volume_defined == false) { parser.incr_input_error(); parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (v_m_defined == false) { parser.incr_input_error(); parser.error_msg("V_m not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (pr_in_defined == false) { parser.incr_input_error(); parser.error_msg("Pr_in not defined for GAS_PHASE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } @@ -436,6 +560,29 @@ cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void cxxGasPhase::totalize(PHREEQC_PTR_ARG) +{ + this->totals.clear(); + // component structures + for (size_t i = 0; i < this->gas_comps.size(); i++) + { + struct phase *phase_ptr; + int l; + phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->gas_comps[i].Get_phase_name().c_str(), &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, this->gas_comps[i].Get_moles()); + } + else + { + assert(false); + } + } + return; +} +#ifdef SKIP +void +cxxGasPhase::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures @@ -457,3 +604,13 @@ cxxGasPhase::totalize(PHREEQC_PTR_ARG) } return; } +#endif +LDBLE cxxGasPhase::Calc_total_moles(void) +{ + LDBLE tot = 0.0; + for (size_t i = 0; i < this->gas_comps.size(); i++) + { + tot += gas_comps[i].Get_moles(); + } + return tot; +} diff --git a/GasPhase.h b/GasPhase.h index 080b3b50..d9f09229 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -6,10 +6,11 @@ #include // std::string #include // std::list #include // std::vector - +#include "phrqtype.h" #include "NumKeyword.h" #include "NameDouble.h" #include "Phreeqc_class.h" +#include "GasComp.h" class cxxMix; class cxxGasPhase:public cxxNumKeyword @@ -17,9 +18,8 @@ class cxxGasPhase:public cxxNumKeyword public: cxxGasPhase(PHRQ_io * io=NULL); - cxxGasPhase(struct gas_phase *, PHRQ_io * io=NULL); - cxxGasPhase(const std::map < int, cxxGasPhase > &entity_map, - cxxMix & mx, int n_user, PHRQ_io * io=NULL); + cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, + cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxGasPhase(); enum GP_TYPE @@ -45,26 +45,50 @@ class cxxGasPhase:public cxxNumKeyword { return this->totals; }; - const cxxNameDouble & Get_gasPhaseComps(void) const {return gasPhaseComps;}; + std::vector & Get_gas_comps(void) {return gas_comps;}; + void Set_gas_comps(const std::vector v) {gas_comps = v;}; + GP_TYPE Get_type(void) const {return type;}; + void Set_type(GP_TYPE t) {type = t;}; double Get_total_p(void) const {return total_p;}; double Get_volume(void) const {return volume;}; + void Set_volume(LDBLE v) {volume = v;}; double Get_v_m(void) const {return v_m;}; + void Set_v_m(LDBLE v) {v_m = v;}; bool Get_pr_in(void) const {return pr_in;}; + void Set_pr_in(bool tf) {pr_in = tf;}; cxxNameDouble & Get_totals(void) {return totals;}; + bool Get_new_def(void) const {return this->new_def;}; + void Set_new_def(bool tf) {this->new_def = tf;}; + bool Get_solution_equilibria(void) const {return this->solution_equilibria;}; + void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;}; + int Get_n_solution(void) const {return this->n_solution;}; + void Set_n_solution(int i) {this->n_solution = i;}; + LDBLE Get_total_moles(void) {return (LDBLE) total_moles;}; + void Set_total_moles(LDBLE t) {total_moles = t;}; + LDBLE Get_total_p(void) {return (LDBLE) total_p;}; + void Set_total_p(LDBLE t) {total_p = t;}; + LDBLE Get_temperature(void) {return (LDBLE) temperature;}; + void Set_temperature(LDBLE t) {temperature = t;}; + LDBLE Calc_total_moles(void); + protected: void add(const cxxGasPhase & addee, double extensive); protected: - cxxNameDouble gasPhaseComps; + bool new_def; + bool solution_equilibria; + int n_solution; GP_TYPE type; - double total_p; - double volume; - double v_m; + LDBLE total_p; + LDBLE total_moles; + LDBLE volume; + LDBLE v_m; bool pr_in; + LDBLE temperature; + std::vector gas_comps; cxxNameDouble totals; - }; #endif // !defined(GASPHASE_H_INCLUDED) diff --git a/ISolution.cxx b/ISolution.cxx index 842ccc97..f3faee0f 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -193,8 +193,8 @@ cxxISolution & cxxISolution::read(CParser & parser) case CParser::OPTION_ERROR: opt = CParser::OPTION_EOF; CParser::error_msg("Unknown input in SOLUTION keyword.", - CParser::OT_CONTINUE); - CParser::error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + CParser::error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // temp @@ -299,7 +299,7 @@ cxxISolution & cxxISolution::read(CParser & parser) parser. error_msg ("Expected numeric value for mass of water in solution.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 43f1fb72..2547bed8 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -169,7 +169,7 @@ cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, parser. error_msg ("No element or master species given for concentration input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return cxxISolutionComp::ERROR; } description = token1; @@ -189,7 +189,7 @@ cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, std::ostringstream err; err << "Concentration data error for " << token1 << " in solution input."; - parser.error_msg(err, CParser::OT_CONTINUE); + parser.error_msg(err, PHRQ_io::OT_CONTINUE); return cxxISolutionComp::ERROR; } if ((j = parser.copy_token(token, ptr)) == CParser::TT_EMPTY) @@ -232,7 +232,7 @@ cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) { parser.error_msg("Expecting gram formula weight.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return cxxISolutionComp::ERROR; } else @@ -272,7 +272,7 @@ cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, // Check for saturation index if (!(std::istringstream(token) >> this->phase_si)) { - parser.error_msg("Expected saturation index.", CParser::OT_CONTINUE); + parser.error_msg("Expected saturation index.", PHRQ_io::OT_CONTINUE); return cxxISolutionComp::ERROR; } return cxxISolutionComp::OK; @@ -295,6 +295,6 @@ cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const cons s_oss << " conc_moles=\"" << this->moles << "\""; - s_oss << "\">" << std::endl; + s_oss << "\">" << "\n"; } #endif diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 1a08fc9f..cf6f1f74 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -73,32 +73,32 @@ cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Kinetics_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; + s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << std::endl; + charge_balance << "\"" << "\n"; if (this->phase_name != NULL) { s_oss << indent0 << "phase_name=\"" << this-> - phase_name << "\"" << std::endl; + phase_name << "\"" << "\n"; } if (this->rate_name != NULL) { s_oss << indent0 << "rate_name=\"" << this-> - rate_name << "\"" << std::endl; + rate_name << "\"" << "\n"; } s_oss << indent0 << "phase_proportion=\"" << this-> - phase_proportion << "\"" << std::endl; + phase_proportion << "\"" << "\n"; // totals s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); // formula_totals s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); } #endif @@ -119,20 +119,20 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Kinetics_Comp element and attributes s_oss << indent0 << "-rate_name " << this-> - rate_name << std::endl; - s_oss << indent1 << "-tol " << this->tol << std::endl; - s_oss << indent1 << "-m " << this->m << std::endl; - s_oss << indent1 << "-m0 " << this->m0 << std::endl; - s_oss << indent1 << "-moles " << this->moles << std::endl; + rate_name << "\n"; + s_oss << indent1 << "-tol " << this->tol << "\n"; + s_oss << indent1 << "-m " << this->m << "\n"; + s_oss << indent1 << "-m0 " << this->m0 << "\n"; + s_oss << indent1 << "-moles " << this->moles << "\n"; // namecoef s_oss << indent1; - s_oss << "-namecoef" << std::endl; + s_oss << "-namecoef" << "\n"; this->namecoef.dump_raw(s_oss, indent + 2); // d_params s_oss << indent1; - s_oss << "-d_params" << std::endl; + s_oss << "-d_params" << "\n"; { int i = 0; s_oss << indent2; @@ -141,13 +141,13 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { if (i++ == 5) { - s_oss << std::endl; + s_oss << "\n"; s_oss << indent2; i = 0; } s_oss << *it << " "; } - s_oss << std::endl; + s_oss << "\n"; } } @@ -202,8 +202,8 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Kinetics for more processing - //parser.error_msg("Unknown input in KINETICS_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in KINETICS_COMP read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // rate_name @@ -212,7 +212,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -227,7 +227,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) this->tol = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for tol.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } tol_defined = true; break; @@ -238,7 +238,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) this->m = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for m.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } m_defined = true; break; @@ -249,7 +249,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) this->m0 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for m0.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } m0_defined = true; break; @@ -261,7 +261,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) this->moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for moles.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } moles_defined = true; break; @@ -275,7 +275,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for namecoef.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 5; break; @@ -304,31 +304,31 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Rate_name not defined for KineticsComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (tol_defined == false) { parser.incr_input_error(); parser.error_msg("Tol not defined for KineticsComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (m_defined == false) { parser.incr_input_error(); parser.error_msg("M not defined for KineticsComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (m0_defined == false) { parser.incr_input_error(); parser.error_msg("M0 not defined for KineticsComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (moles_defined == false) { parser.incr_input_error(); parser.error_msg("Moles not defined for KineticsComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/NameDouble.cxx b/NameDouble.cxx index 788ed6e7..7f533f32 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -193,7 +193,7 @@ cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const { s_oss << indent0; s_oss << xmlElement << xmlAtt1 << it->first << xmlAtt2 << it-> - second << "/>" << std::endl; + second << "/>" << "\n"; } } @@ -210,7 +210,7 @@ cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { s_oss << indent0; - s_oss << it->first << " " << it->second << std::endl; + s_oss << it->first << " " << it->second << "\n"; } } @@ -448,7 +448,7 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd) int n = dictionary.string2int(it->first); if (n < 0) { - std::cerr << it->first << std::endl; + std::cerr << it->first << "\n"; error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); } diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 0c62e6e0..63599c8e 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -25,7 +25,7 @@ error_msg(const std::string & stdstr, int stop) { this->base_error_count++; std::ostringstream msg; - msg << "ERROR: " << stdstr << std::endl; + msg << "ERROR: " << stdstr << "\n"; if (this->io) { this->io->output_msg(msg.str().c_str()); @@ -53,8 +53,8 @@ warning_msg(const std::string & stdstr) } else { - std::cerr << stdstr << std::endl; - std::cout << stdstr << std::endl; + std::cerr << stdstr << "\n"; + std::cout << stdstr << "\n"; } } @@ -67,7 +67,7 @@ output_msg(const std::string & stdstr) } else { - std::cout << stdstr << std::endl; + std::cout << stdstr << "\n"; } } @@ -80,7 +80,7 @@ screen_msg(const std::string & stdstr) } else { - std::cerr << stdstr << std::endl; + std::cerr << stdstr << "\n"; } } @@ -93,6 +93,6 @@ echo_msg(const std::string & stdstr) } else { - std::cout << stdstr << std::endl; + std::cout << stdstr << "\n"; } } \ No newline at end of file diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 0dbe65da..8aaa8c87 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -1,5 +1,7 @@ #include +#include "Utils.h" #include "PHRQ_io.h" +#include "Parser.h" #include #include @@ -358,11 +360,11 @@ warning_msg(const char *err_str) { if (error_ostream != NULL && error_on) { - (*error_ostream) << err_str << std::endl; + (*error_ostream) << err_str << "\n"; error_ostream->flush(); } std::ostringstream warn_str; - warn_str << err_str << std::endl; + warn_str << err_str << "\n"; log_msg(warn_str.str().c_str()); log_flush(); output_msg(warn_str.str().c_str()); @@ -516,4 +518,267 @@ pop_istream() istream_list.pop_front(); delete_istream_list.pop_front(); } -} \ No newline at end of file +} +/* ---------------------------------------------------------------------- */ +PHRQ_io::LINE_TYPE PHRQ_io:: +get_line(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line from input file put in "line". + * Copy of input line is stored in "line_save". + * Characters after # are discarded in line but retained in "line_save" + * + * Arguments: + * fp is file name + * Returns: + * EMPTY, + * EOF, + * KEYWORD, + * OK, + * OPTION + */ + int i; + bool empty; + std::string stdtoken; + void *cookie; + bool continue_loop = true;; + + PHRQ_io::LINE_TYPE return_value; + // loop for include files + for (;;) + { + cookie = this->get_istream(); + if (cookie == NULL) + { + break; + } + return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + /* + * Eliminate all characters after # sign as a comment + */ + i = -1; + empty = true; + /* + * Get line, check for eof + */ + continue_loop = false; + + + //if (!m_input_stream.eof()) + ////{ + //// error_msg("Reading input file.", OT_CONTINUE); + //// error_msg("istream::get() returned an error.", OT_STOP); + ////} + ////else + //{ + // //{{MOD + // m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + // //}}MOD + // m_next_keyword = Keywords::KEY_END; + // return LT_EOF; + //} + if (get_logical_line(cookie) == LT_EOF) + { + //if (!m_input_stream.eof()) + //{ + // error_msg("Reading input file.", OT_CONTINUE); + // error_msg("istream::get() returned an error.", OT_STOP); + //} + //pop next file + this->pop_istream(); + continue_loop = true; + break; + } + /* + * Get long lines + */ + bool empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + if (this->accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + + } + if (continue_loop) continue; + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + CParser::copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + + // add new include file to stack + //ptr = line; + //copy_token(stdtoken, &ptr); + + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + CParser::copy_token(stdtoken, beg, end); + Utilities::str_tolower(stdtoken); + if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) || + (strstr(stdtoken.c_str(),"include_file") == stdtoken.c_str())) + { + std::string file_name; + file_name.assign(beg, end); + file_name = trim(file_name); + + if (file_name.size() > 0) + { + std::ifstream *next_stream = new std::ifstream(file_name.c_str(), std::ios_base::in); + if (!next_stream->is_open()) + { + // error opening file + // error_string = sformatf( "Could not open include file %s", file_name); + std::ostringstream errstr; + errstr << "Could not open include file " << file_name; + error_msg(errstr.str().c_str(), OT_STOP); + } + this->push_istream(next_stream); + continue; + } + } + return return_value; + } + m_next_keyword = Keywords::KEY_END; + return LT_EOF; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +PHRQ_io::LINE_TYPE PHRQ_io:: +get_logical_line(void * cookie) +{ + int + j; + unsigned int + pos; + char + c; + if (!cookie) + return LT_EOF; + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + + //while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) + while ((j = istream_getc(cookie)) != EOF) + { + c = (char) j; + if (c == '#') + { + // ignore all chars after # until newline + do + { + c = (char) j; + if (c == '\n') + { + break; + } + m_line_save += c; + } + while ((j = istream_getc(cookie)) != EOF); + //while ((j = + // m_input_stream.get()) != std::char_traits < + // char >::eof()); + } + if (c == ';') + break; + if (c == '\n') + { + break; + } + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + //while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) + while ((j = PHRQ_io::istream_getc(cookie)) != EOF) + { + c = (char) j; + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') + { + // remove '\\' + for (; pos < m_line_save.size(); pos++) + { + m_line_save[pos] = m_line_save[pos + 1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) + break; + } + } + else + { + m_line_save += c; + } + } + if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) + { + return (LT_EOF); + } + return (LT_OK); +} + +bool PHRQ_io:: +check_key(std::string::iterator begin, std::string::iterator end) +{ + std::string lowercase; + CParser::copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), + tolower); + + m_next_keyword = Keywords::Keyword_search(lowercase); + if (m_next_keyword == Keywords::KEY_NONE) + { + return false; + } + return true; +} + diff --git a/PHRQ_io.h b/PHRQ_io.h index 680a5036..943b26e0 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -10,6 +10,7 @@ #include #include #include +#include "Keywords.h" class PhreeqcStop : std::exception { @@ -18,6 +19,20 @@ class PhreeqcStop : std::exception class IPQ_DLL_EXPORT PHRQ_io { public: + enum LINE_TYPE + { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; + + enum ONERROR_TYPE + { + OT_CONTINUE = 0, + OT_STOP = 1 + }; // constructor/destructor PHRQ_io(void); virtual ~ PHRQ_io(); @@ -103,6 +118,24 @@ public: void Set_screen_on(bool tf) {this->screen_on = tf;}; bool Get_screen_on(void) {return this->screen_on;}; + // input methods + LINE_TYPE get_line(void); + LINE_TYPE get_logical_line(void * cookie); + bool check_key(std::string::iterator begin, std::string::iterator end); + std::string & Get_m_line() {return m_line;} + std::string & Get_m_line_save() {return m_line_save;} + std::string & Get_accumulated() {return accumulated;} + LINE_TYPE Get_m_line_type() {return m_line_type;}; + void Set_accumulate(bool tf) + { + if (tf) + { + accumulated.clear(); + } + this->accumulate = tf; + } + Keywords::KEYWORDS Get_m_next_keyword() const {return m_next_keyword;} + // echo enum ECHO_OPTION { @@ -136,5 +169,14 @@ protected: std::list istream_list; std::list delete_istream_list; + + // input data members + Keywords::KEYWORDS m_next_keyword; + std::string m_line; + std::string m_line_save; + std::string accumulated; + bool accumulate; + LINE_TYPE m_line_type; }; + #endif /* _PHRQIO_H */ diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 05a1f136..8093e0af 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -92,14 +92,14 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const // PPassemblage element and attributes s_oss << indent0; - s_oss << "eltList.dump_xml(s_oss, indent + 1); // ppAssemblageComps s_oss << indent1; - s_oss << "::const_iterator it = ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { @@ -125,12 +125,12 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; s_oss << "EQUILIBRIUM_PHASES_RAW " << n_user_local << " " << this-> - description << std::endl; + description << "\n"; // eltList s_oss << indent1; - s_oss << "-eltList " << std::endl; + s_oss << "-eltList " << "\n"; this->eltList.dump_raw(s_oss, indent + 2); // ppAssemblagComps @@ -138,7 +138,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) { s_oss << indent1; - s_oss << "-component" << std::endl; + s_oss << "-component" << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } } @@ -191,8 +191,8 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) opt = CParser::OPT_EOF; parser. error_msg("Unknown input in EQUILIBRIUM_PHASES_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -203,7 +203,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected element name and moles for totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 0; break; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 2b2e7f54..373bdfca 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -73,21 +73,21 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const // Pure_Phase element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; s_oss << indent0 << "add_formula=\"" << this-> - add_formula << "\"" << std::endl; - s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; - s_oss << indent0 << "si_org=\"" << this->si_org << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + add_formula << "\"" << "\n"; + s_oss << indent0 << "si=\"" << this->si << "\"" << "\n"; + s_oss << indent0 << "si_org=\"" << this->si_org << "\"" << "\n"; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << "\n"; s_oss << indent0 << "initial_moles=\"" << this-> - initial_moles << "\"" << std::endl; + initial_moles << "\"" << "\n"; s_oss << indent0 << "force_equality=\"" << this-> - force_equality << "\"" << std::endl; + force_equality << "\"" << "\n"; s_oss << indent0 << "dissolve_only=\"" << this-> - dissolve_only << "\"" << std::endl; + dissolve_only << "\"" << "\n"; s_oss << indent0 << "precipitate_only=\"" << this-> - precipitate_only << "\"" << std::endl; + precipitate_only << "\"" << "\n"; } @@ -108,17 +108,17 @@ cxxPPassemblageComp::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 << std::endl; + s_oss << indent0 << "-name " << this->name << "\n"; if (this->add_formula.size() != 0) - s_oss << indent1 << "-add_formula " << this->add_formula << std::endl; - s_oss << indent1 << "-si " << this->si << std::endl; - s_oss << indent1 << "-si_org " << this->si_org << std::endl; - s_oss << indent1 << "-moles " << this->moles << std::endl; - s_oss << indent1 << "-delta " << this->delta << std::endl; - s_oss << indent1 << "-initial_moles " << this->initial_moles << std::endl; - s_oss << indent1 << "-force_equality " << this->force_equality << std::endl; - s_oss << indent1 << "-dissolve_only " << this->dissolve_only << std::endl; - s_oss << indent1 << "-precipitate_only " << this->precipitate_only << std::endl; + s_oss << indent1 << "-add_formula " << this->add_formula << "\n"; + s_oss << indent1 << "-si " << this->si << "\n"; + s_oss << indent1 << "-si_org " << this->si_org << "\n"; + s_oss << indent1 << "-moles " << this->moles << "\n"; + s_oss << indent1 << "-delta " << this->delta << "\n"; + s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n"; + s_oss << indent1 << "-force_equality " << this->force_equality << "\n"; + s_oss << indent1 << "-dissolve_only " << this->dissolve_only << "\n"; + s_oss << indent1 << "-precipitate_only " << this->precipitate_only << "\n"; } void @@ -176,8 +176,8 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in PURE_PHASE read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in PURE_PHASE read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name @@ -186,7 +186,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -201,7 +201,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->add_formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for add_formula.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -215,7 +215,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->si = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for si.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } si_defined = true; break; @@ -226,7 +226,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for moles.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } moles_defined = true; break; @@ -237,7 +237,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->delta = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for delta.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } delta_defined = true; break; @@ -248,7 +248,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->initial_moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for initial_moles.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } initial_moles_defined = true; break; @@ -260,7 +260,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->dissolve_only = false; parser.incr_input_error(); parser.error_msg("Expected boolean value for dissolve_only.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } dissolve_only_defined = true; if (this->dissolve_only) @@ -275,7 +275,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->force_equality = false; parser.incr_input_error(); parser.error_msg("Expected boolean value for force_equality.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } force_equality_defined = true; break; @@ -286,7 +286,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->precipitate_only = false; parser.incr_input_error(); parser.error_msg("Expected boolean value for precipitate_only.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } precipitate_only_defined = true; if (this->precipitate_only) @@ -300,7 +300,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) this->si_org = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for si_org.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } si_org_defined = true; break; @@ -315,37 +315,37 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Name not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (si_defined == false) { parser.incr_input_error(); parser.error_msg("Si not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (moles_defined == false) { parser.incr_input_error(); parser.error_msg("Moles not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (delta_defined == false) { parser.incr_input_error(); parser.error_msg("Delta not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (initial_moles_defined == false) { parser.incr_input_error(); parser.error_msg("Initial_moles not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (dissolve_only_defined == false) { parser.incr_input_error(); parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } /* don't check to maintain backward compatibility if (precipitate_only_defined == false) @@ -353,7 +353,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Precipitate_only not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } */ if (force_equality_defined == false) @@ -361,13 +361,13 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser.error_msg ("Force_equality not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (si_org_defined == false) { parser.incr_input_error(); parser.error_msg("Si_org not defined for PPassemblageComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/Parser.cxx b/Parser.cxx index 664d3e3c..fdf8f99d 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -19,12 +19,36 @@ ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// +CParser::CParser(PHRQ_io *io): +PHRQ_base(io), +m_input_stream(std::cin), +//m_output_stream(std::cout), +//m_error_stream(std::cerr), +m_input_error(0), +m_next_keyword(Keywords::KEY_NONE) +{ + if (!io) + { + error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP); + } + m_line_save = io->Get_m_line(); + m_line = io->Get_m_line(); + m_line_type = io->Get_m_line_type(); + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = true; + +} CParser::CParser(std::istream & input, PHRQ_io *io): PHRQ_base(io), m_input_stream(input), -m_output_stream(std::cout), -m_error_stream(std::cerr), +//m_output_stream(std::cout), +//m_error_stream(std::cerr), m_input_error(0), m_next_keyword(Keywords::KEY_NONE) { @@ -33,8 +57,10 @@ m_next_keyword(Keywords::KEY_NONE) echo_file = EO_ALL; echo_stream = EO_NONE; accumulate = false; + phrq_io_only = false; } +#ifdef SKIP CParser::CParser(std::istream & input, std::ostream & output, PHRQ_io *io) : PHRQ_base(io), @@ -66,16 +92,16 @@ m_next_keyword(Keywords::KEY_NONE) echo_stream = EO_NONE; accumulate = false; } - +#endif CParser::~CParser() { } -CParser::LINE_TYPE CParser::check_line(const std::string & str, +PHRQ_io::LINE_TYPE CParser::check_line(const std::string & str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print) { - LINE_TYPE + PHRQ_io::LINE_TYPE i; // Get line @@ -93,27 +119,30 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, case EO_NONE: break; case EO_ALL: - if (i != LT_EOF) + if (i != PHRQ_io::LT_EOF) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - get_output() << msg; + //get_output() << msg; + io->output_msg(msg.str().c_str()); } break; case EO_KEYWORDS: - if (i == LT_KEYWORD) + if (i == PHRQ_io::LT_KEYWORD) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - get_output() << msg; + //get_output() << msg; + io->output_msg(msg.str().c_str()); } break; case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) + if (i != PHRQ_io::LT_KEYWORD && i != PHRQ_io::LT_EOF) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; - get_output() << msg; + //get_output() << msg; + io->output_msg(msg.str().c_str()); } break; } @@ -123,7 +152,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, case EO_NONE: break; case EO_ALL: - if (i != LT_EOF) + if (i != PHRQ_io::LT_EOF) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; @@ -131,7 +160,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, } break; case EO_KEYWORDS: - if (i == LT_KEYWORD) + if (i == PHRQ_io::LT_KEYWORD) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; @@ -140,7 +169,7 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, break; case EO_NOKEYWORDS: - if (i != LT_KEYWORD && i != LT_EOF) + if (i != PHRQ_io::LT_KEYWORD && i != PHRQ_io::LT_EOF) { std::ostringstream msg; msg << "\t" << m_line_save << "\n"; @@ -149,34 +178,51 @@ CParser::LINE_TYPE CParser::check_line(const std::string & str, break; } } - while (i == LT_EMPTY && allow_empty == false); + while (i == PHRQ_io::LT_EMPTY && allow_empty == false); // Check eof - if (i == LT_EOF && allow_eof == false) + if (i == PHRQ_io::LT_EOF && allow_eof == false) { std::ostringstream msg; msg << "Unexpected eof while reading " << str << "\nExecution terminated.\n"; - error_msg(msg.str().c_str(), OT_STOP); + error_msg(msg.str().c_str(), PHRQ_io::OT_STOP); } // Check keyword - if (i == LT_KEYWORD && allow_keyword == false) + if (i == PHRQ_io::LT_KEYWORD && allow_keyword == false) { std::ostringstream msg; msg << "Expected data for " << str << ", but got a keyword ending data block."; - error_msg(msg.str().c_str(), OT_CONTINUE); + error_msg(msg.str().c_str(), PHRQ_io::OT_CONTINUE); incr_input_error(); } m_line_type = i; return i; } - -CParser::LINE_TYPE CParser::get_line() +PHRQ_io::LINE_TYPE CParser::get_line_phrq_io() { - CParser::LINE_TYPE return_value = LT_EMPTY; - while (return_value == LT_EMPTY) + m_line_type = io->get_line(); + m_line_save = io->Get_m_line_save(); + m_line = io->Get_m_line(); + m_next_keyword = io->Get_m_next_keyword(); + if (accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + return m_line_type; +} + +PHRQ_io::LINE_TYPE CParser::get_line() +{ + if (this->phrq_io_only) + { + return get_line_phrq_io(); + } + PHRQ_io::LINE_TYPE return_value = PHRQ_io::LT_EMPTY; + while (return_value == PHRQ_io::LT_EMPTY) { // // Eliminate all characters after # sign as a comment @@ -185,12 +231,12 @@ CParser::LINE_TYPE CParser::get_line() // // Get line, check for eof // - if (get_logical_line() == LT_EOF) + if (get_logical_line() == PHRQ_io::LT_EOF) { if (!m_input_stream.eof()) { - error_msg("Reading input file.", OT_CONTINUE); - error_msg("istream::get() returned an error.", OT_STOP); + error_msg("Reading input file.", PHRQ_io::OT_CONTINUE); + error_msg("istream::get() returned an error.", PHRQ_io::OT_STOP); } else { @@ -198,7 +244,7 @@ CParser::LINE_TYPE CParser::get_line() m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); //}}MOD m_next_keyword = Keywords::KEY_END; - return LT_EOF; + return PHRQ_io::LT_EOF; } } @@ -225,17 +271,17 @@ CParser::LINE_TYPE CParser::get_line() // // New line character encountered // - return_value = (empty ? LT_EMPTY : LT_OK); + return_value = (empty ? PHRQ_io::LT_EMPTY : PHRQ_io::LT_OK); } // // Determine return_value // - if (return_value == LT_OK) + if (return_value == PHRQ_io::LT_OK) { if (check_key(m_line.begin(), m_line.end())) { - return_value = LT_KEYWORD; + return_value = PHRQ_io::LT_KEYWORD; } else { @@ -246,7 +292,7 @@ CParser::LINE_TYPE CParser::get_line() if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) { - return_value = LT_OPTION; + return_value = PHRQ_io::LT_OPTION; } } } @@ -261,7 +307,7 @@ CParser::LINE_TYPE CParser::get_line() EOF on empty line on end of file or OK otherwise */ -CParser::LINE_TYPE CParser::get_logical_line() +PHRQ_io::LINE_TYPE CParser::get_logical_line() { int j; @@ -333,9 +379,9 @@ CParser::LINE_TYPE CParser::get_logical_line() } if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) { - return (LT_EOF); + return (PHRQ_io::LT_EOF); } - return (LT_OK); + return (PHRQ_io::LT_OK); } bool @@ -396,7 +442,7 @@ CParser::check_key(std::string::iterator begin, std::string::iterator end) } return true; } - +#ifdef SKIP CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, bool alkalinity, bool check_compatibility, @@ -503,7 +549,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, { std::ostringstream err; err << "Unknown unit, " << tot_units; - error_msg(err.str().c_str(), OT_CONTINUE); + error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; } @@ -531,7 +577,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, if (print) { error_msg("Only alkalinity can be entered in equivalents.", - OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; } @@ -564,11 +610,11 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, std::ostringstream err; err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; - error_msg(err.str().c_str(), OT_CONTINUE); + error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; } - +#endif CParser::TOKEN_TYPE CParser::token_type(const std::string & token) { if (!token.empty()) @@ -696,16 +742,16 @@ CParser::get_option(const std::vector < std::string > &opt_list, // // Read line // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) + PHRQ_io::LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == PHRQ_io::LT_EOF) { j = OPT_EOF; } - else if (lt == LT_KEYWORD) + else if (lt == PHRQ_io::LT_KEYWORD) { j = OPT_KEYWORD; } - else if (lt == LT_OPTION) + else if (lt == PHRQ_io::LT_OPTION) { opt_ptr = m_line.begin(); std::string::iterator end = m_line.end(); @@ -724,7 +770,10 @@ CParser::get_option(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } } } @@ -732,7 +781,10 @@ CParser::get_option(const std::vector < std::string > &opt_list, { if (true) // (database_file == NULL) { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } std::ostringstream err; @@ -785,16 +837,16 @@ CParser::get_option(const std::vector < std::string > &opt_list, // // Read line // - LINE_TYPE lt = check_line("get_option", false, true, true, true); - if (lt == LT_EOF) + PHRQ_io::LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == PHRQ_io::LT_EOF) { j = OPT_EOF; } - else if (lt == LT_KEYWORD) + else if (lt == PHRQ_io::LT_KEYWORD) { j = OPT_KEYWORD; } - else if (lt == LT_OPTION) + else if (lt == PHRQ_io::LT_OPTION) { std::string::iterator opt_ptr = m_line.begin(); std::string::iterator end = m_line.end(); @@ -850,7 +902,7 @@ CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, if (begin == end) { error_msg("Empty string in get_elt. Expected an element name.", - OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } @@ -876,7 +928,7 @@ CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, else if (begin == end) { error_msg("No ending bracket (]) for element name", - OT_CONTINUE); + PHRQ_io::OT_CONTINUE); incr_input_error(); return PARSER_ERROR; } @@ -925,7 +977,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Element name must be followed by " << "parentheses in redox couple, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); incr_input_error(); return PARSER_ERROR; } @@ -941,7 +993,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "End of line or " "/" " encountered before end of parentheses, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } paren1.insert(paren1.end(), *ptr); // element.push_back(c); @@ -959,7 +1011,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << " " "/" " must follow parentheses " << "ending first half of redox couple, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } ++ptr; @@ -970,7 +1022,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Redox couple must be two redox states " << "of the same element, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } if (*ptr != '(') @@ -978,7 +1030,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Element name must be followed by " "parentheses in redox couple, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); incr_input_error(); return PARSER_ERROR; } @@ -993,7 +1045,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "End of line or " "/" " encountered before end of parentheses, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } paren2.insert(paren2.end(), *ptr); // element.push_back(c); @@ -1017,7 +1069,7 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) std::ostringstream err_msg; err_msg << "Both parts of redox couple are the same, " << token << "."; - error_msg(err_msg.str().c_str(), OT_CONTINUE); + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); return PARSER_ERROR; } return PARSER_OK; @@ -1036,7 +1088,7 @@ CParser::STATUS_TYPE CParser::addPair(std::map < std::string, double >&totals, j = copy_token(token, pos); - if (j == TT_EMPTY) + if (j == CParser::TT_EMPTY) return PARSER_OK; if (!(m_line_iss >> d)) @@ -1067,16 +1119,16 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, // // Read line // - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) + PHRQ_io::LINE_TYPE lt = m_line_type; + if (lt == PHRQ_io::LT_EOF) { j = OPT_EOF; } - else if (lt == LT_KEYWORD) + else if (lt == PHRQ_io::LT_KEYWORD) { j = OPT_KEYWORD; } - else if (lt == LT_OPTION) + else if (lt == PHRQ_io::LT_OPTION) { opt_ptr = m_line.begin(); std::string::iterator end = m_line.end(); @@ -1095,7 +1147,10 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } } } @@ -1103,7 +1158,10 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // (database_file == NULL) { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } //std::cerr << "Unknown option." << "\n"; //std::cerr << m_line_save << "\n"; @@ -1157,16 +1215,16 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, // // Read line // - LINE_TYPE lt = m_line_type; - if (lt == LT_EOF) + PHRQ_io::LINE_TYPE lt = m_line_type; + if (lt == PHRQ_io::LT_EOF) { j = OPT_EOF; } - else if (lt == LT_KEYWORD) + else if (lt == PHRQ_io::LT_KEYWORD) { j = OPT_KEYWORD; } - else if (lt == LT_OPTION) + else if (lt == PHRQ_io::LT_OPTION) { std::string::iterator opt_ptr = m_line.begin(); std::string::iterator end = m_line.end(); @@ -1191,7 +1249,10 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } } } @@ -1199,10 +1260,13 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // (database_file == NULL) { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } - error_msg("Unknown option.", OT_CONTINUE); - error_msg(m_line_save.c_str(), OT_CONTINUE); + error_msg("Unknown option.", PHRQ_io::OT_CONTINUE); + error_msg(m_line_save.c_str(), PHRQ_io::OT_CONTINUE); incr_input_error(); j = OPT_ERROR; next_pos = pos_ptr; @@ -1226,7 +1290,10 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - get_output() << "\t" << m_line_save << "\n"; + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); } } } @@ -1304,7 +1371,7 @@ bool CParser::get_true_false(std::istream::pos_type & pos, bool def) CParser::TOKEN_TYPE CParser::get_rest_of_line(std::string &token) { token.clear(); - std::istringstream::pos_type pos = m_line_iss.tellg(); + //std::istringstream::pos_type pos = m_line_iss.tellg(); int j; while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) { diff --git a/Parser.h b/Parser.h index 59563312..5bf84a01 100644 --- a/Parser.h +++ b/Parser.h @@ -12,18 +12,21 @@ #include // std::istream #include "PHRQ_base.h" #include "Keywords.h" +#include "PHRQ_io.h" + class CParser: public PHRQ_base { public: + CParser(PHRQ_io *io=NULL); CParser(std::istream & input, PHRQ_io *io=NULL); - CParser(std::istream & input, std::ostream & output, PHRQ_io *io=NULL); - CParser(std::istream & input, std::ostream & output, - std::ostream & error, PHRQ_io *io=NULL); + //CParser(std::istream & input, std::ostream & output, PHRQ_io *io=NULL); + //CParser(std::istream & input, std::ostream & output, + // std::ostream & error, PHRQ_io *io=NULL); virtual ~ CParser(); - +#ifdef SKIP enum LINE_TYPE { LT_EOF = -1, @@ -32,7 +35,7 @@ class CParser: public PHRQ_base LT_KEYWORD = 3, LT_OPTION = 8 }; - +#endif enum TOKEN_TYPE { TT_EMPTY = 2, @@ -48,26 +51,6 @@ class CParser: public PHRQ_base FT_ERROR = 1 }; -// enum KEY_TYPE -// { -// KT_NONE = -1, -// KT_END = 0, -// KT_EOF = 1, -// KT_SOLUTION_RAW = 5, -// KT_EXCHANGE_RAW = 6, -// KT_GASPHASE_RAW = 7, -// KT_KINETICS_RAW = 8, -// KT_PPASSEMBLAGE_RAW = 9, -// KT_SSASSEMBLAGE_RAW = 10, -// KT_SURFACE_RAW = 11, -// KT_TEMPERATURE_RAW = 12, -// KT_REACTION_RAW = 13, -// KT_MIX_RAW = 14 -//#if defined MULTICHART -// , KT_USER_GRAPH = 15 -//#endif -// }; - enum OPT_TYPE { OPT_DEFAULT = -4, @@ -75,13 +58,13 @@ class CParser: public PHRQ_base OPT_KEYWORD = -2, OPT_EOF = -1 }; - +#ifdef SKIP enum ONERROR_TYPE { OT_CONTINUE = 0, OT_STOP = 1 }; - +#endif enum ECHO_OPTION { EO_NONE = 0, @@ -116,7 +99,7 @@ class CParser: public PHRQ_base Terminates if EOF and allow_eof == false. */ - LINE_TYPE check_line(const std::string & str, bool allow_empty, + PHRQ_io::LINE_TYPE check_line(const std::string & str, bool allow_empty, bool allow_eof, bool allow_keyword, bool print); /** @@ -133,14 +116,15 @@ class CParser: public PHRQ_base LT_OK, LT_OPTION */ - LINE_TYPE get_line(); + PHRQ_io::LINE_TYPE get_line(); + PHRQ_io::LINE_TYPE get_line_phrq_io(); // bool check_key(const std::string::iterator ptr); bool check_key(std::string::iterator begin, std::string::iterator end); - STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, - bool check_compatibility, - const std::string & default_units, bool print); + //STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, + // bool check_compatibility, + // const std::string & default_units, bool print); //KEY_TYPE next_keyword() const @@ -183,15 +167,15 @@ class CParser: public PHRQ_base return m_line_iss; } int incr_input_error(); - std::ostream & get_output() - { - return m_output_stream; - } + //std::ostream & get_output() + //{ + // return m_output_stream; + //} int get_input_error() { return m_input_error; } - +#ifdef SKIP std::istream::pos_type tellg() { return m_input_stream.tellg(); @@ -200,6 +184,7 @@ class CParser: public PHRQ_base { return m_input_stream.seekg(p); } +#endif @@ -219,18 +204,18 @@ class CParser: public PHRQ_base TT_DIGIT TT_UNKNOWN */ - static TOKEN_TYPE copy_token(std::string & token, + static CParser::TOKEN_TYPE copy_token(std::string & token, std::string::iterator & begin, std::string::iterator & end); static CParser::TOKEN_TYPE copy_title(std::string & token, std::string::iterator & begin, std::string::iterator & end); - static TOKEN_TYPE token_type(const std::string & token); - static TOKEN_TYPE copy_token(std::string & token, std::istream & is); - TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); + static CParser::TOKEN_TYPE token_type(const std::string & token); + static CParser::TOKEN_TYPE copy_token(std::string & token, std::istream & is); + CParser::TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); bool get_true_false(std::istream::pos_type & pos, bool def); - TOKEN_TYPE get_rest_of_line(std::string &token); - static TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); + CParser::TOKEN_TYPE get_rest_of_line(std::string &token); + static CParser::TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); CParser::TOKEN_TYPE peek_token(); /** @@ -294,23 +279,24 @@ class CParser: public PHRQ_base std::istream::pos_type & pos); protected: - LINE_TYPE get_logical_line(); + PHRQ_io::LINE_TYPE get_logical_line(); protected: std::istream & m_input_stream; - std::ostream & m_output_stream; - std::ostream & m_error_stream; + //std::ostream & m_output_stream; + //std::ostream & m_error_stream; int m_input_error; //KEY_TYPE m_next_keyword; Keywords::KEYWORDS m_next_keyword; std::string m_line; std::string m_line_save; std::istringstream m_line_iss; - LINE_TYPE m_line_type; + PHRQ_io::LINE_TYPE m_line_type; ECHO_OPTION echo_stream; ECHO_OPTION echo_file; std::string accumulated; bool accumulate; + bool phrq_io_only; }; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index fa87e366..11c7c810 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -186,13 +186,25 @@ size_t Phreeqc::list_components(std::list &list_c) } // irreversible reactions - for (i = 0; i < count_irrev; i++) { - reaction_calc(&irrev[i]); - cxxReaction entity(&irrev[i]); - accumulator.add_extensive(entity.Get_elementList(), 1.0); + std::map::const_iterator cit = Rxn_reaction_map.begin(); + for (; cit != Rxn_reaction_map.end(); cit++) + { + cxxReaction r_ptr(cit->second); + reaction_calc(&r_ptr); + accumulator.add_extensive(r_ptr.Get_elementList(), 1.0); + } } - +#ifdef SKIP + { + for (i = 0; i < count_irrev; i++) + { + reaction_calc(&irrev[i]); + cxxReaction entity(&irrev[i]); + accumulator.add_extensive(entity.Get_elementList(), 1.0); + } + } +#endif // pure phases for (i = 0; i < count_pp_assemblage; i++) { @@ -202,19 +214,23 @@ size_t Phreeqc::list_components(std::list &list_c) } // exchangers - //for (i = 0; i < count_exchange; i++) - //{ - // cxxExchange entity(&exchange[i], phrq_io); - // entity.totalize(); - // accumulator.add_extensive(entity.Get_totals(), 1.0); - //} - std::map::const_iterator cit = Rxn_exchange_map.begin(); - for (; cit != Rxn_exchange_map.end(); cit++) +#ifdef SKIP + for (i = 0; i < count_exchange; i++) { - cxxExchange entity = cit->second; + cxxExchange entity(&exchange[i], phrq_io); entity.totalize(); accumulator.add_extensive(entity.Get_totals(), 1.0); } +#endif + { + std::map::const_iterator cit = Rxn_exchange_map.begin(); + for (; cit != Rxn_exchange_map.end(); cit++) + { + cxxExchange entity = cit->second; + entity.totalize(); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } + } // surfaces for (i = 0; i < count_surface; i++) @@ -225,13 +241,23 @@ size_t Phreeqc::list_components(std::list &list_c) } // gas phases + { + std::map::const_iterator cit = Rxn_gas_phase_map.begin(); + for (; cit != Rxn_gas_phase_map.end(); cit++) + { + cxxGasPhase entity = cit->second; + entity.totalize(this); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } + } +#ifdef SKIP for (i = 0; i < count_gas_phase; i++) { cxxGasPhase entity(&gas_phase[i], phrq_io); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } - +#endif // solid-solutions for (i = 0; i < count_s_s_assemblage; i++) { @@ -320,7 +346,7 @@ void Phreeqc::init(void) max_pp_assemblage = MAX_PP_ASSEMBLAGE; //max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; - max_gas_phase = MAX_PP_ASSEMBLAGE; + //max_gas_phase = MAX_PP_ASSEMBLAGE; max_kinetics = MAX_PP_ASSEMBLAGE; max_s_s_assemblage = MAX_PP_ASSEMBLAGE; @@ -340,12 +366,12 @@ void Phreeqc::init(void) count_pp_assemblage = 0; //count_exchange = 0; count_surface = 0; - count_gas_phase = 0; + //count_gas_phase = 0; count_kinetics = 0; count_s_s_assemblage = 0; count_elements = 0; - count_irrev = 0; + //count_irrev = 0; count_master = 0; //count_mix = 0; count_phases = 0; @@ -392,7 +418,7 @@ void Phreeqc::init(void) pp_assemblage = 0; //exchange = 0; surface = 0; - gas_phase = 0; + //gas_phase = 0; kinetics = 0; s_s_assemblage = 0; cell_data = 0; @@ -403,7 +429,7 @@ void Phreeqc::init(void) inverse = 0; count_inverse = 0; - irrev = 0; + //irrev = 0; line = 0; line_save = 0; @@ -470,7 +496,7 @@ void Phreeqc::init(void) use.solution_in = FALSE; use.pp_assemblage_in = FALSE; use.mix_in = FALSE; - use.irrev_in = FALSE; + use.reaction_in = FALSE; /* * Initialize punch */ @@ -661,7 +687,7 @@ void Phreeqc::init(void) copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_irrev.n_user = copy_irrev.start = copy_irrev.end = 0; + copy_reaction.n_user = copy_reaction.start = copy_reaction.end = 0; copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0; @@ -712,7 +738,7 @@ void Phreeqc::init(void) dbg_surface = surface; dbg_pp_assemblage = pp_assemblage; dbg_kinetics = kinetics; - dbg_irrev = irrev; + //dbg_irrev = irrev; //dbg_mix = mix; dbg_master = master; calculating_deriv = FALSE; diff --git a/Phreeqc.h b/Phreeqc.h index 3885e728..f5581cd1 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -131,7 +131,7 @@ public: //int system_total_solids(struct exchange *exchange_ptr, int system_total_solids(cxxExchange *exchange_ptr, struct pp_assemblage *pp_assemblage_ptr, - struct gas_phase *gas_phase_ptr, + cxxGasPhase *gas_phase_ptr, struct s_s_assemblage *s_s_assemblage_ptr, struct surface *surface_ptr); @@ -570,7 +570,8 @@ public: int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); - LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); + //LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); LDBLE calc_PR(); int setup_pure_phases(void); int adjust_setup_pure_phases(void); @@ -620,7 +621,7 @@ public: int print_alkalinity(void); int print_diffuse_layer(struct surface_charge *surface_charge_ptr); int print_eh(void); - int print_irrev(void); + int print_reaction(void); int print_kinetics(void); int print_mix(void); int print_pp_assemblage(void); @@ -653,11 +654,10 @@ public: int read_t_c_only(char *ptr, LDBLE *t_c); int read_p_c_only(char *ptr, LDBLE * p_c); int read_omega_only(char *ptr, LDBLE *omega); - //int read_delta_v_only(char *ptr, LDBLE * delta_v); int read_number_description(char *ptr, int *n_user, int *n_user_end, char **description, int allow_negative=FALSE); int check_key(const char *str); - int check_units(char *tot_units, int alkalinity, int check_compatibility, + int check_units(char * tot_units, int alkalinity, int check_compatibility, const char *default_units, int print); int find_option(const char *item, int *n, const char **list, int count_list, int exact); @@ -703,8 +703,10 @@ public: int read_pure_phases(void); int read_rates(void); int read_reaction(void); - int read_reaction_reactants(struct irrev *irrev_ptr); - int read_reaction_steps(struct irrev *irrev_ptr); + //int read_reaction_reactants(struct irrev *irrev_ptr); + int read_reaction_reactants(cxxReaction *reaction_ptr); + //int read_reaction_steps(struct irrev *irrev_ptr); + int read_reaction_steps(cxxReaction *reaction_ptr); int read_solid_solutions(void); int read_temperature(void); int read_reaction_temps(struct temperature *temperature_ptr); @@ -731,26 +733,26 @@ public: int cleanup_after_parser(CParser &parser); // ReadClass.cxx - + int read_generic(Keywords::KEYWORDS key); int read_solution_raw(void); - int read_exchange_raw(void); + //int read_exchange_raw(void); int read_surface_raw(void); int read_equilibrium_phases_raw(void); int read_kinetics_raw(void); int read_solid_solutions_raw(void); - int read_gas_phase_raw(void); - int read_reaction_raw(void); - int read_mix_raw(void); - int read_temperature_raw(void); + //int read_gas_phase_raw(void); + //int read_reaction_raw(void); + //int read_mix_raw(void); + //int read_temperature_raw(void); int read_dump(void); int read_solution_modify(void); int read_equilibrium_phases_modify(void); - int read_exchange_modify(void); + //int read_exchange_modify(void); int read_surface_modify(void); int read_solid_solutions_modify(void); - int read_gas_phase_modify(void); + //int read_gas_phase_modify(void); int read_kinetics_modify(void); - int read_reaction_modify(void); + //int read_reaction_modify(void); //int read_reaction_temperature_modify(void); int read_delete(void); int read_run_cells(void); @@ -818,21 +820,24 @@ public: int xsolution_zero(void); //int add_exchange(struct exchange *exchange_ptr); int add_exchange(cxxExchange *exchange_ptr); - int add_gas_phase(struct gas_phase *gas_phase_ptr); + int add_gas_phase(cxxGasPhase *gas_phase_ptr); int add_kinetics(struct kinetics *kinetics_ptr); //int add_mix(struct mix *mix_ptr); int add_mix(cxxMix * mix_ptr); int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); - int add_reaction(struct irrev *irrev_ptr, int step_number, + //int add_reaction(struct irrev *irrev_ptr, int step_number, + // LDBLE step_fraction); + int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); - int gas_phase_check(struct gas_phase *gas_phase_ptr); + int gas_phase_check(cxxGasPhase *gas_phase_ptr); int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); - int reaction_calc(struct irrev *irrev_ptr); + //int reaction_calc(struct irrev *irrev_ptr); + int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); @@ -878,8 +883,9 @@ protected: struct exchange *exchange_search(int n_user, int *n, int print); int exchange_sort(void); #endif - static int gas_comp_compare(const void *ptr1, const void *ptr2); + //static int gas_comp_compare(const void *ptr1, const void *ptr2); public: +#ifdef SKIP struct gas_phase *gas_phase_alloc(void); struct gas_phase *gas_phase_bsearch(int k, int *n); protected: @@ -901,12 +907,14 @@ public: int n_user_new); struct gas_phase *gas_phase_search(int n_user, int *n); int gas_phase_sort(void); +#endif enum entity_type get_entity_enum(char *name); struct inverse *inverse_alloc(void); int inverse_delete(int i); static int inverse_isotope_compare(const void *ptr1, const void *ptr2); struct inverse *inverse_search(int n_user, int *n); int inverse_sort(void); +#ifdef SKIP struct irrev *irrev_bsearch(int k, int *n); int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, int n_user_new); @@ -916,6 +924,7 @@ public: struct irrev *irrev_search(int n_user, int *n); int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); int irrev_sort(void); +#endif public: struct kinetics *kinetics_alloc(void); struct kinetics *kinetics_bsearch(int k, int *n); @@ -1105,18 +1114,18 @@ public: int unknown_free(struct unknown *unknown_ptr); int entity_exists(char *name, int n_user); - static int exchange_compare_int(const void *ptr1, const void *ptr2); - static int gas_phase_compare_int(const void *ptr1, const void *ptr2); + //static int exchange_compare_int(const void *ptr1, const void *ptr2); + //static int gas_phase_compare_int(const void *ptr1, const void *ptr2); static int inverse_compare(const void *ptr1, const void *ptr2); int inverse_free(struct inverse *inverse_ptr); - static int irrev_compare(const void *ptr1, const void *ptr2); - static int irrev_compare_int(const void *ptr1, const void *ptr2); + //static int irrev_compare(const void *ptr1, const void *ptr2); + //static int irrev_compare_int(const void *ptr1, const void *ptr2); static int kinetics_compare_int(const void *ptr1, const void *ptr2); int logk_init(struct logk *logk_ptr); static int master_compare_string(const void *ptr1, const void *ptr2); int master_free(struct master *master_ptr); - static int mix_compare(const void *ptr1, const void *ptr2); - static int mix_compare_int(const void *ptr1, const void *ptr2); + //static int mix_compare(const void *ptr1, const void *ptr2); + //static int mix_compare_int(const void *ptr1, const void *ptr2); struct phase *phase_alloc(void); static int phase_compare_string(const void *ptr1, const void *ptr2); int phase_free(struct phase *phase_ptr); @@ -1132,8 +1141,8 @@ public: static int solution_compare_int(const void *ptr1, const void *ptr2); static int species_list_compare(const void *ptr1, const void *ptr2); static int surface_compare_int(const void *ptr1, const void *ptr2); - static int temperature_compare(const void *ptr1, const void *ptr2); - static int temperature_compare_int(const void *ptr1, const void *ptr2); + //static int temperature_compare(const void *ptr1, const void *ptr2); + //static int temperature_compare_int(const void *ptr1, const void *ptr2); static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); #ifdef PHREEQCI_GUI @@ -1144,18 +1153,18 @@ public: #endif // convert class to struct (structures.cpp) - struct mix * cxxMix2mix(const cxxMix *mx); + //struct mix * cxxMix2mix(const cxxMix *mx); struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); //struct exchange * cxxExchange2exchange(const cxxExchange * ex); //struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); - struct master * Get_exch_master(const cxxExchComp * ec); - struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); - struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); - struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); + //struct master * Get_exch_master(const cxxExchComp * ec); + //struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); + //struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); + //struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); - struct irrev * cxxReaction2irrev(const cxxReaction * rxn); + //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); @@ -1331,10 +1340,10 @@ protected: Address Hash_multi(HashTable * Table, const char *Key); void ExpandTable_multi(HashTable * Table); public: - //bool recursive_include(std::ifstream & input_stream, std::iostream & accumulated_stream); int main_method(int argc, char *argv[]); void set_phast(int); size_t list_components(std::list &list_c); + PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} protected: void init(void); @@ -1426,7 +1435,7 @@ protected: struct copier copy_gas_phase; struct copier copy_kinetics; struct copier copy_mix; - struct copier copy_irrev; + struct copier copy_reaction; struct copier copy_temperature; struct copier copy_pressure; @@ -1450,17 +1459,21 @@ protected: /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ - + std::map Rxn_reaction_map; +#ifdef SKIP struct irrev *irrev; struct irrev *dbg_irrev; int count_irrev; +#endif /*---------------------------------------------------------------------- * Gas phase *---------------------------------------------------------------------- */ - + std::map Rxn_gas_phase_map; +#ifdef SKIP int count_gas_phase; int max_gas_phase; struct gas_phase *gas_phase; +#endif /*---------------------------------------------------------------------- * Solid solution *---------------------------------------------------------------------- */ @@ -2102,7 +2115,8 @@ public: std::vector keycount; // used to mark keywords that have been read #endif /* _INC_PHREEQC_H */ - +#ifndef _INC_ISFINITE_H +#define _INC_ISFINITE_H /********************************* isfinite handling (Note: Should NOT be guarded) @@ -2128,3 +2142,4 @@ public: #endif }; +#endif diff --git a/Pressure.cxx b/Pressure.cxx index 71998ca9..cd34b9ef 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -48,7 +48,7 @@ cxxPressure::read(CParser & parser) */ // Number and description set in read_reaction_pressure - CParser::LINE_TYPE lt; + PHRQ_io::LINE_TYPE lt; bool done = false; for (;;) { @@ -60,21 +60,21 @@ cxxPressure::read(CParser & parser) std::string token, str; lt = parser.check_line(str, false, true, true, true); - if (lt == CParser::LT_EMPTY || - lt == CParser::LT_KEYWORD || - lt == CParser::LT_EOF) + if (lt == PHRQ_io::LT_EMPTY || + lt == PHRQ_io::LT_KEYWORD || + lt == PHRQ_io::LT_EOF) { break; } - if (lt == CParser::LT_OPTION) + if (lt == PHRQ_io::LT_OPTION) { - this->error_msg("Expected numeric value for pressures.", CParser::OT_CONTINUE); + this->error_msg("Expected numeric value for pressures.", PHRQ_io::OT_CONTINUE); break; } if (done) { - this->error_msg("Unknown input following equal increment definition.", CParser::OT_CONTINUE); + this->error_msg("Unknown input following equal increment definition.", PHRQ_io::OT_CONTINUE); continue; } @@ -101,7 +101,7 @@ cxxPressure::read(CParser & parser) if (!(iss >> d)) { this->error_msg("Expected numeric value for pressures.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -165,18 +165,18 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "REACTION_PRESSURE_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "REACTION_PRESSURE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-count " << this->count << std::endl; + s_oss << "-count " << this->count << "\n"; s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; // Temperature element and attributes s_oss << indent1; - s_oss << "-pressures " << std::endl; + s_oss << "-pressures " << "\n"; { int i = 0; s_oss << indent2; @@ -185,13 +185,13 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con { if (i++ == 5) { - s_oss << std::endl; + s_oss << "\n"; s_oss << indent2; i = 0; } s_oss << *it << " "; } - s_oss << std::endl; + s_oss << "\n"; } } @@ -218,6 +218,7 @@ cxxPressure::read_raw(CParser & parser) bool useLastLine(false); // Number and description set in read_reaction_pressure_raw + this->read_number_description(parser); opt_save = CParser::OPT_ERROR; bool equalIncrements_defined(false); @@ -248,8 +249,8 @@ cxxPressure::read_raw(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in REACTION_PRESSURE_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -266,7 +267,7 @@ cxxPressure::read_raw(CParser & parser) { parser.incr_input_error(); parser.error_msg("Expected numeric value for pressures.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -282,7 +283,7 @@ cxxPressure::read_raw(CParser & parser) { this->equalIncrements = 0; parser.incr_input_error(); - parser.error_msg("Expected boolean value for equalIncrements.", CParser::OT_CONTINUE); + parser.error_msg("Expected boolean value for equalIncrements.", PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -294,7 +295,7 @@ cxxPressure::read_raw(CParser & parser) { this->count = 0; parser.incr_input_error(); - parser.error_msg("Expected integer value for count.", CParser::OT_CONTINUE); + parser.error_msg("Expected integer value for count.", PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -309,13 +310,13 @@ cxxPressure::read_raw(CParser & parser) { parser.incr_input_error(); parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (count_defined == false) { parser.incr_input_error(); parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } #ifdef SKIP @@ -335,15 +336,15 @@ cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Temperature element and attributes s_oss << indent0; - s_oss << " - pitzer_temperature_gammas << "\"" << std::endl; + pitzer_temperature_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = temperatureComps.begin(); it != temperatureComps.end(); ++it) { diff --git a/Pressure.h b/Pressure.h index 4053fe1a..22d42323 100644 --- a/Pressure.h +++ b/Pressure.h @@ -23,11 +23,11 @@ class cxxPressure:public cxxNumKeyword int read(CParser & parser); void read_raw(CParser & parser); LDBLE Pressure_for_step(int step_number); - std::vector & Get_pressures(void) {return pressures;}; + std::vector & Get_pressures(void) {return pressures;} int Get_count(void) const; - void Set_count(int i) {count = i;}; - bool Get_equalIncrements(void) const {return equalIncrements;}; - void Set_equalIncrements(bool tf) {equalIncrements = tf;}; + void Set_count(int i) {count = i;} + bool Get_equalIncrements(void) const {return equalIncrements;} + void Set_equalIncrements(bool tf) {equalIncrements = tf;} protected: std::vector < double >pressures; diff --git a/Reaction.cxx b/Reaction.cxx index e57f71ed..0bf19517 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -29,6 +29,7 @@ cxxReaction::cxxReaction(PHRQ_io *io) reactantList.type = cxxNameDouble::ND_NAME_COEF; elementList.type = cxxNameDouble::ND_ELT_MOLES; } +#ifdef SKIP cxxReaction::cxxReaction(struct irrev *irrev_ptr, PHRQ_io *io) // // constructor for cxxReaction from struct irrev @@ -64,7 +65,7 @@ elementList(irrev_ptr->elts) this->equalIncrements = false; } } - +#endif cxxReaction::~cxxReaction() { } @@ -86,15 +87,15 @@ cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Reaction element and attributes s_oss << indent0; - s_oss << " - pitzer_irrev_gammas << "\"" << std::endl; + pitzer_irrev_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = irrevComps.begin(); it != irrevComps.end(); ++it) { @@ -122,21 +123,21 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Reaction element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "REACTION_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "REACTION_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-units " << this->units << std::endl; + s_oss << "-units " << this->units << "\n"; s_oss << indent1; - s_oss << "-reactant_list " << std::endl; + s_oss << "-reactant_list " << "\n"; this->reactantList.dump_raw(s_oss, indent + 2); s_oss << indent1; - s_oss << "-element_list " << std::endl; + s_oss << "-element_list " << "\n"; this->elementList.dump_raw(s_oss, indent + 2); s_oss << indent1; - s_oss << "-steps " << std::endl; + s_oss << "-steps " << "\n"; { int i = 0; s_oss << indent2; @@ -145,20 +146,20 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con { if (i++ == 5) { - s_oss << std::endl; + s_oss << "\n"; s_oss << indent2; i = 0; } s_oss << *it << " "; } - s_oss << std::endl; + s_oss << "\n"; } s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; s_oss << indent1; - s_oss << "-count_steps " << this->countSteps << std::endl; + s_oss << "-count_steps " << this->countSteps << "\n"; } @@ -224,8 +225,8 @@ cxxReaction::read_raw(CParser & parser, const bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in IRREV_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -245,7 +246,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) { parser.incr_input_error(); parser.error_msg("Expected reactant formula and coefficient.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 1; useLastLine = false; @@ -257,7 +258,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) { parser.incr_input_error(); parser.error_msg("Expected element formula and coefficient.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 2; useLastLine = false; @@ -277,7 +278,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) { parser.incr_input_error(); parser.error_msg("Expected numeric value for steps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -295,7 +296,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) parser.incr_input_error(); parser. error_msg("Expected boolean value for equalIncrements.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -308,7 +309,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) this->countSteps = 0; parser.incr_input_error(); parser.error_msg("Expected integer value for countSteps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -325,20 +326,29 @@ cxxReaction::read_raw(CParser & parser, const bool check) { parser.incr_input_error(); parser.error_msg("Units not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (equalIncrements_defined == false) { parser.incr_input_error(); parser. error_msg("Equal_increments not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (countSteps_defined == false) { parser.incr_input_error(); parser.error_msg("Count_steps not defined for REACTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } +int cxxReaction:: +Get_actualSteps(void) const +{ + if (equalIncrements) + { + return this->countSteps; + } + return (int) this->steps.size(); +} \ No newline at end of file diff --git a/Reaction.h b/Reaction.h index 75a783e7..2060ae06 100644 --- a/Reaction.h +++ b/Reaction.h @@ -15,20 +15,25 @@ class cxxReaction:public cxxNumKeyword public: cxxReaction(PHRQ_io *io = NULL); - cxxReaction(struct irrev *, PHRQ_io *io = NULL); + //cxxReaction(struct irrev *, PHRQ_io *io = NULL); ~cxxReaction(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; - void read_raw(CParser & parser, bool check); - const cxxNameDouble &Get_elementList(void) const {return this->elementList;}; - const cxxNameDouble &Get_reactantList(void) const {return this->reactantList;}; - const std::vector < double > &Get_steps(void) const {return this->steps;}; - int Get_countSteps(void) const {return this->countSteps;}; - bool Get_equalIncrements(void) const {return this->equalIncrements;}; - const std::string &Get_units(void) const {return this->units;}; + void read_raw(CParser & parser, bool check=true); + const cxxNameDouble &Get_elementList(void) const {return this->elementList;} + void Set_elementList(cxxNameDouble nd) {this->elementList = nd;} + cxxNameDouble &Get_reactantList(void) {return this->reactantList;} + std::vector < double > &Get_steps(void) {return this->steps;} + void Set_steps(std::vector &v) {steps = v;} + int Get_actualSteps(void) const; + int Get_countSteps(void) const {return this->countSteps;} + void Set_countSteps(int i) {countSteps = i;} + bool Get_equalIncrements(void) const {return this->equalIncrements;} + void Set_equalIncrements(bool tf) {equalIncrements = tf;} + const std::string &Get_units(void) const {return this->units;} void Set_units(const char * s) { diff --git a/ReadClass.cxx b/ReadClass.cxx index 3fc21c2a..8c2b59ff 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -69,10 +69,7 @@ read_solution_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -119,7 +116,7 @@ read_solution_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_exchange_raw(void) @@ -163,10 +160,7 @@ read_exchange_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -194,6 +188,7 @@ read_exchange_raw(void) Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); } } + #ifdef SKIP //struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); struct exchange *exchange_ptr = cxxExchange2exchange(&ex); @@ -227,7 +222,7 @@ read_exchange_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_raw(void) @@ -271,10 +266,7 @@ read_surface_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -367,10 +359,7 @@ read_equilibrium_phases_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -464,10 +453,7 @@ read_kinetics_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -560,10 +546,7 @@ read_solid_solutions_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -614,7 +597,76 @@ read_solid_solutions_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_gas_phase_raw(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads GAS_PHASE_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + /* + * Accumulate lines in std string + */ + std::string keywordLines(""); + keywordLines.append(line); + keywordLines.append("\n"); +/* + * Read additonal lines + */ + int save_echo_input = pr.echo_input; + pr.echo_input = FALSE; + for (;;) + { + return_value = check_line("gas_phase_raw", TRUE, TRUE, TRUE, FALSE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; + keywordLines.append(line); + keywordLines.append("\n"); + } + pr.echo_input = save_echo_input; + + std::istringstream iss_in(keywordLines); + CParser parser(iss_in, phrq_io); + assert(!reading_database()); + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + //For testing, need to read line to get started + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + cxxGasPhase entity(phrq_io); + entity.read_raw(parser); + + Rxn_gas_phase_map[entity.Get_n_user()] = entity; + + // Need to output the next keyword + if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); + return (return_value); +} +#endif +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_gas_phase_raw(void) @@ -709,7 +761,8 @@ read_gas_phase_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#endif +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_reaction_raw(void) @@ -753,10 +806,8 @@ read_reaction_raw(void) pr.echo_input = save_echo_input; std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); if (pr.echo_input == FALSE) { @@ -805,6 +856,7 @@ read_reaction_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif #ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -926,9 +978,7 @@ read_dump(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -976,9 +1026,7 @@ read_delete(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1028,9 +1076,7 @@ read_run_cells(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1100,9 +1146,7 @@ read_solution_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1199,9 +1243,7 @@ read_equilibrium_phases_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1248,6 +1290,7 @@ read_equilibrium_phases_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_exchange_modify(void) @@ -1293,9 +1336,7 @@ read_exchange_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1392,6 +1433,7 @@ read_exchange_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_modify(void) @@ -1436,9 +1478,7 @@ read_surface_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1526,9 +1566,7 @@ read_solid_solutions_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1572,6 +1610,86 @@ read_solid_solutions_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_gas_phase_modify(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads GAS_PHASE_MODIFY data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + // find gas_phase number + char token[MAX_LENGTH]; + char *next; + int l, n_user; + next = line; + copy_token(token, &next, &l); + if (copy_token(token, &next, &l) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + return (ERROR); + } + else + { + sscanf(token,"%d", &n_user); + } + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + CParser parser(iss_in, phrq_io); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + + cxxGasPhase *gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, n_user); + if (gas_phase_ptr == NULL) + { + input_error++; + error_string = sformatf( "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + // read entity + gas_phase_ptr->read_raw(parser, false); + + // Need to output the next keyword + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); + return (return_value); +} +#endif +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_gas_phase_modify(void) @@ -1660,6 +1778,7 @@ read_gas_phase_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_modify(void) @@ -1704,9 +1823,7 @@ read_kinetics_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; // ?? - std::ostringstream oss_err; // ?? - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1750,6 +1867,7 @@ read_kinetics_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_reaction_modify(void) @@ -1793,9 +1911,7 @@ read_reaction_modify(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); assert(!reading_database()); //For testing, need to read line to get started @@ -1838,6 +1954,7 @@ read_reaction_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: streamify_to_next_keyword(std::istringstream & lines) @@ -2075,6 +2192,22 @@ delete_entities(void) } // gas_phases + if (delete_info.Get_gas_phase().Get_defined()) + { + if (delete_info.Get_gas_phase().Get_numbers().size() == 0) + { + Rxn_gas_phase_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_gas_phase().Get_numbers().begin(); it != delete_info.Get_gas_phase().Get_numbers().end(); it++) + { + Rxn_gas_phase_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_gas_phase().Get_defined()) { if (delete_info.Get_gas_phase().Get_numbers().size() == 0) @@ -2096,7 +2229,7 @@ delete_entities(void) } } } - +#endif // kineticss if (delete_info.Get_kinetics().Get_defined()) { @@ -2159,6 +2292,22 @@ delete_entities(void) } #endif // reactions + if (delete_info.Get_reaction().Get_defined()) + { + if (delete_info.Get_reaction().Get_numbers().size() == 0) + { + Rxn_reaction_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_reaction().Get_numbers().begin(); it != delete_info.Get_reaction().Get_numbers().end(); it++) + { + Rxn_reaction_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_reaction().Get_defined()) { if (delete_info.Get_reaction().Get_numbers().size() == 0) @@ -2180,6 +2329,7 @@ delete_entities(void) } } } +#endif // temperatures if (delete_info.Get_temperature().Get_defined()) { @@ -2261,10 +2411,11 @@ run_as_cells(void) */ dup_print("Beginning of batch-reaction calculations.", TRUE); count_steps = 1; - if (use.irrev_in == TRUE && use.irrev_ptr != NULL) + if (use.reaction_in == TRUE && use.reaction_ptr != NULL) { - if (abs(use.irrev_ptr->count_steps) > count_steps) - count_steps = abs(use.irrev_ptr->count_steps); + int count = ((cxxReaction *) use.reaction_ptr)->Get_actualSteps(); + if (count > count_steps) + count_steps = count; } if (use.kinetics_in == TRUE && use.kinetics_ptr != NULL) { @@ -2593,6 +2744,27 @@ dump_ostream(std::ostream& os) } // gas_phases + if (dump_info.Get_bool_gas_phase()) + { + if (dump_info.Get_gas_phase().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_gas_phase_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_gas_phase().begin(); it != dump_info.Get_gas_phase().end(); it++) + { + cxxGasPhase *p = Utilities::Rxn_find(Rxn_gas_phase_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_gas_phase()) { if (dump_info.Get_gas_phase().size() == 0) @@ -2617,7 +2789,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // kinetics if (dump_info.Get_bool_kinetics()) { @@ -2692,6 +2864,27 @@ dump_ostream(std::ostream& os) } #endif // reaction + if (dump_info.Get_bool_reaction()) + { + if (dump_info.Get_reaction().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_reaction_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_reaction().begin(); it != dump_info.Get_reaction().end(); it++) + { + cxxReaction *p = Utilities::Rxn_find(Rxn_reaction_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_reaction()) { if (dump_info.Get_reaction().size() == 0) @@ -2716,7 +2909,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // temperature if (dump_info.Get_bool_temperature()) { @@ -2760,10 +2953,10 @@ dump_ostream(std::ostream& os) } } // Turn off any reaction calculation - os << "USE mix none" << std::endl; - os << "USE reaction none" << std::endl; - os << "USE reaction_temperature none" << std::endl; - os << "USE reaction_pressure none" << std::endl; + os << "USE mix none" << "\n"; + os << "USE reaction none" << "\n"; + os << "USE reaction_temperature none" << "\n"; + os << "USE reaction_pressure none" << "\n"; // Turn off dump until next read dump_info.SetAll(false); @@ -2794,9 +2987,10 @@ read_user_graph_handler(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); + //std::ostringstream oss_out; + //std::ostringstream oss_err; + //CParser parser(iss_in, oss_out, oss_err, phrq_io); + CParser parser(iss_in, phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; @@ -2820,4 +3014,86 @@ read_user_graph_handler(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_generic(Keywords::KEYWORDS key) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads _raw and _modify data blocks + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value; + + std::string token; + char *next; + int n_user; + next = line; + copy_token(token, &next); + if (copy_token(token, &next) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected reactant number following keyword.\n%s\n", line_save); + error_msg(error_string, CONTINUE); + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + return (ERROR); + } + else + { + sscanf(token.c_str(),"%d", &n_user); + } + /* + * Make parser + */ + std::istringstream iss_in; + return_value = streamify_to_next_keyword(iss_in); + CParser parser(iss_in, phrq_io); + assert(!reading_database()); + + //For testing, need to read line to get started + parser.set_echo_file(CParser::EO_NONE); + std::vector < std::string > vopts; + std::istream::pos_type next_char; + parser.get_option(vopts, next_char); + + if (pr.echo_input == FALSE) + { + parser.set_echo_file(CParser::EO_NONE); + } + else + { + parser.set_echo_file(CParser::EO_NOKEYWORDS); + } + switch (key) + { + case Keywords::KEY_REACTION_PRESSURE_RAW: + { + cxxPressure entity(this->phrq_io); + entity.read_raw(parser); + if (entity.Get_base_error_count() == 0) + { + Rxn_pressure_map[n_user] = entity; + } + // Make copies if necessary + Utilities::Rxn_copies(Rxn_pressure_map, entity.Get_n_user(), entity.Get_n_user_end()); + } + break; + } + + // Need to output the next keyword + if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); + return (return_value); +} #endif \ No newline at end of file diff --git a/SSassemblage.cxx b/SSassemblage.cxx index aeb7480d..f0352b2e 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -90,14 +90,14 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const // SSassemblage element and attributes s_oss << indent0; - s_oss << "eltList.dump_xml(s_oss, indent + 1); // ssAssemblageSSs s_oss << indent1; - s_oss << "::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { @@ -122,14 +122,14 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) // SSassemblage element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << "\n"; // ssAssemblageSSs for (std::map < std::string, cxxSSassemblageSS >::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { s_oss << indent1; - s_oss << "-solid_solution" << std::endl; + s_oss << "-solid_solution" << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } } @@ -181,8 +181,8 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) opt = CParser::OPT_EOF; parser. error_msg("Unknown input in SOLID_SOLUTIONS_RAW or SOLID_SOLUTIONS_MODIFY keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; diff --git a/SSassemblageSS.cxx b/SSassemblageSS.cxx index 7545b704..f044bb9a 100644 --- a/SSassemblageSS.cxx +++ b/SSassemblageSS.cxx @@ -8,7 +8,6 @@ #include // std::sort #include "Utils.h" // define first -#include "Phreeqc.h" #include "SSassemblageSS.h" //#include "Dictionary.h" #include "phqalloc.h" @@ -91,16 +90,16 @@ cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const con // S_S element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; s_oss << indent0 << "add_formula=\"" << this-> - add_formula << "\"" << std::endl; - s_oss << indent0 << "si=\"" << this->si << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "delta=\"" << this->delta << "\"" << std::endl; + add_formula << "\"" << "\n"; + s_oss << indent0 << "si=\"" << this->si << "\"" << "\n"; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; + s_oss << indent0 << "delta=\"" << this->delta << "\"" << "\n"; s_oss << indent0 << "initial_moles=\"" << this-> - initial_moles << "\"" << std::endl; + initial_moles << "\"" << "\n"; s_oss << indent0 << "dissolve_only=\"" << this-> - dissolve_only << "\"" << std::endl; + dissolve_only << "\"" << "\n"; } #endif @@ -117,18 +116,18 @@ cxxSSassemblageSS::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 << std::endl; - //s_oss << indent0 << "-total_moles " << this->total_moles << std::endl; - s_oss << indent1 << "-a0 " << this->a0 << std::endl; - s_oss << indent1 << "-a1 " << this->a1 << std::endl; - s_oss << indent1 << "-ag0 " << this->ag0 << std::endl; - s_oss << indent1 << "-ag1 " << this->ag1 << std::endl; - s_oss << indent1 << "-miscibility " << this->miscibility << std::endl; - //s_oss << indent0 << "-spinodal " << this->spinodal << std::endl; - //s_oss << indent0 << "-tk " << this->tk << std::endl; - s_oss << indent1 << "-xb1 " << this->xb1 << std::endl; - s_oss << indent1 << "-xb2 " << this->xb2 << std::endl; - s_oss << indent1 << "-components " << std::endl; + 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); } @@ -191,8 +190,8 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in S_S read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in S_S read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name @@ -201,7 +200,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -217,7 +216,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) { this->total_moles = 0; parser.incr_input_error(); - parser.error_msg("Expected numeric value for total_moles.", CParser::OT_CONTINUE); + parser.error_msg("Expected numeric value for total_moles.", PHRQ_io::OT_CONTINUE); } total_moles_defined = true; */ @@ -230,7 +229,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->a0 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for a0.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } a0_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -242,7 +241,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->a1 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for a1.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } a1_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -253,7 +252,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Expected phase name and moles for comps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 4; break; @@ -264,7 +263,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->miscibility = 0; parser.incr_input_error(); parser.error_msg("Expected boolean value for miscibility.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } miscibility_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -276,7 +275,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) { this->spinodal = 0; parser.incr_input_error(); - parser.error_msg("Expected boolean value for spinodal.", CParser::OT_CONTINUE); + parser.error_msg("Expected boolean value for spinodal.", PHRQ_io::OT_CONTINUE); } spinodal_defined = true; */ @@ -289,7 +288,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) { this->tk = 0; parser.incr_input_error(); - parser.error_msg("Expected numeric value for tk.", CParser::OT_CONTINUE); + parser.error_msg("Expected numeric value for tk.", PHRQ_io::OT_CONTINUE); } tk_defined = true; */ @@ -302,7 +301,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->xb1 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for xb1.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } xb1_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -314,7 +313,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->xb2 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for xb2.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } xb2_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -326,7 +325,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->ag0 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for ag0.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } ag0_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -338,7 +337,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) this->ag1 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for ag1.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } ag1_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -356,65 +355,65 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Name not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } /* if (total_moles_defined == false) { parser.incr_input_error(); - parser.error_msg("Total_moles not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + parser.error_msg("Total_moles not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); } */ if (a0_defined == false) { parser.incr_input_error(); parser.error_msg("A0 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (a1_defined == false) { parser.incr_input_error(); parser.error_msg("A1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (ag0_defined == false) { parser.incr_input_error(); parser.error_msg("Ag0 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (ag1_defined == false) { parser.incr_input_error(); parser.error_msg("Ag1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (miscibility_defined == false) { parser.incr_input_error(); parser.error_msg("Miscibility not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } /* if (spinodal_defined == false) { parser.incr_input_error(); - parser.error_msg("Spinodal not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + parser.error_msg("Spinodal not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); } if (tk_defined == false) { parser.incr_input_error(); - parser.error_msg("Tk not defined for SSassemblageSS input.", CParser::OT_CONTINUE); + parser.error_msg("Tk not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); } */ if (xb1_defined == false) { parser.incr_input_error(); parser.error_msg("Xb1 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (xb2_defined == false) { parser.incr_input_error(); parser.error_msg("Xb2 not defined for SSassemblageSS input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/Solution.cxx b/Solution.cxx index 4b5c1575..cbdee3ea 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -144,50 +144,50 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const // Solution element and attributes s_oss << indent0; - s_oss << "new_def << "\"" << std::endl; + //s_oss << "soln_new_def=\"" << this->new_def << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_n_user=\"" << this->n_user << "\" " << std::endl; + s_oss << "soln_n_user=\"" << this->n_user << "\" " << "\n"; s_oss << indent1; - s_oss << "soln_description=\"" << this->description << "\"" << std::endl; + s_oss << "soln_description=\"" << this->description << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_tc=\"" << this->tc << "\"" << std::endl; + s_oss << "soln_tc=\"" << this->tc << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_ph=\"" << this->ph << "\"" << std::endl; + s_oss << "soln_ph=\"" << this->ph << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_solution_pe=\"" << this->pe << "\"" << std::endl; + s_oss << "soln_solution_pe=\"" << this->pe << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_mu=\"" << this->mu << "\"" << std::endl; + s_oss << "soln_mu=\"" << this->mu << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_ah2o=\"" << this->ah2o << "\"" << std::endl; + s_oss << "soln_ah2o=\"" << this->ah2o << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_total_h=\"" << this->total_h << "\"" << std::endl; + s_oss << "soln_total_h=\"" << this->total_h << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_total_o=\"" << this->total_o << "\"" << std::endl; + s_oss << "soln_total_o=\"" << this->total_o << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_cb=\"" << this->cb << "\"" << std::endl; + s_oss << "soln_cb=\"" << this->cb << "\"" << "\n"; s_oss << indent1; - s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << std::endl; + s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << "\n"; s_oss << indent1; s_oss << "soln_total_alkalinity=\"" << this-> - total_alkalinity << "\"" << std::endl; + total_alkalinity << "\"" << "\n"; s_oss << indent1; - s_oss << "\">" << std::endl; + s_oss << "\">" << "\n"; // soln_total conc structures this->totals.dump_xml(s_oss, indent + 1); @@ -201,7 +201,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << "first << "\"" ; s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; + s_oss << "\">" << "\n"; } } */ @@ -214,7 +214,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << "first << "\"" ; s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << std::endl; + s_oss << "\">" << "\n"; } } */ @@ -227,7 +227,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const // End of solution s_oss << indent0; - s_oss << "" << std::endl; + s_oss << "" << "\n"; return; } @@ -249,35 +249,35 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Solution element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SOLUTION_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "SOLUTION_RAW " << n_user_local << " " << this->description << "\n"; - //s_oss << "# Critical values" << std::endl; + //s_oss << "# Critical values" << "\n"; s_oss << indent1; - s_oss << "-temp " << this->tc << std::endl; + s_oss << "-temp " << this->tc << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_h " << this->total_h << std::endl; + s_oss << "-total_h " << this->total_h << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_o " << this->total_o << std::endl; + s_oss << "-total_o " << this->total_o << "\n"; // new identifier s_oss << indent1; - s_oss << "-cb " << this->cb << std::endl; + s_oss << "-cb " << this->cb << "\n"; // soln_total conc structures s_oss << indent1; - s_oss << "-totals" << std::endl; + s_oss << "-totals" << "\n"; this->totals.dump_raw(s_oss, indent + 2); - //s_oss << "# Optional critical values" << std::endl; + //s_oss << "# Optional critical values" << "\n"; // Isotopes s_oss << indent1; - s_oss << "-Isotopes" << std::endl; + s_oss << "-Isotopes" << "\n"; { for (std::list < cxxSolutionIsotope >::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) @@ -287,49 +287,49 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con } s_oss << indent1; - s_oss << "-pH " << this->ph << std::endl; + s_oss << "-pH " << this->ph << "\n"; s_oss << indent1; - s_oss << "-pe " << this->pe << std::endl; + s_oss << "-pe " << this->pe << "\n"; // new identifier s_oss << indent1; - s_oss << "-mu " << this->mu << std::endl; + s_oss << "-mu " << this->mu << "\n"; // new identifier s_oss << indent1; - s_oss << "-ah2o " << this->ah2o << std::endl; + s_oss << "-ah2o " << this->ah2o << "\n"; // new identifier s_oss << indent1; - s_oss << "-mass_water " << this->mass_water << std::endl; + s_oss << "-mass_water " << this->mass_water << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_alkalinity " << this->total_alkalinity << std::endl; + s_oss << "-total_alkalinity " << this->total_alkalinity << "\n"; // master_activity map s_oss << indent1; - s_oss << "-activities" << std::endl; + s_oss << "-activities" << "\n"; this->master_activity.dump_raw(s_oss, indent + 2); /* { for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; + s_oss << it->first << " " << it->second << "\n"; } } */ // species_gamma map s_oss << indent1; - s_oss << "-gammas" << std::endl; + s_oss << "-gammas" << "\n"; this->species_gamma.dump_raw(s_oss, indent + 2); /* { { for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { s_oss << indent2; - s_oss << it->first << " " << it->second << std::endl; + s_oss << it->first << " " << it->second << "\n"; } } } @@ -406,8 +406,8 @@ cxxSolution::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in SOLUTION_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); continue; case 0: // totals @@ -417,7 +417,7 @@ cxxSolution::read_raw(CParser & parser, bool check) // parser.incr_input_error(); // parser. // error_msg("Expected element name and moles for totals.", - // CParser::OT_CONTINUE); + // PHRQ_io::OT_CONTINUE); //} { cxxNameDouble temp_totals; @@ -426,7 +426,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected element name and moles for totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -444,7 +444,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser. error_msg ("Expected species name and log activity for activities.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 1; break; @@ -457,7 +457,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser. error_msg ("Expected species name and activity coefficient for gammas.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 2; break; @@ -469,7 +469,7 @@ cxxSolution::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Expected data for isotopes.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -490,7 +490,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->tc = 25.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for temperature.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } tc_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -502,7 +502,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->ph = 7.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for pH.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } ph_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -514,7 +514,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->pe = 4.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for pe.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } pe_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -527,7 +527,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->mu = 1e-7; parser.incr_input_error(); parser.error_msg("Expected numeric value for ionic strength.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } mu_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -541,7 +541,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected numeric value for activity of water.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } ah2o_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -553,7 +553,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->total_h = 111.1; parser.incr_input_error(); parser.error_msg("Expected numeric value for total hydrogen.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } total_h_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -565,7 +565,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->total_o = 55.55; parser.incr_input_error(); parser.error_msg("Expected numeric value for total oxygen.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } total_o_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -578,7 +578,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->mass_water = 1.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for mass of water.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } mass_water_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -592,7 +592,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected numeric value for total_alkalinity.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } total_alkalinity_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -605,7 +605,7 @@ cxxSolution::read_raw(CParser & parser, bool check) this->cb = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge balance.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } cb_defined = true; opt_save = CParser::OPT_DEFAULT; @@ -623,63 +623,63 @@ cxxSolution::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (ph_defined == false) { parser.incr_input_error(); parser.error_msg("pH not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (pe_defined == false) { parser.incr_input_error(); parser.error_msg("pe not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (mu_defined == false) { parser.incr_input_error(); parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (ah2o_defined == false) { parser.incr_input_error(); parser. error_msg("Activity of water not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (total_h_defined == false) { parser.incr_input_error(); parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (total_o_defined == false) { parser.incr_input_error(); parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (cb_defined == false) { parser.incr_input_error(); parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (mass_water_defined == false) { parser.incr_input_error(); parser.error_msg("Temp not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (total_alkalinity_defined == false) { parser.incr_input_error(); parser. error_msg("Total alkalinity not defined for SOLUTION_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } return; @@ -1469,13 +1469,13 @@ cxxSolution::Update(const cxxNameDouble &nd) // */ // std::ostringstream msg; // status_on = FALSE; -// std::cout << std::endl << "TEST CLASSES" << std::endl; +// std::cout << "\n" << "TEST CLASSES" << "\n"; // for (i = 0; i < count_solution; i++) // { // if (solution[i]->new_def == TRUE) // { // std::cout << "Solution new_def " << solution[i]-> -// n_user << std::endl; +// n_user << "\n"; // cxxISolution sol(solution[i]); // solution_free(solution[i]); // solution[i] = NULL; @@ -1486,7 +1486,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // else // { -// std::cout << "Solution " << solution[i]->n_user << std::endl; +// std::cout << "Solution " << solution[i]->n_user << "\n"; // std::ostringstream oss; // cxxSolution sol(solution[i]); // solution_free(solution[i]); @@ -1515,7 +1515,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // { // if (exchange[i].new_def != TRUE) // { -// std::cout << "Exchange " << exchange[i].n_user << std::endl; +// std::cout << "Exchange " << exchange[i].n_user << "\n"; // std::ostringstream oss; // cxxExchange ex(&(exchange[i])); // ex.dump_raw(oss, 0); @@ -1544,7 +1544,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // { // if (surface[i].new_def != TRUE) // { -// std::cout << "Surface " << surface[i].n_user << std::endl; +// std::cout << "Surface " << surface[i].n_user << "\n"; // std::ostringstream oss; // cxxSurface ex(&(surface[i])); // ex.dump_raw(oss, 0); @@ -1577,7 +1577,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // if (pp_assemblage[i].new_def != TRUE) // { // std::cout << "PPassemblage " << pp_assemblage[i]. -// n_user << std::endl; +// n_user << "\n"; // std::ostringstream oss; // cxxPPassemblage ex(&(pp_assemblage[i])); // ex.dump_raw(oss, 0); @@ -1609,7 +1609,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // for (i = 0; i < count_kinetics; i++) // { -// std::cout << "Kinetics " << kinetics[i].n_user << std::endl; +// std::cout << "Kinetics " << kinetics[i].n_user << "\n"; // std::ostringstream oss; // cxxKinetics ex(&(kinetics[i])); // ex.dump_raw(oss, 0); @@ -1640,7 +1640,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // if (s_s_assemblage[i].new_def != TRUE) // { // std::cout << "Solid solution " << s_s_assemblage[i]. -// n_user << std::endl; +// n_user << "\n"; // std::ostringstream oss; // cxxSSassemblage ex(&(s_s_assemblage[i])); // ex.dump_raw(oss, 0); @@ -1674,7 +1674,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // { // if (gas_phase[i].new_def != TRUE) // { -// std::cout << "Gas phase " << gas_phase[i].n_user << std::endl; +// std::cout << "Gas phase " << gas_phase[i].n_user << "\n"; // std::ostringstream oss; // cxxGasPhase ex(&(gas_phase[i])); // ex.dump_raw(oss, 0); @@ -1705,7 +1705,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // for (i = 0; i < count_irrev; i++) // { -// std::cout << "Reaction " << irrev[i].n_user << std::endl; +// std::cout << "Reaction " << irrev[i].n_user << "\n"; // std::ostringstream oss; // cxxReaction ex(&(irrev[i])); // ex.dump_raw(oss, 0); @@ -1734,7 +1734,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // for (i = 0; i < count_mix; i++) // { -// std::cout << "Mix " << mix[i].n_user << std::endl; +// std::cout << "Mix " << mix[i].n_user << "\n"; // std::ostringstream oss; // cxxMix ex(&(mix[i])); // ex.dump_raw(oss, 0); @@ -1763,7 +1763,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // for (i = 0; i < count_temperature; i++) // { -// std::cout << "Temperature " << temperature[i].n_user << std::endl; +// std::cout << "Temperature " << temperature[i].n_user << "\n"; // std::ostringstream oss; // cxxTemperature ex(&(temperature[i])); // ex.dump_raw(oss, 0); diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 482ef502..c708877f 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -91,32 +91,32 @@ cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const indent1.append(Utilities::INDENT); s_oss << indent0; - s_oss << " - isotope_number << "\"" << std::endl; + isotope_number << "\"" << "\n"; s_oss << indent1; - s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << std::endl; + s_oss << "iso_elt_name=\"" << this->elt_name << "\"" << "\n"; s_oss << indent1; - s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << std::endl; + s_oss << "iso_isotope_name=\"" << this->isotope_name << "\"" << "\n"; s_oss << indent1; - s_oss << "iso_total=\"" << this->total << "\"" << std::endl; + s_oss << "iso_total=\"" << this->total << "\"" << "\n"; s_oss << indent1; - s_oss << "iso_ratio=\"" << this->ratio << "\"" << std::endl; + s_oss << "iso_ratio=\"" << this->ratio << "\"" << "\n"; if (this->ratio_uncertainty != NAN) { s_oss << indent1; s_oss << "iso_ratio_uncertainty=\"" << this-> - ratio_uncertainty << "\"" << std::endl; + ratio_uncertainty << "\"" << "\n"; } s_oss << indent0; - s_oss << "\">" << std::endl; + s_oss << "\">" << "\n"; } void @@ -138,7 +138,7 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const { s_oss << this->ratio_uncertainty << " "; } - s_oss << std::endl; + s_oss << "\n"; } CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream::pos_type next_char ) @@ -192,7 +192,7 @@ CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream parser.incr_input_error(); parser. error_msg("Expected numeric value for mass of water in solution.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -243,7 +243,7 @@ cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) parser.incr_input_error(); parser.error_msg("Expected isotope name to" " begin with an isotopic number.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return ERROR; } assert(parser.get_iss().good() || parser.get_iss().eof()); @@ -252,8 +252,8 @@ cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) std::istringstream::int_type c = parser.get_iss().peek(); if (c == std::char_traits < char >::eof() || !(::isupper(c))) { - parser.error_msg("Expecting element name.", CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + parser.error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); parser.incr_input_error(); return ERROR; } @@ -272,7 +272,7 @@ cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) assert(parser.get_iss().fail()); parser.incr_input_error(); parser.error_msg("Expected numeric value for isotope ratio.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return ERROR; } assert(parser.get_iss().good() || parser.get_iss().eof()); @@ -287,7 +287,7 @@ cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) parser. error_msg ("Expected numeric value for uncertainty in isotope ratio.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); return ERROR; } } diff --git a/StorageBin.cxx b/StorageBin.cxx index 95f7c7b9..8b38d195 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -375,15 +375,15 @@ cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const // StorageBin element and attributes s_oss << indent0; - s_oss << " - pitzer_mix_gammas << "\"" << std::endl; + pitzer_mix_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { @@ -505,13 +505,13 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent, int *n void cxxStorageBin::read_raw(CParser & parser) { - CParser::LINE_TYPE i; + PHRQ_io::LINE_TYPE i; while ((i = parser.check_line("StorageBin read_raw", false, true, true, - true)) != CParser::LT_KEYWORD) + true)) != PHRQ_io::LT_KEYWORD) { - if (i == CParser::LT_EOF) - return; // CParser::LT_EOF; + if (i == PHRQ_io::LT_EOF) + return; // PHRQ_io::LT_EOF; } for (;;) @@ -624,13 +624,13 @@ cxxStorageBin::read_raw(CParser & parser) } END_OF_SIMULATION_INPUT: - return; //CParser::LT_OK; + return; //PHRQ_io::LT_OK; } int cxxStorageBin::read_raw_keyword(CParser & parser) { - CParser::LINE_TYPE i; + PHRQ_io::LINE_TYPE i; int entity_number = -999; switch (parser.next_keyword()) @@ -641,10 +641,10 @@ cxxStorageBin::read_raw_keyword(CParser & parser) case Keywords::KEY_END: while ((i = parser.check_line("StorageBin read_raw_keyword", false, true, - true, true)) != CParser::LT_KEYWORD) + true, true)) != PHRQ_io::LT_KEYWORD) { - if (i == CParser::LT_EOF) - break; // CParser::LT_EOF; + if (i == PHRQ_io::LT_EOF) + break; // PHRQ_io::LT_EOF; } break; /*case CParser::KT_EOF: @@ -753,7 +753,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) default: break; } - return (entity_number); //CParser::LT_OK; + return (entity_number); //PHRQ_io::LT_OK; } //void @@ -1060,7 +1060,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed Solution" << std::endl; + //std::cerr << "Packed Solution" << "\n"; // Exchanger if (this->getExchange(n) != NULL) @@ -1072,7 +1072,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed Exchange" << std::endl; + //std::cerr << "Packed Exchange" << "\n"; // GasPhase if (this->getGasPhase(n) != NULL) @@ -1084,7 +1084,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed GasPhase" << std::endl; + //std::cerr << "Packed GasPhase" << "\n"; // Kinetics if (this->getKinetics(n) != NULL) @@ -1096,7 +1096,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed Kinetics" << std::endl; + //std::cerr << "Packed Kinetics" << "\n"; // PPassemblages if (this->getPPassemblage(n) != NULL) @@ -1108,7 +1108,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed PPassemblage" << std::endl; + //std::cerr << "Packed PPassemblage" << "\n"; // SSassemblages if (this->getSSassemblage(n) != NULL) @@ -1120,7 +1120,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed SSassemblage" << std::endl; + //std::cerr << "Packed SSassemblage" << "\n"; // Surfaces if (this->getSurface(n) != NULL) @@ -1132,7 +1132,7 @@ cxxStorageBin::mpi_send(int n, int task_number) { ints.push_back(0); } - //std::cerr << "Packed Surface" << std::endl; + //std::cerr << "Packed Surface" << "\n"; // Pack data int max_size = 0; @@ -1155,11 +1155,11 @@ cxxStorageBin::mpi_send(int n, int task_number) /* for (int j = 0; j < i; j++) { int_array[j] = ints[j]; - //std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl; + //std::cerr << "Sending ints " << j << " value " << ints[j] << "\n"; } for (int j = 0; j < d; j++) { double_array[j] = doubles[j]; - //std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl; + //std::cerr << "Sending doubles " << j << " value " << doubles[j] << "\n"; } */ /* @@ -1243,7 +1243,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setSolution(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked Solution" << std::endl; + //std::cerr << "Unpacked Solution" << "\n"; // Exchanger if (ints[i++] != 0) @@ -1252,7 +1252,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setExchange(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked Exchange" << std::endl; + //std::cerr << "Unpacked Exchange" << "\n"; // GasPhase if (ints[i++] != 0) @@ -1261,7 +1261,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setGasPhase(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked GasPhase" << std::endl; + //std::cerr << "Unpacked GasPhase" << "\n"; // Kinetics if (ints[i++] != 0) @@ -1270,7 +1270,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setKinetics(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked Kinetics" << std::endl; + //std::cerr << "Unpacked Kinetics" << "\n"; // PPassemblage if (ints[i++] != 0) @@ -1279,7 +1279,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setPPassemblage(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked PPassemblage" << std::endl; + //std::cerr << "Unpacked PPassemblage" << "\n"; // SSassemblage if (ints[i++] != 0) @@ -1288,7 +1288,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setSSassemblage(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked SSassemblage" << std::endl; + //std::cerr << "Unpacked SSassemblage" << "\n"; // Surfaces if (ints[i++] != 0) @@ -1297,7 +1297,7 @@ cxxStorageBin::mpi_recv(int task_number) entity.mpi_unpack(ints, &i, doubles, &d); this->setSurface(entity.Get_n_user(), &entity); } - //std::cerr << "Unpacked Surface" << std::endl; + //std::cerr << "Unpacked Surface" << "\n"; delete[]ints; delete[]doubles; @@ -1503,10 +1503,10 @@ cxxStorageBin::Set_System(struct Use *use_ptr) } } // reaction - if (use_ptr->irrev_ptr != NULL) + if (use_ptr->reaction_ptr != NULL) { std::map < int, cxxReaction >::iterator it = - this->Reactions.find(use_ptr->n_irrev_user); + this->Reactions.find(use_ptr->n_reaction_user); if (it != this->Reactions.end()) { this->system.Set_Reaction(&(it->second)); diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 53d4023b..7e88348d 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -17,9 +17,9 @@ StorageBinListItem::StorageBinListItem(CParser & parser) for (;;) { //read lines - CParser::LINE_TYPE l = parser.check_line("read StorageBinListLtem", false, true, true, true); + PHRQ_io::LINE_TYPE l = parser.check_line("read StorageBinListLtem", false, true, true, true); std::istream::pos_type next_char = 0; - if (l == CParser::LT_EOF) break; + if (l == PHRQ_io::LT_EOF) break; for (;;) { std::string token; @@ -36,7 +36,7 @@ StorageBinListItem::StorageBinListItem(CParser & parser) { // ignore characters like RUN //parser.error_msg("Expected single number or range of numbers.", - // CParser::OT_CONTINUE); + // PHRQ_io::OT_CONTINUE); //break; } } @@ -259,7 +259,7 @@ bool StorageBinList::Read(CParser & parser) else { parser.error_msg("Expected single number or range of numbers.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); break; } } @@ -302,8 +302,8 @@ bool StorageBinList::Read(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input reading DELETE definition.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; return_value = false; break; diff --git a/Surface.cxx b/Surface.cxx index 03a488ce..e676fd0e 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -154,44 +154,44 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const // Surface element and attributes s_oss << indent0; - s_oss << "diffuse_layer << "\"" << std::endl; - s_oss << "surface_type=\"" << this->type << "\"" << std::endl; + //s_oss << "diffuse_layer=\"" << this->diffuse_layer << "\"" << "\n"; + s_oss << "surface_type=\"" << this->type << "\"" << "\n"; s_oss << indent1; - //s_oss << "edl=\"" << this->edl << "\"" << std::endl; - s_oss << "dl_type=\"" << this->dl_type << "\"" << std::endl; + //s_oss << "edl=\"" << this->edl << "\"" << "\n"; + s_oss << "dl_type=\"" << this->dl_type << "\"" << "\n"; s_oss << indent1; - s_oss << "sites_units=\"" << this->sites_units << "\"" << std::endl; + s_oss << "sites_units=\"" << this->sites_units << "\"" << "\n"; s_oss << indent1; s_oss << "only_counter_ions=\"" << this-> - only_counter_ions << "\"" << std::endl; + only_counter_ions << "\"" << "\n"; //s_oss << indent1; - //s_oss << "donnan=\"" << this->donnan << "\"" << std::endl; + //s_oss << "donnan=\"" << this->donnan << "\"" << "\n"; s_oss << indent1; - s_oss << "thickness=\"" << this->thickness << "\"" << std::endl; + s_oss << "thickness=\"" << this->thickness << "\"" << "\n"; s_oss << indent1; - s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << std::endl; + s_oss << "debye_lengths=\"" << this->debye_lengths << "\"" << "\n"; s_oss << indent1; - s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << std::endl; + s_oss << "DDL_viscosity=\"" << this->DDL_viscosity << "\"" << "\n"; s_oss << indent1; - s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << std::endl; + s_oss << "DDL_limit=\"" << this->DDL_limit << "\"" << "\n"; s_oss << indent1; - s_oss << "transport=\"" << this->transport << "\"" << std::endl; + s_oss << "transport=\"" << this->transport << "\"" << "\n"; // surface component structures s_oss << indent1; - s_oss << "::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) @@ -201,7 +201,7 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const } // surface charge structures s_oss << indent1; - s_oss << "::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { @@ -228,46 +228,46 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons // Surface element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - //s_oss << "-diffuse_layer " << this->diffuse_layer << std::endl; - s_oss << "-type " << this->type << std::endl; + //s_oss << "-diffuse_layer " << this->diffuse_layer << "\n"; + s_oss << "-type " << this->type << "\n"; s_oss << indent1; - //s_oss << "-edl " << this->edl << std::endl; - s_oss << "-dl_type " << this->dl_type << std::endl; + //s_oss << "-edl " << this->edl << "\n"; + s_oss << "-dl_type " << this->dl_type << "\n"; s_oss << indent1; - s_oss << "-sites_units " << this->sites_units << std::endl; + s_oss << "-sites_units " << this->sites_units << "\n"; s_oss << indent1; - s_oss << "-only_counter_ions " << this->only_counter_ions << std::endl; + s_oss << "-only_counter_ions " << this->only_counter_ions << "\n"; //s_oss << indent1; - //s_oss << "-donnan " << this->donnan << std::endl; + //s_oss << "-donnan " << this->donnan << "\n"; s_oss << indent1; - s_oss << "-thickness " << this->thickness << std::endl; + s_oss << "-thickness " << this->thickness << "\n"; s_oss << indent1; - s_oss << "-debye_lengths " << this->debye_lengths << std::endl; + s_oss << "-debye_lengths " << this->debye_lengths << "\n"; s_oss << indent1; - s_oss << "-DDL_viscosity " << this->DDL_viscosity << std::endl; + s_oss << "-DDL_viscosity " << this->DDL_viscosity << "\n"; s_oss << indent1; - s_oss << "-DDL_limit " << this->DDL_limit << std::endl; + s_oss << "-DDL_limit " << this->DDL_limit << "\n"; s_oss << indent1; - s_oss << "-transport " << this->transport << std::endl; + s_oss << "-transport " << this->transport << "\n"; // surfaceComps structures for (std::map < std::string, cxxSurfaceComp >::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) { s_oss << indent1; - s_oss << "-component" << std::endl; + s_oss << "-component" << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } // surface charge structures @@ -276,7 +276,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons surfaceCharges.begin(); it != surfaceCharges.end(); ++it) { s_oss << indent1; - s_oss << "-charge_component " << std::endl; + s_oss << "-charge_component " << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } } @@ -352,21 +352,21 @@ cxxSurface::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in SURFACE keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; case 0: // diffuse_layer parser.incr_input_error(); parser.error_msg("Diffuse layer is obsolete, use -type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); /* if (!(parser.get_iss() >> this->diffuse_layer)) { this->diffuse_layer = false; parser.incr_input_error(); - parser.error_msg("Expected boolean value for diffuse_layer.", CParser::OT_CONTINUE); + parser.error_msg("Expected boolean value for diffuse_layer.", PHRQ_io::OT_CONTINUE); } diffuse_layer_defined = true; */ @@ -376,13 +376,13 @@ cxxSurface::read_raw(CParser & parser, bool check) case 1: // edl parser.incr_input_error(); parser.error_msg("-edl is obsolete, use -type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); /* if (!(parser.get_iss() >> this->edl)) { this->edl = false; parser.incr_input_error(); - parser.error_msg("Expected boolean value for edl.", CParser::OT_CONTINUE); + parser.error_msg("Expected boolean value for edl.", PHRQ_io::OT_CONTINUE); } edl_defined = true; */ @@ -396,7 +396,7 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected boolean value for only_counter_ions.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } only_counter_ions_defined = true; useLastLine = false; @@ -405,13 +405,13 @@ cxxSurface::read_raw(CParser & parser, bool check) case 3: // donnan parser.incr_input_error(); parser.error_msg("-Donnan is obsolete, use -dl_type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); /* if (!(parser.get_iss() >> this->donnan)) { this->donnan = false; parser.incr_input_error(); - parser.error_msg("Expected boolean value for donnan.", CParser::OT_CONTINUE); + parser.error_msg("Expected boolean value for donnan.", PHRQ_io::OT_CONTINUE); } donnan_defined = true; */ @@ -424,7 +424,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->thickness = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for thickness.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } thickness_defined = true; useLastLine = false; @@ -492,7 +492,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->type = NO_EDL; parser.incr_input_error(); parser.error_msg("Expected numeric value for type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } this->type = (SURFACE_TYPE) i; type_defined = true; @@ -505,7 +505,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->dl_type = NO_DL; parser.incr_input_error(); parser.error_msg("Expected numeric value for dl_type.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } this->dl_type = (DIFFUSE_LAYER_TYPE) i; dl_type_defined = true; @@ -518,7 +518,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->sites_units = SITES_ABSOLUTE; parser.incr_input_error(); parser.error_msg("Expected numeric value for sites_units.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } this->sites_units = (SITES_UNITS) i; sites_units_defined = true; @@ -531,7 +531,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->debye_lengths = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for debye_lengths.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } debye_lengths_defined = true; useLastLine = false; @@ -543,7 +543,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->DDL_viscosity = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for DDL_viscosity.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } DDL_viscosity_defined = true; useLastLine = false; @@ -555,7 +555,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->DDL_limit = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for DDL_limit.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } DDL_limit_defined = true; useLastLine = false; @@ -567,7 +567,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->transport = false; parser.incr_input_error(); parser.error_msg("Expected boolean value for transport.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } transport_defined = true; useLastLine = false; @@ -583,11 +583,11 @@ cxxSurface::read_raw(CParser & parser, bool check) /* if (diffuse_layer_defined == false) { parser.incr_input_error(); - parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); } if (edl_defined == false) { parser.incr_input_error(); - parser.error_msg("Edl not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + parser.error_msg("Edl not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); } */ if (only_counter_ions_defined == false) @@ -595,61 +595,61 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Only_counter_ions not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } /* if (donnan_defined == false) { parser.incr_input_error(); - parser.error_msg("Donnan not defined for SURFACE_RAW input.", CParser::OT_CONTINUE); + parser.error_msg("Donnan not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); } */ if (thickness_defined == false) { parser.incr_input_error(); parser.error_msg("Thickness not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (type_defined == false) { parser.incr_input_error(); parser.error_msg("Surface type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (dl_type_defined == false) { parser.incr_input_error(); parser.error_msg("Dl_type not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (sites_units_defined == false) { parser.incr_input_error(); parser.error_msg("Sites_units not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (debye_lengths_defined == false) { parser.incr_input_error(); parser.error_msg("Debye_lengths not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (DDL_viscosity_defined == false) { parser.incr_input_error(); parser.error_msg("DDL_viscosity not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (DDL_limit_defined == false) { parser.incr_input_error(); parser.error_msg("DDL_limit not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (transport_defined == false) { parser.incr_input_error(); parser.error_msg("Transport not defined for SURFACE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 4f971075..320e01e4 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -73,7 +73,7 @@ cxxSurfaceCharge::~cxxSurfaceCharge() // { // std::ostringstream error_oss; // error_oss << "Surface charge psi_master not found." << this-> -// name << std::endl; +// name << "\n"; // //Utilities::error_msg(error_oss.str(), CONTINUE); // error_msg(error_oss.str().c_str(), CONTINUE); // } @@ -96,23 +96,23 @@ cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const // Surf_Charge element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << std::endl; + s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; s_oss << indent0 << "specific_area=\"" << this-> - specific_area << "\"" << std::endl; - s_oss << indent0 << "grams=\"" << this->grams << "\"" << std::endl; + specific_area << "\"" << "\n"; + s_oss << indent0 << "grams=\"" << this->grams << "\"" << "\n"; s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << std::endl; + charge_balance << "\"" << "\n"; s_oss << indent0 << "mass_water=\"" << this-> - mass_water << "\"" << std::endl; - s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << std::endl; - s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << std::endl; - s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << std::endl; + mass_water << "\"" << "\n"; + s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << "\n"; + s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << "\n"; + s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << "\n"; s_oss << indent0 << "capacitance=\"" << this-> - capacitance[0] << " " << this->capacitance[0] << "\"" << std::endl; + capacitance[0] << " " << this->capacitance[0] << "\"" << "\n"; // totals s_oss << indent0; - s_oss << "diffuse_layer_totals.dump_xml(s_oss, indent + 1); } @@ -133,28 +133,28 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const // Surf_Charge element and attributes - s_oss << indent0 << "-name " << this->name << std::endl; + s_oss << indent0 << "-name " << this->name << "\n"; s_oss << indent1 << "-specific_area " << this-> - specific_area << std::endl; - s_oss << indent1 << "-grams " << this->grams << std::endl; + specific_area << "\n"; + s_oss << indent1 << "-grams " << this->grams << "\n"; s_oss << indent1 << "-charge_balance " << this-> - charge_balance << std::endl; + charge_balance << "\n"; s_oss << indent1 << "-mass_water " << this-> - mass_water << std::endl; + mass_water << "\n"; s_oss << indent1 << "-la_psi " << this-> - la_psi << std::endl; + la_psi << "\n"; s_oss << indent1 << "-la_psi1 " << this-> - la_psi1 << std::endl; + la_psi1 << "\n"; s_oss << indent1 << "-la_psi2 " << this-> - la_psi2 << std::endl; + la_psi2 << "\n"; s_oss << indent1 << "-capacitance0 " << this-> - capacitance[0] << std::endl; + capacitance[0] << "\n"; s_oss << indent1 << "-capacitance1 " << this-> - capacitance[1] << std::endl; + capacitance[1] << "\n"; // totals s_oss << indent1; - s_oss << "-diffuse_layer_totals" << std::endl; + s_oss << "-diffuse_layer_totals" << "\n"; this->diffuse_layer_totals.dump_raw(s_oss, indent + 2); } @@ -216,8 +216,8 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_CHARGE read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in SURF_CHARGE read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name @@ -226,7 +226,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -241,7 +241,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->specific_area = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for specific_area.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } specific_area_defined = true; break; @@ -252,7 +252,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->grams = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for grams.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } grams_defined = true; break; @@ -264,7 +264,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->charge_balance = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge_balance.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } charge_balance_defined = true; break; @@ -275,7 +275,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->mass_water = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for mass_water.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } mass_water_defined = true; break; @@ -287,7 +287,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } la_psi_defined = true; break; @@ -301,7 +301,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 6; break; @@ -312,7 +312,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi1 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi1.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } la_psi1_defined = true; break; @@ -323,7 +323,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->la_psi2 = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la_psi.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } la_psi2_defined = true; break; @@ -334,7 +334,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->capacitance[0] = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for capacitance0.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } capacitance0_defined = true; break; @@ -345,7 +345,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) this->capacitance[1] = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for capacitance1.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } capacitance1_defined = true; break; @@ -361,62 +361,62 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Name not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (specific_area_defined == false) { parser.incr_input_error(); parser.error_msg("Specific_area not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (grams_defined == false) { parser.incr_input_error(); parser.error_msg("Grams not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (charge_balance_defined == false) { parser.incr_input_error(); parser. error_msg("Charge_balance not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (mass_water_defined == false) { parser.incr_input_error(); parser.error_msg("Mass_water not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (la_psi_defined == false) { parser.incr_input_error(); parser.error_msg("La_psi not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (la_psi1_defined == false) { parser.incr_input_error(); parser.error_msg("La_psi1 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (la_psi2_defined == false) { parser.incr_input_error(); parser.error_msg("La_psi2 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (capacitance0_defined == false) { parser.incr_input_error(); parser.error_msg("Capacitance0 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (capacitance1_defined == false) { parser.incr_input_error(); parser.error_msg("Capacitance1 not defined for SurfaceCharge input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 2ec5e323..08f6e84d 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -77,36 +77,36 @@ cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const // Surf_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << std::endl; + s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; s_oss << indent0 << "formula_z=\"" << this-> - formula_z << "\"" << std::endl; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << std::endl; - s_oss << indent0 << "la=\"" << this->la << "\"" << std::endl; - //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << std::endl; + formula_z << "\"" << "\n"; + s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; + s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; + //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << "\n"; s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << std::endl; + charge_balance << "\"" << "\n"; if (this->phase_name.size() != 0) { s_oss << indent0 << "phase_name=\"" << this-> - phase_name << "\"" << std::endl; + phase_name << "\"" << "\n"; } if (this->rate_name.size() != 0) { s_oss << indent0 << "rate_name=\"" << this-> - rate_name << "\"" << std::endl; + rate_name << "\"" << "\n"; } s_oss << indent0 << "phase_proportion=\"" << this-> - phase_proportion << "\"" << std::endl; - s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << std::endl; + phase_proportion << "\"" << "\n"; + s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << "\n"; // formula_totals s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); // totals s_oss << indent0; - s_oss << "totals.dump_xml(s_oss, indent + 1); } @@ -128,36 +128,36 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Surf_Comp element and attributes s_oss << indent0 << "-formula " << this-> - formula << std::endl; + formula << "\n"; s_oss << indent1 << "-formula_z " << this-> - formula_z << std::endl; - s_oss << indent1 << "-moles " << this->moles << std::endl; - s_oss << indent1 << "-la " << this->la << std::endl; - //s_oss << indent1 << "-charge_number " << this->charge_number << std::endl; + formula_z << "\n"; + s_oss << indent1 << "-moles " << this->moles << "\n"; + s_oss << indent1 << "-la " << this->la << "\n"; + //s_oss << indent1 << "-charge_number " << this->charge_number << "\n"; s_oss << indent1 << "-charge_balance " << this-> - charge_balance << std::endl; + charge_balance << "\n"; if (this->phase_name.size() != 0) { s_oss << indent1 << "-phase_name " << this-> - phase_name << std::endl; + phase_name << "\n"; } if (this->rate_name.size() != 0) { s_oss << indent1 << "-rate_name " << this-> - rate_name << std::endl; + rate_name << "\n"; } s_oss << indent1 << "-phase_proportion " << this-> - phase_proportion << std::endl; - s_oss << indent1 << "-Dw " << this->Dw << std::endl; + phase_proportion << "\n"; + s_oss << indent1 << "-Dw " << this->Dw << "\n"; // formula_totals s_oss << indent1; - s_oss << "-formula_totals" << std::endl; + s_oss << "-formula_totals" << "\n"; this->formula_totals.dump_raw(s_oss, indent + 2); // totals s_oss << indent1; - s_oss << "-totals" << std::endl; + s_oss << "-totals" << "\n"; this->totals.dump_raw(s_oss, indent + 2); } @@ -217,8 +217,8 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_COMP read.", CParser::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + //parser.error_msg("Unknown input in SURF_COMP read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // formula @@ -227,7 +227,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->formula.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for formula.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -242,7 +242,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->moles = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for moles.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } moles_defined = true; break; @@ -253,7 +253,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->la = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for la.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } la_defined = true; break; @@ -264,7 +264,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->charge_number = 0; parser.incr_input_error(); parser.error_msg("Expected integer value for charge_number.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } charge_number_defined = true; break; @@ -275,7 +275,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->charge_balance = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for charge_balance.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } charge_balance_defined = true; break; @@ -286,7 +286,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->phase_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for phase_name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -300,7 +300,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->rate_name.clear(); parser.incr_input_error(); parser.error_msg("Expected string value for rate_name.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -315,7 +315,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg("Expected numeric value for phase_proportion.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } break; @@ -327,7 +327,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceComp totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 8; break; @@ -338,7 +338,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->formula_z = 0; parser.incr_input_error(); parser.error_msg("Expected numeric value for formula_z.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } formula_z_defined = true; break; @@ -351,7 +351,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for SurfaceComp formula totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 10; break; @@ -362,7 +362,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) this->Dw = 0.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for Dw.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } Dw_defined = true; break; @@ -377,45 +377,45 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Formula not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (formula_z_defined == false) { parser.incr_input_error(); parser.error_msg("Formula_z not defined for ExchComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (moles_defined == false) { parser.incr_input_error(); parser.error_msg("Moles not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (la_defined == false) { parser.incr_input_error(); parser.error_msg("La not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } #ifdef SKIP if (charge_number_defined == false) { parser.incr_input_error(); parser.error_msg("Charge_number not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } #endif if (charge_balance_defined == false) { parser.incr_input_error(); parser.error_msg("Charge_balance not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (Dw_defined == false) { parser.incr_input_error(); parser.error_msg("Dw not defined for SurfaceComp input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } diff --git a/Temperature.cxx b/Temperature.cxx index a4417715..00a67e61 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -49,15 +49,15 @@ cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Temperature element and attributes s_oss << indent0; - s_oss << " - pitzer_temperature_gammas << "\"" << std::endl; + pitzer_temperature_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = temperatureComps.begin(); it != temperatureComps.end(); ++it) { @@ -86,7 +86,7 @@ cxxTemperature::read(CParser & parser) */ // Number and description set in read_reaction_temperature - CParser::LINE_TYPE lt; + PHRQ_io::LINE_TYPE lt; bool done = false; for (;;) { @@ -95,21 +95,21 @@ cxxTemperature::read(CParser & parser) std::string token, str; lt = parser.check_line(str, false, true, true, true); - if (lt == CParser::LT_EMPTY || - lt == CParser::LT_KEYWORD || - lt == CParser::LT_EOF) + if (lt == PHRQ_io::LT_EMPTY || + lt == PHRQ_io::LT_KEYWORD || + lt == PHRQ_io::LT_EOF) { break; } - if (lt == CParser::LT_OPTION) + if (lt == PHRQ_io::LT_OPTION) { - this->error_msg("Expected numeric value for temperatures.", CParser::OT_CONTINUE); + this->error_msg("Expected numeric value for temperatures.", PHRQ_io::OT_CONTINUE); break; } if (done) { - this->error_msg("Unknown input following equal increment definition.", CParser::OT_CONTINUE); + this->error_msg("Unknown input following equal increment definition.", PHRQ_io::OT_CONTINUE); continue; } @@ -136,7 +136,7 @@ cxxTemperature::read(CParser & parser) if (!(iss >> d)) { this->error_msg("Expected numeric value for temperatures.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -200,18 +200,18 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-count_temps " << this->Get_countTemps() << std::endl; + s_oss << "-count_temps " << this->Get_countTemps() << "\n"; s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << std::endl; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; // Temperature element and attributes s_oss << indent1; - s_oss << "-temps " << std::endl; + s_oss << "-temps " << "\n"; { int i = 0; s_oss << indent2; @@ -220,13 +220,13 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) { if (i++ == 5) { - s_oss << std::endl; + s_oss << "\n"; s_oss << indent2; i = 0; } s_oss << *it << " "; } - s_oss << std::endl; + s_oss << "\n"; } } @@ -285,8 +285,8 @@ cxxTemperature::read_raw(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in TEMPERATURE_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -304,7 +304,7 @@ cxxTemperature::read_raw(CParser & parser) { parser.incr_input_error(); parser.error_msg("Expected numeric value for temps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -322,7 +322,7 @@ cxxTemperature::read_raw(CParser & parser) parser.incr_input_error(); parser. error_msg("Expected boolean value for equalIncrements.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -335,7 +335,7 @@ cxxTemperature::read_raw(CParser & parser) this->countTemps = 0; parser.incr_input_error(); parser.error_msg("Expected integer value for countTemps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; useLastLine = false; @@ -352,7 +352,7 @@ cxxTemperature::read_raw(CParser & parser) parser. error_msg ("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (countTemps_defined == false) { @@ -360,7 +360,7 @@ cxxTemperature::read_raw(CParser & parser) parser. error_msg ("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } /* ---------------------------------------------------------------------- */ diff --git a/Temperature.h b/Temperature.h index fb7386cc..68656ac9 100644 --- a/Temperature.h +++ b/Temperature.h @@ -23,11 +23,11 @@ class cxxTemperature:public cxxNumKeyword void read_raw(CParser & parser); int read(CParser & parser); LDBLE Temperature_for_step(int step_number); - std::vector & Get_temps(void) {return temps;}; + std::vector & Get_temps(void) {return temps;} int Get_countTemps(void) const; - void Set_countTemps(int i) {countTemps = i;}; - bool Get_equalIncrements(void) const {return equalIncrements;}; - void Set_equalIncrements(bool tf) {equalIncrements = tf;}; + void Set_countTemps(int i) {countTemps = i;} + bool Get_equalIncrements(void) const {return equalIncrements;} + void Set_equalIncrements(bool tf) {equalIncrements = tf;} protected: std::vector < double >temps; diff --git a/Utils.cxx b/Utils.cxx index 407d24f2..86c174f5 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -9,6 +9,7 @@ #include "Utils.h" #include "Parser.h" + //////////////////////////////////////////////////////////////////////////// int Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) diff --git a/Utils.h b/Utils.h index e96c8831..913a02ab 100644 --- a/Utils.h +++ b/Utils.h @@ -1,6 +1,6 @@ #if !defined(UTILITIES_H_INCLUDED) #define UTILITIES_H_INCLUDED - +#include "Phreeqc.h" #include #include // std::istringstream std::ostringstream #include // std::ostream @@ -11,14 +11,14 @@ namespace Utilities { const char INDENT[] = " "; - +#ifdef SKIP enum STATUS_TYPE { - OK = 0, - ERROR = 1 + ST_OK = 0, + ST_ERROR = 1 }; - - STATUS_TYPE parse_couple(std::string & token); +#endif + //STATUS_TYPE parse_couple(std::string & token); int strcmp_nocase(const char *str1, const char *str2); @@ -89,6 +89,78 @@ namespace Utilities return (b.find(i) != b.end());} */ -} + template < typename T > + void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end) + { + if (n_user_end <= n_user) return; + typename std::map < int, T >::iterator it; + it = b.find(n_user); + if (it != b.end()) + { + for (int j = n_user + 1; j <= n_user_end; j++) + { + b[j] = it->second; + it = b.find(j); + it->second.Set_n_user(j); + it->second.Set_n_user_end(j); + } + } + } + template < typename T > + int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + { + typename std::map < int, T >::iterator it; + assert(!phreeqc_cookie->reading_database()); + T entity(phreeqc_cookie->Get_phrq_io()); + + CParser parser(phreeqc_cookie->Get_phrq_io()); + //if (phreeqc_cookie->pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); + entity.read_raw(parser); + + // Store + if (entity.Get_base_error_count() == 0) + { + m[entity.Get_n_user()] = entity; + } + + // Make copies if necessary + Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end()); + return phreeqc_cookie->cleanup_after_parser(parser); + } + + template < typename T > + int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + { + typename std::map < int, T >::iterator it; + + CParser parser(phreeqc_cookie->Get_phrq_io()); + + std::string key_name; + std::string::iterator b = parser.line().begin(); + std::string::iterator e = parser.line().end(); + CParser::copy_token(key_name, b, e); + + cxxNumKeyword nk; + nk.read_number_description(parser); + T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user()); + if (!entity_ptr) + { + std::ostringstream errstr; + errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n"; + phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP); + } + + entity_ptr->read_raw(parser, false); + + return phreeqc_cookie->cleanup_after_parser(parser); + } + + /* + template + bool exists (std::map b, int i){ + return (b.find(i) != b.end());} + */ + +} #endif // UTILITIES_H_INCLUDED diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 377096d1..74c36c2e 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -129,15 +129,15 @@ cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Kinetics element and attributes s_oss << indent0; - s_oss << " - pitzer_kinetics_gammas << "\"" << std::endl; + pitzer_kinetics_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { @@ -165,47 +165,47 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co // Kinetics element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "KINETICS_RAW " << n_user_local << " " << this->description << std::endl; + s_oss << "KINETICS_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-step_divide " << this->step_divide << std::endl; + s_oss << "-step_divide " << this->step_divide << "\n"; s_oss << indent1; - s_oss << "-rk " << this->rk << std::endl; + s_oss << "-rk " << this->rk << "\n"; s_oss << indent1; - s_oss << "-bad_step_max " << this->bad_step_max << std::endl; + s_oss << "-bad_step_max " << this->bad_step_max << "\n"; s_oss << indent1; - s_oss << "-use_cvode " << this->use_cvode << std::endl; + s_oss << "-use_cvode " << this->use_cvode << "\n"; s_oss << indent1; - s_oss << "-cvode_steps " << this->cvode_steps << std::endl; + s_oss << "-cvode_steps " << this->cvode_steps << "\n"; s_oss << indent1; - s_oss << "-cvode_order " << this->cvode_order << std::endl; + s_oss << "-cvode_order " << this->cvode_order << "\n"; // kineticsComps structures for (std::list < cxxKineticsComp >::const_iterator it = kineticsComps.begin(); it != kineticsComps.end(); ++it) { s_oss << indent1; - s_oss << "-component" << std::endl; + s_oss << "-component" << "\n"; (*it).dump_raw(s_oss, indent + 2); } // totals s_oss << indent1; - s_oss << "-totals " << std::endl; + s_oss << "-totals " << "\n"; this->totals.dump_raw(s_oss, indent + 2); // equal_steps s_oss << indent1; - s_oss << "-equal_steps " << this->equal_steps << std::endl; + s_oss << "-equal_steps " << this->equal_steps << "\n"; // steps s_oss << indent1; - s_oss << "-steps " << std::endl; + s_oss << "-steps " << "\n"; { int i = 0; s_oss << indent2; @@ -214,13 +214,13 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co { if (i++ == 5) { - s_oss << std::endl; + s_oss << "\n"; s_oss << indent2; i = 0; } s_oss << *it << " "; } - s_oss << std::endl; + s_oss << "\n"; } return; } @@ -291,8 +291,8 @@ cxxKinetics::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in KINETICS_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -302,7 +302,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->step_divide = 1.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for step_divide.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } step_divide_defined = true; useLastLine = false; @@ -314,7 +314,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->rk = 3; parser.incr_input_error(); parser.error_msg("Expected integer value for rk.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } rk_defined = true; useLastLine = false; @@ -326,7 +326,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->bad_step_max = 500; parser.incr_input_error(); parser.error_msg("Expected integer value for bad_step_max.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } bad_step_max_defined = true; useLastLine = false; @@ -338,7 +338,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->use_cvode = false; parser.incr_input_error(); parser.error_msg("Expected boolean value for use_cvode.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } use_cvode_defined = true; useLastLine = false; @@ -404,7 +404,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser. error_msg ("Expected element name and molality for KineticsComp totals.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } opt_save = 5; useLastLine = false; @@ -420,7 +420,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Expected numeric value for steps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } else { @@ -438,7 +438,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->cvode_steps = 100; parser.incr_input_error(); parser.error_msg("Expected integer value for cvode_steps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } cvode_steps_defined = true; useLastLine = false; @@ -450,7 +450,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->cvode_order = 5; parser.incr_input_error(); parser.error_msg("Expected integer value for cvode_order.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } cvode_order_defined = true; useLastLine = false; @@ -461,7 +461,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) this->equal_steps = 0; parser.incr_input_error(); parser.error_msg("Expected integer value for equal_steps.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } equal_steps_defined = true; useLastLine = false; @@ -482,44 +482,44 @@ cxxKinetics::read_raw(CParser & parser, bool check) { parser.incr_input_error(); parser.error_msg("Step_divide not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (rk_defined == false) { parser.incr_input_error(); parser.error_msg("Rk not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (bad_step_max_defined == false) { parser.incr_input_error(); parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (use_cvode_defined == false) { parser.incr_input_error(); parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (cvode_steps_defined == false) { parser.incr_input_error(); parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } if (cvode_order_defined == false) { parser.incr_input_error(); parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } // disable to remain backward compatible with PHAST restart files? //if (equal_steps_defined == false) //{ // parser.incr_input_error(); // parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", - // CParser::OT_CONTINUE); + // PHRQ_io::OT_CONTINUE); //} } } diff --git a/cxxMix.cxx b/cxxMix.cxx index bfc12a83..e3ecf318 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -71,15 +71,15 @@ cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const // Mix element and attributes s_oss << indent0; - s_oss << " - pitzer_mix_gammas << "\"" << std::endl; + pitzer_mix_gammas << "\"" << "\n"; // components s_oss << indent1; - s_oss << "::const_iterator it = mixComps.begin(); it != mixComps.end(); ++it) { @@ -107,12 +107,12 @@ cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const // Mix element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "MIX " << n_user_local << " " << this->description << std::endl; + s_oss << "MIX " << n_user_local << " " << this->description << "\n"; for (std::map < int, double >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { - s_oss << indent1 << it->first << " " << it->second << std::endl; + s_oss << indent1 << it->first << " " << it->second << "\n"; } } @@ -163,8 +163,8 @@ cxxMix::read_raw(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input in MIX_COMP_RAW keyword.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; break; @@ -178,7 +178,7 @@ cxxMix::read_raw(CParser & parser) parser. error_msg ("Expected integer value for solution number.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); break; } if (!(parser.get_iss() >> d)) @@ -187,7 +187,7 @@ cxxMix::read_raw(CParser & parser) parser. error_msg ("Expected numeric value for solution fraction.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); break; } this->mixComps[i] = d; diff --git a/cxxMix.h b/cxxMix.h index 84418a45..b966700d 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -34,7 +34,7 @@ class cxxMix:public cxxNumKeyword { mixComps[n] = f; } - }; + } void Multiply(LDBLE f) { for (std::map < int, LDBLE >::iterator it = this->mixComps.begin(); @@ -42,7 +42,7 @@ class cxxMix:public cxxNumKeyword { it->second *= f; } - }; + } const std::map < int, LDBLE > & Get_mixComps() const { diff --git a/dumper.cpp b/dumper.cpp index 4c93e5a0..84e574ac 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -2,6 +2,7 @@ #include "dumper.h" #include "Parser.h" +#include "PHRQ_io.h" dumper::dumper(PHRQ_io *io) : @@ -170,7 +171,7 @@ bool dumper::Read(CParser & parser) else { parser.error_msg("Expected single number or range of numbers.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } @@ -241,8 +242,8 @@ bool dumper::Read(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input reading DUMP definition.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; return_value = false; break; @@ -393,7 +394,7 @@ bool dumper::Read(CParser & parser) else { parser.error_msg("Expected single number or range of numbers.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } } @@ -465,8 +466,8 @@ bool dumper::Read(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input reading DUMP definition.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; return_value = false; break; diff --git a/runner.cpp b/runner.cpp index fb98feb2..c36ea8ad 100644 --- a/runner.cpp +++ b/runner.cpp @@ -95,7 +95,7 @@ bool runner::Read(CParser & parser) else { parser.error_msg("Expected single number or range of numbers.", - CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); } } break; @@ -103,8 +103,8 @@ bool runner::Read(CParser & parser) if (!(parser.get_iss() >> this->start_time)) { parser.error_msg("Expected start_time for RUN_CELLS.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); } break; case 3: //time_step @@ -114,8 +114,8 @@ bool runner::Read(CParser & parser) if (!(parser.get_iss() >> this->time_step)) { parser.error_msg("Expected time_step for RUN_CELLS.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); } break; default: @@ -123,8 +123,8 @@ bool runner::Read(CParser & parser) case CParser::OPT_ERROR: opt = CParser::OPT_EOF; parser.error_msg("Unknown input reading RUN_CELLS definition.", - CParser::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), CParser::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); useLastLine = false; return_value = false; break; From 15dbbaa342b5567fb946834339ec2830ecbaed85 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Jan 2012 17:01:12 +0000 Subject: [PATCH 0393/1077] New Makefile. Parser.h in header file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5968 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 615 +++++++++++++++++++++++++++++++++---------------------- Utils.h | 1 + 2 files changed, 367 insertions(+), 249 deletions(-) diff --git a/Makefile b/Makefile index 12ac7fc3..66f812f0 100644 --- a/Makefile +++ b/Makefile @@ -178,6 +178,7 @@ COMMON_CXXOBJS = \ Exchange.o \ ExchComp.o \ GasPhase.o \ + GasComp.o \ ISolution.o \ ISolutionComp.o \ Keywords.o \ @@ -230,292 +231,350 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../cxxKinetics.h ../NumKeyword.h ../KineticsComp.h ../NameDouble.h \ - ../Parser.h ../cxxMix.h ../phreeqc/phqalloc.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../cxxMix.h \ - ../NumKeyword.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../cxxKinetics.h ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h +cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../phreeqc/phqalloc.h Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../cxxMix.h ../NumKeyword.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Exchange.h ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../ExchComp.h ../NameDouble.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h +GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../GasComp.h ../NameDouble.h ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../GasPhase.h ../NumKeyword.h ../NameDouble.h \ - ../Parser.h ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../GasPhase.h ../NameDouble.h ../Phreeqc_class.h ../GasComp.h \ + ../phreeqc/phqalloc.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../ISolutionComp.h ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../ISolution.h ../ISolutionComp.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../ISolution.h ../ISolutionComp.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../Phreeqc_class.h \ + ../phreeqc/phqalloc.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../KineticsComp.h ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../NameDouble.h ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h -Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h -PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h + ../Parser.h ../Keywords.h ../PHRQ_io.h +Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h +PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../PPassemblageComp.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../PPassemblage.h ../NumKeyword.h ../PPassemblageComp.h ../NameDouble.h \ - ../Parser.h ../Phreeqc_class.h ../cxxMix.h ../phreeqc/phqalloc.h -Pressure.o: ../Pressure.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Pressure.h \ - ../NumKeyword.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../PPassemblage.h ../PPassemblageComp.h ../NameDouble.h \ + ../Phreeqc_class.h ../phreeqc/phqalloc.h +Pressure.o: ../Pressure.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../phreeqc/phqalloc.h Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../Reaction.h ../NumKeyword.h ../NameDouble.h \ - ../Parser.h ../phreeqc/phqalloc.h -ReadClass.o: ../ReadClass.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../Phreeqc_class.h ../Parser.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../NameDouble.h ../Exchange.h ../ExchComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Reaction.h ../NameDouble.h ../phreeqc/phqalloc.h +ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Phreeqc_class.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../GasPhase.h ../Reaction.h ../cxxMix.h \ + ../SSassemblage.h ../GasPhase.h ../GasComp.h ../Reaction.h \ ../Temperature.h ../phreeqc/phqalloc.h Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../Solution.h ../NumKeyword.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Parser.h ../NameDouble.h ../Phreeqc_class.h \ - ../cxxMix.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SolutionIsotope.h ../Parser.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SolutionIsotope.h ../phreeqc/phqalloc.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SSassemblage.h ../NumKeyword.h ../NameDouble.h ../Parser.h \ - ../Phreeqc_class.h ../SSassemblageSS.h ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SSassemblageSS.h \ + ../phreeqc/phqalloc.h SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SSassemblageSS.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SSassemblageSS.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../StorageBin.h ../System.h \ - ../Phreeqc_class.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ - ../Temperature.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../NameDouble.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ + ../SSassemblage.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SurfaceCharge.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SurfaceCharge.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ ../phreeqc/phqalloc.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Surface.h ../NumKeyword.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../cxxMix.h ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../SurfaceCharge.h \ + ../phreeqc/phqalloc.h System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../System.h ../NameDouble.h ../Parser.h \ - ../Phreeqc_class.h ../SSassemblage.h ../NumKeyword.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../cxxKinetics.h ../KineticsComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../cxxMix.h ../Reaction.h \ - ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Temperature.h \ - ../NumKeyword.h ../phreeqc/phqalloc.h -Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ../Keywords.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../System.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../SSassemblage.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../Reaction.h ../Temperature.h +Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Temperature.h ../phreeqc/phqalloc.h +Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h +Calculate_value.o: ../Calculate_value.cpp ../Calculate_value.h \ + ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h ../phreeqc/phrqtype.h +Calculate_values\ .o: ../Calculate_values\ .cpp ../Calculate_values.h \ + ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h ../Parser.h \ + ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../PBasic.h +Calculate_values.o: ../Calculate_values.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Calculate_values.h \ + ../Calculate_value.h ../Parser.h ../PBasic.h +ChartHandler.o: ../ChartHandler.cpp +ChartObject.o: ../ChartObject.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../NameDouble.h ../Parser.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h \ - ../KineticsComp.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ + ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h CurveObject.o: ../CurveObject.cpp ../CurveObject.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h + ../Parser.h ../Keywords.h ../PHRQ_io.h Keywords.o: ../Keywords.cpp ../Keywords.h +Logk.o: ../Logk.cpp ../Logk.h ../phreeqc/phrqtype.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../PHRQ_io.h ../Keywords.h ../phreeqc/phqalloc.h ../NameDouble.h \ - ../Parser.h + ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../NameDouble.h ../Parser.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../Exchange.h ../ExchComp.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../GasPhase.h ../SSassemblage.h ../cxxKinetics.h \ - ../KineticsComp.h ../phreeqc/phqalloc.h ../PBasic.h -PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ + ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h \ + ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h +PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../phreeqc/NA.h + ../Parser.h ../Keywords.h ../PHRQ_io.h ../phreeqc/NA.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../Keywords.h + ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../Parser.h ../phreeqc/../PHRQ_base.h \ - ../phreeqc/../Keywords.h ../phreeqc/../PBasic.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ + ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/../PBasic.h ../phreeqc/../Exchange.h \ + ../phreeqc/../NumKeyword.h ../phreeqc/../ExchComp.h \ + ../phreeqc/../NameDouble.h ../phreeqc/../GasPhase.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../GasComp.h +ChartObject.o: ../phreeqc/ChartObject.cpp cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h @@ -523,56 +582,91 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h -input.o: ../phreeqc/input.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h +gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../GasPhase.h \ + ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../GasComp.h +input.o: ../phreeqc/input.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -kinetics.o: ../phreeqc/kinetics.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h ../StorageBin.h ../System.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Reaction.h \ - ../NumKeyword.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h +kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ + ../Phreeqc_class.h ../Reaction.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ ../PPassemblage.h ../PPassemblageComp.h ../Surface.h ../SurfaceComp.h \ ../SurfaceCharge.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../SSassemblage.h ../Temperature.h ../phreeqc/nvector_serial.h -mainsubs.o: ../phreeqc/mainsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h ../PBasic.h + ../GasComp.h ../SSassemblage.h ../Temperature.h \ + ../phreeqc/nvector_serial.h +mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../ExchComp.h ../GasPhase.h \ + ../Phreeqc_class.h ../GasComp.h ../Reaction.h +model_aw_fraction.o: ../phreeqc/model_aw_fraction.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../Parser.h ../GasPhase.h ../Phreeqc_class.h \ + ../GasComp.h +model\ with\ ah2o.o: ../phreeqc/model\ with\ ah2o.cpp ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h nvector_serial.o: ../phreeqc/nvector_serial.cpp \ @@ -583,69 +677,83 @@ parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../Parser.h pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -prep.o: ../phreeqc/prep.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h +prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -print.o: ../phreeqc/print.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h +print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../GasComp.h ../Reaction.h +read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -read.o: ../phreeqc/read.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h ../Pressure.h ../NumKeyword.h \ - ../Parser.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Phreeqc.h ../phreeqc/phqalloc.h ../Pressure.h ../Temperature.h \ + ../Parser.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../GasPhase.h ../Phreeqc_class.h ../GasComp.h ../Reaction.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h ../phreeqc/phrqtype.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../PHRQ_io.h \ - ../phreeqc/../SSassemblageSS.h ../Phreeqc.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/phrqtype.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../SSassemblageSS.h \ + ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../Parser.h smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h @@ -653,71 +761,80 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h ../StorageBin.h ../System.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../Solution.h \ - ../NumKeyword.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SSassemblageSS.h ../NameDouble.h -structures.o: ../phreeqc/structures.cpp ../Phreeqc.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ + ../Parser.h ../Phreeqc_class.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SSassemblageSS.h ../NameDouble.h ../Temperature.h \ + ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h +structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/../cxxMix.h ../phreeqc/../NumKeyword.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Exchange.h \ - ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../Parser.h ../phreeqc/../Keywords.h ../phreeqc/../GasPhase.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../cxxKinetics.h \ - ../phreeqc/../KineticsComp.h ../phreeqc/../PPassemblage.h \ - ../phreeqc/../PPassemblageComp.h ../phreeqc/../PPassemblageComp.h \ - ../phreeqc/../Reaction.h ../phreeqc/../Solution.h \ - ../phreeqc/../SolutionIsotopeList.h ../phreeqc/../SolutionIsotope.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../GasComp.h ../Reaction.h ../phreeqc/../cxxKinetics.h \ + ../phreeqc/../NumKeyword.h ../phreeqc/../KineticsComp.h \ + ../phreeqc/../NameDouble.h ../phreeqc/../PHRQ_base.h \ + ../phreeqc/../PPassemblage.h ../phreeqc/../PPassemblageComp.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../PPassemblageComp.h \ + ../phreeqc/../Solution.h ../phreeqc/../SolutionIsotopeList.h \ + ../phreeqc/../SolutionIsotope.h ../phreeqc/../Parser.h \ ../phreeqc/../PHRQ_io.h ../phreeqc/../SolutionIsotopeList.h \ ../phreeqc/../SSassemblage.h ../phreeqc/../SSassemblageSS.h \ ../phreeqc/../Surface.h ../phreeqc/../SurfaceComp.h \ ../phreeqc/../SurfaceCharge.h ../phreeqc/../SurfaceComp.h \ - ../phreeqc/../SurfaceCharge.h ../phreeqc/../Temperature.h \ - ../phreeqc/../StorageBin.h ../phreeqc/../System.h + ../phreeqc/../SurfaceCharge.h ../phreeqc/../StorageBin.h \ + ../phreeqc/../System.h sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h -tally.o: ../phreeqc/tally.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -tidy.o: ../phreeqc/tidy.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -transport.o: ../phreeqc/transport.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../phreeqc/global_structures.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ +tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ + ../Reaction.h +tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ + ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h +transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../GasPhase.h ../Phreeqc_class.h ../GasComp.h +utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug diff --git a/Utils.h b/Utils.h index 913a02ab..89ac681d 100644 --- a/Utils.h +++ b/Utils.h @@ -6,6 +6,7 @@ #include // std::ostream #include // std::istream #include // std::map +#include "Parser.h" namespace Utilities { From 16e007620718b15346515e6e48bb050fbe4a8e12 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Jan 2012 18:05:26 +0000 Subject: [PATCH 0394/1077] eof handling in cleanup_after_parser. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5973 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Parser.h b/Parser.h index 5bf84a01..2a1be2bb 100644 --- a/Parser.h +++ b/Parser.h @@ -217,6 +217,7 @@ class CParser: public PHRQ_base CParser::TOKEN_TYPE get_rest_of_line(std::string &token); static CParser::TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); CParser::TOKEN_TYPE peek_token(); + PHRQ_io::LINE_TYPE get_m_line_type(void) const {return this->m_line_type;} /** Function reads an element name out of the equation string. From 90934690e396fe4f9c3bfbffbe5997b3253617d4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Jan 2012 22:50:46 +0000 Subject: [PATCH 0395/1077] started removing SKIP fixed exch_kin_related bug, by commenting exchange code in quick_setup (prep). Will have to test if this works. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5977 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 34 ---------------------- Phreeqc.h | 84 ++----------------------------------------------------- 2 files changed, 2 insertions(+), 116 deletions(-) diff --git a/Parser.h b/Parser.h index 2a1be2bb..784a9dd8 100644 --- a/Parser.h +++ b/Parser.h @@ -26,16 +26,6 @@ class CParser: public PHRQ_base // std::ostream & error, PHRQ_io *io=NULL); virtual ~ CParser(); -#ifdef SKIP - enum LINE_TYPE - { - LT_EOF = -1, - LT_OK = 1, - LT_EMPTY = 2, - LT_KEYWORD = 3, - LT_OPTION = 8 - }; -#endif enum TOKEN_TYPE { TT_EMPTY = 2, @@ -58,13 +48,6 @@ class CParser: public PHRQ_base OPT_KEYWORD = -2, OPT_EOF = -1 }; -#ifdef SKIP - enum ONERROR_TYPE - { - OT_CONTINUE = 0, - OT_STOP = 1 - }; -#endif enum ECHO_OPTION { EO_NONE = 0, @@ -167,27 +150,10 @@ class CParser: public PHRQ_base return m_line_iss; } int incr_input_error(); - //std::ostream & get_output() - //{ - // return m_output_stream; - //} int get_input_error() { return m_input_error; } -#ifdef SKIP - std::istream::pos_type tellg() - { - return m_input_stream.tellg(); - } - std::istream& seekg(std::istream::pos_type p) - { - return m_input_stream.seekg(p); - } -#endif - - - /** Copies from begin to token until first space is encountered. diff --git a/Phreeqc.h b/Phreeqc.h index f5581cd1..ab7a794c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -857,74 +857,13 @@ protected: int elt_list_print(struct elt_list *elt_list_ptr); struct elt_list *elt_list_save(void); cxxNameDouble elt_list_NameDouble(void); -#ifdef SKIP public: - struct exchange *exchange_alloc(void); - struct exchange *exchange_bsearch(int k, int *n); -protected: - int exchange_comp_compare(const void *ptr1, const void *ptr2); - void exchange_comp_init(struct exch_comp *exch_comp_ptr); -public: - int exchange_copy(struct exchange *exchange_old_ptr, - struct exchange *exchange_new_ptr, int n_user_new); -protected: - static int exchange_compare(const void *ptr1, const void *ptr2); - int exchange_copy_to_last(int n, int n_user); - int exchange_delete(int n_user_old); - int exchange_duplicate(int n_user_old, int n_user_new); - int exchange_init(struct exchange *exchange_ptr, int n_user, int n_user_end, - const char *description); -public: - int exchange_free(struct exchange *exchange_ptr); -protected: - int exchange_ptr_to_user(struct exchange *exchange_old_ptr, int n_user_new); - struct exchange *exchange_replicate(struct exchange *exchange_old_ptr, - int n_user_new); - struct exchange *exchange_search(int n_user, int *n, int print); - int exchange_sort(void); -#endif - //static int gas_comp_compare(const void *ptr1, const void *ptr2); -public: -#ifdef SKIP - struct gas_phase *gas_phase_alloc(void); - struct gas_phase *gas_phase_bsearch(int k, int *n); -protected: - static int gas_phase_compare(const void *ptr1, const void *ptr2); -public: - int gas_phase_copy(struct gas_phase *gas_phase_old_ptr, - struct gas_phase *gas_phase_new_ptr, int n_user_new); -protected: - int gas_phase_copy_to_last(int n, int n_user); - int gas_phase_delete(int n_user_old); - int gas_phase_duplicate(int n_user_old, int n_user_new); - int gas_phase_init(struct gas_phase *gas_phase_ptr, int n_user, - int n_user_end, char *description); -public: - int gas_phase_free(struct gas_phase *gas_phase_ptr); - int gas_phase_ptr_to_user(struct gas_phase *gas_phase_ptr_old, - int n_user_new); - struct gas_phase *gas_phase_replicate(struct gas_phase *gas_phase_old_ptr, - int n_user_new); - struct gas_phase *gas_phase_search(int n_user, int *n); - int gas_phase_sort(void); -#endif enum entity_type get_entity_enum(char *name); struct inverse *inverse_alloc(void); int inverse_delete(int i); static int inverse_isotope_compare(const void *ptr1, const void *ptr2); struct inverse *inverse_search(int n_user, int *n); int inverse_sort(void); -#ifdef SKIP - struct irrev *irrev_bsearch(int k, int *n); - int irrev_copy(struct irrev *irrev_old_ptr, struct irrev *irrev_new_ptr, - int n_user_new); - int irrev_delete(int n_user_old); - int irrev_duplicate(int n_user_old, int n_user_new); - int irrev_free(struct irrev *irrev_ptr); - struct irrev *irrev_search(int n_user, int *n); - int irrev_ptr_to_user(struct irrev *irrev_ptr_old, int n_user_new); - int irrev_sort(void); -#endif public: struct kinetics *kinetics_alloc(void); struct kinetics *kinetics_bsearch(int k, int *n); @@ -1391,13 +1330,6 @@ protected: /* ---------------------------------------------------------------------- * Exchange * ---------------------------------------------------------------------- */ -#ifdef SKIP - struct exchange *exchange; - struct exchange *dbg_exchange; - int count_exchange; - int max_exchange; -#endif - std::map Rxn_exchange_map; /* ---------------------------------------------------------------------- @@ -1451,29 +1383,17 @@ protected: *---------------------------------------------------------------------- */ std::map Rxn_mix_map; std::map Dispersion_mix_map; - //std::map Stagnant_mix_map; - //struct mix *mix; - //struct mix *dbg_mix; - //int count_mix; /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ std::map Rxn_reaction_map; -#ifdef SKIP - struct irrev *irrev; - struct irrev *dbg_irrev; - int count_irrev; -#endif + /*---------------------------------------------------------------------- * Gas phase *---------------------------------------------------------------------- */ std::map Rxn_gas_phase_map; -#ifdef SKIP - int count_gas_phase; - int max_gas_phase; - struct gas_phase *gas_phase; -#endif + /*---------------------------------------------------------------------- * Solid solution *---------------------------------------------------------------------- */ From 18eba6bd38ae6341b7d7fab10f369227f980f889 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Jan 2012 16:36:31 +0000 Subject: [PATCH 0396/1077] cleaning up bugs with exchange git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5978 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 1 + GasPhase.cxx | 4 ++++ Parser.cxx | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Exchange.cxx b/Exchange.cxx index 21160896..d620561a 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -437,6 +437,7 @@ cxxExchange::Get_exchComps(void) { return (this->exchComps); } + const cxxNameDouble & cxxExchange::Get_totals() const { diff --git a/GasPhase.cxx b/GasPhase.cxx index 47c2cc1c..c663b408 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -30,6 +30,7 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) n_solution = -999; type = cxxGasPhase::GP_PRESSURE; total_p = 1.0; + total_moles = 0.0; volume = 1.0; v_m = 0; pr_in = false; @@ -310,7 +311,10 @@ cxxGasPhase::read_raw(CParser & parser, bool check) } else { + CParser::ECHO_OPTION eo = parser.get_echo_file(); + parser.set_echo_file(CParser::EO_NONE); opt = parser.getOptionFromLastLine(vopts, next_char); + parser.set_echo_file(eo); } if (opt == CParser::OPT_DEFAULT) { diff --git a/Parser.cxx b/Parser.cxx index fdf8f99d..a283023a 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1245,7 +1245,7 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, pos_ptr = 0; copy_token(option, pos_ptr); next_pos = pos_ptr; - if (true) // pr.echo_input == TRUE + if (this->echo_file) // pr.echo_input == TRUE { if (true) // database_file == NULL { From 7257281b55355950dc39a72b763cc517b526b2de Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Jan 2012 17:06:45 +0000 Subject: [PATCH 0397/1077] Fixed bug in read_gas_phase_modify, appended components already in list. Removed #SKIP from basicsubs.cpp, gases.cpp, input.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5979 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index c663b408..529973a1 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -403,7 +403,19 @@ cxxGasPhase::read_raw(CParser & parser, bool check) } else { - this->gas_comps.push_back(gc); + size_t i; + for (i = 0; i < this->gas_comps.size(); i++) + { + if (this->gas_comps[i].Get_phase_name() == gc.Get_phase_name()) + { + this->gas_comps[i] = gc; + break; + } + } + if (i >= this->gas_comps.size()) + { + this->gas_comps.push_back(gc); + } } //opt_save = 4; useLastLine = true; From 9758c574e4681dba6c94628ab3a27994822c941b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Jan 2012 19:39:34 +0000 Subject: [PATCH 0398/1077] Last of SKIPs In parser, do not echo if using last line. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5982 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 21 - ExchComp.h | 1 - Exchange.cxx | 26 -- Exchange.h | 1 - Parser.cxx | 3 +- Phreeqc.cpp | 28 +- Reaction.cxx | 37 -- Reaction.h | 1 - ReadClass.cxx | 1139 ------------------------------------------------- cxxMix.cxx | 23 - cxxMix.h | 1 - dumper.cpp | 225 ---------- 12 files changed, 4 insertions(+), 1502 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 2a52469b..b01b1b0f 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -38,27 +38,6 @@ cxxExchComp::cxxExchComp(PHRQ_io *io) formula_z = 0.0; } #ifdef SKIP -cxxExchComp::cxxExchComp(struct exch_comp * exch_comp_ptr, PHRQ_io *io) - // - // constructor for cxxExchComp from struct exch_comp - // -: -PHRQ_base(io), -formula_totals(exch_comp_ptr->formula_totals), totals(exch_comp_ptr->totals) -{ - this->Set_formula(exch_comp_ptr->formula); - moles = exch_comp_ptr->moles; - // totals in constructor - //formula_totals in constructor - la = exch_comp_ptr->la; - charge_balance = exch_comp_ptr->charge_balance; - this->Set_phase_name(exch_comp_ptr->phase_name); - phase_proportion = exch_comp_ptr->phase_proportion; - this->Set_rate_name(exch_comp_ptr->rate_name); - formula_z = exch_comp_ptr->formula_z; -} -#endif -#ifdef SKIP cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, std::vector < double >&f_vector) // diff --git a/ExchComp.h b/ExchComp.h index e01202c6..efdfe2c7 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -14,7 +14,6 @@ class cxxExchComp: public PHRQ_base public: cxxExchComp(PHRQ_io *io=NULL); - //cxxExchComp(struct exch_comp *, PHRQ_io *io=NULL); ~cxxExchComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/Exchange.cxx b/Exchange.cxx index d620561a..922d5470 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -31,32 +31,6 @@ cxxExchange::cxxExchange(PHRQ_io *io) n_solution = -999; pitzer_exchange_gammas = true; } -#ifdef SKIP -cxxExchange::cxxExchange(struct exchange * exchange_ptr, PHRQ_io *io) - // - // constructor for cxxExchange from struct exchange - // -: -cxxNumKeyword(io) -{ - int i; - - this->Set_description(exchange_ptr->description); - n_user = exchange_ptr->n_user; - n_user_end = exchange_ptr->n_user_end; - pitzer_exchange_gammas = (exchange_ptr->pitzer_exchange_gammas == TRUE); - for (i = 0; i < exchange_ptr->count_comps; i++) - { - cxxExchComp ec(&(exchange_ptr->comps[i]), this->Get_io()); - std::string str(ec.Get_formula()); - exchComps[str] = ec; - } - - - - -} -#endif cxxExchange::cxxExchange(const std::map < int, cxxExchange > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) diff --git a/Exchange.h b/Exchange.h index 743a5154..9c4221c2 100644 --- a/Exchange.h +++ b/Exchange.h @@ -16,7 +16,6 @@ class cxxExchange:public cxxNumKeyword public: cxxExchange(PHRQ_io *io=NULL); - //cxxExchange(struct exchange *, PHRQ_io *io=NULL); cxxExchange(const std::map < int, cxxExchange > &exchange_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxExchange(); diff --git a/Parser.cxx b/Parser.cxx index a283023a..45dd80bc 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1245,7 +1245,8 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, pos_ptr = 0; copy_token(option, pos_ptr); next_pos = pos_ptr; - if (this->echo_file) // pr.echo_input == TRUE + //if (this->echo_file) // pr.echo_input == TRUE + if (false) { if (true) // database_file == NULL { diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 11c7c810..514d3591 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -195,16 +195,7 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(r_ptr.Get_elementList(), 1.0); } } -#ifdef SKIP - { - for (i = 0; i < count_irrev; i++) - { - reaction_calc(&irrev[i]); - cxxReaction entity(&irrev[i]); - accumulator.add_extensive(entity.Get_elementList(), 1.0); - } - } -#endif + // pure phases for (i = 0; i < count_pp_assemblage; i++) { @@ -214,14 +205,6 @@ size_t Phreeqc::list_components(std::list &list_c) } // exchangers -#ifdef SKIP - for (i = 0; i < count_exchange; i++) - { - cxxExchange entity(&exchange[i], phrq_io); - entity.totalize(); - accumulator.add_extensive(entity.Get_totals(), 1.0); - } -#endif { std::map::const_iterator cit = Rxn_exchange_map.begin(); for (; cit != Rxn_exchange_map.end(); cit++) @@ -250,14 +233,7 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(entity.Get_totals(), 1.0); } } -#ifdef SKIP - for (i = 0; i < count_gas_phase; i++) - { - cxxGasPhase entity(&gas_phase[i], phrq_io); - entity.totalize(this); - accumulator.add_extensive(entity.Get_totals(), 1.0); - } -#endif + // solid-solutions for (i = 0; i < count_s_s_assemblage; i++) { diff --git a/Reaction.cxx b/Reaction.cxx index 0bf19517..eede6263 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -29,43 +29,6 @@ cxxReaction::cxxReaction(PHRQ_io *io) reactantList.type = cxxNameDouble::ND_NAME_COEF; elementList.type = cxxNameDouble::ND_ELT_MOLES; } -#ifdef SKIP -cxxReaction::cxxReaction(struct irrev *irrev_ptr, PHRQ_io *io) - // - // constructor for cxxReaction from struct irrev - // - : -cxxNumKeyword(io), -reactantList(irrev_ptr->list, irrev_ptr->count_list), -elementList(irrev_ptr->elts) -{ - int i; - - this->Set_description(irrev_ptr->description); - this->n_user = irrev_ptr->n_user; - this->n_user_end = irrev_ptr->n_user_end; - this->Set_units(irrev_ptr->units); - // steps - if (irrev_ptr->count_steps < 0) - { - for (i = 0; i < 1; i++) - { - this->steps.push_back(irrev_ptr->steps[i]); - } - this->countSteps = -irrev_ptr->count_steps; - this->equalIncrements = true; - } - else - { - for (i = 0; i < irrev_ptr->count_steps; i++) - { - this->steps.push_back(irrev_ptr->steps[i]); - } - this->countSteps = irrev_ptr->count_steps; - this->equalIncrements = false; - } -} -#endif cxxReaction::~cxxReaction() { } diff --git a/Reaction.h b/Reaction.h index 2060ae06..5b3ffe28 100644 --- a/Reaction.h +++ b/Reaction.h @@ -15,7 +15,6 @@ class cxxReaction:public cxxNumKeyword public: cxxReaction(PHRQ_io *io = NULL); - //cxxReaction(struct irrev *, PHRQ_io *io = NULL); ~cxxReaction(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; diff --git a/ReadClass.cxx b/ReadClass.cxx index 8c2b59ff..072f9d53 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -116,113 +116,6 @@ read_solution_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_exchange_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads EXCHANGE_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("exchange_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxExchange ex(phrq_io); - ex.read_raw(parser); - int n_user = ex.Get_n_user(); - int n_user_end = ex.Get_n_user_end(); - ex.Set_n_user_end(n_user); - Rxn_exchange_map[n_user] = ex; - if (n_user_end > n_user) - { - for (int i = n_user + 1; i <= n_user_end; i++) - { - Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); - } - } - -#ifdef SKIP - //struct exchange *exchange_ptr = ex.cxxExchange2exchange(PHREEQC_THIS); - struct exchange *exchange_ptr = cxxExchange2exchange(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (exchange_bsearch(exchange_ptr->n_user, &n) != NULL) - { - exchange_free(&exchange[n]); - exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); - } - else - { - n = count_exchange++; - if (count_exchange >= max_exchange) - { - space((void **) ((void *) &(exchange)), count_exchange, - &max_exchange, sizeof(struct exchange)); - } - exchange_copy(exchange_ptr, &exchange[n], exchange_ptr->n_user); - exchange_sort(); - } - exchange_free(exchange_ptr); - free_check_null(exchange_ptr); -#endif - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_raw(void) @@ -597,363 +490,6 @@ read_solid_solutions_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_gas_phase_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads GAS_PHASE_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("gas_phase_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxGasPhase entity(phrq_io); - entity.read_raw(parser); - - Rxn_gas_phase_map[entity.Get_n_user()] = entity; - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_gas_phase_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads GAS_PHASE_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("gas_phase_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxGasPhase ex(phrq_io); - ex.read_raw(parser); - //struct gas_phase *gas_phase_ptr = ex.cxxGasPhase2gas_phase(PHREEQC_THIS); - struct gas_phase *gas_phase_ptr = cxxGasPhase2gas_phase(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (gas_phase_bsearch(gas_phase_ptr->n_user, &n) != NULL) - { - gas_phase_free(&gas_phase[n]); - gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); - } - else - { - n = count_gas_phase++; - if (count_gas_phase >= max_gas_phase) - { - space((void **) ((void *) &(gas_phase)), count_gas_phase, - &max_gas_phase, sizeof(struct gas_phase)); - } - gas_phase_copy(gas_phase_ptr, &gas_phase[n], gas_phase_ptr->n_user); - gas_phase_sort(); - } - gas_phase_free(gas_phase_ptr); - free_check_null(gas_phase_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_reaction_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads REACTION_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("reaction_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxReaction ex; - ex.read_raw(parser, true); - //struct irrev *irrev_ptr = ex.cxxReaction2irrev(PHREEQC_THIS); - struct irrev *irrev_ptr = cxxReaction2irrev(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (irrev_bsearch(irrev_ptr->n_user, &n) != NULL) - { - irrev_free(&irrev[n]); - irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); - } - else - { - n = count_irrev++; - irrev = - (struct irrev *) PHRQ_realloc(irrev, - (size_t) count_irrev * - sizeof(struct irrev)); - if (irrev == NULL) - malloc_error(); - irrev_copy(irrev_ptr, &irrev[n], irrev_ptr->n_user); - irrev_sort(); - } - irrev_free(irrev_ptr); - free_check_null(irrev_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_mix_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads MIX (_RAW) data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("mix_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - std::ostringstream oss_out; - std::ostringstream oss_err; - - CParser parser(iss_in, oss_out, oss_err, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxMix ex(phrq_io); - ex.read_raw(parser); - //struct mix *mix_ptr = ex.cxxMix2mix(PHREEQC_THIS); - struct mix *mix_ptr = cxxMix2mix(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (mix_bsearch(mix_ptr->n_user, &n) != NULL) - { - mix_free(&mix[n]); - mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); - } - else - { - n = count_mix++; - mix = - (struct mix *) PHRQ_realloc(mix, - (size_t) count_mix * - sizeof(struct mix)); - if (mix == NULL) - malloc_error(); - mix_copy(mix_ptr, &mix[n], mix_ptr->n_user); - mix_sort(); - } - mix_free(mix_ptr); - free_check_null(mix_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -1290,150 +826,6 @@ read_equilibrium_phases_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_exchange_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads EXCHANGE_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find exchange number - char token[MAX_LENGTH]; - char *next; - int l, n_user; - next = line; - copy_token(token, &next, &l); - if (copy_token(token, &next, &l) != DIGIT) - { - input_error++; - error_string = sformatf( "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - cxxExchange * entity = Utilities::Rxn_find(Rxn_exchange_map, n_user); - if (entity == NULL) - { - input_error++; - error_string = sformatf( "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - entity->read_raw(parser, false); - - /* recalculate formula_totals */ - std::map::iterator cit = entity->Get_exchComps().begin(); - for ( ; cit != entity->Get_exchComps().end(); cit++) - { - char * temp_formula = string_duplicate(cit->second.Get_formula().c_str()); - char *ptr = temp_formula; - - count_elts = 0; - paren_count = 0; - get_elts_in_species(&ptr, 1.0); - - cxxNameDouble nd(elt_list_save()); - //exchange[n].comps[i].formula_totals = elt_list_save(); - //free_check_null(temp_formula); - cit->second.Set_formula_totals(elt_list_save()); - } - - - -#ifdef SKIP - if (exchange_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Exchange %d not found for EXCHANGE_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxExchange entity(&(exchange[n]), phrq_io); - entity.read_raw(parser, false); - - // save entity - //struct exchange *entity_ptr = entity.cxxExchange2exchange(PHREEQC_THIS); - struct exchange *entity_ptr = cxxExchange2exchange(&entity); - exchange_free(&(exchange[n])); - exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); - - /* tidy description and n_user_end */ - free_check_null(exchange[n].description); - exchange[n].description = string_duplicate(entity_ptr->description); - exchange[n].n_user_end = exchange[n].n_user; - - /* recalculate formula_totals */ - int i; - for (i = 0; i < exchange[n].count_comps; i++) - { - count_elts = 0; - paren_count = 0; - char * temp_formula = string_duplicate(exchange[n].comps[i].formula); - char *ptr = temp_formula; - get_elts_in_species(&ptr, 1.0); - free_check_null(exchange[n].comps[i].formula_totals); - exchange[n].comps[i].formula_totals = elt_list_save(); - free_check_null(temp_formula); - } - - - //exchange[n].new_def = TRUE; - exchange_free(entity_ptr); - free_check_null(entity_ptr); -#endif - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_modify(void) @@ -1610,175 +1002,6 @@ read_solid_solutions_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_gas_phase_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads GAS_PHASE_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - // find gas_phase number - char token[MAX_LENGTH]; - char *next; - int l, n_user; - next = line; - copy_token(token, &next, &l); - if (copy_token(token, &next, &l) != DIGIT) - { - input_error++; - error_string = sformatf( "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - cxxGasPhase *gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, n_user); - if (gas_phase_ptr == NULL) - { - input_error++; - error_string = sformatf( "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - gas_phase_ptr->read_raw(parser, false); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_gas_phase_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads GAS_PHASE_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - // find gas_phase 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++; - error_string = sformatf( "Expected gas_phase number following GAS_PHASE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - std::ostringstream oss_out; - std::ostringstream oss_err; - CParser parser(iss_in, oss_out, oss_err, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (gas_phase_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Gas_phase %d not found for GAS_PHASE_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxGasPhase entity(&(gas_phase[n]), phrq_io); - entity.read_raw(parser, false); - // save entity - //struct gas_phase *entity_ptr = entity.cxxGasPhase2gas_phase(PHREEQC_THIS); - struct gas_phase *entity_ptr = cxxGasPhase2gas_phase(&entity); - gas_phase_free(&(gas_phase[n])); - gas_phase_copy(entity_ptr, &(gas_phase[n]), entity_ptr->n_user); - free_check_null(gas_phase[n].description); - gas_phase[n].description = string_duplicate(entity_ptr->description); - gas_phase_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_modify(void) @@ -1867,94 +1090,6 @@ read_kinetics_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_reaction_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads REACTION_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - // find gas_phase 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++; - error_string = sformatf( "Expected reaction number following REACTION_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (irrev_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Reaction %d not found for REACTION_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxReaction entity(&(irrev[n])); - entity.read_raw(parser, false); - // save entity - //struct irrev *entity_ptr = entity.cxxReaction2irrev(PHREEQC_THIS); - struct irrev *entity_ptr = cxxReaction2irrev(&entity); - irrev_free(&(irrev[n])); - irrev_copy(entity_ptr, &(irrev[n]), entity_ptr->n_user); - free_check_null(irrev[n].description); - irrev[n].description = string_duplicate(entity_ptr->description); - irrev_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: streamify_to_next_keyword(std::istringstream & lines) @@ -2122,29 +1257,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_exchange().Get_defined()) - { - if (delete_info.Get_exchange().Get_numbers().size() == 0) - { - for (i = 0; i < count_exchange; i++) - { - exchange_delete(exchange[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_exchange().Get_numbers().begin(); it != delete_info.Get_exchange().Get_numbers().end(); it++) - { - if (exchange_bsearch(*it, &n) != NULL) - { - exchange_delete(*it); - } - } - } - } -#endif // surfaces if (delete_info.Get_surface().Get_defined()) { @@ -2207,29 +1319,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_gas_phase().Get_defined()) - { - if (delete_info.Get_gas_phase().Get_numbers().size() == 0) - { - for (i = 0; i < count_gas_phase; i++) - { - gas_phase_delete(gas_phase[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_gas_phase().Get_numbers().begin(); it != delete_info.Get_gas_phase().Get_numbers().end(); it++) - { - if (gas_phase_bsearch(*it, &n) != NULL) - { - gas_phase_delete(*it); - } - } - } - } -#endif // kineticss if (delete_info.Get_kinetics().Get_defined()) { @@ -2268,29 +1357,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_mix().Get_defined()) - { - if (delete_info.Get_mix().Get_numbers().size() == 0) - { - for (i = 0; i < count_mix; i++) - { - mix_delete(mix[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_mix().Get_numbers().begin(); it != delete_info.Get_mix().Get_numbers().end(); it++) - { - if (mix_bsearch(*it, &n) != NULL) - { - mix_delete(*it); - } - } - } - } -#endif // reactions if (delete_info.Get_reaction().Get_defined()) { @@ -2307,29 +1373,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_reaction().Get_defined()) - { - if (delete_info.Get_reaction().Get_numbers().size() == 0) - { - for (i = 0; i < count_irrev; i++) - { - irrev_delete(irrev[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_reaction().Get_numbers().begin(); it != delete_info.Get_reaction().Get_numbers().end(); it++) - { - if (irrev_bsearch(*it, &n) != NULL) - { - irrev_delete(*it); - } - } - } - } -#endif // temperatures if (delete_info.Get_temperature().Get_defined()) { @@ -2665,32 +1708,7 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_exchange()) - { - if (dump_info.Get_exchange().size() == 0) - { - for (i = 0; i < count_exchange; i++) - { - cxxExchange cxxentity(&exchange[i], phrq_io); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_exchange().begin(); it != dump_info.Get_exchange().end(); it++) - { - if (exchange_bsearch(*it, &n) != NULL) - { - cxxExchange cxxentity(&exchange[n], phrq_io); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // surfaces if (dump_info.Get_bool_surface()) { @@ -2764,32 +1782,7 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_gas_phase()) - { - if (dump_info.Get_gas_phase().size() == 0) - { - for (i = 0; i < count_gas_phase; i++) - { - cxxGasPhase cxxentity(&gas_phase[i], phrq_io); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_gas_phase().begin(); it != dump_info.Get_gas_phase().end(); it++) - { - if (gas_phase_bsearch(*it, &n) != NULL) - { - cxxGasPhase cxxentity(&gas_phase[n], phrq_io); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // kinetics if (dump_info.Get_bool_kinetics()) { @@ -2837,32 +1830,7 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_mix()) - { - if (dump_info.Get_mix().size() == 0) - { - for (i = 0; i < count_mix; i++) - { - cxxMix cxxentity(&mix[i], phrq_io); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_mix().begin(); it != dump_info.Get_mix().end(); it++) - { - if (mix_bsearch(*it, &n) != NULL) - { - cxxMix cxxentity(&mix[n], phrq_io); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // reaction if (dump_info.Get_bool_reaction()) { @@ -2884,32 +1852,7 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_reaction()) - { - if (dump_info.Get_reaction().size() == 0) - { - for (i = 0; i < count_irrev; i++) - { - cxxReaction cxxentity(&irrev[i]); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_reaction().begin(); it != dump_info.Get_reaction().end(); it++) - { - if (irrev_bsearch(*it, &n) != NULL) - { - cxxReaction cxxentity(&irrev[n]); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // temperature if (dump_info.Get_bool_temperature()) { @@ -3015,85 +1958,3 @@ read_user_graph_handler(void) return (return_value); } #endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_generic(Keywords::KEYWORDS key) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads _raw and _modify data blocks - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - std::string token; - char *next; - int n_user; - next = line; - copy_token(token, &next); - if (copy_token(token, &next) != DIGIT) - { - input_error++; - error_string = sformatf( "Expected reactant number following keyword.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token.c_str(),"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - switch (key) - { - case Keywords::KEY_REACTION_PRESSURE_RAW: - { - cxxPressure entity(this->phrq_io); - entity.read_raw(parser); - if (entity.Get_base_error_count() == 0) - { - Rxn_pressure_map[n_user] = entity; - } - // Make copies if necessary - Utilities::Rxn_copies(Rxn_pressure_map, entity.Get_n_user(), entity.Get_n_user_end()); - } - break; - } - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif \ No newline at end of file diff --git a/cxxMix.cxx b/cxxMix.cxx index e3ecf318..6e7a28e5 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -26,30 +26,7 @@ cxxMix::cxxMix(PHRQ_io *io) : cxxNumKeyword(io) { } -#ifdef SKIP -cxxMix::cxxMix(struct mix *mix_ptr, PHRQ_io *io) - // - // constructor for cxxMix from struct mix - // - : -cxxNumKeyword(io) -{ - int i; - this->Set_description(mix_ptr->description); - this->n_user = mix_ptr->n_user; - this->n_user_end = mix_ptr->n_user_end; - // comps - if (mix_ptr->count_comps > 0) - { - for (i = 0; i < mix_ptr->count_comps; i++) - { - this->mixComps[mix_ptr->comps[i].n_solution] = - mix_ptr->comps[i].fraction; - } - } -} -#endif cxxMix::~cxxMix() { } diff --git a/cxxMix.h b/cxxMix.h index b966700d..97871bc7 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -15,7 +15,6 @@ class cxxMix:public cxxNumKeyword public: cxxMix(PHRQ_io *io=NULL); - //cxxMix(struct mix *, PHRQ_io *io=NULL); ~cxxMix(); //void dump_xml(std::ostream& os, unsigned int indent = 0)const; diff --git a/dumper.cpp b/dumper.cpp index 84e574ac..748e2c94 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -255,231 +255,6 @@ bool dumper::Read(CParser & parser) return(return_value); } -#ifdef SKIP -bool dumper::Read(CParser & parser) -{ - - bool return_value(true); - static std::vector < std::string > vopts; - if (vopts.empty()) - { - vopts.reserve(20); - vopts.push_back("solution"); - vopts.push_back("solutions"); - vopts.push_back("pp_assemblage"); - vopts.push_back("pp_assemblages"); - vopts.push_back("equilibrium_phase"); - vopts.push_back("equilibrium_phases"); - vopts.push_back("exchange"); - vopts.push_back("surface"); - vopts.push_back("s_s_assemblage"); - vopts.push_back("solid_solution"); - vopts.push_back("solid_solutions"); - vopts.push_back("gas_phase"); - vopts.push_back("gas_phases"); - vopts.push_back("kinetics"); - vopts.push_back("file"); - vopts.push_back("append"); - vopts.push_back("all"); - vopts.push_back("cell"); - vopts.push_back("cells"); // 18 - vopts.push_back("mix"); // 19 - vopts.push_back("reaction"); // 20 - vopts.push_back("reactions"); // 21 - vopts.push_back("temperature"); // 22 - vopts.push_back("reaction_temperature"); // 23 - vopts.push_back("reaction_temperatures"); // 24 - vopts.push_back("pressure"); // 25 - vopts.push_back("reaction_pressure"); // 26 - vopts.push_back("reaction_pressures"); // 27 - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); - - // Read mix number and description - //this->read_number_description(parser); - - opt_save = CParser::OPT_DEFAULT; - - for (;;) - { - int opt; - StorageBinListItem cells; - opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPT_DEFAULT) - { - opt = opt_save; - } - else - { - opt_save = opt; - } - - // Select StorageBinListItem - StorageBinListItem *item = NULL; - switch (opt) - { - case 0: - case 1: - item = &(this->binList.Get_solution()); - break; - case 2: - case 3: - case 4: - case 5: - item = &(this->binList.Get_pp_assemblage()); - break; - case 6: - item = &(this->binList.Get_exchange()); - break; - case 7: - item = &(this->binList.Get_surface()); - break; - case 8: - case 9: - case 10: - item = &(this->binList.Get_s_s_assemblage()); - break; - case 11: - case 12: - item = &(this->binList.Get_gas_phase()); - break; - case 13: - item = &(this->binList.Get_kinetics()); - break; - case 17: // cell - case 18: // cells - item = &cells; - break; - case 19: // mix - item = &(this->binList.Get_mix()); - break; - case 20: // reaction - case 21: // reactions - item = &(this->binList.Get_reaction()); - break; - case 22: // temperature - case 23: // reaction_temperature - case 24: // reaction_temperatures - item = &(this->binList.Get_temperature()); - break; - case 25: // pressure - case 26: // reaction_pressure - case 27: // reaction_pressures - item = &(this->binList.Get_pressure()); - break; - default: - break; - } - - // Read dump entity list of numbers or number ranges for line, store in item - if ((opt >= 0 && opt <= 13) || (opt >= 17 && opt <= 28)) - { - for (;;) - { - CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - if (j == CParser::TT_DIGIT) - { - item->Augment(token); - } - else if (j == CParser::TT_EMPTY) - { - item->Augment(token); - break; - } - else - { - parser.error_msg("Expected single number or range of numbers.", - PHRQ_io::OT_CONTINUE); - } - } - } - - if (opt == 17 || opt == 18) - { - this->binList.TransferAll(cells); - } - // Process other identifiers - std::set < int >::iterator it; - switch (opt) - { - case CParser::OPT_EOF: - break; - case CParser::OPT_KEYWORD: - break; - - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 17: - case 18: - case 19: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 26: - case 27: - break; - case 14: //file - std::getline(parser.get_iss(), this->file_name); - this->file_name = trim(this->file_name, " \t"); - if (this->file_name.size() == 0) - { - this->file_name = "dump.out"; - } - - break; - case 15: //append - { - parser.copy_token(token, next_char); - //if (!(parser.get_iss() >> this->append)) - this->append = true; - if (token.c_str()[0] == 'f' || token.c_str()[0] == 'F') - { - this->append = false; - } - } - break; - case 16: //all - this->SetAll(true); - break; - default: - case CParser::OPT_DEFAULT: - case CParser::OPT_ERROR: - opt = CParser::OPT_EOF; - parser.error_msg("Unknown input reading DUMP definition.", - PHRQ_io::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; - return_value = false; - break; - } - - - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } - return(return_value); -} -#endif bool dumper::Get_bool_any(void) { return ( From 67eb82710734346a294dba269640277622df0e43 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Jan 2012 21:56:25 +0000 Subject: [PATCH 0399/1077] Tony's updates relative to 5941. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5986 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index ab7a794c..535e2009 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -547,9 +547,9 @@ public: int build_solution_phase_boundaries(void); int build_species_list(int n); int build_min_surface(void); - LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE P); + LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); LDBLE calc_delta_v(reaction * r_ptr, bool phase); - int calc_vm(LDBLE tc); + int calc_vm(LDBLE tc,LDBLE pa); int change_hydrogen_in_elt_list(LDBLE charge); int clear(void); int convert_units(struct solution *solution_ptr); @@ -1467,6 +1467,7 @@ protected: LDBLE patm_x; bool numerical_fixed_volume; bool force_numerical_fixed_volume; + bool switch_numerical; LDBLE ph_x; LDBLE solution_pe_x; LDBLE mu_x; From d0c049ed5df095339967b13358b74f3ac4290178 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 5 Jan 2012 22:02:04 +0000 Subject: [PATCH 0400/1077] windows log functions passed git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5988 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index 943b26e0..67f81859 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -65,7 +65,7 @@ public: bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void log_flush(void); void log_close(void); - void log_msg(const char * str); + virtual void log_msg(const char * str); void Set_log_ostream(std::ostream * out) {this->log_ostream = out;}; std::ostream *Get_log_ostream(void) {return this->log_ostream;}; void Set_log_on(bool tf) {this->log_on = tf;}; From e295db8b6ec85a4191cfd4f1ea7a7a271d3d4eb4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Jan 2012 23:21:02 +0000 Subject: [PATCH 0401/1077] New files git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5992 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasComp.cxx | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++ GasComp.h | 48 +++++++++++ 2 files changed, 282 insertions(+) create mode 100644 GasComp.cxx create mode 100644 GasComp.h diff --git a/GasComp.cxx b/GasComp.cxx new file mode 100644 index 00000000..845b97a8 --- /dev/null +++ b/GasComp.cxx @@ -0,0 +1,234 @@ +// ExchComp.cxx: implementation of the cxxExchComp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include // std::cout std::cerr +#include // assert +#include // std::sort +#include + +#include "Utils.h" // define first +#include "Phreeqc.h" +#include "GasComp.h" +#include "phqalloc.h" + + + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxGasComp::cxxGasComp(PHRQ_io *io) + // + // default constructor for cxxExchComp + // + : PHRQ_base(io) +{ + p_read = 0.0; + moles = 0.0; + initial_moles = 0.0; +} + +cxxGasComp::~cxxGasComp() +{ +} + +void +cxxGasComp::dump_raw(std::ostream & s_oss, unsigned int indent) const +{ + //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + /* + std::string phase_name; + std::string name; + LDBLE p_read; + LDBLE moles; + LDBLE initial_moles; // Exch_Comp element and attributes + */ + s_oss << indent0 << "-phase_name " << this->phase_name << "\n"; + //s_oss << indent0 << "-name " << this->name << "\n"; + s_oss << indent0 << "-p_read " << this->p_read << "\n"; + s_oss << indent0 << "-moles " << this->moles << "\n"; + s_oss << indent0 << "-initial_moles " << this->initial_moles << "\n"; + + //s_oss << indent1 << "# critical values" << "\n"; + +} + +bool +cxxGasComp::read_raw(CParser & parser, bool check) +{ + std::string str; + + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("phase_name"); // 0 + vopts.push_back("name"); // 1 + vopts.push_back("p_read"); // 2 + vopts.push_back("moles"); // 3 + vopts.push_back("initial_moles"); // 4 + } + int errors = parser.get_input_error(); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool phase_name_defined(false); + bool moles_defined(false); + int opt; + for (;;) + { + opt = parser.get_option(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_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in EXCH_COMP read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + break; + + case 0: // phase_name + if (!(parser.get_iss() >> str)) + { + this->phase_name.clear(); + parser.incr_input_error(); + parser.error_msg("Expected string value for phase_name.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->phase_name = str; + } + phase_name_defined = true; + break; + + case 1: // name + if (!(parser.get_iss() >> str)) + { + this->phase_name.clear(); + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->phase_name = str; + } + break; + + case 2: // p_read + if (!(parser.get_iss() >> this->p_read)) + { + this->p_read = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial partial pressure.", + PHRQ_io::OT_CONTINUE); + } + break; + + case 3: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + PHRQ_io::OT_CONTINUE); + } + moles_defined = true; + break; + + case 4: // initial_moles + if (!(parser.get_iss() >> this->initial_moles)) + { + this->initial_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial_moles.", + PHRQ_io::OT_CONTINUE); + } + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + if (check) + { + // members that must be defined + if (phase_name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Phase_name not defined for GasComp input.", + PHRQ_io::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for GasComp input.", + PHRQ_io::OT_CONTINUE); + } + } + return (parser.get_input_error() == errors); +} +void +cxxGasComp::add(const cxxGasComp & addee, LDBLE extensive) +{ + LDBLE ext1, ext2, f1, f2; + if (extensive == 0.0) + return; + if (addee.phase_name.size() == 0) + return; + + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } + + assert(this->phase_name == addee.phase_name); + + //double moles; + this->p_read += addee.p_read * extensive; + this->moles += addee.moles * extensive; + this->initial_moles += addee.initial_moles * extensive; +} + +void +cxxGasComp::multiply(LDBLE extensive) +{ + this->p_read *= extensive; + this->moles *= extensive; + this->initial_moles *= extensive; +} + diff --git a/GasComp.h b/GasComp.h new file mode 100644 index 00000000..6182c49d --- /dev/null +++ b/GasComp.h @@ -0,0 +1,48 @@ +#if !defined(GASCOMP_H_INCLUDED) +#define GASCOMP_H_INCLUDED + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "NameDouble.h" + +class cxxGasComp: public PHRQ_base +{ + + public: + cxxGasComp(PHRQ_io *io=NULL); + + ~cxxGasComp(); + + + void dump_raw(std::ostream & s_oss, unsigned int indent) const; + + bool read_raw(CParser & parser, bool check=true); + + std::string Get_phase_name(void) const {return this->phase_name;} + void Set_phase_name(std::string s) {this->phase_name = s;} + LDBLE Get_p_read() const {return this->p_read;} + void Set_p_read(LDBLE t) {this->p_read = t;} + LDBLE Get_moles() const {return this->moles;} + void Set_moles(LDBLE t) {this->moles = t;} + LDBLE Get_initial_moles() const {return this->initial_moles;} + void Set_initial_moles(LDBLE t) {this->initial_moles = t;} + + void add(const cxxGasComp & addee, LDBLE extensive); + void cxxGasComp::multiply(LDBLE extensive); + +#ifdef USE_MPI + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif + protected: + std::string phase_name; + LDBLE p_read; + LDBLE moles; + LDBLE initial_moles; +}; + +#endif // !defined(GASCOMP_H_INCLUDED) From 1ed24bf1c727d66c4de8e79bf43bea1c3fd55dbd Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 5 Jan 2012 23:49:45 +0000 Subject: [PATCH 0402/1077] added GasComp.cxx to unit project; fixed typo in GasPhase.cxx git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5993 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index 529973a1..8c138d40 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -394,7 +394,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) cxxGasComp gc; //bool tf = gc.read_raw(parser, next_char); //if (!tf - if (!gc.read_raw(parser, next_char)) + if (!gc.read_raw(parser, false)) { parser.incr_input_error(); parser.error_msg From ff5fc98ae4aa30ee119892eda768c9f65b7f22ff Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 6 Jan 2012 00:11:00 +0000 Subject: [PATCH 0403/1077] removed extra qualification cxxGasComp:: on member multiply git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5994 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasComp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GasComp.h b/GasComp.h index 6182c49d..6eb55c42 100644 --- a/GasComp.h +++ b/GasComp.h @@ -32,7 +32,7 @@ class cxxGasComp: public PHRQ_base void Set_initial_moles(LDBLE t) {this->initial_moles = t;} void add(const cxxGasComp & addee, LDBLE extensive); - void cxxGasComp::multiply(LDBLE extensive); + void multiply(LDBLE extensive); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); From 48639132978fd83855dde81739c95297dd3617c5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 Jan 2012 16:38:58 +0000 Subject: [PATCH 0404/1077] pp_assemblage is mostly working. Need final checking git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5996 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.cxx | 47 +++++++++++++++++++++++++++++++------------ PPassemblage.h | 18 +++++++++++++---- PPassemblageComp.cxx | 4 ++-- PPassemblageComp.h | 44 +++++++++++++++++++++------------------- Phreeqc.cpp | 20 +++++++++++++----- Phreeqc.h | 39 ++++++++++++++++++++--------------- ReadClass.cxx | 48 +++++++++++++++++++++++++++++++++++++++----- 7 files changed, 154 insertions(+), 66 deletions(-) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 8093e0af..e1e937cc 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -26,7 +26,7 @@ cxxPPassemblage::cxxPPassemblage(PHRQ_io * io) { eltList.type = cxxNameDouble::ND_ELT_MOLES; } - +#ifdef SKIP cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr, PHRQ_io * io) // // constructor for cxxPPassemblage from struct PPassemblage @@ -48,7 +48,7 @@ eltList(pp_assemblage_ptr->next_elt) this->ppAssemblageComps[str] = ppComp; } } - +#endif cxxPPassemblage::cxxPPassemblage(const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): @@ -101,7 +101,7 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "::const_iterator it = - ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { (*it).second.dump_xml(s_oss, indent + 2); } @@ -135,7 +135,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) // ppAssemblagComps for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = - ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { s_oss << indent1; s_oss << "-component" << "\n"; @@ -220,9 +220,9 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->ppAssemblageComps.find(ec.Get_name()) != this->ppAssemblageComps.end()) + if (this->pp_assemblage_comps.find(ec.Get_name()) != this->pp_assemblage_comps.end()) { - cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ec.Get_name())->second; + cxxPPassemblageComp & comp = this->pp_assemblage_comps.find(ec.Get_name())->second; comp.read_raw(reread, false); } else @@ -230,7 +230,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) cxxPPassemblageComp ppComp1(this->Get_io()); ppComp1.read_raw(reread, false); std::string str(ppComp1.Get_name()); - this->ppAssemblageComps[str] = ppComp1; + this->pp_assemblage_comps[str] = ppComp1; } } useLastLine = true; @@ -294,7 +294,7 @@ cxxPPassemblage::totalize(PHREEQC_PTR_ARG) this->totals.clear(); // component structures for (std::map < std::string, cxxPPassemblageComp >::iterator it = - ppAssemblageComps.begin(); it != ppAssemblageComps.end(); ++it) + pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { (*it).second.totalize(P_INSTANCE); this->totals.add_extensive((*it).second.Get_totals(), 1.0); @@ -311,13 +311,13 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) if (extensive == 0.0) return; //std::list ppAssemblageComps; - for (std::map < std::string, cxxPPassemblageComp >::const_iterator itadd = addee.ppAssemblageComps.begin(); - itadd != addee.ppAssemblageComps.end(); ++itadd) + for (std::map < std::string, cxxPPassemblageComp >::const_iterator itadd = addee.pp_assemblage_comps.begin(); + itadd != addee.pp_assemblage_comps.end(); ++itadd) { bool found = false; for (std::map < std::string, cxxPPassemblageComp >::iterator it = - this->ppAssemblageComps.begin(); - it != this->ppAssemblageComps.end(); ++it) + this->pp_assemblage_comps.begin(); + it != this->pp_assemblage_comps.end(); ++it) { if ((*it).second.Get_name() == itadd->second.Get_name()) { @@ -331,10 +331,31 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) cxxPPassemblageComp entity = (*itadd).second; entity.multiply(extensive); std::string str(entity.Get_name()); - this->ppAssemblageComps[str] = entity; + this->pp_assemblage_comps[str] = entity; } } //cxxNameDouble eltList; this->eltList.add_extensive(addee.eltList, extensive); } +cxxPPassemblageComp * cxxPPassemblage:: +Find(const std::string name_in) +{ + std::string name(name_in); + Utilities::str_tolower(name); + + cxxPPassemblageComp * comp = NULL; + std::map::iterator it; + it = this->pp_assemblage_comps.begin(); + for ( ; it != this->pp_assemblage_comps.end(); it++) + { + std::string pname(it->first); + Utilities::str_tolower(pname); + if (name == pname) + { + comp = &it->second; + break; + } + } + return comp; +} \ No newline at end of file diff --git a/PPassemblage.h b/PPassemblage.h index f0d6c8eb..9a7d9eaf 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -17,7 +17,7 @@ class cxxPPassemblage:public cxxNumKeyword public: cxxPPassemblage(PHRQ_io * io=NULL); - cxxPPassemblage(struct pp_assemblage *, PHRQ_io * io=NULL); + //cxxPPassemblage(struct pp_assemblage *, PHRQ_io * io=NULL); cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxPPassemblage(); @@ -34,10 +34,19 @@ class cxxPPassemblage:public cxxNumKeyword { return this->eltList; }; - const std::map & Get_ppAssemblageComps() const + void Set_eltList(cxxNameDouble & nd) {this->eltList = nd;} + std::map & Get_pp_assemblage_comps() { - return this->ppAssemblageComps; + return this->pp_assemblage_comps; }; + void Set_pp_assemblage_comps(std::map & c) + { + this->pp_assemblage_comps = c; + }; + bool Get_new_def(void) const {return this->new_def;} + void Set_new_def(bool tf) {this->new_def = tf;} + + cxxPPassemblageComp *Find(const std::string name); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); @@ -51,7 +60,8 @@ protected: void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: - std::map ppAssemblageComps; + bool new_def; + std::map pp_assemblage_comps; cxxNameDouble eltList; cxxNameDouble totals; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 373bdfca..ce0cfc2b 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -33,7 +33,7 @@ PHRQ_base(io) dissolve_only = false; precipitate_only = false; } - +#ifdef SKIP cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) : PHRQ_base(io) @@ -52,7 +52,7 @@ PHRQ_base(io) dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); } - +#endif cxxPPassemblageComp::~cxxPPassemblageComp() { } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 0dbfd400..2186b96a 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -15,16 +15,14 @@ class cxxPPassemblageComp: public PHRQ_base public: cxxPPassemblageComp(PHRQ_io *io=NULL); - cxxPPassemblageComp(struct pure_phase *, PHRQ_io *io=NULL); + //cxxPPassemblageComp(struct pure_phase *, PHRQ_io *io=NULL); ~cxxPPassemblageComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - const std::string &Get_name() const - { - return this->name; - } + + const std::string &Get_name() const {return this->name;} void Set_name(const char * s) { if(s != NULL) @@ -32,10 +30,7 @@ class cxxPPassemblageComp: public PHRQ_base else this->name.clear(); } - const std::string &Get_add_formula() const - { - return this->add_formula; - } + const std::string &Get_add_formula() const {return this->add_formula;} void Set_add_formula(const char * s) { if(s != NULL) @@ -45,18 +40,25 @@ class cxxPPassemblageComp: public PHRQ_base } void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & Get_totals() const - { - return (this->totals); - }; - double Get_si() const {return this->si;}; - double Get_si_org() const {return this->si_org;}; - double Get_moles() const {return this->moles;}; - double Get_delta() const {return this->delta;}; - double Get_initial_moles() const {return this->initial_moles;}; - bool Get_force_equality() const {return this->force_equality;}; - bool Get_dissolve_only() const {return this->dissolve_only;}; - bool Get_precipitate_only() const {return this->precipitate_only;}; + const cxxNameDouble & Get_totals() const {return (this->totals);} + void Get_totals(cxxNameDouble & nd) {this->totals = nd;} + double Get_si() const {return this->si;} + void Set_si(LDBLE t) {this->si = t;} + double Get_si_org() const {return this->si_org;} + void Set_si_org(LDBLE t) {this->si_org = t;} + double Get_moles() const {return this->moles;} + void Set_moles(LDBLE t) {this->moles = t;} + double Get_delta() const {return this->delta;} + void Set_delta(LDBLE t) {this->delta = t;} + double Get_initial_moles() const {return this->initial_moles;} + void Set_initial_moles(LDBLE t) {this->initial_moles = t;} + + bool Get_force_equality() const {return this->force_equality;} + void Set_force_equality(bool tf) {this->force_equality = tf;} + bool Get_dissolve_only() const {return this->dissolve_only;} + void Set_dissolve_only(bool tf) {this->dissolve_only = tf;} + bool Get_precipitate_only() const {return this->precipitate_only;} + void Set_precipitate_only(bool tf) {this->precipitate_only = tf;} void add(const cxxPPassemblageComp & comp, double extensive); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 514d3591..18440592 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -197,13 +197,23 @@ size_t Phreeqc::list_components(std::list &list_c) } // pure phases + { + std::map::const_iterator cit = Rxn_pp_assemblage_map.begin(); + for (; cit != Rxn_pp_assemblage_map.end(); cit++) + { + cxxPPassemblage entity = cit->second; + entity.totalize(this); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } + } +#ifdef SKIP for (i = 0; i < count_pp_assemblage; i++) { cxxPPassemblage entity(&pp_assemblage[i], phrq_io); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } - +#endif // exchangers { std::map::const_iterator cit = Rxn_exchange_map.begin(); @@ -319,7 +329,7 @@ void Phreeqc::init(void) LOG_10 = log(10.0); max_solution = MAX_SOLUTION; - max_pp_assemblage = MAX_PP_ASSEMBLAGE; + //max_pp_assemblage = MAX_PP_ASSEMBLAGE; //max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; @@ -339,7 +349,7 @@ void Phreeqc::init(void) max_master_isotope = MAX_ELTS; count_solution = 0; - count_pp_assemblage = 0; + //count_pp_assemblage = 0; //count_exchange = 0; count_surface = 0; //count_gas_phase = 0; @@ -391,7 +401,7 @@ void Phreeqc::init(void) dump_in = FALSE; transport_warnings = TRUE; - pp_assemblage = 0; + //pp_assemblage = 0; //exchange = 0; surface = 0; //gas_phase = 0; @@ -712,7 +722,7 @@ void Phreeqc::init(void) dbg_solution = solution; //dbg_exchange = exchange; dbg_surface = surface; - dbg_pp_assemblage = pp_assemblage; + //dbg_pp_assemblage = pp_assemblage; dbg_kinetics = kinetics; //dbg_irrev = irrev; //dbg_mix = mix; diff --git a/Phreeqc.h b/Phreeqc.h index 535e2009..a29c36a9 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -130,7 +130,7 @@ public: LDBLE total_mole(const char *total_name); //int system_total_solids(struct exchange *exchange_ptr, int system_total_solids(cxxExchange *exchange_ptr, - struct pp_assemblage *pp_assemblage_ptr, + cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, struct s_s_assemblage *s_s_assemblage_ptr, struct surface *surface_ptr); @@ -700,7 +700,8 @@ public: int read_named_logk(void); int read_phases(void); int read_print(void); - int read_pure_phases(void); + //int read_pure_phases(void); + int read_pp_assemblage(void); int read_rates(void); int read_reaction(void); //int read_reaction_reactants(struct irrev *irrev_ptr); @@ -737,7 +738,7 @@ public: int read_solution_raw(void); //int read_exchange_raw(void); int read_surface_raw(void); - int read_equilibrium_phases_raw(void); + //int read_equilibrium_phases_raw(void); int read_kinetics_raw(void); int read_solid_solutions_raw(void); //int read_gas_phase_raw(void); @@ -746,7 +747,7 @@ public: //int read_temperature_raw(void); int read_dump(void); int read_solution_modify(void); - int read_equilibrium_phases_modify(void); + //int read_equilibrium_phases_modify(void); //int read_exchange_modify(void); int read_surface_modify(void); int read_solid_solutions_modify(void); @@ -824,7 +825,8 @@ public: int add_kinetics(struct kinetics *kinetics_ptr); //int add_mix(struct mix *mix_ptr); int add_mix(cxxMix * mix_ptr); - int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + //int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); //int add_reaction(struct irrev *irrev_ptr, int step_number, // LDBLE step_fraction); int add_reaction(cxxReaction *reaction_ptr, int step_number, @@ -833,9 +835,11 @@ public: int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); - int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + //int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); int gas_phase_check(cxxGasPhase *gas_phase_ptr); - int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); + //int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); + int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); //int reaction_calc(struct irrev *irrev_ptr); int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); @@ -922,6 +926,7 @@ protected: int phase_delete(int i); struct phase *phase_store(const char *name); public: +#ifdef SKIP struct pp_assemblage *pp_assemblage_alloc(void); struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); protected: @@ -947,6 +952,7 @@ protected: struct pp_assemblage *pp_assemblage_search(int n_user, int *n); int pp_assemblage_sort(void); static int pure_phase_compare(const void *ptr1, const void *ptr2); +#endif struct rate *rate_bsearch(char *ptr, int *j); int rate_free(struct rate *rate_ptr); struct rate *rate_search(const char *name, int *n); @@ -1069,7 +1075,7 @@ public: static int phase_compare_string(const void *ptr1, const void *ptr2); int phase_free(struct phase *phase_ptr); int phase_init(struct phase *phase_ptr); - static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); + //static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); static int rate_compare(const void *ptr1, const void *ptr2); static int rate_compare_string(const void *ptr1, const void *ptr2); struct species *s_alloc(void); @@ -1101,8 +1107,8 @@ public: //struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); //struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); //struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); - struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); - struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); + //struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); + //struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); @@ -1404,11 +1410,11 @@ protected: /*---------------------------------------------------------------------- * Pure-phase assemblage *---------------------------------------------------------------------- */ - - int count_pp_assemblage; - int max_pp_assemblage; - struct pp_assemblage *pp_assemblage; - struct pp_assemblage *dbg_pp_assemblage; + std::map Rxn_pp_assemblage_map; + //int count_pp_assemblage; + //int max_pp_assemblage; + //struct pp_assemblage *pp_assemblage; + //struct pp_assemblage *dbg_pp_assemblage; /*---------------------------------------------------------------------- * Species_list *---------------------------------------------------------------------- */ @@ -1899,8 +1905,9 @@ public: M_Env kinetics_machEnv; N_Vector kinetics_y, kinetics_abstol; void *kinetics_cvode_mem; - struct pp_assemblage *cvode_pp_assemblage_save; + //struct pp_assemblage *cvode_pp_assemblage_save; struct s_s_assemblage *cvode_s_s_assemblage_save; + cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; LDBLE *m_temp; int set_and_run_attempt; diff --git a/ReadClass.cxx b/ReadClass.cxx index 072f9d53..292a7374 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -207,7 +207,7 @@ read_surface_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_equilibrium_phases_raw(void) @@ -302,7 +302,7 @@ read_equilibrium_phases_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_raw(void) @@ -734,7 +734,7 @@ read_solution_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_equilibrium_phases_modify(void) @@ -826,6 +826,7 @@ read_equilibrium_phases_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_modify(void) @@ -1218,6 +1219,22 @@ delete_entities(void) } // pp_assemblages + if (delete_info.Get_pp_assemblage().Get_defined()) + { + if (delete_info.Get_pp_assemblage().Get_numbers().size() == 0) + { + Rxn_pp_assemblage_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_pp_assemblage().Get_numbers().begin(); it != delete_info.Get_pp_assemblage().Get_numbers().end(); it++) + { + Rxn_pp_assemblage_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_pp_assemblage().Get_defined()) { if (delete_info.Get_pp_assemblage().Get_numbers().size() == 0) @@ -1240,7 +1257,7 @@ delete_entities(void) } } } - +#endif // exchangers if (delete_info.Get_exchange().Get_defined()) { @@ -1662,6 +1679,27 @@ dump_ostream(std::ostream& os) } // pp_assemblages + if (dump_info.Get_bool_pp_assemblage()) + { + if (dump_info.Get_pp_assemblage().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_pp_assemblage_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_pp_assemblage().begin(); it != dump_info.Get_pp_assemblage().end(); it++) + { + cxxPPassemblage *p = Utilities::Rxn_find(Rxn_pp_assemblage_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_pp_assemblage()) { if (dump_info.Get_pp_assemblage().size() == 0) @@ -1686,7 +1724,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // exchanges if (dump_info.Get_bool_exchange()) { From 2590f549809cd36fbdf27b78590a90e225e378c3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 Jan 2012 18:43:00 +0000 Subject: [PATCH 0405/1077] Bug fixes for pp_assemblage git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5998 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblageComp.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index ce0cfc2b..fae4aece 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -26,7 +26,7 @@ PHRQ_base(io) { si = 0; si_org = 0; - moles = 0; + moles = 10; delta = 0; initial_moles = 0; force_equality = false; From 3458661f90c0ec1ccff35e934c7c2053c9573dd7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 Jan 2012 20:42:21 +0000 Subject: [PATCH 0406/1077] bug with case for phase name in surf_related_pz git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@5999 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 18440592..912334b5 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -706,7 +706,7 @@ void Phreeqc::init(void) } pitzer_pe = FALSE; - + count_pp = count_pg = count_s_s = 0; // used in store_get_equi_reactants /* * SIT */ From 89153db83990f5e763d5985e4fbbbae28df2d9eb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Jan 2012 05:19:21 +0000 Subject: [PATCH 0407/1077] turn off warnings for dll linkage for std::list git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6010 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PHRQ_io.h b/PHRQ_io.h index 67f81859..0089c2d0 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -167,9 +167,19 @@ protected: bool screen_on; ECHO_OPTION echo_destination; +#if defined(_MSC_VER) +/* disable warning C4251: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' */ +#pragma warning(disable:4251) +#endif + std::list istream_list; std::list delete_istream_list; +#if defined(_MSC_VER) +/* reset warning C4251 */ +#pragma warning(default:4251) +#endif + // input data members Keywords::KEYWORDS m_next_keyword; std::string m_line; From 619e7824a6753469703aa6d00e8170410c6ed0e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jan 2012 17:07:49 +0000 Subject: [PATCH 0408/1077] Tony's 1/10/12 changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6017 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index a29c36a9..8eb3af89 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -136,7 +136,7 @@ public: struct surface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); - + static LDBLE f_Vm(LDBLE v1, void *cookie); // chart.cpp #if defined PHREEQ98 void DeleteCurves(void); @@ -549,10 +549,15 @@ public: int build_min_surface(void); LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); LDBLE calc_delta_v(reaction * r_ptr, bool phase); - int calc_vm(LDBLE tc,LDBLE pa); + //LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(); + int calc_vm(LDBLE tc, LDBLE pa); int change_hydrogen_in_elt_list(LDBLE charge); int clear(void); int convert_units(struct solution *solution_ptr); + LDBLE a_aa_sum, b2, b_sum, R_TK; + LDBLE f_Vm(LDBLE v1); struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr); @@ -570,9 +575,6 @@ public: int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn); - //LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); - LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); - LDBLE calc_PR(); int setup_pure_phases(void); int adjust_setup_pure_phases(void); int setup_related_surface(void); From f0855460916129ef25313f7686bf9467e64f9b0b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jan 2012 19:10:05 +0000 Subject: [PATCH 0409/1077] Renaming SSassemblageSS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6018 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 8 ++++---- Phreeqc.h | 30 +++++++++++++++--------------- ReadClass.cxx | 34 +++++++++++++++++----------------- SSassemblageSS.cxx => SS.cxx | 0 SSassemblageSS.h => SS.h | 0 SSassemblage.cxx | 2 +- SSassemblage.h | 2 +- Solution.cxx | 12 ++++++------ StorageBin.cxx | 16 ++++++++-------- StorageBinList.cpp | 8 ++++---- StorageBinList.h | 4 ++-- dumper.cpp | 2 +- 12 files changed, 59 insertions(+), 59 deletions(-) rename SSassemblageSS.cxx => SS.cxx (100%) rename SSassemblageSS.h => SS.h (100%) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 912334b5..d6bc11f1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -247,7 +247,7 @@ size_t Phreeqc::list_components(std::list &list_c) // solid-solutions for (i = 0; i < count_s_s_assemblage; i++) { - cxxSSassemblage entity(&s_s_assemblage[i]); + cxxSSassemblage entity(&ss_assemblage[i]); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } @@ -406,7 +406,7 @@ void Phreeqc::init(void) surface = 0; //gas_phase = 0; kinetics = 0; - s_s_assemblage = 0; + ss_assemblage = 0; cell_data = 0; elements = 0; elt_list = 0; @@ -544,7 +544,7 @@ void Phreeqc::init(void) */ last_model.exchange = NULL; last_model.gas_phase = NULL; - last_model.s_s_assemblage = NULL; + last_model.ss_assemblage = NULL; last_model.kinetics = NULL; last_model.pp_assemblage = NULL; last_model.add_formula = NULL; @@ -601,7 +601,7 @@ void Phreeqc::init(void) pr.initial_exchangers = TRUE; pr.reactions = TRUE; pr.gas_phase = TRUE; - pr.s_s_assemblage = TRUE; + pr.ss_assemblage = TRUE; pr.pp_assemblage = TRUE; pr.surface = TRUE; pr.exchange = TRUE; diff --git a/Phreeqc.h b/Phreeqc.h index 8eb3af89..da9fdd4f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -132,7 +132,7 @@ public: int system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, - struct s_s_assemblage *s_s_assemblage_ptr, + struct ss_assemblage *s_s_assemblage_ptr, struct surface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); @@ -833,7 +833,7 @@ public: // LDBLE step_fraction); int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - int add_s_s_assemblage(struct s_s_assemblage *s_s_assemblage_ptr); + int add_s_s_assemblage(struct ss_assemblage *s_s_assemblage_ptr); int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); @@ -845,7 +845,7 @@ public: //int reaction_calc(struct irrev *irrev_ptr); int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); - int s_s_assemblage_check(struct s_s_assemblage *s_s_assemblage_ptr); + int s_s_assemblage_check(struct ss_assemblage *s_s_assemblage_ptr); // structures.cpp ------------------------------- int clean_up(void); @@ -969,29 +969,29 @@ protected: struct species *s_search(const char *name); struct species *s_store(const char *name, LDBLE z, int replace_if_found); public: - struct s_s_assemblage *s_s_assemblage_alloc(void); - struct s_s_assemblage *s_s_assemblage_bsearch(int k, int *n); + struct ss_assemblage *s_s_assemblage_alloc(void); + struct ss_assemblage *s_s_assemblage_bsearch(int k, int *n); protected: static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); public: - int s_s_assemblage_copy(struct s_s_assemblage *s_s_assemblage_old_ptr, - struct s_s_assemblage *s_s_assemblage_new_ptr, + int s_s_assemblage_copy(struct ss_assemblage *s_s_assemblage_old_ptr, + struct ss_assemblage *s_s_assemblage_new_ptr, int n_user_new); protected: int s_s_assemblage_copy_to_last(int n, int n_user); int s_s_assemblage_duplicate(int n_user_old, int n_user_new); int s_s_assemblage_delete(int n_user_old); public: - int s_s_assemblage_free(struct s_s_assemblage *s_s_assemblage_ptr); + int s_s_assemblage_free(struct ss_assemblage *s_s_assemblage_ptr); protected: - int s_s_assemblage_init(struct s_s_assemblage *s_s_assemblage_ptr, + int s_s_assemblage_init(struct ss_assemblage *s_s_assemblage_ptr, int n_user, int n_user_end, char *description); - int s_s_assemblage_ptr_to_user(struct s_s_assemblage *s_s_assemblage_ptr_old, + int s_s_assemblage_ptr_to_user(struct ss_assemblage *s_s_assemblage_ptr_old, int n_user_new); - struct s_s_assemblage *s_s_assemblage_replicate(struct s_s_assemblage + struct ss_assemblage *s_s_assemblage_replicate(struct ss_assemblage *s_s_assemblage_old_ptr, int n_user_new); - struct s_s_assemblage *s_s_assemblage_search(int n_user, int *n); + struct ss_assemblage *s_s_assemblage_search(int n_user, int *n); int s_s_assemblage_sort(void); static int s_s_compare(const void *ptr1, const void *ptr2); struct save_values *save_values_bsearch(struct save_values *k, int *n); @@ -1114,7 +1114,7 @@ public: //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); - struct s_s_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); + struct ss_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); struct surface * cxxSurface2surface(const cxxSurface * surf); struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); @@ -1408,7 +1408,7 @@ protected: int count_s_s_assemblage; int max_s_s_assemblage; - struct s_s_assemblage *s_s_assemblage; + struct ss_assemblage *ss_assemblage; /*---------------------------------------------------------------------- * Pure-phase assemblage *---------------------------------------------------------------------- */ @@ -1908,7 +1908,7 @@ public: N_Vector kinetics_y, kinetics_abstol; void *kinetics_cvode_mem; //struct pp_assemblage *cvode_pp_assemblage_save; - struct s_s_assemblage *cvode_s_s_assemblage_save; + struct ss_assemblage *cvode_s_s_assemblage_save; cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; LDBLE *m_temp; diff --git a/ReadClass.cxx b/ReadClass.cxx index 292a7374..937e0192 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -456,8 +456,8 @@ read_solid_solutions_raw(void) cxxSSassemblage ex; ex.read_raw(parser); - //struct s_s_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); - struct s_s_assemblage *s_s_assemblage_ptr = cxxSSassemblage2s_s_assemblage(&ex); + //struct ss_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + struct ss_assemblage *s_s_assemblage_ptr = cxxSSassemblage2s_s_assemblage(&ex); int n; /* @@ -466,8 +466,8 @@ read_solid_solutions_raw(void) if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) { - s_s_assemblage_free(&s_s_assemblage[n]); - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], + s_s_assemblage_free(&ss_assemblage[n]); + s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[n], s_s_assemblage_ptr->n_user); } else @@ -475,11 +475,11 @@ read_solid_solutions_raw(void) n = count_s_s_assemblage++; if (count_s_s_assemblage >= max_s_s_assemblage) { - space((void **) ((void *) &(s_s_assemblage)), + space((void **) ((void *) &(ss_assemblage)), count_s_s_assemblage, &max_s_s_assemblage, - sizeof(struct s_s_assemblage)); + sizeof(struct ss_assemblage)); } - s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[n], + s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[n], s_s_assemblage_ptr->n_user); s_s_assemblage_sort(); } @@ -986,16 +986,16 @@ read_solid_solutions_modify(void) } // read entity - cxxSSassemblage entity(&(s_s_assemblage[n])); + cxxSSassemblage entity(&(ss_assemblage[n])); entity.read_raw(parser, false); // save entity - //struct s_s_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); - struct s_s_assemblage *entity_ptr = cxxSSassemblage2s_s_assemblage(&entity); - s_s_assemblage_free(&(s_s_assemblage[n])); - s_s_assemblage_copy(entity_ptr, &(s_s_assemblage[n]), entity_ptr->n_user); - free_check_null(s_s_assemblage[n].description); - s_s_assemblage[n].description = string_duplicate(entity_ptr->description); + //struct ss_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); + struct ss_assemblage *entity_ptr = cxxSSassemblage2s_s_assemblage(&entity); + s_s_assemblage_free(&(ss_assemblage[n])); + s_s_assemblage_copy(entity_ptr, &(ss_assemblage[n]), entity_ptr->n_user); + free_check_null(ss_assemblage[n].description); + ss_assemblage[n].description = string_duplicate(entity_ptr->description); s_s_assemblage_free(entity_ptr); free_check_null(entity_ptr); @@ -1304,7 +1304,7 @@ delete_entities(void) { for (i = 0; i < count_s_s_assemblage; i++) { - s_s_assemblage_delete(s_s_assemblage[i].n_user); + s_s_assemblage_delete(ss_assemblage[i].n_user); } } else @@ -1780,7 +1780,7 @@ dump_ostream(std::ostream& os) { for (i = 0; i < count_s_s_assemblage; i++) { - cxxSSassemblage cxxentity(&s_s_assemblage[i]); + cxxSSassemblage cxxentity(&ss_assemblage[i]); cxxentity.dump_raw(os,0); } } @@ -1792,7 +1792,7 @@ dump_ostream(std::ostream& os) if (s_s_assemblage_bsearch(*it, &n) != NULL) { - cxxSSassemblage cxxentity(&s_s_assemblage[n]); + cxxSSassemblage cxxentity(&ss_assemblage[n]); cxxentity.dump_raw(os,0); } } diff --git a/SSassemblageSS.cxx b/SS.cxx similarity index 100% rename from SSassemblageSS.cxx rename to SS.cxx diff --git a/SSassemblageSS.h b/SS.h similarity index 100% rename from SSassemblageSS.h rename to SS.h diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f0352b2e..266795b7 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -28,7 +28,7 @@ cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) { } -cxxSSassemblage::cxxSSassemblage(struct s_s_assemblage * s_s_assemblage_ptr, PHRQ_io * io) +cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * s_s_assemblage_ptr, PHRQ_io * io) // // constructor for cxxSSassemblage from struct SSassemblage // diff --git a/SSassemblage.h b/SSassemblage.h index 4b20db5a..7a123879 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -22,7 +22,7 @@ class cxxSSassemblage:public cxxNumKeyword public: cxxSSassemblage(PHRQ_io * io = NULL); - cxxSSassemblage(struct s_s_assemblage *, PHRQ_io * io = NULL); + cxxSSassemblage(struct ss_assemblage *, PHRQ_io * io = NULL); cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); diff --git a/Solution.cxx b/Solution.cxx index cbdee3ea..bd7a9df9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1637,12 +1637,12 @@ cxxSolution::Update(const cxxNameDouble &nd) // } // for (i = 0; i < count_s_s_assemblage; i++) // { -// if (s_s_assemblage[i].new_def != TRUE) +// if (ss_assemblage[i].new_def != TRUE) // { -// std::cout << "Solid solution " << s_s_assemblage[i]. +// std::cout << "Solid solution " << ss_assemblage[i]. // n_user << "\n"; // std::ostringstream oss; -// cxxSSassemblage ex(&(s_s_assemblage[i])); +// cxxSSassemblage ex(&(ss_assemblage[i])); // ex.dump_raw(oss, 0); // //std::cerr << oss.str(); // @@ -1659,10 +1659,10 @@ cxxSolution::Update(const cxxNameDouble &nd) // // ex1.read_raw(cparser); // -// struct s_s_assemblage *s_s_assemblage_ptr = +// struct ss_assemblage *s_s_assemblage_ptr = // ex1.cxxSSassemblage2s_s_assemblage(); -// s_s_assemblage_free(&s_s_assemblage[i]); -// s_s_assemblage_copy(s_s_assemblage_ptr, &s_s_assemblage[i], +// s_s_assemblage_free(&ss_assemblage[i]); +// s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[i], // s_s_assemblage_ptr->n_user); // s_s_assemblage_free(s_s_assemblage_ptr); // free_check_null(s_s_assemblage_ptr); diff --git a/StorageBin.cxx b/StorageBin.cxx index 8b38d195..935c34ea 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -799,10 +799,10 @@ cxxStorageBin::read_raw_keyword(CParser & parser) // } // // // SSassemblages -// if (system_ptr->s_s_assemblage != NULL) +// if (system_ptr->ss_assemblage != NULL) // { -// this->SSassemblages[system_ptr->s_s_assemblage->n_user] = -// cxxSSassemblage(system_ptr->s_s_assemblage); +// this->SSassemblages[system_ptr->ss_assemblage->n_user] = +// cxxSSassemblage(system_ptr->ss_assemblage); // } // // // Surfaces @@ -1016,14 +1016,14 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // SSassemblages if (this->getSSassemblage(n) != NULL) { - //system_ptr->s_s_assemblage = + //system_ptr->ss_assemblage = // (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(P_INSTANCE); - system_ptr->s_s_assemblage = + system_ptr->ss_assemblage = P_INSTANCE_POINTER cxxSSassemblage2s_s_assemblage((this->getSSassemblage(n))); } else { - system_ptr->s_s_assemblage = NULL; + system_ptr->ss_assemblage = NULL; } // Surfaces @@ -1472,7 +1472,7 @@ cxxStorageBin::Set_System(struct Use *use_ptr) this->system.Set_PPassemblage(&(it->second)); } } - // s_s_assemblage + // ss_assemblage if (use_ptr->s_s_assemblage_ptr != NULL) { std::map < int, cxxSSassemblage >::iterator it = @@ -1579,7 +1579,7 @@ cxxStorageBin::Set_System(int i) this->system.Set_PPassemblage(&(it->second)); } } - // s_s_assemblage + // ss_assemblage { std::map < int, cxxSSassemblage >::iterator it = this->SSassemblages.find(i); if (it != this->SSassemblages.end()) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 7e88348d..444af1a0 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -121,7 +121,7 @@ void StorageBinList::SetAll(bool tf) this->pp_assemblage.Clear(); this->exchange.Clear(); this->surface.Clear(); - this->s_s_assemblage.Clear(); + this->ss_assemblage.Clear(); this->gas_phase.Clear(); this->kinetics.Clear(); this->mix.Clear(); @@ -133,7 +133,7 @@ void StorageBinList::SetAll(bool tf) this->pp_assemblage.Set_defined(tf); this->exchange.Set_defined(tf); this->surface.Set_defined(tf); - this->s_s_assemblage.Set_defined(tf); + this->ss_assemblage.Set_defined(tf); this->gas_phase.Set_defined(tf); this->kinetics.Set_defined(tf); this->mix.Set_defined(tf); @@ -154,7 +154,7 @@ bool StorageBinList::Read(CParser & parser) vopts.push_back("equilibrium_phases"); vopts.push_back("exchange"); vopts.push_back("surface"); - vopts.push_back("s_s_assemblage"); + vopts.push_back("ss_assemblage"); vopts.push_back("solid_solution"); vopts.push_back("solid_solutions"); vopts.push_back("gas_phase"); @@ -323,7 +323,7 @@ void StorageBinList::TransferAll(StorageBinListItem &source) this->pp_assemblage.Augment(*it); this->exchange.Augment(*it); this->surface.Augment(*it); - this->s_s_assemblage.Augment(*it); + this->ss_assemblage.Augment(*it); this->gas_phase.Augment(*it); this->kinetics.Augment(*it); this->mix.Augment(*it); diff --git a/StorageBinList.h b/StorageBinList.h index 3101fa1a..1fb39f3b 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -37,7 +37,7 @@ public: StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; StorageBinListItem & Get_exchange(void) { return(this->exchange); }; StorageBinListItem & Get_surface(void) { return(this->surface); }; - StorageBinListItem & Get_s_s_assemblage(void) { return(this->s_s_assemblage); }; + StorageBinListItem & Get_s_s_assemblage(void) { return(this->ss_assemblage); }; StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; StorageBinListItem & Get_mix(void) { return(this->mix); }; @@ -49,7 +49,7 @@ protected: StorageBinListItem pp_assemblage; StorageBinListItem exchange; StorageBinListItem surface; - StorageBinListItem s_s_assemblage; + StorageBinListItem ss_assemblage; StorageBinListItem gas_phase; StorageBinListItem kinetics; StorageBinListItem mix; diff --git a/dumper.cpp b/dumper.cpp index 748e2c94..e5c530cf 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -50,7 +50,7 @@ bool dumper::Read(CParser & parser) vopts.push_back("equilibrium_phases"); // 10 vopts.push_back("exchange"); vopts.push_back("surface"); - vopts.push_back("s_s_assemblage"); + vopts.push_back("ss_assemblage"); vopts.push_back("solid_solution"); vopts.push_back("solid_solutions"); // 15 vopts.push_back("gas_phase"); From cbd736da15ee2e68da88834f5ab0ea0c7b0f3298 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jan 2012 19:14:07 +0000 Subject: [PATCH 0410/1077] Renaming SSassemblageSS to SS and cxxSS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6019 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 ++-- SS.cxx | 30 +++++++++++++++--------------- SS.h | 10 +++++----- SSassemblage.cxx | 28 ++++++++++++++-------------- SSassemblage.h | 6 +++--- StorageBin.cxx | 2 +- System.cxx | 2 +- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index da9fdd4f..5f89d724 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -46,7 +46,7 @@ class cxxReaction; class cxxSolution; class cxxSolutionIsotopeList; class cxxSSassemblage; -class cxxSSassemblageSS; +class cxxSS; class cxxSurface; class cxxSurfaceCharge; class cxxSurfaceComp; @@ -1115,7 +1115,7 @@ public: struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); struct ss_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); - struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSSassemblageSS > * sscomp); + struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp); struct surface * cxxSurface2surface(const cxxSurface * surf); struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); diff --git a/SS.cxx b/SS.cxx index f044bb9a..87549328 100644 --- a/SS.cxx +++ b/SS.cxx @@ -1,4 +1,4 @@ -// SSassemblageSS.cxx: implementation of the cxxSSassemblageSS class. +// SSassemblageSS.cxx: implementation of the cxxSS class. // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG @@ -8,7 +8,7 @@ #include // std::sort #include "Utils.h" // define first -#include "SSassemblageSS.h" +#include "SS.h" //#include "Dictionary.h" #include "phqalloc.h" @@ -18,11 +18,11 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -cxxSSassemblageSS::cxxSSassemblageSS(PHRQ_io *io) +cxxSS::cxxSS(PHRQ_io *io) : PHRQ_base(io) // - // default constructor for cxxSSassemblageSS + // default constructor for cxxSS // { //total_moles = 0; @@ -39,10 +39,10 @@ PHRQ_base(io) //double p[4]; } -cxxSSassemblageSS::cxxSSassemblageSS(struct s_s *s_s_ptr, PHRQ_io *io) +cxxSS::cxxSS(struct s_s *s_s_ptr, PHRQ_io *io) : PHRQ_base(io) // - // constructor for cxxSSassemblageSS from struct s_s + // constructor for cxxSS from struct s_s // { this->Set_name(s_s_ptr->name); @@ -69,13 +69,13 @@ PHRQ_base(io) // } } -cxxSSassemblageSS::~cxxSSassemblageSS() +cxxSS::~cxxSS() { } #ifdef SKIP void -cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const +cxxSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const { //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; @@ -104,7 +104,7 @@ cxxSSassemblageSS::dump_xml(std::ostream & s_oss, unsigned int indent) const con } #endif void -cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const +cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const { //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; @@ -132,7 +132,7 @@ cxxSSassemblageSS::dump_raw(std::ostream & s_oss, unsigned int indent) const } void -cxxSSassemblageSS::read_raw(CParser & parser, bool check) +cxxSS::read_raw(CParser & parser, bool check) { std::string str; @@ -420,7 +420,7 @@ cxxSSassemblageSS::read_raw(CParser & parser, bool check) #ifdef USE_MPI void -cxxSSassemblageSS::mpi_pack(std::vector < int >&ints, +cxxSS::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) { extern cxxDictionary dictionary; @@ -436,7 +436,7 @@ cxxSSassemblageSS::mpi_pack(std::vector < int >&ints, } void -cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -456,7 +456,7 @@ cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif void -cxxSSassemblageSS::totalize(PHREEQC_PTR_ARG) +cxxSS::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures @@ -480,7 +480,7 @@ cxxSSassemblageSS::totalize(PHREEQC_PTR_ARG) } void -cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive) +cxxSS::add(const cxxSS & addee, double extensive) { if (extensive == 0.0) return; @@ -499,7 +499,7 @@ cxxSSassemblageSS::add(const cxxSSassemblageSS & addee, double extensive) } void -cxxSSassemblageSS::multiply(double extensive) +cxxSS::multiply(double extensive) { //char *name; //cxxNameDouble comps; diff --git a/SS.h b/SS.h index 7f7ef0e8..4398d752 100644 --- a/SS.h +++ b/SS.h @@ -9,13 +9,13 @@ #include "NameDouble.h" #include "Phreeqc_class.h" -class cxxSSassemblageSS: public PHRQ_base +class cxxSS: public PHRQ_base { public: - cxxSSassemblageSS(PHRQ_io *io=NULL); - cxxSSassemblageSS(struct s_s *, PHRQ_io *io=NULL); - ~cxxSSassemblageSS(); + cxxSS(PHRQ_io *io=NULL); + cxxSS(struct s_s *, PHRQ_io *io=NULL); + ~cxxSS(); enum SS_PARAMETER_TYPE { @@ -65,7 +65,7 @@ class cxxSSassemblageSS: public PHRQ_base void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif - void add(const cxxSSassemblageSS & comp, double extensive); + void add(const cxxSS & comp, double extensive); void multiply(double extensive); double Get_a0() const {return (this->a0);}; double Get_a1() const {return (this->a1);}; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 266795b7..3a817e70 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -11,7 +11,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SSassemblage.h" -#include "SSassemblageSS.h" +#include "SS.h" #include "cxxMix.h" #include "phqalloc.h" @@ -41,7 +41,7 @@ cxxNumKeyword(io) n_user_end = s_s_assemblage_ptr->n_user_end; for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) { - cxxSSassemblageSS ssSS(&(s_s_assemblage_ptr->s_s[i]), this->Get_io()); + cxxSS ssSS(&(s_s_assemblage_ptr->s_s[i]), this->Get_io()); std::string str(ssSS.Get_name()); ssAssemblageSSs[str] = ssSS; } @@ -52,7 +52,7 @@ cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; - //std::list ssAssemblageSSs; + //std::list ssAssemblageSSs; // // Mix // @@ -98,7 +98,7 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const // ssAssemblageSSs s_oss << indent1; s_oss << "::const_iterator it = + for (std::list < cxxSS >::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { it->dump_xml(s_oss, indent + 2); @@ -125,7 +125,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << "\n"; // ssAssemblageSSs - for (std::map < std::string, cxxSSassemblageSS >::const_iterator it = + for (std::map < std::string, cxxSS >::const_iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { s_oss << indent1; @@ -188,7 +188,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) case 0: // solid_solution { - cxxSSassemblageSS ec(this->Get_io()); + cxxSS ec(this->Get_io()); // preliminary read parser.set_accumulate(true); @@ -200,12 +200,12 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) reread.set_echo_stream(CParser::EO_NONE); if (this->ssAssemblageSSs.find(ec.Get_name()) != this->ssAssemblageSSs.end()) { - cxxSSassemblageSS & ec1 = this->ssAssemblageSSs.find(ec.Get_name())->second; + cxxSS & ec1 = this->ssAssemblageSSs.find(ec.Get_name())->second; ec1.read_raw(reread, false); } else { - cxxSSassemblageSS ec1(this->Get_io()); + cxxSS ec1(this->Get_io()); ec1.read_raw(reread, false); std::string str(ec1.Get_name()); this->ssAssemblageSSs[str] = ec1; @@ -229,7 +229,7 @@ cxxSSassemblage::mpi_pack(std::vector < int >&ints, /* int n_user; */ ints.push_back(this->n_user); ints.push_back((int) this->ssAssemblageSSs.size()); - for (std::map < std::string, cxxSSassemblageSS >::iterator it = + for (std::map < std::string, cxxSS >::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) { @@ -253,7 +253,7 @@ cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) this->ssAssemblageSSs.clear(); for (int n = 0; n < count; n++) { - cxxSSassemblageSS ssc; + cxxSS ssc; ssc.mpi_unpack(ints, &i, doubles, &d); std::string str(ssc.get_name()); this->ssAssemblageSSs[str] = ssc; @@ -268,7 +268,7 @@ cxxSSassemblage::totalize(PHREEQC_PTR_ARG) { this->totals.clear(); // component structures - for (std::map < std::string, cxxSSassemblageSS >::iterator it = + for (std::map < std::string, cxxSS >::iterator it = ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) { (*it).second.totalize(P_INSTANCE); @@ -285,11 +285,11 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) if (extensive == 0.0) return; - for (std::map < std::string, cxxSSassemblageSS >::const_iterator itadd = + for (std::map < std::string, cxxSS >::const_iterator itadd = addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); ++itadd) { - std::map < std::string, cxxSSassemblageSS >::iterator it = + std::map < std::string, cxxSS >::iterator it = this->ssAssemblageSSs.find((*itadd).first); if (it != this->ssAssemblageSSs.end()) { @@ -297,7 +297,7 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) } else { - cxxSSassemblageSS entity = (*itadd).second; + cxxSS entity = (*itadd).second; entity.multiply(extensive); std::string str(entity.Get_name()); this->ssAssemblageSSs[str] = entity; diff --git a/SSassemblage.h b/SSassemblage.h index 7a123879..856a3b76 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -12,7 +12,7 @@ #include "NameDouble.h" #include "Phreeqc_class.h" -class cxxSSassemblageSS; +class cxxSS; //#include "cxxMix.h" class cxxMix; @@ -32,7 +32,7 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); - const std::map & Get_ssAssemblageSSs() const + const std::map & Get_ssAssemblageSSs() const { return this->ssAssemblageSSs; }; @@ -53,7 +53,7 @@ protected: void add(const cxxSSassemblage & addee, double extensive); protected: - std::map < std::string, cxxSSassemblageSS > ssAssemblageSSs; + std::map < std::string, cxxSS > ssAssemblageSSs; cxxNameDouble totals; }; diff --git a/StorageBin.cxx b/StorageBin.cxx index 935c34ea..97db04f8 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -23,7 +23,7 @@ #include "GasPhase.h" #include "cxxKinetics.h" #include "PPassemblage.h" -#include "SSassemblageSS.h" +#include "SS.h" #include "SSassemblage.h" #include "Surface.h" #include "cxxMix.h" diff --git a/System.cxx b/System.cxx index 5aa91ac2..40ce26b1 100644 --- a/System.cxx +++ b/System.cxx @@ -8,7 +8,7 @@ #include "GasPhase.h" #include "cxxKinetics.h" #include "PPassemblage.h" -#include "SSassemblageSS.h" +#include "SS.h" #include "SSassemblage.h" #include "Surface.h" #include "cxxMix.h" From 4f0fb6c92803e90934db0d1476316482361ec9c9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jan 2012 20:11:15 +0000 Subject: [PATCH 0411/1077] Finished ss_assemblage rename. Added Use class git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6020 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 8 +-- Phreeqc.h | 64 ++++++++--------- ReadClass.cxx | 70 +++++++++---------- SSassemblage.cxx | 12 ++-- Solution.cxx | 16 ++--- StorageBin.cxx | 8 +-- StorageBinList.cpp | 2 +- StorageBinList.h | 2 +- Use.cpp | 69 +++++++++++++++++++ Use.h | 168 +++++++++++++++++++++++++++++++++++++++++++++ dumper.cpp | 4 +- dumper.h | 4 +- 12 files changed, 332 insertions(+), 95 deletions(-) create mode 100644 Use.cpp create mode 100644 Use.h diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d6bc11f1..359044f9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -245,7 +245,7 @@ size_t Phreeqc::list_components(std::list &list_c) } // solid-solutions - for (i = 0; i < count_s_s_assemblage; i++) + for (i = 0; i < count_ss_assemblage; i++) { cxxSSassemblage entity(&ss_assemblage[i]); entity.totalize(this); @@ -334,7 +334,7 @@ void Phreeqc::init(void) max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; max_kinetics = MAX_PP_ASSEMBLAGE; - max_s_s_assemblage = MAX_PP_ASSEMBLAGE; + max_ss_assemblage = MAX_PP_ASSEMBLAGE; max_elements = MAX_ELEMENTS; max_elts = MAX_ELTS; @@ -354,7 +354,7 @@ void Phreeqc::init(void) count_surface = 0; //count_gas_phase = 0; count_kinetics = 0; - count_s_s_assemblage = 0; + count_ss_assemblage = 0; count_elements = 0; //count_irrev = 0; @@ -669,7 +669,7 @@ void Phreeqc::init(void) copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_s_s_assemblage.n_user = copy_s_s_assemblage.start = copy_s_s_assemblage.end = 0; + copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0; copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; copy_mix.n_user = copy_mix.start = copy_mix.end = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 5f89d724..1bcab483 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -132,7 +132,7 @@ public: int system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, - struct ss_assemblage *s_s_assemblage_ptr, + struct ss_assemblage *ss_assemblage_ptr, struct surface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); @@ -417,7 +417,7 @@ public: int xexchange_save(int n_user); int xgas_save(int n_user); int xpp_assemblage_save(int n_user); - int xs_s_assemblage_save(int n_user); + int xss_assemblage_save(int n_user); int xsurface_save(int n_user); int do_initialize(void); int do_status(void); @@ -543,7 +543,7 @@ public: int build_min_exch(void); int build_model(void); int build_pure_phases(void); - int build_s_s_assemblage(void); + int build_ss_assemblage(void); int build_solution_phase_boundaries(void); int build_species_list(int n); int build_min_surface(void); @@ -578,7 +578,7 @@ public: int setup_pure_phases(void); int adjust_setup_pure_phases(void); int setup_related_surface(void); - int setup_s_s_assemblage(void); + int setup_ss_assemblage(void); int setup_solution(void); int adjust_setup_solution(void); int setup_surface(void); @@ -627,7 +627,7 @@ public: int print_kinetics(void); int print_mix(void); int print_pp_assemblage(void); - int print_s_s_assemblage(void); + int print_ss_assemblage(void); int print_saturation_indices(void); int print_surface_cd_music(void); int print_totals(void); @@ -639,7 +639,7 @@ public: int punch_molalities(void); int punch_activities(void); int punch_pp_assemblage(void); - int punch_s_s_assemblage(void); + int punch_ss_assemblage(void); int punch_saturation_indices(void); int punch_totals(void); int punch_user_punch(void); @@ -774,7 +774,7 @@ public: int dump_mix(int k); int dump_pp_assemblage(int k); int dump_reaction(int k); - int dump_s_s_assemblage(int k); + int dump_ss_assemblage(int k); int dump_solution(int k); int dump_surface(int k); int dump_cpp(void); @@ -833,7 +833,7 @@ public: // LDBLE step_fraction); int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - int add_s_s_assemblage(struct ss_assemblage *s_s_assemblage_ptr); + int add_ss_assemblage(struct ss_assemblage *ss_assemblage_ptr); int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); @@ -845,7 +845,7 @@ public: //int reaction_calc(struct irrev *irrev_ptr); int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); - int s_s_assemblage_check(struct ss_assemblage *s_s_assemblage_ptr); + int ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr); // structures.cpp ------------------------------- int clean_up(void); @@ -969,30 +969,30 @@ protected: struct species *s_search(const char *name); struct species *s_store(const char *name, LDBLE z, int replace_if_found); public: - struct ss_assemblage *s_s_assemblage_alloc(void); - struct ss_assemblage *s_s_assemblage_bsearch(int k, int *n); + struct ss_assemblage *ss_assemblage_alloc(void); + struct ss_assemblage *ss_assemblage_bsearch(int k, int *n); protected: - static int s_s_assemblage_compare(const void *ptr1, const void *ptr2); + static int ss_assemblage_compare(const void *ptr1, const void *ptr2); public: - int s_s_assemblage_copy(struct ss_assemblage *s_s_assemblage_old_ptr, - struct ss_assemblage *s_s_assemblage_new_ptr, + int ss_assemblage_copy(struct ss_assemblage *ss_assemblage_old_ptr, + struct ss_assemblage *ss_assemblage_new_ptr, int n_user_new); protected: - int s_s_assemblage_copy_to_last(int n, int n_user); - int s_s_assemblage_duplicate(int n_user_old, int n_user_new); - int s_s_assemblage_delete(int n_user_old); + int ss_assemblage_copy_to_last(int n, int n_user); + int ss_assemblage_duplicate(int n_user_old, int n_user_new); + int ss_assemblage_delete(int n_user_old); public: - int s_s_assemblage_free(struct ss_assemblage *s_s_assemblage_ptr); + int ss_assemblage_free(struct ss_assemblage *ss_assemblage_ptr); protected: - int s_s_assemblage_init(struct ss_assemblage *s_s_assemblage_ptr, + int ss_assemblage_init(struct ss_assemblage *ss_assemblage_ptr, int n_user, int n_user_end, char *description); - int s_s_assemblage_ptr_to_user(struct ss_assemblage *s_s_assemblage_ptr_old, + int ss_assemblage_ptr_to_user(struct ss_assemblage *ss_assemblage_ptr_old, int n_user_new); - struct ss_assemblage *s_s_assemblage_replicate(struct ss_assemblage - *s_s_assemblage_old_ptr, + struct ss_assemblage *ss_assemblage_replicate(struct ss_assemblage + *ss_assemblage_old_ptr, int n_user_new); - struct ss_assemblage *s_s_assemblage_search(int n_user, int *n); - int s_s_assemblage_sort(void); + struct ss_assemblage *ss_assemblage_search(int n_user, int *n); + int ss_assemblage_sort(void); static int s_s_compare(const void *ptr1, const void *ptr2); struct save_values *save_values_bsearch(struct save_values *k, int *n); static int save_values_compare(const void *ptr1, const void *ptr2); @@ -1083,7 +1083,7 @@ public: struct species *s_alloc(void); int s_free(struct species *s_ptr); int s_init(struct species *s_ptr); - static int s_s_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); static int solution_compare(const void *ptr1, const void *ptr2); static int solution_compare_int(const void *ptr1, const void *ptr2); static int species_list_compare(const void *ptr1, const void *ptr2); @@ -1114,7 +1114,7 @@ public: //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); - struct ss_assemblage * cxxSSassemblage2s_s_assemblage(const cxxSSassemblage * ss); + struct ss_assemblage * cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss); struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp); struct surface * cxxSurface2surface(const cxxSurface * surf); struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); @@ -1188,7 +1188,7 @@ public: int tidy_phases(void); int tidy_pp_assemblage(void); int tidy_solutions(void); - int tidy_s_s_assemblage(void); + int tidy_ss_assemblage(void); int tidy_species(void); int tidy_surface(void); int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); @@ -1371,7 +1371,7 @@ protected: struct copier copy_pp_assemblage; struct copier copy_exchange; struct copier copy_surface; - struct copier copy_s_s_assemblage; + struct copier copy_ss_assemblage; struct copier copy_gas_phase; struct copier copy_kinetics; struct copier copy_mix; @@ -1406,8 +1406,8 @@ protected: * Solid solution *---------------------------------------------------------------------- */ - int count_s_s_assemblage; - int max_s_s_assemblage; + int count_ss_assemblage; + int max_ss_assemblage; struct ss_assemblage *ss_assemblage; /*---------------------------------------------------------------------- * Pure-phase assemblage @@ -1554,7 +1554,7 @@ protected: *---------------------------------------------------------------------- */ int new_model, new_exchange, new_pp_assemblage, new_surface, new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_s_s_assemblage, new_kinetics, new_copy, + new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, new_pitzer; /*---------------------------------------------------------------------- @@ -1908,7 +1908,7 @@ public: N_Vector kinetics_y, kinetics_abstol; void *kinetics_cvode_mem; //struct pp_assemblage *cvode_pp_assemblage_save; - struct ss_assemblage *cvode_s_s_assemblage_save; + struct ss_assemblage *cvode_ss_assemblage_save; cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; LDBLE *m_temp; diff --git a/ReadClass.cxx b/ReadClass.cxx index 937e0192..714ebd4d 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -456,35 +456,35 @@ read_solid_solutions_raw(void) cxxSSassemblage ex; ex.read_raw(parser); - //struct ss_assemblage *s_s_assemblage_ptr = ex.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); - struct ss_assemblage *s_s_assemblage_ptr = cxxSSassemblage2s_s_assemblage(&ex); + //struct ss_assemblage *ss_assemblage_ptr = ex.cxxSSassemblage2ss_assemblage(PHREEQC_THIS); + struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&ex); int n; /* * This is not quite right, may not produce sort order, forced sort */ - if (s_s_assemblage_bsearch(s_s_assemblage_ptr->n_user, &n) != NULL) + if (ss_assemblage_bsearch(ss_assemblage_ptr->n_user, &n) != NULL) { - s_s_assemblage_free(&ss_assemblage[n]); - s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[n], - s_s_assemblage_ptr->n_user); + ss_assemblage_free(&ss_assemblage[n]); + ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[n], + ss_assemblage_ptr->n_user); } else { - n = count_s_s_assemblage++; - if (count_s_s_assemblage >= max_s_s_assemblage) + n = count_ss_assemblage++; + if (count_ss_assemblage >= max_ss_assemblage) { space((void **) ((void *) &(ss_assemblage)), - count_s_s_assemblage, &max_s_s_assemblage, + count_ss_assemblage, &max_ss_assemblage, sizeof(struct ss_assemblage)); } - s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[n], - s_s_assemblage_ptr->n_user); - s_s_assemblage_sort(); + ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[n], + ss_assemblage_ptr->n_user); + ss_assemblage_sort(); } - s_s_assemblage_free(s_s_assemblage_ptr); - free_check_null(s_s_assemblage_ptr); + ss_assemblage_free(ss_assemblage_ptr); + free_check_null(ss_assemblage_ptr); // Need to output the next keyword if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); @@ -977,7 +977,7 @@ read_solid_solutions_modify(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - if (s_s_assemblage_bsearch(n_user, &n) == NULL) + if (ss_assemblage_bsearch(n_user, &n) == NULL) { input_error++; error_string = sformatf( "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n", n_user); @@ -990,13 +990,13 @@ read_solid_solutions_modify(void) entity.read_raw(parser, false); // save entity - //struct ss_assemblage *entity_ptr = entity.cxxSSassemblage2s_s_assemblage(PHREEQC_THIS); - struct ss_assemblage *entity_ptr = cxxSSassemblage2s_s_assemblage(&entity); - s_s_assemblage_free(&(ss_assemblage[n])); - s_s_assemblage_copy(entity_ptr, &(ss_assemblage[n]), entity_ptr->n_user); + //struct ss_assemblage *entity_ptr = entity.cxxSSassemblage2ss_assemblage(PHREEQC_THIS); + struct ss_assemblage *entity_ptr = cxxSSassemblage2ss_assemblage(&entity); + ss_assemblage_free(&(ss_assemblage[n])); + ss_assemblage_copy(entity_ptr, &(ss_assemblage[n]), entity_ptr->n_user); free_check_null(ss_assemblage[n].description); ss_assemblage[n].description = string_duplicate(entity_ptr->description); - s_s_assemblage_free(entity_ptr); + ss_assemblage_free(entity_ptr); free_check_null(entity_ptr); // Need to output the next keyword @@ -1184,7 +1184,7 @@ delete_entities(void) !delete_info.Get_pp_assemblage().Get_defined() && !delete_info.Get_exchange().Get_defined() && !delete_info.Get_surface().Get_defined() && - !delete_info.Get_s_s_assemblage().Get_defined() && + !delete_info.Get_ss_assemblage().Get_defined() && !delete_info.Get_gas_phase().Get_defined() && !delete_info.Get_kinetics().Get_defined() && !delete_info.Get_mix().Get_defined() && @@ -1297,24 +1297,24 @@ delete_entities(void) } } - // s_s_assemblages - if (delete_info.Get_s_s_assemblage().Get_defined()) + // ss_assemblages + if (delete_info.Get_ss_assemblage().Get_defined()) { - if (delete_info.Get_s_s_assemblage().Get_numbers().size() == 0) + if (delete_info.Get_ss_assemblage().Get_numbers().size() == 0) { - for (i = 0; i < count_s_s_assemblage; i++) + for (i = 0; i < count_ss_assemblage; i++) { - s_s_assemblage_delete(ss_assemblage[i].n_user); + ss_assemblage_delete(ss_assemblage[i].n_user); } } else { std::set < int >::iterator it; - for (it = delete_info.Get_s_s_assemblage().Get_numbers().begin(); it != delete_info.Get_s_s_assemblage().Get_numbers().end(); it++) + for (it = delete_info.Get_ss_assemblage().Get_numbers().begin(); it != delete_info.Get_ss_assemblage().Get_numbers().end(); it++) { - if (s_s_assemblage_bsearch(*it, &n) != NULL) + if (ss_assemblage_bsearch(*it, &n) != NULL) { - s_s_assemblage_delete(*it); + ss_assemblage_delete(*it); } } } @@ -1773,12 +1773,12 @@ dump_ostream(std::ostream& os) } } - // s_s_assemblages - if (dump_info.Get_bool_s_s_assemblage()) + // ss_assemblages + if (dump_info.Get_bool_ss_assemblage()) { - if (dump_info.Get_s_s_assemblage().size() == 0) + if (dump_info.Get_ss_assemblage().size() == 0) { - for (i = 0; i < count_s_s_assemblage; i++) + for (i = 0; i < count_ss_assemblage; i++) { cxxSSassemblage cxxentity(&ss_assemblage[i]); cxxentity.dump_raw(os,0); @@ -1787,10 +1787,10 @@ dump_ostream(std::ostream& os) else { std::set < int >::iterator it; - for (it = dump_info.Get_s_s_assemblage().begin(); it != dump_info.Get_s_s_assemblage().end(); it++) + for (it = dump_info.Get_ss_assemblage().begin(); it != dump_info.Get_ss_assemblage().end(); it++) { - if (s_s_assemblage_bsearch(*it, &n) != NULL) + if (ss_assemblage_bsearch(*it, &n) != NULL) { cxxSSassemblage cxxentity(&ss_assemblage[n]); cxxentity.dump_raw(os,0); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 3a817e70..13db002c 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -28,7 +28,7 @@ cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) { } -cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * s_s_assemblage_ptr, PHRQ_io * io) +cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * ss_assemblage_ptr, PHRQ_io * io) // // constructor for cxxSSassemblage from struct SSassemblage // @@ -36,12 +36,12 @@ cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * s_s_assemblage_ptr, PHRQ cxxNumKeyword(io) { int i; - this->Set_description(s_s_assemblage_ptr->description); - n_user = s_s_assemblage_ptr->n_user; - n_user_end = s_s_assemblage_ptr->n_user_end; - for (i = 0; i < s_s_assemblage_ptr->count_s_s; i++) + this->Set_description(ss_assemblage_ptr->description); + n_user = ss_assemblage_ptr->n_user; + n_user_end = ss_assemblage_ptr->n_user_end; + for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) { - cxxSS ssSS(&(s_s_assemblage_ptr->s_s[i]), this->Get_io()); + cxxSS ssSS(&(ss_assemblage_ptr->s_s[i]), this->Get_io()); std::string str(ssSS.Get_name()); ssAssemblageSSs[str] = ssSS; } diff --git a/Solution.cxx b/Solution.cxx index bd7a9df9..354f20e4 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1635,7 +1635,7 @@ cxxSolution::Update(const cxxNameDouble &nd) // kinetics_free(kinetics_ptr); // free_check_null(kinetics_ptr); // } -// for (i = 0; i < count_s_s_assemblage; i++) +// for (i = 0; i < count_ss_assemblage; i++) // { // if (ss_assemblage[i].new_def != TRUE) // { @@ -1659,13 +1659,13 @@ cxxSolution::Update(const cxxNameDouble &nd) // // ex1.read_raw(cparser); // -// struct ss_assemblage *s_s_assemblage_ptr = -// ex1.cxxSSassemblage2s_s_assemblage(); -// s_s_assemblage_free(&ss_assemblage[i]); -// s_s_assemblage_copy(s_s_assemblage_ptr, &ss_assemblage[i], -// s_s_assemblage_ptr->n_user); -// s_s_assemblage_free(s_s_assemblage_ptr); -// free_check_null(s_s_assemblage_ptr); +// struct ss_assemblage *ss_assemblage_ptr = +// ex1.cxxSSassemblage2ss_assemblage(); +// ss_assemblage_free(&ss_assemblage[i]); +// ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[i], +// ss_assemblage_ptr->n_user); +// ss_assemblage_free(ss_assemblage_ptr); +// free_check_null(ss_assemblage_ptr); // // } // diff --git a/StorageBin.cxx b/StorageBin.cxx index 97db04f8..94595c1d 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -1017,9 +1017,9 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) if (this->getSSassemblage(n) != NULL) { //system_ptr->ss_assemblage = - // (this->getSSassemblage(n))->cxxSSassemblage2s_s_assemblage(P_INSTANCE); + // (this->getSSassemblage(n))->cxxSSassemblage2ss_assemblage(P_INSTANCE); system_ptr->ss_assemblage = - P_INSTANCE_POINTER cxxSSassemblage2s_s_assemblage((this->getSSassemblage(n))); + P_INSTANCE_POINTER cxxSSassemblage2ss_assemblage((this->getSSassemblage(n))); } else { @@ -1473,10 +1473,10 @@ cxxStorageBin::Set_System(struct Use *use_ptr) } } // ss_assemblage - if (use_ptr->s_s_assemblage_ptr != NULL) + if (use_ptr->ss_assemblage_ptr != NULL) { std::map < int, cxxSSassemblage >::iterator it = - this->SSassemblages.find(use_ptr->n_s_s_assemblage_user); + this->SSassemblages.find(use_ptr->n_ss_assemblage_user); if (it != this->SSassemblages.end()) { this->system.Set_SSassemblage(&(it->second)); diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 444af1a0..b5d52991 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -211,7 +211,7 @@ bool StorageBinList::Read(CParser & parser) case 5: case 6: case 7: - item = &(this->Get_s_s_assemblage()); + item = &(this->Get_ss_assemblage()); break; case 8: item = &(this->Get_gas_phase()); diff --git a/StorageBinList.h b/StorageBinList.h index 1fb39f3b..a60c021a 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -37,7 +37,7 @@ public: StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; StorageBinListItem & Get_exchange(void) { return(this->exchange); }; StorageBinListItem & Get_surface(void) { return(this->surface); }; - StorageBinListItem & Get_s_s_assemblage(void) { return(this->ss_assemblage); }; + StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; StorageBinListItem & Get_mix(void) { return(this->mix); }; diff --git a/Use.cpp b/Use.cpp new file mode 100644 index 00000000..85f494db --- /dev/null +++ b/Use.cpp @@ -0,0 +1,69 @@ +#include +#include "Use.h" + +Use::Use() +{ + solution_in = false; + n_solution_user = -999; + n_solution = -999; + solution_ptr = NULL; + + pp_assemblage_in = false; + n_pp_assemblage_user = -999; + pp_assemblage_ptr = NULL; + + mix_in = false; + n_mix_user = -999; + mix_ptr = NULL; + n_mix_user_orig = -999; + + reaction_in = false; + n_reaction_user = -999; + reaction_ptr = NULL; + + exchange_in = false; + n_exchange_user = -999; + exchange_ptr = NULL; + + kinetics_in = false; + n_kinetics_user = -999; + n_kinetics = -999; + kinetics *kinetics_ptr = NULL; + + surface_in = false; + n_surface_user = -999; + n_surface = -999; + surface_ptr = NULL; + + pressure_in = false; + n_pressure_user = -999; + pressure_ptr = NULL; + + temperature_in = false; + n_temperature_user = -999; + temperature_ptr = NULL; + + inverse_in = false; + n_inverse_user = -999; + n_inverse = -999; + inverse *inverse_ptr = NULL; + + gas_phase_in = false; + n_gas_phase_user = -999; + gas_phase_ptr = NULL; + + ss_assemblage_in = false; + n_ss_assemblage_user = -999; + n_ss_assemblage = -999; + ss_assemblage *ss_assemblage_ptr = NULL; + + trans_in = false; + advect_in = false; + +} + + +Use::~Use(void) +{ +} + diff --git a/Use.h b/Use.h new file mode 100644 index 00000000..d9c8f42f --- /dev/null +++ b/Use.h @@ -0,0 +1,168 @@ +#if !defined(USE_H_INCLUDED) +#define USE_H_INCLUDED +class cxxPPassemblage; +class cxxMix; +class cxxReaction; +class cxxExchange; +class cxxGasPhase; +class cxxPressure; +class cxxTemperature; + +class Use +{ +public: + Use(); + virtual ~Use(void); + + bool Get_solution_in(void) const {return this->solution_in;} + bool Get_pp_assemblage_in(void) const {return this->pp_assemblage_in;} + bool Get_mix_in(void) const {return this->mix_in;} + bool Get_reaction_in(void) const {return this->reaction_in;} + bool Get_exchange_in(void) const {return this->exchange_in;} + bool Get_kinetics_in(void) const {return this->kinetics_in;} + bool Get_surface_in(void) const {return this->surface_in;} + bool Get_pressure_in(void) const {return this->pressure_in;} + bool Get_temperature_in(void) const {return this->temperature_in;} + bool Get_gas_phase_in(void) const {return this->gas_phase_in;} + bool Get_inverse_in(void) const {return this->inverse_in;} + bool Get_ss_assemblage_in(void) const {return this->ss_assemblage_in;} + + void Set_solution_in(bool tf) {solution_in = tf;} + void Set_pp_assemblage_in(bool tf) {pp_assemblage_in = tf;} + void Set_mix_in(bool tf) {mix_in = tf;} + void Set_reaction_in(bool tf) {reaction_in = tf;} + void Set_exchange_in(bool tf) {exchange_in = tf;} + void Set_kinetics_in(bool tf) {kinetics_in = tf;} + void Set_surface_in(bool tf) {surface_in = tf;} + void Set_pressure_in(bool tf) {pressure_in = tf;} + void Set_temperature_in(bool tf) {temperature_in = tf;} + void Set_gas_phase_in(bool tf) {gas_phase_in = tf;} + void Set_inverse_in(bool tf) {inverse_in = tf;} + void Set_ss_assemblage_in(bool tf) {ss_assemblage_in = tf;} + + int Get_n_solution_user(void) const {return n_solution_user;} + int Get_n_pp_assemblage_user(void) const {return n_pp_assemblage_user;} + int Get_n_mix_user(void) const {return n_mix_user;} + int Get_n_reaction_user(void) const {return n_reaction_user;} + int Get_n_exchange_user(void) const {return n_exchange_user;} + int Get_n_kinetics_user(void) const {return n_kinetics_user;} + int Get_n_surface_user(void) const {return n_surface_user;} + int Get_n_pressure_user(void) const {return n_pressure_user;} + int Get_n_temperature_user(void) const {return n_temperature_user;} + int Get_n_gas_phase_user(void) const {return n_gas_phase_user;} + int Get_n_inverse_user(void) const {return n_inverse_user;} + int Get_n_ss_assemblage_user(void) const {return n_ss_assemblage_user;} + + void Set_n_solution_user(int i) {n_solution_user = i;} + void Set_n_pp_assemblage_user(int i) {n_pp_assemblage_user = i;} + void Set_n_mix_user(int i) {n_mix_user = i;} + void Set_n_reaction_user(int i) {n_reaction_user = i;} + void Set_n_exchange_user(int i) {n_exchange_user = i;} + void Set_n_kinetics_user(int i) {n_kinetics_user = i;} + void Set_n_surface_user(int i) {n_surface_user = i;} + void Set_n_pressure_user(int i) {n_pressure_user = i;} + void Set_n_temperature_user(int i) {n_temperature_user = i;} + void Set_n_gas_phase_user(int i) {n_gas_phase_user = i;} + void Set_n_inverse_user(int i) {n_inverse_user = i;} + void Set_n_ss_assemblage_user(int i) {n_ss_assemblage_user = i;} + + int Get_n_solution(void) const {return n_solution;} + //int Get_n_mix(void) const {return n_mix;} + int Get_n_kinetics(void) const {return n_kinetics;} + int Get_n_surface(void) const {return n_surface;} + int Get_n_inverse(void) const {return n_inverse;} + int Get_n_ss_assemblage(void) const {return n_ss_assemblage;} + + void Set_n_solution(int i) {n_solution = i;} + //void Set_n_mix(int i) {n_mix = i;} + void Set_n_kinetics(int i) {n_kinetics = i;} + void Set_n_surface(int i) {n_surface = i;} + void Set_n_inverse(int i) {n_inverse = i;} + void Set_n_ss_assemblage(int i) {n_ss_assemblage = i;} + + struct solution * Get_solution_ptr(void) const {return this->solution_ptr;} + cxxPPassemblage * Get_pp_assemblage_ptr(void) const {return this->pp_assemblage_ptr;} + cxxMix * Get_mix_ptr(void) const {return this->mix_ptr;} + cxxReaction * Get_reaction_ptr(void) const {return this->reaction_ptr;} + cxxExchange * Get_exchange_ptr(void) const {return this->exchange_ptr;} + struct kinetics * Get_kinetics_ptr(void) const {return this->kinetics_ptr;} + struct surface * Get_surface_ptr(void) const {return this->surface_ptr;} + cxxPressure * Get_pressure_ptr(void) const {return this->pressure_ptr;} + cxxTemperature * Get_temperature_ptr(void) const {return this->temperature_ptr;} + cxxGasPhase * Get_gas_phase_ptr(void) const {return this->gas_phase_ptr;} + struct inverse * Get_inverse_ptr(void) const {return this->inverse_ptr;} + struct ss_assemblage * Get_ss_assemblage_ptr(void) const {return this->ss_assemblage_ptr;} + + void Set_solution_ptr(struct solution * p) {this->solution_ptr = p;} + void Set_pp_assemblage_ptr(cxxPPassemblage * p) {this->pp_assemblage_ptr = p;} + void Set_mix_ptr(cxxMix * p) {this->mix_ptr = p;} + void Set_reaction_ptr(cxxReaction * p) {this->reaction_ptr = p;} + void Set_exchange_ptr(cxxExchange * p) {this->exchange_ptr = p;} + void Set_kinetics_ptr(struct kinetics * p) {this->kinetics_ptr = p;} + void Set_surface_ptr(struct surface * p) {this->surface_ptr = p;} + void Set_pressure_ptr(cxxPressure * p) {this->pressure_ptr = p;} + void Set_temperature_ptr(cxxTemperature * p) {this->temperature_ptr = p;} + void Set_gas_phase_ptr(cxxGasPhase * p) {this->gas_phase_ptr = p;} + void Set_inverse_ptr(struct inverse * p) {this->inverse_ptr = p;} + void Set_ss_assemblage_ptr(struct ss_assemblage * p) {this->ss_assemblage_ptr = p;} + +protected: + bool solution_in; + int n_solution_user; + int n_solution; + struct solution *solution_ptr; + + bool pp_assemblage_in; + int n_pp_assemblage_user; + cxxPPassemblage *pp_assemblage_ptr; + + bool mix_in; + int n_mix_user; + //int n_mix; + cxxMix * mix_ptr; + int n_mix_user_orig; + + bool reaction_in; + int n_reaction_user; + cxxReaction * reaction_ptr; + + bool exchange_in; + int n_exchange_user; + cxxExchange * exchange_ptr; + + bool kinetics_in; + int n_kinetics_user; + int n_kinetics; + struct kinetics *kinetics_ptr; + + bool surface_in; + int n_surface_user; + int n_surface; + struct surface *surface_ptr; + + bool pressure_in; + int n_pressure_user; + cxxPressure *pressure_ptr; + + bool temperature_in; + int n_temperature_user; + cxxTemperature *temperature_ptr; + + bool inverse_in; + int n_inverse_user; + int n_inverse; + struct inverse *inverse_ptr; + + bool gas_phase_in; + int n_gas_phase_user; + cxxGasPhase * gas_phase_ptr; + + bool ss_assemblage_in; + int n_ss_assemblage_user; + int n_ss_assemblage; + struct ss_assemblage *ss_assemblage_ptr; + + bool trans_in; + bool advect_in; +}; +#endif // !defined(USE_H_INCLUDED) diff --git a/dumper.cpp b/dumper.cpp index e5c530cf..723a02f8 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -122,7 +122,7 @@ bool dumper::Read(CParser & parser) case 13: case 14: case 15: - item = &(this->binList.Get_s_s_assemblage()); + item = &(this->binList.Get_ss_assemblage()); break; case 16: case 17: @@ -262,7 +262,7 @@ bool dumper::Get_bool_any(void) Get_bool_pp_assemblage() || Get_bool_exchange() || Get_bool_surface() || - Get_bool_s_s_assemblage() || + Get_bool_ss_assemblage() || Get_bool_gas_phase() || Get_bool_kinetics() || Get_bool_mix() || diff --git a/dumper.h b/dumper.h index bcaa4996..721b39b3 100644 --- a/dumper.h +++ b/dumper.h @@ -22,7 +22,7 @@ public: bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; bool Get_bool_surface(void) { return(this->binList.Get_surface().Get_defined()); }; - bool Get_bool_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_defined()); }; + bool Get_bool_ss_assemblage(void) { return(this->binList.Get_ss_assemblage().Get_defined()); }; bool Get_bool_gas_phase(void) { return(this->binList.Get_gas_phase().Get_defined()); }; bool Get_bool_kinetics(void) { return(this->binList.Get_kinetics().Get_defined()); }; bool Get_bool_mix(void) { return(this->binList.Get_mix().Get_defined()); }; @@ -35,7 +35,7 @@ public: std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; std::set < int > & Get_exchange(void) { return(this->binList.Get_exchange().Get_numbers()); }; std::set < int > & Get_surface(void) { return(this->binList.Get_surface().Get_numbers()); }; - std::set < int > & Get_s_s_assemblage(void) { return(this->binList.Get_s_s_assemblage().Get_numbers()); }; + std::set < int > & Get_ss_assemblage(void) { return(this->binList.Get_ss_assemblage().Get_numbers()); }; std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; From 568a2ab70a9e7ea44abf5dafa326d0583cdb11fa Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 16:15:48 +0000 Subject: [PATCH 0412/1077] classified struct use finished rename of s_s_assemblage and SSassemblageSS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6032 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 24 ++++++++++++------------ Phreeqc.cpp | 10 +++++----- Phreeqc.h | 9 +++++---- ReadClass.cxx | 24 ++++++++++++------------ StorageBin.cxx | 47 ++++++++++++++++++++++++----------------------- StorageBin.h | 3 ++- Use.cpp | 18 ++++++++++++------ Use.h | 27 +++++++++++++++++---------- 8 files changed, 89 insertions(+), 73 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 9a4ffe34..7dc7923f 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1983,7 +1983,7 @@ factor(struct LOC_exec * LINK) break; case toksim_time: - if (PhreeqcPtr->use.kinetics_in == FALSE) + if (!PhreeqcPtr->use.Get_kinetics_in()) { if (PhreeqcPtr->state == PHAST) { @@ -2016,7 +2016,7 @@ factor(struct LOC_exec * LINK) break; case toktotal_time: - if (PhreeqcPtr->use.kinetics_in == FALSE) + if (!PhreeqcPtr->use.Get_kinetics_in()) { if (PhreeqcPtr->state == PHAST) { @@ -2289,14 +2289,14 @@ factor(struct LOC_exec * LINK) n.stringval = true; if (PhreeqcPtr->state == REACTION) { - if (PhreeqcPtr->use.mix_in == TRUE) + if (PhreeqcPtr->use.Get_mix_in()) { - sprintf(string, "Mix %d", PhreeqcPtr->use.n_mix_user); + sprintf(string, "Mix %d", PhreeqcPtr->use.Get_n_mix_user()); n.UU.sval = PhreeqcPtr->string_duplicate(string); } else { - soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.n_solution_user, &nn, TRUE); + soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.Get_n_solution_user(), &nn, TRUE); if (soln_ptr != NULL) { n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->description); @@ -2314,9 +2314,9 @@ factor(struct LOC_exec * LINK) } else { - if (PhreeqcPtr->use.solution_ptr != NULL) + if (PhreeqcPtr->use.Get_solution_ptr() != NULL) { - n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.solution_ptr->description); + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.Get_solution_ptr()->description); } else { @@ -2757,7 +2757,7 @@ factor(struct LOC_exec * LINK) } else if (PhreeqcPtr->state == ADVECTION) { - n.UU.val = (LDBLE) PhreeqcPtr->use.n_solution_user; + n.UU.val = (LDBLE) PhreeqcPtr->use.Get_n_solution_user(); } else { @@ -2831,17 +2831,17 @@ factor(struct LOC_exec * LINK) } else if (PhreeqcPtr->state < REACTION) { - n.UU.val = PhreeqcPtr->use.solution_ptr->n_user; + n.UU.val = PhreeqcPtr->use.Get_solution_ptr()->n_user; } else { - if (PhreeqcPtr->use.mix_in == TRUE) + if (PhreeqcPtr->use.Get_mix_in()) { - n.UU.val = PhreeqcPtr->use.n_mix_user; + n.UU.val = PhreeqcPtr->use.Get_n_mix_user(); } else { - n.UU.val = PhreeqcPtr->use.n_solution_user; + n.UU.val = PhreeqcPtr->use.Get_n_solution_user(); } } if (parse_all) n.UU.val = 1; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 359044f9..6dafb4cb 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -479,10 +479,10 @@ void Phreeqc::init(void) /* * Initialize use pointers */ - use.solution_in = FALSE; - use.pp_assemblage_in = FALSE; - use.mix_in = FALSE; - use.reaction_in = FALSE; + //use.Get_solution_in() = FALSE; + //use.Get_pp_assemblage_in() = FALSE; + //use.Get_mix_in() = FALSE; + //use.Get_reaction_in() = FALSE; /* * Initialize punch */ @@ -718,7 +718,7 @@ void Phreeqc::init(void) /* * to facilitate debuging */ - dbg_use = &use; + //dbg_use = &use; dbg_solution = solution; //dbg_exchange = exchange; dbg_surface = surface; diff --git a/Phreeqc.h b/Phreeqc.h index 1bcab483..81aa9ec0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -31,6 +31,7 @@ #include "Keywords.h" #include "Pressure.h" #include "cxxMix.h" +#include "Use.h" class cxxNameDouble; class cxxKinetics; @@ -422,7 +423,7 @@ public: int do_initialize(void); int do_status(void); void save_init(int i); - void use_init(void); + //void use_init(void); int copy_use(int i); int set_use(void); @@ -1360,9 +1361,9 @@ protected: /*---------------------------------------------------------------------- * Use *---------------------------------------------------------------------- */ - - struct Use use; - struct Use *dbg_use; + cxxUse use; + //struct Use use; + //struct Use *dbg_use; /*---------------------------------------------------------------------- * Copy *---------------------------------------------------------------------- */ diff --git a/ReadClass.cxx b/ReadClass.cxx index 714ebd4d..1d3cf2f2 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1471,28 +1471,28 @@ run_as_cells(void) */ dup_print("Beginning of batch-reaction calculations.", TRUE); count_steps = 1; - if (use.reaction_in == TRUE && use.reaction_ptr != NULL) + if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { - int count = ((cxxReaction *) use.reaction_ptr)->Get_actualSteps(); + int count = ((cxxReaction *) use.Get_reaction_ptr())->Get_actualSteps(); if (count > count_steps) count_steps = count; } - if (use.kinetics_in == TRUE && use.kinetics_ptr != NULL) + if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) { - if (abs(use.kinetics_ptr->count_steps) > count_steps) - count_steps = abs(use.kinetics_ptr->count_steps); + if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) + count_steps = abs(use.Get_kinetics_ptr()->count_steps); } - if (use.temperature_in == TRUE && use.temperature_ptr != NULL) + if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) { - int count = ((cxxTemperature *) use.temperature_ptr)->Get_countTemps(); + int count = ((cxxTemperature *) use.Get_temperature_ptr())->Get_countTemps(); if (count > count_steps) { count_steps = count; } } - if (use.pressure_in == TRUE && use.pressure_ptr != NULL) + if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) { - int count = ((cxxPressure *) use.pressure_ptr)->Get_count(); + int count = ((cxxPressure *) use.Get_pressure_ptr())->Get_count(); if (count > count_steps) { count_steps = count; @@ -1522,7 +1522,7 @@ run_as_cells(void) * Determine time step for kinetics */ kin_time = 0.0; - if (use.kinetics_in == TRUE) + if (use.Get_kinetics_in() == TRUE) { // runner kin_time // equivalent to kin_time in count_steps @@ -1634,9 +1634,9 @@ run_as_cells(void) * save end of reaction */ memcpy(&save, &save_data, sizeof(struct save)); - if (use.kinetics_in == TRUE) + if (use.Get_kinetics_in() == TRUE) { - kinetics_duplicate(-2, use.n_kinetics_user); + kinetics_duplicate(-2, use.Get_n_kinetics_user()); } saver(); } diff --git a/StorageBin.cxx b/StorageBin.cxx index 94595c1d..686d3b1d 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -30,6 +30,7 @@ #include "Reaction.h" #include "Temperature.h" #include "phqalloc.h" +#include "Use.h" ////////////////////////////////////////////////////////////////////// @@ -1418,114 +1419,114 @@ cxxStorageBin::Get_System(void) } void -cxxStorageBin::Set_System(struct Use *use_ptr) +cxxStorageBin::Set_System(cxxUse *use_ptr) { // Initialize this->system.Initialize(); // Solution - if (use_ptr->solution_ptr != NULL) + if (use_ptr->Get_solution_ptr() != NULL) { std::map < int, cxxSolution >::iterator it = - this->Solutions.find(use_ptr->n_solution_user); + this->Solutions.find(use_ptr->Get_n_solution_user()); if (it != this->Solutions.end()) { this->system.Set_Solution(&(it->second)); } } // Exchange - if (use_ptr->exchange_ptr != NULL) + if (use_ptr->Get_exchange_ptr() != NULL) { std::map < int, cxxExchange >::iterator it = - this->Exchangers.find(use_ptr->n_exchange_user); + this->Exchangers.find(use_ptr->Get_n_exchange_user()); if (it != this->Exchangers.end()) { this->system.Set_Exchange(&(it->second)); } } // gas_phase - if (use_ptr->gas_phase_ptr != NULL) + if (use_ptr->Get_gas_phase_ptr() != NULL) { std::map < int, cxxGasPhase >::iterator it = - this->GasPhases.find(use_ptr->n_gas_phase_user); + this->GasPhases.find(use_ptr->Get_n_gas_phase_user()); if (it != this->GasPhases.end()) { this->system.Set_GasPhase(&(it->second)); } } // kinetics - if (use_ptr->kinetics_ptr != NULL) + if (use_ptr->Get_kinetics_ptr() != NULL) { std::map < int, cxxKinetics >::iterator it = - this->Kinetics.find(use_ptr->n_kinetics_user); + this->Kinetics.find(use_ptr->Get_n_kinetics_user()); if (it != this->Kinetics.end()) { this->system.Set_Kinetics(&(it->second)); } } // pp_assemblage - if (use_ptr->pp_assemblage_ptr != NULL) + if (use_ptr->Get_pp_assemblage_ptr() != NULL) { std::map < int, cxxPPassemblage >::iterator it = - this->PPassemblages.find(use_ptr->n_pp_assemblage_user); + this->PPassemblages.find(use_ptr->Get_n_pp_assemblage_user()); if (it != this->PPassemblages.end()) { this->system.Set_PPassemblage(&(it->second)); } } // ss_assemblage - if (use_ptr->ss_assemblage_ptr != NULL) + if (use_ptr->Get_ss_assemblage_ptr() != NULL) { std::map < int, cxxSSassemblage >::iterator it = - this->SSassemblages.find(use_ptr->n_ss_assemblage_user); + this->SSassemblages.find(use_ptr->Get_n_ss_assemblage_user()); if (it != this->SSassemblages.end()) { this->system.Set_SSassemblage(&(it->second)); } } // surface - if (use_ptr->surface_ptr != NULL) + if (use_ptr->Get_surface_ptr() != NULL) { std::map < int, cxxSurface >::iterator it = - this->Surfaces.find(use_ptr->n_surface_user); + this->Surfaces.find(use_ptr->Get_n_surface_user()); if (it != this->Surfaces.end()) { this->system.Set_Surface(&(it->second)); } } // mix - if (use_ptr->mix_ptr != NULL) + if (use_ptr->Get_mix_ptr() != NULL) { std::map < int, cxxMix >::iterator it = - this->Mixes.find(use_ptr->n_mix_user); + this->Mixes.find(use_ptr->Get_n_mix_user()); if (it != this->Mixes.end()) { this->system.Set_Mix(&(it->second)); } } // reaction - if (use_ptr->reaction_ptr != NULL) + if (use_ptr->Get_reaction_ptr() != NULL) { std::map < int, cxxReaction >::iterator it = - this->Reactions.find(use_ptr->n_reaction_user); + this->Reactions.find(use_ptr->Get_n_reaction_user()); if (it != this->Reactions.end()) { this->system.Set_Reaction(&(it->second)); } } // reaction temperature - if (use_ptr->temperature_ptr != NULL) + if (use_ptr->Get_temperature_ptr() != NULL) { std::map < int, cxxTemperature >::iterator it = - this->Temperatures.find(use_ptr->n_temperature_user); + this->Temperatures.find(use_ptr->Get_n_temperature_user()); if (it != this->Temperatures.end()) { this->system.Set_Temperature(&(it->second)); } } // reaction pressure - if (use_ptr->pressure_ptr != NULL) + if (use_ptr->Get_pressure_ptr() != NULL) { - cxxPressure * p = Utilities::Rxn_find(this->Pressures, use_ptr->n_pressure_user); + cxxPressure * p = Utilities::Rxn_find(this->Pressures, use_ptr->Get_n_pressure_user()); if (p != NULL) { this->system.Set_Pressure(p); diff --git a/StorageBin.h b/StorageBin.h index 47175d27..65565675 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -18,6 +18,7 @@ class cxxSSassemblage; class cxxSurface; class cxxReaction; class cxxTemperature; +class cxxUse; class cxxStorageBin: public PHRQ_base { @@ -77,7 +78,7 @@ class cxxStorageBin: public PHRQ_base void Remove_Pressure(int n_user); cxxSystem &Get_System(void); - void Set_System(struct Use *use_ptr); + void Set_System(cxxUse *use_ptr); void Set_System(int i); void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/Use.cpp b/Use.cpp index 85f494db..cac9e4e9 100644 --- a/Use.cpp +++ b/Use.cpp @@ -1,7 +1,18 @@ #include #include "Use.h" -Use::Use() +cxxUse::cxxUse() +{ + this->init(); + +} + + +cxxUse::~cxxUse(void) +{ +} +void cxxUse:: +init(void) { solution_in = false; n_solution_user = -999; @@ -59,11 +70,6 @@ Use::Use() trans_in = false; advect_in = false; - } -Use::~Use(void) -{ -} - diff --git a/Use.h b/Use.h index d9c8f42f..717f52d8 100644 --- a/Use.h +++ b/Use.h @@ -8,11 +8,12 @@ class cxxGasPhase; class cxxPressure; class cxxTemperature; -class Use +class cxxUse { public: - Use(); - virtual ~Use(void); + cxxUse(); + virtual ~cxxUse(void); + void init(void); bool Get_solution_in(void) const {return this->solution_in;} bool Get_pp_assemblage_in(void) const {return this->pp_assemblage_in;} @@ -26,6 +27,8 @@ public: bool Get_gas_phase_in(void) const {return this->gas_phase_in;} bool Get_inverse_in(void) const {return this->inverse_in;} bool Get_ss_assemblage_in(void) const {return this->ss_assemblage_in;} + bool Get_advect_in(void) const {return this->advect_in;} + bool Get_trans_in(void) const {return this->trans_in;} void Set_solution_in(bool tf) {solution_in = tf;} void Set_pp_assemblage_in(bool tf) {pp_assemblage_in = tf;} @@ -39,10 +42,13 @@ public: void Set_gas_phase_in(bool tf) {gas_phase_in = tf;} void Set_inverse_in(bool tf) {inverse_in = tf;} void Set_ss_assemblage_in(bool tf) {ss_assemblage_in = tf;} + void Set_advect_in(bool tf) {advect_in = tf;} + void Set_trans_in(bool tf) {trans_in = tf;} int Get_n_solution_user(void) const {return n_solution_user;} int Get_n_pp_assemblage_user(void) const {return n_pp_assemblage_user;} int Get_n_mix_user(void) const {return n_mix_user;} + int Get_n_mix_user_orig(void) const {return n_mix_user_orig;} int Get_n_reaction_user(void) const {return n_reaction_user;} int Get_n_exchange_user(void) const {return n_exchange_user;} int Get_n_kinetics_user(void) const {return n_kinetics_user;} @@ -56,6 +62,7 @@ public: void Set_n_solution_user(int i) {n_solution_user = i;} void Set_n_pp_assemblage_user(int i) {n_pp_assemblage_user = i;} void Set_n_mix_user(int i) {n_mix_user = i;} + void Set_n_mix_user_orig(int i) {n_mix_user = i;} void Set_n_reaction_user(int i) {n_reaction_user = i;} void Set_n_exchange_user(int i) {n_exchange_user = i;} void Set_n_kinetics_user(int i) {n_kinetics_user = i;} @@ -65,7 +72,7 @@ public: void Set_n_gas_phase_user(int i) {n_gas_phase_user = i;} void Set_n_inverse_user(int i) {n_inverse_user = i;} void Set_n_ss_assemblage_user(int i) {n_ss_assemblage_user = i;} - +#ifdef SKIP int Get_n_solution(void) const {return n_solution;} //int Get_n_mix(void) const {return n_mix;} int Get_n_kinetics(void) const {return n_kinetics;} @@ -79,7 +86,7 @@ public: void Set_n_surface(int i) {n_surface = i;} void Set_n_inverse(int i) {n_inverse = i;} void Set_n_ss_assemblage(int i) {n_ss_assemblage = i;} - +#endif struct solution * Get_solution_ptr(void) const {return this->solution_ptr;} cxxPPassemblage * Get_pp_assemblage_ptr(void) const {return this->pp_assemblage_ptr;} cxxMix * Get_mix_ptr(void) const {return this->mix_ptr;} @@ -109,7 +116,7 @@ public: protected: bool solution_in; int n_solution_user; - int n_solution; + //int n_solution; struct solution *solution_ptr; bool pp_assemblage_in; @@ -132,12 +139,12 @@ protected: bool kinetics_in; int n_kinetics_user; - int n_kinetics; + //int n_kinetics; struct kinetics *kinetics_ptr; bool surface_in; int n_surface_user; - int n_surface; + //int n_surface; struct surface *surface_ptr; bool pressure_in; @@ -150,7 +157,7 @@ protected: bool inverse_in; int n_inverse_user; - int n_inverse; + //int n_inverse; struct inverse *inverse_ptr; bool gas_phase_in; @@ -159,7 +166,7 @@ protected: bool ss_assemblage_in; int n_ss_assemblage_user; - int n_ss_assemblage; + //int n_ss_assemblage; struct ss_assemblage *ss_assemblage_ptr; bool trans_in; From 765d54139f29cfbb435933ade1f9807ee8ae2382 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 16:28:00 +0000 Subject: [PATCH 0413/1077] first bug with use git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6033 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Use.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Use.cpp b/Use.cpp index cac9e4e9..7eba2b96 100644 --- a/Use.cpp +++ b/Use.cpp @@ -16,7 +16,6 @@ init(void) { solution_in = false; n_solution_user = -999; - n_solution = -999; solution_ptr = NULL; pp_assemblage_in = false; @@ -38,12 +37,10 @@ init(void) kinetics_in = false; n_kinetics_user = -999; - n_kinetics = -999; kinetics *kinetics_ptr = NULL; surface_in = false; n_surface_user = -999; - n_surface = -999; surface_ptr = NULL; pressure_in = false; @@ -56,7 +53,6 @@ init(void) inverse_in = false; n_inverse_user = -999; - n_inverse = -999; inverse *inverse_ptr = NULL; gas_phase_in = false; @@ -65,8 +61,7 @@ init(void) ss_assemblage_in = false; n_ss_assemblage_user = -999; - n_ss_assemblage = -999; - ss_assemblage *ss_assemblage_ptr = NULL; + ss_assemblage_ptr = NULL; trans_in = false; advect_in = false; From 765f7b8d131d064764291778fdda75bf2d11b637 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 16:46:37 +0000 Subject: [PATCH 0414/1077] Linux Makefile cxxUse constructor errors git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6034 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 272 ++++++++++++++++++++++++++++--------------------------- Use.cpp | 4 +- 2 files changed, 143 insertions(+), 133 deletions(-) diff --git a/Makefile b/Makefile index 66f812f0..90a82077 100644 --- a/Makefile +++ b/Makefile @@ -201,7 +201,7 @@ COMMON_CXXOBJS = \ SolutionIsotope.o \ SolutionIsotopeList.o \ SSassemblage.o \ - SSassemblageSS.o \ + SS.o \ StorageBin.o \ StorageBinList.o \ Surface.o \ @@ -209,6 +209,7 @@ COMMON_CXXOBJS = \ SurfaceComp.o \ System.o \ Temperature.o \ + Use.o \ Utils.o # ----------------------------------------------------------------------------- @@ -231,7 +232,7 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../cxxKinetics.h ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -239,43 +240,44 @@ cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../phreeqc/phqalloc.h Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Exchange.h ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ + ../phreeqc/phqalloc.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../GasComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../GasComp.h ../NameDouble.h ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../GasPhase.h ../NameDouble.h ../Phreeqc_class.h ../GasComp.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../GasPhase.h ../NameDouble.h ../Phreeqc_class.h \ + ../GasComp.h ../phreeqc/phqalloc.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../ISolutionComp.h ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ @@ -283,7 +285,7 @@ ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../ISolution.h ../ISolutionComp.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../NameDouble.h ../Phreeqc_class.h \ @@ -293,7 +295,7 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ @@ -301,7 +303,7 @@ NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../NameDouble.h ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ @@ -311,14 +313,15 @@ Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h @@ -327,7 +330,7 @@ PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../PPassemblage.h ../PPassemblageComp.h ../NameDouble.h \ ../Phreeqc_class.h ../phreeqc/phqalloc.h @@ -336,21 +339,21 @@ Pressure.o: ../Pressure.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../phreeqc/phqalloc.h Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Reaction.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Reaction.h ../NameDouble.h ../phreeqc/phqalloc.h ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../Phreeqc_class.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ @@ -363,15 +366,15 @@ Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../SolutionIsotope.h ../phreeqc/phqalloc.h SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ @@ -379,7 +382,7 @@ SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../SolutionIsotopeList.h ../SolutionIsotope.h ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ @@ -387,38 +390,37 @@ SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SSassemblageSS.h \ + ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SS.h \ ../phreeqc/phqalloc.h -SSassemblageSS.o: ../SSassemblageSS.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SSassemblageSS.h ../NameDouble.h ../Phreeqc_class.h \ +SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../SS.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../NameDouble.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ ../SSassemblage.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h \ + ../PPassemblageComp.h ../SS.h ../Surface.h ../SurfaceComp.h \ ../SurfaceCharge.h ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../SurfaceCharge.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h @@ -427,7 +429,7 @@ SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ ../phreeqc/phqalloc.h @@ -436,7 +438,7 @@ Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Surface.h \ ../SurfaceComp.h ../NameDouble.h ../SurfaceCharge.h \ ../phreeqc/phqalloc.h @@ -445,19 +447,19 @@ System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../System.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../SSassemblage.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ - ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblageSS.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../Reaction.h ../Temperature.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../System.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../SSassemblage.h ../Solution.h ../SolutionIsotopeList.h \ + ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SS.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../Reaction.h ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../Temperature.h ../phreeqc/phqalloc.h Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -465,7 +467,8 @@ Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h Calculate_value.o: ../Calculate_value.cpp ../Calculate_value.h \ ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h ../phreeqc/phrqtype.h Calculate_values\ .o: ../Calculate_values\ .cpp ../Calculate_values.h \ @@ -477,7 +480,7 @@ Calculate_values.o: ../Calculate_values.cpp ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Calculate_values.h \ ../Calculate_value.h ../Parser.h ../PBasic.h ChartHandler.o: ../ChartHandler.cpp @@ -487,7 +490,7 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ @@ -504,13 +507,13 @@ PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ - ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h + ../Use.h ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ @@ -522,58 +525,61 @@ PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../Parser.h ../Keywords.h ../PHRQ_io.h ../phreeqc/NA.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h +Use.o: ../Use.cpp ../Use.h advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ ../phreeqc/../PHRQ_io.h ../phreeqc/../PBasic.h ../phreeqc/../Exchange.h \ ../phreeqc/../NumKeyword.h ../phreeqc/../ExchComp.h \ ../phreeqc/../NameDouble.h ../phreeqc/../GasPhase.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../GasComp.h + ../phreeqc/../Phreeqc_class.h ../phreeqc/../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h ChartObject.o: ../phreeqc/ChartObject.cpp cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ @@ -583,20 +589,21 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../GasPhase.h \ - ../NameDouble.h ../Parser.h ../Phreeqc_class.h ../GasComp.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../GasPhase.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ + ../GasComp.h input.o: ../phreeqc/input.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -604,28 +611,28 @@ integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ ../Phreeqc_class.h ../Reaction.h ../cxxKinetics.h ../KineticsComp.h \ @@ -639,33 +646,34 @@ mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../ExchComp.h ../GasPhase.h \ - ../Phreeqc_class.h ../GasComp.h ../Reaction.h + ../Phreeqc_class.h ../GasComp.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h model_aw_fraction.o: ../phreeqc/model_aw_fraction.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ ../NameDouble.h ../Parser.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h model\ with\ ah2o.o: ../phreeqc/model\ with\ ah2o.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h @@ -678,27 +686,27 @@ parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ ../Parser.h pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ @@ -706,52 +714,54 @@ pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../Reaction.h + ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Phreeqc.h ../phreeqc/phqalloc.h ../Pressure.h ../Temperature.h \ - ../Parser.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../GasPhase.h ../Phreeqc_class.h ../GasComp.h ../Reaction.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Pressure.h \ + ../Temperature.h ../Parser.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ + ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ ../phreeqc/../PHRQ_io.h ../phreeqc/phrqtype.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../SSassemblageSS.h \ - ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../phreeqc/../Phreeqc_class.h ../phreeqc/../SS.h ../Phreeqc.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ ../Parser.h smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ @@ -762,42 +772,40 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ - ../Parser.h ../Phreeqc_class.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SSassemblageSS.h ../NameDouble.h ../Temperature.h \ - ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Parser.h \ + ../StorageBin.h ../System.h ../NameDouble.h ../Phreeqc_class.h \ + ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../NameDouble.h ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../Reaction.h structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../Reaction.h ../phreeqc/../cxxKinetics.h \ - ../phreeqc/../NumKeyword.h ../phreeqc/../KineticsComp.h \ - ../phreeqc/../NameDouble.h ../phreeqc/../PHRQ_base.h \ - ../phreeqc/../PPassemblage.h ../phreeqc/../PPassemblageComp.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../PPassemblageComp.h \ - ../phreeqc/../Solution.h ../phreeqc/../SolutionIsotopeList.h \ - ../phreeqc/../SolutionIsotope.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/../SolutionIsotopeList.h \ - ../phreeqc/../SSassemblage.h ../phreeqc/../SSassemblageSS.h \ - ../phreeqc/../Surface.h ../phreeqc/../SurfaceComp.h \ - ../phreeqc/../SurfaceCharge.h ../phreeqc/../SurfaceComp.h \ - ../phreeqc/../SurfaceCharge.h ../phreeqc/../StorageBin.h \ - ../phreeqc/../System.h + ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../Use.h ../phreeqc/../cxxKinetics.h ../phreeqc/../NumKeyword.h \ + ../phreeqc/../KineticsComp.h ../phreeqc/../NameDouble.h \ + ../phreeqc/../PHRQ_base.h ../phreeqc/../Solution.h \ + ../phreeqc/../SolutionIsotopeList.h ../phreeqc/../SolutionIsotope.h \ + ../phreeqc/../Parser.h ../phreeqc/../PHRQ_io.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../SolutionIsotopeList.h \ + ../phreeqc/../SSassemblage.h ../phreeqc/../SS.h ../phreeqc/../Surface.h \ + ../phreeqc/../SurfaceComp.h ../phreeqc/../SurfaceCharge.h \ + ../phreeqc/../SurfaceComp.h ../phreeqc/../SurfaceCharge.h \ + ../phreeqc/../StorageBin.h ../phreeqc/../System.h sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ @@ -805,34 +813,36 @@ tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h \ ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ - ../Reaction.h + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ + ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../GasPhase.h ../Phreeqc_class.h ../GasComp.h + ../GasPhase.h ../Phreeqc_class.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h # ----------------------------------------------------------------------------- diff --git a/Use.cpp b/Use.cpp index 7eba2b96..e6f8c349 100644 --- a/Use.cpp +++ b/Use.cpp @@ -37,7 +37,7 @@ init(void) kinetics_in = false; n_kinetics_user = -999; - kinetics *kinetics_ptr = NULL; + kinetics_ptr = NULL; surface_in = false; n_surface_user = -999; @@ -53,7 +53,7 @@ init(void) inverse_in = false; n_inverse_user = -999; - inverse *inverse_ptr = NULL; + inverse_ptr = NULL; gas_phase_in = false; n_gas_phase_user = -999; From 93aa3317b8849959579e53d3f835e368ff9c0ea0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 17:45:20 +0000 Subject: [PATCH 0415/1077] n_mix_user_orig setter bug. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6036 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Use.h | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/Use.h b/Use.h index 717f52d8..acc8afa1 100644 --- a/Use.h +++ b/Use.h @@ -62,7 +62,7 @@ public: void Set_n_solution_user(int i) {n_solution_user = i;} void Set_n_pp_assemblage_user(int i) {n_pp_assemblage_user = i;} void Set_n_mix_user(int i) {n_mix_user = i;} - void Set_n_mix_user_orig(int i) {n_mix_user = i;} + void Set_n_mix_user_orig(int i) {n_mix_user_orig = i;} void Set_n_reaction_user(int i) {n_reaction_user = i;} void Set_n_exchange_user(int i) {n_exchange_user = i;} void Set_n_kinetics_user(int i) {n_kinetics_user = i;} @@ -72,21 +72,7 @@ public: void Set_n_gas_phase_user(int i) {n_gas_phase_user = i;} void Set_n_inverse_user(int i) {n_inverse_user = i;} void Set_n_ss_assemblage_user(int i) {n_ss_assemblage_user = i;} -#ifdef SKIP - int Get_n_solution(void) const {return n_solution;} - //int Get_n_mix(void) const {return n_mix;} - int Get_n_kinetics(void) const {return n_kinetics;} - int Get_n_surface(void) const {return n_surface;} - int Get_n_inverse(void) const {return n_inverse;} - int Get_n_ss_assemblage(void) const {return n_ss_assemblage;} - void Set_n_solution(int i) {n_solution = i;} - //void Set_n_mix(int i) {n_mix = i;} - void Set_n_kinetics(int i) {n_kinetics = i;} - void Set_n_surface(int i) {n_surface = i;} - void Set_n_inverse(int i) {n_inverse = i;} - void Set_n_ss_assemblage(int i) {n_ss_assemblage = i;} -#endif struct solution * Get_solution_ptr(void) const {return this->solution_ptr;} cxxPPassemblage * Get_pp_assemblage_ptr(void) const {return this->pp_assemblage_ptr;} cxxMix * Get_mix_ptr(void) const {return this->mix_ptr;} @@ -116,7 +102,6 @@ public: protected: bool solution_in; int n_solution_user; - //int n_solution; struct solution *solution_ptr; bool pp_assemblage_in; @@ -125,7 +110,6 @@ protected: bool mix_in; int n_mix_user; - //int n_mix; cxxMix * mix_ptr; int n_mix_user_orig; @@ -139,12 +123,10 @@ protected: bool kinetics_in; int n_kinetics_user; - //int n_kinetics; struct kinetics *kinetics_ptr; bool surface_in; int n_surface_user; - //int n_surface; struct surface *surface_ptr; bool pressure_in; @@ -157,7 +139,6 @@ protected: bool inverse_in; int n_inverse_user; - //int n_inverse; struct inverse *inverse_ptr; bool gas_phase_in; @@ -166,7 +147,6 @@ protected: bool ss_assemblage_in; int n_ss_assemblage_user; - //int n_ss_assemblage; struct ss_assemblage *ss_assemblage_ptr; bool trans_in; From 9aef1acfe71f61881adcbeb460641fc356f2c7c7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 19:49:05 +0000 Subject: [PATCH 0416/1077] out of range subscript in get_line git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6037 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 8aaa8c87..d43f3be3 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -742,11 +742,12 @@ get_logical_line(void * cookie) if (c == '\n') { // remove '\\' - for (; pos < m_line_save.size(); pos++) - { - m_line_save[pos] = m_line_save[pos + 1]; - } - m_line_save.erase(m_line_save.size() - 1, 1); + m_line_save = m_line_save.substr(0,pos); + //for (; pos < m_line_save.size(); pos++) + //{ + // m_line_save[pos] = m_line_save[pos + 1]; + //} + //m_line_save.erase(m_line_save.size() - 1, 1); break; } m_line_save += c; From 76839828774c4a9279e8b329b1bbe8c06f3da1c2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jan 2012 21:13:51 +0000 Subject: [PATCH 0417/1077] changed all double to LDBLE git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6038 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 18 +++++----- ChartObject.h | 36 +++++++++---------- CurveObject.h | 18 +++++----- ExchComp.cxx | 38 ++++++++++---------- ExchComp.h | 38 ++++++++++---------- Exchange.cxx | 10 +++--- Exchange.h | 6 ++-- GasComp.cxx | 2 +- GasComp.h | 4 +-- GasPhase.cxx | 16 ++++----- GasPhase.h | 12 +++---- ISolution.cxx | 6 ++-- ISolution.h | 6 ++-- ISolutionComp.h | 24 ++++++------- KineticsComp.cxx | 36 +++++++++---------- KineticsComp.h | 28 +++++++-------- PPassemblage.cxx | 10 +++--- PPassemblage.h | 6 ++-- PPassemblageComp.cxx | 28 +++++++-------- PPassemblageComp.h | 28 +++++++-------- Parser.cxx | 4 +-- Parser.h | 5 +-- Pressure.cxx | 4 +-- Pressure.h | 4 +-- Reaction.cxx | 4 +-- Reaction.h | 4 +-- ReadClass.cxx | 2 +- SS.cxx | 22 ++++++------ SS.h | 27 +++++++------- SSassemblage.cxx | 10 +++--- SSassemblage.h | 6 ++-- Solution.cxx | 74 +++++++++++++++++++------------------- Solution.h | 78 ++++++++++++++++++++--------------------- SolutionIsotope.cxx | 4 +-- SolutionIsotope.h | 26 +++++++------- SolutionIsotopeList.cxx | 6 ++-- SolutionIsotopeList.h | 4 +-- StorageBin.cxx | 22 ++++++------ Surface.cxx | 18 +++++----- Surface.h | 22 ++++++------ SurfaceCharge.cxx | 46 ++++++++++++------------ SurfaceCharge.h | 40 ++++++++++----------- SurfaceComp.cxx | 38 ++++++++++---------- SurfaceComp.h | 34 +++++++++--------- Temperature.cxx | 4 +-- Temperature.h | 4 +-- Utils.cxx | 8 ++--- Utils.h | 2 +- cxxKinetics.cxx | 22 ++++++------ cxxKinetics.h | 16 ++++----- cxxMix.cxx | 6 ++-- runner.h | 9 ++--- 52 files changed, 474 insertions(+), 471 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 0d693080..1ed9ed7b 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -127,7 +127,7 @@ ChartObject::Set_axis_scale(CParser & parser) std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; - double *scale_ptr = NULL; + LDBLE *scale_ptr = NULL; std::vector string_vector; size_t j = 0; @@ -220,7 +220,7 @@ ChartObject::Set_axis_scale(CParser & parser) estream << "Maximum must be larger than minimum of axis_scale " << type << "-scale." << "\n"; estream << "Switching values for MIN and MAX. " << "\n"; warning_msg(estream.str().c_str()); - double t; + LDBLE t; t = scale_ptr[0]; scale_ptr[0] = scale_ptr[1]; scale_ptr[1] = scale_ptr[0]; @@ -568,7 +568,7 @@ ChartObject::OpenCSVFile(std::string file_name) } // x value for all curves - double x_value = atof(tok1.c_str()); + LDBLE x_value = atof(tok1.c_str()); // y values for curves std::string tok2; @@ -1014,7 +1014,7 @@ ChartObject::Finalize_graph_pts(void) { if (graph_x != NA) { - std::map::iterator it; + std::map::iterator it; for (it = graph_y.begin(); it != graph_y.end(); it++) { Curves[it->first]->Get_x().push_back(graph_x); @@ -1054,9 +1054,9 @@ ChartObject::Add_new_series(void) } void ChartObject::Add_curve(bool plotxy, std::string id, - double line_width, + LDBLE line_width, std::string symbol, - double symbol_size, + LDBLE symbol_size, int y_axis, std::string color) { @@ -1120,7 +1120,7 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) } // axis_scale_x - double *scale_ptr = this->axis_scale_x; + LDBLE *scale_ptr = this->axis_scale_x; { oss << indent1 << "-axis_scale x_axis "; for (i = 0; i < 4; i++) @@ -1249,8 +1249,8 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) // temporary storage before stored graph_x/y/sy data are stored in curves // Initialize_graph_pts and Finalize_graph_pts use this storage. - double graph_x; - std::map graph_y; + LDBLE graph_x; + std::map graph_y; std::map secondary_y; // temporary plotxy curve definitions before stored in curves diff --git a/ChartObject.h b/ChartObject.h index 4ce210b4..7f102579 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -65,18 +65,18 @@ class ChartObject:public cxxNumKeyword { return this->axis_titles; } - // double axis_scale_x[5]; - double *Get_axis_scale_x() + // LDBLE axis_scale_x[5]; + LDBLE *Get_axis_scale_x() { return this->axis_scale_x; } - // double axis_scale_y[5]; - double *Get_axis_scale_y() + // LDBLE axis_scale_y[5]; + LDBLE *Get_axis_scale_y() { return this->axis_scale_y; } - // double axis_scale_y2[5]; - double *Get_axis_scale_y2() + // LDBLE axis_scale_y2[5]; + LDBLE *Get_axis_scale_y2() { return this->axis_scale_y2; } @@ -217,17 +217,17 @@ class ChartObject:public cxxNumKeyword return this->rate_new_def; } // int default_symbol; - //double graph_x; - void Set_graph_x(double d) + //LDBLE graph_x; + void Set_graph_x(LDBLE d) { this->graph_x = d; } - double Get_graph_x() + LDBLE Get_graph_x() { return this->graph_x; } - //std::map graph_y; - std::map &Get_graph_y() + //std::map graph_y; + std::map &Get_graph_y() { return this->graph_y; } @@ -297,9 +297,9 @@ class ChartObject:public cxxNumKeyword void Get_color_string_csv(std::string &color); void Add_new_series(void); void Add_curve(bool plotxy, std::string id = "", - double line_width = 1.0, + LDBLE line_width = 1.0, std::string symbol = "", - double symbol_size = 6.0, + LDBLE symbol_size = 6.0, int y_axis = 1, std::string color = ""); void dump(std::ostream & s_oss, unsigned int indent); @@ -315,9 +315,9 @@ class ChartObject:public cxxNumKeyword std::vector Color_vector; std::string chart_title; std::vector axis_titles; - double axis_scale_x[5]; - double axis_scale_y[5]; - double axis_scale_y2[5]; + LDBLE axis_scale_x[5]; + LDBLE axis_scale_y[5]; + LDBLE axis_scale_y2[5]; int chart_type; bool graph_initial_solutions; @@ -355,8 +355,8 @@ class ChartObject:public cxxNumKeyword // temporary storage before stored graph_x/y/sy data are stored in curves // Initialize_graph_pts and Finalize_graph_pts use this storage. - double graph_x; - std::map graph_y; + LDBLE graph_x; + std::map graph_y; std::map secondary_y; // temporary plotxy curve definitions before stored in curves diff --git a/CurveObject.h b/CurveObject.h index 32392bd0..c826bb6a 100644 --- a/CurveObject.h +++ b/CurveObject.h @@ -2,7 +2,7 @@ #define CURVEOBJECT_H_INCLUDED #include #include - +#include "phrqtype.h" class CurveObject { @@ -33,19 +33,19 @@ public: { return this->symbol; } - void Set_symbol_size(double f) + void Set_symbol_size(LDBLE f) { this->symbol_size = f; } - double Get_symbol_size(void) + LDBLE Get_symbol_size(void) { return this->symbol_size; } - void Set_line_w(double f) + void Set_line_w(LDBLE f) { this->line_w = f; } - double Get_line_w(void) + LDBLE Get_line_w(void) { return this->line_w; } @@ -53,11 +53,11 @@ public: { this->y_axis = f; } - std::vector & Get_x() + std::vector & Get_x() { return this->x; } - std::vector & Get_y() + std::vector & Get_y() { return this->y; } @@ -76,12 +76,12 @@ public: protected: //float *x, *y; - std::vector x, y; + std::vector x, y; //int nxy, npoints, npoints_plot, prev_npoints; std::string id, color, symbol; int y_axis; - double line_w, symbol_size; + LDBLE line_w, symbol_size; public: diff --git a/ExchComp.cxx b/ExchComp.cxx index b01b1b0f..3327cd69 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -39,7 +39,7 @@ cxxExchComp::cxxExchComp(PHRQ_io *io) } #ifdef SKIP cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, - std::vector < double >&f_vector) + std::vector < LDBLE >&f_vector) // // constructor for cxxExchComp from mixing // @@ -49,7 +49,7 @@ cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, // // check consistency // - std::vector < double >::iterator it_f; + std::vector < LDBLE >::iterator it_f; std::vector < cxxExchComp >::iterator it_ec; // set fixed variables it_ec = ec_vector.begin(); @@ -72,7 +72,7 @@ cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, } } // calculate sum of extensive factors - double sum_extensive = 0; + LDBLE sum_extensive = 0; for (it_f = f_vector.begin(); it_f != f_vector.end(); it_f++) { sum_extensive += *it_f; @@ -87,8 +87,8 @@ cxxExchComp::cxxExchComp(std::vector < cxxExchComp > &ec_vector, it_f = f_vector.begin(); for (; it_ec != ec_vector.end();) { - double extensive = *it_f; - double intensive = extensive / sum_extensive; + LDBLE extensive = *it_f; + LDBLE intensive = extensive / sum_extensive; this->moles += it_ec->moles * extensive; this->la += it_ec->la * intensive; this->charge_balance += it_ec->charge_balance * extensive; @@ -416,9 +416,9 @@ cxxExchComp::read_raw(CParser & parser, bool check) } } void -cxxExchComp::add(const cxxExchComp & addee, double extensive) +cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) { - double ext1, ext2, f1, f2; + LDBLE ext1, ext2, f1, f2; if (extensive == 0.0) return; if (addee.formula.size() == 0) @@ -452,13 +452,13 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) this->formula = addee.formula; this->formula_totals = addee.formula_totals; } - //double moles; + //LDBLE moles; this->moles += addee.moles * extensive; //cxxNameDouble totals; this->totals.add_extensive(addee.totals, extensive); - //double la; + //LDBLE la; this->la = f1 * this->la + f2 * addee.la; - //double charge_balance; + //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; //char *phase_name; @@ -490,7 +490,7 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) } else if (this->rate_name.size() != 0) { - //double phase_proportion; + //LDBLE phase_proportion; this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } @@ -507,27 +507,27 @@ cxxExchComp::add(const cxxExchComp & addee, double extensive) } } void -cxxExchComp::multiply(double extensive) +cxxExchComp::multiply(LDBLE extensive) { //char * formula; - //double moles; + //LDBLE moles; this->moles *= extensive; //cxxNameDouble formula_totals; //cxxNameDouble totals; this->totals.multiply(extensive); - //double la; - //double charge_balance; + //LDBLE la; + //LDBLE charge_balance; this->charge_balance *= extensive; //char *phase_name; - //double phase_proportion; + //LDBLE phase_proportion; this->phase_proportion *= extensive; - //double formula_z; + //LDBLE formula_z; } #ifdef USE_MPI void cxxExchComp::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->formula)); @@ -543,7 +543,7 @@ cxxExchComp::mpi_pack(std::vector < int >&ints, } void -cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxExchComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; diff --git a/ExchComp.h b/ExchComp.h index efdfe2c7..0271dfcf 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -33,27 +33,27 @@ class cxxExchComp: public PHRQ_base else this->formula.clear(); } - double Get_moles() const + LDBLE Get_moles() const { return this->moles; } - void Set_moles(double d) + void Set_moles(LDBLE d) { this->moles = d; } - double Get_la() const + LDBLE Get_la() const { return this->la; } - void Set_la(double d) + void Set_la(LDBLE d) { this->la = d; } - double Get_charge_balance() const + LDBLE Get_charge_balance() const { return this->charge_balance; } - void Set_charge_balance(double d) + void Set_charge_balance(LDBLE d) { this->charge_balance = d; } @@ -68,11 +68,11 @@ class cxxExchComp: public PHRQ_base else this->phase_name.clear(); } - double Get_phase_proportion() const + LDBLE Get_phase_proportion() const { return this->phase_proportion; } - void Set_phase_proportion(double d) + void Set_phase_proportion(LDBLE d) { this->phase_proportion = d; } @@ -87,11 +87,11 @@ class cxxExchComp: public PHRQ_base else this->rate_name.clear(); } - double Get_formula_z() const + LDBLE Get_formula_z() const { return this->formula_z; } - void Set_formula_z(double d) + void Set_formula_z(LDBLE d) { this->formula_z = d; } @@ -124,25 +124,25 @@ class cxxExchComp: public PHRQ_base cxxNameDouble & Get_formula_totals(void) {return this->formula_totals;} - void add(const cxxExchComp & comp, double extensive); - void multiply(double extensive); + void add(const cxxExchComp & comp, LDBLE extensive); + void multiply(LDBLE extensive); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif protected: std::string formula; - double moles; + LDBLE moles; cxxNameDouble formula_totals; cxxNameDouble totals; - double la; - double charge_balance; + LDBLE la; + LDBLE charge_balance; std::string phase_name; - double phase_proportion; + LDBLE phase_proportion; std::string rate_name; - double formula_z; // charge on formula + LDBLE formula_z; // charge on formula public: diff --git a/Exchange.cxx b/Exchange.cxx index 922d5470..b50466e6 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -40,8 +40,8 @@ cxxNumKeyword(io) // // Mix exchangers // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -310,7 +310,7 @@ cxxExchange::read_raw(CParser & parser, bool check) } } void -cxxExchange::add(const cxxExchange & addee, double extensive) +cxxExchange::add(const cxxExchange & addee, LDBLE extensive) // // Add existing exchange to "this" exchange // @@ -340,7 +340,7 @@ cxxExchange::add(const cxxExchange & addee, double extensive) /* ---------------------------------------------------------------------- */ void cxxExchange::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ @@ -357,7 +357,7 @@ cxxExchange::mpi_pack(std::vector < int >&ints, /* ---------------------------------------------------------------------- */ void -cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxExchange::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; diff --git a/Exchange.h b/Exchange.h index 9c4221c2..8221f846 100644 --- a/Exchange.h +++ b/Exchange.h @@ -47,11 +47,11 @@ public: std::vector Vectorize(void); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif protected: - void add(const cxxExchange & addee, double extensive); + void add(const cxxExchange & addee, LDBLE extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/GasComp.cxx b/GasComp.cxx index 845b97a8..2c6e842d 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -218,7 +218,7 @@ cxxGasComp::add(const cxxGasComp & addee, LDBLE extensive) assert(this->phase_name == addee.phase_name); - //double moles; + //LDBLE moles; this->p_read += addee.p_read * extensive; this->moles += addee.moles * extensive; this->initial_moles += addee.initial_moles * extensive; diff --git a/GasComp.h b/GasComp.h index 6eb55c42..2063c2aa 100644 --- a/GasComp.h +++ b/GasComp.h @@ -35,8 +35,8 @@ class cxxGasComp: public PHRQ_base void multiply(LDBLE extensive); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif protected: std::string phase_name; diff --git a/GasPhase.cxx b/GasPhase.cxx index 8c138d40..e5829f31 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -54,8 +54,8 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, std::map comp_map; std::map::iterator comp_it; - const std::map < int, double > & mixcomps = mx.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE > & mixcomps = mx.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { const cxxGasPhase *entity_ptr = &(entity_map.find(it->first)->second); @@ -133,8 +133,8 @@ cxxNumKeyword(io) // Mix // //cxxNameDouble gasPhaseComps; - const std::map < int, double > & mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE > & mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -144,8 +144,8 @@ cxxNumKeyword(io) this->gasPhaseComps.add_extensive(entity_ptr->gasPhaseComps, it->second); //GP_TYPE type; - //double total_p; - //double volume; + //LDBLE total_p; + //LDBLE volume; if (first) { this->type = entity_ptr->type; @@ -529,7 +529,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxGasPhase::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { ints.push_back(this->n_user); this->gasPhaseComps.mpi_pack(ints, doubles); @@ -548,7 +548,7 @@ cxxGasPhase::mpi_pack(std::vector < int >&ints, } void -cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxGasPhase::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { int i = *ii; int d = *dd; diff --git a/GasPhase.h b/GasPhase.h index d9f09229..a229cbdc 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -35,8 +35,8 @@ class cxxGasPhase:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif void totalize(PHREEQC_PTR_ARG); @@ -50,10 +50,10 @@ class cxxGasPhase:public cxxNumKeyword GP_TYPE Get_type(void) const {return type;}; void Set_type(GP_TYPE t) {type = t;}; - double Get_total_p(void) const {return total_p;}; - double Get_volume(void) const {return volume;}; + LDBLE Get_total_p(void) const {return total_p;}; + LDBLE Get_volume(void) const {return volume;}; void Set_volume(LDBLE v) {volume = v;}; - double Get_v_m(void) const {return v_m;}; + LDBLE Get_v_m(void) const {return v_m;}; void Set_v_m(LDBLE v) {v_m = v;}; bool Get_pr_in(void) const {return pr_in;}; void Set_pr_in(bool tf) {pr_in = tf;}; @@ -74,7 +74,7 @@ class cxxGasPhase:public cxxNumKeyword LDBLE Calc_total_moles(void); protected: - void add(const cxxGasPhase & addee, double extensive); + void add(const cxxGasPhase & addee, LDBLE extensive); protected: bool new_def; diff --git a/ISolution.cxx b/ISolution.cxx index f3faee0f..527216a6 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -43,7 +43,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) // Converts from input units to moles per kilogram water // { - double sum_solutes = 0; + LDBLE sum_solutes = 0; // foreach conc std::map < std::string, cxxISolutionComp >::iterator iter = this->comps.begin(); @@ -61,7 +61,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) /* * Convert liters to kg solution */ - double moles = iter->second.get_input_conc(); + LDBLE moles = iter->second.get_input_conc(); if (this->units.find("/l") != std::string::npos) { moles /= this->density; @@ -107,7 +107,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) /* * Convert /kgs to /kgw */ - double l_mass_water; + LDBLE l_mass_water; if ((this->units.find("kgs") != std::string::npos) || (this->units.find("/l") != std::string::npos)) { diff --git a/ISolution.h b/ISolution.h index ec148918..34836fe8 100644 --- a/ISolution.h +++ b/ISolution.h @@ -23,11 +23,11 @@ class cxxISolution:public cxxSolution //static cxxISolution& read(CParser& parser); //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - double Get_density() const + LDBLE Get_density() const { return this->density; } - void Set_density(double l_density) + void Set_density(LDBLE l_density) { this->density = l_density; } @@ -54,7 +54,7 @@ class cxxISolution:public cxxSolution protected: friend class cxxISolutionComp; // for this->pe access - double density; + LDBLE density; std::string units; std::map < std::string, cxxISolutionComp > comps; struct pe_data *pes; diff --git a/ISolutionComp.h b/ISolutionComp.h index 6cf592c2..43cc7bbe 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -34,20 +34,20 @@ class cxxISolutionComp: public PHRQ_base this->description.clear(); } - double Get_moles() const + LDBLE Get_moles() const { return this->moles; } - void Set_moles(double l_moles) + void Set_moles(LDBLE l_moles) { this->moles = l_moles; } - double Get_input_conc() const + LDBLE Get_input_conc() const { return this->input_conc; } - void Set_input_conc(double l_input_conc) + void Set_input_conc(LDBLE l_input_conc) { this->input_conc = l_input_conc; } @@ -77,7 +77,7 @@ class cxxISolutionComp: public PHRQ_base } - double Get_phase_si() const + LDBLE Get_phase_si() const { return this->phase_si; } @@ -107,12 +107,12 @@ class cxxISolutionComp: public PHRQ_base this->as.clear(); } - //double get_gfw()const {return this->gfw;} - double Get_gfw() const + //LDBLE get_gfw()const {return this->gfw;} + LDBLE Get_gfw() const { return this->gfw; }; - void Set_gfw(double l_gfw) + void Set_gfw(LDBLE l_gfw) { this->gfw = l_gfw; } @@ -125,14 +125,14 @@ class cxxISolutionComp: public PHRQ_base protected: std::string description; - double moles; - double input_conc; + LDBLE moles; + LDBLE input_conc; std::string units; std::string equation_name; - double phase_si; + LDBLE phase_si; int n_pe; std::string as; - double gfw; + LDBLE gfw; }; #endif // ISOLUTIONCOMP_H_INCLUDED diff --git a/KineticsComp.cxx b/KineticsComp.cxx index cf6f1f74..1d009f17 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -136,7 +136,7 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { int i = 0; s_oss << indent2; - for (std::vector < double >::const_iterator it = d_params.begin(); + for (std::vector < LDBLE >::const_iterator it = d_params.begin(); it != d_params.end(); it++) { if (i++ == 5) @@ -155,7 +155,7 @@ void cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; - double d; + LDBLE d; static std::vector < std::string > vopts; if (vopts.empty()) @@ -175,7 +175,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) std::string token; int opt_save; - std::vector < double > temp_d_params; + std::vector < LDBLE > temp_d_params; opt_save = CParser::OPT_ERROR; bool rate_name_defined(false); bool tol_defined(false); @@ -336,7 +336,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxKineticsComp::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->rate_name)); @@ -346,14 +346,14 @@ cxxKineticsComp::mpi_pack(std::vector < int >&ints, doubles.push_back(this->m0); doubles.push_back(this->moles); ints.push_back((int) this->d_params.size()); - for (std::vector < double >::iterator it = this->d_params.begin(); + for (std::vector < LDBLE >::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) { doubles.push_back(*it); } } void -cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxKineticsComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -375,7 +375,7 @@ cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive) +cxxKineticsComp::add(const cxxKineticsComp & addee, LDBLE extensive) { if (extensive == 0.0) return; @@ -390,27 +390,27 @@ cxxKineticsComp::add(const cxxKineticsComp & addee, double extensive) //char * rate_name; assert(this->rate_name == addee.rate_name); //cxxNameDouble namecoef; - //double tol; - //double m; + //LDBLE tol; + //LDBLE m; this->m += addee.m * extensive; - //double m0; + //LDBLE m0; this->m0 += addee.m0 * extensive; - //double moles; + //LDBLE moles; this->moles += addee.moles * extensive; - //std::vector d_params; + //std::vector d_params; } void -cxxKineticsComp::multiply(double extensive) +cxxKineticsComp::multiply(LDBLE extensive) { //char * rate_name; //cxxNameDouble namecoef; - //double tol; - //double m; + //LDBLE tol; + //LDBLE m; this->m *= extensive; - //double m0; + //LDBLE m0; this->m0 *= extensive; - //double moles; + //LDBLE moles; this->moles *= extensive; - //std::vector d_params; + //std::vector d_params; } diff --git a/KineticsComp.h b/KineticsComp.h index 33f335e5..231f4cb5 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -36,27 +36,27 @@ public: } const cxxNameDouble &Get_namecoef(void) const {return namecoef;}; - double Get_tol(void) const {return tol;}; - double Get_m(void) const {return m;}; - double Get_m0(void) const {return m0;}; - double Get_moles(void) const {return moles;}; - const std::vector < double > &Get_d_params(void) const {return d_params;}; + LDBLE Get_tol(void) const {return tol;}; + LDBLE Get_m(void) const {return m;}; + LDBLE Get_m0(void) const {return m0;}; + LDBLE Get_moles(void) const {return moles;}; + const std::vector < LDBLE > &Get_d_params(void) const {return d_params;}; #ifdef USE_MPI - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); #endif - void add(const cxxKineticsComp & comp, double extensive); - void multiply(double extensive); + void add(const cxxKineticsComp & comp, LDBLE extensive); + void multiply(LDBLE extensive); protected: std::string rate_name; cxxNameDouble namecoef; //stoichiometry of reaction - double tol; - double m; - double m0; - double moles; - std::vector < double >d_params; + LDBLE tol; + LDBLE m; + LDBLE m0; + LDBLE moles; + std::vector < LDBLE >d_params; public: diff --git a/PPassemblage.cxx b/PPassemblage.cxx index e1e937cc..257d854b 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -59,8 +59,8 @@ cxxNumKeyword(io) // // Mix // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -246,7 +246,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) /* ---------------------------------------------------------------------- */ void cxxPPassemblage::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ @@ -263,7 +263,7 @@ cxxPPassemblage::mpi_pack(std::vector < int >&ints, /* ---------------------------------------------------------------------- */ void -cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxPPassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -303,7 +303,7 @@ cxxPPassemblage::totalize(PHREEQC_PTR_ARG) } void -cxxPPassemblage::add(const cxxPPassemblage & addee, double extensive) +cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) // // Add to existing ppassemblage to "this" ppassemblage // diff --git a/PPassemblage.h b/PPassemblage.h index 9a7d9eaf..9ae894e9 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -48,14 +48,14 @@ class cxxPPassemblage:public cxxNumKeyword cxxPPassemblageComp *Find(const std::string name); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif void totalize(PHREEQC_PTR_ARG); protected: - void add(const cxxPPassemblage & addee, double extensive); + void add(const cxxPPassemblage & addee, LDBLE extensive); // not written void dump_xml(std::ostream & os, unsigned int indent = 0) const; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index fae4aece..a6281774 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -375,7 +375,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; @@ -392,7 +392,7 @@ cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, } void -cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -436,9 +436,9 @@ cxxPPassemblageComp::totalize(PHREEQC_PTR_ARG) void -cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) +cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, LDBLE extensive) { - double ext1, ext2, f1, f2; + LDBLE ext1, ext2, f1, f2; if (extensive == 0.0) return; if (addee.name.size() == 0) @@ -475,15 +475,15 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) error_msg(oss.str().c_str(), CONTINUE); return; } - //double si; + //LDBLE si; this->si = this->si * f1 + addee.si * f2; - //double si_org; + //LDBLE si_org; this->si_org = this->si_org * f1 + addee.si_org * f2; - //double moles; + //LDBLE moles; this->moles += addee.moles * extensive; - //double delta; + //LDBLE delta; this->delta += addee.delta * extensive; - //double initial_moles; + //LDBLE initial_moles; this->initial_moles += addee.initial_moles * extensive; //bool force_equality; //bool dissolve_only; @@ -491,16 +491,16 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, double extensive) } void -cxxPPassemblageComp::multiply(double extensive) +cxxPPassemblageComp::multiply(LDBLE extensive) { //char * name; //char *add_formula; - //double si; - //double moles; + //LDBLE si; + //LDBLE moles; this->moles *= extensive; - //double delta; + //LDBLE delta; this->delta *= extensive; - //double initial_moles; + //LDBLE initial_moles; this->initial_moles *= extensive; //bool force_equality; //bool dissolve_only; diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 2186b96a..9f30d6db 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -42,15 +42,15 @@ class cxxPPassemblageComp: public PHRQ_base void totalize(PHREEQC_PTR_ARG); const cxxNameDouble & Get_totals() const {return (this->totals);} void Get_totals(cxxNameDouble & nd) {this->totals = nd;} - double Get_si() const {return this->si;} + LDBLE Get_si() const {return this->si;} void Set_si(LDBLE t) {this->si = t;} - double Get_si_org() const {return this->si_org;} + LDBLE Get_si_org() const {return this->si_org;} void Set_si_org(LDBLE t) {this->si_org = t;} - double Get_moles() const {return this->moles;} + LDBLE Get_moles() const {return this->moles;} void Set_moles(LDBLE t) {this->moles = t;} - double Get_delta() const {return this->delta;} + LDBLE Get_delta() const {return this->delta;} void Set_delta(LDBLE t) {this->delta = t;} - double Get_initial_moles() const {return this->initial_moles;} + LDBLE Get_initial_moles() const {return this->initial_moles;} void Set_initial_moles(LDBLE t) {this->initial_moles = t;} bool Get_force_equality() const {return this->force_equality;} @@ -61,21 +61,21 @@ class cxxPPassemblageComp: public PHRQ_base void Set_precipitate_only(bool tf) {this->precipitate_only = tf;} - void add(const cxxPPassemblageComp & comp, double extensive); - void multiply(double extensive); + void add(const cxxPPassemblageComp & comp, LDBLE extensive); + void multiply(LDBLE extensive); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif protected: std::string name; std::string add_formula; - double si; - double si_org; - double moles; - double delta; - double initial_moles; + LDBLE si; + LDBLE si_org; + LDBLE moles; + LDBLE delta; + LDBLE initial_moles; bool force_equality; bool dissolve_only; bool precipitate_only; diff --git a/Parser.cxx b/Parser.cxx index 45dd80bc..00882443 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1075,12 +1075,12 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) return PARSER_OK; } -CParser::STATUS_TYPE CParser::addPair(std::map < std::string, double >&totals, +CParser::STATUS_TYPE CParser::addPair(std::map < std::string, LDBLE >&totals, std::istream::pos_type & pos) { std::string token; //char * ctoken; - double + LDBLE d; CParser::TOKEN_TYPE j; diff --git a/Parser.h b/Parser.h index 784a9dd8..52368a95 100644 --- a/Parser.h +++ b/Parser.h @@ -3,7 +3,7 @@ #if defined(WIN32) #include #endif - +#include "phrqtype.h" #include // std::string #include // std::map #include // std::vector @@ -16,6 +16,7 @@ + class CParser: public PHRQ_base { public: @@ -242,7 +243,7 @@ class CParser: public PHRQ_base STATUS_TYPE parse_couple(std::string & token); - STATUS_TYPE addPair(std::map < std::string, double >&totals, + STATUS_TYPE addPair(std::map < std::string, LDBLE >&totals, std::istream::pos_type & pos); protected: diff --git a/Pressure.cxx b/Pressure.cxx index cd34b9ef..8a0a94a3 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -180,7 +180,7 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con { int i = 0; s_oss << indent2; - for (std::vector < double >::const_iterator it = this->pressures.begin(); + for (std::vector < LDBLE >::const_iterator it = this->pressures.begin(); it != this->pressures.end(); it++) { if (i++ == 5) @@ -200,7 +200,7 @@ cxxPressure::read_raw(CParser & parser) { // clear steps for modify operation, if pressures are read bool cleared_once = false; - double d; + LDBLE d; CParser::TOKEN_TYPE k; static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/Pressure.h b/Pressure.h index 22d42323..da9fe36f 100644 --- a/Pressure.h +++ b/Pressure.h @@ -23,14 +23,14 @@ class cxxPressure:public cxxNumKeyword int read(CParser & parser); void read_raw(CParser & parser); LDBLE Pressure_for_step(int step_number); - std::vector & Get_pressures(void) {return pressures;} + std::vector & Get_pressures(void) {return pressures;} int Get_count(void) const; void Set_count(int i) {count = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} protected: - std::vector < double >pressures; + std::vector < LDBLE >pressures; int count; bool equalIncrements; diff --git a/Reaction.cxx b/Reaction.cxx index eede6263..9086ef7b 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -104,7 +104,7 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con { int i = 0; s_oss << indent2; - for (std::vector < double >::const_iterator it = this->steps.begin(); + for (std::vector < LDBLE >::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { if (i++ == 5) @@ -132,7 +132,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) { int j; - double d; + LDBLE d; CParser::TOKEN_TYPE k; static std::vector < std::string > vopts; if (vopts.empty()) diff --git a/Reaction.h b/Reaction.h index 5b3ffe28..99676f9e 100644 --- a/Reaction.h +++ b/Reaction.h @@ -25,7 +25,7 @@ class cxxReaction:public cxxNumKeyword const cxxNameDouble &Get_elementList(void) const {return this->elementList;} void Set_elementList(cxxNameDouble nd) {this->elementList = nd;} cxxNameDouble &Get_reactantList(void) {return this->reactantList;} - std::vector < double > &Get_steps(void) {return this->steps;} + std::vector < LDBLE > &Get_steps(void) {return this->steps;} void Set_steps(std::vector &v) {steps = v;} int Get_actualSteps(void) const; int Get_countSteps(void) const {return this->countSteps;} @@ -45,7 +45,7 @@ class cxxReaction:public cxxNumKeyword protected: cxxNameDouble reactantList; cxxNameDouble elementList; - std::vector < double >steps; + std::vector < LDBLE >steps; int countSteps; bool equalIncrements; std::string units; diff --git a/ReadClass.cxx b/ReadClass.cxx index 1d3cf2f2..63807fe7 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -1445,7 +1445,7 @@ run_as_cells(void) run_info.Set_run_cells(true); dup_print("Beginning of run as cells.", TRUE); - double initial_total_time_save; + LDBLE initial_total_time_save; if (run_info.Get_start_time() != NA) { initial_total_time_save = run_info.Get_start_time(); diff --git a/SS.cxx b/SS.cxx index 87549328..00550f27 100644 --- a/SS.cxx +++ b/SS.cxx @@ -36,7 +36,7 @@ PHRQ_base(io) xb1 = 0; xb2 = 0; //SS_PARAMETER_TYPE type = SS_PARM_NONE; - //double p[4]; + //LDBLE p[4]; } cxxSS::cxxSS(struct s_s *s_s_ptr, PHRQ_io *io) @@ -421,7 +421,7 @@ cxxSS::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxSS::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; ints.push_back(dictionary.string2int(this->name)); @@ -436,7 +436,7 @@ cxxSS::mpi_pack(std::vector < int >&ints, } void -cxxSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSS::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -480,7 +480,7 @@ cxxSS::totalize(PHREEQC_PTR_ARG) } void -cxxSS::add(const cxxSS & addee, double extensive) +cxxSS::add(const cxxSS & addee, LDBLE extensive) { if (extensive == 0.0) return; @@ -492,20 +492,20 @@ cxxSS::add(const cxxSS & addee, double extensive) //char *name; //cxxNameDouble comps; this->comps.add_extensive(addee.comps, extensive); - //double a0, a1; - //double ag0, ag1; + //LDBLE a0, a1; + //LDBLE ag0, ag1; //bool miscibility; - //double xb1, xb2; + //LDBLE xb1, xb2; } void -cxxSS::multiply(double extensive) +cxxSS::multiply(LDBLE extensive) { //char *name; //cxxNameDouble comps; this->comps.multiply(extensive); - //double a0, a1; - //double ag0, ag1; + //LDBLE a0, a1; + //LDBLE ag0, ag1; //bool miscibility; - //double xb1, xb2; + //LDBLE xb1, xb2; } diff --git a/SS.h b/SS.h index 4398d752..88aa5984 100644 --- a/SS.h +++ b/SS.h @@ -6,6 +6,7 @@ #include // std::string #include // std::list #include // std::vector +#include "phrqtype.h" #include "NameDouble.h" #include "Phreeqc_class.h" @@ -61,26 +62,26 @@ class cxxSS: public PHRQ_base }; #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - void add(const cxxSS & comp, double extensive); - void multiply(double extensive); - double Get_a0() const {return (this->a0);}; - double Get_a1() const {return (this->a1);}; - double Get_ag0() const {return (this->ag0);}; - double Get_ag1() const {return (this->ag1);}; + void add(const cxxSS & comp, LDBLE extensive); + void multiply(LDBLE extensive); + LDBLE Get_a0() const {return (this->a0);}; + LDBLE Get_a1() const {return (this->a1);}; + LDBLE Get_ag0() const {return (this->ag0);}; + LDBLE Get_ag1() const {return (this->ag1);}; bool Get_miscibility() const {return (this->miscibility);}; - double Get_xb1() const {return (this->xb1);}; - double Get_xb2() const {return (this->xb2);}; + LDBLE Get_xb1() const {return (this->xb1);}; + LDBLE Get_xb2() const {return (this->xb2);}; protected: std::string name; cxxNameDouble comps; - double a0, a1; - double ag0, ag1; + LDBLE a0, a1; + LDBLE ag0, ag1; bool miscibility; - double xb1, xb2; + LDBLE xb1, xb2; cxxNameDouble totals; public: diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 13db002c..94f70ffd 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -56,8 +56,8 @@ cxxNumKeyword(io) // // Mix // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -223,7 +223,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) /* ---------------------------------------------------------------------- */ void cxxSSassemblage::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ @@ -239,7 +239,7 @@ cxxSSassemblage::mpi_pack(std::vector < int >&ints, /* ---------------------------------------------------------------------- */ void -cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSSassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -277,7 +277,7 @@ cxxSSassemblage::totalize(PHREEQC_PTR_ARG) return; } void -cxxSSassemblage::add(const cxxSSassemblage & addee, double extensive) +cxxSSassemblage::add(const cxxSSassemblage & addee, LDBLE extensive) // // Add to existing ssassemblage to "this" ssassemblage // diff --git a/SSassemblage.h b/SSassemblage.h index 856a3b76..4426e39a 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -38,8 +38,8 @@ public: }; #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif void totalize(PHREEQC_PTR_ARG); @@ -50,7 +50,7 @@ public: protected: - void add(const cxxSSassemblage & addee, double extensive); + void add(const cxxSSassemblage & addee, LDBLE extensive); protected: std::map < std::string, cxxSS > ssAssemblageSSs; diff --git a/Solution.cxx b/Solution.cxx index 354f20e4..ac495b0e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -107,8 +107,8 @@ isotopes(io) // // Mix solutions // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { std::map < int, cxxSolution >::const_iterator sol = @@ -196,7 +196,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const this->master_activity.dump_xml(s_oss, indent + 1); /* { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { s_oss << indent1; s_oss << "first << "\"" ; @@ -209,7 +209,7 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const this->species_gamma.dump_xml(s_oss, indent + 1); /* { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { s_oss << indent1; s_oss << "first << "\"" ; @@ -314,7 +314,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con this->master_activity.dump_raw(s_oss, indent + 2); /* { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { + for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { s_oss << indent2; s_oss << it->first << " " << it->second << "\n"; } @@ -327,7 +327,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con /* { { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { + for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { s_oss << indent2; s_oss << it->first << " " << it->second << "\n"; } @@ -704,17 +704,17 @@ cxxSolution::zero() } void -cxxSolution::add(const cxxSolution & addee, double extensive) +cxxSolution::add(const cxxSolution & addee, LDBLE extensive) // // Add existing solution to "this" solution // { if (extensive == 0.0) return; - double ext1 = this->mass_water; - double ext2 = addee.mass_water * extensive; - double f1 = ext1 / (ext1 + ext2); - double f2 = ext2 / (ext1 + ext2); + LDBLE ext1 = this->mass_water; + LDBLE ext2 = addee.mass_water * extensive; + LDBLE f1 = ext1 / (ext1 + ext2); + LDBLE f2 = ext2 / (ext1 + ext2); this->tc = f1 * this->tc + f2 * addee.tc; this->ph = f1 * this->ph + f2 * addee.ph; this->pe = f1 * this->pe + f2 * addee.pe; @@ -732,7 +732,7 @@ cxxSolution::add(const cxxSolution & addee, double extensive) } void -cxxSolution::multiply(double extensive) +cxxSolution::multiply(LDBLE extensive) // // Multiply existing solution by extensive // @@ -748,7 +748,7 @@ cxxSolution::multiply(double extensive) this->isotopes.multiply(extensive); } -double +LDBLE cxxSolution::Get_total(char *string) const { cxxNameDouble::const_iterator it = this->totals.find(string); @@ -761,11 +761,11 @@ cxxSolution::Get_total(char *string) const return (it->second); } } -double +LDBLE cxxSolution::Get_total_element(const char *string) const { cxxNameDouble::const_iterator it; - double d = 0.0; + LDBLE d = 0.0; for (it = this->totals.begin(); it != this->totals.end(); ++it) { // C++ way to do it @@ -786,12 +786,12 @@ cxxSolution::Get_total_element(const char *string) const } void -cxxSolution::Set_total(char *string, double d) +cxxSolution::Set_total(char *string, LDBLE d) { this->totals[string] = d; } -double +LDBLE cxxSolution::Get_master_activity(char *string) const { cxxNameDouble::const_iterator it = this->master_activity.find(string); @@ -809,7 +809,7 @@ cxxSolution::Get_master_activity(char *string) const /* ---------------------------------------------------------------------- */ void cxxSolution::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) /* ---------------------------------------------------------------------- */ { /* @@ -846,7 +846,7 @@ cxxSolution::mpi_pack(std::vector < int >&ints, int i = ints.size(); int int_array[i]; int d = doubles.size(); - double double_array[d]; + LDBLE double_array[d]; for (int j = 0; j < i; j++) { int_array[j] = ints[j]; } @@ -866,7 +866,7 @@ cxxSolution::mpi_pack(std::vector < int >&ints, /* ---------------------------------------------------------------------- */ void -cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSolution::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -909,10 +909,10 @@ cxxSolution::mpi_send(int task_number) //int count_totals, count_totals_position, count_activity, count_activity_position; int max_size, member_size, position; //int ints[MESSAGE_MAX_NUMBERS]; - //double doubles[MESSAGE_MAX_NUMBERS]; + //LDBLE doubles[MESSAGE_MAX_NUMBERS]; void *buffer; std::vector < int >ints; - std::vector < double >doubles; + std::vector < LDBLE >doubles; /* * Make list of list of ints and doubles from solution structure * This list is not the complete structure, but only enough @@ -972,7 +972,7 @@ cxxSolution::mpi_send(int task_number) int i = (int) ints.size(); int *int_array = new int[i]; int d = (int) doubles.size(); - double *double_array = new double[d]; + LDBLE *double_array = new LDBLE[d]; for (int j = 0; j < i; j++) { int_array[j] = ints[j]; @@ -1034,7 +1034,7 @@ cxxSolution::mpi_recv(int task_number) int count_doubles; MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); - double *doubles = new double[count_doubles]; + LDBLE *doubles = new LDBLE[count_doubles]; MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD); buffer = free_check_null(buffer); @@ -1083,7 +1083,7 @@ cxxSolution::mpi_recv(int task_number) } #endif void -cxxSolution::Set_master_activity(char *string, double d) +cxxSolution::Set_master_activity(char *string, LDBLE d) { this->master_activity[string] = d; } @@ -1116,7 +1116,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina // redox element erase and replace if (master_ptr_secondary != master_ptr) { - double d = it->second; + LDBLE d = it->second; orig_master_activity.erase(orig_master_activity.find(master_ptr->elt->name)); orig_master_activity[master_ptr_secondary->elt->name] = d; redo = true; @@ -1149,7 +1149,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina // redox element erase and replace if (master_ptr_secondary != master_ptr) { - double d = it->second; + LDBLE d = it->second; mod_master_activity.erase(mod_master_activity.find(master_ptr->elt->name)); mod_master_activity[master_ptr_secondary->elt->name] = d; redo = true; @@ -1183,7 +1183,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina } if (strcmp(ename, "H") == 0 || strcmp(ename, "O") == 0) continue; - double d_mod, d_orig; + LDBLE d_mod, d_orig; d_mod = this->Get_total_element(ename); if (d_mod <= 0) continue; @@ -1199,7 +1199,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina } // case where total for both orig and modified are greater than 0 - double lratio = log10(d_mod / d_orig); + LDBLE lratio = log10(d_mod / d_orig); int j; j = master_primary_ptr->number; @@ -1224,7 +1224,7 @@ cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & origina it1 = orig_master_activity.find(P_INSTANCE_POINTER master[j]->elt->name); if (it1 != orig_master_activity.end()) { - double d = it1->second; + LDBLE d = it1->second; mod_master_activity[P_INSTANCE_POINTER master[j]->elt->name] = d + lratio; } else @@ -1279,8 +1279,8 @@ cxxSolution::modify_activities(const cxxSolution & original) { // valence in current and element in original ename = it->first.substr(0, indexCh); - double orig_tot = original.Get_total_element(ename.c_str()); - double tot = this->Get_total_element(ename.c_str()); + LDBLE orig_tot = original.Get_total_element(ename.c_str()); + LDBLE tot = this->Get_total_element(ename.c_str()); if (tot > 0 && orig_tot > 0) { factor[ename] = log10(tot/orig_tot); @@ -1290,7 +1290,7 @@ cxxSolution::modify_activities(const cxxSolution & original) { // element in current and valence in original ename = it->first; - double orig_tot = original.Get_total_element(ename.c_str()); + LDBLE orig_tot = original.Get_total_element(ename.c_str()); if (it->second > 0 && orig_tot > 0) { factor[ename] = log10(it->second/orig_tot); @@ -1306,7 +1306,7 @@ cxxSolution::modify_activities(const cxxSolution & original) if (orig_it != original.Get_master_activity().end()) { // Found exact match - double d = orig_it->second + it->second; + LDBLE d = orig_it->second + it->second; updated_orig_activities[it->first.c_str()] = d; } else @@ -1319,7 +1319,7 @@ cxxSolution::modify_activities(const cxxSolution & original) { if (strstr(orig_it->first.c_str(), v_name.c_str()) == orig_it->first.c_str()) { - double d = orig_it->second + it->second; + LDBLE d = orig_it->second + it->second; updated_orig_activities[orig_it->first.c_str()] = d; } } @@ -1417,12 +1417,12 @@ cxxSolution::Update(const cxxNameDouble &nd) // Exact match if ( it->first == sol_it->first) { - double d = sol_it->second + it->second; + LDBLE d = sol_it->second + it->second; updated_activities[it->first.c_str()] = d; } else if (strstr(v_name.c_str(), sol_it->first.c_str()) == sol_it->first.c_str()) { - double d = sol_it->second + it->second; + LDBLE d = sol_it->second + it->second; updated_activities[sol_it->first.c_str()] = d; } } diff --git a/Solution.h b/Solution.h index 4ee8d1b4..ebc3c836 100644 --- a/Solution.h +++ b/Solution.h @@ -24,99 +24,99 @@ class cxxSolution:public cxxNumKeyword cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSolution(); - double Get_tc() const + LDBLE Get_tc() const { return this->tc; } - void Set_tc(double l_tc) + void Set_tc(LDBLE l_tc) { this->tc = l_tc; } - double Get_ph() const + LDBLE Get_ph() const { return this->ph; } - void Set_ph(double pH) + void Set_ph(LDBLE pH) { this->ph = pH; } - double Get_pe() const + LDBLE Get_pe() const { return this->pe; } - void Set_pe(double l_pe) + void Set_pe(LDBLE l_pe) { this->pe = l_pe; } - double Get_mu() const + LDBLE Get_mu() const { return this->mu; } - void Set_mu(double l_mu) + void Set_mu(LDBLE l_mu) { this->mu = l_mu; } - double Get_ah2o() const + LDBLE Get_ah2o() const { return this->ah2o; } - void Set_ah2o(double l_ah2o) + void Set_ah2o(LDBLE l_ah2o) { this->ah2o = l_ah2o; } - double Get_total_h() const + LDBLE Get_total_h() const { return this->total_h; } - void Set_total_h(double l_total_h) + void Set_total_h(LDBLE l_total_h) { this->total_h = l_total_h; } - double Get_total_o() const + LDBLE Get_total_o() const { return this->total_o; } - void Set_total_o(double l_total_o) + void Set_total_o(LDBLE l_total_o) { this->total_o = l_total_o; } - double Get_cb() const + LDBLE Get_cb() const { return this->cb; } - void Set_cb(double l_cb) + void Set_cb(LDBLE l_cb) { this->cb = l_cb; } - double Get_mass_water() const + LDBLE Get_mass_water() const { return this->mass_water; } - void Set_mass_water(long double l_mass_water) + void Set_mass_water(LDBLE l_mass_water) { this->mass_water = l_mass_water; } - double Get_total_alkalinity() const + LDBLE Get_total_alkalinity() const { return this->total_alkalinity; } - void Set_total_alkalinity(double l_total_alkalinity) + void Set_total_alkalinity(LDBLE l_total_alkalinity) { this->total_alkalinity = l_total_alkalinity; } - double Get_total(char *string) const; - double Get_total_element(const char *string) const; - void Set_total(char *string, double value); + LDBLE Get_total(char *string) const; + LDBLE Get_total_element(const char *string) const; + void Set_total(char *string, LDBLE value); const cxxNameDouble & Get_totals(void) const { @@ -144,41 +144,41 @@ class cxxSolution:public cxxNumKeyword { return this->species_gamma; } - double Get_master_activity(char *string) const; - void Set_master_activity(char *string, double value); + LDBLE Get_master_activity(char *string) const; + void Set_master_activity(char *string, LDBLE value); const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); - void multiply(double extensive); + void multiply(LDBLE extensive); //void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); void modify_activities(const cxxSolution & original); void Simplify_totals(); void Update(const cxxNameDouble &nd); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); void mpi_send(int task_number); void mpi_recv(int task_number); #endif protected: void zero(); - void add(const cxxSolution & addee, double extensive); + void add(const cxxSolution & addee, LDBLE extensive); // not checked void dump_xml(std::ostream & os, unsigned int indent = 0) const; - double tc; - double ph; - double pe; - double mu; - double ah2o; - double total_h; - double total_o; - double cb; - double mass_water; - double total_alkalinity; + LDBLE tc; + LDBLE ph; + LDBLE pe; + LDBLE mu; + LDBLE ah2o; + LDBLE total_h; + LDBLE total_o; + LDBLE cb; + LDBLE mass_water; + LDBLE total_alkalinity; cxxNameDouble totals; //std::list isotopes; cxxNameDouble master_activity; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index c708877f..a082f919 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -214,7 +214,7 @@ cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const void cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr, - double intensive, double extensive) + LDBLE intensive, LDBLE extensive) { if ((this->isotope_number == isotope_ptr.isotope_number) && (this->elt_name == isotope_ptr.elt_name) && @@ -229,7 +229,7 @@ cxxSolutionIsotope::add(const cxxSolutionIsotope & isotope_ptr, } } void -cxxSolutionIsotope::multiply(double extensive) +cxxSolutionIsotope::multiply(LDBLE extensive) { this->total *= extensive; } diff --git a/SolutionIsotope.h b/SolutionIsotope.h index e21ac555..ab698914 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -18,11 +18,11 @@ class cxxSolutionIsotope: public PHRQ_base CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type next_char); - double Get_isotope_number() const + LDBLE Get_isotope_number() const { return this->isotope_number; } - void Set_isotope_number(double d) + void Set_isotope_number(LDBLE d) { this->isotope_number = d; } @@ -48,21 +48,21 @@ class cxxSolutionIsotope: public PHRQ_base else this->isotope_name.clear(); } - double Get_total() const + LDBLE Get_total() const { return this->total; } - void Set_total(double d) + void Set_total(LDBLE d) { this->total = d; } - double Get_ratio() const + LDBLE Get_ratio() const { return this->ratio; } - double Get_ratio_uncertainty() const + LDBLE Get_ratio_uncertainty() const { return this->ratio_uncertainty; } @@ -73,18 +73,18 @@ class cxxSolutionIsotope: public PHRQ_base } bool operator<(const cxxSolutionIsotope & conc) const; - void add(const cxxSolutionIsotope & isotope_ptr, double intensive, - double extensive); - void multiply(double extensive); + void add(const cxxSolutionIsotope & isotope_ptr, LDBLE intensive, + LDBLE extensive); + void multiply(LDBLE extensive); protected: friend class cxxSolutionIsotopeList; - double isotope_number; + LDBLE isotope_number; std::string elt_name; std::string isotope_name; - double total; - double ratio; - double ratio_uncertainty; + LDBLE total; + LDBLE ratio; + LDBLE ratio_uncertainty; bool ratio_uncertainty_defined; }; #endif // SOLUTIONISOTOPE_H_INCLUDED diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx index c1bf00d5..e90417d7 100644 --- a/SolutionIsotopeList.cxx +++ b/SolutionIsotopeList.cxx @@ -37,8 +37,8 @@ cxxSolutionIsotopeList::~cxxSolutionIsotopeList() { } void -cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, - double extensive) +cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, LDBLE intensive, + LDBLE extensive) { for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); itold != old.end(); ++itold) @@ -75,7 +75,7 @@ cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, double intensive, } } void -cxxSolutionIsotopeList::multiply(double extensive) +cxxSolutionIsotopeList::multiply(LDBLE extensive) { for (cxxSolutionIsotopeList::iterator it = this->begin(); it != this->end(); ++it) diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h index 6de61a5a..aff54b89 100644 --- a/SolutionIsotopeList.h +++ b/SolutionIsotopeList.h @@ -18,8 +18,8 @@ public: ~cxxSolutionIsotopeList(); - void add(cxxSolutionIsotopeList oldlist, double intensive, double extensive); - void multiply(double extensive); + void add(cxxSolutionIsotopeList oldlist, LDBLE intensive, LDBLE extensive); + void multiply(LDBLE extensive); protected: diff --git a/StorageBin.cxx b/StorageBin.cxx index 686d3b1d..7f75d2d0 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -904,7 +904,7 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) * mixes solutions based on cxxMix structure, returns new solution * return solution must be freed by calling method */ - double intensive, extensive; + LDBLE intensive, extensive; cxxSolution *cxxsoln_ptr, *cxxsoln_ptr1; /* * Zero out global solution data @@ -915,9 +915,9 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) */ extensive = 0.0; - std::map < int, double >*mixcomps = mixmap.comps(); + std::map < int, LDBLE >*mixcomps = mixmap.comps(); - std::map < int, double >::const_iterator it; + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps->begin(); it != mixcomps->end(); it++) { extensive += it->second; @@ -1049,7 +1049,7 @@ cxxStorageBin::mpi_send(int n, int task_number) // Send data for system n to task_number // std::vector < int >ints; - std::vector < double >doubles; + std::vector < LDBLE >doubles; // Solution if (this->getSolution(n) != NULL) @@ -1152,7 +1152,7 @@ cxxStorageBin::mpi_send(int n, int task_number) int i = (int) ints.size(); //int int_array[i]; int d = (int) doubles.size(); - //double double_array[d]; + //LDBLE double_array[d]; /* for (int j = 0; j < i; j++) { int_array[j] = ints[j]; @@ -1222,7 +1222,7 @@ cxxStorageBin::mpi_recv(int task_number) int count_doubles; MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD); - double *doubles = new double[count_doubles]; + LDBLE *doubles = new LDBLE[count_doubles]; if (count_doubles > 0) { MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, @@ -1318,8 +1318,8 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) */ new_exch_ptr = new cxxExchange(); - std::map < int, double >::const_iterator it_mix; - std::map < int, double >*mixcomps = mixmap.comps(); + std::map < int, LDBLE >::const_iterator it_mix; + std::map < int, LDBLE >*mixcomps = mixmap.comps(); // Pitzer_exchange_gammas it_mix = mixcomps->begin(); @@ -1338,7 +1338,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) * Make list of ExchComps */ std::vector < cxxExchComp > ec_vector; - std::vector < double >f_vector; + std::vector < LDBLE >f_vector; // // make list of all exchange components and their mix fractions // @@ -1372,9 +1372,9 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) { std::vector < cxxExchComp > ec_subvector; - std::vector < double >f_subvector; + std::vector < LDBLE >f_subvector; std::vector < cxxExchComp >::iterator it_ec = ec_vector.begin(); - std::vector < double >::iterator it_f = f_vector.begin(); + std::vector < LDBLE >::iterator it_f = f_vector.begin(); current_formula = NULL; for (; it_ec != ec_vector.end(); it_ec++) { diff --git a/Surface.cxx b/Surface.cxx index e676fd0e..95cc3d0d 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -95,8 +95,8 @@ cxxNumKeyword(io) // // Mix exchangers // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -657,7 +657,7 @@ cxxSurface::read_raw(CParser & parser, bool check) #ifdef USE_MPI /* ---------------------------------------------------------------------- */ void -cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) +cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) /* ---------------------------------------------------------------------- */ { /* int n_user; */ @@ -691,7 +691,7 @@ cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) /* ---------------------------------------------------------------------- */ void -cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSurface::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) /* ---------------------------------------------------------------------- */ { int i = *ii; @@ -751,7 +751,7 @@ cxxSurface::totalize() } void -cxxSurface::add(const cxxSurface & addee, double extensive) +cxxSurface::add(const cxxSurface & addee, LDBLE extensive) // // Add surface to "this" exchange // @@ -768,13 +768,13 @@ cxxSurface::add(const cxxSurface & addee, double extensive) this->sites_units = addee.sites_units; //bool only_counter_ions; this->only_counter_ions = addee.only_counter_ions; - //double thickness; + //LDBLE thickness; this->thickness = addee.thickness; - //double debye_lengths; + //LDBLE debye_lengths; this->debye_lengths = addee.debye_lengths; - //double DDL_viscosity; + //LDBLE DDL_viscosity; this->DDL_viscosity = addee.DDL_viscosity; - //double DDL_limit; + //LDBLE DDL_limit; this->DDL_limit = addee.DDL_limit; //bool transport; this->transport = addee.transport; diff --git a/Surface.h b/Surface.h index 47d49695..2ae15390 100644 --- a/Surface.h +++ b/Surface.h @@ -40,21 +40,21 @@ class cxxSurface:public cxxNumKeyword }; #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - void add(const cxxSurface & addee, double extensive); + void add(const cxxSurface & addee, LDBLE extensive); const std::map < std::string, cxxSurfaceComp > & Get_surfaceComps() const {return this->surfaceComps;}; const std::map < std::string, cxxSurfaceCharge > & Get_surfaceCharges() const {return this->surfaceCharges;}; SURFACE_TYPE Get_type(void) const {return this->type;}; DIFFUSE_LAYER_TYPE Get_dl_type(void) const {return dl_type;}; SITES_UNITS Get_sites_units(void) const {return sites_units;}; bool Get_only_counter_ions(void) const {return only_counter_ions;}; - double Get_thickness(void) const {return thickness;}; - double Get_debye_lengths(void) const {return debye_lengths;}; - double Get_DDL_viscosity(void) const {return DDL_viscosity;}; - double Get_DDL_limit(void) const {return DDL_limit;}; + LDBLE Get_thickness(void) const {return thickness;}; + LDBLE Get_debye_lengths(void) const {return debye_lengths;}; + LDBLE Get_DDL_viscosity(void) const {return DDL_viscosity;}; + LDBLE Get_DDL_limit(void) const {return DDL_limit;}; bool Get_transport(void) const {return transport;}; protected: @@ -64,10 +64,10 @@ protected: enum DIFFUSE_LAYER_TYPE dl_type; enum SITES_UNITS sites_units; bool only_counter_ions; - double thickness; - double debye_lengths; - double DDL_viscosity; - double DDL_limit; + LDBLE thickness; + LDBLE debye_lengths; + LDBLE DDL_viscosity; + LDBLE DDL_limit; bool transport; cxxNameDouble totals; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 320e01e4..64b119a8 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -424,7 +424,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxSurfaceCharge::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; @@ -442,7 +442,7 @@ cxxSurfaceCharge::mpi_pack(std::vector < int >&ints, } void -cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -463,17 +463,17 @@ cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) +cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, LDBLE extensive) { if (extensive == 0.0) return; //char * name; - //double specific_area; - //double grams; - //double charge_balance; - //double mass_water; - //double la_psi, la_psi1, la_psi2; - //double capacitance[2]; + //LDBLE specific_area; + //LDBLE grams; + //LDBLE charge_balance; + //LDBLE mass_water; + //LDBLE la_psi, la_psi1, la_psi2; + //LDBLE capacitance[2]; //char * name; if (this->name.size() == 0 && addee.name.size() == 0) @@ -482,7 +482,7 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) } assert(this->name == addee.name); - double ext1, ext2, f1, f2; + LDBLE ext1, ext2, f1, f2; ext1 = this->specific_area * this->grams; ext2 = addee.specific_area * addee.grams * extensive; if (ext1 + ext2 != 0) @@ -496,19 +496,19 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) f2 = 0.5; } - //double specific_area; + //LDBLE specific_area; this->specific_area = f1 * this->specific_area + f2 * addee.specific_area; - //double grams; + //LDBLE grams; this->grams += addee.grams * extensive; - //double charge_balance; + //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; - //double mass_water; + //LDBLE mass_water; this->mass_water += addee.mass_water * extensive; - //double la_psi, la_psi1, la_psi2; + //LDBLE la_psi, la_psi1, la_psi2; this->la_psi = this->la_psi * f1 + addee.la_psi * f2; this->la_psi1 = this->la_psi1 * f1 + addee.la_psi1 * f2; this->la_psi2 = this->la_psi2 * f1 + addee.la_psi2 * f2; - //double capacitance[2]; + //LDBLE capacitance[2]; this->capacitance[0] = this->capacitance[0] * f1 + this->capacitance[0] * f2; this->capacitance[1] = @@ -516,18 +516,18 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, double extensive) } void -cxxSurfaceCharge::multiply(double extensive) +cxxSurfaceCharge::multiply(LDBLE extensive) { //char * name; - //double specific_area; - //double grams; + //LDBLE specific_area; + //LDBLE grams; this->grams *= extensive; - //double charge_balance; + //LDBLE charge_balance; this->charge_balance *= extensive; - //double mass_water; + //LDBLE mass_water; this->mass_water *= extensive; - //double la_psi, la_psi1, la_psi2; - //double capacitance[2]; + //LDBLE la_psi, la_psi1, la_psi2; + //LDBLE capacitance[2]; //cxxNameDouble diffuse_layer_totals; this->diffuse_layer_totals.multiply(extensive); } diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 5dd746cf..df9014f0 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -37,32 +37,32 @@ public: else this->name.clear(); } - void add(const cxxSurfaceCharge & comp, double extensive); - void multiply(double extensive); + void add(const cxxSurfaceCharge & comp, LDBLE extensive); + void multiply(LDBLE extensive); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - double Get_specific_area() const {return this->specific_area;}; - double Get_grams() const {return this->grams;}; - double Get_charge_balance() const {return this->charge_balance;}; - double Get_mass_water() const {return this->mass_water;}; - double Get_la_psi() const {return this->la_psi;}; - double Get_la_psi1() const {return this->la_psi1;}; - double Get_la_psi2() const {return this->la_psi2;}; - double Get_capacitance0() const {return this->capacitance[0];}; - double Get_capacitance1() const {return this->capacitance[1];}; + LDBLE Get_specific_area() const {return this->specific_area;}; + LDBLE Get_grams() const {return this->grams;}; + LDBLE Get_charge_balance() const {return this->charge_balance;}; + LDBLE Get_mass_water() const {return this->mass_water;}; + LDBLE Get_la_psi() const {return this->la_psi;}; + LDBLE Get_la_psi1() const {return this->la_psi1;}; + LDBLE Get_la_psi2() const {return this->la_psi2;}; + LDBLE Get_capacitance0() const {return this->capacitance[0];}; + LDBLE Get_capacitance1() const {return this->capacitance[1];}; const cxxNameDouble & Get_diffuse_layer_totals(void) const {return this->diffuse_layer_totals;}; protected: std::string name; - double specific_area; - double grams; - double charge_balance; - double mass_water; - double la_psi, la_psi1, la_psi2; - double capacitance[2]; - //std::map g; + LDBLE specific_area; + LDBLE grams; + LDBLE charge_balance; + LDBLE mass_water; + LDBLE la_psi, la_psi1, la_psi2; + LDBLE capacitance[2]; + //std::map g; //char * psi_master_name; cxxNameDouble diffuse_layer_totals; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 08f6e84d..4d66bebf 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -423,7 +423,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxSurfaceComp::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { extern cxxDictionary dictionary; @@ -442,7 +442,7 @@ cxxSurfaceComp::mpi_pack(std::vector < int >&ints, } void -cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxSurfaceComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { extern cxxDictionary dictionary; int i = *ii; @@ -464,7 +464,7 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) +cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) { if (extensive == 0.0) return; @@ -487,7 +487,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) // this and addee must have same formula // otherwise generate a new exchcomp with multiply - double ext1, ext2, f1, f2; + LDBLE ext1, ext2, f1, f2; ext1 = this->moles; ext2 = addee.moles * extensive; if (ext1 + ext2 != 0) @@ -500,16 +500,16 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) f1 = 0.5; f2 = 0.5; } - //double formula_z; + //LDBLE formula_z; - //double moles; + //LDBLE moles; this->moles += addee.moles * extensive; //cxxNameDouble totals; this->totals.add_extensive(addee.totals, extensive); - //double la; + //LDBLE la; this->la = f1 * this->la + f2 * addee.la; //int charge_number; - //double charge_balance; + //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; //char *phase_name; @@ -540,7 +540,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) } else if (this->rate_name.size() != 0) { - //double phase_proportion; + //LDBLE phase_proportion; this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } @@ -554,27 +554,27 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, double extensive) error_msg(oss.str().c_str(), CONTINUE); return; } - //double Dw; + //LDBLE Dw; } void -cxxSurfaceComp::multiply(double extensive) +cxxSurfaceComp::multiply(LDBLE extensive) { //char * formula; //cxxNameDouble formula_totals; - //double formula_z; - //double moles; + //LDBLE formula_z; + //LDBLE moles; this->moles *= extensive; //cxxNameDouble totals; this->totals.multiply(extensive); - //double la; + //LDBLE la; //int charge_number; - //double charge_balance; + //LDBLE charge_balance; this->charge_balance *= extensive; //char *phase_name; - //double phase_proportion; + //LDBLE phase_proportion; //char *rate_name; - //double Dw; + //LDBLE Dw; } const std::string & cxxSurfaceComp::Get_phase_name() const @@ -615,13 +615,13 @@ cxxSurfaceComp::Set_formula(const char * f) else this->formula.clear(); } -double +LDBLE cxxSurfaceComp::Get_charge_balance() const { return this->charge_balance; } void -cxxSurfaceComp::Set_charge_balance(double d) +cxxSurfaceComp::Set_charge_balance(LDBLE d) { this->charge_balance = d; } diff --git a/SurfaceComp.h b/SurfaceComp.h index f7c7ee68..f0637061 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -24,39 +24,39 @@ public: void Set_rate_name(const char * f); const std::string &Get_formula() const; void Set_formula(const char * f); - double Get_charge_balance() const; - void Set_charge_balance(double d); + LDBLE Get_charge_balance() const; + void Set_charge_balance(LDBLE d); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); const cxxNameDouble & Get_totals() const; const cxxNameDouble & Get_formula_totals() const; - double Get_formula_z(void) const {return formula_z;}; - double Get_moles(void) const {return moles;}; - double Get_la(void) const {return la;}; - double Get_phase_proportion(void) const {return phase_proportion;}; - double Get_Dw(void) const {return Dw;}; - void add(const cxxSurfaceComp & comp, double extensive); - void multiply(double extensive); + LDBLE Get_formula_z(void) const {return formula_z;}; + LDBLE Get_moles(void) const {return moles;}; + LDBLE Get_la(void) const {return la;}; + LDBLE Get_phase_proportion(void) const {return phase_proportion;}; + LDBLE Get_Dw(void) const {return Dw;}; + void add(const cxxSurfaceComp & comp, LDBLE extensive); + void multiply(LDBLE extensive); #ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif protected: std::string formula; cxxNameDouble formula_totals; - double formula_z; - double moles; + LDBLE formula_z; + LDBLE moles; cxxNameDouble totals; - double la; + LDBLE la; //int charge_number; - double charge_balance; + LDBLE charge_balance; std::string phase_name; - double phase_proportion; + LDBLE phase_proportion; std::string rate_name; - double Dw; + LDBLE Dw; public: }; diff --git a/Temperature.cxx b/Temperature.cxx index 00a67e61..f16b1565 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -215,7 +215,7 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) { int i = 0; s_oss << indent2; - for (std::vector < double >::const_iterator it = this->temps.begin(); + for (std::vector < LDBLE >::const_iterator it = this->temps.begin(); it != this->temps.end(); it++) { if (i++ == 5) @@ -233,7 +233,7 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxTemperature::read_raw(CParser & parser) { - double d; + LDBLE d; CParser::TOKEN_TYPE k; // clear steps for modify operation, if pressures are read bool cleared_once = false; diff --git a/Temperature.h b/Temperature.h index 68656ac9..96acf6e3 100644 --- a/Temperature.h +++ b/Temperature.h @@ -23,14 +23,14 @@ class cxxTemperature:public cxxNumKeyword void read_raw(CParser & parser); int read(CParser & parser); LDBLE Temperature_for_step(int step_number); - std::vector & Get_temps(void) {return temps;} + std::vector & Get_temps(void) {return temps;} int Get_countTemps(void) const; void Set_countTemps(int i) {countTemps = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} protected: - std::vector < double >temps; + std::vector < LDBLE >temps; int countTemps; bool equalIncrements; diff --git a/Utils.cxx b/Utils.cxx index 86c174f5..ee311679 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -92,13 +92,13 @@ Utilities::squeeze_white(std::string & s_l) s_l = str; } -//+NAN double: 7ff8000000000000 -//-NAN double: fff8000000000000 +//+NAN LDBLE: 7ff8000000000000 +//-NAN LDBLE: fff8000000000000 /* -double Utilities::get_nan(void) +LDBLE Utilities::get_nan(void) { unsigned long long raw = 0x7ff0000000000000; - double d = *( double* )&raw; + LDBLE d = *( LDBLE* )&raw; return(d); } diff --git a/Utils.h b/Utils.h index 89ac681d..b5d93c27 100644 --- a/Utils.h +++ b/Utils.h @@ -31,7 +31,7 @@ namespace Utilities void squeeze_white(std::string & s_l); - double get_nan(void); + LDBLE get_nan(void); //void error_msg(const std::string&, const int stopflag); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 74c36c2e..ef60e559 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -95,8 +95,8 @@ cxxNumKeyword(io) // // Mix // - const std::map < int, double >&mixcomps = mix.Get_mixComps(); - std::map < int, double >::const_iterator it; + const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entities.find(it->first) != entities.end()) @@ -209,7 +209,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co { int i = 0; s_oss << indent2; - for (std::vector < double >::const_iterator it = this->steps.begin(); + for (std::vector < LDBLE >::const_iterator it = this->steps.begin(); it != this->steps.end(); it++) { if (i++ == 5) @@ -229,7 +229,7 @@ void cxxKinetics::read_raw(CParser & parser, bool check) { - double d; + LDBLE d; static std::vector < std::string > vopts; if (vopts.empty()) { @@ -251,7 +251,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) std::string token; int opt_save; bool useLastLine(false); - std::vector < double > temp_steps; + std::vector < LDBLE > temp_steps; // Read kinetics number and description this->read_number_description(parser); @@ -527,7 +527,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) #ifdef USE_MPI void cxxKinetics::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) + std::vector < LDBLE >&doubles) { ints.push_back(this->n_user); ints.push_back((int) this->kineticsComps.size()); @@ -544,7 +544,7 @@ cxxKinetics::mpi_pack(std::vector < int >&ints, } */ ints.push_back((int) this->steps.size()); - for (std::vector < double >::iterator it = this->steps.begin(); + for (std::vector < LDBLE >::iterator it = this->steps.begin(); it != this->steps.end(); it++) { doubles.push_back(*it); @@ -559,7 +559,7 @@ cxxKinetics::mpi_pack(std::vector < int >&ints, } void -cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +cxxKinetics::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { int i = *ii; int d = *dd; @@ -595,7 +595,7 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) } #endif void -cxxKinetics::add(const cxxKinetics & addee, double extensive) +cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) // // Add to existing ppassemblage to "this" ppassemblage // @@ -630,10 +630,10 @@ cxxKinetics::add(const cxxKinetics & addee, double extensive) this->kineticsComps.push_back(entity); } } - //std::vector steps; + //std::vector steps; this->steps = addee.steps; //cxxNameDouble totals; - //double step_divide; + //LDBLE step_divide; this->step_divide = addee.step_divide; //int rk; this->rk = addee.rk; diff --git a/cxxKinetics.h b/cxxKinetics.h index 1657a0ee..e1758f7b 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -6,7 +6,7 @@ #include // std::string #include // std::list #include // std::vector - +#include "phrqtype.h" #include "NumKeyword.h" #include "KineticsComp.h" #include "PHRQ_base.h" @@ -31,8 +31,8 @@ class cxxKinetics:public cxxNumKeyword //bool Get_related_phases(void) const; //bool Get_related_rate(void) const; - const std::vector < double > &Get_steps(void) const {return steps;}; - double Get_step_divide(void) const {return step_divide;}; + const std::vector < LDBLE > &Get_steps(void) const {return steps;}; + LDBLE Get_step_divide(void) const {return step_divide;}; int Get_rk(void) const {return rk;}; int Get_bad_step_max(void) const {return bad_step_max;}; bool Get_use_cvode(void) const {return use_cvode;}; @@ -44,18 +44,18 @@ class cxxKinetics:public cxxNumKeyword #ifdef USE_MPI - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); #endif protected: - void add(const cxxKinetics & addee, double extensive); + void add(const cxxKinetics & addee, LDBLE extensive); protected: std::list < cxxKineticsComp > kineticsComps; - std::vector < double >steps; + std::vector < LDBLE >steps; int equal_steps; cxxNameDouble totals; - double step_divide; + LDBLE step_divide; int rk; int bad_step_max; bool use_cvode; diff --git a/cxxMix.cxx b/cxxMix.cxx index 6e7a28e5..3f5a76e5 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -86,7 +86,7 @@ cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const int n_user_local = (n_out != NULL) ? *n_out : this->n_user; s_oss << "MIX " << n_user_local << " " << this->description << "\n"; - for (std::map < int, double >::const_iterator it = this->mixComps.begin(); + for (std::map < int, LDBLE >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { s_oss << indent1 << it->first << " " << it->second << "\n"; @@ -98,7 +98,7 @@ cxxMix::read_raw(CParser & parser) { int i; - double d; + LDBLE d; static std::vector < std::string > vopts; if (vopts.empty()) { @@ -181,7 +181,7 @@ void cxxMix::Vectorize(std::vector &n, std::vector &f) { n.clear(); f.clear(); - for (std::map < int, double >::const_iterator it = this->mixComps.begin(); + for (std::map < int, LDBLE >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) { n.push_back(it->first); diff --git a/runner.h b/runner.h index 60c71c2e..5cc2e61b 100644 --- a/runner.h +++ b/runner.h @@ -3,6 +3,7 @@ #include // std::set #include // std::string +#include "phrqtype.h" #include "StorageBinList.h" #include "PHRQ_base.h" class CParser; @@ -15,14 +16,14 @@ public: virtual ~runner(void); bool Read(CParser & parser); StorageBinListItem & Get_cells(void) { return(this->cells); }; - double Get_time_step() { return(this->time_step); }; - double Get_start_time() { return(this->start_time); }; + LDBLE Get_time_step() { return(this->time_step); }; + LDBLE Get_start_time() { return(this->start_time); }; bool Get_run_cells() { return(this->run_cells); }; void Set_run_cells(bool tf) { this->run_cells = tf; }; protected: - double time_step; - double start_time; + LDBLE time_step; + LDBLE start_time; StorageBinListItem cells; bool run_cells; }; From f108e75a4f8f604b954d6878ee887fe822e28627 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Jan 2012 00:00:54 +0000 Subject: [PATCH 0418/1077] long double mismatch git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6044 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 1d009f17..9d2c9162 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -155,7 +155,6 @@ void cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; - LDBLE d; static std::vector < std::string > vopts; if (vopts.empty()) @@ -283,8 +282,9 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case 6: // d_params while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - sscanf(token.c_str(), "%lf", &d); - temp_d_params.push_back(d); + double dd; + sscanf(token.c_str(), "%lf", &dd); + temp_d_params.push_back((LDBLE) dd); d_params_defined = true; } opt_save = 6; From 875a5f1a487c40af2415bf38f75db7d55f0243d0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Jan 2012 15:59:11 +0000 Subject: [PATCH 0419/1077] floating point exceptions on Linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6048 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 3a87f246..dab40dec 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -9,8 +9,8 @@ #include "GasPhase.h" #include "SSassemblage.h" #include "cxxKinetics.h" - - +#include +#include /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ @@ -21,7 +21,8 @@ main(int argc, char *argv[]) */ { - //int errors; + // check for floating point exceptions on Linux + // feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW); #if defined(WIN32_MEMORY_DEBUG) int tmpDbgFlag; From 549ba5c2b3dafc60e265284274a33533908c60ec Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Jan 2012 18:27:42 +0000 Subject: [PATCH 0420/1077] Jonathan Toner changes for low temperature pitzer included as comments. Change when his paper is published. Windows fp exception checker. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6052 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index dab40dec..77618e7c 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -9,8 +9,8 @@ #include "GasPhase.h" #include "SSassemblage.h" #include "cxxKinetics.h" -#include -#include +//#include +//#include /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ @@ -38,7 +38,28 @@ main(int argc, char *argv[]) _CrtSetDbgFlag(tmpDbgFlag); //_crtBreakAlloc = 9482; #endif - +#ifdef SKIP +//Set the x86 floating-point control word according to what +//exceptions you want to trap. +_clearfp(); //Always call _clearfp before setting the control + //word +//Because the second parameter in the following call is 0, it +//only returns the floating-point control word +unsigned int cw = _controlfp(0, 0); //Get the default control + //word +//Set the exception masks off for exceptions that you want to +//trap. When a mask bit is set, the corresponding floating-point +//exception is //blocked from being generating. +cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE| + EM_DENORMAL|EM_INVALID); +//For any bit in the second parameter (mask) that is 1, the +//corresponding bit in the first parameter is used to update +//the control word. +unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. + //MCW_EM is defined in float.h. + //Restore the original value when done: + //_controlfp(cwOriginal, MCW_EM); +#endif Phreeqc phreeqc_instance; phreeqc_instance.main_method(argc, argv); } From f5b51e1db85a9249dda47f4fa32f145c400f5ef4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 12 Jan 2012 21:51:18 +0000 Subject: [PATCH 0421/1077] moved -r6061 http://internalbrr.cr.usgs.gov/svn_GW/phreeqc/branches/rename_cpp to http://internalbrr.cr.usgs.gov/svn_GW/phreeqcpp/branches/ErrorHandling/src/rename_cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6062 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- rename_cpp/Form1.h | 1050 +++ rename_cpp/Form1.resX | 33 + rename_cpp/Makefile | 237 + rename_cpp/NA.h | 1 + rename_cpp/PHRQ_io_output.cpp | 794 ++ rename_cpp/ZedGraph.dll | Bin 0 -> 307200 bytes rename_cpp/advection.cpp | 125 + rename_cpp/basicsubs.cpp | 3061 ++++++++ rename_cpp/chart_icon.gif | Bin 0 -> 2141 bytes rename_cpp/cl1.cpp | 890 +++ rename_cpp/cl1mp.cpp | 1131 +++ rename_cpp/cvdense.cpp | 504 ++ rename_cpp/cvdense.h | 223 + rename_cpp/cvode.cpp | 3780 ++++++++++ rename_cpp/cvode.h | 892 +++ rename_cpp/dense.cpp | 124 + rename_cpp/dense.h | 297 + rename_cpp/distribution.checklist | 85 + rename_cpp/distribution.mk | 391 + rename_cpp/dw.cpp | 414 ++ rename_cpp/gases.cpp | 675 ++ rename_cpp/global_structures.h | 1350 ++++ rename_cpp/input.cpp | 127 + rename_cpp/integrate.cpp | 1247 ++++ rename_cpp/inverse.cpp | 5155 +++++++++++++ rename_cpp/isotopes.cpp | 1852 +++++ rename_cpp/kinetics.cpp | 2983 ++++++++ rename_cpp/mainsubs.cpp | 3520 +++++++++ rename_cpp/model.cpp | 5576 +++++++++++++++ rename_cpp/newiso.dat | 5565 +++++++++++++++ rename_cpp/nvector.cpp | 220 + rename_cpp/nvector.h | 441 ++ rename_cpp/nvector_serial.cpp | 978 +++ rename_cpp/nvector_serial.h | 325 + rename_cpp/parse.cpp | 1048 +++ rename_cpp/phqalloc.cpp | 292 + rename_cpp/phqalloc.h | 47 + rename_cpp/phreeqc.rev | 4579 ++++++++++++ rename_cpp/phreex.ico | Bin 0 -> 318 bytes rename_cpp/phrqtype.h | 18 + rename_cpp/pitzer.cpp | 2210 ++++++ rename_cpp/pitzer_structures.cpp | 306 + rename_cpp/prep.cpp | 6663 +++++++++++++++++ rename_cpp/print.cpp | 3586 ++++++++++ rename_cpp/read.cpp | 10732 ++++++++++++++++++++++++++++ rename_cpp/readtr.cpp | 1234 ++++ rename_cpp/revisions | 3102 ++++++++ rename_cpp/sit.cpp | 1357 ++++ rename_cpp/smalldense.cpp | 270 + rename_cpp/smalldense.h | 217 + rename_cpp/spread.cpp | 1335 ++++ rename_cpp/step.cpp | 1747 +++++ rename_cpp/structures.cpp | 7451 +++++++++++++++++++ rename_cpp/sundialsmath.cpp | 82 + rename_cpp/sundialsmath.h | 118 + rename_cpp/sundialstypes.h | 143 + rename_cpp/tally.cpp | 1403 ++++ rename_cpp/tidy.cpp | 5032 +++++++++++++ rename_cpp/transport.cpp | 6311 ++++++++++++++++ rename_cpp/utilities.cpp | 1842 +++++ 60 files changed, 105171 insertions(+) create mode 100644 rename_cpp/Form1.h create mode 100644 rename_cpp/Form1.resX create mode 100644 rename_cpp/Makefile create mode 100644 rename_cpp/NA.h create mode 100644 rename_cpp/PHRQ_io_output.cpp create mode 100644 rename_cpp/ZedGraph.dll create mode 100644 rename_cpp/advection.cpp create mode 100644 rename_cpp/basicsubs.cpp create mode 100644 rename_cpp/chart_icon.gif create mode 100644 rename_cpp/cl1.cpp create mode 100644 rename_cpp/cl1mp.cpp create mode 100644 rename_cpp/cvdense.cpp create mode 100644 rename_cpp/cvdense.h create mode 100644 rename_cpp/cvode.cpp create mode 100644 rename_cpp/cvode.h create mode 100644 rename_cpp/dense.cpp create mode 100644 rename_cpp/dense.h create mode 100644 rename_cpp/distribution.checklist create mode 100644 rename_cpp/distribution.mk create mode 100644 rename_cpp/dw.cpp create mode 100644 rename_cpp/gases.cpp create mode 100644 rename_cpp/global_structures.h create mode 100644 rename_cpp/input.cpp create mode 100644 rename_cpp/integrate.cpp create mode 100644 rename_cpp/inverse.cpp create mode 100644 rename_cpp/isotopes.cpp create mode 100644 rename_cpp/kinetics.cpp create mode 100644 rename_cpp/mainsubs.cpp create mode 100644 rename_cpp/model.cpp create mode 100644 rename_cpp/newiso.dat create mode 100644 rename_cpp/nvector.cpp create mode 100644 rename_cpp/nvector.h create mode 100644 rename_cpp/nvector_serial.cpp create mode 100644 rename_cpp/nvector_serial.h create mode 100644 rename_cpp/parse.cpp create mode 100644 rename_cpp/phqalloc.cpp create mode 100644 rename_cpp/phqalloc.h create mode 100644 rename_cpp/phreeqc.rev create mode 100644 rename_cpp/phreex.ico create mode 100644 rename_cpp/phrqtype.h create mode 100644 rename_cpp/pitzer.cpp create mode 100644 rename_cpp/pitzer_structures.cpp create mode 100644 rename_cpp/prep.cpp create mode 100644 rename_cpp/print.cpp create mode 100644 rename_cpp/read.cpp create mode 100644 rename_cpp/readtr.cpp create mode 100644 rename_cpp/revisions create mode 100644 rename_cpp/sit.cpp create mode 100644 rename_cpp/smalldense.cpp create mode 100644 rename_cpp/smalldense.h create mode 100644 rename_cpp/spread.cpp create mode 100644 rename_cpp/step.cpp create mode 100644 rename_cpp/structures.cpp create mode 100644 rename_cpp/sundialsmath.cpp create mode 100644 rename_cpp/sundialsmath.h create mode 100644 rename_cpp/sundialstypes.h create mode 100644 rename_cpp/tally.cpp create mode 100644 rename_cpp/tidy.cpp create mode 100644 rename_cpp/transport.cpp create mode 100644 rename_cpp/utilities.cpp diff --git a/rename_cpp/Form1.h b/rename_cpp/Form1.h new file mode 100644 index 00000000..af14fe82 --- /dev/null +++ b/rename_cpp/Form1.h @@ -0,0 +1,1050 @@ +#pragma once +#include +#define P_INSTANCE_POINTER1 phreeqc_ptr-> +namespace zdg_ui2 { + using namespace System; + //using namespace System::ComponentModel; + using namespace System::Resources; + using namespace System::Windows::Forms; + using namespace System::Drawing; + using namespace System::Threading; + using namespace ZedGraph; + +// Form1 is only used with MULTICHART + public ref class ChartObj : public System::Object + { + public: Phreeqc* phreeqc_ptr; + public: ChartObject* chartobject_ptr; + public: ChartObj(ChartObject* ptr) + { + this->chartobject_ptr = ptr; + this->phreeqc_ptr = this->chartobject_ptr->Get_phreeqc(); + } + }; + + public ref class Form1 : public System::Windows::Forms::Form + { + public: long int tickStart; + public: Form1 ^myForm; + public: Form1() + { + InitializeComponent(); + col_use = 0; + symbol_use = 0; + Y2 = false; + phreeqc_done = false; + + } + public: Form1(ChartObject *ptr) + { + this->chartobject_ptr = ptr; + this->phreeqc_ptr = chartobject_ptr->Get_phreeqc(); + InitializeComponent(); + col_use = 0; + symbol_use = 0; + Y2 = false; + phreeqc_done = false; + Y2show = false; + } + static void ThreadForm(Object^ data) + { + ChartObject *ptr = ((ChartObj^)(data))->chartobject_ptr; + Form1 ^myForm = gcnew Form1(ptr); + myForm->ShowDialog(); + myForm->~Form1(); + } + private: bool phreeqc_done; + + private: void SetSize() + { + zg1->Location = Point( 0, 0 ); + // Leave a small margin around the outside of the control + zg1->Size = System::Drawing::Size( ClientRectangle.Width - 0, + ClientRectangle.Height - 0 ); + } + + System::Void MyFormClosingEventHandler( + System::Object^ sender, + System::Windows::Forms::FormClosingEventArgs ^e) + { + ChartObject *chart = this->chartobject_ptr; + if (chart != NULL) + { + chart->Set_done(true); + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + } + this->phreeqc_ptr = NULL; + this->chartobject_ptr = NULL; + } + + System::Void Form1_Load(System::Object ^sender, System::EventArgs ^e) + { + CreateGraph( zg1 ); + SetSize(); + } + + System::Void Form1_Resize(System::Object ^sender, System::EventArgs ^e) + { + SetSize(); + } + + //static bool LogX, LogY, LogY2; + bool LogX, LogY, LogY2; + private: bool check_neg_log( int i, int i2) + { + ChartObject *chart = this->chartobject_ptr; + if (chart == NULL) return false; + std::vector &Curves = chart->Get_Curves(); + if (LogX && chart->Get_axis_scale_x()[4] == 10.0 && + Curves[i]->Get_x()[i2] <= 0) + { + P_INSTANCE_POINTER1 warning_msg("Obtained x_value <= 0, removing point..."); + //axis_scale_x[4] = NA; /* if reverting to linear... */ + //LogX = false; + return true; + } + if (Curves[i]->Get_y()[i2] <= 0 && + (chart->Get_axis_scale_y()[4] == 10.0 || + chart->Get_axis_scale_y2()[4] == 10.0)) + { + if (Curves[i]->Get_y_axis() == 2 && LogY2) + { + P_INSTANCE_POINTER1 warning_msg("Obtained sy_value <= 0, removing point......"); + //axis_scale_y2[4] = NA; + //LogY2 = false; + return true; + } + else if (LogY) + { + P_INSTANCE_POINTER1 warning_msg("Obtained y_value <= 0, removing point......"); + //axis_scale_y[4] = NA; + //LogY = false; + return true; + } + } + return false; + } + + private: PointPairList ^list; + int col_use, symbol_use; + bool Y2, Y2show; + static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; + + void DefineCurves(GraphPane ^myPane, int init) + { + ChartObject *chart = this->chartobject_ptr; + if (chart == NULL) + { + return; + } + std::vector Curves; + size_t i; + for (i = 0; i < chart->Get_CurvesCSV().size(); i++) + { + Curves.push_back(chart->Get_CurvesCSV()[i]); + } + for (i = 0; i < chart->Get_Curves().size(); i++) + { + Curves.push_back(chart->Get_Curves()[i]); + } + + chart->Set_curve_added(false); + + // Set the titles and axis labels + myPane->Title->Text = gcnew String(chart->Get_chart_title().c_str()); + if (chart->Get_axis_titles().size() > 0) + myPane->XAxis->Title->Text = gcnew String(chart->Get_axis_titles()[0].c_str()); + if (chart->Get_axis_titles().size() > 1) + myPane->YAxis->Title->Text = gcnew String(chart->Get_axis_titles()[1].c_str()); + if (chart->Get_axis_titles().size() > 2) + myPane->Y2Axis->Title->Text = gcnew String(chart->Get_axis_titles()[2].c_str()); + + LineItem ^myCurve; + + Color col; + + String ^s_t; + if (chart->Get_axis_scale_x()[4] == 10.0) LogX = true; + else LogX = false; + if (chart->Get_axis_scale_y()[4] == 10.0) LogY = true; + else LogY = false; + if (chart->Get_axis_scale_y2()[4] == 10.0) LogY2 = true; + else LogY2 = false; + + //Rewrite all curves + zg1->GraphPane->CurveList->Clear(); + for (size_t i = 0; i < Curves.size(); i++) + { + // even curves with no data + //if (Curves[i]->Get_x().size() == 0) continue; + list = gcnew PointPairList(); + if (Curves[i]->Get_y_axis() == 2) + { + Y2 = true; + Y2show = true; + } + else + Y2 = false; + for (int i2 = 0; (i2 < (int) Curves[i]->Get_x().size()); i2++) + { + if ((LogX && Curves[i]->Get_x()[i2] <=0) + || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + continue; + else + list->Add( Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + } + + col = Color::FromName(gcnew String(Curves[i]->Get_color().c_str())); + if (!col.IsKnownColor) + { + col = Color::FromName(ColorList[col_use]); + std::string newcol; + ToString(col.ToString(), newcol); + Utilities::replace("Color [","",newcol); + Utilities::replace("]","",newcol); + Curves[i]->Set_color(newcol); + + } + if (++col_use > 6) col_use = 0; + + SymbolType symb = chart->Return_SymbolType + (Curves[i]->Get_symbol()); + + // id + s_t = gcnew String(Curves[i]->Get_id().c_str()); + + + // Add curve to chart + myCurve = myPane->AddCurve( s_t, list, col, symb ); + + + // Curve with no points is invisible + if (Curves[i]->Get_x().size() == 0) + { + myCurve->IsVisible = false; + myCurve->Label->IsVisible = false; + } + + if (Curves[i]->Get_line_w() > 0.0) + myCurve->Line->Width = (float) Curves[i]->Get_line_w(); + else + myCurve->Line->IsVisible = false; + /* hmm... dash/dot don't display well */ + // myCurve->Line->Style = System::Drawing::Drawing2D::DashStyle::Dot; + myCurve->Symbol->Fill = gcnew Fill( Color::FromName("White") ); + if (Curves[i]->Get_symbol_size() > 0.0) + myCurve->Symbol->Size = (float) Curves[i]->Get_symbol_size(); + else + myCurve->Symbol->IsVisible = false; + myCurve->Symbol->Border->Width = (float) Curves[i]->Get_line_w(); + if (Y2) + myCurve->IsY2Axis = true; + delete list; + } + + if (Y2show) + myPane->Legend->Position = ZedGraph::LegendPos::TopCenter; + else + myPane->Legend->Position = ZedGraph::LegendPos::Right; + myPane->Legend->FontSpec->Size = 12; + myPane->Legend->FontSpec->IsBold = false; + + // Show the x axis grid + myPane->XAxis->MajorGrid->IsVisible = true; + if (fabs(chart->Get_axis_scale_x()[0] - NA) > 1e-3) + myPane->XAxis->Scale->Min = chart->Get_axis_scale_x()[0]; + else + myPane->XAxis->Scale->MinAuto = true; + if (fabs(chart->Get_axis_scale_x()[1] - NA) > 1e-3) + myPane->XAxis->Scale->Max = chart->Get_axis_scale_x()[1]; + else + myPane->XAxis->Scale->MaxAuto = true; + if (fabs(chart->Get_axis_scale_x()[2] - NA) > 1e-3) + myPane->XAxis->Scale->MajorStep = chart->Get_axis_scale_x()[2]; + else + myPane->XAxis->Scale->MajorStepAuto = true; + if (fabs(chart->Get_axis_scale_x()[3] - NA) > 1e-3) + { + myPane->XAxis->Scale->MinorStep = chart->Get_axis_scale_x()[3]; + if (chart->Get_axis_scale_x()[3] == 0.0) + // remove minor tics + myPane->XAxis->MinorTic->Size = 0; + } + else + myPane->XAxis->Scale->MinorStepAuto = true; + if (chart->Get_axis_scale_x()[4] == 10.0) + myPane->XAxis->Type = AxisType::Log; + + // Make the Y axis scale red + // myPane->YAxis->Scale->FontSpec->FontColor = Color::Red; + // myPane->YAxis->Title->FontSpec->FontColor = Color::Red; + // turn off the opposite tics so the Y tics don't show up on the Y2 axis + if (Y2show) + { + myPane->YAxis->MajorTic->IsOpposite = false; + myPane->YAxis->MinorTic->IsOpposite = false; + } + // Don't display the Y zero line + myPane->YAxis->MajorGrid->IsZeroLine = false; + // Align the Y axis labels so they are flush to the axis + myPane->YAxis->Scale->Align = AlignP::Inside; + myPane->YAxis->MajorGrid->IsVisible = true; + if (fabs(chart->Get_axis_scale_y()[0] - NA) > 1e-3) + myPane->YAxis->Scale->Min = chart->Get_axis_scale_y()[0]; + else + myPane->YAxis->Scale->MinAuto = true; + if (fabs(chart->Get_axis_scale_y()[1] - NA) > 1e-3) + myPane->YAxis->Scale->Max = chart->Get_axis_scale_y()[1]; + else + myPane->YAxis->Scale->MaxAuto = true; + if (fabs(chart->Get_axis_scale_y()[2] - NA) > 1e-3) + myPane->YAxis->Scale->MajorStep = chart->Get_axis_scale_y()[2]; + else + myPane->YAxis->Scale->MajorStepAuto = true; + if (fabs(chart->Get_axis_scale_y()[3] - NA) > 1e-3) + { + myPane->YAxis->Scale->MinorStep = chart->Get_axis_scale_y()[3]; + if (chart->Get_axis_scale_y()[3] == 0.0) + // remove minor tics + myPane->YAxis->MinorTic->Size = 0; + } + else + myPane->YAxis->Scale->MinorStepAuto = true; + if (chart->Get_axis_scale_y()[4] == 10.0) + myPane->YAxis->Type = AxisType::Log; + + // Enable the Y2 axis display + if (Y2show) + { + myPane->Y2Axis->IsVisible = true; + // Make the Y2 axis scale blue + // myPane->Y2Axis->Scale->FontSpec->FontColor = Color::Blue; + // myPane->Y2Axis->Title->FontSpec->FontColor = Color::Blue; + // turn off the opposite tics so the Y2 tics don't show up on the Y axis + myPane->Y2Axis->MajorTic->IsOpposite = false; + myPane->Y2Axis->MinorTic->IsOpposite = false; + // Don't display the Y2 axis grid lines + myPane->Y2Axis->MajorGrid->IsVisible = false; + // Align the Y2 axis labels so they are flush to the axis + myPane->Y2Axis->Scale->Align = AlignP::Inside; + + if (fabs(chart->Get_axis_scale_y2()[0] - NA) > 1e-3) + myPane->Y2Axis->Scale->Min = chart->Get_axis_scale_y2()[0]; + else + myPane->Y2Axis->Scale->MinAuto = true; + if (fabs(chart->Get_axis_scale_y2()[1] - NA) > 1e-3) + myPane->Y2Axis->Scale->Max = chart->Get_axis_scale_y2()[1]; + else + myPane->Y2Axis->Scale->MaxAuto = true; + if (fabs(chart->Get_axis_scale_y2()[2] - NA) > 1e-3) + myPane->Y2Axis->Scale->MajorStep = chart->Get_axis_scale_y2()[2]; + else + myPane->Y2Axis->Scale->MajorStepAuto = true; + if (fabs(chart->Get_axis_scale_y2()[3] - NA) > 1e-3) + { + myPane->Y2Axis->Scale->MinorStep = chart->Get_axis_scale_y2()[3]; + if (chart->Get_axis_scale_y2()[3] == 0.0) + // remove minor tics + myPane->Y2Axis->MinorTic->Size = 0; + } + else + myPane->Y2Axis->Scale->MinorStepAuto = true; + if (chart->Get_axis_scale_y2()[4] == 10.0) + myPane->Y2Axis->Type = AxisType::Log; + } + + myPane->XAxis->MinorTic->IsOutside = false; + myPane->XAxis->MajorTic->IsOutside = false; + myPane->YAxis->MinorTic->IsOutside = false; + myPane->YAxis->MajorTic->IsOutside = false; + myPane->Y2Axis->MinorTic->IsOutside = false; + myPane->Y2Axis->MajorTic->IsOutside = false; + + // Fill the axis background with a gradient + //myPane->Chart->Fill = gcnew Fill( Color::White, Color::LightYellow, 45.0f ); /* FromArgb(255, 255, 224) */ + myPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + + // normalize pane size... + myPane->BaseDimension = 8.0F; + // increase bottom margin to accommodate text options... + myPane->Margin->Bottom = 15.0F; + + // Make sure auto scale, Refresh + zg1->AxisChange(); + zg1->Refresh(); + + } + + public: void CreateGraph( ZedGraphControl ^z1 ) { + // Get a reference to the GraphPane instance in the ZedGraphControl + GraphPane ^myPane = z1->GraphPane; + + // lock thread + while (0 != System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 1)) + System::Threading::Thread::Sleep(1); + + DefineCurves(myPane, 0); + + // Add text boxes with instructions... + TextObj ^text; + text = gcnew TextObj( + L" Click right mouse for options... \0", + 0.01f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); + text->FontSpec->StringAlignment = StringAlignment::Near; + text->FontSpec->Size = 10; + text->FontSpec->FontColor = Color::Red; + text->ZOrder = ZOrder::H_BehindAll; + myPane->GraphObjList->Add( text ); + text = gcnew TextObj( + L" Press Alt + F4 to quit", + 0.81f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); + text->FontSpec->StringAlignment = StringAlignment::Near; + text->FontSpec->Size = 10; + text->FontSpec->FontColor = Color::Red; + text->ZOrder = ZOrder::H_BehindAll; + myPane->GraphObjList->Add( text ); + + // Enable scrollbars if needed... + /*z1->IsShowHScrollBar = true; + z1->IsShowVScrollBar = true; + z1->IsAutoScrollRange = true; + z1->IsScrollY2 = true;*/ + + // OPTIONAL: Show tooltips when the mouse hovers over a point + z1->IsShowPointValues = false; + z1->PointValueEvent += gcnew ZedGraphControl::PointValueHandler( this, + &Form1::MyPointValueHandler ); + + // OPTIONAL: Add a custom context menu item + z1->ContextMenuBuilder += gcnew ZedGraphControl::ContextMenuBuilderEventHandler( + this, &Form1::MyContextMenuBuilder ); + + // OPTIONAL: Handle the Zoom Event + z1->ZoomEvent += gcnew ZedGraphControl::ZoomEventHandler( this, + &Form1::MyZoomEvent ); + + // Size the control to fit the window + SetSize(); + + // Tell ZedGraph to calculate the axis ranges + // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets + // up the proper scrolling parameters + + z1->AxisChange(); + // Make sure the Graph gets redrawn + z1->Invalidate(); + timer1->Interval = this->chartobject_ptr->Get_update_time_chart(); + timer1->Enabled = true; + timer1->Start(); + + tickStart = Environment::TickCount; + + //unlock thread + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + } + + /// + /// Display customized tooltips when the mouse hovers over a point + /// + System::String ^MyPointValueHandler( ZedGraphControl ^control, GraphPane ^pane, + CurveItem ^curve, int iPt ) { + // Get the PointPair that is under the mouse + PointPair pt = curve[iPt]; + return curve->Label->Text + " is " + pt.Y.ToString( "e3" ) + " units at X = " + pt.X.ToString( "e3" ); + } + + // Add some explanation to the menu.. + void MyContextMenuBuilder( ZedGraphControl ^control, + System::Windows::Forms::ContextMenuStrip ^menuStrip, + Point mousePt, + ZedGraphControl::ContextMenuObjectState objState ) { + ToolStripMenuItem ^item = gcnew ToolStripMenuItem(); + item->Text = L"Zoom: left mouse + drag\nPan: middle mouse + drag"; + menuStrip->Items->Insert(5, item ); + + menuStrip->Items->RemoveAt(0); + ToolStripMenuItem ^item2 = gcnew ToolStripMenuItem(); + item2->Text = L"Save Data to File..."; + item2->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SaveCurves ); + menuStrip->Items->Insert(0, item2 ); + + } + + void form_error_msg( std::string estring ) + { + if (this->chartobject_ptr != NULL) + { + P_INSTANCE_POINTER1 error_msg(estring.c_str(), CONTINUE); + } + else + { + std::cerr << "ERROR: " << estring << std::endl; + } + } +#ifdef SKIP + void SaveCurves( System::Object ^sender, System::EventArgs ^e ) + { + std::string file_name = "curves.u_g"; + // Get the graph curves... + std::ofstream f_out(file_name.c_str(), std::ifstream::out); + + if (!f_out.is_open()) + { + std::ostringstream estream; + estream << "Could not open csv file for USER_GRAPH " << file_name; + form_error_msg(estream.str()); + return; + } + + // write headings + size_t max_points = 0; + f_out.precision(4); + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + LineItem ^curve; + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + + // Calculate max_points + if ((size_t) ip->Count > max_points) + max_points = ip->Count; + + // write headers + std::string s_std; + ToString(curve->Label->Text, s_std); + f_out.width(12); + f_out << "x" << "\t"; + f_out.width(12); + if (s_std.size() > 0) + { + f_out << s_std << "\t"; + } + else + { + f_out << "y" << "\t"; + } + } + + f_out << std::endl; + + // write data + size_t i2 = 0; + f_out << std::scientific; + f_out.precision(4); + + while (i2 < max_points) + { + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + LineItem ^curve; + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + if (i2 < (size_t) ip->Count) + { + //double x = ip[i]->X; + f_out.width(12); + f_out << ip[i2]->X << "\t"; + f_out.width(12); + f_out << ip[i2]->Y << "\t"; + } + else if (i2 < max_points) + { + f_out.width(13); + f_out << "\t"; + f_out.width(13); + f_out << "\t"; + } + } + f_out << std::endl; + i2++; + } + f_out.close(); + return; + } +#endif + void SaveCurves( System::Object ^sender, System::EventArgs ^e ) + { + SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog; + //TCHAR dir[MAX_PATH]; + //::GetCurrentDirectory(MAX_PATH, dir); + //String ^d = gcnew String(dir); + //saveFileDialog1->InitialDirectory = d; + saveFileDialog1->FileName = "curves.u_g"; + saveFileDialog1->Filter = "User graph files (*.u_g)|*.u_g|txt files (*.txt)|*.txt|All files (*.*)|*.*"; + saveFileDialog1->FilterIndex = 1; + saveFileDialog1->RestoreDirectory = true; +#undef OK + if ( saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK ) + { + std::string file_name; + ToString(saveFileDialog1->FileName, file_name); + std::ofstream f_out(file_name.c_str(), std::ifstream::out); + + if (!f_out.is_open()) + { + std::ostringstream estream; + estream << "Could not open file to save curves for USER_GRAPH " << file_name; + form_error_msg(estream.str()); + return; + } + + // write headings + size_t max_points = 0; + f_out.precision(4); + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + LineItem ^curve; + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + + // Calculate max_points + if ((size_t) ip->Count > max_points) + max_points = ip->Count; + + // write headers + std::string s_std; + ToString(curve->Label->Text, s_std); + f_out.width(12); + f_out << "x" << "\t"; + f_out.width(12); + if (s_std.size() > 0) + { + f_out << s_std << "\t"; + } + else + { + f_out << "y" << "\t"; + } + } + + f_out << std::endl; + + // write data + size_t i2 = 0; + f_out << std::scientific; + f_out.precision(4); + + while (i2 < max_points) + { + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + LineItem ^curve; + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + if (i2 < (size_t) ip->Count) + { + //double x = ip[i]->X; + f_out.width(12); + f_out << ip[i2]->X << "\t"; + f_out.width(12); + f_out << ip[i2]->Y << "\t"; + } + else if (i2 < max_points) + { + f_out.width(13); + f_out << "\t"; + f_out.width(13); + f_out << "\t"; + } + } + f_out << std::endl; + i2++; + } + f_out.close(); + + + } + else + { + // no dialog + std::ostringstream estream; + estream << "Could not open dialog to save curves. "; + form_error_msg(estream.str()); + return; + } + return; + } + + // Respond to a Zoom Event + void MyZoomEvent( ZedGraphControl ^control, ZoomState ^oldState, ZoomState ^newState ) + { + // Here we get notification everytime the user zooms + } + private: void timer1_Tick(System::Object ^sender, System::EventArgs ^e ) + { + LineItem ^curve; + ChartObject *chart = this->chartobject_ptr; + if (chart == NULL) return; + + //lock for thread + while (0 != System::Threading::Interlocked::Exchange(chart->usingResource, 1)) + System::Threading::Thread::Sleep(1); + + if (this->chartobject_ptr->Get_curve_added()) + { + DefineCurves(zg1->GraphPane, zg1->GraphPane->CurveList->Count); + } + else if (this->chartobject_ptr->Get_point_added()) + { + + // Make list of curves + std::vector Curves; + size_t j; + for (j = 0; j < chart->Get_CurvesCSV().size(); j++) + { + Curves.push_back(chart->Get_CurvesCSV()[j]); + } + for (j = 0; j < chart->Get_Curves().size(); j++) + { + Curves.push_back(chart->Get_Curves()[j]); + } + // Add points to curves ... + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + if ((size_t) ip->Count < Curves[i]->Get_x().size()) + { + if (Curves[i]->Get_y_axis() == 2) + Y2 = true; + else + Y2 = false; + for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + { + if ((LogX && Curves[i]->Get_x()[i2] <=0) + || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + continue; + else + ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + } + } + } + // Add points to curves ... + + //size_t i, k; + //k = 0; + //for (i = 0; i < Curves.size(); i++) + //{ + // if (Curves[i]->Get_x().size() == 0) continue; + // curve = (LineItem ^) zg1->GraphPane->CurveList[k++]; + // // Get the PointPairList + // IPointListEdit ^ip = (IPointListEdit^) curve->Points; + // if ((size_t) ip->Count < Curves[i]->Get_x().size()) + // { + // if (Curves[i]->Get_y_axis() == 2) + // Y2 = true; + // else + // Y2 = false; + // for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + // { + // if ((LogX && Curves[i]->Get_x()[i2] <=0) + // || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + // || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + // continue; + // else + // ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + // } + // } + //} + /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ + if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + if (Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1] > max) + max = Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->XAxis->Scale->Max = max; + } + if ((fabs(chart->Get_axis_scale_y()[1] - NA) < 1e-3) && zg1->GraphPane->YAxis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->YAxis->Scale->Max = max; + } + if ((fabs(chart->Get_axis_scale_y2()[1] - NA) < 1e-3) && zg1->GraphPane->Y2Axis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (!curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->Y2Axis->Scale->Max = max; + } + zg1->AxisChange(); + zg1->Refresh(); + } + + chart->Set_point_added(false); + if (chart->Get_end_timer()) + { + timer1->Stop(); + chart->Set_done(true); + phreeqc_done = true; + + //std::string str; + // + + //System::Runtime::Serialization::SerializationInfo ^info; + ////System::Runtime::Serialization::SerializationInfo ^info = gcnew System::Runtime::Serialization::SerializationInfo(); + ////System::Runtime::Serialization::StreamingContext context; + //System::IO::Stream ^strm = System::IO::File::Create("serialize"); + //zg1->GraphPane->GetObjectData(info, strm); + // + //this->ToString(info->ToString(), str); + //std::cerr << str; + + { + //// Debugging check + //std::vector Curves = chart->Get_CurvesCSV(); + //size_t i; + //for (i = 0; i < chart->Get_Curves().size(); i++) + //{ + // Curves.push_back(chart->Get_Curves()[i]); + //} + //for (i = 0; i < (size_t) zg1->GraphPane->CurveList->Count; i++) + //{ + // if (zg1->GraphPane->CurveList[i]->Points->Count != + // Curves[i]->Get_x().size()) + // { + // std::cerr << "Form: " << i << "\t" << zg1->GraphPane->CurveList[i]->Points->Count << std::endl; + // std::cerr << "Curves: " << i << "\t" << Curves[i]->Get_x().size() << std::endl; + // //form_error_msg("Did not plot all points. Why?"); + // } + // assert (zg1->GraphPane->CurveList[i]->Points->Count == + // Curves[i]->Get_x().size()); + //} + } + //unlock thread before setting chartobject_ptr to NULL + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + this->phreeqc_ptr = NULL; + this->chartobject_ptr = NULL; + return; + } + + //unlock thread + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + //tickStart = Environment::TickCount; + return; + } + + private: void timer1_Tick_old(System::Object ^sender, System::EventArgs ^e ) + { + LineItem ^curve; + ChartObject *chart = this->chartobject_ptr; + if (chart == NULL) return; + //std::cerr << "timer1_Tick." << std::endl; + //lock for thread + while (0 != System::Threading::Interlocked::Exchange(chart->usingResource, 1)) + System::Threading::Thread::Sleep(1); + + std::vector Curves; + size_t i; + for (i = 0; i < chart->Get_CurvesCSV().size(); i++) + { + Curves.push_back(chart->Get_CurvesCSV()[i]); + } + for (i = 0; i < chart->Get_Curves().size(); i++) + { + Curves.push_back(chart->Get_Curves()[i]); + } + + if ( ((Environment::TickCount - tickStart ) > this->chartobject_ptr->Get_update_time_chart()) + || chart->Get_end_timer() ) { + if (this->chartobject_ptr->Get_curve_added()) + { + DefineCurves(zg1->GraphPane, zg1->GraphPane->CurveList->Count); + + } + else if (this->chartobject_ptr->Get_point_added()) + { + // Add points to curves ... + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + if ((size_t) ip->Count < Curves[i]->Get_x().size()) + { + + if (Curves[i]->Get_y_axis() == 2) + Y2 = true; + else + Y2 = false; + for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + { + if ((LogX && Curves[i]->Get_x()[i2] <=0) + || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + continue; + else + ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + } + } + } + + /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ + if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + if (Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1] > max) + max = Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->XAxis->Scale->Max = max; + } + if ((fabs(chart->Get_axis_scale_y()[1] - NA) < 1e-3) && zg1->GraphPane->YAxis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->YAxis->Scale->Max = max; + } + if ((fabs(chart->Get_axis_scale_y2()[1] - NA) < 1e-3) && zg1->GraphPane->Y2Axis->Type == AxisType::Log) + { + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (!curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->Y2Axis->Scale->Max = max; + } + + zg1->AxisChange(); + zg1->Refresh(); + tickStart = Environment::TickCount; + } + } + chart->Set_point_added(false); + if (chart->Get_end_timer()) + { + //std::cerr << "Form got end_timer message." << std::endl; + zg1->Refresh(); + timer1->Stop(); + chart->Set_done(true); + phreeqc_done = true; + //unlock thread + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + this->phreeqc_ptr = NULL; + this->chartobject_ptr = NULL; + //std::cerr << "Form released thread, pointers null." << std::endl; + } + else + { + //unlock thread + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + } + return; + } + void ToString(System::String^ src, std::string& dest) + { + using namespace System::Runtime::InteropServices; + const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(src)).ToPointer(); + dest = chars; + Marshal::FreeHGlobal(IntPtr((void*)chars)); + } + ~Form1() { + if (this->zg1) delete zg1; + //if (this->timer1) delete timer1); + if (components) { + delete components; + } + } + public: ZedGraph::ZedGraphControl ^zg1; + private: System::Windows::Forms::Timer ^timer1; + private: System::ComponentModel::Container ^components; + private: Phreeqc * phreeqc_ptr; + ChartObject * chartobject_ptr; + + public: +#pragma region Windows Form Designer generated code + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + void InitializeComponent() + { + this->components = (gcnew System::ComponentModel::Container()); + this->zg1 = (gcnew ZedGraph::ZedGraphControl()); + this->timer1 = (gcnew System::Windows::Forms::Timer( this->components )); + this->SuspendLayout(); + // + // zg1 + // + this->zg1->Location = System::Drawing::Point(12, 12); + this->zg1->Name = L"zg1"; + this->zg1->ScrollGrace = 0; + this->zg1->ScrollMaxX = 0; + this->zg1->ScrollMaxY = 0; + this->zg1->ScrollMaxY2 = 0; + this->zg1->ScrollMinX = 0; + this->zg1->ScrollMinY = 0; + this->zg1->ScrollMinY2 = 0; + this->zg1->Size = System::Drawing::Size(this->chartobject_ptr->Get_PanelWidth() - 2 * 12, chartobject_ptr->Get_PanelHeight() - 2 * 12); + this->zg1->TabIndex = 0; + this->timer1->Tick += gcnew System::EventHandler( this, &Form1::timer1_Tick ); + // + // Form1 + // + this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); + this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; + this->AutoValidate = System::Windows::Forms::AutoValidate::EnablePreventFocusChange; + this->ClientSize = System::Drawing::Size(this->chartobject_ptr->Get_PanelWidth(), chartobject_ptr->Get_PanelHeight()); + this->Controls->Add(this->zg1); + this->Name = L"Form1"; + this->StartPosition = System::Windows::Forms::FormStartPosition::WindowsDefaultLocation;//:CenterScreen; + //this->Text = L"PHREEQC chart"; + System::String ^desc = gcnew String(this->chartobject_ptr->Get_description().c_str()); + this->Text = L"Phreeqc USER_GRAPH " + this->chartobject_ptr->Get_n_user() + " " + desc; + this->TopMost = false; + System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); + try + { + this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); + } + catch (...) + { + } + + this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::MyFormClosingEventHandler); + this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load); + this->Resize += gcnew System::EventHandler(this, &Form1::Form1_Resize); + this->ResumeLayout(false); + } +#pragma endregion + + + }; +} \ No newline at end of file diff --git a/rename_cpp/Form1.resX b/rename_cpp/Form1.resX new file mode 100644 index 00000000..fc36b375 --- /dev/null +++ b/rename_cpp/Form1.resX @@ -0,0 +1,33 @@ + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/ + mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz + k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g + AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA + + + \ No newline at end of file diff --git a/rename_cpp/Makefile b/rename_cpp/Makefile new file mode 100644 index 00000000..ad676f3a --- /dev/null +++ b/rename_cpp/Makefile @@ -0,0 +1,237 @@ +# +# Make file for PHREEQC +# +# $(CURDIR) is current directory +TOPDIR:=$(CURDIR)/.. +PROGRAM=phreeqc +EXE=$(TOPDIR)/bin/$(PROGRAM) +SRC=. + +# Do not print commands before executing +#.SILENT: + +# Provides compatibility with GNU make +#.SUFFIXES: + +# Change to pawd if using automounter +PWD=pwd + +# Change to C compiler on your system +CC=g++ + +# Change to C compiler options on your system +#CCFLAGS=-O3 -fno-signed-zeros -Wall -ansi -pedantic -std=c99 -DHAVE_ISFINITE -DNDEBUG # -frounding-math # -pg +CCFLAGS=-O3 -Wall -ansi -pedantic -DHAVE_ISFINITE -DNDEBUG # -frounding-math # -pg -std=c99 + +# Remove the following definition if you do not have +# gmp (Gnu Multiple Precision) package on your system +INVERSE_CL1MP=TRUE + +LOADFLAGS= -lm # -pg +LOADFLAGS+=$(call ld-option, -Wl$(comma)--hash-style=sysv) + +#.c.o : +# ${CC} ${CCFLAGS} -c -o $@ $< +%.o : $(SRC)/%.c + ${CC} ${CCFLAGS} -c -o $@ $< +%.o : $(SRC)/%.cpp + ${CC} ${CCFLAGS} -c -o $@ $< + +# Location to copy scripts on installation +BINDIR=$(HOME)/bin + +OBJECTS= \ + advection.o \ + basic.o \ + basicsubs.o \ + cl1.o \ + cvdense.o \ + cvode.o \ + dense.o \ + dw.o \ + input.o \ + integrate.o \ + inverse.o \ + isotopes.o \ + kinetics.o \ + main.o \ + mainsubs.o \ + model.o \ + nvector.o \ + nvector_serial.o \ + p2clib.o \ + parse.o \ + phqalloc.o \ + phreeqc_files.o \ + pitzer.o \ + pitzer_structures.o \ + prep.o \ + print.o \ + read.o \ + readtr.o \ + sit.o \ + smalldense.o \ + spread.o \ + step.o \ + structures.o \ + sundialsmath.o \ + tally.o \ + tidy.o \ + transport.o \ + utilities.o + +ifdef INVERSE_CL1MP + LOADFLAGS += /z/parkplace/usr/lib/libgmp.a + CCFLAGS += -DINVERSE_CL1MP + OBJECTS += cl1mp.o +endif + +all: $(EXE) + +install: +# +# Create directory for binary and scripts if necessary +# + if [ ! -d $(BINDIR) ]; \ + then \ + mkdir $(BINDIR); \ + echo Created directory $(BINDIR); \ + fi +# +# Put path name of current directory into script for +# locating data files, put script in top directory, +# put symbolic link in BINDIR +# + cd $(TOPDIR); dir1=`$(PWD)`/bin; cd $(BINDIR); if [ `$(PWD)` = $$dir1 ]; \ + then \ + echo "Can not install to $(BINDIR). Choose another directory."; \ + exit 4 ; \ + fi + cd $(TOPDIR); \ + rm -f $(BINDIR)/$(PROGRAM); \ + rm -f $(PROGRAM); \ + sed "s?TOPDIR=.\{0,80\}?TOPDIR=`$(PWD)`?" bin/$(PROGRAM).orig > $(PROGRAM); \ + chmod 755 $(PROGRAM) + cd $(TOPDIR); dir1=`$(PWD)`; cd $(BINDIR); if [ `$(PWD)` != $$dir1 ]; then \ + ln -s $$dir1/$(PROGRAM) $(BINDIR); \ + echo Symbolic link for $(PROGRAM) has been placed in $(BINDIR). ; \ + fi +# +# Check that all necessary files are in place. +# + if [ -f $(BINDIR)/$(PROGRAM) -a \ + -f $(TOPDIR)/bin/$(PROGRAM) -a \ + -f $(TOPDIR)/$(PROGRAM) ]; \ + then echo "Installation complete."; \ + else echo "Installation incomplete."; \ + for FILE in $(BINDIR)/$(PROGRAM) \ + $(TOPDIR)/bin/$(PROGRAM) $(TOPDIR)/$(PROGRAM) ; \ + do \ + if [ ! -f $$FILE ]; then echo $$FILE is missing.; fi; \ + done; \ + fi + echo "Add directory $(BINDIR) to PATH." + +clean: + rm -f $(BINDIR)/$(PROGRAM) + rm -f $(TOPDIR)/bin/$(PROGRAM) + rm -f $(TOPDIR)/src/*.o + rm -f $(SUN_DIR)/bin/$(PROGRAM) + rm -f $(SUN_DIR)/src/*.o + rm -f $(TOPDIR)/src/$(PROGRAM) + rm -f $(DEBUG_DIR)/*.o + echo Removed object and executable files generated by make. + +$(EXE): $(OBJECTS) + echo $(TOPDIR) + $(CC) -o $(EXE) $(OBJECTS) $(LOADFLAGS) # -L/z/parkplace/home/dlpark/packages/efence -lefence + echo Compilation complete, $(EXE). + +advection.o: $(SRC)/advection.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +basic.o: $(SRC)/basic.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/p2c.h $(SRC)/basic.h + +basicsubs.o: $(SRC)/basicsubs.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +cl1.o: $(SRC)/cl1.c $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h + +cl1mp.o: $(SRC)/cl1mp.c $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqtype.h + +cvdense.o: $(SRC)/cvdense.c $(SRC)/cvdense.h $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +cvode.o: $(SRC)/cvode.c $(SRC)/cvode.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/nvector.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/kinetics.h $(SRC)/phqalloc.h + +dense.o: $(SRC)/dense.c $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/output.h $(SRC)/phqalloc.h + +dw.o: $(SRC)/dw.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phrqproto.h $(SRC)/output.h $(SRC)/pitzer.h + +input.o: $(SRC)/input.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/input.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h + +integrate.o: $(SRC)/integrate.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +inverse.o: $(SRC)/inverse.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +isotopes.o: $(SRC)/isotopes.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +kinetics.o: $(SRC)/kinetics.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/sundialstypes.h $(SRC)/cvode.h $(SRC)/nvector.h $(SRC)/cvdense.h $(SRC)/dense.h $(SRC)/smalldense.h $(SRC)/nvector_serial.h $(SRC)/kinetics.h + +main.o: $(SRC)/main.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +mainsubs.o: $(SRC)/mainsubs.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +model.o: $(SRC)/model.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +nvector.o: $(SRC)/nvector.c $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h + +nvector_serial.o: $(SRC)/nvector_serial.c $(SRC)/nvector_serial.h $(SRC)/nvector.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +output.o: $(SRC)/output.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/phqalloc.h + +p2clib.o: $(SRC)/p2clib.c $(SRC)/p2c.h $(SRC)/output.h + +parse.o: $(SRC)/parse.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +phqalloc.o: $(SRC)/phqalloc.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/output.h + +phreeqc_files.o: $(SRC)/phreeqc_files.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/input.h + +pitzer.o: $(SRC)/pitzer.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer_structures.h $(SRC)/pitzer.h + +pitzer_structures.o: $(SRC)/pitzer_structures.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer_structures.h $(SRC)/pitzer.h + +prep.o: $(SRC)/prep.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +print.o: $(SRC)/print.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer.h + +read.o: $(SRC)/read.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +readtr.o: $(SRC)/readtr.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +sit.o: $(SRC)/sit.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h $(SRC)/pitzer_structures.h $(SRC)/pitzer.h + +smalldense.o: $(SRC)/smalldense.c $(SRC)/smalldense.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/sundialsmath.h $(SRC)/output.h $(SRC)/phqalloc.h + +spread.o: $(SRC)/spread.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +step.o: $(SRC)/step.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +structures.o: $(SRC)/structures.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +sundialsmath.o: $(SRC)/sundialsmath.c $(SRC)/sundialsmath.h $(SRC)/sundialstypes.h $(SRC)/phrqtype.h $(SRC)/output.h + +tally.o: $(SRC)/tally.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +tidy.o: $(SRC)/tidy.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +transport.o: $(SRC)/transport.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +utilities.o: $(SRC)/utilities.c $(SRC)/global.h $(SRC)/phrqtype.h $(SRC)/global_structures.h $(SRC)/phqalloc.h $(SRC)/output.h $(SRC)/phrqproto.h + +-include $(CURDIR)/distribution.mk + +#ld-option +# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) +comma=, +ld-option = $(shell if $(CC) $(1) \ + -nostdlib -o /dev/null -xc /dev/null \ + > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) diff --git a/rename_cpp/NA.h b/rename_cpp/NA.h new file mode 100644 index 00000000..7f1afa93 --- /dev/null +++ b/rename_cpp/NA.h @@ -0,0 +1 @@ +#define NA -98.7654321 \ No newline at end of file diff --git a/rename_cpp/PHRQ_io_output.cpp b/rename_cpp/PHRQ_io_output.cpp new file mode 100644 index 00000000..af13bb9b --- /dev/null +++ b/rename_cpp/PHRQ_io_output.cpp @@ -0,0 +1,794 @@ +#include +#include "Phreeqc.h" +#include "phqalloc.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (state == TRANSPORT && transport_warnings == FALSE) + return (OK); + if (state == ADVECTION && advection_warnings == FALSE) + return (OK); + count_warnings++; + if (pr.warnings >= 0) + { + if (count_warnings > pr.warnings) + return (OK); + } + if (phrq_io) + { + if (status_on) + { + phrq_io->screen_msg("\n"); + } + std::ostringstream msg; + msg << "WARNING: " << err_str; + phrq_io->warning_msg(msg.str().c_str()); + } + + return OK; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +echo_msg(const char *str) +/* ---------------------------------------------------------------------- */ +{ + if (pr.echo_input == TRUE) + { + if (phrq_io) phrq_io->echo_msg(str); + } +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +set_forward_output_to_log(int value) +/* ---------------------------------------------------------------------- */ +{ + forward_output_to_log = value; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_forward_output_to_log(void) +/* ---------------------------------------------------------------------- */ +{ + return forward_output_to_log; +} + +#if defined(HDF5_CREATE) +extern void HDFWriteHyperSlabV(const char *name, const char *format, + va_list argptr); +#endif + +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +extern int Merge_fpunchf(const int length, const char *format, + va_list argptr); +#endif +void Phreeqc:: +fpunchf_heading(const char *name) +{ + if (pr.punch == TRUE && punch.in == TRUE) + { + punch_msg(name); + } +} +void Phreeqc:: +fpunchf(const char *name, const char *format, double d) +{ + if (phrq_io) phrq_io->fpunchf(name, format, d); +} +void Phreeqc:: +fpunchf(const char *name, const char *format, char * s) +{ + if (phrq_io) phrq_io->fpunchf(name, format, s); +} +void Phreeqc:: +fpunchf(const char *name, const char *format, int d) +{ + if (phrq_io) phrq_io->fpunchf(name, format, d); +} + +void Phreeqc:: +fpunchf_user(int user_index, const char *format, double d) +{ + static int s_warning = 0; + static char buffer[80]; + const char *name; + + // check headings + if (user_index < user_punch_count_headings) + { + name = user_punch_headings[user_index]; + } + else + { + if (s_warning == 0) + { + error_string = sformatf( + "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + warning_msg(error_string); + s_warning = 1; + } + sprintf(buffer, "no_heading_%d", + (user_index - user_punch_count_headings) + 1); + name = buffer; + } + if (phrq_io) phrq_io->fpunchf(name, format, (double) d); +} + +void Phreeqc:: +fpunchf_user(int user_index, const char *format, char * d) +{ + static int s_warning = 0; + static char buffer[80]; + const char *name; + + // check headings + if (user_index < user_punch_count_headings) + { + name = user_punch_headings[user_index]; + } + else + { + if (s_warning == 0) + { + error_string = sformatf( + "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + warning_msg(error_string); + s_warning = 1; + } + sprintf(buffer, "no_heading_%d", + (user_index - user_punch_count_headings) + 1); + name = buffer; + } + if (phrq_io) phrq_io->fpunchf(name, format, d); +} + +int Phreeqc:: +fpunchf_end_row(const char *format) +{ + if (phrq_io) + { + phrq_io->fpunchf_end_row(format); + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log) +/* ---------------------------------------------------------------------- */ +{ + int l; + char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; + char query[2 * MAX_LENGTH]; + char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; + char *env_ptr; + char *ptr; +/* + * Prepare error handling + */ + try { + if (phrq_io == NULL) + { + std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; + } +/* + * Prep for get_line + */ + max_line = MAX_LINE; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); +/* + * Open error ostream + */ + if (argc > 4) + { + if (!phrq_io->error_open(argv[4])) + { + error_string = sformatf( "Error opening file, %s.", argv[4]); + warning_msg(error_string); + } + } + else + { + phrq_io->error_open(NULL); + } +/* + * For now, set screen ostream to error ostream + */ + //phrq_io->Set_screen_ostream(phrq_io->Get_error_ostream()); +/* + * Open user-input file + */ + strcpy(query, "Name of input file?"); + std::ifstream * local_input_stream = NULL; + if (argc <= 1) + { + default_name[0] = '\0'; + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); + } + else + { + strcpy(default_name, argv[1]); + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); + } + screen_msg(sformatf("Input file: %s\n\n", default_name)); + strcpy(in_file, default_name); +/* + * Open file for output + */ + strcpy(query, "Name of output file?"); + ptr = default_name; + copy_token(token, &ptr, &l); + strcat(token, ".out"); + std::ofstream * local_output_stream; + if (argc <= 1) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, false); + } + else if (argc == 2) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + else if (argc >= 3) + { + strcpy(token, argv[2]); + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + screen_msg(sformatf("Output file: %s\n\n", token)); + strcpy(out_file, token); + phrq_io->Set_output_ostream(local_output_stream); +/* + * Open log file + */ + if (log == TRUE) + { + if (!phrq_io->log_open("phreeqc.log")) + { + error_msg("Can't open log file, phreeqc.log.", STOP); + } + } +/* + * Read input file for DATABASE keyword + */ + if (local_input_stream->is_open()) + { + phrq_io->push_istream(local_input_stream); + if (get_line() == KEYWORD) + { + ptr = line; + copy_token(token, &ptr, &l); + if (strcmp_nocase(token, "database") == 0) + { +#ifdef PHREEQ98 + user_database = string_duplicate(prefix_database_dir(ptr)); +#else + user_database = string_duplicate(ptr); +#endif + if (string_trim(user_database) == EMPTY) + { + warning_msg("DATABASE file name is missing; default database will be used."); + user_database = (char *) free_check_null(user_database); + } + } + } + phrq_io->pop_istream(); + } + else + { + delete local_input_stream; + error_string = sformatf( "Error opening file, %s.", in_file); + error_msg(error_string, STOP); + } + +/* + * Open data base + */ + strcpy(query, "Name of database file?"); + env_ptr = getenv("PHREEQC_DATABASE"); + if (user_database != NULL) + { + strcpy(token, user_database); + } + else if (env_ptr != NULL) + { + strcpy(token, env_ptr); + } + else + { + strcpy(token, default_data_base); + } + + std::ifstream * local_database_file; + if (argc <= 1) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, false); + } + else if (argc < 4) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + else if (argc >= 4) + { + if (user_database == NULL) + { + strcpy(token, argv[3]); + } + else + { +#ifndef PHREEQCI_GUI + warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); +#endif + } + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + local_database_file->close(); + delete local_database_file; + //if (local_database_file != NULL) + //{ + // if (phrq_io) phrq_io->Set_database_file(local_database_file); + //} + screen_msg(sformatf("Database file: %s\n\n", token)); + strcpy(db_file, token); + + output_msg(sformatf(" Input file: %s\n", in_file)); + output_msg(sformatf(" Output file: %s\n", out_file)); + output_msg(sformatf("Database file: %s\n\n", token)); + /* + * local cleanup + */ + user_database = (char *) free_check_null(user_database); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + *db_cookie = new std::ifstream(db_file, std::ios_base::in); + *input_cookie = new std::ifstream(in_file, std::ios_base::in); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} +/* ---------------------------------------------------------------------- */ +std::ifstream * Phreeqc:: +open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH]; + std::ifstream *new_stream; + int l; + + //std::ostream * screen_file_save = phrq_io->Get_screen_ostream(); + std::ostream * error_file_save = phrq_io->Get_error_ostream(); + + for (;;) + { +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { + //phrq_io->Set_screen_ostream(&std::cerr); + phrq_io->Set_error_ostream(&std::cerr); + screen_msg(sformatf("%s\n", query));; + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ifstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { + //phrq_io->Set_screen_ostream(&std::cerr); + phrq_io->Set_error_ostream(&std::cerr); + error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + screen_msg(error_string); + //screen_flush(); + error_flush(); + batch = FALSE; + continue; + } + break; + } + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { + //phrq_io->Set_screen_ostream(screen_file_save); + phrq_io->Set_error_ostream(error_file_save); + } + return (new_stream); +} +/* ---------------------------------------------------------------------- */ +std::ofstream * Phreeqc:: +open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH]; + std::ofstream *new_stream; + int l; + + //std::ostream * screen_file_save = phrq_io->Get_screen_ostream(); + std::ostream * error_file_save = phrq_io->Get_error_ostream(); + + for (;;) + { +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { + //phrq_io->Set_screen_ostream(&std::cerr); + phrq_io->Set_error_ostream(&std::cerr); + screen_msg(sformatf("%s\n", query));; + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ofstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { + //phrq_io->Set_screen_ostream(&std::cerr); + phrq_io->Set_error_ostream(&std::cerr); + error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + screen_msg( error_string); + //screen_flush(); + error_flush(); + batch = FALSE; + continue; + } + break; + } + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { + //phrq_io->Set_screen_ostream(screen_file_save); + phrq_io->Set_error_ostream(error_file_save); + } + return (new_stream); +} +// ---------------------------------------------------------------------- */ +// screen ostream methods +// ---------------------------------------------------------------------- */ +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +screen_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + { + return this->phrq_io->screen_open(file_name); + } + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +screen_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->screen_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +screen_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->screen_close(); +} +#endif +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +screen_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) phrq_io->screen_msg(err_str); +} +// ---------------------------------------------------------------------- */ +// dump file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +dump_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + return this->phrq_io->dump_open(file_name); + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +dump_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->dump_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +dump_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->dump_close(); +} +///* ---------------------------------------------------------------------- */ +//void Phreeqc:: +//dump_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) this->phrq_io->dump_rewind(); +//} +///* ---------------------------------------------------------------------- */ +//bool Phreeqc:: +//dump_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) +// return this->phrq_io->dump_isopen(); +// return false; +//} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +dump_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->dump_msg(str); +} +// ---------------------------------------------------------------------- */ +// error file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +error_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + return this->phrq_io->error_open(file_name); + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +error_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->error_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +error_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->error_close(); +} +///* ---------------------------------------------------------------------- */ +//void Phreeqc:: +//error_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) this->phrq_io->error_rewind(); +//} +///* ---------------------------------------------------------------------- */ +//bool Phreeqc:: +//error_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) +// return this->phrq_io->error_isopen(); +// return false; +//} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + if (get_input_errors() <= 0) + input_error = 1; + if (phrq_io) + { + std::ostringstream msg; + msg << "ERROR: " << err_str << "\n"; + + phrq_io->output_msg(msg.str().c_str()); + phrq_io->log_msg(msg.str().c_str()); + + if (status_on) + { + phrq_io->screen_msg("\n"); + } + phrq_io->error_msg(msg.str().c_str(), stop); + } + + if (stop) + { + throw PhreeqcStop(); + } +} +// ---------------------------------------------------------------------- */ +// log file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +log_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + return this->phrq_io->log_open(file_name); + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +log_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->log_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +log_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->log_close(); +} +///* ---------------------------------------------------------------------- */ +//void Phreeqc:: +//log_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) this->phrq_io->log_rewind(); +//} +///* ---------------------------------------------------------------------- */ +//bool Phreeqc:: +//log_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) +// return this->phrq_io->log_isopen(); +// return false; +//} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +log_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->log_msg(str); +} +// ---------------------------------------------------------------------- */ +// output_temp file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +output_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + return this->phrq_io->output_open(file_name); + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +output_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->output_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +output_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->output_close(); +} +///* ---------------------------------------------------------------------- */ +//void Phreeqc:: +//output_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) this->phrq_io->output_rewind(); +//} +///* ---------------------------------------------------------------------- */ +//bool Phreeqc:: +//output_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) +// return this->phrq_io->output_isopen(); +// return false; +//} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +output_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + { + if (get_forward_output_to_log()) + { + phrq_io->log_msg(str); + } + else + { + phrq_io->output_msg(str); + } + } +} +// ---------------------------------------------------------------------- */ +// punch file methods +// ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +punch_open(const char *file_name) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) + return this->phrq_io->punch_open(file_name); + return false; +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +punch_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->punch_flush(); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +punch_close(void) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->punch_close(); +} +///* ---------------------------------------------------------------------- */ +//void Phreeqc:: +//punch_rewind(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) this->phrq_io->punch_rewind(); +//} +///* ---------------------------------------------------------------------- */ +//bool Phreeqc:: +//punch_isopen(void) +///* ---------------------------------------------------------------------- */ +//{ +// if (phrq_io) +// return this->phrq_io->punch_isopen(); +// return false; +//} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +punch_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (phrq_io) this->phrq_io->punch_msg(str); +} diff --git a/rename_cpp/ZedGraph.dll b/rename_cpp/ZedGraph.dll new file mode 100644 index 0000000000000000000000000000000000000000..8b150d8249231da8eaaa67bc920c1f18b25ce9c2 GIT binary patch literal 307200 zcmeFad3;<~bqD_R-kUd@G}6<^Gx8E!@s=0ONVX-%v7E$`vnOOD39%$+-$-I7&mGw* zWIT%4mnI=lC?o_LLIVW~DO(GrKuV!dAZdV>9TQRtlqH0vC8fpreZS}2w~Q=1q5XY6 zzdwGN&u8Ad_uS>2d+xdCp1Z!Yr|+~J%d%YjpL)u&K7u!Y6Y@O#V-CTk6@OE*K9qmx z$d7cK_0W+QUU&V>!0tx){KgeG4qSD`O*e&m2Clqjpt1L+f$MJ?IQiTQ25tICcsh_`Hh*x~#GmW2|;za0Fh z$3Dv%-gC_h_P~GPK2xqar8^acMZbKwG1IsTK%osZvTW9!c&C07V90Renq46xl2!{e zOFYI;{U$8y#FY10=d&DmmIKdn;8_kl%YkP(@GJ+O<-oHXc$Ndta^P7G{Qrmp>p8B* zk7HBY%2=;_xothsXIpuJVyJnmZ9VB()_DV#HD_Rld#&ErbK36TRUh8j_0!AVfA;pD zz3>YU{OU9Pd!PTi6OQ?df4b@Ri{BF5a_`vrpZ(zP-m&@KiMKuQqVIkEBNx5*)Nj4z zoX@Sl{`ofyeg8Xe|Nh@yef%juzWd1=N7vqe%+GH=E?@inMc?ec>ftm0XV3A!{M}!@ z>-j&sdGJkZ&f9YOlKhje`puhnyfNH({)2D&)_Ldd>R&u^({j6cJZ1w1SK3ZX8~|*M z0OA1Pga{xG0LCMLH~^T40O9}u182=t8~|*K0OA1PqzE7m0FI3S;s9WC1P})RV-Y|c z0Bnf>;sD?{0`NX23J?bXn<9WXENkg{+ggH(>98!{UQ-Nw%PQE-KEx{Q&t`*Oc)#rp zA{_GvHfARBzLjM?GTmalZAn+qbWV#2_h&s#hhz(;1G6}HG!I{WrQ!|Gax5<_194?T zw}L9+Wq=j-7yH_Xif9_%l+c7?wbLYJsV__C4I)h$o$yLzoF+KRbM3I^IbsrChKDqYvC%6me4=08}D?H~?4`0mK2o$_OBitq`{XK=4|@07Rfy#84anNC4$Big9EV zLmY^)Is%9TfHe_7902r30C50-x>GFT002Uu0C50-St|vI1ArqUfH(kH8Ue%sz)%Db z2LQtnKpX(n2sj^Qp~JRkz_&v17nX9f9tF}dKX4rbFSVO|JHwtGd;qDCk-(AjdK1of zI$YqERffERDhpc6x0{emx4uf>A*u?Zwn%-I@Kz6^)@ubX#e1+q87{APEVQ(A+VyQ| zA-T*kPU{3OLt+E;!a3#y5|2h4z8QCL#NHR+9lV@@o7Ce3ub?jqdSzSCtLT$*pe-9( zm?O)sNRpE|fak_XC@$^+$T%R}ihKvN#%MxOqDv`C5mue6X6PeThi z{B-pzj6V!5lE>54GwZ9po)6;7Goj__`0|WsQNA#0#njPX*-gw*3n$L!d#U=vDkOfW z({2(dp1~?49g>LvZS&#)V0i=(2LMM!0C51YAp(d)`UTnqm_SeTdvHD4>QF_sXT79v zRq8{<2D+ZzGjDV)?-rwLw~4Y(dY?!qA3L7tdFUVu=0$=-^nBlej3=%=G%YCJ zNQ&`Z8&NKfD{Z?8<={F2v{_+~gKnfn|6mdTML0hI#f(xQvfZLzQfPprXb%9!#qLU;o-NHIJ1VG!+xFtmUe9hE!rX8;7y`S8O~bSGX9 zza6Xwpq$Bu<49HZV7)RAKjVA7cCXXxhKr!&>zCS1@}&-v__njTyzhqpLvl0U8G#v` z+q)K-m2-Zs-ks0-IfVWcO0Ar&-By^LQkeP;YUd51$jHR4Pe&!2fN!+R6l)ti!%L%}6B)F@1f4|BYP+fx z=e5p&-_A-^LHDu7`h)kOJZlHD^;xw;iHuff{iZ0#>;!lcWLp_@ia|C`&t@PK z@i54|)|mj?`}nL@gQHQ@b^*q&^VSu@#C!5^2z%v|C!LiQhAW(_yJuRxi z?AS|K?P8jFcSG4ZK4J-=qIo7>`En*T|Ep;mu3Ezn#F^c9) zZ2I6VXzy@gXUrY4O=W3Bv1a&A)r=?NZz?2b zd%=C+E(BGoBM<+Z;a>}YsShvsQ;oo}cbyUb#6(yW0p4H$Qe)XD%cbjS#ak9SJ70T) zu5{bV_jaHou)^!n#Kt}cU9Fma>;X8v%J`oXvS%$st&I9XdENSX`nI#a>xEAsRyhOh zel)Z@dL4{4SJ=%9Sylj!1weh(5Ysz_%`?bO0Tl&Y34rhJJqKW@7n9K4Lx1>Q_E=rL zAUCc7$#HW=5{Y8+!q<1OU-P}@6+pUoJM=;Qh$tfk?jcZ9egU)>o{uuz@jUbT!@LveYL=b3y z!Fz=AJMZTse&?&ccb}h+_?=(uXW?C9*q>kO=ipst*q=WH``Z`}CbQj5fmg82!N(OS z(@;_SpRrQ_wwvIaJGMofeRQs)Q|vsoEO)ADxpM|4Kp~Va&>Jftk{iNKDU3ZuW_eXH zDvG^OEi^}?L;({S9r?t#rl^b*BgiLf`N%nL2Umm1)017cmj{o~%ea-`O#nfIfdA;4 zRwJ*nOX+aG=Vp~Sm&|W-J&CevVyg#Nf8YaUKo00 zf2r3yP$|LcR-uG}=)ypBje+O|e@Vp643qci+s=B`nd{K}!bcfqdPB4vk>&4N8_ONY z4=k}hV_mvR?G4t!MsN%PzLV*-MAtcCi4vryz<}+DB)MM64en;fPWTlR(#=MGH4(3? zlwI_WPWV-kvakz;xUhonGSPguI$3soS0jWIDCNkPD&>r%`I^XK*o_9{f*Em|4AOvO zPRI!1Hc4Z+?K!?D+y-YnaK&*pm+ENBaiLzJiw+F1kM|BI`CYS-4l3Nw=fF5B#2uZOp7DWI4TDaU*Lnkf!$zz+A zjGy#k@#0}w6R(-rc(eA%YxNZ#4~;m+85z@$n!R|}&2 zM9gv`X1?p^?m`pF-6h%kIYXguFz zA|oA!Lh8*nX(;p-4i=GOZ!r-OL#3(*5f#i;lc~^q4*2~%sdXy3bI7=}^lk9nh^A8? zi?T>HbaV`C@CacljoqJW@_jABA$DSOpA_RjFX`5|7+kPElGLH#>WpwbzzQ=%d!;&f zKR_IVI2LlTV59j?eVfWp!E-~5Y&|a{uc@N9Mx-`7DdGnouFfR#&}1vsgu!Y)x!^Q86ZlVV73lAaARW&*I9b{o+c?$bsQ z+q#_5L1KLv0tPMQyUj}wP09)_F7HV{lheY7uR*#NBedm4yGC1X3CZ;5mj-eHD$X( zBqf|dg6@O~OeG0TWct*zvbg|EDy+pD>@BQ?U9A8*1d`271rW-@s;OT+`Kc8*-QO|N zhp>6DjZT$$lBW6%etziMO1V&53rQ{91pzDEH9vX=(Q75Y0999jfu4b?`*NjRM3Ssu zybBt$c&H>rBq{nuKg%S3e#^824k!zZB{Bda#y$^`GL=BJE`o2$+WIUa%nwtYFdu5T z()!$jDX2b73fdupBjR5gNgUXQB!)(uPGgA!RY@sl$Ige2s+2o7V>lTVPCB1X>3jq~ zSl&sNcitt{m?q;eQCZPx^z);(5q@wW8R2)LVmf`y9^P^N_+?K$^;D(Yl_pd=ye{eR zl+di-#ft7an9##SolofesBMHE94Lf#fzU1=vz~@fNYC$K1gN!Us{Nq;xTm-0;QrX} z^$*b>tJShrfSqd zq-(hdfnDhC156$iBxiQ?)RjX6)XS1*Fe!N<))XAo$zU3<+FI4qL(3%|NeOmD@h;YQ z=;#YM?T=c}h5evEJykuNHC^&E?W7JF?+A>Eq?;@{d%)F>taO(lIkooiJ=;kSig9(g z9_^&JAd2Q|_(yc*CA~{T9s(F3QKu>aOM90}RZD<$xnT`aWTXJ5QTo$8V!HR!P)`R9 zy?N;oXI?<_tAJqvd&6=O4yu}R=PHPV{K{R4vs5W}*8*tSZrbhLs=+WTlmH}gm){Ll zgVv~~e5Kq|+v=BK+4saLa&TjoNRXDGlO)U}mas0Rqs#9>Ry}@?pF_X*H&C<1sj`pE zx~9s#y=A|+)9>2p`#b&Koxx=>tNgMKQF{wv1>OEyvuJ_&26q$_(Hn(HFqmAw5Z(?3 zZ2mZkIuHIwgu^(BmZz#Z?~(PZy^DG)y?rtpS-;M&$f{HQRKKq>vMr4Wb6qJ!8ZEpH zxz=h6g}j;}u)>ox;cEa=AzmN=gYGKyRn_P#)s-lm=*s?ub>%YX%4Mo67yFn3IfSlU z>}z_&jdkU+dAhP6xcd*%l>znRCH89{w?#kN){)NGv}5$9?Ob<*Bk)=1OU?ivqO^lc z*JrG6+ZOk?`E~yYJ%fqvNfk=$&~TnBS7hK$;$_bqt|QZnZFnEY1O|b!-CNY@CRT z$xn&UVYRjxr(?A!e#`+8VE9MQ3FEY_);8muuv)O$T|2mf5*>UR7P@U8@NUO@=1PEq zs|W|=bur{>19^Q6xrUH|-hmFQ8eA)GE?*gU1G;v1@O*%0uEV1>0(8ArrDAiV2xiML z33db1sF(9GJK+s>5he=^UT`DaGuxr7WXqvWxP?c<51Zby!tcxAun+l$0{~XSf1xlp ziKy{rAP;XsdKmr!z@S$Fn4lB@EL8<`DI%=(&ioLjCi)MvSj+)oH2IWXx0Tg7bOhX1 zsP;`I3`w@wIxDUYcgLPe_y^)XA2dag=#C?4fJCa!ych*)LB1gxO*)TGoaja&$^>Y% zup#*pT#*l(x^Q<;=dP-Daiz8w?&*YZp$$Rq*XW*3r(U+3Xaa5>+~Qjr z9eU~+BI!G5!>8t%v!eZzoL~GF@_re`+ zLFMju*6z1b8%JrUS=Ps_^23(nqL=1g*)M!0+OL$gFwJ5?Nq`5Px>r{BL}3D$8Kdmy zB7zD$gr!ElT(7LChBpIgueC-Rfx^P;0qTO$!getg{2`tiP=Q52n0C!Ch~WTBixTFB zFJz1h@d$6hg9{lF+80EPT**pXmWRoCr%AqZhP`dLl@(FQ)-ij6ron9!Exh()_}EJ?T7b1} zqsX(h7VI5@{{p-VtSbB<=Tu78C4gOnf0jV}*bX4-JhzSdGJB%i>&xE1NmT*(MN+-+ zYN5red(k|!?1tsy^+zGx@m^}uq&EGLR%xA*LRr~%MkFiH@Q8yh1Z$D+N78vq1s5p7 zWO1PrYYVpYs+f+G;Y-nTMzh#h0Sg|iXH(CHvnV#ANr(E#{-wQkx>I zA&-u-Htyi^fQ~01QWp9&SPJV9D_+1jyHcoa1gS(8-U?jnR;mX(5#dYG?1e7^AlwCg zj3sAG5DEXZIAw&4e6)t;43dDY1@d+zvN8j6)sFSzg=sh+G>o;;a8xRDgZJN{#?zDu zV-_alLp9haLWu8#nvOn6VW>IBlo%9I88R4*Te`l(ngEUH^uZ^JM^anGS{W*5E8-VC z$uwkIfTU)=k6~d)x@L@y_N{>pQ61#0(;=$^A|H5qW5>hmhA%-jONR66SUQS6h>)eD z*mX&=hDz92!sv^2iw$^nxhg$Rc05xNa>sN1RE;L9IG#*!blN#Lggz#f)RlN~CB!u9 zmmwghTNYk|iOb4?j^HCeqbyaW%bAOC0`W#}uXNR}*8Q@1K`UxR@Sb7ta`r$c=rR53 zXAEZDCk>S|4>NjU*)5SqjfwoOd@8qa8&SW?lwW7$m3TM!Ymf?i&#_=n9HPD^P+qMs zXLzHEeZAMLiRl_^fPM??SPwQ!2s;^FY?TnCm&*O?gDMv|wZHVOvoF>9V@8S8+xNA zv%zknD{#l=09R*ZaY$2AJd1Uv=trpf8aAu3jn%Q6iEl%QtgMVjxc^dQ#ACG8HcU7~ zQ`*yMOs3ywTw|{_(L-T3k1cP<4PTCug3+8eA)k+g9&pC)fh&^|lucbJPmfbF>wQg1 z%El;+o*s7qbB4E;GE>+hw7z4ogx!puJJn-r`eIgBaAZ|ysuL@|vO1BQ>dNYpPmhyv zcX_*ZhWe#1o0r2PS?tBirbrUyIX)?~ zyYA*cP3V=WR##?sMO!8$8^xHW85=#4aBnK|DPvSAqxyLKrOegtm~0L&-DbNYwIHXiBfGDi#mmxh60 z5Lo%19z>eRsW!+J5S&#a_tS8>V;AD-=n%>oH~?{$QC3Eklqk+kT`3RSgYjy6NO^kP zN#%$y+ZbMnG`_c@u!Dxq`d*Y6x`S0Vs>OZyd$qxQ90Ggs(=P>$3W$|Bv9`06*Ua#}o3M zsuTu?B!a&~qvQKid_(ZK2ONVNYqhjvSb|vNOHS-nCvU$FeOmEgP-hm0QZ~Rwz9$FA zIyztroSsEzjqaYu`%GvGAhGnAS$&C#RSicFH};_C_N2d0VH|n47s_NMta5pCVg5E0 zkL$UxtKIreJ>6En$_;NPytB76xEPL|y&3LVE$rM;#>%z?VRN0#3^V988icJT*t&fu z6Xtp|Yb1rAn+{$J2>pykKlDnWhD8QJSuy#QdQ04oRR~^>M;W>{d;=UNu)DXLdltDx zNsx0{1HETVm!TmU{Fvl2A~jPJd2DMyGnS!Ir=Q0>nc3CmWh-|o^Kx*Iaa=5{W0_Fc zpXI8ciC{oE1u<&0WSD02XDAP9zx+u@=Y7$BB3CYp!lV{#-%)UTXr(>#CKRGYkAg6F z^a)7L%v}J7cjK|Y8&ZUMnF9CN7BI5bctF7X`K#Bh?k({093(SRS+uP)5w=!j@slEp z_2HSfAPel33Ezr$HiWh;R7d+UM7$TS@NIa&eIMQEKY_V3*M>R9nYBi@C{B(CHv`X6 zX*|nj{tU^9=YG5+Jh1!Tv0$!IIf5X`b3O7zZ-#N6p}lYBohHveXP$QWuEXXvFraxk zumyayN&f7acOy;fx#acCd+0o0oPR;*1$62(&dhrWxG)8H9|6xJAb0>ywU7tqkmo_; z`NnrSK?aM)#9HA?ykts26IVi5vL*_u{DZ9W4*(Lv1u&_pXu=hQVrXfgjo&2sGnPbJ z;ivN_xN7pJ8~Oj$y!=_XfmfC>8~7o~nSM;J!B__xdMY83z|BH8x;x?`(ZAw^C24fR zmjm8E5Cz5zg%D$$g1r)&eFBg3w#{IWU!a9ju&dl&hWSy+HvC(2P#40Mwn}JLef(H%cPC}rI3sl4s2inF!{@y^KDa-`zrwOS9pTP^_Ec-04 zz#A5Z-w)(~>G^_UG@WS{7i1a7&+yPoudOQ#1K9A3_GPobs+V(>5v;0&m=*BqZnaRe zD~0xhE7C`(PN-NXT%dd6X!{MgmIb^p4?-}p;OvEh=m0IC(KFLMV^2BojQtm%;b##k z{2U(9+NN$wN_Nh}a*WH-IuDH0k+$8WTM8nlfG~&955U;lk*gfO>6-aRT93P88KJ5BfYQEN1vU&7jlVT-&PNC{;*tvycX% z_=Scxgx~l-A^dI%p}12B#eXoue{M%ObcjNsq-^_o&X${&!E@|?*Cv|{zl~gQ5?=2n z2+;PaOgP_n2CIVoq|Bw&C!p)mhP|0DA+wn;;{g*mg#18IKnb4zf~UhXKT<8fiK?ZT zRr3N!0yKMU4F4)3@=}355+cu#7d?b0;-P!w7Ql^){XgJFSvcQx5#Dv_`yu9>3xt%w znpiUPb-X)ap`a2Ax!{|4n!_l0U3W;GQ?P??Nu(@fcji~G#1$qcGOS7k=aH^&naxhJg4OZ z-vK<_k4M2<(=}!TcAz}_MF*DOjmu{q1$<58RL9y~3BD)p^Wd%;H+GTj?l*2spzmI6 z+`HjkV%)dDz0|m04)-$Sz7y^v#C@PVM|1{j9^v4kz+*54=ic<8IWA$VMyP#h;jqq=LdaRWvq9v#nC7~v?8aU0LIkfhh?pswSJhj% zD$snSO~dFuOq+h1#+-8k9NO~Mnx;RmIh*!;gjK2~?RorEb+ay5$?H)rXYW25R$jdu zr+a=5x;Y`ghOM1#oU1wMbEI_)PgVDw2ZknAQvnBCphS^~>$e|5nhnf*?7eU~x!jB{ zbkPMfDjMC<=<|-ec!r$tQDoJ&7N}e3R1a>lYFFs|x{c2Lj<+k{sE1#L5}}vC3J+%+ zF=etHXDb~!tPp!-{o)Chpw@#mv|qr5nG=l)|1aSm`XMIwv8L7oNzk=Ob7bXL2<$>K zC-^m7#cY(!3H~EWhC=&sGRl(Dyw*D6q=@EAtRrrT)_;DVIz(q8b?90jM!us`hwp<+ zSsT(q+Cq(E{INxZi6C7`?1O$eeEs48&k>lHU`jyx~1GVMyZV9r-|*p^|KIST^n3AvvHur*aIE9N zpN**7O2H1FqLlS^RAzAKyKvhbVBCQUpJ505LltKR{d1ucE94H9O*U{v=cui74e~kW z8RauEb2;#I<{Dp!^kz=__z<~bHSkXnSRL)lNrxdAyR!ND7}d6$1I|r?(|H=&cVzn{ z3vACgMCnHC0LAy}g8>Tf)mN=3;gw8kOS8Y z4l8qF+$VP_%EX05k? zGr?|^D-5|_=l&I3o<$s?`759qIw+xe(O}N3JLjzpTa;$v znK}s1h8R!tLL5fdv&H>c@yMCtLn8f$g^(hDZRdGw>uE_luL3@X@;Ni-f#2+#$a3XZ zb!zZhdle$cFLnfFGUy_$R7@FOLZ#xiF2xJ>J~k4c0zU1+`*glF_G}bePWfmON6zSI zy02=u(`GQjWWw+{DeXbd>ef$N&MPQ2ZedVT^JHAEdJ7#`IaK@ajDf>Faz^Ni>0qGSi?e`gMBrJg=GS4OY#PXd1ln4 z8PW5j8gL~%BAa%mbvcS=m)sU6^4!6fA0)!_@lZZkUjCpva3me)cAJ+YvE=0FT>u^$ zT)m0_=DLTz5W}~EA~9g~pq2(nD|A-CH|LzUN$$+w4JrUSjU&@7V?*2!h!#!d7yuq| zfrMo$gnf8u=8rLlYMevdR+xh=M2Ff|n1e0EhA0syH(AaXM|6mYB|;mjtR(=9^hrtr zI6K`iFa)9esGy_CFlyXnl2(EyBhjKJBhgHwfH_UCT;C{;g8*zF=&P;crG2ntXm205 zn1Q)#`(SHfHl94A)^Y^-ze!t*6COh!+nr}UANjJqER*B=zju3ahqAJ{wpM9CJMOmk z5w*4^R&U`xZ>b*eH%&^~=njKZuMBvmIFmL-OvqS~WlW1U7YQVIZ0jW8Ie|PI%D6*z zWsvW>y=c&>(+_g(F@4mPp^Xu0$H6 zyZ-WN@Yqd8u8#INB5XiN$tc!vn+h?<1SB%nr?00Yn+ndF;A|XhJ423J z$4ykG5bHB{e1G_JKsN@$ldEf|V;d#!8vj*Aj*kZ4(L)8Hf9<{rHHgAStJz`iM*`1LeLr^yU8SEtEL zHD{;Ej5T*B#3U2ehVl5lbr##&OM!bU_VF zuaqa=1y}=}sWz1I!wqUIRO1Ay$;g^Gn;x+ygx5}Edkhe!JB_PifS_<1J0pNF31SSs zJJvLj;Ky35$9Q7RN<6ld-Dpf^!2pQI*4hv|1*(mrFSUqAhLp{@)oqEp3VYE2Sgc7L+6FLdjih5vIku3ErHW`>sLNhR(#C+8aJ({)N z4ccJcETFrEDRP)Z?tN;rcZfZ1*As)fSC@HQnble34Zc;@zKMbpK9`7Y~GxKvoy>L(C z$$0Z;`iyFe1+r%wc(zy+Y}ebx*AXpJt4K7guCW+qb(G2W|y+>cl45SyQ0~D_1 zbHcNcINTr8;7ARIKZ#2>+;|Z*#SF~3!Y$;TYq3w|Ps=)Q{M7HkC>&;BY!vRHSGndi z1`!_i(^M3WFKk5$>z&3{=5=OUUiZ^$>ZEa2oR?IY)3})lpsUiz>5b~iv0kX8TV@nj zFrzq9t@1C1sFJDT9xev4N~SFgH8Dt>%JOZb$v{bxwhEJuBx$RNOkC&(TNW)QpdZ}5 zdyyFPy91i4-mf=Jg+D;GVB*J-d!}e1RR^!F&ap*Q=h!&<=h#jvbCg(^K+Qkon|5Od z=QwD~V||Ulf+uUCB>;2y+xYk4U+ZjOf8XxG26kZMd5=8b!Kd^$=OYS#kxeDjsWY1> zCNs#?+!>?**aQS{T6LxmD{U=kDLnHgM=VlesE@F4}=R!88tOuIC%&u;q>uDTg4?S>bRC(Aa`NXNC=c2+VCpOM%7~ z1ZLiM8316f)xn(YV15&#ia!z;v4zbYfa23i}aO@BZi(b)_ZHYrUZ|`jollmfD>cl%u zT)Cc3Oo{EaayyV##CAunpd0IVkgE9|UU~Q$$jRbih->UyGVx!K)7ZLAjt_U);UkD0 zE<>Bd#Ry%9g$;ceLCIoS*a-s0p2UzBn_)@!*iYe(3ta}wUBnpb(Mu*mUWm8_)H6D1 zFJlW`w)O|}N_G_Y2PUP;oIAQGfv`wrck`Xd#3ZXLLxxtjM?$jR1VRG~*K1vj-Jz4* zBZ^HpWcbKSYiIBzB8d^ex-IjFshCj1W<_7?Ylmv?ep1DweK8X{V^`x%P zcK8_Ny*lw~3UZWlIhSq*rOm4mh<&Ki3~&#OriM{(VdJMX15D$mnnB()gRWFF7&--U zr41BuHA-y|SHpC+$$W1D5uwZ1HpO?96jgY?P+P?#@QLvD8DCmhaV1yG_t9eP#Qk0c zXLJOzBodg!8Se8_vcY?p^X($_jH6LNjrG>ihh2Fl*}?dg)# z)50~pJS}*my@vXnqgQ~6=tbu%IaV8hcKrqZG#&VZ)B3uDH55owcP4>zF7|PR!KTKt zhx9?Ft5EjzD}tdOXKz5Z0pZ*6t{A`(p+)b|-al>Eu4lq_us7~yd z%B@6kCU#7gGCSS;&aQ{9zy8tl$Q=n&VIu*94wC>j{iddZQ4(K?MS`>)&cUDlrOP%f)g*p~md4wwJY zBT4>;r5j!B|Bmhs&eK?@ruflSt6+VJS_=GNzC&)MbN>-lu3QO6z6Xl2a+T%?u4IXM zvZ|iYJb}DVL*5amml%#<=T)qKDjVEtk!NEy_wUT-M`bW;*2S{cQD!Xnx zRxIoF9N@yb5^zb7BXus}ju;}v+G4C1vRs&e3eh+Ua(!?x00;u4X#0U2OSehU;&Lsv z){bkrV8Aw^D`>#JkZZqm!yxR^<1jYKfXG+krW96= zd?fx}5czPX@PX+L=EJn%1Jkzn5I$UB_(0rkd=Nmw2j-dZfq1|NlcmW`_+azyr)d57 zR>(-Se$3i!TR+D5D%L}~eyr`T`7Y|sH{!9-Qm%-qSwBuh^>FLQ?RdC;Z18*lDB|^F zdJegMEJ)4zaXV6!HPVOC`tcS_#mpQ9-N9Kl%^q%O}{pF=-~ah`8yWaKM-g&VvS zEC+iTMOg0M3v8dKh=VWQt}ef@P&m%iX?PJ18SDKg zs>>AMc6RKgl&3nn8>JCLZ8$OHHzk8f?3m0O+}Lnah@HT`vIccI@Ot95I)&uSfK{UhA!LqrCS2S<=pK? zIC8BYpz-Aa!L+=)36Ok?E}Slm;^aJu1KT=^lgmmRh!Gp-miOvtsyp3(rP@Wtxc>}Q zmuegUOG8m`yy*_tclF~OoHP;KKq(@U!JE+lmp1ZU2zk$;+K7+zzP1rulxWg-YIZor>&EYHI~ZP#K-P2jJe2Y)~O(@0o!+T&jc{~Cn7a31{i2L90$ zobz2*AufMTJmL|a$KI!e;aDcjIn9SqJ@t5K^i&NiWuFD8^&>nq#=~tfZe@(mF~+~+ zL7nK~LS2h?ix0~-#<-@O-|l0)jzz%;_SBkkVY^@0j$M~Gu{*)Yg_AtRtWNIW&B+~{ zJ*{x^LtPR4~K(sq6oJ|>z4p>LzuIuLEDwHbh>b6FrG^-iZ;??xNA})wkbcG zId>zD+-A4?S&UUSVMtAP4kML~pdF(@xIMxlu-kJ(eR;%pFzb+K>?NFksP*L;o9A}{ zMO?S!p`b9essHqAE;2wJKM6AzQ1DCF7c4A5TIW)~2QyOcL?!l5fR&cqWQX%qGSQTU zR?dn>#hzC&RaM)-AkNO%K3Qvx z8TVXkFyn?TH^4kU_p2#tII2Ro%=f+$G@K{04Jj`;dYtUE#D4_DyXlR~rj>iOvv5%zv+B%Mg%7yq8QiEJW9TTO=+)7q)K>{#1TVHolaD#B zqvO_R@lB0D84s;stI&8O`dojF=HF!5;zXX1c*B z^Ujz0cspR&J6@d{6|1>2;yT`l-AB_JADQ4`ftMlms{WyqFZ}N#^AqM8gSl(*F$3I$ z_ELlm#UJ1pPd>o$NoN=G+!f8GT1XgYfv<98W#2(Qz*eZjG%g`A-c91g?6jZB$_A>e z>>QJE#f)sw1Kpg9Li@8WI5hnoG5Ju?mw-lnPU~JHeNImXnB^+yMo|o8Srl0r7Y6_= zw*VrCFa$@ig3U-*oy2a-YKxK03isSa6D>xygE55bxP|+?my^!J#Kc7q*z4kj_n{^N zd^)8d7cn^@Yi8sJthaZv-Y{iwKi`)o8(J_57_n#Zr5&8CCb3*ghH%Qytar`ciRdln zZqL4sPSR%2{xO}T%ASRR=C(+WJ^LCuiI}@5k4Lscj#JCb!s2&ZETldAS~^LI&23SI zU@IOoy=W9IQlrFG!a7Ikpn`2`S35n96j=#!gkwsPBg|5g9O0AF2&=O3j-pS~Gmdf?q8g6?@W^^;Z zgn>@u$1yW;%`EGDbgf2=AOmZx%QDW0NBNcV+oqf(jJyh6bVk3rq>4kvmt;a2!?fJn=MAwL#$ zXSSg9lcP=-nHsuAOG4nzPs;RCu}-SOO}Ehon0zv`fvYJP}-Tp zoo}qWdvjGyd@roelaOaEo2^L1?BL_oIW`CB1?Jd@DsvS6${bsfLfMGa#WuwKRfRdW z6)KTa;E^*DC!)L<8=)^INOt$(j0ER5PlG?6-|S;upAHBD&cJKP%x^A=rzOy!bnd3h zT05$J7VvzAjD@oLd%ijEmzvM|EMU=m)|tpNp3mYrg^NHFZA9#Q!g&bJGm)NRRyVwC z2eLZODWLTpdY(z>H1kXeoirSg|NMETXkH09NApV00YWpcMDl3&orU+jc_qf;yb|9! zuY?UYIBYb`Dg0%G>QtfD!1)K}hdJ?c!GV%HdT~~E`qVG%!)-+u09GH=Z6fuR zPIwNYGGd|Aarf*+HOPm_v=?S|+>_iA>UNlQfGfuCRXy{RgiGTlZ=dntlD{ zpoe`>DYNK8C7LvyWN4DD1mRUA0aGhyRz{YY03j7yN6!?}#kbyLjCF1)<6UTwd{ok4 zlWt}3%h860y6EUNu$@|*g|zu~C5}k35$Y#sIITAkSZ&=!!MyvBiQ1xZpT}h=2Y;Hv zkr__e0!1X@`6#&934*g$wB_muCBSJCmmqYS#Lhea#1TFb5j2SHU<_hY`6qCLBK(lP z1(R3;#DoAzDgcv0@)v*Teui|j*M?SRhLpRA$C0EqnJRoBPVY1sIXp5-1}41~fEFKc6T6T=$@(|L zuzxiSW1PXQV3ehbRm#o*f`{ZN95G~G|H zp|Wu;!x!q_NdTmAH^X1uE{*gm3!TO+!quKI^f>WZr+KnTN^IfKZ6v@5DDm6M$VF%s zicpJfVi1ECTSR#9AGCX8jf&AX$7<}GV?FlIu_9M;xHQMguFkRY$!9k+a|sUs{*wHE zT~wpNui$lYm}&;Zd9C*|GWN2`TifzU5pSKonJ*%8>s^S0rKtDl>)m`+TklohU-H%0 z`hfbt)MzW|2jRr{!Rb@{(c(~_;D-%mTZo*hLr4$tgw#ih(FyroEk)~u9^Hal_i!lz zPLl+*gbJrg^esM|CJ9P5j?$OfI7+W<9Hm2PH`~NIpvdVv~A1& z?-wY+a_RqEsmb{49lF!T>rso39N8{M^qS%|?nSuD5n1c4D2|ko>H{&9rLASbc`bHo zucDb0dMoX7*9{ZHmqq>`3OJj~`(VFb!eo8lkwo}x`5 z8b98@&yw3(pDN)js@-HUjZS7M?IsIm0IIcFFau!WY^h!W*iF{RUY3T(uw#$h4^H3A zr96G<2oF5dj`TnlOK1Qrr7dz|EOy<`Dz!{X+2K(PMcasjZKA_MOOv0ilXn$c<~Re+ zZ-zO{n1pMf5eIEuY+7aSK^wG#e*i(@2O-axMM^>51xOSX8A((W)(dw+&4woQ0+tiW z_zrxc*#R_2_67zZ8Q=5q%V1R67F2AS-s*gMop5c6;H@e0obcVCZ$4QEL$3$1aV|n_ zZ;Dzcy!deBnuK6BD_oc@4glU40mK2o0}((R08rK?i8uhD6bV2a08q{ZAPxX1(gF}i zLu(NmS9Lk9V9UlHEDK=cDp-6DSWAzoBsy`0E@g}xN7W@W@RSyUC2Mi~m5J9Mtw`J& zJ7!i&y-NZ|_M$O4B~OxzLzaUXFIWO~H~5&zt*FX6z?C`z=Z>AXvBwGD#QbM) z+i2mI*QEkDg&D^R-<(9kN!}O^BQfzf;oV6rl$>m>;|@+Pe_;}nH&F~ix~RiRw@STNaELd!3lxM$lDqg8YWTM2;Y`msi-tL#TW8Ef7g4L+L?S9{O8&)P)ld*&j7Z;MT`ry_v z@i!z_8gKM7vKg-VBX9zry;IM>!&Agp82K4>3Beb3laMZC6?QW#9DU1%J#=NUZI%o4 zvZ)R$R_20LZn48!wFx_mK3plMF~x_^=0!_hDJa&*x;A6u4%7^{Ao*P)v-qA-0iW3} z$xLG{O{tR5)SHdSF z3%;KlIo|j4>yK5)5Fp;jpzmkbukpKA89}p-!6MpFpWl-PRM0R! zjTBYJt-}s>$(1r&?nO?1?-q;?EMyyP{ypwh^rvF)^Sd3a!a08TcE8)jDx6DKk1p@^ zz=cIREaSO8++O`?lwge?i_NXW{l2eJ{q6W56Qb4;)!$xQgUCmwBlh{e;$cL^1DE+4 zow8n6`}Sg&r_3=xKCK-f)@ZRF)n544f%Xm2S`?S*3cR_Q&3DKlg9_ddnz6KBuR0pF zXs@46-U^R)#xHJ5Td;ZF>zU)hRg1E(Zj`GX6n4%^Q`B{C_+I37vCu4C#Xzd72rmQ5 z@CxZp#?c(7cNS{bi9K6Pt*Wtkb7>;ngT}hE$eoRI<0hQDBPXX*o+;zzR!Z!8MqJz+ z;z^QDM?VbDZI`(n1p?!+!St039|qT87k>yZ;fG^kI^wWre6d*M%6<;J$yDoclGb+W zxVndXKoVGo-DKX?(X$+^CPeaAt6;*7$-+LwmewVkwhLTxNFrg9cY#R7+L?#Ri>>l$ z^NJ%Cn9LF%^(5X{ zvw>!p^Xe1+p2pLUDMu{JrgoT2VJIxEKStzkl)hX)LjA+*G+> zcC270^lgyA`dOJqKO}7lKLXsrFWpxB!fhA}b=>C{tA0Lm_WK3h>peXgffoC@$Qewb zx}RG+vn?;|IjY1NbXMbRJNx5=or@33wo~)sRH)d2|AC_O7tJ!Lq4HTUx%Ck|&??1@ z`8)w1O#%LqfWJuruvp}_K9&MJO2FTz0N*3vQz^iA3HWph@Gk^>CIxtifWJ)v{)vE3 zqyUc)@bMJjVFEsx0(_Z(2UCDA5%70-ur1RTegJR&Vji&MQSn*EsGwv(#03^LDlbbJ z6_o{yO3AWC1!S?Jvav)_u~?X>L@Y;C7#1Na$Afh9f$AXPNWlzVyhl?2DI=>hiXjDMbw&UwEvqvENRe5c z5kShy+KT|f2-a@|5Du_9Bfx`jw^*GKKzPCG)UqRc`Dw81RZ|8`px-teX|m{clU$hi z(*(-$+fA}!g7&1zflRQQu^aKN9QSBy6 zJ&H?3q*1Z3c9Z2Etr`%EYd2Z)10C#2t8#HI>rXzAGPuQt=9CY@6DENqa(*CTlemrJ=3VXNpeWq*j8Gal7O86n#F|*jJ=eGV0&`7_$t-TIhtpl@}lJ$sY%^Fkg zJ0ha;nI*u*mWo5PQ(^SqnO>$P*>omz;<+0NwkL6=Z$VU{QaNB8$ zb`+L7O;(rInbTx_X{9+$QOi=xPLp-fk_vH}tRAf+r^(7`Ne#gmq+6=VX|kHMuAC<8 zswEZXG+ALSsWqp`TGOg?nyk8()SuI2{b?mSP1c-NpVMU3Y5h4()}2Xqw ze;)pq;D0p!wd*hhV7r?6YnXw9k!JvwL+p74<_TlZFEM6{J%5+>Y)^aMl}>X9b8DOj zTViGhsJ{hxxt@X#l*v!qx6bCqdoaCM0BPz@<5Mv}8oSf@ zY79`xYy2n%NK1DbPZEGuQ7|&t$mJt|v~#D?9|NStJB^JoK-#|3I4=gMTsAI`0VrSU#yDD@y}&S`v+2~KR!kY3Yv8eeDlw)Sv(O?x`@;;uHY#t(>4Rzp?WajkcQ zk;i%K3Y0`!dSr9!4<*qSt!Ds~L|as!0ZPK_loD2X_HmH;S;w&+Qdgpz2BvNUKZi8!srByOK14Uu_peW!7becx#CeBta_`O(Xh7;~J3JNkaKT$L z+=Y7_^4_xHjHmbeU{Eji5*M*W6;?!7aUNexCBj7`R;2GFoceI^4rkTWub%wWikt55 z*qDQDLiL3)tai>7^&&1+NQ;aKmw4xs}L|kf7SvL>|0Mw!a5C;H{MgVaD!1gUM z#4#8fV1p?qqS5G-XyO2XaxVaJ03hUZ=Yu!^5E=;(2LM#Il0+N;P&diizbL7SSZ8Dp zgB5zdAq8HfV_YHI zLx64p(E>)WXdjkB8~{-NNe1EofJ$2c;sAh3TL9t!fJ$2c;sAhMh5*C?0DA}lhywuj zAp#Hw0Bo!R5C;JJBY-&2Upv-oq_+m#+*;!5Gy$&al>Jlt-ijcZ-D&+8t~ThonEPq{ z1khT&4bI7>gJYi`#kO(!fHE&*gw{`)Dc9reAA}=&!f%rNQCVH^DIRX7nKsaiHT=D5Od2K57W(-8Wzy>#T5JUMg zp>)dk+T=@%`SBYtD$;y&QV>5gn2;{tb{ZUkxkz2J3&;8gH^D=FvCG{B->F)0{7fN% zJFXw3&8OdxCT~=C#FNa!SS}MCVh3Cusuv8ipBTql9VK9w!L(!5mfO}pcE<}(**XRn{Tl#>k6s2$C0Xu%wP#)t?CxCGMZ3p7lE~&iwJ+DymsKO2CrpZfg~~- zVccGYn=h27<^1eYjFL*(=`yfW0_`Rxb86N9yz3WVKKsh^#;42J)K5?br6+%Ota{&R z-@B#neLv?%4mtOQ1GMGNmDa?ve<*kPo#oPIY(TMaNVKFPz)i1AKmGxL;U*HlIC;W{ z87mw7IjF((C#i7v0!~KZgOuDY zh{d^AqtJrZup3`tj1v;+2`3R_l(y#N7tBD$52_Qe@ZSq6&qY|uR zl~(HiJk&ovwx^zR;W77z`q7b!)f3YPT%0N^`+g7BBYm#uArm(G`mq3w+QBPWhTgp2 zH5Hu3R-=t)WHF}n{ZbaETqGm1hzT!l#P0f@j>5&^0s_>e&)5$1T>-u(OlJYT2!F{AaLG8%7jbxXf?1E3*m0Al)<7ubVwom4HVG{z#4~yM}q9n?bzD_j3SWYx6v;9o$WUkX{osXt!xf5}t-y!C9t1Ky2(R z0FrnWh`EI4veJ6dGm=dfF5*JZfQ|V&n|R)iTOd)8v zxJN5oy)9D-fEPGDn+g7egiCqQi-5puK@Me3_r+go-Sow1y~(jK*0rvQ`O>aD zrHYQiHAY{@l#E(cTpGIw8&(p?Bp}yZR9n*)jllM3OnA*jT5v7xu{gUWHM`}FpiMid zm;)P7QJ)7ZW56+pEe4lnVLCKByaZ*P-hrx=p@($QrmMHZOC>B_wVh`5YT`8$>sRNb zaSiq4!dWnAD3=T8SZ|%?T>mRSII+o+yXlVueb)+)XaV5dgc=7}m6wG}xl-QpO3R(R5`1Xu`S*i4mR+}Kg#z*yo%;>+&;aodI-gdri@1;O9hSF z+*;kIw^k3KKnuje*HNdSE@;$T#$W(=zPjNkrL}T}htdQ2R zyT!@O^()oURot7dwb!Il$4Ewss~-9ye^2oE;Fi5|gKG7;qz&V25Z6_bUiaG3$x(Dand$m*+dss;uiM z6WHBc5!;aKcx;FfL+NMOf5c-ampD?VbxAl_tV5h-&D}JSUBDlo0OXh zy_Oj3`5oAvm4X)mXUF2ZI4+vqXy;^?O1!(I=q5*7xLAIO{$LZjCu#~&bi+J$OW&^A z5?8+#&2OIz#8m2!VB=+z{?yycFj z9C&=av^x&I$NmjsQqbUXkPuvfhtW+3$BiX7iHk-V zJO^AXM62vm4-WgDCZ%lQ+SiF=A~F!qj^gD|y+mec%}q>SuWL#&8&StyrnLVPL}utY zb^SFsk+#mRblQ#0MQb;Dy-{Qs_ePC1$b`|xx=2JB#*>&&B_qA6MKpbe%SBV z@9K&!Wa*oTFHTuK(N!Cc;8p_f13bRK<%#i4Q9-PUu6&MzD$Y^O7&;vHY3YzL+5eja z5dZPO4;}7T=XW`xM9lQk_#Wp5%CS7;?#<_6M;-Ux)AQv1faje&ZZ#ox4D_(~HI5@W|?l5rjK<05w5N2X(u>e|V>zuwy>nse+ zM1j#j!elGPYNN1UITXb7Kx#y|D?2^46UzO^3x!PX#OH)`mSGXL`QYmrB`8#>WD6Zb zkAsgp(2!8u0jP`(@(hSsk0}t6F$HpnJM!&l8=GNs^G^|o0mU%lGaloo$v;GVT#U!% zbJ3R}=-LTcMh?sjwpWVBw98WDz6I>!#MFG=L59;G|TTFtvc~_ zoo~D6v&U`1caNxS2TdG&%lej7D7R#Cf-M!yGYvm8?a3s1WPI-DAU|HFpL?Rs_Y3;8 zYJ!QmUnag~6LY_6^Zh#U^-awEN1N|I;j7I322c59z#L};HP@HkGckt|it#=2@`<_M z#=Zv|6LbF^`>fRybN`e0auajEqwkG(cHgq;J>MLkJCKAuI6n6jeOt$G>sfx|zVSH= z(?zRV`9;ev?YUxnu7kesto_&#g^l+3oDE;&cys}C4qd0xg;PDom7!~rFpsXQ>B`cz zk1nVj@AOS}d zDRyuTY@4IhDU3oVH@M7E&?gP)0C02!5C;J3B7isms6_yA08ozr;&?_e zuq9N{iUUbtcql*|TNI1kWbh=mQV9-?H97cd4c)0wyci2FCfzxM<;B9_4|u=F*>LS@ zkxKf`6CX*WPt5xk6VfM!d`nQD-=6slM&$+c1Bi4=TXv_%+2J&E@Flb?%nE*)FHLeo zVlx<(ZdsM!8*G6iGP0@!-=s&^3C=Wf8}I!Rs@;~58>d%#6E6wIci~tu{5BJ-kl$vK zn!~D_IV3N55KRh;Xi`kzqrJCd9$u+jWtk&9R|*_qvF6|ipCuRAGk=dVC;?9RNxFpy zC;U6QjR*z%Sy1SoZ}SbjuJzY#c<1Sg2hsE%fd)+PuAo=)!*+~AZiZ0Yjfbf?I?*Cb zK^k9<0m4rl>ZCT37{U~6orz-zPo2j1NyEwQG|($$Wf>gn^`;E-bPcK3W^@~gZd+<6 zfwyf-prlmg&1^>?r7G42ptqfnN&_IJD(VJ6O0|{VMgj%j;I&XSB0{F&P(*^q$bPJI zW3KK@nXyzI#c@}KI?4&YhZs;vB(s0i@3q#5(7RK?IgoZtMMy|>bWt2aornGG60U_d z>DW9nQ^9jhI!b~`Cm~TfhI`aMf|_JYQ__~CrBbqihjSBW;eDgh`hB6*3H}XlP7APk z;>GN7!-( zctipR2~ESqs9+;gIdWx@J$np1n$IjY!Ml>wp4~*JpnLq_gdgMXL`TSyIB=5?&BYNa zB9ek%5IGvx&-tcYZU>L}J1AQ>__!Rdh!0TX=y=2Jj5=l#1Hd2w<7_=rcI*I)V@RPz z_Rmlh@@=tC#F@q?Hkhe$)%3T_RJm$;Q)a5{lo(Kh$Tw@jl9C_CDA8=S@Ra(u8P@%1>Rf?NxNs~n{VR{ZrNu~3!7Dr>C#R4I$d*;K@_w=@4- z5_j9{0MO`|STE%#OF8Y?pNXGzrce$TuzQnm6HRTSP{(WH};kphkO+cE5Qnu52ls7 z+K}iOksE;<-+BPw<+mP(`eggH9JbtYE<=+6GY*MFQ$v=8sCuMRqr&dNdWcL3WaP$R zEWYLC>_;^8<_|p^Mkvek;ndx zehG_!C0zu3`c$5zioPY2`h3jzQ@pu%{sM0Fjfd}nv23eF2wbPBCOGB3d&0Q38^O6h z7yX8Xu{(r~x}#p#`m~!=kl{U`dnGN_^ijecfS^k$)Ou83WTtl-h%9rl+6FHLWMbPK z6>D{linKaM%}ND5#y1tTH~`oZ0mK2oaS=cq0306y!~wtw5kMSbuUs6JHTW5bwr95@ zid>Z_cR zxcpGzN?zjy41YEBQ?gff553A1r}4T&g)8xm_c43}mKBrq_tUEd0`2VccBjhltGEpD zT^THc%7!t=NVLj^0gy_S4Fe!qDjNnsI#f1N<3HY;jQIiLhq6lbS(wyl>#eq7{>Dmo zSlb>0AX6Xfg`(1qAQ#+;zOAGS-P7oxa%!an9ML$XBH~HcBHcjkSR_OgO%vsy38F0G zgbVaY&u{A%r_vqY#^=CD;`oT|&Km9PwcwZ=53U3VA@LGO5^@znN}Y~ZDupNF%8ODL zloqaw#U+Fs-z;6#wvk;*t%U0(W=3g8d6Nb5P34*p)zO;tnLr zI5!+oI?A1oOXg;=qik}RKeZ&8|=70 z?AFuyIPk9hA@Ya&~Nq^X*{bA*4dp7i)6@QW6w;tb>!mZ+Y zYvfSc7cMf zXv>bZ4Fekpnzap&Q}KQU-cdhF`1|n3W)kba=fU3&IBmf^8dMbj9Xf5vE=ngi**U3; z-IBW47oisju13?9HfnS2!fHUI6zGJ|Sh&Zr4}&SpHe-F!3;VFn5?n(y(4m*+^Ls?N ziP}dakBegVe{@+#n(yNPOUd*(oqS)4k8WThKiGy`*Kyt)(#e|}=iTk-BW`rJqg-jy zCv-Y82E-bj-0esj^;;#R5%(cp0CVn;-zvd8d11(Wt0bX0xd%LNZP=psPVyUwQ{YEC z9^N6Tc$ybthfVyg5_%5#tr9_M?vQLpiu@10L(;aYfbT*1oEabd2H%C{%CG7a_Zc}- zS9_(do)6|Z@*xqet6!juNF$%w46f6AoHWD&050MH%Bc*@*6)fXO$nKsUH@cp2+AGRDt+%9_!!z?CN-!wHn% z4t628|A)CZ0kf;B^2JY`bMCog-KtwvxwkThgoI<=TOlMNBmq*DgjqyTgj*G6h#FJv z3AX|w#l2q8R=bOZR0#Ohzg2m#{oo8L>yb+vw04*&+f+e`>nOlaBB$R z{l9;IufDJD*?aB1*Is+=wWqcBUfahKBZouC)rB}%`f9ixJS&AceQ-3gt-(}+oCfyR z{=~dx6yu<@&W(ctIv0+$2cn}gjgHNr!_e?^$UEoIar#+kNTe4UI?`h<3&pU`hs6QF z@!IgGjx*mA!U*C(gcpVYaR6{i2oMJVr-lG=0B~Xm5C;G+3IXB(;It4R4ggLH0pbAQ zsia3`(>@C7>+-qJ9V2ZDy&)HN?wztwOix(ZITpw z@=?r5nk3V1ol7X`v0LZRNlNV24mwGL-NH=AOzK&3yM;NC+rklkw>8EPvG_{`SUXTOg;(;Ym(u%uw5;MK7kUHgVmTXC80kQ=qHfCp1hCA$YWf3 zl-gl=ZR^)s+_1ck@KULFgpEqRBTUxh_ur<4S@Y`?WB=j zm2;k5vAai`$Q-3v^wOm65su;gKP6=25_Pgd4V0D7S?;K_~v zuG`SfL`jVE2}G)ok0lBbMq+Xk=_!pQ%SJ=gt(b<_E;XK;;SqZ={wfTHH5}| z6H(lN2fYh@T`OhJ4TrsWVh@>6{>STe|5DJ%Q1Wtm=$L;oplPrO_2F3;;>)$QjzS@a zx1!VRvrJ*Q%V(UY$4;|;ZI2|&jD`z|cj%=7F>-Ua~=QGPc{Gp+d^~CXfs26ZV-!;WD#O-ZYf}~xO z4bX_wfRBM6$Vy|8pF544?AsYkvLxwXGY~(KOV_X=?jykuJ!AW5rFGb;Rt{W8o+)b$ zzRVM^T_|>F%l86-$;E~_^rGvZFbA%R)qSYq!bLzHkloJGT;tXjIfKDvK;tY3F6U=3 zcnv>`gDdc1oh`)v#;fqXisf~X#qmgK`$ypyPXVyDb*kg;PU$XoumwTrGgz!jMTpI( zg%t%GmyH$!EKzK14=A#XVL_&b_hp0y$XM4Hqt?>%Lmqh6?Z~VNIt<#d?CIe9;9G%j ziQ=6aXkXZ&4KAF#5`Mg@k_mo*VBBe8b?|kk!C(p@eV()1-R*OyymDOy8N$F)wtNF! zCGTqaWNA3DGKejOtB?S%N`ZC4V!QyBc>*t#V>O&oisR}lWrn&Iq3vPSaLSu>d27S6 z!yDeN<={?c**_6n;F`#@zV&>{G~bjdQJ4ctS6o&TZCc}bex;Xcir9HT4uFZmgALZ} zJ{j}i?k_11IA*=qwyYLq>N2bd?cv3#%If)*UdJego*e1zikWxTt@*5g7 zE46UlaecN%$7Ni-t~}u+MEGE;t_o@rjbpC#Cd%9-;nfVDiA3Kkf0Z_N^vsz&uAeA} zTiaYjsfvm#sY;tmsdD>F`9;SM2qezLKvw3A9*QpMN7`JPQNXvhx#}yoxt^=ExxgcI zq|H?yH;S-3s|#as0B}JF5C;Gkh5&H@00p=v5eERT2m#`lZO!`U?aQt9=eO&c^=#>? zWWVAi$^zLx=Tg>g?E13vMYl2Q@XHRZNn`x3*onE(I1!wR>th#VKf%)5h zo%r8qw_XWf6VoWJ8+Yz##e|Q=G=55kR==G@$R>v!B}6 z80DSxnqoD|3?Ibk9f$9w*A%regmBG4c#PE;6U^^SK(FwC2Ix_^#B)g^IwBLF&?*s` z*c6pL+QVYmRcy@yhJ{tJHESLgR>jsVq*z!LTLWNWZK<_uSw@41MYN^<41i^_r4mg# zmdTcyG%@t4B+@Q1MBla)^mAUdG`BR@F>m9gD^4V2vI0YBB1cYeH9CDB?W0UPZqP(6 z#epY7%3@!OVbmWokJllO*6RTA+xVe=^b&CE3E0N-^x;=+lP;w)H;eAN-dka)6OXPN0an$#Z9 z0}UsBb>8P%?+4v&$(v#)cgoluVJhUGifBR%t{AO=jRI1WPm9hfs39yZ#x@HXZ;j(s zyD~ImAQXNN6ymYMn8G9~uX+e>D-ji*8{{e#*Q-_rRX9qnw_{uoBZ44$L|+?>5pm8a zbB-m}n$xtbHf}4ezFFOzL!%TH>JPfrt62w5a1A~%2>yC}VE*?F_;iy!ln|YoIzFed ziIIoh{ejli{X8x!VuQf}ODrnF9Ndhq=!!b>&!6UBFwMVE{JQc^R6XrT;BGrv#F?zl zvH=j5`~ob&+pIB5W+!ElX60ZKc{F*9HSY0-%04gnclON@Ao#s_!%{3xP=&YpWZ{t3 zg+oRc4%u+wpmO&GYsq6F|2^wdkezG5|J1-4MHl~gifJG>50B5Xu5sV;FnqAM#oguL zLFgZ9s}zLCl>(?yaya;MO5T$?Yu_+H2(r4n0`?zU98i$QELWH>1=*O*Y)FK#G zgLT(4vRozse+gQHe)kDKl*&{Eo0pw!FcJwRW<77OIP( zAkg+HG+@qSNN~OU6AKY2_4OF??08&sU?^?Yeg$i2L!8Gc;M*If=dm=-Bf4-rTP}~z zmP=Tcf>qn7`JAOAF}ec|kET07nK@VAfc$Zg4f`J)tli4tPNmmQ$;WZ8I|sj8dbGa* zcH9!>aEt?JwZ%pE`d#TG%0)MQOMK#dEl#hcZ>jP?dwb+|$go7erJfU#fOPE_%cvQJ zXKr8)D=+1*x8rJlG8GsEXS5%I2Qn(A%xEb+BUmB2ok!7!V3!~D&8b6e0s9MyEq=xB zH&|{Xmi-Vtm{;!_@+Rb|%@yBRaQcIP`3udA;HD{=O(P1&ceCjDui>A2sY~#WT`%hb z{I~G`F8qHE|D0++gMUuf*W$lAl+9-gwv*2Imoir`UrG2Xd9M4@GqFPG&&nq_EqMrf{-Bjz0Q&CLjTm31%K>lgK zRGw-`O=&K9w^Vu1rae+}ckk#=W7y~F33QI_#?A8*tleZ%CGSSjWboo{7BRTg1@kmU z7Rhqu{(SW$98Qr51;ul1*AR?_oDVV)pPI>1em4v|*P+zY8wjOTy@cbFvLFbSARb@e z23PAeI9dGGW9xS#Jomcaz{pS6n2P(Do7*l?=JTjXDd`ODpUc~acUzZ7YxZg z>YG-meiW*|gv?N= zZoEZ-LPfS>N(C*{^_4bPD<~Fjt8fWaZgX8zZgUM(Zgcq~XVex#7Wl_?!JjaoCDsKz z#9YVxbU(Vh#3X(%z0JKqfbcnABZK0Q;oMJ{^^6+EWrp+a&#Y(A_L%g@U+)vVS^?KY z0Blwf!;K+ecN6MwLOv8jpoS#mUO;ButGZmnf5vc(Ac>Q3d+BYy2H|=q;X!4S@aca? ze2UIxlTY>(nPTSgy0bzq7=Ye#VzJ^=ZsC3lnPH;+Nf5EH<`#n2L(D9!0kFXK6w4Z} zP6WWB8UTxHPqA#t4I~!Qo??k4D-0Gqqqrw3m%dft`fosqih`?k)MT{pG4f6KLalb^B#zz?ecmx1l%jBWI2RpIgpbR1sdvSbD*AH>T zDXliBTL0zXjez1r)779svkQ)qEvmT_+x}l8@=llx<0p6%bM%{V>tklyv~p3#;2y|a z!O0vXC2t0zOz=0PCoScmZagLSkN;NYT9`4q!WC)s!yvPEh&@G5N{GhW?J$&v^vMOa zQX}^WU_DSD&hAwpR{^PL4^8LwE3kmpb@wXszyyxdfDYFhMxFm1=!niqMsGj;1vb9+ zV*ws4Lf-vZoNvwgi{UI}F585jymnY-FTdR|OY}Ej(|YsG<9&%Y!M_21esf5+1j&Z) z#biDEY`HI5z$ek?Hi8JNFDE&0(x`d7w&Y4CoS+G|-QMo8G=F$1ef{?Fep-=Z_A>%7 zEh~9r{a8>Ub3}R_BB>>%(H%P{OJFnZQDA5f*bw3H0(Mhyqyu(RAca(K-i47Kgy)ik zgLP&-eu#D4PF-Wz&?f9#(uD=8@^u;bdM)^x(p^I%q2u^cU^kqS5ZTcXI@SS%S;$0_ zuq0O4>_*37VL&!!aU8HSmOvwzoDs&GCt))l-C-zT>~?D-G4?H7{qQO{oZcADo1S zBo={iKk%p4aIf-?`sl4>BK|-lF3)nD7;Iw$3|eDsdznkKGK3tBOxsrhHqeH$3gJ*o znW+m0j-l}u6jIQ`-UyO!I0BV+DSt#ahP^n|YfeE!;z~TMkNEB+{V*iN&&ph-E`GTY zC$6ClEht!k^Jd_@QEfEDxS(cnCEVbmAGr7tTy!Wdx`xhcK}+Kf=O*6;WNo?yFtl19 zY~wp^q5BM_}deP#2>BS57rI#$(mtLA(n%$Rflj9tRU7+E>mc#MR#K89C$QnFI9bQv< za-=EYh&PY%@XhnfJ1F7+pgRPJ1AsyZ5C;I25Fic!${|1;01SozaR5*x-~hw2gd<)L zM}WO zx0d0zwHQA-k0Uc}oyU>U%J)F#aVz21d0gvIIHl-zYZaX=m)$yyPL>GM38}V=aELF; zyR`@*u9OaqfOEjtDCwA2hc94}bfw>s>eMrHLa!qgE@$Ta_kly$_+SCF6pn~TAQL_z z+mRYl5*^{c(&z~5g-8nH7uX`PTk<)6g`c;h&*$G9YoYG6gq z(_cSV_<)8d)?{pDoog~SL_lr_4&mbNCL10gcN6kb2zs+m0bd~?Pk_i4ELlVVX*0Z^ zG?J*RS=ME&EA3~@>PZ)BteB348f(G;^avbTZvbS!_6i0E*{{w2T5{b)Bh&3Ea`;;E z+CX(JM!qK3Vq~yAMQ$eJlCAa>d6AhjpNJgEVx`SCi|8d(oc4bpsv+}#0OwuP*A1+sf_D1oYoUsSvB%ccn06OhZTxoQSPe1DY#W;#r2{T9Z2yDoLHrNk zS62x#%z%hF*CicExH7T*_cHaz(dX7q&W3A>{*+Tn9W)-UD{yNiaZX1?Ytd@xK3yn` z{VyXA#DHa1)Qp@xidGAFs~~-rb-(p5H>sQJlkb3!IP+FACsnZ4N?{vG z)&rQ)d7C~##@kX8_;6mj{;WP*=Zoq$lShrClSdQNq#M&YXg5w)Xe6Dw+ImVctH%5Lq&KIBUfiUV0i$ru$AL7Qz z`!o3xHLYI)wB)5tBpZfeMT*_vD+mBCS#*6EGj8mg#WQXk`7nDuySm2i3+LRa$hN+t zY_ff3s_TY{@i23ok(6oA+-4@ncPo2=hU@bX4S9U9Xf_}&(LmdQQ+iyZ{s{v5mJV4= zE*;(K8l0nvIEO1o=!0?7-b>4j44WjvKukgq?mPhQxJmAW1+@yv98%Sb z%?d~A1`jK;i(Hk>><&HzbY|k&zI-$r`~&>s-j3bDT@1(u>?^VX`wA8IdhiiKWHyof zp1z~-j2V9l4Upr=j)~y@S<|wxCN9mXQyjvyY4o=`js#ze(wdo6KV+YJ0?*oyF|&-e z(r3YV6|**GufRd*V(Rb_Cq6`FfO3r0hR`05poxwI6YiYWesTO0Nk}l0#OUToB3*7> z?PTd(-@b|yQq9y1bRQfsxlfEAFk_QcGC$a)9Rx_1bQOOke^d6OPR5bP2skklbA7i7 zXU<~st0~J0UEWbj%E7&;oa%|sfoSYG5e*6=+tnoq^hurteUycMqU7I&)yHC z>*Fm8E<%D^0fCs_#*djmzY}hqv*pvrry&D4$wAxS@`fJJSvaI-mEc&8{~-{~Ra|4B z*V^Ox??PHx?f@>s2*l+R+jkWD?8cx(`1@pp4`P-pcW@hv5I6&ozwZE%6WDRqBY{1c zYSDFPqp;N5!WLeX+a1`wl^o$1oRKSl^Bc=S4;%}Uh3H31Oyq;$g$-Zh`OrAW<&H8^ zPN0psRuw!8I39&_m)%fVvH`4eI0P@-x?}gw$RRVdIrZ_fwhQ&~^c+whFAG1cgkbtA z*2fcgV0}Dg2f7d5a|z#mwy)y6&wn?F#$rb;ei<11r?6wdG*N;n?j|^H=yfslH6vAi z5;_WK@J*XCeMImc0C9hTla=5OxOH`djBX#@F(C$tVcNKRFk9El1gvJcOh8ifiiET` zy;3JCNPuac<#WeRi1WJ?(V0pFC1*qEAY@tS z>xer)f+pkYGtq-M(DuUA%G2>~!6gIi}~gFJv{~FJf_<>N4;j+H-2>2HQ*UTWK%Fub$*yMiCm#-z(;>;}IOyb1 zMk+_dfzlii0>l9Ti$C-fibu!l)t#6f%#aA5!5DBs5(2^DAx3ckusQ^Y1Az4*KpX%Z z83M!sz=jYY4gih{0pb8)V+at(%WW~v3rQH=Dne5(m;K+c!l3KSSu0iKph~1t9vTOl zw1Eb?bu6&7w(w^JKmPxe6x7+~OlAKV2B%*Gl3(NCRoZ8v4BBM zso$d4l!}5CKE{&%rpZdMTifv4BrELJD4nbcn0um={IFZw=_DuY)^T)_2X^atI$3&K zNt*1zHer)IwkyH|X;XU7oK?X*+xIj@q9tgKsuZ1dO7?A%Wtw5ouBWI3g&@AV*|GIRv{`lXEBYr!2$yrbL zs5mq}fpFFMD#IH05ikfrG+b-!j{wTL##0eM`Ik8GFLH8#BT35NxwY-e?#7>)1Juen z!`p^eLMe{IyeOefr`Oa&(yk+A$!V-Y0xg9IDfIQkzzw|w26|1+G%jEQ$x`IkX|yAN zNb$joC+ftpu$?P^)9#hCHegB=G$v0Vu@1D;H@afhf%f3$jsoidrc;s509XgG4IBgX z(gOK!V(957GTb0lr8+rm0OYbg#a3=~*5tDGx!01pCYmvC8Al^;wO2G*k+<3_CQC(* zYS(DclcU--3P9%ip9Pn&cUE$paU7&Rou{c!5AHt8U1&OpS)YwOFt%-2q)`SZ^fe>5_8ze-~|HZu($^= z&?w?ra6uvEI=jcuDq;X;GfAD6DNlX~c+MEQ1}A%GAB|xa5K+-a`_W%7Mmb+AbLp^m zXSdjAsa6M;EwwpAN0+s*gs|R$xSjV8bYQ9#J8$ClWc?3=jv6i`q+sXlKY*rCRS$-N z|D@LmK7ttC4h$O8!LcO+8=kng!m9Ue7!?Zs0Reqb^NNCJCuALqX#P?!jqQl=CcC*^ zPN9NoKj2k$9Z@kc=gg3|%_lz!TvP$8BnAHnuS$zpIaP_6kcV_s7$z`klT*RR5EI&9 z-ZWqvobWjlog)tP@OZ^B!xz2$f0Ae%fhO;Uvp?$~Z(@XjESyW>-T>A6St#$bs=U`G zsIhZVY$&wj*g3?`8C5@YkwDRTlL7UrdjCyb^G*x({;%kocU7qO&szTj^?36^)}vj- zqG8raolg8(u;Js57ouqD=hekc2$0zyo_Cf8CcMO+0;(K*U~oVm-z&wXN~uj(K6QAh zUxM<6pVl$VqAo9)I$~!!nL6K>mqh(gwNs4x(@B9UVY)I?qEr;HI!K5@UlzI{644=L z3PK18>5#JQbScY?p=e;L}5uA}Fy;z<5?o3>J0c@V7tPvk%h(Z8gub@)pE zg5xx^icwgjk#unLkA;nGgWSUY2}{Y@)1&K)(sEtSv@?l45^SBl$ttm=75a6h^`PFX=|Sq>fs6`CRlt&HgEr_rH@u@~=On4=aUu z1bJ3Q5QgtV_^qhR9#_W(T+@I-0uBwis<^SC$&mqca|D=s2g=7i%G_?;DwsPOnX1tW zc<@mrD$PT9EY!k*^eHG zb(CLa9p1(~C>BGT=b2uuw=O%xcT%>oNk6?CnLhwRBXau^ePg@iZx;RYPskQuFE5ZK=USU-tp3!w?m%0JhMvu zb4e71n0Fy(ttZVH4>T3|5`h6m*fnR^C1uV!LYuGxat5vW5Lz%f7rgY&3<}6{7d83n zEV!yg_MDxr38d}7jD_Porhf74)2y9+PeywVy!?{r^-;f}ALinv=Xr-P_=`~mGlK_3{TBzn1hEpS=ZC=td1tT@ zDs)CXE4za=jz7G1G&a)agp2lmwzN4fQnRB}$PBcpk*Tz)lBu+*5-GQ-4Jo&&DN&su zRU)Y5_1oIV(S>8c$F`{up|+0?C-7=GEc9Tx>G_|hmuKMkh1}Ry4K$z+$305I%DL(w zrk)-eh9t2i(kGdT??L1pol!r4 zWAYdxU|ysvEw($iXd6=nl|K##x>F8`Pkfp5$Q7XI}0%XcgWsOOI*5t)e2#PD zgG2Gbd}0@h#C~|;n!NP^d~xNpvoDYpUZfz&5>#s8I zzheZaJc+A4UO(=A;wkEMU#2e`;EoPbO6IOuyH-QgzXF@pV2?fZF%afrzW;tAPjy1| zjRjbW65~E$+_c1nJt?h@`k`e*GI=CXXq!F zvDM@T(SYPtRy_OU_#XmH-{CDczX`@L@N4`=f%M^+|F;O#^YkADGv9;y?z0^KR;0J5 zoskQ&|QA6;KT|=Eg)-kgLY2=x4H;zJa!-CHUYQJO7pus;Tf{oym7#nG}J5kzHY-EHczn3#i}9Gm+LF^6_ad(A@_({oM07+{wsVjjkb`| z`UCzmX})Lrb>P{t;#FVR`}RQ>&#LaqZM2bn$<2<17WVy7#)JjWS>p2g;k38qXClOi zFk2+E4ZCr4M`!-m94I=(uQPh}tXc9`)R4z%aUpKftqEK47At9$xO;BBacgJXxgID6 zaa@P*0h4+t*Ia)8J$l*>%+cekTd$SEuoJCq!GbKT_@%50}Cb!89TUxj`a)dP7E2rV3KjXfvrAM zka_;$KyKcI7e+}CIZ@Fdsj{-X*FCff6Dxl;5=g)9TE9x0cYhr`rrY}8NVFkv%gra@ zaP@8PyxVecFG`;4Hphd}OYV>tuygLze#G4LK43wrpWrt_2{UfM>898Iq_rN(15oJYk#@3c;5_q0`hjDH(luCB4bjc=U zaCAdNpg*eQz}7BKFp<^>)Ap|s7Nya6(B*^d|3JWomm>F0Zl$KtY=tz0+`60?4b36D z_K%D!>M=q6pG1AKJ2(xs7oqN8|4JepR3^+om=T2kg&5mEP8LtcnVuczw^N8ae{RNN zgcBMLjzOdC!Nou zYCp$D_*_-X30Oy@*{YT^fUvM31I_`=ZearDZhw-6T{x|33t`zz`6J^0|EpSz)FJ!A zs(X4QZngVOKXnJ9h2gVR?KMQxS+&(m-9^*N*BzG6mZ+Rnjmv~WhD_7Z)Hb=Et22*F zz^>r|k%vd(K<-?tFFQyhxB08t> z(KPrll;9Nn@529I@fC;hhg1d*mj0I7beVkn(Lo9-9WTi zqNEWg8D$!VbjGbGgOk|PnJfb%>|w5emt2HsK)5i$bu1wx^p`-LELCtwVd}>y#cp~w{sXokQyTrCP>c8Y*sfp=`{N?aFfd3`<_wm0L|Ht58 zMF111AtMZ1BG=O+Ln~e;e|N%FnfOw9;!7vM^@20Lb^F(j|J9bE75{$f>lXj|v6Hr_ z3h+40qLOO6p>b+0ph`7RWBh06BG5kuO_t+h{hQl+7R01Ue&fVFQpMtijc?uG$I5VvIVtOmh)A^aigb)v%h_eCaHeV>t#ZYWD zUnI_taHe<~ovj`CZN5yLucGrTIxEdH1o8?(UP7llAJall>bB0~&-whhfIk=U=R*8U zzKe9d6fS#;zX2{Gdaa8YdP9C;}#cz47CXNpW!&N{*IOeCyzf)nYM5+>ha z;ki23+KE0SF5C2XyrJ9G8|YHoPU9g02BB0nYHz z3BlvVeF%STXE?noHn={(@LFd$y(&w1>zMC=3qi^teePvXX99XvOq@my2=xe@GG}hf zU}P9}Vz)4X8jQmI*eIsLR5lDlGjIl)sO*%3L?|y`NQ?*JDzmz9=o?8T~EaF5s+m0L; z7Y6_&Ljd9cK;#(PFe=ahu-jo$_Bs5r@cgpO{IaNmK^y?E9t9wdwT8kI(Bfcu%l1dn zS`_94*yGYBPDEspq!R}KtbYNBgLP}iZ+A;kE22|YY!y)7?eLE4% z6%ouU)3`D9Vkzrn$kF>bPRSu9D96ZE*AA`&wOZa9&cx&T$qp8U`%eCaaP^uDWhW}Q z6_K&!#^XJdOYVK`#PBUj^~qW8874CBbz!IiG;mg zhxVwrpAQ{Wa4wN}LYw}IjwraEBzJ(ROA#=(hbU_}i=?G{Jqf<-BD7!3Bofaxud_2S zNvo2ZUT=ra%m%=f8K&(rFWuw30(5;)_$fK)Hjq$go9z?(GVGn(weCdTwZ)q2a7L-9 zEl&o{(@Yd3WjnHh-6d&H2FQ{fg}f@lo8N(k4+(Gl^TC^8w4C5#IG}fu@=pB#(QBS? zdPta$y(<4aveB?JpO%RF8?&>}0gl+&J*{YiiEK1QKn}0=rsTf`wqrN+ z#<`3ax=WM|Y(DF)Azmbt5^SKqJwiW(nzHdd#Cn&?28+GO6I_KT!-uJ7Dga~{_tDt>Xb9Ao^hikU)RZ^Y>r{z^ zy#$V|L}*$`G<%Y0BqT(`kXkC`F`*NjgGBjM8lDvDH*I~zwk%v6M4M%MocbARGo^1( zDSas^5SlA`0mI|KWHX?3R3q#J*M%ZMbwJX>(j9G#icue7C6bcKk zBann(N0q~ogy6I>&&bw_Flj|(>AK={MFR0?x`HzXtSJ8q5y4#b7_KNv2?_BFSEeIY zd|E_wT9x3f5H%j5l|wAqdYI8GKp`zA@JZU-@JY&rsax3+j>gul&o@YAG6^FIDY<11 z^RZb$0(%f=8M=$^X^ODut~`x!8rPsZjVM~iP268Fjr=6cPtk>IJw1lJhWnBb>>#+c z*CZj2&l+d=rP?oS0=ba5=R!GrXflqVyf_JAw!>#AL}r?`keIDGn7q3l z>kZ1xC@k<6aZL>@k?#2{ELBu|IBchOj|)_4AEzqZ({x-9;n=xgWV{dH$+<~rkj)rm zPE)@Kp;N!XPwfgLzYl;ev+zPMaFKzs7mA=8PE}|GkQZq%T5<*f!4{;4V4Lt z>lj{aJR;=1I$@bw0)jSujm=F4;Y~RD0;jZXXfVtO9$;DIjiV?6e=vq)rR0s9u{ppA z18+E;_O`xOS}!w(wRiS!VK4AMkP>}>VELbLKPDApHB>1A)mA=Qx=(BNaCl*du} zydDziJVOn^>B1u0whrlf;xBq$+Qu#I|LnF4U~aG$5NRD#PSK?s@tXQg zBz9B3hI35&0X$tmQgF(Lf))xFhb4giB+GCSHx5AKJQKDLZkO;PY_HjU>Ctq+sd;|)CzlAetkq7A)jLWsTbhG^wA z#bnoFhTY|V38Etxgn=<4g#8-V6q_R&sZy$8o++v(JLLwiiYbxBQLQKBZ7O&R+R9Ml z7GwuRJYV?Nz{5Y(&F!OY>Uvm9R{I>d%M?;i|N$E-JTQ89}Mb(fnQo7t6*q+4-aZe@1`P+KaGe z13$1VP3NRIFQb$FnBBS@zkU@g(r za;BJ%X68&WBhAg3VosW!BhyCB&ygml89D(65Y5q%36*B)Offsn6K4XcOv3VXa#FvN ziL6SQ8`rI*Kmg)E<@4*{F~_%IA}pnJOok>elTDbz)I^9t9Kgt#m|zqK0Iv=K;sAiW zkr?6tKsdx@yEp(~`6Y%pz&n@g6#1L=j^~^f+@CL}MZHX)r_1x8Ck zI+Yy;Kss%oeYsJrkWSlYUu*!R)AlJH20%KM=>|YLmFWVYY^M2cis3Jj*ZOdq&gI~S z|8!kuJc>g@q#YqJts#e?V$LHNEim62H+NW;`Iw|PwMPiK-=$~foIc@svfu*~?{{#T)Qws|A4l$PzO9saw?I}}yt zx;5*g=FK9W+5TI=afS(V^O+khyYPmJVHl3O<;q8#r@nIF!yEJgtsI6;A94JQfV3P` zojMmR4R_-Y9kpfTn()s>@`9Jy0b?>|Gv`PQ;zRO`@$=h15sA1D=u|eoOc%xFD|DbE z{i*>p|Biz6j1BWe_XC8_1NyB}=G}B&jcjR|p9K2p0ACQ>6 zRvdGKfF%*YqT84Us_zzgBdy?`HV*$Y%zjo5OQB*mOT^jv9+vVx;zB;urL4mD<;bt- zP2_rDbF0VhaeCYy+SvRgqJ?$h`Jd86Oj9#yqAuhhQZgNc*upWMQZcm)_jSApb8dC? zhSBkSoHq-c$lFVYSqr_-Gw)B6>gQEXNkQJY*5^Sl_CUd#7i&>L=?*pZgX=geU+gXW zm19}s6Juu=Q!7vL>SyACvI)bK)8d#6TYAj+*qP9iNGx}@SPYX`iYms0Gm<7xK{N&~y(X+~p4Ips4j-Fz6L*i+$A#n-7oPc&!*0KI%cxVSPbjGFPSn$NWzu(U z9vw@CnW32VBJM1LCbV0e^sE=dFrMYC7d2-&tXYrmtx$GtpY0ZxW}?34^HNHlr{x|t z%QzzrgzSrmRZORMoe73eMkEr(5{$b;NO33B%C z3_Wimt*I$a^|M(P*SZVi^CuYJY?N=@Qa3#XGJJBRF8s_%*P#G!EH4}x-QPTBtG1*! zKl~F@D}}I{aH=;`&lqCEIveXY<~aA?Jc_f)C3nTk`S-^2Moo)EWva~e8+)$+;0~hD z039OCP>n@ZYa*t_I#mqDV^k7-EUl#PIuoigLq~0NZ87o;jgD2JSTI3PkBsd)({WE3 zT!RDC3fq0R#4tVx7h=SG7)v-cLmnG1WnLBbE*8$&^9CurcZ5K>sAVic%SfzaxJ<27X}`ohwdYO8f~;5Xo|_8L&`I9`sMvdkY zxgTLy+EQp(RZ#Rakw7l^-)6$KPUB^kwMP$IouKFw5Kzsyj)rqw*ydQAS71E)AOeQH zMqfYlNFBXI*n-MyN)>MmCmwu65hYe{m(y4e5BF(u<+V%IXYZ2jo^=?Dg6|>#Be=b5 zg2Q>^m?-k$MW=CGzRdsH*_ST zPZQmHn(Wi;z%;v8CQeSD7M7MP$qE8b&bkEnBQ(s@-EQ#*wNJO6` zYX7)mZ9}5|zWy1Byk$K&u6cxha(&U52sJcElD@R#e~(QM3&HEqS&BYQ8~|J&0>sg> zr)~g1md$EM%4>WEBtRWVxTF*ZQobbwh~te4sKIg+F;NS_EC!zK;!={=EguUNt1Ho1 znhdlhpC;oQCvoGcmbda#ZVKWLh3DxsiL235&1BSyMpZrTMd7W&ue@Iyu^iLc06L}HdpQU8sD1^be&)^G$F7#e+JObU$;3`Ub`V3jKUM32li?& zNF{vN?^-k8Yy1pI62R1LiXW(!AVncl+nz~c%XDB%_!Qe8fGq(GvB^4!I@pGAIOOrP z^ME`mrgrqCl5u=*AOuKNJB>mFkXm#a3kZM%@1%Ah(UZl3$^vQMigHv_-4YF4!)c4dBL|6zD)3N?DK}5 za@AfszB~B70-38b+@C1U;mF!8V^dfRoEyT_xV|AJanw45&=P4mSWUZn!C{K|By^*= zRZy4pYDyHvBj-K)m%s1|F{)fN+gshy; zp8pv#_B?DeBy2F?G{h`M7)stagex@5KvN7@3WvrRVEh2a7!p!7(-;HqZFHJl$f+>~ zw-cIIvkTh!hqf5hLPG&I|5U)RB34IT_3DnzSB5-@R*BC#_je!AR70^;ESI{CIfWuj zS%=O+NT3(mYADXnhVWTUHQ<&t?sl6fJ(UPy&tRCYXMPf2Pi(4Tt=&2rmG85o#4wA# zDP^5#>MxvD+=|YtbsK+f#*doQeFt3B(8GL7ZWyomrCRS~gm>}h7RC}&yf?u$^!{+Z z5O~N$P2Ng!C&&sqz;GMlqqC0C8}xlCf}D$hrq|PlH4opkaoRwm0SVdg#eF zWQ%S-)$68vog##2bkY6mv-0UpReKe30uNG-E;^w%)fvI5_6Q&fcev-5z~BOdK%yAf zUF?YAA%;Mr7@EaiLtIndf58mqEtJ#x_$I=rxzLu14RBZO3%5 z4OQ4`(}(jO<}q94OBAe3OoWq9Ik^dSFZg5(z}$dphcan(!JChFmlmvcVFb%5_omDF z>L3UDG>GChrU&CtMZ{$Xl}^RmTWcSK5Yu*bC^N;5(5|6GK9$vr62AGXiwWNX=Bhgm zY1yKM;ZxWfW0usB7A)*TT3;gFvB8*blm2fIshGjxnqtO4w2Ml)#$F6eIDp+Sm;gz30Wl!1L4B@fBSx!w;fs3()=li5XDoh8fDVaQuPIbigBzDe&aB(CY(=)rG z%-#)4swwtPxC-|p%C_450f%wmDp!P>HeJkCQh|khJ81KB@^14>=i0)_9ePq%nn6u+Oy{vXtV2pCZw?%^G3hKY@R~re>BQ(xAq}Sui(hB!4`H& z-R5ubW6tLM45Ej;K5?H6m9ndN45vBhPzHzz9ZDa+GBw!~{Mq;rDs*X8fu*p%7wnY%7a)%9T-VFF`uh;Ww&$(PHQx`H*Su3w==yR5X|ib3;ds@VA}=Y@ zlESUchsiW7M2XIu#3@$q4jNtYoVCBv{2?Bizp=M3bE+624X&BgxRAkCKk3Iv)NIv{ zAxt*`SQ(Q%v1}*F*gTh9uiu4vzilxe{@GJ3$-H&E0CXqtdG{fu@_K#i7@{ zFc^mtwH)jCtTcl(u@-dQa>Qqe5x*ccfrGh;_%T;;uSx=Je;w#`?!f+pV=XoGirAPc z_tzs_#YSuV7b-jGFRc57b|Rg(F5fs6ZGG}lvfZE-N^Z*~D{~!+I1fc(8kJIX)XzzB z$WI#O5q?QUV~=6By3SWOMoc=~Nmskdc?`g?wqh7@I4zvh+&TGTVrFi;Lk4Lj)vH&= z)_&ghH=*RK!ani{HW^IlhhF8-+?n0BjaZ{x{UqE)Y~ z=OAe>B+F2}>z#HD^~Q zoO{5Weta1+Sk5^$*SUUI&aLIp#JwY2{6a;r@is&-8ui&6lZT=(1!s65lMZ*)x$DBx zRF|cJ@bEmIcf3^rJ(;%c5j%Cx< zOs__Fq7N=pTCqrKMF8o>@bWVN`xn4OWJ1?PuZ*8;cYJ?htI1>98j9Fetj#0D#IDWX z0Ek@$I9ycuKj8EU_!eSJI~HH`ml%f$bprTv`RV{RySBguTcE+OA;x|Sfq-Gu&JF(* znu)Gw%g{V53@t^5XXv`ELsqLw0wc)@lz)sQ$7wsz3>sMAC_h#WZSE)x<;Uh5fMzb? z!;B8rC+M7Dko0O~JTw5J7lIeuWB-b@7uzSj-PJ>3CYkg?*}M#stpFQ%o>TE*RV6p< zdW9#Jvgbz}q5r#}-$~LxZzwaQX8^O-5u25M<})@UpCjUY4naPbolPzKU^<{@FFkW+ zdjD*h0)LqAmJ>t1O??n@B6}3#ctmcSx?{x@mW$&k7fipxpo!OHsO?ivrEm9z?)$Kg z7&^gjLC?!`WYE-}#tOJkA#-*kPmh?Or$;ow%P|6+C;16Qldx;6nR1r!Qd75Q@GDB( z3lN-~=|j@@QLvY=PmYzi^a|-Po(d)Ig;A=dc_Xk)g@^J`x=@Kr{pqP)mi1MUQ5&-vSaDT~B^_V4#8P%CtayA*a zbkex9lh)>ni+*|)T4irh*TSRpt`6U}z7!?6pL|x)xfqCtWuChW;uNxdNELlVvQ8#|?iz1aJTVYkn9bC@jFKc*Sk2v`6Rd%8y>n(; zqt>C9#I|QYi#mjM8}m%&?*zY~42VT)R{o2nYC--wJZuXVv`6%DYfCKYA_AuGxiNgX zYBKT1@Pyxw;N4wFXVkcM+CvIL))FUt%bq(868bnrZ#r1qZima0*zJcIPl&? zO0{VnAx#9O)ku2LZQO-caYixKxEtRk*KtpY8vCrs_b^aZG(U?A*iwz(+!WH~{#E5Fic!J{khV z0VV3)0Qj^bjq!lvFPg0Ug*w!aBixzXLpvi(q8M8L2xo8+4}m*P=4H1&hTkT0v0MK{ zr;zl!a78Lclr^Rkj3GA(=S6Y4C7BbP4|gyb=ERlkv?rifOG**MgT9Ly?tkwfoo zFh6r|gLx`nO(*R@5BoPJk5p~D0~H>1htP>s$~uE8j)U@r4B;sKtxo!Ik_{skv2{|Y?6s#)>Kl7_$#EA{Te0N33d~}{Td}3UCU+60A0%@zaXY#?SaYEEK{&K zcWlTsn(4KseB_z6r0LWIGUr|Y44wut7HeRlYskYZd&`@=+YqBqbCzv01*0m{n zTqRp?MKr^L1oZU^uA(<+Wf(a(=8+QqFzz zpywy}rk&s^dA=mua31qzl&*;z`k0@5g-#e3fb#)5?-l3Q z==_p6ze?vni}QXu@1fIaVlha&Znkxnq7HF8Q^c#tohc$#?9LQ1D|%;&s1?66MckT! zGezW@gR429Lnc1yp~V3JkqST@01$%!!~p=&2tXVFFmJJxCB-XC*6jUBheQ;I^m{jV zlxNzUYAt3bdOudU=QK`>0K!A3aS;I+lX9l0jW-e?XSal(PUCI>W_vEg@SyPphGUMK zSlr%8ukeLBNylm#8mG;;tdLTy{P(s+HC2`L_UhcQ(D23hQhhk(VIy@Pkl(c*(OY=_r$R;U%M|NAM7i*2eT~ z)72CE(s~;eYaVm_spMYvUS?f0j^Ld*3>5qZrKsVx4G9xaDWz03*TdQf&+x!5E}Q4O12DtR4Xm{{Ix-0iwtyVtJO<7&8X$>gFGm)l`Ae?4B%WveCxxp@9hg&PQ|6wxjndgH?G?ko|gt+bxQ|lxJ z+np?FfGK`%??OyEq~L(Elu}f1#s3)dMa6xTU(SzTWcuI;nd?uV*r1~DqQIX0M4Hf4 zMtLCoPf@)IbEV!AGoes*Ni>Gcc_35MDTP{ZI#;?5H2sUT8J1`hJ6%n6{jSOpm*W`f zCqO;AXqjNkRA-g#b2;DzKLy%&zVkEqlJkn^nD6{tqQ~={Ct!00IDJgJekgMvxVR&b zJ29O5OjxJ*)db^nR2<^nAHWzR!MkUIo)9Er`6yvhhub!y8XGP$Vwp zPq)+OO#O;tDO2YFZP~+Phg1I=gV2<{x(P*HEf4b&k z?=lO^G&mKC(w5wUzPo}Gg4o*`c{R3dv_4qyUmyk-Qk>Uq1FheV>ZG4s zeYmxwu&0ehFbeQn{OWi=jihG~FvI#e1dz#>A~|&4I7g!&!R5afnS^hPRUKqc< z!ptN>G}^Dm+DB<;SRJThpQ5T_bxc@O0>Z2kvEGdgby;{ET*-Z&xh!~NMEW*bwG2_> z0N^_zKpc150}+YS9Z9{)SJ+POu$><05zyWz@Wo0=zI-x|{yM+DMEtY;T=A$>OwrZ` zhZ>S*x4w(trV!PV?KXsqDrsi;HIc?fil^zF;2zMZ2rvjeK!Py{eU)EGBgdf=v|Yd+ z=d5~~av1|q30+5G0HW96Z!AZ+&Lo6N8GsUdXQ5(-Xq4|pF~fAqcQXKSkDmIt??_+A z(nEI4evT|&H8!55S3F+uOYnBc37{g);YHNobbP}wAFIk-@GC;_QtH1lBKxw#fqzeo zf2HX_r|%_6c9Cwy^n?G+x|JoBHtSxD#6Jv&u{VD?x{xOQi2xkF&+Ux^AkL350y_7m zH~@Hr0DQmCFNTmu@hu14kTm*!Aif?R21Fc&@k=PbKQ!MTneP+)61g}K;mHsn4gh`} z0>lBpPeOn=0Km|xIK;8Vo_ZXBAcut#ud^Wn{X_q3W1_8(_*roMdHZs!{rT;aSlH#n zWLx~>|57BHYuisV3I5PS`s-07yz9yHkxjBd?b%O$irXS&1)eYk3z{skJ()-3CJU`B zz&oL*bK#bO@F+7{P|4*cc_=m5N#NuaOiUKrlOCcrNwnSiDSm}FcI#(!k}H_$v*`9D z24=5Gj@tI*n@AS9YPWul-=^?F+T@qC2(*!VB#Yn#k1;M8j>Q2HDpp50tEe5Rr~p$b zlYw5GvM1jhWrKME-OL9lxtNiIp2`|0;96($(-ChRk%UPcRWKZKL?k8)5ufy~!{lot zHaJpmlj)Eds7e3Vz>4qWulPl|I7h?X2y>Rg^)~`tqT9}4QoEjg&LybAM4v;i5b7<> zuZ8qAMj7ea&Peo1#a4S~R5f%hOo4TC5-q)2|4_X!9Crtk;q8*rG zMAWc_2EhIkJMz1eUKM~?WK}2h%Sh&2e^XQ^(cuTyiS{F=11JBrLooodSDTIjke}Le z41f&O&dC7CG3{UsfGo20FuJZ&$On6hJTMDR@C10Wx?%P|1*LAx9SARn~Lxt7J3 zta$g$mh+g{kSw)chxY8Z@xwQUe+x1(oOQZ)78kI0Rcs*K# z?T>(qI0>>J=z_}uscnVH0C>v5X*|#Fv%Q6GY9&H9RT0LmZTiGR8;I-rryJ;*8$CS^|ZX3AVL@1d^skW*NvI{wN~=XaBJ(vL#7)wOh~>i=wO zbJxdRokJa44;B-j~vlwAe`Z1aBhzr*)@de7h}m(ER=r{VHHT&L6e~mV)@5V z602FtBE73LR4-a^{w!G6;>J4@DLBe(eHW}a{~oEJ3#LShY7y%PabJfrn68Pt(ExL> zH!m|JC3BvUOel>dVn*VGV)xX6#cp0CcA7Y=iH$%pafd*qX|WZD#azesDgn&bnP$mZ zst3kNyJg#yJ;8MCj41Y?#s-^yhXP07`2y}p$tkdQu*f8Mqau!KB)#cpkdG++0z(8@ zhUnlnIyAhOXIR$(l0X^?j=7hu9uhT%QVOx5*&LQxl6!{NuG^g5P865(O?+ z4hMU{R?{XQx0e4`*bWD~mTwN*;e31bi8dw^Y`44Y)i&+YWL~b*i&ReFRdKm$x-Qieh7x(SfS5XXAmgC! z!<=ay{`!y)`>eyisqW1-Znto_myV2ci=mw{fHUe59|XVCkuzhb`=S z0Z~Ox9zxOPCFLZ^q%u&Jb&$g4M54?o$~^2qMJV(2d=@wByAf4JPNFO)B}Pl7MeH|a zEGn?a^w8KpXHRZKqz)+(e>?!JMQqJt{+*8RUjApI;L3R9|&>3LIt$aSPD0Ccg5bvk;4 zQg_{lnFUmc_JeNUK=AMA2}?NGu5*#Pwec;X+<(~G_|wq+=C0!&3j4rcb{$vMevfOs z520Up7vvvT;V*zR<~YE#N4)yDe!cPfxI3OlC|`sb9)LrHHt$H~32PkboYL#N6R>JI zEfF>p9rK>an2CD|JCh%vAE^z8SQmKVwG%v3T8TVQkF3rWUB!OZP%3n&zWuGB`_ZUB zLn}xHT62;?5RDbQ`4W2}2hx(M&@V@!!M& zzkWYUteF2l4rv2ff5Gf!CO+kbi8pD@QqZu@pA2zLekNX+`OXEtHo4#%Gvq*P`u7ADsZ6beiD+{sLJ{GMlKY;w= z_BP8rKGD$TMGZ~kc{=4bZH-gzx!c;jsI6(*w5B!9jcGfY8_im9UvC26llXQ0Q&1lC zhcX{pVJ$yCY=h@p%db{9*UGp4KUyC238n;LKQen6s6)LFW#FG#PnktjyteYGt}s=l zZZ5fS>4)kKfgA1x9{~Jp*f@_87~M7##baLc37@;npPf=ty?Xkfn0V7miq_4qgr9 zQ`lPbzfX#`Lhg#Zy)9mxt)_||EiA=Xiyjf0HAYdrh(VQpK3!X3%+;un7jfCeWJFOm zyodc_Y&zrb-(ClkztVR>=VtvhqT8@AUQ^Fm!CJa7epEr=(wv;tso5yVx$ayDBu=NA zsVEDrAl#BZQm1g9DVOG83gwu6UkJ#6Kv0NY;E`&0|K%8|FNz(OtF?BjD zI8Eoyd-ULvq>^e_`$fts&lR14?9&IO zZ6vcoGrbZ1y@H=R4gVMTSyHn@5z`;y_pC42mIXaPDK&6L(VcguYEd@b1*p;33>4;d zm$BA&bv1*9iBAJjn4!?5)q@bQ+Cl{t-BW^7Fsr~R{ZqO#!HW?@<=Ub(i)??XBw>m_ zVnD*}S_Pd^8M3GFc8oi93ubCqB#QfHxIKMV2>OHan!v!(m%6o!`nrs&>1CXvsvhda z;8`7~_^!uyj1$7q9VUc#qwJ{@sfKzI!zJdKCK^6BAhuYx>Fd&i(|FR)21zi4Ox$v5 zqI!u|5pEW+G4*39B-7A-SUO=w)`nyIx?n^XH?~r85v!DggA;4PTyhtznHQnQt43L{ zxs*AxG9+nWvdUQ4O3LVUz`zobfPD2rl~%lD#rBSAenAQ7F6nA&!)6i?=H7k4+zZS- zueo>QoupD8_Pz2YXw5`3z{a-rEs1qlKW@+hA-RFiOAw5YEF_9i@o)#%aF4ahE?;Vu z&0Y!Zz`^<`70IjvqG3k?G$nWbntt2q>%r~NepFu#*H?M~&(vTqDSKur19w^Wayf_n zIpkP&;h@-*`2}=|yjMDalssszGdK)<0^t1Kv%cwC)-RB5AU7``wt-l~s0EXQ(+;0i z6(iY2pwo6D0mgujw_^0#PhPS3ALkv{uZI?&-u0)^{vNq;C_m%T>1ok{(!gb$Fx8GO4Fu1!Nv$mn>?I_)9d*9x1Bjah=!u?9ZxJx>r@v8Ll62FR z;?6m!g2fOW?SP4pjeTJ{<)(-V4X3 zPokJOWHwM*(zmp4S>GXg3#_!PbjXH6X<7gB(jooJO3V8X0dqzq-h$E+s0jMS?qdH6 zm{D9&S~xa>)vTrN`mty}7A|)!8^KzLjzczV+xVR@8zwJ?$qz;7p-ld9jR|-CSkCx? zYS{?1-Ex`!nWULaI+HeC z(tXGzUD7s9*Q6_@AQW0klCqYz5Sn&Mk^&`77#0PzfFdFwYZ0gjih`(Y0xBSzD2q#_ zf>5A>P*iq=_xnBfKF>UprV9Rl|M&C0pU*Gtoaf$iw{y31w{y?U+u5$Bu0|@6X-5M_ zr#2(Ah}FWtB%%eW$z>+X#bsm4N=%lE<3%m;idJl29l+t){F-1q0mlToG$prZjQChI zBaZV5ZwHoYvK9oEc9Fj9FEAEnj}vyn?LzK_pbf4|jK!|b*!Wny+(CBlv`(d8X@MV1 z4SGsPl9gonAZE)n?_^$Iw`3h=oS399!sCZpZFic&2JV$hfE z@9ZKnra)!}cr(V!D4#&--hi?_G?)d~4vxj#DEkWLEHxE+V*^`8c&`_4a~_&X_@93X zkt5^*2w8hCmQR6Ck^?=*XWVqqtS^|Eim{i%`M3xe>PA!WW4dRe#vx^>4ENyDW#smV zJS35SiIE#2{Ra_wfsnqJ{17(YLPCCVNg$%hkMtpbAU87uSs|ap2vgWO4#9+WZoEO{ zK2LjzA5$X^4JfH3MkK8H*rill?ceOI`8w6SA35fy)Pi!o2gdzyoS9MANIW0|)1l`4 zmt#Pzf$bbiSQZ7B%BKZ|iFsaL!cu@kZ+m@9e@>htv`?8+;6#RjP#me->qqtH!~wW{ zN;t4oFZ8uy6iHa*@*7XZ5&%R=BR&RZ6bDw(Wo}iXrp6(PjHszQX zm~fwzS<%9V6r*~gW2@FPh&TsD5dT7L;J7jrG*~wkARgrI6a@{yG+y0PD8XhVLLmC zW=Y-7;!=1}CvRt`(k$uQ*&3L&Qcp?S&Q2g=Xg?GfC+ft_{t-M-h@qg+eh9((8K=M9 z|0H#kGZO=3!Wgq4!~lfQk1um44q^b}9U|5uC=EDJ;74DZonj(?&j}(11bNp%hyjRy z5YcPdE;F8(S0J46**)S8A?av}@-u$*zFUU<>WywLfiMo%IbPu+T6G249s9fwO9Igj zH}WFDmkYzws_WYBIE?L7?v0T!1h}6GR$ytJ7oxg>)}9Zw`^$8%FL3XoRaynY-wbz& za9t0J1ekr^|Ci$CKF-CSGWY-uN%tkUldud-TO0_EqBCuEGlxe0hq=@hZ4k_st_ySF zjM=ifnTM^+jq%3J==NX`q+VC5++4!|DQ_=fT-*)b>{U(3nWuE6sl&Z!BWa-2)UexA za4lVX>Bh{(pPq}hG}e-P2D;F?Zw0#6hZQdAqbd&*d9HE6jTTtHKK2qeu;3d&*x56Y zdXYUiy9r-W7!nJ^7o~~wp)o^fhK&a``51^yW`BZU6&GO3*;j0IYdAihc>M9%W_n?z z*;CiFkE*C$u>7MDk)~GNrgLlYsM1u#u&(vN@7dG;7*rx7RTfpFIZQgi#CYNCcp( zwZE#7>ZJOXy(>sN2^66B9t!C#AYLw<^Ja=%r4hwBm<3652^?*SXGnGe%OZUhtC%LJeE;NnxXWSpjwZ3Zb4tsy6MrX@vs7?68JbtqY0WCz|J5? z21$D*_I#Sa*oB6oP(}82gbJB@fHd|zNea<$rW3@M(;BUeqk62-5RMrw?}q*XH2f7b zxT~M2WBRnn@?8JalR!?ZV&P5LoU>}ig}eAIhMt=9LCX~LEeb}m=fYkOJHHe$9&hyF%xuW|FnVrpZR%zMnYh1;2Hswj(Q;jIT}y~yB`ah;G~7!)a(qN!N#rg} ztqR@*MNymcgb`}N8fQM4Q%fGzW}YWt{-f~9cRV0ms>w7L_E>hE`Xx^LVYNG0wnn#- zT312|Q30aB5^B|F!BDMM=u4jvJ2*K)MrGyuD`Lr8TAXk!Cgx7cPL4$H}cgLG;`CJRBfrA zi}M}q15qgaLyc6;&2j1k6Q*FCDW!6s0H(1lism?ds>mt6jzB%=IUh{rISVkAvjKH@ zPMvsu>Q`G3=NqUKD5&Ihga90}Zy;b@QO8LbusZ(+Gn8}^Z)e|x1!AREcaYZfa^$** z){tw(^JrE#z`>uzEIwLP9t+jrl)pUt4s5Z^SnP;n%ko{Z3<}jIJFZ5%@pn84 zC@;%&u7uO+;hJ!`_dS><#~j9YMsa3ASYm!^CX$lL-Q=?H4YbH*#P{L7I8$Z(9O3#2 zk-*|iD4fR33_Z-r&ymQ_n|tTSD#z8DdF=K5 z5iHi|AYL{6veo@KCQoiI$76Sph-!B|sp+-UM9@17^ro=OzmxN=!0>1kQlw&m^3Gst zfmiK<-&1oH~2DibVKva;>G|9ct=)C}V1eOp? z>cTc>zwZTTF?|G>%q$Z!2_?G^1L1}*xCBR6dUsuQXy>{c1GczV+ozznJ_$@s1(Nl| zIl9TDnFQVw+vp}ItzR=#FAn4Itu1%*vZqmQ4nlqh9Zm94vtR!DAWD&O>6BW6E2&vA zN`(i!k(W8fBxRfp{dg0z_wR6C>6Qnzx=MiY2tY$yySc7NiwTCgv|GT2D69J^xZ_f* z4rM%!Zd%#%DDYM{p_^#_ekMYTd$Q+Qc;NcWQVWnh{`K=NHX;(5TB*jD6~|E^s5~kg*)-hj#at{z)$_CMXNV~5Iv*`OJP!C^$sG2G+4cZX=LhFZzZ6= zw;WKv>%kN)e{T|>-W0L&jt2?DT1ZmY{2O;CVi$E{71VD@;LB~@FpuamX2ClD{` z+SxXk_0t~`Idn@A@qPLr4R&@tjC?Ij4A~Ent4*><6(SsBz^SR}j-2{rer1e)8k7xV zUzf7*=waavqiVjP)ri;(v07qeHlH1V2^R+kS&iwenD;UpX;Eoloj5(1ABfg1u*>Uys!k$$^MN)XeShrRkV;l^99d9PVS3 zXmV$9CmLoUxkoS9K>=GqO~|g06_X~2S_MPd`#}{{l;fW6X~=fWO0$WFMLhysXG53` z`t3k+I21{r0;iqPyxP&7QLhSwPz~f8(ipq`gq(4Iz}bhsSPi(&(S6XXCfw?nyVSy; zI`@-8>MTpCJyH*B4F1-2B7uo@c@YIDbB)bL6RK_-!;8ibHm2xgoDZ_S)!@tiiyPn- z_;C8Uu!x0(AGD6Cui$qVek^IsAQU!jRTqBS@cS`-kK@KqzB`r;SmM`l}Z68U*k#4+CgKqIkd*>Nn5mwPP5@uZ-h>YOwdid!24o{Xoz%t z44NCJIf!srhsYvdl9lipjcEYOaA}sv3Vmv#!g)F&L;LvxL`<3}rF~OzVLsA=0(Xj5 zszT>gGLktK7)@@Tw9J7{;cFM|6Vnp5iaZl8mi0atS2(>BD4_Eb6b-ZnW0&ny783XZ z`{O~jQnx87_!}NzNP7;KVk%iQjdf3c#Xm>WdatSP~ z3VL}^!e9?jD>X(phNJ;IInHZKq=P301Z70S8*9}3mMC@J`iX-|p2UlsQKAgCVXh6& z)`^}?NP8!=VIVLE!5t^~W!W##kb>b58Y+^BK@Gn|OY_TB-qd6qVFu!Z%EEX*FQSh* zGc$0cI>>Vh9S&^zE^=H`md7892oe#TJG(xQ7EC;^f`4WUQi(_03HeN%mEo*69Y>YU zm@RJFJW1nAi65i!Vjd)TGkH^LVklldBS73hyv-MJ@$=CpaIvtq3@62@1uxSQj#tdv zK?CkR_>pUzs_Vy%+KS={7p0$IYm0>l*D|HP4a%&2ZCZa++{h=;Js@uA*lT*7Ez zOQkJXO+`;d-PD%pCeV!z#2!mbnGi)<{Y_`CzTe4-LZmk{fZSH=fx zRvwF2LYcL>K)4fV*an*$i`pwL7l_yRARHYJLdJ^p8CmanJf;VPx!8z6gH?|KKvG;mp2F2*O8gH28u0yVA3XLh)CAx#?(lI zvuCvd_-P(I_gAnnDSsnHWh!TzFkyd%GfAy1bs$XTIZh;#InE@LISwVs9Ot2_9H*eE z9A}@}_Yjyci%Z+6EU*pP1H^hwVX=XE9I-ZAgn0)b024M=I?qNQOn0E$L!WsNIOiRJ zp@={i7~|4+cnjVE=tV$I8n^JSgAfA{;~az-fJi$CF`%fqP>{886UyixC}(-~0$n8opLRBaJa<7F z!zv0|Sdyb*_|soU$;b;Gf~s~=5XAd#__`MCk zO8l1K*YHCCJG+&|ZfC!YPYkEh+|4l7VhC{4s^d@QNfXcR-bah^j{W+;zw;l&&N!oM zi3Z)en(FQ^pMh9N%HD|)i*+*GFC?ihgXAWgF0&%$97TI6-O;=*Si3(RyX6ohjHK|QBd9$+vo-1!NU1YkMNs8_*Nr% z9fKx=b{&VIBcJnnM2(z-i#R!lb_;LLY3(7vW*-|AtV@!^%_&GSMkd{21H){ zUFI=aHw|6*I=D<2Z*?;!(}d4OM)^b$Bg|d__b4okRxEf|#I47C6DSJiwLzA5Vr-Mf z%}90QMuqDXq{3ZWF{>XtO5*0vme6V*){!_w(jbG_ygF>L_JbZZec+nKkQ&slP}I2I zTty7@W@S;aK{*jciF89DCG@0 zSR{wyw7}9&5H`~Oy4dCV8Rjn>0;kNEr}eDvWpENn=R8t2L!EaCe`-pVT30^fdwY7J zU;XdjB|HL^>b^?|YMz5#p5CLF?PqzH(7pHIyi4dJ`h9zE9~-<6Fk8{V^465zaK*-} zmHs8s+>bp4%mm{*E{t;zG9bI1EruKKX`E6Y&>NwtfOax2&gN@1&J3nB$!BSRqw3UbfClsi=rj}R-w+A@wzn>}fZn%G2KwE7HpNHR zf^yRP$e(+ca}gT5OgF@UPCK6nj_;GuU*0GGMHeNq2HWuq@wG3ZK9y4RJ*ZXho(l{< z^YH0}&=wSZ=rPJx*wRxU^dG*==NF~3Jvy{s6wdZA4l5W+LnxC|GD);HWTne!$K?Sy zbEpt2;^sKUv_3={W$KfG7opyv-^&v*ES$cWh|>wiqr+A09Zu8I$2XGut?A9r@OvR% z9YrkA{KOK$heTn=lH~%Mlp)LRWWd@58KXpNOWAYRR18`%DTHMzCGBcMgYY3%4W#l4Xq0^W)o4qpk4Tq}4Xb2Q zeqoy~)d_fWQHu8hoFDm|Oi30~LXa)5rs~!D09>)=!EYO~$G229wiIuQHxpYFOiuEL zk`s$MCV~NX4g^i72Sc)Ok0pyU!*CfTQ;KKe{YhEHab?eQ_)y*JkyJBY@~PXY)qg;* z%mwJD`cVlxAQnrCg->;f0SX5AfKi?Z-164D4tUSVgDxv8Gy4m;kr8ev0iUw4_+@b= zB09CQh%{($oX$P8l1JA-=bvWwek(k zx(weWBz^}3@pwsS z0$wJ^+w~F(Sw0p~m7vhDPr+c#lOBr~!;1SPjIMdo?eSP`TGDaW$TleIm235rWU1j3jY6DLHBMG#^Dg0Tof3_u78oNtKX6l1_g zr)S6!O3)uD+s63_|1{ZsCO+r56CcSup3ZX-QUrF#6)r-j(6P-$2nmt~_O9g5?CCqo z6B)ZDxiowFj9ur_AQ-#Or9m)uol8B%x)Bo)h(NG@w29TDO{^VlV&#x+nl)iS{Q%V5 zDLh~qoRW11TiwgWu+Zv0Obj^xBnC4bK)fs)#fph8d{mYwyFJ(r{!CQ+$~L?co1uH)Vj~Qx|lDQ_xT~D+N6XrxyhU zjaM8dSRuE#u{NhaoO7db(^P%4HL!;Ud>AJ_5?(47?VO}yrADIk`Dr_7;orXvCUoin z1?5_)W3eS`9xNlp;KO8f+P2WH39yAcAq}*4zR5n!@p&=Qma+(FvUOpm!Fe+%7Lw~1 z3r33x#leA-{kR?)zy|NyXefziXxBofMkf}MbYysI!f>GXZsyX2{@(d_rWYN`Jlm>E za*RA<^~0e9n#?f?Fw7h`{l-vvEsx-{7s9pY4VWBtwi*LL5H6MrLP60DLUF=X7%Cr+ zgsMm5V7Tjq{fu?iz%zPrym;Rg*`rmSWxuP#F>jt&lpvF{K{id@58HiqfHM7A225PPjUT& zfebtr`Bwj8-UVrAE8wKx8y*A`&lzy@67LNoKR9O?44iY$FdPy5+jEA9p^AEOk(Klr zh=Y2LWsVX@x}P9j=%_gn32?#8G-TWoldb(tH2$nK)g;%B#rli!q*~HBe4=@4B}l_! zrX7(5@iH;T))9qaQ&!RhN@Ha4dR}W{hoUZT?1%=_idN1QIA<0E5X}xk3_!FH(Q4Ng zb=-#eXXlY`2@0t&^CDB{n+_#xR706NG{Q>BCGQ5UC1v>IJOli~ z+>4RNx5r}Jv;ntXvdh>PnSCJU@v;wgF+I{qU9{@V+8v*uc%H(>zV~hqtvcU&&Tz0! zQqlx_GHJSZahRsAK_kt>G<6Lc1QXGfzLjz3WqhIv2SU`X1U}J*KJL%H2oB91S6;2) z(|8ZppXjmeKZSDXi(R*aJhuI(%)!P73d+Xl&)l1E#*2Aw1G@AuH)C4a2VjJ%5H`W= zyC`+E@2H{-tI#8ygM#Y?Z=VTyI&U_@e%55D|D_b9WqsrpiHQ+;EAmq}-?q-Tj`;JC z&nHP(q~WX|F&Fjwh%WB)gpwDfSjQ|?{qSBS<=|MF23HaCTwpP{K@QI2Z*XX@=W`>K z4$k9mNNBIeb0b3?oX4Me1n{AbZ5UB=YXuKIo>`)o4DPMgfJ!zOd=yJRJ+ z_$4b50}#hM2r&S$+Chi`h&2vE3_z@P5MsdVyED;)(i7O}C=0pTY5)2(#GG{0+BSB2 zPe9O~3(%ab-VHP|4Xbw@jU>qGZKsi>SiL6#_O=n61fV4$NrKh89DZEQosca#)WVPwzb!e`34p8AF=OB=5Ty~`$^CPrpx3wHD}9b* zDCJl_2y6na$HPW$pw$r4F&6IG3i2JvH5d^QA{Hrm|2MZ1Nnvn!aUG`c9n0Nlq%c4e z*DM>|^6;lUXFw(9rB2eOYk4b4GCYSA>DFPS5J{149cE)gizPC76NIVj#vnn^PXp>i zrtRZcE<%FGxMF)-Q6;X}o{@{;d$SxTrlDXnwN`pGzO}`;(1fp+J#>74X9hD6?i24b zU~vTVcwWW%gO6$I^QtLU`a57lm6G zI(;t1xY4|n#kjGt2uDgZV&L{ijUZ8x5ig2qHBaskCL52%L04qSkIm19hq0p8(ond# zbP4EztW;2T!re`jnODINkVhkpJn}q^JPJrH`9q;P<4YsfdVGis5N>$6J_NA<2(5Kh zM4f5|I!T+xqUPgZKpAD=`!lEXA#}JtP_as9)W`zix}12CM}-q1t;^ZtMvAptI3D)i z@#F=x1>EB*L>~g)I`0aiakYV4#aj0?CMwZ-=w>a%K&4KBFP^+jDey%M1<+V=wbLw* z#1W3lAygDh-_Kfz*zpKNpP(NoqT5AfJOYuQh$Hd?B|>?}I4*Ng9@G2O@i;9*g!T=| zyEKUXQ}tYoGH5#LdDa8IxQbLD@6!a_OTdkSrx?uqqpTieUXiveL8BPp0EQT7@g-{E&Fzf3;eyGlOBBtOg5{ ze1Dt16y8kJP6Se&LolIbBMl|P6)ngcBh8xk8&4?&H9Z}R|jR)6FdRxNC zG|CO(L{S;G`OAvrD8Xo4EpjjBsrq{Tc+FTFVqnNKE~!R98HyD$(9+B#7IDJ1sp|;Q zFi*>X?rpRpTrp&8#)qvpyBd_kTM%u*Jfo(Iy(Y~jCu}GYv*R(RNFk0G-I^2gq`gUm(W~1*CPi4hfU_VzWvA3 zuBnuDMh0+y^CqNKGa@V+i~Is7C&HAtz=bKo$$_vRizlPUf~qO%9+dl{Md~XMaDj~B zUVO3&YAwzv7MSphfKwup;wcRd2!n|tM@%#3G`eELP)A>Vd1~L@#=aQzYNdBquBBH)*0g$K~XU! zM{8%J2Z~_|FdPzUGr)*pWPCsk6dI30+mOFW(9Tmc&hyy()WPv+ZIM5_6MYoRXR36H zrV`19Q_ut326k#XfX}@?mirt?iWyyGS#&6KW{bfhxvIC=H8dHfVh9 zP=iJrCLT77C61>9w5QbMO6@D61Je?A{EX3l22Cz4j41 z&66c)m#l#vvJUf*MPDvi1M_5!_mJg{DKk(z44w@7^8R;LVpZOMq3^_8ArT1`hZC4g zMf-~J-a;KvF-SOvpdd{T!7lF{g#PvwHpCiN_5p8zej~QNZE`mkkycSIFVW4`t$0z~IOZ z$>93(x7o<2m%r80uKC+Y7{SLHV)%kxrSz1wkX@zzf5on5?ZvKAm`dD;{@aIJr7(6A z9Ru^3;xeClm-$S|GatUW+=u!6ip*zZ?$XPafcfzID4CB&fca=lRY)T$WA?dPi}gd{uqx0-kb3dy))%yJZ^#a zVLBd4$co0=LG`_cur7l zLp&ky9M7y2+kGXWl5iTsB!s(ENu(qy=2)oqG%R%YM=ysfKlPJJ^kly-f?Yk%hB6@- zI9)9+375cIOQa;!(uycTEh{0~lY!97NRlZ5$S)*-uoEnz#b4ZyV675(C1ij~(OgQy z;o2=F5uLPte7AmbiN49SchZRf1D8Zw;(?L~VnVb`JeZkOf-TJc6AvVzV`%F!Cy@pIYI%w35HN*_B;g{?47WLNN%54GlR6#U`#OjgxYD3-AN%oXU)3^?fZHV zxEo(*{Df8hAkL}yLsOTw&$kXvfIW;hE;?b8%l)!8fO;EQ>f$=qUQ68u;DXcZ0Fy-{ z8Lj)0i)}Q-MzGn;t;LG*b_M2yLAmSGnraq>O^0Is&~Oik3&x`|sB!x$IOE&E*zV=7 zh#%`m=#RnUE?Kya%?xvV>#29pwQ`RHdlC6L_e{JKi+XhD;4`7A8PX|QBP{O0$-LOF zFIYvLkp}Kq3X0C*Lido2M8)Wrqq~09h&^!Lb)@m1Fbej7*}EO=0ke0)XcqcVd=YV) z(1^g&knCxP(>R`pI<`pqP}mx-VIZk_C&Zx1jgFtf5Li4g2-kr9d(cs44$<+Y#v2j_ zPoC}g$15s()9{}n#I!Gx2+&tN3N8$l(7I9^r(yFYMD4&%^!TP)B(EoP6aP#ChSQom zi}dzqNkF!oq9xo}G|oLAlPmSD;|PbKKbQ5+qOyRgX#-@|N`O1sl@;54=*7*0mq4a4ep^%X-N z{b&;pcFJ=+*-7Sjw3E#70EnEtF~{?tWR3?s6*-;|@yu!?zdW-N0}v-W2r+y~uJy~& z^1;}kuzEY;+(Rdb*-4OAtM?nI!`=?y^cliJ&{_SQ2R#a@%U@rE_t|j?brw#e4`n)b zb}nL(6kwiDv(SShqa}s$EqWBoc@&9H{71A&KWN40pI2 z&b`FLaJo>;$qd8kLeU2?$cLPZfX79-UQK@iBN#L|V0^)_sx7;?>M=*YBURIohvq|~ zpDM?A=E;-f{pWH68wfTuIa;32%|s7k|GC^{#4(Ew!Z@DrA{YmUS@_7u@!dki{&TMY zLgxn8i(_Di z`7LbSA=`vCaq7!CSob{#SF8IwkY9m@;-7IZ9ir+i`02k#0YZTv;x|uV$AjS(*r2*W za57~aEOUuOgx;D!0932%E{k0?4sVWCLdcjIH#!a(oAIL0kK<9}u8)a5?gkNEV?5~d zVJGVR_@?vG&3(#FEH9#oBJ6DA1Y;!n{?0M+BFrg^^t!80zVi9O?nxNl!j89)tJ6cj zyYr4O=CfovhZ`NfPtw}Fh`FDeW5-J6*za%)wPP#VV|po@KF%Zixy!W){=9d&PNDsE zR0IU60lQyDHW2R}^ZL8X^>aaz9i*MRT+2*vJCt9MJ(`0ZNv}F#ULN+R8(pjs#^`gG ziwh&Y(9-8lT=%$lxj+qD3xu_kbANrQrT=!pP z2yq|j(RaIAs-^g=hiRYH^{E_-CY57>knx?$?+RSpq`^v0NBX!iBG^+3vB=#T0%H}ZV`A>euc`0~7Km}M~FfI`gOl0lDegqSQHy9CCSV~6M zMB_2ozjrD_%hbR1Z}SwuOD~c^KxPoP2b3JR{J)%wK;O(Ct1}O>P-X#SUJ%~Q6H%D? z`QFU)J^}YiX0eayYKO=k@3FC!=*Gl4$3?3`KY`9sUQhe*GrG`EKn>n29>_%U0ff(!tanZPZG$^%rL*VFtz4kN3Kd zLz!$k0*$+-LR&=hqMb@(M32_`gRz~%`QQ=)NdI^U{R6M4Rk{6RV71)w(|seN=IrnE z4O`7cy2b2so3QS)kaz>43}y+(V;zMv!AdKXoAwwo>^{T#Mf;MWxdt-~p?SEWd5oOJK{ACI5OcG1bfLqP+G9e$ zU+Q4r@sQ0p@zAUpPeDBS;y`)$si#BXt{moiB&lLTQO6Y+gtab98$zc-5~G?LOh!|& z%w`*Mrt}IaR@ZG>xe4B48bzulmN|sYQ~Ttdz~SLwbHz%$9;#c2Y=+ePL(z;Cipixw zIRl*#41?N-o zn02^mB~%Xnr^1+oOHfYc@^nngUxKRsAI`i(I%@*YdwDXC*Xd2UFq3!>$he6u8mz6R zPGej=%;&EKvgLRW7%%#Gap6oAUOD$vDg-=SyF?ZaJ6Xn&GuD0uk@BG`teguX#j{n2 z6pv@+iwI&Ju3aL<<;Fx=Jd#L^>MsA@{x6<>PGh3H0T+v%F?LU5yxgHv%&qRI3Wrwn zjuZA|n&Rb!PKEx8-MqqIU#}1v!1GQ-Ltr2fk72!w?D<=8A17XnUl3v_0oYpNC1M+Z zw`ZUci5^*yVb>$>eWC;$kI^_i;!ND0R&K}3TJUsDS<6a1U6W{OjVGF`PN{O2@;UEe8zRmr&u8zeEY*GWRl5B*eU;(D~s0xxi4EgHXM77so`*Fdp}ZTk#YhU;V;P4GeMr%0#&HNEA&1q7CQ{?O3}85=FT6 zoEe3FfDLLq(1iEPWge5|+5ng+->!>c;}wq~`Rjfkr*1i}?Ogf#bO)9`R`2OpsPuGj zDc5@@jh$lbrtxGkZhH~&&n{TFhS=QbC=37W2qeTl*%zX$sBW%%rO&MD4PW$>((ahz4W;pc`hl(gCqFT25+ocS>CaJ+canU$O8HrCP7brv*!jRyeI}XFO}4)FSZDj&p+E`b zw6ec?|32D$&Cqx$oa}7STJ{t57#e_j(O?{7E>CtMo8c}E3T1vB?A{I zqRm17@JRFU$WfO!SCV4?5Mm6BLR=*iU!CU@u;&1d?{~B(2eb$b;Wvwt-r{q@c)Jd9( zJfg}nW`tv%JJ!)nTI==FzA;c$H8bMY<4Osa8CQUY0%+>4W{j@KR*6x2(@q`^g4^X! zG9P_3UgMzy6AD5y+SL;$RGey}wQiKrdE#~a`3rK=){I|Cr@*gN3~uX0rRua_Y2zF} zEzwyf`z>*Ya#{jQ#A9b5^kOq;Y%rk zSO|t@AiyxOSK3@0F0f-Jo7vw4$vdDmNko)eU_{)VlZaNh5w%D}c{>J5L;qN$q?$_n zt(ax&BBr#oHg=zjir4S77>w=rX$|3j=&5G9qR)xtNS)44lxvpMI}P!HEn~{GE|W1mc35LuNI-gE54yH zPUAxQVbE|$-UY2WD9}-XwmA3#$h-Kc92QcW`UVx=$&E)GV?{j5{dKUNW(Nh8q>fSF zgUT!^hzk>xq#Hpjl%yp)2zvG`!u6*@EU`$sRI9 zItruWL`58F!|a7T4tj~)LBdY|0MWU2;9cEZw)&L?K8LYU-!7hhFRU*6f*zlzz;E=s zfOCG0s?><29OdQT7EH~7^u*q7N!@(*3bPkNT4t(6Pk8+)s_tRBeUsrS%b$Rs{$o^< zC3?Q34T$nw8M~n;*o&twUE%6f6dXvU_rr+af7I#q=;k=q3I1nKvWT5DZLfHE+_{eo zBU&eOnmpY+aqIj|RF!U{cz&AG_98Gmeq)&dy1NmXW2}F4j3o!nj?HwhUdQ>5R1L z8rpiHi)JwNViJ|D1(*Q6^xAzq-Cf_%32gQUY;`=!X&}l8Ve!UMK5U&eu-XZY;=~z= zCn{U3^?|AZX!r31nuI$;ZtA$$t%C%!lMsQ8%%n$fTy#f+o^v_1St6W?+tt)*Dkx54 z0?@6`eQ+-_4G{uPW9Uiyl;u_i*gnVIr*OH21`^fYWQtNF-dMWs={CJt5}nqvsn?kl zjpLssT`@0Ob(P>)gL#|?$H{=`;>Mq*qs${t&@t&A356<*LR-FINmy-Z(&4mavI!%- zd#ni~7U*0$mJx^rLp4i7EY&I0amS%}9N11j$Pone@;$`U@STZqc*q6Zmf^yMq!O9NY z{Xtae>6lO9uBKmf@Q{Y#keK^<f0R4_5Kd3Z1D(9LEU}dYIMq;-p)rb)C$o2;b!IRm&<2qo9IUhH2Rb)8 zq*O1GUg7V>wKacQ(!Lo4>zTbgIW5nkXtM1r#cJdhu_hiY<2NJ?8yCOkm-OZDGWR>{ zAB`tPo;m~M=O0VyqSd6(adkP|FE4bbRVOF{CH<@l7^|)ibF-Jx=xpm{!hL3$FxE;l z4_GE(VK5aYE6sPc#crh)m|}J_wLIxIz6pgHLHjaucYMrDoiqD3XN^!e;cvs#m&Ki} zX1syyTnSGkYlz z+0}HWoYyeSkdolD|88FHnRMfbjQf!_n65iwrkD_0P^?*Imswg$50x)coBHvT*~tz$opzF459F;a%Pb9x4_JbN=0#CLwok{}T-nD|oQ4UZ~P z7zbO~W{w<90kyagRpI(_Ce_hFt}hqmOo-7jx1vHgwY`{MQ8IEmn6#^8M9^@)h|ZWj z_lN=Y0P$4^AqF5WbP!?y;sOUD1|U#}I#MwJ@l6LI1|V=HPx}x95LY+|F>w4S zQV=PTKSy2SweZu!G_2ll)5!F#-fc9J`uu?Cj*O|!KcGU>udu!K-T*(nHxk@LfLnt8 z-tQ3HOz>TTTL^9i=zIgMu7`!BOECK<*fn#pdat9eD+#_uuT%ux!_u;PuOjklf@|m^ z??AEGtlsYd_AvKW@AqkBzOCNdXp|gtUzXwx{Bu-2W`7U5dsva^7cbE)nTH|`nkDyk zb_dOpeLK60W|lepKM%8h8cImBvwtRH1iEIAP-JKSK*Sz5pSIMJrqPxP(nQ))H=0Ut zzdZ;=?)N6YtS3KZay@kS(e-!_THRAk1>EfhT1{R$p5zRpf-?-Ap$@!^Y7jbC`+h1) z=VRYbMd^(1TRn_auia6B1fLpTKw%fHrX)L-Q{PM@DU|xNJGMm}3Z)k9ju+fKn7Xvp zy}C%0(M=gMdK_39y2ET`AsE)pGSK}>cB}PsS-Ni;1jKmYgBdnKHVT3{G>CbEV3rJm z+0tFnAeax`6&)t$Eq@zoeiFth&6BpT^38vp^fJ{PdSV0gs7jr7|sT(b5{#x02v&lfWu+|DdMvc ztP{V3@xS|<09tF&SVSjx=^ZDG!T#x}cigpOK4mXUL~Ah;Lh6t?I%=KH6OMk2C+?sb z$CYqoE^rQsLtmZTWr(vDXSwWq8C*=yV@38k`v-JKT>~|paqOx)K1e3-=2T&B%i_UN zsHfOKP%;(BzJtJJMc4#$3p588sSFd!bwKsV>&kJQXW^(QK>c08%%M(lLS_k%l=+}j zF#7~z?vEUl&A%sy2YikS+<2&Q4bD{ko2DTco&)XTH@g&3*Tzttm`meH9C(0KOze|n zi7OQoPELZ11Nj-ZTy&ee13VWSc>xGN2DEG$8mn`c1zUycFQ~UROTXIyE2cS0VbY~= zgLz>L9->*EQ9#9r@m_v9*a(sdgnY5r7rjx_t_|`Jv@391ivR^O>kk` zx>ouN)#HusA|#IqQFO*894(^Qg5EcNL9rC+Jne?}fAd8es@C$Mlhj4`YZ)U8(pta# zlQvVo8x#d_?>JuKAGlmMZChqF)3HMUp$(ayc$z$vSF)+E#0*i37JK>(-11BT7IyiS zZAFkkw~|HB#LA9T2Nmf2Vn-o_4nQLgTQM_Sj<*=dS#Yo{wGqm6VcH{IpF5k<^>MWV z$|*AQoL8qIH?RAZl>2DM#y;e!oLIOvkV*u1&J9Ciro=yHNve6d^YrwOP?!ZzPa{nh zX6@N<2zg7An~!k}gt|O$R)>7xl;_vfnPvKIW$vSpmtqqa@>`f;TQ%jK^TD*BORkI7 zY%g+vyO+9093;&T0oXQA3gXMQ**gWbpI#3l^o+o;)R8>R)LaxsJg38I@M97_ld0f79<0O3dEDxd&(=^_Qr>WVE>eh;n}hUsGd9DaX{HfZ#rMIw zN_9W`i)LM=-qxW9_330VdenzRN_=54tVKkbAI&5B`4P__bhXJZGf`JiEHfS}bgs*I z{0|X%W2`V(`hswKETb=i@M$*AOQ7N&E=|q|5{HBuyCQD&GXPXl%E02FapxIWRbOVs zV-dI4nsJ={Gc+lLcW-IZ{k3+s8Rl^z@xMqX$8}S zP`eJ?uAk#|hTTL-*?><5R)B|wl5>XIXuAU>O9DjU`!VQEre4b8Wl}FZYknE+Jb>?b zd=IqvW{*-hq?hr8cZ8pV+m&!T8{akfHrx+n*#J}oSGe)wmh@LpH)W9TkOQ^!$*_UJ zNHrndU~`K+58rUU1cNW0l9@1wgi{DN%u>c!f-uc4if3|y(mHY)<~gZ@$ZrR@UYF`GW1| zO>JMfK!N|K;l=BxIUhWp~Z?1kb#Bss3Dp+v3+CfSZ&7-a|ik3J9al1 zGnxY=X}AW~vNBu}r{^I1Ij)1tb6f~lswZTxTb9Tw64={|iD6G8ZvGc~4u&|XT!@*4usIeS+1?8LHsbeX{2IOpfH+wa zCTdD$rt8sCq7AvcW86vEam=hW!Q%OVI#}i)*ToHGTd511|)U3A>rO9D>-+~pZ@qt1dKMDbWSlNFVHk1q= zKut=+<(Dlj9;il;$x$59$Ab_N%wUe?pImP0TQ!A)#6u`JQ)Y0bO~H`CA-#~sqNTR# zo>3N%7Mz?=UWT`in1pnVX6=gP@JJyy@#QUYZt(M@{89E5K_{~(Vm8%x13!eWqqo}4 zrhYm|%p7jM>#cY3af;Y05Ia~MH{%Q9TAmRZBy7v@Uq#Xb?qV#$cLZax*GdRB{F-a0T3W~~P4<}KDULhF6 z?NH%4oADjqw~TFEh{3IMmgmU?lD*DGkW7u@P51`kR8eN2MubA^ zB%*aIua%2Eyk@h@Ep$UwzR(AgES?)K>aUDH15Mc812Jv_rdI!2P$r%(g*#rDjz)C@ zb;_zo+PB|n-?ntG^iYzvvmheV=e+S{=OelxZuUIgBkb%X~8WC%~b4eG84^F>~3-rFFUcj$xVa;8uW8ABd}M{L#t3ggWXMTBi?Ax z-UiVdt>TRayPH)c-e|}|fFjxzXQ9(7-lPugZgMQmw(M^5D_yBz&pcTmdmhd&%QBdk zGj~D=XX!&Kjw;AL`cP&ilfzdJU)|Y`VOI1HNDcZs7rKp03cl+B&}e5D0W0IZU;P#J z*O$NbIgx-mdXd8Ps)KiXBt*=^mHTj)k;3k{hv&K267ihp-axCV=8lm`=XgNZX~*xQ z2r#!W0IjAibleY(;7`pjbf?v{kB%k~q=hhKw6Qx5a}hG$*d41$@(5I`=ZKkBX$;8H zX>@0`d)(bt0QV0|og)qzk?f8n^6(TJfG2?49uVMSMu?3dkNXX@N^`Ju+nj3Y##d{& zoJMO_r=2u!!H~~Xg`sAKTe>Nxu>O}OC#}rGRP2s#ySZnlkhW%XZ%zLCyamR(wxkbl zWfhx~5Z18O&Fb`GS+ACK*sZKiL!!f%1SieScg_OJM>moox!r^ zEa}rC7o%&=l8$WG>c8569W(|HbIC12$q;2#BjBaV$k>@+Aw&0LK`Z_W21(#4?((en4rHSpC0?sXgK2(Qa3PTz#sipk{`PRUr7x-8O7B*02fWt!Kc!SWrNEi8Pk z_I!k{671E^fe&5lot!vvjzFc$(19&ZqA;Rb=P@rIwa^>aSQD4_lx{4Huqfn2=y5l( z8j@3nTIoL8Nw}~!f_Uz0AByiDfcO-+v2^6+vL3e}`IDuL-f7MYGh zF_~Zn6LYj+Li&ACUe_k6&RhyYkqXjoaa&7smD@&K%XV`;8SRbiHqU~u!O>=f%dr%qM zg;6~M(aRK!&3+bRt{L^26$-n9Q==3!)&n%?czv%(srhgrUXVA1q12x&8X|uuX zVnhg0m!LG^m8Ov!bO`4iZ1XEq*#qE>fw=c&T*F3vb_>wl1T$!ezKFFYm4!x-XamHd z6$$}+*aEQ&%}&pA&V@FxAYEajNiD!Hv#Kx!Xabi6TZ%G^jSD`euW<{~B*}9_5(a-& zh5j5LRJE>sXkJ4d)%_>$$q8Rzr4=`+nLLg77$)FJo^P@me@x!v&qIPOSU?fBA4>URe5?ISq0B4nHMl|tZT{7 zYlc$sJh?rT68NQ0^?5i#-}#8EXr+EP;^0({i~dxO>-|)YOMThvYel@64N$I^k8eH- zJauAdlYM#A^RQ;r_<79rLsOpzI)i!nbMyG-n+V3IFHO`CWTdIjyO<_UI7*z(yOF8q|}IzI7kkvicf+?aMZIcCA@I{;)Nj*-ahCujzD6hpjno^_q^Fs`Z`6XFJ;4 zR@GFkSkuwjmfbMBZu~_4tErm5sl97c$C}w2)@YU!p`?QO>&xMuV6?7B4@ zX0Mty?YODOPpzLcee#qw6C0+F+B>mL8@k%ouW?dewx)}0#@W1HI(Gs8pZ`hZ>aU+W z@}A5uhCN$(OvlSd?wb9|HN%d&WBAA`ZVj&e)$SWkn%q75 z)E9Pa+`Xt=GT6B&#Sln%oo%yz5%#pxzF@F4bUu4&L-`sV%RZ$x9@uO`?=kBU;WBAezGffk1zPj_RDu)x7C+`e|UcNC*OPJlKUpS zdehyzzVZ!U%pePFuUzm$ubTw$`I}$6`zJns3n20n|KEP{Kip3$QL6p+6LvXIKbZ(? zpMEj}sD1R4gW$ARKUoE2KmCNV(tGujEkJtu$wiJIZ$Dw@Dd;EP24Wxm;t z`hqR;1^s-3;s5jF2WXT(Gk%cfdCQi}^C>+D#9%*#gV@xG)9R+tX8_C)Z}vinYE-XM zCqm?~{Y#jiEbBtqpU_Dk&wS6P?ne_Ib@(!M$)i413f!pu4?lpj;cvr!&=T0^wP)G% z_-CQ19r5Qo8zU45`Or6+0wGMDZ1jitJq!NQ8dho{+;4;(b0qaUeAmI#JbXvvHwtDy zzUBBGj^8g~pNVkGV1{=YtAh9fEx!Q1a28#8#GzrE90%2{!OMbC^{e26fI9@fAkYfE z3QQzK{G?EMD5@F-bD&@j7t97RpDl1(=%P?i?FwBM45}$%!p7KT!4mc0fZGQIRZ*On z`ZB@`6U0A|ApT)7pIv_YfD%SjJJ@s@dsJ=Id6#jD1g9tlou*3jZ zqGFX#r^?jU%2O(X>ds2ypAh)6zz+b+RA$I2l_hG(P{w(E74veNz{5r?8d0JyA92=* zsHz{y+$|RP{ut)^s<96u{(p|!F|I_7N|UNb1;(mrzOIh2a~9!%M*2BqG0htVer?H) zaZwdm%Cw#V464UhlKw?UUlc-Vtfv1r0i)`Gwb!Mhs%P!GwNdq>wU+|^T;T5nvqxaj z33MGRuu)*Mz*7ZYBJjQwzI(!C-)~QlT0QZ_6QXK_z!fJh#CcxZi7bbn6HlouQx^%` zCh#%9sCxZG(mAv3LHJqG_FaTs4RcUk)5h|=2{5XPPokd$U`ic+5)?73Kc7U`Hvpq5 zzK&&e?sS%LBg{c{$U5TJu3NV@sBVKfsNNOKo$d7b>vq=Zr|rZ?*AosAI32J=9lHK$ z)cg5>LG?4i|3=`;0(S$Jsdv{iFUM_Qy?1S33^xPr@B8xx(iX`QvqIpp0?!h731Cz` zlwEjYRQ*=q9{@oK@Fi;4#?O<8$68KRE>#n(TR%cXo32Yui*I#uKF6tue?qaBm1l}Mp zu<4=@N_7*{9WLg-ox*wvoJz_^oXSwcPh&~$e;UjDZ!kyI$AY=)bhfVFoPO`=CF%n) zkLqSiJG`6puj)PvZN96UZS_LIpWJg~4|-M)V_Vis{5b-z5%@?i!)9`f|8{{p0ZY`2 zXEK%VpS5FLQoVcDU(brF=-JHasI%$wV!#r0-`Na%>^UsM>^Xuzhxxir;M2gAsGct} z#jk&H$2f8%&6miD$wO0W9C$Cy792S8MX>Eg2$KASN8p6NRiv8<9AlaSI-!`>J^8T^7ZC7tgDFrc@#WAxOXE8?uta0ixb*I`7 zSua(Uu*KC+RK3MA8!NVl)GR9>=UeK#60SzvhWc*txQ+7NCvNrPmiGNjY>lv;rY8Dc z_4u6Xdr#c!S}w$ZH_N$ld_d?8>Z&@ifmH07PgVFmD^{+wh6X4Y(wolWrz3< zlyJRpdqy4YJILd9qOVij&WGD&YQ3+^<93?wVoBjLi8JT>x{b<3F2|u2e9?Ec*zOS9 zg~oQT*e*4;hs1WZvHeDDw;0|1 ziEW3mm5Xhsu?-R1%f>cFY_A$yjo9`W+jOzLZ)^+17POFCl>9Q-E>jWM@})b(dQ8^} z+~O*2J??RvX$AZYw;FC^)gmh>woZviz6-xHkhH zveIf3+cslc@6V^c(mGk<{HcUnXLWeox~#2|!h@2+7V82(+sp4@t5rSLH~bOw_ua6K zf$egMS2tF=>X|Ag%_b+Pr9*gh7wORP^lDSXo!5Mch4f1FzGyUHpJQ^7tHl$`_pOt}ZI<}F z!&>KY`?1w6Zu8-Gi|;OLi`Wj9SnjsY_4xd`^(}F0h1+@1$8n|DR!g|Yts4WZqjuP~ zt6y7pirZKW_F0PBx0B}UXsRw|e;mzS){U}Qw8+6JFv z)N9s|AWQH&u-&HqY7O=He8U;eUf;FvJ|~fNd#krJ+1!EA3I@ z_7dDqQ^(n(J#Hu1P2%<%+^+Ry?YSPe4*OtndmC=c!F3PuxNWjq#qB+~m8nzhm0}A7 zF{b)XvwJ)~Pq)7qV!4#SZM!|cm&4Qz4s75n#|^uA@kA7a~WhuavuoA-hE+yvW|){kson5A@vguBx& z4(ChhVSB!~og;3K+6%DaRO+i6Io>{Q9~ib#n}6@3?MY*sb}DVZwU>o?95mq^&PtxM zSB4MG{UEen9h$p8v>EVeK%W{?`VQc+rI;hB^Gh)|Qokro01k@}1^hyM9N-t@lK}6J z&jkD=z7TM6*&%=@3%o?&y=BC|C2(AV<~4~Hz;6zG1n~NSPXOL2@X>)!!TcvNza`L0 zJ`GG+l72=BoGI|2Bz+zw=5~SI0xuMJmB3pB-X-u6fjg4xk(a+Ee}}LiCI19ioFc4B zG5$J%3j`jKqR-W0K26|Ofe)rI`%xdHb^-b-b_2#L{suUx;%&f;m>a~rM9eK>UN7)m z!CWHd8^wHwm>(AN(_(&E%x{a?9z?221P&57THvHX?*Kn@(1(DF1uh%J`Z{{hC&0Af z@WQ7~8x#UOdl26HR$muC->lpS%mbC10DoV3I^Y|XX8=ZroMQ!p&s1$zD{_CT`nkO# z_ol#41P&az9{8anpYpB9WkznsEV&LC>?^iF3dcx;duLA}ZW3ZKP^qYW@(f{x#)o$yeKvM0nE&=>_ z^yPrR8_hBajk!92k`b63b3M#M1&$fBJ>cZ!M3`6P)(bpUU^k#ooi&D~cikA4*v(_l z3?|j_feQf72wn{MQsA3_FZjt_PaMazI>(Xb$H#5P-pe!NUJlyolX0&C2GTSa3uG>A zl}r=vmwp5IiD}061gK4_zrs&atr$l0v*}l1-XWO32pk3fx=d^p+V3gEP`uyyAzMmj zMUEwGtHt{*cq`Jc@0UT1z z7&6sQn0mC;%xXNFtL6dYR|g4PQN0=aQMyJ}31)-9Ednp9t_VAI#M<$xD{5GVy2eST zUtL>sL)fQotzljNP~g1+9})OO4a@U6fx86$Q{cY@Mr!F=R{I2E7%DJb%RWA_mMxQQ z&z6{N#n^D8TOd=hRZ}hD5`j#`R*czJOvRQI(V`H)t(carmWj`!1TubGogl6q0?!wC znZWG=?-KZ!Kwa0**ZwVRD^h3+wYE@htKGG41HY&Cl7Lf>@7J=OSmQ}yOkh&rFo9#o z({;SSdcn*Sc*Xd4QEMBguE*N!*(roO1)eUL^8|iF;5LDG2%I*RZQ#KvPXRt8m}dmO zB=8>sKNT3OXPkotRtuaZ@L++*)-#5zz%vAXRp3Xf%Z zzwWt7!Hk&37Fa!vEpy5=(m7k;Vu5?NSlxHtokE{0B<$a&vWdkxzm}iuIZ$6E1>SP7~Q5{3?6d5z}u!@0P}r-e)Yt3QgZ(c!rKL2Ch!J8 zCoT4Fzj}PeK}CM`^o&CRcg!Gfd|}24m|vSgO5PJl4&WCK;8&5EE8&`&NeagTCe<6W zNY!U4e{zOG?x8uxowFFv4vFUpfxiI8;Y;t&8WKa>p8Yasb+g%j(}1>`J$nT32Z;H| z*<)coVRkjtR*^#{@t)_1SW@-QVa#{VA?7Orw*fk(_wzZdg(n1(qx#hE;NPcS63AR* zMlt6m#7XYwQys7Yt<5;~qrO7IetKOz? zv0q)-#2UXG&>2l`n>)LBMefG}?-@n&{QU^;7R=8D{zl-ODYJ{6P%q9c39rb#A~04> z^BZD*U!Z>;F{OZx|1tBP0H#{tM1fNTP8ZlDaDPC@|FU^2Ktrp*RRY%u>=3wFV6VWl z1%6fFr2?-MxX#BIUYxtarFr|jHNe~=@CO2aEbu;oj|H3ftLxq zL*TCj?gVtg{&W6GpiM0xEEYIW;AlX{Pu<8YTpw;AoFe8&VRl@nEa(D$CZL0vyI?ag z2M9b=;7ozX06Ko!7jQ<@1?XV5EO--`^8{WY@FszG3jDdi-wAvL&^5z*7Z&QQ+4FUMKMT0`C?0n7}^(IyAhx z@NA^JM<7Rh%!C)RpX#2dd!_D=p+&^U7g2-ZkVWSK>K-~_5y$lDf>|h#eYUW7AF_x& zy=4*OUk?~pXDQ=hmV#pR1rcsT=CkPQ3JHunGqd-;4uSib<%;W0lN-t1MEF; z1K{}wb^=~}AgCM%NwZ$#cteu6;6x*Q3~HY1=vmXJs*YxiexGV)Tq<&hnB3wDm3LShf^Ur|8gd z%knu1hX%F{^a2@YSn&kDAJetgJcgr&p7ZBtAW5a`BEJUFD?ulfzbt3W zZwvf*c@{lr%$Uu^m_HoORyy!-)_%?5@1PzBuV70{3#?m_MQdq>&!n2Rf*jz070fl) zn6^3wX0(47<5O6tKtbxWg3&duIn}5m+JLV`^Q~MF_gz8T>NWA{T^077wI)@*uCYp5N$xs)CCgLS+Gm*;ZHIrSjd|xqdZy&% zOZnN6PyKOa2$He8SF)YIE6_fY=2AdihEDxz-Z%zr!{Lp(U3q!w=%YA8^R_E*x|$NU zE{7B9R+pz1doo9{wDlU3D?w*$y6&jkQY&&d3jF^6!`^#`S54e?_VnmvNp{PXS0Vyhqhzh8Hhze2-7^;F1DFG1?1O${O;w>l&QuJMG z);c=}5pJIQd!F~XzU%wWA9L;BtSM{Olsz+h_CC_xAl*;FRm2y)J_PscUTC)y;F_X- z?-lTLIvHF=wCkN4Rglh6NT+vibZbcWA#mXtb#II{R=Q71cN(~gn1gY}J2K2N86I0^ z@Lq=^a(koYe*%{*c5`pV_8HtNV13aWM{KJP_S|B9%7*Bo99)x~b&=BtXZRbWyH&c| z!7V11HbHl#beBkXEx5S4861tP8+6O}Mct}Pw-LC38bqA~Jpy+jU}p?=A;8*w7ewEF z1wm^!T*n34z^i?+b{6)>RG42_#EhgALrf4z%?;R-BlJArnUl#a1VN%wA6f6dbIKHf1M@7Mj(@qUeaO)zT7{e<$6jwyzwKN}05u#@gc z>5c;T<`JI8qHIV_7jHpoIKqd5i=%E}txfB0+z)}hQ|T^A$LpN*FW{vy8l`upAAswx z(yznJ@OV0|9B~dt<91+I0rv(?(QMFQ_^@6Ja3jQx;cMa|l$7j0TPWh}Xxs~JFa~?p zh%ui&ym9V=CqN;kj8~rfSYKpof_nIWyrr*$Adi5YH9km>!0B zKJhfuc!=i{)0k#Jyb$pc(;|o$BIYu!2U#Jpi0L4tQb;UiIt!^35+5>MfsmnMBU2%F zHqdsaGVWaX_60nQm-ejTE&xhoN_O9c=TNhl+Pceu&NB6Mb71Z88`BUs7f8F8Qkej< zaN%Qm5oF6mw+rnlwjFrkVS|DrUM|06jhkcf-F+hVY&*kqM{*Fh%XnY1yf0& zVxlWkHD3;#jp@VG7-UgmFjGg6MT_A~13?xo#xgw)vKW!YGy`NYVk*-@kj07@nbv?T zR=m#iDaeY8g-i!PR$MG)Is>v2Vhz&`kd+V{nIb}R#699urV1gsK>18PJmmLP^Qy#}(f zVhqztkd+nBF>MD~IWe2*7|7r$Gt=)ND=*G78KJpAH4>;qk)dCT3ZfoU1xbyW8inov zSzD&Iq4_{PnRGetvsWSPndK4rO{hEEg!6NNf-L5#F?zz_KqO zWG%6d>ASECKwFqDNZEEKvv4lRz5t4Y9I6%mL)3=nGDOXR?h{%CqKv|tQb&|v$^@z_ z?qhnja3Lj8v}IZbR8Ks_bg*!gQeRADx&YKbyvkIuNNFWWtYWGUbidfi)U!w>rJ*>< zGz_SbxWV*tk^7WnQ4C(}L9O2fYAmWTeNm*5(nPdmIt}!I=*Ltjyp_^ajAM!eY9?M{ z>JZ*hX)cyB^#y7nK4lsU)KYxQ^bAldaamH9Js+sGC|n73$+DLMwGkC0`RyH$LyBm^ zbQmaA^kDiEsI3^qR3xI6@}QW(lnB&LEM`gtYA-f34U6cdbPxxbo&f47E&<_*w|Nl* zlujb88qwN_45f=0;?Yo`GI-b!Lhg?krF0dQna%-q6LXo=$N@?Z(Gp%n$B?m+k-K;z*>}EudK)i`!LrbD8i1)NOBFP{9W(?B)HYnRB7RThmYf1R8EJzz;3agVu zW%v*qT6a%OF*REpX^WJnoQ8OQk%mV=LC=dZ_o#kxiRrJH<#1jovmMC_$1WGo3KL&z zhL9y=GnA>K1XC4BnM^6M<P#^a58y+{_hOUPmqc}ZwG8TSE#&a3sFOyr{MZ!rRguZ`ZEOeib#ba2%Cg1T*kbA% z;wPr-KyQgFlCngp;=R;`BDyDrgt4diK=o~r$<(-b22eJU=vX{MSuD;o^^ug^OU4rq zNt!MxODvGI6kcaWtxJ@6R$VMA_a$mj;yIwSbfj$2xkNE_i5M)&FVaioiuc4uNm=6I z5*f<-VkgrRC4Lm|i<2DkSqS;QNE%3K&V-Ol#Rf^)VhNQ2vWAFeNQoUtyn6_FPcNhkHkcL-2-H8L6$4lNb-vTAlrZfn4M$WJ)&-8 z%2VdXeWz~rXj9zJ>Q;|-#HrfnOcZa2Cz~7RXuCYx6c?fG@d)GXzbW2Vo@{R1y&Ap` zg1Y1>o8qczhdsi0CzvR|?>rgCJLwU|JL?g~``1nJe)eQ@;~HxhJ=zr4R{PDP9dZ4% zYd6Ka?#VFTpB`a6I5Gl1)EeW#;!YCj34eRUvbk}CHT+mZpnQ*Mp&ns8JbhG953r%e zA?L)}S{0AVmOd6lbwO6mll3iqDu{+dDm9cTk7AB5i3O#9(rPMuJ^D?ntu%%A z7*MvZ^mXk%Wv?XEIzy?e9K4B+d!*}im84-9?}W0iw5um7O(proxzeFPDMa>#(h)%E z9>wbQlqnqYkJ6>}`pN|+rA%qPfiieFrs)?UKuO9pBB{&$%G(|_)9+W-d(=j6q#8?aDvZE1^BQ+6(^Y>!=`P7{KU5}1G*c!rjh6Jiq}gIpnSMH){u+t# zX4@~88KgH?q9x^t`DGr}TPUrW-YzpzZ>e-(T3P0hXsPs-W7UvH8BJMEw#4Km)QYSlIf2!`9S3) z}}kWEtJ zndX8lTdB;n2xQsHeUkEQwC6L*{Y+@jXOxy4a_PM}!ml(KkGbc8m6qs!CB>s<`ea3& zK$?ZcU(ugcT&5E7e*#4?Rfso?sY-FC+VMW1c&0}2IbxbpnJG0s7wA5w9w3{p+|M)$ zWYd-AOf%xcjTuT?rrGh)KwX*MfOyX-V~Aw^J*T|kQ8WEHWt~T*j2D#s9+fj@Dd#<^ zZoHx-Jt4~nsWdX?Dld4{&RD3#K8Z4F^NW=7lBoU`DJLb-Sg=@*m|#I;b$l0Ni8ACV zjF+dZi|=Q=@5#2t4>gu6i==F3^omiR)?K4)lH|85B`h`8DBGE8Cma%Ml#q#-3ij}o zARFRQu92f`l|-7YRd$jLdgB&jt+Jo#frRB^tx`Tqz|Rk>>`#q#N;VOsdBFHc*~YRd z3Evv)m4lLIizx}`jV(&j6pHs^!VM!&sq?HPdr87beW#Mlv|7>}rp=PBFddN8ZYst5 zE+GfruUSeYE=YpyJ^0ZGwo{4r$ToK>*^;PyyOil9!#jexOPMg8(lpCP0AKvx!=l?Ps1)_5;O1pWaf|Z+@@*#Pki&NyU7H zLS8QWmU&8v_UL`{j8c*5PmukfH1+6x^G9V7Q=xKinLjC;m`ayhAbwW1d$h*9pk&UW z9IAut7v-;4CCR?>tFl58wZUH%lt61ObfNSHvw)JzjnpsQBrBkH<+hu@1!P7@nR)u< zAZn&x@u*w5J?2%9`j^X4t||6wnBQp!^Sh>OXTmhEDncse*T#ootiD#NtE*Gc@ z)2ronh`*Hkm=>4I2WluOORO%p!4zr>Nv9nwgQB*lkh1KGI^3iErlPKuMD0vfHloa{J-%rlGzQ*Uo>^~3{%VUmw_%YbtwO*X{cA2dY0EMcy(hgm1t0T z{96f!X+-%jpm3%MAhXn1rYRt^)O(p`fy`DbG0g{=t=4A3vDHzNm~d=$)MiY$6YQ#~ zOt=&5s$H0tl#jH0YHy~G%EtmdL?o>gqK@+DvKgZ4^JE!7R@#DpnUO>`3st8`qERta z?KvMq(x_Niwcn8OM1J{lR=67J5xkYHZjnT7FiO2nGMRgns=q1Y0d=&Z)O1OdU$i=e zWKc)lt!Q-=5zG$z0?lC=_V5_B@LK|Yet~^DR!wJG9Y4q_p<_9fnJQFR zVO3Y#G1aM%1JsQPYqN&hj|pqDhB`zNS+}OTR}xvbwtCN^0{KRxG$N$u8<3KL=u&#l{#cG>Phx&qwbMJB}!G5 zcLHT7VW+A^JW8$H;^r*7kNljaVX_6&6tLc(R z7oc}hM!IxW>%E8Mx93)T&+4W&W?EcvAy5hvjzrzn>r6NjbypX^Pw}uV^-w=x!nV{y zUCXqhVvgvkZf4qCF&Ah%Q$EOgse74@fvlH$i0J~zdaEax%u2aH=a@=V$`O6kUzjR@ ztdDw)sSe2cs@hW0>;aJVRYRECRT`=HQzM!BRN7M*7al@ft6necuzP+iP~^Up!*2TVBs z9K<=`EU%&ckVl_YYHdHFuBDLTt4huEVQQX7^YjtwUrc!a8>z-GLrwkSTPW>FwKdbZ zN?q;8)O4m_fkvrEn66jqYmZi=KA?DR90 zMJso;pH!1q5|spcN}VprFUnVb%AV+zVQakK&Qj&yOvxEpf|;$hTZQp(we-5}SC_6v z^4o7$e$Sqwu937=MO#l%w=rQoJga_2Az>^yDyFK3Jz8N;Q!jdyYd@#@)?k{{AD&ku zB;jcKvHiSSToUz;=hgO-XzZD(jwKRU4=<^Un6MsRQP+KlY32zm(d+7vwMaO}+-J{M zhp!9JA^Q!r(nm;?`AouafD&_MJeWhDw%<~VtVfz;x2?KEEKo}^ z^{bi>RF!EI$QG(eOp`&jP)(6Ux-3%nZjfn$X4mYuy?QuT+Hl@cCvKwr-mV(zEKw_O zMj}hRr*8NdiN=Ygfp~=~CB!-(sDErlncrSjHAj4)>f4AmND5=xDJhoefTRSb6OyVk z{Vb`Aq&!Dd+W~3zX0og00}W*=46^0w7^Y~DEm!@L{B|73R;bT0RR!4!brn+*$X2Sk zOszq-QvH@G4P>j-(@X(ob>nuF{k^)aS2kbR_1V9EeluA0p>7G$~V45lg74~g~a%SblMOdmj+8`V#lav{x)YCcn5^&Mi9dVuN6>iIy&n2v*N zvwDWUSZN})B;lS$nv2z>N_8+4pU5xWT0>+oCSTN#xmh7=o7UD zQ+y4dwN$h1SdkTEY}pGe_)DS1{EF z*$(w1CcHE6R6l0IJM&I;2UDk-Eu3BIKBfURQ-F?0%2P(x?BMKHAO8%ko2O*e?CI=L z$1zO<+N(~Kv{iehWiq&VKdcc8s@GTURqhJ*fW4w4-LG^NkwvImwRH ze9}3h#xea^bB8#pPLwoBT&_9EIjXkYg&`*iwbqNyNp;O`B44dHoFCM}dx%!YuXKJ@ z%kL#BT5F?oSxxx@31;H8p0cm1vpm}FTvNA5%2R6B+U;Cd_kT$t8`e7L{H4nObA$X+ zYWd;+WK#~HY?er?^}S4_YmL+$ZLXwj@eIfuZLg$BVp^>Z zj!z3YgdzQ6R;}$$A?;m{esDsyy-f3KU2uwMgTJAW%OPaA_PwOpVpFZ(oCr-hjI!Ax z4|Ivt;v~_`v6u$8J^0bSMlmhTqbRqS_KqaF=R|4CNe1_vl5Ui?mdM5y5~Xcs!WI&x zZD+z&WVE)I30INP+94)fMaF0+m~a&tqn%?KTGwaAYQHdzuNww*jS1(G#Wn3)skM#s z$l_XvB)aF6&|Z*4_neZNehfoSg1c|L8>huF<(IGS#%nK1B1@FjK9S_NaV#jS?O?*O zpse;K)4IC#-E!Jtrmc08fle~z*KOgJ*UmG2S2q>tH>Tg~!r2k+2GjMraCSs9k5d`c zL^wO5g)-TRaCStCVhROWC9M=wQIJ*A$}^P!S!Jy{)4d?8tkq+hRUXccXpNcXmxr?> zT5G0?5U;A%f$2VoS5@o5lnk_*YT5y&wuznG>e`P?-4omB z)ivjYfS=zU1hN`hNg}!Cs-e~MsGLzlYw1ySqqa8RqeezOZHq^L>d9KU?=Vejk&U%# zl5iGuMQ^MnN}^WKSi3HXTEPR_-0!6>(2u&o$CPs<%?9e{HrKYXY)s-%x3$*#B!wK4 z*v(DVIxE|{TDByzL}zU}$-olt*`2jnlE@OBwJVZn zHriEdcbdw#I)0AZP0KtJpr!5rE$$pq`N~_|hqZB%sCNv}UL=`)xL%|+M0<_tT)kMJ zg-m~d>{0D~CZ~QZ&>E(g`WLOC+6JbI^)CZ`%G3a4!?fK@sURDs9boEH|Driu`<7{V z{mVdSiKLZAXzhLs*ledeLR%w=>@rf@Kr*n)K6j+HO%mBHHU`Wb+npRyBw$H-8X<8x??EVx3 zYUj~CzUkU14vBleGqfX2xHI&e*6CMFlb#JeuVoTJ*>(K|ZNEp3Z>CoLk_-v5n!Xpc z>5@p7m$X?V16}I*Uee|=wM}RQbljt6zFAuQZH(OgkBzHhw(cWXi zvEUVLHB20_UEOt?Gps&<44cSl~;PBG!G z%4^zBOt`D^n)W+W=LX%a*R?;H1~upiWc@D7U_ajA5#L-bjOpnHBY>irW;F0w^Rzgo zHyVTiRbW~PviVvKrcEH5uhnPT*&s)}p*3MT+8`IG4b#scdsFMkq$lM9^(2z5^(`&i zqfFmh+NjHc8hgsOP|LW2L^ZZZ8zadtVv_v6MOwBbYP*ZHlYd}H8r>Fad#_4TR>x2G zEzy#$A^Anwq?df}YJIO0-Ip}i_rA85=>ec++VC3`FEweAZ@D%>l3#R6@>wgjgg+@> zdeSoAO6@+T?P05ZtF>g0J_1_f(H0;4{oP*_Z+qAd-#RTs(j+l1=}X^wt-7QvF)it^ zZ=<%3L%y7J%J;E0Q7916FJ4aimv5Uk-J{=qd0MuDvPt5tr0YPnbtLMIpKI$S`RzyV zuNv~Xwv}nz{k4I1F-^YTXYJ7TGtId_4CpA+yZ6HkS3AYD?S7cyYX4$72C`k+?@X6L zwoChq33se_YZknlj`uj+vEHo}CXzLsuO)hv>C4wq4KtLz+B#3RKOr0BDG);XD)4)cTfmSi$IB4m) zOgIi&`c_F<_UK0N>_y+nl-&rPz3BUyUILk;A7NSmGDklp$#1W0v_rW1PfVK{P6u1ys?kHoqW+Osh4M3ojg)6 zsrO{cOWp&rflP;z3l%D*k77CtAxr5?n65*}Qu<0sv+cr-BMQaopEKRtI0on|rn-$w z0eveEG|}BYPCqGS)RyA((avr6Sj#mdLk3n`@MQH6W05^dMim(@9}zjCam{(y*m@udxGAd3F|#Ue}w6S z=02;e{utBx=3zh+B>C;_P@-~rHq$;RQ8|4P(~;)W3zgTGGM#JwBG5jjE6qph74&bI z!dmPxE9l=dm2ELnuc-gX)Cgo1^-GedEmhJlGhth*tY4*&&>LSZR7I~`Qnmu1cM8?g zcYCz5P+k43M{5h!(;tz?%&4c<*B_IFJ#|x|`uYS()cfn} z&y~m8vc#(`_7`feXI4SkOtGxR;X)mCA&;)j6q{OnSE!SoD2e(?7kv#A?hAL<&(x6d z!&}))U%b(>aUMy8q_KbD4S_`tE+_u z=+l|9TZzyC`pZnXT1waFG2v<{T|dBty>Y#jpP8_C4AQSK;eGlc zUDPJ6@jm^K?l8@PG7Q#>Fue<97_7%K<+i$LKCG8v%5QZUs1nn6P`(Vk7Sr!gz6?Ey z$!+bk9?_dJm1-RZlu9J$1w-_~9$BG7^tm2IgpSm=Ny2A!5uxMtx%Ww}AzqG^tmg-{+O5lnKC4%#FVhqaTGtMpp{Fpd zj&Bh9oSx~?gQ2ta618i+*Lp`^%GAB}xX>l~d5@kBeNRtoL?H*X zo))@Hzv9vC&=vZeWRi^l*&2PFN3%oM>gkP1_5{e*>${o|t&3k2x=Fv{(b~{Fedz-z z%Mx>1?+)FgCpRTp)cU*71NuQpe(^!;OQA>f3(ZhQiLrJ6vjOL2mOdg&Gd76;TD)X zuH*9c^Lj0&)#dI9`$bP8g6CD`!+zD9N}^HmSG@%jj*6G`t`rj5#8L5^{)k6a!+zJF z@@R#9O@G;=q_98r<&vljf9Y#U24#34>@R(bBx*f>=_OjCo-`^dMrR^9Dr&|=CcL9t zM$=X@qyKX{(C6#F54YCfp@1X3R~&RJN+POB`(sP9?%!;uvFY zTO!UKvj*%o|pr*-D*bRUIBu$97eoH`|Rq*FOsMg)G*+a$XHsa zv95XzV^kj`8Z~Me!~4oq><%d}huvpnGWAT^A?`CKG7U<}2YP{NcuJ0_W6WWCG9?%2 zEvD%yKC7xa7Q=M$YsJE-9%$6)8drZ!|EA3nO3K~1@tA;mXvpZ4m0Ja zlyvJE-!tK^bUouoCft>-XIx@B0(#art~31xde%3LepFg)kqwM+rqI-7VGWGRObr^W z2}?3+GexE50^QG4I@M?0Z!}}7k{Sloj!3=@(a>1KgijojjgbDBA3mE{=`=MaO7e?( zsUL^6G(Z5qJflr&7c+%vtJOR8Df>ZB_GoHXyPdI(QyG`KJFLCYa{#6JTT<|Y}3nXpApGEOq#93|U0&xCW7Y~wc~;Xb(6dd3jLWqx+# zgSopKsMFr z%k(VBrWy}3%>~&sV+7L&Ae&~4W5VYv(~YN@@cGJgW4a_73uYKiM_?IfEO_2HFA1Na z^e;Tqm@txR8lR!eF=k65%fDvqmxPwzXTN3~_2`=Yx^YGl-2>(s7l`CNV7_sQWjG4Y zH!6?99JZ=Bw!US2B8fCxWE_-4Bj#e`=OEb<;}1!g`(uUQGqlmN9)OODrACNH8Okyv z(xZH_%(%y+bA>-JdU$lP@N#3QM^_53GO|5Vi>xzV^C+aqCS#RHQAIvAJ|?n{w%Y-H z`E#bT?ec;4G5y*Op5_|Yn6&mKi+pC-W2Dx0;r8bWe`XY8x~KgPvE8_rsZ#rVpc+i| zK=!%Okf{~OJ~vV%%@p0*_tSS6k4Ty=2Dkss*=fwBkYY^x_#(TEjZ9CrzgT#WvDcGT zEwaxz?a8hbK4@HL@#8X=FPp0mYE?Hd;P)=2iKRgqIhrbiu%{Ag@oTGGB%k&DJ9 zj~W)aY?RN$RA!1T?RypZ)A*U`K>J}u4AUMvqD*T#=7@Cj9;Qz^<^q*v+6%IQW=kR%Uow<|=2IS33m<4M^$2F4X6!SV z1Ko2THp@uDm0P&+uvuABo^rHfo$!av!hQ@%W8Dz*1xYjt4>kXiglF2ChYvTc$rzH> z2*b^ACR`(oFl$J{aqy@ZX*TmHCHyh7t4AyB$IVAQN(&!nPL@P^jyInt8R*$3e7yOJ zB+_iWxmyyA!cUl2h~ygKDYMoT)QomACYdcI!8b=b4Gf=bPVi`G_*C=wR0@f^950#K z(~;<|J=>h+(PeYCdB&q>!e23q%)pSO=NvOe656vl{O?t~B+_$^IY|;(@HKM{g|u-m zVXnD>3HK7_nx8V^Ucx+cHxuq9%rg%XLHVYK&o@^*C-nq+BYcS|o+m2NX+`*QGmR;s zQ(pL5bDgAZN-pS_^XMr2M_4zHE`{$f`%9wI?ldz< z2Bp0gzSA5jiAuZEoFa*8Ww-eTk-&N69&?|htt!s)_L;|-a8~)HneZa&k|%Ihx!ewBdWQv!vzi zZk@ z(rE=x(4IBZBxQ+_kl$JJAj@!v;H-I;r-JIi5 z<%mDb^j9grkTSI+u9<1CAyNJPX>O22y-HZl>oTNl$*L9UQEm9Q?%|TiN}82PGO$wB z5Y3t>iPF@pS&}GC!&*ck;aOJe5X;)m@$l)mZB?I3n&H!N$67*Uuj7FE8BDlNO|WJ&;kvl2HJ=Gr zA!V(1m~aMP&RWidGx&1WI;LHn(j&@STbRD?lmYZPk*uQ%)-*MDtjgCx+JQxDpucxG8HI$W<)jXibpdd>RB(mjWX(~jjRol z{5FoXjjU}u_P*AN9%KvLHTw^bhP$MqVjdL?t2Gwpt|jB4JVRy+trF(B4x5}yIU=p zux@)>>m^ZX2Uv$C;kZ=F7+{_CC_{P3y5P|}5f53)yMYpY81bkT=}}(9DC-_cr1fYk zfn=cdml30_Dw0U+(bfZ!NbAR~o#?%93+1BGs4}&b*n#lBc=kFt)v8FIh?EC}JOr}Z+7b5)Dt4yJ( zzXL5`dbaZpG1+>L>5b0$K)FmGc7|25^$F9S&ag_hc1fB9W$3CuYYks2%O~G>pJrW` zCGl718xcUuW%=NYrw{&5vlCNj7c=sCYqcb*zvrzVNCr7P2O-@R zG9FNF*leqkB&wBHtXd?4T3HkJiq(L~9@iyDykb4TG^I-}Pzuv*kj=3=F}(}2IaV)8 zRGY6_FH54@eBH|DkSi;djGSj3VA@bA0q7XhDM)j^b%yB*q&eTZKm=M>iG0JVyfRRR zgvbTfAdfPXh1MvK8bmI%R(X^X`Hpo`5|ws|b)IBU+K!P+tV@ze>m^p|D$Ieje$Sdh zB-`LpD`hpxCJA5HZjsBa5^H2g*^gFO6C`1a+-I+`p7H3K{h{?dhr}J^wbmRWxqGnA zn#(fWJy>ToU5jawF6*uCl1P`0)(A;{yLQ(f#b#?PQ^T&0MsBvAW@_0rM{KdCGIj2n z3-l5ZXqKUTY;E!AvB;0DA3Pc#xz#Ga4s*vcOpn}dwe)CqNo2u%YXr%_g7YHt ztqGDy>wGI;5^25HvOgj#;eBPFHJAzSD_>cQm~iYlWJTp-NNT&^TBU&EU_W_$*JY94 zT8T{010A#4%aDG%W?HCu-0H@ZoMr>{XKI^fN1U)Sn9|a|iacSBWEzlm7-%BXqiNT| zPgu_}Wu}GdC#=~_{nc;1Za)EO z>t+4f10ddMD}rfww@ZQ$o6`ZzGJh}?9!W(2fkS!PItfP{srhl|fkqm13UGbxJ zK@!#Uk5=|3j7K&7la;wyrXuhx&d=5wkEZ*6w%*)=GI)+xYp(Bt)$$XfC%b7yf3aps z!gCkXeV42wpP~$Rm*@I^vo_>W$Z1fb%htBfko@BHZoZNxhkI0~sA13Xs7X=V-r`ZmqJ`|UOzXS#FIvPdyqi*4 z-)(r&qBi_>h}30Uw+Tg~ZTLL1q&?lH6fJH~U^?AxX3=}>B_6$1w2Zxr>6dQHiYC|> zJo>0;c{@6vQu(9XXGJU9$sT=Ow1%C|WOV<&Xl;ACM?V)$wAV2e>Hb&IhW2%)lHJ{6 z$@Z>2lxE59*L_Xw7xog(uN7IWnJvBuP|0E~?Y$mVE|zLf*%y%2E7s9o`Xy1d?xpoK zJ7hmmB2YJb2vd{pt%`NGYky6$PTji{>uq=QXkfAa_7IOo6dP!#AEA%~yFXRzVSCq6 zqRj3yiw(2EnBI4kMl#_Z{BkkMqfK!~i;eaOzfY8DZ}=8dp)q8veO?ldXU+7n_H~ak zl<{`^V=_OGohvrp9wdp{`~-U_$)L@@6E?vfLu6m-o+BpMPcmsea)BmGqW0Mws3csEDN)bZ#fa?6J$%+Pc1fnB z9$`S`m~h4k-~M948K>V)WWsY@lkH?CJi{~DZpnmacqZHJnNoUOG^g0zn0ofO4D=Wi z&Uc@+$1~x4_gOnz5}o0hYENgvGdxr6mpSB+9y`P|dmht-9{E5UCDHEBbbAXE?*7cM zw@D&=lyesrmvt@f^x%J-yI=P?Fy+)iWe&q1~0KMo(8?Xs0tJ_Z;L~ zXpdxiu;(GM$R5Ykr{__iNle2)_O?BZ=_!!CZO>wQ9%PH{xlC_>Y_a_|({hl#V=rU+ z7-a9*IYe?SUt(YJC_HM3{pycc25L+1+HXmcYx}5o?WK~k#Fsrw0ZllMA+yBMo@Jw! z+9xH^{N)4tCy%b#%k9gO@}NZ;&PrSSgz@s^{AHD`NusCKt8DmG2FSLm__TVpU6~1= zR!dbQp3X9|hWNpkF2lBnK4vfqBDL zg*MsWFomYpjM`*>&xEIFHrqck;VGKU_9Z5K*1E;M&V*~&Ew*t1HKR4&$95qmZ1W%6 z#h9?iePWkn!XEdDU5=@Guk9gQ?P^Sodew{CY9|uO8rx>K^e8!Mo4wAXjEFq@fs2?s z)!%1!8%bDy=@FmVog|T!KC^58f+1-Q`?7QqN;{36GwMI%a1|BF&E56G;Y|eJPIHQ;1;C zV|vta`)#InmMD;KC7 z6P~pA!LG)HCoO)k6PfU&#W_2f2~S#_vs*F!*sElbAMN%`mwKHm{G;8S=|-;|;=J9T z$?csF^axW_?;YYN`!S|?ko{y&Ad*)4mz^z%#*ly6dztWyC_mfBDWvG!dvny!_UAXq z@*!nDkGg1oEs5;;i+zk`=SuI5`o%s&By;%1w*L&&$^nqo_NbKctKE|bEdO29WqU4D zyK+B7U9nGiAv2V#w)$5fl`BzK?W&R}_iJ_?l0j|$6?M%{mP94GW-nvH5?!}*Ib=u~ zBl^0%oeB5(ZrBHyR`(8x{?k511ZD8U--lh4L~U1dqJ@fWSAMz7aFU7S_p>agB@=!> z%W~RF!f`1>v7K~}BBO0*yhry$`<&-Jx@;A47D=M=g*r<~2IaeGg*s~_kuISQ{A0YQ zOJPS-ko@-Ny?s`=<6}D9I}9k22<|`$(GkuRBB@!FGsmN&BFe%4CWll&Rx>)~O5(@{oxR&`#GM0!?t z-jU?DYxNna*L0RMHR-d*tm&*{YTpOGrtEByL@le9BMeOQw1d0SwVftR*v{%W-6Z+# zzK~`eC!J*SY+4;>u1C%Ey3Temd5p>I>$93Tvq%!vSX0M#QBS&CG*jpG zgs1I#IG-`$X}ey|1&)WiF}=>}ltlJScdkmJ9x%u$5+O?jWvCi9*h%nc zh5e{g-J@~Q!=2WWsJ)DEI*<(7OIGv>j zN^^{JmSm9TrN}YP1tJ@t3XO5Dvn;LeJ?a=ICX(tQt?zTunNB>@i=AGM9_#dF>ect< z=yA>rBK!9~Ta59}J50m-z7sv(SM&gV?{Re~p+FPQMF z1W!0;iJ*LIqMvlGOQP@oWI5f72CTb2`f2A;k3Nm|JJ}v(DAS#HJ=z~K-Pt3F>@vgo znq**?{E!*WaY4Rd1nQY-1VF3Bu7b^+~=F+EMdYut2xe=Xp~XUndkf> z$#3uOnh5&XsCJ+kn1w zB5M*I?AJ2pYiDpRB&wC8&SFWlemLrUz=Z3Eqt05UsQx+PTW2#T!8QAl&m~+lxNo3D+&YP0Rp68t-M6%WW z%V}D-pbQtCE|O@xzUZWTbW~h)HhMHR<`*YV66OA@lTR|p{cz;3&H+i3`>)P&)p>npDaJ67jiFnad(Npzm5wA=W8Oq0$Nm2q21@{3Ys;Xg>+{vOSZ zDdSFH>e7E<%)Rb9rXE1??j@$aKnZU3hNS1f{u5)$x|vKFK;_)+OvC#3bjrKi8&Sv! z{ZrHm?x-e2&x5RzJL&&R2HOCyNMb>faN}`sP=#G{|bJ|4rNsq4C z_1q~G5Arjd2JTEEIZH@#XEEWrG0C0FgzLs6cO?_98}D~NV#0Of{cb*yz}ZDZ_c{~K zE|Oinh165dE*iT8=R**E&5 zELl>XoQbz^*R(@+c?>=^L zJ5WfdP573cJIJF1yOTTKqt9cyxGzhhy6x)DBN^CwZ%kMBZAqj{SNE_a(xscLwIM6v zeq9f@G869C^>NcvNQV1$1Kg;#NL06j+&GV}*$=rDCD9Do&vf$b@zKh}(k+>-G_MIFYpO5OJ?7StMCBXp zrb?nQ`Ej>15qtqRCj4=C0Mk>Q_L!OOB##F9#=5hZ@N1dlT&-iE?C_r%ZmdV8j0tWP zkB-Dlbeni|D&`rtt0dCQ?>;GsG@Ifsp^$dd0dU6JeW;Vn0nQyR(WknZ9xcAG@f5~PH=7AhVa#-AFs(A_^(n z*~{)$k1oZ`b`N=^$If*xcoY%)mis`LfL%(*E_OS6R5kWJccLU}k?*@xNCqwPzS#HO z7bKBg-ghrbBD*YeD|W>+=?&lIZcip`k*nRKO!$?*weEE$Y@h4gvfaoo_!XJ;ZdE3n z#jbbjFySnAy_?E}`-&Uf&P=$kxWVnsgnNe@-9b#acev3V#)PxHP444NILq7QPGnjQ zwYk}y!n9=o>|?q!nQruI9J|GRmC5bh0%!pfeoy>k_dO>3p7_V^Y9{T{3h2{cNY_WlWVK{71M6eWt)4H=@jU)%{@yb?+>542fGLAuWjt7?vp)`sK)YK zza*Sv_VwktFG!*q%X1g?lyxM}L2P%2_mZi|InfTcU0D2AloangO7 z346yW_Zdkzh8z{A-Pb%?8hgh5z@wD#^X?XpR@fKZy&ioO`>XpekG92Lb}vgJTVHYi zA{p3vXY3W%8j8A*t*^NENTS|x)vYZF*IXIOb@zlM8r`nDKYMgI_PQHBEMURQ=3j1- zM`vS&Z-qy{#%jLJ9^HsFe0x1|i`%~R;ek}5i--6|dQ_@-A>Z>Jl`9_Rd()$8#S8lq zMg-y|77zE;_NYnmNT1)M)Z$UTk3H&AJjS=jqh7^hefG#eDg%p`@b&a4)+*(j{TRx~ zf^ok2lCZT#T5-N5lCs1f>7|Ot`AUq!kYvv?zQ{31w8s+ftN*ynLB5ew*4Kndo`v(Z zVG131(Jbfd$W(RUWuTr+Z3m7lUf!3^ls2#n(4$P15;BWd@Qr2)O??vRNhTb7D*C1~ z;n-8r_dXMz52@r^&4lMeD)}}r;kUyo`?fLRx5Fy?b~E9(!>ahcV#05SRq=hx)PG=( zsOmE_skGw;!WX)Hp-htp!WX)HQB1QyR?Sz6=`D~|^Oa}%0A$sD)tNSfth%or5&Zkl zGsSE8ntC*&cun8*v6$Z^@y)#Ny6SyIij(zl}Dc!f57*I zBx*fPeb0~#TF>6%O?{EmArWX3R;h(8*iA$;7n&zYoj5`HfO}q@QF6M)4h-Kiy{~d#St5gw`BgIBq;OZg;TtjpL*A)H1g@1wuR~19$HO0kP!QpRCKRB=8 zYwFj*KEc=PhGAah2KzT3j{XZq{Jj*xVaNhhYin-_c{}?=j>K{m2RER98MxMD3)DsB zJNO&oK9HIMQ&2=h>E4=JGw|0$TPY=N3w(5$g7I%sKx=CPW9c`g^LPKd)93H80;T@D z|J|jA*49KX1XL)YPtp%3L=OkR^) zBIvr=AWXjnxG+{oe~MKWu2oS<`UGE7|D7lO7f5%pbeDmviVx*=aGC|zn%MX^sV27m zqmO=@kh=I(hQE6~Nn6tMCm9#DRRvua=&Xs~r1XZA{w1$zbPe`_KSPDMCb*jLfvbx! zaH0Q#Yl>KK74h%GSX>IS^W9kc*11qgnHQCXu5S$!>{Cz+3j7~EmI7;B6XhWtT~v~( z1^ZY1M;~1zg1;de-6AbW#}F9Tlp!q+dFL|XSgp#tttK9pDP#Qxd{C;hKlU9}pbv&r z!GAQkhQR-<3*4`%)+k2|PyPYvS{V|@D-~u7FxwEH$aHqdbiN2m2gBfu0&~GIhQKhU zpfHre*AQM4$HCR*48#yW$P_4dYVG7wyG7kp?vL0jRnh)&)UX%0su%*UCheez37$_t z^RBSA)Wp-UTGGWda1AjFTvN=GDcov9vejZK4Q>e^$do^n{&c-A==$ILD}rKe_F@G_ z7#e4&T$JNJ8K$6J-9BWnhLjH35PPD^qeO6+ySY9kbH8)jBP&s>E4bE#m5KF2ajEXe z4X(An+gumPG8WD2Ff~oKRcyUjUsSHa5JnY`f~$#4aCL!t8X^m>O)&*rOUwjU5fpNs zye3U3wrSUCz^td6dO82SYxCQo91zK2>tt-%ygY6l79bDeK zvBRyp;aVV&3tf{NTt`Pi9}1(2GxD0;U*TF6G;RlL6?`3>&i}iv$yQ_yT%{`VP7xT@ zvHfTwd@TA0*8=uLT@;u8pTM;$$_8Cm^saA?g&}oO7o>)`A6!#31=r%cXK?xy62ln( zAUzBB?%+Bi9bESx;*#dWK#FC=_J2R@s%avNeb9fZcU^Ed|0fFs zuR1k>|G=tx-h|dBA1oKmg@RpGY?uCb9_y$D2Di`P zYqIkfkd7v;r^~ts)Hsc?|IgcSL3uSf@uoiCa zBRF%@MQM;4q9V8^w_(y8{R6YmTlEa~x%1uXKhqZ5hEM7oB5H#sg+x7YLwQ{moaXIH zL0ZvW>2@o=cD>OiWF#=mGpMkv|}~^ zQdYU{hR9s7)j=NzR}<5~M;HI>AIOWOlvhEE)kT}}s84Wee^2M;zD6zo&i1)`Yv3MH z@H|=Nop7p6>U{+k3zUUyLjE-WTno>sa5aImjv^BZ=AX15LN1lP#DoI-mxF6f;J-fy zQm!q1@L!&9_0dH;&p#l&Qwo9b!L=WJO*6wDGROYl(%e`P56fKcY~fp_WUB&;1y+>* z*$n5_bg+Hu;>G_+w_CLh_6gQJ>_D{&4 z=7e`YUfs?pJxxmRY&y)sLDBFhpy zyTdTSb2*d41X~8f>#{a)P7SSUvwdh*fNtQPLM@6`vg8)*Uf#`4X5c;*JYEH_K!fLp z`(;UKrbpxa|IPI&tu(Q`H?KW|M~pkKvuNa@7D8?H)|CjZN;J857qH$@S(_9$c&&Fv z`Ul_pg0F+M3cjW}z@5i|;P7{UT~N9}e?%YZgSw#A9JRMQ`=6I>^_nc*-^1U$3cz%3 z^`RM^_K!K@OvZewAlBd0*F`Ci8X{hX36|1o7uUkH+BJDa790l47`SJVHG=Ca__-cQ zaYe7mwY<(dd;jeJ@1A@W?3SqV8IX3)>`3d>veNTqWspt$Opm z0j~4|cX`V9cKwLTj%fzQ?OSaaocryrD?;6=qNc1tyjDbG>9&;a>)@*5O>i}__#b_A z@gDdaVmY{`$oX#!V~LG2wOeZ>*#4w#V>qp&h}XeIZE+s{PukuZ23z=h5FYi%z5V|Q z{r_&m|2d1H1#YgdTk{H7^?x@c)|V>lOOy4bLw#W_U|pE9E-bE#y9=qpJ(pU`-G#?? z{`p<&@ZTLWSX9K4~)KlO|IPhA@^~#n^Hczbl;uU_Cf71+FUIm)F$Ju`D!i53BriI!hwq8~I3Hob7$wHm+e1gH}9MB)`z2JZI z`G-5_b!*+x8j#uvN^hP$q7Tl6@SYxgN+Gz{1Yh4xj|`90phP zaQ_AUHM#4h$Y;>x2K=%1b@89oK8=vKYXf(`Ho2R!Yz938r*jLg=~-LwZj2&Gig!It z-tTnz?7-mXU;n$KN^tE2U(@a@j+~nKN!G|EaPOu+2JXVtA93}nifb}1j!rjAZ}p+@ z+S8bCD7dhCE8hY4Ho|I*I17sg z9Xz+ZT`s{h3Y^~t<}ktj1#|L1>4H}ZluK}U92o-7#mH`V){{oaJ<_&cf*V+W75FH8 zUI;_pynl;5BA`{E?h1S`_rU3z+gaewx&=$={MFsh(}Kr@q)FIwaaLxE#&8`N@o4sl zAp^VjXuW@0_0V`5Y-gIqp}!$lNr841JclR!3*Oz(L=TxexwqcsgUcIyO=%8>xPg;e zcpb=bl$>LX1s6`Jf(s{9!BzN77uk(cqZ}!*k2RVgX%H3#&5m8ods^qy`TmI`3ASZw-QjdJKKbI#e>hw z{a2sPP#ICTe>Vc$djGxiefG}nfuxi>ooQSrEsQ>awsEU%@u_9-Y=`FRff;-7NJ1y` z{~lhKXTXA={RJ$4yIQ-o-QI3qO=ZFG|CRMDmGSOJOUxy(-*W3%hii6SuGtN_mN(^E z{+~`Z7L1BFkFml2R3h}beVAbT1joJA|1+rHz;h)W;VqF5KDO8ot|Pty*A>UW4cw>b zB>(^6?LFYDEYH93`+3ev5HyGjP1qnHLxw=u*@+TB5|H2shvbkPa*`9yNq~R|2&hrC z;%IAK;Kor!?Z9dkM=i!ttG42vRUB>Y{Ml;ze!tg!KjS2{@B98g@8^%^dtLW+U-#bY zIUjB1EJg3JIPu}^<#2N5%t!D+>xXccm}3OTl+1Usy5G}x01lsHmh6iBzu5iwf7Lho z`wD&c%#-kS2Ggk9ls=)>`&6Eezn62yi~nT%zu%kEJ~(?^>^*Gd-Sp0Eq1u*VIqQz6 zq}OGCf}J-(-2+g^GIL$6^A9OIjrKO$5^dE>_@f2&YWl=(d_WC{B&bGfO$kM}wg1%8 z|5H!v?}c;?{QtApWr$9HsB=vB!%VeP;{Pc{{x6k}l6yOYmM# zTosEg(KeFPMMCsTY_-ZKC+~!-clO%ER8aO>UyPJd3?a!E!TaN9?^7IUN7Xd${A}|7BkiysrsvZOjxUq6_Sk-z@xIOy=dlkk_T68P&6n^ycK@Yi1rkiR@N2z0Rg<*6Z{Ltr}$ zbQtIe`RlJvRwt^Fkd1_S6zFKsF`#2W$AOLm9S=GlbOPuE&`F?^@pl^jrpjL)=qQyB zJ|Fh;LFa=m1YHQa2yt74xGjRYO8)XxHROxsufM8+tOoqq_&XONoCkUyWVP~_rwV>Yx{hs{gsp~+mgY0_H>p^b>y%F?g_;oYf-VF0D z`O8zcKz=LuTS0Hb-yQh76XrWX?*hFG^d8WAK<|~m{_2PD>kW%Dao*@Arq`vV_QgM}X@I6*L9ut2av@JzuP!6@)I zC#?p)6z%}7vbNagHEzn?V%Gz!6~8ZDt@!(vhZJqk5lN@Ly79+qC-fgt*9qLRq$s25)y6O?N z&z`YrQr>=5xT-pDAJdq(Tb%)&YPEb-YhIgbS+y0&@BZ|bw9hm-@bap!!e85eU-gH) zJ?e<2f5PqG@LP?0B-Po0&LneQiogEk9 zfR~~3;DAoMIRB9WeFOBfZ$O8I-#j~UKg#h5=xl5HuKl&TqUojZ*Xjp?zb<_#d=9=3 z`|N-Tfjdw`I_<~$=h*M7{Y`J6tY2(;MD-0Yww-qFuoi?)KRfNp{4Wp+W_nS2UZIvq)vXNP8mLV;8!Y~NCm%E{eU~w4TDZbx>AWp)Ys~Q1Y>oD z;7y`)H*miy&cE{n%ldg@!@%9vH6xFR?6yXuq*z9qA-QSfQIMR5QaAujrv0iR7Y(#5 z#{Yo&6~3{5K>ZDPP;#;YrSq13P<@#CIcL#0}%`KvNP<1u0vN}c5DUzM=?VEwSMbg)zpZx^~ z1CJauO0W~3tbr^0$dOgtV=E&bTGhv<9&(wp#bA{C{Q_L-g5rK{bfg<={uO zUJIPi`UAvg2IT#N(bl)s;NXVV`v>i_FKIofMg^H~=Oa&E3ZIV}^~|92Ro~SwKr?SO z+DLHh>bEh56s-OYB&V-V1@nU|h9aMX%T^y$1;O;{w+0miHwbPO+#z@^uv6W*`UAxO zp4IFh*kf#y9%GyI7&Aq(LnJ#yQh}JftL4i-%q{C2CDd4-Q7H zSI)VAN+&cQhGc6xI+fTk^^m1hXp>{o9S&4a-c z@x`=*!Io9Mg1OS(b0y~Qi_eFGeb;WE_LcCt`1L2 ziL7-U`2Dlv>`v>z+Wvipi9gwa*Vq0PJ@8wC?*WHND8nRf!z6BSaXJFL&cI_4U%%!XIcOvKWPS|PnT^Ee(v_`DEF2B>7vaWxhG2+h{N&CH$qA}v< zy^;fCBo1RF#4!@{F%t89YyP^I^R3WlgI~_ix6WGkc_iPeUH9AkeKtq=sKwruxs6|= zM9;%9g8dc74&m8r?X#bpJY;${eCQQ?S!zY!kjxDN$9HhV8Q<~O?0joo#}B4w2X=$c z4%`XckI{jn412km67!i7+nEy2Vv!V!q*zk)sHEsoNlUS$g1zOg8O5SMSXHd=70kD4 z)-#?QzxE&|1N$M|^{eocw%-BfTlcL0`HXz)!}ZSqdvACic-n?nX5=Hbt1PzV-$Alv z!{2~6ZTNOZwOV-cL({4y4y%Jd+%R)yzV*ejP%-U&j7LjjlJHKewelyzMaQ>>iPV2VwS-$rP{zULe!7jm9 z1wRn{i=ef!e;?-Ld$Vdn7j6vAu8};i30<`jZ8mhb;GD9T!klRwG5hNvk?p15?EM(8 zt9u=g7#^_R*|;k2fc5D{j4w#(Na#E{dHn4C7JsvAzcuoLgKEDu;esCnrwf({?&@DY zd$-ige5>(-b7tpTYc5zZd$r`=>d?*$)RFr!ig9#njjzh_eCzHD;?S%+{d>T> zFW4>o8;H-Y{=qqn$w|OZHx8RKPs(wgpWS!UfjNwA&fFU4 zoE0RdbBO4##MMFT%uN^>t!0Asf(gNP!Oen~3GV9OyKi>j$jwjoJ!IcL1S7tr<&a%e zbwTz%o4)~$UTgCj_{RAgB{$E_x31cJRAi@UUI%;|>lc=Lb|ARr!|c6QuPw6+_F6}8 zDJ{qj4Bf(dUb}^DD!!!%^`U*sC9vHB$zJP)Vbytit?zC59c*`Rd948Xv*lgbKD33k z<(Vz%WAd$+wj5Q+R(X8kPU|NZHWlx*o&>&caaPPYysh51{y6vw?E`eWQ3^Xz_XP7w--Iaqy?b`$H#{d|7z|7E z%CEgJ{&fQwLt@$1RTk^aF|+ns*GyV5`y-@uV84%4)z;HWK2m3Gol$a*r2QOep(-uxl!q4SDNmr2PD1Op?kLWElr3dA>n=_;eI3GCZuO$OKdCMYdu)Ap)}vRD7qcEuH&&%&ao$# z<>IT~(XxE&_gmMM4HF-N7U$SOi(|ns=@o}b4}UOp;kH0I>)x&zaS1W5zQ1i~`JoWM z8~#;@rEn<3QQ%N$Q#Ixl$lGU%4~3W_w!5+A`|Q`ZwUi%Fh4Fpm`&I6+GlHGgKel~Z z-f8vT{%_#Xf+q+L5G;@9RD6y2W8P>D+kPVW@!JQB1Tzrp%ra|vh538Loiab~ zlzF=)wwBn^hZPllu*21gbCoQ0KK^=RUXrEGv7QZNspZ!5z zmTI-;0?!xRA-D_IKC{$E;_6dz^#xpIsXtmThqBZO_PgOMwbZ6gqhOohE}Q=JxJ@Vy}ASs}{Tg~&fF{0U*kFgMH?4hl1@VPS?fGF;dvON|Ma0Z$Fj15OT~ z37jeVb49;c^vgwmp6D+W{c6!aM>LmJ z?Vv2?_As&CC3r$MH3ta}6TDaOkH9|aFWDP%`l$cO-Uj?8`*NV_^<7}F*UdouG77MF zuf4#WUXK8e5j>&SQ{Z!ZJr5kz>owr8Uhm`_sYdqtBnPF|iy@W^E);AN+$^|5@CLzM zy%_(yg#VS`r-EMy4m*PWoO%RxW(q%7aG^-<68@KhBYRVGOmAv#>&<+)q&M?nM{m}; zD|@p>UDKO2>S3|{sn|X$woi!dd*b#}!M_NqKJ+tJuv&0wANqfe@Z0*lc|w+YRQO*B zz9*P%dV;sh>qw3?_X_Y5Gv4QOsSDe`TeaKO{(|lq^B5pk$PU_XBhh`BR|{Fv^r7rH>jaP zx2iEh`x*P8>XwQM_}3MAb_glsOUihVGQMJt6bw0C^q!tbN_$eqGY(33q?D6(MRp7& zrF)S_jvBg3p_kGgX40<6nn|Q|zXz21q_ihx zxTIZ?V}^+w`FyvSe?5tmdZcuJK;-WYBc)tuWSN-h56$%dIipWXJyQ5T`4G*Kk;8>T zPD*#AbVu41xqbL&LeH8^%5X{PPqwA?NF6itfoA$c+7Uqo`MwdP z)F)-Qq)$aAiJbbQMep0mq;yA0d48=x$?noIPX;&nFBq{Yp9(nZSODTswDc$W6it+`eds6C? zc11oKDfW?uk#~!^^fXeYla%2+1v)8f{gea7OxhLcKZ=z8kCa~(fAus{x+A4O*|ts>=_~5qTvDd57bxvXsZZJ!88~GW zDD_CGN6LJu0A;*MyCUBiMM`(144?Fs2+GOGNvTgtds4@~EAsrPP9rC!9x44Jr5QtFXXj}+}<^dTcBr9LV3Nne3JX;z1q;x;Z z$VnYD-O)@v(ymC;*a~A$N`FYHM@l`?uET`r zFDdm%srM8p^YehQC+&(X8AnS0NvTgt{X?Mihm`iDU6HNhNU29kz3h;-C+&(nJ&siJ z2b6j=Q*RWgXA~9lzJ6nKVv*8^+~BmO1-!-lhU5FE3#=kDeXJO{PcKI z+LO{fsbl|UXA~9lzIome#)t&^pBK!q|_s&-XUX8+7(HjN=iLa z>XA|}JFMlT^pCVFa@VP(jy?5988c~D)mA_xOZ8pp=t3a=N4W^T>k}4v3yLk(6>$>XWiON$KuG zP{#8RDEn(t_T!||k4LooQJ_*^K)WL46KR(8g3{ljUfQ3hdTaWjp_t%{Kcw`Zl>Xm( zl-3)Xqv@@NerRZ*ua*an*0j#hr;gR;4?+Klm0sXDO@|s9AFbm{+7(g7q>P`K4Q0HS zXItuw?B@fU4SmAU_Y57>OWV&ibh)9M4SmAU_Y56$gwZ$DR_6wPHpNzZ1w$e7+XcT4 zlRq~?+#>jx;KzaovM4_`oA_lf(K&+nf?!^6@*fMf_aXn9;MYfzKX4SWIY;Dz-wF;t znvydG_w^(HvEZ@CkgpN!6wE%BlEH$D1#c95Td?nOqAz%@-~qv}1cx6_+r5H2Payx5 z;FkX6UlY9XMDouFekquD5+&COel2)xE+rcUUlyE@N6BKrz5~d|1$PR*EcmTp`h8@k8P`{3I` z@DHkOxjS-q=3bZkqufVxzsx-*Z*bm-y!^and6(qv&ihf`&+>kqcQEg>JbOUz0aFGn z9MCl2g#qsm`163^z}^Fg3>-0V`oJ>=E*{uC@H+#a82Gz^UkwZlnmy>;LFW&;WzZLc zz8+)`&Ki8=;7Nn$4USHUPf1VNHs!i0d!{r`O-;RG>UC3ZntJQhA5T3n^~I@gO$|@W znKp3R_-V7JT|VvVY1d7AWZDzc!uiMN&(1$9|APEW@^8+6F#qTI&*#6B|4IIr`Msv+ zOh0b=sOd%1E2b}2$$KRNxt^f#x!KmF6`Urzt)^lzs3n{oV%+!+-! z&YICMqj|=L8CT7?W5)e6J_`S6#v3zw%^W$ibmqL7n`hoQ^TC2#Fw`P7Y^P8E| zX3d+mc-DqlSI)YA*8Q`dnf3XsuV$S%d&=zU*&Va@&VFU~C$s-FyU(04b0*BmpEGAp z`JCl*;&YO7HqW_s&MkB9nzMJ#zB!N2d2!AMa}LexcxU1M!az}O(U78%MdOMl7fmmkTU1&!uc*4{+@i*!ONuTp zdZFm6qEzt}#SaueSN!+lP{~mx14;@@E-$&h-bI@KoYQnlH-LT$0GR2N!1)y3A;YKL`= z`i}Kob*1$^b(M9Uy4Jd0{lL0e-C*rfH(Ix-o2*;aE!J)7R_hLRhjpjA)4EITvF=q5 zTR&7!SP!TtaX;#5MEDEr`@wGs{s_2az|Vjy1lt5J7Q9yQR>21Ze=hjE;5&k!3;vH_uYvSuPVdKo zxx!BpEE22|j17DmwyTA|Q1EKOI|TO$K0WZ4(0NVp6Vd;Z;J1QVgXlv)!GVIO3}U!b z2fYX^7hEdxxX3pO-emn6wwDV3`SHI6pEG0xX6-pc#sVK1LLZ(M95$5vsY4k`zTl&R z`vrgDlRqb#Q|yhH%?=N21->whZhtHIhd?JJUkJZ+`19b;9nKgo9npkYUaeq*;CjIe zN6_t#5lPryE0{B6J@}j6jy6zLrMCh#mIFHT~*-WFUs{2$rK z$w>_5PlDeH1}9T;gy6A)LnhPJ2*J^UlLcoBmI*GHta>R`BUmSrwSt$44_6CbFStkW zCxTB-W-c9=%(T29lGnu5JA$7~4#Uqk?cPA0lV46|9{x=%oHq}%N$rJIIn;@OA1(mv4Y`P5w!}xx!@G= z-zk^?yt!a1@WnE^>KRH;|KBWQSSOWG|D&?c;P&@r^xrBcj-JX8e{?!)&ZDO@MNbJn zFZlZDbi1Iu7uIAt=lwaRQ~i!;ettUr`KRa~aRy!K_VP`j0&aEd@Yj5QtsY^AFcIiA zpE1mt&p4bopFZfi6bc^!+kJt)z&*j^fn)4Epss;KMPK{>z)Y?gr}^CKI6tv~em*Do zs^Hs#p9=n6P}g4VPh}NjQe8z?uPz*g_2qJrtP*@+CiCj|Rm49Del41TYU+Oz*aUrl zE?r;EeAd0+ZKC7!kgO*khHCq{X_3BB$K<`>Zpi&T+lfnPSNLGmC8tX=^izC5XfU81x0ly0U5U7F=1N&Kz z0ME7`2mZ}^1~@<11-yJ2eY;WcKEcNXj|jXB+vkLTW!Z1RPm+}0bvEOybHiU(A3nQ# zTX^DZDSh8K^8DFjjz>>^4%_LU&S7rC&aVbU53Ku9LcM_;au3T(-xY zA=kstYtCgV{IzlSxh&;7&Se}XoYy@jIYYjJD_v^39QBy{<#|kEOJEahFb^x3a@ zkI3&Wq~>11y99qCIBYrPetkXiYCm;txvTI-OpUKt{uN@(MYvYHZ87De@sedf?*Y<(+)W750 ztURCN80$dq(T|+l75a@$#{+zoF?ecx2y0OI@G=%>G+(&m#--`Jk9XkOx%=@)X{@X5lqN7?Lnv z+4Acg5y;yh&BDuwEJz|M8@5@%9JK}mbrx1Ny&&m@-&L?7Jp%G|xI2=i)&gyq`@pt0 zFb6*&aU|p&K(0lOf^8pQ4sM&|K)wNJ;jb^`M*(y2&f;juHv;iO1}hdD(teO{#>yoN zYms9h>4zN*3*51gUx?LA7H+K^2gz~jc-S5b%u(Ca36O6E+A#Nr?FqmvwH+(79CZ=U zhWRA$mtYN)r7i|qFy}#jA}|N9IR-%93AA7y2sv(oLcRm*q%3tA5Wg^r^^y&Z!H`^H z4S{VZ(1zVm*bW9}sVTu>kWU5LSXm8+d?*liD1sv(&j(sCpA6e!z#R2bXe4Z31mgE; za4Kyb(8AwX@S}kiR%YYDkHxCY!U}By`0-esS?W}v4fAQ>Ckjr+YR!g} zcp6r1mYO0s4XZaB(ixCU$6C>bbQbuTSTov?5@)FbNM-}^g*#OQelF04xdeQnU@_K~ zHl$^cl&T8wC4yz@3`oj>Hq4daPY2pCF91JJaK1Vdl1jk^crC;onJP%m#46gxit;RA z71pX2Zs65`UyN5nmRcgX6t9PDXq*elGQ1wbP9D%w=cp+7vjxvpb ~v|$$mAH_=7 zR?C4Fq;c>o1naT#wV=@i$x5^&3mR-sakL)1YC~JG@P;N0zDe+Lv<6E(0Yu%l)&h^j zYSmUJV7-buh7~JH2kTV}E8Z>O#{n&@e7Ax>Rj?4NSA3~oumr1ETNMkIVkL_g&OjTh z;LE^Q0Bx*>F9%jy-+^Sl;6ki%ZM6VssYO`pBHw_>E9+YDRf3DL?nRCPkylv%B6U~+ z+p5935tzbC*v5K#H?R#WVOzCZw*%K;C2V6|y$86_x(9fHbsz8=>we(1SQFdoyVgVS z`FlVctLYzszftgJ>nD)hB)H4k2l;NGjTQFKz~5~>27V9FQukVqgTF`cKHTZW@8JnP zU_Ax-{Xk1SXgvddui!)0vyeP2_+#q;QJ`A+*&gx6>SwKr2 zVgCVqFTvjSSK#~De+C|D{}tHR{yTK~;YAF-11orp{ZH`6+TTKc9MD#y?0^#Vq0?{^YJZ@3T1kbStLvps@x%N=-=h?%7wf4!- zSq`*S)E)(Xgjc-^1(0+A@r#mn5%>*)8|@NEE&$qU zlU)XWGY}^mb_Mtgfq0*6p8-L zoJH6%@V@}s>RG!1{4WKcv*VB)5bUy>Ab(!)MY|dD7X)9jlaT)kXseg))xcldX-HnR z+rhsg_?o>IlHUMr^;^3G{HOK?@Sg}CvNuBVncx@pCdfY*{2zM@ zfuBHrzTgFceUNMv+!Xj3E)aqI6Tw4)Y{)+aVk`(A0X{6)H`oXKkl<0kp~1ee9R@_r4E6&*0*E+p}^CF!+~c6PX^8l zj)Lv{;3?oM1s4RzLb6bBQE)uuX9`vYCqP~;xFk3U^2I<)tqq5IGUK-i}NvGgt zp^cF50NU#E&?fL#2woZ50?Bs-cZRk?eiaaHJhUDBHG;cC7elfOXsKI6o#1Z~yd!iO zBzFq#30)5PU4r{U-vR$vXeVrcF8D;~YDgXjqJ4#~1^+9-Ux&U2{*};mz*j@p178c> z2>eaxX5eo_yMeEVZUr6;-41*sbSHdx6KJcqLVLi!E%!jKLvgY5G$teGvKEI(aOTl0*k{3fFaE(pH{$$Y_@@NdCK!v|rz0*Evz;eSKE2Z(t~*a}$c zAs~K*I*e{n{W2Va=hXdJSs92m=hTe{l0?z zA}2#~wBRw3QIH=C#5z543i#oICr8FYGD2`_)CGv|40G&9fIGD6oJ1!QUbguQU<&? zQURU&1n-ZW0m%;qpNLd~e>$=Nw$BJY8#xn_UkJV)sRDm6vKY2+0P#C;k+Zu$S}~U>@dp0qh5@0}jHRDxe0d8-PPFC&4dc zs9yp{sNVxes`G*Y?CG=u$Eb5c_y)Fm1UO#32b`d?!U62moCutZ-YJ0nngnnv-U$V; zJM%~2e6=PLz%I!62Sh*sldf*J+MZ73OrA}njOG?#}~lmct;XYE7S;Jy_yYN zsg?s9)TO{ibsI3QehF++p8}heeMA8JhBJYy)p@|Q+5v1=zXo=w*}VhUzgr00sBQyp zQXc`gsDA*rtI>S|*jbwiycDlA@I_433cOO?0^F${241UzM+WfilN{jp)HL9AY6b9m zbrtYNbsO+z^(1hY`WNt4Rd`fD-Kll~?^5po?@>qR1n^~(xxgQ)tAG!v8*(b}EtBu( zlmLH_QwIEQP7&~?oHKyCa?XU#Ejg9=w#glk?^Sm}bFaD^ntRo~aJyIi5Sn|{1JK;7 z9)xCl>IW%)i>E)zawN)UD)zt1ko!xJyDM=I;ITo22ag{7%G7z&7Eil7f9~|o8B=EF z&+K3DtAep5+e(fsJ-PJyvPl)n`nQ!m*upWCWgjmzV2=O=931=b-DUfF$UaaH;asY_9#65m%Ral1GX7(T zA8*GQOhEJfE>dbPTu?q6d;l@wesTzZVf;n#$Nl1L{Pn`$5%}YNa3B0}Z}({Y9g9|T zJlf1aw34A{7sF-Oa|CuYxtlo#yO!gzTR8zclc%X^$m{8-?F*3GXQHMrLESzJe@pSV z3^hE8I$ehv9YcLyg}R$S%}rtlybU#V4eIGy{H;e#JscLn@X|JJN;8cuQMJecbg)1WTfccGqE1dn%nwWrz^x%4B;wmJ#H3Z824ph_|jtMpN~bv9{>Scp_FFOSB>lH3jS9>3Q*Vo02#zjK))i z(R9o+d0bJlxiy-KrD}SLR8?EDu4!SLl1xRosyMbX+MZ~WJkl``tnO%ysf<)1p=)9i zfvQ*n(TyitRE5MvgdWTMQj4PX(UfP4)W;;cPPpP`UUWq)p~|AInkj0GrrMN*Q_&V{ zMycv_;D~r$QDHPC!m7GxB4#2=R#nDZlBu#(yk5;q)+MqiyCZH>0X(y=0`2UTtH zx+YaK(alKDE1j>xgX39R6f z`jS*Ci4b)rGYOJAk~}4BX)@IubsK_+s^e{m%vvsmQ5~;SjCM3tkVYKiEzyMb%xTOe z>*`{yQc_D95|x{j6E>(RB(;>8s}`ZD##-vh$Vp3PAf~COFxy3Q+0R(j>i`*Ih|&NZv|aN;YVJ z57VBdP9wsxZdDB})pSw|6YXiw=gCsu;!3wkRbEvn%^D2?{ex~JXv(OM>3AI?813+q zS=E7_p?Ta{@s|4J+VnU!iL_drj-{LtsX1MjOeNwg(DtdRqyXyBpA@6dY+zk4X=!g( zNHTg*qcqNoYkFK+tR_zP@ZSm&VxGJbc6Y=%B$E$FS zRIPA&PWT{wxKxpfVswQ*M@7*@Vg-w&ptUs-*IlRAGL0YppndUVPiXR2dMOt2qF6ea zXqRSPt822!l`8bY%806(5$YmFTFDq$*xuHbY)PwzSX(VUam?v%=5F>ARX2r+>Wo;2 z=MB2O_{w-JB|=9vL+E(u7ka*CN~w#^z#liCG1FH2;aN|Vq`~a>Qexj-X8iH%xt?VT zsmW2+A0fZlvG==@AgPogq^2Iu{eERiJe>@u%vG(JA@;OUtuO@juw-ZN56o|-W12G@ zF`ynoYWl`$>iCSb^}29cdM4UcqzllB3KH>XTJptj*7jA6$+gn%rTsWs-KCzcZyM-V z&Jb(uk`}h9a+xJDW)*3_#ILiYhfYrk+l+@@dtiZV=R{Fq322c zy5*?KCLc{&DDZ16>8>FHt-(z7O@@s}-KBor){aU{(lJzL=z7ws=$aVDs8}(2$Yg^= zq??HO(@mrUSeU|)c1A4LT9C#hsZIA(IyVn%<#WXe;6g7_qVCFkdNP(3V1)5`>&moV zL3>-$KN--P-KEskTBzN1Iy3xc?H4n$T#Gri(q45FdYVfPr|AIH`q zFAm*A#!)w^7-jhD=FlheyYz{D!=C51htN3gA(!e_oLt-Dx$P!0F1ty^C~lnn8&^T{ z$uo6#ujitRTRk=KekB;ibtNj4rz9r7ng~R3acj58I|9GDBXhm(=7!#Bk>8akEl##$ zDuErNI=!_dG3y~TZhOc%r}6^yOh(@mNc2RrAcZBgvx+yf`&zMPajB|Un=VYf-r|(} zKRbgZa<#i>kcwB`UOs=qljVVLWYPnuEF>UQ)#>i8EixuIb7SyNJxp9Vad_*wrrIv@}_XL>C8DCRAfTsPLv!$_qm!QcV}KY z2EH*68hT98lU~PQbwzsm?HctQ-ZP@8J?ApPb?w}oRJH37O2+V8yH0oD zGOJOw9X^xngVc8PnBc(QZZkL|@y*mA={{ksP0QR$&lc&T`+O}^re|f4F=G~F%mSRv z2rT)z$AwKg!&OFGFa=JjT5O|>l_SWUAB>a2#HW#u|$!DTw6#8^+%1?#tmsMXsvAn&*J zTWU?eEhIYInMGhxwOS0z9>TDuR#BxMeG!z9bL6nqmTJQ;zZgo;6BxDvTf*zK6s?r` z>}g|L(5alTq zhF3>*5^FGKSsGhw?s7&o_EdKzsH{m;_Oy6j)z-dprRnaq2FE|mNmDLOq37matm$#F zW2Rf4tEPBhC3%YNrG^;f?U-kHGOk5+1EIB-B-zZUm6jt5PEMaQ+fllQq&VpX0baZ| zbYUvCCLUYs>@afkP&RW>Au)hqBe10nC5%R0=h&oG1r9i5|1svOD_`g1%XDn8O0UDk zr!R9=buyW#j<+fqARL2l7GKqtf^D5QOo(6t*A#mDRB8w^m&2@=H$5EGF2FVv8;qB+ zMak9<>|hd{(>9u_8&k1py9IL!b=;B9aOL0S z!!o_tm5CNJ)u8e^y&lb!`QCgzcArKb>%m7ZTXCT~9BNMzg0G01$u#KEic@R{*s z?R2)hD)dCC`@F}9-D!_8yYnR^zT2jfZkD=B(!uyzsuuWKGz4BRsW*KxM0&CSk+Xf% zW3Q&B$23Ok${vkjxdY=$YaEt)E1qZ|cXw%9wjq9A<8l zu}|R?j~Qxt=H0R;*@QEef;932Et7}m!n@}wg*Ys3F=`lm4Y!8325M{Jp4%>K(Aztw z=mp)(g*cRHNO1olqzX%ZR_xi7%yCd9%vHSTX98Bf6fy(9B!ePO(rM{Rw9!yQCYCE8Vjs~dUVNhmKIN^83%J?!P(`iYm7BVaZ3eN#DBU~ z(XukhRL7#taAd|6Z}5=((%Vjz#$RnhY2jE6L8hfoc8tl^+6o-V#_P}#l&o%#Cerk) zJeqDS!YGNsOlL5hIo?&I9k*$T;zZn{VR|xxnN%!h9G6OHvb*LQs3}L2o}JI=`VT)` zCq8>~2B>g5Mc)_D(U>H4iusPqBTI0JrnZik8gvj0k)u>r7c?-VT@p{nc~%LQHMTWYU!9Z-AhIg0U9T@U$b8>qk-6N# zsf~NngOM@!ASgF1r6@lW0xdj~wmVFaTJ10vl3ltP9~CW_;kC3akVANdHTqiJ z0adi%3Ic0~-0Hwo$&E?H;gZT6@_Qt%us7R`yjdp~AZpj?L;BhdZR{|{Hr~-;T;zDy zVN6Bjp>BtsA|cpD-Z7|GqDU}GGI)6d6Gmy%x60}S*I#0K>7M5847~xYD@t>8-NH6~ z+*;|e^V^%Dr^VolaPp2VV;*<;#kh&0RWL-w(McpaFpEx0gRCgQ>9}@*qid#!ec@W% zh7tpsyzo`1(%6r~`UMfx%Vy3;^<)VmS+Qt2ObDC(2QS~4xH|DXOdKJS_<3=2W8j1? zb4|T%k}^{j+zm2WES9nl=l1UzHfD3}@RnN29uNJAJ3K6sZEUV4JejO~JmccldM?yl zC(OAb3?R5oB`9^9eW>=U0CHJ6)z+a&Hm!}LE2vHJLK81JiDOqzr|2w<7VYHb6BTLY z8j#WAt)uB$=x*m!Rl7D`-`401N^CCZm&X}8k^M%xv8t_uT|!!udPo*vOGPNwTIedg zV_WIzOy{L)8&c8wI5rS43MF&`*r`bjwIU;~eP^sSM;Sv!7!(@Tl_Eq}44(3{Bngyi zjxtQ3yr5~7Ay^n|VI?KeftpZ+z*p^0h7)YT>8(3e%S(-_b|rclxw6IJWHe_m!cgMg z=%Um$h;?lP)*li{P>CBTq9ZM(9vAO;`Hp)v*deUNkd4t`g}xVrykLcLoBPZ0n<7!?JPfTUOZCXSXJD z(+O$5EY_xP`GJurv3mOA#{GU=rd-_~Da;nWOYfT&N%2%QNPxNwUMkQACEp>1*pZH37!>ega{DS)e?I93JAOMwmxW!OtQ zBBL#g(b02^>ol`cZdy9R2E)*;Tr1W7YgVf=NKBMv#FrzA+L*bI$C##LyhO*q(aqqR z0F>7mj*T33o!x&N%S!OL4a)YzN|#{Q5KrTJTXn2uVR9{Zb-xhqRogcx!1q zmDcVY$vhks=%xWDRZuBPCDZ2OrSxiInO3!!Yd0YGgp^~3$iQ`<#2HH^b2cSh6d9S2 zV+~c?ZYYwpFwP9d6hvse1qD_eYnDP-=kN`vrA$5xGn&HAW4-iS-9%a|N>`a$8KPR8 zbH!3p`B*jQ$JXju2VJAOnA;{;H97^LE!??uMcVDRQ8D%9Sku@FS~~m!rkxFyl%8Pj zqRpV%?9?*Ra_W+{b1ItSgQ<^n=f;fATmx;`z*tpi;qY!qQs3N=#3XiZwG=zol;KWp zL1OWQ8kFItr(Ei~@kw~?k8T(`bj`c|vz>XaoLunSIyvF#WJu@_CU&^l>?-(-o~>kx zwlTTiU`j);=qjVSo$5GhUgGGqI+G~f@O11=D>TXSY;Z3PZGvLWQCqljPgpLokXFRz zLS@%LebhxZC8wd%zMDvEv2FUAuh#1(^fbL@?J0UPPtVudJw=~TYdU?8R&h+)&fn{3 zd%r~M9InICx`(r&8@4^2FOp+EV-@$_r76oo#O(yI+u-qR@#0+Z{G!yINug=tjw`xW z?({p?mi0nOB&>00SluL8rSQ1}oH&h5#!D$SSx(BM23N+=s*|mYuo!P+ZwI4UVCnI1 zA#MTazDUPnok=KCCSuf3eG-8NBgZciGIyC`^=w403`-zH7K^10?4DwQV^&zz=!erB zZ!mt#nBfVy98Y-0s_4oXdqPrlFf#PGnTY8Yx@(_N_nN*Qvw~|uPCKNh^m<8d-?}{{ zdqwt$lG`%YLSlM3w^MWSRg|R55+%*Ct03p=gk0N9ne+?@%uv(qYLgSFn0!5l=_;7% zPS*h6bsL9Qn$gW$%88A*TLZ-`CbMyBf!E%&+1IQ%m)661MaHm=*-WbE*zT+S%VMeI zJUV5b`sCHP?~e%@^EZvnD;jG22Fb7tYmpe8MI5+mFqrZWFM^Dz63dxJZ4}mLE{=BK ze{Bb*94E-yKrYjSfZ9<@#8=JtlvKrV8dR@!G;bujblj+UMjaPz_C-z$Ozd2PL`a+5 z_<2SX9WBU+pRV4ioHr< z7o&mWNdo4vCG`#1sKtXg9+_cL<1C?2sT8utCy0+A)T+@Y5Sq$$ zZ0Mz7#V2!RR1@@^^I|LURuM`LPp!fv-XAner>fi@%u#R!ht-nhYxguDf{2xg#?py+ z$%MUO9kkyQ%!>8aK6YW3LEw%(i_*}+GR>QZ!t2y=nheCvU}^eW0DRdrnWev zz0bYtyLRUq595WnG6zQzw-mNiTN-4OrFJDAa<~RM@;ldjZ5v<7VeukQ0I{co zApt|6JfuQlvjO7>3n#d;5#h8rN7BH@uQ>14H-T1QhF*-c;3+>LqNCYi5Kk*ODRWEFJM|`O59ML$*4rZiCRTQD(N~?Lf06h zOn+pOuGP8;s~S-`a2_hBMx4N4zaDE=X^NaFVF%lEMKtMrFt<&pEnb)6{0)19IvB@) zz3RoL& z!8()4VJ4!UV5+hblP_J$C3yeLU3AEC%+s9IR}4+Uv?uxzs3;`bn_IYl$QMzlWOdvU z*7d11mDH7o0f~sY?i!?A{PB=7@e6dx9X4*d{0?iSUGaUuUPQ>x=x0=GS}0V8j}HP4jI$AVJlW`@Zq z`xP?XmGDU)6J^Fht5Igc@T^@<2h>f+A6~bxJU?|>J+lczFXwO! z-Qc_=mSbS|O|H@ko_Rh`{i~8ZXh-Fi^OM4kr9QsK$1n5o5&>P7vZ~M%b}kxZHjWbK zs=&;u{gdY^9NOb1A)bVxyTnN-9>Pl7DvGD-(8QL?GD^u~VI(i*D#&g0avs;HC4$(8 zNZ|?sCe-i+-KR_|^#oGS@Njv7o1@OO&oyZsZG@({b4}W^G?9$9(O2`>Mtf)s5SQXa zwNV^u8_#TXw0{b>zhr+_x;giq4?9EGz%9(BxTC|XW17eH92%BpII78TwA62^$xu{F z#d&vOhK>oYTL>mxtcrNJD{J{h=)GM7>WT;*g;)b7KyBECFgnIOpSySooU-vrv)LI@ zdLO$3RV~#Pt9MLzIbR1av}%pirnFjWXgMA#HO5=&c}cF!@H!Pd=PET4*_$bGta+C< zt%@C&$XZq8*zuzlX5Lw7WM+scs5K}5YCihCT3xG!H4*g5u_lu^>-XHsF;N?A(-xFbYNyH$+Mix2fV~(J(aUwTdV4Q#}dY)zaJ9Az?$NopwfOs;-rTwKSQVrrX;kZD2v!&-32 z#q|cgas|&K#w54i707rD4XN-l9-~^v(%6rdNXob@I_%KRk(gX66Kiv;grVSIgwtX1 zI3u&%jPg<~`I4D}!^U0?!es!!VYS`|!TeVCJV4Es2RLuXqgMCvI$p9dq3cyzZo_#3 zF2eLVJEzpem=$B8QIF<<`|%EM0`>%^MtOn-D_0`tF@3-{Gq7yO_2oA0ahe@#y}JhY z_H0;Co{8mY_IJcWCy`Pfa${$QQp0MgNwbz4gSPSVKwEld+Uuy(Mst*P&m`J*mubI! z`J+Ae38>*2b)HeFyDU@Bi;t)0#mtkL9M1I62ywLqOEqqbOQy^E&pEe*&}_+o)3d+I zSTx<9axOy2fg-v>-rVx>?!jke6g6fY<`p<4Fg$$nIJz@MX9@_{y7V3#7ZA=4oK6!q zxZPTXjsDCE=9#s!XEy1qlG?@X7|k`tv8}}>$6a#{lv2+qD8X?q1+txv=wcz`>~?eg z!AdE6^Kv-BJqhe=W9Q#+GQx2cV?JpyFz}hS+CZ{KRtVWu1 zWs)veE+*PxTB+ktE7u@4PNo?(orA88WTI>3ny{zVGvny@f3$E13%yZ5FX@G|-Qw_7 zsFWtIg?OHV4Sh)5ZA?>Ni%>Tt-BnU|%5ab*WeWdP2^`6FWD)5R3u|54i#FyHu5))T zNl7)Xk0rE+H0tc)!2?Fx6gI5m>*SDu`_OEfh^1r|@8mV%)R|jk?(v$G?peuH6Q)s8 z>2&;f7s*K-4oeP`g-$kzf9wWKn{>_6He8eLo?N5!v98H9U)SulVl8qnD7i*`Kgl(k z*-F}(jB|`~uT3my#XI;omMV}+>U>&aHmXu*>)9$z^}t8QcsR!jfE`;i&)0U2N!u9@ zw3RU!S5DZ*nPb$p8L`nC86uxnMiBm3qi{?-y*Q#n)T!r2vq`+ESx&@_(dc>KB3e2R z3%m*H^!5ZOYJkJx{7c)(4OT}SaUvS;cxBq}I&(+tPDn-`RMY2*w$)GqzP1j&b7{#>0+k>k1 z6>ZMvI$(qqp5NgJfX@a|v>37ij>h)q+u`-del2vOhiVRDs^IFE4s``CEpCAK^bo281l((|!AODOeo(Haa z5uR|g@dCLl7_c0{=mC>v^zxOr@Ni3!hu9onYVm?i#y*@=M(Zo;ac0S#RWgiZQ51JI z;%yzK50ytXoHlYlOz(^>k{j39VQ5aSiOC5wZuYlg(T#$4T_dV|j)SEs!=%R&ICDhD zA}xD`Vq><+XlGbXtjs2bGgm??gk6Dk6Q)`E^1Sr_ddAvQq-SArBaIs~5)>+y&tHa^ zDPcq*F@YI-W1<~bZBo+0P-49E#e}YUN)M~+O{lu3M{LlxafBn!1bqIN=~;|3mqqLt z84m93qkYNq5+bqf=~EAh&a!xVK{MvUJc+~CJ309%&~qSDCmdTQ6vLI#Wdd<4#jmav zGDMz!H(ieOe05V_8gIbL!vvKf(%xl=*hR}`KL$s?>srjK@Y)%k>M4TuPGsVXa5~0D zL3?ftIIE~bzgq8mgze3#nbX(-zJ(*`o<#WSj zQl*QL2+>YoG8RtX{Uxg}91GV?=(^Jvs9mG%i%3?ZQo8A&518I$Bt_?TrcCQ)CP?dL z%KZL0IpO!uk!d|&erP41fEw(L+~tF7&~Etv2$g^a{Wg-Dr?Q{u+yY}=(0MPzho1ej zC}nG>3YW{!n_>&OzFsn%jQ-Fr80R~@U=Q=@PO7?JZ3T}UrO5esD0%Ee$=Q#e=fgW3 zjruQ~K~onc8C{aTGeF<@pK~h6>-=&Ki0o+MEpeX?p9)5iW%XLd_gk5z$OV2oZ_Sx1 z>DW7^!pU#E0e8JvL-hkwWU-gMCK9-b!}{)yTBbmpK};8=Yg^kQ-<3rf;3m8==wX5G z^ham4nGXGC&)(aO(e~Qx*=x@|_u9-Z+C8S@w~&3ubpCMserjI3FT`Ftc2@MqaB&|! z)3^@vrf6lXc?EBmBxAvAbzxO3E;)md`bDs$r@d9heyVqvH?SA55l)`f`vr$Kbh?Z=T^Za>itA zd{Wds{c_s(0>vj_9&wQ17mCe03ZFq1GI&v^XQ4}Ccp!!u6&7wdy}}x&IF6@Hj#)GkYMh7LQfNwwi-&$OT<68<#7drNo4Xi{ zF&?NE#i#%Gjx zcplRz8#dbGGFkBHZ$3M31GQtmyFv_@Zo`W2xYFXp(dP}WIAJTYHl^mW-A#jKLyNq)2l*R{AnK4mXUh}M(UP?K2bR56M+A+`ulg*5?8En1VT*!ql3PJ#4^khD9ckA=(^ z!qQqMGgv1elOvhQ?VcdyCY<66ru;ICPO)d!srAeld0pLFzI!)Q8-4nV9i29OT>@8_ z3Cpm3-VCn2d8t1!P{0{z3udHl`ZDZm6tgCp!sQd(FOs4+z9XiEu{Kxo>Fo7JW#Fh?h{i!awe(Fky5O`l@xfyGI!@l_|&7<8%ibfJ}c%FB4L zvd%lN;nG%man3|!)>+}i9xbUyM5J%x%0~8o-CbJ8WS*09Zy0vcV$1PcK830P_bwKd z6)HZoCdDVncQo738wJul3dqk2F zcOca1qP&pXYuN6V%?^6bcxWLrP;VU_J~GV6|7K73I@#3JoGuh6QIbN*3(93)i>0-6 zwXVUl!6qv`(l#)-Hcm#kwvK>{SRHOztj!5j=cFt{wcUS9Lq*zg=Ec>Gni~^goIuy% z$7trq+Ocnzz-L;p4~$QD&BH2^SIr9AaGtk9t_tZ-`Y(#DbVl`pbQ<%~M8^``GQb{N zPgU~;e(54`co$2p!G%05OWJV|UFkUu~TV%45o0a%r3|7=8FSS6Tw+mTTF7`0Pl`4##J(db?0;APu zM7|IMP&!kDEW#R3V(k44gA{nTxcqMvky+?yF^cjYE7nHbd*g92erAcy3fG%CR+H7A zwGtM2=>58Z?lRCiS{s@9`p8~?DoAe+$N0G#?suB6*YS!JW~vpumXVZXDRZ>UVB|xq z?u=UobZoWDEo;@x??B`8e;C0ry5ew7s6>h1!;oIVCvzGiy~P7?`A`np8OBZhIT@&? zsQm|OX z>#Rc_WBzKsEy5a57Q=Un{u78!*6%AH28(4E-`m89K@UP%O%1`*9nis5-Jc|76U+Hyx&1#dfh5XH_q(L()_vsW9xoD z6`csKw;CI&8&<+$Z)JW4iP7#ZqetCkCNTZmN#aO{t_2db{{65FMe)TSviXQ5G9BNU zG!~qwstWv+&ZLR@_jJ5kgjqR$eW9h^+{b4ya?z1Yb##SZxjs{~*ktY!ogO|Zccltb5#*|wx44i7LM_xVJm~U$q z;7qcOhn0|`3#h_tn@q{+=*Vz;*Zc+^6}b0c_RGp}jjO&6W7|sUA22h(C9W7noGj}b zq|8ZOq!?P|r|mG$kLi1|U`*v>uIMccXDU*$04)ohEW#*R*Jf7r)k%EA41@7Z)aW&c zFh2n&XRR_H(eEtMvp1AZoK`fsXi~x0g8YKQv6ClHEgD-maoUuzMW;*a^6e-hqhep3sZC zZV1M#(})U&FW$*F-k5IbR&+wOGPB3c5XmvKV5G%DbmgRFas9cY(_3R&P|f{3+7#l` z8uE$Wl}@HoDz^%_*2d{TTdX0O^3BEOC)?sHJFsVrLdOK872}f6))bK>%$FU9n|~(t zZ)WMdQK&jo7AE4fSzHC)T{ODpjW%=P#Z&PvIkkD;54P<4wbsM#M78 zEaKL}LRCS}# z>%rbkd$E{mPhr+K4!2dB`GrIN%9bPaWL^l49p_QFSx`{Vi311FFb>G{$5 zm>Ji^iFne)25Tg`(^zKQFT)Rurc^z9 zheqrV{;&4V2S(2F&hO96{+U_t%y?&PV-t4cmqLQc*^X^YY&ZkE_#e(0Z19>aiCt&x zUE7;F4M=c0PC>0zs1DUghnk!cm7IDl z^pa~LQ3;xUzQ5o5zB6O59g^!Qsk-~;eV_l&@A*Byf6w1HaM}+u7Nh2n-B|b_#=2+F z9NwvQ;q*FCz$s*t2-vy$xT3x8=j(NReI#bsvC-ysB0xw~^|Tg21PfO*JM%!|7{P{)L)-y5n=Rm9g$Ren`LhWv4Pnh} zac#mU6#bTOngKJR;P-rn(a9lAds&M6q&pysj~yL{?IBCw)*~rUrACC1$xqH;`M@QP zP6E-}V9IYvx|3rXpAPZup?*Tpik3-%__GUh-DFXK%rfLox=&P2+afBYu;G3@*~Hy? zsK65G3#uplRyf8$Avr8^3S@;-8f@4;#nW;jl3KPnjECk8Qs&Y}FhP*Cm4p%ABUo?8 zXYM&UG0~J+Hj3mDu29u2Uqg0ujmefUKFnkD7?Td@?&Ek+6O$)&Kg_gk?maPXeZ~+c z-oUInY(FWKG!;*>T2hgQ=J_?h9c-par5w6sbB-1|bkc9_n!s^2dT`1pk^wJWsO{#{ z8c?}oEV%_s0{kJnJn^Vs)?ktq{Epbh9iU9!c5^I#46ndT_P5@)au7KEec1X(;#E5n zG;MIwU8q|mESdn7t--s^6uTPL1(y^+yG(o-El_SOi>K2A-( zHtApsFlg%(l1oFY$!YcgF0jmE1M%+IK(R>%9SqPJOPfJ5k1ExW&OCO;-R|yi8cLDl z%RPLzYkt4R}gncGj-ki`|{g(JeLr^zdDQ=+$nS6;C$)&+Nwc?p(+6^n-KhB&11;=YC; zIFpxaU2LukB6k-9nubXar@?W|c59BPdP*uWjYyBc#pJntV)7t%QvCf`cKfgc!wp>; z=y!g`3d;N<2u~F67>y6l8KL<3IRpsi4>~3m$2+_@jQ$5X4m)Kgk%5+S8IxN!3_M)5 zOKoh#t9H?m$Q8MKVL&dk?@TxOK`KdM!?F$Sgn5(LMm~PfCkWHm;gEB;!(&*$*x|XrdNR3C78R+-2OpEjZQqfeUOrn(vk% zx@>fOiVhMjo)q65w7sh7EF)(+AZxo7`SAEDPL0|2DlBi*!LBLaa%$`BCZZV!`G+v= zx`?K_i1(b!j86Ad*nVdr#r78)?zDkiA+{ghqWt`{oW2@k(JlL!!)Z8?c}HF0G)nHH zOv8z%w3IUK*A&s06UmiDpHdCV0@Z}knb5u^I^7VRZikLHL;F_fQ3F&K1J~ijd!Z*7 z2c2R{V2t5~?Nd(FWwY&vkI~WG8#QLcA5OBn7fuh=c0j8PI zBvv@JHgMWu2+6Zf!!T3Gtc#zVLCL4L1u0sJ(d{EwnC^BR*yJH|tu=NsC+BWuS<+kD z1Ba18ck!ik6MTuAY7-~(Ga9;UI(&P&kwW=wy2PZV=1ojN$2(hnYpSArP9}BjJ?UUovganP2h4S={$$SXSrl=!5n?dh7fkIV-Mv3ZHTM6^pU zzkS{?2FY;!#ay(_Y8lg3dtmWHtm>FJ7jan6PH+n>>m_=P*zd8a*x z>}e@{jmx#KCV37?d)^cn^<#~h$1i1$6Pw14_u;`MsVm*5AXDw+RJ>jfzUn;82R*S0;oua#Z*{exUR#H=hrc)A^IP5;jvDGsVt;Xo{h5PhFk*hD4`n@EL zr`TJH4I%vca5&0xYZMNJ$#6W(F#R;iBveFbmF|h?pfP@r<6=Ze$O+=72^kF`6S`Iq z9=cZAGYU6`(6OEWBOwfZ+|q2PyefH)hShulM7gdMvXin8k)D;q5EemNz$5no@{NVV zAuQ!I3t^Xra}s6F@CVu5awu-o1p8d7xYtq+3#fC2UzcEEES#deyQvjJg|x!UIPD4&yjbu+fqb zC|mRVBt{Q489fNLv$m{hQ!?%&b0W>gx%pDx_0gyCjj(Fn!|l( zNIibpI*wReQiuD_gpUFogNw`5!r-W-7WbWDE0}7zTw6p+&9=Dj3}k}Aa+z8VT3iB| z`$A8G6}h~9ayi_gcXbdnf?S~vnL@oj$eK`h%N3Vdd-wlql&<}GNif{8)p%AMD`_!G z2a10=WltB6n;f|k35TM1NwQGn9y&(&f53RS8M=dZ9q8oQvH^ZB~ zo2k#`WXRo*3tn6zIib+0a6kDc;6#d91k}bhlvFxh9!^{s^>wNT;iunW#U3< zOtE!@kEum-tqQB~3m7$2O;6$^!jDmv%7};+WlN+U<6j~t3Oj-Wt6Ei?Vl!pIAyF*4 z6hvW>g#Z2cm~4nsh2q0u7mx|vQz6`_IF%(KBDlCBioBbFN@ADkYr@oq(4#cR!>2*z zZsJt>#|-sj61JN zO9kx^F>2wEL2W|1SEA9oDO`QT@GiyY*utnLj?V0vAw()7ln;|$rR=dbAEHf1s24HX zqkT-?UME0_^Mj;LF}6f7Bv=`umn4Wo?*#d!c1d4WiU$HiA!?J`Lq=Ldu2c9fQ#8y+ zl1lyI{UR*88j;#|B_l<|_bB4>c925pPsO-n8e9Fc;WxvYa4UFP6FwVOhTlZ-wffez z`EE*m;qD!mP*{_OqOcYCWME8@LzH(sR&#qvSKV|u)lG#OL zVQQDkOvB1*k6J96R^Nn$3D*o$B7L;bOHOf)Up1uuYc8#+HSXdX(>N=KuTdm@xkS{F zXwWpY?6tcobO;y&A*#P6#M+FIF}@Rx$dF(yRjGeXJ-!>ChpL4;$?r6iP=crk{9L27 zdoABE>5r3728MC$wTjzAe~V*9+bX}ctgyT_h3dE{zO97KR_^dJy{>V> zl=ERq5gp3vY2|3iP035jr({N4(W z91EG=raSa1wAP}VJMi?N@#gc8Y(E2Mz&rmCzl>J zjJdpT3BS5E^_?+vMw8dH=V*(&x;?I`P(x9@BGX#ZEc8mI`_RGZKj~3Xd(wxbGwR)K zxtcg_OHpo?6jRPMi6q%V9j-;yYEeumii=s*Gb|+9LxZ1PP~WGZTw#bF$;l{zx9Lx5 zzp-Y_)xw`brr=YLi|bvbyiTiwO5)` za!xI5F@R#p*AlWsIC6_Y`uT`+9HEk0lKCy6*GZoWQm1Y9To_EspXOY|tQfUQ&I+ey zC(u((IK1CZ#ZZN-Rh9<2YJ+kmwvzfwEp35yQL~+?)&f)Ni$q!r*G?ajydEdKk0a41 ziE9Z(Z>c4%A%c_n)n;p2WZ52a(}y2;5IEhO6t2}HqQi+G3KcCfV~BO8-r_6PJO$kq zQg&=ZitJ`sFC87aWHg5khW5AoVm84_hMQN)8Lqi}Y*-{(7rd>!E-4_qOhB=rsJ@bv zklpLn(GJqPL`Tz`ohQDLj$k2ze4=-0icL)Thtu#l6~p|8!3nX-utvjnhK6P+urP27oe zmS##Urr7c!MC}y!$003NmFy4ETdVd>!(!eQ-#cHp#h+M`d%)_E6lWJ{kA<>sgvD5z zVW%f@I4lx{sg?f_J5%OSy}T{7PGz)OtD#pg-U$@~TkaFUvftiE_3rru6k)CoFxNGTZLT!O;y6iQ zPdy!nNWXi?;W$K^o{-*8SkIfgn7GZiu<7%ZK7}+v`mpeWwA$(WRJaZQ9T)jO2=3J) zJr(~!_@>35J4vr=Y~oT^8b$V(dP`a*857dBg&K)8?etI_Y4u%ukiJq&#AmXZH1?GA zWUC1^t|q_i67kLs{;^dSsz&i~;y(tCn`I>9MEVoWA`XY&KXZ9$p>fLPMkb0|pN>=H zySdHxkv89k7N6{~)3idG1}rf$5VmC}`KVg0jj1}eS?{D(X&6(Attp#&xM^{OU;Ei< zQjYFP><^7Wef;lzwF?+U{o;6R3*!KBxZ6QPyqgrC@Q22^k|UfKB;^rWq%lS4bqyj) zaEaQ48Y<}3I4K^D7EiT~L>D#3m8sppShG2LO+%4Ys!L;Qk_0lD??{64^)1 z=v}4ZYu5?Z%?{RNu%xb9VR~h$o~lQJZ`wB%&tSJWFV12!kLS(;q%Hv9Z%kK2YRU$W1w@X(X^!xFVQv3iFL$|^lAYe05p+S4`* zvj<#j9A)<7HSF_BeJam2l8pk4#x$N1Rf;ElTq*mZDw`pmd2(uai1DDy#87;o71Pxw zriIOWtY*nmVeq73DKecWY{#I0_nvo1_)easE_6kTd>GyNVqhFKu`MS8Mz#3O4w(fBbG)=xUn zEbg#*EE@;OVw1Jjn!A+)fNz8NLZcpWn56gV7T)z)8I20uc5bon%1v&SBw-BL79y+1 zM^iqdn991VFNQshDL-U%asuw21QsMPW9395Y{4(+3Sa|rowJ-qM!tJi<;3%MngC7DWNrh7@{+Dv88y|r1q1P}UaH=#t$j9$Z9zBxnF6JNjpKt%!^5fsgWV`d7KmF-XKi9c{Ma9l2lyB*ZGMVx% za^7Z6o}p6vPB+247BtKVGxxFT~!xUM(X^|)4;YXz>m z&2=}fmF8O69c459m3sjwqk!^W4|t#_>MT|2!^M1-R+aab_x46z8QNGZ@6TozM4gG7 zbU25L#cV$6a92LcmiLpTD#w`ec6NiKYU83fp&TgiT-qTl+@8)7RH~gxfsL z9a$K4c^cdm67+fjpH*Br$!|WzQhbSgb>N)Mr^Ux!FTO-^3!)BBR^Ho}ln-L}st8)0 zrHFfrQKwgYuR?(zlc zm)#yZd#O%{E*4cxdA}95$@;GL&2sIJ1xk?$%lj*vC@b4fJ$W*eN~LT!jqD(2$zR1B zn1+H%@!L6WP(bm>ltf_41uFRgYx&9`G2P|*_3A`kJy0VB@UtMw#jcV;v{OX(tkSN) zRX=6221nA zSE*enKp*fbF8l@Mj-7p_zLHV%vplI??)oVKSkR+Wk3IqYxE_B_C+`!B?1STBI9SqZ z8WD0v05(gQIAmWZ-5$h81Z0hPpv%6Z{f2HO6QO#*f~c#AuaGa&BVb}wrHw9#!jeku zIRKrdV4gy?u&Zv%^F!mHqxuD_rS?P?rciC9jOzjW-v0W90+e9fQ9lE7<`=AJmJKmc zwp#asVY~JM?uNRj@r)j$JnHW_C4Gma*7DkSDx+TScOVB8Q@)FG2BFq$26BK*GTxRM zwPmKW05-DSLTT+qJzi2@*IrVEiRVT4ya-_ylpocAEP2LYYCL0zIRzAz+IjV7Z`2XH zDue1dO4Rd3T31jX#u;lhm7-^+vbzLl(^#Vix*95Il0=_1V7Ks4A1pvlrBZ=Hv)Qbg ziGmn(*4pO^TaFv_XT(({7od27k@64QVZcVVUWm<2zkHq@RM_-|WP z^qIBvsbV7sSpYf0|(JFL?Xi)90Q(QQQ6;HjTtyA#~c?geJY` zfdxfZiMBe$IFfce_j}FHFG?Gp^>$P1BFPzR6a7wa@uzl*faLU?-!_=P-5-_Wv~m7| zz-~MP(N_jr3TiwO7v#BLw%jk{snpM^r+Jz7lMg{7pP}Z@Eg??`Ya>Bmh-oo=1t|yt`pw3PiTqF#g-FoEArP#b&J?^a& zTdptGW0@ZPdPI7x)MGs&8`B9cSSjdv6=li*0e^)eLIukRXAvQTt>r{m->CN1MSht+ z#sa~VexHf!a#cnb?ca!%mnjmhMp$LF@2auix5j?gYO8%$W_+S|7Dqj)n<`NYCxDhFG4N z%1%=jk6Xaw*i)_%2T}s8@3g3$WUtg8&xa0VEeZr2k>qV*`UxI&88eNVTyH2$22TA? z^%zkP@RHjpw~lECr9Gi%!vsiu)arP{J4>30%%1O06X7hSqDsXyE)x+IQKwKV%I|B@ zD@2I8JVt6ouu~sT>Qg&L?fHg>N{g-4MXpkHlT3o;7?dlRqo^IWj|#V`SXuV-PWH4+k~QYl!TXgBKJgSjACVi ziY()>x|kGtM$(G)?{#C=^2(7{@1h#cJAtCJ#g{_yZ7b~CW>de8a_GjMBoCr3~g1ytRbB_h6VcwpXt)!QQ!>uB-zwqF{kejZmG_Xr58*$WL#vut?Q*ixR za4bZ4dUXhPi@1md%C zh^BLzG3fo0C$&htmh-8$oKJa98%jRrZfv|t;}P7NeX8%Ywa0T#RQVplAPvI7J_%Nn;Zr?{Wq5Pg^TYn=PvmQNI%U@ z+Ux-}CQ$>$z5ybAp5vTsK2Tulc@}eFwh!yB1FyS*TT!F#Lz7s-a|N<7{}HFHqA>dC zQF`80(U-&qbg7;*de+Y>a-*EJm+fgu=zEc`nX!$LL>(a&Y(9-{enUN45;B~a-Zc7n zQ?&CVIcq=i@E=?FkKz1ce<_a`=s`gMCY3QkT(#b9G~7)Vue3q41oyNT%}E~ zB6l0Jl>T34v5kL%TLBnFtaSSQxp9^s>HBeO}3`BP#E@C82Svm$29iD~e^j)A zFf|6p0%hV56cKtMK|S=83{04$>#}ysgu*6)pBkbnp7J)Bk$FioBMF?07U+G0()D@c zDTC@MvBhhmng1pFBbSd~0Lcoa6lYl*Sfzoa6Huzw{=CfEyQZsZ@4^YvfVG$C1$$c| z3K-C^#exP3K2YCE)rP0qE1vt6tZ@RvC>tXQ%-SnzTJ6V%w%U(H??hKkK=5Yu4Hg1) zVm-`0($(v-Y?C-9H|__w0W@@%oak$&cUp{7e7p_J48vf4lBmpZT|c_0S_Tul>;n zpZw{+{MP#IZ~c!`?`-{#8#CMA_g{0ppFj4)zxXdV{O$Q4|Fgfm^}*%KCszL9k~4qw zS0DXc@$H+=-+$L<|MIo}aL2QyzK`~P{Wl+d;ky5R%gpzu?ppi9cVFJTd}sb!M}Gf5 zef`=GKmX0?Kly&=pJ2RZ`g1wt;&&?fPFOH64`LH9k)JeMl>{cu z_XaXN;D6na3hQDtPHTwZ`5eY8)+XVVdbPAT*TafSx^#jZhNqQyFT?jr{g`!I{TNk~ zh&;TGb>^7!2D0*A>&^PsQdfWqOYh4q)T{@~Ta18bOO-(wt@6oI2~7&aLh}oA3y4Q7 z!GI+)$duIlSy)o8pUx}_d3%!t19DMVmdoK}foVUoLy94ZU6ku7nyo3tat@RTD>;oa zugVovxLcwK2*vOxgl6T0uzR96zy@QY@p@gz+FRbQwvEvbg~E-w zMO5EXq|Np_I9_%Fl=AEsFHk`J3o2-=T%{f5y~SLYg%QBIB*khzN>c}g!p0n;vAu%I zsH)2YDbp7;+OetTm#gJ!Qk$uv`j=VEqLaQVAA^st(!X)t)$$l92c?U0`SKXZ7AC<} z{R{jp$aPc_%#etXK0vI0LCwm05~DwS3rVUzNb03fx~U_FFgBuWhEwyozFfD;mF4KK zo?I7Q^aKrBN}nl$@c8BEE9QFQ6dEcDUt`cGs4^S>Gh{eqSe}88!lMK13%As{B!2oiF0_l&{1g2ucsB z{fj&jruDqtax7l^Gmg+5{3Hu2s(z@#!uu7l&NXy8| zZQ`-q$cR$w@4`Bsm)jnUM1vX4sNg`+O$seK@|%z^`+i zUadzNB*eihmx4Y55F?)@Y~CyPmi7c*}btP6YhBLMO+36e<#A=3WwvrB7`yc zcPEUrHNP~%kkNLT4rw8bD{yMsgv;>ALYgq-UhdmYih({{Bq3_p*iPN_aI})&LmO zRaY_dB{$z~q?$oBKT9Lsp5-_N*=S@)eFKEh)BW1jHo(Y|Mn4E?df#GJYfz*0yJS zPxXB`6F$_QEvZE4ZRtjOm5YPI-I;J#d-|4E#)4Z7<66VfiLq5i0*2cNVz&EC9qEql z-^he*?WLta|J-G5$b@xCS!2g_jg~=g*YUN>?f7c$NOzTourm|3C;3EmQI!b0ye~R9 zc`B+N#%?9-27Tz~hNv}fRJH2@3Da%Xe8E11ZJ96>U#vJyG@l>Bpq(^8bUiyaYQ;C* zn=vTjzCq#9(DV%kPGncoh1)aXmINj)vf~1D(kOMzY-TB=l4c^ism@srqZvMx7Fw4H ztCH;G=CUl~a<2cfLQYhVj9r}N*E8WGNfs9ex`PkSAB~V&@Y*QUpiAP!l*ZxB>RK^a z<+}@9xG0X9IE@OKu^OlCTOZNE>J$KT1z&;_5Xfz+E*2~zgw>gFV**GjT4;F-nKerb zVPz)VFjw-Fj#?8BX2P#0iM^4+=}5$PLZ%(CY3mnBLc4Z#H@AdY2hyZNM_ELkvw#QQ zdjU6R!kPqv7&3wIz&bCY%4N8qH{m=lIE2laa65Oz`Pk@K^|)}>Y*#DfDvYbe;w#Xi z$-|M#5M@ea|H5SmJQX78beTdJqv_)_kzMweQn%yw${GDDEx$m zCmPtxLk>ucq~)P|Q~8k;Mwu=VbYphh1I<#HN%;M*>E}6)ybfi;rnD^GH658;IXo2$ zK^1jn)gjrK(7u0>$?A41!PJWt5Yb2@<2J3&ee3pZj}WfQg!d=KxQdPqRXAs}3|Hv1 zHxs(;qI2BRF?&uPgkQ!nX-pWy?PCwhqHr_Eb;YD?8`=1(Jh{xSP2PuaPbTcRa#_dq zS&ebzb7}=0(f!Su;1G6*08i3wT-_HAX2SlK;<)C%4X*aGstL>U)djzwltFr8BDpj` zzD}#AL?KbdCo*~@~D6guLc22Yw` z*r#ta577dh6lE(8&|N3^)T6qoX*rq=7pq>1xHl7aUZIE+e#@(H#}SjjlMi7KTB zFxSaibTaG8qQ9nT+0-9zek?b3)E-}*seL}4tlKlk2V7PsfxFX>x}@KWSQ#CgJ~TNs zF@Es>!hGsAnc?hJ=?7|bS@kwk3)rYkMYCL?4Fs%EYYAo(kAV^s{*}hv<;K0NX7n>D zeYYj(SAs$9wMl91?DuX?VTIG-FF z!O<9J_I}omlDJa~UkY6mx->a|OwZb^tzgdP=yH~awdPl8{HZ;^ZT-*wvZUr7)&z9; za1pD4?9ZYY64z$8<|LIL2dSfzMLm`*pHSj<|Vn4cMoewwsKfxEfW`A zT<|U~Xhn;~!;x)(eAHY2UO6T%ZV7Y_;kKonE~%7_8QVP^|O{{*uxq#t-dsA?Q!F&$30Q)afAVkK|iwdhV~h*U)9=G z?KRe^)Xn9_7yb2Re|^qp_YC6*#Y(~En^ju;-MP7u7PSuWdCu)Q_6=d0o0yf zwx`w;%Z;z~vt--&V!83$*XAf%1Y->_ zNg+UpvApDhyA=m<$3^g3kkjESKNbL$;`Toav5gG-2|%1GxJr4nOWWYoju*A#KyPFS zyVu25949b=y)&QdggEG!r8!o(O+1QN5IB`jntX&NwC$QBR+5r$_vIFdo%umfzRlm_ zoD^T{4}pbT5`f3L?FUpuwa81=FO9BX&amY;!6|QnmGNu|(W>eTSvxo3O%yr+u%g`} z0t`Brl;e-oCEI;WD-pbg6Ei;g5rNt)Bf)8eTujJG(iE``X91zM#uR&#WTeFHfa6vY zlqm|%etL3An+l*n+aL6U@V1@m%W{i70NQ*jcG(MsnD6MxX}7tM`+-~qh4o2Os_ccM zT~A0|qd7SClfYQKI>%Phv@cqFquVI6D*0cJ@}(GCad#2PK~fY3ZR12dJHcIwUr40* z1@w^bU{RNI&g8r(Lm}FDAW3;%+h6b-eqYbZCt@lw1iWXj0rp%< zh@3B1O|ZZuc#!(a{(5$~^xrVOHmm>2MAFjay+HgwXv(Nld#!EDgNm^2sSb>(12(3r z;0kh;Vu6&s+{pO)_k7pT>vrapz1d^FX`)_kyo$~gW7XH@dId!CkJD>!8c`Sf$-%DI z*k-WT#VIcKU!CisBWLE=T0u-))Wvy*a#u?n@yassY5XZ7s37kva*!mgo8;+;+3&Xa(JlEK-a=Af{Q_ zZlibPuq$SvXzl5$d=kn|e`JFy2Y+nYm-HWo`TVEgfY)ZPgHCpfLipPqtIXI`Oia|> zZo$VSU7P(>CXBUh7~o^7V?O<)N#j*E|2t}P%*;+}u6q19UpZsQsp;6}NS&pmspwM- z=WQtZ;P|w@$=wk$XtYZt%Qj+z!Ycw&9rGr6I+yK{mmp0 zDbb(DmhJ~1{W`$G0OM}-PNnf(PRg-$dq5{y`t20q_YsuEewj0k*NN{(4!?zf!ASr- z+UZIi{s5#>u3Lm9_Ycs>xy9LRU_qY28djO@*3D;!a#5xJjti|g9x&LM+W4Y#o;MDm z^#p&|zeq)It=M0`-WhBW!}Q~6t>P_fb&xIHOL94OY$KoFYW;)cw5!_;;RZ(<7!&oI zzyMrH4$P`e>>ou$SyY>0k+P@72 z=%9|9`tG?FP1+chTLK=6uf2}R1IENZ8cMuG>nfvShIn)-l3Z93RV-ZcjGR%?vSW~DmYLZqV5Ha{djPpU^e9&<|Xal~%n0wW`Yz5a4 zM-5+^TN1ZlUDo``X#|9FsN_7%^aS|`)B%Bi-xIV!?sv+KAJL-&C~>6|3Qfc7Y6#fr zCzu5Nx!@bfuVMt}`&}Kuz+0{k^k1tX;-fOAWyEm~Q7z?yfa>0X;1=vZ!6gm#Ksiq!P?l*}1O@IK0c*|86?VO9G^AGJ){kI zl*13km0VaTU0r#09d;35h+&gChYA9k+=hGII{Q?6sgoDRUZzreSLm+2n@7cJFFL!$ zZ6hsiQM`=wXRrrUcD@&si(1c#Y?Ts;Z$rqHxy6;=?xOL(Ez>flKnk^A!u8dgZ(eus@J;JhZCF>mY1R7CbsJXQ@{x^)@Q!V$-m+%h`kM}Ohon+!J=7Oh z|LnUpE`sn1*;}Pred{bLHN0wwlUpkq-bNt{G8{wFT%Y=Lq%EeF_i8_98 z_@T@9YbPT!T_0oa{GQ3<>4&)ZS~;H<^v&6?|K6QDlu21x_77kAgU;}kf7HpQ^DTS& zf9v^Af30}qwmPy zl#A9lfY%oOSrkNOPEn37$n>j9b)B_-t`EvJY*+p1>PWwoF}}voQasZ+OQ9KHYFND{cJ+JvYZ=3 ztt$t0S+lO@^eZjxlFK>DQr?ZB(31Cl^6HZk&34_)HNb26*LxkQH*zVjdSO#2l22Dq z`bCxg*^+yJO3+^l_iDRfmBlfBCcq}^lcYOB`Uz{bzQ5ISndls0QFs!Cvd-{!6CZ1E z*9O8q3f7JSNpgj$E-+47u*Klq6_>3GA5~+5EBSslyj!eq^!W~5@OTp3&OmKR&P&@m zcOMDQ?PXky?aSeM(E4bIe$l0ux 0) + { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Equilibrate solutions with phases, exchangers, surfaces + */ + last_model.force_prep = TRUE; + rate_sim_time_start = 0; + for (advection_step = 1; advection_step <= count_ad_shifts; + advection_step++) + { + log_msg(sformatf( + "\nBeginning of advection time step %d, cumulative pore volumes %f.\n", + advection_step, + (double) (((LDBLE) advection_step) / + ((LDBLE) count_ad_cells)))); + if (pr.use == TRUE && pr.all == TRUE) + { + output_msg(sformatf( + "Beginning of advection time step %d, cumulative pore volumes %f.\n", + advection_step, + (double) (((LDBLE) advection_step) / + ((LDBLE) count_ad_cells)))); + } +/* + * Advect + */ + for (i = count_ad_cells; i > 0; i--) + { + solution_duplicate(i - 1, i); + } +/* + * Equilibrate and (or) mix + */ + for (i = 1; i <= count_ad_cells; i++) + { + set_initial_moles(i); + cell_no = i; + set_advection(i, TRUE, TRUE, i); + run_reactions(i, kin_time, TRUE, 1.0); + if (advection_kin_time_defined == TRUE) + { + rate_sim_time = rate_sim_time_start + kin_time; + } + log_msg(sformatf( "\nCell %d.\n\n", i)); + if (pr.use == TRUE && pr.all == TRUE && + advection_step % print_ad_modulus == 0 && + advection_print[i - 1] == TRUE) + { + output_msg(sformatf( "\nCell %d.\n\n", i)); + } + if (advection_step % punch_ad_modulus == 0 && + advection_punch[i - 1] == TRUE) + { + punch_all(); + } + if (advection_step % print_ad_modulus == 0 && + advection_print[i - 1] == TRUE) + { + print_all(); + } + if (i > 1) + solution_duplicate(-2, i - 1); + saver(); + } + solution_duplicate(-2, count_ad_cells); + rate_sim_time_start += kin_time; + } + initial_total_time += rate_sim_time_start; + /* free_model_allocs(); */ + mass_water_switch = FALSE; + return (OK); +} diff --git a/rename_cpp/basicsubs.cpp b/rename_cpp/basicsubs.cpp new file mode 100644 index 00000000..ae58678a --- /dev/null +++ b/rename_cpp/basicsubs.cpp @@ -0,0 +1,3061 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + +#include "../NameDouble.h" +#include "../PBasic.h" +#include "../Exchange.h" +#include "../GasPhase.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +activity(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE a; + + s_ptr = s_search(species_name); + if (s_ptr == s_h2o) + { + a = pow((LDBLE) 10., s_h2o->la); + } + else if (s_ptr == s_eminus) + { + a = pow((LDBLE) 10., s_eminus->la); + } + else if (s_ptr == NULL || s_ptr->in == FALSE) + { + a = 1e-99; + } + else + { + a = pow((LDBLE) 10., s_ptr->lm + s_ptr->lg); + } + return (a); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +activity_coefficient(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE g; + + s_ptr = s_search(species_name); + if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + { + g = pow((LDBLE) 10., s_ptr->lg); + } + else + { + g = 0; + } + return (g); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +log_activity_coefficient(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE g; + + s_ptr = s_search(species_name); + if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + { + g = s_ptr->lg; + } + else + { + g = 0; + } + return (g); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_SC(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE lm, a, l_z, Dw, SC, ff; + + SC = 0; + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].s->type == EX) + continue; + if (species_list[i].s->type == SURF) + continue; + if (i > 0 + && strcmp(species_list[i].s->name, + species_list[i - 1].s->name) == 0) + continue; + if (species_list[i].s == s_h2o) + continue; + if ((Dw = species_list[i].s->dw) == 0) + continue; + if ((l_z = fabs(species_list[i].s->z)) == 0) + continue; + + lm = species_list[i].s->lm; + if (lm > -9) + { +/* + if (l_z < 1.5) { + ff = (mu_x < 0.36 ? 0.6 : + sqrt(mu_x)); + } + else { + ff = (mu_x < pow(0.4*l_z, 2.0) ? 0.4 : + sqrt(mu_x) / l_z); + } +*/ + ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z); + + ff *= species_list[i].s->lg; + if (ff > 0) ff = 0; + a = under(lm + ff); + SC += a * l_z * l_z * Dw; + } + } + SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); +/* correct for temperature dependency... + SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and + Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: + SC_T = SC_298 * (viscos_298 / viscos_T) + */ + SC *= 0.88862 / viscosity(); + + return (SC); +} + +/* VP: Density Start */ +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_dens(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates density based on the formulas and parameters from Millero, + * 2000. + * + * Millero, F.J. (2000) The equation of state of lakes. Aquatic geochemistry + * volume 6, pages 1-17 + */ + int i; + /* + LDBLE rho_0; + LDBLE solution_mass, solution_volume; + */ + LDBLE rho_new, rho_old; + LDBLE e_T, M_T; + LDBLE a, b, c, d, e, f; + LDBLE phi_0_i, b_v_i, s_v_i, PHI_v, B_v, S_v; + /* + LDBLE k, I_m, I_v; + LDBLE AA_basic, BB, CC; + */ + LDBLE k; + LDBLE gfw; + int l_z; + struct species *s_ptr; + + /* Density of pure water (UNESCO, 1983) */ + //rho_0 = 999.842594 + (6.793952e-2 + (-9.095290e-3 + (1.001685e-4 + (-1.120083e-6 + 6.536332e-9 * tc_x) * tc_x) * tc_x) * tc_x) * tc_x; + //rho_0 = calc_rho_0(tc_x, patm_x); // done in k_temp + //rho_0 /= 1000; + s_v_i = 1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc_x) * tc_x) * tc_x; + rho_new = rho_0; + rho_old = 0.0; + + e_T = 0.0; + M_T = 0.0; + I_m = 0.0; + PHI_v = 0.0; + B_v = 0.0; + S_v = 0.0; + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].s->type != AQ) + continue; + if (strcmp(species_list[i].s->name, "CO2") == 0) + continue; + + if (species_list[i].master_s->secondary != NULL) + gfw = species_list[i].master_s->secondary->gfw; + else + gfw = species_list[i].master_s->primary->gfw; + + if (species_list[i].s->millero[0] == 0) + s_ptr = species_list[i].master_s; + else + s_ptr = species_list[i].s; + + /* Special case: CO3-2 species */ + if (strcmp(s_ptr->name, "CO3-2") == 0) + { + if (strstr(species_list[i].s->name, "HCO3") != NULL) + { + s_ptr = s_search("HCO3-"); + } else if (strstr(species_list[i].s->name, "CO3") != NULL) + { + compute_gfw("CO3-2", &gfw); + } + } + + l_z = abs((int) s_ptr->z); + a = s_ptr->millero[0]; + b = s_ptr->millero[1]; + c = s_ptr->millero[2]; + d = s_ptr->millero[3]; + e = s_ptr->millero[4]; + f = s_ptr->millero[5]; + phi_0_i = a + (b + c * tc_x) * tc_x; + b_v_i = d + (e + f * tc_x) * tc_x; + + PHI_v += (species_list[i].s->moles * phi_0_i); + B_v += (species_list[i].s->moles * b_v_i); + S_v += (species_list[i].s->moles * l_z * (s_v_i * l_z / 2)); + + if (l_z == 0) e_T += (species_list[i].s->moles * 2); /* For uncharged species like H4SiO4 (times 2 because e_T is divided by 2 later on) */ + else e_T += (species_list[i].s->moles * l_z); + M_T += (species_list[i].s->moles * gfw); + I_m += (species_list[i].s->moles * (l_z * l_z)); + } + + /* If pure water then return rho_0 */ + if (PHI_v == 0) + return rho_0; + + solution_mass = mass_water_aq_x * 1000 + M_T; + e_T /= 2; + M_T /= e_T; + I_m /= 2; + PHI_v /= e_T; + B_v /= e_T; + S_v /= e_T; + + k = e_T / I_m; + AA_basic = k * (M_T - rho_0 * PHI_v); + BB_basic = -k * rho_0 * S_v; + CC = -k * rho_0 * B_v; + +/* DP: Replace Pickard iteration with interval halving */ +#ifdef SKIP + do { + rho_old = rho_new; + solution_volume = solution_mass / rho_new / 1000; + if (solution_volume != 0) I_v = I_m / solution_volume; + rho_new = AA_basic * I_v + BB_basic * exp(1.5 * log(I_v)) + CC * exp(2 * log(I_v)); /* exp/log is used for exponentiation */ + rho_new = rho_new / 1000 + rho_0; + } while ((fabs(rho_new - rho_old) > 1.0e-6) && (rho_new < 1.99999)); +#endif + rho_new = halve(f_rho, 0.5, 2.0, 1e-7); +/* DP: End Replace Pickard iteration with interval halving */ + + /*if (isnan(rho_new) || rho_new > 1.99999) rho_new = 1.99999;*/ + if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999; + + return rho_new; /*(rho_new - rho_0) * 1e3; */ +} +/* VP: Density End */ +/* DP: Function for interval halving */ + +LDBLE Phreeqc:: +f_rho(LDBLE rho_old, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + LDBLE rho, I_v; + Phreeqc * pThis; + + pThis = (Phreeqc *) cookie; + + pThis->solution_volume = pThis->solution_mass / rho_old / 1000; + I_v = 1.0; + if (pThis->solution_volume != 0) + I_v = pThis->I_m / pThis->solution_volume; + rho = I_v * (pThis->AA_basic + pThis->BB_basic * sqrt(I_v) + pThis->CC * (I_v)); + rho = rho / 1000 + pThis->rho_0; + return (rho - rho_old); +} + +/* DP: End function for interval halving */ + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_logk_n(const char *name) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH]; + int i; + LDBLE lk; + struct logk *logk_ptr; + LDBLE l_logk[MAX_LOG_K_INDICES]; + struct name_coef add_logk; + + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + l_logk[i] = 0.0; + } + strcpy(token, name); + logk_ptr = logk_search(token); + if (logk_ptr != NULL) + { + add_logk.name = token; + add_logk.coef = 1.0; + add_other_logk(l_logk, 1, &add_logk); + lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); + return (lk); + } + return (-999.99); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_logk_p(const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + LDBLE lk; + LDBLE l_logk[MAX_LOG_K_INDICES]; + + strcpy(token, name); + phase_ptr = phase_bsearch(token, &j, FALSE); + if (phase_ptr != NULL) + { + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + l_logk[i] = 0.0; + } + select_log_k_expression(phase_ptr->logk, l_logk); + add_other_logk(l_logk, phase_ptr->count_add_logk, phase_ptr->add_logk); + lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); + return (lk); + } + return (-999.99); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_logk_s(const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + char token[MAX_LENGTH]; + struct species *s_ptr; + LDBLE lk, l_logk[MAX_LOG_K_INDICES]; + + strcpy(token, name); + s_ptr = s_search(token); + if (s_ptr != NULL) + { + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + l_logk[i] = 0.0; + } + select_log_k_expression(s_ptr->logk, l_logk); + add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk); + lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); + return (lk); + } + return (-999.99); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_surface_charge(const char *surface_name) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr; + int i, j, k; + LDBLE charge; + struct rxn_token_temp *token_ptr; + struct master *master_ptr; + + /* + * Go through species, sum charge + */ + charge = 0; + for (k = 0; k < count_s_x; k++) + { + if (s_x[k]->type != SURF) + continue; + /* + * Match surface_name + */ + count_trxn = 0; + trxn_add(s_x[k]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ + for (i = 1; i < count_trxn; i++) + { + token_ptr = &(trxn.token[i]); + if (token_ptr->s->type != SURF) + continue; + master_ptr = trxn.token[i].s->primary; + strcpy(token, master_ptr->elt->name); + replace("_", " ", token); + ptr = token; + copy_token(token1, &ptr, &j); + if (strcmp(surface_name, token1) == 0) + { + charge += s_x[k]->moles * s_x[k]->z; + } + } + } + return (charge); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +diff_layer_total(const char *total_name, const char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in DDL layer + */ + int i, j, k, count_g; + struct surface_charge *surface_charge_ptr1; + char name[MAX_LENGTH], token[MAX_LENGTH]; + char surface_name_local[MAX_LENGTH]; + char *ptr; + struct master *master_ptr; + + LDBLE mass_water_surface; + LDBLE molality, moles_excess, moles_surface, charge; + + if (use.Get_surface_ptr() == NULL || (dl_type_x == NO_DL && + strcmp_nocase("psi", total_name) != 0 && + strcmp_nocase("psi1", total_name) != 0 && + strcmp_nocase("psi2", total_name) != 0 && + strcmp_nocase("charge", total_name) != 0 + && strcmp_nocase("charge1", + total_name) != 0 + && strcmp_nocase("charge2", + total_name) != 0 + && strcmp_nocase("sigma", + total_name) != 0 + && strcmp_nocase("sigma1", + total_name) != 0 + && strcmp_nocase("sigma2", + total_name) != 0)) + return (0); + +/* + * Find surface... + */ + i = 0; + for (j = 0; j < count_unknowns; j++) + { + /*if (use.Get_surface_ptr()->edl == TRUE) { */ + if (use.Get_surface_ptr()->type == DDL) + { + if (x[j]->type != SURFACE_CB) + continue; + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); + } + else if (use.Get_surface_ptr()->type == CD_MUSIC) + { + if (x[j]->type != SURFACE_CB) + continue; + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); + } + else + { + if (x[j]->type != SURFACE) + continue; + strcpy(token, x[j]->master[0]->elt->name); + replace("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + } + if (surface_name != NULL) + { + if (strcmp(name, surface_name) == 0) + break; + } + else + { + break; + } + } + if (j >= count_unknowns) + return (0); + strcpy(surface_name_local, name); + /* + * Psi, charge, sigma + */ + if (strcmp_nocase("psi", total_name) == 0) + { + /*if (use.Get_surface_ptr()->edl == TRUE) { */ + if (use.Get_surface_ptr()->type == DDL) + { + return ((LDBLE) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ)); + } + else if (use.Get_surface_ptr()->type == CD_MUSIC) + { + master_ptr = surface_get_psi_master(surface_name, SURF_PSI); + if (master_ptr != NULL) + { + /*return((LDBLE) (-x[j]->surface_charge->psi_master->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ)); */ + return ((LDBLE) + (-master_ptr->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / + F_KJ_V_EQ)); + } + else + { + return (0.0); + } + } + else + { + return (0); + } + } + else if (strcmp_nocase("psi1", total_name) == 0) + { + master_ptr = surface_get_psi_master(surface_name, SURF_PSI1); + if (master_ptr != NULL) + { + return ((LDBLE) + (-master_ptr->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / + F_KJ_V_EQ)); + } + else + { + return (0.0); + } + } + else if (strcmp_nocase("psi2", total_name) == 0) + { + master_ptr = surface_get_psi_master(surface_name, SURF_PSI2); + if (master_ptr != NULL) + { + return ((LDBLE) + (-master_ptr->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / + F_KJ_V_EQ)); + } + else + { + return (0.0); + } + } + else if (strcmp_nocase("charge", total_name) == 0) + { + if (use.Get_surface_ptr()->type == DDL && dl_type_x == NO_DL) + { + return ((LDBLE) (x[j]->f)); + } + else if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) + (x[j]->surface_charge->sigma0 * + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) / F_C_MOL)); + } + else + { + return (calc_surface_charge(surface_name_local)); + } + } + else if (strcmp_nocase("charge1", total_name) == 0) + { + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) + (x[j]->surface_charge->sigma1 * + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) / F_C_MOL)); + } + else + { + return (0); + } + } + else if (strcmp_nocase("charge2", total_name) == 0) + { + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) + (x[j]->surface_charge->sigma2 * + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) / F_C_MOL)); + } + else + { + return (0); + } + } + else if (strcmp_nocase("sigma", total_name) == 0) + { + if (use.Get_surface_ptr()->type == DDL) + { + if (dl_type_x != NO_DL) + { + charge = calc_surface_charge(surface_name_local); + } + else + { + charge = x[j]->f; + } + if ((x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) > 0) + { + return ((LDBLE) + (charge * F_C_MOL / + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams))); + } + else + { + return (0); + } + } + else if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) (x[j]->surface_charge->sigma0)); + } + else + { + return (0); + } + } + else if (strcmp_nocase("sigma1", total_name) == 0) + { + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) (x[j]->surface_charge->sigma1)); + } + else + { + return (0); + } + } + else if (strcmp_nocase("sigma2", total_name) == 0) + { + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + return ((LDBLE) (x[j]->surface_charge->sigma2)); + } + else + { + return (0); + } + } + else if (strcmp_nocase("water", total_name) == 0) + { + if (dl_type_x != NO_DL) + { + return (x[j]->surface_charge->mass_water); + } + else + { + return (0); + } + } +/* + * find total moles of each element in diffuse layer... + */ + surface_charge_ptr1 = x[j]->surface_charge; + mass_water_surface = surface_charge_ptr1->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + + moles_excess = + mass_water_aq_x * molality * (surface_charge_ptr1->g[count_g].g * + s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - + 1)); + moles_surface = mass_water_surface * molality + moles_excess; +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), Phreeqc:: elt_list_compare); + elt_list_combine(); + } +/* + * Return totals + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + return ((LDBLE) elt_list[j].coef); + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +equi_phase(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.Get_pp_assemblage_in() == FALSE || use.Get_pp_assemblage_ptr() == NULL) + return (0); + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + if (strcmp_nocase(x[j]->pp_assemblage_comp_name, phase_name) == 0) + { + break; + } + } +/* + * Print pure phase assemblage data + */ +#ifdef SKIP + if (j == count_unknowns) + { + /* if not an unknown */ + for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) + { + if (strcmp_nocase + (use.Get_pp_assemblage_ptr()->pure_phases[i].name, phase_name) == 0) + { + return (use.Get_pp_assemblage_ptr()->pure_phases[i].moles); + } + } + } +#endif + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + if (j == count_unknowns) + { + /* if not an unknown */ + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + if (strcmp_nocase + (it->second.Get_name().c_str(), phase_name) == 0) + { + return (it->second.Get_moles()); + } + } + } + else + { + /* if an unknown */ + if (x[j]->moles < 0.0) + x[j]->moles = 0.0; + return (x[j]->moles); + } + return (0); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_gas_comp(const char *gas_comp_name) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) + return (0); + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + if (strcmp_nocase(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), gas_comp_name) == 0) + { + struct phase *phase_ptr = phase_bsearch(gas_comp_name, &i, false); + if (phase_ptr) + { + return (phase_ptr->moles_x); + } + } + } + return (0); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_gas_p(void) +/* ---------------------------------------------------------------------- */ +{ + if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) + return (0); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_unknown == NULL) + return (0); + if (gas_unknown->moles < 1e-12) + return (0); + } + return (gas_phase_ptr->Get_total_p()); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_gas_vm(void) +/* ---------------------------------------------------------------------- */ +{ + if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) + return (0); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_unknown == NULL) + return (0); + if (gas_unknown->moles < 1e-12) + return (0); + } + // also for non-PR gas phases... + return (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_misc1(const char *s_s_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0.0); + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name) == 0) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].miscibility == TRUE) + { + return (use.Get_ss_assemblage_ptr()->s_s[j].xb1); + } + else + { + return (1.0); + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_misc2(const char *s_s_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0.0); + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name) == 0) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].miscibility == TRUE) + { + return (use.Get_ss_assemblage_ptr()->s_s[j].xb2); + } + else + { + return (1.0); + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_s_s_comp(const char *s_s_comp_name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + if (strcmp_nocase + (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, + s_s_comp_name) == 0) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + { + return (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles); + } + else + { + return (0.0); + } + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +get_calculate_value(const char *name) +/* ---------------------------------------------------------------------- */ +/* + * Gets value from a calclate_value structure + * arguments: name + * return: LDBLE of value + */ +{ + struct calculate_value *calculate_value_ptr; + calculate_value_ptr = calculate_value_search(name); + if (calculate_value_ptr == NULL) + { + error_string = sformatf( "CALC_VALUE Basic function, %s not found.", + name); + error_msg(error_string, CONTINUE); + input_error++; + return (MISSING); + } + if (name == NULL) + { + error_string = sformatf( + "Definition for calculated value not found, %s", name); + input_error++; + error_msg(error_string, CONTINUE); + return (MISSING); + } + //if (calculate_value_ptr->calculated == FALSE) + //{ + // error_string = sformatf( + // "Calculated value used before it has been calculated, %s.\nCalculated values are evalutated in the order in which they were defined.", + // name); + // input_error++; + // error_msg(error_string, CONTINUE); + // return (MISSING); + //} + char l_command[] = "run"; + PBasic interp(this, this->phrq_io); + if (calculate_value_ptr->new_def == TRUE) + { + if (interp.basic_compile + (calculate_value_ptr->commands, + &calculate_value_ptr->linebase, + &calculate_value_ptr->varbase, + &calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + + if (interp.basic_run(l_command, + calculate_value_ptr->linebase, + calculate_value_ptr->varbase, + calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + else + { + calculate_value_ptr->calculated = TRUE; + calculate_value_ptr->value = rate_moles; + } + return (calculate_value_ptr->value); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +kinetics_moles(const char *kinetics_name) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (use.Get_kinetics_in() == FALSE || use.Get_kinetics_ptr() == NULL) + return (0); + for (i = 0; i < use.Get_kinetics_ptr()->count_comps; i++) + { + if (strcmp_nocase + (use.Get_kinetics_ptr()->comps[i].rate_name, kinetics_name) == 0) + { + return (use.Get_kinetics_ptr()->comps[i].m); + } + } + + error_string = sformatf( "No data for rate %s in KINETICS keyword.", + kinetics_name); + warning_msg(error_string); + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +log_activity(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE la; + + s_ptr = s_search(species_name); + + if (s_ptr == s_eminus) + { + la = s_eminus->la; + } + else if (s_ptr == NULL || s_ptr->in == FALSE) + { + la = -99.99; + } + else if (s_ptr == s_h2o) + { + la = s_h2o->la; + } + else + { + la = s_ptr->lm + s_ptr->lg; + } + return (la); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +log_molality(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE lm; + + s_ptr = s_search(species_name); + + if (s_ptr == s_eminus) + { + lm = -99.99; + } + else if (s_ptr == NULL || s_ptr->in == FALSE) + { + lm = -99.99; + } + else if (s_ptr == s_h2o) + { + lm = log10(s_ptr->moles / mass_water_aq_x); + } + else + { + lm = s_ptr->lm; + } + return (lm); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +molality(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE m; + + s_ptr = s_search(species_name); + if (s_ptr == NULL || s_ptr == s_eminus || s_ptr->in == FALSE) + { + m = 1e-99; + } + else + { + /* m = pow(10., s_ptr->lm); */ + m = s_ptr->moles / mass_water_aq_x; + } + return (m); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +pr_pressure(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct phase *phase_ptr; + int l; + + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + error_string = sformatf( "Gas %s, not found.", phase_name); + warning_msg(error_string); + return (1e-99); + } + else if (phase_ptr->in != FALSE && phase_ptr->pr_in) + { + return phase_ptr->pr_p; + } + return (0.0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +pressure(void) +/* ---------------------------------------------------------------------- */ +{ + return (patm_x); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +pr_phi(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct phase *phase_ptr; + int l; + + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + error_string = sformatf( "Gas %s, not found.", phase_name); + warning_msg(error_string); + return (1e-99); + } + else if (phase_ptr->in != FALSE && phase_ptr->pr_in) + { + return phase_ptr->pr_phi; + } + return (1.0); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +saturation_ratio(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + int l; + LDBLE si, iap; + + iap = 0.0; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + error_string = sformatf( "Mineral %s, not found.", phase_name); + warning_msg(error_string); + return (1e-99); + } + else if (phase_ptr->in != FALSE) + { + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = iap - phase_ptr->lk; + return (pow((LDBLE) 10.0, si)); + } + return (0.0); + +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si) +/* ---------------------------------------------------------------------- */ +{ + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + int l; + + *si = -99.99; + *iap = 0.0; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + error_string = sformatf( "Mineral %s, not found.", phase_name); + warning_msg(error_string); + *si = -99; + } + else if (phase_ptr->in != FALSE) + { + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + *iap += rxn_ptr->s->la * rxn_ptr->coef; + } + *si = *iap - phase_ptr->lk; + } + else + { + return (ERROR); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_gases(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) + return (0); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + tot = 0; + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + struct phase * phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), + &i, FALSE); + if (match_elts_in_species(phase_ptr->formula, mytemplate) == TRUE) + { + if (name == NULL) + { + tot += phase_ptr->moles_x; + } + else + { + for (next_elt = phase_ptr->next_elt; + next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += next_elt->coef * phase_ptr->moles_x; + break; + } + } + } + } + } + return (tot); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_species(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + count_elts = 0; + paren_count = 0; + tot = 0; + for (i = 0; i < count_s_x; i++) + { + if (match_elts_in_species(s_x[i]->name, mytemplate) == TRUE) + { + if (name == NULL) + { + tot += s_x[i]->moles; + } + else + { + for (next_elt = s_x[i]->next_elt; next_elt->elt != NULL; + next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += next_elt->coef * s_x[i]->moles; + break; + } + } + } + } + } + return (tot); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_s_s(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE tot; + struct elt_list *next_elt; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + tot = 0; + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, mytemplate) == + 0) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == FALSE) + { + tot = 0; + break; + } + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + if (name == NULL) + { + tot += use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + } + else + { + for (next_elt = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].phase-> + next_elt; next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += + next_elt->coef * + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + break; + } + } + } + } + break; + } + } + return (tot); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +list_s_s(std::string s_s_name, cxxNameDouble &composition) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + LDBLE tot = 0; + composition.clear(); + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name.c_str()) == 0) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + composition.add(use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles); + tot += use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + } + break; + } + } + return (tot); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +match_elts_in_species(const char *name, const char *mytemplate) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, i1, l, case_no, match; + char c, c1; + char *ptr, *ptr1; + const char *replace_name, *name_ptr; + LDBLE d; + char element[MAX_LENGTH]; + char token[MAX_LENGTH], equal_list[MAX_LENGTH], elt_name[MAX_LENGTH]; + char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH]; + char str[2]; + + strcpy(token, name); + squeeze_white(token); + while (replace("(+", "(", token)); + while (replace("++++++", "+6", token)); + while (replace("+++++", "+5", token)); + while (replace("++++", "+4", token)); + while (replace("+++", "+3", token)); + while (replace("++", "+2", token)); + while (replace("------", "-6", token)); + while (replace("-----", "-5", token)); + while (replace("----", "-4", token)); + while (replace("---", "-3", token)); + while (replace("--", "-2", token)); + + ptr = token; + count_match_tokens = 0; + while ((c = *ptr) != '\0') + { + c1 = *(ptr + 1); + str[0] = c; + str[1] = '\0'; +/* + * New element + */ + if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) + { + /* + * Get new element and subscript + */ + if (get_elt(&ptr, element, &l) == ERROR) + { + return (ERROR); + } + match_tokens[count_match_tokens].name = string_hsave(element); + if (get_num(&ptr, &d) == ERROR) + { + return (ERROR); + } + match_tokens[count_match_tokens++].coef = d; + } + else + { + match_tokens[count_match_tokens].name = string_hsave(str); + match_tokens[count_match_tokens++].coef = 1.0; + ptr += 1; + } + } + /* + * Replace elements with first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) + { + replace("{", "", equal_list); + replace("}", "", equal_list); + while (replace(",", " ", equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list from template + */ + if (copy_token(elt_name, &ptr1, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a nonempty list of element names in isotope sum. %s", + mytemplate); + error_msg(error_string, CONTINUE); + return (ERROR); + } + replace_name = string_hsave(elt_name); + /* + * Replace in species all equivalent names from template + */ + while (copy_token(elt_name, &ptr1, &l) != EMPTY) + { + name_ptr = string_hsave(elt_name); + for (i = 0; i < count_match_tokens; i++) + { + if (name_ptr == match_tokens[i].name) + { + match_tokens[i].name = replace_name; + } + } + } + } + /* + * Combine contiguous elements + */ + i1 = 0; + for (i = 1; i < count_match_tokens; i++) + { + if ((isupper((int) (match_tokens[i].name[0])) != FALSE) + && (match_tokens[i].name == match_tokens[i1].name)) + { + match_tokens[i1].coef += match_tokens[i].coef; + } + else + { + i1++; + match_tokens[i1].name = match_tokens[i].name; + match_tokens[i1].coef = match_tokens[i].coef; + } + } + count_match_tokens = i1 + 1; + /* + * write out string + */ + token[0] = '\0'; + for (i = 0; i < count_match_tokens; i++) + { + strcat(token, match_tokens[i].name); + if (match_tokens[i].coef != 1.0) + { + sprintf(token1, "%g", (double) match_tokens[i].coef); + strcat(token, token1); + } + } + /* + * Write a template name using first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) + { + strcpy(equal_list1, equal_list); + replace("{", "", equal_list); + replace("}", "", equal_list); + while (replace(",", " ", equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list + */ + if (copy_token(elt_name, &ptr1, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a nonempty list of element names in isotope sum. %s", + mytemplate); + error_msg(error_string, CONTINUE); + return (ERROR); + } + replace_name = string_hsave(elt_name); + replace(equal_list1, replace_name, template1); + squeeze_white(template1); + ptr = template1; + } + /* + * Compare string + */ + /* Cases: 0 exact match + * 1 leading wild card + * 2 trailing wild card + * 3 leading and trailing wild card + */ + case_no = 0; + if (template1[0] == '*') + case_no = 1; + l = (int) strlen(template1); + if (template1[l - 1] == '*') + { + if (case_no != 1) + { + case_no = 2; + } + else + { + case_no = 3; + } + } + while (replace("*", "", template1)); + match = FALSE; + switch (case_no) + { + case 0: + /* exact match */ + if (strcmp(token, template1) == 0) + match = TRUE; + break; + case 1: + /* leading wild card */ + if ((ptr = strstr(token, template1)) == NULL) + { + match = FALSE; + } + else + { + if (strcmp(ptr, template1) == 0) + match = TRUE; + } + break; + case 2: + /* trailing wild card */ + if (strstr(token, template1) == token) + match = TRUE; + break; + case 3: + /* trailing wild card */ + if (strstr(token, template1) != NULL) + match = TRUE; + break; + } + return (match); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +extract_bracket(char **string, char *bracket_string) +/* ---------------------------------------------------------------------- */ +{ + char *ptr, *ptr1; + + if ((ptr = strstr(*string, "{")) == NULL) + return (FALSE); + strcpy(bracket_string, ptr); + if ((ptr1 = strstr(bracket_string, "}")) == NULL) + { + error_string = sformatf( + "No matching bracket (}) in isotope template string %s", + *string); + error_msg(error_string, CONTINUE); + input_error++; + return (FALSE); + } + ptr1[1] = '\0'; + *string = strstr(*string, "}"); + *string += 1; + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +surf_total(const char *total_name, const char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in LDBLE layer + */ + int i, j, k; + char name[MAX_LENGTH], token[MAX_LENGTH]; + char surface_name_local[MAX_LENGTH]; + char *ptr; + + if (use.Get_surface_ptr() == NULL) + return (0); + +/* + * Find surface... + */ + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE) + continue; + strcpy(token, x[j]->master[0]->elt->name); + replace("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + if (surface_name != NULL) + { + if (strcmp(name, surface_name) == 0) + break; + } + else + { + break; + } + } + if (j >= count_unknowns) + return (0); + strcpy(surface_name_local, name); +/* + * find total moles of each element in diffuse layer... + */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type != SURF) + continue; + for (i = 0; s_x[j]->next_elt[i].elt != NULL; i++) + { + if (s_x[j]->next_elt[i].elt->master->type != SURF) continue; + + strcpy(token, s_x[j]->next_elt[i].elt->name); + replace("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + if (strcmp(name, surface_name_local) == 0) + { +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, s_x[j]->moles); + //fprintf(stderr, "%15s\t%e\t%s\t%s\n", s_x[j]->name, s_x[j]->moles, name, surface_name_local ); + break; + } + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Return totals + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + return ((LDBLE) elt_list[j].coef); + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +total(const char *total_name) +/* ---------------------------------------------------------------------- */ +{ + struct master *master_ptr; + LDBLE t; + int i; + + if (strcmp(total_name, "H") == 0) + { + return (total_h_x / mass_water_aq_x); + } + if (strcmp(total_name, "O") == 0) + { + return (total_o_x / mass_water_aq_x); + } + master_ptr = master_bsearch(total_name); + t = 0.0; + if (master_ptr == NULL) + { + if (strcmp_nocase(total_name, "water") == 0) + { + return (mass_water_aq_x); + } + else if (strcmp_nocase(total_name, "charge") == 0) + { + return (cb_x / mass_water_aq_x); + } +/* + sprintf (error_string, "Can not find definition for master species, %s.", + total_name); + warning_msg (error_string); +*/ + } +/* + * Primary master species + */ + else if (master_ptr->primary == TRUE) + { + /* + * Not a redox element + */ + if (master_ptr->s->secondary == NULL) + { + t = master_ptr->total / mass_water_aq_x; + /* + * Redox element, need to sum totals of all redox states + */ + } + else + { + t = 0; + for (i = master_ptr->number + 1; + (i < count_master && master[i]->elt->primary == master_ptr); + i++) + { + t += master[i]->total / mass_water_aq_x; + } + } + } +/* + * Secondary master species + */ + else + { + t = master_ptr->total / mass_water_aq_x; + } + return (t); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +total_mole(const char *total_name) +/* ---------------------------------------------------------------------- */ +{ + struct master *master_ptr; + LDBLE t; + int i; + + if (strcmp(total_name, "H") == 0) + { + return (total_h_x); + } + if (strcmp(total_name, "O") == 0) + { + return (total_o_x); + } + master_ptr = master_bsearch(total_name); + t = 0.0; + if (master_ptr == NULL) + { + if (strcmp_nocase(total_name, "water") == 0) + { + return (mass_water_aq_x / gfw_water * 1000.); + } + else if (strcmp_nocase(total_name, "charge") == 0) + { + return (cb_x); + } +/* + sprintf (error_string, "Can not find definition for master species, %s.", + total_name); + warning_msg (error_string); +*/ + } +/* + * Primary master species + */ + else if (master_ptr->primary == TRUE) + { + /* + * Not a redox element + */ + if (master_ptr->s->secondary == NULL) + { + t = master_ptr->total; + /* + * Redox element, need to sum totals of all redox states + */ + } + else + { + t = 0; + for (i = master_ptr->number + 1; + (i < count_master && master[i]->elt->primary == master_ptr); + i++) + { + t += master[i]->total; + } + } + } +/* + * Secondary master species + */ + else + { + t = master_ptr->total; + } + return (t); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; + + sys_tot = 0; + count_sys = 0; + max_sys = 100; + space((void **) ((void *) &sys), INIT, &max_sys, + sizeof(struct system_species)); + if (strcmp_nocase(total_name, "elements") == 0) + { + system_total_elements(); + } + else if (strcmp_nocase(total_name, "phases") == 0) + { + system_total_si(); + } + else if (strcmp_nocase(total_name, "aq") == 0) + { + system_total_aq(); + } + else if (strcmp_nocase(total_name, "ex") == 0) + { + system_total_ex(); + } + else if (strcmp_nocase(total_name, "surf") == 0) + { + system_total_surf(); + } + else if (strcmp_nocase(total_name, "s_s") == 0) + { + system_total_s_s(); + } + else if (strcmp_nocase(total_name, "gas") == 0) + { + system_total_gas(); + } + else + { + if (strstr(total_name, "(") == NULL) + { + system_total_elt(total_name); + } + else + { + system_total_elt_secondary(total_name); + } + } + /* + * Sort system species + */ + if (count_sys > 1) + { + qsort(sys, (size_t) count_sys, + (size_t) sizeof(struct system_species), system_species_compare); + } + /* + * malloc space + */ + *names = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + if (names == NULL) + malloc_error(); + *types = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + if (types == NULL) + malloc_error(); + *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(LDBLE)); + if (moles == NULL) + malloc_error(); + + (*names)[0] = NULL; + (*types)[0] = NULL; + (*moles)[0] = 0; + for (i = 0; i < count_sys; i++) + { + (*names)[i + 1] = sys[i].name; + (*types)[i + 1] = sys[i].type; + (*moles)[i + 1] = sys[i].moles; + } + *count = (LDBLE) count_sys; + if (strcmp_nocase(total_name, "elements") == 0) + { + sys_tot = 0;; + for (i = 0; i < count_sys; i++) + { + if (strcmp(sys[i].type, "dis") == 0 && + strstr(sys[i].name, "(") == NULL && + strcmp(sys[i].name, "H") != 0 + && strcmp(sys[i].name, "O") != 0) + { + sys_tot += sys[i].moles; + } + } + } + PHRQ_free(sys); + return (sys_tot); +} + +/* ---------------------------------------------------------------------- */ +std::string Phreeqc:: +phase_formula(std::string phase_name, cxxNameDouble &stoichiometry) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns formula of mineral + * Also returns arrays of elements and stoichiometry in elts_arg and coef_arg + */ + stoichiometry.clear(); + std::string formula; + + int j; + struct phase *phase_ptr = phase_bsearch(phase_name.c_str(), &j, FALSE); + if (phase_ptr != NULL) + { + formula.append(phase_ptr->formula); + cxxNameDouble nd(phase_ptr->next_elt); + stoichiometry = nd; + } + + return (formula); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_elements(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE t; + char name[MAX_LENGTH]; + struct master *master_ptr; + + /* + * Include H and O + */ + sys[count_sys].name = string_duplicate("H"); + sys[count_sys].moles = total_h_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + sys[count_sys].name = string_duplicate("O"); + sys[count_sys].moles = total_o_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + /* + * Include H(1) and O(-2) + */ + sys[count_sys].name = string_duplicate("H(1)"); + sys[count_sys].moles = solution_sum_secondary("H(1)"); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + sys[count_sys].name = string_duplicate("O(-2)"); + sys[count_sys].moles = solution_sum_secondary("O(-2)"); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("dis"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + + for (i = 0; i < count_master; i++) + { + master_ptr = master[i]; + if (master_ptr->primary == TRUE && master_ptr->total_primary <= 0) + continue; + if (master_ptr->in == FALSE + && (master_ptr->primary == FALSE + || master_ptr->total_primary == 0)) + continue; + /* + * H and O + */ + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + if (master_ptr->primary == TRUE) + { + if (master_ptr->total_primary > 0) + { + t = master_ptr->total_primary; + /* + * Not a redox element + */ + } + else if (master_ptr->s->secondary == NULL) + { + t = master_ptr->total; + /* + * Redox element, need to sum totals of all redox states + */ + } + else + { + t = 0; + for (j = master_ptr->number + 1; + master[j]->elt->primary == master_ptr; j++) + { + t += master[j]->total; + } + } + /* + * Secondary master species + */ + } + else + { + t = master_ptr->total; + } + strcpy(name, master[i]->elt->name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = t; + sys_tot += sys[count_sys].moles; + if (master[i]->s->type <= SOLID) + { + sys[count_sys].type = string_duplicate("dis"); + } + else if (master[i]->s->type == EX) + { + sys[count_sys].type = string_duplicate("ex"); + } + else if (master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + { + sys[count_sys].type = string_duplicate("surf"); + } + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_si(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE si, iap; + struct rxn_token *rxn_ptr; + char name[MAX_LENGTH]; + + for (i = 0; i < count_phases; i++) + { + if (phases[i]->in == FALSE || phases[i]->type != SOLID) + continue; +/* + * Print saturation index + */ + iap = 0.0; + for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = -phases[i]->lk + iap; + strcpy(name, phases[i]->name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = si; + if (si > sys_tot) + sys_tot = si; + sys[count_sys].type = string_duplicate("phase"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_aq(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ) + continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("aq"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_ex(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != EX) + continue; + if (s_x[i]->primary != NULL) + continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("ex"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_surf(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != SURF) + continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("surf"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_gas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; + +/* + * find total in gas phase + */ + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), + &i, FALSE); + assert(phase_ptr); + sys[count_sys].name = string_duplicate(phase_ptr->name); + sys[count_sys].moles = phase_ptr->moles_x; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_s_s(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, k; + +/* + * Solid solutions + */ + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; i++) + { + sys[count_sys].name = + string_duplicate(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. + phase->name); + sys[count_sys].moles = + use.Get_ss_assemblage_ptr()->s_s[k].comps[i].moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_elt(const char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j, k, count_g; + LDBLE molality, moles_excess, moles_surface, mass_water_surface; + char name[MAX_LENGTH]; + +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) + { + count_elts = 0; + paren_count = 0; + add_elt_list(s_x[i]->next_elt, s_x[i]->moles); + + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + if (s_x[i]->type == AQ) + { + sys[count_sys].type = string_duplicate("aq"); + } + else if (s_x[i]->type == EX) + { + sys[count_sys].type = string_duplicate("ex"); + /* subtract again the dummy moles of primary exchange species... */ + if (s_x[i]->primary != NULL) + { + sys_tot -= elt_list[j].coef; + } + } + else if (s_x[i]->type == SURF) + { + sys[count_sys].type = string_duplicate("surf"); + } + else if (s_x[i]->type == HPLUS) + { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_h_x; */ + } + else if (s_x[i]->type == H2O) + { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_o_x; */ + } + else + { + error_msg("System_total", STOP); + } + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + { + /* + * Find position of component in surface charge data + */ + i = -1; + for (k = 0; k < count_unknowns; k++) + { + if (x[k]->type != SURFACE_CB) + continue; + i++; + /* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + mass_water_surface = x[k]->surface_charge->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + moles_excess = + mass_water_aq_x * molality * + (x[k]->surface_charge->g[count_g].g * s_x[j]->erm_ddl + + mass_water_surface / mass_water_aq_x * (s_x[j]->erm_ddl - + 1)); + moles_surface = mass_water_surface * molality + moles_excess; + /* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Print totals + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + strcpy(name, x[k]->master[0]->elt->name); + replace("_psi", "", name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("diff"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + } +/* + * find total moles in mineral phases + */ + if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PP) + continue; + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + if (it->second.Get_add_formula().size() > 0) + continue; + count_elts = 0; + paren_count = 0; + int j; + struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + add_elt_list(phase_ptr->next_elt, x[i]->moles); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("equi"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + } +/* + * Solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) + { + if (use.Get_ss_assemblage_ptr()->s_s[k].s_s_in == TRUE) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; + i++) + { + count_elts = 0; + paren_count = 0; + add_elt_list(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. + phase->next_elt, + use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. + moles); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), + elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(use.Get_ss_assemblage_ptr()-> + s_s[k].comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, + &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +/* + * find total in gas phase + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + struct phase *phase_ptr = + phase_bsearch(gas_phase_ptr->Get_gas_comps()[i].Get_phase_name().c_str(), &k, FALSE); + assert(phase_ptr); + if (phase_ptr->in == TRUE) + { + count_elts = 0; + paren_count = 0; + add_elt_list(phase_ptr->next_elt, phase_ptr->moles_x); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_elt_secondary(const char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j, k, l, count_g; + LDBLE molality, moles_excess, moles_surface, mass_water_surface, sum, + coef; + char name[MAX_LENGTH]; +/* + * find total moles in aq, surface, and exchange + */ + for (i = 0; i < count_s_x; i++) + { + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) + { + add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); + } + else + { + add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + if (s_x[i]->type == AQ) + { + sys[count_sys].type = string_duplicate("aq"); + } + else if (s_x[i]->type == EX) + { + sys[count_sys].type = string_duplicate("ex"); + } + else if (s_x[i]->type == SURF) + { + sys[count_sys].type = string_duplicate("surf"); + } + else if (s_x[i]->type == HPLUS) + { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_h_x; */ + } + else if (s_x[i]->type == H2O) + { + sys[count_sys].type = string_duplicate("aq"); + /* sys[count_sys].moles = total_o_x; */ + } + else + { + error_msg("System_total", STOP); + } + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + { + /* + * Find position of component in surface charge data + */ + i = -1; + for (k = 0; k < count_unknowns; k++) + { + if (x[k]->type != SURFACE_CB) + continue; + i++; + /* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + mass_water_surface = x[k]->surface_charge->mass_water; + sum = 0; + for (j = 0; j < count_s_x; j++) + { + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) + { + add_elt_list(s_x[i]->next_secondary, 1); + } + else + { + add_elt_list(s_x[i]->next_sys_total, 1); + } + for (l = 0; l < count_elts; l++) + { + if (strcmp(elt_list[l].elt->name, total_name) == 0) + { + coef = elt_list[l].coef; + if (s_x[j]->type > H2O) + continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + moles_excess = + mass_water_aq_x * molality * + x[k]->surface_charge->g[count_g].g; + moles_surface = + mass_water_surface * molality + moles_excess; + sum += moles_surface * coef; + break; + } + } + if (l >= count_elts) + continue; + strcpy(name, x[k]->master[0]->elt->name); + replace("_psi", "", name); + sys[count_sys].name = string_duplicate(name); + sys[count_sys].moles = sum; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("diff"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } +/* + * find total moles in mineral phases + */ + if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PP) + continue; + //if (x[i]->pure_phase->add_formula != NULL) + // continue; + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + if (it->second.Get_add_formula().size() > 0) + continue; + count_elts = 0; + paren_count = 0; + int j; + struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + add_elt_list(phase_ptr->next_sys_total, x[i]->moles); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("equi"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + } +/* + * Solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) + { + if (use.Get_ss_assemblage_ptr()->s_s[k].s_s_in == TRUE) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; + i++) + { + count_elts = 0; + paren_count = 0; + add_elt_list(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. + phase->next_sys_total, + use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. + moles); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), + elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(use.Get_ss_assemblage_ptr()-> + s_s[k].comps[i].phase->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, + &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +/* + * find total in gas phase + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + struct phase *phase_ptr = + phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &i, FALSE); + assert(phase_ptr); + if (phase_ptr->in == TRUE) + { + count_elts = 0; + paren_count = 0; + add_elt_list(phase_ptr->next_sys_total, + phase_ptr->moles_x); + + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for (int j1 = 0; j1 < (size_t) count_elts; j1++) + { + if (strcmp(elt_list[j1].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j1].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("gas"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + break; + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +solution_sum_secondary(const char *total_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i, j; + LDBLE sum; +/* + * find total moles in aq, surface, and exchange + */ + sum = 0; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > H2O) + continue; + count_elts = 0; + paren_count = 0; + if (s_x[i]->next_secondary != NULL) + { + add_elt_list(s_x[i]->next_secondary, s_x[i]->moles); + } + else + { + add_elt_list(s_x[i]->next_sys_total, s_x[i]->moles); + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Look for element + */ + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sum += elt_list[j].coef; + break; + } + } + } + return (sum); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_species_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct system_species *a, *b; + + a = (const struct system_species *) ptr1; + b = (const struct system_species *) ptr2; + if (a->moles < b->moles) + return (1); + if (a->moles > b->moles) + return (-1); + return (0); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_total_solids(cxxExchange *exchange_ptr, + cxxPPassemblage *pp_assemblage_ptr, + cxxGasPhase *gas_phase_ptr, + struct ss_assemblage *ss_assemblage_ptr, + struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in solid phases + */ + int i, j; + + count_elts = 0; + paren_count = 0; +/* + * find total moles in exchanger + */ + if (exchange_ptr != NULL) + { + std::map::iterator it = exchange_ptr->Get_exchComps().begin(); + for ( ; it != exchange_ptr->Get_exchComps().end(); it++) + { + add_elt_list(it->second.Get_totals(), 1.0); + } + } + if (surface_ptr != NULL) + { + for (i = 0; i < surface_ptr->count_comps; i++) + { + add_elt_list(surface_ptr->comps[i].totals, 1.0); + } + } + if (ss_assemblage_ptr != NULL) + { + for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) + { + for (j = 0; j < ss_assemblage_ptr->s_s[i].count_comps; j++) + { + add_elt_list(ss_assemblage_ptr->s_s[i].comps[j].phase-> + next_elt, + ss_assemblage_ptr->s_s[i].comps[j].moles); + } + } + } + if (gas_phase_ptr != NULL) + { + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + struct phase *phase_ptr = + phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &i, FALSE); + add_elt_list(phase_ptr->next_elt, gas_phase_ptr->Get_gas_comps()[j].Get_moles()); + } + } + if (pp_assemblage_ptr != NULL) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + int j; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &j, FALSE); + add_elt_list(phase_ptr->next_elt, + it->second.Get_moles()); + } + //for (i = 0; i < pp_assemblage_ptr->count_comps; i++) + //{ + // add_elt_list(pp_assemblage_ptr->pure_phases[i].phase->next_elt, + // pp_assemblage_ptr->pure_phases[i].moles); + //} + } + + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + return (OK); +} + +LDBLE Phreeqc:: +iso_value(const char *total_name) +{ + int j; + char token[MAX_LENGTH]; + char my_total_name[MAX_LENGTH]; + strcpy(token, ""); + strcpy(my_total_name, total_name); + while (replace(" ","_",my_total_name)); + for (j = 0; j < count_isotope_ratio; j++) + { + if (isotope_ratio[j]->ratio == MISSING) + continue; + if (strcmp(my_total_name, isotope_ratio[j]->name) != 0) + continue; + return (isotope_ratio[j]->converted_ratio); + } + strcpy(my_total_name, total_name); + while (replace("[","",my_total_name)); + while (replace("]","",my_total_name)); + strcat(token,"R("); + strcat(token,my_total_name); + strcat(token,")"); + for (j = 0; j < count_isotope_ratio; j++) + { + if (isotope_ratio[j]->ratio == MISSING) + continue; + if (strcmp(token, isotope_ratio[j]->name) != 0) + continue; + return (isotope_ratio[j]->converted_ratio); + } + return -1000.; +} + +char * Phreeqc:: +iso_unit(const char *total_name) +{ + int j; + char token[MAX_LENGTH], unit[MAX_LENGTH]; + struct master_isotope *master_isotope_ptr; + char my_total_name[MAX_LENGTH]; + strcpy(token, ""); + strcpy(my_total_name, total_name); + while (replace(" ","_",my_total_name)); + strcpy(unit, "unknown"); + for (j = 0; j < count_isotope_ratio; j++) + { + if (isotope_ratio[j]->ratio == MISSING) + continue; + if (strcmp(my_total_name, isotope_ratio[j]->name) != 0) + continue; + master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name); + if (master_isotope_ptr != NULL) + { + strcpy(unit, master_isotope_ptr->units); + } + return string_duplicate(unit); + } + strcpy(my_total_name, total_name); + while (replace("[","",my_total_name)); + while (replace("]","",my_total_name)); + strcat(token,"R("); + strcat(token,my_total_name); + strcat(token,")"); + for (j = 0; j < count_isotope_ratio; j++) + { + if (isotope_ratio[j]->ratio == MISSING) + continue; + if (strcmp(token, isotope_ratio[j]->name) != 0) + continue; + master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name); + if (master_isotope_ptr != NULL) + { + strcpy(unit, master_isotope_ptr->units); + } + return string_duplicate(unit); + } + return string_duplicate(unit); +} + +int Phreeqc:: +basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) +{ + return this->basic_interpreter->basic_compile(commands, lnbase, vbase, lpbase); +} + +int Phreeqc:: +basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) +{ + return this->basic_interpreter->basic_run(commands, lnbase, vbase, lpbase); +} + +void Phreeqc:: +basic_free(void) +{ + delete this->basic_interpreter; +} + diff --git a/rename_cpp/chart_icon.gif b/rename_cpp/chart_icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..53bfb63abdc7c3d1d990ec5043b314b34fd1d5f8 GIT binary patch literal 2141 zcmX|=c~sJA7snrg)CvuZ6qJmLG;v9Z)U-@+#fY%nGA%1yB61tTGpFi$%&$-|Gy`TG>^90cS-Pi9q2v&j5 z03cupO(g>X<2guGh#(oeUxgv@FeKT~pbEoO$bt~Qt~^Mq6ql-?RvzA!C(}X@3=!1~ zA^1x1HhoDmR4m+3I;%+KF<=Z~5Ep8eA#H?Qj|NJj3hyCdJL$W`Lt01{$7V}a4*ig9 z9KwVtd94u9OMpyOsik7YephS+4DS_?5MHTX!Sq7}lVs_OFq@{sJyq@$JQ#Fl~o(4b#0OEKK=lApMfM6;NKDWY7M^Y;;=dZbl|BcfVTtx zB#_2ujiwuHZ;#7O0;c?%+MYc+Q?8Dqm#`Av8%$QmVH5Q}Uv{~OEI%DMXbbp#0Hz-f z;^qQi0bpS8ZyuHjz$EyI1^`*|e;yV^FZroy1F+yIFg*pZSiMIh@;U776xceq3m^Cb z@Lk`m$LH1E22=m?qq_aTT_s2g*7FnVw38+}ENhM*KJ^}8s{w0{?H9`72q4M@G}AV~ zllOp0Q-J0C^wh)Y@3}*s3?|*3rX^w1_#nrCbshj?09NZ~fh7QZ0>Bo4zAwcrkq#XA z`8)$o`M<=At@a1Pp<=Ka0cSpA!c5a@{vE6r8b~O9goY{Lh{Pwnaqf2JtSJ`Vj0~hA} zJz`rm+MK)a#+82ajFokT1L3cqo%K6GF3E6D*?Tdxo>n+m;)Z-y)V|=p@~cDqqiXtv z1grmkh#o?P{hs*u=Z{Qy+7iRX!Ac)rc?vU^Ocy1I7rbRm^G&n1u=AT->tYM;3{>$!Xp z0krQcWXlGuB6hpn+;PH;AEr*Iez83A)B)9FnZz+_dWuu%AL%XHnOa4i$2y#xgLqPN zbKIQx3T0$&q%6l)X)Y&sS~2TKaxa~t>kNI0%&5z|O%8=f0*rkX5eVx$FWYIz_&^NY ztpDIJZN93sF>?NTN+wL9Dn1!oW3C>^5n0qb$Cby&?P-&ui{8R-Idv4RSj;qNNenMZ z3EgMC%mLMP`9p18PD&_)nuojd($dE$g=jgk--lwq^qM=xvjZgw;#KGS<$kU2qTlI_ z#?<*w*oD3tYZEqw+iB<%yvk2+5Ds8Q3XZ?k8p8B4Oc8)@?E$97-j9t+C z(&0lt+WCMVg6O=NV&oriSaQ#SrbBm2*GNfAE;93_HkHYQD@$UXhLU}(1BQ?M?}6J? zOe*?E<(AirInN+9>f!|98)rT8u{Xj5S=4#`(tG(tzN2v3v2G6*l+vO^aflGW~F_*x;u) z|DA_l_)T~foP5tOiI|R##ig*9hQELdTkqkc#DkT*W;cL483W*`>@VH%lJl5u&rv!u zgquTX*!ar$U4caoUS1Bx+IVFLF{30o8!gLN9yYS9`Qh$x!{Rlb6ZVYlaS2v$MEAXS zlmKIoM-G+ONWjvt&e!?y+C@_)Z#-X zg;!+1$oQ`auRwD}n=R#G)_4kHxuigYllQ%Pa zu}1VB>ct5M=noXrytl`Hg@y=3a-uE0Hz@L5ahXbPDP^atB^X-?HL zYDnSqppd3_C5_@(I>BypF@pfCm%|N+`F)Yc2TNKZ;{{-#uYi~Z5@Xs-@^+|V@(^YH z%0S$TCye|u0-SR)5Lb+Q7(dulv6yPGXcr-qlYyA0MqCJ}s_(aII44_Ko(Urj^cOa6 zKl7Sm8<02ck(n{_zCx>t56q*_`&GN0P(`Wp-b8+woh?6wx~|#SeruqRky&=0k+6E* Vx1xOhwd%pH1pffb;!FTM{{fu%o3H=? literal 0 HcmV?d00001 diff --git a/rename_cpp/cl1.cpp b/rename_cpp/cl1.cpp new file mode 100644 index 00000000..97712778 --- /dev/null +++ b/rename_cpp/cl1.cpp @@ -0,0 +1,890 @@ +#include +#include +#include +#include + +#include "Phreeqc.h" +#include "phqalloc.h" + +/* debug +#define DEBUG_CL1 +#define CHECK_ERRORS + */ + +int Phreeqc:: +cl1(int k, int l, int m, int n, + int l_nklmd, int l_n2d, + LDBLE * q, + int *l_kode, LDBLE l_toler, + int *l_iter, LDBLE * l_x, LDBLE * l_res, LDBLE * l_error, + LDBLE * l_cu, int *l_iu, int *l_s, int check) +{ + /* System generated locals */ + union double_or_int + { + int ival; + LDBLE dval; + } *q2; + + /* Local variables */ + int nklm; + LDBLE xmin, xmax; + int iout = 0; + // static i runs faster on windows + int i, j; + LDBLE l_z; + int maxit, n1, n2; + LDBLE pivot; + int ia, ii, kk, nk, js; + int in = 0; + LDBLE sn; + int iphase, kforce; + LDBLE zu, zv; + LDBLE tpivot; + int klm, jmn, nkl, jpn; + LDBLE cuv, sum; + int klm1; + int q_dim, cu_dim; + int kode_arg; + LDBLE check_toler; +#ifdef CHECK_ERRORS + char **col_name, **row_name; + int *row_back, *col_back; +#endif +/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ +/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ +/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ +/* AX=B */ +/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ +/* CX=D */ +/* AND M LINEAR INEQUALITY CONSTRAINTS */ +/* EX.LE.F. */ +/* DESCRIPTION OF PARAMETERS */ +/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ +/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ +/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ +/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ +/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ +/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ +/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ +/* AT LEAST N2D COLUMNS. */ +/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ +/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ +/* AND N+1 COLUMNS OF Q AS FOLLOWS */ +/* A B */ +/* Q = C D */ +/* E F */ +/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ +/* KODE A CODE USED ON ENTRY TO, AND EXIT */ +/* FROM, THE SUBROUTINE. */ +/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ +/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ +/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ +/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ +/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ +/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ +/* RES (SEE BELOW). */ +/* ON EXIT, KODE HAS ONE OF THE */ +/* FOLLOWING VALUES */ +/* 0- OPTIMAL SOLUTION FOUND, */ +/* 1- NO FEASIBLE SOLUTION TO THE */ +/* CONSTRAINTS, */ +/* 2- CALCULATIONS TERMINATED */ +/* PREMATURELY DUE TO ROUNDING ERRORS, */ +/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ +/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ +/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ +/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ +/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ +/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ +/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ +/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ +/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ +/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ +/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ +/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ +/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ +/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ +/* ON EXIT THIS ARRAY CONTAINS A */ +/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ +/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ +/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ +/* VARIABLES. THE VALUES -1, 0, OR 1 */ +/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ +/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ +/* OR .GE.0 RESPECTIVELY. */ +/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ +/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ +/* IN THE FIRST K COMPONENTS, D-CX IN THE */ +/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ +/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ +/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ +/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ +/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ +/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ +/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ +/* RESPECTIVELY. */ +/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ +/* ABSOLUTE VALUES OF THE RESIDUALS. */ +/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ +/* WORKSPACE. */ +/* DOUBLE PRECISION DBLE */ +/* REAL */ + +/* INITIALIZATION. */ + + zv = 0; + kode_arg = *l_kode; + cl1_space(check, l_n2d, k + l + m, l_nklmd); + +/* Parameter adjustments */ + q_dim = l_n2d; + q2 = (union double_or_int *) q; + cu_dim = l_nklmd; + +/* Function Body */ + maxit = *l_iter; + n1 = n + 1; + n2 = n + 2; + nk = n + k; + nkl = nk + l; + klm = k + l + m; + klm1 = klm + 1; + nklm = n + klm; + kforce = 1; + *l_iter = 0; + js = 0; + ia = -1; + +/* SET UP LABELS IN Q. */ + for (j = 0; j < n; ++j) + { + q2[klm1 * q_dim + j].ival = j + 1; + } +/* L10: */ + for (i = 0; i < klm; ++i) + { + q2[i * q_dim + n1].ival = n + i + 1; + if (q2[i * q_dim + n].dval < 0.) + { + for (j = 0; j < n1; ++j) + { + q2[i * q_dim + j].dval = -q2[i * q_dim + j].dval; + } + q2[i * q_dim + n1].ival = -q2[i * q_dim + n1].ival; +/* L20: */ + } + } +/* L30: */ +/* SET UP PHASE 1 COSTS. */ + iphase = 2; +#ifdef DEBUG_CL1 + output_msg(sformatf( "Set up phase 1 costs\n")); +#endif +/* Zero first row of cu and iu */ + memcpy((void *) &(l_cu[0]), (void *) &(scratch[0]), + (size_t) nklm * sizeof(LDBLE)); + for (j = 0; j < nklm; ++j) + { + l_iu[j] = 0; + } +/* L40: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L40\n")); +#endif + if (l != 0) + { + for (j = nk; j < nkl; ++j) + { + l_cu[j] = 1.; + l_iu[j] = 1; + } +/* L50: */ + iphase = 1; + } + +/* Copy first row of cu and iu to second row */ + memcpy((void *) &(l_cu[cu_dim]), (void *) &(l_cu[0]), + (size_t) nklm * sizeof(LDBLE)); + memcpy((void *) &(l_iu[cu_dim]), (void *) &(l_iu[0]), + (size_t) nklm * sizeof(int)); + +/* L60: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L60\n")); +#endif + if (m != 0) + { + for (j = nkl; j < nklm; ++j) + { + l_cu[cu_dim + j] = 1.; + l_iu[cu_dim + j] = 1; + jmn = j - n; + if (q2[jmn * q_dim + n1].ival < 0) + { + iphase = 1; + } + } +/* L70: */ + } +/* L80: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L80\n")); +#endif + if (*l_kode != 0) + { + for (j = 0; j < n; ++j) + { + if (l_x[j] < 0.) + { +/* L90: */ + l_cu[j] = 1.; + l_iu[j] = 1; + } + else if (l_x[j] > 0.) + { + l_cu[cu_dim + j] = 1.; + l_iu[cu_dim + j] = 1; + } + } +/* L110: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L110\n")); +#endif + for (j = 0; j < k; ++j) + { + jpn = j + n; + if (l_res[j] < 0.) + { +/* L120: */ + l_cu[jpn] = 1.; + l_iu[jpn] = 1; + if (q2[j * q_dim + n1].ival > 0) + { + iphase = 1; + } + } + else if (l_res[j] > 0.) + { +/* L130: */ + l_cu[cu_dim + jpn] = 1.; + l_iu[cu_dim + jpn] = 1; + if (q2[j * q_dim + n1].ival < 0) + { + iphase = 1; + } + } + } +/* L140: */ + } +/* L150: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L150\n")); +#endif + if (iphase == 2) + { + goto L500; + } +/* COMPUTE THE MARGINAL COSTS. */ + L160: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L160\n")); +#endif + for (j = js; j < n1; ++j) + { + sum = 0.; + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + if (ii < 0) + { + l_z = l_cu[cu_dim - ii - 1]; + } + else + { + l_z = l_cu[ii - 1]; + } + sum += q2[i * q_dim + j].dval * l_z; + } + q2[klm * q_dim + j].dval = sum; + } + for (j = js; j < n; ++j) + { + ii = q2[klm1 * q_dim + j].ival; + if (ii < 0) + { + l_z = l_cu[cu_dim - ii - 1]; + } + else + { + l_z = l_cu[ii - 1]; + } + q2[klm * q_dim + j].dval -= l_z; + } +/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ + L240: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L240, xmax %e\n", xmax)); +#endif + xmax = 0.; + if (js >= n) + { + goto L490; /* test for optimality */ + } + for (j = js; j < n; ++j) + { + zu = q2[klm * q_dim + j].dval; + ii = q2[klm1 * q_dim + j].ival; + if (ii > 0) + { + zv = -zu - l_cu[ii - 1] - l_cu[cu_dim + ii - 1]; + } + else + { + ii = -ii; + zv = zu; + zu = -zu - l_cu[ii - 1] - l_cu[cu_dim + ii - 1]; + } +/* L260 */ + if (kforce == 1 && ii > n) + { + continue; + } + if (l_iu[ii - 1] != 1 && zu > xmax) + { + xmax = zu; + in = j; + } +/* L270 */ + if (l_iu[cu_dim + ii - 1] != 1 && zv > xmax) + { + xmax = zv; + in = j; + } + } +/* L280 */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L280 xmax %e, toler %e\n", xmax, l_toler)); +#endif + if (xmax <= l_toler) + { +#ifdef DEBUG_CL1 + output_msg(sformatf( "xmax before optimality test %e\n", xmax)); +#endif + goto L490; /* test for optimality */ + } + if (q2[klm * q_dim + in].dval != xmax) + { + for (i = 0; i < klm1; ++i) + { + q2[i * q_dim + in].dval = -q2[i * q_dim + in].dval; + } + q2[klm1 * q_dim + in].ival = -q2[klm1 * q_dim + in].ival; +/* L290: */ + q2[klm * q_dim + in].dval = xmax; + } +/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ + if (iphase != 1 && ia != -1) + { + xmax = 0.; +/* find maximum absolute value in column "in" */ + for (i = 0; i <= ia; ++i) + { + l_z = fabs(q2[i * q_dim + in].dval); + if (l_z > xmax) + { + xmax = l_z; + iout = i; + } + } +/* L310: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L310, xmax %e\n", xmax)); +#endif +/* switch row ia with row iout, use memcpy */ + if (xmax > l_toler) + { + memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[iout * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[iout * q_dim]), (void *) &(scratch[0]), + (size_t) n2 * sizeof(LDBLE)); +/* L320: */ +/* set pivot to row ia, column in */ + iout = ia; + --ia; + pivot = q2[iout * q_dim + in].dval; + goto L420; /* Gauss Jordan */ + } + } +/* L330: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L330, xmax %e\n", xmax)); +#endif + kk = -1; +/* divide column n1 by positive value in column "in" greater than toler */ + for (i = 0; i < klm; ++i) + { + l_z = q2[i * q_dim + in].dval; + if (l_z > l_toler) + { + ++kk; + l_res[kk] = q2[i * q_dim + n].dval / l_z; + l_s[kk] = i; + } + } +/* L340: */ +#ifdef DEBUG_CL1 + if (kk < 0) + { + output_msg(sformatf( "kode = 2 in loop 340.\n")); + } +#endif + L350: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L350, xmax %e\n", xmax)); +#endif + if (kk < 0) + { +/* no positive value found in L340 or bypass intermediate verticies */ + *l_kode = 2; + goto L590; + } +/* L360: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L360, xmax %e\n", xmax)); +#endif +/* find minimum residual */ + xmin = l_res[0]; + iout = l_s[0]; + j = 0; + if (kk != 0) + { + for (i = 1; i <= kk; ++i) + { + if (l_res[i] < xmin) + { + j = i; + xmin = l_res[i]; + iout = l_s[i]; + } + } +/* L370: */ +/* put kk in position j */ + l_res[j] = l_res[kk]; + l_s[j] = l_s[kk]; + } +/* L380: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L380 iout %d, xmin %e, xmax %e\n", iout, + xmin, xmax)); +#endif + --kk; + pivot = q2[iout * q_dim + in].dval; + ii = q2[iout * q_dim + n1].ival; + if (iphase != 1) + { + if (ii < 0) + { +/* L390: */ + if (l_iu[-ii - 1] == 1) + { + goto L420; + } + } + else + { + if (l_iu[cu_dim + ii - 1] == 1) + { + goto L420; + } + } + } +/* L400: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L400\n")); +#endif + ii = abs(ii); + cuv = l_cu[ii - 1] + l_cu[cu_dim + ii - 1]; + if (q2[klm * q_dim + in].dval - pivot * cuv > l_toler) + { + +/* BYPASS INTERMEDIATE VERTICES. */ + for (j = js; j < n1; ++j) + { + l_z = q2[iout * q_dim + j].dval; + q2[klm * q_dim + j].dval -= l_z * cuv; + q2[iout * q_dim + j].dval = -l_z; + } +/* L410: */ + q2[iout * q_dim + n1].ival = -q2[iout * q_dim + n1].ival; + goto L350; + } +/* GAUSS-JORDAN ELIMINATION. */ + L420: +#ifdef DEBUG_CL1 + output_msg(sformatf( "Gauss Jordon %d\n", *l_iter)); +#endif + if (*l_iter >= maxit) + { + *l_kode = 3; + goto L590; + } +/* L430: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L430\n")); +#endif + ++(*l_iter); + for (j = js; j < n1; ++j) + { + if (j != in) + { + q2[iout * q_dim + j].dval /= pivot; + } + } +/* L440: */ + for (j = js; j < n1; ++j) + { + if (j != in) + { + l_z = -q2[iout * q_dim + j].dval; + for (i = 0; i < klm1; ++i) + { + if (i != iout) + { + q2[i * q_dim + j].dval += l_z * q2[i * q_dim + in].dval; + } + } +/* L450: */ + } + } +/* L460: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L460\n")); +#endif + tpivot = -pivot; + for (i = 0; i < klm1; ++i) + { + if (i != iout) + { + q2[i * q_dim + in].dval /= tpivot; + } + } +/* L470: */ + q2[iout * q_dim + in].dval = 1. / pivot; + ii = q2[iout * q_dim + n1].ival; + q2[iout * q_dim + n1].ival = q2[klm1 * q_dim + in].ival; + q2[klm1 * q_dim + in].ival = ii; + ii = abs(ii); + if (l_iu[ii - 1] == 0 || l_iu[cu_dim + ii - 1] == 0) + { + goto L240; + } +/* switch column */ + for (i = 0; i < klm1; ++i) + { + l_z = q2[i * q_dim + in].dval; + q2[i * q_dim + in].dval = q2[i * q_dim + js].dval; + q2[i * q_dim + js].dval = l_z; + } + i = q2[klm1 * q_dim + in].ival; + q2[klm1 * q_dim + in].ival = q2[klm1 * q_dim + js].ival; + q2[klm1 * q_dim + js].ival = i; +/* L480: */ + ++js; + goto L240; +/* TEST FOR OPTIMALITY. */ + L490: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L490\n")); +#endif + if (kforce == 0) + { + if (iphase == 1) + { + if (q2[klm * q_dim + n].dval <= l_toler) + { + goto L500; + } +#ifdef DEBUG_CL1 + output_msg(sformatf( "q2[klm1-1, n1-1] > *toler. %e\n", + q2[(klm1 - 1) * q_dim + n1 - 1].dval)); +#endif + *l_kode = 1; + goto L590; + } + *l_kode = 0; + goto L590; + } + if (iphase != 1 || q2[klm * q_dim + n].dval > l_toler) + { + kforce = 0; + goto L240; + } +/* SET UP PHASE 2 COSTS. */ + L500: +#ifdef DEBUG_CL1 + output_msg(sformatf( "Set up phase 2 costs %d\n", *l_iter)); +#endif + iphase = 2; + for (j = 0; j < nklm; ++j) + { + l_cu[j] = 0.; + } +/* L510: */ + for (j = n; j < nk; ++j) + { + l_cu[j] = 1.; + } + memcpy((void *) &(l_cu[cu_dim]), (void *) &(l_cu[0]), + (size_t) nklm * sizeof(LDBLE)); +/* L520: */ + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + if (ii <= 0) + { + if (l_iu[cu_dim - ii - 1] == 0) + { + continue; + } + l_cu[cu_dim - ii - 1] = 0.; + } + else + { +/* L530: */ + if (l_iu[ii - 1] == 0) + { + continue; + } + l_cu[ii - 1] = 0.; + } +/* L540: */ + ++ia; +/* switch row */ + memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[i * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[i * q_dim]), (void *) &(scratch[0]), + (size_t) n2 * sizeof(LDBLE)); +/* L550: */ + } +/* L560: */ + goto L160; + + +/* PREPARE OUTPUT. */ + L590: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L590\n")); +#endif + sum = 0.; + for (j = 0; j < n; ++j) + { + l_x[j] = 0.; + } +/* L600: */ + for (i = 0; i < klm; ++i) + { + l_res[i] = 0.; + } +/* L610: */ + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + sn = 1.; + if (ii < 0) + { + ii = -ii; + sn = -1.; + } + if (ii <= n) + { +/* L620: */ + l_x[ii - 1] = sn * q2[i * q_dim + n].dval; + } + else + { +/* L630: */ + l_res[ii - n - 1] = sn * q2[i * q_dim + n].dval; + if (ii >= n1 && ii <= nk) + { +/* * DBLE(Q(I,N1)) */ + sum += q2[i * q_dim + n].dval; + } + } + } +/* L640: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L640\n")); +#endif + *l_error = sum; + /* + * Check calculation + */ + if ((check == 1) && (*l_kode == 0)) + { + check_toler = 10. * l_toler; + /* + * Check optimization constraints + */ + if (kode_arg == 1) + { + for (i = 0; i < k; ++i) + { + if (res_arg[i] < 0.0) + { + if (l_res[i] > check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: optimization constraint not satisfied row %d, res %s, constraint %f.\n", + row_name[row_back[i]], l_res[i], res_arg[i])); +#endif + *l_kode = 1; + } + } + else if (res_arg[i] > 0.0) + { + if (l_res[i] < -check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: optimization constraint not satisfied row %s, res %e, constraint %f.\n", + row_name[row_back[i]], l_res[i], res_arg[i])); +#endif + *l_kode = 1; + } + } + } + } + /* + * Check equalities + */ + for (i = k; i < k + l; ++i) + { + if (fabs(l_res[i]) > check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: equality constraint not satisfied row %s, res %e, tolerance %e.\n", + row_name[row_back[i]], l_res[i], check_toler)); +#endif + *l_kode = 1; + } + } + /* + * Check inequalities + */ + for (i = k + l; i < k + l + m; ++i) + { + if (l_res[i] < -check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: inequality constraint not satisfied row %s, res %e, tolerance %e.\n", + row_name[row_back[i]], l_res[i], check_toler)); +#endif + *l_kode = 1; + } + } + /* + * Check dissolution/precipitation constraints + */ + if (kode_arg == 1) + { + for (i = 0; i < n; ++i) + { + if (x_arg[i] < 0.0) + { + if (l_x[i] > check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", + col_name[col_back[i]], l_x[i], x_arg[i])); +#endif + *l_kode = 1; + } + } + else if (x_arg[i] > 0.0) + { + if (l_x[i] < -check_toler) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1: dis/pre constraint not satisfied column %s, x %e, constraint %f.\n", + col_name[col_back[i]], l_x[i], x_arg[i])); +#endif + *l_kode = 1; + } + } + } + } + if (*l_kode == 1) + { + output_msg(sformatf( + "\n\tCL1: Roundoff errors in optimization.\n\t Try using -multiple_precision in INVERSE_MODELING\n")); + } + } + return 0; +} + +void Phreeqc:: +cl1_space(int check, int l_n2d, int klm, int l_nklmd) +{ + if (check == 1) + { + if (x_arg == NULL) + { + x_arg = (LDBLE *) PHRQ_malloc((size_t) (l_n2d * sizeof(LDBLE))); + } + else if (l_n2d > x_arg_max) + { + x_arg = + (LDBLE *) PHRQ_realloc(x_arg, (size_t) (l_n2d * sizeof(LDBLE))); + x_arg_max = l_n2d; + } + if (x_arg == NULL) + malloc_error(); + zero_double(x_arg, l_n2d); + + if (res_arg == NULL) + { + res_arg = (LDBLE *) PHRQ_malloc((size_t) ((klm) * sizeof(LDBLE))); + } + else if (klm > res_arg_max) + { + res_arg = + (LDBLE *) PHRQ_realloc(res_arg, + (size_t) ((klm) * sizeof(LDBLE))); + res_arg_max = klm; + } + if (res_arg == NULL) + malloc_error(); + zero_double(res_arg, klm); + } + +/* Make scratch space */ + if (scratch == NULL) + { + scratch = (LDBLE *) PHRQ_malloc((size_t) l_nklmd * sizeof(LDBLE)); + } + else if (l_nklmd > scratch_max) + { + scratch = + (LDBLE *) PHRQ_realloc(scratch, (size_t) l_nklmd * sizeof(LDBLE)); + scratch_max = l_nklmd; + } + if (scratch == NULL) + malloc_error(); + zero_double(scratch, l_nklmd); +} diff --git a/rename_cpp/cl1mp.cpp b/rename_cpp/cl1mp.cpp new file mode 100644 index 00000000..573dfc10 --- /dev/null +++ b/rename_cpp/cl1mp.cpp @@ -0,0 +1,1131 @@ +#include +#include +#include +#include +#include + +//#define Phreeqc:: Phreeqc:: +#include "Phreeqc.h" +#include "phqalloc.h" +#include "phrqtype.h" + +/* debug +#define DEBUG_CL1 +#define CHECK_ERRORS + */ + + +int Phreeqc:: +cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode_arg, LDBLE toler_arg, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error_arg, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg) +{ + /* System generated locals */ + union double_or_int + { + int ival; + mpf_t dval; + } *q2; + + /* Local variables */ + int nklm; + int iout = 0; + // static i runs faster + int i, j; + int maxit, n1, n2; + int ia, ii, kk, nk, js; + int in = 0; + int iphase, kforce; + int klm, jmn, nkl, jpn; + int klm1; + int *kode; + int q_dim, cu_dim; + int iswitch; + mpf_t *q; + mpf_t *x; + mpf_t *res; + mpf_t error; + mpf_t *cu; + mpf_t dummy, dummy1, sum, z, zu, zv, xmax, minus_one, toler, check_toler; + /*mpf_t *scratch; */ + mpf_t pivot, xmin, cuv, tpivot, sn; + mpf_t zero; + int censor; + mpf_t censor_tol; +/* THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX */ +/* METHOD OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION */ +/* TO A K BY N SYSTEM OF LINEAR EQUATIONS */ +/* AX=B */ +/* SUBJECT TO L LINEAR EQUALITY CONSTRAINTS */ +/* CX=D */ +/* AND M LINEAR INEQUALITY CONSTRAINTS */ +/* EX.LE.F. */ +/* DESCRIPTION OF PARAMETERS */ +/* K NUMBER OF ROWS OF THE MATRIX A (K.GE.1). */ +/* L NUMBER OF ROWS OF THE MATRIX C (L.GE.0). */ +/* M NUMBER OF ROWS OF THE MATRIX E (M.GE.0). */ +/* N NUMBER OF COLUMNS OF THE MATRICES A,C,E (N.GE.1). */ +/* KLMD SET TO AT LEAST K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* KLM2D SET TO AT LEAST K+L+M+2 FOR ADJUSTABLE DIMENSIONS. */ +/* NKLMD SET TO AT LEAST N+K+L+M FOR ADJUSTABLE DIMENSIONS. */ +/* N2D SET TO AT LEAST N+2 FOR ADJUSTABLE DIMENSIONS */ +/* Q TWO DIMENSIONAL REAL ARRAY WITH KLM2D ROWS AND */ +/* AT LEAST N2D COLUMNS. */ +/* ON ENTRY THE MATRICES A,C AND E, AND THE VECTORS */ +/* B,D AND F MUST BE STORED IN THE FIRST K+L+M ROWS */ +/* AND N+1 COLUMNS OF Q AS FOLLOWS */ +/* A B */ +/* Q = C D */ +/* E F */ +/* THESE VALUES ARE DESTROYED BY THE SUBROUTINE. */ +/* KODE A CODE USED ON ENTRY TO, AND EXIT */ +/* FROM, THE SUBROUTINE. */ +/* ON ENTRY, THIS SHOULD NORMALLY BE SET TO 0. */ +/* HOWEVER, IF CERTAIN NONNEGATIVITY CONSTRAINTS */ +/* ARE TO BE INCLUDED IMPLICITLY, RATHER THAN */ +/* EXPLICITLY IN THE CONSTRAINTS EX.LE.F, THEN KODE */ +/* SHOULD BE SET TO 1, AND THE NONNEGATIVITY */ +/* CONSTRAINTS INCLUDED IN THE ARRAYS X AND */ +/* RES (SEE BELOW). */ +/* ON EXIT, KODE HAS ONE OF THE */ +/* FOLLOWING VALUES */ +/* 0- OPTIMAL SOLUTION FOUND, */ +/* 1- NO FEASIBLE SOLUTION TO THE */ +/* CONSTRAINTS, */ +/* 2- CALCULATIONS TERMINATED */ +/* PREMATURELY DUE TO ROUNDING ERRORS, */ +/* 3- MAXIMUM NUMBER OF ITERATIONS REACHED. */ +/* TOLER A SMALL POSITIVE TOLERANCE. EMPIRICAL */ +/* EVIDENCE SUGGESTS TOLER = 10**(-D*2/3), */ +/* WHERE D REPRESENTS THE NUMBER OF DECIMAL */ +/* DIGITS OF ACCURACY AVAILABLE. ESSENTIALLY, */ +/* THE SUBROUTINE CANNOT DISTINGUISH BETWEEN ZERO */ +/* AND ANY QUANTITY WHOSE MAGNITUDE DOES NOT EXCEED */ +/* TOLER. IN PARTICULAR, IT WILL NOT PIVOT ON ANY */ +/* NUMBER WHOSE MAGNITUDE DOES NOT EXCEED TOLER. */ +/* ITER ON ENTRY ITER MUST CONTAIN AN UPPER BOUND ON */ +/* THE MAXIMUM NUMBER OF ITERATIONS ALLOWED. */ +/* A SUGGESTED VALUE IS 10*(K+L+M). ON EXIT ITER */ +/* GIVES THE NUMBER OF SIMPLEX ITERATIONS. */ +/* X ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST N2D. */ +/* ON EXIT THIS ARRAY CONTAINS A */ +/* SOLUTION TO THE L1 PROBLEM. IF KODE=1 */ +/* ON ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE */ +/* SIMPLE NONNEGATIVITY CONSTRAINTS ON THE */ +/* VARIABLES. THE VALUES -1, 0, OR 1 */ +/* FOR X(J) INDICATE THAT THE J-TH VARIABLE */ +/* IS RESTRICTED TO BE .LE.0, UNRESTRICTED, */ +/* OR .GE.0 RESPECTIVELY. */ +/* RES ONE DIMENSIONAL REAL ARRAY OF SIZE AT LEAST KLMD. */ +/* ON EXIT THIS CONTAINS THE RESIDUALS B-AX */ +/* IN THE FIRST K COMPONENTS, D-CX IN THE */ +/* NEXT L COMPONENTS (THESE WILL BE =0),AND */ +/* F-EX IN THE NEXT M COMPONENTS. IF KODE=1 ON */ +/* ENTRY, THIS ARRAY IS ALSO USED TO INCLUDE SIMPLE */ +/* NONNEGATIVITY CONSTRAINTS ON THE RESIDUALS */ +/* B-AX. THE VALUES -1, 0, OR 1 FOR RES(I) */ +/* INDICATE THAT THE I-TH RESIDUAL (1.LE.I.LE.K) IS */ +/* RESTRICTED TO BE .LE.0, UNRESTRICTED, OR .GE.0 */ +/* RESPECTIVELY. */ +/* ERROR ON EXIT, THIS GIVES THE MINIMUM SUM OF */ +/* ABSOLUTE VALUES OF THE RESIDUALS. */ +/* CU A TWO DIMENSIONAL REAL ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* IU A TWO DIMENSIONAL INTEGER ARRAY WITH TWO ROWS AND */ +/* AT LEAST NKLMD COLUMNS USED FOR WORKSPACE. */ +/* S INTEGER ARRAY OF SIZE AT LEAST KLMD, USED FOR */ +/* WORKSPACE. */ +/* DOUBLE PRECISION DBLE */ +/* REAL */ + +/* INITIALIZATION. */ + /* + * mp variables + */ + censor = 1; + if (censor_arg == 0.0) + censor = 0; + mpf_set_default_prec(96); + mpf_init(zero); + mpf_init(dummy); + mpf_init(dummy1); + mpf_init_set_d(censor_tol, censor_arg); + q = (mpf_t *) + PHRQ_malloc((size_t) + (max_row_count * max_column_count * sizeof(mpf_t))); + if (q == NULL) + malloc_error(); + for (i = 0; i < max_row_count * max_column_count; ++i) + { + mpf_init_set_d(q[i], q_arg[i]); + if (censor == 1) + { + if (mpf_cmp(q[i], zero) != 0) + { + mpf_abs(dummy1, q[i]); + if (mpf_cmp(dummy1, censor_tol) <= 0) + { + mpf_set_si(q[i], 0); + } + } + } + } + x = (mpf_t *) PHRQ_malloc((size_t) (n2d * sizeof(mpf_t))); + if (x == NULL) + malloc_error(); + for (i = 0; i < n2d; ++i) + { + mpf_init_set_d(x[i], x_arg[i]); + } + res = (mpf_t *) PHRQ_malloc((size_t) ((k + l + m) * sizeof(mpf_t))); + if (res == NULL) + malloc_error(); + for (i = 0; i < k + l + m; ++i) + { + mpf_init_set_d(res[i], res_arg[i]); + } + cu = (mpf_t *) PHRQ_malloc((size_t) (2 * nklmd * sizeof(mpf_t))); + if (cu == NULL) + malloc_error(); + for (i = 0; i < 2 * nklmd; ++i) + { + mpf_init_set_d(cu[i], cu_arg[i]); + } + kode = (int *) PHRQ_malloc(sizeof(int)); + if (kode == NULL) + malloc_error(); + *kode = *kode_arg; + mpf_init(sum); + mpf_init(error); + mpf_init(z); + mpf_init(zu); + mpf_init(zv); + mpf_init(xmax); + mpf_init_set_si(minus_one, -1); + mpf_init_set_d(toler, toler_arg); + mpf_init_set_d(check_toler, toler_arg); + mpf_init(pivot); + mpf_init(xmin); + mpf_init(cuv); + mpf_init(tpivot); + mpf_init(sn); +/* Parameter adjustments */ + q_dim = n2d; + q2 = (union double_or_int *) q; + cu_dim = nklmd; + +/* Function Body */ + maxit = *iter; + n1 = n + 1; + n2 = n + 2; + nk = n + k; + nkl = nk + l; + klm = k + l + m; + klm1 = klm + 1; + nklm = n + klm; + kforce = 1; + *iter = 0; + js = 0; + ia = -1; +/* Make scratch space */ +/* + scratch = (LDBLE *) PHRQ_malloc( (size_t) nklmd * sizeof(LDBLE)); + if (scratch == NULL) malloc_error(); + for (i=0; i < nklmd; i++) { + scratch[i] = 0.0; + } +*/ +/* + scratch = (mpf_t *) PHRQ_malloc( (size_t) nklmd * sizeof(mpf_t)); + if (scratch == NULL) malloc_error(); + for (i=0; i < nklmd; i++) { + mpf_init(scratch[i]); + } +*/ +/* SET UP LABELS IN Q. */ + for (j = 0; j < n; ++j) + { + q2[klm1 * q_dim + j].ival = j + 1; + } +/* L10: */ + for (i = 0; i < klm; ++i) + { + q2[i * q_dim + n1].ival = n + i + 1; + if (mpf_cmp_d(q2[i * q_dim + n].dval, 0.0) < 0) + { + for (j = 0; j < n1; ++j) + { + /* q2[ i * q_dim + j ].dval = -q2[ i * q_dim + j ].dval; */ + mpf_neg(q2[i * q_dim + j].dval, q2[i * q_dim + j].dval); + } + q2[i * q_dim + n1].ival = -q2[i * q_dim + n1].ival; +/* L20: */ + } + } +/* L30: */ +/* SET UP PHASE 1 COSTS. */ + iphase = 2; +#ifdef DEBUG_CL1 + output_msg(sformatf( "Set up phase 1 costs\n")); +#endif +/* Zero first row of cu and iu */ + /*memcpy( (void *) &(cu[0]), (void *) &(scratch[0]), (size_t) nklm * sizeof(mpf_t) ); */ + for (j = 0; j < nklm; ++j) + { + mpf_set_si(cu[j], 0); + iu[j] = 0; + } +/* L40: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L40\n")); +#endif + if (l != 0) + { + for (j = nk; j < nkl; ++j) + { + mpf_set_si(cu[j], 1); + /*cu[ j ] = 1.; */ + iu[j] = 1; + } +/* L50: */ + iphase = 1; + } + +/* Copy first row of cu and iu to second row */ + /*memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(mpf_t) ); */ + for (i = 0; i < nklm; ++i) + { + mpf_set(cu[cu_dim + i], cu[i]); + } + memcpy((void *) &(iu[cu_dim]), (void *) &(iu[0]), + (size_t) nklm * sizeof(int)); +/* L60: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L60\n")); +#endif + if (m != 0) + { + for (j = nkl; j < nklm; ++j) + { + /* cu[ cu_dim + j ] = 1.; */ + mpf_set_si(cu[cu_dim + j], 1); + iu[cu_dim + j] = 1; + jmn = j - n; + if (q2[jmn * q_dim + n1].ival < 0) + { + iphase = 1; + } + } +/* L70: */ + } +/* L80: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L80\n")); +#endif + if (*kode != 0) + { + for (j = 0; j < n; ++j) + { + /* if ( x[j] < 0.) { */ + if (mpf_cmp_si(x[j], 0) < 0) + { +/* L90: */ + /* cu[ j ] = 1.; */ + mpf_set_si(cu[j], 1); + iu[j] = 1; + /* } else if (x[j] > 0.) { */ + } + else if (mpf_cmp_si(x[j], 0) > 0) + { + /* cu[ cu_dim + j ] = 1.; */ + mpf_set_si(cu[cu_dim + j], 1); + iu[cu_dim + j] = 1; + } + } +/* L110: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L110\n")); +#endif + for (j = 0; j < k; ++j) + { + jpn = j + n; + /* if (res[j] < 0.) { */ + if (mpf_cmp_si(res[j], 0) < 0) + { +/* L120: */ + /* cu[ jpn ] = 1.; */ + mpf_set_si(cu[jpn], 1); + iu[jpn] = 1; + if (q2[j * q_dim + n1].ival > 0) + { + iphase = 1; + } + /* } else if (res[j] > 0.) { */ + } + else if (mpf_cmp_si(res[j], 0) > 0) + { +/* L130: */ + /* cu[ cu_dim + jpn ] = 1.; */ + mpf_set_si(cu[cu_dim + jpn], 1); + iu[cu_dim + jpn] = 1; + if (q2[j * q_dim + n1].ival < 0) + { + iphase = 1; + } + } + } +/* L140: */ + } +/* L150: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L150\n")); +#endif + if (iphase == 2) + { + goto L500; + } +/* COMPUTE THE MARGINAL COSTS. */ + L160: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L160\n")); +#endif + for (j = js; j < n1; ++j) + { + mpf_set_si(sum, 0); + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + if (ii < 0) + { + /* z = cu[ cu_dim - ii - 1 ]; */ + mpf_set(z, cu[cu_dim - ii - 1]); + } + else + { + /*z = cu[ ii - 1 ]; */ + mpf_set(z, cu[ii - 1]); + } + /*sum += q2[ i * q_dim + j ].dval * z; */ + mpf_mul(dummy, q2[i * q_dim + j].dval, z); + mpf_add(sum, sum, dummy); + } + /*q2[ klm * q_dim + j ].dval = sum; */ + mpf_set(q2[klm * q_dim + j].dval, sum); + } + for (j = js; j < n; ++j) + { + ii = q2[klm1 * q_dim + j].ival; + if (ii < 0) + { + /*z = cu[ cu_dim - ii - 1 ]; */ + mpf_set(z, cu[cu_dim - ii - 1]); + } + else + { + /*z = cu[ ii - 1 ]; */ + mpf_set(z, cu[ii - 1]); + } + /*q2[ klm * q_dim + j ].dval -= z; */ + mpf_sub(q2[klm * q_dim + j].dval, q2[klm * q_dim + j].dval, z); + } +/* DETERMINE THE VECTOR TO ENTER THE BASIS. */ + L240: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L240, xmax %e\n", mpf_get_d(xmax))); +#endif + /*xmax = 0.; */ + mpf_set_si(xmax, 0); + if (js >= n) + { + goto L490; /* test for optimality */ + } + for (j = js; j < n; ++j) + { + /*zu = q2[ klm * q_dim + j ].dval; */ + mpf_set(zu, q2[klm * q_dim + j].dval); + ii = q2[klm1 * q_dim + j].ival; + if (ii > 0) + { + /*zv = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; */ + mpf_mul(dummy, cu[cu_dim + ii - 1], minus_one); + mpf_sub(dummy, dummy, cu[ii - 1]); + mpf_sub(zv, dummy, zu); + } + else + { + ii = -ii; + /* zv = zu; */ + mpf_set(zv, zu); + /* zu = -zu - cu[ ii - 1 ] - cu[ cu_dim + ii - 1 ]; */ + mpf_mul(dummy, cu[cu_dim + ii - 1], minus_one); + mpf_sub(dummy, dummy, cu[ii - 1]); + mpf_sub(zu, dummy, zu); + } +/* L260 */ + if (kforce == 1 && ii > n) + { + continue; + } + /*if (iu[ ii - 1 ] != 1 && zu > xmax){ */ + if ((iu[ii - 1] != 1) && (mpf_cmp(zu, xmax) > 0)) + { + /*xmax = zu; */ + mpf_set(xmax, zu); + in = j; + } +/* L270 */ + /*if (iu[ cu_dim + ii - 1 ] != 1 && zv > xmax ) { */ + if ((iu[cu_dim + ii - 1] != 1) && (mpf_cmp(zv, xmax) > 0)) + { + /*xmax = zv; */ + mpf_set(xmax, zv); + in = j; + } + } +/* L280 */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L280 xmax %e, toler %e\n", mpf_get_d(xmax), + mpf_get_d(toler))); +#endif + /*if (xmax <= toler) { */ + if (mpf_cmp(xmax, toler) <= 0) + { +#ifdef DEBUG_CL1 + output_msg(sformatf( "xmax before optimality test %e\n", + mpf_get_d(xmax))); +#endif + goto L490; /* test for optimality */ + } + /*if (q2[ klm * q_dim + in ].dval != xmax) { */ + if (mpf_cmp(q2[klm * q_dim + in].dval, xmax) != 0) + { + for (i = 0; i < klm1; ++i) + { + /*q2[ i * q_dim + in ].dval = -q2[ i * q_dim + in ].dval; */ + mpf_neg(q2[i * q_dim + in].dval, q2[i * q_dim + in].dval); + } + q2[klm1 * q_dim + in].ival = -q2[klm1 * q_dim + in].ival; +/* L290: */ + /*q2[ klm * q_dim + in ].dval = xmax; */ + mpf_set(q2[klm * q_dim + in].dval, xmax); + } +/* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ + if (iphase != 1 && ia != -1) + { + /*xmax = 0.; */ + mpf_set_si(xmax, 0); +/* find maximum absolute value in column "in" */ + for (i = 0; i <= ia; ++i) + { + /*z = fabs(q2[ i * q_dim + in ].dval); */ + mpf_abs(z, q2[i * q_dim + in].dval); + /*if (z > xmax) { */ + if (mpf_cmp(z, xmax) > 0) + { + /*xmax = z; */ + mpf_set(xmax, z); + iout = i; + } + } +/* L310: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L310, xmax %e\n", mpf_get_d(xmax))); +#endif +/* switch row ia with row iout, use memcpy */ + /*if (xmax > toler) { */ + if (mpf_cmp(xmax, toler) > 0) + { + /* + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(mpf_t) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ iout * q_dim]), + (size_t) n2 * sizeof(mpf_t) ); + memcpy( (void *) &(q2[ iout * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(mpf_t) ); + */ + for (i = 0; i < n1; ++i) + { + mpf_set(dummy, q2[ia * q_dim + i].dval); + mpf_set(q2[ia * q_dim + i].dval, q2[iout * q_dim + i].dval); + mpf_set(q2[iout * q_dim + i].dval, dummy); + } + j = q2[ia * q_dim + n1].ival; + q2[ia * q_dim + n1].ival = q2[iout * q_dim + n1].ival; + q2[iout * q_dim + n1].ival = j; + +/* L320: */ +/* set pivot to row ia, column in */ + iout = ia; + --ia; + /*pivot = q2[ iout * q_dim + in ].dval; */ + mpf_set(pivot, q2[iout * q_dim + in].dval); + goto L420; /* Gauss Jordan */ + } + } +/* L330: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L330, xmax %e\n", mpf_get_d(xmax))); +#endif + kk = -1; +/* divide column n1 by positive value in column "in" greater than toler */ + for (i = 0; i < klm; ++i) + { + /*z = q2[ i * q_dim + in ].dval; */ + mpf_set(z, q2[i * q_dim + in].dval); + /*if (z > toler) { */ + if (mpf_cmp(z, toler) > 0) + { + ++kk; + /*res[kk] = q2[ i * q_dim + n ].dval / z; */ + mpf_div(res[kk], q2[i * q_dim + n].dval, z); + s[kk] = i; + } + } +/* L340: */ + if (kk < 0) + { + output_msg(sformatf( "kode = 2 in loop 340.\n")); + } + L350: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L350, xmax %e\n", mpf_get_d(xmax))); +#endif + if (kk < 0) + { +/* no positive value found in L340 or bypass intermediate verticies */ + *kode = 2; + goto L590; + } +/* L360: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L360, xmax %e\n", mpf_get_d(xmax))); +#endif +/* find minimum residual */ + /*xmin = res[ 0 ]; */ + mpf_set(xmin, res[0]); + iout = s[0]; + j = 0; + if (kk != 0) + { + for (i = 1; i <= kk; ++i) + { + /*if (res[i] < xmin) { */ + if (mpf_cmp(res[i], xmin) < 0) + { + j = i; + /*xmin = res[i]; */ + mpf_set(xmin, res[i]); + iout = s[i]; + } + } +/* L370: */ +/* put kk in position j */ + /*res[j] = res[kk]; */ + mpf_set(res[j], res[kk]); + s[j] = s[kk]; + } +/* L380: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L380 iout %d, xmin %e, xmax %e\n", iout, + mpf_get_d(xmin), mpf_get_d(xmax))); +#endif + --kk; + /*pivot = q2[ iout * q_dim + in ].dval; */ + mpf_set(pivot, q2[iout * q_dim + in].dval); + ii = q2[iout * q_dim + n1].ival; + if (iphase != 1) + { + if (ii < 0) + { +/* L390: */ + if (iu[-ii - 1] == 1) + { + goto L420; + } + } + else + { + if (iu[cu_dim + ii - 1] == 1) + { + goto L420; + } + } + } +/* L400: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L400\n")); +#endif + ii = abs(ii); + /*cuv = cu[ ii - 1 ] + cu[ cu_dim + ii - 1]; */ + mpf_add(cuv, cu[ii - 1], cu[cu_dim + ii - 1]); + /*if (q2[ klm * q_dim + in ].dval - pivot * cuv > toler) { */ + mpf_mul(dummy, pivot, cuv); + mpf_sub(dummy, q2[klm * q_dim + in].dval, dummy); + if (mpf_cmp(dummy, toler) > 0) + { +/* BYPASS INTERMEDIATE VERTICES. */ + for (j = js; j < n1; ++j) + { + /*z = q2[ iout * q_dim + j ].dval; */ + mpf_set(z, q2[iout * q_dim + j].dval); + /*q2[ klm * q_dim + j ].dval -= z * cuv; */ + mpf_mul(dummy1, z, cuv); + mpf_sub(q2[klm * q_dim + j].dval, q2[klm * q_dim + j].dval, + dummy1); + + if (censor == 1) + { + if (mpf_cmp(q2[klm * q_dim + j].dval, zero) != 0) + { + mpf_abs(dummy1, q2[klm * q_dim + j].dval); + if (mpf_cmp(dummy1, censor_tol) <= 0) + { + mpf_set_si(q2[klm * q_dim + j].dval, 0); + } + } + } + + /*q2[ iout * q_dim + j ].dval = -z; */ + mpf_neg(q2[iout * q_dim + j].dval, z); + } +/* L410: */ + q2[iout * q_dim + n1].ival = -q2[iout * q_dim + n1].ival; + goto L350; + } +/* GAUSS-JORDAN ELIMINATION. */ + L420: +#ifdef DEBUG_CL1 + output_msg(sformatf( "Gauss Jordon %d\n", *iter)); +#endif + if (*iter >= maxit) + { + *kode = 3; + goto L590; + } +/* L430: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L430\n")); +#endif + ++(*iter); + for (j = js; j < n1; ++j) + { + if (j != in) + { + /*q2[ iout * q_dim + j ].dval /= pivot; */ + mpf_div(q2[iout * q_dim + j].dval, q2[iout * q_dim + j].dval, + pivot); + } + } +/* L440: */ + for (j = js; j < n1; ++j) + { + if (j != in) + { + /*z = -q2[ iout * q_dim + j ].dval; */ + mpf_neg(z, q2[iout * q_dim + j].dval); + for (i = 0; i < klm1; ++i) + { + if (i != iout) + { + /*q2[ i * q_dim + j ].dval += z * q2[ i * q_dim + in ].dval; */ + mpf_mul(dummy, z, q2[i * q_dim + in].dval); + mpf_add(q2[i * q_dim + j].dval, q2[i * q_dim + j].dval, + dummy); + + if (censor == 1) + { + if (mpf_cmp(q2[i * q_dim + j].dval, zero) != 0) + { + mpf_abs(dummy1, q2[i * q_dim + j].dval); + if (mpf_cmp(dummy1, censor_tol) <= 0) + { + mpf_set_si(q2[i * q_dim + j].dval, 0); + } + } + } + } + } +/* L450: */ + } + } +/* L460: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L460\n")); +#endif + /*tpivot = -pivot; */ + mpf_neg(tpivot, pivot); + for (i = 0; i < klm1; ++i) + { + if (i != iout) + { + /*q2[ i * q_dim + in ].dval /= tpivot; */ + mpf_div(q2[i * q_dim + in].dval, q2[i * q_dim + in].dval, tpivot); + } + } +/* L470: */ + /*q2[ iout * q_dim + in ].dval = 1. / pivot; */ + mpf_set_si(dummy, 1); + mpf_div(q2[iout * q_dim + in].dval, dummy, pivot); + ii = q2[iout * q_dim + n1].ival; + q2[iout * q_dim + n1].ival = q2[klm1 * q_dim + in].ival; + q2[klm1 * q_dim + in].ival = ii; + ii = abs(ii); + if (iu[ii - 1] == 0 || iu[cu_dim + ii - 1] == 0) + { + goto L240; + } +/* switch column */ + for (i = 0; i < klm1; ++i) + { + /*z = q2[ i * q_dim + in ].dval; */ + mpf_set(z, q2[i * q_dim + in].dval); + /*q2[ i * q_dim + in ].dval = q2[ i * q_dim + js ].dval; */ + mpf_set(q2[i * q_dim + in].dval, q2[i * q_dim + js].dval); + /*q2[ i * q_dim + js ].dval = z; */ + mpf_set(q2[i * q_dim + js].dval, z); + } + i = q2[klm1 * q_dim + in].ival; + q2[klm1 * q_dim + in].ival = q2[klm1 * q_dim + js].ival; + q2[klm1 * q_dim + js].ival = i; +/* L480: */ + ++js; + goto L240; +/* TEST FOR OPTIMALITY. */ + L490: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L490\n")); +#endif + if (kforce == 0) + { + if (iphase == 1) + { + /*if (q2[ klm * q_dim + n ].dval <= toler) { */ + if (mpf_cmp(q2[klm * q_dim + n].dval, toler) <= 0) + { + goto L500; + } +#ifdef DEBUG_CL1 + output_msg(sformatf( "q2[klm1-1, n1-1] > *toler. %e\n", + mpf_get_d(q2[(klm1 - 1) * q_dim + n1 - 1].dval))); +#endif + *kode = 1; + goto L590; + } + *kode = 0; + goto L590; + } + /*if (iphase != 1 || q2[ klm * q_dim + n ].dval > toler) { */ + if ((iphase != 1) || (mpf_cmp(q2[klm * q_dim + n].dval, toler) > 0)) + { + kforce = 0; + goto L240; + } +/* SET UP PHASE 2 COSTS. */ + L500: +#ifdef DEBUG_CL1 + output_msg(sformatf( "Set up phase 2 costs %d\n", *iter)); +#endif + iphase = 2; + for (j = 0; j < nklm; ++j) + { + /*cu[ j ] = 0.; */ + mpf_set_si(cu[j], 0); + } +/* L510: */ + for (j = n; j < nk; ++j) + { + /*cu[ j ] = 1.; */ + mpf_set_si(cu[j], 1); + } + /* + memcpy( (void *) &(cu[cu_dim]), (void *) &(cu[0]), (size_t) nklm * sizeof(LDBLE) ); + */ + for (i = 0; i < nklm; ++i) + { + mpf_set(cu[cu_dim + i], cu[i]); + } + +/* L520: */ + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + if (ii <= 0) + { + if (iu[cu_dim - ii - 1] == 0) + { + continue; + } + /*cu[ cu_dim - ii - 1 ] = 0.; */ + mpf_set_si(cu[cu_dim - ii - 1], 0); + } + else + { +/* L530: */ + if (iu[ii - 1] == 0) + { + continue; + } + /*cu[ ii - 1 ] = 0.; */ + mpf_set_si(cu[ii - 1], 0); + } +/* L540: */ + ++ia; +/* switch row */ + /* + memcpy( (void *) &(scratch[0]), (void *) &(q2[ ia * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ ia * q_dim ]), (void *) &(q2[ i * q_dim]), + (size_t) n2 * sizeof(LDBLE) ); + memcpy( (void *) &(q2[ i * q_dim ]), (void *) &(scratch[ 0 ]), + (size_t) n2 * sizeof(LDBLE) ); + */ + for (iswitch = 0; iswitch < n1; ++iswitch) + { + mpf_set(dummy, q2[ia * q_dim + iswitch].dval); + mpf_set(q2[ia * q_dim + iswitch].dval, + q2[i * q_dim + iswitch].dval); + mpf_set(q2[i * q_dim + iswitch].dval, dummy); + } + iswitch = q2[ia * q_dim + n1].ival; + q2[ia * q_dim + n1].ival = q2[i * q_dim + n1].ival; + q2[i * q_dim + n1].ival = iswitch; +/* L550: */ + } +/* L560: */ + goto L160; + + +/* PREPARE OUTPUT. */ + L590: +#ifdef DEBUG_CL1 + output_msg(sformatf( "L590\n")); +#endif + /*sum = 0.; */ + mpf_set_si(sum, 0); + for (j = 0; j < n; ++j) + { + /*x[j] = 0.; */ + mpf_set_si(x[j], 0); + } +/* L600: */ + for (i = 0; i < klm; ++i) + { + /*res[i] = 0.; */ + mpf_set_si(res[i], 0); + } +/* L610: */ + for (i = 0; i < klm; ++i) + { + ii = q2[i * q_dim + n1].ival; + /*sn = 1.; */ + mpf_set_si(sn, 1); + if (ii < 0) + { + ii = -ii; + /*sn = -1.; */ + mpf_set_si(sn, -1); + } + if (ii <= n) + { +/* L620: */ + /*x[ii - 1] = sn * q2[ i * q_dim + n ].dval; */ + mpf_mul(x[ii - 1], sn, q2[i * q_dim + n].dval); + } + else + { +/* L630: */ + /*res[ii - n - 1] = sn * q2[ i * q_dim + n ].dval; */ + mpf_mul(res[ii - n - 1], sn, q2[i * q_dim + n].dval); + if (ii >= n1 && ii <= nk) + { +/* * DBLE(Q(I,N1)) */ + /*sum += q2[ i * q_dim + n ].dval; */ + mpf_add(sum, sum, q2[i * q_dim + n].dval); + } + } + } +/* L640: */ +#ifdef DEBUG_CL1 + output_msg(sformatf( "L640\n")); +#endif + /* + * Check calculation + */ + mpf_set_si(dummy, 100); + mpf_mul(check_toler, toler, dummy); + if (check && *kode == 0) + { + /* + * Check optimization constraints + */ + if (*kode_arg == 1) + { + for (i = 0; i < k; ++i) + { + if (res_arg[i] < 0.0) + { + mpf_sub(dummy, res[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy, dummy1) > 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", + i, mpf_get_d(res[i]), res_arg[i])); +#endif + *kode = 1; + } + } + else if (res_arg[i] > 0.0) + { + mpf_add(dummy, res[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy, dummy1) < 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: optimization constraint not satisfied row %d, res %e, constraint %f.\n", + i, mpf_get_d(res[i]), res_arg[i])); +#endif + *kode = 1; + } + } + } + } + /* + * Check equalities + */ + for (i = k; i < k + l; ++i) + { + mpf_abs(dummy, res[i]); + if (mpf_cmp(dummy, check_toler) > 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: equality constraint not satisfied row %d, res %e, tolerance %e.\n", + i, mpf_get_d(res[i]), mpf_get_d(check_toler))); +#endif + + *kode = 1; + } + } + /* + * Check inequalities + */ + for (i = k + l; i < k + l + m; ++i) + { + mpf_neg(dummy, check_toler); + if (mpf_cmp(res[i], dummy) < 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: inequality constraint not satisfied row %d, res %e, tolerance %e.\n", + i, mpf_get_d(res[i]), mpf_get_d(check_toler))); +#endif + *kode = 1; + } + } + /* + * Check dissolution/precipitation constraints + */ + if (*kode_arg == 1) + { + for (i = 0; i < n; ++i) + { + if (x_arg[i] < 0.0) + { + mpf_sub(dummy, x[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy, dummy1) > 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", + i, mpf_get_d(x[i]), x_arg[i])); +#endif + *kode = 1; + } + } + else if (x_arg[i] > 0.0) + { + mpf_add(dummy, x[i], check_toler); + mpf_set_si(dummy1, 0); + if (mpf_cmp(dummy, dummy1) < 0) + { +#ifdef CHECK_ERRORS + output_msg(sformatf( + "\tCL1MP: dis/pre constraint not satisfied column %d, x %e, constraint %f.\n", + i, mpf_get_d(x[i]), x_arg[i])); +#endif + *kode = 1; + } + } + } + } + if (*kode == 1) + { + output_msg(sformatf( + "\n\tCL1MP: Roundoff errors in optimization.\n\t Deleting model.\n")); + } + } + /* + * set return variables + */ + /**error = sum;*/ + mpf_set(error, sum); + *error_arg = mpf_get_d(error); + *kode_arg = *kode; + for (i = 0; i < n2d; ++i) + { + x_arg[i] = mpf_get_d(x[i]); + } + for (i = 0; i < k + l + m; ++i) + { + res_arg[i] = mpf_get_d(res[i]); + } + + /*scratch = free_check_null (scratch); */ + + for (i = 0; i < max_row_count * max_column_count; ++i) + { + mpf_clear(q[i]); + } + q = (mpf_t *) free_check_null(q); + for (i = 0; i < n2d; ++i) + { + mpf_clear(x[i]); + } + x = (mpf_t *) free_check_null(x); + for (i = 0; i < k + l + m; ++i) + { + mpf_clear(res[i]); + } + res = (mpf_t *) free_check_null(res); + for (i = 0; i < 2 * nklmd; ++i) + { + mpf_clear(cu[i]); + } + cu = (mpf_t *) free_check_null(cu); + mpf_clear(dummy); + mpf_clear(dummy1); + mpf_clear(sum); + mpf_clear(error); + mpf_clear(z); + mpf_clear(zu); + mpf_clear(zv); + mpf_clear(xmax); + mpf_clear(minus_one); + mpf_clear(toler); + mpf_clear(check_toler); + mpf_clear(pivot); + mpf_clear(xmin); + mpf_clear(cuv); + mpf_clear(tpivot); + mpf_clear(sn); + mpf_clear(censor_tol); + kode = (int *) free_check_null(kode); + return 0; +} diff --git a/rename_cpp/cvdense.cpp b/rename_cpp/cvdense.cpp new file mode 100644 index 00000000..fb782aa3 --- /dev/null +++ b/rename_cpp/cvdense.cpp @@ -0,0 +1,504 @@ +/******************************************************************* + * * + * File : cvdense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for the CVODE dense linear * + * solver, CVDENSE. * + * * + *******************************************************************/ + + +#include +#include +#include +#include "cvdense.h" +#include "cvode.h" +#include "dense.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "sundialsmath.h" + + +#include "Phreeqc.h" +#define malloc PHRQ_malloc +#define MACHENV machEnv->phreeqc_ptr-> +#define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> +#define MACHENV_MALLOC MACHENV +#define CVMEM_MALLOC CVMEM + +#include "phqalloc.h" +/* WARNING don't include any headers below here */ + +/* Error Messages */ + +#define CVDENSE "CVDense/CVReInitDense-- " + +#define MSG_CVMEM_NULL CVDENSE "CVode Memory is NULL.\n\n" + +#define MSG_MEM_FAIL CVDENSE "A memory request failed.\n\n" + +#define MSG_WRONG_NVEC CVDENSE "Incompatible NVECTOR implementation.\n\n" + +/* Other Constants */ + +#define MIN_INC_MULT RCONST(1000.0) +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) +#define TWO RCONST(2.0) + + +/****************************************************************** + * * + * Types : CVDenseMemRec, CVDenseMem * + *----------------------------------------------------------------* + * The type CVDenseMem is pointer to a CVDenseMemRec. This * + * structure contains CVDense solver-specific data. * + * * + ******************************************************************/ + +typedef struct +{ + + CVDenseJacFn d_jac; /* jac = Jacobian routine to be called */ + + DenseMat d_M; /* M = I - gamma J, gamma = h / l1 */ + + integertype *d_pivots; /* pivots = pivot array for PM = LU */ + + DenseMat d_savedJ; /* savedJ = old Jacobian */ + + long int d_nstlj; /* nstlj = nst at last Jacobian eval. */ + + long int d_nje; /* nje = no. of calls to jac */ + + void *d_J_data; /* J_data is passed to jac */ + +} CVDenseMemRec, *CVDenseMem; + + +/* CVDENSE linit, lsetup, lsolve, lfree, and DQJac routines */ + +static int CVDenseInit(CVodeMem cv_mem); + +static int CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, booleantype * jcurPtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + +static int CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, + N_Vector fcur); + +static void CVDenseFree(CVodeMem cv_mem); + +static void CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype t, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + +/*************** CVDenseDQJac **************************************** + + This routine generates a dense difference quotient approximation to + the Jacobian of f(t,y). It assumes that a dense matrix of type + DenseMat is stored column-wise, and that elements within each column + are contiguous. The address of the jth column of J is obtained via + the macro DENSE_COL and an N_Vector with the jth column as the + component array is created using N_VMake and N_VSetData. Finally, the + actual computation of the jth column of the Jacobian is done with a + call to N_VLinearSum. + +**********************************************************************/ + +static void +CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype tn, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3) +{ + realtype fnorm, minInc, inc, inc_inv, yjsaved, srur; + realtype *y_data, *ewt_data; + N_Vector ftemp, jthCol; + M_Env machEnv; + integertype j; + + machEnv = y->menv; /* Get machine environment */ + + ftemp = vtemp1; /* Rename work vector for use as f vector value */ + + /* Obtain pointers to the data for ewt, y */ + ewt_data = N_VGetData(ewt); + y_data = N_VGetData(y); + + /* Set minimum increment based on uround and norm of f */ + srur = RSqrt(uround); + fnorm = N_VWrmsNorm(fy, ewt); + minInc = (fnorm != ZERO) ? + (MIN_INC_MULT * ABS(h) * uround * N * fnorm) : ONE; + + jthCol = N_VMake(N, y_data, machEnv); /* j loop overwrites this data address */ + + /* This is the only for loop for 0..N-1 in CVODE */ + for (j = 0; j < N; j++) + { + + /* Generate the jth col of J(tn,y) */ + + N_VSetData(DENSE_COL(J, j), jthCol); + yjsaved = y_data[j]; + inc = MAX(srur * ABS(yjsaved), minInc / ewt_data[j]); + y_data[j] += inc; + f(N, tn, y, ftemp, f_data); + inc_inv = ONE / inc; + N_VLinearSum(inc_inv, ftemp, -inc_inv, fy, jthCol); + y_data[j] = yjsaved; + } + + N_VDispose(jthCol); + + /* Increment counter nfe = *nfePtr */ + *nfePtr += N; +} + + +/* Readability Replacements */ + +#define N (cv_mem->cv_N) +#define lmm (cv_mem->cv_lmm) +#define f (cv_mem->cv_f) +#define f_data (cv_mem->cv_f_data) +#define uround (cv_mem->cv_uround) +#define nst (cv_mem->cv_nst) +#define tn (cv_mem->cv_tn) +#define h (cv_mem->cv_h) +#define gamma (cv_mem->cv_gamma) +#define gammap (cv_mem->cv_gammap) +#define gamrat (cv_mem->cv_gamrat) +#define ewt (cv_mem->cv_ewt) +#define nfe (cv_mem->cv_nfe) +#define errfp (cv_mem->cv_errfp) +#define iopt (cv_mem->cv_iopt) +#define linit (cv_mem->cv_linit) +#define lsetup (cv_mem->cv_lsetup) +#define lsolve (cv_mem->cv_lsolve) +#define lfree (cv_mem->cv_lfree) +#define lmem (cv_mem->cv_lmem) +#define setupNonNull (cv_mem->cv_setupNonNull) +#define machenv (cv_mem->cv_machenv) + +#define jac (cvdense_mem->d_jac) +#define M (cvdense_mem->d_M) +#define pivots (cvdense_mem->d_pivots) +#define savedJ (cvdense_mem->d_savedJ) +#define nstlj (cvdense_mem->d_nstlj) +#define nje (cvdense_mem->d_nje) +#define J_data (cvdense_mem->d_J_data) + + +/*************** CVDense ********************************************* + + This routine initializes the memory record and sets various function + fields specific to the dense linear solver module. CVDense first + calls the existing lfree routine if this is not NULL. Then it sets + the cv_linit, cv_lsetup, cv_lsolve, cv_lfree fields in (*cvode_mem) + to be CVDenseInit, CVDenseSetup, CVDenseSolve, and CVDenseFree, + respectively. It allocates memory for a structure of type + CVDenseMemRec and sets the cv_lmem field in (*cvode_mem) to the + address of this structure. It sets setupNonNull in (*cvode_mem) to + TRUE, the d_J_data field in CVDenseMemRec to be the input + parameter jac_data, and the d_jac field to be: + (1) the input parameter djac if djac != NULL or + (2) CVDenseDQJac if djac == NULL. + Finally, it allocates memory for M, savedJ, and pivots. + The return value is SUCCESS = 0, or LMEM_FAIL = -1. + + NOTE: The dense linear solver assumes a serial implementation + of the NVECTOR package. Therefore, CVDense will first + test for compatible a compatible N_Vector internal + representation by checking (1) the machine environment + ID tag and (2) that the functions N_VMake, N_VDispose, + N_VGetData, and N_VSetData are implemented. + +**********************************************************************/ + +int +CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) +{ + CVodeMem cv_mem; + CVDenseMem cvdense_mem; + + /* Return immediately if cvode_mem is NULL */ + cv_mem = (CVodeMem) cvode_mem; + if (cv_mem == NULL) + { /* CVode reports this error */ + return (LMEM_FAIL); + } + + /* Test if the NVECTOR package is compatible with the DENSE solver */ + if ((strcmp(machenv->tag, "serial")) || + machenv->ops->nvmake == NULL || + machenv->ops->nvdispose == NULL || + machenv->ops->nvgetdata == NULL || machenv->ops->nvsetdata == NULL) + { + CVMEM warning_msg( MSG_WRONG_NVEC); + return (LMEM_FAIL); + } + + if (lfree != NULL) + lfree(cv_mem); + + /* Set four main function fields in cv_mem */ + linit = CVDenseInit; + lsetup = CVDenseSetup; + lsolve = CVDenseSolve; + lfree = CVDenseFree; + + /* Get memory for CVDenseMemRec */ + lmem = cvdense_mem = (CVDenseMem) CVMEM_MALLOC malloc(sizeof(CVDenseMemRec)); + if (cvdense_mem == NULL) + { + CVMEM warning_msg( MSG_MEM_FAIL); + return (LMEM_FAIL); + } + + /* Set Jacobian routine field, J_data, and setupNonNull */ + if (djac == NULL) + { + jac = CVDenseDQJac; + } + else + { + jac = djac; + } + J_data = jac_data; + setupNonNull = TRUE; + + /* Allocate memory for M, savedJ, and pivot array */ + + M = DenseAllocMat(N); + if (M == NULL) + { + CVMEM warning_msg( MSG_MEM_FAIL); + return (LMEM_FAIL); + } + savedJ = DenseAllocMat(N); + if (savedJ == NULL) + { + CVMEM warning_msg( MSG_MEM_FAIL); + DenseFreeMat(M); + return (LMEM_FAIL); + } + pivots = DenseAllocPiv(N); + if (pivots == NULL) + { + CVMEM warning_msg( MSG_MEM_FAIL); + DenseFreeMat(M); + DenseFreeMat(savedJ); + return (LMEM_FAIL); + } + + return (SUCCESS); +} + +/*************** CVReInitDense**************************************** + + This routine resets the link between the main CVODE module and the + dense linear solver module CVDENSE. No memory freeing or allocation + operations are done, as the existing linear solver memory is assumed + sufficient. All other initializations are the same as in CVDense. + The return value is SUCCESS = 0, or LMEM_FAIL = -1. + +**********************************************************************/ + +int +CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) +{ + CVodeMem cv_mem; + CVDenseMem cvdense_mem; + + /* Return immediately if cvode_mem is NULL */ + cv_mem = (CVodeMem) cvode_mem; + if (cv_mem == NULL) + { /* CVode reports this error */ + CVMEM warning_msg( MSG_CVMEM_NULL); + return (LMEM_FAIL); + } + + /* Test if the NVECTOR package is compatible with the DENSE solver */ + if ((strcmp(machenv->tag, "serial")) || + machenv->ops->nvmake == NULL || + machenv->ops->nvdispose == NULL || + machenv->ops->nvgetdata == NULL || machenv->ops->nvsetdata == NULL) + { + CVMEM warning_msg( MSG_WRONG_NVEC); + return (LMEM_FAIL); + } + + cvdense_mem = (CVDenseMem) lmem; /* Use existing linear solver memory pointer */ + + /* Set four main function fields in cv_mem */ + linit = CVDenseInit; + lsetup = CVDenseSetup; + lsolve = CVDenseSolve; + lfree = CVDenseFree; + + /* Set Jacobian routine field, J_data, and setupNonNull */ + if (djac == NULL) + { + jac = CVDenseDQJac; + } + else + { + jac = djac; + } + J_data = jac_data; + setupNonNull = TRUE; + + return (SUCCESS); +} + +/*************** CVDenseInit ***************************************** + + This routine does remaining initializations specific to the dense + linear solver. + +**********************************************************************/ + +static int +CVDenseInit(CVodeMem cv_mem) +{ + CVDenseMem cvdense_mem; + cvdense_mem = (CVDenseMem) lmem; + + /* Initialize nje and nstlj, and set workspace lengths */ + + nje = 0; + if (iopt != NULL) + { + iopt[DENSE_NJE] = nje; + iopt[DENSE_LRW] = 2 * N * N; + iopt[DENSE_LIW] = N; + } + nstlj = 0; + + return (LINIT_OK); +} + +/*************** CVDenseSetup **************************************** + + This routine does the setup operations for the dense linear solver. + It makes a decision whether or not to call the Jacobian evaluation + routine based on various state variables, and if not it uses the + saved copy. In any case, it constructs the Newton matrix + M = I - gamma*J, updates counters, and calls the dense LU + factorization routine. + +**********************************************************************/ + +static int +CVDenseSetup(CVodeMem cv_mem, int convfail, N_Vector ypred, + N_Vector fpred, booleantype * jcurPtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3) +{ + booleantype jbad, jok; + realtype dgamma; + integertype ier; + CVDenseMem cvdense_mem; + + cvdense_mem = (CVDenseMem) lmem; + + /* Use nst, gamma/gammap, and convfail to set J eval. flag jok */ + + dgamma = ABS((gamma / gammap) - ONE); + jbad = (nst == 0) || (nst > nstlj + CVD_MSBJ) || + ((convfail == FAIL_BAD_J) && (dgamma < CVD_DGMAX)) || + (convfail == FAIL_OTHER); + jok = !jbad; + + if (jok) + { + /* If jok = TRUE, use saved copy of J */ + *jcurPtr = FALSE; + DenseCopy(savedJ, M); + } + else + { + /* If jok = FALSE, call jac routine for new J value */ + nje++; + if (iopt != NULL) + iopt[DENSE_NJE] = nje; + nstlj = nst; + *jcurPtr = TRUE; + DenseZero(M); + jac(N, M, f, f_data, tn, ypred, fpred, ewt, h, + uround, J_data, &nfe, vtemp1, vtemp2, vtemp3); + DenseCopy(M, savedJ); + } + + /* Scale and add I to get M = I - gamma*J */ + DenseScale(-gamma, M); + DenseAddI(M); + + /* Do LU factorization of M */ + ier = DenseFactor(M, pivots); + + /* Return 0 if the LU was complete; otherwise return 1 */ + if (ier > 0) + return (1); + return (0); +} + +/*************** CVDenseSolve **************************************** + + This routine handles the solve operation for the dense linear solver + by calling the dense backsolve routine. The returned value is 0. + +**********************************************************************/ + +static int +CVDenseSolve(CVodeMem cv_mem, N_Vector b, N_Vector ycur, N_Vector fcur) +{ + CVDenseMem cvdense_mem; + realtype *bd; + + cvdense_mem = (CVDenseMem) lmem; + + bd = N_VGetData(b); + DenseBacksolve(M, pivots, bd); + N_VSetData(bd, b); + + /* If BDF, scale the correction to account for change in gamma */ + if ((lmm == BDF) && (gamrat != ONE)) + { + N_VScale(TWO / (ONE + gamrat), b, b); + } + + return (0); +} + +/*************** CVDenseFree ***************************************** + + This routine frees memory specific to the dense linear solver. + +**********************************************************************/ + +static void +CVDenseFree(CVodeMem cv_mem) +{ + CVDenseMem cvdense_mem; + + cvdense_mem = (CVDenseMem) lmem; + + DenseFreeMat(M); + DenseFreeMat(savedJ); + DenseFreePiv(pivots); + CVMEM_MALLOC PHRQ_free(cvdense_mem); +} diff --git a/rename_cpp/cvdense.h b/rename_cpp/cvdense.h new file mode 100644 index 00000000..1e8b25d8 --- /dev/null +++ b/rename_cpp/cvdense.h @@ -0,0 +1,223 @@ +#ifndef _INC_CVDENSE_H +#define _INC_CVDENSE_H +/******************************************************************* + * * + * File : cvdense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for the CVODE dense linear solver, * + * CVDENSE. * + * * + * Note: The type integertype must be large enough to store the * + * value of the linear system size N. * + * * + *******************************************************************/ + +#ifndef _cvdense_h +#define _cvdense_h + + +#include +#include "cvode.h" +#include "sundialstypes.h" +#include "dense.h" +#include "nvector.h" + + +/****************************************************************** + * * + * CVDENSE solver statistics indices * + *----------------------------------------------------------------* + * The following enumeration gives a symbolic name to each * + * CVDENSE statistic. The symbolic names are used as indices into * + * the iopt and ropt arrays passed to CVodeMalloc. * + * The CVDENSE statistics are: * + * * + * iopt[DENSE_NJE] : number of Jacobian evaluations, i.e. of * + * calls made to the dense Jacobian routine * + * (default or user-supplied). * + * * + * iopt[DENSE_LRW] : size (in realtype words) of real workspace * + * matrices and vectors used by this solver. * + * * + * iopt[DENSE_LIW] : size (in integertype words) of integer * + * workspace vectors used by this solver. * + * * + ******************************************************************/ + + enum + { DENSE_NJE = CVODE_IOPT_SIZE, DENSE_LRW, DENSE_LIW }; + + +/****************************************************************** + * * + * CVDENSE solver constants * + *----------------------------------------------------------------* + * CVD_MSBJ : maximum number of steps between dense Jacobian * + * evaluations * + * * + * CVD_DGMAX : maximum change in gamma between dense Jacobian * + * evaluations * + * * + ******************************************************************/ + +#define CVD_MSBJ 50 + +#define CVD_DGMAX RCONST(0.2) + + +/****************************************************************** + * * + * Type : CVDenseJacFn * + *----------------------------------------------------------------* + * A dense Jacobian approximation function Jac must have the * + * prototype given below. Its parameters are: * + * * + * N is the length of all vector arguments. * + * * + * J is the dense matrix (of type DenseMat) that will be loaded * + * by a CVDenseJacFn with an approximation to the Jacobian matrix * + * J = (df_i/dy_j) at the point (t,y). * + * J is preset to zero, so only the nonzero elements need to be * + * loaded. Two efficient ways to load J are: * + * * + * (1) (with macros - no explicit data structure references) * + * for (j=0; j < N; j++) { * + * col_j = DENSE_COL(J,j); * + * for (i=0; i < N; i++) { * + * generate J_ij = the (i,j)th Jacobian element * + * col_j[i] = J_ij; * + * } * + * } * + * * + * (2) (without macros - explicit data structure references) * + * for (j=0; j < N; j++) { * + * col_j = (J->data)[j]; * + * for (i=0; i < N; i++) { * + * generate J_ij = the (i,j)th Jacobian element * + * col_j[i] = J_ij; * + * } * + * } * + * * + * The DENSE_ELEM(A,i,j) macro is appropriate for use in small * + * problems in which efficiency of access is NOT a major concern. * + * * + * f is the right hand side function for the ODE problem. * + * * + * f_data is a pointer to user data to be passed to f, the same * + * as the F_data parameter passed to CVodeMalloc. * + * * + * t is the current value of the independent variable. * + * * + * y is the current value of the dependent variable vector, * + * namely the predicted value of y(t). * + * * + * fy is the vector f(t,y). * + * * + * ewt is the error weight vector. * + * * + * h is a tentative step size in t. * + * * + * uround is the machine unit roundoff. * + * * + * jac_data is a pointer to user data - the same as the jac_data * + * parameter passed to CVDense. * + * * + * nfePtr is a pointer to the memory location containing the * + * CVODE problem data nfe = number of calls to f. The Jacobian * + * routine should update this counter by adding on the number * + * of f calls made in order to approximate the Jacobian, if any. * + * For example, if the routine calls f a total of N times, then * + * the update is *nfePtr += N. * + * * + * vtemp1, vtemp2, and vtemp3 are pointers to memory allocated * + * for vectors of length N which can be used by a CVDenseJacFn * + * as temporary storage or work space. * + * * + ******************************************************************/ + + typedef void (*CVDenseJacFn) (integertype N, DenseMat J, RhsFn f, + void *f_data, realtype t, N_Vector y, + N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + +/****************************************************************** + * * + * Function : CVDense * + *----------------------------------------------------------------* + * A call to the CVDense function links the main CVODE integrator * + * with the CVDENSE linear solver. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * djac is the dense Jacobian approximation routine to be used. * + * A user-supplied djac routine must be of type * + * CVDenseJacFn. Pass NULL for djac to use the default * + * difference quotient routine CVDenseDQJac supplied * + * with this solver. * + * * + * jac_data is a pointer to user data which is passed to the * + * djac routine every time it is called. * + * * + * The return values of CVDense are: * + * SUCCESS = 0 if successful * + * LMEM_FAIL = -1 if there was a memory allocation failure * + * * + * NOTE: The dense linear solver assumes a serial implementation * + * of the NVECTOR package. Therefore, CVDense will first * + * test for a compatible N_Vector internal representation * + * by checking (1) the machine environment ID tag and * + * (2) that the functions N_VMake, N_VDispose, N_VGetData, * + * and N_VSetData are implemented. * + * * + ******************************************************************/ + + int CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); + + +/****************************************************************** + * * + * Function : CVReInitDense * + *----------------------------------------------------------------* + * A call to the CVReInitDense function resets the link between * + * the main CVODE integrator and the CVDENSE linear solver. * + * After solving one problem using CVDENSE, call CVReInit and then* + * CVReInitDense to solve another problem of the same size, if * + * there is a change in the CVDense parameters djac or jac_data. * + * If there is no change in parameters, it is not necessary to * + * call either CVReInitDense or CVDense for the new problem. * + * * + * All arguments to CVReInitDense have the same names and meanings* + * as those of CVDense. The cvode_mem argument must be identical * + * to its value in the previous CVDense call. * + * * + * The return values of CVReInitDense are: * + * SUCCESS = 0 if successful, or * + * LMEM_FAIL = -1 if the cvode_mem argument is NULL * + * * + * NOTE: CVReInitDense performs the same compatibility tests as * + * CVDense. * + * * + ******************************************************************/ + + int CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data); + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ +#endif /* _INC_CVDENSE_H */ diff --git a/rename_cpp/cvode.cpp b/rename_cpp/cvode.cpp new file mode 100644 index 00000000..2abf8cc7 --- /dev/null +++ b/rename_cpp/cvode.cpp @@ -0,0 +1,3780 @@ +/*#define DEBUG_CVODE*/ +/******************************************************************* + * * + * File : cvode.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, * + * and Dan Shumaker @ LLNL * + * Version of : 24 July 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for the main CVODE integrator. * + * It is independent of the CVODE linear solver in use. * + * * + *******************************************************************/ + + +/************************************************************/ +/******************* BEGIN Imports **************************/ +/************************************************************/ +#include +#include +#include "cvode.h" +#include "sundialstypes.h" +#include "nvector.h" +#include "sundialsmath.h" + +#include "Phreeqc.h" +#define malloc MACHENV_MALLOC PHRQ_malloc +#define MACHENV machEnv->phreeqc_ptr-> +#define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> +#define MACHENV_MALLOC MACHENV +#define CVMEM_MALLOC CVMEM + +#include "phqalloc.h" +/* WARNING don't include any headers below here */ + + +/************************************************************/ +/******************** END Imports ***************************/ +/************************************************************/ + + +/***************************************************************/ +/*********************** BEGIN Macros **************************/ +/***************************************************************/ + +/* Macro: loop */ + +#define loop for(;;) + +/***************************************************************/ +/************************ END Macros ***************************/ +/***************************************************************/ + + + +/************************************************************/ +/************** BEGIN CVODE Private Constants ***************/ +/***************************************** +*******************/ + +#define FOURTH RCONST(0.25) /* real 0.25 */ +#define THREE RCONST(3.0) /* real 3.0 */ +#define FOUR RCONST(4.0) /* real 4.0 */ +#define HUN RCONST(100.0) /* real 100.0 */ +#define TINY RCONST(1.0e-10) /* small number */ +#define HALF RCONST(0.5) /* real 0.5 */ +#define ZERO RCONST(0.0) /* real 0.0 */ +#define ONE RCONST(1.0) /* real 1.0 */ +#define TWO RCONST(2.0) /* real 2.0 */ +#define TWELVE RCONST(12.0) /* real 12.0 */ + +/***************************************************************/ +/************** BEGIN Default Constants ************************/ +/***************************************************************/ + +#define HMIN_DEFAULT ZERO /* hmin default value */ +#define HMAX_INV_DEFAULT ZERO /* hmax_inv default value */ +#define MXHNIL_DEFAULT 10 /* mxhnil default value */ +#define MXSTEP_DEFAULT 1000 /* mxstep default value */ + + +/***************************************************************/ +/*************** END Default Constants *************************/ +/***************************************************************/ + + +/***************************************************************/ +/************ BEGIN Routine-Specific Constants *****************/ +/***************************************************************/ + +/* CVodeDky */ + +#define FUZZ_FACTOR RCONST(100.0) + +/* CVHin */ + +#define HLB_FACTOR RCONST(100.0) +#define HUB_FACTOR RCONST(0.1) +#define H_BIAS HALF +#define MAX_ITERS 4 + +/* CVSet */ + +#define CORTES RCONST(0.1) + +/* CVStep return values */ + +#define SUCCESS_STEP 0 +#define REP_ERR_FAIL -1 +#define REP_CONV_FAIL -2 +#define SETUP_FAILED -3 +#define SOLVE_FAILED -4 + +/* CVStep control constants */ + +#define PREDICT_AGAIN -5 +#define DO_ERROR_TEST 1 + +/* CVStep */ + +#define THRESH RCONST(1.5) +#define ETAMX1 RCONST(10000.0) +#define ETAMX2 RCONST(10.0) +#define ETAMX3 RCONST(10.0) +#define ETAMXF RCONST(0.2) +#define ETAMIN RCONST(0.1) +#define ETACF RCONST(0.25) +#define ADDON RCONST(0.000001) +#define BIAS1 RCONST(6.0) +#define BIAS2 RCONST(6.0) +#define BIAS3 RCONST(10.0) +#define ONEPSM RCONST(1.000001) + +#define SMALL_NST 10 /* nst > SMALL_NST => use ETAMX3 */ +#define MXNCF 10 /* max no. of convergence failures during */ + /* one step try */ +#define MXNEF 7 /* max no. of error test failures during */ + /* one step try */ +#define MXNEF1 3 /* max no. of error test failures before */ + /* forcing a reduction of order */ +#define SMALL_NEF 2 /* if an error failure occurs and */ + /* SMALL_NEF <= nef <= MXNEF1, then */ + /* reset eta = MIN(eta, ETAMXF) */ +#define LONG_WAIT 10 /* number of steps to wait before */ + /* considering an order change when */ + /* q==1 and MXNEF1 error test failures */ + /* have occurred */ + +/* CVnls return values */ + +#define SOLVED 0 +#define CONV_FAIL -1 +#define SETUP_FAIL_UNREC -2 +#define SOLVE_FAIL_UNREC -3 + +/* CVnls input flags */ + +#define FIRST_CALL 0 +#define PREV_CONV_FAIL -1 +#define PREV_ERR_FAIL -2 + +/* CVnls other constants */ + +#define FUNC_MAXCOR 3 /* maximum no. of corrector iterations */ + /* for iter == FUNCTIONAL */ +#define NEWT_MAXCOR 3 /* maximum no. of corrector iterations */ + /* for iter == NEWTON */ + +#define CRDOWN RCONST(0.3) /* constant used in the estimation of the */ + /* convergence rate (crate) of the */ + /* iterates for the nonlinear equation */ +#define DGMAX RCONST(0.3) /* iter == NEWTON, |gamma/gammap-1| > DGMAX */ + /* => call lsetup */ + +#define RDIV TWO /* declare divergence if ratio del/delp > RDIV */ +#define MSBP 20 /* max no. of steps between lsetup calls */ + +#define TRY_AGAIN_CVODE 99 /* control constant for CVnlsNewton - should be */ + /* distinct from CVnls return values */ + + +/***************************************************************/ +/*************** END Routine-Specific Constants ***************/ +/***************************************************************/ + + +/***************************************************************/ +/***************** BEGIN Error Messages ************************/ +/***************************************************************/ + +/* CVodeMalloc/CVReInit Error Messages */ + +#define CVM "CVodeMalloc/CVReInit-- " + +#define MSG_Y0_NULL CVM "y0=NULL illegal.\n\n" + +#define MSG_BAD_N CVM "N=%ld < 1 illegal.\n\n" + +#define MSG_BAD_LMM_1 CVM "lmm=%d illegal.\n" +#define MSG_BAD_LMM_2 "The legal values are ADAMS=%d and BDF=%d.\n\n" +#define MSG_BAD_LMM MSG_BAD_LMM_1 MSG_BAD_LMM_2 + +#define MSG_BAD_ITER_1 CVM "iter=%d illegal.\n" +#define MSG_BAD_ITER_2 "The legal values are FUNCTIONAL=%d " +#define MSG_BAD_ITER_3 "and NEWTON=%d.\n\n" +#define MSG_BAD_ITER MSG_BAD_ITER_1 MSG_BAD_ITER_2 MSG_BAD_ITER_3 + +#define MSG_BAD_ITOL_1 CVM "itol=%d illegal.\n" +#define MSG_BAD_ITOL_2 "The legal values are SS=%d and SV=%d.\n\n" +#define MSG_BAD_ITOL MSG_BAD_ITOL_1 MSG_BAD_ITOL_2 + +#define MSG_F_NULL CVM "f=NULL illegal.\n\n" + +#define MSG_RELTOL_NULL CVM "reltol=NULL illegal.\n\n" + +#define MSG_BAD_RELTOL CVM "*reltol=%g < 0 illegal.\n\n" + +#define MSG_ABSTOL_NULL CVM "abstol=NULL illegal.\n\n" + +#define MSG_BAD_ABSTOL CVM "Some abstol component < 0.0 illegal.\n\n" + +#define MSG_BAD_OPTIN_1 CVM "optIn=%d illegal.\n" +#define MSG_BAD_OPTIN_2 "The legal values are FALSE=%d and TRUE=%d.\n\n" +#define MSG_BAD_OPTIN MSG_BAD_OPTIN_1 MSG_BAD_OPTIN_2 + +#define MSG_BAD_OPT CVM "optIn=TRUE, but iopt=ropt=NULL.\n\n" + +#define MSG_MEM_FAIL CVM "A memory request failed.\n\n" + +#define MSG_BAD_EWT CVM "Some initial ewt component = 0.0 illegal.\n\n" + +#define MSG_REI_NO_MEM "CVReInit-- cvode_mem = NULL illegal.\n\n" + +#define MSG_REI_MAXORD1 "CVReInit-- Illegal attempt to increase " +#define MSG_REI_MAXORD2 "maximum method order from %d to %d.\n\n" +#define MSG_REI_MAXORD MSG_REI_MAXORD1 MSG_REI_MAXORD2 + + +/* CVode error messages */ + +#define CVODE "CVode-- " + +#define NO_MEM "cvode_mem=NULL illegal.\n\n" + +#define MSG_CVODE_NO_MEM CVODE NO_MEM + +#define MSG_LINIT_NULL CVODE "The linear solver's init routine is NULL.\n\n" + +#define MSG_LSETUP_NULL CVODE "The linear solver's setup routine is NULL.\n\n" + +#define MSG_LSOLVE_NULL CVODE "The linear solver's solve routine is NULL.\n\n" + +#define MSG_LFREE_NULL CVODE "The linear solver's free routine is NULL.\n\n" + +#define MSG_LINIT_FAIL CVODE "The linear solver's init routine failed.\n\n" + +#define MSG_YOUT_NULL CVODE "yout=NULL illegal.\n\n" + +#define MSG_T_NULL CVODE "t=NULL illegal.\n\n" + +#define MSG_BAD_ITASK_1 CVODE "itask=%d illegal.\nThe legal values are" +#define MSG_BAD_ITASK_2 " NORMAL=%d and ONE_STEP=%d.\n\n" +#define MSG_BAD_ITASK MSG_BAD_ITASK_1 MSG_BAD_ITASK_2 + +#define MSG_BAD_HMIN_HMAX_1 CVODE "Inconsistent step size limits:\n" +#define MSG_BAD_HMIN_HMAX_2 "ropt[HMIN]=%g > ropt[HMAX]=%g.\n\n" +#define MSG_BAD_HMIN_HMAX MSG_BAD_HMIN_HMAX_1 MSG_BAD_HMIN_HMAX_2 + +#define MSG_BAD_H0 CVODE "h0=%g and tout-t0=%g inconsistent.\n\n" + +#define MSG_BAD_TOUT_1 CVODE "Trouble interpolating at tout = %g.\n" +#define MSG_BAD_TOUT_2 "tout too far back in direction of integration.\n\n" +#define MSG_BAD_TOUT MSG_BAD_TOUT_1 MSG_BAD_TOUT_2 + +#define MSG_MAX_STEPS_1 CVODE "At t=%g, mxstep=%d steps taken on " +#define MSG_MAX_STEPS_2 "this call before\nreaching tout=%g.\n\n" +#define MSG_MAX_STEPS MSG_MAX_STEPS_1 MSG_MAX_STEPS_2 + +#define MSG_EWT_NOW_BAD_1 CVODE "At t=%g, " +#define MSG_EWT_NOW_BAD_2 "some ewt component has become <= 0.0.\n\n" +#define MSG_EWT_NOW_BAD MSG_EWT_NOW_BAD_1 MSG_EWT_NOW_BAD_2 + +#define MSG_TOO_MUCH_ACC CVODE "At t=%g, too much accuracy requested.\n\n" + +#define MSG_HNIL_1 CVODE "Warning.. internal t=%g and step size h=%g\n" +#define MSG_HNIL_2 "are such that t + h == t on the next step.\n" +#define MSG_HNIL_3 "The solver will continue anyway.\n\n" +#define MSG_HNIL MSG_HNIL_1 MSG_HNIL_2 MSG_HNIL_3 + +#define MSG_HNIL_DONE_1 CVODE "The above warning has been issued %d times " +#define MSG_HNIL_DONE_2 "and will not be\nissued again for this problem.\n\n" +#define MSG_HNIL_DONE MSG_HNIL_DONE_1 MSG_HNIL_DONE_2 + +#define MSG_ERR_FAILS_1 CVODE "At t=%g and step size h=%g, the error test\n" +#define MSG_ERR_FAILS_2 "failed repeatedly or with |h| = hmin.\n\n" +#define MSG_ERR_FAILS MSG_ERR_FAILS_1 MSG_ERR_FAILS_2 + +#define MSG_CONV_FAILS_1 CVODE "At t=%g and step size h=%g, the corrector\n" +#define MSG_CONV_FAILS_2 "convergence failed repeatedly or " +#define MSG_CONV_FAILS_3 "with |h| = hmin.\n\n" +#define MSG_CONV_FAILS MSG_CONV_FAILS_1 MSG_CONV_FAILS_2 MSG_CONV_FAILS_3 + +#define MSG_SETUP_FAILED_1 CVODE "At t=%g, the setup routine failed in an " +#define MSG_SETUP_FAILED_2 "unrecoverable manner.\n\n" +#define MSG_SETUP_FAILED MSG_SETUP_FAILED_1 MSG_SETUP_FAILED_2 + +#define MSG_SOLVE_FAILED_1 CVODE "At t=%g, the solve routine failed in an " +#define MSG_SOLVE_FAILED_2 "unrecoverable manner.\n\n" +#define MSG_SOLVE_FAILED MSG_SOLVE_FAILED_1 MSG_SOLVE_FAILED_2 + +#define MSG_TOO_CLOSE_1 CVODE "tout=%g too close to t0=%g to start" +#define MSG_TOO_CLOSE_2 " integration.\n\n" +#define MSG_TOO_CLOSE MSG_TOO_CLOSE_1 MSG_TOO_CLOSE_2 + + +/* CVodeDky Error Messages */ + +#define DKY "CVodeDky-- " + +#define MSG_DKY_NO_MEM DKY NO_MEM + +#define MSG_BAD_K DKY "k=%d illegal.\n\n" + +#define MSG_BAD_T_1 DKY "t=%g illegal.\n" +#define MSG_BAD_T_2 "t not in interval tcur-hu=%g to tcur=%g.\n\n" +#define MSG_BAD_T MSG_BAD_T_1 MSG_BAD_T_2 + +#define MSG_BAD_DKY DKY "dky=NULL illegal.\n\n" + +/***************************************************************/ +/****************** END Error Messages *************************/ +/***************************************************************/ + + +/************************************************************/ +/*************** END CVODE Private Constants ****************/ +/************************************************************/ + + +/**************************************************************/ +/********* BEGIN Private Helper Functions Prototypes **********/ +/**************************************************************/ + +static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq, + int maxord, M_Env machEnv); +static void CVFreeVectors(CVodeMem cv_mem, int maxord); + +static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur); +static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur); +static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur); + +static booleantype CVHin(CVodeMem cv_mem, realtype tout); +static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist); +static realtype CVYddNorm(CVodeMem cv_mem, realtype hg); + +static int CVStep(CVodeMem cv_mem); + +static int CVsldet(CVodeMem cv_mem); + +static void CVAdjustParams(CVodeMem cv_mem); +static void CVAdjustOrder(CVodeMem cv_mem, int deltaq); +static void CVAdjustAdams(CVodeMem cv_mem, int deltaq); +static void CVAdjustBDF(CVodeMem cv_mem, int deltaq); +static void CVIncreaseBDF(CVodeMem cv_mem); +static void CVDecreaseBDF(CVodeMem cv_mem); + +static void CVRescale(CVodeMem cv_mem); + +static void CVPredict(CVodeMem cv_mem); + +static void CVSet(CVodeMem cv_mem); +static void CVSetAdams(CVodeMem cv_mem); +static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]); +static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], + realtype hsum); +static realtype CVAltSum(int iend, realtype a[], int k); +static void CVSetBDF(CVodeMem cv_mem); +static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, + realtype alpha0_hat, realtype xi_inv, + realtype xistar_inv); + +static int CVnls(CVodeMem cv_mem, int nflag); +static int CVnlsFunctional(CVodeMem cv_mem); +static int CVnlsNewton(CVodeMem cv_mem, int nflag); +static int CVNewtonIteration(CVodeMem cv_mem); + +static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, + int *ncfPtr); + +static void CVRestore(CVodeMem cv_mem, realtype saved_t); + +static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, + int *kflagPtr, realtype saved_t, + int *nefPtr, realtype * dsmPtr); + +static void CVCompleteStep(CVodeMem cv_mem); + +static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm); +static void CVSetEta(CVodeMem cv_mem); +static realtype CVComputeEtaqm1(CVodeMem cv_mem); +static realtype CVComputeEtaqp1(CVodeMem cv_mem); +static void CVChooseEta(CVodeMem cv_mem); +static void CVBDFStab(CVodeMem cv_mem); + +static int CVHandleFailure(CVodeMem cv_mem, int kflag); + + +/**************************************************************/ +/********** END Private Helper Functions Prototypes ***********/ +/**************************************************************/ + + +/**************************************************************/ +/**************** BEGIN Readability Constants *****************/ +/**************************************************************/ + + +#define uround (cv_mem->cv_uround) +#define zn (cv_mem->cv_zn) +#define ewt (cv_mem->cv_ewt) +#define y (cv_mem->cv_y) +#define acor (cv_mem->cv_acor) +#define tempv (cv_mem->cv_tempv) +#define ftemp (cv_mem->cv_ftemp) +#define q (cv_mem->cv_q) +#define qprime (cv_mem->cv_qprime) +#define qwait (cv_mem->cv_qwait) +#define L (cv_mem->cv_L) +#define h (cv_mem->cv_h) +#define hprime (cv_mem->cv_hprime) +#define eta (cv_mem-> cv_eta) +#define etaqm1 (cv_mem-> cv_etaqm1) +#define etaq (cv_mem-> cv_etaq) +#define etaqp1 (cv_mem-> cv_etaqp1) +#define nscon (cv_mem->cv_nscon) +#define ssdat (cv_mem->cv_ssdat) +#define hscale (cv_mem->cv_hscale) +#define tn (cv_mem->cv_tn) +#define tau (cv_mem->cv_tau) +#define tq (cv_mem->cv_tq) +#define l (cv_mem->cv_l) +#define rl1 (cv_mem->cv_rl1) +#define gamma (cv_mem->cv_gamma) +#define gammap (cv_mem->cv_gammap) +#define gamrat (cv_mem->cv_gamrat) +#define crate (cv_mem->cv_crate) +#define acnrm (cv_mem->cv_acnrm) +#define mnewt (cv_mem->cv_mnewt) +#define qmax (cv_mem->cv_qmax) +#define mxstep (cv_mem->cv_mxstep) +#define maxcor (cv_mem->cv_maxcor) +#define mxhnil (cv_mem->cv_mxhnil) +#define hmin (cv_mem->cv_hmin) +#define hmax_inv (cv_mem->cv_hmax_inv) +#define etamax (cv_mem->cv_etamax) +#define nst (cv_mem->cv_nst) +#define nfe (cv_mem->cv_nfe) +#define ncfn (cv_mem->cv_ncfn) +#define netf (cv_mem->cv_netf) +#define nni (cv_mem-> cv_nni) +#define nsetups (cv_mem->cv_nsetups) +#define nhnil (cv_mem->cv_nhnil) +#define lrw (cv_mem->cv_lrw) +#define liw (cv_mem->cv_liw) +#define linit (cv_mem->cv_linit) +#define lsetup (cv_mem->cv_lsetup) +#define lsolve (cv_mem->cv_lsolve) +#define lfree (cv_mem->cv_lfree) +#define lmem (cv_mem->cv_lmem) +#define qu (cv_mem->cv_qu) +#define nstlp (cv_mem->cv_nstlp) +#define hu (cv_mem->cv_hu) +#define saved_tq5 (cv_mem->cv_saved_tq5) +#define jcur (cv_mem->cv_jcur) +#define tolsf (cv_mem->cv_tolsf) +#define setupNonNull (cv_mem->cv_setupNonNull) +#define machenv (cv_mem->cv_machenv) +#define sldeton (cv_mem->cv_sldeton) + +/**************************************************************/ +/***************** END Readability Constants ******************/ +/**************************************************************/ + + +/***************************************************************/ +/************* BEGIN CVODE Implementation **********************/ +/***************************************************************/ + + +/***************************************************************/ +/********* BEGIN Exported Functions Implementation *************/ +/***************************************************************/ + + +/******************** CVodeMalloc ******************************* + + CVodeMalloc allocates and initializes memory for a problem. All + problem specification inputs are checked for errors. If any + error occurs during initialization, it is reported to the file + whose file pointer is errfp and NULL is returned. Otherwise, the + pointer to successfully initialized problem memory is returned. + +*****************************************************************/ + +void * +CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, + realtype * reltol, void *abstol, + void *f_data, FILE * errfp, booleantype optIn, + long int iopt[], realtype ropt[], M_Env machEnv) +{ + booleantype allocOK, ioptExists, roptExists, neg_abstol, ewtsetOK; + int maxord; + CVodeMem cv_mem; + FILE *fp; + int i, k; + + /* Check for legal input parameters */ + + fp = (errfp == NULL) ? stdout : errfp; + + if (y0 == NULL) + { + MACHENV warning_msg( MSG_Y0_NULL); + return (NULL); + } + + if (N <= 0) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_N, N)); + return (NULL); + } + + if ((lmm != ADAMS) && (lmm != BDF)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_LMM, lmm, ADAMS, BDF)); + return (NULL); + } + + if ((iter != FUNCTIONAL) && (iter != NEWTON)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON)); + return (NULL); + } + + if ((itol != SS) && (itol != SV)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITOL, itol, SS, SV)); + return (NULL); + } + + if (f == NULL) + { + MACHENV warning_msg(MSG_F_NULL); + return (NULL); + } + + if (reltol == NULL) + { + MACHENV warning_msg(MSG_RELTOL_NULL); + return (NULL); + } + + if (*reltol < ZERO) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_RELTOL, (double) *reltol)); + return (NULL); + } + + if (abstol == NULL) + { + MACHENV warning_msg(MSG_ABSTOL_NULL); + return (NULL); + } + + if (itol == SS) + { + neg_abstol = (*((realtype *) abstol) < ZERO); + } + else + { + neg_abstol = (N_VMin((N_Vector) abstol) < ZERO); + } + if (neg_abstol) + { + MACHENV warning_msg(MSG_BAD_ABSTOL); + return (NULL); + } + + if ((optIn != FALSE) && (optIn != TRUE)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_OPTIN, optIn, FALSE, TRUE)); + return (NULL); + } + + if ((optIn) && (iopt == NULL) && (ropt == NULL)) + { + MACHENV warning_msg(MSG_BAD_OPT); + return (NULL); + } + + ioptExists = (iopt != NULL); + roptExists = (ropt != NULL); + + /* Compute maxord */ + + maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; + + if (optIn && ioptExists) + { + if (iopt[MAXORD] > 0) + maxord = MIN(maxord, iopt[MAXORD]); + } + + cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec)); + if (cv_mem == NULL) + { + MACHENV warning_msg(MSG_MEM_FAIL); + return (NULL); + } + + /* Allocate the vectors */ + + allocOK = CVAllocVectors(cv_mem, N, maxord, machEnv); + if (!allocOK) + { + MACHENV warning_msg(MSG_MEM_FAIL); + MACHENV_MALLOC PHRQ_free(cv_mem); + return (NULL); + } + + /* Copy tolerances into memory, and set the ewt vector */ + + cv_mem->cv_itol = itol; + cv_mem->cv_reltol = reltol; + cv_mem->cv_abstol = abstol; + ewtsetOK = CVEwtSet(cv_mem, y0); + if (!ewtsetOK) + { + MACHENV warning_msg(MSG_BAD_EWT); + CVFreeVectors(cv_mem, maxord); + MACHENV_MALLOC PHRQ_free(cv_mem); + return (NULL); + } + + /* All error checking is complete at this point */ + + /* Copy the remaining input parameters into CVODE memory */ + + cv_mem->cv_N = N; + cv_mem->cv_f = f; + cv_mem->cv_f_data = f_data; + cv_mem->cv_lmm = lmm; + cv_mem->cv_iter = iter; + cv_mem->cv_optIn = optIn; + cv_mem->cv_iopt = iopt; + cv_mem->cv_ropt = ropt; + cv_mem->cv_errfp = fp; + tn = t0; + machenv = machEnv; + + /* Set step parameters */ + + q = 1; + L = 2; + qwait = L; + qmax = maxord; + etamax = ETAMX1; + + /* Set uround */ + + uround = UnitRoundoff(); + + /* Set the linear solver addresses to NULL. + (We check != NULL later, in CVode, if using NEWTON.) */ + + linit = NULL; + lsetup = NULL; + lsolve = NULL; + lfree = NULL; + lmem = NULL; + + /* Initialize zn[0] in the history array */ + + N_VScale(ONE, y0, zn[0]); + + /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ + + hmax_inv = HMAX_INV_DEFAULT; + hmin = HMIN_DEFAULT; + if (optIn && roptExists) + { + if (ropt[HMIN] > ZERO) + hmin = ropt[HMIN]; + } + + mxhnil = MXHNIL_DEFAULT; + mxstep = MXSTEP_DEFAULT; + if (optIn && ioptExists) + { + if (iopt[MXHNIL] != 0) + mxhnil = iopt[MXHNIL]; + if (iopt[MXSTEP] > 0) + mxstep = iopt[MXSTEP]; + } + + if ((!optIn) && roptExists) + ropt[H0] = ZERO; + + /* Set maxcor */ + + maxcor = (iter == NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; + + /* Initialize all the counters */ + + nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; + + /* Initialize all other variables corresponding to optional outputs */ + + qu = 0; + hu = ZERO; + tolsf = ONE; + + /* Initialize optional output locations in iopt, ropt */ + /* and Stablilty Limit Detection data. */ + + nscon = 0; + sldeton = FALSE; + if (ioptExists) + { + iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; + iopt[NCFN] = iopt[NETF] = 0; + iopt[QU] = qu; + iopt[QCUR] = 0; + iopt[LENRW] = lrw; + iopt[LENIW] = liw; + if (optIn && iopt[SLDET] && (lmm == BDF)) + { + sldeton = TRUE; + iopt[NOR] = 0; + for (i = 1; i <= 5; i++) + { + for (k = 1; k <= 3; k++) + ssdat[i - 1][k - 1] = ZERO; + } + } + } + + if (roptExists) + { + ropt[HU] = hu; + ropt[HCUR] = ZERO; + ropt[TCUR] = t0; + ropt[TOLSF] = tolsf; + } + + + /* Problem has been successfully initialized */ + + return ((void *) cv_mem); +} + + +/******************** CVReInit ********************************** + + CVReInit re-initializes CVODE's memory for a problem, assuming + it has already been allocated in a prior CVodeMalloc call. + All problem specification inputs are checked for errors. + The problem size N is assumed to be unchanged since the call to + CVodeMalloc, and the maximum order maxord must not be larger. + If any error occurs during initialization, it is reported to the + file whose file pointer is errfp. + The return value is SUCCESS = 0 if no errors occurred, or + a negative value otherwise. + +*****************************************************************/ + +int +CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, + realtype * reltol, void *abstol, + void *f_data, FILE * errfp, booleantype optIn, + long int iopt[], realtype ropt[], M_Env machEnv) +{ + booleantype ioptExists, roptExists, neg_abstol, ewtsetOK; + int maxord, i, k; + CVodeMem cv_mem; + FILE *fp; + + /* Check for legal input parameters */ + + fp = (errfp == NULL) ? stdout : errfp; + + if (cvode_mem == NULL) + { + MACHENV warning_msg(MSG_REI_NO_MEM); + return (CVREI_NO_MEM); + } + cv_mem = (CVodeMem) cvode_mem; + + if (y0 == NULL) + { + MACHENV warning_msg(MSG_Y0_NULL); + return (CVREI_ILL_INPUT); + } + + if ((lmm != ADAMS) && (lmm != BDF)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_LMM, lmm, ADAMS, BDF)); + return (CVREI_ILL_INPUT); + } + + if ((iter != FUNCTIONAL) && (iter != NEWTON)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON)); + return (CVREI_ILL_INPUT); + } + + if ((itol != SS) && (itol != SV)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITOL, itol, SS, SV)); + return (CVREI_ILL_INPUT); + } + + if (f == NULL) + { + MACHENV warning_msg(MSG_F_NULL); + return (CVREI_ILL_INPUT); + } + + if (reltol == NULL) + { + MACHENV warning_msg(MSG_RELTOL_NULL); + return (CVREI_ILL_INPUT); + } + + if (*reltol < ZERO) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_RELTOL, (double) *reltol)); + return (CVREI_ILL_INPUT); + } + + if (abstol == NULL) + { + MACHENV warning_msg(MSG_ABSTOL_NULL); + return (CVREI_ILL_INPUT); + } + + if (itol == SS) + { + neg_abstol = (*((realtype *) abstol) < ZERO); + } + else + { + neg_abstol = (N_VMin((N_Vector) abstol) < ZERO); + } + if (neg_abstol) + { + MACHENV warning_msg(MSG_BAD_ABSTOL); + return (CVREI_ILL_INPUT); + } + + if ((optIn != FALSE) && (optIn != TRUE)) + { + MACHENV warning_msg(MACHENV sformatf(MSG_BAD_OPTIN, optIn, FALSE, TRUE)); + return (CVREI_ILL_INPUT); + } + + if ((optIn) && (iopt == NULL) && (ropt == NULL)) + { + MACHENV warning_msg(MSG_BAD_OPT); + return (CVREI_ILL_INPUT); + } + + ioptExists = (iopt != NULL); + roptExists = (ropt != NULL); + + /* Compute new maxord and check against old value */ + + maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX; + if (optIn && ioptExists) + { + if (iopt[MAXORD] > 0) + maxord = MIN(maxord, iopt[MAXORD]); + } + if (maxord > qmax) + { + MACHENV warning_msg(MACHENV sformatf(MSG_REI_MAXORD, qmax, maxord)); + return (CVREI_ILL_INPUT); + } + + /* Copy tolerances into memory, and set the ewt vector */ + + cv_mem->cv_itol = itol; + cv_mem->cv_reltol = reltol; + cv_mem->cv_abstol = abstol; + ewtsetOK = CVEwtSet(cv_mem, y0); + if (!ewtsetOK) + { + MACHENV warning_msg(MSG_BAD_EWT); + return (CVREI_ILL_INPUT); + } + + /* All error checking is complete at this point */ + + /* Copy the remaining input parameters into CVODE memory */ + + cv_mem->cv_f = f; + cv_mem->cv_f_data = f_data; + cv_mem->cv_lmm = lmm; + cv_mem->cv_iter = iter; + cv_mem->cv_optIn = optIn; + cv_mem->cv_iopt = iopt; + cv_mem->cv_ropt = ropt; + cv_mem->cv_errfp = fp; + tn = t0; + machenv = machEnv; + + /* Set step parameters */ + + q = 1; + L = 2; + qwait = L; + qmax = maxord; + etamax = ETAMX1; + + /* Set uround */ + + uround = UnitRoundoff(); + + /* Initialize zn[0] in the history array */ + + N_VScale(ONE, y0, zn[0]); + + /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */ + + hmax_inv = HMAX_INV_DEFAULT; + hmin = HMIN_DEFAULT; + if (optIn && roptExists) + { + if (ropt[HMIN] > ZERO) + hmin = ropt[HMIN]; + } + + mxhnil = MXHNIL_DEFAULT; + mxstep = MXSTEP_DEFAULT; + if (optIn && ioptExists) + { + if (iopt[MXHNIL] != 0) + mxhnil = iopt[MXHNIL]; + if (iopt[MXSTEP] > 0) + mxstep = iopt[MXSTEP]; + } + + if ((!optIn) && roptExists) + ropt[H0] = ZERO; + + /* Set maxcor */ + + maxcor = (iter == NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR; + + /* Initialize all the counters */ + + nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0; + + /* Initialize all other vars corresponding to optional outputs */ + + qu = 0; + hu = ZERO; + tolsf = ONE; + + /* Initialize optional output locations in iopt, ropt */ + /* and Stablilty Limit Detection data. */ + + nscon = 0; + sldeton = FALSE; + if (ioptExists) + { + iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0; + iopt[NCFN] = iopt[NETF] = 0; + iopt[QU] = qu; + iopt[QCUR] = 0; + iopt[LENRW] = lrw; + iopt[LENIW] = liw; + if (optIn && iopt[SLDET] && (lmm == BDF)) + { + sldeton = TRUE; + iopt[NOR] = 0; + for (i = 1; i <= 5; i++) + { + for (k = 1; k <= 3; k++) + ssdat[i - 1][k - 1] = ZERO; + } + } + } + + if (roptExists) + { + ropt[HU] = hu; + ropt[HCUR] = ZERO; + ropt[TCUR] = t0; + ropt[TOLSF] = tolsf; + } + + /* Problem has been successfully re-initialized */ + + return (SUCCESS); +} + + +/**************************************************************/ +/************** BEGIN More Readability Constants **************/ +/**************************************************************/ + +#define N (cv_mem->cv_N) +#define f (cv_mem->cv_f) +#define f_data (cv_mem->cv_f_data) +#define lmm (cv_mem->cv_lmm) +#define iter (cv_mem->cv_iter) +#define itol (cv_mem->cv_itol) +#define reltol (cv_mem->cv_reltol) +#define abstol (cv_mem->cv_abstol) +#define optIn (cv_mem->cv_optIn) +#define iopt (cv_mem->cv_iopt) +#define ropt (cv_mem->cv_ropt) +#define errfp (cv_mem->cv_errfp) + +/**************************************************************/ +/*************** END More Readability Constants ***************/ +/**************************************************************/ + + +/********************* CVode **************************************** + + This routine is the main driver of the CVODE package. + + It integrates over a time interval defined by the user, by calling + CVStep to do internal time steps. + + The first time that CVode is called for a successfully initialized + problem, it computes a tentative initial step size h. + + CVode supports two modes, specified by itask: NORMAL and ONE_STEP. + In the NORMAL mode, the solver steps until it reaches or passes tout + and then interpolates to obtain y(tout). + In the ONE_STEP mode, it takes one internal step and returns. + +********************************************************************/ + +int +CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype * t, int itask) +{ + int nstloc, kflag, istate, next_q, ier; + realtype rh, next_h; + booleantype hOK, ewtsetOK; + CVodeMem cv_mem; + realtype t0; + + /* Check for legal inputs in all cases */ + + cv_mem = (CVodeMem) cvode_mem; + if (cvode_mem == NULL) + { + CVMEM warning_msg(MSG_CVODE_NO_MEM); + return (CVODE_NO_MEM); + } + + if ((y = yout) == NULL) + { + CVMEM warning_msg(MSG_YOUT_NULL); + return (ILL_INPUT); + } + + if (t == NULL) + { + CVMEM warning_msg(MSG_T_NULL); + return (ILL_INPUT); + } + t0 = tn; + *t = tn; + + if ((itask != NORMAL) && (itask != ONE_STEP)) + { + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_ITASK, itask, NORMAL, ONE_STEP)); + return (ILL_INPUT); + } + + /* Set hmax_inv from ropt[HMAX] and test for hmin > hmax */ + + if (optIn && ropt != NULL) + { + if (ropt[HMAX] > ZERO) + hmax_inv = ONE / ropt[HMAX]; + if (hmin * hmax_inv > ONE) + { + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_HMIN_HMAX, (double) hmin, + (double) ropt[HMAX])); + return (ILL_INPUT); + } + } + + /* On first call, check solver functions and call linit function */ + + if (nst == 0) + { + if (iter == NEWTON) + { + if (linit == NULL) + { + CVMEM warning_msg(MSG_LINIT_NULL); + return (ILL_INPUT); + } + if (lsetup == NULL) + { + CVMEM warning_msg(MSG_LSETUP_NULL); + return (ILL_INPUT); + } + if (lsolve == NULL) + { + CVMEM warning_msg(MSG_LSOLVE_NULL); + return (ILL_INPUT); + } + if (lfree == NULL) + { + CVMEM warning_msg(MSG_LFREE_NULL); + return (ILL_INPUT); + } + ier = linit(cv_mem); + if (ier != LINIT_OK) + { + CVMEM warning_msg(MSG_LINIT_FAIL); + return (ILL_INPUT); + } + } + + /* On the first call, call f at (t0,y0), set zn[1] = y'(t0), + set initial h (from H0 or CVHin), and scale zn[1] by h */ + CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tn; + CVMEM cvode_step_fraction = 0; + + f(N, tn, zn[0], zn[1], f_data); + nfe = 1; + h = ZERO; + if (ropt != NULL) + h = ropt[H0]; + if ((h != ZERO) && ((tout - tn) * h < ZERO)) + { + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_H0, (double) h, + (double) (tout - tn))); + return (ILL_INPUT); + } + if (h == ZERO) + { + hOK = CVHin(cv_mem, tout); + if (!hOK) + { + CVMEM warning_msg(CVMEM sformatf(MSG_TOO_CLOSE, (double) tout, + (double) tn)); + return (ILL_INPUT); + } + } + rh = ABS(h) * hmax_inv; + if (rh > ONE) + h /= rh; + if (ABS(h) < hmin) + h *= hmin / ABS(h); + hscale = h; + N_VScale(h, zn[1], zn[1]); + + } /* end of first call block */ + + /* If not the first call, check if tout already reached */ + + if ((itask == NORMAL) && (nst > 0) && ((tn - tout) * h >= ZERO)) + { + *t = tout; + ier = CVodeDky(cv_mem, tout, 0, yout); + if (ier != OKAY) + { /* ier must be == BAD_T */ + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_TOUT, (double) tout)); + return (ILL_INPUT); + } + return (SUCCESS); + } + + /* Looping point for internal steps */ + + nstloc = 0; + loop + { + + next_h = h; + next_q = q; + + /* Reset and check ewt */ + + if (nst > 0) + { + ewtsetOK = CVEwtSet(cv_mem, zn[0]); + if (!ewtsetOK) + { + CVMEM warning_msg(CVMEM sformatf(MSG_EWT_NOW_BAD, (double) tn)); + istate = ILL_INPUT; + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + } + + /* Check for too many steps */ + + if (nstloc >= mxstep) + { + istate = TOO_MUCH_WORK; + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + + /* Check for too much accuracy requested */ + + if ((tolsf = uround * N_VWrmsNorm(zn[0], ewt)) > ONE) + { + CVMEM warning_msg(CVMEM sformatf(MSG_TOO_MUCH_ACC, (double) tn)); + istate = TOO_MUCH_ACC; + *t = tn; + N_VScale(ONE, zn[0], yout); + tolsf *= TWO; + break; + } + + /* Check for h below roundoff level in tn */ + + if (tn + h == tn) + { + nhnil++; + if (nhnil <= mxhnil) + CVMEM warning_msg(CVMEM sformatf(MSG_HNIL, (double) tn, (double) h)); + if (nhnil == mxhnil) + CVMEM warning_msg(CVMEM sformatf(MSG_HNIL_DONE, mxhnil)); + } + + /* Call CVStep to take a step */ + + kflag = CVStep(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After CVStep, y Fail\n"); + } + else + { + CVMEM warning_msg("After CVStep, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CCVMEM warning_msg("After CVStep, zn Fail\n"); + } + else + { + CVMEM warning_msg("After CVStep, zn OK\n"); + } +#endif + /* Process failed step cases, and exit loop */ + + if (kflag != SUCCESS_STEP) + { + istate = CVHandleFailure(cv_mem, kflag); + *t = tn; + N_VScale(ONE, zn[0], yout); + break; + } + + nstloc++; + + /* Check if in one-step mode, and if so copy y and exit loop */ + + if (itask == ONE_STEP) + { + istate = SUCCESS; + *t = tn; + N_VScale(ONE, zn[0], yout); + next_q = qprime; + next_h = hprime; + break; + } + CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tn; + CVMEM cvode_step_fraction = (tn - t0) / (tout - t0); + /* + CVMEM warning_msg(CVMEM sformatf("ODE: tn %e, t0 %e, tout %e, step_frac %e\n", (double) tn, (double) t0, (double) tout, (double) cvode_step_fraction)); + */ + /* Check if tout reached, and if so interpolate and exit loop */ + + if ((tn - tout) * h >= ZERO) + { + /* + CVMEM warning_msg("*tn %e, t0 %e, tout %e, h %e\n", tn, t0, tout,h).c_str()); + */ + CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tout; + CVMEM cvode_step_fraction = 1.0; + istate = SUCCESS; + *t = tout; + (void) CVodeDky(cv_mem, tout, 0, yout); + next_q = qprime; + next_h = hprime; + break; + } + } + + /* End of step loop; load optional outputs and return */ + + if (iopt != NULL) + { + iopt[NST] = nst; + iopt[NFE] = nfe; + iopt[NSETUPS] = nsetups; + iopt[NNI] = nni; + iopt[NCFN] = ncfn; + iopt[NETF] = netf; + iopt[QU] = q; + iopt[QCUR] = next_q; + } + + if (ropt != NULL) + { + ropt[HU] = h; + ropt[HCUR] = next_h; + ropt[TCUR] = tn; + ropt[TOLSF] = tolsf; + } +#ifdef DEBUG_CVODE + /* + * check interpolation + */ + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("End of cvode, Interpolated y Fail\n"); + return (-1); + } + else + { + CVMEM warning_msg("End of cvode, Interpolated y OK\n"); + } +#endif + return (istate); +} + +/*************** CVodeDky ******************************************** + + This routine computes the k-th derivative of the interpolating + polynomial at the time t and stores the result in the vector dky. + The formula is: + q + dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] , + j=k + where c(j,k) = j*(j-1)*...*(j-k+1), q is the current order, and + zn[j] is the j-th column of the Nordsieck history array. + + This function is called by CVode with k = 0 and t = tout, but + may also be called directly by the user. + +**********************************************************************/ + +int +CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky) +{ + realtype s, c, r; + realtype tfuzz, tp, tn1; + int i, j; + CVodeMem cv_mem; + + cv_mem = (CVodeMem) cvode_mem; + + /* Check all inputs for legality */ + + if (cvode_mem == NULL) + { + /* + CVMEM warning_msg(MSG_DKY_NO_MEM); + */ + return (DKY_NO_MEM); + } + + if (dky == NULL) + { + CVMEM warning_msg(MSG_BAD_DKY); + return (BAD_DKY); + } + + if ((k < 0) || (k > q)) + { + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_K, k)); + return (BAD_K); + } + + tfuzz = FUZZ_FACTOR * uround * (ABS(tn) + ABS(hu)); + if (hu < ZERO) + tfuzz = -tfuzz; + tp = tn - hu - tfuzz; + tn1 = tn + tfuzz; + if ((t - tp) * (t - tn1) > ZERO) + { + CVMEM warning_msg(CVMEM sformatf(MSG_BAD_T, (double) t, (double) (tn - hu), + (double) tn)); + return (BAD_T); + } + + /* Sum the differentiated interpolating polynomial */ + + s = (t - tn) / h; + for (j = q; j >= k; j--) + { + c = ONE; + for (i = j; i >= j - k + 1; i--) + c *= i; + if (j == q) + { + N_VScale(c, zn[q], dky); + } + else + { + N_VLinearSum(c, zn[j], s, dky, dky); + } + } + if (k == 0) + return (OKAY); + r = RPowerI(h, -k); + N_VScale(r, dky, dky); + return (OKAY); +} + +/********************* CVodeFree ********************************** + + This routine frees the problem memory allocated by CVodeMalloc. + Such memory includes all the vectors allocated by CVAllocVectors, + and the memory lmem for the linear solver (deallocated by a call + to lfree). + +*******************************************************************/ + +void +CVodeFree(void *cvode_mem) +{ + CVodeMem cv_mem; + + cv_mem = (CVodeMem) cvode_mem; + + if (cvode_mem == NULL) + return; + + CVFreeVectors(cv_mem, qmax); + if (iter == NEWTON) + lfree(cv_mem); + CVMEM_MALLOC PHRQ_free(cv_mem); +} + + +/***************************************************************/ +/********** END Exported Functions Implementation **************/ +/***************************************************************/ + + +/*******************************************************************/ +/******** BEGIN Private Helper Functions Implementation ************/ +/*******************************************************************/ + +/****************** CVAllocVectors *********************************** + + This routine allocates the CVODE vectors ewt, acor, tempv, ftemp, and + zn[0], ..., zn[maxord]. The length of the vectors is the input + parameter neq and the maximum order (needed to allocate zn) is the + input parameter maxord. If all memory allocations are successful, + CVAllocVectors returns TRUE. Otherwise all allocated memory is freed + and CVAllocVectors returns FALSE. + This routine also sets the optional outputs lrw and liw, which are + (respectively) the lengths of the real and integer work spaces + allocated here. + +**********************************************************************/ + +static booleantype +CVAllocVectors(CVodeMem cv_mem, integertype neq, int maxord, M_Env machEnv) +{ + int i, j; + + /* Allocate ewt, acor, tempv, ftemp */ + + ewt = N_VNew(neq, machEnv); + if (ewt == NULL) + return (FALSE); + acor = N_VNew(neq, machEnv); + if (acor == NULL) + { + N_VFree(ewt); + return (FALSE); + } + tempv = N_VNew(neq, machEnv); + if (tempv == NULL) + { + N_VFree(ewt); + N_VFree(acor); + return (FALSE); + } + ftemp = N_VNew(neq, machEnv); + if (ftemp == NULL) + { + N_VFree(tempv); + N_VFree(ewt); + N_VFree(acor); + return (FALSE); + } + + /* Allocate zn[0] ... zn[maxord] */ + + for (j = 0; j <= maxord; j++) + { + zn[j] = N_VNew(neq, machEnv); + if (zn[j] == NULL) + { + N_VFree(ewt); + N_VFree(acor); + N_VFree(tempv); + N_VFree(ftemp); + for (i = 0; i < j; i++) + N_VFree(zn[i]); + return (FALSE); + } + } + + /* Set solver workspace lengths */ + + lrw = (maxord + 5) * neq; + liw = 0; + + return (TRUE); +} + +/***************** CVFreeVectors ********************************* + + This routine frees the CVODE vectors allocated in CVAllocVectors. + +******************************************************************/ + +static void +CVFreeVectors(CVodeMem cv_mem, int maxord) +{ + int j; + + N_VFree(ewt); + N_VFree(acor); + N_VFree(tempv); + N_VFree(ftemp); + for (j = 0; j <= maxord; j++) + N_VFree(zn[j]); +} + +/*********************** CVEwtSet ************************************** + + This routine is responsible for setting the error weight vector ewt, + according to tol_type, as follows: + + (1) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + *abstol), i=0,...,neq-1 + if tol_type = SS + (2) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + abstol[i]), i=0,...,neq-1 + if tol_type = SV + + CVEwtSet returns TRUE if ewt is successfully set as above to a + positive vector and FALSE otherwise. In the latter case, ewt is + considered undefined after the FALSE return from CVEwtSet. + + All the real work is done in the routines CVEwtSetSS, CVEwtSetSV. + +***********************************************************************/ + +static booleantype +CVEwtSet(CVodeMem cv_mem, N_Vector ycur) +{ + switch (itol) + { + case SS: + return (CVEwtSetSS(cv_mem, ycur)); + case SV: + return (CVEwtSetSV(cv_mem, ycur)); + } + return (-99); +} + +/*********************** CVEwtSetSS ********************************* + + This routine sets ewt as decribed above in the case tol_type = SS. + It tests for non-positive components before inverting. CVEwtSetSS + returns TRUE if ewt is successfully set to a positive vector + and FALSE otherwise. In the latter case, ewt is considered + undefined after the FALSE return from CVEwtSetSS. + +********************************************************************/ + +static booleantype +CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur) +{ + realtype rtoli, atoli; + + rtoli = *reltol; + atoli = *((realtype *) abstol); + N_VAbs(ycur, tempv); + N_VScale(rtoli, tempv, tempv); + N_VAddConst(tempv, atoli, tempv); + if (N_VMin(tempv) <= ZERO) + return (FALSE); + N_VInv(tempv, ewt); + return (TRUE); +} + +/*********************** CVEwtSetSV ********************************* + + This routine sets ewt as decribed above in the case tol_type = SV. + It tests for non-positive components before inverting. CVEwtSetSV + returns TRUE if ewt is successfully set to a positive vector + and FALSE otherwise. In the latter case, ewt is considered + undefined after the FALSE return from CVEwtSetSV. + +********************************************************************/ + +static booleantype +CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur) +{ + realtype rtoli; + rtoli = *reltol; + N_VAbs(ycur, tempv); + N_VLinearSum(rtoli, tempv, ONE, (N_Vector) abstol, tempv); + if (N_VMin(tempv) <= ZERO) + return (FALSE); + N_VInv(tempv, ewt); + return (TRUE); +} + +/******************* CVHin *************************************** + + This routine computes a tentative initial step size h0. + If tout is too close to tn (= t0), then CVHin returns FALSE and + h remains uninitialized. Otherwise, CVHin sets h to the chosen + value h0 and returns TRUE. + + The algorithm used seeks to find h0 as a solution of + (WRMS norm of (h0^2 ydd / 2)) = 1, + where ydd = estimated second derivative of y. + +*****************************************************************/ + +static booleantype +CVHin(CVodeMem cv_mem, realtype tout) +{ + int sign, count; + realtype tdiff, tdist, tround, hlb, hub; + realtype hg, hgs, hnew, hrat, h0, yddnrm; + + /* Test for tout too close to tn */ + + if ((tdiff = tout - tn) == ZERO) + return (FALSE); + + sign = (tdiff > ZERO) ? 1 : -1; + tdist = ABS(tdiff); + tround = uround * MAX(ABS(tn), ABS(tout)); + if (tdist < TWO * tround) + return (FALSE); + + /* Set lower and upper bounds on h0, and take geometric mean + Exit with this value if the bounds cross each other */ + + hlb = HLB_FACTOR * tround; + hub = CVUpperBoundH0(cv_mem, tdist); + hg = RSqrt(hlb * hub); + if (hub < hlb) + { + if (sign == -1) + hg = -hg; + h = hg; + return (TRUE); + } + + /* Loop up to MAX_ITERS times to find h0. + Stop if new and previous values differ by a factor < 2. + Stop if hnew/hg > 2 after one iteration, as this probably means + that the ydd value is bad because of cancellation error. */ + + count = 0; + loop + { + count++; + if (count >= MAX_ITERS) + break; + hgs = hg * sign; + yddnrm = CVYddNorm(cv_mem, hgs); + if (CVMEM cvode_error == TRUE) + { + hg /= 2.; +#ifdef DEBUG_CVODE + CVMEM warning_msg("halving step in CVHin\n"); +#endif + continue; + } + + hnew = + (yddnrm * hub * hub > + TWO) ? RSqrt(TWO / yddnrm) : RSqrt(hg * hub); + + hrat = hnew / hg; + if ((hrat > HALF) && (hrat < TWO)) + break; + if ((count >= 2) && (hrat > TWO)) + { + hnew = hg; + break; + } + hg = hnew; + } + + /* Apply bounds, bias factor, and attach sign */ + + h0 = H_BIAS * hnew; + if (h0 < hlb) + h0 = hlb; + if (h0 > hub) + h0 = hub; + if (sign == -1) + h0 = -h0; + h = h0; + return (TRUE); +} + +/******************** CVUpperBoundH0 ****************************** + + This routine sets an upper bound on abs(h0) based on + tdist = abs(tout - t0) and the values of y[i]/y'[i]. + +******************************************************************/ + +static realtype +CVUpperBoundH0(CVodeMem cv_mem, realtype tdist) +{ + realtype atoli, hub_inv, hub; + booleantype vectorAtol; + N_Vector temp1, temp2; + + atoli = 0; + vectorAtol = (itol == SV); + if (!vectorAtol) + atoli = *((realtype *) abstol); + temp1 = tempv; + temp2 = acor; + N_VAbs(zn[0], temp1); + N_VAbs(zn[1], temp2); + if (vectorAtol) + { + N_VLinearSum(HUB_FACTOR, temp1, ONE, (N_Vector) abstol, temp1); + } + else + { + N_VScale(HUB_FACTOR, temp1, temp1); + N_VAddConst(temp1, atoli, temp1); + } + N_VDiv(temp2, temp1, temp1); + hub_inv = N_VMaxNorm(temp1); + hub = HUB_FACTOR * tdist; + if (hub * hub_inv > ONE) + hub = ONE / hub_inv; + return (hub); +} + +/****************** CVYddNorm ************************************* + + This routine computes an estimate of the second derivative of y + using a difference quotient, and returns its WRMS norm. + +******************************************************************/ + +static realtype +CVYddNorm(CVodeMem cv_mem, realtype hg) +{ + realtype yddnrm; + + N_VLinearSum(hg, zn[1], ONE, zn[0], y); + f(N, tn + hg, y, tempv, f_data); +#ifdef DEBUG_CVODE + if (cvode_error == TRUE) + { + CVMEM warning_msg("CVYddNorm error\n"); + } +#endif + nfe++; + N_VLinearSum(ONE, tempv, -ONE, zn[1], tempv); + N_VScale(ONE / hg, tempv, tempv); + + yddnrm = N_VWrmsNorm(tempv, ewt); + return (yddnrm); +} + +/********************* CVStep ************************************** + + This routine performs one internal cvode step, from tn to tn + h. + It calls other routines to do all the work. + + The main operations done here are as follows: + * preliminary adjustments if a new step size was chosen; + * prediction of the Nordsieck history array zn at tn + h; + * setting of multistep method coefficients and test quantities; + * solution of the nonlinear system; + * testing the local error; + * updating zn and other state data if successful; + * resetting stepsize and order for the next step. + * if SLDET is on, check for stability, reduce order if necessary. + On a failure in the nonlinear system solution or error test, the + step may be reattempted, depending on the nature of the failure. + +********************************************************************/ + +static int +CVStep(CVodeMem cv_mem) +{ + realtype saved_t, dsm; + int ncf, nef, nflag; + booleantype passed; + + int kflag; + + saved_t = tn; + ncf = nef = 0; + nflag = FIRST_CALL; + + + if ((nst > 0) && (hprime != h)) + CVAdjustParams(cv_mem); + + /* Looping point for attempts to take a step */ + loop + { + CVMEM cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + CVMEM cvode_test = FALSE; + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("Before predict, y Fail, time %e\n", tn); +#endif + } + else + { + CVMEM cvode_prev_good_time = CVMEM cvode_last_good_time; + N_VScale(1.0, CVMEM cvode_last_good_y, CVMEM cvode_prev_good_y); + CVMEM cvode_last_good_time = tn; + N_VScale(1.0, y, CVMEM cvode_last_good_y); +#ifdef DEBUG_CVODE + CVMEM warning_msg("Before predict, y OK, time %e\n", tn); +#endif + } +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("Before predict, zn Fail\n"); + } + else + { + CVMEM warning_msg("Before predict, zn OK\n"); + } + saved_t = tn; +#endif + CVPredict(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After predict, y Fail\n"); + } + else + { + CVMEM warning_msg("After predict, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After predict, zn Fail\n"); + + } + else + { + CVMEM warning_msg("After predict, zn OK\n"); + } +#endif + CVSet(cv_mem); + + nflag = CVnls(cv_mem, nflag); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After CVnls, y Fail\n"); + } + else + { + CVMEM warning_msg("After CVnls, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After CVnls, zn Fail\n"); + } + else + { + CVMEM warning_msg("After CVnls, zn OK\n"); + } +#endif + kflag = CVHandleNFlag(cv_mem, &nflag, saved_t, &ncf); + if (kflag == PREDICT_AGAIN) + continue; + if (kflag != DO_ERROR_TEST) + return (kflag); + /* Return if nonlinear solve failed and recovery not possible. */ +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("Before error test, y Fail\n"); + } + else + { + CVMEM warning_msg("Before error test, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("Before error test, zn Fail\n"); + } + else + { + CVMEM warning_msg("Before error test, zn OK\n"); + } +#endif + passed = CVDoErrorTest(cv_mem, &nflag, &kflag, saved_t, &nef, &dsm); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg(CVMEM sformatf("After error test, y Fail, passed %d\n", + passed)); + } + else + { + CVMEM warning_msg(CVMEM sformatf("After error test, y OK, passed %d\n", + passed)); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After error test, zn Fail\n"); + } + else + { + CVMEM warning_msg("After error test, zn OK\n"); + } +#endif + /* Return if error test failed and recovery not possible. */ + if ((!passed) && (kflag == REP_ERR_FAIL)) + return (kflag); + if (passed) + break; + /* Retry step if error test failed, nflag == PREV_ERR_FAIL */ + } +#ifdef DEBUG_CVODE + CVMEM warning_msg("Finished step in CVStep\n"); +#endif + /* Nonlinear system solve and error test were both successful. + Update data, and consider change of step and/or order. */ + + + CVCompleteStep(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After complete step, y Fail\n"); + } + else + { + CVMEM warning_msg("After complete step, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After complete step, zn Fail\n"); + } + else + { + CVMEM warning_msg("After complete step, zn OK\n"); + } +#endif + CVPrepareNextStep(cv_mem, dsm); + + /* If Stablilty Limit Detection is turned on, call stability limit + detection routine for possible order reduction. */ + + if (sldeton) + CVBDFStab(cv_mem); +#ifdef DEBUG_CVODE + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After cvbfdstab, y Fail\n"); + } + else + { + CVMEM warning_msg("After cvbfdstab, y OK\n"); + } + cvode_test = TRUE; + f(N, tn, zn[0], ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("After cvbfdstab, zn Fail\n"); + } + else + { + CVMEM warning_msg("After cvbfdstab, zn OK\n"); + } +#endif + etamax = (nst <= SMALL_NST) ? ETAMX2 : ETAMX3; + + /* Finally, we rescale the acor array to be the + estimated local error vector. */ + + N_VScale(ONE / tq[2], acor, acor); + return (SUCCESS_STEP); + +} + + +/********************* CVAdjustParams ******************************** + + This routine is called when a change in step size was decided upon, + and it handles the required adjustments to the history array zn. + If there is to be a change in order, we call CVAdjustOrder and reset + q, L = q+1, and qwait. Then in any case, we call CVRescale, which + resets h and rescales the Nordsieck array. + +**********************************************************************/ + +static void +CVAdjustParams(CVodeMem cv_mem) +{ + if (qprime != q) + { + CVAdjustOrder(cv_mem, qprime - q); + q = qprime; + L = q + 1; + qwait = L; + } + CVRescale(cv_mem); +} + +/********************* CVAdjustOrder ***************************** + + This routine is a high level routine which handles an order + change by an amount deltaq (= +1 or -1). If a decrease in order + is requested and q==2, then the routine returns immediately. + Otherwise CVAdjustAdams or CVAdjustBDF is called to handle the + order change (depending on the value of lmm). + +******************************************************************/ + +static void +CVAdjustOrder(CVodeMem cv_mem, int deltaq) +{ + if ((q == 2) && (deltaq != 1)) + return; + + switch (lmm) + { + case ADAMS: + CVAdjustAdams(cv_mem, deltaq); + break; + case BDF: + CVAdjustBDF(cv_mem, deltaq); + break; + } +} + +/*************** CVAdjustAdams *********************************** + + This routine adjusts the history array on a change of order q by + deltaq, in the case that lmm == ADAMS. + +*****************************************************************/ + +static void +CVAdjustAdams(CVodeMem cv_mem, int deltaq) +{ + int i, j; + realtype xi, hsum; + + /* On an order increase, set new column of zn to zero and return */ + + if (deltaq == 1) + { + N_VConst(ZERO, zn[L]); + return; + } + + /* On an order decrease, each zn[j] is adjusted by a multiple + of zn[q]. The coefficients in the adjustment are the + coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_j), + integrated, where xi_j = [t_n - t_(n-j)]/h. */ + + for (i = 0; i <= qmax; i++) + l[i] = ZERO; + l[1] = ONE; + hsum = ZERO; + for (j = 1; j <= q - 2; j++) + { + hsum += tau[j]; + xi = hsum / hscale; + for (i = j + 1; i >= 1; i--) + l[i] = l[i] * xi + l[i - 1]; + } + + for (j = 1; j <= q - 2; j++) + l[j + 1] = q * (l[j] / (j + 1)); + + for (j = 2; j < q; j++) + N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); +} + +/********************** CVAdjustBDF ******************************* + + This is a high level routine which handles adjustments to the + history array on a change of order by deltaq in the case that + lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and + CVDecreaseBDF if deltaq = -1 to do the actual work. + +******************************************************************/ + +static void +CVAdjustBDF(CVodeMem cv_mem, int deltaq) +{ + switch (deltaq) + { + case 1: + CVIncreaseBDF(cv_mem); + return; + case -1: + CVDecreaseBDF(cv_mem); + return; + } +} + +/******************** CVIncreaseBDF ********************************** + + This routine adjusts the history array on an increase in the + order q in the case that lmm == BDF. + A new column zn[q+1] is set equal to a multiple of the saved + vector (= acor) in zn[qmax]. Then each zn[j] is adjusted by + a multiple of zn[q+1]. The coefficients in the adjustment are the + coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-1)), + where xi_j = [t_n - t_(n-j)]/h. + +*********************************************************************/ + +static void +CVIncreaseBDF(CVodeMem cv_mem) +{ + realtype alpha0, alpha1, prod, xi, xiold, hsum, A1; + int i, j; + + for (i = 0; i <= qmax; i++) + l[i] = ZERO; + l[2] = alpha1 = prod = xiold = ONE; + alpha0 = -ONE; + hsum = hscale; + if (q > 1) + { + for (j = 1; j < q; j++) + { + hsum += tau[j + 1]; + xi = hsum / hscale; + prod *= xi; + alpha0 -= ONE / (j + 1); + alpha1 += ONE / xi; + for (i = j + 2; i >= 2; i--) + l[i] = l[i] * xiold + l[i - 1]; + xiold = xi; + } + } + A1 = (-alpha0 - alpha1) / prod; + N_VScale(A1, zn[qmax], zn[L]); + for (j = 2; j <= q; j++) + { + N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); + } +} + +/********************* CVDecreaseBDF ****************************** + + This routine adjusts the history array on a decrease in the + order q in the case that lmm == BDF. + Each zn[j] is adjusted by a multiple of zn[q]. The coefficients + in the adjustment are the coefficients of the polynomial + x*x*(x+xi_1)*...*(x+xi_(q-2)), where xi_j = [t_n - t_(n-j)]/h. + +******************************************************************/ + +static void +CVDecreaseBDF(CVodeMem cv_mem) +{ + realtype hsum, xi; + int i, j; + + for (i = 0; i <= qmax; i++) + l[i] = ZERO; + l[2] = ONE; + hsum = ZERO; + for (j = 1; j <= q - 2; j++) + { + hsum += tau[j]; + xi = hsum / hscale; + for (i = j + 2; i >= 2; i--) + l[i] = l[i] * xi + l[i - 1]; + } + + for (j = 2; j < q; j++) + N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]); +} + +/**************** CVRescale *********************************** + + This routine rescales the Nordsieck array by multiplying the + jth column zn[j] by eta^j, j = 1, ..., q. Then the value of + h is rescaled by eta, and hscale is reset to h. + +***************************************************************/ + +static void +CVRescale(CVodeMem cv_mem) +{ + int j; + realtype factor; + + factor = eta; + for (j = 1; j <= q; j++) + { + N_VScale(factor, zn[j], zn[j]); + factor *= eta; + } + h = hscale * eta; + hscale = h; + nscon = 0; +} + +/********************* CVPredict ************************************* + + This routine advances tn by the tentative step size h, and computes + the predicted array z_n(0), which is overwritten on zn. The + prediction of zn is done by repeated additions. + +*********************************************************************/ + +static void +CVPredict(CVodeMem cv_mem) +{ + int j, k; + + tn += h; + for (k = 1; k <= q; k++) + for (j = q; j >= k; j--) + N_VLinearSum(ONE, zn[j - 1], ONE, zn[j], zn[j - 1]); +} + +/************************** CVSet ********************************* + + This routine is a high level routine which calls CVSetAdams or + CVSetBDF to set the polynomial l, the test quantity array tq, + and the related variables rl1, gamma, and gamrat. + +******************************************************************/ + +static void +CVSet(CVodeMem cv_mem) +{ + switch (lmm) + { + case ADAMS: + CVSetAdams(cv_mem); + break; + case BDF: + CVSetBDF(cv_mem); + break; + } + rl1 = ONE / l[1]; + gamma = h * rl1; + if (nst == 0) + gammap = gamma; + gamrat = (nst > 0) ? gamma / gammap : ONE; /* protect x / x != 1.0 */ +} + +/******************** CVSetAdams ********************************* + + This routine handles the computation of l and tq for the + case lmm == ADAMS. + + The components of the array l are the coefficients of a + polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by + q-1 + (d/dx) Lambda(x) = c * PRODUCT (1 + x / xi_i) , where + i=1 + Lambda(-1) = 0, Lambda(0) = 1, and c is a normalization factor. + Here xi_i = [t_n - t_(n-i)] / h. + + The array tq is set to test quantities used in the convergence + test, the error test, and the selection of h at a new order. + +*****************************************************************/ + +static void +CVSetAdams(CVodeMem cv_mem) +{ + realtype m[L_MAX], M[3], hsum; + + if (q == 1) + { + l[0] = l[1] = tq[1] = tq[5] = ONE; + tq[2] = TWO; + tq[3] = TWELVE; + tq[4] = CORTES * tq[2]; /* = 0.1 * tq[2] */ + return; + } + + hsum = CVAdamsStart(cv_mem, m); + + M[0] = CVAltSum(q - 1, m, 1); + M[1] = CVAltSum(q - 1, m, 2); + + CVAdamsFinish(cv_mem, m, M, hsum); +} + +/****************** CVAdamsStart ******************************** + + This routine generates in m[] the coefficients of the product + polynomial needed for the Adams l and tq coefficients for q > 1. + +******************************************************************/ + +static realtype +CVAdamsStart(CVodeMem cv_mem, realtype m[]) +{ + realtype hsum, xi_inv, sum; + int i, j; + + hsum = h; + m[0] = ONE; + for (i = 1; i <= q; i++) + m[i] = ZERO; + for (j = 1; j < q; j++) + { + if ((j == q - 1) && (qwait == 1)) + { + sum = CVAltSum(q - 2, m, 2); + tq[1] = m[q - 2] / (q * sum); + } + xi_inv = h / hsum; + for (i = j; i >= 1; i--) + m[i] += m[i - 1] * xi_inv; + hsum += tau[j]; + /* The m[i] are coefficients of product(1 to j) (1 + x/xi_i) */ + } + return (hsum); +} + +/****************** CVAdamsFinish ******************************* + + This routine completes the calculation of the Adams l and tq. + +******************************************************************/ + +static void +CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype hsum) +{ + int i; + realtype M0_inv, xi, xi_inv; + + M0_inv = ONE / M[0]; + + l[0] = ONE; + for (i = 1; i <= q; i++) + l[i] = M0_inv * (m[i - 1] / i); + xi = hsum / h; + xi_inv = ONE / xi; + + tq[2] = xi * M[0] / M[1]; + tq[5] = xi / l[q]; + + if (qwait == 1) + { + for (i = q; i >= 1; i--) + m[i] += m[i - 1] * xi_inv; + M[2] = CVAltSum(q, m, 2); + tq[3] = L * M[0] / M[2]; + } + + tq[4] = CORTES * tq[2]; +} + +/****************** CVAltSum ************************************** + + CVAltSum returns the value of the alternating sum + sum (i= 0 ... iend) [ (-1)^i * (a[i] / (i + k)) ]. + If iend < 0 then CVAltSum returns 0. + This operation is needed to compute the integral, from -1 to 0, + of a polynomial x^(k-1) M(x) given the coefficients of M(x). + +******************************************************************/ + +static realtype +CVAltSum(int iend, realtype a[], int k) +{ + int i, sign; + realtype sum; + + if (iend < 0) + return (ZERO); + + sum = ZERO; + sign = 1; + for (i = 0; i <= iend; i++) + { + sum += sign * (a[i] / (i + k)); + sign = -sign; + } + return (sum); +} + +/***************** CVSetBDF ************************************** + + This routine computes the coefficients l and tq in the case + lmm == BDF. CVSetBDF calls CVSetTqBDF to set the test + quantity array tq. + + The components of the array l are the coefficients of a + polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by + q-1 + Lambda(x) = (1 + x / xi*_q) * PRODUCT (1 + x / xi_i) , where + i=1 + xi_i = [t_n - t_(n-i)] / h. + + The array tq is set to test quantities used in the convergence + test, the error test, and the selection of h at a new order. + + +*****************************************************************/ + +static void +CVSetBDF(CVodeMem cv_mem) +{ + realtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum; + int i, j; + + l[0] = l[1] = xi_inv = xistar_inv = ONE; + for (i = 2; i <= q; i++) + l[i] = ZERO; + alpha0 = alpha0_hat = -ONE; + hsum = h; + if (q > 1) + { + for (j = 2; j < q; j++) + { + hsum += tau[j - 1]; + xi_inv = h / hsum; + alpha0 -= ONE / j; + for (i = j; i >= 1; i--) + l[i] += l[i - 1] * xi_inv; + /* The l[i] are coefficients of product(1 to j) (1 + x/xi_i) */ + } + + /* j = q */ + alpha0 -= ONE / q; + xistar_inv = -l[1] - alpha0; + hsum += tau[q - 1]; + xi_inv = h / hsum; + alpha0_hat = -l[1] - xi_inv; + for (i = q; i >= 1; i--) + l[i] += l[i - 1] * xistar_inv; + } + + CVSetTqBDF(cv_mem, hsum, alpha0, alpha0_hat, xi_inv, xistar_inv); +} + +/****************** CVSetTqBDF ************************************ + + This routine sets the test quantity array tq when lmm == BDF. + +******************************************************************/ + +static void +CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0, + realtype alpha0_hat, realtype xi_inv, realtype xistar_inv) +{ + realtype A1, A2, A3, A4, A5, A6; + realtype C, CPrime, CPrimePrime; + + A1 = ONE - alpha0_hat + alpha0; + A2 = ONE + q * A1; + tq[2] = ABS(alpha0 * (A2 / A1)); + tq[5] = ABS((A2) / (l[q] * xi_inv / xistar_inv)); + if (qwait == 1) + { + C = xistar_inv / l[q]; + A3 = alpha0 + ONE / q; + A4 = alpha0_hat + xi_inv; + CPrime = A3 / (ONE - A4 + A3); + tq[1] = ABS(CPrime / C); + hsum += tau[q]; + xi_inv = h / hsum; + A5 = alpha0 - (ONE / (q + 1)); + A6 = alpha0_hat - xi_inv; + CPrimePrime = A2 / (ONE - A6 + A5); + tq[3] = ABS(CPrimePrime * xi_inv * (q + 2) * A5); + } + tq[4] = CORTES * tq[2]; +} + +/****************** CVnls ***************************************** + + This routine attempts to solve the nonlinear system associated + with a single implicit step of the linear multistep method. + Depending on iter, it calls CVnlsFunctional or CVnlsNewton + to do the work. + +******************************************************************/ + +static int +CVnls(CVodeMem cv_mem, int nflag) +{ + switch (iter) + { + case FUNCTIONAL: + return (CVnlsFunctional(cv_mem)); + case NEWTON: + return (CVnlsNewton(cv_mem, nflag)); + } + return (-99); +} + +/***************** CVnlsFunctional ******************************** + + This routine attempts to solve the nonlinear system using + functional iteration (no matrices involved). + +******************************************************************/ + +static int +CVnlsFunctional(CVodeMem cv_mem) +{ + int m; + realtype del, delp, dcon; + + /* Initialize counter and evaluate f at predicted y */ + + delp = 0; + crate = ONE; + m = 0; + f(N, tn, zn[0], tempv, f_data); + nfe++; + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsFunctional, Fail at beginning\n"); +#endif + return (CONV_FAIL); + } + else + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsFunctional, OK at beginning\n"); +#endif + } + N_VConst(ZERO, acor); + + /* Loop until convergence; accumulate corrections in acor */ + + loop + { + /* Correct y directly from the last f value */ + N_VLinearSum(h, tempv, -ONE, zn[1], tempv); + N_VScale(rl1, tempv, tempv); + N_VLinearSum(ONE, zn[0], ONE, tempv, y); + /* Get WRMS norm of current correction to use in convergence test */ + N_VLinearSum(ONE, tempv, -ONE, acor, acor); + del = N_VWrmsNorm(acor, ewt); + N_VScale(ONE, tempv, acor); + + /* Test for convergence. If m > 0, an estimate of the convergence + rate constant is stored in crate, and used in the test. */ + if (m > 0) + crate = MAX(CRDOWN * crate, del / delp); + dcon = del * MIN(ONE, crate) / tq[4]; + if (dcon <= ONE) + { + acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt); + return (SOLVED); /* Convergence achieved */ + } + + /* Stop at maxcor iterations or if iter. seems to be diverging */ + m++; + if ((m == maxcor) || ((m >= 2) && (del > RDIV * delp))) + return (CONV_FAIL); + /* Save norm of correction, evaluate f, and loop again */ + delp = del; + f(N, tn, y, tempv, f_data); + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsFunctional, Fail at end\n"); +#endif + return (CONV_FAIL); + } + else + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsFunctional, OK at end\n"); +#endif + } + nfe++; + } +} + +/*********************** CVnlsNewton ********************************** + + This routine handles the Newton iteration. It calls lsetup if + indicated, calls CVNewtonIteration to perform the iteration, and + retries a failed attempt at Newton iteration if that is indicated. + See return values at top of this file. + +**********************************************************************/ + +static int +CVnlsNewton(CVodeMem cv_mem, int nflag) +{ + N_Vector vtemp1, vtemp2, vtemp3; + int convfail, ier; + booleantype callSetup; + + vtemp1 = acor; /* rename acor as vtemp1 for readability */ + vtemp2 = y; /* rename y as vtemp2 for readability */ + vtemp3 = tempv; /* rename tempv as vtemp3 for readability */ + + /* Set flag convfail, input to lsetup for its evaluation decision */ + convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) ? + NO_FAILURES : FAIL_OTHER; + + /* Decide whether or not to call setup routine (if one exists) */ + if (setupNonNull) + { + callSetup = (nflag == PREV_CONV_FAIL) || (nflag == PREV_ERR_FAIL) || + (nst == 0) || (nst >= nstlp + MSBP) + || (ABS(gamrat - ONE) > DGMAX); + } + else + { + crate = ONE; + callSetup = FALSE; + } + + /* Looping point for the solution of the nonlinear system. + Evaluate f at the predicted y, call lsetup if indicated, and + call CVNewtonIteration for the Newton iteration itself. */ + + loop + { + + f(N, tn, zn[0], ftemp, f_data); + + nfe++; + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg(CVMEM sformatf("CVnlsNewton, start of loop, time %e\n", + tn)); +#endif + return (CONV_FAIL); + } + else + { +#ifdef DEBUG_CVODE + CVMEM warning_msg(CVMEM sformatf( + "CVnlsNewton, OK, start of loop, time %e\n", tn)); +#endif + } + + if (callSetup) + { + ier = lsetup(cv_mem, convfail, zn[0], ftemp, &jcur, + vtemp1, vtemp2, vtemp3); + nsetups++; + callSetup = FALSE; + gamrat = crate = ONE; + gammap = gamma; + nstlp = nst; + /* Return if lsetup failed */ + if (ier < 0) + return (SETUP_FAIL_UNREC); + if (ier > 0) + return (CONV_FAIL); + } + + /* Set acor to zero and load prediction into y vector */ + N_VConst(ZERO, acor); + N_VScale(ONE, zn[0], y); + + /* Do the Newton iteration */ + ier = CVNewtonIteration(cv_mem); + + CVMEM cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + CVMEM cvode_test = FALSE; + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg(CVMEM sformatf( + "After CVNewtonIteration, Fail, ier %d\n", ier)); +#endif + return (CONV_FAIL); + } + else + { +#ifdef DEBUG_CVODE + CVMEM warning_msg(CVMEM sformatf("After CVNewtonIteration, OK, ier %d\n", + ier)); +#endif + } + /* If there is a convergence failure and the Jacobian-related + data appears not to be current, loop again with a call to lsetup + in which convfail=FAIL_BAD_J. Otherwise return. */ + if (ier != TRY_AGAIN_CVODE) + return (ier); + callSetup = TRUE; + convfail = FAIL_BAD_J; + } +} + +/********************** CVNewtonIteration **************************** + + This routine performs the Newton iteration. If the iteration succeeds, + it returns the value SOLVED. If not, it may signal the CVnlsNewton + routine to call lsetup again and reattempt the iteration, by + returning the value TRY_AGAIN_CVODE. (In this case, CVnlsNewton must set + convfail to FAIL_BAD_J before calling setup again). + Otherwise, this routine returns one of the appropriate values + SOLVE_FAIL_UNREC or CONV_FAIL back to CVnlsNewton. + +*********************************************************************/ + +static int +CVNewtonIteration(CVodeMem cv_mem) +{ + int m, ret; + realtype del, delp, dcon; + N_Vector b; + + + mnewt = m = 0; + delp = 0; + + /* Looping point for Newton iteration */ + loop + { + + /* Evaluate the residual of the nonlinear system */ + N_VLinearSum(rl1, zn[1], ONE, acor, tempv); + N_VLinearSum(gamma, ftemp, -ONE, tempv, tempv); + + /* Call the lsolve function */ + b = tempv; + ret = lsolve(cv_mem, b, y, ftemp); + nni++; + + if (ret < 0) + return (SOLVE_FAIL_UNREC); + + /* If lsolve had a recoverable failure and Jacobian data is + not current, signal to try the solution again */ + if (ret > 0) + { + if ((!jcur) && (setupNonNull)) + return (TRY_AGAIN_CVODE); + return (CONV_FAIL); + } + /* Get WRMS norm of correction; add correction to acor and y */ + del = N_VWrmsNorm(b, ewt); + N_VLinearSum(ONE, acor, ONE, b, acor); + N_VLinearSum(ONE, zn[0], ONE, acor, y); + + /* Test for convergence. If m > 0, an estimate of the convergence + rate constant is stored in crate, and used in the test. */ + if (m > 0) + { + crate = MAX(CRDOWN * crate, del / delp); + } + dcon = del * MIN(ONE, crate) / tq[4]; + +#ifdef DEBUG_CVODE + /* added before SOLVED */ + cvode_test = TRUE; + f(N, tn, y, ftemp, f_data); + cvode_test = FALSE; + if (cvode_error == TRUE) + { + CVMEM warning_msg("CVnlsNewton, Fail at SOLVED\n"); + return (CONV_FAIL); + } + else + { + CVMEM warning_msg("CVnlsNewton, OK at SOLVED\n"); + } +#endif + if (dcon <= ONE) + { + acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt); + jcur = FALSE; + return (SOLVED); /* Nonlinear system was solved successfully */ + } + + mnewt = ++m; + + /* Stop at maxcor iterations or if iter. seems to be diverging. + If still not converged and Jacobian data is not current, + signal to try the solution again */ + if ((m == maxcor) || ((m >= 2) && (del > RDIV * delp))) + { + if ((!jcur) && (setupNonNull)) + return (TRY_AGAIN_CVODE); + return (CONV_FAIL); + } + + /* Save norm of correction, evaluate f, and loop again */ + delp = del; + f(N, tn, y, ftemp, f_data); + + if (CVMEM cvode_error == TRUE) + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsNewton, Fail at end\n"); +#endif + return (CONV_FAIL); + } + else + { +#ifdef DEBUG_CVODE + CVMEM warning_msg("CVnlsNewton, OK at end\n"); +#endif + } + nfe++; + } +} + +/********************** CVHandleNFlag ******************************* + + This routine takes action on the return value nflag = *nflagPtr + returned by CVnls, as follows: + + If CVnls succeeded in solving the nonlinear system, then + CVHandleNFlag returns the constant DO_ERROR_TEST, which tells CVStep + to perform the error test. + + If the nonlinear system was not solved successfully, then ncfn and + ncf = *ncfPtr are incremented and Nordsieck array zn is restored. + + If the solution of the nonlinear system failed due to an + unrecoverable failure by setup, we return the value SETUP_FAILED. + + If it failed due to an unrecoverable failure in solve, then we return + the value SOLVE_FAILED. + + Otherwise, a recoverable failure occurred when solving the + nonlinear system (CVnls returned nflag == CONV_FAIL). + In this case, we return the value REP_CONV_FAIL if ncf is now + equal to MXNCF or |h| = hmin. + If not, we set *nflagPtr = PREV_CONV_FAIL and return the value + PREDICT_AGAIN, telling CVStep to reattempt the step. + +*********************************************************************/ + +static int +CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, int *ncfPtr) +{ + int nflag; + + nflag = *nflagPtr; + + if (nflag == SOLVED) + return (DO_ERROR_TEST); + + /* The nonlinear soln. failed; increment ncfn and restore zn */ + ncfn++; + CVRestore(cv_mem, saved_t); + + /* Return if lsetup or lsolve failed unrecoverably */ + if (nflag == SETUP_FAIL_UNREC) + return (SETUP_FAILED); + if (nflag == SOLVE_FAIL_UNREC) + return (SOLVE_FAILED); + + /* At this point, nflag == CONV_FAIL; increment ncf */ + + (*ncfPtr)++; + etamax = ONE; + /* If we had MXNCF failures or |h| = hmin, return REP_CONV_FAIL */ + if ((ABS(h) <= hmin * ONEPSM) || (*ncfPtr == MXNCF)) + return (REP_CONV_FAIL); + + /* Reduce step size; return to reattempt the step */ + eta = MAX(ETACF, hmin / ABS(h)); + *nflagPtr = PREV_CONV_FAIL; + CVRescale(cv_mem); + return (PREDICT_AGAIN); +} + +/********************** CVRestore ************************************ + + This routine restores the value of tn to saved_t and undoes the + prediction. After execution of CVRestore, the Nordsieck array zn has + the same values as before the call to CVPredict. + +********************************************************************/ + +static void +CVRestore(CVodeMem cv_mem, realtype saved_t) +{ + int j, k; + + tn = saved_t; + for (k = 1; k <= q; k++) + for (j = q; j >= k; j--) + N_VLinearSum(ONE, zn[j - 1], -ONE, zn[j], zn[j - 1]); +} + +/******************* CVDoErrorTest ******************************** + + This routine performs the local error test. + The weighted local error norm dsm is loaded into *dsmPtr, and + the test dsm ?<= 1 is made. + + If the test passes, CVDoErrorTest returns TRUE. + + If the test fails, we undo the step just taken (call CVRestore), + set *nflagPtr to PREV_ERR_FAIL, and return FALSE. + + If MXNEF error test failures have occurred or if ABS(h) = hmin, + we set *kflagPtr = REP_ERR_FAIL. (Otherwise *kflagPtr has the + value last returned by CVHandleNflag.) + + If more than MXNEF1 error test failures have occurred, an order + reduction is forced. + +******************************************************************/ + +static booleantype +CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, + realtype saved_t, int *nefPtr, realtype * dsmPtr) +{ + realtype dsm; + + dsm = acnrm / tq[2]; + + /* If est. local error norm dsm passes test, return TRUE */ + *dsmPtr = dsm; + if (dsm <= ONE) + return (TRUE); + + /* Test failed; increment counters, set nflag, and restore zn array */ + (*nefPtr)++; + netf++; + *nflagPtr = PREV_ERR_FAIL; + CVRestore(cv_mem, saved_t); + + /* At MXNEF failures or |h| = hmin, return with kflag = REP_ERR_FAIL */ + if ((ABS(h) <= hmin * ONEPSM) || (*nefPtr == MXNEF)) + { + *kflagPtr = REP_ERR_FAIL; + return (FALSE); + } + + /* Set etamax = 1 to prevent step size increase at end of this step */ + etamax = ONE; + + /* Set h ratio eta from dsm, rescale, and return for retry of step */ + if (*nefPtr <= MXNEF1) + { + eta = ONE / (RPowerR(BIAS2 * dsm, ONE / L) + ADDON); + eta = MAX(ETAMIN, MAX(eta, hmin / ABS(h))); + if (*nefPtr >= SMALL_NEF) + eta = MIN(eta, ETAMXF); + CVRescale(cv_mem); + return (FALSE); + } + + /* After MXNEF1 failures, force an order reduction and retry step */ + if (q > 1) + { + eta = MAX(ETAMIN, hmin / ABS(h)); + CVAdjustOrder(cv_mem, -1); + L = q; + q--; + qwait = L; + CVRescale(cv_mem); + return (FALSE); + } + + /* If already at order 1, restart: reload zn from scratch */ + eta = MAX(ETAMIN, hmin / ABS(h)); + h *= eta; + hscale = h; + qwait = LONG_WAIT; + nscon = 0; + f(N, tn, zn[0], tempv, f_data); + if (CVMEM cvode_error == TRUE) + { + CVMEM warning_msg("CVDoErrorTest"); + /*exit(8); */ + CVMEM error_msg("CVDoErrorTest", 1 /* STOP */ ); + } + nfe++; + N_VScale(h, tempv, zn[1]); + return (FALSE); +} + +/*************** CVCompleteStep ********************************** + + This routine performs various update operations when the solution + to the nonlinear system has passed the local error test. + We increment the step counter nst, record the values hu and qu, + update the tau array, and apply the corrections to the zn array. + The tau[i] are the last q values of h, with tau[1] the most recent. + The counter qwait is decremented, and if qwait == 1 (and q < qmax) + we save acor and tq[5] for a possible order increase. + +******************************************************************/ + +static void +CVCompleteStep(CVodeMem cv_mem) +{ + int i, j; + + nst++; + nscon++; + hu = h; + qu = q; + + for (i = q; i >= 2; i--) + tau[i] = tau[i - 1]; + if ((q == 1) && (nst > 1)) + tau[2] = tau[1]; + tau[1] = h; + + for (j = 0; j <= q; j++) + N_VLinearSum(l[j], acor, ONE, zn[j], zn[j]); + qwait--; + if ((qwait == 1) && (q != qmax)) + { + N_VScale(ONE, acor, zn[qmax]); + saved_tq5 = tq[5]; + } +} + +/************* CVPrepareNextStep ********************************** + + This routine handles the setting of stepsize and order for the + next step -- hprime and qprime. Along with hprime, it sets the + ratio eta = hprime/h. It also updates other state variables + related to a change of step size or order. + +******************************************************************/ + +static void +CVPrepareNextStep(CVodeMem cv_mem, realtype dsm) +{ + /* If etamax = 1, defer step size or order changes */ + if (etamax == ONE) + { + qwait = MAX(qwait, 2); + qprime = q; + hprime = h; + eta = ONE; + return; + } + + /* etaq is the ratio of new to old h at the current order */ + etaq = ONE / (RPowerR(BIAS2 * dsm, ONE / L) + ADDON); + + /* If no order change, adjust eta and acor in CVSetEta and return */ + if (qwait != 0) + { + eta = etaq; + qprime = q; + CVSetEta(cv_mem); + return; + } + + /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are + the ratios of new to old h at orders q-1 and q+1, respectively. + CVChooseEta selects the largest; CVSetEta adjusts eta and acor */ + qwait = 2; + etaqm1 = CVComputeEtaqm1(cv_mem); + etaqp1 = CVComputeEtaqp1(cv_mem); + CVChooseEta(cv_mem); + CVSetEta(cv_mem); +} + +/***************** CVSetEta *************************************** + + This routine adjusts the value of eta according to the various + heuristic limits and the optional input hmax. It also resets + etamax to be the estimated local error vector. + +*******************************************************************/ + +static void +CVSetEta(CVodeMem cv_mem) +{ + + /* If eta below the threshhold THRESH, reject a change of step size */ + if (eta < THRESH) + { + eta = ONE; + hprime = h; + } + else + { + /* Limit eta by etamax and hmax, then set hprime */ + eta = MIN(eta, etamax); + eta /= MAX(ONE, ABS(h) * hmax_inv * eta); + hprime = h * eta; + if (qprime < q) + nscon = 0; + } + + /* Reset etamax for the next step size change, and scale acor */ +} + +/*************** CVComputeEtaqm1 ********************************** + + This routine computes and returns the value of etaqm1 for a + possible decrease in order by 1. + +******************************************************************/ + +static realtype +CVComputeEtaqm1(CVodeMem cv_mem) +{ + realtype ddn; + + etaqm1 = ZERO; + if (q > 1) + { + ddn = N_VWrmsNorm(zn[q], ewt) / tq[1]; + etaqm1 = ONE / (RPowerR(BIAS1 * ddn, ONE / q) + ADDON); + } + return (etaqm1); +} + +/*************** CVComputeEtaqp1 ********************************** + + This routine computes and returns the value of etaqp1 for a + possible increase in order by 1. + +******************************************************************/ + +static realtype +CVComputeEtaqp1(CVodeMem cv_mem) +{ + realtype dup, cquot; + + etaqp1 = ZERO; + if (q != qmax) + { + cquot = (tq[5] / saved_tq5) * RPowerI(h / tau[2], L); + N_VLinearSum(-cquot, zn[qmax], ONE, acor, tempv); + dup = N_VWrmsNorm(tempv, ewt) / tq[3]; + etaqp1 = ONE / (RPowerR(BIAS3 * dup, ONE / (L + 1)) + ADDON); + } + return (etaqp1); +} + +/******************* CVChooseEta ********************************** + + Given etaqm1, etaq, etaqp1 (the values of eta for qprime = + q - 1, q, or q + 1, respectively), this routine chooses the + maximum eta value, sets eta to that value, and sets qprime to the + corresponding value of q. If there is a tie, the preference + order is to (1) keep the same order, then (2) decrease the order, + and finally (3) increase the order. If the maximum eta value + is below the threshhold THRESH, the order is kept unchanged and + eta is set to 1. + +******************************************************************/ + +static void +CVChooseEta(CVodeMem cv_mem) +{ + realtype etam; + + etam = MAX(etaqm1, MAX(etaq, etaqp1)); + + if (etam < THRESH) + { + eta = ONE; + qprime = q; + return; + } + + if (etam == etaq) + { + eta = etaq; + qprime = q; + } + else if (etam == etaqm1) + { + eta = etaqm1; + qprime = q - 1; + } + else + { + eta = etaqp1; + qprime = q + 1; + if (lmm == BDF) + N_VScale(ONE, acor, zn[qmax]); + } +} + +/****************** CVHandleFailure ****************************** + + This routine prints error messages for all cases of failure by + CVStep. It returns to CVode the value that CVode is to return to + the user. + +*****************************************************************/ + +static int +CVHandleFailure(CVodeMem cv_mem, int kflag) +{ + /* Set vector of absolute weighted local errors */ + N_VProd(acor, ewt, tempv); + N_VAbs(tempv, tempv); + + /* Depending on kflag, print error message and return error flag */ + switch (kflag) + { + case REP_ERR_FAIL: + { + //sprintf(error_string_long, MSG_ERR_FAILS, (double) tn, (double) h); + //CVMEM warning_msg(error_string_long); + char * error_string = CVMEM sformatf(MSG_ERR_FAILS, (double) tn, (double) h); + CVMEM warning_msg(error_string); + } + return (ERR_FAILURE); + case REP_CONV_FAIL: + { + //sprintf(error_string_long, MSG_CONV_FAILS, (double) tn, (double) h); + //CVMEM warning_msg(error_string_long); + char * error_string = CVMEM sformatf(MSG_CONV_FAILS, (double) tn, (double) h); + CVMEM warning_msg(error_string); + } + + return (CONV_FAILURE); + case SETUP_FAILED: + { + //sprintf(error_string_long, MSG_SETUP_FAILED, (double) tn); + //CVMEM warning_msg(error_string_long); + char * error_string = CVMEM sformatf(MSG_SETUP_FAILED, (double) tn); + CVMEM warning_msg(error_string); + } + return (SETUP_FAILURE); + case SOLVE_FAILED: + { + //sprintf(error_string_long, MSG_SOLVE_FAILED, (double) tn); + //CVMEM warning_msg(error_string_long); + char * error_string = CVMEM sformatf(MSG_SOLVE_FAILED, (double) tn); + CVMEM warning_msg(error_string); + } + return (SOLVE_FAILURE); + } + return (-99); +} + +/****************** CVBDFStab *********************************** + This routine handles the BDF Stability Limit Detection Algorithm + STALD. It is called if lmm = BDF and the SLDET option is on. + If the order is 3 or more, the required norm data is saved. + If a decision to reduce order has not already been made, and + enough data has been saved, CVsldet is called. If it signals + a stability limit violation, the order is reduced, and the step + size is reset accordingly. + +*****************************************************************/ + +void +CVBDFStab(CVodeMem cv_mem) +{ + int i, k, ldflag, factorial; + realtype sq, sqm1, sqm2; + + /* If order is 3 or greater, then save scaled derivative data, + push old data down in i, then add current values to top. */ + + if (q >= 3) + { + for (k = 1; k <= 3; k++) + { + for (i = 5; i >= 2; i--) + ssdat[i][k] = ssdat[i - 1][k]; + } + factorial = 1; + for (i = 1; i <= q - 1; i++) + factorial *= i; + sq = factorial * q * (q + 1) * acnrm / tq[5]; + sqm1 = factorial * q * N_VWrmsNorm(zn[q], ewt); + sqm2 = factorial * N_VWrmsNorm(zn[q - 1], ewt); + ssdat[1][1] = sqm2 * sqm2; + ssdat[1][2] = sqm1 * sqm1; + ssdat[1][3] = sq * sq; + } + + if (qprime >= q) + { + + /* If order is 3 or greater, and enough ssdat has been saved, + nscon >= q+5, then call stability limit detection routine. */ + + if ((q >= 3) && (nscon >= q + 5)) + { + ldflag = CVsldet(cv_mem); + if (ldflag > 3) + { + /* A stability limit violation is indicated by + a return flag of 4, 5, or 6. + Reduce new order. */ + qprime = q - 1; + eta = etaqm1; + eta = MIN(eta, etamax); + eta = eta / MAX(ONE, ABS(h) * hmax_inv * eta); + hprime = h * eta; + iopt[NOR] = iopt[NOR] + 1; + /* CVMEM warning_msg(CVMEM sformatf( + " Order reduced to %d by CVBDFStab at nst = %d,\n h = %e hnew = %e\n", + qprime,nst,h,h*eta)); */ + } + } + } + else + { + /* Otherwise, let order increase happen, and + reset stability limit counter, nscon. */ + nscon = 0; + } +} + +/********************* CVsldet ************************************ + This routine detects stability limitation using stored scaled + derivatives data. CVsldet returns the magnitude of the + dominate characteristic root, rr. The presents of a stability + limit is indicated by rr > "something a little less then 1.0", + and a positive kflag. This routine should only be called if + order is greater than or equal to 3, and data has been collected + for 5 time steps. + + Returned values: + kflag = 1 -> Found stable characteristic root, normal matrix case + kflag = 2 -> Found stable characteristic root, quartic solution + kflag = 3 -> Found stable characteristic root, quartic solution, + with Newton correction + kflag = 4 -> Found stability violation, normal matrix case + kflag = 5 -> Found stability violation, quartic solution + kflag = 6 -> Found stability violation, quartic solution, + with Newton correction + + kflag < 0 -> No stability limitation, + or could not compute limitation. + + kflag = -1 -> Min/max ratio of ssdat too small. + kflag = -2 -> For normal matrix case, vmax > vrrt2*vrrt2 + kflag = -3 -> For normal matrix case, The three ratios + are inconsistent. + kflag = -4 -> Small coefficient prevents elimination of quartics. + kflag = -5 -> R value from quartics not consistent. + kflag = -6 -> No corrected root passes test on qk values + kflag = -7 -> Trouble solving for sigsq. + kflag = -8 -> Trouble solving for B, or R via B. + kflag = -9 -> R via sigsq[k] disagrees with R from data. + +********************************************************************/ + +static int +CVsldet(CVodeMem cv_mem) +{ + integertype i, k, j, it, kmin, kflag = 0; + realtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4]; + realtype drr[4], rrc[4], sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; + realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; + realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; + realtype small_cvode, tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; + realtype rsa, rsb, rsc, rsd, rse, rd1a, rd1b, rd1c, rd1d; + realtype rd2a, rd2b, rd2c, rd3a, rd3b, cest1, corr1; + realtype ratp, ratm, qfac1, qfac2, bb, rrb; + + /* The following are cutoffs and tolerances used by this routine */ + + rrcut = 0.98; + vrrtol = 1.0e-4; + vrrt2 = 5.0e-4; + sqtol = 1.0e-3; + rrtol = 1.0e-2; + + rr = ZERO; + + /* Index k corresponds to the degree of the interpolating polynomial. */ + /* k = 1 -> q-1 */ + /* k = 2 -> q */ + /* k = 3 -> q+1 */ + + /* Index i is a backward-in-time index, i = 1 -> current time, */ + /* i = 2 -> previous step, etc */ + + /* get maxima, minima, and variances, and form quartic coefficients */ + + for (k = 1; k <= 3; k++) + { + smink = ssdat[1][k]; + smaxk = ZERO; + + for (i = 1; i <= 5; i++) + { + smink = MIN(smink, ssdat[i][k]); + smaxk = MAX(smaxk, ssdat[i][k]); + } + + if (smink < TINY * smaxk) + { + kflag = -1; + return (kflag); + } + smax[k] = smaxk; + ssmax[k] = smaxk * smaxk; + + sumrat = ZERO; + sumrsq = ZERO; + for (i = 1; i <= 4; i++) + { + rat[i][k] = ssdat[i][k] / ssdat[i + 1][k]; + sumrat = sumrat + rat[i][k]; + sumrsq = sumrsq + rat[i][k] * rat[i][k]; + } + rav[k] = FOURTH * sumrat; + vrat[k] = ABS(FOURTH * sumrsq - rav[k] * rav[k]); + + qc[5][k] = ssdat[1][k] * ssdat[3][k] - ssdat[2][k] * ssdat[2][k]; + qc[4][k] = ssdat[2][k] * ssdat[3][k] - ssdat[1][k] * ssdat[4][k]; + qc[3][k] = ZERO; + qc[2][k] = ssdat[2][k] * ssdat[5][k] - ssdat[3][k] * ssdat[4][k]; + qc[1][k] = ssdat[4][k] * ssdat[4][k] - ssdat[3][k] * ssdat[5][k]; + + for (i = 1; i <= 5; i++) + { + qco[i][k] = qc[i][k]; + } + } /* End of k loop */ + + /* Isolate normal or nearly-normal matrix case. Three quartic will + have common or nearly-common roots in this case. + Return a kflag = 1 if this procedure works. If three root + differ more than vrrt2, return error kflag = -3. */ + + vmin = MIN(vrat[1], MIN(vrat[2], vrat[3])); + vmax = MAX(vrat[1], MAX(vrat[2], vrat[3])); + + if (vmin < vrrtol * vrrtol) + { + if (vmax > vrrt2 * vrrt2) + { + kflag = -2; + return (kflag); + } + else + { + rr = (rav[1] + rav[2] + rav[3]) / THREE; + + drrmax = ZERO; + for (k = 1; k <= 3; k++) + { + adrr = ABS(rav[k] - rr); + drrmax = MAX(drrmax, adrr); + } + if (drrmax > vrrt2) + { + kflag = -3; + } + + kflag = 1; + + /* can compute charactistic root, drop to next section */ + + } + } + else + { + + /* use the quartics to get rr. */ + + if (ABS(qco[1][1]) < TINY * ssmax[1]) + { + small_cvode = qco[1][1]; + kflag = -4; + return (kflag); + } + + tem = qco[1][2] / qco[1][1]; + for (i = 2; i <= 5; i++) + { + qco[i][2] = qco[i][2] - tem * qco[i][1]; + } + + qco[1][2] = ZERO; + tem = qco[1][3] / qco[1][1]; + for (i = 2; i <= 5; i++) + { + qco[i][3] = qco[i][3] - tem * qco[i][1]; + } + qco[1][3] = ZERO; + + if (ABS(qco[2][2]) < TINY * ssmax[2]) + { + small_cvode = qco[2][2]; + kflag = -4; + return (kflag); + } + + tem = qco[2][3] / qco[2][2]; + for (i = 3; i <= 5; i++) + { + qco[i][3] = qco[i][3] - tem * qco[i][2]; + } + + if (ABS(qco[4][3]) < TINY * ssmax[3]) + { + small_cvode = qco[4][3]; + kflag = -4; + return (kflag); + } + + rr = -qco[5][3] / qco[4][3]; + + if (rr < TINY || rr > HUN) + { + kflag = -5; + return (kflag); + } + + for (k = 1; k <= 3; k++) + { + qkr[k] = + qc[5][k] + rr * (qc[4][k] + + rr * rr * (qc[2][k] + rr * qc[1][k])); + } + + sqmax = ZERO; + for (k = 1; k <= 3; k++) + { + saqk = ABS(qkr[k]) / ssmax[k]; + if (saqk > sqmax) + sqmax = saqk; + } + sqmin = sqmax; + if (sqmax < sqtol) + { + kflag = 2; + + /* can compute charactistic root, drop to "given rr,etc" */ + + } + else + { + + /* do Newton corrections to improve rr. */ + + for (it = 1; it <= 3; it++) + { + for (k = 1; k <= 3; k++) + { + qp = qc[4][k] + rr * rr * (THREE * qc[2][k] + + rr * FOUR * qc[1][k]); + drr[k] = ZERO; + if (ABS(qp) > TINY * ssmax[k]) + drr[k] = -qkr[k] / qp; + rrc[k] = rr + drr[k]; + } + + for (k = 1; k <= 3; k++) + { + s = rrc[k]; + sqmaxk = ZERO; + for (j = 1; j <= 3; j++) + { + qjk[j][k] = qc[5][j] + s * (qc[4][j] + + s * s * (qc[2][j] + + s * qc[1][j])); + saqj = ABS(qjk[j][k]) / ssmax[j]; + if (saqj > sqmaxk) + sqmaxk = saqj; + } + sqmx[k] = sqmaxk; + } + + sqmin = sqmx[1]; + kmin = 1; + for (k = 2; k <= 3; k++) + { + if (sqmx[k] < sqmin) + { + kmin = k; + sqmin = sqmx[k]; + } + } + rr = rrc[kmin]; + + if (sqmin < sqtol) + { + kflag = 3; + /* can compute charactistic root */ + /* break out of Newton correction loop and drop to "given rr,etc" */ + break; + } + else + { + for (j = 1; j <= 3; j++) + { + qkr[j] = qjk[j][kmin]; + } + } + } /* end of Newton correction loop */ + + if (sqmin > sqtol) + { + kflag = -6; + return (kflag); + } + } /* end of if (sqmax < sqtol) else */ + } /* end of if(vmin < vrrtol*vrrtol) else, quartics to get rr. */ + + /* given rr, find sigsq[k] and verify rr. */ + /* All positive kflag drop to this section */ + + for (k = 1; k <= 3; k++) + { + rsa = ssdat[1][k]; + rsb = ssdat[2][k] * rr; + rsc = ssdat[3][k] * rr * rr; + rsd = ssdat[4][k] * rr * rr * rr; + rse = ssdat[5][k] * rr * rr * rr * rr; + rd1a = rsa - rsb; + rd1b = rsb - rsc; + rd1c = rsc - rsd; + rd1d = rsd - rse; + rd2a = rd1a - rd1b; + rd2b = rd1b - rd1c; + rd2c = rd1c - rd1d; + rd3a = rd2a - rd2b; + rd3b = rd2b - rd2c; + + if (ABS(rd1b) < TINY * smax[k]) + { + kflag = -7; + return (kflag); + } + + cest1 = -rd3a / rd1b; + if (cest1 < TINY || cest1 > FOUR) + { + kflag = -7; + return (kflag); + } + corr1 = (rd2b / cest1) / (rr * rr); + sigsq[k] = ssdat[3][k] + corr1; + } + + if (sigsq[2] < TINY) + { + kflag = -8; + return (kflag); + } + + ratp = sigsq[3] / sigsq[2]; + ratm = sigsq[1] / sigsq[2]; + qfac1 = FOURTH * (q * q - ONE); + qfac2 = TWO / (q - ONE); + bb = ratp * ratm - ONE - qfac1 * ratp; + tem = ONE - qfac2 * bb; + + if (ABS(tem) < TINY) + { + kflag = -8; + return (kflag); + } + + rrb = ONE / tem; + + if (ABS(rrb - rr) > rrtol) + { + kflag = -9; + return (kflag); + } + + /* Check to see if rr is above cutoff rrcut */ + if (rr > rrcut) + { + if (kflag == 1) + kflag = 4; + if (kflag == 2) + kflag = 5; + if (kflag == 3) + kflag = 6; + } + + /* All positive kflag returned at this point */ + + return (kflag); + +} + + +/*******************************************************************/ +/********* END Private Helper Functions Implementation *************/ +/*******************************************************************/ + + +/***************************************************************/ +/************** END CVODE Implementation ***********************/ +/***************************************************************/ diff --git a/rename_cpp/cvode.h b/rename_cpp/cvode.h new file mode 100644 index 00000000..fdbe25ae --- /dev/null +++ b/rename_cpp/cvode.h @@ -0,0 +1,892 @@ +#ifndef _INC_CVODE_H +#define _INC_CVODE_H +/******************************************************************* + * * + * File : cvode.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban * + * and Dan Shumaker @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/cvode/LICENSE * + *-----------------------------------------------------------------* + * This is the interface file for the main CVODE integrator. * + * * + *******************************************************************/ +#ifndef _cvode_h +#define _cvode_h + + +#include +#include "sundialstypes.h" +#include "nvector.h" + +/****************************************************************** + * * + * CVODE is used to solve numerically the ordinary initial value * + * problem : * + * * + * y' = f(t,y), * + * y(t0) = y0, * + * * + * where t0, y0 in R^N, and f: R x R^N -> R^N are given. * + * * + ******************************************************************/ + + +/****************************************************************** + * * + * Enumerations for inputs to CVodeMalloc, CVReInit, and CVode. * + *----------------------------------------------------------------* + * Symbolic constants for the lmm, iter, and itol input * + * parameters to CVodeMalloc and CVReInit, as well as the input * + * parameter itask to CVode, are given below. * + * * + * lmm : The user of the CVODE package specifies whether to use * + * the ADAMS or BDF (backward differentiation formula) * + * linear multistep method. The BDF method is recommended * + * for stiff problems, and the ADAMS method is recommended * + * for nonstiff problems. * + * * + * iter : At each internal time step, a nonlinear equation must * + * be solved. The user can specify either FUNCTIONAL * + * iteration, which does not require linear algebra, or a * + * NEWTON iteration, which requires the solution of linear * + * systems. In the NEWTON case, the user also specifies a * + * CVODE linear solver. NEWTON is recommended in case of * + * stiff problems. * + * * + * itol : This parameter specifies the relative and absolute * + * tolerance types to be used. The SS tolerance type means * + * a scalar relative and absolute tolerance, while the SV * + * tolerance type means a scalar relative tolerance and a * + * vector absolute tolerance (a potentially different * + * absolute tolerance for each vector component). * + * * + * itask : The itask input parameter to CVode indicates the job * + * of the solver for the next user step. The NORMAL * + * itask is to have the solver take internal steps until * + * it has reached or just passed the user specified tout * + * parameter. The solver then interpolates in order to * + * return an approximate value of y(tout). The ONE_STEP * + * option tells the solver to just take one internal step * + * and return the solution at the point reached by that * + * step. * + * * + ******************************************************************/ + + enum + { ADAMS, BDF }; /* lmm */ + + enum + { FUNCTIONAL, NEWTON }; /* iter */ + + enum + { SS, SV }; /* itol */ + + enum + { NORMAL, ONE_STEP }; /* itask */ + + +/****************************************************************** + * * + * Type : RhsFn * + *----------------------------------------------------------------* + * The f function which defines the right hand side of the ODE * + * system y' = f(t,y) must have type RhsFn. * + * f takes as input the problem size N, the independent variable * + * value t, and the dependent variable vector y. It stores the * + * result of f(t,y) in the vector ydot. The y and ydot arguments * + * are of type N_Vector. * + * (Allocation of memory for ydot is handled within CVODE.) * + * The f_data parameter is the same as the f_data * + * parameter passed by the user to the CVodeMalloc routine. This * + * user-supplied pointer is passed to the user's f function * + * every time it is called. * + * A RhsFn f does not have a return value. * + * * + ******************************************************************/ + + typedef void (*RhsFn) (integertype N, realtype t, N_Vector y, + N_Vector ydot, void *f_data); + + +/****************************************************************** + * * + * Function : CVodeMalloc * + *----------------------------------------------------------------* + * CVodeMalloc allocates and initializes memory for a problem to * + * to be solved by CVODE. * + * * + * N is the number of equations in the ODE system. * + * * + * f is the right hand side function in y' = f(t,y). * + * * + * t0 is the initial value of t. * + * * + * y0 is the initial condition vector y(t0). * + * * + * lmm is the type of linear multistep method to be used. * + * The legal values are ADAMS and BDF (see previous * + * description). * + * * + * iter is the type of iteration used to solve the nonlinear * + * system that arises during each internal time step. * + * The legal values are FUNCTIONAL and NEWTON. * + * * + * itol is the type of tolerances to be used. * + * The legal values are: * + * SS (scalar relative and absolute tolerances), * + * SV (scalar relative tolerance and vector * + * absolute tolerance). * + * * + * reltol is a pointer to the relative tolerance scalar. * + * * + * abstol is a pointer to the absolute tolerance scalar or * + * an N_Vector of absolute tolerances. * + * * + * The parameters itol, reltol, and abstol define a vector of * + * error weights, ewt, with components * + * ewt[i] = 1/(reltol*abs(y[i]) + abstol) (if itol = SS), or * + * ewt[i] = 1/(reltol*abs(y[i]) + abstol[i]) (if itol = SV). * + * This vector is used in all error and convergence tests, which * + * use a weighted RMS norm on all error-like vectors v: * + * WRMSnorm(v) = sqrt( (1/N) sum(i=1..N) (v[i]*ewt[i])^2 ). * + * * + * f_data is a pointer to user data that will be passed to the * + * user's f function every time f is called. * + * * + * errfp is the file pointer for an error file where all CVODE * + * warning and error messages will be written. This * + * parameter can be stdout (standard output), stderr * + * (standard error), a file pointer (corresponding to * + * a user error file opened for writing) returned by * + * fopen, or NULL. If the user passes NULL, then all * + * messages will be written to standard output. * + * * + * optIn is a flag indicating whether there are any optional * + * inputs from the user in the arrays iopt and ropt. * + * Pass FALSE to indicate no optional inputs and TRUE * + * to indicate that optional inputs are present. * + * * + * iopt is the user-allocated array (of size OPT_SIZE given * + * later) that will hold optional integer inputs and * + * outputs. The user can pass NULL if he/she does not * + * wish to use optional integer inputs or outputs. * + * If optIn is TRUE, the user should preset to 0 those * + * locations for which default values are to be used. * + * * + * ropt is the user-allocated array (of size OPT_SIZE given * + * later) that will hold optional real inputs and * + * outputs. The user can pass NULL if he/she does not * + * wish to use optional real inputs or outputs. * + * If optIn is TRUE, the user should preset to 0.0 the * + * locations for which default values are to be used. * + * * + * machEnv is a pointer to machine environment-specific * + * information. * + * * + * Note: The tolerance values may be changed in between calls to * + * CVode for the same problem. These values refer to * + * (*reltol) and either (*abstol), for a scalar absolute * + * tolerance, or the components of abstol, for a vector * + * absolute tolerance. * + * * + * If successful, CVodeMalloc returns a pointer to initialized * + * problem memory. This pointer should be passed to CVode. If * + * an initialization error occurs, CVodeMalloc prints an error * + * message to the file specified by errfp and returns NULL. * + * * + ******************************************************************/ + + + void *CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, realtype * reltol, + void *abstol, void *f_data, FILE * errfp, + booleantype optIn, long int iopt[], realtype ropt[], + M_Env machEnv); + + +/****************************************************************** + * * + * Function : CVReInit * + *----------------------------------------------------------------* + * CVReInit re-initializes CVode for the solution of a problem, * + * where a prior call to CVodeMalloc has been made with the same * + * problem size N. CVReInit performs the same input checking * + * and initializations that CVodeMalloc does (except for N). * + * But it does no memory allocation, assuming that the existing * + * internal memory is sufficient for the new problem. * + * * + * The use of CVReInit requires that the maximum method order, * + * maxord, is no larger for the new problem than for the problem * + * specified in the last call to CVodeMalloc. This condition is * + * automatically fulfilled if the multistep method parameter lmm * + * is unchanged (or changed from ADAMS to BDF) and the default * + * value for maxord is specified. * + * * + * If iter = NEWTON, then following the call to CVReInit, a call * + * to the linear solver specification routine is necessary if a * + * different linear solver is chosen, but may not be otherwise. * + * If the same linear solver is chosen, and there are no changes * + * in the input parameters to the specification routine, then no * + * call to that routine is needed. * + * If there are changes in parameters, but they do not increase * + * the linear solver memory size, then a call to the corresponding* + * CVReInit routine must made to communicate the new * + * parameters; in that case the linear solver memory is reused. * + * If the parameter changes do increase the linear solver memory * + * size, then the main linear solver specification routine must be* + * called. See the linear solver documentation for full details. * + * * + * The first argument to CVReInit is: * + * * + * cvode_mem = pointer to CVODE memory returned by CVodeMalloc. * + * * + * All the remaining arguments to CVReInit have names and * + * meanings identical to those of CVodeMalloc. Note that the * + * problem size N is not passed as an argument to CVReInit, * + * as that is assumed to be unchanged since the CVodeMalloc call. * + * * + * The return value of CVReInit is equal to SUCCESS = 0 if there * + * were no errors; otherwise it is a negative int equal to: * + * CVREI_NO_MEM indicating cvode_mem was NULL, or * + * CVREI_ILL_INPUT indicating an input argument was illegal * + * (including an attempt to increase maxord). * + * In case of an error return, an error message is also printed. * + * * + * Note: the reported workspace sizes iopt[LENRW] and iopt[LENIW] * + * are left unchanged from the values computed by CVodeMalloc, and* + * so may be larger than would be computed for the new problem. * + ******************************************************************/ + + int CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, + int lmm, int iter, int itol, realtype * reltol, + void *abstol, void *f_data, FILE * errfp, + booleantype optIn, long int iopt[], + realtype ropt[], M_Env machEnv); + + +/* CVReInit return values: */ + +/* SUCCESS = 0 (Defined under CVode return values, but listed + here also for completeness) */ + enum + { CVREI_NO_MEM = -1, CVREI_ILL_INPUT = -2 }; + + +/****************************************************************** + * * + * Function : CVode * + *----------------------------------------------------------------* + * CVode integrates the ODE over an interval in t. * + * If itask is NORMAL, then the solver integrates from its * + * current internal t value to a point at or beyond tout, then * + * interpolates to t = tout and returns y(tout) in the user- * + * allocated vector yout. If itask is ONE_STEP, then the solver * + * takes one internal time step and returns in yout the value of * + * y at the new internal time. In this case, tout is used only * + * during the first call to CVode to determine the direction of * + * integration and the rough scale of the problem. In either * + * case, the time reached by the solver is placed in (*t). The * + * user is responsible for allocating the memory for this value. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * tout is the next time at which a computed solution is desired * + * * + * yout is the computed solution vector. In NORMAL mode with no * + * errors, yout=y(tout). * + * * + * t is a pointer to a real location. CVode sets (*t) to the * + * time reached by the solver and returns yout=y(*t). * + * * + * itask is either NORMAL or ONE_STEP mode. These two modes have * + * been described above. * + * * + * The return values for CVode are defined later in this file. * + * Here is a brief description of each return value: * + * * + * SUCCESS : CVode succeeded. * + * * + * CVODE_NO_MEM : The cvode_mem argument was NULL. * + * * + * ILL_INPUT : One of the inputs to CVode is illegal. This * + * includes the situation when a component of the * + * error weight vectors becomes < 0 during * + * internal time-stepping. The ILL_INPUT flag * + * will also be returned if the linear solver * + * routine CV--- (called by the user after * + * calling CVodeMalloc) failed to set one of the * + * linear solver-related fields in cvode_mem or * + * if the linear solver's init routine failed. In * + * any case, the user should see the printed * + * error message for more details. * + * * + * TOO_MUCH_WORK : The solver took mxstep internal steps but * + * could not reach tout. The default value for * + * mxstep is MXSTEP_DEFAULT = 500. * + * * + * TOO_MUCH_ACC : The solver could not satisfy the accuracy * + * demanded by the user for some internal step. * + * * + * ERR_FAILURE : Error test failures occurred too many times * + * (= MXNEF = 7) during one internal time step or * + * occurred with |h| = hmin. * + * * + * CONV_FAILURE : Convergence test failures occurred too many * + * times (= MXNCF = 10) during one internal time * + * step or occurred with |h| = hmin. * + * * + * SETUP_FAILURE : The linear solver's setup routine failed in an * + * unrecoverable manner. * + * * + * SOLVE_FAILURE : The linear solver's solve routine failed in an * + * unrecoverable manner. * + * * + ******************************************************************/ + + + int CVode(void *cvode_mem, realtype tout, N_Vector yout, + realtype * t, int itask); + + +/* CVode return values */ + + enum + { SUCCESS = 0, CVODE_NO_MEM = -1, ILL_INPUT = -2, TOO_MUCH_WORK = -3, + TOO_MUCH_ACC = -4, ERR_FAILURE = -5, CONV_FAILURE = -6, + SETUP_FAILURE = -7, SOLVE_FAILURE = -8 + }; + + +/****************************************************************** + * * + * Function : CVodeDky * + *----------------------------------------------------------------* + * CVodeDky computes the kth derivative of the y function at * + * time t, where tn-hu <= t <= tn, tn denotes the current * + * internal time reached, and hu is the last internal step size * + * successfully used by the solver. The user may request * + * k=0, 1, ..., qu, where qu is the current order. The * + * derivative vector is returned in dky. This vector must be * + * allocated by the caller. It is only legal to call this * + * function after a successful return from CVode. * + * * + * cvode_mem is the pointer to CVODE memory returned by * + * CVodeMalloc. * + * * + * t is the time at which the kth derivative of y is evaluated. * + * The legal range for t is [tn-hu,tn] as described above. * + * * + * k is the order of the derivative of y to be computed. The * + * legal range for k is [0,qu] as described above. * + * * + * dky is the output derivative vector [(D_k)y](t). * + * * + * The return values for CVodeDky are defined later in this file. * + * Here is a brief description of each return value: * + * * + * OKAY : CVodeDky succeeded. * + * * + * BAD_K : k is not in the range 0, 1, ..., qu. * + * * + * BAD_T : t is not in the interval [tn-hu,tn]. * + * * + * BAD_DKY : The dky argument was NULL. * + * * + * DKY_NO_MEM : The cvode_mem argument was NULL. * + * * + ******************************************************************/ + + + int CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky); + + +/* CVodeDky return values */ + + enum + { OKAY = 0, BAD_K = -1, BAD_T = -2, BAD_DKY = -3, DKY_NO_MEM = -4 }; + + +/****************************************************************** + * * + * Function : CVodeFree * + *----------------------------------------------------------------* + * CVodeFree frees the problem memory cvode_mem allocated by * + * CVodeMalloc. Its only argument is the pointer cvode_mem * + * returned by CVodeMalloc. * + * * + ******************************************************************/ + + void CVodeFree(void *cvode_mem); + + +/****************************************************************** + * * + * Optional Inputs and Outputs * + *----------------------------------------------------------------* + * The user should declare two arrays for optional input and * + * output, an iopt array for optional integer input and output * + * and an ropt array for optional real input and output. The * + * size of both these arrays should be OPT_SIZE. * + * So the user's declaration should look like: * + * * + * long int iopt[OPT_SIZE]; * + * realtype ropt[OPT_SIZE]; * + * * + * The enumerations below the OPT_SIZE definition * + * are indices into the iopt and ropt arrays. Here is a brief * + * description of the contents of these positions: * + * * + * iopt[MAXORD] : maximum lmm order to be used by the solver. * + * Optional input. (Default = 12 for ADAMS, 5 for * + * BDF). * + * * + * iopt[MXSTEP] : maximum number of internal steps to be taken by * + * the solver in its attempt to reach tout. * + * Optional input. (Default = 500). * + * * + * iopt[MXHNIL] : maximum number of warning messages issued by the* + * solver that t + h = t on the next internal step.* + * A value of -1 means no such messages are issued.* + * Optional input. (Default = 10). * + * * + * iopt[NST] : cumulative number of internal steps taken by * + * the solver (total so far). Optional output. * + * * + * iopt[NFE] : number of calls to the user's f function. * + * Optional output. * + * * + * iopt[NSETUPS] : number of calls made to the linear solver's * + * setup routine. Optional output. * + * * + * iopt[NNI] : number of NEWTON iterations performed. * + * Optional output. * + * * + * iopt[NCFN] : number of nonlinear convergence failures * + * that have occurred. Optional output. * + * * + * iopt[NETF] : number of local error test failures that * + * have occurred. Optional output. * + * * + * iopt[QU] : order used during the last internal step. * + * Optional output. * + * * + * iopt[QCUR] : order to be used on the next internal step. * + * Optional output. * + * * + * iopt[LENRW] : size of required CVODE internal real work * + * space, in realtype words. Optional output. * + * * + * iopt[LENIW] : size of required CVODE internal integer work * + * space, in integertype words. Optional output. * + * * + * iopt[SLDET] : Flag to turn on/off stability limit detection * + * (1 = on, 0 = off). When BDF is used and order * + * is 3 or greater, CVsldet is call to detect * + * stability limit. If limit is detected, the * + * order is reduced. Optional input. * + * * + * iopt[NOR] : Number of order reductions due to * + * stability limit detection. * + * Optional output. * + * * + * ropt[H0] : initial step size. Optional input. * + * * + * ropt[HMAX] : maximum absolute value of step size allowed. * + * Optional input. (Default is infinity). * + * Note: If optIn = TRUE, the value of ropt[HMAX] * + * is examined on every call to CVode, and so can * + * be changed between calls. * + * * + * ropt[HMIN] : minimum absolute value of step size allowed. * + * Optional input. (Default is 0.0). * + * * + * ropt[HU] : step size for the last internal step. * + * Optional output. * + * * + * ropt[HCUR] : step size to be attempted on the next internal * + * step. Optional output. * + * * + * ropt[TCUR] : current internal time reached by the solver. * + * Optional output. * + * * + * ropt[TOLSF] : a suggested factor by which the user's * + * tolerances should be scaled when too much * + * accuracy has been requested for some internal * + * step. Optional output. * + * * + ******************************************************************/ + +/* iopt, ropt array sizes */ + +#define OPT_SIZE 40 + + +/* iopt and ropt offsets * + * The constants CVODE_IOPT_SIZE and CVODE_ROPT_SIZE are equal to * + * the number of integer and real optional inputs and outputs * + * actually accessed in cvode.c. The locations beyond these * + * values are used by the linear solvers. */ + +#define CVODE_IOPT_SIZE 15 +#define CVODE_ROPT_SIZE 7 + +/* iopt indices */ + enum + { MAXORD, MXSTEP, MXHNIL, + NST, NFE, NSETUPS, NNI, NCFN, NETF, QU, QCUR, + LENRW, LENIW, SLDET, NOR + }; + +/* ropt indices */ + + enum + { H0, HMAX, HMIN, + HU, HCUR, TCUR, TOLSF + }; + + +/* Basic CVODE constants */ + +#define ADAMS_Q_MAX 12 /* max value of q for lmm == ADAMS */ +#define BDF_Q_MAX 5 /* max value of q for lmm == BDF */ +#define Q_MAX ADAMS_Q_MAX /* max value of q for either lmm */ +#define L_MAX (Q_MAX+1) /* max value of L for either lmm */ +#define NUM_TESTS 5 /* number of error test quantities */ + + +/****************************************************************** + * * + * Types : struct CVodeMemRec, CVodeMem * + *----------------------------------------------------------------* + * The type CVodeMem is type pointer to struct CVodeMemRec. This * + * structure contains fields to keep track of problem state. * + * * + ******************************************************************/ + + typedef struct CVodeMemRec + { + + realtype cv_uround; /* machine unit roundoff */ + + /* Problem Specification Data */ + + integertype cv_N; /* ODE system size */ + RhsFn cv_f; /* y' = f(t,y(t)) */ + void *cv_f_data; /* user pointer passed to f */ + int cv_lmm; /* lmm = ADAMS or BDF */ + int cv_iter; /* iter = FUNCTIONAL or NEWTON */ + int cv_itol; /* itol = SS or SV */ + realtype *cv_reltol; /* ptr to relative tolerance */ + void *cv_abstol; /* ptr to absolute tolerance */ + + /* Nordsieck History Array */ + + N_Vector cv_zn[L_MAX]; /* Nordsieck array, of size N x (q+1). */ + /* zn[j] is a vector of length N (j=0,...,q) */ + /* zn[j] = [1/factorial(j)] * h^j * (jth */ + /* derivative of the interpolating polynomial */ + + /* Vectors of length N */ + + N_Vector cv_ewt; /* error weight vector */ + N_Vector cv_y; /* y is used as temporary storage by the solver */ + /* The memory is provided by the user to CVode */ + /* where the vector is named yout. */ + N_Vector cv_acor; /* In the context of the solution of the */ + /* nonlinear equation, acor = y_n(m) - y_n(0). */ + /* On return, this vector is scaled to give */ + /* the estimated local error in y. */ + N_Vector cv_tempv; /* temporary storage vector */ + N_Vector cv_ftemp; /* temporary storage vector */ + + /* Step Data */ + + int cv_q; /* current order */ + int cv_qprime; /* order to be used on the next step */ + /* = q-1, q, or q+1 */ + int cv_qwait; /* number of internal steps to wait before */ + /* considering a change in q */ + int cv_L; /* L = q + 1 */ + + realtype cv_h; /* current step size */ + realtype cv_hprime; /* step size to be used on the next step */ + realtype cv_eta; /* eta = hprime / h */ + realtype cv_hscale; /* value of h used in zn */ + realtype cv_tn; /* current internal value of t */ + + realtype cv_tau[L_MAX + 1]; /* array of previous q+1 successful step */ + /* sizes indexed from 1 to q+1 */ + realtype cv_tq[NUM_TESTS + 1]; /* array of test quantities indexed from */ + /* 1 to NUM_TESTS(=5) */ + realtype cv_l[L_MAX]; /* coefficients of l(x) (degree q poly) */ + + realtype cv_rl1; /* 1 / l[1] */ + realtype cv_gamma; /* gamma = h * rl1 */ + realtype cv_gammap; /* gamma at the last setup call */ + realtype cv_gamrat; /* gamma / gammap */ + + realtype cv_crate; /* estimated corrector convergence rate */ + realtype cv_acnrm; /* | acor | wrms */ + int cv_mnewt; /* Newton iteration counter */ + + /* Limits */ + + int cv_qmax; /* q <= qmax */ + int cv_mxstep; /* maximum number of internal steps for one user call */ + int cv_maxcor; /* maximum number of corrector iterations for the */ + /* solution of the nonlinear equation */ + int cv_mxhnil; /* maximum number of warning messages issued to the */ + /* user that t + h == t for the next internal step */ + + realtype cv_hmin; /* |h| >= hmin */ + realtype cv_hmax_inv; /* |h| <= 1/hmax_inv */ + realtype cv_etamax; /* eta <= etamax */ + + /* Counters */ + + long int cv_nst; /* number of internal steps taken */ + long int cv_nfe; /* number of f calls */ + long int cv_ncfn; /* number of corrector convergence failures */ + long int cv_netf; /* number of error test failures */ + long int cv_nni; /* number of Newton iterations performed */ + long int cv_nsetups; /* number of setup calls */ + int cv_nhnil; /* number of messages issued to the user that */ + /* t + h == t for the next iternal step */ + long int cv_lrw; /* number of realtype words in CVODE work vectors */ + long int cv_liw; /* no. of integertype words in CVODE work vectors */ + long int cv_nscon; /* counter for STALD method */ + + realtype cv_etaqm1; /* ratio of new to old h for order q-1 */ + realtype cv_etaq; /* ratio of new to old h for order q */ + realtype cv_etaqp1; /* ratio of new to old h for order q+1 */ + realtype cv_ssdat[6][4]; /* scaled data array for STALD */ + + /* Linear Solver Data */ + + /* Linear Solver functions to be called */ + + int (*cv_linit) (struct CVodeMemRec * cv_mem); + + int (*cv_lsetup) (struct CVodeMemRec * cv_mem, int convfail, + N_Vector ypred, N_Vector fpred, + booleantype * jcurPtr, N_Vector vtemp1, + N_Vector vtemp2, N_Vector vtemp3); + + int (*cv_lsolve) (struct CVodeMemRec * cv_mem, N_Vector b, + N_Vector ycur, N_Vector fcur); + + void (*cv_lfree) (struct CVodeMemRec * cv_mem); + + /* Linear Solver specific memory */ + + void *cv_lmem; + + /* Saved Values */ + + int cv_qu; /* last successful q value used */ + long int cv_nstlp; /* step number of last setup call */ + realtype cv_hu; /* last successful h value used */ + realtype cv_saved_tq5; /* saved value of tq[5] */ + booleantype cv_jcur; /* Is the Jacobian info used by */ + /* linear solver current? */ + realtype cv_tolsf; /* tolerance scale factor */ + booleantype cv_setupNonNull; /* Does setup do something? */ + + /* Arrays for Optional Input and Optional Output */ + + booleantype cv_optIn; /* boolean input optIn */ + long int *cv_iopt; /* long int optional input, output */ + realtype *cv_ropt; /* real optional input, output */ + + /* Error File */ + + FILE *cv_errfp; /* CVODE error messages are sent to errfp */ + + /* Pointer to Machine Environment-Specific Information */ + + M_Env cv_machenv; + + /* Stability Limit Detection control flag */ + + booleantype cv_sldeton; /* Is Stability Limit Detection on */ + + } *CVodeMem; + + +/****************************************************************** + * * + * Communication between user and a CVODE Linear Solver * + *----------------------------------------------------------------* + * Return values of the linear solver specification routine. * + * The values of these are given in the enum statement below. * + * SUCCESS : The routine was successful. * + * * + * LMEM_FAIL : A memory allocation failed. * + * * + * LIN_ILL_INPUT: Some input was illegal (see message). * + * * + ******************************************************************/ + +/* SUCCESS = 0 (Defined under CVode return values, but listed + here also for completeness) */ + enum + { LMEM_FAIL = -1, LIN_ILL_INPUT = -2 }; + + +/****************************************************************** + * * + * Communication between cvode.c and a CVODE Linear Solver * + *----------------------------------------------------------------* + * (1) cv_linit return values * + * * + * LINIT_OK : The cv_linit routine succeeded. * + * * + * LINIT_ERR : The cv_linit routine failed. Each linear solver * + * init routine should print an appropriate error * + * message to (cv_mem->errfp). * + * * + * (2) convfail (input to cv_lsetup) * + * * + * NO_FAILURES : Either this is the first cv_setup call for this * + * step, or the local error test failed on the * + * previous attempt at this step (but the Newton * + * iteration converged). * + * * + * FAIL_BAD_J : This value is passed to cv_lsetup if * + * * + * (1) The previous Newton corrector iteration * + * did not converge and the linear solver's * + * setup routine indicated that its Jacobian- * + * related data is not current. * + * or * + * (2) During the previous Newton corrector * + * iteration, the linear solver's solve routine * + * failed in a recoverable manner and the * + * linear solver's setup routine indicated that * + * its Jacobian-related data is not current. * + * * + * FAIL_OTHER : During the current internal step try, the * + * previous Newton iteration failed to converge * + * even though the linear solver was using current * + * Jacobian-related data. * + * * + * (3) Parameter documentation, as well as a brief description * + * of purpose, for each CVODE linear solver routine to be * + * called in cvode.c is given below the constant declarations * + * that follow. * + * * + ******************************************************************/ + +/* cv_linit return values */ + +#define LINIT_OK 0 +#define LINIT_ERR -1 + +/* Constants for convfail (input to cv_lsetup) */ + +#define NO_FAILURES 0 +#define FAIL_BAD_J 1 +#define FAIL_OTHER 2 + + +/******************************************************************* + * * + * int (*cv_linit)(CVodeMem cv_mem); * + *-----------------------------------------------------------------* + * The purpose of cv_linit is to complete initializations for * + * specific linear solver, such as counters and statistics. * + * An LInitFn should return LINIT_OK (= 0) if it has successfully * + * initialized the CVODE linear solver and LINIT_ERR (= -1) * + * otherwise. These constants are defined above. If an error does * + * occur, an appropriate message should be sent to (cv_mem->errfp).* + * * + *******************************************************************/ + +/******************************************************************* + * * + * int (*cv_lsetup)(CVodeMem cv_mem, int convfail, N_Vector ypred, * + * N_Vector fpred, booleantype *jcurPtr, * + * N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); * + *-----------------------------------------------------------------* + * The job of cv_lsetup is to prepare the linear solver for * + * subsequent calls to cv_lsolve. It may re-compute Jacobian- * + * related data is it deems necessary. Its parameters are as * + * follows: * + * * + * cv_mem - problem memory pointer of type CVodeMem. See the big * + * typedef earlier in this file. * + * * + * convfail - a flag to indicate any problem that occurred during * + * the solution of the nonlinear equation on the * + * current time step for which the linear solver is * + * being used. This flag can be used to help decide * + * whether the Jacobian data kept by a CVODE linear * + * solver needs to be updated or not. * + * Its possible values have been documented above. * + * * + * ypred - the predicted y vector for the current CVODE internal * + * step. * + * * + * fpred - f(tn, ypred). * + * * + * jcurPtr - a pointer to a boolean to be filled in by cv_lsetup. * + * The function should set *jcurPtr=TRUE if its Jacobian * + * data is current after the call and should set * + * *jcurPtr=FALSE if its Jacobian data is not current. * + * Note: If cv_lsetup calls for re-evaluation of * + * Jacobian data (based on convfail and CVODE state * + * data), it should return *jcurPtr=TRUE unconditionally;* + * otherwise an infinite loop can result. * + * * + * vtemp1 - temporary N_Vector provided for use by cv_lsetup. * + * * + * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * + * * + * vtemp3 - temporary N_Vector provided for use by cv_lsetup. * + * * + * The cv_lsetup routine should return 0 if successful, * + * a positive value for a recoverable error, and a negative value * + * for an unrecoverable error. * + * * + *******************************************************************/ + +/******************************************************************* + * * + * int (*cv_lsolve)(CVodeMem cv_mem, N_Vector b, N_Vector ycur, * + * N_Vector fcur); * + *-----------------------------------------------------------------* + * cv_lsolve must solve the linear equation P x = b, where * + * P is some approximation to (I - gamma J), J = (df/dy)(tn,ycur) * + * and the RHS vector b is input. The N-vector ycur contains * + * the solver's current approximation to y(tn) and the vector * + * fcur contains the N-vector f(tn,ycur). The solution is to be * + * returned in the vector b. cv_lsolve returns a positive value * + * for a recoverable error and a negative value for an * + * unrecoverable error. Success is indicated by a 0 return value. * + * * + *******************************************************************/ + +/******************************************************************* + * * + * void (*cv_lfree)(CVodeMem cv_mem); * + *-----------------------------------------------------------------* + * cv_lfree should free up any memory allocated by the linear * + * solver. This routine is called once a problem has been * + * completed and the linear solver is no longer needed. * + * * + *******************************************************************/ + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ +#endif /* _INC_CVODE_H */ diff --git a/rename_cpp/dense.cpp b/rename_cpp/dense.cpp new file mode 100644 index 00000000..35b536e1 --- /dev/null +++ b/rename_cpp/dense.cpp @@ -0,0 +1,124 @@ +/******************************************************************* + * * + * File : dense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package. * + * * + *******************************************************************/ + +#include +#include +#include "sundialstypes.h" +#include "sundialsmath.h" +#include "dense.h" +#include "smalldense.h" + +/* WARNING don't include any headers below here */ + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) + + +/* Implementation */ + + +DenseMat +DenseAllocMat(integertype N) +{ + DenseMat A; + + if (N <= 0) + return (NULL); + + A = (DenseMat) malloc(sizeof *A); + if (A == NULL) + return (NULL); + + A->data = denalloc(N); + if (A->data == NULL) + { + free(A); + return (NULL); + } + + A->size = N; + + return (A); +} + + +integertype * +DenseAllocPiv(integertype N) +{ + if (N <= 0) + return (NULL); + + return ((integertype *) malloc(N * sizeof(integertype))); +} + + +integertype +DenseFactor(DenseMat A, integertype * p) +{ + return (gefa(A->data, A->size, p)); +} + + +void +DenseBacksolve(DenseMat A, integertype * p, realtype * b) +{ + gesl(A->data, A->size, p, b); +} + + +void +DenseZero(DenseMat A) +{ + denzero(A->data, A->size); +} + +void +DenseCopy(DenseMat A, DenseMat B) +{ + dencopy(A->data, B->data, A->size); +} + +void +DenseScale(realtype c, DenseMat A) +{ + denscale(c, A->data, A->size); +} + +void +DenseAddI(DenseMat A) +{ + denaddI(A->data, A->size); +} + +void +DenseFreeMat(DenseMat A) +{ + denfree(A->data); + free(A); +} + +void +DenseFreePiv(integertype * p) +{ + free(p); +} + +void +DensePrint(DenseMat A) +{ + denprint(A->data, A->size); +} diff --git a/rename_cpp/dense.h b/rename_cpp/dense.h new file mode 100644 index 00000000..ac8c69bf --- /dev/null +++ b/rename_cpp/dense.h @@ -0,0 +1,297 @@ +#ifndef _INC_DENSE_H +#define _INC_DENSE_H +/******************************************************************* + * * + * File : dense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic DENSE linear solver * + * package. The routines listed in this file all use type * + * DenseMat, defined below, for matrices. These routines in turn * + * call routines in the smalldense.h/smalldense.c module, which * + * use the type realtype** for matrices. This separation allows * + * for possible modifications in which matrices of type DenseMat * + * may not be stored contiguously, while small matrices can still * + * be treated with the routines in smalldense. * + * * + * Routines that work with the type DenseMat begin with "Dense". * + * The DenseAllocMat function allocates a dense matrix for use in * + * the other DenseMat routines listed in this file. Matrix * + * storage details are given in the documentation for the type * + * DenseMat. The DenseAllocPiv function allocates memory for * + * pivot information. The storage allocated by DenseAllocMat and * + * DenseAllocPiv is deallocated by the routines DenseFreeMat and * + * DenseFreePiv, respectively. The DenseFactor and DenseBacksolve * + * routines perform the actual solution of a dense linear system. * + * * + * Routines that work with realtype** begin with "den" (except for * + * the factor and solve routines which are called gefa and gesl, * + * respectively). The underlying matrix storage is described in * + * the documentation for denalloc in smalldense.h * + * * + *******************************************************************/ +#ifndef _dense_h +#define _dense_h + + +#include "sundialstypes.h" +#include "smalldense.h" + + +/****************************************************************** + * * + * Type: DenseMat * + *----------------------------------------------------------------* + * The type DenseMat is defined to be a pointer to a structure * + * with a size and a data field. The size field indicates the * + * number of columns (== number of rows) of a dense matrix, while * + * the data field is a two dimensional array used for component * + * storage. The elements of a dense matrix are stored columnwise * + * (i.e columns are stored one on top of the other in memory). If * + * A is of type DenseMat, then the (i,j)th element of A (with * + * 0 <= i,j <= size-1) is given by the expression (A->data)[j][i] * + * or by the expression (A->data)[0][j*n+i]. The macros below * + * allow a user to access efficiently individual matrix * + * elements without writing out explicit data structure * + * references and without knowing too much about the underlying * + * element storage. The only storage assumption needed is that * + * elements are stored columnwise and that a pointer to the jth * + * column of elements can be obtained via the DENSE_COL macro. * + * Users should use these macros whenever possible. * + * * + ******************************************************************/ + + typedef struct _DenseMat + { + integertype size; + realtype **data; + } *DenseMat; + + +/* DenseMat accessor macros */ + + +/****************************************************************** + * * + * Macro : DENSE_ELEM * + * Usage : DENSE_ELEM(A,i,j) = a_ij; OR * + * a_ij = DENSE_ELEM(A,i,j); * + *----------------------------------------------------------------* + * DENSE_ELEM(A,i,j) references the (i,j)th element of the N by N * + * DenseMat A, 0 <= i,j <= N-1. * + * * + ******************************************************************/ + +#define DENSE_ELEM(A,i,j) ((A->data)[j][i]) + + +/****************************************************************** + * * + * Macro : DENSE_COL * + * Usage : col_j = DENSE_COL(A,j); * + *----------------------------------------------------------------* + * DENSE_COL(A,j) references the jth column of the N by N * + * DenseMat A, 0 <= j <= N-1. The type of the expression * + * DENSE_COL(A,j) is realtype *. After the assignment in the usage* + * above, col_j may be treated as an array indexed from 0 to N-1. * + * The (i,j)th element of A is referenced by col_j[i]. * + * * + ******************************************************************/ + +#define DENSE_COL(A,j) ((A->data)[j]) + + +/* Functions that use the DenseMat representation for a dense matrix */ + + +/****************************************************************** + * * + * Function : DenseAllocMat * + * Usage : A = DenseAllocMat(N); * + * if (A == NULL) ... memory request failed * + *----------------------------------------------------------------* + * DenseAllocMat allocates memory for an N by N dense matrix and * + * returns the storage allocated (type DenseMat). DenseAllocMat * + * returns NULL if the request for matrix storage cannot be * + * satisfied. See the above documentation for the type DenseMat * + * for matrix storage details. * + * * + ******************************************************************/ + + DenseMat DenseAllocMat(integertype N); + + +/****************************************************************** + * * + * Function : DenseAllocPiv * + * Usage : p = DenseAllocPiv(N); * + * if (p == NULL) ... memory request failed * + *----------------------------------------------------------------* + * DenseAllocPiv allocates memory for pivot information to be * + * filled in by the DenseFactor routine during the factorization * + * of an N by N dense matrix. The underlying type for pivot * + * information is an array of N integers and this routine returns * + * the pointer to the memory it allocates. If the request for * + * pivot storage cannot be satisfied, DenseAllocPiv returns NULL. * + * * + ******************************************************************/ + + integertype *DenseAllocPiv(integertype N); + + +/****************************************************************** + * * + * Function : DenseFactor * + * Usage : ier = DenseFactor(A, p); * + * if (ier != 0) ... A is singular * + *----------------------------------------------------------------* + * DenseFactor performs the LU factorization of the N by N dense * + * matrix A. This is done using standard Gaussian elimination * + * with partial pivoting. * + * * + * A successful LU factorization leaves the matrix A and the * + * pivot array p with the following information: * + * * + * (1) p[k] contains the row number of the pivot element chosen * + * at the beginning of elimination step k, k=0, 1, ..., N-1. * + * * + * (2) If the unique LU factorization of A is given by PA = LU, * + * where P is a permutation matrix, L is a lower triangular * + * matrix with all 1's on the diagonal, and U is an upper * + * triangular matrix, then the upper triangular part of A * + * (including its diagonal) contains U and the strictly lower * + * triangular part of A contains the multipliers, I-L. * + * * + * DenseFactor returns 0 if successful. Otherwise it encountered * + * a zero diagonal element during the factorization. In this case * + * it returns the column index (numbered from one) at which * + * it encountered the zero. * + * * + ******************************************************************/ + + integertype DenseFactor(DenseMat A, integertype * p); + + +/****************************************************************** + * * + * Function : DenseBacksolve * + * Usage : DenseBacksolve(A, p, b); * + *----------------------------------------------------------------* + * DenseBacksolve solves the N-dimensional system A x = b using * + * the LU factorization in A and the pivot information in p * + * computed in DenseFactor. The solution x is returned in b. This * + * routine cannot fail if the corresponding call to DenseFactor * + * did not fail. * + * * + ******************************************************************/ + + void DenseBacksolve(DenseMat A, integertype * p, realtype * b); + + +/****************************************************************** + * * + * Function : DenseZero * + * Usage : DenseZero(A); * + *----------------------------------------------------------------* + * DenseZero sets all the elements of the N by N matrix A to 0.0. * + * * + ******************************************************************/ + + void DenseZero(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseCopy * + * Usage : DenseCopy(A, B); * + *----------------------------------------------------------------* + * DenseCopy copies the contents of the N by N matrix A into the * + * N by N matrix B. * + * * + ******************************************************************/ + + void DenseCopy(DenseMat A, DenseMat B); + + +/****************************************************************** + * * + * Function: DenseScale * + * Usage : DenseScale(c, A); * + *----------------------------------------------------------------* + * DenseScale scales the elements of the N by N matrix A by the * + * constant c and stores the result back in A. * + * * + ******************************************************************/ + + void DenseScale(realtype c, DenseMat A); + + +/****************************************************************** + * * + * Function : DenseAddI * + * Usage : DenseAddI(A); * + *----------------------------------------------------------------* + * DenseAddI adds the identity matrix to A and stores the result * + * back in A. * + * * + ******************************************************************/ + + void DenseAddI(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseFreeMat * + * Usage : DenseFreeMat(A); * + *----------------------------------------------------------------* + * DenseFreeMat frees the memory allocated by DenseAllocMat for * + * the N by N matrix A. * + * * + ******************************************************************/ + + void DenseFreeMat(DenseMat A); + + +/****************************************************************** + * * + * Function : DenseFreePiv * + * Usage : DenseFreePiv(p); * + *----------------------------------------------------------------* + * DenseFreePiv frees the memory allocated by DenseAllocPiv for * + * the pivot information array p. * + * * + ******************************************************************/ + + void DenseFreePiv(integertype * p); + + +/****************************************************************** + * * + * Function : DensePrint * + * Usage : DensePrint(A); * + *----------------------------------------------------------------* + * This routine prints the N by N dense matrix A to standard * + * output as it would normally appear on paper. It is intended * + * as a debugging tool with small values of N. The elements are * + * printed using the %g option. A blank line is printed before * + * and after the matrix. * + * * + ******************************************************************/ + + void DensePrint(DenseMat A); + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ +#endif /* _INC_DENSE_H */ diff --git a/rename_cpp/distribution.checklist b/rename_cpp/distribution.checklist new file mode 100644 index 00000000..86f3bb93 --- /dev/null +++ b/rename_cpp/distribution.checklist @@ -0,0 +1,85 @@ +(1) Copy distribution.checklist to checklist.VERSION + +(2) XXX Update version and date in main.c + +(3) XXX Update doc/README.TXT + XXX uname -r + XXX gcc -v + +(4) Update src/revisions + when all_dist is run by make, src/revisions is copied + to doc/RELEASE.TXT + + ( ../doc/phreeqc.txt now static, only RELEASE.TXT + has history 2/2/05) + +(5) Update Makefile and distribution.mk + set VERSION number + set VER_DATE + add any new files to distribution + database files + source files + output files + doc files + +(6) svn status ~/programs/phreeqc -q + svn ci ~/programs/phreeqc + svn update + +(7) remake everything + make clean_all + make output_files (also remakes programs) + +(8) svn status ~/programs/phreeqc -q + should be clean + otherwise commit and restart checklist at item 5 + +(9) make all_dist REVISION=xxx + ls phreeqc_export +Linux/ phreeqc-2.12-577.Linux.tar.gz phreeqc-2.12-577.source.tar.gz Source/ + +(10) test Unix distributions + make test_dist + or + make linux_test, sun_test, source_test + +(11) Scott is making batch windows + +(12) make web + install windows version + copy README.TXT to ~/programs/phreeqc/win + + cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc + cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT + cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT + cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT + cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT + cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt + cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT + +(13) check for latest version of Phreeqc For Windows. + +(14) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/index.html + phreeqci version, date, size + windows batch phreeqc version size + Linux batch phreeqc version size + Generic batch phreeqc version size + phreeqc for windows version, date, size + +(15) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqci/index.html + PhreeqcI version, date, size + +(16) send mail to Brian Marshal + +(17) PHAST + unpack release version in packages + Update table in /z/linarcolkr/home/www/projects/GWC_coupled/phast/index.html + copy release notes + from ~/packages/phast-x.x/doc/RELEASE.TXT + to /z/linarcolkr/home/www/projects/GWC_coupled/phast/RELEASE.TXT + copy readme + from ~/packages/phast-x.x/README + to /z/linarcolkr/home/www/projects/GWC_coupled/phast/README + +(18) Update status.fm + diff --git a/rename_cpp/distribution.mk b/rename_cpp/distribution.mk new file mode 100644 index 00000000..800088e7 --- /dev/null +++ b/rename_cpp/distribution.mk @@ -0,0 +1,391 @@ +# Locations to save compressed tar file for distribution +EXPORT=$(TOPDIR)/src/phreeqc_export +EXPORT_DIR=$(EXPORT) +WIN_DIR=$(TOPDIR)/win +DIST_DIR=$(EXPORT_DIR) +DEBUG_DIR=phreeqc_debug +CURSRC=$(CURDIR) +DEBUG_EXE=$(CURSRC)/phreeqc +VERSION=2.12 +VER_DATE:=November 10, 2005 +VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") +V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") +GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") +KERNEL_VER:=$(shell uname -r) +ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) +TEXTCP=textcp DOS +SUN_DIR=$(TOPDIR)/src/Sun +UNIX2DOS=unix2dos +CCFLAGS_DBG=-Wall -ansi -g -DUSE_PHRQ_ALLOC # -std=c99 + +CFG1 :=`uname` +CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") +ifeq ($(CFG), CYGWIN) + SPOOL=> + SPOOL2=2>&1 +else + SPOOL=>& + SPOOL2= +endif + +# list of files for distribution +FILES= \ + $(CURSRC)/Makefile \ + $(CURSRC)/advection.c \ + $(CURSRC)/basic.c \ + $(CURSRC)/basicsubs.c \ + $(CURSRC)/cl1.c \ + $(CURSRC)/cl1mp.c \ + $(CURSRC)/cvdense.c \ + $(CURSRC)/cvode.c \ + $(CURSRC)/dense.c \ + $(CURSRC)/dw.c \ + $(CURSRC)/input.c \ + $(CURSRC)/integrate.c \ + $(CURSRC)/inverse.c \ + $(CURSRC)/isotopes.c \ + $(CURSRC)/kinetics.c \ + $(CURSRC)/main.c \ + $(CURSRC)/mainsubs.c \ + $(CURSRC)/model.c \ + $(CURSRC)/nvector.c \ + $(CURSRC)/nvector_serial.c \ + $(CURSRC)/output.c \ + $(CURSRC)/p2clib.c \ + $(CURSRC)/parse.c \ + $(CURSRC)/phqalloc.c \ + $(CURSRC)/phreeqc_files.c \ + $(CURSRC)/pitzer.c \ + $(CURSRC)/pitzer_structures.c \ + $(CURSRC)/prep.c \ + $(CURSRC)/print.c \ + $(CURSRC)/read.c \ + $(CURSRC)/readtr.c \ + $(CURSRC)/sit.c \ + $(CURSRC)/smalldense.c \ + $(CURSRC)/spread.c \ + $(CURSRC)/step.c \ + $(CURSRC)/structures.c \ + $(CURSRC)/sundialsmath.c \ + $(CURSRC)/tally.c \ + $(CURSRC)/tidy.c \ + $(CURSRC)/transport.c \ + $(CURSRC)/utilities.c \ + $(CURSRC)/basic.h \ + $(CURSRC)/cvdense.h \ + $(CURSRC)/cvode.h \ + $(CURSRC)/dense.h \ + $(CURSRC)/global.h \ + $(CURSRC)/global_structures.h \ + $(CURSRC)/input.h \ + $(CURSRC)/kinetics.h \ + $(CURSRC)/nvector.h \ + $(CURSRC)/nvector_serial.h \ + $(CURSRC)/output.h \ + $(CURSRC)/p2c.h \ + $(CURSRC)/phqalloc.h \ + $(CURSRC)/phrqproto.h \ + $(CURSRC)/phrqtype.h \ + $(CURSRC)/pitzer.h \ + $(CURSRC)/pitzer_structures.h \ + $(CURSRC)/smalldense.h \ + $(CURSRC)/sundialsmath.h \ + $(CURSRC)/sundialstypes.h \ + database/*.dat \ + examples/ex1 examples/ex1.out \ + examples/ex2 examples/ex2.out examples/ex2.sel \ + examples/ex3 examples/ex3.out \ + examples/ex4 examples/ex4.out \ + examples/ex5 examples/ex5.out examples/ex5.sel \ + examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ + examples/ex7 examples/ex7.out examples/ex7.sel \ + examples/ex8 examples/ex8.out examples/ex8.sel \ + examples/ex9 examples/ex9.out examples/ex9.sel \ + examples/ex10 examples/ex10.out examples/ex10.sel \ + examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ + examples/ex12 examples/ex12.out examples/ex12.sel \ + examples/ex12a examples/ex12a.out examples/ex12a.sel \ + examples/ex13a examples/ex13a.out examples/ex13a.sel \ + examples/ex13b examples/ex13b.out examples/ex13b.sel \ + examples/ex13c examples/ex13c.out examples/ex13c.sel \ + examples/ex14 examples/ex14.out examples/ex14.sel \ + examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ + examples/ex16 examples/ex16.out \ + examples/ex17 examples/ex17.out \ + examples/ex18 examples/ex18.out \ + NOTICE.TXT \ + README.TXT \ + RELEASE.TXT \ + doc/manual.pdf \ + doc/wrir02-4172.pdf \ + doc/phreeqc.txt \ + bin/phreeqc.orig \ + test/test.sh \ + test/clean.sh \ + test/check.sh + +SED_ARGS= \ + -e "s/@VERSION@/$(VERSION)/" \ + -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ + -e "s/VERSION_DATE/$(VERSION)/" \ + -e "s^@GCC_VER@^$(GCC_VER)^" \ + -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ + -e "s/@REVISION@/$(REVISION)/" \ + -e "s/@PHREEQC_VER@/$(VERSION)/" \ + -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" + +SED_ARGS2=\ + -e "s/^\# Remove the following definition if you do not have /\# Add the following definition if you have/" \ + -e "s/^INVERSE_CL1MP=TRUE/\#INVERSE_CL1MP=TRUE/" + +remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files + +output_files: linux_output_files # sun_output_files + +# make sure program is compiles, run examples and mytest +linux_output_files: all + cd ../examples; make >& make.out + cd ../mytest; make >& make.out + +clean_linux_output_files: + cd ../examples; make clean + cd ../mytest; make clean + +sun_output_files: phreeqc.sun + ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" + +phreeqc.sun: + ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" + +clean_sun_output_files: + cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean + +all_dist: clean_dist linux source # win # sun + +test_dist: linux_test source_test # sun_test + +# +#Linux +# +linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist + +source: source_export source_clean source_sed_files source_dist + +linux_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Linux + svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux + +linux_clean: + rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o + +linux_sed_list= \ + "$(EXPORT_DIR)/Linux/doc/README.TXT \ + $(EXPORT_DIR)/Linux/src/main.c" + +linux_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT + for FILE in "$(linux_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT + mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT + +linux_compile: + make -C $(EXPORT_DIR)/Linux/src + +linux_output: + cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out + +linux_dist: + cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar + + cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) + cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile + cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz + cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) + +source_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Source + svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source + +source_clean: + rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o + +source_sed_list= \ + "$(EXPORT_DIR)/Source/doc/README.TXT \ + $(EXPORT_DIR)/Source/src/main.c" + +source_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT + sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile + for FILE in "$(source_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT + mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT + +source_dist: + cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar + cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz + cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) + +linux_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh + rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k + cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh + +source_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source + cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k + cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh + +# +#Sun +# +sun: sun_export sun_clean sun_sed_files sun_compile sun_output sun_dist + +sun_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Sun + svn export .. $(EXPORT_DIR)/Sun + +sun_clean: + rm -f $(EXPORT_DIR)/Sun/bin/$(PROGRAM) $(EXPORT_DIR)/Sun/src/*.o + +sun_sed_list= \ + "$(EXPORT_DIR)/Sun/doc/README.TXT \ + $(EXPORT_DIR)/Sun/src/main.c" + +sun_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Sun/src/revisions > $(EXPORT_DIR)/Sun/doc/RELEASE.TXT + for FILE in "$(sun_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done + +sun_compile: + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/src" + +sun_output: + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples clean" + ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples" > $(EXPORT_DIR)/Sun/examples/make.out 2>> $(EXPORT_DIR)/Sun/examples/make.out + +sun_dist: + cd $(EXPORT_DIR)/Sun; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Sun; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Sun; tar -rf $(PROGRAM).tar bin/$(PROGRAM) + cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar + cd $(EXPORT_DIR)/Sun; tar -czf $(PROGRAM).Sun.tar.gz $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).Sun.tar.gz $(DIST_DIR)/$(ROOTNAME).Sun.tar.gz + cd $(EXPORT_DIR)/Sun; echo $(ROOTNAME).Sun.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) + +sun_test: + rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Sun + cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Sun.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Sun + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./test.sh" + rm -f $(DIST_DIR)/phreeqc-$(VERSION).Sun/bin/phreeqc + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/src; make -k" + ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./clean.sh; ./test.sh" + +clean_dist: + rm -rf $(EXPORT_DIR) + +clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files + +# +#Win +# +win: win_export win_sed_files win_dist + +win_export: + mkdir -p $(EXPORT_DIR) + rm -rf $(EXPORT_DIR)/Win + svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win + +win_sed_list= \ + "$(EXPORT_DIR)/Win/src/main.c" + +win_sed_files: + sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT + $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT + sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT + $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT + for FILE in "$(win_sed_list)"; do \ + sed $(SED_ARGS) < $$FILE > t; \ + mv t $$FILE; \ + $(UNIX2DOS) $$FILE; \ + done + mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT + +win_dist: + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar +# Translate cr/lf + cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ + if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ + else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done + cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) + cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +# remove example output + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel +# remove bin directory + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin +# remove test directory files + cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat +# copy bat file + cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat + cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz + cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . + @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). + cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) + +win_echo_files: + @echo $(FILES) + +debug: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) + +debug_nomp: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) + +web: + cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc + cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT + cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT + cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT + cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT + cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt + cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT + +tester: + cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + svn status -q ../mytest + svn status -q ../examples diff --git a/rename_cpp/dw.cpp b/rename_cpp/dw.cpp new file mode 100644 index 00000000..d0c557c7 --- /dev/null +++ b/rename_cpp/dw.cpp @@ -0,0 +1,414 @@ +#include "Phreeqc.h" + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +DW(LDBLE T) +/* ---------------------------------------------------------------------- */ +/* +C +C SUBROUTINE TO CALCULATE THE DENSITY OF WATER AS A FUNCTION OF +C TEMPERATURE. T IS IN KELVIN, P IS IN PASCALS, DW0 IS IN G/CM^3 +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + LDBLE FP = 9.869232667e0, P, DGSS, D; + + BB(T); + P = 1.0e0 / FP; + if (T > 373.149e0) + P = PS(T); + DGSS = P / T / .4e0; + if (T < TZ) + { + DGSS = 1.0e0 / (VLEST(T)); + } + DFIND(&D, P, DGSS, T); + DW0 = D; + VP = P * FP; + return OK; +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +BB(LDBLE T) +/* ---------------------------------------------------------------------- */ +/* + +C +C THIS SUBROUTINE CALCULATES THE B'S NEEDED FOR FUNCTION DW. +C THE B'S CALCULATED HERE ARE IN CM3/G. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + LDBLE V[11]; + int I; + /* COMMON /BCONST/ */ + LDBLE P[11] = + { 0, 0.7478629e0, -.3540782e0, 0.e0, 0e0, .007159876e0, 0.e0, + -.003528426e0, 0., 0., 0. + }; + LDBLE Q[11] = + { 0, 1.1278334e0, 0.e0, -.5944001e0, -5.010996e0, 0.e0, .63684256e0, + 0., 0., 0., 0. + }; + + V[1] = 1.0; + for (I = 2; I <= 10; I++) + { + V[I] = V[I - 1] * TZ / T; + } + B1 = P[1] + P[2] * log(1.e0 / V[2]); + B2 = Q[1]; + B1T = P[2] * V[2] / TZ; + B2T = 0.e0; + B1TT = 0.e0; + B2TT = 0.e0; + for (I = 3; I <= 10; I++) + { + B1 = B1 + P[I] * V[I - 1]; + B2 = B2 + Q[I] * V[I - 1]; + B1T = B1T - (I - 2) * P[I] * V[I - 1] / T; + B2T = B2T - (I - 2) * Q[I] * V[I - 1] / T; + B1TT = B1TT + P[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; + B2TT = B2TT + Q[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; + } + B1TT = B1TT - B1T / T; + B2TT = B2TT - B2T / T; + return OK; +} + +/* ---------------------------------------------------------------------- */ + LDBLE Phreeqc:: +PS(LDBLE T) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES AN APPROXIMATION TO THE VAPOR PRESSURE, P +C AS A FUNCTION OF THE INPUT TEMPERATURE. THE VAPOR PRESSURE +C CALCULATED AGREES WITH THE VAPOR PRESSURE PREDICTED BY THE SURFACE +C TO WITHIN .02% TO WITHIN A DEGREE OR SO OF THE CRITICAL TEMPERATUR +C AND CAN SERVE AS AN INITIAL GUESS FOR FURTHER REFINEMENT BY +C IMPOSING THE CONDITION THAT GL=GV. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + LDBLE A[9] = { 0, -7.8889166e0, 2.5514255e0, -6.716169e0, + 33.239495e0, -105.38479e0, 174.35319e0, -148.39348e0, + 48.631602e0 + }; + LDBLE PL, V, W, B, L_Z, Q; + int I; + if (T <= 314.e0) + { + PL = 6.3573118e0 - 8858.843e0 / T + 607.56335e0 * pow(T, (LDBLE) -.6e0); + return (.1e0 * exp(PL)); + } + V = T / 647.25e0; + W = fabs(1.e0 - V); + B = 0.e0; + for (I = 1; I <= 8; I++) + { + L_Z = I; + B = B + A[I] * pow(W, ((L_Z + 1.e0) / 2.e0)); + } + Q = B / V; + return (22.093e0 * exp(Q)); +} + +/* ---------------------------------------------------------------------- */ + LDBLE Phreeqc:: +VLEST(LDBLE T) +/* ---------------------------------------------------------------------- */ +/* +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + LDBLE A = -1.59259e1, B = 6.57886e-2, C = -1.12666e-4, D = 7.33191e-8, + E = 1.60229e3, F = 2.88572e0, G = 650.0e0; + + return (A + B * T + C * T * T + D * T * T * T + E / T + F / (G - T)); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T) +/* ---------------------------------------------------------------------- */ +/* +C +C ROUTINE TO FIND DENSITY CORRESPONDING TO INPUT PRESSURE P(MPA), AN +C TEMPERATURE T(K), USING INITIAL GUESS DENSITY D(G/CM3). THE OUTPUT +C DENSITY IS IN G/CM3. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + int L; + LDBLE DD, RT, PP_dfind, DPD, DPDX, DP, X; + /* LDBLE DD, RT, PP, DPD, DPDX, DP, X; */ + + DD = D; + RT = GASCON * T; + if (DD <= 0.e0) + DD = 1.e-8; + if (DD > 1.9e0) + DD = 1.9e0; + L = 0; + for (L = 1; L <= 30; L++) + { + if (DD <= 0.e0) + DD = 1.e-8; + if (DD > 1.9e0) + DD = 1.9e0; + QQ(T, DD); + PP_dfind = RT * DD * BASE(DD) + Q0; + DPD = RT * (Z + Y * DZ) + Q5; + /* + C + C THE FOLLOWING 3 LINES CHECK FOR NEGATIVE DP/DRHO, AND IF SO ASSUME + C GUESS TO BE IN 2-PHASE REGION, AND CORRECT GUESS ACCORDINGLY. + C + */ + if (DPD <= 0.e0) + { + if (D >= .2967e0) + DD = DD * 1.02e0; + if (D < .2967e0) + DD = DD * .98e0; + if (L <= 10) + continue; + } + else + { +/* 13 */ + DPDX = DPD * 1.1e0; + if (DPDX < 0.1e0) + DPDX = 0.1e0; + DP = fabs(1.e0 - PP_dfind / P); + if (DP < 1.e-8) + break; + if (D > .3e0 && DP < 1.e-7) + break; + if (D > .7e0 && DP < 1.e-6) + break; + X = (P - PP_dfind) / DPDX; + if (fabs(X) > .1e0) + X = X * .1e0 / fabs(X); + DD = DD + X; + if (DD < 0.e0) + DD = 1.e-8; + } + } + if (L > 30) + error_msg("In subroutine DFIND", STOP); + //cite Jonathan Toner, remove error_msg + //DD = 1; +/* 20 CONTINUE */ + *DOUT = DD; + return OK; +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +QQ(LDBLE T, LDBLE D) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS ROUTINE CALCULATES, FOR A GIVEN T(K) AND D(G/CM3), THE RESIDUL +C CONTRIBUTIONS TO: PRESSURE (Q), DP/DRHO (Q5) +C THIS SUBROUTINE IS USED IN DENSITY OF WATER CALCULATION. +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + /* COMMON /NCONST/ */ + LDBLE G[41] = + { 0, -.53062968529023e3, .22744901424408e4, .78779333020687e3, + -.69830527374994e2, .17863832875422e5, -.39514731563338e5, + .33803884280753e5, + -.13855050202703e5, -.25637436613260e6, .48212575981415e6, + -.34183016969660e6, + .12223156417448e6, .11797433655832e7, -.21734810110373e7, + .10829952168620e7, + -.25441998064049e6, -.31377774947767e7, .52911910757704e7, + -.13802577177877e7, + -.25109914369001e6, .46561826115608e7, -.72752773275387e7, + .41774246148294e6, + .14016358244614e7, -.31555231392127e7, .47929666384584e7, + .40912664781209e6, + -.13626369388386e7, .69625220862664e6, -.10834900096447e7, + -.22722827401688e6, + .38365486000660e6, .68833257944332e4, .21757245522644e5, + -.26627944829770e4, + -.70730418082074e5, -.225e0, -1.68e0, .055e0, -93.0e0 + }; + /*int II[41]={0,4*0,4*1,4*2,4*3,4*4,4*5,4*6,4*8,2*2,0,4,3*2,4}; */ + int II[41] = + { 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, + 5, + 5, 6, 6, 6, 6, 8, 8, 8, 8, 2, 2, 0, 4, 2, 2, 2, 4 + }; + /*int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,3*4,0,2,0,0}; */ + int JJ[41] = + { 0, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, + 5, + 7, 2, 3, 5, 7, 2, 3, 5, 7, 1, 4, 4, 4, 0, 2, 0, 0 + }; + int NC = 36; + /* COMMON /ADDCON/ */ + LDBLE ATZ[5] = { 0, 64.e1, 64.e1, 641.6e0, 27.e1 }, ADZ[5] = + { + 0, .319e0, .319e0, .319e0, 1.55e0}, AAT[5] = + { + 0, 2.e4, 2.e4, 4.e4, 25.e0}, AAD[5] = + { + 0, 34.e0, 4.e1, 3.e1, 1.05e3}; + LDBLE *QZT; + LDBLE QR[12], QT[11] /*, QZT[10] */ ; + /*EQUIVALENCE (QT(2),QZT(1)) */ + + LDBLE E, Q10, Q20, V, QP, DDZ, DEL, EX1, DEX, ATT, TX, + TAU, EX2, TEX, QM, FCT, Q5T; + int I, K, L, J, KM; + QZT = &(QT[1]); + QR[1] = 0.e0; + Q5 = 0.e0; + Q0 = 0.e0; + E = exp(-AA * D); + Q10 = D * D * E; + Q20 = 1.e0 - E; + QR[2] = Q10; + V = TZ / T; + QT[1] = T / TZ; + /*DO 4 I=2,10 */ + for (I = 2; I <= 10; I++) + { + QR[I + 1] = QR[I] * Q20; + /* 4 QT[I]=QT[I-1]*V */ + QT[I] = QT[I - 1] * V; + } + /* DO 10 I=1,NC */ + for (I = 1; I <= NC; I++) + { + K = II[I] + 1; + L = JJ[I]; + QP = G[I] * AA * QR[K + 1] * QZT[L]; + Q0 = Q0 + QP; + /*10 Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP */ + Q5 = Q5 + AA * (2.e0 / D - AA * (1.e0 - E * (K - 1) / Q20)) * QP; + } + QP = 0.e0; + /* DO 20 J=37,40 */ + for (J = 37; J <= 40; J++) + { + if (fabs(G[J]) < 1.0e-20) + continue; + K = II[J]; + KM = JJ[J]; + DDZ = ADZ[J - 36]; + DEL = D / DDZ - 1.e0; + if (fabs(DEL) < 1.e-10) + DEL = 1.e-10; + EX1 = -AAD[J - 36] * pow(DEL, K); + if (EX1 <= -88.028e0) + { + DEX = 0.e0; + } + else + { + DEX = exp(EX1) * pow(DEL, KM); + } + ATT = AAT[J - 36]; + TX = ATZ[J - 36]; + TAU = T / TX - 1.e0; + EX2 = -ATT * TAU * TAU; + if (EX2 <= -88.028e0) + { + TEX = 0.e0; + } + else + { + TEX = exp(EX2); + } + Q10 = DEX * TEX; + QM = KM / DEL - K * AAD[J - 36] * pow(DEL, (K - 1)); + FCT = QM * D * D * Q10 / DDZ; + Q5T = + FCT * (2.e0 / D + QM / DDZ) - pow((D / DDZ), + 2) * Q10 * (KM / DEL / DEL + + K * (K - + 1) * AAD[J - + 36] * + pow(DEL, (K - 2))); + Q5 = Q5 + Q5T * G[J]; + QP = QP + G[J] * FCT; + /* 20 CONTINUE */ + } + Q0 = Q0 + QP; + return OK; +} + +/* ---------------------------------------------------------------------- */ + LDBLE Phreeqc:: +BASE(LDBLE D) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES THE Z (=PBASE/(DRT)) NEEDED FOR FUNCTION +C +C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) +C +*/ +{ + LDBLE X, Z0, DZ0; +/* +C +C G1,G2 AND GF ARE THE ALPHA, BETA AND GAMMA FOR DENSITY OF WATER +C CALCULATIONS. B1 AND B2 ARE THE 'EXCLUDED VOLUME' AND '2ND VIRIAL +C SUPPLIED BY THE SUBROUTINE BB(T), WHICH ALSO SUPPLIES THE 1ST AND +C 2ND DERIVATIVES WITH RESPECT TO T (B1T,B2T,B1TT,B2TT). +C +*/ + Y = .25e0 * B1 * D; + X = 1.e0 - Y; + Z0 = (1.e0 + G1 * Y + G2 * Y * Y) / pow(X, 3); + Z = Z0 + 4.e0 * Y * (B2 / B1 - GF); + DZ0 = + (G1 + 2.e0 * G2 * Y) / pow(X, + 3) + 3.e0 * (1.e0 + G1 * Y + + G2 * Y * Y) / pow(X, 4); + DZ = DZ0 + 4.e0 * (B2 / B1 - GF); + return (Z); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +DC(LDBLE T) +/* ---------------------------------------------------------------------- */ +/* +C +C THIS FUNCTION CALCULATES THE RELATIVE DIELECTRIC CONSTANT AS A +C FUNCTION OF TEMPERATURE, ASSUMING ONE ATMOSPHERE PRESSURE +C ACCORDING TO D. J. BRADLEY AND K. S. PITZER, (1979) +C +*/ +{ + LDBLE D1000, C, B; + LDBLE U[10] = { 0, 3.4279e2, -5.0866e-3, 9.4690e-7, -2.0525e0, 3.1159e3, + -1.8289e2, -8.0325e3, 4.2142e6, 2.1417e0 + }; + D1000 = U[1] * exp(U[2] * T + U[3] * T * T); + C = U[4] + U[5] / (U[6] + T); + B = U[7] + U[8] / T + U[9] * T; + return (D1000 + C * log((B + VP * 1.01325e0) / (B + 1000.0e0))); +} diff --git a/rename_cpp/gases.cpp b/rename_cpp/gases.cpp new file mode 100644 index 00000000..dfe22908 --- /dev/null +++ b/rename_cpp/gases.cpp @@ -0,0 +1,675 @@ +#include "Phreeqc.h" +#include "GasPhase.h" +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_fixed_volume_gas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for gas phase unknown (sum of partial pressures) + * in unknown structure + */ + //int i; + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); +/* + * One for each gas component + */ + gas_unknowns.clear(); + gas_unknown = NULL; + gas_phase_ptr->Set_total_moles(0); + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + const cxxGasComp *comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int j; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_phase_name().c_str(), &j, FALSE); + x[count_unknowns]->type = GAS_MOLES; + //x[count_unknowns]->description = string_hsave("gas moles"); + x[count_unknowns]->description = phase_ptr->name; + x[count_unknowns]->phase = phase_ptr; + x[count_unknowns]->moles = comp_ptr->Get_moles(); + if (x[count_unknowns]->moles <= 0) + { + x[count_unknowns]->moles = MIN_TOTAL; + } + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + //x[count_unknowns]->gas_phase = use.Get_gas_phase_ptr(); + gas_unknowns.push_back(x[count_unknowns]); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + x[count_unknowns]->moles); + x[count_unknowns]->phase->moles_x = x[count_unknowns]->moles; + count_unknowns++; + } + if (gas_unknowns.size() > 0) + { + gas_unknown = gas_unknowns[0]; + } + same_pressure = FALSE; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_fixed_volume_gas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * sum of partial pressures equation and + * mass balance equations for elements contained in gases + */ + //int i, j; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + //struct gas_comp *gas_comp_ptr; + //struct phase *phase_ptr; + struct unknown *unknown_ptr; + LDBLE coef, coef_elt; + + if (gas_unknown == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + const cxxGasComp *comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int j; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_phase_name().c_str(), &j, FALSE); +/* + * Determine elements in gas component + */ + count_elts = 0; + paren_count = 0; + if (phase_ptr->rxn_x == NULL) + continue; + add_elt_list(phase_ptr->next_elt, 1.0); +#define COMBINE +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif +/* + * Build mass balance sums for each element in gas + */ + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tMass balance summations %s.\n\n", + phase_ptr->name)); + } + + /* All elements in gas */ + for (j = 0; j < count_elts; j++) + { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name, "H") == 0) + { + unknown_ptr = mass_hydrogen_unknown; + } + else if (strcmp(elt_list[j].elt->name, "O") == 0) + { + unknown_ptr = mass_oxygen_unknown; + } + else + { + if (elt_list[j].elt->primary->in == TRUE) + { + unknown_ptr = elt_list[j].elt->primary->unknown; + } + else if (elt_list[j].elt->primary->s->secondary != NULL) + { + unknown_ptr = + elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr != NULL) + { + coef = elt_list[j].coef; + //store_mb(&(gas_comp_ptr->phase->moles_x), &(unknown_ptr->f), coef); + store_mb(&(gas_unknowns[i]->moles), &(unknown_ptr->f), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\n", + unknown_ptr->description, (double) coef)); + } + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* Total pressure of gases */ + store_mb(&(phase_ptr->p_soln_x), &(gas_unknown->f), + 1.0); + } +/* + * Build jacobian sums for mass balance equations + */ + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tJacobian summations %s.\n\n", + phase_ptr->name)); + } + for (j = 0; j < count_elts; j++) + { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name, "H") == 0) + { + unknown_ptr = mass_hydrogen_unknown; + } + else if (strcmp(elt_list[j].elt->name, "O") == 0) + { + unknown_ptr = mass_oxygen_unknown; + } + else + { + if (elt_list[j].elt->primary->in == TRUE) + { + unknown_ptr = elt_list[j].elt->primary->unknown; + } + else if (elt_list[j].elt->primary->s->secondary != NULL) + { + unknown_ptr = + elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr == NULL) + { + continue; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\t%s.\n", + unknown_ptr->description)); + } + row = unknown_ptr->number * (count_unknowns + 1); + coef_elt = elt_list[j].coef; + for (rxn_ptr = phase_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL) + { + error_string = sformatf( + "Element needed for gas component, %s, is not in model.", + phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + continue; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%s\n", + master_ptr->s->name)); + } + if (master_ptr->unknown == NULL) + { + continue; + } + if (master_ptr->in == FALSE) + { + error_string = sformatf( + "Element, %s, in phase, %s, is not in model.", + master_ptr->elt->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + col = master_ptr->unknown->number; + coef = coef_elt * rxn_ptr->coef; + //store_jacob(&(gas_comp_ptr->phase->moles_x), + // &(array[row + col]), coef); + store_jacob(&(gas_unknowns[i]->moles), + &(array[row + col]), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + master_ptr->s->name, (double) coef, + row / (count_unknowns + 1), col)); + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* derivative wrt total moles of gas */ + store_jacob(&(phase_ptr->fraction_x), + &(array[row + gas_unknown->number]), coef_elt); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + "gas moles", (double) elt_list[j].coef, + row / (count_unknowns + 1), + gas_unknown->number)); + } + } + } +/* + * Build jacobian sums for sum of partial pressures equation + */ + if (gas_phase_ptr->Get_type() != cxxGasPhase::GP_PRESSURE) + continue; + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tPartial pressure eqn %s.\n\n", + phase_ptr->name)); + } + unknown_ptr = gas_unknown; + row = unknown_ptr->number * (count_unknowns + 1); + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) + { + if (rxn_ptr->s != s_eminus && rxn_ptr->s->in == FALSE) + { + error_string = sformatf( + "Element in species, %s, in phase, %s, is not in model.", + rxn_ptr->s->name, phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + } + else + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + + if (master_ptr == NULL) + { + error_string = sformatf( + "Master species for %s, in phase, %s, is not in model.", + rxn_ptr->s->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%s\n", master_ptr->s->name)); + } + if (master_ptr->unknown == NULL) + { + assert(false); + continue; + } + if (master_ptr->in == FALSE) + { + error_string = sformatf( + "Element, %s, in phase, %s, is not in model.", + master_ptr->elt->name, phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + } + col = master_ptr->unknown->number; + coef = rxn_ptr->coef; + store_jacob(&(phase_ptr->p_soln_x), &(array[row + col]), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + master_ptr->s->name, (double) coef, + row / (count_unknowns + 1), col)); + } + } + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_PR(void) +/* ---------------------------------------------------------------------- */ +/* Calculate fugacity and fugacity coefficient for gas pressures if critical T and P + are defined. + 1) Solve molar volume V_m or total pressure P from Peng-Robinson's EOS: + P = R * T / (V_m - b) - a * aa / (V_m^2 + 2 * b * V_m - b^2) + a = 0.457235 * (R * T_c)^2 / P_c + b = 0.077796 * R * T_c / P_c + aa = (1 + kk * (1 - T_r^0.5))^2 + kk = 0.37464 + 1.54226 * omega - 0.26992 * omega^2 + T_r = T / T_c + multicomponent gas phase: + use: b_sum = Sum(x_i * b), x_i is mole-fraction + a_aa_sum = Sum_i( Sum_j(x_i * x_j * (a_i * aa_i * a_j * aa_j)^0.5) ) + 2) Find the fugacity coefficient phi for gas i: + log(phi_i) = B_ratio * (z - 1) - log(z - B) + A / (2.8284 * B) * (B_ratio - 2 / a_aa_sum * a_aa_sum2) *\ + log((z + 2.4142 * B) / (z - 0.4142 * B)) + B_ratio = b_i / b_sum + A = a_aa_sum * P / R_TK^2 + B = b_sum * P / R_TK + a_aa_sum2 = Sum_j(x_j * (a_aa_i * a_aa_j)^0.5 + 3) correct the solubility of gas i with: + pr_si_f = log10(phi_i) - Delta_V_i * (P - 1) / (2.303 * R * TK); +*/ +{ + //int i, i1; + LDBLE T_c, P_c; + LDBLE A, B, B_r, /*b2,*/ kk, oo, a_aa, T_r; + LDBLE m_sum, /*b_sum, a_aa_sum,*/ a_aa_sum2; + LDBLE phi; + LDBLE /*R_TK,*/ R = R_LITER_ATM; /* L atm / (K mol) */ + LDBLE r3[4], r3_12, rp, rp3, rq, rz, ri, ri1, one_3 = 0.33333333333333333; + LDBLE disct, vinit, v1, ddp, dp_dv, dp_dv2; + int it; + struct phase *phase_ptr; + LDBLE V_m = 0, P = 0; + + LDBLE TK = tk_x; + bool halved; + R_TK = R * TK; + m_sum = b_sum = a_aa_sum = 0.0; + size_t i; + + if (gas_unknowns.size() == 0) + { + error_msg("No gas unknowns.", STOP); + } + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + + for (i = 0; i < gas_unknowns.size(); i++) + { + m_sum += gas_unknowns[i]->moles; + phase_ptr = gas_unknowns[i]->phase; + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + continue; + if (!phase_ptr->pr_a) + { + T_c = phase_ptr->t_c; + P_c = phase_ptr->p_c; + phase_ptr->pr_a = 0.457235 * R * R * T_c * T_c / P_c; + phase_ptr->pr_b = 0.077796 * R * T_c / P_c; + T_r = TK / T_c; + oo = phase_ptr->omega; + kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); + phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); + phase_ptr->pr_tk = TK; + phase_ptr->pr_in = true; + } + if (phase_ptr->pr_tk != TK) + { + T_r = TK / phase_ptr->t_c; + oo = phase_ptr->omega; + kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); + phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); + phase_ptr->pr_tk = TK; + phase_ptr->pr_in = true; + } + } + if (m_sum == 0) + return (OK); + gas_phase_ptr->Set_v_m(gas_phase_ptr->Get_volume() / m_sum); + for (i = 0; i < gas_unknowns.size(); i++) + { + phase_ptr = gas_unknowns[i]->phase; + phase_ptr->fraction_x = gas_unknowns[i]->moles / m_sum; // phase_ptr->fraction_x updated + } + + for (i = 0; i < gas_unknowns.size(); i++) + { + a_aa_sum2 = 0.0; + phase_ptr = gas_unknowns[i]->phase; + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + continue; + b_sum += phase_ptr->fraction_x * phase_ptr->pr_b; + size_t i1; + struct phase *phase_ptr1; + for (i1 = 0; i1 < gas_unknowns.size(); i1++) + { + phase_ptr1 = gas_unknowns[i1]->phase; + if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) + continue; + if (phase_ptr1->fraction_x == 0) + continue; + a_aa = sqrt(phase_ptr->pr_a * phase_ptr->pr_alpha * + phase_ptr1->pr_a * phase_ptr1->pr_alpha); + if (!strcmp(phase_ptr->name, "H2O(g)")) + { + if (!strcmp(phase_ptr1->name, "CO2(g)")) + a_aa *= 0.81; // Soreide and Whitson, 1992, FPE 77, 217 + else if (!strcmp(phase_ptr1->name, "H2S(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr1->name, "CH4(g)")) + a_aa *= 0.51; + else if (!strcmp(phase_ptr1->name, "N2(g)")) + a_aa *= 0.51; + } + if (!strcmp(phase_ptr1->name, "H2O(g)")) + { + if (!strcmp(phase_ptr->name, "CO2(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr->name, "H2S(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr->name, "CH4(g)")) + a_aa *= 0.51; + else if (!strcmp(phase_ptr->name, "N2(g)")) + a_aa *= 0.51; + } + a_aa_sum += phase_ptr->fraction_x * phase_ptr1->fraction_x * a_aa; + a_aa_sum2 += phase_ptr1->fraction_x * a_aa; + } + phase_ptr->pr_aa_sum2 = a_aa_sum2; + } + b2 = b_sum * b_sum; + + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + V_m = gas_phase_ptr->Get_volume() / m_sum; + P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); + if (iterations > 0 && P < 150) + { + // check for 3-roots... + r3[1] = b_sum - R_TK / P; + r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; + r3[3] = b2 * b_sum + (R_TK * b2 - b_sum * a_aa_sum) / P; + // the discriminant of the cubic eqn... + disct = 18. * r3[1] * r3[2] * r3[3] - + 4. * pow(r3[1], 3) * r3[3] + + r3[1] * r3[1] * r3[2] * r3[2] - + 4. * pow(r3[2], 3) - + 27. * r3[3] * r3[3]; + if (disct > 0) + { + // 3-roots, find the largest P... + it = 0; + halved = false; + ddp = 1e-9; + v1 = vinit = 0.429; + dp_dv = f_Vm(v1, this); + while (fabs(dp_dv) > 1e-11 && it < 40) + { + it +=1; + dp_dv2 = f_Vm(v1 - ddp, this); + v1 -= (dp_dv * ddp / (dp_dv - dp_dv2)); + if (!halved && (v1 > vinit || v1 < 0.03)) + { + vinit -= 0.05; + if (vinit < 0.03) + { + vinit = halve(f_Vm, 0.03, 1.0, 1e-3); + if (f_Vm(vinit - 2e-3, this) < 0) + vinit = halve(f_Vm, vinit + 2e-3, 1.0, 1e-3); + halved = true; + } + v1 = vinit; + } + dp_dv = f_Vm(v1, this); + if (fabs(dp_dv) < 1e-11) + { + if (f_Vm(v1 - 1e-4, this) < 0) + { + v1 = halve(f_Vm, v1 + 1e-4, 1.0, 1e-3); + dp_dv = f_Vm(v1, this); + } + } + } + if (it == 40) + { +// accept a (possible) whobble in the curve... +// error_msg("No convergence when calculating P in Peng-Robinson.", STOP); + } + if (V_m < v1) + P = R_TK / (v1 - b_sum) - a_aa_sum / (v1 * (v1 + 2 * b_sum) - b2); + } + } + if (P <= 0) // iterations = -1 + P = 1.; + gas_phase_ptr->Set_total_p(P); // phase_ptr->total_p updated + gas_phase_ptr->Set_v_m(V_m); + } + else + { + assert(false); + P = gas_phase_ptr->Get_total_p(); + r3[1] = b_sum - R_TK / P; + r3_12 = r3[1] * r3[1]; + r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; + r3[3] = b2 * b_sum + (R_TK * b2 - b_sum * a_aa_sum) / P; + // solve t^3 + rp*t + rq = 0. + // molar volume V_m = t - r3[1] / 3... + rp = r3[2] - r3_12 / 3; + rp3 = rp * rp * rp; + rq = (2.0 * r3_12 * r3[1] - 9.0 * r3[1] * r3[2]) / 27 + r3[3]; + rz = rq * rq / 4 + rp3 / 27; + if (rz >= 0) // Cardono's method... + { + ri = sqrt(rz); + if (ri + rq / 2 <= 0) + { + V_m = pow(ri - rq / 2, one_3) + pow(- ri - rq / 2, one_3) - r3[1] / 3; + } else + { + ri = - pow(ri + rq / 2, one_3); + V_m = ri - rp / (3.0 * ri) - r3[1] / 3; + } + } else // use complex plane... + { + ri = sqrt(- rp3 / 27); // rp < 0 + ri1 = acos(- rq / 2 / ri); + V_m = 2.0 * pow(ri, one_3) * cos(ri1 / 3) - r3[1] / 3; + } + gas_phase_ptr->Set_v_m(V_m); // phase_ptr->fraction_x updated + } + // calculate the fugacity coefficients... + for (i = 0; i < gas_unknowns.size(); i++) + { + phase_ptr = gas_unknowns[i]->phase; + if (phase_ptr->fraction_x == 0.0) + { + phase_ptr->pr_p = 0; + phase_ptr->pr_phi = 1; + phase_ptr->pr_si_f = 0.0; + continue; + } + phase_ptr->pr_p = phase_ptr->fraction_x * P; + + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + { + phase_ptr->pr_phi = 1; + continue; + } + rz = P * V_m / R_TK; + A = a_aa_sum * P / (R_TK * R_TK); + B = b_sum * P / R_TK; + B_r = phase_ptr->pr_b / b_sum; + if (rz > B) + phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + else + phi = -3.0; // fugacity coefficient > 0.05 + phase_ptr->pr_phi = exp(phi); + phase_ptr->pr_si_f = phi / LOG_10; // pr_si_f updated + phase_ptr->pr_in = true; + } + return (V_m); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_fixed_volume_gas_pressures(void) +/* ---------------------------------------------------------------------- */ +{ + int n_g = 0; + LDBLE lp; + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + bool PR = false, pr_done = false; + size_t i; +/* + * moles and partial pressures for gases + */ + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + gas_phase_ptr->Set_total_moles(0); + + for (i = 0; i < gas_unknowns.size(); i++) + { + phase_ptr = gas_unknowns[i]->phase; + if (phase_ptr->in == TRUE) + { + if (!PR && phase_ptr->t_c > 0 && phase_ptr->p_c > 0) + PR = true; + n_g++; + } + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gas_unknowns[i]->moles); + } + if (PR && gas_phase_ptr->Get_total_moles() > 0) + { + calc_PR(); + pr_done = true; + gas_phase_ptr->Set_total_moles(0); + } else + { + gas_phase_ptr->Set_total_p(0); + gas_phase_ptr->Set_total_moles(0); + } + for (i = 0; i < gas_unknowns.size(); i++) + { + phase_ptr = gas_unknowns[i]->phase; + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + //lp = -k_calc(phase_ptr->rxn_x->logk, tk_x, use.Get_gas_phase_ptr()->total_p * PASCAL_PER_ATM); + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + phase_ptr->p_soln_x = exp(LOG_10 * (lp - phase_ptr->pr_si_f)); + + if (pr_done) + { + lp = phase_ptr->p_soln_x / gas_phase_ptr->Get_total_p() * + gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_v_m(); + phase_ptr->moles_x = lp; + } + else + { + phase_ptr->moles_x = phase_ptr->p_soln_x * gas_phase_ptr->Get_volume() / (R_LITER_ATM * tk_x); + gas_phase_ptr->Set_total_p(gas_phase_ptr->Get_total_p() + phase_ptr->p_soln_x); + } + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + phase_ptr->moles_x); + } + else + { + phase_ptr->moles_x = 0; + phase_ptr->fraction_x = 0; + } + } + + return (OK); +} diff --git a/rename_cpp/global_structures.h b/rename_cpp/global_structures.h new file mode 100644 index 00000000..a8f6eccc --- /dev/null +++ b/rename_cpp/global_structures.h @@ -0,0 +1,1350 @@ +#ifndef _INC_GLOBAL_STRUCTURES_H +#define _INC_GLOBAL_STRUCTURES_H +/* ---------------------------------------------------------------------- + * #define DEFINITIONS + * ---------------------------------------------------------------------- */ +#ifndef NAN +# define NAN -99999999 +#endif +#define MISSING -9999.999 +//#define NA -98.765 /* NA = not available */ +#include "NA.h" + +#define F_C_MOL 96493.5 /* C/mol or joule/volt-eq */ +#define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ +#define F_KCAL_V_EQ 23.0623 /* kcal/volt-eq */ +#define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ +#define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ +#define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ +#define EPSILON 78.5 /* dialectric constant, dimensionless */ +#define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ +#define JOULES_PER_CALORIE 4.1840 +#define PASCAL_PER_ATM 1.01325E5 /* conversion from atm to Pa */ +#define AVOGADRO 6.02252e23 /* atoms / mole */ + +#define TRUE 1 +#define FALSE 0 +#define OK 1 +#define ERROR 0 +#define STOP 1 +#define CONTINUE 0 + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPT_1 -5 + +#define DISP 2 +#define STAG 3 +#define NOMIX 4 + +#define CONVERGED 2 +#define MASS_BALANCE 3 + +#define REWRITE 2 +#define INIT -1 + +/* check_line values, plus EMPTY, EOF, OK */ +#define KEYWORD 3 + +/* copy_token values */ +#define EMPTY 2 +#define UPPER 4 +#define LOWER 5 +#define DIGIT 6 +#define UNKNOWN 7 +#define OPTION 8 + +/* species types */ +#define AQ 0 +#define HPLUS 1 +#define H2O 2 +#define EMINUS 3 +#define SOLID 4 +#define EX 5 +#define SURF 6 +#define SURF_PSI 7 +#define SURF_PSI1 8 +#define SURF_PSI2 9 + +/* unknown types */ +#define MB 10 +#define ALK 11 +#define CB 12 +#define SOLUTION_PHASE_BOUNDARY 13 +#define MU 14 +#define AH2O 15 +#define MH 16 +#define MH2O 17 +#define PP 18 +#define EXCH 19 +#define SURFACE 20 +#define SURFACE_CB 21 +#define SURFACE_CB1 22 +#define SURFACE_CB2 23 +#define GAS_MOLES 24 +#define S_S_MOLES 25 +#define PITZER_GAMMA 26 +#define SLACK 28 +/* state */ +#define INITIALIZE 0 +#define INITIAL_SOLUTION 1 +#define INITIAL_EXCHANGE 2 +#define INITIAL_SURFACE 3 +#define INITIAL_GAS_PHASE 4 +#define REACTION 5 +#define INVERSE 6 +#define ADVECTION 7 +#define TRANSPORT 8 +#define PHAST 9 + +/* constaints in mass balance */ +#define EITHER 0 +#define DISSOLVE 1 +#define PRECIPITATE -1 + +/* gas phase type */ +#define PRESSURE 1 +#define VOLUME 2 + +#define MAX_PP_ASSEMBLAGE 10 /* default estimate of the number of phase assemblages */ +#define MAX_ADD_EQUATIONS 20 /* maximum number of equations added together to reduce eqn to + master species */ +#define MAX_ELEMENTS 50 /* default estimate of the number of elements */ +#define MAX_LENGTH 256 /* maximum number of characters component name */ +#define MAX_LINE 4096 /* estimate of maximum line length */ +#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ +#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +#define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ +#define MAX_MASTER 50 /* default estimate of the number of master species */ +#define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in + an equation */ +#define MAX_PHASES 500 /* initial guess of number of phases defined */ +#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ +#define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ +#define MAX_STRINGS 3000 +#define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ +#define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ +#define MAX_SUM_MB 500 /* list used to calculate mass balance sums */ +#define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ +#define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ +#define TOL 1e-9 /* tolerance for comparisons of double numbers */ +#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +#define MIN_TOTAL 1e-25 +#define MIN_TOTAL_SS MIN_TOTAL/100 +#define MIN_RELATED_SURFACE MIN_TOTAL*100 +#define MIN_RELATED_LOG_ACTIVITY -30 +#define REF_PRES_PASCAL 1.01325E5 /* Reference pressure: 1 atm */ +/* + * Hash definitions + */ +# define SegmentSize 256 +# define SegmentSizeShift 8 /* log2(SegmentSize) */ +# define DirectorySize 256 +# define DirectorySizeShift 8 /* log2(DirectorySize) */ +# define Prime1 37 +# define Prime2 1048583 +# define DefaultMaxLoadFactor 5 +// +// Typedefs and structure definitions +// +typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; +typedef enum { cm3_per_mol } DELTA_V_UNIT; +enum SURFACE_TYPE +{ UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC, CCM }; +enum DIFFUSE_LAYER_TYPE +{ NO_DL, BORKOVEK_DL, DONNAN_DL }; +enum SITES_UNITS +{ SITES_ABSOLUTE, SITES_DENSITY }; +enum entity_type +{ Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, + Kinetics, Mix, Temperature, Pressure, UnKnown +}; + +typedef enum { + logK_T0, + delta_h, + T_A1, + T_A2, + T_A3, + T_A4, + T_A5, + T_A6, + delta_v, /* set in calc_delta_v: calculated molar volume-change of the reaction */ + vm_tc, /* set in k_temp: calculated molar volume of the species at tc */ + vm0, /* read: molar volume at tc = 0 */ + vm1, /* read: coef * tc */ + vm2, /* read: coef * tc * tc */ + kappa, /* read: compressibility coef * P */ + MAX_LOG_K_INDICES /* Keep this definition at the end of the enum */ +} LOG_K_INDICES; +/* HSEARCH(3C) */ +typedef struct entry +{ + const char *key; + void *data; +} ENTRY; +typedef enum +{ FIND, ENTER } ACTION; + +/* TSEARCH(3C) */ +typedef enum +{ preorder, postorder, endorder, leaf } VISIT; + +typedef struct Element +{ + /* + ** The user only sees the first two fields, + ** as we pretend to pass back only a pointer to ENTRY. + ** {S}he doesn't know what else is in here. + */ + const char *Key; + char *Data; + struct Element *Next; /* secret from user */ +} Element, *Segment; + +typedef struct +{ + short p; /* Next bucket to be split */ + short maxp; /* upper bound on p during expansion */ + long KeyCount; /* current # keys */ + short SegmentCount; /* current # segments */ + short MinLoadFactor; + short MaxLoadFactor; + Segment *Directory[DirectorySize]; +} HashTable; + +typedef unsigned long Address; + +typedef struct PHRQMemHeader +{ + struct PHRQMemHeader *pNext; /* memory allocated just after this one */ + struct PHRQMemHeader *pPrev; /* memory allocated just prior to this one */ + size_t size; /* memory request + sizeof(PHRQMemHeader) */ +#if !defined(NDEBUG) + char *szFileName; /* file name */ + int nLine; /* line number */ + int dummy; /* alignment */ +#endif +} PHRQMemHeader; + +struct model +{ + int force_prep; + LDBLE temperature; + int count_exchange; + struct master **exchange; + + int count_kinetics; + struct kinetics *kinetics; + + int count_gas_phase; + struct phase **gas_phase; + + int count_ss_assemblage; + const char **ss_assemblage; + + int count_pp_assemblage; + struct phase **pp_assemblage; + const char **add_formula; + LDBLE *si; + + /*int diffuse_layer; */ + /*int edl; */ + enum DIFFUSE_LAYER_TYPE dl_type; + enum SURFACE_TYPE surface_type; + int only_counter_ions; + /*int donnan; */ + LDBLE thickness; + int count_surface_comp; + const char **surface_comp; + int count_surface_charge; + const char **surface_charge; + LDBLE pressure; +}; + + + +struct name_master +{ + const char *name; + struct master *master; +}; +struct name_species +{ + const char *name; + struct species *s; +}; +struct name_phase +{ + const char *name; + struct phase *phase; +}; +struct punch +{ + int in; + int new_def; + struct name_master *totals; + int count_totals; + struct name_species *molalities; + int count_molalities; + struct name_species *activities; + int count_activities; + struct name_phase *pure_phases; + int count_pure_phases; + struct name_phase *si; + int count_si; + struct name_phase *gases; + int count_gases; + struct name_phase *s_s; + int count_s_s; + struct name_phase *kinetics; + int count_kinetics; + struct name_master *isotopes; + int count_isotopes; + struct name_master *calculate_values; + int count_calculate_values; + int inverse; + int sim; + int state; + int soln; + int dist; + int time; + int step; + int rxn; + int temp; + int ph; + int pe; + int alk; + int mu; + int water; + int high_precision; + int user_punch; + int charge_balance; + int percent_error; +}; +/* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ +struct surface +{ + int n_user; + int n_user_end; + int new_def; + /*int diffuse_layer; */ + /*int edl; */ + int only_counter_ions; + /*int donnan; */ + enum DIFFUSE_LAYER_TYPE dl_type; + enum SURFACE_TYPE type; + enum SITES_UNITS sites_units; + LDBLE thickness; + LDBLE debye_lengths; + LDBLE DDL_viscosity; /* viscosity relative to pure water */ + LDBLE DDL_limit; /* limits DDL water to this fraction of bulk water */ + char *description; + int solution_equilibria; + int n_solution; + int count_comps; + struct surface_comp *comps; + int count_charge; + struct surface_charge *charge; + int related_phases; + int related_rate; + int transport; /* transports comp's and charges if true */ +}; +struct surface_comp +{ + const char *formula; + struct elt_list *formula_totals; + LDBLE formula_z; + LDBLE moles; + struct master *master; + struct elt_list *totals; + LDBLE la; + int charge; + LDBLE cb; + const char *phase_name; + LDBLE phase_proportion; + const char *rate_name; + LDBLE Dw; /* diffusion coefficient in water, used in MCD. No transport if 0 */ +}; +struct surface_charge +{ + const char *name; + LDBLE specific_area; + LDBLE grams; + LDBLE charge_balance; + LDBLE mass_water; + struct elt_list *diffuse_layer_totals; + int count_g; + struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ + LDBLE la_psi, la_psi1, la_psi2; + LDBLE psi, psi1, psi2; + LDBLE capacitance[2]; + LDBLE sigma0, sigma1, sigma2, sigmaddl; +}; +struct surface_diff_layer +{ + LDBLE charge; + LDBLE g; + LDBLE dg; + LDBLE psi_to_z; +}; + +struct Change_Surf +{ + const char *comp_name; + LDBLE fraction; + const char *new_comp_name; + LDBLE new_Dw; + int cell_no; + int next; +}; + +struct Charge_Group +{ + LDBLE z; + LDBLE eq; +}; +/* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ +struct kinetics +{ + int n_user; + int n_user_end; + char *description; + int count_comps; + struct kinetics_comp *comps; + int count_steps; + LDBLE *steps; + LDBLE step_divide; + /*char *units; */ + struct elt_list *totals; + int rk; + int bad_step_max; + int use_cvode; + int cvode_order; + int cvode_steps; +}; +struct kinetics_comp +{ + const char *rate_name; + struct name_coef *list; + int count_list; + /* struct phase *phase; */ + LDBLE tol; + LDBLE m; + LDBLE initial_moles; + LDBLE m0; + LDBLE moles; + int count_c_params; + const char **c_params; + int count_d_params; + LDBLE *d_params; +}; + +/*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ +struct save_values +{ + LDBLE value; + int count_subscripts; + int *subscripts; +}; + +struct save +{ + int solution; + int n_solution_user; + int n_solution_user_end; + int mix; + int n_mix_user; + int n_mix_user_end; + int reaction; + int n_reaction_user; + int n_reaction_user_end; + int pp_assemblage; + int n_pp_assemblage_user; + int n_pp_assemblage_user_end; + int exchange; + int n_exchange_user; + int n_exchange_user_end; + int kinetics; + int n_kinetics_user; + int n_kinetics_user_end; + int surface; + int n_surface_user; + int n_surface_user_end; + int gas_phase; + int n_gas_phase_user; + int n_gas_phase_user_end; + int ss_assemblage; + int n_ss_assemblage_user; + int n_ss_assemblage_user_end; +}; +#ifdef SKIP +/*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ +struct Use +{ + int solution_in; + int n_solution_user; + int n_solution; + struct solution *solution_ptr; + + int pp_assemblage_in; + int n_pp_assemblage_user; + //int n_pp_assemblage; + //struct pp_assemblage *pp_assemblage_ptr; + void *pp_assemblage_ptr; + + int mix_in; + int n_mix_user; + int n_mix; + //struct mix *mix_ptr; + void * mix_ptr; + int n_mix_user_orig; + + int reaction_in; + int n_reaction_user; + //int n_irrev; + //struct irrev *irrev_ptr; + void * reaction_ptr; + + int exchange_in; + int n_exchange_user; + //int n_exchange; + //struct exchange *exchange_ptr; + void * exchange_ptr; + + int kinetics_in; + int n_kinetics_user; + int n_kinetics; + struct kinetics *kinetics_ptr; + + int surface_in; + int n_surface_user; + int n_surface; + struct surface *surface_ptr; + + int pressure_in; + int n_pressure_user; + void *pressure_ptr; + + int temperature_in; + int n_temperature_user; + void *temperature_ptr; + + int inverse_in; + int n_inverse_user; + int n_inverse; + struct inverse *inverse_ptr; + + int gas_phase_in; + int n_gas_phase_user; + //int n_gas_phase; + //struct gas_phase *gas_phase_ptr; + void * gas_phase_ptr; + + int ss_assemblage_in; + int n_ss_assemblage_user; + int n_ss_assemblage; + struct ss_assemblage *ss_assemblage_ptr; + + int trans_in; + int advect_in; +}; +#endif +/*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ +struct copier +{ + int count; + int max; + int *n_user; + int *start; + int *end; +}; + +/*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ +struct inverse +{ + int n_user; + char *description; + int new_def; + int minimal; + int range; + int mp; + LDBLE mp_censor; + LDBLE range_max; + LDBLE tolerance; + LDBLE mp_tolerance; + int count_uncertainties; + LDBLE *uncertainties; + int count_ph_uncertainties; + LDBLE *ph_uncertainties; + LDBLE water_uncertainty; + int mineral_water; + int carbon; + LDBLE *dalk_dph; + LDBLE *dalk_dc; + int count_solns; + int *solns; + int count_force_solns; + int *force_solns; + int count_elts; + struct inv_elts *elts; + int count_phases; + struct inv_phases *phases; + int count_master_list; + struct master **master_list; + int count_redox_rxns; + int count_isotopes; + struct inv_isotope *isotopes; + int count_i_u; + struct inv_isotope *i_u; + int count_isotope_unknowns; + struct isotope *isotope_unknowns; + const char *netpath; + const char *pat; +}; +struct inv_elts +{ + const char *name; + struct master *master; + int row; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_isotope +{ + const char *isotope_name; + LDBLE isotope_number; + const char *elt_name; + int count_uncertainties; + LDBLE *uncertainties; +}; +struct inv_phases +{ + const char *name; + struct phase *phase; + int column; + int constraint; + int force; + int count_isotopes; + struct isotope *isotopes; +}; +struct name_coef +{ + const char *name; + LDBLE coef; +}; +/*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ +struct ss_assemblage +{ + int n_user; + int n_user_end; + char *description; + int new_def; + /* int type; */ + /* int solution_equilibria; */ + /* int n_solution; */ + int count_s_s; + struct s_s *s_s; +}; +struct s_s +{ + const char *name; + struct s_s_comp *comps; + int count_comps; + LDBLE total_moles; + LDBLE dn; + LDBLE a0, a1; + LDBLE ag0, ag1; + int s_s_in; + int miscibility; + int spinodal; + LDBLE tk, xb1, xb2; + int input_case; + LDBLE p[4]; +}; +struct s_s_comp +{ + const char *name; + struct phase *phase; + LDBLE initial_moles; + LDBLE moles; + LDBLE init_moles; + LDBLE delta; + LDBLE fraction_x; + LDBLE log10_lambda; + LDBLE log10_fraction_x; + LDBLE dn, dnc, dnb; +}; +#ifdef SKIP +/*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + struct pp_assemblage + { + int n_user; + int n_user_end; + char *description; + int new_def; + struct elt_list *next_elt; + int count_comps; + struct pure_phase *pure_phases; + }; + struct pure_phase + { + struct phase *phase; + const char *name; + const char *add_formula; + LDBLE si; + LDBLE si_org; + LDBLE moles; + LDBLE delta; + LDBLE initial_moles; + int force_equality; + int dissolve_only; + int precipitate_only; +}; +#endif +/*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ +struct species_list +{ + struct species *master_s; + struct species *s; + LDBLE coef; +}; + +/*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ +struct list0 +{ + LDBLE *target; + LDBLE coef; +}; +struct list1 +{ + LDBLE *source; + LDBLE *target; +}; +struct list2 +{ + LDBLE *source; + LDBLE *target; + LDBLE coef; +}; + +/*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + struct solution + { + int new_def; + int n_user; + int n_user_end; + char *description; + LDBLE tc; + LDBLE ph; + LDBLE solution_pe; + LDBLE mu; + LDBLE ah2o; + LDBLE density; + LDBLE total_h; + LDBLE total_o; + LDBLE cb; + LDBLE mass_water; + LDBLE total_alkalinity; + const char *units; + struct pe_data *pe; + int default_pe; + struct conc *totals; + struct master_activity *master_activity; + int count_master_activity; + int count_isotopes; + struct isotope *isotopes; + struct master_activity *species_gamma; + int count_species_gamma; + LDBLE patm; + }; + struct master_activity + { + const char *description; + LDBLE la; + }; + struct conc + { + const char *description; + /*int skip; */ + LDBLE moles; + LDBLE input_conc; + const char *units; + const char *equation_name; + struct phase *phase; + LDBLE phase_si; + int n_pe; + const char *as; + LDBLE gfw; + }; + struct pe_data + { + const char *name; + struct reaction *rxn; + }; + struct isotope + { + LDBLE isotope_number; + const char *elt_name; + const char *isotope_name; + LDBLE total; + LDBLE ratio; + LDBLE ratio_uncertainty; + LDBLE x_ratio_uncertainty; + struct master *master; + struct master *primary; + LDBLE coef; /* coefficient of element in phase */ +}; +struct iso +{ + const char *name; + LDBLE value; + LDBLE uncertainty; +}; +/*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ +struct stag_data +{ + int count_stag; + LDBLE exch_f; + LDBLE th_m; + LDBLE th_im; +}; +struct cell_data +{ + LDBLE length; + LDBLE mid_cell_x; + LDBLE disp; + LDBLE temp; + LDBLE por; /* free (uncharged) porewater porosities */ + LDBLE por_il; /* interlayer water porosities */ + int punch; + int print; +}; + +/*---------------------------------------------------------------------- + * Keywords + *---------------------------------------------------------------------- */ + struct key + { + char *name; + int keycount; + }; + struct const_key + { + const char *name; + int keycount; +}; + +/*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ +struct element +{ + const char *name; /* element name */ + /* int in; */ + struct master *master; + struct master *primary; + LDBLE gfw; +}; +/*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ +struct elt_list +{ /* list of name and number of elements in an equation */ + struct element *elt; /* pointer to element structure */ + LDBLE coef; /* number of element e's in eqn */ +}; +/*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ +struct reaction +{ + LDBLE logk[MAX_LOG_K_INDICES]; + LDBLE dz[3]; + struct rxn_token *token; +}; +struct rxn_token +{ + struct species *s; + LDBLE coef; + const char *name; +}; +/*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ +struct species +{ /* all data pertinent to an aqueous species */ + const char *name; /* name of species */ + const char *mole_balance; /* formula for mole balance */ + int in; /* species used in model if TRUE */ + int number; + struct master *primary; /* points to master species list, NULL if not primary master */ + struct master *secondary; /* points to master species list, NULL if not secondary master */ + LDBLE gfw; /* gram formula wt of species */ + LDBLE z; /* charge of species */ + LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */ + LDBLE erm_ddl; /* enrichment factor in DDL */ + LDBLE equiv; /* equivalents in exchange species */ + LDBLE alk; /* alkalinity of species, used for cec in exchange */ + LDBLE carbon; /* stoichiometric coefficient of carbon in species */ + LDBLE co2; /* stoichiometric coefficient of C(4) in species */ + LDBLE h; /* stoichiometric coefficient of H in species */ + LDBLE o; /* stoichiometric coefficient of O in species */ + LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analytical expression */ +/* VP: Density Start */ + LDBLE millero[6]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ +/* VP: Density End */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + struct name_coef *add_logk; + LDBLE lg; /* log10 activity coefficient, gamma */ + LDBLE lg_pitzer; /* log10 activity coefficient, from pitzer calculation */ + LDBLE lm; /* log10 molality */ + LDBLE la; /* log10 activity */ + LDBLE dg; /* gamma term for jacobian */ + LDBLE dg_total_g; + LDBLE moles; /* moles in solution; moles/mass_water = molality */ + int type; /* flag indicating presence in model and types of equations */ + int gflag; /* flag for preferred activity coef eqn */ + int exch_gflag; /* flag for preferred activity coef eqn */ + struct elt_list *next_elt; /* pointer to next element */ + struct elt_list *next_secondary; + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ + LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ + struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each + surface */ + LDBLE cd_music[5]; + LDBLE dz[3]; + DELTA_V_UNIT original_deltav_units; +}; +struct logk +{ /* Named log K's */ + const char *name; /* name of species */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE log_k[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + int count_add_logk; + int done; + struct name_coef *add_logk; + LDBLE log_k_original[MAX_LOG_K_INDICES]; /* log kt0, delh, 5 coefficients analalytical expression */ + DELTA_V_UNIT original_deltav_units; +}; +struct species_diff_layer +{ + struct surface_charge *charge; + int count_g; + LDBLE g_moles; + LDBLE dg_g_moles; /* g_moles*dgterm */ + LDBLE dx_moles; + LDBLE dh2o_moles; /* moles*g*Ws/Waq */ + LDBLE drelated_moles; /* for related phase */ +}; + +/*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ +struct phase +{ /* all data pertinent to a pure solid phase */ + const char *name; /* name of species */ + const char *formula; /* chemical formula */ + int in; /* species used in model if TRUE */ + LDBLE lk; /* log10 k at working temperature */ + LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analalytical expression */ + DELTA_H_UNIT original_units; /* enum with original delta H units */ + DELTA_V_UNIT original_deltav_units; + int count_add_logk; + struct name_coef *add_logk; + LDBLE moles_x; + LDBLE delta_max; + LDBLE p_soln_x; + LDBLE fraction_x; + LDBLE log10_lambda, log10_fraction_x; + LDBLE dn, dnb, dnc; + LDBLE gn, gntot; + LDBLE gn_n, gntot_n; + LDBLE t_c, p_c, omega; /* gas: critical TK, critical P(atm), Pitzer acentric coeff */ + LDBLE pr_a, pr_b, pr_alpha; /* Peng-Robinson parm's */ + LDBLE pr_tk, pr_p; /* Temperature (K), Pressure (atm) */ + LDBLE pr_phi; /* fugacity coefficient (-) */ + LDBLE pr_aa_sum2; /* for calculating multicomponent phi */ + LDBLE delta_v[9]; /* delta_v[0] = [1] + [2]*T + [3]/T + [4]*log10(T) + [5]/T^2 + [6]*T^2 + [7]*P */ + LDBLE pr_si_f; /* si adapter: log10(phi) - delta_v[0] * (P - 1) /RT */ + bool pr_in; /* Peng-Robinson in the calc's, or not */ + + int type; /* flag indicating presence in model and types of equations */ + struct elt_list *next_elt; /* pointer to list of elements in phase */ + struct elt_list *next_sys_total; + int check_equation; /* switch to check equation for charge and element balance */ + struct reaction *rxn; /* pointer to data base reaction */ + struct reaction *rxn_s; /* pointer to reaction converted to secondary and primary + master species */ + struct reaction *rxn_x; /* reaction to be used in model */ + int replaced; /* equation contains solids or gases */ + int in_system; +}; +/*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + struct master + { /* list of name and number of elements in an equation */ + int in; /* TRUE if in model, FALSE if out, REWRITE if other mb eq */ + int number; /* sequence number in list of masters */ + int last_model; /* saved to determine if model has changed */ + int type; /* AQ or EX */ + int primary; /* TRUE if master species is primary */ + LDBLE coef; /* coefficient of element in master species */ + LDBLE total; /* total concentration for element or valence state */ + LDBLE isotope_ratio; + LDBLE isotope_ratio_uncertainty; + int isotope; + LDBLE total_primary; + /* LDBLE la; */ /* initial guess of master species log activity */ + struct element *elt; /* element structure */ + LDBLE alk; /* alkalinity of species */ + LDBLE gfw; /* default gfw for species */ + const char *gfw_formula; /* formula from which to calcuate gfw */ + struct unknown *unknown; /* pointer to unknown structure */ + struct species *s; /* pointer to species structure */ + struct reaction *rxn_primary; /* reaction writes master species in terms of primary + master species */ + struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary + master species */ + struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points + to location */ + int minor_isotope; +}; +/*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ +struct unknown +{ + int type; + LDBLE moles; + LDBLE ln_moles; + LDBLE f; + LDBLE sum; + LDBLE delta; + LDBLE la; + int number; + const char *description; + struct master **master; + struct phase *phase; + LDBLE si; + //struct gas_phase *gas_phase; + int n_gas_phase_user; + struct conc *total; + struct species *s; + //struct exch_comp *exch_comp; + const char * exch_comp; + //struct pure_phase *pure_phase; + const char *pp_assemblage_comp_name; + struct s_s *s_s; + struct s_s_comp *s_s_comp; + int s_s_comp_number; + int s_s_in; + struct surface_comp *surface_comp; + LDBLE related_moles; + struct unknown *potential_unknown, *potential_unknown1, + *potential_unknown2; + int count_comp_unknowns; + struct unknown **comp_unknowns; /* list for CD_MUSIC of comps that contribute to 0 plane mass-balance term */ + struct unknown *phase_unknown; + struct surface_charge *surface_charge; + LDBLE mass_water; + int dissolve_only; + LDBLE inert_moles; + LDBLE V_m; + LDBLE pressure; + int mb_number; +}; + +/*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ +struct reaction_temp +{ + LDBLE logk[MAX_LOG_K_INDICES]; + LDBLE dz[3]; + struct rxn_token_temp *token; +}; +struct rxn_token_temp +{ /* data for equations, aq. species or minerals */ + const char *name; /* pointer to a species name (formula) */ + LDBLE z; /* charge on species */ + struct species *s; + struct unknown *unknown; + LDBLE coef; /* coefficient of species name */ +}; +struct unknown_list +{ + struct unknown *unknown; + LDBLE *source; + LDBLE *gamma_source; + /* int row; */ + /* int col; */ + LDBLE coef; +}; +/* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ +struct prints +{ + int all; + int initial_solutions; + int initial_exchangers; + int reactions; + int gas_phase; + int ss_assemblage; + int pp_assemblage; + int surface; + int exchange; + int kinetics; + int totals; + int eh; + int species; + int saturation_indices; + int irrev; + int mix; + int reaction; + int use; + int logfile; + int punch; + int status; + int inverse; + int dump; + int user_print; + int headings; + int user_graph; + int echo_input; + int warnings; + int initial_isotopes; + int isotope_ratios; + int isotope_alphas; + int hdf; + int alkalinity; +}; +/* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ +struct rate +{ + const char *name; + char *commands; + int new_def; + void *linebase; + void *varbase; + void *loopbase; +}; +/* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ +struct spread_row +{ + int count; + int empty, string, number; + char **char_vector; + LDBLE *d_vector; + int *type_vector; +}; +struct defaults +{ + LDBLE temp; + LDBLE density; + const char *units; + const char *redox; + LDBLE ph; + LDBLE pe; + LDBLE water; + int count_iso; + struct iso *iso; + LDBLE pressure; /* pressure in atm */ +}; +struct spread_sheet +{ + struct spread_row *heading; + struct spread_row *units; + int count_rows; + struct spread_row **rows; + struct defaults defaults; +}; +/* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ +struct master_isotope +{ + const char *name; + struct master *master; + struct element *elt; + const char *units; + LDBLE standard; + LDBLE ratio; + LDBLE moles; + int total_is_major; + int minor_isotope; +}; +struct calculate_value +{ + const char *name; + LDBLE value; + char *commands; + int new_def; + int calculated; + void *linebase; + void *varbase; + void *loopbase; +}; +struct isotope_ratio +{ + const char *name; + const char *isotope_name; + LDBLE ratio; + LDBLE converted_ratio; +}; +struct isotope_alpha +{ + const char *name; + const char *named_logk; + LDBLE value; +}; +struct system_species +{ + char *name; + char *type; + LDBLE moles; +}; + +/* tally.c ------------------------------- */ +struct tally_buffer +{ + const char *name; + struct master *master; + LDBLE moles; + LDBLE gfw; +}; +struct tally +{ + const char *name; + enum entity_type type; + const char *add_formula; + LDBLE moles; + struct elt_list *formula; + /* + * first total is initial + * second total is final + * third total is difference (final - initial) + */ + struct tally_buffer *total[3]; +}; + +/* transport.c ------------------------------- */ +struct spec +{ + const char *name; /* name of species */ + const char *aq_name; /* name of aqueous species in EX species */ + int type; /* type: AQ or EX */ + LDBLE a; /* activity */ + LDBLE lm; /* log(concentration) */ + LDBLE lg; /* log(gamma) */ + LDBLE c; /* concentration for AQ, equivalent fraction for EX */ + LDBLE z; /* charge number */ + LDBLE Dwt; /* temperature corrected free water diffusion coefficient, m2/s */ + LDBLE erm_ddl; /* enrichment factor in ddl */ +}; +struct sol_D +{ + int count_spec; /* number of aqueous + exchange species */ + int count_exch_spec; /* number of exchange species */ + LDBLE exch_total, x_max; /* total moles of X-, max X- in transport step in sol_D[1] */ + struct spec *spec; +}; +struct J_ij +{ + const char *name; + LDBLE tot1, tot2; +}; +struct M_S +{ + const char *name; + LDBLE tot1, tot2; +}; +// Pitzer definitions +typedef enum +{ TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, + TYPE_PSI, TYPE_ETHETA, TYPE_ALPHAS, TYPE_MU, TYPE_ETA, TYPE_Other, + TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU +} pitz_param_type; + +struct pitz_param +{ + const char *species[3]; + int ispec[3]; + pitz_param_type type; + LDBLE p; + union + { + LDBLE b0; + LDBLE b1; + LDBLE b2; + LDBLE c0; + LDBLE theta; + LDBLE lamda; + LDBLE zeta; + LDBLE psi; + LDBLE alphas; + LDBLE mu; + LDBLE eta; + LDBLE eps; + LDBLE eps1; + } U; + LDBLE a[6]; + LDBLE alpha; + LDBLE os_coef; + LDBLE ln_coef[3]; + struct theta_param *thetas; +}; + +struct theta_param +{ + LDBLE zj; + LDBLE zk; + LDBLE etheta; + LDBLE ethetap; +}; + +#endif /* _INC_GLOBAL_STRUCTURES_H */ + diff --git a/rename_cpp/input.cpp b/rename_cpp/input.cpp new file mode 100644 index 00000000..7622fe97 --- /dev/null +++ b/rename_cpp/input.cpp @@ -0,0 +1,127 @@ +#include +#include "Utils.h" +#include "Phreeqc.h" +#include +#include +#include "phqalloc.h" + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +set_reading_database(int reading_database) +/* ---------------------------------------------------------------------- */ +{ + reading_db = reading_database; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reading_database(void) +/* ---------------------------------------------------------------------- */ +{ + return reading_db; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print) +/* ---------------------------------------------------------------------- */ +{ + //assert(get_istream() != NULL); + if (phrq_io->get_istream() == NULL) + return EOF; + if (reading_database()) + print = FALSE; + return check_line_impl(string, allow_empty, allow_eof, allow_keyword, + print); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_line_impl(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function gets a new line and checks for empty, eof, and keywords. + * + * Arguments: + * string Input, character string used in printing error message + * allow_empty Input, True or false, if a blank line is accepable + * if false, another line is read + * allow_eof Input, True or false, if EOF is acceptable + * allow_keyword Input, True or false, if a keyword is acceptable + * + * Returns: + * EMPTY if empty line read and allow_empty == true + * KEYWORD if line begins with keyword + * EOF if eof and allow_eof == true + * OK otherwise + * OPTION if line begins with -[alpha] + * + * Terminates if EOF and allow_eof == false. + */ + int i; + + +/* Get line */ + do + { + i = get_line(); + if ((print == TRUE && i != EOF) || i == KEYWORD) + { + echo_msg(sformatf( "\t%s\n", line_save)); + } + } + while (i == EMPTY && allow_empty == FALSE); +/* Check eof */ + if (i == EOF && allow_eof == FALSE) + { + error_string = sformatf( + "Unexpected eof while reading %s\nExecution terminated.\n", + string); + error_msg(error_string, STOP); + } +/* Check keyword */ + if (i == KEYWORD && allow_keyword == FALSE) + { + error_string = sformatf( + "Expected data for %s, but got a keyword ending data block.", + string); + error_msg(error_string, CONTINUE); + input_error++; + } + check_line_return = i; + return (i); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_line(void) +/* ---------------------------------------------------------------------- */ +{ + PHRQ_io::LINE_TYPE j = phrq_io->get_line(); + // check_key sets next_keyword + //int return_value = check_key(parser.line().c_str()); + next_keyword = phrq_io->Get_m_next_keyword(); + + + // copy parser line to line and line_save + // make sure there is enough space + size_t l1 = strlen(phrq_io->Get_m_line().c_str()) + 1; + size_t l2 = strlen(phrq_io->Get_m_line_save().c_str()) + 1; + size_t l = (l1 > l2) ? l1 : l2; + if (l >= (size_t) max_line) + { + max_line = l * 2; + line_save = (char *) PHRQ_realloc(line_save, + (size_t) max_line * sizeof(char)); + if (line_save == NULL) + malloc_error(); + line = (char *) PHRQ_realloc(line, (size_t) max_line * sizeof(char)); + if (line == NULL) + malloc_error(); + } + strcpy(line, phrq_io->Get_m_line().c_str()); + strcpy(line_save, phrq_io->Get_m_line_save().c_str()); + return j; +} diff --git a/rename_cpp/integrate.cpp b/rename_cpp/integrate.cpp new file mode 100644 index 00000000..a8f88865 --- /dev/null +++ b/rename_cpp/integrate.cpp @@ -0,0 +1,1247 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + + +#define MAX_QUAD 20 +#define K_POLY 5 + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_all_g(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int converge, converge1; + int count_g, count_charge; + LDBLE new_g, xd1; + LDBLE epsilon; + + if (use.Get_surface_ptr() == NULL) + return (OK); +/* + * calculate g for each surface + */ + epsilon = convergence_tolerance; + if (convergence_tolerance >= 1e-8) + { + G_TOL = 1e-9; + } + else + { + G_TOL = 1e-10; + } + + converge = TRUE; + count_charge = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + if (debug_diffuse_layer == TRUE) + output_msg(sformatf( "Calc_all_g, X[%d]\n", j)); + surface_charge_ptr = x[j]->surface_charge; + count_g = 1; + x[j]->surface_charge->g[0].charge = 0.0; + x[j]->surface_charge->g[0].g = 0.0; + x[j]->surface_charge->g[0].dg = 0.0; + xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); + /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + /* 1000 J/kJ and 1000 L/m**3 */ + alpha = + sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * + tk_x * 0.5); +/* + * calculate g for given surface for each species + */ + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS) + continue; + for (k = 0; k < count_g; k++) + { + if (equal + (x[j]->surface_charge->g[k].charge, s_x[i]->z, + G_TOL) == TRUE) + { + s_x[i]->diff_layer[count_charge].charge = + x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + break; + } + } + if (k < count_g) + continue; + + if (x[j]->surface_charge->grams > 0.0) + { + z = s_x[i]->z; + if ((use.Get_surface_ptr()->only_counter_ions == FALSE) || + (((x[j]->master[0]->s->la > 0) && (z < 0)) + || ((x[j]->master[0]->s->la < 0) && (z > 0)))) + { + if (xd > 0.1) + { + new_g = qromb_midpnt(1.0, xd); + } + else if (xd > 0.01) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, xd); + } + else if (xd > 0.001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, xd); + } + else if (xd > 0.0001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, xd); + } + else if (xd > 0.00001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, .0001); + new_g += qromb_midpnt(0.0001, xd); + } + else if (xd > 0.000001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, .0001); + new_g += qromb_midpnt(0.0001, .00001); + new_g += qromb_midpnt(0.00001, xd); + } + else if (xd > 0.0000001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, .0001); + new_g += qromb_midpnt(0.0001, .00001); + new_g += qromb_midpnt(0.00001, .000001); + new_g += qromb_midpnt(0.000001, xd); + } + else if (xd > 0.00000001) + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, .0001); + new_g += qromb_midpnt(0.0001, .00001); + new_g += qromb_midpnt(0.00001, .000001); + new_g += qromb_midpnt(0.000001, .0000001); + new_g += qromb_midpnt(0.0000001, xd); + } + else + { + new_g = qromb_midpnt(1.0, 0.1); + new_g += qromb_midpnt(0.1, 0.01); + new_g += qromb_midpnt(0.01, .001); + new_g += qromb_midpnt(0.001, .0001); + new_g += qromb_midpnt(0.0001, .00001); + new_g += qromb_midpnt(0.00001, .000001); + new_g += qromb_midpnt(0.000001, .0000001); + new_g += qromb_midpnt(0.0000001, .00000001); + new_g += qromb_midpnt(0.00000001, xd); + } + } + else + { + new_g = 0; + } + } + else + { + new_g = 0.0; + } + if ((use.Get_surface_ptr()->only_counter_ions == TRUE) && new_g < 0) + new_g = 0; + x[j]->surface_charge->g[count_g].charge = s_x[i]->z; + converge1 = TRUE; + if (fabs(new_g) >= 1.) + { + if (fabs + ((new_g - x[j]->surface_charge->g[count_g].g) / new_g) > + epsilon) + { + converge1 = FALSE; + } + } + else + { + if (fabs(new_g - x[j]->surface_charge->g[count_g].g) > + epsilon) + { + converge1 = FALSE; + } + } + if (converge1 == FALSE) + { + converge = FALSE; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[count_g]. + charge, + (double) x[j]->surface_charge->g[count_g].g, + (double) new_g, + (double) (new_g - + x[j]->surface_charge->g[count_g].g))); + } + } + x[j]->surface_charge->g[count_g].g = new_g; + if (new_g == 0) + { + x[j]->surface_charge->g[count_g].dg = 0; + } + else + { + if (x[j]->surface_charge->grams > 0.0) + { + x[j]->surface_charge->g[count_g].dg = + surface_charge_ptr->grams * + surface_charge_ptr->specific_area * alpha * + g_function(xd) / F_C_MOL; + x[j]->surface_charge->g[count_g].dg *= + -2. / (exp(x[j]->master[0]->s->la * LOG_10) * + exp(x[j]->master[0]->s->la * LOG_10)); + if ((xd - 1) < 0.0) + { + x[j]->surface_charge->g[count_g].dg *= -1.0; + } + if (fabs(x[j]->surface_charge->g[count_g].dg) < 1e-8) + { + xd1 = exp(-2 * 1e-3 * LOG_10); + + + new_g = qromb_midpnt(1.0, xd1); + x[j]->surface_charge->g[count_g].dg = new_g / .001; + } + } + else + { + x[j]->surface_charge->g[count_g].dg = 0.0; + } + } + s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = count_g; + count_g++; + + } + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "\nSurface component %d: charge,\tg,\tdg/dlny,\txd\n", + count_charge)); + for (i = 0; i < count_g; i++) + { + output_msg(sformatf( + "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg, + (double) xd)); + } + } + count_charge++; + } + return (converge); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +g_function(LDBLE x_value) +/* ---------------------------------------------------------------------- */ +{ + LDBLE sum, return_value, sum1; + int i, j; + LDBLE ln_x_value; + + if (equal(x_value, 1.0, G_TOL * 100) == TRUE) + return (0.0); + sum = 0.0; + ln_x_value = log(x_value); + for (j = 0; j < use.Get_surface_ptr()->charge[0].count_g; j++) + { + use.Get_surface_ptr()->charge[0].g[j].psi_to_z = + exp(ln_x_value * use.Get_surface_ptr()->charge[0].g[j].charge) - 1.0; + } + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type < H2O && s_x[i]->z != 0.0) + { + for (j = 0; j < use.Get_surface_ptr()->charge[0].count_g; j++) + { + if (use.Get_surface_ptr()->charge[0].g[j].charge == s_x[i]->z) + { + sum += + s_x[i]->moles * + use.Get_surface_ptr()->charge[0].g[j].psi_to_z; + break; + } + } + } + } + if (sum < 0.0) + { + sum = 0.0; + sum1 = 0.0; + output_msg(sformatf( + "Species\tmoles\tX**z-1\tsum\tsum charge\n")); + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type < H2O && s_x[i]->z != 0.0) + { + sum += s_x[i]->moles * (pow(x_value, s_x[i]->z) - 1.0); + sum1 += s_x[i]->moles * s_x[i]->z; + output_msg(sformatf( "%s\t%e\t%e\t%e\t%e\n", + s_x[i]->name, (double) s_x[i]->moles, + (double) (pow((LDBLE) x_value, (LDBLE) s_x[i]->z) - + 1.0), (double) sum, (double) sum1)); + } + } + error_string = sformatf( "Negative sum in g_function, %e\t%e.", + (double) sum, (double) x_value); + error_msg(error_string, CONTINUE); + error_string = sformatf( + "Solutions must be charge balanced, charge imbalance is %e\n", + (double) sum1); + error_msg(error_string, STOP); + } + + return_value = + (exp(ln_x_value * z) - + 1) / sqrt((x_value * x_value * mass_water_aq_x * sum)); + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy) +/* ---------------------------------------------------------------------- */ +{ + int i, m, ns; + LDBLE den, dif, dift, ho, hp, w; + LDBLE *c, *d; + + ns = 1; + dif = fabs(xv - xa[1]); +/* + * Malloc work space + */ + c = (LDBLE *) PHRQ_malloc((size_t) (n + 1) * sizeof(LDBLE)); + if (c == NULL) + malloc_error(); + d = (LDBLE *) PHRQ_malloc((size_t) (n + 1) * sizeof(LDBLE)); + if (d == NULL) + malloc_error(); + + + + for (i = 1; i <= n; i++) + { + dift = fabs(xv - xa[i]); + if (dift < dif) + { + ns = i; + dif = dift; + } + c[i] = ya[i]; + d[i] = ya[i]; + } + + *yv = ya[ns--]; + for (m = 1; m < n; m++) + { + for (i = 1; i <= n - m; i++) + { + ho = xa[i] - xv; + hp = xa[i + m] - xv; + w = c[i + 1] - d[i]; + if ((den = ho - hp) == 0.0) + { + error_msg("In subroutine polint.", STOP); + } + den = w / den; + d[i] = hp * den; + c[i] = ho * den; + } + if (2 * ns < (n - m)) + { + *dy = c[ns + 1]; + } + else + { + *dy = d[ns--]; + } + *yv += *dy; + +/* *yv += (*dy = (2 * ns < (n-m) ? c[ns+1] : d[ns--])); */ + } + c = (LDBLE *) free_check_null(c); + d = (LDBLE *) free_check_null(d); + return; +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +midpnt(LDBLE x1, LDBLE x2, int n) +/* ---------------------------------------------------------------------- */ +{ + LDBLE xv, tnm, sum, del, ddel; + int it, j; + + if (n == 1) + { + midpoint_sv = (x2 - x1) * g_function(0.5 * (x1 + x2)); + return (midpoint_sv); + } + else + { + for (it = 1, j = 1; j < n - 1; j++) + it *= 3; + tnm = (LDBLE) it; + del = (x2 - x1) / (3 * tnm); + ddel = del + del; + xv = x1 + 0.5 * del; + sum = 0.0; + for (j = 1; j <= it; j++) + { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == + WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + sum += g_function(xv); + xv += ddel; + sum += g_function(xv); + xv += del; + } + midpoint_sv = (midpoint_sv + (x2 - x1) * sum / tnm) / 3.0; + return midpoint_sv; + } +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +qromb_midpnt(LDBLE x1, LDBLE x2) +/* ---------------------------------------------------------------------- */ +{ + LDBLE ss, dss; + LDBLE sv[MAX_QUAD + 2], h[MAX_QUAD + 2]; + int j; + + h[0] = 1.0; + sv[0] = midpnt(x1, x2, 1); + for (j = 1; j < MAX_QUAD; j++) + { + sv[j] = midpnt(x1, x2, j + 1); + h[j] = h[j - 1] / 9.0; + + if (fabs(sv[j] - sv[j - 1]) <= G_TOL * fabs(sv[j])) + { + sv[j] *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + if ((x2 - 1) < 0.0) + sv[j] *= -1.0; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "Iterations in qromb_midpnt: %d\n", j)); + } + return (sv[j]); + } + + if (j >= K_POLY - 1) + { + polint(&h[j - K_POLY], &sv[j - K_POLY], K_POLY, 0.0, &ss, &dss); + if (fabs(dss) <= G_TOL * fabs(ss) || fabs(dss) < G_TOL) + { + ss *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + if ((x2 - 1) < 0.0) + ss *= -1.0; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "Iterations in qromb_midpnt: %d\n", j)); + } + return (ss); + } + } + + } + error_string = sformatf( + "\nToo many iterations integrating diffuse layer.\n"); + error_msg(error_string, STOP); + return (-999.9); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_init_g(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge; + + if (use.Get_surface_ptr() == NULL) + return (OK); + +/* + * calculate g for each surface + */ + count_charge = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + surface_charge_ptr = x[j]->surface_charge; + count_g = 0; + if (x[j]->surface_charge->g != NULL) + { + count_g = x[j]->surface_charge->count_g; + } + if (count_g == 0) + { + x[j]->surface_charge->g = + (struct surface_diff_layer *) PHRQ_malloc((size_t) + sizeof(struct + surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) + malloc_error(); + x[j]->surface_charge->g[0].charge = 0.0; + x[j]->surface_charge->g[0].g = 0.0; + x[j]->surface_charge->g[0].dg = 0.0; + xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); + /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + /* second 1000 is liters/m**3 */ + alpha = + sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + 1000.0 * tk_x * 0.5); + } +/* + * calculate g for given surface for each species + */ + count_g = 1; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS) + continue; + for (k = 0; k < count_g; k++) + { + if (equal + (x[j]->surface_charge->g[k].charge, s_x[i]->z, + G_TOL) == TRUE) + { + s_x[i]->diff_layer[count_charge].charge = + x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + break; + } + } + if (k >= count_g) + { + + /* malloc space to save g for charge */ + x[j]->surface_charge->g = + (struct surface_diff_layer *) PHRQ_realloc(x[j]-> + surface_charge-> + g, + (size_t) + (count_g + + 1) * + sizeof(struct + surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) + malloc_error(); + + /* save g for charge */ + x[j]->surface_charge->g[count_g].charge = s_x[i]->z; + if (x[j]->surface_charge->grams > 0.0) + { + x[j]->surface_charge->g[count_g].g = + 2 * alpha * sqrt(mu_x) * (pow(xd, s_x[i]->z / 2.0) - + 1) * + surface_charge_ptr->grams * + surface_charge_ptr->specific_area / F_C_MOL; + x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; + if ((use.Get_surface_ptr()->only_counter_ions == TRUE) && + x[j]->surface_charge->g[count_g].g < 0) + { + x[j]->surface_charge->g[count_g].g = 0; + x[j]->surface_charge->g[count_g].dg = 0; + } + } + else + { + x[j]->surface_charge->g[count_g].g = 0.0; + x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; + } + /* save g for species */ + s_x[i]->diff_layer[count_charge].charge = + x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = count_g; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + count_g++; + } + } + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "\nSurface component %d: charge,\tg,\tdg\n", + count_charge)); + for (i = 0; i < count_g; i++) + { + output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg)); + } + } + count_charge++; + x[j]->surface_charge->count_g = count_g; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_surface_water(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * In initial surface calculation, need to calculate + * mass of water in diffuse layer. + * diffuse layer water + aqueous solution water = bulk water. + * Ionic strength is fixed, so diffuse-layer water will not change + */ + int i; + LDBLE debye_length, b, r, rd, ddl_limit, rd_limit, fraction, sum_surfs, l_s; + LDBLE damp_aq; + +/* + * Debye length = 1/k = sqrt[eta*eta_zero*R*T/(2*F**2*mu_x*1000)], Dzombak and Morel, p 36 + * + * 1000 converts kJ to J; 1000 converts Liters to meter**3; debye_length is in meters. + */ + debye_length = (EPSILON * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) + / (2. * F_C_MOL * F_C_MOL * mu_x * 1000.); + debye_length = sqrt(debye_length); + + /* ddl is at most the fraction ddl_limit of bulk water */ + ddl_limit = use.Get_surface_ptr()->DDL_limit; + +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + + if (use.Get_surface_ptr()->debye_lengths > 0) + { + sum_surfs = 0.0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + sum_surfs += + x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams; + } + + rd = debye_length * use.Get_surface_ptr()->debye_lengths; + use.Get_surface_ptr()->thickness = rd; + + if (state == INITIAL_SURFACE) + { + /* distribute water over DDL (rd) and free pore (r - rd) */ + /* find r: free pore (m3) = pi * (r - rd)^2 * L, where L = A / (2*pi*r), + A = sum_surfs = sum of the surface areas */ + b = -2 * (rd + use.Get_solution_ptr()->mass_water / (1000 * sum_surfs)); + r = 0.5 * (-b + sqrt(b * b - 4 * rd * rd)); + /* DDL (m3) = pi * (r^2 - (r - rd)^2) * L */ + rd_limit = (1 - sqrt(1 - ddl_limit)) * r; + /* rd should be smaller than r and the ddl limit */ + if (rd > rd_limit) + { + mass_water_surfaces_x = + use.Get_solution_ptr()->mass_water * ddl_limit / (1 - + ddl_limit); + r = 0.002 * (mass_water_surfaces_x + + use.Get_solution_ptr()->mass_water) / sum_surfs; + rd_limit = (1 - sqrt(1 - ddl_limit)) * r; + use.Get_surface_ptr()->thickness = rd = rd_limit; + } + else + mass_water_surfaces_x = + (r * r / pow(r - rd, 2) - + 1) * use.Get_solution_ptr()->mass_water; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + l_s = x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams; + x[i]->surface_charge->mass_water = + mass_water_surfaces_x * l_s / sum_surfs; + } + } + else + { + r = 0.002 * mass_water_bulk_x / sum_surfs; + rd_limit = (1 - sqrt(1 - ddl_limit)) * r; + if (rd > rd_limit) + { + use.Get_surface_ptr()->thickness = rd = rd_limit; + fraction = ddl_limit; + } + else + fraction = 1 - pow(r - rd, 2) / (r * r); + damp_aq = 1.0; + if (g_iterations > 10) + damp_aq = 0.2; + else if (g_iterations > 5) + damp_aq = 0.5; + mass_water_surfaces_x = damp_aq * fraction * mass_water_bulk_x + + (1 - damp_aq) * mass_water_surfaces_x; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + l_s = x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams; + x[i]->surface_charge->mass_water = + mass_water_surfaces_x * l_s / sum_surfs; + } + } + } + else + { + /* take constant thickness of, default 1e-8 m (100 Angstroms) */ + mass_water_surfaces_x = 0.0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + x[i]->surface_charge->mass_water = + x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams * use.Get_surface_ptr()->thickness * + 1000; + mass_water_surfaces_x += x[i]->surface_charge->mass_water; + } + } + + if (use.Get_surface_ptr()->type == CD_MUSIC) + mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; + else + { + /* for variable distribution of water over DDL and bulk... */ + if (state > INITIAL_SURFACE) + mass_water_aq_x = mass_water_bulk_x - mass_water_surfaces_x; + else + mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) +/* ---------------------------------------------------------------------- */ +{ + int i, j, count_g; + LDBLE mass_water_surface; + LDBLE molality, moles_excess, moles_surface; + + if (use.Get_surface_ptr() == NULL) + return (OK); +/* + * Find position of component in list of components + */ + i = 0; + + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + if (&(use.Get_surface_ptr()->charge[j]) == surface_charge_ptr1) + { + i = j; + break; + } + } + if (j >= use.Get_surface_ptr()->count_charge) + { + error_string = sformatf( + "In sum_diffuse_layer, component not found, %s.", + surface_charge_ptr1->name); + error_msg(error_string, STOP); + } +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + count_elts = 0; + paren_count = 0; + mass_water_surface = surface_charge_ptr1->mass_water; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; +#ifdef SKIP + moles_excess = mass_water_bulk_x * +/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ + surface_charge_ptr1->g[count_g].g * molality; +#endif + moles_excess = + mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; + + moles_surface = mass_water_surface * molality + moles_excess; +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + add_elt_list(s_h2o->next_elt, mass_water_surface / gfw_water); + + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_all_donnan(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge, converge, cd_m; + char name[MAX_LENGTH]; + LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; + LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif, var1; + LDBLE cz, cm, cp; + + if (use.Get_surface_ptr() == NULL) + return (OK); +/* if (use.Get_surface_ptr()->type == CD_MUSIC) + return (calc_all_donnan_music()); + */ f_sinh = + sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + tk_x * mu_x); + cz = cm = 1.0; + cp = 1.0; +/* + * calculate g for each surface... + */ + converge = TRUE; + count_charge = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + surface_charge_ptr = x[j]->surface_charge; + + if (debug_diffuse_layer == TRUE) + output_msg(sformatf( "Calc_all_g, X[%d]\n", j)); +/* + * sum eq of each charge number in solution... + */ + count_g = x[j]->surface_charge->count_g; + for (i = 0; i < count_g; i++) + { + charge_group[i].eq = 0.0; + } + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS) + continue; + for (k = 0; k < count_g; k++) + { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) + { +#ifdef SKIP + if (s_x[i]->z > 0) + cz = s_x[i]->z * pow(cp, s_x[i]->z); + else + cz = s_x[i]->z * pow(cm, -s_x[i]->z); + charge_group[k].eq += cz * s_x[i]->moles; +#endif + charge_group[k].eq += + s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; + break; + } + } + } + /* find surface charge from potential... */ + A_surf = + x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ + f_psi = f_psi / 2; + cd_m = 1; + } else + { + f_psi = x[j]->master[0]->s->la * LOG_10; + cd_m = -1; + } + surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; + if (surf_chrg_eq < -5e3) + { + surf_chrg_eq = -5e3; + var1 = surf_chrg_eq / (A_surf * f_sinh / F_C_MOL); + var1 = (var1 + sqrt(var1 * var1 + 1)); + f_psi = (var1 > 1e-8 ? log(var1) : -18.4); + surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; + x[j]->master[0]->s->la = f_psi / LOG_10; + } + /* also for the derivative... */ + dif = 1e-5; + f_psi2 = f_psi + dif; + surf_chrg_eq2 = A_surf * f_sinh * sinh(f_psi2) / F_C_MOL; + + /* find psi_avg that matches surface charge... */ + psi_avg = calc_psi_avg(surf_chrg_eq); + psi_avg2 = calc_psi_avg(surf_chrg_eq2); + + /*output_msg(sformatf( "psi's %e %e %e\n", f_psi, psi_avg, surf_chrg_eq)); */ + + /* fill in g's */ + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + + for (k = 0; k < count_g; k++) + { + x[j]->surface_charge->g[k].charge = charge_group[k].z; +#ifdef SKIP + if (charge_group[k].z > 0) + cz = pow(cp, charge_group[k].z); + else + cz = pow(cm, -charge_group[k].z); + new_g = cz * (exp(-charge_group[k].z * psi_avg)) - 1; + if (new_g < -ratio_aq) + new_g = -ratio_aq + G_TOL * 1e-5; + new_g2 = cz * (exp(-charge_group[k].z * psi_avg2)) - 1; + if (new_g2 < -ratio_aq) + new_g2 = -ratio_aq + G_TOL * 1e-5; +#endif + new_g = ratio_aq * (exp(cd_m * charge_group[k].z * psi_avg) - 1); + if (use.Get_surface_ptr()->only_counter_ions && + ((surf_chrg_eq < 0 && charge_group[k].z < 0) + || (surf_chrg_eq > 0 && charge_group[k].z > 0))) + new_g = -ratio_aq; + if (new_g <= -ratio_aq) + new_g = -ratio_aq + G_TOL * 1e-3; + new_g2 = ratio_aq * (exp(cd_m * charge_group[k].z * psi_avg2) - 1); + if (use.Get_surface_ptr()->only_counter_ions && + ((surf_chrg_eq < 0 && charge_group[k].z < 0) + || (surf_chrg_eq > 0 && charge_group[k].z > 0))) + new_g2 = -ratio_aq; + if (new_g2 <= -ratio_aq) + new_g2 = -ratio_aq + G_TOL * 1e-3; + if (fabs(new_g) >= 1) + { + if (fabs((new_g - x[j]->surface_charge->g[k].g) / new_g) > + convergence_tolerance) + { + converge = FALSE; + } + } + else + { + if (fabs(new_g - x[j]->surface_charge->g[k].g) > + convergence_tolerance) + { + converge = FALSE; + } + } + x[j]->surface_charge->g[k].g = new_g; + if (new_g != 0) + { + x[j]->surface_charge->g[k].dg = (new_g2 - new_g) / dif; + } + else + { + x[j]->surface_charge->g[k].dg = -charge_group[k].z; + } + /* save g for species */ + for (i = 0; i < count_s_x; i++) + { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) + { + s_x[i]->diff_layer[count_charge].charge = + x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + } + } + } + if (debug_diffuse_layer == TRUE) + { + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); +/* surf_chrg_eq = calc_surface_charge(name); + */ + output_msg(sformatf( + "\nDonnan all on %s (%d): charge, \tg, \tdg, Psi_surface = %8f V. \n", + name, count_charge, + x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * + tk_x / F_KJ_V_EQ)); + for (i = 0; i < count_g; i++) + { + output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg)); + } + } + count_charge++; + } + return (converge); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_init_donnan(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int count_g, count_charge; + char name[MAX_LENGTH]; + LDBLE f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; + + if (use.Get_surface_ptr() == NULL) + return (OK); +/* if (use.Get_surface_ptr()->type == CD_MUSIC) + return (calc_init_donnan_music()); + */ f_sinh = + sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + tk_x * mu_x); + if (convergence_tolerance >= 1e-8) + { + G_TOL = 1e-9; + } + else + { + G_TOL = 1e-13; + } +/* + * sum eq of each charge number in solution... + */ + charge_group = (struct Charge_Group *) free_check_null(charge_group); + charge_group = + (struct Charge_Group *) PHRQ_malloc((size_t) + sizeof(struct Charge_Group)); + if (charge_group == NULL) + malloc_error(); + charge_group[0].z = 0.0; + charge_group[0].eq = 0.0; + + count_g = 1; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS) + continue; + for (k = 0; k < count_g; k++) + { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) + { + charge_group[k].eq += + s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; + break; + } + } + if (k >= count_g) + { + charge_group = + (struct Charge_Group *) PHRQ_realloc(charge_group, + (size_t) (count_g + + 1) * + sizeof(struct + Charge_Group)); + if (charge_group == NULL) + malloc_error(); + charge_group[count_g].z = s_x[i]->z; + charge_group[count_g].eq = + s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; + + count_g++; + } + } +/* + * calculate g for each surface... + */ + count_charge = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + surface_charge_ptr = x[j]->surface_charge; + + x[j]->surface_charge->g = + (struct surface_diff_layer *) PHRQ_malloc((size_t) count_g * + sizeof(struct + surface_diff_layer)); + if (x[j]->surface_charge->g == NULL) + malloc_error(); + x[j]->surface_charge->count_g = count_g; + + /* find surface charge from potential... */ + A_surf = + x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ + f_psi = f_psi / 2; + } else + f_psi = x[j]->master[0]->s->la * LOG_10; + surf_chrg_eq = A_surf * f_sinh * sinh(f_psi) / F_C_MOL; + + /* find psi_avg that matches surface charge... */ +/* psi_avg = calc_psi_avg (0); + appt 7/9/8... may have to change above one */ + psi_avg = calc_psi_avg(0 * surf_chrg_eq); + + /* fill in g's */ + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + + for (k = 0; k < count_g; k++) + { + x[j]->surface_charge->g[k].charge = charge_group[k].z; + x[j]->surface_charge->g[k].g = + ratio_aq * (exp(-charge_group[k].z * psi_avg) - 1); + if (use.Get_surface_ptr()->only_counter_ions + && ((surf_chrg_eq < 0 && charge_group[k].z < 0) + || (surf_chrg_eq > 0 && charge_group[k].z > 0))) + x[j]->surface_charge->g[k].g = -ratio_aq; + if (x[j]->surface_charge->g[k].g != 0) + { + x[j]->surface_charge->g[k].dg = + -A_surf * f_sinh * cosh(f_psi) / (charge_group[k].eq * + F_C_MOL); + } + else + { + x[j]->surface_charge->g[k].dg = -charge_group[k].z; + } + /* save g for species */ + for (i = 0; i < count_s_x; i++) + { + if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) + { + s_x[i]->diff_layer[count_charge].charge = + x[j]->surface_charge; + s_x[i]->diff_layer[count_charge].count_g = k; + s_x[i]->diff_layer[count_charge].g_moles = 0.0; + s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; + } + } + } + if (debug_diffuse_layer == TRUE) + { + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); +/* surf_chrg_eq = calc_surface_charge(name); + */ + output_msg(sformatf( + "\nDonnan init on %s : charge, \tg, \tdg, Psi_surface = %8f V. \n", + name, + x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * + tk_x / F_KJ_V_EQ)); + for (i = 0; i < count_g; i++) + { + output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", + (double) x[j]->surface_charge->g[i].charge, + (double) x[j]->surface_charge->g[i].g, + (double) x[j]->surface_charge->g[i].dg)); + } + } + count_charge++; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_psi_avg(LDBLE surf_chrg_eq) +/* ---------------------------------------------------------------------- */ +{ +/* + * calculate the average (F * Psi / RT) that lets the DL charge counter the surface charge + */ + int i, l_iter, count_g; + LDBLE fd, fd1, p, temp, ratio_aq; +/* LDBLE dif; + */ + count_g = surface_charge_ptr->count_g; + ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + p = 0; + if (surf_chrg_eq == 0 || ratio_aq == 0) + return (0.0); + else if (surf_chrg_eq < 0) + p = -0.5 * log(-surf_chrg_eq * ratio_aq / mu_x + 1); + else if (surf_chrg_eq > 0) + p = 0.5 * log(surf_chrg_eq * ratio_aq / mu_x + 1); +/* + * Optimize p in SS{s_x[i]->moles * z_i * g(p)} = -surf_chrg_eq + * g(p) = exp(-p * z_i) * ratio_aq + * Elsewhere in PHREEQC, g is the excess, after subtraction of conc's for p = 0: + * g(p) = (exp(-p *z_i) - 1) * ratio_aq + */ + l_iter = 0; + do + { + fd = surf_chrg_eq; + fd1 = 0.0; + for (i = 1; i < count_g; i++) + { +/* if (use.Get_surface_ptr()->type == CD_MUSIC) + temp = exp(-charge_group[i].z * p); + else + */ /* multiply with ratio_aq for multiplier options cp and cm + in calc_all_donnan (not used now)... */ + temp = exp(-charge_group[i].z * p) * ratio_aq; + + if (use.Get_surface_ptr()->only_counter_ions && + ((surf_chrg_eq < 0 && charge_group[i].z < 0) + || (surf_chrg_eq > 0 && charge_group[i].z > 0))) + temp = 0.0; + fd += charge_group[i].eq * temp; + fd1 -= charge_group[i].z * charge_group[i].eq * temp; + } + fd /= -fd1; + p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); + if (fabs(p) < G_TOL) + p = 0.0; + l_iter++; + if (l_iter > 50) + { + error_string = sformatf( + "\nToo many iterations in subroutine calc_psi_avg; surface charge = %12.4e; surface water = %12.4e.\n", + (double) surf_chrg_eq, (double) surface_charge_ptr->mass_water); + error_msg(error_string, STOP); + } + } + while (fabs(fd) > 1e-12 && p != 0.0); + if (debug_diffuse_layer == TRUE) + output_msg(sformatf( + "iter in calc_psi_avg = %d. g(+1) = %8f. surface charge = %12.4e.\n", + l_iter, (double) (exp(-p) - 1), (double) surf_chrg_eq)); + + return (p); +} diff --git a/rename_cpp/inverse.cpp b/rename_cpp/inverse.cpp new file mode 100644 index 00000000..82713097 --- /dev/null +++ b/rename_cpp/inverse.cpp @@ -0,0 +1,5155 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + + +#define MAX_MODELS 20 +#define MIN_TOTAL_INVERSE 1e-14 + +/* variables local to module */ +#define SCALE_EPSILON .0009765625 +#define SCALE_WATER 1. +#define SCALE_ALL 1. +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_models(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of inverse models, make calculations + * for any marked "new". + */ + int n, print1; + char string[MAX_LENGTH]; + + // Revert to previous headings after inverse modeling + std::vector old_headings; + int i; + for (i = 0; i < user_punch_count_headings; i++) + { + old_headings.push_back(user_punch_headings[i]); + } + + array1 = NULL; + inv_zero = NULL; + inv_res = NULL; + inv_delta1 = NULL; + delta2 = NULL; + delta3 = NULL; + delta_save = NULL; + inv_cu = NULL; + inv_iu = NULL; + inv_is = NULL; + col_name = NULL; + row_name = NULL; + min_delta = NULL; + max_delta = NULL; + good = NULL; + bad = NULL; + minimal = NULL; + + print1 = TRUE; + state = INVERSE; + dl_type_x = NO_DL; + + for (n = 0; n < count_inverse; n++) + { + if (inverse[n].new_def == TRUE) + { +/* + * dump .lon file + */ + if (inverse[n].netpath != NULL) + dump_netpath(&inverse[n]); + +/* + * open .pat file + */ + if (inverse[n].pat != NULL) + { + strcpy(string, inverse[n].pat); + if (replace(".pat", ".pat", string) != TRUE) + { + strcat(string, ".pat"); + } + netpath_file = fopen(string, "w"); + if (netpath_file == NULL) + { + error_string = sformatf( "Can't open file, %s.", string); + error_msg(error_string, STOP); + } + count_inverse_models = 0; + count_pat_solutions = 0; + /* Header */ + fprintf(netpath_file, "2.14 # File format\n"); + } +/* + * Fill in stucture "use". + */ + use.Set_inverse_in(true); + use.Set_inverse_ptr(&inverse[n]); + use.Set_n_inverse_user(inverse[n].n_user); +/* + * Initial prints + */ + error_string = sformatf( + "Beginning of inverse modeling %d calculations.", + inverse[n].n_user); + dup_print(error_string, TRUE); + + if (inverse[n].mp == TRUE) + { + output_msg(sformatf( + "Using Cl1MP multiprecision optimization routine.\n")); + + } + else + { + output_msg(sformatf( + "Using Cl1 standard precision optimization routine.\n")); + } + status(0, NULL); + +/* + * Setup and solve + */ + count_calls = 0; + setup_inverse(&(inverse[n])); + punch_model_heading(&inverse[n]); + solve_inverse(&(inverse[n])); + if (inverse[n].count_isotope_unknowns > 0) + { + inverse[n].isotope_unknowns = + (struct isotope *) free_check_null(inverse[n]. + isotope_unknowns); + } + inverse[n].new_def = FALSE; + if (inverse[n].pat != NULL) + { + fclose(netpath_file); + netpath_file = NULL; + } + } + } + + user_punch_count_headings = old_headings.size(); + user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, + (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + for (i = 0; i < user_punch_count_headings; i++) + { + user_punch_headings[i] = string_hsave(old_headings[i].c_str()); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_inverse(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in array for an inverse problem + */ + int i, j, k, i_alk, i_carb; + int max; + int count_rows_t; + int column, row; + int temp, temppun; + LDBLE isotope_number; + LDBLE f, coef, cb, conc; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + struct solution *solution_ptr; + struct reaction *rxn_ptr; + struct master *master_ptr; +/* + * Determine array sizes, row and column positions + */ + toler = inv_ptr->tolerance; + if (inv_ptr->mp == TRUE) + { + toler = inv_ptr->mp_tolerance; + } +/* + * Alkalinity derivatives with pH and carbon + */ + carbon = 1; + temp = pr.status; + pr.status = FALSE; + temppun = punch.in; + punch.in = FALSE; + carbon_derivs(inv_ptr); + pr.status = temp; + punch.in = temppun; + state = INVERSE; +/* + * tidy isotopes if necessary + */ + inv_ptr->count_isotope_unknowns = 0; + if (inv_ptr->count_isotopes > 0) + { + inv_ptr->count_isotope_unknowns = + count_isotope_unknowns(inv_ptr, &inv_ptr->isotope_unknowns); + if (get_input_errors() > 0) + { + error_msg("Stopping because of input errors.", STOP); + } + check_isotopes(inv_ptr); + if (get_input_errors() > 0) + { + error_msg("Stopping because of input errors.", STOP); + } + } + +/* + * count unknowns + */ + max_column_count = inv_ptr->count_elts * inv_ptr->count_solns + /* epsilons */ + inv_ptr->count_solns + /* solutions */ + inv_ptr->count_phases + /* phases */ + inv_ptr->count_redox_rxns + /* redox reactions */ + carbon * inv_ptr->count_solns + /* pH */ + 1 + /* water */ + inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* isotopes in solution */ + inv_ptr->count_isotopes * inv_ptr->count_phases + /* isotopes in phases */ + 1 + 1; /* rhs, ineq */ + count_unknowns = max_column_count - 2; + col_phases = inv_ptr->count_solns; + col_redox = col_phases + inv_ptr->count_phases; + col_epsilon = col_redox + inv_ptr->count_redox_rxns; + col_ph = col_epsilon + inv_ptr->count_elts * inv_ptr->count_solns; + col_water = col_ph + carbon * inv_ptr->count_solns; + col_isotopes = col_water + 1; + col_phase_isotopes = + col_isotopes + inv_ptr->count_isotope_unknowns * inv_ptr->count_solns; + max_row_count = inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ + carbon * inv_ptr->count_solns + /* optimize ph */ + 1 + /* optimize water */ + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ + inv_ptr->count_isotopes * inv_ptr->count_phases + /* optimize phase isotopes */ + inv_ptr->count_elts + /* mass balances */ + 1 + 1 + /* fractions, init and final */ + inv_ptr->count_solns + /* charge balances */ + carbon * inv_ptr->count_solns + /* dAlk = dC + dph */ + inv_ptr->count_isotopes + /* isotopes */ + 2 * inv_ptr->count_solns * inv_ptr->count_elts + /* epsilon constraints */ + 2 * carbon * inv_ptr->count_solns + /* epsilon on ph */ + 2 + /* epsilon for water */ + 2 * inv_ptr->count_isotope_unknowns * inv_ptr->count_solns + /* epsilon for isotopes */ + 2 * inv_ptr->count_isotopes * inv_ptr->count_phases + /* epsilon for isotopes in phases */ + 2; /* work space */ + + row_mb = inv_ptr->count_solns * inv_ptr->count_elts + + carbon * inv_ptr->count_solns + 1 + + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + + inv_ptr->count_isotopes * inv_ptr->count_phases; + row_fract = row_mb + inv_ptr->count_elts; + row_charge = row_fract + 2; + row_carbon = row_charge + inv_ptr->count_solns; + row_isotopes = row_carbon + carbon * inv_ptr->count_solns; + row_epsilon = row_isotopes + inv_ptr->count_isotopes; +/* The next three are not right, some rows of epsilon are deleted */ +/* + row_ph_epsilon = row_epsilon + 2 * inv_ptr->count_solns * inv_ptr->count_elts; + row_water_epsilon = row_ph + 2 * carbon * inv_ptr->count_solns; + row_isotope_epsilon + row_isotope_phase_epsilon + */ +/* + * Malloc space for arrays + */ + array = (LDBLE *) free_check_null(array); + array = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * + sizeof(LDBLE)); + if (array == NULL) + malloc_error(); + + array1 = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * max_row_count * + sizeof(LDBLE)); + if (array1 == NULL) + malloc_error(); + + col_name = + (const char **) PHRQ_malloc((size_t) max_column_count * sizeof(char *)); + if (col_name == NULL) + malloc_error(); + + row_name = (const char **) PHRQ_malloc((size_t) max_row_count * sizeof(char *)); + if (row_name == NULL) + malloc_error(); + + delta = (LDBLE *) free_check_null(delta); + delta = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (delta == NULL) + malloc_error(); + + inv_delta1 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (inv_delta1 == NULL) + malloc_error(); + + delta2 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (delta2 == NULL) + malloc_error(); + + delta3 = (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (delta3 == NULL) + malloc_error(); + + delta_save = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (delta_save == NULL) + malloc_error(); + + min_delta = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (min_delta == NULL) + malloc_error(); + + max_delta = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (max_delta == NULL) + malloc_error(); + + inv_res = (LDBLE *) PHRQ_malloc((size_t) max_row_count * sizeof(LDBLE)); + if (inv_res == NULL) + malloc_error(); + + if (max_column_count < max_row_count) + { + max = max_row_count; + } + else + { + max = max_column_count; + } + inv_zero = (LDBLE *) PHRQ_malloc((size_t) max * sizeof(LDBLE)); + if (inv_zero == NULL) + malloc_error(); +/* + * Define inv_zero and inv_zero array, delta + */ + for (i = 0; i < max; i++) + inv_zero[i] = 0.0; + + memcpy((void *) &(delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(min_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + for (i = 0; i < max_row_count; i++) + { + memcpy((void *) &(array[i * max_column_count]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * begin filling array + */ + count_rows = 0; +/* + * optimization + */ + count_optimize = inv_ptr->count_solns * inv_ptr->count_elts + /* optimize */ + carbon * inv_ptr->count_solns + /* optimize ph */ + 1 + /* optimize water */ + inv_ptr->count_solns * inv_ptr->count_isotope_unknowns + /* optimize isotopes */ + inv_ptr->count_isotopes * inv_ptr->count_phases; /* optimize phase isotopes */ + + for (i = 0; i < count_optimize; i++) + { + row_name[count_rows] = string_hsave("optimize"); + count_rows++; + } + write_optimize_names(inv_ptr); +/* + * equalities + */ + +/* + * Mass_balance: solution data + */ + + /* initialize master species */ + for (i = 0; i < count_master; i++) + { + master[i]->in = -1; + if (strstr(master[i]->elt->name, "Alk") == master[i]->elt->name) + { + master_alk = master[i]; + } + } + /* mark master species included in model, write row names */ + count_rows_t = count_rows; + i_alk = -1; + i_carb = -1; + for (i = 0; i < inv_ptr->count_elts; i++) + { + master_ptr = inv_ptr->elts[i].master; + if (master_ptr == master_alk) + i_alk = i; + if (strcmp(master_ptr->elt->name, "C(4)") == 0) + i_carb = i; + inv_ptr->elts[i].master->in = count_rows_t; + row_name[count_rows_t] = inv_ptr->elts[i].master->elt->name; + count_rows_t++; + } + /* put concentrations in array */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + xsolution_zero(); + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + if (solution_ptr == NULL) + { + error_string = sformatf( "Solution number %d not found.", + inv_ptr->solns[i]); + error_msg(error_string, STOP); + } + /* write master species concentrations */ + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + master_ptr->total += solution_ptr->totals[j].moles; + /* List elements not included in model */ + if (master_ptr->in < 0) + { + error_string = sformatf( + "%s is included in solution %d, but is not included as a mass-balance constraint.", + solution_ptr->totals[j].description, + inv_ptr->solns[i]); + warning_msg(error_string); + } + } + master_alk->total = solution_ptr->total_alkalinity; + f = 1.0; + if (i == (inv_ptr->count_solns - 1)) + { + f = -1.0; + } + column = i; + sprintf(token, "soln %d", i); + col_name[column] = string_hsave(token); + for (j = 0; j < count_master; j++) + { + if (master[j]->in >= 0) + { + array[master[j]->in * max_column_count + i] = + f * master[j]->total; + if (master[j]->s == s_eminus) + { + array[master[j]->in * max_column_count + i] = 0.0; + } + } + } + /* calculate charge balance for elements in model */ + cb = 0; + for (j = 0; j < count_master; j++) + { + if (master[j]->in >= 0) + { + if (master[j]->s == s_eminus) + { + coef = 0.0; + } + else if (master[j] == master_alk) + { + coef = -1.0; + } + else + { + coef = master[j]->s->z + master[j]->s->alk; + } + cb += coef * master[j]->total; + } + } + if (fabs(cb) < toler) + cb = 0.0; + array[(row_charge + i) * max_column_count + i] = cb; + } + +/* mass_balance: phase data */ + + for (i = 0; i < inv_ptr->count_phases; i++) + { + phase_ptr = inv_ptr->phases[i].phase; + rxn_ptr = phase_ptr->rxn_s; + column = col_phases + i; + col_name[column] = phase_ptr->name; + for (j = 1; rxn_ptr->token[j].s != NULL; j++) + { + if (rxn_ptr->token[j].s->secondary != NULL) + { + master_ptr = rxn_ptr->token[j].s->secondary; + } + else + { + master_ptr = rxn_ptr->token[j].s->primary; + } + if (master_ptr == NULL) + { + error_string = sformatf( + "Setup_inverse, reaction for phase, %s.", + phase_ptr->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) + continue; + if (master_ptr->s == s_h2o) + { + row = row_fract; +/* turn off h2o from minerals in water mass balance */ + if (inv_ptr->mineral_water != TRUE) + continue; + + } + else + { + row = master_ptr->in; + } + /* e- has coef of 0 for some reason */ + coef = master_ptr->coef; + if (coef <= 0) + coef = 1.0; + array[row * max_column_count + column] = + rxn_ptr->token[j].coef * coef; + } + row = master_alk->in; /* include alkalinity for phase */ + array[row * max_column_count + column] = calc_alk(rxn_ptr); + } + +/* mass balance: redox reaction data */ + + k = 0; + for (i = 0; i < inv_ptr->count_elts; i++) + { + if (inv_ptr->elts[i].master->s->primary == NULL) + { + coef = inv_ptr->elts[i].master->coef; + rxn_ptr = inv_ptr->elts[i].master->rxn_primary; + column = col_redox + k; + col_name[column] = inv_ptr->elts[i].master->elt->name; + k++; + for (j = 0; rxn_ptr->token[j].s != NULL; j++) + { + if (rxn_ptr->token[j].s->secondary != NULL) + { + master_ptr = rxn_ptr->token[j].s->secondary; + } + else + { + master_ptr = rxn_ptr->token[j].s->primary; + } + if (master_ptr == NULL) + { + error_string = sformatf( + "Subroutine setup_inverse, element not found, %s.", + rxn_ptr->token[j].s->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) + continue; + if (master_ptr->s == s_h2o) + { + row = row_fract; +/* turn off h2o from minerals in water mass balance */ + if (inv_ptr->mineral_water != TRUE) + continue; + } + else + { + row = master_ptr->in; + } + array[row * max_column_count + column] = + rxn_ptr->token[j].coef; + /* if coefficient of element is not 1.0 in master species */ + if (j != 0) + array[row * max_column_count + column] /= coef; + } + row = master_alk->in; /* include alkalinity for redox reaction */ + array[row * max_column_count + column] = + (calc_alk(rxn_ptr) - inv_ptr->elts[i].master->s->alk) / coef; + } + } + +/* mass-balance: epsilons */ + + column = col_epsilon; + for (i = 0; i < inv_ptr->count_elts; i++) + { + row = inv_ptr->elts[i].master->in; + for (j = 0; j < inv_ptr->count_solns; j++) + { + if (j < (inv_ptr->count_solns - 1)) + { + array[row * max_column_count + column] = 1.0; + } + else + { + array[row * max_column_count + column] = -1.0; + } + if (inv_ptr->elts[i].master->s == s_eminus) + { + array[row * max_column_count + column] = 0.0; + } + sprintf(token, "%s %d", row_name[row], j); + col_name[column] = string_hsave(token); + column++; + } + } + count_rows += inv_ptr->count_elts; + +/* put names in col_name for ph */ + + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "ph %d", i); + col_name[column] = string_hsave(token); + column++; + } +/* put names in col_name for water */ + + sprintf(token, "water"); + col_name[column] = string_hsave(token); + column++; + +/* put names of isotopes in col_name */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + sprintf(token, "%d%s %d", + (int) inv_ptr->isotope_unknowns[j].isotope_number, + inv_ptr->isotope_unknowns[j].elt_name, i); + col_name[column] = string_hsave(token); + column++; + } + } + +/* put phase isotopes in col_name */ + + if (inv_ptr->count_isotopes > 0) + { + /* isotopes of phases phases */ + for (i = 0; i < inv_ptr->count_phases; i++) + { + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + sprintf(token, "%d%s %s", + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name, + inv_ptr->phases[i].phase->name); + col_name[column] = string_hsave(token); + column++; + } + } + } +/* + * Initial solution mixing fractions or water mass balance + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + if (i < inv_ptr->count_solns - 1) + { + array[count_rows * max_column_count + i] = + 1.0 / gfw_water * solution_ptr->mass_water; + } + else + { + array[count_rows * max_column_count + inv_ptr->count_solns - 1] = + -1.0 / gfw_water * solution_ptr->mass_water; + } + } + /* coefficient for water uncertainty */ + if (inv_ptr->water_uncertainty > 0) + { + array[count_rows * max_column_count + col_water] = 1.0; + } + row_name[count_rows] = string_hsave("H2O"); + row_water = count_rows; + count_rows++; + +/* + * Final solution fraction equals 1.0 + */ + + array[count_rows * max_column_count + inv_ptr->count_solns - 1] = 1.0; + array[count_rows * max_column_count + count_unknowns] = 1.0; + row_name[count_rows] = string_hsave("fract, final"); + count_rows++; + +/* + * Charge balance: + */ + + for (i = 0; i < inv_ptr->count_solns; i++) + { +/* solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); */ +/* array[count_rows * max_column_count + i] = solution_ptr->cb; */ + for (j = 0; j < inv_ptr->count_elts; j++) + { + column = col_epsilon + j * inv_ptr->count_solns + i; + coef = + inv_ptr->elts[j].master->s->z + + inv_ptr->elts[j].master->s->alk; + if (inv_ptr->elts[j].master == master_alk) + { + coef = -1.0; + } + array[count_rows * max_column_count + column] = coef; + if (inv_ptr->elts[j].master->s == s_eminus) + { + array[count_rows * max_column_count + column] = 0.0; + } + } + sprintf(token, "%s %d", "charge", i); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * dC = (dC/dph)*dph + (dC/dAlk)*dAlk for each solution + */ +/* + * dAlk = (dAlk/dC)*dC + (dAlk/dpH)*dpH for each solution + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (inv_ptr->dalk_dph[i] != 0 || inv_ptr->dalk_dc[i] != 0) + { + column = col_ph + i; + array[count_rows * max_column_count + column] = + inv_ptr->dalk_dph[i]; + column = col_epsilon + i_alk * inv_ptr->count_solns + i; + array[count_rows * max_column_count + column] = -1.0; + column = col_epsilon + i_carb * inv_ptr->count_solns + i; + array[count_rows * max_column_count + column] = + inv_ptr->dalk_dc[i]; + } + sprintf(token, "%s %d", "dAlk", i); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * Isotope mass balances + */ + if (get_input_errors() > 0) + { + error_msg("Stopping because of input errors.", STOP); + } + if (inv_ptr->count_isotopes != 0) + { + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + isotope_balance_equation(inv_ptr, count_rows, j); + sprintf(token, "%d%s", (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities + */ + row_epsilon = count_rows; + for (i = 0; i < inv_ptr->count_solns; i++) + { + for (j = 0; j < inv_ptr->count_elts; j++) + { + if (inv_ptr->elts[j].master->s == s_eminus) + continue; + column = col_epsilon + j * inv_ptr->count_solns + i; + +/* calculate magnitude of bound */ + + coef = inv_ptr->elts[j].uncertainties[i]; + if (coef <= 0.0) + { + coef = -coef; + } + else + { + coef = + array[inv_ptr->elts[j].master->in * max_column_count + + i] * coef; + coef = fabs(coef); + } + + if (coef < toler) + coef = 0; + +/* zero column if uncertainty is zero */ + if (coef == 0.0) + { + for (k = 0; k < count_rows; k++) + { + array[k * max_column_count + column] = 0.0; + } + continue; + } + +/* this statement probably obviates some of the following logic. */ +/* coef += toler; */ + +/* scale epsilon optimization equation */ + + if (coef < toler) + { + array[(column - col_epsilon) * max_column_count + column] = + SCALE_EPSILON / toler; + } + else + { + array[(column - col_epsilon) * max_column_count + column] = + SCALE_EPSILON / coef; + } + +/* set upper limit of change in positive direction */ + if (coef < toler) + { + coef = toler; + f = 10; + } + else + { + f = 1.0; + } + array[count_rows * max_column_count + column] = 1.0 * f; + array[count_rows * max_column_count + i] = -coef * f; + sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, + "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + conc = array[inv_ptr->elts[j].master->in * max_column_count + i]; + + /* if concentration is zero, only positive direction allowed */ + if (conc == 0.0) + { + delta[column] = 1.0; + continue; + } + /* if uncertainty is less than tolerance, set uncertainty to toler */ + if (coef <= toler) + { +/* f = 10 * toler / coef; */ + coef = toler; + f = 10; + } + else + { + f = 1.0; + } + /* if uncertainty is greater than concentration, + maximum negative is equal to concentrations, + except alkalinity */ + if (coef > fabs(conc) && + (strstr(inv_ptr->elts[j].master->elt->name, "Alkalinity") != + inv_ptr->elts[j].master->elt->name)) + coef = fabs(conc) + toler; + + array[count_rows * max_column_count + i] = -coef * f; + array[count_rows * max_column_count + column] = -1.0 * f; + sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, + "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities for pH + */ + /* row_ph_epsilon = count_rows; */ + if (inv_ptr->carbon == TRUE) + { + for (i = 0; i < inv_ptr->count_solns; i++) + { + column = col_ph + i; + coef = inv_ptr->ph_uncertainties[i]; + +/* scale epsilon in optimization equation */ + + array[(column - col_epsilon) * max_column_count + column] = + SCALE_EPSILON / coef; + +/* set upper limit of change in positive direction */ + + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%s %s", "pH", "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%s %s", "pH", "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } + } +/* + * inequalities for water + */ + column = col_water; + coef = inv_ptr->water_uncertainty; + /* row_water_epsilon = count_rows; */ + if (coef > 0.0) + { +/* set upper limit of change in positive direction */ + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + count_unknowns] = coef; + sprintf(token, "%s %s", "water", "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + count_unknowns] = coef; + sprintf(token, "%s %s", "water", "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + } +/* + * inequalities for isotopes + */ + row_isotope_epsilon = count_rows; + if (inv_ptr->count_isotopes > 0) + { + for (i = 0; i < inv_ptr->count_solns; i++) + { + solution_ptr = solution_bsearch(inv_ptr->solns[i], &k, TRUE); + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + column = + col_isotopes + (i * inv_ptr->count_isotope_unknowns) + j; + master_ptr = inv_ptr->isotope_unknowns[j].master; + isotope_number = inv_ptr->isotope_unknowns[j].isotope_number; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (solution_ptr->isotopes[k].master == master_ptr && + solution_ptr->isotopes[k].isotope_number == + isotope_number) + { + coef = solution_ptr->isotopes[k].x_ratio_uncertainty; + +/* scale epsilon in optimization equation */ + + array[(column - col_epsilon) * max_column_count + + column] = SCALE_EPSILON / coef; + +/* set upper limit of change in positive direction */ + array[count_rows * max_column_count + column] = 1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%d%s %s", + (int) solution_ptr->isotopes[k]. + isotope_number, + solution_ptr->isotopes[k].elt_name, "eps+"); + row_name[count_rows] = string_hsave(token); + count_rows++; + +/* set lower limit of change in negative direction */ + + array[count_rows * max_column_count + column] = -1.0; + array[count_rows * max_column_count + i] = -coef; + sprintf(token, "%d%s %s", + (int) solution_ptr->isotopes[k]. + isotope_number, + solution_ptr->isotopes[k].elt_name, "eps-"); + row_name[count_rows] = string_hsave(token); + count_rows++; + break; + } + } + } + } + } +/* + * inequalities for isotopes in phases + */ + /* row_isotope_phase_epsilon = count_rows; */ + phase_isotope_inequalities(inv_ptr); + if (get_input_errors() > 0) + { + error_msg("Stopping because of input errors.", STOP); + } +/* + * Set non-negativity constraints + */ + + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (inv_ptr->phases[i].constraint == PRECIPITATE) + { + delta[col_phases + i] = -1.0; + } + else if (inv_ptr->phases[i].constraint == DISSOLVE) + { + delta[col_phases + i] = 1.0; + } + } + for (i = 0; i < (inv_ptr->count_solns - 1); i++) + { + delta[i] = 1.0; + } +/* + * Scale water equation + */ + for (i = 0; i < max_column_count; i++) + { + array[row_water * max_column_count + i] *= SCALE_WATER; + } +/* + * Arrays are complete + */ + if (debug_inverse == TRUE) + { + for (i = 0; i < count_unknowns; i++) + { + output_msg(sformatf( "%d\t%s\n", i, col_name[i])); + } + for (i = 0; i < count_rows; i++) + { + k = 0; + output_msg(sformatf( "%d\t%s\n", i, row_name[i])); + for (j = 0; j < count_unknowns + 1; j++) + { + if (k > 7) + { + output_msg(sformatf( "\n")); + k = 0; + } + output_msg(sformatf( "%11.2e", + (double) array[i * max_column_count + j])); + k++; + } + if (k != 0) + { + output_msg(sformatf( "\n")); + } + output_msg(sformatf( "\n")); + } + output_msg(sformatf( "row_mb %d\n", row_mb)); + output_msg(sformatf( "row_fract %d\n", row_fract)); + output_msg(sformatf( "row_charge %d\n", row_charge)); + output_msg(sformatf( "row_carbon %d\n", row_carbon)); + output_msg(sformatf( "row_isotopes %d\n", row_isotopes)); + output_msg(sformatf( "row_epsilon %d\n", row_epsilon)); + + output_msg(sformatf( "col_phases %d\n", col_phases)); + output_msg(sformatf( "col_redox %d\n", col_redox)); + output_msg(sformatf( "col_epsilon %d\n", col_epsilon)); + output_msg(sformatf( "col_ph %d\n", col_ph)); + output_msg(sformatf( "col_water %d\n", col_water)); + output_msg(sformatf( "col_isotopes %d\n", col_isotopes)); + output_msg(sformatf( "col_phase_isotopes %d\n", + col_phase_isotopes)); + output_msg(sformatf( "count_unknowns %d\n", count_unknowns)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solve_inverse(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Exhaustively search for mass-balance models with two options + * -minimal on or off + * -range on or off + * + */ + int i, j, n; + int quit, print, first; + int first_of_model_size, model_size; + unsigned long minimal_bits, good_bits; + char token[MAX_LENGTH]; + + n = count_unknowns; /* columns in A, C, E */ + klmd = max_row_count - 2; + nklmd = n + klmd; + n2d = n + 2; + + max_good = MAX_MODELS; + max_bad = MAX_MODELS; + max_minimal = MAX_MODELS; + + good = + (unsigned long *) PHRQ_malloc((size_t) max_good * + sizeof(unsigned long)); + if (good == NULL) + malloc_error(); + count_good = 0; + + bad = + (unsigned long *) PHRQ_malloc((size_t) max_bad * + sizeof(unsigned long)); + if (bad == NULL) + malloc_error(); + count_bad = 0; + + minimal = + (unsigned long *) PHRQ_malloc((size_t) max_minimal * + sizeof(unsigned long)); + if (minimal == NULL) + malloc_error(); + count_minimal = 0; + + col_back = (int *) PHRQ_malloc((size_t) max_column_count * sizeof(int)); + if (col_back == NULL) + malloc_error(); + + row_back = (int *) PHRQ_malloc((size_t) max_row_count * sizeof(int)); + if (row_back == NULL) + malloc_error(); + +/* + * Allocate space for arrays + */ + inv_cu = (LDBLE *) PHRQ_malloc((size_t) 2 * nklmd * sizeof(LDBLE)); + if (inv_cu == NULL) + malloc_error(); + memset(inv_cu, 0, ((size_t) (2 * nklmd * sizeof(LDBLE)))); + inv_iu = (int *) PHRQ_malloc((size_t) 2 * nklmd * sizeof(int)); + if (inv_iu == NULL) + malloc_error(); + inv_is = (int *) PHRQ_malloc((size_t) klmd * sizeof(int)); + if (inv_is == NULL) + malloc_error(); + + for (i = 0; i < 79; i++) + token[i] = '='; + token[79] = '\0'; +/* + * Set solutions, largest bit is final solution, smallest bit is initial solution 1 + * Set phases, largest bit is last phase, smallest bit is first phase + * Set current bits to complete list. + */ + soln_bits = 0; + if (inv_ptr->count_solns + inv_ptr->count_phases > 32) + { + error_msg + ("For inverse modeling, sum of initial solutions and phases must be <= 32.\n\tFor all reasonable calculations, the sum should be much less than 32.", + STOP); + } + for (i = inv_ptr->count_solns; i > 0; i--) + { + temp_bits = 1 << (i - 1); + soln_bits += temp_bits; + } + if (check_solns(inv_ptr) == ERROR) + { + error_msg("Calculations terminating.", STOP); + } +/* + * solutions are in highest bits, phases are in lower bits; + */ +/* + * All combinations of solutions + */ + first = TRUE; + for (; + get_bits(soln_bits, inv_ptr->count_solns - 2, + inv_ptr->count_solns - 1) > 0; soln_bits--) + { +/* + * Loop through all models of of descending size + */ + for (model_size = inv_ptr->count_phases; model_size >= 0; + model_size--) + { + first_of_model_size = TRUE; + quit = TRUE; + while (next_set_phases(inv_ptr, first_of_model_size, model_size) + == TRUE) + { + first_of_model_size = FALSE; + current_bits = + (soln_bits << inv_ptr->count_phases) + phase_bits; + + if (subset_bad(current_bits) == TRUE + || subset_minimal(current_bits) == TRUE) + continue; + quit = FALSE; +/* + * Switch for finding minimal models only + */ + if (inv_ptr->minimal == TRUE + && superset_minimal(current_bits) == TRUE) + continue; +/* + * Solve for minimum epsilons, continue if no solution found. + */ + if (solve_with_mask(inv_ptr, current_bits) == ERROR) + { + save_bad(current_bits); + if (first == TRUE) + { + post_mortem(); + quit = TRUE; + break; + } + else + { + continue; + } + } + first = FALSE; +/* + * Model has been found, set bits + */ + good_bits = current_bits; + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (equal(inv_delta1[i + inv_ptr->count_solns], 0.0, TOL) == + TRUE) + { + good_bits = set_bit(good_bits, i, 0); + } + } + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (equal(inv_delta1[i], 0.0, TOL) == TRUE) + { + good_bits = + set_bit(good_bits, i + inv_ptr->count_phases, 0); + } + } +/* + * Determine if model is new + */ + for (j = 0; j < count_good; j++) + { + if (good_bits == good[j]) + break; + } +/* + * Calculate ranges and print model only if NOT looking for minimal models + */ + print = FALSE; + if (j >= count_good && inv_ptr->minimal == FALSE) + { + print = TRUE; + save_good(good_bits); + if (inv_ptr->range == TRUE) + { + range(inv_ptr, good_bits); + } + print_model(inv_ptr); + punch_model(inv_ptr); + dump_netpath_pat(inv_ptr); + } +/* + * If superset of a minimal model continue + */ + minimal_bits = good_bits; + if (superset_minimal(minimal_bits) == TRUE) + { + if (print == TRUE) + { + if (pr.inverse == TRUE && pr.all == TRUE) + { + output_msg(sformatf( "%s\n\n", token)); + } + } + continue; + } +/* + * If not superset of minimal model, find minimal model + */ + minimal_bits = minimal_solve(inv_ptr, minimal_bits); + if (minimal_bits == good_bits && print == TRUE) + { + if (pr.inverse == TRUE && pr.all == TRUE) + { + output_msg(sformatf( + "\nModel contains minimum number of phases.\n")); + } + } + if (print == TRUE) + { + if (pr.inverse == TRUE && pr.all == TRUE) + { + output_msg(sformatf( "%s\n\n", token)); + } + } + for (j = 0; j < count_good; j++) + { + if (minimal_bits == good[j]) + break; + } + if (j >= count_good) + { + save_good(minimal_bits); + if (inv_ptr->range == TRUE) + { + range(inv_ptr, minimal_bits); + } + print_model(inv_ptr); + if (pr.inverse == TRUE && pr.all == TRUE) + { + output_msg(sformatf( + "\nModel contains minimum number of phases.\n")); + output_msg(sformatf( "%s\n\n", token)); + } + punch_model(inv_ptr); + dump_netpath_pat(inv_ptr); + } + save_minimal(minimal_bits); + } + if (quit == TRUE) + break; + } + } +/* + * Summary print + */ + if (pr.inverse == TRUE && pr.all == TRUE) + { + output_msg(sformatf( "\nSummary of inverse modeling:\n\n")); + output_msg(sformatf( "\tNumber of models found: %d\n", + count_good)); + output_msg(sformatf( "\tNumber of minimal models found: %d\n", + count_minimal)); + output_msg(sformatf( + "\tNumber of infeasible sets of phases saved: %d\n", + count_bad)); + output_msg(sformatf( "\tNumber of calls to cl1: %d\n", + count_calls)); + } + array = (LDBLE *) free_check_null(array); + delta = (LDBLE *) free_check_null(delta); + array1 = (LDBLE *) free_check_null(array1); + inv_zero = (LDBLE *) free_check_null(inv_zero); + inv_res = (LDBLE *) free_check_null(inv_res); + inv_delta1 = (LDBLE *) free_check_null(inv_delta1); + delta2 = (LDBLE *) free_check_null(delta2); + delta3 = (LDBLE *) free_check_null(delta3); + delta_save = (LDBLE *) free_check_null(delta_save); + inv_cu = (LDBLE *) free_check_null(inv_cu); + inv_iu = (int *) free_check_null(inv_iu); + inv_is = (int *) free_check_null(inv_is); + col_name = (const char **) free_check_null(col_name); + row_name = (const char **) free_check_null(row_name); + col_back = (int *) free_check_null(col_back); + row_back = (int *) free_check_null(row_back); + min_delta = (LDBLE *) free_check_null(min_delta); + max_delta = (LDBLE *) free_check_null(max_delta); + good = (unsigned long *) free_check_null(good); + bad = (unsigned long *) free_check_null(bad); + minimal = (unsigned long *) free_check_null(minimal); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +unsigned long Phreeqc:: +minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Starting with phases indicated in minimal bits, sequentially + * remove phases to find minimal solution + */ + int i; + unsigned long temp_bits_l; + if (debug_inverse == TRUE) + { + output_msg(sformatf( "Beginning minimal solve: \n")); + bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); + } + for (i = 0; i < inv_ptr->count_phases + inv_ptr->count_solns - 1; i++) + { + if (get_bits(minimal_bits, i, 1) == 0) + continue; + temp_bits_l = 1 << i; /* 0's and one 1 */ + temp_bits_l = ~temp_bits_l; /* 1's and one 0 */ + minimal_bits = minimal_bits & temp_bits_l; + if (debug_inverse == TRUE) + { + output_msg(sformatf( "Solving for minimal\n")); + bit_print(minimal_bits, + inv_ptr->count_phases + inv_ptr->count_solns); + } + +/* + * minimal_bits can not be superset of a minimal model, but + * could be subset of one of the sets of minerals with no feasible solution + * If it is a subset, then replace mineral and go on to next + */ + if (subset_bad(minimal_bits) == TRUE) + { + /* put bit back */ + minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ + continue; + } + if (solve_with_mask(inv_ptr, minimal_bits) == ERROR) + { + save_bad(minimal_bits); + /* put bit back */ + minimal_bits = minimal_bits | ~temp_bits_l; /* 0's and one 1 */ + } + + } + if (debug_inverse == TRUE) + { + output_msg(sformatf( "\n\nMINIMAL MODEL\n\n")); + bit_print(minimal_bits, inv_ptr->count_phases + inv_ptr->count_solns); + } + + solve_with_mask(inv_ptr, minimal_bits); + unsigned long actual_bits = 0; + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (equal(inv_delta1[i], 0.0, TOL) == FALSE) + { + actual_bits = set_bit(actual_bits, i + inv_ptr->count_phases, 1); + } + } + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (equal(inv_delta1[i + inv_ptr->count_solns], 0.0, TOL) == FALSE) + { + actual_bits = set_bit(actual_bits, i, 1); + } + } + if (actual_bits != minimal_bits) + { + warning_msg("Roundoff errors in minimal calculation"); + } + return (actual_bits); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Uses cur_bits to zero out columns of the array and then solves. + */ + int i, k, l, m, n; + +/* + * Calculate dimensions + */ + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; + + + + memcpy((void *) &(inv_res[0]), (void *) &(inv_zero[0]), + (size_t) max_row_count * sizeof(LDBLE)); + memcpy((void *) &(delta2[0]), (void *) &(delta[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(delta_save[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + + shrink(inv_ptr, array, array1, + &k, &l, &m, &n, cur_bits, delta2, col_back, row_back); + /* + * Save delta constraints + */ + for (i = 0; i < n; i++) + { + delta_save[col_back[i]] = delta2[i]; + } + + + if (debug_inverse == TRUE) + { + output_msg(sformatf( "\nColumns\n")); + for (i = 0; i < n; i++) + { + output_msg(sformatf( "\t%d\t%s\n", i, + col_name[col_back[i]])); + } + + output_msg(sformatf( "\nRows\n")); + for (i = 0; i < k + l + m; i++) + { + output_msg(sformatf( "\t%d\t%s\n", i, + row_name[row_back[i]])); + } + + output_msg(sformatf( "\nA and B arrays:\n\n")); + array_print(array1, k + l + m, n + 1, max_column_count); + + output_msg(sformatf( "\nInput delta vector:\n")); + for (i = 0; i < n; i++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e", i, + col_name[col_back[i]], (double) delta2[i])); + output_msg(sformatf( "\n")); + } + + for (i = 0; i < k + l + m; i++) + { + if (inv_res[i] == 0) + continue; + output_msg(sformatf( "\nInput inv_res is non zero:\n")); + output_msg(sformatf( "%6d %-12.12s %10.2e", i, + row_name[row_back[i]], (double) inv_res[i])); + output_msg(sformatf( "\n")); + } + } +/* + * Call CL1 + */ + + if (debug_inverse == TRUE) + { + output_msg(sformatf( + "k, l, m, n, max_col, max_row\t%d\t%d\t%d\t%d\t%d\t%d\n", + k, l, m, n, max_column_count, max_row_count)); + } + + kode = 1; + iter = 1000; + count_calls++; + +#ifdef INVERSE_CL1MP + if (inv_ptr->mp == TRUE) + { + cl1mp(k, l, m, n, + nklmd, n2d, array1, + &kode, inv_ptr->mp_tolerance, &iter, + delta2, inv_res, &error, inv_cu, inv_iu, inv_is, TRUE, inv_ptr->mp_censor); + } + else + { + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, delta2, inv_res, &error, inv_cu, inv_iu, inv_is, TRUE); + } +#else + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, delta2, inv_res, &error, inv_cu, inv_iu, inv_is, TRUE); +#endif + if (kode == 3) + { + error_string = sformatf( + "Exceeded maximum iterations in inverse modeling: %d.\n" + "Recompile program with larger limit.", iter); + error_msg(error_string, STOP); + } + memcpy((void *) &(inv_delta1[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + for (i = 0; i < n; i++) + { + inv_delta1[col_back[i]] = delta2[i]; + } + +/* + * Debug, write results + */ + + if (debug_inverse == TRUE) + { + output_msg(sformatf( "kode: %d\titer: %d\terror: %e\n", kode, + iter, (double) error)); + output_msg(sformatf( "\nsolution vector:\n")); + for (i = 0; i < n; i++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e", i, + col_name[col_back[i]], (double) delta2[i])); + output_msg(sformatf( "\n")); + } + + output_msg(sformatf( "\nresidual vector:\n")); + for (i = 0; i < (k + l + m); i++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, + row_name[row_back[i]], (double) inv_res[i])); + } + } + + if (kode != 0) + { + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +unsigned long Phreeqc:: +get_bits(unsigned long bits, int position, int number) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns number of bits from position and below. + * position begins at 0. + */ + return ((bits >> (position + 1 - number)) & ~(~0 << number)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of minimal models + */ + minimal[count_minimal] = bits; + count_minimal++; + if (count_minimal >= max_minimal) + { + max_minimal *= 2; + minimal = + (unsigned long *) PHRQ_realloc(minimal, + (size_t) max_minimal * + sizeof(unsigned long)); + if (minimal == NULL) + malloc_error(); + } + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_good(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of good models, not necessarily minimal + */ + good[count_good] = bits; + count_good++; + if (count_good >= max_good) + { + max_good *= 2; + good = + (unsigned long *) PHRQ_realloc(good, + (size_t) max_good * + sizeof(unsigned long)); + if (good == NULL) + malloc_error(); + } + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_bad(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Keeps list of sets of phases with no feasible solution + */ + bad[count_bad] = bits; + count_bad++; + if (count_bad >= max_bad) + { + max_bad *= 2; + bad = + (unsigned long *) PHRQ_realloc(bad, + (size_t) max_bad * + sizeof(unsigned long)); + if (bad == NULL) + malloc_error(); + } + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +superset_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a superset of any of the minimal models + */ + int i; + unsigned long temp_bits_l; + for (i = 0; i < count_minimal; i++) + { + temp_bits_l = bits | minimal[i]; + if (temp_bits_l == bits) + { + return (TRUE); + } + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +subset_bad(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a superset of any of the bad models + */ + int i; + unsigned long temp_bits_l; + for (i = 0; i < count_bad; i++) + { + temp_bits_l = bits | bad[i]; + if (temp_bits_l == bad[i]) + { + return (TRUE); + } + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +subset_minimal(unsigned long bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks whether bits is a subset of any of the minimal models + */ + int i; + unsigned long temp_bits_l; + for (i = 0; i < count_minimal; i++) + { + temp_bits_l = bits | minimal[i]; + if (temp_bits_l == minimal[i]) + { + return (TRUE); + } + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +bit_print(unsigned long bits, int l) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints l bits of an unsigned long + */ + int i; + + for (i = l - 1; i >= 0; i--) + { + output_msg(sformatf( "%lu ", get_bits(bits, i, 1))); + } + output_msg(sformatf( "\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_model(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model + */ + int i, j, k; + int column; + int print_msg; + struct solution *solution_ptr; + struct master *master_ptr; + struct isotope *isotope_ptr; + LDBLE d1, d2, d3, d4; + char token[MAX_LENGTH]; +/* + * Update screen + */ + status(count_good, NULL); +/* + * print solution data, epsilons, and revised data + */ + if (pr.inverse == FALSE || pr.all == FALSE) + return (OK); + max_pct = 0; + scaled_error = 0; + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (equal(inv_delta1[i], 0.0, toler) == TRUE) + continue; + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + xsolution_zero(); + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + master_ptr->total = solution_ptr->totals[j].moles; + } + + output_msg(sformatf( "\nSolution %d: %s\n", inv_ptr->solns[i], + solution_ptr->description)); + output_msg(sformatf( + "\n%15.15s %12.12s %12.12s %12.12s\n", " ", + "Input", "Delta", "Input+Delta")); + master_alk->total = solution_ptr->total_alkalinity; + if (inv_ptr->carbon == TRUE) + { + d1 = solution_ptr->ph; + d2 = inv_delta1[col_ph + i] / inv_delta1[i]; + d3 = d1 + d2; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + output_msg(sformatf( + "%15.15s %12.3e +%12.3e =%12.3e\n", "pH", + (double) d1, (double) d2, (double) d3)); + if (inv_ptr->ph_uncertainties[i] > 0) + { + scaled_error += fabs(d2) / inv_ptr->ph_uncertainties[i]; +/* debug + output_msg(sformatf( "%e\t%e\t%e\n", fabs(d2) / inv_ptr->ph_uncertainties[i], fabs(d2), inv_ptr->ph_uncertainties[i])); + */ + } + else if (d2 != 0.0) + { + error_msg("Computing delta pH/uncertainty", CONTINUE); + } + } + for (j = 0; j < inv_ptr->count_elts; j++) + { + if (inv_ptr->elts[j].master->s == s_eminus) + continue; + d1 = inv_ptr->elts[j].master->total; + d2 = inv_delta1[col_epsilon + j * inv_ptr->count_solns + + i] / inv_delta1[i]; + d3 = d1 + d2; + + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + + output_msg(sformatf( + "%15.15s %12.3e +%12.3e =%12.3e\n", + inv_ptr->elts[j].master->elt->name, (double) d1, + (double) d2, (double) d3)); + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE) + { + d3 = fabs(d2 / d1); + if (d3 > max_pct) + max_pct = d3; + } + d4 = 0; + if (inv_ptr->elts[j].uncertainties[i] > 0) + { + d4 = fabs(inv_ptr->elts[j].uncertainties[i] * d1); + } + else if (inv_ptr->elts[j].uncertainties[i] < 0) + { + d4 = -inv_ptr->elts[j].uncertainties[i]; + } + if (d4 > 0) + { + scaled_error += fabs(d2) / d4; +/* debug + output_msg(sformatf( "%e\t%e\t%e\n", fabs(d2) / d4, fabs(d2), d4)); + */ + } + else if (d2 != 0.0) + { + error_msg("Computing delta element/uncertainty", CONTINUE); + } + } + if (inv_ptr->count_isotopes > 0) + { + /* adjustments to solution isotope composition */ + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (inv_ptr->isotope_unknowns[j].elt_name != + solution_ptr->isotopes[k].elt_name || + inv_ptr->isotope_unknowns[j].isotope_number != + solution_ptr->isotopes[k].isotope_number) + continue; + d1 = solution_ptr->isotopes[k].ratio; + d2 = inv_delta1[col_isotopes + + i * inv_ptr->count_isotope_unknowns + + j] / inv_delta1[i]; + d3 = d1 + d2; + + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + sprintf(token, "%d%s", + (int) inv_ptr->isotope_unknowns[j]. + isotope_number, + inv_ptr->isotope_unknowns[j].elt_name); + output_msg(sformatf( + "%15.15s %12g +%12g =%12g\n", token, + (double) d1, (double) d2, (double) d3)); +/* + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == FALSE ) { + d3 = fabs(d2/d1); + if (d3 > max_pct) max_pct = d3; + } + */ + if (solution_ptr->isotopes[k].x_ratio_uncertainty > 0) + { + scaled_error += + fabs(d2) / + solution_ptr->isotopes[k].x_ratio_uncertainty; +/* debug + output_msg(sformatf( "%e\t%e\t%e\n", fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty , fabs(d2), solution_ptr->isotopes[k].x_ratio_uncertainty)); + */ + } + else if (d2 != 0.0) + { + error_msg + ("Computing delta solution isotope/uncertainty", + CONTINUE); + } + } + } + } + } + +/* + * Adjustments to phases + */ + print_msg = FALSE; + if (inv_ptr->count_isotopes > 0) + { + output_msg(sformatf( "\nIsotopic composition of phases:\n")); + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (inv_ptr->phases[i].count_isotopes == 0) + continue; + j = col_phases + i; + if (equal(inv_delta1[j], 0.0, toler) == TRUE && + equal(min_delta[j], 0.0, toler) == TRUE && + equal(max_delta[j], 0.0, toler) == TRUE) + continue; + isotope_ptr = inv_ptr->phases[i].isotopes; + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + for (k = 0; k < inv_ptr->phases[i].count_isotopes; k++) + { + if (inv_ptr->isotopes[j].elt_name != + isotope_ptr[k].elt_name || + inv_ptr->isotopes[j].isotope_number != + isotope_ptr[k].isotope_number) + continue; + d1 = isotope_ptr[k].ratio; + column = + col_phase_isotopes + i * inv_ptr->count_isotopes + j; + if (inv_delta1[col_phases + i] != 0.0) + { + d2 = inv_delta1[column] / inv_delta1[col_phases + i]; + } + else + { + continue; + } + d3 = d1 + d2; + if (equal(d1, 0.0, 1e-7) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, 1e-7) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, 1e-7) == TRUE) + d3 = 0.0; + sprintf(token, "%d%s %s", + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name, + inv_ptr->phases[i].phase->name); + output_msg(sformatf( + "%15.15s %12g +%12g =%12g", token, + (double) d1, (double) d2, (double) d3)); + if (fabs(d2) > (isotope_ptr[k].ratio_uncertainty + toler)) + { + output_msg(sformatf( " **")); + print_msg = TRUE; + } + output_msg(sformatf( "\n")); + if (isotope_ptr[k].ratio_uncertainty > 0) + { + scaled_error += + fabs(d2) / isotope_ptr[k].ratio_uncertainty; +/* debug + output_msg(sformatf( "%e\t%e\t%e\n", fabs(d2) / isotope_ptr[k].ratio_uncertainty, fabs(d2), isotope_ptr[k].ratio_uncertainty)); + */ + } + else if (d2 != 0.0) + { + error_msg + ("Computing delta phase isotope/uncertainty", + CONTINUE); + } + } + } + } + } + if (print_msg == TRUE) + { + output_msg(sformatf( + "\n**\tWARNING: The adjustment to at least one isotopic" + "\n\tcomposition of a phase exceeded the specified uncertainty" + "\n\tfor the phase. If the phase is not constrained to dissolve" + "\n\tor precipitate, then the isotopic composition of the phase" + "\n\tis also unconstrained.\n")); + } + output_msg(sformatf( "\n%-20.20s %7s %12.12s %12.12s\n", + "Solution fractions:", " ", "Minimum", "Maximum")); + for (i = 0; i < inv_ptr->count_solns; i++) + { + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + output_msg(sformatf( "%11s%4d %12.3e %12.3e %12.3e\n", + "Solution", inv_ptr->solns[i], (double) d1, (double) d2, + (double) d3)); + } + + output_msg(sformatf( "\n%-25.25s %2s %12.12s %12.12s\n", + "Phase mole transfers:", " ", "Minimum", "Maximum")); + for (i = col_phases; i < col_redox; i++) + { + if (equal(inv_delta1[i], 0.0, toler) == TRUE && + equal(min_delta[i], 0.0, toler) == TRUE && + equal(max_delta[i], 0.0, toler) == TRUE) + continue; + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + output_msg(sformatf( + "%15.15s %12.3e %12.3e %12.3e %s\n", col_name[i], + (double) d1, (double) d2, (double) d3, + inv_ptr->phases[i - col_phases].phase->formula)); + } + + output_msg(sformatf( "\n%-25.25s\n", "Redox mole transfers:")); + for (i = col_redox; i < col_epsilon; i++) + { + if (equal(inv_delta1[i], 0.0, toler) == TRUE) + continue; + output_msg(sformatf( "%15.15s %12.3e\n", col_name[i], + (double) inv_delta1[i])); + } + + output_msg(sformatf( + "\nSum of residuals (epsilons in documentation): %12.3e\n", + ((double) (error / SCALE_EPSILON)))); + output_msg(sformatf( + "Sum of delta/uncertainty limit: %12.3e\n", + (double) scaled_error)); + output_msg(sformatf( + "Maximum fractional error in element concentration: %12.3e\n", + (double) max_pct)); +/* + * Flush buffer after each model + */ + output_flush(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_model_heading(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model headings to selected output file + */ + int i; + char token[MAX_LENGTH]; + if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) + return (OK); + std::vector heading_names; + int l = (punch.high_precision == FALSE) ? 15 : 20; + +/* + * Print sum of residuals and maximum fractional error + */ + heading_names.push_back(sformatf("%*s\t", l, "Sum_resid")); + heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U")); + heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr")); + +/* + * Print solution numbers + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "Soln_%d", inv_ptr->solns[i]); + std::string tok1(token); + tok1.append("_min"); + std::string tok2(token); + tok2.append("_max"); + + heading_names.push_back(sformatf("%*s\t", l, token)); + heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + } +/* + * Print phase names + */ + for (i = col_phases; i < col_redox; i++) + { + + std::string tok1(col_name[i]); + tok1.append("_max"); + std::string tok2(col_name[i]); + tok2.append("_max"); + + heading_names.push_back(sformatf("%*s\t", l, col_name[i])); + heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + + } + + size_t j; + + user_punch_count_headings = heading_names.size(); + user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, + (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + + for (j = 0; j < heading_names.size(); j++) + { + fpunchf_heading(heading_names[j].c_str()); + user_punch_headings[j] = string_hsave(heading_names[j].c_str()); + } + fpunchf_heading("\n"); +/* + * Flush buffer after each model + */ + punch_flush(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_model(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model to selected output file + */ + int i; + LDBLE d1, d2, d3; + if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) + return (OK); + n_user_punch_index = 0; +/* + * write residual info + */ + if (punch.high_precision == FALSE) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) (error / SCALE_EPSILON)); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) scaled_error); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) max_pct); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) (error / SCALE_EPSILON)); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) scaled_error); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) max_pct); + } +/* + * write solution fractions + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + if (punch.high_precision == FALSE) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + } + } +/* + * write phase transfers + */ + for (i = col_phases; i < col_redox; i++) + { + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + if (punch.high_precision == FALSE) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + } + } + punch_msg("\n"); + +/* + * Flush buffer after each model + */ + punch_flush(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +unsigned long Phreeqc:: +set_bit(unsigned long bits, int position, int value) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets a single bit + */ + unsigned long temp_bits_l; + + temp_bits_l = 1 << position; + if (value == 0) + { + temp_bits_l = ~temp_bits_l; + temp_bits_l = bits & temp_bits_l; + } + else + { + temp_bits_l = bits | temp_bits_l; + } + return (temp_bits_l); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +next_set_phases(struct inverse *inv_ptr, + int first_of_model_size, int model_size) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + unsigned long temp_bits_l; + +/* + * min_ and max_position are arrays, logically with length + * of model_size, that contain minimum and maximum + * phase numbers that can be in that model position. + * + * now contains a list of phase numbers to mark as in for this + * model + */ + +/* + * Initialize for a given model_size + */ + if (first_of_model_size == TRUE) + { + for (i = 0; i < model_size; i++) + { + min_position[i] = i; + now[i] = i; + max_position[i] = inv_ptr->count_phases - model_size + i; + } + } + else + { +/* + * Determine next combination of phases for fixed model_size + */ + for (i = (model_size - 1); i >= 0; i--) + { + if (now[i] < max_position[i]) + { + now[i]++; + if (i < (model_size - 1)) + { + k = now[i]; + for (j = (i + 1); j < model_size; j++) + { + k++; + now[j] = k; + } + } + break; + } + } + if (i < 0) + return (FALSE); + } +/* + * Set bits which switch in phases + */ + temp_bits_l = 0; + for (j = 0; j < model_size; j++) + { + temp_bits_l += (1 << now[j]); + } + phase_bits = temp_bits_l; + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +range(struct inverse *inv_ptr, unsigned long cur_bits) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes the model from cur_bits and sequentially determines the + * minimum and maximum values for each solution fraction and + * each phase mass transfer. + */ + int i, j; + int k, l, m, n; + int f; + unsigned long bits; + LDBLE error2; +/* + * Include forced solutions and phases in range calculation + */ + for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) + { + if (i < inv_ptr->count_phases) + { + if (inv_ptr->phases[i].force == TRUE) + { + cur_bits = set_bit(cur_bits, i, 1); + } + } + else + { + if (inv_ptr->force_solns[i - inv_ptr->count_phases] == TRUE) + { + cur_bits = set_bit(cur_bits, i, 1); + } + } + } + + memcpy((void *) &(min_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); +/* + * Switch bits so that phases are high and solutions are low + */ + bits = + get_bits(cur_bits, inv_ptr->count_phases + inv_ptr->count_solns - 1, + inv_ptr->count_solns); + bits += + (get_bits(cur_bits, inv_ptr->count_phases - 1, inv_ptr->count_phases) + << inv_ptr->count_solns); +/* + * Do range calculation + */ + for (i = 0; i < inv_ptr->count_solns + inv_ptr->count_phases; i++) + { + if (inv_ptr->count_solns == i + 1) + { + min_delta[i] = 1.0; + max_delta[i] = 1.0; + continue; + } + if (get_bits(bits, i, 1) == 0) + continue; +/* + * Calculate min and max + */ + for (f = -1; f < 2; f += 2) + { + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; /* number of variables */ +/* + * Copy equations + */ + memcpy((void *) &(array1[0]), (void *) &(array[0]), + (size_t) max_column_count * max_row_count * sizeof(LDBLE)); + memcpy((void *) &(delta2[0]), (void *) &(delta[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(delta3[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(delta_save[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(inv_res[0]), (void *) &(inv_zero[0]), + (size_t) max_row_count * sizeof(LDBLE)); + +/* + * Change optimization + */ + for (j = 0; j < k; j++) + { + memcpy((void *) &(array1[j * max_column_count]), + (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } + array1[i] = 1.0; + if (f < 1) + { + array1[n] = -fabs(inv_ptr->range_max); + } + else + { + array1[n] = fabs(inv_ptr->range_max); + } + shrink(inv_ptr, array1, array1, + &k, &l, &m, &n, cur_bits, delta2, col_back, row_back); + /* + * Save delta constraints + */ + for (j = 0; j < n; j++) + { + delta_save[col_back[j]] = delta2[j]; + } + if (debug_inverse == TRUE) + { + output_msg(sformatf( "\nInput delta:\n\n")); + for (j = 0; j < n; j++) + { + output_msg(sformatf( "\t%d %s\t%g\n", j, + col_name[col_back[j]], (double) delta2[j])); + } + output_msg(sformatf( "\nA and B arrays:\n\n")); + array_print(array1, k + l + m, n + 1, max_column_count); + } + kode = 1; + iter = 200; + count_calls++; +#ifdef INVERSE_CL1MP + if (inv_ptr->mp == TRUE) + { + cl1mp(k, l, m, n, + nklmd, n2d, array1, + &kode, inv_ptr->mp_tolerance, &iter, + delta2, inv_res, &error2, inv_cu, inv_iu, inv_is, TRUE, + inv_ptr->mp_censor); + } + else + { + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, delta2, inv_res, &error2, inv_cu, inv_iu, inv_is, + TRUE); + } +#else + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, delta2, inv_res, &error2, inv_cu, inv_iu, inv_is, TRUE); +#endif + if (kode != 0) + { + output_msg(sformatf( + "Error in subroutine range. Kode = %d\n", kode)); + } + + if (debug_inverse == TRUE) + { + output_msg(sformatf( "kode: %d\titer: %d\terror: %e\n", + kode, iter, (double) error2)); + output_msg(sformatf( "k, l, m, n: %d\t%d\t%d\t%d\n", k, + l, m, n)); + output_msg(sformatf( "\nsolution vector %s\n", + col_name[i])); + for (j = 0; j < n; j++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e", j, + col_name[col_back[j]], (double) delta2[j])); + output_msg(sformatf( "\n")); + } + + output_msg(sformatf( "\nresidual vector:\n")); + for (j = 0; j < (k + l + m); j++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", j, + row_name[row_back[j]], (double) inv_res[j])); + } + } + for (j = 0; j < n; j++) + { + if (col_back[j] == i) + break; + } + if (f < 0) + { + min_delta[i] = delta2[j]; + } + else + { + max_delta[i] = delta2[j]; + } + for (j = 0; j < n; j++) + { + delta3[col_back[j]] = delta2[j]; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, + int *k, int *l, int *m, int *n, + unsigned long cur_bits, + LDBLE * delta_l, int *col_back_l, int *row_back_l) +/* ---------------------------------------------------------------------- */ +{ +/* + * Shrink eliminates any rows that are all zeros and any columns + * that are not in cur_bits, result is put in array_out + * + * k, l, m, n return the new sizes of the array. + * delta is remapped to retain any non-negativity constraints + * Col_back maps columns that remain back to original columns + * Row_back maps rows that remain back to original rows + */ + int i, j, row; + int k1, l1, m1; + int cur_col, column; + int nonzero; +/* + * Copy array_in to array_out + */ + if (array_in != array_out) + { + for (i = 0; i < (*k + *l + *m); i++) + { + memcpy(&(array_out[i * max_column_count]), + &(array_in[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + } + } +/* + * Determine columns to eliminate + */ + for (i = 0; i < (*n + 1); i++) + col_back_l[i] = i; + +/* + * Drop phases not in model + */ + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (get_bits(cur_bits, i, 1) == 0) + { + col_back_l[col_phases + i] = -1; + /* drop isotopes */ + if (inv_ptr->count_isotopes > 0) + { + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + column = + col_phase_isotopes + i * inv_ptr->count_isotopes + j; + col_back_l[column] = -1; + } + } + } + } +/* + * Drop solutions not in model + */ + for (i = 0; i < (inv_ptr->count_solns - 1); i++) + { + if (get_bits(cur_bits, inv_ptr->count_phases + i, 1) == 0) + { + col_back_l[i] = -1; + /* drop all epsilons for the solution */ + for (j = 0; j < inv_ptr->count_elts; j++) + { + column = col_epsilon + j * inv_ptr->count_solns + i; + col_back_l[column] = -1; + } + /* drop pH for the solution */ + if (inv_ptr->carbon == TRUE) + { + column = col_ph + i; + col_back_l[column] = -1; + } + /* drop isotopes */ + if (inv_ptr->count_isotopes > 0) + { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + column = + col_isotopes + i * inv_ptr->count_isotope_unknowns + + j; + col_back_l[column] = -1; + } + } + } + } + +/* + * Drop epsilons not used + */ + for (i = col_epsilon; i < *n; i++) + { + if (col_back_l[i] < 0) + continue; + for (j = 0; j < (*k + *l + *m); j++) + { + if (array_out[j * max_column_count + i] != 0) + break; + } + if (j == (*k + *l + *m)) + { + col_back_l[i] = -1; + } + } +/* + * rewrite array_out + */ + cur_col = 0; + for (i = 0; i < (*n + 1); i++) + { + if (col_back_l[i] < 0) + continue; + if (cur_col == col_back_l[i]) + { + cur_col++; + continue; + } + for (j = 0; j < (*k + *l + *m); j++) + { + array_out[j * max_column_count + cur_col] = + array_out[j * max_column_count + i]; + } + col_back_l[cur_col] = col_back_l[i]; + delta_l[cur_col] = delta_l[i]; + cur_col++; + } + *n = cur_col - 1; +/* + * Eliminate unnecessary optimization eqns + */ + row = 0; + k1 = 0; + for (i = 0; i < *k; i++) + { + if (memcmp(&(array_out[i * max_column_count]), &(inv_zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) + { + continue; + } +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + k1++; + } + +/* + * Eliminate unnecessary equality eqns + */ + l1 = 0; + for (i = *k; i < (*k + *l); i++) + { + nonzero = FALSE; + for (j = 0; j < *n; j++) + { + if (equal(array_out[i * max_column_count + j], 0.0, toler) == + FALSE) + { + nonzero = TRUE; + break; + } + } + if (nonzero == FALSE) + continue; +/* + if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) { + continue; + } + */ +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + l1++; + } +/* + * Eliminate unnecessary inequality eqns + */ + m1 = 0; + for (i = (*k + *l); i < (*k + *l + *m); i++) + { + nonzero = FALSE; + for (j = 0; j < *n; j++) + { + if (equal(array_out[i * max_column_count + j], 0.0, toler) == + FALSE) + { + nonzero = TRUE; + break; + } + } + if (nonzero == FALSE) + continue; +/* + if (memcmp(&(array_out[i * max_column_count]), &(zero[0]), + (size_t) (*n) * sizeof(LDBLE)) == 0) { + continue; + } + */ +/* + memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), + (size_t) max_column_count * sizeof(LDBLE)); + */ + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + row_back_l[row] = i; + row++; + m1++; + } + + *k = k1; + *l = l1; + *m = m1; +/* + * Scale all inequality rows + */ + + for (i = *k + *l; i < *k + *l + *m; i++) + { + for (j = 0; j < *n + 1; j++) + { + array_out[i * max_column_count + j] *= SCALE_ALL; + } + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_solns(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check_solns checks that each solution can be charge balanced within + * the given constraints. If not, it is an error and the program will + * terminate. + */ + int i, j; + int k, l, m, n; + int return_value; + unsigned long bits; + LDBLE error2; + + memcpy((void *) &(min_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(max_delta[0]), (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + +/* + * Switch bits so that phases are high and solutions are low + */ + return_value = OK; + for (i = 0; i < inv_ptr->count_solns; i++) + { + bits = 0; + bits += 1 << (inv_ptr->count_phases + i); +/* + * Check for feasibility of charge balance with given uncertainties + */ + k = row_mb; /* rows in A */ + l = row_epsilon - row_mb; /* rows in C */ + m = count_rows - row_epsilon; /* rows in E */ + n = count_unknowns; /* number of variables */ +/* debug + output_msg(sformatf( "\nColumns\n")); + for (j = 0; j < n; j++) { + output_msg(sformatf( "\t%d\t%s\n", j, col_name[j])); + } + + output_msg(sformatf( "\nRows\n")); + for (j = 0; j < k + l + m; j++) { + output_msg(sformatf( "\t%d\t%s\n", j, row_name[j])); + } + + output_msg(sformatf( "\nA and B arrays:\n\n")); + array_print(array, k + l + m, + n + 1, max_column_count); + */ +/* + * Copy equations + */ + memcpy((void *) &(array1[0]), (void *) &(array[0]), + (size_t) max_column_count * max_row_count * sizeof(LDBLE)); + memcpy((void *) &(delta2[0]), (void *) &(delta[0]), + (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(inv_res[0]), (void *) &(inv_zero[0]), + (size_t) max_row_count * sizeof(LDBLE)); + +/* + * Keep optimization + */ +/* + * Zero out mass balance rows and fraction rows + */ + for (j = row_mb; j < row_charge; j++) + { + memcpy((void *) &(array1[j * max_column_count]), + (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * Set fraction of solution to 1.0 + */ + array1[(row_charge - 1) * max_column_count + i] = 1.0; + array1[(row_charge - 1) * max_column_count + n] = 1.0; + +/* + * Zero out charge balance rows for other solutions + */ + for (j = 0; j < inv_ptr->count_solns; j++) + { + if (j == i) + continue; + memcpy((void *) &(array1[(row_charge + j) * max_column_count]), + (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } + +/* + * Zero out isotope mole balance + */ + for (j = row_isotopes; j < row_epsilon; j++) + { + memcpy((void *) &(array1[j * max_column_count]), + (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } + +/* + * Zero out isotope uncertainties + */ + for (j = row_isotope_epsilon; j < count_rows; j++) + { + memcpy((void *) &(array1[j * max_column_count]), + (void *) &(inv_zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); + } +/* + * Can't Zero out epsilon constraint rows for other solutions because not sure which + * are which + */ + + shrink(inv_ptr, array1, array1, + &k, &l, &m, &n, bits, delta2, col_back, row_back); +/* Debug + + output_msg(sformatf( "\nColumns\n")); + for (j = 0; j < n; j++) { + output_msg(sformatf( "\t%d\t%s\n", j, col_name[col_back[j]])); + } + + output_msg(sformatf( "\nRows\n")); + for (j = 0; j < k + l + m; j++) { + output_msg(sformatf( "\t%d\t%s\n", j, row_name[row_back[j]])); + } + + output_msg(sformatf( "\nA and B arrays:\n\n")); + array_print(array1, k + l + m, + n + 1, max_column_count); + + output_msg(sformatf( "\nInput delta vector:\n")); + for (j=0; j < n; j++) { + output_msg(sformatf( "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j])); + output_msg(sformatf( "\n")); + } + */ + + kode = 1; + iter = 200; + count_calls++; + cl1(k, l, m, n, + nklmd, n2d, array1, + &kode, toler, &iter, delta2, inv_res, &error2, inv_cu, inv_iu, inv_is, TRUE); + + if (kode != 0) + { + error_string = sformatf( + "Not possible to balance solution %d with input uncertainties.", + inv_ptr->solns[i]); + error_msg(error_string, CONTINUE); + return_value = ERROR; + } + +/* Debug + output_msg(sformatf( "kode: %d\titer: %d\terror: %e\n", kode, iter, error)); + output_msg(sformatf( "k, l, m, n: %d\t%d\t%d\t%d\n", k, l, m, n)); + + output_msg(sformatf( "\nsolution vector %s\n", col_name[i])); + for (j = 0; j < n; j++) { + output_msg(sformatf( "%6d %-12.12s %10.2e", j, col_name[col_back[j]], delta2[j])); + output_msg(sformatf( "\n")); + } + + output_msg(sformatf( "\nresidual vector:\n")); + for (j = 0; j < (k + l + m); j++) { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", j, row_name[row_back[j]], inv_res[j])); + } + */ + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +post_mortem(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Post_mortem simply identifies which equality and inequality of the + * array have not been satisfied. + * + */ + int i, j; + LDBLE sum; +/* + * Check equalities + */ + output_msg(sformatf( + "\nPost_mortem examination of inverse modeling:\n\n")); + for (i = row_mb; i < row_epsilon; i++) + { + sum = 0; + for (j = 0; j < count_unknowns; j++) + { + sum += inv_delta1[j] * array[i * max_column_count + j]; + } + + if (equal(sum, array[(i * max_column_count) + count_unknowns], toler) + == FALSE) + { + output_msg(sformatf( + "\tERROR: equality not satisfied for %s, %e.\n", + row_name[i], + (double) (sum - array[(i * max_column_count) + count_unknowns]))); + } + } +/* + * Check inequalities + */ + for (i = row_epsilon; i < count_rows; i++) + { + sum = 0; + for (j = 0; j < count_unknowns; j++) + { + sum += inv_delta1[j] * array[i * max_column_count + j]; + } + + if (sum > array[(i * max_column_count) + count_unknowns] + toler) + { + output_msg(sformatf( + "\tERROR: inequality not satisfied for %s, %e\n", + row_name[i], + (double) (sum - array[(i * max_column_count) + count_unknowns]))); + } + } +/* + * Check dissolution/precipitation constraints + */ + for (i = 0; i < count_unknowns; i++) + { + if (delta_save[i] > 0.5 && inv_delta1[i] < -toler) + { + output_msg(sformatf( + "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", + i, col_name[i], (double) inv_delta1[i])); + } + else if (delta_save[i] < -0.5 && inv_delta1[i] > toler) + { + output_msg(sformatf( + "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", + i, col_name[i], (double) inv_delta1[i])); + } + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +test_cl1_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * checks that equality and inequalities are satisfied + * + */ + int i, j; + LDBLE sum; + int local_debug_inverse = debug_inverse; + local_debug_inverse = TRUE; +/* + * Check equalities + */ + bool rv = true; + if (debug_inverse) + { + output_msg(sformatf( + "\nTesting cl1 inverse modeling:\n\n")); + } + for (i = row_mb; i < row_epsilon; i++) + { + sum = 0; + for (j = 0; j < count_unknowns; j++) + { + sum += inv_delta1[j] * array[i * max_column_count + j]; + } + + if (equal(sum, array[(i * max_column_count) + count_unknowns], toler) == FALSE) + { + if (debug_inverse) + { + output_msg(sformatf("\tERROR: equality not satisfied for %s, %e.\n", row_name[i], + (double) (sum - array[(i * max_column_count) + count_unknowns]))); + } + rv = false; + } + } +/* + * Check inequalities + */ + for (i = row_epsilon; i < count_rows; i++) + { + sum = 0; + for (j = 0; j < count_unknowns; j++) + { + sum += inv_delta1[j] * array[i * max_column_count + j]; + } + + if (sum > array[(i * max_column_count) + count_unknowns] + toler) + { + if (debug_inverse) + { + output_msg(sformatf( + "\tERROR: inequality not satisfied for %s, %e\n", + row_name[i], + (double) (sum - array[(i * max_column_count) + count_unknowns]))); + } + rv = false; + } + } +/* + * Check dissolution/precipitation constraints + */ + for (i = 0; i < count_unknowns; i++) + { + if (delta_save[i] > 0.5 && inv_delta1[i] < -toler) + { + if (debug_inverse) + { + output_msg(sformatf( + "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", + i, col_name[i], (double) inv_delta1[i])); + } + rv = false; + + } + else if (delta_save[i] < -0.5 && inv_delta1[i] > toler) + { + if (debug_inverse) + { + output_msg(sformatf( + "\tERROR: Dissolution/precipitation constraint not satisfied for column %d, %s, %e.\n", + i, col_name[i], (double) inv_delta1[i])); + } + rv = false; + } + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +carbon_derivs(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, n, temp; + LDBLE c_uncertainty, d_carbon, alk_plus, alk_minus; + struct solution *solution_ptr_orig, *solution_ptr; + + inv_ptr->dalk_dph = (LDBLE *) free_check_null(inv_ptr->dalk_dph); + inv_ptr->dalk_dph = + (LDBLE *) PHRQ_malloc((size_t) inv_ptr->count_solns * sizeof(LDBLE)); + if (inv_ptr->dalk_dph == NULL) + malloc_error(); + + inv_ptr->dalk_dc = (LDBLE *) free_check_null(inv_ptr->dalk_dc); + inv_ptr->dalk_dc = + (LDBLE *) PHRQ_malloc((size_t) inv_ptr->count_solns * sizeof(LDBLE)); + if (inv_ptr->dalk_dc == NULL) + malloc_error(); + + for (i = 0; i < inv_ptr->count_solns; i++) + { + solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &n, TRUE); + if (solution_ptr_orig == NULL) + { + error_string = sformatf( "Solution %d for inverse " + "modeling not found.", inv_ptr->solns[i]); + error_msg(error_string, STOP); + } +/* + * Find carbon uncertainty + */ + c_uncertainty = 0; + d_carbon = 0; + for (j = 0; j < inv_ptr->count_elts; j++) + { + if (inv_ptr->elts[j].master == s_co3->secondary) + { + c_uncertainty = inv_ptr->elts[j].uncertainties[i]; + break; + } + } + if (c_uncertainty < 0.0) + { + d_carbon = -c_uncertainty; + } + else if (c_uncertainty > 0.0) + { + for (k = 0; solution_ptr_orig->totals[k].description != NULL; k++) + { + if (strcmp(solution_ptr_orig->totals[k].description, "C(4)") + == 0) + { + d_carbon = solution_ptr_orig->totals[k].moles / + solution_ptr_orig->mass_water * c_uncertainty; + break; + } + + } + } + +/* + * Make four copies of solution + * Modify ph and carbon in solutions + */ + set_ph_c(inv_ptr, i, solution_ptr_orig, -5, 0.0, 1.0, 0.0); + set_ph_c(inv_ptr, i, solution_ptr_orig, -4, 0.0, -1.0, 0.0); + if (c_uncertainty != 0) + { + set_ph_c(inv_ptr, i, solution_ptr_orig, -3, d_carbon, 0.0, 1.0); + set_ph_c(inv_ptr, i, solution_ptr_orig, -2, d_carbon, 0.0, -1.0); + } +/* */ + temp = pr.all; + pr.all = FALSE; + initial_solutions(FALSE); + pr.all = temp; +/* + * dAlk/dpH + */ + solution_ptr = solution_bsearch(-5, &n, TRUE); + alk_plus = solution_ptr->total_alkalinity; + solution_ptr = solution_bsearch(-4, &n, TRUE); + alk_minus = solution_ptr->total_alkalinity; + inv_ptr->dalk_dph[i] = (alk_plus - alk_minus) / + (2.0 * inv_ptr->ph_uncertainties[i]); +/* + * dAlk/dC + */ + if (d_carbon != 0) + { + solution_ptr = solution_bsearch(-3, &n, TRUE); + alk_plus = solution_ptr->total_alkalinity; + solution_ptr = solution_bsearch(-2, &n, TRUE); + alk_minus = solution_ptr->total_alkalinity; + inv_ptr->dalk_dc[i] = (alk_plus - alk_minus) / (2.0 * d_carbon); + } + else + { + inv_ptr->dalk_dc[i] = 0.0; + } + if (debug_inverse == TRUE) + { + output_msg(sformatf( "dAlk/dph = %e\tdAlk/dC = %e\n", + (double) inv_ptr->dalk_dph[i], + (double) inv_ptr->dalk_dc[i])); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_ph_c(struct inverse *inv_ptr, + int i, + struct solution *solution_ptr_orig, + int n_user_new, LDBLE d_carbon, LDBLE ph_factor, LDBLE c_factor) +/* ---------------------------------------------------------------------- */ +{ + int j, n_user_orig; + struct solution *solution_ptr; + struct conc *conc_ptr; + + n_user_orig = inv_ptr->solns[i]; + solution_duplicate(n_user_orig, n_user_new); + solution_ptr = solution_bsearch(n_user_new, &j, TRUE); + solution_ptr->new_def = TRUE; + solution_ptr->n_user_end = n_user_new; + solution_ptr->ph += inv_ptr->ph_uncertainties[i] * ph_factor; + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + conc_ptr = &solution_ptr->totals[j]; + conc_ptr->input_conc = + conc_ptr->moles / solution_ptr_orig->mass_water; + conc_ptr->units = string_hsave("Mol/kgw"); + if (strcmp(conc_ptr->description, "C(4)") == 0) + { + conc_ptr->input_conc += d_carbon * c_factor; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +isotope_balance_equation(struct inverse *inv_ptr, int row, int n) +/* ---------------------------------------------------------------------- */ +/* + * routine fills in an isotope balance equation + * + * row is the row in array that needs to be filled + * n is the isotope number in inv_ptr + */ +{ + int i, j, k; + LDBLE isotope_number; + int column; + LDBLE f; + struct master *primary_ptr; + struct solution *solution_ptr; + struct isotope *isotope_ptr; +/* + * Determine primary master species and isotope number for + * isotope mass-balance equation + */ + column = 0; + primary_ptr = master_bsearch_primary(inv_ptr->isotopes[n].elt_name); + isotope_number = inv_ptr->isotopes[n].isotope_number; + /* isotope element must be defined */ + if (primary_ptr == NULL) + { + error_string = sformatf( + "In isotope calculation: element not defined: %s.", + inv_ptr->isotopes[n].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + + /* isotope element must be primary */ + if (primary_ptr->primary != TRUE) + { + error_string = sformatf( "Isotope mass-balance may only be used" + " for total element concentrations.\n" + "Secondary species not allowed: %s.", + inv_ptr->isotopes[n].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + +/* + * Fill in terms for each solution + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (i == (inv_ptr->count_solns - 1)) + { + f = -1.0; + } + else + { + f = 1.0; + } + + /* mixing fraction term */ + solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + isotope_ptr = solution_ptr->isotopes; + for (j = 0; j < solution_ptr->count_isotopes; j++) + { + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) + { + array[row * max_column_count + i] += + f * isotope_ptr[j].total * isotope_ptr[j].ratio; + } + } + + /* epsilon of total moles of element valence * ratio */ + for (j = 0; j < solution_ptr->count_isotopes; j++) + { + + /* What to do with H and O, skip for now ??? */ + if (primary_ptr == s_hplus->primary + || primary_ptr == s_h2o->primary) + continue; + + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) + { + + /* find column of master for solution i */ + for (k = 0; k < inv_ptr->count_elts; k++) + { + if (isotope_ptr[j].master == inv_ptr->elts[k].master) + break; + } + column = col_epsilon + (k * inv_ptr->count_solns) + i; + array[row * max_column_count + column] += + f * isotope_ptr[j].ratio; + } + } + + /* epsilon of ratio * total of element valence */ + for (j = 0; j < solution_ptr->count_isotopes; j++) + { + + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) + { + + /* find column of epsilon for ratio of valence */ + for (k = 0; k < inv_ptr->count_isotope_unknowns; k++) + { + if (isotope_ptr[j].master == + inv_ptr->isotope_unknowns[k].master + && isotope_ptr[j].isotope_number == + inv_ptr->isotope_unknowns[k].isotope_number) + { + column = + col_isotopes + + (i * inv_ptr->count_isotope_unknowns) + k; + } + } + array[row * max_column_count + column] += + f * isotope_ptr[j].total; + } + } + } +/* + * Fill in terms for each phase + */ + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (inv_ptr->phases[i].count_isotopes <= 0) + continue; + isotope_ptr = inv_ptr->phases[i].isotopes; + for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) + { + if (isotope_ptr[j].primary == primary_ptr && + isotope_ptr[j].isotope_number == isotope_number) + { + /* term for alpha phase unknowns */ + column = col_phases + i; + array[row * max_column_count + column] = + isotope_ptr[j].ratio * isotope_ptr[j].coef; + /* term for phase isotope uncertainty unknown */ + column = col_phase_isotopes + i * inv_ptr->count_isotopes + n; + array[row * max_column_count + column] = isotope_ptr[j].coef; + break; + } + } + + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through elements for which isotope balances are requested + * and make a array of isotope structures + * return total number of isotope unknowns and structure array + */ + int i, k; + LDBLE isotope_number; + struct master *primary_ptr; + int count_isotopes; + struct isotope *isotopes; + + if (inv_ptr->count_isotopes == 0) + { + *isotope_unknowns = NULL; + return (0); + } + isotopes = + (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); + if (isotopes == NULL) + malloc_error(); + count_isotopes = 0; + + for (i = 0; i < inv_ptr->count_isotopes; i++) + { + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + if (primary_ptr == NULL) + { + error_string = sformatf( + "Element not found for isotope calculation: %s.", + inv_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (primary_ptr->primary != TRUE) + { + error_string = sformatf( "Isotope mass-balance may only be used" + " for total element concentrations.\n" + "Secondary species not allowed: %s.", + inv_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + + /* nonredox element */ + if (primary_ptr->s->secondary == NULL) + { + isotopes = + (struct isotope *) PHRQ_realloc(isotopes, + (size_t) (count_isotopes + + 1) * + sizeof(struct isotope)); + if (isotopes == NULL) + malloc_error(); + isotopes[count_isotopes].primary = primary_ptr; + isotopes[count_isotopes].master = primary_ptr; + isotopes[count_isotopes].isotope_number = isotope_number; + isotopes[count_isotopes].elt_name = primary_ptr->elt->name; + count_isotopes++; + + /* redox element */ + } + else + { + + /* find master */ + for (k = 0; k < count_master; k++) + { + if (master[k] == primary_ptr) + break; + } + + /* sum all secondary for master */ + k++; + for (; k < count_master; k++) + { + if (master[k]->elt->primary != primary_ptr) + break; + isotopes = + (struct isotope *) PHRQ_realloc(isotopes, + (size_t) (count_isotopes + + + 1) * + sizeof(struct isotope)); + if (isotopes == NULL) + malloc_error(); + isotopes[count_isotopes].primary = primary_ptr; + isotopes[count_isotopes].master = master[k]; + isotopes[count_isotopes].isotope_number = isotope_number; + isotopes[count_isotopes].elt_name = master[k]->elt->name; + count_isotopes++; + } + } + } + *isotope_unknowns = isotopes; + return (count_isotopes); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_isotopes(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through elements for which isotope balances are requested + * and make sure each solution has isotope ratios defined + */ + int i, ii, j, k, l; + int err, found_isotope; + LDBLE isotope_number; + struct master *master_ptr, *primary_ptr; + struct solution *solution_ptr; + struct phase *phase_ptr; + char token[MAX_LENGTH]; + +/* + * Check solutions for necessary isotope data + */ + for (j = 0; j < inv_ptr->count_solns; j++) + { + solution_ptr = solution_bsearch(inv_ptr->solns[j], &i, TRUE); + xsolution_zero(); + add_solution(solution_ptr, 1.0, 1.0); +/* + * Go through inverse isotopes and make sure isotope data for each solution + * inv_ptr->isotopes has elements; inv_ptr->i_u has redox states and uncertainties + */ + for (i = 0; i < inv_ptr->count_isotopes; i++) + { + err = FALSE; + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + found_isotope = FALSE; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (solution_ptr->isotopes[k].primary == primary_ptr && + solution_ptr->isotopes[k].isotope_number == + isotope_number) + { + found_isotope = TRUE; + break; + } + } + if (found_isotope == TRUE) + continue; + + /* did not find isotope, which is ok if element not in solution */ + if (primary_ptr == s_h2o->primary + || primary_ptr == s_hplus->primary) + { + err = TRUE; + } + else if (primary_ptr->total > 0) + { + err = TRUE; + } + if (err == TRUE) + { + error_string = sformatf( + "In solution %d, isotope ratio(s) are needed for element: %g%s.", + solution_ptr->n_user, (double) isotope_number, + primary_ptr->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } +/* + * Go through solution isotopes and set uncertainties + */ + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + solution_ptr->isotopes[k].x_ratio_uncertainty = NAN; +/* + * Search for secondary or primary master in inverse uncertainties + */ + ii = -1; + for (i = 0; i < inv_ptr->count_i_u; i++) + { + master_ptr = master_bsearch(inv_ptr->i_u[i].elt_name); + if (master_ptr == solution_ptr->isotopes[k].master) + { + ii = i; + break; + } + if (master_ptr == solution_ptr->isotopes[k].primary) + { + ii = i; + } + } + /* solution isotope data not being used in inverse */ + if (ii == -1) + continue; + + i = ii; + /* use inverse-defined uncertainties first */ + if (j < inv_ptr->i_u[i].count_uncertainties + && inv_ptr->i_u[i].uncertainties[j] != NAN) + { + solution_ptr->isotopes[k].x_ratio_uncertainty = + inv_ptr->i_u[i].uncertainties[j]; + + /* use solution-defined uncertainties second */ + } + else if (solution_ptr->isotopes[k].ratio_uncertainty != NAN) + { + solution_ptr->isotopes[k].x_ratio_uncertainty = + solution_ptr->isotopes[k].ratio_uncertainty; + /* use isotope defaults third */ + } + else + { + sprintf(token, "%g%s", + (double) solution_ptr->isotopes[k].isotope_number, + solution_ptr->isotopes[k].elt_name); + for (l = 0; l < count_iso_defaults; l++) + { + if (strcmp(token, iso_defaults[l].name) == 0) + { + solution_ptr->isotopes[k].x_ratio_uncertainty = + iso_defaults[l].uncertainty; + error_string = sformatf( + "Solution %d, element %g%s: default isotope ratio uncertainty is used, %g.", + solution_ptr->n_user, + (double) solution_ptr->isotopes[k]. + isotope_number, + solution_ptr->isotopes[k].elt_name, + (double) solution_ptr->isotopes[k]. + x_ratio_uncertainty); + warning_msg(error_string); + break; + } + } + } + if (solution_ptr->isotopes[k].x_ratio_uncertainty == NAN) + { + error_string = sformatf( + "In solution %d, isotope ratio uncertainty is needed for element: %g%s.", + solution_ptr->n_user, + (double) solution_ptr->isotopes[k].isotope_number, + solution_ptr->isotopes[k].elt_name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } +/* + * Check phases for necessary isotope data + */ + for (j = 0; j < inv_ptr->count_phases; j++) + { + for (i = 0; i < inv_ptr->count_isotopes; i++) + { + primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); + isotope_number = inv_ptr->isotopes[i].isotope_number; + found_isotope = FALSE; + for (k = 0; k < inv_ptr->phases[j].count_isotopes; k++) + { + if (inv_ptr->phases[j].isotopes[k].primary == primary_ptr && + inv_ptr->phases[j].isotopes[k].isotope_number == + isotope_number) + { + found_isotope = TRUE; + break; + } + } + if (found_isotope == TRUE) + continue; + + /* did not find isotope, which is ok if element not in solution */ + phase_ptr = inv_ptr->phases[j].phase; + k = 0; + while (phase_ptr->next_elt[k].elt != NULL) + { + if (phase_ptr->next_elt[k].elt->primary == primary_ptr) + { + if (s_hplus->primary == primary_ptr || + s_h2o->primary == primary_ptr) + { + k++; + continue; + } + else + { + error_string = sformatf( + "In phase %s, isotope ratio(s) are needed for element: %g%s.", + phase_ptr->name, (double) isotope_number, + primary_ptr->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + } + k++; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_isotope_inequalities(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + int column; + char token[MAX_LENGTH]; + if (inv_ptr->count_isotopes <= 0) + return OK; + for (i = 0; i < inv_ptr->count_phases; i++) + { + if (inv_ptr->phases[i].count_isotopes <= 0) + continue; + + for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) + { + /* find index number */ + for (k = 0; k < inv_ptr->count_isotopes; k++) + { + if (inv_ptr->phases[i].isotopes[j].elt_name == + inv_ptr->isotopes[k].elt_name + && inv_ptr->phases[i].isotopes[j].isotope_number == + inv_ptr->isotopes[k].isotope_number) + { + break; + } + } + if (k >= inv_ptr->count_isotopes) + break; + column = col_phase_isotopes + i * inv_ptr->count_isotopes + k; +/* + * zero column if uncertainty is zero + */ + if (inv_ptr->phases[i].isotopes[j].ratio_uncertainty == 0) + { + for (k = 0; k < count_rows; k++) + { + array[k * max_column_count + column] = 0.0; + } + continue; + } + +/* + * optimization + */ + array[(column - col_epsilon) * max_column_count + column] = + SCALE_EPSILON / + inv_ptr->phases[i].isotopes[j].ratio_uncertainty; +/* + * two inequalities to account for absolute value + */ + /* for phases constrained to precipitate */ + if (inv_ptr->phases[i].constraint == PRECIPITATE) + { + array[count_rows * max_column_count + col_phases + i] = + inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = 1.0; + sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, + "iso pos"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + array[count_rows * max_column_count + col_phases + i] = + inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = -1.0; + sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, + "iso neg"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + /* for phases constrained to dissolve */ + } + else if (inv_ptr->phases[i].constraint == DISSOLVE) + { + array[count_rows * max_column_count + col_phases + i] = + -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = -1.0; + sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, + "iso pos"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + array[count_rows * max_column_count + col_phases + i] = + -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + array[count_rows * max_column_count + column] = 1.0; + sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, + "iso neg"); + row_name[count_rows] = string_hsave(token); + count_rows++; + + /* Error if phase is not constrained */ + } + else + { + error_string = sformatf( + "In isotope calculations, all phases containing isotopes must be" + " constrained.\nPhase %s is not constrained.\n", + inv_ptr->phases[i].phase->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +write_optimize_names(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, row; + char token[MAX_LENGTH]; + row = 0; +/* + * epsilons for analytical data + */ + for (j = 0; j < inv_ptr->count_elts; j++) + { + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "%s %s %d", "optimize", + inv_ptr->elts[j].master->elt->name, inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * pH + */ + if (carbon > 0) + { + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "%s %s %d", "optimize", "pH", inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * water + */ + sprintf(token, "%s %s", "optimize", "water"); + row_name[row] = string_hsave(token); + row++; +/* + * solution isotopes + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + sprintf(token, "%s %d%s %d", "optimize", + (int) inv_ptr->isotope_unknowns[j].isotope_number, + inv_ptr->isotope_unknowns[j].elt_name, inv_ptr->solns[i]); + row_name[row] = string_hsave(token); + row++; + } + } +/* + * phase isotopes + */ + + for (i = 0; i < inv_ptr->count_phases; i++) + { + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + sprintf(token, "%s %s %d%s", "optimize", + inv_ptr->phases[i].phase->name, + (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name); + row_name[row] = string_hsave(token); + row++; + } + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +dump_netpath(struct inverse *inverse_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l; + char string[MAX_LENGTH]; + char *ptr; + + /*if (netpath_dumped) return; */ + if (inverse_ptr->netpath == NULL) + return; + + /* open file */ + strcpy(string, inverse_ptr->netpath); + if (replace(".lon", ".lon", string) != TRUE) + { + strcat(string, ".lon"); + } + netpath_file = fopen(string, "w"); + if (netpath_file == NULL) + { + error_string = sformatf( "Can't open file, %s.", inverse_ptr->netpath); + error_msg(error_string, STOP); + } + add_to_file("netpath.fil", inverse_ptr->netpath); + + /* Header */ + fprintf(netpath_file, + "2.14 # File format\n"); + + /* write out each solution */ + for (i = 0; i < count_solution; i++) + { + if (solution[i]->n_user < 0) + continue; + + /* flags and description */ + ptr = solution[i]->description; + j = copy_token(string, &ptr, &l); + if (j != EMPTY) + { + sprintf(string, "%s", solution[i]->description); + } + else + { + sprintf(string, "Solution %d", solution[i]->n_user); + } + fprintf(netpath_file, "4020%s\n", string); + + /* lat/lon */ + fprintf(netpath_file, + " # Lat/lon\n"); + + /* well number */ + fprintf(netpath_file, + "%15d # Well number\n", + solution[i]->n_user); + + /* total number of wells */ + fprintf(netpath_file, + "%15d # Total wells\n", + count_solution); + + /* address */ + fprintf(netpath_file, + " # Address1\n"); + fprintf(netpath_file, + " # Address2\n"); + fprintf(netpath_file, + " # Address3\n"); + fprintf(netpath_file, + " # Address4\n"); + fprintf(netpath_file, + " # Address5\n"); + + /* temperature */ + fprintf(netpath_file, + "%15g # Temperature\n", + (double) solution[i]->tc); + + /* pH */ + fprintf(netpath_file, + "%15g # pH\n", + (double) solution[i]->ph); + + /* DO */ + print_total(netpath_file, solution[i], "O(0)", "Dissolved Oxygen"); + + /* TDIC */ + print_total(netpath_file, solution[i], "C(4)", "TDIC"); + + /* Tritium */ + print_isotope(netpath_file, solution[i], "3H(1)", "Tritium"); + + /* H2S */ + print_total(netpath_file, solution[i], "S(-2)", "H2S"); + + /* Calcium */ + print_total(netpath_file, solution[i], "Ca", "Calcium"); + + /* Eh */ + fprintf(netpath_file, + "%15g # Eh\n", + (double) (0.059 * solution[i]->solution_pe)); + + /* Magnesium */ + print_total(netpath_file, solution[i], "Mg", "Magnesium"); + + /* Sodium */ + print_total(netpath_file, solution[i], "Na", "Sodium"); + + /* Potassium */ + print_total(netpath_file, solution[i], "K", "Potassium"); + + /* Chloride */ + print_total(netpath_file, solution[i], "Cl", "Chloride"); + + /* Sulfate */ + print_total(netpath_file, solution[i], "S(6)", "Sulfate"); + + /* Fluoride */ + print_total(netpath_file, solution[i], "F", "Fluoride"); + + /* Silica */ + print_total(netpath_file, solution[i], "Si", "Silica"); + + /* Bromide */ + print_total(netpath_file, solution[i], "Br", "Bromide"); + + /* Boron */ + print_total(netpath_file, solution[i], "B", "Boron"); + + /* Barium */ + print_total(netpath_file, solution[i], "Ba", "Barium"); + + /* Lithium */ + print_total(netpath_file, solution[i], "Li", "Lithium"); + + /* Strontium */ + print_total(netpath_file, solution[i], "Sr", "Strontium"); + + /* Iron */ + print_total_multi(netpath_file, solution[i], "Iron", "Fe", "Fe(2)", + "Fe(3)", "", ""); + + + /* Manganese */ + print_total_multi(netpath_file, solution[i], "Manganese", "Mn", + "Mn(2)", "Mn(3)", "Mn(6)", "Mn(7)"); + + /* Nitrate */ + print_total(netpath_file, solution[i], "N(5)", "Nitrate"); + + /* Ammonium */ + print_total_multi(netpath_file, solution[i], "Ammonium", "N(-3)", + "Amm", "", "", ""); + + /* Phosphate */ + print_total(netpath_file, solution[i], "P", "Phosphate"); + + /* DOC */ + print_total_multi(netpath_file, solution[i], "DOC", "Fulvate", + "Humate", "", "", ""); + + /* Sp. Cond. */ + fprintf(netpath_file, + " # Sp. Cond.\n"); + + /* Density */ + fprintf(netpath_file, + " # Density\n"); + + /* Delta C-13 TDIC */ + print_isotope(netpath_file, solution[i], "13C(4)", "Delta C-13 TDIC"); + + /* C-14 TDIC */ + print_isotope(netpath_file, solution[i], "14C(4)", "C-14 TDIC"); + + /* Delta S-34 (SO4) */ + print_isotope(netpath_file, solution[i], "34S(6)", + "Delta S-34 (SO4)"); + + /* Delta S-34 (H2S) */ + print_isotope(netpath_file, solution[i], "34S(-2)", + "Delta S-34 (H2S)"); + + /* Delta Deuterium */ + print_isotope(netpath_file, solution[i], "2H(1)", "Delta Deuterium"); + + /* Delta O-18 */ + print_isotope(netpath_file, solution[i], "18O(-2)", "Delta O-18"); + + /* CH4 (aq) */ + print_total(netpath_file, solution[i], "C(-4)", "CH4 (aq)"); + + /* Sr 87/86 */ + print_isotope(netpath_file, solution[i], "87Sr", "Sr 87/86"); + + /* Al */ + print_total(netpath_file, solution[i], "Al", "Alumninum"); + + /* N2 (aq) */ + print_total(netpath_file, solution[i], "N(0)", "N2 (aq)"); + + /* N-15 of N2 (aq) */ + print_isotope(netpath_file, solution[i], "15N(0)", "N-15 of N2 (aq)"); + + /* N-15 of Nitrate */ + print_isotope(netpath_file, solution[i], "15N(5)", "N-15 of Nitrate"); + + /* N-15 of Ammonium */ + print_isotope(netpath_file, solution[i], "15N(-3)", + "N-15 of Ammonium"); + + /* Formation */ + fprintf(netpath_file, + " # Formation\n"); + + } + if (netpath_file != NULL) + { + fclose(netpath_file); + netpath_file = NULL; + } + return; +} + +/* ---------------------------------------------------------------------- */ +struct conc * Phreeqc:: +get_inv_total(struct solution *solution_ptr, const char *elt) +/* ---------------------------------------------------------------------- */ +{ + int i; + + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + if (strcmp(elt, solution_ptr->totals[i].description) == 0) + return (&solution_ptr->totals[i]); + } + return (NULL); + +} + +/* ---------------------------------------------------------------------- */ +struct isotope * Phreeqc:: +get_isotope(struct solution *solution_ptr, const char *elt) +/* ---------------------------------------------------------------------- */ +{ + int i; + + for (i = 0; i < solution_ptr->count_isotopes; i++) + { + if (strcmp(elt, solution_ptr->isotopes[i].isotope_name) == 0) + return (&solution_ptr->isotopes[i]); + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +print_total(FILE * l_netpath_file, struct solution *solution_ptr, + const char *elt, const char *string) +/* ---------------------------------------------------------------------- */ +{ + struct conc *tot_ptr; + tot_ptr = get_inv_total(solution_ptr, elt); + if (tot_ptr == NULL) + { + fprintf(l_netpath_file, + " # %s\n", + string); + } + else + { + fprintf(l_netpath_file, + "%15g # %s\n", + (double) (1000 * tot_ptr->moles / solution_ptr->mass_water), + string); + } +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +print_isotope(FILE * l_netpath_file, struct solution *solution_ptr, + const char *elt, const char *string) +/* ---------------------------------------------------------------------- */ +{ + struct isotope *iso_ptr; + iso_ptr = get_isotope(solution_ptr, elt); + if (iso_ptr == NULL) + { + fprintf(l_netpath_file, + " # %s\n", + string); + } + else + { + fprintf(l_netpath_file, + "%15g # %s\n", + (double) iso_ptr->ratio, string); + } +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +print_total_multi(FILE * l_netpath_file, struct solution *solution_ptr, + const char *string, const char *elt0, const char *elt1, + const char *elt2, const char *elt3, const char *elt4) +/* ---------------------------------------------------------------------- */ +{ + char elts[5][MAX_LENGTH]; + struct conc *tot_ptr; + LDBLE sum; + int i, found; + + strcpy(elts[0], elt0); + strcpy(elts[1], elt1); + strcpy(elts[2], elt2); + strcpy(elts[3], elt3); + strcpy(elts[4], elt4); + + + sum = 0; + found = FALSE; + for (i = 0; i < 5; i++) + { + tot_ptr = get_inv_total(solution_ptr, elts[i]); + if (tot_ptr == NULL) + { + continue; + } + else + { + sum += tot_ptr->moles; + found = TRUE; + } + } + if (found != TRUE) + { + fprintf(l_netpath_file, + " # %s\n", + string); + } + else + { + fprintf(l_netpath_file, + "%15g # %s\n", + (double) (1000 * sum / solution_ptr->mass_water), string); + } + return; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +dump_netpath_pat(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints model + */ + int i, j, k; + struct solution *solution_ptr, *solution_ptr_orig; + struct master *master_ptr; + LDBLE d1, d2, d3; + char string[MAX_LENGTH], string1[MAX_LENGTH], token[MAX_LENGTH]; + char *ptr, *str_ptr; + int l; + LDBLE sum, sum1, sum_iso, d; + LDBLE *array_save, *l_delta_save; + int count_unknowns_save, max_row_count_save, max_column_count_save, temp, + count_current_solutions, temp_punch; + int solnmap[10][2]; + struct isotope *isotope_ptr; + FILE *model_file; + struct elt_list *next_elt; + int exch, column; + LDBLE f; + struct rxn_token *rxn_ptr; +/* + * print solution data, epsilons, and revised data + */ + if (inv_ptr->pat == NULL) + return (OK); + + array_save = array; + l_delta_save = delta; + count_unknowns_save = count_unknowns; + max_row_count_save = max_row_count; + max_column_count_save = max_column_count; + + array = NULL; + delta = NULL; + count_unknowns = 0; + max_row_count = 0; + max_column_count = 0; + + count_current_solutions = 0; + count_inverse_models++; + + for (i = 0; i < inv_ptr->count_solns; i++) + { + if (equal(inv_delta1[i], 0.0, toler) == TRUE) + continue; + solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + + solution_duplicate(solution_ptr_orig->n_user, -6); + solution_ptr = solution_bsearch(-6, &j, TRUE); + xsolution_zero(); + + /* Adjust pH */ + if (inv_ptr->carbon == TRUE) + { + d1 = solution_ptr->ph; + d2 = inv_delta1[col_ph + i] / inv_delta1[i]; + d3 = d1 + d2; + solution_ptr->ph = d3; + } + + /* put original totals in master */ + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + master_ptr->total = solution_ptr->totals[j].moles; + } + + /* ignore alkalinity */ + /*master_alk->total = solution_ptr->total_alkalinity; */ + + /* update total in master */ + for (j = 0; j < inv_ptr->count_elts; j++) + { + if (inv_ptr->elts[j].master->s == s_eminus) + continue; + d1 = inv_ptr->elts[j].master->total; + d2 = inv_delta1[col_epsilon + j * inv_ptr->count_solns + + i] / inv_delta1[i]; + d3 = d1 + d2; + inv_ptr->elts[j].master->total = d3; + } + + /* put updated total back in solution */ + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + master_ptr = master_bsearch(solution_ptr->totals[j].description); + solution_ptr->totals[j].moles = master_ptr->total; + } + + + /* update isotopes in solution */ + if (inv_ptr->count_isotopes > 0) + { + /* adjustments to solution isotope composition */ + for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) + { + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (inv_ptr->isotope_unknowns[j].elt_name != + solution_ptr->isotopes[k].elt_name || + inv_ptr->isotope_unknowns[j].isotope_number != + solution_ptr->isotopes[k].isotope_number) + continue; + d1 = solution_ptr->isotopes[k].ratio; + d2 = inv_delta1[col_isotopes + + i * inv_ptr->count_isotope_unknowns + + j] / inv_delta1[i]; + d3 = d1 + d2; + solution_ptr->isotopes[k].ratio = d3; + } + } + } + + set_initial_solution(-6, -7); + temp = pr.all; + pr.all = FALSE; + temp_punch = pr.punch; + pr.punch = FALSE; + phrq_io->Set_punch_on(false); + initial_solutions(FALSE); + pr.all = temp; + pr.punch = temp_punch; + phrq_io->Set_punch_on(pr.punch == TRUE); + solution_ptr = solution_bsearch(-7, &j, TRUE); + + /* Header */ + ptr = solution_ptr_orig->description; + if (copy_token(string, &ptr, &l) != EMPTY) + { + fprintf(netpath_file, "%d. %s\n", count_inverse_models, + solution_ptr_orig->description); + } + else + { + fprintf(netpath_file, "%d. Solution %d\n", count_inverse_models, + solution_ptr_orig->n_user); + } + + /* bookkeeping */ + count_pat_solutions++; + solnmap[count_current_solutions][0] = solution_ptr_orig->n_user; + solnmap[count_current_solutions][1] = count_pat_solutions; + count_current_solutions++; + + /* Dump info to .pat file */ + print_total_pat(netpath_file, "C", "C"); + print_total_pat(netpath_file, "S", "S"); + print_total_pat(netpath_file, "Ca", "CA"); + print_total_pat(netpath_file, "Al", "AL"); + print_total_pat(netpath_file, "Mg", "MG"); + print_total_pat(netpath_file, "Na", "NA"); + print_total_pat(netpath_file, "K", "K"); + print_total_pat(netpath_file, "Cl", "CL"); + print_total_pat(netpath_file, "F", "F"); + print_total_pat(netpath_file, "Si", "SI"); + print_total_pat(netpath_file, "Br", "BR"); + print_total_pat(netpath_file, "B", "B"); + print_total_pat(netpath_file, "Ba", "BA"); + print_total_pat(netpath_file, "Li", "LI"); + print_total_pat(netpath_file, "Sr", "SR"); + print_total_pat(netpath_file, "Fe", "FE"); + print_total_pat(netpath_file, "Mn", "MN"); + print_total_pat(netpath_file, "N", "N"); + print_total_pat(netpath_file, "P", "P"); + fprintf(netpath_file, "%14g # TEMP\n", (double) solution_ptr->tc); + print_total_pat(netpath_file, "S(-2)", "H2S"); + print_total_pat(netpath_file, "S(6)", "SO4"); + + /* N15 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "15N") != NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # N15\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # N15\n", + (double) (sum_iso / sum)); + } + + /* RS of N */ + sum = 0; + sum = + total("N(-3)") * -3 + total("N(0)") * 0 + total("N(3)") * 3 + + total("N(5)") * 5; + sum1 = total("N(-3)") + total("N(0)") + total("N(3)") + total("N(5)"); + if (sum1 == 0) + { + fprintf(netpath_file, "%14g* # RS of N\n", (double) sum1); + } + else + { + fprintf(netpath_file, "%14g # RS of N\n", + (double) (sum / sum1)); + } + + /* DOX */ + print_total_pat(netpath_file, "O(0)", "DOX"); + + /*HCO3 */ + d = 1000 * sum_match_species("*HCO3*", "C"); + if (d == 0.0) + { + fprintf(netpath_file, "%14g* # HCO3\n", (double) d); + } + else + { + fprintf(netpath_file, "%14g # HCO3\n", (double) d); + } + + /* pH */ + fprintf(netpath_file, "%14g # PH\n", (double) solution_ptr->ph); + + /*H2CO3* */ + d = 1000 * (molality("H2CO3") + molality("CO2")); + if (d == 0.0) + { + fprintf(netpath_file, "%14g* # H2CO3\n", (double) d); + } + else + { + fprintf(netpath_file, "%14g # H2CO3\n", (double) d); + } + + /*CO3 */ + d = sum_match_species("*CO3*", "C"); + d -= sum_match_species("*HCO3*", "C"); + d *= 1000.0; + if (d == 0.0) + { + fprintf(netpath_file, "%14g* # CO3\n", (double) d); + } + else + { + fprintf(netpath_file, "%14g # CO3\n", (double) d); + } + + /* CARBONATES */ + print_total_pat(netpath_file, "C(4)", "CARBONATES"); + print_total_pat(netpath_file, "Fe(2)", "FE2+"); + print_total_pat(netpath_file, "Fe(3)", "FE3+"); + print_total_pat(netpath_file, "Mn(2)", "MN2+"); + print_total_pat(netpath_file, "Mn(3)", "MN3+"); + print_total_pat(netpath_file, "Mn(6)", "MN6+"); + print_total_pat(netpath_file, "Mn(7)", "MN7+"); + print_total_pat(netpath_file, "C(-4)", "CH4"); + print_total_pat(netpath_file, "Doc", "DOC"); + + /*RS OF DOC */ + fprintf(netpath_file, "%14g* # RS OF DOC\n", 0.0); + + /* Blank */ + print_total_pat(netpath_file, "Blank", "BLANK"); + + /*C13 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "13C") != NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # C13\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # C13\n", + (double) (sum_iso / sum)); + } + + /*C14 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "14C") != NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # C14\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # C14\n", + (double) (sum_iso / sum)); + } + + /*SR87 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "87Sr") != + NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # SR87\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # SR87\n", + (double) (sum_iso / sum)); + } + + /*D*/ sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "2H") != NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # D\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # D\n", (double) (sum_iso / sum)); + } + + /*O-18 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "18O") != NULL) + { + if (strcmp(solution_ptr->isotopes[k].elt_name, "O(-2)") == 0) + { + d = solution_ptr->total_o - total("O(0)"); + } + else if (strcmp(solution_ptr->isotopes[k].elt_name, "H(1)") + == 0) + { + d = solution_ptr->total_h - total("H(0)"); + } + else + { + d = total(solution_ptr->isotopes[k].elt_name); + } + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # O-18\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # O-18\n", + (double) (sum_iso / sum)); + } + + /*TRITIUM*/ sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "3H") != NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # TRITIUM\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # TRITIUM\n", + (double) (sum_iso / sum)); + } + + /*34SSO4 */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "34S(6)") != + NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # 34SSO4\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # 34SSO4\n", + (double) (sum_iso / sum)); + } + + /*34SH2S */ + sum_iso = 0; + sum = 0; + for (k = 0; k < solution_ptr->count_isotopes; k++) + { + if (strstr(solution_ptr->isotopes[k].isotope_name, "34S(-2)") != + NULL) + { + d = total(solution_ptr->isotopes[k].elt_name); + sum_iso += solution_ptr->isotopes[k].ratio * d; + sum += d; + } + } + if (sum == 0) + { + fprintf(netpath_file, "%14g* # 34SH2S\n", (double) sum); + } + else + { + fprintf(netpath_file, "%14g # 34SH2S\n", + (double) (sum_iso / sum)); + } + + /* Well number */ + fprintf(netpath_file, "%14d # Well number\n", + count_pat_solutions); + } + free_model_allocs(); + array = array_save; + delta = l_delta_save; + count_unknowns = count_unknowns_save; + max_row_count = max_row_count_save; + max_column_count = max_column_count_save; + +/* + * Open model file + */ + strcpy(string, inv_ptr->pat); + replace(".pat", "", string); + string_trim(string); + sprintf(string1, "%s-%d.mod", string, count_inverse_models); + model_file = fopen(string1, "w"); + if (model_file == NULL) + { + error_string = sformatf( "Can't open file, %s.", string); + error_msg(error_string, STOP); + } + add_to_file("model.fil", string1); + + +/* + * Write header + */ + fprintf(model_file, "%s\n", string); + +/* + * Write well numbers + */ + for (i = 0; i < count_current_solutions; i++) + { + fprintf(model_file, "%3d", solnmap[i][1]); + } + fprintf(model_file, "\n"); +/* + * Write elements + */ + xsolution_zero(); + for (j = 0; j < count_master; j++) + { + master[j]->in = FALSE; + } + for (j = 0; j < inv_ptr->count_elts; j++) + { + master_ptr = inv_ptr->elts[j].master; + master_ptr = master_ptr->elt->primary; + if (strcmp(master_ptr->elt->name, "Alkalinity") == 0) + continue; + if (strcmp(master_ptr->elt->name, "H") == 0) + continue; + if (strcmp(master_ptr->elt->name, "O") == 0) + continue; + if (strcmp(master_ptr->elt->name, "X") == 0) + continue; + if (strcmp(master_ptr->elt->name, "E") == 0) + continue; + master_ptr->in = TRUE; + } + for (j = 0; j < count_master; j++) + { + if (master[j]->in == TRUE) + { + strcpy(string, master[j]->elt->name); + str_toupper(string); + fprintf(model_file, " %-2s", string); + } + } + fprintf(model_file, " %-2s", "RS"); +/* + * Add isotope mole balance + */ + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + sprintf(string, "%d%s", (int) inv_ptr->isotopes[j].isotope_number, + inv_ptr->isotopes[j].elt_name); + if (strcmp(string, "13C") == 0) + fprintf(model_file, " %-2s", "I1"); + if (strcmp(string, "14C") == 0) + fprintf(model_file, " %-2s", "I2"); + if (strcmp(string, "34S") == 0) + fprintf(model_file, " %-2s", "I3"); + if (strcmp(string, "87Sr") == 0) + fprintf(model_file, " %-2s", "I4"); + if (strcmp(string, "15N") == 0) + fprintf(model_file, " %-2s", "I9"); + if (strcmp(string, "2H") == 0) + fprintf(model_file, " %-2s", "D "); + if (strcmp(string, "3H") == 0) + fprintf(model_file, " %-2s", "TR"); + if (strcmp(string, "18O") == 0) + fprintf(model_file, " %-2s", "18"); + } + + /* end of element line */ + fprintf(model_file, "\n"); + +/* + * Write phase information + */ + for (i = 0; i < inv_ptr->count_phases; i++) + { + j = col_phases + i; + /* skip if not in model */ +/* if (equal (inv_delta1[j], 0.0, toler) == TRUE) continue;*/ + + /* Do not include Na exchange phase */ + if (strcmp_nocase(inv_ptr->phases[i].name, "NaX") == 0) + continue; +/* + * Determine if exchange reaction + */ + exch = FALSE; + for (next_elt = inv_ptr->phases[i].phase->next_elt; + next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, "X") == 0) + { + exch = TRUE; + break; + } + } +/* + * Write phase name and constraints + */ + strncpy(string, inv_ptr->phases[i].name, (size_t) 8); + str_ptr = string_pad(string, 10); + str_ptr[10] = '\0'; + if (inv_ptr->phases[i].force == TRUE) + { + str_ptr[8] = 'F'; + } + else + { + str_ptr[8] = ' '; + } + switch (inv_ptr->phases[i].constraint) + { + case EITHER: + str_ptr[9] = ' '; + break; + case PRECIPITATE: + if (exch == TRUE) + { + str_ptr[9] = '+'; + } + else + { + str_ptr[9] = '-'; + } + break; + case DISSOLVE: + if (exch == TRUE) + { + str_ptr[9] = '-'; + } + else + { + str_ptr[9] = '+'; + } + break; + } + fprintf(model_file, "%-10s", str_ptr); + str_ptr = (char *) free_check_null(str_ptr); +/* + * Write stoichiometry + */ + for (next_elt = inv_ptr->phases[i].phase->next_elt; + next_elt->elt != NULL; next_elt++) + { + f = 1.0; + if (exch == TRUE) + f = -1.0; + master_ptr = next_elt->elt->primary; + if (strcmp(master_ptr->elt->name, "Alkalinity") == 0) + continue; + if (strcmp(master_ptr->elt->name, "H") == 0) + continue; + if (strcmp(master_ptr->elt->name, "O") == 0) + continue; + if (strcmp(master_ptr->elt->name, "E") == 0) + continue; + strcpy(string, master_ptr->elt->name); + if (strcmp(master_ptr->elt->name, "X") == 0) + { + strcpy(string, "Na"); + f = 1.0; + } + str_toupper(string); + fprintf(model_file, " %-2s%12.7f", string, + (double) (next_elt->coef * f)); + } +/* + * Calculate RS + */ + sum = 0; + for (rxn_ptr = inv_ptr->phases[i].phase->rxn_s->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + if (rxn_ptr->s == s_hplus) + continue; + if (rxn_ptr->s == s_h2o) + continue; + if (rxn_ptr->s->secondary == NULL && rxn_ptr->s != s_eminus) + continue; + if (rxn_ptr->s == s_o2) + { + sum += 4 * rxn_ptr->coef; + } + else if (rxn_ptr->s == s_h2) + { + sum += -2 * rxn_ptr->coef; + } + else if (rxn_ptr->s == s_eminus) + { + sum += -1 * rxn_ptr->coef; + } + else + { + strcpy(string, rxn_ptr->s->secondary->elt->name); + replace("(", " ", string); + replace(")", " ", string); + ptr = string; + copy_token(token, &ptr, &l); + copy_token(string1, &ptr, &l); + sscanf(string1, SCANFORMAT, &f); + sum += f * rxn_ptr->coef; + } + } + if (sum != 0.0) + fprintf(model_file, " %-2s%12.7f", "RS", (double) sum); +/* + * Add isotopes + */ + + for (k = 0; k < inv_ptr->phases[i].count_isotopes; k++) + { + isotope_ptr = inv_ptr->phases[i].isotopes; + d1 = isotope_ptr[k].ratio; + for (j = 0; j < inv_ptr->count_isotopes; j++) + { + if ((inv_ptr->isotopes[j].elt_name != isotope_ptr[k].elt_name) + || (inv_ptr->isotopes[j].isotope_number != + isotope_ptr[k].isotope_number)) + continue; + break; + } + d2 = 0.0; + if (j < inv_ptr->count_isotopes) + { + column = col_phase_isotopes + i * inv_ptr->count_isotopes + j; + if (inv_delta1[col_phases + i] != 0.0) + { + d2 = inv_delta1[column] / inv_delta1[col_phases + i]; + } + } + d3 = d1 + d2; + sprintf(string, "%d%s", (int) isotope_ptr[k].isotope_number, + isotope_ptr[k].elt_name); + if (strcmp(string, "13C") == 0) + fprintf(model_file, " %-2s%12.7f", "I1", (double) d3); + if (strcmp(string, "14C") == 0) + fprintf(model_file, " %-2s%12.7f", "I2", (double) d3); + if (strcmp(string, "34S") == 0) + { + fprintf(model_file, " %-2s%12.7f", "I3", (double) d3); + fprintf(model_file, " %-2s%12.7f", "I7", 0.0); + } + if (strcmp(string, "87Sr") == 0) + fprintf(model_file, " %-2s%12.7f", "I4", (double) d3); + if (strcmp(string, "15N") == 0) + fprintf(model_file, " %-2s%12.7f", "I9", (double) d3); + if (strcmp(string, "2H") == 0) + fprintf(model_file, " %-2s%12.7f", "D ", (double) d3); + if (strcmp(string, "3H") == 0) + fprintf(model_file, " %-2s%12.7f", "TR", (double) d3); + if (strcmp(string, "18O") == 0) + fprintf(model_file, " %-2s%12.7f", "18", (double) d3); + } +/* + * Done with stoichiometry + */ + fprintf(model_file, "\n"); + } + fprintf(model_file, "\n"); +/* + * Write extra stuff at bottom + */ + /* + (Iflag(i),i=2,6), (P(i),i=1,2), (Isdocrs(i),i=0,5), Disalong, + (C14dat(i),i=1,5), (Usera(i),i=1,2), + (C14dat(i),i=8,9), i10, i11, (C14dat(i),i=12,13), + (Dbdata(Well(0),i),i=44,47), Dbdata(Well(0),49), + ((Dbdata(Well(iwell),i),i=44,47),Dbdata(Well(iwell),49),Usera(iwell),iwell=1,Iflag(1)+1) + 9030 FORMAT (5(I2),2(F8.4),6(I1),F6.3,/, + 7(F8.3),/, + 2(F8.3),2(F8.0), 2(F8.3),/, + 5(F8.3),/, + 7(6(F8.3),/)) + */ + /* iflags */ + /*fprintf(model_file,"%2d", i); */ /* not written, 1, mixing, number of mixing wells -1 */ + fprintf(model_file, "%2d", 3); /* 2, exchange */ + i = 0; + if (inv_ptr->count_isotopes > 0) + i = 1; + fprintf(model_file, "%2d", i); /* 3, Rayleigh */ + fprintf(model_file, "%2d", 1); /* 4, A0 model */ + fprintf(model_file, "%2d", 0); /* 5, Mook/Deines */ + fprintf(model_file, "%2d", 0); /* 6, Evaporation/Dilution */ + /* p */ + fprintf(model_file, "%8.4f%8.4f", 1.0, 0.0); /* P(1),(2) fraction of CO2, fraction of Ca in exch */ + fprintf(model_file, "000000"); /* isdocrs(0,5) doc, rs? */ + fprintf(model_file, "%6.3f\n", 1.0); /* disalong */ + fprintf(model_file, + " 0.000 100.000 0.000 0.000 -25.000 100.000 100.000\n"); + fprintf(model_file, + " 0.000 0.000 0. 0. 0.000 0.000 \n"); + /* Final well data */ + fprintf(model_file, " -40.000 -25.000 0.000 0.000 0.000\n"); + /* other wells */ + for (i = 0; i < count_current_solutions - 1; i++) + { + fprintf(model_file, + " -40.000 -25.000 0.000 0.000 0.000 100.000\n"); + } + fprintf(model_file, "\n"); + fclose(model_file); + state = INVERSE; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +print_total_pat(FILE * l_netpath_file, const char *elt, const char *string) +/* ---------------------------------------------------------------------- */ +{ + LDBLE d; + d = 1000.0 * total(elt); + if (strcmp(elt,"O(0)") == 0) + { + d = d/2.0; + } + if (d == 0) + { + fprintf(l_netpath_file, "%14g%1s # %s\n", (double) d, "*", string); + } + else + { + fprintf(l_netpath_file, "%14g%1s # %s\n", (double) d, " ", string); + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_initial_solution(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + int j; + struct solution *solution_ptr; + struct conc *conc_ptr; + + solution_duplicate(n_user_old, n_user_new); + solution_ptr = solution_bsearch(n_user_new, &j, TRUE); + solution_ptr->new_def = TRUE; + solution_ptr->n_user_end = n_user_new; + for (j = 0; solution_ptr->totals[j].description != NULL; j++) + { + conc_ptr = &solution_ptr->totals[j]; + conc_ptr->input_conc = conc_ptr->moles / solution_ptr->mass_water; + conc_ptr->units = string_hsave("Mol/kgw"); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_to_file(const char *filename, const char *string) +/* ---------------------------------------------------------------------- */ +{ + FILE *model_file; + char c; + int i; + char string_line[MAX_LINE]; + + model_file = fopen(filename, "r"); + if (model_file == NULL) + { + model_file = fopen(filename, "w"); + if (model_file == NULL) + { + error_string = sformatf( "Can't open file, %s.", filename); + error_msg(error_string, STOP); + } + } + i = 0; + /* + * Read each line of file, check if equal to string; if not, append string to file + */ + for (;;) + { + c = getc(model_file); + if (c != EOF && c != '\n' && i != MAX_LINE) + { + string_line[i] = c; + i++; + continue; + } + if (i >= MAX_LINE) + { + string_line[MAX_LINE - 1] = '\0'; + error_string = sformatf( "File name in %s is greater than %d characters: %s\n", filename, MAX_LINE, string_line); + warning_msg(error_string); + } + else + { + string_line[i] = '\0'; + } + /* new line or eof */ + string_trim(string_line); + if (strcmp(string_line, string) == 0) + { + fclose(model_file); + return (OK); + } + /* eof, add line */ + if (c == EOF) + { + fclose(model_file); + model_file = fopen(filename, "a"); + if (model_file) + { + fprintf(model_file, "%s\n", string); + fclose(model_file); + } + else + { + error_string = sformatf("Could not open netpath model file: %s\n", filename); + error_msg(error_string, STOP); + } + return (OK); + } + /* new line */ + i = 0; + } +} + diff --git a/rename_cpp/isotopes.cpp b/rename_cpp/isotopes.cpp new file mode 100644 index 00000000..883eace2 --- /dev/null +++ b/rename_cpp/isotopes.cpp @@ -0,0 +1,1852 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species information for isotopes + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + + int j, l; + struct master_isotope *master_isotope_ptr, *master_isotope_ptr_major; + char token[MAX_LENGTH]; + struct element *elt_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "isotope", /* 0 */ + "total_is_major" /* 1 */ + }; + int count_opt_list = 2; + + master_isotope_ptr = NULL; + elt_ptr = NULL; +/* + * Read name followed by options + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* isotope */ + if (elt_ptr == NULL) + { + error_string = sformatf( + "The element of which this isotope is a minor isotope has not been defined, %s. ISOTOPES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + /* + * Save an isotope + */ + master_isotope_ptr = NULL; + j = copy_token(token, &next_char, &l); + master_isotope_ptr = master_isotope_store(token, TRUE); + master_isotope_ptr->elt = elt_ptr; + master_isotope_ptr->minor_isotope = TRUE; + master_isotope_ptr->total_is_major = FALSE; + /* + * Read units + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting units for isotopic values, %s. ISOTOPES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + master_isotope_ptr->units = string_hsave(token); + /* + * Read standard + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting isotope ratio of standard, %s. ISOTOPES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + sscanf(token, SCANFORMAT, &(master_isotope_ptr->standard)); + opt_save = OPTION_DEFAULT; + break; + case 1: /* total_is_major_isotope */ + error_string = sformatf( + "Obsolete identifier. The total of the element must be the sum of all isotopes. ISOTOPES data block.\n%s", + line); + warning_msg(error_string); + break; + case OPTION_DEFAULT: +/* + * Read and element name + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting an element name for isotope definition, %s. ISOTOPES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + elt_ptr = element_store(token); + master_isotope_ptr = master_isotope_store(token, TRUE); + master_isotope_ptr_major = master_isotope_ptr; + master_isotope_ptr->elt = elt_ptr; + master_isotope_ptr->minor_isotope = FALSE; + master_isotope_ptr->total_is_major = FALSE; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate calculate_value + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, length, line_length, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct calculate_value *calculate_value_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; +/* + * Read advection number (not currently used) + */ + n = -1; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + calculate_value_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in CALCULATE_VALUE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPT_1; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read calculate_value name */ +/* + * Read calculate_value name + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a name for calculate_value definition, %s. CALCULATE_VALUES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + calculate_value_ptr = calculate_value_store(token, TRUE); + calculate_value_ptr->new_def = TRUE; + calculate_value_ptr->commands = + (char *) PHRQ_malloc(sizeof(char)); + if (calculate_value_ptr->commands == NULL) + malloc_error(); + calculate_value_ptr->commands[0] = '\0'; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + opt_save = OPT_1; + break; + + case OPT_1: /* read command */ + length = (int) strlen(calculate_value_ptr->commands); + line_length = (int) strlen(line); + calculate_value_ptr->commands = + (char *) PHRQ_realloc(calculate_value_ptr->commands, + (size_t) (length + line_length + + 2) * sizeof(char)); + if (calculate_value_ptr->commands == NULL) + malloc_error(); + calculate_value_ptr->commands[length] = ';'; + calculate_value_ptr->commands[length + 1] = '\0'; + strcat((calculate_value_ptr->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* output_msg(sformatf( "%s", calculate_value[0].commands)); + */ return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_isotope_ratios(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads isotope_ratio info, ratios are calculated with + * Basic programs read in CALCULATE_VALUE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct isotope_ratio *isotope_ratio_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "no_options" /* 0 */ + }; + int count_opt_list = 0; +/* + * Read number (not currently used) + */ + n = -1; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + isotope_ratio_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ISOTOPE_RATIOS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* read isotope_ratio name */ +/* + * Read isotope_ratio name + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a name for isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_ratio_ptr = isotope_ratio_store(token, TRUE); + /* + * Read isotope + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a name of isotope for an isotope_ratio definition, %s. ISOTOPE_RATIOS data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_ratio_ptr->isotope_name = string_hsave(token); + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_isotope_alphas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads isotope_alpha info, ratios are calculated with + * Basic programs read in CALCULATE_VALUE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct isotope_alpha *isotope_alpha_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "no_options" /* 0 */ + }; + int count_opt_list = 0; +/* + * Read number (not currently used) + */ + n = -1; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + isotope_alpha_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ISOTOPE_ALPHAS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* read isotope_alpha name */ +/* + * Read isotope_alpha name + */ + if (copy_token(token, &next_char, &l) == EMPTY) + { + error_string = sformatf( + "Expecting a name for isotope_alpha definition, %s. ISOTOPE_ALPHAS data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + isotope_alpha_ptr = isotope_alpha_store(token, TRUE); + isotope_alpha_ptr->name = string_hsave(token); + if (copy_token(token, &next_char, &l) != EMPTY) + { + isotope_alpha_ptr->named_logk = string_hsave(token); + } + + + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_isotopes(struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + const char *ptr; + struct master_isotope *master_isotope_ptr; + LDBLE total_moles; + /* + * zero out isotopes + */ + for (i = 0; i < count_master_isotope; i++) + { + master_isotope[i]->moles = 0; + } + master_isotope_ptr = master_isotope_search("H"); + if (master_isotope_ptr != NULL) + { + total_moles = total_h_x; + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + total_moles); + } + master_isotope_ptr = master_isotope_search("O"); + if (master_isotope_ptr != NULL) + { + total_moles = total_o_x; + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + total_moles); + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + ptr = solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) + continue; + if (master_isotope_ptr->minor_isotope == FALSE) + { + total_moles = total(master_isotope_ptr->name); + calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + total_moles); + } + } + /* + * Set isotopes flag + */ + initial_solution_isotopes = FALSE; + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->minor_isotope == TRUE + && master_isotope[i]->moles > 0) + { + initial_solution_isotopes = TRUE; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calculate_isotope_moles(struct element *elt_ptr, + struct solution *solution_ptr, LDBLE total_moles) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l_iter; + int count_isotopes, total_is_major; + const char *ptr; + struct master_isotope *master_isotope_ptr, *master_isotope_ptr1; + struct master_isotope list[MAX_ELTS]; + LDBLE m_major, tot; + /* + * Get total concentration of elt_ptr + */ + if (total_moles <= 0) + { + error_string = sformatf( + "Can not calculate molality of isotopes, molality of element is zero, %s", + elt_ptr->name); + warning_msg(error_string); + return (ERROR); + } + m_major = total_moles; + /* + * Make a list of isotopes + */ + count_isotopes = 0; + total_is_major = FALSE; + master_isotope_ptr = master_isotope_search("H"); + if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) + { + memcpy(&(list[count_isotopes]), master_isotope_ptr, + sizeof(struct master_isotope)); + list[count_isotopes].ratio = 1.0; + if (list[count_isotopes].minor_isotope == FALSE) + { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + master_isotope_ptr = master_isotope_search("O"); + if ((master_isotope_ptr != NULL) && (master_isotope_ptr->elt == elt_ptr)) + { + memcpy(&(list[count_isotopes]), master_isotope_ptr, + sizeof(struct master_isotope)); + list[count_isotopes].ratio = 1.0; + if (list[count_isotopes].minor_isotope == FALSE) + { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + ptr = solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) + continue; + if (master_isotope_ptr->elt != elt_ptr) + continue; + memcpy(&(list[count_isotopes]), master_isotope_ptr, + sizeof(struct master_isotope)); + if (list[count_isotopes].minor_isotope == FALSE) + { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; + } + /* + * Loop to calculate isotope molalities + */ + for (l_iter = 0; l_iter < itmax; l_iter++) + { + tot = 0; + for (i = 0; i < count_isotopes; i++) + { + if (list[i].minor_isotope == FALSE) + { + list[i].moles = m_major; + tot += m_major; + continue; + } + if (strcmp_nocase(list[i].units, "permil") == 0) + { + from_permil(&(list[i]), m_major); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pct") == 0) + { + from_pct(&(list[i]), total_moles); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pmc") == 0) + { + from_pct(&(list[i]), total_moles); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "tu") == 0) + { + from_tu(&(list[i])); + tot += list[i].moles; + continue; + } + if (strcmp_nocase(list[i].units, "pci/l") == 0) + { + from_pcil(&(list[i])); + tot += list[i].moles; + continue; + } + error_string = sformatf( "Isotope units not recognized, %s", + list[i].units); + input_error++; + error_msg(error_string, CONTINUE); + } + if (total_is_major == TRUE) + break; + if (fabs(total_moles - tot) < convergence_tolerance * total_moles) + { + break; + } + else + { + m_major = m_major * total_moles / tot; + } + } + if (l_iter >= itmax) + { + error_msg("Failed to converge in CALCULATE_ISOTOPE_MOLES.", STOP); + } + /* + * Update master_isotope + */ + for (j = 0; j < count_master_isotope; j++) + { + for (i = 0; i < count_isotopes; i++) + { + if (list[i].name == master_isotope[j]->name) + { + memcpy(master_isotope[j], &(list[i]), + sizeof(struct master_isotope)); + } + } + } + /* + * Update solution + */ + master_isotope_ptr1 = master_isotope_search("H"); + if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) + { + total_h_x = m_major; + } + master_isotope_ptr1 = master_isotope_search("O"); + if (master_isotope_ptr1 != NULL && master_isotope_ptr1->elt == elt_ptr) + { + total_o_x = m_major; + } + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + ptr = solution_ptr->totals[i].description; + master_isotope_ptr = master_isotope_search(ptr); + if (master_isotope_ptr == NULL) + continue; + if (master_isotope_ptr->elt != elt_ptr) + continue; + solution_ptr->totals[i].moles = master_isotope_ptr->moles; + solution_ptr->totals[i].input_conc = master_isotope_ptr->moles; + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total) +/* ---------------------------------------------------------------------- */ +{ + LDBLE r; + + r = (master_isotope_ptr->ratio / 1000. + + 1.0) * master_isotope_ptr->standard; + master_isotope_ptr->moles = major_total * r; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +from_pct(struct master_isotope *master_isotope_ptr, LDBLE total_moles) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = + master_isotope_ptr->ratio / 100 * master_isotope_ptr->standard * + total_moles; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +from_tu(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = + master_isotope_ptr->ratio * master_isotope_ptr->standard * + mass_water_aq_x / gfw_water; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +from_pcil(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +{ + master_isotope_ptr->moles = + master_isotope_ptr->ratio * master_isotope_ptr->standard * + mass_water_aq_x / gfw_water; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_initial_solution_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + + if (pr.initial_isotopes == FALSE || pr.all == FALSE) + return (OK); + if (state != INITIAL_SOLUTION) + return (OK); + if (initial_solution_isotopes == FALSE) + return (OK); +/* + * Print heading + */ + print_centered("Isotopes"); + output_msg(sformatf( "%10s\t%12s\t%12s\t%12s\t%12s\n\n", "Isotope", + "Molality", "Moles", "Ratio", "Units")); + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->minor_isotope == FALSE) + { + print_isotope = FALSE; + for (j = 0; j < count_master_isotope; j++) + { + if ((master_isotope[j]->elt == master_isotope[i]->elt) && + (master_isotope[j]->minor_isotope == TRUE) && + (master_isotope[j]->moles > 0)) + { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) + continue; + /* + * Print isotope values + */ + output_msg(sformatf( "%10s\t%12.5e\t%12.5e\n", + master_isotope[i]->name, + (double) (master_isotope[i]->moles / mass_water_aq_x), + (double) master_isotope[i]->moles)); + for (j = 0; j < count_master_isotope; j++) + { + if (i == j) + continue; + if ((master_isotope[j]->elt == master_isotope[i]->elt) && + (master_isotope[j]->minor_isotope == TRUE)) + { + output_msg(sformatf( + "%10s\t%12.5e\t%12.5e\t%12.5e\t%12s\n", + master_isotope[j]->name, + (double) (master_isotope[j]->moles / + mass_water_aq_x), + (double) master_isotope[j]->moles, + (double) master_isotope[j]->ratio, + master_isotope[j]->units)); + } + } + output_msg(sformatf( "\n")); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch isotope ratios relative to standards + */ + int i; + LDBLE iso; + struct isotope_ratio *isotope_ratio_ptr; + struct master_isotope *master_isotope_ptr; + + if (punch.in == FALSE || punch.isotopes == FALSE) + return (OK); + if (punch.count_isotopes == 0) + return (OK); + for (i = 0; i < punch.count_isotopes; i++) + { + iso = MISSING; + if (state == INITIAL_SOLUTION) + { + isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + if (isotope_ratio_ptr != NULL) + { + master_isotope_ptr = + master_isotope_search(isotope_ratio_ptr->isotope_name); + if (master_isotope_ptr != NULL + && master_isotope_ptr->minor_isotope == TRUE) + { + iso = master_isotope_ptr->ratio; + } + } + } + else + { + isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + if (isotope_ratio_ptr != NULL) + { + iso = isotope_ratio_ptr->converted_ratio; + } + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%12.4e\t", + (double) iso); + } + else + { + fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%20.12e\t", + (double) iso); + } + + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch calculate values + */ + int i; + LDBLE result; + struct calculate_value *calculate_value_ptr; + + if (punch.in == FALSE || punch.calculate_values == FALSE) + return (OK); + if (punch.count_calculate_values == 0) + return (OK); + for (i = 0; i < punch.count_calculate_values; i++) + { + result = MISSING; + calculate_value_ptr = + calculate_value_search(punch.calculate_values[i].name); + if (calculate_value_ptr != NULL) + { + result = calculate_value_ptr->value; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("V_%s", punch.calculate_values[i].name), + "%12.4e\t", (double) result); + } + else + { + fpunchf(sformatf("V_%s", punch.calculate_values[i].name), + "%20.12e\t", (double) result); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_isotope_ratios(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + struct master *master_ptr; + struct master_isotope *master_isotope_ptr; + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + + + if (pr.isotope_ratios == FALSE || pr.all == FALSE) + return (OK); + if (state == INITIAL_SOLUTION) + return (OK); +/* + * Print heading + */ + print_isotope = FALSE; + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->minor_isotope == FALSE) + continue; + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) + continue; + if (master_ptr->total > 0 || master_ptr->s->moles > 0) + { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) + return (OK); + + print_centered("Isotope Ratios"); + output_msg(sformatf( "%25s\t%12s\t%15s\n\n", "Isotope Ratio", + "Ratio", "Input Units")); + + for (j = 0; j < count_isotope_ratio; j++) + { + if (isotope_ratio[j]->ratio == MISSING) + continue; + isotope_ratio_ptr = isotope_ratio[j]; + master_isotope_ptr = + master_isotope_search(isotope_ratio[j]->isotope_name); + /* + * Print isotope ratio + */ + strcpy(token, isotope_ratio[j]->name); + while (replace("_", " ", token) == TRUE); + output_msg(sformatf( " %-20s\t%12.5e\t%15.5g %-10s\n", + token, (double) isotope_ratio[j]->ratio, + (double) isotope_ratio[j]->converted_ratio, + master_isotope_ptr->units)); + } + output_msg(sformatf( "\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_isotope_alphas(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print isotopes for initial solution + */ + int i, j; + int print_isotope; + struct master *master_ptr; + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + LDBLE log_alpha; + + if (pr.isotope_alphas == FALSE || pr.all == FALSE) + return (OK); + if (state == INITIAL_SOLUTION) + return (OK); +/* + * Print heading + */ + print_isotope = FALSE; + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->minor_isotope == FALSE) + continue; + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) + continue; + if (master_ptr->total > 0 || master_ptr->s->moles > 0) + { + print_isotope = TRUE; + break; + } + } + if (print_isotope == FALSE) + return (OK); + + print_centered("Isotope Alphas"); + output_msg(sformatf( "%75s\n", "1000ln(Alpha)")); + output_msg(sformatf( "%79s\n", "----------------------")); + output_msg(sformatf( "%-37s%14s%14s%12.1f C\n\n", + " Isotope Ratio", "Solution alpha", "Solution", + (double) tc_x)); + + for (j = 0; j < count_isotope_alpha; j++) + { + if (isotope_alpha[j]->value == MISSING) + continue; + isotope_alpha_ptr = isotope_alpha[j]; + /* + * Print isotope ratio + */ + strcpy(token, isotope_alpha[j]->name); + while (replace("_", " ", token) == TRUE); + if (isotope_alpha[j]->named_logk != NULL) + { + if (isotope_alpha[j]->value <= 0) + { + log_alpha = -999.999; + } + else + { + log_alpha = 1000 * log(isotope_alpha[j]->value); + } + output_msg(sformatf( "%-37s%14.5g%14.5g%14.5g\n", token, + (double) isotope_alpha[j]->value, (double) log_alpha, + (double) (1000 * + calc_logk_n(isotope_alpha[j]->named_logk) * + LOG_10))); + } + else + { + output_msg(sformatf( "%-37s%14.5g%14.5g\n", token, + (double) isotope_alpha[j]->value, + (double) (1000 * log(isotope_alpha[j]->value)))); + } + + } + output_msg(sformatf( "\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ + int j; + struct calculate_value *calculate_value_ptr; + struct isotope_ratio *isotope_ratio_ptr; + struct isotope_alpha *isotope_alpha_ptr; + struct master_isotope *master_isotope_ptr; + char l_command[] = "run"; + + + /* + * initialize ratios as missing + */ + for (j = 0; j < count_calculate_value; j++) + { + calculate_value[j]->calculated = FALSE; + calculate_value[j]->value = MISSING; + } + + for (j = 0; j < count_calculate_value; j++) + { + calculate_value_ptr = calculate_value[j]; + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) + { + if (basic_compile + (calculate_value[j]->commands, &calculate_value[j]->linebase, + &calculate_value[j]->varbase, + &calculate_value[j]->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run + (l_command, calculate_value[j]->linebase, + calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + else + { + calculate_value[j]->calculated = TRUE; + calculate_value[j]->value = rate_moles; + } + } + for (j = 0; j < count_isotope_ratio; j++) + { + isotope_ratio_ptr = isotope_ratio[j]; + master_isotope_ptr = + master_isotope_search(isotope_ratio_ptr->isotope_name); + calculate_value_ptr = calculate_value_search(isotope_ratio_ptr->name); + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->value == MISSING) + { + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + } + else + { + isotope_ratio_ptr->ratio = calculate_value_ptr->value; + isotope_ratio_ptr->converted_ratio = + convert_isotope(master_isotope_ptr, + calculate_value_ptr->value); + } + } + for (j = 0; j < count_isotope_alpha; j++) + { + isotope_alpha_ptr = isotope_alpha[j]; + calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->value == MISSING) + { + isotope_alpha_ptr->value = MISSING; + } + else + { + isotope_alpha_ptr->value = calculate_value_ptr->value; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +convert_isotope(struct master_isotope * master_isotope_ptr, LDBLE ratio) +/* ---------------------------------------------------------------------- */ +{ + const char *units; + units = master_isotope_ptr->units; + + if (strcmp_nocase(units, "permil") == 0) + { + return ((ratio / master_isotope_ptr->standard - 1) * 1000); + } + if (strcmp_nocase(units, "pct") == 0) + { + return (ratio / master_isotope_ptr->standard * 100.); + } + if (strcmp_nocase(units, "pmc") == 0) + { + return (ratio / master_isotope_ptr->standard * 100.); + } + if (strcmp_nocase(units, "tu") == 0) + { + return (ratio / master_isotope_ptr->standard); + } + if (strcmp_nocase(units, "pci/l") == 0) + { + return (ratio / master_isotope_ptr->standard); + } + error_string = sformatf( + "Did not recognize isotope units in convert_isotope, %s", units); + error_msg(error_string, STOP); + return (-99.0); +} + +/* + * Utility routines for master_isotope + */ + +/* ---------------------------------------------------------------------- */ +struct master_isotope * Phreeqc:: +master_isotope_store(const char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for master_isotope. + * + * Pointer to a master_isotope structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old master_isotope structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old master_isotope structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "master_isotope". + * replace_if_found input, TRUE means reinitialize master_isotope structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to master_isotope structure "master_isotope" where "name" can be found. + */ + int n; + struct master_isotope *master_isotope_ptr; + ENTRY item, *found_item; + char token[MAX_LENGTH]; +/* + * Search list + */ + strcpy(token, name); + + item.key = token; + item.data = NULL; + found_item = hsearch_multi(master_isotope_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + return (master_isotope_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + master_isotope_init(master_isotope_ptr); + } + else + { + n = count_master_isotope++; + /* make sure there is space in s */ + if (count_master_isotope >= max_master_isotope) + { + space((void **) ((void *) &master_isotope), count_master_isotope, + &max_master_isotope, sizeof(struct master_isotope *)); + } + /* Make new master_isotope structure */ + master_isotope[n] = master_isotope_alloc(); + master_isotope_ptr = master_isotope[n]; + } + /* set name and z in pointer in master_isotope structure */ + master_isotope_ptr->name = string_hsave(token); +/* + * Update hash table + */ + item.key = master_isotope_ptr->name; + item.data = (void *) master_isotope_ptr; + found_item = hsearch_multi(master_isotope_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in master_isotope_store."); + error_msg(error_string, CONTINUE); + } + + return (master_isotope_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct master_isotope * Phreeqc:: +master_isotope_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a master_isotope structure, initializes + * arguments: void + * return: pointer to a master_isotope structure + */ +{ + struct master_isotope *master_isotope_ptr; + master_isotope_ptr = + (struct master_isotope *) PHRQ_malloc(sizeof(struct master_isotope)); + if (master_isotope_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + master_isotope_init(master_isotope_ptr); + + return (master_isotope_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +master_isotope_init(struct master_isotope *master_isotope_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a master_isotope structure + */ +{ +/* + * set pointers in structure to NULL + */ + master_isotope_ptr->name = NULL; + master_isotope_ptr->master = NULL; + master_isotope_ptr->elt = NULL; + master_isotope_ptr->units = NULL; + master_isotope_ptr->standard = 0; + master_isotope_ptr->ratio = 0; + master_isotope_ptr->moles = 0; + master_isotope_ptr->total_is_major = 0; + master_isotope_ptr->minor_isotope = 1; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct master_isotope * Phreeqc:: +master_isotope_search(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for master_isotope. + * + * Arguments: + * name input, character string to be found in "master_isotope". + * + * Returns: + * pointer to master_isotope structure "master_isotope" where "name" can be found. + * or NULL if not found. + */ + struct master_isotope *master_isotope_ptr; + ENTRY item, *found_item; + char token[MAX_LENGTH]; +/* + * Search list + */ + strcpy(token, name); + + item.key = token; + item.data = NULL; + found_item = hsearch_multi(master_isotope_hash_table, item, FIND); + + if (found_item != NULL) + { + master_isotope_ptr = (struct master_isotope *) (found_item->data); + return (master_isotope_ptr); + } + return (NULL); +} + +/* + * Utility routines for calculate_value + */ + +/* ---------------------------------------------------------------------- */ +struct calculate_value * Phreeqc:: +calculate_value_store(const char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for calculate_value. + * + * Pointer to a calculate_value structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old calculate_value structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old calculate_value structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "calculate_value". + * replace_if_found input, TRUE means reinitialize calculate_value structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to calculate_value structure "calculate_value" where "name" can be found. + */ + int n; + struct calculate_value *calculate_value_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(calculate_value_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + return (calculate_value_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + calculate_value_free(calculate_value_ptr); + calculate_value_init(calculate_value_ptr); + } + else + { + n = count_calculate_value++; + /* make sure there is space in s */ + if (count_calculate_value >= max_calculate_value) + { + space((void **) ((void *) &calculate_value), + count_calculate_value, &max_calculate_value, + sizeof(struct calculate_value *)); + } + /* Make new calculate_value structure */ + calculate_value[n] = calculate_value_alloc(); + calculate_value_ptr = calculate_value[n]; + } + /* set name and z in pointer in calculate_value structure */ + calculate_value_ptr->name = string_hsave(name); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) calculate_value_ptr; + found_item = hsearch_multi(calculate_value_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in calculate_value_store."); + error_msg(error_string, CONTINUE); + } + + return (calculate_value_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct calculate_value * Phreeqc:: +calculate_value_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a calculate_value structure, initializes + * arguments: void + * return: pointer to a calculate_value structure + */ +{ + struct calculate_value *calculate_value_ptr; + calculate_value_ptr = + (struct calculate_value *) + PHRQ_malloc(sizeof(struct calculate_value)); + if (calculate_value_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + calculate_value_init(calculate_value_ptr); + + return (calculate_value_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +calculate_value_init(struct calculate_value *calculate_value_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a calculate_value structure + */ +{ +/* + * set pointers in structure to NULL + */ + calculate_value_ptr->name = NULL; + calculate_value_ptr->commands = NULL; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct calculate_value * Phreeqc:: +calculate_value_search(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for calculate_value. + * + * Arguments: + * name input, character string to be found in "calculate_value". + * + * Returns: + * pointer to calculate_value structure "calculate_value" where "name" can be found. + * or NULL if not found. + */ + struct calculate_value *calculate_value_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(calculate_value_hash_table, item, FIND); + + if (found_item != NULL) + { + calculate_value_ptr = (struct calculate_value *) (found_item->data); + return (calculate_value_ptr); + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calculate_value_free(struct calculate_value *calculate_value_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within calculate_value[i], does not free calculate_value structure + * Input: i, number of calculate_value + * Return: OK + */ + char cmd[] = "new; quit"; + + if (calculate_value_ptr == NULL) + return (ERROR); + calculate_value_ptr->commands = + (char *) free_check_null(calculate_value_ptr->commands); + basic_run(cmd, calculate_value_ptr->linebase, + calculate_value_ptr->varbase, calculate_value_ptr->loopbase); + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + return (OK); +} + +/* + * Utility routines for isotope_ratio + */ + +/* ---------------------------------------------------------------------- */ +struct isotope_ratio * Phreeqc:: +isotope_ratio_store(const char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_ratio. + * + * Pointer to a isotope_ratio structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old isotope_ratio structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old isotope_ratio structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "isotope_ratio". + * replace_if_found input, TRUE means reinitialize isotope_ratio structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. + */ + int n; + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + return (isotope_ratio_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + isotope_ratio_init(isotope_ratio_ptr); + } + else + { + n = count_isotope_ratio++; + /* make sure there is space in s */ + if (count_isotope_ratio >= max_isotope_ratio) + { + space((void **) ((void *) &isotope_ratio), count_isotope_ratio, + &max_isotope_ratio, sizeof(struct isotope_ratio *)); + } + /* Make new isotope_ratio structure */ + isotope_ratio[n] = isotope_ratio_alloc(); + isotope_ratio_ptr = isotope_ratio[n]; + } + /* set name and z in pointer in isotope_ratio structure */ + isotope_ratio_ptr->name = string_hsave(name); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) isotope_ratio_ptr; + found_item = hsearch_multi(isotope_ratio_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in isotope_ratio_store."); + error_msg(error_string, CONTINUE); + } + + return (isotope_ratio_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct isotope_ratio * Phreeqc:: +isotope_ratio_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a isotope_ratio structure, initializes + * arguments: void + * return: pointer to a isotope_ratio structure + */ +{ + struct isotope_ratio *isotope_ratio_ptr; + isotope_ratio_ptr = + (struct isotope_ratio *) PHRQ_malloc(sizeof(struct isotope_ratio)); + if (isotope_ratio_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + isotope_ratio_init(isotope_ratio_ptr); + + return (isotope_ratio_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a isotope_ratio structure + */ +{ +/* + * set pointers in structure to NULL + */ + isotope_ratio_ptr->name = NULL; + isotope_ratio_ptr->isotope_name = NULL; + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct isotope_ratio * Phreeqc:: +isotope_ratio_search(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_ratio. + * + * Arguments: + * name input, character string to be found in "isotope_ratio". + * + * Returns: + * pointer to isotope_ratio structure "isotope_ratio" where "name" can be found. + * or NULL if not found. + */ + struct isotope_ratio *isotope_ratio_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_ratio_hash_table, item, FIND); + + if (found_item != NULL) + { + isotope_ratio_ptr = (struct isotope_ratio *) (found_item->data); + return (isotope_ratio_ptr); + } + return (NULL); +} + +/* + * Utility routines for isotope_alpha + */ + +/* ---------------------------------------------------------------------- */ +struct isotope_alpha * Phreeqc:: +isotope_alpha_store(const char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_alpha. + * + * Pointer to a isotope_alpha structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old isotope_alpha structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old isotope_alpha structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "isotope_alpha". + * replace_if_found input, TRUE means reinitialize isotope_alpha structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. + */ + int n; + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + return (isotope_alpha_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + isotope_alpha_init(isotope_alpha_ptr); + } + else + { + n = count_isotope_alpha++; + /* make sure there is space in s */ + if (count_isotope_alpha >= max_isotope_alpha) + { + space((void **) ((void *) &isotope_alpha), count_isotope_alpha, + &max_isotope_alpha, sizeof(struct isotope_alpha *)); + } + /* Make new isotope_alpha structure */ + isotope_alpha[n] = isotope_alpha_alloc(); + isotope_alpha_ptr = isotope_alpha[n]; + } + /* set name and z in pointer in isotope_alpha structure */ + isotope_alpha_ptr->name = string_hsave(name); +/* + * Update hash table + */ + item.key = string_hsave(token); + item.data = (void *) isotope_alpha_ptr; + found_item = hsearch_multi(isotope_alpha_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in isotope_alpha_store."); + error_msg(error_string, CONTINUE); + } + + return (isotope_alpha_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct isotope_alpha * Phreeqc:: +isotope_alpha_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a isotope_alpha structure, initializes + * arguments: void + * return: pointer to a isotope_alpha structure + */ +{ + struct isotope_alpha *isotope_alpha_ptr; + isotope_alpha_ptr = + (struct isotope_alpha *) PHRQ_malloc(sizeof(struct isotope_alpha)); + if (isotope_alpha_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + isotope_alpha_init(isotope_alpha_ptr); + + return (isotope_alpha_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a isotope_alpha structure + */ +{ +/* + * set pointers in structure to NULL + */ + isotope_alpha_ptr->name = NULL; + isotope_alpha_ptr->named_logk = NULL; + isotope_alpha_ptr->value = MISSING; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct isotope_alpha * Phreeqc:: +isotope_alpha_search(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for isotope_alpha. + * + * Arguments: + * name input, character string to be found in "isotope_alpha". + * + * Returns: + * pointer to isotope_alpha structure "isotope_alpha" where "name" can be found. + * or NULL if not found. + */ + struct isotope_alpha *isotope_alpha_ptr; + char token[MAX_LENGTH]; + ENTRY item, *found_item; +/* + * Search list + */ + strcpy(token, name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(isotope_alpha_hash_table, item, FIND); + + if (found_item != NULL) + { + isotope_alpha_ptr = (struct isotope_alpha *) (found_item->data); + return (isotope_alpha_ptr); + } + return (NULL); +} diff --git a/rename_cpp/kinetics.cpp b/rename_cpp/kinetics.cpp new file mode 100644 index 00000000..3afde67f --- /dev/null +++ b/rename_cpp/kinetics.cpp @@ -0,0 +1,2983 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" + +#include + +#include "StorageBin.h" +#include "Reaction.h" +#include "cxxKinetics.h" +#include "Solution.h" +#include "cxxMix.h" +#include "PPassemblage.h" +#include "Surface.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "SSassemblage.h" +#include "Temperature.h" + +#include +#include +#include "nvector_serial.h" /* definitions of type N_Vector and macro */ + /* NV_Ith_S, prototypes for N_VNew, N_VFree */ +/* These macros are defined in order to write code which exactly matches + the mathematical problem description given above. + + Ith(v,i) references the ith component of the vector v, where i is in + the range [1..NEQ] and NEQ is defined below. The Ith macro is defined + using the N_VIth macro in nvector.h. N_VIth numbers the components of + a vector starting from 0. + + IJth(A,i,j) references the (i,j)th element of the dense matrix A, where + i and j are in the range [1..NEQ]. The IJth macro is defined using the + DENSE_ELEM macro in dense.h. DENSE_ELEM numbers rows and columns of a + dense matrix starting from 0. */ + +#define Ith(v,i) NV_Ith_S(v,i-1) /* Ith numbers components 1..NEQ */ +#define IJth(A,i,j) DENSE_ELEM(A,i-1,j-1) /* IJth numbers rows,cols 1..NEQ */ + +#define MAX_DIVIDE 2 +#define KINETICS_TOL 1e-8; + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * determine rates and + * a list of elements and amounts in + * the reaction. + */ + int i, j, return_value; + LDBLE coef; + char l_command[] = "run"; + struct rate *rate_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + return_value = OK; + count_elts = 0; + paren_count = 0; + rate_time = time_step; + +/* t1 = clock(); */ + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + coef = 0.0; +/* + * Send command to basic interpreter + */ + rate_ptr = rate_search(kinetics_ptr->comps[i].rate_name, &j); + if (rate_ptr == NULL) + { + error_string = sformatf( "Rate not found for %s", + kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + else + { + rate_moles = NAN; + rate_m = kinetics_ptr->comps[i].m; + rate_m0 = kinetics_ptr->comps[i].m0; + rate_p = kinetics_ptr->comps[i].d_params; + count_rate_p = kinetics_ptr->comps[i].count_d_params; + if (rate_ptr->new_def == TRUE) + { + if (basic_compile + (rates[j].commands, &rates[j].linebase, &rates[j].varbase, + &rates[j].loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in rate %s.", + kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + + rate_ptr->new_def = FALSE; + } + if (basic_run + (l_command, rates[j].linebase, rates[j].varbase, + rates[j].loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in rate %s.", + kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Moles of reaction not SAVE'd for %s.", + kinetics_ptr->comps[i].rate_name); + error_msg(error_string, STOP); + } + else + { + + coef = rate_moles; + } + } +/* + * Accumulate moles of reaction for component + */ + kinetics_ptr->comps[i].moles += coef; + if (coef == 0.0) + continue; + } +/* t2=clock(); + printf("secs in reac %e, t2 %e\n", t2-t1, t1); + */ + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * using extrapolated values, which were + * stored in moles in run_kinetics + */ + int i, j, k; + LDBLE coef; + char token[MAX_LENGTH]; + struct phase *phase_ptr; + struct master *master_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + kinetics_ptr->totals = + (struct elt_list *) free_check_null(kinetics_ptr->totals); + count_elts = 0; + paren_count = 0; + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + if (kinetics_ptr->comps[i].moles > m_temp[i]) + { + kinetics_ptr->comps[i].moles = m_temp[i]; + kinetics_ptr->comps[i].m = 0; + } + coef = kinetics_ptr->comps[i].moles; + if (coef == 0.0) + continue; +/* + * Reactant is a pure phase, copy formula into token + */ + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) + { + phase_ptr = NULL; + strcpy(token, kinetics_ptr->comps[i].list[j].name); + phase_ptr = phase_bsearch(token, &k, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, + coef * kinetics_ptr->comps[i].list[j].coef); + } + else + { + char * temp_name = string_duplicate(kinetics_ptr->comps[i].list[j].name); + char * ptr = temp_name; + get_elts_in_species(&ptr, + coef * + kinetics_ptr->comps[i].list[j].coef); + free_check_null(temp_name); + } + } + if (use.Get_exchange_ptr() != NULL + //&& use.Get_exchange_ptr()->related_rate == TRUE) + && ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate()) + { + cxxExchange * exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); + std::map::iterator it = exchange_ptr->Get_exchComps().begin(); + for ( ; it != exchange_ptr->Get_exchComps().end(); it++) + { + std::string name(it->second.Get_rate_name()); + + if (name.size() > 0) + { + if (strcmp_nocase + (kinetics_ptr->comps[i].rate_name, + name.c_str()) == 0) + { + /* found kinetics component */ + add_elt_list(it->second.Get_formula_totals(), -coef*it->second.Get_phase_proportion()); + } + } + } + + } + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->related_rate == TRUE) + { + for (j = 0; j < use.Get_surface_ptr()->count_comps; j++) + { + if (use.Get_surface_ptr()->comps[j].rate_name != NULL) + { + if (strcmp_nocase + (kinetics_ptr->comps[i].rate_name, + use.Get_surface_ptr()->comps[j].rate_name) == 0) + { + /* found kinetics component */ + char * temp_formula = string_duplicate(use.Get_surface_ptr()->comps[j].formula); + char *ptr = temp_formula; +/* Surface = 0 when m becomes low ... + */ + if (0.9 * use.Get_surface_ptr()->comps[j].phase_proportion * + (kinetics_ptr->comps[i].m) < MIN_RELATED_SURFACE) + { + master_ptr = master_bsearch(ptr); + master_ptr->total = 0.0; + } + else + { + get_elts_in_species(&ptr, + -coef * + use.Get_surface_ptr()->comps[j]. + phase_proportion); + } + free_check_null(temp_formula); + } + } + } + } + } + kinetics_ptr->totals = elt_list_save(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Runge-Kutta-Fehlberg method; 6 evaluations of the derivative + * give O(h^5) global error and error estimate + * calc_kinetic_reaction(.., ..) calculates moles of intermediate derivatives; + * these are calc'd for the whole step h. + * calc_final_kinetic reaction(..) translates moles to PHREEQC reaction. + */ + int j, k, m, save_old; + int l_bad, step_bad, step_ok; + int n_reactions; + LDBLE h, h_old, h_sum; + LDBLE *rk_moles; + LDBLE l_error, error_max, safety, moles_max, moles_reduction; + struct kinetics *kinetics_ptr; + int equal_rate, zero_rate; + + cxxPPassemblage *pp_assemblage_save = NULL; + struct ss_assemblage *ss_assemblage_save = NULL; + + LDBLE b31 = 3. / 40., b32 = 9. / 40., + b51 = -11. / 54., b53 = -70. / 27., b54 = 35. / 27., + b61 = 1631. / 55296., b62 = 175. / 512., b63 = 575. / 13824., b64 = + 44275. / 110592., b65 = 253. / 4096., c1 = 37. / 378., c3 = + 250. / 621., c4 = 125. / 594., c6 = 512. / 1771., dc5 = + -277. / 14336.; + LDBLE dc1 = c1 - 2825. / 27648., dc3 = c3 - 18575. / 48384., dc4 = + c4 - 13525. / 55296., dc6 = c6 - 0.25; +/* + * Save kinetics i and solution i, if necessary + */ + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); + kinetics_duplicate(i, save_old); + if (nsaver != i) + { + solution_duplicate(i, save_old); + } + +/* + * Malloc some space + */ + if (kinetics_bsearch(i, &m) == NULL) + return (OK); + n_reactions = kinetics[m].count_comps; + rk_moles = + (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); + if (rk_moles == NULL) + malloc_error(); + + /*if (use_mix != NOMIX) last_model.force_prep = TRUE; */ + set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); + run_reactions_iterations += iterations; + + saver(); + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, NOMIX, TRUE, i); + } + else if (state == ADVECTION) + { + set_advection(i, NOMIX, TRUE, i); + } + else if (state == REACTION) + { + set_reaction(i, NOMIX, TRUE); + } +#ifdef SKIP + if (use.Get_pp_assemblage_ptr() != NULL) + { + pp_assemblage_save = + (struct pp_assemblage *) + PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_save == NULL) + malloc_error(); + } +#endif + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_save = + (struct ss_assemblage *) + PHRQ_malloc(sizeof(struct ss_assemblage)); + if (ss_assemblage_save == NULL) + malloc_error(); + } + + kinetics_ptr = kinetics_bsearch(i, &m); + + step_bad = step_ok = 0; + l_bad = FALSE; + h_sum = 0.; + h = h_old = kin_time; + moles_max = 0.1; + moles_reduction = 1.0; + safety = 0.7; + if (kinetics_ptr->rk < 1) + kinetics_ptr->rk = 1; + else if (kinetics_ptr->rk > 3) + kinetics_ptr->rk = 6; + + if (kinetics_ptr->rk == 6) + equal_rate = FALSE; + else + equal_rate = TRUE; +/* + * if step_divide > 1, initial timestep is divided + * if < 1, step_divide indicates maximal reaction... + */ + if (kinetics_ptr->step_divide > 1.0) + { + h = h_old = kin_time / kinetics_ptr->step_divide; + equal_rate = FALSE; + } + else if (kinetics_ptr->step_divide < 1.0) + moles_max = kinetics_ptr->step_divide; + + rate_sim_time = rate_sim_time_start + h_sum; + + status(0, NULL); + while (h_sum < kin_time) + { + + if (step_bad > kinetics_ptr->bad_step_max) + { + error_string = sformatf( + "Bad RK steps > %d. Please decrease (time)step or increase -bad_step_max.", + kinetics_ptr->bad_step_max); + error_msg(error_string, STOP); + } + + MOLES_TOO_LARGE: + if (moles_reduction > 1.0) + { + h_old = h; + h = safety * h / (1.0 + moles_reduction); + moles_reduction = 1.0; + equal_rate = FALSE; + l_bad = TRUE; + } +/* + * find k1 + */ + if (l_bad == TRUE) + { + for (j = 0; j < n_reactions; j++) + { + rk_moles[j] *= (h / h_old); + kinetics_ptr->comps[j].moles = rk_moles[j] * 0.2; + kinetics_ptr->comps[j].m = m_temp[j]; + } + l_bad = FALSE; + } + else + { +/* + * define pointers for calc_kinetic_, they are lost after saver()... + */ + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, NOMIX, TRUE, i); + } + else if (state == ADVECTION) + { + set_advection(i, NOMIX, TRUE, i); + } + else if (state == REACTION) + { + set_reaction(i, NOMIX, TRUE); + } + /* + * Moles of minerals and solid solutions may change to make positive + * concentrations. Reactions may take out more than is present in + * solution. + */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage *pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_ptr->Get_n_user()); + assert(pp_ptr); + pp_assemblage_save = new cxxPPassemblage(*pp_ptr); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_copy(use.Get_ss_assemblage_ptr(), + ss_assemblage_save, + use.Get_ss_assemblage_ptr()->n_user); + } + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = 0.; + m_temp[j] = kinetics_ptr->comps[j].m; + } + + rate_sim_time = rate_sim_time_start + h_sum; + calc_kinetic_reaction(kinetics_ptr, h); + + /* store k1 in rk_moles ... */ + for (j = 0; j < n_reactions; j++) + { + if (moles_reduction * moles_max < + fabs(kinetics_ptr->comps[j].moles)) + { + moles_reduction = + fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k2 ... */ + rk_moles[j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles *= 0.2; + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + } +/* + * Quit rk with rk = 1 and equal rates ... + */ + if (kinetics_ptr->rk == 1 && equal_rate) + { + zero_rate = TRUE; + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = rk_moles[j]; + if (fabs(kinetics_ptr->comps[j].moles) > MIN_TOTAL) + zero_rate = FALSE; + } + + if (zero_rate == FALSE) + { + calc_final_kinetic_reaction(kinetics_ptr); + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) + kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == + MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + calc_kinetic_reaction(kinetics_ptr, h); + for (j = 0; j < n_reactions; j++) + { + if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > + kinetics_ptr->comps[j].tol) + { + equal_rate = FALSE; + break; + } + } + } + if (zero_rate || equal_rate) + { + /* removing the following line causes different results for + example 6 distributed with the program */ + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + } + goto EQUAL_RATE_OUT; + } + else + { + kinetics_ptr->rk = 3; + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = 0.2 * rk_moles[j]; + } + } + } +/* + * Continue with rk ... + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + +/* + * find k2 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.2 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + + /* store k2 in rk_moles */ + k = n_reactions; + for (j = 0; j < n_reactions; j++) + { + if (moles_reduction * moles_max < + fabs(kinetics_ptr->comps[j].moles)) + { + moles_reduction = + fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k3 */ + rk_moles[k + j] = kinetics_ptr->comps[j].moles; + + kinetics_ptr->comps[j].moles = b31 * rk_moles[j] + + b32 * rk_moles[k + j]; +/* + * check for equal_rate ... + */ + if (equal_rate + && fabs(rk_moles[j] - rk_moles[k + j]) > + kinetics_ptr->comps[j].tol) + { + equal_rate = FALSE; + } + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 2 and equal rates ... + */ + if (kinetics_ptr->rk == 2 && equal_rate) + { + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = + 0.3 * rk_moles[j] + 0.7 * rk_moles[k + j]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) + kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j = 0; j < n_reactions; j++) + { + if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > + kinetics_ptr->comps[j].tol) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate) + kinetics_ptr->rk = 1; + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k3 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.3 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + + /* store k3 in rk_moles */ + k = 2 * n_reactions; + for (j = 0; j < n_reactions; j++) + { + if (moles_reduction * moles_max < + fabs(kinetics_ptr->comps[j].moles)) + { + moles_reduction = + fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + /* define reaction for calculating k4 ... */ + rk_moles[k + j] = kinetics_ptr->comps[j].moles; + + kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] + - 0.9 * rk_moles[n_reactions + j] + 1.2 * rk_moles[k + j]; +/* + * check for equal_rate ... + */ + if (equal_rate + && fabs(rk_moles[j] - rk_moles[k + j]) > + kinetics_ptr->comps[j].tol) + equal_rate = FALSE; + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 3 and equal rates ... + */ + if (kinetics_ptr->rk == 3 && equal_rate) + { + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = 0.5 * rk_moles[j] + - 1.5 * rk_moles[n_reactions + j] + 2 * rk_moles[k + j]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) + kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j = 0; j < n_reactions; j++) + { + if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > + kinetics_ptr->comps[j].tol) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate) + kinetics_ptr->rk = 1; + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k4 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.6 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + + /* store k4 in rk_moles */ + k = 3 * n_reactions; + for (j = 0; j < n_reactions; j++) + { + if (moles_reduction * moles_max < + fabs(kinetics_ptr->comps[j].moles)) + { + moles_reduction = + fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + + /* define reaction for calculating k5 */ + rk_moles[k + j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = b51 * rk_moles[j] + + 2.5 * rk_moles[n_reactions + j] + + b53 * rk_moles[2 * n_reactions + j] + b54 * rk_moles[k + j]; + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k5 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + + /* store k5 in rk_moles */ + k = 4 * n_reactions; + for (j = 0; j < n_reactions; j++) + { + if (moles_reduction * moles_max < + fabs(kinetics_ptr->comps[j].moles)) + { + moles_reduction = + fabs(kinetics_ptr->comps[j].moles) / moles_max; + } + + /* define reaction for calculating k6 */ + rk_moles[k + j] = kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = b61 * rk_moles[j] + + b62 * rk_moles[n_reactions + j] + + b63 * rk_moles[2 * n_reactions + j] + + b64 * rk_moles[3 * n_reactions + j] + b65 * rk_moles[k + j]; + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k6 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + kinetics_ptr->comps[j].moles = 0.; + } + rate_sim_time = rate_sim_time_start + h_sum + 0.875 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + + /* store k6 in rk_moles */ + k = 5 * n_reactions; + for (j = 0; j < n_reactions; j++) + { + rk_moles[k + j] = kinetics_ptr->comps[j].moles; + } + +/* + * Evaluate error + */ + error_max = 0.; + for (j = 0; j < n_reactions; j++) + { + l_error = fabs(dc1 * rk_moles[j] + + dc3 * rk_moles[2 * n_reactions + j] + + dc4 * rk_moles[3 * n_reactions + j] + + dc5 * rk_moles[4 * n_reactions + j] + + dc6 * rk_moles[5 * n_reactions + j]); + + /* tol is in moles/l */ + l_error /= kinetics_ptr->comps[j].tol; + if (l_error > error_max) + error_max = l_error; + } + +/* + * repeat with smaller step + */ +/* printf("timest %g ; error_max %g\n", h, error_max); */ + if (error_max > 1) + { + h_old = h; + if (step_ok == 0) + h = h * safety / error_max; + else + h = h * safety * pow(error_max, (LDBLE) -0.25); + l_bad = TRUE; + step_bad++; + } + else + { +/* + * OK, calculate result + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = c1 * rk_moles[j] + + c3 * rk_moles[2 * n_reactions + j] + + c4 * rk_moles[3 * n_reactions + j] + + c6 * rk_moles[5 * n_reactions + j]; + } + calc_final_kinetic_reaction(kinetics_ptr); + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].m = + m_temp[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 1.e-30) + kinetics_ptr->comps[j].m = 0; + kinetics_ptr->comps[j].moles = 0.; + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (j = 0; j < n_reactions; j++) + { + if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > + kinetics_ptr->comps[j].tol) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate && kinetics_ptr->rk < 6) + kinetics_ptr->rk = 1; + + saver(); + + step_ok++; + h_sum += h; + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + } +/* + * and increase step size ... + */ + if (h_sum < kin_time) + { + if (error_max > 0.000577) + { + h = h * safety * pow(error_max, (LDBLE) -0.2e0); + } + else + { + h *= 4; + } + if (h > (kin_time - h_sum)) + h = (kin_time - h_sum); + } + } +#if !defined(PHREEQCI_GUI) +#ifndef PHREEQ98 + if (pr.status == TRUE && status_on == TRUE + && (int) (1e3 / CLOCKS_PER_SEC * ((float) clock() - status_timer)) > status_interval) + { + char str[MAX_LENGTH]; + backspace_screen(37); + sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, + step_ok, (int) (100 * h_sum / kin_time)); + screen_msg(sformatf("%-37s", str)); + } +#endif +#endif + } + + EQUAL_RATE_OUT: + +/* + * Run one more time to get distribution of species + */ + if (state >= REACTION || nsaver != i) + { + set_and_run_wrapper(i, NOMIX, FALSE, nsaver, 0.); + run_reactions_iterations += iterations; + } +/* saver(); */ /* reset for printing */ + if (use_mix == DISP) + { + //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; + use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); + use.Set_mix_in(true); + use.Set_n_mix_user(i); + } + else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) + { + //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use.Get_mix_ptr() != NULL) + { + use.Set_mix_in(true); + use.Set_n_mix_user(i); + } + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) + { + solution_duplicate(save_old, i); + } + rk_moles = (LDBLE *) free_check_null(rk_moles); + + rate_sim_time = rate_sim_time_start + kin_time; + use.Set_kinetics_in(true); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_save = + (struct ss_assemblage *) free_check_null(ss_assemblage_save); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ + int j, converge, max_try; + int old_diag, old_itmax; + LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; + LDBLE small_pe_step, small_step; + cxxPPassemblage *pp_assemblage_save = NULL; + struct ss_assemblage *ss_assemblage_save = NULL; + struct kinetics *kinetics_save = NULL; + + + small_pe_step = 5.; + small_step = 10.; + converge = FALSE; + + old_diag = diagonal_scale; + old_itmax = itmax; + old_tol = ineq_tol; + old_step = step_size; + old_pe = pe_step_size; + old_min_value = min_value; + old_pp_column_scale = pp_column_scale; + + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, use_mix, use_kinetics, i); + } + else if (state == ADVECTION) + { + set_advection(i, use_mix, use_kinetics, i); + } + else if (state == REACTION) + { + set_reaction(i, use_mix, use_kinetics); + } + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + if (pp_assemblage_save) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_save = + (struct ss_assemblage *) + PHRQ_malloc(sizeof(struct ss_assemblage)); + if (ss_assemblage_save == NULL) + malloc_error(); + ss_assemblage_copy(use.Get_ss_assemblage_ptr(), ss_assemblage_save, + use.Get_ss_assemblage_ptr()->n_user); + } + if (use.Get_kinetics_ptr() != NULL) + { + kinetics_save = + (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); + if (kinetics_save == NULL) + malloc_error(); + kinetics_copy(use.Get_kinetics_ptr(), kinetics_save, + use.Get_kinetics_ptr()->n_user); + } + + if (pitzer_model == TRUE || sit_model == TRUE) + { + diagonal_scale = TRUE; + always_full_pitzer = FALSE; + max_try = 13; + } + else + { + max_try = 13; + } + max_try = (max_tries < max_try) ? max_tries : max_try; + /*max_try = 1; */ + for (j = 0; j < max_try; j++) + { + if (j == 1) + { + always_full_pitzer = TRUE; + if (pe_step_size <= small_pe_step && step_size <= small_step) + continue; + itmax *= 2; + step_size = small_step; + pe_step_size = small_pe_step; + error_string = sformatf( + "Trying smaller step size, pe step size %g, %g ... \n", + (double) step_size, (double) pe_step_size); + warning_msg(error_string); + } + else if (j == 2) + { + itmax *= 2; + ineq_tol /= 10.; + error_string = sformatf( "Trying reduced tolerance %g ...\n", + (double) ineq_tol); + warning_msg(error_string); + } + else if (j == 3) + { + itmax *= 2; + ineq_tol *= 10.; + error_string = sformatf( "Trying increased tolerance %g ...\n", + (double) ineq_tol); + warning_msg(error_string); + } + else if (j == 4) + { + itmax *= 2; + if (diagonal_scale == TRUE) + { + diagonal_scale = FALSE; + } + else + { + diagonal_scale = TRUE; + } + error_string = sformatf( "Trying diagonal scaling ...\n"); + warning_msg(error_string); + } + else if (j == 5) + { + itmax *= 2; + if (diagonal_scale == TRUE) + { + diagonal_scale = FALSE; + } + else + { + diagonal_scale = TRUE; + } + ineq_tol /= 10.; + error_string = sformatf( + "Trying diagonal scaling and reduced tolerance %g ...\n", + (double) ineq_tol); + warning_msg(error_string); + } + else if (j == 6) + { + if (pitzer_model == TRUE || sit_model == TRUE) continue; + itmax *= 2; + pp_column_scale = 1e-10; + error_string = sformatf( + "Trying scaling pure_phase columns %g ...\n", + (double) pp_column_scale); + warning_msg(error_string); + } + else if (j == 7) + { + if (pitzer_model == TRUE || sit_model == TRUE) continue; + itmax *= 2; + pp_column_scale = 1e-10; + if (diagonal_scale == TRUE) + { + diagonal_scale = FALSE; + } + else + { + diagonal_scale = TRUE; + } + error_string = sformatf( + "Trying scaling pure_phase columns and diagonal scale %g ...\n", + (double) pp_column_scale); + warning_msg(error_string); + } + else if (j == 8) + { + if (pitzer_model == TRUE || sit_model == TRUE) continue; + itmax *= 2; + min_value *= 10; + error_string = sformatf( "Trying increased scaling %g ...\n", + (double) min_value); + warning_msg(error_string); + } + else if (j == 9) + { + if (pitzer_model == TRUE || sit_model == TRUE) continue; + aqueous_only = 5; + error_string = sformatf( + "Skipping optimize equations for first %d iterations ...\n", + aqueous_only); + warning_msg(error_string); + } + else if (j == 10) + { + if (pitzer_model == TRUE || sit_model == TRUE) continue; + negative_concentrations = TRUE; + error_string = sformatf( + "Adding inequality to make concentrations greater than zero.\n"); + warning_msg(error_string); + } + else if (j == 11) + { + itmax *= 2; + ineq_tol /= 100.; + error_string = sformatf( "Trying reduced tolerance %g ...\n", + (double) ineq_tol); + warning_msg(error_string); + } + else if (j == 12) + { + itmax *= 2; + ineq_tol /= 1000.; + error_string = sformatf( "Trying reduced tolerance %g ...\n", + (double) ineq_tol); + warning_msg(error_string); + } + if (j > 0) + { + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, + use.Get_ss_assemblage_ptr(), + ss_assemblage_save->n_user); + } + if (kinetics_save != NULL) + { + kinetics_free(use.Get_kinetics_ptr()); + kinetics_copy(kinetics_save, use.Get_kinetics_ptr(), + kinetics_save->n_user); + } + } + set_and_run_attempt = j; + + converge = + set_and_run(i, use_mix, use_kinetics, nsaver, step_fraction); + /* reset values */ + diagonal_scale = old_diag; + itmax = old_itmax; + ineq_tol = old_tol; + step_size = old_step; + pe_step_size = old_pe; + min_value = old_min_value; + pp_column_scale = old_pp_column_scale; + aqueous_only = 0; + negative_concentrations = FALSE; + if (converge == TRUE) + { + break; + } + else if (converge == MASS_BALANCE) + { + break; + } + warning_msg + ("Numerical method failed with this set of convergence parameters.\n"); + } + if (converge == FALSE && use.Get_kinetics_ptr() != NULL + && use.Get_kinetics_ptr()->use_cvode == TRUE) + { + error_string = sformatf( + "Numerical method failed on all parameter combinations, retrying integration"); + warning_msg(error_string); + converge = MASS_BALANCE; + } + if (converge == FALSE) + { +/* + * write to error.inp what failed to converge. + */ + std::ofstream error_input("error.inp"); + //cxxStorageBin error_bin(PHREEQC_THIS_COMMA &use, phrq_io); + cxxStorageBin error_bin; + Use2cxxStorageBin(error_bin); + error_bin.dump_raw(error_input, 0); + error_input.close(); + + /* if (state == TRANSPORT && dump_modulus == 0) dump(); */ + check_residuals(); + pr.all = TRUE; + pr.gas_phase = use.Get_gas_phase_in(); + pr.pp_assemblage = use.Get_pp_assemblage_in(); + pr.ss_assemblage = use.Get_ss_assemblage_in(); + pr.surface = use.Get_surface_in(); + pr.exchange = use.Get_exchange_in(); + pr.totals = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = use.Get_reaction_in(); + pr.mix = use.Get_mix_in(); + pr.reaction = TRUE; + pr.use = TRUE; + sum_species(); + print_all(); + error_string = sformatf( + "Numerical method failed on all combinations of convergence parameters"); + error_msg(error_string, STOP); + } + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + ss_assemblage_save = + (struct ss_assemblage *) free_check_null(ss_assemblage_save); + } + if (kinetics_save != NULL) + { + kinetics_free(kinetics_save); + kinetics_save = (struct kinetics *) free_check_null(kinetics_save); + } + if (converge == MASS_BALANCE) + { + return (MASS_BALANCE); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + * step_fraction--fraction of irreversible reaction to add + */ + int n,n2, converge; + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, use_mix, use_kinetics, nsaver); + } + else if (state == ADVECTION) + { + set_advection(i, use_mix, use_kinetics, nsaver); + } + else if (state == REACTION) + { + set_reaction(i, use_mix, use_kinetics); + } + cell = i; +/* + * Take step + */ + if (state >= REACTION) + { + if (step(step_fraction) == MASS_BALANCE) + { + return (MASS_BALANCE); + } +/* + * Always use solution, exchange, and surface -1 + */ + use.Set_solution_ptr(solution_bsearch(-1, &n, TRUE)); + + /* new */ + if (use.Get_exchange_ptr() != NULL) + { + //use.Get_exchange_ptr() = exchange_bsearch(-1, &n1); + use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, -1)); + } + if (use.Get_surface_ptr() != NULL) + { + use.Set_surface_ptr(surface_bsearch(-1, &n2)); + } + +/* + * Adjust the total pressure to the gas pressure + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* + * Fixed-pressure Gas phase and solution will react + * Change total pressure of current simulation to pressure + * of gas phase + */ + patm_x = gas_phase_ptr->Get_total_p(); + } + /* fixed volume gas phase is handled in calc_gas_pressures */ + + } + } + /* end new */ + if (use.Get_surface_ptr() != NULL) + { + dl_type_x = use.Get_surface_ptr()->dl_type; + } + if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + { + converge = surface_model(); + } + else + { + prep(); + k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + set(FALSE); + converge = model(); + } + sum_species(); + return (converge); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_transport(int i, int use_mix, int use_kinetics, int nsaver) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + */ + int n; + + cell = i; + reaction_step = 1; +/* + * Find mixture or solution + */ + + use.Set_mix_ptr(NULL); + use.Set_mix_in(false); + if (use_mix == DISP) + { + //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; + use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); + use.Set_mix_in(true); + use.Set_n_mix_user(i); + use.Set_n_mix_user_orig(i); + } + else if (use_mix == STAG && multi_Dflag != TRUE) + { + //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use.Get_mix_ptr() != NULL) + { + use.Set_mix_in(true); + use.Set_n_mix_user(i); + use.Set_n_mix_user_orig(i); + } + else + { + int n_solution; + use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() == NULL) + { + error_string = sformatf( "Solution %d not found.", + use.Get_n_solution_user()); + error_msg(error_string, STOP); + } + use.Set_n_solution_user(i); + use.Set_solution_in(true); + } + } + else + { + int n_solution; + use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() == NULL) + { + error_string = sformatf( "Solution %d not found.", + use.Get_n_solution_user()); + error_msg(error_string, STOP); + } + use.Set_n_solution_user(i); + use.Set_solution_in(true); + } + save.solution = TRUE; + save.n_solution_user = nsaver; + save.n_solution_user_end = nsaver; +/* + * Find pure phase assemblage + */ + + //use.Get_pp_assemblage_ptr() = pp_assemblage_bsearch(i, &use.n_pp_assemblage); + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, i)); + if (use.Get_pp_assemblage_ptr() != NULL) + { + use.Set_pp_assemblage_in(true); + use.Set_n_pp_assemblage_user(i); + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } + else + { + use.Set_pp_assemblage_in(false); + save.pp_assemblage = FALSE; + } +/* + * Find irreversible reaction + */ + //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); + use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); + if (use.Get_reaction_ptr() != NULL) + { + use.Set_reaction_in(true); + use.Set_n_reaction_user(i); + } + else + { + use.Set_reaction_in(false); + } +/* + * Find exchange + */ + //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); + use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); + if (use.Get_exchange_ptr() != NULL) + { + use.Set_exchange_in(true); + use.Set_n_exchange_user(i); + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } + else + { + use.Set_exchange_in(false); + save.exchange = FALSE; + } + +/* + * Find surface + */ + int n_surface; + use.Set_surface_ptr(surface_bsearch(i, &n_surface)); + //use.Set_n_surface(n_surface); + if (use.Get_surface_ptr() != NULL) + { + use.Set_surface_in(true); + use.Set_n_surface_user(i); + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } + else + { + use.Set_surface_in(false); + save.surface = FALSE; + dl_type_x = NO_DL; + } +/* + * Find temperature; temp retardation is done in step + */ + use.Set_temperature_ptr(Utilities::Rxn_find(Rxn_temperature_map, i)); + if (use.Get_temperature_ptr() != NULL) + { + use.Set_temperature_in(true); + use.Set_n_temperature_user(i); + } + else + { + use.Set_temperature_in(false); + } +/* + * Find pressure + */ + use.Set_pressure_ptr(Utilities::Rxn_find(Rxn_pressure_map, i)); + if (use.Get_pressure_ptr() != NULL) + { + use.Set_pressure_in(true); + use.Set_n_pressure_user(i); + } + else + { + use.Set_pressure_in(false); + } +/* + * Find gas + */ + //use.Get_gas_phase_ptr() = gas_phase_bsearch(i, &use.n_gas_phase); + use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, i)); + if (use.Get_gas_phase_ptr() != NULL) + { + use.Set_gas_phase_in(true); + use.Set_n_gas_phase_user(i); + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } + else + { + use.Set_gas_phase_in(false); + save.gas_phase = FALSE; + } +/* + * Find ss_assemblage + */ + int n_ss_assemblage; + use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); + //use.Set_n_ss_assemblage(n_ss_assemblage); + if (use.Get_ss_assemblage_ptr() != NULL) + { + use.Set_ss_assemblage_in(true); + use.Set_n_ss_assemblage_user(i); + save.ss_assemblage = TRUE; + save.n_ss_assemblage_user = i; + save.n_ss_assemblage_user_end = i; + } + else + { + use.Set_ss_assemblage_in(false); + save.ss_assemblage = FALSE; + } +/* + * Find kinetics + */ + use.Set_kinetics_ptr(NULL); + use.Set_kinetics_in(false); + save.kinetics = FALSE; + if (use_kinetics == TRUE) + { + use.Set_kinetics_ptr(kinetics_bsearch(i, &n)); + if (use.Get_kinetics_ptr() != NULL) + { + use.Set_n_kinetics_user(i); + //use.Set_n_kinetics(n); + use.Set_kinetics_in(true); + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } + } + /* + if (use.irrev_ptr != NULL && use.Get_kinetics_ptr() != NULL) + { + warning_msg("Should not use REACTION in same simulation with KINETICS."); + } + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_reaction(int i, int use_mix, int use_kinetics) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + */ +/* + * Find mixture or solution + */ + use.Set_mix_ptr(NULL); + use.Set_solution_ptr(NULL); + if (use_mix == TRUE && use.Get_mix_in() == TRUE) + { + //use.Get_mix_ptr() = mix_bsearch(i, &use.n_mix); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use.Get_mix_ptr() == NULL) + { + error_string = sformatf( "MIX %d not found.", i); + error_msg(error_string, STOP); + } + } + else + { + int n_solution; + use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() == NULL) + { + error_string = sformatf( "Solution %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find pure phase assemblage + */ + if (use.Get_pp_assemblage_in() == TRUE) + { + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, i)); + if (use.Get_pp_assemblage_ptr() == NULL) + { + error_string = sformatf( "PP_ASSEMBLAGE %d not found.", i); + error_msg(error_string, STOP); + } + } + +/* + * Find irreversible reaction + */ + if (use.Get_reaction_in() == TRUE) + { + //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); + use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); + if (use.Get_reaction_ptr() == NULL) + { + error_string = sformatf( "REACTION %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find exchange + */ + if (use.Get_exchange_in() == TRUE) + { + //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); + use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); + if (use.Get_exchange_ptr() == NULL) + { + error_string = sformatf( "EXCHANGE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find surface + */ + dl_type_x = NO_DL; + if (use.Get_surface_in() == TRUE) + { + int n_surface; + use.Set_surface_ptr(surface_bsearch(i, &n_surface)); + //use.Set_n_surface(n_surface); + if (use.Get_surface_ptr() == NULL) + { + error_string = sformatf( "SURFACE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find temperature; temp retardation is done in step + */ + if (use.Get_temperature_in() == TRUE) + { + use.Set_temperature_ptr(Utilities::Rxn_find(Rxn_temperature_map, i)); + if (use.Get_temperature_ptr() == NULL) + { + error_string = sformatf( "TEMPERATURE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find pressure + */ + if (use.Get_pressure_in() == TRUE) + { + use.Set_pressure_ptr(Utilities::Rxn_find(Rxn_pressure_map, i)); + if (use.Get_pressure_ptr() == NULL) + { + error_string = sformatf( "PRESSURE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find gas + */ + if (use.Get_gas_phase_in() == TRUE) + { + use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, i)); + if (use.Get_gas_phase_ptr() == NULL) + { + error_string = sformatf( "GAS_PHASE %d not found.", i); + error_msg(error_string, STOP); + } + } +/* + * Find ss_assemblage + */ + if (use.Get_ss_assemblage_in() == TRUE) + { + int n_ss_assemblage; + use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); + //use.Set_n_ss_assemblage(n_ss_assemblage); + if (use.Get_ss_assemblage_ptr() == NULL) + { + error_string = sformatf( "Solid-solution Assemblage %d not found.", + i); + error_msg(error_string, STOP); + } + } +/* + * Find kinetics + */ + if (use_kinetics == TRUE && use.Get_kinetics_in() == TRUE) + { + int n_kinetics; + use.Set_kinetics_ptr(kinetics_bsearch(i, &n_kinetics)); + //use.Set_n_kinetics(n_kinetics); + if (use.Get_kinetics_ptr() == NULL) + { + error_string = sformatf( "KINETICS %d not found.", i); + error_msg(error_string, STOP); + } + } + else + { + use.Set_kinetics_ptr(NULL); + } + /* + if (use.irrev_ptr != NULL && use.Get_kinetics_ptr() != NULL) + { + warning_msg("Should not use REACTION in same simulation with KINETICS."); + } + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Kinetics calculations + * Rates and moles of each reaction are calculated in calc_kinetic_reaction + * Total number of moles in reaction is stored in kinetics[i].totals + */ + + int j, n, converge, m_iter; + int pr_all_save; + int nsaver; + struct kinetics *kinetics_ptr; + cxxPPassemblage *pp_assemblage_ptr; + struct ss_assemblage *ss_assemblage_ptr; + cxxUse use_save; + int save_old, m, n_reactions /*, nok, nbad */ ; + + /* CVODE definitions */ + realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; + long int iopt[OPT_SIZE]; + int flag; +/* + * Set nsaver + */ + run_reactions_iterations = 0; + kin_time_x = kin_time; + nsaver = i; + if (state == TRANSPORT || state == PHAST) + { + if (use_mix == DISP) + { + nsaver = -2; + } + else if (use_mix == STAG) + { + nsaver = -2 - i; + } + } + if (state == ADVECTION) + { + nsaver = -2; + } +/* + * Check that reaction exists for this cell .. + */ + if (kin_time <= 0 || + (state == REACTION && use.Get_kinetics_in() == FALSE) || + (state == TRANSPORT && kinetics_bsearch(i, &n) == NULL) || + (state == PHAST && kinetics_bsearch(i, &n) == NULL) || + (state == ADVECTION && kinetics_bsearch(i, &n) == NULL)) + { + converge = + set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + run_reactions_iterations += iterations; + } + else + { +/* + * Save moles of kinetic reactants for printout... + */ + kinetics_ptr = kinetics_bsearch(i, &n); + + m_temp = + (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * + sizeof(LDBLE)); + if (m_temp == NULL) + malloc_error(); + + m_original = + (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * + sizeof(LDBLE)); + if (m_original == NULL) + malloc_error(); + + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + m_original[j] = kinetics_ptr->comps[j].m; + m_temp[j] = kinetics_ptr->comps[j].m; + } +/* +* Start the loop for timestepping ... + * Use either Runge-Kutta-Fehlberg, or final result extrapolation + */ + pr_all_save = pr.all; + pr.all = FALSE; +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * (if (incremental_reactions == FALSE || reaction_step == 1) + */ + store_get_equi_reactants(i, FALSE); + if (kinetics_ptr->use_cvode == FALSE) + { +/* in case dispersivity is not wanted.. + if (multi_Dflag) + rk_kinetics(i, kin_time, NOMIX, nsaver, step_fraction); + else + */ rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); + } + else + { + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); + if (nsaver != i) + { + solution_duplicate(i, save_old); + } + for (j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + +/* + * Do mix first + */ + kinetics_ptr = kinetics_bsearch(i, &m); + n_reactions = kinetics_ptr->count_comps; + cvode_n_user = i; + cvode_kinetics_ptr = (void *) kinetics_ptr; + cvode_n_reactions = n_reactions; + cvode_rate_sim_time_start = rate_sim_time_start; + cvode_rate_sim_time = rate_sim_time; + + if (multi_Dflag) + converge = set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + else + converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + saver(); + //pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); + pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); + ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); + if (pp_assemblage_ptr != NULL) + { + cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (ss_assemblage_ptr != NULL) + { + cvode_ss_assemblage_save = + (struct ss_assemblage *) + PHRQ_malloc(sizeof(struct ss_assemblage)); + if (cvode_ss_assemblage_save == NULL) + malloc_error(); + ss_assemblage_copy(ss_assemblage_ptr, + cvode_ss_assemblage_save, + ss_assemblage_ptr->n_user); + } + + /* allocate space for CVODE */ + kinetics_machEnv = M_EnvInit_Serial(n_reactions); + kinetics_machEnv->phreeqc_ptr = this; + kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (kinetics_y == NULL) + malloc_error(); + cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_last_good_y == NULL) + malloc_error(); + cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_prev_good_y == NULL) + malloc_error(); + kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); + if (kinetics_abstol == NULL) + malloc_error(); + +/* + * Set y to 0.0 + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = 0.0; + Ith(kinetics_y, j + 1) = 0.0; + Ith(kinetics_abstol, j + 1) = kinetics_ptr->comps[j].tol; + /*Ith(abstol,j+1) = 1e-8; */ + /* m_temp[j] = kinetics_ptr->comps[j].m; */ + } + reltol = 0.0; + + /* Call CVodeMalloc to initialize CVODE: + + NEQ is the problem size = number of equations + f is the user's right hand side function in y'=f(t,y) + T0 is the initial time + y is the initial dependent variable vector + BDF specifies the Backward Differentiation Formula + NEWTON specifies a Newton iteration + SV specifies scalar relative and vector absolute tolerances + &reltol is a pointer to the scalar relative tolerance + abstol is the absolute tolerance vector + FALSE indicates there are no optional inputs in iopt and ropt + iopt is an array used to communicate optional integer input and output + ropt is an array used to communicate optional real input and output + + A pointer to CVODE problem memory is returned and stored in cvode_mem. */ + /* Don't know what this does */ + /* + iopt[SLDET] = TRUE; + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); + iopt[MXSTEP] is maximum number of steps that CVODE tries. + */ + iopt[MXSTEP] = kinetics_ptr->cvode_steps; + iopt[MAXORD] = kinetics_ptr->cvode_order; + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, + &reltol, kinetics_abstol, this, NULL, TRUE, iopt, + ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + t = 0; + tout = kin_time; + /*ropt[HMAX] = tout/10.; */ + /*ropt[HMIN] = 1e-17; */ + use_save = use; + flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); + rate_sim_time = rate_sim_time_start + t; + /* + printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", + t, Ith(y,1), Ith(y,2), Ith(y,3)); + */ + m_iter = 0; + sum_t = 0; + RESTART: + while (flag != SUCCESS) + { + sum_t += cvode_last_good_time; + error_string = sformatf( + "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", + (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); + warning_msg(error_string); +#ifdef DEBUG_KINETICS + if (m_iter > 5) + dump_kinetics_stderr(cell_no); +#endif + + cvode_last_good_time = 0; + if (++m_iter >= kinetics_ptr->bad_step_max) + { + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + error_msg("Repeated restart of integration.", STOP); + } + tout1 = tout - sum_t; + t = 0; + N_VScale(1.0, cvode_last_good_y, kinetics_y); + for (j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + iopt[MXSTEP] = kinetics_ptr->cvode_steps; + iopt[MAXORD] = kinetics_ptr->cvode_order; + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, + SV, &reltol, kinetics_abstol, this, NULL, + TRUE, iopt, ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + flag = + CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); + /* + error_string = sformatf( "CVode failed, flag=%d.\n", flag); + error_msg(error_string, STOP); + */ + } + /* + odeint(&ystart[-1], n_reactions, 0, kin_time, kinetics_ptr->comps[0].tol, kin_time/kinetics_ptr->step_divide, 0.0, &nok, &nbad, i, nsaver ); + */ + for (j = 0; j < n_reactions; j++) + { + kinetics_ptr->comps[j].moles = Ith(kinetics_y, j + 1); + kinetics_ptr->comps[j].m = + m_original[j] - kinetics_ptr->comps[j].moles; + if (kinetics_ptr->comps[j].m < 0) + { + kinetics_ptr->comps[j].moles = m_original[j]; + kinetics_ptr->comps[j].m = 0.0; + } + } + if (use.Get_pp_assemblage_ptr() != NULL) + { + Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(cvode_ss_assemblage_save, + use.Get_ss_assemblage_ptr(), i); + } + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == + MASS_BALANCE) + { + /*error_msg("FAIL 2 after successful integration in CVode", CONTINUE); */ + warning_msg("FAIL 2 after successful integration in CVode"); + flag = -1; + goto RESTART; + } + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + kinetics_ptr->comps[j].m = + m_original[j] - kinetics_ptr->comps[j].moles; + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) + { + solution_duplicate(save_old, i); + } + free_cvode(); + use.Set_mix_in(use_save.Get_mix_in()); + use.Set_mix_ptr(use_save.Get_mix_ptr()); + } + + rate_sim_time = rate_sim_time_start + kin_time; + store_get_equi_reactants(i, TRUE); + pr.all = pr_all_save; + + kinetics_ptr = kinetics_bsearch(i, &n); + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + kinetics_ptr->comps[j].moles = + m_original[j] - kinetics_ptr->comps[j].m; +/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0; + */ } + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + } + iterations = run_reactions_iterations; + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = NULL; + } + if (cvode_ss_assemblage_save != NULL) + { + ss_assemblage_free(cvode_ss_assemblage_save); + cvode_ss_assemblage_save = + (struct ss_assemblage *) + free_check_null(cvode_ss_assemblage_save); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +free_cvode(void) +/* ---------------------------------------------------------------------- */ +{ + if (kinetics_y != NULL) + N_VFree(kinetics_y); /* Free vector */ + kinetics_y = NULL; + if (cvode_last_good_y != NULL) + N_VFree(cvode_last_good_y); /* Free vector */ + cvode_last_good_y = NULL; + if (cvode_prev_good_y != NULL) + N_VFree(cvode_prev_good_y); /* Free vector */ + cvode_prev_good_y = NULL; + if (kinetics_abstol != NULL) + N_VFree(kinetics_abstol); /* Free vector */ + kinetics_abstol = NULL; + if (kinetics_cvode_mem != NULL) + CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + kinetics_cvode_mem = NULL; + if (kinetics_machEnv != NULL) + M_EnvFree_Serial(kinetics_machEnv); /* Free the machine environment memory */ + kinetics_machEnv = NULL; + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = NULL; + } + if (cvode_ss_assemblage_save != NULL) + { + ss_assemblage_free(cvode_ss_assemblage_save); + cvode_ss_assemblage_save = + (struct ss_assemblage *) + free_check_null(cvode_ss_assemblage_save); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_advection(int i, int use_mix, int use_kinetics, int nsaver) +/* ---------------------------------------------------------------------- */ +{ +/* + * i --user number for soln, reaction, etc. + * use_mix --integer flag + state == TRANSPORT: DISP, STAG, NOMIX + state == REACTION: TRUE, FALSE + state == ADVECTION: TRUE, FALSE + * use_kinetics --true or false flag to calculate kinetic reactions + * nsaver --user number to store solution + */ + int n; + + cell = i; + reaction_step = 1; +/* + * Find mixture or solution + */ + + use.Set_mix_ptr(NULL); + use.Set_mix_in(false); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use_mix == TRUE && use.Get_mix_ptr() != NULL) + { + use.Set_mix_in(true); + use.Set_n_mix_user(i); + use.Set_n_mix_user_orig(i); + use.Set_n_solution_user(i); + } + else + { + int n_solution; + use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() == NULL) + { + error_string = sformatf( "Solution %d not found.", + use.Get_n_solution_user()); + error_msg(error_string, STOP); + } + use.Set_n_solution_user(i); + use.Set_solution_in(true); + } + save.solution = TRUE; + save.n_solution_user = nsaver; + save.n_solution_user_end = nsaver; +/* + * Find pure phase assemblage + */ + + //use.Get_pp_assemblage_ptr() = pp_assemblage_bsearch(i, &use.n_pp_assemblage); + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, i)); + if (use.Get_pp_assemblage_ptr() != NULL) + { + use.Set_pp_assemblage_in(true); + use.Set_n_pp_assemblage_user(i); + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } + else + { + use.Set_pp_assemblage_in(false); + save.pp_assemblage = FALSE; + } +/* + * Find irreversible reaction + */ + //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); + use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); + if (use.Get_reaction_ptr() != NULL) + { + use.Set_reaction_in(true); + use.Set_n_reaction_user(i); + } + else + { + use.Set_reaction_in(false); + } +/* + * Find exchange + */ + //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); + use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); + if (use.Get_exchange_ptr() != NULL) + { + use.Set_exchange_in(true); + use.Set_n_exchange_user(i); + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } + else + { + use.Set_exchange_in(false); + save.exchange = FALSE; + } + +/* + * Find surface + */ + int n_surface; + use.Set_surface_ptr(surface_bsearch(i, &n_surface)); + //use.Set_n_surface(n_surface); + if (use.Get_surface_ptr() != NULL) + { + use.Set_surface_in(true); + use.Set_n_surface_user(i); + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } + else + { + use.Set_surface_in(false); + save.surface = FALSE; + dl_type_x = NO_DL; + } +/* + * Find temperature; temp retardation is done in step + */ + use.Set_temperature_ptr(Utilities::Rxn_find(Rxn_temperature_map, i)); + if (use.Get_temperature_ptr() != NULL) + { + use.Set_temperature_in(true); + use.Set_n_temperature_user(i); + } + else + { + use.Set_temperature_in(false); + } +/* + * Find pressure + */ + use.Set_pressure_ptr(Utilities::Rxn_find(Rxn_pressure_map, i)); + if (use.Get_pressure_ptr() != NULL) + { + use.Set_pressure_in(true); + use.Set_n_pressure_user(i); + } + else + { + use.Set_pressure_in(false); + } +/* + * Find gas + */ + //use.Get_gas_phase_ptr() = gas_phase_bsearch(i, &use.n_gas_phase); + use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, i)); + if (use.Get_gas_phase_ptr() != NULL) + { + use.Set_gas_phase_in(true); + use.Set_n_gas_phase_user(i); + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } + else + { + use.Set_gas_phase_in(false); + save.gas_phase = FALSE; + } +/* + * Find ss_assemblage + */ + int n_ss_assemblage; + use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); + //use.Set_n_ss_assemblage(n_ss_assemblage); + if (use.Get_ss_assemblage_ptr() != NULL) + { + use.Set_ss_assemblage_in(true); + use.Set_n_ss_assemblage_user(i); + save.ss_assemblage = TRUE; + save.n_ss_assemblage_user = i; + save.n_ss_assemblage_user_end = i; + } + else + { + use.Set_ss_assemblage_in(false); + save.ss_assemblage = FALSE; + } +/* + * Find kinetics + */ + use.Set_kinetics_ptr(NULL); + use.Set_kinetics_in(false); + save.kinetics = FALSE; + if (use_kinetics == TRUE) + { + use.Set_kinetics_ptr(kinetics_bsearch(i, &n)); + if (use.Get_kinetics_ptr() != NULL) + { + use.Set_n_kinetics_user(i); + //use.Set_n_kinetics(n); + use.Set_kinetics_in(true); + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } + } + /* + if (use.irrev_ptr != NULL && use.Get_kinetics_ptr() != NULL) + { + warning_msg("Should not use REACTION in same simulation with KINETICS."); + } + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_get_equi_reactants(int l, int kin_end) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + + if (use.Get_pp_assemblage_in() == TRUE) + { + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, l)); + } + else + use.Set_pp_assemblage_ptr(NULL); + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + if (use.Get_gas_phase_in() == TRUE) + { + //use.Get_gas_phase_ptr() = gas_phase_bsearch(l, &use.n_gas_phase); + use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, l)); + } + else + use.Set_gas_phase_ptr(NULL); + if (use.Get_ss_assemblage_in() == TRUE) + { + int n_ss_assemblage; + use.Set_ss_assemblage_ptr( + ss_assemblage_bsearch(l, &n_ss_assemblage)); + //use.Set_n_ss_assemblage(n_ss_assemblage); + } + else + use.Set_ss_assemblage_ptr(NULL); + + if (kin_end == FALSE) + { + count_pp = count_s_s = count_pg = 0; + if (use.Get_pp_assemblage_ptr() != NULL) + //count_pp = use.Get_pp_assemblage_ptr()->count_comps; + count_pp = (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + count_pg = (int) gas_phase_ptr->Get_gas_comps().size(); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; + i++) + { + count_s_s++; + } + } + } + k = count_pp + count_s_s + count_pg; + x0_moles = NULL; + if (k == 0) + return (OK); + x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE)); + if (x0_moles == NULL) + malloc_error(); + for (i = 0; i < k; i++) + { + x0_moles[i] = 0.0; + } + k = -1; + if (pp_assemblage_ptr) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + x0_moles[++k] = it->second.Get_moles(); + } + } +#ifdef SKIP + for (j = 0; j < count_pp; j++) + { + x0_moles[++k] = use.Get_pp_assemblage_ptr()->pure_phases[j].moles; + } +#endif + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr) + { + for (size_t l = 0; l < gas_phase_ptr->Get_gas_comps().size(); l++) + { + x0_moles[++k] += gas_phase_ptr->Get_gas_comps()[l].Get_moles(); + } + } + } + if (count_s_s != 0) + { + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; + i++) + { + x0_moles[++k] = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + } +/*!!!! also miscibility gap comps ?? + */ + } + } + } + else + { + k = -1; + if (pp_assemblage_ptr && count_pp > 0) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + it->second.Set_moles(x0_moles[++k]); + it->second.Set_delta(0.0); + } + } +#ifdef SKIP + for (j = 0; j < count_pp; j++) + { + use.Get_pp_assemblage_ptr()->pure_phases[j].moles = x0_moles[++k]; + use.Get_pp_assemblage_ptr()->pure_phases[j].delta = 0.0; + } +#endif + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr && count_pg) + { + std::vector temp_comps(gas_phase_ptr->Get_gas_comps()); + for (size_t l = 0; l < temp_comps.size(); l++) + { + temp_comps[l].Set_moles(x0_moles[++k]); + } + gas_phase_ptr->Set_gas_comps(temp_comps); + } + } + if (count_s_s != 0) + { + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; + i++) + { + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].initial_moles = + x0_moles[++k]; + } +/*!!!! also miscibility gap comps ?? + */ + } + } +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * if (incremental_reactions == FALSE || reaction_step == count_total_steps) + */ + x0_moles = (LDBLE *) free_check_null(x0_moles); + } + return (OK); +} + + +void Phreeqc:: +f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data) +{ + int i, n_reactions, n_user; + LDBLE step_fraction; + struct kinetics *kinetics_ptr; + Phreeqc *pThis = (Phreeqc *) f_data; + + pThis->cvode_error = FALSE; + n_reactions = pThis->cvode_n_reactions; + n_user = pThis->cvode_n_user; + kinetics_ptr = (struct kinetics *) pThis->cvode_kinetics_ptr; + step_fraction = pThis->cvode_step_fraction; + pThis->rate_sim_time = pThis->cvode_rate_sim_time; + + for (i = 0; i < n_reactions; i++) + { + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_ptr->comps[i].moles = Ith(y, i + 1); + kinetics_ptr->comps[i].m = pThis->m_original[i] - Ith(y, i + 1); + if (kinetics_ptr->comps[i].m < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = pThis->m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + pThis->calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->use.Get_ss_assemblage_ptr() != NULL) + { + pThis->ss_assemblage_free(pThis->use.Get_ss_assemblage_ptr()); + pThis->ss_assemblage_copy(pThis->cvode_ss_assemblage_save, + pThis->use.Get_ss_assemblage_ptr(), n_user); + } + + if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) + { + pThis->run_reactions_iterations += pThis->iterations; + pThis->cvode_error = TRUE; + /* + error_msg("Mass balance error in f", CONTINUE); + */ + return; + } + if (pThis->cvode_test == TRUE) + { + return; + } + pThis->run_reactions_iterations += pThis->iterations; + for (i = 0; i < n_reactions; i++) + { + kinetics_ptr->comps[i].moles = 0.0; + } + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + for (i = 0; i < n_reactions; i++) + { + /* + dydx[i + 1] = kinetics_ptr->comps[i].moles; + */ + Ith(ydot, i + 1) = kinetics_ptr->comps[i].moles; + } + return; +} + +/* +static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); +*/ + +void Phreeqc:: +Jac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype t, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, + N_Vector vtemp3) +{ + int count_cvode_errors; + int i, j, n_reactions, n_user; + LDBLE *initial_rates, del; + struct kinetics *kinetics_ptr; + LDBLE step_fraction; + + Phreeqc *pThis = (Phreeqc *) f_data; + + pThis->cvode_error = FALSE; + n_reactions = pThis->cvode_n_reactions; + n_user = pThis->cvode_n_user; + kinetics_ptr = (struct kinetics *) pThis->cvode_kinetics_ptr; + step_fraction = pThis->cvode_step_fraction; + pThis->rate_sim_time = pThis->cvode_rate_sim_time; + + initial_rates = + (LDBLE *) pThis->PHRQ_malloc ((size_t) n_reactions * sizeof(LDBLE)); + if (initial_rates == NULL) + pThis->malloc_error(); + + for (i = 0; i < n_reactions; i++) + { + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_ptr->comps[i].moles = Ith(y, i + 1); + kinetics_ptr->comps[i].m = pThis->m_original[i] - Ith(y, i + 1); + if (kinetics_ptr->comps[i].m < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = pThis->m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + pThis->calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) + { + pThis->run_reactions_iterations += pThis->iterations; + pThis->cvode_error = TRUE; + /* + error_msg("Mass balance error in jacobian", CONTINUE); + */ + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; + } + pThis->run_reactions_iterations += pThis->iterations; + for (i = 0; i < n_reactions; i++) + kinetics_ptr->comps[i].moles = 0.0; + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + for (i = 0; i < n_reactions; i++) + { + initial_rates[i] = kinetics_ptr->comps[i].moles; + } + for (i = 0; i < n_reactions; i++) + { + /* calculate reaction up to current time */ + del = 1e-12; + pThis->cvode_error = TRUE; + count_cvode_errors = 0; + while (pThis->cvode_error == TRUE) + { + del /= 10.; + for (j = 0; j < n_reactions; j++) + { + /* + kinetics_ptr->comps[j].moles = y[j + 1]; + kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; + */ + kinetics_ptr->comps[j].moles = Ith(y, j + 1); + kinetics_ptr->comps[j].m = pThis->m_original[j] - Ith(y, j + 1); + if (kinetics_ptr->comps[i].m < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_ptr->comps[i].moles = pThis->m_original[i]; + kinetics_ptr->comps[i].m = 0.0; + } + } + + /* Add small amount of ith reaction */ + kinetics_ptr->comps[i].m -= del; + if (kinetics_ptr->comps[i].m < 0) + { + kinetics_ptr->comps[i].m = 0; + } + kinetics_ptr->comps[i].moles += del; + pThis->calc_final_kinetic_reaction(kinetics_ptr); + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->set_and_run_wrapper + (n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) + { + count_cvode_errors++; + pThis->cvode_error = TRUE; + if (count_cvode_errors > 30) + { + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; + } + pThis->run_reactions_iterations += pThis->iterations; + continue; + } + pThis->cvode_error = FALSE; + pThis->run_reactions_iterations += pThis->iterations; + /*kinetics_ptr->comps[i].moles -= del; */ + for (j = 0; j < n_reactions; j++) + kinetics_ptr->comps[j].moles = 0.0; + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + + /* calculate new rates for df/dy[i] */ + /* dfdx[i + 1] = 0.0; */ + for (j = 0; j < n_reactions; j++) + { + IJth(J, j + 1, i + 1) = + (kinetics_ptr->comps[j].moles - initial_rates[j]) / del; + } + } + } + for (i = 0; i < n_reactions; i++) + { + kinetics_ptr->comps[i].moles = 0; + } + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; +} + +void Phreeqc:: +cvode_init(void) +{ + cvode_kinetics_ptr = NULL; + cvode_test = 0; + cvode_error = 0; + cvode_n_user = -99; + cvode_n_reactions = -99; + cvode_step_fraction = 0.0; + cvode_rate_sim_time = 0.0; + cvode_rate_sim_time_start = 0.0; + cvode_last_good_time = 0.0; + cvode_prev_good_time = 0.0; + cvode_last_good_y = NULL; + cvode_prev_good_y = NULL; + kinetics_machEnv = NULL; + kinetics_y = kinetics_abstol = NULL; + kinetics_cvode_mem = NULL; + cvode_pp_assemblage_save = NULL; + cvode_ss_assemblage_save = NULL; + return; +} diff --git a/rename_cpp/mainsubs.cpp b/rename_cpp/mainsubs.cpp new file mode 100644 index 00000000..407aa82a --- /dev/null +++ b/rename_cpp/mainsubs.cpp @@ -0,0 +1,3520 @@ +#include +#include +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "PBasic.h" +#include "Temperature.h" +#include "Exchange.h" +#include "ExchComp.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" + +#if defined(WINDOWS) || defined(_WINDOWS) +#include +#endif + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +initialize(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialize global variables + */ + int i; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + + moles_per_kilogram_string = string_duplicate("Mol/kgw"); + pe_string = string_duplicate("pe"); + + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + itmax = 100; + max_tries = 100; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif + convergence_tolerance = 1e-8; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif + step_size = 100.; + pe_step_size = 10.; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + censor = 0.0; + mass_water_switch = FALSE; + /* mass_water_switch = TRUE; */ + delay_mass_water = FALSE; + incremental_reactions = FALSE; + aqueous_only = 0; + negative_concentrations = FALSE; + + LOG_10 = log(10.0); + /* Use space for all memory allocation */ + max_solution = MAX_SOLUTION; + //max_pp_assemblage = MAX_PP_ASSEMBLAGE; + //max_exchange = MAX_PP_ASSEMBLAGE; + max_surface = MAX_PP_ASSEMBLAGE; + //max_gas_phase = MAX_PP_ASSEMBLAGE; + max_kinetics = MAX_PP_ASSEMBLAGE; + max_ss_assemblage = MAX_PP_ASSEMBLAGE; + + max_elements = MAX_ELEMENTS; + max_elts = MAX_ELTS; + max_line = MAX_LINE; + max_master = MAX_MASTER; + max_mb_unknowns = MAX_TRXN; + max_phases = MAX_PHASES; + max_s = MAX_S; + max_strings = MAX_STRINGS; + max_trxn = MAX_TRXN; + max_logk = MAX_S; + max_master_isotope = MAX_ELTS; + + count_solution = 0; + //count_pp_assemblage = 0; + //count_exchange = 0; + count_surface = 0; + //count_gas_phase = 0; + count_kinetics = 0; + count_ss_assemblage = 0; + + count_elements = 0; + //count_irrev = 0; + count_master = 0; + //count_mix = 0; + count_phases = 0; + count_s = 0; + count_logk = 0; + count_master_isotope = 0; +/* + * Initialize advection + */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + advection_punch = (int *) PHRQ_malloc(sizeof(int)); + if (advection_punch == NULL) + malloc_error(); + advection_punch[0] = TRUE; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = (int *) PHRQ_malloc(sizeof(int)); + if (advection_print == NULL) + malloc_error(); + advection_print[0] = TRUE; + advection_warnings = TRUE; +/* + * Initialize transport + */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + interlayer_tortf = 100.0; + interlayer_Dpor = 0.1; +/* !!!! count_stag = 0; */ + mcd_substeps = 1.0; + print_modulus = 1; + punch_modulus = 1; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; +/* + * Allocate space + */ + //space((void **) ((void *) &pp_assemblage), INIT, &max_pp_assemblage, + // sizeof(struct pp_assemblage)); + + //space((void **) ((void *) &exchange), INIT, &max_exchange, + // sizeof(struct exchange)); + + space((void **) ((void *) &surface), INIT, &max_surface, + sizeof(struct surface)); + + //space((void **) ((void *) &gas_phase), INIT, &max_gas_phase, + // sizeof(struct gas_phase)); + + space((void **) ((void *) &kinetics), INIT, &max_kinetics, + sizeof(struct kinetics)); + + space((void **) ((void *) &ss_assemblage), INIT, &max_ss_assemblage, + sizeof(struct ss_assemblage)); + + space((void **) ((void *) &cell_data), INIT, &count_cells, + sizeof(struct cell_data)); + + space((void **) ((void *) &elements), INIT, &max_elements, + sizeof(struct element *)); + + space((void **) ((void *) &elt_list), INIT, &max_elts, + sizeof(struct elt_list)); + + + inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); + if (inverse == NULL) + malloc_error(); + count_inverse = 0; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); + + space((void **) ((void *) &master), INIT, &max_master, + sizeof(struct master *)); + + space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, + sizeof(struct unknown_list)); + + //mix = (struct mix *) PHRQ_malloc((size_t) sizeof(struct mix)); + //if (mix == NULL) + // malloc_error(); + //count_mix = 0; +/* !!!! */ + stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data)); + if (stag_data == NULL) + malloc_error(); + stag_data->count_stag = 0; + stag_data->exch_f = 0; + stag_data->th_m = 0; + stag_data->th_im = 0; + + space((void **) ((void *) &phases), INIT, &max_phases, + sizeof(struct phase *)); + + space((void **) ((void *) &trxn.token), INIT, &max_trxn, + sizeof(struct rxn_token_temp)); + + space((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); + + space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); + + space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, + sizeof(struct master_isotope *)); + + solution = + (struct solution **) PHRQ_malloc((size_t) MAX_SOLUTION * + sizeof(struct solution *)); + if (solution == NULL) + malloc_error(); + + title_x = NULL; + pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; +/* SRC ADDED */ + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; +/* SRC ADDED */ + count_isotopes_x = 0; + isotopes_x = + (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); + if (isotopes_x == NULL) + malloc_error(); + x = NULL; + max_unknowns = 0; + + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + + hcreate_multi((unsigned) max_logk, &logk_hash_table); + hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); +/* + * Create hash tables + */ + hcreate_multi((unsigned) max_elements, &elements_hash_table); + hcreate_multi((unsigned) max_s, &species_hash_table); + hcreate_multi((unsigned) max_phases, &phases_hash_table); +/* + * Initialize use pointers + */ + //use_init(); +/* + * Initialize punch + */ + punch.in = FALSE; + punch.new_def = FALSE; + punch.count_totals = 0; + punch.totals = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.totals == NULL) + malloc_error(); + punch.count_molalities = 0; + punch.molalities = + (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.molalities == NULL) + malloc_error(); + punch.count_activities = 0; + punch.activities = + (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.activities == NULL) + malloc_error(); + punch.count_pure_phases = 0; + punch.pure_phases = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.pure_phases == NULL) + malloc_error(); + punch.count_si = 0; + punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.si == NULL) + malloc_error(); + punch.count_gases = 0; + punch.gases = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.gases == NULL) + malloc_error(); + punch.count_s_s = 0; + punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.s_s == NULL) + malloc_error(); + + punch.count_kinetics = 0; + punch.kinetics = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.kinetics == NULL) + malloc_error(); + + punch.count_isotopes = 0; + punch.isotopes = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.isotopes == NULL) + malloc_error(); + + punch.count_calculate_values = 0; + punch.calculate_values = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.calculate_values == NULL) + malloc_error(); + + count_save_values = 0; + save_values = + (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); + if (save_values == NULL) + malloc_error(); + + punch.inverse = TRUE; + + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; +/* + * last model + */ + last_model.force_prep = TRUE; + last_model.temperature = -100; + last_model.pressure = 0; + last_model.count_exchange = -1; + last_model.exchange = NULL; + last_model.count_kinetics = -1; + last_model.kinetics = NULL; + last_model.count_gas_phase = -1; + last_model.gas_phase = NULL; + last_model.count_ss_assemblage = -1; + last_model.ss_assemblage = NULL; + last_model.count_pp_assemblage = -1; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.dl_type = NO_DL; + last_model.surface_type = UNKNOWN_DL; + last_model.only_counter_ions = FALSE; + last_model.thickness = 1e-8; + last_model.count_surface_comp = -1; + last_model.surface_comp = NULL; + last_model.count_surface_charge = -1; + last_model.surface_charge = NULL; +/* + * rates + */ + rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); + if (rates == NULL) + malloc_error(); + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_p = NULL; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; +/* + * user_print, user_punch + */ + user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_print == NULL) + malloc_error(); + user_print->commands = NULL; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_punch == NULL) + malloc_error(); + user_punch->commands = NULL; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + user_punch_headings = (const char **) PHRQ_malloc(sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + user_punch_count_headings = 0; +#if defined PHREEQ98 +/* + * user_graph + */ + user_graph = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_graph == NULL) + malloc_error(); + user_graph->commands = NULL; + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); + if (user_graph_headings == NULL) + malloc_error(); + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_temp == NULL) + malloc_error(); + llnl_count_temp = 0; + llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_adh == NULL) + malloc_error(); + llnl_count_adh = 0; + llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdh == NULL) + malloc_error(); + llnl_count_bdh = 0; + llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdot == NULL) + malloc_error(); + llnl_count_bdot = 0; + llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_co2_coefs == NULL) + malloc_error(); + llnl_count_co2_coefs = 0; +/* + * + */ + basic_interpreter = new PBasic(this, phrq_io); + + change_surf = + (struct Change_Surf *) + PHRQ_malloc((size_t) (2 * sizeof(struct Change_Surf))); + if (change_surf == NULL) + malloc_error(); + change_surf[0].cell_no = -99; + change_surf[0].next = TRUE; + change_surf[1].cell_no = -99; + change_surf[1].next = FALSE; + change_surf_count = 0; + + +#if defined(WINDOWS) || defined(_WINDOWS) + /* SRC pr.status = FALSE; */ +#endif + /* Initialize print here, not in global.h */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.ss_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + if (phast == TRUE) + { + pr.status = FALSE; + } + else + { + pr.status = TRUE; + } + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + count_warnings = 0; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + species_list = NULL; + + user_database = NULL; + first_read_input = TRUE; + have_punch_name = FALSE; + selected_output_file_name = NULL; + dump_file_name = NULL; + +#ifdef PHREEQCI_GUI + g_spread_sheet.heading = NULL; + g_spread_sheet.units = NULL; + g_spread_sheet.count_rows = 0; + g_spread_sheet.rows = NULL; + g_spread_sheet.defaults.units = NULL; + g_spread_sheet.defaults.count_iso = 0; + g_spread_sheet.defaults.iso = NULL; +#endif + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + space((void **) ((void *) &calculate_value), INIT, &max_calculate_value, + sizeof(struct calculate_value *)); + hcreate_multi((unsigned) max_calculate_value, + &calculate_value_hash_table); + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, + sizeof(struct isotope_ratio *)); + hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + space((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, + sizeof(struct isotope_alpha *)); + hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); + + /* + * define constant named log_k + */ + strcpy(token, "XconstantX"); + logk_ptr = logk_store(token, TRUE); + strcpy(token, "1.0"); + read_log_k_only(token, &logk_ptr->log_k[0]); + + phreeqc_mpi_myself = 0; + + copier_init(©_solution); + copier_init(©_pp_assemblage); + copier_init(©_exchange); + copier_init(©_surface); + copier_init(©_ss_assemblage); + copier_init(©_gas_phase); + copier_init(©_kinetics); + copier_init(©_mix); + copier_init(©_reaction); + copier_init(©_temperature); + copier_init(©_pressure); + + set_forward_output_to_log(FALSE); + simulation = 0; + /* + * cvode + */ + + cvode_init(); + /* + * Pitzer + */ + pitzer_init(); + /* + * SIT + */ + sit_init(); + /* + * to facilitate debuging + */ + //dbg_use = &use; + dbg_solution = solution; + //dbg_exchange = exchange; + dbg_surface = surface; + //dbg_pp_assemblage = pp_assemblage; + dbg_kinetics = kinetics; + //dbg_irrev = irrev; + //dbg_mix = mix; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + + zeros = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (zeros == NULL) + malloc_error(); + zeros[0] = 0.0; + zeros_max = 1; + + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + + charge_group = NULL; + print_density = 0; + + + same_model = FALSE; + same_temperature = FALSE; + same_pressure = FALSE; + g_iterations = -1; + G_TOL = 1e-8; + save_init(-1); + count_species_list = 0; + max_species_list = 0; + count_sum_jacob0 = 0; + max_sum_jacob0 = 0; + count_sum_mb1 = 0; + max_sum_mb1 = 0; + count_sum_jacob1 = 0; + max_sum_jacob1 = 0; + count_sum_mb2 = 0; + max_sum_mb2 = 0; + count_sum_jacob2 = 0; + max_sum_jacob2 = 0; + count_sum_delta = 0; + max_sum_delta = 0; + new_x = FALSE; + tc_x = 0; + tk_x = 0; + ph_x = 0; + solution_pe_x = 0; + mu_x = 0; + ah2o_x = 0; + density_x = 0; + total_h_x = 0; + total_o_x = 0; + cb_x = 0; + total_ions_x = 0; + mass_water_aq_x = 0; + mass_water_surfaces_x = 0; + mass_water_bulk_x = 0; + default_pe_x = 0; + dl_type_x = NO_DL; + total_carbon = 0; + total_co2 = 0; + total_alkalinity = 0; + gfw_water = 0; + step_x = 0; + kin_time_x = 0; + correct_disp = FALSE; + cell = 0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + default_Dw = 0; + multi_Dpor = 0; + interlayer_Dpor = 0.1; + multi_Dpor_lim = 0; + interlayer_Dpor_lim = 0; + multi_Dn = 0; + interlayer_tortf = 100; + cell_no = 0; + new_model = TRUE; + new_exchange = FALSE; + new_pp_assemblage = FALSE; + new_surface = FALSE; + new_reaction = FALSE; + new_temperature = FALSE; + new_mix = FALSE; + new_solution = FALSE; + new_gas_phase = FALSE; + new_inverse = FALSE; + new_punch = FALSE; + new_ss_assemblage = FALSE; + new_kinetics = FALSE; + new_copy = FALSE; + new_pitzer = FALSE; + element_h_one = NULL; + count_elts = 0; + count_s_x = 0; + max_s_x = 0; + count_unknowns = 0; + ah2o_unknown = NULL; + alkalinity_unknown = NULL; + carbon_unknown = NULL; + charge_balance_unknown = NULL; + exchange_unknown = NULL; + mass_hydrogen_unknown = NULL; + mass_oxygen_unknown = NULL; + mb_unknown = NULL; + mu_unknown = NULL; + pe_unknown = NULL; + ph_unknown = NULL; + pure_phase_unknown = NULL; + solution_phase_boundary_unknown = NULL; + surface_unknown = NULL; + gas_unknown = NULL; + s_s_unknown = NULL; + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] = 0; + } + for (i = 0; i < 3; i++) + { + trxn.dz[i] = 0; + } + count_trxn = 0; + count_mb_unknowns = 0; + status_on = TRUE; + status_timer = (float) clock(); + status_interval = 0; + count_rate_p = 0; + //strcpy(error_string,""); + reaction_step = 0; + transport_step = 0; + transport_start = 0; + advection_step = 0; + stop_program = FALSE; + count_strings = 0; + input_error = 0; + parse_error = 0; + paren_count = 0; + iterations = 0; + gamma_iterations = 0; + run_reactions_iterations = 0; + step_size_now = step_size; + dampen_ah2o = false; + slack = false; + numerical_fixed_volume = false; + force_numerical_fixed_volume = false; + switch_numerical = false; + pe_step_size_now = pe_step_size; + count_total_steps = 0; + remove_unstable_phases = FALSE; + for (i = 0; i < 50; i++) + { + match_tokens[i].name = NULL; + match_tokens[i].coef = 0; + } + count_match_tokens = 0; + initial_solution_isotopes = FALSE; + full_pitzer = FALSE; + always_full_pitzer = FALSE; + IC = -1; + COSMOT = 0; + AW = 0; + sys = NULL; + count_sys = 0; + max_sys = 0; + sys_tot = 0; + AA_basic = 0; + BB_basic = 0; + CC = 0; + I_m = 0; + rho_0 = 0; + solution_mass = 0; + solution_volume = 0; + + patm_x = 1; /* Initialize pressure of component x to 1 atm */ + + /* model_min_value = 0; */ + + return; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_use(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Structure "use" has list of solution, ex, surf, pp_assemblage, + * gas_phase and solid solution to use in current calculations, + * also mix, irrev, and temp. + * This routine searches for the user numbers in each list + * (solution, ex, ...) and sets a pointer in structure use + */ + +/* + * Initial solution case + */ + use.Set_pp_assemblage_ptr(NULL); + use.Set_mix_ptr(NULL); + use.Set_reaction_ptr(NULL); + use.Set_exchange_ptr(NULL); + use.Set_kinetics_ptr(NULL); + use.Set_surface_ptr(NULL); + use.Set_temperature_ptr(NULL); + use.Set_pressure_ptr(NULL); + use.Set_gas_phase_ptr(NULL); + use.Set_ss_assemblage_ptr(NULL); + + if (state < REACTION) + { + return (OK); + } +/* + * Reaction case + */ + if (use.Get_pp_assemblage_in() == FALSE && + use.Get_reaction_in() == FALSE && + use.Get_mix_in() == FALSE && + use.Get_exchange_in() == FALSE && + use.Get_kinetics_in() == FALSE && + use.Get_surface_in() == FALSE && + use.Get_temperature_in() == FALSE && + use.Get_pressure_in() == FALSE && + use.Get_gas_phase_in() == FALSE && use.Get_ss_assemblage_in() == FALSE) + { + return (FALSE); + } + if (use.Get_solution_in() == FALSE && use.Get_mix_in() == FALSE) + return (FALSE); +/* + * Find solution + */ + if (use.Get_solution_in() == TRUE) + { + int n_solution; + use.Set_solution_ptr( + solution_bsearch(use.Get_n_solution_user(), &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() == NULL) + { + error_string = sformatf( "Solution %d not found.", + use.Get_n_solution_user()); + error_msg(error_string, STOP); + } + } +/* + * Find mixture + */ + if (use.Get_mix_in() == TRUE) + { + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user())); + //use.Get_mix_ptr() =(void *) Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); + use.Set_n_mix_user_orig(use.Get_n_mix_user()); + if (use.Get_mix_ptr() == NULL) + { + error_string = sformatf( "Mix %d not found.", + use.Get_n_mix_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_mix_ptr(NULL); + } +/* + * Find pure phase assemblage + */ + if (use.Get_pp_assemblage_in() == TRUE) + { + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user())); + //use.Get_pp_assemblage_ptr() = + // pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), + // &use.n_pp_assemblage); + if (use.Get_pp_assemblage_ptr() == NULL) + { + error_string = sformatf( "Pure phase assemblage %d not found.", + use.Get_n_pp_assemblage_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_pp_assemblage_ptr(NULL); + } +/* + * Find irrev reaction + */ + if (use.Get_reaction_in() == TRUE) + { + use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user())); + if (use.Get_reaction_ptr() == NULL) + { + error_string = sformatf( "Reaction %d not found.", + use.Get_n_reaction_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_reaction_ptr(NULL); + } +/* + * Find exchange + */ + if (use.Get_exchange_in() == TRUE) + { + use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user())); + if (use.Get_exchange_ptr() == NULL) + { + error_string = sformatf( "Exchange %d not found.", + use.Get_n_exchange_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_exchange_ptr(NULL); + } +/* + * Find kinetics + */ + if (use.Get_kinetics_in() == TRUE) + { + int n_kinetics; + use.Set_kinetics_ptr( + kinetics_bsearch(use.Get_n_kinetics_user(), &n_kinetics)); + //use.Set_n_kinetics(n_kinetics); + if (use.Get_kinetics_ptr() == NULL) + { + error_string = sformatf( "Kinetics %d not found.", + use.Get_n_kinetics_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_kinetics_ptr(NULL); + } +/* + * Find surface + */ + dl_type_x = NO_DL; + if (use.Get_surface_in() == TRUE) + { + int n_surface; + use.Set_surface_ptr(surface_bsearch(use.Get_n_surface_user(), &n_surface)); + //use.Set_n_surface(n_surface); + if (use.Get_surface_ptr() == NULL) + { + error_string = sformatf( "Surface %d not found.", + use.Get_n_surface_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_surface_ptr(NULL); + } +/* + * Find temperature + */ + if (use.Get_temperature_in() == TRUE) + { + use.Set_temperature_ptr(Utilities::Rxn_find(Rxn_temperature_map, use.Get_n_temperature_user())); + if (use.Get_temperature_ptr() == NULL) + { + error_string = sformatf( "Temperature %d not found.", + use.Get_n_temperature_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_temperature_ptr(NULL); + } +/* + * Find pressure + */ + if (use.Get_pressure_in() == TRUE) + { + use.Set_pressure_ptr(Utilities::Rxn_find(Rxn_pressure_map, use.Get_n_pressure_user())); + if (use.Get_pressure_ptr() == NULL) + { + error_string = sformatf( "Pressure %d not found.", use.Get_n_pressure_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_pressure_ptr(NULL); + } +/* + * Find gas + */ + if (use.Get_gas_phase_in() == TRUE) + { + //use.Get_gas_phase_ptr() = gas_phase_bsearch(use.Get_n_gas_phase_user(), &use.n_gas_phase); + use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, use.Get_n_gas_phase_user())); + if (use.Get_gas_phase_ptr() == NULL) + { + error_string = sformatf( "Gas_phase %d not found.", + use.Get_n_gas_phase_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_gas_phase_ptr(NULL); + } +/* + * Find ss_assemblage + */ + if (use.Get_ss_assemblage_in() == TRUE) + { + int n_ss_assemblage_user; + use.Set_ss_assemblage_ptr( + ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), + &n_ss_assemblage_user)); + if (use.Get_ss_assemblage_ptr() == NULL) + { + error_string = sformatf( "ss_assemblage %d not found.", + use.Get_n_ss_assemblage_user()); + error_msg(error_string, STOP); + } + } + else + { + use.Set_ss_assemblage_ptr(NULL); + } + /* + if (use.irrev_ptr != NULL && use.Get_kinetics_ptr() != NULL) + { + warning_msg("Should not use REACTION in same simulation with KINETICS."); + } + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_solutions(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of solutions, make initial solution calculations + * for any marked "new". + */ + int i, converge, converge1; + int n, last, n_user, print1; + char token[2 * MAX_LENGTH]; + + state = INITIAL_SOLUTION; + set_use(); + print1 = TRUE; + dl_type_x = NO_DL; + for (n = 0; n < count_solution; n++) + { + initial_solution_isotopes = FALSE; + if (solution[n] != NULL && solution[n]->new_def == TRUE) + { + if (print1 == TRUE && print == TRUE) + { + dup_print("Beginning of initial solution calculations.", + TRUE); + print1 = FALSE; + } + if (print == TRUE) + { + sprintf(token, "Initial solution %d.\t%.350s", + solution[n]->n_user, solution[n]->description); + dup_print(token, FALSE); + } + use.Set_solution_ptr(solution[n]); + prep(); + k_temp(solution[n]->tc, solution[n]->patm); + set(TRUE); + always_full_pitzer = FALSE; + converge = model(); + if (converge == ERROR && diagonal_scale == FALSE) + { + diagonal_scale = TRUE; + always_full_pitzer = TRUE; + set(TRUE); + converge = model(); + diagonal_scale = FALSE; + } + converge1 = check_residuals(); + sum_species(); + add_isotopes(solution[n]); + punch_all(); + print_all(); + /* free_model_allocs(); */ + if (converge == ERROR || converge1 == ERROR) + { + error_msg("Model failed to converge for initial solution.", + STOP); + } + n_user = solution[n]->n_user; + last = solution[n]->n_user_end; + /* copy isotope data */ + if (solution[n]->count_isotopes > 0) + { + count_isotopes_x = solution[n]->count_isotopes; + isotopes_x = + (struct isotope *) PHRQ_realloc(isotopes_x, + (size_t) count_isotopes_x + * sizeof(struct isotope)); + if (isotopes_x == NULL) + malloc_error(); + memcpy(isotopes_x, solution[n]->isotopes, + (size_t) count_isotopes_x * sizeof(struct isotope)); + } + else + { + count_isotopes_x = 0; + } + xsolution_save(n_user); + for (i = n_user + 1; i <= last; i++) + { + solution_duplicate(n_user, i); + } + } + } + initial_solution_isotopes = FALSE; + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_exchangers(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of exchangers, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i, converge, converge1; + int last, n_user, print1; + char token[2 * MAX_LENGTH]; + + state = INITIAL_EXCHANGE; + set_use(); + print1 = TRUE; + dl_type_x = NO_DL; + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + if (!it->second.Get_new_def()) + continue; + cxxExchange *exchange_ptr = &(it->second); + n_user = exchange_ptr->Get_n_user(); + last = exchange_ptr->Get_n_user_end(); + exchange_ptr->Set_n_user_end(n_user); + exchange_ptr->Set_new_def(false); + if (exchange_ptr->Get_solution_equilibria()) + { + if (print1 == TRUE && print == TRUE) + { + dup_print("Beginning of initial exchange" + "-composition calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) + { + sprintf(token, "Exchange %d.\t%.350s", + exchange_ptr->Get_n_user(), exchange_ptr->Get_description().c_str()); + dup_print(token, FALSE); + } + use.Set_exchange_ptr(exchange_ptr); + use.Set_solution_ptr(solution_bsearch(exchange_ptr->Get_n_solution(), &i, TRUE)); + if (use.Get_solution_ptr() == NULL) + { + error_msg + ("Solution not found for initial exchange calculation", + STOP); + } + + prep(); + k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + set(TRUE); + converge = model(); + converge1 = check_residuals(); + sum_species(); + species_list_sort(); + print_exchange(); + xexchange_save(n_user); + punch_all(); + /* free_model_allocs(); */ + if (converge == ERROR || converge1 == ERROR) + { + error_msg + ("Model failed to converge for initial exchange calculation.", + STOP); + } + } + for (i = n_user + 1; i <= last; i++) + { + //exchange_duplicate(n_user, i); + Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_gas_phases(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of gas_phases, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i, converge, converge1; + int last, n_user, print1; + char token[2 * MAX_LENGTH]; + struct phase *phase_ptr; + struct rxn_token *rxn_ptr; + LDBLE lp; + bool PR = false; + + state = INITIAL_GAS_PHASE; + set_use(); + print1 = TRUE; + dl_type_x = NO_DL; + std::map::iterator it = Rxn_gas_phase_map.begin(); + for ( ; it != Rxn_gas_phase_map.end(); it++) + //for (n = 0; n < count_gas_phase; n++) + { + cxxGasPhase *gas_phase_ptr = &it->second; + if (!gas_phase_ptr->Get_new_def()) + continue; + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + gas_phase_ptr->Set_new_def(false); + if (gas_phase_ptr->Get_solution_equilibria()) + { + if (print1 == TRUE && print == TRUE) + { + dup_print("Beginning of initial gas_phase" + "-composition calculations.", TRUE); + print1 = FALSE; + } + if (print == TRUE) + { + sprintf(token, "Gas_Phase %d.\t%.350s", + gas_phase_ptr->Get_n_user(), gas_phase_ptr->Get_description().c_str()); + dup_print(token, FALSE); + } + + /* Try to obtain a solution pointer */ + use.Set_solution_ptr( + solution_bsearch(gas_phase_ptr->Get_n_solution(), &i, TRUE)); + prep(); + k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + set(TRUE); + converge = model(); + converge1 = check_residuals(); + if (converge == ERROR || converge1 == ERROR) + { + /* free_model_allocs(); */ + error_msg + ("Model failed to converge for initial gas phase calculation.", + STOP); + } + use.Set_gas_phase_ptr(gas_phase_ptr); + gas_phase_ptr->Set_total_p(0); + gas_phase_ptr->Set_total_moles(0); + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + { + cxxGasComp * gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); + //phase_ptr = gas_comp_ptr->phase; + int k; + phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + for (rxn_ptr = phase_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + phase_ptr->p_soln_x = exp(lp * LOG_10); + gas_phase_ptr->Set_total_p(gas_phase_ptr->Get_total_p() + phase_ptr->p_soln_x); + phase_ptr->moles_x = phase_ptr->p_soln_x * + gas_phase_ptr->Get_volume() / (R_LITER_ATM * tk_x); + gc_ptr->Set_moles(phase_ptr->moles_x); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + phase_ptr->moles_x); + if (phase_ptr->p_c || phase_ptr->t_c) + PR = true; + } + else + { + phase_ptr->moles_x = 0; + } + } + if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->patm) > 5) + { + sprintf(token, + "WARNING: While initializing gas phase composition by equilibrating:\n%s (%.2f atm) %s (%.2f atm).\n%s.", + " Gas phase pressure", + (double) gas_phase_ptr->Get_total_p(), + "is not equal to solution-pressure", + (double) use.Get_solution_ptr()->patm, + " Pressure effects on solubility may be incorrect"); + dup_print(token, FALSE); + } + + print_gas_phase(); + if (PR /*&& use.Get_gas_phase_ptr()->total_p > 1.0*/) + warning_msg("While initializing gas phase composition by equilibrating:\n" + " Found definitions of gas' critical temperature and pressure.\n" + " Going to use Peng-Robinson in subsequent calculations.\n"); + xgas_save(n_user); + punch_all(); + /* free_model_allocs(); */ + } + Utilities::Rxn_copies(Rxn_gas_phase_map, n_user, last); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_surfaces(int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of surfaces, make initial calculations + * for any marked "new" that are defined to be in equilibrium with a + * solution. + */ + int i; + int n, last, n_user, print1; + char token[2 * MAX_LENGTH]; + + state = INITIAL_SURFACE; + set_use(); + print1 = TRUE; + for (n = 0; n < count_surface; n++) + { + if (surface[n].new_def != TRUE) + continue; + n_user = surface[n].n_user; + last = surface[n].n_user_end; + surface[n].n_user_end = n_user; + if (surface[n].solution_equilibria == TRUE) + { + if (print1 == TRUE && print == TRUE) + { + dup_print + ("Beginning of initial surface-composition calculations.", + TRUE); + print1 = FALSE; + } + if (print == TRUE) + { + sprintf(token, "Surface %d.\t%.350s", + surface[n].n_user, surface[n].description); + dup_print(token, FALSE); + } + use.Set_surface_ptr(&(surface[n])); + dl_type_x = use.Get_surface_ptr()->dl_type; + use.Set_solution_ptr( + solution_bsearch(surface[n].n_solution, &i, TRUE)); + if (use.Get_solution_ptr() == NULL) + { + error_msg + ("Solution not found for initial surface calculation", + STOP); + } + set_and_run_wrapper(-1, FALSE, FALSE, -1, 0.0); + species_list_sort(); + print_surface(); + /*print_all(); */ + punch_all(); + xsurface_save(n_user); + /* free_model_allocs(); */ + } + for (i = n_user + 1; i <= last; i++) + { + surface_duplicate(n_user, i); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make all reaction calculation which could include: + * equilibrium with a pure-phase assemblage, + * equilibrium with an exchanger, + * equilibrium with an surface, + * equilibrium with a gas phase, + * equilibrium with a solid solution assemblage, + * kinetics, + * change of temperature, + * mixture, + * or irreversible reaction. + */ + int count_steps, use_mix, m; + char token[2 * MAX_LENGTH]; + struct save save_data; + LDBLE kin_time; + struct kinetics *kinetics_ptr; + + state = REACTION; + /* last_model.force_prep = TRUE; */ + if (set_use() == FALSE) + return (OK); +/* + * Find maximum number of steps + */ + dup_print("Beginning of batch-reaction calculations.", TRUE); + count_steps = 1; + if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) + { + cxxReaction *reaction_ptr = (cxxReaction *) use.Get_reaction_ptr(); + if (reaction_ptr->Get_actualSteps() > count_steps) + count_steps = reaction_ptr->Get_actualSteps(); + } + if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) + { + if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) + count_steps = abs(use.Get_kinetics_ptr()->count_steps); + } + if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) + { + int count = ((cxxTemperature *) use.Get_temperature_ptr())->Get_countTemps(); + if (count > count_steps) + { + count_steps = count; + } + } + if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) + { + int count = ((cxxPressure *) use.Get_pressure_ptr())->Get_count(); + if (count > count_steps) + { + count_steps = count; + } + } + count_total_steps = count_steps; +/* + * save data for saving solutions + */ + memcpy(&save_data, &save, sizeof(struct save)); + /* + *Copy everything to -2 + */ + copy_use(-2); + rate_sim_time_start = 0; + rate_sim_time = 0; + for (reaction_step = 1; reaction_step <= count_steps; reaction_step++) + { + sprintf(token, "Reaction step %d.", reaction_step); + if (reaction_step > 1 && incremental_reactions == FALSE) + { + copy_use(-2); + } + set_initial_moles(-2); + dup_print(token, FALSE); +/* + * Determine time step for kinetics + */ + kin_time = 0.0; + if (use.Get_kinetics_in() == TRUE) + { + kinetics_ptr = kinetics_bsearch(-2, &m); + if (incremental_reactions == FALSE) + { + if (kinetics_ptr->count_steps > 0) + { + if (reaction_step > kinetics_ptr->count_steps) + { + kin_time = + kinetics_ptr->steps[kinetics_ptr->count_steps - + 1]; + } + else + { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + kin_time = kinetics_ptr->steps[0]; + } + else + { + kin_time = + reaction_step * kinetics_ptr->steps[0] / + ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + else + { + /* incremental reactions */ + if (kinetics_ptr->count_steps > 0) + { + if (reaction_step > kinetics_ptr->count_steps) + { + kin_time = + kinetics_ptr->steps[kinetics_ptr->count_steps - + 1]; + } + else + { + kin_time = kinetics_ptr->steps[reaction_step - 1]; + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + kin_time = 0; + } + else + { + kin_time = + kinetics_ptr->steps[0] / + ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + } + if (incremental_reactions == FALSE || + (incremental_reactions == TRUE && reaction_step == 1)) + { + use_mix = TRUE; + } + else + { + use_mix = FALSE; + } +/* + * Run reaction step + */ + run_reactions(-2, kin_time, use_mix, 1.0); + if (incremental_reactions == TRUE) + { + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start; + } + else + { + rate_sim_time = kin_time; + } + if (state != ADVECTION) + { + punch_all(); + print_all(); + } + /* saves back into -2 */ + if (reaction_step < count_steps) + { + saver(); + } + } +/* + * save end of reaction + */ + memcpy(&save, &save_data, sizeof(struct save)); + if (use.Get_kinetics_in() == TRUE) + { + kinetics_duplicate(-2, use.Get_n_kinetics_user()); + } + saver(); + + /* free_model_allocs(); */ + /* last_model.force_prep = TRUE; */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +saver(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save results of calcuations (data in variables with _x, + * in unknown structure x, in master, or s) into structure + * arrays. Structure "save" has info on whether to save + * data for each entity (solution, ex, surf, pp, gas, or s_s). + * Initial calculation may be saved into multiple "n_user" + * slots. + */ + int i, n; + char token[MAX_LENGTH]; + + if (save.solution == TRUE) + { + sprintf(token, "Solution after simulation %d.", simulation); + description_x = (char *) free_check_null(description_x); + description_x = string_duplicate(token); + n = save.n_solution_user; + xsolution_save(n); + for (i = save.n_solution_user + 1; i <= save.n_solution_user_end; i++) + { + solution_duplicate(n, i); + } + } + if (save.pp_assemblage == TRUE) + { + n = save.n_pp_assemblage_user; + xpp_assemblage_save(n); + Utilities::Rxn_copies(Rxn_pp_assemblage_map, save.n_pp_assemblage_user, save.n_pp_assemblage_user_end); + //for (i = save.n_pp_assemblage_user + 1; + // i <= save.n_pp_assemblage_user_end; i++) + //{ + // pp_assemblage_duplicate(n, i); + //} + } + if (save.exchange == TRUE) + { + n = save.n_exchange_user; + xexchange_save(n); + for (i = save.n_exchange_user + 1; i <= save.n_exchange_user_end; i++) + { + //exchange_duplicate(n, i); + Utilities::Rxn_copy(Rxn_exchange_map, n, i); + } + } + if (save.surface == TRUE) + { + n = save.n_surface_user; + xsurface_save(n); + for (i = save.n_surface_user + 1; i <= save.n_surface_user_end; i++) + { + surface_duplicate(n, i); + } + } + if (save.gas_phase == TRUE) + { + n = save.n_gas_phase_user; + xgas_save(n); + for (i = save.n_gas_phase_user + 1; i <= save.n_gas_phase_user_end; + i++) + { + //gas_phase_duplicate(n, i); + Utilities::Rxn_copy(Rxn_gas_phase_map, n, i); + } + } + if (save.ss_assemblage == TRUE) + { + n = save.n_ss_assemblage_user; + xss_assemblage_save(n); + for (i = save.n_ss_assemblage_user + 1; + i <= save.n_ss_assemblage_user_end; i++) + { + ss_assemblage_duplicate(n, i); + } + } + if (save.kinetics == TRUE && use.Get_kinetics_in() == TRUE + /*&& use.Get_kinetics_ptr() != NULL */) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + } + else if (use.Get_kinetics_in() != FALSE) + { + use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + } + if (use.Get_kinetics_ptr() != NULL) + { + n = use.Get_kinetics_ptr()->n_user; + for (i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) + { + kinetics_duplicate(n, i); + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xexchange_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save exchanger assemblage into structure exchange with user + * number n_user. + */ + int i, j; + char token[MAX_LENGTH]; + int count_comps; + //struct exchange temp_exchange, *exchange_ptr; + + LDBLE charge; + if (use.Get_exchange_ptr() == NULL) + return (OK); + + cxxExchange temp_exchange = *((cxxExchange *) use.Get_exchange_ptr()); +/* + * Store data for structure exchange + */ + temp_exchange.Set_n_user(n_user); + temp_exchange.Set_n_user_end(n_user); + temp_exchange.Set_new_def(false); + sprintf(token, "Exchange assemblage after simulation %d.", simulation); + temp_exchange.Set_description(token); + temp_exchange.Set_solution_equilibria(false); + temp_exchange.Set_n_solution(-999); + temp_exchange.Get_exchComps().clear(); + +/* + * Write exch_comp structure for each exchange component + */ + count_comps = 0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == EXCH) + { + const cxxExchComp *comp_ptr = ((cxxExchange *) use.Get_exchange_ptr())->ExchComp_find(x[i]->exch_comp); + if (!comp_ptr) + { + assert(false); + } + cxxExchComp xcomp = *comp_ptr; + xcomp.Set_la(x[i]->master[0]->s->la); + xcomp.Set_moles(0); +/* + * Save element concentrations on exchanger + */ + count_elts = 0; + paren_count = 0; + charge = 0.0; + for (j = 0; j < count_species_list; j++) + { + if (species_list[j].master_s == x[i]->master[0]->s) + { + add_elt_list(species_list[j].s->next_elt, + species_list[j].s->moles); + charge += species_list[j].s->moles * species_list[j].s->z; + } + } +/* + * Keep exchanger related to phase even if none currently in solution + */ + if (xcomp.Get_phase_name().size() != 0 && count_elts == 0) + { + add_elt_list(x[i]->master[0]->s->next_elt, 1e-20); + } +/* + * Store list + */ + xcomp.Set_charge_balance(charge); + + xcomp.Set_totals(elt_list_NameDouble()); +/* debug + output_msg(sformatf( "Exchange charge_balance: %e\n", charge)); + */ + /* update unknown pointer */ + //x[i]->exch_comp = &(temp_exchange.comps[count_comps]); + temp_exchange.Get_exchComps()[x[i]->exch_comp] = xcomp; + } + } +/* + * Finish up + */ + Rxn_exchange_map[n_user] = temp_exchange; + + use.Set_exchange_ptr(NULL); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xgas_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save gas composition into structure gas_phase with user + * number n_user. + */ + //int count_comps, n, i; + //struct gas_phase temp_gas_phase, *gas_phase_ptr; + char token[MAX_LENGTH]; + + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase temp_gas_phase(*gas_phase_ptr); +/* + * Count gases + */ + //size_t count_comps = gas_phase_ptr->Get_gasPhaseComps().size(); +/* + * Store in gas_phase + */ + + temp_gas_phase.Set_n_user(n_user); + temp_gas_phase.Set_n_user_end(n_user); + sprintf(token, "Gas phase after simulation %d.", simulation); + temp_gas_phase.Set_description(token); + temp_gas_phase.Set_new_def(false); + temp_gas_phase.Set_solution_equilibria(false); + temp_gas_phase.Set_n_solution(-99); +/* + * Update amounts + */ + for (size_t i = 0 ; i < temp_gas_phase.Get_gas_comps().size(); i++) + { + cxxGasComp * gc_ptr = &(temp_gas_phase.Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); + assert(phase_ptr); + gc_ptr->Set_moles(phase_ptr->moles_x); + } + Rxn_gas_phase_map[n_user] = temp_gas_phase; + + use.Set_gas_phase_ptr(NULL); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xss_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save ss_assemblage composition into structure ss_assemblage with user + * number n_user. + */ + int i, j, n; + int count_comps, count_s_s; + struct ss_assemblage temp_ss_assemblage, *ss_assemblage_ptr; + char token[MAX_LENGTH]; + + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); +/* + * Set ss_assemblage + */ + temp_ss_assemblage.n_user = n_user; + temp_ss_assemblage.n_user_end = n_user; + sprintf(token, "Solid solution assemblage after simulation %d.", + simulation); + temp_ss_assemblage.description = string_duplicate(token); + temp_ss_assemblage.new_def = FALSE; + count_s_s = use.Get_ss_assemblage_ptr()->count_s_s; + temp_ss_assemblage.count_s_s = count_s_s; +/* + * Malloc space for solid solutions + */ + /* ss_assemblage->s_s */ + temp_ss_assemblage.s_s = + (struct s_s *) PHRQ_malloc((size_t) count_s_s * sizeof(struct s_s)); + if (temp_ss_assemblage.s_s == NULL) + malloc_error(); + for (i = 0; i < count_s_s; i++) + { + memcpy(&(temp_ss_assemblage.s_s[i]), + &(use.Get_ss_assemblage_ptr()->s_s[i]), sizeof(struct s_s)); + /* + * Malloc space for solid soution components + */ + count_comps = use.Get_ss_assemblage_ptr()->s_s[i].count_comps; + temp_ss_assemblage.s_s[i].comps = + (struct s_s_comp *) PHRQ_malloc((size_t) count_comps * + sizeof(struct s_s_comp)); + if (temp_ss_assemblage.s_s[i].comps == NULL) + malloc_error(); + memcpy((void *) temp_ss_assemblage.s_s[i].comps, + (void *) use.Get_ss_assemblage_ptr()->s_s[i].comps, + (size_t) count_comps * sizeof(struct s_s_comp)); + + /* set initial moles for quick setup */ + for (j = 0; j < count_comps; j++) + { + temp_ss_assemblage.s_s[i].comps[j].initial_moles = + temp_ss_assemblage.s_s[i].comps[j].moles; + } + } +/* + * Finish up + */ + ss_assemblage_ptr = ss_assemblage_bsearch(n_user, &n); + if (ss_assemblage_ptr == NULL) + { + space((void **) ((void *) &ss_assemblage), count_ss_assemblage, + &max_ss_assemblage, sizeof(struct ss_assemblage)); + n = count_ss_assemblage++; + } + else + { + ss_assemblage_free(&ss_assemblage[n]); + } + memcpy(&ss_assemblage[n], &temp_ss_assemblage, + sizeof(struct ss_assemblage)); + /* sort only if necessary */ + if (n == count_ss_assemblage - 1 && count_ss_assemblage > 1) + { + if (ss_assemblage[n].n_user < ss_assemblage[n - 1].n_user) + { + qsort(ss_assemblage, + (size_t) count_ss_assemblage, + (size_t) sizeof(struct ss_assemblage), + ss_assemblage_compare); + } + } + use.Set_ss_assemblage_ptr(NULL); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xpp_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save pure_phase assemblage into instance of cxxPPassemblage with user + * number n_user. + */ + std::string token; + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); + + cxxPPassemblage temp_pp_assemblage(*pp_assemblage_ptr); + + temp_pp_assemblage.Set_n_user(n_user); + temp_pp_assemblage.Set_n_user_end(n_user); + std::ostringstream desc; + desc << "Pure-phase assemblage after simulation " << simulation << "."; + temp_pp_assemblage.Set_description(desc.str().c_str()); + temp_pp_assemblage.Set_new_def(false); +/* + * Update amounts + */ + for (int j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + cxxPPassemblageComp *comp = temp_pp_assemblage.Find(x[j]->pp_assemblage_comp_name); + comp->Set_moles(x[j]->moles); + comp->Set_delta(0.0); + } +/* + * Finish up + */ + + Rxn_pp_assemblage_map[n_user] = temp_pp_assemblage; + use.Set_pp_assemblage_ptr(NULL); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xpp_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save pure_phase assemblage into structure pp_assemblage with user + * number n_user. + */ + int count_comps, n, j, i; + struct pp_assemblage temp_pp_assemblage, *pp_assemblage_ptr; + char token[MAX_LENGTH]; + + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); +/* + * Count pure phases + */ + count_comps = use.Get_pp_assemblage_ptr()->count_comps; + + temp_pp_assemblage.n_user = n_user; + temp_pp_assemblage.n_user_end = n_user; + sprintf(token, "Pure-phase assemblage after simulation %d.", simulation); + temp_pp_assemblage.description = string_duplicate(token); + temp_pp_assemblage.new_def = FALSE; + temp_pp_assemblage.count_comps = count_comps; + temp_pp_assemblage.next_elt = + elt_list_dup(use.Get_pp_assemblage_ptr()->next_elt); +/* + * Malloc space and copy pure phase data + */ + temp_pp_assemblage.pure_phases = + (struct pure_phase *) PHRQ_malloc((size_t) count_comps * + sizeof(struct pure_phase)); + if (temp_pp_assemblage.pure_phases == NULL) + malloc_error(); + memcpy((void *) temp_pp_assemblage.pure_phases, + (void *) use.Get_pp_assemblage_ptr()->pure_phases, + (size_t) count_comps * sizeof(struct pure_phase)); +/* + * Update amounts + */ + i = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + temp_pp_assemblage.pure_phases[i].moles = x[j]->moles; + temp_pp_assemblage.pure_phases[i].delta = 0.0; + + /* update unknown ptr, old may be freed later */ + x[j]->pure_phase = &(temp_pp_assemblage.pure_phases[i]); + i++; + } +/* + * Finish up + */ + pp_assemblage_ptr = pp_assemblage_bsearch(n_user, &n); + if (pp_assemblage_ptr == NULL) + { + space((void **) ((void *) &pp_assemblage), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage)); + n = count_pp_assemblage++; + } + else + { + pp_assemblage_free(&pp_assemblage[n]); + } + memcpy(&pp_assemblage[n], &temp_pp_assemblage, + sizeof(struct pp_assemblage)); + /* sort only if necessary */ + if (n == count_pp_assemblage - 1 && count_pp_assemblage > 1) + { + if (pp_assemblage[n].n_user < pp_assemblage[n - 1].n_user) + { + qsort(pp_assemblage, + (size_t) count_pp_assemblage, + (size_t) sizeof(struct pp_assemblage), + pp_assemblage_compare); + } + } + use.Get_pp_assemblage_ptr() = NULL; + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xsolution_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save solution composition into structure solution with user number + * n_user. + * + * input: n_user is user solution number of target + */ + int i, j, n; + int count_mass_balance, count_master_activity; + int max_mass_balance, max_master_activity; + struct solution *solution_ptr; + struct master *master_i_ptr, *master_ptr; +/* + * Malloc space for solution data + */ + solution_ptr = solution_alloc(); + + max_mass_balance = MAX_MASS_BALANCE; + max_master_activity = MAX_MASS_BALANCE; + + solution_ptr->n_user = n_user; + solution_ptr->n_user_end = n_user; + solution_ptr->new_def = FALSE; + solution_ptr->description = string_duplicate(description_x); + solution_ptr->tc = tc_x; + solution_ptr->patm = patm_x; + solution_ptr->ph = ph_x; + solution_ptr->solution_pe = solution_pe_x; + solution_ptr->mu = mu_x; + solution_ptr->ah2o = ah2o_x; + solution_ptr->density = density_x; + solution_ptr->total_h = total_h_x; + solution_ptr->total_o = total_o_x; + solution_ptr->cb = cb_x; /* cb_x does not include surface charge sfter sum_species */ + /* does include surface charge after step */ + + solution_ptr->mass_water = mass_water_aq_x; + solution_ptr->total_alkalinity = total_alkalinity; + /*solution_ptr->total_co2 = total_co2; */ + solution_ptr->units = moles_per_kilogram_string; +/* + * Copy pe data + */ + + pe_data_free(solution_ptr->pe); + /*solution_ptr->pe = pe_data_dup(pe_x); */ + solution_ptr->pe = pe_data_alloc(); + solution_ptr->default_pe = 0; + /* + * Add in minor isotopes if initial solution calculation + */ + if (initial_solution_isotopes == TRUE) + { + for (i = 0; i < count_master_isotope; i++) + { + if (master_isotope[i]->moles > 0) + { + master_i_ptr = master_bsearch(master_isotope[i]->name); + master_ptr = master_isotope[i]->elt->master; + if (master_isotope[i]->minor_isotope == TRUE) + { + master_i_ptr->total = master_isotope[i]->moles; + if (master_ptr->total > 0) + { + master_i_ptr->s->la = + master_ptr->s->la + + log10(master_i_ptr->total / master_ptr->total); + } + else + { + master_i_ptr->s->la = master_ptr->s->la; + } + } + else if (master_isotope[i]->minor_isotope == FALSE + && master_ptr->s != s_hplus + && master_ptr->s != s_h2o) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr->s->secondary->total = + master_isotope[i]->moles; + } + else + { + master_ptr->s->primary->total = + master_isotope[i]->moles; + } + } + } + } + } +/* + * Copy totals data + */ + count_mass_balance = 0; + count_master_activity = 0; + for (i = 0; i < count_master; i++) + { + if (master[i]->in == FALSE) + continue; + if (master[i]->s->type == EX || + master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + continue; + if (master[i]->s == s_hplus) + continue; + if (master[i]->s == s_h2o) + continue; +/* + * Save list of log activities + */ + if (master[i]->in != FALSE) + { + count_master_activity++; + } + } + solution_ptr->master_activity = + (struct master_activity *) PHRQ_realloc(solution_ptr-> + master_activity, + (size_t) + (count_master_activity + + 1) * + sizeof(struct + master_activity)); + solution_ptr->count_master_activity = count_master_activity; + count_master_activity = 0; + for (i = 0; i < count_master; i++) + { + if (master[i]->s->type == EX || + master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) + continue; + if (master[i]->s == s_hplus) + continue; + if (master[i]->s == s_h2o) + continue; +/* + * Save list of log activities + */ + if (master[i]->in != FALSE) + { + solution_ptr->master_activity[count_master_activity].description = + master[i]->elt->name; + solution_ptr->master_activity[count_master_activity++].la = + master[i]->s->la; + /* + if (count_master_activity + 2 >= max_master_activity) { + space ((void *) &(solution_ptr->master_activity), count_master_activity + 2, + &max_master_activity, sizeof (struct master_activity)); + } + */ + } + if (master[i]->total <= MIN_TOTAL) + { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + continue; + } +/* if (master[i]->total <= 0.0) continue; */ +/* + * Save list of concentrations + */ + solution_ptr->totals[count_mass_balance].description = + master[i]->elt->name; + solution_ptr->totals[count_mass_balance].input_conc = + master[i]->total; + solution_ptr->totals[count_mass_balance].moles = master[i]->total; + solution_ptr->totals[count_mass_balance].units = solution_ptr->units; + solution_ptr->totals[count_mass_balance].equation_name = NULL; + solution_ptr->totals[count_mass_balance].n_pe = 0; + solution_ptr->totals[count_mass_balance].phase = NULL; + solution_ptr->totals[count_mass_balance].phase_si = 0.0; + solution_ptr->totals[count_mass_balance].as = NULL; + solution_ptr->totals[count_mass_balance].gfw = master[i]->elt->primary->elt->gfw; + count_mass_balance++; +/* + * Make space + */ + if (count_mass_balance + 2 >= max_mass_balance) + { + space((void **) ((void *) &(solution_ptr->totals)), + count_mass_balance + 2, &max_mass_balance, + sizeof(struct conc)); + } + } + if (pitzer_model == TRUE || sit_model == TRUE) + { + i = 0; + for (j = 0; j < count_s; j++) + { + if (s[j]->lg != 0.0) + i++; + } + solution_ptr->species_gamma = + (struct master_activity *) PHRQ_realloc(solution_ptr-> + species_gamma, + (size_t) (i * + sizeof(struct + master_activity))); + i = 0; + for (j = 0; j < count_s; j++) + { + if (s[j]->lg != 0.0) + { + solution_ptr->species_gamma[i].la = s[j]->lg; + solution_ptr->species_gamma[i].description = s[j]->name; + i++; + } + } + solution_ptr->count_species_gamma = i; + } + else + { + solution_ptr->species_gamma = NULL; + solution_ptr->count_species_gamma = 0; + } +/* + * Mark end of totals + */ + solution_ptr->totals[count_mass_balance].description = NULL; + count_mass_balance++; + solution_ptr->master_activity[count_master_activity].description = NULL; + count_master_activity++; + solution_ptr->totals = + (struct conc *) PHRQ_realloc(solution_ptr->totals, + (size_t) count_mass_balance * + sizeof(struct conc)); + if (solution_ptr->totals == NULL) + malloc_error(); + solution_ptr->master_activity = + (struct master_activity *) PHRQ_realloc(solution_ptr-> + master_activity, + (size_t) + count_master_activity * + sizeof(struct + master_activity)); + if (solution_ptr->master_activity == NULL) + malloc_error(); + solution_ptr->count_master_activity = count_master_activity; +/* + * Save isotope data + */ + if (count_isotopes_x > 0) + { + solution_ptr->count_isotopes = count_isotopes_x; + solution_ptr->isotopes = + (struct isotope *) PHRQ_realloc(solution_ptr->isotopes, + (size_t) count_isotopes_x * + sizeof(struct isotope)); + if (solution_ptr->isotopes == NULL) + malloc_error(); + memcpy(solution_ptr->isotopes, isotopes_x, + (size_t) count_isotopes_x * sizeof(struct isotope)); + for (i = 0; i < count_isotopes_x; i++) + { + solution_ptr->isotopes[i].total = + solution_ptr->isotopes[i].master->total; + if (solution_ptr->isotopes[i].master == s_hplus->secondary) + { + solution_ptr->isotopes[i].total = + 2 * mass_water_aq_x / gfw_water; + } + if (solution_ptr->isotopes[i].master == s_h2o->secondary) + { + solution_ptr->isotopes[i].total = mass_water_aq_x / gfw_water; + } + } + } + else + { + solution_ptr->count_isotopes = 0; + solution_ptr->isotopes = + (struct isotope *) free_check_null(solution_ptr->isotopes); + solution_ptr->isotopes = NULL; + } +/* + * Save solution in solution + */ + if (solution_bsearch(n_user, &n, FALSE) != NULL) + { + solution_free(solution[n]); + } + else + { + n = count_solution++; + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } + } + solution[n] = solution_ptr; + /* sort only if necessary */ + if (count_solution > 1 + && (solution[count_solution - 1]->n_user < + solution[count_solution - 2]->n_user)) + { + solution_sort(); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xsurface_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save surface data into structure surface with user + * number n_user. + */ + int i, j, n, last_charge; + int count_comps, count_charge; + char token[MAX_LENGTH]; + struct surface temp_surface, *surface_ptr; + LDBLE charge; + if (use.Get_surface_ptr() == NULL) + return (OK); +/* + * Store data for structure surface + */ + memcpy(&temp_surface, use.Get_surface_ptr(), sizeof(struct surface)); + temp_surface.n_user = n_user; + temp_surface.n_user_end = n_user; + temp_surface.new_def = FALSE; + temp_surface.dl_type = dl_type_x; + sprintf(token, "Surface assemblage after simulation %d.", simulation); + temp_surface.description = string_duplicate(token); + temp_surface.solution_equilibria = FALSE; + temp_surface.n_solution = -10; +/* + * Allocate space to pointer comps + */ + + count_comps = use.Get_surface_ptr()->count_comps; + count_charge = use.Get_surface_ptr()->count_charge; + temp_surface.count_comps = count_comps; + temp_surface.comps = + (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * + sizeof(struct surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + /*if (temp_surface.edl == FALSE) { */ + if (temp_surface.type == NO_EDL) + { + temp_surface.charge = NULL; + temp_surface.count_charge = 0; + } + else + { + temp_surface.count_charge = count_charge; + temp_surface.charge = + (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * + sizeof(struct + surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + } +/* + * Write surface_comp structure for each surf component into comps_ptr + */ + count_comps = 0; + count_charge = 0; + /* + * Initial entry of surface sites is random + * Charge balance numbering follows the initial entry + * Surface sites are then sorted alphabetically + * Now when we save, the site order differs from the charge order + * last_charge sets up logic to renumber charge balance equations. + */ + last_charge = -1; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE) + { + memcpy(&temp_surface.comps[count_comps], x[i]->surface_comp, + sizeof(struct surface_comp)); + + temp_surface.comps[count_comps].master = x[i]->master[0]; + temp_surface.comps[count_comps].la = x[i]->master[0]->s->la; + /* temp_surface.comps[count_comps].formula = NULL; */ + temp_surface.comps[count_comps].moles = 0.; + if (x[i]->surface_comp->charge == last_charge) + { + temp_surface.comps[count_comps].charge = count_charge - 1; + } + else + { + temp_surface.comps[count_comps].charge = count_charge; + } + last_charge = x[i]->surface_comp->charge; +/* + * Save element concentrations on surface + */ + count_elts = 0; + paren_count = 0; + charge = 0.0; + for (j = 0; j < count_species_list; j++) + { + if (species_list[j].master_s == x[i]->master[0]->s) + { + add_elt_list(species_list[j].s->next_elt, + species_list[j].s->moles); + charge += species_list[j].s->moles * species_list[j].s->z; + } + } + temp_surface.comps[count_comps].totals = elt_list_save(); + temp_surface.comps[count_comps].formula_totals = + elt_list_dup(x[i]->surface_comp->formula_totals); + temp_surface.comps[count_comps].cb = charge; + + /* update unknown pointer */ + x[i]->surface_comp = &(temp_surface.comps[count_comps]); + count_comps++; + } + else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->type == DDL) + { + memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, + sizeof(struct surface_charge)); + temp_surface.charge[count_charge].charge_balance = x[i]->f; + temp_surface.charge[count_charge].mass_water = + x[i]->surface_charge->mass_water; + temp_surface.charge[count_charge].diffuse_layer_totals = NULL; + temp_surface.charge[count_charge].count_g = 0; + temp_surface.charge[count_charge].g = NULL; +/* + * Added code to save g + */ + + if (x[i]->surface_charge->count_g > + 0 /*&& use.Get_surface_ptr()->type != CD_MUSIC */ ) + { + temp_surface.charge[count_charge].count_g = + x[i]->surface_charge->count_g; + temp_surface.charge[count_charge].g = + (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]-> + surface_charge-> + count_g * + sizeof(struct + surface_diff_layer)); + if (temp_surface.charge[count_charge].g == NULL) + malloc_error(); + memcpy(temp_surface.charge[count_charge].g, + x[i]->surface_charge->g, + (size_t) x[i]->surface_charge->count_g * + sizeof(struct surface_diff_layer)); + } + + /*temp_surface.charge[count_charge].psi_master = x[i]->master[0]; */ + temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; +/* + * Store moles from diffuse_layer + */ + if (dl_type_x != NO_DL) + { + sum_diffuse_layer(x[i]->surface_charge); + temp_surface.charge[count_charge].diffuse_layer_totals = + elt_list_save(); + } + + /* update unknown pointer */ + x[i]->surface_charge = &(temp_surface.charge[count_charge]); + x[i]->surface_comp = x[i - 1]->surface_comp; + + count_charge++; + } + else if (x[i]->type == SURFACE_CB + && use.Get_surface_ptr()->type == CD_MUSIC) + { + memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, + sizeof(struct surface_charge)); + if (dl_type_x != NO_DL) + { + temp_surface.charge[count_charge].charge_balance = + (x[i]->surface_charge->sigma0 + + x[i]->surface_charge->sigma1 + + x[i]->surface_charge->sigma2 + + x[i]->surface_charge->sigmaddl) + * (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams) / F_C_MOL; + } + else + { + temp_surface.charge[count_charge].charge_balance = + (x[i]->surface_charge->sigma0 + + x[i]->surface_charge->sigma1 + + x[i]->surface_charge->sigma2) + * (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams) / F_C_MOL; + } + temp_surface.charge[count_charge].mass_water = + x[i]->surface_charge->mass_water; + temp_surface.charge[count_charge].diffuse_layer_totals = NULL; + temp_surface.charge[count_charge].count_g = 0; + temp_surface.charge[count_charge].g = NULL; +/* + * Added code to save g + */ + + if (x[i]->surface_charge->count_g > 0) + { + temp_surface.charge[count_charge].count_g = + x[i]->surface_charge->count_g; + temp_surface.charge[count_charge].g = + (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]-> + surface_charge-> + count_g * + sizeof(struct + surface_diff_layer)); + if (temp_surface.charge[count_charge].g == NULL) + malloc_error(); + memcpy(temp_surface.charge[count_charge].g, + x[i]->surface_charge->g, + (size_t) x[i]->surface_charge->count_g * + sizeof(struct surface_diff_layer)); + } + + /*temp_surface.charge[count_charge].psi_master = x[i]->master[0]; */ + temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; +/* + * Store moles from diffuse_layer + */ + if (dl_type_x != NO_DL) + { + sum_diffuse_layer(x[i]->surface_charge); + temp_surface.charge[count_charge].diffuse_layer_totals = + elt_list_save(); + } + + /* update unknown pointer */ + x[i]->surface_charge = &(temp_surface.charge[count_charge]); + x[i]->surface_comp = x[i - 1]->surface_comp; + + count_charge++; + } + } +/* + * Finish up + */ + surface_ptr = surface_bsearch(n_user, &n); + if (surface_ptr == NULL) + { + n = count_surface++; + space((void **) ((void *) &surface), count_surface, &max_surface, + sizeof(struct surface)); + } + else + { + surface_free(&surface[n]); + } + memcpy(&surface[n], &temp_surface, sizeof(struct surface)); + if (n == count_surface - 1 && count_surface > 1) + { + if (surface[n].n_user < surface[n - 1].n_user) + { + qsort(surface, + (size_t) count_surface, + (size_t) sizeof(struct surface), surface_compare); + } + } + use.Set_surface_ptr(NULL); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_use(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find mixture + */ + if (use.Get_mix_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_mix_map, use.Get_n_mix_user(), i); + } +/* + * Find solution + */ + if (use.Get_solution_in() == TRUE) + { + solution_duplicate(use.Get_n_solution_user(), i); + } +/* + * Always save solution to i, mixing or not + */ + save.solution = TRUE; + save.n_solution_user = i; + save.n_solution_user_end = i; +/* + * Find pure phase assemblage + */ + if (use.Get_pp_assemblage_in() == TRUE) + { + //pp_assemblage_duplicate(use.Get_n_pp_assemblage_user(), i); + Utilities::Rxn_copy(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user(), i); + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + } + else + { + save.pp_assemblage = FALSE; + } +/* + * Find irrev reaction + */ + if (use.Get_reaction_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_reaction_map, use.Get_n_reaction_user(), i); + save.reaction = TRUE; + save.n_reaction_user = i; + save.n_reaction_user_end = i; + } + else + { + save.reaction = FALSE; + } +/* + * Find exchange + */ + if (use.Get_exchange_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_exchange_map, use.Get_n_exchange_user(), i); + save.exchange = TRUE; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + } + else + { + save.exchange = FALSE; + } +/* + * Find kinetics + */ + if (use.Get_kinetics_in() == TRUE) + { + kinetics_duplicate(use.Get_n_kinetics_user(), i); + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } + else + { + save.kinetics = FALSE; + } +/* + * Find surface + */ + dl_type_x = NO_DL; + if (use.Get_surface_in() == TRUE) + { + surface_duplicate(use.Get_n_surface_user(), i); + save.surface = TRUE; + save.n_surface_user = i; + save.n_surface_user_end = i; + } + else + { + save.surface = FALSE; + } +/* + * Find temperature + */ + if (use.Get_temperature_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_temperature_map, use.Get_n_temperature_user(), i); + } +/* + * Find pressure + */ + if (use.Get_pressure_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_pressure_map, use.Get_n_pressure_user(), i); + } +/* + * Find gas + */ + if (use.Get_gas_phase_in() == TRUE) + { + //gas_phase_duplicate(use.Get_n_gas_phase_user(), i); + Utilities::Rxn_copy(Rxn_gas_phase_map, use.Get_n_gas_phase_user(), i); + save.gas_phase = TRUE; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + } + else + { + save.gas_phase = FALSE; + } +/* + * Find solid solution + */ + if (use.Get_ss_assemblage_in() == TRUE) + { + ss_assemblage_duplicate(use.Get_n_ss_assemblage_user(), i); + save.ss_assemblage = TRUE; + save.n_ss_assemblage_user = i; + save.n_ss_assemblage_user_end = i; + } + else + { + save.ss_assemblage = FALSE; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +step_save_exch(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save exchange composition + * + * input: n_user is user exchange number of target + */ + //int i; + bool found; + + if (use.Get_exchange_ptr() == NULL) + return (OK); + + cxxExchange *temp_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); + assert(temp_ptr); + + // Set all totals to 0.0 + cxxExchange temp_exchange = *temp_ptr; + { + std::map::iterator it = temp_exchange.Get_exchComps().begin(); + for ( ; it != temp_exchange.Get_exchComps().end(); it++) + { + it->second.Get_totals().multiply(0.0); + } + } + + // Set exchange total in one component + for (int i = 0; i < count_master; i++) + { + if (master[i]->s->type != EX) + continue; + found = false; + std::string e(master[i]->elt->name); + std::map::iterator it = temp_exchange.Get_exchComps().begin(); + for ( ; it != temp_exchange.Get_exchComps().end(); it++) + { + cxxNameDouble *nd = &(it->second.Get_totals()); + cxxNameDouble::iterator nd_it = nd->find(e); + if (nd_it != nd->end()) + { + LDBLE coef; + if (master[i]->total <= MIN_TOTAL) + { + coef = MIN_TOTAL; + } + else + { + coef = master[i]->total; + } + nd->insert(nd_it->first.c_str(), coef); + break; + } + } + } + + Rxn_exchange_map[n_user] = temp_exchange; + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +step_save_exch(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save exchange composition + * + * input: n_user is user exchange number of target + */ + //int i; + bool found; + + if (use.Get_exchange_ptr() == NULL) + return (OK); + //exchange_duplicate(use.Get_exchange_ptr()->n_user, n_user); + //exchange_ptr = exchange_bsearch(n_user, &n); + cxxExchange *temp_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); + assert(temp_ptr); + cxxExchange temp_exchange = *temp_ptr; + + for (int i = 0; i < count_master; i++) + { + if (master[i]->s->type != EX) + continue; + found = false; + std::string e(master[i]->elt->name); + std::map::iterator it = temp_exchange.Get_exchComps().begin(); + for ( ; it != temp_exchange.Get_exchComps().end(); it++) + { + cxxNameDouble nd = it->second.Get_totals(); + nd.multiply(0.0); + cxxNameDouble::iterator nd_it =nd.find(e); + if ((!found) && nd_it != nd.end()) + { + found = true; + LDBLE coef; + if (master[i]->total <= MIN_TOTAL) + { + coef = MIN_TOTAL; + } + else + { + coef = master[i]->total; + } + nd[nd_it->first.c_str()] = coef; + } + it->second.Set_totals(nd); + } + } + + Rxn_exchange_map[n_user] = temp_exchange; + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +step_save_surf(int n_user) +/* ---------------------------------------------------------------------- */ +{ + /* + * Save surface for intermediate calculation + * Amt of surface may have changed due to reaction or surface related + * to kinetic reactant. + * + * input: n_user is user solution number of target + */ + int i, j, k, n, m; + struct surface *surface_ptr; + /* + * Malloc space for solution data + */ + if (use.Get_surface_ptr() == NULL) + return (OK); + surface_duplicate(use.Get_surface_ptr()->n_user, n_user); + surface_ptr = surface_bsearch(n_user, &n); + for (i = 0; i < count_master; i++) + { + if (master[i]->s->type != SURF) + continue; + for (j = 0; j < surface_ptr->count_comps; j++) + { + for (k = 0; surface_ptr->comps[j].totals[k].elt != NULL; k++) + { + if (surface_ptr->comps[j].totals[k].elt == master[i]->elt) + { + if (master[i]->total <= MIN_TOTAL) + { + surface_ptr->comps[j].totals[k].coef = MIN_TOTAL; + } + else + { + surface_ptr->comps[j].totals[k].coef = + master[i]->total; + } + break; + } + } + } + } + /* + * Update grams + */ + /*if (surface_ptr->edl == TRUE && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) { */ + if ((surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) + { + for (j = 0; j < surface_ptr->count_comps; j++) + { + if (surface_ptr->comps[j].rate_name != NULL) + { + for (m = 0; m < use.Get_kinetics_ptr()->count_comps; m++) + { + if (strcmp_nocase + (use.Get_kinetics_ptr()->comps[m].rate_name, + surface_ptr->comps[j].rate_name) != 0) + continue; + surface_ptr->charge[surface_ptr->comps[j].charge].grams = + use.Get_kinetics_ptr()->comps[m].m; + break; + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_entities(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, n, return_value; + int verbose; + + verbose = FALSE; + return_value = OK; + if (copy_solution.count > 0) + { + for (j = 0; j < copy_solution.count; j++) + { + if (solution_bsearch(copy_solution.n_user[j], &n, FALSE) != NULL) + { + for (i = copy_solution.start[j]; i <= copy_solution.end[j]; + i++) + { + if (i == copy_solution.n_user[j]) + continue; + solution_duplicate(copy_solution.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("SOLUTION to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_pp_assemblage.count > 0) + { + for (j = 0; j < copy_pp_assemblage.count; j++) + { + //if (pp_assemblage_bsearch(copy_pp_assemblage.n_user[j], &n) != NULL) + if (Utilities::Rxn_find(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j]) != NULL) + { + for (i = copy_pp_assemblage.start[j]; + i <= copy_pp_assemblage.end[j]; i++) + { + if (i == copy_pp_assemblage.n_user[j]) + continue; + //pp_assemblage_duplicate(copy_pp_assemblage.n_user[j], i); + Utilities::Rxn_copy(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("EQUILIBRIUM_PHASES to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_reaction.count > 0) + { + for (j = 0; j < copy_reaction.count; j++) + { + //if (irrev_bsearch(copy_irrev.n_user[j], &n) != NULL) + if (Utilities::Rxn_find(Rxn_reaction_map, copy_reaction.n_user[j]) != NULL) + { + for (i = copy_reaction.start[j]; i <= copy_reaction.end[j]; i++) + { + if (i == copy_reaction.n_user[j]) + continue; + //irrev_duplicate(copy_irrev.n_user[j], i); + Utilities::Rxn_copy(Rxn_reaction_map, copy_reaction.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("REACTION to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_mix.count > 0) + { + for (j = 0; j < copy_mix.count; j++) + { + if (Utilities::Rxn_find(Rxn_mix_map, copy_mix.n_user[j]) != NULL) + { + for (i = copy_mix.start[j]; i <= copy_mix.end[j]; i++) + { + if (i != copy_mix.n_user[j]) + { + Utilities::Rxn_copy(Rxn_mix_map, copy_mix.n_user[j], i); + } + } + } + else + { + if (verbose == TRUE) + { + warning_msg("Mix to copy not found."); + return_value = ERROR; + } + } + } + } + + if (copy_exchange.count > 0) + { + for (j = 0; j < copy_exchange.count; j++) + { + if (Utilities::Rxn_find(Rxn_exchange_map, copy_exchange.n_user[j]) != NULL) + { + for (i = copy_exchange.start[j]; i <= copy_exchange.end[j]; + i++) + { + if (i == copy_exchange.n_user[j]) + continue; + Utilities::Rxn_copy(Rxn_exchange_map, copy_exchange.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("EXCHANGE to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_surface.count > 0) + { + for (j = 0; j < copy_surface.count; j++) + { + if (surface_bsearch(copy_surface.n_user[j], &n) != NULL) + { + for (i = copy_surface.start[j]; i <= copy_surface.end[j]; i++) + { + if (i == copy_surface.n_user[j]) + continue; + surface_duplicate(copy_surface.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("SURFACE to copy not found."); + return_value = ERROR; + } + } + } + } + + if (copy_temperature.count > 0) + { + for (j = 0; j < copy_temperature.count; j++) + { + if (Utilities::Rxn_find(Rxn_temperature_map, copy_temperature.n_user[j]) != NULL) + { + for (i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++) + { + if (i != copy_temperature.n_user[j]) + { + Utilities::Rxn_copy(Rxn_temperature_map, copy_temperature.n_user[j], i); + } + } + } + else + { + if (verbose == TRUE) + { + warning_msg("temperature to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_pressure.count > 0) + { + for (j = 0; j < copy_pressure.count; j++) + { + if (Utilities::Rxn_find(Rxn_pressure_map, copy_pressure.n_user[j]) != NULL) + { + for (i = copy_pressure.start[j]; i <= copy_pressure.end[j]; i++) + { + if (i != copy_pressure.n_user[j]) + { + Utilities::Rxn_copy(Rxn_pressure_map, copy_pressure.n_user[j], i); + } + } + } + else + { + if (verbose == TRUE) + { + warning_msg("pressure to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_gas_phase.count > 0) + { + for (j = 0; j < copy_gas_phase.count; j++) + { + if (Utilities::Rxn_find(Rxn_gas_phase_map, copy_gas_phase.n_user[j]) != NULL) + { + for (i = copy_gas_phase.start[j]; i <= copy_gas_phase.end[j]; + i++) + { + if (i == copy_gas_phase.n_user[j]) + continue; + Utilities::Rxn_copy(Rxn_gas_phase_map, copy_gas_phase.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("EXCHANGE to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_kinetics.count > 0) + { + for (j = 0; j < copy_kinetics.count; j++) + { + if (kinetics_bsearch(copy_kinetics.n_user[j], &n) != NULL) + { + for (i = copy_kinetics.start[j]; i <= copy_kinetics.end[j]; + i++) + { + if (i == copy_kinetics.n_user[j]) + continue; + kinetics_duplicate(copy_kinetics.n_user[j], i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("KINETICS to copy not found."); + return_value = ERROR; + } + } + } + } + if (copy_ss_assemblage.count > 0) + { + for (j = 0; j < copy_ss_assemblage.count; j++) + { + if (ss_assemblage_bsearch(copy_ss_assemblage.n_user[j], &n) != + NULL) + { + for (i = copy_ss_assemblage.start[j]; + i <= copy_ss_assemblage.end[j]; i++) + { + if (i == copy_ss_assemblage.n_user[j]) + continue; + ss_assemblage_duplicate(copy_ss_assemblage.n_user[j], + i); + } + } + else + { + if (verbose == TRUE) + { + warning_msg("SOLID_SOLUTIONS to copy not found."); + return_value = ERROR; + } + } + } + } + copy_solution.count = 0; + copy_pp_assemblage.count = 0; + copy_exchange.count = 0; + copy_surface.count = 0; + copy_ss_assemblage.count = 0; + copy_gas_phase.count = 0; + copy_kinetics.count = 0; + copy_mix.count = 0; + copy_reaction.count = 0; + copy_temperature.count = 0; + copy_pressure.count = 0; + new_copy = FALSE; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_database(void) +/* ---------------------------------------------------------------------- */ +{ + simulation = 0; + +/* + * Prepare error handling + */ + try + { + set_reading_database(TRUE); + dup_print("Reading data base.", TRUE); + read_input(); + tidy_model(); + status(0, NULL); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + set_reading_database(FALSE); + return 0; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +run_simulations(void) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH]; +#ifdef SKIP +#if defined(WIN32) + unsigned int old_exponent_format; + old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); +#endif +#endif +/* + * Prepare error handling + */ + try + { +/* + * Read input data for simulation + */ + for (simulation = 1;; simulation++) + { + +#if defined PHREEQ98 + AddSeries = !connect_simulations; +#endif + sprintf(token, "Reading input data for simulation %d.", simulation); + + dup_print(token, TRUE); + if (read_input() == EOF) + break; + + if (title_x != NULL) + { + sprintf(token, "TITLE"); + dup_print(token, TRUE); + if (pr.headings == TRUE) + output_msg(sformatf( "%s\n\n", title_x)); + } + tidy_model(); +#ifdef PHREEQ98 + if (!phreeq98_debug) + { +#endif + +/* + * Calculate distribution of species for initial solutions + */ + if (new_solution) + initial_solutions(TRUE); +/* + * Calculate distribution for exchangers + */ + if (new_exchange) + initial_exchangers(TRUE); +/* + * Calculate distribution for surfaces + */ + if (new_surface) + initial_surfaces(TRUE); +/* + * Calculate initial gas composition + */ + if (new_gas_phase) + initial_gas_phases(TRUE); +/* + * Calculate reactions + */ + reactions(); +/* + * Calculate inverse models + */ + inverse_models(); +/* + * Calculate advection + */ + if (use.Get_advect_in()) + { + dup_print("Beginning of advection calculations.", TRUE); + advection(); + } +/* + * Calculate transport + */ + if (use.Get_trans_in()) + { + dup_print("Beginning of transport calculations.", TRUE); + transport(); + } +/* + * run + */ + run_as_cells(); +/* + * Copy + */ + if (new_copy) copy_entities(); +/* + * dump + */ + dump_entities(); +/* + * delete + */ + delete_entities(); +/* + * End of simulation + */ + dup_print("End of simulation.", TRUE); +#ifdef PHREEQ98 + } /* if (!phreeq98_debug) */ +#endif + } + + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +do_initialize(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prepare error handling + */ + try { + + state = INITIALIZE; + + initialize(); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +do_status(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prepare error handling + */ + try { + + if (pr.status == TRUE) + { +#if defined(PHREEQCI_GUI) + state = -1; + status(0, "\r\nDone."); +#else + status(0, "\nDone."); +#endif + screen_msg("\n"); + } + dup_print("End of run.", TRUE); + screen_msg("\nEnd of Run.\n"); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} +void Phreeqc:: +save_init(int i) +{ + save.solution = i; + save.n_solution_user = i; + save.n_solution_user_end = i; + save.mix = i; + save.n_mix_user = i; + save.n_mix_user_end = i; + save.reaction = i; + save.n_reaction_user = i; + save.n_reaction_user_end = i; + save.pp_assemblage = i; + save.n_pp_assemblage_user = i; + save.n_pp_assemblage_user_end = i; + save.exchange = i; + save.n_exchange_user = i; + save.n_exchange_user_end = i; + save.kinetics = i; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + save.surface = i; + save.n_surface_user = i; + save.n_surface_user_end = i; + save.gas_phase = i; + save.n_gas_phase_user = i; + save.n_gas_phase_user_end = i; + save.ss_assemblage = i; + save.n_ss_assemblage_user = i; + save.n_ss_assemblage_user_end = i; +} +#ifdef SKIP +void Phreeqc:: +use_init(void) +{ + use.Get_solution_in() = FALSE; + use.Get_n_solution_user()= -1; + use.Get_n_solution()= -1; + use.Get_solution_ptr() = NULL; + + use.Get_pp_assemblage_in() = FALSE; + use.Get_n_pp_assemblage_user()= -1; + //use.n_pp_assemblage= -1; + use.Get_pp_assemblage_ptr() = NULL; + + use.Get_mix_in() = FALSE; + use.Get_n_mix_user()= -1; + //use.n_mix= -1; + use.Get_mix_ptr() = NULL; + use.Get_n_mix_user_orig()= -1; + + use.Get_reaction_in() = FALSE; + use.Get_n_reaction_user()= -1; + //use.n_irrev= -1; + use.Get_reaction_ptr() = NULL; + + use.Get_exchange_in() = FALSE; + use.Get_n_exchange_user()= -1; + //use.n_exchange= -1; + use.Get_exchange_ptr() = NULL; + + use.Get_kinetics_in() = FALSE; + use.Get_n_kinetics_user()= -1; + use.n_kinetics= -1; + use.Get_kinetics_ptr() = NULL; + + use.Get_surface_in() = FALSE; + use.Get_n_surface_user()= -1; + use.n_surface= -1; + use.Get_surface_ptr() = NULL; + + use.Get_temperature_in() = FALSE; + use.Get_n_temperature_user()= -1; + use.Get_temperature_ptr() = NULL; + + use.Get_pressure_in() = FALSE; + use.Get_n_pressure_user()= -1; + use.Get_pressure_ptr() = NULL; + + use.Get_inverse_in() = FALSE; + use.Get_n_inverse_user()= -1; + use.n_inverse= -1; + use.Get_inverse_ptr() = NULL; + + use.Get_gas_phase_in() = FALSE; + use.Get_n_gas_phase_user()= -1; + //use.n_gas_phase= -1; + use.Get_gas_phase_ptr() = NULL; + + use.Get_ss_assemblage_in() = FALSE; + use.Get_n_ss_assemblage_user()= -1; + use.n_ss_assemblage= -1; + use.Get_ss_assemblage_ptr() = NULL; + + use.trans_in = FALSE; + use.advect_in = FALSE; +} +#endif \ No newline at end of file diff --git a/rename_cpp/model.cpp b/rename_cpp/model.cpp new file mode 100644 index 00000000..2dceb7fd --- /dev/null +++ b/rename_cpp/model.cpp @@ -0,0 +1,5576 @@ +#include "Phreeqc.h" +#include "phqalloc.h" +#include "cxxMix.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * model is called after the equations have been set up by prep + * and initial guesses have been made in set. + * + * Here is the outline of the calculation sequence: + * residuals--residuals are calculated, if small we are done + * sum_jacobian--jacobian is calculated + * ineq--inequality solver is called + * reset--estimates of unknowns revised, if changes are small solution + * has been found, usually convergence is found in residuals. + * gammas--new activity coefficients + * molalities--calculate molalities + * mb_sums--calculate mass-balance sums + * mb_gases--decide if gas_phase exists + * mb_s_s--decide if solid_solutions exists + * switch_bases--check to see if new basis species is needed + * reprep--rewrite equations with new basis species if needed + * revise_guesses--revise unknowns to get initial mole balance + * check_residuals--check convergence one last time + * sum_species--calculate sums of elements from species concentrations + * + * An additional pass through may be needed if unstable phases still exist + * in the phase assemblage. + */ + int l_kode, return_kode; + int r; + int count_infeasible, count_basis_change; + int debug_model_save; + int mass_water_switch_save; + + set_inert_moles(); +/* debug_model = TRUE; */ +/* debug_prep = TRUE; */ +/* debug_set = TRUE; */ + /* mass_water_switch == TRUE, mass of water is constant */ + if (pitzer_model == TRUE && sit_model == TRUE) + { + input_error++; + error_msg("Cannot use PITZER and SIT data blocks in same run (database + input file).", STOP); + } + if (pitzer_model == TRUE) + { + + l_kode = model_pz(); + unset_inert_moles(); + return l_kode; + } + if (sit_model == TRUE) + { + + l_kode = model_sit(); + unset_inert_moles(); + return l_kode; + } + mass_water_switch_save = mass_water_switch; + if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) + { + mass_water_switch = TRUE; + } + debug_model_save = debug_model; + pe_step_size_now = pe_step_size; + step_size_now = step_size; + if (!use.Get_kinetics_in()) status(0, NULL); + iterations = 0; + count_basis_change = count_infeasible = 0; + stop_program = FALSE; + remove_unstable_phases = FALSE; + for (;;) + { + mb_gases(); + mb_s_s(); + l_kode = 1; + while ((r = residuals()) != CONVERGED + || remove_unstable_phases == TRUE) + { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == + WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + iterations++; + if (iterations > itmax - 1 && debug_model == FALSE + && pr.logfile == TRUE) + { + set_forward_output_to_log(TRUE); + debug_model = TRUE; + } + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nIteration %d\tStep_size = %f\n", iterations, + (double) step_size_now)); + output_msg(sformatf( "\t\tPe_step_size = %f\n\n", + (double) pe_step_size_now)); + } +/* + * Iterations exceeded + */ + if (iterations > itmax) + { + error_string = sformatf( "Maximum iterations exceeded, %d\n", + itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } +/* + * Calculate jacobian + */ + if (state >= REACTION && numerical_deriv) + { + //jacobian_sums(); + numerical_jacobian(); + } + else /* hmm */ + { + jacobian_sums(); + numerical_jacobian(); + } +/* + * Full matrix with pure phases + */ + if (r == OK || remove_unstable_phases == TRUE) + { + return_kode = ineq(l_kode); + if (return_kode != OK) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + } + log_msg(sformatf("Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + count_infeasible++; + } + if (return_kode == 2) + { + ineq(0); + } + reset(); + } + gammas(mu_x); + if (molalities(FALSE) == ERROR) + { + revise_guesses(); +/* adjust_step_size(); */ + } + if (use.Get_surface_ptr() != NULL && + use.Get_surface_ptr()->dl_type != NO_DL && + use.Get_surface_ptr()->related_phases == TRUE) + initial_surface_water(); + mb_sums(); + mb_gases(); + mb_s_s(); +/* + * Switch bases if necessary + */ + + if (switch_bases() == TRUE) + { + count_basis_change++; + reprep(); + gammas(mu_x); + molalities(TRUE); + if (use.Get_surface_ptr() != NULL && + use.Get_surface_ptr()->dl_type != NO_DL && + use.Get_surface_ptr()->related_phases == TRUE) + initial_surface_water(); + revise_guesses(); + mb_sums(); + mb_gases(); + mb_s_s(); + } +/* debug + species_list_sort(); + sum_species(); + print_species(); + print_exchange(); + print_surface(); + */ + if (stop_program == TRUE) + { + break; + } + } +/* + * Check for stop_program + */ + + if (stop_program == TRUE) + { + break; + } + if (check_residuals() == ERROR) + { + stop_program = TRUE; + break; + } + if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE + && mass_water_switch == TRUE) + { + log_msg(sformatf( + "\nChanging water switch to FALSE. Iteration %d.\n", + iterations)); + mass_water_switch = FALSE; + continue; + } + if (remove_unstable_phases == FALSE) + break; + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nNumber of infeasible solutions: %d\n", + count_infeasible)); + log_msg(sformatf( "Number of basis changes: %d\n\n", + count_basis_change)); + log_msg(sformatf( "Number of iterations: %d\n\n", iterations)); + debug_model = debug_model_save; + set_forward_output_to_log(FALSE); + unset_inert_moles(); + if (stop_program == TRUE) + { + return (ERROR); + } + return (OK); +} + +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +adjust_step_size(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Step sizes are cut down if overflow occurs in molalities + */ + pe_step_size_now -= (pe_step_size_now - 1.0) / 2.0; + step_size_now -= (step_size_now - 1.) / 2.0; + if (pe_step_size_now < 1.5) + pe_step_size_now = 1.5; + if (step_size_now < 1.5) + step_size_now = 1.5; + log_msg(sformatf( "\tNew step sizes: %f\t%f\t%d\n", + step_size_now, pe_step_size_now, iterations)); + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_residuals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks for convergence of all equations, prints any nonconvergence + * Sets variable remove_unstable_phases if a phase is present, + * but undersaturated (i.e. aragonite in calcite-saturated solution). + */ + int i, return_value; + LDBLE epsilon; + epsilon = convergence_tolerance; + + return_value = OK; + if (stop_program == TRUE) + { + warning_msg + ("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:"); + /*error_msg("The program has failed to converge to a numerical solution.\n\nThe following equations were not satisfied:", CONTINUE); */ + } + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB || x[i]->type == ALK) + { + if (fabs(residual[i]) >= epsilon * x[i]->moles + && x[i]->moles > MIN_TOTAL /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s has not converged. Total: %e\tCalculated: " + "%e\tResidual: %e\n", x[i]->description, + (double) x[i]->moles, (double) x[i]->f, + (double) residual[i]); + error_msg(error_string, CONTINUE); + if (x[i]->type == ALK) + { + error_msg("Is non-carbonate alkalinity " + "greater than total alkalinity?\n", CONTINUE); + } + return_value = ERROR; + } + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + if (fabs(residual[i]) >= epsilon /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s solution phase boundary has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == CB) + { + if (fabs(residual[i]) >= + epsilon * mu_x * + mass_water_aq_x /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Charge balance has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == MU && pitzer_model == FALSE && sit_model == FALSE) + { + if (fabs(residual[i]) >= + epsilon * mu_x * + mass_water_aq_x /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Ionic strength has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == AH2O && pitzer_model == FALSE && sit_model == FALSE) + { + if (fabs(residual[i]) >= epsilon /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Activity of water has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if ((x[i]->type == MH + && (pitzer_model == FALSE || pitzer_pe == TRUE))) + { +#define COMBINE + /*#define COMBINE_CHARGE */ +#ifdef COMBINE +#ifndef COMBINE_CHARGE + if (fabs(residual[i]) > + epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles)) +#else + if (fabs(residual[i]) > + epsilon * (x[i]->moles + 2 * mass_oxygen_unknown->moles + + charge_balance_unknown->moles)) +#endif +#else + if (fabs(residual[i]) >= + epsilon * x[i]->moles /* || stop_program == TRUE */ ) +#endif + { + error_string = sformatf( + "%20s Mass of hydrogen has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == MH2O) + { + if (mass_water_switch == TRUE) + continue; + if (fabs(residual[i]) >= + 0.01 * epsilon * x[i]->moles /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Mass of oxygen has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == PP) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + if (comp_ptr->Get_add_formula().size() == 0) + //if (x[i]->pure_phase->add_formula == NULL) + { + if (x[i]->dissolve_only == TRUE) + { + if ((residual[i] > epsilon && x[i]->moles > 0.0) + || + ((residual[i] < -epsilon + && (comp_ptr->Get_initial_moles() - x[i]->moles) > + 0))) + { + log_msg(sformatf( + "%20s Dissolve_only pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + } + } + else + { + if ((residual[i] >= epsilon + && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) + { + remove_unstable_phases = TRUE; + log_msg(sformatf( + "%20s Pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + } + else if (residual[i] <= -epsilon) + { + error_string = sformatf( + "%20s Pure phase has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + } + else + { + if ((fabs(residual[i]) >= epsilon + && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) + { + log_msg(sformatf( + "%s, Pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + error_string = sformatf( + "%s, Pure phase with add formula has not converged.\n\t SI may be a local minimum." + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + warning_msg(error_string); + } + } + } +#ifdef SKIP + else if (x[i]->type == PP) + { + if (x[i]->pure_phase->add_formula == NULL) + { + if (x[i]->dissolve_only == TRUE) + { + if ((residual[i] > epsilon && x[i]->moles > 0.0) + || + ((residual[i] < -epsilon + && (x[i]->pure_phase->initial_moles - x[i]->moles) > + 0))) + { + log_msg(sformatf( + "%20s Dissolve_only pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + } + } + else + { + if ((residual[i] >= epsilon + && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) + { + remove_unstable_phases = TRUE; + log_msg(sformatf( + "%20s Pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + } + else if (residual[i] <= -epsilon) + { + error_string = sformatf( + "%20s Pure phase has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + } + else + { + if ((fabs(residual[i]) >= epsilon + && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) + { + log_msg(sformatf( + "%s, Pure phase has not converged. \tResidual: %e\n", + x[i]->description, (double) residual[i])); + error_string = sformatf( + "%s, Pure phase with add formula has not converged.\n\t SI may be a local minimum." + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + warning_msg(error_string); + } + } + } +#endif + else if (x[i]->type == EXCH) + { + if ( /* stop_program == TRUE || */ + (x[i]->moles <= MIN_RELATED_SURFACE + && fabs(residual[i]) > epsilon) + || (x[i]->moles > MIN_RELATED_SURFACE + && (fabs(residual[i]) > epsilon * x[i]->moles))) + { + error_string = sformatf( + "%20s Exchanger mass balance has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == SURFACE) + { + if (fabs(residual[i]) < ineq_tol && fabs(residual[i]) < 1e-2*x[i]->moles) continue; + if ( /* stop_program == TRUE || */ + (x[i]->moles <= MIN_RELATED_SURFACE + && fabs(residual[i]) > epsilon) + || (x[i]->moles > MIN_RELATED_SURFACE + && (fabs(residual[i]) > epsilon * x[i]->moles))) + { + error_string = sformatf( + "%20s Surface mass balance has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + { + if ((x[i]->surface_charge->grams > MIN_RELATED_SURFACE + && fabs(residual[i]) > + epsilon) /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Surface charge/potential has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == GAS_MOLES) + { + if (gas_in == FALSE) + continue; + if (residual[i] >= epsilon + || residual[i] <= -epsilon /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Total moles in gas phase has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + else if (x[i]->type == PITZER_GAMMA) + { + if (fabs(residual[i]) > epsilon) + { + error_string = sformatf( + "%20s log gamma not converged.\tResidual: %e\n", + x[i]->description, (double) residual[i]); + } + } + else if (x[i]->type == S_S_MOLES) + { + if (x[i]->s_s_in == FALSE) + continue; + if (x[i]->moles <= MIN_TOTAL_SS) + continue; + if (residual[i] >= epsilon + || residual[i] <= -epsilon /* || stop_program == TRUE */ ) + { + error_string = sformatf( + "%20s Total moles in solid solution has not converged. " + "\tResidual: %e\n", x[i]->description, + (double) residual[i]); + error_msg(error_string, CONTINUE); + } + } + } + if (remove_unstable_phases == TRUE) + { + log_msg(sformatf( "%20sRemoving unstable phases, iteration %d.", + " ", iterations)); + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +gammas(LDBLE mu) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates gammas and [moles * d(ln gamma)/d mu] for all aqueous + * species. + */ + int i, j; + int ifirst, ilast; + LDBLE d1, d2, d3, f, a_llnl, b_llnl, bdot_llnl, log_g_co2, dln_g_co2, c2_llnl; + LDBLE s1, s2, s3; + LDBLE c1, c2, a, b; + LDBLE muhalf, equiv; + /* Initialize */ + if (pitzer_model == TRUE) + return gammas_pz(); + if (sit_model == TRUE) + return gammas_sit(); + a_llnl = b_llnl = bdot_llnl = log_g_co2 = dln_g_co2 = c2_llnl = 0; +/* + * compute temperature dependence of a and b for debye-huckel + */ + s1 = 374.11 - tc_x; + s2 = pow(s1, (LDBLE) 1.0 / (LDBLE) 3.0); + s3 = 1.0 + 0.1342489 * s2 - 3.946263e-03 * s1; + s3 = s3 / (3.1975 - 0.3151548 * s2 - 1.203374e-03 * s1 + + 7.48908e-13 * (s1 * s1 * s1 * s1)); + s3 = sqrt(s3); + if (tk_x >= 373.15) + { + c1 = 5321.0 / tk_x + 233.76 - + tk_x * (tk_x * (8.292e-07 * tk_x - 1.417e-03) + 0.9297); + } + else + { + /* replaced by wateq4f expression + c1=87.74-tc_x*(tc_x*(1.41e-06*tc_x-9.398e-04)+0.4008); + */ + c1 = 2727.586 + 0.6224107 * tk_x - 466.9151 * log(tk_x) - + 52000.87 / tk_x; + } + c1 = sqrt(c1 * tk_x); + /* replaced by wateq4f expressions + a=1824600.0*s3/(c1 * c1 * c1); + b=50.29*s3/c1; + */ + a = 1824827.7 * s3 / (c1 * c1 * c1); + b = 50.2905 * s3 / c1; + /* + * LLNL temperature dependence + */ + if (llnl_count_temp > 0) + { + ifirst = 0; + ilast = llnl_count_temp; + if (tc_x < llnl_temp[0] || tc_x > llnl_temp[llnl_count_temp - 1]) + { + error_msg + ("Temperature out of range of LLNL_AQUEOUS_MODEL parameters", + STOP); + } + for (i = 0; i < llnl_count_temp; i++) + { + if (tc_x >= llnl_temp[i]) + ifirst = i; + if (tc_x <= llnl_temp[i]) + { + ilast = i; + break; + } + } + if (ilast == ifirst) + { + f = 1; + } + else + { + f = (tc_x - llnl_temp[ifirst]) / (llnl_temp[ilast] - + llnl_temp[ifirst]); + } + a_llnl = (1 - f) * llnl_adh[ifirst] + f * llnl_adh[ilast]; + b_llnl = (1 - f) * llnl_bdh[ifirst] + f * llnl_bdh[ilast]; + bdot_llnl = (1 - f) * llnl_bdot[ifirst] + f * llnl_bdot[ilast]; + /* + * CO2 activity coefficient + */ + log_g_co2 = + (llnl_co2_coefs[0] + llnl_co2_coefs[1] * tk_x + + llnl_co2_coefs[2] / tk_x) * mu - (llnl_co2_coefs[3] + + llnl_co2_coefs[4] * tk_x) * + (mu / (mu + 1)); + log_g_co2 /= LOG_10; + dln_g_co2 = + (llnl_co2_coefs[0] + llnl_co2_coefs[1] * tk_x + + llnl_co2_coefs[2] / tk_x) - (llnl_co2_coefs[3] + + llnl_co2_coefs[4] * tk_x) * (1 / + ((mu + + 1) * + (mu + + 1))); + } + +/* + * constants for equations + */ + muhalf = sqrt(mu); + c1 = (-a) * LOG_10 * (1.0 / + (2 * muhalf * (muhalf + 1.0) * (muhalf + 1.0)) - + 0.3); + c2 = -a / (2 * muhalf); + if (llnl_count_temp > 0) + { + c2_llnl = -a_llnl / (2 * muhalf); + } + +/* + * Calculate activity coefficients + */ + for (i = 0; i < count_s_x; i++) + { + switch (s_x[i]->gflag) + { + case 0: /* uncharged */ + s_x[i]->lg = s_x[i]->dhb * mu; + s_x[i]->dg = s_x[i]->dhb * LOG_10 * s_x[i]->moles; + break; + case 1: /* Davies */ + s_x[i]->lg = -s_x[i]->z * s_x[i]->z * a * + (muhalf / (1.0 + muhalf) - 0.3 * mu); + s_x[i]->dg = c1 * s_x[i]->z * s_x[i]->z * s_x[i]->moles; + break; + case 2: /* Extended D-H, WATEQ D-H */ + s_x[i]->lg = -a * muhalf * s_x[i]->z * s_x[i]->z / + (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu; + s_x[i]->dg = (c2 * s_x[i]->z * s_x[i]->z / + ((1.0 + s_x[i]->dha * b * muhalf) * (1.0 + + s_x[i]->dha * + b * muhalf)) + + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; +/* if (mu_x < 1e-6) s_x[i]->dg = 0.0; */ + break; + case 3: /* Always 1.0 */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + break; + case 4: /* Exchange */ +/* + * Find CEC + * z contains valence of cation for exchange species, alk contains cec + */ +/* !!!!! */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == EX) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->exch_gflag == 1 && s_x[i]->alk > 0) + { + /* Davies */ + d1 = s_x[i]->lg; + s_x[i]->lg = -s_x[i]->equiv * s_x[i]->equiv * a * + (muhalf / (1.0 + muhalf) - 0.3 * mu) + + log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + if (s_x[i]->a_f && s_x[i]->primary == NULL) + { + d2 = s_x[i]->moles * s_x[i]->equiv / s_x[i]->alk; + if (d2 > 1) d2 = 1; + d2 = s_x[i]->lg - s_x[i]->a_f * (1 - d2); + d3 = 0.89; + if (iterations < 10) d3 = 0.7; else d3 = 0.89; + s_x[i]->lg = d3 * d1 + (1 - d3) * d2; + } + s_x[i]->dg = + c1 * s_x[i]->equiv * s_x[i]->equiv * s_x[i]->moles; + } + else if (s_x[i]->exch_gflag == 2 && s_x[i]->alk > 0) + { + /* Extended D-H, WATEQ D-H */ + d1 = s_x[i]->lg; + s_x[i]->lg = -a * muhalf * s_x[i]->equiv * s_x[i]->equiv / + (1.0 + s_x[i]->dha * b * muhalf) + s_x[i]->dhb * mu + + log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + if (s_x[i]->a_f && s_x[i]->primary == NULL) + { + d2 = s_x[i]->moles * s_x[i]->equiv / s_x[i]->alk; + if (d2 > 1) d2 = 1; + d2 = s_x[i]->lg - s_x[i]->a_f * (1 - d2); + d3 = 0.89; + if (iterations < 10) d3 = 0.7; else d3 = 0.89; + s_x[i]->lg = d3 * d1 + (1 - d3) * d2; + } + s_x[i]->dg = (c2 * s_x[i]->equiv * s_x[i]->equiv / + ((1.0 + s_x[i]->dha * b * muhalf) * (1.0 + + s_x[i]-> + dha * b * + muhalf)) + + s_x[i]->dhb) * LOG_10 * s_x[i]->moles; + } + else if (s_x[i]->exch_gflag == 7 && s_x[i]->alk > 0) + { + if (llnl_count_temp > 0) + { + s_x[i]->lg = + -a_llnl * muhalf * s_x[i]->equiv * s_x[i]->equiv / + (1.0 + s_x[i]->dha * b_llnl * muhalf) + + bdot_llnl * mu + + log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + s_x[i]->dg = + (c2_llnl * s_x[i]->equiv * s_x[i]->equiv / + ((1.0 + s_x[i]->dha * b_llnl * muhalf) * (1.0 + + s_x[i]-> + dha * + b_llnl * + muhalf)) + + bdot_llnl) * LOG_10 * s_x[i]->moles; + } + else + { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", + STOP); + } + } + else + { +/* + * Master species is a dummy variable with meaningless activity and mass + */ + if (s_x[i]->primary != NULL) + { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + else + { + if (s_x[i]->alk <= 0) + { + s_x[i]->lg = 0.0; + } + else + { + s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + } + s_x[i]->dg = 0.0; + } + } + break; + case 5: /* Always 1.0 */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + break; + case 6: /* Surface */ +/* + * Find moles of sites. + * s_x[i]->equiv is stoichiometric coefficient of sites in species + */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == SURF) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (use.Get_surface_ptr()->type == CD_MUSIC) + { + /* mole fraction */ + equiv = 1.0; + } + else + { + equiv = s_x[i]->equiv; + } + if (s_x[i]->alk > 0) + { + s_x[i]->lg = log10(equiv / s_x[i]->alk); + s_x[i]->dg = 0.0; + } + else + { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + break; + case 7: /* LLNL */ + if (llnl_count_temp > 0) + { + if (s_x[i]->z == 0) + { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + else + { + s_x[i]->lg = -a_llnl * muhalf * s_x[i]->z * s_x[i]->z / + (1.0 + s_x[i]->dha * b_llnl * muhalf) + + bdot_llnl * mu; + s_x[i]->dg = + (c2_llnl * s_x[i]->z * s_x[i]->z / + ((1.0 + s_x[i]->dha * b_llnl * muhalf) * (1.0 + + s_x[i]-> + dha * + b_llnl * + muhalf)) + + bdot_llnl) * LOG_10 * s_x[i]->moles; + break; + } + } + else + { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); + } + break; + case 8: /* LLNL CO2 */ + if (llnl_count_temp > 0) + { + s_x[i]->lg = log_g_co2; + s_x[i]->dg = dln_g_co2 * s_x[i]->moles; + } + else + { + error_msg("LLNL_AQUEOUS_MODEL_PARAMETERS not defined.", STOP); + } + break; + case 9: /* activity water */ + s_x[i]->lg = log10(exp(s_h2o->la * LOG_10) * gfw_water); + s_x[i]->dg = 0.0; + break; + } +/* + if (mu_unknown != NULL) { + if (fabs(residual[mu_unknown->number]) > 0.1 && + fabs(residual[mu_unknown->number])/mu_x > 0.5) { + s_x[i]->dg = 0.0; + } + } + */ + } + return (OK); +} + +/* ------------------------------------------------------------------------------- */ +int Phreeqc:: +ineq(int in_kode) +/* ------------------------------------------------------------------------------- */ +{ +/* + * Sets up equations and inequalities for Cl1. + * Scales columns if necessary. + * Eliminates equations that are not necessary because + * gas_phase, s_s, or phase equation is not needed + * Mallocs space + * Calls Cl1 + * Rescales results if necessary + */ + int i, j; + int return_code; + int l_count_rows; + int l_count_optimize, count_equal; + int k, l, m, n; + int l_klmd, l_nklmd, l_n2d; + int l_iter; + LDBLE l_error; + LDBLE max; + int l_kode; + LDBLE min; +#ifdef SLNQ + LDBLE *slnq_array; + LDBLE *slnq_delta1; +#endif +/* Debug + if (debug_model == TRUE) { + output_msg(sformatf( "\narray:\n\n"); + array_print(array, count_unknowns, count_unknowns + 1, count_unknowns + 1)); + } + */ +/* + * Special case for removing unstable phases + */ + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblageComp * comp_ptr; + + if (remove_unstable_phases == TRUE) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nSolution vector for removing unstable phases:\n")); + } + for (i = 0; i < count_unknowns; i++) + { + + if (x[i]->type == PP) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); + if (residual[i] > 0e-8 && x[i]->moles > 0 && + it->second.Get_add_formula().size() == 0 + && x[i]->dissolve_only == FALSE) + { + /* + * Set mass transfer to all of phase + */ + delta[i] = x[i]->moles; + } + else + { + delta[i] = 0.0; + } + if (debug_model == TRUE) + { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, + x[i]->description, (double) delta[i])); + } + } + } +#ifdef SKIP + for (i = 0; i < count_unknowns; i++) + { + + if (x[i]->type == PP && residual[i] > 0e-8 && x[i]->moles > 0 && + x[i]->pure_phase->add_formula == NULL + && x[i]->dissolve_only == FALSE) + { +/* + * Set mass transfer to all of phase + */ + delta[i] = x[i]->moles; + } + else + { + delta[i] = 0.0; + } + if (debug_model == TRUE) + { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, + x[i]->description, (double) delta[i])); + } + } +#endif + remove_unstable_phases = FALSE; + return (OK); + } +/* + * Pitzer model does not have activity of water or mu + */ + if (pitzer_model == TRUE || sit_model == TRUE) + { + for (i = 0; i < count_unknowns; i++) + { + if ((x[i]->type == AH2O && full_pitzer == FALSE) || + (x[i]->type == MH && pitzer_model == TRUE && pitzer_pe == FALSE) || + x[i]->type == MU || + (x[i]->type == PITZER_GAMMA && full_pitzer == FALSE)) + { + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] = 0.0; + } + for (j = 0; j < count_unknowns + 1; j++) + { + array[i * (count_unknowns + 1) + j] = 0.0; + } + } + } + } +/* +* Slack unknown +*/ + + if (slack && slack_unknown) + { + int n = slack_unknown->number; + // slack row + for (j = 0; j <= count_unknowns + 1; j++) + { + array[n * (count_unknowns + 1) + j] = 0.0; + } + // slack column + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + n] = 1.0; + } + } +#ifdef SKIP + if (slack && slack_unknown) + { + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type == SLACK) + { + array[j * (count_unknowns + 1) + x[j]->number] = 1.0; + array[x[j]->mb_number * (count_unknowns + 1) + x[j]->number] = 1.0; + } + } + } +#endif +/* + * Initialize space if necessary + */ + ineq_init(3 * count_unknowns, 3 * count_unknowns); +/* + * Normalize column + */ + space((void **) ((void *) &normal), count_unknowns, &normal_max, + sizeof(LDBLE)); + + for (i = 0; i < count_unknowns; i++) + normal[i] = 1.0; + + + for (i = 0; i < count_unknowns; i++) + { + max = 0.0; + + if (x[i]->type == MB || x[i]->type == ALK || x[i]->type == EXCH + || x[i]->type == SURFACE || x[i]->type == SURFACE_CB + || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) + { + if (x[i]->moles <= MIN_RELATED_SURFACE + && (x[i]->type == EXCH || x[i]->type == SURFACE)) + continue; + for (j = 0; j < count_unknowns; j++) + { + if (x[i]->type == SURFACE && x[j]->type == SURFACE_CB) + continue; + if (x[i]->type == SURFACE_CB1 && x[j]->type == SURFACE_CB2) + continue; + + if (fabs(array[j * (count_unknowns + 1) + i]) > max) + { + max = fabs(array[j * (count_unknowns + 1) + i]); + if (max > min_value) + break; + } + } + if (diagonal_scale == TRUE) + { + if (fabs(array[i * (count_unknowns + 1) + i]) < min_value) + { + max = fabs(array[i * (count_unknowns + 1) + i]); + } + } + + if (max == 0) + { + array[i * (count_unknowns + 1) + i] = 1e-5 * x[i]->moles; + max = fabs(1e-5 * x[i]->moles); + } + } + + if (x[i]->type == MH && (pitzer_model == FALSE || pitzer_pe == TRUE)) + { + /* make absolute value of diagonal at least 1e-12 */ + + min = 1e-12; + min = MIN_TOTAL; + array[x[i]->number * (count_unknowns + 1) + x[i]->number] += min; + if (fabs + (array[x[i]->number * (count_unknowns + 1) + x[i]->number]) < + min) + array[x[i]->number * (count_unknowns + 1) + x[i]->number] = + min; + max = 0.0; + + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != MB && + x[j]->type != SURFACE && + x[j]->type != SURFACE_CB && + x[j]->type != SURFACE_CB1 && + x[j]->type != SURFACE_CB2 && + x[j]->type != EXCH && x[j]->type != MH + && x[j]->type != MH2O) + continue; + if (fabs(array[j * (count_unknowns + 1) + i]) > max) + { + max = fabs(array[j * (count_unknowns + 1) + i]); + if (max > min_value) + break; + } + } + } + + if (max > 0.0 && max < min_value) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "Scaling column for %s, max= %e\n", + x[i]->description, (double) max)); + } + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] *= min_value / max; + } + normal[i] = min_value / max; + } + } + +/* + * Allocate arrays for inequality solver + */ + max_row_count = 2 * count_unknowns + 2; + max_column_count = count_unknowns + 2; + space((void **) ((void *) &ineq_array), max_row_count * max_column_count, + &ineq_array_max, sizeof(LDBLE)); + + space((void **) ((void *) &back_eq), max_row_count, &back_eq_max, + sizeof(int)); + + space((void **) ((void *) &zero), max_row_count, &zero_max, + sizeof(LDBLE)); + zero_double(zero, max_row_count); + + space((void **) ((void *) &res), max_row_count, &res_max, sizeof(LDBLE)); + zero_double(res, max_row_count); + + space((void **) ((void *) &delta1), max_column_count, &delta1_max, + sizeof(LDBLE)); + zero_double(delta1, max_column_count); + +/* + * Copy equations to optimize into ineq_array + */ + l_count_rows = 0; + for (i = 0; i < count_unknowns; i++) + { + if (iterations < aqueous_only) + continue; +/* + * slack + */ + if (slack && slack_unknown && x[i]->type == SLACK) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + l_count_rows++; + } +/* + * Pure phases + */ + if (x[i]->type == PP) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + /* not in model, ignore */ + if (x[i]->phase->in == FALSE) + continue; + if (it->second.Get_force_equality()) + continue; + /* Undersaturated and no mass, ignore */ + if (x[i]->f > 0e-8 && x[i]->moles <= 0 + && it->second.Get_add_formula().size() == 0) + { + continue; + } + else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE + && (x[i]->moles - it->second.Get_initial_moles() >= 0)) + { + continue; + } + else + { + /* Copy in saturation index equation (has mass or supersaturated) */ + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + if (it->second.Get_add_formula().size() == 0 + && x[i]->dissolve_only == FALSE) + { + res[l_count_rows] = 1.0; + } +/* + * If infeasible solution on first attempt, remove constraints on IAP + */ + if (pp_scale != 1) + { + for (j = 0; j < count_unknowns + 1; j++) + { + ineq_array[l_count_rows * max_column_count + j] *= + pp_scale; + } + } + + if (in_kode != 1) + { + res[l_count_rows] = 0.0; + } + l_count_rows++; + } + } +#ifdef SKIP + if (x[i]->type == PP) + { + /* not in model, ignore */ + if (x[i]->pure_phase->phase->in == FALSE) + continue; + if (x[i]->pure_phase->force_equality == TRUE) + continue; + /* Undersaturated and no mass, ignore */ + if (x[i]->f > 0e-8 && x[i]->moles <= 0 + && x[i]->pure_phase->add_formula == NULL) + { + continue; + } + else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE + && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) + { + continue; + } + else + { + /* Copy in saturation index equation (has mass or supersaturated) */ + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + if (x[i]->pure_phase->add_formula == NULL + && x[i]->dissolve_only == FALSE) + { + res[l_count_rows] = 1.0; + } +/* + * If infeasible solution on first attempt, remove constraints on IAP + */ + if (pp_scale != 1) + { + for (j = 0; j < count_unknowns + 1; j++) + { + ineq_array[l_count_rows * max_column_count + j] *= + pp_scale; + } + } + + if (in_kode != 1) + { + res[l_count_rows] = 0.0; + } + l_count_rows++; + } + } +#endif + else if (x[i]->type == ALK || x[i]->type == SOLUTION_PHASE_BOUNDARY) + { +/* + * Alkalinity and solution phase boundary + */ + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + l_count_rows++; +/* + * Gas phase + */ + } + else if (x[i]->type == GAS_MOLES && gas_in == TRUE) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + + res[l_count_rows] = 1.0; + if (in_kode != 1) + { + res[l_count_rows] = 0.0; + } + l_count_rows++; +/* + * Solid solution + */ + } + else if (x[i]->type == S_S_MOLES && x[i]->s_s_in == TRUE) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + res[l_count_rows] = 1.0; + if (in_kode != 1) + { + res[l_count_rows] = 0.0; + } + l_count_rows++; + } + } + l_count_optimize = l_count_rows; +/* + * Copy equality equations into ineq_array + */ + for (i = 0; i < count_unknowns; i++) + { + comp_ptr = NULL; + cxxPPassemblageComp *comp_ptr1 = NULL; + if (x[i]->type == PP) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + } + if (x[i]->type == SURFACE && x[i]->phase_unknown != NULL) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->phase_unknown->phase->name); + } + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL) + { + comp_ptr1 = pp_assemblage_ptr->Find(x[i-1]->phase_unknown->phase->name); + } + if (x[i]->type != SOLUTION_PHASE_BOUNDARY && + x[i]->type != ALK && + x[i]->type != GAS_MOLES && x[i]->type != S_S_MOLES + /* && x[i]->type != PP */ + && x[i]->type != SLACK + ) + { + if (x[i]->type == PP && !comp_ptr->Get_force_equality()) + continue; + if (x[i]->type == MH && pitzer_model == TRUE && pitzer_pe == FALSE) + continue; + if (mass_water_switch == TRUE && x[i] == mass_oxygen_unknown) + continue; +/* + * Mass balance, CB, MU, AH2O, MH, MH2O, others + */ + if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) + continue; + if (x[i]->type == SURFACE && + x[i]->phase_unknown == NULL + && x[i]->moles <= MIN_RELATED_SURFACE) + continue; + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) && + /* x[i-1]->phase_unknown == NULL && */ + /* x[i-1]->moles <= MIN_RELATED_SURFACE) continue; */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) + continue; + if (x[i]->type == SURFACE && x[i]->phase_unknown != NULL && +/* x[i]->phase_unknown->f > 0e-8 && */ + x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && + comp_ptr->Get_add_formula().size() == 0) + continue; + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL && +/* x[i-1]->phase_unknown->f > 0e-8 && */ +/* x[i-1]->phase_unknown->moles <= MIN_RELATED_SURFACE && */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + comp_ptr1->Get_add_formula().size() == 0) + continue; + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + if (mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown) + { + k = mass_oxygen_unknown->number; + for (j = 0; j < count_unknowns; j++) + { + ineq_array[l_count_rows * max_column_count + j] -= + 2 * array[k * (count_unknowns + 1) + j]; + } + } + l_count_rows++; + } + else if (x[i]->type == PITZER_GAMMA) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + l_count_rows++; + } + } + count_equal = l_count_rows - l_count_optimize; +/* + * Copy inequality constraints into ineq + */ + if (pure_phase_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == PP) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + /* not in model, ignore */ + if (x[i]->phase->in == FALSE) + continue; + /* No moles and undersaturated, ignore */ + if (x[i]->moles <= 0.0 && x[i]->f > 0e-8 && + comp_ptr->Get_add_formula().size() == 0) + { + continue; + /* No moles of pure phase present, must precipitate */ + } + else if (x[i]->moles <= 0.0) + { + delta1[i] = -1.0; + } + else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE + && (x[i]->moles - comp_ptr->Get_initial_moles() >= + 0)) + { + continue; + } + else + { + + /* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */ + memcpy((void *) + &(ineq_array[l_count_rows * max_column_count]), + (void *) &(zero[0]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[l_count_rows * max_column_count + i] = 1.0; + ineq_array[l_count_rows * max_column_count + + count_unknowns] = x[i]->moles; + back_eq[l_count_rows] = i; + l_count_rows++; + } + /* Pure phase is present and dissolve_only, force ppt to be <= amount of dissolved so far */ + if (x[i]->dissolve_only == TRUE) + { + memcpy((void *) + &(ineq_array[l_count_rows * max_column_count]), + (void *) &(zero[0]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[l_count_rows * max_column_count + i] = -1.0; + ineq_array[l_count_rows * max_column_count + + count_unknowns] = + comp_ptr->Get_initial_moles() - x[i]->moles; + back_eq[l_count_rows] = i; + l_count_rows++; + } + } + } + } +/* + * Add inequality for mass of oxygen greater than zero + */ + if (pitzer_model || sit_model) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MH2O) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type < PP) + { + ineq_array[l_count_rows * max_column_count + j] = 0.0; + } + else + { + /*ineq_array[l_count_rows*max_column_count + j] = -ineq_array[l_count_rows*max_column_count + j]; */ + } + } + ineq_array[l_count_rows * max_column_count + count_unknowns] = + 0.5 * x[i]->moles; + l_count_rows++; + } + } + } + + +/* + * Hydrogen mass balance is good + */ +/* + * No moles and undersaturated, mass transfer must be zero + */ + if (pure_phase_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == PP) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + if ((x[i]->moles <= 0.0 && x[i]->f > 0e-8 && + comp_ptr->Get_add_formula().size() == 0) + || x[i]->phase->in == FALSE) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + if (x[i]->dissolve_only == TRUE) + { + if (x[i]->f < 0e-8 + && (x[i]->moles - comp_ptr->Get_initial_moles() >= + 0)) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } + } + } +/* + * No moles of exchanger + */ + if (use.Get_exchange_ptr() != NULL + //&& (use.Get_exchange_ptr()->related_phases == TRUE + // || use.Get_exchange_ptr()->related_rate == TRUE)) + && (((cxxExchange *) use.Get_exchange_ptr())->Get_related_phases() || + ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate())) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == EXCH && x[i]->moles <= 0) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } +/* + * No moles of surface + */ + if (use.Get_surface_ptr() != NULL + && (use.Get_surface_ptr()->related_phases == TRUE + || use.Get_surface_ptr()->related_rate == TRUE)) + { + for (i = 0; i < count_unknowns; i++) + { + comp_ptr = NULL; + cxxPPassemblageComp * comp_ptr1 = NULL; + if (x[i]->type == SURFACE && x[i]->phase_unknown != NULL) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->phase_unknown->phase->name); + } + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && (x[i - 1]->phase_unknown != NULL)) + { + comp_ptr1 = pp_assemblage_ptr->Find(x[i-1]->phase_unknown->phase->name); + } + if ((x[i]->type == SURFACE && x[i]->phase_unknown != NULL && +/* x[i]->phase_unknown->f > 0e-8 && */ + x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && + comp_ptr->Get_add_formula().size() == 0) || + ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL && +/* x[i-1]->phase_unknown->f > 0e-8 && */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + comp_ptr1->Get_add_formula().size() == 0)) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } +#ifdef SKIP +/* + * No moles of surface + */ + if (use.Get_surface_ptr() != NULL + && (use.Get_surface_ptr()->related_phases == TRUE + || use.Get_surface_ptr()->related_rate == TRUE)) + { + for (i = 0; i < count_unknowns; i++) + { + if ((x[i]->type == SURFACE && x[i]->phase_unknown != NULL && +/* x[i]->phase_unknown->f > 0e-8 && */ + x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && + x[i]->phase_unknown->pure_phase->add_formula == NULL) || + ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL && +/* x[i-1]->phase_unknown->f > 0e-8 && */ + x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + x[i - 1]->phase_unknown->pure_phase->add_formula == NULL)) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } +#endif +/* + * No moles of surface + */ + if (use.Get_surface_ptr() != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if ((x[i]->type == SURFACE && + x[i]->phase_unknown == NULL && + x[i]->moles <= MIN_RELATED_SURFACE) || + ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown == NULL + && x[i]->surface_charge->grams <= MIN_RELATED_SURFACE)) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } +/* + * Moles of gas must be >= zero + */ + if (gas_in == TRUE) + { + for (i = gas_unknown->number; i < count_unknowns; i++) + { + if (x[i]->type == GAS_MOLES) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(zero[0]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[l_count_rows * max_column_count + i] = -1.0; + ineq_array[l_count_rows * max_column_count + count_unknowns] = + x[i]->moles; + back_eq[l_count_rows] = i; + l_count_rows++; + } + else + { + break; + } + } + } + else if (use.Get_gas_phase_ptr() != NULL && gas_in == FALSE) + { +/* + * Moles of gas small and sum p < ptotal + */ + i = gas_unknown->number; + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } +/* + * Phase must be "in" and moles of solid solution must be >= zero + */ + + if (s_s_unknown != NULL) + { + for (i = s_s_unknown->number; i < count_unknowns; i++) + { + if (x[i]->type != S_S_MOLES) + break; + if (x[i]->phase->in == TRUE && x[i]->s_s_in == TRUE) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(zero[0]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[l_count_rows * max_column_count + i] = 1.0; + ineq_array[l_count_rows * max_column_count + count_unknowns] = + 0.99 * x[i]->moles - MIN_TOTAL_SS; + back_eq[l_count_rows] = i; + l_count_rows++; + } + else + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] = 0.0; + } + } + } + } +/* + * Add inequality if total moles of element is less than zero + */ + if (negative_concentrations) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB && x[i]->moles < 0.0) + { + memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + (void *) &(array[i * (count_unknowns + 1)]), + (size_t) (count_unknowns + 1) * sizeof(LDBLE)); + back_eq[l_count_rows] = i; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type < PP) + { + ineq_array[l_count_rows * max_column_count + j] = 0.0; + } + } + l_count_rows++; + } + } + } +/* + * Zero column for mass of water + */ + if (mass_oxygen_unknown != NULL && mass_water_switch == TRUE) + { + k = mass_oxygen_unknown->number; + for (j = 0; j < l_count_rows + 1; j++) + { + ineq_array[j * max_column_count + k] = 0; + } + } +/* + * Scale column for pure phases + */ + for (i = 0; i < count_unknowns; i++) + { + if ((x[i]->type == PP || x[i]->type == S_S_MOLES) + && pp_column_scale != 1.0) + { + for (j = 0; j < l_count_rows; j++) + { + ineq_array[j * max_column_count + i] *= pp_column_scale; + } + normal[i] = pp_column_scale; + } + + } + if (debug_model == TRUE) + { + output_msg(sformatf( "\nA and B arrays:\n\n")); + array_print(ineq_array, l_count_rows, count_unknowns + 1, + max_column_count); + } +/* + * Calculate dimensions + */ + k = l_count_optimize; /* rows in A */ + l = count_equal; /* rows in C */ + m = l_count_rows - l - k; /* rows in E */ + if (m < 0) + m = 0; + + if (debug_model == TRUE) + { + output_msg(sformatf( "k, l, m\t%d\t%d\t%d\n", k, l, m)); + } + + n = count_unknowns; /* columns in A, C, E */ + l_klmd = max_row_count - 2; + l_nklmd = n + l_klmd; + l_n2d = n + 2; +/* + * Retain constraints on mineral mass transfers, even if infeasible on + * first attempt. + */ + l_kode = 1; + + if (in_kode == 2) + { + l_kode = 1; + } + l_iter = 2*(count_unknowns + l_count_rows); +/* + * Allocate space for arrays + */ + space((void **) ((void *) &cu), 2 * l_nklmd, &cu_max, sizeof(LDBLE)); + + space((void **) ((void *) &iu), 2 * l_nklmd, &iu_max, sizeof(int)); + + space((void **) ((void *) &is), l_klmd, &is_max, sizeof(int)); + +#ifdef SLNQ + slnq_array = + (LDBLE *) PHRQ_malloc((size_t) count_unknowns * + (count_unknowns + 1) * sizeof(LDBLE)); + if (slnq_array == NULL) + malloc_error(); + for (i = 0; i < k + l; i++) + { + for (j = 0; j <= count_unknowns; j++) + { + slnq_array[i * (count_unknowns + 1) + j] = + ineq_array[i * max_column_count + j]; + } + } + slnq_delta1 = + (LDBLE *) PHRQ_malloc((size_t) max_column_count * sizeof(LDBLE)); + if (slnq_delta1 == NULL) + malloc_error(); + memcpy((void *) &(slnq_delta1[0]), (void *) &(zero[0]), + (size_t) max_column_count * sizeof(LDBLE)); +#endif +/* + * Call CL1 + */ + cl1(k, l, m, n, + l_nklmd, l_n2d, ineq_array, + &l_kode, ineq_tol, &l_iter, delta1, res, &l_error, cu, iu, is, FALSE); +/* Set return_kode */ + if (l_kode == 1) + { + return_code = ERROR; + } + else if (l_kode == 2) + { + return_code = 2; + } + else if (l_kode == 3) + { + return_code = ERROR; + return_code = 2; + //error_msg("Too many iterations in Cl1. Should not have done this.", STOP); + warning_msg("Too many iterations in Cl1. Should not have done this."); + } + else + { + return_code = OK; + } +#ifdef SLNQ +/* if (l_kode > 0 && ((k + l) == count_unknowns)) { */ + if (l_kode > 0 && ((k + l) <= count_unknowns)) + { + if (add_trivial_eqns(k + l, count_unknowns, slnq_array) == TRUE) + { + if (debug_model == TRUE) + output_msg(sformatf( "Calling SLNQ, iteration %d\n", + iterations)); + log_msg(sformatf( "Calling SLNQ, iteration %d\n", + iterations)); + if (slnq + (count_unknowns, slnq_array, slnq_delta1, count_unknowns + 1, + debug_model) == OK) + { + memcpy((void *) &(delta1[0]), (void *) &(slnq_delta1[0]), + (size_t) count_unknowns * sizeof(LDBLE)); + if (debug_model == TRUE) + output_msg(sformatf( "Using SLNQ results.\n")); + log_msg(sformatf( "Using SLNQ results.\n")); + return_code = OK; + } + else + { + if (debug_model == TRUE) + output_msg(sformatf( + "Could not use SLNQ results.\n")); + log_msg(sformatf( "Could not use SLNQ results.\n")); + } + } + else + { + log_msg(sformatf( + "Could not call SLNQ, row %d, unknowns %d, iteration %d\n", + k + l, count_unknowns, iterations)); + } + } + else if (l_kode > 0) + { + log_msg(sformatf( "Could not call SLNQ, row %d, unknowns %d\n", + k + l, count_unknowns)); + } +#endif +/* Copy delta1 into delta and scale */ + + memcpy((void *) &(delta[0]), (void *) &(delta1[0]), + (size_t) count_unknowns * sizeof(LDBLE)); + for (i = 0; i < count_unknowns; i++) + delta[i] *= normal[i]; +/* + * Rescale columns of array + */ + for (i = 0; i < count_unknowns; i++) + { + if (normal[i] != 1.0) + { + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] /= normal[i]; + } + } + } + + /* adjust unknowns where cl1 failed */ + if (l_kode != 0) + { + for (i = 0; i < l_count_rows; i++) + { + /* + output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, + x[back_eq[i]]->description, (double) res[i); + */ + j = back_eq[i]; + if (x[j]->type == MB && delta[j] == 0.0 && fabs(res[i]) > ineq_tol) + { + delta[j] = res[i]/fabs(res[i]) * 1; + } + } + } + +/* + * Debug, write results of ineq + */ + + if (debug_model == TRUE) + { + output_msg(sformatf( "kode: %d\titer: %d\terror: %e\n", l_kode, + l_iter, (double) l_error)); + output_msg(sformatf( "\nsolution vector:\n")); + for (i = 0; i < count_unknowns; i++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e", i, + x[i]->description, (double) delta[i])); + if (x[i]->type == PP) + { + output_msg(sformatf( " -SI %10.2e Moles %10.2e", + (double) x[i]->f, (double) x[i]->moles)); + if (x[i]->f < 0e-8 || x[i]->moles > 0.0) + { + output_msg(sformatf( " **")); + } + } + output_msg(sformatf( "\n")); + } + + output_msg(sformatf( "\nresidual vector:\n")); + for (i = 0; i < l_count_rows; i++) + { + output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, + x[back_eq[i]]->description, (double) res[i])); + } + } +#ifdef SLNQ + slnq_array = (LDBL *) free_check_null(slnq_array); + slnq_delta1 = (LDBL *) free_check_null(slnq_delta1); +#endif + return (return_code); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +jacobian_sums(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fills in jacobian array, uses arrays sum_jacob0, sum_jacob1, and + * sum_jacob2. + */ + int i, j, k; + LDBLE sinh_constant; +/* + * Clear array, note residuals are in array[i, count_unknowns+1] + */ + for (i = 0; i < count_unknowns; i++) + { + array[i] = 0.0; + } + for (i = 1; i < count_unknowns; i++) + { + memcpy((void *) &(array[i * (count_unknowns + 1)]), + (void *) &(array[0]), (size_t) count_unknowns * sizeof(LDBLE)); + } +/* + * Add constant terms + */ + for (k = 0; k < count_sum_jacob0; k++) + { + *sum_jacob0[k].target += sum_jacob0[k].coef; + } +/* + * Add terms with coefficients of 1.0 + */ + for (k = 0; k < count_sum_jacob1; k++) + { + *sum_jacob1[k].target += *sum_jacob1[k].source; + } +/* + * Add terms with coefficients != 1.0 + */ + for (k = 0; k < count_sum_jacob2; k++) + { + *sum_jacob2[k].target += *sum_jacob2[k].source * sum_jacob2[k].coef; + } +/* + * Make final adustments to jacobian array + */ +/* + * Ionic strength + */ + if (mu_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + // using straight mu equation + array[mu_unknown->number * (count_unknowns + 1) + i] *= 0.5; + } + array[mu_unknown->number * (count_unknowns + 1) + + mu_unknown->number] -= mass_water_aq_x; + } +/* + * Mass of oxygen + */ + if (mass_oxygen_unknown != NULL && mu_unknown != NULL) + { + array[mu_unknown->number * (count_unknowns + 1) + + mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x; + } +/* + * Activity of water + */ + if (ah2o_unknown != NULL) + { + if (dampen_ah2o) + { + // factors for tanh attenuation to make ah2o positive + LDBLE y_sum = ah2o_unknown->f; + LDBLE x_h2o = mass_water_aq_x; + LDBLE a = 0.017; + LDBLE lim = 95.0 - 100.0*a*y_sum/x_h2o; + LDBLE factor = -a*(x_h2o*(-0.5*tanh(lim) - 0.5) + (50.0*a*y_sum - 47.5 * x_h2o) / (cosh(lim)*cosh(lim))) / + (x_h2o*x_h2o); + + for (i = 0; i < count_unknowns; i++) + { + array[ah2o_unknown->number * (count_unknowns + 1) + i] *= factor; + } + // activity of water term + array[ah2o_unknown->number * (count_unknowns + 1) + + ah2o_unknown->number] -= exp(s_h2o->la * LOG_10); + + // mass of water term + if (mass_oxygen_unknown != NULL) + { + array[ah2o_unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number] -= + a*y_sum*(x_h2o*(0.5*tanh(lim) + 0.5) + (47.5*x_h2o - 50.0*a*y_sum)/(cosh(lim)*cosh(lim))) / + (x_h2o*x_h2o*x_h2o); + } + } + else + { + for (i = 0; i < count_unknowns; i++) + { + array[ah2o_unknown->number * (count_unknowns + 1) + i] *= -0.017; + } + array[ah2o_unknown->number * (count_unknowns + 1) + ah2o_unknown->number] -= + mass_water_aq_x * exp(s_h2o->la * LOG_10); + if (mass_oxygen_unknown != NULL) + { + array[ah2o_unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number] -= + (exp(s_h2o->la * LOG_10) - 1) * mass_water_aq_x; + } + } + } + +/* + * Surface charge balance + */ + if (surface_unknown != NULL && dl_type_x == NO_DL) + { + sinh_constant = + sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * + 1000); + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE_CB && x[i]->surface_charge->grams > 0) + { + for (j = 0; j < count_unknowns; j++) + { + array[x[i]->number * (count_unknowns + 1) + j] *= + F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + } + array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= + sinh_constant * sqrt(mu_x) * + cosh(x[i]->master[0]->s->la * LOG_10); + if (mu_unknown != NULL) + { + array[x[i]->number * (count_unknowns + 1) + + mu_unknown->number] -= + 0.5 * sinh_constant / sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10); + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_sums(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates sums of species for calculation of mass balances, charge + * balance. Also calculates saturation indices for solution_phase_boundaries + * and pure_phases. After this routine total calcium calculated from all + * calcium species in solution is stored in x[i]->f. Also calculates + * x[i]->sum for some types of unknowns. Uses arrays sum_mb1 and + * sum_mb1, which are generated in prep and reprep. + */ + int k; +/* + * Clear functions in unknowns + */ + for (k = 0; k < count_unknowns; k++) + { + x[k]->f = 0.0; + x[k]->sum = 0.0; + } +/* + * Add terms with coefficients of 1.0 + */ + for (k = 0; k < count_sum_mb1; k++) + { + *sum_mb1[k].target += *sum_mb1[k].source; +/* { k += 1; k -= 1;} */ + } +/* + * Add terms with coefficients != 1.0 + */ + for (k = 0; k < count_sum_mb2; k++) + { + *sum_mb2[k].target += *sum_mb2[k].source * sum_mb2[k].coef; +/* { k += 1; k -= 1;} */ + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_gases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Determines whether gas_phase equation is needed + */ + gas_in = FALSE; + if (gas_unknown == NULL || use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_unknown->f > gas_phase_ptr->Get_total_p() + 1e-7 || + gas_unknown->moles > MIN_TOTAL) + { + gas_in = TRUE; + patm_x = gas_phase_ptr->Get_total_p(); + + } + } + else + { + if (numerical_fixed_volume && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume)) + { + gas_in = TRUE; + } + else + { + gas_in = FALSE; + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_s_s(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE lp, log10_iap, total_moles; + LDBLE iapc, iapb, l_kc, l_kb, lc, lb, xcaq, xbaq, xb, xc; + LDBLE sigmapi_aq, sigmapi_solid; + LDBLE total_p; + struct s_s *s_s_ptr; + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; +/* + * Determines whether solid solution equation is needed + */ + if (s_s_unknown == NULL || use.Get_ss_assemblage_ptr() == NULL) + return (OK); + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[i]); + total_moles = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) + { + total_moles += s_s_ptr->comps[j].moles; + } + if (total_moles > 1e-13) + { + s_s_ptr->s_s_in = TRUE; + } + else if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) + { + /* + * Calculate IAPc and IAPb + */ + if (s_s_ptr->comps[0].phase->rxn_x != NULL) + { + log10_iap = 0; + for (rxn_ptr = s_s_ptr->comps[0].phase->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapc = exp(log10_iap * LOG_10); + } + else + { + iapc = 1e-99; + } + if (s_s_ptr->comps[1].phase->rxn_x != NULL) + { + log10_iap = 0; + for (rxn_ptr = s_s_ptr->comps[1].phase->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapb = exp(log10_iap * LOG_10); + } + else + { + iapb = 1e-99; + } + /* + * Calculate sigma pi, aq + */ + sigmapi_aq = iapc + iapb; + /* + * Calculate xc,aq and xb, aq + */ + xcaq = iapc / (iapb + iapc); + xbaq = iapb / (iapb + iapc); + /* + * Get Kc and Kb + */ + l_kc = exp(s_s_ptr->comps[0].phase->lk * LOG_10); + l_kb = exp(s_s_ptr->comps[1].phase->lk * LOG_10); + /* + * Solve for xb + */ + xb = s_s_root(s_s_ptr->a0, s_s_ptr->a1, l_kc, l_kb, xcaq, xbaq); + /* + * Calculate lambdac and lambdab + */ + xc = 1 - xb; + lc = exp((s_s_ptr->a0 - s_s_ptr->a1 * (-4 * xb + 3)) * xb * xb); + lb = exp((s_s_ptr->a0 + s_s_ptr->a1 * (4 * xb - 1)) * xc * xc); + /* + * Calculate sigma pi, solid + */ + sigmapi_solid = xb * lb * l_kb + xc * lc * l_kc; + /* + * If Sigma pi, solid < sigma pi, aq, then use eqns + */ + if (sigmapi_solid < sigmapi_aq) + { + s_s_ptr->s_s_in = TRUE; + } + else + { + s_s_ptr->s_s_in = FALSE; + } + } + else + { + /* + * Calculate total mole fraction from solution activities + */ + total_p = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) + { + phase_ptr = s_s_ptr->comps[j].phase; + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + for (rxn_ptr = s_s_ptr->comps[j].phase->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + total_p += exp(lp * LOG_10); + } + } + if (total_p > 1.0) + { + s_s_ptr->s_s_in = TRUE; + } + else + { + s_s_ptr->s_s_in = FALSE; + } + } + } + for (i = s_s_unknown->number; i < count_unknowns; i++) + { + if (x[i]->type != S_S_MOLES) + break; + x[i]->s_s_in = x[i]->s_s->s_s_in; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +molalities(int allow_overflow) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates la for master species + * Calculates lm and moles from lk, lg, and la's of master species + * Adjusts lm of h2 and o2. + */ + int i, j, count_g; + LDBLE total_g; + struct rxn_token *rxn_ptr; +/* + * la for master species + */ + for (i = 0; i < count_master; i++) + { + if (master[i]->in == REWRITE) + { + master[i]->s->la = master[i]->s->lm + master[i]->s->lg; + } + } + if (dl_type_x != NO_DL) + { + s_h2o->tot_g_moles = s_h2o->moles; + s_h2o->tot_dh2o_moles = 0.0; + } + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS && s_x[i]->type != EX + && s_x[i]->type != SURF) + continue; +/* + * lm and moles for all aqueous species + */ + s_x[i]->lm = s_x[i]->lk - s_x[i]->lg; + for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef; + /* + if (isnan(rxn_ptr->s->la)) + { + fprintf(stderr,"molalities la %s %e\n", rxn_ptr->s->name, rxn_ptr->s->la); + } + */ + } + if (s_x[i]->type == EX) + { + s_x[i]->moles = exp(s_x[i]->lm * LOG_10); + } + else if (s_x[i]->type == SURF) + { + s_x[i]->moles = exp(s_x[i]->lm * LOG_10); /* formerly * mass water */ + + } + else + { + s_x[i]->moles = under(s_x[i]->lm) * mass_water_aq_x; + //output_msg(sformatf("%s \t%e\n", s_x[i]->name, s_x[i]->moles)); + /* + if (_isnan(s_x[i]->moles)) + { + fprintf(stderr,"molalities moles %s %e\n", s_x[i]->name, s_x[i]->moles); + exit(4); + } + */ + if (s_x[i]->moles / mass_water_aq_x > 100) + { + log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", + s_x[i]->name, + (double) (s_x[i]->moles / mass_water_aq_x), + (double) s_x[i]->lm, iterations)); + + if (iterations >= 0 && allow_overflow == FALSE) + { + return (ERROR); + } + } + + } + } +/* + * other terms for diffuse layer model + */ + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->type == CD_MUSIC + && dl_type_x != NO_DL) + calc_all_donnan(); + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS && s_x[i]->type != EX + && s_x[i]->type != SURF) + continue; + if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL + && s_x[i]->type <= HPLUS) + { + total_g = 0.0; + s_x[i]->tot_dh2o_moles = 0.0; + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + count_g = s_x[i]->diff_layer[j].count_g; +/* + * partially corrected formulation assumes mass of water in diffuse layer + * is insignificant. Excess is calculated on the basis of moles_water_aq_x + * instead of moles_water_bulk. + */ + /* revised eq. 61 */ + s_x[i]->diff_layer[j].g_moles = + s_x[i]->moles * s_x[i]->erm_ddl * + (s_x[i]->diff_layer[j].charge->g[count_g].g + + s_x[i]->diff_layer[j].charge->mass_water / + mass_water_aq_x); + if (s_x[i]->moles > 1e-30) + { + s_x[i]->diff_layer[j].dg_g_moles = + s_x[i]->dg * s_x[i]->diff_layer[j].g_moles / + s_x[i]->moles; + } + + /* + * first term of 63 is summed for all surfaces in + * s_x[i]->tot_g_moles. This sum is then used in + * the jacobian for species i + */ + total_g += + s_x[i]->diff_layer[j].charge->g[count_g].g + + s_x[i]->diff_layer[j].charge->mass_water / + mass_water_aq_x; + + /* revised eq. 63, second term */ + /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ + s_x[i]->diff_layer[j].dx_moles = + s_x[i]->moles * s_x[i]->erm_ddl * + s_x[i]->diff_layer[j].charge->g[count_g].dg; + + /* revised eq. 63, third term */ + s_x[i]->diff_layer[j].dh2o_moles = + -s_x[i]->moles * s_x[i]->erm_ddl * + s_x[i]->diff_layer[j].charge->mass_water / + mass_water_aq_x; + s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; + + /* surface related to phase */ + s_x[i]->diff_layer[j].drelated_moles = + s_x[i]->moles * s_x[i]->erm_ddl * + use.Get_surface_ptr()->charge[j].specific_area * + use.Get_surface_ptr()->thickness / mass_water_aq_x; + } + s_x[i]->tot_g_moles = + s_x[i]->moles * (1 + total_g /* s_x[i]->erm_ddl */ ); + + /* note that dg is for cb, act water, mu eqns */ + /* dg_total_g for mole balance eqns */ + /* dg_g_moles for surface cb */ + + if (s_x[i]->moles > 1e-30) + { + s_x[i]->dg_total_g = + s_x[i]->dg * s_x[i]->tot_g_moles / s_x[i]->moles; + } + else + { + s_x[i]->dg_total_g = 0.0; + } + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( "%s\t%e\t%e\n", s_x[i]->name, + (double) s_x[i]->moles, + (double) s_x[i]->tot_g_moles)); + output_msg(sformatf( "\tg\n")); + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + count_g = s_x[i]->diff_layer[j].count_g; + output_msg(sformatf( "\t%e", + (double) s_x[i]->diff_layer[j].charge-> + g[count_g].g)); + } + output_msg(sformatf( "\n\tg_moles\n")); + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + output_msg(sformatf( "\t%e", + (double) s_x[i]->diff_layer[j].g_moles)); + } + output_msg(sformatf( "\n\tdg\n")); + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + count_g = s_x[i]->diff_layer[j].count_g; + output_msg(sformatf( "\t%e", + (double) s_x[i]->diff_layer[j].charge-> + g[count_g].dg)); + } + output_msg(sformatf( "\n\tdx_moles\n")); + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + output_msg(sformatf( "\t%e", + (double) s_x[i]->diff_layer[j].dx_moles)); + } + output_msg(sformatf( "\n\tdh2o_moles\t%e\n", + (double) s_x[i]->tot_dh2o_moles)); + for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + { + output_msg(sformatf( "\t%e", + (double) s_x[i]->diff_layer[j].dh2o_moles)); + } + output_msg(sformatf( "\n")); + } + } + } + + calc_gas_pressures(); + calc_s_s_fractions(); + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_gas_pressures(void) +/* ---------------------------------------------------------------------- */ +{ + int n_g = 0; + LDBLE lp, V_m = 0; + struct rxn_token *rxn_ptr; + //struct gas_comp *gas_comp_ptr; + //struct phase *phase_ptr; + //struct phase **phase_ptrs; + std::vector phase_ptrs; + bool PR = false, pr_done = false; +/* + * moles and partial pressures for gases + */ + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) + { + if (iterations > 2) + return calc_fixed_volume_gas_pressures(); + else + return OK; + } + if (iterations > 2 && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_moles(0); + } + + //phase_ptrs = new phase *[gas_phase_ptr->Get_gas_comps().size()]; + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + const cxxGasComp * gas_comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int j; + struct phase *phase_ptr = phase_bsearch(gas_comp_ptr->Get_phase_name().c_str(), &j, FALSE); + //phase_ptr = use.Get_gas_phase_ptr()->comps[i].phase; + if (phase_ptr->in == TRUE) + { + phase_ptrs.push_back(phase_ptr); + //phase_ptrs[i] = phase_ptr; + if (!PR && phase_ptr->t_c > 0 && phase_ptr->p_c > 0) + PR = true; + n_g++; + } + //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); + if (iterations > 2 && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + phase_ptr->moles_x); + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (PR /*&& gas_unknown->gas_phase->total_p > 1 */ && iterations > 2) + { + calc_PR(phase_ptrs, gas_phase_ptr->Get_total_p(), tk_x, 0); + } + } else + { + if (PR) + { + if (gas_phase_ptr->Get_total_moles() > 0) + { + V_m = gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles(); + if (V_m < 0.03) + { + V_m = 0.03; + } else if (V_m > 1e4) + { + V_m = 1e4; + } + if (gas_phase_ptr->Get_v_m() > 0.03) + { + if (V_m < 0.04) + V_m = (9. * gas_phase_ptr->Get_v_m() + V_m) / 10; + else if (V_m < 0.045) + V_m = (6. * gas_phase_ptr->Get_v_m() + V_m) / 7; + else if (V_m < 0.07) + V_m = (3. * gas_phase_ptr->Get_v_m() + V_m) / 4; + else + V_m = (1. * gas_phase_ptr->Get_v_m() + V_m) / 2; + } + if (iterations > 99) + { + //V_m *= 1; /* debug */ + numerical_fixed_volume = true; + switch_numerical = true; + warning_msg + ("Numerical method failed, switching to numerical derivatives."); + prep(); + switch_numerical = false; + } + } else + V_m = 1.0; + calc_PR(phase_ptrs, 0, tk_x, V_m); + pr_done = true; + + if (fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) + { + same_pressure = FALSE; + if (V_m < 0.07) + patm_x = (1. * patm_x + gas_phase_ptr->Get_total_p()) / 2; + else + patm_x = gas_phase_ptr->Get_total_p(); + k_temp(tc_x, patm_x); + } + } else + { + gas_phase_ptr->Set_total_p(0); + } + } + + gas_phase_ptr->Set_total_moles(0); + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + std::vector gas_comps; + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + const cxxGasComp *gas_comp = &(gas_phase_ptr->Get_gas_comps()[i]); + int j; + struct phase *phase_ptr = phase_bsearch(gas_comp->Get_phase_name().c_str(), &j, FALSE); + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + phase_ptr->p_soln_x = exp(LOG_10 * (lp - phase_ptr->pr_si_f)); + if (!strcmp(phase_ptr->name, "H2O(g)") && phase_ptr->p_soln_x > 90) + phase_ptr->p_soln_x = 90; + + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + phase_ptr->moles_x = phase_ptr->p_soln_x * + gas_unknown->moles / gas_phase_ptr->Get_total_p(); + phase_ptr->fraction_x = + phase_ptr->moles_x / gas_unknown->moles; + } + else + { + if (pr_done) + { + lp = phase_ptr->p_soln_x / gas_phase_ptr->Get_total_p() * + gas_phase_ptr->Get_volume() / V_m; + if (lp > 0) + phase_ptr->moles_x = lp; + if (iterations > 50) + { + lp *= 1.0; /* debug */ + } + } else + { + phase_ptr->moles_x = phase_ptr->p_soln_x * + gas_phase_ptr->Get_volume() / (R_LITER_ATM * tk_x); + gas_phase_ptr->Set_total_p(gas_phase_ptr->Get_total_p() + phase_ptr->p_soln_x); + } + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + + phase_ptr->moles_x); + } + } + else + { + phase_ptr->moles_x = 0; + phase_ptr->fraction_x = 0; + } + } + + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && !PR) + { + /* + * Fixed-volume gas phase reacting with a solution + * Change pressure used in logK to pressure of gas phase + */ + if (gas_phase_ptr->Get_total_p() > 1500) + { + gas_phase_ptr->Set_total_moles(0); + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); + //phase_ptr = use.Get_gas_phase_ptr()->comps[i].phase; + const cxxGasComp *gas_comp = &(gas_phase_ptr->Get_gas_comps()[i]); + int j; + struct phase *phase_ptr = phase_bsearch(gas_comp->Get_phase_name().c_str(), &j, FALSE); + if (phase_ptr->in == TRUE) + { + phase_ptr->moles_x *= 1500.0 / gas_phase_ptr->Get_total_p(); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + + phase_ptr->moles_x); + } + } + gas_phase_ptr->Set_total_p(1500.0); + } + if (iterations > 1 && fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) + { + same_pressure = FALSE; + if (gas_phase_ptr->Get_total_p() > 1e3) + patm_x = (3 * patm_x + gas_phase_ptr->Get_total_p()) / 4; + else + patm_x = (1 * patm_x + gas_phase_ptr->Get_total_p()) / 2; + k_temp(tc_x, patm_x); + } + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_s_s_fractions(void) +/* ---------------------------------------------------------------------- */ +{ + int i, k; + LDBLE moles, n_tot; + struct s_s *s_s_ptr; + +/* + * moles and lambdas for solid solutions + */ + if (s_s_unknown == NULL) + return (OK); +/* + * Calculate mole fractions and log lambda and derivative factors + */ + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[i]); + n_tot = 0; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + moles = s_s_ptr->comps[k].moles; + if (s_s_ptr->comps[k].moles < 0) + { + moles = MIN_TOTAL_SS; + s_s_ptr->comps[k].initial_moles = moles; + } + n_tot += moles; + } + s_s_ptr->total_moles = n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + moles = s_s_ptr->comps[k].moles; + if (s_s_ptr->comps[k].moles < 0) + { + moles = MIN_TOTAL_SS; + } + s_s_ptr->comps[k].fraction_x = moles / n_tot; + s_s_ptr->comps[k].log10_fraction_x = log10(moles / n_tot); + + /* all mb and jacobian items must be in x or phase to be static between models */ + s_s_ptr->comps[k].phase->log10_fraction_x = + s_s_ptr->comps[k].log10_fraction_x; + } + if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0) + { + s_s_binary(s_s_ptr); + } + else + { + s_s_ideal(s_s_ptr); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_s_binary(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE xb1, xc1; +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = s_s_ptr->total_moles; + + nc = s_s_ptr->comps[0].moles; + xc = nc / n_tot; + nb = s_s_ptr->comps[1].moles; + xb = nb / n_tot; +/* + * In miscibility gap + */ + l_a0 = s_s_ptr->a0; + l_a1 = s_s_ptr->a1; + if (s_s_ptr->miscibility == TRUE && xb > s_s_ptr->xb1 + && xb < s_s_ptr->xb2) + { + xb1 = s_s_ptr->xb1; + xc1 = 1.0 - xb1; + s_s_ptr->comps[0].fraction_x = xc1; + s_s_ptr->comps[0].log10_fraction_x = log10(xc1); + s_s_ptr->comps[0].phase->log10_fraction_x = + s_s_ptr->comps[0].log10_fraction_x; + + s_s_ptr->comps[1].fraction_x = xb1; + s_s_ptr->comps[1].log10_fraction_x = log10(xb1); + s_s_ptr->comps[1].phase->log10_fraction_x = + s_s_ptr->comps[1].log10_fraction_x; + + s_s_ptr->comps[0].log10_lambda = + xb1 * xb1 * (l_a0 - l_a1 * (3 - 4 * xb1)) / LOG_10; + s_s_ptr->comps[0].phase->log10_lambda = + s_s_ptr->comps[0].log10_lambda; + + s_s_ptr->comps[1].log10_lambda = + xc1 * xc1 * (l_a0 + l_a1 * (4 * xb1 - 1)) / LOG_10; + s_s_ptr->comps[1].phase->log10_lambda = + s_s_ptr->comps[1].log10_lambda; + + s_s_ptr->comps[0].dnb = 0; + s_s_ptr->comps[0].dnc = 0; + s_s_ptr->comps[1].dnb = 0; + s_s_ptr->comps[1].dnc = 0; + s_s_ptr->comps[0].phase->dnb = 0; + s_s_ptr->comps[0].phase->dnc = 0; + s_s_ptr->comps[1].phase->dnb = 0; + s_s_ptr->comps[1].phase->dnc = 0; + } + else + { +/* + * Not in miscibility gap + */ + s_s_ptr->comps[0].fraction_x = xc; + s_s_ptr->comps[0].log10_fraction_x = log10(xc); + s_s_ptr->comps[0].phase->log10_fraction_x = + s_s_ptr->comps[0].log10_fraction_x; + + s_s_ptr->comps[1].fraction_x = xb; + s_s_ptr->comps[1].log10_fraction_x = log10(xb); + s_s_ptr->comps[1].phase->log10_fraction_x = + s_s_ptr->comps[1].log10_fraction_x; + + s_s_ptr->comps[0].log10_lambda = + xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; + s_s_ptr->comps[0].phase->log10_lambda = + s_s_ptr->comps[0].log10_lambda; + + s_s_ptr->comps[1].log10_lambda = + xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; + s_s_ptr->comps[1].phase->log10_lambda = + s_s_ptr->comps[1].log10_lambda; + + xc2 = xc * xc; + xc3 = xc2 * xc; + xb2 = xb * xb; + xb3 = xb2 * xb; + xb4 = xb3 * xb; + + /* used derivation that did not substitute x2 = 1-x1 */ + + /* first component, df1/dn1 */ + dnc = 2 * l_a0 * xb2 + 12 * l_a1 * xc * xb2 + 6 * l_a1 * xb2; + s_s_ptr->comps[0].phase->dnc = -xb / nc + dnc / n_tot; + + + /* first component, df1/dn2 */ + dnb = + 1 - 2 * l_a0 * xb + 2 * l_a0 * xb2 + 8 * l_a1 * xc * xb - + 12 * l_a1 * xc * xb2 - 2 * l_a1 * xb + 2 * l_a1 * xb2; + s_s_ptr->comps[0].phase->dnb = dnb / n_tot; + + /* second component, df2/dn1 */ + dnc = + 1 - 2 * l_a0 * xc + 2 * l_a0 * xc2 - 8 * l_a1 * xb * xc + + 12 * l_a1 * xb * xc2 + 2 * l_a1 * xc - 2 * l_a1 * xc2; + s_s_ptr->comps[1].phase->dnc = dnc / n_tot; + + /* second component, df2/dn2 */ + dnb = 2 * l_a0 * xc2 + 12 * l_a1 * xb * xc2 - 6 * l_a1 * xc2; + s_s_ptr->comps[1].phase->dnb = -xc / nb + dnb / n_tot; + + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_s_ideal(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + int k, j; + LDBLE n_tot, n_tot1; + +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = s_s_ptr->total_moles; + +/* + * Ideal solid solution + */ + s_s_ptr->dn = 1.0 / n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + n_tot1 = 0; + for (j = 0; j < s_s_ptr->count_comps; j++) + { + if (j != k) + { + n_tot1 += s_s_ptr->comps[j].moles; + } + } + s_s_ptr->comps[k].log10_lambda = 0; + s_s_ptr->comps[k].phase->log10_lambda = 0; + + s_s_ptr->comps[k].dnb = -(n_tot1) / (s_s_ptr->comps[k].moles * n_tot); + s_s_ptr->comps[k].phase->dnb = s_s_ptr->comps[k].dnb; + + s_s_ptr->comps[k].dn = s_s_ptr->dn; + s_s_ptr->comps[k].phase->dn = s_s_ptr->dn; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reset(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks deltas (changes to unknowns) to make sure they are reasonable + * Scales deltas if necessary + * Updates unknowns with deltas + */ + + int i, j; + int converge; + LDBLE up, down; + LDBLE d; + LDBLE factor, f0; + LDBLE sum_deltas; + LDBLE step_up; + LDBLE mu_calc; + LDBLE old_moles; + int warning; +/* + * Calculate interphase mass transfers + */ + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblageComp * comp_ptr; + + step_up = log(step_size_now); + factor = 1.; + + if ((pure_phase_unknown != NULL || s_s_unknown != NULL) + && calculating_deriv == FALSE) + { +/* + * Don't take out more mineral than is present + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == PP || x[i]->type == S_S_MOLES) + { + + if (delta[i] < -1e8) + { + delta[i] = -10.; + } + else if (delta[i] > 1e8) + { + delta[i] = 10; + } + if (x[i]->dissolve_only == TRUE) + { + assert (x[i]->type == PP); + comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + assert(comp_ptr); + if ((delta[i] < 0.0) + && (-delta[i] > + (comp_ptr->Get_initial_moles() - x[i]->moles))) + { + if ((comp_ptr->Get_initial_moles() - x[i]->moles) != + 0.0) + { + f0 = fabs(delta[i] / + (comp_ptr->Get_initial_moles() - + x[i]->moles)); + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s, Precipitating too much dissolve_only mineral.\tDelta %e\tCurrent %e\tInitial %e\n", + x[i]->description, + (double) delta[i], + (double) x[i]->moles, + (double) comp_ptr->Get_initial_moles())); + } + factor = f0; + } + } + else + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s, Precipitating dissolve_only mineral.\tDelta %e\n", + x[i]->description, + (double) delta[i])); + } + delta[i] = 0; + } + } + } + if ( /* delta[i] > 0.0 && */ x[i]->moles > 0.0 + && delta[i] > x[i]->moles) + { + f0 = delta[i] / x[i]->moles; + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s, Removing more than total mineral.\t%f\n", + x[i]->description, (double) f0)); + } + factor = f0; + } + } + else if (delta[i] > 0.0 && x[i]->moles <= 0.0) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s\tDelta: %e\tMass: %e " + "Dissolving mineral with 0.0 mass.\n ", + x[i]->description, (double) delta[i], + (double) x[i]->moles)); + } + delta[i] = 0.0; + } + else if (x[i]->s_s_comp != NULL && delta[i] < -x[i]->s_s_comp->phase->delta_max) + // Uses delta_max computed in step + // delta_max is the maximum amount of the mineral that could form based + // on the limiting element in the system + { + f0 = -delta[i] / x[i]->s_s_comp->phase->delta_max; + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s, Precipitating too much mineral.\t%f\n", + x[i]->description, (double) f0)); + } + factor = f0; + } + } + } + } + } +/* + * Calculate change in element concentrations due to pure phases and gases + */ + warning = 0; + for (i = 0; i < count_unknowns; i++) + { + + /*if (isnan(delta[i]))*/ + if (!PHR_ISFINITE((double) delta[i])) + { + warning ++; + delta[i] = 0; + } + + } + if (warning > 0) + { + error_string = sformatf( "%d delta equal NaN\n", warning); + warning_msg(error_string); + } + if (pure_phase_unknown != NULL || gas_unknown != NULL + || s_s_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + x[i]->delta = 0.0; + } + + for (i = 0; i < count_sum_delta; i++) + { + *sum_delta[i].target += *sum_delta[i].source * sum_delta[i].coef; + } + +/* + * Apply factor from minerals to deltas + */ + + + for (i = 0; i < count_unknowns; i++) + { + x[i]->delta /= factor; + if (x[i]->type == PP || x[i]->type == S_S_MOLES) + delta[i] /= factor; + } + + } + + +/* + * Calc factor for mass balance equations for aqueous unknowns + */ + factor = 1.0; + sum_deltas = 0.0; + for (i = 0; i < count_unknowns; i++) + + { + /* fixes underflow problem on Windows */ + if (delta[i] > 0) + { + sum_deltas += delta[i]; + } + else + { + sum_deltas -= delta[i]; + + } + /*sum_deltas += fabs(delta[i]); */ + if (calculating_deriv == FALSE) + { + up = step_up; + down = up; + if (x[i]->type <= SOLUTION_PHASE_BOUNDARY) + { + up = step_up; + down = 1.3 * up; + } + else if (x[i]->type == MU) + { + up = 100 * mu_x; + down = mu_x; + } + else if (x[i]->type == AH2O) + { + down = up; + } + else if (x[i]->type == MH) + { + up = log(pe_step_size_now); + down = 1.3 * up; + } + else if (x[i]->type == MH2O) + { + /* ln gH2O + delta; ln(gH2O*delta); */ + /* + up = log(10.); + down = log(4.); + */ + up = log(1.3); + down = log(1.2); + + } + else if (x[i]->type == PP) + { + continue; + } + else if (x[i]->type == GAS_MOLES) + { + up = 1000. * x[i]->moles; + if (up <= 0.0) + up = 1e-1; + if (up >= 1.0) + up = 1.; + down = x[i]->moles; + } + else if (x[i]->type == S_S_MOLES) + { + continue; + } + else if (x[i]->type == EXCH) + { + up = step_up; + down = 1.3 * up; + } + else if (x[i]->type == SURFACE) + { + up = step_up; + down = 1.3 * up; + } + else if (x[i]->type == PITZER_GAMMA) + { + up = step_up; + if (up > 1) + { + up = 0.7; + } + down = 1.3 * up; + } + else if (x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + { + up = step_up; + down = 1.3 * up; + /* + up = 1.3; + down = 1.2; + */ + } + + if (delta[i] > 0.0) + { + f0 = delta[i] / up; + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( "%-10.10s\t%f\n", + x[i]->description, (double) f0)); + } + factor = f0; + } + } + else + { + f0 = delta[i] / (-down); + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( "%-10.10s\t%f\n", + x[i]->description, (double) f0)); + } + factor = f0; + } + } + } + } + + /*converge=TRUE; */ + + if (debug_model == TRUE) + { + output_msg(sformatf( "\nSum of deltas: %12.6f\n", + (double) sum_deltas)); + output_msg(sformatf( "Factor: %12.4e\n", (double) factor)); + } + factor = 1.0 / factor; + + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PP && x[i]->type != S_S_MOLES) + delta[i] *= factor; + } + + warning = 0; + for (i = 0; i < count_unknowns; i++) + { + + /*if (isnan(delta[i]))*/ + if (!PHR_ISFINITE((double) delta[i])) + { + warning ++; + delta[i] = 0; + } + + } + if (warning > 0) + { + error_string = sformatf( "%d delta equal NaN after scaling\n", warning); + warning_msg(error_string); + } +/* + * Solution mass balances: MB, ALK, CB, SOLUTION_PHASE_BOUNDARY + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB || x[i]->type == ALK || x[i]->type == EXCH + || x[i]->type == SURFACE) + { + /*if ( fabs(delta[i]) >= epsilon ) converge = FALSE; */ + d = delta[i] / LOG_10; + /* surface */ + if (x[i]->type == SURFACE) + { + old_moles = x[i]->moles; + if (x[i]->phase_unknown != NULL) + { + x[i]->moles = x[i]->surface_comp->phase_proportion * + (x[i]->phase_unknown->moles - + delta[x[i]->phase_unknown->number]); + if (x[i]->phase_unknown->moles - + delta[x[i]->phase_unknown->number] <= + MIN_RELATED_SURFACE) + { + x[i]->moles = 0.0; + if (fabs(x[i]->f) > MIN_RELATED_SURFACE) + { + x[i]->master[0]->s->la -= 5.; + } + } + if (old_moles <= 0 && x[i]->moles > 0) + { + x[i]->master[0]->s->la = log10(x[i]->moles) - 5.; + } + } + else if (x[i]->surface_comp->phase_name != NULL) + { + /* probably initial surface calculation */ + if (x[i]->moles <= MIN_RELATED_SURFACE) + { + x[i]->moles = 0.0; + if (fabs(x[i]->f) > MIN_RELATED_SURFACE) + { + x[i]->master[0]->s->la -= 5.; + } + } + } + } + /* exch */ + if (x[i]->type == EXCH && x[i]->moles <= MIN_RELATED_SURFACE) + { + x[i]->moles = 0.0; + if (fabs(x[i]->f) > MIN_RELATED_SURFACE) + { + x[i]->master[0]->s->la -= 5.; + } + } + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e " + "%-8s%10.2e\n", x[i]->description, "old la", + (double) x[i]->master[0]->s->la, "new la", + (double) x[i]->master[0]->s->la + (double) d, + "delta", (double) delta[i], "delta/c", (double) d)); + } + x[i]->master[0]->s->la += d; + if (x[i]->master[0]->s->la < (double) (DBL_MIN_10_EXP + 10)) + x[i]->master[0]->s->la = (double) (DBL_MIN_10_EXP + 10); + +/* + * Surface charge balance + */ + + } + else if (x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + { + d = delta[i] / LOG_10; + if (x[i]->phase_unknown != NULL) + { + x[i]->surface_charge->grams = /* !!!! x[i]->surface_comp->phase_proportion * */ + (x[i]->phase_unknown->moles - + delta[x[i]->phase_unknown->number]); + if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) + { + x[i]->surface_charge->grams = 0.0; + } + } + if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) + { + x[i]->surface_charge->grams = 0.0; + } + x[i]->related_moles = x[i]->surface_charge->grams; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", + x[i]->description, "old f*psi", + (double) x[i]->master[0]->s->la, "new f*psi", + (double) x[i]->master[0]->s->la + (double) d, + "delta", (double) d)); + } + + x[i]->master[0]->s->la += d; + + /* recalculate g's for component */ + if (dl_type_x != NO_DL + && (use.Get_surface_ptr()->type == DDL + || (use.Get_surface_ptr()->type == CD_MUSIC + && x[i]->type == SURFACE_CB2))) + { + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "\ncharge, old g, new g, dg*delta," + " dg, delta\n")); + } + for (j = 0; j < x[i]->surface_charge->count_g; j++) + { + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "%12f\t%12.4e\t%12.4e\t%12.4e\t%12.4e\t%12.4e\n", + (double) x[i]->surface_charge->g[j]. + charge, + (double) x[i]->surface_charge->g[j].g, + (double) x[i]->surface_charge->g[j].g + + (double) (x[i]->surface_charge->g[j].dg * + delta[i]), + (double) (x[i]->surface_charge->g[j].dg * + delta[i]), + (double) x[i]->surface_charge->g[j].dg, + (double) delta[i])); + } + if (use.Get_surface_ptr()->dl_type != DONNAN_DL) + { + x[i]->surface_charge->g[j].g += + x[i]->surface_charge->g[j].dg * delta[i]; + } + } + if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + { + calc_all_donnan(); + } + } + +/* Solution phase boundary */ + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + d = delta[i] / LOG_10; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old la", + (double) x[i]->master[0]->s->la, "new la", + (double) (x[i]->master[0]->s->la + d), "delta", + (double) delta[i], "delta/c", (double) d)); + } + x[i]->master[0]->s->la += d; +/* Charge balance */ + } + else if (x[i]->type == CB) + { + /*if (fabs(delta[i]) > epsilon * mu_x * mass_water_aq_x ) converge=FALSE; */ + d = delta[i] / LOG_10; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old la", + (double) x[i]->master[0]->s->la, "new la", + (double) (x[i]->master[0]->s->la + d), "delta", + (double) delta[i], "delta/c", (double) d)); + } + x[i]->master[0]->s->la += d; +/* Ionic strength */ + } + else if (x[i]->type == MU) + { + + /*if (fabs(delta[i]) > epsilon * mu_x ) converge=FALSE; */ + // using straight ionic strength equation + { + mu_calc = 0.5 * mu_unknown->f / mass_water_aq_x; + } + if (debug_model == TRUE) + { + output_msg(sformatf( "Calculated mu: %e\n", + (double) mu_calc)); + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e\n", + x[i]->description, "old mu", (double) mu_x, + "new mu", (double) (mu_x + delta[i]), "delta", + (double) delta[i])); + } + d = mu_x + delta[i]; + if (d < 1e-7) + { + delta[i] = sqrt(mu_calc * mu_x) - mu_x; + mu_x = sqrt(mu_calc * mu_x); + } + else + { + mu_x += delta[i]; + if (patm_x > 1 && fabs(delta[i]) > 1e-3 * mu_x) + { + same_model = false; + k_temp(tc_x, patm_x); + } + } + //if (mu_x > 50) mu_x = 50; + if (mu_x <= 1e-8) + { + mu_x = 1e-8; + } +/* Activity of water */ + } + else if (x[i]->type == AH2O) + { + /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue; */ + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + d = delta[i] / LOG_10; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old la", + (double) x[i]->master[0]->s->la, "new la", + (double) (x[i]->master[0]->s->la + d), "delta", + (double) delta[i], "delta/c", (double) d)); + } + s_h2o->la += d; +/* pe */ + } + else if (x[i]->type == MH) + { + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + d = delta[i] / LOG_10; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old pe", + (double) x[i]->master[0]->s->la, "new pe", + (double) (x[i]->master[0]->s->la + d), "delta", + (double) delta[i], "delta/c", (double) d)); + } + s_eminus->la += d; +/* Mass of water */ + } + else if (x[i]->type == MH2O) + { + if (mass_water_switch == TRUE) + continue; + /*if (fabs(delta[i]) > epsilon * mass_water_aq_x) converge=FALSE; */ + /* ln(gh2o) + delta, log(gh2o) + d, gh2o * 10**d */ + d = exp(delta[i]); + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old MH2O", + (double) mass_water_aq_x, "new MH2O", + (double) (mass_water_aq_x * d), "delta", + (double) delta[i], "10**d/c", (double) d)); + } + mass_water_aq_x *= d; + + mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; + if (debug_model == TRUE && dl_type_x != NO_DL) + { + output_msg(sformatf( + "mass_water bulk: %e\taq: %e\tsurfaces: %e\n", + (double) mass_water_bulk_x, + (double) mass_water_aq_x, + (double) mass_water_surfaces_x)); + } + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; +/*appt */ + if (use.Get_surface_ptr() != NULL) + { + if (use.Get_surface_ptr()->debye_lengths > 0) + x[i]->master[0]->s->moles = mass_water_bulk_x / gfw_water; + } + + if (mass_water_aq_x < 1e-10) + { + error_string = sformatf( + "Mass of water is less than 1e-10 kilogram.\n" + "The aqueous phase may not be stable relative to given masses of minerals."); + warning_msg(error_string); + stop_program = TRUE; + return (TRUE); + } +/* Pure phases */ + } + else if (x[i]->type == PP) + { + comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mass", + (double) x[i]->moles, "new mass", + (double) (x[i]->moles - delta[i]), "delta", + (double) delta[i])); + } + if (equal(x[i]->moles, delta[i], ineq_tol)) + { + x[i]->moles = 0.0; + } + else + { + x[i]->moles -= delta[i]; + } + + if (x[i]->dissolve_only == TRUE) + { + if (equal + (x[i]->moles, comp_ptr->Get_initial_moles(), ineq_tol)) + x[i]->moles = comp_ptr->Get_initial_moles(); + } + /*if (fabs(x[i]->moles) < MIN_RELATED_SURFACE) x[i]->moles = 0.0; */ + } + else if (x[i]->type == GAS_MOLES) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + /*if (gas_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE; */ + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mol", + (double) x[i]->moles, "new mol", + (double) (x[i]->moles + delta[i]), "delta", + (double) delta[i])); + } + x[i]->moles += delta[i]; + if (x[i]->moles < MIN_TOTAL) + x[i]->moles = MIN_TOTAL; + + if (x[i] == gas_unknown && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) + && numerical_fixed_volume && !calculating_deriv) + { + patm_x = gas_phase_ptr->Get_total_p(); + k_temp(tc_x, patm_x); + } + + } + else if (x[i]->type == S_S_MOLES) + { + + /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ + /*if (x[i]->s_s_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE; */ + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mol", + (double) x[i]->moles, "new mol", + (double) (x[i]->moles - delta[i]), "delta", + (double) delta[i])); + } + x[i]->moles -= delta[i]; + if (x[i]->moles < MIN_TOTAL_SS && calculating_deriv == FALSE) + x[i]->moles = MIN_TOTAL_SS; + x[i]->s_s_comp->moles = x[i]->moles; +/* Pitzer gamma */ + } + else if (x[i]->type == PITZER_GAMMA) + { + if (full_pitzer == FALSE) + continue; + d = delta[i]; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.5f %-9s%10.5f %-6s%10.2e %-8s%10.2e\n", + x[i]->description, "old lg", (double) x[i]->s->lg, + "new lg", (double) (x[i]->s->lg + d), "delta", + (double) delta[i], "delta", (double) d)); + } + x[i]->s->lg += d; + } + } +/* + * Reset total molalities in mass balance equations + */ + if (pure_phase_unknown != NULL || gas_unknown != NULL + || s_s_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB || x[i]->type == MH || + x[i]->type == MH2O || + x[i]->type == CB || x[i]->type == EXCH + || x[i]->type == SURFACE) + { + /*if (fabs(x[i]->delta) > epsilon*x[i]->moles) converge = FALSE; */ + if (x[i]->type == SURFACE) + x[i]->delta = 0.0; + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + x[i]->description, "old mole", + (double) x[i]->moles, "new mole", + (double) (x[i]->moles + x[i]->delta), "delta", + (double) x[i]->delta)); + } + x[i]->moles += x[i]->delta; + } + } + } + converge = FALSE; + return (converge); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +residuals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates residuals for all equations + */ + int i, j; + int converge; + + LDBLE l_toler; + LDBLE sum_residual; + LDBLE sinh_constant; + LDBLE sum, sum1; + struct master *master_ptr, *master_ptr1, *master_ptr2; + LDBLE sigmaddl, negfpsirt; + int print_fail; + + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + print_fail = FALSE; + sum_residual = 0.0; + sigmaddl = 0; + sum = 0; +/* + * Calculate residuals + */ + converge = TRUE; + l_toler = convergence_tolerance; + + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB) + { + residual[i] = x[i]->moles - x[i]->f; + if ((fabs(residual[i]) > l_toler * x[i]->moles + && x[i]->moles > MIN_TOTAL) || x[i]->moles < 0) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == ALK) + { + residual[i] = x[i]->moles - x[i]->f; + if (fabs(residual[i]) > l_toler * x[i]->moles) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + residual[i] = x[i]->f * LOG_10; + if (fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == CB) + { + residual[i] = -x[i]->f; + if (ph_unknown == charge_balance_unknown) + { + residual[i] += x[i]->moles; + } + if (fabs(residual[i]) >= l_toler * mu_x * mass_water_aq_x) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == MU && pitzer_model == FALSE && sit_model == FALSE) + { + // Using straight ionic strength equation + { + residual[i] = mass_water_aq_x * mu_x - 0.5 * x[i]->f; + } + if (fabs(residual[i]) > l_toler * mu_x * mass_water_aq_x) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == AH2O) + { + /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue; */ + if (dampen_ah2o) + { + // a = 0.017; Y = sum(m(i)); X = Mw (mass of water) + // Aw = (1 - a y/x) 0.5 (tanh(100 (0.95 - ay/x)) + 1) + 0.05 (0.5 (1 - tanh(100(0.95 - ay/x)))) + residual[i] = exp(s_h2o->la * LOG_10) - ((1.0 - 0.017 * x[i]->f/mass_water_aq_x) * + 0.5*(tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)) + 1) + + 0.05*0.5*(1.0 - tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)))) ; + } + else + { + residual[i] = mass_water_aq_x * exp(s_h2o->la * LOG_10) - mass_water_aq_x + + 0.017 * x[i]->f; + } + + if (pitzer_model || sit_model) + { + residual[i] = pow((LDBLE) 10.0, s_h2o->la) - AW; + if (full_pitzer == FALSE) + { + residual[i] = 0.0; + } + } + if (fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == MH + && (pitzer_model == FALSE || pitzer_pe == TRUE)) + { +#ifdef COMBINE + residual[i] = x[i]->moles - x[i]->f; +#else + residual[i] = (x[i]->moles - 2 * s_h2o->moles) - x[i]->f; + x[i]->f += 2 * s_h2o->moles; +#endif + if (mass_water_switch == TRUE) + { + residual[i] -= + 2 * (mass_oxygen_unknown->moles - mass_oxygen_unknown->f); + } +#ifdef COMBINE +#ifndef COMBINE_CHARGE + if (fabs(residual[i]) > + l_toler * (x[i]->moles + 2 * mass_oxygen_unknown->moles)) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } +#else + if (fabs(residual[i]) > + l_toler * (x[i]->moles + 2 * mass_oxygen_unknown->moles + + charge_balance_unknown->moles)) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } +#endif +#else + if (fabs(residual[i]) > l_toler * x[i]->moles) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } +#endif + } + else if (x[i]->type == MH2O) + { + if (mass_water_switch == TRUE) + continue; +#ifdef COMBINE + residual[i] = x[i]->moles - x[i]->f; +#else + residual[i] = (x[i]->moles - s_h2o->moles) - x[i]->f; + x[i]->f += s_h2o->moles; +#endif + if (fabs(residual[i]) > 0.01 * l_toler * x[i]->moles) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == PP) + { + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + residual[i] = x[i]->f * LOG_10; + if (comp_ptr->Get_add_formula().size() == 0) + { + if (x[i]->dissolve_only == TRUE) + { + if ((residual[i] > l_toler && x[i]->moles > 0.0) + || (residual[i] < -l_toler + && (comp_ptr->Get_initial_moles() - + x[i]->moles) > 0)) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", + iterations, x[i]->description, i, + residual[i])); + converge = FALSE; + } + } + else + { + if (residual[i] < -l_toler || iterations < 1) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", + iterations, x[i]->description, i, + residual[i])); + converge = FALSE; + } + } + } + else + { + /* if (x[i]->moles > 0.0 && fabs(residual[i]) > l_toler) converge = FALSE; */ + if (residual[i] < -l_toler || iterations < 1) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", + iterations, x[i]->description, i, + residual[i])); + converge = FALSE; + } + } + } + else if (x[i]->type == GAS_MOLES) + { + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) + { + residual[i] = x[i]->moles - x[i]->phase->moles_x; + } + else + { + //residual[i] = x[i]->gas_phase->total_p - x[i]->f; + residual[i] = gas_phase_ptr->Get_total_p() - x[i]->f; + } + + if (fabs(residual[i]) > l_toler && gas_in == TRUE) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == S_S_MOLES) + { + residual[i] = x[i]->f * LOG_10; + //if (x[i]->moles <= MIN_TOTAL_SS && iterations > 2) + // continue; + if (fabs(residual[i]) > l_toler && x[i]->s_s_in == TRUE) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == EXCH) + { + residual[i] = x[i]->moles - x[i]->f; + if (x[i]->moles <= MIN_RELATED_SURFACE) + { + if (fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", + iterations, x[i]->description, i, + residual[i])); + converge = FALSE; + } + } + else if (fabs(residual[i]) > l_toler * x[i]->moles) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SURFACE) + { + residual[i] = x[i]->moles - x[i]->f; + if (x[i]->moles <= MIN_RELATED_SURFACE) + { + if (fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", + iterations, x[i]->description, i, + residual[i])); + converge = FALSE; + } + } + else if (fabs(residual[i]) < ineq_tol && fabs(residual[i]) < 1e-2*x[i]->moles) + { + } + else if (fabs(residual[i]) > l_toler * x[i]->moles) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == PITZER_GAMMA) + { + if (full_pitzer == FALSE) + continue; + residual[i] = x[i]->s->lg - x[i]->s->lg_pitzer; + if (fabs(residual[i]) > l_toler) + { + /* + fprintf(stderr,"Residuals %d: %s %d %e\n", iterations, x[i]->description, i, residual[i]); + */ + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->type == DDL) + { + /*sinh_constant = 0.1174; */ + sinh_constant = + sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + tk_x * 1000); +/* if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { */ + if (x[i]->surface_charge->grams == 0) + { + residual[i] = 0.0; + } + else if (dl_type_x != NO_DL) + { + residual[i] = -x[i]->f; + } + else + { +/* + * sinh_constant is (8 e e0 R T 1000)**1/2 + * = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*t_x*1000) + * ~ 0.1174 at 25C + */ + residual[i] = + sinh_constant * sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10) - + x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + } + if (debug_model == TRUE) + { + output_msg(sformatf( "Charge/Potential\n")); + if (x[i]->surface_charge->grams > 0) + { + output_msg(sformatf( + "\tSum of surface charge %e eq\n", + (double) (x[i]->f + /* F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams) */ + ))); + } + else + { + output_msg(sformatf( "\tResidual %e\n", + (double) x[i]->f)); + } + output_msg(sformatf( "\t grams %g\n", + (double) x[i]->surface_charge->grams)); + output_msg(sformatf( "\tCharge from potential %e eq\n", + (double) (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams / F_C_MOL * + sinh_constant * sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10)))); + output_msg(sformatf( "\t FPsi/2RT %e\n", + (double) (x[i]->master[0]->s->la * LOG_10))); + output_msg(sformatf( "\t Sinh(FPsi/2RT) %e\n", + sinh(x[i]->master[0]->s->la * LOG_10))); + output_msg(sformatf( "\t Cosh(FPsi/2RT) %e\n", + cosh(x[i]->master[0]->s->la * LOG_10))); + output_msg(sformatf( "\t Sqrt(mu_x) %e\n", + sqrt(mu_x))); + } + if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + && fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SURFACE_CB + && use.Get_surface_ptr()->type == CD_MUSIC) + { + if (x[i]->surface_charge->grams == 0) + { + residual[i] = 0.0; + } + else + { + /* sum is in moles of charge */ + /*psi = pow(10, x[i]->surface_charge->psi_master->s->la); */ /* = exp(-Fpsi/RT) */ + master_ptr = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI); + master_ptr1 = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI1); + master_ptr2 = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI2); + x[i]->surface_charge->psi = + -(master_ptr->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ; + x[i]->surface_charge->psi1 = + -(master_ptr1->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ; + x[i]->surface_charge->psi2 = + -(master_ptr2->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ; + sum = 0; + for (j = 0; j < x[i]->count_comp_unknowns; j++) + { + sum += + x[i]->comp_unknowns[j]->moles * + x[i]->comp_unknowns[j]->master[0]->s->z; + } + x[i]->surface_charge->sigma0 = + (x[i]->f + + sum) * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + /* f is in moles */ + /* eqns A-3 */ + residual[i] = + x[i]->surface_charge->sigma0 - + x[i]->surface_charge->capacitance[0] * + (x[i]->surface_charge->psi - x[i]->surface_charge->psi1); + } + if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + && fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual A %d: %s %d %e\n", + iterations, x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SURFACE_CB1) + { + if (x[i]->surface_charge->grams == 0) + { + residual[i] = 0.0; + } + else + { + /* eqns A-4 */ + /*psi = pow(10, x[i]->surface_charge->psi_master1->s->la); */ /* = exp(-Fpsi/RT) */ + x[i]->surface_charge->sigma1 = + x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + residual[i] = + (x[i]->surface_charge->sigma0 + + x[i]->surface_charge->sigma1) - + x[i]->surface_charge->capacitance[1] * + (x[i]->surface_charge->psi1 - x[i]->surface_charge->psi2); + } + if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + && fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual B %d: %s %d %e\n", + iterations, x[i]->description, i, residual[i])); + converge = FALSE; + } + } + else if (x[i]->type == SURFACE_CB2) + { + if (x[i]->surface_charge->grams == 0) + { + residual[i] = 0.0; + } + else if (dl_type_x != NO_DL) + { + sum = 0; + sum1 = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type == SURF) + { + sum += under(s_x[j]->lm) * s_x[j]->dz[2]; + } + if (s_x[j]->type < H2O) + { + sum1 += s_x[j]->z * s_x[j]->diff_layer->g_moles; + } + } + x[i]->surface_charge->sigma2 = + sum * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + x[i]->surface_charge->sigmaddl = + (x[i]->f - + sum) * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + + residual[i] = + x[i]->f + (x[i]->surface_charge->sigma0 + + x[i]->surface_charge->sigma1) * + (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams) / F_C_MOL; + /* residual[i] = sum + (x[i]->surface_charge->sigma0 + x[i]->surface_charge->sigma1) * (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams) / F_C_MOL */ + } + else + { + /* eqns A-6 and A-7 */ + sinh_constant = + sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + tk_x * 1000); + /* + * sinh_constant is (8 e e0 R T 1000)**1/2 + * = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*t_x*1000) + * ~ 0.1174 at 25C + */ + master_ptr2 = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI2); + negfpsirt = master_ptr2->s->la * LOG_10; + sum = 0; + sum1 = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type < H2O) + { + sum += + under(s_x[j]->lm) * + (exp(s_x[j]->z * negfpsirt) - 1); + sum1 += under(s_x[j]->lm) * s_x[j]->z; + } + } + + /* add fictitious monovalent ion that balances charge */ + sum += fabs(sum1) * (exp(-sum1 / fabs(sum1) * negfpsirt) - 1); + + if (sum < 0) + { + sum = -sum; + { + if (print_fail) + output_msg(sformatf( + "Failed Residual C %d: %s %d %e %e\n", + iterations, x[i]->description, i, sum, + l_toler)); + converge = FALSE; + } + /*output_msg(sformatf( "Negative sum, iteration %d\n", iterations)); */ + } + x[i]->surface_charge->sigma2 = + x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * + x[i]->surface_charge->grams); + if ((negfpsirt) < 0) + { + sigmaddl = -0.5 * sinh_constant * sqrt(sum); + } + else + { + sigmaddl = 0.5 * sinh_constant * sqrt(sum); + } + x[i]->surface_charge->sigmaddl = sigmaddl; + residual[i] = + (x[i]->surface_charge->sigma0 + + x[i]->surface_charge->sigma1 + + x[i]->surface_charge->sigma2) + sigmaddl; + } + if (debug_model == TRUE) + { + master_ptr = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI); + master_ptr1 = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI1); + master_ptr2 = + surface_get_psi_master(x[i]->surface_charge->name, + SURF_PSI2); + output_msg(sformatf( "CD_music Charge/Potential 2\n")); + output_msg(sformatf( "\tgrams %g\n", + (double) x[i]->surface_charge->grams)); + output_msg(sformatf( "\tCapacitances %g\t%g\n", + (double) x[i]->surface_charge->capacitance[0], + x[i]->surface_charge->capacitance[1])); + output_msg(sformatf( "\t-F/(RT) %g\n", + (double) -F_KJ_V_EQ / (R_KJ_DEG_MOL * tk_x))); + output_msg(sformatf( "\tResidual 0 %14e\n", + (double) residual[master_ptr->unknown->number])); + output_msg(sformatf( "\tResidual 1 %14e\n", + (double) residual[master_ptr1->unknown->number])); + output_msg(sformatf( "\tResidual 2 %14e\n", + (double) residual[master_ptr2->unknown->number])); + output_msg(sformatf( "\texp(-FPsi0/RT) %14e", + (double) pow((LDBLE) 10., master_ptr->s->la))); + output_msg(sformatf( "\tPsi0 %14e\n", + (double) x[i]->surface_charge->psi)); + output_msg(sformatf( "\texp(-FPsi1/RT) %14e", + (double) pow((LDBLE) 10., master_ptr1->s->la))); + output_msg(sformatf( "\tPsi1 %14e\n", + (double) x[i]->surface_charge->psi1)); + output_msg(sformatf( "\texp(-FPsi2/RT) %14e", + (double) pow((LDBLE) 10., master_ptr2->s->la))); + output_msg(sformatf( "\tPsi2 %14e\n", + (double) x[i]->surface_charge->psi2)); + output_msg(sformatf( "\tf 0 %14e", + (double) master_ptr->unknown->f)); + output_msg(sformatf( "\tsigma 0 %14e\n", + (double) x[i]->surface_charge->sigma0)); + output_msg(sformatf( "\tf 1 %14e", + (double) master_ptr1->unknown->f)); + output_msg(sformatf( "\tsigma 1 %14e\n", + (double) x[i]->surface_charge->sigma1)); + output_msg(sformatf( "\tf 2 %14e", + (double) master_ptr2->unknown->f)); + output_msg(sformatf( "\tsigma 2 %14e\n", + (double) x[i]->surface_charge->sigma2)); + output_msg(sformatf( "\tsigma ddl %14e\n", + (double) sigmaddl)); + output_msg(sformatf( "\texp sum %14e\n", + (double) sum)); + + } + if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + && fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual D %d: %s %d %e\n", + iterations, x[i]->description, i, residual[i])); + converge = FALSE; + } + } +/* + * Store residuals in array + */ + array[(i + 1) * (count_unknowns + 1) - 1] = residual[i]; + sum_residual += fabs(residual[i]); + } +/* + * Return + */ + if ((pitzer_model == TRUE || sit_model == TRUE) && iterations < 1) + return (OK); + if (converge == TRUE) + { + return (CONVERGED); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set(int initial) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets initial guesses for unknowns if initial == TRUE + * Revises guesses whether initial is true or not + */ + int i; + struct solution *solution_ptr; +/* + * Set initial log concentrations to zero + */ + if (pitzer_model == TRUE) + return (set_pz(initial)); + if (sit_model == TRUE) + return (set_sit(initial)); + iterations = -1; + solution_ptr = use.Get_solution_ptr(); + for (i = 0; i < count_s_x; i++) + { + s_x[i]->lm = LOG_ZERO_MOLALITY; + s_x[i]->lg = 0.0; + } +/* + * Set master species activities + */ + + tc_x = solution_ptr->tc; + tk_x = tc_x + 273.15; + + patm_x = solution_ptr->patm; + +/* + * H+, e-, H2O + */ + mass_water_aq_x = solution_ptr->mass_water; + mu_x = solution_ptr->mu; + s_h2o->moles = mass_water_aq_x / gfw_water; + s_h2o->la = log10(solution_ptr->ah2o); + s_hplus->la = -solution_ptr->ph; + s_hplus->lm = s_hplus->la; + s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; + s_eminus->la = -solution_ptr->solution_pe; + if (initial == TRUE) + initial_guesses(); + if (dl_type_x != NO_DL) + initial_surface_water(); + revise_guesses(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +initial_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make initial guesses for activities of master species and + * ionic strength + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.Get_solution_ptr(); + mu_x = + s_hplus->moles + + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + mu_x /= mass_water_aq_x; + s_h2o->la = 0.0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type < CB) + { + mu_x += + x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * + x[i]->master[0]->s->z; + x[i]->master[0]->s->la = log10(x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == CB) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == EXCH) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(x[i]->moles); + } + } + else if (x[i]->type == SURFACE) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); + } + } + else if (x[i]->type == SURFACE_CB) + { + x[i]->master[0]->s->la = 0.0; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +revise_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Revise la's of master species + */ + int i; + int l_iter, max_iter, repeat, fail; + LDBLE weight, f; + LDBLE d; + + max_iter = 10; + gammas(mu_x); + l_iter = 0; + repeat = TRUE; + fail = FALSE;; + while (repeat == TRUE) + { + l_iter++; + if (debug_set == TRUE) + { + output_msg(sformatf( "\nBeginning set iteration %d.\n", + l_iter)); + } + if (l_iter == max_iter + 1) + { + log_msg(sformatf( + "Did not converge in set, iteration %d.\n", + iterations)); + fail = TRUE; + } + if (l_iter > 2 * max_iter) + { + log_msg(sformatf( + "Did not converge with relaxed criteria in set.\n")); + return (OK); + } + molalities(TRUE); + mb_sums(); + if (state < REACTION) + { + sum_species(); + } + else + { + for (i = 0; i < count_unknowns; i++) + { + x[i]->sum = x[i]->f; + } + } +/* debug + if (debug_set == TRUE) { + pr.species = TRUE; + pr.all = TRUE; + print_species(); + } + */ + repeat = FALSE; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type == MB || +/* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || x[i]->type == SURFACE) + { + + if (debug_set == TRUE) + { + output_msg(sformatf( + "\n\t%5s at beginning of set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + if (fabs(x[i]->moles) < 1e-30) + x[i]->moles = 0; + + f = fabs(x[i]->sum); + /*if (isnan(f) || !_finite(f))*/ + if (!PHR_ISFINITE((double) f)) + { + f = 0; + } + if (f == 0 && x[i]->moles == 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + continue; + } + else if (f == 0) + { + repeat = TRUE; + x[i]->master[0]->s->la += 5; + if (x[i]->master[0]->s->la < -999.) + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + else if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + repeat = TRUE; + d = weight * log10(fabs(x[i]->moles / x[i]->sum)); + /*if (!isnan(d) && _finite(d))*/ + if (PHR_ISFINITE((double) d)) + { + x[i]->master[0]->s->la += d; + } + else + { + warning_msg("Adjustment to la in revise_guesses was NaN\n"); + x[i]->master[0]->s->la += 5.0; + } + + } + if (debug_set == TRUE) + { + output_msg(sformatf( + "\t%5s not converged in set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, + (double) x[i]->sum, (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + else if (x[i]->type == ALK) + { + f = total_co2; + if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + repeat = TRUE; + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + x[i]->master[0]->s->la += weight * + log10(fabs(x[i]->moles / x[i]->sum)); + if (debug_set == TRUE) + { + output_msg(sformatf( + "%s not converged in set. %e\t%e\t%e\n", + x[i]->description, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + } + } + log_msg(sformatf( "Iterations in revise_guesses: %d\n", l_iter)); + mu_x = mu_unknown->f * 0.5 / mass_water_aq_x; + if (mu_x <= 1e-8) + { + mu_x = 1e-8; + } + gammas(mu_x); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sum_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates total alk, total carbon, total co2, electrical balance, + * total hydrogen, and total oxygen. + * + * Sorts species for summing and printing based on valence state and + * concentrations. + * + * Sums total valence states and stores in master[i]->total. + */ + int i, j; + struct master *master_ptr; +/* + * Set global variables + */ + ph_x = -s_hplus->la; + solution_pe_x = -s_eminus->la; + ah2o_x = exp(s_h2o->la * LOG_10); + density_x = 1.0; + if (s_o2 != NULL) + s_o2->moles = under(s_o2->lm) * mass_water_aq_x; + if (s_h2 != NULL) + s_h2->moles = under(s_h2->lm) * mass_water_aq_x; + +/* + * Calculate sums + */ + total_alkalinity = 0.0; + total_carbon = 0.0; + total_co2 = 0.0; + cb_x = 0.0; + total_ions_x = 0.0; + total_o_x = 0.0; + total_h_x = 0.0; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type == EX) + continue; + if (s_x[i]->type == SURF) + continue; + cb_x += s_x[i]->z * s_x[i]->moles; + total_ions_x += fabs(s_x[i]->z * s_x[i]->moles); + total_alkalinity += s_x[i]->alk * s_x[i]->moles; + total_carbon += s_x[i]->carbon * s_x[i]->moles; + total_co2 += s_x[i]->co2 * s_x[i]->moles; + + total_h_x += s_x[i]->h * s_x[i]->moles; + total_o_x += s_x[i]->o * s_x[i]->moles; + + if (use.Get_surface_ptr() != NULL) + { + if (use.Get_surface_ptr()->debye_lengths > 0 && state >= REACTION + && s_x[i]->type == H2O) + { + total_h_x -= 2 * mass_water_surfaces_x / gfw_water; + total_o_x -= mass_water_surfaces_x / gfw_water; + } + } + } +/* + * Sum valence states, put in master->total + */ + for (i = 0; i < count_master; i++) + { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + } + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].master_s->secondary != NULL) + { + master_ptr = species_list[i].master_s->secondary; + } + else + { + master_ptr = species_list[i].master_s->primary; + } + master_ptr->total += species_list[i].s->moles * species_list[i].coef; + } +/* + * Calculate mass-balance sums + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == MB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || + x[i]->type == SURFACE || + (x[i]->type == CB && x[i] != ph_unknown && x[i] != pe_unknown)) + { + x[i]->sum = 0.0; + for (j = 0; x[i]->master[j] != NULL; j++) + { + x[i]->sum += x[i]->master[j]->total; + } + } + else if (x[i]->type == ALK) + { + x[i]->sum = total_co2; + } + } +/* + * Calculate total element concentrations + */ + for (i = 0; i < count_master; i++) + { + master[i]->elt->primary->total_primary += master[i]->total; + } + /* + * Calculate isotope ratios + */ + calculate_values(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Use extra iterative loop to converge on g_factors + */ + int i, n, debug_diffuse_layer_save, debug_model_save; + struct solution *solution_ptr; + LDBLE prev_aq_x; +/* + * Allocate space for g factors for diffuse layer in surface complexation + */ + debug_diffuse_layer_save = debug_diffuse_layer; + debug_model_save = debug_model; + if (last_model.force_prep == TRUE) + { + same_model = FALSE; + } + else + { + same_model = check_same_model(); + } + if (dl_type_x != NO_DL && same_model == FALSE) + { + for (i = 0; i < count_s; i++) + { + s[i]->diff_layer = + (struct species_diff_layer *) free_check_null(s[i]-> + diff_layer); + s[i]->diff_layer = + (struct species_diff_layer *) PHRQ_malloc((size_t) use.Get_surface_ptr()-> + count_charge * + sizeof(struct + species_diff_layer)); + if (s[i]->diff_layer == NULL) + malloc_error(); + } + } + if (state >= REACTION && dl_type_x != NO_DL) + { + if (use.Get_mix_ptr() != NULL) + { + mass_water_bulk_x = 0.0; + std::map::const_iterator cit; + for (cit = (( cxxMix *) use.Get_mix_ptr())->Get_mixComps().begin(); cit != (( cxxMix *) use.Get_mix_ptr())->Get_mixComps().end(); cit++) + { + solution_ptr = solution_bsearch(cit->first, &n, TRUE); + mass_water_bulk_x += solution_ptr->mass_water * cit->second; + } + } + else + { + mass_water_bulk_x = use.Get_solution_ptr()->mass_water; + } + for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + { + mass_water_bulk_x += use.Get_surface_ptr()->charge[i].mass_water; + if (use.Get_surface_ptr()->debye_lengths > 0) + use.Get_surface_ptr()->charge[i].mass_water = 0.0; + } + } + prep(); + k_temp(tc_x, patm_x); + if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + { + initial_surface_water(); + calc_init_donnan(); + } + else + { + calc_init_g(); + } + if (state >= REACTION && use.Get_surface_ptr()->new_def == FALSE) + { + set(FALSE); + } + else + { + set(TRUE); + } + if (model() == ERROR) + return (ERROR); + g_iterations = 0; + + if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + { + do + { + g_iterations++; + prev_aq_x = mass_water_aq_x; + k_temp(tc_x, patm_x); + gammas(mu_x); + molalities(TRUE); + mb_sums(); + if (model() == ERROR) + return (ERROR); + if (use.Get_surface_ptr()->related_phases != TRUE + && use.Get_surface_ptr()->related_rate != TRUE) + initial_surface_water(); + if (debug_model == TRUE) + { + output_msg(sformatf( + "Surface_model (Donnan approximation): %d g_iterations, %d model iterations\n", + g_iterations, iterations)); + } + } + while ((calc_all_donnan() == FALSE + || fabs(1 - prev_aq_x / mass_water_aq_x) > 1e-6) + && g_iterations < itmax); + } + else + { + do + { + g_iterations++; + if (g_iterations > itmax - 10) + { + debug_model = TRUE; + debug_diffuse_layer = TRUE; + } + k_temp(tc_x, patm_x); + gammas(mu_x); + molalities(TRUE); + mb_sums(); + if (model() == ERROR) + return (ERROR); + if (use.Get_surface_ptr()->related_phases != TRUE + && use.Get_surface_ptr()->related_rate != TRUE) + initial_surface_water(); + if (debug_model == TRUE) + { + output_msg(sformatf( + "Surface_model (full integration): %d g_iterations, %d iterations\n", + g_iterations, iterations)); + } + } + while (calc_all_g() == FALSE && g_iterations < itmax); + } + if (g_iterations >= itmax) + { + pr.all = TRUE; + pr.surface = TRUE; + pr.species = TRUE; + pr.use = TRUE; + print_all(); + error_msg("Did not converge on g (diffuse layer excess)", STOP); + } + debug_diffuse_layer = debug_diffuse_layer_save; + debug_model = debug_model_save; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +free_model_allocs(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * free space allocated in model + */ + int i; + if (x != NULL) + { + for (i = 0; i < max_unknowns; i++) + { + unknown_free(x[i]); + } + } + x = (struct unknown **) free_check_null(x); + max_unknowns = 0; + array = (LDBLE *) free_check_null(array); + delta = (LDBLE *) free_check_null(delta); + residual = (LDBLE *) free_check_null(residual); + s_x = (struct species **) free_check_null(s_x); + sum_mb1 = (struct list1 *) free_check_null(sum_mb1); + sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); + sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); + sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); + sum_delta = (struct list2 *) free_check_null(sum_delta); + charge_group = (struct Charge_Group *) free_check_null(charge_group); + return (OK); +} + +#ifdef SLNQ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_trivial_eqns(int rows, int cols, LDBLE * matrix) +/* ---------------------------------------------------------------------- */ +{ + int r, i, j; + r = rows; + if (rows == cols) + return (OK); + if (rows > cols) + return (ERROR); + for (i = 0; i < cols; i++) + { + for (j = 0; j < rows; j++) + { + if (matrix[j * (cols + 1) + i] != 0.0) + break; + } + if (j < rows) + continue; + for (j = 0; j < cols + 1; j++) + matrix[r * (cols + 1) + j] = 0.0; + matrix[r * (cols + 1) + i] = 1.0; + r++; + } + if (r == cols) + return (OK); + return (ERROR); +} +#endif +#define ZERO_TOL 1.0e-30 +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +s_s_root(LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE x0, y0, x1, y1, xb, miny; + +/* + * Bracket answer + */ + x0 = 0.0; + x1 = 0.0; + y0 = s_s_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + miny = fabs(y0); + for (i = 1; i <= 10; i++) + { + x1 = (LDBLE) i / 10; + y1 = s_s_f(x1, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + if (fabs(y1) < miny) + { + miny = fabs(y1); + } + if (y0 * y1 < 0) + { + break; + } + else + { + x0 = x1; + y0 = y1; + } + } +/* + * Interval halve + */ + if (i > 10) + { + xb = 0.0; + } + else + { + xb = s_s_halve(l_a0, l_a1, x0, x1, l_kc, l_kb, xcaq, xbaq); + } + return (xb); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +s_s_halve(LDBLE l_a0, LDBLE l_a1, LDBLE x0, LDBLE x1, LDBLE l_kc, LDBLE l_kb, + LDBLE xcaq, LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE l_x, y0, dx, y; + + y0 = s_s_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + dx = (x1 - x0); +/* + * Loop for interval halving + */ + for (i = 0; i < 100; i++) + { + dx *= 0.5; + l_x = x0 + dx; + y = s_s_f(l_x, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + if (dx < 1e-8 || y == 0) + { + break; + } + if (y0 * y >= 0) + { + x0 = l_x; + y0 = y; + } + } + return (x0 + dx); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +s_s_f(LDBLE xb, LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, + LDBLE xbaq) +/* ---------------------------------------------------------------------- */ +{ +/* + * Need root of this function to determine xb + */ + LDBLE lb, lc, f, xc, r; + xc = 1 - xb; + if (xb == 0) + xb = 1e-20; + if (xc == 0) + xc = 1e-20; + lc = exp((l_a0 - l_a1 * (-4 * xb + 3)) * xb * xb); + lb = exp((l_a0 + l_a1 * (4 * xb - 1)) * xc * xc); + r = lc * l_kc / (lb * l_kb); + f = xcaq * (xb / r + xc) + xbaq * (xb + r * xc) - 1; + return (f); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +numerical_jacobian(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE *base; + LDBLE d, d1, d2; + int i, j; + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (! + (numerical_deriv || + (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->type == CD_MUSIC) || + (gas_phase_ptr != NULL && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) + )) + return(OK); + + calculating_deriv = TRUE; + gammas(mu_x); + molalities(TRUE); + mb_sums(); + residuals(); +/* + * Clear array, note residuals are in array[i, count_unknowns+1] + */ + + for (i = 0; i < count_unknowns; i++) + { + array[i] = 0.0; + } + for (i = 1; i < count_unknowns; i++) + { + memcpy((void *) &(array[i * (count_unknowns + 1)]), + (void *) &(array[0]), (size_t) count_unknowns * sizeof(LDBLE)); + } + + base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + if (base == NULL) + malloc_error(); + for (i = 0; i < count_unknowns; i++) + { + base[i] = residual[i]; + } + d = 0.0001; + d1 = d * log(10.0); + d2 = 0; + for (i = 0; i < count_unknowns; i++) + { + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case MH: + s_eminus->la += d; + d2 = d1; + break; + case AH2O: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case PITZER_GAMMA: + x[i]->s->lg += d; + d2 = d; + break; + case MH2O: + mass_water_aq_x *= (1.0 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + d2 = log(1.0 + d); + break; + case MU: + d2 = d * mu_x; + mu_x += d2; + gammas(mu_x); + break; + case PP: + for (j = 0; j < count_unknowns; j++) + { + delta[j] = 0.0; + } + d2 = -1e-8; + delta[i] = d2; + reset(); + d2 = delta[i]; + break; + case S_S_MOLES: + if (x[i]->s_s_in == FALSE) + continue; + for (j = 0; j < count_unknowns; j++) + { + delta[j] = 0.0; + } + /*d2 = -1e-8; */ + d2 = -d * x[i]->moles; + d2 = -.1 * x[i]->moles; + /* + if (d2 > -1e-10) d2 = -1e-10; + calculating_deriv = FALSE; + */ + delta[i] = d2; + /*fprintf (stderr, "delta before reset %e\n", delta[i]); */ + reset(); + d2 = delta[i]; + /*fprintf (stderr, "delta after reset %e\n", delta[i]); */ + break; + case GAS_MOLES: + if (gas_in == FALSE) + continue; + + d2 = d * x[i]->moles; + if (d2 < 1e-14) + d2 = 1e-14; + x[i]->moles += d2; + break; + } + molalities(TRUE); + mb_sums(); + /* + mb_s_s(); + mb_gases(); + */ + residuals(); + //output_msg(sformatf( "%d\n", i)); + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + //output_msg(sformatf( "\t%d %e %e %e %e\n", j, array[j*(count_unknowns + 1) + i] , residual[j], base[j], d2)); + } + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + case AH2O: + x[i]->master[0]->s->la -= d; + break; + case MH: + s_eminus->la -= d; + if (array[i * (count_unknowns + 1) + i] == 0) + { + /*output_msg(sformatf( "Zero diagonal for MH\n")); */ + array[i * (count_unknowns + 1) + i] = + exp(s_h2->lm * LOG_10) * 2; + } + break; + case PITZER_GAMMA: + x[i]->s->lg -= d; + break; + case MH2O: + mass_water_aq_x /= (1 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + break; + case MU: + mu_x -= d2; + gammas(mu_x); + break; + case PP: + delta[i] = -d2; + reset(); + break; + case S_S_MOLES: + delta[i] = -d2; + reset(); + break; + case GAS_MOLES: + x[i]->moles -= d2; + break; + } + } + molalities(TRUE); + mb_sums(); + mb_gases(); + mb_s_s(); + residuals(); + free_check_null(base); + calculating_deriv = FALSE; + return OK; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +ineq_init(int l_max_row_count, int l_max_column_count) +/* ---------------------------------------------------------------------- */ +{ + if (normal == NULL) + { + normal = + (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + normal_max = count_unknowns; + if (normal == NULL) + malloc_error(); + } + if (ineq_array == NULL) + { + ineq_array = + (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * l_max_column_count * + sizeof(LDBLE)); + if (ineq_array == NULL) + malloc_error(); + ineq_array_max = l_max_row_count * l_max_column_count; + } + if (back_eq == NULL) + { + back_eq = (int *) PHRQ_malloc((size_t) l_max_row_count * sizeof(int)); + if (back_eq == NULL) + malloc_error(); + back_eq_max = l_max_row_count; + } + if (zero == NULL) + { + zero = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); + if (zero == NULL) + malloc_error(); + zero_max = l_max_row_count; + } + if (res == NULL) + { + res = (LDBLE *) PHRQ_malloc((size_t) l_max_row_count * sizeof(LDBLE)); + if (res == NULL) + malloc_error(); + res_max = l_max_row_count; + } + if (delta1 == NULL) + { + delta1 = + (LDBLE *) PHRQ_malloc((size_t) l_max_column_count * sizeof(LDBLE)); + if (delta1 == NULL) + malloc_error(); + delta1_max = l_max_column_count; + } + if (cu == NULL) + { + cu = (LDBLE *) PHRQ_malloc((size_t) 3 * l_max_row_count * + sizeof(LDBLE)); + if (cu == NULL) + malloc_error(); + cu_max = 3 * l_max_row_count; + } + if (iu == NULL) + { + iu = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); + if (iu == NULL) + malloc_error(); + iu_max = 3 * l_max_row_count; + } + if (is == NULL) + { + is = (int *) PHRQ_malloc((size_t) 3 * l_max_row_count * sizeof(int)); + if (is == NULL) + malloc_error(); + is_max = 3 * l_max_row_count; + } +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +set_inert_moles(void) +/* ---------------------------------------------------------------------- */ +{ + int j; + if (use.Get_pp_assemblage_ptr() == NULL) return; + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) continue; + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + if (comp_ptr->Get_precipitate_only()) + { + x[j]->inert_moles = x[j]->moles; + x[j]->moles = 0; + } + } +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +unset_inert_moles() +/* ---------------------------------------------------------------------- */ +{ + int j; + if (use.Get_pp_assemblage_ptr() == NULL) return; + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) continue; + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + if (comp_ptr->Get_precipitate_only()) + { + x[j]->moles += x[j]->inert_moles; + x[j]->inert_moles = 0; + } + } +} diff --git a/rename_cpp/newiso.dat b/rename_cpp/newiso.dat new file mode 100644 index 00000000..b3fb3237 --- /dev/null +++ b/rename_cpp/newiso.dat @@ -0,0 +1,5565 @@ +SOLUTION_MASTER_SPECIES +E e- 0 0 0.0 +H H3O+ -1 H 1.008 +H(0) H2 0 H +H(1) H3O+ -1 H +O H2O 0 O 16.00 +O(0) O2 0 O +O(-2) H2O 0 O +Ca Ca+2 0 Ca 40.08 +Mg Mg+2 0 Mg 24.312 +Na Na+ 0 Na 22.9898 +K K+ 0 K 39.102 +Fe Fe+2 0.0 Fe 55.847 +Fe(+2) Fe+2 0.0 Fe +Fe(+3) Fe+3 -2.0 Fe +Al Al+3 0.0 Al 26.9815 +Si H4SiO4 0.0 SiO2 28.0843 +Cl Cl- 0 Cl 35.453 +C CO2 0 HCO3 12.0111 +C(4) CO2 0 HCO3 +C(-4) CH4 0 CH4 +S SO4-2 0 S 31.972 +S(6) SO4-2 0 SO4 +S(-2) HS- 1 S +N NO3- 0 N 14.0067 +N(+5) NO3- 0 N +N(+3) NO2- 0 N +N(0) N2 0 N +N(-3) NH4+ 0 N +P PO4-3 2.0 P 30.9738 +F F- 0.0 F 18.9984 +Br Br- 0.0 Br 79.904 + +SOLUTION_SPECIES +H3O+ = H3O+ + log_k 0.000 + -gamma 9.0000 0.0000 + +e- = e- + log_k 0.000 + +H2O = H2O + log_k 0.000 + +Ca+2 = Ca+2 + log_k 0.000 + -gamma 5.0000 0.1650 + +Mg+2 = Mg+2 + log_k 0.000 + -gamma 5.5000 0.2000 + +Na+ = Na+ + log_k 0.000 + -gamma 4.0000 0.0750 + +K+ = K+ + log_k 0.000 + -gamma 3.5000 0.0150 + +Fe+2 = Fe+2 + log_k 0.000 + -gamma 6.0000 0.0000 + +Al+3 = Al+3 + log_k 0.000 + -gamma 9.0000 0.0000 + +H4SiO4 = H4SiO4 + log_k 0.000 + +Cl- = Cl- + log_k 0.000 + -gamma 3.5000 0.0150 + +SO4-2 = SO4-2 + log_k 0.000 + -gamma 5.0000 -0.0400 + +NO3- = NO3- + log_k 0.000 + -gamma 3.0000 0.0000 + +PO4-3 = PO4-3 + log_k 0.000 + -gamma 4.0000 0.0000 + +F- = F- + log_k 0.000 + -gamma 3.5000 0.0000 + +Br- = Br- + log_k 0.000 + -gamma 3.0000 0.0000 + +2H2O = OH- + H3O+ + log_k -14.000 + delta_h 13.362 kcal + -analytic -283.971 -0.05069842 13323.0 102.24447 -1119669.0 + -gamma 3.5000 0.0000 + +6 H2O = O2 + 4 H3O+ + 4 e- + log_k -86.08 + delta_h 134.79 kcal + +2 H3O+ + 2 e- = H2 + 2H2O + log_k -3.15 + delta_h -1.759 kcal + +CO2 + 2H2O = HCO3- + H3O+ + log_k -6.352 + delta_h 2.177 kcal + -analytic -356.3094 -0.06092 21834.37 126.8339 -1684915 + +CO2 + 3H2O = CO3-2 + 2H3O+ + log_k -16.681 + delta_h 5.738 kcal + -analytic -464.1965 -0.09344813 26986.16 165.75951 -2248628.9 + +CO3-2 + 10 H3O+ + 8 e- = CH4 + 13 H2O + log_k 41.071 + delta_h -61.039 kcal + +SO4-2 + H3O+ = HSO4- + H2O + log_k 1.988 + delta_h 3.85 kcal + -analytic -56.889 0.006473 2307.9 19.8858 0.0 + +SO4-2 + 9 H3O+ + 8 e- = HS- + 13 H2O + log_k 33.65 + delta_h -60.140 kcal + -gamma 3.5000 0.0000 + +HS- + H2O = S-2 + H3O+ + log_k -12.918 + delta_h 12.1 kcal + -gamma 5.0000 0.0000 + +HS- + H3O+ = H2S + H2O + log_k 6.994 + delta_h -5.300 kcal + -analytic -11.17 0.02386 3279.0 + +NO3- + 2 H3O+ + 2 e- = NO2- + 3H2O + log_k 28.570 + delta_h -43.760 kcal + -gamma 3.0000 0.0000 + +2 NO3- + 12 H3O+ + 10e- = N2 + 18 H2O + log_k 207.080 + delta_h -312.130 kcal + +NH4+ + H2O = NH3 + H3O+ + log_k -9.252 + delta_h 12.48 kcal + -analytic 0.6322 -0.001225 -2835.76 + +NO3- + 10 H3O+ + 8 e- = NH4+ + 13 H2O + log_k 119.077 + delta_h -187.055 kcal + -gamma 2.5000 0.0000 + +NH4+ + SO4-2 = NH4SO4- + log_k 1.11 + +PO4-3 + H3O+ = HPO4-2 + H2O + log_k 12.346 + delta_h -3.530 kcal + -gamma 4.0000 0.0000 + +PO4-3 + 2 H3O+ = H2PO4- + 2H2O + log_k 19.553 + delta_h -4.520 kcal + -gamma 4.5000 0.0000 + +H3O+ + F- = HF + H2O + log_k 3.18 + delta_h 3.18 kcal + -analytic -2.033 0.012645 429.01 + +H3O+ + 2 F- = HF2- + H2O + log_k 3.760 + delta_h 4.550 kcal + +Ca+2 + OH- = CaOH+ + log_k -12.780 + +Ca+2 + CO3-2 = CaCO3 + log_k 3.224 + delta_h 3.545 kcal + -analytic -1228.732 -0.299440 35512.75 485.818 + +#Ca+2 + HCO3- = CaHCO3+ +Ca+2 + CO3-2 + H3O+ = CaHCO3+ + H2O + log_k 11.435 + delta_h -0.871 kcal + -analytic 1317.0071 0.34546894 -39916.84 -517.70761 563713.9 + -gamma 5.4000 0.0000 + +Ca+2 + SO4-2 = CaSO4 + log_k 2.300 + delta_h 1.650 kcal + +Ca+2 + HSO4- = CaHSO4+ + log_k 1.08 + +Ca+2 + PO4-3 = CaPO4- + log_k 6.459 + delta_h 3.100 kcal + +Ca+2 + HPO4-2 = CaHPO4 + log_k 2.739 + delta_h 3.3 kcal + +Ca+2 + H2PO4- = CaH2PO4+ + log_k 1.408 + delta_h 3.4 kcal + +Ca+2 + F- = CaF+ + log_k 0.940 + delta_h 4.120 kcal + +Mg+2 + OH- = MgOH+ + log_k -11.440 + delta_h 15.952 kcal + +Mg+2 + CO3-2 = MgCO3 + log_k 2.98 + delta_h 2.713 kcal + -analytic 0.9910 0.00667 + +Mg+2 + H3O+ + CO3-2 = MgHCO3+ + H2O + log_k 11.399 + delta_h -2.771 kcal + -analytic 48.6721 0.03252849 -2614.335 -18.00263 563713.9 + +Mg+2 + SO4-2 = MgSO4 + log_k 2.370 + delta_h 4.550 kcal + +Mg+2 + PO4-3 = MgPO4- + log_k 6.589 + delta_h 3.100 kcal + +Mg+2 + HPO4-2 = MgHPO4 + log_k 2.87 + delta_h 3.3 kcal + +Mg+2 + H2PO4- = MgH2PO4+ + log_k 1.513 + delta_h 3.4 kcal + +Mg+2 + F- = MgF+ + log_k 1.820 + delta_h 3.200 kcal + +Na+ + OH- = NaOH + log_k -14.180 + +Na+ + CO3-2 = NaCO3- + log_k 1.270 + delta_h 8.910 kcal + +Na+ + HCO3- = NaHCO3 + log_k -0.25 + +Na+ + SO4-2 = NaSO4- + log_k 0.700 + delta_h 1.120 kcal + +Na+ + HPO4-2 = NaHPO4- + log_k 0.29 + +Na+ + F- = NaF + log_k -0.240 + +K+ + OH- = KOH + log_k -14.460 + +K+ + SO4-2 = KSO4- + log_k 0.850 + delta_h 2.250 kcal + -analytic 3.106 0.0 -673.6 + +K+ + HPO4-2 = KHPO4- + log_k 0.29 + +Fe+2 + 2H2O = FeOH+ + H3O+ + log_k -9.500 + delta_h 13.200 kcal + +Fe+2 + Cl- = FeCl+ + log_k 0.140 + +Fe+2 + CO3-2 = FeCO3 + log_k 4.380 + +Fe+2 + HCO3- = FeHCO3+ + log_k 2.0 + +Fe+2 + SO4-2 = FeSO4 + log_k 2.250 + delta_h 3.230 kcal + +Fe+2 + HSO4- = FeHSO4+ + log_k 1.08 + +Fe+2 + 2HS- = Fe(HS)2 + log_k 8.95 + +Fe+2 + 3HS- = Fe(HS)3- + log_k 10.987 + +Fe+2 + HPO4-2 = FeHPO4 + log_k 3.6 + +Fe+2 + H2PO4- = FeH2PO4+ + log_k 2.7 + +Fe+2 + F- = FeF+ + log_k 1.000 + +Fe+2 = Fe+3 + e- + log_k -13.020 + delta_h 9.680 kcal + -gamma 9.0000 0.0000 + +Fe+3 + 2H2O = FeOH+2 + H3O+ + log_k -2.19 + delta_h 10.4 kcal + +Fe+3 + 4H2O = Fe(OH)2+ + 2 H3O+ + log_k -5.67 + delta_h 17.1 kcal + +Fe+3 + 6 H2O = Fe(OH)3 + 3 H3O+ + log_k -12.56 + delta_h 24.8 kcal + +Fe+3 + 8 H2O = Fe(OH)4- + 4 H3O+ + log_k -21.6 + delta_h 31.9 kcal + +2 Fe+3 + 4 H2O = Fe2(OH)2+4 + 2 H3O+ + log_k -2.95 + delta_h 13.5 kcal + +3 Fe+3 + 8 H2O = Fe3(OH)4+5 + 4 H3O+ + log_k -6.3 + delta_h 14.3 kcal + +Fe+3 + Cl- = FeCl+2 + log_k 1.48 + delta_h 5.6 kcal + +Fe+3 + 2 Cl- = FeCl2+ + log_k 2.13 + +Fe+3 + 3 Cl- = FeCl3 + log_k 1.13 + +Fe+3 + SO4-2 = FeSO4+ + log_k 4.04 + delta_h 3.91 kcal + +Fe+3 + HSO4- = FeHSO4+2 + log_k 2.48 + +Fe+3 + 2 SO4-2 = Fe(SO4)2- + log_k 5.38 + delta_h 4.60 kcal + +Fe+3 + HPO4-2 = FeHPO4+ + log_k 5.43 + delta_h 5.76 kcal + +Fe+3 + H2PO4- = FeH2PO4+2 + log_k 5.43 + +Fe+3 + F- = FeF+2 + log_k 6.2 + delta_h 2.7 kcal + +Fe+3 + 2 F- = FeF2+ + log_k 10.8 + delta_h 4.8 kcal + +Fe+3 + 3 F- = FeF3 + log_k 14.0 + delta_h 5.4 kcal + +Al+3 + 2H2O = AlOH+2 + H3O+ + log_k -5.00 + delta_h 11.49 kcal + -analytic -38.253 0.0 -656.27 14.327 + +Al+3 + 4 H2O = Al(OH)2+ + 2 H3O+ + log_k -10.1 + delta_h 26.90 kcal + -analytic 88.500 0.0 -9391.6 -27.121 + +Al+3 + 6 H2O = Al(OH)3 + 3 H3O+ + log_k -16.9 + delta_h 39.89 kcal + -analytic 226.374 0.0 -18247.8 -73.597 + +Al+3 + 8 H2O = Al(OH)4- + 4 H3O+ + log_k -22.7 + delta_h 42.30 kcal + -analytic 51.578 0.0 -11168.9 -14.865 + +Al+3 + SO4-2 = AlSO4+ + log_k 3.5 + delta_h 2.29 kcal + +Al+3 + 2SO4-2 = Al(SO4)2- + log_k 5.0 + delta_h 3.11 kcal + +Al+3 + HSO4- = AlHSO4+2 + log_k 0.46 + +Al+3 + F- = AlF+2 + log_k 7.000 + delta_h 1.060 kcal + +Al+3 + 2 F- = AlF2+ + log_k 12.700 + delta_h 1.980 kcal + +Al+3 + 3 F- = AlF3 + log_k 16.800 + delta_h 2.160 kcal + +Al+3 + 4 F- = AlF4- + log_k 19.400 + delta_h 2.200 kcal + +Al+3 + 5 F- = AlF5-2 + log_k 20.600 + delta_h 1.840 kcal + +Al+3 + 6 F- = AlF6-3 + log_k 20.600 + delta_h -1.670 kcal + +H4SiO4 + H2O = H3SiO4- + H3O+ + log_k -9.83 + delta_h 6.12 kcal + -analytic -302.3724 -0.050698 15669.69 108.18466 -1119669.0 + +H4SiO4 + 2H2O= H2SiO4-2 + 2 H3O+ + log_k -23.0 + delta_h 17.6 kcal + -analytic -294.0184 -0.072650 11204.49 108.18466 -1119669.0 + +H4SiO4 + 4 H3O+ + 6 F- = SiF6-2 + 8 H2O + log_k 30.180 + delta_h -16.260 kcal +PHASES +Calcite + CaCO3 = CO3-2 + Ca+2 + log_k -8.480 + delta_h -2.297 kcal + -analytic -171.9065 -0.077993 2839.319 71.595 + +Dolomite + CaMg(CO3)2 = Ca+2 + Mg+2 + 2 CO3-2 + log_k -17.090 + delta_h -9.436 kcal + +Siderite + FeCO3 = Fe+2 + CO3-2 + log_k -10.890 + delta_h -2.480 kcal + +Gypsum + CaSO4:2H2O = Ca+2 + SO4-2 + 2 H2O + log_k -4.580 + delta_h -0.109 kcal + -analytic 68.2401 0.0 -3221.51 -25.0627 + +Anhydrite + CaSO4 = Ca+2 + SO4-2 + log_k -4.360 + delta_h -1.710 kcal + -analytic 197.52 0.0 -8669.8 -69.835 + +Hydroxyapatite + Ca5(PO4)3OH + 4 H3O+ = 5H2O + 3 HPO4-2 + 5 Ca+2 + log_k -3.421 + delta_h -36.155 kcal + +Fluorite + CaF2 = Ca+2 + 2 F- + log_k -10.600 + delta_h 4.690 kcal + -analytic 66.348 0.0 -4298.2 -25.271 + +SiO2(a) + SiO2 + 2 H2O = H4SiO4 + log_k -2.710 + delta_h 3.340 kcal + -analytic -0.26 0.0 -731.0 + +Chalcedony + SiO2 + 2 H2O = H4SiO4 + log_k -3.550 + delta_h 4.720 kcal + -analytic -0.09 0.0 -1032.0 + +Quartz + SiO2 + 2 H2O = H4SiO4 + log_k -3.980 + delta_h 5.990 kcal + -analytic 0.41 0.0 -1309.0 + +Gibbsite + Al(OH)3 + 3 H3O+ = Al+3 + 6 H2O + log_k 8.110 + delta_h -22.800 kcal + +Al(OH)3(a) + Al(OH)3 + 3 H3O+ = Al+3 + 6 H2O + log_k 10.800 + delta_h -26.500 kcal + +Kaolinite + Al2Si2O5(OH)4 + 6 H3O+ = 7H2O + 2 H4SiO4 + 2 Al+3 + log_k 7.435 + delta_h -35.300 kcal + +Albite + NaAlSi3O8 + 8 H2O = Na+ + Al(OH)4- + 3 H4SiO4 + log_k -18.002 + delta_h 25.896 kcal + +Anorthite + CaAl2Si2O8 + 8 H2O = Ca+2 + 2 Al(OH)4- + 2 H4SiO4 + log_k -19.714 + delta_h 11.580 kcal + +K-feldspar + KAlSi3O8 + 8 H2O = K+ + Al(OH)4- + 3 H4SiO4 + log_k -20.573 + delta_h 30.820 kcal + +K-mica + KAl3Si3O10(OH)2 + 10 H3O+ = K+ + 3 Al+3 + 3 H4SiO4 + 10H2O + log_k 12.703 + delta_h -59.376 kcal + +Chlorite(14A) + Mg5Al2Si3O10(OH)8 + 16 H3O+ = 5Mg+2 + 2Al+3 + 3H4SiO4 + 22H2O + log_k 68.38 + delta_h -151.494 kcal + +Ca-Montmorillonite + Ca0.165Al2.33Si3.67O10(OH)2 + 14 H2O = 0.165Ca+2 + 2.33 Al(OH)4- + 3.67 H4SiO4 + 2 H3O+ + log_k -45.027 + delta_h 58.373 kcal + +Talc + Mg3Si4O10(OH)2 + 4 H2O + 6 H3O+ = 3 Mg+2 + 4 H4SiO4 + 6H2O + log_k 21.399 + delta_h -46.352 kcal + +Illite + K0.6Mg0.25Al2.3Si3.5O10(OH)2 + 12.4H2O = 0.6K+ + 0.25Mg+2 + 2.3Al(OH)4- + 3.5H4SiO4 + 1.2H3O+ + log_k -40.267 + delta_h 54.684 kcal + +Chrysotile + Mg3Si2O5(OH)4 + 6 H3O+ = 7H2O + 2 H4SiO4 + 3 Mg+2 + log_k 32.200 + delta_h -46.800 kcal + -analytic 13.248 0.0 10217.1 -6.1894 + +Sepiolite + Mg2Si3O7.5OH:3H2O + 4 H3O+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + 4H2O + log_k 15.760 + delta_h -10.700 kcal + +Sepiolite(d) + Mg2Si3O7.5OH:3H2O + 4 H3O+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + 4H2O + log_k 18.660 + +Hematite + Fe2O3 + 6 H3O+ = 2 Fe+3 + 9 H2O + log_k -4.008 + delta_h -30.845 kcal + +Goethite + FeOOH + 3 H3O+ = Fe+3 + 5 H2O + log_k -1.000 + delta_h -14.48 kcal + +Fe(OH)3(a) + Fe(OH)3 + 3 H3O+ = Fe+3 + 6 H2O + log_k 4.891 + +Pyrite + FeS2 + 2H3O+ + 2e- = Fe+2 + 2HS- + 2H2O + log_k -18.479 + delta_h 11.300 kcal + +FeS(ppt) + FeS + H3O+ = Fe+2 + HS- + H2O + log_k -3.915 + +Mackinawite + FeS + H3O+ = Fe+2 + HS- + H2O + log_k -4.648 + +Sulfur + S + 2 H3O+ + 2e- = H2S + 2H2O + log_k 4.882 + delta_h -9.5 kcal + +Vivianite + Fe3(PO4)2:8H2O = 3 Fe+2 + 2 PO4-3 + 8 H2O + log_k -36.000 + +Halite + NaCl = Na+ + Cl- + log_k 1.582 + delta_h 0.918 kcal + +CO2(g) + CO2(g) = CO2 + log_k -1.468 + delta_h -4.776 kcal + -analytic 108.3865 0.01985076 -6919.53 -40.45154 669365.0 + +O2(g) + O2 = O2 + log_k -2.960 + delta_h -1.844 kcal + +H2(g) + H2 = H2 + log_k -3.150 + delta_h -1.759 kcal + +H2O(g) + H2O = H2O + log_k 1.51 + delta_h -44.03 kJ + +N2(g) + N2 = N2 + log_k -3.260 + delta_h -1.358 kcal + +H2S(g) + H2S = H2S + log_k -0.997 + delta_h -4.570 kcal + +CH4(g) + CH4 = CH4 + log_k -2.860 + delta_h -3.373 kcal + +NH3(g) + NH3 = NH3 + log_k 1.770 + delta_h -8.170 kcal + +Melanterite + FeSO4:7H2O = 7 H2O + Fe+2 + SO4-2 + log_k -2.209 + delta_h 4.910 kcal + -analytic 1.447 -0.004153 0.0 0.0 -214949.0 + +Alunite + KAl3(SO4)2(OH)6 + 6 H3O+ = K+ + 3 Al+3 + 2 SO4-2 + 12H2O + log_k -1.400 + delta_h -50.250 kcal + +Jarosite-K + KFe3(SO4)2(OH)6 + 6 H3O+ = 3 Fe+3 + 12 H2O + K+ + 2 SO4-2 + log_k -9.210 + delta_h -31.280 kcal + +EXCHANGE_MASTER_SPECIES + X X- +EXCHANGE_SPECIES + X- = X- + log_k 0.0 + + Na+ + X- = NaX + log_k 0.0 + -gamma 4.0 0.075 + + K+ + X- = KX + log_k 0.7 + -gamma 3.5 0.015 + delta_h -4.3 # Jardine & Sparks, 1984 + + NH4+ + X- = NH4X + log_k 0.6 + -gamma 2.5 0.0 + delta_h -2.4 # Laudelout et al., 1968 + + Ca+2 + 2X- = CaX2 + log_k 0.8 + -gamma 5.0 0.165 + delta_h 7.2 # Van Bladel & Gheyl, 1980 + + Mg+2 + 2X- = MgX2 + log_k 0.6 + -gamma 5.5 0.2 + delta_h 7.4 # Laudelout et al., 1968 + + Fe+2 + 2X- = FeX2 + log_k 0.44 + -gamma 6.0 0.0 + + Al+3 + 3X- = AlX3 + log_k 0.41 + -gamma 9.0 0.0 + + AlOH+2 + 2X- = AlOHX2 + log_k 0.89 + -gamma 0.0 0.0 + +SURFACE_MASTER_SPECIES + Hfo_s Hfo_sOH + Hfo_w Hfo_wOH + +SURFACE_SPECIES +# All surface data from +# Dzombak and Morel, 1990 +# +# +# Acid-base data from table 5.7 +# +# strong binding site--Hfo_s, + + Hfo_sOH = Hfo_sOH + log_k 0.0 + + Hfo_sOH + H3O+ = Hfo_sOH2+ + H2O + log_k 7.29 # = pKa1,int + + Hfo_sOH + H2O = Hfo_sO- + H3O+ + log_k -8.93 # = -pKa2,int + +# weak binding site--Hfo_w + + Hfo_wOH = Hfo_wOH + log_k 0.0 + + Hfo_wOH + H3O+ = Hfo_wOH2+ + H2O + log_k 7.29 # = pKa1,int + + Hfo_wOH + H2O = Hfo_wO- + H3O+ + log_k -8.93 # = -pKa2,int + +############################################### +# CATIONS # +############################################### +# +# Cations from table 10.1 or 10.5 +# +# Calcium + Hfo_sOH + Ca+2 = Hfo_sOHCa+2 + log_k 4.97 + + Hfo_wOH + Ca+2 + H2O = Hfo_wOCa+ + H3O+ + log_k -5.85 +# +# Derived constants table 10.5 +# +# Magnesium + Hfo_wOH + Mg+2 + H2O = Hfo_wOMg+ + H3O+ + log_k -4.6 +# Iron +# Hfo_sOH + Fe+2 + H2O = Hfo_sOFe+ + H3O+ +# log_k 0.7 # LFER using table 10.5 + +# Hfo_wOH + Fe+2 + H2O = Hfo_wOFe+ + H3O+ +# log_k -2.5 # LFER using table 10.5 + +# Iron, strong site: Appelo, Van der Weiden, Tournassat & Charlet, subm. + Hfo_sOH + Fe+2 + H2O = Hfo_sOFe+ + H3O+ + log_k -0.95 +# Iron, weak site: Liger et al., GCA 63, 2939, re-optimized for D&M + Hfo_wOH + Fe+2 + H2O = Hfo_wOFe+ + H3O+ + log_k -2.98 + + Hfo_wOH + Fe+2 + 3H2O = Hfo_wOFeOH + 2H3O+ + log_k -11.55 + +############################################### +# ANIONS # +############################################### +# +# Anions from table 10.6 +# +# Phosphate + Hfo_wOH + PO4-3 + 3 H3O+ = Hfo_wH2PO4 + 4H2O + log_k 31.29 + + Hfo_wOH + PO4-3 + 2 H3O+ = Hfo_wHPO4- + 3H2O + log_k 25.39 + + Hfo_wOH + PO4-3 + H3O+ = Hfo_wPO4-2 + 2H2O + log_k 17.72 +# +# Anions from table 10.7 +# +# Sulfate + Hfo_wOH + SO4-2 + H3O+ = Hfo_wSO4- + 2H2O + log_k 7.78 + + Hfo_wOH + SO4-2 = Hfo_wOHSO4-2 + log_k 0.79 +# +# Derived constants table 10.10 +# + Hfo_wOH + F- + H3O+ = Hfo_wF + 2H2O + log_k 8.7 + + Hfo_wOH + F- = Hfo_wOHF- + log_k 1.6 +# +# Carbonate: Van Geen et al., 1994 reoptimized for HFO +# 0.15 g HFO/L has 0.344 mM sites == 2 g of Van Geen's Goethite/L +# +# Hfo_wOH + CO3-2 + H3O+ = Hfo_wCO3- + 2H2O +# log_k 12.56 +# +# Hfo_wOH + CO3-2 + 2 H3O+= Hfo_wHCO3 + 3 H2O +# log_k 20.62 + +# 9/19/96 +# Added analytical expression for H2S, NH3, KSO4. +# Added species CaHSO4+. +# Added delta H for Goethite. + +# +# Begin Isotope definitions +# +############################################################################################### +SOLUTION_MASTER_SPECIES +############################################################################################### +D D2O 0 D 2 +D(1) D2O 0 D +D(0) HD 0 D +T HTO 0 T 3 +T(1) HTO 0 T +T(0) HT 0 T +[18O] H2[18O] 0 [18O] 18 +[18O](-2) H2[18O] 0 [18O] 18 +[18O](0) O[18O] 0 [18O] 18 +[13C] [13C]O2 0 [13C] 13 +[13C](4) [13C]O2 0 [13C] +[13C](-4) [13C]H4 0 [13C] +[14C] [14C]O2 0 [14C] 14 +[14C](4) [14C]O2 0 [14C] +[14C](-4) [14C]H4 0 [14C] +[34S] [34S]O4-2 0 [34S] 33.967 +[34S](6) [34S]O4-2 0 [34S] +[34S](-2) H[34S]- 0 [34S] +[15N] [15N]O3- 0 [15N] 15.00010897312 +[15N](5) [15N]O3- 0 [15N] +[15N](3) [15N]O2- 0 [15N] +[15N](0) N[15N] 0 [15N] +[15N](-3) [15N]H4+ 0 [15N] +############################################################################################### +ISOTOPES +############################################################################################### +H + -isotope D permil 155.76e-6 # VSMOW (Clark and Fritz, 1997) + -isotope T TU 1e-18 # Solomon and Cook, in eds, Cook and Herczeg, 2000 +H(0) + -isotope D(0) permil 155.76e-6 # VSMOW (Clark and Fritz, 1997) + -isotope T(0) TU 1e-18 # Solomon and Cook, in eds, Cook and Herczeg, 2000 + # 1 THO in 10^18 H2O +# -isotope T pCi/L 3.125e-18 # +#1e-18/3.2 = T/mol H2O +C + -isotope [13C] permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite + # Chang and Li, 1990, Chinese Science Bulletin + -isotope [13C](4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite + # Chang and Li, 1990, Chinese Science Bulletin + -isotope [13C](-4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite + -isotope [14C] pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon + -isotope [14C](4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon + # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) + -isotope [14C](-4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon +C(4) + -isotope [13C](4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite + # Chang and Li, 1990, Chinese Science Bulletin + -isotope [14C](4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon + # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) + # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) +C(-4) + -isotope [13C](-4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite + -isotope [14C](-4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon + # 14C calculation + # + # lambda = ln(2)/(5730 yrs * 3.15576e7 sec/yr) + # mole/g carbon = -(dn/dt)/lambda = 0.226 dps / 3.8332476e-12 / 6.022136736e23 + # mole C/g C NBS Oxalic Acid with 13C = -19.3: 0.08325783313 + # mole 14C/mol Modern Carbon mol/g carbon/ (mole C/g C) = 1.175887709e-12 + # +O + -isotope [18O] permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) + -isotope [18O](0) permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) +O(0) + -isotope [18O](0) permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) + +S + # Coplen and others, 2002 + -isotope [34S] permil 0.04416264 # VCDT, Vienna Canyon Diablo Troilite + -isotope [34S](6) permil 0.04416264 # VCDT + -isotope [34S](-2) permil 0.04416264 # VCDT +S(6) + -isotope [34S](6) permil 0.04416264 # VCDT +S(-2) + -isotope [34S](-2) permil 0.04416264 # VCDT +N + # Coplen and others, 2002 + -isotope [15N] permil 0.003676867 # Air + -isotope [15N](5) permil 0.003676867 # Air + -isotope [15N](3) permil 0.003676867 # Air + -isotope [15N](0) permil 0.003676867 # Air + -isotope [15N](-3) permil 0.003676867 # Air +N(5) + -isotope [15N](5) permil 0.003676867 # Air +N(3) + -isotope [15N](3) permil 0.003676867 # Air +N(0) + -isotope [15N](0) permil 0.003676867 # Air +N(-3) + -isotope [15N](-3) permil 0.003676867 # Air +############################################################################################### +ISOTOPE_RATIOS +############################################################################################### +# +# Total aqueous ratios +# + R(D) D + R(T) T + R(18O) [18O] + R(13C) [13C] + R(14C) [14C] + R(15N) [15N] + R(34S) [34S] +# H2O(l) ratios + R(D)_H2O(l) D + R(T)_H2O(l) T + R(18O)_H2O(l) [18O] +# OH- ratios + R(D)_OH- D + R(T)_OH- T + R(18O)_OH- [18O] +# H3O+ ratios + R(D)_H3O+ D + R(T)_H3O+ T + R(18O)_H3O+ [18O] +# O2(aq) ratios + R(18O)_O2(aq) [18O] +# H2(aq) ratios + R(D)_H2(aq) D + R(T)_H2(aq) T +# CO2(aq) ratios + R(13C)_CO2(aq) [13C] + R(14C)_CO2(aq) [14C] + R(18O)_CO2(aq) [18O] +# HCO3- ratios + R(D)_HCO3- D + R(T)_HCO3- T + R(18O)_HCO3- [18O] + R(13C)_HCO3- [13C] + R(14C)_HCO3- [14C] +# CO3-2 ratios + R(18O)_CO3-2 [18O] + R(13C)_CO3-2 [13C] + R(14C)_CO3-2 [14C] +# CH4(aq) ratios + R(D)_CH4(aq) D + R(T)_CH4(aq) T + R(13C)_CH4(aq) [13C] + R(14C)_CH4(aq) [14C] +# SO4-2 ratios + R(34S)_SO4-2 [34S] +# HSO4- ratios + R(D)_HSO4- D + R(T)_HSO4- T + R(34S)_HSO4- [34S] +# S-2 ratios + R(34S)_S-2 [34S] +# HS- ratios + R(D)_HS- D + R(T)_HS- T + R(34S)_HS- [34S] +# H2S ratios + R(D)_H2S(aq) D + R(T)_H2S(aq) T + R(34S)_H2S(aq) [34S] +# NO3- ratios + R(15N)_NO3- [15N] +# NO2- ratios + R(15N)_NO2- [15N] +# N2(aq) ratios + R(15N)_N2(aq) [15N] +# NH3(aq) ratios + R(D)_NH3(aq) D + R(T)_NH3(aq) T + R(15N)_NH3(aq) [15N] +# NH4+ ratios + R(D)_NH4+ D + R(T)_NH4+ T + R(15N)_NH4+ [15N] +# +# Ratios for minerals and gases +# +# H2O(g) ratios + R(D)_H2O(g) D + R(T)_H2O(g) T + R(18O)_H2O(g) [18O] +# O2(g) ratios + R(18O)_O2(g) [18O] +# H2(g) ratios + R(D)_H2(g) D + R(T)_H2(g) T +# CO2(g) ratios + R(18O)_CO2(g) [18O] + R(13C)_CO2(g) [13C] + R(14C)_CO2(g) [14C] +# Calcite ratios + R(18O)_Calcite [18O] + R(13C)_Calcite [13C] + R(14C)_Calcite [14C] +# Pyrite ratios + R(34S)_Pyrite [34S] +# CH4(g) ratios + R(D)_CH4(g) D + R(T)_CH4(g) T + R(13C)_CH4(g) [13C] + R(14C)_CH4(g) [14C] +# H2S(g) ratios + R(D)_H2S(g) D + R(T)_H2S(g) T + R(34S)_H2S(g) [34S] +# Gypsum ratios + R(34S)_Gypsum [34S] +# Anhydrite ratios + R(34S)_Anhydrite [34S] +# N2(g) ratios + R(15N)_N2(g) [15N] +# NH3(g) ratios + R(D)_NH3(g) D + R(T)_NH3(g) T + R(15N)_NH3(g) [15N] + +ISOTOPE_ALPHAS +# OH- + Alpha_D_OH-/H2O(l) Log_alpha_D_OH-/H2O(l) + Alpha_T_OH-/H2O(l) Log_alpha_T_OH-/H2O(l) + Alpha_18O_OH-/H2O(l) Log_alpha_18O_OH-/H2O(l) +# H3O+ + Alpha_D_H3O+/H2O(l) Log_alpha_D_H3O+/H2O(l) + Alpha_T_H3O+/H2O(l) Log_alpha_T_H3O+/H2O(l) + Alpha_18O_H3O+/H2O(l) Log_alpha_18O_H3O+/H2O(l) +# O2(aq) + Alpha_18O_O2(aq)/H2O(l) Log_alpha_18O_O2(aq)/H2O(l) +# H2(aq) + Alpha_D_H2(aq)/H2O(l) Log_alpha_D_H2(aq)/H2O(l) + Alpha_T_H2(aq)/H2O(l) Log_alpha_T_H2(aq)/H2O(l) +# CO2(aq) + Alpha_18O_CO2(aq)/H2O(l) Log_alpha_18O_CO2(aq)/H2O(l) + Alpha_13C_CO2(aq)/CO2(g) Log_alpha_13C_CO2(aq)/CO2(g) + Alpha_14C_CO2(aq)/CO2(g) Log_alpha_14C_CO2(aq)/CO2(g) +# HCO3- + Alpha_D_HCO3-/H2O(l) Log_alpha_D_HCO3-/H2O(l) + Alpha_T_HCO3-/H2O(l) Log_alpha_T_HCO3-/H2O(l) + Alpha_18O_HCO3-/H2O(l) Log_alpha_18O_HCO3-/H2O(l) + Alpha_13C_HCO3-/CO2(aq) Log_alpha_13C_HCO3-/CO2(aq) + Alpha_14C_HCO3-/CO2(aq) Log_alpha_14C_HCO3-/CO2(aq) + Alpha_13C_HCO3-/CO2(g) Log_alpha_13C_HCO3-/CO2(g) + Alpha_14C_HCO3-/CO2(g) Log_alpha_14C_HCO3-/CO2(g) +# CO3-2 + Alpha_18O_CO3-2/H2O(l) Log_alpha_18O_CO3-2/H2O(l) + Alpha_13C_CO3-2/CO2(aq) Log_alpha_13C_CO3-2/CO2(aq) + Alpha_14C_CO3-2/CO2(aq) Log_alpha_14C_CO3-2/CO2(aq) + Alpha_13C_CO3-2/CO2(g) Log_alpha_13C_CO3-2/CO2(g) + Alpha_14C_CO3-2/CO2(g) Log_alpha_14C_CO3-2/CO2(g) +# CH4(aq) + Alpha_D_CH4(aq)/H2O(l) Log_alpha_D_CH4(aq)/H2O(l) + Alpha_T_CH4(aq)/H2O(l) Log_alpha_T_CH4(aq)/H2O(l) + Alpha_13C_CH4(aq)/CO2(aq) Log_alpha_13C_CH4(aq)/CO2(aq) + Alpha_14C_CH4(aq)/CO2(aq) Log_alpha_14C_CH4(aq)/CO2(aq) +# HSO4- + Alpha_D_HSO4-/H2O(l) Log_alpha_D_HSO4-/H2O(l) + Alpha_T_HSO4-/H2O(l) Log_alpha_T_HSO4-/H2O(l) + Alpha_34S_HSO4-/SO4-2 Log_alpha_34S_HSO4-/SO4-2 +# S-2 + Alpha_34S_S-2/HS- Log_alpha_34S_S-2/HS- +# HS- + Alpha_D_HS-/H2O(l) Log_alpha_D_HS-/H2O(l) + Alpha_T_HS-/H2O(l) Log_alpha_T_HS-/H2O(l) + Alpha_34S_HS-/SO4-2 Log_alpha_34S_HS-/SO4-2 +# H2S + Alpha_D_H2S(aq)/H2O(l) Log_alpha_D_H2S(aq)/H2O(l) + Alpha_T_H2S(aq)/H2O(l) Log_alpha_T_H2S(aq)/H2O(l) + Alpha_34S_H2S(aq)/HS- Log_alpha_34S_H2S(aq)/HS- +# NO2- + Alpha_15N_NO2-/NO3- Log_alpha_15N_NO2-/NO3- +# N2(aq) + Alpha_15N_N2(aq)/NO3- Log_alpha_15N_N2(aq)/NO3- +# NH3(aq) + Alpha_D_NH3(aq)/H2O(l) Log_alpha_D_NH3(aq)/H2O(l) + Alpha_T_NH3(aq)/H2O(l) Log_alpha_T_NH3(aq)/H2O(l) + Alpha_15N_NH3(aq)/NO3- Log_alpha_15N_NH3(aq)/NO3- +# NH4+ + Alpha_D_NH4+/H2O(l) Log_alpha_D_NH4+/H2O(l) + Alpha_T_NH4+/H2O(l) Log_alpha_T_NH4+/H2O(l) + Alpha_15N_NH4+/NH3(aq) Log_alpha_15N_NH4+/NH3(aq) +# H2O(g) + Alpha_D_H2O(g)/H2O(l) Log_alpha_D_H2O(g)/H2O(l) + Alpha_T_H2O(g)/H2O(l) Log_alpha_T_H2O(g)/H2O(l) + Alpha_18O_H2O(g)/H2O(l) Log_alpha_18O_H2O(g)/H2O(l) +# O2(g) + Alpha_18O_O2(g)/H2O(l) Log_alpha_18O_O2(g)/H2O(l) #? +# H2(g) + Alpha_D_H2(g)/H2O(l) Log_alpha_D_H2(g)/H2O(l) #? + Alpha_T_H2(g)/H2O(l) Log_alpha_T_H2(g)/H2O(l) #? +# CO2(g) + Alpha_18O_CO2(g)/H2O(l) Log_alpha_18O_CO2(g)/H2O(l) + Alpha_13C_CO2(g)/CO2(aq) Log_alpha_13C_CO2(g)/CO2(aq) + Alpha_14C_CO2(g)/CO2(aq) Log_alpha_14C_CO2(g)/CO2(aq) +# Calcite + Alpha_18O_Calcite/H2O(l) Log_alpha_18O_Calcite/H2O(l) + Alpha_13C_Calcite/CO2(aq) Log_alpha_13C_Calcite/CO2(aq) + Alpha_13C_Calcite/CO2(g) Log_alpha_13C_Calcite/CO2(g) + Alpha_14C_Calcite/CO2(aq) Log_alpha_14C_Calcite/CO2(aq) + Alpha_14C_Calcite/CO2(g) Log_alpha_14C_Calcite/CO2(g) +# Pyrite + Alpha_34S_Pyrite/HS- Log_alpha_34S_Pyrite/HS- +# CH4(g) + Alpha_D_CH4(g)/H2O(l) Log_alpha_D_CH4(g)/H2O(l) + Alpha_T_CH4(g)/H2O(l) Log_alpha_T_CH4(g)/H2O(l) + Alpha_13C_CH4(g)/CO2(aq) Log_alpha_13C_CH4(g)/CO2(aq) #? + Alpha_14C_CH4(g)/CO2(aq) Log_alpha_14C_CH4(g)/CO2(aq) #? +# H2S(g) + Alpha_D_H2S(g)/H2S(aq) Log_alpha_D_H2S(g)/H2S(aq) + Alpha_T_H2S(g)/H2S(aq) Log_alpha_T_H2S(g)/H2S(aq) + Alpha_34S_H2S(g)/H2S(aq) Log_alpha_34S_H2S(g)/H2S(aq) +# Gypsum + Alpha_34S_Gypsum/SO4-2 Log_alpha_34S_Gypsum/SO4-2 +# Anhydrite + Alpha_34S_Anhydrite/SO4-2 Log_alpha_34S_Anhydrite/SO4-2 +# N2(g) + Alpha_15N_N2(g)/N2(aq) Log_alpha_15N_N2(g)/N2(aq) +# NH3(g) + Alpha_D_NH3(g)/H2O(l) Log_alpha_D_NH3(g)/H2O(l) + #Alpha_T_NH3(g)/H2O(l) Log_alpha_T_NH3(g)/H2O(l) + Alpha_15N_NH3(g)/NH3(aq) Log_alpha_15N_NH3(g)/NH3(aq) + +NAMED_EXPRESSIONS +# +# OH- fractionation factors +# +Log_alpha_D_OH-/H2O(l) # 1000ln(alpha(25C)) = -741.9 + # 13.5 C + -ln_alpha1000 -741.9 # Heinzinger and Weston, J Phys Chem, 1964, p. 2179-2183 + # Modified August 22, 2008 + +Log_alpha_T_OH-/H2O(l) # 1000ln(alpha(13.5C)) = -1483.8 + # 13.5 C + -add_logk Log_alpha_D_OH-/H2O(l) 2 # Craig, J Geol, 1954, p 133. + # Modified August 22, 2008 + +Log_alpha_18O_OH-/H2O(l) # + # 25 C + -ln_alpha1000 -39.221 # Green and Taube, J Phys Chem, 1963, v 67, p. 1565-1566. + # 15 C + # -ln_alpha1000 -44.017 # Green and Taube, J Phys Chem, 1963, v 67, p. 1565-1566. + # Modified August 22, 2008 +# +# H3O+ fractionation factors +# +Log_alpha_D_H3O+/H2O(l) # + # 13.5 C + -ln_alpha1000 -364.6431 # Heinzinger and Weston, J Phys Chem, 1964, p. 744-751. + # Modified August 22, 2008 + +Log_alpha_T_H3O+/H2O(l) # 1000ln(alpha(13.5C)) = -799.286 + # 13.5 C + -add_logk Log_alpha_D_H3O+/H2O(l) 2 # Craig, J Geol, 1954, p 133. + # Modified August 22, 2008 + +Log_alpha_18O_H3O+/H2O(l) # 1000ln(alpha(25C)) = 22.9 + # 25 C + -ln_alpha1000 22.86 # Thorton, 1962 Am Chem Soc J, 1962, v 84, p. 2474-2475. + # Checked August 22, 2008 +# +# O2(aq) fractionation factors +# +Log_alpha_18O_O2(aq)/H2O(l) + -ln_alpha1000 0 # Unknown + +# +# H2(aq) fractionation factors +# +Log_alpha_D_H2(aq)/H2O(l) # 1000ln(alpha(25C)) = ??? + -add_logk Log_alpha_D_H2(g)/H2(aq) -1 + -add_logk Log_alpha_D_H2(g)/H2O(l) 1 + # Added August 22, 2008 + +Log_alpha_T_H2(aq)/H2O(l) + -add_logk Log_alpha_T_H2(g)/H2(aq) -1 + -add_logk Log_alpha_T_H2(g)/H2O(l) 1 + # Added August 22, 2008 +# +# CO2(aq) fractionation factors +# +Log_alpha_18O_CO2(aq)/H2O(l) # 1000ln(alpha(25C)) = 41.2 + # 0-100 C + -ln_alpha1000 -21.9285 0.0 19.43596e3 0.0 -0.181115e6 + +Log_alpha_13C_CO2(aq)/CO2(g) # 1000ln(alpha(25C)) -0.84 + # Deines and others (1974) + -ln_alpha1000 -0.91 0.0 0.0 0.0 .0063e6 + +Log_alpha_14C_CO2(aq)/CO2(g) # 1000ln(alpha(25C)) -0.84 + -add_logk Log_alpha_13C_CO2(aq)/CO2(g) 2 +# +# HCO3- fractionation factors +# +Log_alpha_18O_HCO3-/H2O(l) + -ln_alpha1000 0.0 #? + +Log_alpha_D_HCO3-/H2O(l) + -ln_alpha1000 0.0 + +Log_alpha_T_HCO3-/H2O(l) + -ln_alpha1000 0.0 + +Log_alpha_13C_HCO3-/CO2(g) # 1000ln(alpha(25C)) = 7.82 + # Deines and others (1974) + -ln_alpha1000 -4.54 0.0 0.0 0.0 1.099e6 + +Log_alpha_13C_HCO3-/CO2(aq) # 1000ln(alpha(25C)) = 8.7 + # 0-100 C +# -ln_alpha1000 -3.63 0.0 0.0 0.0 1.0927e6 + -add_logk Log_alpha_13C_HCO3-/CO2(g) 1 + -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 + +Log_alpha_14C_HCO3-/CO2(g) # 1000ln(alpha(25C)) = 7.82 + # Deines and others (1974) + -add_logk Log_alpha_13C_HCO3-/CO2(g) 2 + +Log_alpha_14C_HCO3-/CO2(aq) # 1000ln(alpha(25C)) = 17.3 + # 0-100 C +# -ln_alpha1000 -7.26 0.0 0.0 0.0 2.1854e6 + -add_logk Log_alpha_14C_HCO3-/CO2(g) 1 + -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 +# +# CO3-2 fractionation factors +# +Log_alpha_18O_CO3-2/H2O(l) + -ln_alpha1000 0.0 + +Log_alpha_13C_CO3-2/CO2(g) # 1000ln(alpha(25C)) + # Deines and others (1974) + -ln_alpha1000 -3.4 0.0 0.0 0.0 0.870e6 + +Log_alpha_13C_CO3-2/CO2(aq) # 1000ln(alpha(25C)) + # 0-100 C +# -ln_alpha1000 -2.49 0.0 0.0 0.0 0.8637e6 + -add_logk Log_alpha_13C_CO3-2/CO2(g) 1 + -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 + +Log_alpha_14C_CO3-2/CO2(g) # 1000ln(alpha(25C)) + # Deines and others (1974) + -add_logk Log_alpha_13C_CO3-2/CO2(g) 2 + +Log_alpha_14C_CO3-2/CO2(aq) # 1000ln(alpha(25C)) + # +# -ln_alpha1000 -2.49 0.0 0.0 0.0 0.8637e6 + -add_logk Log_alpha_14C_CO3-2/CO2(g) 1 + -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 +# +# CH4(aq) fractionation factors +# +Log_alpha_D_CH4(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_CH4(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_13C_CH4(aq)/CO2(aq) + -ln_alpha1000 0 + +Log_alpha_14C_CH4(aq)/CO2(aq) + -ln_alpha1000 0 +# +# HSO4- fractionation factors +# +Log_alpha_D_HSO4-/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_HSO4-/H2O(l) + -ln_alpha1000 0 + +Log_alpha_34S_HSO4-/SO4-2 + -ln_alpha1000 0.0 +# +# S-2 fractionation factors +# +Log_alpha_34S_S-2/HS- + -ln_alpha1000 0.0 +# +# HS- fractionation factors +# +Log_alpha_D_HS-/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_HS-/H2O(l) + -ln_alpha1000 0 + +Log_alpha_34S_HS-/SO4-2 + -ln_alpha1000 0.0 +# +# H2S fractionation factors +# +Log_alpha_D_H2S(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_H2S(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_34S_H2S(aq)/HS- + -ln_alpha1000 0.0 +# +# NO2- fractionation factors +# +Log_alpha_15N_NO2-/NO3- + -ln_alpha1000 0.0 +# +# N2(aq) fractionation factors +# +Log_alpha_15N_N2(aq)/NO3- + -ln_alpha1000 0.0 +# +# NH3(aq) fractionation factors +# +Log_alpha_D_NH3(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_NH3(aq)/H2O(l) + -ln_alpha1000 0 + +Log_alpha_15N_NH3(aq)/NO3- + -ln_alpha1000 0 +# +# NH4+ fractionation factors +# +Log_alpha_D_NH4+/H2O(l) + -ln_alpha1000 0 + +Log_alpha_T_NH4+/H2O(l) + -ln_alpha1000 0 + +Log_alpha_15N_NH4+/NH3(aq) + -ln_alpha1000 0 +# +# H2O(g) fractionation factors +# +Log_alpha_D_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -76.4 + # 0-100 C + -ln_alpha1000 -52.612 0.0 76.248e3 0.0 -24.844e6 + # Friedman and O'Neil: Majzoub, 1971, J Chim Phys, v 65, p. 563-568. + # Checked August 22, 2008 + +Log_alpha_T_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -152.7 + # 0-100 C + -add_logk Log_alpha_D_H2O(g)/H2O(l) 2 # Craig, J Geol, 1954, p 133. + # Modified August 22, 2008 + +Log_alpha_18O_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -9.3 + # 0-100 C + -ln_alpha1000 2.0667 0.0 0.4156e3 0.0 -1.137e6 + # Friedman and O'Neil: Majzoub, 1971, J Chim Phys, v 65, p. 563-568. + # Checked August 22, 2008 +# +# O2(g) fractionaton factors +# + +Log_alpha_18O_O2(g)/H2O(l) # Unknown + -ln_alpha1000 0.0 + +Log_alpha_18O_O2(g)/O2(aq) # 1000ln(alpha(25C)) = 0.6 + # 0.85 - 0.01TC 1-23C = 3.5815 - .01TK + -ln_alpha1000 3.5815 -.01 0 0 0 # Kroopnick and Craig, 1972, Science, v. 175, p. 54-55. + # Added August 22, 2008 +# +# H2(g) fractionaton factors +# +Log_alpha_D_H2O(g)/H2(g) # 1000ln(alpha(25C)) = 266. + -ln_alpha1000 -303.9 0.0 467.6e3 0.0 0.0 + # Friedman and O'Neil: Seuss, 1949, Zeitschrift Naturforschung + # Friedman and O'Neil: Battinga, 1969, Geochim Cosmochim Acta, v 33, p. 49-64. + # Added August 22, 2008 + +Log_alpha_T_H2O(g)/H2(g) # 1000ln(alpha(25C)) = 532. + -add_logk Log_alpha_D_H2O(g)/H2(g) 2 # Craig, J Geol, 1954, p 133. + # Added August 22, 2008 + +Log_alpha_D_H2(g)/H2(aq) # 1000ln(alpha(25C)) = 0 + -ln_alpha1000 0 # Assumed August 22, 2008 + +Log_alpha_T_H2(g)/H2(aq) # 1000ln(alpha(25C)) = 0 + -add_logk Log_alpha_T_H2(g)/H2(aq) 2 # Craig, J Geol, 1954, p 133. + # Added August 22, 2008 + +Log_alpha_D_H2(g)/H2O(l) # + -add_logk Log_alpha_D_H2O(g)/H2(g) -1 + -add_logk Log_alpha_D_H2O(g)/H2O(l) 1 + # Added August 22, 2008 + +Log_alpha_T_H2(g)/H2O(l) + -add_logk Log_alpha_T_H2O(g)/H2(g) -1 + -add_logk Log_alpha_T_H2O(g)/H2O(l) 1 + # Added August 22, 2008 + + + +# +# CO2(g) fractionaton factors +# +Log_alpha_18O_CO2(g)/H2O(l) # 1000ln(alpha(25C)) = 40.151 + # 0-100 C + -ln_alpha1000 -19.97 0.0 17.9942e3 0.0 -0.0206e6 + # Battinga, written commun. 1973, cited in Friedman and O'Neil + +Log_alpha_13C_CO2(g)/CO2(aq) # 1000ln(alpha(25C)) = 0.84 + # 0-100 C + -ln_alpha1000 0.91 0.0 0.0 0.0 -0.0063e6 + +Log_alpha_14C_CO2(g)/CO2(aq) # 1000ln(alpha(25C)) = 1.7 + # 0-100 C + -ln_alpha1000 1.82 0.0 0.0 0.0 -0.0126e6 +# +# CO2-Calcite fractionation factors +# +#Log_alpha_18O_CO2(aq)/Calcite # 1000ln(alpha(25C)) = 13.6 +# # 0-100 C +# -ln_alpha1000 -4.7383 0.0 12.05276e3 0.0 -1.963915e6 +Log_alpha_18O_Calcite/H2O(l) # 1000ln(alpha(25C)) = 28.38 + # O'Neil, Clayton and Mayeda (1969) + -ln_alpha1000 -2.89 0 0 0 2.78e6 + +Log_alpha_13C_Calcite/CO2(g) # 1000ln(alpha(25C)) + # Deines and others (1974) + -ln_alpha1000 -3.63 0.0 0.0 0.0 1.194e6 + +Log_alpha_13C_Calcite/CO2(aq) # 1000ln(alpha(25C)) + # Deines and others (1974) + -add_logk Log_alpha_13C_Calcite/CO2(g) 1 + -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 + +Log_alpha_14C_Calcite/CO2(g) # 1000ln(alpha(25C)) + -add_logk Log_alpha_13C_Calcite/CO2(g) 2 + +Log_alpha_14C_Calcite/CO2(aq) # 1000ln(alpha(25C)) + # Deines and others (1974) + -add_logk Log_alpha_14C_Calcite/CO2(g) 1 + -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 +# +# Pyrite fractionation factors +# +Log_alpha_34S_Pyrite/HS- + -ln_alpha1000 0 +# +# CH4(g) fractionation factors +# +Log_alpha_D_CH4(g)/H2O(l) #? + -ln_alpha1000 0.0 + +Log_alpha_T_CH4(g)/H2O(l) #? + -ln_alpha1000 0.0 + +Log_alpha_13C_CH4(g)/CO2(aq) #? + -ln_alpha1000 0.0 + +Log_alpha_14C_CH4(g)/CO2(aq) #? + -ln_alpha1000 0.0 +# +# H2S(g) fractionation factors +# +Log_alpha_D_H2S(g)/H2S(aq) + -ln_alpha1000 0 + +Log_alpha_T_H2S(g)/H2S(aq) + -ln_alpha1000 0 + +Log_alpha_34S_H2S(g)/H2S(aq) + -ln_alpha1000 0 +# +# Gypsum fractionation factors +# +Log_alpha_34S_Gypsum/SO4-2 + -ln_alpha1000 0 +# +# Anhydrite fractionation factors +# +Log_alpha_34S_Anhydrite/SO4-2 + -ln_alpha1000 0 +# +# N2(g) fractionation factors +# +Log_alpha_15N_N2(g)/N2(aq) + -ln_alpha1000 0 +# +# NH3(g) fractionation factors +# +Log_alpha_D_NH3(g)/H2O(l) #? + -ln_alpha1000 0 + +Log_alpha_T_NH3(g)/H2O(l) #? + -ln_alpha1000 0 + +Log_alpha_15N_NH3(g)/NH3(aq) + -ln_alpha1000 0 + +############################################################################################### +CALCULATE_VALUES +############################################################################################### +# +# Ratios +# +R(D) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = TOT("D") +40 total_H = TOT("H") +50 ratio = total_D/total_H +100 save ratio + -end + +R(T) ?? + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = TOT("T") +40 total_water = MOL("H2O") +50 ratio = total_T/total_water +100 save ratio + -end + +R(18O) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 total_18O = TOT("[18O]") +40 total_16O = TOT("O") +50 ratio = total_18O/total_16O +100 save ratio + -end + +R(13C) + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 100 +30 total_13C = TOT("[13C]") +40 total_12C = TOT("C") +50 ratio = total_13C/total_12C +100 save ratio + -end + +R(14C) + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 100 +30 total_14C = TOT("[14C]") +40 total_C = TOT("C") +50 ratio = total_14C/total_C +100 save ratio + -end + +R(15N) + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = TOT("[15N]") +40 total_14N = TOT("N") +50 ratio = total_15N/total_14N +100 save ratio + -end + +R(34S) + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 100 +30 total_34S = TOT("[34S]") +40 total_32S = TOT("S") +50 ratio = total_34S/total_32S +100 save ratio + -end +# +# H2O(l) ratios +# +R(D)_H2O(l) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("{H,D,T}2{O,[18O]}","D") +40 total_H = sum_species("{H,D,T}2{O,[18O]}","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_H2O(l) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{H,D,T}2{O,[18O]}","T") +40 total_H = sum_species("{H,D,T}2{O,[18O]}","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(18O)_H2O(l) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 total_18O = sum_species("{H,D,T}2[18O]","[18O]") +40 total_16O = sum_species("{H,D,T}2O","O") +50 if (total_16O <= 0) THEN GOTO 100 +60 ratio = total_18O/total_16O +100 save ratio + -end +# +# OH- ratios +# +R(D)_OH- + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("*{O,[18O]}D*","D") +40 total_H = sum_species("*{O,[18O]}H*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_OH- + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("*{O,[18O]}T*","T") +40 total_H = sum_species("*{O,[18O]}H*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(18O)_OH- + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 total_18O = sum_species("*[18O]{H,D,T}*","[18O]") +40 total_16O = sum_species("*O{H,D,T}*","O") +50 ratio = total_18O/total_16O +100 save ratio + -end + +# +# H3O+ ratios +# +R(D)_H3O+ + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("{H,D,T}3{O,[18O]}+","D") +40 total_H = sum_species("{H,D,T}3{O,[18O]}+","H") +50 ratio = total_D/total_H +100 save ratio + -end + +R(T)_H3O+ + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{H,D,T}3{O,[18O]}+","T") +40 total_H = sum_species("{H,D,T}3{O,[18O]}+","H") +50 ratio = total_T/total_H +100 save ratio + -end + +R(18O)_H3O+ + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 total_18O = sum_species("{H,D,T}3{O,[18O]}+","[18O]") +40 total_16O = sum_species("{H,D,T}3{O,[18O]}+","O") +50 ratio = total_18O/total_16O +100 save ratio + -end + +# +# O2(aq) ratios +# +R(18O)_O2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 total_18O = sum_species("{O,[18O]}2","[18O]") +40 total_O = sum_species("{O,[18O]}2","O") +50 if (total_O <= 0) THEN GOTO 100 +60 ratio = total_18O/total_O +100 save ratio + -end +# +# H2(aq) ratios +# +R(D)_H2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("{H,D,T}2","D") +40 total_H = sum_species("{H,D,T}2","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_H2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{H,D,T}2","T") +40 total_H = sum_species("{H,D,T}2","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end +# +# CO2(aq) ratios +# +R(13C)_CO2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 100 +30 total_13C = sum_species("[13C]{O,[18O]}2","[13C]") +40 total_12C = sum_species("C{O,[18O]}2","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_13C/total_12C +100 save ratio + -end + +R(14C)_CO2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 100 +30 total_14C = sum_species("[14C]{O,[18O]}2","[14C]") +40 total_12C = sum_species("C{O,[18O]}2","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_14C/total_12C +100 save ratio + -end + +R(18O)_CO2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 if (TOT("C") <= 0) THEN GOTO 100 +40 total_18O = sum_species("{C,[13C],[14C]}{O,[18O]}2","[18O]") +50 total_16O = sum_species("{C,[13C],[14C]}{O,[18O]}2","O") +60 if (total_16O <= 0) THEN GOTO 100 +70 ratio = total_18O/total_16O +100 save ratio + -end +# +# HCO3- ratios +# +R(D)_HCO3- + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 if (TOT("C") <= 0) THEN GOTO 100 +40 total_D = sum_species("*D{C,[13C],[14C]}{O,[18O]}3*","D") +50 total_H = sum_species("*H{C,[13C],[14C]}{O,[18O]}3*","H") +60 if (total_H <= 0) THEN GOTO 100 +70 ratio = total_D/total_H +100 save ratio + -end + +R(T)_HCO3- + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 if (TOT("C") <= 0) THEN GOTO 100 +40 total_T = sum_species("*T{C,[13C],[14C]}{O,[18O]}3*","T") +50 total_H = sum_species("*H{C,[13C],[14C]}{O,[18O]}3*","H") +60 if (total_H <= 0) THEN GOTO 100 +70 ratio = total_T/total_H +100 save ratio + -end + +R(18O)_HCO3- + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 if (TOT("C") <= 0) THEN GOTO 100 +40 total_18O = sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","[18O]") +50 total_16O = sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","O") +60 if (total_16O <= 0) THEN GOTO 100 +70 ratio = total_18O/total_16O +100 save ratio + -end + +R(13C)_HCO3- + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 100 +30 total_13C = sum_species("*{H,D,T}[13C]{O,[18O]}3*","[13C]") +40 total_12C = sum_species("*{H,D,T}C{O,[18O]}3*","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_13C/total_12C +100 save ratio + -end + +R(14C)_HCO3- + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 100 +30 total_14C = sum_species("*{H,D,T}[14C]{O,[18O]}3*","[14C]") +40 total_12C = sum_species("*{H,D,T}C{O,[18O]}3*","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_14C/total_12C +100 save ratio + -end +# +# CO3-2 ratios +# +R(18O)_CO3-2 + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 100 +30 if (TOT("C") <= 0) THEN GOTO 100 +40 total_18O = sum_species("*{C,[13C],[14C]}{O,[18O]}3*","[18O]") - sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","[18O]") +50 total_16O = sum_species("*{C,[13C],[14C]}{O,[18O]}3*","O") - sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","O") +60 if (total_16O <= 0) THEN GOTO 100 +70 ratio = total_18O/total_16O +100 save ratio + -end + +R(13C)_CO3-2 + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 100 +30 total_13C = sum_species("*[13C]{O,[18O]}3*","[13C]") - sum_species("*{H,D,T}[13C]{O,[18O]}3*","[13C]") +40 total_12C = sum_species("*C{O,[18O]}3*","C") - sum_species("*{H,D,T}C{O,[18O]}3*","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_13C/total_12C +100 save ratio + -end + +R(14C)_CO3-2 + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 100 +30 total_14C = sum_species("*[14C]{O,[18O]}3*","[14C]") - sum_species("*{H,D,T}[14C]{O,[18O]}3*","[14C]") +40 total_12C = sum_species("*C{O,[18O]}3*","C") - sum_species("*{H,D,T}C{O,[18O]}3*","C") +50 if (total_12C <= 0) THEN GOTO 100 +60 ratio = total_14C/total_12C +100 save ratio + -end +# +# CH4(aq) ratios +# +R(D)_CH4(aq) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("{C,[13C],[14C]}{H,D,T}4","D") +40 total_H = sum_species("{C,[13C],[14C]}{H,D,T}4","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_CH4(aq) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{C,[13C],[14C]}{H,D,T}4","T") +40 total_H = sum_species("{C,[13C],[14C]}{H,D,T}4","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(13C)_CH4(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 100 +30 total_13C = sum_species("[13C]{H,D,T}4","[13C]") +40 total_C = sum_species("C{H,D,T}4","C") +50 if (total_C <= 0) THEN GOTO 100 +60 ratio = total_13C/total_C +100 save ratio + -end + +R(14C)_CH4(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 100 +30 total_14C = sum_species("[14C]{H,D,T}4","[14C]") +40 total_C = sum_species("C{H,D,T}4","C") +50 if (total_C <= 0) THEN GOTO 100 +60 ratio = total_14C/total_C +100 save ratio + -end +# +# SO4-2 ratios +# +R(34S)_SO4-2 + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 100 +30 total_34S = sum_species("*[34S]O4*","[34S]") - sum_species("*{H,D,T}[34S]O4*","[34S]") +40 total_S = sum_species("*SO4*","S") - sum_species("*{H,D,T}SO4*","S") +50 if (total_S <= 0) THEN GOTO 100 +60 ratio = total_34S/total_S +100 save ratio + -end +# +# HSO4- ratios +# +R(D)_HSO4- + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("*D{S,[34S]}O4*","D") +40 total_H = sum_species("*H{S,[34S]}O4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_HSO4- + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("*T{S,[34S]}O4*","T") +40 total_H = sum_species("*H{S,[34S]}O4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(34S)_HSO4- + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 100 +30 total_34S = sum_species("*{H,D,T}[34S]O4*","[34S]") +40 total_S = sum_species("*{H,D,T}SO4*","S") +50 if (total_S <= 0) THEN GOTO 100 +60 ratio = total_34S/total_S +100 save ratio + -end +# +# S-2 ratios +# +R(34S)_S-2 + -start +10 ratio = -9999.999 +20 if (TOT("[34S](-2)") <= 0) THEN GOTO 100 +30 total_34S = MOL("[34S]-2") +40 total_S = MOL("S-2") +50 if (total_S <= 0) THEN GOTO 100 +60 ratio = total_34S/total_S +100 save ratio + -end +# +# HS- ratios +# +R(D)_HS- + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("*D{S,[34S]}*","D") - sum_species("*D{S,[34S]}O4*","D") +40 total_H = sum_species("*H{S,[34S]}*","H") - sum_species("*H{S,[34S]}O4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_HS- + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("*T{S,[34S]}*","T") - sum_species("*T{S,[34S]}O4*","T") +40 total_H = sum_species("*H{S,[34S]}*","H") - sum_species("*H{S,[34S]}O4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(34S)_HS- + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 100 +30 total_34S = sum_species("*{H,D,T}[34S]*","[34S]") - sum_species("*{H,D,T}[34S]O4*","[34S]") +40 total_S = sum_species("*{H,D,T}S*","S") - sum_species("*{H,D,T}SO4*","S") +50 if (total_S <= 0) THEN GOTO 100 +60 ratio = total_34S/total_S +100 save ratio + -end +# +# H2S ratios +# +R(D)_H2S(aq) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("*{H,D,T}2{S,[34S]}*","D") - sum_species("*{H,D,T}2{S,[34S]}O4*","D") +40 total_S = sum_species("*{H,D,T}2{S,[34S]}*","H") - sum_species("*{H,D,T}2{S,[34]}SO4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_H2S(aq) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{H,D,T}2{S,[34S]}","T") +40 total_H = sum_species("{H,D,T}2{S,[34S]}","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(34S)_H2S(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 100 +30 total_34S = sum_species("{H,D,T}2[34S]","[34S]") +40 total_S = sum_species("{H,D,T}2S","S") +50 if (total_S <= 0) THEN GOTO 100 +60 ratio = total_34S/total_S +100 save ratio + -end +# +# NO3- ratios +# +R(15N)_NO3- + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = TOT("[15N](5)") +40 total_N = TOT("N(5)") +50 if (total_N <= 0) THEN GOTO 100 +60 ratio = total_15N/total_N +100 save ratio + -end +# +# NO2- ratios +# +R(15N)_NO2- + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = TOT("[15N](3)") +40 total_N = TOT("N(3)") +50 if (total_N <= 0) THEN GOTO 100 +60 ratio = total_15N/total_N +100 save ratio + -end +# +# N2(aq) ratios +# +R(15N)_N2(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = TOT("[15N](0)") +40 total_N = TOT("N(0)") +50 if (total_N <= 0) THEN GOTO 100 +60 ratio = total_15N/total_N +100 save ratio + -end +# +# NH3(aq) ratios +# +R(D)_NH3(aq) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("{[15N],N}{H,D,T}3","D") +40 total_H = sum_species("{[15N],N}{H,D,T}3","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_NH3(aq) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("{[15N],N}{H,D,T}3","T") +40 total_H = sum_species("{[15N],N}{H,D,T}3","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(15N)_NH3(aq) + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = sum_species("[15N]{H,D,T}3","[15N]") +40 total_N = sum_species("N{H,D,T}3","N") +50 if (total_N <= 0) THEN GOTO 100 +60 ratio = total_15N/total_N +100 save ratio + -end +# +# NH4+ ratios +# +R(D)_NH4+ + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 100 +30 total_D = sum_species("*{[15N],N}{H,D,T}4*","D") +40 total_H = sum_species("*{[15N],N}{H,D,T}4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_D/total_H +100 save ratio + -end + +R(T)_NH4+ + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 100 +30 total_T = sum_species("*{[15N],N}{H,D,T}4*","T") +40 total_H = sum_species("*{[15N],N}{H,D,T}4*","H") +50 if (total_H <= 0) THEN GOTO 100 +60 ratio = total_T/total_H +100 save ratio + -end + +R(15N)_NH4+ + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 100 +30 total_15N = sum_species("*[15N]{H,D,T}4*","[15N]") +40 total_N = sum_species("*N{H,D,T}4*","N") +50 if (total_N <= 0) THEN GOTO 100 +60 ratio = total_15N/total_N +100 save ratio + -end +# +# Ratios for minerals and gases +# +# +# H2O(g) ratios +# +R(D)_H2O(g) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 total_D = SUM_GAS("{H,D,T}2{O,[18O]}", "D") +50 total_H = SUM_GAS("{H,D,T}2{O,[18O]}", "H") +60 if (total_h <= 0) THEN GOTO 1000 +70 ratio = total_D/total_H +1000 save ratio + -end + +R(T)_H2O(g) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 total_T = SUM_GAS("{H,D,T}2{O,[18O]}", "T") +50 total_H = SUM_GAS("{H,D,T}2{O,[18O]}", "H") +60 if (total_h <= 0) THEN GOTO 1000 +70 ratio = total_T/total_H +1000 save ratio + -end + +R(18O)_H2O(g) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 total_18O = SUM_GAS("{H,D,T}2[18O]", "[18O]") +50 total_O = SUM_GAS("{H,D,T}2O", "O") +60 if (total_O <= 0) THEN GOTO 1000 +70 ratio = total_18O/total_O +1000 save ratio + -end +# +# O2(g) ratios +# +R(18O)_O2(g) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 +40 total_18O = SUM_GAS("{O,[18O]}2", "[18O]") +50 total_O = SUM_GAS("{O,[18O]}2", "O") +60 if (total_O <= 0) THEN GOTO 1000 +70 ratio = total_18O/total_O +1000 save ratio + -end +# +# H2(g) ratios +# +R(D)_H2(g) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 total_D = SUM_GAS("{H,D,T}2", "D") +50 total_H = SUM_GAS("{H,D,T}2", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_D/total_H +1000 save ratio + -end + +R(T)_H2(g) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 total_T = SUM_GAS("{H,D,T}2", "T") +50 total_H = SUM_GAS("{H,D,T}2", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_T/total_H +1000 save ratio + -end +# +# CO2(g) ratios +# +R(18O)_CO2(g) + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 total_18O = SUM_GAS("{C,[13C],[14C]}{O,[18O]}2", "[18O]") +50 total_O = SUM_GAS("{C,[13C],[14C]}{O,[18O]}2", "O") +60 if (total_O <= 0) THEN GOTO 1000 +70 ratio = total_18O/total_O +1000 save ratio + -end + +R(13C)_CO2(g) + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[13C]O2(g)") <= 0) THEN GOTO 1000 +50 total_13C = SUM_GAS("[13C]{O,[18O]}2", "[13C]") +60 total_C = SUM_GAS("C{O,[18O]}2", "C") +70 if (total_C <= 0) THEN GOTO 1000 +80 ratio = total_13C/total_C +1000 save ratio + -end + +R(14C)_CO2(g) + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[14C]O2(g)") <= 0) THEN GOTO 1000 +50 total_14C = SUM_GAS("[14C]{O,[18O]}2", "[14C]") +60 total_C = SUM_GAS("C{O,[18O]}2", "C") +70 if (total_C <= 0) THEN GOTO 1000 +80 ratio = total_14C/total_C +1000 save ratio + -end +# +# Calcite ratios +# +R(18O)_Calcite + -start +10 ratio = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 total_18O = SUM_S_S("Calcite", "[18O]") +50 total_O = SUM_S_S("Calcite", "O") +60 if (total_O <= 0) THEN GOTO 1000 +70 ratio = total_18O/total_O +1000 save ratio + -end + +R(13C)_Calcite + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 total_13C = SUM_S_S("Calcite", "[13C]") +50 total_C = SUM_S_S("Calcite", "C") +60 if (total_C <= 0) THEN GOTO 1000 +70 ratio = total_13C/total_C +1000 save ratio + -end + +R(14C)_Calcite + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 total_14C = SUM_S_S("Calcite", "[14C]") +50 total_C = SUM_S_S("Calcite", "C") +60 if (total_C <= 0) THEN GOTO 1000 +70 ratio = total_14C/total_C +1000 save ratio + -end +# +# Pyrite ratios +# +R(34S)_Pyrite + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (S_S("Pyrite") <= 0) THEN GOTO 1000 +40 total_34S = SUM_S_S("Pyrite", "[34S]") +50 total_S = SUM_S_S("Pyrite", "S") +60 if (total_S <= 0) THEN GOTO 1000 +70 ratio = total_34S/total_S +1000 save ratio + -end +# +# CH4(g) ratios +# +R(D)_CH4(g) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 total_D = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "D") +50 total_H = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_D/total_H +1000 save ratio + -end + +R(T)_CH4(g) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 total_T = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "T") +50 total_H = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_T/total_H +1000 save ratio + -end + +R(13C)_CH4(g) + -start +10 ratio = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 total_13C = SUM_GAS("[13C]{H,D,T}4", "[13C]") +50 total_C = SUM_GAS("C{H,D,T}4", "C") +60 if (total_C <= 0) THEN GOTO 1000 +70 ratio = total_13C/total_C +1000 save ratio + -end + +R(14C)_CH4(g) + -start +10 ratio = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 total_14C = SUM_GAS("[14C]{H,D,T}4", "[14C]") +50 total_C = SUM_GAS("C{H,D,T}4", "C") +60 if (total_C <= 0) THEN GOTO 1000 +70 ratio = total_14C/total_C +1000 save ratio + -end +# +# H2S(g) ratios +# +R(D)_H2S(g) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 +40 total_D = SUM_GAS("{H,D,T}2{S,[34S]}", "D") +50 total_H = SUM_GAS("{H,D,T}2{S,[34S]}", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_D/total_H +1000 save ratio + -end + +R(T)_H2S(g) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 +40 total_T = SUM_GAS("{H,D,T}2{S,[34S]}", "T") +50 total_H = SUM_GAS("{H,D,T}2{S,[34S]}", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_T/total_H +1000 save ratio + -end + +R(34S)_H2S(g) + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 +40 total_34S = SUM_GAS("{H,D,T}2[34S]", "[34S]") +50 total_S = SUM_GAS("{H,D,T}2S", "S") +60 if (total_S <= 0) THEN GOTO 1000 +70 ratio = total_34S/total_S +1000 save ratio + -end +# +# Gypsum ratios +# +R(34S)_Gypsum + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (S_S("Gypsum") <= 0) THEN GOTO 1000 +40 total_34S = SUM_S_S("Gypsum", "[34S]") +50 total_S = SUM_S_S("Gypsum", "S") +60 if (total_S <= 0) THEN GOTO 1000 +70 ratio = total_34S/total_S +1000 save ratio + -end +# +# Anhydrite ratios +# +R(34S)_Anhydrite + -start +10 ratio = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (S_S("Anhydrite") <= 0) THEN GOTO 1000 +40 total_34S = SUM_S_S("Anhydrite", "[34S]") +50 total_S = SUM_S_S("Anhydrite", "S") +60 if (total_S <= 0) THEN GOTO 1000 +70 ratio = total_34S/total_S +1000 save ratio + -end +# +# N2(g) ratios +# +R(15N)_N2(g) + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (GAS("N2(g)") <= 0) THEN GOTO 1000 +40 total_15N = SUM_GAS("{[15N],N}2", "[15N]") +50 total_N = SUM_GAS("{[15N],N}2", "N") +60 if (total_N <= 0) THEN GOTO 1000 +70 ratio = total_15N/total_N +1000 save ratio + -end +# +# NH3(g) ratios +# +R(D)_NH3(g) + -start +10 ratio = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +40 total_D = SUM_GAS("{[15N],N}{H,D,T}3", "D") +50 total_H = SUM_GAS("{[15N],N}{H,D,T}3", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_D/total_H +1000 save ratio + -end + +R(T)_NH3(g) + -start +10 ratio = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +40 total_T = SUM_GAS("{[15N],N}{H,D,T}3", "T") +50 total_H = SUM_GAS("{[15N],N}{H,D,T}3", "H") +60 if (total_H <= 0) THEN GOTO 1000 +70 ratio = total_T/total_H +1000 save ratio + -end + +R(15N)_NH3(g) + -start +10 ratio = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +40 total_15N = SUM_GAS("[15N]{H,D,T}3", "[15N]") +50 total_N = SUM_GAS("N{H,D,T}3", "N") +60 if (total_N <= 0) THEN GOTO 1000 +70 ratio = total_15N/total_N +1000 save ratio + -end +############################################################################################### +CALCULATE_VALUES +############################################################################################### +# +# Alphas +# +# +# H2O(l) ratios +# +# +# OH- ratios +# +Alpha_D_OH-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(D)_OH-") +40 r2 = CALC_VALUE("R(D)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_OH-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(T)_OH-") +40 r2 = CALC_VALUE("R(T)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_OH-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(18O)_OH-") +40 r2 = CALC_VALUE("R(18O)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# H3O+ ratios +# +Alpha_D_H3O+/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(D)_H3O+") +40 r2 = CALC_VALUE("R(D)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H3O+/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(T)_H3O+") +40 r2 = CALC_VALUE("R(T)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_H3O+/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 r1 = CALC_VALUE("R(18O)_H3O+") +40 r2 = CALC_VALUE("R(18O)_H2O(l)") +50 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# O2(aq) ratios +# +Alpha_18O_O2(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(18O)_O2(aq)") +60 r2 = CALC_VALUE("R(18O)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# H2(aq) ratios +# +Alpha_D_H2(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2(aq)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2(aq)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# CO2(aq) ratios +# +Alpha_18O_CO2(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_CO2(aq)") +50 r2 = CALC_VALUE("R(18O)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CO2(aq)/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_CO2(aq)") +50 r2 = CALC_VALUE("R(13C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CO2(aq)/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_CO2(aq)") +50 r2 = CALC_VALUE("R(14C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# HCO3- ratios +# +Alpha_D_HCO3-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(D)_HCO3-") +50 r2 = CALC_VALUE("R(D)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_HCO3-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(T)_HCO3-") +50 r2 = CALC_VALUE("R(T)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_HCO3-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_HCO3-") +50 r2 = CALC_VALUE("R(18O)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_HCO3-/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_HCO3-") +50 r2 = CALC_VALUE("R(18O)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_HCO3-/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_HCO3-") +50 r2 = CALC_VALUE("R(13C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_HCO3-/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_HCO3-") +50 r2 = CALC_VALUE("R(13C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_HCO3-/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_HCO3-") +50 r2 = CALC_VALUE("R(14C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_HCO3-/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_HCO3-") +50 r2 = CALC_VALUE("R(14C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# CO3-2 ratios +# +Alpha_18O_CO3-2/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_CO3-2") +50 r2 = CALC_VALUE("R(18O)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_CO3-2/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_CO3-2") +50 r2 = CALC_VALUE("R(18O)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CO3-2/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_CO3-2") +50 r2 = CALC_VALUE("R(13C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CO3-2/CO2(aq) #? + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_CO3-2") +50 r2 = CALC_VALUE("R(13C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CO3-2/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_CO3-2") +50 r2 = CALC_VALUE("R(14C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CO3-2/CO2(aq) #? + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_CO3-2") +50 r2 = CALC_VALUE("R(14C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# CH4(aq) ratios +# +Alpha_D_CH4(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_CH4(aq)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_CH4(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_CH4(aq)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CH4(aq)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(13C)_CH4(aq)") +60 r2 = CALC_VALUE("R(13C)_CO2(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CH4(aq)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (TOT("C") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(14C)_CH4(aq)") +60 r2 = CALC_VALUE("R(14C)_CO2(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# HSO4-2 ratios +# +Alpha_D_HSO4-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_HSO4-") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_HSO4-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_HSO4-") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_34S_HSO4-/SO4-2 + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_HSO4-") +60 r2 = CALC_VALUE("R(34S)_SO4-2") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# S-2 ratios +# +Alpha_34S_S-2/HS- + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_S-2") +60 r2 = CALC_VALUE("R(34S)_HS-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +# +# HS- ratios +# +Alpha_D_HS-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_HS-") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_HS-/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_HS-") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_34S_HS-/SO4-2 + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +40 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_HS-") +60 r2 = CALC_VALUE("R(34S)_SO4-2") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# H2S ratios +# +Alpha_D_H2S(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2S(aq)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_D_H2S(aq)/HS- + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2S(aq)") +60 r2 = CALC_VALUE("R(D)_HS-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2S(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2S(aq)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2S(aq)/HS- + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2S(aq)") +60 r2 = CALC_VALUE("R(T)_HS-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_34S_H2S(aq)/HS- + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_H2S(aq)") +60 r2 = CALC_VALUE("R(34S)_HS-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# NO3- ratios +# +Alpha_15N_NO2-/NO3- + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(5)") <= 0) THEN GOTO 1000 +40 if (TOT("N(3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_NO2-") +60 r2 = CALC_VALUE("R(15N)_NO3-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# N2(aq) ratios +# +Alpha_15N_N2(aq)/NO3- + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(5)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_N2(aq)") +60 r2 = CALC_VALUE("R(15N)_NO3-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# NH3(aq) ratios +# +Alpha_D_NH3(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_NH3(aq)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_NH3(aq)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_NH3(aq)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_15N_NH3(aq)/NO3- + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_NH3(aq)") +60 r2 = CALC_VALUE("R(15)_NO3-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# NH4+ ratios +# +Alpha_D_NH4+/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_NH4+") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_NH4+/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_NH4+") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_15N_NH4+/NO3- + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(5)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_NH4+") +60 r2 = CALC_VALUE("R(15N)_NO3-") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_15N_NH4+/NH3(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(5)") <= 0) THEN GOTO 1000 +40 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_NH4+") +60 r2 = CALC_VALUE("R(15N)_NH3(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# Ratios for minerals and gases +# +# +# H2O(g) ratios +# +Alpha_D_H2O(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(D)_H2O(g)") +50 r2 = CALC_VALUE("R(D)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2O(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(T)_H2O(g)") +50 r2 = CALC_VALUE("R(T)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_H2O(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_H2O(g)") +50 r2 = CALC_VALUE("R(18O)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# O2(g) ratios +# +Alpha_18O_O2(aq)/O2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("O[18O](g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(18O)_O2(aq)") +60 r2 = CALC_VALUE("R(18O)_O2(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_O2(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("O[18O](g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(18O)_O2(g)") +60 r2 = CALC_VALUE("R(18O)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +# +# H2(g) ratios +# +Alpha_D_H2(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("HD(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2(g)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("HT(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2(g)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_D_H2(aq)/H2(g) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("HD(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2(aq)") +60 r2 = CALC_VALUE("R(D)_H2(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2(aq)/H2(g) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("HT(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2(aq)") +60 r2 = CALC_VALUE("R(T)_H2(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# CO2(g) ratios +# +Alpha_18O_CO2(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CO[18O](g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(18O)_CO2(g)") +60 r2 = CALC_VALUE("R(18O)_H2O(l)") +70 if (r1 <= 0) THEN GOTO 1000 +80 if (r2 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_CO2(g)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CO[18O](g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(18O)_CO2(g)") +60 r2 = CALC_VALUE("R(18O)_CO2(aq)") +70 if (r1 <= 0) THEN GOTO 1000 +80 if (r2 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CO2(g)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[13C]O2(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(13C)_CO2(g)") +60 r2 = CALC_VALUE("R(13C)_CO2(aq)") +70 if (r1 <= 0) THEN GOTO 1000 +80 if (r2 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CO2(g)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[134]O2(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(14C)_CO2(g)") +60 r2 = CALC_VALUE("R(14C)_CO2(aq)") +70 if (r1 <= 0) THEN GOTO 1000 +80 if (r2 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# Calcite ratios +# +Alpha_18O_Calcite/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_Calcite") +50 r2 = CALC_VALUE("R(18O)_H2O(l)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_18O_Calcite/CO3-2 + -start +10 alpha = -9999.999 +20 if (TOT("[18O]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(18O)_Calcite") +50 r2 = CALC_VALUE("R(18O)_CO3-2") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_Calcite/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +35 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_Calcite") +50 r2 = CALC_VALUE("R(13C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_Calcite/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_Calcite") +50 r2 = CALC_VALUE("R(13C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_Calcite/CO3-2 + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(13C)_Calcite") +50 r2 = CALC_VALUE("R(13C)_CO3-2") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_Calcite/CO2(g) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +35 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_Calcite") +50 r2 = CALC_VALUE("R(14C)_CO2(g)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_Calcite/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_Calcite") +50 r2 = CALC_VALUE("R(14C)_CO2(aq)") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_Calcite/CO3-2 + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (S_S("Calcite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(14C)_Calcite") +50 r2 = CALC_VALUE("R(14C)_CO3-2") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# Pyrite ratios +# +Alpha_34S_Pyrite/HS- + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (S_S("Pyrite") <= 0) THEN GOTO 1000 +40 r1 = CALC_VALUE("R(34S)_Pyrite") +50 r2 = CALC_VALUE("R(34S)_HS-") +60 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# CH4(g) ratios +# +Alpha_D_CH4(aq)/CH4(g) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CH3D(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_CH4(aq)") +60 r2 = CALC_VALUE("R(D)_CH4(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_D_CH4(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CH3D(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_CH4(g)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_CH4(aq)/CH4(g) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CH3T(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_CH4(aq)") +60 r2 = CALC_VALUE("R(T)_CH4(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_CH4(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("CH3T(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_CH4(g)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CH4(g)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[13C]H4(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(13C)_CH4(g)") +60 r2 = CALC_VALUE("R(13C)_CO2(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_13C_CH4(aq)/CH4(g) + -start +10 alpha = -9999.999 +20 if (TOT("[13C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[13C]H4(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(13C)_CH4(aq)") +60 r2 = CALC_VALUE("R(13C)_CH4(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CH4(g)/CO2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[14C]H4(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(14C)_CH4(g)") +60 r2 = CALC_VALUE("R(14C)_CO2(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_14C_CH4(aq)/CH4(g) + -start +10 alpha = -9999.999 +20 if (TOT("[14C]") <= 0) THEN GOTO 1000 +30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 +40 if (GAS("[14C]H4(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(14C)_CH4(aq)") +60 r2 = CALC_VALUE("R(14C)_CH4(g)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# H2S(g) ratios +# +Alpha_D_H2S(g)/H2S(aq) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_H2S(g)") +60 r2 = CALC_VALUE("R(D)_H2S(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_H2S(g)/H2S(aq) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_H2S(g)") +60 r2 = CALC_VALUE("R(T)_H2S(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_34S_H2S(g)/H2S(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_H2S(g)") +60 r2 = CALC_VALUE("R(34S)_H2S(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# Gypsum ratios +# +Alpha_34S_Gypsum/SO4-2 + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +40 if (S_S("Gypsum") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_Gypsum") +60 r2 = CALC_VALUE("R(34S)_SO4-2") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# Anhydrite ratios +# +Alpha_34S_Anhydrite/SO4-2 + -start +10 alpha = -9999.999 +20 if (TOT("[34S]") <= 0) THEN GOTO 1000 +30 if (TOT("S(6)") <= 0) THEN GOTO 1000 +40 if (S_S("Anhydrite") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(34S)_Anhydrite") +60 r2 = CALC_VALUE("R(34S)_SO4-2") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# N2(g) ratios +# +Alpha_15N_N2(g)/N2(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(0)") <= 0) THEN GOTO 1000 +40 if (GAS("N2(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_N2(g)") +60 r2 = CALC_VALUE("R(15N)_N2(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +# +# NH3(g) ratios +# +Alpha_D_NH3(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("D") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(D)_NH3(g)") +60 r2 = CALC_VALUE("R(D)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_T_NH3(g)/H2O(l) + -start +10 alpha = -9999.999 +20 if (TOT("T") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(T)_NH3(g)") +60 r2 = CALC_VALUE("R(T)_H2O(l)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end + +Alpha_15N_NH3(g)/NH3(aq) + -start +10 alpha = -9999.999 +20 if (TOT("[15N]") <= 0) THEN GOTO 1000 +30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 +40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 +50 r1 = CALC_VALUE("R(15N)_NH3(g)") +60 r2 = CALC_VALUE("R(15N)_NH3(aq)") +70 if (r2 <= 0) THEN GOTO 1000 +80 if (r1 <= -9999) THEN GOTO 1000 +90 alpha = r1/r2 +1000 save alpha + -end +############################################################################################### +SOLUTION_SPECIES +############################################################################################### +D2O = D2O + -activity_water + log_k 0 + +HTO = HTO + -activity_water + log_k 0 + +H2[18O] = H2[18O] + -activity_water + log_k 0 + +CO2 = CO2 + log_k 0 + +[13C]O2 = [13C]O2 + log_k 0 + +[14C]O2 = [14C]O2 + log_k 0 + +[34S]O4-2 = [34S]O4-2 + log_k 0.0 + -gamma 5.0000 -0.0400 + +[15N]O3- = [15N]O3- + log_k 0.0 + -gamma 3.0000 0.0000 + +# +# H2O reactions +# last update July 31, 2006 +# checked September 19, 2006 +# +0.5H2O + 0.5D2O = HDO + log_k 0.301029995663 # log10(2) + -activity_water + +HDO + HTO = DTO + H2O + -mole_balance DTO + log_k -0.301029995663 # log10(1/2) + -activity_water + +2HTO = T2O + H2O + -mole_balance T2O + log_k -0.6020599913279623960 # log10(1/4) + -activity_water + +H2[18O] + HDO = HD[18O] + H2O + -mole_balance HD[18O] + log_k 0.0 + -activity_water + +H2[18O] + HTO = HT[18O] + H2O + -mole_balance HT[18O] + log_k 0.0 + -activity_water + +DTO + H2[18O] = DT[18O] + H2O + -mole_balance DT[18O] + log_k 0.0 + -activity_water + +D2O + H2[18O] = D2[18O] + H2O + -mole_balance D2[18O] + log_k 0.0 + -activity_water + +H2[18O] + T2O = T2[18O] + H2O + -mole_balance T2[18O] + log_k 0.0 + -activity_water +# +# OH- reactions +# last update July 31, 2006 +# checked September 19, 2006 +# +OH- + HDO = OD- + H2O + -mole_balance OD + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_D_OH-/H2O(l) 1.0 + -gamma 3.5000 0.0000 + +OH- + HTO = OT- + H2O + -mole_balance OT + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_T_OH-/H2O(l) 1.0 + -gamma 3.5000 0.0000 + +OH- + H2[18O] = [18O]H- + H2O + -mole_balance [18O]H + -add_logk Log_alpha_18O_OH-/H2O(l) 1.0 + -gamma 3.5000 0.0000 + +[18O]H- + OD- = [18O]D- + OH- + -mole_balance [18O]D + log_k 0.0 + -gamma 3.5000 0.0000 + +[18O]H- + OT- = [18O]T- + OH- + -mole_balance [18O]T + log_k 0.0 + -gamma 3.5000 0.0000 +# +# H3O+ reactions +# last update July 31, 2006 +# checked September 19, 2006 +# +H3O+ + HDO = H2DO+ + H2O + -mole_balance H2DO + log_k 0.176091259055 # log10(1.5) + -add_logk Log_alpha_D_H3O+/H2O(l) 1.0 + -gamma 9.0000 0.0000 + +2H2DO+ = HD2O+ + H3O+ + -mole_balance HD2O + log_k -0.477121254719662 # log10(1/3) + -gamma 9.0000 0.0000 + +H2DO+ + HD2O+ = D3O+ + H3O+ + -mole_balance D3O + log_k -0.954242509439324 # log10(1/9) + -gamma 9.0000 0.0000 + +H3O+ + HTO = H2TO+ + H2O + -mole_balance H2TO + log_k 0.176091259055 # log10(1.5) + -add_logk Log_alpha_T_H3O+/H2O(l) 1.0 + -gamma 9.0000 0.0000 + +2H2TO+ = HT2O+ + H3O+ + -mole_balance HT2O + log_k -0.477121254719662 # log10(1/3) + -gamma 9.0000 0.0000 + +H2TO+ + HT2O+ = T3O+ + H3O+ + -mole_balance T3O + log_k -0.954242509439324 # log10(1/9) + -gamma 9.0000 0.0000 + +H2TO+ + H2DO+ = HDTO+ + H3O+ + -mole_balance HDTO + log_k -0.477121254719662 # log10(1/3) + -gamma 9.0000 0.0000 + +H2TO+ + HD2O+ = D2TO+ + H3O+ + -mole_balance D2TO + log_k -0.477121254719662 # log10(1/3) + -gamma 9.0000 0.0000 + +H2DO+ + HT2O+ = DT2O+ + H3O+ + -mole_balance DT2O + log_k -0.477121254719662 # log10(1/3) + -gamma 9.0000 0.0000 + +H3O+ + H2[18O] = H3[18O]+ + H2O + -mole_balance H3[18O] + -add_logk Log_alpha_18O_H3O+/H2O(l) 1.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + H2DO+ = H2D[18O]+ + H3O+ + -mole_balance H2D[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + HD2O+ = HD2[18O]+ + H3O+ + -mole_balance HD2[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + D3O+ = D3[18O]+ + H3O+ + -mole_balance D3[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + H2TO+ = H2T[18O]+ + H3O+ + -mole_balance H2T[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + HT2O+ = HT2[18O]+ + H3O+ + -mole_balance HT2[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + T3O+ = T3[18O]+ + H3O+ + -mole_balance T3[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + HDTO+ = HDT[18O]+ + H3O+ + -mole_balance HDT[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + D2TO+ = D2T[18O]+ + H3O+ + -mole_balance D2T[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +H3[18O]+ + DT2O+ = DT2[18O]+ + H3O+ + -mole_balance DT2[18O] + log_k 0.0 + -gamma 9.0000 0.0000 + +# +# O2 reactions +# last update July 31, 2006 +# checked September 19, 2006 +# + +O2 + H2[18O] = O[18O] + H2O + log_k 0.301029995663 # log10(2) + -add_logk Log_alpha_18O_O2(aq)/H2O(l) 1.0 + -mole_balance O(0)[18O](0) + +2O[18O] = [18O]2 + O2 + log_k -0.602059991327962396 # -log10(4) + -mole_balance [18O](0)2 +# +# H2 reactions +# last update July 31, 2006 +# checked September 19, 2006 +# +H2 + HDO = HD + H2O + -mole_balance H(0)D(0) + -add_logk Log_alpha_D_H2(aq)/H2O(l) 1.0 + +2HD = D2 + H2 + -mole_balance D(0)2 + log_k -0.602059991327962396 # -log10(4) + +H2 + HTO = HT + H2O + -mole_balance H(0)T(0) + -add_logk Log_alpha_T_H2(aq)/H2O(l) 1.0 + +2HT = T2 + H2 + -mole_balance T(0)2 + log_k -0.602059991327962396 # -log10(4) + +HT + HD = DT + H2 + -mole_balance D(0)T(0) + log_k -0.301029995663 # -log10(2) +# +# CO2 reactions +# last update July 31, 2006 +# Checked September 19, 2006 +# +CO2 + H2[18O] = CO[18O] + H2O + log_k 0.301029995663 # log10(2) + -add_logk Log_alpha_18O_CO2(aq)/H2O(l) 1.0 + +2CO[18O] = C[18O]2 + CO2 + log_k -0.6020599913279623960 # log10(1/4) + +[13C]O2 + CO[18O] = [13C]O[18O] + CO2 + log_k 0 + +[13C]O2 + C[18O]2 = [13C][18O]2 + CO2 + log_k 0 + +[14C]O2 + CO[18O] = [14C]O[18O] + CO2 + log_k 0 + +[14C]O2 + C[18O]2 = [14C][18O]2 + CO2 + log_k 0 +# +# HCO3- reactions +# last update July 31, 2006 +# Checked September 19, 2006 +# +HCO3- + H2[18O] = HCO2[18O]- + H2O + -add_logk Log_alpha_18O_HCO3-/H2O(l) 1.0 + +HCO2[18O]- = HCO[18O]O- +HCO2[18O]- = HC[18O]O2- +2HCO2[18O]- = HCO[18O]2- + HCO3- +HCO[18O]2- = HC[18O]O[18O]- +HCO[18O]2- = HC[18O]2O- +3HCO2[18O]- = HC[18O]3- + 2HCO3- + +HDO + HCO3- = DCO3- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_D_HCO3-/H2O(l) 1.0 + +DCO3- + HCO2[18O]- = DCO2[18O]- + HCO3- +DCO3- + HCO[18O]O- = DCO[18O]O- + HCO3- +DCO3- + HC[18O]O2- = DC[18O]O2- + HCO3- +DCO3- + HCO[18O]2- = DCO[18O]2- + HCO3- +DCO3- + HC[18O]O[18O]- = DC[18O]O[18O]- + HCO3- +DCO3- + HC[18O]2O- = DC[18O]2O- + HCO3- +DCO3- + HC[18O]3- = DC[18O]3- + HCO3- + +HTO + HCO3- = TCO3- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_T_HCO3-/H2O(l) 1.0 + +TCO3- + HCO2[18O]- = TCO2[18O]- + HCO3- +TCO3- + HCO[18O]O- = TCO[18O]O- + HCO3- +TCO3- + HC[18O]O2- = TC[18O]O2- + HCO3- +TCO3- + HCO[18O]2- = TCO[18O]2- + HCO3- +TCO3- + HC[18O]O[18O]- = TC[18O]O[18O]- + HCO3- +TCO3- + HC[18O]2O- = TC[18O]2O- + HCO3- +TCO3- + HC[18O]3- = TC[18O]3- + HCO3- + +HCO3- + [13C]O2 = H[13C]O3- + CO2 + -add_logk Log_alpha_13C_HCO3-/CO2(aq) 1.0 + +H[13C]O3- + HCO2[18O]- = H[13C]O2[18O]- + HCO3- +H[13C]O3- + HCO[18O]O- = H[13C]O[18O]O- + HCO3- +H[13C]O3- + HC[18O]O2- = H[13C][18O]O2- + HCO3- +H[13C]O3- + HCO[18O]2- = H[13C]O[18O]2- + HCO3- +H[13C]O3- + HC[18O]O[18O]- = H[13C][18O]O[18O]- + HCO3- +H[13C]O3- + HC[18O]2O- = H[13C][18O]2O- + HCO3- +H[13C]O3- + HC[18O]3- = H[13C][18O]3- + HCO3- +DCO3- + H[13C]O3- = D[13C]O3- + HCO3- +H[13C]O3- + DCO2[18O]- = D[13C]O2[18O]- + HCO3- +H[13C]O3- + DCO[18O]O- = D[13C]O[18O]O- + HCO3- +H[13C]O3- + DC[18O]O2- = D[13C][18O]O2- + HCO3- +H[13C]O3- + DCO[18O]2- = D[13C]O[18O]2- + HCO3- +H[13C]O3- + DC[18O]O[18O]- = D[13C][18O]O[18O]- + HCO3- +H[13C]O3- + DC[18O]2O- = D[13C][18O]2O- + HCO3- +H[13C]O3- + DC[18O]3- = D[13C][18O]3- + HCO3- +TCO3- + H[13C]O3- = T[13C]O3- + HCO3- +H[13C]O3- + TCO2[18O]- = T[13C]O2[18O]- + HCO3- +H[13C]O3- + TCO[18O]O- = T[13C]O[18O]O- + HCO3- +H[13C]O3- + TC[18O]O2- = T[13C][18O]O2- + HCO3- +H[13C]O3- + TCO[18O]2- = T[13C]O[18O]2- + HCO3- +H[13C]O3- + TC[18O]O[18O]- = T[13C][18O]O[18O]- + HCO3- +H[13C]O3- + TC[18O]2O- = T[13C][18O]2O- + HCO3- +H[13C]O3- + TC[18O]3- = T[13C][18O]3- + HCO3- + +HCO3- + [14C]O2 = H[14C]O3- + CO2 + -add_logk Log_alpha_14C_HCO3-/CO2(aq) 1.0 + +H[14C]O3- + HCO2[18O]- = H[14C]O2[18O]- + HCO3- +H[14C]O3- + HCO[18O]O- = H[14C]O[18O]O- + HCO3- +H[14C]O3- + HC[18O]O2- = H[14C][18O]O2- + HCO3- +H[14C]O3- + HCO[18O]2- = H[14C]O[18O]2- + HCO3- +H[14C]O3- + HC[18O]O[18O]- = H[14C][18O]O[18O]- + HCO3- +H[14C]O3- + HC[18O]2O- = H[14C][18O]2O- + HCO3- +H[14C]O3- + HC[18O]3- = H[14C][18O]3- + HCO3- +DCO3- + H[14C]O3- = D[14C]O3- + HCO3- +H[14C]O3- + DCO2[18O]- = D[14C]O2[18O]- + HCO3- +H[14C]O3- + DCO[18O]O- = D[14C]O[18O]O- + HCO3- +H[14C]O3- + DC[18O]O2- = D[14C][18O]O2- + HCO3- +H[14C]O3- + DCO[18O]2- = D[14C]O[18O]2- + HCO3- +H[14C]O3- + DC[18O]O[18O]- = D[14C][18O]O[18O]- + HCO3- +H[14C]O3- + DC[18O]2O- = D[14C][18O]2O- + HCO3- +H[14C]O3- + DC[18O]3- = D[14C][18O]3- + HCO3- +TCO3- + H[14C]O3- = T[14C]O3- + HCO3- +H[14C]O3- + TCO2[18O]- = T[14C]O2[18O]- + HCO3- +H[14C]O3- + TCO[18O]O- = T[14C]O[18O]O- + HCO3- +H[14C]O3- + TC[18O]O2- = T[14C][18O]O2- + HCO3- +H[14C]O3- + TCO[18O]2- = T[14C]O[18O]2- + HCO3- +H[14C]O3- + TC[18O]O[18O]- = T[14C][18O]O[18O]- + HCO3- +H[14C]O3- + TC[18O]2O- = T[14C][18O]2O- + HCO3- +H[14C]O3- + TC[18O]3- = T[14C][18O]3- + HCO3- +# +# CO3-2 reactions +# last update July 31, 2006 +# Checked September 19, 2006 +# +CO3-2 + H2[18O] = CO2[18O]-2 + H2O + log_k 0.477121254719 # log10(3) + -add_logk Log_alpha_18O_CO3-2/H2O(l) 1.0 + +2CO2[18O]-2 = CO[18O]2-2 + CO3-2 + log_k -0.477121254719 # -log10(3) + +CO2[18O]-2 + CO[18O]2-2 = C[18O]3-2 + CO3-2 + log_k -0.954242509439324 # log10(1/9) + +CO3-2 + [13C]O2 = [13C]O3-2 + CO2 + -add_logk Log_alpha_13C_CO3-2/CO2(aq) 1.0 + +[13C]O3-2 + CO2[18O]-2 = [13C]O2[18O]-2 + CO3-2 + log_k 0.0 + +[13C]O3-2 + CO[18O]2-2 = [13C]O[18O]2-2 + CO3-2 + log_k 0.0 + +[13C]O3-2 + C[18O]3-2 = [13C][18O]3-2 + CO3-2 + log_k 0.0 + +CO3-2 + [14C]O2 = [14C]O3-2 + CO2 + -add_logk Log_alpha_14C_CO3-2/CO2(aq) 1.0 + +[14C]O3-2 + CO2[18O]-2 = [14C]O2[18O]-2 + CO3-2 + log_k 0.0 + +[14C]O3-2 + CO[18O]2-2 = [14C]O[18O]2-2 + CO3-2 + log_k 0.0 + +[14C]O3-2 + C[18O]3-2 = [14C][18O]3-2 + CO3-2 + log_k 0.0 +# +# CH4 reactions +# Updated September 19, 2006 +# Checked September 19, 2006 +# +CH4 + HDO = CH3D + H2O + log_k 0.301029995663981198 # log10(2) + -add_logk Log_alpha_D_CH4(aq)/H2O(l) 1.0 + +2CH3D = CH2D2 + CH4 + log_k -0.42596873227228 # log10(3/8) + +3CH3D = CHD3 + 2CH4 + log_k -1.20411998265 # log10(1/16) + +4CH3D = CD4 + 3CH4 + log_k -2.408239965311 # log10(1/256) + +CH4 + HTO = CH3T + H2O + log_k 0.301029995663981198 # log10(2) + -add_logk Log_alpha_T_CH4(aq)/H2O(l) 1.0 + +2CH3T = CH2T2 + CH4 + log_k -0.42596873227228 # log10(3/8) + +3CH3T = CHT3 + 2CH4 + log_k -1.20411998265 # log10(1/16) + +4CH3T = CT4 + 3CH4 + log_k -2.408239965311 # log10(1/256) +# +# Added mixed DT C methane species May 19, 2006 +# +CH3T + CHD3 = CD3T + CH4 + log_k -0.602059991327962396 # -log10(4) + +CH2T2 + CH2D2 = CD2T2 + CH4 + log_k -0.7781512503836 # -log10(6) + +CHT3 + CH3D = CDT3 + CH4 + log_k -0.602059991327962396 # -log10(4) + +[13C]O2 + CH4 = [13C]H4 + CO2 + -add_logk Log_alpha_13C_CH4(aq)/CO2(aq) 1.0 + +[13C]H4 + CH3D = [13C]H3D + CH4 +[13C]H4 + CH2D2 = [13C]H2D2 + CH4 +[13C]H4 + CHD3 = [13C]HD3 + CH4 +[13C]H4 + CD4 = [13C]D4 + CH4 +[13C]H4 + CH3T = [13C]H3T + CH4 +[13C]H4 + CH2T2 = [13C]H2T2 + CH4 +[13C]H4 + CHT3 = [13C]HT3 + CH4 +[13C]H4 + CT4 = [13C]T4 + CH4 +[13C]H4 + CD3T = [13C]D3T + CH4 +[13C]H4 + CD2T2 = [13C]D2T2 + CH4 +[13C]H4 + CDT3 = [13C]DT3 + CH4 + +[14C]O2 + CH4 = [14C]H4 + CO2 + -add_logk Log_alpha_14C_CH4(aq)/CO2(aq) 1.0 +# +# Added mixed DT 14C methane species May 19, 2006 +# +[14C]H4 + CH3D = [14C]H3D + CH4 +[14C]H4 + CH2D2 = [14C]H2D2 + CH4 +[14C]H4 + CHD3 = [14C]HD3 + CH4 +[14C]H4 + CD4 = [14C]D4 + CH4 +[14C]H4 + CH3T = [14C]H3T + CH4 +[14C]H4 + CH2T2 = [14C]H2T2 + CH4 +[14C]H4 + CHT3 = [14C]HT3 + CH4 +[14C]H4 + CT4 = [14C]T4 + CH4 +[14C]H4 + CD3T = [14C]D3T + CH4 +[14C]H4 + CD2T2 = [14C]D2T2 + CH4 +[14C]H4 + CDT3 = [14C]DT3 + CH4 +# +# HSO4- reactions +# Updated September 28, 2006 +# Checked September 28, 2006 +# +HSO4- + HDO = DSO4- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_D_HSO4-/H2O(l) 1.0 + -mole_balance DS(6)O4- + +HSO4- + HTO = TSO4- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_T_HSO4-/H2O(l) 1.0 + -mole_balance TS(6)O4- + +[34S]O4-2 + HSO4- = H[34S]O4- + SO4-2 + -add_logk Log_alpha_34S_HSO4-/SO4-2 1.0 + -mole_balance H[34S](6)O4- + +H[34S]O4- + DSO4- = D[34S]O4- + HSO4- + -mole_balance D[34S](6)O4 + +H[34S]O4- + TSO4- = T[34S]O4- + HSO4- + -mole_balance T[34S](6)O4- +# +# S-2 reactions +# +S-2 + H[34S]- = [34S]-2 + HS- + -add_logk Log_alpha_34S_S-2/HS- 1.0 + -mole_balance [34S](-2) + -gamma 5.0000 0.0000 +# +# HS- reactions +# +HS- + HDO = DS- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_D_HS-/H2O(l) 1.0 + -mole_balance DS(-2) + -gamma 3.5000 0.0000 + +HS- + HTO = TS- + H2O + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_T_HS-/H2O(l) 1.0 + -mole_balance TS(-2) + -gamma 3.5000 0.0000 + +HS- + [34S]O4-2 = H[34S]- + SO4-2 + -add_logk Log_alpha_34S_HS-/SO4-2 1.0 + -mole_balance H[34S](-2) + -gamma 3.5000 0.0000 + +H[34S]- + DS- = D[34S]- + HS- + -gamma 3.5000 0.0000 + -mole_balance D[34S](-2) + +H[34S]- + TS- = T[34S]- + HS- + -gamma 3.5000 0.0000 + -mole_balance T[34S](-2) +# +# H2S reactions +# +H2S + HDO = HDS + H2O + -add_logk Log_alpha_D_H2S(aq)/H2O(l) 1.0 + -mole_balance HDS(-2) + +2HDS = D2S + H2S + log_k -0.602059991327962396 # -log10(4) + -mole_balance D2S(-2) + +H2S + HTO = HTS + H2O + -add_logk Log_alpha_T_H2S(aq)/H2O(l) 1.0 + -mole_balance HTS(-2) + +2HTS = T2S + H2S + log_k -0.602059991327962396 # -log10(4) + -mole_balance T2S(-2) + +HDS + HTS = DTS + H2S + log_k -0.301029995663 # log10(1/2) + -mole_balance DTS(-2) + +H[34S]- + H2S = H2[34S] + HS- + -add_logk Log_alpha_34S_H2S(aq)/HS- 1.0 + -mole_balance H2[34S](-2) + +H2[34S] + HDS = HD[34S] + H2S + -mole_balance HD[34S](-2) + +H2[34S] + D2S = D2[34S] + H2S + -mole_balance D2[34S](-2) + +H2[34S] + HTS = HT[34S] + H2S + -mole_balance HT[34S](-2) + +H2[34S] + T2S = T2[34S] + H2S + -mole_balance T2[34S](-2) + +H2[34S] + DTS = DT[34S] + H2S + -mole_balance DT[34S](-2) +# +# NO2- reactions +# Updated March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +[15N]O3- + NO2- = [15N]O2- + NO3- + -add_logk Log_alpha_15N_NO2-/NO3- 1.0 + -gamma 3.0000 0.0000 +# +# N2 reactions +# +N2 + [15N]O3- = N[15N] + NO3- + log_k 0.301029995663 # log10(2) + -add_logk Log_alpha_15N_N2(aq)/NO3- 1.0 + -mole_balance [15N](0)N(0) +2N[15N] = [15N]2 + N2 + log_k -0.602059991327962396 # -log10(4) + -mole_balance [15N](0)2 +# +# NH3 reactions +# +HDO + NH3 = NH2D + H2O + log_k 0.176091259055 # log10(1.5) + -add_logk Log_alpha_D_NH3(aq)/H2O(l) 1.0 + +2NH2D = NHD2 + NH3 + log_k -0.477121254719 # -log10(3) + +3NH2D = ND3 + 2NH3 + -logk -1.431363764158 # log10(1/27) + +HTO + NH3 = NH2T + H2O + log_k 0.176091259055 # log10(1.5) + -add_logk Log_alpha_T_NH3(aq)/H2O(l) 1.0 + +2NH2T = NHT2 + NH3 + log_k -0.477121254719662 # log10(1/3) + +3NH2T = NT3 + 2NH3 + -logk -1.431363764158 # log10(1/27) + +NHD2 + NH2T = ND2T + NH3 + log_k -0.477121254719 # -log10(3) + +NH2D + NHT2 = NDT2 + NH3 + log_k -0.477121254719 # -log10(3) + +# Checked September 19, 2006 + +NH3 + [15N]O3- = [15N]H3 + NO3- + -add_logk Log_alpha_15N_NH3(aq)/NO3- 1.0 + -mole_balance [15N](-3)H3 + +[15N]H3 + NH2D = [15N]H2D + NH3 +[15N]H3 + NHD2 = [15N]HD2 + NH3 +[15N]H3 + ND3 = [15N]D3 + NH3 +[15N]H3 + NH2T = [15N]H2T + NH3 +[15N]H3 + NHT2 = [15N]HT2 + NH3 +[15N]H3 + NT3 = [15N]T3 + NH3 +[15N]H3 + ND2T = [15N]D2T + NH3 +[15N]H3 + NDT2 = [15N]DT2 + NH3 +# +# NH4+ reactions +# Updated September 19, 2006 +# Checked September 19, 2006 +# +HDO + NH4+ = NH3D+ + H2O + log_k 0.301029995663 # log10(2) + -add_logk Log_alpha_D_NH4+/H2O(l) 1.0 + -mole_balance N(-3)H3D + -gamma 2.5000 0.0000 + +2NH3D+ = NH2D2+ + NH4+ + log_k -0.42596873227228 # log10(3/8) + -mole_balance N(-3)H2D2 + -gamma 2.5000 0.0000 + +3NH3D+ = NHD3+ + 2NH4+ + log_k -1.20411998265 # log10(1/16) + -mole_balance N(-3)HD3 + -gamma 2.5000 0.0000 + +4NH3D+ = ND4+ + 3NH4+ + log_k -2.408239965311 # log10(1/256) + -mole_balance N(-3)D4 + -gamma 2.5000 0.0000 + +HTO + NH4+ = NH3T+ + H2O + log_k 0.301029995663 # log10(2) + -add_logk Log_alpha_T_NH4+/H2O(l) 1.0 + -mole_balance N(-3)H3T + -gamma 2.5000 0.0000 + +2NH3T+ = NH2T2+ + NH4+ + log_k -0.42596873227228 # log10(3/8) + -mole_balance N(-3)H2T2 + -gamma 2.5000 0.0000 + +3NH3T+ = NHT3+ + 2NH4+ + log_k -1.20411998265 # log10(1/16) + -mole_balance N(-3)HT3 + -gamma 2.5000 0.0000 + +4NH3T+ = NT4+ + 3NH4+ + log_k -2.408239965311 # log10(1/256) + -mole_balance N(-3)T4 + -gamma 2.5000 0.0000 +# +# Updated September 19, 2006 +# Checked September 19, 2006 +# +NHD3+ + NH3T+ = ND3T+ + NH4+ + log_k -0.602059991327962396 # -log10(4) + -mole_balance N(-3)D3T + -gamma 2.5000 0.0000 + +NH2D2+ + NH2T2+ = ND2T2+ + NH4+ + log_k -0.7781512503836 # -log10(6) + -mole_balance N(-3)D2T2 + -gamma 2.5000 0.0000 + +NH3D+ + NHT3+ = NDT3+ + NH4+ + log_k -0.602059991327962396 # -log10(4) + -mole_balance N(-3)DT3 + -gamma 2.5000 0.0000 + +[15N]H3 + NH4+ = [15N]H4+ + NH3 + -add_logk Log_alpha_15N_NH4+/NH3(aq) 1.0 + -mole_balance [15N](-3)H4 + -gamma 2.5000 0.0000 + +[15N]H4+ + NH3D+ = [15N]H3D+ + NH4+ + -mole_balance [15N](-3)H3D + -gamma 2.5000 0.0000 + +[15N]H4+ + NH2D2+ = [15N]H2D2+ + NH4+ + -mole_balance [15N](-3)H2D2 + -gamma 2.5000 0.0000 + +[15N]H4+ + NHD3+ = [15N]HD3+ + NH4+ + -mole_balance [15N](-3)HD3 + -gamma 2.5000 0.0000 + +[15N]H4+ + ND4+ = [15N]D4+ + NH4+ + -mole_balance [15N](-3)D4+ + -gamma 2.5000 0.0000 + +[15N]H4+ + NH3T+ = [15N]H3T+ + NH4+ + -mole_balance [15N](-3)H3T + -gamma 2.5000 0.0000 + +[15N]H4+ + NH2T2+ = [15N]H2T2+ + NH4+ + -mole_balance [15N](-3)H2T2 + -gamma 2.5000 0.0000 + +[15N]H4+ + NHT3+ = [15N]HT3+ + NH4+ + -mole_balance [15N](-3)HT3 + -gamma 2.5000 0.0000 + +[15N]H4+ + NT4+ = [15N]T4+ + NH4+ + -mole_balance [15N](-3)T4+ + -gamma 2.5000 0.0000 + +[15N]H4+ + ND3T+ = [15N]D3T+ + NH4+ + -mole_balance [15N](-3)D3T + -gamma 2.5000 0.0000 + +[15N]H4+ + ND2T2+ = [15N]D2T2+ + NH4+ + -mole_balance [15N](-3)D2T2 + -gamma 2.5000 0.0000 + +[15N]H4+ + NDT3+ = [15N]DT3+ + NH4+ + -mole_balance [15N](-3)DT3 + -gamma 2.5000 0.0000 +# +# Missing NH4SO4- reactions +# +# +# Missing HPO4-2 reactions +# +# +# Missing H2PO4- reactions +# +# +# Missing HF reactions +# +# +# Missing HF2- reactions +# +# +# CaOH reactions +# +CaOH+ + [18O]H- = Ca[18O]H+ + OH- + -mole_balance Ca[18O]H +CaOH+ + OD- = CaOD+ + OH- + -mole_balance CaOD +CaOH+ + [18O]D- = Ca[18O]D+ + OH- + -mole_balance Ca[18O]D +CaOH+ + OT- = CaOT+ + OH- + -mole_balance CaOT+ +CaOH+ + [18O]T- = Ca[18O]T+ + OH- + -mole_balance Ca[18O]T +# +# CaCO3 reactions +# +CaCO3 + CO2[18O]-2 = CaCO2[18O] + CO3-2 +CaCO3 + CO[18O]2-2 = CaCO[18O]2 + CO3-2 +CaCO3 + C[18O]3-2 = CaC[18O]3 + CO3-2 +CaCO3 + [13C]O3-2 = Ca[13C]O3 + CO3-2 +CaCO3 + [13C]O2[18O]-2 = Ca[13C]O2[18O] + CO3-2 +CaCO3 + [13C]O[18O]2-2 = Ca[13C]O[18O]2 + CO3-2 +CaCO3 + [13C][18O]3-2 = Ca[13C][18O]3 + CO3-2 +CaCO3 + [14C]O3-2 = Ca[14C]O3 + CO3-2 +CaCO3 + [14C]O2[18O]-2 = Ca[14C]O2[18O] + CO3-2 +CaCO3 + [14C]O[18O]2-2 = Ca[14C]O[18O]2 + CO3-2 +CaCO3 + [14C][18O]3-2 = Ca[14C][18O]3 + CO3-2 +# +# CaHCO3+ reactions +# +CaHCO3+ + HCO2[18O]- = CaHCO2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HCO[18O]O- = CaHCO[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HC[18O]O2- = CaHC[18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HCO[18O]2- = CaHCO[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HC[18O]O[18O]- = CaHC[18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HC[18O]2O- = CaHC[18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + HC[18O]3- = CaHC[18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C]O3- = CaH[13C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C]O2[18O]- = CaH[13C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C]O[18O]O- = CaH[13C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C][18O]O2- = CaH[13C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C]O[18O]2- = CaH[13C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C][18O]O[18O]- = CaH[13C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C][18O]2O- = CaH[13C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[13C][18O]3- = CaH[13C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C]O3- = CaH[14C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C]O2[18O]- = CaH[14C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C]O[18O]O- = CaH[14C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C][18O]O2- = CaH[14C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C]O[18O]2- = CaH[14C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C][18O]O[18O]- = CaH[14C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C][18O]2O- = CaH[14C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + H[14C][18O]3- = CaH[14C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +# DCO3- +CaHCO3+ + DCO3- = CaDCO3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DCO2[18O]- = CaDCO2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DCO[18O]O- = CaDCO[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DC[18O]O2- = CaDC[18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DCO[18O]2- = CaDCO[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DC[18O]O[18O]- = CaDC[18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DC[18O]2O- = CaDC[18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + DC[18O]3- = CaDC[18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C]O3- = CaD[13C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C]O2[18O]- = CaD[13C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C]O[18O]O- = CaD[13C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C][18O]O2- = CaD[13C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C]O[18O]2- = CaD[13C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C][18O]O[18O]- = CaD[13C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C][18O]2O- = CaD[13C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[13C][18O]3- = CaD[13C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C]O3- = CaD[14C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C]O2[18O]- = CaD[14C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C]O[18O]O- = CaD[14C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C][18O]O2- = CaD[14C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C]O[18O]2- = CaD[14C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C][18O]O[18O]- = CaD[14C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C][18O]2O- = CaD[14C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + D[14C][18O]3- = CaD[14C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +# TCO3- +CaHCO3+ + TCO3- = CaTCO3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TCO2[18O]- = CaTCO2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TCO[18O]O- = CaTCO[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TC[18O]O2- = CaTC[18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TCO[18O]2- = CaTCO[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TC[18O]O[18O]- = CaTC[18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TC[18O]2O- = CaTC[18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + TC[18O]3- = CaTC[18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C]O3- = CaT[13C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C]O2[18O]- = CaT[13C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C]O[18O]O- = CaT[13C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C][18O]O2- = CaT[13C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C]O[18O]2- = CaT[13C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C][18O]O[18O]- = CaT[13C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C][18O]2O- = CaT[13C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[13C][18O]3- = CaT[13C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C]O3- = CaT[14C]O3+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C]O2[18O]- = CaT[14C]O2[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C]O[18O]O- = CaT[14C]O[18O]O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C][18O]O2- = CaT[14C][18O]O2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C]O[18O]2- = CaT[14C]O[18O]2+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C][18O]O[18O]- = CaT[14C][18O]O[18O]+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C][18O]2O- = CaT[14C][18O]2O+ + HCO3- + -gamma 5.4000 0.0000 + +CaHCO3+ + T[14C][18O]3- = CaT[14C][18O]3+ + HCO3- + -gamma 5.4000 0.0000 +# +# CaSO4 reactions +# +# Updated May 17, 2006 +CaSO4 + [34S]O4-2 = Ca[34S]O4 + SO4-2 +# +# CaHSO4+ reactions +# +CaHSO4+ + H[34S]O4- = CaH[34S]O4+ + HSO4- +CaHSO4+ + D[34S]O4- = CaD[34S]O4+ + HSO4- +CaHSO4+ + T[34S]O4- = CaT[34S]O4+ + HSO4- +# +# Missing CaPO4- reactions +# +# +# Missing CaHPO4 reactions +# +# +# Missing CaH2PO4+ reactions +# +# +# MgOH+ reactions +# +MgOH+ + [18O]H- = Mg[18O]H+ + OH- +MgOH+ + OD- = MgOD+ + OH- +MgOH+ + [18O]D- = Mg[18O]D+ + OH- +MgOH+ + OT- = MgOT+ + OH- +MgOH+ + [18O]T- = Mg[18O]T+ + OH- +# +# MgCO3 reactions +# +MgCO3 + CO2[18O]-2 = MgCO2[18O] + CO3-2 +MgCO3 + CO[18O]2-2 = MgCO[18O]2 + CO3-2 +MgCO3 + C[18O]3-2 = MgC[18O]3 + CO3-2 +MgCO3 + [13C]O3-2 = Mg[13C]O3 + CO3-2 +MgCO3 + [13C]O2[18O]-2 = Mg[13C]O2[18O] + CO3-2 +MgCO3 + [13C]O[18O]2-2 = Mg[13C]O[18O]2 + CO3-2 +MgCO3 + [13C][18O]3-2 = Mg[13C][18O]3 + CO3-2 +MgCO3 + [14C]O3-2 = Mg[14C]O3 + CO3-2 +MgCO3 + [14C]O2[18O]-2 = Mg[14C]O2[18O] + CO3-2 +MgCO3 + [14C]O[18O]2-2 = Mg[14C]O[18O]2 + CO3-2 +MgCO3 + [14C][18O]3-2 = Mg[14C][18O]3 + CO3-2 +# +# MgHCO3+ reactions +# +MgHCO3+ + HCO2[18O]- = MgHCO2[18O]+ + HCO3- +MgHCO3+ + HCO[18O]O- = MgHCO[18O]O+ + HCO3- +MgHCO3+ + HC[18O]O2- = MgHC[18O]O2+ + HCO3- +MgHCO3+ + HCO[18O]2- = MgHCO[18O]2+ + HCO3- +MgHCO3+ + HC[18O]O[18O]- = MgHC[18O]O[18O]+ + HCO3- +MgHCO3+ + HC[18O]2O- = MgHC[18O]2O+ + HCO3- +MgHCO3+ + HC[18O]3- = MgHC[18O]3+ + HCO3- +MgHCO3+ + H[13C]O3- = MgH[13C]O3+ + HCO3- +MgHCO3+ + H[13C]O2[18O]- = MgH[13C]O2[18O]+ + HCO3- +MgHCO3+ + H[13C]O[18O]O- = MgH[13C]O[18O]O+ + HCO3- +MgHCO3+ + H[13C][18O]O2- = MgH[13C][18O]O2+ + HCO3- +MgHCO3+ + H[13C]O[18O]2- = MgH[13C]O[18O]2+ + HCO3- +MgHCO3+ + H[13C][18O]O[18O]- = MgH[13C][18O]O[18O]+ + HCO3- +MgHCO3+ + H[13C][18O]2O- = MgH[13C][18O]2O+ + HCO3- +MgHCO3+ + H[13C][18O]3- = MgH[13C][18O]3+ + HCO3- +MgHCO3+ + H[14C]O3- = MgH[14C]O3+ + HCO3- +MgHCO3+ + H[14C]O2[18O]- = MgH[14C]O2[18O]+ + HCO3- +MgHCO3+ + H[14C]O[18O]O- = MgH[14C]O[18O]O+ + HCO3- +MgHCO3+ + H[14C][18O]O2- = MgH[14C][18O]O2+ + HCO3- +MgHCO3+ + H[14C]O[18O]2- = MgH[14C]O[18O]2+ + HCO3- +MgHCO3+ + H[14C][18O]O[18O]- = MgH[14C][18O]O[18O]+ + HCO3- +MgHCO3+ + H[14C][18O]2O- = MgH[14C][18O]2O+ + HCO3- +MgHCO3+ + H[14C][18O]3- = MgH[14C][18O]3+ + HCO3- + +# DCO3- +MgHCO3+ + DCO3- = MgDCO3+ + HCO3- +MgHCO3+ + DCO2[18O]- = MgDCO2[18O]+ + HCO3- +MgHCO3+ + DCO[18O]O- = MgDCO[18O]O+ + HCO3- +MgHCO3+ + DC[18O]O2- = MgDC[18O]O2+ + HCO3- +MgHCO3+ + DCO[18O]2- = MgDCO[18O]2+ + HCO3- +MgHCO3+ + DC[18O]O[18O]- = MgDC[18O]O[18O]+ + HCO3- +MgHCO3+ + DC[18O]2O- = MgDC[18O]2O+ + HCO3- +MgHCO3+ + DC[18O]3- = MgDC[18O]3+ + HCO3- +MgHCO3+ + D[13C]O3- = MgD[13C]O3+ + HCO3- +MgHCO3+ + D[13C]O2[18O]- = MgD[13C]O2[18O]+ + HCO3- +MgHCO3+ + D[13C]O[18O]O- = MgD[13C]O[18O]O+ + HCO3- +MgHCO3+ + D[13C][18O]O2- = MgD[13C][18O]O2+ + HCO3- +MgHCO3+ + D[13C]O[18O]2- = MgD[13C]O[18O]2+ + HCO3- +MgHCO3+ + D[13C][18O]O[18O]- = MgD[13C][18O]O[18O]+ + HCO3- +MgHCO3+ + D[13C][18O]2O- = MgD[13C][18O]2O+ + HCO3- +MgHCO3+ + D[13C][18O]3- = MgD[13C][18O]3+ + HCO3- +MgHCO3+ + D[14C]O3- = MgD[14C]O3+ + HCO3- +MgHCO3+ + D[14C]O2[18O]- = MgD[14C]O2[18O]+ + HCO3- +MgHCO3+ + D[14C]O[18O]O- = MgD[14C]O[18O]O+ + HCO3- +MgHCO3+ + D[14C][18O]O2- = MgD[14C][18O]O2+ + HCO3- +MgHCO3+ + D[14C]O[18O]2- = MgD[14C]O[18O]2+ + HCO3- +MgHCO3+ + D[14C][18O]O[18O]- = MgD[14C][18O]O[18O]+ + HCO3- +MgHCO3+ + D[14C][18O]2O- = MgD[14C][18O]2O+ + HCO3- +MgHCO3+ + D[14C][18O]3- = MgD[14C][18O]3+ + HCO3- + +# TCO3- +MgHCO3+ + TCO3- = MgTCO3+ + HCO3- +MgHCO3+ + TCO2[18O]- = MgTCO2[18O]+ + HCO3- +MgHCO3+ + TCO[18O]O- = MgTCO[18O]O+ + HCO3- +MgHCO3+ + TC[18O]O2- = MgTC[18O]O2+ + HCO3- +MgHCO3+ + TCO[18O]2- = MgTCO[18O]2+ + HCO3- +MgHCO3+ + TC[18O]O[18O]- = MgTC[18O]O[18O]+ + HCO3- +MgHCO3+ + TC[18O]2O- = MgTC[18O]2O+ + HCO3- +MgHCO3+ + TC[18O]3- = MgTC[18O]3+ + HCO3- +MgHCO3+ + T[13C]O3- = MgT[13C]O3+ + HCO3- +MgHCO3+ + T[13C]O2[18O]- = MgT[13C]O2[18O]+ + HCO3- +MgHCO3+ + T[13C]O[18O]O- = MgT[13C]O[18O]O+ + HCO3- +MgHCO3+ + T[13C][18O]O2- = MgT[13C][18O]O2+ + HCO3- +MgHCO3+ + T[13C]O[18O]2- = MgT[13C]O[18O]2+ + HCO3- +MgHCO3+ + T[13C][18O]O[18O]- = MgT[13C][18O]O[18O]+ + HCO3- +MgHCO3+ + T[13C][18O]2O- = MgT[13C][18O]2O+ + HCO3- +MgHCO3+ + T[13C][18O]3- = MgT[13C][18O]3+ + HCO3- +MgHCO3+ + T[14C]O3- = MgT[14C]O3+ + HCO3- +MgHCO3+ + T[14C]O2[18O]- = MgT[14C]O2[18O]+ + HCO3- +MgHCO3+ + T[14C]O[18O]O- = MgT[14C]O[18O]O+ + HCO3- +MgHCO3+ + T[14C][18O]O2- = MgT[14C][18O]O2+ + HCO3- +MgHCO3+ + T[14C]O[18O]2- = MgT[14C]O[18O]2+ + HCO3- +MgHCO3+ + T[14C][18O]O[18O]- = MgT[14C][18O]O[18O]+ + HCO3- +MgHCO3+ + T[14C][18O]2O- = MgT[14C][18O]2O+ + HCO3- +MgHCO3+ + T[14C][18O]3- = MgT[14C][18O]3+ + HCO3- +# +# MgSO4 reactions +# +MgSO4 + [34S]O4-2 = Mg[34S]O4 + SO4-2 +# +# Missing MgPO4- reactions +# +# +# Missing MgHPO4 reactions +# +# +# Missing Mg2PO4+ reactions +# +# +# NaOH reactions +# +NaOH + [18O]H- = Na[18O]H + OH- +NaOH + OD- = NaOD + OH- +NaOH + [18O]D- = Na[18O]D + OH- +NaOH + OT- = NaOT + OH- +NaOH + [18O]T- = Na[18O]T + OH- +# +# NaCO3- reactions +# +NaCO3- + CO2[18O]-2 = NaCO2[18O]- + CO3-2 +NaCO3- + CO[18O]2-2 = NaCO[18O]2- + CO3-2 +NaCO3- + C[18O]3-2 = NaC[18O]3- + CO3-2 +NaCO3- + [13C]O3-2 = Na[13C]O3- + CO3-2 +NaCO3- + [13C]O2[18O]-2 = Na[13C]O2[18O]- + CO3-2 +NaCO3- + [13C]O[18O]2-2 = Na[13C]O[18O]2- + CO3-2 +NaCO3- + [13C][18O]3-2 = Na[13C][18O]3- + CO3-2 +NaCO3- + [14C]O3-2 = Na[14C]O3- + CO3-2 +NaCO3- + [14C]O2[18O]-2 = Na[14C]O2[18O]- + CO3-2 +NaCO3- + [14C]O[18O]2-2 = Na[14C]O[18O]2- + CO3-2 +NaCO3- + [14C][18O]3-2 = Na[14C][18O]3- + CO3-2 +# +# NaHCO3 reactions +# +NaHCO3 + HCO2[18O]- = NaHCO2[18O] + HCO3- +NaHCO3 + HCO[18O]O- = NaHCO[18O]O + HCO3- +NaHCO3 + HC[18O]O2- = NaHC[18O]O2 + HCO3- +NaHCO3 + HCO[18O]2- = NaHCO[18O]2 + HCO3- +NaHCO3 + HC[18O]O[18O]- = NaHC[18O]O[18O] + HCO3- +NaHCO3 + HC[18O]2O- = NaHC[18O]2O + HCO3- +NaHCO3 + HC[18O]3- = NaHC[18O]3 + HCO3- +NaHCO3 + H[13C]O3- = NaH[13C]O3 + HCO3- +NaHCO3 + H[13C]O2[18O]- = NaH[13C]O2[18O] + HCO3- +NaHCO3 + H[13C]O[18O]O- = NaH[13C]O[18O]O + HCO3- +NaHCO3 + H[13C][18O]O2- = NaH[13C][18O]O2 + HCO3- +NaHCO3 + H[13C]O[18O]2- = NaH[13C]O[18O]2 + HCO3- +NaHCO3 + H[13C][18O]O[18O]- = NaH[13C][18O]O[18O] + HCO3- +NaHCO3 + H[13C][18O]2O- = NaH[13C][18O]2O + HCO3- +NaHCO3 + H[13C][18O]3- = NaH[13C][18O]3 + HCO3- +NaHCO3 + H[14C]O3- = NaH[14C]O3 + HCO3- +NaHCO3 + H[14C]O2[18O]- = NaH[14C]O2[18O] + HCO3- +NaHCO3 + H[14C]O[18O]O- = NaH[14C]O[18O]O + HCO3- +NaHCO3 + H[14C][18O]O2- = NaH[14C][18O]O2 + HCO3- +NaHCO3 + H[14C]O[18O]2- = NaH[14C]O[18O]2 + HCO3- +NaHCO3 + H[14C][18O]O[18O]- = NaH[14C][18O]O[18O] + HCO3- +NaHCO3 + H[14C][18O]2O- = NaH[14C][18O]2O + HCO3- +NaHCO3 + H[14C][18O]3- = NaH[14C][18O]3 + HCO3- + +# DCO3- +NaHCO3 + DCO3- = NaDCO3 + HCO3- +NaHCO3 + DCO2[18O]- = NaDCO2[18O] + HCO3- +NaHCO3 + DCO[18O]O- = NaDCO[18O]O + HCO3- +NaHCO3 + DC[18O]O2- = NaDC[18O]O2 + HCO3- +NaHCO3 + DCO[18O]2- = NaDCO[18O]2 + HCO3- +NaHCO3 + DC[18O]O[18O]- = NaDC[18O]O[18O] + HCO3- +NaHCO3 + DC[18O]2O- = NaDC[18O]2O + HCO3- +NaHCO3 + DC[18O]3- = NaDC[18O]3 + HCO3- +NaHCO3 + D[13C]O3- = NaD[13C]O3 + HCO3- +NaHCO3 + D[13C]O2[18O]- = NaD[13C]O2[18O] + HCO3- +NaHCO3 + D[13C]O[18O]O- = NaD[13C]O[18O]O + HCO3- +NaHCO3 + D[13C][18O]O2- = NaD[13C][18O]O2 + HCO3- +NaHCO3 + D[13C]O[18O]2- = NaD[13C]O[18O]2 + HCO3- +NaHCO3 + D[13C][18O]O[18O]- = NaD[13C][18O]O[18O] + HCO3- +NaHCO3 + D[13C][18O]2O- = NaD[13C][18O]2O + HCO3- +NaHCO3 + D[13C][18O]3- = NaD[13C][18O]3 + HCO3- +NaHCO3 + D[14C]O3- = NaD[14C]O3 + HCO3- +NaHCO3 + D[14C]O2[18O]- = NaD[14C]O2[18O] + HCO3- +NaHCO3 + D[14C]O[18O]O- = NaD[14C]O[18O]O + HCO3- +NaHCO3 + D[14C][18O]O2- = NaD[14C][18O]O2 + HCO3- +NaHCO3 + D[14C]O[18O]2- = NaD[14C]O[18O]2 + HCO3- +NaHCO3 + D[14C][18O]O[18O]- = NaD[14C][18O]O[18O] + HCO3- +NaHCO3 + D[14C][18O]2O- = NaD[14C][18O]2O + HCO3- +NaHCO3 + D[14C][18O]3- = NaD[14C][18O]3 + HCO3- + +# TCO3- +NaHCO3 + TCO3- = NaTCO3 + HCO3- +NaHCO3 + TCO2[18O]- = NaTCO2[18O] + HCO3- +NaHCO3 + TCO[18O]O- = NaTCO[18O]O + HCO3- +NaHCO3 + TC[18O]O2- = NaTC[18O]O2 + HCO3- +NaHCO3 + TCO[18O]2- = NaTCO[18O]2 + HCO3- +NaHCO3 + TC[18O]O[18O]- = NaTC[18O]O[18O] + HCO3- +NaHCO3 + TC[18O]2O- = NaTC[18O]2O + HCO3- +NaHCO3 + TC[18O]3- = NaTC[18O]3 + HCO3- +NaHCO3 + T[13C]O3- = NaT[13C]O3 + HCO3- +NaHCO3 + T[13C]O2[18O]- = NaT[13C]O2[18O] + HCO3- +NaHCO3 + T[13C]O[18O]O- = NaT[13C]O[18O]O + HCO3- +NaHCO3 + T[13C][18O]O2- = NaT[13C][18O]O2 + HCO3- +NaHCO3 + T[13C]O[18O]2- = NaT[13C]O[18O]2 + HCO3- +NaHCO3 + T[13C][18O]O[18O]- = NaT[13C][18O]O[18O] + HCO3- +NaHCO3 + T[13C][18O]2O- = NaT[13C][18O]2O + HCO3- +NaHCO3 + T[13C][18O]3- = NaT[13C][18O]3 + HCO3- +NaHCO3 + T[14C]O3- = NaT[14C]O3 + HCO3- +NaHCO3 + T[14C]O2[18O]- = NaT[14C]O2[18O] + HCO3- +NaHCO3 + T[14C]O[18O]O- = NaT[14C]O[18O]O + HCO3- +NaHCO3 + T[14C][18O]O2- = NaT[14C][18O]O2 + HCO3- +NaHCO3 + T[14C]O[18O]2- = NaT[14C]O[18O]2 + HCO3- +NaHCO3 + T[14C][18O]O[18O]- = NaT[14C][18O]O[18O] + HCO3- +NaHCO3 + T[14C][18O]2O- = NaT[14C][18O]2O + HCO3- +NaHCO3 + T[14C][18O]3- = NaT[14C][18O]3 + HCO3- +# +# NaSO4- reactions +# +NaSO4- + [34S]O4-2 = Na[34S]O4- + SO4-2 +# +# Missing NaHPO4- reactions +# +# +# KOH reactions +# +KOH + [18O]H- = K[18O]H + OH- +KOH + OD- = KOD + OH- +KOH + [18O]D- = K[18O]D + OH- +KOH + OT- = KOT + OH- +KOH + [18O]T- = K[18O]T + OH- +# +# KSO4- reactions +# +KSO4- + [34S]O4-2 = K[34S]O4- + SO4-2 +# +# Missing FeOH+ reactions +# +# +# Missing FeCO3 reactions +# +# +# Missing FeHCO3+ reactions +# +# +# Missing FeSO4 reactions +# +# +# Missing FeHSO4+ reactions +# +# +# Missing Fe(HS)2 reactions +# +# +# Missing Fe(HS)3- reactions +# +# +# Missing FeHPO4 reactions +# +# +# Missing FeH2PO4+ reactions +# +# +# Missing FeOH+2 reactions +# +# +# Missing Fe(OH)2+ reactions +# +# +# Missing Fe(OH)3 reactions +# +# +# Missing Fe(OH)4- reactions +# +# +# Missing Fe2(OH)2+4 reactions +# +# +# Missing Fe3(OH)4+5 reactions +# +# +# Missing FeSO4+ reactions +# +# +# Missing FeHSO4+2 reactions +# +# +# Missing Fe(SO4)2- reactions +# +# +# Missing FeHPO4+ reactions +# +# +# Missing FeH2PO4+2 reactions +# +# +# Missing AlOH+2 reactions +# +# +# Missing Al(OH)2+ reactions +# +# +# Missing Al(OH)3 reactions +# +# +# Missing Al(OH)4- reactions +# +# +# Missing AlSO4+ reactions +# +# +# Missing Al(SO4)2- reactions +# +# +# Missing AlHSO4+2 reactions +# +# +# Missing H4SiO4 reactions +# +# +# Missing H3SiO4- reactions +# +# +# Missing H2SiO4-2 reactions +# + +############################################################################################### +PHASES +############################################################################################### +# +# Water vapor - Water +# last update March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +HDO(g) + HDO(g) + H2O(l) = H2O(g) + HDO(aq) + -add_logk Log_alpha_D_H2O(g)/H2O(l) -1.0 + +HTO(g) + HTO(g) + H2O(l) = H2O(g) + HTO(aq) + -add_logk Log_alpha_T_H2O(g)/H2O(l) -1.0 + +DTO(g) + DTO(g) + H2O(g) = HDO(g) + HTO(g) + log_k 0.301029995663 # log10(2) + +D2O(g) + D2O(g) + H2O(g) = 2HDO(g) + log_k 0.602059991327962396 # log10(4) + +T2O(g) + T2O(g) + H2O(g) = 2HTO(g) + log_k 0.602059991327962396 # log10(4) + +H2[18O](g) + H2[18O](g) + H2O(l) = H2O(g) + H2[18O](aq) + -add_logk Log_alpha_18O_H2O(g)/H2O(l) -1.0 + +HD[18O](g) + HD[18O](g) + H2O(g) = HDO(g) + H2[18O](g) + log_k 0.0 + +HT[18O](g) + HT[18O](g) + H2O(g) = HTO(g) + H2[18O](g) + log_k 0.0 + +D2[18O](g) + D2[18O](g) + H2O(g) = D2O(g) + H2[18O](g) + log_k 0.0 + +T2[18O](g) + T2[18O](g) + H2O(g) = T2O(g) + H2[18O](g) + log_k 0.0 + +DT[18O](g) + DT[18O](g) + H2O(g) = DTO(g) + H2[18O](g) + log_k 0.0 +# +# O2 gas - O2 aqueous +# last update March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +O[18O](g) + O[18O](g) + H2O(l) = O2(g) + H2[18O](aq) +## symmetry K ?? + -add_logk Log_alpha_18O_O2(g)/H2O(l) -1.0 + +[18O]2(g) + [18O]2(g) + O2(g) = 2O[18O](g) + log_k 0.602059991327962396 # log10(4) +# +# H2 gas - H2 aqueous +# last update March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +HD(g) + HD(g) + H2O(l) = H2(g) + HDO(aq) + -add_logk Log_alpha_D_H2(g)/H2O(l) -1.0 + +HT(g) + HT(g) + H2O(l) = H2(g) + HTO(aq) + -add_logk Log_alpha_T_H2(g)/H2O(l) -1.0 + +D2(g) + D2(g) + H2(g) = 2HD(g) + log_k 0.602059991327962396 # log10(4) + +T2(g) + T2(g) + H2(g) = 2HT(g) + log_k 0.602059991327962396 # log10(4) + +DT(g) + DT(g) + H2(g) = HD(g) + HT(g) + log_k 0.301029995663 # log10(2) +# +# CO2 gas - CO2 aqueous +# last update March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +CO[18O](g) + CO[18O](g) + H2O(l) = H2[18O](aq) + CO2(g) + log_k -0.301029995663 # -log10(2) + -add_logk Log_alpha_18O_CO2(g)/H2O(l) -1.0 + +C[18O]2(g) + C[18O]2(g) + CO2(g) = 2CO[18O](g) + log_k 0.602059991327962396 # log10(4) + +[13C]O2(g) + [13C]O2(g) + CO2(aq) = [13C]O2(aq) + CO2(g) + -add_logk Log_alpha_13C_CO2(g)/CO2(aq) -1.0 + +[13C]O[18O](g) + [13C]O[18O](g) + CO2(g) = [13C]O2(g) + CO[18O](g) + log_k 0 + +[13C][18O]2(g) + [13C][18O]2(g) + CO2(g) = C[18O]2(g) + [13C]O2(g) + log_k 0 + +[14C]O2(g) + [14C]O2(g) + CO2(aq) = [14C]O2(aq) + CO2(g) + -add_logk Log_alpha_14C_CO2(g)/CO2(aq) -1.0 + +[14C]O[18O](g) + [14C]O[18O](g) + CO2(g) = [14C]O2(g) + CO[18O](g) + log_k 0 + +[14C][18O]2(g) + [14C][18O]2(g) + CO2(g) = [14C]O2(g) + C[18O]2(g) + log_k 0 +# +# Calcite +# last update Feb 13, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +CaCO2[18O](s) + CaCO2[18O](s) + H2O(l) = H2[18O](aq) + Calcite(s) + log_k -0.477121254719 # -log10(3) ??? + -add_logk Log_alpha_18O_Calcite/H2O(l) -1.0 + +CaCO[18O]2(s) + CaCO[18O]2(s) + Calcite(s) = 2CaCO2[18O](s) + log_k 0.477121254719 # log10(3) + +CaC[18O]3(s) + CaC[18O]3(s) + 2Calcite(s) = 3CaCO2[18O](s) + log_k 1.431363764158 # log10(27) + +Ca[13C]O3(s) + Ca[13C]O3(s) + CO2 = [13C]O2 + Calcite(s) + -add_logk Log_alpha_13C_Calcite/CO2(aq) -1.0 + +Ca[13C]O2[18O](s) + Ca[13C]O2[18O](s) + Calcite(s) = Ca[13C]O3(s) + CaCO2[18O](s) + log_k 0 + +Ca[13C]O[18O]2(s) + Ca[13C]O[18O]2(s) + Calcite(s) = Ca[13C]O3(s) + CaCO[18O]2(s) + log_k 0 + +Ca[13C][18O]3(s) + Ca[13C][18O]3(s) + Calcite(s) = Ca[13C]O3(s) + CaC[18O]3(s) + log_k 0 + +Ca[14C]O3(s) + Ca[14C]O3(s) + CO2 = Calcite(s) + [14C]O2 + -add_logk Log_alpha_14C_Calcite/CO2(aq) -1.0 + +Ca[14C]O2[18O](s) + Ca[14C]O2[18O](s) + Calcite(s) = Ca[14C]O3(s) + CaCO2[18O](s) + log_k 0 + +Ca[14C]O[18O]2(s) + Ca[14C]O[18O]2(s) + Calcite(s) = Ca[14C]O3(s) + CaCO[18O]2(s) + log_k 0 + +Ca[14C][18O]3(s) + Ca[14C][18O]3(s) + Calcite(s) = Ca[14C]O3(s) + CaC[18O]3(s) + log_k 0 +# +# Pyrite, March 20, 2006 +# Update September 28, 2006 +# Checked September 28, 2006 +# +Pyrite_FeS[34S] + FeS[34S](s) + HS- = Pyrite(s) + H[34S]- + -add_logk Log_alpha_34S_Pyrite/HS- -1.0 + +Pyrite_Fe[34S]S + Fe[34S]S(s) = Pyrite_FeS[34S](s) + +Pyrite_Fe[34S]2 + Fe[34S]2(s) + Pyrite(s) = 2Pyrite_FeS[34S](s) +# +# CH4 reactions +# last update March 20, 2006 +# Updated September 19, 2006 +# Checked September 19, 2006 +# +CH3D(g) + CH3D(g) + H2O(l) = CH4(g) + HDO(aq) + log_k -0.301029995663 # -log10(2) ??? + -add_logk Log_alpha_D_CH4(g)/H2O(l) -1.0 + +CH2D2(g) + CH2D2(g) + CH4(g) = 2CH3D(g) + log_k 0.42596873227228 # log10(8/3) + +CHD3(g) + CHD3(g) + 2CH4(g) = 3CH3D(g) + log_k 1.20411998265 # log10(16) + +CD4(g) + CD4(g) + 3CH4(g) = 4CH3D(g) + log_k 2.408239965311 # log10(256) + +CH3T(g) + CH3T(g) + H2O(l) = CH4(g) + HTO(aq) + log_k -0.301029995663 # -log10(2) ??? + -add_logk Log_alpha_T_CH4(g)/H2O(l) -1.0 + +CH2T2(g) + CH2T2(g) + CH4(g) = 2CH3T(g) + log_k 0.42596873227228 # log10(8/3) + +CHT3(g) + CHT3(g) + 2CH4(g) = 3CH3T(g) + log_k 1.20411998265 # log10(16) + +CT4(g) + CT4(g) + 3CH4(g) = 4CH3T(g) + log_k 2.408239965311 # log10(256) + +CD3T(g) + CD3T(g) + CH4(g) = CHD3(g) + CH3T(g) + log_k 0.602059991327962396 # log10(4) + +CD2T2(g) + CD2T2(g) + CH4(g) = CH2D2(g) + CH2T2(g) + log_k 0.7781512503836 # log10(6) + +CDT3(g) + CDT3(g) + CH4(g) = CHT3(g) + CH3D(g) + log_k 0.602059991327962396 # log10(4) + +[13C]H4(g) + [13C]H4(g) + CO2(aq) = [13C]O2(aq) + CH4(g) + -add_logk Log_alpha_13C_CH4(g)/CO2(aq) -1.0 + +[13C]H3D(g) + [13C]H3D(g) + CH4(g) = CH3D(g) + [13C]H4(g) + +[13C]H2D2(g) + [13C]H2D2(g) + CH4(g) = CH2D2(g) + [13C]H4(g) + +[13C]HD3(g) + [13C]HD3(g) + CH4(g) = CHD3(g) + [13C]H4(g) + +[13C]D4(g) + [13C]D4(g) + CH4(g) = CD4(g) + [13C]H4(g) + +[13C]H3T(g) + [13C]H3T(g) + CH4(g) = CH3T(g) + [13C]H4(g) + +[13C]H2T2(g) + [13C]H2T2(g) + CH4(g) = CH2T2(g) + [13C]H4(g) + +[13C]HT3(g) + [13C]HT3(g) + CH4(g) = CHT3(g) + [13C]H4(g) + +[13C]T4(g) + [13C]T4(g) + CH4(g) = CT4(g) + [13C]H4(g) + +[13C]D3T(g) + [13C]D3T(g) + CH4(g) = CD3T(g) + [13C]H4(g) + +[13C]D2T2(g) + [13C]D2T2(g) + CH4(g) = CD2T2(g) + [13C]H4(g) + +[13C]DT3(g) + [13C]DT3(g) + CH4(g) = CDT3(g) + [13C]H4(g) + +[13C]T4(g) + [13C]T4(g) + CH4(g) = CT4(g) + [13C]H4(g) + +[14C]H4(g) + [14C]H4(g) + CO2(aq) = [14C]O2(aq) + CH4(g) + -add_logk Log_alpha_14C_CH4(g)/CO2(aq) -1.0 + +[14C]H3D(g) + [14C]H3D(g) + CH4(g) = CH3D(g) + [14C]H4(g) + +[14C]H2D2(g) + [14C]H2D2(g) + CH4(g) = CH2D2(g) + [14C]H4(g) + +[14C]HD3(g) + [14C]HD3(g) + CH4(g) = CHD3(g) + [14C]H4(g) + +[14C]D4(g) + [14C]D4(g) + CH4(g) = CD4(g) + [14C]H4(g) + +[14C]H3T(g) + [14C]H3T(g) + CH4(g) = CH3T(g) + [14C]H4(g) + +[14C]H2T2(g) + [14C]H2T2(g) + CH4(g) = CH2T2(g) + [14C]H4(g) + +[14C]HT3(g) + [14C]HT3(g) + CH4(g) = CHT3(g) + [14C]H4(g) + +[14C]T4(g) + [14C]T4(g) + CH4(g) = CT4(g) + [14C]H4(g) + +[14C]D3T(g) + [14C]D3T(g) + CH4(g) = CD3T(g) + [14C]H4(g) + +[14C]D2T2(g) + [14C]D2T2(g) + CH4(g) = CD2T2(g) + [14C]H4(g) + +[14C]DT3(g) + [14C]DT3(g) + CH4(g) = CDT3(g) + [14C]H4(g) + +[14C]T4(g) + [14C]T4(g) + CH4(g) = CT4(g) + [14C]H4(g) +# +# updated March 20, 2006 +# Updated September 28, 2006 +# Checked September 28, 2006 +# +HDS(g) + HDS(g) + H2S(aq) = HDS(aq) + H2S(g) + -add_logk Log_alpha_D_H2S(g)/H2S(aq) -1.0 + +D2S(g) + D2S(g) + H2S(g) = 2HDS(g) + log_k 0.602059991327962396 # log10(4) + +HTS(g) + HTS(g) + H2S(aq) = HTS(aq) + H2S(g) + -add_logk Log_alpha_T_H2S(g)/H2S(aq) -1.0 + +T2S(g) + T2S(g) + H2S(g) = 2HTS(g) + log_k 0.602059991327962396 # log10(4) + +DTS(g) + DTS(g) + H2S(g) = HDS(g) + HTS(g) + log_k 0.301029995663 # log10(2) + +H2[34S](g) + H2[34S](g) + H2S(aq) = H2[34S](aq) + H2S(g) + -add_logk Log_alpha_34S_H2S(g)/H2S(aq) -1.0 + +HD[34S](g) + HD[34S](g) + H2S(g) = HDS(g) + H2[34S](g) + +D2[34S](g) + D2[34S](g) + H2S(g) = D2S(g) + H2[34S](g) + +HT[34S](g) + HT[34S](g) + H2S(g) = HTS(g) + H2[34S](g) + +T2[34S](g) + T2[34S](g) + H2S(g) = T2S(g) + H2[34S](g) + +DT[34S](g) + DT[34S](g) + H2S(g) = DTS(g) + H2[34S](g) + +# +# Gypsum and anhydrite +# +Ca[34S]O4:2H2O + Ca[34S]O4:2H2O + SO4-2 = [34S]O4-2 + Gypsum(s) + -add_logk Log_alpha_34S_Gypsum/SO4-2 -1.0 + +Ca[34S]O4 + Ca[34S]O4 + SO4-2 = [34S]O4-2 + Anhydrite(s) + -add_logk Log_alpha_34S_Anhydrite/SO4-2 -1.0 +# +# Nitrogen phases +# Checked September 19, 2006 +# +N[15N](g) + N[15N](g) + N2(aq) = N[15N](aq) + N2(g) + -add_logk Log_alpha_15N_N2(g)/N2(aq) -1.0 + +[15N]2(g) + [15N]2(g) + N2(g) = 2N[15N](g) + log_k 0.602059991327962396 # log10(4) + +NH2D(g) + NH2D(g) + H2O(l) = NH3(g) + HDO(aq) +## symmetry K?? + -add_logk Log_alpha_D_NH3(g)/H2O(l) -1.0 + +NHD2(g) + NHD2(g) + NH3(g) = 2NH2D(g) + log_k 0.477121254719 # log10(3) + +ND3(g) + ND3(g) + 2NH3(g) = 3NH2D(g) + -logk 1.431363764158 # log10(27) + +NH2T(g) + NH2T(g) + H2O(l) = NH3(g) + HTO(aq) +## symmetry K?? + -add_logk Log_alpha_T_NH3(g)/H2O(l) -1.0 + +NHT2(g) + NHT2(g) + NH3(g) = 2NH2T(g) + log_k 0.477121254719 # log10(3) + +NT3(g) + NT3(g) + 2NH3(g) = 3NH2T(g) + -logk 1.431363764158 # log10(27) + +ND2T(g) + ND2T(g) + NH3(g) = NHD2(g) + NH2T(g) + log_k 0.477121254719 # log10(3) + +NDT2(g) + NDT2(g) + NH3(g) = NH2D(g) + NHT2(g) + log_k 0.477121254719 # log10(3) + +[15N]H3(g) + [15N]H3(g) + NH3(aq) = [15N]H3(aq) + NH3(g) + -add_logk Log_alpha_15N_NH3(g)/NH3(aq) -1.0 + +[15N]H2D(g) + [15N]H2D(g) + NH3(g) = NH2D(g) + [15N]H3(g) + +[15N]HD2(g) + [15N]HD2(g) + NH3(g) = NHD2(g) + [15N]H3(g) + +[15N]D3(g) + [15N]D3(g) + NH3(g) = ND3(g) + [15N]H3(g) + +[15N]H2T(g) + [15N]H2T(g) + NH3(g) = NH2T(g) + [15N]H3(g) + +[15N]HT2(g) + [15N]HT2(g) + NH3(g) = NHT2(g) + [15N]H3(g) + +[15N]T3(g) + [15N]T3(g) + NH3(g) = NT3(g) + [15N]H3(g) + +[15N]D2T(g) + [15N]D2T(g) + NH3(g) = ND2T(g) + [15N]H3(g) + +[15N]DT2(g) + [15N]DT2(g) + NH3(g) = NDT2(g) + [15N]H3(g) diff --git a/rename_cpp/nvector.cpp b/rename_cpp/nvector.cpp new file mode 100644 index 00000000..f467c77d --- /dev/null +++ b/rename_cpp/nvector.cpp @@ -0,0 +1,220 @@ +/******************************************************************* + * * + * File : nvector.c * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic NVECTOR * + * package. It contains the implementation of the N_Vector * + * kernels listed in nvector.h. * + * * + *******************************************************************/ + +#include "nvector.h" /* generic M_Env and N_Vector */ + +N_Vector +N_VNew(integertype n, M_Env machEnv) +{ + N_Vector v_new; + v_new = machEnv->ops->nvnew(n, machEnv); + return (v_new); +} + +N_Vector_S +N_VNew_S(integertype ns, integertype n, M_Env machEnv) +{ + N_Vector_S vs_new; + vs_new = machEnv->ops->nvnewS(ns, n, machEnv); + return (vs_new); +} + +void +N_VFree(N_Vector v) +{ + v->menv->ops->nvfree(v); +} + +void +N_VFree_S(integertype ns, N_Vector_S vs) +{ + (*vs)->menv->ops->nvfreeS(ns, vs); +} + +N_Vector +N_VMake(integertype n, realtype * v_data, M_Env machEnv) +{ + N_Vector v_new; + v_new = machEnv->ops->nvmake(n, v_data, machEnv); + return (v_new); +} + +void +N_VDispose(N_Vector v) +{ + v->menv->ops->nvdispose(v); +} + +realtype * +N_VGetData(N_Vector v) +{ + realtype *data; + data = v->menv->ops->nvgetdata(v); + return (data); +} + +void +N_VSetData(realtype * v_data, N_Vector v) +{ + v->menv->ops->nvsetdata(v_data, v); +} + +void +N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z) +{ + z->menv->ops->nvlinearsum(a, x, b, y, z); +} + +void +N_VConst(realtype c, N_Vector z) +{ + z->menv->ops->nvconst(c, z); +} + +void +N_VProd(N_Vector x, N_Vector y, N_Vector z) +{ + z->menv->ops->nvprod(x, y, z); +} + +void +N_VDiv(N_Vector x, N_Vector y, N_Vector z) +{ + z->menv->ops->nvdiv(x, y, z); +} + +void +N_VScale(realtype c, N_Vector x, N_Vector z) +{ + z->menv->ops->nvscale(c, x, z); +} + +void +N_VAbs(N_Vector x, N_Vector z) +{ + z->menv->ops->nvabs(x, z); +} + +void +N_VInv(N_Vector x, N_Vector z) +{ + z->menv->ops->nvinv(x, z); +} + +void +N_VAddConst(N_Vector x, realtype b, N_Vector z) +{ + z->menv->ops->nvaddconst(x, b, z); +} + +realtype +N_VDotProd(N_Vector x, N_Vector y) +{ + realtype prod; + prod = y->menv->ops->nvdotprod(x, y); + return (prod); +} + +realtype +N_VMaxNorm(N_Vector x) +{ + realtype norm; + norm = x->menv->ops->nvmaxnorm(x); + return (norm); +} + +realtype +N_VWrmsNorm(N_Vector x, N_Vector w) +{ + realtype norm; + norm = x->menv->ops->nvwrmsnorm(x, w); + return (norm); +} + +realtype +N_VMin(N_Vector x) +{ + realtype minval; + minval = x->menv->ops->nvmin(x); + return (minval); +} + +realtype +N_VWL2Norm(N_Vector x, N_Vector w) +{ + realtype norm; + norm = x->menv->ops->nvwl2norm(x, w); + return (norm); +} + +realtype +N_VL1Norm(N_Vector x) +{ + realtype norm; + norm = x->menv->ops->nvl1norm(x); + return (norm); +} + +void +N_VOneMask(N_Vector x) +{ + x->menv->ops->nvonemask(x); +} + +void +N_VCompare(realtype c, N_Vector x, N_Vector z) +{ + z->menv->ops->nvcompare(c, x, z); +} + +booleantype +N_VInvTest(N_Vector x, N_Vector z) +{ + booleantype flag; + flag = z->menv->ops->nvinvtest(x, z); + return (flag); +} + +booleantype +N_VConstrProdPos(N_Vector c, N_Vector x) +{ + booleantype flag; + flag = x->menv->ops->nvconstrprodpos(c, x); + return (flag); +} + +booleantype +N_VConstrMask(N_Vector c, N_Vector x, N_Vector m) +{ + booleantype flag; + flag = x->menv->ops->nvconstrmask(c, x, m); + return (flag); +} + +realtype +N_VMinQuotient(N_Vector num, N_Vector denom) +{ + realtype quotient; + quotient = num->menv->ops->nvminquotient(num, denom); + return (quotient); +} + +void +N_VPrint(N_Vector x) +{ + x->menv->ops->nvprint(x); +} diff --git a/rename_cpp/nvector.h b/rename_cpp/nvector.h new file mode 100644 index 00000000..77673d9c --- /dev/null +++ b/rename_cpp/nvector.h @@ -0,0 +1,441 @@ +/******************************************************************* + * * + * File : nvector.h * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic NVECTOR package. * + * It defines the N_Vector and M_Env structures: * + * M_Env has an implementation-dependent 'content' field * + * which contains the data needed to generate a new * + * nvector in that implementation and an 'ops' filed * + * which is a structure listing operations acting on * + * such nvectors. * + * N_Vector has an implementation-dependent 'content' field * + * which contains the description and actual data of * + * the nvector and a 'menv' field which points to the * + * M_Env structure used in creating the nvector. * + * * + * Part I of this file contains type declarations for the * + * the following structures: _generic_M_Env, _generic_N_Vector, * + * and _generic_N_Vector_Ops, as well as references to pointers * + * to such structures (M_Env and N_Vector). * + * * + * Part II of this file contains the prototypes for the vector * + * kernels which operate on N_Vector. * + * * + * A particular implementation of an NVECTOR package must then * + * specify the 'content' fields of M_Env and N_Vector, define * + * the propotypes for kernel operations on those N_Vectors * + * (NOTE: kernel routine names must be unique to that * + * implementation), and finally provide an initialization * + * routine (which generates an M_Env with that particular * + * 'content' field and links the defined vector kernel routines * + * into the 'ops' field). * + * * + *******************************************************************/ + +class Phreeqc; +#ifndef included_nvector_h +#define included_nvector_h + +#include "sundialstypes.h" /* definition of types */ + +/**************************************************************** + * Generic definitions of machine environment and N_Vector * + ****************************************************************/ + +/* Forward reference for pointer to N_Vector_Ops object */ + typedef struct _generic_N_Vector_Ops *N_Vector_Ops; + +/* Forward reference for pointer to M_Env object */ + typedef struct _generic_M_Env *M_Env; + +/* Forward reference for pointer to N_Vector object */ + typedef struct _generic_N_Vector *N_Vector; + +/* Define array of N_Vectors */ + typedef N_Vector *N_Vector_S; + +/* Structure containing function pointers to vector operations */ + struct _generic_N_Vector_Ops + { + N_Vector(*nvnew) (integertype, M_Env); + N_Vector_S(*nvnewS) (integertype, integertype, M_Env); + void (*nvfree) (N_Vector); + void (*nvfreeS) (integertype, N_Vector_S); + N_Vector(*nvmake) (integertype, realtype *, M_Env); + void (*nvdispose) (N_Vector); + realtype *(*nvgetdata) (N_Vector); + void (*nvsetdata) (realtype *, N_Vector); + void (*nvlinearsum) (realtype, N_Vector, realtype, N_Vector, + N_Vector); + void (*nvconst) (realtype, N_Vector); + void (*nvprod) (N_Vector, N_Vector, N_Vector); + void (*nvdiv) (N_Vector, N_Vector, N_Vector); + void (*nvscale) (realtype, N_Vector, N_Vector); + void (*nvabs) (N_Vector, N_Vector); + void (*nvinv) (N_Vector, N_Vector); + void (*nvaddconst) (N_Vector, realtype, N_Vector); + realtype(*nvdotprod) (N_Vector, N_Vector); + realtype(*nvmaxnorm) (N_Vector); + realtype(*nvwrmsnorm) (N_Vector, N_Vector); + realtype(*nvmin) (N_Vector); + realtype(*nvwl2norm) (N_Vector, N_Vector); + realtype(*nvl1norm) (N_Vector); + void (*nvonemask) (N_Vector); + void (*nvcompare) (realtype, N_Vector, N_Vector); + booleantype(*nvinvtest) (N_Vector, N_Vector); + booleantype(*nvconstrprodpos) (N_Vector, N_Vector); + booleantype(*nvconstrmask) (N_Vector, N_Vector, N_Vector); + realtype(*nvminquotient) (N_Vector, N_Vector); + void (*nvprint) (N_Vector); + }; + +/* A machine environment is a structure with an implementation + dependent 'content' representation (used to generate a new vector + in that implementation), a set of operations defined in the above + structure, and an ID tag */ + struct _generic_M_Env + { + void *content; + struct _generic_N_Vector_Ops *ops; + char tag[8]; + Phreeqc * phreeqc_ptr; + }; + +/* A vector is a structure with an implementation dependent content + representation and a pointer to the machine environment + corresponding to that implementation */ + struct _generic_N_Vector + { + void *content; + struct _generic_M_Env *menv; + }; + +/**************************************************************** + * Functions exported by nvector * + ****************************************************************/ + +/*--------------------------------------------------------------* + * Function : N_VNew * + * Usage : v = N_VNew(n, machEnv); * + *--------------------------------------------------------------* + * Returns a new N_Vector of length n. The parameter machEnv * + * is a pointer to machine environment-specific information. * + * If there is not enough memory for a new N_Vector, then * + * N_VNew returns NULL. * + *--------------------------------------------------------------*/ + + N_Vector N_VNew(integertype n, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VNew_S * + * Usage : v = N_VNew_S(ns, n, machEnv); * + *--------------------------------------------------------------* + * Returns an array of ns new N_Vectors of length n. The * + * parameter machEnv is a pointer to machine environment * + * specific information. * + * If there is not enough memory for a new array of N_Vectors * + * or for one of the components, then N_VNew_S returns NULL. * + *--------------------------------------------------------------*/ + + N_Vector_S N_VNew_S(integertype ns, integertype n, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VFree * + * Usage : N_VFree(v); * + *--------------------------------------------------------------* + * Frees the N_Vector v. It is illegal to use v after the call * + * N_VFree(v). * + *--------------------------------------------------------------*/ + + void N_VFree(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VFree_S * + * Usage : N_VFree_S(ns, vs); * + *--------------------------------------------------------------* + * Frees the array of ns N_Vectors vs. * + * It is illegal to use vs after the call N_VFree_S(Ns,vs). * + *--------------------------------------------------------------*/ + + void N_VFree_S(integertype ns, N_Vector_S vs); + +/*--------------------------------------------------------------* + * Function : N_VMake * + * Usage : v = N_VMake(n, v_data, machEnv); * + *--------------------------------------------------------------* + * Creates an N_Vector with component array data allocated by * + * the user. * + *--------------------------------------------------------------*/ + + N_Vector N_VMake(integertype n, realtype * v_data, M_Env machEnv); + +/*--------------------------------------------------------------* + * Function : N_VDispose * + * Usage : N_VDispose(v); * + *--------------------------------------------------------------* + * Destroys an N_Vector with component array data allocated by * + * the user. * + *--------------------------------------------------------------*/ + + void N_VDispose(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VGetData * + * Usage : v_data = N_VGetData(v); * + *--------------------------------------------------------------* + * Extracts the data component array from the N_Vector v. * + * Note: this routine is used in the solver-specific interfaces * + * to the dense and banded linear solvers, as well as the * + * interfaces to the banded preconditioners provided with * + * SUNDIALS. It needs not be implemented by a user * + * defined NVECTOR module, if these linear solvers are not* + * used. * + *--------------------------------------------------------------*/ + + realtype *N_VGetData(N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VSetData * + * Usage : N_VSetData(v_data, v); * + *--------------------------------------------------------------* + * Attaches the data component array v_data to the N_Vector v. * + * Note: this routine is used in the solver-specific interfaces * + * to the dense and banded linear solvers, as well as the * + * interfaces to the banded preconditioners provided with * + * SUNDIALS. It needs not be implemented by a user * + * defined NVECTOR module, if these linear solvers are not* + * used. * + *--------------------------------------------------------------*/ + + void N_VSetData(realtype * v_data, N_Vector v); + +/*--------------------------------------------------------------* + * Function : N_VLinearSum * + * Operation : z = a x + b y * + *--------------------------------------------------------------*/ + + void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, + N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VConst * + * Operation : z[i] = c for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + + void N_VConst(realtype c, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VProd * + * Operation : z[i] = x[i] * y[i] for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + + void N_VProd(N_Vector x, N_Vector y, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VDiv * + * Operation : z[i] = x[i] / y[i] for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + + void N_VDiv(N_Vector x, N_Vector y, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VScale * + * Operation : z = c x * + *--------------------------------------------------------------*/ + + void N_VScale(realtype c, N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VAbs * + * Operation : z[i] = |x[i]|, for i=0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + + void N_VAbs(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VInv * + * Operation : z[i] = 1.0 / x[i] for i = 0, 1, ..., N-1 * + *--------------------------------------------------------------* + * This routine does not check for division by 0. It should be * + * called only with an N_Vector x which is guaranteed to have * + * all non-zero components. * + *--------------------------------------------------------------*/ + + void N_VInv(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VAddConst * + * Operation : z[i] = x[i] + b for i = 0, 1, ..., N-1 * + *--------------------------------------------------------------*/ + + void N_VAddConst(N_Vector x, realtype b, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VDotProd * + * Usage : dotprod = N_VDotProd(x, y); * + *--------------------------------------------------------------* + * Returns the value of the ordinary dot product of x and y: * + * -> sum (i=0 to N-1) {x[i] * y[i]} * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VDotProd(N_Vector x, N_Vector y); + +/*--------------------------------------------------------------* + * Function : N_VMaxNorm * + * Usage : maxnorm = N_VMaxNorm(x); * + *--------------------------------------------------------------* + * Returns the maximum norm of x: * + * -> max (i=0 to N-1) |x[i]| * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VMaxNorm(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VWrmsNorm * + * Usage : wrmsnorm = N_VWrmsNorm(x, w); * + *--------------------------------------------------------------* + * Returns the weighted root mean square norm of x with * + * weight vector w: * + * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) / N] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VWrmsNorm(N_Vector x, N_Vector w); + +/*--------------------------------------------------------------* + * Function : N_VMin * + * Usage : min = N_VMin(x); * + *--------------------------------------------------------------* + * Returns the smallest element of x: * + * -> min (i=0 to N-1) x[i] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VMin(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VWL2Norm * + * Usage : wl2norm = N_VWL2Norm(x, w); * + *--------------------------------------------------------------* + * Returns the weighted Euclidean L2 norm of x with * + * weight vector w: * + * -> sqrt [(sum (i=0 to N-1) {(x[i] * w[i])^2}) ] * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VWL2Norm(N_Vector x, N_Vector w); + +/*--------------------------------------------------------------* + * Function : N_VL1Norm * + * Usage : l1norm = N_VL1Norm(x); * + *--------------------------------------------------------------* + * Returns the L1 norm of x: * + * -> sum (i=0 to N-1) {ABS(x[i])} * + * Returns 0.0 if N <= 0. * + *--------------------------------------------------------------*/ + + realtype N_VL1Norm(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VOneMask * + * Operation : x[i] = 1.0 if |x[i]| != 0. i = 0, 1, ..., N-1 * + * 0.0 otherwise * + *--------------------------------------------------------------*/ + + void N_VOneMask(N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VCompare * + * Operation : z[i] = 1.0 if |x[i]| >= c i = 0, 1, ..., N-1 * + * 0.0 otherwise * + *--------------------------------------------------------------*/ + + void N_VCompare(realtype c, N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VInvTest * + * Operation : z[i] = 1.0 / x[i] with a test for x[i]==0.0 * + * before inverting x[i]. * + *--------------------------------------------------------------* + * This routine returns TRUE if all components of x are * + * non-zero (successful inversion) and returns FALSE * + * otherwise. * + *--------------------------------------------------------------*/ + + booleantype N_VInvTest(N_Vector x, N_Vector z); + +/*--------------------------------------------------------------* + * Function : N_VConstrProdPos * + * Usage : booltest = N_VConstrProdPos(c,x); * + *--------------------------------------------------------------* + * Returns a boolean equal to * + * FALSE if some c[i] != 0.0 and x[i]*c[i] <= 0.0, or * + * TRUE otherwise. * + * * + * This routine is used for constraint checking. * + *--------------------------------------------------------------*/ + + booleantype N_VConstrProdPos(N_Vector c, N_Vector x); + +/*--------------------------------------------------------------* + * Function : N_VConstrMask * + * Operation : m[i] = 1.0 if constraint test fails for x[i] * + * m[i] = 0.0 if constraint test passes for x[i] * + * where the constraint tests are as follows: * + * If c[i] = 2.0, then x[i] must be > 0.0. * + * If c[i] = 1.0, then x[i] must be >= 0.0. * + * If c[i] = -1.0, then x[i] must be <= 0.0. * + * If c[i] = -2.0, then x[i] must be < 0.0. * + *--------------------------------------------------------------* + * This routine returns a boolean FALSE if any element failed * + * the constraint test, TRUE if all passed. It also sets a * + * mask vector m, with elements equal to 1.0 where the * + * corresponding constraint test failed, and equal to 0.0 * + * where the constraint test passed. * + * This routine is specialized in that it is used only for * + * constraint checking. * + *--------------------------------------------------------------*/ + + booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m); + +/*--------------------------------------------------------------* + * Function : N_VMinQuotient * + * Operation : minq = min ( num[i]/denom[i]) over all i such * + * that denom[i] != 0. * + *--------------------------------------------------------------* + * This routine returns the minimum of the quotients obtained * + * by term-wise dividing num[i] by denom[i]. A zero element * + * in denom will be skipped. If no such quotients are found, * + * then the large value 1.e99 is returned. * + *--------------------------------------------------------------*/ + + realtype N_VMinQuotient(N_Vector num, N_Vector denom); + +/*--------------------------------------------------------------* + * Function : N_VPrint * + * Usage : N_VPrint(x); * + *--------------------------------------------------------------* + * Prints the N_Vector x to stdout. * + * This routine is provided as an aid in debugging code which * + * uses this vector package. * + *--------------------------------------------------------------*/ + + void N_VPrint(N_Vector x); + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ diff --git a/rename_cpp/nvector_serial.cpp b/rename_cpp/nvector_serial.cpp new file mode 100644 index 00000000..50ce7a78 --- /dev/null +++ b/rename_cpp/nvector_serial.cpp @@ -0,0 +1,978 @@ +/******************************************************************* + * * + * File : nvector_serial.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * + * Radu Serban, and Allan G. Taylor, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a serial implementation * + * of the NVECTOR package. It contains the implementation of * + * the serial machine environment intialization and free * + * routines (and of the Fortran callable interfaces to them) * + * and of the N_Vector kernels listed in nvector_serial.h. * + * * + *******************************************************************/ + +#include +#include +#include +#include "nvector_serial.h" +#include "sundialstypes.h" +#include "sundialsmath.h" + +/* WARNING don't include any headers below here */ + +#define ZERO RCONST(0.0) +#define HALF RCONST(0.5) +#define ONE RCONST(1.0) +#define ONEPT5 RCONST(1.5) + + +/* Private Helper Prototypes */ +/* z=x */ +static void VCopy_Serial(N_Vector x, N_Vector z); +/* z=x+y */ +static void VSum_Serial(N_Vector x, N_Vector y, N_Vector z); +/* z=x-y */ +static void VDiff_Serial(N_Vector x, N_Vector y, N_Vector z); +/* z=-x */ +static void VNeg_Serial(N_Vector x, N_Vector z); +/* z=c(x+y) */ +static void VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); +/* z=c(x-y) */ +static void VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z); +/* z=ax+y */ +static void VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); +/* z=ax-y */ +static void VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z); +/* y <- ax+y */ +static void Vaxpy_Serial(realtype a, N_Vector x, N_Vector y); +/* x <- ax */ +static void VScaleBy_Serial(realtype a, N_Vector x); + +/********************* Exported Functions ************************/ + +/* Serial implementation of the machine environment + initialization routine */ + +M_Env +M_EnvInit_Serial(integertype vec_length) +{ + M_Env me; + + /* Create machine environment structure */ + me = (M_Env) malloc(sizeof *me); + if (me == NULL) + return (NULL); + + /* Create serial content of machine environment structure */ + me->content = + (M_EnvSerialContent) malloc(sizeof(struct _M_EnvSerialContent)); + if (me->content == NULL) + { + free(me); + return (NULL); + } + + /* Load serial content of machine environment structure */ + ME_CONTENT_S(me)->length = vec_length; + + /* Attach vector operations */ + me->ops = (N_Vector_Ops) malloc(sizeof(struct _generic_N_Vector_Ops)); + if (me->ops == NULL) + { + free(me->content); + free(me); + return (NULL); + } + + me->ops->nvnew = N_VNew_Serial; + me->ops->nvnewS = N_VNew_S_Serial; + me->ops->nvfree = N_VFree_Serial; + me->ops->nvfreeS = N_VFree_S_Serial; + me->ops->nvmake = N_VMake_Serial; + me->ops->nvdispose = N_VDispose_Serial; + me->ops->nvgetdata = N_VGetData_Serial; + me->ops->nvsetdata = N_VSetData_Serial; + me->ops->nvlinearsum = N_VLinearSum_Serial; + me->ops->nvconst = N_VConst_Serial; + me->ops->nvprod = N_VProd_Serial; + me->ops->nvdiv = N_VDiv_Serial; + me->ops->nvscale = N_VScale_Serial; + me->ops->nvabs = N_VAbs_Serial; + me->ops->nvinv = N_VInv_Serial; + me->ops->nvaddconst = N_VAddConst_Serial; + me->ops->nvdotprod = N_VDotProd_Serial; + me->ops->nvmaxnorm = N_VMaxNorm_Serial; + me->ops->nvwrmsnorm = N_VWrmsNorm_Serial; + me->ops->nvmin = N_VMin_Serial; + me->ops->nvwl2norm = N_VWL2Norm_Serial; + me->ops->nvl1norm = N_VL1Norm_Serial; + me->ops->nvonemask = N_VOneMask_Serial; + me->ops->nvcompare = N_VCompare_Serial; + me->ops->nvinvtest = N_VInvTest_Serial; + me->ops->nvconstrprodpos = N_VConstrProdPos_Serial; + me->ops->nvconstrmask = N_VConstrMask_Serial; + me->ops->nvminquotient = N_VMinQuotient_Serial; + me->ops->nvprint = N_VPrint_Serial; + + /* Attach ID tag */ + strcpy(me->tag, ID_TAG_S); + + return (me); + +} + +/* Serial implementation of the machine environment + free routine */ + +void +M_EnvFree_Serial(M_Env machEnv) +{ + if (machEnv == NULL) + return; + + free(machEnv->content); + free(machEnv->ops); + free(machEnv); +} + +/***************************************************************************/ + +/* BEGIN implementation of vector operations */ + +N_Vector +N_VNew_Serial(integertype n, M_Env machEnv) +{ + N_Vector v; + integertype length; + + if (n <= 0) + return (NULL); + + if (machEnv == NULL) + return (NULL); + + v = (N_Vector) malloc(sizeof *v); + if (v == NULL) + return (NULL); + + v->content = + (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); + if (v->content == NULL) + { + free(v); + return (NULL); + } + + length = ME_CONTENT_S(machEnv)->length; + + NV_CONTENT_S(v)->data = (realtype *) malloc(length * sizeof(realtype)); + if (NV_CONTENT_S(v)->data == NULL) + { + free(v->content); + free(v); + return (NULL); + } + + NV_CONTENT_S(v)->length = length; + + v->menv = machEnv; + + return (v); +} + + +N_Vector_S +N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv) +{ + N_Vector_S vs; + integertype is, j; + + + if (ns <= 0 || n <= 0) + return (NULL); + + if (machEnv == NULL) + return (NULL); + + vs = (N_Vector_S) malloc(ns * sizeof(N_Vector *)); + if (vs == NULL) + return (NULL); + + for (is = 0; is < ns; is++) + { + vs[is] = N_VNew_Serial(n, machEnv); + if (vs[is] == NULL) + { + for (j = 0; j < is; j++) + N_VFree_Serial(vs[j]); + free(vs); + return (NULL); + } + } + + return (vs); +} + + +void +N_VFree_Serial(N_Vector v) +{ + free(NV_DATA_S(v)); + free(NV_CONTENT_S(v)); + free(v); +} + + +void +N_VFree_S_Serial(integertype ns, N_Vector_S vs) +{ + integertype is; + + for (is = 0; is < ns; is++) + N_VFree_Serial(vs[is]); + free(vs); +} + +N_Vector +N_VMake_Serial(integertype n, realtype * v_data, M_Env machEnv) +{ + N_Vector v; + integertype length; + + if (n <= 0) + return (NULL); + + if (machEnv == NULL) + return (NULL); + + v = (N_Vector) malloc(sizeof *v); + if (v == NULL) + return (NULL); + + v->content = + (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); + if (v->content == NULL) + { + free(v); + return (NULL); + } + + length = ME_CONTENT_S(machEnv)->length; + + NV_CONTENT_S(v)->data = v_data; + + NV_CONTENT_S(v)->length = length; + + v->menv = machEnv; + + return (v); +} + +void +N_VDispose_Serial(N_Vector v) +{ + free(NV_CONTENT_S(v)); + free(v); +} + +realtype * +N_VGetData_Serial(N_Vector v) +{ + realtype *v_data; + v_data = NV_CONTENT_S(v)->data; + return (v_data); +} + +void +N_VSetData_Serial(realtype * v_data, N_Vector v) +{ + NV_CONTENT_S(v)->data = v_data; +} + +void +N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, + N_Vector z) +{ + integertype i, N; + realtype c, *xd, *yd, *zd; + N_Vector v1, v2; + booleantype test; + + if ((b == ONE) && (z == y)) + { /* BLAS usage: axpy y <- ax+y */ + Vaxpy_Serial(a, x, y); + return; + } + + if ((a == ONE) && (z == x)) + { /* BLAS usage: axpy x <- by+x */ + Vaxpy_Serial(b, y, x); + return; + } + + /* Case: a == b == 1.0 */ + + if ((a == ONE) && (b == ONE)) + { + VSum_Serial(x, y, z); + return; + } + + /* Cases: (1) a == 1.0, b = -1.0, (2) a == -1.0, b == 1.0 */ + + /*if ((test = ((a == ONE) && (b == -ONE))) || ((a == -ONE) && (b == ONE))) { */ + test = ((a == ONE) && (b == -ONE)); + if (test || ((a == -ONE) && (b == ONE))) + { + v1 = test ? y : x; + v2 = test ? x : y; + VDiff_Serial(v2, v1, z); + return; + } + + /* Cases: (1) a == 1.0, b == other or 0.0, (2) a == other or 0.0, b == 1.0 */ + /* if a or b is 0.0, then user should have called N_VScale */ + + /*if ((test = (a == ONE)) || (b == ONE)) { */ + test = (a == ONE); + if (test || (b == ONE)) + { + c = test ? b : a; + v1 = test ? y : x; + v2 = test ? x : y; + VLin1_Serial(c, v1, v2, z); + return; + } + + /* Cases: (1) a == -1.0, b != 1.0, (2) a != 1.0, b == -1.0 */ + + /*if ((test = (a == -ONE)) || (b == -ONE)) { */ + test = (a == -ONE); + if (test || (b == -ONE)) + { + c = test ? b : a; + v1 = test ? y : x; + v2 = test ? x : y; + VLin2_Serial(c, v1, v2, z); + return; + } + + /* Case: a == b */ + /* catches case both a and b are 0.0 - user should have called N_VConst */ + + if (a == b) + { + VScaleSum_Serial(a, x, y, z); + return; + } + + /* Case: a == -b */ + + if (a == -b) + { + VScaleDiff_Serial(a, x, y, z); + return; + } + + /* Do all cases not handled above: + (1) a == other, b == 0.0 - user should have called N_VScale + (2) a == 0.0, b == other - user should have called N_VScale + (3) a,b == other, a !=b, a != -b */ + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = a * (*xd++) + b * (*yd++); +} + + +void +N_VConst_Serial(realtype c, N_Vector z) +{ + integertype i, N; + realtype *zd; + + N = NV_LENGTH_S(z); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = c; +} + + +void +N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = (*xd++) * (*yd++); +} + + +void +N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = (*xd++) / (*yd++); +} + + +void +N_VScale_Serial(realtype c, N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + if (z == x) + { /* BLAS usage: scale x <- cx */ + VScaleBy_Serial(c, x); + return; + } + + if (c == ONE) + { + VCopy_Serial(x, z); + } + else if (c == -ONE) + { + VNeg_Serial(x, z); + } + else + { + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + for (i = 0; i < N; i++) + *zd++ = c * (*xd++); + } +} + + +void +N_VAbs_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++, xd++, zd++) + *zd = ABS(*xd); +} + + +void +N_VInv_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = ONE / (*xd++); +} + + +void +N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = (*xd++) + b; +} + + +realtype +N_VDotProd_Serial(N_Vector x, N_Vector y) +{ + integertype i, N; + realtype sum = ZERO, *xd, *yd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + + for (i = 0; i < N; i++) + sum += (*xd++) * (*yd++); + + return (sum); +} + + +realtype +N_VMaxNorm_Serial(N_Vector x) +{ + integertype i, N; + realtype max = ZERO, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i = 0; i < N; i++, xd++) + { + if (ABS(*xd) > max) + max = ABS(*xd); + } + + return (max); +} + + +realtype +N_VWrmsNorm_Serial(N_Vector x, N_Vector w) +{ + integertype i, N; + realtype sum = ZERO, prodi, *xd, *wd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + wd = NV_DATA_S(w); + + for (i = 0; i < N; i++) + { + prodi = (*xd++) * (*wd++); + sum += prodi * prodi; + } + + return (RSqrt(sum / N)); +} + + +realtype +N_VMin_Serial(N_Vector x) +{ + integertype i, N; + realtype min, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + min = xd[0]; + + xd++; + for (i = 1; i < N; i++, xd++) + { + if ((*xd) < min) + min = *xd; + } + + return (min); +} + + +realtype +N_VWL2Norm_Serial(N_Vector x, N_Vector w) +{ + integertype i, N; + realtype sum = ZERO, prodi, *xd, *wd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + wd = NV_DATA_S(w); + + for (i = 0; i < N; i++) + { + prodi = (*xd++) * (*wd++); + sum += prodi * prodi; + } + + return (RSqrt(sum)); +} + + +realtype +N_VL1Norm_Serial(N_Vector x) +{ + integertype i, N; + realtype sum = ZERO, *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i = 0; i < N; i++) + sum += ABS(xd[i]); + + return (sum); +} + + +void +N_VOneMask_Serial(N_Vector x) +{ + integertype i, N; + realtype *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i = 0; i < N; i++, xd++) + { + if (*xd != ZERO) + *xd = ONE; + } +} + + +void +N_VCompare_Serial(realtype c, N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++, xd++, zd++) + { + *zd = (ABS(*xd) >= c) ? ONE : ZERO; + } +} + + +booleantype +N_VInvTest_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + { + if (*xd == ZERO) + return (FALSE); + *zd++ = ONE / (*xd++); + } + + return (TRUE); +} + + +booleantype +N_VConstrProdPos_Serial(N_Vector c, N_Vector x) +{ + integertype i, N; + realtype *xd, *cd; + booleantype test; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + cd = NV_DATA_S(c); + + test = TRUE; + + for (i = 0; i < N; i++, xd++, cd++) + { + if (*cd != ZERO) + { + if ((*xd) * (*cd) <= ZERO) + { + test = FALSE; + break; + } + } + } + return (test); +} + + +booleantype +N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m) +{ + integertype i, N; + booleantype test; + realtype *cd, *xd, *md; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + cd = NV_DATA_S(c); + md = NV_DATA_S(m); + + test = TRUE; + + for (i = 0; i < N; i++, cd++, xd++, md++) + { + *md = ZERO; + if (*cd == ZERO) + continue; + if (*cd > ONEPT5 || (*cd) < -ONEPT5) + { + if ((*xd) * (*cd) <= ZERO) + { + test = FALSE; + *md = ONE; + } + continue; + } + if ((*cd) > HALF || (*cd) < -HALF) + { + if ((*xd) * (*cd) < ZERO) + { + test = FALSE; + *md = ONE; + } + } + } + return (test); +} + + +realtype +N_VMinQuotient_Serial(N_Vector num, N_Vector denom) +{ + booleantype notEvenOnce; + integertype i, N; + realtype *nd, *dd, min; + + N = NV_LENGTH_S(num); + nd = NV_DATA_S(num); + dd = NV_DATA_S(denom); + min = 0; + + notEvenOnce = TRUE; + + for (i = 0; i < N; i++, nd++, dd++) + { + if (*dd == ZERO) + continue; + else + { + if (notEvenOnce) + { + min = *nd / *dd; + notEvenOnce = FALSE; + } + else + min = MIN(min, (*nd) / (*dd)); + } + } + if (notEvenOnce) + min = 1.e99; + + return (min); +} + + +void +N_VPrint_Serial(N_Vector x) +{ + integertype i, N; + realtype *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i = 0; i < N; i++) + printf("%11.8g\n", (double) (*xd++)); + + printf("\n"); +} + + +/***************** Private Helper Functions **********************/ + + +static void +VCopy_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = *xd++; +} + + +static void +VSum_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = (*xd++) + (*yd++); +} + + +static void +VDiff_Serial(N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = (*xd++) - (*yd++); +} + + +static void +VNeg_Serial(N_Vector x, N_Vector z) +{ + integertype i, N; + realtype *xd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = -(*xd++); +} + + +static void +VScaleSum_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = c * ((*xd++) + (*yd++)); +} + + +static void +VScaleDiff_Serial(realtype c, N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = c * ((*xd++) - (*yd++)); +} + + +static void +VLin1_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = a * (*xd++) + (*yd++); +} + + +static void +VLin2_Serial(realtype a, N_Vector x, N_Vector y, N_Vector z) +{ + integertype i, N; + realtype *xd, *yd, *zd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + zd = NV_DATA_S(z); + + for (i = 0; i < N; i++) + *zd++ = a * (*xd++) - (*yd++); +} + +static void +Vaxpy_Serial(realtype a, N_Vector x, N_Vector y) +{ + integertype i, N; + realtype *xd, *yd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + yd = NV_DATA_S(y); + + if (a == ONE) + { + for (i = 0; i < N; i++) + *yd++ += (*xd++); + return; + } + + if (a == -ONE) + { + for (i = 0; i < N; i++) + *yd++ -= (*xd++); + return; + } + + for (i = 0; i < N; i++) + *yd++ += a * (*xd++); +} + +static void +VScaleBy_Serial(realtype a, N_Vector x) +{ + integertype i, N; + realtype *xd; + + N = NV_LENGTH_S(x); + xd = NV_DATA_S(x); + + for (i = 0; i < N; i++) + *xd++ *= a; +} diff --git a/rename_cpp/nvector_serial.h b/rename_cpp/nvector_serial.h new file mode 100644 index 00000000..288b1a7a --- /dev/null +++ b/rename_cpp/nvector_serial.h @@ -0,0 +1,325 @@ +#ifndef _INC_NVECTOR_SERIAL_H +#define _INC_NVECTOR_SERIAL_H +/******************************************************************* + * * + * File : nvector_serial.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * + * : Radu Serban, and Allan G. Taylor, LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a serial implementation of the * + * NVECTOR package. * + * * + * Part I of this file contains declarations which are specific * + * to the particular machine environment in which this version * + * of the vector package is to be used. This includes the * + * typedef for the 'content' fields of the structures M_Env and * + * N_Vector (M_EnvSerialContent and N_VectorSerialContent, * + * respectively). * + * * + * Part II of this file defines accessor macros that allow the * + * user to use efficiently the type N_Vector without making * + * explicit references to its underlying representation. * + * * + * Part III of this file contains the prototype for the * + * initialization routine specific to this implementation * + * (M_EnvInit_Serial) as well as prototypes for the vector * + * kernels which operate on the serial N_Vector. These * + * prototypes are unique to this particular implementation of * + * the vector package. * + * * + * NOTES: * + * * + * The definitions of the generic M_Env and N_Vector structures * + * are in the header file nvector.h. * + * * + * The definitions of the types realtype and integertype are in * + * the header file sundialstypes.h and these may be changed * + * according to the user's needs. The sundialstypes.h file also * + * contains the definition for the type booleantype. * + * * + * N_Vector arguments to arithmetic kernels need not be * + * distinct. Thus, for example, the call * + * N_VLinearSum_Serial(a,x,b,y,y); y <- ax+by * + * is legal. * + * * + * This version of nvector is for the ordinary sequential * + * machine environment. In the documentation given below, N is * + * the length of all N_Vector parameters and x[i] denotes the * + * ith component of the N_Vector x, where 0 <= i <= N-1. * + * * + *******************************************************************/ +#ifndef included_nvector_serial_h +#define included_nvector_serial_h + +#include "nvector.h" /* Generic M_Env and N_Vector type definitions */ +#include "sundialstypes.h" + + +/**************************************************************** + * PART I: * + * Serial implementaion of M_Env and N_Vector * + ****************************************************************/ + +/* The serial implementation of the machine environment has + ID tag 'serial' */ +#define ID_TAG_S "serial" + +/* The serial implementation of the machine environment 'content' + structure contains the length of vectors */ + + struct _M_EnvSerialContent + { + integertype length; + }; + + typedef struct _M_EnvSerialContent *M_EnvSerialContent; + +/* The serial implementation of the N_Vector 'content' + structure contains the length of the vector and a pointer + to an array of realtype components */ + + struct _N_VectorSerialContent + { + integertype length; + realtype *data; + }; + + typedef struct _N_VectorSerialContent *N_VectorSerialContent; + +/**************************************************************** + * * + * PART II: Macros * + * NV_MAKE_S, NV_DISPOSE_S, NVS_MAKE_S, NVS_DISPOSE_S * + * ME_CONTENT_S, NV_CONTENT_S * + * NV_DATA_S, NV_LENGTH_S, NV_Ith_S * + *--------------------------------------------------------------* + * In the descriptions below, the following user declarations * + * are assumed: * + * * + * M_Env machenv; * + * N_Vector v, *vs; * + * realtype *v_data, **vs_data, r; * + * integertype v_len, s_len, i; * + * * + * (1) NV_MAKE_S, NV_DISPOSE_S * + * * + * These companion routines are used to create and * + * destroy an N_Vector with a component array v_data * + * allocated by the user. * + * * + * The call NV_MAKE_S(v, v_data, machenv) makes v an * + * N_Vector with component array v_data. The length of the * + * array is taken from machenv. * + * NV_MAKE_S stores the pointer v_data so that changes * + * made by the user to the elements of v_data are * + * simultaneously reflected in v. There is no copying of * + * elements. * + * * + * The call NV_DISPOSE_S(v) frees all memory associated * + * with v except for its component array. This memory was * + * allocated by the user and, therefore, should be * + * deallocated by the user. * + * * + * (2) NVS_MAKE_S, NVS_DISPOSE_S * + * * + * These companion routines are used to create and destroy * + * an array of N_Vectors with component vs_data allocated * + * by the user. * + * * + * The call NVS_MAKE_S(vs, vs_data, s_len, machenv) makes * + * vs an array of s_len N_Vectors, each with component * + * array vs_data[i] and array length taken from machenv. * + * NVS_MAKE_S stores the pointers vs_data[i] so that * + * changes made by the user to the elements of vs_data are * + * simultaneously reflected in vs. There is no copying of * + * elements. * + * * + * The call NVS_DISPOSE_S(vs) frees all memory associated * + * with vs except for its components' component array. * + * This memory was allocated by the user and, therefore, * + * should be deallocated by the user. * + * * + * (3) ME_CONTENT_S, NV_CONTENT_S * + * * + * These routines give access to the contents of the serial * + * machine environment and N_Vector, respectively. * + * * + * The assignment m_cont = ME_CONTENT_S(machenv) sets * + * m_cont to be a pointer to the serial machine * + * environment content structure. * + * * + * The assignment v_cont = NV_CONTENT_S(v) sets * + * v_cont to be a pointer to the serial N_Vector content * + * structure. * + * * + * (4) NV_DATA_S, NV_LENGTH_S * + * * + * These routines give individual access to the parts of * + * the content of a serial N_Vector. * + * * + * The assignment v_data=NV_DATA_S(v) sets v_data to be * + * a pointer to the first component of v. The assignment * + * NV_DATA_S(v)=v_data sets the component array of v to * + * be v_data by storing the pointer v_data. * + * * + * The assignment v_len=NV_LENGTH_S(v) sets v_len to be * + * the length of v. The call NV_LENGTH_S(v)=len_v sets * + * the length of v to be len_v. * + * * + * (5) NV_Ith_S * + * * + * In the following description, the components of an * + * N_Vector are numbered 0..N-1, where N is the length of * + * v. * + * * + * The assignment r=NV_Ith_S(v,i) sets r to be the value of * + * the ith component of v. The assignment NV_Ith_S(v,i)=r * + * sets the value of the ith component of v to be r. * + * * + * Notes.. * + * * + * Users who use the macros (1) and/or (2) must * + * #include since these macros expand to calls to * + * malloc and free. * + * * + * When looping over the components of an N_Vector v, it is * + * more efficient to first obtain the component array via * + * v_data=NV_DATA_S(v) and then access v_data[i] within the * + * loop than it is to use NV_Ith_S(v,i) within the loop. * + * * + * NV_MAKE_S and NV_DISPOSE_S are similar to N_VNew_Serial and * + * N_VFree_Serial, while NVS_MAKE_S and NVS_DISPOSE_S are * + * similar to N_VNew_S_Serial and N_VFree_S_Serial. The * + * difference is one of responsibility for component memory * + * allocation and deallocation. N_VNew_Serial allocates memory * + * for the N_Vector components and N_VFree_Serial frees the * + * component memory allocated by N_VNew_Serial. For NV_MAKE_S * + * and NV_DISPOSE_S, the component memory is allocated and * + * freed by the user of this package. Similar remarks hold for * + * NVS_MAKE_S, NVS_DISPOSE_S and N_VNew_S_Serial, * + * N_VFree_S_Serial. * + * * + ****************************************************************/ + +#define NV_MAKE_S(v, v_data, machenv) \ + v = (N_Vector) malloc(sizeof(*v)); \ + v->content = (N_VectorSerialContent) malloc(sizeof(struct _N_VectorSerialContent)); \ + v->content->data = v_data; \ + v->content->length = machenv->content->v_len; \ + v->menv = machenv + +#define NV_DISPOSE_S(v) \ + PHRQ_free((N_VectorSerialContent)(v->content)); \ + PHRQ_free(v) + +#define NVS_MAKE_S(vs, vs_data, s_len, machenv) \ + vs = (N_Vector_S) malloc(s_len*sizeof(N_Vector *)); \ + for ((int)is=0; iscontent) ) + +#define NV_CONTENT_S(v) ( (N_VectorSerialContent)(v->content) ) + +#define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length ) + +#define NV_DATA_S(v) ( NV_CONTENT_S(v)->data ) + +#define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] ) + + +/**************************************************************** + * PART III: * + * Functions exported by nvector_serial * + ****************************************************************/ + +/*--------------------------------------------------------------* + * Routine : M_EnvInit_Serial * + *--------------------------------------------------------------* + * This function sets the content field of the machine * + * environment for the serial implementation to a structure of * + * type _MEnvSerialContent and attaches the vector operations * + * defined for this implementation. * + * * + * If successful, M_EnvInit_Serial returns a pointer of type * + * M_Env. This pointer should in turn be passed in any user * + * calls to N_VNew, or uses of the macros NV_MAKE_S and * + * NVS_MAKE_S. * + * * + *--------------------------------------------------------------* + * * + * vec_length is the length of the vector. * + * * + *--------------------------------------------------------------*/ + + M_Env M_EnvInit_Serial(integertype vec_length); + +/*--------------------------------------------------------------* + * Function M_EnvFree_Serial * + *--------------------------------------------------------------* + * Function to free the block of machine-dependent environment * + * information created by M_EnvInit_Serial. * + * Its only argument is the pointer machenv returned by * + * M_EnvInit_Serial. * + * * + *--------------------------------------------------------------*/ + + void M_EnvFree_Serial(M_Env machenv); + +/*--------------------------------------------------------------* + * Serial implementations of the vector operations * + * * + * For a complete description of each of the following routines * + * see the header file nvector.h * + *--------------------------------------------------------------*/ + + N_Vector N_VNew_Serial(integertype n, M_Env machEnv); + N_Vector_S N_VNew_S_Serial(integertype ns, integertype n, M_Env machEnv); + void N_VFree_Serial(N_Vector v); + void N_VFree_S_Serial(integertype ns, N_Vector_S vs); + N_Vector N_VMake_Serial(integertype n, realtype * v_data, M_Env machEnv); + void N_VDispose_Serial(N_Vector v); + realtype *N_VGetData_Serial(N_Vector v); + void N_VSetData_Serial(realtype * v_data, N_Vector v); + void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, + N_Vector z); + void N_VConst_Serial(realtype c, N_Vector z); + void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z); + void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z); + void N_VScale_Serial(realtype c, N_Vector x, N_Vector z); + void N_VAbs_Serial(N_Vector x, N_Vector z); + void N_VInv_Serial(N_Vector x, N_Vector z); + void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z); + realtype N_VDotProd_Serial(N_Vector x, N_Vector y); + realtype N_VMaxNorm_Serial(N_Vector x); + realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w); + realtype N_VMin_Serial(N_Vector x); + realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w); + realtype N_VL1Norm_Serial(N_Vector x); + void N_VOneMask_Serial(N_Vector x); + void N_VCompare_Serial(realtype c, N_Vector x, N_Vector z); + booleantype N_VInvTest_Serial(N_Vector x, N_Vector z); + booleantype N_VConstrProdPos_Serial(N_Vector c, N_Vector x); + booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m); + realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom); + void N_VPrint_Serial(N_Vector x); + + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ +#endif /* _INC_NVECTOR_SERIAL_H */ diff --git a/rename_cpp/parse.cpp b/rename_cpp/parse.cpp new file mode 100644 index 00000000..ea261556 --- /dev/null +++ b/rename_cpp/parse.cpp @@ -0,0 +1,1048 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +parse_eq(char *eqn, struct elt_list **elt_ptr, int association) +/* ---------------------------------------------------------------------- */ +/* + * function to break equation up into component species + * returns species name, coefficient, and charge in global variable "rxn_list". + * Also returns pointer to elt_list structure array with list of elements + * and coefficients in species. + * rxn_list global variable, output with contiguous rxn_list structures, + * which is the reaction. Target species is first in + * list, coefficient is -1.0. + * + * Argurments: + * *eqn input, pointer to equation to be parsed. + * **elt_ptr output, pointer to contiguous elt_list structures, + * which is list of elements and coefficients in the + * target species. + * association input, TRUE or FALSE if reaction is an association reaction + */ +{ + int i; + LDBLE coef, l_z; + char c; + char *ptr; + char token[MAX_LENGTH]; + + paren_count = 0; +/* + * Remove white space + */ + squeeze_white(eqn); +/* + * Check for illegal characters + */ + for (i = 0; (c = eqn[i]) != '\0'; i++) + { + if (islegit(c) == FALSE) + { + error_string = sformatf( "Character is not allowed,\ + %c (octal: %o).", c, c); + error_msg(error_string, CONTINUE); + return (ERROR); + } + } + +/* + * Find coefficients, name, and charge for each species for lhs + */ + count_trxn = 0; + trxn.dz[0] = trxn.dz[1] = trxn.dz[2] = 0.0; + ptr = eqn; + c = ptr[0]; + for (;;) + { + if (c == '=') + break; + if (c == '\0') + { + error_string = sformatf( "Equation has no equal sign.\n\t%s", eqn); + error_msg(error_string, CONTINUE); + return (ERROR); + } + if (get_species(&ptr) == ERROR) + { + return (ERROR); + } + c = ptr[0]; + if (association == FALSE) + { + trxn.token[count_trxn].coef *= -1.0; + } + count_trxn++; + } +/* + * Get coefficient, name, and charge of species for dissociation reaction + */ + ptr++; + if (association == TRUE) + { + if (get_species(&ptr) == ERROR) + { + return (ERROR); + } + trxn.token[count_trxn].coef *= -1.0; + /* Swap species into first structure position */ + const char * char_ptr = trxn.token[0].name; + coef = trxn.token[0].coef; + l_z = trxn.token[0].z; + trxn.token[0].name = trxn.token[count_trxn].name; + trxn.token[0].coef = trxn.token[count_trxn].coef; + trxn.token[0].z = trxn.token[count_trxn].z; + trxn.token[count_trxn].name = char_ptr; + trxn.token[count_trxn].coef = coef; + trxn.token[count_trxn].z = l_z; + count_trxn++; + } +/* + * Get reaction species from rhs of equation + */ + c = ptr[0]; + for (;;) + { + if (c == '\0') + break; + if (get_species(&ptr) == ERROR) + { + return (ERROR); + } + c = ptr[0]; + if (association == TRUE) + { + trxn.token[count_trxn].coef *= -1.0; + } + count_trxn++; + } +/* + * Sort list of reaction species + */ + trxn_sort(); +/* + * Get elements in species or mineral formula + */ + count_elts = 0; + strcpy(token, trxn.token[0].name); + replace("(s)", "", token); + replace("(S)", "", token); + replace("(g)", "", token); + replace("(G)", "", token); + char *char_ptr = token; + + if (get_elts_in_species(&char_ptr, trxn.token[0].coef) == ERROR) + { + return (ERROR); + } +/* + * Sort elements in reaction and combine + */ + qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), + elt_list_compare); + if (elt_list_combine() == ERROR) + return (ERROR); +/* + * Malloc space and store element data for return + */ + *elt_ptr = + (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * + sizeof(struct elt_list)); + if (*elt_ptr == NULL) + malloc_error(); + for (i = 0; i < count_elts; i++) + { + (*elt_ptr)[i].elt = elt_list[i].elt; + (*elt_ptr)[i].coef = -elt_list[i].coef; + } + (*elt_ptr)[count_elts].elt = NULL; +/* + * Debugging print of parsed equation + trxn_print(); + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_eqn(int association) +/* ---------------------------------------------------------------------- */ +/* + * Check that equation is balanced reaction. Uses array "trxn.token" and + * assumes "count_trxn" is set to number of species in reaction. + * Charge and elements are checked. + * + * Arguments: + * + * association input, TRUE or FALSE if reaction is an association reaction. + */ +{ + int i; + int oops = 0; + LDBLE sumcharge; + + paren_count = 0; + count_elts = 0; +/* + * Check that coefficient of first species is -1.0 + */ + if (equal(trxn.token[0].coef, -1.0, TOL) == FALSE) + { + if (association == TRUE) + { + error_string = sformatf( + "Coefficient of first species on rhs is not equal to 1.0."); + error_msg(error_string, CONTINUE); + } + else + { + error_string = sformatf( + "Coefficient of mineral (first on lhs) is not equal to 1.0."); + error_msg(error_string, CONTINUE); + } + return (ERROR); + } +/* + * Go through all species in the reaction; sum the charge and store elements + */ + sumcharge = 0.0; + for (i = 0; i < count_trxn; i++) + { + sumcharge += (trxn.token[i].coef) * (trxn.token[i].z); + char * temp_name = string_duplicate(trxn.token[i].name); + char *t_ptr = temp_name; + if (get_elts_in_species(&t_ptr, trxn.token[i].coef) == ERROR) + { + free_check_null(temp_name); + return (ERROR); + } + free_check_null(temp_name); + } +/* + * Sort elements in reaction and combine + */ + qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), + elt_list_compare); + if (elt_list_combine() == ERROR) + return (ERROR); +/* + * Check charge + */ + if (equal(sumcharge, 0.0, TOL) == FALSE) + { + error_string = sformatf( "Equation is not charge balanced."); + error_msg(error_string, CONTINUE); + oops++; + } +/* + * Check mass balance + */ + for (i = 0; i < count_elts; i++) + { + if ((equal(elt_list[i].coef, 0.0, TOL) == FALSE) && + strncmp((elt_list[i].elt)->name, "e", MAX_LENGTH) != 0) + { + error_string = sformatf( + "Equation does not balance for element, %s.", + (elt_list[i].elt)->name); + error_msg(error_string, CONTINUE); + oops++; + } + } + if (oops == 0) + { + return (OK); + } + else + { + return (ERROR); + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_charge(char *charge, LDBLE * l_z) +/* ---------------------------------------------------------------------- */ +/* + * Function takes character string and calculates the charge on + * the species. Charge can be in two forms: (1) string of "+" or "-" + * or (2) + or - followed by an integer. Charge is reduced to form (2) + * and stored in the pointer location *charge. + * + * Arguments: + * *charge input, string containing charge + * output, string containing charge of the form + or - + * followed by an integer, if integer greater than 1. + * *z output, value of charge. + * + * Returns: + * ERROR, + * OK. + */ +{ + int i; + char *ptr; + char c, c1; +/* + * Charge is zero + */ + if ((c = charge[0]) == '\0') + { + *l_z = 0.0; + return (OK); + } +/* + * Error check for + or - at start of string + */ + if (c != '+' && c != '-') + { + error_string = sformatf( + "Character string for charge does not start with + or -,\t%s.", + charge); + error_msg(error_string, CONTINUE); + return (ERROR); + } +/* + * Count string of +'s or -'s + */ + i = 0; + while (c == (c1 = charge[i++])); + i--; + if (c1 == '\0') + { + if (c == '-') + i = -i; + } + else + { +/* + * + or - followed by a number + */ + errno = 0; + i = strtol(charge, &ptr, 0); +/* + * Truncate fractional part of charge if all zeros + */ + if (*ptr != '\0') + { + if (*ptr == '.') + { + while (*(++ptr) != '\0') + { + if (*ptr != '0') + { + *l_z = strtod(charge, &ptr); + return (OK); + } + } +/* + * Non-numeric characters + */ + } + else + { + error_string = sformatf( + "Error in character string for charge, %s.", charge); + error_msg(error_string, CONTINUE); + return (ERROR); + } + } + } +/* + * Charge is zero, must have had +0 or -0 in eqn + */ + if (i == 0) + { + charge[0] = '\0'; + } +/* + * Charge is +1 or -1, single + or - + */ + if (abs(i) == 1) + { + charge[0] = c; + charge[1] = '\0'; + } +/* + * Abs(z)>1, set charge to + or - plus integer + */ + if (abs(i) > 1) + { + if (sprintf(charge, "%-+d", i) == EOF) + { + error_string = sformatf( + "Error converting charge to character string, %s.", + charge); + error_msg(error_string, CONTINUE); + return (ERROR); + } + } + *l_z = i; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_coef(LDBLE * coef, char **eqnaddr) +/* ---------------------------------------------------------------------- */ +/* + * Function reads through eqn and determines the coefficient of the next + * species. + * + * Arguments: + * *coef output, coefficient of next species. + * + * **eqnaddr input, pointer to a position in eqn to start parsing + * output, pointer to next position after coefficient + * + * Returns: + * ERROR, + * OK. + */ +{ + int i; + char c, c1; + char *ptr, *ptr1, *rest; + char token[MAX_LENGTH];; + + rest = *eqnaddr; + ptr = *eqnaddr; /* address of a position in eqn */ + c = *ptr; /* character in eqn */ + *coef = 0.0; +/* + * No leading sign or number + */ + if (isalpha((int) c) || + (c == '(') || (c == ')') || (c == '[') || (c == ']')) + { + *coef = 1.0; + return (OK); + } +/* + * Leading +, no digits + */ + c1 = *(ptr + 1); + if (c == '+' && + (isalpha((int) c1) || + (c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']'))) + { + *eqnaddr = ++ptr; + *coef = 1.0; + return (OK); + } +/* + * Leading -, no digits + */ + if (c == '-' && + (isalpha((int) c1) || + (c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']'))) + { + *eqnaddr = ++ptr; + *coef = -1.0; + return (OK); + } + i = 0; +/* + * Has number coefficient + */ + if (isdigit((int) c) || c == '+' || c == '-' || c == '.') + { + while (isdigit((int) c) || c == '+' || c == '-' || c == '.') + { + token[i++] = c; + if (i >= MAX_LENGTH) + { + error_string = sformatf( + "Coefficient has more than MAX_LENGTH characters."); + error_msg(error_string, CONTINUE); + return (ERROR); + } + c = *(++ptr); + } + token[i] = '\0'; + *eqnaddr = ptr; + errno = 0; + *coef = strtod(token, &ptr1); + if ((errno == ERANGE) || (*ptr1 != '\0')) + { + error_string = sformatf( + "Error converting coefficient in get_coef, %s.", token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + return (OK); + } +/* + * None of the above, unknown construct + */ + error_string = sformatf( + "Illegal equation construct detected in get_coef.\n\t%s.", rest); + error_msg(error_string, CONTINUE); + return (ERROR); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_elt(char **t_ptr, char *element, int *i) +/* ---------------------------------------------------------------------- */ +/* + * Function reads an element name out of the equation string. + * An element name is composed of a capital letter followed by any number + * of lower case characters. + * + * Arguments: + * **t_ptr input, points to position in the equation to begin + * output, points to next character of equation after + * element name. + * *element input pointer to place to return element character string + */ +{ + char c; + + c = *(*t_ptr)++; + if (c == '\0') + { + error_string = sformatf( + "Empty string in get_elt. Expected an element name."); + error_msg(error_string, CONTINUE); + return (ERROR); + } +/* + * Load name into char array element + */ + element[0] = c; + *i = 1; + if (c == '[') + { + while ((c = (**t_ptr)) != ']') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + if ((c = (**t_ptr)) == ']') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + break; + } + else if (**t_ptr == '\0') + { + error_msg("No ending bracket (]) for element name", CONTINUE); + input_error++; + break; + } + } + while (islower((int) (c = (**t_ptr))) || c == '_') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + } + else + { + while (islower((int) (c = (**t_ptr))) || c == '_') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + } + element[*i] = '\0'; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_elts_in_species(char **t_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, count, l; + char c, c1; + LDBLE d; + char element[MAX_LENGTH]; + + while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) + { + /* close parenthesis */ + if (c == ')') + { + paren_count--; + if (paren_count < 0) + { + error_string = sformatf( "Too many right parentheses."); + error_msg(error_string, CONTINUE); + return (ERROR); + } + (*t_ptr)++; + return (OK); + } + c1 = *((*t_ptr) + 1); + /* beginning of element name */ + if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) + { +/* + * Get new element and subscript + */ + if (get_elt(t_ptr, element, &l) == ERROR) + { + return (ERROR); + } + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_store(element); + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + elt_list[count_elts].coef = d * coef; + count_elts++; +/* + * Expand working space for elements if necessary + */ + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + continue; + } +/* + * Open parentheses + */ + if (c == '(') + { + count = count_elts; + if (c1 == ')') + { + error_string = sformatf( "Empty parentheses."); + warning_msg(error_string); + } + paren_count++; + (*t_ptr)++; + if (get_elts_in_species(t_ptr, coef) == ERROR) + { + return (ERROR); + } + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + for (i = count; i < count_elts; i++) + { + elt_list[i].coef *= d; + } + continue; + } +/* + * Colon + */ + if (c == ':') + { + count = count_elts; + (*t_ptr)++; + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + if (get_elts_in_species(t_ptr, coef) == ERROR) + { + return (ERROR); + } + for (i = count; i < count_elts; i++) + { + elt_list[i].coef *= d; + } + continue; + } +/* + * Not beginning of element and not opening paren + */ + error_string = sformatf( + "Parsing error in get_elts_in_species, unexpected character, %c.", + c); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + if (paren_count != 0) + { + error_string = sformatf( "Unbalanced parentheses."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +get_secondary(char **t_ptr, char *element, int *i) +/* ---------------------------------------------------------------------- */ +/* + * Function reads an element name out of the equation string. + * An element name is composed of a capital letter followed by any number + * of lower case characters. + * + * Arguments: + * **t_ptr input, points to position in the equation to begin + * output, points to next character of equation after + * element name. + * *element input pointer to place to return element character string + */ +{ + int j; + char c; + char *ptr; + + c = *(*t_ptr)++; + if (c == '\0') + { + error_string = sformatf( + "Empty string in get_elt. Expected an element name."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Load name into char array element + */ + element[0] = c; + *i = 1; + if (c == '[') + { + while ((c = (**t_ptr)) != ']') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + if ((c = (**t_ptr)) == ']') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + c = (**t_ptr); + break; + } + else if ((c = (**t_ptr)) == '\0') + { + error_msg("Did not find ending bracket (])", CONTINUE); + input_error++; + return (ERROR); + } + } + while (islower((int) (c = (**t_ptr))) || c == '_') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + } + else + { + while (islower((int) (c = (**t_ptr))) || c == '_') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + } +/* + * Check if secondary master species element + */ + j = *i; + ptr = *t_ptr; + if (c == '(') + { + /* copy parenthesis */ + element[*i] = c; + (*i)++; + (*t_ptr)++; + /* copy number */ + for (;;) + { + c = **t_ptr; + if (isdigit((int) c) || c == '-' || c == '.') + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + else if (c == '+') + { + (*t_ptr)++; + } + else + { + break; + } + } + /* go back to before parenthesis */ + if (c != ')') + { + *i = j; + *t_ptr = ptr; + /* put in closing parenthesis */ + } + else + { + element[*i] = c; + (*i)++; + (*t_ptr)++; + } + } + element[*i] = '\0'; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_secondary_in_species(char **t_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, count, l; + char c, c1; + LDBLE d; + char element[MAX_LENGTH]; + + while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0')) + { + /* close parenthesis */ + if (c == ')') + { + paren_count--; + if (paren_count < 0) + { + error_string = sformatf( "Too many right parentheses."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + (*t_ptr)++; + return (OK); + } + c1 = *((*t_ptr) + 1); + /* beginning of element name */ + if (isupper((int) c) || c == '[' || (c == 'e' && c1 == '-')) + { +/* + * Get new element and subscript + */ + if (get_secondary(t_ptr, element, &l) == ERROR) + { + return (ERROR); + } + elt_list[count_elts].elt = element_store(element); + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + elt_list[count_elts].coef = d * coef; + count_elts++; +/* + * Expand working space for elements if necessary + */ + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + continue; + } +/* + * Open parentheses + */ + if (c == '(') + { + count = count_elts; + if (c1 == ')') + { + error_string = sformatf( "Empty parentheses."); + warning_msg(error_string); + } + paren_count++; + (*t_ptr)++; + if (get_secondary_in_species(t_ptr, coef) == ERROR) + { + return (ERROR); + } + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + for (i = count; i < count_elts; i++) + { + elt_list[i].coef *= d; + } + continue; + } +/* + * Colon + */ + if (c == ':') + { + count = count_elts; + (*t_ptr)++; + if (get_num(t_ptr, &d) == ERROR) + { + return (ERROR); + } + if (get_secondary_in_species(t_ptr, coef) == ERROR) + { + return (ERROR); + } + for (i = count; i < count_elts; i++) + { + elt_list[i].coef *= d; + } + continue; + } +/* + * Not beginning of element and not opening paren + */ + error_string = sformatf( + "Parsing error in get_secondary_in_species, unexpected character, %c.", + c); + error_msg(error_string, CONTINUE); + return (ERROR); + } + if (paren_count != 0) + { + error_string = sformatf( "Unbalanced parentheses."); + error_msg(error_string, CONTINUE); + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_num(char **t_ptr, LDBLE * num) +/* ---------------------------------------------------------------------- */ +/* + * Function reads through a string looking for leading numeric field + * if no numeric field is found, the number is set to 1.0. + * + * Arguments: + * + * **t_ptr input, points to a position in a character string from which + * a number is to be extracted. + * output, points to next position to be parsed. + * *num address where the number is to be stored. + * + * Returns: + * ERROR, + * OK. + */ +{ + int i, decimal; + char c; + char *ptr1; + char token[MAX_LENGTH]; + + *num = 1.0; + i = 0; + c = **t_ptr; + decimal = 0; + if (isdigit((int) c) || (c == '.')) + { + while (isdigit((int) c) || (c == '.')) + { + if (c == '.') + decimal++; + if (decimal > 1) + break; + token[i++] = c; + /* check number length */ + if (i >= MAX_LENGTH) + { + error_string = sformatf( + "Number was greater than MAX_LENGTH characters."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + c = *(++(*t_ptr)); + } + token[i] = '\0'; + errno = 0; + *num = strtod(token, &ptr1); + if (errno == ERANGE) + { + error_string = sformatf( "Converting number in get_num, %s.", token); + input_error++; + error_msg(error_string, CONTINUE); + return (ERROR); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_species(char **ptr) +/* ---------------------------------------------------------------------- */ +{ +/* Function reads next species out of the equation, including optional + * preceding coefficient and optional trailing charge. Data are + * store in trxn.token[count]. + * + * Arguments: + * **ptr input, points to the position in the equation to pick up the species. + * output, points to the next character after the species charge. + * + */ + char string[MAX_LENGTH]; + int l; + + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, + sizeof(struct rxn_token_temp)); + } + /* coefficient */ + if (get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR) + { + return (ERROR); + } + /* name and charge */ + if (get_token(ptr, string, &trxn.token[count_trxn].z, &l) == ERROR) + { + return (ERROR); + } + trxn.token[count_trxn].name = string_hsave(string); + /* + trxn.token[count_trxn].z = 0; + trxn.token[count_trxn].s = NULL; + trxn.token[count_trxn].unknown = NULL; + */ + return (OK); +} diff --git a/rename_cpp/phqalloc.cpp b/rename_cpp/phqalloc.cpp new file mode 100644 index 00000000..3746b942 --- /dev/null +++ b/rename_cpp/phqalloc.cpp @@ -0,0 +1,292 @@ +#define INCLUDE_PHRQALLOC_H +#include "Phreeqc.h" +#include +#include +#include + +#if defined(PHREEQCI_GUI) +#define _CRTDBG_MAP_ALLOC +#include +#endif +#if defined(USE_PHRQ_ALLOC) +/* ---------------------------------------------------------------------- */ +#if !defined(NDEBUG) +void * Phreeqc:: +PHRQ_malloc(size_t size, const char *szFileName, int nLine) +#else +void *Phreeqc:: +PHRQ_malloc(size_t size) +#endif +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader *) malloc(sizeof(PHRQMemHeader) + size); + + if (p == NULL) + return NULL; + + memset(p, 0, sizeof(PHRQMemHeader) + size); + p->pNext = NULL; + + if ((p->pPrev = s_pTail) != NULL) + { + s_pTail->pNext = p; + } + + p->size = sizeof(PHRQMemHeader) + size; +#if !defined(NDEBUG) + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) + strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + s_pTail = p; + p++; + return ((void *) (p)); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +PHRQ_free(void *ptr) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + if (ptr == NULL) + return; + + p = (PHRQMemHeader *) ptr - 1; + + if (p->pNext != NULL) + { + p->pNext->pPrev = p->pPrev; + } + else + { + /* Handle special case when (p == s_pTail) */ + assert(s_pTail != NULL); + assert(p == s_pTail); + s_pTail = p->pPrev; + } + + if (p->pPrev) + { + p->pPrev->pNext = p->pNext; + } + +#if !defined(NDEBUG) + free(p->szFileName); +#endif + + free(p); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +PHRQ_free_all(void) +/* ---------------------------------------------------------------------- */ +{ + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + std::ostringstream ostrm; + + if (s_pTail == NULL) + { +#if !defined(NDEBUG) + output_msg("No memory leaks\n"); +#endif + return; + } + while (s_pTail->pPrev != NULL) + { + s_pTail = s_pTail->pPrev; +#if !defined(NDEBUG) + ostrm.clear(); + ostrm << s_pTail->pNext->szFileName << "(" << s_pTail->pNext->nLine; + ostrm << ") " << (void *) (s_pTail->pNext + 1) << ": freed in PHRQ_free_all\n"; + output_msg(ostrm.str().c_str()); + //output_msg(sformatf("%s(%d) %p: freed in PHRQ_free_all\n", + // s_pTail->pNext->szFileName, s_pTail->pNext->nLine, + // (void *) (s_pTail->pNext + 1))); + free(s_pTail->pNext->szFileName); +#endif + free(s_pTail->pNext); + } + +#if !defined(NDEBUG) + ostrm.clear(); + ostrm << s_pTail->szFileName << "(" << s_pTail->nLine; + ostrm << ") " << (void *) (s_pTail + 1) << ": freed in PHRQ_free_all\n"; + output_msg(ostrm.str().c_str()); + //output_msg(sformatf( "%s(%d) %p: freed in PHRQ_free_all\n", + // s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail + 1))); + free(s_pTail->szFileName); +#endif + free(s_pTail); + s_pTail = NULL; +} + +/* ---------------------------------------------------------------------- */ +void * Phreeqc:: +PHRQ_calloc(size_t num, size_t size +#if !defined(NDEBUG) + , const char *szFileName, int nLine +#endif + ) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader *) malloc(sizeof(PHRQMemHeader) + size * num); + + if (p == NULL) + return NULL; + + p->pNext = NULL; + + if ((p->pPrev = s_pTail) != NULL) + { + s_pTail->pNext = p; + } + + p->size = sizeof(PHRQMemHeader) + size * num; + +#if !defined(NDEBUG) + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) + strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + s_pTail = p; + p++; + return memset(p, 0, size * num); +} + +/* ---------------------------------------------------------------------- */ +void * Phreeqc:: +PHRQ_realloc(void *ptr, size_t size +#if !defined(NDEBUG) + , const char *szFileName, int nLine +#endif + ) +/* ---------------------------------------------------------------------- */ +{ + PHRQMemHeader *p; + size_t new_size; + size_t old_size; + + if (ptr == NULL) + { + return PHRQ_malloc(size +#if !defined(NDEBUG) + , szFileName, nLine +#endif + ); + } + + assert((s_pTail == NULL) || (s_pTail->pNext == NULL)); + + p = (PHRQMemHeader *) ptr - 1; + + new_size = sizeof(PHRQMemHeader) + size; + + old_size = p->size; + p = (PHRQMemHeader *) realloc(p, new_size); + if (p != NULL) + { + p->size = new_size; + if (new_size > old_size) + { + memset((char *) p + old_size, 0, new_size - old_size); + } + } + + if (p == NULL) + return NULL; + + if (p->pPrev != NULL) + { + p->pPrev->pNext = p; + } + + if (p->pNext != NULL) + { + p->pNext->pPrev = p; + } + else + { + s_pTail = p; + } + +#if !defined(NDEBUG) + free(p->szFileName); + p->szFileName = (char *) malloc(strlen(szFileName) + 1); + if (p->szFileName) + strcpy(p->szFileName, szFileName); + p->nLine = nLine; +#endif + + p++; + return ((void *) (p)); +} +#else /* USE_PHRQ_ALLOC */ +/* ---------------------------------------------------------------------- */ +void *Phreeqc:: +#if !defined(NDEBUG) +PHRQ_malloc(size_t size, const char *szFileName, int nLine) +#else +PHRQ_malloc(size_t size) +#endif +/* ---------------------------------------------------------------------- */ +{ + return malloc(size); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +PHRQ_free(void *ptr) +/* ---------------------------------------------------------------------- */ +{ + free(ptr); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +PHRQ_free_all(void) +/* ---------------------------------------------------------------------- */ +{ +} + +/* ---------------------------------------------------------------------- */ +void * Phreeqc:: +#if !defined(NDEBUG) +PHRQ_calloc(size_t num, size_t size, const char *szFileName, int nLine) +#else +PHRQ_calloc(size_t num, size_t size) +#endif +/* ---------------------------------------------------------------------- */ +{ + return calloc(num, size); +} + +/* ---------------------------------------------------------------------- */ +void * Phreeqc:: +#if !defined(NDEBUG) +PHRQ_realloc(void *ptr, size_t size, const char *szFileName, int nLine) +#else +PHRQ_realloc(void *ptr, size_t size) +#endif +/* ---------------------------------------------------------------------- */ +{ + return realloc(ptr, size); +} +#endif /* USE_PHRQ_ALLOC */ diff --git a/rename_cpp/phqalloc.h b/rename_cpp/phqalloc.h new file mode 100644 index 00000000..12e0454d --- /dev/null +++ b/rename_cpp/phqalloc.h @@ -0,0 +1,47 @@ +#if !defined (INCLUDE_PHRQALLOC_H) +#define INCLUDE_PHRQALLOC_H + +#if defined (USE_PHRQ_ALLOC) + +#if !defined(NDEBUG) +void *PHRQ_malloc(size_t, const char *, int); +void *PHRQ_calloc(size_t, size_t, const char *, int); +void *PHRQ_realloc(void *, size_t, const char *, int); +#else +extern void *PHRQ_malloc(size_t); +extern void *PHRQ_calloc(size_t, size_t); +extern void *PHRQ_realloc(void *, size_t); +#endif + +extern void PHRQ_free(void *); +extern void PHRQ_free_all(void); + +#if !defined(NDEBUG) +#define PHRQ_malloc(s) PHRQ_malloc(s, __FILE__, __LINE__) +#define PHRQ_calloc(c, s) PHRQ_calloc(c, s, __FILE__, __LINE__) +#define PHRQ_realloc(p, s) PHRQ_realloc(p, s, __FILE__, __LINE__) +#endif + +#else /* defined (USE_PHRQ_ALLOC) */ + +#if !defined(NDEBUG) +void *PHRQ_malloc(size_t, const char *, int); +void *PHRQ_calloc(size_t, size_t, const char *, int); +void *PHRQ_realloc(void *, size_t, const char *, int); +#else +extern void *PHRQ_malloc(size_t); +extern void *PHRQ_calloc(size_t, size_t); +extern void *PHRQ_realloc(void *, size_t); +#endif +void PHRQ_free(void *); +void PHRQ_free_all(void); + +#if !defined(NDEBUG) +#define PHRQ_malloc(s) PHRQ_malloc(s, __FILE__, __LINE__) +#define PHRQ_calloc(c, s) PHRQ_calloc(c, s, __FILE__, __LINE__) +#define PHRQ_realloc(p, s) PHRQ_realloc(p, s, __FILE__, __LINE__) +#endif + +#endif /* defined (USE_PHRQ_ALLOC) */ + +#endif /* !defined (INCLUDE_PHRQALLOC_H) */ diff --git a/rename_cpp/phreeqc.rev b/rename_cpp/phreeqc.rev new file mode 100644 index 00000000..8dc8253f --- /dev/null +++ b/rename_cpp/phreeqc.rev @@ -0,0 +1,4579 @@ + +RCS file: RCS/README.TXT,v +Working file: README.TXT +head: 1.17 +branch: +locks: strict +access list: +symbolic names: +keyword substitution: kv +total revisions: 17 +============================================================================= + +RCS file: RCS/NOTICE.TXT,v +Working file: NOTICE.TXT +head: 1.1 +branch: +locks: strict +access list: +symbolic names: +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: RCS/RELEASE.TXT,v +Working file: RELEASE.TXT +head: 1.16 +branch: +locks: strict + dlpark: 1.16 +access list: +symbolic names: +keyword substitution: kv +total revisions: 16 +============================================================================= + +RCS file: src/RCS/Makefile,v +Working file: src/Makefile +head: 1.35 +branch: +locks: strict +access list: +symbolic names: + C_260: 1.33 + C_259: 1.33 + C_258: 1.33 + C_257: 1.31 + C_256: 1.31 + C_255: 1.31 + C_254: 1.30 + C_253: 1.26 + C_252: 1.25 + C_251: 1.25 + C_250: 1.25 + C_249: 1.24 + C_248: 1.24 + C_247: 1.24 + C_246: 1.24 + C_245: 1.24 + C_244: 1.24 + C_243: 1.24 + C_242: 1.23 + C_241: 1.22 + C_240: 1.22 + C_239: 1.22 + C_238: 1.22 + C_237: 1.22 + C_236: 1.22 + C_235: 1.22 + C_234: 1.22 + C_233: 1.22 + C_232: 1.22 + C_231: 1.22 + C_230: 1.22 + C_229: 1.22 + C_227: 1.22 + C_226: 1.22 + C_225: 1.22 + C_224: 1.22 + C_222: 1.21 + C_221: 1.21 + C_220: 1.21 + C_219: 1.21 + C_218: 1.21 + RC1: 1.20 + C_216: 1.20 + C_215: 1.20 + C_214: 1.20 + C_213: 1.20 + C_212: 1.20 + C_206: 1.18 + C_205_3: 1.15 + C_205_2: 1.15 + C_205_1: 1.15 + C_205: 1.15 + C_204_2: 1.14 + C_204_1: 1.14 + C_204: 1.14 + C_202: 1.10 + C_201: 1.5 + C_200: 1.5 +keyword substitution: kv +total revisions: 35 +============================================================================= + +RCS file: src/RCS/advection.c,v +Working file: src/advection.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.5 + C_246: 2.5 + C_245: 2.5 + C_244: 2.5 + C_243: 2.5 + C_242: 2.4 + C_241: 2.4 + C_240: 2.4 + C_239: 2.4 + C_238: 2.3 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/basic.c,v +Working file: src/basic.c +head: 2.44 +branch: +locks: strict + dlpark: 2.44 +access list: +symbolic names: + C_260: 2.44 + C_259: 2.44 + C_258: 2.44 + C_257: 2.44 + C_256: 2.43 + C_255: 2.43 + C_254: 2.43 + C_253: 2.42 + C_252: 2.42 + C_251: 2.42 + C_250: 2.42 + C_249: 2.41 + C_248: 2.41 + C_247: 2.41 + C_246: 2.41 + C_245: 2.41 + C_244: 2.41 + C_243: 2.41 + C_242: 2.39 + C_241: 2.39 + C_240: 2.39 + C_239: 2.39 + C_238: 2.38 + C_237: 2.37 + C_236: 2.37 + C_235: 2.37 + C_234: 2.37 + C_233: 2.36 + C_232: 2.34 + C_231: 2.33 + C_230: 2.30 + C_229: 2.30 + C_227: 2.30 + C_226: 2.30 + C_225: 2.30 + C_224: 2.30 + C_222: 2.30 + C_221: 2.20 + C_220: 2.20 + C_219: 2.19 + C_218: 2.19 + RC1: 2.19 + C_216: 2.19 + C_215: 2.18 + C_214: 2.17 + C_213: 2.17 + C_212: 2.16 + C_206: 2.16 + C_205_3: 2.14 + C_205_2: 2.14 + C_205_1: 2.13 + C_205: 2.11 + C_204_2: 2.11 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.10 + C_202_1: 2.10 + C_202: 2.6 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 45 +============================================================================= + +RCS file: src/RCS/basicsubs.c,v +Working file: src/basicsubs.c +head: 2.18 +branch: +locks: strict + dlpark: 2.18 +access list: +symbolic names: + C_260: 2.18 + C_259: 2.18 + C_258: 2.18 + C_257: 2.18 + C_256: 2.17 + C_255: 2.17 + C_254: 2.17 + C_253: 2.16 + C_252: 2.16 + C_251: 2.15 + C_250: 2.15 + C_249: 2.14 + C_248: 2.14 + C_247: 2.14 + C_246: 2.14 + C_245: 2.14 + C_244: 2.14 + C_243: 2.14 + C_242: 2.13 + C_241: 2.13 + C_240: 2.13 + C_239: 2.13 + C_238: 2.12 + C_237: 2.12 + C_236: 2.12 + C_235: 2.12 + C_234: 2.12 + C_233: 2.11 + C_232: 2.9 + C_231: 2.9 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.6 + C_222: 2.6 + C_221: 2.6 + C_220: 2.6 + C_219: 2.6 + C_218: 2.6 + RC1: 2.6 + C_216: 2.6 + C_215: 2.6 + C_214: 2.5 + C_213: 2.4 + C_212: 2.3 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.1 + C_205_1: 2.1 +keyword substitution: kv +total revisions: 18 +============================================================================= + +RCS file: src/RCS/cl1.c,v +Working file: src/cl1.c +head: 2.7 +branch: +locks: strict + dlpark: 2.7 +access list: +symbolic names: + C_260: 2.7 + C_259: 2.7 + C_258: 2.7 + C_257: 2.6 + C_256: 2.5 + C_255: 2.5 + C_254: 2.5 + C_253: 2.5 + C_252: 2.5 + C_251: 2.5 + C_250: 2.5 + C_249: 2.4 + C_248: 2.4 + C_247: 2.4 + C_246: 2.4 + C_245: 2.4 + C_244: 2.4 + C_243: 2.4 + C_242: 2.3 + C_241: 2.3 + C_240: 2.3 + C_239: 2.2 + C_238: 2.1 + C_237: 2.1 + C_236: 2.1 + C_235: 2.1 + C_234: 2.1 + C_233: 2.1 + C_232: 2.1 + C_231: 2.1 + C_230: 2.1 + C_229: 2.1 + C_227: 2.1 + C_226: 2.1 + C_225: 2.1 + C_224: 2.1 + C_222: 2.1 + C_221: 2.1 + C_220: 2.1 + C_219: 2.1 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: src/RCS/cvdense.c,v +Working file: src/cvdense.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 + C_225: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/cvode.c,v +Working file: src/cvode.c +head: 1.10 +branch: +locks: strict +access list: +symbolic names: + C_260: 1.10 + C_259: 1.9 + C_258: 1.9 + C_257: 1.9 + C_256: 1.8 + C_255: 1.8 + C_254: 1.8 + C_253: 1.8 + C_252: 1.8 + C_251: 1.8 + C_250: 1.7 + C_249: 1.6 + C_248: 1.6 + C_247: 1.6 + C_246: 1.6 + C_245: 1.6 + C_244: 1.6 + C_243: 1.6 + C_242: 1.4 + C_241: 1.4 + C_240: 1.4 + C_239: 1.4 + C_238: 1.2 + C_237: 1.2 + C_236: 1.2 + C_235: 1.2 + C_234: 1.2 + C_233: 1.2 + C_232: 1.2 + C_231: 1.2 + C_230: 1.2 + C_229: 1.2 + C_227: 1.2 + C_226: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: src/RCS/dense.c,v +Working file: src/dense.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/input.c,v +Working file: src/input.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.1 + C_254: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/integrate.c,v +Working file: src/integrate.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.4 + C_237: 2.4 + C_236: 2.4 + C_235: 2.4 + C_234: 2.4 + C_233: 2.4 + C_232: 2.4 + C_231: 2.4 + C_230: 2.4 + C_229: 2.4 + C_227: 2.4 + C_226: 2.4 + C_225: 2.4 + C_224: 2.3 + C_222: 2.3 + C_221: 2.3 + C_220: 2.3 + C_219: 2.3 + C_218: 2.3 + RC1: 2.3 + C_216: 2.3 + C_215: 2.3 + C_214: 2.3 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/inverse.c,v +Working file: src/inverse.c +head: 2.10 +branch: +locks: strict + dlpark: 2.10 +access list: +symbolic names: + C_260: 2.10 + C_259: 2.10 + C_258: 2.10 + C_257: 2.10 + C_256: 2.9 + C_255: 2.9 + C_254: 2.9 + C_253: 2.8 + C_252: 2.8 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.4 + C_241: 2.4 + C_240: 2.4 + C_239: 2.4 + C_238: 2.3 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.1 + C_206: 2.1 + C_205_3: 2.1 + C_205_2: 2.1 + C_205_1: 2.1 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: src/RCS/isotopes.c,v +Working file: src/isotopes.c +head: 2.12 +branch: +locks: strict + dlpark: 2.12 +access list: +symbolic names: + C_260: 2.12 + C_259: 2.12 + C_258: 2.12 + C_257: 2.12 + C_256: 2.11 + C_255: 2.11 + C_254: 2.11 + C_253: 2.11 + C_252: 2.11 + C_251: 2.11 + C_250: 2.10 + C_249: 2.9 + C_248: 2.9 + C_247: 2.9 + C_246: 2.9 + C_245: 2.9 + C_244: 2.9 + C_243: 2.9 + C_242: 2.8 + C_241: 2.8 + C_240: 2.8 + C_239: 2.8 + C_238: 2.7 + C_237: 2.7 + C_236: 2.7 + C_235: 2.7 + C_234: 2.7 + C_233: 2.7 + C_232: 2.7 + C_231: 2.7 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.7 + C_222: 2.7 + C_221: 2.7 + C_220: 2.7 + C_219: 2.7 + C_218: 2.7 + RC1: 2.7 + C_216: 2.7 + C_215: 2.7 + C_214: 2.7 + C_213: 2.7 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.2 + C_205_2: 2.1 + C_205_1: 2.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: src/RCS/kinetics.c,v +Working file: src/kinetics.c +head: 2.36 +branch: +locks: strict + dlpark: 2.36 +access list: +symbolic names: + C_260: 2.36 + C_259: 2.36 + C_258: 2.36 + C_257: 2.33 + C_256: 2.32 + C_255: 2.31 + C_254: 2.31 + C_253: 2.30 + C_252: 2.30 + C_251: 2.29 + C_250: 2.29 + C_249: 2.28 + C_248: 2.28 + C_247: 2.26 + C_246: 2.26 + C_245: 2.26 + C_244: 2.26 + C_243: 2.26 + C_242: 2.24 + C_241: 2.24 + C_240: 2.24 + C_239: 2.23 + C_238: 2.22 + C_237: 2.22 + C_236: 2.22 + C_235: 2.22 + C_234: 2.21 + C_233: 2.21 + C_232: 2.21 + C_231: 2.21 + C_230: 2.21 + C_229: 2.21 + C_227: 2.21 + C_226: 2.20 + C_225: 2.19 + C_224: 2.19 + C_222: 2.19 + C_221: 2.19 + C_220: 2.19 + C_219: 2.18 + C_218: 2.17 + RC1: 2.17 + C_216: 2.17 + C_215: 2.17 + C_214: 2.17 + C_213: 2.17 + C_212: 2.16 + C_206: 2.16 + C_205_3: 2.16 + C_205_2: 2.16 + C_205_1: 2.15 + C_205: 2.11 + C_204_2: 2.7 + C_204_1: 2.7 + C_204: 2.7 + C_202_2: 2.6 + C_202_1: 2.6 + C_202: 2.4 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 37 +============================================================================= + +RCS file: src/RCS/main.c,v +Working file: src/main.c +head: 2.35 +branch: +locks: strict +access list: +symbolic names: + C_260: 2.35 + C_259: 2.34 + C_258: 2.34 + C_257: 2.34 + C_256: 2.33 + C_255: 2.33 + C_254: 2.32 + C_253: 2.31 + C_252: 2.30 + C_251: 2.30 + C_250: 2.30 + C_249: 2.29 + C_248: 2.29 + C_247: 2.29 + C_246: 2.29 + C_245: 2.29 + C_244: 2.28 + C_243: 2.28 + C_242: 2.26 + C_241: 2.25 + C_240: 2.25 + C_239: 2.25 + C_238: 2.25 + C_237: 2.24 + C_236: 2.24 + C_235: 2.24 + C_234: 2.23 + C_233: 2.23 + C_232: 2.23 + C_231: 2.23 + C_230: 2.23 + C_229: 2.23 + C_227: 2.23 + C_226: 2.23 + C_225: 2.23 + C_224: 2.23 + C_222: 2.22 + C_221: 2.22 + C_220: 2.22 + C_219: 2.22 + C_218: 2.20 + RC1: 2.19 + C_216: 2.19 + C_215: 2.18 + C_214: 2.18 + C_213: 2.18 + C_212: 2.14 + C_206: 2.14 + C_205_3: 2.13 + C_205_2: 2.13 + C_205_1: 2.13 + C_205: 2.13 + C_204_2: 2.12 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.9 + C_202_1: 2.6 + C_202: 2.4 + C_201: 2.2 + C_200: 2.1 +keyword substitution: kv +total revisions: 36 +============================================================================= + +RCS file: src/RCS/mainsubs.c,v +Working file: src/mainsubs.c +head: 2.38 +branch: +locks: strict + dlpark: 2.38 +access list: +symbolic names: + C_260: 2.38 + C_259: 2.38 + C_258: 2.38 + C_257: 2.36 + C_256: 2.35 + C_255: 2.35 + C_254: 2.34 + C_253: 2.33 + C_252: 2.33 + C_251: 2.32 + C_250: 2.32 + C_249: 2.31 + C_248: 2.31 + C_247: 2.30 + C_246: 2.30 + C_245: 2.30 + C_244: 2.30 + C_243: 2.30 + C_242: 2.28 + C_241: 2.28 + C_240: 2.28 + C_239: 2.27 + C_238: 2.25 + C_237: 2.24 + C_236: 2.24 + C_235: 2.24 + C_234: 2.23 + C_233: 2.23 + C_232: 2.23 + C_231: 2.23 + C_230: 2.23 + C_229: 2.23 + C_227: 2.22 + C_226: 2.22 + C_225: 2.22 + C_224: 2.22 + C_222: 2.22 + C_221: 2.22 + C_220: 2.22 + C_219: 2.22 + C_218: 2.21 + RC1: 2.21 + C_216: 2.21 + C_215: 2.21 + C_214: 2.20 + C_213: 2.20 + C_212: 2.17 + C_206: 2.15 + C_205_3: 2.14 + C_205_2: 2.13 + C_205_1: 2.12 + C_205: 2.11 + C_204_2: 2.10 + C_204_1: 2.10 + C_204: 2.10 + C_202_2: 2.6 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 39 +============================================================================= + +RCS file: src/RCS/model.c,v +Working file: src/model.c +head: 2.27 +branch: +locks: strict + dlpark: 2.27 +access list: +symbolic names: + C_260: 2.27 + C_259: 2.27 + C_258: 2.27 + C_257: 2.26 + C_256: 2.25 + C_255: 2.25 + C_254: 2.25 + C_253: 2.24 + C_252: 2.24 + C_251: 2.24 + C_250: 2.24 + C_249: 2.23 + C_248: 2.23 + C_247: 2.22 + C_246: 2.22 + C_245: 2.22 + C_244: 2.22 + C_243: 2.22 + C_242: 2.20 + C_241: 2.19 + C_240: 2.19 + C_239: 2.19 + C_238: 2.17 + C_237: 2.17 + C_236: 2.17 + C_235: 2.17 + C_234: 2.17 + C_233: 2.16 + C_232: 2.15 + C_231: 2.15 + C_230: 2.14 + C_229: 2.14 + C_227: 2.14 + C_226: 2.14 + C_225: 2.14 + C_224: 2.14 + C_222: 2.14 + C_221: 2.14 + C_220: 2.14 + C_219: 2.14 + C_218: 2.14 + RC1: 2.13 + C_216: 2.13 + C_215: 2.13 + C_214: 2.12 + C_213: 2.12 + C_212: 2.11 + C_206: 2.11 + C_205_3: 2.11 + C_205_2: 2.11 + C_205_1: 2.10 + C_205: 2.8 + C_204_2: 2.6 + C_204_1: 2.6 + C_204: 2.6 + C_202_2: 2.5 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 28 +============================================================================= + +RCS file: src/RCS/nvector.c,v +Working file: src/nvector.c +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_260: 1.3 + C_259: 1.3 + C_258: 1.3 + C_257: 1.3 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/nvector_serial.c,v +Working file: src/nvector_serial.c +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_260: 1.5 + C_259: 1.5 + C_258: 1.5 + C_257: 1.5 + C_256: 1.4 + C_255: 1.4 + C_254: 1.4 + C_253: 1.4 + C_252: 1.4 + C_251: 1.4 + C_250: 1.4 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: src/RCS/output.c,v +Working file: src/output.c +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_260: 1.2 + C_259: 1.2 + C_258: 1.2 + C_257: 1.1 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: src/RCS/p2clib.c,v +Working file: src/p2clib.c +head: 2.6 +branch: +locks: strict + dlpark: 2.6 +access list: +symbolic names: + C_260: 2.6 + C_259: 2.6 + C_258: 2.6 + C_257: 2.6 + C_256: 2.5 + C_255: 2.5 + C_254: 2.5 + C_253: 2.5 + C_252: 2.5 + C_251: 2.5 + C_250: 2.5 + C_249: 2.5 + C_248: 2.5 + C_247: 2.5 + C_246: 2.5 + C_245: 2.5 + C_244: 2.5 + C_243: 2.5 + C_242: 2.3 + C_241: 2.3 + C_240: 2.3 + C_239: 2.3 + C_238: 2.3 + C_237: 2.3 + C_236: 2.3 + C_235: 2.3 + C_234: 2.3 + C_233: 2.3 + C_232: 2.3 + C_231: 2.3 + C_230: 2.3 + C_229: 2.3 + C_227: 2.3 + C_226: 2.3 + C_225: 2.3 + C_224: 2.3 + C_222: 2.3 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.1 + C_206: 2.1 + C_205_3: 2.1 + C_205_2: 2.1 + C_205_1: 2.1 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: src/RCS/parse.c,v +Working file: src/parse.c +head: 2.8 +branch: +locks: strict + dlpark: 2.8 +access list: +symbolic names: + C_260: 2.8 + C_259: 2.8 + C_258: 2.8 + C_257: 2.8 + C_256: 2.7 + C_255: 2.7 + C_254: 2.7 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.6 + C_248: 2.6 + C_247: 2.6 + C_246: 2.6 + C_245: 2.6 + C_244: 2.6 + C_243: 2.6 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.4 + C_237: 2.4 + C_236: 2.4 + C_235: 2.4 + C_234: 2.4 + C_233: 2.4 + C_232: 2.4 + C_231: 2.4 + C_230: 2.4 + C_229: 2.4 + C_227: 2.4 + C_226: 2.4 + C_225: 2.4 + C_224: 2.4 + C_222: 2.4 + C_221: 2.4 + C_220: 2.4 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.4 + C_212: 2.3 + C_206: 2.3 + C_205_3: 2.3 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: src/RCS/phqalloc.c,v +Working file: src/phqalloc.c +head: 2.9 +branch: +locks: strict + dlpark: 2.9 +access list: +symbolic names: + C_260: 2.9 + C_259: 2.9 + C_258: 2.9 + C_257: 2.9 + C_256: 2.8 + C_255: 2.8 + C_254: 2.8 + C_253: 2.7 + C_252: 2.7 + C_251: 2.7 + C_250: 2.7 + C_249: 2.7 + C_248: 2.7 + C_247: 2.7 + C_246: 2.7 + C_245: 2.7 + C_244: 2.7 + C_243: 2.7 + C_242: 2.5 + C_241: 2.5 + C_240: 2.5 + C_239: 2.5 + C_238: 2.5 + C_237: 2.5 + C_236: 2.5 + C_235: 2.5 + C_234: 2.5 + C_233: 2.5 + C_232: 2.5 + C_231: 2.5 + C_230: 2.5 + C_229: 2.5 + C_227: 2.5 + C_226: 2.5 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.5 + C_218: 2.5 + RC1: 2.5 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.4 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.2 + C_204_1: 2.2 + C_204: 2.2 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: src/RCS/phreeqc_files.c,v +Working file: src/phreeqc_files.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.3 + C_257: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/prep.c,v +Working file: src/prep.c +head: 2.15 +branch: +locks: strict + dlpark: 2.15 +access list: +symbolic names: + C_260: 2.15 + C_259: 2.15 + C_258: 2.15 + C_257: 2.15 + C_256: 2.14 + C_255: 2.14 + C_254: 2.14 + C_253: 2.14 + C_252: 2.14 + C_251: 2.14 + C_250: 2.14 + C_249: 2.13 + C_248: 2.13 + C_247: 2.13 + C_246: 2.13 + C_245: 2.13 + C_244: 2.13 + C_243: 2.13 + C_242: 2.11 + C_241: 2.11 + C_240: 2.11 + C_239: 2.11 + C_238: 2.10 + C_237: 2.9 + C_236: 2.9 + C_235: 2.9 + C_234: 2.9 + C_233: 2.9 + C_232: 2.8 + C_231: 2.8 + C_230: 2.8 + C_229: 2.8 + C_227: 2.7 + C_226: 2.7 + C_225: 2.7 + C_224: 2.6 + C_222: 2.6 + C_221: 2.6 + C_220: 2.6 + C_219: 2.5 + C_218: 2.5 + RC1: 2.5 + C_216: 2.5 + C_215: 2.5 + C_214: 2.5 + C_213: 2.5 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.4 + C_205_2: 2.4 + C_205_1: 2.3 + C_205: 2.3 + C_204_2: 2.3 + C_204_1: 2.3 + C_204: 2.3 + C_202_2: 2.3 + C_202_1: 2.3 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 16 +============================================================================= + +RCS file: src/RCS/print.c,v +Working file: src/print.c +head: 2.38 +branch: +locks: strict + dlpark: 2.38 +access list: +symbolic names: + C_260: 2.38 + C_259: 2.38 + C_258: 2.38 + C_257: 2.38 + C_256: 2.37 + C_255: 2.36 + C_254: 2.35 + C_253: 2.34 + C_252: 2.34 + C_251: 2.32 + C_250: 2.32 + C_249: 2.31 + C_248: 2.31 + C_247: 2.31 + C_246: 2.31 + C_245: 2.31 + C_244: 2.31 + C_243: 2.31 + C_242: 2.30 + C_241: 2.30 + C_240: 2.30 + C_239: 2.30 + C_238: 2.29 + C_237: 2.29 + C_236: 2.29 + C_235: 2.28 + C_234: 2.27 + C_233: 2.27 + C_232: 2.27 + C_231: 2.27 + C_230: 2.27 + C_229: 2.27 + C_227: 2.27 + C_226: 2.27 + C_225: 2.26 + C_224: 2.26 + C_222: 2.26 + C_221: 2.25 + C_220: 2.25 + C_219: 2.24 + C_218: 2.24 + RC1: 2.24 + C_216: 2.24 + C_215: 2.24 + C_214: 2.21 + C_213: 2.20 + C_212: 2.15 + C_206: 2.15 + C_205_3: 2.11 + C_205_2: 2.10 + C_205_1: 2.9 + C_205: 2.8 + C_204_2: 2.7 + C_204_1: 2.7 + C_204: 2.7 + C_202_2: 2.5 + C_202_1: 2.4 + C_202: 2.4 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 39 +============================================================================= + +RCS file: src/RCS/read.c,v +Working file: src/read.c +head: 2.43 +branch: +locks: strict + dlpark: 2.43 +access list: +symbolic names: + C_260: 2.43 + C_259: 2.43 + C_258: 2.43 + C_257: 2.43 + C_256: 2.42 + C_255: 2.41 + C_254: 2.41 + C_253: 2.39 + C_252: 2.39 + C_251: 2.39 + C_250: 2.39 + C_249: 2.38 + C_248: 2.38 + C_247: 2.38 + C_246: 2.38 + C_245: 2.38 + C_244: 2.38 + C_243: 2.38 + C_242: 2.36 + C_241: 2.36 + C_240: 2.36 + C_239: 2.36 + C_238: 2.35 + C_237: 2.33 + C_236: 2.33 + C_235: 2.32 + C_234: 2.31 + C_233: 2.31 + C_232: 2.31 + C_231: 2.31 + C_230: 2.31 + C_229: 2.31 + C_227: 2.30 + C_226: 2.29 + C_225: 2.29 + C_224: 2.29 + C_222: 2.29 + C_221: 2.29 + C_220: 2.29 + C_219: 2.29 + C_218: 2.29 + RC1: 2.29 + C_216: 2.29 + C_215: 2.28 + C_214: 2.27 + C_213: 2.27 + C_212: 2.23 + C_206: 2.21 + C_205_3: 2.20 + C_205_2: 2.19 + C_205_1: 2.18 + C_205: 2.17 + C_204_2: 2.12 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.8 + C_202_1: 2.6 + C_202: 2.2 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 44 +============================================================================= + +RCS file: src/RCS/readtr.c,v +Working file: src/readtr.c +head: 2.13 +branch: +locks: strict + dlpark: 2.13 +access list: +symbolic names: + C_260: 2.13 + C_259: 2.13 + C_258: 2.12 + C_257: 2.12 + C_256: 2.11 + C_255: 2.10 + C_254: 2.10 + C_253: 2.9 + C_252: 2.9 + C_251: 2.9 + C_250: 2.9 + C_249: 2.8 + C_248: 2.8 + C_247: 2.8 + C_246: 2.8 + C_245: 2.8 + C_244: 2.8 + C_243: 2.8 + C_242: 2.6 + C_241: 2.6 + C_240: 2.6 + C_239: 2.6 + C_238: 2.5 + C_237: 2.5 + C_236: 2.5 + C_235: 2.5 + C_234: 2.5 + C_233: 2.5 + C_232: 2.5 + C_231: 2.5 + C_230: 2.5 + C_229: 2.5 + C_227: 2.5 + C_226: 2.5 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.3 + C_214: 2.3 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.1 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.1 + C_202_1: 2.1 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/smalldense.c,v +Working file: src/smalldense.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/spread.c,v +Working file: src/spread.c +head: 2.17 +branch: +locks: strict + dlpark: 2.17 +access list: +symbolic names: + C_260: 2.17 + C_259: 2.17 + C_258: 2.16 + C_257: 2.16 + C_256: 2.15 + C_255: 2.15 + C_254: 2.15 + C_253: 2.15 + C_252: 2.15 + C_251: 2.15 + C_250: 2.15 + C_249: 2.14 + C_248: 2.14 + C_247: 2.14 + C_246: 2.14 + C_245: 2.14 + C_244: 2.14 + C_243: 2.14 + C_242: 2.13 + C_241: 2.13 + C_240: 2.13 + C_239: 2.13 + C_238: 2.12 + C_237: 2.12 + C_236: 2.12 + C_235: 2.12 + C_234: 2.12 + C_233: 2.12 + C_232: 2.12 + C_231: 2.12 + C_230: 2.11 + C_229: 2.11 + C_227: 2.11 + C_226: 2.11 + C_225: 2.11 + C_224: 2.11 + C_222: 2.11 + C_221: 2.11 + C_220: 2.11 + C_219: 2.11 + C_218: 2.11 + RC1: 2.11 + C_216: 2.11 + C_215: 2.11 + C_214: 2.11 + C_213: 2.11 + C_212: 2.10 + C_206: 2.10 + C_205_3: 2.10 + C_205_2: 2.10 + C_205_1: 2.9 + C_205: 2.8 + C_204_2: 2.8 + C_204_1: 2.7 + C_204: 2.6 + C_202_2: 2.3 + C_202_1: 2.2 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 18 +============================================================================= + +RCS file: src/RCS/step.c,v +Working file: src/step.c +head: 2.13 +branch: +locks: strict + dlpark: 2.13 +access list: +symbolic names: + C_260: 2.13 + C_259: 2.13 + C_258: 2.13 + C_257: 2.13 + C_256: 2.12 + C_255: 2.12 + C_254: 2.12 + C_253: 2.12 + C_252: 2.12 + C_251: 2.12 + C_250: 2.12 + C_249: 2.11 + C_248: 2.11 + C_247: 2.11 + C_246: 2.11 + C_245: 2.11 + C_244: 2.11 + C_243: 2.11 + C_242: 2.10 + C_241: 2.10 + C_240: 2.10 + C_239: 2.10 + C_238: 2.9 + C_237: 2.7 + C_236: 2.7 + C_235: 2.7 + C_234: 2.7 + C_233: 2.7 + C_232: 2.7 + C_231: 2.7 + C_230: 2.7 + C_229: 2.7 + C_227: 2.7 + C_226: 2.6 + C_225: 2.5 + C_224: 2.5 + C_222: 2.5 + C_221: 2.5 + C_220: 2.5 + C_219: 2.4 + C_218: 2.4 + RC1: 2.4 + C_216: 2.4 + C_215: 2.4 + C_214: 2.4 + C_213: 2.3 + C_212: 2.2 + C_206: 2.2 + C_205_3: 2.2 + C_205_2: 2.2 + C_205_1: 2.2 + C_205: 2.2 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/structures.c,v +Working file: src/structures.c +head: 2.35 +branch: +locks: strict + dlpark: 2.35 +access list: +symbolic names: + C_260: 2.35 + C_259: 2.35 + C_258: 2.34 + C_257: 2.33 + C_256: 2.32 + C_255: 2.32 + C_254: 2.31 + C_253: 2.29 + C_252: 2.29 + C_251: 2.29 + C_250: 2.29 + C_249: 2.28 + C_248: 2.28 + C_247: 2.28 + C_246: 2.28 + C_245: 2.28 + C_244: 2.28 + C_243: 2.28 + C_242: 2.26 + C_241: 2.25 + C_240: 2.25 + C_239: 2.24 + C_238: 2.23 + C_237: 2.22 + C_236: 2.22 + C_235: 2.22 + C_234: 2.21 + C_233: 2.21 + C_232: 2.20 + C_231: 2.20 + C_230: 2.20 + C_229: 2.20 + C_227: 2.19 + C_226: 2.19 + C_225: 2.19 + C_224: 2.19 + C_222: 2.19 + C_221: 2.19 + C_220: 2.19 + C_219: 2.19 + C_218: 2.18 + RC1: 2.18 + C_216: 2.18 + C_215: 2.18 + C_214: 2.17 + C_213: 2.17 + C_212: 2.15 + C_206: 2.14 + C_205_3: 2.13 + C_205_2: 2.13 + C_205_1: 2.12 + C_205: 2.11 + C_204_2: 2.10 + C_204_1: 2.10 + C_204: 2.10 + C_202_2: 2.6 + C_202_1: 2.4 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 36 +============================================================================= + +RCS file: src/RCS/sundialsmath.c,v +Working file: src/sundialsmath.c +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.3 + C_255: 1.3 + C_254: 1.3 + C_253: 1.3 + C_252: 1.3 + C_251: 1.3 + C_250: 1.3 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/tally.c,v +Working file: src/tally.c +head: 1.14 +branch: +locks: strict + dlpark: 1.14 +access list: +symbolic names: + C_260: 1.14 + C_259: 1.14 + C_258: 1.14 + C_257: 1.14 + C_256: 1.13 + C_255: 1.13 + C_254: 1.13 + C_253: 1.13 + C_252: 1.13 + C_251: 1.12 + C_250: 1.12 + C_249: 1.11 + C_248: 1.11 + C_247: 1.11 + C_246: 1.10 + C_245: 1.10 + C_244: 1.9 + C_243: 1.8 + C_242: 1.6 + C_241: 1.5 + C_240: 1.4 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: src/RCS/tidy.c,v +Working file: src/tidy.c +head: 2.30 +branch: +locks: strict +access list: +symbolic names: + C_260: 2.30 + C_259: 2.29 + C_258: 2.29 + C_257: 2.29 + C_256: 2.28 + C_255: 2.28 + C_254: 2.28 + C_253: 2.27 + C_252: 2.27 + C_251: 2.27 + C_250: 2.27 + C_249: 2.26 + C_248: 2.26 + C_247: 2.26 + C_246: 2.26 + C_245: 2.26 + C_244: 2.26 + C_243: 2.26 + C_242: 2.24 + C_241: 2.23 + C_240: 2.23 + C_239: 2.22 + C_238: 2.21 + C_237: 2.19 + C_236: 2.19 + C_235: 2.19 + C_234: 2.19 + C_233: 2.19 + C_232: 2.17 + C_231: 2.17 + C_230: 2.17 + C_229: 2.16 + C_227: 2.16 + C_226: 2.16 + C_225: 2.16 + C_224: 2.16 + C_222: 2.16 + C_221: 2.16 + C_220: 2.15 + C_219: 2.15 + C_218: 2.15 + RC1: 2.15 + C_216: 2.15 + C_215: 2.15 + C_214: 2.15 + C_213: 2.15 + C_212: 2.10 + C_206: 2.9 + C_205_3: 2.9 + C_205_2: 2.8 + C_205_1: 2.7 + C_205: 2.6 + C_204_2: 2.5 + C_204_1: 2.4 + C_204: 2.3 + C_202_2: 2.2 + C_202_1: 2.2 + C_202: 2.1 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 31 +============================================================================= + +RCS file: src/RCS/transport.c,v +Working file: src/transport.c +head: 2.14 +branch: +locks: strict + dlpark: 2.14 +access list: +symbolic names: + C_260: 2.14 + C_259: 2.14 + C_258: 2.14 + C_257: 2.14 + C_256: 2.13 + C_255: 2.13 + C_254: 2.13 + C_253: 2.13 + C_252: 2.13 + C_251: 2.13 + C_250: 2.13 + C_249: 2.12 + C_248: 2.12 + C_247: 2.12 + C_246: 2.12 + C_245: 2.12 + C_244: 2.12 + C_243: 2.12 + C_242: 2.10 + C_241: 2.10 + C_240: 2.10 + C_239: 2.10 + C_238: 2.9 + C_237: 2.8 + C_236: 2.8 + C_235: 2.8 + C_234: 2.8 + C_233: 2.8 + C_232: 2.8 + C_231: 2.8 + C_230: 2.8 + C_229: 2.8 + C_227: 2.8 + C_226: 2.8 + C_225: 2.8 + C_224: 2.8 + C_222: 2.8 + C_221: 2.8 + C_220: 2.7 + C_219: 2.7 + C_218: 2.7 + RC1: 2.6 + C_216: 2.5 + C_215: 2.5 + C_214: 2.5 + C_213: 2.5 + C_212: 2.4 + C_206: 2.4 + C_205_3: 2.4 + C_205_2: 2.4 + C_205_1: 2.4 + C_205: 2.3 + C_204_2: 2.1 + C_204_1: 2.1 + C_204: 2.1 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 15 +============================================================================= + +RCS file: src/RCS/utilities.c,v +Working file: src/utilities.c +head: 2.30 +branch: +locks: strict + dlpark: 2.30 +access list: +symbolic names: + C_260: 2.30 + C_259: 2.30 + C_258: 2.30 + C_257: 2.30 + C_256: 2.29 + C_255: 2.29 + C_254: 2.29 + C_253: 2.28 + C_252: 2.28 + C_251: 2.28 + C_250: 2.28 + C_249: 2.27 + C_248: 2.27 + C_247: 2.27 + C_246: 2.27 + C_245: 2.27 + C_244: 2.27 + C_243: 2.27 + C_242: 2.25 + C_241: 2.24 + C_240: 2.24 + C_239: 2.24 + C_238: 2.23 + C_237: 2.22 + C_236: 2.22 + C_235: 2.21 + C_234: 2.21 + C_233: 2.21 + C_232: 2.19 + C_231: 2.18 + C_230: 2.18 + C_229: 2.16 + C_227: 2.15 + C_226: 2.15 + C_225: 2.15 + C_224: 2.15 + C_222: 2.15 + C_221: 2.15 + C_220: 2.14 + C_219: 2.13 + C_218: 2.13 + RC1: 2.13 + C_216: 2.13 + C_215: 2.13 + C_214: 2.11 + C_213: 2.11 + C_212: 2.9 + C_206: 2.9 + C_205_3: 2.8 + C_205_2: 2.8 + C_205_1: 2.7 + C_205: 2.6 + C_204_2: 2.5 + C_204_1: 2.5 + C_204: 2.5 + C_202_2: 2.4 + C_202_1: 2.4 + C_202: 2.3 + C_201: 2.1 + C_200: 2.0 +keyword substitution: kv +total revisions: 31 +============================================================================= + +RCS file: src/RCS/cvdense.h,v +Working file: src/cvdense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/cvode.h,v +Working file: src/cvode.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/dense.h,v +Working file: src/dense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/global.h,v +Working file: src/global.h +head: 2.47 +branch: +locks: strict + dlpark: 2.47 +access list: +symbolic names: + C_260: 2.47 + C_259: 2.47 + C_258: 2.46 + C_257: 2.44 + C_256: 2.44 + C_255: 2.44 + C_254: 2.43 + C_253: 2.42 + C_252: 2.42 + C_251: 2.42 + C_250: 2.42 + C_249: 2.41 + C_248: 2.41 + C_247: 2.40 + C_246: 2.40 + C_245: 2.40 + C_244: 2.39 + C_243: 2.39 + C_242: 2.36 + C_241: 2.35 + C_240: 2.35 + C_239: 2.34 + C_238: 2.33 + C_237: 2.32 + C_236: 2.32 + C_235: 2.32 + C_234: 2.31 + C_233: 2.31 + C_232: 2.30 + C_231: 2.30 + C_230: 2.30 + C_229: 2.30 + C_227: 2.29 + C_226: 2.28 + C_225: 2.28 + C_224: 2.28 + C_222: 2.28 + C_221: 2.28 + C_220: 2.28 + C_219: 2.27 + C_218: 2.27 + RC1: 2.27 + C_216: 2.27 + C_215: 2.26 + C_214: 2.25 + C_213: 2.24 + C_212: 2.19 + C_206: 2.18 + C_205_3: 2.17 + C_205_2: 2.16 + C_205_1: 2.15 + C_205: 2.13 + C_204_2: 2.11 + C_204_1: 2.11 + C_204: 2.11 + C_202_2: 2.7 + C_202_1: 2.5 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 48 +============================================================================= + +RCS file: src/RCS/input.h,v +Working file: src/input.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/kinetics.h,v +Working file: src/kinetics.h +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_260: 1.2 + C_259: 1.2 + C_258: 1.2 + C_257: 1.2 + C_256: 1.2 + C_255: 1.2 + C_254: 1.2 + C_253: 1.2 + C_252: 1.2 + C_251: 1.2 + C_250: 1.2 + C_249: 1.2 + C_248: 1.2 + C_247: 1.2 + C_246: 1.2 + C_245: 1.2 + C_244: 1.2 + C_243: 1.2 + C_242: 1.2 + C_241: 1.2 + C_240: 1.2 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: src/RCS/nvector.h,v +Working file: src/nvector.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/nvector_serial.h,v +Working file: src/nvector_serial.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/output.h,v +Working file: src/output.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/p2c.h,v +Working file: src/p2c.h +head: 2.2 +branch: +locks: strict + dlpark: 2.2 +access list: +symbolic names: + C_260: 2.2 + C_259: 2.2 + C_258: 2.2 + C_257: 2.2 + C_256: 2.2 + C_255: 2.2 + C_254: 2.2 + C_253: 2.2 + C_252: 2.2 + C_251: 2.2 + C_250: 2.2 + C_249: 2.2 + C_248: 2.2 + C_247: 2.2 + C_246: 2.2 + C_245: 2.2 + C_244: 2.2 + C_243: 2.2 + C_242: 2.2 + C_241: 2.2 + C_240: 2.2 + C_239: 2.2 + C_238: 2.1 + C_237: 2.1 + C_236: 2.1 + C_235: 2.1 + C_234: 2.1 + C_233: 2.1 + C_232: 2.1 + C_231: 2.1 + C_230: 2.1 + C_229: 2.1 + C_227: 2.1 + C_226: 2.1 + C_225: 2.1 + C_224: 2.1 + C_222: 2.1 + C_221: 2.1 + C_220: 2.1 + C_219: 2.1 + C_218: 2.1 + RC1: 2.1 + C_216: 2.1 + C_215: 2.1 + C_214: 2.1 + C_213: 2.1 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: src/RCS/phqalloc.h,v +Working file: src/phqalloc.h +head: 2.3 +branch: +locks: strict + dlpark: 2.3 +access list: +symbolic names: + C_260: 2.3 + C_259: 2.3 + C_258: 2.3 + C_257: 2.2 + C_256: 2.2 + C_255: 2.2 + C_254: 2.2 + C_253: 2.2 + C_252: 2.2 + C_251: 2.2 + C_250: 2.2 + C_249: 2.2 + C_248: 2.2 + C_247: 2.2 + C_246: 2.2 + C_245: 2.2 + C_244: 2.2 + C_243: 2.2 + C_242: 2.2 + C_241: 2.2 + C_240: 2.2 + C_239: 2.2 + C_238: 2.2 + C_237: 2.2 + C_236: 2.2 + C_235: 2.2 + C_234: 2.2 + C_233: 2.2 + C_232: 2.2 + C_231: 2.2 + C_230: 2.2 + C_229: 2.2 + C_227: 2.2 + C_226: 2.2 + C_225: 2.2 + C_224: 2.2 + C_222: 2.2 + C_221: 2.2 + C_220: 2.2 + C_219: 2.2 + C_218: 2.2 + RC1: 2.2 + C_216: 2.2 + C_215: 2.2 + C_214: 2.2 + C_213: 2.2 + C_212: 2.0 + C_206: 2.0 + C_205_3: 2.0 + C_205_2: 2.0 + C_205_1: 2.0 + C_205: 2.0 + C_204_2: 2.0 + C_204_1: 2.0 + C_204: 2.0 + C_202_2: 2.0 + C_202_1: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: src/RCS/phrqproto.h,v +Working file: src/phrqproto.h +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_260: 1.6 + C_259: 1.6 + C_258: 1.6 + C_257: 1.6 + C_256: 1.5 + C_255: 1.5 + C_254: 1.4 + C_253: 1.2 + C_252: 1.2 + C_251: 1.1 + C_250: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: src/RCS/phrqtype.h,v +Working file: src/phrqtype.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/smalldense.h,v +Working file: src/smalldense.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/sundialsmath.h,v +Working file: src/sundialsmath.h +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_260: 1.1 + C_259: 1.1 + C_258: 1.1 + C_257: 1.1 + C_256: 1.1 + C_255: 1.1 + C_254: 1.1 + C_253: 1.1 + C_252: 1.1 + C_251: 1.1 + C_250: 1.1 + C_249: 1.1 + C_248: 1.1 + C_247: 1.1 + C_246: 1.1 + C_245: 1.1 + C_244: 1.1 + C_243: 1.1 + C_242: 1.1 + C_241: 1.1 + C_240: 1.1 + C_239: 1.1 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: src/RCS/sundialstypes.h,v +Working file: src/sundialstypes.h +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_260: 1.4 + C_259: 1.4 + C_258: 1.4 + C_257: 1.4 + C_256: 1.4 + C_255: 1.4 + C_254: 1.4 + C_253: 1.4 + C_252: 1.4 + C_251: 1.4 + C_250: 1.4 + C_249: 1.3 + C_248: 1.3 + C_247: 1.3 + C_246: 1.3 + C_245: 1.3 + C_244: 1.3 + C_243: 1.3 + C_242: 1.3 + C_241: 1.3 + C_240: 1.3 + C_239: 1.2 + C_238: 1.1 + C_237: 1.1 + C_236: 1.1 + C_235: 1.1 + C_234: 1.1 + C_233: 1.1 + C_232: 1.1 + C_231: 1.1 + C_230: 1.1 + C_229: 1.1 + C_227: 1.1 + C_226: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: database/RCS/llnl.dat,v +Working file: database/llnl.dat +head: 1.14 +branch: +locks: strict +access list: +symbolic names: + C_210: 1.14 + C_209: 1.14 + C_224: 1.12 + C_207: 1.12 + C_206: 1.11 + C_205: 1.11 + C_204: 1.10 +keyword substitution: kv +total revisions: 14 +============================================================================= + +RCS file: database/RCS/minteq.dat,v +Working file: database/minteq.dat +head: 2.1 +branch: +locks: strict +access list: +symbolic names: + C_210: 2.1 + C_209: 2.1 + C_224: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: database/RCS/phreeqc.dat,v +Working file: database/phreeqc.dat +head: 2.3 +branch: +locks: strict + dlpark: 2.3 +access list: +symbolic names: + C_210: 2.3 + C_209: 2.3 + C_224: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: database/RCS/wateq4f.dat,v +Working file: database/wateq4f.dat +head: 2.6 +branch: +locks: strict + dlpark: 2.6 +access list: +symbolic names: + C_210: 2.6 + C_209: 2.6 + C_224: 2.4 + C_207: 2.2 + C_206: 2.2 + C_205: 2.2 + C_204: 2.2 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: database/RCS/iso.dat,v +Working file: database/iso.dat +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_210: 1.4 + C_209: 1.4 + C_224: 1.4 + C_207: 1.4 + C_206: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex1,v +Working file: examples/ex1 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex1.out,v +Working file: examples/ex1.out +head: 1.7 +branch: +locks: strict + dlpark: 1.7 +access list: +symbolic names: + C_212: 1.7 + C_211: 1.5 + C_210: 1.5 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: examples/RCS/ex2,v +Working file: examples/ex2 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex2.out,v +Working file: examples/ex2.out +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex2.sel,v +Working file: examples/ex2.sel +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex3,v +Working file: examples/ex3 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex3.out,v +Working file: examples/ex3.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex4,v +Working file: examples/ex4 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex4.out,v +Working file: examples/ex4.out +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_212: 1.6 + C_211: 1.4 + C_210: 1.4 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: examples/RCS/ex5,v +Working file: examples/ex5 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex5.out,v +Working file: examples/ex5.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex5.sel,v +Working file: examples/ex5.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex6,v +Working file: examples/ex6 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex6.out,v +Working file: examples/ex6.out +head: 1.13 +branch: +locks: strict + dlpark: 1.13 +access list: +symbolic names: + C_212: 1.13 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.9 + C_206: 1.7 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 13 +============================================================================= + +RCS file: examples/RCS/ex6A-B.sel,v +Working file: examples/ex6A-B.sel +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex6C.sel,v +Working file: examples/ex6C.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex7,v +Working file: examples/ex7 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex7.out,v +Working file: examples/ex7.out +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.9 + C_210: 1.8 + C_224: 1.7 + C_208: 1.7 + C_207: 1.7 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex7.sel,v +Working file: examples/ex7.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex8,v +Working file: examples/ex8 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex8.out,v +Working file: examples/ex8.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex8.sel,v +Working file: examples/ex8.sel +head: 1.9 +branch: +locks: strict + dlpark: 1.9 +access list: +symbolic names: + C_212: 1.9 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.5 + C_205: 1.5 + C_204: 1.5 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 9 +============================================================================= + +RCS file: examples/RCS/ex9,v +Working file: examples/ex9 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex9.out,v +Working file: examples/ex9.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.5 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex9.sel,v +Working file: examples/ex9.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex10,v +Working file: examples/ex10 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex10.out,v +Working file: examples/ex10.out +head: 1.12 +branch: +locks: strict + dlpark: 1.12 +access list: +symbolic names: + C_212: 1.12 + C_211: 1.10 + C_210: 1.9 + C_224: 1.8 + C_208: 1.8 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 12 +============================================================================= + +RCS file: examples/RCS/ex10.sel,v +Working file: examples/ex10.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex11,v +Working file: examples/ex11 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.1 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex11.out,v +Working file: examples/ex11.out +head: 1.13 +branch: +locks: strict + dlpark: 1.13 +access list: +symbolic names: + C_212: 1.13 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 13 +============================================================================= + +RCS file: examples/RCS/ex11adv.sel,v +Working file: examples/ex11adv.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex11trn.sel,v +Working file: examples/ex11trn.sel +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_212: 1.4 + C_211: 1.4 + C_210: 1.4 + C_224: 1.4 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: examples/RCS/ex12,v +Working file: examples/ex12 +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex12.out,v +Working file: examples/ex12.out +head: 1.3 +branch: +locks: strict + dlpark: 1.3 +access list: +symbolic names: + C_212: 1.3 + C_211: 1.1 + C_210: 1.1 + C_224: 1.1 + C_208: 1.1 + C_207: 1.1 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: examples/RCS/ex12.sel,v +Working file: examples/ex12.sel +head: 1.11 +branch: +locks: strict + dlpark: 1.11 +access list: +symbolic names: + C_212: 1.11 + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.9 + C_207: 1.9 + C_206: 1.7 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: examples/RCS/ex13a,v +Working file: examples/ex13a +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13a.out,v +Working file: examples/ex13a.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13a.sel,v +Working file: examples/ex13a.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13b,v +Working file: examples/ex13b +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13b.out,v +Working file: examples/ex13b.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13b.sel,v +Working file: examples/ex13b.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13c,v +Working file: examples/ex13c +head: 2.1 +branch: +locks: strict + dlpark: 2.1 +access list: +symbolic names: + C_212: 2.1 + C_211: 2.1 + C_210: 2.1 + C_224: 2.1 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: examples/RCS/ex13c.out,v +Working file: examples/ex13c.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex13c.sel,v +Working file: examples/ex13c.sel +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.5 + C_210: 1.5 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex14,v +Working file: examples/ex14 +head: 2.2 +branch: +locks: strict + dlpark: 2.2 +access list: +symbolic names: + C_212: 2.2 + C_211: 2.2 + C_210: 2.2 + C_224: 2.2 + C_208: 2.1 + C_207: 2.1 + C_206: 2.1 + C_205: 2.1 + C_204: 2.1 + C_202: 2.1 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 3 +============================================================================= + +RCS file: examples/RCS/ex14.out,v +Working file: examples/ex14.out +head: 1.15 +branch: +locks: strict + dlpark: 1.15 +access list: +symbolic names: + C_212: 1.15 + C_211: 1.13 + C_210: 1.12 + C_224: 1.11 + C_208: 1.9 + C_207: 1.8 + C_206: 1.6 + C_205: 1.6 + C_204: 1.6 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 15 +============================================================================= + +RCS file: examples/RCS/ex14.sel,v +Working file: examples/ex14.sel +head: 1.8 +branch: +locks: strict + dlpark: 1.8 +access list: +symbolic names: + C_212: 1.8 + C_211: 1.7 + C_210: 1.7 + C_224: 1.6 + C_208: 1.4 + C_207: 1.4 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: examples/RCS/ex15,v +Working file: examples/ex15 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex15.dat,v +Working file: examples/ex15.dat +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex15.out,v +Working file: examples/ex15.out +head: 1.8 +branch: +locks: strict + dlpark: 1.8 +access list: +symbolic names: + C_212: 1.8 + C_211: 1.6 + C_210: 1.6 + C_224: 1.5 + C_208: 1.5 + C_207: 1.5 + C_206: 1.4 + C_205: 1.3 + C_204: 1.3 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 8 +============================================================================= + +RCS file: examples/RCS/ex15.sel,v +Working file: examples/ex15.sel +head: 1.7 +branch: +locks: strict + dlpark: 1.7 +access list: +symbolic names: + C_212: 1.7 + C_211: 1.7 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.5 + C_205: 1.4 + C_204: 1.4 + C_202: 1.3 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 7 +============================================================================= + +RCS file: examples/RCS/ex16,v +Working file: examples/ex16 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex16.out,v +Working file: examples/ex16.out +head: 1.5 +branch: +locks: strict + dlpark: 1.5 +access list: +symbolic names: + C_212: 1.5 + C_211: 1.3 + C_210: 1.3 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.1 + C_205: 1.1 + C_204: 1.1 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 5 +============================================================================= + +RCS file: examples/RCS/ex17,v +Working file: examples/ex17 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex17.out,v +Working file: examples/ex17.out +head: 1.10 +branch: +locks: strict + dlpark: 1.10 +access list: +symbolic names: + C_212: 1.10 + C_211: 1.8 + C_210: 1.7 + C_224: 1.6 + C_208: 1.6 + C_207: 1.6 + C_206: 1.4 + C_205: 1.4 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 10 +============================================================================= + +RCS file: examples/RCS/ex18,v +Working file: examples/ex18 +head: 2.0 +branch: +locks: strict + dlpark: 2.0 +access list: +symbolic names: + C_212: 2.0 + C_211: 2.0 + C_210: 2.0 + C_224: 2.0 + C_208: 2.0 + C_207: 2.0 + C_206: 2.0 + C_205: 2.0 + C_204: 2.0 + C_202: 2.0 + C_201: 2.0 + C_200: 2.0 + C_1: 2.0 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: examples/RCS/ex18.out,v +Working file: examples/ex18.out +head: 1.6 +branch: +locks: strict + dlpark: 1.6 +access list: +symbolic names: + C_212: 1.6 + C_211: 1.4 + C_210: 1.4 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 + C_201: 1.2 + C_200: 1.1 + C_1: 1.1 +keyword substitution: kv +total revisions: 6 +============================================================================= + +RCS file: doc/RCS/manual.pdf,v +Working file: doc/manual.pdf +head: 1.1 +branch: +locks: strict + dlpark: 1.1 +access list: +symbolic names: + C_211: 1.1 + C_210: 1.1 + C_224: 1.1 + C_208: 1.1 + C_207: 1.1 + C_206: 1.1 + C_205: 1.1 +keyword substitution: kv +total revisions: 1 +============================================================================= + +RCS file: doc/RCS/phreeqc.txt,v +Working file: doc/phreeqc.txt +head: 1.11 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.11 + C_210: 1.10 + C_224: 1.9 + C_208: 1.8 + C_207: 1.8 + C_206: 1.7 + C_205: 1.6 + C_204_2: 1.5 + C_204: 1.4 + C_202: 1.1 + C_201: 1.1 +keyword substitution: kv +total revisions: 11 +============================================================================= + +RCS file: bin/RCS/phreeqc.orig,v +Working file: bin/phreeqc.orig +head: 1.4 +branch: +locks: strict + dlpark: 1.4 +access list: +symbolic names: + C_209: 1.4 + C_208: 1.4 + C_224: 1.4 + C_206: 1.4 + C_205: 1.4 + C_202: 1.4 + C_201: 1.4 + C_200: 1.4 + C_1: 1.4 +keyword substitution: kv +total revisions: 4 +============================================================================= + +RCS file: test/RCS/test.sh,v +Working file: test/test.sh +head: 1.2 +branch: +locks: strict + dlpark: 1.2 +access list: +symbolic names: + C_211: 1.2 + C_210: 1.2 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: test/RCS/clean.sh,v +Working file: test/clean.sh +head: 1.2 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.2 + C_210: 1.2 + C_224: 1.2 + C_208: 1.2 + C_207: 1.2 + C_206: 1.2 + C_205: 1.2 + C_204: 1.2 + C_202: 1.2 +keyword substitution: kv +total revisions: 2 +============================================================================= + +RCS file: test/RCS/check.sh,v +Working file: test/check.sh +head: 1.3 +branch: +locks: strict +access list: +symbolic names: + C_211: 1.3 + C_210: 1.3 + C_224: 1.3 + C_208: 1.3 + C_207: 1.3 + C_206: 1.3 + C_205: 1.3 + C_204: 1.3 + C_202: 1.3 +keyword substitution: kv +total revisions: 3 +============================================================================= diff --git a/rename_cpp/phreex.ico b/rename_cpp/phreex.ico new file mode 100644 index 0000000000000000000000000000000000000000..65cd87ba82d0f706b3c453b4970c8a72188fca81 GIT binary patch literal 318 zcma)1y9&ZU5F9~>8WOJ3)-o0%zCOn)LgE3BoY&DP6P{4c}P7h@#EKy1}~EZb!~x9;%!Ga~?^_ p0Y2lSV!cYa7vcm#P)fm8cahtLE0yEzih5}+0{i73`Tf^_mnR5fUrzu4 literal 0 HcmV?d00001 diff --git a/rename_cpp/phrqtype.h b/rename_cpp/phrqtype.h new file mode 100644 index 00000000..ab7160b5 --- /dev/null +++ b/rename_cpp/phrqtype.h @@ -0,0 +1,18 @@ +#ifndef _INC_PHRQTYPE_H +#define _INC_PHRQTYPE_H +/* + * The following implements long double + * Many machines long double = double so there is no advantage + * Check float.h include file for number of digits (LDBL_DIG) + * Need to define here and in cl1.c + */ + +/*#define USE_LONG_DOUBLE*/ +#ifdef USE_LONG_DOUBLE +#define LDBLE long double +#define SCANFORMAT "%Lf" +#else +#define LDBLE double +#define SCANFORMAT "%lf" +#endif +#endif /* _INC_PHRQTYPE_H */ diff --git a/rename_cpp/pitzer.cpp b/rename_cpp/pitzer.cpp new file mode 100644 index 00000000..857ae789 --- /dev/null +++ b/rename_cpp/pitzer.cpp @@ -0,0 +1,2210 @@ +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Exchange.h" + +#define PITZER + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer_init(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Initialization for pitzer + */ + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + use_etheta = TRUE; + space((void **) ((void *) &pitz_params), INIT, &max_pitz_param, + sizeof(struct pitz_param *)); + + max_theta_param = 100; + count_theta_param = 0; + space((void **) ((void *) &theta_params), INIT, &max_theta_param, + sizeof(struct theta_param *)); + + ICON = TRUE; + OTEMP = -100.; + for (i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } + pitzer_pe = FALSE; + VP = 0; + DW0 = 0; + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer_tidy(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Make lists of species for cations, anions, neutral + */ + const char *string1, *string2; + int i, j, order; + int i0, i1, i2; + int count_pos, count_neg, count_neut, count[3], jj; + LDBLE z0, z1; + struct pitz_param *pzp_ptr; + struct theta_param *theta_param_ptr; + /* + * Ensure new parameters are calculated + */ + OTEMP = -100.; + /* + * allocate pointers to species structures + */ + if (spec != NULL) + spec = (struct species **) free_check_null(spec); + spec = + (struct species **) + PHRQ_malloc((size_t) (3 * count_s * sizeof(struct species *))); + if (spec == NULL) + malloc_error(); + for (i = 0; i < 3 * count_s; i++) + spec[i] = NULL; + cations = spec; + neutrals = &(spec[count_s]); + anions = &(spec[2 * count_s]); + MAXCATIONS = count_s; + FIRSTANION = 2 * count_s; + MAXNEUTRAL = count_s; + count_cations = 0; + count_anions = 0; + count_neutrals = 0; + if (itmax < 200) + itmax = 200; + /* + * allocate other arrays for Pitzer + */ + if (IPRSNT != NULL) + IPRSNT = (int *) free_check_null(IPRSNT); + IPRSNT = (int *) PHRQ_malloc((size_t) (3 * count_s * sizeof(int))); + if (IPRSNT == NULL) + malloc_error(); + if (M != NULL) + M = (LDBLE *) free_check_null(M); + M = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + if (M == NULL) + malloc_error(); + if (LGAMMA != NULL) + LGAMMA = (LDBLE *) free_check_null(LGAMMA); + LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + if (LGAMMA == NULL) + malloc_error(); + + + for (i = 0; i < count_s; i++) + { + if (s[i] == s_eminus) + continue; + if (s[i] == s_h2o) + continue; + if (s[i]->z < -.001) + { + anions[count_anions++] = s[i]; + } + else if (s[i]->z > .001) + { + cations[count_cations++] = s[i]; + } + else + { + neutrals[count_neutrals++] = s[i]; + } + } + /* + * Add etheta to parameter list in case theta not defined for + * cation-cation or anion-anion pair + * Remove old TYPE_ETHETA definitions + */ + j = 0; + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_ETHETA) + { + pitz_params[i] = + (struct pitz_param *) free_check_null(pitz_params[i]); + } + else + { + pitz_params[j++] = pitz_params[i]; + } + } + count_pitz_param = j; + for (i = 0; i < count_cations - 1; i++) + { + for (j = i + 1; j < count_cations; j++) + { + sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name); + pzp_ptr = pitz_param_read(line, 2); + pzp_ptr->type = TYPE_ETHETA; + if (count_pitz_param >= max_pitz_param) + { + space((void **) ((void *) &pitz_params), count_pitz_param, + &max_pitz_param, sizeof(struct pitz_param *)); + } + pitz_params[count_pitz_param++] = pzp_ptr; + + } + } + for (i = 2 * count_s; i < 2 * count_s + count_anions - 1; i++) + { + for (j = i + 1; j < 2 * count_s + count_anions; j++) + { + sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name); + pzp_ptr = pitz_param_read(line, 2); + pzp_ptr->type = TYPE_ETHETA; + if (count_pitz_param >= max_pitz_param) + { + space((void **) ((void *) &pitz_params), count_pitz_param, + &max_pitz_param, sizeof(struct pitz_param *)); + } + pitz_params[count_pitz_param] = pzp_ptr; + count_pitz_param++; + } + } + /* + * put species numbers in pitz_params + */ + for (i = 0; i < count_pitz_param; i++) + { + for (j = 0; j < 3; j++) + { + if (pitz_params[i]->species[j] == NULL) + continue; + pitz_params[i]->ispec[j] = ISPEC(pitz_params[i]->species[j]); + if ((j < 2 && pitz_params[i]->ispec[j] == -1) || + (j == 3 + && (pitz_params[i]->type == TYPE_PSI + || pitz_params[i]->type == TYPE_ZETA) + && pitz_params[i]->ispec[j] == -1)) + { + input_error++; + error_string = sformatf( + "Species for Pitzer parameter not defined in SOLUTION_SPECIES, %s", + pitz_params[i]->species[j]); + error_msg(error_string, CONTINUE); + return (ERROR); + } + } + } + /* + * McGinnis data + */ + string1 = string_hsave("K+"); + string2 = string_hsave("Cl-"); + IC = ISPEC(string2); + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->species[0] == string1 && + pitz_params[i]->species[1] == string2) + { + switch (pitz_params[i]->type) + { + case TYPE_B0: + mcb0 = pitz_params[i]; + break; + case TYPE_B1: + mcb1 = pitz_params[i]; + break; + case TYPE_C0: + mcc0 = pitz_params[i]; + break; + case TYPE_B2: + case TYPE_THETA: + case TYPE_LAMDA: + case TYPE_ZETA: + case TYPE_PSI: + case TYPE_ETHETA: + case TYPE_ALPHAS: + case TYPE_MU: + case TYPE_ETA: + case TYPE_Other: + default: + break; + } + } + } + if (mcb0 == NULL && mcb1 == NULL && mcc0 == NULL && ICON == TRUE) + { + error_string = sformatf( + "No KCl interaction parameters, turning off MacInnis scaling."); + warning_msg(error_string); + ICON = FALSE; + } + /* + * Set alpha values + */ + for (i = 0; i < count_pitz_param; i++) + { + z0 = fabs(spec[pitz_params[i]->ispec[0]]->z); + z1 = fabs(spec[pitz_params[i]->ispec[1]]->z); + if (equal(z0, 1.0, 1e-8) || equal(z1, 1.0, 1e-8)) + { + order = 1; + } + else if (equal(z0, 2.0, 1e-8) && equal(z1, 2.0, 1e-8)) + { + order = 2; + } + else + { + order = 3; + } + if (pitz_params[i]->type == TYPE_B1) + { + switch (order) + { + case 1: + case 3: + pitz_params[i]->alpha = 2.0; + break; + case 2: + pitz_params[i]->alpha = 1.4; + break; + } + } + else if (pitz_params[i]->type == TYPE_B2) + { + switch (order) + { + case 1: + pitz_params[i]->alpha = 12.0; + break; + case 2: + pitz_params[i]->alpha = 12.0; + break; + case 3: + pitz_params[i]->alpha = 50.0; + break; + } + } + } + /* + * Add specific alphas + */ + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_ALPHAS) + { + for (j = 0; j < count_pitz_param; j++) + { + if (pitz_params[j]->type != TYPE_B1) + continue; + if (pitz_params[i]->ispec[0] != pitz_params[j]->ispec[0]) + continue; + if (pitz_params[i]->ispec[1] != pitz_params[j]->ispec[1]) + continue; + pitz_params[j]->alpha = pitz_params[i]->a[0]; + break; + } + for (j = 0; j < count_pitz_param; j++) + { + if (pitz_params[j]->type != TYPE_B2) + continue; + if (pitz_params[i]->ispec[0] != pitz_params[j]->ispec[0]) + continue; + if (pitz_params[i]->ispec[1] != pitz_params[j]->ispec[1]) + continue; + pitz_params[j]->alpha = pitz_params[i]->a[1]; + break; + } + } + } + + /* + * Add thetas pointer to etheta pitzer parameters + */ + + if (count_theta_param > 0) + { + for (i = 0; i < count_theta_param; i++) + { + theta_params[i] = + (struct theta_param *) free_check_null(theta_params[i]); + } + } + count_theta_param = 0; + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_ETHETA) + { + z0 = spec[pitz_params[i]->ispec[0]]->z; + z1 = spec[pitz_params[i]->ispec[1]]->z; + theta_param_ptr = theta_param_search(z0, z1); + if (theta_param_ptr == NULL) + { + if (count_theta_param >= max_theta_param) + { + space((void **) ((void *) &theta_params), + count_theta_param, &max_theta_param, + sizeof(struct theta_param *)); + } + theta_params[count_theta_param] = theta_param_alloc(); + theta_param_init(theta_params[count_theta_param]); + theta_params[count_theta_param]->zj = z0; + theta_params[count_theta_param]->zk = z1; + theta_param_ptr = theta_params[count_theta_param]; + count_theta_param++; + } + pitz_params[i]->thetas = theta_param_ptr; + } + } + /* + * Tidy TYPE_MU + */ + + /* Coef for Osmotic coefficient for TYPE_MU */ + + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_MU) + { + i0 = pitz_params[i]->ispec[0]; + i1 = pitz_params[i]->ispec[1]; + i2 = pitz_params[i]->ispec[2]; + count_pos = count_neg = count_neut = 0; + for (j = 0; j <= 2; j++) + { + if (spec[pitz_params[i]->ispec[j]]->z > 0) + { + count_pos++; + } + if (spec[pitz_params[i]->ispec[j]]->z == 0) + { + count_neut++; + } + if (spec[pitz_params[i]->ispec[j]]->z < 0) + { + count_neg++; + } + } + /* All neutral */ + if (count_neut == 3) + { + if (i0 == i1 && i1 == i2) + { + /* type n, n, n */ + pitz_params[i]->os_coef = 1; + continue; + } + else if (i0 == i1 || i1 == i2 || i0 == i2) + { + /* type n, n, n' */ + pitz_params[i]->os_coef = 3; + continue; + } + else + { + /* type n, n', n'' */ + pitz_params[i]->os_coef = 6; + continue; + } + } + /* Two neutral, one anion or cation */ + if (i0 == i1 || i1 == i2 || i0 == i2) + { + /* type n, n, a|c */ + pitz_params[i]->os_coef = 3; + continue; + } + else + { + /* type n, n', a|c */ + pitz_params[i]->os_coef = 6; + continue; + } + } + } + + /* Coef for gammas for TYPE_MU */ + + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_MU) + { + for (j = 0; j <= 2; j++) + { + count[j] = 0; + for (jj = 0; jj <= 2; jj++) + { + if (pitz_params[i]->ispec[j] == pitz_params[i]->ispec[jj]) + { + count[j]++; + } + } + } + for (j = 0; j <= 2; j++) + { + /* cation or anion */ + if (spec[pitz_params[i]->ispec[j]]->z < 0 + || spec[pitz_params[i]->ispec[j]]->z > 0) + { + if (count[0] > 1 || count[1] > 1) + { + pitz_params[i]->ln_coef[j] = 3; + } + else + { + pitz_params[i]->ln_coef[j] = 6; + } + continue; + } + /* Neutral */ + if (count[j] == 3) + { + pitz_params[i]->ln_coef[j] = 1; + } + else if (count[j] == 2) + { + pitz_params[i]->ln_coef[j] = 3; + } + else if (count[j] == 1) + { + if (count[0] > 1 || count[1] > 1) + { + pitz_params[i]->ln_coef[j] = 3; + } + else + { + pitz_params[i]->ln_coef[j] = 6; + } + } + } + } + } + /* Debug TYPE_MU coefficients */ + /* + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_MU) + { + fprintf(stderr, "%s\t%s\t%s\n", pitz_params[i]->species[0], pitz_params[i]->species[1], pitz_params[i]->species[2]); + fprintf(stderr, "%f\t%f\t%f\n", pitz_params[i]->ln_coef[0], pitz_params[i]->ln_coef[1], pitz_params[i]->ln_coef[2]); + fprintf(stderr, "%f\n\n", pitz_params[i]->os_coef); + } + } + */ + /* + * Tidy TYPE_LAMDA + */ + + /* Coef for Osmotic coefficient for TYPE_LAMDA */ + + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_LAMDA) + { + i0 = pitz_params[i]->ispec[0]; + i1 = pitz_params[i]->ispec[1]; + /* All neutral */ + if (i0 == i1) + { + /* type n, n */ + pitz_params[i]->os_coef = 0.5; + pitz_params[i]->ln_coef[0] = 1; + pitz_params[i]->ln_coef[1] = 1; + } + else + { + /* type nn', na, nc */ + pitz_params[i]->os_coef = 1; + pitz_params[i]->ln_coef[0] = 2; + pitz_params[i]->ln_coef[1] = 2; + } + } + } + /* Debug TYPE_LAMDA coefficients */ + /* + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type == TYPE_LAMDA) + { + fprintf(stderr, "%s\t%s\n", pitz_params[i]->species[0], pitz_params[i]->species[1]); + fprintf(stderr, "%f\t%f\n", pitz_params[i]->ln_coef[0], pitz_params[i]->ln_coef[1]); + fprintf(stderr, "%f\n\n", pitz_params[i]->os_coef); + } + } + */ + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ISPEC(const char *name) +/* ---------------------------------------------------------------------- */ +/* + * Find species number in spec for character string species name + */ +{ + int i; + for (i = 0; i < 3 * count_s; i++) + { + if (spec[i] == NULL) + continue; + if (name == spec[i]->name) + { + return (i); + } + } + return (-1); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_pitzer(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Reads advection information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + /* + * Read advection parameters: + * number of cells; + * number of shifts; + */ + int n, j; + struct pitz_param *pzp_ptr; + pitz_param_type pzp_type; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "b0", /* 0 */ + "b1", /* 1 */ + "b2", /* 2 */ + "c0", /* 3 */ + "theta", /* 4 */ + "lamda", /* 5 */ + "zeta", /* 6 */ + "psi", /* 7 */ + "macinnes", /* 8 */ + "macinnis", /* 9 */ + "mac", /* 10 */ + "redox", /* 11 */ + "pe", /* 12 */ + "alphas", /* 13 */ + "mu", /* 14 */ + "eta", /* 15 */ + "etheta", /* 16 */ + "use_etheta", /* 17 */ + "lambda" /* 18 */ + }; + int count_opt_list = 19; + /* + * Read lines + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + n = -1; + pzp_type = TYPE_Other; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + pzp_ptr = pitz_param_read(line, n); + if (pzp_ptr != NULL) + { + pzp_ptr->type = pzp_type; + j = pitz_param_search(pzp_ptr); + if (j < 0) + { + if (count_pitz_param >= max_pitz_param) + { + space((void **) ((void *) &pitz_params), + count_pitz_param, &max_pitz_param, + sizeof(struct pitz_param *)); + } + + pitz_params[count_pitz_param] = pzp_ptr; + count_pitz_param++; + } + else + { + if (pitz_params[j]->species[2] != NULL) + { + error_string = sformatf( "Redefinition of parameter, %s %s %s\n", + pitz_params[j]->species[0], pitz_params[j]->species[1], pitz_params[j]->species[2]); + } + else + { + error_string = sformatf( "Redefinition of parameter, %s %s\n", + pitz_params[j]->species[0], pitz_params[j]->species[1]); + } + warning_msg(error_string); + pitz_params[j] = (struct pitz_param *) free_check_null(pitz_params[j]); + pitz_params[j] = pzp_ptr; + } + } + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in PITZER keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* b0 */ + pzp_type = TYPE_B0; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 1: /* b1 */ + pzp_type = TYPE_B1; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 2: /* b2 */ + pzp_type = TYPE_B2; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 3: /* c0 */ + pzp_type = TYPE_C0; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 4: /* theta */ + pzp_type = TYPE_THETA; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 5: /* lamda */ + case 18: /* lambda */ + pzp_type = TYPE_LAMDA; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 6: /* zeta */ + pzp_type = TYPE_ZETA; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 7: /* psi */ + pzp_type = TYPE_PSI; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 13: /* alphas */ + pzp_type = TYPE_ALPHAS; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 8: /* macinnes */ + case 9: /* macinnis */ + case 10: /* mac */ + opt_save = OPTION_ERROR; + ICON = get_true_false(next_char, TRUE); + break; + case 11: /* redox */ + case 12: /* pe */ + opt_save = OPTION_ERROR; + pitzer_pe = get_true_false(next_char, TRUE); + break; + case 14: /* mu */ + pzp_type = TYPE_MU; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 15: /* eta */ + pzp_type = TYPE_ETA; + n = 3; + opt_save = OPTION_DEFAULT; + break; + case 16: /* etheta */ + case 17: /* use_etheta */ + opt_save = OPTION_ERROR; + use_etheta = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + pitzer_model = TRUE; + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +PTEMP(LDBLE TK) +/* ---------------------------------------------------------------------- */ +{ +/* +C +C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER +C +*/ + LDBLE DC0; + int i; + LDBLE TR = 298.15; + + if (fabs(TK - OTEMP) < 0.001e0) + return OK; + OTEMP = TK; +/* +C Set DW0 +*/ + DW(TK); + for (i = 0; i < count_pitz_param; i++) + { + calc_pitz_param(pitz_params[i], TK, TR); + } + DC0 = DC(TK); + if (fabs(TK - TR) < 0.001e0) + { + A0 = 0.392e0; + //Cite Jonathan Toner + //A0 = 86.6836498e0 + (TK)*0.084879594e0 - (0.0000888785e0)*pow(TK,(LDBLE) 2.0e0) + (4.88096e-8)*pow(TK,(LDBLE) 3.0e0) - (1327.31477e0/(TK)) - 17.6460172e0*log(TK); + + } + else + { + DC0 = DC(TK); + A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); + /*A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) +/* ---------------------------------------------------------------------- */ +{ + LDBLE param; + /* + */ + if (fabs(TK - TR) < 0.001) + { + param = pz_ptr->a[0]; + } + else + { + param = (pz_ptr->a[0] + + pz_ptr->a[1] * (1.e0 / TK - 1.e0 / TR) + + pz_ptr->a[2] * log(TK / TR) + + pz_ptr->a[3] * (TK - TR) + + pz_ptr->a[4] * (TK * TK - TR * TR)) + + pz_ptr->a[5] * (1.e0 / (TK * TK) - 1.e0 / (TR * TR)); + } + pz_ptr->p = param; + switch (pz_ptr->type) + { + case TYPE_B0: + pz_ptr->U.b0 = param; + break; + case TYPE_B1: + pz_ptr->U.b1 = param; + break; + case TYPE_B2: + pz_ptr->U.b2 = param; + break; + case TYPE_C0: + pz_ptr->U.c0 = param; + break; + case TYPE_THETA: + pz_ptr->U.theta = param; + break; + case TYPE_LAMDA: + pz_ptr->U.lamda = param; + break; + case TYPE_ZETA: + pz_ptr->U.zeta = param; + break; + case TYPE_ETHETA: + break; + case TYPE_PSI: + pz_ptr->U.psi = param; + break; + case TYPE_ALPHAS: + break; + case TYPE_MU: + pz_ptr->U.mu = param; + break; + case TYPE_ETA: + pz_ptr->U.eta = param; + break; + case TYPE_Other: + default: + error_msg("Should not be TYPE_Other in function calc_pitz_param", + STOP); + break; + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer(void) +/* ---------------------------------------------------------------------- */ +{ + int i, i0, i1, i2; + LDBLE param, l_alpha, z0, z1, z2; + LDBLE etheta, ethetap; + /* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, + BMXPHI, PHIPHI, AW, A, B; + */ + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + B; + LDBLE I, TK; + int LNEUT; + /* + C + C INITIALIZE + C + */ + CONV = 1.0 / log(10.0); + XI = 0.0e0; + XX = 0.0e0; + OSUM = 0.0e0; + LNEUT = FALSE; + /*n + I = *I_X; + TK = *TK_X; + */ + I = mu_x; + TK = tk_x; + /* DH_AB(TK, &A, &B); */ + /* + C + C TRANSFER DATA FROM TO M + C + */ + for (i = 0; i < 3 * count_s; i++) + { + IPRSNT[i] = FALSE; + M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + M[i] = under(spec[i]->lm); + if (M[i] > MIN_TOTAL) + IPRSNT[i] = TRUE; + } + } + if (ICON == TRUE) + { + IPRSNT[IC] = TRUE; + } + /* + ICON = 0; + M[1] = 1.40070736; + M[4] = 2.52131086E-05; + M[140] = 4.59985435E-09; + */ + + /* + C + C COMPUTE PITZER COEFFICIENTS' TEMPERATURE DEPENDENCE + C + */ + PTEMP(TK); + for (i = 0; i < 2 * count_s + count_anions; i++) + { + LGAMMA[i] = 0.0; + if (IPRSNT[i] == TRUE) + { + XX = XX + M[i] * fabs(spec[i]->z); + XI = XI + M[i] * spec[i]->z * spec[i]->z; + OSUM = OSUM + M[i]; + } + } + I = XI / 2.0e0; + /* + C + C EQUATION (8) + C + */ + BIGZ = XX; + DI = sqrt(I); + /* + C + C CALCULATE F & GAMCLM + C + */ + B = 1.2; + F = -A0 * (DI / (1.0e0 + B * DI) + 2.0e0 * log(1.0e0 + B * DI) / B); + XXX = 2.0e0 * DI; + XXX = + (1.0e0 - (1.0e0 + XXX - XXX * XXX * 0.5e0) * exp(-XXX)) / (XXX * XXX); + /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I; */ + /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I; */ + /*GAMCLM = F + I * 2.0e0 * (mcb0->p + mcb1->p * XXX) + 1.5e0 * mcc0->p * I * I; */ + GAMCLM = F; + if (mcb0 != NULL) + GAMCLM += I * 2.0e0 * mcb0->p; + if (mcb1 != NULL) + GAMCLM += I * 2.0e0 * mcb1->p * XXX; + if (mcc0 != NULL) + GAMCLM += 1.5e0 * mcc0->p * I * I; + CSUM = 0.0e0; + OSMOT = -(A0) * pow(I, (LDBLE) 1.5e0) / (1.0e0 + B * DI); + /* + * Calculate ethetas + */ + for (i = 0; i < count_theta_param; i++) + { + z0 = theta_params[i]->zj; + z1 = theta_params[i]->zk; + ETHETAS(z0, z1, I, ðeta, ðetap); + theta_params[i]->etheta = etheta; + theta_params[i]->ethetap = ethetap; + } + /* + * Sums for F, LGAMMA, and OSMOT + */ + for (i = 0; i < count_pitz_param; i++) + { + i0 = pitz_params[i]->ispec[0]; + i1 = pitz_params[i]->ispec[1]; + if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) + continue; + z0 = spec[i0]->z; + z1 = spec[i1]->z; + param = pitz_params[i]->p; + l_alpha = pitz_params[i]->alpha; + switch (pitz_params[i]->type) + { + case TYPE_B0: + LGAMMA[i0] += M[i1] * 2.0 * param; + LGAMMA[i1] += M[i0] * 2.0 * param; + OSMOT += M[i0] * M[i1] * param; + break; + case TYPE_B1: + if (param != 0.0) + { + F += M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); + LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); + OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); + } + break; + case TYPE_B2: + if (param != 0.0) + { + F += M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); + LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); + OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); + } + break; + case TYPE_C0: + CSUM += + M[i0] * M[i1] * pitz_params[i]->p / (2.0e0 * + sqrt(fabs(z0 * z1))); + LGAMMA[i0] += M[i1] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + LGAMMA[i1] += M[i0] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + OSMOT += + M[i0] * M[i1] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + break; + case TYPE_THETA: + LGAMMA[i0] += 2.0 * M[i1] * (param /*+ ETHETA(z0, z1, I) */ ); + LGAMMA[i1] += 2.0 * M[i0] * (param /*+ ETHETA(z0, z1, I) */ ); + OSMOT += M[i0] * M[i1] * param; + break; + case TYPE_ETHETA: + /* + ETHETAS(z0, z1, I, ðeta, ðetap); + */ + if (use_etheta == TRUE) + { + etheta = pitz_params[i]->thetas->etheta; + ethetap = pitz_params[i]->thetas->ethetap; + F += M[i0] * M[i1] * ethetap; + LGAMMA[i0] += 2.0 * M[i1] * etheta; + LGAMMA[i1] += 2.0 * M[i0] * etheta; + OSMOT += M[i0] * M[i1] * (etheta + I * ethetap); + /* + F += M[i0]*M[i1]*ETHETAP(z0, z1, I); + LGAMMA[i0] += 2.0*M[i1]*(ETHETA(z0, z1, I) ); + LGAMMA[i1] += 2.0*M[i0]*(ETHETA(z0, z1, I) ); + OSMOT += M[i0]*M[i1]*(ETHETA(z0, z1, I) + I*ETHETAP(z0, z1, I) ); + */ + } + break; + case TYPE_PSI: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + z2 = spec[i2]->z; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_LAMDA: + LGAMMA[i0] += M[i1] * param * pitz_params[i]->ln_coef[0]; + LGAMMA[i1] += M[i0] * param * pitz_params[i]->ln_coef[1]; + OSMOT += M[i0] * M[i1] * param * pitz_params[i]->os_coef; + break; + case TYPE_ZETA: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_MU: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + + LGAMMA[i0] += M[i1] * M[i2] * param * pitz_params[i]->ln_coef[0]; + LGAMMA[i1] += M[i0] * M[i2] * param * pitz_params[i]->ln_coef[1]; + LGAMMA[i2] += M[i0] * M[i1] * param * pitz_params[i]->ln_coef[2]; + OSMOT += M[i0] * M[i1] * M[i2] * param * pitz_params[i]->os_coef; + break; + case TYPE_ETA: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_ALPHAS: + break; + case TYPE_Other: + default: + error_msg("TYPE_Other in pitz_param list.", STOP); + break; + } + } + + /* + * Add F and CSUM terms to LGAMMA + */ + + for (i = 0; i < count_cations; i++) + { + z0 = spec[i]->z; + LGAMMA[i] += z0 * z0 * F + fabs(z0) * CSUM; + } + for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) + { + z0 = spec[i]->z; + LGAMMA[i] += z0 * z0 * F + fabs(z0) * CSUM; + } + /* + C + C CONVERT TO MACINNES CONVENTION + C + */ + if (ICON == TRUE) + { + PHIMAC = LGAMMA[IC] - GAMCLM; + /* + C + C CORRECTED ERROR IN PHIMAC, NOVEMBER, 1989 + C + */ + for (i = 0; i < 2 * count_s + count_anions; i++) + { + if (IPRSNT[i] == TRUE) + { + LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; + } + } + } + + COSMOT = 1.0e0 + 2.0e0 * OSMOT / OSUM; + /* + C + C CALCULATE THE ACTIVITY OF WATER + C + */ + AW = exp(-OSUM * COSMOT / 55.50837e0); + /* + if (AW > 1.0) + AW = 1.0; + */ + /*s_h2o->la=log10(AW); */ + mu_x = I; + for (i = 0; i < 2 * count_s + count_anions; i++) + { + if (IPRSNT[i] == FALSE) + continue; + /*spec[i]->lg=LGAMMA[i]*CONV; */ + spec[i]->lg_pitzer = LGAMMA[i] * CONV; + /* + output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); + */ + } + /* + output_msg(sformatf( "OSUM: %e\n", OSUM)); + output_msg(sformatf( "OSMOT: %e\n", OSMOT)); + output_msg(sformatf( "COSMOT: %e\n", COSMOT)); + output_msg(sformatf( "F: %e\n", F)); + output_msg(sformatf( "AW: %e\n", AW)); + */ + /* + *I_X = I; + *COSMOT_X = COSMOT; + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +JAY(LDBLE X) +/* ---------------------------------------------------------------------- */ +/* +C +C FUNCTION TO CALCULATE JAY AND JPRIME +C +C J0 AND J1, USED IN CALCULATION OF ETHETA AND ETHEAP +C +*/ +{ + LDBLE JAY; + BDK(X); + JAY = X / 4.0e0 - 1.0e0 + 0.5e0 * (BK[0] - BK[2]); + return JAY; +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +JPRIME(LDBLE L_Y) +/* ---------------------------------------------------------------------- */ +{ + LDBLE L_DZ; + BDK(L_Y); + if (L_Y > 1.0e0) + { + L_DZ = -4.0e0 * pow(L_Y, (LDBLE) -1.1e0) / 9.0e0; + } + else + { + L_DZ = 0.8e0 * pow(L_Y, (LDBLE) -0.8e0); + } + return (L_Y * (.25e0 + L_DZ * (DK[0] - DK[2]) / 2.0e0)); +} + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +BDK(LDBLE X) +/* ---------------------------------------------------------------------- */ +/* +C +C NUMERICAL APPROXIMATION TO THE INTEGRALS IN THE EXPRESSIONS FOR J0 +C AND J1. CHEBYSHEV APPROXIMATION IS USED. THE CONSTANTS 'AK' ARE +C DEFINED IN BLOCK COMMON. +C +*/ +/* +C +C AK IS USED TO CALCULATE HIGHER ORDER ELECTROSTATIC TERMS IN +C SUBROUTINE PITZER +C +*/ +{ + LDBLE AKX[42] = { + 1.925154014814667e0, -.060076477753119e0, -.029779077456514e0, + -.007299499690937e0, 0.000388260636404e0, 0.000636874599598e0, + 0.000036583601823e0, -.000045036975204e0, -.000004537895710e0, + 0.000002937706971e0, 0.000000396566462e0, -.000000202099617e0, + -.000000025267769e0, 0.000000013522610e0, 0.000000001229405e0, + -.000000000821969e0, -.000000000050847e0, 0.000000000046333e0, + 0.000000000001943e0, -.000000000002563e0, -.000000000010991e0, + 0.628023320520852e0, 0.462762985338493e0, 0.150044637187895e0, + -.028796057604906e0, -.036552745910311e0, -.001668087945272e0, + 0.006519840398744e0, 0.001130378079086e0, -.000887171310131e0, + -.000242107641309e0, 0.000087294451594e0, 0.000034682122751e0, + -.000004583768938e0, -.000003548684306e0, -.000000250453880e0, + 0.000000216991779e0, 0.000000080779570e0, 0.000000004558555e0, + -.000000006944757e0, -.000000002849257e0, 0.000000000237816e0 + }; +/* + LDBLE PRECISION AK, BK, DK + COMMON / MX8 / AK(0:20,2),BK(0:22),DK(0:22) +*/ + LDBLE *AK; + LDBLE L_Z; + int II; + int i; + + if (X <= 1.0e0) + { + II = 1; + L_Z = 4.0e0 * pow(X, (LDBLE) 0.2e0) - 2.0e0; + AK = &AKX[0]; + } + else + { + II = 2; + L_Z = 40.0e0 * pow(X, (LDBLE) -1.0e-1) / 9.0e0 - 22.0e0 / 9.0e0; + AK = &AKX[21]; + } + for (i = 20; i >= 0; i--) + { + BK[i] = L_Z * BK[i + 1] - BK[i + 2] + AK[i]; + DK[i] = BK[i + 1] + L_Z * DK[i + 1] - DK[i + 2]; + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +G(LDBLE L_Y) +/* ---------------------------------------------------------------------- */ +{ + LDBLE d=0.0; + if (L_Y != 0.0) + { + d = 2.0e0 * (1.0e0 - (1.0e0 + L_Y) * exp(-L_Y)) / (L_Y * L_Y); + } + + return (d); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +GP(LDBLE L_Y) +/* ---------------------------------------------------------------------- */ +{ + LDBLE d=0.0; + if (L_Y != 0.0) + { + d = -2.0e0 * (1.0e0 - (1.0e0 + L_Y + L_Y * L_Y / 2.0e0) * exp(-L_Y)) / + (L_Y * L_Y); + } + return d; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap) +/* ---------------------------------------------------------------------- */ +{ + LDBLE XCON, ZZ; + LDBLE XJK, XJJ, XKK; + + *etheta = 0.0; + *ethetap = 0.0; + if (ZJ == ZK) + return (OK); + XCON = 6.0e0 * A0 * sqrt(I); + ZZ = ZJ * ZK; +/* +C +C NEXT 3 ARE EQUATION (A1) +C +*/ + XJK = XCON * ZZ; + XJJ = XCON * ZJ * ZJ; + XKK = XCON * ZK * ZK; +/* +C +C EQUATION (A3) +C +*/ + *etheta = + ZZ * (JAY(XJK) - JAY(XJJ) / 2.0e0 - JAY(XKK) / 2.0e0) / (4.0e0 * I); + *ethetap = + ZZ * (JPRIME(XJK) - JPRIME(XJJ) / 2.0e0 - + JPRIME(XKK) / 2.0e0) / (8.0e0 * I * I) - *etheta / I; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer_clean_up(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all allocated memory, except strings + */ + int i; + for (i = 0; i < count_pitz_param; i++) + { + pitz_params[i] = + (struct pitz_param *) free_check_null(pitz_params[i]); + } + count_pitz_param = 0; + pitz_params = (struct pitz_param **) free_check_null(pitz_params); + for (i = 0; i < count_theta_param; i++) + { + theta_params[i] = + (struct theta_param *) free_check_null(theta_params[i]); + } + count_theta_param = 0; + theta_params = (struct theta_param **) free_check_null(theta_params); + LGAMMA = (LDBLE *) free_check_null(LGAMMA); + IPRSNT = (int *) free_check_null(IPRSNT); + spec = (struct species **) free_check_null(spec); + M = (LDBLE *) free_check_null(M); + + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_pz(int initial) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets initial guesses for unknowns if initial == TRUE + * Revises guesses whether initial is true or not + */ + int i; + struct solution *solution_ptr; +/* + * Set initial log concentrations to zero + */ + iterations = -1; + solution_ptr = use.Get_solution_ptr(); + for (i = 0; i < count_s_x; i++) + { + s_x[i]->lm = LOG_ZERO_MOLALITY; + s_x[i]->lg_pitzer = 0.0; + } + if (initial == TRUE || set_and_run_attempt > 0) + { + for (i = 0; i < count_s_x; i++) + { + s_x[i]->lg = 0.0; + } + } +/* + * Set master species activities + */ + + tc_x = solution_ptr->tc; + tk_x = tc_x + 273.15; + patm_x = solution_ptr->patm; +/* + * H+, e-, H2O + */ + mass_water_aq_x = solution_ptr->mass_water; + mu_x = solution_ptr->mu; + s_h2o->moles = mass_water_aq_x / gfw_water; + s_h2o->la = log10(solution_ptr->ah2o); + AW = pow((LDBLE) 10.0, s_h2o->la); + s_hplus->la = -solution_ptr->ph; + s_hplus->lm = s_hplus->la; + s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; + s_eminus->la = -solution_ptr->solution_pe; + if (initial == TRUE) + pitzer_initial_guesses(); + if (dl_type_x != NO_DL) + initial_surface_water(); + pitzer_revise_guesses(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer_initial_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make initial guesses for activities of master species and + * ionic strength + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.Get_solution_ptr(); + mu_x = + s_hplus->moles + + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + mu_x /= mass_water_aq_x; + s_h2o->la = 0.0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type < CB) + { + mu_x += + x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * + x[i]->master[0]->s->z; + x[i]->master[0]->s->la = log10(x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == CB) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == EXCH) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(x[i]->moles); + } + } + else if (x[i]->type == SURFACE) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); + } + } + else if (x[i]->type == SURFACE_CB) + { + x[i]->master[0]->s->la = 0.0; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer_revise_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Revise molalities species + */ + int i; + int l_iter, max_iter, repeat, fail; + LDBLE weight, f; + + max_iter = 10; + /* gammas(mu_x); */ + l_iter = 0; + repeat = TRUE; + fail = FALSE;; + while (repeat == TRUE) + { + l_iter++; + if (debug_set == TRUE) + { + output_msg(sformatf( "\nBeginning set iteration %d.\n", + l_iter)); + } + if (l_iter == max_iter + 1) + { + log_msg(sformatf( + "Did not converge in set, iteration %d.\n", + iterations)); + fail = TRUE; + } + if (l_iter > 2 * max_iter) + { + log_msg(sformatf( + "Did not converge with relaxed criteria in set.\n")); + return (OK); + } + molalities(TRUE); + /*pitzer(); */ + /*s_h2o->la = 0.0; */ + /*molalities(TRUE); */ + mb_sums(); + if (state < REACTION) + { + sum_species(); + } + else + { + for (i = 0; i < count_unknowns; i++) + { + x[i]->sum = x[i]->f; + } + } + /*n + if (debug_set == TRUE) { + pr.species = TRUE; + pr.all = TRUE; + print_species(); + } + */ + repeat = FALSE; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type == MB || +/* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || x[i]->type == SURFACE) + { + + if (debug_set == TRUE) + { + output_msg(sformatf( + "\n\t%5s at beginning of set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + if (fabs(x[i]->moles) < 1e-30) + x[i]->moles = 0; + f = fabs(x[i]->sum); + if (f == 0 && x[i]->moles == 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + continue; + } + else if (f == 0) + { + repeat = TRUE; + x[i]->master[0]->s->la += 5; +/*!!!!*/ if (x[i]->master[0]->s->la < -999.) + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + else if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + repeat = TRUE; + x[i]->master[0]->s->la += + weight * log10(fabs(x[i]->moles / x[i]->sum)); + } + if (debug_set == TRUE) + { + output_msg(sformatf( + "\t%5s not converged in set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, + (double) x[i]->sum, (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + else if (x[i]->type == ALK) + { + f = total_co2; + if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + repeat = TRUE; + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + x[i]->master[0]->s->la += weight * + log10(fabs(x[i]->moles / x[i]->sum)); + if (debug_set == TRUE) + { + output_msg(sformatf( + "%s not converged in set. %e\t%e\t%e\n", + x[i]->description, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + } + } + log_msg(sformatf( "Iterations in pitzer_revise_guesses: %d\n", l_iter)); + /*mu_x = mu_unknown->f * 0.5 / mass_water_aq_x; */ + if (mu_x <= 1e-8) + { + mu_x = 1e-8; + } + /*gammas(mu_x); */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +jacobian_pz(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE *base; + LDBLE d, d1, d2; + int i, j; + +Restart: + int pz_max_unknowns = max_unknowns; + if (full_pitzer == TRUE) + { + molalities(TRUE); + pitzer(); + residuals(); + } + base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + if (base == NULL) + malloc_error(); + for (i = 0; i < count_unknowns; i++) + { + base[i] = residual[i]; + } + d = 0.0001; + d1 = d * log(10.0); + d2 = 0; + for (i = 0; i < count_unknowns; i++) + { + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case AH2O: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case PITZER_GAMMA: + x[i]->s->lg += d; + d2 = d; + break; + case MH2O: + mass_water_aq_x *= (1.0 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + d2 = log(1.0 + d); + break; + case MH: + if (pitzer_pe == TRUE) + { + s_eminus->la += d; + d2 = d1; + break; + } + else + { + continue; + } + case GAS_MOLES: + if (gas_in == FALSE) + continue; + d2 = d * x[i]->moles; + if (d2 < 1e-14) + d2 = 1e-14; + x[i]->moles += d2; + break; + case MU: + case PP: + case S_S_MOLES: + continue; + break; + } + molalities(TRUE); + if (max_unknowns > pz_max_unknowns) + { + base = (LDBLE *) free_check_null(base); + goto Restart; + } + if (full_pitzer == TRUE) + pitzer(); + mb_sums(); + residuals(); + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] = + -(residual[j] - base[j]) / d2; + } + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + case AH2O: + x[i]->master[0]->s->la -= d; + break; + case MH: + s_eminus->la -= d; + if (array[i * (count_unknowns + 1) + i] == 0) + { + array[i * (count_unknowns + 1) + i] = + exp(s_h2->lm * LOG_10) * 2; + } + break; + case PITZER_GAMMA: + x[i]->s->lg -= d; + break; + case MH2O: + mass_water_aq_x /= (1 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + break; + case GAS_MOLES: + if (gas_in == FALSE) + continue; + x[i]->moles -= d2; + break; + + } + } + molalities(TRUE); + if (full_pitzer == TRUE) + pitzer(); + mb_sums(); + residuals(); + free_check_null(base); + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +model_pz(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * model is called after the equations have been set up by prep + * and initial guesses have been made in set. + * + * Here is the outline of the calculation sequence: + * residuals--residuals are calculated, if small we are done + * sum_jacobian--jacobian is calculated + * ineq--inequality solver is called + * reset--estimates of unknowns revised, if changes are small solution + * has been found, usually convergence is found in residuals. + * gammas--new activity coefficients + * molalities--calculate molalities + * mb_sums--calculate mass-balance sums + * mb_gases--decide if gas_phase exists + * mb_s_s--decide if solid_solutions exists + * switch_bases--check to see if new basis species is needed + * reprep--rewrite equations with new basis species if needed + * pitzer_revise_guesses--revise unknowns to get initial mole balance + * check_residuals--check convergence one last time + * sum_species--calculate sums of elements from species concentrations + * + * An additional pass through may be needed if unstable phases still exist + * in the phase assemblage. + */ + int l_kode, return_kode; + int r; + int count_infeasible, count_basis_change; + int debug_model_save; + int mass_water_switch_save; + +/* debug_model = TRUE; */ +/* debug_prep = TRUE; */ +/* debug_set = TRUE; */ + /* mass_water_switch == TRUE, mass of water is constant */ + mass_water_switch_save = mass_water_switch; + if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) + { + mass_water_switch = TRUE; + } + debug_model_save = debug_model; + pe_step_size_now = pe_step_size; + step_size_now = step_size; + if (!use.Get_kinetics_in()) status(0, NULL); + iterations = 0; + gamma_iterations = 0; + count_basis_change = count_infeasible = 0; + stop_program = FALSE; + remove_unstable_phases = FALSE; + if (always_full_pitzer == TRUE) + { + full_pitzer = TRUE; + } + else + { + full_pitzer = FALSE; + } + for (;;) + { + mb_gases(); + mb_s_s(); + l_kode = 1; + while ((r = residuals()) != CONVERGED + || remove_unstable_phases == TRUE) + { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == + WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + iterations++; + if (iterations > itmax - 1 && debug_model == FALSE + && pr.logfile == TRUE) + { + set_forward_output_to_log(TRUE); + debug_model = TRUE; + } + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nIteration %d\tStep_size = %f\n", iterations, + (double) step_size_now)); + output_msg(sformatf( "\t\tPe_step_size = %f\n\n", + (double) pe_step_size_now)); + } + /* + * Iterations exceeded + */ + if (iterations > itmax) + { + error_string = sformatf( "Maximum iterations exceeded, %d\n", + itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + /* + * Calculate jacobian + */ + gammas_pz(); + jacobian_sums(); + jacobian_pz(); + /* + * Full matrix with pure phases + */ + if (r == OK || remove_unstable_phases == TRUE) + { + return_kode = ineq(l_kode); + if (return_kode != OK) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + } + log_msg(sformatf( "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + count_infeasible++; + } + if (return_kode == 2) + { + ineq(0); + } + reset(); + } + gammas_pz(); + if (full_pitzer == TRUE) + pitzer(); + if (always_full_pitzer == TRUE) + { + full_pitzer = TRUE; + } + else + { + full_pitzer = FALSE; + } + molalities(TRUE); + if (use.Get_surface_ptr() != NULL && + use.Get_surface_ptr()->dl_type != NO_DL && + use.Get_surface_ptr()->related_phases == TRUE) + initial_surface_water(); + mb_sums(); + mb_gases(); + mb_s_s(); + /* debug + species_list_sort(); + sum_species(); + print_species(); + print_exchange(); + print_surface(); + */ + if (stop_program == TRUE) + { + break; + } + } +/* + * Check for stop_program + */ + + if (stop_program == TRUE) + { + break; + } + if (check_residuals() == ERROR) + { + stop_program = TRUE; + break; + } + /* remove_unstable_phases is set in check_residuals */ + if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE + && mass_water_switch == TRUE) + { + log_msg(sformatf( + "\nChanging water switch to FALSE. Iteration %d.\n", + iterations)); + mass_water_switch = FALSE; + continue; + } + gamma_iterations++; + if (gamma_iterations > itmax) + { + error_string = sformatf( "Maximum gamma iterations exceeded, %d\n", + itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + if (check_gammas_pz() != TRUE) + { + full_pitzer = TRUE; + continue; + } + if (remove_unstable_phases == FALSE) + break; + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nNumber of infeasible solutions: %d\n", + count_infeasible)); + log_msg(sformatf( "Number of basis changes: %d\n\n", + count_basis_change)); + log_msg(sformatf( "Number of iterations: %d\n\n", iterations)); + debug_model = debug_model_save; + set_forward_output_to_log(FALSE); + if (stop_program == TRUE) + { + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_gammas_pz(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE old_aw, old_mu, tol; + int converge, i; + + old_mu = mu_x; + old_aw = s_h2o->la; + pitzer(); + molalities(TRUE); + mb_sums(); + converge = TRUE; + tol = convergence_tolerance * 10.; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PITZER_GAMMA) + continue; + if (fabs(x[i]->s->lg - x[i]->s->lg_pitzer) > tol) + { + converge = FALSE; + } + } + if (fabs(old_mu - mu_x) > 1e-3 * mu_x) + { + same_model = false; + k_temp(tc_x, patm_x); + } + if (fabs(old_mu - mu_x) > tol) + converge = FALSE; + if ((pow((LDBLE) 10.0, s_h2o->la) - AW) > tol) + converge = FALSE; + return converge; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +gammas_pz() +/* ---------------------------------------------------------------------- */ +{ +/* + * Need exchange gammas for pitzer + */ + int i, j; + LDBLE coef; + /* Initialize */ +/* + * Calculate activity coefficients + */ + for (i = 0; i < count_s_x; i++) + { + switch (s_x[i]->gflag) + { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + break; + case 4: /* Exchange */ + /* Now calculated in next loop */ + break; + case 5: /* Always 1.0 */ + break; + case 6: /* Surface */ +/* + * Find moles of sites. + * s_x[i]->equiv is stoichiometric coefficient of sites in species + */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == SURF) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->alk > 0) + { + s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); + s_x[i]->dg = 0.0; + } + else + { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + break; + case 7: /* LLNL */ + break; + case 8: /* LLNL CO2 */ + break; + case 9: /* activity water */ + s_x[i]->lg = log10(exp(s_h2o->la * LOG_10) * gfw_water); + s_x[i]->dg = 0.0; + break; + } +/* + if (mu_unknown != NULL) { + if (fabs(residual[mu_unknown->number]) > 0.1 && + fabs(residual[mu_unknown->number])/mu_x > 0.5) { + s_x[i]->dg = 0.0; + } + } + */ + } + /* + * calculate exchange gammas + */ + + if (use.Get_exchange_ptr() != NULL) + { + for (i = 0; i < count_s_x; i++) + { + switch (s_x[i]->gflag) + { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + case 5: /* Always 1.0 */ + case 6: /* Surface */ + case 7: /* LLNL */ + case 8: /* LLNL CO2 */ + case 9: /* activity water */ + break; + case 4: /* Exchange */ + + /* + * Find CEC + * z contains valence of cation for exchange species, alk contains cec + */ + /* !!!!! */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == EX) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown-> + moles; + break; + } + } + /* + * Master species is a dummy variable with meaningless activity and mass + */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + if (s_x[i]->primary != NULL) + { + break; + } + /* + * All other species + */ + + /* modific 29 july 2005... */ + if (s_x[i]->equiv != 0 && s_x[i]->alk > 0) + { + s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + } + //if (use.Get_exchange_ptr()->pitzer_exchange_gammas == TRUE) + if (((cxxExchange *) use.Get_exchange_ptr())->Get_pitzer_exchange_gammas()) + { + /* Assume equal gamma's of solute and exchangeable species... */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == EX) + continue; + coef = s_x[i]->rxn_x->token[j].coef; + s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg; + s_x[i]->dg += coef * s_x[i]->rxn_x->token[j].s->dg; + } + } + } + } + } +/* ...end modific 29 july 2005 */ + + return (OK); +} diff --git a/rename_cpp/pitzer_structures.cpp b/rename_cpp/pitzer_structures.cpp new file mode 100644 index 00000000..6414089e --- /dev/null +++ b/rename_cpp/pitzer_structures.cpp @@ -0,0 +1,306 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + + +/* ********************************************************************** + * + * Routines related to structure "pitz_param" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pitz_param * Phreeqc:: +pitz_param_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct pitz_param *pitz_param_ptr; + pitz_param_ptr = + (struct pitz_param *) PHRQ_malloc(sizeof(struct pitz_param)); + if (pitz_param_ptr == NULL) + malloc_error(); + return (pitz_param_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitz_param_init(struct pitz_param *pitz_param_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Frees all data associated with pitz_param structure. + */ + + if (pitz_param_ptr == NULL) + return (ERROR); + pitz_param_ptr->species[0] = NULL; + pitz_param_ptr->species[1] = NULL; + pitz_param_ptr->species[2] = NULL; + pitz_param_ptr->ispec[0] = -1; + pitz_param_ptr->ispec[1] = -1; + pitz_param_ptr->ispec[2] = -1; + pitz_param_ptr->type = TYPE_Other; + pitz_param_ptr->p = 0.0; + pitz_param_ptr->U.b0 = 0.0; + for (i = 0; i < 6; i++) + { + pitz_param_ptr->a[i] = 0.0; + } + pitz_param_ptr->alpha = 0.0; + pitz_param_ptr->thetas = NULL; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct pitz_param * Phreeqc:: +pitz_param_read(char *string, int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read pitzer parameter info from string + * n is number of species (character values) + * + */ + int l, i, j, k; + char *ptr; + char token[2 * MAX_LENGTH]; + struct pitz_param pzp, *pzp_ptr; + + if (n != 2 && n != 3) + return (NULL); + if (string == NULL) + return (NULL); + + pitz_param_init(&pzp); + ptr = string; + if (copy_token(token, &ptr, &l) == EMPTY) + return (NULL); + ptr = string; + for (i = 0; i < n; i++) + { + if (copy_token(token, &ptr, &l) == EMPTY) + return (NULL); + pzp.species[i] = string_hsave(token); + } + k = 0; + for (i = 0; i < 6; i++) + { + if (copy_token(token, &ptr, &l) == EMPTY) + break; + j = sscanf(token, SCANFORMAT, &pzp.a[i]); + if (j <= 0) + break; + k++; + } + if (k <= 0) + return (NULL); + pzp_ptr = pitz_param_duplicate(&pzp); + return (pzp_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct pitz_param * Phreeqc:: +pitz_param_duplicate(struct pitz_param *old_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space and makes duplicate copy of pitz_param structure + */ + struct pitz_param *new_ptr; + + new_ptr = pitz_param_alloc(); + pitz_param_init(new_ptr); +/* + * Copy data + */ + pitz_param_copy(old_ptr, new_ptr); + return (new_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies pitz_param data from old_ptr to new location, new_ptr. + * Space for the new_ptr structure must already be malloced. + */ +/* + * Store data for structure pitz_param + */ + memcpy(new_ptr, old_ptr, sizeof(struct pitz_param)); + return (OK); +} + +#include +#include +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitz_param_search(struct pitz_param *pzp_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search of pitz_params for same type and species + * Returns -1 if not found, index number in pitz_params if found + */ + int i; + if (pzp_ptr == NULL) + return -1; + if (pzp_ptr->type == TYPE_Other) + return -1; + + std::list new_parm; + + for (i = 0; i < 3; i++) + { + if (pzp_ptr->species[i] != NULL) new_parm.push_back(pzp_ptr->species[i]); + } + new_parm.sort(); + + for (i = 0; i < count_pitz_param; i++) + { + if (pitz_params[i]->type != pzp_ptr->type) continue; + std::list old_parm; + int j; + for (j = 0; j < 3; j++) + { + if (pitz_params[i]->species[j] != NULL) old_parm.push_back(pitz_params[i]->species[j]); + } + old_parm.sort(); + if (old_parm.size() != new_parm.size()) continue; + bool found = true; + std::list::iterator nit = new_parm.begin(); + std::list::iterator oit = old_parm.begin(); + while (nit != new_parm.end()) + { + if (*nit != *oit) + { + found = false; + break; + } + nit++; + oit++; + } + if (found) break; + } + if (i >= count_pitz_param) + { + return -1; + } + return i; +} + + +#include +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_param_search(struct pitz_param *pzp_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search of pitz_params for same type and species + * Returns -1 if not found, index number in pitz_params if found + */ + int i; + if (pzp_ptr == NULL) + return -1; + if (pzp_ptr->type == TYPE_Other) + return -1; + + std::list new_parm; + + for (i = 0; i < 3; i++) + { + if (pzp_ptr->species[i] != NULL) new_parm.push_back(pzp_ptr->species[i]); + } + new_parm.sort(); + + for (i = 0; i < count_sit_param; i++) + { + if (sit_params[i]->type != pzp_ptr->type) continue; + std::list old_parm; + int j; + for (j = 0; j < 3; j++) + { + if (sit_params[i]->species[j] != NULL) old_parm.push_back(sit_params[i]->species[j]); + } + old_parm.sort(); + if (old_parm.size() != new_parm.size()) continue; + bool found = true; + std::list::iterator nit = new_parm.begin(); + std::list::iterator oit = old_parm.begin(); + while (nit != new_parm.end()) + { + if (*nit != *oit) + { + found = false; + break; + } + nit++; + oit++; + } + if (found) break; + } + if (i >= count_sit_param) + { + return -1; + } + return i; +} + +/* ********************************************************************** + * + * Routines related to structure "theta_parm" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct theta_param * Phreeqc:: +theta_param_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct theta_param *theta_param_ptr; + theta_param_ptr = + (struct theta_param *) PHRQ_malloc(sizeof(struct theta_param)); + if (theta_param_ptr == NULL) + malloc_error(); + return (theta_param_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +theta_param_init(struct theta_param *theta_param_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data associated with theta_param structure. + */ + + if (theta_param_ptr == NULL) + return (ERROR); + theta_param_ptr->zj = 0; + theta_param_ptr->zk = 0; + theta_param_ptr->etheta = 0; + theta_param_ptr->ethetap = 0; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct theta_param * Phreeqc:: +theta_param_search(LDBLE zj, LDBLE zk) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search of theta_params for same charge + * Returns NULL if not found, index number in theta_params if found + */ + int i; + for (i = 0; i < count_theta_param; i++) + { + if ((theta_params[i]->zj == zj && theta_params[i]->zk == zk) || + (theta_params[i]->zj == zk && theta_params[i]->zk == zj)) + { + return theta_params[i]; + } + } + return NULL; +} diff --git a/rename_cpp/prep.cpp b/rename_cpp/prep.cpp new file mode 100644 index 00000000..72f604fb --- /dev/null +++ b/rename_cpp/prep.cpp @@ -0,0 +1,6663 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include +#include +#include "Exchange.h" +#include "GasPhase.h" +#include "PPassemblage.h" +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +prep(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input is model defined by the structure use. + * Most of routine is skipped if model, as defined by master.total + * plus use.pure_phases, is same as previous calculation. + * Routine sets up struct unknown for each unknown. + * Determines elements, species, and phases that are in the model. + * Calculates mass-action equations for each species and phase. + * Routine builds a set of lists for calculating mass balance and + * for building jacobian. + */ + struct solution *solution_ptr; + + if (state >= REACTION) + { + same_model = check_same_model(); + } + else + { + same_model = FALSE; + last_model.force_prep = TRUE; + } + /*same_model = FALSE; */ +/* + * Initialize s, master, and unknown pointers + */ + solution_ptr = use.Get_solution_ptr(); + if (solution_ptr == NULL) + { + error_msg("Solution needed for calculation not found, stopping.", + STOP); + } + description_x = (char *) free_check_null(description_x); + description_x = string_duplicate(solution_ptr->description); +/* + * Allocate space for unknowns + * Must allocate all necessary space before pointers to + * X are set. + */ + + if (!same_model && !switch_numerical) + numerical_fixed_volume = false; + if (same_model == FALSE || switch_numerical) + { + clear(); + setup_unknowns(); +/* + * Set unknown pointers, unknown types, validity checks + */ + if (state == INITIAL_SOLUTION) + convert_units(solution_ptr); + setup_solution(); + setup_exchange(); + setup_surface(); + setup_pure_phases(); + setup_gas_phase(); + setup_ss_assemblage(); + setup_related_surface(); + setup_slack(); + tidy_redox(); + if (get_input_errors() > 0) + { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Allocate space for array + */ +/* + array = (LDBLE *) PHRQ_malloc( (size_t) (count_unknowns+1) * count_unknowns * sizeof( LDBLE )); + if (array == NULL) malloc_error(); + delta = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); + if (delta == NULL) malloc_error(); + residual = (LDBLE *) PHRQ_malloc( (size_t) count_unknowns * sizeof( LDBLE )); + if (residual == NULL) malloc_error(); +*/ + array = + (LDBLE *) PHRQ_malloc((size_t) (max_unknowns + 1) * + max_unknowns * sizeof(LDBLE)); + if (array == NULL) + malloc_error(); + delta = (LDBLE *) PHRQ_malloc((size_t) max_unknowns * sizeof(LDBLE)); + if (delta == NULL) + malloc_error(); + residual = + (LDBLE *) PHRQ_malloc((size_t) max_unknowns * sizeof(LDBLE)); + if (residual == NULL) + malloc_error(); + for (int j = 0; j < max_unknowns; j++) + { + residual[j] = 0; + } + +/* + * Build lists to fill Jacobian array and species list + */ + build_model(); + adjust_setup_pure_phases(); + adjust_setup_solution(); + } + else + { +/* + * If model is same, just update masses, don't rebuild unknowns and lists + */ + quick_setup(); + } + if (get_input_errors() > 0) + { + error_msg("Program stopping due to input errors.", STOP); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +quick_setup(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine is used if model is the same as previous model + * Assumes moles of elements, exchangers, surfaces, gases, and solid solutions have + * been accumulated in array master, usually by subroutine step. + * Updates essential information for the model. + */ + int i, j, k, l; + char token[MAX_LENGTH], name[MAX_LENGTH]; + + for (i = 0; i < count_master; i++) + { + if (master[i]->s->type == SURF_PSI) + continue; + if (master[i]->s == s_eminus || + master[i]->s == s_hplus || + master[i]->s == s_h2o || master[i]->s == s_h2 + || master[i]->s == s_o2) + continue; + if (master[i]->total > 0) + { + if (master[i]->s->secondary != NULL) + { + master[i]->s->secondary->unknown->moles = master[i]->total; + } + else + { + master[i]->unknown->moles = master[i]->total; + } + } + } +/* + * Reaction: pH for charge balance + */ + ph_unknown->moles = use.Get_solution_ptr()->cb; +/* + * Reaction: pe for total hydrogen + */ + if (mass_hydrogen_unknown != NULL) + { +/* Use H - 2O linear combination in place of H */ +#define COMBINE + /*#define COMBINE_CHARGE */ +#ifdef COMBINE + mass_hydrogen_unknown->moles = + use.Get_solution_ptr()->total_h - 2 * use.Get_solution_ptr()->total_o; +#else + mass_hydrogen_unknown->moles = use.Get_solution_ptr()->total_h; +#endif + } +/* + * Reaction H2O for total oxygen + */ + if (mass_oxygen_unknown != NULL) + { + mass_oxygen_unknown->moles = use.Get_solution_ptr()->total_o; + } + +/* + * pp_assemblage + */ + j = 0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == PP) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); + cxxPPassemblageComp * comp_ptr = &(it->second); + + x[i]->moles = comp_ptr->Get_moles(); + /* A. Crapsi */ + x[i]->si = comp_ptr->Get_si(); + x[i]->delta = comp_ptr->Get_delta(); + /* End A. Crapsi */ + x[i]->dissolve_only = comp_ptr->Get_dissolve_only() ? TRUE : FALSE; + comp_ptr->Set_delta(0.0); + } + } + // Need to update SIs for gases + adjust_setup_pure_phases(); + +/* + * gas phase + */ + if (gas_unknown != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if ((gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) && + numerical_fixed_volume && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume)) + { + //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + //{ + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + //int k; + //struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + gas_unknowns[i]->moles = gc_ptr->Get_moles(); + if (gas_unknowns[i]->moles <= 0) + gas_unknowns[i]->moles = MIN_TOTAL; + gas_unknowns[i]->phase->pr_in = false; + gas_unknowns[i]->phase->pr_phi = 1.0; + gas_unknowns[i]->phase->pr_p = 0; + //gas_unknowns[i]->gas_phase = use.Get_gas_phase_ptr(); + } + same_pressure = FALSE; + } + else + { + gas_unknown->moles = 0.0; + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + gas_unknown->moles += gc_ptr->Get_moles(); + } + if (gas_unknown->moles <= 0) + gas_unknown->moles = MIN_TOTAL; + gas_unknown->ln_moles = log(gas_unknown->moles); + //gas_unknown->gas_phase = gas_phase_ptr; + } + } + +/* + * ss_assemblage + */ + if (s_s_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == S_S_MOLES) + break; + } + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (k = 0; k < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; k++) + { + x[i]->s_s = &(use.Get_ss_assemblage_ptr()->s_s[j]); + x[i]->s_s_comp = &(use.Get_ss_assemblage_ptr()->s_s[j].comps[k]); + x[i]->s_s_comp_number = j; + x[i]->moles = x[i]->s_s_comp->moles; + if (x[i]->moles <= 0) + { + x[i]->moles = MIN_TOTAL_SS; + x[i]->s_s_comp->moles = MIN_TOTAL_SS; + } + x[i]->s_s_comp->initial_moles = x[i]->moles; + x[i]->ln_moles = log(x[i]->moles); + + x[i]->phase->dn = x[i]->s_s_comp->dn; + x[i]->phase->dnb = x[i]->s_s_comp->dnb; + x[i]->phase->dnc = x[i]->s_s_comp->dnc; + x[i]->phase->log10_fraction_x = + x[i]->s_s_comp->log10_fraction_x; + x[i]->phase->log10_lambda = x[i]->s_s_comp->log10_lambda; + i++; + } + } + } +/* + * exchange + */ + // number of moles is set from master->moles above +/* + * surface + */ + if (use.Get_surface_ptr() != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE) + { + break; + } + } + j = 0; + k = 0; + for (; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE_CB) + { + x[i]->surface_charge = &(use.Get_surface_ptr()->charge[j]); + x[i]->related_moles = x[i]->surface_charge->grams; + x[i]->mass_water = use.Get_surface_ptr()->charge[j++].mass_water; + x[i]->surface_comp = x[i - 1]->surface_comp; + + /* test that charge and surface match */ + char * temp_formula = string_duplicate(x[i]->surface_comp->formula); + char * ptr = temp_formula; + copy_token(token, &ptr, &l); + char * ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + ptr1[0] = '\0'; + if (strcmp(name, x[i]->surface_charge->name) != 0) + { + free_check_null(temp_formula); + error_string = sformatf( + "Internal error: Surface charge name %s does not match surface component name %s\nTry alphabetical order for surfaces in SURFACE", + x[i]->surface_charge->name, + x[i]->surface_comp->formula); + error_msg(error_string, STOP); + } + free_check_null(temp_formula); + + /* moles picked up from master->total */ + } + else if (x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) + { + /* + charge = use.Get_surface_ptr()->comps[i].charge; + x[count_unknowns]->surface_charge = &use.Get_surface_ptr()->charge[charge]; + */ + x[i]->surface_charge = x[i - 1]->surface_charge; + x[i]->related_moles = x[i]->surface_charge->grams; + x[i]->mass_water = x[i]->surface_charge->mass_water; + } + else if (x[i]->type == SURFACE) + { + x[i]->surface_comp = &(use.Get_surface_ptr()->comps[k++]); + /* moles picked up from master->total + except for surfaces related to kinetic minerals ... */ + if (x[i]->surface_comp->rate_name != NULL) + { + for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; + l++) + { + if (x[i]->surface_comp->totals[l].elt->master->type != + SURF) + continue; + if (strcmp_nocase + (x[i]->description, + x[i]->surface_comp->totals[l].elt->name) == 0) + { + x[i]->moles = x[i]->surface_comp->totals[l].coef; + /* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + } + } + } + } + else + { + break; + } + + } + } + save_model(); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * sum of partial pressures equation and + * mass balance equations for elements contained in gases + */ + //int i, j; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + //struct gas_comp *gas_comp_ptr; + //struct phase *phase_ptr; + struct unknown *unknown_ptr; + LDBLE coef, coef_elt; + + if (gas_unknown == NULL) + return (OK); + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && + numerical_fixed_volume) + { + return build_fixed_volume_gas(); + } + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + assert(phase_ptr); +/* + * Determine elements in gas component + */ + count_elts = 0; + paren_count = 0; + if (phase_ptr->rxn_x == NULL) + continue; + add_elt_list(phase_ptr->next_elt, 1.0); +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif +/* + * Build mass balance sums for each element in gas + */ + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tMass balance summations %s.\n\n", + phase_ptr->name)); + } + + /* All elements in gas */ + for (int j = 0; j < count_elts; j++) + { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name, "H") == 0) + { + unknown_ptr = mass_hydrogen_unknown; + } + else if (strcmp(elt_list[j].elt->name, "O") == 0) + { + unknown_ptr = mass_oxygen_unknown; + } + else + { + if (elt_list[j].elt->primary->in == TRUE) + { + unknown_ptr = elt_list[j].elt->primary->unknown; + } + else if (elt_list[j].elt->primary->s->secondary != NULL) + { + unknown_ptr = + elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr != NULL) + { + coef = elt_list[j].coef; + store_mb(&(phase_ptr->moles_x), &(unknown_ptr->f), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\n", + unknown_ptr->description, (double) coef)); + } + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* Total pressure of gases */ + store_mb(&(phase_ptr->p_soln_x), &(gas_unknown->f), 1.0); + } +/* + * Build jacobian sums for mass balance equations + */ + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tJacobian summations %s.\n\n", + phase_ptr->name)); + } + for (int j = 0; j < count_elts; j++) + { + unknown_ptr = NULL; + if (strcmp(elt_list[j].elt->name, "H") == 0) + { + unknown_ptr = mass_hydrogen_unknown; + } + else if (strcmp(elt_list[j].elt->name, "O") == 0) + { + unknown_ptr = mass_oxygen_unknown; + } + else + { + if (elt_list[j].elt->primary->in == TRUE) + { + unknown_ptr = elt_list[j].elt->primary->unknown; + } + else if (elt_list[j].elt->primary->s->secondary != NULL) + { + unknown_ptr = + elt_list[j].elt->primary->s->secondary->unknown; + } + } + if (unknown_ptr == NULL) + { + continue; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\t%s.\n", + unknown_ptr->description)); + } + row = unknown_ptr->number * (count_unknowns + 1); + coef_elt = elt_list[j].coef; + for (rxn_ptr = phase_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL) + { + error_string = sformatf( + "Element needed for gas component, %s, is not in model.", + phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + continue; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%s\n", + master_ptr->s->name)); + } + if (master_ptr->unknown == NULL) + { + continue; + } + if (master_ptr->in == FALSE) + { + error_string = sformatf( + "Element, %s, in phase, %s, is not in model.", + master_ptr->elt->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + col = master_ptr->unknown->number; + coef = coef_elt * rxn_ptr->coef; + store_jacob(&(phase_ptr->moles_x), + &(array[row + col]), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + master_ptr->s->name, (double) coef, + row / (count_unknowns + 1), col)); + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* derivative wrt total moles of gas */ + store_jacob(&(phase_ptr->fraction_x), + &(array[row + gas_unknown->number]), coef_elt); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + "gas moles", (double) elt_list[j].coef, + row / (count_unknowns + 1), + gas_unknown->number)); + } + } + } +/* + * Build jacobian sums for sum of partial pressures equation + */ + if (gas_phase_ptr->Get_type() != cxxGasPhase::GP_PRESSURE) + continue; + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tPartial pressure eqn %s.\n\n", + phase_ptr->name)); + } + unknown_ptr = gas_unknown; + row = unknown_ptr->number * (count_unknowns + 1); + for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) + { + if (rxn_ptr->s != s_eminus && rxn_ptr->s->in == FALSE) + { + error_string = sformatf( + "Element in species, %s, in phase, %s, is not in model.", + rxn_ptr->s->name, phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + } + else + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + + if (master_ptr == NULL) + { + error_string = sformatf( + "Master species for %s, in phase, %s, is not in model.", + rxn_ptr->s->name, phase_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%s\n", master_ptr->s->name)); + } + if (master_ptr->unknown == NULL) + { + assert(false); + continue; + } + if (master_ptr->in == FALSE) + { + error_string = sformatf( + "Element, %s, in phase, %s, is not in model.", + master_ptr->elt->name, phase_ptr->name); + warning_msg(error_string); + //error_msg(error_string, CONTINUE); + //input_error++; + } + col = master_ptr->unknown->number; + coef = rxn_ptr->coef; + store_jacob(&(phase_ptr->p_soln_x), &(array[row + col]), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + master_ptr->s->name, (double) coef, + row / (count_unknowns + 1), col)); + } + } + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * mass action equation for component + * mass balance equations for elements contained in solid solutions + */ + int i, j, k, l, stop; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + struct s_s *s_s_ptr, *s_s_ptr_old; + char token[MAX_LENGTH]; + char *ptr; + + if (s_s_unknown == NULL) + return (OK); + s_s_ptr_old = NULL; + col = 0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != S_S_MOLES) + continue; + s_s_ptr = x[i]->s_s; + if (s_s_ptr != s_s_ptr_old) + { + col = x[i]->number; + s_s_ptr_old = s_s_ptr; + } +/* + * Calculate function value (inverse saturation index) + */ + if (x[i]->phase->rxn_x == NULL) + continue; + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + /* include mole fraction */ + store_mb(&(x[i]->phase->log10_fraction_x), &(x[i]->f), 1.0); + + /* include activity coeficient */ + store_mb(&(x[i]->phase->log10_lambda), &(x[i]->f), 1.0); +/* + * Put coefficients into mass action equations + */ + /* first IAP terms */ + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) + continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, + rxn_ptr->coef); + } + + if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) + { +/* + * For binary solid solution + */ + /* next dnc terms */ + row = x[i]->number * (count_unknowns + 1); + if (x[i]->s_s_comp_number == 0) + { + col = x[i]->number; + } + else + { + col = x[i]->number - 1; + } + store_jacob(&(x[i]->phase->dnc), &(array[row + col]), -1); + + /* next dnb terms */ + col++; + store_jacob(&(x[i]->phase->dnb), &(array[row + col]), -1); + } + else + { +/* + * For ideal solid solution + */ + row = x[i]->number * (count_unknowns + 1); + for (j = 0; j < s_s_ptr->count_comps; j++) + { + if (j != x[i]->s_s_comp_number) + { +/* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ + store_jacob(&(x[i]->phase->dn), &(array[row + col + j]), + -1.0); + } + else + { + store_jacob(&(x[i]->phase->dnb), &(array[row + col + j]), + -1.0); + } + } + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + strcpy(token, x[i]->phase->formula); + ptr = token; + get_elts_in_species(&ptr, 1.0); +/* + * Go through elements in phase + */ +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (j = 0; j < count_elts; j++) + { + + if (strcmp(elt_list[j].elt->name, "H") == 0 + && mass_hydrogen_unknown != NULL) + { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, + elt_list[j].coef); + + } + else if (strcmp(elt_list[j].elt->name, "O") == 0 + && mass_oxygen_unknown != NULL) + { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, + elt_list[j].coef); + + } + else + { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element in phase, %s, is not in model.", + x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) + { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } + else if (master_ptr->in == TRUE) + { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, + elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } + else if (master_ptr->in == REWRITE) + { + stop = FALSE; + for (k = 0; k < count_unknowns; k++) + { + if (x[k]->type != MB) + continue; + for (l = 0; x[k]->master[l] != NULL; l++) + { + if (x[k]->master[l] == master_ptr) + { + store_jacob0(x[k]->master[0]->unknown-> + number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], + &x[k]->master[0]->unknown-> + delta, elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) + break; + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_jacobian_sums(int k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function builds lists sum_jacob1 and sum_jacob2 that describe how to sum molalities + * to form jacobian. + */ + int i, j, kk; + int count_g; + LDBLE coef; + LDBLE *source, *target; + + if (debug_prep == TRUE) + output_msg(sformatf( "\n\tJacobian summations.\n")); +/* + * Calculate jacobian coefficients for each mass balance equation + */ + for (i = 0; i < count_mb_unknowns; i++) + { +/* + * Store d(moles) for a mass balance equation + */ + /* initial solution only */ + if (mb_unknowns[i].unknown->type == SOLUTION_PHASE_BOUNDARY) + { + continue; + } + coef = mb_unknowns[i].coef; + if (debug_prep == TRUE) + output_msg(sformatf( "\n\tMass balance eq: %s\t%f\n", + mb_unknowns[i].unknown->description, (double) coef)); + store_dn(k, mb_unknowns[i].source, mb_unknowns[i].unknown->number, + coef, mb_unknowns[i].gamma_source); +/* + * Add extra terms for change in dg/dx in diffuse layer model + */ + if (s[k]->type >= H2O || dl_type_x == NO_DL) + { + continue; + } + else if ((mb_unknowns[i].unknown->type == MB || + mb_unknowns[i].unknown->type == MH || + mb_unknowns[i].unknown->type == MH2O) && state >= REACTION) + { + if (mass_oxygen_unknown != NULL) + { + /* term for water, sum of all surfaces */ + source = &s[k]->tot_dh2o_moles; + target = + &(array + [mb_unknowns[i].unknown->number * (count_unknowns + 1) + + mass_oxygen_unknown->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + "sum[dn(i,s)/dlnwater]", (double) coef, + mb_unknowns[i].unknown->number, + mass_oxygen_unknown->number)); + } + } + + /* terms for psi, one for each surface */ + count_g = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + /*if (x[j]->type < SURFACE_CB || x[j]->type > SURFACE_CB1) continue; */ + source = &s[k]->diff_layer[count_g].dx_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + x[j]->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + "dg/dlny", (double) coef, + mb_unknowns[i].unknown->number, x[j]->number)); + } + count_g++; + if (count_g >= use.Get_surface_ptr()->count_charge) + break; + } + + /* terms for related phases */ + count_g = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + /*if (x[j]->type < SURFACE_CB || x[j]->type > SURFACE_CB1) continue; */ + + /* has related phase */ + if (x[j - 1]->surface_comp->phase_name == NULL) + continue; + + /* now find the related phase */ + for (kk = count_unknowns - 1; kk >= 0; kk--) + { + if (x[kk]->type != PP) + continue; + if (x[kk]->phase->name == + x[j - 1]->surface_comp->phase_name) + break; + } + + if (kk >= 0) + { + source = &s[k]->diff_layer[count_g].drelated_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + x[kk]->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( + "\t\t%-24s%10.3f\t%d\t%d\n", "dphase", + (double) coef, + mb_unknowns[i].unknown->number, + x[kk]->number)); + } + } + count_g++; + if (count_g >= use.Get_surface_ptr()->count_charge) + break; + } + + } + else if (mb_unknowns[i].unknown->type == SURFACE_CB) + { + count_g = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + if (mb_unknowns[i].unknown->number == x[j]->number) + { + source = &s[k]->diff_layer[count_g].dx_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + x[j]->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( + "\t\t%-24s%10.3f\t%d\t%d\n", "dg/dlny", + (double) coef, + mb_unknowns[i].unknown->number, + x[j]->number)); + } + + /* term for related phase */ + /* has related phase */ + if (x[j - 1]->surface_comp->phase_name != NULL) + { + + /* now find the related phase */ + for (kk = count_unknowns - 1; kk >= 0; kk--) + { + if (x[kk]->type != PP) + continue; + if (x[kk]->phase->name == + x[j - 1]->surface_comp->phase_name) + break; + } + if (kk >= 0) + { + source = + &s[k]->diff_layer[count_g].drelated_moles; + target = + &(array + [mb_unknowns[i].unknown->number * + (count_unknowns + 1) + x[kk]->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( + "\t\t%-24s%10.3f\t%d\t%d\n", + "dphase", (double) coef, + mb_unknowns[i].unknown->number, + x[kk]->number)); + } + } + } + + if (mass_oxygen_unknown != NULL) + { + /* term for water, for same surfaces */ + source = &s[k]->diff_layer[count_g].dh2o_moles; + target = &(array[mb_unknowns[i].unknown->number * + (count_unknowns + 1) + + mass_oxygen_unknown->number]); + store_jacob(source, target, coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( + "\t\t%-24s%10.3f\t%d\t%d\n", + "dn(i,s)/dlnwater", (double) coef, + mb_unknowns[i].unknown->number, + mass_oxygen_unknown->number)); + } + } + break; + } + count_g++; + if (count_g >= use.Get_surface_ptr()->count_charge) + break; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_mb_sums(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function builds lists sum_mb1 and sum_mb2 that describe how to sum molalities + * to calculate mass balance sums, including activity of water, ionic strength, + * charge balance, and alkalinity. + */ + int i; + LDBLE *target; +/* + * Make space for lists + */ + if (count_sum_mb1 + count_mb_unknowns >= max_sum_mb1) + { + space((void **) ((void *) &sum_mb1), + count_sum_mb1 + count_mb_unknowns, &max_sum_mb1, + sizeof(struct list1)); + } + if (count_sum_mb2 + count_mb_unknowns >= max_sum_mb2) + { + space((void **) ((void *) &sum_mb2), + count_sum_mb2 + count_mb_unknowns, &max_sum_mb2, + sizeof(struct list2)); + } + + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tMass balance summations.\n\n")); + } + for (i = 0; i < count_mb_unknowns; i++) + { + target = &(mb_unknowns[i].unknown->f); + store_mb(mb_unknowns[i].source, target, mb_unknowns[i].coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\n", + mb_unknowns[i].unknown->description, + (double) mb_unknowns[i].coef)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Guts of prep. Determines species in model, rewrites equations, + * builds lists for mass balance and jacobian sums. + */ + int i, j, j0, k; + LDBLE coef_e; + + if (s_hplus == NULL || s_eminus == NULL || s_h2o == NULL) + { + error_msg("Data base is missing H+, H2O, or e- species.", CONTINUE); + input_error++; + } +/* + * Make space for lists of pointers to species in the model + */ + + max_s_x = MAX_S; + space((void **) ((void *) &s_x), INIT, &max_s_x, + sizeof(struct species *)); + + max_sum_mb1 = MAX_SUM_MB; + count_sum_mb1 = 0; + space((void **) ((void *) &sum_mb1), INIT, &max_sum_mb1, + sizeof(struct list1)); + + max_sum_mb2 = MAX_SUM_MB; + count_sum_mb2 = 0; + space((void **) ((void *) &sum_mb2), INIT, &max_sum_mb2, + sizeof(struct list2)); + + max_sum_jacob0 = MAX_SUM_JACOB0; + count_sum_jacob0 = 0; + space((void **) ((void *) &sum_jacob0), INIT, &max_sum_jacob0, + sizeof(struct list0)); + + max_sum_jacob1 = MAX_SUM_JACOB1; + count_sum_jacob1 = 0; + space((void **) ((void *) &sum_jacob1), INIT, &max_sum_jacob1, + sizeof(struct list1)); + + max_sum_jacob2 = MAX_SUM_JACOB2; + count_sum_jacob2 = 0; + space((void **) ((void *) &sum_jacob2), INIT, &max_sum_jacob2, + sizeof(struct list2)); + + + max_sum_delta = MAX_SUM_JACOB0; + count_sum_delta = 0; + space((void **) ((void *) &sum_delta), INIT, &max_sum_delta, + sizeof(struct list2)); + + max_species_list = 5 * MAX_S; + count_species_list = 0; + species_list = (struct species_list *) free_check_null(species_list); + space((void **) ((void *) &species_list), INIT, &max_species_list, + sizeof(struct species_list)); + +/* + * Pick species in the model, determine reaction for model, build jacobian + */ + count_s_x = 0; + compute_gfw("H2O", &gfw_water); + gfw_water *= 0.001; + for (i = 0; i < count_s; i++) + { + if (s[i]->type > H2O && s[i]->type != EX && s[i]->type != SURF) + continue; + s[i]->in = FALSE; + count_trxn = 0; + trxn_add(s[i]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */ +/* + * Check if species is in model + */ + s[i]->in = inout(); + if (s[i]->in == TRUE) + { + /* for isotopes, activity of water is for 1H and 16O */ + if (s[i]->gflag == 9) + { + gfw_water = 18.0 / 1000.0; + } + if (pitzer_model == FALSE && sit_model == FALSE) + s[i]->lg = 0.0; + if (count_s_x + 1 >= max_s_x) + { + space((void **) ((void *) &s_x), count_s_x + 1, + &max_s_x, sizeof(struct species *)); + } + s_x[count_s_x++] = s[i]; +/* + * Write mass action equation for current model + */ + write_mass_action_eqn_x(STOP); + if (s[i]->type == SURF) + { + add_potential_factor(); + add_cd_music_factors(i); + } + rxn_free(s[i]->rxn_x); + s[i]->rxn_x = rxn_alloc(count_trxn + 1); + trxn_copy(s[i]->rxn_x); + for (j = 0; j < 3; j++) + { + s[i]->dz[j] = s[i]->rxn_x->dz[j]; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n%s\n\tMass-action equation\n", + s[i]->name)); + trxn_print(); + } +/* + * Determine mass balance equations, build sums for mass balance, build sums for jacobian + */ + count_trxn = 0; + trxn_add(s[i]->rxn_s, 1.0, FALSE); + if (s[i]->next_secondary == NULL) + { + write_mb_eqn_x(); + } + else + { + count_elts = 0; + add_elt_list(s[i]->next_secondary, 1.0); + } + if (s[i]->type == SURF) + { + add_potential_factor(); + add_cd_music_factors(i); + add_surface_charge_balance(); + add_cd_music_charge_balances(i); + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\tElement composition\n", + trxn.token[0].s->name)); + for (j = 0; j < count_elts; j++) + { + output_msg(sformatf( "\t\t%-20s\t%10.2f\n", + elt_list[j].elt->name, + (double) elt_list[j].coef)); + } + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\n\tMass balance equation\n", + s[i]->name)); + trxn_print(); + } + if (s[i]->type < EMINUS) + { + mb_for_species_aq(i); + } + else if (s[i]->type == EX) + { + mb_for_species_ex(i); + } + else if (s[i]->type == SURF) + { + mb_for_species_surf(i); + } +#ifdef COMBINE + build_mb_sums(); +#else + if (s[i] != s_h2o) + { + build_mb_sums(); + } +#endif + if (!pitzer_model && !sit_model) + build_jacobian_sums(i); +/* + * Build list of species for summing and printing + */ + if (s[i]->next_secondary == NULL) + { + write_mb_for_species_list(i); + } + else + { + count_elts = 0; + add_elt_list(s[i]->next_secondary, 1.0); + } + build_species_list(i); + } + } + if (dl_type_x != NO_DL && (pitzer_model == TRUE || sit_model == TRUE)) + { + error_msg("-diffuse_layer option not available for Pizer or SIT model", + STOP); + } +/* + * Sum diffuse layer water into hydrogen and oxygen mass balances + */ + if (dl_type_x != NO_DL && state >= REACTION) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE_CB) + { +#ifndef COMBINE + store_mb(&(x[i]->mass_water), + &(mass_hydrogen_unknown->f), 2 / gfw_water); +#endif + if (mass_oxygen_unknown != NULL) + { + store_mb(&(x[i]->mass_water), + &(mass_oxygen_unknown->f), 1 / gfw_water); + } + } + } + } +/* + * For Pizer model add lg unknown for each aqueous species + */ + + if (pitzer_model == TRUE || sit_model == TRUE) + { + j0 = count_unknowns; + j = count_unknowns + count_s_x; + k = j0; + for (i = j0; i < j; i++) + { + if (s_x[i - j0]->type == EX) + continue; + if (s_x[i - j0]->type == SURF) + continue; + x[k]->number = k; + x[k]->type = PITZER_GAMMA; + x[k]->s = s_x[i - j0]; + x[k]->description = s_x[i - j0]->name; + k++; + count_unknowns++; + } + } +/* + * Rewrite phases to current master species + */ + for (i = 0; i < count_phases; i++) + { + count_trxn = 0; + trxn_add_phase(phases[i]->rxn_s, 1.0, FALSE); + trxn_reverse_k(); + phases[i]->in = inout(); + if (phases[i]->in == TRUE) + { +/* + * Replace e- in original equation with default redox reaction + */ + coef_e = trxn_find_coef("e-", 1); + if (equal(coef_e, 0.0, TOL) == FALSE) + { + trxn_add(pe_x[default_pe_x].rxn, coef_e, TRUE); + } +/* + * Rewrite reaction to current master species + */ + write_mass_action_eqn_x(STOP); + trxn_reverse_k(); + rxn_free(phases[i]->rxn_x); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\nPhase: %s\n", phases[i]->name)); + trxn_print(); + } + phases[i]->rxn_x = rxn_alloc(count_trxn + 1); + trxn_copy(phases[i]->rxn_x); + write_phase_sys_total(i); + } + } + build_solution_phase_boundaries(); + build_pure_phases(); + build_min_exch(); + build_min_surface(); + build_gas_phase(); + build_ss_assemblage(); +/* + * Sort species list, by master only + */ + qsort(&species_list[0], (size_t) count_species_list, + (size_t) sizeof(struct species_list), species_list_compare_master); +/* + * Save model description + */ + save_model(); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Includes calculation of inverse saturation index in sum_mb. + * Puts coefficients in iap and mass balance equations for each phase. + */ + //int i; + //int stop, j, k, l; + //char token[MAX_LENGTH]; + bool stop; + std::string token; + char *ptr; + struct master *master_ptr; + struct rxn_token *rxn_ptr; +/* + * Build into sums the logic to calculate inverse saturation indices for + * pure phases + */ + if (pure_phase_unknown == NULL) + return (OK); + + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); +/* + * Calculate inverse saturation index + */ + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) + continue; + if (pure_phase_unknown == NULL) + pure_phase_unknown = x[i]; + + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + store_mb(&(x[i]->si), &(x[i]->f), 1.0); + + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + } + for (int i = 0; i < count_unknowns; i++) + { +/* + * rxn_x is null if an element in phase is not in solution + */ + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) + continue; +/* + * Put coefficients into IAP equations + */ + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) + continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, + rxn_ptr->coef); + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + if (comp_ptr->Get_add_formula().size() > 0) + { + char * char_name = string_duplicate(comp_ptr->Get_add_formula().c_str()); + ptr = char_name; + get_elts_in_species(&ptr, 1.0); + free_check_null(char_name); + } + else + { + char * char_name = string_duplicate(x[i]->phase->formula); + ptr = char_name; + get_elts_in_species(&ptr, 1.0); + free_check_null(char_name); + } +/* + * Go through elements in phase + */ + +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (int j = 0; j < count_elts; j++) + { + + if (strcmp(elt_list[j].elt->name, "H") == 0 + && mass_hydrogen_unknown != NULL) + { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, + elt_list[j].coef); + + } + else if (strcmp(elt_list[j].elt->name, "O") == 0 + && mass_oxygen_unknown != NULL) + { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, + elt_list[j].coef); + + } + else + { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element in phase, %s, is not in model.", + x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) + { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } + else if (master_ptr->in == TRUE) + { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, + elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } + else if (master_ptr->in == REWRITE) + { + stop = false; + for (int k = 0; k < count_unknowns; k++) + { + if (x[k]->type != MB) + continue; + for (int l = 0; x[k]->master[l] != NULL; l++) + { + if (x[k]->master[l] == master_ptr) + { + store_jacob0(x[k]->master[0]->unknown-> + number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], + &x[k]->master[0]->unknown-> + delta, elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) + break; + } + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Includes calculation of inverse saturation index in sum_mb. + * Puts coefficients in iap and mass balance equations for each phase. + */ + int i; + int stop, j, k, l; + char token[MAX_LENGTH]; + char *ptr; + struct master *master_ptr; + struct rxn_token *rxn_ptr; +/* + * Build into sums the logic to calculate inverse saturation indices for + * pure phases + */ + if (pure_phase_unknown == NULL) + return (OK); +/* + * Calculate inverse saturation index + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) + continue; + if (pure_phase_unknown == NULL) + pure_phase_unknown = x[i]; + + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + store_mb(&(x[i]->si), &(x[i]->f), 1.0); + + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + } + for (i = 0; i < count_unknowns; i++) + { +/* + * rxn_x is null if an element in phase is not in solution + */ + if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) + continue; +/* + * Put coefficients into IAP equations + */ + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) + continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, + rxn_ptr->coef); + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + if (x[i]->pure_phase->add_formula != NULL) + { + strcpy(token, x[i]->pure_phase->add_formula); + ptr = token; + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, x[i]->phase->formula); + ptr = token; + get_elts_in_species(&ptr, 1.0); + } +/* + * Go through elements in phase + */ + +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (j = 0; j < count_elts; j++) + { + + if (strcmp(elt_list[j].elt->name, "H") == 0 + && mass_hydrogen_unknown != NULL) + { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, + elt_list[j].coef); + + } + else if (strcmp(elt_list[j].elt->name, "O") == 0 + && mass_oxygen_unknown != NULL) + { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, + elt_list[j].coef); + + } + else + { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element in phase, %s, is not in model.", + x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) + { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } + else if (master_ptr->in == TRUE) + { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, + elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } + else if (master_ptr->in == REWRITE) + { + stop = FALSE; + for (k = 0; k < count_unknowns; k++) + { + if (x[k]->type != MB) + continue; + for (l = 0; x[k]->master[l] != NULL; l++) + { + if (x[k]->master[l] == master_ptr) + { + store_jacob0(x[k]->master[0]->unknown-> + number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], + &x[k]->master[0]->unknown-> + delta, elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) + break; + } + } + } + } + } + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_solution_phase_boundaries(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + struct rxn_token *rxn_ptr; +/* + * Build into sums the logic to calculate inverse saturation indices for + * solution phase boundaries + */ + if (solution_phase_boundary_unknown == NULL) + return (OK); +/* + * Calculate inverse saturation index + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SOLUTION_PHASE_BOUNDARY) + continue; + + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + store_mb(&(x[i]->si), &(x[i]->f), 1.0); + if (x[i]->phase->in != TRUE) + { + error_string = sformatf( + "Solution does not contain all elements for phase-boundary mineral, %s.", + x[i]->phase->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + } + if (get_input_errors() > 0) + return (ERROR); +/* + * Put coefficients into array + */ + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SOLUTION_PHASE_BOUNDARY) + continue; + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr->unknown == NULL) + continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, + rxn_ptr->coef); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_species_list(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Builds a list that includes an entry for each master species in each + * secondary reaction. Used for summing species of each element and + * printing results. + */ + int j; + struct master *master_ptr; +/* + * Check space and store reaction token name and pointer to species + */ + if (count_species_list + count_elts >= max_species_list) + { + space((void **) ((void *) &species_list), + count_species_list + count_elts, &max_species_list, + sizeof(struct species_list)); + } +/* + * Treat species made only with H+, e-, and H2O specially + */ + if (is_special(s[n]) == TRUE) + { + species_list[count_species_list].master_s = s_hplus; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = 0.0; + count_species_list++; + return (OK); + } +/* + * Treat exchange species specially + */ + if (s[n]->type == EX) + { + if (s[n]->primary != NULL) + return (OK); /* master species has zero molality */ + for (j = 0; j < count_elts; j++) + { + if (elt_list[j].elt->master->s->type != EX) + continue; + master_ptr = elt_list[j].elt->master; + species_list[count_species_list].master_s = + elt_list[j].elt->master->s; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return (OK); + } +/* + * Treat surface species specially + */ + if (s[n]->type == SURF_PSI) + return (OK); + if (s[n]->type == SURF) + { + for (j = 0; j < count_elts; j++) + { + if (elt_list[j].elt->master->s->type != SURF) + continue; + master_ptr = elt_list[j].elt->master; + species_list[count_species_list].master_s = + elt_list[j].elt->master->s; + species_list[count_species_list].s = s[n]; + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return (OK); + } +/* + * Other aqueous species + */ + for (j = 0; j < count_elts; j++) + { + if (is_special(elt_list[j].elt->master->s) == TRUE) + continue; + if (elt_list[j].elt->master->s->secondary != NULL) + { + master_ptr = elt_list[j].elt->master->s->secondary; + } + else + { + master_ptr = elt_list[j].elt->master->s->primary; + } + species_list[count_species_list].master_s = master_ptr->s; + species_list[count_species_list].s = s[n]; +/* + * Find coefficient for element represented by master species + */ + species_list[count_species_list].coef = master_ptr->coef * + elt_list[j].coef; + count_species_list++; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +clear(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Resets information for setting up a new model + */ + struct solution *solution_ptr; +/* + * Clear species solution-dependent data + */ + solution_ptr = use.Get_solution_ptr(); + + for (i = 0; i < count_s; i++) + { + s[i]->in = FALSE; + } +/* + * Set pe structure + */ + pe_data_free(pe_x); + pe_x = pe_data_dup(solution_ptr->pe); + default_pe_x = solution_ptr->default_pe; +/* + * Clear master species solution-dependent data + */ + for (i = 0; i < count_master; i++) + { + master[i]->in = FALSE; + master[i]->unknown = NULL; + master[i]->pe_rxn = &(pe_x[solution_ptr->default_pe].rxn); +/* + * copy primary reaction to secondary reaction + */ + rxn_free(master[i]->rxn_secondary); + master[i]->rxn_secondary = rxn_dup(master[i]->rxn_primary); + } + + if (state == INITIAL_SOLUTION) + { + s_h2o->secondary->in = TRUE; + s_hplus->secondary->in = TRUE; + } + else + { + s_h2o->primary->in = TRUE; + s_hplus->primary->in = TRUE; + } + s_eminus->primary->in = TRUE; +/* + * Set all unknown pointers to NULL + */ + mb_unknown = NULL; + ah2o_unknown = NULL; + mass_hydrogen_unknown = NULL; + mass_oxygen_unknown = NULL; + mu_unknown = NULL; + alkalinity_unknown = NULL; + carbon_unknown = NULL; + ph_unknown = NULL; + pe_unknown = NULL; + charge_balance_unknown = NULL; + solution_phase_boundary_unknown = NULL; + pure_phase_unknown = NULL; + exchange_unknown = NULL; + surface_unknown = NULL; + gas_unknown = NULL; + s_s_unknown = NULL; +/* + * Free arrays used in model + */ + free_model_allocs(); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +convert_units(struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Converts solution concentrations to moles/kg water + * Uses totals.input conc to calculate totals.moles. + */ + int i, l; + LDBLE sum_solutes; + char c; + struct master *master_ptr; + struct conc *tot_ptr; + char token[MAX_LENGTH]; +/* + * Convert units + */ + sum_solutes = exp(-solution_ptr->ph * LOG_10); + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + master_ptr = master_bsearch(solution_ptr->totals[i].description); + if (master_ptr != NULL) + { + if (master_ptr->minor_isotope == TRUE) + continue; + } + tot_ptr = &(solution_ptr->totals[i]); + tot_ptr->moles = 0.0; + if (strcmp(tot_ptr->description, "H(1)") == 0 || + strcmp(tot_ptr->description, "E") == 0) + { + continue; + } + if (tot_ptr->input_conc <= 0) + continue; +/* + * Get gfw + */ + /* use given gfw if gfw > 0.0 */ + /* use formula give with "as" */ + if (tot_ptr->gfw <= 0.0) + { + if (tot_ptr->as != NULL) + { + /* use given chemical formula to calculate gfw */ + if (compute_gfw(tot_ptr->as, &(tot_ptr->gfw)) == ERROR) + { + error_string = sformatf( "Could not compute gfw, %s.", + tot_ptr->as); + error_msg(error_string, CONTINUE); + input_error++; + } + if (strcmp(tot_ptr->description, "Alkalinity") == 0 && + strcmp(tot_ptr->as, "CaCO3") == 0) + { + tot_ptr->gfw /= 2.; + error_string = sformatf( + "Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.", + (double) tot_ptr->gfw); + warning_msg(error_string); + } + /* use gfw of master species */ + } + else + { + char * temp_desc = string_duplicate(tot_ptr->description); + char *ptr = temp_desc; + copy_token(token, &ptr, &l); + master_ptr = master_bsearch(token); + free_check_null(temp_desc); + if (master_ptr != NULL) + { + /* use gfw for element redox state */ + tot_ptr->gfw = master_ptr->gfw; + } + else + { + error_string = sformatf( "Could not find gfw, %s.", + tot_ptr->description); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } + } +/* + * Convert liters to kg solution + */ + tot_ptr->moles = tot_ptr->input_conc; + if (strstr(solution_ptr->units, "/l") != NULL) + { + tot_ptr->moles *= 1.0 / (solution_ptr->density); + } +/* + * Convert milli or micro + */ + c = tot_ptr->units[0]; + if (c == 'm') + { + tot_ptr->moles *= 1e-3; + } + else if (c == 'u') + { + tot_ptr->moles *= 1e-6; + } +/* + * Sum grams of solute, convert from moles necessary + */ + if (strstr(tot_ptr->units, "g/kgs") != NULL || + strstr(tot_ptr->units, "g/l") != NULL) + { + sum_solutes += tot_ptr->moles; + } + else if (strstr(tot_ptr->units, "Mol/kgs") != NULL || + strstr(tot_ptr->units, "Mol/l") != NULL || + strstr(tot_ptr->units, "eq/l") != NULL) + { + sum_solutes += (tot_ptr->moles) * (tot_ptr->gfw); + } +/* + * Convert grams to moles, if necessary + */ + if (strstr(tot_ptr->units, "g/") != NULL && tot_ptr->gfw != 0.0) + { + tot_ptr->moles /= tot_ptr->gfw; + } + } +/* + * Convert /kgs to /kgw + */ + if (strstr(solution_ptr->units, "kgs") != NULL || + strstr(solution_ptr->units, "/l") != NULL) + { + mass_water_aq_x = 1.0 - 1e-3 * sum_solutes; + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + solution_ptr->totals[i].moles /= mass_water_aq_x; + } + } +/* + * Scale by mass of water in solution + */ + mass_water_aq_x = solution_ptr->mass_water; + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + solution_ptr->totals[i].moles *= mass_water_aq_x; + } + + solution_ptr->units = moles_per_kilogram_string; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct master ** Phreeqc:: +get_list_master_ptrs(char *ptr, struct master *master_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input: ptr contains a list of one or more master species names + * Output: space is allocated and a list of master species pointers is + * returned. + */ + int j, l, count_list; + char token[MAX_LENGTH]; + struct master **master_ptr_list; + struct master *master_ptr0; +/* + * Make list of master species pointers + */ + count_list = 0; + master_ptr_list = unknown_alloc_master(); + master_ptr0 = master_ptr; + if (master_ptr0 == master_ptr->s->primary) + { +/* + * First in list is primary species + */ + for (j = 0; j < count_master; j++) + { + if (master[j] == master_ptr0) + break; + } + j++; +/* + * Element has only one valence + */ + if (j >= count_master || master[j]->elt->primary != master_ptr0) + { + master_ptr_list[count_list++] = master_ptr0; +/* + * Element has multiple valences + */ + } + else + { + if (master_ptr0->s->secondary == NULL) + { + error_string = sformatf( + "Master species for valence states of element %s are not correct.\n\tPossibly related to master species for %s.", + master_ptr0->elt->name, master[j]->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + } + master_ptr_list[count_list++] = master_ptr0->s->secondary; + while (j < count_master && master[j]->elt->primary == master_ptr0) + { + if (master[j]->s->primary == NULL) + { + master_ptr_list = + (struct master **) PHRQ_realloc((void *) + master_ptr_list, + (size_t) (count_list + + + 2) * + sizeof(struct master + *)); + if (master_ptr_list == NULL) + malloc_error(); + master_ptr_list[count_list++] = master[j]; + } + j++; + } + } + } + else + { +/* + * First in list is secondary species, Include all valences from input + */ + master_ptr_list[count_list++] = master_ptr0; + while (copy_token(token, &ptr, &l) != EMPTY) + { + master_ptr = master_bsearch(token); + if (master_ptr != NULL) + { + master_ptr_list = + (struct master **) PHRQ_realloc((void *) master_ptr_list, + (size_t) (count_list + + 2) * + sizeof(struct master *)); + if (master_ptr_list == NULL) + malloc_error(); + master_ptr_list[count_list++] = master_ptr; + } + } + } + master_ptr_list[count_list] = NULL; + return (master_ptr_list); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inout(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct rxn_token_temp *token_ptr; +/* + * Routine goes through trxn to determine if each master species is + * in this model. + * Assumes equation is written in terms of primary and secondary species + * Checks to see if in is TRUE or REWRITE for each species + * Returns TRUE if in model + * FALSE if not + */ + for (i = 1; i < count_trxn; i++) + { + token_ptr = &(trxn.token[i]); + /* Check primary master species in */ + if (token_ptr->s->primary != NULL + && (token_ptr->s->primary->in == TRUE)) + continue; + /* Check secondary master species */ + if ((token_ptr->s->secondary != NULL) + && (token_ptr->s->secondary->in != FALSE)) + { + continue; + } + /* Must be primary master species that is out */ + return (FALSE); + } + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +is_special(struct species *l_spec) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks to see if a species is composed of only H, O, and e- + * Returns TRUE if true + * FALSE if not + */ + int special; + struct rxn_token *token_ptr; + + special = TRUE; + for (token_ptr = l_spec->rxn_s->token + 1; token_ptr->s != NULL; + token_ptr++) + { + if (token_ptr->s != s_hplus && + token_ptr->s != s_h2o && token_ptr->s != s_eminus) + { + special = FALSE; + break; + } + } + return (special); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, LDBLE coef, + LDBLE * gamma_ptr) +/* ---------------------------------------------------------------------- */ +/* + * Takes an unknown pointer and a coefficient and puts in + * list of mb_unknowns + */ +{ + if (equal(coef, 0.0, TOL) == TRUE) + return (OK); + if ((count_mb_unknowns + 1) >= max_mb_unknowns) + { + space((void **) ((void *) &mb_unknowns), count_mb_unknowns + 1, + &max_mb_unknowns, sizeof(struct unknown_list)); + } + mb_unknowns[count_mb_unknowns].unknown = unknown_ptr; + mb_unknowns[count_mb_unknowns].source = LDBLE_ptr; + mb_unknowns[count_mb_unknowns].gamma_source = gamma_ptr; + mb_unknowns[count_mb_unknowns].coef = coef; + count_mb_unknowns++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_for_species_aq(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i, j; + struct master *master_ptr; + struct unknown *unknown_ptr; + + count_mb_unknowns = 0; +/* + * e- does not appear in any mass balances + */ + if (s[n]->type == EMINUS) + return (OK); +/* + * Do not include diffuse layer in cb, alk, ah2o, mu + */ + if (charge_balance_unknown != NULL && s[n]->type < H2O) + { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, + &s[n]->dg); + } + if (alkalinity_unknown != NULL && s[n]->type < H2O) + { + store_mb_unknowns(alkalinity_unknown, &s[n]->moles, s[n]->alk, + &s[n]->dg); + } + if (ah2o_unknown != NULL && s[n]->type < H2O) + { + store_mb_unknowns(ah2o_unknown, &s[n]->moles, 1.0, &s[n]->dg); + } + if (mu_unknown != NULL && s[n]->type < H2O) + { + store_mb_unknowns(mu_unknown, &s[n]->moles, s[n]->z * s[n]->z, + &s[n]->dg); + } +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (mass_hydrogen_unknown != NULL) + { + if (dl_type_x != NO_DL && state >= REACTION) + { +#ifdef COMBINE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, + s[n]->h - 2 * s[n]->o, &s[n]->dg_total_g); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, + s[n]->h, &s[n]->dg_total_g); +#endif + } + else + { +#ifdef COMBINE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, + s[n]->h - 2 * s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, + &s[n]->dg); +#endif + } + } + if (mass_oxygen_unknown != NULL) + { + if (dl_type_x != NO_DL && state >= REACTION) + { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->tot_g_moles, + s[n]->o, &s[n]->dg_total_g); + } + else + { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, + &s[n]->dg); + } + } +/* + * Sum diffuse layer charge into (surface + DL) charge balance + */ + if (use.Get_surface_ptr() != NULL && s[n]->type < H2O && dl_type_x != NO_DL) + { + j = 0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE_CB) + { + unknown_ptr = x[i]; + if (use.Get_surface_ptr()->type == CD_MUSIC) + unknown_ptr = x[i + 2]; + store_mb_unknowns(unknown_ptr, &s[n]->diff_layer[j].g_moles, + s[n]->z, &s[n]->diff_layer[j].dg_g_moles); + j++; + } + } + } +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) + continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr = master_ptr->s->secondary; + } + } + if (master_ptr->unknown == ph_unknown) + { + continue; + } + else if (master_ptr->unknown == pe_unknown) + { + continue; + } + else if (master_ptr->unknown == charge_balance_unknown) + { + continue; + } + else if (master_ptr->unknown == alkalinity_unknown) + { + continue; + } + else if (master_ptr->unknown->type == SOLUTION_PHASE_BOUNDARY) + { + continue; + } + if (dl_type_x != NO_DL && state >= REACTION) + { + store_mb_unknowns(master_ptr->unknown, + &s[n]->tot_g_moles, + elt_list[i].coef * master_ptr->coef, + &s[n]->dg_total_g); + } + else + { + store_mb_unknowns(master_ptr->unknown, + &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_for_species_ex(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert exchange species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i; + struct master *master_ptr; + count_mb_unknowns = 0; +/* + * Master species for exchange do not appear in any mass balances + */ + if (s[n]->type == EX && s[n]->primary != NULL) + return (OK); +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (charge_balance_unknown != NULL) + { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, + &s[n]->dg); + } + if (mass_hydrogen_unknown != NULL) + { +#ifdef COMBINE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, + s[n]->h - 2 * s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, + &s[n]->dg); +#endif + } + if (mass_oxygen_unknown != NULL) + { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, + &s[n]->dg); + } +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) + continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr = master_ptr->s->secondary; + } + } +/* + * Special for ph_unknown, pe_unknown, and alkalinity_unknown + */ + if (master_ptr->unknown == ph_unknown) + { + continue; + } + else if (master_ptr->unknown == pe_unknown) + { + continue; + } + else if (master_ptr->unknown == alkalinity_unknown) + { + continue; + } +/* + * EX, sum exchange species only into EXCH mass balance in initial calculation + * into all mass balances in reaction calculation + */ + if (state >= REACTION || master_ptr->s->type == EX) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mb_for_species_surf(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of mass balance and charge balance equations in which + * to insert species n. + * + * count_mb_unknowns - number of equations and summation relations + * mb_unknowns.source - pointer to the LDBLE number to be multiplied + * by coef, usually moles. + * mb_unknowns.unknown - pointer to unknown which contains row number + * mb_unknowns.coef - coefficient of s[n] in equation or relation + */ + int i; + struct master *master_ptr; + + count_mb_unknowns = 0; +/* + * Include in charge balance, if diffuse_layer_x == FALSE + */ + if (charge_balance_unknown != NULL && dl_type_x == NO_DL) + { + store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, + &s[n]->dg); + } +/* + * Include diffuse layer in hydrogen and oxygen mass balance + */ + if (mass_hydrogen_unknown != NULL) + { +#ifdef COMBINE + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, + s[n]->h - 2 * s[n]->o, &s[n]->dg); +#else + store_mb_unknowns(mass_hydrogen_unknown, &s[n]->moles, s[n]->h, + &s[n]->dg); +#endif + } + if (mass_oxygen_unknown != NULL) + { + store_mb_unknowns(mass_oxygen_unknown, &s[n]->moles, s[n]->o, + &s[n]->dg); + } +/* + * Other mass balances + */ +/* + * Other mass balances + */ + for (i = 0; i < count_elts; i++) + { +/* Skip H+, e-, and H2O */ + if (elt_list[i].elt->master->s->type > AQ && + elt_list[i].elt->master->s->type < SOLID) + continue; + master_ptr = elt_list[i].elt->master; + if (master_ptr->primary == TRUE) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr = master_ptr->s->secondary; + } + } +/* + * SURF_PSI, sum surface species in (surface + DL) charge balance + */ + if (master_ptr->s->type == SURF_PSI + && use.Get_surface_ptr()->type != CD_MUSIC) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->z, + &s[n]->dg); + continue; + } + if (master_ptr->s->type == SURF_PSI + && use.Get_surface_ptr()->type == CD_MUSIC) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->dz[0], + &s[n]->dg); + continue; + } + if (master_ptr->s->type == SURF_PSI1) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->dz[1], + &s[n]->dg); + continue; + } + if (master_ptr->s->type == SURF_PSI2) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->dz[2], + &s[n]->dg); + /* + if (diffuse_layer_x == TRUE) { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->z, &s[n]->dg ); + } else { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->dz[2], &s[n]->dg ); + } + */ + continue; + } +/* + * Special for ph_unknown, pe_unknown, and alkalinity_unknown + */ + if (master_ptr->unknown == ph_unknown) + { + continue; + } + else if (master_ptr->unknown == pe_unknown) + { + continue; + } + else if (master_ptr->unknown == alkalinity_unknown) + { + continue; + } +/* + * SURF, sum surface species only into SURFACE mass balance in initial calculation + * into all mass balances in reaction calculation + */ + if (state >= REACTION || master_ptr->s->type == SURF) + { + store_mb_unknowns(master_ptr->unknown, &s[n]->moles, + elt_list[i].coef * master_ptr->coef, &s[n]->dg); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reprep(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * If a basis species has been switched, makes new model. + * Unknowns are not changed, but mass-action equations are + * rewritten and lists for mass balance and jacobian are regenerated + */ + int i; +/* + * Initialize s, master, and unknown pointers + */ + for (i = 0; i < count_master; i++) + { + if (master[i]->in == FALSE) + continue; + rxn_free(master[i]->rxn_secondary); + master[i]->rxn_secondary = rxn_dup(master[i]->rxn_primary); + } + resetup_master(); +/* + * Set unknown pointers, unknown types, validity checks + */ + tidy_redox(); + if (get_input_errors() > 0) + { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Free arrays built in build_model + */ + s_x = (struct species **) free_check_null(s_x); + sum_mb1 = (struct list1 *) free_check_null(sum_mb1); + sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); + sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); + sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); + sum_delta = (struct list2 *) free_check_null(sum_delta); +/* + * Build model again + */ + build_model(); + same_model = FALSE; + k_temp(tc_x, patm_x); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +resetup_master(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * For basis switch, rewrite equations for master species + * Set master_ptr->rxn_secondary, + * master_ptr->pe_rxn, + * and special cases for alkalinity, carbon, and pH. + */ + int i, j; + struct master *master_ptr, *master_ptr0; + + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != MB) + continue; + master_ptr0 = x[i]->master[0]; + for (j = 0; (master_ptr = x[i]->master[j]) != NULL; j++) + { +/* + * Set flags + */ + if (j == 0) + { + if (master_ptr->s->primary == NULL) + { + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_dup(master_ptr->s->rxn_s); + } + } + else + { + if (master_ptr0->s->primary == NULL) + { + rewrite_master_to_secondary(master_ptr, master_ptr0); + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_alloc(count_trxn + 1); + trxn_copy(master_ptr->rxn_secondary); + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +write_mass_action_eqn_x(int stop) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reduce mass-action equation to the master species that are in the model + */ + LDBLE coef_e; + int count, repeat; + int i, count_rxn_orig; +/* + * Rewrite any secondary master species flagged REWRITE + * Replace pe if necessary + */ + count = 0; + repeat = TRUE; + while (repeat == TRUE) + { + count++; + if (count > MAX_ADD_EQUATIONS) + { + error_string = sformatf( "Could not reduce equation " + "to primary and secondary species that are " + "in the model\n\t Species: %s.", trxn.token[0].s->name); + if (stop == STOP) + { + input_error++; + error_msg(error_string, CONTINUE); + } + else + { + warning_msg(error_string); + } + return (ERROR); + } + repeat = FALSE; + count_rxn_orig = count_trxn; + for (i = 1; i < count_rxn_orig; i++) + { + if (trxn.token[i].s->secondary == NULL) + continue; + if (trxn.token[i].s->secondary->in == REWRITE) + { + repeat = TRUE; + coef_e = + rxn_find_coef(trxn.token[i].s->secondary->rxn_secondary, + "e-"); + trxn_add(trxn.token[i].s->secondary->rxn_secondary, + trxn.token[i].coef, FALSE); + if (equal(coef_e, 0.0, TOL) == FALSE) + { + trxn_add(*(trxn.token[i].s->secondary->pe_rxn), + trxn.token[i].coef * coef_e, FALSE); + } + } + } + trxn_combine(); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_potential_factor(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add the potential factor to surface mass-action equations. + * Factor is essentially the activity coefficient, representing + * the work required to bring charged ions to the surface + */ + int i; + char token[MAX_LENGTH]; + LDBLE sum_z; + struct master *master_ptr; + struct unknown *unknown_ptr; + + /*if (use.Get_surface_ptr()->edl == FALSE) return(OK); */ + if (use.Get_surface_ptr()->type != DDL) + return (OK); + sum_z = 0.0; + master_ptr = NULL; +/* + * Find sum of charge of aqueous species and surface master species + */ + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->type == AQ || trxn.token[i].s == s_hplus || + trxn.token[i].s == s_eminus) + { + sum_z += trxn.token[i].s->z * trxn.token[i].coef; + } + if (trxn.token[i].s->type == SURF) + { + master_ptr = trxn.token[i].s->primary; + } + } +/* + * Find potential unknown for surface species + */ + if (master_ptr == NULL) + { + error_string = sformatf( + "Did not find a surface species in equation defining %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + error_string = sformatf( + "One of the following must be defined with SURFACE_SPECIES:"); + error_msg(error_string, CONTINUE); + for (i = 1; i < count_trxn; i++) + { + error_string = sformatf( " %s", trxn.token[i].name); + error_msg(error_string, CONTINUE); + } + input_error++; + return (ERROR); + } + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + if (unknown_ptr == NULL) + { + error_string = sformatf( + "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ +/* + * Make sure there is space + */ + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, + sizeof(struct rxn_token_temp)); + } +/* + * Include psi in mass action equation + */ + if (master_ptr != NULL) + { + trxn.token[count_trxn].name = master_ptr->s->name; + trxn.token[count_trxn].s = master_ptr->s; + trxn.token[count_trxn].coef = -2.0 * sum_z; + count_trxn++; + } + else + { + output_msg(sformatf( + "How did this happen in add potential factor?\n")); + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_cd_music_factors(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add the potential factors for cd_music to surface mass-action equations. + * Factors are essentially the activity coefficient, representing + * the work required to bring charged ions to the three charge layers + * of the cd_music model + */ + int i; + char token[MAX_LENGTH]; + struct master *master_ptr; + struct unknown *unknown_ptr; + + /*if (use.Get_surface_ptr()->edl == FALSE) return(OK); */ + if (use.Get_surface_ptr()->type != CD_MUSIC) + return (OK); + master_ptr = NULL; +/* + * Find sum of charge of aqueous species and surface master species + */ + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->type == SURF) + { + master_ptr = trxn.token[i].s->primary; + } + } +/* + * Find potential unknown for surface species + */ + if (master_ptr == NULL) + { + error_string = sformatf( + "Did not find a surface species in equation defining %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + error_string = sformatf( + "One of the following must be defined with SURFACE_SPECIES:"); + error_msg(error_string, CONTINUE); + for (i = 1; i < count_trxn; i++) + { + error_string = sformatf( " %s", trxn.token[i].name); + error_msg(error_string, CONTINUE); + } + input_error++; + return (ERROR); + } + strcpy(token, master_ptr->elt->name); + /* + * Plane 0 + */ + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + if (unknown_ptr == NULL) + { + error_string = sformatf( + "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Make sure there is space + */ + if (count_trxn + 3 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 3, &max_trxn, + sizeof(struct rxn_token_temp)); + } + /* + * Include psi in mass action equation + */ + trxn.token[count_trxn].name = master_ptr->s->name; + trxn.token[count_trxn].s = master_ptr->s; + /*trxn.token[count_trxn].coef = s[n]->dz[0];*/ + trxn.token[count_trxn].coef = trxn.dz[0]; + + count_trxn++; + + /* + * Plane 1 + */ + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI1); + if (unknown_ptr == NULL) + { + error_string = sformatf( + "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Include psi in mass action equation + */ + trxn.token[count_trxn].name = master_ptr->s->name; + trxn.token[count_trxn].s = master_ptr->s; + /*trxn.token[count_trxn].coef = s[n]->dz[1];*/ + trxn.token[count_trxn].coef = trxn.dz[1]; + count_trxn++; + /* + * Plane 2 + */ + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI2); + if (unknown_ptr == NULL) + { + error_string = sformatf( + "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Include psi in mass action equation + */ + trxn.token[count_trxn].name = master_ptr->s->name; + trxn.token[count_trxn].s = master_ptr->s; + /*trxn.token[count_trxn].coef = s[n]->dz[2];*/ + trxn.token[count_trxn].coef = trxn.dz[2]; + count_trxn++; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_surface_charge_balance(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Include charge balance in list for mass-balance equations + */ + int i; + char *ptr; + char token[MAX_LENGTH]; + + struct master *master_ptr; + struct unknown *unknown_ptr; + + if (use.Get_surface_ptr()->type != DDL) + return (OK); + master_ptr = NULL; +/* + * Find master species + */ + for (i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->primary->s->type == SURF) + { + master_ptr = elt_list[i].elt->primary; + break; + } + } + if (i >= count_elts) + { + error_string = sformatf( + "No surface master species found for surface species."); + error_msg(error_string, STOP); + } +/* + * Find potential unknown for surface species + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + if (unknown_ptr == NULL) + { + error_string = sformatf( + "No potential unknown found for surface species %s.", token); + error_msg(error_string, STOP); + } + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ +/* + * Include charge balance in list for mass-balance equations + */ + char * temp_name = string_duplicate(master_ptr->elt->name); + ptr = temp_name; + get_secondary_in_species(&ptr, 1.0); + free_check_null(temp_name); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_cd_music_charge_balances(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add the potential factor to surface mass-action equations. + * Factor is essentially the activity coefficient, representing + * the work required to bring charged ions to the surface + */ + int i; + char token[MAX_LENGTH]; + + struct master *master_ptr; + struct unknown *unknown_ptr; + + if (use.Get_surface_ptr()->type != CD_MUSIC) + return (OK); + master_ptr = NULL; +/* + * Find master species + */ + for (i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->primary->s->type == SURF) + { + master_ptr = elt_list[i].elt->primary; + break; + } + } + if (i >= count_elts) + { + error_string = sformatf( + "No surface master species found for surface species."); + error_msg(error_string, STOP); + } + /* + * Find potential unknown for plane 0 + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Include charge balance in list for mass-balance equations + */ + { + char * temp_name = string_duplicate( master_ptr->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, s[n]->dz[0]); + free_check_null(temp_name); + } + /* + * Find potential unknown for plane 1 + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI1); + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Include charge balance in list for mass-balance equations + */ + { + char * temp_name = string_duplicate( master_ptr->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, s[n]->dz[1]); + free_check_null(temp_name); + } + /* + * Find potential unknown for plane 2 + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI2); + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + /* + * Include charge balance in list for mass-balance equations + */ + { + char * temp_name = string_duplicate(master_ptr->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, s[n]->dz[2]); + free_check_null(temp_name); + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for secondary master species in terms of another secondary master species + * Store result in rxn_secondary of master_ptr. + */ + LDBLE coef1, coef2; + struct master *master_ptr_p1, *master_ptr_p2; +/* + * Check that the two master species have the same primary master species + */ + master_ptr_p1 = master_ptr1->elt->primary; + master_ptr_p2 = master_ptr2->elt->primary; + if (master_ptr_p1 != master_ptr_p2 || master_ptr_p1 == NULL) + { + error_string = sformatf( + "All redox states must be for the same element. %s\t%s.", + master_ptr1->elt->name, master_ptr2->elt->name); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find coefficient of primary master in reaction + */ + coef1 = rxn_find_coef(master_ptr1->rxn_primary, master_ptr_p1->s->name); + coef2 = rxn_find_coef(master_ptr2->rxn_primary, master_ptr_p1->s->name); + if (equal(coef1, 0.0, TOL) == TRUE || equal(coef2, 0.0, TOL) == TRUE) + { + error_string = sformatf( + "One of these equations does not contain master species for element, %s or %s.", + master_ptr1->s->name, master_ptr2->s->name); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Rewrite equation to secondary master species + */ + count_trxn = 0; + trxn_add(master_ptr1->rxn_primary, 1.0, FALSE); + trxn_add(master_ptr2->rxn_primary, -coef1 / coef2, TRUE); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_exchange(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for exchanger in unknowns structures + */ + //int i, j; + struct master *master_ptr; + struct master **master_ptr_list; + + if (use.Get_exchange_ptr() == NULL) + return (OK); + std::vector comps = ((cxxExchange *) use.Get_exchange_ptr())->Vectorize(); + for (size_t j = 0; j < comps.size(); j++) + { + cxxExchComp * comp_ptr = comps[j]; + cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + for ( ; it != nd.end(); it++) + { +/* + * Find master species + */ + //master_ptr = use.Get_exchange_ptr()->comps[j].totals[i].elt->master; + element * elt_ptr = element_store(it->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + it->first.c_str()); + input_error++; + error_msg(error_string, CONTINUE); + continue; + } + master_ptr = elt_ptr->master; + if (master_ptr->type != EX) + continue; +/* + * Check for data already given + */ + if (master_ptr->in != FALSE) + { + x[master_ptr->unknown->number]->moles += + it->second; + } + else + { +/* + * Set flags + */ + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; +/* + * Set unknown data + */ + x[count_unknowns]->type = EXCH; + x[count_unknowns]->exch_comp = string_hsave(it->first.c_str()); + x[count_unknowns]->description = elt_ptr->name; + x[count_unknowns]->moles = it->second; + x[count_unknowns]->master = master_ptr_list; + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + count_unknowns++; + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for gas phase unknown (sum of partial pressures) + * in unknown structure + */ + //int i; + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && ( + gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) + { + return setup_fixed_volume_gas(); + } + +/* + * One for total moles in gas + */ + x[count_unknowns]->type = GAS_MOLES; + x[count_unknowns]->description = string_hsave("gas moles"); + x[count_unknowns]->moles = 0.0; + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + x[count_unknowns]->moles += gc_ptr->Get_moles(); + } + if (x[count_unknowns]->moles <= 0) + x[count_unknowns]->moles = MIN_TOTAL; + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + //x[count_unknowns]->gas_phase = use.Get_gas_phase_ptr(); + gas_unknown = x[count_unknowns]; + count_unknowns++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_slack(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for slack unknown + */ + slack_unknown = NULL; + if (slack) + { + x[count_unknowns]->type = SLACK; + x[count_unknowns]->description = string_hsave("slack"); + x[count_unknowns]->moles = 0.0; + x[count_unknowns]->number = count_unknowns; + slack_unknown = x[count_unknowns]; + count_unknowns++; + } + return (OK); +} + +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_slack(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for slack unknown + */ + + slack_unknown = NULL; + if (slack) + { + int i = count_unknowns; + int j; + for (j = 0; j < i; j++) + { + if (x[j]->type == MB) + { + x[count_unknowns]->type = SLACK; + x[count_unknowns]->description = string_hsave("slack"); + x[count_unknowns]->moles = 0.0; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->mb_number = j; + slack_unknown = x[count_unknowns]; + count_unknowns++; + } + } + if (count_unknowns > i) + { + slack_unknown = x[i]; + } + } + + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for solid solution unknowns (sum of partial pressures) + * in unknown structure + */ + int i, j; + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); +/* + * One for each component in each solid solution + */ + s_s_unknown = NULL; + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + x[count_unknowns]->type = S_S_MOLES; + x[count_unknowns]->description = + string_hsave(use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name); + x[count_unknowns]->moles = 0.0; + if (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles <= 0) + { + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles = MIN_TOTAL_SS; + } + x[count_unknowns]->moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].initial_moles = + x[count_unknowns]->moles; + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + x[count_unknowns]->s_s = &(use.Get_ss_assemblage_ptr()->s_s[j]); + x[count_unknowns]->s_s_comp = + &(use.Get_ss_assemblage_ptr()->s_s[j].comps[i]); + x[count_unknowns]->s_s_comp_number = i; + x[count_unknowns]->phase = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].phase; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->phase->dn = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dn; + x[count_unknowns]->phase->dnb = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dnb; + x[count_unknowns]->phase->dnc = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dnc; + x[count_unknowns]->phase->log10_fraction_x = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_fraction_x; + x[count_unknowns]->phase->log10_lambda = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_lambda; + if (s_s_unknown == NULL) + s_s_unknown = x[count_unknowns]; + count_unknowns++; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_surface(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Fill in data for surface assemblage in unknown structure + */ + int i, j, k, plane; + struct master *master_ptr; + struct master **master_ptr_list; + struct unknown *unknown_ptr, **unknown_target; + char token[MAX_LENGTH], cb_suffix[MAX_LENGTH], psi_suffix[MAX_LENGTH], + mass_balance_name[MAX_LENGTH]; + const char *name1, *name2; + int mb_unknown_number, type; + + if (use.Get_surface_ptr() == NULL) + return (OK); + + for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + { + /* + * Find master species for each surface, setup unknown structure + */ + for (j = 0; use.Get_surface_ptr()->comps[i].totals[j].elt != NULL; j++) + { + master_ptr = use.Get_surface_ptr()->comps[i].totals[j].elt->master; + if (master_ptr == NULL) + { + error_string = sformatf( + "Master species not in data base for %s, skipping element.", + use.Get_surface_ptr()->comps[i].totals[j].elt->name); + warning_msg(error_string); + continue; + } + if (master_ptr->type != SURF) + continue; + /* + * Check that data not already given + */ if (master_ptr->in != FALSE) + { + error_string = sformatf( + "Analytical data entered twice for %s.", + master_ptr->s->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + /* + * Set flags + */ + use.Get_surface_ptr()->comps[i].master = master_ptr; + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; + /* + * Setup mass balance unknown + */ + x[count_unknowns]->type = SURFACE; + x[count_unknowns]->description = + use.Get_surface_ptr()->comps[i].totals[j].elt->name; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->surface_comp = &(use.Get_surface_ptr()->comps[i]); + x[count_unknowns]->master = master_ptr_list; + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + x[count_unknowns]->moles = + use.Get_surface_ptr()->comps[i].totals[j].coef; + if (surface_unknown == NULL) + surface_unknown = x[count_unknowns]; + x[count_unknowns]->potential_unknown = NULL; + count_unknowns++; + /*if (use.Get_surface_ptr()->edl == FALSE) continue; */ + if (use.Get_surface_ptr()->type == DDL) + { + /* + * Setup surface-potential unknown + */ + strcpy(token, master_ptr->elt->name); + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + if (unknown_ptr != NULL) + { + x[count_unknowns - 1]->potential_unknown = unknown_ptr; + } + else + { + /* + * Find master species + */ + replace("_CB", "_psi", token); + master_ptr = master_bsearch(token); + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; + /* + * Find surface charge structure + */ + x[count_unknowns]->type = SURFACE_CB; + k = use.Get_surface_ptr()->comps[i].charge; + x[count_unknowns]->surface_charge = + &use.Get_surface_ptr()->charge[k]; + x[count_unknowns]->related_moles = + x[count_unknowns]->surface_charge->grams; + x[count_unknowns]->mass_water = + use.Get_surface_ptr()->charge[k].mass_water; + replace("_psi", "_CB", token); + x[count_unknowns]->description = string_hsave(token); + x[count_unknowns]->master = master_ptr_list; + /*use.Get_surface_ptr()->charge[k].psi_master = x[count_unknowns]->master[0]; */ + x[count_unknowns]->master[0]->unknown = x[count_unknowns]; + x[count_unknowns]->moles = 0.0; + x[count_unknowns - 1]->potential_unknown = + x[count_unknowns]; + x[count_unknowns]->surface_comp = + x[count_unknowns - 1]->surface_comp; + count_unknowns++; + } + } + else if (use.Get_surface_ptr()->type == CD_MUSIC) + { + /* + * Setup 3 surface-potential unknowns + */ + mb_unknown_number = count_unknowns - 1; + strcpy(token, master_ptr->elt->name); + strcpy(mass_balance_name, token); + for (plane = SURF_PSI; plane <= SURF_PSI2; plane++) + { + strcpy(cb_suffix, "_CB"); + strcpy(psi_suffix, "_psi"); + unknown_target = NULL; + type = SURFACE_CB; + switch (plane) + { + case SURF_PSI: + type = SURFACE_CB; + unknown_target = + &(x[mb_unknown_number]->potential_unknown); + break; + case SURF_PSI1: + strcat(cb_suffix, "b"); + strcat(psi_suffix, "b"); + type = SURFACE_CB1; + unknown_target = + &(x[mb_unknown_number]->potential_unknown1); + break; + case SURF_PSI2: + strcat(cb_suffix, "d"); + strcat(psi_suffix, "d"); + type = SURFACE_CB2; + unknown_target = + &(x[mb_unknown_number]->potential_unknown2); + break; + } + unknown_ptr = find_surface_charge_unknown(token, plane); + if (unknown_ptr != NULL) + { + *unknown_target = unknown_ptr; + } + else + { + /* + * Find master species + */ + replace(cb_suffix, psi_suffix, token); + master_ptr = master_bsearch(token); + master_ptr_list = unknown_alloc_master(); + master_ptr_list[0] = master_ptr; + master_ptr->in = TRUE; + /* + * Find surface charge structure + */ + x[count_unknowns]->type = type; + k = use.Get_surface_ptr()->comps[i].charge; + x[count_unknowns]->surface_charge = + &use.Get_surface_ptr()->charge[k]; + x[count_unknowns]->related_moles = + x[count_unknowns]->surface_charge->grams; + x[count_unknowns]->mass_water = + use.Get_surface_ptr()->charge[k].mass_water; + replace(psi_suffix, cb_suffix, token); + x[count_unknowns]->description = string_hsave(token); + x[count_unknowns]->master = master_ptr_list; + /* + * Find surface charge structure + */ + if (plane == SURF_PSI) + { + /*use.Get_surface_ptr()->charge[k].psi_master = x[count_unknowns]->master[0]; */ + x[mb_unknown_number]->potential_unknown = + x[count_unknowns]; + } + else if (plane == SURF_PSI1) + { + /*use.Get_surface_ptr()->charge[k].psi_master1 = x[count_unknowns]->master[0]; */ + x[mb_unknown_number]->potential_unknown1 = + x[count_unknowns]; + } + else if (plane == SURF_PSI2) + { + /*use.Get_surface_ptr()->charge[k].psi_master2 = x[count_unknowns]->master[0]; */ + x[mb_unknown_number]->potential_unknown2 = + x[count_unknowns]; + } + x[count_unknowns]->master[0]->unknown = + x[count_unknowns]; + x[count_unknowns]->moles = 0.0; + x[count_unknowns]->surface_comp = + x[mb_unknown_number]->surface_comp; + count_unknowns++; + } + } + /* Add SURFACE unknown to a list for SURF_PSI */ + unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + unknown_ptr->comp_unknowns = + (struct unknown **) PHRQ_realloc(unknown_ptr-> + comp_unknowns, + (size_t) ((unknown_ptr-> + count_comp_unknowns + + + 1) * + sizeof(struct + unknown + *))); + if (unknown_ptr->comp_unknowns == NULL) + malloc_error(); + unknown_ptr->comp_unknowns[unknown_ptr-> + count_comp_unknowns++] = + x[mb_unknown_number]; + } + } + } + /* + * check related phases + */ + if (use.Get_surface_ptr()->related_phases == TRUE) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE) + continue; + if (x[j]->potential_unknown != x[i]) + continue; + if (x[j]->surface_comp->phase_name != + x[i]->surface_comp->phase_name) + { + if (x[i]->surface_comp->phase_name == NULL) + { + name1 = string_hsave("None"); + } + else + { + name1 = x[i]->surface_comp->phase_name; + } + if (x[j]->surface_comp->phase_name == NULL) + { + name2 = string_hsave("None"); + } + else + { + name2 = x[j]->surface_comp->phase_name; + } + input_error++; + error_string = sformatf( + "All surface sites for a single component must be related to the same phase.\n\tSite: %s is related to %s, Site: %s is related to %s", + x[i]->surface_comp->master->s->name, name1, + x[j]->surface_comp->master->s->name, name2); + + error_msg(error_string, CONTINUE); + } + } + } + } + /* + * check related kinetics + */ + if (use.Get_surface_ptr()->related_rate == TRUE) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE) + continue; + if (x[j]->potential_unknown != x[i]) + continue; + if (x[j]->surface_comp->rate_name != + x[i]->surface_comp->rate_name) + { + if (x[i]->surface_comp->rate_name == NULL) + { + name1 = string_hsave("None"); + } + else + { + name1 = x[i]->surface_comp->rate_name; + } + if (x[j]->surface_comp->rate_name == NULL) + { + name2 = string_hsave("None"); + } + else + { + name2 = x[j]->surface_comp->rate_name; + } + input_error++; + error_string = sformatf( + "All surface sites for a single component must be related to the same kinetic reaction.\n\tSite: %s is related to %s, Site: %s is related to %s", + x[i]->surface_comp->master->s->name, name1, + x[j]->surface_comp->master->s->name, name2); + + error_msg(error_string, CONTINUE); + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct unknown * Phreeqc:: +find_surface_charge_unknown(char *str_ptr, int plane) +/* ---------------------------------------------------------------------- */ +{ +/* + * Makes name for the potential unknown and returns in str_ptr + * Returns NULL if this unknown not in unknown list else + * returns a pointer to the potential unknown + */ + int i; + char *ptr; + char token[MAX_LENGTH]; + + replace("_", " ", str_ptr); + ptr = str_ptr; + copy_token(token, &ptr, &i); + if (plane == SURF_PSI) + { + strcat(token, "_CB"); + } + else if (plane == SURF_PSI1) + { + strcat(token, "_CBb"); + } + else if (plane == SURF_PSI2) + { + strcat(token, "_CBd"); + } + strcpy(str_ptr, token); + for (i = 0; i < count_unknowns; i++) + { + if (strcmp(token, x[i]->description) == 0) + { + return (x[i]); + } + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn) +/* ---------------------------------------------------------------------- */ +{ +/* + * Rewrites rxn_secondary for all redox states in list + * First, in = TRUE; others, in = REWRITE + */ + int j; + struct master *master_ptr, *master_ptr0; +/* + * Set master_ptr->in, master_ptr->rxn + */ + master_ptr0 = master_ptr_list[0]; + for (j = 0; (master_ptr = master_ptr_list[j]) != NULL; j++) + { +/* + * Check that data not already given + */ + if (master_ptr->s == s_h2o) + { + error_string = sformatf( + "Can not enter concentration data for O(-2),\n\tdissolved oxygen is O(0),\n\tfor mass of water, use -water identifier."); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + + if (master_ptr->in != FALSE) + { + if (master_ptr->s != s_eminus && master_ptr->s != s_hplus) + { + error_string = sformatf( + "Analytical data entered twice for %s.", + master_ptr->s->name); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } +/* + * Set flags + */ + if (j == 0) + { + master_ptr->in = TRUE; + if (master_ptr->s->primary == NULL) + { + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_dup(master_ptr->s->rxn_s); +/* debug + trxn_print (); + */ + } + } + else + { + master_ptr->in = REWRITE; + if (master_ptr0->s->primary == NULL) + { + rewrite_master_to_secondary(master_ptr, master_ptr0); + rxn_free(master_ptr->rxn_secondary); + master_ptr->rxn_secondary = rxn_alloc(count_trxn + 1); + trxn_copy(master_ptr->rxn_secondary); +/* debug + trxn_print (); + */ + } + } + master_ptr->pe_rxn = pe_rxn; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) +/* ---------------------------------------------------------------------- */ +/* Calculate fugacity and fugacity coefficient for gas pressures if critical T and P + are defined. + 1) Solve molar volume V_m or total pressure P from Peng-Robinson's EOS: + P = R * T / (V_m - b) - a * aa / (V_m^2 + 2 * b * V_m - b^2) + a = 0.457235 * (R * T_c)^2 / P_c + b = 0.077796 * R * T_c / P_c + aa = (1 + kk * (1 - T_r^0.5))^2 + kk = 0.37464 + 1.54226 * omega - 0.26992 * omega^2 + T_r = T / T_c + multicomponent gas phase: + use: b_sum = Sum(x_i * b), x_i is mole-fraction + a_aa_sum = Sum_i( Sum_j(x_i * x_j * (a_i * aa_i * a_j * aa_j)^0.5) ) + 2) Find the fugacity coefficient phi for gas i: + log(phi_i) = B_ratio * (z - 1) - log(z - B) + A / (2.8284 * B) * (B_ratio - 2 / a_aa_sum * a_aa_sum2) *\ + log((z + 2.4142 * B) / (z - 0.4142 * B)) + B_ratio = b_i / b_sum + A = a_aa_sum * P / R_TK^2 + B = b_sum * P / R_TK + a_aa_sum2 = Sum_j(x_j * (a_aa_i * a_aa_j)^0.5 + 3) correct the solubility of gas i with: + pr_si_f = log10(phi_i) - Delta_V_i * (P - 1) / (2.303 * R * TK); +*/ +{ + int i, i1, n_g = phase_ptrs.size(); + LDBLE T_c, P_c; + LDBLE A, B, B_r, /*b2,*/ kk, oo, a_aa, T_r; + LDBLE m_sum, /*b_sum, a_aa_sum,*/ a_aa_sum2; + LDBLE phi; + LDBLE /*R_TK,*/ R = R_LITER_ATM; /* L atm / (K mol) */ + LDBLE r3[4], r3_12, rp, rp3, rq, rz, ri, ri1, one_3 = 0.33333333333333333; + LDBLE disct, vinit, v1, ddp, dp_dv, dp_dv2; + int it; + struct phase *phase_ptr, *phase_ptr1; + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + bool halved; + R_TK = R * TK; + m_sum = b_sum = a_aa_sum = 0.0; + for (i = 0; i < n_g; i++) + { + phase_ptr = phase_ptrs[i]; + if (n_g > 1) + { + if (phase_ptr->moles_x == 0) + continue; + m_sum += phase_ptr->moles_x; + } + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + continue; + if (!phase_ptr->pr_a) + { + T_c = phase_ptr->t_c; + P_c = phase_ptr->p_c; + phase_ptr->pr_a = 0.457235 * R * R * T_c * T_c / P_c; + phase_ptr->pr_b = 0.077796 * R * T_c / P_c; + T_r = TK / T_c; + oo = phase_ptr->omega; + kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); + phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); + phase_ptr->pr_tk = TK; + phase_ptr->pr_in = true; + } + if (phase_ptr->pr_tk != TK) + { + T_r = TK / phase_ptr->t_c; + oo = phase_ptr->omega; + kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); + phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); + phase_ptr->pr_tk = TK; + phase_ptr->pr_in = true; + } + } + for (i = 0; i < n_g; i++) + { + phase_ptr = phase_ptrs[i]; + if (n_g == 1) + { + phase_ptr->fraction_x = 1.0; + break; + } + if (m_sum == 0) + return (OK); + phase_ptr->fraction_x = phase_ptr->moles_x / m_sum; + } + + for (i = 0; i < n_g; i++) + { + a_aa_sum2 = 0.0; + phase_ptr = phase_ptrs[i]; + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + continue; + b_sum += phase_ptr->fraction_x * phase_ptr->pr_b; + for (i1 = 0; i1 < n_g; i1++) + { + phase_ptr1 = phase_ptrs[i1]; + if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) + continue; + if (phase_ptr1->fraction_x == 0) + continue; + a_aa = sqrt(phase_ptr->pr_a * phase_ptr->pr_alpha * + phase_ptr1->pr_a * phase_ptr1->pr_alpha); + if (!strcmp(phase_ptr->name, "H2O(g)")) + { + if (!strcmp(phase_ptr1->name, "CO2(g)")) + a_aa *= 0.81; // Soreide and Whitson, 1992, FPE 77, 217 + else if (!strcmp(phase_ptr1->name, "H2S(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr1->name, "CH4(g)")) + a_aa *= 0.51; + else if (!strcmp(phase_ptr1->name, "N2(g)")) + a_aa *= 0.51; + } + if (!strcmp(phase_ptr1->name, "H2O(g)")) + { + if (!strcmp(phase_ptr->name, "CO2(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr->name, "H2S(g)")) + a_aa *= 0.81; + else if (!strcmp(phase_ptr->name, "CH4(g)")) + a_aa *= 0.51; + else if (!strcmp(phase_ptr->name, "N2(g)")) + a_aa *= 0.51; + } + a_aa_sum += phase_ptr->fraction_x * phase_ptr1->fraction_x * a_aa; + a_aa_sum2 += phase_ptr1->fraction_x * a_aa; + } + phase_ptr->pr_aa_sum2 = a_aa_sum2; + } + b2 = b_sum * b_sum; + + if (V_m) + { + P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); + if (iterations > 0 && P < 150) + { + // check for 3-roots... + r3[1] = b_sum - R_TK / P; + r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; + r3[3] = b2 * b_sum + (R_TK * b2 - b_sum * a_aa_sum) / P; + // the discriminant of the cubic eqn... + disct = 18. * r3[1] * r3[2] * r3[3] - + 4. * pow(r3[1], 3) * r3[3] + + r3[1] * r3[1] * r3[2] * r3[2] - + 4. * pow(r3[2], 3) - + 27. * r3[3] * r3[3]; + //if (iterations > 50) + // it = 0; // debug + if (disct > 0) + { + // 3-roots, find the largest P... + it = 0; + halved = false; + ddp = 1e-9; + v1 = vinit = 0.429; + dp_dv = f_Vm(v1, this); + while (fabs(dp_dv) > 1e-11 && it < 40) + { + it +=1; + dp_dv2 = f_Vm(v1 - ddp, this); + v1 -= (dp_dv * ddp / (dp_dv - dp_dv2)); + if (!halved && (v1 > vinit || v1 < 0.03)) + { + vinit -= 0.05; + if (vinit < 0.03) + { + vinit = halve(f_Vm, 0.03, 1.0, 1e-3); + if (f_Vm(vinit - 2e-3, this) < 0) + vinit = halve(f_Vm, vinit + 2e-3, 1.0, 1e-3); + halved = true; + } + v1 = vinit; + } + dp_dv = f_Vm(v1, this); + if (fabs(dp_dv) < 1e-11) + { + if (f_Vm(v1 - 1e-4, this) < 0) + { + v1 = halve(f_Vm, v1 + 1e-4, 1.0, 1e-3); + dp_dv = f_Vm(v1, this); + } + } + } + if (it == 40) + { +// accept a (possible) whobble in the curve... +// error_msg("No convergence when calculating P in Peng-Robinson.", STOP); + } + if (V_m < v1) + P = R_TK / (v1 - b_sum) - a_aa_sum / (v1 * (v1 + 2 * b_sum) - b2); + } + } + if (P <= 0) // iterations = -1 + P = 1.; + } else + { + r3[1] = b_sum - R_TK / P; + r3_12 = r3[1] * r3[1]; + r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; + r3[3] = b2 * b_sum + (R_TK * b2 - b_sum * a_aa_sum) / P; + // solve t^3 + rp*t + rq = 0. + // molar volume V_m = t - r3[1] / 3... + rp = r3[2] - r3_12 / 3; + rp3 = rp * rp * rp; + rq = (2.0 * r3_12 * r3[1] - 9.0 * r3[1] * r3[2]) / 27 + r3[3]; + rz = rq * rq / 4 + rp3 / 27; + if (rz >= 0) // Cardono's method... + { + ri = sqrt(rz); + if (ri + rq / 2 <= 0) + { + V_m = pow(ri - rq / 2, one_3) + pow(- ri - rq / 2, one_3) - r3[1] / 3; + } + else + { + ri = - pow(ri + rq / 2, one_3); + V_m = ri - rp / (3.0 * ri) - r3[1] / 3; + } + } + else // use complex plane... + { + ri = sqrt(- rp3 / 27); // rp < 0 + ri1 = acos(- rq / 2 / ri); + V_m = 2.0 * pow(ri, one_3) * cos(ri1 / 3) - r3[1] / 3; + } + } + // calculate the fugacity coefficients... + for (i = 0; i < n_g; i++) + { + phase_ptr = phase_ptrs[i]; + if (phase_ptr->fraction_x == 0.0) + { + phase_ptr->pr_p = 0; + phase_ptr->pr_phi = 1; + phase_ptr->pr_si_f = 0.0; + continue; + } + phase_ptr->pr_p = phase_ptr->fraction_x * P; + if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + { + phase_ptr->pr_phi = 1; + continue; + } + rz = P * V_m / R_TK; + A = a_aa_sum * P / (R_TK * R_TK); + B = b_sum * P / R_TK; + B_r = phase_ptr->pr_b / b_sum; + if (rz > B) + phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + else + phi = -3.0; // fugacity coefficient > 0.05 + phase_ptr->pr_phi = exp(phi); + phase_ptr->pr_si_f = phi / LOG_10; + // for initial equilibrations, adapt log_k of the gas phase... + if (state < REACTION) + { + phase_ptr->lk = calc_lk_phase(phase_ptr, TK, P); + } + phase_ptr->pr_in = true; + } + if (gas_phase_ptr && iterations > 2) + { + gas_phase_ptr->Set_total_p(P); + gas_phase_ptr->Set_v_m(V_m); + return (OK); + } + return (V_m); +} + +LDBLE Phreeqc:: +f_Vm(LDBLE v1, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + Phreeqc * pThis; + + pThis = (Phreeqc *) cookie; + + LDBLE dp_dv = -pThis->R_TK / ((v1 - pThis->b_sum) * (v1 - pThis->b_sum)) + + pThis->a_aa_sum * (2 * v1 + 2 * pThis->b_sum) / + ((v1 * (v1 + 2. * pThis->b_sum) - pThis->b2) * (v1 * (v1 + 2. * pThis->b_sum) - pThis->b2)); + return dp_dv; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE si_org; +/* + * Fills in data for pure_phase assemglage in unknown structure + */ + + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); +/* + * Setup unknowns + */ + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + cxxPPassemblageComp * comp_ptr = &(it->second); + int j; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &j, FALSE); + assert(phase_ptr); + x[count_unknowns]->type = PP; + x[count_unknowns]->description = string_hsave(comp_ptr->Get_name().c_str()); + x[count_unknowns]->pp_assemblage_comp_name = x[count_unknowns]->description; + x[count_unknowns]->moles = comp_ptr->Get_moles(); + x[count_unknowns]->phase = phase_ptr; + x[count_unknowns]->si = comp_ptr->Get_si(); + si_org = comp_ptr->Get_si_org(); + /* si_org is used for Peng-Robinson gas, with the fugacity + coefficient added later in adjust_pure_phases, + when rxn_x has been defined for each phase in the model */ + x[count_unknowns]->delta = comp_ptr->Get_delta(); + x[count_unknowns]->dissolve_only = comp_ptr->Get_dissolve_only(); + if (pure_phase_unknown == NULL) + pure_phase_unknown = x[count_unknowns]; + count_unknowns++; + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct phase *phase_ptr; + LDBLE si_org; +/* + * Fills in data for pure_phase assemglage in unknown structure + */ + + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); +/* + * Setup unknowns + */ + for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) + { + x[count_unknowns]->type = PP; + x[count_unknowns]->description = + use.Get_pp_assemblage_ptr()->pure_phases[i].name; + x[count_unknowns]->moles = + use.Get_pp_assemblage_ptr()->pure_phases[i].moles; + x[count_unknowns]->phase = phase_ptr = + use.Get_pp_assemblage_ptr()->pure_phases[i].phase; + x[count_unknowns]->si = use.Get_pp_assemblage_ptr()->pure_phases[i].si; + si_org = use.Get_pp_assemblage_ptr()->pure_phases[i].si_org; + /* si_org is used for Peng-Robinson gas, with the fugacity + coefficient added later in adjust_pure_phases, + when rxn_x has been defined for each phase in the model */ + x[count_unknowns]->delta = + use.Get_pp_assemblage_ptr()->pure_phases[i].delta; + x[count_unknowns]->pure_phase = + &(use.Get_pp_assemblage_ptr()->pure_phases[i]); + x[count_unknowns]->dissolve_only = + use.Get_pp_assemblage_ptr()->pure_phases[i].dissolve_only; + if (pure_phase_unknown == NULL) + pure_phase_unknown = x[count_unknowns]; + count_unknowns++; + } + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +adjust_setup_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct phase *phase_ptr; + LDBLE si_org, p, t; +/* + * Fills in data for pure_phase assemglage in unknown structure + */ + + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); +/* + * Adjust si for gases + */ + for (i = 0; i < count_unknowns; i++) + { + std::vector phase_ptrs; + if (x[i]->type == PP) + { + phase_ptr = x[i]->phase; + phase_ptrs.push_back(phase_ptr); + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + si_org = comp_ptr->Get_si_org(); + if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) + { + p = exp(si_org * LOG_10); + t = use.Get_solution_ptr()->tc + 273.15; + if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) + { + calc_PR(phase_ptrs, p, t, 0); + } + x[i]->si = si_org + phase_ptr->pr_si_f; + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fills in data in unknown structure for the solution + */ + int l, i, j; + struct master *master_ptr; + struct solution *solution_ptr; + char *ptr; + char token[MAX_LENGTH]; + struct master_isotope *master_isotope_ptr; + struct phase *phase_ptr; + + solution_ptr = use.Get_solution_ptr(); + count_unknowns = 0; + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + /* solution_ptr->totals[i].skip = FALSE; */ + char * temp_desc = string_duplicate(solution_ptr->totals[i].description); + ptr = temp_desc; + copy_token(token, &ptr, &l); + master_ptr = master_bsearch(token); + /* + * Treat minor isotopes as special in initial solution calculation + */ + if ((state == INITIAL_SOLUTION) && (master_ptr != NULL) + && (master_ptr->minor_isotope == TRUE) + && (initial_solution_isotopes == FALSE)) + { + master_isotope_ptr = master_isotope_search(token); + if (master_isotope_ptr != NULL) + { + master_isotope_ptr->ratio = + solution_ptr->totals[i].input_conc; + } + /* solution_ptr->totals[i].skip = TRUE; */ + free_check_null(temp_desc); + continue; + } +/* + * Check that total not <= zero + */ + if (solution_ptr->totals[i].input_conc <= 0.0) + { + if (strcmp(token, "H(1)") != 0 && strcmp(token, "E") != 0) + { + /* solution_ptr->totals[i].skip = TRUE; */ + free_check_null(temp_desc); + continue; + } + } +/* + * Find master species + */ + master_ptr = master_bsearch(token); + if (master_ptr == NULL) + { + /* solution_ptr->totals[i].skip = TRUE; */ + error_string = sformatf( + "Master species not in data base for %s, skipping element.", + solution_ptr->totals[i].description); + warning_msg(error_string); + free_check_null(temp_desc); + continue; + } + if (master_ptr->type != AQ) + { + /* solution_ptr->totals[i].skip = TRUE; */ + error_string = sformatf( + "Only aqueous concentrations are allowed in solution data, ignoring %s.", + solution_ptr->totals[i].description); + warning_msg(error_string); + free_check_null(temp_desc); + continue; + } +/* + * Store list of master species pointers, set master[i].in and master[i].rxn for list + */ + x[count_unknowns]->master = get_list_master_ptrs(ptr, master_ptr); + setup_master_rxn(x[count_unknowns]->master, + &(pe_x[solution_ptr->totals[i].n_pe].rxn)); + +/* + * Set default unknown data + */ + x[count_unknowns]->type = MB; + x[count_unknowns]->description = solution_ptr->totals[i].description; + x[count_unknowns]->total = &(solution_ptr->totals[i]); + for (j = 0; x[count_unknowns]->master[j] != NULL; j++) + { + x[count_unknowns]->master[j]->unknown = x[count_unknowns]; + } + x[count_unknowns]->moles = solution_ptr->totals[i].moles; +/* + * Set pointers + */ + free_check_null(temp_desc); + temp_desc = string_duplicate(solution_ptr->totals[i].description); + ptr = temp_desc; + copy_token(token, &ptr, &l); + str_tolower(token); + if (strstr(token, "alk") != NULL) + { + if (alkalinity_unknown == NULL) + { + x[count_unknowns]->type = ALK; + alkalinity_unknown = x[count_unknowns]; + } + else + { + error_msg("Alkalinity entered more than once.", CONTINUE); + input_error++; + } + } + else if (strcmp(token, "c") == 0 || strcmp(token, "c(4)") == 0) + { + if (carbon_unknown == NULL) + { + carbon_unknown = x[count_unknowns]; + } + else + { + error_msg("Carbon entered more than once.", CONTINUE); + input_error++; + } + } + else if (strcmp(token, "h(1)") == 0) + { + if (ph_unknown == NULL) + { + ph_unknown = x[count_unknowns]; + } + else + { + error_msg("pH entered more than once.", CONTINUE); + input_error++; + } + } + else if (strcmp(token, "e") == 0) + { + if (pe_unknown == NULL) + { + pe_unknown = x[count_unknowns]; + } + else + { + error_msg("pe entered more than once.", CONTINUE); + input_error++; + } + } + free_check_null(temp_desc); +/* + * Charge balance unknown + */ + if (solution_ptr->totals[i].equation_name != NULL) + { + char * temp_eq_name = string_duplicate(solution_ptr->totals[i].equation_name); + ptr = temp_eq_name; + copy_token(token, &ptr, &l); + str_tolower(token); + if (strstr(token, "charge") != NULL) + { + if (charge_balance_unknown == NULL) + { + charge_balance_unknown = x[count_unknowns]; + x[count_unknowns]->type = CB; + if (charge_balance_unknown == ph_unknown) + { + x[count_unknowns]->moles = solution_ptr->cb; + } + } + else + { + error_msg("Charge balance specified for more" + " than one species.", CONTINUE); + input_error++; + } + } + else + { +/* + * Solution phase boundaries + */ + solution_ptr->totals[i].phase = + phase_bsearch(solution_ptr->totals[i].equation_name, &l, + FALSE); + if (solution_ptr->totals[i].phase == NULL) + { + error_string = sformatf( "Expected a mineral name, %s.", + solution_ptr->totals[i].equation_name); + error_msg(error_string, CONTINUE); + input_error++; + } + x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; + phase_ptr = solution_ptr->totals[i].phase; + x[count_unknowns]->phase = phase_ptr; + x[count_unknowns]->si = solution_ptr->totals[i].phase_si; + /* For Peng-Robinson gas, the fugacity + coefficient is added later in adjust_setup_solution, + when rxn_x has been defined for each phase in the model */ + if (solution_phase_boundary_unknown == NULL) + { + solution_phase_boundary_unknown = x[count_unknowns]; + } + } + free_check_null(temp_eq_name); + } + count_unknowns++; + } +/* + * Set mb_unknown + */ + if (count_unknowns > 0) + mb_unknown = x[0]; +/* + * Special for alkalinity + */ + if (alkalinity_unknown != NULL) + { + if (carbon_unknown != NULL) + { +/* + * pH adjusted to obtain given alkalinity + */ + if (ph_unknown == NULL) + { + output_msg(sformatf("\npH will be adjusted to obtain desired alkalinity.\n\n")); + ph_unknown = alkalinity_unknown; + master_ptr = master_bsearch("H(1)"); + alkalinity_unknown->master[0] = master_ptr; + master_ptr->in = TRUE; + master_ptr->unknown = ph_unknown; + ph_unknown->master[0] = master_ptr; + ph_unknown->description = string_hsave("H(1)"); + } + else + { + error_msg("pH adjustment is needed for alkalinity but" + " charge balance or a phase boundary was also specified.", + CONTINUE); + input_error++; + } +/* + * Carbonate ion adjusted to obtain given alkalintiy + */ + } + else + { + if (alkalinity_unknown->master[0]->s->secondary != NULL) + { + alkalinity_unknown->master[0]->s->secondary->in = TRUE; + alkalinity_unknown->master[0]->s->secondary->unknown = + alkalinity_unknown; + } + else + { + error_msg + ("Error in definition of Alkalinity in SOLUTION_MASTER_SPECIES and SOLUTION_SPECIES.\n\tAlkalinity master species should be same as master species for C(4).", + CONTINUE); + input_error++; + } + } + } + if (pitzer_model == FALSE && sit_model == FALSE) + { + /* + * Ionic strength + */ + mu_unknown = x[count_unknowns]; + x[count_unknowns]->description = string_hsave("Mu"); + x[count_unknowns]->type = MU; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->moles = 0.0; + mu_unknown = x[count_unknowns]; + count_unknowns++; + } + /* + * Activity of water + */ + ah2o_unknown = x[count_unknowns]; + ah2o_unknown->description = string_hsave("A(H2O)"); + ah2o_unknown->type = AH2O; + ah2o_unknown->number = count_unknowns; + ah2o_unknown->master = unknown_alloc_master(); + ah2o_unknown->master[0] = master_bsearch("O"); + ah2o_unknown->master[0]->unknown = ah2o_unknown; + ah2o_unknown->moles = 0.0; + count_unknowns++; + + if (state >= REACTION) + { +/* + + * Reaction: pH for charge balance + */ + ph_unknown = x[count_unknowns]; + ph_unknown->description = string_hsave("pH"); + ph_unknown->type = CB; + ph_unknown->moles = solution_ptr->cb; + ph_unknown->number = count_unknowns; + ph_unknown->master = unknown_alloc_master(); + ph_unknown->master[0] = s_hplus->primary; + ph_unknown->master[0]->unknown = ph_unknown; + charge_balance_unknown = ph_unknown; + count_unknowns++; +/* + * Reaction: pe for total hydrogen + */ + pe_unknown = x[count_unknowns]; + mass_hydrogen_unknown = x[count_unknowns]; + mass_hydrogen_unknown->description = string_hsave("Hydrogen"); + mass_hydrogen_unknown->type = MH; +#ifdef COMBINE + mass_hydrogen_unknown->moles = + solution_ptr->total_h - 2 * solution_ptr->total_o; +#else + mass_hydrogen_unknown->moles = solution_ptr->total_h; +#endif + mass_hydrogen_unknown->number = count_unknowns; + mass_hydrogen_unknown->master = unknown_alloc_master(); + mass_hydrogen_unknown->master[0] = s_eminus->primary; + mass_hydrogen_unknown->master[0]->unknown = mass_hydrogen_unknown; + count_unknowns++; +/* + * Reaction H2O for total oxygen + */ + mass_oxygen_unknown = x[count_unknowns]; + mass_oxygen_unknown->description = string_hsave("Oxygen"); + mass_oxygen_unknown->type = MH2O; + mass_oxygen_unknown->moles = solution_ptr->total_o; + mass_oxygen_unknown->number = count_unknowns; + mass_oxygen_unknown->master = unknown_alloc_master(); + mass_oxygen_unknown->master[0] = s_h2o->primary; + count_unknowns++; + } +/* + * Validity tests + */ + if ((ph_unknown != NULL) && + (ph_unknown == charge_balance_unknown) + && (alkalinity_unknown != NULL)) + { + error_msg("pH adustment can not attain charge balance" + " when alkalinity is fixed.", CONTINUE); + input_error++; + } + if ((alkalinity_unknown != NULL) && + (alkalinity_unknown->type == CB || + alkalinity_unknown->type == SOLUTION_PHASE_BOUNDARY)) + { + error_msg("Alkalinity can not be used with charge balance" + " or solution phase boundary constraints.", CONTINUE); + input_error++; + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +adjust_setup_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fills in data in unknown structure for the solution + */ + int i; + struct phase *phase_ptr; + LDBLE p, t; + + for (i = 0; i < count_unknowns; i++) + { + std::vector phase_ptrs; + if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + //solution_ptr->totals[i].phase = + // phase_bsearch(solution_ptr->totals[i].equation_name, &l, + // FALSE); + //if (solution_ptr->totals[i].phase == NULL) + //{ + // error_string = sformatf( "Expected a mineral name, %s.", + // solution_ptr->totals[i].equation_name); + // error_msg(error_string, CONTINUE); + // input_error++; + //} + x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; + //phase_ptr = solution_ptr->totals[i].phase; + //x[count_unknowns]->phase = phase_ptr; + //x[count_unknowns]->si = solution_ptr->totals[i].phase_si; + + phase_ptr = x[i]->phase; + phase_ptrs.push_back(phase_ptr); + if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) + { + p = exp(x[i]->si * LOG_10); + t = use.Get_solution_ptr()->tc + 273.15; + if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) + { + calc_PR(phase_ptrs, p, t, 0); + } + x[i]->si += phase_ptr->pr_si_f; + } + } + } + return (OK); + +} +/* ---------------------------------------------------------------------- */ +struct master ** Phreeqc:: +unknown_alloc_master(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space for a list of 2 master pointers + */ + struct master **master_ptr; + + master_ptr = (struct master **) PHRQ_malloc(2 * sizeof(struct master *)); + if (master_ptr == NULL) + malloc_error(); + master_ptr[0] = NULL; + master_ptr[1] = NULL; + return (master_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_unknowns(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Counts unknowns and allocates space for unknown structures + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.Get_solution_ptr(); +/* + * Calculate maximum number of unknowns + */ + max_unknowns = 0; +/* + * Count mass balance in solution + */ + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + max_unknowns++; +/* + * Add 5 for ionic strength, activity of water, charge balance, total H, total O + */ + max_unknowns += 5; +/* + * Count pure phases + */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + max_unknowns += (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); + //max_unknowns += use.Get_pp_assemblage_ptr()->count_comps; + +/* + for (i = 0; use.Get_pp_assemblage_ptr()->pure_phases[i].name != NULL; i++ ) { + max_unknowns++; + } + */ + } +/* + * Count exchange + */ + if (use.Get_exchange_ptr() != NULL) + { + cxxExchange *exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); + std::vector comps = exchange_ptr->Vectorize(); + for (size_t j = 0; j < comps.size(); j++) + { + cxxExchComp * comp_ptr = comps[j]; + cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + for ( ; it != nd.end(); it++) + { + element * elt_ptr = element_store(it->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + error_string = sformatf( + "Master species missing for element %s", + it->first.c_str()); + error_msg(error_string, STOP); + } + if (elt_ptr->master->type == EX) + { + max_unknowns++; + } + } + } + } +/* + * Count surfaces + */ + if (use.Get_surface_ptr() != NULL) + { + if (use.Get_surface_ptr()->type != CD_MUSIC) + { + max_unknowns += + use.Get_surface_ptr()->count_comps + use.Get_surface_ptr()->count_charge; + } + else + { + max_unknowns += + use.Get_surface_ptr()->count_comps + + 4 * use.Get_surface_ptr()->count_charge; + } + } +/* + * Count gas components + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) + { + max_unknowns += gas_phase_ptr->Get_gas_comps().size(); + } + else + { + max_unknowns++; + } + } +/* + * Count solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + /* max_unknowns += 2 * use.Get_ss_assemblage_ptr()->count_s_s; */ + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + max_unknowns += use.Get_ss_assemblage_ptr()->s_s[i].count_comps; + } + } + +/* + * Pitzer/Sit + */ + max_unknowns++; + if (pitzer_model == TRUE || sit_model == TRUE) + { + max_unknowns += count_s; + } +/* + * One for slack + */ + max_unknowns++; + +/* + * Allocate space for pointer array and structures + */ + + space((void **) ((void *) &x), INIT, &max_unknowns, + sizeof(struct unknown *)); + for (i = 0; i < max_unknowns; i++) + { + x[i] = (struct unknown *) unknown_alloc(); + x[i]->number = i; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_dn(int k, LDBLE * source, int row, LDBLE coef_in, LDBLE * gamma_source) +/* ---------------------------------------------------------------------- */ +{ +/* + * Stores the terms for d moles of species k in solution into row, multiplied + * by coef_in + */ + int col; + LDBLE coef; + struct rxn_token *rxn_ptr; + struct master *master_ptr; + + if (equal(coef_in, 0.0, TOL) == TRUE) + { + return (OK); + } +/* Gamma term for d molality of species */ +/* Note dg includes molality as a factor */ + + row = row * (count_unknowns + 1); + if (s[k]->type != SURF && s[k] != s_h2o) + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + "Activity coefficient", (double) (-1.0 * coef_in), + row / (count_unknowns + 1), mu_unknown->number)); + } + /* mu term */ + if (gamma_source != NULL) + { + store_jacob(gamma_source, &array[row + mu_unknown->number], + -1.0 * coef_in); + } + } +/* + * Mass of water factor + */ + if (mass_oxygen_unknown != NULL && s[k]->type != EX && s[k]->type != SURF) + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + mass_oxygen_unknown->master[0]->s->name, + (double) coef_in, row / (count_unknowns + 1), + mass_oxygen_unknown->number)); + } + store_jacob(source, &(array[row + mass_oxygen_unknown->number]), + coef_in); + } + if (s[k] == s_h2o) + return (OK); + for (rxn_ptr = s[k]->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%s\n", master_ptr->s->name)); + } + if (master_ptr->unknown == NULL) + continue; + col = master_ptr->unknown->number; + coef = coef_in * rxn_ptr->coef; + store_jacob(source, &(array[row + col]), coef); + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d\n", + master_ptr->s->name, (double) coef, + row / (count_unknowns + 1), col)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_jacob(LDBLE * source, LDBLE * target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds a new item to either sum_jacob1 or sum_jacob2 + * If coef is 1.0, adds to sum_jacob1, which does not require a multiply + * Otherwise, adds to sum_jacob2, which allows multiply by coef + */ + if (equal(coef, 1.0, TOL) == TRUE) + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\tjacob1 %d\n", count_sum_jacob1)); + } + sum_jacob1[count_sum_jacob1].source = source; + sum_jacob1[count_sum_jacob1++].target = target; + /* Check space */ + if (count_sum_jacob1 >= max_sum_jacob1) + { + space((void **) ((void *) &sum_jacob1), count_sum_jacob1, + &max_sum_jacob1, sizeof(struct list1)); + } + } + else + { + if (debug_prep == TRUE) + { + output_msg(sformatf( "\t\tjacob2 %d\n", count_sum_jacob2)); + } + sum_jacob2[count_sum_jacob2].source = source; + sum_jacob2[count_sum_jacob2].target = target; + sum_jacob2[count_sum_jacob2++].coef = coef; + /* Check space */ + if (count_sum_jacob2 >= max_sum_jacob2) + { + space((void **) ((void *) &sum_jacob2), count_sum_jacob2, + &max_sum_jacob2, sizeof(struct list2)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_jacob0(int row, int column, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Stores in list a constant coef which will be added into jacobian array + */ + sum_jacob0[count_sum_jacob0].target = + &(array[row * (count_unknowns + 1) + column]); + sum_jacob0[count_sum_jacob0++].coef = coef; + /* Check space */ + if (count_sum_jacob0 >= max_sum_jacob0) + { + space((void **) ((void *) &sum_jacob0), count_sum_jacob0, + &max_sum_jacob0, sizeof(struct list0)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_mb(LDBLE * source, LDBLE * target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds item to list sum_mb1 or sum_mb2 + * If coef is 1.0, adds to sum_mb1, which does not require a multiply + * else, adds to sum_mb2, which will multiply by coef + */ + if (equal(coef, 1.0, TOL) == TRUE) + { + sum_mb1[count_sum_mb1].source = source; + sum_mb1[count_sum_mb1++].target = target; + if (count_sum_mb1 >= max_sum_mb1) + { + space((void **) ((void *) &sum_mb1), + count_sum_mb1 + count_trxn + 4, &max_sum_mb1, + sizeof(struct list1)); + } + } + else + { + sum_mb2[count_sum_mb2].source = source; + sum_mb2[count_sum_mb2].coef = coef; + sum_mb2[count_sum_mb2++].target = target; + if (count_sum_mb2 >= max_sum_mb2) + { + space((void **) ((void *) &sum_mb2), count_sum_mb2, + &max_sum_mb2, sizeof(struct list2)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * List sum_delta is summed to determine the change in the mass of + * each element due to mass transfers of minerals, changes show up + * in x[i]->delta. These may be multiplied by a factor under some + * situations where the entire calculated step is not taken + */ + sum_delta[count_sum_delta].source = source; + sum_delta[count_sum_delta].target = target; + sum_delta[count_sum_delta++].coef = coef; + /* Check space */ + if (count_sum_delta >= max_sum_delta) + { + space((void **) ((void *) &sum_delta), count_sum_delta, + &max_sum_delta, sizeof(struct list2)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +switch_bases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check if activity of first master species is predominant among activities of + * secondary master species included in mass balance. + */ + int i, j; + int first; + int return_value; + LDBLE la, la1; + struct master *master_ptr; + + return_value = FALSE; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != MB) + continue; + first = 0; + la = x[i]->master[0]->s->la; + for (j = 1; x[i]->master[j] != NULL; j++) + { + la1 = x[i]->master[j]->s->lm + x[i]->master[j]->s->lg; + if (first == 0 && la1 > la + 10.) + { + la = la1; + first = j; + } + else if (first != 0 && la1 > la) + { + la = la1; + first = j; + } + } + if (first != 0) + { + master_ptr = x[i]->master[0]; + x[i]->master[0] = x[i]->master[first]; + x[i]->master[0]->in = TRUE; + x[i]->master[first] = master_ptr; + x[i]->master[first]->in = REWRITE; +/* + fprintf(stderr, "Switching bases to %s.\tIteration %d\n", + x[i]->master[0]->s->name, iterations, la, x[i]->master[0]->s->la); + */ + x[i]->master[0]->s->la = la; + + log_msg(sformatf( "Switching bases to %s.\tIteration %d\n", + x[i]->master[0]->s->name, iterations)); + return_value = TRUE; + } + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_redox(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write pe redox reactions (rxn in struct pe_data) in terms of master species + * defined in analytical data + * + */ + int i, j, l; + char *ptr; + char token[MAX_LENGTH], tok1[MAX_LENGTH], tok2[MAX_LENGTH]; + struct pe_data *pe_data_ptr; + struct master *master_ptr1, *master_ptr2; +/* + * Keep valences of oxygen and hydrogen in model, if not already in + */ + for (i = 0; i < count_master; i++) + { + if (master[i]->primary == TRUE && + (master[i]->s == s_hplus || master[i]->s == s_h2o)) + { + j = i + 1; + while (j < count_master && master[j]->elt->primary == master[i]) + { + if (master[j]->in == FALSE && master[j]->s != master[i]->s) + { + master[j]->in = REWRITE; + master[j]->pe_rxn = master[i]->pe_rxn; + } + j++; + } + } + } +/* + * Writes equations for e- for each redox couple used in solution n + */ + for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) + { + if (strcmp_nocase_arg1(pe_data_ptr->name, "pe") == 0) + { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); + } + else + { + strcpy(token, pe_data_ptr->name); + replace("/", " ", token); + ptr = token; +/* + * Get redox states and elements from redox couple + */ + copy_token(tok1, &ptr, &l); + copy_token(tok2, &ptr, &l); +/* + * Find master species + */ + master_ptr1 = master_bsearch(tok1); + master_ptr2 = master_bsearch(tok2); + if (master_ptr1 != NULL && master_ptr2 != NULL) + { + rewrite_master_to_secondary(master_ptr1, master_ptr2); +/* + * Rewrite equation to e- + */ + trxn_swap("e-"); + } + else + { + error_string = sformatf( + "Can not find master species for redox couple, %s.", + pe_data_ptr->name); + error_msg(error_string, STOP); + } + if (inout() == FALSE) + { + error_string = sformatf( + "Analytical data missing for redox couple, %s\n\t Using pe instead.", + pe_data_ptr->name); + warning_msg(error_string); + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); + pe_data_ptr->name = pe_x[0].name; + } + else + { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_alloc(count_trxn + 1); + trxn_copy(pe_data_ptr->rxn); + } + } + } +/* + * Rewrite equations to master species that are "in" the model + */ + for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) + { + count_trxn = 0; + trxn_add(pe_data_ptr->rxn, 1.0, FALSE); + if (write_mass_action_eqn_x(CONTINUE) == FALSE) + { + error_string = sformatf( "Could not rewrite redox " + "couple equation for %s\n\t Possibly missing data for one " + "of the redox states.", pe_data_ptr->name); + warning_msg(error_string); + error_string = sformatf( "Using pe instead of %s.", + pe_data_ptr->name); + warning_msg(error_string); + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_dup(pe_x[0].rxn); + pe_data_ptr->name = pe_x[0].name; + } + else + { + rxn_free(pe_data_ptr->rxn); + pe_data_ptr->rxn = rxn_alloc(count_trxn + 1); + trxn_copy(pe_data_ptr->rxn); + } + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +write_mb_eqn_x(void) +/* ---------------------------------------------------------------------- */ +{ + int count, repeat; + int i, count_rxn_orig; + int j, k; + struct master *master_ptr; +/* + * Rewrite any secondary master species flagged REWRITE + * Don't add in any pe reactions + */ + count = 0; + repeat = TRUE; + while (repeat == TRUE) + { + count++; + if (count > MAX_ADD_EQUATIONS) + { + error_string = sformatf( "Could not reduce equation " + "to primary and secondary species that are " + "in the model, %s.", trxn.token[0].s->name); + error_msg(error_string, CONTINUE); + return (ERROR); + } + repeat = FALSE; + count_rxn_orig = count_trxn; + for (i = 1; i < count_rxn_orig; i++) + { + if (trxn.token[i].s->secondary == NULL) + continue; + if (trxn.token[i].s->secondary->in == REWRITE) + { + repeat = TRUE; + trxn_add(trxn.token[i].s->secondary->rxn_secondary, + trxn.token[i].coef, FALSE); + } + } + trxn_combine(); + } +/* + * + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) + { + j = count_elts; + char * temp_name = string_duplicate(trxn.token[i].s->name); + char * ptr = temp_name; + get_elts_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + for (k = j; k < count_elts; k++) + { + if (trxn.token[i].s->secondary != NULL) + { + master_ptr = trxn.token[i].s->secondary->elt->primary; + } + else + { + master_ptr = trxn.token[i].s->primary; + } + if (elt_list[k].elt == master_ptr->elt) + { + elt_list[k].coef = 0.0; + break; + } + } + if (trxn.token[i].s->secondary == NULL) + { + char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + } + else + { + char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); + ptr = temp_name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +write_mb_for_species_list(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets up data to add to species_list + * Original secondary redox states are retained + */ + int i; +/* + * Start with secondary reaction + */ + count_trxn = 0; + trxn_add(s[n]->rxn_s, 1.0, FALSE); +/* + * Copy to elt_list + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->secondary == NULL) + { + char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); + char * ptr = temp_name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + } + else + { + char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); + char * ptr = temp_name; + if (get_secondary_in_species(&ptr, trxn.token[i].coef) == ERROR) + { + input_error++; + error_string = sformatf( "Error parsing %s.", trxn.token[i].s->secondary->elt->name); + error_msg(error_string, CONTINUE); + } + free_check_null(temp_name); + } + } + for (i = 0; i < count_elts; i++) + { + if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_h_one; + elt_list[count_elts].coef = elt_list[i].coef * 2; + count_elts++; + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + s[n]->next_sys_total = + (struct elt_list *) free_check_null(s[n]->next_sys_total); + s[n]->next_sys_total = elt_list_save(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +write_phase_sys_total(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets up data to add to species_list + * Original secondary redox states are retained + */ + int i; +/* + * Start with secondary reaction + */ + count_trxn = 0; + trxn_add_phase(phases[n]->rxn_s, 1.0, FALSE); +/* + * Copy to elt_list + */ + count_elts = 0; + paren_count = 0; + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->secondary == NULL) + { + char * temp_name = string_duplicate(trxn.token[i].s->primary->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + } + else + { + char * temp_name = string_duplicate(trxn.token[i].s->secondary->elt->name); + char *ptr = temp_name; + get_secondary_in_species(&ptr, trxn.token[i].coef); + free_check_null(temp_name); + } + } + for (i = 0; i < count_elts; i++) + { + if (strcmp(elt_list[i].elt->name, "O(-2)") == 0) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_h_one; + elt_list[count_elts].coef = elt_list[i].coef * 2; + count_elts++; + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + phases[n]->next_sys_total = + (struct elt_list *) free_check_null(phases[n]->next_sys_total); + phases[n]->next_sys_total = elt_list_save(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_delta_v(reaction *r_ptr, bool phase) +/* ---------------------------------------------------------------------- */ +{ +/* calculate delta_v from molar volumes */ + + int p = -1; + LDBLE d_v = 0.0; + + if (phase) + p = 1; /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ + + for (size_t i = 0; r_ptr->token[i].name; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += p * r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + } + return d_v; +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ +/* + * calculate log_k for a single phase, correct for pressure + */ + + reaction *r_ptr = (p_ptr->rxn_x ? p_ptr->rxn_x :\ + (p_ptr->rxn_s ? p_ptr->rxn_s : NULL)); + if (!r_ptr) + return 0.0; + if (!r_ptr->logk[vm0]) + return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); + + LDBLE tc = TK - 273.15; + LDBLE kp_t, d_v = 0.0; + + for (size_t i = 0; r_ptr->token[i].name; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H2O")) + { + d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); + } + else if (r_ptr->token[i].s->logk[vm0]) + { + d_v += r_ptr->token[i].coef * (r_ptr->token[i].s->logk[vm0] +\ + (r_ptr->token[i].s->logk[vm1] + r_ptr->token[i].s->logk[vm2] * tc) * tc); + if (r_ptr->token[i].s->logk[kappa]) + { + kp_t = r_ptr->token[i].s->logk[kappa]; + //if (r_ptr->token[i].s->z > 0) + //{ + // /* correct kappa of cations for temperature, but kappa should be <= 0, Table 43.6 */ + // kp_t += 4e-5 * (tc - 25); + // if (kp_t > 0) + // kp_t = 0; + //} + d_v += kp_t * pa; + } + } + } + d_v -= p_ptr->logk[vm0] + (p_ptr->logk[vm1] * tc + p_ptr->logk[vm2] * tc) * tc; + r_ptr->logk[delta_v] = d_v; + + if (!strcmp(r_ptr->token[0].name, "H2O(g)")) + r_ptr->logk[delta_v] = 0.0; + + return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_vm(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculate molar volumes for aqueous species, using the millero parm's. + * Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm. + */ + LDBLE kp_t; + + /* S_v * Iv^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221, + Use mu_x for the volume averaged Iv, the difference is negligible....*/ + LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(mu_x); + // Sv_I = 0.0; + for (int i = 0; i < count_s_x; i++) + { + if (!strcmp(s_x[i]->name, "H2O")) + { + s_x[i]->logk[vm_tc] = 18.016 / rho_0; + continue; + } + if (!s_x[i]->logk[vm0]) + continue; + /* the volume terms... */ + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; + if (s_x[i]->logk[kappa]) + { + kp_t = s_x[i]->logk[kappa]; + //if (s_x[i]->z > 0) + //{ + // /* correct kappa of cations for temperature, but kappa should be <= 0, Table 43.6 */ + // kp_t += 4e-5 * (tc - 25); + // if (kp_t > 0) + // kp_t = 0; + //} + s_x[i]->rxn_x->logk[vm_tc] += kp_t * pa; + } + + /* the ionic strength term * Iv^0.5... */ + s_x[i]->rxn_x->logk[vm_tc] += 0.5 * s_x[i]->z * s_x[i]->z * Sv_I; + /* plus the volume terms * Iv, take mu_x for Iv... */ + //s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x; + + /* for calculating delta_v of the reaction... */ + s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates log k's for all species and pure_phases + */ + if (same_model == TRUE && same_temperature == TRUE && same_pressure == TRUE) + return (OK); + int i; + LDBLE tempk = tc + 273.15; +/* + * Calculate log k for all aqueous species + */ + /* calculate relative molar volumes for tc... */ + rho_0 = calc_rho_0(tc, pa); + calc_vm(tc, pa); + + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->rxn_x->logk[vm_tc]) + /* calculate delta_v for the reaction... */ + s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); + + if (same_model && same_temperature && s_x[i]->rxn_x->logk[delta_v] == 0) + continue; + s_x[i]->lk = k_calc(s_x[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); + } +/* + * Calculate log k for all pure phases + */ + for (i = 0; i < count_phases; i++) + { + if (phases[i]->in == TRUE) + { + phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - + (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc + phases[i]->logk[vm2] * tc * tc); + phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); + } + } +/* + * Calculate miscibility gaps for solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + if (fabs(tempk - use.Get_ss_assemblage_ptr()->s_s[i].tk) > 0.01) + { + s_s_prep(tempk, &(use.Get_ss_assemblage_ptr()->s_s[i]), FALSE); + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +k_calc(LDBLE * l_logk, LDBLE tempk, LDBLE presPa) +/* ---------------------------------------------------------------------- */ +{ + /* + * Calculates log k at specified temperature and pressure + * Returns calculated log k. + * + * delta_v is in cm3/mol. + */ + + /* Molar energy */ + LDBLE me = tempk * R_KJ_DEG_MOL; + + /* Pressure difference */ + LDBLE delta_p = presPa - REF_PRES_PASCAL; + + /* Calculate new log k value for this temperature and pressure */ + LDBLE lk = l_logk[logK_T0] + - l_logk[delta_h] * (298.15 - tempk) / (LOG_10 * me * 298.15) + + l_logk[T_A1] + + l_logk[T_A2] * tempk + + l_logk[T_A3] / tempk + + l_logk[T_A4] * log10(tempk) + + l_logk[T_A5] / (tempk * tempk) + + l_logk[T_A6] * tempk * tempk; + if (delta_p > 0) + /* cm3 * J /mol = 1e-9 m3 * kJ /mol */ + lk -= l_logk[delta_v] * 1E-9 * delta_p / (LOG_10 * me); + return lk; +} + + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +save_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * save temperature + */ + last_model.temperature = tc_x; +/* + * save pressure + */ + last_model.pressure = patm_x; +/* + * mark master species + */ + for (i = 0; i < count_master; i++) + { + master[i]->last_model = FALSE; + if (master[i]->total > 0) + { + if (master[i]->primary == TRUE) + { + master[i]->last_model = TRUE; + } + else + { + /* mark primary master */ + master[i]->s->secondary->elt->primary->last_model = TRUE; + } + } + } +/* + * save list of phase pointers for gas phase + */ + last_model.gas_phase = + (struct phase **) free_check_null(last_model.gas_phase); + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + last_model.count_gas_phase = (int) gas_phase_ptr->Get_gas_comps().size(); + last_model.gas_phase = + (struct phase **) PHRQ_malloc((size_t) last_model.count_gas_phase * + sizeof(struct phase *)); + if (last_model.gas_phase == NULL) + malloc_error(); + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + assert(phase_ptr); + last_model.gas_phase[i] = phase_ptr; + } + } + else + { + last_model.count_gas_phase = 0; + last_model.gas_phase = NULL; + } +/* + * save list of names of solid solutions + */ + last_model.ss_assemblage = + (const char **) free_check_null(last_model.ss_assemblage); + if (use.Get_ss_assemblage_ptr() != NULL) + { + last_model.count_ss_assemblage = use.Get_ss_assemblage_ptr()->count_s_s; + last_model.ss_assemblage = + (const char **) PHRQ_malloc((size_t) use.Get_ss_assemblage_ptr()-> + count_s_s * sizeof(char *)); + if (last_model.ss_assemblage == NULL) + malloc_error(); + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + last_model.ss_assemblage[i] = + use.Get_ss_assemblage_ptr()->s_s[i].name; + } + } + else + { + last_model.count_ss_assemblage = 0; + last_model.ss_assemblage = NULL; + } +/* + * save list of phase pointers for pp_assemblage + */ + last_model.pp_assemblage = + (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.add_formula = + (const char **) free_check_null(last_model.add_formula); + last_model.si = (LDBLE *) free_check_null(last_model.si); + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + last_model.count_pp_assemblage = (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); + last_model.pp_assemblage = + (struct phase **) PHRQ_malloc((size_t) last_model.count_pp_assemblage * + sizeof(struct phase *)); + if (last_model.pp_assemblage == NULL) + malloc_error(); + last_model.add_formula = + (const char **) PHRQ_malloc((size_t)last_model.count_pp_assemblage * sizeof(char *)); + if (last_model.add_formula == NULL) + malloc_error(); + last_model.si = + (LDBLE *) PHRQ_malloc((size_t) last_model.count_pp_assemblage * sizeof(LDBLE)); + if (last_model.si == NULL) + malloc_error(); + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + i = 0; + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + int j; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &j, false); + assert(phase_ptr); + last_model.pp_assemblage[i] = phase_ptr; + last_model.add_formula[i] = string_hsave(it->second.Get_add_formula().c_str()); + last_model.si[i] = it->second.Get_si(); + i++; + } + } + else + { + last_model.count_pp_assemblage = 0; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + } +#ifdef SKIP + if (use.Get_pp_assemblage_ptr() != NULL) + { + last_model.count_pp_assemblage = use.Get_pp_assemblage_ptr()->count_comps; + last_model.pp_assemblage = + (struct phase **) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> + count_comps * + sizeof(struct phase *)); + if (last_model.pp_assemblage == NULL) + malloc_error(); + last_model.add_formula = + (const char **) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> + count_comps * sizeof(char *)); + if (last_model.add_formula == NULL) + malloc_error(); + last_model.si = + (LDBLE *) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> + count_comps * sizeof(LDBLE)); + if (last_model.si == NULL) + malloc_error(); + for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) + { + last_model.pp_assemblage[i] = + use.Get_pp_assemblage_ptr()->pure_phases[i].phase; + last_model.add_formula[i] = + use.Get_pp_assemblage_ptr()->pure_phases[i].add_formula; + last_model.si[i] = use.Get_pp_assemblage_ptr()->pure_phases[i].si; + } + } + else + { + last_model.count_pp_assemblage = 0; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + } +#endif +/* + * save data for surface + */ + last_model.surface_comp = + (const char **) free_check_null(last_model.surface_comp); + last_model.surface_charge = + (const char **) free_check_null(last_model.surface_charge); + if (use.Get_surface_ptr() != NULL) + { + /* comps */ + last_model.count_surface_comp = use.Get_surface_ptr()->count_comps; + last_model.surface_comp = + (const char **) PHRQ_malloc((size_t) use.Get_surface_ptr()->count_comps * + sizeof(char *)); + if (last_model.surface_comp == NULL) + malloc_error(); + for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + { + last_model.surface_comp[i] = use.Get_surface_ptr()->comps[i].formula; + } + /* charge */ + last_model.count_surface_charge = use.Get_surface_ptr()->count_charge; + last_model.surface_charge = + (const char **) PHRQ_malloc((size_t) use.Get_surface_ptr()->count_charge * + sizeof(char *)); + if (last_model.surface_charge == NULL) + malloc_error(); + for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + { + last_model.surface_charge[i] = use.Get_surface_ptr()->charge[i].name; + } + last_model.dl_type = use.Get_surface_ptr()->dl_type; + /*last_model.edl = use.Get_surface_ptr()->edl; */ + last_model.surface_type = use.Get_surface_ptr()->type; + } + else + { + last_model.dl_type = NO_DL; + /*last_model.edl = -1; */ + last_model.surface_type = UNKNOWN_DL; + last_model.count_surface_comp = 0; + last_model.surface_comp = NULL; + last_model.count_surface_charge = 0; + last_model.surface_charge = NULL; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_same_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Force new model to be built in prep + */ + if (last_model.force_prep == TRUE) + { + last_model.force_prep = FALSE; + same_temperature = FALSE; + same_pressure = FALSE; + return (FALSE); + } +/* + * Check temperature + */ + if (fabs(tc_x - last_model.temperature) < 0.05) + { + same_temperature = TRUE; + } + else + { + same_temperature = FALSE; + } +/* + * Check pressure + */ + if (fabs(patm_x - last_model.pressure) < 0.01) + { + same_pressure = TRUE; + } + else + { + same_pressure = FALSE; + } +/* + * Check master species + */ + for (i = 0; i < count_master; i++) + { +/* + output_msg(sformatf("%s\t%e\t%d\n", master[i]->elt->name, + master[i]->total, master[i]->last_model); + */ + if (master[i]->s == s_hplus || master[i]->s == s_h2o) + continue; + if (master[i]->total > MIN_TOTAL && master[i]->last_model == TRUE) + { + if (master[i]->s->secondary != NULL) + { + if (master[i]->s->secondary->unknown != NULL) + continue; + } + else + { + if (master[i]->unknown != NULL) + continue; + } + } + if (master[i]->total <= MIN_TOTAL && master[i]->last_model == FALSE) + continue; + return (FALSE); + } +/* + * Check gas_phase + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (last_model.gas_phase == NULL) + return (FALSE); + if (last_model.count_gas_phase != (int) gas_phase_ptr->Get_gas_comps().size()) + return (FALSE); + for (i = 0; i < (int) gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + assert(phase_ptr); + if (last_model.gas_phase[i] != phase_ptr) + { + return (FALSE); + } + } + } + else + { + if (last_model.gas_phase != NULL) + return (FALSE); + } +/* + * Check solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + if (last_model.count_ss_assemblage != + use.Get_ss_assemblage_ptr()->count_s_s) + return (FALSE); + for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + { + if (last_model.ss_assemblage[i] != + use.Get_ss_assemblage_ptr()->s_s[i].name) + { + return (FALSE); + } + } + } + else + { + if (last_model.ss_assemblage != NULL) + return (FALSE); + } +/* + * Check pure_phases + */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + if (last_model.count_pp_assemblage != (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size()) + return (FALSE); + + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + i = 0; + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + int j; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &j, FALSE); + assert(phase_ptr); + if (last_model.pp_assemblage[i] != phase_ptr) + { + return (FALSE); + } + if (last_model.add_formula[i] != + string_hsave(it->second.Get_add_formula().c_str())) + { + return (FALSE); + } + i++; + /* A. Crapsi + if (last_model.si[i] != use.Get_pp_assemblage_ptr()->pure_phases[i].si) + { + return (FALSE); + } + */ + } + } + else + { + if (last_model.pp_assemblage != NULL) + return (FALSE); + } +#ifdef SKIP + if (use.Get_pp_assemblage_ptr() != NULL) + { + if (last_model.count_pp_assemblage != + use.Get_pp_assemblage_ptr()->count_comps) + return (FALSE); + for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) + { + if (last_model.pp_assemblage[i] != + use.Get_pp_assemblage_ptr()->pure_phases[i].phase) + { + return (FALSE); + } + if (last_model.add_formula[i] != + use.Get_pp_assemblage_ptr()->pure_phases[i].add_formula) + { + return (FALSE); + } + /* A. Crapsi + if (last_model.si[i] != use.Get_pp_assemblage_ptr()->pure_phases[i].si) + { + return (FALSE); + } + */ + } + } + else + { + if (last_model.pp_assemblage != NULL) + return (FALSE); + } +#endif +/* + * Check surface + */ + if (use.Get_surface_ptr() != NULL) + { + if (last_model.count_surface_comp != use.Get_surface_ptr()->count_comps) + return (FALSE); + if (last_model.count_surface_charge != use.Get_surface_ptr()->count_charge) + return (FALSE); + if (last_model.dl_type != use.Get_surface_ptr()->dl_type) + return (FALSE); + /*if (last_model.edl != use.Get_surface_ptr()->edl) return(FALSE); */ + if (last_model.surface_type != use.Get_surface_ptr()->type) + return (FALSE); + /* + if (last_model.only_counter_ions != use.Get_surface_ptr()->only_counter_ions) return(FALSE); + */ + for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + { + if (last_model.surface_comp[i] != + use.Get_surface_ptr()->comps[i].formula) + return (FALSE); + } + for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + { + if (last_model.surface_charge[i] != + use.Get_surface_ptr()->charge[i].name) + return (FALSE); + } + } + else + { + if (last_model.surface_comp != NULL) + return (FALSE); + } +/* + * Model is the same + */ + return (TRUE); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_min_exch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Defines proportionality factor between mineral and exchanger to + * jacob0 + */ + int j, k, jj; + int row; + //struct exch_comp *comp_ptr; + struct master *master_ptr; + struct unknown *unknown_ptr; + LDBLE coef; + + if (use.Get_exchange_ptr() == NULL) + return (OK); + cxxExchange *ex_ptr = (cxxExchange *) use.Get_exchange_ptr(); + int n_user = ex_ptr->Get_n_user(); + cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, n_user); + if (exchange_ptr == NULL) + { + input_error++; + error_string = sformatf( "Exchange %d not found.", + use.Get_n_exchange_user()); + error_msg(error_string, CONTINUE); + } + n_user = exchange_ptr->Get_n_user(); + if (!exchange_ptr->Get_related_phases()) + return (OK); + std::vector comps = exchange_ptr->Vectorize(); + for (size_t i = 0; i < comps.size(); i++) + { + cxxExchComp * comp_ptr = comps[i]; + if (comp_ptr->Get_phase_name().size() == 0) + continue; + // Find exchange master + cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + struct master *exchange_master = NULL; + for ( ; it != nd.end(); it++) + { + element * elt_ptr = element_store(it->first.c_str()); + assert (elt_ptr); + if (elt_ptr->master->type == EX) + { + exchange_master = elt_ptr->master; + } + } + if (exchange_master == NULL) + { + input_error++; + error_string = sformatf( + "Did not find master exchange species for %s", + comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + /* find unknown number */ + for (j = count_unknowns - 1; j >= 0; j--) + { + if (x[j]->type != EXCH) + continue; + if (x[j]->master[0] == exchange_master) + break; + } + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + //if (x[k]->phase->name == exchange[n].comps[i].phase_name) + if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + break; + } + if (j == -1) + { + input_error++; + error_string = sformatf( + "Did not find unknown for master exchange species %s", + exchange_master->s->name); + error_msg(error_string, CONTINUE); + } + if (j == -1 || k == -1) + continue; +/* + * Build jacobian + */ + + /* charge balance */ + store_jacob0(charge_balance_unknown->number, x[k]->number, + comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + store_sum_deltas(&delta[k], &charge_balance_unknown->delta, + -comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + + + /* mole balance balance */ + count_elts = 0; + paren_count = 0; + add_elt_list(comp_ptr->Get_formula_totals(), 1.0); +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (jj = 0; jj < count_elts; jj++) + { + master_ptr = elt_list[jj].elt->primary; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Did not find unknown for exchange related to mineral %s", + comp_ptr->Get_phase_name().c_str()); + error_msg(error_string, STOP); + } + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr->s->type == EX) + { + if (equal + (x[j]->moles, + x[k]->moles * elt_list[jj].coef * + comp_ptr->Get_phase_proportion(), + 5.0 * convergence_tolerance) == FALSE) + { + error_string = sformatf( + "Resetting number of sites in exchanger %s (=%e) to be consistent with moles of phase %s (=%e).\n%s", + master_ptr->s->name, (double) x[j]->moles, + comp_ptr->Get_phase_name().c_str(), + (double) (x[k]->moles * elt_list[jj].coef * + comp_ptr->Get_phase_proportion()), + "\tHas equilibrium_phase assemblage been redefined?\n"); + warning_msg(error_string); + x[j]->moles = + x[k]->moles * elt_list[jj].coef * + comp_ptr->Get_phase_proportion(); + } + } + coef = elt_list[jj].coef; + if (master_ptr->s == s_hplus) + { + row = mass_hydrogen_unknown->number; + unknown_ptr = mass_hydrogen_unknown; + } + else if (master_ptr->s == s_h2o) + { + row = mass_oxygen_unknown->number; + unknown_ptr = mass_oxygen_unknown; + } + else + { + row = master_ptr->unknown->number; + unknown_ptr = master_ptr->unknown; + } + store_jacob0(row, x[k]->number, + coef * comp_ptr->Get_phase_proportion()); + store_sum_deltas(&delta[k], &unknown_ptr->delta, + -coef * comp_ptr->Get_phase_proportion()); + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_min_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Defines proportionality factor between mineral and surface to + * jacob0 + */ + int i, j, k, n, jj, row; + struct elt_list *next_elt; + struct surface_comp *comp_ptr; + struct unknown *unknown_ptr; + struct master *master_ptr; + LDBLE coef; + + if (use.Get_surface_ptr() == NULL) + return (OK); + if (surface_bsearch(use.Get_surface_ptr()->n_user, &n) == NULL) + { + input_error++; + error_string = sformatf( "Surface %d not found.", + use.Get_surface_ptr()->n_user); + error_msg(error_string, CONTINUE); + } + if (surface[n].related_phases == FALSE) + return (OK); + for (i = 0; i < surface[n].count_comps; i++) + { + if (surface[n].comps[i].phase_name == NULL) + continue; + + /* find unknown number */ + for (j = count_unknowns - 1; j >= 0; j--) + { + if (x[j]->type != SURFACE) + continue; + if (x[j]->master[0] == surface[n].comps[i].master) + break; + } + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == surface[n].comps[i].phase_name) + break; + } + if (j == -1) + { + input_error++; + error_string = sformatf( + "Did not find unknown for master surface species %s", + surface[n].comps[i].master->s->name); + error_msg(error_string, CONTINUE); + } + if (j == -1 || k == -1) + continue; + + comp_ptr = x[j]->surface_comp; + + if (surface[n].type == CD_MUSIC) + { + /* Add formula for CD_MUSIC */ + next_elt = comp_ptr->formula_totals; + } + else + { + /* Add master species for non CD_MUSIC */ + next_elt = x[j]->master[0]->s->next_elt; + } + + + /* update grams == moles in this case */ + if (j < count_unknowns - 1 && x[j + 1]->type == SURFACE_CB) + { + store_sum_deltas(&delta[k], &(x[j + 1]->related_moles), -1.0); + } + + /* charge balance */ + store_jacob0(charge_balance_unknown->number, x[k]->number, + comp_ptr->formula_z * comp_ptr->phase_proportion); + store_sum_deltas(&delta[k], &charge_balance_unknown->delta, + -comp_ptr->formula_z * comp_ptr->phase_proportion); + + + count_elts = 0; + paren_count = 0; + add_elt_list(next_elt, 1.0); +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (jj = 0; jj < count_elts; jj++) + { + master_ptr = elt_list[jj].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Did not find unknown for surface related to mineral %s", + surface[n].comps[i].phase_name); + error_msg(error_string, STOP); + } + if (master_ptr->s->type == SURF) + { + if (equal + (x[j]->moles, + x[k]->moles * elt_list[jj].coef * + comp_ptr->phase_proportion, + 5.0 * convergence_tolerance) == FALSE) + { + error_string = sformatf( + "Resetting number of sites in surface %s (=%e) to be consistent with moles of phase %s (=%e).\n%s", + master_ptr->s->name, (double) x[j]->moles, + comp_ptr->phase_name, + (double) (x[k]->moles * elt_list[jj].coef * + comp_ptr->phase_proportion), + "\tHas equilibrium_phase assemblage been redefined?\n"); + warning_msg(error_string); + x[j]->moles = + x[k]->moles * elt_list[jj].coef * + comp_ptr->phase_proportion; + } + } + coef = elt_list[jj].coef; + if (master_ptr->s == s_hplus) + { + row = mass_hydrogen_unknown->number; + unknown_ptr = mass_hydrogen_unknown; + } + else if (master_ptr->s == s_h2o) + { + row = mass_oxygen_unknown->number; + unknown_ptr = mass_oxygen_unknown; + } + else + { + row = master_ptr->unknown->number; + unknown_ptr = master_ptr->unknown; + } + store_jacob0(row, x[k]->number, + coef * comp_ptr->phase_proportion); + store_sum_deltas(&delta[k], &unknown_ptr->delta, + -coef * comp_ptr->phase_proportion); + } + + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_related_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Fill in data for surface assemblage in unknown structure + */ + int i, k; + struct surface_comp *comp_ptr; + + if (use.Get_surface_ptr() == NULL) + return (OK); + if (use.Get_surface_ptr()->related_phases == FALSE) + return (OK); + + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SURFACE && x[i]->surface_comp->phase_name != NULL) + { + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == x[i]->surface_comp->phase_name) + break; + } + if (k == -1) + continue; + + comp_ptr = x[i]->surface_comp; + x[i]->phase_unknown = x[k]; +/* !!!!! */ + x[i]->moles = x[k]->moles * comp_ptr->phase_proportion; + + } + else if (x[i]->type == SURFACE_CB + && x[i - 1]->surface_comp->phase_name != NULL) + { + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == x[i]->surface_comp->phase_name) + break; + } + if (k == -1) + continue; + + comp_ptr = x[i]->surface_comp; + x[i]->phase_unknown = x[k]; +/* !!!! Added for security, not checked... */ + x[i]->related_moles = x[k]->moles * comp_ptr->phase_proportion; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +change_hydrogen_in_elt_list(LDBLE charge) +/* ---------------------------------------------------------------------- */ +{ + int j; + int found_h, found_o; + LDBLE coef_h, coef_o, coef; + found_h = -1; + found_o = -1; + coef_h = 0.0; + coef_o = 0.0; + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, "H") == 0) + { + found_h = j; + coef_h = elt_list[j].coef; + } + else if (strcmp(elt_list[j].elt->name, "O") == 0) + { + found_o = j; + coef_o = elt_list[j].coef; + } + } + coef = coef_h - 2 * coef_o - charge; + if (found_h < 0 && found_o < 0) + return (OK); + if (found_h >= 0 && found_o < 0) + return (OK); + if (found_h < 0 && found_o >= 0) + { + elt_list[count_elts].elt = s_hplus->primary->elt; + elt_list[count_elts].coef = coef; + count_elts++; + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + return (OK); + } + elt_list[found_h].coef = coef; + return (OK); +} diff --git a/rename_cpp/print.cpp b/rename_cpp/print.cpp new file mode 100644 index 00000000..9c8cdafb --- /dev/null +++ b/rename_cpp/print.cpp @@ -0,0 +1,3586 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include +#include +#include "Temperature.h" +#include "cxxMix.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +array_print(LDBLE * array_l, int row_count, int column_count, + int l_max_column_count) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + + for (i = 0; i < row_count; i++) + { + k = 0; + output_msg(sformatf("%d\n", i)); + for (j = 0; j < column_count; j++) + { + if (k > 7) + { + output_msg(sformatf("\n")); + k = 0; + } + output_msg(sformatf("%11.2e", + (double) array_l[i * l_max_column_count + j])); + k++; + } + if (k != 0) + { + output_msg(sformatf("\n")); + } + output_msg(sformatf("\n")); + } + output_msg(sformatf("\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_all(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print each block of results in sequence to file output + * also print selected output to punch_file + * Each routine is controlled by a variable in structure print. + * print.all == FALSE will turn off all prints. + */ +/* + * Makes sorted list including all species for each valence state + */ + if (pr.all == FALSE) + return (OK); + if (pr.surface == TRUE || pr.exchange == TRUE || pr.species == TRUE) + { + species_list_sort(); + } +/* + * Print results + */ + s_h2o->lm = s_h2o->la; + print_using(); + print_mix(); + print_reaction(); + print_kinetics(); + print_user_print(); + print_gas_phase(); + print_pp_assemblage(); + print_ss_assemblage(); + print_surface(); + print_exchange(); + print_initial_solution_isotopes(); + print_isotope_ratios(); + print_isotope_alphas(); + print_totals(); + print_eh(); + print_species(); + print_alkalinity(); + print_saturation_indices(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_all(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + +//#ifndef PHREEQ98 /* if not PHREEQ98 use the standard declaration */ +// if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE) && user_graph->commands == NULL) +// return (OK); +///* +// * Punch results +// */ +// if (state == TRANSPORT || state == PHAST || state == ADVECTION) +// { +// use.Get_kinetics_ptr() = kinetics_bsearch(use.Get_n_kinetics_user(), &i); +// } +// else if (use.Get_kinetics_in() != FALSE) +// { +// use.Get_kinetics_ptr() = kinetics_bsearch(-2, &i); +// } +//#else /* if PHREEQ98 execute punch_user_graph first, that is, before punch.in and pr.punch is checked */ + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + } + else if (use.Get_kinetics_in() != FALSE) + { + use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + } +#if defined PHREEQ98 + if (pr.user_graph == TRUE) + { + punch_user_graph(); + } +#elif defined MULTICHART + if (pr.user_graph == TRUE) + { + chart_handler.Punch_user_graph(PHREEQC_THIS); + } +#endif + if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) + return (OK); +//#endif + punch_identifiers(); + punch_totals(); + punch_molalities(); + punch_activities(); + punch_pp_assemblage(); + punch_saturation_indices(); + punch_gas_phase(); + punch_kinetics(); + punch_ss_assemblage(); + punch_isotopes(); + punch_calculate_values(); + punch_user_punch(); +/* + * new line for punch_file + */ + punch_msg("\n"); + +/* + * signal end of row + */ + fpunchf_end_row("\n"); + punch_flush(); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_diffuse_layer(struct surface_charge *surface_charge_ptr1) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints total moles of each element in diffuse layer + * Remove comment to print total moles of each species + */ + int i, j, count_g; + LDBLE mass_water_surface, r, sum_surfs; + LDBLE molality, moles_excess, moles_surface, d; + + if (use.Get_surface_ptr() == NULL) + return (OK); +/* + * Find position of component in surface charge data + */ + i = 0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + if (x[j]->surface_charge == surface_charge_ptr1) + { + break; + } + i++; + } + if (j >= count_unknowns) + { + error_string = sformatf( + "In print_diffuse_layer: component not found, %s.", + surface_charge_ptr1->name); + error_msg(error_string, STOP); + } +/* + * Loop through all surface components, calculate each H2O surface (diffuse layer), + * H2O aq, and H2O bulk (diffuse layers plus aqueous). + */ + + if (mass_water_surfaces_x != 0) + { + d = 100 * surface_charge_ptr1->mass_water / mass_water_surfaces_x; + } + else + { + d = 0.0; + } + output_msg(sformatf( + "\tWater in diffuse layer: %8.3e kg, %4.1f%% of total DDL-water.\n", + (double) surface_charge_ptr1->mass_water, (double) d)); + if (use.Get_surface_ptr()->debye_lengths > 0) + { + sum_surfs = 0.0; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + sum_surfs += + x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams; + } + r = 0.002 * mass_water_bulk_x / sum_surfs; + output_msg(sformatf( + "\tRadius of total pore: %8.3e m; of free pore: %8.3e m.\n", + (double) r, (double) (r - use.Get_surface_ptr()->thickness))); + } + + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( + "\n\t\tDistribution of species in diffuse layer\n\n")); + output_msg(sformatf( + "\n\tSpecies \t Moles \tMoles excess\t g\n")); + } + mass_water_surface = surface_charge_ptr1->mass_water; + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + count_g = s_x[j]->diff_layer[i].count_g; + moles_excess = + mass_water_aq_x * molality * (surface_charge_ptr1->g[count_g].g * + s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - + 1)); + moles_surface = mass_water_surface * molality + moles_excess; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", + s_x[j]->name, moles_surface, moles_excess, + s_x[j]->diff_layer[i].charge->g[count_g].g)); + } +/* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } +/* + strcpy(token, s_h2o->name); + ptr = &(token[0]); + get_elts_in_species (&ptr, mass_water_surface / gfw_water); + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Print totals + */ + if (use.Get_surface_ptr()->dl_type != DONNAN_DL) + { + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water)\n\n")); + } + else + { + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation \n\n")); + } + output_msg(sformatf("\tElement \t Moles\n")); + for (j = 0; j < count_elts; j++) + { + output_msg(sformatf("\t%-14s\t%12.4e\n", + elt_list[j].elt->name, (double) elt_list[j].coef)); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_eh(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints eh calculated from redox couples + * Only calculates eh if two redox states of an element have mass balance + * equations. + */ + int i, j, k, first; + LDBLE pe, eh; + struct master *master_ptr0, *master_ptr1; + char token[MAX_LENGTH]; + + if (pr.eh == FALSE || pr.all == FALSE) + return (OK); + + tk_x = tc_x + 273.15; + + first = TRUE; + for (i = 0; i < count_master; i++) + { + if (master[i]->in != TRUE) + continue; + if (master[i]->primary == TRUE) + continue; +/* + * Secondary master species has mass balance equation + */ + master_ptr0 = master[i]->elt->primary; + for (k = i + 1; k < count_master; k++) + { + if (master[k]->in != TRUE) + continue; + master_ptr1 = master[k]->elt->primary; + if (master_ptr1 != master_ptr0) + break; +/* + * Another secondary master species of same element has mass balance equation + * Rewrite equations to calculate pe + */ + rewrite_master_to_secondary(master[k], master[i]); + trxn_swap("e-"); +/* debug + trxn_print(); + */ +/* + * Calculate pe, eh + */ + pe = -k_calc(trxn.logk, tk_x, patm_x * PASCAL_PER_ATM); + for (j = 1; j < count_trxn; j++) + { + pe -= trxn.token[j].s->la * trxn.token[j].coef; + } + eh = ((LOG_10 * R_KJ_DEG_MOL * tk_x) / F_KJ_V_EQ) * pe; +/* + * Print heading + */ + if (first == TRUE) + { + print_centered("Redox couples"); + output_msg(sformatf("\t%-15s%12s%12s\n\n", + "Redox couple", "pe", "Eh (volts)")); + first = FALSE; + } +/* + * Print result + */ + strcpy(token, master[i]->elt->name); + strcat(token, "/"); + strcat(token, master[k]->elt->name); + output_msg(sformatf("\t%-15s%12.4f%12.4f\n", token, + (double) pe, (double) eh)); + } + } + if (first == FALSE) + output_msg(sformatf("\n")); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_exchange(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print moles of each exchange species + */ + int i; + //struct exchange *exchange_ptr; + cxxExchange * exchange_ptr; + const char *name, *name1; + struct master *master_ptr; + LDBLE dum, dum2; +/* + * Print exchange data + */ + exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); + if (exchange_ptr == NULL || pr.exchange == FALSE || pr.all == FALSE) + return (OK); + + if (state >= REACTION) + { + print_centered("Exchange composition"); + } +/* + * Print list of species + */ + + s_h2o->lm = s_h2o->la; + name = s_hplus->secondary->elt->name; + for (i = 0; i < count_species_list; i++) + { +/* + * Get name of master species + */ + if (species_list[i].s->type != EX) + continue; + if (species_list[i].master_s->secondary != NULL) + { + master_ptr = species_list[i].master_s->secondary; + name1 = species_list[i].master_s->secondary->elt->name; + } + else + { + master_ptr = species_list[i].master_s->primary; + name1 = species_list[i].master_s->primary->elt->name; + } +/* + * Check if new master species, print total molality + */ + if (name1 != name) + { + name = name1; + output_msg(sformatf("%-14s%12.3e mol", name, + (double) master_ptr->unknown->moles)); + cxxExchange *exchange_ptr = (cxxExchange *) (use.Get_exchange_ptr()); + const cxxExchComp *exch_comp = exchange_ptr->ExchComp_find(master_ptr->unknown->exch_comp); + assert(exch_comp); + if (exch_comp->Get_phase_name().size() > 0) + { + output_msg(sformatf("\t[%g (mol %s)/(mol %s)]", + (double) exch_comp->Get_phase_proportion(), + exch_comp->Get_formula().c_str(), + exch_comp->Get_phase_name().c_str())); + } + else if (exch_comp->Get_rate_name().size() > 0) + { + output_msg(sformatf( + "\t[%g (mol %s)/(mol kinetic reactant %s)]", + (double) exch_comp->Get_phase_proportion(), + exch_comp->Get_formula().c_str(), + exch_comp->Get_rate_name().c_str())); + } + output_msg(sformatf("\n\n")); + /* Heading for species */ + output_msg(sformatf("\t%-15s%12s%12s%12s%10s\n", " ", " ", + "Equiv- ", "Equivalent", "Log ")); + output_msg(sformatf("\t%-15s%12s%12s%12s%10s\n\n", + "Species", "Moles ", "alents ", "Fraction", "Gamma")); + } +/* + * Print species data + */ +/* !!!!! */ + if (master_ptr->total > 1.0e-10) + { + if (species_list[i].s->equiv != 0.0) + { + dum = fabs(species_list[i].s->equiv) / master_ptr->total; + } + else + { + if (species_list[i].master_s->z == 0) + { + dum = 1 / master_ptr->total; + } + else + { + dum = 1; + } + } + if (species_list[i].master_s->z != 0.0) + { + dum2 = fabs(species_list[i].master_s->z); + } + else + { + dum2 = 1; + } + output_msg(sformatf("\t%-15s%12.3e%12.3e%12.3e%10.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) (species_list[i].s->moles * dum2 * + species_list[i].s->equiv), + (double) (species_list[i].s->moles * + dum /* / dum2 */ ), + (double) (species_list[i].s->lg - log10(dum)))); + } + } + output_msg(sformatf("\n")); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints gas phase composition if present + */ + //int j; + LDBLE lp, moles, initial_moles, delta_moles; + struct rxn_token *rxn_ptr; + char info[MAX_LENGTH]; + bool PR = false; + + if (pr.gas_phase == FALSE || pr.all == FALSE) + return (OK); + if (use.Get_gas_phase_ptr() == NULL) + return (OK); + + cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_v_m() >= 0.01) + PR = true; + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_unknown == NULL) + return (OK); + if (gas_unknown->moles < 1e-12) + { + sprintf(info, "Fixed-pressure gas phase %d dissolved completely", + use.Get_n_gas_phase_user()); + print_centered(info); + return (OK); + } + gas_phase_ptr->Set_total_moles(gas_unknown->moles); + gas_phase_ptr->Set_volume(gas_phase_ptr->Get_total_moles() * R_LITER_ATM * tk_x / + gas_phase_ptr->Get_total_p()); + if (PR) + gas_phase_ptr->Set_volume(gas_phase_ptr->Get_v_m() * gas_unknown->moles); + } +/* + * Print heading + */ + print_centered("Gas phase"); + //output_msg(OUTPUT_MESSAGE, "\n"); + output_msg(sformatf("Total pressure: %5.2f atmospheres", + (double) gas_phase_ptr->Get_total_p())); + if (PR) + output_msg(" (Peng-Robinson calculation)\n"); + else if (gas_phase_ptr->Get_total_p() >= 1500) + output_msg(" WARNING: Program's limit.\n"); + else + output_msg(" \n"); + output_msg(sformatf(" Gas volume: %10.2e liters\n", + (double) gas_phase_ptr->Get_volume())); + if(gas_phase_ptr->Get_total_moles() > 0) + output_msg(sformatf(" Molar volume: %10.2e liters/mole", + (double) (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()))); + if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles() <= 0.03) || (PR && gas_phase_ptr->Get_v_m() <= 0.03))) + output_msg(" WARNING: Program's limit for Peng-Robinson.\n"); + else + output_msg("\n"); + if (PR) + output_msg(sformatf( " P * Vm / RT: %8.5f (Compressibility Factor Z) \n", + (double) (gas_phase_ptr->Get_total_p() * gas_phase_ptr->Get_v_m() / (R_LITER_ATM * tk_x)))); + + + output_msg(sformatf("\n%68s\n%78s\n", "Moles in gas", + "----------------------------------")); + if (gas_phase_ptr->Get_v_m() >= 0.03) + output_msg(sformatf( "%-11s%12s%12s%7s%12s%12s%12s\n\n", "Component", + "log P", "P", "phi", "Initial", "Final", "Delta")); + else + output_msg(sformatf("%-18s%12s%12s%12s%12s%12s\n\n", "Component", + "log P", "P", "Initial", "Final", "Delta")); + + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + //for (j = 0; j < use.Get_gas_phase_ptr()->count_comps; j++) + { +/* + * Calculate partial pressure + */ + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + for (rxn_ptr = + phase_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + lp -= phase_ptr->pr_si_f; + moles = phase_ptr->moles_x; + } + else + { + lp = -99.99; + moles = 0; + phase_ptr->p_soln_x = 0; + } +/* + * Print gas composition + */ + if (state != TRANSPORT && state != PHAST) + { + initial_moles = gc_ptr->Get_moles(); + delta_moles = phase_ptr->moles_x - gc_ptr->Get_moles(); + } + else + { + initial_moles = gc_ptr->Get_initial_moles(); + delta_moles = gc_ptr->Get_initial_moles() - + gc_ptr->Get_moles(); + } + if (moles <= MIN_TOTAL) + moles = 0.0; + if (fabs(delta_moles) <= MIN_TOTAL) + delta_moles = 0.0; + if (PR) + output_msg(sformatf("%-11s%12.2f%12.3e%7.3f%12.3e%12.3e%12.3e\n", + phase_ptr->name, + (double) lp, + (double) phase_ptr->p_soln_x, + (double) phase_ptr->pr_phi, + (double) initial_moles, + (double) moles, + (double) delta_moles)); + else + output_msg(sformatf("%-18s%12.2f%12.3e%12.3e%12.3e%12.3e\n", + phase_ptr->name, + (double) lp, + (double) phase_ptr->p_soln_x, + (double) initial_moles, + (double) moles, + (double) delta_moles)); + if (!strcmp(phase_ptr->name, "H2O(g)") && phase_ptr->p_soln_x == 90) + output_msg(" WARNING: The pressure of H2O(g) is above program's limit: use the polynomial for log_k.\n"); + + } + output_msg("\n"); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Prints solid solution composition if present + */ + int i, j; + LDBLE delta_moles; + LDBLE nb, nc, xb, xb1, xb2, xb1moles, xb2moles; + struct s_s *s_s_ptr; + + if (pr.ss_assemblage == FALSE || pr.all == FALSE) + return (OK); + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + /* + * Print heading + */ + print_centered("Solid solutions"); + output_msg(sformatf("\n")); + output_msg(sformatf("%-15s %22s %11s %11s %11s\n\n", + "Solid solution", "Component", "Moles", "Delta moles", + "Mole fract")); + /* + * Print solid solutions + */ + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + { + /* solid solution name, moles */ + output_msg(sformatf("%-15s %22s %11.2e\n", + use.Get_ss_assemblage_ptr()->s_s[j].name, " ", + (double) use.Get_ss_assemblage_ptr()->s_s[j].total_moles)); + /* component name, moles, delta moles, mole fraction */ + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + if (state != TRANSPORT && state != PHAST) + { + delta_moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. + initial_moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].delta; + } + else + { + delta_moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].init_moles; + } + output_msg(sformatf( + "%15s %22s %11.2e %11.2e %11.2e\n", " ", + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, + (double) use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. + moles, (double) delta_moles, + (double) (use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. + moles / + use.Get_ss_assemblage_ptr()->s_s[j]. + total_moles))); + } + s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[j]); + if (s_s_ptr->miscibility == TRUE) + { + nc = s_s_ptr->comps[0].moles; + nb = s_s_ptr->comps[1].moles; + xb = nb / (nb + nc); + xb1 = s_s_ptr->xb1; + xb2 = s_s_ptr->xb2; + + if (xb > xb1 && xb < xb2) + { + xb2moles = (xb1 - 1) / xb1 * nb + nc; + xb2moles = xb2moles / ((xb1 - 1) / xb1 * xb2 + (1 - xb2)); + xb1moles = (nb - xb2moles * xb2) / xb1; + output_msg(sformatf( + "\n%14s Solid solution is in miscibility gap\n", + " ")); + output_msg(sformatf( + "%14s End members in pct of %s\n\n", " ", + s_s_ptr->comps[1].name)); + output_msg(sformatf("%22s %11g pct %11.2e\n", + " ", (double) xb1, (double) xb1moles)); + output_msg(sformatf("%22s %11g pct %11.2e\n", + " ", (double) xb2, (double) xb2moles)); + } + } + } + else + { + /* solid solution name, moles */ + output_msg(sformatf("%-15s %22s %11.2e\n", + use.Get_ss_assemblage_ptr()->s_s[j].name, " ", + (double) 0.0)); + /* component name, moles, delta moles, mole fraction */ + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) + { + if (state != TRANSPORT && state != PHAST) + { + delta_moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. + initial_moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].delta; + } + else + { + delta_moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].init_moles; + } + output_msg(sformatf( + "%15s %22s %11.2e %11.2e %11.2e\n", " ", + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, + (double) 0, (double) delta_moles, (double) 0)); + } + } + } + output_msg(sformatf("\n")); + return (OK); +} +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +print_reaction(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints irreversible reaction as defined and as + * relative moles of each element and total amount + * of reaction + */ + cxxReaction *reaction_ptr; + if (pr.use == FALSE || pr.all == FALSE) + return (OK); + if (state < REACTION || use.Get_reaction_in() == FALSE) + return (OK); + if (state == TRANSPORT && transport_step == 0) + return (OK); + reaction_ptr = (cxxReaction *) use.Get_reaction_ptr(); +/* + * Print amount of reaction + */ + output_msg(sformatf("Reaction %d.\t%s\n\n", use.Get_n_reaction_user(), + reaction_ptr->Get_description().c_str())); + output_msg(sformatf( + "\t%11.3e moles of the following reaction have been added:\n\n", + (double) step_x)); +/* + * Print reaction + */ + output_msg(sformatf("\t%-15s%10s\n", " ", "Relative")); + output_msg(sformatf("\t%-15s%10s\n\n", "Reactant", "moles")); + //for (i = 0; i < irrev_ptr->count_list; i++) + cxxNameDouble::const_iterator cit = reaction_ptr->Get_reactantList().begin(); + for ( ; cit != reaction_ptr->Get_reactantList().end(); cit++) + { + //output_msg(sformatf("\t%-15s%13.5f\n", + // irrev_ptr->list[i].name, (double) irrev_ptr->list[i].coef)); + output_msg(sformatf("\t%-15s%13.5f\n", + cit->first.c_str(), (double) cit->second)); + } + output_msg(sformatf("\n")); +/* + * Debug + */ + + output_msg(sformatf("\t%-15s%10s\n", " ", "Relative")); + output_msg(sformatf("\t%-15s%10s\n", "Element", "moles")); + //for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) + cit = reaction_ptr->Get_elementList().begin(); + for ( ; cit != reaction_ptr->Get_elementList().end(); cit++) + { + struct element * elt_ptr = element_store(cit->first.c_str()); + assert(elt_ptr); + output_msg(sformatf("\t%-15s%13.5f\n", + elt_ptr->name, + (double) cit->second)); + } + output_msg(sformatf("\n")); + return (OK); +} +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +print_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + int i, j; + LDBLE sim_time; + struct kinetics *kinetics_ptr; + if (pr.kinetics == FALSE || pr.all == FALSE) + return (OK); + if (state < REACTION) + return (OK); + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + } + else + { + kinetics_ptr = kinetics_bsearch(-2, &i); + } + } + if (kinetics_ptr == NULL) + return (OK); +/* + * determine time step + */ + if (state == TRANSPORT || state == PHAST) + { + kin_time_x = timest; + } + else if (state == ADVECTION) + { + kin_time_x = advection_kin_time; + } + sim_time = 0.; + if (run_info.Get_run_cells()) + { + sim_time = rate_sim_time; + } + else + { + if (incremental_reactions == TRUE) + { + if (kinetics_ptr->count_steps > 0) + { + for (i = 0; i < reaction_step; i++) + { + if (i < kinetics_ptr->count_steps) + { + sim_time += kinetics_ptr->steps[i]; + } + else + { + sim_time += + kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + sim_time = kinetics_ptr->steps[0]; + } + else + { + sim_time = + reaction_step * kinetics_ptr->steps[0] / + ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } + } +/* + * Print amount of reaction + */ + if (phast == FALSE) + { + output_msg(sformatf("Kinetics %d.\t%s\n\n", + use.Get_n_kinetics_user(), kinetics_ptr->description)); + } + else + { + output_msg(sformatf("Kinetics.\n\n")); + } +/* + * Print reaction + */ + if (state == TRANSPORT) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) (initial_total_time + transport_step * timest))); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == ADVECTION) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) (initial_total_time + + advection_step * advection_kin_time))); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == PHAST) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) rate_sim_time_end)); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == REACTION) + { + if (incremental_reactions == FALSE) + { + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else + { + output_msg(sformatf( + "\tTime step: %g seconds (Incremented time: %g seconds)\n\n", + (double) kin_time_x, (double) sim_time)); + } + } + output_msg(sformatf("\t%-15s%12s%12s %-15s%12s\n\n", + "Rate name", "Delta Moles", "Total Moles", "Reactant", + "Coefficient")); + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + if (state != TRANSPORT && state != PHAST) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + kinetics_ptr->comps[i].rate_name, + (double) -kinetics_ptr->comps[i].moles, + (double) kinetics_ptr->comps[i].m)); + } + else + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + kinetics_ptr->comps[i].rate_name, + (double) (kinetics_ptr->comps[i].m - + kinetics_ptr->comps[i].initial_moles), + (double) kinetics_ptr->comps[i].m)); + } + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) + { + if (j == 0) + { + output_msg(sformatf(" %-15s%12g\n", + kinetics_ptr->comps[i].list[j].name, + (double) kinetics_ptr->comps[i].list[j].coef)); + } + else + { + output_msg(sformatf("\t%39s %-15s%12g\n", " ", + kinetics_ptr->comps[i].list[j].name, + (double) kinetics_ptr->comps[i].list[j].coef)); + } + } + } + output_msg(sformatf("\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_master_reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Debugging print routine to test primary and secondary reactions + */ + int i; + struct rxn_token *next_token; + + for (i = 0; i < count_master; i++) + { + output_msg(sformatf("%s\t%s\n\tPrimary reaction\n", + master[i]->elt->name, master[i]->s->name)); + next_token = master[i]->rxn_primary->token; + for (; next_token->s != NULL; next_token++) + { + output_msg(sformatf("\t\t%s\t%f\n", next_token->s->name, + (double) next_token->coef)); + } + output_msg(sformatf("\n\tSecondary reaction:\n")); + if (master[i]->rxn_secondary != NULL) + { + next_token = master[i]->rxn_secondary->token; + for (; next_token->s != NULL; next_token++) + { + output_msg(sformatf("\t\t%s\t%f\n", + next_token->s->name, (double) next_token->coef)); + } + } + output_msg(sformatf("\n\tRedox reaction:\n")); + if (*(master[i]->pe_rxn) != NULL) + { + next_token = (*(master[i]->pe_rxn))->token; + for (; next_token->s != NULL; next_token++) + { + output_msg(sformatf("\t\t%s\t%f\n", + next_token->s->name, (double) next_token->coef)); + } + } + output_msg(sformatf("\n")); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +print_mix(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints definition of mixing, solution number and multiplier + */ + int n; + //struct mix *mix_ptr; + cxxMix * mix_ptr; + struct solution *solution_ptr; + + if (pr.use == FALSE || pr.all == FALSE) + return (OK); + if (use.Get_mix_in() == FALSE || state < REACTION) + return (OK); + if (state == TRANSPORT) + { + //mix_ptr = mix_bsearch(use.Get_n_mix_user(), &i); + mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); + } + else + { + //mix_ptr = mix_bsearch(use.Get_n_mix_user_orig(), &i); + mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user_orig()); + } + if (mix_ptr == NULL) + { + mix_ptr = (cxxMix *) use.Get_mix_ptr(); + } +/* + * Print mixture data + */ + if (mix_ptr == NULL) + { + return (OK); + + } + if (state == TRANSPORT) + { + output_msg(sformatf("Mixture %d.\t%s\n\n", use.Get_n_mix_user(), + mix_ptr->Get_description().c_str())); + } + else + { + output_msg(sformatf("Mixture %d.\t%s\n\n", mix_ptr->Get_n_user(), + mix_ptr->Get_description().c_str())); + } + std::map::const_iterator cit; + for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) + { + solution_ptr = solution_bsearch(cit->first, &n, TRUE); + if (solution_ptr == NULL) + { + input_error++; + return (ERROR); + } + output_msg(sformatf("\t%11.3e Solution %d\t%-55s\n", + (double) cit->second, + cit->first, solution[n]->description)); + } + output_msg(sformatf("\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_reaction(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Debugging print of individual chemical reactions for + * species or phases + */ + int j; + struct rxn_token *next_token; + + if (pr.use == FALSE || pr.all == FALSE) + return (OK); + + output_msg(sformatf("%s\t\n", rxn_ptr->token[0].s->name)); + output_msg(sformatf("\n\tlog k:\n")); + for (j = 0; j < MAX_LOG_K_INDICES; j++) + { + output_msg(sformatf("\t%f", (double) rxn_ptr->logk[j])); + } + output_msg(sformatf("\n\nReaction:\n")); + for (next_token = rxn_ptr->token; next_token->s != NULL; next_token++) + { + output_msg(sformatf("\t\t%s\t%f\n", next_token->s->name, + (double) next_token->coef)); + } + output_msg(sformatf("\n")); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_saturation_indices(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices of all applicable pure_phases + */ + int i; + LDBLE si, iap; + LDBLE lk; + LDBLE la_eminus; + struct rxn_token *rxn_ptr; + struct reaction *reaction_ptr; + const char *pr_in; + //bool PR = false, DV = false, PR_inprint, gas = true; + bool PR_inprint, gas = true; + + if (pr.saturation_indices == FALSE || pr.all == FALSE) + return (OK); + if (state == INITIAL_SOLUTION) + { + iap = 0; + for (rxn_ptr = pe_x[default_pe_x].rxn->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + iap += rxn_ptr->coef * rxn_ptr->s->la; + /* fprintf(output,"\t%s\t%f\t%f\n", rxn_ptr->s->name, rxn_ptr->coef, rxn_ptr->s->la ); */ + } + lk = k_calc(pe_x[default_pe_x].rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); + la_eminus = lk + iap; + /* fprintf(output,"\t%s\t%f\n", "pe", si ); */ + } + else + { + la_eminus = s_eminus->la; + } +/* If a fixed pressure gas-phase disappeared, no PR for the SI's of gases... */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_unknown == NULL || gas_unknown->moles < 1e-12) + gas = false; + } + } + +/* + * Print heading + */ + print_centered("Saturation indices"); + output_msg(sformatf("\t%-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI ", + "log IAP", "log K(", int(tk_x), " K, ", int(floor(patm_x + 0.5)), " atm)")); + + for (i = 0; i < count_phases; i++) + { + if (phases[i]->in == FALSE || phases[i]->type != SOLID) + continue; + /* check for solids and gases in equation */ + if (phases[i]->replaced) + reaction_ptr = phases[i]->rxn_s; + else + reaction_ptr = phases[i]->rxn; +/* + * Print saturation index + */ + PR_inprint = false; + if (phases[i]->pr_in) + { + PR_inprint = true; + phases[i]->pr_in = false; + } + //lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); + reaction_ptr->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - + (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc_x + phases[i]->logk[vm2] * tc_x * tc_x); + lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); + if (PR_inprint) + phases[i]->pr_in = true; + iap = 0.0; + for (rxn_ptr = reaction_ptr->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s != s_eminus) + { + iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; + } + else + { + iap += la_eminus * rxn_ptr->coef; + } + } + si = -lk + iap; + //if (gas && phases[i]->pr_in && phases[i]->pr_p) + //{ + // pr_in = "**"; + // PR = true; + //} + //else if (fabs(reaction_ptr->logk[delta_v]) > 0.01 && patm_x > 1) + //{ + // pr_in = "* "; + // DV = true; + //} + //else + pr_in = " "; + + output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", + phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, + phases[i]->formula)); + //if (fabs(reaction_ptr->logk[delta_v]) > 0.01 && patm_x > 1) + // output_msg(sformatf("\t%s%6.2f%s", + // " Delta_V ", reaction_ptr->logk[delta_v], " cm3/mol")); + if (gas && phases[i]->pr_in && phases[i]->pr_p) + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + output_msg("\n"); + + } + //if (DV) + // output_msg(sformatf("\t%24s %s\n", + // "* ", "with Delta_V * (P - 1) / 2.3RT.")); + //if (PR) + // output_msg(sformatf("\t%24s %s\n", + // "**", "SI from Peng-Robinson fugacity - Delta_V * (P - 1) / 2.3RT.")); + //if (PR || DV) + // output_msg("\n"); + //else + output_msg("\n\n"); + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices and masses of pure_phases in pp_assemblage + */ + int j, k; + LDBLE si, iap, lk; + char token[MAX_LENGTH]; + struct rxn_token *rxn_ptr; + struct phase *phase_ptr; + //bool PR = false, PR_inprint; + bool PR_inprint; + const char *pr_in; + + if (pr.pp_assemblage == FALSE || pr.all == FALSE) + return (OK); + if (pure_phase_unknown == NULL) + return (OK); + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); +/* + * Print heading + */ + print_centered("Phase assemblage"); + output_msg(sformatf("%73s\n", "Moles in assemblage")); + output_msg(sformatf("%-14s%8s%2s%7s %11s", "Phase", "SI", " ", "log IAP", + "log K(T, P)")); + output_msg(sformatf(" %8s%12s%12s", " Initial", " Final", + " Delta")); + output_msg("\n\n"); + + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); +/* + * Print saturation index + */ + iap = 0.0; + phase_ptr = x[j]->phase; + if (x[j]->phase->rxn_x == NULL || phase_ptr->in == FALSE) + { + output_msg(sformatf("%-18s%23s", x[j]->phase->name, + "Element not present.")); + } + else + { + phase_ptr = x[j]->phase; + PR_inprint = false; + if (phase_ptr->pr_in) + { + PR_inprint = true; + phase_ptr->pr_in = false; + } + lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); + if (PR_inprint) + phase_ptr->pr_in = true; + for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s != s_eminus) + { + iap += (rxn_ptr->s->lm + rxn_ptr->s->lg) * rxn_ptr->coef; + } + else + { + iap += s_eminus->la * rxn_ptr->coef; + } + } + si = -lk + iap; + /* + for (rxn_ptr = x[j]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = -x[j]->phase->lk + iap; + output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) x[j]->phase->lk); + */ + //if (phase_ptr->pr_in && phase_ptr->pr_p) + //{ + // pr_in = "**"; + // PR = true; + //} + //else + pr_in = " "; + output_msg(sformatf("%-14s%8.2f%2s%7.2f %8.2f", + x[j]->phase->name, (double) si, pr_in, (double) iap, + (double) lk)); + } +/* + * Print pure phase assemblage data + */ + if (x[j]->moles < 0.0) + x[j]->moles = 0.0; + if (state != TRANSPORT && state != PHAST) + { + sprintf(token, " %11.3e %11.3e %11.3e", + (double) (comp_ptr->Get_moles() + + comp_ptr->Get_delta()), (double) x[j]->moles, + (double) (x[j]->moles - comp_ptr->Get_moles() - + comp_ptr->Get_delta())); + } + else + { + sprintf(token, " %11.3e %11.3e %11.3e", + (double) comp_ptr->Get_initial_moles(), + (double) x[j]->moles, + (double) (x[j]->moles - comp_ptr->Get_initial_moles())); + } + if (x[j]->moles <= 0.0) + { + for (k = 0; k < 11; k++) + { + token[13 + k] = ' '; + } + } + if (comp_ptr->Get_add_formula().size() == 0) + { + output_msg(sformatf("%37s\n", token)); + } + else + { + output_msg(sformatf("\n %-18s%-15s%36s\n", + comp_ptr->Get_add_formula().c_str(), " is reactant", token)); + } + } + //if (PR) + // output_msg(sformatf("%25s %s\n", + // "**", "SI from Peng-Robinson fugacity - Delta(V) * (P - 1) / 2.3RT.")); + output_msg("\n"); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of solution, uses array species_list for + * order of aqueous species. + */ + int i; + const char *name, *name1; + struct master *master_ptr; + LDBLE min; + LDBLE lm; + + if (pr.species == FALSE || pr.all == FALSE) + return (OK); + min = -1000; + print_centered("Distribution of species"); +/* + * Heading for species + */ + if (pitzer_model == TRUE) + { + if (ICON == TRUE) + { + output_msg(sformatf("%67s%11s\n", "MacInnes", "MacInnes")); + output_msg(sformatf("\t%-15s%12s%12s%10s%10s%10s\n", " ", + " ", "MacInnes", "Log ", "Log ", "Log ")); + } + else + { + output_msg(sformatf("%67s%11s\n", "Unscaled", "Unscaled")); + output_msg(sformatf("\t%-15s%12s%12s%10s%10s%10s\n", " ", + " ", "Unscaled", "Log ", "Log ", "Log ")); + } + } + else + { + output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n", " ", + " ", " ", "Log ", "Log ", "Log ", "mole V")); + } + output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n\n", "Species", + "Molality", "Activity", "Molality", "Activity", "Gamma", "cm3/mol")); +/* + * Print list of species + */ + s_h2o->lm = s_h2o->la; + name = s_hplus->secondary->elt->name; + for (i = 0; i < count_species_list; i++) + { +/* + * Get name of master species + */ + if (species_list[i].s->type == EX) + continue; + if (species_list[i].s->type == SURF) + continue; + if (species_list[i].master_s->secondary != NULL) + { + master_ptr = species_list[i].master_s->secondary; + name1 = species_list[i].master_s->secondary->elt->name; + } + else + { + master_ptr = species_list[i].master_s->primary; + name1 = species_list[i].master_s->primary->elt->name; + } +/* + * Check if new master species, print total molality + */ + if (name1 != name) + { + name = name1; + output_msg(sformatf("%-11s%12.3e\n", name, + (double) (master_ptr->total / mass_water_aq_x))); + min = censor * master_ptr->total / mass_water_aq_x; + if (min > 0) + { + min = log10(min); + } + else + { + min = -1000.; + } + } +/* + * Print species data + */ + if (species_list[i].s->lm > min) + { + if (species_list[i].s == s_h2o) + { + lm = log10(s_h2o->moles / mass_water_aq_x); + } + else + { + lm = species_list[i].s->lm; + } + output_msg(sformatf( + " %-13s%12.3e%12.3e%10.3f%10.3f%10.3f", + species_list[i].s->name, + (double) ((species_list[i].s->moles) / + mass_water_aq_x), + (double) under(species_list[i].s->lm + + species_list[i].s->lg), (double) lm, + (double) (species_list[i].s->lm + + species_list[i].s->lg), + (double) species_list[i].s->lg)); + if (species_list[i].s->logk[vm_tc] || !strcmp(species_list[i].s->name, "H+")) + output_msg(sformatf("%10.2f\n", + (double) species_list[i].s->logk[vm_tc])); + else + output_msg(sformatf(" (0) \n")); + } + } + output_msg(sformatf("\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of surface, including charge and potential, + * grams and specific area, moles of each species on surface sites, + * and description of diffuse layer if applicable. + */ + int i, j, k; + struct surface *surface_ptr; + char name[MAX_LENGTH], token[MAX_LENGTH]; + struct master *master_ptr; + LDBLE molfrac, charge; + char *ptr; +/* + * Print surface speciation + */ + surface_ptr = use.Get_surface_ptr(); + if (surface_ptr == NULL || pr.surface == FALSE || pr.all == FALSE) + return (OK); + if (surface_ptr->type == CD_MUSIC) + return (print_surface_cd_music()); + + if (state >= REACTION) + { + print_centered("Surface composition"); + } +/* + * Print list of species + */ + + s_h2o->lm = s_h2o->la; + for (j = 0; j < count_unknowns; j++) + { + /*if (use.Get_surface_ptr()->edl == TRUE) { */ + if (use.Get_surface_ptr()->type == DDL) + { + if (x[j]->type != SURFACE_CB) + continue; + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); + } + else + { + if (x[j]->type != SURFACE) + continue; + strcpy(token, x[j]->master[0]->elt->name); + replace("_", " ", token); + ptr = token; + copy_token(name, &ptr, &k); + } + output_msg(sformatf("%-14s\n", name)); +/* + * Description of surface + */ + if (dl_type_x != NO_DL) + { + output_msg(sformatf( + "\t%11.3e Surface + diffuse layer charge, eq\n", + (double) x[j]->f)); + } + /*if (use.Get_surface_ptr()->edl == TRUE && diffuse_layer_x == FALSE) { */ + if (use.Get_surface_ptr()->type == DDL && dl_type_x == NO_DL) + { + charge = x[j]->f; + } + else + { + charge = calc_surface_charge(name); + } + output_msg(sformatf("\t%11.3e Surface charge, eq\n", + (double) charge)); + if (x[j]->type == SURFACE_CB) + { + if ((x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) > 0) + { + output_msg(sformatf("\t%11.3e sigma, C/m**2\n", + (double) (charge * F_C_MOL / + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams)))); + } + else + { + output_msg(sformatf("\tundefined sigma, C/m**2\n")); + } + output_msg(sformatf("\t%11.3e psi, V\n", + (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ))); + output_msg(sformatf("\t%11.3e -F*psi/RT\n", + (double) (x[j]->master[0]->s->la * (-2) * LOG_10))); + output_msg(sformatf("\t%11.3e exp(-F*psi/RT)\n", + exp(x[j]->master[0]->s->la * (-2) * LOG_10))); + if (x[j]->surface_comp->phase_name != NULL) + { + output_msg(sformatf( + "\t%11.3e specific area, m**2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->phase_name)); + output_msg(sformatf( + "\t%11.3e m**2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * + x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->phase_name)); + } + else if (x[j]->surface_comp->rate_name != NULL) + { + output_msg(sformatf( + "\t%11.3e specific area, m**2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->rate_name)); + output_msg(sformatf( + "\t%11.3e m**2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * + x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->rate_name)); + } + else + { + output_msg(sformatf( + "\t%11.3e specific area, m**2/g\n", + (double) x[j]->surface_charge->specific_area)); + output_msg(sformatf("\t%11.3e m**2 for %11.3e g\n\n", + (double) (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams), + (double) x[j]->surface_charge->grams)); + } + if (dl_type_x != NO_DL) + print_diffuse_layer(x[j]->surface_charge); + output_msg(sformatf("\n")); +/* + * Heading for species + */ + for (k = j - 1; k < count_unknowns; k++) + { + if (x[k]->type != SURFACE) + continue; + if (x[j] != x[k]->potential_unknown) + continue; + master_ptr = x[k]->master[0]; + output_msg(sformatf("%-14s\n", + x[k]->master[0]->elt->name)); + output_msg(sformatf("\t%11.3e moles", + (double) x[k]->moles)); + if (x[k]->surface_comp->phase_name != NULL) + { + output_msg(sformatf("\t[%g mol/(mol %s)]\n", + (double) x[k]->surface_comp->phase_proportion, + x[k]->surface_comp->phase_name)); + } + else if (x[k]->surface_comp->rate_name != NULL) + { + output_msg(sformatf( + "\t[%g mol/(mol kinetic reactant %s)]\n", + (double) x[k]->surface_comp->phase_proportion, + x[k]->surface_comp->rate_name)); + } + else + { + output_msg(sformatf("\n")); + } + output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n", " ", + " ", "Mole", " ", "Log")); + output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", + "Species", "Moles", "Fraction", "Molality", + "Molality")); + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].master_s != master_ptr->s) + continue; +/* + * Print species data + */ + if (x[k]->moles >= MIN_RELATED_SURFACE) + { + molfrac = + (LDBLE) (species_list[i].s->moles) / x[k]->moles * + species_list[i].s->equiv; + } + else + { + molfrac = 0.0; + } + output_msg(sformatf( + "\t%-15s%12.3e%12.3f%12.3e%12.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) molfrac, + (double) (species_list[i].s->moles / + mass_water_aq_x), + log10(species_list[i].s->moles / + mass_water_aq_x))); + } + output_msg(sformatf("\n")); + } + } + else + { + k = j; + master_ptr = x[k]->master[0]; + output_msg(sformatf("%-14s\n", x[k]->master[0]->elt->name)); + output_msg(sformatf("\t%11.3e moles\n", + (double) x[k]->moles)); + output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n", " ", " ", + "Mole", " ", "Log")); + output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", + "Species", "Moles", "Fraction", "Molality", + "Molality")); + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].master_s != master_ptr->s) + continue; +/* + * Print species data + */ + if (x[k]->moles >= MIN_RELATED_SURFACE) + { + molfrac = + (double) (species_list[i].s->moles) / x[k]->moles * + species_list[i].s->equiv; + } + else + { + molfrac = 0.0; + } + output_msg(sformatf( + "\t%-15s%12.3e%12.3f%12.3e%12.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) molfrac, + (double) (species_list[i].s->moles / + mass_water_aq_x), + log10(species_list[i].s->moles / mass_water_aq_x))); + } + output_msg(sformatf("\n")); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_surface_cd_music(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of cd music surfaces, including charge and potential, + * grams and specific area, moles of each species on surface sites, + * and description of diffuse layer if applicable. + */ + int i, j, k; + struct surface *surface_ptr; + char name[MAX_LENGTH]; + struct master *master_ptr, *master_ptr0, *master_ptr1, *master_ptr2; + struct unknown *unknown_ptr0, *unknown_ptr1, *unknown_ptr2; + LDBLE molfrac, charge0, charge1, charge2, sum; + + +/* + * Print surface speciation + */ + surface_ptr = use.Get_surface_ptr(); + if (surface_ptr == NULL || pr.surface == FALSE || pr.all == FALSE) + return (OK); + + if (state >= REACTION) + { + print_centered("Surface composition"); + } +/* + * Print list of species + */ + + s_h2o->lm = s_h2o->la; + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE_CB) + continue; + strcpy(name, x[j]->master[0]->elt->name); + replace("_psi", "", name); + output_msg(sformatf("%-14s\n", name)); +/* + * Description of surface + */ + if (dl_type_x != NO_DL) + { + output_msg(sformatf( + "\t%11.3e Surface + diffuse layer charge, eq\n\n", + (double) (x[j + 2]->f + (x[j]->surface_charge->sigma0 + x[j]->surface_charge->sigma1) * (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams) / F_C_MOL))); + } + master_ptr0 = + surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI); + master_ptr1 = + surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI1); + master_ptr2 = + surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI2); + unknown_ptr0 = x[master_ptr0->unknown->number]; + unknown_ptr1 = x[master_ptr1->unknown->number]; + unknown_ptr2 = x[master_ptr2->unknown->number]; + + charge0 = unknown_ptr0->f; + charge1 = unknown_ptr1->f; + if (dl_type_x != NO_DL) + { + charge2 = + x[j]->surface_charge->sigma2 * + (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) / F_C_MOL; + } + else + { + charge2 = unknown_ptr2->f; + } + sum = 0; + for (k = 0; k < x[j]->count_comp_unknowns; k++) + { + sum += + x[j]->comp_unknowns[k]->moles * + x[j]->comp_unknowns[k]->master[0]->s->z; + } + output_msg(sformatf("\t%11.3e Surface charge, plane 0, eq\n", + (double) (charge0 + sum))); + output_msg(sformatf("\t%11.3e Surface charge, plane 1, eq\n", + (double) charge1)); + output_msg(sformatf("\t%11.3e Surface charge, plane 2, eq\n", + (double) charge2)); + output_msg(sformatf( + "\t%11.3e Sum of surface charge, all planes, eq\n\n", + (double) (charge0 + sum + charge1 + charge2))); + if (x[j]->type == SURFACE_CB) + { + if ((x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams) > 0) + { + output_msg(sformatf( + "\t%11.3e sigma, plane 0, C/m**2\n", + (double) x[j]->surface_charge->sigma0)); + output_msg(sformatf( + "\t%11.3e sigma, plane 1, C/m**2\n", + (double) x[j]->surface_charge->sigma1)); + output_msg(sformatf( + "\t%11.3e sigma, plane 2, C/m**2\n", + (double) x[j]->surface_charge->sigma2)); + output_msg(sformatf( + "\t%11.3e sigma, diffuse layer, C/m**2\n\n", + (double) x[j]->surface_charge->sigmaddl)); + } + else + { + output_msg(sformatf("\tundefined sigma, C/m**2\n")); + } + output_msg(sformatf("\t%11.3e psi, plane 0, V\n", + (double) (-master_ptr0->s->la * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ))); + output_msg(sformatf("\t%11.3e psi, plane 1, V\n", + (double) (-master_ptr1->s->la * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ))); + output_msg(sformatf("\t%11.3e psi, plane 2, V\n\n", + (double) (-master_ptr2->s->la * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ))); + output_msg(sformatf("\t%11.3e exp(-F*psi/RT), plane 0\n", + (double) (exp(master_ptr0->s->la * LOG_10)))); + output_msg(sformatf("\t%11.3e exp(-F*psi/RT), plane 1\n", + (double) (exp(master_ptr1->s->la * LOG_10)))); + output_msg(sformatf( + "\t%11.3e exp(-F*psi/RT), plane 2\n\n", + (double) (exp(master_ptr2->s->la * LOG_10)))); + + output_msg(sformatf("\t%11.3e capacitance 0-1, F/m^2\n", + (double) (x[j]->surface_charge->capacitance[0]))); + output_msg(sformatf("\t%11.3e capacitance 1-2, F/m^2\n", + (double) (x[j]->surface_charge->capacitance[1]))); + + if (x[j]->surface_comp->phase_name != NULL) + { + output_msg(sformatf( + "\t%11.3e specific area, m^2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->phase_name)); + output_msg(sformatf( + "\t%11.3e m^2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * + x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->phase_name)); + } + else if (x[j]->surface_comp->rate_name != NULL) + { + output_msg(sformatf( + "\t%11.3e specific area, m^2/mol %s\n", + (double) x[j]->surface_charge->specific_area, + x[j]->surface_comp->rate_name)); + output_msg(sformatf( + "\t%11.3e m^2 for %11.3e moles of %s\n\n", + (double) (x[j]->surface_charge->grams * + x[j]->surface_charge->specific_area), + (double) x[j]->surface_charge->grams, + x[j]->surface_comp->rate_name)); + } + else + { + output_msg(sformatf( + "\t%11.3e specific area, m^2/g\n", + (double) x[j]->surface_charge->specific_area)); + output_msg(sformatf("\t%11.3e m^2 for %11.3e g\n\n", + (double) (x[j]->surface_charge->specific_area * + x[j]->surface_charge->grams), + (double) x[j]->surface_charge->grams)); + } + if (dl_type_x != NO_DL) + print_diffuse_layer(x[j]->surface_charge); + output_msg(sformatf("\n")); +/* + * Heading for species + */ + for (k = j - 1; k < count_unknowns; k++) + { + if (x[k]->type != SURFACE) + continue; + if (x[j] != x[k]->potential_unknown) + continue; + master_ptr = x[k]->master[0]; + output_msg(sformatf("%-14s\n", + x[k]->master[0]->elt->name)); + output_msg(sformatf("\t%11.3e moles", + (double) x[k]->moles)); + if (x[k]->surface_comp->phase_name != NULL) + { + output_msg(sformatf("\t[%g mol/(mol %s)]\n", + (double) x[k]->surface_comp->phase_proportion, + x[k]->surface_comp->phase_name)); + } + else if (x[k]->surface_comp->rate_name != NULL) + { + output_msg(sformatf( + "\t[%g mol/(mol kinetic reactant %s)]\n", + (double) x[k]->surface_comp->phase_proportion, + x[k]->surface_comp->rate_name)); + } + else + { + output_msg(sformatf("\n")); + } + output_msg(sformatf("\t%-20s%12s%12s%12s%12s\n", " ", + " ", "Mole", " ", "Log")); + output_msg(sformatf("\t%-20s%12s%12s%12s%12s\n\n", + "Species", "Moles", "Fraction", "Molality", + "Molality")); + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].master_s != master_ptr->s) + continue; +/* + * Print species data + */ + if (x[k]->moles >= MIN_RELATED_SURFACE) + { + molfrac = + (LDBLE) (species_list[i].s->moles) / x[k]->moles * + species_list[i].s->equiv; + } + else + { + molfrac = 0.0; + } + output_msg(sformatf( + "\t%-20s%12.3e%12.3f%12.3e%12.3f\n", + species_list[i].s->name, + (double) species_list[i].s->moles, + (double) molfrac, + (double) (species_list[i].s->moles / + mass_water_aq_x), + log10(species_list[i].s->moles / + mass_water_aq_x))); + } + output_msg(sformatf("\n")); + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_totals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print total concentrations of elements, molality and moles. + */ + int i, pure_water; + LDBLE EC, dens; + + if (pr.totals == FALSE || pr.all == FALSE) + return (OK); + print_centered("Solution composition"); + pure_water = TRUE; + output_msg(sformatf("\t%-15s%12s%12s\n\n", "Elements", "Molality", + "Moles")); + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == alkalinity_unknown) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e\n", + x[i]->total->description, + (double) (x[i]->f / mass_water_aq_x), + (double) x[i]->f)); + pure_water = FALSE; + } + if (x[i] == ph_unknown) + continue; + if (x[i] == pe_unknown) + continue; + if (x[i] == charge_balance_unknown) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + x[i]->description, + (double) (x[i]->sum / mass_water_aq_x), + (double) x[i]->sum)); + output_msg(sformatf(" Charge balance\n")); + pure_water = FALSE; + continue; + } + if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + x[i]->description, + (double) (x[i]->sum / mass_water_aq_x), + (double) x[i]->sum)); + output_msg(sformatf(" Equilibrium with %s\n", + x[i]->phase->name)); + pure_water = FALSE; + continue; + } + if (x[i]->type == MB) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e\n", + x[i]->description, + (double) (x[i]->sum / mass_water_aq_x), + (double) x[i]->sum)); + pure_water = FALSE; + } + } + + if (pure_water == TRUE) + { + output_msg(sformatf("\t%-15s\n", "Pure water")); + } +/* + * Description of solution + */ + output_msg(sformatf("\n")); + print_centered("Description of solution"); +/* + * pH + */ + output_msg(sformatf("%45s%7.3f ", "pH = ", + (double) (-(s_hplus->la)))); + if (ph_unknown == NULL) + { + output_msg(sformatf("\n")); + } + else if (ph_unknown == charge_balance_unknown) + { + output_msg(sformatf(" Charge balance\n")); + } + else if (ph_unknown->type == SOLUTION_PHASE_BOUNDARY) + { + output_msg(sformatf(" Equilibrium with %s\n", + ph_unknown->phase->name)); + } + else if (ph_unknown->type == ALK) + { + output_msg(sformatf(" Adjust alkalinity\n")); + } +/* + * pe + */ + output_msg(sformatf("%45s%7.3f ", "pe = ", + (double) (-(s_eminus->la)))); + if (pe_unknown == NULL) + { + output_msg(sformatf("\n")); + } + else if (pe_unknown == charge_balance_unknown) + { + output_msg(sformatf(" Charge balance\n")); + } + else if (pe_unknown->type == SOLUTION_PHASE_BOUNDARY) + { + output_msg(sformatf(" Equilibrium with %s\n", + pe_unknown->phase->name)); + } + else if (pe_unknown->type == MH) + { + output_msg(sformatf(" Adjusted to redox equilibrium\n")); + } +/* + * Others + */ + EC = calc_SC(); + if (EC > 0) + { + output_msg(sformatf("%36s%i%7s%i\n", + "Specific Conductance (uS/cm, ", (int) tc_x, " oC) = ", (int) EC)); + } +/* VP: Density Start */ + if (print_density) + { + dens = calc_dens(); + output_msg(sformatf("%45s%9.5f", "Density (g/cm3) = ", + (double) dens)); + if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program's limit)")); + else output_msg(sformatf("\n")); + } +/* VP: Density End */ + output_msg(sformatf("%45s%7.3f\n", "Activity of water = ", + exp(s_h2o->la * LOG_10))); + output_msg(sformatf("%45s%11.3e\n", "Ionic strength = ", + (double) mu_x)); + output_msg(sformatf("%45s%11.3e\n", "Mass of water (kg) = ", + (double) mass_water_aq_x)); + if (alkalinity_unknown == NULL) + { + output_msg(sformatf("%45s%11.3e\n", + "Total alkalinity (eq/kg) = ", + (double) (total_alkalinity / mass_water_aq_x))); + } + if (carbon_unknown == NULL) + { + output_msg(sformatf("%45s%11.3e\n", + "Total carbon (mol/kg) = ", + (double) (total_carbon / mass_water_aq_x))); + } + output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", + (double) (total_co2 / mass_water_aq_x))); + output_msg(sformatf("%45s%6.2f\n", "Temperature (deg C) = ", + (double) tc_x)); + + if (patm_x != 1.0) + { + /* only print if different than default */ + output_msg(sformatf("%45s%5.2f\n", "Pressure (atm) = ", + (double) patm_x)); + } + + output_msg(sformatf("%45s%11.3e\n", "Electrical balance (eq) = ", + (double) cb_x)); + output_msg(sformatf("%45s%6.2f\n", + "Percent error, 100*(Cat-|An|)/(Cat+|An|) = ", + (double) (100 * cb_x / total_ions_x))); + output_msg(sformatf("%45s%3d\n", "Iterations = ", iterations)); + if (pitzer_model == TRUE || sit_model == TRUE) + { + if (always_full_pitzer == FALSE) + { + output_msg(sformatf("%45s%3d\n", "Gamma iterations = ", + gamma_iterations)); + } + else + { + output_msg(sformatf("%45s%3d\n", "Gamma iterations = ", + iterations)); + } + output_msg(sformatf("%45s%9.5f\n", "Osmotic coefficient = ", + (double) COSMOT)); + if (print_density) output_msg(sformatf("%45s%9.5f\n", "Density of water = ", + (double) DW0)); + } + output_msg(sformatf("%45s%e\n", "Total H = ", (double) total_h_x)); + output_msg(sformatf("%45s%e\n", "Total O = ", (double) total_o_x)); + output_msg(sformatf("\n")); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_user_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print with user defined BASIC print routine + */ + int i; + struct kinetics *kinetics_ptr; + + char l_command[] = "run"; + + if (pr.user_print == FALSE || pr.all == FALSE) + return (OK); + if (user_print->commands == NULL) + return (OK); + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + kinetics_ptr = use.Get_kinetics_ptr(); + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + } + else + { + use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + } + } + print_centered("User print"); + if (user_print->new_def == TRUE) + { + /* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */ + if (basic_compile + (user_print->commands, &user_print->linebase, + &user_print->varbase, &user_print->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + user_print->new_def = FALSE; + } + if (basic_run + (l_command, user_print->linebase, user_print->varbase, + user_print->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + output_msg(sformatf("\n")); + if (use.Get_kinetics_in() == TRUE) + { + use.Set_kinetics_ptr(kinetics_ptr); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_using(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print entities used in calculation + */ + //struct mix *mix_ptr; + cxxMix * mix_ptr; + struct solution *solution_ptr; + //struct exchange *exchange_ptr; + struct surface *surface_ptr; + //struct pp_assemblage *pp_assemblage_ptr; + struct ss_assemblage *ss_assemblage_ptr; + //struct gas_phase *gas_phase_ptr; + //struct irrev *irrev_ptr; + struct kinetics *kinetics_ptr; + int n; + + if (pr.use == FALSE || pr.all == FALSE) + return (OK); + if (state < REACTION || phast == TRUE) + return (OK); +/* + * Mixture or Solution + */ + if (use.Get_mix_in() == TRUE) + { + if (state == TRANSPORT) + { + mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); + } + else + { + mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user_orig()); + } + if (mix_ptr == NULL) + { + mix_ptr = (cxxMix *) use.Get_mix_ptr(); + } + if (mix_ptr != NULL) + { + if (state == TRANSPORT) + { + output_msg(sformatf("Using mix %d.\t%s\n", + use.Get_n_mix_user(), mix_ptr->Get_description().c_str())); + } + else + { + output_msg(sformatf("Using mix %d.\t%s\n", + use.Get_n_mix_user_orig(), mix_ptr->Get_description().c_str())); + } + + } + } + else + { + solution_ptr = solution_bsearch(use.Get_n_solution_user(), &n, TRUE); + output_msg(sformatf("Using solution %d.\t%s\n", + use.Get_n_solution_user(), solution_ptr->description)); + } +/* + * Exchange and surface + */ + if (use.Get_exchange_in() == TRUE) + { + cxxExchange *exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); + output_msg(sformatf("Using exchange %d.\t%s\n", + use.Get_n_exchange_user(), exchange_ptr->Get_description().c_str())); + } + if (use.Get_surface_in() == TRUE) + { + surface_ptr = surface_bsearch(use.Get_n_surface_user(), &n); + output_msg(sformatf("Using surface %d.\t%s\n", + use.Get_n_surface_user(), surface_ptr->description)); + } + if (use.Get_pp_assemblage_in() == TRUE) + { + //pp_assemblage_ptr = pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), &n); + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user()); + output_msg(sformatf("Using pure phase assemblage %d.\t%s\n", + use.Get_n_pp_assemblage_user(), pp_assemblage_ptr->Get_description().c_str())); + } + if (use.Get_ss_assemblage_in() == TRUE) + { + ss_assemblage_ptr = + ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); + output_msg(sformatf( + "Using solid solution assemblage %d.\t%s\n", + use.Get_n_ss_assemblage_user(), + ss_assemblage_ptr->description)); + } + if (use.Get_gas_phase_in() == TRUE) + { + //gas_phase_ptr = gas_phase_bsearch(use.Get_n_gas_phase_user(), &n); + cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, use.Get_n_gas_phase_user()); + output_msg(sformatf("Using gas phase %d.\t%s\n", + use.Get_n_gas_phase_user(), gas_phase_ptr->Get_description().c_str())); + } + if (use.Get_temperature_in() == TRUE) + { + cxxTemperature *temperature_ptr = Utilities::Rxn_find(Rxn_temperature_map, use.Get_n_temperature_user()); + output_msg(sformatf("Using temperature %d.\t%s\n", + use.Get_n_temperature_user(), temperature_ptr->Get_description().c_str())); + } + if (use.Get_pressure_in() == TRUE) + { + cxxPressure *pressure_ptr = Utilities::Rxn_find(Rxn_pressure_map, use.Get_n_pressure_user()); + output_msg(sformatf("Using pressure %d.\t%s\n", + use.Get_n_pressure_user(), pressure_ptr->Get_description().c_str())); + } + if (use.Get_reaction_in() == TRUE) + { + if (state != TRANSPORT || transport_step > 0) + { + //irrev_ptr = irrev_bsearch(use.n_irrev_user, &n); + cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); + output_msg(sformatf("Using reaction %d.\t%s\n", + use.Get_n_reaction_user(), reaction_ptr->Get_description().c_str())); + } + } + if (use.Get_kinetics_in() == TRUE) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &n); + } + else + { + kinetics_ptr = kinetics_bsearch(-2, &n); + } + output_msg(sformatf("Using kinetics %d.\t%s\n", + use.Get_n_kinetics_user(), kinetics_ptr->description)); + } + output_msg(sformatf("\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints selected gas phase data + */ + int i; + LDBLE p, total_moles, volume; + LDBLE moles; + + if (punch.count_gases <= 0) + return (OK); + p = 0.0; + total_moles = 0.0; + volume = 0.0; + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + if (gas_unknown != NULL && use.Get_gas_phase_ptr() != NULL) + { + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + gas_phase_ptr->Set_total_moles(gas_unknown->moles); + gas_phase_ptr->Set_volume( + gas_phase_ptr->Get_total_moles() * R_LITER_ATM * tk_x / + gas_phase_ptr->Get_total_p()); + } + p = gas_phase_ptr->Get_total_p(); + total_moles = gas_phase_ptr->Get_total_moles(); + volume = total_moles * R_LITER_ATM * tk_x / gas_phase_ptr->Get_total_p(); + if (gas_phase_ptr->Get_v_m() > 0.03) + volume = 0.03 * gas_phase_ptr->Get_total_moles(); + } + if (punch.high_precision == FALSE) + { + fpunchf("pressure", "%12.4e\t", (double) p); + fpunchf("total mol", "%12.4e\t", (double) total_moles); + fpunchf("volume", "%12.4e\t", (double) volume); + } + else + { + fpunchf("pressure", "%20.12e\t", (double) p); + fpunchf("total mol", "%20.12e\t", (double) total_moles); + fpunchf("volume", "%20.12e\t", (double) volume); + } + for (i = 0; i < punch.count_gases; i++) + { + moles = 0.0; + if (gas_phase_ptr != NULL && punch.gases[i].phase != NULL) + { + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + //for (j = 0; j < use.Get_gas_phase_ptr()->count_comps; j++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + if (phase_ptr != punch.gases[i].phase) + continue; + moles = phase_ptr->moles_x; + if (moles <= MIN_TOTAL) + moles = 0.0; + break; + } + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("g_%s", punch.gases[i].name), "%12.4e\t", (double) moles); + } + else + { + fpunchf(sformatf("g_%s", punch.gases[i].name), "%20.12e\t", + (double) moles); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints solid solution composition if present + */ + int i, j, k; + int found; + LDBLE moles; + +/* + * Print solid solutions + */ + for (k = 0; k < punch.count_s_s; k++) + { + found = FALSE; + if (use.Get_ss_assemblage_ptr() != NULL) + { + for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + { + for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; + i++) + { + if (strcmp_nocase + (punch.s_s[k].name, + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name) == 0) + { + if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + { + moles = + use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + } + else + { + moles = 0; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), + "%12.4e\t", (double) moles); + } + else + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), + "%20.12e\t", (double) moles); + } + found = TRUE; + break; + } + } + if (found == TRUE) + break; + } + } + if (found == FALSE) + { + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", (double) 0.0); + } + else + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", + (double) 0.0); + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_totals(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print total concentrations of elements, molality and moles. + */ + int j; + LDBLE molality; + + for (j = 0; j < punch.count_totals; j++) + { + if (punch.totals[j].master == NULL) + { + molality = 0.0; + } + else if (punch.totals[j].master->primary == TRUE) + { + if (strncmp(punch.totals[j].name, "Alkalinity", 20) == 0) + { + molality = total_alkalinity / mass_water_aq_x; + } else + { + molality = punch.totals[j].master->total_primary / mass_water_aq_x; + } + } + else + { + molality = punch.totals[j].master->total / mass_water_aq_x; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name), + "%12.4e\t", (double) molality); + } + else + { + fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name), + "%20.12e\t", (double) molality); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_molalities(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print concentrations of species (aq, ex, surf) + */ + int j; + LDBLE molality; + + for (j = 0; j < punch.count_molalities; j++) + { + molality = 0.0; + if (punch.molalities[j].s != NULL + && punch.molalities[j].s->in == TRUE) + { + molality = punch.molalities[j].s->moles / mass_water_aq_x; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name), + "%12.4e\t", (double) molality); + } + else + { + fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name), + "%20.12e\t", (double) molality); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_activities(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print concentrations of species (aq, ex, surf) + */ + int j; + LDBLE la; + + for (j = 0; j < punch.count_activities; j++) + { + la = -999.999; + if (punch.activities[j].s != NULL + && punch.activities[j].s->in == TRUE) + { + /*la = punch.activities[j].s->lm + punch.activities[j].s->lg; */ + la = log_activity(punch.activities[j].s->name); + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("la_%s", punch.activities[j].name), "%12.4e\t", + (double) la); + } + else + { + fpunchf(sformatf("la_%s", punch.activities[j].name), + "%20.12e\t", (double) la); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints masses of selected pure_phases in pp_assemblage + */ + int i, j; + LDBLE moles, delta_moles; + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + for (i = 0; i < punch.count_pure_phases; i++) + { + delta_moles = 0; + moles = 0.0; + if (punch.pure_phases[i].phase != NULL) + { + for (j = 0; j < count_unknowns; j++) + { + if (x == NULL || x[j]->type != PP) + continue; + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); +/* + * Print pure phase assemblage data + */ + if (punch.pure_phases[i].phase != x[j]->phase) + continue; + if (state != TRANSPORT && state != PHAST) + { + moles = x[j]->moles; + delta_moles = + x[j]->moles - comp_ptr->Get_moles() - + comp_ptr->Get_delta(); + } + else + { + moles = x[j]->moles; + delta_moles = + x[j]->moles - comp_ptr->Get_initial_moles(); + } + break; + } + } + if (punch.high_precision == FALSE) + { + fpunchf(punch.pure_phases[i].name, "%12.4e\t", (double) moles); + fpunchf(sformatf("d_%s", punch.pure_phases[i].name), "%12.4e\t", + (double) delta_moles); + } + else + { + fpunchf(punch.pure_phases[i].name, "%20.12e\t", (double) moles); + fpunchf(sformatf("d_%s", punch.pure_phases[i].name), + "%20.12e\t", (double) delta_moles); + } + } + return (OK); +} + +#define PHAST_NULL(x) (phast ? NULL : x) +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_identifiers(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints series of integers to identify simulation number, + * state of calculations, reaction or transport step number, + * and temp, ph, pe, and mass of water for each line + * of selected output. + */ + const char *sformat; + const char *dformat; + const char *gformat; + int i, l; + char token[MAX_LENGTH]; + + if (punch.in == FALSE) + return (OK); + if (punch.high_precision == FALSE) + { + l = 12; + sformat = "%12s\t"; + dformat = "%12d\t"; + gformat = "%12g\t"; + } + else + { + l = 20; + sformat = "%20s\t"; + dformat = "%20d\t"; + gformat = "%20g\t"; + } + +/* + * simulation or simul_tr + */ + + if (punch.sim == TRUE) + { + if (state != TRANSPORT && state != PHAST) + { + fpunchf(PHAST_NULL("sim"), dformat, simulation); + } + else + { + fpunchf(PHAST_NULL("sim"), dformat, simul_tr); + } + } + if (punch.state == TRUE) + { + switch (state) + { + case 0: + strcpy(token, "init"); + break; + case 1: + strcpy(token, "i_soln"); + break; + case 2: + strcpy(token, "i_exch"); + break; + case 3: + strcpy(token, "i_surf"); + break; + case 4: + strcpy(token, "i_gas"); + break; + case 5: + strcpy(token, "react"); + break; + case 6: + strcpy(token, "inverse"); + break; + case 7: + strcpy(token, "advect"); + break; + case 8: + strcpy(token, "transp"); + break; + } + fpunchf(PHAST_NULL("state"), sformat, token); + + } +/* + * solution number or cell number and time + */ + if (punch.soln == TRUE) + { + if (state == TRANSPORT || state == PHAST) + { + fpunchf(PHAST_NULL("soln"), dformat, cell); + } + else if (state == ADVECTION) + { + fpunchf(PHAST_NULL("soln"), dformat, use.Get_n_solution_user()); + } + else if (state < REACTION) + { + fpunchf(PHAST_NULL("soln"), dformat, use.Get_solution_ptr()->n_user); + } + else + { + if (use.Get_mix_in() == TRUE) + { + if (state != TRANSPORT) + { + fpunchf(PHAST_NULL("soln"), dformat, use.Get_n_mix_user_orig()); + } + else + { + fpunchf(PHAST_NULL("soln"), dformat, use.Get_n_mix_user()); + } + + } + else + { + fpunchf(PHAST_NULL("soln"), dformat, use.Get_n_solution_user()); + } + } + } + if (punch.dist == TRUE) + { + if (state == ADVECTION) + { + fpunchf(PHAST_NULL("dist_x"), dformat, use.Get_n_solution_user()); + } + else if (state == TRANSPORT) + { + fpunchf(PHAST_NULL("dist_x"), gformat, + (double) cell_data[cell - 1].mid_cell_x); + } + else + { + fpunchf(PHAST_NULL("dist_x"), dformat, -99); + } + } + /* + //if (punch.time == TRUE) + //{ + // if (state == REACTION && incremental_reactions == TRUE + // && use.Get_kinetics_ptr() != NULL) + // { + // if (use.Get_kinetics_ptr()->count_steps > 0) + // { + // kin_time_x = 0.; + // for (i = 0; i < reaction_step; i++) + // { + // if (i < use.Get_kinetics_ptr()->count_steps) + // { + // kin_time_x += use.Get_kinetics_ptr()->steps[i]; + // } + // else + // { + // kin_time_x += + // use.Get_kinetics_ptr()->steps[use.Get_kinetics_ptr()-> + // count_steps - 1]; + // } + // } + // } + // else if (use.Get_kinetics_ptr()->count_steps < 0) + // { + // if (reaction_step > -use.Get_kinetics_ptr()->count_steps) + // { + // kin_time_x = use.Get_kinetics_ptr()->steps[0]; + // } + // else + // { + // kin_time_x = + // reaction_step * use.Get_kinetics_ptr()->steps[0] / + // ((LDBLE) (-use.Get_kinetics_ptr()->count_steps)); + // } + // } + // } + */ + if (punch.time == TRUE) + { + LDBLE reaction_time = kin_time_x; + if (state == REACTION && incremental_reactions == TRUE + && use.Get_kinetics_ptr() != NULL) + { + if (use.Get_kinetics_ptr()->count_steps > 0) + { + reaction_time = 0.0; + for (i = 0; i < reaction_step; i++) + { + if (i < use.Get_kinetics_ptr()->count_steps) + { + reaction_time += use.Get_kinetics_ptr()->steps[i]; + } + else + { + reaction_time += + use.Get_kinetics_ptr()->steps[use.Get_kinetics_ptr()->count_steps - 1]; + } + } + } + else if (use.Get_kinetics_ptr()->count_steps < 0) + { + if (reaction_step > -use.Get_kinetics_ptr()->count_steps) + { + reaction_time = use.Get_kinetics_ptr()->steps[0]; + } + else + { + reaction_time = + reaction_step * use.Get_kinetics_ptr()->steps[0] / + ((LDBLE) (-use.Get_kinetics_ptr()->count_steps)); + } + } + } + if (state == REACTION) + { + fpunchf(PHAST_NULL("time"), gformat, (double) reaction_time); + } + else if (state == TRANSPORT || state == PHAST) + { + fpunchf(PHAST_NULL("time"), gformat, + (double) (initial_total_time + rate_sim_time)); + } + else if (state == ADVECTION) + { + if (advection_kin_time_defined == TRUE) + { + fpunchf(PHAST_NULL("time"), gformat, + (double) (initial_total_time + rate_sim_time)); + } + else + { + fpunchf(PHAST_NULL("time"), dformat, advection_step); + } + } + else + { + fpunchf(PHAST_NULL("time"), dformat, -99); + } + } + +/* + * reaction or transport step + */ + if (punch.step == TRUE) + { + if (state == REACTION) + { + fpunchf(PHAST_NULL("step"), dformat, reaction_step); + } + else if (state == ADVECTION) + { + fpunchf(PHAST_NULL("step"), dformat, advection_step); + } + else if (state == TRANSPORT) + { + fpunchf(PHAST_NULL("step"), dformat, transport_step); + } + else + { + fpunchf(PHAST_NULL("step"), dformat, -99); + } + } + if (punch.ph == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("pH", "%12g\t", (double) (-s_hplus->la)); + } + else + { + fpunchf("pH", "%20.12e\t", (double) (-s_hplus->la)); + } + } + if (punch.pe == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("pe", "%12g\t", (double) (-s_eminus->la)); + } + else + { + fpunchf("pe", "%20.12e\t", (double) (-s_eminus->la)); + } + } + if (punch.rxn == TRUE) + { + if (state >= REACTION && use.Get_reaction_in() == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("reaction", "%12.4e\t", (double) step_x); + } + else + { + fpunchf("reaction", "%20.12e\t", (double) step_x); + } + } + else + { + if (punch.high_precision == FALSE) + { + fpunchf("reaction", "%12d\t", -99); + } + else + { + fpunchf("reaction", "%20d\t", -99); + } + } + } + if (punch.temp == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("temp(C)", "%12.3f\t", (double) tc_x); + } + else + { + fpunchf("temp(C)", "%20.12e\t", (double) tc_x); + } + } + if (punch.alk == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("Alk(eq/kgw)", "%12g\t", + (double) (total_alkalinity / mass_water_aq_x)); + } + else + { + fpunchf("Alk(eq/kgw)", "%20.12e\t", + (double) (total_alkalinity / mass_water_aq_x)); + } + } + if (punch.mu == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("mu", "%12g\t", (double) mu_x); + } + else + { + fpunchf("mu", "%20.12e\t", (double) mu_x); + } + } + if (punch.water == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("mass_H2O", "%12g\t", (double) mass_water_aq_x); + } + else + { + fpunchf("mass_H2O", "%20.12e\t", (double) mass_water_aq_x); + } + } + if (punch.charge_balance == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("charge(eq)", "%12g\t", (double) cb_x); + } + else + { + fpunchf("charge(eq)", "%20.12e\t", (double) cb_x); + } + } + if (punch.percent_error == TRUE) + { + if (punch.high_precision == FALSE) + { + fpunchf("pct_err", "%12g\t", + (double) (100 * cb_x / total_ions_x)); + } + else + { + fpunchf("pct_err", "%20.12e\t", + (double) (100 * cb_x / total_ions_x)); + } + } + + return (OK); +} + +#undef PHAST_NULL +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_saturation_indices(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints saturation indices of selected phases + */ + int i; + LDBLE si, iap; + struct rxn_token *rxn_ptr; + + for (i = 0; i < punch.count_si; i++) + { + if (punch.si[i].phase == NULL || punch.si[i].phase->in == FALSE) + { + si = -999.999; + } + else + { +/* + * Print saturation index + */ + iap = 0.0; + for (rxn_ptr = punch.si[i].phase->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + iap += rxn_ptr->s->la * rxn_ptr->coef; + } + si = -punch.si[i].phase->lk + iap; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("si_%s", punch.si[i].name), "%12.4f\t", (double) si); + } + else + { + fpunchf(sformatf("si_%s", punch.si[i].name), "%20.12e\t", (double) si); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + int i, j; + struct kinetics *kinetics_ptr; + LDBLE moles, delta_moles; + + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + } + else + { + kinetics_ptr = kinetics_bsearch(-2, &i); + } + } + for (i = 0; i < punch.count_kinetics; i++) + { + moles = 0.0; + delta_moles = 0.0; + if (kinetics_ptr != NULL) + { + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + if (strcmp_nocase + (punch.kinetics[i].name, + kinetics_ptr->comps[j].rate_name) == 0) + { + if (state != TRANSPORT && state != PHAST) + { + moles = kinetics_ptr->comps[j].m; + delta_moles = -kinetics_ptr->comps[j].moles; + } + else + { + moles = kinetics_ptr->comps[j].m; + delta_moles = + kinetics_ptr->comps[j].m - + kinetics_ptr->comps[j].initial_moles; + } + break; + } + } + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t", + (double) moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t", + (double) -delta_moles); + } + else + { + fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t", + (double) moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t", + (double) -delta_moles); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_user_punch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Punch with user defined BASIC print routine + */ + char l_command[] = "run"; + + n_user_punch_index = 0; + if (punch.user_punch == FALSE) + return (OK); + if (user_punch->commands == NULL) + return (OK); + if (user_punch->new_def == TRUE) + { + if (basic_compile + (user_punch->commands, &user_punch->linebase, + &user_punch->varbase, &user_punch->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PUNCH.", STOP); + } + user_punch->new_def = FALSE; + } + if (basic_run + (l_command, user_punch->linebase, user_punch->varbase, + user_punch->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PUNCH.", STOP); + } + return (OK); +} + +#if defined PHREEQ98 +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_user_graph(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Graph with user defined BASIC print routine + */ + char command[] = "run"; + + colnr = 0; +/* if (pr.user_graph == FALSE || pr.all == FALSE) return(OK); */ +/* if (punch.user_punch == FALSE) return(OK); */ +/* if (punch.in == FALSE) return(OK); */ + if (user_graph->commands == NULL) + return (OK); + if (((state == INITIAL_SOLUTION) || (state == INITIAL_EXCHANGE) + || (state == INITIAL_SURFACE) || (state == INITIAL_GAS_PHASE)) + && (graph_initial_solutions == FALSE)) + return (OK); + if (FirstCallToUSER_GRAPH) + AddSeries = TRUE; + if (state == REACTION) + { + /*if (reaction_step == 1) AddSeries = TRUE; + else AddSeries = FALSE; */ + if (reaction_step == 1 && !connect_simulations) + AddSeries = TRUE; + if (reaction_step > 1) + AddSeries = FALSE; + } + if (state == ADVECTION) + { + if (advection_step == 0 && graph_initial_solutions == FALSE) + return (OK); + if (((chart_type == 1) && (advection_step == punch_ad_modulus)) || + ((chart_type == 0) && (advection_step != prev_advection_step))) + AddSeries = TRUE; + else + AddSeries = FALSE; + } + if (state == TRANSPORT) + { + if (transport_step == 0 && graph_initial_solutions == FALSE) + return (OK); + if (((chart_type == 1) && (transport_step == punch_modulus)) || + ((chart_type == 0) && (transport_step != prev_transport_step))) + AddSeries = TRUE; + else + AddSeries = FALSE; + } + if (user_graph->new_def == TRUE) + { + if (basic_compile + (user_graph->commands, &user_graph->linebase, + &user_graph->varbase, &user_graph->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + user_graph->new_def = FALSE; + } + if (basic_run + (command, user_graph->linebase, user_graph->varbase, + user_graph->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + if (state == ADVECTION) + prev_advection_step = advection_step; + if (state == TRANSPORT) + prev_transport_step = transport_step; + /*if (state == REACTION) prev_reaction_step = reaction_step; */ + + if (FirstCallToUSER_GRAPH) + { + start_chart(0); + } + + FirstCallToUSER_GRAPH = FALSE; + + return (OK); +} +#endif +#if defined(MULTICHART) +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_user_graph(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Graph with user defined BASIC print routine + */ + char command[] = "run"; + ChartObject *chart = chart_handler.Get_current_chart(); + if (chart == NULL) return OK; + + chart->Set_AddSeries(false); + + if (chart->Get_rate_command_list().size() == 0) + return (OK); + + // Skip initial calculations if initial_solutions == false + if (((state == INITIAL_SOLUTION) || (state == INITIAL_EXCHANGE) + || (state == INITIAL_SURFACE) || (state == INITIAL_GAS_PHASE)) + && (chart->Get_graph_initial_solutions() == false)) + return (OK); + + if (state == REACTION) + { + /*if (reaction_step == 1) AddSeries = TRUE; + else AddSeries = FALSE; */ + if (reaction_step == 1) + chart->Set_AddSeries(true); + if (reaction_step > 1) + chart->Set_AddSeries(false); + } + + if (state == ADVECTION) + { + + if (advection_step == 0 && chart->Get_graph_initial_solutions() == false) + return (OK); + if ( + ((chart->Get_chart_type() == 1) && (advection_step == punch_ad_modulus)) || + ((chart->Get_chart_type() == 0) && (advection_step != chart->Get_prev_advection_step())) + ) + { + chart->Set_AddSeries(true); + } + else + chart->Set_AddSeries(false); + } + if (state == TRANSPORT) + { + if (transport_step == 0 && chart->Get_graph_initial_solutions() == FALSE) + return (OK); + if ( + ((chart->Get_chart_type() == 1) && (transport_step == punch_modulus)) || + ((chart->Get_chart_type() == 0) && (transport_step != chart->Get_prev_transport_step())) + ) + { + chart->Set_AddSeries(true); + } + else + { + chart->Set_AddSeries(false); + } + } + + // From cmdplot_xy merged into transport and advection above + + // From plotXY + if (chart->Get_FirstCallToUSER_GRAPH()) + chart->Set_prev_sim_no(simulation); + else + { + if (simulation != chart->Get_prev_sim_no()) + { + chart->Set_AddSeries(true); + } + } + chart->Set_prev_sim_no(simulation); + if (chart->Get_AddSeries() && !chart->Get_connect_simulations()) + { + chart->Add_new_series(); + } + + chart->Set_colnr(chart->Get_ColumnOffset()); + chart->Initialize_graph_pts(); + if (chart->Get_rate_new_def()) + { + if (basic_compile + (chart->Get_user_graph()->commands, &chart->Get_user_graph()->linebase, + &chart->Get_user_graph()->varbase, &chart->Get_user_graph()->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + chart->Set_rate_new_def(false); + } + + // basic_run calculates points for all graph and plotxy curves + // colnr identifies the curve and is incremented as each Y/Y2 curve point is added + if (basic_run + (command, chart->Get_user_graph()->linebase, + chart->Get_user_graph()->varbase, chart->Get_user_graph()->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_GRAPH.", STOP); + } + chart->Finalize_graph_pts(); + + if (state == ADVECTION) + chart->Set_prev_advection_step(advection_step); + if (state == TRANSPORT) + chart->Set_prev_transport_step(transport_step); + + if (chart->Get_FirstCallToUSER_GRAPH()) + { + chart->start_chart(); + } + chart->Set_new_ug(false); + + chart->Set_FirstCallToUSER_GRAPH(false); + + return (OK); +} +#endif // MULTICHART + +//char * Phreeqc:: +//sformatf(const char *format, ...) +//{ +//#if defined(HDF5_CREATE) || defined SWIG_SHARED_OBJ +// static char l_scratch[240]; +// va_list args; +// +// va_start(args, format); +// if (vsprintf(l_scratch, format, args) > 239) +// { +// error_msg("buffer overwrite in sformatf", STOP); +// } +// va_end(args); +// return l_scratch; +//#else +// return NULL; +//#endif +//} + +//std::string Phreeqc:: +//sformatf(const char *format, ...) +//{ +// +// +// size_t max = 240; +// char * l_scratch = NULL; +// bool success = false; +// do +// { +// va_list args; +// va_start(args, format); +// l_scratch = (char *) PHRQ_realloc(l_scratch, max * sizeof(char)); +// success = (vsnprintf(l_scratch, max, format, args) > 0); +// va_end(args); +// max *= 2; +// } +// while (!success); +// +// std::string str(l_scratch); +// l_scratch = (char *) free_check_null(l_scratch); +// return str; +// +//} +char * Phreeqc:: +sformatf(const char *format, ...) +{ + + + bool success = false; + do + { + va_list args; + va_start(args, format); + int j = vsnprintf(sformatf_buffer, sformatf_buffer_size, format, args); + success = (j > 0 && j <= (int) sformatf_buffer_size); + va_end(args); + if (!success) + { + sformatf_buffer_size *= 2; + sformatf_buffer = (char *) PHRQ_realloc(sformatf_buffer, sformatf_buffer_size * sizeof(char)); + if (sformatf_buffer == NULL) malloc_error(); + } + } + while (!success); + + return sformatf_buffer; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_alkalinity(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints description of solution, uses array species_list for + * order of aqueous species. + */ + int i, j; + struct species_list *alk_list; + int count_alk_list; + LDBLE min; + + if (pr.alkalinity == FALSE || pr.all == FALSE) + return (OK); + print_centered("Distribution of alkalinity"); + alk_list = + (struct species_list *) + PHRQ_malloc((size_t) (count_s_x * sizeof(struct species_list))); + if (alk_list == NULL) + malloc_error(); + j = 0; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->alk == 0.0) + continue; + alk_list[j].master_s = s_hplus; + alk_list[j].s = s_x[i]; + alk_list[j].coef = s_x[i]->alk; + j++; + } + count_alk_list = j; + min = fabs(censor * total_alkalinity / mass_water_aq_x); + if (count_alk_list > 0) + { + output_msg(sformatf("\t%26s%11.3e\n\n", + "Total alkalinity (eq/kgw) = ", + (double) (total_alkalinity / mass_water_aq_x))); + output_msg(sformatf("\t%-15s%12s%12s%10s\n\n", "Species", + "Alkalinity", "Molality", "Alk/Mol")); + qsort(&alk_list[0], (size_t) count_alk_list, + (size_t) sizeof(struct species_list), species_list_compare_alk); + for (i = 0; i < count_alk_list; i++) + { + if (fabs + (alk_list[i].s->alk * (alk_list[i].s->moles) / + mass_water_aq_x) < min) + continue; + output_msg(sformatf("\t%-15s%12.3e%12.3e%10.2f\n", + alk_list[i].s->name, + (double) (alk_list[i].s->alk * + (alk_list[i].s->moles) / mass_water_aq_x), + (double) ((alk_list[i].s->moles) / mass_water_aq_x), + (double) (alk_list[i].s->alk))); + } + } + + output_msg(sformatf("\n")); + alk_list = (struct species_list *) free_check_null(alk_list); + return (OK); +} + diff --git a/rename_cpp/read.cpp b/rename_cpp/read.cpp new file mode 100644 index 00000000..9c37a3f7 --- /dev/null +++ b/rename_cpp/read.cpp @@ -0,0 +1,10732 @@ +#include +#include +#include + +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Pressure.h" +#include "Temperature.h" +#include "Parser.h" +#include "cxxMix.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_input(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l; + char *ptr; + char token[2 * MAX_LENGTH]; +#define LAST_C_KEYWORD 61 + + parse_error = 0; + input_error = 0; + next_keyword = Keywords::KEY_NONE; + count_warnings = 0; +/* + * Initialize keyword counters + */ + for (i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + { + keycount[i] = 0; + } +/* + * Initialize use and save pointers + */ + use.init(); + + save.solution = FALSE; + save.mix = FALSE; + save.reaction = FALSE; + save.kinetics = FALSE; + save.pp_assemblage = FALSE; + save.exchange = FALSE; + save.surface = FALSE; + save.gas_phase = FALSE; + save.ss_assemblage = FALSE; + title_x = (char *) free_check_null(title_x); + + while ((i = check_line("Subroutine Read", FALSE, TRUE, TRUE, TRUE)) != KEYWORD) + { + /* empty, eof, keyword, print */ + + if (i == EOF) + return (EOF); + error_string = sformatf( + "Unknown input, no keyword has been specified."); + warning_msg(error_string); + } + + for (;;) + { + if (next_keyword > 0) + { + if (next_keyword != Keywords::KEY_DATABASE && !reading_database()) + { + first_read_input = FALSE; + } + } + // mark keyword read + if (next_keyword > 0 && next_keyword < Keywords::KEY_COUNT_KEYWORDS) + { + keycount[next_keyword]++; + } + switch (next_keyword) + { + case Keywords::KEY_NONE: /* Have not read line with keyword */ + error_string = sformatf( "Unknown input, no keyword has been specified."); + warning_msg(error_string); + while ((j = check_line("No keyword", FALSE, TRUE, TRUE, TRUE)) != KEYWORD && j != EOF) + { + warning_msg(error_string); + } + break; + case Keywords::KEY_END: + goto END_OF_SIMULATION_INPUT; + case Keywords::KEY_SOLUTION_SPECIES: /* Read aqueous model */ + read_species(); + break; + case Keywords::KEY_SOLUTION_MASTER_SPECIES: /* Read master species */ + read_master_species(); + break; + case Keywords::KEY_SOLUTION: /* Read solution data */ + read_solution(); + solution_sort(); + break; + case Keywords::KEY_PHASES: + read_phases(); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: + //read_pure_phases(); + read_pp_assemblage(); + break; + case Keywords::KEY_REACTION: + read_reaction(); + break; + case Keywords::KEY_MIX: + read_mix(); + break; + case Keywords::KEY_USE: + read_use(); + break; + case Keywords::KEY_SAVE: + read_save(); + break; + case Keywords::KEY_EXCHANGE_SPECIES: + read_exchange_species(); + break; + case Keywords::KEY_EXCHANGE_MASTER_SPECIES: + read_exchange_master_species(); + break; + case Keywords::KEY_EXCHANGE: + read_exchange(); + break; + case Keywords::KEY_SURFACE_SPECIES: + read_surface_species(); + break; + case Keywords::KEY_SURFACE_MASTER_SPECIES: + read_surface_master_species(); + break; + case Keywords::KEY_SURFACE: + read_surf(); + break; + case Keywords::KEY_REACTION_TEMPERATURE: + read_temperature(); + break; + case Keywords::KEY_INVERSE_MODELING: + read_inverse(); + break; + case Keywords::KEY_GAS_PHASE: + read_gas_phase(); + break; + case Keywords::KEY_TRANSPORT: + read_transport(); + break; + case Keywords::KEY_KNOBS: + read_debug(); + break; + case Keywords::KEY_SELECTED_OUTPUT: + read_selected_output(); + break; + case Keywords::KEY_PRINT: + read_print(); + break; + case Keywords::KEY_TITLE: + read_title(); + break; + case Keywords::KEY_ADVECTION: + read_advection(); + break; + case Keywords::KEY_KINETICS: + read_kinetics(); + break; + case Keywords::KEY_INCREMENTAL_REACTIONS: + read_incremental_reactions(); + break; + case Keywords::KEY_RATES: + read_rates(); + break; + case Keywords::KEY_SOLUTION_SPREAD: + read_solution_spread(); + break; + case Keywords::KEY_USER_PRINT: + read_user_print(); + break; + case Keywords::KEY_USER_PUNCH: + read_user_punch(); + break; + case Keywords::KEY_SOLID_SOLUTIONS: + read_solid_solutions(); + break; + case Keywords::KEY_USER_GRAPH: +#if defined PHREEQ98 + read_user_graph(); +#elif defined MULTICHART + read_user_graph_handler(); +# else + for (;;) + { + j = check_line("Reading user_graph", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD) + { + break; + } + } +#endif + break; + case Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS: + read_llnl_aqueous_model_parameters(); + break; + case Keywords::KEY_DATABASE: + if (reading_database()) + { + /* warning_msg("DATABASE is ignored in the database file."); */ + } + else if (first_read_input == FALSE) + { + error_msg("DATABASE must be the first keyword in the input file.", CONTINUE); + input_error++; + } + else + { + ptr = line; + copy_token(token, &ptr, &l); +#if defined(SWIG_SHARED_OBJ) + warning_msg("DATABASE keyword is ignored by IPhreeqc."); +#else + user_database = string_duplicate(ptr); + if (string_trim(user_database) == EMPTY) + { + error_msg("DATABASE file name is missing.", CONTINUE); + input_error++; + user_database = (char *) free_check_null(user_database); + } + first_read_input = FALSE; +#endif + } + j = check_line("Reading after DATABASE", FALSE, TRUE, TRUE, TRUE); + break; + case Keywords::KEY_NAMED_EXPRESSIONS: + read_named_logk(); + break; + case Keywords::KEY_ISOTOPES: + read_isotopes(); + break; + case Keywords::KEY_CALCULATE_VALUES: + read_calculate_values(); + break; + case Keywords::KEY_ISOTOPE_RATIOS: + read_isotope_ratios(); + break; + case Keywords::KEY_ISOTOPE_ALPHAS: + read_isotope_alphas(); + break; + case Keywords::KEY_COPY: + read_copy(); + break; + case Keywords::KEY_PITZER: + read_pitzer(); + break; + case Keywords::KEY_SIT: + read_sit(); + break; + case Keywords::KEY_SOLUTION_RAW: + read_solution_raw(); + break; + case Keywords::KEY_EXCHANGE_RAW: + //read_exchange_raw(); + Utilities::Rxn_read_raw(Rxn_exchange_map, this); + break; + case Keywords::KEY_SURFACE_RAW: + read_surface_raw(); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: + //read_equilibrium_phases_raw(); + Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, this); + break; + case Keywords::KEY_KINETICS_RAW: + read_kinetics_raw(); + break; + case Keywords::KEY_SOLID_SOLUTIONS_RAW: + read_solid_solutions_raw(); + break; + case Keywords::KEY_GAS_PHASE_RAW: + //read_gas_phase_raw(); + Utilities::Rxn_read_raw(Rxn_gas_phase_map, this); + break; + case Keywords::KEY_REACTION_RAW: + //read_reaction_raw(); + Utilities::Rxn_read_raw(Rxn_reaction_map, this); + break; + case Keywords::KEY_MIX_RAW: + //read_mix_raw(); + Utilities::Rxn_read_raw(Rxn_mix_map, this); + break; + case Keywords::KEY_REACTION_TEMPERATURE_RAW: + //read_temperature_raw(); + Utilities::Rxn_read_raw(Rxn_temperature_map, this); + break; + case Keywords::KEY_DUMP: + read_dump(); + break; + case Keywords::KEY_SOLUTION_MODIFY: + read_solution_modify(); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY: + //read_equilibrium_phases_modify(); + Utilities::Rxn_read_modify(Rxn_pp_assemblage_map, this); + break; + case Keywords::KEY_EXCHANGE_MODIFY: + //read_exchange_modify(); + Utilities::Rxn_read_modify(Rxn_exchange_map, this); + break; + case Keywords::KEY_SURFACE_MODIFY: + read_surface_modify(); + break; + case Keywords::KEY_SOLID_SOLUTIONS_MODIFY: + read_solid_solutions_modify(); + break; + case Keywords::KEY_GAS_PHASE_MODIFY: + //read_gas_phase_modify(); + Utilities::Rxn_read_modify(Rxn_gas_phase_map, this); + break; + case Keywords::KEY_KINETICS_MODIFY: + read_kinetics_modify(); + break; + case Keywords::KEY_DELETE: + read_delete(); + break; + case Keywords::KEY_RUN_CELLS: + read_run_cells(); + break; + case Keywords::KEY_REACTION_MODIFY: + //read_reaction_modify(); + Utilities::Rxn_read_modify(Rxn_reaction_map, this); + break; + //case LAST_C_KEYWORD + 22: //reaction_temperature_modify + // keyword[LAST_C_KEYWORD + 22].keycount++; + // read_reaction_temperature_modify(); + // break; + case Keywords::KEY_SOLID_SOLUTION_MODIFY: + read_solid_solutions_modify(); + break; + case Keywords::KEY_REACTION_PRESSURE: + read_reaction_pressure(); + break; + case Keywords::KEY_REACTION_PRESSURE_RAW: + //read_reaction_pressure_raw(); + Utilities::Rxn_read_raw(Rxn_pressure_map, this); + break; +#ifdef SKIP + //case Keywords::KEY_REACTION_PRESSURE_MODIFY: + // read_reaction_pressure_modify(); + // break; +#endif + default: + error_msg("Error in keyword switch", STOP); + break; + } + } + END_OF_SIMULATION_INPUT: + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_conc(int n, int count_mass_balance, char *str) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + int alk; + int count_redox_states; + + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; +/* + * Set defaults + */ + /* + solution[n]->totals[count_mass_balance].equation_name = NULL; + solution[n]->totals[count_mass_balance].phase = NULL; + solution[n]->totals[count_mass_balance].phase_si = 0.0; + solution[n]->totals[count_mass_balance].units=NULL; + solution[n]->totals[count_mass_balance].n_pe=-1; + solution[n]->totals[count_mass_balance].as=NULL; + solution[n]->totals[count_mass_balance].gfw= 0.0; + */ + conc_init(&(solution[n]->totals[count_mass_balance])); + +/* + * Remove space between "kg" and "solution" or "water" in units + */ + replace("Kg", "kg", str); + replace("KG", "kg", str); + while (replace("kg ", "kg", str) == TRUE); + ptr = str; +/* + * Read master species list for mass balance equation + */ + token1[0] = '\0'; + count_redox_states = 0; + while (((j = copy_token(token, &ptr, &l)) == UPPER) || + (token[0] == '[') || + (strcmp_nocase_arg1(token, "ph") == 0) || + (strcmp_nocase_arg1(token, "pe") == 0)) + { + count_redox_states++; + replace("(+", "(", token); + if (count_redox_states > 1) + strcat(token1, " "); + strcat(token1, token); + } + if (count_redox_states == 0) + { + input_error++; + error_msg + ("No element or master species given for concentration input.", + CONTINUE); + return (ERROR); + } + solution[n]->totals[count_mass_balance].description = + string_hsave(token1); +/* + * Determine if reading alkalinity, allow equivalents for units + */ + str_tolower(token1); + if (strstr(token1, "alk") == token1) + { + alk = TRUE; + } + else + { + alk = FALSE; + } +/* + * Read concentration + */ + + j = sscanf(token, SCANFORMAT, + &(solution[n]->totals[count_mass_balance].input_conc)); + if (j == 0) + { + error_string = sformatf( + "Concentration data error for %s in solution input.", token1); + error_msg(error_string, CONTINUE); + return (ERROR); + } + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); +/* + * Read optional data + */ + strcpy(token1, token); +/* + * Check for units info + */ + if (check_units(token1, alk, FALSE, solution[n]->units, FALSE) == OK) + { + if (check_units(token1, alk, FALSE, solution[n]->units, TRUE) == OK) + { + solution[n]->totals[count_mass_balance].units = + string_hsave(token1); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); + } + else + { + return (ERROR); + } + } +/* + * Check for "as" followed by formula to be used for gfw + */ + strcpy(token1, token); + str_tolower(token1); + if (strcmp(token1, "as") == 0) + { + copy_token(token, &ptr, &l); + solution[n]->totals[count_mass_balance].as = string_hsave(token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); +/* + * Check for "gfw" followed by gram formula weight + */ + } + else if (strcmp(token1, "gfw") == 0 || strcmp(token1, "gfm") == 0) + { + if (copy_token(token, &ptr, &l) != DIGIT) + { + error_msg("Expecting gram formula weight.", CONTINUE); + return (ERROR); + } + else + { + sscanf(token, SCANFORMAT, + &(solution[n]->totals[count_mass_balance].gfw)); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); + } + } +/* + * Check for redox couple for pe + */ + if (strcmp_nocase_arg1(token, "pe") == 0) + { + solution[n]->totals[count_mass_balance].n_pe = + pe_data_store(&(solution[n]->pe), token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); + } + else if (strstr(token, "/") != NULL) + { + if (parse_couple(token) == OK) + { + solution[n]->totals[count_mass_balance].n_pe = + pe_data_store(&(solution[n]->pe), token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); + } + else + { + return (ERROR); + } + } +/* + * Must have phase + */ + solution[n]->totals[count_mass_balance].equation_name = + string_hsave(token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + return (OK); +/* + * Check for saturation index + */ + j = sscanf(token, SCANFORMAT, + &(solution[n]->totals[count_mass_balance].phase_si)); + if (j != 1) + { + error_msg("Expected saturation index.", CONTINUE); + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_exchange_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for exchange species, parse equations + */ + int i; + int association; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; + + struct species *s_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + LDBLE exchange_coef; + LDBLE offset; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "mb", /* 2 */ + "mass_balance", /* 3 */ + "log_k", /* 4 */ + "logk", /* 5 */ + "delta_h", /* 6 */ + "deltah", /* 7 */ + "analytical_expression", /* 8 */ + "a_e", /* 9 */ + "ae", /* 10 */ + "mole_balance", /* 11 */ + "gamma", /* 12 */ + "davies", /* 13 */ + "offset", /* 14 */ + "llnl_gamma", /* 15 */ + "add_logk", /* 16 */ + "add_log_k", /* 17 */ + "add_constant", /* 18 */ + "delta_v", /* 19 */ + "deltav", /* 20 */ + "vm" /* 21, molar volume, must replace delta_v */ + }; + int count_opt_list = 22; + + association = TRUE; + s_ptr = NULL; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EXCHANGE_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* mb */ + case 3: /* mass_balance */ + case 11: /* mole_balance */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count = 0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = + (struct elt_list *) free_check_null(s_ptr->next_secondary); + s_ptr->next_secondary = elt_list_save(); +/* debug + for (i = 0; i < count_elts; i++) { + output_msg(sformatf("%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef)); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 4: /* log_k */ + case 5: /* logk */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 6: /* delta_h */ + case 7: /* deltah */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], + &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 8: /* analytical_expression */ + case 9: /* a_e */ + case 10: /* ae */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[T_A1])); + opt_save = OPTION_DEFAULT; + break; + case 12: /* gamma */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 2; + s_ptr->a_f = 0; + i = sscanf(next_char, SCANFORMAT SCANFORMAT SCANFORMAT, &s_ptr->dha, + &s_ptr->dhb, &s_ptr->a_f); + if (i < 2) + { + error_string = sformatf( "Expecting 2 activity-" + "coefficient parameters, a and b."); + warning_msg(error_string); + } + if (s_ptr->dha == 0 && s_ptr->dhb == 0) + { + s_ptr->dhb = 99.9; + s_ptr->exch_gflag = 1; + } + opt_save = OPTION_DEFAULT; + break; + case 13: /* davies */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 1; + s_ptr->dha = 0; + s_ptr->dhb = 99.9; + opt_save = OPTION_DEFAULT; + break; + case 14: /* offset */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (sscanf(next_char, SCANFORMAT, &offset) != 1) + { + error_msg("No offset for log K given", STOP); + } + s_ptr->logk[0] += offset; + opt_save = OPTION_DEFAULT; + break; + case 15: /* llnl_gamma */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->exch_gflag = 7; /* llnl D-H */ + i = sscanf(next_char, SCANFORMAT, &s_ptr->dha); + if (i < 1) + { + error_string = sformatf( + "Expecting activity-coefficient parameter, a."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 16: /* add_logk */ + case 17: /* add_log_k */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) + { + input_error++; + error_string = sformatf( + "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 18: /* add_constant */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + input_error++; + error_string = sformatf( + "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = + string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 19: /* delta_v */ + case 20: /* deltav */ + case 21: /* vm, molar volume */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_v_only(next_char, &s_ptr->logk[vm0], + &s_ptr->original_deltav_units); + opt_save = OPTION_DEFAULT; + break; + + case OPTION_DEFAULT: +/* + * Get exchange species information and parse equation + */ + s_ptr = NULL; + if (parse_eq(line, &next_elt, association) == ERROR) + { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = + s_store(trxn.token[0].name, trxn.token[0].z, TRUE); + for (i = 1; i < count_trxn; i++) + { + trxn.token[i].s = + s_store(trxn.token[i].name, trxn.token[i].z, FALSE); + } +/* + * Save element list and carbon, hydrogen, and oxygen in species + */ + trxn.token[0].s->next_elt = next_elt; + for (; next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, "C") == 0) + { + trxn.token[0].s->carbon = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "H") == 0) + { + trxn.token[0].s->h = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "O") == 0) + { + trxn.token[0].s->o = next_elt->coef; + } + } +/* + * Find valence of cation from coefficients of reaction components + * Changed to be coefficient of exchanger + */ + exchange_coef = 0.0; + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->type == EX) + { + exchange_coef = trxn.token[i].coef; + } + } + trxn.token[0].s->equiv = exchange_coef; +/* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc(count_trxn + 1); +/* + * Copy reaction to reaction for species + */ + token_ptr = trxn.token[0].s->rxn->token; + for (i = 0; i < count_trxn; i++) + { + token_ptr[i].s = trxn.token[i].s; + token_ptr[i].coef = trxn.token[i].coef; + } + token_ptr[i].s = NULL; +/* + * Set type for species + */ + trxn.token[0].s->type = EX; + s_ptr = trxn.token[0].s; +/* + * Set gamma data + */ + s_ptr->gflag = 4; + s_ptr->exch_gflag = 3; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + opt_save = OPTION_DEFAULT; +/* + * Save as a phase for inverse modeling only + */ + phase_ptr = phase_store(s_ptr->name); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( "Copying exchange to phases."); + error_msg(error_string, CONTINUE); + } + phase_ptr->formula = s_ptr->name; + phase_ptr->check_equation = FALSE; + phase_ptr->type = EX; + phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt); + phase_ptr->rxn = rxn_dup(s_ptr->rxn); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_exchange(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads exchange data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, l; + int n_user, n_user_end; + LDBLE conc; + char *ptr; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + //struct exchange *exchange_ptr; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "equilibrate", /* 0 */ + "equil", /* 1 */ + "pitzer_exchange_gammas", /* 2 */ + "exchange_gammas", /* 3 */ + "gammas", /* 4 */ + "equilibrium" /* 5 */ + }; + int count_opt_list = 6; +/* + * kin_exch is for exchangers, related to kinetically reacting minerals + * they are defined if "sites" is followed by mineral name: + * Z Manganite ('equi' or 'kine') 0.25 + * ^Name ^equi or kinetic mineral ^switch ^prop.factor + */ +/* + * Read exchange number and description + */ + + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); +/* + * Default values + n_user, description + */ + cxxExchange temp_exchange; + cxxExchComp *comp = NULL; + temp_exchange.Set_new_def(true); + temp_exchange.Set_n_user(n_user); + temp_exchange.Set_n_user_end(n_user_end); + temp_exchange.Set_description(description); + free_check_null(description); +/* + * Set use data + */ + if (use.Get_exchange_in() == FALSE) + { + use.Set_exchange_in(true); + use.Set_n_exchange_user(n_user); + } +/* + * Read exchange data + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EXCHANGE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* equilibrate */ + case 1: /* equil */ + case 5: /* equilibrium */ + /* + * Read solution to equilibrate with + */ + for (;;) + { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) + { + int n_solution; + sscanf(token, "%d", &n_solution); + temp_exchange.Set_n_solution(n_solution); + temp_exchange.Set_new_def(true); + temp_exchange.Set_solution_equilibria(true); + break; + } + if (i == EMPTY) + { + error_msg + ("Expected a solution number with which to equilibrate exchanger.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case 2: /* pitzer_exchange_gammas */ + case 3: /* exchange_gammas */ + case 4: /* gammas */ + temp_exchange.Set_pitzer_exchange_gammas( + get_true_false(next_char, TRUE) == TRUE); + break; + case OPTION_DEFAULT: + ptr = line; + i = copy_token(token, &ptr, &l); + /* + * Species formula is stored in token + */ + if (i != UPPER && token[0] != '[') + { /* maybe a bit more clear? */ + error_string = sformatf( + "Expected exchanger name to begin with a capital letter, but found:\n %s", + line_save); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + delete comp; + comp = new cxxExchComp; + comp->Set_formula(token); + //exchange[n].comps[count_comps].formula = string_hsave(token); + prev_next_char = ptr; + i = copy_token(token1, &ptr, &l); + if (i == DIGIT) + { + /* + * Read exchange concentration + */ + + /* exchanger conc. is read directly .. */ + if (sscanf(token1, SCANFORMAT, &conc) < 1) + { + error_string = sformatf( + "Expected concentration of exchanger, but found:\n %s", + line_save); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + prev_next_char = ptr; + j = copy_token(token1, &ptr, &l); + if (j == UPPER || j == LOWER) + { + comp->Set_rate_name(token1); + if (copy_token(token1, &ptr, &l) != DIGIT) + { + error_string = sformatf( + "Expected a coefficient to relate exchange to kinetic reaction, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + LDBLE p; + sscanf(token1, SCANFORMAT, &p); + comp->Set_phase_proportion(p); + } + /* + * Read equilibrium phase name or kinetics rate name + */ + } + else if (i != EMPTY) + { + + /* exchanger conc. is related to mineral or kinetics */ + comp->Set_phase_name(token1); + prev_next_char = ptr; + j = copy_token(token1, &ptr, &l); + if (j != DIGIT) + { + if (token1[0] == 'K' || token1[0] == 'k') + { + comp->Set_rate_name(comp->Get_phase_name().c_str()); + comp->Set_phase_name(""); + } + else if (token1[0] != 'E' && token1[0] != 'e') + { + error_string = sformatf( + "Character string expected to be 'equilibrium_phase' or 'kinetics'\n to relate exchange to mineral or kinetic reaction, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + prev_next_char = ptr; + j = copy_token(token1, &ptr, &l); + } + + + if (j != DIGIT) + { + error_string = sformatf( + "Expected a coefficient to relate exchanger to mineral or kinetic reaction, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + LDBLE p; + sscanf(token1, SCANFORMAT, &p); + comp->Set_phase_proportion(p); + /* real conc must be defined in tidy_model */ + conc = 1.0; + } + else + { + error_msg + ("Expected concentration of exchanger, mineral name, or kinetic reaction name.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + /* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + ptr = token; + get_elts_in_species(&ptr, conc); + /* + * save formula for adjusting number of exchange sites + */ + ptr = token; + LDBLE z; + get_token(&ptr, token1, &z, &l); + comp->Set_formula_z(z); + comp->Set_formula_totals(elt_list_NameDouble()); + /* + * Save elt_list + */ + comp->Set_moles(conc); + comp->Set_totals(elt_list_NameDouble()); + comp->Set_charge_balance(0.0); + temp_exchange.Get_exchComps()[comp->Get_formula()] = *comp; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + Rxn_exchange_map[n_user] = temp_exchange; + + //if (n_user_end > n_user) + //{ + // for (int i = n_user + 1; i <= n_user_end; i++) + // { + // Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); + // } + //} + delete comp; + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_exchange_master_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species data from data file or input file + */ + int j, l; + char *ptr, *ptr1; + LDBLE l_z; + struct element *elts_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + for (;;) + { + j = check_line("Exchange species equation", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD) + { + break; + } +/* + * Get element name with valence, allocate space, store + */ + ptr = line; +/* + * Get element name and save pointer to character string + */ + if (copy_token(token, &ptr, &l) != UPPER && token[0] != '[') + { + parse_error++; + error_msg("Reading element for master species.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + /* + if (token[0] == '[') { + ptr1 = token; + get_elt(&ptr, element, &l); + strcpy(token, element); + } + */ + replace("(+", "(", token); +/* + * Delete master if it exists + */ + master_delete(token); +/* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master >= max_master) + { + space((void **) ((void *) &master), count_master + 1, + &max_master, sizeof(struct master *)); + } + master[count_master] = master_alloc(); +/* + * Set type to EX + */ + master[count_master]->type = EX; +/* + * Save element name + */ + master[count_master]->elt = element_store(token); +/* + * Save pointer to species data for master species + */ + if ((copy_token(token, &ptr, &l) != UPPER) && + token[0] != '[' && (strcmp_nocase_arg1(token, "e-") != 0)) + { + parse_error++; + error_msg("Reading master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + s_ptr = s_search(token); + if (s_ptr != NULL) + { + master[count_master]->s = s_ptr; + } + else + { + ptr1 = token; + get_token(&ptr1, token1, &l_z, &l); + master[count_master]->s = s_store(token1, l_z, FALSE); + } +/* + * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES + */ + master[count_master]->primary = TRUE; + if (strcmp(master[count_master]->elt->name, "E") != 0) + { + elts_ptr = element_store(master[count_master]->elt->name); + elts_ptr->gfw = 0.0; + } + + count_master++; + if (count_master >= max_master) + { + space((void **) ((void *) &master), count_master, &max_master, + sizeof(struct master *)); + } + } + return (j); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads gas phase data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, l; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + //struct gas_phase *gas_phase_ptr; + cxxGasPhase temp_gas_phase; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "pressure", /* 0 */ + "volume", /* 1 */ + "temp", /* 2 */ + "temperature", /* 3 */ + "fixed_pressure", /* 4 */ + "fixed_volume", /* 5 */ + "equilibrium", /* 6 */ + "equilibrate", /* 7 */ + "equil" /* 8 */ + }; + int count_opt_list = 9; +/* + * Read gas_phase number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + temp_gas_phase.Set_n_user(n_user); + temp_gas_phase.Set_n_user_end(n_user_end); + temp_gas_phase.Set_description(description); + temp_gas_phase.Set_new_def(true); + free_check_null(description); +/* + * Set use data to first read + */ + if (use.Get_gas_phase_in() == FALSE) + { + use.Set_gas_phase_in(true); + use.Set_n_gas_phase_user(n_user); + } +/* + * Read phases + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in GAS_PHASE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* pressure */ + sscanf(next_char, SCANFORMAT, &dummy); + temp_gas_phase.Set_total_p(dummy); + break; + case 1: /* Volume */ + sscanf(next_char, SCANFORMAT, &dummy); + temp_gas_phase.Set_volume(dummy); + break; + case 2: /* Temperature */ + case 3: + j = sscanf(next_char, SCANFORMAT, &dummy); + if (j == 1) + { + temp_gas_phase.Set_temperature(dummy + 273.15); + } + break; + case 4: /* fixed_pressure */ + temp_gas_phase.Set_type(cxxGasPhase::GP_PRESSURE); + break; + case 5: /* fixed_volume */ + temp_gas_phase.Set_type(cxxGasPhase::GP_VOLUME); + break; + case 6: /* equilibrate */ + case 7: /* equilibrium */ + case 8: /* equil */ +/* + * Read solution to equilibrate with + */ + for (;;) + { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) + { + sscanf(token, "%d", &l); + temp_gas_phase.Set_n_solution(l); + temp_gas_phase.Set_new_def(true); + temp_gas_phase.Set_solution_equilibria(true); + break; + } + if (i == EMPTY) + { + error_msg + ("Expected a solution number with which to equilibrate gas phase.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case OPTION_DEFAULT: + { + cxxGasComp temp_comp; + /* + * Read name + */ + ptr = line; + copy_token(token, &ptr, &l); + temp_comp.Set_phase_name(token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + { + temp_comp.Set_p_read(NAN); + temp_gas_phase.Get_gas_comps().push_back(temp_comp); + break; + } + /* + * Read initial partial pressure of gas + */ + + j = sscanf(token, SCANFORMAT, &dummy); + + if (j != 1) + { + error_msg("Expected partial pressure of gas in gas phase.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else + { + temp_comp.Set_p_read(dummy); + temp_gas_phase.Get_gas_comps().push_back(temp_comp); + } + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + + // sort components + std::map gc; + for (size_t i = 0; i < temp_gas_phase.Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(temp_gas_phase.Get_gas_comps()[i]); + gc[gc_ptr->Get_phase_name()] = *gc_ptr; + } + std::vector vgc; + std::map::iterator it = gc.begin(); + for ( ; it != gc.end(); it++) + { + vgc.push_back(it->second); + } + temp_gas_phase.Set_gas_comps(vgc); + + + Rxn_gas_phase_map[n_user] = temp_gas_phase; + + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_inverse(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads data for mass_balance calculations + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int n, j; + int n_user, n_user_end; + char *ptr; + char *description; + LDBLE range_max, inv_tol, water_uncertainty; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "solutions", /* 0 */ + "uncertainty", /* 1 */ + "uncertainties", /* 2 */ + "balances", /* 3 */ + "phase_data", /* 4 */ + "range", /* 5 */ + "minimal", /* 6 */ + "minimum", /* 7 */ + "balance", /* 8 */ + "bal", /* 9 */ + "sol", /* 10 */ + "phases", /* 11 */ + "ranges", /* 12 */ + "tolerance", /* 13 */ + "u_water", /* 14 */ + "uncertainty_water", /* 15 */ + "force", /* 16 */ + "force_solution", /* 17 */ + "force_solutions", /* 18 */ + "isotopes", /* 19 */ + "mineral_water", /* 20 */ + "phase", /* 21 */ + "multiple_precision", /* 22 */ + "mp_tolerance", /* 23 */ + "censor_mp", /* 24 */ + "lon_netpath", /* 25 */ + "pat_netpath" /* 26 */ + }; + int count_opt_list = 27; + + ptr = line; +/* + * Read solution number and description + */ + read_number_description(ptr, &n_user, &n_user_end, &description); +/* + * Malloc space for solution data + */ + if (inverse_search(n_user, &n) != NULL) + { + inverse_delete(n); + } + inverse_alloc(); + n = count_inverse - 1; +/* + * Initialize structure and use + */ + inverse[n].new_def = TRUE; + inverse[n].n_user = n_user; + inverse[n].range = FALSE; + inverse[n].range_max = 1000.; + inverse[n].tolerance = 1e-10; + inverse[n].minimal = FALSE; + inverse[n].description = description; + inverse[n].count_uncertainties = 1; + inverse[n].uncertainties[0] = 0.05; + inverse[n].count_ph_uncertainties = 1; + inverse[n].ph_uncertainties[0] = 0.05; + inverse[n].water_uncertainty = 0.0; + inverse[n].mineral_water = TRUE; + inverse[n].mp = FALSE; + inverse[n].mp_tolerance = 1e-12; + inverse[n].mp_censor = 1e-20; + inverse[n].netpath = NULL; + inverse[n].pat = NULL; +/* + * Read data for inverse modeling + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + opt_save = opt; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in INVERSE_MODELING keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* solutions */ + case 10: /* solution */ + inverse[n].solns = + read_list_ints(&next_char, &inverse[n].count_solns, TRUE); + opt_save = OPTION_ERROR; + break; + case 1: /* uncertainty */ + case 2: /* uncertainties */ + inverse[n].uncertainties = + (LDBLE *) free_check_null(inverse[n].uncertainties); + inverse[n].uncertainties = + read_list_doubles(&next_char, + &inverse[n].count_uncertainties); + opt_save = OPTION_ERROR; + break; + case 3: /* balances */ + case 8: /* balance */ + case 9: /* bal */ + read_inv_balances(&(inverse[n]), next_char); + break; + case 4: /* phase_data */ + case 11: /* phases */ + case 21: /* phase */ + read_inv_phases(&(inverse[n]), next_char); + break; + case 5: /* range */ + case 12: /* ranges */ + inverse[n].range = TRUE; + j = sscanf(next_char, SCANFORMAT, &range_max); + if (j == 1) + { + inverse[n].range_max = range_max; + } + opt_save = OPTION_ERROR; + break; + case 6: /* minimal */ + case 7: /* minimum */ + inverse[n].minimal = TRUE; + opt_save = OPTION_ERROR; + break; + case 13: /* tolerance */ + j = sscanf(next_char, SCANFORMAT, &inv_tol); + if (j == 1) + { + inverse[n].tolerance = inv_tol; + } + opt_save = OPTION_ERROR; + break; + case 14: /* u_water */ + case 15: /* uncertainty_water */ + j = sscanf(next_char, SCANFORMAT, &water_uncertainty); + if (j == 1) + { + inverse[n].water_uncertainty = water_uncertainty; + } + opt_save = OPTION_ERROR; + break; + case 16: /* force */ + case 17: /* force_solution */ + case 18: /* force_solutions */ + inverse[n].force_solns = + (int *) free_check_null(inverse[n].force_solns); + inverse[n].force_solns = + read_list_t_f(&next_char, &inverse[n].count_force_solns); + opt_save = OPTION_ERROR; + break; + case 19: /* isotope values */ + read_inv_isotopes(&(inverse[n]), next_char); + break; + case 20: /* mineral_water */ + inverse[n].mineral_water = get_true_false(next_char, TRUE); + break; + case 22: /* multiple_precision */ + inverse[n].mp = get_true_false(next_char, TRUE); + break; + case 23: /* mp_tolerance */ + j = sscanf(next_char, SCANFORMAT, &inv_tol); + if (j == 1) + { + inverse[n].mp_tolerance = fabs(inv_tol); + } + break; + case 24: /* censor_mp */ + j = sscanf(next_char, SCANFORMAT, &inv_tol); + if (j == 1) + { + inverse[n].mp_censor = fabs(inv_tol); + } + break; + case 25: /* lon_netpath */ + /*copy_token(file_name, &next_char, &l); */ + if (string_trim(next_char) != EMPTY) + { + inverse[n].netpath = string_hsave(next_char); + } + else + { + inverse[n].netpath = string_hsave("netpath"); + } + opt_save = OPTION_ERROR; + break; + case 26: /* pat_netpath */ + /*copy_token(file_name, &next_char, &l); */ + if (string_trim(next_char) != EMPTY) + { + inverse[n].pat = string_hsave(next_char); + } + else + { + inverse[n].pat = string_hsave("netpath"); + } + opt_save = OPTION_ERROR; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * Default: soln 1 -> soln 2 + */ + if (inverse[n].count_solns == 0) + { + inverse[n].solns = (int *) PHRQ_malloc(2 * sizeof(int)); + if (inverse[n].solns == NULL) + malloc_error(); + inverse[n].solns[0] = 1; + inverse[n].solns[1] = 2; + inverse[n].count_solns = 2; + } +/* + * Sort isotopes + */ + if (inverse[n].count_isotopes > 0) + { + qsort(inverse[n].isotopes, + (size_t) inverse[n].count_isotopes, + (size_t) sizeof(struct inv_isotope), inverse_isotope_compare); + } + + if (inverse[n].count_i_u > 0) + { + qsort(inverse[n].i_u, + (size_t) inverse[n].count_i_u, + (size_t) sizeof(struct inv_isotope), inverse_isotope_compare); + } + + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_inv_balances(struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int j, l, count; + char token[MAX_LENGTH]; +/* + * Read element name + */ + j = copy_token(token, &ptr, &l); + if (j == EMPTY) + { + return (OK); + } + else if (j == LOWER && strcmp_nocase_arg1(token, "ph") != 0) + { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else if (strcmp_nocase_arg1(token, "ph") != 0) + { + inverse_ptr->elts = + (struct inv_elts *) PHRQ_realloc(inverse_ptr->elts, + (size_t) (inverse_ptr-> + count_elts + + 1) * + sizeof(struct inv_elts)); + if (inverse_ptr->elts == NULL) + malloc_error(); + replace("(+", "(", token); + inverse_ptr->elts[inverse_ptr->count_elts].name = string_hsave(token); +/* + * Read element uncertainties + */ + inverse_ptr->elts[inverse_ptr->count_elts].uncertainties = + read_list_doubles(&ptr, &count); + inverse_ptr->elts[inverse_ptr->count_elts].count_uncertainties = + count; + inverse_ptr->count_elts++; + } + else if (strcmp_nocase_arg1(token, "ph") == 0) + { + inverse_ptr->ph_uncertainties = + (LDBLE *) free_check_null(inverse_ptr->ph_uncertainties); + inverse_ptr->ph_uncertainties = read_list_doubles(&ptr, &count); + inverse_ptr->count_ph_uncertainties = count; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_inv_isotopes(struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, l1, l2, count; + LDBLE isotope_number; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr1, *ptr2; + const char * redox_name, *element_name; +/* + * Read element name + */ + ptr1 = ptr; + j = copy_token(token, &ptr1, &l); +/* + * ptr1 is start of uncertainties + */ + if (j == EMPTY) + { + return (OK); + } + else if (j != DIGIT) + { + error_msg("Expecting isotope to begin with isotope number.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Read isotope name + */ + ptr2 = token; + get_num(&ptr2, &isotope_number); + if (ptr2[0] == '\0' || isupper((int) ptr2[0]) == FALSE) + { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + + /* redox state name with parentheses */ + redox_name = string_hsave(ptr2); + + copy_token(token, &ptr2, &l1); + replace("(", " ", token); + ptr2 = token; + + /* element name, without parentheses */ + copy_token(token1, &ptr2, &l2); + element_name = string_hsave(token1); + +/* + * add element name to inv_ptr->isotopes + */ + for (i = 0; i < inverse_ptr->count_isotopes; i++) + { + if (element_name == inverse_ptr->isotopes[i].elt_name) + break; + } + if (i == inverse_ptr->count_isotopes) + { + inverse_ptr->isotopes = + (struct inv_isotope *) PHRQ_realloc(inverse_ptr->isotopes, + (size_t) (inverse_ptr-> + count_isotopes + + 1) * + sizeof(struct inv_isotope)); + if (inverse_ptr->isotopes == NULL) + malloc_error(); + inverse_ptr->isotopes[inverse_ptr->count_isotopes].isotope_number = + isotope_number; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].elt_name = + element_name; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties = + (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->isotopes[inverse_ptr->count_isotopes]. + uncertainties == NULL) + malloc_error(); + inverse_ptr->count_isotopes++; + } +/* + * add redox state name to inv_ptr->i_u + */ + inverse_ptr->i_u = + (struct inv_isotope *) PHRQ_realloc(inverse_ptr->i_u, + (size_t) (inverse_ptr-> + count_i_u + + 1) * + sizeof(struct inv_isotope)); + if (inverse_ptr->i_u == NULL) + malloc_error(); + inverse_ptr->i_u[inverse_ptr->count_i_u].elt_name = redox_name; + inverse_ptr->i_u[inverse_ptr->count_i_u].isotope_number = isotope_number; +/* + * Read isotope uncertainties + */ + inverse_ptr->i_u[inverse_ptr->count_i_u].uncertainties = + read_list_doubles(&ptr1, &count); + inverse_ptr->i_u[inverse_ptr->count_i_u].count_uncertainties = count; + inverse_ptr->count_i_u++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_inv_phases(struct inverse *inverse_ptr, char *ptr) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + int count_isotopes; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr1; + struct isotope *isotopes; +/* + * Read phase name + */ + j = copy_token(token, &ptr, &l); + if (j == EMPTY) + return (OK); + inverse_ptr->phases = + (struct inv_phases *) PHRQ_realloc(inverse_ptr->phases, + (size_t) (inverse_ptr-> + count_phases + + 1) * + sizeof(struct inv_phases)); + if (inverse_ptr->phases == NULL) + malloc_error(); + inverse_ptr->phases[inverse_ptr->count_phases].name = string_hsave(token); +/* + * Read constraint, force, and isotopes + */ + inverse_ptr->phases[inverse_ptr->count_phases].constraint = EITHER; + inverse_ptr->phases[inverse_ptr->count_phases].force = FALSE; + count_isotopes = 0; + isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); + if (isotopes == NULL) + malloc_error(); + + for (;;) + { + j = copy_token(token, &ptr, &l); + if (j == EMPTY) + break; + strcpy(token1, token); + str_tolower(token1); + if (token1[0] == 'p') + { + inverse_ptr->phases[inverse_ptr->count_phases].constraint = + PRECIPITATE; + } + else if (token1[0] == 'd') + { + inverse_ptr->phases[inverse_ptr->count_phases].constraint = + DISSOLVE; + } + else if (token[0] == 'f') + { + inverse_ptr->phases[inverse_ptr->count_phases].force = TRUE; + } + else if (j == DIGIT) + { +/* + * read isotope data + */ + isotopes = + (struct isotope *) PHRQ_realloc(isotopes, + (size_t) (count_isotopes + + 1) * + sizeof(struct isotope)); + if (isotopes == NULL) + malloc_error(); + ptr1 = token; + + /* isotope number */ + get_num(&ptr1, &(isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) + { + error_string = sformatf( "Expecting element name: %s.", ptr1); + error_msg(error_string, CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + + /* element name */ + isotopes[count_isotopes].elt_name = string_hsave(ptr1); + + /* ratio */ + j = copy_token(token, &ptr, &l); + if (j != DIGIT) + { + error_msg("Expecting isotope ratio for phase.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio)); + + /* read and store isotope ratio uncertainty */ + prev_next_char = ptr; + if (copy_token(token, &ptr, &l) != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, + &(isotopes[count_isotopes].ratio_uncertainty)); + + count_isotopes++; + } + else + { + error_string = sformatf( + "Unknown option for inverse modeling phase."); + warning_msg(error_string); + } + } + if (count_isotopes > 0) + { + inverse_ptr->phases[inverse_ptr->count_phases].isotopes = isotopes; + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = + count_isotopes; + } + else + { + inverse_ptr->phases[inverse_ptr->count_phases].isotopes = NULL; + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = 0; + isotopes = (struct isotope *) free_check_null(isotopes); + } + inverse_ptr->count_phases++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads kinetics data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read kinetics + */ + int i, j, k, l, count_comps, count_steps, count_list; + char *ptr; + char *description; + char token[MAX_LENGTH]; + int n; + int n_user, n_user_end; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + LDBLE step, coef; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "tol", /* 0 */ + "m", /* 1 */ + "m0", /* 2 */ + "parms", /* 3 */ + "formula", /* 4 */ + "steps", /* 5 */ + "step_divide", /* 6 */ + "parameters", /* 7 */ + "runge-kutta", /* 8 */ + "runge_kutta", /* 9 */ + "rk", /* 10 */ + "bad_step_max", /* 11 */ + "cvode", /* 12 */ + "cvode_steps", /* 13 */ + "cvode_order", /* 14 */ + "time_steps" /* 15 */ + }; + int count_opt_list = 16; + +/* + * Read kinetics number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + +/* + * Find space for kinetics data + */ + kinetics_ptr = kinetics_search(n_user, &n, FALSE); + if (kinetics_ptr != NULL) + { + kinetics_free(kinetics_ptr); + } + else + { + space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, + sizeof(struct kinetics)); + n = count_kinetics++; + } +/* + * Set use data to first read + */ + if (use.Get_kinetics_in() == FALSE) + { + use.Set_kinetics_in(true); + use.Set_n_kinetics_user(n_user); + } +/* + * Initialize + */ + kinetics_init(&(kinetics[n]), n_user, n_user_end, description); + free_check_null(description); + kinetics_ptr = &kinetics[n]; + + count_steps = 0; +/* + * Read kinetics data + */ + return_value = UNKNOWN; + kinetics_comp_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: /* allocate space, read new name */ + count_comps = kinetics_ptr->count_comps++; + kinetics_ptr->comps = + (struct kinetics_comp *) PHRQ_realloc(kinetics_ptr->comps, + (size_t) (count_comps + + 1) * + sizeof(struct + kinetics_comp)); + if (kinetics_ptr->comps == NULL) + malloc_error(); + kinetics_ptr->comps[count_comps].moles = 0; + ptr = line; + copy_token(token, &ptr, &l); + kinetics_ptr->comps[count_comps].rate_name = string_hsave(token); + kinetics_ptr->comps[count_comps].tol = 1e-8; + kinetics_ptr->comps[count_comps].m0 = -1.0; + kinetics_ptr->comps[count_comps].m = -1.0; + kinetics_ptr->comps[count_comps].count_c_params = 0; + + kinetics_comp_ptr = &kinetics_ptr->comps[count_comps]; + kinetics_comp_ptr->d_params = + (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (kinetics_comp_ptr->d_params == NULL) + malloc_error(); + kinetics_comp_ptr->count_d_params = 0; + + kinetics_comp_ptr->c_params = + (const char **) PHRQ_malloc(sizeof(char *)); + if (kinetics_comp_ptr->c_params == NULL) + malloc_error(); + kinetics_comp_ptr->count_c_params = 0; + + kinetics_comp_ptr->count_list = 0; + kinetics_comp_ptr->list = + (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); + if (kinetics_comp_ptr->list == NULL) + malloc_error(); + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in KINETICS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* tolerance */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char, &l) == DIGIT) + { + kinetics_comp_ptr->tol = strtod(token, &ptr); + } + else + { + error_string = sformatf( + "Expecting numerical value for tolerance, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 1: /* m */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char, &l) == DIGIT) + { + kinetics_comp_ptr->m = strtod(token, &ptr); + } + else + { + error_string = sformatf( + "Expecting numerical value for moles of reactant (m), but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 2: /* m0 */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char, &l) == DIGIT) + { + kinetics_comp_ptr->m0 = strtod(token, &ptr); + } + else + { + error_string = sformatf( + "Expecting numerical value for initial moles of reactant (m0), but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 3: /* parms */ + case 7: /* parameters */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + while ((j = copy_token(token, &next_char, &l)) != EMPTY) + { + /* + * Store a LDBLE parameter + */ + if (j == DIGIT) + { + kinetics_comp_ptr->d_params = + (LDBLE *) PHRQ_realloc(kinetics_comp_ptr-> + d_params, + (size_t) + (kinetics_comp_ptr-> + count_d_params + + 1) * sizeof(LDBLE)); + if (kinetics_comp_ptr->d_params == NULL) + malloc_error(); + kinetics_comp_ptr->d_params[kinetics_comp_ptr-> + count_d_params] = + strtod(token, &ptr); + kinetics_comp_ptr->count_d_params++; + } + else + { + /* + * Store a character parameter + */ + kinetics_comp_ptr->c_params = + (const char **) PHRQ_realloc(kinetics_comp_ptr-> + c_params, + (size_t) + (kinetics_comp_ptr-> + count_c_params + + 1) * sizeof(char *)); + if (kinetics_comp_ptr->c_params == NULL) + malloc_error(); + kinetics_comp_ptr->c_params[kinetics_comp_ptr-> + count_c_params] = + string_hsave(token); + kinetics_comp_ptr->count_c_params++; + } + } + } + break; + case 4: /* formula */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + /* + * Store reactant name, default coefficient + */ + ptr = next_char; + while (copy_token(token, &ptr, &l) != EMPTY) + { + if (isalpha((int) token[0]) || (token[0] == '(') + || (token[0] == '[')) + { + count_list = kinetics_comp_ptr->count_list++; + kinetics_comp_ptr->list = + (struct name_coef *) + PHRQ_realloc(kinetics_comp_ptr->list, + (size_t) (count_list + + 1) * + sizeof(struct name_coef)); + if (kinetics_comp_ptr->list == NULL) + malloc_error(); + kinetics_comp_ptr->list[count_list].name = + string_hsave(token); + kinetics_comp_ptr->list[count_list].coef = 1.0; + } + else + { + /* + * Store relative coefficient + */ + j = sscanf(token, SCANFORMAT, &coef); + if (j == 1) + { + count_list = kinetics_comp_ptr->count_list - 1; + kinetics_comp_ptr->list[count_list].coef = coef; + } + else + { + error_msg + ("Reading relative coefficient of reactant.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + } + } + break; + case 5: /* steps */ + case 15: /* time_steps */ + /* + * Read one or more kinetics time increments + */ + while ((j = copy_token(token, &next_char, &l)) == DIGIT) + { + /* Read next step increment(s) */ +/* multiple, equal timesteps 15 aug. 2005 */ + if (replace("*", " ", token) == TRUE) + { + if (sscanf(token, "%d" SCANFORMAT, &k, &step) == 2) + { + for (i = 0; i < k; i++) + { + count_steps++; + kinetics_ptr->steps = + (LDBLE *) PHRQ_realloc(kinetics_ptr->steps, + (size_t) count_steps * + sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) + malloc_error(); + kinetics_ptr->steps[kinetics_ptr->count_steps] = + step; + kinetics_ptr->count_steps = count_steps; + } + } + else + { + input_error++; + error_msg + ("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", + CONTINUE); + } + } + else + { + step = strtod(token, &ptr); + count_steps++; + kinetics_ptr->steps = + (LDBLE *) PHRQ_realloc(kinetics_ptr->steps, + (size_t) count_steps * + sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) + malloc_error(); + kinetics_ptr->steps[kinetics_ptr->count_steps] = step; + kinetics_ptr->count_steps = count_steps; + } + } + if (j == EMPTY) + break; + /* + * Read number of increments + */ + if (kinetics_ptr->count_steps != 1) + { + error_msg + ("To define equal time increments, only one total time should be defined.", + CONTINUE); + input_error++; + break; + } + do + { + j = sscanf(token, "%d", &i); + if (j == 1 && i > 0) + { + kinetics_ptr->count_steps = -i; + break; + } + else if (j == 1 && i <= 0) + { + error_msg + ("Expecting positive number for number of equal " + "time increments for kinetics.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + while (copy_token(token, &next_char, &l) != EMPTY); + break; + case 6: /* step_divide */ + if (copy_token(token, &next_char, &l) == DIGIT) + { + sscanf(token, SCANFORMAT, &kinetics_ptr->step_divide); + } + else + { + error_string = sformatf( + "Expecting numerical value for step_divide."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 8: /* runge-kutta */ + case 9: /* runge_kutta */ + case 10: /* rk */ + j = copy_token(token, &next_char, &l); + if (j == DIGIT) + { + kinetics_ptr->rk = (int) strtod(token, &ptr); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting order for Runge-Kutta method."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 11: /* bad_step_max */ + j = copy_token(token, &next_char, &l); + if (j == DIGIT) + { + kinetics_ptr->bad_step_max = (int) strtod(token, &ptr); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( "Expecting maximal bad steps number."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 12: /* cvode */ + kinetics[n].use_cvode = get_true_false(next_char, TRUE); + break; + case 13: /* cvode_steps */ + j = copy_token(token, &next_char, &l); + if (j == DIGIT) + { + kinetics_ptr->cvode_steps = (int) strtod(token, &ptr); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting maximum number of steps for one call to cvode."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 14: /* cvode_order */ + j = copy_token(token, &next_char, &l); + if (j == DIGIT) + { + kinetics_ptr->cvode_order = (int) strtod(token, &ptr); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting number of terms (order) used in cvode (1-5)."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + +/* + * Default reactant + */ + for (i = 0; i < kinetics[n].count_comps; i++) + { + if (kinetics[n].comps[i].count_list == 0) + { + kinetics[n].comps[i].list[0].name = + kinetics_ptr->comps[i].rate_name; + kinetics[n].comps[i].list[0].coef = 1; + kinetics[n].comps[i].count_list = 1; + } + } +/* + * Default 1 sec + */ + if (kinetics[n].count_steps == 0) + { + kinetics[n].count_steps = 1; + kinetics[n].steps[0] = 1.0; + } +/* + * set defaults for moles + */ + for (i = 0; i < kinetics[n].count_comps; i++) + { + if (kinetics[n].comps[i].m0 < 0) + { + if (kinetics[n].comps[i].m < 0) + { + kinetics[n].comps[i].m0 = 1; + } + else + { + kinetics[n].comps[i].m0 = kinetics[n].comps[i].m; + } + } + if (kinetics[n].comps[i].m < 0) + { + kinetics[n].comps[i].m = kinetics[n].comps[i].m0; + } + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +LDBLE * Phreeqc:: +read_list_doubles(char **ptr, int *count_doubles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of LDBLE numbers until end of line is reached or + * a LDBLE can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-LDBLE token or end of line + * + * count_doubles exit: number of LDBLEs read + * + * Returns: + * pointer to a list of count_doubles LDBLEs. + */ + + LDBLE *LDBLE_list; + char token[MAX_LENGTH]; + LDBLE value; + char *ptr_save; + int l; + + LDBLE_list = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (LDBLE_list == NULL) + malloc_error(); + *count_doubles = 0; + + ptr_save = *ptr; + while (copy_token(token, ptr, &l) != EMPTY) + { + if (sscanf(token, SCANFORMAT, &value) == 1) + { + *count_doubles = *count_doubles + 1; + LDBLE_list = + (LDBLE *) PHRQ_realloc(LDBLE_list, + (size_t) (*count_doubles) * + sizeof(LDBLE)); + if (LDBLE_list == NULL) + malloc_error(); + LDBLE_list[(*count_doubles) - 1] = value; + ptr_save = *ptr; + } + else + { + *ptr = ptr_save; + break; + } + } + return (LDBLE_list); +} + +/* ---------------------------------------------------------------------- */ +int * Phreeqc:: +read_list_ints(char **ptr, int *count_ints, int positive) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of int numbers until end of line is reached or + * an int can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints exit: number of LDBLEs read + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints. + */ + int *int_list; + char token[MAX_LENGTH]; + int value; + int l; + char *ptr_save; + + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) + malloc_error(); + *count_ints = 0; + + ptr_save = *ptr; + while (copy_token(token, ptr, &l) != EMPTY) + { + if (sscanf(token, "%d", &value) == 1) + { + (*count_ints)++; + int_list = + (int *) PHRQ_realloc(int_list, + (size_t) (*count_ints) * sizeof(int)); + if (int_list == NULL) + malloc_error(); + int_list[(*count_ints) - 1] = value; + if (value <= 0 && positive == TRUE) + { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + ptr_save = *ptr; + } + else + { + *ptr = ptr_save; + break; + } + } + return (int_list); +} + +/* ---------------------------------------------------------------------- */ +int * Phreeqc:: +read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of int numbers until end of line is reached or + * an int can not be read from a token. + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints entry: number of ints already in list + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints + */ + char token[MAX_LENGTH]; + int value, value1, value2; + int i, l; + char *ptr_save; + + if (int_list == NULL) + { + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) + malloc_error(); + *count_ints = 0; + } + ptr_save = *ptr; + while (copy_token(token, ptr, &l) != EMPTY) + { + if (sscanf(token, "%d", &value) == 1) + { + /* Read an integer */ + (*count_ints)++; + int_list = + (int *) PHRQ_realloc(int_list, + (size_t) (*count_ints) * sizeof(int)); + if (int_list == NULL) + malloc_error(); + int_list[(*count_ints) - 1] = value; + if (value <= 0 && positive == TRUE) + { + error_msg("Expected an integer greater than zero.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + /* Read range of integers */ + if (replace("-", " ", token) == TRUE) + { + if (sscanf(token, "%d %d", &value1, &value2) != 2) + { + error_msg("Expected an integer range n-m.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else if (value2 < value1) + { + error_msg("Expected an integer range n-m, with n <= m.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else if (value2 <= 0 && positive == TRUE) + { + error_msg("Expected an integer greater than zero.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else + { + for (i = value1 + 1; i <= value2; i++) + { + (*count_ints)++; + int_list = + (int *) PHRQ_realloc(int_list, + (size_t) (*count_ints) * + sizeof(int)); + if (int_list == NULL) + malloc_error(); + int_list[(*count_ints) - 1] = i; + } + } + } + ptr_save = *ptr; + } + else + { + *ptr = ptr_save; + break; + } + } + return (int_list); +} + +/* ---------------------------------------------------------------------- */ +int * Phreeqc:: +read_list_t_f(char **ptr, int *count_ints) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads a list of true and false until end of line is reached or + * until non- t or f is found + * + * Arguments: + * ptr entry: points to line to read from + * exit: points to next non-int token or end of line + * + * count_ints exit: number of LDBLEs read + * + * positive entry: if TRUE, expects to read only positive integers + * + * Returns: + * pointer to a list of count_ints ints. + */ + int *int_list; + char token[MAX_LENGTH]; + int value; + int l; + + int_list = (int *) PHRQ_malloc(sizeof(int)); + if (int_list == NULL) + malloc_error(); + *count_ints = 0; + + while (copy_token(token, ptr, &l) != EMPTY) + { + str_tolower(token); + if (token[0] == 't') + { + value = TRUE; + } + else if (token[0] == 'f') + { + value = FALSE; + } + else + { + error_msg("Expected TRUE or FALSE.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + (*count_ints)++; + int_list = + (int *) PHRQ_realloc(int_list, + (size_t) (*count_ints) * sizeof(int)); + if (int_list == NULL) + malloc_error(); + int_list[(*count_ints) - 1] = value; + } + return (int_list); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_log_k_only(char *ptr, LDBLE * log_k) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read log k + */ + *log_k = 0.0; + replace("=", " ", ptr); + if (sscanf(ptr, SCANFORMAT, log_k) < 1) + { + input_error++; + error_msg("Expecting log k.", CONTINUE); + return (ERROR); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_t_c_only(char *ptr, LDBLE *t_c) +/* ---------------------------------------------------------------------- */ +{ + *t_c = 0.0; + replace("=", " ", ptr); + if (sscanf(ptr, SCANFORMAT, t_c) < 1) + { + input_error++; + error_msg("Expecting numeric value for critical temperature T_c (K)", CONTINUE); + return (ERROR); + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_p_c_only(char *ptr, LDBLE * p_c) +/* ---------------------------------------------------------------------- */ +{ + *p_c = 0.0; + replace("=", " ", ptr); + if (sscanf(ptr, SCANFORMAT, p_c) < 1) + { + input_error++; + error_msg("Expecting numeric value for critical pressure P_c (atm)", CONTINUE); + return (ERROR); + } + return OK; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_omega_only(char *ptr, LDBLE *omega) +/* ---------------------------------------------------------------------- */ +{ + *omega = 0.0; + replace("=", " ", ptr); + if (sscanf(ptr, SCANFORMAT, omega) < 1) + { + input_error++; + error_msg("Expecting numeric value for acentric factor Omega", CONTINUE); + return (ERROR); + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_delta_v_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + char token[MAX_LENGTH]; + /* + * Read analytical expression + */ + for (j = 0; j < 8; j++) + { + delta_v[j] = 0.0; + } + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT /*SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT*/, + &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3])/*, + &(delta_v[4]), &(delta_v[5]), &(delta_v[6]), &(delta_v[7])*/); + if (j < 1) + { + input_error++; + error_msg("Expecting numeric values for the species' molar volume, vm.", + CONTINUE); + return (ERROR); + } + /* + * Read delta V units + */ + *units = cm3_per_mol; + do + { + j = copy_token(token, &ptr, &l); + } while (j == DIGIT); + + if (j == EMPTY) + { + return (OK); + } + + LDBLE factor = 1.0; + if (j == UPPER || j == LOWER) + { + str_tolower(token); + if (strstr(token, "cm3") != NULL) + { + /* cm3/mol */ + ; + } + else if (strstr(token, "dm3") != NULL) + { + /* Convert dm3/mol to cm3/mol */ + //*delta_v *= 1E3; + factor = 1e3; + } + else if (strstr(token, "m3") != NULL) + { + /* Convert m3/mol to cm3/mol */ + //*delta_v *= 1E6; + factor = 1e6; + } + + for (int i = 0; i < 8; i++) + { + delta_v[i] *= factor; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_delta_h_only(char *ptr, LDBLE * delta_h, DELTA_H_UNIT * units) +/* ---------------------------------------------------------------------- */ +{ + int j, l, kilo, joul; + char token[MAX_LENGTH]; +/* + * Read delta H + */ + *delta_h = 0.0; + replace("=", " ", ptr); + j = copy_token(token, &ptr, &l); + if (j == EMPTY) + { + input_error++; + error_msg("Expecting numeric value for delta H.", CONTINUE); + return (ERROR); + } + if (sscanf(token, SCANFORMAT, delta_h) < 1) + { + input_error++; + error_msg("Expecting numeric value for delta H.", CONTINUE); + return (ERROR); + } +/* + * Read delta H units + */ + j = copy_token(token, &ptr, &l); + *units = kjoules; + kilo = TRUE; + joul = TRUE; + if (j == EMPTY) + { + return (OK); + } + if (j == UPPER || j == LOWER) + { + str_tolower(token); + if (strstr(token, "k") != token) + { + /* convert to kilo */ + kilo = FALSE; + *delta_h /= 1000.; + } + if (strstr(token, "c") != NULL) + { + /* convert to joules */ + *delta_h *= JOULES_PER_CALORIE; + joul = FALSE; + } + } + if (kilo == TRUE && joul == TRUE) + { + *units = kjoules; + } + else if (kilo == FALSE && joul == TRUE) + { + *units = joules; + } + else if (kilo == TRUE && joul == FALSE) + { + *units = kcal; + } + else if (kilo == FALSE && joul == FALSE) + { + *units = cal; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_analytical_expression_only(char *ptr, LDBLE * log_k) +/* ---------------------------------------------------------------------- */ +{ + int j; + int num_terms = T_A6 - T_A1 + 1; +/* + * Read analytical expression + */ + for (j = 0; j < num_terms; j++) + { + log_k[j] = 0.0; + } + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + &(log_k[0]), &(log_k[1]), &(log_k[2]), &(log_k[3]), + &(log_k[4]), &(log_k[5])); + if (j < 1) + { + input_error++; + error_msg("Expecting numeric values for analytical expression.", + CONTINUE); + return (ERROR); + } + return (OK); +} + +/* VP: Density Start */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_millero_abcdef (char *ptr, LDBLE * abcdef) +/* ---------------------------------------------------------------------- */ +{ + int j; +/* + * Read a, b, c, d, e and f parameters for Millero density model. + */ + for (j = 0; j < 6; j++) + { + abcdef[j] = 0.0; + } + j = + sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + &(abcdef[0]), &(abcdef[1]), &(abcdef[2]), &(abcdef[3]), &(abcdef[4]), &(abcdef[5])); + if (j < 1) + { + input_error++; + error_msg ("Expecting numeric values for analytical expression.", + CONTINUE); + return (ERROR); + } + return (OK); +} +/* VP: Density End */ + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_incremental_reactions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Define flow only + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int j, l; + char *ptr; + char token[MAX_LENGTH]; + + ptr = line; + /* read keyword */ + copy_token(token, &ptr, &l); + + /* read true or false */ + incremental_reactions = get_true_false(ptr, TRUE); +/* + * find next keyword + */ + while ((j = + check_line("Subroutine Read", FALSE, TRUE, TRUE, + FALSE)) != KEYWORD) + { + /* empty, eof, keyword, print */ + if (j == EOF) + return (EOF); + error_string = sformatf( "Unknown input: %s", line); + error_msg(error_string, CONTINUE); + input_error++; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_master_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads master species data from data file or input file + */ + int j, i, l; + char *ptr, *ptr1; + LDBLE l_z; + struct element *elts_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + elts_ptr = NULL; + for (;;) + { + j = check_line("Master species", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD) + { + break; + } +/* + * Get element name with valence, allocate space, store + */ + ptr = line; +/* + * Get element name and save pointer to character string + */ + if (copy_token(token, &ptr, &l) != UPPER && token[0] != '[') + { + parse_error++; + error_msg("Reading element for master species.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + /* + if (token[0] == '[') { + ptr1 = token; + get_elt(&ptr, element, &l); + strcpy(token, element); + } + */ + replace("(+", "(", token); +/* + * Delete master if it exists + */ + master_delete(token); +/* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master >= max_master) + { + space((void **) ((void *) &master), count_master + 1, + &max_master, sizeof(struct master *)); + } + master[count_master] = master_alloc(); +/* + * Set type to AQ + */ + master[count_master]->type = AQ; +/* + * Save element name + */ + master[count_master]->elt = element_store(token); +/* + * Save pointer to species data for master species + */ + if ((copy_token(token, &ptr, &l) != UPPER) && + token[0] != '[' && (strcmp_nocase_arg1(token, "e-") != 0)) + { + parse_error++; + error_msg("Reading master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + + s_ptr = s_search(token); + if (s_ptr != NULL) + { + master[count_master]->s = s_ptr; + } + else + { + ptr1 = token; + get_token(&ptr1, token1, &l_z, &l); + master[count_master]->s = s_store(token1, l_z, FALSE); + } + +/* + * Read alkalinity for species + */ + copy_token(token, &ptr, &l); + i = sscanf(token, SCANFORMAT, &master[count_master]->alk); + if (i != 1) + { + input_error++; + if (elts_ptr != NULL) + { + error_string = sformatf( + "Expected alkalinity for master species, %s, in master species input.", + elts_ptr->name); + } + else + { + error_string = sformatf( + "Expected alkalinity for master species in master species input."); + } + error_msg(error_string, CONTINUE); + continue; + } +/* + * Read default gfw for species + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, SCANFORMAT, &master[count_master]->gfw); + } + else if (i == UPPER) + { + master[count_master]->gfw_formula = string_hsave(token); + } + else + { + input_error++; + if (elts_ptr != NULL) + { + error_string = sformatf( + "Expected gram formula weight for master species, %s, in master species input.", + elts_ptr->name); + } + else + { + error_string = sformatf( + "Expected gram formula weight for master species in master species input."); + } + error_msg(error_string, CONTINUE); + continue; + } +/* + * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES + */ + if (strchr(master[count_master]->elt->name, '(') == NULL) + { + master[count_master]->primary = TRUE; + /* Read gram formula weight for primary */ + if (strcmp(master[count_master]->elt->name, "E") != 0) + { + elts_ptr = master[count_master]->elt; + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, SCANFORMAT, &elts_ptr->gfw); + } + else + { + input_error++; + if (elts_ptr != NULL) + { + error_string = sformatf( + "Expected gram formula weight for element, %s.", + elts_ptr->name); + } + else + { + error_string = sformatf( + "Expected gram formula weight for element."); + } + + error_msg(error_string, CONTINUE); + continue; + } + } + } + else + { + master[count_master]->primary = FALSE; + } + count_master++; + if (count_master >= max_master) + { + space((void **) ((void *) &master), count_master, &max_master, + sizeof(struct master *)); + } + + } + return (j); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_mix(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads mixing fractions + */ + int n_user, n_user_end; + int return_value; + int n_solution; + LDBLE fraction; + int j, i, l; + char *ptr; + char token[MAX_LENGTH]; + char *description; + //struct mix *mix_ptr; + cxxMix temp_mix; + +/* + * Read mix number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + temp_mix.Set_n_user(n_user); + temp_mix.Set_n_user_end(n_user); + temp_mix.Set_description(description); +/* + * Set use data to first read + */ + if (use.Get_mix_in() == FALSE) + { + use.Set_mix_in(true); + use.Set_n_mix_user(n_user); + } +/* + * Read mixture data + */ + for (;;) + { + return_value = check_line("Mixture data", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + { + break; + } + ptr = line; +/* + * Read n_user + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, "%d ", &n_solution); + } + else + { + input_error++; + error_msg("Expected a solution number in mix input.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Read fraction for solution + */ + copy_token(token, &ptr, &l); + j = sscanf(token, SCANFORMAT, &fraction); + if (j != 1) + { + input_error++; + error_msg("Expected a mixing fraction.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + +/* + * Save data + */ + temp_mix.Add(n_solution ,fraction); + } + if (temp_mix.Get_mixComps().size() == 0) + { + input_error++; + error_msg + ("Must define at least one solution number and mixing fraction for MIX input.", + CONTINUE); + } + Rxn_mix_map[n_user] = temp_mix; + + // copy if needed + if (n_user_end > n_user) + { + int i; + for (i = n_user + 1; i <= n_user_end; i++) + { + Utilities::Rxn_copy(Rxn_mix_map, n_user, i); + } + } + + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_number_description(char *ptr, int *n_user, + int *n_user_end, char **description, int allow_negative) +/* ---------------------------------------------------------------------- */ +{ + int l, n; + char token[MAX_LENGTH]; + char *ptr1; +/* + * Read user number, allow negative numbers Oct 3, 2011 + */ + copy_token(token, &ptr, &l); // keyword + ptr1 = ptr; + copy_token(token, &ptr, &l); + + if (!isdigit(token[0]) && token[0] != '-') + { + *n_user = 1; + *n_user_end = 1; + } + else + { + if (replace("-", " ", &token[1])) + { + n = sscanf(token, "%d%d", n_user, n_user_end); + if (n != 2) + { + if (next_keyword >= 0) + { + error_string = sformatf( "Reading number range for %s.", Keywords::Keyword_name_search(next_keyword).c_str()); + } + else + { + error_string = sformatf( "Reading number range for keyword."); + } + error_msg(error_string, CONTINUE); + input_error++; + } + ptr1 = ptr; + } + else + { + n = sscanf(token, "%d", n_user); + if (n != 1) + { + if (next_keyword >= 0) + { + error_string = sformatf( "Reading number range for %s.", Keywords::Keyword_name_search(next_keyword).c_str()); + } + else + { + error_string = sformatf( "Reading number range for keyword."); + } + error_msg(error_string, CONTINUE); + input_error++; + } + *n_user_end = *n_user; + ptr1 = ptr; + }; + } + if (*n_user < 0 && allow_negative == FALSE) + { + error_string = sformatf( "Negative number in number range not allowed for keyword."); + error_msg(error_string, CONTINUE); + input_error++; + } +/* + * Read description + */ + for (; isspace((int) ptr1[0]); ptr1++); + *description = string_duplicate(ptr1); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for phases, parse equations + */ + int j, i, l; + int association; + char *ptr; + char token[MAX_LENGTH]; + char token1[MAX_LENGTH]; + struct phase *phase_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "log_k", /* 2 */ + "logk", /* 3 */ + "delta_h", /* 4 */ + "deltah", /* 5 */ + "analytical_expression", /* 6 */ + "a_e", /* 7 */ + "ae", /* 8 */ + "add_logk", /* 9 */ + "add_log_k", /* 10 */ + "add_constant", /* 11 */ + "t_c", /* 12 */ + "p_c", /* 13 */ + "omega", /* 14 */ + "delta_v", /* 15 */ + "deltav", /* 16 */ + "vm" /* 17, molar volume, must replace delta_v */ + }; + int count_opt_list = 18; + + association = FALSE; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + phase_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in PHASES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (phase_ptr == NULL) + break; + phase_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (phase_ptr == NULL) + break; + phase_ptr->check_equation = TRUE; + break; + case 2: /* log_k */ + case 3: /* logk */ + if (phase_ptr == NULL) + break; + read_log_k_only(next_char, &phase_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 4: /* delta_h */ + case 5: /* deltah */ + if (phase_ptr == NULL) + break; + read_delta_h_only(next_char, &phase_ptr->logk[1], + &phase_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 6: /* analytical_expression */ + case 7: /* a_e */ + case 8: /* ae */ + if (phase_ptr == NULL) + break; + read_analytical_expression_only(next_char, &(phase_ptr->logk[T_A1])); + opt_save = OPTION_DEFAULT; + break; + case 9: /* add_logk */ + case 10: /* add_log_k */ + if (phase_ptr == NULL) + break; + if (phase_ptr->count_add_logk == 0) + { + phase_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (phase_ptr->add_logk == NULL) + malloc_error(); + } + else + { + phase_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, + (size_t) ((phase_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (phase_ptr->add_logk == NULL) + malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) + { + input_error++; + error_string = sformatf( + "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + phase_ptr->add_logk[phase_ptr->count_add_logk].name = + string_hsave(token); + /* read coef */ + i = sscanf(next_char, SCANFORMAT, + &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); + if (i <= 0) + { + phase_ptr->add_logk[phase_ptr->count_add_logk].coef = 1; + } + phase_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 11: /* add_constant */ + if (phase_ptr == NULL) + break; + if (phase_ptr->count_add_logk == 0) + { + phase_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (phase_ptr->add_logk == NULL) + malloc_error(); + } + else + { + phase_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, + (size_t) ((phase_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (phase_ptr->add_logk == NULL) + malloc_error(); + } + i = sscanf(next_char, SCANFORMAT, + &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); + if (i <= 0) + { + input_error++; + error_string = sformatf( + "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + phase_ptr->add_logk[phase_ptr->count_add_logk].name = + string_hsave("XconstantX"); + /* read coef */ + phase_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 12: /* T_c */ + if (phase_ptr == NULL) + break; + read_t_c_only(next_char, &phase_ptr->t_c); + opt_save = OPTION_DEFAULT; + break; + case 13: /* P_c */ + if (phase_ptr == NULL) + break; + read_p_c_only(next_char, &phase_ptr->p_c); + opt_save = OPTION_DEFAULT; + break; + case 14: /* Omega */ + if (phase_ptr == NULL) + break; + read_omega_only(next_char, &phase_ptr->omega); + opt_save = OPTION_DEFAULT; + break; + case 15: /* delta_v */ + case 16: /* delta_v */ + case 17: /* vm, molar volume */ + if (phase_ptr == NULL) + break; + //read_delta_v_only(next_char, &phase_ptr->delta_v[1], + read_delta_v_only(next_char, &(phase_ptr->logk[vm0]), + &phase_ptr->original_deltav_units); + phase_ptr->delta_v[1] = phase_ptr->logk[vm0]; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get element name and save pointer to character string + */ + phase_ptr = NULL; + ptr = line; + copy_token(token, &ptr, &l); +/* + * Get and parse equation + */ + j = check_line("Phase equation", FALSE, TRUE, TRUE, TRUE); + if (j == EOF || j == KEYWORD) + { + return_value = j; + break; + } + if (parse_eq(line, &next_elt, association) == ERROR) + { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } + phase_ptr = phase_store(token); +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + strcpy(token1, trxn.token[0].name); + replace("(g)", "", token1); + replace("(s)", "", token1); + replace("(G)", "", token1); + replace("(S)", "", token1); + phase_ptr->formula = string_hsave(token1); + for (i = 1; i < count_trxn; i++) + { + if ((strstr(trxn.token[i].name, "(s)") == NULL) && + (strstr(trxn.token[i].name, "(g)") == NULL) && + (strstr(trxn.token[i].name, "(S)") == NULL) && + (strstr(trxn.token[i].name, "(G)") == NULL)) + { + strcpy(token1, trxn.token[i].name); + replace("(aq)", "", token1); + replace("(AQ)", "", token1); + replace("H2O(l)", "H2O", token1); + replace("(H2O(L)", "H2O", token1); + trxn.token[i].s = s_store(token1, trxn.token[i].z, FALSE); + } + else + { + trxn.token[i].s = NULL; + } + } +/* + * Save element list + */ + phase_ptr->next_elt = next_elt; +/* + * Malloc space for phase reaction + */ + phase_ptr->rxn = rxn_alloc(count_trxn + 1); +/* + * Copy reaction to reaction for phase, first token (token[0]) is not used + * except to check that coef of phase formula = 1.0 + */ + token_ptr = phase_ptr->rxn->token; + /* token_ptr[0].coef=0; */ + token_ptr[0].coef = trxn.token[0].coef; + token_ptr[0].s = trxn.token[1].s; + for (i = 1; i < count_trxn; i++) + { + token_ptr[i].name = NULL; + token_ptr[i].s = trxn.token[i].s; + token_ptr[i].coef = trxn.token[i].coef; + if (token_ptr[i].s == NULL) + { + token_ptr[i].name = trxn.token[i].name; + } + } + token_ptr[0].name = trxn.token[1].name; + /* + token_ptr[0].name=phase_ptr->name; + token_ptr[0].s=NULL; + */ + token_ptr[i].s = NULL; + token_ptr[i].name = NULL; +/* + * Set type for phase + */ + phase_ptr->type = SOLID; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads pp_assemblage data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + //int j, n, l, return_value; + int j; + int return_value; + //int count_pure_phases; + int n_user, n_user_end; + char *ptr; + char *description; + //char token[MAX_LENGTH]; + std::string token; + int opt, opt_save; + char *next_char; + const char *opt_list[] = { + "force_equality" /* 0 */ + }; + int count_opt_list = 1; + + ptr = line; + /* + * Read pp_assemblage number + */ + read_number_description(ptr, &n_user, &n_user_end, &description); + /* + * Find pp_assemblage or realloc space for pp_assemblage + */ + cxxPPassemblage temp_pp_assemblage; + cxxPPassemblageComp *comp = NULL; + std::map comps; + temp_pp_assemblage.Set_new_def(true); + temp_pp_assemblage.Set_n_user(n_user); + temp_pp_assemblage.Set_n_user_end(n_user_end); + temp_pp_assemblage.Set_description(description); + free_check_null(description); + /* + * Set use data to first read + */ + if (use.Get_pp_assemblage_in() == FALSE) + { + use.Set_pp_assemblage_in(true); + use.Set_n_pp_assemblage_user(n_user); + } + /* + * Read equilibrium phase data + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EQUILIBRIUM_PHASES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* force_equality */ + if (comp == NULL) + { + error_msg + ("Force_equality defined before equilibrium phase has been defined.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else + { + comp->Set_force_equality(get_true_false(next_char, TRUE) == TRUE); + } + break; + case OPTION_DEFAULT: + /* + * Make space, set default + */ + if (comp) + { + comps[comp->Get_name()] = *comp; + } + delete comp; + comp = new cxxPPassemblageComp; + /* + * Read name + */ + ptr = line; + copy_token(token, &ptr); + comp->Set_name(token.c_str()); + + if ((j = copy_token(token, &ptr)) == EMPTY) + continue; + /* + * Read saturation index + */ + j = sscanf(token.c_str(), SCANFORMAT, &dummy); + comp->Set_si(dummy); + comp->Set_si_org(dummy); + if (j != 1) + { + error_msg("Expected saturation index.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } + /* + * Adding a reaction to the phase boundary + */ + if ((j = copy_token(token, &ptr)) == EMPTY) + continue; + if (j == UPPER || j == LOWER) + { + comp->Set_add_formula(token.c_str()); + j = copy_token(token, &ptr); + } + /* + * Read amount + */ + if (j == EMPTY) + continue; + j = sscanf(token.c_str(), SCANFORMAT, &dummy); + comp->Set_moles(dummy); + if (j != 1) + { + error_msg("Expected amount of mineral.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } + if ((j = copy_token(token, &ptr)) == EMPTY) + continue; + Utilities::str_tolower(token); + if (strstr(token.c_str(), "d") == token.c_str()) + { + comp->Set_dissolve_only(true); + comp->Set_precipitate_only(false); + } else if (strstr(token.c_str(), "p") == token.c_str()) + { + comp->Set_precipitate_only(true); + comp->Set_dissolve_only(false); + } + else + { + error_msg + ("Unexpected data at end of equilibrium-phase definition.", + CONTINUE); + input_error++; + continue; + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + if (comp) + { + comps[comp->Get_name()] = *comp; + delete comp; + comp = NULL; + } + temp_pp_assemblage.Set_pp_assemblage_comps(comps); + Rxn_pp_assemblage_map[n_user] = temp_pp_assemblage; + + return (return_value); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_pure_phases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads pure phase data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int j, n, l, return_value; + int count_pure_phases; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + int opt, opt_save; + char *next_char; + const char *opt_list[] = { + "force_equality" /* 0 */ + }; + int count_opt_list = 1; + + ptr = line; + /* + * Read pp_assemblage number + */ + read_number_description(ptr, &n_user, &n_user_end, &description); + /* + * Find pp_assemblage or realloc space for pp_assemblage + */ + + if (pp_assemblage_search(n_user, &n) != NULL) + { + pp_assemblage_free(&pp_assemblage[n]); + } + else + { + n = count_pp_assemblage++; + space((void **) ((void *) &pp_assemblage), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage)); + } + /* + * Set use data to first read + */ + if (use.Get_pp_assemblage_in() == FALSE) + { + use.Get_pp_assemblage_in() = TRUE; + use.Get_n_pp_assemblage_user() = n_user; + } + + pp_assemblage_init(&(pp_assemblage[n]), n_user, n_user_end, description); + free_check_null(description); + count_pure_phases = 0; + /* + * Read equilibrium phase data + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in EQUILIBRIUM_PHASES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* force_equality */ + if (count_pure_phases == 0) + { + error_msg + ("Force_equality defined before equilibrium phase has been defined.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + else + { + pp_assemblage[n].pure_phases[count_pure_phases - + 1].force_equality = + get_true_false(next_char, TRUE); + } + break; + case OPTION_DEFAULT: + /* + * Make space, set default + */ + count_pure_phases++; + pp_assemblage[n].pure_phases = + (struct pure_phase *) PHRQ_realloc(pp_assemblage[n]. + pure_phases, + (size_t) + (count_pure_phases) * + sizeof(struct pure_phase)); + if (pp_assemblage[n].pure_phases == NULL) + malloc_error(); + pp_assemblage[n].pure_phases[count_pure_phases - 1].si = 0.0; + pp_assemblage[n].pure_phases[count_pure_phases - 1].si_org = 0.0; + pp_assemblage[n].pure_phases[count_pure_phases - 1].add_formula = + NULL; + pp_assemblage[n].pure_phases[count_pure_phases - 1].moles = 10.0; + pp_assemblage[n].pure_phases[count_pure_phases - 1].delta = 0.0; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].initial_moles = 0.0; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].force_equality = FALSE; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].dissolve_only = FALSE; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].precipitate_only = FALSE; + /* + * Read name + */ + ptr = line; + copy_token(token, &ptr, &l); + pp_assemblage[n].pure_phases[count_pure_phases - 1].name = + string_hsave(token); + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + continue; + /* + * Read saturation index + */ + j = sscanf(token, SCANFORMAT, &dummy); + pp_assemblage[n].pure_phases[count_pure_phases - 1].si = + (LDBLE) dummy; + pp_assemblage[n].pure_phases[count_pure_phases - 1].si_org = + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected saturation index.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } + /* + * Adding a reaction to the phase boundary + */ + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + continue; + if (j == UPPER || j == LOWER) + { + pp_assemblage[n].pure_phases[count_pure_phases - + 1].add_formula = + string_hsave(token); + j = copy_token(token, &ptr, &l); + } + /* + * Read amount + */ + if (j == EMPTY) + continue; + j = sscanf(token, SCANFORMAT, &dummy); + pp_assemblage[n].pure_phases[count_pure_phases - 1].moles = + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected amount of mineral.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + continue; + } + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + continue; + str_tolower(token); + if (strstr(token, "d") == token) + { + pp_assemblage[n].pure_phases[count_pure_phases - + 1].dissolve_only = TRUE; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].precipitate_only = FALSE; + } else if (strstr(token, "p") == token) + { + pp_assemblage[n].pure_phases[count_pure_phases - + 1].precipitate_only = TRUE; + pp_assemblage[n].pure_phases[count_pure_phases - + 1].dissolve_only = FALSE; + } + else + { + error_msg + ("Unexpected data at end of equilibrium-phase definition.", + CONTINUE); + input_error++; + continue; + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + pp_assemblage[n].count_comps = count_pure_phases; + /* + * Sort phases by name (lowercase) + */ + qsort(pp_assemblage[n].pure_phases, + (size_t) count_pure_phases, + (size_t) sizeof(struct pure_phase), pure_phase_compare); + + return (return_value); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_reaction(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads reaction data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read reaction + */ + int l; + char *ptr; + char *description; + char token[MAX_LENGTH]; + int return_value; + int n_user, n_user_end; + +/* + * Read reaction number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + +/* + * Set use data to first read + */ + if (use.Get_reaction_in() == FALSE) + { + use.Set_reaction_in(true); + use.Set_n_reaction_user(n_user); + } +/* + * Defaults + */ + cxxReaction temp_reaction; + temp_reaction.Set_n_user(n_user); + temp_reaction.Set_n_user_end(n_user_end); + temp_reaction.Set_description(description); + free_check_null(description); +/* + * Read reaction data + */ + for (;;) + { +/* + * Read line + */ + return_value = check_line("Reaction data", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + { + break; + } + ptr = line; + copy_token(token, &ptr, &l); + if (isalpha((int) token[0]) || (token[0] == '(') || (token[0] == '[')) + { +/* + * Read reactant information + */ + read_reaction_reactants(&temp_reaction); + } + else + { +/* + * Read steps information + */ + read_reaction_steps(&temp_reaction); + } + } +/* + * Default 1 mol of reaction + */ + if (temp_reaction.Get_steps().size() == 0) + { + std::vector v; + v.push_back(1.0); + temp_reaction.Set_steps(v); + } + if (temp_reaction.Get_equalIncrements()) + { + if (temp_reaction.Get_countSteps() == 0) + { + temp_reaction.Set_countSteps(1); + } + } + Rxn_reaction_map[n_user] = temp_reaction; + // copy if needed + Utilities::Rxn_copies(Rxn_reaction_map, n_user, n_user_end); + + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_reaction_reactants(cxxReaction *reaction_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read reactants, may be a chemical formula or a pure_phase name + * followed by relative reaction coefficient, default 1.0. + * + */ + std::string token, last_token; + LDBLE coef; + char *ptr; +/* + * Read one or more reactants + */ + ptr = line; + while (copy_token(token, &ptr) != EMPTY) + { +/* + * Store reactant name, default coefficient + */ + if (isalpha((int) token[0]) || (token[0] == '(') || (token[0] == '[')) + { + + reaction_ptr->Get_reactantList()[token] = 1.0; + last_token = token; +/* + * Store relative coefficient + */ + } + else + { + int j = sscanf(token.c_str(), SCANFORMAT, &coef); + if (j == 1 && last_token.size() > 0) + { + reaction_ptr->Get_reactantList()[last_token] = coef; + } + else + { + error_msg("Reading relative coefficient of reactant.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_reaction_steps(cxxReaction *reaction_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read amount(s) of irrev reactions in one of three forms: + * + * 6 millimoles in 6 steps or + * + * 1 2 3 4 5 6 millimoles or + * + * 6*1 millimoles + * INCREMENTAL_REACTIONS + */ + + char *ptr; + std::string token, token1; + + ptr = line; +/* + * Read one or more reaction increments + */ + for (;;) + { + if (copy_token(token, &ptr) == EMPTY) + { + return (OK); + } +/* + * Read next step increment + */ +/* begin modif 29 july 2005... */ + if (replace("*", " ", token)) + { + int n; + LDBLE value; + if (sscanf(token.c_str(), "%d" SCANFORMAT, &n, &value) == 2) + { + for (int i = 0; i < n; i++) + { + reaction_ptr->Get_steps().push_back(value); + } + } + else + { + input_error++; + error_msg + ("Format error in multiple, equal REACTION steps.\nCorrect is (for example): 0.2 4*0.1 2*0.5 0.3\n", + CONTINUE); + } + } + else + { + LDBLE step; + int j = sscanf(token.c_str(), SCANFORMAT, &step); + if (j == 1) + { + reaction_ptr->Get_steps().push_back(step); + } + else + { + break; + } + } +/* ...end modif 29 july 2005 */ + } +/* + * Read units + */ + token1 = token; + token1.append("/l"); + char * t1 = string_duplicate(token1.c_str()); + if (check_units(t1, FALSE, FALSE, NULL, FALSE) == OK) + { + replace("/l", "", t1); + if (strstr(t1, "Mol") == NULL) + { + error_string = sformatf( "Units of steps not in moles, %s.", token.c_str()); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + else + { + reaction_ptr->Set_units(t1); + } + if (copy_token(token, &ptr) == EMPTY) + { + return (OK); + } + } +/* + * Read number of equal increments, store as negative integer + */ + if (reaction_ptr->Get_actualSteps() != 1) + { + error_msg + ("To define equal increments, only one reaction increment should be defined.", + CONTINUE); + input_error++; + return (ERROR); + } + do + { + int i; + int j = sscanf(token.c_str(), "%d", &i); + if (j == 1 && i > 0) + { + reaction_ptr->Set_countSteps(i); + reaction_ptr->Set_equalIncrements(true); + return (OK); + } + else if (j == 1 && i <= 0) + { + break; + } + } + while (copy_token(token, &ptr) != EMPTY); + + error_msg("Expecting positive number for number of equal " + "increments to add.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_save(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, mix, irreversible reaction, and pure phases to use + * in reaction calculation + */ + int i, l, n, n_user, n_user_end; + char *ptr; + char token[MAX_LENGTH]; +/* + * Read "save" + */ + ptr = line; + copy_token(token, &ptr, &l); +/* + * Read keyword + */ + copy_token(token, &ptr, &l); + check_key(token); +/* + * Read number + */ + for (;;) + { + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + replace("-", " ", token); + n = sscanf(token, "%d%d", &n_user, &n_user_end); + if (n == 1) + { + n_user_end = n_user; + } + if (n_user < 0) + { + error_msg("Number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + break; + } + else if (i == EMPTY) + { + error_string = sformatf( "No number given, 1 assumed."); + warning_msg(error_string); + n_user = 1; + n_user_end = 1; + break; + } + } + + switch (next_keyword) + { + case Keywords::KEY_SOLUTION: /* Solution */ + save.solution = TRUE; + save.n_solution_user = n_user; + save.n_solution_user_end = n_user_end; + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */ + save.pp_assemblage = TRUE; + save.n_pp_assemblage_user = n_user; + save.n_pp_assemblage_user_end = n_user_end; + break; + case Keywords::KEY_EXCHANGE: /* exchange */ + save.exchange = TRUE; + save.n_exchange_user = n_user; + save.n_exchange_user_end = n_user_end; + break; + case Keywords::KEY_SURFACE: /* surface */ + save.surface = TRUE; + save.n_surface_user = n_user; + save.n_surface_user_end = n_user_end; + break; + case Keywords::KEY_GAS_PHASE: /* gas_phase */ + save.gas_phase = TRUE; + save.n_gas_phase_user = n_user; + save.n_gas_phase_user_end = n_user_end; + break; + case Keywords::KEY_SOLID_SOLUTIONS: /* solid_solutions */ + save.ss_assemblage = TRUE; + save.n_ss_assemblage_user = n_user; + save.n_ss_assemblage_user_end = n_user_end; + break; + default: + input_error++; + error_msg + ("Expecting keyword solution, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions.", + CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of save", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (ERROR); + } + + check_line("End of save", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_selected_output(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for to output to flat file + */ + int value; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "file", /* 0 */ + "totals", /* 1 */ + "molalities", /* 2 */ + "activities", /* 3 */ + "pure_phases", /* 4 */ + "si", /* 5 */ + "saturation_indices", /* 6 */ + "gases", /* 7 */ + "equilibrium_phases", /* 8 */ + "equilibria", /* 9 */ + "equilibrium", /* 10 */ + "pure", /* 11 */ + "inverse", /* 12 */ + "kinetic_reactants", /* 13 */ + "kinetics", /* 14 */ + "solid_solutions", /* 15 */ + "inverse_modeling", /* 16 */ + "reset", /* 17 */ + "simulation", /* 18 */ + "sim", /* 19 */ + "state", /* 20 */ + "solution", /* 21 */ + "soln", /* 22 */ + "distance", /* 23 */ + "dist", /* 24 */ + "time", /* 25 */ + "step", /* 26 */ + "reaction", /* 27 */ + "rxn", /* 28 */ + "temperature", /* 29 */ + "temp", /* 30 */ + "ph", /* 31 */ + "pe", /* 32 */ + "alkalinity", /* 33 */ + "alk", /* 34 */ + "ionic_strength", /* 35 */ + "mu", /* 36 */ + "water", /* 37 */ + "high_precision", /* 38 */ + "user_punch", /* 39 */ + "mol", /* 40 */ + "kin", /* 41 */ + "charge_balance", /* 42 */ + "percent_error", /* 43 */ + "selected_out", /* 44 */ + "selected_output", /* 45 */ + "isotopes", /* 46 */ + "calculate_values", /* 47 */ + "equilibrium_phase" /* 48 */ + }; + int count_opt_list = 49; + + int i, l; + char file_name[MAX_LENGTH], token[MAX_LENGTH]; + + punch.in = TRUE; + punch.new_def = TRUE; + punch.count_totals = 0; + punch.count_molalities = 0; + punch.count_activities = 0; + punch.count_pure_phases = 0; + punch.count_si = 0; + punch.count_gases = 0; + punch.count_kinetics = 0; + punch.count_s_s = 0; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + opt_save = opt; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* file name */ + /* copy_token(file_name, &next_char, &l); */ + if (string_trim(next_char) != EMPTY) + { + strcpy(file_name, next_char); + have_punch_name = TRUE; + punch_close(); + if (punch_open(file_name) != OK) + { + error_string = sformatf( "Can't open file, %s.", file_name); + input_error++; + error_msg(error_string, CONTINUE); + } + } + opt_save = OPTION_ERROR; + break; + case 1: /* totals */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '[') + { + error_string = sformatf( "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + punch.count_totals++; + punch.totals = + (struct name_master *) PHRQ_realloc(punch.totals, + (size_t) punch. + count_totals * + sizeof(struct + name_master)); + if (punch.totals == NULL) + malloc_error(); + punch.totals[punch.count_totals - 1].name = + string_hsave(token); + } + } + break; + case 2: /* molalities */ + case 40: /* mol */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) + { + error_string = sformatf( "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + punch.count_molalities++; + punch.molalities = + (struct name_species *) PHRQ_realloc(punch. + molalities, + (size_t) punch. + count_molalities + * + sizeof(struct + name_species)); + if (punch.molalities == NULL) + malloc_error(); + punch.molalities[punch.count_molalities - 1].name = + string_hsave(token); + } + } + break; + case 3: /* activities */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) + { + error_string = sformatf( "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + punch.count_activities++; + punch.activities = + (struct name_species *) PHRQ_realloc(punch. + activities, + (size_t) punch. + count_activities + * + sizeof(struct + name_species)); + if (punch.activities == NULL) + malloc_error(); + punch.activities[punch.count_activities - 1].name = + string_hsave(token); + } + } + break; + case 4: /* pure_phases */ + case 8: /* equilibrium_phases */ + case 9: /* equilibria */ + case 10: /* equilibrium */ + case 11: /* pure */ + case 48: /* equilibrium_phase */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_pure_phases++; + punch.pure_phases = + (struct name_phase *) PHRQ_realloc(punch.pure_phases, + (size_t) punch. + count_pure_phases * + sizeof(struct + name_phase)); + if (punch.pure_phases == NULL) + malloc_error(); + punch.pure_phases[punch.count_pure_phases - 1].name = + string_hsave(token); + } + break; + case 5: /* si */ + case 6: /* saturation_index */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_si++; + punch.si = + (struct name_phase *) PHRQ_realloc(punch.si, + (size_t) punch. + count_si * + sizeof(struct + name_phase)); + if (punch.si == NULL) + malloc_error(); + punch.si[punch.count_si - 1].name = string_hsave(token); + } + break; + case 7: /* gases */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_gases++; + punch.gases = + (struct name_phase *) PHRQ_realloc(punch.gases, + (size_t) punch. + count_gases * + sizeof(struct + name_phase)); + if (punch.gases == NULL) + malloc_error(); + punch.gases[punch.count_gases - 1].name = string_hsave(token); + } + break; + case 12: /* inverse */ + case 16: /* inverse_modeling */ + punch.inverse = get_true_false(next_char, TRUE); + break; + case 13: /* kinetic_reactants */ + case 14: /* kinetics */ + case 41: /* kin */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_kinetics++; + punch.kinetics = + (struct name_phase *) PHRQ_realloc(punch.kinetics, + (size_t) punch. + count_kinetics * + sizeof(struct + name_phase)); + if (punch.kinetics == NULL) + malloc_error(); + punch.kinetics[punch.count_kinetics - 1].name = + string_hsave(token); + } + break; + case 15: /* solid_solutions */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_s_s++; + punch.s_s = + (struct name_phase *) PHRQ_realloc(punch.s_s, + (size_t) punch. + count_s_s * + sizeof(struct + name_phase)); + if (punch.s_s == NULL) + malloc_error(); + punch.s_s[punch.count_s_s - 1].name = string_hsave(token); + } + break; + case 46: /* isotopes */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '[') + { + error_string = sformatf( "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + punch.count_isotopes++; + punch.isotopes = + (struct name_master *) PHRQ_realloc(punch.isotopes, + (size_t) punch. + count_isotopes * + sizeof(struct + name_master)); + if (punch.isotopes == NULL) + malloc_error(); + punch.isotopes[punch.count_isotopes - 1].name = + string_hsave(token); + } + } + break; + case 47: /* calculate_values */ + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + punch.count_calculate_values++; + punch.calculate_values = + (struct name_master *) PHRQ_realloc(punch. + calculate_values, + (size_t) punch. + count_calculate_values + * + sizeof(struct + name_master)); + if (punch.calculate_values == NULL) + malloc_error(); + punch.calculate_values[punch.count_calculate_values - + 1].name = string_hsave(token); + } + break; + case 17: /* reset */ + value = get_true_false(next_char, TRUE); + /* matches print order */ + punch.sim = value; + punch.state = value; + punch.soln = value; + punch.dist = value; + punch.time = value; + punch.step = value; + punch.ph = value; + punch.pe = value; + punch.rxn = value; + punch.temp = value; + punch.alk = value; + punch.mu = value; + punch.water = value; + punch.charge_balance = value; + punch.percent_error = value; + break; + case 18: /* simulation */ + case 19: /* sim */ + punch.sim = get_true_false(next_char, TRUE); + break; + case 20: /* state */ + punch.state = get_true_false(next_char, TRUE); + break; + case 21: /* solution */ + case 22: /* soln */ + punch.soln = get_true_false(next_char, TRUE); + break; + case 23: /* distance */ + case 24: /* dist */ + punch.dist = get_true_false(next_char, TRUE); + break; + case 25: /* time */ + punch.time = get_true_false(next_char, TRUE); + break; + case 26: /* step */ + punch.step = get_true_false(next_char, TRUE); + break; + case 27: /* reaction */ + case 28: /* rxn */ + punch.rxn = get_true_false(next_char, TRUE); + break; + case 29: /* temperature */ + case 30: /* temp */ + punch.temp = get_true_false(next_char, TRUE); + break; + case 31: /* ph */ + punch.ph = get_true_false(next_char, TRUE); + break; + case 32: /* pe */ + punch.pe = get_true_false(next_char, TRUE); + break; + case 33: /* alkalinity */ + case 34: /* alk */ + punch.alk = get_true_false(next_char, TRUE); + break; + case 35: /* ionic strength */ + case 36: /* mu */ + punch.mu = get_true_false(next_char, TRUE); + break; + case 37: /* water */ + punch.water = get_true_false(next_char, TRUE); + break; + case 38: /* high_precision */ + punch.high_precision = get_true_false(next_char, TRUE); + if (punch.high_precision == TRUE /*&& convergence_tolerance > 1e-12*/) + { + convergence_tolerance = 1e-12; + } + break; + case 39: /* user_punch */ + punch.user_punch = get_true_false(next_char, TRUE); + break; + case 42: /* charge_balance */ + punch.charge_balance = get_true_false(next_char, TRUE); + break; + case 43: /* percent_error */ + punch.percent_error = get_true_false(next_char, TRUE); + break; + case 44: /* selected_out */ + case 45: /* selected_output */ + pr.punch = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + if (!have_punch_name) + { + punch_close(); + if (punch_open("selected.out") != OK) + { + error_string = sformatf( "Can't open file, %s.", "selected.out"); + input_error++; + error_msg(error_string, CONTINUE); + } + } + + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int n_user, n_user_end; + int default_pe, alk; + int count_isotopes; + int max_mass_balance, count_mass_balance; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "press", /* 11 */ + "pressure" /* 12 */ + }; + int count_opt_list = 13; +/* + * Read solution number and description + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); +/* + * Malloc space for solution data + */ + if (solution_bsearch(n_user, &n, FALSE) != NULL) + { + solution_free(solution[n]); + } + else + { + n = count_solution++; + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } + } + solution[n] = solution_alloc(); + + solution[n]->n_user = n_user; + solution[n]->n_user_end = n_user_end; + if (use.Get_solution_in() == FALSE) + { + use.Set_solution_in(true); + use.Set_n_solution_user(n_user); + } + max_mass_balance = MAX_MASS_BALANCE; +/* + * Set default ph, temp, density, pe, units + */ + solution[n]->description = description; + solution[n]->tc = 25.0; + solution[n]->patm = 1; + solution[n]->ph = 7.0; + solution[n]->density = 1.0; + solution[n]->solution_pe = 4.0; + solution[n]->mass_water = 1.0; + solution[n]->ah2o = 1.0; + solution[n]->mu = 1e-7; + solution[n]->cb = 0.0; + solution[n]->count_master_activity = 0; + default_pe = 0; + solution[n]->units = string_hsave("mMol/kgw"); + solution[n]->totals[0].description = NULL; + count_mass_balance = 0; + count_isotopes = 0; +/* + * Read concentration data + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + ptr = next_char; + if (copy_token(token, &ptr, &l) == DIGIT) + { + opt = 9; + } + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* temperature */ + case 1: + if (sscanf(next_char, SCANFORMAT, &(solution[n]->tc)) != 1) + { + solution[n]->tc = 25; + } + break; + case 2: /* density */ + case 3: + sscanf(next_char, SCANFORMAT, &(solution[n]->density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + { + if (check_units(token, FALSE, FALSE, solution[n]->units, TRUE) == + OK) + { + solution[n]->units = string_hsave(token); + } + else + { + input_error++; + } + } + break; + case 5: /* redox */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + if (parse_couple(token) == OK) + { + default_pe = pe_data_store(&(solution[n]->pe), token); + } + else + { + input_error++; + } + break; + case 6: /* ph */ + if (read_conc(n, count_mass_balance, line) == ERROR) + { + input_error++; + break; + } + solution[n]->ph = + solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL) + { + break; + } + solution[n]->totals[count_mass_balance].description = + string_hsave("H(1)"); + count_mass_balance++; + break; + case 7: /* pe */ + if (read_conc(n, count_mass_balance, line) == ERROR) + { + input_error++; + break; + } + solution[n]->solution_pe = + solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL) + { + break; + } + solution[n]->totals[count_mass_balance].description = + string_hsave("E"); + count_mass_balance++; + break; + case 9: /* isotope */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + solution[n]->isotopes = + (struct isotope *) PHRQ_realloc(solution[n]->isotopes, + (size_t) (count_isotopes + + 1) * + sizeof(struct isotope)); + if (solution[n]->isotopes == NULL) + malloc_error(); + + /* read and save element name */ + ptr1 = token; + get_num(&ptr1, + &(solution[n]->isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) + { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + solution[n]->isotopes[count_isotopes].elt_name = + string_hsave(ptr1); + + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, + &(solution[n]->isotopes[count_isotopes].ratio)); + + solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; + + /* read and store isotope ratio uncertainty */ + if ((j = copy_token(token, &next_char, &l)) != EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, + &(solution[n]->isotopes[count_isotopes]. + ratio_uncertainty)); + } + count_isotopes++; + break; + case 10: /* water */ + j = copy_token(token, &next_char, &l); + if (j == EMPTY) + { + solution[n]->mass_water = 1.0; + } + else if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token, SCANFORMAT, &dummy); + solution[n]->mass_water = (LDBLE) dummy; + } + break; + case 11: /* pressure */ + case 12: + if (sscanf(next_char, SCANFORMAT, &(solution[n]->patm)) != 1) + { + solution[n]->patm = 1; + } + break; + case OPTION_DEFAULT: +/* + * Read concentration + */ + if (read_conc(n, count_mass_balance, line) == ERROR) + { + input_error++; + break; + } + count_mass_balance++; + break; + } + if (count_mass_balance + 1 >= max_mass_balance) + { + space((void **) ((void *) &(solution[n]->totals)), + count_mass_balance + 1, &max_mass_balance, + sizeof(struct conc)); + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * fix up default units and default pe + */ + for (i = 0; i < count_mass_balance; i++) + { + strcpy(token, solution[n]->totals[i].description); + str_tolower(token); + if (solution[n]->totals[i].units == NULL) + { + solution[n]->totals[i].units = solution[n]->units; + } + else + { + alk = FALSE; + if (strstr(token, "alk") == token) + alk = TRUE; + strcpy(token1, solution[n]->totals[i].units); + if (check_units(token1, alk, TRUE, solution[n]->units, TRUE) == + ERROR) + { + input_error++; + } + else + { + solution[n]->totals[i].units = string_hsave(token1); + } + } + if (solution[n]->totals[i].n_pe < 0) + { + solution[n]->totals[i].n_pe = default_pe; + } + } + solution[n]->default_pe = default_pe; +/* + * Mark end of solution + */ + solution[n]->totals[count_mass_balance].description = NULL; + solution[n]->count_isotopes = count_isotopes; + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_species(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for aqueous species, parse equations + */ + int i; + int association; + struct species *s_ptr; + struct elt_list *next_elt; + char *ptr, token[MAX_LENGTH]; + bool vm_read; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "gamma", /* 2 */ + "mb", /* 3 */ + "mass_balance", /* 4 */ + "log_k", /* 5 */ + "logk", /* 6 */ + "delta_h", /* 7 */ + "deltah", /* 8 */ + "analytical_expression", /* 9 */ + "a_e", /* 10 */ + "ae", /* 11 */ + "mole_balance", /* 12 */ + "llnl_gamma", /* 13 */ + "co2_llnl_gamma", /* 14 */ + "activity_water", /* 15 */ + "add_logk", /* 16 */ + "add_log_k", /* 17 */ + "add_constant", /* 18 */ + "dw", /* 19 */ + "erm_ddl", /* 20 */ +/* VP: Density Start */ + "millero", /* 21 */ +/* VP: Density End */ + "delta_v", /* 22 */ + "deltav", /* 23 */ + "vm" /* 24, molar volume, must replace delta_v */ + }; + int count_opt_list = 25; + + association = TRUE; + s_ptr = NULL; +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + vm_read = false; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* gamma data */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 2; /* Wateq D-H */ + i = sscanf(next_char, SCANFORMAT SCANFORMAT, &s_ptr->dha, + &s_ptr->dhb); + if (i < 2) + { + error_string = sformatf( "Expecting 2 activity-" + "coefficient parameters, a and b."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 3: /* mb */ + case 4: /* mass_balance */ + case 12: /* mole_balance */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count = 0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + s_ptr->next_secondary = + (struct elt_list *) free_check_null(s_ptr->next_secondary); + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = elt_list_save(); +/* debug + for (i = 0; i < count_elts; i++) { + output_msg(sformatf("%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef)); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 5: /* log_k */ + case 6: /* logk */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 7: /* delta_h */ + case 8: /* deltah */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], + &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 9: /* analytical_expression */ + case 10: /* a_e */ + case 11: /* ae */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[T_A1])); + opt_save = OPTION_DEFAULT; + break; + case 13: /* llnl_gamma */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 7; /* llnl D-H */ + i = sscanf(next_char, SCANFORMAT, &s_ptr->dha); + if (i < 1) + { + error_string = sformatf( + "Expecting activity-coefficient parameter, a."); + warning_msg(error_string); + } + opt_save = OPTION_DEFAULT; + break; + case 14: /* co2_llnl_gamma */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 8; /* llnl CO2 D-H */ + opt_save = OPTION_DEFAULT; + break; + case 15: /* activity water */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->gflag = 9; /* activity_water/55.5 for HDO, D2O, H2[O18], etc */ + opt_save = OPTION_DEFAULT; + break; + case 16: /* add_logk */ + case 17: /* add_log_k */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) + { + input_error++; + error_string = sformatf( + "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 18: /* add_constant */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + input_error++; + error_string = sformatf( + "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = + string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 19: /* tracer diffusion coefficient */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + i = sscanf(next_char, SCANFORMAT, &s_ptr->dw); + opt_save = OPTION_DEFAULT; + break; + case 20: /* enrichment factor in the DDL */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + i = sscanf(next_char, SCANFORMAT, &s_ptr->erm_ddl); + if (s_ptr->erm_ddl < 0) + { + error_string = sformatf( "Expecting enrichment factor > 0, " + "resetting to erm_ddl = 1."); + warning_msg(error_string); + s_ptr->erm_ddl = 1.0; + } + opt_save = OPTION_DEFAULT; + break; +/* VP: Density Start */ + case 21: /* Millero a, b, c, d, e and f coefficients */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + print_density = read_millero_abcdef (next_char, &(s_ptr->millero[0])); + if (!vm_read) + { + /* copy millero parms into logk, for calculating pressure dependency... */ + for (i = 0; i < 3; i++) + s_ptr->logk[vm0 + i] = s_ptr->millero[i]; + } + opt_save = OPTION_DEFAULT; + break; +/* VP: Density End */ + + case 22: /* delta_v */ + case 23: /* deltav */ + case 24: /* vm, molar volume */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_v_only(next_char, &s_ptr->logk[vm0], + &s_ptr->original_deltav_units); + vm_read = true; + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get space for species information and parse equation + */ + s_ptr = NULL; + if (parse_eq(line, &next_elt, association) == ERROR) + { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = + s_store(trxn.token[0].name, trxn.token[0].z, TRUE); + for (i = 1; i < count_trxn; i++) + { + trxn.token[i].s = + s_store(trxn.token[i].name, trxn.token[i].z, FALSE); + } +/* + * Save element list and carbon, hydrogen, and oxygen in species + */ + trxn.token[0].s->next_elt = next_elt; + trxn.token[0].s->next_secondary = NULL; + for (; next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, "C") == 0) + { + trxn.token[0].s->carbon = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "H") == 0) + { + trxn.token[0].s->h = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "O") == 0) + { + trxn.token[0].s->o = next_elt->coef; + } + } +/* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc(count_trxn + 1); +/* + * Copy reaction to reaction for species + */ + trxn_copy(trxn.token[0].s->rxn); + s_ptr = trxn.token[0].s; +/* + * Default gamma data + */ + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + if (equal(s_ptr->z, 0.0, TOL) == TRUE) + { + s_ptr->gflag = 0; /* Uncharged */ + s_ptr->dhb = 0.1; + } + else + { + s_ptr->gflag = 1; /* Davies */ + } +/* + * Set type for species + */ + if (strcmp(trxn.token[0].s->name, "H+") == 0) + { + s_hplus = trxn.token[0].s; + s_hplus->type = HPLUS; + } + else if (strcmp(trxn.token[0].s->name, "H3O+") == 0) + { + s_h3oplus = trxn.token[0].s; + s_h3oplus->type = HPLUS; + } + else if (strcmp(trxn.token[0].s->name, "e-") == 0) + { + s_eminus = trxn.token[0].s; + s_eminus->type = EMINUS; + s_eminus->gflag = 3; /* Always 1 */ + } + else if (strcmp(trxn.token[0].s->name, "H2O") == 0) + { + s_h2o = trxn.token[0].s; + s_h2o->type = H2O; + s_h2o->gflag = 3; /* Always 1 */ + } + else if (strstr(trxn.token[0].s->name, "(s)") != NULL) + { + trxn.token[0].s->type = SOLID; + } + else if (strcmp(trxn.token[0].s->name, "H2") == 0) + { + trxn.token[0].s->type = AQ; + s_h2 = trxn.token[0].s; + } + else if (strcmp(trxn.token[0].s->name, "O2") == 0) + { + trxn.token[0].s->type = AQ; + s_o2 = trxn.token[0].s; + } + else + { + trxn.token[0].s->type = AQ; + } + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_use(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, mix, irreversible reaction, and pure phases to use + * in reaction calculation + */ + int i, l, n_user, return_value; + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH];; +/* + * Read "use" + */ + ptr = line; + copy_token(token, &ptr, &l); +/* + * Read keyword + */ + copy_token(token, &ptr, &l); + check_key(token); + if (next_keyword != Keywords::KEY_SOLUTION && + next_keyword != Keywords::KEY_MIX && + next_keyword != Keywords::KEY_KINETICS && + next_keyword != Keywords::KEY_REACTION && + next_keyword != Keywords::KEY_REACTION_TEMPERATURE && + next_keyword != Keywords::KEY_REACTION_PRESSURE && + next_keyword != Keywords::KEY_EQUILIBRIUM_PHASES && + next_keyword != Keywords::KEY_EXCHANGE && + next_keyword != Keywords::KEY_SURFACE && + next_keyword != Keywords::KEY_GAS_PHASE && + next_keyword != Keywords::KEY_SOLID_SOLUTIONS) + { + input_error++; + error_msg("Unknown item in USE keyword", CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of use", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (ERROR); + } +/* + * Read number + */ + strcpy(token1, token); + for (;;) + { + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, "%d", &n_user); + if (n_user < 0) + { + error_msg("Number must be a positive integer.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + if (strstr(token, "-") != NULL) + { + error_string = sformatf( + "USE does not accept a range of numbers, %s.", token); + warning_msg(error_string); + error_string = sformatf( + "Only %s %d will be used in the batch-reaction calculation.", + token1, n_user); + warning_msg(error_string); + error_string = sformatf( + "NOTE--USE is not needed for ADVECTION and TRANSPORT calculations."); + warning_msg(error_string); + + } + break; + } + else if (i == EMPTY) + { + error_string = sformatf( "No number given, 1 assumed."); + warning_msg(error_string); + n_user = 1; + break; + } + else if (token[0] == 'N' || token[0] == 'n') + { + n_user = -2; + break; + } + } + switch (next_keyword) + { + case Keywords::KEY_SOLUTION: /* Solution */ + use.Set_n_solution_user(n_user); + if (n_user >= 0) + { + use.Set_solution_in(true); + } + else + { + use.Set_solution_in(false); + } + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */ + use.Set_n_pp_assemblage_user(n_user); + if (n_user >= 0) + { + use.Set_pp_assemblage_in(true); + } + else + { + use.Set_pp_assemblage_in(false); + } + break; + case Keywords::KEY_REACTION: /* Reaction */ + use.Set_n_reaction_user(n_user); + if (n_user >= 0) + { + use.Set_reaction_in(true); + } + else + { + use.Set_reaction_in(false); + } + break; + case Keywords::KEY_MIX: /* Mix */ + use.Set_n_mix_user(n_user); + if (n_user >= 0) + { + use.Set_mix_in(true); + } + else + { + use.Set_mix_in(false); + } + break; + case Keywords::KEY_EXCHANGE: /* Ex */ + use.Set_n_exchange_user(n_user); + if (n_user >= 0) + { + use.Set_exchange_in(true); + } + else + { + use.Set_exchange_in(false); + } + break; + case Keywords::KEY_SURFACE: /* Surface */ + use.Set_n_surface_user(n_user); + if (n_user >= 0) + { + use.Set_surface_in(true); + } + else + { + use.Set_surface_in(false); + } + break; + case Keywords::KEY_REACTION_TEMPERATURE: /* Temperature */ + use.Set_n_temperature_user(n_user); + if (n_user >= 0) + { + use.Set_temperature_in(true); + } + else + { + use.Set_temperature_in(false); + } + break; + case Keywords::KEY_REACTION_PRESSURE: /* pressure */ + use.Set_n_pressure_user(n_user); + if (n_user >= 0) + { + use.Set_pressure_in(true); + } + else + { + use.Set_pressure_in(false); + } + break; + case Keywords::KEY_GAS_PHASE: /* Gas */ + use.Set_n_gas_phase_user(n_user); + if (n_user >= 0) + { + use.Set_gas_phase_in(true); + } + else + { + use.Set_gas_phase_in(false); + } + break; + case Keywords::KEY_KINETICS: /* Kinetics */ + use.Set_n_kinetics_user(n_user); + if (n_user >= 0) + { + use.Set_kinetics_in(true); + } + else + { + use.Set_kinetics_in(false); + } + break; + case Keywords::KEY_SOLID_SOLUTIONS: /* solid_solutions */ + use.Set_n_ss_assemblage_user(n_user); + if (n_user >= 0) + { + use.Set_ss_assemblage_in(true); + } + else + { + use.Set_ss_assemblage_in(false); + } + break; + default: + input_error++; + error_msg(line_save, CONTINUE); + error_msg("Error in switch for USE.", STOP); + break; + } + return_value = check_line("End of use", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_surface_species(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Read data for surface species, parse equations + */ + int i, j; + int association; + char token[MAX_LENGTH]; + char *ptr; + LDBLE offset; + + struct species *s_ptr; + struct elt_list *next_elt; + struct rxn_token *token_ptr; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "no_check", /* 0 */ + "check", /* 1 */ + "mb", /* 2 */ + "mass_balance", /* 3 */ + "log_k", /* 4 */ + "logk", /* 5 */ + "delta_h", /* 6 */ + "deltah", /* 7 */ + "analytical_expression", /* 8 */ + "a_e", /* 9 */ + "ae", /* 10 */ + "mole_balance", /* 11 */ + "offset", /* 12 */ + "add_logk", /* 13 */ + "add_log_k", /* 14 */ + "add_constant", /* 15 */ + "cd_music", /* 16 */ + "music", /* 17 */ + "delta_v", /* 18 */ + "deltav", /* 19 */ + "vm" + }; + int count_opt_list = 21; + + association = TRUE; + /* + * Read eqn from file and call parser + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + s_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SURFACE_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* no_check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = FALSE; + break; + case 1: /* check */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + s_ptr->check_equation = TRUE; + break; + case 2: /* mb */ + case 3: /* mass_balance */ + case 11: /* mole_balance */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + count_elts = 0; + paren_count = 0; + copy_token(token, &next_char, &i); + s_ptr->mole_balance = string_hsave(token); + ptr = token; + s_ptr->next_secondary = + (struct elt_list *) free_check_null(s_ptr->next_secondary); + get_secondary_in_species(&ptr, 1.0); + s_ptr->next_secondary = elt_list_save(); + /* debug + for (i = 0; i < count_elts; i++) { + output_msg(sformatf("%s\t%f\n", elt_list[i].elt->name, + elt_list[i].coef)); + } + */ + opt_save = OPTION_DEFAULT; + break; + case 4: /* log_k */ + case 5: /* logk */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &s_ptr->logk[0]); + opt_save = OPTION_DEFAULT; + break; + case 6: /* delta_h */ + case 7: /* deltah */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &s_ptr->logk[1], + &s_ptr->original_units); + opt_save = OPTION_DEFAULT; + break; + case 8: /* analytical_expression */ + case 9: /* a_e */ + case 10: /* ae */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(s_ptr->logk[T_A1])); + opt_save = OPTION_DEFAULT; + break; + case 12: /* offset */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (sscanf(next_char, SCANFORMAT, &offset) != 1) + { + error_msg("No offset for log K given", STOP); + } + s_ptr->logk[0] += offset; + opt_save = OPTION_DEFAULT; + break; + case 13: /* add_logk */ + case 14: /* add_log_k */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) + { + input_error++; + error_string = sformatf( + "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + s_ptr->add_logk[s_ptr->count_add_logk].name = string_hsave(token); + /* read coef */ + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + s_ptr->add_logk[s_ptr->count_add_logk].coef = 1; + } + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 15: /* add_constant */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (s_ptr->count_add_logk == 0) + { + s_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + else + { + s_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (size_t) ((s_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (s_ptr->add_logk == NULL) + malloc_error(); + } + i = sscanf(next_char, SCANFORMAT, + &s_ptr->add_logk[s_ptr->count_add_logk].coef); + if (i <= 0) + { + input_error++; + error_string = sformatf( + "Expected the constant to add for log_K definition."); + error_msg(error_string, CONTINUE); + break; + } + /* set name */ + s_ptr->add_logk[s_ptr->count_add_logk].name = + string_hsave("XconstantX"); + /* read coef */ + s_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 16: /* cd_music */ + case 17: /* music */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + for (j = 0; j < 5; j++) + { + if (copy_token(token, &next_char, &i) == EMPTY) + break; + if (sscanf(token, SCANFORMAT, &s_ptr->cd_music[j]) != 1) + break; + } + s_ptr->dz[0] = s_ptr->cd_music[0] + s_ptr->cd_music[3] * s_ptr->cd_music[4]; + s_ptr->dz[1] = s_ptr->cd_music[1] + (1 - s_ptr->cd_music[3]) * s_ptr->cd_music[4]; + s_ptr->dz[2] = s_ptr->cd_music[2]; + for (j = 0; j < 3; j++) + { + s_ptr->rxn->dz[j] = s_ptr->dz[j]; + } + opt_save = OPTION_DEFAULT; + break; + case 18: /* delta_v */ + case 19: /* deltav */ + case 20: /* vm, molar volume */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_v_only(next_char, &s_ptr->logk[vm0], + &s_ptr->original_deltav_units); + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: + /* + * Get surface species information and parse equation + */ + s_ptr = NULL; + if (parse_eq(line, &next_elt, association) == ERROR) + { + parse_error++; + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } + /* + * Get pointer to each species in the reaction, store new species if necessary + */ + trxn.token[0].s = + s_store(trxn.token[0].name, trxn.token[0].z, TRUE); + for (i = 1; i < count_trxn; i++) + { + trxn.token[i].s = + s_store(trxn.token[i].name, trxn.token[i].z, FALSE); + } + /* + * Save element list and carbon, hydrogen, and oxygen in species + */ + trxn.token[0].s->next_elt = next_elt; + for (; next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, "C") == 0) + { + trxn.token[0].s->carbon = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "H") == 0) + { + trxn.token[0].s->h = next_elt->coef; + } + if (strcmp(next_elt->elt->name, "O") == 0) + { + trxn.token[0].s->o = next_elt->coef; + } + } + /* + * Find coefficient of surface in rxn, store in equiv + */ + trxn.token[0].s->equiv = 0.0; + for (i = 1; i < count_trxn; i++) + { + if (trxn.token[i].s->type == SURF) + { + trxn.token[0].s->equiv = trxn.token[i].coef; + } + } + if (trxn.token[0].s->equiv == 0.0) + trxn.token[0].s->equiv = 1.0; + /* + * Malloc space for species reaction + */ + trxn.token[0].s->rxn = rxn_alloc(count_trxn + 1); + /* + * Copy reaction to reaction for species + */ + token_ptr = trxn.token[0].s->rxn->token; + for (i = 0; i < count_trxn; i++) + { + token_ptr[i].s = trxn.token[i].s; + token_ptr[i].coef = trxn.token[i].coef; + } + token_ptr[i].s = NULL; + /* + * Set type for species + */ + trxn.token[0].s->type = SURF; + s_ptr = trxn.token[0].s; + /* + * Read gamma data + */ + s_ptr->gflag = 6; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_surf(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Reads surface data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int count_comps, count_charge; + int n_user, n_user_end; + LDBLE conc, area, grams, thickness; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH], name[MAX_LENGTH]; + struct surface *surface_ptr; + struct surface_charge *charge_ptr; + struct surface_comp *comp_ptr; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "equilibrate", /* 0 */ + "equil", /* 1 */ + "diff", /* 2 */ + "diffuse_layer", /* 3 */ + "no_edl", /* 4 */ + "no_electrostatic", /* 5 */ + "only_counter_ions", /* 6 */ + "donnan", /* 7 */ + "cd_music", /* 8 */ + "capacitances", /* 9 */ + "sites", /* 10 */ + "sites_units", /* 11 */ + "constant_capacitance", /* 12 */ + "ccm", /* 13 */ + "equilibrium", /* 14 */ + "site_units" /* 15 */ + }; + int count_opt_list = 16; + /* + * kin_surf is for Surfaces, related to kinetically reacting minerals + * they are defined if "sites" is followed by mineral name: + * Surf_wOH Manganite [equilibrium_phases or kinetics] 0.25 4000 + * ^Name mineral ^switch ^prop.factor ^m2/mol + */ + /* + * Read surface number and description + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + /* + * Find space for surface data + */ + surface_ptr = surface_search(n_user, &n, FALSE); + if (surface_ptr != NULL) + { + surface_free(&surface[n]); + } + else + { + n = count_surface++; + space((void **) ((void *) &surface), count_surface, &max_surface, + sizeof(struct surface)); + } + /* + * Initialize + */ + surface_init(&(surface[n]), n_user, n_user_end, description); + free_check_null(description); + + if (use.Get_surface_in() == FALSE) + { + use.Set_surface_in(true); + use.Set_n_surface_user(n_user); + } + /* + * Read surface data + */ + count_charge = 0; + count_comps = 0; + return_value = UNKNOWN; + comp_ptr = NULL; + charge_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SURFACE keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* equilibrate */ + case 1: /* equil */ + case 14: /* equilibrium */ + for (;;) + { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) + { + sscanf(token, "%d", &surface[n].n_solution); + surface[n].solution_equilibria = TRUE; + break; + } + if (i == EMPTY) + { + error_msg + ("Expected a solution number with which to equilibrate surface.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + break; + case 2: /* diffuse_layer */ + case 3: + surface[n].thickness = 1e-8; + surface[n].dl_type = BORKOVEK_DL; + sscanf(next_char, SCANFORMAT, &surface[n].thickness); + /* surface[n].thickness = thickness; + } + */ break; + case 4: /* no electrostatic */ + case 5: + /*surface[n].edl = FALSE; */ + surface[n].type = NO_EDL; + break; + case 6: + surface[n].only_counter_ions = TRUE; + break; + case 7: /* donnan for DL conc's */ + surface[n].dl_type = DONNAN_DL; + /*surface[n].diffuse_layer = TRUE; */ + thickness = 0.0; + for (;;) + { + i = copy_token(token, &next_char, &l); + if (i == DIGIT) + { + sscanf(token, SCANFORMAT, &surface[n].thickness); + thickness = 1; + continue; + } + else if (i != EMPTY) + { + if (token[0] == 'D' || token[0] == 'd') + { + if (thickness != 0) + { + error_msg + ("You must enter EITHER thickness OR Debye lengths (1/k),\n and relative DDL viscosity, DDL limit.\nCorrect is (for example): -donnan 1e-8 viscosity 0.5\n or (default values): -donnan debye_lengths 1 viscosity 1 limit 0.8", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + j = copy_token(token1, &next_char, &l); + if (j == DIGIT) + { + sscanf(token1, SCANFORMAT, + &surface[n].debye_lengths); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number of Debye lengths (1/k).", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else if (token[0] == 'V' || token[0] == 'v') + { + j = copy_token(token1, &next_char, &l); + if (j == DIGIT) + { + sscanf(token1, SCANFORMAT, + &surface[n].DDL_viscosity); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number for relative DDL viscosity.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else if (token[0] == 'L' || token[0] == 'l') + { + j = copy_token(token1, &next_char, &l); + if (j == DIGIT) + { + sscanf(token1, SCANFORMAT, &surface[n].DDL_limit); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number for maximum of DDL water as fraction of bulk water.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else + { + error_msg + ("Expected diffuse layer thickness (m) or Debye lengths (1/k) for \n\tcalculating the thickness, and relative DDL viscosity and DDL limit.\nCorrect is (for example): -donnan 1e-8 visc 0.5\n or (default values): -donnan debye_lengths 1 visc 1 lim 0.8", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else + break; + } + break; + case 8: /* cd_music */ + /*surface[n].edl = FALSE; */ + surface[n].type = CD_MUSIC; + break; + case 9: /* capacitances */ + /* + * Read capacitance for CD_MUSIC + */ + if (charge_ptr == NULL) + { + error_msg + ("Surface component has not been defined for capacitances.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + copy_token(token1, &next_char, &l); + if (sscanf(token1, SCANFORMAT, &grams) == 1) + { + charge_ptr->capacitance[0] = grams; + } + copy_token(token1, &next_char, &l); + if (sscanf(token1, SCANFORMAT, &grams) == 1) + { + charge_ptr->capacitance[1] = grams; + } + break; + case 10: /* sites */ + case 11: /* sites_units */ + case 15: /* site_units */ + j = copy_token(token1, &next_char, &l); + if (token1[0] == 'A' || token1[0] == 'a') + { + surface[n].sites_units = SITES_ABSOLUTE; + } + else if (token1[0] == 'D' || token1[0] == 'd') + { + surface[n].sites_units = SITES_DENSITY; + } + else + { + error_msg + ("Character string expected to be 'Absolute' or 'Density' to define the units of the first item in the definition of a surface component.\n", + CONTINUE); + input_error++; + break; + } + break; + case 12: /* constant_capacitance */ + case 13: /* ccm */ + surface[n].type = CCM; + copy_token(token1, &next_char, &l); + if (sscanf(token1, SCANFORMAT, &(charge_ptr->capacitance[0])) != 1) + { + error_msg("Expected capacitance for constant_capacitance model.\n", + CONTINUE); + input_error++; + break; + } + + /* constant capacitance model not implemented yet */ + error_msg("Constant capacitance model not implemented.", CONTINUE); + input_error++; + + break; + case OPTION_DEFAULT: + /* + * Read surface component + */ + ptr = line; + i = copy_token(token, &ptr, &l); + if (i != UPPER && token[0] != '[') + { + error_msg + ("Expected surface name to begin with a capital letter.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + /* + * Realloc space for new surface component + */ + surface[n].comps = + (struct surface_comp *) PHRQ_realloc(surface[n].comps, + (size_t) (count_comps + + 1) * + sizeof(struct + surface_comp)); + if (surface[n].comps == NULL) + malloc_error(); + surface[n].comps[count_comps].formula = string_hsave(token); + surface[n].comps[count_comps].formula_totals = NULL; + surface[n].comps[count_comps].formula_z = 0.0; + surface[n].comps[count_comps].moles = 0; + surface[n].comps[count_comps].la = 0; + surface[n].comps[count_comps].charge = 0; + surface[n].comps[count_comps].cb = 0; + surface[n].comps[count_comps].phase_name = NULL; + surface[n].comps[count_comps].phase_proportion = 0; + surface[n].comps[count_comps].rate_name = NULL; + comp_ptr = &(surface[n].comps[count_comps]); + surface[n].comps[count_comps].Dw = 0; + i = copy_token(token1, &ptr, &l); + if (i == DIGIT) + { + /* + * Read surface concentration + */ + /* surface concentration is read directly */ + if (sscanf(token1, SCANFORMAT, &conc) < 1) + { + error_msg("Expected number of surface sites in moles.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + surface[n].comps[count_comps].moles = conc; + /* + * Read equilibrium phase name or kinetics rate name + */ + } + else if (i != EMPTY) + { + + /* surface conc. is related to mineral or kinetics */ + surface[n].comps[count_comps].phase_name = + string_hsave(token1); + j = copy_token(token1, &ptr, &l); + + /* read optional 'equilibrium_phases' or 'kinetics' */ + if (j == DIGIT) + { + surface[n].related_phases = TRUE; + } + else + { + if (token1[0] == 'K' || token1[0] == 'k') + { + surface[n].comps[count_comps].rate_name = + surface[n].comps[count_comps].phase_name; + surface[n].comps[count_comps].phase_name = NULL; + surface[n].related_rate = TRUE; + } + else if (token1[0] == 'E' || token1[0] == 'e') + { + surface[n].related_phases = TRUE; + surface[n].comps[count_comps].rate_name = NULL; + } + else + { + error_msg + ("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate surface to mineral or kinetic reaction.\n", + CONTINUE); + input_error++; + break; + } + j = copy_token(token1, &ptr, &l); + } + + /* read proportion */ + if (j != DIGIT) + { + error_msg + ("Expected a coefficient to relate surface to mineral or kinetic reaction.\n", + CONTINUE); + input_error++; + break; + } + sscanf(token1, SCANFORMAT, + &surface[n].comps[count_comps].phase_proportion); + /* real conc must be defined in tidy_model */ + conc = 1.0; + } + else + { + error_msg + ("Expected concentration of surface, mineral name, or kinetic reaction name.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + /* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + ptr1 = token; + get_elts_in_species(&ptr1, conc); + + /* + * save formula for adjusting number of exchange sites + */ + + ptr1 = token; + get_token(&ptr1, token1, + &surface[n].comps[count_comps].formula_z, &l); + surface[n].comps[count_comps].formula_totals = elt_list_save(); + surface[n].comps[count_comps].totals = elt_list_save(); + /* + * Search for charge structure + */ + ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + ptr1[0] = '\0'; + for (i = 0; i < count_charge; i++) + { + if (strcmp(surface[n].charge[i].name, name) == 0) + break; + } + if (i >= count_charge) + { + surface[n].charge = + (struct surface_charge *) PHRQ_realloc(surface[n].charge, + (size_t) + (count_charge + + 1) * + sizeof(struct + surface_charge)); + if (surface[n].charge == NULL) + malloc_error(); + i = count_charge; + surface[n].charge[i].name = string_hsave(name); + if (surface[n].comps[count_comps].phase_name == NULL + && surface[n].comps[count_comps].rate_name == NULL) + { + surface[n].charge[i].specific_area = 600.0; + surface[n].charge[i].grams = 0.0; + } + else + { + surface[n].charge[i].specific_area = 0.0; + surface[n].charge[i].grams = 1.0; + } + surface[n].charge[i].charge_balance = 0.0; + surface[n].charge[i].mass_water = 0.0; + surface[n].charge[i].diffuse_layer_totals = NULL; + surface[n].charge[i].count_g = 0; + surface[n].charge[i].g = NULL; + surface[n].charge[i].la_psi = 0; + surface[n].charge[i].la_psi1 = 0; + surface[n].charge[i].la_psi2 = 0; + surface[n].charge[i].psi = 0; + surface[n].charge[i].psi1 = 0; + surface[n].charge[i].psi2 = 0; + surface[n].charge[i].capacitance[0] = 1.0; + surface[n].charge[i].capacitance[1] = 5.0; + surface[n].charge[i].sigma0 = 0; + surface[n].charge[i].sigma1 = 0; + surface[n].charge[i].sigma2 = 0; + surface[n].charge[i].sigmaddl = 0; + count_charge++; + } + charge_ptr = &(surface[n].charge[i]); + surface[n].comps[count_comps].charge = i; + count_comps++; + /* + * Read surface area (m2/g) + */ + copy_token(token1, &ptr, &l); + if (sscanf(token1, SCANFORMAT, &area) == 1) + { + surface[n].charge[i].specific_area = area; + } + else + { + break; + } + /* + * Read grams of solid (g) + */ + copy_token(token1, &ptr, &l); + if (sscanf(token1, SCANFORMAT, &grams) == 1) + { + surface[n].charge[i].grams = grams; + } + /* read Dw */ + copy_token(token1, &ptr, &l); + str_tolower(token1); + if (strcmp(token1, "dw") == 0) + { + j = copy_token(token1, &ptr, &l); + if (j != DIGIT) + { + error_msg + ("Expected surface diffusion coefficient (m2/s).\n", + CONTINUE); + input_error++; + break; + } + else + { + sscanf(token1, SCANFORMAT, + &surface[n].comps[count_comps - 1].Dw); + if (surface[n].comps[count_comps - 1].Dw > 0) + { + surface[n].transport = TRUE; + if (surface[n].related_rate == TRUE + || surface[n].related_phases == TRUE) + { + error_msg + ("Can't transport surfaces related to phases or rates (yet).", + CONTINUE); + input_error++; + } + } + break; + } + } + break; + + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + surface[n].count_comps = count_comps; + surface[n].count_charge = count_charge; + + /* sort charge */ + qsort(surface[n].charge, + (size_t) surface[n].count_charge, + (size_t) sizeof(struct surface_charge), surface_charge_compare); + + /* renumber charge variable in comps */ + for (i = 0; i < surface[n].count_comps; i++) + { + char * temp_formula = string_duplicate(surface[n].comps[i].formula); + ptr = temp_formula; + copy_token(token, &ptr, &l); + ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + ptr1[0] = '\0'; + for (j = 0; j < surface[n].count_charge; j++) + { + if (strcmp(surface[n].charge[j].name, name) == 0) + { + surface[n].comps[i].charge = j; + break; + } + } + free_check_null(temp_formula); + assert(j < surface[n].count_charge); + } + + /* + * copy Dw > 0 to all comps with the same charge structure, check edl & dif for surface transport + */ + if (surface[n].transport == TRUE) + { + /* + if (surface[n].edl == FALSE || surface[n].diffuse_layer == FALSE) { + surface[n].edl = TRUE; + surface[n].diffuse_layer = TRUE; + warning_msg("Can't transport without edl and diffuse layer, set to true"); + } + */ + if (surface[n].type <= NO_EDL) + { + input_error++; + error_msg + ("Must use default Dzombak and Morel or -cd_music for surface transport.", + CONTINUE); + } + if (surface[n].dl_type <= NO_DL) + { + input_error++; + error_msg + ("Must use -donnan or -diffuse_layer for surface transport.", + CONTINUE); + } + for (i = 0; i < count_comps; i++) + { + if (surface[n].comps[i].Dw > 0) + { + for (j = 0; j < count_comps; j++) + { + if (surface[n].comps[j].charge == + surface[n].comps[i].charge) + surface[n].comps[j].Dw = surface[n].comps[i].Dw; + } + } + } + } + /* + * Make sure surface area is defined + */ + /*if (surface[n].edl == TRUE) { */ + if (surface[n].type == DDL || surface[n].type == CD_MUSIC) + { + for (i = 0; i < count_charge; i++) + { + if (surface[n].charge[i].grams * + surface[n].charge[i].specific_area <= 0) + { + error_string = sformatf( "Surface area not defined for %s.\n", + surface[n].charge[i].name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } + /* + * Logical checks + */ + if (surface[n].type == UNKNOWN_DL) + { + error_string = sformatf( "Unknown surface type.\n"); + error_msg(error_string, CONTINUE); + input_error++; + } + else if (surface[n].type == NO_EDL) + { + if (surface[n].dl_type != NO_DL) + { + error_string = sformatf( + "No electrostatic term calculations do not allow calculation of the diffuse layer composition.\n"); + warning_msg(error_string); + surface[n].dl_type = NO_DL; + } + } + else if (surface[n].type == DDL) + { + /* all values of dl_type are valid */ + } + else if (surface[n].type == CD_MUSIC) + { + if (surface[n].dl_type == BORKOVEK_DL) + { + error_string = sformatf( + "Borkovec and Westall diffuse layer calculation is not allowed with a CD_MUSIC surface.\n\tUsing Donnan diffuse layer calculation."); + warning_msg(error_string); + surface[n].dl_type = DONNAN_DL; + } + if (surface[n].debye_lengths > 0) + { + error_msg + ("Variable DDL thickness is not permitted in CD_MUSIC. Fix DDL thickness\n\tfor example (default value): -donnan 1e-8", + CONTINUE); + input_error++; + } + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_surface_master_species(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Reads master species data from data file or input file + */ + int l, return_value; + char *ptr, *ptr1; + LDBLE l_z; + struct master *m_ptr; + struct species *s_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + int opt, opt_save; + char *next_char; + const char *opt_list[] = { + "capacitance", /* 0 */ + "cd_music_capacitance" /* 1 */ + }; + int count_opt_list = 0; + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + m_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SURFACE_MASTER_SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: + /* + * Get "element" name with valence, allocate space, store + */ + ptr = line; + /* + * Get element name and save pointer to character string + */ + if (copy_token(token, &ptr, &l) != UPPER && token[0] != '[') + { + parse_error++; + error_msg("Reading element for master species.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + replace("(+", "(", token); + /* + * Delete master if it exists + */ + master_delete(token); + /* + * Increase pointer array, if necessary, and malloc space + */ + if (count_master + 4 >= max_master) + { + space((void **) ((void *) &master), count_master + 4, + &max_master, sizeof(struct master *)); + } + /* + * Save values in master and species structure for surface sites + */ + master[count_master] = master_alloc(); + master[count_master]->type = SURF; + master[count_master]->elt = element_store(token); + m_ptr = master[count_master]; + if (copy_token(token, &ptr, &l) != UPPER && token[0] != '[') + { + parse_error++; + error_msg("Reading surface master species name.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + s_ptr = s_search(token); + if (s_ptr != NULL) + { + master[count_master]->s = s_ptr; + } + else + { + ptr1 = token; + get_token(&ptr1, token1, &l_z, &l); + master[count_master]->s = s_store(token1, l_z, FALSE); + } + master[count_master]->primary = TRUE; + strcpy(token, master[count_master]->elt->name); + count_master++; + /* + * Save values in master and species structure for surface psi + */ + strcpy(token1, token); + replace("_", " ", token1); + ptr1 = token1; + copy_token(token, &ptr1, &l); + strcat(token, "_psi"); + add_psi_master_species(token); + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_psi_master_species(char *token) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + struct master *master_ptr; + char *ptr; + char token1[MAX_LENGTH]; + int i, n, plane; + + strcpy(token1, token); + for (plane = SURF_PSI; plane <= SURF_PSI2; plane++) + { + strcpy(token, token1); + switch (plane) + { + case SURF_PSI: + break; + case SURF_PSI1: + strcat(token, "b"); + break; + case SURF_PSI2: + strcat(token, "d"); + break; + } + master_ptr = master_search(token, &n); + if (master_ptr == NULL) + { + master[count_master] = master_alloc(); + master[count_master]->type = plane; + master[count_master]->elt = element_store(token); + s_ptr = s_search(token); + if (s_ptr != NULL) + { + master[count_master]->s = s_ptr; + } + else + { + master[count_master]->s = s_store(token, 0.0, FALSE); + } + count_elts = 0; + paren_count = 0; + ptr = token; + get_elts_in_species(&ptr, 1.0); + master[count_master]->s->next_elt = elt_list_save(); + master[count_master]->s->type = plane; + master[count_master]->primary = TRUE; + master[count_master]->s->rxn = rxn_alloc(3); + /* + * Define reaction for psi + */ + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + master[count_master]->s->rxn->logk[i] = 0.0; + } + master[count_master]->s->rxn->token[0].s = + master[count_master]->s; + master[count_master]->s->rxn->token[0].coef = -1.0; + master[count_master]->s->rxn->token[1].s = + master[count_master]->s; + master[count_master]->s->rxn->token[1].coef = 1.0; + master[count_master]->s->rxn->token[2].s = NULL; + count_master++; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_title(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads title for simulation + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr, *ptr1; + int l, title_x_length, line_length; + int return_value; + char token[MAX_LENGTH]; +/* + * Read anything after keyword + */ + ptr = line; + copy_token(token, &ptr, &l); + ptr1 = ptr; + title_x = (char *) free_check_null(title_x); + if (copy_token(token, &ptr, &l) != EMPTY) + { + title_x = string_duplicate(ptr1); + } + else + { + title_x = (char *) PHRQ_malloc(sizeof(char)); + if (title_x == NULL) + malloc_error(); + title_x[0] = '\0'; + } + +/* + * Read additonal lines + */ + for (;;) + { + return_value = check_line("title", TRUE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + break; +/* + * append line to title_x + */ + title_x_length = (int) strlen(title_x); + line_length = (int) strlen(line); + title_x = + (char *) PHRQ_realloc(title_x, + (size_t) (title_x_length + line_length + + 2) * sizeof(char)); + if (title_x == NULL) + malloc_error(); + if (title_x_length > 0) + { + title_x[title_x_length] = '\n'; + title_x[title_x_length + 1] = '\0'; + } + strcat(title_x, line); + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_advection(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads advection information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read advection parameters: + * number of cells; + * number of shifts; + */ + char *ptr; + char *description; + int n_user, n_user_end, i; + + int count_punch, count_print; + int *punch_temp, *print_temp; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "cells", /* 0 */ + "shifts", /* 1 */ + "print", /* 2 */ + "selected_output", /* 3 */ + "punch", /* 4 */ + "print_cells", /* 5 */ + "selected_cells", /* 6 */ + "time_step", /* 7 */ + "timest", /* 8 */ + "output", /* 9 */ + "output_frequency", /* 10 */ + "selected_output_frequency", /* 11 */ + "punch_frequency", /* 12 */ + "print_frequency", /* 13 */ + "punch_cells", /* 14 */ + "initial_time", /* 15 */ + "warning", /* 16 */ + "warnings" /* 17 */ + }; + int count_opt_list = 18; +/* + * Read advection number (not currently used) + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); +/* + * Set use data + */ + use.Set_advect_in(true); + count_ad_cells = 0; + count_ad_shifts = 0; + print_ad_modulus = 1; + punch_ad_modulus = 1; + count_punch = 0; + count_print = 0; + punch_temp = (int *) PHRQ_malloc(sizeof(int)); + if (punch_temp == NULL) + malloc_error(); + print_temp = (int *) PHRQ_malloc(sizeof(int)); + if (print_temp == NULL) + malloc_error(); +/* + * Read lines + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in ADVECTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* cells */ + sscanf(next_char, "%d", &count_ad_cells); + opt_save = OPTION_DEFAULT; + break; + case 1: /* shifts */ + sscanf(next_char, "%d", &count_ad_shifts); + opt_save = OPTION_DEFAULT; + break; + case 2: /* print */ + case 5: /* print_cells */ + print_temp = + read_list_ints_range(&next_char, &count_print, TRUE, + print_temp); + opt_save = 2; + break; + case 3: /* selected_output */ + case 11: /* selected_output_frequency */ + case 12: /* punch_frequency */ + sscanf(next_char, "%d", &punch_ad_modulus); + opt_save = OPTION_DEFAULT; + if (punch_ad_modulus <= 0) + { + error_string = sformatf( + "Punch frequency must be greater than 0. Frequency set to 1000."); + warning_msg(error_string); + punch_ad_modulus = 1000; + } + break; + case 4: /* punch */ + case 14: /* punch_cells */ + case 6: /* selected_cells */ + punch_temp = + read_list_ints_range(&next_char, &count_punch, TRUE, + punch_temp); + opt_save = 4; + break; + case 7: /* time_step */ + case 8: /* timest */ + sscanf(next_char, SCANFORMAT, &advection_kin_time); + advection_kin_time_defined = TRUE; + opt_save = OPTION_DEFAULT; + break; + case 9: /* output */ + case 10: /* output_frequency */ + case 13: /* print_frequency */ + sscanf(next_char, "%d", &print_ad_modulus); + opt_save = OPTION_DEFAULT; + if (print_ad_modulus <= 0) + { + error_string = sformatf( + "Print frequency must be greater than 0. Frequency set to 1000."); + warning_msg(error_string); + print_ad_modulus = 1000; + } + break; + case 15: /* initial_time */ + sscanf(next_char, SCANFORMAT, &initial_total_time); + opt_save = OPTION_DEFAULT; + break; + case 16: /* warning */ + case 17: /* warnings */ + advection_warnings = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * Fill in data for punch + */ + advection_punch = + (int *) PHRQ_realloc(advection_punch, + (size_t) (count_ad_cells + 1) * sizeof(int)); + if (advection_punch == NULL) + malloc_error(); + if (count_punch != 0) + { + for (i = 0; i < count_ad_cells; i++) + advection_punch[i] = FALSE; + for (i = 0; i < count_punch; i++) + { + if (punch_temp[i] > count_ad_cells || punch_temp[i] < 1) + { + error_string = sformatf( + "Cell number for punch is out of range, %d. Request ignored.", + punch_temp[i]); + warning_msg(error_string); + } + else + { + advection_punch[punch_temp[i] - 1] = TRUE; + } + } + } + else + { + for (i = 0; i < count_ad_cells; i++) + advection_punch[i] = TRUE; + } + punch_temp = (int *) free_check_null(punch_temp); +/* + * Fill in data for print + */ + advection_print = + (int *) PHRQ_realloc(advection_print, + (size_t) (count_ad_cells + 1) * sizeof(int)); + if (advection_print == NULL) + malloc_error(); + if (count_print != 0) + { + for (i = 0; i < count_ad_cells; i++) + advection_print[i] = FALSE; + for (i = 0; i < count_print; i++) + { + if (print_temp[i] > count_ad_cells || print_temp[i] < 1) + { + error_string = sformatf( + "Cell number for print is out of range, %d. Request ignored.", + print_temp[i]); + warning_msg(error_string); + } + else + { + advection_print[print_temp[i] - 1] = TRUE; + } + } + } + else + { + for (i = 0; i < count_ad_cells; i++) + advection_print[i] = TRUE; + } + print_temp = (int *) free_check_null(print_temp); + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_debug(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads knobs and debugging info + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "iterations", /* 0 */ + "tolerance", /* 1 */ + "step_size", /* 2 */ + "pe_step_size", /* 3 */ + "scale_pure_phases", /* 4 */ + "diagonal_scale", /* 5 */ + "debug_model", /* 6 */ + "debug_prep", /* 7 */ + "debug_set", /* 8 */ + "debug_inverse", /* 9 */ + "logfile", /* 10 */ + "log_file", /* 11 */ + "debug_diffuse_layer", /* 12 */ + "delay_mass_water", /* 13 */ + "convergence_tolerance", /* 14 */ + "numerical_derivatives", /* 15 */ + "tries", /* 16 */ + "try", /* 17 */ + "numerical_fixed_volume", /* 18 */ + "force_numerical_fixed_volume" /* 19 */ + }; + int count_opt_list = 20; +/* + * Read parameters: + * ineq_tol; + * step_size; + * pe_step_size; + * pp_scale; + * diagonal_scale; + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in KNOBS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* iterations */ + sscanf(next_char, "%d", &itmax); + break; + case 1: /* tolerance */ + sscanf(next_char, SCANFORMAT, &ineq_tol); + break; + case 2: /* step_size */ + sscanf(next_char, SCANFORMAT, &step_size); + break; + case 3: /* pe_step_size */ + sscanf(next_char, SCANFORMAT, &pe_step_size); + break; + case 4: /* pp_scale */ + sscanf(next_char, SCANFORMAT, &pp_scale); + break; + case 5: /* diagonal_scale */ + diagonal_scale = get_true_false(next_char, TRUE); + break; + case 6: /* debug_model */ + debug_model = get_true_false(next_char, TRUE); + break; + case 7: /* debug_prep */ + debug_prep = get_true_false(next_char, TRUE); + break; + case 8: /* debug_set */ + debug_set = get_true_false(next_char, TRUE); + break; + case 9: /* debug_inverse */ + debug_inverse = get_true_false(next_char, TRUE); + break; + case 10: /* logfile */ + case 11: /* log_file */ + pr.logfile = get_true_false(next_char, TRUE); + if (phast == TRUE) + { + pr.logfile = FALSE; + warning_msg("PHREEQC log file is disabled in PHAST"); + } + phrq_io->Set_log_on(pr.logfile == TRUE); + break; + case 12: /* debug_diffuse_layer */ + debug_diffuse_layer = get_true_false(next_char, TRUE); + break; + case 13: /* delay_mass_water */ + delay_mass_water = get_true_false(next_char, TRUE); + break; + case 14: /* convergence_tolerance */ + { + LDBLE ct; + sscanf(next_char, SCANFORMAT, &ct); + convergence_tolerance = ct; + //if (punch.high_precision == TRUE) + //{ + // if (ct < 1e-12) + // { + // convergence_tolerance = ct; + // } + //} + //else + //{ + // { + // convergence_tolerance = ct; + // } + //} + } + break; + case 15: /* numerical_derivatives */ + numerical_deriv = get_true_false(next_char, TRUE); + break; + case 16: /* tries */ + case 17: /* try */ + sscanf(next_char, "%d", &max_tries); + break; + case 18: /* debug_inverse */ + numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); + break; + case 19: /* debug_inverse */ + force_numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads printing info + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int return_value, opt, l; + char *next_char; + char token[MAX_LENGTH]; + LDBLE num; + const char *opt_list[] = { + "reset", /* 0 */ + "gas_phase", /* 1 */ + "pure_phase", /* 2 */ + "surface", /* 3 */ + "exchange", /* 4 */ + "totals", /* 5 */ + "eh", /* 6 */ + "species", /* 7 */ + "saturation_indices", /* 8 */ + "si", /* 9 same a 8 */ + "reaction", /* 10 irrev, not used, pr.use */ + "mix", /* 11 */ + "use", /* 12 */ + "selected_output", /* 13 */ + "equilibrium_phases", /* 14 same as 2 */ + "equilibria", /* 15 same as 2 */ + "equilibrium", /* 16 same as 2 */ + "pure", /* 17 same as 2 */ + "other", /* 18 same as 12 */ + "status", /* 19 */ + "inverse", /* 20 */ + "kinetics", /* 21 */ + "dump", /* 22 */ + "user_print", /* 23 */ + "user_pr", /* 24 */ + "solid_solution", /* 25 */ + "solid_solutions", /* 26 */ + "inverse_modeling", /* 27 */ + "headings", /* 28 */ + "heading", /* 29 */ + "user_graph", /* 30 */ + "echo_input", /* 31 */ + "warning", /* 32 */ + "warnings", /* 33 */ + "initial_isotopes", /* 34 */ + "isotope_ratios", /* 35 */ + "isotope_alphas", /* 36 */ + "censor_species", /* 37 */ + "alkalinity", /* 38 */ + "equilibrium_phase" /* 39 */ + }; + + int count_opt_list = 40; + int value; +/* + * Read flags: + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in PRINT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* reset */ + value = get_true_false(next_char, TRUE); + pr.kinetics = value; + pr.gas_phase = value; + pr.pp_assemblage = value; + pr.surface = value; + pr.exchange = value; + pr.totals = value; + pr.eh = value; + pr.species = value; + pr.saturation_indices = value; + pr.irrev = value; + pr.mix = value; + pr.reaction = value; + pr.use = value; + pr.inverse = value; + pr.user_print = value; + pr.ss_assemblage = value; + pr.headings = value; + pr.initial_isotopes = value; + pr.isotope_ratios = value; + pr.isotope_alphas = value; + pr.echo_input = value; + break; + case 1: /* gas_phase */ + pr.gas_phase = get_true_false(next_char, TRUE); + break; + case 2: /* pure_phase */ + case 14: /* equilibrium_phases */ + case 15: /* equilibria */ + case 16: /* equilibrium */ + case 17: /* pure */ + case 39: /* equilibrium_phase */ + pr.pp_assemblage = get_true_false(next_char, TRUE); + break; + case 3: /* surface */ + pr.surface = get_true_false(next_char, TRUE); + break; + case 4: /* exchange */ + pr.exchange = get_true_false(next_char, TRUE); + break; + case 5: /* totals */ + pr.totals = get_true_false(next_char, TRUE); + break; + case 6: /* eh */ + pr.eh = get_true_false(next_char, TRUE); + break; + case 7: /* species */ + pr.species = get_true_false(next_char, TRUE); + break; + case 8: + case 9: /* saturation_indices */ + pr.saturation_indices = get_true_false(next_char, TRUE); + break; + case 10: /* reaction, not used, pr.use controls */ + pr.irrev = get_true_false(next_char, TRUE); + break; + case 11: /* mix, not used, pr.use controls */ + pr.mix = get_true_false(next_char, TRUE); + break; + case 12: /* use */ + case 18: /* other */ + pr.use = get_true_false(next_char, TRUE); + break; + case 13: /* selected_output */ + pr.punch = get_true_false(next_char, TRUE); + phrq_io->Set_punch_on(pr.punch == TRUE); + break; + case 19: /* status */ + { + int j; + pr.status = get_true_false(next_char, TRUE); + j = copy_token(token, &next_char, &l); + if (j == UPPER || j == LOWER) + { + j = copy_token(token, &next_char, &l); + } + if (j == DIGIT) + { + char * tptr = token; + get_num(&tptr, &num); + status_interval = (int) floor(num); + } + } + if (status_interval < 0) + status_interval = 0; + break; + case 20: /* inverse */ + case 27: /* inverse_modeling */ + pr.inverse = get_true_false(next_char, TRUE); + break; + case 21: /* kinetics */ + pr.kinetics = get_true_false(next_char, TRUE); + break; + case 22: /* dump */ + pr.dump = get_true_false(next_char, TRUE); + phrq_io->Set_dump_on(pr.dump == TRUE); + break; + case 23: /* user_print */ + case 24: /* user_pr */ + pr.user_print = get_true_false(next_char, TRUE); + break; + case 25: /* solid_solution */ + case 26: /* solid_solutions */ + pr.ss_assemblage = get_true_false(next_char, TRUE); + break; + case 28: /* headings */ + case 29: /* heading */ + pr.headings = get_true_false(next_char, TRUE); + break; + case 30: /* user_graph */ + pr.user_graph = get_true_false(next_char, TRUE); + break; + case 31: /* echo_input */ + pr.echo_input = get_true_false(next_char, TRUE); + break; + case 32: /* warning */ + case 33: /* warnings */ + sscanf(next_char, "%d", &pr.warnings); + break; + case 34: /* initial_isotopes */ + pr.initial_isotopes = get_true_false(next_char, TRUE); + break; + case 35: /* isotope_ratios */ + pr.isotope_ratios = get_true_false(next_char, TRUE); + break; + case 36: /* isotope_alphas */ + pr.isotope_alphas = get_true_false(next_char, TRUE); + break; + case 37: /* censor_species */ + if (copy_token(token, &next_char, &l) != EMPTY) + { + sscanf(token, SCANFORMAT, &censor); + } + else + { + censor = 0; + } + break; + case 38: /* alkalinity */ + pr.alkalinity = get_true_false(next_char, TRUE); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +/* + * Utilitity routines for read + */ +/* ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_key(const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check if string begins with a keyword, returns TRUE or FALSE + * + * Arguments: + * *str is pointer to character string to be checked for keywords + * Returns: + * TRUE, + * FALSE. + */ + char *ptr; + std::string stdtoken; + char * token1; + token1 = string_duplicate(str); + + ptr = token1; + int j = copy_token(stdtoken, &ptr); + Utilities::str_tolower(stdtoken); + std::string key(stdtoken); + + if (j == EMPTY) + { + next_keyword = Keywords::KEY_END; + } + else + { + next_keyword = Keywords::Keyword_search(key); + } + + free_check_null(token1); + if (next_keyword > 0) + { + return TRUE; + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_units(char *tot_units, int alkalinity, int check_compatibility, + const char *default_units, int print) +/* ---------------------------------------------------------------------- */ +{ +#define NUNITS (sizeof(units) / sizeof(char *)) +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity TRUE if alkalinity, FALSE if any other total, + * check_compatibility TRUE check alk and default units, FALSE otherwise + * default_units character string of default units (check /L, /kg, etc) + * print TRUE print warning messages + * Output: + * tot_units standard form for unit + */ + int i, found; + char *end; + char string[MAX_LENGTH]; + const char *units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + + if ((end = strstr(tot_units, "/l")) != NULL) + { + *(end + 2) = '\0'; + } + if ((end = strstr(tot_units, "/kgs")) != NULL) + { + *(end + 4) = '\0'; + } + if ((end = strstr(tot_units, "/kgw")) != NULL) + { + *(end + 4) = '\0'; + } +/* + * Check if unit in list + */ + found = FALSE; + for (i = 0; i < (int) NUNITS; i++) + { + if (strcmp(tot_units, units[i]) == 0) + { + found = TRUE; + break; + } + } + if (found == FALSE) + { + if (print == TRUE) + { + error_string = sformatf( "Unknown unit, %s.", tot_units); + error_msg(error_string, CONTINUE); + } + return (ERROR); + } + +/* + * Check if units are compatible with default_units + */ + if (check_compatibility == FALSE) + return (OK); +/* + * Special cases for alkalinity + */ + if (alkalinity == TRUE && strstr(tot_units, "Mol") != NULL) + { + if (print == TRUE) + { + error_string = sformatf( + "Alkalinity given in moles, assumed to be equivalents."); + warning_msg(error_string); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == FALSE && strstr(tot_units, "eq") != NULL) + { + if (print == TRUE) + { + error_msg("Only alkalinity can be entered in equivalents.", + CONTINUE); + } + return (ERROR); + } +/* + * See if default_units are compatible with tot_units + */ + if (strstr(default_units, "/l") && strstr(tot_units, "/l")) + return (OK); + if (strstr(default_units, "/kgs") && strstr(tot_units, "/kgs")) + return (OK); + if (strstr(default_units, "/kgw") && strstr(tot_units, "/kgw")) + return (OK); + + strcpy(string, default_units); + replace("kgs", "kg solution", string); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", string); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", string); + replace("Mol", "mol", string); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); + if (print == TRUE) + { + error_string = sformatf( + "Units for master species, %s, are not compatible with default units, %s.", + tot_units, string); + error_msg(error_string, CONTINUE); + } + return (ERROR); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +find_option(const char *item, int *n, const char **list, int count_list, int exact) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares a string value to match beginning letters of a list of options + * + * Arguments: + * item entry: pointer to string to compare + * n exit: item in list that was matched + * list entry: pointer to list of character values, assumed to + * be lower case + * count_list entry: number of character values in list + * + * Returns: + * OK item matched + * ERROR item not matched + * n -1 item not matched + * i position of match in list + */ + int i; + std::string stdtoken(item); + + Utilities::str_tolower(stdtoken); + for (i = 0; i < count_list; i++) + { + if (exact == TRUE) + { + if (strcmp(list[i], stdtoken.c_str()) == 0) + { + *n = i; + return (OK); + } + } + else + { + if (strstr(list[i], stdtoken.c_str()) == list[i]) + { + *n = i; + return (OK); + } + } + } + *n = -1; + return (ERROR); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_true_false(char *string, int default_value) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns true unless string starts with "F" or "f" + */ + int l; + char token[MAX_LENGTH]; + char *ptr; + + ptr = string; + + if (copy_token(token, &ptr, &l) == EMPTY) + { + return (default_value); + } + else + { + if (token[0] == 'F' || token[0] == 'f') + { + return (FALSE); + } + } + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_option(const char **opt_list, int count_opt_list, char **next_char) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line and check for options + */ + int j; + int opt; + char *opt_ptr; + std::string stdoption; +/* + * Read line + */ + j = check_line("get_option", FALSE, TRUE, TRUE, FALSE); + if (j == EOF) + { + j = OPTION_EOF; + } + else if (j == KEYWORD) + { + j = OPTION_KEYWORD; + } + else if (j == OPTION) + { + opt_ptr = line; + copy_token(stdoption, &opt_ptr); + if (find_option(&(stdoption.c_str()[1]), &opt, opt_list, count_opt_list, FALSE) == OK) + { + j = opt; + replace(stdoption.c_str(), opt_list[j], line_save); + replace(stdoption.c_str(), opt_list[j], line); + opt_ptr = line; + copy_token(stdoption, &opt_ptr); + *next_char = opt_ptr; + if (pr.echo_input == TRUE) + { + if (!reading_database()) + output_msg(sformatf( "\t%s\n", line_save)); + } + } + else + { + if (!reading_database()) + output_msg(sformatf( "\t%s\n", line_save)); + error_msg("Unknown option.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + j = OPTION_ERROR; + *next_char = line; + } + } + else + { + opt_ptr = line; + copy_token(stdoption, &opt_ptr); + if (find_option(&(stdoption.c_str()[0]), &opt, opt_list, count_opt_list, TRUE) == OK) + { + j = opt; + *next_char = opt_ptr; + } + else + { + j = OPTION_DEFAULT; + *next_char = line; + } + if (pr.echo_input == TRUE) + { + if (!reading_database()) + output_msg(sformatf( "\t%s\n", line_save)); + } + } + return (j); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_rates(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int l, length, line_length, n; + int return_value, opt, opt_save; + char token[MAX_LENGTH]; + struct rate *rate_ptr; + char *description; + int n_user, n_user_end; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; +/* + * Read advection number (not currently used) + */ + n = -1; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + rate_ptr = NULL; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in RATES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPT_1; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read rate name */ + ptr = line; + copy_token(token, &ptr, &l); + rate_ptr = rate_search(token, &n); + if (rate_ptr == NULL) + { + rates = + (struct rate *) PHRQ_realloc(rates, + (size_t) (count_rates + + 1) * + sizeof(struct rate)); + if (rates == NULL) + malloc_error(); + rate_ptr = &rates[count_rates]; + count_rates++; + } + else + { + rate_free(rate_ptr); + } + rate_ptr->new_def = TRUE; + rate_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); + if (rate_ptr->commands == NULL) + malloc_error(); + rate_ptr->commands[0] = '\0'; + rate_ptr->name = string_hsave(token); + rate_ptr->linebase = NULL; + rate_ptr->varbase = NULL; + rate_ptr->loopbase = NULL; + opt_save = OPT_1; + break; + case OPT_1: /* read command */ + if (rate_ptr == NULL) + { + input_error++; + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + opt_save = OPT_1; + break; + } + length = (int) strlen(rate_ptr->commands); + line_length = (int) strlen(line); + rate_ptr->commands = + (char *) PHRQ_realloc(rate_ptr->commands, + (size_t) (length + line_length + + 2) * sizeof(char)); + if (rate_ptr->commands == NULL) + malloc_error(); + rate_ptr->commands[length] = ';'; + rate_ptr->commands[length + 1] = '\0'; + strcat((rate_ptr->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* output_msg(sformatf( "%s", rates[0].commands)); + */ return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_user_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int length, line_length; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end" /* 1 */ + }; + int count_opt_list = 2; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in USER_PRINT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: /* read first command */ + rate_free(user_print); + user_print->new_def = TRUE; + user_print->commands = (char *) PHRQ_malloc(sizeof(char)); + if (user_print->commands == NULL) + malloc_error(); + user_print->commands[0] = '\0'; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + user_print->name = + string_hsave("user defined Basic print routine"); + case OPT_1: /* read command */ + length = (int) strlen(user_print->commands); + line_length = (int) strlen(line); + user_print->commands = + (char *) PHRQ_realloc(user_print->commands, + (size_t) (length + line_length + + 2) * sizeof(char)); + if (user_print->commands == NULL) + malloc_error(); + user_print->commands[length] = ';'; + user_print->commands[length + 1] = '\0'; + strcat((user_print->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* output_msg(sformatf( "%s", rates[0].commands)); + */ return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_user_punch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int length, line_length; + int return_value, opt, opt_save; + std::string stdtoken; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end", /* 1 */ + "heading", /* 2 */ + "headings" /* 3 */ + }; + int count_opt_list = 4; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + user_punch_count_headings = 0; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in USER_PUNCH keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading */ + while (copy_token(stdtoken, &next_char) != EMPTY) + { + user_punch_headings = + (const char **) PHRQ_realloc(user_punch_headings, + (size_t) + (user_punch_count_headings + + 1) * sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + user_punch_headings[user_punch_count_headings] = + string_hsave(stdtoken.c_str()); + user_punch_count_headings++; + } + break; + case OPTION_DEFAULT: /* read first command */ + rate_free(user_punch); + user_punch->new_def = TRUE; + user_punch->commands = (char *) PHRQ_malloc(sizeof(char)); + if (user_punch->commands == NULL) + malloc_error(); + user_punch->commands[0] = '\0'; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + user_punch->name = + string_hsave("user defined Basic punch routine"); + case OPT_1: /* read command */ + length = (int) strlen(user_punch->commands); + line_length = (int) strlen(line); + user_punch->commands = + (char *) PHRQ_realloc(user_punch->commands, + (size_t) (length + line_length + + 2) * sizeof(char)); + if (user_punch->commands == NULL) + malloc_error(); + user_punch->commands[length] = ';'; + user_punch->commands[length + 1] = '\0'; + strcat((user_punch->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +#if defined PHREEQ98 +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_user_graph(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int l, length, line_length, CurveInfonr = 0; + int return_value, opt, opt_save; + char file_name[MAX_LENGTH]; + char token[MAX_LENGTH]; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end", /* 1 */ + "heading", /* 2 */ + "headings", /* 3 */ + "chart_title", /* 4 */ + "axis_titles", /* 5 */ + "axis_scale", /* 6 */ + "initial_solutions", /* 7 */ + "plot_concentration_vs", /* 8 */ + "shifts_as_points", /* 9 */ + "grid_offset", /* 10 */ + "connect_simulations", /* 11 */ + "plot_csv_file" /* 12 */ + }; + int count_opt_list = 13; + int i; + + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ +#ifdef PHREEQ98 + user_graph_count_headings = 0; +#endif + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) opt = opt_save; + + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in USER_GRAPH keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading */ + while (copy_token(token, &next_char, &l) != EMPTY) + { + user_graph_headings = + (char **) PHRQ_realloc(user_graph_headings, + (size_t) (user_graph_count_headings + + 1) * sizeof(char *)); + if (user_graph_headings == NULL) + malloc_error(); + user_graph_headings[user_graph_count_headings] = + string_hsave(token); + user_graph_count_headings++; + } + break; +/*Modifications of read_user_punch to change the chart's appearance */ + case 4: /* chart title */ + copy_title(token, &next_char, &l); + SetChartTitle(token); + break; + case 5: /* axis titles */ + i = 0; + while (copy_title(token, &next_char, &l) != EMPTY) + { + SetAxisTitles(token, i); + i++; + } + break; + case 6: { /* axis scales */ + char *axis = ""; + int j = 0; + float f_min, f_max; f_min = (float) -9.999; + prev_next_char = next_char; + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "x") == token) + axis = "x"; + else if ((strstr(token, "y") == token) && (strstr(token, "y2") != token)) + axis = "y"; + else if ((strstr(token, "s") == token) || (strstr(token, "y2") == token)) + axis = "s"; + else + { + input_error++; + copy_token(token, &prev_next_char, &l); + error_string = sformatf( + "Found '%s', but expect axis type \'x\', \'y\', or \'sy\'.", token); + error_msg(error_string, CONTINUE); + } + while ((j < 4) + && (i = copy_token(token, &next_char, &l)) != EMPTY) + { + str_tolower(token); + if ((i == DIGIT) || (strstr(token, "a") == token)) + SetAxisScale(axis, j, token, FALSE); + else + { + input_error++; + copy_token(token, &prev_next_char, &l); + error_string = sformatf( + "Found '%s', but expect number or 'a(uto)'.", token); + error_msg(error_string, CONTINUE); + } + if (i == DIGIT) + { + if (j == 0) + f_min = (float) atof(token); + else if (j == 1 && fabs(f_min + 9.999) > 1e-3) + { + f_max = (float) atof(token); + if (f_min > f_max) + { + error_string = sformatf( + "Maximum must be larger than minimum of axis_scale, interchanging both for %s axis", axis); + warning_msg(error_string); + SetAxisScale(axis, 0, token, FALSE); + sprintf(token, "%e", f_min); + SetAxisScale(axis, 1, token, FALSE); + } + } + } + j++; /* counter for categories */ + prev_next_char = next_char; + } + if (j == 4) + SetAxisScale(axis, j, 0, + get_true_false(next_char, FALSE)); /* anything else than false turns on log scale */ + } + break; + case 7: + graph_initial_solutions = get_true_false(next_char, FALSE); + break; + case 8: + prev_next_char = next_char; + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "x") == token || strstr(token, "d") == token) + chart_type = 0; + else if (strstr(token, "t") == token) + chart_type = 1; + else + { + input_error++; + copy_token(token, &prev_next_char, &l); + error_string = sformatf( + "Found '%s', but expect plot type: (\'x\' or \'dist\') for distance, (\'t\') for time.", + token); + error_msg(error_string, CONTINUE); + } + break; + case 9: + shifts_as_points = get_true_false(next_char, TRUE); + if (shifts_as_points == TRUE) + chart_type = 0; + else + chart_type = 1; + break; + case 10: +#ifdef PHREEQ98 + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &RowOffset); + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + sscanf(token, "%d", &ColumnOffset); +#endif + break; + case 11: + connect_simulations = get_true_false(next_char, TRUE); + break; + case 12: + string_trim(next_char); + strcpy(file_name, next_char); + if (!OpenCSVFile(file_name)) + { + error_string = sformatf( "Can't open file, %s. Give the full path + name, or copy the file to the working directory.", file_name); + input_error++; + error_msg(error_string, CONTINUE); + } + break; + /* End of modifications */ + case OPTION_DEFAULT: /* read first command */ + rate_free(user_graph); + user_graph->new_def = TRUE; + user_graph->commands = (char *) PHRQ_malloc(sizeof(char)); + if (user_graph->commands == NULL) + malloc_error(); + user_graph->commands[0] = '\0'; + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + user_graph->name = + string_hsave("user defined Basic graph routine"); + case OPT_1: /* read command */ + length = strlen(user_graph->commands); + line_length = strlen(line); + user_graph->commands = + (char *) PHRQ_realloc(user_graph->commands, + (size_t) (length + line_length + + 2) * sizeof(char)); + if (user_graph->commands == NULL) + malloc_error(); + user_graph->commands[length] = ';'; + user_graph->commands[length + 1] = '\0'; + strcat((user_graph->commands), line); + opt_save = OPT_1; + break; + } + + if (return_value == EOF || return_value == KEYWORD) + break; + } +#ifdef PHREEQ98 + for (i = 0; i < user_graph_count_headings; i++) + { + GridHeadings(user_graph_headings[i], i); + } +#endif + return (return_value); +} +#endif + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solid_solutions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solid solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, j, n, l; + int count_s_s, number_s_s, count_comps; + int n_user, n_user_end; + char *ptr; + char *description; + char token[MAX_LENGTH]; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "component", /* 0 */ + "comp", /* 1 */ + "parms", /* 2 */ + "gugg_nondimensional", /* 3 */ + "gugg_kj", /* 4 */ + "activity_coefficients", /* 5 */ + "distribution_coefficients", /* 6 */ + "miscibility_gap", /* 7 */ + "spinodal_gap", /* 8 */ + "critical_point", /* 9 */ + "alyotropic_point", /* 10 */ + "temp", /* 11 */ + "tempk", /* 12 */ + "tempc", /* 13 */ + "thompson", /* 14 */ + "margules", /* 15 */ + "comp1", /* 16 */ + "comp2" /* 17 */ + }; + int count_opt_list = 18; +/* + * Read ss_assemblage number + */ + number_s_s = 0; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); +/* + * Find old ss_assemblage or alloc space for new ss_assemblage + */ + if (ss_assemblage_search(n_user, &n) != NULL) + { + ss_assemblage_free(&ss_assemblage[n]); + } + else + { + n = count_ss_assemblage; + space((void **) ((void *) &ss_assemblage), count_ss_assemblage, + &max_ss_assemblage, sizeof(struct ss_assemblage)); + count_ss_assemblage++; + } +/* + * Initialize + */ + ss_assemblage_init(&(ss_assemblage[n]), n_user, n_user_end, + description); + free_check_null(description); +/* + * Set use data to first read + */ + if (!use.Get_ss_assemblage_in()) + { + use.Set_ss_assemblage_in(true); + use.Set_n_ss_assemblage_user(n_user); + } +/* + * Read solid solutions + */ + count_s_s = 0; + count_comps = 0; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLID_SOLUTIONS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + +/* + * New component + */ + case 0: /* component */ + case 1: /* comp */ + count_comps = ss_assemblage[n].s_s[number_s_s].count_comps++; + ss_assemblage[n].s_s[number_s_s].comps = + (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. + s_s[number_s_s].comps, + (size_t) (count_comps + + 1) * + sizeof(struct s_s_comp)); + if (ss_assemblage[n].s_s[number_s_s].comps == NULL) + malloc_error(); + ss_assemblage[n].s_s[number_s_s].comps[count_comps].initial_moles = 0; + ss_assemblage[n].s_s[number_s_s].comps[count_comps].delta = 0; + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + ss_assemblage[n].s_s[number_s_s].comps[count_comps].name = + string_hsave(token); + /* + * Read moles of component + */ + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + { + ss_assemblage[n].s_s[number_s_s].comps[count_comps].moles = + NAN; + } + else + { + j = sscanf(token, SCANFORMAT, &dummy); + ss_assemblage[n].s_s[number_s_s].comps[count_comps].moles = + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; + case 2: /* parms */ + case 3: /* gugg_nondimensional */ + /* + * Read parameters + */ + + ptr = next_char; + if (copy_token(token, &ptr, &l) != EMPTY) + { + sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[0])); + } + if (copy_token(token, &ptr, &l) != EMPTY) + { + sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[1])); + } + ss_assemblage[n].s_s[number_s_s].input_case = 0; + break; + case 4: /* gugg_kj */ + ptr = next_char; + if (copy_token(token, &ptr, &l) != EMPTY) + { + sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[0])); + } + if (copy_token(token, &ptr, &l) != EMPTY) + { + sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[1])); + } + ss_assemblage[n].s_s[number_s_s].input_case = 7; + break; + case 5: /* activity coefficients */ + ptr = next_char; + j = 0; + for (i = 0; i < 4; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 4) + { + error_string = sformatf( + "Expected 4 parameters to calculate a0 and a1 from two activity coefficients, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 1; + break; + case 6: /* distribution coefficients */ + ptr = next_char; + j = 0; + for (i = 0; i < 4; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 4) + { + error_string = sformatf( + "Expected 4 parameters to calculate a0 and a1 from two distribution coefficients, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 2; + break; + case 7: /* miscibility_gap */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected 2 miscibility gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 3; + break; + case 8: /* spinodal_gap */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected 2 spinodal gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 4; + break; + case 9: /* critical point */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected fraction of component 2 and critical temperature to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 5; + break; + case 10: /* alyotropic point */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected fraction of component 2 and sigma pi at alyotropic point to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 6; + break; + case 12: /* tempk */ + ptr = next_char; + j = 0; + if (copy_token(token, &ptr, &l) != EMPTY) + { + j = sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].tk)); + } + if (j != 1) + { + error_string = sformatf( + "Expected temperature (Kelvin) for parameters, assemblage %d, solid solution %s, using 298.15 K", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + warning_msg(error_string); + ss_assemblage[n].s_s[number_s_s].tk = 298.15; + } + break; + case 11: /* temp */ + case 13: /* tempc */ + ptr = next_char; + j = 0; + if (copy_token(token, &ptr, &l) != EMPTY) + { + j = sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].tk)); + } + if (j != 1) + { + error_string = sformatf( + "Expected temperature (Celcius) for parameters, assemblage %d, solid solution %s, using 25 C", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + warning_msg(error_string); + ss_assemblage[n].s_s[number_s_s].tk = 25.; + } + ss_assemblage[n].s_s[number_s_s].tk += 273.15; + break; + case 14: /* Thompson and Waldbaum */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected Wg2 and Wg1 Thompson-Waldbaum parameters to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 8; + break; + case 15: /* Margules */ + ptr = next_char; + j = 0; + for (i = 0; i < 2; i++) + { + if (copy_token(token, &ptr, &l) != EMPTY) + { + j += sscanf(token, SCANFORMAT, + &(ss_assemblage[n].s_s[number_s_s].p[i])); + } + } + if (j != 2) + { + error_string = sformatf( + "Expected alpha2 and alpha3 Margules parameters to calculate a0 and a1, assemblage %d, solid solution %s", + ss_assemblage[n].n_user, + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_assemblage[n].s_s[number_s_s].input_case = 9; + break; + case 16: /* comp1 */ + if (count_comps < 2) + { + ss_assemblage[n].s_s[number_s_s].count_comps = 2; + count_comps = 2; + ss_assemblage[n].s_s[number_s_s].comps = + (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. + s_s[number_s_s].comps, + (size_t) (count_comps) * + sizeof(struct s_s_comp)); + if (ss_assemblage[n].s_s[number_s_s].comps == NULL) + malloc_error(); + } + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + ss_assemblage[n].s_s[number_s_s].comps[0].name = + string_hsave(token); + /* + * Read moles of component + */ + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + { + ss_assemblage[n].s_s[number_s_s].comps[0].moles = NAN; + } + else + { + j = sscanf(token, SCANFORMAT, &dummy); + ss_assemblage[n].s_s[number_s_s].comps[0].moles = + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; + case 17: /* comp2 */ + if (count_comps < 2) + { + ss_assemblage[n].s_s[number_s_s].count_comps = 2; + count_comps = 2; + ss_assemblage[n].s_s[number_s_s].comps = + (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. + s_s[number_s_s].comps, + (size_t) (count_comps) * + sizeof(struct s_s_comp)); + if (ss_assemblage[n].s_s[number_s_s].comps == NULL) + malloc_error(); + } + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr, &l); + ss_assemblage[n].s_s[number_s_s].comps[1].name = + string_hsave(token); + /* + * Read moles of component + */ + if ((j = copy_token(token, &ptr, &l)) == EMPTY) + { + ss_assemblage[n].s_s[number_s_s].comps[1].moles = NAN; + } + else + { + j = sscanf(token, SCANFORMAT, &dummy); + ss_assemblage[n].s_s[number_s_s].comps[1].moles = + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; +/* + * New solid solution + */ + case OPTION_DEFAULT: + number_s_s = count_s_s++; + /* + * Make space, set default + */ + + /* realloc space for one s_s */ + ss_assemblage[n].s_s = + (struct s_s *) PHRQ_realloc(ss_assemblage[n].s_s, + (size_t) (count_s_s + + 1) * + sizeof(struct s_s)); + if (ss_assemblage[n].s_s == NULL) + malloc_error(); + + /* malloc space for one component */ + ss_assemblage[n].s_s[number_s_s].comps = + (struct s_s_comp *) PHRQ_malloc((size_t) + sizeof(struct s_s_comp)); + if (ss_assemblage[n].s_s[number_s_s].comps == NULL) + malloc_error(); + count_comps = 0; + ss_assemblage[n].s_s[number_s_s].count_comps = 0; + ss_assemblage[n].s_s[number_s_s].total_moles = 0; + ss_assemblage[n].s_s[number_s_s].dn = 0; + ss_assemblage[n].s_s[number_s_s].a0 = 0.0; + ss_assemblage[n].s_s[number_s_s].a1 = 0.0; + ss_assemblage[n].s_s[number_s_s].ag0 = 0.0; + ss_assemblage[n].s_s[number_s_s].ag1 = 0.0; + ss_assemblage[n].s_s[number_s_s].s_s_in = FALSE; + ss_assemblage[n].s_s[number_s_s].miscibility = FALSE; + ss_assemblage[n].s_s[number_s_s].spinodal = FALSE; + ss_assemblage[n].s_s[number_s_s].tk = 298.15; + ss_assemblage[n].s_s[number_s_s].xb1 = 0; + ss_assemblage[n].s_s[number_s_s].xb2 = 0; + ss_assemblage[n].s_s[number_s_s].input_case = 0; + ss_assemblage[n].s_s[number_s_s].p[0] = 0.0; + ss_assemblage[n].s_s[number_s_s].p[1] = 0.0; + ss_assemblage[n].s_s[number_s_s].p[2] = 0.0; + ss_assemblage[n].s_s[number_s_s].p[3] = 0.0; + + ss_assemblage[n].s_s[number_s_s].comps->name = NULL; + ss_assemblage[n].s_s[number_s_s].comps->phase = NULL; + /* + * Read solid solution name + */ + ptr = line; + copy_token(token, &ptr, &l); + ss_assemblage[n].s_s[number_s_s].name = string_hsave(token); + ss_assemblage[n].s_s[number_s_s].total_moles = NAN; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + for (i = 0; i < ss_assemblage[n].count_s_s; i++) + { + if (ss_assemblage[n].s_s[i].p[0] != 0.0 || + ss_assemblage[n].s_s[i].p[1] != 0.0) + { + if (ss_assemblage[n].s_s[number_s_s].count_comps != 2) + { + error_string = sformatf( + "Solid solution, %s, is nonideal. Must define exactly two components (-comp1 and -comp2).", + ss_assemblage[n].s_s[number_s_s].name); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } +/* + * Sort components by name (lowercase) + */ + + ss_assemblage[n].count_s_s = count_s_s; + qsort(ss_assemblage[n].s_s, + (size_t) count_s_s, (size_t) sizeof(struct s_s), s_s_compare); + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_llnl_aqueous_model_parameters(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads aqueous model parameters + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int i, count_alloc; + char token[MAX_LENGTH]; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temperatures", /* 0 */ + "temperature", /* 1 */ + "temp", /* 2 */ + "adh", /* 3 */ + "debye_huckel_a", /* 4 */ + "dh_a", /* 5 */ + "bdh", /* 6 */ + "debye_huckel_b", /* 7 */ + "dh_b", /* 8 */ + "bdot", /* 9 */ + "b_dot", /* 10 */ + "c_co2", /* 11 */ + "co2_coefs" /* 12 */ + }; + int count_opt_list = 13; +/* + * Initialize + */ +/* + * Read aqueous model parameters + */ + return_value = UNKNOWN; + opt = get_option(opt_list, count_opt_list, &next_char); + for (;;) + { + next_char = line; + if (opt >= 0) + { + copy_token(token, &next_char, &i); + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg + ("Unknown input in LLNL_AQUEOUS_MODEL_PARAMETERS keyword.", + CONTINUE); + error_msg(line_save, CONTINUE); + break; + +/* + * New component + */ + case 0: /* temperatures */ + case 1: /* temperature */ + case 2: /* temp */ + count_alloc = 1; + llnl_count_temp = 0; + i = read_lines_doubles(next_char, &(llnl_temp), + &(llnl_count_temp), &(count_alloc), + opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_temp = read_list_doubles(&ptr, &count); + llnl_count_temp = count; + */ + break; + case 3: /* adh */ + case 4: /* debye_huckel_a */ + case 5: /* dh_a */ + count_alloc = 1; + llnl_count_adh = 0; + i = read_lines_doubles(next_char, &(llnl_adh), &(llnl_count_adh), + &(count_alloc), opt_list, count_opt_list, + &opt); + /* + ptr = next_char; + llnl_adh = read_list_doubles(&ptr, &count); + llnl_count_adh = count; + */ + break; + case 6: /* bdh */ + case 7: /* debye_huckel_b */ + case 8: /* dh_b */ + count_alloc = 1; + llnl_count_bdh = 0; + i = read_lines_doubles(next_char, &(llnl_bdh), &(llnl_count_bdh), + &(count_alloc), opt_list, count_opt_list, + &opt); + /* + ptr = next_char; + llnl_bdh = read_list_doubles(&ptr, &count); + llnl_count_bdh = count; + */ + break; + case 9: /* bdot */ + case 10: /* b_dot */ + count_alloc = 1; + llnl_count_bdot = 0; + i = read_lines_doubles(next_char, &(llnl_bdot), + &(llnl_count_bdot), &(count_alloc), + opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_bdot = read_list_doubles(&ptr, &count); + llnl_count_bdot = count; + */ + break; + case 11: /* c_co2 */ + case 12: /* co2_coefs */ + count_alloc = 1; + llnl_count_co2_coefs = 0; + i = read_lines_doubles(next_char, &(llnl_co2_coefs), + &(llnl_count_co2_coefs), &(count_alloc), + opt_list, count_opt_list, &opt); + /* + ptr = next_char; + llnl_co2_coefs = read_list_doubles(&ptr, &count); + llnl_count_co2_coefs = count; + */ + break; + } + return_value = check_line_return; + if (return_value == EOF || return_value == KEYWORD) + break; + } + /* check consistency */ + if ((llnl_count_temp <= 0) || + (llnl_count_temp != llnl_count_adh) || + (llnl_count_temp != llnl_count_bdh) || + (llnl_count_temp != llnl_count_bdot)) + { + error_msg + ("Must define equal number (>0) of temperatures, dh_a, dh_b, and bdot parameters\nin LLNL_AQUEOUS_MODEL", + CONTINUE); + input_error++; + } + if (llnl_count_co2_coefs != 5) + { + error_msg + ("Must define 5 CO2 activity coefficient parameters in LLNL_AQUEOUS_MODEL", + CONTINUE); + input_error++; + } + for (i = 1; i < llnl_count_temp; i++) + { + if (llnl_temp[i - 1] > llnl_temp[i]) + { + error_msg + ("Temperatures must be in ascending order in LLNL_AQUEOUS_MODEL", + CONTINUE); + input_error++; + } + } + + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads LDBLEs on line starting at next_char + * and on succeeding lines. Appends to d. + * Stops at KEYWORD, OPTION, and EOF + * + * Input Arguments: + * next_char points to line to read from + * d points to array of LDBLEs, must be malloced + * count_d number of elements in array + * count_alloc number of elements malloced + * + * Output Arguments: + * d points to array of LDBLEs, may have been + * realloced + * count_d updated number of elements in array + * count_alloc updated of elements malloced + * + * Returns: + * KEYWORD + * OPTION + * EOF + * ERROR if any errors reading LDBLEs + */ + + if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) + { + return (ERROR); + } + for (;;) + { + *opt = get_option(opt_list, count_opt_list, &next_char); + if (*opt == OPTION_KEYWORD || *opt == OPTION_EOF + || *opt == OPTION_ERROR) + { + break; + } + else if (*opt >= 0) + { + break; + } + next_char = line; + if (read_line_doubles(next_char, d, count_d, count_alloc) == ERROR) + { + return (ERROR); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_line_doubles(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, n; + LDBLE value; + char token[MAX_LENGTH]; + + for (;;) + { + j = copy_token(token, &next_char, &l); + if (j == EMPTY) + { + break; + } + if (j != DIGIT) + { + return (ERROR); + } + if (replace("*", " ", token) == TRUE) + { + if (sscanf(token, "%d" SCANFORMAT, &n, &value) != 2) + { + return (ERROR); + } + } + else + { + sscanf(token, SCANFORMAT, &value); + n = 1; + } + for (;;) + { + if ((*count_d) + n > (*count_alloc)) + { + *count_alloc *= 2; + *d = (LDBLE *) PHRQ_realloc(*d, + (size_t) (*count_alloc) * + sizeof(LDBLE)); + if (*d == NULL) + malloc_error(); + } + else + { + break; + } + } + for (i = 0; i < n; i++) + { + (*d)[(*count_d) + i] = value; + } + *count_d += n; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +next_keyword_or_option(const char **opt_list, int count_opt_list) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads to next keyword or option or eof + * + * Returns: + * KEYWORD + * OPTION + * EOF + */ + int opt; + char *next_char; + + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_EOF) + { /* end of file */ + break; + } + else if (opt == OPTION_KEYWORD) + { /* keyword */ + break; + } + else if (opt >= 0 && opt < count_opt_list) + { + break; + } + else + { + error_msg("Expected a keyword or option.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + return (opt); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_named_logk(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads K's that can be used to calculate K's for species + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + + int j, l; + int i, empty; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "log_k", /* 0 */ + "logk", /* 1 */ + "delta_h", /* 2 */ + "deltah", /* 3 */ + "analytical_expression", /* 4 */ + "a_e", /* 5 */ + "ae", /* 6 */ + "ln_alpha1000", /* 7 */ + "add_logk", /* 8 */ + "add_log_k", /* 9 */ + "delta_v", /* 10 */ + "deltav", /* 11 */ + "vm" + }; + int count_opt_list = 13; + logk_ptr = NULL; +/* + * Read name followed by options + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SPECIES keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* log_k */ + case 1: /* logk */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_log_k_only(next_char, &logk_ptr->log_k[0]); + logk_copy2orig(logk_ptr); + opt_save = OPTION_DEFAULT; + break; + case 2: /* delta_h */ + case 3: /* deltah */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_h_only(next_char, &logk_ptr->log_k[1], + &logk_ptr->original_units); + logk_copy2orig(logk_ptr); + opt_save = OPTION_DEFAULT; + break; + case 4: /* analytical_expression */ + case 5: /* a_e */ + case 6: /* ae */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_analytical_expression_only(next_char, &(logk_ptr->log_k[T_A1])); + logk_copy2orig(logk_ptr); + opt_save = OPTION_DEFAULT; + break; + case 7: /* ln_alpha1000 */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + empty = TRUE; + for (i = T_A1; i <= T_A6; i++) + { + if (logk_ptr->log_k[i] != 0.0) + { + empty = FALSE; + logk_ptr->log_k[i] = 0.0; + } + } + if (empty == FALSE) + { + error_string = sformatf( + "Analytical expression previously defined for %s in NAMED_EXPRESSIONS\nAnalytical expression will be overwritten.", + logk_ptr->name); + warning_msg(error_string); + } + read_analytical_expression_only(next_char, &(logk_ptr->log_k[T_A1])); + for (i = T_A1; i < T_A6; i++) + { + logk_ptr->log_k[i] /= 1000. * LOG_10; + } + logk_copy2orig(logk_ptr); + opt_save = OPTION_DEFAULT; + break; + case 8: /* add_logk */ + case 9: /* add_log_k */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (logk_ptr->count_add_logk == 0) + { + logk_ptr->add_logk = + (struct name_coef *) + PHRQ_malloc(sizeof(struct name_coef)); + if (logk_ptr->add_logk == NULL) + malloc_error(); + } + else + { + logk_ptr->add_logk = + (struct name_coef *) PHRQ_realloc(logk_ptr->add_logk, + (size_t) ((logk_ptr-> + count_add_logk + + + 1) * + sizeof + (struct + name_coef))); + if (logk_ptr->add_logk == NULL) + malloc_error(); + } + /* read name */ + if (copy_token(token, &next_char, &i) == EMPTY) + { + input_error++; + error_string = sformatf( + "Expected the name of a NAMED_EXPRESSION."); + error_msg(error_string, CONTINUE); + break; + } + logk_ptr->add_logk[logk_ptr->count_add_logk].name = + string_hsave(token); + /* read coef */ + i = sscanf(next_char, SCANFORMAT, + &logk_ptr->add_logk[logk_ptr->count_add_logk].coef); + if (i <= 0) + { + logk_ptr->add_logk[logk_ptr->count_add_logk].coef = 1; + } + logk_ptr->count_add_logk++; + opt_save = OPTION_DEFAULT; + break; + case 10: /* delta_v */ + case 11: /* deltav */ + case 12: /* vm, molar volume */ + if (logk_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_delta_v_only(next_char, &logk_ptr->log_k[vm0], + &logk_ptr->original_deltav_units); + logk_copy2orig(logk_ptr); + opt_save = OPTION_DEFAULT; + break; + case OPTION_DEFAULT: +/* + * Get space for logk information + */ + logk_ptr = NULL; + j = copy_token(token, &next_char, &l); + + logk_ptr = logk_store(token, TRUE); +/* + * Get pointer to each species in the reaction, store new species if necessary + */ + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_copy(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, + * equilibrium_phases, + * exchange, + * surface, + * solid_solution, + * gas_phase, + * kinetics, + * mix, + * reaction, + * reaction_temperature + * + */ + int i, l, n, n_user, n_user_start, n_user_end, return_value; + char *ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH], nonkeyword[MAX_LENGTH]; +/* + * Read "copy" + */ + ptr = line; + copy_token(token, &ptr, &l); +/* + * Read keyword + */ + copy_token(token, &ptr, &l); + check_key(token); + + switch (next_keyword) + { + case Keywords::KEY_NONE: /* Have not read line with keyword */ + strcpy(nonkeyword, token); + break; + case Keywords::KEY_SOLUTION: /* Solution */ + case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */ + case Keywords::KEY_REACTION: /* Reaction */ + case Keywords::KEY_MIX: /* Mix */ + case Keywords::KEY_EXCHANGE: /* Ex */ + case Keywords::KEY_SURFACE: /* Surface */ + case Keywords::KEY_REACTION_TEMPERATURE: /* Temperature */ + case Keywords::KEY_REACTION_PRESSURE: /* Pressure */ + case Keywords::KEY_GAS_PHASE: /* Gas */ + case Keywords::KEY_KINETICS: /* Kinetics */ + case Keywords::KEY_SOLID_SOLUTIONS: /* solid_solutions */ + break; + default: + input_error++; + error_msg + ("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions, or cell.", + CONTINUE); + error_msg(line_save, CONTINUE); + check_line("End of use", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (ERROR); + } +/* + * Read source index + */ + strcpy(token1, token); + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, "%d", &n_user); + if (n_user < 0) + { + error_msg("Source index number must be a positive integer.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + if (strstr(token, "-") != NULL) + { + error_msg + ("COPY does not accept a range of numbers for source index", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + } + else + { + error_msg("Source index number must be a positive integer.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Read target index or range of indices + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + replace("-", " ", &token[1]); + n = sscanf(token, "%d%d", &n_user_start, &n_user_end); + if (n == 1) + { + n_user_end = n_user_start; + } + if (n_user_start < 0) + { + //error_msg("Target index number must be a positive integer.", + // CONTINUE); + //error_msg(line_save, CONTINUE); + //input_error++; + //return (ERROR); + } + } + else + { + error_msg("Target index number must be a positive integer.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + + switch (next_keyword) + { + case Keywords::KEY_NONE: + str_tolower(nonkeyword); + if (strstr(nonkeyword, "cell") != nonkeyword) + { + error_msg("Unknown input in COPY data block.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + copier_add(©_solution, n_user, n_user_start, n_user_end); + copier_add(©_pp_assemblage, n_user, n_user_start, n_user_end); + copier_add(©_reaction, n_user, n_user_start, n_user_end); + copier_add(©_mix, n_user, n_user_start, n_user_end); + copier_add(©_exchange, n_user, n_user_start, n_user_end); + copier_add(©_surface, n_user, n_user_start, n_user_end); + copier_add(©_temperature, n_user, n_user_start, n_user_end); + copier_add(©_pressure, n_user, n_user_start, n_user_end); + copier_add(©_gas_phase, n_user, n_user_start, n_user_end); + copier_add(©_kinetics, n_user, n_user_start, n_user_end); + copier_add(©_ss_assemblage, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_SOLUTION: /* Solution */ + copier_add(©_solution, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */ + copier_add(©_pp_assemblage, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_REACTION: /* Reaction */ + copier_add(©_reaction, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_MIX: /* Mix */ + copier_add(©_mix, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_EXCHANGE: /* Ex */ + copier_add(©_exchange, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_SURFACE: /* Surface */ + copier_add(©_surface, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_REACTION_TEMPERATURE: /* Temperature */ + copier_add(©_temperature, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_REACTION_PRESSURE: /* Pressure */ + copier_add(©_pressure, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_GAS_PHASE: /* Gas */ + copier_add(©_gas_phase, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_KINETICS: /* Kinetics */ + copier_add(©_kinetics, n_user, n_user_start, n_user_end); + break; + case Keywords::KEY_SOLID_SOLUTIONS: /* solid_solutions */ + copier_add(©_ss_assemblage, n_user, n_user_start, n_user_end); + break; + default: + error_msg("Error in switch for READ_COPY.", STOP); + break; + } + return_value = check_line("End of COPY", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_reaction_pressure(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads REACTION_PRESSURE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + assert(!reading_database()); + + // Make instance, set n_user, n_user_end, description + cxxPressure atm(this->phrq_io); + char *ptr = line; + char *description; + int n_user, n_user_end; + read_number_description(ptr, &n_user, &n_user_end, &description); + atm.Set_n_user(n_user); + atm.Set_n_user_end(n_user); + atm.Set_description(description); + free_check_null(description); + + /* + * Make parser + */ + //CParser parser(*phrq_io->get_istream(), this->phrq_io); + CParser parser(this->phrq_io); + if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); + atm.read(parser); + if (atm.Get_base_error_count() == 0) + { + Rxn_pressure_map[n_user] = atm; + } + + if (use.Get_pressure_in() == FALSE) + { + use.Set_pressure_in(true); + use.Set_n_pressure_user(atm.Get_n_user()); + } + + // Make copies if necessary + if (n_user_end > n_user) + { + int i; + for (i = n_user + 1; i <= n_user_end; i++) + { + Utilities::Rxn_copy(Rxn_pressure_map, n_user, i); + } + } + + return cleanup_after_parser(parser); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_reaction_pressure_raw(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads REACTION_PRESSURE_RAW data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + assert(!reading_database()); + + cxxPressure atm(this->phrq_io); + //char *ptr = line; + //char *description; + //int n_user, n_user_end; + //read_number_description(ptr, &n_user, &n_user_end, &description); + //atm.Set_n_user(n_user); + //atm.Set_n_user_end(n_user); + //atm.Set_description(description); + //free_check_null(description); + /* + * Make parser + */ + //CParser parser(*phrq_io->get_istream(), this->phrq_io); + CParser parser(this->phrq_io); + if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); + atm.read_raw(parser); + + // Store + if (atm.Get_base_error_count() == 0) + { + Rxn_pressure_map[atm.Get_n_user()] = atm; + } + + // Make copies if necessary + + Utilities::Rxn_copies(Rxn_pressure_map, atm.Get_n_user(), atm.Get_n_user_end()); + + + return cleanup_after_parser(parser); +} +int Phreeqc:: +cleanup_after_parser(CParser &parser) +{ + // check_key sets next_keyword + if (parser.get_m_line_type() == PHRQ_io::LT_EOF) + { + strcpy(line, ""); + strcpy(line_save, ""); + next_keyword = Keywords::KEY_END; + return(TRUE); + } + int return_value = check_key(parser.line().c_str()); + + // copy parser line to line and line_save + // make sure there is enough space + size_t l1 = strlen(parser.line().c_str()) + 1; + size_t l2 = strlen(parser.line_save().c_str()) + 1; + size_t l = (l1 > l2) ? l1 : l2; + if (l >= (size_t) max_line) + { + max_line = l * 2; + line_save = (char *) PHRQ_realloc(line_save, + (size_t) max_line * sizeof(char)); + if (line_save == NULL) + malloc_error(); + line = (char *) PHRQ_realloc(line, (size_t) max_line * sizeof(char)); + if (line == NULL) + malloc_error(); + } + strcpy(line, parser.line().c_str()); + strcpy(line_save, parser.line_save().c_str()); + return return_value; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_temperature(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads REACTION_TEMPERATURE data block + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + assert(!reading_database()); + + // Make instance, set n_user, n_user_end, description + cxxTemperature t_react(this->phrq_io); + char *ptr = line; + char *description; + int n_user, n_user_end; + read_number_description(ptr, &n_user, &n_user_end, &description); + t_react.Set_n_user(n_user); + t_react.Set_n_user_end(n_user); + t_react.Set_description(description); + free_check_null(description); + + /* + * Make parser + */ + //CParser parser(*phrq_io->get_istream(), this->phrq_io); + CParser parser(this->phrq_io); + if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); + t_react.read(parser); + if (t_react.Get_base_error_count() == 0) + { + Rxn_temperature_map[n_user] = t_react; + } + + if (use.Get_temperature_in() == FALSE) + { + use.Set_temperature_in(true); + use.Set_n_temperature_user(t_react.Get_n_user()); + } + + // Make copies if necessary + if (n_user_end > n_user) + { + int i; + for (i = n_user + 1; i <= n_user_end; i++) + { + Utilities::Rxn_copy(Rxn_temperature_map, n_user, i); + } + } + + return cleanup_after_parser(parser); +} diff --git a/rename_cpp/readtr.cpp b/rename_cpp/readtr.cpp new file mode 100644 index 00000000..17765fec --- /dev/null +++ b/rename_cpp/readtr.cpp @@ -0,0 +1,1234 @@ +#include /* std::cout std::cerr */ +#include +#include +#include "../StorageBin.h" +#include "../SS.h" + +typedef unsigned char boolean; +#include "Phreeqc.h" +#include "phqalloc.h" + + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPTION_DEFAULT2 -5 + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_transport(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads advection and column information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + char *ptr; + int i, j, l; + int old_cells, max; + int count_length, count_disp, count_punch, count_print; + int count_length_alloc, count_disp_alloc; + char token[MAX_LENGTH]; + char *description; + int n_user, n_user_end; + LDBLE *length, *disp; + int *punch_temp, *print_temp; + int return_value, opt, opt_save; + char *next_char, *next_char_save; + char file_name[MAX_LENGTH]; + + const char *opt_list[] = { + "cells", /* 0 */ + "shifts", /* 1 */ + "print", /* 2 */ + "selected_output", /* 3 */ + "bcond", /* 4 */ + "timest", /* 5 */ + "diffc", /* 6 */ + "tempr", /* 7 */ + "length", /* 8 */ + "disp", /* 9 */ + "punch", /* 10 */ + "stagnant", /* 11 */ + "bc", /* 12 */ + "boundary_conditions", /* 13 */ + "time_step", /* 14 */ + "temp_retardation_factor", /* 15 */ + "diffusion_coefficient", /* 16 */ + "dispersivity", /* 17 */ + "direction", /* 18 */ + "temperature_retardation_factor", /* 19 */ + "print_cells", /* 20 */ + "selected_cells", /* 21 */ + "flow_direction", /* 22 */ + "flow", /* 23 */ + "lengths", /* 24 */ + "dispersivities", /* 25 */ + "dump", /* 26 */ + "output", /* 27 */ + "output_frequency", /* 28 */ + "selected_output_frequency", /* 29 */ + "punch_cells", /* 30 */ + "dump_frequency", /* 31 */ + "dump_restart", /* 32 */ + "punch_frequency", /* 33 */ + "print_frequency", /* 34 */ + "correct_disp", /* 35 */ + "initial_time", /* 36 */ + "warning", /* 37 */ + "warnings", /* 38 */ + "thermal_diffusion", /* 39 */ + "multi_d", /* 40 */ + "interlayer_d" /* 41 */ + }; + int count_opt_list = 42; + + strcpy(file_name, "phreeqc.dmp"); +/* + * Initialize + */ + simul_tr++; + if (simul_tr == 1) + { + correct_disp = FALSE; + old_cells = 0; + } + else + old_cells = count_cells; + count_length = count_disp = count_punch = count_print = 0; + + length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (length == NULL) + malloc_error(); + + disp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (disp == NULL) + malloc_error(); + + punch_temp = (int *) PHRQ_malloc(sizeof(int)); + if (punch_temp == NULL) + malloc_error(); + + print_temp = (int *) PHRQ_malloc(sizeof(int)); + if (print_temp == NULL) + malloc_error(); + + count_length_alloc = count_disp_alloc = 1; + transport_start = 1; +/* + * Read transport number (not currently used) + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + description = (char *) free_check_null(description); +/* + * Set use data to last read + */ + use.Set_trans_in(true); +/* + * Read lines + */ + opt_save = OPTION_DEFAULT; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + opt = opt_save; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + case OPTION_DEFAULT: + input_error++; + error_msg("Unknown input in TRANSPORT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* cells */ + sscanf(next_char, "%d", &count_cells); + opt_save = OPTION_DEFAULT; + break; + case 1: /* shifts */ + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, "%d", &count_shifts); + else + { + warning_msg + ("Expected the number of shifts. One shift is assumed."); + count_shifts = 1; + } + j = copy_token(token, &next_char, &l); + if (j != EMPTY) + { + if (j == DIGIT) + sscanf(token, "%d", &ishift); + else + { + input_error++; + error_msg + ("Expected shift direction, -1, 0, 1. Use -direction instead.", + CONTINUE); + ishift = 1; + } + } + opt_save = OPTION_DEFAULT; + break; + case 2: /* print */ + case 20: /* print_cells */ + print_temp = + read_list_ints_range(&next_char, &count_print, TRUE, + print_temp); + opt_save = 2; + break; + case 3: /* selected_output */ + case 29: /* selected_output_frequency */ + case 33: /* punch_frequency */ + sscanf(next_char, "%d", &punch_modulus); + opt_save = OPTION_DEFAULT; + if (punch_modulus <= 0) + { + error_string = sformatf( + "Punch frequency must be greater than 0. Frequency set to 1000."); + warning_msg(error_string); + punch_modulus = 1000; + } + + break; + case 4: /* bcond */ + case 12: /* bc */ + case 13: /* boundary_conditions */ + /* first cell boundary condition */ + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + { + sscanf(token, "%d", &bcon_first); + if (bcon_first < 1 || bcon_first > 3) + { + input_error++; + error_msg + ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", + CONTINUE); + } + } + else if (i == EMPTY) + bcon_first = 3; + else if (strstr(token, "co") == token) + bcon_first = 1; + else if (strstr(token, "cl") == token) + bcon_first = 2; + else if (strstr(token, "f") == token) + bcon_first = 3; + else + { + input_error++; + error_msg + ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", + CONTINUE); + } + + /* last cell boundary condition */ + i = copy_token(token, &next_char, &l); + str_tolower(token); + if (i == DIGIT) + { + sscanf(token, "%d", &bcon_last); + if (bcon_last < 1 || bcon_last > 3) + { + input_error++; + error_msg + ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", + CONTINUE); + } + } + else if (i == EMPTY) + bcon_last = 3; + else if (strstr(token, "co") == token) + bcon_last = 1; + else if (strstr(token, "cl") == token) + bcon_last = 2; + else if (strstr(token, "f") == token) + bcon_last = 3; + else + { + input_error++; + error_msg + ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", + CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; + case 5: /* timest */ + case 14: /* time_step */ + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, SCANFORMAT, ×t); + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, SCANFORMAT, &mcd_substeps); + if (mcd_substeps < 1) + { + mcd_substeps = 1.0; + warning_msg("Substep factor in MCD must be >= 1.0\n" + "mcd_substeps = 1.0 assumed."); + } + opt_save = OPTION_DEFAULT; + break; + case 6: /* diffc */ + case 16: /* diffusion_coefficient */ + sscanf(next_char, SCANFORMAT, &diffc); + opt_save = OPTION_DEFAULT; + break; + case 7: /* tempr */ + case 15: /* temp_retardation_factor */ + case 19: /* temperature_retardation_factor */ + case 39: /* thermal_diffusion */ + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, SCANFORMAT, &tempr); + if (tempr < 1) + { + tempr = 1; + warning_msg + ("Temperature retardation factor < 1 is not possible.\n" + "Temperature retardation factor = 1 assumed."); + } + j = copy_token(token, &next_char, &l); + if (j == DIGIT) + sscanf(token, SCANFORMAT, &heat_diffc); + opt_save = OPTION_DEFAULT; + break; + case 8: /* length */ + case 24: /* lengths */ + if (read_line_LDBLEs + (next_char, &length, &count_length, + &count_length_alloc) == ERROR) + { + input_error++; + error_msg("Reading lengths in TRANSPORT keyword.\n", + CONTINUE); + } + opt_save = 8; + break; + case 9: /* disp */ + case 17: /* dispersivity */ + case 25: /* dispersivities */ + if (read_line_LDBLEs + (next_char, &disp, &count_disp, &count_disp_alloc) == ERROR) + { + input_error++; + error_msg("Reading dispersivities in TRANSPORT keyword.\n", + CONTINUE); + } + opt_save = 9; + break; + case 10: /* punch */ + case 21: /* selected_cells */ + case 30: /* punch_cells */ + punch_temp = + read_list_ints_range(&next_char, &count_punch, TRUE, + punch_temp); + opt_save = 10; + break; + case 11: /* stagnant */ + if (copy_token(token, &next_char, &l) != EMPTY) + { + /* exchange factor */ + if (sscanf(token, "%d", &(stag_data->count_stag)) != 1) + { + input_error++; + error_string = sformatf( + "Expecting number of stagnant layers."); + error_msg(error_string, CONTINUE); + break; + } + + /* exchange factor */ + j = copy_token(token, &next_char, &l); + if (j != EMPTY) + { + if (sscanf(token, SCANFORMAT, &(stag_data->exch_f)) != 1) + { + input_error++; + error_string = sformatf( + "Expecting exchange factor for stagnant layers."); + error_msg(error_string, CONTINUE); + break; + } + copy_token(token, &next_char, &l); + if (sscanf(token, SCANFORMAT, &(stag_data->th_m)) != 1) + { + input_error++; + error_string = sformatf( + "Expecting porosity in the mobile zone."); + error_msg(error_string, CONTINUE); + break; + } + copy_token(token, &next_char, &l); + if (sscanf(token, SCANFORMAT, &(stag_data->th_im)) != 1) + { + input_error++; + error_string = sformatf( + "Expecting porosity in the immobile zone."); + error_msg(error_string, CONTINUE); + break; + } + } + } + opt_save = OPTION_DEFAULT; + break; + case 18: /* direction */ + case 22: /* flow_direction */ + case 23: /* flow */ + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "f") == token) + ishift = 1; + else if (strstr(token, "b") == token) + ishift = -1; + else if (strstr(token, "d") == token) + ishift = 0; + else if (strstr(token, "n") == token) + ishift = 0; + else + { + input_error++; + error_msg + ("Expected flow direction to be 'forward', 'back', or 'no_flow'.", + CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; + case 26: /* dump */ + dump_in = TRUE; + next_char_save = next_char; + if (copy_token(file_name, &next_char, &l) == EMPTY) + strcpy(file_name, "phreeqc.dmp"); + else + { + string_trim(next_char_save); + strcpy(file_name, next_char_save); + } + opt_save = OPTION_DEFAULT; + break; + case 27: /* output */ + case 28: /* output_frequency */ + case 34: /* print_frequency */ + sscanf(next_char, "%d", &print_modulus); + opt_save = OPTION_DEFAULT; + if (print_modulus <= 0) + { + error_string = sformatf( + "Print frequency must be greater than 0. Frequency set to 1000."); + warning_msg(error_string); + print_modulus = 1000; + } + break; + case 31: /* dump_frequency */ + dump_in = TRUE; + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, "%d", &dump_modulus); + else + { + warning_msg("Expected integer value for dump_frequency."); + dump_modulus = 0; + } + opt_save = OPTION_DEFAULT; + break; + case 32: /* dump_restart */ + dump_in = TRUE; + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, "%d", &transport_start); + else + { + warning_msg + ("Expected shift number to start calculations, 1 will be used."); + transport_start = 1; + } + opt_save = OPTION_DEFAULT; + break; + case 35: /* correct_dispersion */ + correct_disp = get_true_false(next_char, TRUE); + opt_save = OPTION_DEFAULT; + break; + case 36: /* initial_time */ + sscanf(next_char, SCANFORMAT, &initial_total_time); + opt_save = OPTION_DEFAULT; + break; + case 37: /* warning */ + case 38: /* warnings */ + transport_warnings = get_true_false(next_char, TRUE); + break; + case 40: /* multicomponent diffusion */ + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "f") == token) + multi_Dflag = 0; + else if (strstr(token, "t") == token) + multi_Dflag = 1; + else + { + input_error++; + error_msg + ("Expected multicomponent diffusion flag: 'true' or 'false'.", + CONTINUE); + } + default_Dw = 1e-9; + multi_Dpor = 0.3; + multi_Dpor_lim = 0.0; + multi_Dn = 1.0; + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + /* default species diffusion coeff */ + if (sscanf(token, SCANFORMAT, &default_Dw) != 1) + { + input_error++; + error_string = sformatf( + "Expected default species diffusion coefficient in water at 25oC, m2/s."); + error_msg(error_string, CONTINUE); + break; + } + } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + /* porosity */ + if (sscanf(token, SCANFORMAT, &multi_Dpor) != 1) + { + input_error++; + error_string = sformatf( + "Expected porosity to calculate diffusion coefficient."); + error_msg(error_string, CONTINUE); + break; + } + } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + /* porosity */ + if (sscanf(token, SCANFORMAT, &multi_Dpor_lim) != 1) + { + input_error++; + error_string = sformatf( + "Expected porosity limit for diffusive transport."); + error_msg(error_string, CONTINUE); + break; + } + } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + if (sscanf(token, SCANFORMAT, &multi_Dn) != 1) + { + input_error++; + error_string = sformatf( + "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); + error_msg(error_string, CONTINUE); + break; + } + } + opt_save = OPTION_DEFAULT; + break; + case 41: /* interlayer diffusion */ + copy_token(token, &next_char, &l); + str_tolower(token); + if (strstr(token, "f") == token) + interlayer_Dflag = 0; + else if (strstr(token, "t") == token) + interlayer_Dflag = 1; + else + { + input_error++; + error_msg + ("Expected interlayer diffusion flag: 'true' or 'false'.", + CONTINUE); + } + interlayer_Dpor = 0.1; + interlayer_Dpor_lim = 0.0; + interlayer_tortf = 100.0; + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + /* porosity */ + if (sscanf(token, SCANFORMAT, &interlayer_Dpor) != 1) + { + input_error++; + error_string = sformatf( "Expected interlayer porosity."); + error_msg(error_string, CONTINUE); + break; + } + } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + /* porosity limit */ + if (sscanf(token, SCANFORMAT, &interlayer_Dpor_lim) != 1) + { + input_error++; + error_string = sformatf( + "Expected interlayer porosity limit for diffusive transport."); + error_msg(error_string, CONTINUE); + break; + } + } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + if (sscanf(token, SCANFORMAT, &interlayer_tortf) != 1) + { + input_error++; + error_string = sformatf( + "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); + error_msg(error_string, CONTINUE); + break; + } + } + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * Determine number of cells + */ + max = count_cells; + if (count_length > max) + max = count_length; + if (count_disp > max) + max = count_disp; + if (max > count_cells) + { + if (max == count_length) + { + sprintf(token, + "Number of cells is increased to number of 'lengths' %d.", + count_length); + warning_msg(token); + } + else + { + sprintf(token, + "Number of cells is increased to number of dispersivities %d.", + count_disp); + warning_msg(token); + } + } +/* + * Allocate space for cell_data + */ + cell_data = + (struct cell_data *) PHRQ_realloc(cell_data, + (size_t) (max * + (1 + + stag_data->count_stag) + + 1) * + sizeof(struct cell_data)); + if (cell_data == NULL) + malloc_error(); +/* + * Fill in data for lengths + */ + if (count_length == 0) + { + if (old_cells < max) + { + error_string = sformatf( + "No cell-lengths were read; length = 1 m assumed."); + warning_msg(error_string); + for (i = 0; i < max; i++) + cell_data[i].length = 1.0; + } + } + else + { + for (i = 0; i < count_length; i++) + { + cell_data[i].length = length[i]; + } + if (max > count_length) + { + error_string = sformatf( + "Cell-lengths were read for %d cells. Last value is used till cell %d.", + count_length, max); + warning_msg(error_string); + for (i = count_length - 1; i < max; i++) + cell_data[i].length = length[count_length - 1]; + } + } + cell_data[0].mid_cell_x = cell_data[0].length / 2; + for (i = 1; i < max; i++) + { + cell_data[i].mid_cell_x = cell_data[i - 1].mid_cell_x + + (cell_data[i - 1].length + cell_data[i].length) / 2; + } + cell_data[max].mid_cell_x = + cell_data[max - 1].mid_cell_x + cell_data[max - 1].length; +/* + * Fill in data for dispersivities + */ + if (count_disp == 0) + { + if (old_cells < max) + { + error_string = sformatf( + "No dispersivities were read; disp = 0 assumed."); + warning_msg(error_string); + for (i = 0; i < max; i++) + cell_data[i].disp = 0.0; + } + } + else + { + for (i = 0; i < count_disp; i++) + cell_data[i].disp = disp[i]; + if (max > count_disp) + { + error_string = sformatf( + "Dispersivities were read for %d cells. Last value is used till cell %d.", + count_disp, max); + warning_msg(error_string); + for (i = count_disp - 1; i < max; i++) + cell_data[i].disp = disp[count_disp - 1]; + } + } + count_cells = max; +/* + * Account for stagnant cells + */ + if (stag_data->count_stag > 0) + { + max = count_cells * (1 + stag_data->count_stag) + 1; + for (i = 0; i < count_cells; i++) + { + for (l = 1; l <= stag_data->count_stag; l++) + cell_data[i + 1 + l * count_cells].mid_cell_x = + cell_data[i].mid_cell_x; + } + } +/* + * Fill in data for punch + */ + if (count_punch != 0) + { + for (i = 0; i < max; i++) + cell_data[i].punch = FALSE; + for (i = 0; i < count_punch; i++) + { + if (punch_temp[i] > max || punch_temp[i] < 1) + { + error_string = sformatf( + "Cell number for punch is out of range, %d. Request ignored.", + punch_temp[i]); + warning_msg(error_string); + } + else + cell_data[punch_temp[i] - 1].punch = TRUE; + } + } + else if (simul_tr == 1) + for (i = 0; i < max; i++) + cell_data[i].punch = TRUE; +/* + * Fill in data for print + */ + if (count_print != 0) + { + for (i = 0; i < max; i++) + cell_data[i].print = FALSE; + for (i = 0; i < count_print; i++) + { + if (print_temp[i] > max || print_temp[i] < 1) + { + error_string = sformatf( + "Cell number for print is out of range, %d. Request ignored.", + print_temp[i]); + warning_msg(error_string); + } + else + cell_data[print_temp[i] - 1].print = TRUE; + } + } + else if (simul_tr == 1) + for (i = 0; i < max; i++) + cell_data[i].print = TRUE; +/* + * Fill in porosities + */ + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + + } + for (i = 0; i < max; i++) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por = multi_Dpor; + cell_data[i].por_il = interlayer_Dpor; + } +/* + * Calculate dump_modulus + */ + if (dump_in == TRUE) + { + if (dump_modulus == 0) + { + warning_msg + ("Expected dump_modulus. Value of 'shifts/2' will be used."); + dump_modulus = count_shifts / 2; + if (dump_modulus == 0) + dump_modulus = 1; + } + if (transport_start > count_shifts) + { + input_error++; + error_string = sformatf( + "Starting shift for transport, %d, is greater than number of shifts, %d.", + transport_start, count_shifts); + error_msg(error_string, CONTINUE); + } + } +/* + * Check boundary conditions + */ + if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) + { + warning_msg + ("Boundary condition = 'closed' not possible with advective transport.\n\t Boundary condition = 'flux' assumed."); + if (bcon_first == 2) + bcon_first = 3; + if (bcon_last == 2) + bcon_last = 3; + } +/* + * Retain data from previous run + */ + if (simul_tr > 1) + { + if ((count_length == 0) && (count_disp == 0)) + dup_print("Column data retained from former run", TRUE); + } +/* + * Check heat_diffc + */ + if (heat_diffc < 0) + heat_diffc = diffc; + else if (stag_data->count_stag == 1) + { + if (stag_data->exch_f > 0) + { + if (diffc <= 0 && heat_diffc > 0) + { + input_error++; + error_string = sformatf( + "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } + else if (heat_diffc > diffc) + { + error_string = sformatf( + "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", + (double) diffc); + warning_msg(error_string); + } + } + else + { + if (heat_diffc > diffc) + { + input_error++; + error_string = sformatf( + "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } + } + } + else if (stag_data->count_stag > 1 && heat_diffc > diffc) + { + input_error++; + error_string = sformatf( + "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); + error_msg(error_string, CONTINUE); + } +/* + * free storage for length, disp, punch + */ + length = (LDBLE *) free_check_null(length); + disp = (LDBLE *) free_check_null(disp); + punch_temp = (int *) free_check_null(punch_temp); + print_temp = (int *) free_check_null(print_temp); + + if (dump_in == TRUE) + { + dump_file_name_cpp.clear(); + dump_file_name_cpp.append(file_name); + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l, n; + LDBLE value; + char token[MAX_LENGTH]; + + for (;;) + { + j = copy_token(token, &next_char, &l); + if (j == EMPTY) + break; + if (j != DIGIT) + return (ERROR); + if (replace("*", " ", token) == TRUE) + { + if (sscanf(token, "%d" SCANFORMAT, &n, &value) != 2) + return (ERROR); + } + else + { + sscanf(token, SCANFORMAT, &value); + n = 1; + } + for (;;) + { + if ((*count_d) + n > (*count_alloc)) + { + *count_alloc *= 2; + *d = (LDBLE *) PHRQ_realloc(*d, + (size_t) (*count_alloc) * + sizeof(LDBLE)); + if (*d == NULL) + malloc_error(); + } + else + break; + } + for (i = 0; i < n; i++) + (*d)[(*count_d) + i] = value; + *count_d += n; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +dump_cpp(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * dumps solution compositions to file + */ + + int i, j, l; + + if (dump_in == FALSE || pr.dump == FALSE) + return (OK); + + cxxStorageBin phreeqcBin(phrq_io); + phreeqc2cxxStorageBin(phreeqcBin); + + std::ofstream fs(dump_file_name_cpp.c_str()); + fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n"; + phreeqcBin.dump_raw(fs, 0); + fs << "END" << "\n"; + + char token[MAX_LENGTH]; + sprintf(token, "KNOBS\n"); + fs << token; + sprintf(token, "\t-iter%15d\n", itmax); + fs << token; + sprintf(token, "\t-tol %15.3e\n", (double) ineq_tol); + fs << token; + sprintf(token, "\t-step%15.3e\n", (double) step_size); + fs << token; + sprintf(token, "\t-pe_s%15.3e\n", (double) pe_step_size); + fs << token; + sprintf(token, "\t-diag "); + fs << token; + if (diagonal_scale == TRUE) + { + sprintf(token, "true\n"); + fs << token; + } + else + { + sprintf(token, "false\n"); + fs << token; + } + + sprintf(token, "SELECTED_OUTPUT\n"); + fs << token; + sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); + fs << token; + if (punch.count_totals != 0) + { + sprintf(token, "\t-tot "); + fs << token; + for (i = 0; i < punch.count_totals; i++) + { + sprintf(token, " %s", punch.totals[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_molalities != 0) + { + sprintf(token, "\t-mol "); + fs << token; + for (i = 0; i < punch.count_molalities; i++) + { + sprintf(token, " %s", punch.molalities[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_activities != 0) + { + sprintf(token, "\t-act "); + fs << token; + for (i = 0; i < punch.count_activities; i++) + { + sprintf(token, " %s", punch.activities[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_pure_phases != 0) + { + sprintf(token, "\t-equ "); + fs << token; + for (i = 0; i < punch.count_pure_phases; i++) + { + sprintf(token, " %s", punch.pure_phases[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_si != 0) + { + sprintf(token, "\t-si "); + fs << token; + for (i = 0; i < punch.count_si; i++) + { + sprintf(token, " %s", punch.si[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_gases != 0) + { + sprintf(token, "\t-gas "); + fs << token; + for (i = 0; i < punch.count_gases; i++) + { + sprintf(token, " %s", punch.gases[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_s_s != 0) + { + sprintf(token, "\t-solid_solutions "); + fs << token; + for (i = 0; i < punch.count_s_s; i++) + { + sprintf(token, " %s", punch.s_s[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + if (punch.count_kinetics != 0) + { + sprintf(token, "\t-kin "); + fs << token; + for (i = 0; i < punch.count_kinetics; i++) + { + sprintf(token, " %s", punch.kinetics[i].name); + fs << token; + } + sprintf(token, "\n"); + fs << token; + } + sprintf(token, "TRANSPORT\n"); + fs << token; + sprintf(token, "\t-cells %6d\n", count_cells); + fs << token; + sprintf(token, "\t-shifts%6d%6d\n", count_shifts, ishift); + fs << token; + sprintf(token, "\t-output_frequency %6d\n", print_modulus); + fs << token; + sprintf(token, "\t-selected_output_frequency %6d\n", + punch_modulus); + fs << token; + sprintf(token, "\t-bcon %6d%6d\n", bcon_first, bcon_last); + fs << token; + sprintf(token, "\t-timest %13.5e\n", (double) timest); + fs << token; + if (punch.high_precision == FALSE) + { + sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + fs << token; + } + else + { + sprintf(token, "\t-diffc %20.12e\n", (double) diffc); + fs << token; + } + sprintf(token, "\t-tempr %13.5e\n", (double) tempr); + fs << token; + if (correct_disp == TRUE) + { + sprintf(token, "\t-correct_disp %s\n", "True"); + fs << token; + } + else + { + sprintf(token, "\t-correct_disp %s\n", "False"); + fs << token; + } + sprintf(token, "\t-length\n"); + fs << token; + for (i = 0; i < count_cells; i++) + { + sprintf(token, "%12.3e", (double) cell_data[i].length); + fs << token; + if (i > 0 && (i % 8) == 0) + { + sprintf(token, "\n"); + fs << token; + } + } + sprintf(token, "\n"); + fs << token; + sprintf(token, "\t-disp\n"); + fs << token; + for (i = 0; i < count_cells; i++) + { + if (punch.high_precision == FALSE) + { + sprintf(token, "%12.3e", (double) cell_data[i].disp); + fs << token; + } + else + { + sprintf(token, "%20.12e", (double) cell_data[i].disp); + fs << token; + } + if (i > 0 && (i % 8) == 0) + { + sprintf(token, "\n"); + fs << token; + } + } + sprintf(token, "\n"); + fs << token; + sprintf(token, "\t-punch_cells"); + fs << token; + if (stag_data->count_stag > 0) + j = 1 + (1 + stag_data->count_stag) * count_cells; + else + j = count_cells; + l = 0; + for (i = 0; i < j; i++) + { + if (cell_data[i].punch != TRUE) + continue; + sprintf(token, " %d", i + 1); + fs << token; + l++; + if ((l % 20) == 0) + { + sprintf(token, "\n"); + fs << token; + } + } + sprintf(token, "\n"); + fs << token; + sprintf(token, "\t-print_cells"); + fs << token; + if (stag_data->count_stag > 0) + j = 1 + (1 + stag_data->count_stag) * count_cells; + else + j = count_cells; + l = 0; + for (i = 0; i < j; i++) + { + if (cell_data[i].print != TRUE) + continue; + sprintf(token, " %d", i + 1); + fs << token; + l++; + if ((l % 20) == 0) + { + sprintf(token, "\n"); + fs << token; + } + } + sprintf(token, "\n"); + fs << token; + sprintf(token, "\t-dump $$$.dmp\n"); + fs << token; + sprintf(token, "\t-dump_frequency %d\n", dump_modulus); + fs << token; + sprintf(token, "\t-dump_restart %d\n", transport_step + 1); + fs << token; + +#if defined MULTICHART + // user graphs + chart_handler.dump(fs, 0); +#endif + + sprintf(token, "END\n"); + fs << token; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +dump(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * dumps solution compositions to file + */ + if (dump_in == FALSE || pr.dump == FALSE) + return (OK); + + dump_cpp(); + return OK; + +} diff --git a/rename_cpp/revisions b/rename_cpp/revisions new file mode 100644 index 00000000..88fd31db --- /dev/null +++ b/rename_cpp/revisions @@ -0,0 +1,3102 @@ +File contains: + "Features not documented in WRIR 99-4295" + "Revisions and Bug Fixes" + +************************************************************ +************************************************************ +* Features not documented in WRIR 99-4259. * +************************************************************ +************************************************************ +------------------------------------------------------------ +Version @PHREEQC_VER@: @PHREEQC_DATE@ +------------------------------------------------------------ + + -------- + svn 5556 + -------- + If -high_precision is set to true in SELECTED_OUTPUT, + convergence tolerance is set to 1e-12. If + -high_precision is set to false, convergence tolerance + is not changed. KNOBS; -convergence_tolerance sets the + convergence tolerance to a specified number. The last + definition (-high_precision true or + -convergence_tolerance) takes precedence for a + calculation. + +------------------------------------------------------------ +Version 2.18.0: April 9, 2011 +------------------------------------------------------------ + -------- + svn 5212 + -------- + Added gfm (gram formula mass) as a synonym to gfw in + reading concentration data for SOLUTION. + + S(6) 1 gfm 96 + + is equivalent to + + S(6) 1 gfw 96. + + -------- + svn 5170 + -------- + Added ceil and floor Basic functions. Ceil(x) is the + smallest integer greater than or equal to x. Floor(x) + is the largest integer less than or equal to x. Note + that all numbers in Basic are of type double in C. + + USER_PRINT + 10 print ceil(2.8), floor(2.8), ceil(-2.8), floor(-2.8) + + This USER_PRINT Basic program has the following output: + + 3 2 -2 -3 + + + -------- + svn 4988 + -------- + Added EOL$ Basic function. EOL$ is the end of line + character for whatever operating system you are + running. + + USER_PRINT + 10 PRINT "line 1"+EOL$+"line 2"+EOL$ + + The result of this USER_PRINT is + + line 1 + line 2 + + -------- + svn 4942 + -------- + Added additional parameter in PRINT for status. Writing + the status line to the screen can slow calculations + substantially under some conditions. + + PRINT + -status (t|f|n) + + t--Print status line. + f--Do not print status line. + n--Print status line every n milliseconds. + + -status 1000 would print the status line every + second. + + -------- + svn 4830 + -------- + Changed default for exchange species activty + coefficients to be equal to the Pitzer + aqueous activity coefficients when using Pitzer + aqueous model. Default is + -pitzer_exchange_gammas true. + + +------------------------------------------------------------ +Version 2.17.5: September 7, 2010 +------------------------------------------------------------ + +------------------------------------------------------------ +Version 2.17.4: September 2, 2010 +------------------------------------------------------------ + + -------- + svn 4771 + -------- + Added synonyms to TOTMOLE: TOTMOL, TOTMOLES + +------------------------------------------------------------ +Version 2.17.3: August 12, 2010 +------------------------------------------------------------ + + -------- + svn 4191 + -------- + Added new Basic functions: + + 10 total_Ca_in_moles = TOTMOLE("Ca") + + TOTMOLE provides the total number of moles of an element + or element valence state in solution. Special values are + "water", which gives number of moles of water, and + "charge", which gives total equivalents of charge + imbalance in solution (same as Basic function + CHARGE_BALANCE). In contrast, the Basic function TOT + returns moles per kilogram of water, or equivalents per + kilogram of water for TOT("charge"). + + 10 O18_permil = ISO("[18O]") + + + ISO gives an isotopic composition in the input units for + an isotope--permil, pmc, or TU in current version of + iso.dat. The string argument can be an isotope name, or + any item defined in the ISOTOPE_RATIOS data block, For + example, ISO("R(13C)_Calcite") will return the carbon-13 + composition of the calcite solid solution in permil + because of the definitions in iso.dat. + + 10 D_units$ = ISO_UNITS("D") + + ISO_UNITS gives the input units for the isotope, D_units$ = + "permil" in the example. The string argument can be an + isotope name or an item defined in the ISOTOPE_RATIOS data + block as explained for the Basic function ISO. + +------------------------------------------------------------ +Version 2.17.0: February 25, 2010 +------------------------------------------------------------ + + -------- + svn 4006 + -------- + + Changed the calculation of Specific Conductance (SC, uS/cm) + to be for the actual temperature of the SOLUTION (in output + and in BASIC function SC). + Previous versions calculated SC for 25 oC, whereas the + complexation model is done at the actual temperature. + To obtain SC at 25 oC, use keyword REACTION_TEMPERATURE, + for example: + + SOLUTION 1; K 1; Cl 1; -temp 99 + REACTION_TEMPERATURE; 25 + END + + The following example prints to the selected output + file the equivalent conductance in (mmho/cm / eq/L) at + 20 degrees C for a 1:1 chloride salt solution: + + USER_PUNCH + -head conc eq_EC_20 + -start + 10 punch tot("Cl"), SC / tot("Cl") * 1e-3 + -end + + where 1e-3 converts from microSiemens/cm to mmho/cm. + (The example given with svn 2448 multiplies SC's incorrectly + with the ratio of the temperatures.) + -------- + svn 3986 + -------- + Added an option for time-substepping in multicomponent + diffusion (-multi_D true), keyword TRANSPORT: + + -time_step 3600 3.0 # 3 time-substeps of 1200 seconds + + This option is useful to avoid a warning about negative + concentrations that may occur in MCD simulations. + + -------- + svn 3902 + -------- + Added four basic functions for use only with PHAST. The + functions are related to the volume, porosity, and + water saturation of a PHAST finite-difference cell: + + CELL_VOLUME--The total volume of the cell in liters. + CELL_PORE_VOLUME--The void volume of the cell in liters. + CELL_SATURATION--The fraction of the void volume filled + with water, unitless. + CELL_POROSITY--The porosity of the cell, equal to + CELL_PORE_VOLUME / CELL_VOLUME, unitless. + + + For example, in a USER_PUNCH program for a PHAST run, + the number of moles of dissolved chloride in a cell is + TOT("Cl")*CELL_PORE_VOLUME for confined flow simulations. + More generally, the number of moles of dissolved chloride + is TOT("Cl")*CELL_SATURATION*CELL_PORE_VOLUME, for confined + or unconfined flow. + + For solids, the number of moles of calcite in the + saturated part of a cell is + EQUI("Calcite")*CELL_SATURATION*CELL_PORE_VOLUME. For + unconfined flow, the solid reactants are distributed + between the saturated and unsaturated part of a water- + table cell. It is a limitation of PHAST that it is not + possible to determine the amounts of solid reactants + in the unsaturated part of a cell. Note that for + steady-state, unconfined flow, the saturation of cells is + constant and the unsaturated part of a water-table cell + is never part of the active domain. + + -------- + svn 3600 + -------- + A new 1/T^2 term (A5 coefficient) was added for all Pitzer-parameter + temperature expressions. + + P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + + A4*(TK*TK - TR*TR) + A5*(1/(TK*TK) - 1/(TR*TR)) + + where TK is temperature in Kelvin. The optional A5 parameter + is read following A4. + + -------- + svn 3591 + -------- + Added T^2 term to analytical expressions for log k. A T^2 term + can now be used in the analytical expressions for any log K. + The analytical expression is as follows: + + log10(K) = A1 + A2*TK + A3/TK + A4*log10(TK) + A5/TK^2 + A6*TK^2, + + where TK is in Kelvin. The A6 term is the new addition. The optional + A6 parameter is read following A5. + + -------- + svn 3485 + -------- + Added the active fraction model for calculating exchanger + compositions described by Appelo (1994), Water Resour. Res. 30, + 2793-2805. The active fraction model is useful for calculating + the decrease of selectivity when concentrations increase (more + specific sites being filled first). In the active fraction model, + log(K) of an exchange-half reaction depends on the equivalent + fraction on the exchanger: + + log(K) = log_k + a_f * (1 - ß_i) + + where log_k is the log of the equilibrium constant when all the + sites are occupied by ion i, + a_f is an empirical coefficient, and + ß_i is the equivalent fraction of i. + + a_f can be defined in EXCHANGE_SPECIES with -gamma after the WATEQ + Debye-Hueckel parameters. + Example: + + EXCHANGE_SPECIES + Na+ + X- = NaX; log_k -0.5 + -gamma 4.0 0.075 0.50 + + The association constant for NaX becomes: + log(K) = -0.5 + 0.50 * (1 - ß_Na) + + -------- + svn 3453 + -------- + Added Specific ion Interaction Theory (SIT) activity coefficient + model as described in Grenthe, Ingmar, Plyasunov, A.V., and + Spahiu, Kastriot, 1997, Estimations of medium effects on + thermodynamic data, in Modelling in Aquatic Chemistry, + Grenthe, Ingmar, and Puigdomenech, Inasi, eds, OECD + Publications, ISBN 92-64-15569-4, 724 p. + + Implementation is similar to the PITZER implementation, a + database with the SIT keyword invokes the SIT activity + coefficient model. Currently, No database is provided. + + The SIT keyword has two identifiers, + -epsilon and -epsilon1, where -epsilon gives the pairwise + interaction parameters and -epsilon1 gives the linear ionic + strength dependency of epsilon, if available. Both parameters + allow for temperature dependence with the same expression used + in PITZER. The five-term expression for temperature dependence is + as follows: + + P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + + A4*(TK*TK - TR*TR), + + where TK is Kelvin and TR is 298.15. + + Example: + SIT + -epsilon + Na+ Br- 0.05 # 0.01 + Na+ Cl- 0.03 # 0.01 + + -epsilon1 # not currently used + + + -------- + svn 3288 + -------- + + Additional arguments for the EDL function for the CD_MUSIC + surface complexation model. The values of charge, sigma, and psi + for the 0, 1, and 2 planes can be obtained from the EDL function. + + EDL("element", "surface") gives the amount of + element in the diffuse layer for "surface". + not including sorbed species. "surface" should + be the surface name, not the surface-site name + (that is, no underscore). + + Special values for "element" include: + "charge" - surface charge, equivalents. + For CD_MUSIC "charge" refers to plane 0. + "charge1"- surface charge on plane 1, equivalents + (CD_MUSIC only). + "charge2"- surface charge on plane 2, equivalents + (CD_MUSIC only). + "sigma" - surface charge density, C/m**2. + For CD_MUSIC "sigma" refers to plane 0. + "sigma1" - surface charge density on plane 1, + equivalents (CD_MUSIC only). + "sigma2" - surface charge density on plane 2, + equivalents (CD_MUSIC only). + "psi" - potential at the surface, Volts. + For CD_MUSIC "psi" refers to plane 0. + "psi1" - surface charge density on plane 1, + equivalents (CD_MUSIC only). + "psi2" - surface charge density on plane 2, + equivalents (CD_MUSIC only). + "water" - mass of water in the diffuse layer, kg. + -------- + svn 3189 + -------- + Density of solutions is now calculated from the concentrations + of dissolved species. The algorithm has been described by Millero + (1974), Millero (2000), Millero (2001) and has been used + successfully by Millero and Lepple (1973), Millero et al (1976), + Fernendez et al. (1982) and Millero (2000) to calculate the + density of seawater, estuaries, lagoons and lakes. + + The calculation relies on apparent molar volumes phi(i), + for individual aqueous species according to the following formula: + + phi(i) = phi(i,inf) + s(t)I^0.5 + beta(i)I + + where phi(i,inf) is the apparent molar volume of species i at + infinite dilution, s(t) is the Debije-Huckel limiting slope, beta(i) + is an empirical constant, and I is the ionic strength. + + s(t) is calculated as a function of temperature. Parameterizations of + phi(i,inf) and beta(i) use the following formulas: + + phi(i,inf) = a + bt +ct^2 + beta(i) = d + et + ft^2 + + where a, b, c, d, e, and f are empirical constants and t in Celcius. + Data input of the constants are in the keyword data block SOLUTION_SPECIES + using the new identifier -millero. + + Example: + + SOLUTION_SPECIES + Na+ = Na+ + log k 0.0 + -gamma 4.0 0.075 + -dw 1.33e-9 + -millero -3.46 0.1092 -0.000768 2.698 -0.106 0.001651 + + Apparent molar volume parameters have been included in the database + phreeqd.dat. Calculations made with this database will include + the calculated density in the "Description of solution". + + A new basic function, RHO, can be used to obtain the density in + USER_PRINT, USER_PUNCH, and RATES data blocks. + + Example: + + USER_PUNCH + -heading density + 10 PUNCH RHO + + -------- + svn 3183 + -------- + Added option for an equilibrium-phase to precipitate only, + parallel to dissolve_only option. + "pre" is added at the end of a line defining an equilibrium- + phase. No data fields may be omitted. Should not + be used when adding an alternative reaction. + Example: + EQUILIBRIUM_PHASES + Dolomite 0 0.1 dissolve_only + Quartz 0 1.5 precipitate_only + + -------- + svn 3160 + -------- + + Surface charge must be higher than -3000 equivalents, + when the diffuse double layer composition is + calculated with option -donnan. + + -------- + svn 3149 + -------- + + Diffusion through DDL water is multiplied with c_DDL,i / c_i + with option -only_counter false. c_DDL,i is the concentration in + DDL water, c_i is the concentration in free porewater. (Previous + versions used a multiplier of 1). + + Added -erm_ddl as parameter for aqueous species, to be defined + with keyword SOLUTION_SPECIES. erm_ddl (> 0) is an + enrichment factor in DDL water calculated with option -donnan: + c_DDL,i = c_i * Boltzmann_factor * erm_ddl + Example: + SOLUTION_SPECIES; Cs+ = Cs+; log_k 0; -erm_ddl 2.1 + Default: erm_ddl = 1.0. + + Added optional multicomponent diffusion of cations in interlayer + space of montmorillonite to keyword TRANSPORT. + In the example, + interlayer diffusion is true (default = false), + interlayer porosity is 0.09 (default = 0.1), + the porosity where interlayer diffusion stops is 0.01 + (default is 0), + the tortuosity factor is 150 (default = 100). + + TRANSPORT + -interlayer_D true 0.09 0.01 150 + + With interlayer_D true, also -multi_D true (and other + parameters) must be set, for example: + -multi_d true 1e-9 0.3 0.05 1.0 + Interlayer diffusion is calculated for the cations associated with X-, + defined with keyword EXCHANGE. + Mass_transfer = -A * (Dw' / t_f) * c_CEC * grad(beta) + A is surface area, A_porewater * (interlayer porosity / free + porewater porosity), + Dw' is the temperature corrected diffusion coefficient of the + aqueous species (defined in SOLUTION_SPECIES), + corrected to zero charge transfer, + t_f is the interlayer tortuosity factor (-), + c_CEC is concentration of total X-, mol(X-) / (L interlayer + water). L interlayer water = (L porewater + L DDL- + water) * (interlayer porosity / free porewater porosity), + grad(beta) is the gradient of the equivalent fraction. + + -------- + svn 2969 + -------- + Added basic functions that return the activity coefficient of + an aqueous species (gamma) and the log base 10 of the activity + coefficient of an aqueous species (lg). + + USER_PUNCH + -start + 10 punch gamma("H+") # activity coefficient + 20 punch lg("H+") # log base 10 activity coefficient + -end + + The functions return zero if the species is not defined for + the aqueous model or if the species is an exchange or surface + species. + +------------------------------------------------------------ +Version 2.15.0: February 5, 2008 +------------------------------------------------------------ + + -------- + svn 2680 + -------- + + Identifiers for paramaters controlling the integration by + CVODE have been added in the KINETICS data block. + + -bad_step_max bad_steps + -cvode_steps steps + -cvode_order order + + -bad_step_max bad_steps--This option was used only in the + Runge-Kutta method. Now, the value of this option is used for + CVODE as well. The value entered is the number of times that + PHREEQC will invoke CVODE to try to integrate a set of + rates over a time interval. Default is 500. + + -cvode_steps steps--The value given is the maximum number of + steps that will taken during one invocation of CVODE. + Default is 100. + + -cvode_order order--CVODE uses a specified number of terms in + an extrapolation of rates using the BFD method. Legal values + are 1 through 5. A smaller value (2) may be needed if the rate + equations are poorly behaved. The default is 5. + + -------- + svn 2457 + -------- + Added options to inverse modeling to translate current + solution definitions in PHREEQC to a Netpath .lon file and + (or) to .pat and model files. + + INVERSE_MODELING + -lon_netpath prefix + + At the beginning of the inverse modeling calculation, each + solution that has been defined (or saved) to PHREEQC, is + written to the file prefix.lon in a format readable by + DBXL (NetpathXL distribution). + + INVERSE_MODELING + -pat_netpath prefix + + A NETPATH model file is written for each inverse model that is + found. The model files are named prefix-n.mod, where n refers + to the sequence number of the model. In addition, a file named + prefix.pat is written that contains the solutions associated + with each model. The solutions are adjusted in accordance with + the deltas calculated for the inverse model. Thus, a solution + could be used for model 1 and model 2, but the concentrations + could be slightly different for the two models. The solutions + are identified by an initial integer corresponding to the + sequence number of the model, followed by the solution description. + + -------- + svn 2448 + -------- + Added calculation of specific conductance. Requires the + use of phreeqd.dat, which contains the diffusion coefficients + of aqueous species. If phreeqd.dat is used, the specific + conductance (uS/cm at 25 C) is printed in the + "Description of solution". + + The Basic function SC returns the value of the specific + conductance for the solution at 25 C. The following example + would print to the selected output file the equivalent conductance + in (mmho/cm / eq/L) at 20 degrees C for a 1:1 chloride salt + solution: + + USER_PUNCH + -head conc eq_EC_20 + -start + 10 punch tot("Cl"), SC / tot("Cl") / 1e3 * .89 * 298 / 293 + -end + + where 1e-3 converts from microSiemens/cm to mmho/cm, .89 + accounts for the viscosity at 20 C, and 298/293 + accounts for the temperature of 20 C. + +------------------------------------------------------------ +Version 2.14.3: November 17, 2007 +------------------------------------------------------------ + -------- + svn 2312 + -------- + Added new option to PITZER datablock, use_etheta t/f. + If true, the nonsymmetric mixing terms--cation/cation and + anion/anion of different charge--are included; if false + these terms are excluded from all equations. Default is true. + + PITZER + -use_etheta true + + + -------- + svn 2270 + -------- + Added additional parameters Pitzer activity formulation for + neutral species, MU and ETA. MU applies to nnn, nnn', nn'n'', + nna, nn'a, nnc, nn'c interactions, where n, n', and n'' are + neutral species, a is an anion and c is a cation. ETA applies + to ncc' and naa' interactions. Also modified LAMDA for the + special case of nn interactions (coefficients in osmotic and + ln equations are different than other interaction types). + Source of equations is Clegg and Whitfield, 1991, Activity + coefficients in natural waters, Chapter 6, in Pitzer, K.S. + (Ed.) Activity Coefficients in Electrolyte Solutions, 2nd + Ed. CRC Press, Boca Raton. Removal of the 6 coefficient in + last two terms of eq 35 and 36 (p. 2404) per Cleg and + Whitfield, 1995, Geochimica et Cosmochemica Acta, v. 59, + no. 12, pp 2403-2421. Order of species in definitions should + not matter. + + PITZER + -MU + CO2 CO2 CO2 ? # nnn + CO2 CO2 NH3 ? # nnn' + CO2 B(OH)3 NH3 ? # nn'n'' + CO2 CO2 Ca+2 ? # nnc + CO2 CO2 Cl- ? # nna + CO2 NH3 Ca+2 ? # nn'c + CO2 NH3 Cl- ? # nn'a + -ETA + CO2 Ca+2 Mg+2 ? # ncc' + CO2 Cl- SO4-2 ? # naa' + + As with all other Pitzer parameters, a five-term expression + for temperature dependence is available: + + P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + + A4*(TK*TK - TR*TR), + + where TK is Kelvin and TR is 298.15. A0 through A4 are + defined in order. Any undefined values are assumed to + be zero. + + -MU + CO2 CO2 CO2 ? ? ? ? ? # nnn + +------------------------------------------------------------ +Version 2.14.2: September 17, 2007 +------------------------------------------------------------ + + Fixed logic of memory checking for PhreeqcI. This serious + bug makes versions 2.14.0 and 2.14.1 unusable. + +------------------------------------------------------------ +Version 2.14.1: September 5, 2007 +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.14.0: August 30, 2007 +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.13.3: February 15, 2007 +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.13.2: February 1, 2007 +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.13.1: January 16, 2007 +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.13.0: November 3, 2006 +------------------------------------------------------------ + + -------- + svn 1368 + -------- +(1) Added multicomponent diffusion (MCD) to transport + capabilities. MCD allows different tracer diffusion + coefficients for species, but calculates charge balanced + transport. In the example, MCD is specified to be true, + default tracer diffusion coefficient for species (Dw) is 1e-9, + porosity is set to 0.3, porosity limit is set to 0.05, and an + exponent of porosity (n) is set to 1.0. Effective diffusion + coefficient is defined by the equation: De = Dw * porosity^n. + Diffusion stops when the porosity falls below the porosity + limit. + + TRANSPORT + -multi_d true 1e-9 0.3 0.05 1.0 + + Added tracer diffusion coefficient to SOLUTION_SPECIES + definitions, -dw identifier. + + SOLUTION_SPECIES + H+ = H+ + log_k 0.0 + -gamma 9.0 0.0 + -dw 9.31e-9 + +(2) Added phreeqd.dat database with diffusion coefficients (-dw) + defined for aqueous species in database directory. + +(3) Added BASIC functions to obtain and modify the porosity + in a cell. The functions can be used in BASIC programs + defined with keyword RATES, USER_PRINT, USER_PUNCH and + USER_GRAPH. + + get_por(cell_no) # returns the porosity in cell + # 'cell_no' + + change_por(0.21, cell_no) # porosity of cell 'cell_no' + # becomes 0.21 + +(4) Mobile surface and Donnan option in SURFACE. Mobile surfaces + are meant for modeling transport of colloids. Only surfaces with + a diffuse double layer can be transported (the ensemble must be + electrically neutral). Surfaces related to equilibrium-phases + and kinetics cannot be transported. + + Example 1: Use donnan assumption to calculate the explicit + composition of the diffuse layer of surfaces. Thickness of the + diffuse layer is defined to be 1e-7 meters. (Default thickness + is 1e-8 meters.) Hfo (both sites Hfo_w and Hfo_s) is a surface + that is transported with advection and dispersion. The diffusion + coefficient of 1e-13 m^2/s is used with option -multi_d true in + TRANSPORT. Sfo is an immobile surface (Dw = 0). + + SURFACE + -donnan 1e-7 + Hfo_w 97.5e-5 600 88e-3 Dw 1e-13 + Hfo_s 2.5e-5 + Sfo_w 97.5e-5 600 88e-3 Dw 0 + Sfo_s 2.5e-5 + + + Example 2: Define Donnan calculation information. Thickness + of the diffuse layer is 1e-8 meters, and relative viscosity is + 0.5. Relative viscosity only applies to multicomponent diffusion + of solutes in the diffuse layer. (Default viscosity is 1.0.) + + SURFACE + -donnan 1e-8 viscosity 0.5 + + Example 3: Define Donnan calculation information. Thickness + of the diffuse layer is 1.5 Debye lengths, maximum fraction of + water that can be in the diffuse layer is 0.9. (Default + thickness in Debye lengths is 1, default limit is 0.8.) + + SURFACE + -donnan debye_lengths 1.5 limit_ddl 0.9 + + When option '-only_counter_ions' is used in conjunction with + with '-donnan', all the co-ions (with the same sign of charge as + the surface) will be excluded from the DDL, and will be given a + concentration of (near) zero in the DDL. + +(5) Added special BASIC function to change the diffusion + coefficient of (part of) a SURFACE, and hence to change the + status from mobile to immobile or immobile to mobile. + + Example 1: take a fraction 0.2 of 'Hfo', rename it to + 'Sorbedhfo', with a diffusion coefficient of 0, in cell 'cell_no' + + USER_PRINT + 10 print 'Changing surface in cell ', cell_no + 20 change_surf("Hfo", 0.2, "Sorbedhfo", 0, cell_no) + + + Example 2: change the diffusion coefficient of 'Hfo' to 1e-12 + m2/s in cell 'cell_no' + + 10 change_surf("Hfo", 1, "Hfo", 1e-12, cell_no) + + This function can be used in BASIC programs defined with keywords + RATES, USER_PRINT, USER_PUNCH and USER_GRAPH. For correct + operation of 'change_surf', the surface components must have + been defined with the same surface species (the association + constants may differ) and the same diffuse layer thickness or + Debye length. The surfaces will be adapted at the end of a + calculation step. The result of change_surf does not show up in + print or punch results of that step, but the reformatting is + effective in the next timestep calculations. + + + -------- + svn 1337 + -------- + Added -add_logk to NAMED_EXPRESSIONS keyword. + + NAMED_EXPRESSIONS + Log_alpha_14C_CO3-2/CO2(aq) + -add_logk Log_alpha_14C_CO3-2/CO2(g) 1 + -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 + + -------- + svn 1281 + -------- + Added new option to PITZER data block to allow definition of + alpha1 and alpha2 for specific electrolytes. Entries are + following -ALPHAS are Ion1, Ion2, alpha1, alpha2. Both + alpha1 and alpha2 should be defined. Default is 0.0 for + undefined values following Ion1 and Ion2. + + Example: + + PITZER + -ALPHAS + # + # Defaults for ion valences in salts + # + # 1-N (only B1): alpha1 = 2 + # 2-2: alpha1 = 1.4 alpha2 = 12.0 + # 3-2, 4-2: alpha1 = 2 alpha2 = 50 + # + #Ion1 Ion2 Alpha1 Alpha2 + Fe+2 Cl- 2 1 + Fe+2 SO4-2 1.559 5.268 + + -------- + svn 1279 + -------- + Added new Basic function OSMOTIC that returns the + osmotic coefficient if the Pitzer model (PITZER keyword data + block) is used or 0.0 if the ion-association model is used. + + Example: + + USER_PRINT + 10 PRINT "Osmotic coefficient: ", OSMOTIC + + + -------- + svn 1245 + -------- + Enabled redox in Pitzer model with option in + PITZER keyword. Typically, the option will be included + in the pitzer database file. + + Example: + + PITZER + -redox TRUE + + The default database for the Pitzer model does not contain + any redox definitions and the default value for the option + is FALSE. At a minimum, species O2 and H2 must be defined + in the database or input file to allow redox calculations. + + -------- + svn 1207 + -------- + Added option to force an equilibrium phase to be + included in the equality constraints. Normally, the SIs of + equilibrium phases are optimized to be negative and the + sum of SIs is minimized. If -force_equality is used, then + the phase must reach its target SI or the calculation fails + with an error. + + Example: + + EQUILIBRIUM_PHASES + Fix_pH -7 NaOH + -force_equality + Calcite 0 + Dolomite 0 + CO2 -3.5 + + One example of using the new option would be to ensure that + a target pH is attained, as in the example above. + + -------- + svn 1179 + -------- + New option (-sites_units or -sites) allows alternative + units (sites/nm^2) for definition of number of sites for a + surface. This approach requires better consistency among the + parameters as both the number of sites and the surface area + are based on the mass. It makes more sense than the default, + which requires the number of sites (first numeric item in a + line) to be defined in units of moles, independently of the + number of grams of sorbent. Units descriptor is either DENSITY, + for defining number sites/nm^2, or ABSOLUTE, for defining + number of sites in moles. Optionally, sites, sites_units, or + -s[ites_units]. ABSOLUTE is the default for backward + compatibility with input files. + + Example: + + SURFACE 1 + -sites_units DENSITY + SurfOH 2.6 600. 1.0 + SurfaOH 2.6 30. 2.0 + + Explanation: + + In this example, Surf has a site density of 2.6 sites per + nanometer squared, a specific area of 600 meters squared per + gram, and a mass of 1 gram. Surfa has a site density of 2.6 + sites per nanometer squared, a specific area of 30 meters + squared per gram, and mass of 2 grams. + + + -------- + svn 1096 + -------- + + Allows solids and gases in the equations for PHASES. This + capability simplifies the definitions for gas and solid + isotopic components. Solids must be identified with "(s)" and + gases with "(g)". The first entity on the left- hand-side of + the equation must be the stoichiometric formula of the solid + or gas component being defined, optionally with (g) or (s). In + turn gases and solids included in the equation must be defined + with reactions that ultimately allow the defined species + (C[18O]2(g) in this case) in terms of aqueous species. + + Example: + + PHASES + C[18O]2(g) + C[18O]2(g) + CO2(g) = 2CO[18O](g) + log_k 0.602059991327962396 # log10(4) + + -------- + svn 1092 + -------- + CD_MUSIC sorption model has been implemented. + Still missing logic for surfaces related to equilibrium- + phases and kinetics. Has explicit calculation of diffuse + layer composition with Donnan assumption. Old diffuse-layer + calculation will not be implemented. + + Example: + + SURFACE + Goe_uniOH .000552 96.387 1 + -capacitance 1.1 5 + Goe_triO .000432 + -cd_music + -donnan + + Explanation: + + 1.1 5 are capacitances for the cd-music model for 0-1 and 1-2 + planes, respectively. + -cd_music specifies that the surface is a cd-music surface. + -donnan optionally calculates the diffuse layer composition + with the Donnan model. + + Example: + + SURFACE_SPECIES + Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O + log_k 20.1 # eq 7 K1, Kin1 + -cd_music -1 -6 0 0.25 5 + + Explanation: + + -cd_music--this option is used to specify the change in charge + by the reaction for three planes, 0 (specific sorption at the + surface), 1 (Stern layer), and 2 (or d, the diffuse layer). + The five numbers in the form above are (1) the change + in charge for plane 0 due to loss or gain of hydrogen and + oxygen at plane 0, (2) the change in charge for plane 1 due to + the hydrogen and oxygen in the ligand that are located at + plane 1, (3) the change in charge in diffuse layer, plane 2, + (4) the fraction of the central ion charge that is + associated with plane 0, and (5) the charge on the central + ion. + + In this example the change in charge at plane 0 is (delta z0) = + -1 (loss of one hydrogen) + 0.25*5 (contribution from As+5) = + 0.25. The charge at plane 0 becomes -0.5 + 0.25 = -0.25. + The change in charge at plane 1 is (delta z1) = -6 (3 oxygens of + the ligand are located at plane 1) + (1-0.25)*5 (contribution + from As+5) = -2.25. The charge at plane 1 becomes 0 + (-2.25) = + -2.25. There is no change in charge associated with plane 2. + The total charge of the species is -0.25 (plane 0) + -2.25 + (plane 1) + 0 (plane 2) = -2.5. + + Alternatively to the form above, the changes in charge + on the three planes can be entered directly as the first + three numbers in the option, followed by two zeros. Thus, the + following is equivalent to the -cd_music definition above, and + consistent with more recent papers which would list + delta z0 = 0.25, delta z1 = -2.25 and delta z2 = 0: + + SURFACE_SPECIES + Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O + log_k 20.1 # eq 7 K1, Kin1 + -cd_music 0.25 -2.25 0 0 0 + + -------- + svn 675: + -------- + Added PRINT option to print the species that contribute + to alkalinity. Alkalinity distribution is printed in + the output file following the distribution of species. + Default at program startup is false. + + Example: + + PRINT + -alkalinity true + +------------------------------------------------------------ +Version 2.12: +------------------------------------------------------------ + +* Made aqueous activity coefficients the default activity + coefficients for exchange species when using the + Pitzer formulation. New option in EXCHANGE is + -pitzer_exchange_gammas T/F, default is true; + defining "false" sets exchange activity coefficients + to 1.0. Option has no effect for ion-association + model (non-Pitzer). + + +* Added multiplier format to REACTION steps and KINETICS steps, + which simplifies definition of multiple equal reaction increments. + + This definition: + + INCREMENTAL_REACTIONS true + REACTION + H2O 1 + -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles + + is equivalent to this definition: + + INCREMENTAL_REACTIONS true + REACTION + H2O 1 + -36 -4 -4 -4 -.25 -.25 -0.19 -0.1 -0.1 -0.1 + -0.1 -0.05 -0.05 -0.05 moles + + + +* Added Pitzer activity formulation. Use pitzer.dat database + to invoke the Pitzer model. Should have same capabilities + as ion-association model except explicit diffuse layer + calculation is not implemented with the Pitzer model. + New keyword is PITZER with following options: + + PITZER + -MacInnes T/F # uses MacInnes assumption or unscaled for + # individual activities and activity coefficients + -B0 + Na+ Cl- 0.0765 -777.03 -4.4706 0.008946 -3.3158E-6 + -B1 + Na+ Cl- 0.2664 0 0 6.1608E-5 1.0715E-6 + -B2 + Mg+2 SO4-2 -37.23 0 0 -0.253 + -C0 + Na+ Cl- 0.00127 33.317 0.09421 -4.655E-5 + -THETA + K+ Na+ -0.012 + -LAMDA + Na+ CO2 0.1 + -ZETA + H+ Cl- B(OH)3 -0.0102 + -PSI + Na+ K+ Cl- -0.0018 + + A five-term expression for temperature dependence is available + for all Pitzer parameter values: + P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + + A4*(TK*TK - TR*TR), + where TK is Kelvin and TR is 298.15. + +* Cl1mp is a new multiple precision version of routine cl1, + a simplex-based optimization routine. Cl1mp was develeped + by using the Gnu Multiple Precision package (gmp). + Calculations are carried out to about 30 significant + digits. Cl1mp may help in some situations where roundoff + errors are a problem, but it is still possible that roundoff + errors will cause cl1mp to fail to find a solution to an + optimization problem. The mp version has the following + options in INVERSE_MODELING: + + -multiple_precision T/F--causes the mp version + to be used in inverse modeling calculations. + -mp_tolerance 1e-12--tolerance for mp version of + cl1. As in cl1, numbers less than the + tolerance are considered to be zero. + 1e-12 is the default. + -censor_mp 1e-20--as calculations occur in the + linear equation array, elements less + than this value are set to zero. Default + is 1e-20. A value of 0.0 causes no + censoring to occur. + +------------------------------------------------------------ +Version 2.11: +------------------------------------------------------------ + +* A new database, minteq.v4.dat, has been translated from + version 4.02 of MINTEQA2 and is included in all + distributions. The database minteq.dat from earlier + version of MINTEQA2 has been slightly revised and is + also included. + +------------------------------------------------------------ +Version 2.10: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.9: +------------------------------------------------------------ +* Added new keyword COPY that allows a data entity + to be copied from one index to a new index + or to a range of indicies. Format is + + COPY keyword index index_start[-index_end] + + where keyword may be SOLUTION + EQUILIBRIUM_PHASES + EXCHANGE + GAS_PHASE + KINETICS + MIX + REACTION + REACTION_TEMPERATURE + SOLID_SOLUTION + SURFACE + +* Added new Basic functions + b$ = PAD(a$, 20) pads a$ to a total of 20 characters + with spaces and stores result in b$. PAD returns + a copy of a$ if a$ is more than 20 characters. + i = INSTR(a$, b$) sets i to the character position of + string b$ in a$, 0 in not found. + b$ = LTRIM(a$) trims white space from beginning of + string a$ and stores result in b$. + b$ = RTRIM(a$) trims white space from end of string + a$ and stores result in b$. + b$ = TRIM(a$) trims white space from beginning and + end of string a$ and stores result in b$. + + +* Added new Basic function SYS that calculates the + total amount of an element in all phases (solution, + equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase). KINETIC reactions are not included. + The function has two forms: (1) one element name as an + argument (variable names are user specified) + + 10 t = SYS("As") + + the function will return the total arsenic in the system. + (2) 5 argumens + + 10 t = SYS("As", count_species, names$, types$, moles) + + will return the total arsenic in the system to t; count_species-- + the number of species that contain arsenic, including + solution, equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase species; names$--a character array that has the + name of each species; type$--a character array that specifies the + type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. + Diff refers to the amount of the element in the diffuse layer of + a surface when the explicit diffuse layer calculation is used; + moles--an array containing the number of moles of the element in + the species. The sum of moles(i) is equal to tot. + + SYS has several special arguments for the form + SYS("arg", count, names$, types$, values) + arg is one of the options listed below. + count is a single numeric value and is the number of elements + in the following arrays. + name$ is an array of string values. + type$ is an array of string values. + values is an array of numeric values. + + Values of arg: + + elt_name returns total number of moles of element in system. + count is the number of species for the element in + the system, including aqueous, exchange, surface, + equilibrium_phase, solid solution component, and + gas phase "species". + Arrays are filled for each "species"; values are moles. + "elements" returns total number of moles of dissolved elements other + than H and O. + count is number of elements, valence states, + exchangers, and surfaces. + Arrays are filled for each element and valence state, + type is "dis"; exchanger, type is "ex", + and surface, type is "surf". Values are moles. + "phases" returns maximum saturation index of all phases. + count is number of phases in system. + Arrays are filled for each phase; values are + saturation indexes. + "aq" returns sum of moles of all aqueous species. + count is number of aqueous species in system. + Arrays are filled with each aqueous species; + values are moles. + "ex" returns sum of moles of all exchange species. + count is number of exchange species in system. + Arrays are filled with each exchange species; + values are moles. + "surf" returns sum of moles of all surface species. + count is number of surface species in system. + Arrays are filled with each surface species; + values are moles. + "s_s" returns sum of moles of all solid solution components. + count is number of solid solution components in system. + Arrays are filled with each solid solution component; + values are moles. + "gas" returns sum of moles of all gas components. + count is number of gas components in system. + Arrays are filled with each gas component; + values are moles. + +* Added new Basic function, DESCRIPTION, that has the value + defined for the description field of the SOLUTION keyword line. + +* Added alternative ordinary differential equation solver + called CVODE, a set of C routines from the Lawrence + Livermore National Labs. CVODE is part of the SUNDIALS + package. CVODE is used in place of the Runge Kutta method + when "-cvode true" is used within a KINETICS data block. + + KINETICS + -cvode true + +------------------------------------------------------------ +Version 2.8: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.7: +------------------------------------------------------------ +Changed format of selected output file: + Removed quotations surrounding strings in headings. + Removed quotations surrounding strings in state variable. + All fields are 12 or 20 places depending on + -high_precision. + Headings are not truncated even if longer than + specified precision. + For isotopes, missing value is -9999.9 + Selected output is updated each simulation. + If a species or phase is defined + subsequent to the simulation where SELECTED_OUTPUT + was defined it will appear in the selected output + file in the simulation in which it is defined and + in subsequent simulations. + +Added strings for each file, which can be extracted from the + executable file with the "ident" command. + +Fixed null pointer for isotope_ratios if Basic routine + was undefined. + +Fixed problem in C++ if structure name is same as member name. + logk member of logk structure was renamed to log_k. + +Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, + SOLUTION_SPECIES, and SURFACE_SPECIES. + + -add_constant -0.301 + + log K is augmented by the specified constant. + + +Theory and implementation of isotopes in PHREEQC is documented in: + +Thorstenson, D.C., and Parkhurst, D.L., 2002, Calculation of +individual isotope equilibrium constants for implementation in +geochemical models: U.S. Geological Survey Water-Resources +Investigations Report 02-4172, 129 p. + +Added KEYWORDS: + +ISOTOPES + Element + -isotope isotope_name units standard_ratio + -total_is_major T/F (OPTION IS DISABLED!!) + +CALCULATE_VALUES + Name + -start + Basic statements, must have SAVE + -end + +ISOTOPE_RATIOS (for printing) + Name=Calculate_values_name Isotope_name + +ISOTOPE_ALPHAS (for printing) + Name=Calculate_values_name Named_logk=named_expression_name + +Basic functions: + calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES + lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS + lk_phase("name") log10(K) of definition in PHASES + lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES + sum_gas("template","element") Sum of element in gases with specified template, moles. + Example: + template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases + sum_species("template","element") Sum of element in aqueous, exchange, and surface species with + specified template (moles) + sum_s_s("s_s_name","element") Sum of element in a specified solid solution (moles) + +PRINT keyword: + -initial_isotopes T/F + -isotope_ratios T/F + -isotope_alphas T/F + -censor_species 1e-8 # omit species from Distribution of Species if less than + # relative minimum of an element or element redox state + # total concentration + +SELECTED_OUTPUT keyword: + -calculate_values name1 name2 ... + -isotopes minor_isotope1 minor_isotope2 .... + +Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic + interpreter. LK_SPECIES("CaHCO3+") returns the + log k for the association reaction for the ion pair + CaHCO3+ at the current temperature. The log K is + for the reaction as defined in the database or + input file. Similarly, + LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the + value for the log K at the current temperature using + expressions defined in NAMED_LOG_K data block; + LK_PHASE("Calcite") returns the value of log K + for calcite at the current temperature for the + dissociation reaction defined in the database or + input file. Values are "log10" values. +Example for Basic program: + 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") + 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") + 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 + +NAMED_EXPRESSION--New keyword data block. + + This data block was implemented to facilitate isotopic + calculations. It allows analytical expressions that + are functions of temperature to be defined. The purpose + is to separate the fractionation factors from the log + K, so that the fractionation factor or its temperature + dependence can be easily modified. The named expression + can be added to a log K for a species or phase by the + -add_logk identifier in SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data + block. Log K, Delta H, and analytical expressions for a + log K can be defined with identifiers -log_k, -delta_h, + and -analytical_expression as described in SOLUTION_SPECIES + in WRIR 99-4259. Fractionation factors are often defined + as 1000*ln(alpha). The identifier -ln_alpha1000 can be used + to enter data in this form. The analytical expression is the + same as defined in SOLUTION_SPECIES, but the result of the + expression is converted to log10(alpha) by dividing by + 1000*ln(10) before it is summed into log K values. + +NAMED_EXPRESSIONS + Log_K_calcite # CaCO3 + 2H3O+ = Ca+2 + 3H2O + CO2 + log_k 8.201 + delta_h -8.035 kcal + -analytic 292.29 0.015455 -24146.841 -94.16451 2248628.9 + + Log_alpha_18O_CO2(aq)/Calcite + -ln_alpha1000 3.8498 0.0 10.611e3 0.0 -1.8034e6 + + Log_alpha_13C_CO2(aq)/Calcite + -ln_alpha1000 2.72 0.0 0.0 0.0 -1.1877e6 + +------------------------------------------------------------ +Added identifier -add_logk to SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, and PHASES data + block. + + Allows a named expression to be added to the definition + of the log K for a species or phase. In the following + example, the log K for the phase Ca[14C][18O]3 is summed from + four parts, one defined with the log_k identifier and the + other three parts from expressions defined in NAMED_EXPRESSIONS. + The named expression is multiplied by the coefficient at the + end of the line before it is summed into the log K. A missing + coefficient is 1.0 by default. + +PHASES + Ca[13C][18O]3 + Ca[13C][18O]3 + 3CO2 + 2H3O+ = Ca+2 + 3H2O + 3CO[18O] + [13C]O2 + log_k 0.903089986991 # 3*log10(2) + -add_logk Log_K_calcite 1.0 + -add_logk Log_alpha_13C_CO2(aq)/Calcite 1.0 + -add_logk Log_alpha_18O_CO2(aq)/Calcite 3.0 + + +SOLUTION keyword: + At present, can only define isotopes in the units defined in ISOTOPES. + +------------------------------------------------------------ +Version 2.6: +------------------------------------------------------------ + + No new features. + +------------------------------------------------------------ +Version 2.5: +------------------------------------------------------------ +Added the capability to use square brackets to define an + "element" name. The brackets act like quotation marks + in that any character string can be used within the + brackets as an element name. For example, [Fe3], [13C], + and [N5] are now legal "element" names. All element + names without brackets must begin with a capital letter, + followed by zero or more lower case letters and underscores. + +Added identifier -activity_water for a species in SOLUTION_SPECIES + data block. This identifier has been added for future updates + that will allow isotopic calculations. It is intended to be + used only for isotopic variations of H2O, like D2O or + H2[O18]. It forces the activity coefficient for the + species to be activity(water)/55.5. This effectively sets + the activity of the species to the mole fraction in + solution. + +Added identifier -bad_step_max to KINETICS data block. + An integer following -bad_step_max gives the maximum number + of times a rate integration may fail before execution of the + program is terminated. Default is 500. + +------------------------------------------------------------ +Version 2.4: +------------------------------------------------------------ + +------------------------------------------------------------ +Added identifier -warnings to PRINT keyword. + + An integer following -warnings gives the maximum number + of warnings to print into the output file. A negative + number allows all warnings to be printed. + + Example: -warnings 20 + +------------------------------------------------------------ +Changed the results of the function CELL_NO in Basic programs. + + Function cell_no in Basic now prints a number equivalent + to -solution in SELECTED_OUTPUT data block. It gives the + solution number for initial solution calculations and the + solution being used in batch reaction calculations. + Result is the same as previous versions for ADVECTION or + TRANSPORT calculations. + +------------------------------------------------------------ +Version 2.3: +------------------------------------------------------------ +DATABASE--New keyword data block + + It must be the first keyword in the input file. + The character string following the keyword is + the pathname for the database file to be used + in the calculation. The file that is specified + takes precedence over any default database + name, including environmental variable + PHREEQC_DATABASE and command line arguments. + +LLNL_AQUEOUS_MODEL_PARAMETERS--New keyword data block + + Added new keyword to make aqueous model similar to + EQ3/6 and Geochemists Workbench when using + llnl.dat as the database file. Values + of Debye-Huckel a and b and bdot (ionic strength + coefficient) are read at fixed temperatures. + Linear interpolation occurs between temperatures. + + New options for SOLUTION_SPECIES are + -llnl_gamma a , where a is the ion-size parameter. + -co2_llnl_gamma , indicates the temperature dependent + function for the bdot term given in + -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS + will be used. Applies to uncharged + species only. + +LLNL_AQUEOUS_MODEL_PARAMETERS +-temperatures + 0.0100 25.0000 60.0000 100.0000 + 150.0000 200.0000 250.0000 300.0000 +#debye huckel a (adh) +-dh_a + 0.4939 0.5114 0.5465 0.5995 + 0.6855 0.7994 0.9593 1.2180 +#debye huckel b (bdh) +-dh_b + 0.3253 0.3288 0.3346 0.3421 + 0.3525 0.3639 0.3766 0.3925 +-bdot + 0.0394 0.0410 0.0438 0.0460 + 0.0470 0.0470 0.0340 0.0000 +#cco2 (coefficients for the Drummond (1981) polynomial) +-co2_coefs + -1.0312 0.0012806 + 255.9 0.4445 + -0.001606 + +------------------------------------------------------------ +Added function SURF to Basic. + + SURF("element", "surface") gives the amount of element + sorbed on "surface". "surface" should be the surface + name, not the surface-site name (that is, no underscore). + +------------------------------------------------------------ +Allow decimals in definition of secondary master species. + + Some redox states do not average to integers, + for convenience in identifying them, decimal numbers + may be used within the parentheses that define the + redox state, example S(0.3) could be used in the + MASTER_SPECIES data block for the valence state of + aqueous species S6-2. + +------------------------------------------------------------ +Eliminate echo of input file in PRINT data block. + + -echo_input T/F turns echoing on and off. + Default is true, initial value is true. + +------------------------------------------------------------ +Added option for an equilibrium-phase to dissolve only. + "dis" is added at the end of a line defining an equilibrium- + phase. No data fields may be omitted. Should not + be used when adding an alternative reaction. + Example: + EQUILIBRIUM_PHASES + Dolomite 0.0 0.001 dis + +------------------------------------------------------------ +Version 2.2: +------------------------------------------------------------ +Added function EDL to Basic. + EDL("element", "surface") gives the amount of + element in the diffuse layer for "surface", not + including sorbed species. "surface" should be + the surface name, not the surface-site name + (that is, no underscore). + + Special values for "element" include: + "charge" - gives surface charge, equivalents. + "sigma" - surface charge density, C/m**2. + "psi" - potential at the surface, Volts. + "water" - mass of water in the diffuse layer, kg. + +------------------------------------------------------------ +End of Features not documented in WRIR 99-4259. +------------------------------------------------------------ + + + +************************************************************ +************************************************************ +* Revisions and Bug Fixes * +************************************************************ +************************************************************ + +------------------------------------------------------------ +Version @PHREEQC_VER@: @PHREEQC_DATE@ +------------------------------------------------------------ + -------- + svn 5570 + -------- + In SELECTED_OUTPUT; -totals, a redox state defined + with a "+" sign, such as Fe(+3), was not recognized + ("Fe(3)" worked correctly). Now Fe(+3) is + synonymous with Fe(3). + +------------------------------------------------------------ +Version 2.18.0: April 9, 2011 +------------------------------------------------------------ + -------- + svn 5212 + -------- + Subscript error in solver (ineq) when reseting deltas + after optimization failed. + + -------- + svn 4996 + -------- + Had conversion conversion to Kelvin as 273.16 in Basic + function TK, should be 273.15. + + -------- + svn 4955 + -------- + Changed O2(g) constant in Amm.dat and iso.dat to + definition from llnl.dat. + + -------- + svn 4954 + -------- + Added two more parameter sets in series of attempts + to converge: tolerance/100 and tolerance/1000. + + -------- + svn 4943 + -------- + Added separate As(3) in sit.dat. + + -------- + svn 4854 + -------- + Added two additional convergence parameter sets: + ineq_tol/100 and ineq_tol/1000. + + -------- + svn 4840 + -------- + Added missing -dw parameters to MgCO3, MgHCO3, and + MgSO4 aqueous species in phreeqc.dat. + +------------------------------------------------------------ +Version 2.17.5: September 7, 2010 +------------------------------------------------------------ + -------- + svn 4793 + -------- + Revised fix for exponential of negative number + in Basic. Error message for negative number raised + to a fractional power. + + +------------------------------------------------------------ +Version 2.17.4: September 2, 2010 +------------------------------------------------------------ + -------- + svn 4771 + -------- + Added synonyms to TOTMOLE: TOTMOL, TOTMOLES + Fixed bug with negative exponential in basic, + for example -0.006^0.9 + +------------------------------------------------------------ +Version 2.17.3: August 12, 2010 +------------------------------------------------------------ + + -------- + svn 4727 + -------- + Increased maximum iterations in cl1 solver. One test + case failed after new compiler was installed. + + -------- + svn 4700 + -------- + Initialized (nearly) all variables in class. + + -------- + svn 4697 + -------- + Fixed bug with second PITZER data block, parameters + were not updated if temperature was not changed. + + -------- + svn 4698 + -------- + Modified PHRQ_malloc and PHRQ_free logic. These routines + are used in almost all cases. + + -------- + svn 4694 + -------- + Initialized variables for V_M structure, rxn->dz (for CD_MUSIC), + Fixed problem where definitions in second SIT data block were + not added to model. + + -------- + svn 4677 + -------- + Renamed all variables that "shadowed" class variables. + + -------- + svn 4643 + -------- + Made isfinite a macro. + + -------- + svn 4539 + -------- + Fixed bug with long file names in inverse modeling files + netpath.fil or model.fil. + + -------- + svn 4490 + -------- + Redox had never been enabled for the SIT formulation. + Added the switch to include the hydrogen balance + equation for SIT. + + -------- + svn 4458 + -------- + Tweaked the convergence parameters for Pitzer log + gamma unknowns. Set a maximum step size for these + unknowns. Also changed usage of internal flags + for Pitzer calculations related to initial solution + calculations. Corrected print of Gamma iterations. + + -------- + svn 4399 + -------- + Error in PHRQ_calloc. Size of allocated block was + not set. Under some situations, could cause serious + errors and a crash. + + -------- + svn 4376 + -------- + Error in logic for removing unstable phases for Pitzer + and SIT. + + -------- + svn 4233 + -------- + Removed duplicate parameter for Na+ -- Cl- in sit.dat. + Value of 0.03 was entered erroneously for both Na/Cl and Cl/Na. + +------------------------------------------------------------ +Version 2.17.0: February 25, 2010 +------------------------------------------------------------ + -------- + svn 4115 + -------- + Fixed bugs with unititialized strings in Basic, which + caused an error in renumbering with PhreeqcI. Tested + most Basic functions. Fixed bugs with LG and GAMMA + functions, which did not return the correct values + for H+. GET_POR now returns 0 if it is not a TRANSPORT + calculation. + + + -------- + svn 4066 + -------- + Fixed bug with SIT calculations (and Pitzer). The + number of solver iterations was too few (200). With + SIT and Pitzer, each species has an unknown, so the + number of unknowns is large for a system with many + elements. Now set the maximum iterations to be + equal to the number of unknows plus the number of + equations/inequalities. + + -------- + svn 4023 + -------- + Trapped error when -mole_balance option was used in + SOLUTION_SPECIES and one of the stated elements was + not defined. + + -------- + svn 4022 + -------- + Redefined CN- and SCN- to be new elements Cyanide and + thiocyanate in llnl.dat. Former definitions were not + useful because cyanide and thiocyanate were never + stable and defining a master species as CN- caused + problems with mole balances, appearing in solutions + without any carbon. + + -------- + svn 3901 + -------- + Error with equations that included (s) or (g). The + equation and log K were correct only for the simulation + when initially read. Now equations an log Ks are correct + for all simulations. Calculates saturation index from + the equation after (s) and (g) are eliminated. + + + -------- + svn 3695 + -------- + For transport calculations, fixed step_fraction when + nmix == 1 and ishift == 0. + + -------- + svn 3684 + -------- + Added more precision in writing dump file fields. + + Multiple REACTIONS were not sorted correctly. Added sort + routine to tidy.c. + + -------- + svn 3640 + -------- + Print correct temperature for gas phase dump. + + Correct total moles of exchanger for function sys("X"). + + -------- + svn 3568 + -------- + minteq.dat: Changing log K of gypsum to minteq version + 4 value (-4.61). Old value (-4.848) is too stable. + + -------- + svn 3483 + -------- + Alkalinity is now printed to the selected output file + when the Alkalinity is used with -totals. + + SELECTED_OUTPUT; -totals Alkalinity + + Modified numerical method to attempt to produce a numerical + solution when complexes are extremely strong. llnl.dat As and F + complexes caused PHREEQC to fail on an initial solution + calculation. The terms of the As and F mass balance equations + were identical to machine precision. One unknown log activity + was adjusted but the other was not. Now attempts an adjustment + for the unadjusted log activity. + + + -------- + svn 3463 + -------- + Modified handling of not-a-number in places that + affected the adjustment of log activities (reset and + revise guesses). Uses isfinite function that is available + on Linux and is ifdef'd in global.h for Visual Studio. + The NaN problem occurred rarely and was related to + bad results from the solver and when poor estimates were + available in revise_guesses. Also insured that log activity + for new master species was well defined in switch_bases. + + -------- + svn 3446 + -------- + Fixed errors in casting for long double version. + + -------- + svn 3440 + -------- + Adjusted numerical calculation to avoid extremely large + calculated specific conductances in high ionic strength + waters. + + -------- + svn 3433 + -------- + -dw and -millero added to phreeqc.dat, which allows + calculation of specific conductance and density. + phreeqd.dat is now redundant and removed from distribution. + + -------- + svn 3425 + -------- + Added error message to require -multi_d for transport of + surfaces. + + -------- + svn 3424 + -------- + Checked for misspellings in EXCHANGE definitions, which + previously caused crash. + + -------- + svn 3423 + -------- + -dw and -millero added to pitzer.dat, which allows + calculation of specific conductance and density. + + -------- + svn 3292 + -------- + Removed redundant warnings related to transport of exchanger + and surface. + + -------- + svn 3287 + -------- + Fixed error in CD_MUSIC surface complexation model. + If reaction equation for a surface species was not + written with the primary surface species, the calculation + was incorrect. The logic to accumulate the change in + charges on the planes was erroneously not included when + rewriting the equations to the master species. + + -------- + svn 3247 + -------- + Revised donnan layer calculation with CD_MUSIC. Fixed + a bug related to moles versus concentration and stream + lined calculation. Minor differences in relevant test + cases. + + -------- + svn 3207 + -------- + Modifications to convergence criteria for surfaces + related to minerals, when moles of mineral is near + zero (<= 1e-14). + + -------- + svn 3100 + -------- + Error when multiple surfaces were used. Sometimes the + surface area from one surface was used for another. + Results were probably incorrect if the surfaces were + not in alphabetical order in their definition in + SURFACE. + + -------- + svn 2711 + -------- + Cleaned up compiler warnings for functions called + with constant strings. +------------------------------------------------------------ +Version 2.15.0: February 5, 2008 +------------------------------------------------------------ + -------- + svn 2386 + -------- + Fixed bug for SELECTED_OUTPUT; -activities H2O. The + resulting value was -30; now produces the correct + result. + +------------------------------------------------------------ +Version 2.14.3: November 17, 2007 +------------------------------------------------------------ + + -------- + svn 2386 + -------- + Fixed bug in routine find_Jstag. Incorrect index (cell_no) + caused segmentation violation in rare instances. + + -------- + svn 2312 + -------- + Added new option to PITZER datablock, use_etheta t/f. + + -------- + svn 2279 + -------- + Error lost 200 moles of mineral. Should only be a problem + in some cases where moles of mineral is greater than 200. + + -------- + svn 2270 + -------- + Added additional parameters Pitzer activity formulation for + neutral species, MU and ETA. + + -------- + svn 2269 + -------- + Fixed buffer overrun in SOLUTION_SPREAD when pasting. + + -------- + svn 2268 + -------- + Fixed error in prep.c where realloc was called instead + of PHRQ_realloc, which eliminated a memory leak. + +------------------------------------------------------------ +Version 2.14.2: September 17, 2007 +------------------------------------------------------------ + + -------- + svn 2267 + -------- + Fixed logic of memory checking for PhreeqcI. This serious + bug makes versions 2.14.0 and 2.14.1 unusable. + +------------------------------------------------------------ +Version 2.14.1: September 5, 2007 +------------------------------------------------------------ + -------- + svn 2219 + -------- + Updated transport.c to adjust transport in diffuse + layer to be charge balanced for MCD calculation. + +------------------------------------------------------------ +Version 2.14.0: August 30, 2007 +------------------------------------------------------------ + ------------- + svn 2203-2204 + ------------- + Revised logic for using phqalloc memory checker. Compiler + option USE_PHRQ_ALLOC now turns on memory checker. If + USE_PHRQ_ALLOC is defined and NDEBUG is not defined, file name + and line number are also used in memory checking. Model.c + now uses same compile options as all other files. + + -------- + svn 2199 + -------- + Initialized variables that caused problems when rerunning + simulations in PfW and PhreeqcI. + + -------- + svn 2138 + -------- + Fixed bugs in MCD calculation related to saving solutions + after initialization. + + -------- + svn 2055 + -------- + Profiled and optimized of code. Automatic string in Basic + factor saves many mallocs. Reordered to minimize call to + strcmp_nocase in basicsubs.c and xsolution_save. Minimized + mallocs for solver. + + -------- + svn 2051 + -------- + Fixed bugs in MCD calculation. + + -------- + svn 2040 + -------- + Fixed warnings for type-punned with new gcc. + + Reverted to 2.12 for infilling solutions for transport. + Only solutions are used, not additional reactants for solution + 0 and n+1. + + Added digits to printout of REACTION stoichiometry. + + -------- + svn 1852 + -------- + Fixed error in CDMUSIC surface related to a phase. + Stoichiometry of H was calculated incorrectly. + + -------- + svn 1837 + -------- + Initialize flag for MCD calculation. PhreeqcI would + do MCD calculation after TRANSPORT was redefined not + to do MCD calculation. + +------------------------------------------------------------ +Version 2.13.2: February 1, 2007 +------------------------------------------------------------ + -------- + svn 1700 + -------- + Fixed bug with redox elements in multi_diffusion + stagnant zones. + + -------- + svn 1683 + -------- + Worked on convergence problems when optimizer fails to + find a solution. Censored values greater than 1e8. + + -------- + svn 1637 + -------- + Fixed bug with dissolve only in ADVECTION calculations. + + -------- + svn 1629 + -------- + Fixed bug with redox elements in multi_diffusions. Added + Phreeqc For Windows changes from 2.13.1. + +------------------------------------------------------------ +Version 2.13.1: January 16, 2007 +------------------------------------------------------------ + -------- + svn 1600 + -------- + Fixed logic error that required rebuilding aqueous model + when not necessary. Now runs faster (sometimes 3X) than + version 2.13.0. + + -------- + svn 1590 + -------- + Removed porosity from one statement to eliminate oscillations + in multicomponent diffusion calculation. + + -------- + svn 1558 + -------- + Dissolve-only option did not work correctly for stagnant cells + in TRANSPORT calculations. The moles of equilibrium phases, + kinetics, gas_phase, and solid solutions were not initialized + at the beginning of each transport step. Thus, the printed values + for delta moles for the step in the output and punch file were + incorrect for stagnant-zone cells. "Dissolve only" was + always tested relative to the number of moles initially in the + cells, not the amount remaining at a given time step. + + -------- + svn 1485 + -------- + Pitzer version with gas_phase did not work. Added + gas_phase and cd_music to numerical derivative routine. + + + + svn 1368: (1) Added multicomponent diffusion in transport and + SOLUTION_SPECIES. (2) Added BASIC functions to obtain and + modify the porosity in a cell. (3) Aded mobile surface and Donnan + option in SURFACE. (4) Added special BASIC function to change + the diffusion coefficient of a SURFACE, and hence to + change the status from mobile to immobile or immobile to + mobile. + + svn 1337: Added -add_logk to NAMED_EXPRESSIONS keyword. + + svn 1306: Revised printing of distribution of species, + pure phase assemblages, and solid solutions to use + longer fields for names. More revisions to logic + for using gases and solids in equations for phases. + Revised logic for solid solutions with small (1e-25) amounts + of component. + + svn 1282: Fixed bug when gas phase had no gas components. + Looked the same as not having a gas phase at all. + + svn 1245: Enabled redox in Pitzer model with option in + PITZER keyword. Typically, the option will be included + in the pitzer database file. + +PITZER + -redox TRUE + + The default database for the Pitzer model does not contain + any redox definitions and the default value for the option + is FALSE. At a minimum, species O2 and H2 must be defined + in the database or input file to allow redox calculations. + + svn 1179: New option (-sites_units density) allows alternative + units (sites/nm^2) for definition of number of sites for a + surface. This approach requires better consistency among the + parameters as both the number of sites and the surface area + are based on the mass. It makes more sense than the default, + which requires the number of sites (first numeric item in a + line) to be defined in units of moles, independently of the + number of grams of sorbent. + +SURFACE 1 + -sites DENSITY + SurfOH 2.6 600. 1.0 + SurfaOH 2.6 30. 2.0 + + In this example, Surf has a site density of 2.6 sites per + nanometer squared, a specific area of 600 meters squared per + gram, and a mass of 1 gram. Surfa has a site density of 2.6 + sites per nanometer squared, a specific area of 30 meters + squared per gram, and mass of 2 grams. + + svn 1128: Fixed bug with value of time printed to selected + output file when using cvode. Value printed was an + intermediate integration time step, not time at end + of integration. + + svn 1096: Allows solids and gases in the equations for + PHASES. This capability simplifies the definitions for + gas and solid isotopic components. Solids must be identified + with "(s)" and gases with "(g)". The first entity on the left- + hand-side of the equation must be the stoichiometric formula + of the solid of gas component being defined, optionally with + (g) or (s). In turn gases and solids included in the equation + must be defined with reactions that ultimately allow the + defined species (C[18O]2(g) in this case) in terms of aqueous + species. + +C[18O]2(g) + C[18O]2(g) + CO2(g) = 2CO[18O](g) + log_k 0.602059991327962396 # log10(4) + + svn 1092: CD_MUSIC sorption model has been implemented. + Still missing logic for surfaces related to equilibrium- + phases and kinetics. Has explicit calculation of diffuse + layer composition with Donnan assumption. Old diffuse-layer + calculation will not be implemented. + + Example: + +SURFACE + Goe_uniOH .000552 96.387 1 + -capacitance 1.1 5 + Goe_triO .000432 + -cd_music + -donnan + + 1.1 5 are capacitances for the cd-music model for 0-1 and 1-2 + planes, respectively. + -cd_music specifies that the surface is a cd-music surface. + -donnan optionally calculates the diffuse layer composition + with the Donnan model. + +SURFACE_SPECIES + Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O + log_k 20.1 # eq 7 K1, Kin1 + -cd_music -1 -6 0 0.25 5 + + -cd_music gives the charge contribution of the surface + species to the three planes. Plane 0 is + -1 + 0.25*5; Plane 1 is -6 + (1-0.25)*5; + Plane 2 (or d) is 0. + + + svn 1030: Fixed bug in tranport. Mixing was not printed + when using -cvode in kinetics. + + svn 984: Fixed bug in transport when cell without a + surface followed a cell with a diffuse-layer surface. + Fixed bug in TOTAL function; code ran of the end of + the list of master species; changed logic to recognize + the end of the list. + + svn 874: Fixed bug in check_same_model. Thought surface + calculation was the same even though -edl switch was + different, which gave irratic results and possible + crash. Now checks more carefully to make sure calculation + for surfaces is really the same and reinitializes if + not. + + svn 847: Fixed bug with DESCRIPTION function. Did not + give correct solution description for reactions. + + svn 826: Update tally.c to avoid conflicts in C++ + version of phast. + + svn 801: Wrote around underflow in fabs in subroutine + reset. + + svn 794: Errors in minteq.v4.dat database. Several redox + reactions had delta H listed as kcal instead of kJ. kcal + is correct only for the following species H2, NO2-, and + NH4+. + + svn 675: + Added PRINT option to print the species that contribute + to alkalinity. Alkalinity distribution is printed in + the output file following the distribution of species. + Default at program startup is false. + + PRINT + -alkalinity true + + svn 655: + IAP and log K printed in Phase assemblage data + block were calculated from reactions rewritten to + new master species. Now the original data base + reaction is used to calculate IAP and log K. + Also fixed check that ensured all elements of + phase in are in solution before SI is calculated. + + svn 631: + Fixed bug with alternate formula for equilibrium phase, + nothing happened if all other equations were satisfied + at beginning of reaction calculation. + + svn 603: + Link gmp library statically. + + svn 601: + Fixed statement on multiprecision. + + svn 581: + Fixed bug in PhreeqcI that did not reinitialize + Chebyschev parameters leading to incorrect results + with Pitzer activity coefficients. Results were + correct on first run, but erroneous on subsequent + runs. + + Added statement to identify multiprecision or + standard solver for inverse modeling. + + svn 578: + + Distribution changes. Fixed names in README file. + Modified Makefile to use specified version. Split + Linux and source distribution procedure. + +------------------------------------------------------------ +Version 2.12 Date: Wed September 28, 2005 +------------------------------------------------------------ + + Executables and output files for Sun operating systems + are no longer provided. + + Limited log activities of master species to be greater + than the smallest machine precision exponential number. + Avoids a matherr exception and allows trial of additional + parameter sets to attempt to solve the system of + equations. + + Made aqueous activity coefficients the default activity + coefficients for exchange species when using the + Pitzer formulation. New option in EXCHANGE is + -pitzer_exchange_gammas T/F, default is true; + defining "false" sets exchange activity coefficients + to 1.0. Option has no effect for ion-association + model (non-Pitzer). + + Edited phreeqc.dat to add -gamma expression for + CdX2 and PbX2. + + Replaced O2(g) log K in phreeqc.dat and wateq4f.dat + with data from llnl.dat, which appears to be better. + + Added multiplier format to REACTION increments, which + simplifies definition of multiple equal reaction increments. + + REACTION + H2O 1 + -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles + + Added Pitzer activity formulation. Use pizer.dat database + to invoke the Pitzer model. Should have same capabilities + as ion-association model except explicit diffuse layer + calculation is not implemented with the Pitzer model. + + + Fixed bug in surface sites related to mineral and exchange + sites related to mineral. Did not have complete logic to + handle redox valence states in formula for species. + + Modified to remove non standard usage of va_list. + + Removed exchange master species from SYS("ex",..) + list of species. This species is fictive and should + not be included in the list. + + Changed -redox in SOLUTION so that if one of the + redox states of a couple is not defined, then + redox defaults to pe. + + Fixed buffer overrun in PhreeqcI with SOLUTION_SPREAD, + caused segmenatation fault with lines greater than + 500 characters. + + Added bigger string for some error messages to avoid + access violation in cvode. + + Changed output_msg to warning_msg for combinations + of convergence parameters so that message would + be controlled by -warnings identifier. + + Carriage returns are now stripped from Basic program + statements. Switching files from Windows to Unix sometimes + leaves extra carriage returns at the ends of lines, which + caused a syntax error for some Basic commands. + + Two bugs were fixed in inverse modeling. (1) Potential + models are now checked for all equality and inequality + constraints. Previously some constraints were not checked. + (2) One loop of cl1 did not include the last row when + checking for the pivot element. Also printing of headers + was slightly modified for inverse modeling. + + A new multiple precision version of cl1 was develeped by + using the Gnu Multiple Precision package (gmp). Calculations + are carried out to about 30 significant digits. The mp + version may help in some situations where roundoff errors are + a problem, but it is still possible that roundoff errors will + cause cl1mp to fail to find a solution to the optimization + problem. The mp version has the following options in + INVERSE_MODELING: + -multiple_precision T/F--causes the mp version + to be used in inverse modeling calculations. + -mp_tolerance 1e-12--tolerance for mp version of + cl1. As in cl1, numbers less than the + tolerance are considered to be zero. + 1e-12 is the default. + -censor_mp 1e-20--as calculations occur in the + linear equation array, elements less + than this value are set to zero. Default + is 1e-20. A value of 0.0 causes no + censoring to occur. + +------------------------------------------------------------ +Version 2.11 Date: Mon February 7, 2005 +------------------------------------------------------------ + + Fixed error in selected output file with mixing reaction. + MIX number was written to two columns, should be one. + + Fixed memory leak with PAD function. + + New database minteq.v4.dat has been translated from version + 4.02 of MINTEQA2. An older version of the MINTEQA2 database is + retained in file minteq.dat. + + Switched version control to subversion. Simplified, + reorganized makefiles. + + Fixed bug with PRINT; -warnings n. Use of this option + generally eliminated all warning messages instead of + all messages after the nth. Default number of warning + messages printed in now 100 per simulation. + + Fixed memory leaks in cvode that caused phreeqci to crash. + Now uses PHRQ_malloc in case of other memory leaks. Also + fixed potential memory error with PAD Basic function. + + Saturation index phases that included water had wrong + value if distribution of species, exchange, or surface + not written also. + + Fixed error message in cvode, if max iterations exceeded + the error caused a segmentation fault. + + Made printing of parameter combination message a warning + message so that it could be turned off. + +------------------------------------------------------------ +Version 2.10 Date: Tue November 2, 2004 +------------------------------------------------------------ + + Rearranged i/o for PHREEQC and reorganized driver + subroutine. The object of these changes is to make + the program more functional as a module for other + programs (PHAST) and eventually to produce a callable + C and Fortran module. + + Fixed a problem with surface related to a phase, when + phase was not part of system (for example, Fe(OH)3a when + there is no iron in system. + + Added convergence parameter set that requires mineral + transfers to produce positive concentrations in the + event that negative concentrations have been produced in + the prior Newton-Raphson iteration. (Fluorite example). + + Fixed bug with kinetics formulas; did not account for + stoichiometric coefficient correctly when using + phase names. Generalized to allow multiple phase + names in the -formula definition. + +------------------------------------------------------------ +Version 2.9 Date: Wed September 15, 2004 +------------------------------------------------------------ + + In inverse modeling, program terminates if sum of initial + solutions and phases is > 32. + + Fixed bug with isotopes. Log activity estimate after initial + solution calculation was inf under some conditions. An initial + surface calculation failed when using D. + + Changed saturation index print out to use reaction and log K + defined in PHASES definition. Previously, reaction could be + rewritten to predominant redox species. + + Fixed incorrect print of elapsed time for kinetics in advection. + + Added phrqproto.h prototype file and phrqtype.h for + switching compilation to long double. + + Fixed incorrect printout of kinetics delta moles with + advection. + + Added convergence parameter set that skips mineral + equations for first 5 iterations. + + Added entity_exists for module. + + Tried to fix bug with mix index incorrect (-2) for + mixing with kinetics. + + Added new keyword COPY that allows a data entity + to be copied from one index to a new index + or to a range of indicies. Format is + + COPY keyword index index_start[-index_end] + + where keyword is one of the following: + SOLUTION + EQUILIBRIUM_PHASES + EXCHANGE + GAS_PHASE + KINETICS + MIX + REACTION + REACTION_TEMPERATURE + SOLID_SOLUTION + SURFACE + + Numerical method had a bug with ionic strength, if + mass of water was not approximately 1. Routine + revise_guesses did not divide by the mass of + water. Also changed check in routine molalities + to check by molality, not moles. + + Fixed a null pointer when surface was related to a + mineral and mineral was not in database. + + Added new Basic functions + i = INSTR(a$, b$) sets i to the character position of + string b$ in a$, 0 in not found. + b$ = LTRIM(a$) trims white space from beginning of + string a$ and stores result in b$. + b$ = RTRIM(a$) trims white space from end of string + a$ and stores result in b$. + b$ = LTRIM(a$) trims white space from beginning and + end of string a$ and stores result in b$. + + Added new Basic function SYS that calculates the to + total amount of an element in all phases (solution, + equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase). KINETIC reactions are not included. + The function has two forms: (1) one element name as an + argument (variable names are user specified) + + 10 t = SYS("As") + + the function will return the total arsenic in the system. + (2) 5 argumens + + 10 t = SYS("As", count_species, names$, types$, moles) + + will return the total arsenic in the system to tot; count_species-- + the number of species that contain arsenic, including + solution, equilibrium_phases, surfaces, exchangers, solid solutions, + and gas phase species; names$--a character array that has the + name of each species; type$--a character array that specifies the + type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. + Diff refers to the amount of the element in the diffuse layer of + a surface when the explicit diffuse layer calculation is used; + moles--an array containing the number of moles of the element in + the species. The sum of moles(i) is equal to tot. + + SYS has several special arguments for the form + SYS("arg", count, names$, types$, values) + arg is one of the options listed below. + count is a single numeric value and is the number of elements + in the following arrays. + name$ is an array of string values. + type$ is an array of string values. + values is an array of numeric values. + + Values of arg: + + elt_name returns total number of moles of element in system. + count is the number of species for the element in + the system, including aqueous, exchange, surface, + equilibrium_phase, solid solution component, and + gas phase "species". + Arrays are filled for each "species"; values are moles. + "elements" returns total number of moles of all elements, + valence states, exchangers, and surfaces. + count is number of elements, valence states, + exchangers, and surfaces. + Arrays are filled for each element, valence state, + exchanger, and surface; values are moles. + "phases" returns maximum saturation index of all phases. + count is number of phases in system. + Arrays are filled for each phase; values are + saturation indexes. + "aq" returns sum of moles of all aqueous species. + count is number of aqueous species in system. + Arrays are filled with each aqueous species; + values are moles. + "ex" returns sum of moles of all exchange species. + count is number of exchange species in system. + Arrays are filled with each exchange species; + values are moles. + "surf" returns sum of moles of all surface species. + count is number of surface species in system. + Arrays are filled with each surface species; + values are moles. + "s_s" returns sum of moles of all solid solution components. + count is number of solid solution components in system. + Arrays are filled with each solid solution component; + values are moles. + "gas" returns sum of moles of all gas components. + count is number of gas components in system. + Arrays are filled with each gas component; + values are moles. + + Added new Basic function, DESCRIPTION, that has the value + defined for the description field of the SOLUTION keyword line. + + Added alternative ordinary differential equation solver + called CVODE, a set of C routines from the Lawrence + Livermore National Labs. CVODE is part of the SUNDIALS + package. CVODE is used in place of the Runge Kutta method + when "-cvode true" is used within a KINETICS data block. + + KINETICS + -cvode true + + Fixed error in SOLUTION_SPREAD, defining -redox + did not set the default redox for the solutions + that were defined; pe was always used as default. + + Modified code to allocate space differently for + pp_assemblage, exchange, surface, gas_phase, + kinetics, and s_s_assemblage. Enough space is allocated + at beginning of distribute_initial_conditions. + May speed up phast initialization and make better + use of available memory. + + Changed gfw of water to 18 if isotopes of water are + included. Solvent is [1H]2[16O]. + + Fixed a bug in surface integration where order of ions + in the list of g's was incorrect. + + Pyrite rate was not 0 if supersaturated in phreeqc.dat + and wateq4f.dat + + Segmentation error if a surface species was not + defined with an equation that contained another surface + species. In this case, the surface master species + had been redefined to be an aqueous species (SOLUTION_SPECIES). + +------------------------------------------------------------ +Version 2.8 Date: Tue April 15, 2003 +------------------------------------------------------------ + + Updated arsenic data in wateq4f.dat to be consistent with + Archer and Nordstrom (2002). + + Revised Basic interpreter to allow lines of any length + and character strings of any length. + + Renumbering basic statement that included the function + SURF in PhreeqcI caused SURF to be omitted and generated + a syntax error. SURF and other functions had not been + implemented in PhreeqcI. + + Fixed a bug in the Basic Interpreter. If elements of + a dimensioned variable (character or number) were used on + both sides of an equation, the result was erroneously + stored in the last element of the variable used on the + right-hand side instead of the element specified on the + left-hand side. + + Using comma in some fields caused an infinite loop. + + Fixed bug with SOLUTION_SPREAD, Phreeqc was not + calculating solution numbers for solution_spread + solutions without solution numbers. + + Fixed bug with stagnant zone calculations. If solutions + not defined for stagnant cells, PhreeqcI crashed. + + Added new state for calculations, PHAST. Previously + phast used the state TRANSPORT, which caused some + erroneous results with temperature when TRANSPORT was + used in the PHREEQC part of the calculation. + + Trying to define dump file in TRANSPORT caused a file + opening error. Fixed logic so now can open a file + and the name can include blanks. + +------------------------------------------------------------ +Version 2.7 Date: Fri February 14, 2003 +------------------------------------------------------------ + + Initialized gfw in elements structure. + + Fixed bug where "time" would be wrong for initial + solution calculation. Needed to initialize + rate variables for PhreeqcI. + + Added print of simulation number to error file for + phreeqci + + Limited printing of cell numbers to output file in advection + calculations. Cell numbers only printed if results + for cell are going to be printed. + + PhreeqcI captured status messages for kinetics, which + made a very large error file in some cases and + a long wait to view the output file in PhreeqcI. + Now PhreeqcI does not capture these intermediate + status messages. + + Removed old code related to redirecting error file + + + Corrected error in transport where wrong time step was used + for integration. + + Changes to speed up transport algorithm. + + Allow file names with spaces in selected_output file name and + dump_file name. + + Modifications to work with RC1 phast log file. + + Allow any characters in square brackets for element name. + - and + and perhaps others caused problems before. + + Fixed log molality of water in species printout, was + equal to log activity of water. Also fixed + basic function for LM. + + Changed solid solution prints to print 0 if solid solution + is not present. + + Fixed bug if no rate name was defined before options + in RATES. + + Fixed warning on Mac compilation in fpunchf. + + Fixed bug if isotopes were used but H and O isotopes + were not defined. + + Fixed bug where special initial solution calculations + were done at later calculation stages. + Needed to set initial_solution_isotopes = FALSE; + + Fixed problem in C++ if structure name is same as member name. + logk member of logk structure was renamed to log_k. + + Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, + SOLUTION_SPECIES, and SURFACE_SPECIES. + + -add_constant -0.301 + + log K is augmented by the specified constant. + + + Added punch_isotopes and punch_calculate_values to allow + printing isotope ratios and any CALCULATE_VALUES result. + + Added KEYWORDS: + + ISOTOPES + Element + -isotope isotope_name units standard_ratio + -total_is_major T/F (OPTION IS DISABLED!!) + + CALCULATE_VALUES + Name + -start + Basic statements, must have SAVE + -end + + ISOTOPE_RATIOS (for printing) + Name=Calculate_values_name Isotope_name + + ISOTOPE_ALPHAS (for printing) + Name=Calculate_values_name Named_logk=named_expression_name + + Basic functions: + calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES + lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS + lk_phase("name") log10(K) of definition in PHASES + lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES + sum_gas("template","element") Sum of element in gases with specified template + template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases + sum_species("template","element") Sum of element in aqueous, exchange, and surface species with + specified template + sum_s_s("s_s_name","element") Sum of element in a specified solid solution + + PRINT keyword: + -initial_isotopes T/F + -isotope_ratios T/F + -isotope_alphas T/F + -censor_species 1e-8 # Omits print of species if less than relative criterion + + SELECTED_OUTPUT keyword: + -calculate_values name1 name2 ... + -isotopes minor_isotope1 minor_isotope2 .... + + Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic + interpreter. LK_SPECIES("CaHCO3+") returns the + log k for the association reaction for the ion pair + CaHCO3+ at the current temperature. The log K is + for the reaction as defined in the database or + input file. Similarly, + LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the + value for the log K at the current temperature using + expressions defined in NAMED_LOG_K data block; + LK_PHASE("Calcite") returns the value of log K + for calcite at the current temperature for the + dissociation reaction defined in the database or + input file. Values are "log10" values. + Example for Basic program: + + 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") + 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") + 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 + + Added NAMED_EXPRESSIONS data block. This data block was + implemented to facilitate isotopic calculations. + It allows analytical expressions that are functions + of temperature to be defined. The purpose is to + separate the fractionation factors from the log K, + so that the fractionation factor or its temperature + dependence can be easily modified. The named + expression can be added to a log K for a species + or phase by the -add_logk identifier in SOLUTION_SPECIES + EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data + block. + +------------------------------------------------------------ +Version 2.6 Date: Mon April 22, 2002 +------------------------------------------------------------ + + PhreeqcI released. + + All selected_output is routed through a single routine. + + Allow "_" inside square brackets, [A_bcd]. + + Fixed bug match_elts_in_species, check for "e-" was wrong. + + Modified minteq.dat to put CuS4S5-3, Cu(S4)2-3 in + in Cu(1) mole balance equations instead of + Cu(2). Before the change, the program would + not converge if Cu(2) were defined in an + initial solution. + + Made revisions hopefully to improve SOLID_SOLUTIONS + convergence with small numbers of moles of + solids. + + Made changes related to dump file and PhreeqcI. + + Iterations now sums iterations in all kinetics calculations + + Fixed bug with LA("H2O"), which was returning natural log + of activity of water. + + +------------------------------------------------------------ +Version 2.5 Date: Mon October 1, 2001 +------------------------------------------------------------ + + In llnl.dat, fixed sign errors in RRE (rare earth elements) + for some redox reactions and removed some redundant + species, generally ReeO2- was retained and Ree(OH)4- + was removed. + + Added the capability to use square brackets to define an + "element" name. The brackets act like quotation marks + in that any character string can be used within the + brackets as an element name. This was introduced to + simplify expansion of the model to isotopic species. + [13C], [14C], and [18O] are legal element names. + + Added identifier -activity_water for a species in + SOLUTION_SPECIES data block. This identifier has been + added for future updates that will allow isotopic + calculations. It is intended to be used only for + isotopic variations of H2O, like D2O or H2[O18]. It + forces the activity coefficient for the species to be + activity(water)/55.5. This effectively sets the activity + of the species to the mole fraction in solution. + + Fixed bug in checking solid solutions for presence or + absence of elements in the system. Programming + error caused segmentation fault if an error + was detected under certain conditions. + + Changed return value of MOL to be molality of water + if argument is "H2O". Also changed return value + of LA to be activity of water if argument is + "H2O". + + Diffuse layer calculation was incorrect if aqueous phase did not + have 1 kilogram of water. Eq. 74 of manual has molality, + but code used moles. The code was corrected by adding + the mass of water to the formulation. + + Stagnant zones with first-order exchange approximation (1 stagnant + cell, exchange factor, and porosities defined) did not work + correctly if mobile and immobile cells did not have equal + volumes of water. The mixing factors were revised to account + for the masses of water in the stagnant and mobile zones. + + A fatal error was erroneously detected if the database file + had a DATABASE data block. DATABASE data block is + now ignored while reading the database file. + + Added identifier -bad_step_max to KINETICS data block. + An integer following -bad_step_max gives the maximum number + of times a rate integration may fail before execution of the + program is terminated. Default is 500. + +------------------------------------------------------------ +Version 2.4.2: Date: Fri June 15, 2001 +------------------------------------------------------------ + + Fixed spreadsheet bug. Program was not ignoring columns + that could not be identified as either element + names or allowed data (ph, pe, number, description, + etc). Also, the program failed if a spreadsheet solution + number was negative. + +------------------------------------------------------------ +Version 2.4.1: Date: Mon June 4, 2001 +------------------------------------------------------------ + + Fixed spreadsheet bugs with isotopes. + +------------------------------------------------------------ +Version 2.4: Date: Fri June 1, 2001 +------------------------------------------------------------ + + Added structure for spreadsheet for use by PhreeqcI. + + Isotope value initialized incorrectly if only an -uncertainty was + defined in SOLUTION_SPREAD. + + Fixed segmentation violation when primary and secondary master + species were defined improperly. + + Corrected enthalpies of reaction in llnl.dat. Previous release had + erroneously had enthalpies of formation in -delta_H + parameter; the values should be enthalpies of reaction. + Enthalpies of reaction were calculated from the + enthalpies of formation and these values are now included + in the -delta_H parameter. This change will have very + little impact on calculations because the analytical + expression has precedence over -delta_H in calculating + temperature dependence of log K, and nearly all species + and minerals have an analytical expression or lack both + an analytical expression and an enthalpy of reaction. + + Corrected bugs in punch of solid solution components that caused + both selected output and output file errors: moles + were incorrect in selected output, and total moles and + mole fraction were incorrect in output file. + + Added surface complexation constants for Fe+2; two complexes for + weak sites and one complex for strong sites. phreeqc.dat + and wateq4f.dat modified. + + Comment for units of parameters for calcite rate equation was + wrong. Rate equation now uses cm^2/L for area parameter. + Previously the correct units would have been 1/decimeter. + phreeqc.dat and wateq4f.dat modified. + + Fixed a bug when rates were equal within tolerance, but negative + concentrations occurred because of small initial + concentrations. + + Added -warnings to PRINT keyword for specification of maximum + number of warnings to print. Negative number allows + all warnings to be printed. + + Function CELL_NO in Basic now prints a number equivalent to + -solution in SELECTED_OUTPUT data block. This does not + change printing for ADVECTION or TRANSPORT calculations. + + Kinetics time is halved for advective part of reaction in + transport; time incorrectly accounted for before. + + -punch_ identifiers printed -1 instead of the correct solution + number for batch-reaction calculations. + + -high_precision is no longer reset to false with every + SELECTED_OUTPUT data block. + + SELECTED_OUTPUT file name stored for use by PhreeqcI. + + Alkalinity for NH3 corrected to 1.0 in llnl.dat. + + Fixed bug with USER_PRINT of kinetics. Did not find correct + kinetics information in some cases. + + Fixed bug in default values for SOLUTION_SPREAD. Cannot use phase + name and SI for pH or pe, and bug did not allow PHREEQC + to run. Now PHREEQC runs, but warns that this is not + allowed. + +------------------------------------------------------------ +Version 2.3: Date: Tue January 2, 2001 +------------------------------------------------------------ + + Added new keyword DATABASE. It must be the first keyword in + the input file. The character string following the + keyword is the pathname for the database file to + be used in the calculation. The file that is + specified takes precedence over any default + database name, including environmental variable + PHREEQC_DATABASE and command line arguments. + + Fixed bug in SOLUTION_SPREAD. If first heading in + the spread-sheet input was an identifier--pH, + pe, units, etc--then the headings were interpreted + as an identifier and bad things happened. + + Added new keyword to make aqueous model similar to + LLNL and Geochemists Workbench when using + llnl.dat as the database file. Values + of Debye-Huckel a and b and bdot (ionic strength + coefficient) are read at fixed temperatures. + Linear interpolation occurs between temperatures. + + New options for SOLUTION_SPECIES are + -llnl_gamma a , where a is the ion-size parameter. + -co2_llnl_gamma , indicates the temperature dependent + function for the bdot term given in + -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS + will be used. Applies to uncharged + species only. + +LLNL_AQUEOUS_MODEL_PARAMETERS +-temperatures + 0.0100 25.0000 60.0000 100.0000 + 150.0000 200.0000 250.0000 300.0000 +#debye huckel a (adh) +-dh_a + 0.4939 0.5114 0.5465 0.5995 + 0.6855 0.7994 0.9593 1.2180 +#debye huckel b (bdh) +-dh_b + 0.3253 0.3288 0.3346 0.3421 + 0.3525 0.3639 0.3766 0.3925 +-bdot + 0.0394 0.0410 0.0438 0.0460 + 0.0470 0.0470 0.0340 0.0000 +#cco2 (coefficients for the Drummond (1981) polynomial) +-co2_coefs + -1.0312 0.0012806 + 255.9 0.4445 + -0.001606 + + + Fixed bug in basic interpreter. A number like "..524" would + cause an infinite loop. + + Added function SURF to Basic. + SURF("element", "surface") gives the amount of + element sorbed on "surface". "surface" + should be the surface name, not the + surface-site name (that is, no underscore). + + Fixed option to "runge_kutta" from "runge-kutta" to match + documentation for KINETICS. + + Fixed UO2+2 and Mn+2 reaction stoichiometry for Hfo surface complexation + in wateq4f.dat. + + Added option for an equilibrium-phase to dissolve only. + "dis" is added at the end of a line defining an equilibrium- + phase. No data fields may be omitted. Should not + be used when adding an alternative reaction. + Example: + EQUILIBRIUM_PHASES + Dolomite 0.0 0.001 dis + R-K integration failed when only the final rate generated + negative concentrations. + Allow decimals in definition of secondary master species, for + example S(0.3). + Fixed bug if description was more than about 85 characters; + now allows about 400 characters. + Fixed bug for surface/exchange sites related to phases. Was + checking internal copies of surfaces/exchange with negative + numbers. + Fixed bug in quick prep that did not set the correct pointer + for gas phases. + Fixed segmentation fault that occurred if all elements for + phase-boundary mineral were not in the solution. + Only applied to a phase used to define concentration + in an initial solution calculation. + Added option to eliminate echo of input file in PRINT + data block. -echo_input T/F turns echoing on + and off. Default is on. + + +------------------------------------------------------------ +Release 2.2: Date: Wed March 1, 2000 +------------------------------------------------------------ + + Fixed bug in MIX if no solutions are defined. + Changed printout for surface. + Only gives net surface charge for diffuse layer + calculation. + Prints correct value for the surface charge and + surface charge density for diffuse-layer + calculation. + + Added function EDL to Basic. + EDL("element", "surface") gives the amount of + element in the diffuse layer for "surface". + not including sorbed species. "surface" should + be the surface name, not the surface-site name + (that is, no underscore). + + Special values for "element" include: + "charge" - gives surface charge, equivalents. + "sigma" - surface charge density, C/m**2. + "psi" - potential at the surface, Volts. + "water" - mass of water in the diffuse layer, kg. + Changed distribution to be more consistent with other USGS + water-resources applications. + +------------------------------------------------------------ +Release 2.1: Date: Wed January 19, 2000 +------------------------------------------------------------ + + Added additional #ifdef's for PhreeqcI. + Fixed problem with formats for USER_PUNCH and + others with Microsoft C++ 3 digit + exponents. + +Initial Release 2.0: Date: Wed December 15, 1999 + +Version: C_54 = Version 2.0 + diff --git a/rename_cpp/sit.cpp b/rename_cpp/sit.cpp new file mode 100644 index 00000000..22936a98 --- /dev/null +++ b/rename_cpp/sit.cpp @@ -0,0 +1,1357 @@ +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Exchange.h" + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_init(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialization for SIT + */ + sit_model = FALSE; + max_sit_param = 100; + count_sit_param = 0; + space((void **) ((void *) &sit_params), INIT, &max_sit_param, + sizeof(struct pitz_param *)); + OTEMP = -100.; + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_tidy(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Make lists of species for cations, anions, neutral + */ + int i, j; + /* + * Ensure new parameters are calculated + */ + OTEMP = -100.; + /* + * allocate pointers to species structures + */ + if (spec != NULL) spec = (struct species **) free_check_null(spec); + spec = (struct species **) PHRQ_malloc((size_t) (3 * count_s * sizeof(struct species *))); + if (spec == NULL) malloc_error(); + for (i = 0; i < 3 * count_s; i++) spec[i] = NULL; + + cations = spec; + neutrals = &(spec[count_s]); + anions = &(spec[2 * count_s]); + sit_MAXCATIONS = count_s; + sit_FIRSTANION = 2 * count_s; + sit_MAXNEUTRAL = count_s; + sit_count_cations = 0; + sit_count_anions = 0; + sit_count_neutrals = 0; + if (itmax < 200) itmax = 200; + /* + * allocate other arrays for SIT + */ + if (sit_IPRSNT != NULL) sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); + sit_IPRSNT = (int *) PHRQ_malloc((size_t) (3 * count_s * sizeof(int))); + if (sit_IPRSNT == NULL) malloc_error(); + if (sit_M != NULL) sit_M = (LDBLE *) free_check_null(sit_M); + sit_M = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + if (sit_M == NULL) malloc_error(); + if (sit_LGAMMA != NULL) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); + sit_LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * count_s * sizeof(LDBLE))); + if (sit_LGAMMA == NULL) malloc_error(); + + + for (i = 0; i < count_s; i++) + { + if (s[i] == s_eminus) + continue; + if (s[i] == s_h2o) + continue; + if (s[i]->z < -.001) + { + anions[sit_count_anions++] = s[i]; + } + else if (s[i]->z > .001) + { + cations[sit_count_cations++] = s[i]; + } + else + { + neutrals[sit_count_neutrals++] = s[i]; + } + } + /* + * no ethetas + */ + /* + * put species numbers in sit_params + */ + for (i = 0; i < count_sit_param; i++) + { + for (j = 0; j < 3; j++) + { + if (sit_params[i]->species[j] == NULL) + continue; + sit_params[i]->ispec[j] = sit_ISPEC(sit_params[i]->species[j]); + if ((j < 2 && sit_params[i]->ispec[j] == -1) || + (j == 3 + && (sit_params[i]->type == TYPE_PSI + || sit_params[i]->type == TYPE_ZETA) + && sit_params[i]->ispec[j] == -1)) + { + input_error++; + error_string = sformatf( + "Species for Pitzer parameter not defined in SOLUTION_SPECIES, %s", + sit_params[i]->species[j]); + error_msg(error_string, CONTINUE); + } + } + } + if (get_input_errors() > 0) return (ERROR); + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_ISPEC(const char *name) +/* ---------------------------------------------------------------------- */ +/* + * Find species number in spec for character string species name + */ +{ + int i; + for (i = 0; i < 3 * count_s; i++) + { + if (spec[i] == NULL) + continue; + if (name == spec[i]->name) + { + return (i); + } + } + return (-1); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_sit(void) +/* ---------------------------------------------------------------------- */ +{ + /* + * Reads advection information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + /* + * Read advection parameters: + * number of cells; + * number of shifts; + */ + int n, j; + struct pitz_param *pzp_ptr; + pitz_param_type pzp_type; + + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "epsilon", /* 0 */ + "epsilon1" /* 1 */ + }; + int count_opt_list = 2; + /* + * Read lines + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + n = -1; + pzp_type = TYPE_Other; + pitzer_pe = TRUE; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + pzp_ptr = pitz_param_read(line, n); + if (pzp_ptr != NULL) + { + pzp_ptr->type = pzp_type; + j = sit_param_search(pzp_ptr); + if (j < 0) + { + if (count_sit_param >= max_sit_param) + { + space((void **) ((void *) &sit_params), + count_sit_param, &max_sit_param, + sizeof(struct pitz_param *)); + } + + sit_params[count_sit_param] = pzp_ptr; + count_sit_param++; + } + else + { + sit_params[j] = (struct pitz_param *) free_check_null(sit_params[j]); + sit_params[j] = pzp_ptr; + } + } + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SIT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* epsilon */ + pzp_type = TYPE_SIT_EPSILON; + n = 2; + opt_save = OPTION_DEFAULT; + break; + case 1: /* epsilon1 */ + pzp_type = TYPE_SIT_EPSILON_MU; + n = 2; + opt_save = OPTION_DEFAULT; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + sit_model = TRUE; + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) +/* ---------------------------------------------------------------------- */ +{ + LDBLE param; + /* + */ + + if (fabs(TK - TR) < 0.01) + { + param = pz_ptr->a[0]; + } + else + { + param = (pz_ptr->a[0] + + pz_ptr->a[1] * (1.e0 / TK - 1.e0 / TR) + + pz_ptr->a[2] * log(TK / TR) + + pz_ptr->a[3] * (TK - TR) + + pz_ptr->a[4] * (TK * TK - TR * TR)); + } + pz_ptr->p = param; + switch (pz_ptr->type) + { + case TYPE_SIT_EPSILON: + pz_ptr->U.eps = param; + break; + case TYPE_SIT_EPSILON_MU: + pz_ptr->U.eps1 = param; + break; + case TYPE_Other: + default: + error_msg("Should not be TYPE_Other in function calc_sit_param", + STOP); + break; + } + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit(void) +/* ---------------------------------------------------------------------- */ +{ + int i, i0, i1; + LDBLE param, z0, z1; + LDBLE A, AGAMMA, T; + /* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, + BMXPHI, PHIPHI, AW, A, B; + */ +/* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + B; +*/ + LDBLE CONV, XI, XX, OSUM, DI, F,CSUM, OSMOT, B; + LDBLE I, TK; + int LNEUT; + /* + C + C INITIALIZE + C + */ + CONV = 1.0 / log(10.0); + XI = 0.0e0; + XX = 0.0e0; + OSUM = 0.0e0; + LNEUT = FALSE; + /*n + I = *I_X; + TK = *TK_X; + */ + I = mu_x; + TK = tk_x; + /* DH_AB(TK, &A, &B); */ + /* + C + C TRANSFER DATA FROM TO sit_M + C + */ + for (i = 0; i < 3 * count_s; i++) + { + sit_IPRSNT[i] = FALSE; + sit_M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + sit_M[i] = under(spec[i]->lm); + if (sit_M[i] > MIN_TOTAL) + sit_IPRSNT[i] = TRUE; + } + } + /* + C + C COMPUTE SIT COEFFICIENTS' TEMPERATURE DEPENDENCE + C + */ + PTEMP_SIT(TK); + for (i = 0; i < 2 * count_s + sit_count_anions; i++) + { + sit_LGAMMA[i] = 0.0; + if (sit_IPRSNT[i] == TRUE) + { + XX = XX + sit_M[i] * fabs(spec[i]->z); + XI = XI + sit_M[i] * spec[i]->z * spec[i]->z; + OSUM = OSUM + sit_M[i]; + } + } + I = XI / 2.0e0; + DI = sqrt(I); + /* + C + C CALCULATE F & GAMCLM + C + */ + AGAMMA = 3*sit_A0; /* Grenthe p 379 */ + A = AGAMMA / log(10.0); + /* + * F is now for log10 gamma + */ + + B = 1.5; + F = -A * (DI / (1.0e0 + B * DI)); + + + CSUM = 0.0e0; + /*OSMOT = -(sit_A0) * pow(I, 1.5e0) / (1.0e0 + B * DI);*/ + T = 1.0 + B*DI; + OSMOT = -2.0*A/(B*B*B)*(T - 2.0*log(T) - 1.0/T); + /* + * Sums for sit_LGAMMA, and OSMOT + * epsilons are tabulated for log10 gamma (not ln gamma) + */ + for (i = 0; i < count_sit_param; i++) + { + i0 = sit_params[i]->ispec[0]; + i1 = sit_params[i]->ispec[1]; + if (sit_IPRSNT[i0] == FALSE || sit_IPRSNT[i1] == FALSE) continue; + z0 = spec[i0]->z; + z1 = spec[i1]->z; + param = sit_params[i]->p; + switch (sit_params[i]->type) + { + case TYPE_SIT_EPSILON: + sit_LGAMMA[i0] += sit_M[i1] * param; + sit_LGAMMA[i1] += sit_M[i0] * param; + if (z0 == 0.0 && z1 == 0.0) + { + OSMOT += sit_M[i0] * sit_M[i1] * param / 2.0; + } + else + { + OSMOT += sit_M[i0] * sit_M[i1] * param; + } + break; + case TYPE_SIT_EPSILON_MU: + sit_LGAMMA[i0] += sit_M[i1] * I * param; + sit_LGAMMA[i1] += sit_M[i0] * I * param; + OSMOT += sit_M[i0] * sit_M[i1] * param; + if (z0 == 0.0 && z1 == 0.0) + { + OSMOT += sit_M[i0] * sit_M[i1] * param * I / 2.0; + } + else + { + OSMOT += sit_M[i0] * sit_M[i1] * param * I; + } + break; + default: + case TYPE_Other: + error_msg("TYPE_Other in pitz_param list.", STOP); + break; + } + } + + /* + * Add F and CSUM terms to sit_LGAMMA + */ + + for (i = 0; i < sit_count_cations; i++) + { + z0 = spec[i]->z; + sit_LGAMMA[i] += z0 * z0 * F; + } + for (i = 2 * count_s; i < 2 * count_s + sit_count_anions; i++) + { + z0 = spec[i]->z; + sit_LGAMMA[i] += z0 * z0 * F; + } + /* + C + C CONVERT TO MACINNES CONVENTION + C + */ + /*COSMOT = 1.0e0 + 2.0e0 * OSMOT / OSUM;*/ + COSMOT = 1.0e0 + OSMOT*log(10.0) / OSUM; + /* + C + C CALCULATE THE ACTIVITY OF WATER + C + */ + AW = exp(-OSUM * COSMOT / 55.50837e0); + /*if (AW > 1.0) AW = 1.0;*/ + /*s_h2o->la=log10(AW); */ + mu_x = I; + for (i = 0; i < 2 * count_s + sit_count_anions; i++) + { + if (sit_IPRSNT[i] == FALSE) continue; + spec[i]->lg_pitzer = sit_LGAMMA[i]; +/* + output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, sit_M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); +*/ + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_clean_up(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all allocated memory, except strings + */ + int i; + + for (i = 0; i < count_sit_param; i++) + { + sit_params[i] = (struct pitz_param *) free_check_null(sit_params[i]); + } + count_sit_param = 0; + sit_params = (struct pitz_param **) free_check_null(sit_params); + sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); + sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); + spec = (struct species **) free_check_null(spec); + sit_M = (LDBLE *) free_check_null(sit_M); + + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_sit(int initial) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sets initial guesses for unknowns if initial == TRUE + * Revises guesses whether initial is true or not + */ + int i; + struct solution *solution_ptr; +/* + * Set initial log concentrations to zero + */ + iterations = -1; + solution_ptr = use.Get_solution_ptr(); + for (i = 0; i < count_s_x; i++) + { + s_x[i]->lm = LOG_ZERO_MOLALITY; + s_x[i]->lg_pitzer = 0.0; + } + if (initial == TRUE || set_and_run_attempt > 0) + { + for (i = 0; i < count_s_x; i++) + { + s_x[i]->lg = 0.0; + } + } +/* + * Set master species activities + */ + tc_x = solution_ptr->tc; + tk_x = tc_x + 273.15; + patm_x = solution_ptr->patm; +/* + * H+, e-, H2O + */ + mass_water_aq_x = solution_ptr->mass_water; + mu_x = solution_ptr->mu; + s_h2o->moles = mass_water_aq_x / gfw_water; + s_h2o->la = log10(solution_ptr->ah2o); + AW = pow((LDBLE) 10.0E0, s_h2o->la); + s_hplus->la = -solution_ptr->ph; + s_hplus->lm = s_hplus->la; + s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; + s_eminus->la = -solution_ptr->solution_pe; + if (initial == TRUE) sit_initial_guesses(); + if (dl_type_x != NO_DL) initial_surface_water(); + sit_revise_guesses(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_initial_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make initial guesses for activities of master species and + * ionic strength + */ + int i; + struct solution *solution_ptr; + + solution_ptr = use.Get_solution_ptr(); + mu_x = + s_hplus->moles + + exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + mu_x /= mass_water_aq_x; + s_h2o->la = 0.0; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type < CB) + { + mu_x += + x[i]->moles / mass_water_aq_x * 0.5 * x[i]->master[0]->s->z * + x[i]->master[0]->s->z; + x[i]->master[0]->s->la = log10(x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == CB) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + { + x[i]->master[0]->s->la = + log10(0.001 * x[i]->moles / mass_water_aq_x); + } + else if (x[i]->type == EXCH) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(x[i]->moles); + } + } + else if (x[i]->type == SURFACE) + { + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + x[i]->master[0]->s->la = log10(0.1 * x[i]->moles); + } + } + else if (x[i]->type == SURFACE_CB) + { + x[i]->master[0]->s->la = 0.0; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit_revise_guesses(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Revise molalities species + */ + int i; + int l_iter, max_iter, repeat, fail; + LDBLE weight, f; + + max_iter = 10; + /* gammas(mu_x); */ + l_iter = 0; + repeat = TRUE; + fail = FALSE;; + while (repeat == TRUE) + { + l_iter++; + if (debug_set == TRUE) + { + output_msg(sformatf( "\nBeginning set iteration %d.\n", + l_iter)); + } + if (l_iter == max_iter + 1) + { + log_msg(sformatf( + "Did not converge in set, iteration %d.\n", + iterations)); + fail = TRUE; + } + if (l_iter > 2 * max_iter) + { + log_msg(sformatf( + "Did not converge with relaxed criteria in set.\n")); + return (OK); + } + molalities(TRUE); + /*pitzer(); */ + /*s_h2o->la = 0.0; */ + /*molalities(TRUE); */ + mb_sums(); + if (state < REACTION) + { + sum_species(); + } + else + { + for (i = 0; i < count_unknowns; i++) + { + x[i]->sum = x[i]->f; + } + } + /*n + if (debug_set == TRUE) { + pr.species = TRUE; + pr.all = TRUE; + print_species(); + } + */ + repeat = FALSE; + for (i = 0; i < count_unknowns; i++) + { + if (x[i] == ph_unknown || x[i] == pe_unknown) + continue; + if (x[i]->type == MB || +/* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || x[i]->type == SURFACE) + { + + if (debug_set == TRUE) + { + output_msg(sformatf( + "\n\t%5s at beginning of set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + if (fabs(x[i]->moles) < 1e-30) + x[i]->moles = 0; + f = fabs(x[i]->sum); + if (f == 0 && x[i]->moles == 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + continue; + } + else if (f == 0) + { + repeat = TRUE; + x[i]->master[0]->s->la += 5; +/*!!!!*/ if (x[i]->master[0]->s->la < -999.) + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + else if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + if (x[i]->moles <= 0) + { + x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; + } + else + { + repeat = TRUE; + x[i]->master[0]->s->la += + weight * log10(fabs(x[i]->moles / x[i]->sum)); + } + if (debug_set == TRUE) + { + output_msg(sformatf( + "\t%5s not converged in set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, + (double) x[i]->sum, (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + else if (x[i]->type == ALK) + { + f = total_co2; + if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + { + continue; + } + if (f > 1.5 * fabs(x[i]->moles) + || f < 1e-5 * fabs(x[i]->moles)) + { + repeat = TRUE; + weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + x[i]->master[0]->s->la += weight * + log10(fabs(x[i]->moles / x[i]->sum)); + if (debug_set == TRUE) + { + output_msg(sformatf( + "%s not converged in set. %e\t%e\t%e\n", + x[i]->description, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); + } + } + } + } + } + log_msg(sformatf( "Iterations in sit_revise_guesses: %d\n", l_iter)); + /*mu_x = mu_unknown->f * 0.5 / mass_water_aq_x; */ + if (mu_x <= 1e-8) + { + mu_x = 1e-8; + } + /*gammas(mu_x); */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +jacobian_sit(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE *base; + LDBLE d, d1, d2; + int i, j; + + if (full_pitzer == TRUE) + { + molalities(TRUE); + sit(); + residuals(); + } + base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); + if (base == NULL) + malloc_error(); + for (i = 0; i < count_unknowns; i++) + { + base[i] = residual[i]; + } + d = 0.0001; + d1 = d * log(10.0); + d2 = 0; + for (i = 0; i < count_unknowns; i++) + { + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case AH2O: + x[i]->master[0]->s->la += d; + d2 = d1; + break; + case PITZER_GAMMA: + x[i]->s->lg += d; + d2 = d; + break; + case MH2O: + mass_water_aq_x *= (1.0 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + d2 = log(1.0 + d); + break; + case MH: + s_eminus->la += d; + d2 = d1; + break; + /* + if (pitzer_pe == TRUE) + { + s_eminus->la += d; + d2 = d1; + break; + } + else + { + continue; + } + */ + case GAS_MOLES: + if (gas_in == FALSE) + continue; + d2 = d * x[i]->moles; + if (d2 < 1e-14) + d2 = 1e-14; + x[i]->moles += d2; + break; + case MU: + case PP: + case S_S_MOLES: + continue; + break; + } + molalities(TRUE); + if (full_pitzer == TRUE) + sit(); + mb_sums(); + residuals(); + for (j = 0; j < count_unknowns; j++) + { + array[j * (count_unknowns + 1) + i] = + -(residual[j] - base[j]) / d2; + } + switch (x[i]->type) + { + case MB: + case ALK: + case CB: + case SOLUTION_PHASE_BOUNDARY: + case EXCH: + case SURFACE: + case SURFACE_CB: + case SURFACE_CB1: + case SURFACE_CB2: + case AH2O: + x[i]->master[0]->s->la -= d; + break; + case MH: + s_eminus->la -= d; + if (array[i * (count_unknowns + 1) + i] == 0) + { + array[i * (count_unknowns + 1) + i] = + exp(s_h2->lm * LOG_10) * 2; + } + break; + case PITZER_GAMMA: + x[i]->s->lg -= d; + break; + case MH2O: + mass_water_aq_x /= (1 + d); + x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; + break; + case GAS_MOLES: + if (gas_in == FALSE) + continue; + x[i]->moles -= d2; + break; + } + } + molalities(TRUE); + if (full_pitzer == TRUE) + sit(); + mb_sums(); + residuals(); + free_check_null(base); + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +model_sit(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * model is called after the equations have been set up by prep + * and initial guesses have been made in set. + * + * Here is the outline of the calculation sequence: + * residuals--residuals are calculated, if small we are done + * sum_jacobian--jacobian is calculated + * ineq--inequality solver is called + * reset--estimates of unknowns revised, if changes are small solution + * has been found, usually convergence is found in residuals. + * gammas--new activity coefficients + * molalities--calculate molalities + * mb_sums--calculate mass-balance sums + * mb_gases--decide if gas_phase exists + * mb_s_s--decide if solid_solutions exists + * switch_bases--check to see if new basis species is needed + * reprep--rewrite equations with new basis species if needed + * sit_revise_guesses--revise unknowns to get initial mole balance + * check_residuals--check convergence one last time + * sum_species--calculate sums of elements from species concentrations + * + * An additional pass through may be needed if unstable phases still exist + * in the phase assemblage. + */ + int l_kode, return_kode; + int r; + int count_infeasible, count_basis_change; + int debug_model_save; + int mass_water_switch_save; + +/* debug_model = TRUE; */ +/* debug_prep = TRUE; */ +/* debug_set = TRUE; */ + /* mass_water_switch == TRUE, mass of water is constant */ + mass_water_switch_save = mass_water_switch; + if (mass_water_switch_save == FALSE && delay_mass_water == TRUE) + { + mass_water_switch = TRUE; + } + debug_model_save = debug_model; + pe_step_size_now = pe_step_size; + step_size_now = step_size; + if (!use.Get_kinetics_in()) status(0, NULL); + iterations = 0; + gamma_iterations = 0; + count_basis_change = count_infeasible = 0; + stop_program = FALSE; + remove_unstable_phases = FALSE; + if (always_full_pitzer == TRUE) + { + full_pitzer = TRUE; + } + else + { + full_pitzer = FALSE; + } + for (;;) + { + mb_gases(); + mb_s_s(); + l_kode = 1; + while ((r = residuals()) != CONVERGED + || remove_unstable_phases == TRUE) + { +#if defined(PHREEQCI_GUI) + if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == + WAIT_OBJECT_0) + { + error_msg("Execution canceled by user.", CONTINUE); + RaiseException(USER_CANCELED_RUN, 0, 0, NULL); + } +#endif + iterations++; + if (iterations > itmax - 1 && debug_model == FALSE + && pr.logfile == TRUE) + { + set_forward_output_to_log(TRUE); + debug_model = TRUE; + } + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nIteration %d\tStep_size = %f\n", iterations, + (double) step_size_now)); + output_msg(sformatf( "\t\tPe_step_size = %f\n\n", + (double) pe_step_size_now)); + } + /* + * Iterations exceeded + */ + if (iterations > itmax) + { + error_string = sformatf( "Maximum iterations exceeded, %d\n", + itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + /* + * Calculate jacobian + */ + gammas_sit(); + jacobian_sums(); + jacobian_sit(); + /* + * Full matrix with pure phases + */ + if (r == OK || remove_unstable_phases == TRUE) + { + return_kode = ineq(l_kode); + if (return_kode != OK) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + } + log_msg(sformatf( "Ineq had infeasible solution, " + "kode %d, iteration %d\n", return_kode, + iterations)); + count_infeasible++; + } + if (return_kode == 2) + { + ineq(0); + } + reset(); + } + gammas_sit(); + if (full_pitzer == TRUE) + sit(); + if (always_full_pitzer == TRUE) + { + full_pitzer = TRUE; + } + else + { + full_pitzer = FALSE; + } + molalities(TRUE); + if (use.Get_surface_ptr() != NULL && + use.Get_surface_ptr()->dl_type != NO_DL && + use.Get_surface_ptr()->related_phases == TRUE) + initial_surface_water(); + mb_sums(); + mb_gases(); + mb_s_s(); + /* debug + species_list_sort(); + sum_species(); + print_species(); + print_exchange(); + print_surface(); + */ + if (stop_program == TRUE) + { + break; + } + } +/* + * Check for stop_program + */ + + if (stop_program == TRUE) + { + break; + } + if (check_residuals() == ERROR) + { + stop_program = TRUE; + break; + } + /* remove_unstable_phases is set in check_residuals */ + if (remove_unstable_phases == FALSE && mass_water_switch_save == FALSE + && mass_water_switch == TRUE) + { + log_msg(sformatf( + "\nChanging water switch to FALSE. Iteration %d.\n", + iterations)); + mass_water_switch = FALSE; + continue; + } + gamma_iterations++; + if (gamma_iterations > itmax) + { + error_string = sformatf( "Maximum gamma iterations exceeded, %d\n", + itmax); + warning_msg(error_string); + stop_program = TRUE; + break; + } + if (check_gammas_sit() != TRUE) + { + full_pitzer = TRUE; + continue; + } + if (remove_unstable_phases == FALSE) + break; + if (debug_model == TRUE) + { + output_msg(sformatf( + "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nRemoving unstable phases. Iteration %d.\n", + iterations)); + } + log_msg(sformatf( "\nNumber of infeasible solutions: %d\n", + count_infeasible)); + log_msg(sformatf( "Number of basis changes: %d\n\n", + count_basis_change)); + log_msg(sformatf( "Number of iterations: %d\n\n", iterations)); + debug_model = debug_model_save; + set_forward_output_to_log(FALSE); + if (stop_program == TRUE) + { + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_gammas_sit(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE old_aw, old_mu, tol, t; + int converge, i; + + old_mu = mu_x; + old_aw = s_h2o->la; + sit(); + molalities(TRUE); + mb_sums(); + converge = TRUE; + tol = convergence_tolerance * 10.; + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type != PITZER_GAMMA) + continue; + if (fabs(x[i]->s->lg - x[i]->s->lg_pitzer) > tol) + { + converge = FALSE; + } + } + if (fabs(old_mu - mu_x) > tol) + { + converge = FALSE; + } + if (fabs(old_mu - mu_x) > 1e-3 * mu_x) + { + same_model = false; + k_temp(tc_x, patm_x); + } + t = pow((LDBLE) 10.0, s_h2o->la); + if ((pow((LDBLE) 10.0, s_h2o->la) - AW) > tol) + { + converge = FALSE; + } + return converge; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +gammas_sit() +/* ---------------------------------------------------------------------- */ +{ +/* + * Need exchange gammas for pitzer + */ + int i, j; + LDBLE coef; + /* Initialize */ +/* + * Calculate activity coefficients + */ + for (i = 0; i < count_s_x; i++) + { + switch (s_x[i]->gflag) + { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + break; + case 4: /* Exchange */ + /* Now calculated in next loop */ + break; + case 5: /* Always 1.0 */ + break; + case 6: /* Surface */ +/* + * Find moles of sites. + * s_x[i]->equiv is stoichiometric coefficient of sites in species + */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == SURF) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown->moles; + break; + } + } + if (s_x[i]->alk > 0) + { + s_x[i]->lg = log10(s_x[i]->equiv / s_x[i]->alk); + s_x[i]->dg = 0.0; + } + else + { + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + } + break; + case 7: /* LLNL */ + break; + case 8: /* LLNL CO2 */ + break; + case 9: /* activity water */ + s_x[i]->lg = log10(exp(s_h2o->la * LOG_10) * gfw_water); + s_x[i]->dg = 0.0; + break; + } +/* + if (mu_unknown != NULL) { + if (fabs(residual[mu_unknown->number]) > 0.1 && + fabs(residual[mu_unknown->number])/mu_x > 0.5) { + s_x[i]->dg = 0.0; + } + } + */ + } + /* + * calculate exchange gammas + */ + + if (use.Get_exchange_ptr() != NULL) + { + for (i = 0; i < count_s_x; i++) + { + switch (s_x[i]->gflag) + { + case 0: /* uncharged */ + case 1: /* Davies */ + case 2: /* Extended D-H, WATEQ D-H */ + case 3: /* Always 1.0 */ + case 5: /* Always 1.0 */ + case 6: /* Surface */ + case 7: /* LLNL */ + case 8: /* LLNL CO2 */ + case 9: /* activity water */ + break; + case 4: /* Exchange */ + + /* + * Find CEC + * z contains valence of cation for exchange species, alk contains cec + */ + /* !!!!! */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == EX) + { + s_x[i]->alk = + s_x[i]->rxn_x->token[j].s->primary->unknown-> + moles; + break; + } + } + /* + * Master species is a dummy variable with meaningless activity and mass + */ + s_x[i]->lg = 0.0; + s_x[i]->dg = 0.0; + if (s_x[i]->primary != NULL) + { + break; + } + /* + * All other species + */ + + /* modific 29 july 2005... */ + if (s_x[i]->equiv != 0 && s_x[i]->alk > 0) + { + s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); + } + if (((cxxExchange *) use.Get_exchange_ptr())->Get_pitzer_exchange_gammas()) + { + /* Assume equal gamma's of solute and exchangeable species... */ + for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) + { + if (s_x[i]->rxn_x->token[j].s->type == EX) + continue; + coef = s_x[i]->rxn_x->token[j].coef; + s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg; + s_x[i]->dg += coef * s_x[i]->rxn_x->token[j].s->dg; + } + } + } + } + } +/* ...end modific 29 july 2005 */ + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +PTEMP_SIT(LDBLE TK) +/* ---------------------------------------------------------------------- */ +{ +/* +C +C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER +C +*/ + LDBLE DC0; + int i; + LDBLE TR = 298.15; + + if (fabs(TK - OTEMP) < 0.001e0) return OK; + OTEMP = TK; +/* +C Set DW0 +*/ + DW(TK); + for (i = 0; i < count_sit_param; i++) + { + calc_sit_param(sit_params[i], TK, TR); + } + DC0 = DC(TK); + if (fabs(TK - TR) < 0.001e0) + { + sit_A0 = 0.392e0; + } + else + { + DC0 = DC(TK); + sit_A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); + /*sit_A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ + } + return OK; +} diff --git a/rename_cpp/smalldense.cpp b/rename_cpp/smalldense.cpp new file mode 100644 index 00000000..b7ac1d58 --- /dev/null +++ b/rename_cpp/smalldense.cpp @@ -0,0 +1,270 @@ +/******************************************************************* + * * + * File : smalldense.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package, intended for small dense matrices. * + * * + *******************************************************************/ + +#include +#include +#include "smalldense.h" +#include "sundialstypes.h" +#include "sundialsmath.h" +/* WARNING don't include any headers below here */ + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) + +/* Implementation */ + +realtype ** +denalloc(integertype n) +{ + integertype j; + realtype **a; + + if (n <= 0) + return (NULL); + + a = (realtype **) malloc(n * sizeof(realtype *)); + if (a == NULL) + return (NULL); + + a[0] = (realtype *) malloc(n * n * sizeof(realtype)); + if (a[0] == NULL) + { + free(a); + return (NULL); + } + + for (j = 1; j < n; j++) + a[j] = a[0] + j * n; + + return (a); +} + +integertype * +denallocpiv(integertype n) +{ + if (n <= 0) + return (NULL); + + return ((integertype *) malloc(n * sizeof(integertype))); +} + +integertype +gefa(realtype ** a, integertype n, integertype * p) +{ + integertype i, j, k, l; + realtype *col_j, *col_k, *diag_k; + realtype temp, mult, a_kj; + booleantype swap; + + /* k = elimination step number */ + + for (k = 0; k < n - 1; k++, p++) + { + + col_k = a[k]; + diag_k = col_k + k; + + /* find l = pivot row number */ + + l = k; + for (i = k + 1; i < n; i++) + if (ABS(col_k[i]) > ABS(col_k[l])) + l = i; + *p = l; + + /* check for zero pivot element */ + + if (col_k[l] == ZERO) + return (k + 1); + + /* swap a(l,k) and a(k,k) if necessary */ + + /*if ( (swap = (l != k) )) { */ + swap = (l != k); + if (swap) + { + temp = col_k[l]; + col_k[l] = *diag_k; + *diag_k = temp; + } + + /* Scale the elements below the diagonal in */ + /* column k by -1.0 / a(k,k). After the above swap, */ + /* a(k,k) holds the pivot element. This scaling */ + /* stores the pivot row multipliers -a(i,k)/a(k,k) */ + /* in a(i,k), i=k+1, ..., n-1. */ + + mult = -ONE / (*diag_k); + for (i = k + 1; i < n; i++) + col_k[i] *= mult; + + /* row_i = row_i - [a(i,k)/a(k,k)] row_k, i=k+1, ..., n-1 */ + /* row k is the pivot row after swapping with row l. */ + /* The computation is done one column at a time, */ + /* column j=k+1, ..., n-1. */ + + for (j = k + 1; j < n; j++) + { + + col_j = a[j]; + a_kj = col_j[l]; + + /* Swap the elements a(k,j) and a(k,l) if l!=k. */ + + if (swap) + { + col_j[l] = col_j[k]; + col_j[k] = a_kj; + } + + /* a(i,j) = a(i,j) - [a(i,k)/a(k,k)]*a(k,j) */ + /* a_kj = a(k,j), col_k[i] = - a(i,k)/a(k,k) */ + + if (a_kj != ZERO) + { + for (i = k + 1; i < n; i++) + col_j[i] += a_kj * col_k[i]; + } + } + } + + /* set the last pivot row to be n-1 and check for a zero pivot */ + + *p = n - 1; + if (a[n - 1][n - 1] == ZERO) + return (n); + + /* return 0 to indicate success */ + + return (0); +} + +void +gesl(realtype ** a, integertype n, integertype * p, realtype * b) +{ + integertype k, l, i; + realtype mult, *col_k; + + /* Solve Ly = Pb, store solution y in b */ + + for (k = 0; k < n - 1; k++) + { + l = p[k]; + mult = b[l]; + if (l != k) + { + b[l] = b[k]; + b[k] = mult; + } + col_k = a[k]; + for (i = k + 1; i < n; i++) + b[i] += mult * col_k[i]; + } + + /* Solve Ux = y, store solution x in b */ + + for (k = n - 1; k >= 0; k--) + { + col_k = a[k]; + b[k] /= col_k[k]; + mult = -b[k]; + for (i = 0; i < k; i++) + b[i] += mult * col_k[i]; + } +} + +void +denzero(realtype ** a, integertype n) +{ + integertype i, j; + realtype *col_j; + + for (j = 0; j < n; j++) + { + col_j = a[j]; + for (i = 0; i < n; i++) + col_j[i] = ZERO; + } +} + +void +dencopy(realtype ** a, realtype ** b, integertype n) +{ + integertype i, j; + realtype *a_col_j, *b_col_j; + + for (j = 0; j < n; j++) + { + a_col_j = a[j]; + b_col_j = b[j]; + for (i = 0; i < n; i++) + b_col_j[i] = a_col_j[i]; + } + +} + +void +denscale(realtype c, realtype ** a, integertype n) +{ + integertype i, j; + realtype *col_j; + + for (j = 0; j < n; j++) + { + col_j = a[j]; + for (i = 0; i < n; i++) + col_j[i] *= c; + } +} + +void +denaddI(realtype ** a, integertype n) +{ + integertype i; + + for (i = 0; i < n; i++) + a[i][i] += ONE; +} + +void +denfreepiv(integertype * p) +{ + free(p); +} + +void +denfree(realtype ** a) +{ + free(a[0]); + free(a); +} + +void +denprint(realtype ** a, integertype n) +{ + integertype i, j; + + printf("\n"); + for (i = 0; i < n; i++) + { + for (j = 0; j < n; j++) + { + printf("%10g", (double) a[j][i]); + } + printf("\n"); + } + printf("\n"); +} diff --git a/rename_cpp/smalldense.h b/rename_cpp/smalldense.h new file mode 100644 index 00000000..c7410427 --- /dev/null +++ b/rename_cpp/smalldense.h @@ -0,0 +1,217 @@ +/******************************************************************* + * * + * File : smalldense.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a generic DENSE linear solver * + * package, intended for small dense matrices. These routines * + * use the type realtype** for dense matrix arguments. * + * * + * These routines begin with "den" (except for the factor and * + * solve routines which are called gefa and gesl, respectively). * + * The underlying matrix storage is described in the * + * documentation for denalloc. * + * * + *******************************************************************/ +#ifndef _smalldense_h +#define _smalldense_h + +#include "sundialstypes.h" + + +/****************************************************************** + * * + * Function : denalloc * + * Usage : realtype **a; * + * a = denalloc(n); * + * if (a == NULL) ... memory request failed * + *----------------------------------------------------------------* + * denalloc(n) allocates storage for an n by n dense matrix. It * + * returns a pointer to the newly allocated storage if * + * successful. If the memory request cannot be satisfied, then * + * denalloc returns NULL. The underlying type of the dense matrix * + * returned is realtype **. If we allocate a dense matrix * + * realtype **a by a = denalloc(n), then a[j][i] references the * + * (i,j)th element of the matrix a, 0 <= i,j <= n-1, and a[j] is * + * a pointer to the first element in the jth column of a. * + * The location a[0] contains a pointer to n^2 contiguous * + * locations which contain the elements of a. * + * * + ******************************************************************/ + + realtype **denalloc(integertype n); + + +/****************************************************************** + * * + * Function : denallocpiv * + * Usage : integertype *pivot; * + * pivot = denallocpiv(n); * + * if (pivot == NULL) ... memory request failed * + *----------------------------------------------------------------* + * denallocpiv(n) allocates an array of n integertype. It returns * + * a pointer to the first element in the array if successful. * + * It returns NULL if the memory request could not be satisfied. * + * * + ******************************************************************/ + + integertype *denallocpiv(integertype n); + + +/****************************************************************** + * * + * Function : gefa * + * Usage : integertype ier; * + * ier = gefa(a,n,p); * + * if (ier > 0) ... zero element encountered during * + * the factorization * + *----------------------------------------------------------------* + * gefa(a,n,p) factors the n by n dense matrix a. It overwrites * + * the elements of a with its LU factors and keeps track of the * + * pivot rows chosen in the pivot array p. * + * * + * A successful LU factorization leaves the matrix a and the * + * pivot array p with the following information: * + * * + * (1) p[k] contains the row number of the pivot element chosen * + * at the beginning of elimination step k, k=0, 1, ..., n-1. * + * * + * (2) If the unique LU factorization of a is given by Pa = LU, * + * where P is a permutation matrix, L is a lower triangular * + * matrix with all 1's on the diagonal, and U is an upper * + * triangular matrix, then the upper triangular part of a * + * (including its diagonal) contains U and the strictly lower * + * triangular part of a contains the multipliers, I-L. * + * * + * gefa returns 0 if successful. Otherwise it encountered a zero * + * diagonal element during the factorization. In this case it * + * returns the column index (numbered from one) at which it * + * encountered the zero. * + * * + ******************************************************************/ + + integertype gefa(realtype ** a, integertype n, integertype * p); + + +/****************************************************************** + * * + * Function : gesl * + * Usage : realtype *b; * + * ier = gefa(a,n,p); * + * if (ier == 0) gesl(a,n,p,b); * + *----------------------------------------------------------------* + * gesl(a,n,p,b) solves the n by n linear system ax = b. It * + * assumes that a has been LU factored and the pivot array p has * + * been set by a successful call to gefa(a,n,p). The solution x * + * is written into the b array. * + * * + ******************************************************************/ + + void gesl(realtype ** a, integertype n, integertype * p, realtype * b); + + +/****************************************************************** + * * + * Function : denzero * + * Usage : denzero(a,n); * + *----------------------------------------------------------------* + * denzero(a,n) sets all the elements of the n by n dense matrix * + * a to be 0.0. * + * * + ******************************************************************/ + + void denzero(realtype ** a, integertype n); + + +/****************************************************************** + * * + * Function : dencopy * + * Usage : dencopy(a,b,n); * + *----------------------------------------------------------------* + * dencopy(a,b,n) copies the n by n dense matrix a into the * + * n by n dense matrix b. * + * * + ******************************************************************/ + + void dencopy(realtype ** a, realtype ** b, integertype n); + + +/****************************************************************** + * * + * Function : denscale * + * Usage : denscale(c,a,n); * + *----------------------------------------------------------------* + * denscale(c,a,n) scales every element in the n by n dense * + * matrix a by c. * + * * + ******************************************************************/ + + void denscale(realtype c, realtype ** a, integertype n); + + +/****************************************************************** + * * + * Function : denaddI * + * Usage : denaddI(a,n); * + *----------------------------------------------------------------* + * denaddI(a,n) increments the n by n dense matrix a by the * + * identity matrix. * + * * + ******************************************************************/ + + void denaddI(realtype ** a, integertype n); + + +/****************************************************************** + * * + * Function : denfreepiv * + * Usage : denfreepiv(p); * + *----------------------------------------------------------------* + * denfreepiv(p) frees the pivot array p allocated by * + * denallocpiv. * + * * + ******************************************************************/ + + void denfreepiv(integertype * p); + + +/****************************************************************** + * * + * Function : denfree * + * Usage : denfree(a); * + *----------------------------------------------------------------* + * denfree(a) frees the dense matrix a allocated by denalloc. * + * * + ******************************************************************/ + + void denfree(realtype ** a); + + +/****************************************************************** + * * + * Function : denprint * + * Usage : denprint(a,n); * + *----------------------------------------------------------------* + * denprint(a,n) prints the n by n dense matrix a to standard * + * output as it would normally appear on paper. It is intended as * + * a debugging tool with small values of n. The elements are * + * printed using the %g option. A blank line is printed before * + * and after the matrix. * + * * + ******************************************************************/ + + void denprint(realtype ** a, integertype n); + + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ diff --git a/rename_cpp/spread.cpp b/rename_cpp/spread.cpp new file mode 100644 index 00000000..2e35841c --- /dev/null +++ b/rename_cpp/spread.cpp @@ -0,0 +1,1335 @@ +typedef unsigned char boolean; +#include "Phreeqc.h" +#include "phqalloc.h" + +#define STRING 11 +#define NUMBER 12 +#define MIXED 13 +#define EOL 14 + +#define OPTION_EOF -1 +#define OPTION_KEYWORD -2 +#define OPTION_ERROR -3 +#define OPTION_DEFAULT -4 +#define OPT_1 -5 + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solution_spread(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + struct spread_row *heading, *row_ptr, *units; + int i, j, l, j1, num, count; + int strings, numbers; + int spread_lines; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char *ptr; + struct defaults soln_defaults; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "isotope_uncertainty", /* 11 */ + "uncertainty", /* 12 */ + "uncertainties", /* 13 */ + "pressure" /* 14 */ + }; + int count_opt_list = 15; +/* + * Initialize defaults + */ + soln_defaults.temp = 25; + soln_defaults.density = 1.0; + soln_defaults.units = string_hsave("mmol/kgw"); + soln_defaults.redox = string_hsave("pe"); + soln_defaults.ph = 7.0; + soln_defaults.pe = 4.0; + soln_defaults.water = 1.0; + soln_defaults.pressure = 1.0; + + /* fill in soln_defaults.iso */ + soln_defaults.count_iso = count_iso_defaults; + soln_defaults.iso = + (struct iso *) PHRQ_malloc((size_t) soln_defaults.count_iso * + sizeof(struct iso)); + if (soln_defaults.iso == NULL) + malloc_error(); + /* all iso[i].name is hsave'd, so no conflicts */ + memcpy(soln_defaults.iso, iso_defaults, + (size_t) soln_defaults.count_iso * sizeof(struct iso)); + + heading = NULL; + units = NULL; + return_value = UNKNOWN; + spread_lines = 0; +/* + * Loop on solutions + */ + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (spread_lines == 0 && opt != OPTION_DEFAULT) + { + row_ptr = string_to_spread_row(line); + count = 0; + ptr = line; + numbers = 0; + strings = 0; + while (((j = copy_token(token, &ptr, &l)) != EMPTY)) + { + count++; + if (j == UPPER || j == LOWER) + strings++; + if (j == DIGIT) + numbers++; + } + /* + * Is 2nd token all number + */ + ptr = line; + copy_token(token, &ptr, &l); + j = copy_token(token, &ptr, &l); + num = FALSE; + if (j == DIGIT) + { + strtod(token, &ptr); + j1 = copy_token(token1, &ptr, &l); + if (j1 != EMPTY) + { + num = FALSE; + } + else + { + num = TRUE; + } + } + + /* + * Starts with hyphen + */ + ptr = line; + copy_token(token, &ptr, &l); + if (token[0] == '-') + { + opt = opt; + } + else + { + switch (opt) + { + case 0: /* temp */ + case 1: /* temperature */ + case 2: /* dens */ + case 3: /* density */ + case 10: /* water */ + if (count == 2 && num == TRUE) + { + opt = opt; + } + else + { + opt = OPTION_DEFAULT; + } + break; + case 6: /* ph */ + case 7: /* pe */ + if ((count == 2 || count == 3 || count == 4) + && num == TRUE) + { + opt = opt; + } + else + { + opt = OPTION_DEFAULT; + } + break; + case 5: /* redox */ + case 4: /* units */ + case 8: /* unit */ + if (count == 2) + { + opt = opt; + } + else + { + opt = OPTION_DEFAULT; + } + break; + case 9: /* isotope */ + if (row_ptr->count > 4) + { + opt = OPTION_DEFAULT; + } + else + { + opt = opt; + } + break; + case 11: /* isotope_uncertainty */ + case 12: /* uncertainty */ + case 13: /* uncertainties */ + if (row_ptr->count > 3) + { + opt = OPTION_DEFAULT; + } + else + { + opt = opt; + } + break; + case 14: /* pressure */ + sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); + break; + } + } + spread_row_free(row_ptr); + } + if (opt == OPTION_DEFAULT) + { + if (spread_lines == 0) + { + opt = 100; + } + spread_lines++; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case OPTION_DEFAULT: /* solution definition */ + row_ptr = string_to_spread_row(line); + if (spread_lines == 2) + { + numbers = 0; + strings = 0; + for (i = 0; i < heading->count; i++) + { + if (row_ptr->type_vector[i] == STRING) + { + strings++; + } + else if (row_ptr->type_vector[i] == NUMBER) + { + numbers++; + } + } + if (numbers == 0) + { + units = row_ptr; + break; + } + } + spread_row_to_solution(heading, units, row_ptr, soln_defaults); +#ifdef PHREEQCI_GUI + add_row(row_ptr); +#endif + spread_row_free(row_ptr); + break; + case 0: /* temperature */ + case 1: + sscanf(next_char, SCANFORMAT, &(soln_defaults.temp)); + break; + case 2: /* density */ + case 3: + sscanf(next_char, SCANFORMAT, &(soln_defaults.density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + { + if (check_units(token, FALSE, FALSE, NULL, TRUE) == OK) + { + soln_defaults.units = string_hsave(token); + } + else + { + input_error++; + } + } + break; + case 5: /* redox */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + if (parse_couple(token) == OK) + { + soln_defaults.redox = string_hsave(token); + } + else + { + input_error++; + } + break; + case 6: /* ph */ + copy_token(token, &next_char, &l); + sscanf(token, SCANFORMAT, &(soln_defaults.ph)); + if (copy_token(token, &next_char, &l) != EMPTY) + { + warning_msg + ("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD."); + } + break; + case 7: /* pe */ + copy_token(token, &next_char, &l); + sscanf(token, SCANFORMAT, &(soln_defaults.pe)); + if (copy_token(token, &next_char, &l) != EMPTY) + { + warning_msg + ("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD."); + } + break; + case 11: /* isotope_uncertainty */ + case 12: /* uncertainty */ + case 13: /* uncertainties */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + for (i = 0; i < soln_defaults.count_iso; i++) + { + if (strcmp(token, soln_defaults.iso[i].name) == 0) + { + break; + } + } + if (i == soln_defaults.count_iso) + { + soln_defaults.iso = + (struct iso *) PHRQ_realloc(soln_defaults.iso, + (size_t) (i + + 1) * + sizeof(struct iso)); + if (soln_defaults.iso == NULL) + malloc_error(); + soln_defaults.iso[i].name = string_hsave(token); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } + + /* read and store isotope ratio uncertainty */ + if ((j = copy_token(token, &next_char, &l)) != EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + else + { + sscanf(token, SCANFORMAT, + &(soln_defaults.iso[i].uncertainty)); + } + } + else + { + soln_defaults.iso[i].uncertainty = NAN; + } + break; + case 10: /* water */ + j = copy_token(token, &next_char, &l); + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token, SCANFORMAT, &(soln_defaults.water)); + } + break; + case 9: /* isotope */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + for (i = 0; i < soln_defaults.count_iso; i++) + { + if (strcmp(token, soln_defaults.iso[i].name) == 0) + { + break; + } + } + if (i == soln_defaults.count_iso) + { + soln_defaults.iso = + (struct iso *) PHRQ_realloc(soln_defaults.iso, + (size_t) (i + + 1) * + sizeof(struct iso)); + if (soln_defaults.iso == NULL) + malloc_error(); + soln_defaults.iso[i].name = string_hsave(token); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for default isotope ratio."); + error_msg(error_string, CONTINUE); + break; + } + sscanf(token, SCANFORMAT, &(soln_defaults.iso[i].value)); + /* read and store isotope ratio uncertainty */ + if ((j = copy_token(token, &next_char, &l)) != EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + else + { + sscanf(token, SCANFORMAT, + &(soln_defaults.iso[i].uncertainty)); + } + } + break; + case 14: /* pressure */ + sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); + break; + case 100: /* read headings */ + heading = string_to_spread_row(line); + for (i = 0; i < heading->count; i++) + { + while (replace(" ", "", heading->char_vector[i]) == TRUE); + while (replace(",", "_", heading->char_vector[i]) == TRUE); + } + + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +#ifdef PHREEQCI_GUI + if (heading) + g_spread_sheet.heading = copy_row(heading); + if (units) + g_spread_sheet.units = copy_row(units); + copy_defaults(&g_spread_sheet.defaults, &soln_defaults); +#endif + spread_row_free(heading); + spread_row_free(units); + + soln_defaults.iso = (struct iso *) free_check_null(soln_defaults.iso); + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +spread_row_to_solution(struct spread_row *heading, struct spread_row *units, + struct spread_row *data, struct defaults defaults) +/* ---------------------------------------------------------------------- */ +{ + int i, j, n, l; + Keywords::KEYWORDS next_keyword_save; + int n_user, n_user_end; + int default_pe, alk; + int count_isotopes; + int max_mass_balance, count_mass_balance; + char *ptr, *ptr1; + char *description; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + char string[2 * MAX_LENGTH]; + LDBLE l_dummy; + + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "description", /* 11 */ + "desc", /* 12 */ + "descriptor" /* 13 */ + }; + int count_opt_list = 14; + +/* + * look for solution number + */ + n_user = -1; + n_user_end = -1; + description = string_duplicate(""); + for (i = 0; i < heading->count; i++) + { + if (strcmp_nocase(heading->char_vector[i], "number") == 0) + { + break; + } + } + if (i == heading->count || data->type_vector[i] == EMPTY + || data->count <= i) + { + n_user = -1; + } + else if (data->type_vector[i] == STRING) + { + input_error++; + error_string = sformatf( + "Expected solution number or number range in 'number' column, found: %s.", + data->char_vector[i]); + error_msg(error_string, CONTINUE); + } + else + { + strcpy(string, "solution_s "); + strcat(string, data->char_vector[i]); + ptr = string; + description = (char *) free_check_null(description); + next_keyword_save = next_keyword; + next_keyword = Keywords::KEY_SOLUTION_SPREAD; + read_number_description(ptr, &n_user, &n_user_end, &description); + next_keyword = next_keyword_save; + } +/* + * set up solution + */ + + if (n_user >= 0 && solution_bsearch(n_user, &n, FALSE) != NULL) + { + solution_free(solution[n]); + } + else + { + n = count_solution++; + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } + } + solution[n] = solution_alloc(); + + solution[n]->n_user = n_user; + solution[n]->n_user_end = n_user_end; + if (use.Get_solution_in() == FALSE) + { + use.Set_solution_in(true); + use.Set_n_solution_user(n_user); + } + max_mass_balance = MAX_MASS_BALANCE; +/* + * Set default ph, temp, density, pe, units + */ + solution[n]->description = description; + solution[n]->tc = defaults.temp; + solution[n]->patm = defaults.pressure; + solution[n]->ph = defaults.ph; + solution[n]->density = defaults.density; + solution[n]->solution_pe = defaults.pe; + solution[n]->mass_water = defaults.water; + solution[n]->ah2o = 1.0; + solution[n]->mu = 1e-7; + solution[n]->cb = 0.0; + default_pe = 0; + solution[n]->units = defaults.units; + solution[n]->totals[0].description = NULL; + count_mass_balance = 0; + count_isotopes = 0; + default_pe = pe_data_store(&(solution[n]->pe), defaults.redox); +/* + * Read concentration data + */ + return_value = UNKNOWN; + for (i = 0; i < heading->count; i++) + { + if (strcmp_nocase(heading->char_vector[i], "number") == 0) + continue; + if (strcmp_nocase(heading->char_vector[i], "uncertainty") == 0) + continue; + if (strcmp_nocase(heading->char_vector[i], "uncertainties") == 0) + continue; + if (strcmp_nocase(heading->char_vector[i], "isotope_uncertainty") == + 0) + continue; + /* + * Copy in element name + */ + if (heading->type_vector[i] == EMPTY) + continue; + strcpy(string, heading->char_vector[i]); + strcat(string, " "); + /* + * Copy in concentration data + */ + if (i >= data->count || data->type_vector[i] == EMPTY) + continue; + strcat(string, data->char_vector[i]); + strcat(string, " "); + /* + * Copy in concentration data + */ + if (units != NULL && i < units->count + && units->type_vector[i] != EMPTY) + { + strcat(string, units->char_vector[i]); + } +/* + * Parse string just like read_solution input + */ + next_char = string; + opt = get_option_string(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT && heading->type_vector[i] == NUMBER) + { + opt = 9; + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* temperature */ + case 1: + sscanf(next_char, SCANFORMAT, &(solution[n]->tc)); + break; + case 2: /* density */ + case 3: + sscanf(next_char, SCANFORMAT, &(solution[n]->density)); + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + { + if (check_units(token, FALSE, FALSE, solution[n]->units, TRUE) == + OK) + { + solution[n]->units = string_hsave(token); + } + else + { + input_error++; + } + } + break; + case 5: /* redox */ + if (copy_token(token, &next_char, &l) == EMPTY) + break; + if (parse_couple(token) == OK) + { + default_pe = pe_data_store(&(solution[n]->pe), token); + } + else + { + input_error++; + } + break; + case 6: /* ph */ + next_char = string; + if (read_conc(n, count_mass_balance, next_char) == ERROR) + { + input_error++; + break; + } + solution[n]->ph = + solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL) + { + break; + } + solution[n]->totals[count_mass_balance].description = + string_hsave("H(1)"); + count_mass_balance++; + break; + case 7: /* pe */ + next_char = string; + if (read_conc(n, count_mass_balance, next_char) == ERROR) + { + input_error++; + break; + } + solution[n]->solution_pe = + solution[n]->totals[count_mass_balance].input_conc; + if (solution[n]->totals[count_mass_balance].equation_name == NULL) + { + break; + } + solution[n]->totals[count_mass_balance].description = + string_hsave("E"); + count_mass_balance++; + break; + case 9: /* isotope */ + next_char = string; + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + solution[n]->isotopes = + (struct isotope *) PHRQ_realloc(solution[n]->isotopes, + (size_t) (count_isotopes + + 1) * + sizeof(struct isotope)); + if (solution[n]->isotopes == NULL) + malloc_error(); + /* read and save element name */ + ptr1 = token; + get_num(&ptr1, + &(solution[n]->isotopes[count_isotopes].isotope_number)); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) + { + error_msg("Expecting element name.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + return (ERROR); + } + solution[n]->isotopes[count_isotopes].elt_name = + string_hsave(ptr1); + + /* read and store isotope ratio */ + if (copy_token(token, &next_char, &l) != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token, SCANFORMAT, + &(solution[n]->isotopes[count_isotopes].ratio)); + + /* read and store isotope ratio uncertainty */ + /* first choice is next column */ + if ((i + 1) < heading->count && + (strcmp_nocase(heading->char_vector[i + 1], "uncertainty") == + 0 + || strcmp_nocase(heading->char_vector[i + 1], + "isotope_uncertainty") == 0 + || strcmp_nocase(heading->char_vector[i + 1], + "uncertainties") == 0) + && (i + 1) < data->count + && data->type_vector[i + 1] == NUMBER) + { + solution[n]->isotopes[count_isotopes].ratio_uncertainty = + data->d_vector[i + 1]; + } + else + { + next_char = string; + copy_token(token, &next_char, &l); + for (j = 0; j < defaults.count_iso; j++) + { + if (strcmp(token, defaults.iso[j].name) == 0) + { + solution[n]->isotopes[count_isotopes]. + ratio_uncertainty = defaults.iso[j].uncertainty; + break; + } + } + if (j == defaults.count_iso) + { + solution[n]->isotopes[count_isotopes].ratio_uncertainty = + NAN; + } + } + count_isotopes++; + break; + case 10: /* water */ + j = copy_token(token, &next_char, &l); + if (j == EMPTY) + { + solution[n]->mass_water = 1.0; + } + else if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token, SCANFORMAT, &l_dummy); + solution[n]->mass_water = (LDBLE) l_dummy; + } + break; + case 11: /* description */ + case 12: /* desc */ + case 13: /* descriptor */ + solution[n]->description = + (char *) free_check_null(solution[n]->description); + solution[n]->description = string_duplicate(next_char); + break; + case OPTION_DEFAULT: +/* + * Read concentration + */ + next_char = string; + if (copy_token(token, &next_char, &l) == LOWER) + continue; + next_char = string; + if (read_conc(n, count_mass_balance, next_char) == ERROR) + { +#ifdef SKIP + input_error++; + break; +#endif + } + count_mass_balance++; + break; + } + if (count_mass_balance + 1 >= max_mass_balance) + { + space((void **) ((void *) &(solution[n]->totals)), + count_mass_balance + 1, &max_mass_balance, + sizeof(struct conc)); + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * Sort totals by description + */ + qsort(solution[n]->totals, + (size_t) count_mass_balance, + (size_t) sizeof(struct conc), conc_compare); +/* + * fix up default units and default pe + */ + for (i = 0; i < count_mass_balance; i++) + { + strcpy(token, solution[n]->totals[i].description); + str_tolower(token); + if (solution[n]->totals[i].units == NULL) + { + solution[n]->totals[i].units = solution[n]->units; + } + else + { + alk = FALSE; + if (strstr(token, "alk") == token) + alk = TRUE; + strcpy(token1, solution[n]->totals[i].units); + if (check_units(token1, alk, TRUE, solution[n]->units, TRUE) == + ERROR) + { + input_error++; + } + else + { + solution[n]->totals[i].units = string_hsave(token1); + } + } + if (solution[n]->totals[i].n_pe < 0) + { + solution[n]->totals[i].n_pe = default_pe; + } + } + solution[n]->default_pe = default_pe; +/* + * Mark end of solution + */ + solution[n]->totals[count_mass_balance].description = NULL; + solution[n]->count_isotopes = count_isotopes; + if (count_isotopes > 0) + { + qsort(solution[n]->isotopes, + (size_t) count_isotopes, + (size_t) sizeof(struct isotope), isotope_compare); + } + else + { + solution[n]->isotopes = + (struct isotope *) free_check_null(solution[n]->isotopes); + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +struct spread_row * Phreeqc:: +string_to_spread_row(char *string) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + static int length = 10; /* possible memory error if length of line is smaller than previous line */ + char *token; + char *ptr; + struct spread_row *spread_row_ptr; +/* + * Allocate space + */ + token = (char *) PHRQ_malloc(strlen(line) + 1); + if (token == NULL) + malloc_error(); + spread_row_ptr = + (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); + if (spread_row_ptr == NULL) + malloc_error(); + spread_row_ptr->char_vector = + (char **) PHRQ_malloc((size_t) length * sizeof(char *)); + if (spread_row_ptr->char_vector == NULL) + malloc_error(); + spread_row_ptr->d_vector = + (LDBLE *) PHRQ_malloc((size_t) length * sizeof(LDBLE)); + if (spread_row_ptr->d_vector == NULL) + malloc_error(); + spread_row_ptr->type_vector = + (int *) PHRQ_malloc((size_t) length * sizeof(int)); + if (spread_row_ptr->type_vector == NULL) + malloc_error(); + spread_row_ptr->count = 0; + spread_row_ptr->empty = 0; + spread_row_ptr->string = 0; + spread_row_ptr->number = 0; + ptr = string; +/* + * Split by tabs, reallocate space + */ + for (;;) + { + if (spread_row_ptr->count + 1 > length) + { + length *= 2; + + spread_row_ptr->char_vector = + (char **) PHRQ_realloc(spread_row_ptr->char_vector, + (size_t) length * sizeof(char *)); + if (spread_row_ptr->char_vector == NULL) + malloc_error(); + + spread_row_ptr->d_vector = + (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, + (size_t) length * sizeof(LDBLE)); + if (spread_row_ptr->d_vector == NULL) + malloc_error(); + + spread_row_ptr->type_vector = + (int *) PHRQ_realloc(spread_row_ptr->type_vector, + (size_t) length * sizeof(int)); + if (spread_row_ptr->type_vector == NULL) + malloc_error(); + } + j = copy_token_tab(token, &ptr, &l); + if (j == EOL) + break; + spread_row_ptr->char_vector[spread_row_ptr->count] = + string_duplicate(token); + spread_row_ptr->d_vector[spread_row_ptr->count] = NAN; + if (j == EMPTY || l == 0) + { + spread_row_ptr->empty++; + spread_row_ptr->type_vector[spread_row_ptr->count] = EMPTY; + } + else if (j == UPPER || j == LOWER) + { + spread_row_ptr->string++; + spread_row_ptr->type_vector[spread_row_ptr->count] = STRING; + } + else if (j == DIGIT) + { + spread_row_ptr->number++; + spread_row_ptr->d_vector[spread_row_ptr->count] = + strtod(token, NULL); + spread_row_ptr->type_vector[spread_row_ptr->count] = NUMBER; + } + spread_row_ptr->count++; + } +/* + * Clean up and return + */ + if (spread_row_ptr->count == 0) + { + spread_row_ptr->char_vector = + (char **) free_check_null(spread_row_ptr->char_vector); + spread_row_ptr->d_vector = + (LDBLE *) free_check_null(spread_row_ptr->d_vector); + spread_row_ptr->type_vector = + (int *) free_check_null(spread_row_ptr->type_vector); + } + else + { +/* Do not realloc to smaller size, memory error */ +/* + spread_row_ptr->char_vector = + (char **) PHRQ_realloc (spread_row_ptr->char_vector, + (size_t) spread_row_ptr->count * + sizeof (char *)); + if (spread_row_ptr->char_vector == NULL) + malloc_error (); + spread_row_ptr->d_vector = + (LDBLE *) PHRQ_realloc (spread_row_ptr->d_vector, + (size_t) spread_row_ptr->count * + sizeof (LDBLE)); + if (spread_row_ptr->d_vector == NULL) + malloc_error (); + spread_row_ptr->type_vector = + (int *) PHRQ_realloc (spread_row_ptr->type_vector, + (size_t) spread_row_ptr->count * sizeof (int)); + if (spread_row_ptr->type_vector == NULL) + malloc_error (); +*/ + } + token = (char *) free_check_null(token); + return (spread_row_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +spread_row_free(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (spread_row_ptr == NULL) + return (OK); + for (i = 0; i < spread_row_ptr->count; i++) + { + spread_row_ptr->char_vector[i] = + (char *) free_check_null(spread_row_ptr->char_vector[i]); + } + + spread_row_ptr->char_vector = + (char **) free_check_null(spread_row_ptr->char_vector); + spread_row_ptr->d_vector = + (LDBLE *) free_check_null(spread_row_ptr->d_vector); + spread_row_ptr->type_vector = + (int *) free_check_null(spread_row_ptr->type_vector); + spread_row_ptr = (struct spread_row *) free_check_null(spread_row_ptr); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_token_tab(char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first tab is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * EOL, + * UNKNOWN. + */ + int i, j, return_value; + char c; +/* + * Strip leading spaces + */ + while ((c = **ptr) == ' ') + (*ptr)++; +/* + * Check what we have + */ + if (isupper((int) c)) + { + return_value = UPPER; + } + else if (islower((int) c)) + { + return_value = LOWER; + } + else if (isdigit((int) c) || c == '.' || c == '-') + { + return_value = DIGIT; + } + else if (c == '\0') + { + return_value = EOL; + return (return_value); + } + else if (c == '\t') + { + return_value = EMPTY; + } + else + { + return_value = UNKNOWN; + } +/* + * Begin copying to token + */ + i = 0; + for (;;) + { + c = **ptr; + if (c == '\t') + { + (*ptr)++; + break; + } + else if (c == '\0') + { + break; + } + else + { + token_ptr[i] = c; + (*ptr)++; + i++; + } + } + token_ptr[i] = '\0'; + *length = i; +/* + * Strip trailing spaces + */ + for (j = i - 1; j >= 0; j--) + { + if (j != ' ') + break; + } + if (j != i - 1) + { + token_ptr[j + 1] = '\0'; + *length = j + 1; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +get_option_string(const char **opt_list, int count_opt_list, char **next_char) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line and check for options + */ + int j; + int opt_l, opt; + char *opt_ptr; + char option[MAX_LENGTH]; + + opt_ptr = *next_char; + if (opt_ptr[0] == '-') + { + opt_ptr++; + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[1]), &opt, opt_list, count_opt_list, FALSE) + == OK) + { + j = opt; + *next_char = opt_ptr; + } + else + { + error_msg("Unknown option.", CONTINUE); + error_msg(*next_char, CONTINUE); + input_error++; + j = OPTION_ERROR; + } + } + else + { + copy_token(option, &opt_ptr, &opt_l); + if (find_option(&(option[0]), &opt, opt_list, count_opt_list, TRUE) + == OK) + { + j = opt; + *next_char = opt_ptr; + } + else + { + j = OPTION_DEFAULT; + } + } + return (j); +} + +#ifdef PHREEQCI_GUI +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +free_spread(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + spread_row_free(g_spread_sheet.heading); + spread_row_free(g_spread_sheet.units); + for (i = 0; i < g_spread_sheet.count_rows; i++) + { + spread_row_free(g_spread_sheet.rows[i]); + } + g_spread_sheet.rows = free_check_null(g_spread_sheet.rows); + + for (i = 0; i < g_spread_sheet.defaults.count_iso; i++) + { + g_spread_sheet.defaults.iso[i].name = + free_check_null(g_spread_sheet.defaults.iso[i].name); + } + g_spread_sheet.defaults.iso = + free_check_null(g_spread_sheet.defaults.iso); + + g_spread_sheet.defaults.redox = + free_check_null(g_spread_sheet.defaults.redox); + g_spread_sheet.defaults.units = + free_check_null(g_spread_sheet.defaults.units); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +add_row(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + g_spread_sheet.rows = + (struct spread_row **) PHRQ_realloc(g_spread_sheet.rows, + sizeof(struct spread_row *) * + (g_spread_sheet.count_rows + 1)); + if (g_spread_sheet.rows == NULL) + { + malloc_error(); + } + else + { + g_spread_sheet.rows[g_spread_sheet.count_rows++] = + copy_row(spread_row_ptr); + } +} + +/* ---------------------------------------------------------------------- */ +struct spread_row * Phreeqc:: +copy_row(struct spread_row *spread_row_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct spread_row *new_spread_row_ptr; +/* + * Allocate space + */ + new_spread_row_ptr = + (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); + if (new_spread_row_ptr == NULL) + malloc_error(); + new_spread_row_ptr->char_vector = + (char **) PHRQ_malloc((size_t) spread_row_ptr->count * + sizeof(char *)); + if (new_spread_row_ptr->char_vector == NULL) + malloc_error(); + new_spread_row_ptr->d_vector = + (LDBLE *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(LDBLE)); + if (new_spread_row_ptr->d_vector == NULL) + malloc_error(); + new_spread_row_ptr->type_vector = + (int *) PHRQ_malloc((size_t) spread_row_ptr->count * sizeof(int)); + if (new_spread_row_ptr->type_vector == NULL) + malloc_error(); + + for (i = 0; i < spread_row_ptr->count; i++) + { + new_spread_row_ptr->char_vector[i] = + string_duplicate(spread_row_ptr->char_vector[i]); + new_spread_row_ptr->d_vector[i] = spread_row_ptr->d_vector[i]; + new_spread_row_ptr->type_vector[i] = spread_row_ptr->type_vector[i]; + } + new_spread_row_ptr->count = spread_row_ptr->count; + new_spread_row_ptr->empty = spread_row_ptr->empty; + new_spread_row_ptr->number = spread_row_ptr->number; + new_spread_row_ptr->string = spread_row_ptr->string; + + return new_spread_row_ptr; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + dest_ptr->count_iso = src_ptr->count_iso; + dest_ptr->density = src_ptr->density; + dest_ptr->iso = + (struct iso *) PHRQ_malloc(sizeof(struct iso) * src_ptr->count_iso); + if (dest_ptr->iso == NULL) + { + malloc_error(); + } + else + { + for (i = 0; i < src_ptr->count_iso; i++) + { + dest_ptr->iso[i] = src_ptr->iso[i]; + dest_ptr->iso[i].name = string_duplicate(src_ptr->iso[i].name); + } + } + + dest_ptr->pe = src_ptr->pe; + dest_ptr->ph = src_ptr->ph; + dest_ptr->redox = string_duplicate(src_ptr->redox); + dest_ptr->temp = src_ptr->temp; + dest_ptr->units = string_duplicate(src_ptr->units); + dest_ptr->water = src_ptr->water; +} + +#endif diff --git a/rename_cpp/step.cpp b/rename_cpp/step.cpp new file mode 100644 index 00000000..73353f7e --- /dev/null +++ b/rename_cpp/step.cpp @@ -0,0 +1,1747 @@ +#include "Phreeqc.h" +#include "phqalloc.h" + +#include "Utils.h" +#include "StorageBin.h" +#include "Solution.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "SS.h" +#include "NameDouble.h" +#include "Temperature.h" +#include "cxxMix.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +step(LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * zero global solution, add solution or mixture, add exchange, + * add surface, add gas phase, add solid solutions, + * set temperature, and add reaction. + * Ensure all elements + * included in any of these are present in small amounts. + * Save result as n_user -1. + */ + LDBLE difftemp; + int step_number; + cxxPPassemblage *pp_assemblage_save = NULL; + struct ss_assemblage *ss_assemblage_save = NULL; +/* + * Zero out global solution data + */ + + xsolution_zero(); +/* + * Set reaction to zero + */ + step_x = 0.0; + step_number = reaction_step; +/* + * Mixing or solution + */ + if (use.Get_mix_ptr() != NULL) + { + add_mix((cxxMix *) use.Get_mix_ptr()); + } + else if (use.Get_solution_ptr() != NULL) + { + add_solution(use.Get_solution_ptr(), 1.0, 1.0); + } + else + { + input_error++; + error_msg("Neither mixing nor an initial solution have " + "been defined in reaction step.", STOP); + } +/* + * Reaction + */ + if (use.Get_reaction_ptr() != NULL) + { + //add_reaction(use.irrev_ptr, step_number, step_fraction); + add_reaction( (cxxReaction *)use.Get_reaction_ptr(), step_number, step_fraction); + } +/* + * Kinetics + */ + if (use.Get_kinetics_ptr() != NULL) + { + add_kinetics(use.Get_kinetics_ptr()); + } +/* + * Exchange + */ + if (use.Get_exchange_ptr() != NULL) + { + add_exchange((cxxExchange *) use.Get_exchange_ptr()); + } +/* + * Surface + */ + if (use.Get_surface_ptr() != NULL) + { + add_surface(use.Get_surface_ptr()); + } +/* + * Gases + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + add_gas_phase(gas_phase_ptr); + } +/* + * Temperature + */ + if (use.Get_temperature_ptr() != NULL) + { + cxxTemperature *t_ptr = (cxxTemperature *) use.Get_temperature_ptr(); + tc_x = t_ptr->Temperature_for_step(step_number); + } + if ((state == TRANSPORT) && (transport_step != 0) && + (cell > 0) && (cell != count_cells + 1)) + { + difftemp = tc_x - cell_data[cell - 1].temp; + cell_data[cell - 1].temp += difftemp / tempr; + tc_x = cell_data[cell - 1].temp; + } +/* + * Pressure + */ + if (use.Get_pressure_ptr() != NULL) + { + cxxPressure *p_ptr = (cxxPressure *) use.Get_pressure_ptr(); + patm_x = p_ptr->Pressure_for_step(step_number); + } +/* + * Pure phases and solid solutions are added to avoid + * zero or negative concentrations + */ +/* + * Pure phases + */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + add_pp_assemblage(pp_assemblage_ptr); + } +#ifdef SKIP + if (use.Get_pp_assemblage_ptr() != NULL) + { + pp_assemblage_save = + (struct pp_assemblage *) + PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_save == NULL) + malloc_error(); + pp_assemblage_copy(use.Get_pp_assemblage_ptr(), pp_assemblage_save, + use.Get_pp_assemblage_ptr()->n_user); + add_pp_assemblage(use.Get_pp_assemblage_ptr()); + } +#endif +/* + * Solid solutions + */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_save = + (struct ss_assemblage *) + PHRQ_malloc(sizeof(struct ss_assemblage)); + if (ss_assemblage_save == NULL) + malloc_error(); + ss_assemblage_copy(use.Get_ss_assemblage_ptr(), ss_assemblage_save, + use.Get_ss_assemblage_ptr()->n_user); + add_ss_assemblage(use.Get_ss_assemblage_ptr()); + } +/* + * Check that elements are available for gas components, + * pure phases, and solid solutions + */ + if (use.Get_gas_phase_ptr() != NULL) + { + cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + gas_phase_check(gas_phase_ptr); + } + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + pp_assemblage_check(pp_assemblage_ptr); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_check(use.Get_ss_assemblage_ptr()); + } +/* + * Check that element moles are >= zero + */ + if (solution_check() == MASS_BALANCE) + { + /* reset moles and deltas */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_free(use.Get_ss_assemblage_ptr()); + ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), + use.Get_ss_assemblage_ptr()->n_user); + ss_assemblage_free(ss_assemblage_save); + ss_assemblage_save = + (struct ss_assemblage *) + free_check_null(ss_assemblage_save); + } + return (MASS_BALANCE); + } +/* + * Copy global into solution n_user = -1 + */ + xsolution_save(-1); + step_save_surf(-1); + step_save_exch(-1); +/* + * Clean up temporary space + */ + if (pp_assemblage_save != NULL) + { + //pp_assemblage_free(pp_assemblage_save); + //pp_assemblage_save = + // (struct pp_assemblage *) free_check_null(pp_assemblage_save); + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + ss_assemblage_free(ss_assemblage_save); + ss_assemblage_save = + (struct ss_assemblage *) free_check_null(ss_assemblage_save); + } + + // + // Solution -1 has sum of solution/mix, exchange, surface, gas_phase + // reaction, kinetics + // + // Determine system totals, calculate maximum mineral precipitation + if (use.Get_pp_assemblage_in() || use.Get_ss_assemblage_in()) + { + cxxStorageBin sys_bin(phrq_io); + //cxxSolution soln(PHREEQC_THIS_COMMA -1, phrq_io); + int n; + struct solution *sol = solution_bsearch(-1, &n, false); + cxxSolution soln(sol, phrq_io); + sys_bin.Set_Solution(-1, soln); + if (use.Get_pp_assemblage_in()) + { + //cxxPPassemblage pp(use.Get_pp_assemblage_ptr(), phrq_io); + cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + sys_bin.Set_PPassemblage(-1, *pp_assemblage_ptr); + } + if (use.Get_ss_assemblage_in()) + { + cxxSSassemblage ss(use.Get_ss_assemblage_ptr()); + sys_bin.Set_SSassemblage(-1, ss); + } + sys_bin.Set_System(-1); + sys_bin.Get_System().totalize(PHREEQC_THIS); + cxxNameDouble sys_tots = sys_bin.Get_System().Get_Totals(); + if (use.Get_pp_assemblage_in()) + { + cxxPPassemblage *pp_assemblage_ptr = sys_bin.Get_PPassemblage(-1); + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + int n; + struct phase *p_ptr = phase_bsearch((it->first).c_str(), &n, FALSE); + struct elt_list *e_ptr; + LDBLE min = 1e10; + for (e_ptr = p_ptr->next_elt; e_ptr->elt != NULL; e_ptr++) + { + std::string e(e_ptr->elt->primary->elt->name); + cxxNameDouble::iterator st = sys_tots.find(e.c_str()); + if (st != sys_tots.end()) + { + LDBLE m1 = st->second / e_ptr->coef; + if (m1 < min) min = m1; + } + } + p_ptr->delta_max = min; + } + } + if (use.Get_ss_assemblage_in()) + { + cxxSSassemblage *ss = sys_bin.Get_SSassemblage(-1); + std::map ::const_iterator it; + for (it = ss->Get_ssAssemblageSSs().begin(); it != ss->Get_ssAssemblageSSs().end(); it++) + { + cxxNameDouble::const_iterator comp_it; + for (comp_it = (it->second).Get_comps().begin(); comp_it != (it->second).Get_comps().end(); comp_it++) + { + int n; + struct phase *p_ptr = phase_bsearch((comp_it->first).c_str(), &n, FALSE); + struct elt_list *e_ptr; + LDBLE min = 1e10; + for (e_ptr = p_ptr->next_elt; e_ptr->elt != NULL; e_ptr++) + { + std::string e(e_ptr->elt->primary->elt->name); + cxxNameDouble::iterator st = sys_tots.find(e.c_str()); + if (st != sys_tots.end()) + { + LDBLE m1 = st->second / e_ptr->coef; + if (m1 < min) + { + min = m1; + } + } + } + p_ptr->delta_max = min; + } + } + } + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xsolution_zero(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Zero out _x variables, master->totals, and species->la + */ + int i; +/* + * Zero totals in master structures + */ + new_x = FALSE; + + tc_x = 0.0; + patm_x = 0; + ph_x = 0.0; + solution_pe_x = 0.0; + mu_x = 0.0; + ah2o_x = 0.0; + density_x = 0.0; + total_h_x = 0.0; + total_o_x = 0.0; + cb_x = 0.0; + mass_water_aq_x = 0.0; + units_x = moles_per_kilogram_string; + + for (i = 0; i < count_master; i++) + { + master[i]->total = 0.0; + master[i]->total_primary = 0.0; + master[i]->s->la = 0.0; + } + if (pitzer_model == TRUE || sit_model == TRUE) + { + for (i = 0; i < count_s; i++) + { + s[i]->lg = 0.0; + } + } +/* + * Copy pe data (not sure this will be used + */ +/* + pe_data_free (pe_x); + pe_x = pe_data_alloc(); + */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate solution data in master->totals and _x variables. + * + * extensive is multiplication factor for solution + * intensive is fraction of all multiplication factors for all solutions + */ + int i; + struct master *master_ptr; + struct species *species_ptr; +/* + * Add solution to global variables + */ + tc_x += solution_ptr->tc * intensive; + ph_x += solution_ptr->ph * intensive; + patm_x += solution_ptr->patm * intensive; + // + //k_temp(tc_x, patm_x); + solution_pe_x += solution_ptr->solution_pe * intensive; + mu_x += solution_ptr->mu * intensive; + ah2o_x += solution_ptr->ah2o * intensive; + density_x += solution_ptr->density * intensive; + + total_h_x += solution_ptr->total_h * extensive; + total_o_x += solution_ptr->total_o * extensive; + cb_x += solution_ptr->cb * extensive; + mass_water_aq_x += solution_ptr->mass_water * extensive; +/* + * Copy totals data into primary master species + */ + for (i = 0; solution_ptr->totals[i].description != NULL; i++) + { + master_ptr = + master_bsearch_primary(solution_ptr->totals[i].description); + master_ptr->total += solution_ptr->totals[i].moles * extensive; + } +/* + * Accumulate initial guesses for activities + */ + /*for (i=0; solution_ptr->master_activity[i].description != NULL; i++) { */ + for (i = 0; i < solution_ptr->count_master_activity; i++) + { + if (solution_ptr->master_activity[i].description != NULL) + { + master_ptr = + master_bsearch(solution_ptr->master_activity[i].description); + if (master_ptr != NULL) + { + master_ptr->s->la += + solution_ptr->master_activity[i].la * intensive; + } + } + } +/* + * Accumulate initial guesses for log gamma + */ + if (pitzer_model == TRUE || sit_model == TRUE) + { + for (i = 0; i < solution_ptr->count_species_gamma; i++) + { + species_ptr = + s_search(solution_ptr->species_gamma[i].description); + if (species_ptr != NULL) + { + species_ptr->lg += + solution_ptr->species_gamma[i].la * intensive; + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_exchange(cxxExchange *exchange_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate exchange data in master->totals and _x variables. + */ + struct master *master_ptr; + + if (exchange_ptr == NULL) + return (OK); +/* + * Add element concentrations on exchanger to master species totals + */ + std::vector comps = exchange_ptr->Vectorize(); + for (size_t i = 0; i < comps.size(); i++) + { + cxxExchComp *comp_ptr = comps[i]; + cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + //for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) + for ( ; it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + assert(elt_ptr != NULL && elt_ptr->primary != NULL); + master_ptr = elt_ptr->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += coef; + } + else + { + master_ptr->total += coef; + } + } + } + if (exchange_ptr->Get_new_def()) + { + for (int i = 0; i < count_master; i++) + { + if (master[i]->type == EX && master[i]->total > 0) + { + master[i]->s->la = log10(0.1 * master[i]->total); + } + } + } + else + { + for (size_t i = 0; i < comps.size(); i++) + { + cxxExchComp *comp_ptr = comps[i]; + cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + //for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) + for ( ; it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + assert(elt_ptr->master); + if (elt_ptr->master->type == EX) + { + elt_ptr->master->s->la = comps[i]->Get_la(); + } + } + + //exchange_ptr->comps[i].master->s->la = exchange_ptr->comps[i].la; + cb_x += comps[i]->Get_charge_balance(); + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_surface(struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate surface data in master->totals and _x variables. + */ + int i, j; + struct master *master_ptr; + + if (surface_ptr == NULL) + return (OK); +/* + * Add element concentrations on surface to master species totals + */ + dl_type_x = surface_ptr->dl_type; + for (i = 0; i < surface_ptr->count_comps; i++) + { + /*if(surface_ptr->edl == FALSE) { */ + if (surface_ptr->type == NO_EDL) + { + cb_x += surface_ptr->comps[i].cb; + } +#ifdef SKIP_MUSIC + if (surface_ptr->type == CD_MUSIC) + { + cb_x += surface_ptr->comps[i].cb; + } +#endif + if (surface_ptr->new_def == FALSE) + { + surface_ptr->comps[i].master->s->la = surface_ptr->comps[i].la; + } +/* + * Add surface and specifically sorbed elements + */ + for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) + { + master_ptr = surface_ptr->comps[i].totals[j].elt->primary; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Element not defined in database, %s.", + surface_ptr->comps[i].totals[j].elt->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) + { + total_h_x += surface_ptr->comps[i].totals[j].coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += surface_ptr->comps[i].totals[j].coef; + } + else + { + master_ptr->total += surface_ptr->comps[i].totals[j].coef; + } + } + } + /*if (surface_ptr->edl == FALSE) return(OK); */ + if (surface_ptr->type != DDL && surface_ptr->type != CD_MUSIC) + return (OK); + for (i = 0; i < surface_ptr->count_charge; i++) + { + /*if (surface_ptr->edl == TRUE) { */ + /*cb_x += surface_ptr->charge[i].charge_balance; */ + if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + { + cb_x += surface_ptr->charge[i].charge_balance; + } + if (surface_ptr->new_def == FALSE) + { + master_ptr = + surface_get_psi_master(surface_ptr->charge[i].name, SURF_PSI); + master_ptr->s->la = surface_ptr->charge[i].la_psi; + /*surface_ptr->charge[i].psi_master->s->la = surface_ptr->charge[i].la_psi; */ + } +/* + * Add diffuse layer elements (including water in Debye layer) + */ + if (surface_ptr->dl_type != NO_DL && surface_ptr->new_def == FALSE) + { + for (j = 0; + surface_ptr->charge[i].diffuse_layer_totals[j].elt != NULL; + j++) + { + master_ptr = + surface_ptr->charge[i].diffuse_layer_totals[j].elt-> + primary; + if (master_ptr->s == s_hplus) + { + total_h_x += + surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += + surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } + else + { + master_ptr->total += + surface_ptr->charge[i].diffuse_layer_totals[j].coef; + } + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_mix(cxxMix *mix_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * calls add_solution to accumulate all data in master->totals + * and other variables. + */ + int n; + LDBLE sum_fractions, intensive, extensive; + struct solution *solution_ptr; + int count_positive; + LDBLE sum_positive; + + if (mix_ptr == NULL) + return (OK); + if (mix_ptr->Get_mixComps().size() == 0) + return (OK); + sum_fractions = 0.0; + sum_positive = 0.0; + count_positive = 0; + std::map::const_iterator it; + for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) + { + sum_fractions += it->second; + if (it->second > 0) + { + sum_positive += it->second; + count_positive++; + } + } + for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) + { + solution_ptr = solution_bsearch(it->first, &n, TRUE); + if (solution_ptr == NULL) + { + input_error++; + continue; + } + extensive = it->second; + intensive = extensive / sum_fractions; + if (count_positive < (int) mix_ptr->Get_mixComps().size()) + { + if (it->second > 0) + { + intensive = extensive / sum_positive; + } + else + { + intensive = 0; + } + } + add_solution(solution_ptr, extensive, intensive); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add a small amount of each phase if necessary to insure + * all elements exist in solution. + */ + int i; + LDBLE amount_to_add, total; + char token[MAX_LENGTH]; + char *ptr; + //struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + //struct phase *phase_ptr; + //LDBLE p, t; + + //pure_phase_ptr = pp_assemblage_ptr->pure_phases; + + // Should be be done when it gets to prep (modified quick_setup in case same_model). + //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + //{ + // phase_ptr = pure_phase_ptr[j].phase; + // if (/*pure_phase_ptr[j].si_org > 0 && */phase_ptr->p_c > 0 && phase_ptr->t_c > 0) + // { + // p = exp(pure_phase_ptr[j].si_org * LOG_10); + // t = tc_x + 273.15; + // if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) + // { + // calc_PR(&phase_ptr, 1, p, t, 0); + // } + // pure_phase_ptr[j].si = pure_phase_ptr[j].si_org + phase_ptr->pr_si_f; + // } + //} + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) + return (OK); +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + cxxPPassemblageComp * comp_ptr = &(it->second); + if (comp_ptr->Get_precipitate_only()) continue; + int l; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + count_elts = 0; + paren_count = 0; + amount_to_add = 0.0; + comp_ptr->Set_delta(0.0); + if (comp_ptr->Get_add_formula().size() > 0) + { + strcpy(token, comp_ptr->Get_add_formula().c_str()); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, phase_ptr->formula); + add_elt_list(phase_ptr->next_elt, 1.0); + } + if (comp_ptr->Get_moles() > 0.0) + { + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL) + { + continue; + } + else + { + total = (-master_ptr->total + 1e-10) / elt_list[i].coef; + if (amount_to_add < total) + { + amount_to_add = total; + } + } + } + if (comp_ptr->Get_moles() < amount_to_add) + { + amount_to_add =comp_ptr->Get_moles(); + } + } + if (amount_to_add > 0.0) + { + comp_ptr->Set_moles(comp_ptr->Get_moles() - amount_to_add); + comp_ptr->Set_delta(amount_to_add); +/* + * Add reaction to totals + */ + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += elt_list[i].coef * amount_to_add; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += elt_list[i].coef * amount_to_add; + } + else + { + master_ptr->total += elt_list[i].coef * amount_to_add; + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add a small amount of each phase if necessary to insure + * all elements exist in solution. + */ + int i, j; + LDBLE amount_to_add, total; + char token[MAX_LENGTH]; + char *ptr; + struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + //struct phase *phase_ptr; + //LDBLE p, t; + + pure_phase_ptr = pp_assemblage_ptr->pure_phases; + + // Should be be done when it gets to prep (modified quick_setup in case same_model). + //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + //{ + // phase_ptr = pure_phase_ptr[j].phase; + // if (/*pure_phase_ptr[j].si_org > 0 && */phase_ptr->p_c > 0 && phase_ptr->t_c > 0) + // { + // p = exp(pure_phase_ptr[j].si_org * LOG_10); + // t = tc_x + 273.15; + // if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) + // { + // calc_PR(&phase_ptr, 1, p, t, 0); + // } + // pure_phase_ptr[j].si = pure_phase_ptr[j].si_org + phase_ptr->pr_si_f; + // } + //} + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) + return (OK); +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + pure_phase_ptr = pp_assemblage_ptr->pure_phases; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + { + if (pure_phase_ptr[j].precipitate_only) continue; + count_elts = 0; + paren_count = 0; + amount_to_add = 0.0; + pure_phase_ptr[j].delta = 0.0; + if (pure_phase_ptr[j].add_formula != NULL) + { + strcpy(token, pure_phase_ptr[j].add_formula); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, pure_phase_ptr[j].phase->formula); + add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); + } + if (pure_phase_ptr[j].moles > 0.0) + { + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL) + { + continue; + } + else + { + total = (-master_ptr->total + 1e-10) / elt_list[i].coef; + if (amount_to_add < total) + { + amount_to_add = total; + } + } + } + if (pure_phase_ptr[j].moles < amount_to_add) + { + amount_to_add = pure_phase_ptr[j].moles; + } + } + if (amount_to_add > 0.0) + { + pure_phase_ptr[j].moles -= amount_to_add; + pure_phase_ptr[j].delta = amount_to_add; +/* + * Add reaction to totals + */ + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += elt_list[i].coef * amount_to_add; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += elt_list[i].coef * amount_to_add; + } + else + { + master_ptr->total += elt_list[i].coef * amount_to_add; + } + } + } + } + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check list of all elements in pure_phase assemblage to see + * if all are in model. Return true if all are present, + * Return false if one or more is missing. + */ + struct master *master_ptr; + + cxxNameDouble nd = pp_assemblage_ptr->Get_eltList(); + cxxNameDouble::iterator it; + for (it = nd.begin(); it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + if (elt_ptr == NULL || elt_ptr->primary == NULL) + { + return FALSE; + } + + master_ptr = elt_ptr->primary; + if (master_ptr->s == s_h2o || master_ptr->s == s_hplus) + continue; + if (master_ptr->total > MIN_TOTAL) + continue; + return (FALSE); + } + return (TRUE); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check list of all elements in pure_phase assemblage to see + * if all are in model. Return true if all are present, + * Return false if one or more is missing. + */ + int j; + struct master *master_ptr; + for (j = 0; pp_assemblage_ptr->next_elt[j].elt != NULL; j++) + { + master_ptr = pp_assemblage_ptr->next_elt[j].elt->primary; + if (master_ptr->s == s_h2o || master_ptr->s == s_hplus) + continue; + if (master_ptr->total > MIN_TOTAL) + continue; + return (FALSE); + } + return (TRUE); +} +#endif + /* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add irreversible reaction + */ + char c; + struct master *master_ptr; +/* + * Calculate and save reaction + */ +/* !!!!! with kinetics reaction, coeff's may change + * and reaction_calc must be called .... + */ + if (reaction_ptr == NULL) + return OK; + + reaction_calc(reaction_ptr); + +/* + * Step size + */ + if (incremental_reactions == FALSE) + { + //if (irrev_ptr->count_steps > 0) + if (!reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0 ) + { + if (step_number > (int) reaction_ptr->Get_steps().size()) + { + step_x = reaction_ptr->Get_steps()[reaction_ptr->Get_steps().size() - 1]; + } + else + { + step_x = reaction_ptr->Get_steps()[step_number - 1]; + } + } + else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) + { + if (step_number > (int) reaction_ptr->Get_actualSteps()) + { + step_x = reaction_ptr->Get_steps()[0]; + } + else + { + step_x = reaction_ptr->Get_steps()[0] * + ((LDBLE) step_number) / + ((LDBLE) (reaction_ptr->Get_actualSteps())); + } + } + else + { + step_x = 0.0; + } + } + else + { + /* Incremental reactions */ + if (!reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) + { + if (step_number > (int) reaction_ptr->Get_actualSteps()) + { + step_x = reaction_ptr->Get_steps()[reaction_ptr->Get_actualSteps() - 1]; + } + else + { + step_x = reaction_ptr->Get_steps()[step_number - 1]; + } + } + else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) + { + if (step_number > (int) reaction_ptr->Get_actualSteps()) + { + step_x = 0; + } + else + { + step_x = reaction_ptr->Get_steps()[0] / ((LDBLE) (reaction_ptr->Get_actualSteps())); + } + } + else + { + step_x = 0.0; + } + } +/* + * Convert units + */ + //c = irrev_ptr->units[0]; + c = reaction_ptr->Get_units().c_str()[0]; + if (c == 'm') + { + step_x *= 1e-3; + } + else if (c == 'u') + { + step_x *= 1e-6; + } + else if (c == 'n') + { + step_x *= 1e-9; + } +/* + * Add reaction to totals + */ + //for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) + cxxNameDouble::const_iterator it = reaction_ptr->Get_elementList().begin(); + for ( ; it != reaction_ptr->Get_elementList().end(); it++) + { + struct element * elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + if (elt_ptr == NULL) + { + assert (false); + } + master_ptr = elt_ptr->primary; + if (master_ptr == NULL) + { + assert (false); + } + if (master_ptr->s == s_hplus) + { + total_h_x += coef * step_x * step_fraction; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += coef * step_x * step_fraction; + } + else + { + master_ptr->total += coef * step_x * step_fraction; + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reaction_calc(cxxReaction *reaction_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through irreversible reaction initially to + * determine a list of elements and amounts in + * the reaction. + */ + //int i, j, + int return_value; + LDBLE coef; + //char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + return_value = OK; + count_elts = 0; + paren_count = 0; + + cxxNameDouble nd(reaction_ptr->Get_reactantList()); + cxxNameDouble::iterator it; + for (it = nd.begin(); it != nd.end(); it++) + { + coef = it->second; + int j; + phase_ptr = phase_bsearch(it->first.c_str(), &j, FALSE); +/* + * Reactant is a pure phase, copy formula into token + */ + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, coef); + } + else + { + //ptr = &(token[0]); + char * token = string_duplicate(it->first.c_str()); + ptr = token; + get_elts_in_species(&ptr, coef); + free_check_null(token); + } + } +/* + * Check that all elements are in database + */ + for (int i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->master == NULL) + { + error_string = sformatf( + "Element or phase not defined in database, %s.", + elt_list[i].elt->name); + error_msg(error_string, CONTINUE); + input_error++; + return_value = ERROR; + } + } + //irrev_ptr->elts = elt_list_save(); + reaction_ptr->Set_elementList(elt_list_NameDouble()); + + return (return_value); +} + /* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_gas_phase(cxxGasPhase *gas_phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate gas data in master->totals and _x variables. + */ + int i; + + //struct gas_comp *gas_comp_ptr; + struct master *master_ptr; + + if (gas_phase_ptr == NULL) + return (OK); + //gas_comp_ptr = gas_phase_ptr->comps; +/* + * calculate reaction + */ + count_elts = 0; + paren_count = 0; + //for (i = 0; i < gas_phase_ptr->count_comps; i++) + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + assert(phase_ptr); + + add_elt_list(phase_ptr->next_elt, gc_ptr->Get_moles()); + } +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Add gas elements to totals + */ + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += elt_list[i].coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += elt_list[i].coef; + } + else + { + master_ptr->total += elt_list[i].coef; + } + } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE && fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) + { + same_pressure = FALSE; + patm_x = gas_phase_ptr->Get_total_p(); + k_temp(tc_x, patm_x); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_ss_assemblage(struct ss_assemblage *ss_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate solid_solution data in master->totals and _x variables. + */ + int i, j, k; + LDBLE amount_to_add, total; + struct s_s *s_s_ptr; + struct master *master_ptr; + char token[MAX_LENGTH]; + char *ptr; + + if (ss_assemblage_ptr == NULL) + return (OK); + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) + { + count_elts = 0; + paren_count = 0; + s_s_ptr = &(ss_assemblage_ptr->s_s[i]); + for (j = 0; j < s_s_ptr->count_comps; j++) + { + amount_to_add = 0.0; + s_s_ptr->comps[j].delta = 0.0; + if (s_s_ptr->comps[j].moles > 0.0) + { + strcpy(token, s_s_ptr->comps[j].phase->formula); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + for (k = 0; k < count_elts; k++) + { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL_SS) + { + continue; + } + else + { + total = + (-master_ptr->total + 1e-10) / elt_list[k].coef; + if (amount_to_add < total) + { + amount_to_add = total; + } + } + } + } + if (s_s_ptr->comps[j].moles < amount_to_add) + { + amount_to_add = s_s_ptr->comps[j].moles; + } + if (amount_to_add > 0.0) + { + s_s_ptr->comps[j].moles -= amount_to_add; + s_s_ptr->comps[j].delta = amount_to_add; +/* + * Add reaction to totals + */ + for (k = 0; k < count_elts; k++) + { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += elt_list[k].coef * amount_to_add; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += elt_list[k].coef * amount_to_add; + } + else + { + master_ptr->total += elt_list[k].coef * amount_to_add; + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_kinetics(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add kinetic reaction + */ + int i; + struct master *master_ptr; +/* + * Add reaction to totals + */ + if (kinetics_ptr->totals == NULL) + return (OK); + for (i = 0; kinetics_ptr->totals[i].elt != NULL; i++) + { + master_ptr = kinetics_ptr->totals[i].elt->primary; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Element %s in kinetic reaction not found in database.", + kinetics_ptr->totals[i].elt->name); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) + { + total_h_x += kinetics_ptr->totals[i].coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += kinetics_ptr->totals[i].coef; + } + else + { + master_ptr->total += kinetics_ptr->totals[i].coef; + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +gas_phase_check(cxxGasPhase *gas_phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + //int i, j; + + //struct gas_comp *gas_comp_ptr; + struct master *master_ptr; + + if (gas_phase_ptr == NULL) + return (OK); + //gas_comp_ptr = gas_phase_ptr->comps; +/* + * Check that all elements are in solution for phases with zero mass + */ + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + //for (i = 0; i < gas_phase_ptr->count_comps; i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); + count_elts = 0; + paren_count = 0; + if (gc_ptr->Get_moles() <= 0.0) + { + add_elt_list(phase_ptr->next_elt, 1.0); + for (int j = 0; j < count_elts; j++) + { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL) + { + continue; + } + else + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element %s is contained in gas %s (which has 0.0 mass),\nbut is not in solution or other phases.", + elt_list[j].elt->name, + phase_ptr->name); + warning_msg(error_string); + } + } + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + //int i, j, k; + //char token[MAX_LENGTH]; + std::string token; + char *ptr; + //struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) + return (OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + cxxPPassemblageComp * comp_ptr = &(it->second); + int l; + struct phase * phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + count_elts = 0; + paren_count = 0; + if (comp_ptr->Get_moles() <= 0.0) + { + comp_ptr->Set_delta(0.0); + if (comp_ptr->Get_add_formula().size() > 0) + { + token = comp_ptr->Get_add_formula(); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + token = phase_ptr->formula; + //strcpy(token, pure_phase_ptr[j].phase->formula); + add_elt_list(phase_ptr->next_elt, 1.0); + } + for (int i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL) + { + continue; + } + else + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element %s is contained in %s (which has 0.0 mass)," + "\t\nbut is not in solution or other phases.", + elt_list[i].elt->name, + phase_ptr->name); + warning_msg(error_string); + } +/* + * Make la's of all master species for the element small, so SI will be small + * and no mass transfer will be calculated + */ + for (int k = 0; k < count_master; k++) + { + if (master[k]->elt->primary == master_ptr) + { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i, j, k; + char token[MAX_LENGTH]; + char *ptr; + struct pure_phase *pure_phase_ptr; + struct master *master_ptr; + + if (check_pp_assemblage(pp_assemblage_ptr) == OK) + return (OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + pure_phase_ptr = pp_assemblage_ptr->pure_phases; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + { + count_elts = 0; + paren_count = 0; + if (pure_phase_ptr[j].moles <= 0.0) + { + pure_phase_ptr[j].delta = 0.0; + if (pure_phase_ptr[j].add_formula != NULL) + { + strcpy(token, pure_phase_ptr[j].add_formula); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, pure_phase_ptr[j].phase->formula); + add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); + } + for (i = 0; i < count_elts; i++) + { + master_ptr = elt_list[i].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL) + { + continue; + } + else + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element %s is contained in %s (which has 0.0 mass)," + "\t\nbut is not in solution or other phases.", + elt_list[i].elt->name, + pure_phase_ptr[j].phase->name); + warning_msg(error_string); + } +/* + * Make la's of all master species for the element small, so SI will be small + * and no mass transfer will be calculated + */ + for (k = 0; k < count_master; k++) + { + if (master[k]->elt->primary == master_ptr) + { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i, j, k, l; + struct master *master_ptr; + + if (ss_assemblage_ptr == NULL) + return (OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) + { + for (j = 0; j < ss_assemblage_ptr->s_s[i].count_comps; j++) + { + count_elts = 0; + paren_count = 0; + if (ss_assemblage_ptr->s_s[i].comps[j].moles <= 0.0) + { + add_elt_list(ss_assemblage_ptr->s_s[i].comps[j].phase-> + next_elt, 1.0); + for (l = 0; l < count_elts; l++) + { + master_ptr = elt_list[l].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL_SS) + { + continue; + } + else + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.", + elt_list[l].elt->name, + ss_assemblage_ptr->s_s[i].comps[j]. + phase->name); + warning_msg(error_string); + } + } + /* + * Make la's of all master species for the element small, + * so SI will be small + * and no mass transfer will be calculated + */ + for (k = 0; k < count_master; k++) + { + if (master[k]->elt->primary == master_ptr) + { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_check(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int i; + struct master *master_ptr; + +/* + * Check that all elements are in solution for phases with zero mass + */ + for (i = 0; i < count_master; i++) + { + master_ptr = master[i]; + if (master_ptr->total >= 0.0) + continue; + if (master_ptr->total > -MIN_TOTAL) + { + master_ptr->total = 0; + continue; + } + if (master_ptr->s == s_eminus || master_ptr->s == s_h2o + || master_ptr->s == s_hplus || master_ptr->s == s_h3oplus) + { + master_ptr->total = 0; + continue; + } + /* + sprintf (error_string, + "Element %s has negative moles in solution, %e. \n\tErroneous mole balance occurs as moles are added to produce zero moles.\n\tUsually caused by KINETICS, REACTION, or diffuse layer calculation.\n\tMay be due to large time steps in early part of KINETICS simulation or negative concentrations in the diffuse layer.", + master_ptr->elt->name, (LDBLE) master_ptr->total); + */ + error_string = sformatf( + "Negative moles in solution for %s, %e. Recovering...", + master_ptr->elt->name, (double) master_ptr->total); + warning_msg(error_string); + return (MASS_BALANCE); + } + return (OK); +} diff --git a/rename_cpp/structures.cpp b/rename_cpp/structures.cpp new file mode 100644 index 00000000..89786dd4 --- /dev/null +++ b/rename_cpp/structures.cpp @@ -0,0 +1,7451 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include + +#include "phqalloc.h" +#include "Temperature.h" +#include "cxxMix.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" +#include "Use.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +clean_up(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all allocated memory, except strings + */ + int i, j; +#if defined MULTICHART + chart_handler.End_timer(); +#endif + + description_x = (char *) free_check_null(description_x); + isotopes_x = (struct isotope *) free_check_null(isotopes_x); + moles_per_kilogram_string = + (char *) free_check_null(moles_per_kilogram_string); + pe_string = (char *) free_check_null(pe_string); +/* model */ + last_model.exchange = + (struct master **) free_check_null(last_model.exchange); + last_model.gas_phase = + (struct phase **) free_check_null(last_model.gas_phase); + last_model.pp_assemblage = + (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.ss_assemblage = + (const char **) free_check_null(last_model.ss_assemblage); + last_model.add_formula = + (const char **) free_check_null(last_model.add_formula); + last_model.si = (LDBLE *) free_check_null(last_model.si); + last_model.surface_comp = + (const char **) free_check_null(last_model.surface_comp); + last_model.surface_charge = + (const char **) free_check_null(last_model.surface_charge); + + /* model */ + free_model_allocs(); + +/* species */ + + for (j = 0; j < count_s; j++) + { + s_free(s[j]); + s[j] = (struct species *) free_check_null(s[j]); + } + s = (struct species **) free_check_null(s); + +/* master species */ + + for (j = 0; j < count_master; j++) + { + master_free(master[j]); + } + master = (struct master **) free_check_null(master); + +/* elements */ + + for (j = 0; j < count_elements; j++) + { + elements[j] = (struct element *) free_check_null(elements[j]); + } + elements = (struct element **) free_check_null(elements); + +/* solutions */ + + for (j = 0; j < count_solution; j++) + { + solution_free(solution[j]); + } + solution = (struct solution **) free_check_null(solution); + +/* surfaces */ + + for (j = 0; j < count_surface; j++) + { + surface_free(&surface[j]); + } + surface = (struct surface *) free_check_null(surface); + +/* exchange */ + Rxn_exchange_map.clear(); + +/* pp assemblages */ + Rxn_pp_assemblage_map.clear(); +#ifdef SKIP + for (j = 0; j < count_pp_assemblage; j++) + { + pp_assemblage_free(&pp_assemblage[j]); + } + pp_assemblage = (struct pp_assemblage *) free_check_null(pp_assemblage); +#endif + +/* s_s assemblages */ + + for (j = 0; j < count_ss_assemblage; j++) + { + ss_assemblage_free(&ss_assemblage[j]); + } + ss_assemblage = + (struct ss_assemblage *) free_check_null(ss_assemblage); + +/* irreversible reactions */ + Rxn_reaction_map.clear(); + +/* temperature */ + Rxn_temperature_map.clear(); + +/* pressure */ + Rxn_pressure_map.clear(); + +/* unknowns */ + + for (j = 0; j < max_unknowns; j++) + { + unknown_free(x[j]); + } + x = (struct unknown **) free_check_null(x); + +/* mixtures */ + Rxn_mix_map.clear(); + +/* phases */ + + for (j = 0; j < count_phases; j++) + { + phase_free(phases[j]); + phases[j] = (struct phase *) free_check_null(phases[j]); + } + phases = (struct phase **) free_check_null(phases); + +/* inverse */ + for (j = 0; j < count_inverse; j++) + { + inverse_free(&(inverse[j])); + } + inverse = (struct inverse *) free_check_null(inverse); + +/* gases */ + Rxn_gas_phase_map.clear(); + +/* kinetics */ + for (j = 0; j < count_kinetics; j++) + { + kinetics_free(&kinetics[j]); + } + kinetics = (struct kinetics *) free_check_null(kinetics); + +/* rates */ + for (j = 0; j < count_rates; j++) + { + rate_free(&rates[j]); + } + rates = (struct rate *) free_check_null(rates); + +/* logk hash table */ + for (j = 0; j < count_logk; j++) + { + free_check_null(logk[j]->add_logk); + logk[j] = (struct logk *) free_check_null(logk[j]); + } + logk = (struct logk **) free_check_null(logk); + +/* save_values */ + for (j = 0; j < count_save_values; j++) + { + save_values[j].subscripts = + (int *) free_check_null(save_values[j].subscripts); + } + save_values = (struct save_values *) free_check_null(save_values); + +/* model */ + +/* global solution */ + + pe_data_free(pe_x); + pe_x = NULL; + +/* species_list */ + + species_list = (struct species_list *) free_check_null(species_list); + +/* transport data */ + + stag_data = (struct stag_data *) free_check_null(stag_data); + cell_data = (struct cell_data *) free_check_null(cell_data); + +/* punch */ + + punch.totals = (struct name_master *) free_check_null(punch.totals); + punch.molalities = + (struct name_species *) free_check_null(punch.molalities); + punch.activities = + (struct name_species *) free_check_null(punch.activities); + punch.pure_phases = + (struct name_phase *) free_check_null(punch.pure_phases); + punch.si = (struct name_phase *) free_check_null(punch.si); + punch.gases = (struct name_phase *) free_check_null(punch.gases); + punch.s_s = (struct name_phase *) free_check_null(punch.s_s); + punch.kinetics = (struct name_phase *) free_check_null(punch.kinetics); + advection_punch = (int *) free_check_null(advection_punch); + advection_print = (int *) free_check_null(advection_print); + punch.isotopes = (struct name_master *) free_check_null(punch.isotopes); + punch.calculate_values = + (struct name_master *) free_check_null(punch.calculate_values); + +/* user_print and user_punch */ + rate_free(user_print); + rate_free(user_punch); + user_print = (struct rate *) free_check_null(user_print); + + user_punch = (struct rate *) free_check_null(user_punch); + user_punch_headings = (const char **) free_check_null(user_punch_headings); + + /* + Free llnl aqueous model parameters + */ + llnl_temp = (LDBLE *) free_check_null(llnl_temp); + llnl_adh = (LDBLE *) free_check_null(llnl_adh); + llnl_bdh = (LDBLE *) free_check_null(llnl_bdh); + llnl_bdot = (LDBLE *) free_check_null(llnl_bdot); + llnl_co2_coefs = (LDBLE *) free_check_null(llnl_co2_coefs); + /* + * Copier space + */ + copier_free(©_solution); + copier_free(©_pp_assemblage); + copier_free(©_exchange); + copier_free(©_surface); + copier_free(©_ss_assemblage); + copier_free(©_gas_phase); + copier_free(©_kinetics); + copier_free(©_mix); + copier_free(©_reaction); + copier_free(©_temperature); + copier_free(©_pressure); + +#if defined PHREEQ98 + rate_free(user_graph); + user_graph = (struct rate *) free_check_null(user_graph); + user_graph_headings = (char **) free_check_null(user_graph_headings); +#ifndef PHREEQ98 + //if (u_g) + // DeleteCurves(); +#endif +#endif + /* master_isotope */ + for (i = 0; i < count_master_isotope; i++) + { + master_isotope[i] = + (struct master_isotope *) free_check_null(master_isotope[i]); + } + master_isotope = + (struct master_isotope **) free_check_null(master_isotope); + hdestroy_multi(master_isotope_hash_table); + master_isotope_hash_table = NULL; + + /* calculate_value */ + for (i = 0; i < count_calculate_value; i++) + { + calculate_value_free(calculate_value[i]); + calculate_value[i] = + (struct calculate_value *) free_check_null(calculate_value[i]); + } + calculate_value = + (struct calculate_value **) free_check_null(calculate_value); + hdestroy_multi(calculate_value_hash_table); + calculate_value_hash_table = NULL; + + /* isotope_ratio */ + for (i = 0; i < count_isotope_ratio; i++) + { + isotope_ratio[i] = + (struct isotope_ratio *) free_check_null(isotope_ratio[i]); + } + isotope_ratio = (struct isotope_ratio **) free_check_null(isotope_ratio); + hdestroy_multi(isotope_ratio_hash_table); + isotope_ratio_hash_table = NULL; + + /* isotope_alpha */ + for (i = 0; i < count_isotope_alpha; i++) + { + isotope_alpha[i] = + (struct isotope_alpha *) free_check_null(isotope_alpha[i]); + } + isotope_alpha = (struct isotope_alpha **) free_check_null(isotope_alpha); + hdestroy_multi(isotope_alpha_hash_table); + isotope_alpha_hash_table = NULL; + + free_tally_table(); + + /* CVODE memory */ + free_cvode(); + + pitzer_clean_up(); + + sit_clean_up(); + + +/* hash tables */ + + hdestroy_multi(elements_hash_table); + hdestroy_multi(species_hash_table); + hdestroy_multi(logk_hash_table); + hdestroy_multi(phases_hash_table); + + elements_hash_table = NULL; + species_hash_table = NULL; + logk_hash_table = NULL; + phases_hash_table = NULL; + +/* strings */ + strings_map_clear(); + +/* delete basic interpreter */ + basic_free(); + change_surf = (struct Change_Surf *) free_check_null(change_surf); + +/* miscellaneous work space */ + + elt_list = (struct elt_list *) free_check_null(elt_list); + trxn.token = (struct rxn_token_temp *) free_check_null(trxn.token); + mb_unknowns = (struct unknown_list *) free_check_null(mb_unknowns); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + zeros = (LDBLE *) free_check_null(zeros); + scratch = (LDBLE *) free_check_null(scratch); + x_arg = (LDBLE *) free_check_null(x_arg); + res_arg = (LDBLE *) free_check_null(res_arg); + + normal = (LDBLE *) free_check_null(normal); + ineq_array = (LDBLE *) free_check_null(ineq_array); + back_eq = (int *) free_check_null(back_eq); + zero = (LDBLE *) free_check_null(zero); + res = (LDBLE *) free_check_null(res); + delta1 = (LDBLE *) free_check_null(delta1); + cu = (LDBLE *) free_check_null(cu); + iu = (int *) free_check_null(iu); + is = (int *) free_check_null(is); + +/* x_arg = res_arg = scratch = NULL; */ + x_arg_max = res_arg_max = scratch_max = 0; + + +/* free user database name if defined */ + user_database = (char *) free_check_null(user_database); + selected_output_file_name = + (char *) free_check_null(selected_output_file_name); + dump_file_name = (char *) free_check_null(dump_file_name); +#ifdef PHREEQCI_GUI + free_spread(); +#endif + title_x = (char *) free_check_null(title_x); + +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + MergeFinalize(); +#endif + + count_solution = 0; + //count_pp_assemblage = 0; + //count_exchange = 0; + count_surface = 0; + //count_gas_phase = 0; + count_kinetics = 0; + count_ss_assemblage = 0; + + count_elements = 0; + //count_irrev = 0; + count_master = 0; + //count_mix = 0; + count_phases = 0; + count_s = 0; + count_logk = 0; + count_master_isotope = 0; + + count_rates = 0; + count_inverse = 0; + count_save_values = 0; + + llnl_count_temp = 0; + llnl_count_adh = 0; + llnl_count_bdh = 0; + llnl_count_bdot = 0; + llnl_count_co2_coefs = 0; + + count_calculate_value = 0; + count_isotope_ratio = 0; + count_isotope_alpha = 0; + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reinitialize(void) +/* ---------------------------------------------------------------------- */ +{ + int j; +/* solutions */ + for (j = 0; j < count_solution; j++) + { + solution_free(solution[j]); + } + count_solution = 0; + +/* surfaces */ + + for (j = 0; j < count_surface; j++) + { + surface_free(&surface[j]); + } + count_surface = 0; + +/* exchange */ + Rxn_exchange_map.clear(); + +/* pp assemblages */ + Rxn_pp_assemblage_map.clear(); +#ifdef SKIP + for (j = 0; j < count_pp_assemblage; j++) + { + pp_assemblage_free(&pp_assemblage[j]); + } + count_pp_assemblage = 0; +#endif +/* s_s assemblages */ + + for (j = 0; j < count_ss_assemblage; j++) + { + ss_assemblage_free(&ss_assemblage[j]); + } + count_ss_assemblage = 0; + +/* gases */ + Rxn_gas_phase_map.clear(); + +/* kinetics */ + for (j = 0; j < count_kinetics; j++) + { + kinetics_free(&kinetics[j]); + } + count_kinetics = 0; + +/* irreversible reactions */ + Rxn_reaction_map.clear(); + + // Temperature + Rxn_temperature_map.clear(); + + // Pressure + Rxn_pressure_map.clear(); + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "element" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +element_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct element *element_ptr1, *element_ptr2; + element_ptr1 = *(const struct element **) ptr1; + element_ptr2 = *(const struct element **) ptr2; +/* return(strcmp_nocase(element_ptr1->name, element_ptr2->name)); */ + return (strcmp(element_ptr1->name, element_ptr2->name)); + +} + +/* ---------------------------------------------------------------------- */ +struct element * Phreeqc:: +element_store(const char *element) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "element" in the hash table for elements. + * + * If found, pointer to the appropriate element structure is returned. + * + * If the string is not found, a new entry is made at the end of + * the elements array (position count_elements) and count_elements is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * + * Arguments: + * element input, character string to be located or stored. + * + * Returns: + * The address of an elt structure that contains the element data. + */ + int n; + struct element *elts_ptr; + ENTRY item, *found_item; + char token[MAX_LENGTH]; +/* + * Search list + */ + strcpy(token, element); + + item.key = token; + item.data = NULL; + found_item = hsearch_multi(elements_hash_table, item, FIND); + if (found_item != NULL) + { + elts_ptr = (struct element *) (found_item->data); + return (elts_ptr); + } +/* + * Save new elt structure and return pointer to it + */ + /* make sure there is space in elements */ + elements[count_elements] = + (struct element *) PHRQ_malloc((size_t) sizeof(struct element)); + if (elements[count_elements] == NULL) + malloc_error(); + /* set name pointer in elements structure */ + elements[count_elements]->name = string_hsave(token); + /* set return value */ + elements[count_elements]->master = NULL; + elements[count_elements]->primary = NULL; + elements[count_elements]->gfw = 0.0; + n = count_elements++; + if (count_elements >= max_elements) + { + space((void **) ((void *) &elements), count_elements, &max_elements, + sizeof(struct element *)); + } +/* + * Update hash table + */ + item.key = elements[n]->name; + item.data = (void *) elements[n]; + found_item = hsearch_multi(elements_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in element_store."); + error_msg(error_string, CONTINUE); + } + return (elements[n]); +} + +/* ********************************************************************** + * + * Routines related to structure "elt_list" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +elt_list_combine(void) +/* ---------------------------------------------------------------------- */ +/* + * Function goes through the list of elements pointed to by elt_list + * and combines the coefficients of elements that are the same. + * Assumes elt_list has been sorted by element name. + */ +{ + int i, j; + + if (count_elts < 1) + { + output_msg("elt_list_combine: How did this happen?\n"); + return (ERROR); + } + if (count_elts == 1) + { + return (OK); + } + j = 0; + for (i = 1; i < count_elts; i++) + { + if (elt_list[i].elt == elt_list[j].elt) + { + elt_list[j].coef += elt_list[i].coef; + } + else + { + j++; + if (i != j) + { + elt_list[j].elt = elt_list[i].elt; + elt_list[j].coef = elt_list[i].coef; + } + } + } + count_elts = j + 1; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +elt_list_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct elt_list *a, *b; + + a = (const struct elt_list *) ptr1; + b = (const struct elt_list *) ptr2; + return (strncmp(a->elt->name, b->elt->name, MAX_LENGTH)); +} + +/* ---------------------------------------------------------------------- */ +struct elt_list * Phreeqc:: +elt_list_dup(struct elt_list *elt_list_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates the elt_list structure pointed to by elt_list_ptr_old. + */ + int i, count_totals; + struct elt_list *elt_list_ptr_new; +/* + * Count totals data and copy + */ + if (elt_list_ptr_old == NULL) + return (NULL); + for (i = 0; elt_list_ptr_old[i].elt != NULL; i++); + count_totals = i; +/* + * Malloc space and store element data + */ + elt_list_ptr_new = + (struct elt_list *) PHRQ_malloc((size_t) (count_totals + 1) * + sizeof(struct elt_list)); + if (elt_list_ptr_new == NULL) + malloc_error(); + memcpy(elt_list_ptr_new, elt_list_ptr_old, + (size_t) (count_totals + 1) * sizeof(struct elt_list)); + return (elt_list_ptr_new); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +elt_list_print(struct elt_list *elt_list_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates the elt_list structure pointed to by elt_list_ptr_old. + */ + int i; +/* + * Debug print for element list + */ + if (elt_list_ptr == NULL) + return (ERROR); + output_msg(sformatf( "Elt_list\n")); + for (i = 0; elt_list_ptr[i].elt != NULL; i++) + { + output_msg(sformatf( "\t%s\t%e\n", elt_list_ptr[i].elt->name, + (double) elt_list_ptr[i].coef)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +cxxNameDouble Phreeqc:: +elt_list_NameDouble(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes data from work space elt_list, makes NameDouble + */ + cxxNameDouble nd; + for(int i = 0; i < count_elts; i++) + { + nd.add(elt_list[i].elt->name, elt_list[i].coef); + } + return (nd); +} +/* ---------------------------------------------------------------------- */ +struct elt_list * Phreeqc:: +elt_list_save(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes data from work space elt_list, allocates a new elt_list structure, + * copies data from work space to new structure, and returns pointer to + * new structure. + */ + int j; + struct elt_list *elt_list_ptr; +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Malloc space and store element data + */ + elt_list_ptr = + (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * + sizeof(struct elt_list)); + if (elt_list_ptr == NULL) + malloc_error(); + for (j = 0; j < count_elts; j++) + { + elt_list_ptr[j].elt = elt_list[j].elt; + elt_list_ptr[j].coef = elt_list[j].coef; + } + elt_list_ptr[count_elts].elt = NULL; + return (elt_list_ptr); +} +/* ********************************************************************** + * + * Routines related to structure "inverse" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct inverse * Phreeqc:: +inverse_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space for a new inverse structure at position count_inverse. + * Initializes structure. + * arguments + * input: none + * output: pointer to an inverse structure + * return: OK + */ +{ + struct inverse *inverse_ptr; + + count_inverse++; + inverse = + (struct inverse *) PHRQ_realloc(inverse, + (size_t) count_inverse * + sizeof(struct inverse)); + if (inverse == NULL) + malloc_error(); + inverse_ptr = &(inverse[count_inverse - 1]); +/* + * Initialize variables + */ + inverse_ptr->description = NULL; + inverse_ptr->count_uncertainties = 0; + inverse_ptr->count_solns = 0; + inverse_ptr->count_elts = 0; + inverse_ptr->count_isotopes = 0; + inverse_ptr->count_i_u = 0; + inverse_ptr->count_phases = 0; + inverse_ptr->count_force_solns = 0; +/* + * allocate space for pointers in structure to NULL + */ + + inverse_ptr->uncertainties = + (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->uncertainties == NULL) + malloc_error(); + + inverse_ptr->ph_uncertainties = + (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (inverse_ptr->ph_uncertainties == NULL) + malloc_error(); + + inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int)); + if (inverse_ptr->force_solns == NULL) + malloc_error(); + + inverse_ptr->dalk_dph = NULL; + inverse_ptr->dalk_dc = NULL; + + inverse_ptr->solns = NULL; + + inverse_ptr->elts = + (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); + if (inverse_ptr->elts == NULL) + malloc_error(); + inverse_ptr->elts[0].name = NULL; + inverse_ptr->elts[0].uncertainties = NULL; + + inverse_ptr->isotopes = + (struct inv_isotope *) PHRQ_malloc((size_t) + sizeof(struct inv_isotope)); + if (inverse_ptr->isotopes == NULL) + malloc_error(); + inverse_ptr->isotopes[0].isotope_name = NULL; + inverse_ptr->isotopes[0].isotope_number = 0; + inverse_ptr->isotopes[0].elt_name = NULL; + + inverse_ptr->i_u = + (struct inv_isotope *) PHRQ_malloc((size_t) + sizeof(struct inv_isotope)); + if (inverse_ptr->i_u == NULL) + malloc_error(); + inverse_ptr->i_u[0].isotope_name = NULL; + inverse_ptr->i_u[0].isotope_number = 0; + inverse_ptr->i_u[0].elt_name = NULL; + + inverse_ptr->phases = + (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); + if (inverse_ptr->phases == NULL) + malloc_error(); + + return (inverse_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare inverse values for n_user + */ + const struct inverse *nptr1; + const struct inverse *nptr2; + + nptr1 = (const struct inverse *) ptr1; + nptr2 = (const struct inverse *) ptr2; + if (nptr1->n_user > nptr2->n_user) + return (1); + if (nptr1->n_user < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Deletes inverse i from list (i is not user number), + * Frees memory allocated to inverse struct + * Input: i, number of inverse struct to delete + * Return: OK + */ + int j; + + inverse_free(&(inverse[i])); + for (j = i; j < (count_inverse - 1); j++) + { + memcpy((void *) &(inverse[j]), (void *) &(inverse[j + 1]), + (size_t) sizeof(struct inverse)); + } + count_inverse--; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_free(struct inverse *inverse_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free all memory for an inverse structure. + */ + int i; + + inverse_ptr->description = + (char *) free_check_null(inverse_ptr->description); +/* Free solns */ + inverse_ptr->solns = (int *) free_check_null(inverse_ptr->solns); + +/* Free uncertainties */ + inverse_ptr->uncertainties = + (LDBLE *) free_check_null(inverse_ptr->uncertainties); + inverse_ptr->ph_uncertainties = + (LDBLE *) free_check_null(inverse_ptr->ph_uncertainties); + +/* Free force_solns */ + inverse_ptr->force_solns = + (int *) free_check_null(inverse_ptr->force_solns); + +/* Free elts */ + for (i = 0; i < inverse_ptr->count_elts; i++) + { + inverse_ptr->elts[i].uncertainties = + (LDBLE *) free_check_null(inverse_ptr->elts[i].uncertainties); + }; + inverse_ptr->elts = + (struct inv_elts *) free_check_null(inverse_ptr->elts); + +/* Free isotopes */ + for (i = 0; i < inverse_ptr->count_isotopes; i++) + { + inverse_ptr->isotopes[i].uncertainties = + (LDBLE *) free_check_null(inverse_ptr->isotopes[i].uncertainties); + }; + inverse_ptr->isotopes = + (struct inv_isotope *) free_check_null(inverse_ptr->isotopes); + + for (i = 0; i < inverse_ptr->count_i_u; i++) + { + inverse_ptr->i_u[i].uncertainties = + (LDBLE *) free_check_null(inverse_ptr->i_u[i].uncertainties); + }; + inverse_ptr->i_u = + (struct inv_isotope *) free_check_null(inverse_ptr->i_u); + +/* Free phases */ + for (i = 0; i < inverse_ptr->count_phases; i++) + { + inverse_ptr->phases[i].isotopes = + (struct isotope *) free_check_null(inverse_ptr->phases[i]. + isotopes); + } + inverse_ptr->phases = + (struct inv_phases *) free_check_null(inverse_ptr->phases); + +/* Free carbon derivatives */ + inverse_ptr->dalk_dph = (LDBLE *) free_check_null(inverse_ptr->dalk_dph); + inverse_ptr->dalk_dc = (LDBLE *) free_check_null(inverse_ptr->dalk_dc); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_isotope_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct inv_isotope *iso_ptr1, *iso_ptr2; + + iso_ptr1 = (const struct inv_isotope *) ptr1; + iso_ptr2 = (const struct inv_isotope *) ptr2; + i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); + if (i != 0) + return (i); + if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) + { + return (-1); + } + else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) + { + return (1); + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +struct inverse * Phreeqc:: +inverse_search(int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "inverse" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in inverse + * + * Returns: + * if found, the address of the inverse element + * if not found, NULL + * + */ + int i; + for (i = 0; i < count_inverse; i++) + { + if (inverse[i].n_user == n_user) + { + *n = i; + return (&(inverse[i])); + } + } +/* + * An inverse structure with n_user was not found + */ + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +inverse_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of inverse structures + */ + if (count_inverse > 0) + { + qsort(inverse, (size_t) count_inverse, + (size_t) sizeof(struct inverse), inverse_compare); + } + return (OK); +} +/* ********************************************************************** + * + * Routines related to structure "kinetics" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct kinetics * Phreeqc:: +kinetics_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct kinetics *kinetics_ptr; + kinetics_ptr = (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); + if (kinetics_ptr == NULL) + malloc_error(); + kinetics_ptr->n_user = -1; + kinetics_ptr->n_user_end = -1; + kinetics_ptr->description = NULL; + kinetics_ptr->count_comps = 0; + kinetics_ptr->comps = NULL; + kinetics_ptr->count_steps = 0; + kinetics_ptr->steps = NULL; + kinetics_ptr->totals = NULL; + kinetics_ptr->rk = 0; + kinetics_ptr->bad_step_max = 0; + kinetics_ptr->use_cvode = FALSE; + + return (kinetics_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct kinetics * Phreeqc:: +kinetics_bsearch(int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search kinetics to find if user kinetics number k exists. + * Kinetics is assumed to be in sort order by user number. + */ + void *void_ptr; + if (count_kinetics == 0) + { + *n = -999; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) &k, + (char *) kinetics, + (size_t) count_kinetics, + (size_t) sizeof(struct kinetics), kinetics_compare_int); + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + *n = (int) ((struct kinetics *) void_ptr - kinetics); + return ((struct kinetics *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct kinetics *kinetics_ptr1, *kinetics_ptr2; + kinetics_ptr1 = (const struct kinetics *) ptr1; + kinetics_ptr2 = (const struct kinetics *) ptr2; + if (kinetics_ptr1->n_user > kinetics_ptr2->n_user) + return (1); + if (kinetics_ptr1->n_user < kinetics_ptr2->n_user) + return (-1); + return (0); + +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +kinetics_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare kinetics user numbers + */ + const int *nptr1; + const struct kinetics *nptr2; + + nptr1 = (const int *) ptr1; + nptr2 = (const struct kinetics *) ptr2; + if (*nptr1 > nptr2->n_user) + return (1); + if (*nptr1 < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_copy(struct kinetics *kinetics_old_ptr, + struct kinetics *kinetics_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies kinetics data from kinetics_old_ptr to new location, kinetics_new_ptr. + * Space for the kinetics_new_ptr structure must already be malloced. + * Space for kinetics components is malloced here. + */ + char token[MAX_LENGTH]; + int count_steps, i; +/* + * copy old to new + */ + memcpy(kinetics_new_ptr, kinetics_old_ptr, sizeof(struct kinetics)); +/* + * Store data for structure kinetics + */ + kinetics_new_ptr->n_user = n_user_new; + kinetics_new_ptr->n_user_end = n_user_new; + sprintf(token, "Kinetics defined in simulation %d.", simulation); + kinetics_new_ptr->description = string_duplicate(token); + kinetics_new_ptr->totals = NULL; + kinetics_new_ptr->totals = elt_list_dup(kinetics_old_ptr->totals); +/* + * Copy time steps + */ + if (kinetics_new_ptr->count_steps > 0) + { + count_steps = kinetics_new_ptr->count_steps; + } + else if (kinetics_new_ptr->count_steps < 0) + { + count_steps = 1; + } + else + { + count_steps = 0; + } + if (count_steps > 0) + { + kinetics_new_ptr->steps = + (LDBLE *) PHRQ_malloc((size_t) (count_steps * sizeof(LDBLE))); + if (kinetics_new_ptr->steps == NULL) + malloc_error(); + memcpy(kinetics_new_ptr->steps, kinetics_old_ptr->steps, + (size_t) count_steps * sizeof(LDBLE)); + } +/* + * Copy kinetic components + */ + if (kinetics_new_ptr->count_comps > 0) + { + kinetics_new_ptr->comps = + (struct kinetics_comp *) PHRQ_malloc((size_t) kinetics_old_ptr-> + count_comps * + sizeof(struct + kinetics_comp)); + if (kinetics_new_ptr->comps == NULL) + malloc_error(); + } + else + { + kinetics_new_ptr->comps = NULL; + } + for (i = 0; i < kinetics_old_ptr->count_comps; i++) + { + kinetics_comp_duplicate(&kinetics_new_ptr->comps[i], + &kinetics_old_ptr->comps[i]); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, + struct kinetics_comp *kinetics_comp_old_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies kinetics comp data from kinetics_comp_old_ptr to new location + * Space for the new structure must already be allocated + */ + memcpy(kinetics_comp_new_ptr, kinetics_comp_old_ptr, + sizeof(struct kinetics_comp)); +/* + * Kinetics character parameters + */ + if (kinetics_comp_new_ptr->count_c_params > 0) + { + kinetics_comp_new_ptr->c_params = + (const char **) + PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_c_params) * + sizeof(char *)); + if (kinetics_comp_new_ptr->c_params == NULL) + malloc_error(); + memcpy(kinetics_comp_new_ptr->c_params, + kinetics_comp_old_ptr->c_params, + (size_t) (kinetics_comp_old_ptr->count_c_params) * + sizeof(char *)); + } + else + { + kinetics_comp_new_ptr->c_params = NULL; + } +/* + * Kinetics LDBLE parameters + */ + if (kinetics_comp_new_ptr->count_d_params > 0) + { + kinetics_comp_new_ptr->d_params = + (LDBLE *) + PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_d_params) * + sizeof(LDBLE)); + if (kinetics_comp_new_ptr->d_params == NULL) + malloc_error(); + memcpy(kinetics_comp_new_ptr->d_params, + kinetics_comp_old_ptr->d_params, + (size_t) (kinetics_comp_old_ptr->count_d_params) * + sizeof(LDBLE)); + } + else + { + kinetics_comp_new_ptr->d_params = + (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + } +/* + * Kinetics list of formulae + */ + if (kinetics_comp_new_ptr->count_list > 0) + { + kinetics_comp_new_ptr->list = + (struct name_coef *) + PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_list) * + sizeof(struct name_coef)); + if (kinetics_comp_new_ptr->list == NULL) + malloc_error(); + memcpy(kinetics_comp_new_ptr->list, kinetics_comp_old_ptr->list, + (size_t) (kinetics_comp_old_ptr->count_list) * + sizeof(struct name_coef)); + } + else + { + kinetics_comp_new_ptr->d_params = NULL; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an kinetics definition from position n to position count_kinetics. + * New kinetics structure is given user number n_user. + */ + space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, + sizeof(struct kinetics)); + kinetics_copy(&kinetics[n], &kinetics[count_kinetics], n_user); + count_kinetics++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array kinetics. + */ +{ + int i; + int n_old; + struct kinetics *kinetics_ptr_old; +/* + * Find n_user_old in structure array + */ + kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); + if (kinetics_ptr_old != NULL) + { + /* + * Delete kinetics + */ + kinetics_free(&kinetics[n_old]); + + for (i = n_old + 1; i < count_kinetics; i++) + { + memcpy((void *) &kinetics[i - 1], (void *) &kinetics[i], + (size_t) sizeof(struct kinetics)); + } + count_kinetics--; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies kinetics[n_user_old] to old n_user_new space if + * found or to kinetics[count_kinetics] if not found. + * Kinetics array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct kinetics *kinetics_ptr_old, *kinetics_ptr_new; +/* + * Find n_user_old in structure array kinetics + */ + if (n_user_old == n_user_new) + return (OK); + kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); + if (kinetics_ptr_old == NULL) + { + error_string = sformatf( "Kinetics %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array kinetics or make new space + */ + sort = FALSE; + kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); + if (kinetics_ptr_new != NULL) + { + kinetics_free(kinetics_ptr_new); + } + else + { + space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, + sizeof(struct kinetics)); + if (n_user_new < kinetics[count_kinetics - 1].n_user) + sort = TRUE; + n_new = count_kinetics++; + } +/* + * Copy data + */ + kinetics_copy(&kinetics[n_old], &kinetics[n_new], n_user_new); + if (sort == TRUE) + kinetics_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_free(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Frees all data associated with kinetics structure. + */ + if (kinetics_ptr == NULL) + return (ERROR); +/* + * Free space allocated for kinetics structure + */ + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + kinetics_ptr->comps[i].c_params = + (const char **) free_check_null(kinetics_ptr->comps[i].c_params); + kinetics_ptr->comps[i].d_params = + (LDBLE *) free_check_null(kinetics_ptr->comps[i].d_params); + kinetics_ptr->comps[i].list = + (struct name_coef *) free_check_null(kinetics_ptr->comps[i].list); + } + kinetics_ptr->description = + (char *) free_check_null(kinetics_ptr->description); + kinetics_ptr->steps = (LDBLE *) free_check_null(kinetics_ptr->steps); + kinetics_ptr->comps = + (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); + kinetics_ptr->totals = + (struct elt_list *) free_check_null(kinetics_ptr->totals); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, + char *description) +/* ---------------------------------------------------------------------- */ +{ + if (kinetics_ptr == NULL) + return (ERROR); + kinetics_ptr->n_user = n_user; + kinetics_ptr->n_user_end = n_user_end; + kinetics_ptr->description = string_duplicate(description); + kinetics_ptr->count_comps = 0; + kinetics_ptr->comps = + (struct kinetics_comp *) PHRQ_malloc((size_t) + sizeof(struct kinetics_comp)); + if (kinetics_ptr->comps == NULL) + malloc_error(); + kinetics_ptr->count_steps = 0; + kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); + if (kinetics_ptr->steps == NULL) + malloc_error(); + kinetics_ptr->step_divide = 1.0; + /*kinetics_ptr->units = string_hsave("sec"); */ + kinetics_ptr->totals = NULL; + kinetics_ptr->rk = 3; + kinetics_ptr->bad_step_max = 500; + kinetics_ptr->use_cvode = FALSE; + kinetics_ptr->cvode_order = 5; + kinetics_ptr->cvode_steps = 100; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies kinetics_ptr_old to old n_user_new space if + * found or to kinetics[count_kinetics] if not found. + * Kinetics array may not be in sort order after the copy. + */ + int n_new, sort; + struct kinetics *kinetics_ptr_new; +/* + * Find n_user_old in structure array kinetics + */ + if (kinetics_ptr_old == NULL) + { + error_string = sformatf( "Kinetics pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array kinetics or make new space + */ + sort = FALSE; + kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); + if (kinetics_ptr_new == kinetics_ptr_old) + return (OK); + if (kinetics_ptr_new != NULL) + { + kinetics_free(kinetics_ptr_new); + } + else + { + space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, + sizeof(struct kinetics)); + if (n_user_new < kinetics[count_kinetics - 1].n_user) + sort = TRUE; + n_new = count_kinetics++; + } +/* + * Copy data + */ + kinetics_copy(kinetics_ptr_old, &kinetics[n_new], n_user_new); + if (sort == TRUE) + kinetics_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct kinetics * Phreeqc:: +kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct kinetics *kinetics_ptr; + kinetics_ptr = kinetics_alloc(); + kinetics_copy(kinetics_old_ptr, kinetics_ptr, n_user_new); + return (kinetics_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct kinetics * Phreeqc:: +kinetics_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Does linear search for user number n_user. + * Returns pointer to kinetics structure and position number, n, + * in kinetics array if found. + * Returns NULL if not found. + */ + int i; + for (i = 0; i < count_kinetics; i++) + { + if (n_user == kinetics[i].n_user) + { + break; + } + } + if (i >= count_kinetics) + { + if (print == TRUE) + { + error_string = sformatf( "Kinetics %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return (NULL); + } + *n = i; + return (&kinetics[i]); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +kinetics_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of kinetics structures + */ + if (count_kinetics > 0) + { + qsort(kinetics, (size_t) count_kinetics, + (size_t) sizeof(struct kinetics), kinetics_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "master" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +master_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a master structure and initializes the space. + * arguments: void + * return: pointer to a master structure + */ +{ + struct master *ptr; + ptr = (struct master *) PHRQ_malloc(sizeof(struct master)); + if (ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL + */ + ptr->in = FALSE; + ptr->number = -1; + ptr->last_model = -1; + ptr->type = 0; + ptr->primary = FALSE; + ptr->coef = 0.0; + ptr->total = 0.0; + ptr->isotope_ratio = 0; + ptr->isotope_ratio_uncertainty = 0; + ptr->isotope = 0; + ptr->total_primary = 0; + ptr->elt = NULL; + ptr->alk = 0.0; + ptr->gfw = 0.0; + ptr->gfw_formula = NULL; + ptr->unknown = NULL; + ptr->s = NULL; + ptr->rxn_primary = NULL; + ptr->rxn_secondary = NULL; + ptr->pe_rxn = NULL; + ptr->minor_isotope = FALSE; + return (ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +master_delete(char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete master species: Free memory of master species structure, free + * the structure, and remove from array master. + * + * Input + * ptr character string with name of element or valence state + * Returns + * TRUE if master species was deleted. + * FALSE if master species was not found. + */ + int j, n; + + if (master_search(ptr, &n) == NULL) + return (FALSE); + master_free(master[n]); + for (j = n; j < (count_master - 1); j++) + { + master[j] = master[j + 1]; + } + count_master--; + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +master_free(struct master *master_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free memory pointed to by master species pointer, master_ptr. + * Frees master_ptr itself. + */ + if (master_ptr == NULL) + return (ERROR); + rxn_free(master_ptr->rxn_primary); + rxn_free(master_ptr->rxn_secondary); + master_ptr = (struct master *) free_check_null(master_ptr); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +master_bsearch(const char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Uses binary search. Assumes master is in sort order. + * Find master species for string (*ptr) containing name of element or valence state. + * + * Input: ptr pointer to string containing element name + * + * Return: pointer to master structure containing name ptr or NULL. + */ + void *void_ptr; + if (count_master == 0) + { + return (NULL); + } + void_ptr = bsearch((const char *) ptr, + (char *) master, + (unsigned) count_master, + sizeof(struct master *), master_compare_string); + if (void_ptr == NULL) + { + char * dup = string_duplicate(ptr); + replace("(+","(", dup); + void_ptr = bsearch((const char *) dup, + (char *) master, + (unsigned) count_master, + sizeof(struct master *), master_compare_string); + dup = (char *) free_check_null(dup); + } + if (void_ptr == NULL) + { + return (NULL); + } + else + { + return (*(struct master **) void_ptr); + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +master_compare_string(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *string_ptr; + const struct master *master_ptr; + + string_ptr = (const char *) ptr1; + master_ptr = *(const struct master **) ptr2; + return (strcmp_nocase(string_ptr, master_ptr->elt->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +master_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct master *master_ptr1, *master_ptr2; + master_ptr1 = *(const struct master **) ptr1; + master_ptr2 = *(const struct master **) ptr2; + return (strcmp_nocase(master_ptr1->elt->name, master_ptr2->elt->name)); +} + +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +master_bsearch_primary(const char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find primary master species for first element in the string, ptr. + * Uses binary search. Assumes master is in sort order. + */ + int l; + char *ptr1; + char elt[MAX_LENGTH]; + struct master *master_ptr_primary; +/* + * Find element name + */ + char * temp_name = string_duplicate(ptr); + ptr1 = temp_name; + get_elt(&ptr1, elt, &l); + free_check_null(temp_name); +/* + * Search master species list + */ + master_ptr_primary = master_bsearch(elt); + if (master_ptr_primary == NULL) + { + input_error++; + error_string = sformatf( + "Could not find primary master species for %s.", ptr); + error_msg(error_string, CONTINUE); + } + return (master_ptr_primary); +} +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +master_bsearch_secondary(char *ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find secondary master species that corresponds to the primary master species. + * i.e. S(6) for S. + */ + int l; + char *ptr1; + char elt[MAX_LENGTH]; + struct master *master_ptr_primary, *master_ptr, *master_ptr_secondary=NULL; + int j; +/* + * Find element name + */ + ptr1 = ptr; + get_elt(&ptr1, elt, &l); +/* + * Search master species list + */ + master_ptr_primary = master_bsearch(elt); + if (master_ptr_primary == NULL) + { + input_error++; + error_string = sformatf( + "Could not find primary master species for %s.", ptr); + error_msg(error_string, CONTINUE); + } +/* + * If last in list or not redox +*/ + if ((master_ptr_primary->number >= count_master - 1) || + (master[master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) + { + return(master_ptr_primary); + } +/* + * Find secondary master with same species as primary + */ + master_ptr = NULL; + for (j = master_ptr_primary->number + 1; j < count_master; j++) + { + if (master[j]->s == master_ptr_primary->s) + { + master_ptr = master[j]; + } + } +/* + * + */ + if (master_ptr->elt->primary != master_ptr_primary) + { + input_error++; + error_string = sformatf( + "Could not find secondary master species for %s.", ptr); + error_msg(error_string, STOP); + } + else + { + master_ptr_secondary = master_ptr; + } + + + return (master_ptr_secondary); +} +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +master_search(char *ptr, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Linear search of master to find master species in string, ptr. + * Returns pointer if found. n contains position in array master. + * Returns NULL if not found. + */ + int i; + struct master *master_ptr; +/* + * Search master species list + */ + *n = -999; + for (i = 0; i < count_master; i++) + { + if (strcmp(ptr, master[i]->elt->name) == 0) + { + *n = i; + master_ptr = master[i]; + return (master_ptr); + } + } + return (NULL); +} +/* ********************************************************************** + * + * Routines related to structure "pe_data" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pe_data * Phreeqc:: +pe_data_alloc(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocate and initialize an array of struct pe_data + */ + struct pe_data *pe_data_ptr; + char token[MAX_LENGTH]; + + pe_data_ptr = + (struct pe_data *) PHRQ_malloc((size_t) (2 * sizeof(struct pe_data))); + if (pe_data_ptr == NULL) + malloc_error(); + pe_data_ptr[0].name = pe_string; + if (s_eminus != NULL && s_eminus->rxn != NULL) + { + pe_data_ptr[0].rxn = rxn_dup(s_eminus->rxn); + } + else + { + pe_data_ptr[0].rxn = rxn_alloc(3); + if (pe_data_ptr[0].rxn == NULL) + malloc_error(); + strcpy(token, "e-"); + s_eminus = s_store(token, -1.0, FALSE); + pe_data_ptr[0].rxn->token[0].s = s_eminus; + pe_data_ptr[0].rxn->token[0].coef = -1.0; + pe_data_ptr[0].rxn->token[1].s = s_eminus; + pe_data_ptr[0].rxn->token[1].coef = -1.0; + pe_data_ptr[0].rxn->token[2].s = NULL; + pe_data_ptr[0].rxn->dz[0] = 0.0; + pe_data_ptr[0].rxn->dz[1] = 0.0; + pe_data_ptr[0].rxn->dz[2] = 0.0; + } + pe_data_ptr[1].name = NULL; + pe_data_ptr[1].rxn = NULL; + + return (pe_data_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct pe_data * Phreeqc:: +pe_data_dup(struct pe_data *pe_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocate space and copy data from pe_ptr_old into the new space. + * Returns pointer to new space. + */ + int i, count_pe; + struct pe_data *pe_ptr_new; +/* + * Count pe data and copy into new structure + */ + if (pe_ptr_old == NULL) + return (ERROR); + for (i = 0; pe_ptr_old[i].name != NULL; i++); + count_pe = i + 1; + pe_ptr_new = + (struct pe_data *) PHRQ_malloc((size_t) count_pe * + sizeof(struct pe_data)); + if (pe_ptr_new == NULL) + malloc_error(); + memcpy((void *) pe_ptr_new, (void *) pe_ptr_old, + (size_t) count_pe * sizeof(struct pe_data)); + for (i = 0; i < count_pe - 1; i++) + { + pe_ptr_new[i].rxn = rxn_dup(pe_ptr_old[i].rxn); + } + pe_ptr_new[count_pe - 1].rxn = NULL; + return (pe_ptr_new); +} + +/* ---------------------------------------------------------------------- */ +struct pe_data * Phreeqc:: +pe_data_free(struct pe_data *pe_data_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all data for pe_data_ptr, including pe_data_ptr. + */ + int i; + + if (pe_data_ptr == NULL) + return (ERROR); + for (i = 0; pe_data_ptr[i].name != NULL; i++) + { + rxn_free(pe_data_ptr[i].rxn); + } + pe_data_ptr = (struct pe_data *) free_check_null(pe_data_ptr); + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pe_data_store(struct pe_data **pe, const char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Find pe name in current list of pe_data structures + * or allocate new pe_data structure + */ + int i; + struct pe_data *pe_data_ptr; +/* + * Search for pe in list + */ + pe_data_ptr = *pe; + for (i = 0; pe_data_ptr[i].name != NULL; i++) + { + if (strcmp(token, pe_data_ptr[i].name) == 0) + { + return (i); + } + } +/* + * Save new struct pe_data in array + */ + *pe = + (struct pe_data *) PHRQ_realloc((void *) *pe, + (size_t) (i + + 2) * + sizeof(struct pe_data)); + if (*pe == NULL) + malloc_error(); + pe_data_ptr = *pe; + pe_data_ptr[i].name = string_hsave(token); + pe_data_ptr[i].rxn = NULL; + pe_data_ptr[i + 1].name = NULL; + return (i); +} + +/* ********************************************************************** + * + * Routines related to structure "phases" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct phase * Phreeqc:: +phase_alloc(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space to a phase structure and initializes + * arguments: void + * return: pointer to new phase structure + */ + struct phase *phase_ptr; +/* + * Allocate space + */ + phase_ptr = (struct phase *) PHRQ_malloc(sizeof(struct phase)); + if (phase_ptr == NULL) + malloc_error(); +/* + * Initialize space + */ + phase_init(phase_ptr); + return (phase_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares names of phases for sort + */ + const struct phase *phase_ptr1, *phase_ptr2; + phase_ptr1 = *(const struct phase **) ptr1; + phase_ptr2 = *(const struct phase **) ptr2; + return (strcmp_nocase(phase_ptr1->name, phase_ptr2->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_compare_string(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *char_ptr; + const struct phase *phase_ptr; + char_ptr = (const char *) ptr1; + phase_ptr = *(const struct phase **) ptr2; + return (strcmp_nocase(char_ptr, phase_ptr->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Deletes phase i from list, phases + * Frees memory allocated to phase[i] and renumbers phases to remove number i. + * Input: i, number of phase + * Return: OK + */ + int j; + + phase_free(phases[i]); + phases[i] = (struct phase *) free_check_null(phases[i]); + for (j = i; j < (count_phases - 1); j++) + { + phases[j] = phases[j + 1]; + } + count_phases--; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_free(struct phase *phase_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within phase[i], does not free phase structure + * Input: i, number of phase + * Return: OK + */ + if (phase_ptr == NULL) + return (ERROR); + phase_ptr->next_elt = + (struct elt_list *) free_check_null(phase_ptr->next_elt); + phase_ptr->next_sys_total = + (struct elt_list *) free_check_null(phase_ptr->next_sys_total); + rxn_free(phase_ptr->rxn); + rxn_free(phase_ptr->rxn_s); + rxn_free(phase_ptr->rxn_x); + phase_ptr->add_logk = + (struct name_coef *) free_check_null(phase_ptr->add_logk); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct phase * Phreeqc:: +phase_bsearch(const char *ptr, int *j, int print) +/* ---------------------------------------------------------------------- */ +{ +/* Binary search the structure array "phases" for a name that is equal to + * ptr. Assumes array phases is in sort order. + * + * Arguments: + * name input, a character string to be located in phases. + * j index number in array phases. + * + * Returns: + * if found, pointer to phase structure. + * if not found, NULL + * + */ + void *void_ptr; + + void_ptr = NULL; + if (count_phases > 0) + { + void_ptr = (void *) + bsearch((char *) ptr, + (char *) phases, + (size_t) count_phases, + (size_t) sizeof(struct phase *), phase_compare_string); + } + if (void_ptr == NULL && print == TRUE) + { + error_string = sformatf( "Could not find phase in list, %s.", ptr); + error_msg(error_string, CONTINUE); + } + + if (void_ptr == NULL) + { + *j = -1; + return (NULL); + } + + *j = (int) ((struct phase **) void_ptr - phases); + return (*(struct phase **) void_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +phase_init(struct phase *phase_ptr) +/* ---------------------------------------------------------------------- */ +/* + * set pointers in phase structure to NULL + */ +{ + int i; + + phase_ptr->name = NULL; + phase_ptr->formula = NULL; + phase_ptr->in = FALSE; + phase_ptr->lk = 0.0; + for (i = 0; i < MAX_LOG_K_INDICES; i++) + phase_ptr->logk[i] = 0.0; + phase_ptr->original_units = kjoules; + phase_ptr->count_add_logk = 0; + phase_ptr->add_logk = NULL; + phase_ptr->moles_x = 0; + phase_ptr->delta_max = 0; + phase_ptr->p_soln_x = 0; + phase_ptr->fraction_x = 0; + phase_ptr->log10_lambda = 0; + phase_ptr->log10_fraction_x = 0; + phase_ptr->dn = 0; + phase_ptr->dnb = 0; + phase_ptr->dnc = 0; + phase_ptr->gn = 0; + phase_ptr->gntot = 0; + phase_ptr->t_c = 0.0; + phase_ptr->p_c = 0.0; + phase_ptr->omega = 0.0; + phase_ptr->pr_a = 0.0; + phase_ptr->pr_b = 0.0; + phase_ptr->pr_alpha = 0.0; + phase_ptr->pr_tk = 0; + phase_ptr->pr_p = 0; + phase_ptr->pr_phi = 1.0; + phase_ptr->pr_aa_sum2 = 0; + for (i = 0; i < 9; i++) + phase_ptr->delta_v[i] = 0.0; + phase_ptr->pr_si_f = 0; + phase_ptr->pr_in = false; + phase_ptr->type = SOLID; + phase_ptr->next_elt = NULL; + phase_ptr->next_sys_total = NULL; + phase_ptr->check_equation = TRUE; + phase_ptr->rxn = NULL; + phase_ptr->rxn_s = NULL; + phase_ptr->rxn_x = NULL; + phase_ptr->replaced = 0; + phase_ptr->in_system = 1; + phase_ptr->original_deltav_units = cm3_per_mol; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct phase * Phreeqc:: +phase_store(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for phases. + * + * If found, pointer to the appropriate phase structure is returned. + * + * If the string is not found, a new entry is made at the end of + * the phases array (position count_phases) and count_phases is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * + * Arguments: + * name input, character string to be located or stored. + * + * Returns: + * The address of a phase structure that contains the phase data. + * If phase existed, it is reinitialized. The structure returned + * contains only the name of the phase. + */ + int n; + struct phase *phase_ptr; + ENTRY item, *found_item; + char token[MAX_LENGTH]; + const char *ptr; +/* + * Search list + */ + + strcpy(token, name); + str_tolower(token); + ptr = string_hsave(token); + + item.key = ptr; + item.data = NULL; + found_item = hsearch_multi(phases_hash_table, item, FIND); + if (found_item != NULL) + { + phase_ptr = (struct phase *) (found_item->data); + phase_free(phase_ptr); + phase_init(phase_ptr); + phase_ptr->name = string_hsave(name); + return (phase_ptr); + } +/* + * Make new phase structure and return pointer to it + */ + /* make sure there is space in phases */ + n = count_phases++; + if (count_phases >= max_phases) + { + space((void **) ((void *) &phases), count_phases, &max_phases, + sizeof(struct phase *)); + } + phases[n] = phase_alloc(); + /* set name in phase structure */ + phases[n]->name = string_hsave(name); +/* + * Update hash table + */ + item.key = ptr; + item.data = (void *) phases[n]; + found_item = hsearch_multi(phases_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in phase_store."); + error_msg(error_string, CONTINUE); + } + + return (phases[n]); +} +#ifdef SKIP +/* ********************************************************************** + * + * Routines related to structure "pp_assemblage" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct pp_assemblage * Phreeqc:: +pp_assemblage_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct pp_assemblage *pp_assemblage_ptr; + pp_assemblage_ptr = + (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); + if (pp_assemblage_ptr == NULL) + malloc_error(); + pp_assemblage_ptr->n_user = -1; + pp_assemblage_ptr->n_user_end = -1; + pp_assemblage_ptr->description = NULL; + pp_assemblage_ptr->new_def = 0; + pp_assemblage_ptr->next_elt = NULL; + pp_assemblage_ptr->count_comps = 0; + pp_assemblage_ptr->pure_phases = NULL; + return (pp_assemblage_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct pp_assemblage * Phreeqc:: +pp_assemblage_bsearch(int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array pp_assemblage to find user number k. + * Assumes pp_assemblage is in sort order. + * + * Input: k, user number to find. + * + * Output: n, position in array pp_assemblage for user number k. + * + * Return: pointer to pp_assemblage structure for user number k, if found. + * NULL if not found. + */ + void *void_ptr; + if (count_pp_assemblage == 0) + { + *n = -999; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) &k, + (char *) pp_assemblage, + (size_t) count_pp_assemblage, + (size_t) sizeof(struct pp_assemblage), + pp_assemblage_compare_int); + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + *n = (int) ((struct pp_assemblage *) void_ptr - pp_assemblage); + return ((struct pp_assemblage *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct pp_assemblage *pp_assemblage_ptr1, *pp_assemblage_ptr2; + pp_assemblage_ptr1 = (const struct pp_assemblage *) ptr1; + pp_assemblage_ptr2 = (const struct pp_assemblage *) ptr2; + if (pp_assemblage_ptr1->n_user > pp_assemblage_ptr2->n_user) + return (1); + if (pp_assemblage_ptr1->n_user < pp_assemblage_ptr2->n_user) + return (-1); + return (0); + +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +pp_assemblage_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare pp_assemblage user numbers + */ + const int *nptr1; + const struct pp_assemblage *nptr2; + + nptr1 = (const int *) ptr1; + nptr2 = (const struct pp_assemblage *) ptr2; + if (*nptr1 > nptr2->n_user) + return (1); + if (*nptr1 < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, + struct pp_assemblage *pp_assemblage_new_ptr, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies pp_assemblage data from pp_assemblage_old_ptr to pp_assemblage_new_ptr. + * Space for a pp_assemblage_new_ptr must already be malloced. + * Space for list of pure phases in assemblage is malloced here. + */ + int count_comps; + char token[MAX_LENGTH]; +/* + * Store data for structure pp_assemblage + */ + pp_assemblage_new_ptr->n_user = n_user_new; + pp_assemblage_new_ptr->n_user_end = n_user_new; + pp_assemblage_new_ptr->new_def = pp_assemblage_old_ptr->new_def; + sprintf(token, "Pp_Assemblage defined in simulation %d.", simulation); + pp_assemblage_new_ptr->description = string_duplicate(token); + pp_assemblage_new_ptr->next_elt = + elt_list_dup(pp_assemblage_old_ptr->next_elt); +/* + * Count pure phases + */ + count_comps = pp_assemblage_old_ptr->count_comps; + pp_assemblage_new_ptr->count_comps = count_comps; +/* + * Malloc space and copy + */ + pp_assemblage_new_ptr->pure_phases = + (struct pure_phase *) PHRQ_malloc((size_t) count_comps * + sizeof(struct pure_phase)); + if (pp_assemblage_new_ptr->pure_phases == NULL) + malloc_error(); + + memcpy((void *) pp_assemblage_new_ptr->pure_phases, + (void *) pp_assemblage_old_ptr->pure_phases, + (size_t) count_comps * sizeof(struct pure_phase)); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an pp_assemblage definition from position n + * to position count_pp_assemblage. + */ + space((void **) ((void *) &pp_assemblage), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage)); + pp_assemblage_copy(&pp_assemblage[n], + &pp_assemblage[count_pp_assemblage], n_user); + count_pp_assemblage++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies pp_assemblage[n_user_old] to old n_user_new space if + * found or to pp_assemblage[count_pp_assemblage] if not found. + * Pp_Assemblage array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct pp_assemblage *pp_assemblage_ptr_old, *pp_assemblage_ptr_new; +/* + * Find n_user_old in structure array pp_assemblage + */ + if (n_user_old == n_user_new) + return (OK); + pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); + if (pp_assemblage_ptr_old == NULL) + { + error_string = sformatf( "Pp_Assemblage %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array pp_assemblage or make new space + */ + sort = FALSE; + pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); + if (pp_assemblage_ptr_new != NULL) + { + pp_assemblage_free(pp_assemblage_ptr_new); + } + else + { + space((void **) ((void *) &pp_assemblage), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage)); + if (n_user_new < pp_assemblage[count_pp_assemblage - 1].n_user) + sort = TRUE; + n_new = count_pp_assemblage++; + } +/* + * Copy data + */ + pp_assemblage_copy(&pp_assemblage[n_old], &pp_assemblage[n_new], + n_user_new); + if (sort == TRUE) + pp_assemblage_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array pp_assemblage. + */ +{ + int i; + int n_old; + struct pp_assemblage *pp_assemblage_ptr_old; +/* + * Find n_user_old in structure array + */ + pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); + if (pp_assemblage_ptr_old != NULL) + { + /* + * Delete pp_assemblage + */ + pp_assemblage_free(&pp_assemblage[n_old]); + + for (i = n_old + 1; i < count_pp_assemblage; i++) + { + memcpy((void *) &pp_assemblage[i - 1], + (void *) &pp_assemblage[i], + (size_t) sizeof(struct pp_assemblage)); + } + count_pp_assemblage--; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for pp_assemblage structure + */ + if (pp_assemblage_ptr == NULL) + return (ERROR); + + pp_assemblage_ptr->description = + (char *) free_check_null(pp_assemblage_ptr->description); + pp_assemblage_ptr->next_elt = + (struct elt_list *) free_check_null(pp_assemblage_ptr->next_elt); + pp_assemblage_ptr->pure_phases = + (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, + int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides initial values for a new pp_assemblage + * arguments: + * n position in array pp_assemblage + * n_user user number for pp_assemblage + * return: OK + */ + pp_assemblage_ptr->n_user = n_user; + pp_assemblage_ptr->n_user_end = n_user_end; + pp_assemblage_ptr->new_def = TRUE; + pp_assemblage_ptr->description = string_duplicate(description); + + pp_assemblage_ptr->next_elt = NULL; + pp_assemblage_ptr->count_comps = 0; + pp_assemblage_ptr->pure_phases = + (struct pure_phase *) PHRQ_malloc((size_t) sizeof(struct pure_phase)); + if (pp_assemblage_ptr->pure_phases == NULL) + malloc_error(); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies pp_assemblage_ptr_old to old n_user_new space if + * found or to pp_assemblage[count_pp_assemblage] if not found. + * Pp_Assemblage array may not be in sort order after the copy. + */ + int n_new, sort; + struct pp_assemblage *pp_assemblage_ptr_new; +/* + * Find n_user_old in structure array pp_assemblage + */ + if (pp_assemblage_ptr_old == NULL) + { + error_string = sformatf( "Pp_Assemblage pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array pp_assemblage or make new space + */ + sort = FALSE; + pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); + if (pp_assemblage_ptr_new == pp_assemblage_ptr_old) + return (OK); + if (pp_assemblage_ptr_new != NULL) + { + pp_assemblage_free(pp_assemblage_ptr_new); + } + else + { + space((void **) ((void *) &pp_assemblage), count_pp_assemblage, + &max_pp_assemblage, sizeof(struct pp_assemblage)); + if (n_user_new < pp_assemblage[count_pp_assemblage - 1].n_user) + sort = TRUE; + n_new = count_pp_assemblage++; + } +/* + * Copy data + */ + pp_assemblage_copy(pp_assemblage_ptr_old, &pp_assemblage[n_new], + n_user_new); + if (sort == TRUE) + pp_assemblage_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct pp_assemblage * Phreeqc:: +pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct pp_assemblage *pp_assemblage_ptr; + pp_assemblage_ptr = pp_assemblage_alloc(); + pp_assemblage_copy(pp_assemblage_old_ptr, pp_assemblage_ptr, n_user_new); + return (pp_assemblage_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct pp_assemblage * Phreeqc:: +pp_assemblage_search(int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "pp_assemblage" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in pp_assemblage + * + * Returns: + * if found, the address of the pp_assemblage element + * if not found, NULL + */ + int i; + for (i = 0; i < count_pp_assemblage; i++) + { + if (pp_assemblage[i].n_user == n_user) + { + *n = i; + return (&(pp_assemblage[i])); + } + } +/* + * Pp_Assemblage not found + */ + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pp_assemblage_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of pp_assemblage structures + */ + if (count_pp_assemblage > 0) + { + qsort(pp_assemblage, (size_t) count_pp_assemblage, + (size_t) sizeof(struct pp_assemblage), pp_assemblage_compare); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pure_phase_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct pure_phase *pure_phase_ptr1, *pure_phase_ptr2; + pure_phase_ptr1 = (const struct pure_phase *) ptr1; + pure_phase_ptr2 = (const struct pure_phase *) ptr2; + return (strcmp_nocase(pure_phase_ptr1->name, pure_phase_ptr2->name)); + +} +#endif +/* ********************************************************************** + * + * Routines related to structure "rates" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct rate * Phreeqc:: +rate_bsearch(char *ptr, int *j) +/* ---------------------------------------------------------------------- */ +{ +/* Binary search the structure array "rates" for a name that is equal to + * ptr. Assumes array rates is in sort order. + * + * Arguments: + * name input, a character string to be located in rates. + * j index number in array rates. + * + * Returns: + * if found, pointer to rate structure. + * if not found, NULL + * + */ + void *void_ptr; + + if (count_rates == 0) + { + *j = -1; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) ptr, + (char *) rates, + (size_t) count_rates, + (size_t) sizeof(struct rate *), rate_compare_string); + + if (void_ptr == NULL) + { + *j = -1; + return (NULL); + } + + *j = (int) ((struct rate *) void_ptr - rates); + return ((struct rate *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rate_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compares names of rates for sort + */ + const struct rate *rate_ptr1, *rate_ptr2; + rate_ptr1 = *(const struct rate **) ptr1; + rate_ptr2 = *(const struct rate **) ptr2; + return (strcmp_nocase(rate_ptr1->name, rate_ptr2->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rate_compare_string(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *char_ptr; + const struct rate *rate_ptr; + char_ptr = (const char *) ptr1; + rate_ptr = *(const struct rate **) ptr2; + return (strcmp_nocase(char_ptr, rate_ptr->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rate_free(struct rate *rate_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees memory allocated within rate[i], does not free rate structure + * Input: i, number of rate + * Return: OK + */ + + + if (rate_ptr == NULL) + return (ERROR); + rate_ptr->commands = (char *) free_check_null(rate_ptr->commands); + if (rate_ptr->linebase != NULL) + { + char cmd[] = "new; quit"; + basic_run(cmd, rate_ptr->linebase, rate_ptr->varbase, rate_ptr->loopbase); + rate_ptr->linebase = NULL; + rate_ptr->varbase = NULL; + rate_ptr->loopbase = NULL; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct rate * Phreeqc:: +rate_search(const char *name, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "rates" for name. + * + * Arguments: + * name input, name of rate + * n output, position in rates + * + * Returns: + * if found, the address of the pp_assemblage element + * if not found, NULL + */ + int i; + *n = -1; + for (i = 0; i < count_rates; i++) + { + if (strcmp_nocase(rates[i].name, name) == 0) + { + *n = i; + return (&(rates[i])); + } + } +/* + * rate name not found + */ + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rate_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of rate structures + */ + if (count_rates > 0) + { + qsort(rates, (size_t) count_rates, (size_t) sizeof(struct rate), + rate_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "reaction", balanced chemical reactions + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct reaction * Phreeqc:: +rxn_alloc(int ntokens) +/* ---------------------------------------------------------------------- */ +{ + int i; +/* + * Allocates space to a rxn structure + * input: ntokens, number of tokens in reaction + * return: pointer to a species structure + */ + struct reaction *rxn_ptr; +/* + * Malloc reaction structure + */ + rxn_ptr = (struct reaction *) PHRQ_malloc(sizeof(struct reaction)); + if (rxn_ptr == NULL) + malloc_error(); +/* + * zero log k data + */ + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + rxn_ptr->logk[i] = 0.0; + } +/* + * zero dz data + */ + for (i = 0; i < 3; i++) + { + rxn_ptr->dz[i] = 0.0; + } +/* + * Malloc rxn_token structure + */ + rxn_ptr->token = + (struct rxn_token *) PHRQ_malloc((size_t) ntokens * + sizeof(struct rxn_token)); + for (i = 0; i < ntokens; i++) + { + rxn_ptr->token[i].s = NULL; + rxn_ptr->token[i].name = NULL; + rxn_ptr->token[i].coef = 0.0; + } + + if (rxn_ptr->token == NULL) + malloc_error(); + return (rxn_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct reaction * Phreeqc:: +rxn_dup(struct reaction *rxn_ptr_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * mallocs space for a reaction and copies the reaction + * input: rxn_ptr_old, pointer to a reaction structure to copy + * + * Return: rxn_ptr_new, pointer to duplicated structure to copy + */ + int i; + struct reaction *rxn_ptr_new; + + if (rxn_ptr_old == NULL) + return (NULL); + for (i = 0; rxn_ptr_old->token[i].s != NULL; i++); + + rxn_ptr_new = rxn_alloc(i + 1); +/* + * Copy logk data + */ + memcpy(rxn_ptr_new->logk, rxn_ptr_old->logk, (size_t) MAX_LOG_K_INDICES * sizeof(LDBLE)); +/* + * Copy dz data + */ + memcpy(rxn_ptr_new->dz, rxn_ptr_old->dz, (size_t) (3 * sizeof(LDBLE))); +/* + * Copy tokens + */ + memcpy(rxn_ptr_new->token, rxn_ptr_old->token, + (size_t) (i + 1) * sizeof(struct rxn_token)); + + return (rxn_ptr_new); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +rxn_find_coef(struct reaction * r_ptr, const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Finds coefficient of token in reaction. + * input: r_ptr, pointer to a reaction structure + * str, string to find as reaction token + * + * Return: 0.0, if token not found + * coefficient of token, if found. + */ + struct rxn_token *r_token; + LDBLE coef; + + r_token = r_ptr->token + 1; + coef = 0.0; + while (r_token->s != NULL) + { + if (strcmp(r_token->s->name, str) == 0) + { + coef = r_token->coef; + break; + } + r_token++; + } + return (coef); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rxn_free(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space allocated for a reaction structure + * input: rxn_ptr, pointer to reaction structure + * return: ERROR, if pointer is NULL + * OK, otherwise. + */ + if (rxn_ptr == NULL) + return (ERROR); + rxn_ptr->token = (struct rxn_token *) free_check_null(rxn_ptr->token); + rxn_ptr = (struct reaction *) free_check_null(rxn_ptr); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rxn_print(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space allocated for a reaction structure + * input: rxn_ptr, pointer to reaction structure + * return: ERROR, if pointer is NULL + * OK, otherwise. + */ + struct rxn_token *next_token; + int i; + if (rxn_ptr == NULL) + return (ERROR); + next_token = rxn_ptr->token; + output_msg(sformatf( "log k data:\n")); + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + output_msg(sformatf( "\t%f\n", (double) rxn_ptr->logk[i])); + } + output_msg(sformatf( "Reaction definition\n")); + while (next_token->s != NULL || next_token->name != NULL) + { + output_msg(sformatf( "\tcoef %f ", next_token->coef)); + if (next_token->s != NULL) + { + output_msg(sformatf( "\tspecies token: %s ", + next_token->s->name)); + } + if (next_token->name != NULL) + { + output_msg(sformatf( "\tname token: %s", next_token->name)); + } + output_msg(sformatf( "\n")); + next_token++; + } + output_msg(sformatf( "dz data\n")); + for (i = 0; i < 3; i++) + { + output_msg(sformatf( "\t%d %e\n", i, (double) rxn_ptr->dz[i])); + + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "species" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct species * Phreeqc:: +s_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a species structure, initializes + * arguments: void + * return: pointer to a species structure + */ +{ + struct species *s_ptr; + s_ptr = (struct species *) PHRQ_malloc(sizeof(struct species)); + if (s_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + s_init(s_ptr); + + return (s_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct species *s_ptr1, *s_ptr2; + s_ptr1 = *(const struct species **) ptr1; + s_ptr2 = *(const struct species **) ptr2; + return (strcmp(s_ptr1->name, s_ptr2->name)); + +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete species i: free memory and renumber array of pointers, s. + */ + int j; + + s_free(s[i]); + s[i] = (struct species *) free_check_null(s[i]); + for (j = i; j < (count_s - 1); j++) + { + s[j] = s[j + 1]; + } + count_s--; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_free(struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for species structure, s_ptr. Does not free s_ptr. + */ + if (s_ptr == NULL) + return (ERROR); + s_ptr->next_elt = (struct elt_list *) free_check_null(s_ptr->next_elt); + s_ptr->next_secondary = + (struct elt_list *) free_check_null(s_ptr->next_secondary); + s_ptr->next_sys_total = + (struct elt_list *) free_check_null(s_ptr->next_sys_total); + s_ptr->add_logk = (struct name_coef *) free_check_null(s_ptr->add_logk); + rxn_free(s_ptr->rxn); + rxn_free(s_ptr->rxn_s); + rxn_free(s_ptr->rxn_x); + s_ptr->diff_layer = + (struct species_diff_layer *) free_check_null(s_ptr->diff_layer); + return (OK); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +s_init(struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a species structure + */ +{ + int i; +/* + * set pointers in structure to NULL + */ + s_ptr->name = NULL; + s_ptr->mole_balance = NULL; + s_ptr->in = FALSE; + s_ptr->number = 0; + s_ptr->primary = NULL; + s_ptr->secondary = NULL; + s_ptr->gfw = 0.0; + s_ptr->z = 0.0; + s_ptr->dw = 0.0; + s_ptr->erm_ddl = 1.0; + s_ptr->equiv = 0; + s_ptr->alk = 0.0; + s_ptr->carbon = 0.0; + s_ptr->co2 = 0.0; + s_ptr->h = 0.0; + s_ptr->o = 0.0; + s_ptr->dha = 0.0; + s_ptr->dhb = 0.0; + s_ptr->a_f = 0.0; + s_ptr->lk = 0.0; + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + s_ptr->logk[i] = 0.0; + } +/* VP: Density Start */ + for (i = 0; i < 6; i++) + { + s_ptr->millero[i] = 0.0; + } +/* VP: Density End */ + s_ptr->original_units = kjoules; + s_ptr->count_add_logk = 0; + s_ptr->add_logk = NULL; + s_ptr->lg = 0.0; + s_ptr->lg_pitzer = 0.0; + s_ptr->lm = 0.0; + s_ptr->la = 0.0; + s_ptr->dg = 0.0; + s_ptr->dg_total_g = 0; + s_ptr->moles = 0.0; + s_ptr->type = 0; + s_ptr->gflag = 0; + s_ptr->exch_gflag = 0; + s_ptr->next_elt = NULL; + s_ptr->next_secondary = NULL; + s_ptr->next_sys_total = NULL; + s_ptr->check_equation = TRUE; + s_ptr->original_deltav_units = cm3_per_mol; + + s_ptr->rxn = NULL; + s_ptr->rxn_s = NULL; + s_ptr->rxn_x = NULL; + s_ptr->tot_g_moles = 0; + s_ptr->tot_dh2o_moles = 0; + s_ptr->diff_layer = NULL; + for (i = 0; i < 5; i++) + { + s_ptr->cd_music[i] = 0.0; + } + for (i = 0; i < 3; i++) + { + s_ptr->dz[i] = 0.0; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct species * Phreeqc:: +s_search(const char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for species. + * + * Arguments: + * name input, a character string to be located in species. + * i is obsolete. + * + * Returns: + * If found, pointer to the appropriate species structure is returned. + * else, NULL pointer is returned. + */ + struct species *s_ptr; + ENTRY item, *found_item; + char safe_name[MAX_LENGTH]; + + strcpy(safe_name, name); + item.key = safe_name; + item.data = NULL; + found_item = hsearch_multi(species_hash_table, item, FIND); + if (found_item != NULL) + { + s_ptr = (struct species *) (found_item->data); + return (s_ptr); + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +struct species * Phreeqc:: +s_store(const char *name, LDBLE l_z, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for species. + * + * Pointer to a species structure is always returned. + * + * If the string is not found, a new entry is made at the end of + * the elements array (position count_elements) and count_elements is + * incremented. A new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old species structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old species structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "species". + * l_z input, charge on "name" + * replace_if_found input, TRUE means reinitialize species if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to species structure "s" where "name" can be found. + */ + int n; + struct species *s_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + item.key = name; + item.data = NULL; + found_item = hsearch_multi(species_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + s_ptr = (struct species *) (found_item->data); + return (s_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + s_ptr = (struct species *) (found_item->data); + s_free(s_ptr); + s_init(s_ptr); + } + else + { + n = count_s++; + /* make sure there is space in s */ + if (count_s >= max_s) + { + space((void **) ((void *) &s), count_s, &max_s, + sizeof(struct species *)); + } + /* Make new species structure */ + s[n] = s_alloc(); + s_ptr = s[n]; + } + /* set name and z in pointer in species structure */ + s_ptr->name = string_hsave(name); + s_ptr->z = l_z; +/* + * Update hash table + */ + item.key = s_ptr->name; + item.data = (void *) s_ptr; + found_item = hsearch_multi(species_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in species_store."); + error_msg(error_string, CONTINUE); + } + + return (s_ptr); +} + +/* ********************************************************************** + * + * Routines related to structure "ss_assemblage" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct ss_assemblage * Phreeqc:: +ss_assemblage_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct ss_assemblage *ss_assemblage_ptr; + ss_assemblage_ptr = + (struct ss_assemblage *) PHRQ_malloc(sizeof(struct ss_assemblage)); + if (ss_assemblage_ptr == NULL) + malloc_error(); + ss_assemblage_ptr->n_user = -1; + ss_assemblage_ptr->n_user_end = -1; + ss_assemblage_ptr->description = NULL; + ss_assemblage_ptr->new_def = 0; + ss_assemblage_ptr->count_s_s = 0; + ss_assemblage_ptr->s_s = NULL; + return (ss_assemblage_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct ss_assemblage * Phreeqc:: +ss_assemblage_bsearch(int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array ss_assemblage to find user number k. + * Assumes ss_assemblage is in sort order. + * + * Input: k, user number to find. + * + * Output: n, position in array ss_assemblage for user number k. + * + * Return: pointer to ss_assemblage structure for user number k, if found. + * NULL if not found. + */ + void *void_ptr; + if (count_ss_assemblage == 0) + { + *n = -999; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) &k, + (char *) ss_assemblage, + (size_t) count_ss_assemblage, + (size_t) sizeof(struct ss_assemblage), + ss_assemblage_compare_int); + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + *n = (int) ((struct ss_assemblage *) void_ptr - ss_assemblage); + return ((struct ss_assemblage *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct ss_assemblage *ss_assemblage_ptr1, *ss_assemblage_ptr2; + ss_assemblage_ptr1 = (const struct ss_assemblage *) ptr1; + ss_assemblage_ptr2 = (const struct ss_assemblage *) ptr2; + if (ss_assemblage_ptr1->n_user > ss_assemblage_ptr2->n_user) + return (1); + if (ss_assemblage_ptr1->n_user < ss_assemblage_ptr2->n_user) + return (-1); + return (0); + +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +ss_assemblage_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare ss_assemblage user numbers + */ + const int *nptr1; + const struct ss_assemblage *nptr2; + + nptr1 = (const int *) ptr1; + nptr2 = (const struct ss_assemblage *) ptr2; + if (*nptr1 > nptr2->n_user) + return (1); + if (*nptr1 < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_copy(struct ss_assemblage *ss_assemblage_old_ptr, + struct ss_assemblage *ss_assemblage_new_ptr, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies ss_assemblage data from ss_assemblage_old_ptr to ss_assemblage_new_ptr. + * Space for a ss_assemblage_new_ptr must already be malloced. + * Space for list of pure phases in assemblage is malloced here. + */ + int i, count_comps, count_s_s; + char token[MAX_LENGTH]; +/* + * Store data for structure ss_assemblage + */ + memcpy(ss_assemblage_new_ptr, ss_assemblage_old_ptr, + sizeof(struct ss_assemblage)); + ss_assemblage_new_ptr->n_user = n_user_new; + ss_assemblage_new_ptr->n_user_end = n_user_new; + sprintf(token, "ss_assemblage defined in simulation %d.", simulation); + ss_assemblage_new_ptr->description = string_duplicate(token); + ss_assemblage_new_ptr->new_def = FALSE; +/* + * Malloc space for s_s structures and fill + */ + count_s_s = ss_assemblage_old_ptr->count_s_s; + ss_assemblage_new_ptr->s_s = + (struct s_s *) PHRQ_malloc((size_t) count_s_s * sizeof(struct s_s)); + if (ss_assemblage_new_ptr->s_s == NULL) + malloc_error(); + memcpy((void *) ss_assemblage_new_ptr->s_s, + (void *) ss_assemblage_old_ptr->s_s, + (size_t) count_s_s * sizeof(struct s_s)); +/* + * Malloc space for components + */ + for (i = 0; i < count_s_s; i++) + { + count_comps = ss_assemblage_old_ptr->s_s[i].count_comps; + ss_assemblage_new_ptr->s_s[i].comps = + (struct s_s_comp *) PHRQ_malloc((size_t) count_comps * + sizeof(struct s_s_comp)); + if (ss_assemblage_new_ptr->s_s[i].comps == NULL) + malloc_error(); + memcpy((void *) ss_assemblage_new_ptr->s_s[i].comps, + (void *) ss_assemblage_old_ptr->s_s[i].comps, + (size_t) count_comps * sizeof(struct s_s_comp)); + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an ss_assemblage definition from position n + * to position count_ss_assemblage. + */ + space((void **) ((void *) &ss_assemblage), count_ss_assemblage, + &max_ss_assemblage, sizeof(struct ss_assemblage)); + ss_assemblage_copy(&ss_assemblage[n], + &ss_assemblage[count_ss_assemblage], n_user); + count_ss_assemblage++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies ss_assemblage[n_user_old] to old n_user_new space if + * found or to ss_assemblage[count_ss_assemblage] if not found. + * ss_assemblage array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct ss_assemblage *ss_assemblage_ptr_old, *ss_assemblage_ptr_new; +/* + * Find n_user_old in structure array ss_assemblage + */ + if (n_user_old == n_user_new) + return (OK); + ss_assemblage_ptr_old = ss_assemblage_bsearch(n_user_old, &n_old); + if (ss_assemblage_ptr_old == NULL) + { + error_string = sformatf( "ss_assemblage %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array ss_assemblage or make new space + */ + sort = FALSE; + ss_assemblage_ptr_new = ss_assemblage_bsearch(n_user_new, &n_new); + if (ss_assemblage_ptr_new != NULL) + { + ss_assemblage_free(ss_assemblage_ptr_new); + } + else + { + space((void **) ((void *) &ss_assemblage), count_ss_assemblage, + &max_ss_assemblage, sizeof(struct ss_assemblage)); + if (n_user_new < ss_assemblage[count_ss_assemblage - 1].n_user) + sort = TRUE; + n_new = count_ss_assemblage++; + } +/* + * Copy data + */ + ss_assemblage_copy(&ss_assemblage[n_old], &ss_assemblage[n_new], + n_user_new); + if (sort == TRUE) + ss_assemblage_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array ss_assemblage. + */ +{ + int i; + int n_old; + struct ss_assemblage *ss_assemblage_ptr_old; +/* + * Find n_user_old in structure array + */ + ss_assemblage_ptr_old = ss_assemblage_bsearch(n_user_old, &n_old); + if (ss_assemblage_ptr_old != NULL) + { + /* + * Delete ss_assemblage + */ + ss_assemblage_free(&ss_assemblage[n_old]); + + for (i = n_old + 1; i < count_ss_assemblage; i++) + { + memcpy((void *) &ss_assemblage[i - 1], + (void *) &ss_assemblage[i], + (size_t) sizeof(struct ss_assemblage)); + } + count_ss_assemblage--; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_free(struct ss_assemblage *ss_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Free space allocated for ss_assemblage structure + */ + int i; + + if (ss_assemblage_ptr == NULL) + return (ERROR); + ss_assemblage_ptr->description = + (char *) free_check_null(ss_assemblage_ptr->description); + for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) + { + ss_assemblage_ptr->s_s[i].comps = + (struct s_s_comp *) free_check_null(ss_assemblage_ptr->s_s[i]. + comps); + } + ss_assemblage_ptr->s_s = + (struct s_s *) free_check_null(ss_assemblage_ptr->s_s); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_init(struct ss_assemblage *ss_assemblage_ptr, int n_user, + int n_user_end, char *description) +/* ---------------------------------------------------------------------- */ +{ + ss_assemblage_ptr->n_user = n_user; + ss_assemblage_ptr->n_user_end = n_user_end; + ss_assemblage_ptr->description = string_duplicate(description); + ss_assemblage_ptr->new_def = TRUE; + ss_assemblage_ptr->count_s_s = 0; + ss_assemblage_ptr->s_s = + (struct s_s *) PHRQ_malloc((size_t) sizeof(struct s_s)); + if (ss_assemblage_ptr->s_s == NULL) + malloc_error(); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_ptr_to_user(struct ss_assemblage *ss_assemblage_ptr_old, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies ss_assemblage_ptr_old to old n_user_new space if + * found or to ss_assemblage[count_ss_assemblage] if not found. + * ss_assemblage array may not be in sort order after the copy. + */ + int n_new, sort; + struct ss_assemblage *ss_assemblage_ptr_new; +/* + * Find n_user_old in structure array ss_assemblage + */ + if (ss_assemblage_ptr_old == NULL) + { + error_string = sformatf( "ss_assemblage pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array ss_assemblage or make new space + */ + sort = FALSE; + ss_assemblage_ptr_new = ss_assemblage_bsearch(n_user_new, &n_new); + if (ss_assemblage_ptr_new == ss_assemblage_ptr_old) + return (OK); + if (ss_assemblage_ptr_new != NULL) + { + ss_assemblage_free(ss_assemblage_ptr_new); + } + else + { + space((void **) ((void *) &ss_assemblage), count_ss_assemblage, + &max_ss_assemblage, sizeof(struct ss_assemblage)); + if (n_user_new < ss_assemblage[count_ss_assemblage - 1].n_user) + sort = TRUE; + n_new = count_ss_assemblage++; + } +/* + * Copy data + */ + ss_assemblage_copy(ss_assemblage_ptr_old, &ss_assemblage[n_new], + n_user_new); + if (sort == TRUE) + ss_assemblage_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct ss_assemblage * Phreeqc:: +ss_assemblage_replicate(struct ss_assemblage *ss_assemblage_old_ptr, + int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct ss_assemblage *ss_assemblage_ptr; + ss_assemblage_ptr = ss_assemblage_alloc(); + ss_assemblage_copy(ss_assemblage_old_ptr, ss_assemblage_ptr, + n_user_new); + return (ss_assemblage_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct ss_assemblage * Phreeqc:: +ss_assemblage_search(int n_user, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "ss_assemblage" for user number n_user. + * + * Arguments: + * n_user input, user number + * n output, position in ss_assemblage + * + * Returns: + * if found, the address of the ss_assemblage element + * if not found, NULL + */ + int i; + for (i = 0; i < count_ss_assemblage; i++) + { + if (ss_assemblage[i].n_user == n_user) + { + *n = i; + return (&(ss_assemblage[i])); + } + } +/* + * ss_assemblage not found + */ + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of ss_assemblage structures + */ + if (count_ss_assemblage > 0) + { + qsort(ss_assemblage, (size_t) count_ss_assemblage, + (size_t) sizeof(struct ss_assemblage), ss_assemblage_compare); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_s_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct s_s *s_s_ptr1, *s_s_ptr2; + s_s_ptr1 = (const struct s_s *) ptr1; + s_s_ptr2 = (const struct s_s *) ptr2; + return (strcmp_nocase(s_s_ptr1->name, s_s_ptr2->name)); + +} + +/* ********************************************************************** + * + * Routines related to structure "save_values" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct save_values * Phreeqc:: +save_values_bsearch(struct save_values *k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search save_values to find if one exists with given coefficients + * Save_Values is assumed to be in sort order by count_subscripts and + * values of subscripts + */ + void *void_ptr; + if (count_save_values == 0) + { + *n = -999; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) k, + (char *) save_values, + (size_t) count_save_values, + (size_t) sizeof(struct save_values), save_values_compare); + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + *n = (int) ((struct save_values *) void_ptr - save_values); + return ((struct save_values *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_values_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct save_values *save_values_ptr1, *save_values_ptr2; + save_values_ptr1 = (const struct save_values *) ptr1; + save_values_ptr2 = (const struct save_values *) ptr2; + if (save_values_ptr1->count_subscripts < + save_values_ptr2->count_subscripts) + { + return (-1); + } + else if (save_values_ptr1->count_subscripts > + save_values_ptr2->count_subscripts) + { + return (1); + } + else + { + for (i = 0; i < save_values_ptr1->count_subscripts; i++) + { + if (save_values_ptr1->subscripts[i] < + save_values_ptr2->subscripts[i]) + { + return (-1); + } + else if (save_values_ptr1->subscripts[i] > + save_values_ptr2->subscripts[i]) + { + return (1); + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_values_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of save_values structures + */ + if (count_save_values > 0) + { + qsort(save_values, (size_t) count_save_values, + (size_t) sizeof(struct save_values), save_values_compare); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +save_values_store(struct save_values *s_v) +/* ---------------------------------------------------------------------- */ +{ +/* + * Look for subscripts + */ + int n, i; + struct save_values *s_v_ptr; + + s_v_ptr = save_values_bsearch(s_v, &n); + if (s_v_ptr != NULL) + { + s_v_ptr->value = s_v->value; + } + else + { + save_values = + (struct save_values *) PHRQ_realloc(save_values, + (size_t) (count_save_values + + 1) * + sizeof(struct save_values)); + if (save_values == NULL) + malloc_error(); + save_values[count_save_values].value = s_v->value; + save_values[count_save_values].count_subscripts = + s_v->count_subscripts; + i = s_v->count_subscripts; + if (i == 0) + i = 1; + save_values[count_save_values].subscripts = + (int *) PHRQ_malloc((size_t) i * sizeof(int)); + if (save_values[count_save_values].subscripts == NULL) + malloc_error(); + save_values[count_save_values].subscripts = + (int *) memcpy(save_values[count_save_values].subscripts, + s_v->subscripts, (size_t) i * sizeof(int)); + count_save_values++; + save_values_sort(); + } + + if (count_save_values > 0) + { + qsort(save_values, (size_t) count_save_values, + (size_t) sizeof(struct save_values), save_values_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "solution" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +conc_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct conc *conc_ptr1, *conc_ptr2; + conc_ptr1 = (const struct conc *) ptr1; + conc_ptr2 = (const struct conc *) ptr2; + return (strcmp_nocase(conc_ptr1->description, conc_ptr2->description)); + +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +conc_init(struct conc *conc_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (conc_ptr == NULL) + return (ERROR); + conc_ptr->description = NULL; + conc_ptr->equation_name = NULL; + conc_ptr->moles = 0; + conc_ptr->input_conc = 0; + conc_ptr->phase = NULL; + conc_ptr->phase_si = 0.0; + conc_ptr->units = NULL; + conc_ptr->n_pe = -1; + conc_ptr->as = NULL; + conc_ptr->gfw = 0.0; + return OK; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +isotope_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int i; + const struct isotope *iso_ptr1, *iso_ptr2; + + iso_ptr1 = (const struct isotope *) ptr1; + iso_ptr2 = (const struct isotope *) ptr2; + i = strcmp_nocase(iso_ptr1->elt_name, iso_ptr2->elt_name); + if (i != 0) + return (i); + if (iso_ptr1->isotope_number < iso_ptr2->isotope_number) + { + return (-1); + } + else if (iso_ptr1->isotope_number > iso_ptr2->isotope_number) + { + return (1); + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +struct solution * Phreeqc:: +solution_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a solution structure + * arguments + * input: none + * return: pointer to a solution structure + */ +{ + int max_mass_balance; + struct solution *solution_ptr; + solution_ptr = (struct solution *) PHRQ_malloc(sizeof(struct solution)); + if (solution_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL + */ + solution_ptr->new_def = TRUE; + solution_ptr->n_user = -1; + solution_ptr->n_user_end = -1; + solution_ptr->description = NULL; + solution_ptr->tc = 0; + solution_ptr->patm = 0; + solution_ptr->ph = 0; + solution_ptr->solution_pe = 0; + solution_ptr->mu = 0; + solution_ptr->ah2o = 0; + solution_ptr->density = 0; + solution_ptr->total_h = 0; + solution_ptr->total_o = 0; + solution_ptr->cb = 0; + solution_ptr->mass_water = 0; + solution_ptr->total_alkalinity = 0; + solution_ptr->units = NULL; +/* + * Initial allocation of space for pe's + */ + solution_ptr->pe = pe_data_alloc(); + solution_ptr->default_pe = 0; +/* + * Initial allocation of space for totals + */ + max_mass_balance = MAX_MASS_BALANCE; + space((void **) ((void *) &(solution_ptr->totals)), INIT, + &max_mass_balance, sizeof(struct conc)); + solution_ptr->totals[0].description = NULL; +/* + * Master activities + */ + space((void **) ((void *) &(solution_ptr->master_activity)), INIT, + &max_mass_balance, sizeof(struct master_activity)); + solution_ptr->master_activity[0].description = NULL; +/* + * Initial allocation of space for isotopes + */ + solution_ptr->isotopes = + (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); + if (solution_ptr->isotopes == NULL) + malloc_error(); + solution_ptr->count_isotopes = 0; +/* + * Initial allocation of space for species_gamma + */ + solution_ptr->species_gamma = NULL; + solution_ptr->count_species_gamma = 0; + + return (solution_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct solution * Phreeqc:: +solution_bsearch(int k, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of solution solution array to find user number k. + * Assumes array solution is in sort order. + * + * Input: k user number to find. + * print, TRUE print warning if solution not found. + * Output: n, position of solution ptr in solution array. + * Return: pointer to solution structure if found + * NULL if not found. + */ + void *void_ptr; + void_ptr = NULL; + if (count_solution > 0) + { + void_ptr = (void *) + bsearch((char *) &k, + (char *) solution, + (size_t) count_solution, + (size_t) sizeof(struct solution *), solution_compare_int); + } + if (void_ptr == NULL && print == TRUE) + { + error_string = sformatf( "Solution %d not found.", k); + error_msg(error_string, CONTINUE); + } + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + + *n = (int) ((struct solution **) void_ptr - solution); + return (*(struct solution **) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare solution user numbers + */ + const struct solution *nptr1; + const struct solution *nptr2; + + nptr1 = *(const struct solution **) ptr1; + nptr2 = *(const struct solution **) ptr2; + if (nptr1->n_user > nptr2->n_user) + return (1); + if (nptr1->n_user < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare solution user number to an integer + */ + const int *nptr1; + const struct solution *nptr2; + + nptr1 = (const int *) ptr1; + nptr2 = *(const struct solution **) ptr2; + if (*nptr1 > nptr2->n_user) + return (1); + if (*nptr1 < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +struct solution * Phreeqc:: +solution_copy(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies solution data to new structure. + * Space for new structure is malloced here. + * + * Input: solution_old_ptr, pointer to structure to be copied. + * n_user_new, user number to give to the new solution. + * + * Return: pointer to new solution structure. + */ + int i; + int count_totals, count_master_activity; + struct solution *solution_new_ptr; +/* + * malloc space for new solution structure + */ + solution_new_ptr = + (struct solution *) PHRQ_malloc(sizeof(struct solution)); + if (solution_new_ptr == NULL) + malloc_error(); +/* + * Copy solution data, but set pointers pe and totals to NULL + */ + memcpy((void *) solution_new_ptr, (void *) solution_old_ptr, + (size_t) sizeof(struct solution)); + solution_new_ptr->n_user = n_user_new; + solution_new_ptr->n_user_end = n_user_new; + solution_new_ptr->description = + string_duplicate(solution_old_ptr->description); +/* + * Count totals data and malloc space + */ + for (i = 0; solution_old_ptr->totals[i].description != NULL; i++); + count_totals = i + 1; + solution_new_ptr->totals = + (struct conc *) PHRQ_malloc((size_t) count_totals * + sizeof(struct conc)); + if (solution_new_ptr->totals == NULL) + malloc_error(); +/* + * Copy totals data + */ + memcpy((void *) solution_new_ptr->totals, + (void *) solution_old_ptr->totals, + (size_t) count_totals * sizeof(struct conc)); +/* + * Count master activity guesses and malloc space + */ + count_master_activity = solution_old_ptr->count_master_activity; + solution_new_ptr->master_activity = + (struct master_activity *) PHRQ_malloc((size_t) count_master_activity + * + sizeof(struct + master_activity)); + if (solution_new_ptr->master_activity == NULL) + malloc_error(); +/* + * Copy master activity guesses + */ + memcpy((void *) solution_new_ptr->master_activity, + (void *) solution_old_ptr->master_activity, + (size_t) count_master_activity * sizeof(struct master_activity)); +/* + * malloc space for species gammas + */ + if (solution_old_ptr->count_species_gamma > 0) + { + solution_new_ptr->species_gamma = + (struct master_activity *) PHRQ_malloc((size_t) + solution_old_ptr-> + count_species_gamma * + sizeof(struct + master_activity)); + if (solution_new_ptr->species_gamma == NULL) + malloc_error(); + /* + * Copy species gammas + */ + memcpy((void *) solution_new_ptr->species_gamma, + (void *) solution_old_ptr->species_gamma, + (size_t) solution_old_ptr->count_species_gamma * + sizeof(struct master_activity)); + solution_new_ptr->count_species_gamma = + solution_old_ptr->count_species_gamma; + } + else + { + solution_new_ptr->species_gamma = NULL; + solution_new_ptr->count_species_gamma = 0; + } +/* + * Copy pe data + */ + solution_new_ptr->pe = pe_data_dup(solution_old_ptr->pe); +/* + * Malloc and copy isotope data + */ + if (solution_old_ptr->count_isotopes > 0) + { + solution_new_ptr->count_isotopes = solution_old_ptr->count_isotopes; + solution_new_ptr->isotopes = + (struct isotope *) PHRQ_malloc((size_t) solution_old_ptr-> + count_isotopes * + sizeof(struct isotope)); + if (solution_new_ptr->isotopes == NULL) + malloc_error(); + memcpy(solution_new_ptr->isotopes, solution_old_ptr->isotopes, + (size_t) solution_old_ptr->count_isotopes * + sizeof(struct isotope)); + } + else + { + solution_new_ptr->count_isotopes = 0; + solution_new_ptr->isotopes = NULL; + } +/* + * Return pointer to new structure + */ + return (solution_new_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_copy_to_last(int n, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies solution from pointer solution[n]. Makes new structure + * and saves pointer in solution[count_solution]. + */ + /* Make sure solution array is large enough */ + if (count_solution + 1 >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } + /* malloc space and copy solution */ + solution[count_solution] = solution_copy(solution[n], n_user_new); + count_solution++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees structure if it does + * Copies structure for solution[n_user_old] to new space + * Saves pointer in old position if it existed, no sort necessary + * Otherwise saves in count_solution position, sort may be necessary + * Solution array is in sort order on exit + */ + int n, n_old, n_new, sort; + struct solution *solution_old_ptr, *solution_new_ptr; +/* + * Find solution n_user_old + */ + if (n_user_old == n_user_new) + return (OK); + solution_old_ptr = solution_bsearch(n_user_old, &n_old, TRUE); + if (solution_old_ptr == NULL) + { + error_string = sformatf( "Solution %d not found.", n_user_old); + error_msg(error_string, STOP); + } +/* + * Check if solution n_user_new already exists + */ + solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); + if (solution_new_ptr != NULL) + { + n = n_new; + solution_free(solution_new_ptr); + sort = FALSE; + } + else + { + n = count_solution; + count_solution++; + if (n_user_new > solution[n - 1]->n_user) + { + sort = FALSE; + } + else + { + sort = TRUE; + } + } + solution[n] = solution_copy(solution_old_ptr, n_user_new); +/* + * Make sure surface array is large enough + */ + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } +/* + * Sort solution if necessary + */ + if (sort == TRUE) + solution_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_delete(int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete a solution structure: free memory and renumber solution. + */ + struct solution *solution_ptr; + int j, n; + solution_ptr = solution_bsearch(n_user, &n, FALSE); + if (solution_ptr != NULL) + { + solution_free(solution[n]); + for (j = n; j < (count_solution - 1); j++) + { + solution[j] = solution[j + 1]; + } + count_solution--; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_delete_n(int n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete a solution structure: free memory and renumber solution. + */ + int j; + if (n >= 0 && n < count_solution) + { + solution_free(solution[n]); + for (j = n; j < (count_solution - 1); j++) + { + solution[j] = solution[j + 1]; + } + count_solution--; + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_free(struct solution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (solution_ptr == NULL) + return (OK); +/* + * Free all memory unique to a solution structure, free solution_ptr too. + */ + solution_ptr->description = + (char *) free_check_null(solution_ptr->description); +/* Free struct conc array */ + solution_ptr->totals = + (struct conc *) free_check_null(solution_ptr->totals); + solution_ptr->master_activity = + (struct master_activity *) free_check_null(solution_ptr-> + master_activity); + solution_ptr->species_gamma = + (struct master_activity *) free_check_null(solution_ptr-> + species_gamma); + solution_ptr->count_species_gamma = 0; +/* Free struct pe_data array */ + pe_data_free(solution_ptr->pe); +/* Free isotope data */ + solution_ptr->isotopes = + (struct isotope *) free_check_null(solution_ptr->isotopes); +/* Free struct solution */ + solution_ptr = (struct solution *) free_check_null(solution_ptr); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees structure if it does + * Copies structure for solution[n_user_old] to new space + * Saves pointer in old position if it existed, no sort necessary + * Otherwise saves in count_solution position, sort may be necessary + * Solution array is in sort order on exit + */ + int n, n_new, sort; + struct solution *solution_new_ptr; +/* + * Find solution n_user_old + */ + if (solution_old_ptr == NULL) + { + error_string = sformatf( "Solution pointer is NULL."); + error_msg(error_string, STOP); + } +/* + * Check if solution n_user_new already exists + */ + solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); + if (solution_new_ptr == solution_old_ptr) + return (OK); + if (solution_new_ptr != NULL) + { + n = n_new; + solution_free(solution_new_ptr); + sort = FALSE; + } + else + { + n = count_solution; + count_solution++; + /* + * Make sure surface array is large enough + */ + if (count_solution >= max_solution) + { + space((void **) ((void *) &(solution)), count_solution, + &max_solution, sizeof(struct solution *)); + } + if (n_user_new > solution[n - 1]->n_user) + { + sort = FALSE; + } + else + { + sort = TRUE; + } + } + solution[n] = solution_copy(solution_old_ptr, n_user_new); +/* + * Sort solution if necessary + */ + if (sort == TRUE) + solution_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct solution * Phreeqc:: +solution_replicate(struct solution *solution_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + return (solution_copy(solution_old_ptr, n_user_new)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of pointers to solution structures, solution. + */ + if (count_solution > 0) + { + qsort(solution, + (size_t) count_solution, + (size_t) sizeof(struct solution *), solution_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "species_list" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +species_list_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + int j; + const char *name1, *name2; + const struct species_list *nptr1, *nptr2; + + nptr1 = (const struct species_list *) ptr1; + nptr2 = (const struct species_list *) ptr2; + +/* + * Put H+ first + */ + if (nptr1->master_s != nptr2->master_s) + { + /* + if (nptr1->master_s == s_hplus) + return (-1); + if (nptr2->master_s == s_hplus) + return (1); + */ + if ((strcmp(nptr1->master_s->name,"H+") == 0) || (strcmp(nptr1->master_s->name,"H3O+") == 0)) + return (-1); + if ((strcmp(nptr2->master_s->name,"H+") == 0) || (strcmp(nptr2->master_s->name,"H3O+") == 0)) + return (1); + } +/* + * Other element valence states + */ + if (nptr1->master_s->secondary != NULL) + { + name1 = nptr1->master_s->secondary->elt->name; + } + else + { + name1 = nptr1->master_s->primary->elt->name; + } + if (nptr2->master_s->secondary != NULL) + { + name2 = nptr2->master_s->secondary->elt->name; + } + else + { + name2 = nptr2->master_s->primary->elt->name; + } +/* + * Compare name of primary or secondary master species; log molality + */ + + j = strcmp(name1, name2); + +/* + * Different master species + */ + if (j != 0) + return (j); + +/* + * Else, descending order by log molality + */ + if (nptr1->s->lm > nptr2->s->lm) + { + return (-1); + } + else if (nptr1->s->lm < nptr2->s->lm) + { + return (1); + } + else + { + return (0); + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +species_list_compare_alk(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct species_list *nptr1, *nptr2; + LDBLE alk1, alk2; + + nptr1 = (const struct species_list *) ptr1; + nptr2 = (const struct species_list *) ptr2; +/* + * Else, descending order by log molality + */ + alk1 = fabs(under(nptr1->s->lm) * nptr1->s->alk); + alk2 = fabs(under(nptr2->s->lm) * nptr2->s->alk); + + if (alk1 > alk2) + { + return (-1); + } + else if (alk1 < alk2) + { + return (1); + } + else + { + return (0); + } +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +species_list_compare_master(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const char *name1, *name2; + const struct species_list *nptr1, *nptr2; + + nptr1 = (const struct species_list *) ptr1; + nptr2 = (const struct species_list *) ptr2; + +/* + * Put H+ first + */ + if (nptr1->master_s != nptr2->master_s) + { + /* + if (nptr1->master_s == s_hplus) + return (-1); + if (nptr2->master_s == s_hplus) + return (1); + */ + if ((strcmp(nptr1->master_s->name,"H+") == 0) || (strcmp(nptr1->master_s->name,"H3O+") == 0)) + return (-1); + if ((strcmp(nptr2->master_s->name,"H+") == 0) || (strcmp(nptr2->master_s->name,"H3O+") == 0)) + return (1); + } +/* + * Other element valence states + */ + if (nptr1->master_s->secondary != NULL) + { + name1 = nptr1->master_s->secondary->elt->name; + } + else + { + name1 = nptr1->master_s->primary->elt->name; + } + if (nptr2->master_s->secondary != NULL) + { + name2 = nptr2->master_s->secondary->elt->name; + } + else + { + name2 = nptr2->master_s->primary->elt->name; + } +/* + * Compare name of primary or secondary master species; log molality + */ + + return (strcmp(name1, name2)); +} + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +species_list_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort list using rules in species_list_compare + */ + if (count_species_list > 0) + { + qsort(&species_list[0], (size_t) count_species_list, + (size_t) sizeof(struct species_list), species_list_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "surface" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct Change_Surf * Phreeqc:: +change_surf_alloc(int count) +/* ---------------------------------------------------------------------- */ +{ + if (count == 1) + return (change_surf); + change_surf = + (struct Change_Surf *) PHRQ_realloc(change_surf, + (size_t) count * + sizeof(struct Change_Surf)); + if (change_surf == NULL) + malloc_error(); + change_surf[count - 1].cell_no = -99; + change_surf[count - 1].next = FALSE; + change_surf[count - 2].next = TRUE; + + return (change_surf); +} + +/* ---------------------------------------------------------------------- */ +struct surface * Phreeqc:: +surface_alloc(void) +/* ---------------------------------------------------------------------- */ +{ + struct surface *surface_ptr; + surface_ptr = (struct surface *) PHRQ_malloc(sizeof(struct surface)); + if (surface_ptr == NULL) + malloc_error(); + surface_ptr->n_user = -1; + surface_ptr->n_user_end = -1; + surface_ptr->new_def = 0; + surface_ptr->only_counter_ions = 0; + surface_ptr->dl_type = BORKOVEK_DL; + surface_ptr->type = UNKNOWN_DL; + surface_ptr->sites_units = SITES_ABSOLUTE; + surface_ptr->thickness = 0; + surface_ptr->debye_lengths = 0; + surface_ptr->DDL_viscosity = 0; /* viscosity relative to pure water */ + surface_ptr->DDL_limit = 0; /* limits DDL water to this fraction of bulk water */ + surface_ptr->description = NULL; + surface_ptr->solution_equilibria = 0; + surface_ptr->n_solution = 0; + surface_ptr->count_comps = 0; + surface_ptr->comps = NULL; + surface_ptr->count_charge = 0; + surface_ptr->charge = NULL; + surface_ptr->related_phases = 0; + surface_ptr->related_rate = 0; + surface_ptr->transport = 0; /* transports comp's and charges if true */ + return (surface_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct surface * Phreeqc:: +surface_bsearch(int k, int *n) +/* ---------------------------------------------------------------------- */ +{ +/* + * Binary search of array surface to find user number k. + * Assumes array surface is in sort order. + * + * Input: k, user number to find. + * Output: n, position in array surface of user number k. + * Return: pointer to surface structure if found, + * NULL if not found. + */ + void *void_ptr; + if (count_surface == 0) + { + *n = -999; + return (NULL); + } + void_ptr = (void *) + bsearch((char *) &k, + (char *) surface, + (size_t) count_surface, + (size_t) sizeof(struct surface), surface_compare_int); + if (void_ptr == NULL) + { + *n = -999; + return (NULL); + } + *n = (int) ((struct surface *) void_ptr - surface); + return ((struct surface *) void_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct master * Phreeqc:: +surface_get_psi_master(const char *name, int plane) +/* ---------------------------------------------------------------------- */ +{ + struct master *master_ptr; + char token[MAX_LENGTH]; + + if (name == NULL) + return (NULL); + strcpy(token, name); + strcat(token, "_psi"); + switch (plane) + { + case SURF_PSI: + break; + case SURF_PSI1: + strcat(token, "b"); + break; + case SURF_PSI2: + strcat(token, "d"); + break; + default: + error_msg("Unknown plane for surface_get_psi_master", STOP); + } + master_ptr = master_bsearch(token); + return (master_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_comp_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct surface_comp *surface_comp_ptr1, *surface_comp_ptr2; + surface_comp_ptr1 = (const struct surface_comp *) ptr1; + surface_comp_ptr2 = (const struct surface_comp *) ptr2; + return (strcmp_nocase + (surface_comp_ptr1->master->elt->name, + surface_comp_ptr2->master->elt->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_charge_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct surface_charge *surface_charge_ptr1, *surface_charge_ptr2; + surface_charge_ptr1 = (const struct surface_charge *) ptr1; + surface_charge_ptr2 = (const struct surface_charge *) ptr2; + return (strcmp_nocase + (surface_charge_ptr1->name, surface_charge_ptr2->name)); +} + + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct surface *surface_ptr1, *surface_ptr2; + surface_ptr1 = (const struct surface *) ptr1; + surface_ptr2 = (const struct surface *) ptr2; + if (surface_ptr1->n_user > surface_ptr2->n_user) + return (1); + if (surface_ptr1->n_user < surface_ptr2->n_user) + return (-1); + return (0); + +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +surface_compare_int(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare surface user numbers to integer + */ + const int *nptr1; + const struct surface *nptr2; + + nptr1 = (const int *) ptr1; + nptr2 = (const struct surface *) ptr2; + if (*nptr1 > nptr2->n_user) + return (1); + if (*nptr1 < nptr2->n_user) + return (-1); + return (0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_copy(struct surface *surface_old_ptr, + struct surface *surface_new_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies data from surface_old_ptr to surface_new_ptr. + * Space for a surface structure must already be malloced. + * User number of new surface structure is n_user. + */ + int count_comps, count_charge, i; + char token[MAX_LENGTH]; +/* + * Store data for structure surface + */ + memcpy(surface_new_ptr, surface_old_ptr, sizeof(struct surface)); + count_comps = surface_old_ptr->count_comps; + count_charge = surface_old_ptr->count_charge; + surface_new_ptr->n_user = n_user_new; + surface_new_ptr->n_user_end = n_user_new; + surface_new_ptr->new_def = surface_old_ptr->new_def; + sprintf(token, "Surface defined in simulation %d.", simulation); + surface_new_ptr->description = string_duplicate(token); + surface_new_ptr->solution_equilibria = FALSE; + surface_new_ptr->n_solution = -10; +/* + * Write surface_comp structure for each surface component + */ + surface_new_ptr->comps = + (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * + sizeof(struct surface_comp)); + if (surface_new_ptr->comps == NULL) + malloc_error(); + memcpy(surface_new_ptr->comps, surface_old_ptr->comps, + (size_t) (count_comps) * sizeof(struct surface_comp)); + for (i = 0; i < count_comps; i++) + { + surface_new_ptr->comps[i].formula_totals = + elt_list_dup(surface_old_ptr->comps[i].formula_totals); + surface_new_ptr->comps[i].totals = + elt_list_dup(surface_old_ptr->comps[i].totals); + } +/* + * Write surface_charge structure for each surface + */ + /*if (surface_old_ptr->edl == TRUE) { */ + if (surface_old_ptr->type == DDL || surface_old_ptr->type == CD_MUSIC) + { + surface_new_ptr->charge = + (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * + sizeof(struct + surface_charge)); + if (surface_new_ptr->charge == NULL) + malloc_error(); + memcpy(surface_new_ptr->charge, surface_old_ptr->charge, + (size_t) (count_charge) * sizeof(struct surface_charge)); + for (i = 0; i < count_charge; i++) + { + surface_new_ptr->charge[i].diffuse_layer_totals = + elt_list_dup(surface_old_ptr->charge[i].diffuse_layer_totals); + surface_new_ptr->charge[i].g = NULL; + } + } + else + { + surface_new_ptr->count_charge = 0; + surface_new_ptr->charge = NULL; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct surface_charge * Phreeqc:: +surface_charge_duplicate(struct surface_charge *charge_old_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Duplicates data from surface_old_ptr + * Space is malloced. + */ + struct surface_charge *charge; +/* + * Write surface_charge structure for each surface + */ + charge = + (struct surface_charge *) PHRQ_malloc(sizeof(struct surface_charge)); + if (charge == NULL) + malloc_error(); + memcpy(charge, charge_old_ptr, sizeof(struct surface_charge)); + charge->diffuse_layer_totals = + elt_list_dup(charge_old_ptr->diffuse_layer_totals); + charge->count_g = 0; + charge->g = NULL; + return (charge); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_charge_free(struct surface_charge *charge) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all space related to surface_charge + */ + if (charge == NULL) + return (ERROR); + charge->diffuse_layer_totals = + (struct elt_list *) free_check_null(charge->diffuse_layer_totals); + charge->g = (struct surface_diff_layer *) free_check_null(charge->g); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_copy_to_last(int n, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies an surface definition to position count_surface. + */ + space((void **) ((void *) &surface), count_surface, &max_surface, + sizeof(struct surface)); + surface_copy(&surface[n], &surface[count_surface], n_user); + count_surface++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_duplicate(int n_user_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies surface[n_user_old] to old n_user_new space if + * found or to surface[count_surface] if not found. + * Surface array may not be in sort order after the copy. + */ + int n_old, n_new, sort; + struct surface *surface_ptr_old, *surface_ptr_new; +/* + * Find n_user_old in structure array surface + */ + if (n_user_old == n_user_new) + return (OK); + surface_ptr_old = surface_bsearch(n_user_old, &n_old); + if (surface_ptr_old == NULL) + { + error_string = sformatf( "Surface %d not found.", n_user_old); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array surface or make new space + */ + sort = FALSE; + surface_ptr_new = surface_bsearch(n_user_new, &n_new); + if (surface_ptr_new != NULL) + { + surface_free(surface_ptr_new); + } + else + { + space((void **) ((void *) &surface), count_surface, &max_surface, + sizeof(struct surface)); + if (n_user_new < surface[count_surface - 1].n_user) + sort = TRUE; + n_new = count_surface++; + } +/* + * Copy data + */ + surface_copy(&surface[n_old], &surface[n_new], n_user_new); + if (sort == TRUE) + surface_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_delete(int n_user_old) +/* ---------------------------------------------------------------------- */ +/* + * Frees space for user number n_user_old, removes structure from + * array surface. + */ +{ + int i; + int n_old; + struct surface *surface_ptr_old; +/* + * Find n_user_old in structure array + */ + surface_ptr_old = surface_bsearch(n_user_old, &n_old); + if (surface_ptr_old != NULL) + { + /* + * Delete surface + */ + surface_free(&surface[n_old]); + + for (i = n_old + 1; i < count_surface; i++) + { + memcpy((void *) &surface[i - 1], (void *) &surface[i], + (size_t) sizeof(struct surface)); + } + count_surface--; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_free(struct surface *surface_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees all space related to surface_ptr, but not surface_ptr. + */ + int k; + + if (surface_ptr == NULL) + return (ERROR); + surface_ptr->description = + (char *) free_check_null(surface_ptr->description); +/* + * totals, then comps + */ + for (k = 0; k < surface_ptr->count_comps; k++) + { + surface_ptr->comps[k].formula_totals = + (struct elt_list *) free_check_null(surface_ptr->comps[k]. + formula_totals); + surface_ptr->comps[k].totals = + (struct elt_list *) free_check_null(surface_ptr->comps[k].totals); + } + surface_ptr->comps = + (struct surface_comp *) free_check_null(surface_ptr->comps); +/* + * diffuse_layer_totals and g, then charge + */ + /*if (surface_ptr->edl == TRUE) { */ + if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + { + for (k = 0; k < surface_ptr->count_charge; k++) + { + surface_ptr->charge[k].diffuse_layer_totals = + (struct elt_list *) free_check_null(surface_ptr->charge[k]. + diffuse_layer_totals); + surface_ptr->charge[k].g = + (struct surface_diff_layer *) free_check_null(surface_ptr-> + charge[k].g); + } + } + surface_ptr->charge = + (struct surface_charge *) free_check_null(surface_ptr->charge); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_init(struct surface *surface_ptr, int n_user, int n_user_end, + char *description) +/* ---------------------------------------------------------------------- */ +{ + + if (surface_ptr == NULL) + return (ERROR); + + surface_ptr->n_user = n_user; + surface_ptr->n_user_end = n_user_end; + surface_ptr->new_def = TRUE; + surface_ptr->dl_type = NO_DL; + surface_ptr->sites_units = SITES_ABSOLUTE; + /*surface_ptr->edl = TRUE; */ + surface_ptr->type = DDL; + surface_ptr->only_counter_ions = FALSE; + /*surface_ptr->donnan = FALSE; */ + surface_ptr->thickness = 1e-8; + surface_ptr->debye_lengths = 0.0; + surface_ptr->DDL_viscosity = 1.0; + surface_ptr->DDL_limit = 0.8; + surface_ptr->description = string_duplicate(description); + surface_ptr->solution_equilibria = FALSE; + surface_ptr->n_solution = -999; + surface_ptr->transport = FALSE; +/* + * Malloc one surface_comp structure + */ + surface_ptr->count_comps = 0; + surface_ptr->comps = + (struct surface_comp *) PHRQ_malloc((size_t) + sizeof(struct surface_comp)); + if (surface_ptr->comps == NULL) + malloc_error(); + surface_ptr->comps[0].master = NULL; + surface_ptr->comps[0].totals = NULL; + surface_ptr->comps[0].phase_name = NULL; + surface_ptr->comps[0].rate_name = NULL; + surface_ptr->comps[0].charge = -1; + surface_ptr->comps[0].moles = 0; + surface_ptr->comps[0].cb = 0; + surface_ptr->comps[0].Dw = 0; +/* + * Malloc one charge structure + */ + surface_ptr->count_charge = 0; + surface_ptr->charge = + (struct surface_charge *) PHRQ_malloc((size_t) + sizeof(struct surface_charge)); + if (surface_ptr->charge == NULL) + malloc_error(); + + surface_ptr->related_phases = FALSE; + surface_ptr->related_rate = FALSE; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks if n_user_new exists, and frees space if it does + * Copies surface_ptr_old to old n_user_new space if + * found or to surface[count_surface] if not found. + * Surface array may not be in sort order after the copy. + */ + int n_new, sort; + struct surface *surface_ptr_new; +/* + * Find n_user_old in structure array surface + */ + if (surface_ptr_old == NULL) + { + error_string = sformatf( "Surface pointer is NULL."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } +/* + * Find n_user_new in structure array surface or make new space + */ + sort = FALSE; + surface_ptr_new = surface_bsearch(n_user_new, &n_new); + if (surface_ptr_new == surface_ptr_old) + return (OK); + if (surface_ptr_new != NULL) + { + surface_free(surface_ptr_new); + } + else + { + space((void **) ((void *) &surface), count_surface, &max_surface, + sizeof(struct surface)); + if (n_user_new < surface[count_surface - 1].n_user) + sort = TRUE; + n_new = count_surface++; + } +/* + * Copy data + */ + surface_copy(surface_ptr_old, &surface[n_new], n_user_new); + if (sort == TRUE) + surface_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct surface * Phreeqc:: +surface_replicate(struct surface *surface_old_ptr, int n_user_new) +/* ---------------------------------------------------------------------- */ +{ + struct surface *surface_ptr; + surface_ptr = surface_alloc(); + surface_copy(surface_old_ptr, surface_ptr, n_user_new); + return (surface_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct surface * Phreeqc:: +surface_search(int n_user, int *n, int print) +/* ---------------------------------------------------------------------- */ +{ +/* Linear search of the structure array "surface" for user number n_user. + * + * Arguments: + * n_user input, user number. + * n output, position in surface. + * + * Returns: + * if found, pointer to surface structure + * if not found, NULL + */ + int i; + for (i = 0; i < count_surface; i++) + { + if (n_user == surface[i].n_user) + { + break; + } + } + if (i >= count_surface) + { + if (print == TRUE) + { + error_string = sformatf( "Surface %d not found.", n_user); + error_msg(error_string, CONTINUE); + } + *n = -999; + return (NULL); + } + *n = i; + return (&surface[i]); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +surface_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Sort array of surface structures + */ + if (count_surface > 0) + { + qsort(surface, (size_t) count_surface, + (size_t) sizeof(struct surface), surface_compare); + } + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "trxn" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rxn_token_temp_compare(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct rxn_token_temp *rxn_token_temp_ptr1, *rxn_token_temp_ptr2; + rxn_token_temp_ptr1 = (const struct rxn_token_temp *) ptr1; + rxn_token_temp_ptr2 = (const struct rxn_token_temp *) ptr2; + return (strcmp(rxn_token_temp_ptr1->name, rxn_token_temp_ptr2->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_add(struct reaction *r_ptr, LDBLE coef, int combine) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds reactions together. + * + * Global variable count_trxn determines which position in trxn is used. + * If count_trxn=0, then the equation effectively is copied into trxn. + * If count_trxn>0, then new equation is added to existing equation. + * + * Arguments: + * *r_ptr points to rxn structure to add. + * + * coef added equation is multiplied by coef. + * combine if TRUE, reaction is reaction is sorted and + * like terms combined. + */ + int i; + struct rxn_token *next_token; +/* + * Accumulate log k for reaction + */ + if (count_trxn == 0) + { + memcpy((void *) trxn.logk, (void *) r_ptr->logk, + (size_t) MAX_LOG_K_INDICES * sizeof(LDBLE)); + for (i = 0; i < 3; i++) + { + trxn.dz[i] = r_ptr->dz[i]; + } + } + else + { + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] += coef * (r_ptr->logk[i]); + } + for (i = 0; i < 3; i++) + { + trxn.dz[i] += coef * r_ptr->dz[i]; + } + } +/* + * Copy equation into work space + */ + next_token = r_ptr->token; + while (next_token->s != NULL) + { + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, + &max_trxn, sizeof(struct rxn_token_temp)); + } + trxn.token[count_trxn].name = next_token->s->name; + trxn.token[count_trxn].s = next_token->s; + trxn.token[count_trxn].coef = coef * next_token->coef; + count_trxn++; + next_token++; + } + if (combine == TRUE) + trxn_combine(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds reactions together. + * + * Global variable count_trxn determines which position in trxn is used. + * If count_trxn=0, then the equation effectively is copied into trxn. + * If count_trxn>0, then new equation is added to existing equation. + * + * Arguments: + * *r_ptr points to rxn structure to add. + * + * coef added equation is multiplied by coef. + * combine if TRUE, reaction is reaction is sorted and + * like terms combined. + */ + int i; + struct rxn_token *next_token; +/* + * Accumulate log k for reaction + */ + if (count_trxn == 0) + { + memcpy((void *) trxn.logk, (void *) r_ptr->logk, + (size_t) MAX_LOG_K_INDICES * sizeof(LDBLE)); + } + else + { + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] += coef * (r_ptr->logk[i]); + } + } +/* + * Copy equation into work space + */ + next_token = r_ptr->token; + while (next_token->s != NULL || next_token->name != NULL) + { + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, + &max_trxn, sizeof(struct rxn_token_temp)); + } + if (next_token->s != NULL) + { + trxn.token[count_trxn].name = next_token->s->name; + trxn.token[count_trxn].s = next_token->s; + } + else + { + trxn.token[count_trxn].name = next_token->name; + trxn.token[count_trxn].s = NULL; + } + trxn.token[count_trxn].coef = coef * next_token->coef; + count_trxn++; + next_token++; + } + if (combine == TRUE) + trxn_combine(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_combine(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Combines coefficients of tokens that are equal in temporary + * reaction structure, trxn. + */ + int j, k; +/* + * Sort trxn species + */ + trxn_sort(); +/* + * Combine trxn tokens + */ + j = 1; + for (k = 2; k < count_trxn; k++) + { + if (trxn.token[k].s != NULL) + { + if ((j > 0) && (trxn.token[k].s == trxn.token[j].s)) + { + trxn.token[j].coef += trxn.token[k].coef; + if (equal(trxn.token[j].coef, 0.0, 1e-5)) + j--; + } + else + { + j++; + if (k != j) + { + trxn.token[j].name = trxn.token[k].name; + trxn.token[j].s = trxn.token[k].s; + trxn.token[j].coef = trxn.token[k].coef; + } + } + } + else + { + if ((j > 0) && (trxn.token[k].s == trxn.token[j].s) + && (trxn.token[k].name == trxn.token[j].name)) + { + trxn.token[j].coef += trxn.token[k].coef; + if (equal(trxn.token[j].coef, 0.0, 1e-5)) + j--; + } + else + { + j++; + if (k != j) + { + trxn.token[j].name = trxn.token[k].name; + trxn.token[j].s = trxn.token[k].s; + trxn.token[j].coef = trxn.token[k].coef; + } + } + } + } + count_trxn = j + 1; /* number excluding final NULL */ + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_copy(struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies trxn to a reaction structure. + * + * Input: rxn_ptr, pointer to reaction structure to copy trxn to. + * + */ + int i; +/* + * Copy logk data + */ + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + rxn_ptr->logk[i] = trxn.logk[i]; + } +/* + * Copy dz data + */ + for (i = 0; i < 3; i++) + { + rxn_ptr->dz[i] = trxn.dz[i]; + } +/* + * Copy tokens + */ + for (i = 0; i < count_trxn; i++) + { + rxn_ptr->token[i].s = trxn.token[i].s; + rxn_ptr->token[i].name = trxn.token[i].name; + rxn_ptr->token[i].coef = trxn.token[i].coef; + } + rxn_ptr->token[count_trxn].s = NULL; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +trxn_find_coef(const char *str, int start) +/* ---------------------------------------------------------------------- */ +{ +/* + * Finds coefficient of specified token in trxn. + * Input: str, token name in reaction. + * + * Return: 0.0, if token not found. + * coefficient of token, if token found. + */ + int i; + LDBLE coef; + + coef = 0.0; + for (i = start; i < count_trxn; i++) + { + if (strcmp(trxn.token[i].s->name, str) == 0) + { + coef = trxn.token[i].coef; + break; + } + } + return (coef); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_multiply(LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ +/* + * Multiplies temporary reaction, trxn, by a constant + * + * Arguments: + * input: coef multiplier. + */ + int i; +/* + * Multiply log k for reaction + */ + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] *= coef; + } +/* + * Multiply dz for reaction + */ + for (i = 0; i < 3; i++) + { + trxn.dz[i] *= coef; + } +/* + * Multiply coefficients of reaction + */ + for (i = 0; i < count_trxn; i++) + { + trxn.token[i].coef *= coef; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Prints trxn + */ + int i; +/* + * Print log k for reaction + */ + + output_msg(sformatf( "\tlog k data:\n")); + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + output_msg(sformatf( "\t\t%f\n", (double) trxn.logk[i])); + } + +/* + * Print dz for reaction + */ + output_msg(sformatf( "\tdz data:\n")); + for (i = 0; i < 3; i++) + { + output_msg(sformatf( "\t\t%f\n", (double) trxn.dz[i])); + } +/* + * Print stoichiometry + */ + output_msg(sformatf( "\tReaction stoichiometry\n")); + for (i = 0; i < count_trxn; i++) + { + output_msg(sformatf( "\t\t%-20s\t%10.2f\n", trxn.token[i].name, + (double) trxn.token[i].coef)); + } + output_msg(sformatf( "\n")); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_reverse_k(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Changes K from dissociation to association and back + */ + int i; +/* + * Accumulate log k for reaction + */ + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] = -trxn.logk[i]; + } + for (i = 0; i < 3; i++) + { + trxn.dz[i] = -trxn.dz[i]; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_sort(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare names in tokens in trxn array for sorting + */ + if (count_trxn - 1 > 0) + { + qsort(&trxn.token[1], + (size_t) count_trxn - 1, + (size_t) sizeof(struct rxn_token_temp), rxn_token_temp_compare); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_swap(const char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Moves specified token to initial position in reaction. + * Input: token, token name to move to initial position. + * + * Return: ERROR, if token not found. + * OK, if token moved to initial position. + */ + int i, j; + LDBLE coef; +/* + * Locate token + */ + for (j = 0; j < count_trxn; j++) + { + if (strcmp(trxn.token[j].s->name, token) == 0) + break; + } + if (j >= count_trxn) + { + input_error++; + error_string = sformatf( "Could not find token in equation, %s.", token); + error_msg(error_string, CONTINUE); + for (i = 0; i < count_trxn; i++) + { + output_msg(sformatf( "%f\t%s\t", + (double) trxn.token[i].coef, trxn.token[i].name)); + } + output_msg(sformatf( "\n")); + return (ERROR); + } +/* + * Swap token to first position + */ + trxn.token[count_trxn].name = trxn.token[0].name; + trxn.token[count_trxn].s = trxn.token[0].s; + trxn.token[count_trxn].coef = trxn.token[0].coef; + + trxn.token[0].name = trxn.token[j].name; + trxn.token[0].s = trxn.token[j].s; + trxn.token[0].coef = trxn.token[j].coef; + + trxn.token[j].name = trxn.token[count_trxn].name; + trxn.token[j].s = trxn.token[count_trxn].s; + trxn.token[j].coef = trxn.token[count_trxn].coef; +/* + * Make coefficient of token -1.0 + */ + coef = -1.0 / trxn.token[0].coef; + trxn_multiply(coef); + return (OK); +} + +/* ********************************************************************** + * + * Routines related to structure "unknown" + * + * ********************************************************************** */ +/* ---------------------------------------------------------------------- */ +struct unknown * Phreeqc:: +unknown_alloc(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Allocates space to an "unknown" structure + * arguments: void + * return: pointer to an "unknown" structure + */ + struct unknown *unknown_ptr; +/* + * Allocate space + */ + unknown_ptr = (struct unknown *) PHRQ_malloc(sizeof(struct unknown)); + if (unknown_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL + */ + unknown_ptr->type = 0; + unknown_ptr->moles = 0.0; + unknown_ptr->ln_moles = 0.0; + unknown_ptr->f = 0.0; + unknown_ptr->sum = 0.0; + unknown_ptr->delta = 0.0; + unknown_ptr->la = 0.0; + unknown_ptr->number = 0; + unknown_ptr->description = NULL; + unknown_ptr->master = NULL; + unknown_ptr->phase = NULL; + unknown_ptr->si = 0.0; + //unknown_ptr->gas_phase = NULL; + unknown_ptr->total = NULL; + unknown_ptr->s = NULL; + unknown_ptr->exch_comp = NULL; + //unknown_ptr->pure_phase = NULL; + unknown_ptr->s_s = NULL; + unknown_ptr->s_s_comp = NULL; + unknown_ptr->s_s_comp_number = 0; + unknown_ptr->s_s_in = FALSE; + unknown_ptr->surface_comp = NULL; + unknown_ptr->related_moles = 0.0; + unknown_ptr->potential_unknown = NULL; + unknown_ptr->potential_unknown1 = NULL; + unknown_ptr->potential_unknown2 = NULL; + unknown_ptr->count_comp_unknowns = 0; + unknown_ptr->comp_unknowns = NULL; + unknown_ptr->phase_unknown = NULL; + unknown_ptr->surface_charge = NULL; + unknown_ptr->mass_water = 0.0; + unknown_ptr->dissolve_only = FALSE; + + return (unknown_ptr); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +unknown_delete(int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Delete unknow from list x + */ + int j; + + unknown_free(x[i]); + for (j = i; j < (count_unknowns); j++) + { + x[j] = x[j + 1]; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +unknown_free(struct unknown *unknown_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Frees space allocated to an unknown structure, frees unknown_ptr. + */ + if (unknown_ptr == NULL) + return (ERROR); + unknown_ptr->master = + (struct master **) free_check_null(unknown_ptr->master); + if (unknown_ptr->type == SURFACE_CB) + { + /* + surface_charge_free(unknown_ptr->surface_charge); + unknown_ptr->surface_charge = (struct surface_charge *) free_check_null(unknown_ptr->surface_charge); + */ + } + unknown_ptr->comp_unknowns = + (struct unknown **) free_check_null(unknown_ptr->comp_unknowns); + unknown_ptr = (struct unknown *) free_check_null(unknown_ptr); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +system_duplicate(int i, int save_old) +/* ---------------------------------------------------------------------- */ +{ + int n; + + if (solution_bsearch(i, &n, TRUE) != NULL) + solution_duplicate(i, save_old); + + //if (pp_assemblage_bsearch(i, &n) != NULL) + // pp_assemblage_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_pp_assemblage_map, i, save_old); + + Utilities::Rxn_copy(Rxn_exchange_map, i, save_old); + + if (surface_bsearch(i, &n) != NULL) + surface_duplicate(i, save_old); + + Utilities::Rxn_copy(Rxn_gas_phase_map, i, save_old); + + if (kinetics_bsearch(i, &n) != NULL) + kinetics_duplicate(i, save_old); + if (ss_assemblage_bsearch(i, &n) != NULL) + ss_assemblage_duplicate(i, save_old); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct logk * Phreeqc:: +logk_store(char *name, int replace_if_found) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for logk. + * + * Pointer to a logk structure is always returned. + * + * If the string is not found, a new entry is made in the hash table. Pointer to + * the new structure is returned. + * If "name" is found and replace is true, pointers in old logk structure + * are freed and replaced with additional input. + * If "name" is found and replace is false, the old logk structure is not + * modified and a pointer to it is returned. + * + * Arguments: + * name input, character string to be found in "logk". + * replace_if_found input, TRUE means reinitialize logk structure if found + * FALSE means just return pointer if found. + * + * Returns: + * pointer to logk structure "logk" where "name" can be found. + */ + int n; + struct logk *logk_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + str_tolower(name); + item.key = name; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + + if (found_item != NULL && replace_if_found == FALSE) + { + logk_ptr = (struct logk *) (found_item->data); + return (logk_ptr); + } + else if (found_item != NULL && replace_if_found == TRUE) + { + logk_ptr = (struct logk *) (found_item->data); + logk_init(logk_ptr); + } + else + { + n = count_logk++; + /* make sure there is space in s */ + if (count_logk >= max_logk) + { + space((void **) ((void *) &logk), count_logk, &max_logk, + sizeof(struct logk *)); + } + /* Make new logk structure */ + logk[n] = logk_alloc(); + logk_ptr = logk[n]; + } + /* set name and z in pointer in logk structure */ + logk_ptr->name = string_hsave(name); +/* + * Update hash table + */ + item.key = logk_ptr->name; + item.data = (void *) logk_ptr; + found_item = hsearch_multi(logk_hash_table, item, ENTER); + if (found_item == NULL) + { + error_string = sformatf( "Hash table error in logk_store."); + error_msg(error_string, CONTINUE); + } + + return (logk_ptr); +} + +/* ---------------------------------------------------------------------- */ +struct logk * Phreeqc:: +logk_alloc(void) +/* ---------------------------------------------------------------------- */ +/* + * Allocates space to a logk structure, initializes + * arguments: void + * return: pointer to a logk structure + */ +{ + struct logk *logk_ptr; + logk_ptr = (struct logk *) PHRQ_malloc(sizeof(struct logk)); + if (logk_ptr == NULL) + malloc_error(); +/* + * set pointers in structure to NULL, variables to zero + */ + logk_init(logk_ptr); + + return (logk_ptr); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +logk_init(struct logk *logk_ptr) +/* ---------------------------------------------------------------------- */ +/* + * return: pointer to a logk structure + */ +{ + int i; +/* + * set pointers in structure to NULL + */ + logk_ptr->name = NULL; +/* + * set varibles = 0 + */ + logk_ptr->lk = 0.0; + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + logk_ptr->log_k[i] = 0.0; + logk_ptr->log_k_original[i] = 0.0; + } + logk_ptr->count_add_logk = 0; + logk_ptr->add_logk = NULL; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +logk_copy2orig(struct logk *logk_ptr) +/* ---------------------------------------------------------------------- */ +/* + * Copies log k data to logk_original + */ +{ + int i; + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + logk_ptr->log_k_original[i] = logk_ptr->log_k[i]; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +struct logk * Phreeqc:: +logk_search(const char *name_in) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function locates the string "name" in the hash table for logk. + * + * Arguments: + * name input, character string to be found in "logk". + * + * Returns: + * pointer to logk structure "logk" where "name" can be found. + * or NULL if not found. + */ + struct logk *logk_ptr; + ENTRY item, *found_item; +/* + * Search list + */ + char * name = string_duplicate(name_in); + str_tolower(name); + item.key = name; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + free_check_null(name); + if (found_item != NULL) + { + logk_ptr = (struct logk *) (found_item->data); + return (logk_ptr); + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +entity_exists(char *name, int n_user) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, 0 Solution + * reaction, 1 Reaction + * exchange, 2 Exchange + * surface, 3 Surface + * gas_phase, 4 Gas_phase + * equilibrium_phases, 5 Pure_phase + * solid_solution, 6 Ss_phase + * kinetics, 7 Kinetics + * mix, 8 Mix + * reaction_temperature 9 Temperature + * unknown 10 UnKnown + */ + int i, return_value; + char *ptr; + char token[MAX_LENGTH]; + enum entity_type type; +/* + * Read keyword + */ + ptr = name; + copy_token(token, &ptr, &i); + type = get_entity_enum(token); + return_value = TRUE; + switch (type) + { + case UnKnown: + warning_msg + ("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); + return_value = 2; + break; + case Solution: /* Solution */ + if (solution_bsearch(n_user, &i, FALSE) == NULL) + { + return_value = FALSE; + } + break; + case Pure_phase: /* Pure phases */ + //if (pp_assemblage_bsearch(n_user, &i) == NULL) + if (Utilities::Rxn_find(Rxn_pp_assemblage_map, n_user) == NULL) + { + return_value = FALSE; + } + break; + case Reaction: /* Reaction */ + //if (irrev_bsearch(n_user, &i) == NULL) + if (Utilities::Rxn_find(Rxn_reaction_map, n_user) == NULL) + { + return_value = FALSE; + } + break; + case Mix: /* Mix */ + if (Utilities::Rxn_find(Rxn_mix_map, n_user) == NULL) + { + return_value = FALSE; + } + //if (mix_bsearch(n_user, &i) == NULL) + //{ + // return_value = FALSE; + //} + break; + case Exchange: /* Ex */ + if (Utilities::Rxn_find(Rxn_exchange_map, n_user) == NULL) + { + return_value = FALSE; + } + break; + case Surface: /* Surface */ + if (surface_bsearch(n_user, &i) == NULL) + { + return_value = FALSE; + } + break; + case Temperature: + if (Utilities::Rxn_find(Rxn_temperature_map, n_user) == NULL) + { + return_value = FALSE; + } + case Pressure: + if (Utilities::Rxn_find(Rxn_pressure_map, n_user) == NULL) + { + return_value = FALSE; + } + case Gas_phase: /* Gas */ + if (Utilities::Rxn_find(Rxn_gas_phase_map, n_user) == NULL) + { + return_value = FALSE; + } + break; + case Kinetics: /* Kinetics */ + if (kinetics_bsearch(n_user, &i) == NULL) + { + return_value = FALSE; + } + break; + case Ss_phase: /* solid_solutions */ + if (ss_assemblage_bsearch(n_user, &i) == NULL) + { + return_value = FALSE; + } + break; + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +enum entity_type Phreeqc:: +get_entity_enum(char *name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution, 0 Solution + * reaction, 1 Reaction + * exchange, 2 Exchange + * surface, 3 Surface + * gas_phase, 4 Gas_phase + * equilibrium_phases, 5 Pure_phase + * solid_solution, 6 Ss_phase + * kinetics, 7 Kinetics + * mix, 8 Mix + * reaction_temperature 9 Temperature + * reaction_pressure + * unknown 10 UnKnown + * + */ + int i; + char *ptr; + char token[MAX_LENGTH]; +/* + * Read keyword + */ + ptr = name; + copy_token(token, &ptr, &i); + check_key(token); + + switch (next_keyword) + { + case Keywords::KEY_SOLUTION: /* Solution */ + return (Solution); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */ + return (Pure_phase); + break; + case Keywords::KEY_REACTION: /* Reaction */ + return (Reaction); + break; + case Keywords::KEY_MIX: /* Mix */ + return (Mix); + break; + case Keywords::KEY_EXCHANGE: /* Ex */ + return (Exchange); + break; + case Keywords::KEY_SURFACE: /* Surface */ + return (Surface); + break; + case Keywords::KEY_REACTION_TEMPERATURE: /* Temperature */ + return (Temperature); + break; + case Keywords::KEY_REACTION_PRESSURE: /* Pressure */ + return (Pressure); + break; + case Keywords::KEY_GAS_PHASE: /* Gas */ + return (Gas_phase); + break; + case Keywords::KEY_KINETICS: /* Kinetics */ + return (Kinetics); + break; + case Keywords::KEY_SOLID_SOLUTIONS: /* solid_solutions */ + return (Ss_phase); + break; + default: + warning_msg + ("EXISTS expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions."); + break; + } + return (UnKnown); +} + +/* + * copier routines + */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copier_add(struct copier *copier_ptr, int n_user, int start, int end) +/* ---------------------------------------------------------------------- */ +/* + * add new set of copy instructions + */ +{ + + if (copier_ptr->count >= copier_ptr->max) + { + copier_ptr->max = copier_ptr->count * 2; + copier_ptr->n_user = + (int *) PHRQ_realloc(copier_ptr->n_user, + (size_t) (copier_ptr->max * sizeof(int))); + if (copier_ptr->n_user == NULL) + malloc_error(); + copier_ptr->start = + (int *) PHRQ_realloc(copier_ptr->start, + (size_t) (copier_ptr->max * sizeof(int))); + if (copier_ptr->start == NULL) + malloc_error(); + copier_ptr->end = + (int *) PHRQ_realloc(copier_ptr->end, + (size_t) (copier_ptr->max * sizeof(int))); + if (copier_ptr->end == NULL) + malloc_error(); + } + copier_ptr->n_user[copier_ptr->count] = n_user; + copier_ptr->start[copier_ptr->count] = start; + copier_ptr->end[copier_ptr->count] = end; + copier_ptr->count++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copier_free(struct copier *copier_ptr) +/* ---------------------------------------------------------------------- */ +/* + * initialize copier structure + */ +{ + + copier_ptr->n_user = (int *) free_check_null(copier_ptr->n_user); + copier_ptr->start = (int *) free_check_null(copier_ptr->start); + copier_ptr->end = (int *) free_check_null(copier_ptr->end); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copier_init(struct copier *copier_ptr) +/* ---------------------------------------------------------------------- */ +/* + * initialize copier structure + */ +{ + + copier_ptr->count = 0; + copier_ptr->max = 10; + copier_ptr->n_user = + (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); + copier_ptr->start = + (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); + copier_ptr->end = + (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); + return (OK); +} +#include "../cxxKinetics.h" +struct kinetics * Phreeqc:: +cxxKinetics2kinetics(const cxxKinetics * kin) + // + // Builds a kinetics structure from instance of cxxKinetics + // +{ + if (kin == NULL) return NULL; + struct kinetics *kinetics_ptr = kinetics_alloc(); + + kinetics_ptr->description = string_duplicate (kin->Get_description().c_str()); + kinetics_ptr->n_user = kin->Get_n_user(); + kinetics_ptr->n_user_end = kin->Get_n_user_end(); + kinetics_ptr->step_divide = kin->Get_step_divide(); + kinetics_ptr->rk = kin->Get_rk(); + kinetics_ptr->bad_step_max = kin->Get_bad_step_max(); + kinetics_ptr->use_cvode = (int) kin->Get_use_cvode(); + kinetics_ptr->cvode_steps = kin->Get_cvode_steps(); + kinetics_ptr->cvode_order = kin->Get_cvode_order(); + + // totals + kinetics_ptr->totals = cxxNameDouble2elt_list(&(kin->Get_totals())); + + // comps + kinetics_ptr->count_comps = (int) kin->Get_kineticsComps().size(); + kinetics_ptr->comps = + (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); + kinetics_ptr->comps = cxxKineticsComp2kinetics_comp(&(kin->Get_kineticsComps())); + + // steps + if (kin->Get_equal_steps() == 0) + { + kinetics_ptr->count_steps = (int) kin->Get_steps().size(); + } + else + { + kinetics_ptr->count_steps = -kin->Get_equal_steps(); + } + kinetics_ptr->steps = (LDBLE *) free_check_null(kinetics_ptr->steps); + if (kin->Get_steps().size() > 0) + { + kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (kin->Get_steps().size() * sizeof(LDBLE))); + if (kinetics_ptr->steps == NULL) + malloc_error(); + std::copy(kin->Get_steps().begin(), kin->Get_steps().end(), + kinetics_ptr->steps); + /* + int i = 0; + for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { + kinetics_ptr->steps[i] = *it; + } + */ + } + return (kinetics_ptr); +} + +struct kinetics_comp * Phreeqc:: +cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > *el) + // + // Builds kinetics_comp structure from of cxxKineticsComp + // +{ + if (el == NULL) return NULL; + struct kinetics_comp *kinetics_comp_ptr = + (struct kinetics_comp *) + PHRQ_malloc((size_t) (el->size() * sizeof(struct kinetics_comp))); + if (kinetics_comp_ptr == NULL) + malloc_error(); + + int i = 0; + for (std::list < cxxKineticsComp >::const_iterator it = el->begin(); + it != el->end(); ++it) + { + if ((*it).Get_rate_name().size() == 0) + kinetics_comp_ptr[i].rate_name = NULL; + else + kinetics_comp_ptr[i].rate_name = string_hsave((*it).Get_rate_name().c_str()); + kinetics_comp_ptr[i].list = cxxNameDouble2name_coef(&((*it).Get_namecoef())); + kinetics_comp_ptr[i].count_list = (int) (*it).Get_namecoef().size(); + kinetics_comp_ptr[i].tol = (*it).Get_tol(); + kinetics_comp_ptr[i].m = (*it).Get_m(); + kinetics_comp_ptr[i].initial_moles = 0.; + kinetics_comp_ptr[i].m0 = (*it).Get_m0(); + kinetics_comp_ptr[i].moles = (*it).Get_moles(); + kinetics_comp_ptr[i].count_c_params = 0; + kinetics_comp_ptr[i].c_params = NULL; +/* + kinetics_comp_ptr[i].count_d_params = 0; + kinetics_comp_ptr[i].d_params = NULL; +*/ + + kinetics_comp_ptr[i].count_d_params = (int) (*it).Get_d_params().size(); + kinetics_comp_ptr[i].d_params = NULL; + if ((*it).Get_d_params().size() > 0) + { + kinetics_comp_ptr[i].d_params = (LDBLE *) + PHRQ_malloc((size_t) ((*it).Get_d_params().size() * sizeof(LDBLE))); + if (kinetics_comp_ptr[i].d_params == NULL) + malloc_error(); + std::copy((*it).Get_d_params().begin(), (*it).Get_d_params().end(), + kinetics_comp_ptr[i].d_params); + } + i++; + } + return (kinetics_comp_ptr); +} +#ifdef SKIP +#include "../PPassemblage.h" +struct pp_assemblage * Phreeqc:: +cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp) + // + // Builds a pp_assemblage structure from instance of cxxPPassemblage + // +{ + struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); + + pp_assemblage_ptr->description = string_duplicate (pp->Get_description().c_str()); + pp_assemblage_ptr->n_user = pp->Get_n_user(); + pp_assemblage_ptr->n_user_end = pp->Get_n_user_end(); + pp_assemblage_ptr->new_def = FALSE; + pp_assemblage_ptr->count_comps = (int) pp->Get_ppAssemblageComps().size(); + pp_assemblage_ptr->pure_phases = + (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); + pp_assemblage_ptr->pure_phases = + cxxPPassemblageComp2pure_phase(&pp->Get_ppAssemblageComps()); + pp_assemblage_ptr->next_elt = cxxNameDouble2elt_list(&pp->Get_eltList()); + return (pp_assemblage_ptr); +} + +#include "../PPassemblageComp.h" +struct pure_phase * Phreeqc:: +cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc) + // + // Builds pure_phase structure from of cxxPPassemblageComp + // +{ + struct pure_phase *pure_phase_ptr = (struct pure_phase *) PHRQ_malloc((size_t) (ppc->size() * sizeof(struct pure_phase))); + if (pure_phase_ptr == NULL) + malloc_error(); + + int i = 0; + for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = ppc->begin(); + it != ppc->end(); ++it) + { + int n; + pure_phase_ptr[i].phase = phase_bsearch((*it).second.Get_name().c_str(), &n, FALSE); + if ((*it).second.Get_name().size() == 0) + pure_phase_ptr[i].name = NULL; + else + pure_phase_ptr[i].name = string_hsave((*it).second.Get_name().c_str()); + if ((*it).second.Get_add_formula().size() == 0) + pure_phase_ptr[i].add_formula = NULL; + else + pure_phase_ptr[i].add_formula = string_hsave((*it).second.Get_add_formula().c_str()); + pure_phase_ptr[i].si = (*it).second.Get_si(); + pure_phase_ptr[i].si_org = (*it).second.Get_si_org(); + pure_phase_ptr[i].moles = (*it).second.Get_moles(); + pure_phase_ptr[i].delta = (*it).second.Get_delta(); + pure_phase_ptr[i].initial_moles = (*it).second.Get_initial_moles(); + pure_phase_ptr[i].force_equality = (int) (*it).second.Get_force_equality(); + pure_phase_ptr[i].dissolve_only = (int) (*it).second.Get_dissolve_only(); + pure_phase_ptr[i].precipitate_only = (int) (*it).second.Get_precipitate_only(); + i++; + } + return (pure_phase_ptr); +} +#endif +#include "../Solution.h" +struct solution * Phreeqc:: +cxxSolution2solution(const cxxSolution * sol) + // + // Builds a solution structure from instance of cxxSolution + // +{ + + struct solution *solution_ptr = solution_alloc(); + + solution_ptr->description = string_duplicate (sol->Get_description().c_str()); + solution_ptr->n_user = sol->Get_n_user(); + solution_ptr->n_user_end = sol->Get_n_user_end(); + solution_ptr->new_def = FALSE; + solution_ptr->tc = sol->Get_tc(); + solution_ptr->ph = sol->Get_ph(); + solution_ptr->solution_pe = sol->Get_pe(); + solution_ptr->mu = sol->Get_mu(); + solution_ptr->ah2o = sol->Get_ah2o(); + solution_ptr->total_h = sol->Get_total_h(); + solution_ptr->total_o = sol->Get_total_o(); + solution_ptr->cb = sol->Get_cb(); + solution_ptr->mass_water = sol->Get_mass_water(); + solution_ptr->total_alkalinity = sol->Get_total_alkalinity(); + solution_ptr->density = 1.0; + solution_ptr->units = moles_per_kilogram_string; + solution_ptr->default_pe = 0; + // pe_data + + // totals + solution_ptr->totals = + (struct conc *) free_check_null(solution_ptr->totals); + solution_ptr->totals = cxxNameDouble2conc(&sol->Get_totals()); + + + // master_activity + solution_ptr->master_activity = + (struct master_activity *) free_check_null(solution_ptr->master_activity); + solution_ptr->master_activity = cxxNameDouble2master_activity(&sol->Get_master_activity()); + solution_ptr->count_master_activity = + (int) sol->Get_master_activity().size() + 1; + + // species_gamma + solution_ptr->species_gamma = cxxNameDouble2master_activity(&sol->Get_species_gamma()); + solution_ptr->count_species_gamma = (int) sol->Get_species_gamma().size(); + + // isotopes + solution_ptr->isotopes = + (struct isotope *) free_check_null(solution_ptr->isotopes); + //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); + solution_ptr->isotopes = cxxSolutionIsotopeList2isotope(&sol->Get_isotopes()); + solution_ptr->count_isotopes = (int) sol->Get_isotopes().size(); + + return (solution_ptr); +} + +#include "../SolutionIsotopeList.h" +struct isotope * Phreeqc:: +cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il) +{ + struct isotope *iso; + if (il->size() <= 0) + { + return NULL; + } + else + { + iso = + (struct isotope *) PHRQ_malloc((size_t) ((il->size()) * sizeof(struct isotope))); + if (iso == NULL) + malloc_error(); + int i = 0; + for (cxxSolutionIsotopeList::const_iterator it = il->begin(); + it != il->end(); ++it) + { + iso[i].isotope_number = it->Get_isotope_number(); + iso[i].elt_name = string_hsave(it->Get_elt_name().c_str()); + iso[i].total = it->Get_total(); + iso[i].ratio = it->Get_ratio(); + iso[i].ratio_uncertainty = it->Get_ratio_uncertainty(); + iso[i].master = master_bsearch(it->Get_elt_name().c_str()); + const char * str = string_hsave(it->Get_elt_name().c_str()); + iso[i].primary = master_bsearch_primary(str); + i++; + } + } + return (iso); +} + +#include "../SSassemblage.h" +#include "../SS.h" +struct ss_assemblage * Phreeqc:: +cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss) + // + // Builds a ss_assemblage structure from instance of cxxSSassemblage + // +{ + struct ss_assemblage *ss_assemblage_ptr = ss_assemblage_alloc(); + + ss_assemblage_ptr->description = string_duplicate (ss->Get_description().c_str()); + ss_assemblage_ptr->n_user = ss->Get_n_user(); + ss_assemblage_ptr->n_user_end = ss->Get_n_user_end(); + ss_assemblage_ptr->new_def = FALSE; + ss_assemblage_ptr->count_s_s = (int) ss->Get_ssAssemblageSSs().size(); + ss_assemblage_ptr->s_s = cxxSSassemblageSS2s_s(&(ss->Get_ssAssemblageSSs())); + return (ss_assemblage_ptr); +} + +struct s_s * Phreeqc:: +cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp) + // + // Builds s_s structure from of cxxSS + // +{ + + // + // generate s_s structures + // + struct s_s *s_s_ptr = + (struct s_s *) PHRQ_malloc((size_t) (sscomp->size() * sizeof(struct s_s))); + if (s_s_ptr == NULL) + malloc_error(); + int j = 0; + for (std::map < std::string, cxxSS >::const_iterator it = sscomp->begin(); + it != sscomp->end(); ++it) + { + s_s_ptr[j].name = string_hsave((*it).second.Get_name().c_str()); + if ((*it).second.Get_name().size() <= 0) + { + error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); + } + assert((*it).second.Get_name().size() > 0); + //s_s_ptr[j].total_moles = it->total_moles; + s_s_ptr[j].total_moles = 0; + s_s_ptr[j].dn = 0; + s_s_ptr[j].a0 = (*it).second.Get_a0(); + s_s_ptr[j].a1 = (*it).second.Get_a1(); + s_s_ptr[j].ag0 = (*it).second.Get_ag0(); + s_s_ptr[j].ag1 = (*it).second.Get_ag1(); + //s_s_ptr[j].ag0 = 0; + //s_s_ptr[j].ag1 = 0; + s_s_ptr[j].s_s_in = TRUE; + s_s_ptr[j].miscibility = (*it).second.Get_miscibility(); + //s_s_ptr[j].spinodal = it->spinodal; + s_s_ptr[j].spinodal = FALSE; + //s_s_ptr[j].tk = it->tk; + s_s_ptr[j].tk = 273.15; + s_s_ptr[j].xb1 = (*it).second.Get_xb1(); + s_s_ptr[j].xb2 = (*it).second.Get_xb2(); + s_s_ptr[j].input_case = 0; + s_s_ptr[j].p[0] = 0; + s_s_ptr[j].p[1] = 0; + s_s_ptr[j].p[2] = 0; + s_s_ptr[j].p[3] = 0; + // + // generate s_s_comp structures + // + s_s_ptr[j].count_comps = (int) (*it).second.Get_comps().size(); + s_s_ptr[j].comps = NULL; + if ((*it).second.Get_comps().size() > 0) + { + int i = 0; + int n; + struct s_s_comp *s_s_comp_ptr = + (struct s_s_comp *) PHRQ_malloc((size_t) ((*it).second.Get_comps().size() * sizeof(struct s_s_comp))); + if (s_s_comp_ptr == NULL) + malloc_error(); + for (cxxNameDouble::const_iterator itc = (*it).second.Get_comps().begin(); + itc != (*it).second.Get_comps().end(); ++itc) + { + s_s_comp_ptr[i].name = string_hsave(itc->first.c_str()); + assert(itc->first.size() > 0); + s_s_comp_ptr[i].phase = phase_bsearch(itc->first.c_str(), &n, TRUE); + s_s_comp_ptr[i].initial_moles = 0; + s_s_comp_ptr[i].moles = itc->second; + s_s_comp_ptr[i].init_moles = 0; + s_s_comp_ptr[i].delta = 0; + s_s_comp_ptr[i].fraction_x = 0; + s_s_comp_ptr[i].log10_lambda = 0; + s_s_comp_ptr[i].log10_fraction_x = 0; + s_s_comp_ptr[i].dn = 0; + s_s_comp_ptr[i].dnc = 0; + s_s_comp_ptr[i].dnb = 0; + i++; + } + s_s_ptr[j].comps = s_s_comp_ptr; + } + j++; + } + return (s_s_ptr); +} + +#include "../Surface.h" +struct surface * Phreeqc:: +cxxSurface2surface(const cxxSurface * surf) + // + // Builds a surface structure from instance of cxxSurface + // +{ + struct surface *surface_ptr = surface_alloc(); + + surface_ptr->description = string_duplicate (surf->Get_description().c_str()); + surface_ptr->n_user = surf->Get_n_user(); + surface_ptr->n_user_end = surf->Get_n_user_end(); + surface_ptr->new_def = FALSE; + surface_ptr->type = surf->Get_type(); + surface_ptr->dl_type = surf->Get_dl_type(); + surface_ptr->sites_units = surf->Get_sites_units(); + surface_ptr->only_counter_ions = surf->Get_only_counter_ions(); + surface_ptr->thickness = surf->Get_thickness(); + surface_ptr->debye_lengths = 1.0; + surface_ptr->solution_equilibria = FALSE; + surface_ptr->n_solution = -2; + surface_ptr->related_phases = (int) surf->Get_related_phases(); + surface_ptr->related_rate = (int) surf->Get_related_rate(); + surface_ptr->transport = surf->Get_transport(); + surface_ptr->debye_lengths = surf->Get_debye_lengths(); + surface_ptr->DDL_viscosity = surf->Get_DDL_viscosity(); + surface_ptr->DDL_limit = surf->Get_DDL_limit(); + + // Surface comps + surface_ptr->count_comps = (int) surf->Get_surfaceComps().size(); + surface_ptr->comps = + (struct surface_comp *) free_check_null(surface_ptr->comps); + surface_ptr->comps = + cxxSurfaceComp2surface_comp(&surf->Get_surfaceComps()); + + // Surface charge + surface_ptr->charge = + (struct surface_charge *) free_check_null(surface_ptr->charge); + + //if (surface_ptr->edl == TRUE) { + if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + { + surface_ptr->count_charge = (int) surf->Get_surfaceCharges().size(); + surface_ptr->charge = + cxxSurfaceCharge2surface_charge(&surf->Get_surfaceCharges()); + } + else + { + surface_ptr->count_charge = 0; + } + // Need to fill in charge (number) in comps list + if (surface_ptr->type != NO_EDL) + { + int i, j; + for (i = 0; i < surface_ptr->count_comps; i++) + { + char token[MAX_LENGTH], name[MAX_LENGTH]; + int l; + strcpy(token, surface_ptr->comps[i].formula); + char *ptr1 = token; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + { + ptr1[0] = '\0'; + } + const char *charge_name = string_hsave(name); + + for (j = 0; j < surface_ptr->count_charge; j++) + { + if (charge_name == surface_ptr->charge[j].name) + { + surface_ptr->comps[i].charge = j; + break; + } + } + assert(j < surface_ptr->count_charge); + } + } + + return (surface_ptr); +} + +#include "../SurfaceComp.h" +struct surface_comp * Phreeqc:: +cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc) + // + // Builds surface_comp structure from of cxxSurfaceComp + // +{ + struct surface_comp *surf_comp_ptr = + (struct surface_comp *) PHRQ_malloc((size_t) (sc->size() * sizeof(struct surface_comp))); + if (surf_comp_ptr == NULL) + malloc_error(); + + int i = 0; + for (std::map < std::string, cxxSurfaceComp >::const_iterator it = sc->begin(); + it != sc->end(); ++it) + { + surf_comp_ptr[i].formula = string_hsave((*it).second.Get_formula().c_str()); + assert((*it).second.Get_formula().size() > 0); + surf_comp_ptr[i].formula_totals = cxxNameDouble2elt_list(&(*it).second.Get_formula_totals()); + surf_comp_ptr[i].formula_z = (*it).second.Get_formula_z(); + surf_comp_ptr[i].moles = (*it).second.Get_moles(); + surf_comp_ptr[i].master = cxxNameDouble2surface_master(&(*it).second.Get_totals()); + surf_comp_ptr[i].totals = cxxNameDouble2elt_list(&(*it).second.Get_totals()); + surf_comp_ptr[i].la = (*it).second.Get_la(); + //surf_comp_ptr[i].charge = it->charge_number; + surf_comp_ptr[i].cb = (*it).second.Get_charge_balance(); + if ((*it).second.Get_phase_name().size() == 0) + surf_comp_ptr[i].phase_name = NULL; + else + surf_comp_ptr[i].phase_name = string_hsave((*it).second.Get_phase_name().c_str()); + surf_comp_ptr[i].phase_proportion = (*it).second.Get_phase_proportion(); + if ((*it).second.Get_rate_name().size() == 0) + surf_comp_ptr[i].rate_name = NULL; + else + surf_comp_ptr[i].rate_name = string_hsave((*it).second.Get_rate_name().c_str()); + surf_comp_ptr[i].Dw = (*it).second.Get_Dw(); + i++; + } + return (surf_comp_ptr); +} + +#include "../SurfaceCharge.h" +struct surface_charge * Phreeqc:: +cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch) + // + // Builds surface_charge structure from of cxxSurfaceCharge + // +{ + struct surface_charge *surf_charge_ptr = + (struct surface_charge *) PHRQ_malloc((size_t) (s_ch->size() * sizeof(struct surface_charge))); + if (surf_charge_ptr == NULL) + malloc_error(); + + int i = 0; + for (std::map < std::string, cxxSurfaceCharge >::const_iterator it = s_ch->begin(); + it != s_ch->end(); ++it) + { + surf_charge_ptr[i].name = string_hsave((*it).second.Get_name().c_str()); + assert((*it).second.Get_name().size() > 0); + surf_charge_ptr[i].specific_area = (*it).second.Get_specific_area(); + surf_charge_ptr[i].grams = (*it).second.Get_grams(); + surf_charge_ptr[i].charge_balance = (*it).second.Get_charge_balance(); + surf_charge_ptr[i].mass_water = (*it).second.Get_mass_water(); + surf_charge_ptr[i].la_psi = (*it).second.Get_la_psi(); + surf_charge_ptr[i].la_psi1 = (*it).second.Get_la_psi1(); + surf_charge_ptr[i].la_psi2 = (*it).second.Get_la_psi2(); + surf_charge_ptr[i].capacitance[0] = (*it).second.Get_capacitance0(); + surf_charge_ptr[i].capacitance[1] = (*it).second.Get_capacitance1(); + surf_charge_ptr[i].sigma0 = 0; + surf_charge_ptr[i].sigma1 = 0; + surf_charge_ptr[i].sigma2 = 0; + surf_charge_ptr[i].sigmaddl = 0; + surf_charge_ptr[i].diffuse_layer_totals = cxxNameDouble2elt_list(&(*it).second.Get_diffuse_layer_totals()); + surf_charge_ptr[i].count_g = 0; + surf_charge_ptr[i].g = NULL; + i++; + } + return (surf_charge_ptr); +} + +struct master * Phreeqc:: +cxxNameDouble2surface_master(const cxxNameDouble * totals) +{ + struct master *master_ptr = NULL; + for (cxxNameDouble::const_iterator it = totals->begin(); + it != totals->end(); it++) + { + /* Find master species */ + const char *eltName = string_hsave(it->first.c_str()); + assert(it->first.size() > 0); + struct element *elt_ptr = element_store(eltName); + if (elt_ptr->master == NULL) + { + std::ostringstream error_oss; + error_oss << "Master species not in data base for " << elt_ptr-> + name << "\n"; + error_msg(error_oss.str().c_str(), CONTINUE); + return (NULL); + } + if (elt_ptr->master->type != SURF) + continue; + master_ptr = elt_ptr->master; + break; + } + if (master_ptr == NULL) + { + std::ostringstream error_oss; + error_oss << + "Surface formula does not contain a surface master species, " << "\n"; + //this->formula << "\n"; + error_msg(error_oss.str().c_str(), CONTINUE); + } + return (master_ptr); +} +struct conc * Phreeqc:: +cxxNameDouble2conc(const cxxNameDouble * nd) + // for Solutions, not ISolutions + // takes a map of (elt name, moles) + // returns list of conc structures +{ + struct conc *c; + assert(nd->type == cxxNameDouble::ND_ELT_MOLES); + c = (struct conc *) + PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct conc))); + if (c == NULL) + malloc_error(); + int i = 0; + for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) + { + c[i].description = string_hsave(it->first.c_str()); + c[i].moles = it->second; + c[i].input_conc = it->second; + c[i].units = NULL; + c[i].equation_name = NULL; + c[i].phase_si = 0.0; + c[i].n_pe = 0; + c[i].as = NULL; + c[i].gfw = 0.0; + //c[i].skip = 0; + c[i].phase = NULL; + i++; + } + c[i].description = NULL; + return (c); +} + +struct name_coef * Phreeqc:: +cxxNameDouble2name_coef(const cxxNameDouble * nd) + // + // Builds a name_coef structure from instance of cxxNameDouble + // +{ + if (nd == NULL) return NULL; + assert(nd->type == cxxNameDouble::ND_NAME_COEF); + struct name_coef *name_coef_ptr = + (struct name_coef *) PHRQ_malloc((size_t) ((nd->size()) * sizeof(struct name_coef))); + if (name_coef_ptr == NULL) + malloc_error(); + int i = 0; + for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) + { + name_coef_ptr[i].name = string_hsave(it->first.c_str()); + name_coef_ptr[i].coef = it->second; + i++; + } + return (name_coef_ptr); +} + +struct elt_list * Phreeqc:: +cxxNameDouble2elt_list(const cxxNameDouble * nd) + // + // Builds a exch_comp structure from instance of cxxNameDouble + // +{ + if (nd == NULL) return NULL; + assert(nd->type == cxxNameDouble::ND_ELT_MOLES); + struct elt_list *elt_list_ptr = + (struct elt_list *) + PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct elt_list))); + if (elt_list_ptr == NULL) + malloc_error(); + int i = 0; + for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) + { + elt_list_ptr[i].elt = element_store(it->first.c_str()); + elt_list_ptr[i].coef = it->second; + i++; + } + elt_list_ptr[i].elt = NULL; + elt_list_ptr[i].coef = 0; + return (elt_list_ptr); +} + +struct master_activity * Phreeqc:: +cxxNameDouble2master_activity(const cxxNameDouble * nd) + // + // Builds a list of master_activity structures from instance of cxxNameDouble + // +{ + int i = 0; + assert(nd->type == cxxNameDouble::ND_SPECIES_LA + || nd->type == cxxNameDouble::ND_SPECIES_GAMMA); + struct master_activity *master_activity_ptr = NULL; + switch (nd->type) + { + case cxxNameDouble::ND_SPECIES_LA: + { + master_activity_ptr = + (struct master_activity *) PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct master_activity))); + if (master_activity_ptr == NULL) + malloc_error(); + for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); + it++) + { + master_activity_ptr[i].description = string_hsave(it->first.c_str()); + master_activity_ptr[i].la = it->second; + i++; + } + } + master_activity_ptr[i].description = NULL; + break; + case cxxNameDouble::ND_SPECIES_GAMMA: + { + if (nd->size() > 0) + { + master_activity_ptr = + (struct master_activity *) PHRQ_malloc((size_t) ((nd->size()) * sizeof(struct master_activity))); + if (master_activity_ptr == NULL) + malloc_error(); + for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); + it++) + { + master_activity_ptr[i].description = string_hsave(it->first.c_str()); + master_activity_ptr[i].la = it->second; + i++; + } + } + } + break; + case cxxNameDouble::ND_ELT_MOLES: + case cxxNameDouble::ND_NAME_COEF: + break; + } + return (master_activity_ptr); +} + +#include "../StorageBin.h" + +void Phreeqc:: +Use2cxxStorageBin(cxxStorageBin & sb) +{ + //Add everything from use structure to storagebin sb + + int n; + sb.Get_system().Set_io(sb.Get_io()); + + //struct Use *use_ptr = &use; + //cxxUse *use_ptr = &use; + if (use.Get_mix_in()) + { + cxxMix *entity = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); + if (entity != NULL) + { + sb.Set_Mix(use.Get_n_mix_user(), entity); + } + } + else if (use.Get_solution_in()) + { + struct solution *struct_entity = solution_bsearch(use.Get_n_solution_user(), &n, FALSE); + if (struct_entity != NULL) + { + cxxSolution entity(struct_entity, sb.Get_io()); + sb.Set_Solution(use.Get_n_solution_user(), &entity); + } + } + if (use.Get_pp_assemblage_in()) + { + cxxPPassemblage *entity_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user()); + if (entity_ptr != NULL) + { + sb.Set_PPassemblage(use.Get_n_pp_assemblage_user(), entity_ptr); + } + } + #ifdef SKIP + if (use.Get_pp_assemblage_in() == TRUE) + { + struct pp_assemblage *struct_entity = pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), &n); + if (struct_entity != NULL) + { + cxxPPassemblage entity(struct_entity, sb.Get_io()); + sb.Set_PPassemblage(use.Get_n_pp_assemblage_user(), &entity); + } + } + #endif + if (use.Get_exchange_in()) + { + cxxExchange *entity_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); + if (entity_ptr != NULL) + { + //cxxExchange entity(struct_entity, sb.Get_io()); + sb.Set_Exchange(use.Get_n_exchange_user(), entity_ptr); + } + } + if (use.Get_surface_in()) + { + struct surface *struct_entity = surface_bsearch(use.Get_n_surface_user(), &n); + if (struct_entity != NULL) + { + cxxSurface entity(struct_entity, sb.Get_io()); + sb.Set_Surface(use.Get_n_surface_user(), &entity); + } + } + if (use.Get_gas_phase_in()) + { + cxxGasPhase *entity_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, use.Get_n_gas_phase_user()); + if (entity_ptr != NULL) + { + sb.Set_GasPhase(use.Get_n_gas_phase_user(), entity_ptr); + } + } + if (use.Get_ss_assemblage_in()) + { + struct ss_assemblage *struct_entity = ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); + if (struct_entity != NULL) + { + cxxSSassemblage entity(struct_entity, sb.Get_io()); + sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), &entity); + } + } + if (use.Get_kinetics_in()) + { + struct kinetics *struct_entity = kinetics_bsearch(use.Get_n_kinetics_user(), &n); + if (struct_entity != NULL) + { + cxxKinetics entity(struct_entity, sb.Get_io()); + sb.Set_Kinetics(use.Get_n_kinetics_user(), &entity); + } + } + if (use.Get_reaction_in()) + { + cxxReaction *entity = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); + if (entity != NULL) + { + sb.Set_Reaction(use.Get_n_reaction_user(), entity); + } + } + if (use.Get_temperature_in()) + { + cxxTemperature *entity = Utilities::Rxn_find(Rxn_temperature_map, use.Get_n_temperature_user()); + if (entity != NULL) + { + sb.Set_Temperature(use.Get_n_temperature_user(), entity); + } + } + if (use.Get_pressure_in()) + { + cxxPressure *entity = Utilities::Rxn_find(Rxn_pressure_map, use.Get_n_pressure_user()); + if (entity != NULL) + { + sb.Set_Pressure(use.Get_n_pressure_user(), entity); + } + } +} + +void Phreeqc:: +phreeqc2cxxStorageBin(cxxStorageBin & sb) + // + // Fills StorageBin sb with all reactants from phreeqc instance. + // equivalent to old import_phreeqc. + // +{ + int i; + + // Solutions + for (i = 0; i < count_solution; i++) + { + //sb.getSolutions()[solution[i]->n_user] = cxxSolution(solution[i], sb.Get_io()); + cxxSolution ent(solution[i], sb.Get_io()); + sb.Set_Solution(solution[i]->n_user, ent); + } + + // Exchangers + { + std::map::iterator it; + for (it = Rxn_exchange_map.begin(); it != Rxn_exchange_map.end(); it++) + { + sb.Set_Exchange(it->second.Get_n_user(), &(it->second)); + } + } + // GasPhases + { + std::map::iterator it; + for (it = Rxn_gas_phase_map.begin(); it != Rxn_gas_phase_map.end(); it++) + { + sb.Set_GasPhase(it->second.Get_n_user(), &(it->second)); + } + } + + // Kinetics + for (i = 0; i < count_kinetics; i++) + { + cxxKinetics entity(&kinetics[i], sb.Get_io()); + sb.Set_Kinetics(kinetics[i].n_user, &entity ); + } + + // PPassemblages + { + std::map::iterator it; + for (it = Rxn_pp_assemblage_map.begin(); it != Rxn_pp_assemblage_map.end(); it++) + { + sb.Set_PPassemblage(it->second.Get_n_user(), &(it->second)); + } + } +#ifdef SKIP + for (i = 0; i < count_pp_assemblage; i++) + { + cxxPPassemblage entity(&pp_assemblage[i], sb.Get_io()); + sb.Set_PPassemblage(pp_assemblage[i].n_user, &entity ); + } +#endif + // SSassemblages + for (i = 0; i < count_ss_assemblage; i++) + { + cxxSSassemblage entity(&ss_assemblage[i], sb.Get_io()); + sb.Set_SSassemblage(ss_assemblage[i].n_user, &entity ); + } + + // Surfaces + for (i = 0; i < count_surface; i++) + { + cxxSurface entity(&surface[i], sb.Get_io()); + sb.Set_Surface(surface[i].n_user, &entity ); + } + + // Mixes + { + std::map::iterator it; + for (it = Rxn_mix_map.begin(); it != Rxn_mix_map.end(); it++) + { + sb.Set_Mix(it->second.Get_n_user(), &(it->second)); + } + } + + // Reactions + { + std::map::iterator it; + for (it = Rxn_reaction_map.begin(); it != Rxn_reaction_map.end(); it++) + { + sb.Set_Reaction(it->second.Get_n_user(), &(it->second)); + } + } + + // Temperatures + { + std::map::iterator it; + for (it = Rxn_temperature_map.begin(); it != Rxn_temperature_map.end(); it++) + { + sb.Set_Temperature(it->second.Get_n_user(), &(it->second)); + } + } + + // Pressures + { + std::map::iterator it; + for (it = Rxn_pressure_map.begin(); it != Rxn_pressure_map.end(); it++) + { + sb.Set_Pressure(it->second.Get_n_user(), &(it->second)); + } + } +} + +void Phreeqc:: +phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) + // + // copy phreeqc reactants numbered n to StorageBin sb + // +{ + int pos; + + // Solutions + { + solution_bsearch(n, &pos, TRUE); + //sb.getSolutions()[n] = cxxSolution(solution[pos], sb.Get_io()); + cxxSolution ent(solution[pos], sb.Get_io()); + sb.Set_Solution(n, ent); + } + + // Exchangers + { + cxxExchange *entity_ptr = Utilities::Rxn_find(Rxn_exchange_map, n); + if (entity_ptr != NULL) + { + sb.Set_Exchange(n, entity_ptr); + } + } + + // GasPhases + { + cxxGasPhase *entity_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, n); + if (entity_ptr != NULL) + { + sb.Set_GasPhase(n, entity_ptr); + } + } + + // Kinetics + { + if (kinetics_bsearch(n, &pos) != NULL) + { + //this->Kinetics[n] = cxxKinetics(&(kinetics[pos]), sb.Get_io()); + cxxKinetics ent(&(kinetics[pos]), sb.Get_io()); + sb.Set_Kinetics(n, &ent ); + } + } + + // PPassemblages + { + cxxPPassemblage *entity_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); + if (entity_ptr != NULL) + { + sb.Set_PPassemblage(n, entity_ptr); + } + } +#ifdef SKIP + { + if (pp_assemblage_bsearch(n, &pos) != NULL) + { + //this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos]), sb.Get_io()); + cxxPPassemblage ent(&(pp_assemblage[pos]), sb.Get_io()); + sb.Set_PPassemblage(n, &ent); + } + } +#endif + // SSassemblages + { + if (ss_assemblage_bsearch(n, &pos) != NULL) + { + //this->SSassemblages[n] = cxxSSassemblage(&(ss_assemblage[pos]), sb.Get_io()); + cxxSSassemblage ent(&(ss_assemblage[pos]), sb.Get_io()); + sb.Set_SSassemblage(n, &ent); + } + } + + // Surfaces + { + if (surface_bsearch(n, &pos) != NULL) + { + //this->Surfaces[n] = cxxSurface(&(surface[pos]), sb.Get_io()); + cxxSurface ent(&(surface[pos]), sb.Get_io()); + sb.Set_Surface(n, &ent); + } + } +} +void Phreeqc:: +cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) +// +// copy all reactants from storage bin number n to phreeqc +// replaces any existing reactants in phreeqc +// +{ + // Solutions + { + std::map < int, cxxSolution >::const_iterator it = sb.Get_Solutions().find(n); + if (it != sb.Get_Solutions().end()) + { + struct solution *solution_old_ptr = cxxSolution2solution(&(it->second)); + solution_ptr_to_user(solution_old_ptr, it->first); + solution_free(solution_old_ptr); + solution_old_ptr = (struct solution *) free_check_null(solution_old_ptr); + } + } + + // Exchangers + { + std::map < int, cxxExchange >::const_iterator it = sb.Get_Exchangers().find(n); + if (it != sb.Get_Exchangers().end()) + { + Rxn_exchange_map[n] = it->second; + } + } + + // GasPhases + { + std::map < int, cxxGasPhase >::const_iterator it = sb.Get_GasPhases().find(n); + if (it != sb.Get_GasPhases().end()) + { + Rxn_gas_phase_map[n] = it->second; + } + } + + // Kinetics + { + std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().find(n); + if (it != sb.Get_Kinetics().end()) + { + struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&(it->second)); + kinetics_ptr_to_user(kinetics_ptr, it->first); + kinetics_free(kinetics_ptr); + kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); + } + } + + // PPassemblages + { + std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().find(n); + if (it != sb.Get_PPassemblages().end()) + { + Rxn_pp_assemblage_map[n] = it->second; + } + } +#ifdef SKIP + { + std::map < int, cxxPPassemblage >::const_iterator it = + sb.Get_PPassemblages().find(n); + if (it != sb.Get_PPassemblages().end()) + { + struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&(it->second)); + pp_assemblage_ptr_to_user(pp_assemblage_ptr, it->first); + pp_assemblage_free(pp_assemblage_ptr); + pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); + } + } +#endif + // SSassemblages + { + std::map < int, cxxSSassemblage >::const_iterator it = + sb.Get_SSassemblages().find(n); + if (it != sb.Get_SSassemblages().end()) + { + struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&(it->second)); + ss_assemblage_ptr_to_user(ss_assemblage_ptr, it->first); + ss_assemblage_free(ss_assemblage_ptr); + ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); + } + } + + // Surfaces + { + std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().find(n); + if (it != sb.Get_Surfaces().end()) + { + struct surface *surface_ptr = cxxSurface2surface(&(it->second)); + surface_ptr_to_user(surface_ptr, it->first); + surface_free(surface_ptr); + surface_ptr = (struct surface *) free_check_null(surface_ptr); + } + } + + // Mixes + { + std::map < int, cxxMix >::const_iterator it = sb.Get_Mixes().find(n); + if (it != sb.Get_Mixes().end()) + { + Rxn_mix_map[n] = it->second; + } + } + + // Reactions + { + std::map < int, cxxReaction >::const_iterator it = sb.Get_Reactions().find(n); + if (it != sb.Get_Reactions().end()) + { + Rxn_reaction_map[n] = it->second; + } + } + // Temperatures + { + std::map < int, cxxTemperature >::const_iterator it = sb.Get_Temperatures().find(n); + if (it != sb.Get_Temperatures().end()) + { + Rxn_temperature_map[n] = it->second; + } + } + // Pressures + { + std::map < int, cxxPressure >::const_iterator it = sb.Get_Pressures().find(n); + if (it != sb.Get_Pressures().end()) + { + Rxn_pressure_map[n] = it->second; + } + } +} +void Phreeqc:: +cxxStorageBin2phreeqc(cxxStorageBin & sb) +// +// copy data from storage bin to phreeqc +// replaces any existing reactants in phreeqc +// +{ + // Solutions + { + + std::map < int, cxxSolution >::const_iterator it = sb.Get_Solutions().begin(); + for ( ; it != sb.Get_Solutions().end(); it ++) + { + struct solution *solution_old_ptr = cxxSolution2solution(&(it->second)); + solution_ptr_to_user(solution_old_ptr, it->first); + solution_free(solution_old_ptr); + solution_old_ptr = (struct solution *) free_check_null(solution_old_ptr); + } + } + + // Exchangers + { + std::map < int, cxxExchange >::const_iterator it = sb.Get_Exchangers().begin(); + for ( ; it != sb.Get_Exchangers().end(); it++) + { + Rxn_exchange_map[it->first] = it->second; + } + } + + // GasPhases + { + std::map < int, cxxGasPhase >::const_iterator it = sb.Get_GasPhases().begin(); + for ( ; it != sb.Get_GasPhases().end(); it++) + { + Rxn_gas_phase_map[it->first] = it->second; + } + } + + // Kinetics + { + std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().begin(); + for ( ; it != sb.Get_Kinetics().end(); it++) + { + struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&(it->second)); + kinetics_ptr_to_user(kinetics_ptr, it->first); + kinetics_free(kinetics_ptr); + kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); + } + } + + // PPassemblages + { + std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().begin(); + for ( ; it != sb.Get_PPassemblages().end(); it++) + { + Rxn_pp_assemblage_map[it->first] = it->second; + } + } +#ifdef SKIP + { + std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().begin(); + for ( ; it != sb.Get_PPassemblages().end(); it++) + { + struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&(it->second)); + pp_assemblage_ptr_to_user(pp_assemblage_ptr, it->first); + pp_assemblage_free(pp_assemblage_ptr); + pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); + } + } +#endif + // SSassemblages + { + std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().begin(); + for ( ; it != sb.Get_SSassemblages().end(); it++) + { + struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&(it->second)); + ss_assemblage_ptr_to_user(ss_assemblage_ptr, it->first); + ss_assemblage_free(ss_assemblage_ptr); + ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); + } + } + + // Surfaces + { + std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().begin(); + for ( ; it != sb.Get_Surfaces().end(); it++) + { + struct surface *surface_ptr = cxxSurface2surface(&(it->second)); + surface_ptr_to_user(surface_ptr, it->first); + surface_free(surface_ptr); + surface_ptr = (struct surface *) free_check_null(surface_ptr); + } + } + // Mixes + { + std::map < int, cxxMix >::const_iterator it = sb.Get_Mixes().begin(); + for ( ; it != sb.Get_Mixes().end(); it++) + { + Rxn_mix_map[it->first] = it->second; + } + } + + // Reactions + { + std::map < int, cxxReaction >::const_iterator it = sb.Get_Reactions().begin(); + for ( ; it != sb.Get_Reactions().end(); it++) + { + Rxn_reaction_map[it->first] = it->second; + } + } + // Temperatures + { + std::map < int, cxxTemperature >::const_iterator it = sb.Get_Temperatures().begin(); + for ( ; it != sb.Get_Temperatures().end(); it++) + { + Rxn_temperature_map[it->first] = it->second; + } + } + // Pressures + { + std::map < int, cxxPressure >::const_iterator it = sb.Get_Pressures().begin(); + for ( ; it != sb.Get_Pressures().end(); it++) + { + Rxn_pressure_map[it->first] = it->second; + } + } +} + + diff --git a/rename_cpp/sundialsmath.cpp b/rename_cpp/sundialsmath.cpp new file mode 100644 index 00000000..7d753816 --- /dev/null +++ b/rename_cpp/sundialsmath.cpp @@ -0,0 +1,82 @@ +/******************************************************************* + * * + * File : sundialsmath.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the implementation file for a C math library. * + * * + *******************************************************************/ + + +#include +#include +#include "sundialsmath.h" +#include "sundialstypes.h" + +#define ZERO RCONST(0.0) +#define ONE RCONST(1.0) +#define TWO RCONST(2.0) + + +realtype +UnitRoundoff(void) +{ + realtype u; + volatile realtype one_plus_u; + + u = ONE; + one_plus_u = ONE + u; + while (one_plus_u != ONE) + { + u /= TWO; + one_plus_u = ONE + u; + } + u *= TWO; + + return (u); +} + + +realtype +RPowerI(realtype base, int exponent) +{ + int i, expt; + realtype prod; + + prod = ONE; + expt = ABS(exponent); + for (i = 1; i <= expt; i++) + prod *= base; + if (exponent < 0) + prod = ONE / prod; + return (prod); +} + + +realtype +RPowerR(realtype base, realtype exponent) +{ + + if (base <= ZERO) + return (ZERO); + + /* return((realtype)pow((double)base,(double)exponent)); */ + return ((realtype) pow(base, exponent)); +} + + +realtype +RSqrt(realtype x) +{ + if (x <= ZERO) + return (ZERO); + + /* return((realtype) sqrt((double) x)); */ + return ((realtype) sqrt(x)); +} diff --git a/rename_cpp/sundialsmath.h b/rename_cpp/sundialsmath.h new file mode 100644 index 00000000..0cb022fb --- /dev/null +++ b/rename_cpp/sundialsmath.h @@ -0,0 +1,118 @@ +/******************************************************************* + * * + * File : sundialsmath.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This is the header file for a C math library. The routines * + * listed here work with the type realtype as defined in * + * sundialstypes.h. * + * To do single precision floating point arithmetic, set the type * + * realtype to be float. To do double precision arithmetic, set * + * the type realtype to be double. The default implementations * + * for RPowerR and RSqrt call standard math library functions * + * which do double precision arithmetic. If this is unacceptable * + * when realtype is float, then the user should re-implement * + * these two routines by calling single precision routines * + * available on his/her machine. * + * * + *******************************************************************/ +#ifndef _sundialsmath_h +#define _sundialsmath_h + +#include "sundialstypes.h" + + +/****************************************************************** + * * + * Macros : MIN, MAX, ABS, SQR * + *----------------------------------------------------------------* + * MIN(A, B) returns the minimum of A and B. * + * * + * MAX(A, B) returns the maximum of A and B. * + * * + * ABS(A) returns the absolute value of A. * + * * + * SQR(A) returns the square of A. * + * * + ******************************************************************/ +#ifndef MIN +#define MIN(A, B) ((A) < (B) ? (A) : (B)) +#endif + +#ifndef MAX +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#endif + +#ifndef ABS +#define ABS(A) ((A < 0) ? -(A) : (A)) +#endif + +#ifndef SQR +#define SQR(A) ((A) * (A)) +#endif + +/****************************************************************** + * * + * Function : UnitRoundoff * + * Usage : realtype uround; * + * uround = UnitRoundoff(); * + *----------------------------------------------------------------* + * UnitRoundoff returns the unit roundoff u for real floating * + * point arithmetic, where u is defined to be the smallest * + * positive real such that 1.0 + u != 1.0. * + * * + ******************************************************************/ + + realtype UnitRoundoff(void); + + +/****************************************************************** + * * + * Function : RPowerI * + * Usage : int exponent; * + * realtype base, ans; * + * ans = RPowerI(base,exponent); * + *----------------------------------------------------------------* + * RPowerI returns the value base^exponent, where base is a * + * realtype and exponent is an int. * + * * + ******************************************************************/ + + realtype RPowerI(realtype base, int exponent); + + +/****************************************************************** + * * + * Function : RPowerR * + * Usage : realtype base, exponent, ans; * + * ans = RPowerR(base,exponent); * + *----------------------------------------------------------------* + * RPowerR returns the value base^exponent, where both base and * + * exponent are realtype. If base < 0.0, then RPowerR returns 0.0 * + * * + ******************************************************************/ + + realtype RPowerR(realtype base, realtype exponent); + + +/****************************************************************** + * * + * Function : RSqrt * + * Usage : realtype sqrt_x; * + * sqrt_x = RSqrt(x); * + *----------------------------------------------------------------* + * RSqrt(x) returns the square root of x. If x < 0.0, then RSqrt * + * returns 0.0. * + * * + ******************************************************************/ + + realtype RSqrt(realtype x); + + +#endif diff --git a/rename_cpp/sundialstypes.h b/rename_cpp/sundialstypes.h new file mode 100644 index 00000000..f343d63e --- /dev/null +++ b/rename_cpp/sundialstypes.h @@ -0,0 +1,143 @@ +#if defined(WIN32) +#include +#endif +#include "phrqtype.h" +#ifndef _INC_SUNDIALSTYPES_H +#define _INC_SUNDIALSTYPES_H +/******************************************************************* + * * + * File : sundialstypes.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *-----------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see sundials/shared/LICENSE * + *-----------------------------------------------------------------* + * This header file exports three types: realtype, integertype, * + * and booleantype, as well as the constants TRUE and FALSE. * + * * + * Users should #include "sundialstypes.h" in any file that * + * shhould be easily modifiable to work with different real or * + * integer types and use the exported names realtype and * + * integertype within such a file. * + * The types for realtype and integertype below have been set to * + * double and long int, respectively. A user should modify these * + * type declarations as he/she sees fit. For example, if a user * + * wants the work with type float because double precision * + * floating point arithmetic is too expensive on the user's * + * machine, then the definition below should be changed to: * + * * + * typedef float realtype; * + * * + * Similarly, if a user does not need to work with extremely large * + * integers (see the system header file for the limits * + * on type int and long int on your machine), then the user * + * should change the definition below to: * + * * + * typedef int integertype; * + * * + * The constants SUNDIALS_FLOAT, SUNDIALS_DOUBLE, SUNDIALS_INT, * + * SUNDIALS_LONG indicate the underlying types for realtype and * + * integertype. They should be set as follows: * + * * + * (1) #define SUNDIALS_FLOAT 1 * + * #define SUNDIALS_DOUBLE 0 (real is float) * + * * + * (2) #define SUNDIALS_FLOAT 0 * + * #define SUNDIALS_DOUBLE 1 (real is double) * + * * + * (3) #define SUNDIALS_INT 1 * + * #define SUNDIALS_LONG 0 (integer is int) * + * * + * (4) #define SUNDIALS_INT 0 * + * #define SUNDIALS_LONG 1 (integer is long int) * + * * + * Thus the legal types for realtype are float and double, while * + * the legal types for integertype are int and long int. * + * The macro RCONST gives a user a convenient way to define real * + * constants. To use the real constant 1.0, for example, the * + * user should write * + * * + * #define ONE RCONST(1.0) * + * * + * If realtype is double, then RCONST(1.0) expands to 1.0. * + * If realtype is float, then RCONST(1.0) expands to 1.0F. * + * There is never a need to explicitly cast 1.0 to (realtype). * + * * + *******************************************************************/ +#ifndef _sundialstypes_h +#define _sundialstypes_h + + +/****************************************************************** + * * + * Types : realtype, integertype * + *----------------------------------------------------------------* + * The types realtype and integertype are currently set to double * + * and int, respectively. See the documentation at the top for * + * usage details and a description of associated constants and * + * macros. * + * * + ******************************************************************/ + +#ifdef USE_LONG_DOUBLE + typedef long double realtype; +#else + typedef double realtype; +#endif + typedef long int integertype; + +#define SUNDIALS_FLOAT 0 +#define SUNDIALS_DOUBLE 1 + +#define SUNDIALS_LONG 1 +#define SUNDIALS_INT 0 + +#if SUNDIALS_FLOAT + +#define RCONST(x) x##F + +#elif SUNDIALS_DOUBLE + +#define RCONST(x) x + +#endif + + +/****************************************************************** + * * + * Type : booleantype * + * Constants : FALSE, TRUE * + *----------------------------------------------------------------* + * ANSI C does not have a built-in boolean type. Below is the * + * definition for a new type booleantype. The advantage of using * + * the name booleantype (instead of int) is an increase in code * + * readability. * + * It allows the programmer to make a distinction between int and * + * boolean data. Variables of type booleantype are intended to * + * have only the two values FALSE and TRUE which are defined * + * below to be equal to 0 and 1, respectively. * + * * + ******************************************************************/ + +#ifndef booleantype +#define booleantype int +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#endif +/* +#ifdef __cplusplus +} +#endif +*/ +#endif /* _INC_SUNDIALSTYPES_H */ diff --git a/rename_cpp/tally.cpp b/rename_cpp/tally.cpp new file mode 100644 index 00000000..706372ce --- /dev/null +++ b/rename_cpp/tally.cpp @@ -0,0 +1,1403 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Temperature.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "Reaction.h" +#include "PPassemblage.h" + +/* + Calling sequence + +Initialization: +--------------- + +build_tally_table(); finds all elements (rows), + possible return values (columns), + allocates space +get_tally_table_rows_columns(int *rows, int *columns) + returns number of rows and columns in table +get_tally_table_row_heading(int row, char *string) + row is C row number + returns row descripter for row +get_tally_table_column_heading(int column, int *type, char *string) + column is C column number + returns column heading for column + +Each call to phreeqc: +--------------------- + +zero_tally_table(); initialize table to 0s +set_reaction_moles(n_user, moles) n_user is reservoir number + moles is number of moles of reaction to add + +int set_reaction_temperature(n_user, tc) + +fill_tally_table(int *n_user, int index_conservative, int n_buffer) + n_user is reservoir number + index_conservative is solution number + where conservative mixing is stored + slot is 0 for initial + + run phreeqc here. + +fill_tally_table(int *n_user, int index_conservative, int n_buffer) + n_user is reservoir number + index_conservative is solution number + where conservative mixing is stored + slot is 1 for final +store_tally_table(LDBLE *array, int row_dim, int col_dim, LDBLE fill_factor) + row_dim is Fortran dimension + col_dim is Fortran dimension + array is space from Fortran + stores conservative mixing (column 0) + stores reaction (column 1) + difference between slot 1 and slot 0 for + all other intities (columns 2-n) + +Finalization: +------------- +int free_tally_table(void); Frees space + +*/ + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_all_components(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Counts components in any defined solution, gas_phase, exchanger, + * surface, or pure_phase_assemblage + * + * Returns n_comp, which is total, including H, O, elements, and Charge + * names contains character strings with names of components + */ + int i, j; +/* + * Accumulate all aqueous components + */ + add_all_components_tally(); +/* + * Count components, 2 for hydrogen, oxygen, + others, + */ + tally_count_component = 0; + for (i = 0; i < count_master; i++) + { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) + { + tally_count_component++; + } + } +/* + * Put information in buffer. + * Buffer contains an entry for every primary master + * species that can be used in the transport problem. + * Each entry in buffer is sent to HST for transort. + */ + t_buffer = + (struct tally_buffer *) PHRQ_malloc((size_t) tally_count_component * + sizeof(struct tally_buffer)); + j = 0; + for (i = 0; i < count_master; i++) + { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) + { + t_buffer[j].name = master[i]->elt->name; + t_buffer[j].master = master[i]; + t_buffer[j].gfw = master[i]->elt->gfw; + j++; + } + } +#ifdef SKIP + output_msg( "List of Components:\n" ); + for (i = 0; i < tally_count_component; i++) + { + output_msg(sformatf( "\t%d\t%s\n", i + 1, buffer[i].name)); + /* + for (j=0; buffer[i].name[j] != '\0'; j++) { + names[i * length + j] = buffer[i].name[j]; + } + */ + } +#endif + /* + * Return value + */ + /**n_comp = count_component;*/ + count_tally_table_rows = tally_count_component; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +store_tally_table(LDBLE * l_array, int row_dim, int col_dim, LDBLE fill_factor) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + if (tally_table == NULL) + { + input_error++; + error_msg("Tally table not defined, get_tally_table_rows_columns", + CONTINUE); + return (ERROR); + } + if (count_tally_table_rows > row_dim) + { + input_error++; + error_msg + ("Too many tally table rows for Fortran storage, store_tally_table", + CONTINUE); + return (ERROR); + } + if (count_tally_table_columns > col_dim) + { + input_error++; + error_msg + ("Too many tally table columns for Fortran storage, store_tally_table", + CONTINUE); + return (ERROR); + } + /* + * store conservative mixing solution + */ + for (j = 0; j < count_tally_table_rows; j++) + { + l_array[j] = tally_table[0].total[1][j].moles; + } + /* + * store reaction solution + */ + for (j = 0; j < count_tally_table_rows; j++) + { + l_array[row_dim + j] = tally_table[1].total[1][j].moles; + } + /* + * Calculate deltas + */ + + diff_tally_table(); + + /* + * store deltas for all other columns + */ + for (i = 2; i < count_tally_table_columns; i++) + { + for (j = 0; j < count_tally_table_rows; j++) + { + l_array[i * row_dim + j] = + tally_table[i].total[2][j].moles / fill_factor; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_tally_table_rows_columns(int *rows, int *columns) +/* ---------------------------------------------------------------------- */ +{ + *rows = 0; + *columns = 0; + if (tally_table == NULL) + { + input_error++; + error_msg("tally table not defined, get_tally_table_rows_columns", + CONTINUE); + return (ERROR); + } + *rows = count_tally_table_rows; + *columns = count_tally_table_columns; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_tally_table_row_heading(int row, char *string) +/* ---------------------------------------------------------------------- */ +{ + /* + * row is C row number + */ + strcpy(string, ""); + if (tally_table == NULL) + { + input_error++; + error_msg("Tally table not defined, get_tally_table row_heading", + CONTINUE); + return (ERROR); + } + if (row >= count_tally_table_rows) + { + input_error++; + error_msg + ("Row exceeds tally table size, get_tally_table row_heading", + CONTINUE); + return (ERROR); + } + strcpy(string, t_buffer[row].name); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_tally_table_column_heading(int column, int *type, char *string) +/* ---------------------------------------------------------------------- */ +{ + /* + * column is C column number + */ + *type = -1; + strcpy(string, ""); + if (tally_table == NULL) + { + input_error++; + error_msg("tally table not defined, get_tally_table_column_heading", + CONTINUE); + return (ERROR); + } + if (column >= count_tally_table_columns) + { + input_error++; + error_msg + ("column exceeds tally table size, get_tally_table_column_heading", + CONTINUE); + return (ERROR); + } + strcpy(string, tally_table[column].name); + *type = tally_table[column].type; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +free_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, k; + if (tally_table == NULL) + return (OK); + for (i = 0; i < count_tally_table_columns; i++) + { + if (tally_table[i].formula != NULL) + tally_table[i].formula = + (struct elt_list *) free_check_null(tally_table[i].formula); + for (k = 0; k < 3; k++) + { + tally_table[i].total[k] = + (struct tally_buffer *) free_check_null(tally_table[i]. + total[k]); + } + } + tally_table = (struct tally *) free_check_null(tally_table); + t_buffer = (struct tally_buffer *) free_check_null(t_buffer); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +zero_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k; + for (i = 0; i < count_tally_table_columns; i++) + { + for (j = 0; j < count_tally_table_rows; j++) + { + for (k = 0; k < 3; k++) + { + tally_table[i].total[k][j].moles = 0; + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +diff_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + /* + output_msg("Difference\n\n"); + */ + for (i = 0; i < count_tally_table_columns; i++) + { + for (j = 0; j < count_tally_table_rows; j++) + { + tally_table[i].total[2][j].moles = + tally_table[i].total[1][j].moles - + tally_table[i].total[0][j].moles; + } + + /* + output_msg(sformatf( "Column %d\t%s\tType: %d\n", i, tally_table[i].name, tally_table[i].type)); + for (j = 0; j < count_tally_table_rows; j++) { + output_msg(sformatf( "\t%d\t%s\t%e\n", j, tally_table[i].total[2][j].name, (double) tally_table[i].total[2][j].moles)); + } + */ + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + output_msg(sformatf( "Tally_table\n\n")); + for (i = 0; i < count_tally_table_columns; i++) + { + output_msg(sformatf( "%s\tType: %d\n", tally_table[i].name, + tally_table[i].type)); + output_msg(sformatf( "\n")); + output_msg(sformatf( "\t%15s\t%15s\t%15s\n", "Initial", + "Final", "Difference")); + for (j = 0; j < count_tally_table_rows; j++) + { + output_msg(sformatf( "%5s\t%15g\t%15g\t%15g\n", + t_buffer[j].name, tally_table[i].total[0][j].moles, + tally_table[i].total[1][j].moles, + tally_table[i].total[2][j].moles)); + } + output_msg(sformatf( "\n")); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +fill_tally_table(int *n_user, int index_conservative, int n_buffer) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. + */ + int i, j, k, n; + struct solution *solution_ptr; + //struct irrev *irrev_ptr; + //struct pp_assemblage *pp_assemblage_ptr; + //struct exchange *exchange_ptr; + struct surface *surface_ptr; + struct ss_assemblage *ss_assemblage_ptr; + //struct gas_phase *gas_phase_ptr; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + int found; + LDBLE moles; + char *ptr; + /* + * Cycle through tally table columns + */ + for (i = 0; i < count_tally_table_columns; i++) + { + switch (tally_table[i].type) + { + case Solution: +/* + * fill solution + */ + if (n_user[Solution] < 0 || n_buffer == 0) + break; + if (i == 0) + { + solution_ptr = solution_bsearch(index_conservative, &n, TRUE); + } + else if (i == 1) + { + solution_ptr = solution_bsearch(n_user[Solution], &n, TRUE); + } + else + { + solution_ptr = NULL; + error_msg + ("Solution is not in first two columns of tally_table", + STOP); + } + if (solution_ptr == NULL) + break; + xsolution_zero(); + add_solution(solution_ptr, 1.0, 1.0); + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_master; j++) + { + if (master[j]->total > 0.0) + { + char * temp_name = string_duplicate(master[j]->elt->primary->elt->name); + ptr = temp_name; + get_elts_in_species(&ptr, master[j]->total); + free_check_null(temp_name); + } + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Reaction: + /* + * fill reaction + */ + if (n_user[Reaction] < 0) + break; + { + cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, n_user[Reaction]); + if (reaction_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + if (n_buffer == 1) + { + moles = reaction_ptr->Get_steps()[0]; + } + else + { + moles = 0.0; + } + reaction_calc(reaction_ptr); + add_elt_list(reaction_ptr->Get_elementList(), moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + } +#ifdef SKIP + irrev_ptr = irrev_bsearch(n_user[Reaction], &n); + if (irrev_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + if (n_buffer == 1) + { + moles = irrev_ptr->steps[0]; + } + else + { + moles = 0.0; + } + add_elt_list(irrev_ptr->elts, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); +#endif + break; + case Pure_phase: + /* + * fill an equilibrium phase + */ + if (n_user[Pure_phase] < 0) + break; + { + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n_user[Pure_phase]); + //pp_assemblage_ptr = pp_assemblage_bsearch(n_user[Pure_phase], &n); + if (pp_assemblage_ptr == NULL) + break; + //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + if (string_hsave(it->second.Get_name().c_str()) == + tally_table[i].name) + break; + if (strcmp_nocase(it->second.Get_name().c_str(), + tally_table[i].name) == 0) + break; + } + if (it == pp_assemblage_ptr->Get_pp_assemblage_comps().end()) + break; + count_elts = 0; + paren_count = 0; + moles = it->second.Get_moles(); + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + } + break; + case Exchange: + { + /* + * fill exchange + */ + if (n_user[Exchange] < 0) + break; + //exchange_ptr = exchange_bsearch(n_user[Exchange], &n); + cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, n_user[Exchange]); + if (exchange_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + std::vector comps = exchange_ptr->Vectorize(); + //for (j = 0; j < exchange_ptr->count_comps; j++) + for (j = 0; j < (int) comps.size(); j++) + { + add_elt_list(comps[j]->Get_totals(), 1.0); + } +#ifdef SKIP + for (j = 0; j < exchange_ptr->count_comps; j++) + { + add_elt_list(exchange_ptr->comps[j].totals, 1.0); + } +#endif + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + } + break; + case Surface: + /* + * fill surface + */ + if (n_user[Surface] < 0) + break; + surface_ptr = surface_bsearch(n_user[Surface], &n); + if (surface_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + for (j = 0; j < surface_ptr->count_comps; j++) + { + add_elt_list(surface_ptr->comps[j].totals, 1.0); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Ss_phase: + /* + * fill an solid solution phase + */ + if (n_user[Ss_phase] < 0) + break; + ss_assemblage_ptr = ss_assemblage_bsearch(n_user[Ss_phase], &n); + if (ss_assemblage_ptr == NULL) + break; + found = FALSE; + moles = 0.0; + for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) + { + for (k = 0; k < ss_assemblage_ptr->s_s[j].count_comps; k++) + { + if (ss_assemblage_ptr->s_s[j].comps[k].phase->name == + tally_table[i].name) + break; + if (strcmp_nocase + (ss_assemblage_ptr->s_s[j].comps[k].phase->name, + tally_table[i].name) == 0) + break; + } + if (k < ss_assemblage_ptr->s_s[j].count_comps) + { + moles = ss_assemblage_ptr->s_s[j].comps[k].moles; + found = TRUE; + break; + } + } + if (found == FALSE) + break; + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Gas_phase: + /* + * fill in gas phase + */ + if (n_user[Gas_phase] < 0) + break; + { + //gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); + cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, n_user[Gas_phase]); + if (gas_phase_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + const std::vector *gc = &(gas_phase_ptr->Get_gas_comps()); + for (size_t l = 0; l < gc->size(); l++) + { + struct phase *phase_ptr = phase_bsearch((*gc)[l].Get_phase_name().c_str(), &k, FALSE); + + add_elt_list(phase_ptr->next_elt, + (*gc)[l].Get_moles()); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + } +#ifdef SKIP + /* + * fill in gas phase + */ + if (n_user[Gas_phase] < 0) + break; + //gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); + + if (gas_phase_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + for (j = 0; j < gas_phase_ptr->count_comps; j++) + { + add_elt_list(gas_phase_ptr->comps[j].phase->next_elt, + gas_phase_ptr->comps[j].moles); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; +#endif + case Kinetics: + /* + * fill in kinetics + */ + if (n_user[Kinetics] < 0) + break; + kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); + if (kinetics_ptr == NULL) + break; + kinetics_comp_ptr = NULL; + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + kinetics_comp_ptr = &kinetics_ptr->comps[j]; + if (kinetics_comp_ptr->rate_name == tally_table[i].name) + break; + if (strcmp_nocase + (kinetics_comp_ptr->rate_name, tally_table[i].name) == 0) + break; + } + if (j >= kinetics_ptr->count_comps) + break; + moles = kinetics_comp_ptr->m; + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + break; + case Mix: + break; + case Temperature: + case Pressure: + break; + case UnKnown: + break; + } +#ifdef SKIP + output_msg(sformatf( "Column %d\t%s\tType: %d\n", i, + tally_table[i].name, tally_table[i].type)); + for (j = 0; j < count_tally_table_rows; j++) + { + output_msg(sformatf( "\t%d\t%s\t%e\n", j, + tally_table[i].total[n_buffer][j].name, + (double) tally_table[i].total[n_buffer][j].moles)); + } +#endif + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +elt_list_to_tally_table(struct tally_buffer *buffer_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + for (i = 0; i < count_tally_table_rows; i++) + { + buffer_ptr[i].moles = 0.0; + } + /* + * copy element list amounts to buffer in tally table + * for column number + */ + + for (j = 0; j < count_elts; j++) + { + if (elt_list[j].elt->primary->s == s_h2o) + continue; + if (elt_list[j].elt->primary->s == s_hplus) + continue; + if (elt_list[j].elt->primary->s == s_h3oplus) + continue; + if (elt_list[j].elt->primary->type != AQ) + continue; + for (i = 0; i < count_tally_table_rows; i++) + { + if (elt_list[j].elt->primary == + buffer_ptr[i].master->elt->primary) + { + buffer_ptr[i].moles = elt_list[j].coef; + break; + } + } + if (i >= count_tally_table_rows) + { + error_msg("Should not be here in elt_list_to_tally_table", STOP); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. Counts number of aqueous components + * to transport. Stores in global variable tally_count_component. + * Also calculates a number greater than all user numbers and + * stores in global variable first_user_number. + */ + int i, j, k, l, n, p, save_print_use; + int count_tt_reaction, count_tt_exchange, count_tt_surface, + count_tt_gas_phase; + int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; + //struct pp_assemblage *pp_assemblage_ptr; + //struct pure_phase *pure_phase_ptr; + struct ss_assemblage *ss_assemblage_ptr; + struct s_s *s_s_ptr; + struct s_s_comp *s_s_comp_ptr; + struct kinetics *kinetics_ptr; + struct kinetics_comp *kinetics_comp_ptr; + struct phase *phase_ptr; + + + char token[MAX_LENGTH]; + char *ptr; +/* + * make list of all elements in all entitites + * defines the number of rows in the table + */ + get_all_components(); + + save_print_use = pr.use; + pr.use = FALSE; +/* + * find nuber of columns + */ + count_tally_table_columns = 0; +/* + * add one for conservative mixing + */ + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Solution_conservative"); + tally_table[n].type = Solution; +/* + * add one for mixing plus reaction + */ + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Solution_reaction"); + tally_table[n].type = Solution; +/* + * add one for reactions + */ + //if (count_irrev > 0) + if (Rxn_reaction_map.size() > 0) + { + count_tt_reaction = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Reaction"); + tally_table[n].type = Reaction; + } + else + { + count_tt_reaction = 0; + } +/* + * add one for exchangers + */ + if (Rxn_exchange_map.size() > 0) + { + count_tt_exchange = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Exchange"); + tally_table[n].type = Exchange; + } + else + { + count_tt_exchange = 0; + } +#ifdef SKIP + if (count_exchange > 0) + { + count_tt_exchange = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Exchange"); + tally_table[n].type = Exchange; + } + else + { + count_tt_exchange = 0; + } +#endif +/* + * add one for surface + */ + if (count_surface > 0) + { + count_tt_surface = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Surface"); + tally_table[n].type = Surface; + } + else + { + count_tt_surface = 0; + } +/* + * add one for gases + */ + //if (count_gas_phase > 0) + if (Rxn_gas_phase_map.size() > 0) + { + count_tt_gas_phase = 1; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave("Gas_phase"); + tally_table[n].type = Gas_phase; + } + else + { + count_tt_gas_phase = 0; + } +/* + * Count pure phases + */ + count_tt_pure_phase = 0; + //if (count_pp_assemblage > 0) + if (Rxn_pp_assemblage_map.size() > 0) + { + /* + * Go through all pure phases in pure phase assemblages + */ + //for (i = 0; i < count_pp_assemblage; i++) + std::map::iterator it; + for (it = Rxn_pp_assemblage_map.begin(); it != Rxn_pp_assemblage_map.end(); it++) + { + //pp_assemblage_ptr = &pp_assemblage[i]; + cxxPPassemblage * pp_assemblage_ptr = &(it->second); + std::map::iterator jit; + jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; jit != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); jit++) + { + cxxPPassemblageComp * comp_ptr = &(jit->second); + int l; + struct phase * phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE); + /* + * check if already in tally_table + */ + for (k = 1; k < count_tally_table_columns; k++) + { + if (tally_table[k].type == Pure_phase && + tally_table[k].name == phase_ptr->name && + tally_table[k].add_formula == + string_hsave(comp_ptr->Get_add_formula().c_str())) + break; + } + if (k < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_pure_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = phase_ptr->name; + tally_table[n].type = Pure_phase; + tally_table[n].add_formula = string_hsave(comp_ptr->Get_add_formula().c_str()); + count_elts = 0; + paren_count = 0; + if (comp_ptr->Get_add_formula().size() > 0) + { + strcpy(token, comp_ptr->Get_add_formula().c_str()); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, phase_ptr->formula); + add_elt_list(phase_ptr->next_elt, 1.0); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +#ifdef SKIP + count_tt_pure_phase = 0; + if (count_pp_assemblage > 0) + { + /* + * Go through all pure phases in pure phase assemblages + */ + for (i = 0; i < count_pp_assemblage; i++) + { + pp_assemblage_ptr = &pp_assemblage[i]; + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + { + pure_phase_ptr = &pp_assemblage_ptr->pure_phases[j]; + /* + * check if already in tally_table + */ + for (k = 1; k < count_tally_table_columns; k++) + { + if (tally_table[k].type == Pure_phase && + tally_table[k].name == pure_phase_ptr->phase->name && + tally_table[k].add_formula == + pure_phase_ptr->add_formula) + break; + } + if (k < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_pure_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = pure_phase_ptr->phase->name; + tally_table[n].type = Pure_phase; + tally_table[n].add_formula = pure_phase_ptr->add_formula; + count_elts = 0; + paren_count = 0; + if (pure_phase_ptr->add_formula != NULL) + { + strcpy(token, pure_phase_ptr->add_formula); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + } + else + { + strcpy(token, pure_phase_ptr->phase->formula); + add_elt_list(pure_phase_ptr->phase->next_elt, 1.0); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +#endif +/* + * Add solid-solution pure phases + */ + count_tt_ss_phase = 0; + if (count_ss_assemblage > 0) + { + /* + * Go through all components of all solid solutions in solid-solution assemblages + */ + for (i = 0; i < count_ss_assemblage; i++) + { + ss_assemblage_ptr = &ss_assemblage[i]; + for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) + { + s_s_ptr = &ss_assemblage_ptr->s_s[j]; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + s_s_comp_ptr = &s_s_ptr->comps[k]; + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) + { + if (tally_table[l].type == Ss_phase && + tally_table[l].name == s_s_comp_ptr->phase->name) + break; + } + if (l < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_ss_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = s_s_comp_ptr->phase->name; + tally_table[n].type = Ss_phase; + count_elts = 0; + paren_count = 0; + strcpy(token, s_s_comp_ptr->phase->formula); + add_elt_list(s_s_comp_ptr->phase->next_elt, 1.0); + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } + } +/* + * Add kinetic reactants + */ + count_tt_kinetics = 0; + if (count_kinetics > 0) + { + for (i = 0; i < count_kinetics; i++) + { + kinetics_ptr = &kinetics[i]; + for (j = 0; j < kinetics_ptr->count_comps; j++) + { + kinetics_comp_ptr = &kinetics_ptr->comps[j]; + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) + { + if (tally_table[l].type == Kinetics && + tally_table[l].name == kinetics_comp_ptr->rate_name) + break; + } + if (l < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_kinetics++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = kinetics_comp_ptr->rate_name; + tally_table[n].type = Kinetics; + /* + * get formula for kinetic component + */ + count_elts = 0; + paren_count = 0; + phase_ptr = NULL; + if (kinetics_ptr->comps[j].count_list == 1) + { + strcpy(token, kinetics_ptr->comps[j].list[0].name); + phase_ptr = phase_bsearch(token, &p, FALSE); + } + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, 1.0); + } + else + { + for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) + { + char * temp_name = string_duplicate(kinetics_ptr->comps[j].list[k].name); + ptr = temp_name; + get_elts_in_species(&ptr, + 1.0 * + kinetics_ptr->comps[j].list[k]. + coef); + free_check_null(temp_name); + } + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +#ifdef SKIP + /* + * Debug print for table definition + */ + output_msg(sformatf( "List of rows for tally table\n")); + for (i = 0; i < count_tally_table_rows; i++) + { + output_msg(sformatf( "\t%-s\n", buffer[i].name)); + } + output_msg(sformatf( "\nList of columns for tally table\n")); + for (i = 0; i < count_tally_table_columns; i++) + { + output_msg(sformatf( "\t%-20s\tType: %d\n", + tally_table[i].name, tally_table[i].type)); + if (tally_table[i].formula != NULL) + { + for (j = 0; tally_table[i].formula[j].elt != NULL; j++) + { + output_msg(sformatf( "\t\t%-10s\t%f\n", + tally_table[i].formula[j].elt->name, + (double) tally_table[i].formula[j].coef)); + } + } + } +#endif + pr.use = save_print_use; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +add_all_components_tally(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine accumulates elements from all solutions, phases, gas phases, + * exchangers, and surfaces. Counts number of aqueous components + * to transport. Stores in global variable tally_count_component. + * Also calculates a number greater than all user numbers and + * stores in global variable first_user_number. + */ + int i, save_print_use; + + save_print_use = pr.use; + pr.use = FALSE; +/* + * Delete solutions less than -1 + */ + while (count_solution > 0 && solution[0]->n_user < -1) + { + i = solution[0]->n_user; + solution_delete(i); + } +/* + * add all solutions + */ + xsolution_zero(); + for (i = 0; i < count_solution; i++) + { + add_solution(solution[i], 1.0 / solution[i]->mass_water, 1.0); + } +/* + * add all irrev reactions + */ + { + std::map::iterator it = Rxn_reaction_map.begin(); + for (; it != Rxn_reaction_map.end(); it++) + { + add_reaction(&it->second, 1, 1.0); + } + } +#ifdef SKIP + for (i = 0; i < count_irrev; i++) + { + add_reaction(&irrev[i], 1, 1.0); + } +#endif +/* + * Add pure phases + */ + { + std::map::iterator it = Rxn_pp_assemblage_map.begin(); + for (; it != Rxn_pp_assemblage_map.end(); it++) + { + add_pp_assemblage(&(it->second)); + } + } +#ifdef SKIP + for (i = 0; i < count_pp_assemblage; i++) + { + add_pp_assemblage(&pp_assemblage[i]); + } +#endif +/* + * Exchangers + */ + { + std::map::iterator it = Rxn_exchange_map.begin(); + for (; it != Rxn_exchange_map.end(); it++) + { + add_exchange(&it->second); + } + } +#ifdef SKIP + for (i = 0; i < count_exchange; i++) + { + add_exchange(&exchange[i]); + } +#endif +/* + * Surfaces + */ + for (i = 0; i < count_surface; i++) + { + add_surface(&surface[i]); + } +/* + * Gases + */ + { + std::map::iterator it = Rxn_gas_phase_map.begin(); + for ( ; it != Rxn_gas_phase_map.end(); it++) + { + add_gas_phase(&it->second); + } + } +#ifdef SKIP + for (i = 0; i < count_gas_phase; i++) + { + add_gas_phase(&gas_phase[i]); + } +#endif +/* + * Add solid-solution pure phases + */ + for (i = 0; i < count_ss_assemblage; i++) + { + add_ss_assemblage(&ss_assemblage[i]); + } +/* + * Add elements in kinetic reactions + */ + for (i = 0; i < count_kinetics; i++) + { + calc_dummy_kinetic_reaction_tally(&kinetics[i]); + add_kinetics(&kinetics[i]); + } +/* + * reset pr.use + */ + pr.use = save_print_use; + return; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components and add positive amount of each reactant + */ + int i, j; + LDBLE coef; + char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + free_check_null(kinetics_ptr->totals); + count_elts = 0; + paren_count = 0; + for (i = 0; i < kinetics_ptr->count_comps; i++) + { + coef = 1.0; +/* + * Reactant is a pure phase, copy formula into token + */ + phase_ptr = NULL; + if (kinetics_ptr->comps[i].count_list == 1) + { + strcpy(token, kinetics_ptr->comps[i].list[0].name); + phase_ptr = phase_bsearch(token, &j, FALSE); + } + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, coef); + } + else + { + for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) + { + char * temp_name = string_duplicate(kinetics_ptr->comps[i].list[j].name); + ptr = temp_name; + get_elts_in_species(&ptr, coef); + free_check_null(temp_name); + } + } + + } + kinetics_ptr->totals = elt_list_save(); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +extend_tally_table(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + /* + * adds another column to tally_table + * increments number of columns + */ + tally_table = + (struct tally *) PHRQ_realloc((void *) tally_table, + (size_t) (count_tally_table_columns + + 1) * sizeof(struct tally)); + if (tally_table == NULL) + malloc_error(); + for (i = 0; i < 3; i++) + { + tally_table[count_tally_table_columns].total[i] = + (struct tally_buffer *) + PHRQ_malloc((size_t) (count_tally_table_rows) * + sizeof(struct tally_buffer)); + if (tally_table[count_tally_table_columns].total[i] == NULL) + malloc_error(); + for (j = 0; j < count_tally_table_rows; j++) + { + tally_table[count_tally_table_columns].total[i][j].name = + t_buffer[j].name; + tally_table[count_tally_table_columns].total[i][j].master = + t_buffer[j].master; + } + } + tally_table[count_tally_table_columns].name = NULL; + tally_table[count_tally_table_columns].type = UnKnown; + tally_table[count_tally_table_columns].add_formula = NULL; + tally_table[count_tally_table_columns].moles = 0.0; + tally_table[count_tally_table_columns].formula = NULL; + count_tally_table_columns++; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_reaction_moles(int n_user, LDBLE moles) +/* ---------------------------------------------------------------------- */ +{ + cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, n_user); + if (reaction_ptr == NULL) + return (ERROR); + std::vector v; + v.push_back(moles); + reaction_ptr->Set_steps(v); + reaction_ptr->Set_countSteps(1); + reaction_ptr->Set_equalIncrements(true); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_reaction_temperature(int n_user, LDBLE tc) +/* ---------------------------------------------------------------------- */ +{ + cxxTemperature * temperature_ptr = Utilities::Rxn_find(Rxn_temperature_map, n_user); + if (temperature_ptr == NULL) + return (ERROR); + temperature_ptr->Get_temps().clear(); + temperature_ptr->Get_temps().push_back(tc); + temperature_ptr->Set_equalIncrements(false); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_kinetics_time(int n_user, LDBLE step) +/* ---------------------------------------------------------------------- */ +{ + int n; + struct kinetics *kinetics_ptr; + + kinetics_ptr = kinetics_bsearch(n_user, &n); + if (kinetics_ptr == NULL) + return (ERROR); + kinetics_ptr->steps[0] = step; + kinetics_ptr->count_steps = 1; + return (OK); +} diff --git a/rename_cpp/tidy.cpp b/rename_cpp/tidy.cpp new file mode 100644 index 00000000..b59e0ca2 --- /dev/null +++ b/rename_cpp/tidy.cpp @@ -0,0 +1,5032 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "PPassemblage.h" +#define ZERO_TOL 1.0e-30 + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_model(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + int n_user, last; + int new_named_logk; + /* + * Determine if any new elements, species, phases have been read + */ + state = INITIALIZE; + new_model = FALSE; + new_pp_assemblage = FALSE; + new_surface = FALSE; + new_exchange = FALSE; + new_reaction = FALSE; + new_temperature = FALSE; + new_mix = FALSE; + new_solution = FALSE; + new_gas_phase = FALSE; + new_inverse = FALSE; + new_punch = FALSE; + new_surface = FALSE; + new_ss_assemblage = FALSE; + new_kinetics = FALSE; + new_pitzer = FALSE; + new_named_logk = FALSE; + + if (keycount[Keywords::KEY_SOLUTION_SPECIES] > 0 || /*"species" */ + keycount[Keywords::KEY_SOLUTION_MASTER_SPECIES] > 0 || /*"master" */ + keycount[Keywords::KEY_PHASES] > 0 || /*"phases" */ + keycount[Keywords::KEY_EXCHANGE_SPECIES] > 0 || /*"exchange_species" */ + keycount[Keywords::KEY_EXCHANGE_MASTER_SPECIES] > 0 || /*"master_exchange_species" */ + keycount[Keywords::KEY_SURFACE_SPECIES] > 0 || /*"surface_species" */ + keycount[Keywords::KEY_SURFACE_MASTER_SPECIES] > 0 || /*"master_surface_species" */ + keycount[Keywords::KEY_RATES] > 0 || /*"rates" */ + keycount[Keywords::KEY_LLNL_AQUEOUS_MODEL_PARAMETERS] > 0 || /*"llnl_aqueous_model_parameters" */ + (keycount[Keywords::KEY_DATABASE] > 0 && simulation == 0) || /*"database" */ + keycount[Keywords::KEY_NAMED_EXPRESSIONS] > 0 || /*"named_analytical_expressions" */ + keycount[Keywords::KEY_ISOTOPES] > 0 || /*"isotopes" */ + keycount[Keywords::KEY_CALCULATE_VALUES] > 0 || /*"calculate_values" */ + keycount[Keywords::KEY_ISOTOPE_RATIOS] > 0 || /*"isotopes_ratios", */ + keycount[Keywords::KEY_ISOTOPE_ALPHAS] > 0 || /*"isotopes_alphas" */ + keycount[Keywords::KEY_PITZER] > 0 || /*"pitzer" */ + keycount[Keywords::KEY_SIT] > 0 /*"sit" */ + ) + { + new_model = TRUE; + } + if (keycount[Keywords::KEY_EQUILIBRIUM_PHASES] > 0 || + keycount[Keywords::KEY_EQUILIBRIUM_PHASES_RAW] > 0 || + keycount[Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY]) + { + new_pp_assemblage = TRUE; /*"pure_phases" */ + } + if (keycount[Keywords::KEY_SURFACE] > 0 || + keycount[Keywords::KEY_SURFACE_RAW] > 0 || + keycount[Keywords::KEY_SURFACE_MODIFY]) + { + new_surface = TRUE; /*"surface" */ + } + if (keycount[Keywords::KEY_EXCHANGE] > 0 || + keycount[Keywords::KEY_SURFACE_RAW] > 0 || + keycount[Keywords::KEY_SURFACE_MODIFY]) + { + new_exchange = TRUE; /*"exchange" */ + } + if (keycount[Keywords::KEY_REACTION] > 0 || + keycount[Keywords::KEY_REACTION_RAW] > 0 || + keycount[Keywords::KEY_REACTION_MODIFY]) + { + new_reaction = TRUE; /*"reaction" */ + } + if (keycount[Keywords::KEY_REACTION_TEMPERATURE] > 0 || + keycount[Keywords::KEY_REACTION_TEMPERATURE_RAW] > 0 || + keycount[Keywords::KEY_REACTION_TEMPERATURE_MODIFY]) + { + new_temperature = TRUE; /*"reacton_temperature" */ + } + if (keycount[Keywords::KEY_MIX] > 0 || + keycount[Keywords::KEY_MIX_RAW] > 0) + { + new_mix = TRUE; /*"mix" */ + } + if (keycount[Keywords::KEY_SOLUTION] > 0 || + keycount[Keywords::KEY_SOLUTION_SPREAD] > 0 || + keycount[Keywords::KEY_SOLUTION_RAW] > 0 || + keycount[Keywords::KEY_SOLUTION_MODIFY]) + { /*"solution" */ + new_solution = TRUE; + } + if (keycount[Keywords::KEY_GAS_PHASE] > 0 || + keycount[Keywords::KEY_GAS_PHASE_RAW] > 0 || + keycount[Keywords::KEY_GAS_PHASE_MODIFY]) + { + new_gas_phase = TRUE; /*"gas_phase" */ + } + if (keycount[Keywords::KEY_SOLID_SOLUTIONS] > 0 || + keycount[Keywords::KEY_SOLID_SOLUTIONS_RAW] > 0 || + keycount[Keywords::KEY_SOLID_SOLUTIONS_MODIFY]) + { + new_ss_assemblage = TRUE; /*"solid_solutions" */ + } + if (keycount[Keywords::KEY_KINETICS] > 0 || + keycount[Keywords::KEY_KINETICS_RAW] > 0 || + keycount[Keywords::KEY_KINETICS_MODIFY]) + { + new_kinetics = TRUE; /*"kinetics" */ + } + if (keycount[Keywords::KEY_INVERSE_MODELING] > 0) + { + new_inverse = TRUE; /*"inverse_modeling" */ + } + if (keycount[Keywords::KEY_SELECTED_OUTPUT] > 0 || /*"selected_output" */ + keycount[Keywords::KEY_USER_PUNCH] > 0) /*"user_punch" */ + { + new_punch = TRUE; + } + + if (keycount[Keywords::KEY_COPY] > 0) + { + new_copy = TRUE; /*"copy" */ + } + if (keycount[Keywords::KEY_PITZER] > 0) + { + new_pitzer = TRUE; /*"pitzer" */ + } + if (keycount[Keywords::KEY_NAMED_EXPRESSIONS] > 0) + { + new_named_logk = TRUE; /*"named_log_k" */ + } + +/* + * Sort arrays + */ + +/* species */ + if (new_model == TRUE) + { + qsort(s, (size_t) count_s, (size_t) sizeof(struct species *), s_compare); + +/* master species */ + qsort(master, (unsigned) count_master, sizeof(struct master *), master_compare); + +/* elements */ + qsort(elements, (size_t) count_elements, (size_t) sizeof(struct element *), element_compare); +/* phases */ + qsort(phases, (size_t) count_phases, (size_t) sizeof(struct phase *), phase_compare); + + } +#ifdef SKIP +/* pure_phases */ + if (new_pp_assemblage) + { + pp_assemblage_sort(); + } +#endif +/* solid solutions */ + if (new_ss_assemblage) + { + ss_assemblage_sort(); + } + +/* surfaces */ + if (new_surface) + { + surface_sort(); + } + +/* reset Peng-Robinson parms... */ + for (i = 0; i < count_phases; i++) + { + phases[i]->pr_in = false; + phases[i]->pr_p = 0.0; + phases[i]->pr_phi = 1.0; + } + +/* kinetics */ + if (new_kinetics) + { + kinetics_sort(); + } + + /* named_log_k */ + if (new_named_logk) + { + tidy_logk(); + } +/* + * Check pointers, write reactions for species + */ + if (new_model) + { + tidy_species(); + + tidy_phases(); + + tidy_master_isotope(); +/* + * calculate gfw of water, kg/mole + */ + compute_gfw("H2O", &gfw_water); + gfw_water *= 0.001; + } +/* + * tidy surface data + */ + if (new_model || new_surface) + { + tidy_surface(); + } +/* + * tidy inverse data + */ + if (new_inverse) + { + tidy_inverse(); + } +/* + * tidy gas phase data + */ + if (new_gas_phase) + { + tidy_gas_phase(); + } +/* reset Peng-Robinson parms... */ + for (i = 0; i < count_phases; i++) + { + phases[i]->pr_in = false; + phases[i]->pr_p = 0.0; + phases[i]->pr_phi = 1.0; + } +/* + * tidy pp_assemblage data + */ + if (new_model || new_pp_assemblage) + { + tidy_pp_assemblage(); + } +/* + * tidy ss_assemblage data + */ + if (new_model || new_ss_assemblage) + { + tidy_ss_assemblage(); + } +/* + * tidy exchange data, after pp_assemblages + */ + if (new_exchange) + { + tidy_exchange(); + } + if (new_exchange) + { + tidy_min_exchange(); + } + if (new_exchange) + { + tidy_kin_exchange(); + } +/* + * tidy surface data + */ + if (new_surface) + { + tidy_min_surface(); + } + if (new_surface) + { + tidy_kin_surface(); + } +/* + * tidy solution isotope data + */ + if (new_solution) + { + tidy_isotopes(); + } + if (new_model) + { + tidy_isotope_ratios(); + } + if (new_model) + { + tidy_isotope_alphas(); + } +/* + * Duplicate kinetics + */ + if (new_kinetics) + { + for (i = 0; i < count_kinetics; i++) + { + if (kinetics[i].n_user_end > kinetics[i].n_user) + { + n_user = kinetics[i].n_user; + last = kinetics[i].n_user_end; + kinetics[i].n_user_end = kinetics[i].n_user; + for (j = n_user + 1; j <= last; j++) + { + kinetics_duplicate(n_user, j); + } + } + } + } + +/* + * Tidy pitzer information + */ + if (pitzer_model && new_model) + { + pitzer_tidy(); + } +/* + * Tidy SIT information + */ + if (sit_model && new_model) + { + sit_tidy(); + } +/* + * Tidy punch information + */ + if (get_input_errors() == 0 && (new_punch || new_model)) + { + tidy_punch(); + } +/* + * Tidy solution information + */ + if (new_solution) + { + tidy_solutions(); + } + + /* if (new_model || new_exchange || new_pp_assemblage || new_surface || new_gas_phase || new_kinetics) reset_last_model(); */ + if (new_model) + { + reset_last_model(); + } +/* + * make sure essential species are defined + */ + if (s_h2o == NULL) + { + input_error++; + error_msg("H2O not defined.", STOP); + } + if (s_h2o->primary == NULL) + { + input_error++; + error_msg("H2O, primary master species for O, not defined.", + CONTINUE); + } + if (s_h2o->secondary == NULL) + { + input_error++; + error_msg("H2O, secondary master species for O(-2), not defined.", + CONTINUE); + } + if (s_hplus == NULL && s_h3oplus == NULL) + { + input_error++; + error_msg("Neither H+ nor H3O+ are defined in solution_species.", + STOP); + } + else if (s_hplus == NULL && s_h3oplus != NULL) + { + s_hplus = s_h3oplus; + s_h3oplus = NULL; + } + else if (s_hplus != NULL && s_h3oplus == NULL) + { + } + else if (s_hplus != NULL && s_h3oplus != NULL) + { + input_error++; + error_msg("Can not define both H+ and H3O+ in solution_species.", + STOP); + } + if (s_hplus->primary == NULL) + { + input_error++; + error_msg("H3O+, primary master species for H, not defined.", + CONTINUE); + } + if (s_hplus->secondary == NULL) + { + input_error++; + error_msg("H3O+, secondary master species for H(1), not defined.", + CONTINUE); + } + if (s_eminus == NULL) + { + input_error++; + error_msg("e- not defined in solution_species.", CONTINUE); + } + if (s_eminus->primary == NULL) + { + input_error++; + error_msg("e-, primary master species for E-, not defined.", + CONTINUE); + } + if (pitzer_model == FALSE || pitzer_pe == TRUE) + { + if (s_h2 == NULL) + { + input_error++; + error_msg("H2(aq) not defined in solution_species.", CONTINUE); + } + if (s_o2 == NULL) + { + input_error++; + error_msg("O2(aq) not defined in solution_species.", CONTINUE); + } + } + element_h_one = element_store("H(1)"); + if (element_h_one == NULL) + { + input_error++; + error_msg("H(1) not defined in solution_master_species.", CONTINUE); + } +/* + * Error check, program termination + */ + if (get_input_errors() > 0 || parse_error > 0) + { + error_msg("Calculations terminating due to input errors.", STOP); + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_species_input(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check species data for completeness + */ + int i; + int return_value; + + return_value = OK; + for (i = 0; i < count_s; i++) + { + if (s[i]->next_elt == NULL) + { + input_error++; + return_value = ERROR; + error_string = sformatf( + "Elements in species have not been tabulated, %s.", + s[i]->name); + error_msg(error_string, CONTINUE); + } + if (s[i]->rxn == NULL) + { + input_error++; + return_value = ERROR; + error_string = sformatf( + "Reaction for species has not been defined, %s.", + s[i]->name); + error_msg(error_string, CONTINUE); + } + else + { + select_log_k_expression(s[i]->logk, s[i]->rxn->logk); + add_other_logk(s[i]->rxn->logk, s[i]->count_add_logk, + s[i]->add_logk); + } + } + return (return_value); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +select_log_k_expression(LDBLE * source_k, LDBLE * target_k) +/* ---------------------------------------------------------------------- */ +{ + int j, analytic; + + analytic = FALSE; + for (j = T_A1; j <= T_A6; j++) + { + if (source_k[j] != 0.0) + { + analytic = TRUE; + break; + } + } + if (analytic == TRUE) + { + target_k[logK_T0] = 0.0; + target_k[delta_h] = 0.0; + for (j = T_A1; j <= T_A6; j++) + { + target_k[j] = source_k[j]; + } + } + else + { + target_k[logK_T0] = source_k[logK_T0]; + target_k[delta_h] = source_k[delta_h]; + for (j = T_A1; j <= T_A6; j++) + { + target_k[j] = 0.0; + } + } + for (j = delta_v; j < MAX_LOG_K_INDICES; j++) + { + target_k[j] = source_k[j]; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_logk(void) +/* ---------------------------------------------------------------------- */ +/* + * Picks log k expression + */ +{ + int i; + for (i = 0; i < count_logk; i++) + { + select_log_k_expression(logk[i]->log_k_original, logk[i]->log_k); + logk[i]->done = FALSE; + } + for (i = 0; i < count_logk; i++) + { + if (logk[i]->done == FALSE) + { + add_logks(logk[i], 0); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk) +/* ---------------------------------------------------------------------- */ +{ + int i, j, analytic; + struct logk *logk_ptr; + char token[MAX_LENGTH]; + LDBLE coef; + ENTRY item, *found_item; + + if (count_add_logk == 0) + return (OK); + for (i = 0; i < count_add_logk; i++) + { + coef = add_logk[i].coef; + strcpy(token, add_logk[i].name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + if (found_item == NULL) + { + input_error++; + error_string = sformatf( + "Could not find named temperature expression, %s\n", + token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + logk_ptr = (struct logk *) found_item->data; + analytic = FALSE; + for (j = T_A1; j <= T_A6; j++) + { + if (logk_ptr->log_k[j] != 0.0) + { + analytic = TRUE; + break; + } + } + if (analytic == TRUE) + { + for (j = T_A1; j <= T_A6; j++) + { + source_k[j] += logk_ptr->log_k[j] * coef; + } + } + else + { + source_k[logK_T0] += logk_ptr->log_k[logK_T0] * coef; + source_k[delta_h] += logk_ptr->log_k[delta_h] * coef; + } + for (j = delta_v; j < MAX_LOG_K_INDICES; j++) + { + source_k[j] += logk_ptr->log_k[j] * coef; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_logks(struct logk *logk_ptr, int repeats) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + struct logk *next_logk_ptr; + char token[MAX_LENGTH]; + LDBLE coef; + ENTRY item, *found_item; + /* + * Adds in other named_expressions to get complete log K + * Evaluates others recursively if necessary + */ + if (repeats > 15) + { + input_error++; + error_string = sformatf( "Circular definition of named_logk? %s\n", + logk_ptr->name); + error_msg(error_string, CONTINUE); + return (ERROR); + } + for (i = 0; i < logk_ptr->count_add_logk; i++) + { + coef = logk_ptr->add_logk[i].coef; + strcpy(token, logk_ptr->add_logk[i].name); + str_tolower(token); + item.key = token; + item.data = NULL; + found_item = hsearch_multi(logk_hash_table, item, FIND); + if (found_item == NULL) + { + input_error++; + error_string = sformatf( + "Could not find named temperature expression, %s\n", + token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + next_logk_ptr = (struct logk *) found_item->data; + if (next_logk_ptr->done == FALSE) + { + /*output_msg(sformatf( "Done == FALSE\n", token)); */ + if (add_logks(next_logk_ptr, repeats + 1) == ERROR) + { + return (ERROR); + } + } + for (j = 0; j < MAX_LOG_K_INDICES; j++) + { + logk_ptr->log_k[j] += next_logk_ptr->log_k[j] * coef; + } + } + logk_ptr->done = TRUE; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +coef_in_master(struct master * master_ptr) +/* ---------------------------------------------------------------------- */ +{ + int l; + LDBLE coef; + char *ptr; + char elt_name[MAX_LENGTH]; + struct elt_list *next_elt; + + coef = 0.0; + char * temp_name = string_duplicate(master_ptr->elt->name); + ptr = temp_name; + get_elt(&ptr, elt_name, &l); + free_check_null(temp_name); + for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL; + next_elt++) + { + if (strcmp(elt_name, next_elt->elt->name) == 0) + { + coef = next_elt->coef; + break; + } + } + return (coef); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rewrite_eqn_to_secondary(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for species in terms of secondary species + * Result is in trxn. + */ + LDBLE coef; + int repeat, i, add_count; + struct rxn_token_temp *token_ptr; +/* + * + */ + add_count = 0; + repeat = TRUE; +/* + * Reduce reaction equation to primary and secondary species + */ + while (repeat == TRUE) + { + repeat = FALSE; + /* Check for too many iterations */ + if (++add_count > MAX_ADD_EQUATIONS) + { + parse_error++; + error_string = sformatf( + "Could not reduce equation to secondary master species, %s.", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + break; + } + + for (i = 1; i < count_trxn; i++) + { + token_ptr = &(trxn.token[i]); + if (token_ptr->s == NULL) + { + error_string = sformatf( + "NULL species pointer for species, %s.", + token_ptr->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + if (token_ptr->s->secondary == NULL + && token_ptr->s->primary == NULL) + { + coef = token_ptr->coef; + trxn_add(token_ptr->s->rxn, coef, TRUE); + repeat = TRUE; + break; + } + } + } + trxn_combine(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +replace_solids_gases(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for species in terms of secondary species + * Result is in trxn. + */ + LDBLE coef; + int n; + int repeat, i, add_count; + struct rxn_token_temp *token_ptr; + struct phase *phase_ptr; + int replaced; + char token[MAX_LENGTH]; +/* + * + */ + add_count = 0; + repeat = TRUE; + replaced = FALSE; +/* + * Reduce reaction equation to primary and secondary species + */ + while (repeat == TRUE) + { + repeat = FALSE; + /* Check for too many iterations */ + if (++add_count > MAX_ADD_EQUATIONS) + { + parse_error++; + error_string = sformatf( + "Could not remove all solids and gases from equation, %s.", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + break; + } + + for (i = 1; i < count_trxn; i++) + { + token_ptr = &(trxn.token[i]); + if (token_ptr->s == NULL) + { + phase_ptr = phase_bsearch(token_ptr->name, &n, FALSE); + /* try phase name without (g) or (s) */ + if (phase_ptr == NULL) + { + strcpy(token, token_ptr->name); + replace("(g)", "", token); + replace("(s)", "", token); + replace("(G)", "", token); + replace("(S)", "", token); + phase_ptr = phase_bsearch(token, &n, FALSE); + } + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( "Phase not found, %s.", + token_ptr->name); + error_msg(error_string, CONTINUE); + break; + } + coef = token_ptr->coef; + /* add reaction for solid/gas */ + /* debug + output_msg(sformatf( "Reaction to add.\n")); + rxn_print(phase_ptr->rxn); + */ + trxn_add_phase(phase_ptr->rxn, coef, FALSE); + + /* remove solid/gas from trxn list */ + trxn.token[i].name = phase_ptr->rxn->token[0].name; + trxn.token[i].s = phase_ptr->rxn->token[0].s; + trxn.token[i].coef = -coef * phase_ptr->rxn->token[0].coef; + repeat = TRUE; + replaced = TRUE; + /* debug + output_msg(sformatf( "Before combined.\n")); + trxn_print(); + */ + /* combine */ + trxn_combine(); + /* debug + output_msg(sformatf( "Combined.\n")); + trxn_print(); + */ + break; + } + } + } + trxn_combine(); + return (replaced); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rewrite_eqn_to_primary(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Write equation for secondary master species in terms of primary master species + * Store result in reaction structure for master species + * rewrite if necessary. + * + */ + int repeat, j, add_count; + +/* + * Check secondary master species + */ + repeat = TRUE; + add_count = 0; +/* + * Check if reaction contains only primary master species + */ + while (repeat == TRUE) + { + repeat = FALSE; +/* + * Check for too many iterations + */ + if (++add_count > MAX_ADD_EQUATIONS) + { + parse_error++; + error_string = sformatf( + "Could not reduce equation to primary master species, %s.", + trxn.token[0].s->name); + error_msg(error_string, CONTINUE); + break; + } +/* + * Go through species in reaction for secondary master species, look for non-primary + * species as reactants, rewrite + */ + for (j = 1; j < count_trxn; j++) + { + if (trxn.token[j].s->primary == NULL) + { + trxn_add(trxn.token[j].s->rxn, trxn.token[j].coef, TRUE); + repeat = TRUE; + break; + } + } + } + trxn_combine(); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_gas_phase(void) +/* ---------------------------------------------------------------------- */ +{ + int n_user, last; + //struct phase *phase_ptr, **phase_ptrs; + LDBLE P, V_m; + bool PR; +/* + * Find all gases for each gas_phase in phase list + */ + std::map::iterator it = Rxn_gas_phase_map.begin(); + //for (i = 0; i < count_gas_phase; i++) + for ( ; it != Rxn_gas_phase_map.end(); it++) + { + cxxGasPhase *gas_phase_ptr = &(it->second); + if (gas_phase_ptr->Get_new_def() != TRUE) + continue; + gas_phase_ptr->Set_new_def(false); + PR = false; + P = 0.0; + //n_g = 0; + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gc.size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Gas not found in PHASES data base, %s.", + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + else + { + //gas_phase[i].comps[j].phase = phase_ptr; + if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) + PR = true; + } +/* + * Fixed pressure + */ + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_phase_ptr->Get_solution_equilibria()) + { + input_error++; + error_string = sformatf( + "Gas phase %d: can not use '-equilibrium' option with fixed pressure gas phase.", + gas_phase_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + } + /* calculate moles */ + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles( + gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: partial pressure of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + else + { +/* + * Fixed volume + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles ( + gc[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: moles of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + } + } + gas_phase_ptr->Set_gas_comps(gc); + //gas_phase[i].pr_in = PR; + gas_phase_ptr->Set_pr_in(PR); + + if (PR && P > 0) + { + std::vector phase_ptrs; + //phase_ptrs = new phase *[gas_phase[i].count_comps]; + //for (j = 0; j < gas_phase[i].count_comps; j++) + //std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + continue; + phase_ptr->moles_x = gc[j].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + //phase_ptrs[n_g] = gas_phase[i].comps[j].phase; + //n_g++; + } + V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); + gas_phase_ptr->Set_v_m(V_m); + gas_phase_ptr->Set_total_p(P); + //V_m = 1.0; + //for (j = 0; j < gas_phase[i].count_comps; j++) + //{ + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + { + gc[j].Set_moles(0.0); + } else + { + gc[j].Set_moles(phase_ptr->moles_x * + gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + } + } + gas_phase_ptr->Set_gas_comps(gc); + //delete phase_ptrs; + } +/* + * Duplicate gas phase, only if not solution equilibria + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + for (int j = n_user + 1; j <= last; j++) + { + //gas_phase_duplicate(n_user, j); + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + } + } + else + { + gas_phase_ptr->Set_new_def(true); + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_inverse(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * After all of data are read, fill in data for an inverse structure, + * including master species pointers, phase pointers, and uncertainties + * and a list of all elements from phases or -balance input. + */ + int i, j, k, l; + int count_in; + LDBLE value; + struct inv_elts *inv_elts; + struct master *master_ptr; + struct master *master_alk_ptr; + struct elt_list *elt_list_ptr; + master_alk_ptr = master_bsearch("Alkalinity"); + for (i = 0; i < count_inverse; i++) + { + if (inverse[i].new_def != TRUE) + continue; +/* + * Set default uncertainties for all solutions, if necessary + */ + if (inverse[i].count_uncertainties < inverse[i].count_solns) + { + inverse[i].uncertainties = + (LDBLE *) PHRQ_realloc(inverse[i].uncertainties, + (size_t) inverse[i].count_solns * + sizeof(LDBLE)); + if (inverse[i].uncertainties == NULL) + malloc_error(); + for (j = inverse[i].count_uncertainties; + j < inverse[i].count_solns; j++) + { + inverse[i].uncertainties[j] = + inverse[i].uncertainties[inverse[i].count_uncertainties - + 1]; + } + } +/* + * Set default ph uncertainties for all solutions, if necessary + */ + if (inverse[i].count_ph_uncertainties < inverse[i].count_solns) + { + inverse[i].ph_uncertainties = + (LDBLE *) PHRQ_realloc(inverse[i].ph_uncertainties, + (size_t) inverse[i].count_solns * + sizeof(LDBLE)); + if (inverse[i].ph_uncertainties == NULL) + malloc_error(); + for (j = inverse[i].count_ph_uncertainties; + j < inverse[i].count_solns; j++) + { + inverse[i].ph_uncertainties[j] = + inverse[i].ph_uncertainties[inverse[i]. + count_ph_uncertainties - 1]; + } + } +/* + * Set default force for all solutions + */ + if (inverse[i].count_force_solns < inverse[i].count_solns) + { + inverse[i].force_solns = + (int *) PHRQ_realloc(inverse[i].force_solns, + (size_t) inverse[i].count_solns * + sizeof(int)); + if (inverse[i].force_solns == NULL) + malloc_error(); + for (j = inverse[i].count_force_solns; j < inverse[i].count_solns; + j++) + { + inverse[i].force_solns[j] = FALSE; + } + } +/* + * Find master species for element, set uncertainties + */ + for (j = 0; j < inverse[i].count_elts; j++) + { + inverse[i].elts[j].master = + master_bsearch_primary(inverse[i].elts[j].name); + if (inverse[i].elts[j].master == NULL) + { + input_error++; + error_string = sformatf( "No master species for element, %s.", + inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + inverse[i].elts[j].uncertainties = + (LDBLE *) PHRQ_realloc(inverse[i].elts[j].uncertainties, + (size_t) inverse[i].count_solns * + sizeof(LDBLE)); + if (inverse[i].elts[j].uncertainties == NULL) + malloc_error(); + if (inverse[i].elts[j].count_uncertainties == 0) + { +/* use default uncertainties for element */ + for (k = 0; k < inverse[i].count_solns; k++) + { + inverse[i].elts[j].uncertainties[k] = + inverse[i].uncertainties[k]; + } + } + else if (inverse[i].elts[j].count_uncertainties < + inverse[i].count_solns) + { +/* use input uncertainties, fill in any missing at end */ + value = + inverse[i].elts[j].uncertainties[inverse[i].elts[j]. + count_uncertainties - 1]; + for (k = inverse[i].elts[j].count_uncertainties; + k < inverse[i].count_solns; k++) + { + inverse[i].elts[j].uncertainties[k] = value; + } + } + } +/* + * Find phase + */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < inverse[i].count_phases; j++) + { + inverse[i].phases[j].phase = + phase_bsearch(inverse[i].phases[j].name, &k, FALSE); + if (inverse[i].phases[j].phase == NULL) + { + input_error++; + error_string = sformatf( "Could not find phase, %s.", + inverse[i].phases[j].name); + error_msg(error_string, CONTINUE); + continue; + } +/* + * Find isotope elements + */ + if (inverse[i].phases[j].count_isotopes > 0) + { + for (k = 0; k < inverse[i].phases[j].count_isotopes; k++) + { + inverse[i].phases[j].isotopes[k].primary = NULL; + inverse[i].phases[j].isotopes[k].master = NULL; + master_ptr = + master_bsearch(inverse[i].phases[j].isotopes[k]. + elt_name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Element not found for isotope calculation: %s.", + inverse[i].phases[j].isotopes[k].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary != TRUE) + { + input_error++; + error_string = sformatf( + "Isotope ratio may only be used" + " for total element in phase.\n" + "Secondary species not allowed: %s.", + master_ptr->elt->name); + error_msg(error_string, CONTINUE); + continue; + } + inverse[i].phases[j].isotopes[k].primary = master_ptr; + inverse[i].phases[j].isotopes[k].master = master_ptr; + /* find coefficient for element */ + for (elt_list_ptr = inverse[i].phases[j].phase->next_elt; + elt_list_ptr->elt != NULL; elt_list_ptr++) + { + if (elt_list_ptr->elt == master_ptr->elt) + { + inverse[i].phases[j].isotopes[k].coef = + elt_list_ptr->coef; + break; + } + } + if (elt_list_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Element, %s,for which isotope ratio was defined is not found in phase, %s", + master_ptr->elt->name, + inverse[i].phases[j].phase->name); + error_msg(error_string, CONTINUE); + continue; + } + } + qsort(inverse[i].phases[j].isotopes, + (size_t) inverse[i].phases[j].count_isotopes, + (size_t) sizeof(struct isotope), isotope_compare); + } + add_elt_list(inverse[i].phases[j].phase->next_elt, 1.0); + + } + if (get_input_errors() > 0) + return (ERROR); +/* + * Sort elements in reaction and combine + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } +/* + * Mark master species list + */ + for (j = 0; j < count_master; j++) + master[j]->in = FALSE; + for (j = 0; j < count_elts; j++) + { + elt_list[j].elt->master->in = TRUE; + } + /* Include all input elements */ + for (j = 0; j < inverse[i].count_elts; j++) + { + inverse[i].elts[j].master->in = TRUE; + } + s_eminus->primary->in = TRUE; /* Include electrons */ + master_alk_ptr->in = TRUE; /* Include alkalinity */ +/* + * Unmark primary and mark secondary master species for redox elements + */ + count_in = 0; + inverse[i].count_redox_rxns = 0; + for (j = 0; j < count_master; j++) + { + /* skip all secondary master species in this loop */ + if (master[j]->primary == FALSE || master[j]->in == FALSE) + continue; + count_in++; + if (j + 1 == count_master) + continue; + /* if next master species is secondary, mark all + secondary master species until a primary is found */ + if (master[j + 1]->primary == FALSE) + { + master[j]->in = FALSE; + count_in--; + for (k = j + 1; k < count_master; k++) + { + if (master[k]->primary == FALSE) + { + count_in++; + master[k]->in = TRUE; + if (master[k]->s->primary == NULL) + { + inverse[i].count_redox_rxns++; + } + } + else + { + break; + } + } + } + } +/* + * Save list of master species in inv_elts structure + */ + inv_elts = + (struct inv_elts *) PHRQ_malloc((size_t) (count_in) * + sizeof(struct inv_elts)); + if (inv_elts == NULL) + malloc_error(); + count_in = 0; + for (j = 0; j < count_master; j++) + { + /* skip H(1) and O(-2) */ + if (master[j]->s == s_hplus || master[j]->s == s_h2o) + continue; + if (master[j]->in == TRUE) + { + /* set master */ + inv_elts[count_in].master = master[j]; + /* alloc uncertainties and set default */ + inv_elts[count_in].uncertainties = + (LDBLE *) PHRQ_malloc((size_t) inverse[i].count_solns * + sizeof(LDBLE)); + if (inv_elts[count_in].uncertainties == NULL) + malloc_error(); + for (k = 0; k < inverse[i].count_solns; k++) + { + inv_elts[count_in].uncertainties[k] = + inverse[i].uncertainties[k]; + } + count_in++; + } + } + if (s_co3->secondary->in == TRUE) + { + inverse[i].carbon = TRUE; + } + else + { + inverse[i].carbon = FALSE; + } +/* + * copy in input uncertainties + */ + /* copy primary redox to all secondary redox */ + for (j = 0; j < inverse[i].count_elts; j++) + { + master_ptr = master_bsearch(inverse[i].elts[j].name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Element not found, %s.", + inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary == FALSE + || master_ptr->s->secondary == NULL) + continue; + for (k = 0; k < count_in; k++) + { + if (master_ptr == inv_elts[k].master->elt->primary) + { + for (l = 0; l < inverse[i].count_solns; l++) + { + inv_elts[k].uncertainties[l] = + inverse[i].elts[j].uncertainties[l]; + } + } + } + inverse[i].elts[j].uncertainties = + (LDBLE *) free_check_null(inverse[i].elts[j].uncertainties); + } + /* copy masters that are not primary redox */ + for (j = 0; j < inverse[i].count_elts; j++) + { + master_ptr = master_bsearch(inverse[i].elts[j].name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Element not found, %s.", + inverse[i].elts[j].name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->primary == TRUE + && master_ptr->s->secondary != NULL) + continue; + for (k = 0; k < count_in; k++) + { + if (master_ptr == inv_elts[k].master) + { + for (l = 0; l < inverse[i].count_solns; l++) + { + inv_elts[k].uncertainties[l] = + inverse[i].elts[j].uncertainties[l]; + } + break; + } + } + inverse[i].elts[j].uncertainties = + (LDBLE *) free_check_null(inverse[i].elts[j].uncertainties); + } +/* + * replace elts in inverse struct + */ + inverse[i].elts = + (struct inv_elts *) free_check_null(inverse[i].elts); + inverse[i].elts = inv_elts; + inverse[i].count_elts = count_in; + for (j = 0; j < inverse[i].count_elts; j++) + { +/* debug + output_msg(sformatf( "\t%d\t%s", j, inverse[i].elts[j].master->elt->name)); + for (k = 0; k < inverse[i].count_solns; k++) { + output_msg(sformatf( "\t%f", inverse[i].elts[j].uncertainties[k])); + } + output_msg(sformatf("\n")); + */ + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_phases(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + int replaced; + /* + * Fix log Ks first, so they can possibly be added to other phase equations + */ + for (i = 0; i < count_phases; i++) + { + select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk); + add_other_logk(phases[i]->rxn->logk, phases[i]->count_add_logk, + phases[i]->add_logk); + phases[i]->rxn->token[0].name = phases[i]->name; + phases[i]->rxn->token[0].s = NULL; + } + /* + * Rewrite all phases to secondary species + */ + for (i = 0; i < count_phases; i++) + { + /* + * Rewrite equation + */ + count_trxn = 0; + trxn_add_phase(phases[i]->rxn, 1.0, FALSE); + trxn.token[0].name = phases[i]->name; + /* debug + output_msg(sformatf( "%s PHASE.\n", phases[i]->name)); + trxn_print(); + */ + replaced = replace_solids_gases(); + phases[i]->replaced = replaced; + /* save rxn */ + /* + rxn_free(phases[i]->rxn); + phases[i]->rxn = rxn_alloc(count_trxn + 1); + trxn_copy(phases[i]->rxn); + */ + /* save rxn_s */ + trxn_reverse_k(); + rewrite_eqn_to_secondary(); + trxn_reverse_k(); + rxn_free(phases[i]->rxn_s); + phases[i]->rxn_s = rxn_alloc(count_trxn + 1); + trxn_copy(phases[i]->rxn_s); + /* + * Check equation + */ + if (phases[i]->check_equation == TRUE) + { + if (replaced == FALSE) + { + phase_rxn_to_trxn(phases[i], phases[i]->rxn); + } + else + { + phase_rxn_to_trxn(phases[i], phases[i]->rxn_s); + } + if (check_eqn(FALSE) == ERROR) + { + input_error++; + error_string = sformatf( + "Equation for phase %s does not balance.", + phases[i]->name); + error_msg(error_string, CONTINUE); + } + } + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + //int i, j, k, l, n_user, first, last; + //struct phase *phase_ptr; + LDBLE coef; + char *ptr; +/* + * Find pointers for pure phases + */ + std::map::iterator it; + it = Rxn_pp_assemblage_map.begin(); + for ( ; it != Rxn_pp_assemblage_map.end(); it++) + { + cxxPPassemblage *pp_assemblage_ptr = &(it->second); + count_elts = 0; + paren_count = 0; + coef = 1.0; + pp_assemblage_ptr->Set_new_def(false); + + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + int k; + struct phase *phase_ptr = phase_bsearch(it->first.c_str(), &k, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( "Phase not found in data base, %s.", + it->first.c_str()); + error_msg(error_string, CONTINUE); + continue; + } + else + { + //pp_assemblage[i].pure_phases[j].phase = phase_ptr; + add_elt_list(phase_ptr->next_elt, coef); + + } + if (it->second.Get_add_formula().size() > 0) + { + int first = count_elts; + phase_ptr = phase_bsearch(it->second.Get_add_formula().c_str(), &k, FALSE); + if (phase_ptr != NULL) + { + //pp_assemblage[i].pure_phases[j].add_formula = phase_ptr->formula; + it->second.Set_add_formula(phase_ptr->formula); + } + { + char * temp_add = string_duplicate(it->second.Get_add_formula().c_str()); + ptr = temp_add; + get_elts_in_species(&ptr, coef); + free_check_null(temp_add); + } + /* check that all elements are in the database */ + for (int l = first; l < count_elts; l++) + { + if (elt_list[l].elt->master == NULL) + { + input_error++; + error_string = sformatf( + "Element \"%s\" in alternative phase for \"%s\" in EQUILIBRIUM_PHASES not found in database.", + elt_list[l].elt->name, + it->first.c_str()); + error_msg(error_string, CONTINUE); + } + } + } + } + +/* + * Store list with all elements in phases and add formulae + */ + cxxNameDouble nd = elt_list_NameDouble(); + pp_assemblage_ptr->Set_eltList(nd); +/* + * Duplicate pure phases if necessary + */ + + int n_user = pp_assemblage_ptr->Get_n_user(); + int n_user_end = pp_assemblage_ptr->Get_n_user_end(); + pp_assemblage_ptr->Set_n_user_end(n_user); + Utilities::Rxn_copies(Rxn_pp_assemblage_map, n_user, n_user_end); + + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_pp_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, l, n_user, first, last; + struct phase *phase_ptr; + LDBLE coef; + char *ptr; +/* + * Find pointers for pure phases + */ + for (i = 0; i < count_pp_assemblage; i++) + { + count_elts = 0; + paren_count = 0; + coef = 1.0; + pp_assemblage[i].new_def = FALSE; + for (j = 0; j < pp_assemblage[i].count_comps; j++) + { + phase_ptr = + phase_bsearch(pp_assemblage[i].pure_phases[j].name, &k, + FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( "Phase not found in data base, %s.", + pp_assemblage[i].pure_phases[j].name); + error_msg(error_string, CONTINUE); + continue; + } + else + { + pp_assemblage[i].pure_phases[j].phase = phase_ptr; + add_elt_list(phase_ptr->next_elt, coef); + + } + if (pp_assemblage[i].pure_phases[j].add_formula != NULL) + { + first = count_elts; + phase_ptr = + phase_bsearch(pp_assemblage[i].pure_phases[j]. + add_formula, &k, FALSE); + if (phase_ptr != NULL) + { + pp_assemblage[i].pure_phases[j].add_formula = + phase_ptr->formula; + } + { + char * temp_add = string_duplicate(pp_assemblage[i].pure_phases[j].add_formula); + ptr = temp_add; + get_elts_in_species(&ptr, coef); + free_check_null(temp_add); + } + /* check that all elements are in the database */ + for (l = first; l < count_elts; l++) + { + if (elt_list[l].elt->master == NULL) + { + input_error++; + error_string = sformatf( + "Element \"%s\" in alternative phase for \"%s\" in EQUILIBRIUM_PHASES not found in database.", + elt_list[l].elt->name, + pp_assemblage[i].pure_phases[j].name); + error_msg(error_string, CONTINUE); + } + } + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + pp_assemblage[i].next_elt = + (struct elt_list *) free_check_null(pp_assemblage[i].next_elt); + pp_assemblage[i].next_elt = elt_list_save(); + +/* + * Store list with all elements in phases and add formulae + */ + +/* + * Duplicate pure phases if necessary + */ + if (pp_assemblage[i].n_user_end > pp_assemblage[i].n_user) + { + n_user = pp_assemblage[i].n_user; + last = pp_assemblage[i].n_user_end; + pp_assemblage[i].n_user_end = pp_assemblage[i].n_user; + for (j = n_user + 1; j <= last; j++) + { + pp_assemblage_duplicate(n_user, j); + } + } + } + return (OK); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, k1, n_user, last; + struct phase *phase_ptr; + struct s_s *s_s_ptr; + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE moles; +/* + * Find pointers for pure phases + */ + for (i = 0; i < count_ss_assemblage; i++) + { + count_elts = 0; + paren_count = 0; + for (j = 0; j < ss_assemblage[i].count_s_s; j++) + { + for (k = 0; k < ss_assemblage[i].s_s[j].count_comps; k++) + { + phase_ptr = + phase_bsearch(ss_assemblage[i].s_s[j].comps[k].name, + &k1, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Phase not found in data base, %s, assemblage %d.", + ss_assemblage[i].s_s[j].comps[k].name, + ss_assemblage[i].n_user); + error_msg(error_string, CONTINUE); + ss_assemblage[i].s_s[j].comps[k].phase = NULL; + continue; + } + else + { + ss_assemblage[i].s_s[j].comps[k].phase = phase_ptr; + ss_assemblage[i].s_s[j].comps[k].phase->moles_x = 0; + ss_assemblage[i].s_s[j].comps[k].phase->fraction_x = 0; + } + if (ss_assemblage[i].s_s[j].comps[k].moles == NAN) + { + input_error++; + error_string = sformatf( + "Moles of solid solution component not defined, %s, assemblage %d.", + ss_assemblage[i].s_s[j].comps[k].name, + ss_assemblage[i].n_user); + error_msg(error_string, CONTINUE); + continue; + } + } + + if (ss_assemblage[i].new_def == TRUE) + { + /* + * Calculate a0 and a1 first + */ + s_s_calc_a0_a1(&(ss_assemblage[i].s_s[j])); + s_s_ptr = &(ss_assemblage[i].s_s[j]); + + n_tot = 0; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + moles = ss_assemblage[i].s_s[j].comps[k].moles; + if (ss_assemblage[i].s_s[j].comps[k].moles <= 0.0) + { + moles = MIN_TOTAL_SS; + ss_assemblage[i].s_s[j].comps[k].initial_moles = + moles; + } + n_tot += moles; + } + + for (k = 0; k < s_s_ptr->count_comps; k++) + { + moles = ss_assemblage[i].s_s[j].comps[k].moles; + if (ss_assemblage[i].s_s[j].comps[k].moles <= 0.0) + { + moles = MIN_TOTAL_SS; + } + ss_assemblage[i].s_s[j].comps[k].fraction_x = + moles / n_tot; + ss_assemblage[i].s_s[j].comps[k].log10_fraction_x = + log10(moles / n_tot); + } + l_a0 = ss_assemblage[i].s_s[j].a0; + l_a1 = ss_assemblage[i].s_s[j].a1; + +/* + * Binary solid solution + */ + if (l_a0 != 0.0 || l_a1 != 0) + { + ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; + nc = ss_assemblage[i].s_s[j].comps[0].moles; + if (nc == 0) + nc = MIN_TOTAL_SS; + nb = ss_assemblage[i].s_s[j].comps[1].moles; + if (nb == 0) + nb = MIN_TOTAL_SS; + xc = nc / n_tot; + xb = nb / n_tot; + + /* lambdas */ + ss_assemblage[i].s_s[j].comps[0].log10_lambda = + xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; + ss_assemblage[i].s_s[j].comps[1].log10_lambda = + xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; + + /* derivatives wrt nc and nb */ + xc2 = xc * xc; + xc3 = xc2 * xc; + xb2 = xb * xb; + xb3 = xb2 * xb; + xb4 = xb3 * xb; + + /* component 1 */ + dnb = + -2 * l_a0 * xb * xc2 - 8 * l_a1 * xb2 * xc2 + + 6 * l_a1 * xb * xc2 - 4 * l_a1 * xc * xb4 - + 8 * l_a1 * xb3 * xc2 - 4 * l_a1 * xb2 * xc3 - + 2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + + 6 * l_a1 * xc * xb2 + 1; + ss_assemblage[i].s_s[j].comps[0].dnb = dnb / n_tot; + dnc = + 2 * l_a0 * xb3 + 2 * l_a0 * xc * xb2 + 8 * l_a1 * xb4 + + 8 * l_a1 * xc * xb3 - 2 * l_a1 * xb3 - 6 * l_a1 * xc * xb2; + ss_assemblage[i].s_s[j].comps[0].dnc = + -xb / nc + dnc / n_tot; + ss_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; + + /* component 2 */ + dnb = + 2 * l_a0 * xb * xc2 + 2 * l_a0 * xc3 + + 8 * l_a1 * xb2 * xc2 + 8 * l_a1 * xb * xc3 - + 2 * l_a1 * xb * xc2 - 6 * l_a1 * xc3; + ss_assemblage[i].s_s[j].comps[1].dnb = + -xc / nb + dnb / n_tot; + dnc = + -2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + + 2 * l_a1 * xc * xb2 - 2 * l_a0 * xb * xc2 - + 8 * l_a1 * xb2 * xc2 + 6 * l_a1 * xb * xc2 + 1; + ss_assemblage[i].s_s[j].comps[1].dnc = dnc / n_tot; + + s_s_prep(ss_assemblage[i].s_s[j].tk, + &(ss_assemblage[i].s_s[j]), TRUE); + ss_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; +/* + * Ideal solid solution + */ + } + else + { + ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; + for (k = 0; k < s_s_ptr->count_comps; k++) + { + ss_assemblage[i].s_s[j].comps[k].log10_lambda = 0; + moles = ss_assemblage[i].s_s[j].comps[k].moles; + if (moles <= 0.0) + moles = MIN_TOTAL_SS; + ss_assemblage[i].s_s[j].comps[k].dnb = + (n_tot - moles) / (moles * n_tot); + ss_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; + } + } + } + } + ss_assemblage[i].new_def = FALSE; + +/* + * Duplicate ss_assemblage if necessary + */ + n_user = ss_assemblage[i].n_user; + last = ss_assemblage[i].n_user_end; + ss_assemblage[i].n_user_end = ss_assemblage[i].n_user; + for (j = n_user + 1; j <= last; j++) + { + ss_assemblage_duplicate(n_user, j); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_punch(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, l; + int punch_save; + char token[MAX_LENGTH]; +/* + * tidy punch information + */ + if (punch.high_precision == FALSE) + { + l = 12; + } + else + { + l = 20; + } + if (punch.in == TRUE) + { + /* totals */ + + for (i = 0; i < punch.count_totals; i++) + { + punch.totals[i].master = master_bsearch(punch.totals[i].name); + } + + /* molalities */ + + for (i = 0; i < punch.count_molalities; i++) + { + punch.molalities[i].s = s_search(punch.molalities[i].name); + } + + /* log activities */ + + for (i = 0; i < punch.count_activities; i++) + { + punch.activities[i].s = s_search(punch.activities[i].name); + } + + /* equilibrium phases */ + + for (i = 0; i < punch.count_pure_phases; i++) + { + punch.pure_phases[i].phase = + phase_bsearch(punch.pure_phases[i].name, &j, FALSE); + } + + /* saturation indices */ + + for (i = 0; i < punch.count_si; i++) + { + punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); + } + + /* gases */ + + for (i = 0; i < punch.count_gases; i++) + { + punch.gases[i].phase = + phase_bsearch(punch.gases[i].name, &j, FALSE); + } + } + /* + * Always write new headings when SELECTED_OUTPUT is read + */ + if (punch.new_def == TRUE && punch.in == TRUE) + { + punch_save = pr.punch; + pr.punch = TRUE; + phrq_io->Set_punch_on(true); + + /* constant stuff, sim, pH, etc. */ + + if (punch.sim == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "sim")); + } + if (punch.state == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "state")); + } + if (punch.soln == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "soln")); + } + if (punch.dist == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "dist_x")); + } + if (punch.time == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "time")); + } + if (punch.step == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "step")); + } + if (punch.ph == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pH")); + } + if (punch.pe == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pe")); + } + if (punch.rxn == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "reaction")); + } + if (punch.temp == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "temp")); + } + if (punch.alk == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "Alk")); + } + if (punch.mu == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mu")); + } + if (punch.water == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mass_H2O")); + } + if (punch.charge_balance == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "charge")); + } + if (punch.percent_error == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pct_err")); + } + /* totals */ + + for (i = 0; i < punch.count_totals; i++) + { + fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name)); + if (punch.totals[i].master == NULL) + { + error_string = sformatf( "Did not find master species," + " %s.", punch.totals[i].name); + warning_msg(error_string); + } + } + + /* molalities */ + + for (i = 0; i < punch.count_molalities; i++) + { + strcpy(token, "m_"); + strcat(token, punch.molalities[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + if (punch.molalities[i].s == NULL) + { + error_string = sformatf( "Did not find species," + " %s.", punch.molalities[i].name); + warning_msg(error_string); + } + } + + /* log activities */ + + for (i = 0; i < punch.count_activities; i++) + { + strcpy(token, "la_"); + strcat(token, punch.activities[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + if (punch.activities[i].s == NULL) + { + error_string = sformatf( "Did not find species, " + "%s.", punch.activities[i].name); + warning_msg(error_string); + } + } + + /* equilibrium phases */ + + for (i = 0; i < punch.count_pure_phases; i++) + { + strcpy(token, "d_"); + strcat(token, punch.pure_phases[i].name); + fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name)); + fpunchf_heading(sformatf("%*s\t", l, token)); + if (punch.pure_phases[i].phase == NULL) + { + error_string = sformatf( "Did not find phase, " + "%s.", punch.pure_phases[i].name); + warning_msg(error_string); + } + } + + /* saturation indices */ + + for (i = 0; i < punch.count_si; i++) + { + strcpy(token, "si_"); + strcat(token, punch.si[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + if (punch.si[i].phase == NULL) + { + error_string = sformatf( "Did not find phase, " + "%s.", punch.si[i].name); + warning_msg(error_string); + } + } + + /* gases */ + + if (punch.count_gases > 0) + { + fpunchf_heading(sformatf("%*s\t", l, "pressure")); + fpunchf_heading(sformatf("%*s\t", l, "total mol")); + fpunchf_heading(sformatf("%*s\t", l, "volume")); + } + for (i = 0; i < punch.count_gases; i++) + { + strcpy(token, "g_"); + strcat(token, punch.gases[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + if (punch.gases[i].phase == NULL) + { + error_string = sformatf( "Did not find phase, " + "%s.", punch.gases[i].name); + warning_msg(error_string); + } + } + + /* kinetics */ + + for (i = 0; i < punch.count_kinetics; i++) + { + strcpy(token, "k_"); + strcat(token, punch.kinetics[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + strcpy(token, "dk_"); + strcat(token, punch.kinetics[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* solid solutions */ + + for (i = 0; i < punch.count_s_s; i++) + { + strcpy(token, "s_"); + strcat(token, punch.s_s[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* isotopes */ + + for (i = 0; i < punch.count_isotopes; i++) + { + if (isotope_ratio_search(punch.isotopes[i].name) == NULL) + { + error_string = sformatf( + "Did not find isotope_ratio definition for " + "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", + punch.isotopes[i].name, punch.isotopes[i].name); + warning_msg(error_string); + } + strcpy(token, "I_"); + strcat(token, punch.isotopes[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* calculate_values */ + + for (i = 0; i < punch.count_calculate_values; i++) + { + if (calculate_value_search(punch.calculate_values[i].name) == NULL) + { + error_string = sformatf( + "Did not find calculate_values definition for " + "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", + punch.calculate_values[i].name, + punch.calculate_values[i].name); + warning_msg(error_string); + } + strcpy(token, "V_"); + strcat(token, punch.calculate_values[i].name); + fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* user_punch */ + if (punch.user_punch == TRUE) + { + for (i = 0; i < user_punch_count_headings; i++) + { + fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); + } + } + fpunchf_heading("\n"); + + punch.new_def = FALSE; + pr.punch = punch_save; + phrq_io->Set_punch_on(pr.punch == TRUE); + } + punch_flush(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_species(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + struct master *master_ptr; + char c, *ptr; +/* + * Make sure species pointers are ok + */ + if (check_species_input() == ERROR) + { + error_msg("Calculations terminating due to input errors.", STOP); + } +/* + * Set secondary and primary pointers in species structures + */ + for (i = 0; i < count_s; i++) + { + s[i]->number = i; + s[i]->primary = NULL; + s[i]->secondary = NULL; + if (s[i]->check_equation == TRUE) + { + species_rxn_to_trxn(s[i]); + if (check_eqn(TRUE) == ERROR) + { + input_error++; + error_string = sformatf( + "Equation for species %s does not balance.", + s[i]->name); + error_msg(error_string, CONTINUE); + } + } + } + for (i = 0; i < count_master; i++) + { + char * temp_name = string_duplicate(master[i]->elt->name); + ptr = temp_name; + if (ptr[0] != '[') + { + while ((c = (int) *(++ptr)) != '\0') + { + if (isupper((int) c)) + { + input_error++; + error_string = sformatf( + "Element or valence name in SOLUTION_MASTER_SPECIES should include only one element, %s.", + master[i]->elt->name); + error_msg(error_string, CONTINUE); + break; + } + } + } + free_check_null(temp_name); + /* store sequence number in master structure */ + master[i]->number = i; + if (strcmp(master[i]->elt->name, "Alkalinity") != 0) + { + if (master[i]->primary == TRUE) + { + master[i]->s->primary = master[i]; + } + else + { + master[i]->s->secondary = master[i]; + } + } + if (strcmp(master[i]->elt->name, "C") == 0) + { + s_co3 = master[i]->s; + } + if (master[i]->gfw_formula != NULL) + { + if (compute_gfw(master[i]->gfw_formula, &master[i]->gfw) == ERROR) + { + input_error++; + error_string = sformatf( + "Calculating gfw for master species, %s, formula %s.", + master[i]->elt->name, master[i]->gfw_formula); + error_msg(error_string, CONTINUE); + } + } + } +/* + * Write equations for all master species in terms of primary + * master species, set coefficient of element in master species + */ + for (i = 0; i < count_master; i++) + { + count_trxn = 0; + if (master[i]->s->primary != NULL) + { + trxn_add(master[i]->s->rxn, 1.0, FALSE); + trxn_add(master[i]->s->rxn, -1.0, TRUE); + } + else + { + trxn_add(master[i]->s->rxn, 1.0, FALSE); + rewrite_eqn_to_primary(); + } + rxn_free(master[i]->rxn_primary); + master[i]->rxn_primary = rxn_alloc(count_trxn + 1); + trxn_copy(master[i]->rxn_primary); + master[i]->coef = coef_in_master(master[i]); + } +/* + * Rewrite all species to secondary species + */ + for (i = 0; i < count_s; i++) + { + count_trxn = 0; + if (s[i]->primary != NULL || s[i]->secondary != NULL) + { + trxn_add(s[i]->rxn, 1.0, FALSE); + trxn_add(s[i]->rxn, -1.0, TRUE); + } + else + { + trxn_add(s[i]->rxn, 1.0, FALSE); + rewrite_eqn_to_secondary(); + } + rxn_free(s[i]->rxn_s); + s[i]->rxn_s = rxn_alloc(count_trxn + 1); + trxn_copy(s[i]->rxn_s); + /* calculate alkalinity */ + s[i]->alk = calc_alk(s[i]->rxn_s); + /* set co2 coefficient */ + s[i]->co2 = 0.0; + for (j = 1; j < count_trxn; j++) + { + if (trxn.token[j].s == s_co3) + { + s[i]->co2 = trxn.token[j].coef; + break; + } + } + } +/* + * Set pointer in element to master species + */ + for (i = 0; i < count_elements; i++) + { + elements[i]->master = master_bsearch(elements[i]->name); + if (elements[i]->master == NULL) + { + input_error++; + error_string = sformatf( "No master species for element %s.", + elements[i]->name); + error_msg(error_string, CONTINUE); + } + elements[i]->primary = master_bsearch_primary(elements[i]->name); + if (elements[i]->primary == NULL) + { + input_error++; + error_string = sformatf( "No master species for element %s.", + elements[i]->name); + error_msg(error_string, CONTINUE); + } + } +/* + * Make sure all primary master species for redox elements + * are also secondary master species + */ + for (i = 0; i < count_master; i++) + { + if (master[i]->primary == FALSE) + { + master_ptr = master[i]->s->secondary->elt->primary; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Every primary master species for a redox element\n" + "\tmust also be a secondary master species.\n" + "\tError in definitions related to %s .\n", + master[i]->s->name); + error_msg(error_string, CONTINUE); + + } + else if (master_ptr->s->secondary == NULL) + { + input_error++; + error_string = sformatf( + "Every primary master species for a redox element\n" + "\tmust also be a secondary master species.\n" + "\t%s is the primary master species for element %s.\n" + "\tAnother entry in SOLUTION_MASTER_SPECIES is needed.\n" + "\tDefine species %s as a secondary master species for a valence state.\n" + "\tFor example: \n" "\t%s(0)\t%s alk gfw", + master_ptr->s->name, master_ptr->elt->name, + master_ptr->s->name, master_ptr->elt->name, + master_ptr->s->name); + error_msg(error_string, CONTINUE); + } + } + } +/* + * Calculate H and O if alternate mass balance is given + */ + for (i = 0; i < count_s; i++) + { + if (s[i]->next_secondary != NULL) + { + s[i]->h = 0.0; + s[i]->o = 0.0; + for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) + { + if (s[i]->next_secondary[j].elt->primary == NULL) + continue; + if (s[i]->next_secondary[j].elt->primary->s == s_hplus || s[i]->next_secondary[j].elt->primary->s == s_h3oplus) + { + s[i]->h += s[i]->next_secondary[j].coef; + } + else if (s[i]->next_secondary[j].elt->primary->s == s_h2o) + { + s[i]->o += s[i]->next_secondary[j].coef; + } + else if (s[i]->mole_balance != NULL) + { + master_ptr = s[i]->next_secondary[j].elt->master; + if (master_ptr != NULL) + { + if (master_ptr->primary == TRUE) + { + if (master_ptr->s->secondary != NULL) + { + master_ptr = master_ptr->s->secondary; + } + } + } + else + { + input_error++; + error_string = sformatf( + "Element in -mole_balance %s not defined for species %s.\n", s[i]->mole_balance, s[i]->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->coef != 1) + { + s[i]->next_secondary[j].coef /= master_ptr->coef; + } + } + } + if (s[i]->type == EX) + { + for (j = 0; s[i]->next_secondary[j].elt != NULL; j++) + { + if (s[i]->next_secondary[j].elt->primary->s->type == EX) + { + s[i]->equiv = s[i]->next_secondary[j].coef; + break; + } + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * After all of data are read, fill in master species for surface comps + * Sort surface + */ + int i, j, k; + char *ptr1; + struct surface *surface_ptr; + struct master *master_ptr; + + for (k = 0; k < count_surface; k++) + { + surface_ptr = &surface[k]; + + for (i = 0; i < surface_ptr->count_comps; i++) + { +/* + * Find master species for each surface + */ + for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) + { + master_ptr = surface_ptr->comps[i].totals[j].elt->master; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Master species not in data base for %s, " + "skipping element.", + surface_ptr->comps[i].totals[j].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) + continue; +/* + * Set flags + */ + surface_ptr->comps[i].master = master_ptr; + /* + * Calculate moles of sites + */ + if (surface_ptr->new_def == TRUE + && surface_ptr->sites_units == SITES_DENSITY + && surface_ptr->comps[i].phase_name == NULL) + { + surface_ptr->comps[i].moles = + surface_ptr->comps[i].moles * 1.0e18 * + surface_ptr->charge[surface_ptr->comps[i].charge]. + specific_area * + surface_ptr->charge[surface_ptr->comps[i].charge]. + grams / AVOGADRO; + /* + * Calculate totals + */ + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(surface_ptr->comps[i].formula); + ptr1 = temp_formula; + get_elts_in_species(&ptr1, surface_ptr->comps[i].moles); + free_check_null(temp_formula); + } + surface_ptr->comps[i].formula_totals = + (struct elt_list *) free_check_null(surface_ptr-> + comps[i]. + formula_totals); + surface_ptr->comps[i].formula_totals = elt_list_save(); + surface_ptr->comps[i].totals = + (struct elt_list *) free_check_null(surface_ptr-> + comps[i].totals); + surface_ptr->comps[i].totals = elt_list_save(); + } + if (surface_ptr->type == CD_MUSIC) + { + /* + surface_ptr->charge[surface_ptr->comps[i].charge].charge_balance += surface_ptr->comps[i].moles*surface_ptr->comps[i].master->s->z; + */ + surface_ptr->charge[surface_ptr->comps[i].charge]. + charge_balance += + surface_ptr->comps[i].moles * + surface_ptr->comps[i].formula_z; + + } + break; + } +#ifdef SKIP_MUSIC + /* + * If charge of formula is non zero + */ + if (surface_ptr->type == CD_MUSIC) + { + surface_ptr->comps[i].cb = + surface_ptr->comps[i].formula_z * + surface_ptr->comps[i].moles; + } +#endif + } + /* + * Check that all surface comps have a corresponding master + */ + for (i = 0; i < surface_ptr->count_comps; i++) + { + if (surface_ptr->comps[i].master == NULL) + { + input_error++; + error_string = sformatf( + "No surface master species for surface component %s, ", + surface_ptr->comps[i].formula); + error_msg(error_string, CONTINUE); + } + } +/* + * Sort components + */ + if (get_input_errors() == 0) + { + qsort(surface[k].comps, + (size_t) surface_ptr->count_comps, + (size_t) sizeof(struct surface_comp), surface_comp_compare); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_solutions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Define n_user for any solutions read by solution_spread that + * don't have n_user defined + */ + int i, l, n, last; + struct conc *tot_ptr; + char *ptr; + struct master *master_ptr; + char token[MAX_LENGTH]; + for (n = 0; n < count_solution; n++) + { + /* + * Check that elements are in database + */ + if (solution[n] != NULL && solution[n]->new_def == TRUE) + { + /* + * Sort totals by description + */ + i = 0; + while (solution[n]->totals[i].description != NULL) + i++; + qsort(solution[n]->totals, + (size_t) i, (size_t) sizeof(struct conc), conc_compare); + /* + * sort isotopes + */ + if (solution[n]->count_isotopes > 0) + { + qsort(solution[n]->isotopes, + (size_t) solution[n]->count_isotopes, + (size_t) sizeof(struct isotope), isotope_compare); + } + else + { + solution[n]->isotopes = + (struct isotope *) free_check_null(solution[n]->isotopes); + } + for (i = 0; solution[n]->totals[i].description != NULL; i++) + { + tot_ptr = &(solution[n]->totals[i]); + if (strcmp(tot_ptr->description, "H(1)") == 0 || + strcmp(tot_ptr->description, "E") == 0) + { + tot_ptr->moles = 0.0; + continue; + } + { + char * temp_desc = string_duplicate(tot_ptr->description); + ptr = temp_desc; + copy_token(token, &ptr, &l); + free_check_null(temp_desc); + } + master_ptr = master_bsearch(token); + if (master_ptr == NULL) + { + error_string = sformatf( + "Could not find element in database, %s.\n\tConcentration is set to zero.", + tot_ptr->description); + warning_msg(error_string); + tot_ptr->input_conc = 0.0; + continue; + } + } + } + } + /* + * Calculate solution numbers + */ + for (n = 0; n < count_solution; n++) + { + if (solution[n] != NULL && solution[n]->new_def == TRUE + && solution[n]->n_user < 0) + { + last = 0; + for (i = 0; i < count_solution; i++) + { + if (solution[i]->n_user > last) + last = solution[i]->n_user; + if (solution[i]->n_user_end > last) + last = solution[i]->n_user_end; + } + if (save.solution == TRUE) + { + if (save.n_solution_user > last) + last = save.n_solution_user; + if (save.n_solution_user_end > last) + last = save.n_solution_user_end; + } + for (i = 0; i < count_solution; i++) + { + if (solution[i]->new_def == TRUE && solution[i]->n_user < 0) + { + solution[i]->n_user = ++last; + solution[i]->n_user_end = last; + if (use.Get_solution_in() && (use.Get_n_solution_user() == -1)) + { + use.Set_n_solution_user(last); + } + } + } + break; + } + } + solution_sort(); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +species_rxn_to_trxn(struct species *s_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copy reaction from reaction structure to + * temp reaction structure. + */ + int i; + + for (i = 0; s_ptr->rxn->token[i].s != NULL; i++) + { + trxn.token[i].name = s_ptr->rxn->token[i].s->name; + trxn.token[i].z = s_ptr->rxn->token[i].s->z; + trxn.token[i].s = s_ptr->rxn->token[i].s; + trxn.token[i].unknown = NULL; + trxn.token[i].coef = s_ptr->rxn->token[i].coef; + count_trxn = i + 1; + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, + &max_trxn, sizeof(struct rxn_token_temp)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copy reaction from reaction structure to + * temp reaction structure. + */ + int i, l; + char *ptr; + char token[MAX_LENGTH]; + LDBLE l_z; + + trxn.token[0].name = phase_ptr->formula; + /* charge */ + char * temp_formula = string_duplicate(phase_ptr->formula); + ptr = temp_formula; + get_token(&ptr, token, &l_z, &l); + free_check_null(temp_formula); + trxn.token[0].z = l_z; + trxn.token[0].s = NULL; + trxn.token[0].unknown = NULL; + /*trxn.token[0].coef = -1.0; */ + /* check for leading coefficient of 1.0 for phase did not work */ + trxn.token[0].coef = phase_ptr->rxn->token[0].coef; + for (i = 1; rxn_ptr->token[i].s != NULL; i++) + { + trxn.token[i].name = rxn_ptr->token[i].s->name; + trxn.token[i].z = rxn_ptr->token[i].s->z; + trxn.token[i].s = NULL; + trxn.token[i].unknown = NULL; + trxn.token[i].coef = rxn_ptr->token[i].coef; + count_trxn = i + 1; + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, + &max_trxn, sizeof(struct rxn_token_temp)); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_isotopes(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Isotope ratios for each element or element valence state + */ + int i, j, k, l, n; + int count_isotopes, primary_number, count_primary; + LDBLE isotope_number; + struct master *master_ptr, *primary_ptr; + struct solution *solution_ptr; + struct isotope *new_isotopes; + struct isotope *primary_isotopes; + char token[MAX_LENGTH]; + + primary_number = 0; + primary_ptr = NULL; + for (n = 0; n < count_solution; n++) + { + if (solution[n]->new_def != TRUE) + continue; + if (solution[n]->count_isotopes == 0) + continue; + solution_ptr = solution[n]; + primary_isotopes = + (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); + if (primary_isotopes == NULL) + malloc_error(); + count_primary = 0; + new_isotopes = + (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); + if (new_isotopes == NULL) + malloc_error(); + count_isotopes = 0; +/* + * Make list of primary master species for isotopes + */ + for (i = 0; i < solution_ptr->count_isotopes; i++) + { + master_ptr = + master_bsearch_primary(solution_ptr->isotopes[i].elt_name); + isotope_number = solution_ptr->isotopes[i].isotope_number; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "In isotope calculation: element not defined: %s.", + solution_ptr->isotopes[i].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + for (j = 0; j < count_primary; j++) + { + if (primary_isotopes[j].master == master_ptr && + primary_isotopes[j].isotope_number == isotope_number) + break; + } + if (j == count_primary) + { + primary_isotopes = + (struct isotope *) PHRQ_realloc(primary_isotopes, + (size_t) (count_primary + + 1) * + sizeof(struct isotope)); + if (primary_isotopes == NULL) + malloc_error(); + primary_isotopes[count_primary].master = master_ptr; + primary_isotopes[count_primary].isotope_number = + isotope_number; + count_primary++; + } + } + if (get_input_errors() > 0) + return (ERROR); +/* + * Go through all redox states of the list of primary species and isotope number + */ + for (j = 0; j < count_primary; j++) + { + + /* find index number of master species, set flag to FALSE */ + master_ptr = primary_isotopes[j].master; + isotope_number = primary_isotopes[j].isotope_number; + for (k = 0; k < count_master; k++) + { + if (master[k] == master_ptr) + { + primary_number = k; + primary_ptr = master[k]; + } + master[k]->isotope = FALSE; + } + + /* go through isotopes of solution and fill in master species */ + for (l = 0; l < solution_ptr->count_isotopes; l++) + { + master_ptr = + master_bsearch(solution_ptr->isotopes[l].elt_name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "In isotope calculation: element not defined: %s.", + solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + continue; + } + + /* only fill for pertinent isotope */ + if (master_ptr->elt->primary != primary_ptr) + continue; + if (solution_ptr->isotopes[l].isotope_number != + isotope_number) + continue; + + /* for primary, fill in ratio for all secondary species */ + if (master_ptr->primary == TRUE + && master_ptr->s->secondary != NULL) + { + for (k = primary_number + 1; k < count_master; k++) + { + if (master[k]->elt->primary != primary_ptr) + break; + master[k]->isotope_ratio = + solution_ptr->isotopes[l].ratio; + master[k]->isotope_ratio_uncertainty = + solution_ptr->isotopes[l].ratio_uncertainty; + if (master[k]->isotope == TRUE) + { + error_string = sformatf( + "In isotope calculation: redefinition of isotope ratio for %s.", + solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + } + master[k]->isotope = TRUE; + } + + /* for secondary and non redox, set ratio */ + } + else + { + master_ptr->isotope_ratio = + solution_ptr->isotopes[l].ratio; + master_ptr->isotope_ratio_uncertainty = + solution_ptr->isotopes[l].ratio_uncertainty; + if (master_ptr->isotope == TRUE) + { + error_string = sformatf( + "In isotope calculation: redefinition of isotope ratio for %s.", + solution_ptr->isotopes[l].elt_name); + error_msg(error_string, CONTINUE); + } + master_ptr->isotope = TRUE; + } + } +/* + * Write new isotope structure + */ + for (k = 0; k < count_master; k++) + { + /* skip primary master species of redox elements */ + if (master[k]->primary == TRUE + && master[k]->s->secondary != NULL) + continue; + if (master[k]->elt->primary == primary_ptr + && master[k]->isotope == FALSE) + { + input_error++; + error_string = sformatf( + "Isotopic ratio not defined for element or valence state %g%s, using 0.", + (double) isotope_number, master[k]->elt->name); + warning_msg(error_string); + master[k]->isotope = TRUE; + master[k]->isotope_ratio = 0.0; + master[k]->isotope_ratio_uncertainty = 0.001; + } + if (master[k]->isotope == FALSE) + continue; + new_isotopes = + (struct isotope *) PHRQ_realloc(new_isotopes, + (size_t) (count_isotopes + + + 1) * + sizeof(struct isotope)); + if (new_isotopes == NULL) + malloc_error(); + new_isotopes[count_isotopes].master = master[k]; + new_isotopes[count_isotopes].primary = primary_ptr; + new_isotopes[count_isotopes].isotope_number = isotope_number; + new_isotopes[count_isotopes].elt_name = master[k]->elt->name; + new_isotopes[count_isotopes].total = 0; + new_isotopes[count_isotopes].ratio = master[k]->isotope_ratio; + new_isotopes[count_isotopes].ratio_uncertainty = + master[k]->isotope_ratio_uncertainty; + sprintf(token, "%d%s", (int) isotope_number, + master[k]->elt->name); + new_isotopes[count_isotopes].isotope_name = + string_hsave(token); + count_isotopes++; + } + } + primary_isotopes = + (struct isotope *) free_check_null(primary_isotopes); + solution_ptr->isotopes = + (struct isotope *) free_check_null(solution_ptr->isotopes); + solution_ptr->isotopes = new_isotopes; + solution_ptr->count_isotopes = count_isotopes; + qsort(solution_ptr->isotopes, + (size_t) count_isotopes, + (size_t) sizeof(struct isotope), isotope_compare); + } + + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_kin_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + int k; + struct kinetics *kinetics_ptr; + //struct exch_comp *comp_ptr; + //struct master *master_ptr; + char *ptr; + LDBLE conc; + + //for (i = 0; i < count_exchange; i++) + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + cxxExchange * exchange_ptr = &(it->second); + if (!exchange_ptr->Get_new_def()) + continue; + if (exchange_ptr->Get_n_user() < 0) + continue; + std::vector comps = exchange_ptr->Vectorize(); + // check elements + for (size_t j = 0; j < comps.size(); j++) + { + if (comps[j]->Get_rate_name().size() == 0) + continue; + /* First find exchange master species */ + cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble::iterator kit = nd.begin(); + bool found_exchange = false; + for (; kit != nd.end(); kit++) + { + /* Find master species */ + struct element *elt_ptr = element_store(kit->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + elt_ptr->name); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_ptr->master->type == EX) + found_exchange = true;; + } + if (!found_exchange) + { + input_error++; + error_string = sformatf( + "Exchange formula does not contain an exchange master species, %s", + comps[j]->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find associated kinetic reaction ... */ + if ((kinetics_ptr = kinetics_bsearch(exchange_ptr->Get_n_user(), &k)) == NULL) + { + input_error++; + error_string = sformatf( + "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", + exchange_ptr->Get_n_user(), comps[j]->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + for (k = 0; k < kinetics_ptr->count_comps; k++) + { + if (strcmp_nocase + (comps[j]->Get_rate_name().c_str(), + kinetics_ptr->comps[k].rate_name) == 0) + { + break; + } + } + if (k == kinetics_ptr->count_comps) + { + input_error++; + error_string = sformatf( + "Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", + comps[j]->Get_rate_name().c_str(), comps[j]->Get_formula().c_str(), exchange_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + continue; + } + + /* use database name for phase */ + comps[j]->Set_rate_name(kinetics_ptr->comps[k].rate_name); + + /* make exchanger concentration proportional to mineral ... */ + conc = kinetics_ptr->comps[k].m * comps[j]->Get_phase_proportion(); + + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comps[j]->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comps[j]->Set_totals(elt_list_NameDouble()); +/* + * No check on availability of exchange elements + */ + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_min_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + int n, jj; + //struct pp_assemblage *pp_a_ptr; + //struct exch_comp *comp_ptr; + //struct master *master_ptr; + char *ptr; + LDBLE conc; + + //for (i = 0; i < count_exchange; i++) + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + cxxExchange * exchange_ptr = &(it->second); + if (!exchange_ptr->Get_new_def()) + continue; + if (exchange_ptr->Get_n_user() < 0) + continue; + n = exchange_ptr->Get_n_user(); + //for (j = 0; j < exchange[i].count_comps; j++) + std::vector comps = exchange_ptr->Vectorize(); + // check elements + for (size_t j = 0; j < comps.size(); j++) + { + cxxExchComp * comp_ptr = comps[j]; + if (comp_ptr->Get_phase_name().size() == 0) + continue; + + + /* First find exchange master species */ + cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble::iterator kit = nd.begin(); + bool found_exchange = false; + for (; kit != nd.end(); kit++) + { + /* Find master species */ + struct element *elt_ptr = element_store(kit->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + kit->first.c_str()); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_ptr->master->type == EX) + { + found_exchange = true;; + } + } + if (!found_exchange) + { + input_error++; + error_string = sformatf( + "Exchange formula does not contain an exchange master species, %s", + comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + cxxPPassemblage *pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); + /* Now find the mineral on which exchanger depends... */ + if (pp_assemblage_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", + n, comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + std::map::iterator jit; + jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; jit != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); jit++) + { + if (strcmp_nocase(comp_ptr->Get_phase_name().c_str(), jit->first.c_str()) == 0) + { + break; + } + } + if (jit == pp_assemblage_ptr->Get_pp_assemblage_comps().end() ) + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", + comp_ptr->Get_phase_name().c_str(), comp_ptr->Get_formula().c_str(), n); + error_msg(error_string, CONTINUE); + continue; + } + /* use database name for phase */ + comp_ptr->Set_phase_name(jit->first.c_str()); + /* make exchanger concentration proportional to mineral ... */ + conc = jit->second.Get_moles() * comp_ptr->Get_phase_proportion(); + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comp_ptr->Set_totals(elt_list_NameDouble()); +/* + * make sure exchange elements are in phase + */ + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, -comp_ptr->Get_phase_proportion()); + free_check_null(temp_formula); + } + int l; + struct phase *phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE); + { + char * temp_formula = string_duplicate(phase_ptr->formula); + ptr = temp_formula; + get_elts_in_species(&ptr, 1.0); + free_check_null(temp_formula); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + for (jj = 0; jj < count_elts; jj++) + { + if (elt_list[jj].elt->primary->s->type != EX + && elt_list[jj].coef < 0) + { + input_error++; + error_string = sformatf( + "Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", + comp_ptr->Get_formula().c_str(), + (double) comp_ptr->Get_phase_proportion(), + phase_ptr->name, + phase_ptr->formula); + error_msg(error_string, CONTINUE); + break; + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_min_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + int k, n, jj; + struct pp_assemblage *pp_a_ptr; + //struct exch_comp *comp_ptr; + //struct master *master_ptr; + char *ptr; + LDBLE conc; + + //for (i = 0; i < count_exchange; i++) + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + cxxExchange * exchange_ptr = &(it->second); + if (!exchange_ptr->Get_new_def()) + continue; + if (exchange_ptr->Get_n_user() < 0) + continue; + n = exchange_ptr->Get_n_user(); + //for (j = 0; j < exchange[i].count_comps; j++) + std::vector comps = exchange_ptr->Vectorize(); + // check elements + for (size_t j = 0; j < comps.size(); j++) + { + cxxExchComp * comp_ptr = comps[j]; + if (comp_ptr->Get_phase_name().size() == 0) + continue; + + + /* First find exchange master species */ + cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble::iterator kit = nd.begin(); + bool found_exchange = false; + for (; kit != nd.end(); kit++) + { + /* Find master species */ + struct element *elt_ptr = element_store(kit->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + kit->first.c_str()); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_ptr->master->type == EX) + { + found_exchange = true;; + } + } + if (!found_exchange) + { + input_error++; + error_string = sformatf( + "Exchange formula does not contain an exchange master species, %s", + comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the mineral on which exchanger depends... */ + if ((pp_a_ptr = pp_assemblage_bsearch(n, &k)) == NULL) + { + input_error++; + error_string = sformatf( + "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", + n, comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + for (k = 0; k < pp_a_ptr->count_comps; k++) + { + if (strcmp_nocase + (comp_ptr->Get_phase_name().c_str(), + pp_a_ptr->pure_phases[k].name) == 0) + { + break; + } + } + if (k == pp_a_ptr->count_comps) + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", + comp_ptr->Get_phase_name().c_str(), comp_ptr->Get_formula().c_str(), n); + error_msg(error_string, CONTINUE); + continue; + } + /* use database name for phase */ + comp_ptr->Set_phase_name(pp_a_ptr->pure_phases[k].phase->name); + /* make exchanger concentration proportional to mineral ... */ + conc = pp_a_ptr->pure_phases[k].moles * comp_ptr->Get_phase_proportion(); + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comp_ptr->Set_totals(elt_list_NameDouble()); +/* + * make sure exchange elements are in phase + */ + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, -comp_ptr->Get_phase_proportion()); + free_check_null(temp_formula); + } + { + char * temp_formula = string_duplicate(pp_a_ptr->pure_phases[k].phase->formula); + ptr = temp_formula; + get_elts_in_species(&ptr, 1.0); + free_check_null(temp_formula); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + for (jj = 0; jj < count_elts; jj++) + { + if (elt_list[jj].elt->primary->s->type != EX + && elt_list[jj].coef < 0) + { + input_error++; + error_string = sformatf( + "Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", + comp_ptr->Get_formula().c_str(), + (double) comp_ptr->Get_phase_proportion(), + pp_a_ptr->pure_phases[k].phase->name, + pp_a_ptr->pure_phases[k].phase->formula); + error_msg(error_string, CONTINUE); + break; + } + } + } + } + return (OK); +} +#endif + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_min_surface(void) +/* ---------------------------------------------------------------------- */ +/* + * If surface is related to mineral, surface amount is + * set in proportion + */ +{ + int i, j, k, n, jj; + //struct pp_assemblage *pp_a_ptr; + struct surface_comp *comp_ptr; + struct master *master_ptr; + char *ptr; + LDBLE conc; + + for (i = 0; i < count_surface; i++) + { + if (surface[i].new_def == FALSE) + continue; + if (surface[i].n_user < 0) + continue; + for (j = 0; j < surface[i].count_comps; j++) + { + if (surface[i].comps[j].phase_name == NULL) + continue; + comp_ptr = &surface[i].comps[j]; + comp_ptr->master = NULL; + n = surface[i].n_user; + + /* First find surface master species */ + + for (k = 0; comp_ptr->totals[k].elt != NULL; k++) + { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) + continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) + { + input_error++; + error_string = sformatf( + "Surface formula does not contain a surface master species, %s", + comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the mineral on which surface depends... */ + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); + //if ((pp_a_ptr = pp_assemblage_bsearch(n, &k)) == NULL) + if (pp_assemblage_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Equilibrium_phases %d must be defined to use surface related to mineral phase, %s", + n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + std::map::iterator jit; + jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; jit != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); jit++) + { + //for (k = 0; k < pp_a_ptr->count_comps; k++) + //{ + if (strcmp_nocase(comp_ptr->phase_name, + jit->first.c_str()) == 0) + { + break; + } + } + if (jit == pp_assemblage_ptr->Get_pp_assemblage_comps().end()) + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to surface, %s, not found in Equilibrium_Phases %d", + comp_ptr->phase_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + int l; + struct phase *phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to surface, %s, not found in database.", + jit->first.c_str(), comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + /* use database name for phase */ + //comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; + //comp_ptr->phase_name = string_hsave(jit->first.c_str()); + comp_ptr->phase_name = phase_ptr->name; + /* make surface concentration proportional to mineral ... */ + conc = jit->second.Get_moles() * comp_ptr->phase_proportion; +#ifdef SKIP_MUSIC + comp_ptr->cb = conc * comp_ptr->formula_z; +#endif +/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ + { + char * temp_formula = string_duplicate(comp_ptr->formula); + ptr = temp_formula; + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comp_ptr->totals = + (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); + + /* area */ + surface[i].charge[comp_ptr->charge].grams = jit->second.Get_moles(); +/* + * make sure surface elements are in phase + * logically necessary for mass balance and to avoid negative concentrations when dissolving phase + */ + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(phase_ptr->formula); + ptr = temp_formula; + get_elts_in_species(&ptr, 1.0); + free_check_null(temp_formula); + } + for (jj = 0; jj < surface[i].count_comps; jj++) + { + if (comp_ptr->charge != surface[i].comps[jj].charge) + continue; + if (surface[i].type == CD_MUSIC) + { + char * temp_formula = string_duplicate(surface[i].comps[jj].formula); + ptr = temp_formula; + get_elts_in_species(&ptr, + -surface[i].comps[jj]. + phase_proportion); + free_check_null(temp_formula); + } + else + { + if (surface[i].comps[jj].master->s->z != 0.0) + { + input_error++; + error_string = sformatf( + "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", + surface[i].comps[jj].master->s->name); + error_msg(error_string, CONTINUE); + } + { + char * temp_name = string_duplicate(surface[i].comps[jj].master->s->name); + ptr = temp_name; + get_elts_in_species(&ptr, + -surface[i].comps[jj]. + phase_proportion); + free_check_null(temp_name); + } + } + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + /* Makes no sense: sorbed species need not be in mineral structure... */ + /* But elements that can desorb into solution must be in mineral */ + /* If you precipitate Ca-Mont, and make SurfMg (assuming this is the + formula in SURFACE), where does the Mg come from? + Further, if you precipitate Ca-Mont, make SurfCa, desorb + all the Ca, then dissolve the "Ca-Mont", you must remove SurfCa, or you + will end up with Ca in solution. H and O are excluded */ + for (jj = 0; jj < count_elts; jj++) + { + if (elt_list[jj].elt->primary->s->type != SURF + && elt_list[jj].coef < 0 + && elt_list[jj].elt->primary->s != s_hplus + && elt_list[jj].elt->primary->s != s_h2o) + { + input_error++; + error_string = sformatf( + "Element %s in sum of surface sites,\n" + "\tincluding %s * %g mol sites/mol phase,\n" + "\texceeds stoichiometry in the related phase %s, %s.", + elt_list[jj].elt->name, + comp_ptr->master->s->name, + (double) comp_ptr->phase_proportion, + phase_ptr->name, + phase_ptr->formula); + error_msg(error_string, CONTINUE); + break; + } + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_kin_surface(void) +/* ---------------------------------------------------------------------- */ +/* + * If surface is related to mineral, surface amount is + * set in proportion + */ +{ + int i, j, k, n, jj, l; + struct kinetics *kinetics_ptr; + struct surface_comp *comp_ptr; + struct master *master_ptr; + struct phase *phase_ptr; + char token[MAX_LENGTH]; + char *ptr; + LDBLE conc; + struct elt_list *elt_list_kinetics; + int count_elts_kinetics; + + n = -999; + comp_ptr = NULL; + for (i = 0; i < count_surface; i++) + { + if (surface[i].new_def == FALSE) + continue; + if (surface[i].n_user < 0) + continue; + for (j = 0; j < surface[i].count_comps; j++) + { + if (surface[i].comps[j].rate_name == NULL) + continue; + comp_ptr = &surface[i].comps[j]; + comp_ptr->master = NULL; + n = surface[i].n_user; + + /* First find surface master species */ + + for (k = 0; comp_ptr->totals[k].elt != NULL; k++) + { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) + continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) + { + input_error++; + error_string = sformatf( + "Surface formula does not contain a surface master species, %s", + comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the kinetic reaction on which surface depends... */ + if ((kinetics_ptr = kinetics_bsearch(n, &k)) == NULL) + { + input_error++; + error_string = sformatf( + "Kinetics %d must be defined to use surface related to kinetic reaction, %s", + n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k = 0; k < kinetics_ptr->count_comps; k++) + { + if (strcmp_nocase + (comp_ptr->rate_name, + kinetics_ptr->comps[k].rate_name) == 0) + { + break; + } + } + if (k == kinetics_ptr->count_comps) + { + input_error++; + error_string = sformatf( + "Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", + comp_ptr->rate_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + + /* use database name for phase */ + comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; + + /* make surface concentration proportional to mineral ... */ + conc = kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; + +/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ + { + char * temp_formula = string_duplicate(comp_ptr->formula); + ptr = temp_formula; + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comp_ptr->totals = + (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); + + /* area */ + surface[i].charge[comp_ptr->charge].grams = + kinetics_ptr->comps[k].m; + } +/* + * check on elements + */ + /* Go through each kinetic reaction, add all related surface compositions + * check for negative values + */ + if (surface[i].related_rate == FALSE) + continue; + kinetics_ptr = kinetics_bsearch(n, &k); + for (k = 0; k < kinetics_ptr->count_comps; k++) + { + count_elts = 0; + paren_count = 0; + + /* added in kinetics formula */ + for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) + { + phase_ptr = NULL; + strcpy(token, kinetics_ptr->comps[k].list[j].name); + phase_ptr = phase_bsearch(token, &jj, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, 1.0); + } + else + { + char * temp_name = string_duplicate(kinetics_ptr->comps[k].list[j].name); + ptr = temp_name; + get_elts_in_species(&ptr, + kinetics_ptr->comps[k].list[j].coef); + free_check_null(temp_name); + } + } + /* save kinetics formula */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + elt_list_kinetics = elt_list_save(); + count_elts_kinetics = count_elts; + + /* get surface formulas */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < surface[i].count_comps; j++) + { + comp_ptr = &surface[i].comps[j]; + if (comp_ptr->rate_name == NULL) + continue; + if (strcmp_nocase + (comp_ptr->rate_name, + kinetics_ptr->comps[k].rate_name) == 0) + { + char * temp_formula = string_duplicate( comp_ptr->formula); + ptr = temp_formula; + get_elts_in_species(&ptr, + -1 * comp_ptr->phase_proportion); + free_check_null(temp_formula); + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (elt_list[j].elt->primary->s->type <= H2O) + { + for (l = 0; l < count_elts_kinetics; l++) + { + if (elt_list[j].elt == elt_list_kinetics[l].elt) + { + break; + } + } + if (l == count_elts_kinetics) + { + input_error++; + error_string = sformatf( + "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", + comp_ptr->formula, + (double) comp_ptr->phase_proportion, + comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } + else if (fabs(elt_list[j].coef) > + fabs(elt_list_kinetics[l].coef)) + { + input_error++; + error_string = sformatf( + "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", + comp_ptr->formula, + (double) comp_ptr->phase_proportion, + comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } + } + } + elt_list_kinetics = + (struct elt_list *) free_check_null(elt_list_kinetics); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, converged, divisions; + LDBLE r, rt, ag0, ag1, crit_pt; + LDBLE xc, tc; + LDBLE l_x, x0, x1, xsm1, xsm2, xb1, xb2; + LDBLE xc1, xc2; + LDBLE facb1, faca1, spim1, xblm1, acrae, acrael, xliapt, xliapm; + LDBLE xaly, xaly1, xaly2; + LDBLE faca, facb, spialy, facal, facbl; + LDBLE tol; + + if (pr.ss_assemblage == FALSE) + print = FALSE; + tol = 1e-6; + r = R_KJ_DEG_MOL; + rt = r * t; + a0 = s_s_ptr->ag0 / rt; + a1 = s_s_ptr->ag1 / rt; + s_s_ptr->a0 = a0; + s_s_ptr->a1 = a1; + ag0 = a0 * rt; + ag1 = a1 * rt; + kc = exp(k_calc(s_s_ptr->comps[0].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + kb = exp(k_calc(s_s_ptr->comps[1].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + crit_pt = fabs(a0) + fabs(a1); +/* + * Default, no miscibility or spinodal gaps + */ + s_s_ptr->miscibility = FALSE; + s_s_ptr->spinodal = FALSE; + xsm1 = 0.5; + xsm2 = 0.5; + xb1 = 0.5; + xb2 = 0.5; + xc1 = 0; + xc2 = 0; + + if (crit_pt >= tol) + { +/* + * Miscibility gap information + */ + if (fabs(a1) < tol) + { + xc = 0.5; + tc = ag0 / (2 * r); + } + else + { + xc = 0.5 + (pow((ag0 * ag0 + 27 * ag1 * ag1), (LDBLE) 0.5) - + ag0) / (18 * ag1); + tc = (12 * ag1 * xc - 6 * ag1 + 2 * ag0) * (xc - xc * xc) / r; + } + if (print == TRUE) + { + error_string = sformatf( "Description of Solid Solution %s", + s_s_ptr->name); + dup_print(error_string, TRUE); + } + if (print == TRUE) + { + output_msg(sformatf( + "\t Temperature: %g kelvin\n", + (double) t)); + output_msg(sformatf( + "\t A0 (dimensionless): %g\n", + (double) a0)); + output_msg(sformatf( + "\t A1 (dimensionless): %g\n", + (double) a1)); + output_msg(sformatf( + "\t A0 (kJ/mol): %g\n", + (double) ag0)); + output_msg(sformatf( + "\t A1 (kJ/mol): %g\n\n", + (double) ag1)); + } + if (xc < 0 || xc > 1) + { + if (print == TRUE) + output_msg(sformatf( + "No miscibility gap above 0 degrees kelvin.\n")); + } + else + { + if (print == TRUE) + { + output_msg(sformatf( + "\t Critical mole-fraction of component 2: %g\n", + (double) xc)); + output_msg(sformatf( + "\t Critical temperature: %g kelvin\n", + (double) tc)); + output_msg(sformatf( + "\n(The critical temperature calculation assumes that the Guggenheim model\ndefined at %g kelvin is valid at the critical temperature.)\n\n\n", + (double) t)); + } + } +/* + * Calculate miscibility and spinodal gaps + */ + if (tc >= t) + { + + /* search for sign changes */ + x0 = 0; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) + { + + /* find first spinodal pt */ + xsm1 = halve(f_spinodal, x0, x1, tol); + xsm1 = halve(f_spinodal, x0, x1, tol); + s_s_ptr->spinodal = TRUE; + + /* find second spinodal pt */ + x0 = x1; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) + { + xsm2 = halve(f_spinodal, x0, x1, tol); + } + else + { + error_msg("Failed to find second spinodal point.", STOP); + } + } + } + } +/* + * Now find Miscibility gap + */ + if (s_s_ptr->spinodal == TRUE) + { + if (print == TRUE) + output_msg(sformatf( + "\t Spinodal-gap mole fractions, component 2: %g\t%g\n", + (double) xsm1, (double) xsm2)); + converged = FALSE; + if (converged == FALSE) + { + for (i = 1; i < 3; i++) + { + divisions = (int) pow(10., i); + for (j = 0; j < divisions; j++) + { + for (k = divisions; k > 0; k--) + { + xc1 = (LDBLE) j / divisions + 0.001; + xc2 = (LDBLE) k / divisions; + converged = solve_misc(&xc1, &xc2, tol); + if (converged == TRUE) + break; + } + if (converged == TRUE) + break; + } + if (converged == TRUE) + break; + } + } + if (converged == FALSE) + { + error_msg("Failed to find miscibility gap.", STOP); + } + s_s_ptr->miscibility = TRUE; + if (xc1 < xc2) + { + xb1 = 1 - xc2; + xb2 = 1 - xc1; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + } + else + { + xb1 = 1 - xc1; + xb2 = 1 - xc2; + } + facb1 = kb * xb1 * exp(xc1 * xc1 * (a0 + a1 * (4 * xb1 - 1))); + faca1 = kc * xc1 * exp(xb1 * xb1 * (a0 - a1 * (3 - 4 * xb1))); + spim1 = log10(faca1 + facb1); + xblm1 = 1. / (1. + faca1 / facb1); + acrae = facb1 / faca1; + acrael = log10(acrae); + xliapt = log10(facb1); + xliapm = log10(faca1); + + if (print == TRUE) + { + output_msg(sformatf( + "\t Miscibility-gap fractions, component 2: %g\t%g\n", + (double) xb1, (double) xb2)); + output_msg(sformatf( + "\n\t\t\tEutectic Point Calculations\n\n")); + output_msg(sformatf( + "\t Aqueous activity ratio (comp2/comp1): %g\n", + (double) acrae)); + output_msg(sformatf( + "\t Log aqueous activity ratio (comp2/comp1): %g\n", + (double) acrael)); + output_msg(sformatf( + "\t Aqueous activity fraction of component 2: %g\n", + (double) xblm1)); + output_msg(sformatf( + "\t Log IAP (component 2): %g\n", + (double) xliapt)); + output_msg(sformatf( + "\t Log IAP (component 1): %g\n", + (double) xliapm)); + output_msg(sformatf( + "\t Log Sum Pi: %g\n", + (double) spim1)); + } + s_s_ptr->tk = t; + s_s_ptr->xb1 = xb1; + s_s_ptr->xb2 = xb2; + } +/* + * Alyotropic point calculation + */ + xaly = -1.0; + l_x = a0 * a0 + 3 * a1 * a1 + 6 * a1 * log(kb / kc); + if (l_x > 0) + { + if (fabs(l_x - a0 * a0) >= tol) + { + xaly1 = (-(a0 - 3 * a1) + pow(l_x, (LDBLE) 0.5)) / (6 * a1); + xaly2 = (-(a0 - 3 * a1) - pow(l_x, (LDBLE) 0.5)) / (6 * a1); + if (xaly1 >= 0 && xaly1 <= 1) + { + xaly = xaly1; + } + if (xaly2 >= 0 && xaly2 <= 1) + { + xaly = xaly2; + } + } + else + { + xaly = 0.5 + log(kb / kc) / (2 * a0); + } + if (xaly > 0 && xaly < 1) + { + faca = + kc * (1 - + xaly) * exp(xaly * xaly * (a0 - a1 * (3 - 4 * xaly))); + facb = + kb * xaly * exp((1 - xaly) * (1 - xaly) * + (a0 + a1 * (4 * xaly - 1.0))); + spialy = log10(faca + facb); + facal = log10(faca); + facbl = log10(facb); + if (xaly > xb1 && xaly < xb2) + { + if (print == TRUE) + output_msg(sformatf( + "\nLocal minimum in the solidus curve coresponding to a maximum\nin the minimum stoichiometric saturation curve.\n\n")); + } + else + { + if (print == TRUE) + output_msg(sformatf( + "\n\t\t\tAlyotropic Point\n\n")); + } + if (print == TRUE) + { + output_msg(sformatf( + "\t Solid mole fraction of component 2: %g\n", + (double) xaly)); + output_msg(sformatf( + "\t Log IAP (component 2): %g\n", + (double) facbl)); + output_msg(sformatf( + "\t Log IAP (component 1): %g\n", + (double) facal)); + output_msg(sformatf( + "\t Log Sum Pi: %g\n", + (double) spialy)); + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE l_x, y, y0, dx; + + y0 = f(x0, this); + dx = (x1 - x0); +/* + * Loop for interval halving + */ + for (i = 0; i < 100; i++) + { + dx *= 0.5; + l_x = x0 + dx; + y = f(l_x, this); + if (dx < tol || y == 0) + { + break; + } + if (y0 * y >= 0) + { + x0 = l_x; + y0 = y; + } + } + return (x0 + dx); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + LDBLE fx0, fx1, divisions; + LDBLE x0, x1, diff; + + x0 = *xx0; + x1 = *xx1; + diff = x1 - x0; + for (j = 0; j < 3; j++) + { + fx0 = f(x0, this); + divisions = (int) pow((LDBLE) 10, (LDBLE) j); + for (i = 1; i < divisions; i++) + { + x1 = *xx0 + diff * (LDBLE) i / divisions; + fx1 = f(x1, this); + if (fx0 * fx1 <= 0) + { + *xx0 = x0; + *xx1 = x1; + return (TRUE); + } + x0 = x1; + fx0 = fx1; + } + } + return (FALSE); +} + + +/* ---------------------------------------------------------------------- */ + LDBLE Phreeqc:: +f_spinodal(LDBLE x, void * cookie) +/* ---------------------------------------------------------------------- */ +{ + LDBLE fx; + Phreeqc * pThis; + pThis = (Phreeqc *) cookie; + fx = -12 * pThis->a1 * x * x * x + (18 * pThis->a1 - + 2 * pThis->a0) * x * x + (2 * pThis->a0 - + 6 * pThis->a1) * x - 1.0; + return (fx); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +slnq(int n, LDBLE * a, LDBLE * l_delta, int ncols, int print) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, m; +/* debug + */ + int row; + + LDBLE b; +/* Debug +*/ + if (print == TRUE) + { + output_msg(sformatf( "\nArray in slnq: \n\n")); + for (i = 0; i < ncols - 1; i++) + { + row = i * (n + 1); + for (j = 0; j < ncols; j++) + { + output_msg(sformatf( "%10.2e", (double) a[row + j])); + } + output_msg(sformatf( "\n")); + } + output_msg(sformatf( "\n")); + } + + if (n == 0) + return (OK); +/* Trivial case */ + if (n == 1) + { + if (fabs(a[0]) < ZERO_TOL) + goto slnq_error; + l_delta[0] = a[1] / a[0]; + return (OK); + } + +/* Reduction loop */ + for (i = 0; i < n - 1; i++) + { + b = fabs(a[i * ncols + i]); + m = i; + +/* Find maximum value in column */ + for (j = i + 1; j < n; j++) + { + if (fabs(a[j * ncols + i]) > b) + { + b = fabs(a[j * ncols + i]); + m = j; + } + } + +/* Check for singularity */ + if (b < ZERO_TOL) + goto slnq_error; + +/* Exchange rows if necessary */ + if (m != i) + { + for (j = i; j <= n; j++) + { + b = a[i * ncols + j]; + a[i * ncols + j] = a[m * ncols + j]; + a[m * ncols + j] = b; + } + } + +/* Make a[i][i]=1.0 */ + for (j = n; j >= i; j--) + { + a[i * ncols + j] /= a[i * ncols + i]; + } + +/* Reduction step */ + for (j = i + 1; j < n; j++) + { + if (a[j * ncols + i] == 0.0) + continue; + b = -a[j * ncols + i]; + for (k = i + 1; k <= n; k++) + { + a[j * ncols + k] += b * a[i * ncols + k]; + } + } + } + +/* Calculation of l_delta[n] */ + if (fabs(a[(n - 1) * ncols + n - 1]) > ZERO_TOL) + { + l_delta[n - 1] = a[(n - 1) * ncols + n] / a[(n - 1) * ncols + n - 1]; + } + else + { + output_msg(sformatf( "Error: Divide by zero in slnq.\n")); + l_delta[n] = 0.0; + goto slnq_error; + } + +/* Back substitution for other delta values */ + for (i = n - 2; i >= 0; i--) + { + l_delta[i] = a[i * ncols + n]; + for (j = i + 1; j < n; j++) + { + l_delta[i] -= a[i * ncols + j] * l_delta[j]; + } + } + if (print == TRUE) + { + output_msg(sformatf( "\nResults from slnq: \n\n")); + for (i = 0; i < n; i++) + { + output_msg(sformatf( "%10.2e", (double) l_delta[i])); + } + output_msg(sformatf( "\n")); + } + return (OK); + + slnq_error:{ + error_string = sformatf( + "Error: Singular matrix in subroutine slnq. \n"); + warning_msg(error_string); + } + return (ERROR); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol) +/* ---------------------------------------------------------------------- */ +{ + int i, repeat, converged, max_iter; + LDBLE x1, x2, xb1, xb2; + LDBLE xc1, xc1_2, xc1_3, xc2, xc2_2, xc2_3; + LDBLE lc1, lc2, lb1, lb2; + LDBLE a[6], d[2]; + LDBLE t; + + d[0] = d[1] = 0; + xc1 = *xxc1; + xc2 = *xxc2; + x1 = 0; + x2 = 0; + converged = TRUE; + max_iter = 25; + for (i = 0; i < max_iter; i++) + { + /* + output_msg(sformatf( "%d xc1: %g\txc2 %g\n", i, xc1, xc2)); + */ + xb1 = 1 - xc1; + xb2 = 1 - xc2; + xc1_2 = xc1 * xc1; + xc1_3 = xc1_2 * xc1; + xc2_2 = xc2 * xc2; + xc2_3 = xc2_2 * xc2; + + lc1 = exp(xb1 * xb1 * (a0 - a1 * (3 - 4 * xb1))); + lb1 = exp(xc1 * xc1 * (a0 + a1 * (4 * xb1 - 1))); + lc2 = exp(xb2 * xb2 * (a0 - a1 * (3 - 4 * xb2))); + lb2 = exp(xc2 * xc2 * (a0 + a1 * (4 * xb2 - 1))); + + /* -fb */ + a[2] = -(xb1 * lb1 - xb2 * lb2); + + /* -fc */ + a[5] = -(xc1 * lc1 - xc2 * lc2); + + if (fabs(a[2]) < tol && fabs(a[5]) < tol) + break; + + /* dfb/dxc1 */ + t = exp(a0 * xc1_2 - 4 * a1 * xc1_3 + 3 * a1 * xc1_2); + a[0] = + (2 * a0 * xc1 + 6 * a1 * xc1 - 2 * a0 * xc1_2 + 12 * a1 * xc1_3 - + 18 * a1 * xc1_2 - 1) * t; + + /* dfb/dxc2 */ + t = exp(a0 * xc2_2 - 4 * a1 * xc2_3 + 3 * a1 * xc2_2); + a[1] = + (2 * a0 * xc2_2 - 12 * a1 * xc2_3 - 2 * a0 * xc2 + + 18 * a1 * xc2_2 - 6 * a1 * xc2 + 1) * t; + + + /* dfc/dxc1 */ + t = exp(a0 * xc1_2 - 2 * a0 * xc1 + a0 - 4 * a1 * xc1_3 + + 9 * a1 * xc1_2 - 6 * a1 * xc1 + a1); + a[3] = + (2 * a0 * xc1_2 - 2 * a0 * xc1 - 12 * a1 * xc1_3 + + 18 * a1 * xc1_2 - 6 * a1 * xc1 + 1) * t; + + /* dfc/dxc2 */ + t = exp(a0 * xc2_2 - 2 * a0 * xc2 + a0 - 4 * a1 * xc2_3 + + 9 * a1 * xc2_2 - 6 * a1 * xc2 + a1); + a[4] = + (-2 * a0 * xc2_2 + 2 * a0 * xc2 + 12 * a1 * xc2_3 - + 18 * a1 * xc2_2 + 6 * a1 * xc2 - 1) * t; + + + /* solve for dxc1 and dxc2 */ + slnq(2, a, d, 3, FALSE); + + repeat = TRUE; + while (repeat == TRUE) + { + x1 = xc1 + d[0]; + x2 = xc2 + d[1]; + if (x1 > 1 || x1 < 0 || x2 > 1 || x2 < 0) + { + d[0] *= 0.5; + d[1] *= 0.5; + } + else + { + repeat = FALSE; + } + }; + xc1 = x1; + xc2 = x2; + + if (fabs(xc1 - xc2) < .01) + { + converged = FALSE; + break; + } + } + if (i == max_iter) + converged = FALSE; + *xxc1 = xc1; + *xxc2 = xc2; + return (converged); +} + +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +s_s_calc_a0_a1(struct s_s *s_s_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, done; + LDBLE r, rt, *p; + LDBLE q1, q2, xbq1, xbq2, xb1, xb2, xc1, xc2; + LDBLE r1, r2, pa1, pb1, pa2, pb2, xsm1, xsm2; + LDBLE pn9, pn10, c5, c6, pl9, pl10, pj9, pj10; + LDBLE xc, tc; + LDBLE spialy, azero, phi1, phi2, test; + LDBLE dq1, dq2, denom, ratio, dr1, dr2, x21, x22, x61, x62; + LDBLE l_a0, l_a1, ag0, ag1; + LDBLE wg2, wg1, alpha2, alpha3; + LDBLE l_kc, l_kb; + LDBLE xaly, xcaly, alpha0, alpha1, fx, fx1; + LDBLE tol; + + tol = 1e-6; + rt = s_s_ptr->tk * R_KJ_DEG_MOL; + if (s_s_ptr->comps[0].phase == NULL || s_s_ptr->comps[1].phase == NULL) + { + input_error++; + error_string = sformatf( + "Two components were not defined for %s solid solution", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + return (ERROR); + } + l_kc = exp(k_calc(s_s_ptr->comps[0].phase->rxn->logk, s_s_ptr->tk, REF_PRES_PASCAL) * + LOG_10); + l_kb = exp(k_calc(s_s_ptr->comps[1].phase->rxn->logk, s_s_ptr->tk, REF_PRES_PASCAL) * + LOG_10); + + p = s_s_ptr->p; + + l_a0 = 0; + l_a1 = 0; + ag0 = 0; + ag1 = 0; + dq2 = 0; + switch (s_s_ptr->input_case) + { + /* + * dimensionless a0 and a1 + */ + case 0: + l_a0 = p[0]; + l_a1 = p[1]; + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * two activity coefficients + * q1, q2, xbq1, xbq2 + */ + case 1: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + done = FALSE; + if (fabs(1 - xbq1) > 0 && q1 > 0) + { + dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); + if (xbq2 <= 0 || xbq2 > 1) + { + l_a0 = dq1; + l_a1 = 0; + done = TRUE; + } + } + if (done == FALSE) + { + if (fabs(xbq2) < 0 || q2 <= 0) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + done = TRUE; + } + } + if (done == FALSE) + { + dq2 = log(q2) / (xbq2 * xbq2); + if (xbq1 < 0. || xbq2 > 1.) + { + l_a0 = dq2; + l_a1 = 0; + done = TRUE; + } + } + if (done == FALSE) + { + denom = 4 * (xbq1 - xbq2) + 2; + if (fabs(denom) >= tol) + { + if (fabs(1 - xbq1) > 0 && q1 > 0) + { + dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); + l_a0 = (dq1 * (3 - 4 * xbq2) + + dq2 * (4 * xbq1 - 1)) / denom; + l_a1 = (dq1 - dq2) / denom; + done = TRUE; + } + } + } + if (done == FALSE) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * two distribution coefficients + * q1, q2, xbq1, xbq2 + */ + case 2: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + ratio = l_kc / l_kb; + dr1 = log(q1 / ratio); + x21 = 2 * xbq1 - 1; + if (fabs(xbq1 - xbq2) < tol || xbq2 < 0) + { + l_a0 = dr1 / x21; + l_a1 = 0; + } + else + { + dr2 = log(q2 / ratio); + x22 = 2 * xbq2 - 1; + if (xbq1 < 0.) + { + l_a0 = dr2 / x22; + l_a1 = 0; + } + else + { + x61 = 6 * xbq1 * xbq1 - 6 * xbq1 + 1; + x62 = 6 * xbq2 * xbq2 - 6 * xbq2 + 1; + if (fabs(x22 * x61 - x21 * x62) < tol) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + l_a0 = (x61 * dr2 - x62 * dr1) / (x22 * x61 - x21 * x62); + l_a1 = (x21 * dr2 - x22 * dr1) / (x21 * x62 - x22 * x61); + } + } + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from miscibility gap fractions + * q1, q2 + */ + case 3: + q1 = p[0]; + q2 = p[1]; + xb1 = q1; + xb2 = q2; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + r1 = log(xb1 / xb2); + r2 = log(xc1 / xc2); + pa1 = xc2 * xc2 - xc1 * xc1; + pb1 = + 3 * (xc2 * xc2 - xc1 * xc1) - 4 * (xc2 * xc2 * xc2 - + xc1 * xc1 * xc1); + pa2 = xb2 * xb2 - xb1 * xb1; + pb2 = + -(3 * (xb2 * xb2 - xb1 * xb1) - + 4 * (xb2 * xb2 * xb2 - xb1 * xb1 * xb1)); + l_a0 = (r1 - pb1 / pb2 * r2) / (pa1 - pa2 * pb1 / pb2); + l_a1 = (r1 - pa1 / pa2 * r2) / (pb1 - pb2 * pa1 / pa2); + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from spinodal gap fractions + * q1, q2 + */ + case 4: + q1 = p[0]; + q2 = p[1]; + xsm1 = q1; + xsm2 = q2; + pn9 = 1 / xsm1; + pn10 = 1 / xsm2; + c5 = 1 - xsm1; + c6 = 1 - xsm2; + pl9 = 6 * c5 - 12 * c5 * c5; + pl10 = 6 * c6 - 12 * c6 * c6; + pj9 = 2 * c5; + pj10 = 2 * c6; + l_a0 = (pn9 - pl9 / pl10 * pn10) / (pj9 - pl9 / pl10 * pj10); + l_a1 = (pn9 - pj9 / pj10 * pn10) / (pl9 - pj9 / pj10 * pl10); + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from critical point + * q1, q2 + */ + case 5: + xc = p[0]; + tc = p[1]; + r = R_KJ_DEG_MOL; + ag1 = r * tc * (2 * xc - 1) / (12 * xc * xc * (1 - xc) * (1 - xc)); + ag0 = (r * tc / (xc * (1 - xc)) - (12 * xc - 6) * ag1) / 2; + + /* io = 0 */ + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * from alyotropic point + * q1, q2 + */ + case 6: + q1 = p[0]; + q2 = p[1]; + xaly = q1; + r = log(l_kb / l_kc); + alpha0 = 2 * xaly - 1; + alpha1 = 6 * xaly * (xaly - 1) + 1; + spialy = pow((LDBLE) 10., q2); + l_a0 = -999.; + l_a1 = -999.; + if (fabs(alpha0) < tol) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + else + { + azero = 1; + if (fabs(alpha0) > tol) + azero = r / alpha0; + xcaly = 1 - xaly; +/* + * Solve for a0 by Newton's method + */ + for (i = 0; i < 50; i++) + { + phi1 = + xcaly * xcaly * (azero + + (r - azero * alpha0) * (4 * xaly - + 1) / alpha1); + phi2 = + xaly * xaly * (azero + + (3 - 4 * xaly) * (azero * alpha0 - + r) / alpha1); + phi1 = xaly * l_kb * exp(phi1); + phi2 = xcaly * l_kc * exp(phi2); + fx = phi1 + phi2 - spialy; + fx1 = + xcaly * xcaly * (1 - + alpha0 * (4 * xaly - + 1) / alpha1) * phi1 + + xaly * xaly * (1 + + alpha0 * (3 - 4 * xaly) / alpha1) * phi2; + if (fabs(fx1) < 1e-10) + { + input_error++; + error_string = sformatf( + "Could not find A0 and A1 calculation from alyotropic point, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + break; + } + l_a0 = azero - fx / fx1; + test = fabs(l_a0 - azero) + fabs(fx); + azero = l_a0; + if (test < tol) + break; + } + if (i == 50) + { + input_error++; + error_string = sformatf( + "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", + s_s_ptr->name); + error_msg(error_string, CONTINUE); + } + else + { + l_a1 = (r - l_a0 * alpha0) / alpha1; + + /* io = 0 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + } + + } + break; + /* + * dimensional (kJ/mol) Guggenheim parameters + * ag0, ag1 + */ + case 7: + ag0 = p[0]; + ag1 = p[1]; + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * Waldbaum-Thompson + * wg2, wg1 + */ + case 8: + wg2 = p[0]; + wg1 = p[1]; + ag0 = (wg2 + wg1) / 2; + ag1 = (wg2 - wg1) / 2; + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * Margules + * alpha2, alpha3 + */ + case 9: + alpha2 = p[0]; + alpha3 = p[1]; + l_a0 = alpha2 + 3 * alpha3 / 4; + l_a1 = alpha3 / 4; + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + } + + s_s_ptr->ag0 = ag0; + s_s_ptr->ag1 = ag1; + s_s_ptr->a0 = l_a0; + s_s_ptr->a1 = l_a1; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_master_isotope(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + + for (i = 0; i < count_master_isotope; i++) + { + /* + * Mark master species list as minor isotope + */ + if (master_isotope[i]->minor_isotope == TRUE) + { + master_ptr = master_bsearch(master_isotope[i]->name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Did not find master species for isotope, %s", + master_isotope[i]->name); + error_msg(error_string, CONTINUE); + master_isotope[i]->master = NULL; + continue; + } + else + { + master_isotope[i]->master = master_ptr; + } + master_ptr->minor_isotope = TRUE; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_isotope_ratios(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct master *master_ptr; + struct master_isotope *master_isotope_ptr; + struct calculate_value *calculate_value_ptr; + + for (i = 0; i < count_isotope_ratio; i++) + { + /* + * Mark master species list as minor isotope + */ + master_isotope_ptr = + master_isotope_search(isotope_ratio[i]->isotope_name); + if (master_isotope_ptr == NULL) + { + input_error++; + error_string = sformatf( + "For ISOTOPE_RATIO %s, did not find ISOTOPE definition for this isotope, %s", + isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); + error_msg(error_string, CONTINUE); + } + master_ptr = master_bsearch(isotope_ratio[i]->isotope_name); + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "For ISOTOPE_RATIO %s, did not find SOLUTION_MASTER_SPECIES for isotope, %s", + isotope_ratio[i]->name, isotope_ratio[i]->isotope_name); + error_msg(error_string, CONTINUE); + } + calculate_value_ptr = calculate_value_search(isotope_ratio[i]->name); + if (calculate_value_ptr == NULL) + { + input_error++; + error_string = sformatf( + "For ISOTOPE_RATIOS %s, did not find corresponding CALCULATE_VALUE definition", + isotope_ratio[i]->name); + error_msg(error_string, CONTINUE); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_isotope_alphas(void) +/* ---------------------------------------------------------------------- */ +{ + int i; + struct calculate_value *calculate_value_ptr; + struct logk *logk_ptr; + + for (i = 0; i < count_isotope_alpha; i++) + { + /* + * Mark master species list as minor isotope + */ + calculate_value_ptr = calculate_value_search(isotope_alpha[i]->name); + if (calculate_value_ptr == NULL) + { + input_error++; + error_string = sformatf( + "For ISOTOPE_ALPHAS %s, did not find corresponding CALCULATE_VALUE definition", + isotope_alpha[i]->name); + error_msg(error_string, CONTINUE); + } + if (isotope_alpha[i]->named_logk != NULL) + { + logk_ptr = logk_search(isotope_alpha[i]->named_logk); + if (logk_ptr == NULL) + { + input_error++; + error_string = sformatf( + "For ISOTOPE_ALPHAS %s, did not find corresponding NAMED_EXPRESSION definition %s.", + isotope_alpha[i]->name, isotope_alpha[i]->named_logk); + error_msg(error_string, CONTINUE); + } + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reset_last_model(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialize model + */ + last_model.force_prep = TRUE; + last_model.count_exchange = 0; + last_model.exchange = + (struct master **) free_check_null(last_model.exchange); + last_model.count_gas_phase = 0; + last_model.gas_phase = + (struct phase **) free_check_null(last_model.gas_phase); + last_model.count_ss_assemblage = 0; + last_model.ss_assemblage = + (const char **) free_check_null(last_model.ss_assemblage); + last_model.count_pp_assemblage = 0; + last_model.pp_assemblage = + (struct phase **) free_check_null(last_model.pp_assemblage); + last_model.add_formula = + (const char **) free_check_null(last_model.add_formula); + last_model.si = (LDBLE *) free_check_null(last_model.si); + last_model.dl_type = NO_DL; + last_model.count_surface_comp = 0; + last_model.surface_comp = + (const char **) free_check_null(last_model.surface_comp); + last_model.count_surface_charge = 0; + last_model.surface_charge = + (const char **) free_check_null(last_model.surface_charge); + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_exchange(void) +/* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + //int i, j, k; + //struct exch_comp *comp_ptr; + //struct master *master_ptr; + + //for (i = 0; i < count_exchange; i++) + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + cxxExchange * exchange_ptr = &(it->second); + if (!exchange_ptr->Get_new_def()) + continue; + if (exchange_ptr->Get_n_user() < 0) + continue; + //for (j = 0; j < exchange[i].count_comps; j++) + std::vector comps = exchange_ptr->Vectorize(); + // check elements + for (size_t j = 0; j < comps.size(); j++) + { + cxxExchComp * comp_ptr = comps[j]; + if (comp_ptr->Get_phase_name().size() > 0) + continue; + if (comp_ptr->Get_rate_name().size() > 0) + continue; + + /* Check elements */ + cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble::iterator kit = nd.begin(); + for (; kit != nd.end(); kit++) + { + /* Find master species */ + //master_ptr = comp_ptr->totals[k].elt->primary; + /* Find master species */ + struct element *elt_ptr = element_store(kit->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + kit->first.c_str()); + error_msg(error_string, CONTINUE); + break; + } + } + } + } + return (OK); +} + diff --git a/rename_cpp/transport.cpp b/rename_cpp/transport.cpp new file mode 100644 index 00000000..ec5a82f8 --- /dev/null +++ b/rename_cpp/transport.cpp @@ -0,0 +1,6311 @@ +#include "Utils.h" +#include "Phreeqc.h" +#include "phqalloc.h" +#include "Exchange.h" +#include "GasPhase.h" +#include "PPassemblage.h" + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +transport(void) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, n; + int j_imm, n_m, n_imm; + LDBLE b, f, mix_f_m, mix_f_imm; + LDBLE water_m, water_imm; + int first_c, last_c, b_c; + int max_iter; + char token[MAX_LENGTH]; + LDBLE kin_time, stagkin_time, kin_time_save; + //struct mix *mix_ptr; + struct surface *surf_ptr, *surf_ptr1; + int punch_boolean; + LDBLE step_fraction; + LDBLE cb_tol; + + state = TRANSPORT; + diffc_tr = diffc; + diffc_max = 0.0; + cb_tol = 1e-9; + transp_surf = warn_fixed_Surf = warn_MCD_X = 0; +/* mass_water_switch = TRUE; */ +/* + * Check existence of solutions + */ + j = -1; + /* check column solutions */ + for (i = 1; i <= count_cells; i++) + { + use.Set_solution_ptr(solution_bsearch(i, &n, TRUE)); + if (use.Get_solution_ptr() == NULL) + { + input_error++; + error_string = sformatf( + "Solution %d is needed for transport, but is not defined.", + i); + error_msg(error_string, CONTINUE); + } + else + cell_data[i - 1].temp = use.Get_solution_ptr()->tc; + } + + if (multi_Dflag) + { + sol_D = (struct sol_D *) PHRQ_malloc((size_t) + (count_cells + 2 + stag_data->count_stag * count_cells) * + sizeof(struct sol_D)); + if (sol_D == NULL) + malloc_error(); + sol_D_dbg = sol_D; + for (i = 0; i < count_cells + 2 + stag_data->count_stag * count_cells; + i++) + { + sol_D[i].count_spec = 0; + sol_D[i].count_exch_spec = 0; + sol_D[i].exch_total = 0; + sol_D[i].x_max = 0; + sol_D[i].spec = NULL; + } + } + /* check solution 0 */ + if (solution_bsearch(0, &n, FALSE) == NULL) + { + if (ishift == 1) + { + input_error++; + error_string = sformatf( + "Solution 0 is needed for transport, but is not defined."); + error_msg(error_string, CONTINUE); + } + else + solution_duplicate(1, 0); + } + + /* check solution count_cells */ + if (solution_bsearch(count_cells + 1, &n, FALSE) == NULL) + { + if (ishift == -1) + { + input_error++; + error_string = sformatf( + "Solution %d is needed for transport, but is not defined.", + count_cells + 1); + error_msg(error_string, CONTINUE); + } + else + solution_duplicate(count_cells, count_cells + 1); + } +/* + * Initialize temperature in stagnant cells ... + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + int n_solution; + use.Set_solution_ptr(solution_bsearch(k, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + if (use.Get_solution_ptr() != NULL) + cell_data[k - 1].temp = use.Get_solution_ptr()->tc; + } + } +/* + * First equilibrate solutions + */ + dup_print("Equilibrating initial solutions", TRUE); + transport_step = 0; + for (i = 0; i <= count_cells + 1; i++) + { + if ((bcon_first == 2 && i == 0) || + (bcon_last == 2 && i == count_cells + 1)) + continue; + set_initial_moles(i); + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->transport == TRUE) + transp_surf = TRUE; + if (transp_surf && !multi_Dflag) + { + error_string = sformatf( + "-multi_d must be defined for surface transport"); + error_msg(error_string, CONTINUE); + } + if (multi_Dflag == TRUE) + { + fill_spec(cell_no); + } + if (cell_no > 0 && cell_no <= count_cells) + { + if ((cell_data[i - 1].punch == TRUE) + && (cell_no != count_cells + 1)) + punch_all(); + if ((cell_data[i - 1].print == TRUE) + && (cell_no != count_cells + 1)) + print_all(); + } +/* if (i > 0 && i <= count_cells)*/ + saver(); + } +/* + * Also stagnant cells + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + cell_no = k; + int n_solution; + + if (solution_bsearch(k, &n_solution, FALSE) != 0) + { + //use.Set_n_solution(n_solution); + set_initial_moles(k); + set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); + if (multi_Dflag == TRUE) + { + fill_spec(cell_no); + } + if ((cell_data[k - 1].punch == TRUE)) + punch_all(); + if ((cell_data[k - 1].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + saver(); + } + } + } +/* + * Initialize mixing factors, define kinetics times + * for multicomponent diffusion, limit mixing by diffc_max (usually from H+) + */ + if (multi_Dflag == TRUE) + diffc_tr = diffc_max; + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) + { + /* multi_D calc's are OK if all cells have the same amount of water */ +/* if (multi_Dflag == TRUE) + { + sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give all cells the same amount of water."); + warning_msg(token); + } + */ + +#ifdef SKIP + mix_ptr = &mix[0]; + for (i = 0; i < count_mix; i++) + mix_free(mix_ptr++); + count_mix = 2 * count_cells; +#endif + Rxn_mix_map.clear(); + +/* + * stagnant mix factors go in mix[0 .. count_cells] + */ +#ifdef SKIP + mix = (struct mix *) PHRQ_realloc(mix, + (size_t) count_mix * + sizeof(struct mix)); + if (mix == NULL) + malloc_error(); + memset(mix, 0, sizeof(struct mix) * count_mix); +#endif + } +/* + * mix[] is extended in init_mix(), to accommodate column mix factors + */ + nmix = init_mix(); + heat_nmix = init_heat_mix(nmix); + if (nmix < 2) + stagkin_time = timest; + else + stagkin_time = timest / nmix; + if (ishift != 0) + kin_time = timest / (1 + nmix); + else + kin_time = stagkin_time; + kin_time_save = kin_time; + +/* Reaction defined for a shift... */ + if (ishift == 0 && nmix == 1) + step_fraction = 1.0; + else + step_fraction = 1.0 / (1.0 + nmix); +/* + * Set boundary conditions, transport direction + */ + last_model.force_prep = TRUE; + if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) + b_c = 1; + else + b_c = 0; + if (ishift >= 0) + { + last_c = count_cells; + first_c = 1; + } + else + { + last_c = 1; + first_c = count_cells; + } +/* + * Define stagnant/mobile mix structure, if not read explicitly. + * + * With count_stag = 1, mix factors are calculated from exchange factor à + * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. + * These variables are read under keyword TRANSPORT, after stagnant, in + * structure stag_data. + * MIX 'cell_no' in input file can be an alternative for the calculation here. + */ + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) + { + b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); + f = exp(-stag_data->exch_f * stagkin_time / (b * stag_data->th_im)); + mix_f_imm = b - b * f; + mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; + n = 0; + for (i = 1; i <= count_cells; i++) + { + j = i; + j_imm = j + (1 + count_cells); + if (solution_bsearch(j, &n_m, TRUE) == NULL) + error_msg + ("Could not find mobile cell solution in TRANSPORT.", + STOP); + if (solution_bsearch(j_imm, &n_imm, TRUE) == NULL) + error_msg + ("Could not find immobile cell solution in TRANSPORT.", + STOP); + water_m = solution[n_m]->mass_water; + water_imm = solution[n_imm]->mass_water; +/* + * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 + */ + { + cxxMix temp_mix; + //mix[n].comps = + // (struct mix_comp *) PHRQ_malloc((size_t) 2 * + // sizeof(struct mix_comp)); + //if (mix[n].comps == NULL) + // malloc_error(); + //mix[n].count_comps = 2; + //mix[n].description = string_duplicate(" "); + //mix[n].n_user = j; + //mix[n].n_user_end = j; + temp_mix.Set_n_user(j); + temp_mix.Set_n_user_end(j); + + //mix[n].comps[0].n_solution = j; + //mix[n].comps[0].fraction = 1 - mix_f_m; + temp_mix.Add(j, 1 - mix_f_m); + //mix[n].comps[1].n_solution = j_imm; + //mix[n].comps[1].fraction = mix_f_m * water_m / water_imm; + temp_mix.Add(j_imm, mix_f_m * water_m / water_imm); + Rxn_mix_map[j] = temp_mix; + n++; + } +/* + * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... + */ + { + cxxMix temp_mix; + //mix[n].comps = + // (struct mix_comp *) PHRQ_malloc((size_t) 2 * + // sizeof(struct mix_comp)); + //if (mix[n].comps == NULL) + // malloc_error(); + //mix[n].count_comps = 2; + //mix[n].description = string_duplicate(" "); + //mix[n].n_user = j_imm; + //mix[n].n_user_end = j_imm; + temp_mix.Set_n_user(j_imm); + temp_mix.Set_n_user_end(j_imm); + + //mix[n].comps[0].n_solution = j_imm; + //mix[n].comps[0].fraction = 1 - mix_f_imm; + temp_mix.Add(j_imm, 1 - mix_f_imm); + //mix[n].comps[1].n_solution = j; + //mix[n].comps[1].fraction = mix_f_imm * water_imm / water_m; + temp_mix.Add(j, mix_f_imm * water_imm / water_m); + Rxn_mix_map[j_imm] = temp_mix; + n++; + } + } + + if (heat_nmix > 0) + { +/* + * Assumption: D_e used for calculating exch_f in input file equals diffc + */ + f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; + f = exp(-f * stagkin_time / (b * stag_data->th_im)); + heat_mix_f_imm = b - b * f; + heat_mix_f_m = + heat_mix_f_imm * stag_data->th_im / stag_data->th_m; + } + } +/* + * Stop if error + */ + if (get_input_errors() > 0) + { + error_msg("Program terminating due to input errors.", STOP); + } +/* + * Now transport + */ + max_iter = 0; + for (transport_step = transport_start; transport_step <= count_shifts; + transport_step++) + { + /* + * Set initial moles of phases + */ + for (i = 1; i <= count_cells; i++) + set_initial_moles(i); + /* + * Also stagnant cells + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + cell_no = k; + int n_solution; + if (solution_bsearch(k, &n_solution, FALSE) != 0) + { + //use.Set_n_solution(n_solution); + set_initial_moles(k); + } + } + } +/* + * Start diffusing if boundary cond = 1, (fixed c, or closed) + */ + if (b_c == 1) + { + /* For half of mixing steps */ + for (j = 1; j <= floor((LDBLE) nmix / 2); j++) + { + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * kin_time; + rate_sim_time = rate_sim_time_start + kin_time; + + if (multi_Dflag) + sprintf(token, + "Transport step %3d. Multicomponent diffusion run %3d.", + transport_step, j); + else + sprintf(token, "Transport step %3d. Mixrun %3d.", + transport_step, j); + dup_print(token, FALSE); + + if (heat_nmix > 0) + { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i = 1; i <= count_cells; i++) + { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag) + fill_spec(i); + saver(); + } + } + /* Go through cells */ + if (transp_surf) + { + if (disp_surf(stagkin_time) == ERROR) + error_msg("Error in surface transport, stopping.", + STOP); + } + if (multi_Dflag) + multi_D(stagkin_time, 1, FALSE); + + for (i = 1; i <= count_cells; i++) + { + + if (iterations > max_iter) + max_iter = iterations; + if (multi_Dflag) + sprintf(token, + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + else + sprintf(token, + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + status(0, token); + + cell_no = i; + run_reactions(i, kin_time, DISP, step_fraction); + if (multi_Dflag) + fill_spec(i); + + /* punch and output file */ + int n_solution; + if ((ishift == 0) && (j == nmix) + && ((stag_data->count_stag == 0) + || solution_bsearch(i + 1 + count_cells, + &n_solution, FALSE) == 0)) + { + //use.Set_n_solution(n_solution); + if ((cell_data[i - 1].punch == TRUE) + && (transport_step % punch_modulus == 0)) + punch_all(); + if ((cell_data[i - 1].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + } + if (i > 1) + solution_duplicate(-2, i - 1); + saver(); + + /* maybe sorb a surface component... */ + if ((ishift == 0) && (j == nmix) + && ((stag_data->count_stag == 0) + || solution_bsearch(i + 1 + count_cells, + &n_solution, FALSE) == 0)) + { + //use.Set_n_solution(n_solution); + if (change_surf_count > 0) + { + for (k = 0; k < change_surf_count; k++) + { + if (change_surf[k].cell_no != i) + break; + reformat_surf(change_surf[k].comp_name, + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); + change_surf[k].cell_no = -99; + } + change_surf_count = 0; + } + } + } + solution_duplicate(-2, count_cells); + + /* Stagnant zone mixing after completion of each + diffusive/dispersive step ... */ + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * stagkin_time; + rate_sim_time = rate_sim_time_start + stagkin_time; + + if (stag_data->count_stag > 0) + { + if ((ishift == 0) && (j == nmix)) + punch_boolean = TRUE; + else + punch_boolean = FALSE; + for (i = 1; i <= count_cells; i++) + mix_stag(i, stagkin_time, punch_boolean, + step_fraction); + } + } + } +/* + * Advective transport + */ + if (ishift != 0) + { + sprintf(token, "Transport step %3d.", transport_step); + dup_print(token, FALSE); + if (b_c == 1) + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * kin_time; + else + rate_sim_time_start = (transport_step - 1) * timest; + rate_sim_time = rate_sim_time_start + kin_time; + + /* halftime kinetics for resident water in first cell ... */ + if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) + { + cell_no = first_c; + kin_time = kin_time_save / 2; + run_reactions(first_c, kin_time, NOMIX, 0.0); + saver(); + kin_time = kin_time_save; + } + + /* for each cell in column */ + for (i = last_c; i != (first_c - ishift); i -= ishift) + solution_duplicate(i - ishift, i); + +/* if boundary_solutions must be flushed by the flux from the column... + if (ishift == 1 && bcon_last == 3) + solution_duplicate (last_c, last_c + 1); + else if (ishift == -1 && bcon_first == 3) + solution_duplicate (last_c, last_c - 1); + */ + if (transp_surf) + { + for (i = last_c + ishift; i != (first_c - ishift); + i -= ishift) + { + if ((ishift == 1 && i == last_c + 1 && bcon_last != 3) || + (ishift == -1 && i == last_c - 1 && bcon_first != 3)) + continue; + int n_surface; + if ((surf_ptr = + surface_bsearch(i - ishift, &n_surface)) == NULL) + { + if ((surface_bsearch(i, &n_surface) != NULL) && + ((i == 0 && bcon_first == 3) + || (i == count_cells + 1 && bcon_last == 3))) + surface_delete(i); + continue; + } + if (surf_ptr->transport) + { + if ((surf_ptr1 = + surface_bsearch(i, &n_surface)) == NULL) + { + n = count_surface++; + space((void **) ((void *) &surface), + count_surface, &max_surface, + sizeof(struct surface)); + surf_ptr1 = &surface[n]; + surf_ptr1->count_comps = 0; + } + if (i == first_c) + mobile_surface_copy(surf_ptr, surf_ptr1, i, + FALSE); + else + mobile_surface_copy(surf_ptr, surf_ptr1, i, TRUE); + if (surface[n].n_user < surface[n - 1].n_user) + surface_sort(); + } + } + } + +/* + * thermal diffusion when nmix = 0... + */ + if ((nmix == 0) && (heat_nmix > 0)) + { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i = 1; i <= count_cells; i++) + { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag) + fill_spec(i); + saver(); + } + } + + for (i = 1; i <= count_cells; i++) + { + if (i == first_c && count_cells > 1) + kin_time /= 2; + if (multi_Dflag) + sprintf(token, + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); + else + sprintf(token, + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); + status(0, token); + cell_no = i; + run_reactions(i, kin_time, NOMIX, step_fraction); + if (multi_Dflag == TRUE) + fill_spec(i); + if (iterations > max_iter) + max_iter = iterations; + int n_solution; + if ((nmix == 0) && ((stag_data->count_stag == 0) || + (solution_bsearch + (i + 1 + count_cells, &n_solution, + FALSE) == 0))) + { + if ((cell_data[i - 1].punch == TRUE) + && (transport_step % punch_modulus == 0)) + punch_all(); + if ((cell_data[i - 1].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + } + if (i == first_c && count_cells > 1) + kin_time = kin_time_save; + saver(); + + /* maybe sorb a surface component... */ + if ((nmix == 0) && ((stag_data->count_stag == 0) || + (solution_bsearch + (i + 1 + count_cells, &n_solution, + FALSE) == 0))) + { + if (change_surf_count > 0) + { + for (k = 0; k < change_surf_count; k++) + { + if (change_surf[k].cell_no != i) + break; + reformat_surf(change_surf[k].comp_name, + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); + change_surf[k].cell_no = -99; + } + change_surf_count = 0; + } + } + + /* If nmix is zero, stagnant zone mixing after + advective step ... */ + if ((nmix == 0) && (stag_data->count_stag > 0)) + { + mix_stag(i, stagkin_time, TRUE, step_fraction); + } + } + } +/* + * Further dispersive and diffusive transport + */ + if (b_c != 1) + j = 1; + for (j = j; j <= nmix; j++) + { + if (multi_Dflag) + sprintf(token, + "Transport step %3d. Multicomponent diffusion run %3d.", + transport_step, j); + else + sprintf(token, "Transport step %3d. Mixrun %3d.", + transport_step, j); + dup_print(token, FALSE); + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * kin_time; + if (ishift != 0) + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start + kin_time; + + if (heat_nmix > 0) + { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i = 1; i <= count_cells; i++) + { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag) + fill_spec(i); + saver(); + } + } + if (transp_surf) + { + if (disp_surf(stagkin_time) == ERROR) + error_msg("Error in surface transport, stopping.", STOP); + } + + if (multi_Dflag == TRUE) + multi_D(stagkin_time, 1, FALSE); + + /* for each cell in column */ + for (i = 1; i <= count_cells; i++) + { + if (iterations > max_iter) + max_iter = iterations; + if (multi_Dflag) + sprintf(token, + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + else + sprintf(token, + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + status(0, token); + cell_no = i; + run_reactions(i, kin_time, DISP, step_fraction); + if (multi_Dflag == TRUE) + fill_spec(i); + int n_solution; + if ((j == nmix) && ((stag_data->count_stag == 0) || + (solution_bsearch + (i + 1 + count_cells, &n_solution, + FALSE) == 0))) + { + if ((cell_data[i - 1].punch == TRUE) + && (transport_step % punch_modulus == 0)) + punch_all(); + if ((cell_data[i - 1].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + } + if (i > 1) + solution_duplicate(-2, i - 1); + saver(); + + /* maybe sorb a surface component... */ + if ((j == nmix) && ((stag_data->count_stag == 0) || + (solution_bsearch + (i + 1 + count_cells, &n_solution, + FALSE) == 0))) + { + if (change_surf_count > 0) + { + for (k = 0; k < change_surf_count; k++) + { + if (change_surf[k].cell_no != i) + break; + reformat_surf(change_surf[k].comp_name, + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); + change_surf[k].cell_no = -99; + } + change_surf_count = 0; + } + } + } + solution_duplicate(-2, count_cells); + + /* Stagnant zone mixing after completion of each + diffusive/dispersive step ... */ + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * stagkin_time; + rate_sim_time = rate_sim_time_start + stagkin_time; + + if (stag_data->count_stag > 0) + { + if (j == nmix) + punch_boolean = TRUE; + else + punch_boolean = FALSE; + for (i = 1; i <= count_cells; i++) + mix_stag(i, stagkin_time, punch_boolean, step_fraction); + } + } + if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) + dump(); + } +#ifdef DOS + screen_msg("\n"); +#else + screen_msg(sformatf("%s%-80s", "\n", " "));; +#endif + /* free_model_allocs(); */ +/* + * free mix structures + */ + Dispersion_mix_map.clear(); + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) + { + //mix_ptr = &mix[0]; + //for (i = 0; i < count_mix; i++) + // mix_free(mix_ptr++); + Rxn_mix_map.clear(); + //count_mix = 0; + } + //else + //{ + //if (nmix > 0) + //{ + //mix_ptr = &mix[count_mix - count_cells]; + //for (i = count_mix - count_cells; i < count_mix; i++) + //mix_free(mix_ptr++); + + //count_mix -= count_cells; + //mix = + // (struct mix *) PHRQ_realloc(mix, + // (size_t) (count_mix + + // 1) * + // sizeof(struct mix)); + //if (mix == NULL) + // malloc_error(); + //} + //} +#ifdef SKIP +/* + * free mix structures + */ + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) + { + mix_ptr = &mix[0]; + for (i = 0; i < count_mix; i++) + mix_free(mix_ptr++); + count_mix = 0; + } + else + { + if (nmix > 0) + { + mix_ptr = &mix[count_mix - count_cells]; + for (i = count_mix - count_cells; i < count_mix; i++) + mix_free(mix_ptr++); + + count_mix -= count_cells; + mix = + (struct mix *) PHRQ_realloc(mix, + (size_t) (count_mix + + 1) * + sizeof(struct mix)); + if (mix == NULL) + malloc_error(); + } + } +#endif + if (heat_nmix > 0) + { + heat_mix_array = (LDBLE *) free_check_null(heat_mix_array); + temp1 = (LDBLE *) free_check_null(temp1); + temp2 = (LDBLE *) free_check_null(temp2); + } + if (multi_Dflag) + { + for (i = 0; i < count_cells + 2 + stag_data->count_stag * count_cells; + i++) + sol_D[i].spec = (struct spec *) free_check_null(sol_D[i].spec); + sol_D = (struct sol_D *) free_check_null(sol_D); + } + + initial_total_time += rate_sim_time; + rate_sim_time = 0; + mass_water_switch = FALSE; + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +init_mix(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE dav, lav, mixf, maxmix, corr_disp, diffc_here, mD; + int i, l_nmix; + + std::vector m; + for(i = 0; i < count_cells + 1; i++) + { + m.push_back(0); + } + //LDBLE *m; + + //m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + //if (m == NULL) + // malloc_error(); + if (multi_Dflag == TRUE) + diffc_here = 0.0; + else + diffc_here = diffc_tr; +/* + * Define mixing factors among inner cells + */ + corr_disp = 1.; + if (correct_disp == TRUE && ishift != 0) + { + if (bcon_first == 3) + corr_disp += 1. / count_cells; + if (bcon_last == 3) + corr_disp += 1. / count_cells; + } + maxmix = 0.0; + + for (i = 1; i < count_cells; i++) + { + lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + if (ishift != 0) + dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; + if (mixf > maxmix) + maxmix = mixf; + m[i] = mixf; /* m[i] has mixf with lower cell */ + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) + { + lav = cell_data[0].length; + if (ishift != 0) + dav = cell_data[0].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + if (mixf > maxmix) + maxmix = mixf; + m[0] = 2 * mixf; + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } + else + m[0] = 0; + + if (bcon_last == 1) + { + lav = cell_data[count_cells - 1].length; + if (ishift != 0) + dav = cell_data[count_cells - 1].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + if (mixf > maxmix) + maxmix = mixf; + m[count_cells] = 2 * mixf; + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } + else + m[count_cells] = 0; + +/* + * Find number of mixes + */ + if (maxmix == 0) + { + l_nmix = 0; + if (multi_Dflag == TRUE && mcd_substeps > 1 + && stag_data->count_stag > 0) + l_nmix = (int) ceil(mcd_substeps); + } + else + { + if ((bcon_first == 1) || (bcon_last == 1)) + l_nmix = 1 + (int) floor(4.5 * maxmix); + else + l_nmix = 1 + (int) floor(3.0 * maxmix); + + if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) + { + if (l_nmix < 2) + l_nmix = 2; + } + if (multi_Dflag == TRUE && mcd_substeps > 1) + l_nmix = (int) ceil(l_nmix * mcd_substeps); + + for (i = 0; i <= count_cells; i++) + m[i] /= l_nmix; + } + /* + * Fill mix structure + */ + + if (l_nmix != 0) + { + //mix = (struct mix *) PHRQ_realloc(mix, + // (size_t) (count_mix + + // count_cells) * + // sizeof(struct mix)); + //if (mix == NULL) + // malloc_error(); + //count_mix += count_cells; + //for (n = count_mix - count_cells; n < count_mix; n++) + //{ + //mix[n].description = NULL; + //mix[n].count_comps = 3; + //mix[n].comps = + // (struct mix_comp *) PHRQ_malloc((size_t) 3 * + // sizeof(struct mix_comp)); + //if (mix[n].comps == NULL) + // malloc_error(); + //} + + //n = count_mix - count_cells; +/* + * max_mix brings n_user outside range of active cells + * mix[n].n_user = mix[n].n_user_end = -999 has same effect + * but max_mix keeps mix in sort order in case mix_bsearch + * is used + */ + //if (n - 1 <= 0) + //{ + // max_mix = 1; + //else + // max_mix = mix[n - 1].n_user + 1; + + //if (max_mix < count_cells * (stag_data->count_stag + 1) + 1) + // max_mix = count_cells * (stag_data->count_stag + 1) + 1; + + for (i = 1; i <= count_cells; i++) + { + cxxMix temp_mix; + dav = 0; + //count_comps = 0; + //mix[n].description = (char *) free_check_null(mix[n].description); + //mix[n].description = string_duplicate(" "); +/* + * again, max_mix brings n_user outside range of active cells, etc... + */ + //mix[n].n_user = max_mix + i; + //mix[n].n_user_end = max_mix + i; + temp_mix.Set_n_user(i); + temp_mix.Set_n_user_end(i); + + //mix[n].comps[count_comps].n_solution = i - 1; + //mix[n].comps[count_comps].fraction = m[i - 1]; + temp_mix.Add(i - 1, m[i - 1]); + + dav += m[i - 1]; + //count_comps++; + //mix[n].comps[count_comps].n_solution = i + 1; + //mix[n].comps[count_comps].fraction = m[i]; + temp_mix.Add(i + 1, m[i]); + + dav += m[i]; + //count_comps++; + //mix[n].comps[count_comps].n_solution = i; + //mix[n].comps[count_comps].fraction = 1.0 - dav; + temp_mix.Add(i, 1.0 - dav); + Dispersion_mix_map[i] = temp_mix; + //n++; + } + } + //m = (LDBLE *) free_check_null(m); + return (l_nmix); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +init_mix(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE dav, lav, mixf, maxmix, corr_disp, diffc_here, mD; + int i, n, l_nmix, count_comps, max_mix; + LDBLE *m; + + m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + if (m == NULL) + malloc_error(); + if (multi_Dflag == TRUE) + diffc_here = 0.0; + else + diffc_here = diffc_tr; +/* + * Define mixing factors among inner cells + */ + corr_disp = 1.; + if (correct_disp == TRUE && ishift != 0) + { + if (bcon_first == 3) + corr_disp += 1. / count_cells; + if (bcon_last == 3) + corr_disp += 1. / count_cells; + } + maxmix = 0.0; + for (i = 1; i < count_cells; i++) + { + lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + if (ishift != 0) + dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + else + dav = 0; + + mixf = + (diffc_here * timest / lav + + dav) * corr_disp / cell_data[i].length; + if (mixf > maxmix) + maxmix = mixf; + m[i] = mixf; /* m[i] has mixf with lower cell */ + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) + { + lav = cell_data[0].length; + if (ishift != 0) + dav = cell_data[0].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + if (mixf > maxmix) + maxmix = mixf; + m[0] = 2 * mixf; + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } + else + m[0] = 0; + + if (bcon_last == 1) + { + lav = cell_data[count_cells - 1].length; + if (ishift != 0) + dav = cell_data[count_cells - 1].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + if (mixf > maxmix) + maxmix = mixf; + m[count_cells] = 2 * mixf; + if (multi_Dflag == TRUE) + { + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } + } + else + m[count_cells] = 0; + +/* + * Find number of mixes + */ + if (maxmix == 0) + { + l_nmix = 0; + if (multi_Dflag == TRUE && mcd_substeps > 1 + && stag_data->count_stag > 0) + l_nmix = (int) ceil(mcd_substeps); + } + else + { + if ((bcon_first == 1) || (bcon_last == 1)) + l_nmix = 1 + (int) floor(4.5 * maxmix); + else + l_nmix = 1 + (int) floor(3.0 * maxmix); + + if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) + { + if (l_nmix < 2) + l_nmix = 2; + } + if (multi_Dflag == TRUE && mcd_substeps > 1) + l_nmix = (int) ceil(l_nmix * mcd_substeps); + + for (i = 0; i <= count_cells; i++) + m[i] /= l_nmix; + } + /* + * Fill mix structure + */ + if (l_nmix != 0) + { + mix = + (struct mix *) PHRQ_realloc(mix, + (size_t) (count_mix + + count_cells) * + sizeof(struct mix)); + if (mix == NULL) + malloc_error(); + count_mix += count_cells; + for (n = count_mix - count_cells; n < count_mix; n++) + { + mix[n].description = NULL; + mix[n].count_comps = 3; + mix[n].comps = + (struct mix_comp *) PHRQ_malloc((size_t) 3 * + sizeof(struct mix_comp)); + if (mix[n].comps == NULL) + malloc_error(); + } + + n = count_mix - count_cells; +/* + * max_mix brings n_user outside range of active cells + * mix[n].n_user = mix[n].n_user_end = -999 has same effect + * but max_mix keeps mix in sort order in case mix_bsearch + * is used + */ + if (n - 1 <= 0) + max_mix = 1; + else + max_mix = mix[n - 1].n_user + 1; + + if (max_mix < count_cells * (stag_data->count_stag + 1) + 1) + max_mix = count_cells * (stag_data->count_stag + 1) + 1; + + for (i = 1; i <= count_cells; i++) + { + dav = 0; + count_comps = 0; + mix[n].description = (char *) free_check_null(mix[n].description); + mix[n].description = string_duplicate(" "); +/* + * again, max_mix brings n_user outside range of active cells, etc... + */ + mix[n].n_user = max_mix + i; + mix[n].n_user_end = max_mix + i; + + mix[n].comps[count_comps].n_solution = i - 1; + mix[n].comps[count_comps].fraction = m[i - 1]; + dav += m[i - 1]; + count_comps++; + mix[n].comps[count_comps].n_solution = i + 1; + mix[n].comps[count_comps].fraction = m[i]; + dav += m[i]; + count_comps++; + mix[n].comps[count_comps].n_solution = i; + mix[n].comps[count_comps].fraction = 1.0 - dav; + + n++; + } + } + m = (LDBLE *) free_check_null(m); + return (l_nmix); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ + int j, n, k, l; + LDBLE t_imm; + struct solution *ptr_imm, *ptr_m; +/* + * Kinetics in transport cell is done while transporting + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + k = i + 1 + n * count_cells; + int n_solution; + if ((ptr_imm = solution_bsearch(k, &n_solution, FALSE)) != NULL) + { + if (n == 1) + { + if (heat_nmix > 0) + { + ptr_m = solution_bsearch(i, &n_solution, FALSE); + t_imm = + heat_mix_f_imm * ptr_m->tc + (1 - + heat_mix_f_imm) * + ptr_imm->tc; + ptr_m->tc = + heat_mix_f_m * ptr_imm->tc + (1 - + heat_mix_f_m) * + ptr_m->tc; + cell_data[i - 1].temp = ptr_m->tc; + cell_data[k - 1].temp = ptr_imm->tc = t_imm; + /* equilibrate again ... */ + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag == TRUE) + fill_spec(cell_no); + saver(); + cell_no = k; + set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); + if (multi_Dflag == TRUE) + fill_spec(cell_no); + saver(); + } +/* + * Mobile cell, kinetics already done ... + */ + cell_no = i; + if (transp_surf) + { + if (diff_stag_surf(i) == ERROR) + error_msg("Error in surface transport, stopping.", + STOP); + } + if (multi_Dflag == TRUE) + multi_D(1.0, i, TRUE); + set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); + if (multi_Dflag == TRUE) + fill_spec(cell_no); + use.Set_kinetics_ptr(kinetics_bsearch(i, &l)); + if (use.Get_kinetics_ptr() != NULL) + { + use.Set_n_kinetics_user(i); + use.Set_kinetics_in(true); + } + + if (l_punch && (cell_data[i - 1].print == TRUE) && + (transport_step % print_modulus == 0)) + print_all(); + if (l_punch && (cell_data[i - 1].punch == TRUE) && + (transport_step % punch_modulus == 0)) + punch_all(); + saver(); + + /* maybe sorb a surface component... */ + if (l_punch && change_surf_count) + { + for (j = 0; j < change_surf_count; j++) + { + if (change_surf[j].cell_no != i) + break; + reformat_surf(change_surf[j].comp_name, + change_surf[j].fraction, + change_surf[j].new_comp_name, + change_surf[j].new_Dw, + change_surf[j].cell_no); + change_surf[j].cell_no = -99; + } + change_surf_count = 0; + } + } + + cell_no = k; + run_reactions(k, kin_time, STAG, step_fraction); + if (multi_Dflag == TRUE) + fill_spec(cell_no); + + if ((cell_data[k - 1].print == TRUE) && (l_punch == TRUE) && + (transport_step % print_modulus == 0)) + print_all(); + if ((cell_data[k - 1].punch == TRUE) && (l_punch == TRUE) && + (transport_step % punch_modulus == 0)) + punch_all(); + saver(); + + /* maybe sorb a surface component... */ + if (l_punch && change_surf_count) + { + for (j = 0; j < change_surf_count; j++) + { + if (change_surf[j].cell_no != k) + break; + reformat_surf(change_surf[j].comp_name, + change_surf[j].fraction, + change_surf[j].new_comp_name, + change_surf[j].new_Dw, + change_surf[j].cell_no); + change_surf[j].cell_no = -99; + } + change_surf_count = 0; + } + } + } + for (n = 1; n <= stag_data->count_stag; n++) + { + k = i + 1 + n * count_cells; + int n_solution; + if (solution_bsearch(k, &n_solution, FALSE) != 0) + { + solution_duplicate(-2 - k, k); + if (n == 1) + solution_duplicate(-2, i); + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +init_heat_mix(int l_nmix) +/* ---------------------------------------------------------------------- */ +{ + LDBLE lav, mixf, maxmix, corr_disp; + int i, j, k, n; + int l_heat_nmix; + LDBLE t0; +/* + * Check for need to model thermal diffusion... + */ + if (heat_diffc <= diffc) + return (0); + if (count_cells < 2) + return (0); + + l_heat_nmix = 0; + t0 = solution_bsearch(0, &n, FALSE)->tc; + for (i = 0; i < count_cells; i++) + { + if (fabs(cell_data[i].temp - t0) > 1.0) + { + l_heat_nmix = 1; + break; + } + } + if (l_heat_nmix == 0) + { + if (fabs(solution_bsearch(count_cells + 1, &n, FALSE)->tc - t0) > 1.0) + l_heat_nmix = 1; + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i < count_cells; i++) + { + k = i + 1 + n * count_cells; + if (solution_bsearch(k, &j, FALSE) != 0) + { + if (fabs(cell_data[k - 1].temp - t0) > 1.0) + { + l_heat_nmix = 1; + break; + } + } + } + } + } + if (l_heat_nmix == 0) + return (0); +/* + * Initialize arrays... + */ + heat_mix_array = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + if (heat_mix_array == NULL) + malloc_error(); + + temp1 = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + if (temp1 == NULL) + malloc_error(); + + temp2 = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + if (temp2 == NULL) + malloc_error(); +/* + * Define mixing factors among inner cells... + */ + corr_disp = 1.; + if (correct_disp == TRUE && ishift != 0) + { + if (bcon_first == 3) + corr_disp += 1. / count_cells; + if (bcon_last == 3) + corr_disp += 1. / count_cells; + } + if (l_nmix > 0) + corr_disp /= l_nmix; + maxmix = 0.0; + for (i = 1; i < count_cells; i++) + { + lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + mixf = + (heat_diffc - + diffc_tr) * timest * corr_disp / tempr / (lav * lav); + if (mixf > maxmix) + maxmix = mixf; + heat_mix_array[i + 1] = mixf; /* m[i] has mixf with lower cell */ + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) + { + lav = cell_data[0].length; + mixf = + (heat_diffc - + diffc_tr) * timest * corr_disp / tempr / (lav * lav); + if (2 * mixf > maxmix) + maxmix = 2 * mixf; + heat_mix_array[1] = 2 * mixf; + } + else + heat_mix_array[1] = 0; + + if (bcon_last == 1) + { + lav = cell_data[count_cells - 1].length; + mixf = + (heat_diffc - + diffc_tr) * timest * corr_disp / tempr / (lav * lav); + if (2 * mixf > maxmix) + maxmix = 2 * mixf; + heat_mix_array[count_cells + 1] = 2 * mixf; + } + else + heat_mix_array[count_cells + 1] = 0; +/* + * Find number of mixes + */ + if (maxmix == 0) + l_heat_nmix = 0; + else + { + l_heat_nmix = 1 + (int) floor(3.0 * maxmix); + for (i = 1; i <= count_cells + 1; i++) + heat_mix_array[i] /= l_heat_nmix; + } + + return (l_heat_nmix); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +heat_mix(int l_heat_nmix) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + + for (i = 1; i <= count_cells; i++) + temp1[i] = solution_bsearch(i, &j, FALSE)->tc; + temp1[0] = solution_bsearch(0, &j, FALSE)->tc; + temp1[count_cells + 1] = + solution_bsearch((count_cells + 1), &j, FALSE)->tc; + + for (i = 1; i <= l_heat_nmix; i++) + { + for (j = 1; j <= count_cells; j++) + temp2[j] = + heat_mix_array[j] * temp1[j - 1] + heat_mix_array[j + + 1] * + temp1[j + 1] + (1 - heat_mix_array[j] - + heat_mix_array[j + 1]) * temp1[j]; + for (j = 1; j <= count_cells; j++) + temp1[j] = temp2[j]; + } + + for (i = 1; i <= count_cells; i++) + { + cell_data[i - 1].temp = temp1[i]; + solution_bsearch(i, &j, FALSE)->tc = temp1[i]; + } + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_initial_moles(int i) +/* ---------------------------------------------------------------------- */ +{ + //struct pp_assemblage *pp_assemblage_ptr; + //struct gas_phase *gas_phase_ptr; + struct kinetics *kinetics_ptr; + struct ss_assemblage *ss_assemblage_ptr; + //struct exchange *exchange_ptr; + char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; + int j, k, l, n; + /* + * Pure phase assemblage + */ + { + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); + if (pp_assemblage_ptr != NULL) + { + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + //gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; + it->second.Set_initial_moles(it->second.Get_moles()); + if (it->second.Get_initial_moles() < 0) + it->second.Set_initial_moles(0.0); + } + } + } +#ifdef SKIP + pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); + if (pp_assemblage_ptr != NULL) + { + for (j = 0; j < pp_assemblage_ptr->count_comps; j++) + { + pp_assemblage_ptr->pure_phases[j].initial_moles = + pp_assemblage_ptr->pure_phases[j].moles; + if (pp_assemblage_ptr->pure_phases[j].initial_moles < 0) + pp_assemblage_ptr->pure_phases[j].initial_moles = 0; + } + } +#endif + /* + * Gas phase + */ + //gas_phase_ptr = gas_phase_bsearch(i, &n); + { + cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, i); + if (gas_phase_ptr != NULL) + { + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t l = 0; l < gc.size(); l++) + { + //gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; + gc[l].Set_initial_moles(gc[l].Get_moles()); + } + gas_phase_ptr->Set_gas_comps(gc); + } + } + /* + * Kinetics + */ + kinetics_ptr = kinetics_bsearch(i, &n); + if (kinetics_ptr != NULL) + { + for (j = 0; j < kinetics_ptr->count_comps; j++) + kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; + } + /* + * Solid solutions + */ + ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); + if (ss_assemblage_ptr != NULL) + { + for (k = 0; k < ss_assemblage_ptr->count_s_s; k++) + { + for (j = 0; j < ss_assemblage_ptr->s_s[k].count_comps; j++) + ss_assemblage_ptr->s_s[k].comps[j].init_moles = + ss_assemblage_ptr->s_s[k].comps[j].moles; + } + } + /* + * For interlayer diffusion: add tiny bit of exchanger if absent + */ + //exchange_ptr = exchange_bsearch(i, &n); + cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, i); + if (interlayer_Dflag && exchange_ptr == NULL) + { + cxxExchange temp_exchange; + temp_exchange.Set_n_user(i); + temp_exchange.Set_n_user_end(i); + temp_exchange.Set_description("Interlayer diffusion: added 2e-10 moles X-"); + use.Set_exchange_in(true); + use.Set_n_exchange_user(i); + + temp_exchange.Set_new_def(true); + temp_exchange.Set_solution_equilibria(true); + temp_exchange.Set_n_solution(i); + + cxxExchComp comp; + count_elts = 0; + paren_count = 0; + strcpy(token, "X"); + ptr = token; + get_elts_in_species(&ptr, 2e-10); + ptr = token; + LDBLE z; + get_token(&ptr, token1, &z, &l); + comp.Set_formula(token1); + comp.Set_formula_z(z); + comp.Set_formula_totals(elt_list_NameDouble()); + comp.Set_moles(2e-10); + comp.Set_totals(elt_list_NameDouble()); + comp.Set_charge_balance(0.0); + temp_exchange.Get_exchComps()[token1] = comp; + Rxn_exchange_map[i] = temp_exchange; + + state = INITIAL_EXCHANGE; + initial_exchangers(TRUE); + state = TRANSPORT; + } +#ifdef SKIP + exchange_ptr = exchange_bsearch(i, &n); + if (interlayer_Dflag && exchange_ptr == NULL) + { + n = count_exchange++; + space((void **) ((void *) &exchange), count_exchange, &max_exchange, + sizeof(struct exchange)); + exchange_init(&(exchange[n]), i, i, + "Interlayer diffusion: added 2e-10 moles X-"); + use.Get_exchange_in() = TRUE; + use.Get_n_exchange_user() = i; + exchange[n].new_def = TRUE; + exchange[n].solution_equilibria = TRUE; + exchange[n].n_solution = i; + exchange[n].n_user = exchange[n].n_user_end = i; + count_elts = 0; + paren_count = 0; + strcpy(token, "X"); + ptr = token; + get_elts_in_species(&ptr, 2e-10); + ptr = token; + get_token(&ptr, token1, &exchange[n].comps[0].formula_z, &l); + exchange[n].comps[0].formula_totals = elt_list_save(); + exchange[n].comps[0].moles = 2e-10; + exchange[n].comps[0].totals = elt_list_save(); + exchange[n].comps[0].charge_balance = 0.0; + exchange[n].count_comps = 1; + if (n == count_exchange - 1 && count_exchange > 1) + { + if (exchange[n].n_user < exchange[n - 1].n_user) + { + qsort(exchange, + (size_t) count_exchange, + (size_t) sizeof(struct exchange), exchange_compare); + } + } + state = INITIAL_EXCHANGE; + initial_exchangers(TRUE); + state = TRANSPORT; + } +#endif + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +fill_spec(int l_cell_no) +/* ---------------------------------------------------------------------- */ +{ +/* copy species activities into sol_D.spec... */ + + int i, i2, count_spec, count_exch_spec; + char token[MAX_LENGTH]; + const char * name; + struct species *s_ptr, *s_ptr2; + struct master *master_ptr; + LDBLE dum, dum2; + LDBLE lm; + LDBLE por, por_il, temp_factor, temp_il_factor, viscos; + bool x_max_done = false; + + s_ptr2 = NULL; + + sol_D[l_cell_no].spec = + (struct spec *) free_check_null(sol_D[l_cell_no].spec); + sol_D[l_cell_no].spec = + (struct spec *) PHRQ_malloc((size_t) count_species_list * + sizeof(struct spec)); + if (sol_D[l_cell_no].spec == NULL) + malloc_error(); + + temp_factor = temp_il_factor = 1.0; + if (l_cell_no == 0) + { + por = cell_data[0].por; + por_il = cell_data[0].por_il; + } + else if (l_cell_no == count_cells + 1) + { + por = cell_data[count_cells - 1].por; + por_il = cell_data[count_cells - 1].por_il; + } + else + { + por = cell_data[l_cell_no - 1].por; + por_il = cell_data[l_cell_no - 1].por_il; + } + if (por < multi_Dpor_lim) + por = temp_factor = 0.0; + + if (por_il < interlayer_Dpor_lim) + por_il = temp_il_factor = 0.0; +/* + * correct diffusion coefficient for temperature and viscosity, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + */ + viscos = viscosity(); +/* + * put temperature factor in por_factor which corrects for porous medium... + */ + temp_factor *= tk_x * 0.88862 / (298.15 * viscos); + temp_il_factor *= tk_x * 0.88862 / (298.15 * viscos); + + count_spec = count_exch_spec = 0; +/* + * sort species by name... + */ + if (count_species_list > 0) + qsort(&species_list[0], (size_t) count_species_list, + (size_t) sizeof(struct species_list), sort_species_name); + + for (i = 0; i < count_species_list; i++) + { +/* + * copy species data + */ + s_ptr = species_list[i].s; + + if (s_ptr->type == EX && !interlayer_Dflag) + continue; + if (s_ptr->type == SURF) + continue; + if (i > 0 && strcmp(s_ptr->name, species_list[i - 1].s->name) == 0) + continue; + if (s_ptr == s_h2o) + continue; + + if (s_ptr->type == EX) + { + if (s_ptr->moles > 1e-30) + { + /* find exchanger's name, use only master exchanger 'X' */ + if (species_list[i].master_s->secondary != NULL) + master_ptr = species_list[i].master_s->secondary; + else + master_ptr = species_list[i].master_s->primary; + if (s_ptr->equiv != 0.0) + dum = fabs(s_ptr->equiv) / master_ptr->total; + else + { + if (species_list[i].master_s->z == 0) + dum = 1 / master_ptr->total; + else + dum = 1; + } + name = master_ptr->elt->name; + if (strcmp(name, "X") != 0) + { + if (!warn_MCD_X) + { + sprintf(token, + "MCD found more than 1 exchanger, uses X for interlayer diffusion."); + warning_msg(token); + warn_MCD_X = 1; + } + continue; + } + dum2 = s_ptr->moles * dum; /* equivalent fraction */ + sol_D[l_cell_no].spec[count_spec].name = + string_hsave(s_ptr->name); + sol_D[l_cell_no].spec[count_spec].type = EX; + sol_D[l_cell_no].spec[count_spec].c = dum2; + sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg - log10(dum); + sol_D[l_cell_no].spec[count_spec].a = dum2 * pow(10, + sol_D + [l_cell_no]. + spec + [count_spec]. + lg); + sol_D[l_cell_no].exch_total = master_ptr->total; + if (transport_step == 0 && !x_max_done) + { + x_max_done = true; + dum = master_ptr->total / solution_bsearch(l_cell_no, &i2, TRUE)->mass_water; + if (dum > sol_D[1].x_max) + sol_D[1].x_max = dum; + } + + /* find the aqueous species in the exchange reaction... */ + for (i2 = 0; (s_ptr->rxn->token[i2].s != NULL); i2++) + { + if ((s_ptr2 = s_ptr->rxn->token[i2].s)->type == AQ) + break; + } + /* copy its name and Dw and charge... */ + sol_D[l_cell_no].spec[count_spec].aq_name = + string_hsave(s_ptr2->name); + sol_D[l_cell_no].spec[count_spec].z = s_ptr2->z; + if (s_ptr2->dw == 0) + sol_D[l_cell_no].spec[count_spec].Dwt = + default_Dw * temp_il_factor; + else + sol_D[l_cell_no].spec[count_spec].Dwt = + s_ptr2->dw * temp_il_factor; + count_exch_spec++; + count_spec++; + } + continue; + } + + lm = s_ptr->lm; + if (lm > MIN_LM) + { + sol_D[l_cell_no].spec[count_spec].name = string_hsave(s_ptr->name); + sol_D[l_cell_no].spec[count_spec].type = AQ; + sol_D[l_cell_no].spec[count_spec].c = + s_ptr->moles / mass_water_aq_x; + sol_D[l_cell_no].spec[count_spec].a = under(lm + s_ptr->lg); + sol_D[l_cell_no].spec[count_spec].lm = lm; + sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg; + sol_D[l_cell_no].spec[count_spec].z = s_ptr->z; + if (s_ptr->dw == 0) + sol_D[l_cell_no].spec[count_spec].Dwt = + default_Dw * temp_factor; + else + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * temp_factor; + if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > + diffc_max) + diffc_max = + sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); + sol_D[l_cell_no].spec[count_spec].erm_ddl = s_ptr->erm_ddl; + + count_spec++; + } + } + sol_D[l_cell_no].spec = + (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, + (size_t) count_spec * + sizeof(struct spec)); + if (sol_D[l_cell_no].spec == NULL) + malloc_error(); + + sol_D[l_cell_no].count_spec = count_spec; + sol_D[l_cell_no].count_exch_spec = count_exch_spec; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sort_species_name(const void *ptr1, const void *ptr2) +/* ---------------------------------------------------------------------- */ +{ + const struct species_list *nptr1, *nptr2; + + nptr1 = (const struct species_list *) ptr1; + nptr2 = (const struct species_list *) ptr2; + + return (strcmp(nptr1->s->name, nptr2->s->name)); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +multi_D(LDBLE DDt, int mobile_cell, int stagnant) +/* ---------------------------------------------------------------------- */ +{ + /* + * 1. determine mole transfer (mol/s) of solute species for the interface between 2 cells. + * 2. sum up as mole transfer of master_species + * 3. add moles of master_species to the 2 cells + * NOTE. Define the water content of stagnant cells relative to the + * mobile cell (with, for example, 1 kg water) + * Define properties of each interface only 1 time with MIX. + */ + int icell, jcell, i, j, k, l, n, length, length2, il_calcs; + int i1; + int first_c, last_c; + char token[MAX_LENGTH]; + LDBLE mixf, temp; + + for (n = 0; n < (stagnant ? stag_data->count_stag : 1); n++) + { + icell = mobile_cell + 1 + n * count_cells; + if (stagnant) + { + if (n == 0) + icell -= 1; + /* + * find the mix ptr for icell and go along the cells that mix with it + */ + //use.Get_mix_ptr() = mix_search(icell, &use.n_mix, FALSE); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); + if (use.Get_mix_ptr() == NULL) + continue; + first_c = 0; + //last_c = use.Get_mix_ptr()->count_comps - 1; + last_c = (int) (((cxxMix *) use.Get_mix_ptr())->Get_mixComps().size() - 1); + } + else + { /* regular column... */ + if (bcon_first == 1) + first_c = 0; + else + first_c = 1; + if (bcon_last == 1) + last_c = count_cells; + else + last_c = count_cells - 1; + } + + for (i = first_c; i <= last_c; i++) + { + if (stagnant) + { + std::vector n_solution; + std::vector fraction; + ((cxxMix *) use.Get_mix_ptr())->Vectorize(n_solution, fraction); + //std::map::const_iterator cit; + //for (cit = ((cxxMix *) use.Get_mix_ptr())->Get_mixComps().begin(); cit != ((cxxMix *) use.Get_mix_ptr())->Get_mixComps().end(); cit++) + //{ + // n_solution.push_back(cit->first); + // fraction.push_back(cit->second); + //} + //if ((jcell = use.Get_mix_ptr()->comps[i].n_solution) <= icell) + if ((jcell = n_solution[i]) <= icell) + continue; + //mixf = use.Get_mix_ptr()->comps[i].fraction; + + mixf = fraction[i]; + if (mcd_substeps > 1) + mixf /= nmix; + } + else + { /* regular column... */ + icell = i; + jcell = i + 1; + mixf = 1.0; + } + /* + * 1. obtain J_ij... + */ + il_calcs = find_J(icell, jcell, mixf, DDt, stagnant); + /* + * 2. sum up the primary or secondary master_species + */ + if (!il_calcs) + { + tot1_h = tot1_o = tot2_h = tot2_o = 0.0; + m_s = (struct M_S *) free_check_null(m_s); + m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * + sizeof(struct M_S)); + if (m_s == NULL) + malloc_error(); + for (i1 = 0; i1 < count_elements; i1++) + { + m_s[i1].name = NULL; + m_s[i1].tot1 = 0; + m_s[i1].tot2 = 0; + } + count_m_s = 0; + } + fill_m_s(J_ij, J_ij_count_spec); + + /* + * 3. find the solutions, add or subtract the moles... + */ + if (i > 0 || stagnant) + { + int n_solution; + use.Set_solution_ptr(solution_bsearch(icell, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + use.Get_solution_ptr()->total_h -= tot1_h; + use.Get_solution_ptr()->total_o -= tot1_o; + use.Get_solution_ptr()->cb -= J_ij_sum; + for (l = 0; l < count_m_s; l++) + { + temp = 0.0; + length = (int) strlen(m_s[l].name); + for (j = 0; + use.Get_solution_ptr()->totals[j].description != NULL; j++) + { + length2 = + (int) (size_t) strcspn(use.Get_solution_ptr()-> + totals[j].description, + "("); + if (strncmp + (m_s[l].name, + use.Get_solution_ptr()->totals[j].description, + length) == 0 && length == length2) + { + if (use.Get_solution_ptr()->totals[j].moles < + m_s[l].tot1) + { + temp = use.Get_solution_ptr()->totals[j].moles; + use.Get_solution_ptr()->totals[j].moles = 0; + /* see if other redox states have more moles... */ + for (k = 1; + use.Get_solution_ptr()->totals[j + + k]. + description != NULL; k++) + { + length2 = + (int) (size_t) strcspn(use.Get_solution_ptr()-> + totals[j + k]. + description, + "("); + if (strncmp + (m_s[l].name, + use.Get_solution_ptr()->totals[j + + k]. + description, length) == 0 + && length == length2) + { + temp += + use.Get_solution_ptr()->totals[j + + k].moles; + if (temp < m_s[l].tot1) + { + use.Get_solution_ptr()->totals[j + + k]. + moles = 0; + } + else + { + use.Get_solution_ptr()->totals[j + + k]. + moles = temp - m_s[l].tot1; + temp = 0.0; + break; + } + } + } + if (temp != 0.0 && m_s[l].tot1 - temp > 1e-12) + { + sprintf(token, + "Negative concentration in MCD: added %.1e moles %s in cell %d.", + (double) (m_s[l].tot1 - temp), + m_s[l].name, icell); + warning_msg(token); + } + } + else + use.Get_solution_ptr()->totals[j].moles -= + m_s[l].tot1; + break; + } + } + if (use.Get_solution_ptr()->totals[j].description == NULL) + { + use.Get_solution_ptr()->totals = + (struct conc *) PHRQ_realloc(use.Get_solution_ptr()-> + totals, + (size_t) (j + + 2) * + sizeof(struct conc)); + use.Get_solution_ptr()->totals[j].description = + string_hsave(m_s[l].name); + use.Get_solution_ptr()->totals[j].moles = -m_s[l].tot1; + if (use.Get_solution_ptr()->totals[j].moles < 0) + { + if (use.Get_solution_ptr()->totals[j].moles < -1e-12) + { + sprintf(token, + "Negative concentration in MCD: added %.2e moles %s in cell %d", + (double) -use.Get_solution_ptr()-> + totals[j].moles, m_s[l].name, icell); + warning_msg(token); + } + use.Get_solution_ptr()->totals[j].moles = 0; + } + use.Get_solution_ptr()->totals[j + 1].description = NULL; + } + } + } + if (i < count_cells || stagnant) + { + int n_solution; + use.Set_solution_ptr( + solution_bsearch(jcell, &n_solution, FALSE)); + //use.Set_n_solution(n_solution); + use.Get_solution_ptr()->total_h += tot2_h; + use.Get_solution_ptr()->total_o += tot2_o; + use.Get_solution_ptr()->cb += J_ij_sum; + for (l = 0; l < count_m_s; l++) + { + temp = 0.0; + length = (int) strlen(m_s[l].name); + for (j = 0; + use.Get_solution_ptr()->totals[j].description != NULL; j++) + { + length2 = + (int) (size_t) strcspn(use.Get_solution_ptr()-> + totals[j].description, + "("); + if (strncmp + (m_s[l].name, + use.Get_solution_ptr()->totals[j].description, + length) == 0 && length == length2) + { + if (use.Get_solution_ptr()->totals[j].moles < + -m_s[l].tot2) + { + temp = use.Get_solution_ptr()->totals[j].moles; + use.Get_solution_ptr()->totals[j].moles = 0; + /* see if other redox states have more moles... */ + for (k = 1; + use.Get_solution_ptr()->totals[j + + k]. + description != NULL; k++) + { + length2 = + (int) (size_t) strcspn(use.Get_solution_ptr()-> + totals[j + k]. + description, + "("); + if (strncmp + (m_s[l].name, + use.Get_solution_ptr()->totals[j + + k]. + description, length) == 0 + && length == length2) + { + temp += + use.Get_solution_ptr()->totals[j + + k].moles; + if (temp < -m_s[l].tot2) + { + use.Get_solution_ptr()->totals[j + + k]. + moles = 0; + } + else + { + use.Get_solution_ptr()->totals[j + + k]. + moles = temp + m_s[l].tot2; + temp = 0.0; + break; + } + } + } + if (temp != 0.0 + && -m_s[l].tot2 - temp > 1e-12) + { + sprintf(token, + "Negative concentration in MCD: added %.3e moles %s in cell %d", + (double) (-m_s[l].tot2 - temp), + m_s[l].name, jcell); + warning_msg(token); + } + } + else + use.Get_solution_ptr()->totals[j].moles += + m_s[l].tot2; + break; + } + } + if (use.Get_solution_ptr()->totals[j].description == NULL) + { + use.Get_solution_ptr()->totals = + (struct conc *) PHRQ_realloc(use.Get_solution_ptr()-> + totals, + (size_t) (j + + 2) * + sizeof(struct conc)); + use.Get_solution_ptr()->totals[j].description = + string_hsave(m_s[l].name); + use.Get_solution_ptr()->totals[j].moles = m_s[l].tot2; + if (use.Get_solution_ptr()->totals[j].moles < 0) + { + if (use.Get_solution_ptr()->totals[j].moles < -1e-12) + { + sprintf(token, + "Negative concentration in MCD: added %.4e moles %s in cell %d", + (double) -use.Get_solution_ptr()-> + totals[j].moles, m_s[l].name, jcell); + warning_msg(token); + } + use.Get_solution_ptr()->totals[j].moles = 0; + } + use.Get_solution_ptr()->totals[j + 1].description = NULL; + } + } + } + } + } + m_s = (struct M_S *) free_check_null(m_s); + J_ij = (struct J_ij *) free_check_null(J_ij); + J_ij_il = (struct J_ij *) free_check_null(J_ij_il); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) +/* ---------------------------------------------------------------------- */ +{ +/* sum up the primary or secondary master_species from solute species + * H and O go in tot1&2_h and tot1&2_o + */ + int j, k, l; + char *ptr; + + for (j = 0; j < l_J_ij_count_spec; j++) + { + { + char * temp_name = string_duplicate(l_J_ij[j].name); + ptr = temp_name; + count_elts = 0; + get_elts_in_species(&ptr, 1); + free_check_null(temp_name); + } + for (k = 0; k < count_elts; k++) + { + if (strcmp(elt_list[k].elt->name, "X") == 0) + continue; + if (strcmp(elt_list[k].elt->name, "H") == 0) + { + tot1_h += elt_list[k].coef * l_J_ij[j].tot1; + tot2_h += elt_list[k].coef * l_J_ij[j].tot2; + } + else if (strcmp(elt_list[k].elt->name, "O") == 0) + { + tot1_o += elt_list[k].coef * l_J_ij[j].tot1; + tot2_o += elt_list[k].coef * l_J_ij[j].tot2; + } + else + { + for (l = 0; l < count_m_s; l++) + { + if (strcmp(m_s[l].name, elt_list[k].elt->name) == 0) + { + m_s[l].tot1 += elt_list[k].coef * l_J_ij[j].tot1; + m_s[l].tot2 += elt_list[k].coef * l_J_ij[j].tot2; + break; + } + } + if (l == count_m_s) + { + m_s[l].name = string_hsave(elt_list[k].elt->name); + m_s[l].tot1 = elt_list[k].coef * l_J_ij[j].tot1; + m_s[l].tot2 = elt_list[k].coef * l_J_ij[j].tot2; + count_m_s++; + } + } + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) +/* ---------------------------------------------------------------------- */ +{ + /* mole transfer of the individual master_species: + * Eqn 1: + * J_ij = DDt * (A_ij / lav) * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * regular column, stagnant FALSE: + * D_i = temperature-corrected Dw + * A_ij = A_icell * A_jcell + * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / + * (length_icell / 2) + * lav = A_icell + A_jcell + * grad(c) is concentration difference in icell and jcell, + for activity corrections see Appelo & Wersin, 2007. + * stagnant TRUE: + * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por + * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; + * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. + * Interlayer diffusion (IL) takes the gradient in the equivalent concentrations on X-. + surface area A for IL: + stagnant: mixf_il is mixf * por_il / por. + por_il = interlayer porosity, from -interlayer_D true 'por_il'. + por = total porosity, from -multi_D true 'multi_Dpor'. + **nov. 12, 2011**: + mixf is corrected, * (1 - por_il / por). + new_pf = (por - por_il)^(-multi_Dn). + in regular column, A is calc'd from (free + DL porewater) and cell-length. + for IL: A * por_il / (por - por_il). + + por_il is entered as a single value. It is limited to 0.999 * por. + por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) + + IL-water = (free + DL porewater) * por_il / (por - por_il). + */ + int i, i_max, j, j_max, k, k_il, l, only_counter, il_calcs; + int i1; + LDBLE lav, A1, A2, A_ij, A_ij_il, ddlm, aq1, aq2, mixf_il; + LDBLE dl_s, dl_aq1, dl_aq2, c_dl, visc1, visc2, dum, dum2, tort1, tort2; + LDBLE por_il1, por_il2, por_il12; + LDBLE c, Dz2c, Dz2c_dl, Dz2c_il, aq_il1, aq_il2; + LDBLE cec1, cec2, cec12, rc1, rc2; + struct V_M + { + LDBLE grad, D, z, Dz, Dzc, Dzc_dl, g_dl; + int o_c; + } *V_M, *V_M_il; + struct surface *s_ptr1, *s_ptr2; + struct surface_charge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; + //struct exchange *ex_ptr1, *ex_ptr2; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + V_M = V_M_il = NULL; + /* check for immediate return and interlayer diffusion calcs... */ + if (interlayer_Dflag) + { + il_calcs = 1; + if (icell == 0 && cell_data[0].por_il < interlayer_Dpor_lim) + il_calcs = 0; + else if (icell == count_cells && + cell_data[count_cells - 1].por_il < interlayer_Dpor_lim) + il_calcs = 0; + else if (icell > 0 + && (cell_data[icell - 1].por_il < interlayer_Dpor_lim + || cell_data[jcell - 1].por_il < interlayer_Dpor_lim)) + il_calcs = 0; + } + else + il_calcs = 0; + + if (stagnant) + { + if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim + || cell_data[jcell - 1].por < multi_Dpor_lim)) + return (OK); + } + else + { /* regular column... */ + if (icell == 0) + { + if (!il_calcs && cell_data[0].por < multi_Dpor_lim) + return (OK); + } + else if (icell == count_cells) + { + if (!il_calcs && cell_data[count_cells - 1].por < multi_Dpor_lim) + return (OK); + } + else + { + if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim + || cell_data[jcell - 1].por < multi_Dpor_lim)) + return (OK); + } + } + + /* do the calcs */ + aq1 = solution_bsearch(icell, &i, TRUE)->mass_water; + aq2 = solution_bsearch(jcell, &i, TRUE)->mass_water; + /* + * check if DL calculations must be made, find amounts of water... + */ + s_charge_ptr1 = s_charge_ptr2 = NULL; + s_ptr1 = s_ptr2 = NULL; + dl_s = dl_aq1 = dl_aq2 = 0.0; + visc1 = visc2 = 1.0; + only_counter = FALSE; + + s_ptr1 = surface_bsearch(icell, &i); + if (s_ptr1 != NULL) + { + if (s_ptr1->dl_type != NO_DL) + { + if (s_ptr1->only_counter_ions) + only_counter = TRUE; + /* find the one (and only one...) immobile surface comp with DL... */ + for (i = 0; i < s_ptr1->count_comps; i++) + { + if (s_ptr1->comps[i].Dw == 0) + { + s_charge_ptr1 = &s_ptr1->charge[s_ptr1->comps[i].charge]; + dl_aq1 = s_charge_ptr1->mass_water; + visc1 = s_ptr1->DDL_viscosity; + /* check for more comps with Dw = 0 */ + for (j = i + 1; j < s_ptr1->count_comps; j++) + { + if (s_ptr1->comps[j].Dw == 0 + && s_ptr1->comps[j].charge != + s_ptr1->comps[i].charge) + { + if (!warn_fixed_Surf) + { + k = (int) strcspn(s_ptr1->comps[i].formula, "_"); + strncpy(token1, s_ptr1->comps[i].formula, k); + token1[k] = '\0'; + sprintf(token, + "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", + token1); + warning_msg(token); + warn_fixed_Surf = 1; + } + break; + } + } + break; + } + } + } + } + s_ptr2 = surface_bsearch(jcell, &i); + if (s_ptr2 != NULL) + { + if (s_ptr2->dl_type != NO_DL) + { + if (s_ptr2->only_counter_ions) + only_counter = TRUE; + for (i = 0; i < s_ptr2->count_comps; i++) + { + if (s_ptr2->comps[i].Dw == 0) + { + s_charge_ptr2 = &s_ptr2->charge[s_ptr2->comps[i].charge]; + dl_aq2 = s_charge_ptr2->mass_water; + visc2 = s_ptr2->DDL_viscosity; + /* check for more comps with Dw = 0 */ + for (j = i + 1; j < s_ptr2->count_comps; j++) + { + if (s_ptr2->comps[j].Dw == 0 + && s_ptr2->comps[j].charge != + s_ptr2->comps[i].charge) + { + if (!warn_fixed_Surf) + { + k = (int) strcspn(s_ptr2->comps[i].formula, "_"); + strncpy(token1, s_ptr2->comps[i].formula, k); + token1[k] = '\0'; + sprintf(token, + "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", + token1); + warning_msg(token); + warn_fixed_Surf = 1; + } + break; + } + } + break; + } + } + } + } + if (!stagnant) + { + if (icell == 0) + visc1 = visc2; + else if (icell == count_cells) + visc2 = visc1; + } + /* in each cell: DL surface = mass_water_DL / (cell_length) + free pore surface = mass_water_free / (cell_length) + determine DL surface as a fraction of the total pore surface... */ + if (dl_aq1 > 0) + dl_s = dl_aq1 / (dl_aq1 + aq1); + if (dl_aq2 > 0) + { + dum = dl_aq2 / (dl_aq2 + aq2); + if (dl_aq1 > 0) + /* average the 2... */ + dl_s = (dl_s + dum) / 2; + else + /* there is one DL surface... */ + dl_s = dum; + } + + por_il1 = por_il2 = por_il12 = 0.0; + cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; + if (il_calcs) + { + /* find interlayer porosity por_il, + make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). + Find amounts of IL water and cec. + Must do this separately, since por and por_il are in cell_data structure. */ + if (icell == 0) + { + por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * + cell_data[0].por_il; + por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * + cell_data[0].por_il; + if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) + /* take the average... */ + por_il12 = (por_il1 + por_il2) / 2; + else + /* at column ends, take the clay... */ + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[0].por) + por_il12 = 0.999 * cell_data[0].por; + + if (por_il2 > 0.999 * cell_data[0].por) + por_il2 = 0.999 * cell_data[0].por; + aq_il2 = (aq2 + dl_aq2) * por_il2 / + (cell_data[0].por - por_il2); + /* Assume interlayer water is proportional with CEC... */ + aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; + } + else if (icell == count_cells) + { + por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * + cell_data[count_cells - 1].por_il; + por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * + cell_data[count_cells - 1].por_il; + if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) + por_il12 = (por_il1 + por_il2) / 2; + else + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[count_cells - 1].por) + por_il12 = 0.999 * cell_data[count_cells - 1].por; + + if (por_il1 > 0.999 * cell_data[count_cells - 1].por) + por_il1 = 0.999 * cell_data[count_cells - 1].por; + aq_il1 = (aq1 + dl_aq1) * por_il1 / + (cell_data[count_cells - 1].por - por_il1); + aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / + sol_D[count_cells].exch_total; + } + else + { + por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * + cell_data[icell - 1].por_il; + por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * + cell_data[jcell - 1].por_il; + + if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) + por_il12 = (por_il1 + por_il2) / 2; + else + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[icell - 1].por || por_il12 > 0.999 * cell_data[jcell - 1].por) + por_il12 = (cell_data[icell - 1].por >= cell_data[jcell - 1].por ? + 0.999 * cell_data[jcell - 1].por : + 0.999 * cell_data[icell - 1].por); + aq_il1 = (aq1 + dl_aq1) * por_il1 / + (cell_data[icell - 1].por - por_il1); + aq_il2 = (aq2 + dl_aq2) * por_il2 / + (cell_data[jcell - 1].por - por_il2); +/* former code... */ + //aq_il1 = (aq1 + dl_aq1) * cell_data[icell - 1].por_il / + // cell_data[icell - 1].por; + //aq_il2 = (aq2 + dl_aq2) * cell_data[jcell - 1].por_il / + // cell_data[jcell - 1].por; +/* end */ + } + if (por_il12 == 0) + il_calcs = 0; + else + { + dum = sol_D[icell].exch_total; + dum2 = sol_D[jcell].exch_total; + rc1 = (dum2 > dum ? dum / dum2 : 1); + rc2 = (dum > dum2 ? dum2 / dum : 1); + if (sol_D[icell].exch_total > 3e-10) + cec1 = dum / aq_il1; + else + cec1 = 2e-10; + if (sol_D[jcell].exch_total > 3e-10) + cec2 = dum2 / aq_il2; + else + cec2 = 2e-10; + /* and the largest for calculating the mass transfer... */ + cec12 = (cec1 > cec2 ? cec1 : cec2); + } + } + + /* In stagnant calc's, find mixf_il for IL diffusion, correct mixf. + In regular column, find surface areas A and A_il */ + tort1 = tort2 = lav = 1.0; + A_ij = A_ij_il = mixf_il = 0.0; + if (stagnant) + { + mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); + dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? + cell_data[icell - 1].por : cell_data[jcell - 1].por); + if (il_calcs) + { + mixf_il = mixf * por_il12 / interlayer_tortf; + dum -= por_il12; + } + mixf *= (dum * pow(dum, multi_Dn)); +/* former code... */ + //mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); + //dum = (cell_data[icell - 1].por_il <= cell_data[jcell - 1].por_il ? + // cell_data[icell - 1].por_il : cell_data[jcell - 1].por_il); + //mixf_il = mixf * dum / interlayer_tortf; + //dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? + // cell_data[icell - 1].por : cell_data[jcell - 1].por); + //mixf *= dum * pow(dum, multi_Dn); +/* end */ + } + else + { /* regular column... */ + if (icell == 0) + { + tort1 = tort2 = pow(cell_data[0].por, -multi_Dn); + lav = cell_data[0].length; + A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); + if (il_calcs) + A_ij_il = + A_ij * por_il12 / ((cell_data[0].por - por_il12) * + interlayer_tortf); + A_ij /= tort1; + } + else if (icell == count_cells) + { + tort1 = tort2 = pow(cell_data[count_cells - 1].por, -multi_Dn); + lav = cell_data[count_cells - 1].length; + A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); + if (il_calcs) + A_ij_il = A_ij * por_il12 / + ((cell_data[count_cells - 1].por - por_il12) * interlayer_tortf); + A_ij /= tort2; + } + else + { + tort1 = pow(cell_data[icell - 1].por, -multi_Dn); + tort2 = pow(cell_data[jcell - 1].por, -multi_Dn); + A1 = (aq1 + dl_aq1) / (cell_data[icell - 1].length * + 0.5 * cell_data[icell - 1].length); + A2 = (aq2 + dl_aq2) / (cell_data[jcell - 1].length * + 0.5 * cell_data[jcell - 1].length); + if (il_calcs) + { + dum = A1 * por_il12 / + ((cell_data[icell - 1].por - por_il12) * interlayer_tortf); + dum2 = A2 * por_il12 / + ((cell_data[jcell - 1].por - por_il12) * interlayer_tortf); + A_ij_il = dum * dum2 / (dum + dum2); + } + A1 /= tort1; + A2 /= tort2; + A_ij = A1 * A2 / (A1 + A2); +/* former code... */ + //A1 = aq1 / (cell_data[icell - 1].length * + // 0.5 * cell_data[icell - 1].length); + //A2 = aq2 / (cell_data[jcell - 1].length * + // 0.5 * cell_data[jcell - 1].length); + //dum = A1 * cell_data[icell - 1].por_il / + // (cell_data[icell - 1].por * interlayer_tortf); + //dum2 = A2 * cell_data[jcell - 1].por_il / + // (cell_data[jcell - 1].por * interlayer_tortf); + //A_ij_il = dum * dum2 / (dum + dum2); + //A1 /= tort1; + //A2 /= tort2; + //A_ij = A1 * A2 / (A1 + A2); + + //A1 = dl_aq1 / (cell_data[icell - 1].length * + // 0.5 * cell_data[icell - 1].length); + //A2 = dl_aq2 / (cell_data[jcell - 1].length * + // 0.5 * cell_data[jcell - 1].length); + //dum = A1 * cell_data[icell - 1].por_il / + // (cell_data[icell - 1].por * interlayer_tortf); + //dum2 = A2 * cell_data[jcell - 1].por_il / + // (cell_data[jcell - 1].por * interlayer_tortf); + //if (dum + dum2 > 0) + //{ + // A_ij_il += dum * dum2 / (dum + dum2); + // A1 /= tort1; + // A2 /= tort2; + // A_ij += (A1 * A2 / (A1 + A2)); + //} +/* end */ + } + } + /* diffuse... */ + J_ij_count_spec = 0; + J_ij_sum = 0.0; + /* + * malloc sufficient space... + */ + k = sol_D[icell].count_spec + sol_D[jcell].count_spec; + + J_ij = (struct J_ij *) free_check_null(J_ij); + J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + if (J_ij == NULL) + malloc_error(); + + V_M = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + if (V_M == NULL) + malloc_error(); + + for (i = 0; i < k; i++) + { + J_ij[i].tot1 = 0.0; + V_M[i].grad = 0.0; + V_M[i].D = 0.0; + V_M[i].Dz = 0.0; + V_M[i].Dzc = 0.0; + V_M[i].Dzc_dl = 0.0; + V_M[i].g_dl = 1.0; + V_M[i].o_c = 1; + } + Dz2c = Dz2c_dl = Dz2c_il = 0.0; + + if (il_calcs) + { + /* also for interlayer cations */ + k = sol_D[icell].count_exch_spec + sol_D[jcell].count_exch_spec; + + J_ij_il = (struct J_ij *) free_check_null(J_ij_il); + J_ij_il = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + if (J_ij_il == NULL) + malloc_error(); + + V_M_il = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + if (V_M_il == NULL) + malloc_error(); + for (i = 0; i < k; i++) + { + J_ij_il[i].tot1 = 0.0; + V_M_il[i].grad = 0.0; + V_M_il[i].D = 0.0; + V_M_il[i].Dz = 0.0; + V_M_il[i].Dzc = 0.0; + V_M_il[i].Dzc_dl = 0.0; + V_M_il[i].g_dl = 1.0; + V_M_il[i].o_c = 1; + } + } + /* + * coefficients in Eqn (1)... + */ + i = j = k = k_il = 0; + i_max = sol_D[icell].count_spec; + j_max = sol_D[jcell].count_spec; + + while (i < i_max || j < j_max) + { + if (j == j_max + || (i < i_max + && strcmp(sol_D[icell].spec[i].name, + sol_D[jcell].spec[j].name) < 0)) + { + /* species 'name' is only in icell */ + if (il_calcs && sol_D[icell].spec[i].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; + V_M_il[k_il].z = sol_D[icell].spec[i].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * sol_D[icell].spec[i].c * cec12 / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + V_M[k].D = sol_D[icell].spec[i].Dwt; + V_M[k].z = sol_D[icell].spec[i].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = V_M[k].Dz * sol_D[icell].spec[i].c / 2; + if (dl_s > 0) + { + s_charge_ptr = + (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; + for (l = 0; l < s_charge_ptr->count_g; l++) + { + if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) + == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) + || (s_charge_ptr->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2; + } + } + else + { + if (dl_aq1 > 0) + { + V_M[k].g_dl = + (1 + + s_charge_ptr->g[l].g * aq1 / + dl_aq1) * + sol_D[icell].spec[i].erm_ddl; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2 * V_M[k].g_dl; + } + else + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2; + } + break; + } + } + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + k++; + } + if (i < i_max) + i++; + } + else if (i == i_max + || (j < j_max + && strcmp(sol_D[icell].spec[i].name, + sol_D[jcell].spec[j].name) > 0)) + { + /* species 'name' is only in jcell */ + if (il_calcs && sol_D[jcell].spec[j].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); + V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; + V_M_il[k_il].z = sol_D[jcell].spec[j].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * sol_D[jcell].spec[j].c * cec12 / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = sol_D[jcell].spec[j].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); + V_M[k].D = sol_D[jcell].spec[j].Dwt; + V_M[k].z = sol_D[jcell].spec[j].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = V_M[k].Dz * sol_D[jcell].spec[j].c / 2; + if (dl_s > 0) + { + s_charge_ptr = + (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; + for (l = 0; l < s_charge_ptr->count_g; l++) + { + if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) + == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) + || (s_charge_ptr->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2; + } + } + else + { + if (dl_aq2 > 0) + { + V_M[k].g_dl = + (1 + + s_charge_ptr->g[l].g * aq2 / + dl_aq2) * + sol_D[jcell].spec[j].erm_ddl; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2 * V_M[k].g_dl; + } + else + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2; + } + break; + } + } + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + k++; + } + if (j < j_max) + j++; + } + else if (strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) + == 0) + { + /* species 'name' is in both cells */ + if (il_calcs && sol_D[icell].spec[i].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + if (sol_D[icell].spec[i].Dwt == 0 + || sol_D[jcell].spec[j].Dwt == 0) + V_M_il[k_il].D = 0.0; + else + V_M_il[k_il].D = + (sol_D[icell].spec[i].Dwt + + sol_D[jcell].spec[j].Dwt) / 2; + + V_M_il[k_il].z = sol_D[icell].spec[i].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + + sol_D[jcell].spec[j].c * cec2) / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + if (sol_D[icell].spec[i].Dwt == 0 + || sol_D[jcell].spec[j].Dwt == 0) + V_M[k].D = 0.0; + else + V_M[k].D = + (sol_D[icell].spec[i].Dwt + + sol_D[jcell].spec[j].Dwt) / 2; + + V_M[k].z = sol_D[icell].spec[i].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = + V_M[k].Dz * (sol_D[icell].spec[i].c + + sol_D[jcell].spec[j].c) / 2; + /* Dzc[k] = Dz[k] * (sol_D[icell].spec[i].c > sol_D[jcell].spec[j].c ? sol_D[icell].spec[i].c : sol_D[jcell].spec[j].c); + */ + if (dl_s > 0) + { + c_dl = 0.0; + if (dl_aq1 > 0) + { + for (l = 0; l < s_charge_ptr1->count_g; l++) + { + if (equal + (s_charge_ptr1->g[l].charge, V_M[k].z, + G_TOL) == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr1->la_psi < 0 + && V_M[k].z < 0) + || (s_charge_ptr1->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + c_dl = sol_D[icell].spec[i].c / 2; + } + } + else + { + V_M[k].g_dl = + (1 + + s_charge_ptr1->g[l].g * aq1 / + dl_aq1) * + sol_D[icell].spec[i].erm_ddl; + c_dl = + sol_D[icell].spec[i].c / 2 * + V_M[k].g_dl; + } + break; + } + } + } + else + c_dl = sol_D[icell].spec[i].c / 2; + + if (dl_aq2 > 0) + { + for (l = 0; l < s_charge_ptr2->count_g; l++) + { + if (equal + (s_charge_ptr2->g[l].charge, V_M[k].z, + G_TOL) == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr2->la_psi < 0 + && V_M[k].z < 0) + || (s_charge_ptr2->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + dum = 1.0; + c_dl += + sol_D[jcell].spec[j].c / 2 * dum; + V_M[k].g_dl = + (V_M[k].g_dl + dum) / 2; + } + } + else + { + dum = + (1 + + s_charge_ptr2->g[l].g * aq2 / + dl_aq2) * + sol_D[jcell].spec[j].erm_ddl; + c_dl += sol_D[jcell].spec[j].c / 2 * dum; + V_M[k].g_dl = (V_M[k].g_dl + dum) / 2; + } + break; + } + } + } + else if (V_M[k].o_c == 1) + c_dl += sol_D[jcell].spec[j].c / 2; + + V_M[k].Dzc_dl = V_M[k].Dz * c_dl; + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = + (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; + if (fabs(ddlm) > 1e-10) + V_M[k].grad *= + (1 + + (sol_D[jcell].spec[j].lg - + sol_D[icell].spec[i].lg) / ddlm); + k++; + } + if (i < i_max) + i++; + if (j < j_max) + j++; + } + } + /* + * fill in J_ij... + */ + if (Dz2c == 0) + k = 0; + J_ij_count_spec = i_max = k; + J_ij_sum = 0; + c = c_dl = 0.0; + for (i = 0; i < i_max; i++) + { + c += V_M[i].Dz * V_M[i].grad; + c_dl += V_M[i].o_c * V_M[i].Dz * V_M[i].g_dl * V_M[i].grad; + } + for (i = 0; i < i_max; i++) + { + J_ij[i].tot1 = -V_M[i].D * V_M[i].grad + c * V_M[i].Dzc / Dz2c; + J_ij[i].tot1 *= (1 - dl_s); + if (Dz2c_dl > 0) + { + dum = + (-V_M[i].D * V_M[i].g_dl * V_M[i].grad + + c_dl * V_M[i].Dzc_dl / Dz2c_dl) * (2 / (visc1 + visc2)); + if ((J_ij[i].tot1 <= 0 && dum <= 0) + || (J_ij[i].tot1 > 0 && dum > 0)) + { + J_ij[i].tot1 += V_M[i].o_c * dum * dl_s; + } + } + /* + * multiply with timestep... + * for stagnant, DDt = 1, the timestep is in mixf. + * NOTE (for stagnant). The timestep calculated in init_mix for MCD (by PHREEQC) must be equal + * or smaller than the timestep taken (by the user) for calculating mixf in MIX. + * Make this timestep small enough, consider the largest Dw in phreeqd.dat (usually H+). + * Dw used for calculating mixf must be given as default_Dw in the input file. + */ + if (stagnant) + J_ij[i].tot1 *= mixf; + else + J_ij[i].tot1 *= A_ij * DDt; + J_ij_sum += V_M[i].z * J_ij[i].tot1; + J_ij[i].tot2 = J_ij[i].tot1; + } + /* + * calculate interlayer mass transfer... + */ + if (il_calcs && Dz2c_il != 0 && k_il > 0) + { + + cxxExchange *ex_ptr1 = Utilities::Rxn_find(Rxn_exchange_map, icell); + cxxExchange *ex_ptr2 = Utilities::Rxn_find(Rxn_exchange_map, jcell); + c = 0.0; + i_max = k_il; + for (i = 0; i < i_max; i++) + c += V_M_il[i].Dz * V_M_il[i].grad; + for (i = 0; i < i_max; i++) + { + J_ij_il[i].tot1 = -V_M_il[i].D * V_M_il[i].grad + + c * V_M_il[i].Dzc / Dz2c_il; + if (stagnant) + J_ij_il[i].tot1 *= mixf_il; + else + J_ij_il[i].tot1 *= A_ij_il * DDt; + J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; + J_ij_il[i].tot2 = J_ij_il[i].tot1; + } + + /* express the transfer in elemental moles... */ + tot1_h = tot1_o = tot2_h = tot2_o = 0.0; + m_s = (struct M_S *) free_check_null(m_s); + m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * + sizeof(struct M_S)); + if (m_s == NULL) + malloc_error(); + for (i1 = 0; i1 < count_elements; i1++) + { + m_s[i1].name = NULL; + m_s[i1].tot1 = 0; + m_s[i1].tot2 = 0; + } + count_m_s = 0; + fill_m_s(J_ij_il, k_il); + + /* do the mass transfer... */ + if (icell > 0 || stagnant) + { + std::vector comps = ex_ptr1->Vectorize(); + size_t k; + //for (k = 0; k < ex_ptr1->count_comps; k++) + for (k = 0; k < comps.size(); k++) + { + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + i_max = 0; + for (; it != nd.end(); it++) + { + if (strcmp("X", it->first.c_str()) == 0) + i_max = 1; + } + if (i_max) + break; + } + + if (k < comps.size()) + { + cxxExchComp *comp_ptr = comps[k]; + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + /* transfer O and H... */ + for (; it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + if (strcmp("H", elt_ptr->name) == 0) + { + if (coef < rc1 * tot1_h) + { + tot1_h -= coef; + //ex_ptr1->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert("H", 0); + } + else + { + comp_ptr->Get_totals().insert("H", coef - rc1 * tot1_h); + //ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_h; + tot1_h *= (1 - rc1); + } + } + else if (strcmp("O", elt_ptr->name) == 0) + { + if (coef < rc1 * tot1_o) + { + tot1_o -= coef; + //ex_ptr1->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert("O", 0); + } + else + { + comp_ptr->Get_totals().insert("O", coef - rc1 * tot1_o); + //ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_o; + tot1_o *= (1 - rc1); + } + } + } + /* transfer other elements... */ + j_max = 0; /* if j_max turns true, reallocate the exchange structure */ + for (j = 0; j < count_m_s; j++) + { + // Make sure list includes each element + comps[k]->Get_totals().add(m_s[j].name, 0); + + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + for (; it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + if (strcmp(m_s[j].name, elt_ptr->name) != 0) + continue; + + /* rc1 part goes to exchange species... */ + if (coef < rc1 * m_s[j].tot1) + { + m_s[j].tot1 -= coef; + //ex_ptr1->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert(m_s[j].name, 0); + } + else + { + comp_ptr->Get_totals().insert(m_s[j].name, coef - rc1 * m_s[j].tot1); + //ex_ptr1->comps[k].totals[i].coef -= rc1 * m_s[j].tot1; + m_s[j].tot1 *= (1 - rc1); + } + } + } + } + } + if (icell < count_cells || stagnant) + { + std::vector comps = ex_ptr2->Vectorize(); + size_t k; + //for (k = 0; k < ex_ptr1->count_comps; k++) + for (k = 0; k < comps.size(); k++) + { + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + i_max = 0; + for (; it != nd.end(); it++) + { + if (strcmp("X", it->first.c_str()) == 0) + i_max = 1; + } + if (i_max) + break; + } + if (k < comps.size()) + { + cxxExchComp *comp_ptr = comps[k]; + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + /* transfer O and H... */ + for (; it != nd.end(); it++) + //for (i = 0;; i++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + + if (strcmp("H", elt_ptr->name) == 0) + { + if (coef < -rc2 * tot2_h) + { + tot2_h += coef; + //ex_ptr2->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert("H", 0); + } + else + { + comp_ptr->Get_totals().insert("H", coef + rc2 * tot2_h); + //ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_h; + tot2_h *= (1 - rc2); + } + } + else if (strcmp("O", elt_ptr->name) == 0) + { + if (coef < -rc2 * tot2_o) + { + tot2_o += coef; + //ex_ptr2->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert("O", 0); + } + else + { + comp_ptr->Get_totals().insert("O", coef + rc2 * tot2_o); + //ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_o; + tot2_o *= (1 - rc2); + } + } + } + /* transfer other elements... */ + //j_max = 0; /* if j_max turns true, reallocate the exchange structure */ + for (j = 0; j < count_m_s; j++) + { + // Make sure list includes each element + comps[k]->Get_totals().add(m_s[j].name, 0); + + cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble::iterator it = nd.begin(); + for (; it != nd.end(); it++) + { + struct element *elt_ptr = element_store(it->first.c_str()); + LDBLE coef = it->second; + if (strcmp(m_s[j].name, elt_ptr->name) != 0) + continue; + + /* rc2 part goes to exchange species... */ + if (coef < -rc2 * m_s[j].tot2) + { + m_s[j].tot2 += coef; + //ex_ptr2->comps[k].totals[i].coef = 0; + comp_ptr->Get_totals().insert(m_s[j].name, 0); + } + else + { + comp_ptr->Get_totals().insert(m_s[j].name, coef + rc2 * m_s[j].tot2); + //ex_ptr2->comps[k].totals[i].coef += rc2 * m_s[j].tot2; + m_s[j].tot2 *= (1 - rc2); + } + } + } + } + } + } + /* appt 3 July 07, improved convergence without transporting charge imbalance */ + J_ij_sum = 0; + V_M = (struct V_M *) free_check_null(V_M); + if (il_calcs) + V_M_il = (struct V_M *) free_check_null(V_M_il); + return (il_calcs); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) +/* ---------------------------------------------------------------------- */ +{ + /* mole transfer of the individual master_species: + * Eqn 1: + * J_ij = DDt * (A_ij / lav) * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * regular column, stagnant FALSE: + * D_i = temperature-corrected Dw + * A_ij = A_icell * A_jcell + * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / + * (length_icell / 2) + * lav = A_icell + A_jcell + * grad(c) is concentration difference in icell and jcell, + for activity corrections see Appelo & Wersin, 2007. + * stagnant TRUE: + * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por + * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; + * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. + * Interlayer diffusion (IL) takes the gradient in the equivalent concentrations on X-. + surface area A for IL: + stagnant: mixf_il is mixf * por_il / por. + por_il = interlayer porosity, from -interlayer_D true 'por_il'. + por = total porosity, from -multi_D true 'multi_Dpor'. + **nov. 12, 2011**: + mixf is corrected, * (1 - por_il / por). + new_pf = (por - por_il)^(-multi_Dn). + in regular column, A is calc'd from (free + DL porewater) and cell-length. + for IL: A * por_il / (por - por_il). + + por_il is entered as a single value. It is limited to 0.999 * por. + por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) + + IL-water = (free + DL porewater) * por_il / (por - por_il). + */ + int i, i_max, j, j_max, k, k_il, l, only_counter, il_calcs; + int i1; + LDBLE lav, A1, A2, A_ij, A_ij_il, ddlm, aq1, aq2, mixf_il; + LDBLE dl_s, dl_aq1, dl_aq2, c_dl, visc1, visc2, dum, dum2, tort1, tort2; + LDBLE por_il1, por_il2, por_il12; + LDBLE c, Dz2c, Dz2c_dl, Dz2c_il, aq_il1, aq_il2; + LDBLE cec1, cec2, cec12, rc1, rc2; + struct V_M + { + LDBLE grad, D, z, Dz, Dzc, Dzc_dl, g_dl; + int o_c; + } *V_M, *V_M_il; + struct surface *s_ptr1, *s_ptr2; + struct surface_charge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; + struct exchange *ex_ptr1, *ex_ptr2; + char token[MAX_LENGTH], token1[MAX_LENGTH]; + + V_M = V_M_il = NULL; + /* check for immediate return and interlayer diffusion calcs... */ + if (interlayer_Dflag) + { + il_calcs = 1; + if (icell == 0 && cell_data[0].por_il < interlayer_Dpor_lim) + il_calcs = 0; + else if (icell == count_cells && + cell_data[count_cells - 1].por_il < interlayer_Dpor_lim) + il_calcs = 0; + else if (icell > 0 + && (cell_data[icell - 1].por_il < interlayer_Dpor_lim + || cell_data[jcell - 1].por_il < interlayer_Dpor_lim)) + il_calcs = 0; + } + else + il_calcs = 0; + + if (stagnant) + { + if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim + || cell_data[jcell - 1].por < multi_Dpor_lim)) + return (OK); + } + else + { /* regular column... */ + if (icell == 0) + { + if (!il_calcs && cell_data[0].por < multi_Dpor_lim) + return (OK); + } + else if (icell == count_cells) + { + if (!il_calcs && cell_data[count_cells - 1].por < multi_Dpor_lim) + return (OK); + } + else + { + if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim + || cell_data[jcell - 1].por < multi_Dpor_lim)) + return (OK); + } + } + + /* do the calcs */ + aq1 = solution_bsearch(icell, &i, TRUE)->mass_water; + aq2 = solution_bsearch(jcell, &i, TRUE)->mass_water; + /* + * check if DL calculations must be made, find amounts of water... + */ + s_charge_ptr1 = s_charge_ptr2 = NULL; + s_ptr1 = s_ptr2 = NULL; + dl_s = dl_aq1 = dl_aq2 = 0.0; + visc1 = visc2 = 1.0; + only_counter = FALSE; + + s_ptr1 = surface_bsearch(icell, &i); + if (s_ptr1 != NULL) + { + if (s_ptr1->dl_type != NO_DL) + { + if (s_ptr1->only_counter_ions) + only_counter = TRUE; + /* find the one (and only one...) immobile surface comp with DL... */ + for (i = 0; i < s_ptr1->count_comps; i++) + { + if (s_ptr1->comps[i].Dw == 0) + { + s_charge_ptr1 = &s_ptr1->charge[s_ptr1->comps[i].charge]; + dl_aq1 = s_charge_ptr1->mass_water; + visc1 = s_ptr1->DDL_viscosity; + /* check for more comps with Dw = 0 */ + for (j = i + 1; j < s_ptr1->count_comps; j++) + { + if (s_ptr1->comps[j].Dw == 0 + && s_ptr1->comps[j].charge != + s_ptr1->comps[i].charge) + { + if (!warn_fixed_Surf) + { + k = (int) strcspn(s_ptr1->comps[i].formula, "_"); + strncpy(token1, s_ptr1->comps[i].formula, k); + token1[k] = '\0'; + sprintf(token, + "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", + token1); + warning_msg(token); + warn_fixed_Surf = 1; + } + break; + } + } + break; + } + } + } + } + s_ptr2 = surface_bsearch(jcell, &i); + if (s_ptr2 != NULL) + { + if (s_ptr2->dl_type != NO_DL) + { + if (s_ptr2->only_counter_ions) + only_counter = TRUE; + for (i = 0; i < s_ptr2->count_comps; i++) + { + if (s_ptr2->comps[i].Dw == 0) + { + s_charge_ptr2 = &s_ptr2->charge[s_ptr2->comps[i].charge]; + dl_aq2 = s_charge_ptr2->mass_water; + visc2 = s_ptr2->DDL_viscosity; + /* check for more comps with Dw = 0 */ + for (j = i + 1; j < s_ptr2->count_comps; j++) + { + if (s_ptr2->comps[j].Dw == 0 + && s_ptr2->comps[j].charge != + s_ptr2->comps[i].charge) + { + if (!warn_fixed_Surf) + { + k = (int) strcspn(s_ptr2->comps[i].formula, "_"); + strncpy(token1, s_ptr2->comps[i].formula, k); + token1[k] = '\0'; + sprintf(token, + "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", + token1); + warning_msg(token); + warn_fixed_Surf = 1; + } + break; + } + } + break; + } + } + } + } + if (!stagnant) + { + if (icell == 0) + visc1 = visc2; + else if (icell == count_cells) + visc2 = visc1; + } + /* in each cell: DL surface = mass_water_DL / (cell_length) + free pore surface = mass_water_free / (cell_length) + determine DL surface as a fraction of the total pore surface... */ + if (dl_aq1 > 0) + dl_s = dl_aq1 / (dl_aq1 + aq1); + if (dl_aq2 > 0) + { + dum = dl_aq2 / (dl_aq2 + aq2); + if (dl_aq1 > 0) + /* average the 2... */ + dl_s = (dl_s + dum) / 2; + else + /* there is one DL surface... */ + dl_s = dum; + } + + por_il1 = por_il2 = por_il12 = 0.0; + cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; + if (il_calcs) + { + /* find interlayer porosity por_il, + make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). + Find amounts of IL water and cec. + Must do this separately, since por and por_il are in cell_data structure. */ + if (icell == 0) + { + por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * + cell_data[0].por_il; + por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * + cell_data[0].por_il; + if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) + /* take the average... */ + por_il12 = (por_il1 + por_il2) / 2; + else + /* at column ends, take the clay... */ + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[0].por) + por_il12 = 0.999 * cell_data[0].por; + + if (por_il2 > 0.999 * cell_data[0].por) + por_il2 = 0.999 * cell_data[0].por; + aq_il2 = (aq2 + dl_aq2) * por_il2 / + (cell_data[0].por - por_il2); + /* Assume interlayer water is proportional with CEC... */ + aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; + } + else if (icell == count_cells) + { + por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * + cell_data[count_cells - 1].por_il; + por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * + cell_data[count_cells - 1].por_il; + if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) + por_il12 = (por_il1 + por_il2) / 2; + else + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[count_cells - 1].por) + por_il12 = 0.999 * cell_data[count_cells - 1].por; + + if (por_il1 > 0.999 * cell_data[count_cells - 1].por) + por_il1 = 0.999 * cell_data[count_cells - 1].por; + aq_il1 = (aq1 + dl_aq1) * por_il1 / + (cell_data[count_cells - 1].por - por_il1); + aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / + sol_D[count_cells].exch_total; + } + else + { + por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * + cell_data[icell - 1].por_il; + por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * + cell_data[jcell - 1].por_il; + + if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) + por_il12 = (por_il1 + por_il2) / 2; + else + por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); + if (por_il12 > 0.999 * cell_data[icell - 1].por || por_il12 > 0.999 * cell_data[jcell - 1].por) + por_il12 = (cell_data[icell - 1].por >= cell_data[jcell - 1].por ? + 0.999 * cell_data[jcell - 1].por : + 0.999 * cell_data[icell - 1].por); + aq_il1 = (aq1 + dl_aq1) * por_il1 / + (cell_data[icell - 1].por - por_il1); + aq_il2 = (aq2 + dl_aq2) * por_il2 / + (cell_data[jcell - 1].por - por_il2); +/* former code... */ + //aq_il1 = (aq1 + dl_aq1) * cell_data[icell - 1].por_il / + // cell_data[icell - 1].por; + //aq_il2 = (aq2 + dl_aq2) * cell_data[jcell - 1].por_il / + // cell_data[jcell - 1].por; +/* end */ + } + if (por_il12 == 0) + il_calcs = 0; + else + { + dum = sol_D[icell].exch_total; + dum2 = sol_D[jcell].exch_total; + rc1 = (dum2 > dum ? dum / dum2 : 1); + rc2 = (dum > dum2 ? dum2 / dum : 1); + if (sol_D[icell].exch_total > 3e-10) + cec1 = dum / aq_il1; + else + cec1 = 2e-10; + if (sol_D[jcell].exch_total > 3e-10) + cec2 = dum2 / aq_il2; + else + cec2 = 2e-10; + /* and the largest for calculating the mass transfer... */ + cec12 = (cec1 > cec2 ? cec1 : cec2); + } + } + + /* In stagnant calc's, find mixf_il for IL diffusion, correct mixf. + In regular column, find surface areas A and A_il */ + tort1 = tort2 = lav = 1.0; + A_ij = A_ij_il = mixf_il = 0.0; + if (stagnant) + { + mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); + dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? + cell_data[icell - 1].por : cell_data[jcell - 1].por); + if (il_calcs) + { + mixf_il = mixf * por_il12 / interlayer_tortf; + dum -= por_il12; + } + mixf *= (dum * pow(dum, multi_Dn)); +/* former code... */ + //mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); + //dum = (cell_data[icell - 1].por_il <= cell_data[jcell - 1].por_il ? + // cell_data[icell - 1].por_il : cell_data[jcell - 1].por_il); + //mixf_il = mixf * dum / interlayer_tortf; + //dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? + // cell_data[icell - 1].por : cell_data[jcell - 1].por); + //mixf *= dum * pow(dum, multi_Dn); +/* end */ + } + else + { /* regular column... */ + if (icell == 0) + { + tort1 = tort2 = pow(cell_data[0].por, -multi_Dn); + lav = cell_data[0].length; + A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); + if (il_calcs) + A_ij_il = + A_ij * por_il12 / ((cell_data[0].por - por_il12) * + interlayer_tortf); + A_ij /= tort1; + } + else if (icell == count_cells) + { + tort1 = tort2 = pow(cell_data[count_cells - 1].por, -multi_Dn); + lav = cell_data[count_cells - 1].length; + A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); + if (il_calcs) + A_ij_il = A_ij * por_il12 / + ((cell_data[count_cells - 1].por - por_il12) * interlayer_tortf); + A_ij /= tort2; + } + else + { + tort1 = pow(cell_data[icell - 1].por, -multi_Dn); + tort2 = pow(cell_data[jcell - 1].por, -multi_Dn); + A1 = (aq1 + dl_aq1) / (cell_data[icell - 1].length * + 0.5 * cell_data[icell - 1].length); + A2 = (aq2 + dl_aq2) / (cell_data[jcell - 1].length * + 0.5 * cell_data[jcell - 1].length); + if (il_calcs) + { + dum = A1 * por_il12 / + ((cell_data[icell - 1].por - por_il12) * interlayer_tortf); + dum2 = A2 * por_il12 / + ((cell_data[jcell - 1].por - por_il12) * interlayer_tortf); + A_ij_il = dum * dum2 / (dum + dum2); + } + A1 /= tort1; + A2 /= tort2; + A_ij = A1 * A2 / (A1 + A2); +/* former code... */ + //A1 = aq1 / (cell_data[icell - 1].length * + // 0.5 * cell_data[icell - 1].length); + //A2 = aq2 / (cell_data[jcell - 1].length * + // 0.5 * cell_data[jcell - 1].length); + //dum = A1 * cell_data[icell - 1].por_il / + // (cell_data[icell - 1].por * interlayer_tortf); + //dum2 = A2 * cell_data[jcell - 1].por_il / + // (cell_data[jcell - 1].por * interlayer_tortf); + //A_ij_il = dum * dum2 / (dum + dum2); + //A1 /= tort1; + //A2 /= tort2; + //A_ij = A1 * A2 / (A1 + A2); + + //A1 = dl_aq1 / (cell_data[icell - 1].length * + // 0.5 * cell_data[icell - 1].length); + //A2 = dl_aq2 / (cell_data[jcell - 1].length * + // 0.5 * cell_data[jcell - 1].length); + //dum = A1 * cell_data[icell - 1].por_il / + // (cell_data[icell - 1].por * interlayer_tortf); + //dum2 = A2 * cell_data[jcell - 1].por_il / + // (cell_data[jcell - 1].por * interlayer_tortf); + //if (dum + dum2 > 0) + //{ + // A_ij_il += dum * dum2 / (dum + dum2); + // A1 /= tort1; + // A2 /= tort2; + // A_ij += (A1 * A2 / (A1 + A2)); + //} +/* end */ + } + } + /* diffuse... */ + J_ij_count_spec = 0; + J_ij_sum = 0.0; + /* + * malloc sufficient space... + */ + k = sol_D[icell].count_spec + sol_D[jcell].count_spec; + + J_ij = (struct J_ij *) free_check_null(J_ij); + J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + if (J_ij == NULL) + malloc_error(); + + V_M = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + if (V_M == NULL) + malloc_error(); + + for (i = 0; i < k; i++) + { + J_ij[i].tot1 = 0.0; + V_M[i].grad = 0.0; + V_M[i].D = 0.0; + V_M[i].Dz = 0.0; + V_M[i].Dzc = 0.0; + V_M[i].Dzc_dl = 0.0; + V_M[i].g_dl = 1.0; + V_M[i].o_c = 1; + } + Dz2c = Dz2c_dl = Dz2c_il = 0.0; + + if (il_calcs) + { + /* also for interlayer cations */ + k = sol_D[icell].count_exch_spec + sol_D[jcell].count_exch_spec; + + J_ij_il = (struct J_ij *) free_check_null(J_ij_il); + J_ij_il = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + if (J_ij_il == NULL) + malloc_error(); + + V_M_il = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + if (V_M_il == NULL) + malloc_error(); + for (i = 0; i < k; i++) + { + J_ij_il[i].tot1 = 0.0; + V_M_il[i].grad = 0.0; + V_M_il[i].D = 0.0; + V_M_il[i].Dz = 0.0; + V_M_il[i].Dzc = 0.0; + V_M_il[i].Dzc_dl = 0.0; + V_M_il[i].g_dl = 1.0; + V_M_il[i].o_c = 1; + } + } + /* + * coefficients in Eqn (1)... + */ + i = j = k = k_il = 0; + i_max = sol_D[icell].count_spec; + j_max = sol_D[jcell].count_spec; + + while (i < i_max || j < j_max) + { + if (j == j_max + || (i < i_max + && strcmp(sol_D[icell].spec[i].name, + sol_D[jcell].spec[j].name) < 0)) + { + /* species 'name' is only in icell */ + if (il_calcs && sol_D[icell].spec[i].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; + V_M_il[k_il].z = sol_D[icell].spec[i].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * sol_D[icell].spec[i].c * cec12 / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + V_M[k].D = sol_D[icell].spec[i].Dwt; + V_M[k].z = sol_D[icell].spec[i].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = V_M[k].Dz * sol_D[icell].spec[i].c / 2; + if (dl_s > 0) + { + s_charge_ptr = + (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; + for (l = 0; l < s_charge_ptr->count_g; l++) + { + if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) + == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) + || (s_charge_ptr->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2; + } + } + else + { + if (dl_aq1 > 0) + { + V_M[k].g_dl = + (1 + + s_charge_ptr->g[l].g * aq1 / + dl_aq1) * + sol_D[icell].spec[i].erm_ddl; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2 * V_M[k].g_dl; + } + else + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[icell].spec[i].c / + 2; + } + break; + } + } + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + k++; + } + if (i < i_max) + i++; + } + else if (i == i_max + || (j < j_max + && strcmp(sol_D[icell].spec[i].name, + sol_D[jcell].spec[j].name) > 0)) + { + /* species 'name' is only in jcell */ + if (il_calcs && sol_D[jcell].spec[j].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); + V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; + V_M_il[k_il].z = sol_D[jcell].spec[j].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * sol_D[jcell].spec[j].c * cec12 / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = sol_D[jcell].spec[j].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); + V_M[k].D = sol_D[jcell].spec[j].Dwt; + V_M[k].z = sol_D[jcell].spec[j].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = V_M[k].Dz * sol_D[jcell].spec[j].c / 2; + if (dl_s > 0) + { + s_charge_ptr = + (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; + for (l = 0; l < s_charge_ptr->count_g; l++) + { + if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) + == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) + || (s_charge_ptr->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2; + } + } + else + { + if (dl_aq2 > 0) + { + V_M[k].g_dl = + (1 + + s_charge_ptr->g[l].g * aq2 / + dl_aq2) * + sol_D[jcell].spec[j].erm_ddl; + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2 * V_M[k].g_dl; + } + else + V_M[k].Dzc_dl = + V_M[k].Dz * sol_D[jcell].spec[j].c / + 2; + } + break; + } + } + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + k++; + } + if (j < j_max) + j++; + } + else if (strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) + == 0) + { + /* species 'name' is in both cells */ + if (il_calcs && sol_D[icell].spec[i].type == EX) + { + J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + if (sol_D[icell].spec[i].Dwt == 0 + || sol_D[jcell].spec[j].Dwt == 0) + V_M_il[k_il].D = 0.0; + else + V_M_il[k_il].D = + (sol_D[icell].spec[i].Dwt + + sol_D[jcell].spec[j].Dwt) / 2; + + V_M_il[k_il].z = sol_D[icell].spec[i].z; + V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; + V_M_il[k_il].Dzc = + V_M_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + + sol_D[jcell].spec[j].c * cec2) / (2 * + V_M_il + [k_il]. + z); + Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; + V_M_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + k_il++; + } + else + { + J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + if (sol_D[icell].spec[i].Dwt == 0 + || sol_D[jcell].spec[j].Dwt == 0) + V_M[k].D = 0.0; + else + V_M[k].D = + (sol_D[icell].spec[i].Dwt + + sol_D[jcell].spec[j].Dwt) / 2; + + V_M[k].z = sol_D[icell].spec[i].z; + V_M[k].Dz = V_M[k].D * V_M[k].z; + V_M[k].Dzc = + V_M[k].Dz * (sol_D[icell].spec[i].c + + sol_D[jcell].spec[j].c) / 2; + /* Dzc[k] = Dz[k] * (sol_D[icell].spec[i].c > sol_D[jcell].spec[j].c ? sol_D[icell].spec[i].c : sol_D[jcell].spec[j].c); + */ + if (dl_s > 0) + { + c_dl = 0.0; + if (dl_aq1 > 0) + { + for (l = 0; l < s_charge_ptr1->count_g; l++) + { + if (equal + (s_charge_ptr1->g[l].charge, V_M[k].z, + G_TOL) == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr1->la_psi < 0 + && V_M[k].z < 0) + || (s_charge_ptr1->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + V_M[k].g_dl = 1.0; + c_dl = sol_D[icell].spec[i].c / 2; + } + } + else + { + V_M[k].g_dl = + (1 + + s_charge_ptr1->g[l].g * aq1 / + dl_aq1) * + sol_D[icell].spec[i].erm_ddl; + c_dl = + sol_D[icell].spec[i].c / 2 * + V_M[k].g_dl; + } + break; + } + } + } + else + c_dl = sol_D[icell].spec[i].c / 2; + + if (dl_aq2 > 0) + { + for (l = 0; l < s_charge_ptr2->count_g; l++) + { + if (equal + (s_charge_ptr2->g[l].charge, V_M[k].z, + G_TOL) == TRUE) + { + if (only_counter) + { + if ((s_charge_ptr2->la_psi < 0 + && V_M[k].z < 0) + || (s_charge_ptr2->la_psi > 0 + && V_M[k].z > 0)) + { + V_M[k].o_c = 0; + V_M[k].Dzc_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + { + dum = 1.0; + c_dl += + sol_D[jcell].spec[j].c / 2 * dum; + V_M[k].g_dl = + (V_M[k].g_dl + dum) / 2; + } + } + else + { + dum = + (1 + + s_charge_ptr2->g[l].g * aq2 / + dl_aq2) * + sol_D[jcell].spec[j].erm_ddl; + c_dl += sol_D[jcell].spec[j].c / 2 * dum; + V_M[k].g_dl = (V_M[k].g_dl + dum) / 2; + } + break; + } + } + } + else if (V_M[k].o_c == 1) + c_dl += sol_D[jcell].spec[j].c / 2; + + V_M[k].Dzc_dl = V_M[k].Dz * c_dl; + Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + } + Dz2c += V_M[k].Dzc * V_M[k].z; + V_M[k].grad = + (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; + if (fabs(ddlm) > 1e-10) + V_M[k].grad *= + (1 + + (sol_D[jcell].spec[j].lg - + sol_D[icell].spec[i].lg) / ddlm); + k++; + } + if (i < i_max) + i++; + if (j < j_max) + j++; + } + } + /* + * fill in J_ij... + */ + if (Dz2c == 0) + k = 0; + J_ij_count_spec = i_max = k; + J_ij_sum = 0; + c = c_dl = 0.0; + for (i = 0; i < i_max; i++) + { + c += V_M[i].Dz * V_M[i].grad; + c_dl += V_M[i].o_c * V_M[i].Dz * V_M[i].g_dl * V_M[i].grad; + } + for (i = 0; i < i_max; i++) + { + J_ij[i].tot1 = -V_M[i].D * V_M[i].grad + c * V_M[i].Dzc / Dz2c; + J_ij[i].tot1 *= (1 - dl_s); + if (Dz2c_dl > 0) + { + dum = + (-V_M[i].D * V_M[i].g_dl * V_M[i].grad + + c_dl * V_M[i].Dzc_dl / Dz2c_dl) * (2 / (visc1 + visc2)); + if ((J_ij[i].tot1 <= 0 && dum <= 0) + || (J_ij[i].tot1 > 0 && dum > 0)) + { + J_ij[i].tot1 += V_M[i].o_c * dum * dl_s; + } + } + /* + * multiply with timestep... + * for stagnant, DDt = 1, the timestep is in mixf. + * NOTE (for stagnant). The timestep calculated in init_mix for MCD (by PHREEQC) must be equal + * or smaller than the timestep taken (by the user) for calculating mixf in MIX. + * Make this timestep small enough, consider the largest Dw in phreeqd.dat (usually H+). + * Dw used for calculating mixf must be given as default_Dw in the input file. + */ + if (stagnant) + J_ij[i].tot1 *= mixf; + else + J_ij[i].tot1 *= A_ij * DDt; + J_ij_sum += V_M[i].z * J_ij[i].tot1; + J_ij[i].tot2 = J_ij[i].tot1; + } + /* + * calculate interlayer mass transfer... + */ + if (il_calcs && Dz2c_il != 0 && k_il > 0) + { + ex_ptr1 = exchange_bsearch(icell, &i); + ex_ptr2 = exchange_bsearch(jcell, &i); + c = 0.0; + i_max = k_il; + for (i = 0; i < i_max; i++) + c += V_M_il[i].Dz * V_M_il[i].grad; + for (i = 0; i < i_max; i++) + { + J_ij_il[i].tot1 = -V_M_il[i].D * V_M_il[i].grad + + c * V_M_il[i].Dzc / Dz2c_il; + if (stagnant) + J_ij_il[i].tot1 *= mixf_il; + else + J_ij_il[i].tot1 *= A_ij_il * DDt; + J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; + J_ij_il[i].tot2 = J_ij_il[i].tot1; + } + + /* express the transfer in elemental moles... */ + tot1_h = tot1_o = tot2_h = tot2_o = 0.0; + m_s = (struct M_S *) free_check_null(m_s); + m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * + sizeof(struct M_S)); + if (m_s == NULL) + malloc_error(); + for (i1 = 0; i1 < count_elements; i1++) + { + m_s[i1].name = NULL; + m_s[i1].tot1 = 0; + m_s[i1].tot2 = 0; + } + count_m_s = 0; + fill_m_s(J_ij_il, k_il); + + /* do the mass transfer... */ + if (icell > 0 || stagnant) + { + for (k = 0; k < ex_ptr1->count_comps; k++) + { + i_max = 0; + for (i = 0;; i++) + { + if (ex_ptr1->comps[k].totals[i].elt == NULL) + break; + if (strcmp("X", ex_ptr1->comps[k].totals[i].elt->name) == + 0) + i_max = 1; + } + if (i_max) + break; + } + if (k < ex_ptr1->count_comps) + { + /* transfer O and H... */ + for (i = 0;; i++) + { + if (ex_ptr1->comps[k].totals[i].elt == NULL) + break; + if (strcmp("H", ex_ptr1->comps[k].totals[i].elt->name) == + 0) + { + if (ex_ptr1->comps[k].totals[i].coef < rc1 * tot1_h) + { + tot1_h -= ex_ptr1->comps[k].totals[i].coef; + ex_ptr1->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_h; + tot1_h *= (1 - rc1); + } + } + else if (strcmp + ("O", + ex_ptr1->comps[k].totals[i].elt->name) == 0) + { + if (ex_ptr1->comps[k].totals[i].coef < rc1 * tot1_o) + { + tot1_o -= ex_ptr1->comps[k].totals[i].coef; + ex_ptr1->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_o; + tot1_o *= (1 - rc1); + } + } + } + /* transfer other elements... */ + j_max = 0; /* if j_max turns true, reallocate the exchange structure */ + for (j = 0; j < count_m_s; j++) + { + i_max = 0; + for (i = 0;; i++) + { + if (ex_ptr1->comps[k].totals[i].elt == NULL) + { + i_max = i; + break; + } + if (strcmp + (m_s[j].name, + ex_ptr1->comps[k].totals[i].elt->name) == 0) + break; + } + if (i_max) + { + /* new exchange element must be added... */ + ex_ptr1->comps[k].totals = + (struct elt_list *) PHRQ_realloc(ex_ptr1-> + comps[k].totals, + (size_t) (i + + 2) * + sizeof(struct + elt_list)); + ex_ptr1->comps[k].formula_totals = + (struct elt_list *) PHRQ_realloc(ex_ptr1-> + comps[k]. + formula_totals, + (size_t) (i + + 2) * + sizeof(struct + elt_list)); + /* fill in new element, next = NULL */ + ex_ptr1->comps[k].totals[i].elt = + element_store(m_s[j].name); + ex_ptr1->comps[k].totals[i + 1].elt = NULL; + + j_max = i_max; + } + /* rc1 part goes to exchange species... */ + if (ex_ptr1->comps[k].totals[i].coef < rc1 * m_s[j].tot1) + { + m_s[j].tot1 -= ex_ptr1->comps[k].totals[i].coef; + ex_ptr1->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr1->comps[k].totals[i].coef -= rc1 * m_s[j].tot1; + m_s[j].tot1 *= (1 - rc1); + } + } + if (j_max) + { + qsort(ex_ptr1->comps[k].totals, (size_t) j_max + 1, + (size_t) sizeof(struct elt_list), elt_list_compare); + } + } + } + if (icell < count_cells || stagnant) + { + for (k = 0; k < ex_ptr2->count_comps; k++) + { + i_max = 0; + for (i = 0;; i++) + { + if (ex_ptr2->comps[k].totals[i].elt == NULL) + break; + if (strcmp("X", ex_ptr2->comps[k].totals[i].elt->name) == + 0) + i_max = 1; + } + if (i_max) + break; + } + if (k < ex_ptr2->count_comps) + { + /* transfer O and H... */ + for (i = 0;; i++) + { + if (ex_ptr2->comps[k].totals[i].elt == NULL) + break; + if (strcmp("H", ex_ptr2->comps[k].totals[i].elt->name) == + 0) + { + if (ex_ptr2->comps[k].totals[i].coef < -rc2 * tot2_h) + { + tot2_h += ex_ptr2->comps[k].totals[i].coef; + ex_ptr2->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_h; + tot2_h *= (1 - rc2); + } + } + else if (strcmp + ("O", + ex_ptr2->comps[k].totals[i].elt->name) == 0) + { + if (ex_ptr2->comps[k].totals[i].coef < -rc2 * tot2_o) + { + tot2_o += ex_ptr2->comps[k].totals[i].coef; + ex_ptr2->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_o; + tot2_o *= (1 - rc2); + } + } + } + /* transfer other elements... */ + j_max = 0; /* if j_max turns true, reallocate the exchange structure */ + for (j = 0; j < count_m_s; j++) + { + i_max = 0; + for (i = 0;; i++) + { + if (ex_ptr2->comps[k].totals[i].elt == NULL) + { + i_max = i; + break; + } + if (strcmp + (m_s[j].name, + ex_ptr2->comps[k].totals[i].elt->name) == 0) + break; + } + if (i_max) + { + /* new exchange element must be added... */ + ex_ptr2->comps[k].totals = + (struct elt_list *) PHRQ_realloc(ex_ptr2-> + comps[k].totals, + (size_t) (i + + 2) * + sizeof(struct + elt_list)); + ex_ptr2->comps[k].formula_totals = + (struct elt_list *) PHRQ_realloc(ex_ptr2-> + comps[k]. + formula_totals, + (size_t) (i + + 2) * + sizeof(struct + elt_list)); + /* fill in new element, next = NULL */ + ex_ptr2->comps[k].totals[i].elt = + element_store(m_s[j].name); + ex_ptr2->comps[k].totals[i].coef = 0.0; + ex_ptr2->comps[k].totals[i + 1].elt = NULL; + + j_max = i_max; + } + /* rc2 part goes to exchange species... */ + if (ex_ptr2->comps[k].totals[i].coef < -rc2 * m_s[j].tot2) + { + m_s[j].tot2 += ex_ptr2->comps[k].totals[i].coef; + ex_ptr2->comps[k].totals[i].coef = 0; + } + else + { + ex_ptr2->comps[k].totals[i].coef += rc2 * m_s[j].tot2; + m_s[j].tot2 *= (1 - rc2); + } + } + if (j_max) + { + qsort(ex_ptr2->comps[k].totals, (size_t) j_max + 1, + (size_t) sizeof(struct elt_list), elt_list_compare); + } + } + } + } + /* appt 3 July 07, improved convergence without transporting charge imbalance */ + J_ij_sum = 0; + V_M = (struct V_M *) free_check_null(V_M); + if (il_calcs) + V_M_il = (struct V_M *) free_check_null(V_M_il); + return (il_calcs); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +disp_surf(LDBLE DDt) +/* ---------------------------------------------------------------------- */ +/* + * Disperse/diffuse surfaces: + * surface[n1] = SS(mixf * surface[n2]) + (1 - SS(mixf) * surface[i1]) + * where SS is Sum of, f2 is a mixing factor. + * Implementation: + * Mobile surface comps and charges are mixed face by face and 1 by 1 in surface[n1]: + Step (from cell 1 to count_cells + 1): + * 1. Surface n1 is made a copy of cell[i1]'s surface, if it exists, or else + * b. a copy of the first encountered mobile surface[n2] from cell i2 = i1 - 1. + * 2 a. Column surfaces are mixed by dispersion/diffusion + * b. Column surfaces are mixed by MCD (if multi_Dflag is true) + * 3. Surfaces n1 and n2 are stored in a temporary surface, with n_user = i1 or i2. + * 4. When done for all cells, new surfaces are copied into the cells. + * NOTE... The surfaces' diffuse_layer, edl and phases/kinetics relations must be identical, + * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. + */ +{ + int i, i1, i2, j, k, k1, n, n1, n2, temp_count_surface; + int charge_done, surf1, surf2; + LDBLE f1, f2, mixf, mixf_store, mcd_mixf; + LDBLE lav, A_ij, por, Dp1, Dp2; + //struct mix *mix_ptr; + cxxMix * mix_ptr; + struct surface *surface_ptr1, *surface_ptr2; + LDBLE viscos_f; +/* + * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + */ + viscos_f = viscosity(); + viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); + + n1 = count_surface; + n2 = n1 + 1; + temp_count_surface = count_surface + 2; + space((void **) ((void *) &surface), temp_count_surface, &max_surface, + sizeof(struct surface)); + surface[n1].count_comps = surface[n1 + 1].count_comps = 0; + + for (i1 = 1; i1 <= count_cells + 1; i1++) + { + + if (i1 <= count_cells && cell_data[i1 - 1].por < multi_Dpor_lim) + continue; + + if (i1 == 1 && bcon_first != 1) + continue; + if (i1 == count_cells + 1 && bcon_last != 1) + continue; + + i2 = i1 - 1; + if (i2 > 0 && cell_data[i2 - 1].por < multi_Dpor_lim) + continue; +/* + * step 1. define surface n1 from cell i1, if it exists... + */ + surface[n1].n_user = surface[n1 + 1].n_user = -99; + if ((surface_ptr1 = surface_bsearch(i1, &n)) != NULL) + surface_copy(surface_ptr1, &surface[n1], i1); + + surface_ptr2 = surface_bsearch(i2, &n); + + surf1 = surf2 = 0; + if (surface_ptr2 != NULL) + { + if (surface_ptr2->transport == TRUE) + surf2 = 1; + } + if (surface_ptr1 != NULL) + { + if (surface_ptr1->transport == TRUE) + surf1 = 1; + } + + mixf = mixf_store = 0; + if (surf1 || surf2) + { +/* + * step 2a. Dispersive mixing of mobile surfaces from column cells i2 < i1... + */ + if (i1 <= count_cells) + //mix_ptr = &mix[count_mix - count_cells + i1 - 1]; + mix_ptr = Utilities::Rxn_find(Dispersion_mix_map, i1); + else + //mix_ptr = &mix[count_mix - 1]; + mix_ptr = Utilities::Rxn_find(Dispersion_mix_map, count_cells); + + //std::map::const_iterator cit; + //for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) + std::vector num; + std::vector frac; + mix_ptr->Vectorize(num, frac); + for(size_t i3 = 0; i3 < num.size(); i3++) + //for (j = 0; j < mix_ptr->count_comps; j++) + { + if (i1 <= count_cells) + { + //if (mix_ptr->comps[j].n_solution == i2) + //if (cit->first == i2) + if (num[i3] == i2) + { + //mixf = mixf_store = mix_ptr->comps[j].fraction; + //mixf = mixf_store = cit->second; + mixf = mixf_store = frac[i3]; + break; + } + } + //else if (mix_ptr->comps[j].n_solution == i1) + //else if (cit->first == i1) + else if (num[i3] == i1) + { + //mixf = mixf_store = mix_ptr->comps[j].fraction; + //mixf = mixf_store = cit->second; + mixf = mixf_store = frac[i3]; + break; + } + } +#ifdef SKIP + for (j = 0; j < mix_ptr->count_comps; j++) + { + if (i1 <= count_cells) + { + if (mix_ptr->comps[j].n_solution == i2) + { + mixf = mixf_store = mix_ptr->comps[j].fraction; + break; + } + } + else if (mix_ptr->comps[j].n_solution == i1) + { + mixf = mixf_store = mix_ptr->comps[j].fraction; + break; + } + } +#endif + /* step 1b. If cell i1 has no surface, get the mobile comps from surface i2... */ + if (surface[n1].n_user == -99) + { + mobile_surface_copy(surface_ptr2, &surface[n1], i1, FALSE); + /* limit charges to 1... */ + if (surface[n1].count_charge > 1) + { + if (sum_surface_comp + (&surface[n1], 0, &surface[n1], 0, 1, &surface[n1], + surface[n1].comps[0].Dw) == ERROR) + return (ERROR); + } + f1 = 0; + } + else + f1 = 1; + /* find the (possibly modified) surface in the previous cell i2... */ + f2 = 1; + if (i2 > 0 || bcon_first == 1) + { + for (k = count_surface + 2; k < temp_count_surface; k++) + { + if (surface[k].n_user == i2) + { + n2 = k; + break; + } + } + /* if not found... */ + if (k == temp_count_surface) + { + n2 = n1 + 1; + /* copy it from surface_ptr2... */ + if (surface_ptr2 != NULL) + surface_copy(surface_ptr2, &surface[n2], i2); + else + { + /* or make it a mobile copy of the surface in cell i1... */ + mobile_surface_copy(surface_ptr1, &surface[n2], i2, + FALSE); + /* limit charges to 1... */ + if (surface[n2].count_charge > 1) + { + if (sum_surface_comp + (&surface[n2], 0, &surface[n2], 0, 1, + &surface[n2], + surface[n2].comps[0].Dw) == ERROR) + return (ERROR); + } + f2 = 0; + } + } + } + +/* + * For MCD, step 2b. Find physical dimensions and porosity of the cells... + */ + if (i1 == 1) + { + por = cell_data[0].por; + lav = cell_data[0].length / 2; + A_ij = + solution_bsearch(1, &n, + TRUE)->mass_water / cell_data[0].length; + } + else if (i1 == count_cells + 1) + { + por = cell_data[count_cells - 1].por; + lav = cell_data[count_cells - 1].length / 2; + A_ij = + solution_bsearch(count_cells, &n, + TRUE)->mass_water / + cell_data[count_cells - 1].length; + } + else + { + por = cell_data[i2 - 1].por; + lav = + (cell_data[i1 - 1].length + cell_data[i2 - 1].length) / 2; + A_ij = + solution_bsearch(i1, &n, + TRUE)->mass_water / (cell_data[i1 - + 1]. + length * + cell_data[i1 - + 1].por); + A_ij += + solution_bsearch(i2, &n, + TRUE)->mass_water / (cell_data[i2 - + 1]. + length * + cell_data[i2 - + 1].por); + A_ij /= 2; + A_ij *= + (cell_data[i1 - 1].por < + cell_data[i2 - 1].por ? cell_data[i1 - + 1].por : cell_data[i2 - + 1]. + por); + } + + /* mix in comps with the same charge structure... */ + if (surf2) + { + for (k = 0; k < surface_ptr2->count_comps; k++) + { + if (surface_ptr2->comps[k].Dw == 0) + continue; + charge_done = FALSE; + for (k1 = 0; k1 < k; k1++) + { + if (surface_ptr2->comps[k1].charge == + surface_ptr2->comps[k].charge) + { + charge_done = TRUE; + break; + } + } + if (charge_done) + continue; + + /* Define the MCD diffusion coefficient... */ + mcd_mixf = 0; + if (multi_Dflag) + { + Dp2 = surface_ptr2->comps[k].Dw * pow(por, multi_Dn); + Dp1 = 0; + if (surface_ptr1 != NULL && surface_ptr1->transport) + { + for (k1 = 0; k1 < surface_ptr1->count_comps; k1++) + { + if (elt_list_compare + (surface_ptr1->comps[k1].totals, + surface_ptr2->comps[k].totals) != 0) + continue; + Dp1 = + surface_ptr1->comps[k].Dw * + pow(cell_data[i1 - 1].por, multi_Dn); + break; + } + } + if (Dp1 > 0) + Dp2 = (Dp2 + Dp1) / 2; + + /* and the mixing factor... */ + mcd_mixf = Dp2 * viscos_f * A_ij * DDt / lav; + } + mixf = mixf_store + mcd_mixf; + + if (mixf < 1e-8) + mixf = 0; + if (mixf > 0.99999999) + mixf = 0.99999999; + if (i1 <= count_cells) + { + if (sum_surface_comp + (&surface[n1], f1, surface_ptr2, k, mixf, + &surface[n1], + surface_ptr2->comps[k].Dw) == ERROR) + return (ERROR); + f1 = 1; + } + if (i2 > 0) + { + if (sum_surface_comp + (&surface[n2], f2, surface_ptr2, k, -mixf, + &surface[n2], + surface_ptr2->comps[k].Dw) == ERROR) + return (ERROR); + f2 = 1; + } + surface[n1].n_user = i1; + } + } + if (surf1) + { + for (k = 0; k < surface_ptr1->count_comps; k++) + { + if (surface_ptr1->comps[k].Dw == 0) + continue; + charge_done = FALSE; + for (k1 = 0; k1 < k; k1++) + { + if (surface_ptr1->comps[k1].charge == + surface_ptr1->comps[k].charge) + { + charge_done = TRUE; + break; + } + } + if (charge_done) + continue; + + /* Define the MCD diffusion coefficient... */ + mcd_mixf = 0; + if (multi_Dflag) + { + if (i1 <= count_cells) + Dp1 = + surface_ptr1->comps[k].Dw * + pow(cell_data[i1 - 1].por, multi_Dn); + else + Dp1 = + surface_ptr1->comps[k].Dw * pow(por, + multi_Dn); + Dp2 = 0; + if (surface_ptr2 != NULL && surface_ptr2->transport) + { + for (k1 = 0; k1 < surface_ptr2->count_comps; k1++) + { + if (elt_list_compare + (surface_ptr2->comps[k1].totals, + surface_ptr1->comps[k].totals) != 0) + continue; + Dp2 = + surface_ptr2->comps[k].Dw * pow(por, + multi_Dn); + break; + } + } + if (Dp2 > 0) + Dp1 = (Dp1 + Dp2) / 2; + + /* and the mixing factor... */ + mcd_mixf = Dp1 * viscos_f * A_ij * DDt / lav; + } + mixf = mixf_store + mcd_mixf; + + if (mixf < 1e-8) + mixf = 0; + if (mixf > 0.99999999) + mixf = 0.99999999; + if (i2 > 0) + { + if (sum_surface_comp + (&surface[n2], f2, surface_ptr1, k, mixf, + &surface[n2], + surface_ptr1->comps[k].Dw) == ERROR) + return (ERROR); + f2 = 1; + } + if (i1 <= count_cells) + { + if (sum_surface_comp + (&surface[n1], f1, surface_ptr1, k, -mixf, + &surface[n1], + surface_ptr1->comps[k].Dw) == ERROR) + return (ERROR); + f1 = 1; + } + surface[n2].n_user = i2; + } + } + } + +/* + * Step 3. copy surface[n1] and [n2] in a new temporary surface... + */ + if (surface[n1].n_user == -99) + continue; + + n = temp_count_surface++; + + space((void **) ((void *) &surface), temp_count_surface, + &max_surface, sizeof(struct surface)); + surface_copy(&surface[n1], &surface[n], i1); + + surface[n1].n_user = -99; + surface[n].n_user = surface[n].n_user_end = i1; + surface_free(&surface[n1]); + surface[n1].count_comps = 0; + if (n2 == n1 + 1 && surface[n2].n_user == i2) + { + n = temp_count_surface++; + + space((void **) ((void *) &surface), temp_count_surface, + &max_surface, sizeof(struct surface)); + surface_copy(&surface[n2], &surface[n], i2); + + surface[n2].n_user = -99; + surface[n].n_user = surface[n].n_user_end = i2; + surface_free(&surface[n1 + 1]); + surface[n1 + 1].count_comps = 0; + } + } +/* + * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... + */ + n2 = 0; + + for (j = count_surface + 2; j < temp_count_surface; j++) + { + i = surface[j].n_user; + if ((i == 0 && bcon_first == 1) + || (i == count_cells + 1 && bcon_last == 1)) + { + surface_free(&surface[j]); + surface[j].count_comps = 0; + continue; + } + if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag)) + { + surface_ptr1 = surface_bsearch(i, &n); + if (surface_ptr1 != NULL) + { + surface_free(surface_ptr1); + surface_copy(&surface[j], surface_ptr1, i); + } + else + { + surface_copy(&surface[j], &surface[count_surface + n2], i); + n2++; + } + } + surface_free(&surface[j]); + surface[j].count_comps = 0; + } + count_surface += n2; + if (n2 > 0) + qsort(surface, (size_t) count_surface, + (size_t) sizeof(struct surface), surface_compare); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sum_surface_comp(struct surface *source1, LDBLE f1, struct surface *source2, + int k, LDBLE f2, struct surface *target, LDBLE new_Dw) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes fraction f1 of the 1st surface, adds fraction f2 of the 2nd surface's comps[k] and its charge. + * The result goes in target + */ + int i, i1, i2; + int new_n_user, found, charge_in; + struct surface temp_surface, *surface_ptr; + + struct surface *surface_ptr1, *surface_ptr2; + char token[MAX_LENGTH]; + int count_comps, count_comps1; + int count_charge, count_charge1, charge1, charge2; + +/* + * Find surfaces + */ + surface_ptr1 = source1; + if (surface_ptr1 == NULL) + { + error_string = sformatf( "Null pointer for surface 1 in sum_surface."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + surface_ptr2 = source2; + + if (check_surfaces(source1, source2) == ERROR) + return (ERROR); +/* + * Store data for structure surface + */ + new_n_user = surface_ptr1->n_user; + surface_copy(surface_ptr1, &temp_surface, new_n_user); + sprintf(token, "Copy"); + temp_surface.description = + (char *) free_check_null(temp_surface.description); + temp_surface.description = string_duplicate(token); + temp_surface.solution_equilibria = FALSE; + temp_surface.n_solution = -99; +/* + * Multiply component compositions by f1 + */ + for (i = 0; i < surface_ptr1->count_comps; i++) + { + temp_surface.comps[i].moles *= f1; + temp_surface.comps[i].cb *= f1; + count_elts = 0; + add_elt_list(surface_ptr1->comps[i].totals, f1); + temp_surface.comps[i].totals = + (struct elt_list *) free_check_null(temp_surface.comps[i].totals); + temp_surface.comps[i].totals = elt_list_save(); + } + if (temp_surface.type != NO_EDL) + { + for (i = 0; i < surface_ptr1->count_charge; i++) + { + temp_surface.charge[i].grams *= f1; + temp_surface.charge[i].charge_balance *= f1; + temp_surface.charge[i].mass_water *= f1; + temp_surface.charge[i].g = NULL; + temp_surface.charge[i].count_g = 0; + count_elts = 0; + if (surface_ptr1->charge[i].diffuse_layer_totals != NULL) + { + add_elt_list(surface_ptr1->charge[i].diffuse_layer_totals, + f1); + temp_surface.charge[i].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[i]. + diffuse_layer_totals); + temp_surface.charge[i].g = + (struct surface_diff_layer *) + free_check_null(temp_surface.charge[i].g); + temp_surface.charge[i].diffuse_layer_totals = elt_list_save(); + } + else + { + temp_surface.charge[i].diffuse_layer_totals = NULL; + } + } + } +/* + * Add in surface_ptr2 + */ + + count_comps = count_comps1 = surface_ptr1->count_comps; + count_charge = count_charge1 = surface_ptr1->count_charge; + + charge2 = surface_ptr2->comps[k].charge; + charge_in = FALSE; + for (i2 = 0; i2 < surface_ptr2->count_comps; i2++) + { + + if (surface_ptr2->comps[i2].charge != charge2) + continue; + /* + * handle comps... + */ + found = FALSE; + for (i1 = 0; i1 < count_comps1; i1++) + { + + /* see if first surface contains the 2nd surface's component */ + if (surface_ptr2->comps[i2].formula == + surface_ptr1->comps[i1].formula) + { + found = TRUE; + if ((surface_ptr1->comps[i1].phase_name != NULL + && surface_ptr2->comps[i2].phase_name == NULL) + || (surface_ptr1->comps[i1].phase_name == NULL + && surface_ptr2->comps[i2].phase_name != NULL)) + { + error_string = sformatf( + "Surfaces differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + else if (surface_ptr1->comps[i1].phase_name != NULL + && surface_ptr2->comps[i2].phase_name != NULL + && strcmp_nocase(surface_ptr1->comps[i1].phase_name, + surface_ptr2->comps[i2]. + phase_name) != 0) + { + error_string = sformatf( + "Surfaces differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + if ((surface_ptr1->comps[i1].rate_name != NULL + && surface_ptr2->comps[i2].rate_name == NULL) + || (surface_ptr1->comps[i1].rate_name == NULL + && surface_ptr2->comps[i2].rate_name != NULL)) + { + error_string = sformatf( + "Surfaces differ in use of related rate (sites proportional to moles of a kinetic reactant). Can not mix."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + else if (surface_ptr1->comps[i1].rate_name != NULL + && surface_ptr2->comps[i2].rate_name != NULL + && strcmp_nocase(surface_ptr1->comps[i1].rate_name, + surface_ptr2->comps[i2]. + rate_name) != 0) + { + error_string = sformatf( + "Surfaces differ in use of related rates (sites proportional to moles of a kinetic reactant). Can not mix."); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + temp_surface.comps[i1].moles += + surface_ptr2->comps[i2].moles * f2; + count_elts = 0; + add_elt_list(temp_surface.comps[i1].totals, 1.0); + add_elt_list(surface_ptr2->comps[i2].totals, f2); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + temp_surface.comps[i1].totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i1].totals); + temp_surface.comps[i1].totals = elt_list_save(); + temp_surface.comps[i1].formula_totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i1]. + formula_totals); + temp_surface.comps[i1].formula_totals = elt_list_save(); + temp_surface.comps[i1].Dw = new_Dw; + charge1 = temp_surface.comps[i1].charge; + break; + } + } + /* sum charge structures if not yet done... */ + if (found && temp_surface.type != NO_EDL && !charge_in) + { + temp_surface.charge[charge1].grams += + surface_ptr2->charge[charge2].grams * f2; + temp_surface.charge[charge1].charge_balance += + surface_ptr2->charge[charge2].charge_balance * f2; + temp_surface.charge[charge1].mass_water += + surface_ptr2->charge[charge2].mass_water * f2; + count_elts = 0; + add_elt_list(temp_surface.charge[charge1].diffuse_layer_totals, + 1.0); + add_elt_list(surface_ptr2->charge[charge2].diffuse_layer_totals, + f2); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + temp_surface.charge[charge1].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[charge1]. + diffuse_layer_totals); + temp_surface.charge[charge1].diffuse_layer_totals = + elt_list_save(); + charge_in = TRUE; + } + + if (found == FALSE) + { + + /* 2nd surface's component not in 1st surface */ + temp_surface.comps = + (struct surface_comp *) PHRQ_realloc(temp_surface.comps, + (size_t) (count_comps + + 1) * + sizeof(struct + surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + memcpy(&temp_surface.comps[count_comps], + &surface_ptr2->comps[i2], sizeof(struct surface_comp)); + temp_surface.comps[count_comps].moles *= f2; + temp_surface.comps[count_comps].cb *= f2; + count_elts = 0; + add_elt_list(surface_ptr2->comps[i2].totals, f2); + temp_surface.comps[count_comps].totals = elt_list_save(); + temp_surface.comps[count_comps].formula_totals = elt_list_save(); + temp_surface.comps[i1].Dw = new_Dw; + count_comps++; + + /* sum charge structures if not yet done... */ + if (temp_surface.type != NO_EDL && !charge_in) + { + + temp_surface.charge = + (struct surface_charge *) PHRQ_realloc(temp_surface. + charge, + (size_t) + (count_charge + + 1) * + sizeof(struct + surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + memcpy(&temp_surface.charge[count_charge], + &surface_ptr2->charge[charge2], + sizeof(struct surface_charge)); + temp_surface.charge[count_charge].grams *= f2; + temp_surface.charge[count_charge].charge_balance *= f2; + temp_surface.charge[count_charge].mass_water *= f2; + temp_surface.charge[count_charge].g = NULL; + temp_surface.charge[count_charge].count_g = 0; + count_elts = 0; + add_elt_list(surface_ptr2-> + charge[surface_ptr2->comps[k].charge]. + diffuse_layer_totals, f2); + temp_surface.charge[count_charge].diffuse_layer_totals = + elt_list_save(); + count_charge++; + charge_in = TRUE; + } + temp_surface.comps[count_comps - 1].charge = count_charge - 1; + } + } + + temp_surface.count_comps = count_comps; + temp_surface.count_charge = count_charge; + temp_surface.transport = FALSE; + for (i = 0; i < count_comps; i++) + { + if (temp_surface.comps[i].Dw > 0) + { + temp_surface.transport = TRUE; + break; + } + } + +/* + * Finish up + */ + surface_ptr = target; + if (surface_ptr == NULL) + { + error_string = sformatf( "Target surface is NULL in sum_surface_comp"); + error_msg(error_string, CONTINUE); + input_error++; + return (ERROR); + } + surface_free(surface_ptr); + surface_copy(&temp_surface, surface_ptr, new_n_user); + surface_free(&temp_surface); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_surfaces(struct surface *surface_ptr1, struct surface *surface_ptr2) +/* ---------------------------------------------------------------------- */ +{ +/* checks if surfaces can be mixed... + */ + int n_user1, n_user2, return_code; + + return_code = OK; + n_user1 = surface_ptr1->n_user; + n_user2 = surface_ptr2->n_user; + + /*if (surface_ptr1->diffuse_layer != surface_ptr2->diffuse_layer) { */ + if (surface_ptr1->dl_type != surface_ptr2->dl_type) + { + error_string = sformatf( + "Surfaces %d and %d differ in definition of diffuse layer. Can not mix.", + n_user1, n_user2); + error_msg(error_string, CONTINUE); + return_code = ERROR; + input_error++; + } + /*if (surface_ptr1->edl != surface_ptr2->edl) { */ + if (surface_ptr1->type != surface_ptr2->type) + { + error_string = sformatf( + "Surfaces %d and %d differ in use of electrical double layer. Can not mix.", + n_user1, n_user2); + error_msg(error_string, CONTINUE); + return_code = ERROR; + input_error++; + } + if (surface_ptr1->only_counter_ions != surface_ptr2->only_counter_ions) + { + error_string = sformatf( + "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Can not mix.", + n_user1, n_user2); + error_msg(error_string, CONTINUE); + return_code = ERROR; + input_error++; + } + if (surface_ptr1->related_phases != surface_ptr2->related_phases) + { + error_string = sformatf( + "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix.", + n_user1, n_user2); + error_msg(error_string, CONTINUE); + return_code = ERROR; + input_error++; + } + if (surface_ptr1->related_rate != surface_ptr2->related_rate) + { + error_string = sformatf( + "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Can not mix.", + n_user1, n_user2); + error_msg(error_string, CONTINUE); + return_code = ERROR; + input_error++; + } + + return (return_code); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +mobile_surface_copy(struct surface *surface_old_ptr, + struct surface *surf_ptr1, int n_user_new, int move_old) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies mobile comps from surface_old_ptr to surf_ptr1, + * comps and charges with Dw > 0 are moved if move_old == TRUE, else copied. + * NOTE... when all comps are moved, the old surface is deleted and surfaces are sorted again, + * which will modify pointers and surface numbers. + * User number of new surface structure is n_user_new, structure is freed when n_user_new is already defined + */ + int count_comps, count_charge, new_charge, n_user_old, charge_done; + int i, i1, i2, j, k, k1, n; + char token[MAX_LENGTH]; + struct surface temp_surface, *surf_ptr; +/* + * Store moving surface's properties in temp_surface + */ + temp_surface.n_user = temp_surface.n_user_end = n_user_new; + temp_surface.new_def = surface_old_ptr->new_def; + sprintf(token, "Surface defined in simulation %d.", simulation); + temp_surface.description = string_duplicate(token); + temp_surface.dl_type = surface_old_ptr->dl_type; + temp_surface.type = surface_old_ptr->type; + temp_surface.only_counter_ions = surface_old_ptr->only_counter_ions; + temp_surface.thickness = surface_old_ptr->thickness; + temp_surface.debye_lengths = surface_old_ptr->debye_lengths; + temp_surface.DDL_viscosity = surface_old_ptr->DDL_viscosity; + temp_surface.DDL_limit = surface_old_ptr->DDL_limit; + temp_surface.solution_equilibria = FALSE; + temp_surface.n_solution = -99; + temp_surface.related_phases = surface_old_ptr->related_phases; + temp_surface.related_rate = surface_old_ptr->related_rate; + temp_surface.transport = TRUE; + + temp_surface.comps = + (struct surface_comp *) PHRQ_malloc(sizeof(struct surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + temp_surface.charge = + (struct surface_charge *) PHRQ_malloc(sizeof(struct surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + + count_comps = surface_old_ptr->count_comps; + count_charge = surface_old_ptr->count_charge; + i1 = i2 = 0; + /* see if comps must be moved, Dw > 0 */ + for (i = 0; i < count_comps; i++) + { + if (surface_old_ptr->comps[i].Dw > 0) + { + i1++; + if (i1 > 1) + { + temp_surface.comps = + (struct surface_comp *) PHRQ_realloc(temp_surface.comps, + (size_t) i1 * + sizeof(struct + surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + } + memcpy(&temp_surface.comps[i1 - 1], &surface_old_ptr->comps[i], + sizeof(struct surface_comp)); + temp_surface.comps[i1 - 1].totals = + elt_list_dup(surface_old_ptr->comps[i].totals); + temp_surface.comps[i1 - 1].formula_totals = + elt_list_dup(surface_old_ptr->comps[i].formula_totals); + + /* charge structure */ + new_charge = TRUE; + for (j = 0; j < i; j++) + { + if (surface_old_ptr->comps[j].charge == + surface_old_ptr->comps[i].charge) + { + temp_surface.comps[i1 - 1].charge = i2 - 1; + new_charge = FALSE; + break; + } + } + if (new_charge) + { + i2++; + if (i2 > 1) + { + temp_surface.charge = + (struct surface_charge *) PHRQ_realloc(temp_surface. + charge, + (size_t) i2 * + sizeof(struct + surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + } + memcpy(&temp_surface.charge[i2 - 1], + &surface_old_ptr->charge[surface_old_ptr->comps[i]. + charge], + (size_t) sizeof(struct surface_charge)); + temp_surface.charge[i2 - 1].diffuse_layer_totals = + elt_list_dup(surface_old_ptr-> + charge[surface_old_ptr->comps[i].charge]. + diffuse_layer_totals); + temp_surface.charge[i2 - 1].g = NULL; + + temp_surface.comps[i1 - 1].charge = i2 - 1; + } + } + } + temp_surface.count_comps = i1; + temp_surface.count_charge = i2; + if (i1 > 0) + { + /* OK, store moved parts from old surface, but first: + get immobile surface comps from new surface... */ + if ((surf_ptr = surface_bsearch(n_user_new, &n)) != NULL) + { + for (k = 0; k < surf_ptr->count_comps; k++) + { + if (surf_ptr->comps[k].Dw > 0) + continue; + charge_done = FALSE; + for (k1 = 0; k1 < k; k1++) + { + if (surf_ptr->comps[k1].charge == + surf_ptr->comps[k].charge) + { + charge_done = TRUE; + break; + } + } + if (charge_done) + continue; + + if (sum_surface_comp + (&temp_surface, 1, surf_ptr, k, 1, &temp_surface, + 0) == ERROR) + return (ERROR); + } + } + if (surf_ptr1->count_comps > 0) + surface_free(surf_ptr1); + surface_copy(&temp_surface, surf_ptr1, n_user_new); + } + + /* delete moved parts from old surface */ + if (move_old && i1 > 0) + { + n_user_old = surface_old_ptr->n_user; + if (i1 != count_comps) + { + /* redefine old surface with only unmovable comps (Dw = 0) */ + /* other temp_surface members were set above */ + temp_surface.n_user = temp_surface.n_user_end = n_user_old; + temp_surface.transport = FALSE; + + for (i = 0; i < temp_surface.count_comps; i++) + { + temp_surface.comps[i].totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i].totals); + temp_surface.comps[i].formula_totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i]. + formula_totals); + } + for (i = 0; i < temp_surface.count_charge; i++) + { + temp_surface.charge[i].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[i]. + diffuse_layer_totals); + temp_surface.charge[i].g = + (struct surface_diff_layer *) + free_check_null(temp_surface.charge[i].g); + } + temp_surface.comps = + (struct surface_comp *) PHRQ_realloc(temp_surface.comps, + sizeof(struct + surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + temp_surface.charge = + (struct surface_charge *) PHRQ_realloc(temp_surface.charge, + sizeof(struct + surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + + i1 = i2 = 0; + for (i = 0; i < count_comps; i++) + { + if (surface_old_ptr->comps[i].Dw == 0) + { + i1++; + if (i1 > 1) + { + temp_surface.comps = + (struct surface_comp *) + PHRQ_realloc(temp_surface.comps, + (size_t) i1 * + sizeof(struct surface_comp)); + if (temp_surface.comps == NULL) + malloc_error(); + } + memcpy(&temp_surface.comps[i1 - 1], + &surface_old_ptr->comps[i], + (size_t) sizeof(struct surface_comp)); + temp_surface.comps[i1 - 1].totals = + elt_list_dup(surface_old_ptr->comps[i].totals); + temp_surface.comps[i1 - 1].formula_totals = + elt_list_dup(surface_old_ptr->comps[i]. + formula_totals); + + /* charge structure */ + new_charge = TRUE; + for (j = 0; j < i; j++) + { + if (surface_old_ptr->comps[j].charge == + surface_old_ptr->comps[i].charge) + { + temp_surface.comps[i1 - 1].charge = i2 - 1; + new_charge = FALSE; + break; + } + } + if (new_charge) + { + i2++; + if (i2 > 1) + { + temp_surface.charge = + (struct surface_charge *) + PHRQ_realloc(temp_surface.charge, + (size_t) i2 * + sizeof(struct surface_charge)); + if (temp_surface.charge == NULL) + malloc_error(); + } + memcpy(&temp_surface.charge[i2 - 1], + &surface_old_ptr->charge[surface_old_ptr-> + comps[i].charge], + (size_t) sizeof(struct surface_charge)); + temp_surface.charge[i2 - 1].diffuse_layer_totals = + elt_list_dup(surface_old_ptr-> + charge[surface_old_ptr->comps[i]. + charge].diffuse_layer_totals); + temp_surface.charge[i2 - 1].g = NULL; + + temp_surface.comps[i1 - 1].charge = i2 - 1; + } + } + } + temp_surface.count_comps = i1; + temp_surface.count_charge = i2; + if (i1 > 0) + { + temp_surface.related_phases = temp_surface.related_rate = + FALSE; + for (i = 0; i < i1; i++) + { + if (surface_old_ptr->comps[i].phase_name != NULL) + temp_surface.related_phases = TRUE; + if (surface_old_ptr->comps[i].rate_name != NULL) + temp_surface.related_rate = TRUE; + } + } + surface_free(surface_old_ptr); + surface_copy(&temp_surface, surface_old_ptr, n_user_old); + } + else + { + surface_sort(); + surface_delete(n_user_old); + } + } + + surface_free(&temp_surface); + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +diff_stag_surf(int mobile_cell) +/* ---------------------------------------------------------------------- */ +/* + * Diffuse stagnant and mobile surfaces, following the steps of disp_surf. + * First the mobile/stagnant surfaces are mixed, then the stagnant surfaces + * when not already done. + * If mixing factors among the cells are defined expicitly, it is assumed that + * mixing with a lower numbered cell was done when that cell was processed: + * for any cell in MCD, need only include the mixing factors for higher numbered cells. + */ +{ + int i, i1, i2, j, k, k1, n, n1, n2, ns, temp_count_surface; + int charge_done, surf1, surf2; + LDBLE f1, f2, mixf, mixf_store; + LDBLE Dp1, Dp2; + //struct mix *mix_ptr; + cxxMix *mix_ptr; + struct surface *surface_ptr1, *surface_ptr2; + LDBLE viscos_f; +/* + * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + */ + viscos_f = viscosity(); + viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); + + n1 = count_surface; + n2 = n1 + 1; + temp_count_surface = count_surface + 2; + space((void **) ((void *) &surface), temp_count_surface, &max_surface, + sizeof(struct surface)); + surface[n1].count_comps = surface[n1 + 1].count_comps = 0; + + for (ns = 0; ns < stag_data->count_stag; ns++) + { + + i1 = mobile_cell + 1 + ns * count_cells; + if (ns == 0) + i1--; + + if (cell_data[i1 - 1].por < multi_Dpor_lim) + continue; + surface[n1].n_user = surface[n1 + 1].n_user = -99; + surface_ptr1 = surface_bsearch(i1, &n); + +/* + * step 2a. mix surfaces... + */ + //mix_ptr = mix_search(i1, &n, FALSE); + mix_ptr = Utilities::Rxn_find(Rxn_mix_map, i1); + if (mix_ptr == NULL) + continue; + + //for (j = 0; j < mix_ptr->count_comps; j++) + //std::map::const_iterator cit; + //for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) + std::vector num; + std::vector frac; + mix_ptr->Vectorize(num, frac); + for (size_t i3 = 0; i3 < num.size(); i3++) + { + + //if ((i2 = mix_ptr->comps[j].n_solution) <= i1) + //if ((i2 = cit->first) <= i1) + if ((i2 = num[i3]) <= i1) + continue; + if (cell_data[i2 - 1].por < multi_Dpor_lim) + continue; + surface_ptr2 = surface_bsearch(i2, &n); + + surf1 = surf2 = 0; + if (surface_ptr2 != NULL) + { + if (surface_ptr2->transport == TRUE) + surf2 = 1; + } + if (surface_ptr1 != NULL) + { + if (surface_ptr1->transport == TRUE) + surf1 = 1; + } + if (!surf1 && !surf2) + continue; + + //mixf = mixf_store = mix_ptr->comps[j].fraction; + //mixf = mixf_store = cit->second; + mixf = mixf_store = frac[i3];; + + /* find the (possibly modified) surface in cell i1... */ + f1 = 1; + for (k = count_surface + 2; k < temp_count_surface; k++) + { + if (surface[k].n_user == i1) + { + n1 = k; + break; + } + } + /* if not found... */ + if (k == temp_count_surface) + { + n1 = count_surface; + /* copy it from surface_ptr1... */ + if (surface_ptr1 != NULL) + surface_copy(surface_ptr1, &surface[n1], i1); + else + { + /* or make it a mobile copy of the surface in cell i2... */ + mobile_surface_copy(surface_ptr2, &surface[n1], i1, + FALSE); + /* limit comps to 1... */ + if (surface[n1].count_comps > 1) + { + if (sum_surface_comp + (&surface[n1], 0, &surface[n1], 0, 1, + &surface[n1], surface[n1].comps[0].Dw) == ERROR) + return (ERROR); + } + f1 = 0; + } + } + /* find the (possibly modified) surface in cell i2... */ + f2 = 1; + for (k = count_surface + 2; k < temp_count_surface; k++) + { + if (surface[k].n_user == i2) + { + n2 = k; + break; + } + } + /* if not found... */ + if (k == temp_count_surface) + { + n2 = count_surface + 1; + /* copy it from surface_ptr2... */ + if (surface_ptr2 != NULL) + surface_copy(surface_ptr2, &surface[n2], i2); + else + { + /* or make it a mobile copy of the surface in cell i1... */ + mobile_surface_copy(surface_ptr1, &surface[n2], i2, + FALSE); + /* limit comps to 1... */ + if (surface[n2].count_comps > 1) + { + if (sum_surface_comp + (&surface[n2], 0, &surface[n2], 0, 1, + &surface[n2], surface[n2].comps[0].Dw) == ERROR) + return (ERROR); + } + f2 = 0; + } + } + + /* For MCD, step 2b. Adapt mixf to default values... */ + if (multi_Dflag) + { + mixf_store *= + (cell_data[i1 - 1].por <= + cell_data[i2 - 1].por ? cell_data[i1 - + 1].por : cell_data[i2 - + 1]. + por); + mixf_store /= (default_Dw * pow(multi_Dpor, multi_Dn) * + multi_Dpor); + } + + /* mix in comps with the same charge structure... */ + if (surf2) + { + for (k = 0; k < surface_ptr2->count_comps; k++) + { + if (surface_ptr2->comps[k].Dw == 0) + continue; + charge_done = FALSE; + for (k1 = 0; k1 < k; k1++) + { + if (surface_ptr2->comps[k1].charge == + surface_ptr2->comps[k].charge) + { + charge_done = TRUE; + break; + } + } + if (charge_done) + continue; + + /* find diffusion coefficients of surfaces... */ + if (multi_Dflag) + { + Dp2 = + surface_ptr2->comps[k].Dw * + pow(cell_data[i2 - 1].por, multi_Dn) * viscos_f; + Dp1 = 0; + if (surf1) + { + for (k1 = 0; k1 < surface_ptr1->count_comps; k1++) + { + if (elt_list_compare + (surface_ptr1->comps[k1].totals, + surface_ptr2->comps[k].totals) != 0) + continue; + Dp1 = + surface_ptr1->comps[k1].Dw * + pow(cell_data[i1 - 1].por, + multi_Dn) * viscos_f; + break; + } + } + if (Dp1 > 0) + Dp2 = (Dp2 + Dp1) / 2; + + /* and adapt the mixing factor... */ + mixf = mixf_store * Dp2; + mixf /= solution_bsearch(i2, &n, FALSE)->mass_water; + } + + if (mixf < 1e-8) + mixf = 0; + if (mixf > 0.99999999) + mixf = 0.99999999; + if (sum_surface_comp + (&surface[n1], f1, surface_ptr2, k, mixf, + &surface[n1], surface_ptr2->comps[k].Dw) == ERROR) + return (ERROR); + f1 = 1; + + if (sum_surface_comp + (&surface[n2], f2, surface_ptr2, k, -mixf, + &surface[n2], surface_ptr2->comps[k].Dw) == ERROR) + return (ERROR); + } + } + + if (surf1) + { + for (k = 0; k < surface_ptr1->count_comps; k++) + { + if (surface_ptr1->comps[k].Dw == 0) + continue; + charge_done = FALSE; + for (k1 = 0; k1 < k; k1++) + { + if (surface_ptr1->comps[k1].charge == + surface_ptr1->comps[k].charge) + { + charge_done = TRUE; + break; + } + } + if (charge_done) + continue; + + /* find diffusion coefficients of surfaces... */ + if (multi_Dflag) + { + Dp1 = + surface_ptr1->comps[k].Dw * + pow(cell_data[i1 - 1].por, multi_Dn) * viscos_f; + + Dp2 = 0; + if (surf2) + { + for (k1 = 0; k1 < surface_ptr2->count_comps; k1++) + { + if (elt_list_compare + (surface_ptr2->comps[k1].totals, + surface_ptr1->comps[k].totals) != 0) + continue; + Dp2 = + surface_ptr2->comps[k1].Dw * + pow(cell_data[i2 - 1].por, + multi_Dn) * viscos_f; + break; + } + } + if (Dp2 > 0) + Dp1 = (Dp1 + Dp2) / 2; + + /* and adapt the mixing factor... */ + mixf = mixf_store * Dp1; + mixf /= solution_bsearch(i1, &n, FALSE)->mass_water; + } + + if (mixf < 1e-8) + mixf = 0; + if (mixf > 0.99999999) + mixf = 0.99999999; + if (sum_surface_comp + (&surface[n2], f2, surface_ptr1, k, mixf, + &surface[n2], surface_ptr1->comps[k].Dw) == ERROR) + return (ERROR); + f2 = 1; + + if (sum_surface_comp + (&surface[n1], f1, surface_ptr1, k, -mixf, + &surface[n1], surface_ptr1->comps[k].Dw) == ERROR) + return (ERROR); + } + } + +/* + * Step 3. copy surface[n1] and [n2] in a new temporary surface... + */ + if (surface[n1].n_user == -99) + continue; + + if (n1 == count_surface) + { + n = temp_count_surface++; + + space((void **) ((void *) &surface), temp_count_surface, + &max_surface, sizeof(struct surface)); + surface_copy(&surface[n1], &surface[n], i1); + + surface_free(&surface[n1]); + surface[n1].count_comps = 0; + } + else + n1 = count_surface; + + if (n2 == count_surface + 1) + { + n = temp_count_surface++; + + space((void **) ((void *) &surface), temp_count_surface, + &max_surface, sizeof(struct surface)); + surface_copy(&surface[n2], &surface[n], i2); + + surface_free(&surface[n2]); + surface[n2].count_comps = 0; + } + else + n2 = count_surface + 1; + } + } +/* + * Step 4. Diffusion is done. New surfaces can be copied in the cells... + */ + + n2 = 0; + + for (j = count_surface + 2; j < temp_count_surface; j++) + { + i = surface[j].n_user; + if ((i == 0 && bcon_first == 1) + || (i == count_cells + 1 && bcon_last == 1)) + { + surface_free(&surface[j]); + surface[j].count_comps = 0; + continue; + } + if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag)) + { + surface_ptr1 = surface_bsearch(i, &n); + if (surface_ptr1 != NULL) + { + surface_free(surface_ptr1); + surface_copy(&surface[j], surface_ptr1, i); + } + else + { + surface_copy(&surface[j], &surface[count_surface + n2], i); + n2++; + } + } + surface_free(&surface[j]); + surface[j].count_comps = 0; + } + count_surface += n2; + if (n2 > 0) + qsort(surface, (size_t) count_surface, + (size_t) sizeof(struct surface), surface_compare); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, + LDBLE new_Dw, int l_cell) +/* ---------------------------------------------------------------------- */ +{ + int i, i1, j, k, k1, n, length, length1, cn, cn1, charge_in; + char string[MAX_LENGTH]; + struct surface temp_surface, *surf_ptr; + + if ((surf_ptr = surface_bsearch(l_cell, &n)) == ERROR) + return (OK); + + if (fraction > 0.99999999) + fraction = 0.99999999; + length = (int) strlen(comp_name); + length1 = (int) strlen(new_comp_name); + for (k = 0; k < surf_ptr->count_comps; k++) + { + if (strncmp(comp_name, surf_ptr->comps[k].formula, length) == 0) + break; + } + if (k == surf_ptr->count_comps) + return (OK); + + surface_copy(surf_ptr, &temp_surface, l_cell); + + for (k1 = 0; k1 < temp_surface.count_comps; k1++) + { + if (strncmp(new_comp_name, temp_surface.comps[k1].formula, length1) + == 0) + break; + } + + charge_in = FALSE; + if (k1 == temp_surface.count_comps) + { + /* new_comp_name absent */ + /* rename the comps... */ + for (i = 0; i < temp_surface.count_comps; i++) + { + if (temp_surface.comps[i].charge != temp_surface.comps[k].charge) + continue; + + strcpy(string, temp_surface.comps[i].formula); + replace(comp_name, new_comp_name, string); + temp_surface.comps[i].formula = string_hsave(string); + + temp_surface.comps[i].moles *= fraction; + + count_elts = 0; + add_elt_list(temp_surface.comps[i].totals, fraction); + temp_surface.comps[i].totals = + (struct elt_list *) free_check_null(temp_surface.comps[i]. + totals); + temp_surface.comps[i].totals = elt_list_save(); +/* appt, is this correct ? */ + temp_surface.comps[i].formula_totals = + (struct elt_list *) free_check_null(temp_surface.comps[i]. + formula_totals); + temp_surface.comps[i].formula_totals = elt_list_save(); + + /* rename surface comp in element list */ + for (j = 0; temp_surface.comps[i].totals[j].elt != NULL; j++) + { + if (strncmp + (comp_name, temp_surface.comps[i].totals[j].elt->name, + length) == 0) + { + strcpy(string, temp_surface.comps[i].totals[j].elt->name); + replace(comp_name, new_comp_name, string); + temp_surface.comps[i].totals[j].elt = + element_store(string); + } + } + for (j = 0; temp_surface.comps[i].formula_totals[j].elt != NULL; + j++) + { + if (strncmp + (comp_name, + temp_surface.comps[i].formula_totals[j].elt->name, + length) == 0) + { + strcpy(string, + temp_surface.comps[i].formula_totals[j].elt->name); + replace(comp_name, new_comp_name, string); + temp_surface.comps[i].formula_totals[j].elt = + element_store(string); + } + } + /* add charge */ + if (!charge_in) + { + cn = temp_surface.comps[i].charge; + + temp_surface.charge[cn].grams *= fraction; + temp_surface.charge[cn].charge_balance *= fraction; + temp_surface.charge[cn].mass_water *= fraction; + + count_elts = 0; + add_elt_list(temp_surface.charge[cn].diffuse_layer_totals, + fraction); + temp_surface.charge[cn].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[cn]. + diffuse_layer_totals); + temp_surface.charge[cn].diffuse_layer_totals = + elt_list_save(); + + strcpy(string, temp_surface.charge[cn].name); + replace(comp_name, new_comp_name, string); + temp_surface.charge[cn].name = string_hsave(string); + /* renaming charge psi_master seems unnecessary... */ + charge_in = TRUE; + } + temp_surface.comps[i].Dw = new_Dw; + } + + /* add remainder of old comp and charge */ + if (fraction < 1) + sum_surface_comp(&temp_surface, 1, surf_ptr, k, 1 - fraction, + &temp_surface, surf_ptr->comps[k].Dw); + } + else + { + /* new_comp_name is already in surface */ + cn = surf_ptr->comps[k].charge; + for (i = 0; i < surf_ptr->count_comps; i++) + { + + if (surf_ptr->comps[i].charge != cn) + continue; + + strcpy(string, surf_ptr->comps[i].formula); + replace(comp_name, new_comp_name, string); + + /* add comps to new_comps */ + for (i1 = 0; i1 < temp_surface.count_comps; i1++) + { + + if (strcmp(string, temp_surface.comps[i1].formula) != 0) + continue; + + temp_surface.comps[i1].moles += + surf_ptr->comps[i].moles * fraction; + temp_surface.comps[i].moles -= + surf_ptr->comps[i].moles * fraction; + + /* rename surface comp in element list */ + for (j = 0; temp_surface.comps[i].totals[j].elt != NULL; j++) + { + if (strncmp + (comp_name, temp_surface.comps[i].totals[j].elt->name, + length) == 0) + { + strcpy(string, + temp_surface.comps[i].totals[j].elt->name); + replace(comp_name, new_comp_name, string); + temp_surface.comps[i].totals[j].elt = + element_store(string); + } + } + for (j = 0; + temp_surface.comps[i].formula_totals[j].elt != NULL; j++) + { + if (strncmp + (comp_name, + temp_surface.comps[i].formula_totals[j].elt->name, + length) == 0) + { + strcpy(string, + temp_surface.comps[i].formula_totals[j].elt-> + name); + replace(comp_name, new_comp_name, string); + temp_surface.comps[i].formula_totals[j].elt = + element_store(string); + } + } + count_elts = 0; + add_elt_list(temp_surface.comps[i1].totals, 1.0); + add_elt_list(temp_surface.comps[i].totals, fraction); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + temp_surface.comps[i1].totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i1].totals); + temp_surface.comps[i1].totals = elt_list_save(); + temp_surface.comps[i1].formula_totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i1]. + formula_totals); + temp_surface.comps[i1].formula_totals = elt_list_save(); + temp_surface.comps[i1].Dw = new_Dw; + + count_elts = 0; + add_elt_list(surf_ptr->comps[i].totals, 1.0 - fraction); + temp_surface.comps[i].totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i].totals); + temp_surface.comps[i].totals = elt_list_save(); + temp_surface.comps[i].formula_totals = + (struct elt_list *) free_check_null(temp_surface. + comps[i]. + formula_totals); + temp_surface.comps[i].formula_totals = elt_list_save(); + + /* add charge */ + if (!charge_in) + { + cn1 = temp_surface.comps[i1].charge; + temp_surface.charge[cn1].grams += + surf_ptr->charge[cn].grams * fraction; + temp_surface.charge[cn1].charge_balance += + surf_ptr->charge[cn].charge_balance * fraction; + temp_surface.charge[cn1].mass_water += + surf_ptr->charge[cn].mass_water * fraction; + + temp_surface.charge[cn].grams -= + surf_ptr->charge[cn].grams * fraction; + temp_surface.charge[cn].charge_balance -= + surf_ptr->charge[cn].charge_balance * fraction; + temp_surface.charge[cn].mass_water -= + surf_ptr->charge[cn].mass_water * fraction; + + count_elts = 0; + add_elt_list(temp_surface.charge[cn1]. + diffuse_layer_totals, 1.0); + add_elt_list(surf_ptr->charge[cn].diffuse_layer_totals, + fraction); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), + elt_list_compare); + elt_list_combine(); + } + temp_surface.charge[cn1].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[cn1]. + diffuse_layer_totals); + temp_surface.charge[cn1].diffuse_layer_totals = + elt_list_save(); + + count_elts = 0; + add_elt_list(surf_ptr->charge[cn].diffuse_layer_totals, + 1.0 - fraction); + temp_surface.charge[cn].diffuse_layer_totals = + (struct elt_list *) free_check_null(temp_surface. + charge[cn]. + diffuse_layer_totals); + temp_surface.charge[cn].diffuse_layer_totals = + elt_list_save(); + + charge_in = TRUE; + } + } + } + } + + temp_surface.transport = FALSE; + for (i = 0; i < temp_surface.count_comps; i++) + { + if (temp_surface.comps[i].Dw > 0) + temp_surface.transport = TRUE; + } + surface_free(surf_ptr); + surface_copy(&temp_surface, surf_ptr, l_cell); + surface_free(&temp_surface); + + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +viscosity(void) +/* ---------------------------------------------------------------------- */ +{ + LDBLE viscos; +/* from Atkins, 1994. Physical Chemistry, 5th ed. */ + viscos = + pow((LDBLE) 10., + -(1.37023 * (tc_x - 20) + + 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); + return viscos; +} diff --git a/rename_cpp/utilities.cpp b/rename_cpp/utilities.cpp new file mode 100644 index 00000000..66b90827 --- /dev/null +++ b/rename_cpp/utilities.cpp @@ -0,0 +1,1842 @@ +#include "Phreeqc.h" +#include "phqalloc.h" +#include "NameDouble.h" +#include "Exchange.h" +#include + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ + struct elt_list *elt_list_ptr1; + + if (elt_list_ptr == NULL) + return (OK); + + for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; + elt_list_ptr1++) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } + return (OK); +} + +int Phreeqc:: +add_elt_list(const cxxNameDouble & nd, LDBLE coef) +/* ---------------------------------------------------------------------- */ +{ + cxxNameDouble::const_iterator cit = nd.begin(); + for ( ; cit != nd.end(); cit++) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = element_store(cit->first.c_str()); + elt_list[count_elts].coef = cit->second * coef; + count_elts++; + } +#ifdef SKIP + for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; + elt_list_ptr1++) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } +#endif + return (OK); +} + + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_alk(struct reaction * rxn_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE return_value; + struct master *master_ptr; + + return_value = 0.0; + for (i = 1; rxn_ptr->token[i].s != NULL; i++) + { + master_ptr = rxn_ptr->token[i].s->secondary; + if (master_ptr == NULL) + { + master_ptr = rxn_ptr->token[i].s->primary; + } + if (master_ptr == NULL) + { + error_string = sformatf( + "Non-master species in secondary reaction, %s.", + rxn_ptr->token[0].s->name); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + return_value += rxn_ptr->token[i].coef * master_ptr->alk; + } + return (return_value); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_rho_0(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ + /* Density of pure water + Millero, 2009, Aq. Geochem. 15, 7-41, 1 - 200 oC, 1 - 1000 atm... */ + + LDBLE rho_0 = (999.83952 + (16.952577 + (-7.9905127e-3 + (-4.6241757e-5 + (1.0584601e-7 -\ + 2.8103006e-10 * tc) * tc) * tc) * tc) * tc) / (1 + 0.016887236 * tc); + /* pressure... */ +/* + //LDBLE A = 5.08531e-2 + (-3.338927e-4 + (5.112457e-6 + (-3.226571e-8 + (1.186388e-10 -\ + // 1.437927e-13 * tc) * tc) * tc) * tc); + //LDBLE B = -5.6999022e-6 + (6.370734e-8 + (-1.047053e-9 + (5.836798e-12 + (-1.658343e-14 +\ + // 3.977591e-22 * tc) * tc) * tc) * tc); + //rho_0 += (A + B * patm_x) * patm_x; + */ + /* But, A and B are near-constants, the pressure term is equal to... */ + rho_0 += 0.046 * pa; + + return (1e-3 * rho_0); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +compute_gfw(const char *string, LDBLE * gfw) +/* ---------------------------------------------------------------------- */ +{ +/* + * Input: string contains a chemical formula + * Output: gfw contains the calculated gfw + */ + int i; + char token[MAX_LENGTH]; + char *ptr; + + count_elts = 0; + paren_count = 0; + strcpy(token, string); + ptr = token; + if (get_elts_in_species(&ptr, 1.0) == ERROR) + { + return (ERROR); + } + *gfw = 0.0; + for (i = 0; i < count_elts; i++) + { + if (elt_list[i].elt->gfw <= 0.0) + { + return (ERROR); + } + *gfw += elt_list[i].coef * (elt_list[i].elt)->gfw; + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_token(char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first space is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * UNKNOWN. + */ + int i, return_value; + char c; + +/* + * Read to end of whitespace + */ + while (isspace((int) (c = **ptr))) + (*ptr)++; +/* + * Check what we have + */ + if (isupper((int) c) || c == '[') + { + return_value = UPPER; + } + else if (islower((int) c)) + { + return_value = LOWER; + } + else if (isdigit((int) c) || c == '.' || c == '-') + { + return_value = DIGIT; + } + else if (c == '\0') + { + return_value = EMPTY; + } + else + { + return_value = UNKNOWN; + } +/* + * Begin copying to token + */ + i = 0; + while ((!isspace((int) (c = **ptr))) && + /* c != ',' && */ + c != ';' && c != '\0') + { + token_ptr[i] = c; + (*ptr)++; + i++; + } + token_ptr[i] = '\0'; + *length = i; +#ifdef PHREEQ98 + if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) + { + error_string = sformatf( + "Commas are not allowed as decimal separator: %s.", + token_ptr); + error_msg(error_string, CONTINUE); + } +#endif + return (return_value); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_token(std::string &token, char **ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token until first space is encountered. + * + * Arguments: + * &token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * UNKNOWN. + */ + int return_value; + char c; + +/* + * Read to end of whitespace + */ + token.clear(); + while (isspace((int) (c = **ptr))) + (*ptr)++; +/* + * Check what we have + */ + if (isupper((int) c) || c == '[') + { + return_value = UPPER; + } + else if (islower((int) c)) + { + return_value = LOWER; + } + else if (isdigit((int) c) || c == '.' || c == '-') + { + return_value = DIGIT; + } + else if (c == '\0') + { + return_value = EMPTY; + } + else + { + return_value = UNKNOWN; + } +/* + * Begin copying to token + */ + char c_char[2]; + c_char[1] = '\0'; + while ((!isspace((int) (c = **ptr))) && + /* c != ',' && */ + c != ';' && c != '\0') + { + //token_ptr[i] = c; + c_char[0] = c; + token.append(c_char); + (*ptr)++; + } +#ifdef PHREEQ98 + if ((return_value == DIGIT) && (strstr(token_ptr, ",") != NULL)) + { + error_string = sformatf( + "Commas are not allowed as decimal separator: %s.", + token_ptr); + error_msg(error_string, CONTINUE); + } +#endif + return (return_value); +} +#if defined PHREEQ98 +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +copy_title(char *token_ptr, char **ptr, int *length) +/* ---------------------------------------------------------------------- */ +{ +/* + * Copies from **ptr to *token_ptr until first space or comma is encountered. + * + * Arguments: + * *token_ptr output, place to store token + * + * **ptr input, character string to read token from + * output, next position after token + * + * length output, length of token + * + * Returns: + * UPPER, + * LOWER, + * DIGIT, + * EMPTY, + * UNKNOWN. + */ + int i, return_value; + char c; + int Quote = FALSE; + +/* + * Read to end of whitespace + */ + while (isspace((int) (c = **ptr)) || (c == ',') || (c == '"')) + { + if (c == '"') + Quote = TRUE; + (*ptr)++; + } +/* + * Check what we have + */ + if (isupper((int) c)) + { + return_value = UPPER; + } + else if (islower((int) c)) + { + return_value = LOWER; + } + else if (isdigit((int) c) || c == '.' || c == '-') + { + return_value = DIGIT; + } + else if (c == '\0') + { + return_value = EMPTY; + } + else + { + return_value = UNKNOWN; + } +/* + * Begin copying to token + */ + i = 0; + if (Quote == TRUE) + { + while (((int) (c = **ptr) != '"') && c != '\0') + { + token_ptr[i] = c; + (*ptr)++; + i++; + } + } + else + { + while ((!isspace((int) (c = **ptr))) && + c != ',' && c != ';' && c != '\0') + { + token_ptr[i] = c; + (*ptr)++; + i++; + } + } + token_ptr[i] = '\0'; + *length = i; + return (return_value); +} +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +dup_print(const char *ptr, int emphasis) +/* ---------------------------------------------------------------------- */ +{ +/* + * print character string to output and logfile + * if emphasis == TRUE the print is set off by + * a row of dashes before and after the character string. + * + */ + int l, i; + char *dash; + + if (pr.headings == FALSE) + return (OK); +#ifdef PHREEQ98 + if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) + { + if (strstr(ptr, "Reading") == ptr) + AddToCEntry((char *) ptr, 1, outputlinenr); + else if (strstr(ptr, "Beginning") == ptr) + AddToCEntry((char *) ptr, 2, outputlinenr); + else if ((strstr(ptr, "TITLE") != ptr) && (strstr(ptr, "End") != ptr)) + AddToCEntry((char *) ptr, 3, outputlinenr); + } +#endif + std::string save_in(ptr); + l = (int) strlen(ptr); + dash = (char *) PHRQ_malloc((size_t) (l + 2) * sizeof(char)); + if (dash == NULL) + malloc_error(); + if (emphasis == TRUE) + { + for (i = 0; i < l; i++) + dash[i] = '-'; + dash[i] = '\0'; + output_msg(sformatf("%s\n%s\n%s\n\n", dash, save_in.c_str(), dash)); + log_msg(sformatf("%s\n%s\n%s\n\n", dash, save_in.c_str(), dash)); + } + else + { + output_msg(sformatf("%s\n\n", save_in.c_str())); + log_msg(sformatf("%s\n\n", save_in.c_str())); + } + dash = (char *) free_check_null(dash); + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +equal(LDBLE a, LDBLE b, LDBLE eps) +/* ---------------------------------------------------------------------- */ +{ +/* + * Checks equality between two LDBLE precision numbers + */ + if (fabs(a - b) <= eps) + return (TRUE); + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +void * Phreeqc:: +free_check_null(void *ptr) +/* ---------------------------------------------------------------------- */ +{ + if (ptr != NULL) + { + PHRQ_free(ptr); + } + return (NULL); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_token(char **eqnaddr, char *string, LDBLE * l_z, int *l) +/* ---------------------------------------------------------------------- */ +/* + * Function finds next species in equation, coefficient has already + * been removed. Also determines charge on the species. + * + * Arguments: + * *eqnaddr input, pointer to position in eqn to start parsing + * output, pointer to a pointer to next position in eqn to start + * parsing. + * *string input pointer to place to store token + * *l_z charge on token + * *l length of token + * + * Returns: + * ERROR, + * OK. + */ +{ + int i, j; + int ltoken, lcharge; + char c; + char *ptr, *ptr1, *rest; + char charge[MAX_LENGTH]; + + rest = *eqnaddr; + ptr = *eqnaddr; + i = 0; +/* + * Find end of token or begining of charge + */ + while (((c = *ptr) != '+') && (c != '-') && (c != '=') && (c != '\0')) + { + string[i++] = c; + if (c == '[') + { + ptr++; + while ((c = *ptr) != ']') + { + if (c == '\0') + { + error_string = sformatf( + "No final bracket \"]\" for element name, %s.", + string); + error_msg(error_string, CONTINUE); + return (ERROR); + } + string[i++] = c; + if (i >= MAX_LENGTH) + { + output_msg(sformatf( + "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", + MAX_LENGTH, string)); + return (ERROR); + } + ptr++; + } + string[i++] = c; + } + + /* check for overflow of space */ + if (i >= MAX_LENGTH) + { + output_msg(sformatf( + "Species name greater than MAX_LENGTH (%d) characters.\n%s\n", + MAX_LENGTH, string)); + return (ERROR); + } + ptr++; + } + string[i] = '\0'; + ltoken = i; +/* + * Check for an empty string + */ + if (i == 0) + { + error_string = sformatf( "NULL string detected in get_token, %s.", rest); + error_msg(error_string, CONTINUE); + return (ERROR); + } +/* + * End of token is = or \0, charge is zero + */ + if (c == '=' || c == '\0') + { + *eqnaddr = ptr; + lcharge = 0; + *l_z = 0.0; + } + else + { +/* + * Copy characters into charge until next species or end is detected + */ + j = 0; + ptr1 = ptr; + while ((isalpha((int) (c = *ptr1)) == FALSE) && + (c != '(') && + (c != ')') && + (c != ']') && (c != '[') && (c != '=') && (c != '\0')) + { + charge[j++] = c; + /* error if no more space */ + if (j >= MAX_LENGTH) + { + error_msg + ("The charge on a species has exceeded MAX_LENGTH characters.", + CONTINUE); + return (ERROR); + } + ptr1++; + } +/* + * Go back to last + or - if not end of side, + * everything before the last + or - in charge is part of the charge + */ + if ((c != '=') && (c != '\0')) + { + while (((c = *ptr1) != '+') && (c != '-')) + { + j--; + ptr1--; + } + } + charge[j] = '\0'; + lcharge = j; + *eqnaddr = ptr1; +/* + * Charge has been written, now need to check if charge has legal format + */ + if (get_charge(charge, l_z) == OK) + { + strcat(string, charge); + } + else + { + return (ERROR); + } + } + *l = ltoken + lcharge; + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +isamong(char c, const char *s_l) +/* ---------------------------------------------------------------------- */ +/* + * Function checks if c is among the characters in the string s + * + * Arguments: + * c input, character to check + * *s string of characters + * + * Returns: + * TRUE if c is in set, + * FALSE if c in not in set. + */ +{ + int i; + + for (i = 0; s_l[i] != '\0'; i++) + { + if (c == s_l[i]) + { + return (TRUE); + } + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +islegit(const char c) +/* ---------------------------------------------------------------------- */ +/* + * Function checks for legal characters for chemical equations + * + * Argument: + * c input, character to check + * + * Returns: + * TRUE if c is in set, + * FALSE if c in not in set. + */ +{ + if (isalpha((int) c) || isdigit((int) c) || isamong(c, "+-=().:_[]")) + { + return (TRUE); + } + return (FALSE); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +malloc_error(void) +/* ---------------------------------------------------------------------- */ +{ + error_msg("NULL pointer returned from malloc or realloc.", CONTINUE); + error_msg("Program terminating.", STOP); + return; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +parse_couple(char *token) +/* ---------------------------------------------------------------------- */ +{ +/* + * Parse couple puts redox couples in standard form + * "+" is removed and couples are rewritten in sort + * order. + */ + int e1, e2, p1, p2; + char *ptr; + char elt1[MAX_LENGTH], elt2[MAX_LENGTH], paren1[MAX_LENGTH], + paren2[MAX_LENGTH]; + + if (strcmp_nocase_arg1(token, "pe") == 0) + { + str_tolower(token); + return (OK); + } + while (replace("+", "", token) == TRUE); + ptr = token; + get_elt(&ptr, elt1, &e1); + if (*ptr != '(') + { + error_string = sformatf( "Element name must be followed by " + "parentheses in redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return (ERROR); + } + paren_count = 1; + paren1[0] = '('; + p1 = 1; + while (ptr != '\0') + { + ptr++; + if (*ptr == '/' || *ptr == '\0') + { + error_string = sformatf( + "End of line or " "/" + " encountered before end of parentheses, %s.", token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + paren1[p1++] = *ptr; + if (*ptr == '(') + paren_count++; + if (*ptr == ')') + paren_count--; + if (paren_count == 0) + break; + } + paren1[p1] = '\0'; + ptr++; + if (*ptr != '/') + { + error_string = sformatf( " " "/" " must follow parentheses " + "ending first half of redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return (ERROR); + } + ptr++; + get_elt(&ptr, elt2, &e2); + if (strcmp(elt1, elt2) != 0) + { + error_string = sformatf( "Redox couple must be two redox states " + "of the same element, %s.", token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + if (*ptr != '(') + { + error_string = sformatf( "Element name must be followed by " + "parentheses in redox couple, %s.", token); + error_msg(error_string, CONTINUE); + parse_error++; + return (ERROR); + } + paren2[0] = '('; + paren_count = 1; + p2 = 1; + while (*ptr != '\0') + { + ptr++; + if (*ptr == '/' || *ptr == '\0') + { + error_string = sformatf( "End of line or " "/" " encountered" + " before end of parentheses, %s.", token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + + paren2[p2++] = *ptr; + if (*ptr == '(') + paren_count++; + if (*ptr == ')') + paren_count--; + if (paren_count == 0) + break; + } + paren2[p2] = '\0'; + if (strcmp(paren1, paren2) < 0) + { + strcpy(token, elt1); + strcat(token, paren1); + strcat(token, "/"); + strcat(token, elt2); + strcat(token, paren2); + } + else if (strcmp(paren1, paren2) > 0) + { + strcpy(token, elt2); + strcat(token, paren2); + strcat(token, "/"); + strcat(token, elt1); + strcat(token, paren1); + } + else + { + error_string = sformatf( "Both parts of redox couple are the same, %s.", + token); + error_msg(error_string, CONTINUE); + return (ERROR); + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_centered(const char *string) +/* ---------------------------------------------------------------------- */ +{ + int i, l, l1, l2; + char token[MAX_LENGTH]; + +#ifdef PHREEQ98 + if ((CreateToC == TRUE) && (AutoLoadOutputFile == TRUE)) + AddToCEntry((char *) string, 4, outputlinenr); +#endif + l = (int) strlen(string); + l1 = (79 - l) / 2; + l2 = 79 - l - l1; + for (i = 0; i < l1; i++) + token[i] = '-'; + token[i] = '\0'; + strcat(token, string); + for (i = 0; i < l2; i++) + token[i + l1 + l] = '-'; + token[79] = '\0'; + output_msg(sformatf("%s\n\n", token)); + return (OK); +} +bool Phreeqc:: +replace(const char *str1, const char *str2, std::string & str) +{ + size_t pos = str.find(str1); + if (pos != std::string::npos) + { + size_t l = strlen(str1); + str.replace(pos, l, str2); + return true; + } + return false; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +replace(const char *str1, const char *str2, char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function replaces str1 with str2 in str + * + * Arguments: + * str1 search str for str1 + * str2 replace str1 if str1 found in str + * str string to be searched + * + * Returns + * TRUE if string was replaced + * FALSE if string was not replaced + */ + int l, l1, l2; + char *ptr_start; + + ptr_start = strstr(str, str1); +/* + * Str1 not found, return + */ + if (ptr_start == NULL) + return (FALSE); +/* + * Str1 found, replace Str1 with Str2 + */ + l = (int) strlen(str); + l1 = (int) strlen(str1); + l2 = (int) strlen(str2); +/* + * Make gap in str long enough for str2 + */ + /* The plus one includes the terminating NULL */ + memmove(ptr_start + l2, ptr_start + l1, l - (ptr_start - str + l1) + 1); +/* + * Copy str2 into str + */ + memcpy(ptr_start, str2, l2); + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +space(void **ptr, int i, int *max, int struct_size) +/* ---------------------------------------------------------------------- */ +{ +/* + * Routine has 4 functions, allocate space, reallocate space, test to + * determine whether space is available, and free space. + * + * Arguments: + * ptr pointer to malloced space + * i value for test + * i = INIT, allocates space + * i >= 0 && i < max, space is available, return + * i >= max, reallocate space + * i = FREE, free space. + * max maximum value for i with available space + * struct size size of structure to be allocated + */ +/* + * Return if space exists + */ + if ((i >= 0) && (i + 1 < *max)) + { + return; + } +/* + * Realloc space + */ + if (i + 1 >= *max) + { + if (*max > 1000) + { + *max += 1000; + } + else + { + *max *= 2; + } + if (i + 1 > *max) + *max = i + 1; + *ptr = PHRQ_realloc(*ptr, (size_t) (*max) * struct_size); + if (*ptr == NULL) + malloc_error(); + return; + } +/* + * Allocate space + */ + if (i == INIT) + { +/* free(*ptr); */ + *ptr = PHRQ_malloc((size_t) (*max) * struct_size); + if (*ptr == NULL) + malloc_error(); + return; + } +/* + * Free space + */ +/* + if ( i == FREE ) { + free(*ptr); + return; + } + */ +/* + * Error + */ + error_msg("Illegal argument to function space.", CONTINUE); + error_msg("Program terminating.", STOP); + return; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +squeeze_white(char *s_l) +/* ---------------------------------------------------------------------- */ +/* + * Delete all white space from string s + * + * Argument: + * *s_l input, character string, possibly containing white space + * output, character string with all white space removed + * + * Return: void + */ +{ + int i, j; + + for (i = j = 0; s_l[i] != '\0'; i++) + { + if (!isspace((int) s_l[i])) + s_l[j++] = s_l[i]; + } + s_l[j] = '\0'; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +str_tolower(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Replaces string, str, with same string, lower case + */ + char *ptr; + ptr = str; + while (*ptr != '\0') + { + *ptr = (char) tolower(*ptr); + ptr++; + } +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +str_toupper(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Replaces string, str, with same string, lower case + */ + char *ptr; + ptr = str; + while (*ptr != '\0') + { + *ptr = (char) toupper(*ptr); + ptr++; + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +strcmp_nocase(const char *str1, const char *str2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare two strings disregarding case + */ + int c1, c2; + while ((c1 = tolower(*str1++)) == (c2 = tolower(*str2++))) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +strcmp_nocase_arg1(const char *str1, const char *str2) +/* ---------------------------------------------------------------------- */ +{ +/* + * Compare two strings disregarding case + */ + int c1, c2; + while ((c1 = tolower(*str1++)) == (c2 = *str2++)) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); +} + +/* ---------------------------------------------------------------------- */ +char * Phreeqc:: +string_duplicate(const char *token) +/* ---------------------------------------------------------------------- */ +{ + int l; + char *str; + + if (token == NULL) + return NULL; + l = (int) strlen(token); + str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); + if (str == NULL) + malloc_error(); + strcpy(str, token); + return (str); +} +/* ---------------------------------------------------------------------- */ +const char * Phreeqc:: +string_hsave(const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save character string str + * + * Arguments: + * str input string to save. + * + * Returns: + * starting address of saved string (str) + */ + std::map::const_iterator it; + it = strings_map.find(str); + if (it != strings_map.end()) + { + return (it->second->c_str()); + } + + std::string *stdstr = new std::string(str); + strings_map[*stdstr] = stdstr; + return(stdstr->c_str()); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +strings_map_clear() +/* ---------------------------------------------------------------------- */ +{ +/* + * Save character string str + * + * Arguments: + * str input string to save. + * + * Returns: + * starting address of saved string (str) + */ + std::map::iterator it; + for (it = strings_map.begin(); it != strings_map.end(); it++) + { + delete it->second; + } + strings_map.clear(); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +under(LDBLE xval) +/* ---------------------------------------------------------------------- */ +{ +/* + * Exponentiate a number, x, but censor large and small numbers + * log values less than MIN_LM are set to 0 + * log values greater than MAX_LM are set to 10**MAX_LM + */ +/* if (xval < MIN_LM) { */ + if (xval < -40.) + { + return (0.0); + } +/* if (xval > MAX_LM) { */ + if (xval > 3.) + { + return (1.0e3); +/* return ( pow (10.0, MAX_LM));*/ + } + return (pow ((LDBLE) 10.0, xval)); +/* return (exp(xval * LOG_10)) */; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +backspace_screen(int spaces) +/* ---------------------------------------------------------------------- */ +{ + int i; + char token[MAX_LENGTH]; + for (i = 0; i < spaces; i++) + { + token[i] = '\b'; + } + token[i] = '\0'; + screen_msg(sformatf("%s", token)); + return (OK); +} + +#ifndef PHREEQCI_GUI +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +status(int count, const char *str) +/* ---------------------------------------------------------------------- */ +{ + static int spinner; + char sim_str[20]; + char state_str[45]; + char spin_str[2]; + float t2; +/* char all[MAX_LENGTH]; */ +#ifdef PHREEQ98 + if (ProcessMessages) + ApplicationProcessMessages(); + if (stop_calculations == TRUE) + error_msg("Execution canceled by user.", STOP); +#endif + + if (pr.status == FALSE || phast == TRUE) + return (OK); + t2 = (float) clock(); + if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) + return (OK); + else + status_timer = t2; + sprintf(sim_str, "Simulation %d.", simulation); + sprintf(state_str, " "); + sprintf(spin_str, " "); + + if (state == INITIALIZE) + { + screen_msg(sformatf("\n%-80s", "Initializing...")); + + status_on = TRUE; + return (OK); + } +/* + * If str is defined print it + */ + if (str != NULL) + { + if (status_on == TRUE) + { + backspace_screen(80); + } + else + { + status_on = TRUE; + } +#ifdef DOS + backspace_screen(80); + /* if (state == TRANSPORT ) backspace_screen(80); */ + screen_msg(sformatf("%-79s", str)); +#else + screen_msg(sformatf("%-80s", str)); +#endif + } + else if (state != TRANSPORT && state != PHAST) + { + if (state == INITIAL_SOLUTION) + { + sprintf(state_str, "Initial solution %d.", + use.Get_solution_ptr()->n_user); + } + else if (state == INITIAL_EXCHANGE) + { + //sprintf(state_str, "Initial exchange %d.", + // (cxxExchange *) use.Get_exchange_ptr()->n_user); + sprintf(state_str, "Initial exchange %d.", + ((cxxExchange *) (use.Get_exchange_ptr()))->Get_n_user()); + } + else if (state == INITIAL_SURFACE) + { + sprintf(state_str, "Initial surface %d.", + use.Get_surface_ptr()->n_user); + } + else if (state == INVERSE) + { + sprintf(state_str, "Inverse %d. Models = %d.", + use.Get_inverse_ptr()->n_user, count); + } + else if (state == REACTION) + { + if (use.Get_kinetics_in() == TRUE) + { + sprintf(state_str, "Kinetic step %d.", reaction_step); + } + else + { + sprintf(state_str, "Reaction step %d.", reaction_step); + } + } + else if (state == ADVECTION || state == TRANSPORT) + { + if (state == ADVECTION) + { + sprintf(state_str, "Advection, shift %d.", advection_step); + } + else if (state == TRANSPORT) + { + sprintf(state_str, "Transport, shift %d.", transport_step); + } + spinner++; + if (spinner == 1) + { + spin_str[0] = '/'; + } + else if (spinner == 2) + { + spin_str[0] = '-'; + } + else + { + spin_str[0] = '\\'; + spinner = 0; + } + } + if (status_on == TRUE) + { + backspace_screen(80); + } + else + { + status_on = TRUE; + } + if (use.Get_kinetics_in() == TRUE) + { +#ifdef DOS + backspace_screen(80); + screen_msg(sformatf("%-15s%-27s%37s", sim_str, state_str, + " ")); +#else + screen_msg(sformatf("%-15s%-27s%38s", sim_str, state_str, + " ")); +#endif + + } + else + { +#ifdef DOS + backspace_screen(80); + screen_msg(sformatf("%-15s%-27s%1s%36s", sim_str, + state_str, spin_str, " ")); +#else + screen_msg(sformatf("%-15s%-27s%1s%37s", sim_str, + state_str, spin_str, " ")); +#endif + } + } + return (OK); +} +#endif /*PHREEQCI_GUI */ +/* +** Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson. +** Coded into C, with minor code improvements, and with hsearch(3) interface, +** by ejp@ausmelb.oz, Jul 26, 1988: 13:16; +** also, hcreate/hdestroy routines added to simulate hsearch(3). +** +** These routines simulate hsearch(3) and family, with the important +** difference that the hash table is dynamic - can grow indefinitely +** beyond its original size (as supplied to hcreate()). +** +** Performance appears to be comparable to that of hsearch(3). +** The 'source-code' options referred to in hsearch(3)'s 'man' page +** are not implemented; otherwise functionality is identical. +** +** Compilation controls: +** DEBUG controls some informative traces, mainly for debugging. +** HASH_STATISTICS causes HashAccesses and HashCollisions to be maintained; +** when combined with DEBUG, these are displayed by hdestroy(). +** +** Problems & fixes to ejp@ausmelb.oz. WARNING: relies on pre-processor +** concatenation property, in probably unnecessary code 'optimisation'. +** Esmond Pitt, Austec (Asia/Pacific) Ltd +** ...!uunet.UU.NET!munnari!ausmelb!ejp,ejp@ausmelb.oz +*/ + +# include + +/* +** Fast arithmetic, relying on powers of 2, +** and on pre-processor concatenation property +*/ + +/* rewrote to remove MUL and DIV */ +# define MOD(x,y) ((x) & ((y)-1)) + +/* +** Local data +*/ + +#ifdef HASH_STATISTICS + long HashAccesses, HashCollisions; +#endif + +/* +** Code +*/ + +int Phreeqc:: +hcreate_multi(unsigned Count, HashTable ** HashTable_ptr) +{ + int i; + HashTable *Table; + /* + ** Adjust Count to be nearest higher power of 2, + ** minimum SegmentSize, then convert into segments. + */ + i = SegmentSize; + while (i < (int) Count) + i <<= 1; +/* Count = DIV(i,SegmentSize); */ + Count = ((i) >> (SegmentSizeShift)); + + Table = (HashTable *) PHRQ_calloc(sizeof(HashTable), 1); + *HashTable_ptr = Table; + + if (Table == NULL) + return (0); + /* + ** resets are redundant - done by calloc(3) + ** + Table->SegmentCount = Table->p = Table->KeyCount = 0; + */ + /* + ** Allocate initial 'i' segments of buckets + */ + for (i = 0; i < (int) Count; i++) + { + Table->Directory[i] = + (Segment *) PHRQ_calloc(sizeof(Segment), SegmentSize); + if (Table->Directory[i] == NULL) + { + hdestroy_multi(Table); + return (0); + } + Table->SegmentCount++; + } +/* Table->maxp = MUL(Count,SegmentSize); */ + Table->maxp = (short) ((Count) << (SegmentSizeShift)); + Table->MinLoadFactor = 1; + Table->MaxLoadFactor = DefaultMaxLoadFactor; +#ifdef HASH_STATISTICS + HashAccesses = HashCollisions = 0; +#endif + return (1); +} + +void Phreeqc:: +hdestroy_multi(HashTable * Table) +{ + int i, j; + Segment *seg; + Element *p, *q; + + if (Table != NULL) + { + for (i = 0; i < Table->SegmentCount; i++) + { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) + { + for (j = 0; j < SegmentSize; j++) + { + p = seg[j]; + while (p != NULL) + { + q = p->Next; + PHRQ_free((void *) p); + p = q; + } + } + PHRQ_free(Table->Directory[i]); + } + } + PHRQ_free(Table); + /* Table = NULL; */ + } +} + +ENTRY * Phreeqc:: +hsearch_multi(HashTable * Table, ENTRY item, ACTION action) +/* ACTION FIND/ENTER */ +{ + Address h; + Segment *CurrentSegment; + int SegmentIndex; + int SegmentDir; + Segment *p, q; + + assert(Table != NULL); /* Kinder really than return(NULL); */ +#ifdef HASH_STATISTICS + HashAccesses++; +#endif + h = Hash_multi(Table, item.key); +/* SegmentDir = DIV(h,SegmentSize); */ + SegmentDir = ((h) >> (SegmentSizeShift)); + SegmentIndex = MOD(h, SegmentSize); + /* + ** valid segment ensured by Hash() + */ + CurrentSegment = Table->Directory[SegmentDir]; + assert(CurrentSegment != NULL); /* bad failure if tripped */ + p = &CurrentSegment[SegmentIndex]; + q = *p; + /* + ** Follow collision chain + */ + while (q != NULL && strcmp(q->Key, item.key)) + { + p = &q->Next; + q = *p; +#ifdef HASH_STATISTICS + HashCollisions++; +#endif + } + if (q != NULL /* found */ + || action == FIND /* not found, search only */ + ) + { + return ((ENTRY *) q); + } + else if ((q = (Element *) PHRQ_calloc(sizeof(Element), 1)) == NULL) + { + malloc_error(); + } + *p = q; /* link into chain */ + /* + ** Initialize new element + */ + q->Key = item.key; + q->Data = (char *) item.data; + /* + ** cleared by calloc(3) + q->Next = NULL; + */ + /* + ** Table over-full? + */ +/* if (++Table->KeyCount / MUL(Table->SegmentCount,SegmentSize) > Table->MaxLoadFactor) */ + if (++Table->KeyCount / ((Table->SegmentCount) << (SegmentSizeShift)) > + Table->MaxLoadFactor) + ExpandTable_multi(Table); /* doesn't affect q */ + return ((ENTRY *) q); +} + +/* +** Internal routines +*/ + + Address Phreeqc:: +Hash_multi(HashTable * Table, const char *Key) +{ + Address h, address; + register unsigned char *k = (unsigned char *) Key; + + h = 0; + /* + ** Convert string to integer + */ + while (*k) + h = h * Prime1 ^ (*k++ - ' '); + h %= Prime2; + address = MOD(h, Table->maxp); + if (address < (unsigned long) Table->p) + address = MOD(h, (Table->maxp << 1)); /* h % (2*Table->maxp) */ + return (address); +} + +void Phreeqc:: +ExpandTable_multi(HashTable * Table) +{ + Address NewAddress; + int OldSegmentIndex, NewSegmentIndex; + int OldSegmentDir, NewSegmentDir; + Segment *OldSegment, *NewSegment; + Element *Current, **Previous, **LastOfNew; + +/* if (Table->maxp + Table->p < MUL(DirectorySize,SegmentSize)) */ + if (Table->maxp + Table->p < ((DirectorySize) << (SegmentSizeShift))) + { + /* + ** Locate the bucket to be split + */ +/* OldSegmentDir = DIV(Table->p,SegmentSize); */ + OldSegmentDir = ((Table->p) >> (SegmentSizeShift)); + OldSegment = Table->Directory[OldSegmentDir]; + OldSegmentIndex = MOD(Table->p, SegmentSize); + /* + ** Expand address space; if necessary create a new segment + */ + NewAddress = Table->maxp + Table->p; +/* NewSegmentDir = DIV(NewAddress,SegmentSize); */ + NewSegmentDir = ((NewAddress) >> (SegmentSizeShift)); + NewSegmentIndex = MOD(NewAddress, SegmentSize); + if (NewSegmentIndex == 0) + { + Table->Directory[NewSegmentDir] = + (Segment *) PHRQ_calloc(sizeof(Segment), SegmentSize); + if (Table->Directory[NewSegmentDir] == NULL) + { + malloc_error(); + } + } + NewSegment = Table->Directory[NewSegmentDir]; + /* + ** Adjust state variables + */ + Table->p++; + if (Table->p == Table->maxp) + { + Table->maxp <<= 1; /* Table->maxp *= 2 */ + Table->p = 0; + } + Table->SegmentCount++; + /* + ** Relocate records to the new bucket + */ + Previous = &OldSegment[OldSegmentIndex]; + Current = *Previous; + LastOfNew = &NewSegment[NewSegmentIndex]; + *LastOfNew = NULL; + while (Current != NULL) + { + if (Hash_multi(Table, Current->Key) == NewAddress) + { + /* + ** Attach it to the end of the new chain + */ + *LastOfNew = Current; + /* + ** Remove it from old chain + */ + *Previous = Current->Next; + LastOfNew = &Current->Next; + Current = Current->Next; + *LastOfNew = NULL; + } + else + { + /* + ** leave it on the old chain + */ + Previous = &Current->Next; + Current = Current->Next; + } + } + } +} + + +void Phreeqc:: +free_hash_strings(HashTable * Table) +{ + int i, j; + Segment *seg; + Element *p, *q; + + if (Table != NULL) + { + for (i = 0; i < Table->SegmentCount; i++) + { + /* test probably unnecessary */ + if ((seg = Table->Directory[i]) != NULL) + { + for (j = 0; j < SegmentSize; j++) + { + p = seg[j]; + while (p != NULL) + { + q = p->Next; + p->Data = (char *) free_check_null((void *) p->Data); + p = q; + } + } + } + } + } +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +string_trim(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from left and right of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, start, end, length; + char *ptr_start; + + l = (int) strlen(str); + /* + * leading whitespace + */ + for (i = 0; i < l; i++) + { + if (isspace((int) str[i])) + continue; + break; + } + if (i == l) + return (EMPTY); + start = i; + ptr_start = &(str[i]); + /* + * trailing whitespace + */ + for (i = l - 1; i >= 0; i--) + { + if (isspace((int) str[i])) + continue; + break; + } + end = i; + if (start == 0 && end == l) + return (FALSE); + length = end - start + 1; + memmove((void *) str, (void *) ptr_start, (size_t) length); + str[length] = '\0'; + + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +string_trim_right(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from right of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, end, length; + + l = (int) strlen(str); + for (i = l - 1; i >= 0; i--) + { + if (isspace((int) str[i])) + continue; + break; + } + end = i; + length = end + 1; + str[length] = '\0'; + if (end == 0) + return (EMPTY); + if (end == l) + return (FALSE); + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +string_trim_left(char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function trims white space from left of string + * + * Arguments: + * str string to trime + * + * Returns + * TRUE if string was changed + * FALSE if string was not changed + * EMPTY if string is all whitespace + */ + int i, l, start, end, length; + char *ptr_start; + + l = (int) strlen(str); + /* + * leading whitespace + */ + for (i = 0; i < l; i++) + { + if (isspace((int) str[i])) + continue; + break; + } + if (i == l) + return (EMPTY); + start = i; + ptr_start = &(str[i]); + end = l; + if (start == 0 && end == l) + return (FALSE); + length = end - start + 1; + memmove((void *) str, (void *) ptr_start, (size_t) length); + str[length] = '\0'; + + return (TRUE); +} + +/* ---------------------------------------------------------------------- */ +char * Phreeqc:: +string_pad(const char *str, int i) +/* ---------------------------------------------------------------------- */ +{ +/* + * Function returns new string padded to width i + * or returns str if longer + * Arguments: + * str string to pad + * + * Returns + * new string of with i + */ + int j, l, max; + char *str_ptr; + + l = (int) strlen(str); + max = l; + if (l < i) + max = i; + str_ptr = (char *) PHRQ_malloc((size_t) ((max + 1) * sizeof(char))); + if (str_ptr == NULL) + malloc_error(); + strcpy(str_ptr, str); + if (i > l) + { + for (j = l; j < i; j++) + { + str_ptr[j] = ' '; + } + str_ptr[i] = '\0'; + } + return (str_ptr); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +zero_double(LDBLE * target, int n) +/* ---------------------------------------------------------------------- */ +{ + int i; + + if (n > zeros_max) + { + zeros = (LDBLE *) PHRQ_realloc(zeros, (size_t) (n * sizeof(LDBLE))); + if (zeros == NULL) + malloc_error(); + for (i = zeros_max; i < n; i++) + { + zeros[i] = 0.0; + } + zeros_max = n; + } + memcpy((void *) target, (void *) zeros, (size_t) (n * sizeof(LDBLE))); + return; +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_input_errors() +/* ---------------------------------------------------------------------- */ +{ + if (input_error == 0) + { + return phrq_io->Get_io_error_count(); + } + return input_error; +} From 6bd23b9b8bd92245c4a53b84502709dabb8eaeed Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 12 Jan 2012 21:57:35 +0000 Subject: [PATCH 0422/1077] Rename item from http://internalbrr.cr.usgs.gov/svn_GW/phreeqcpp/branches/ErrorHandling/src/rename_cpp to http://internalbrr.cr.usgs.gov/svn_GW/phreeqcpp/branches/ErrorHandling/src/phreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6064 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- {rename_cpp => phreeqc}/Form1.h | 0 {rename_cpp => phreeqc}/Form1.resX | 0 {rename_cpp => phreeqc}/Makefile | 0 {rename_cpp => phreeqc}/NA.h | 0 {rename_cpp => phreeqc}/PHRQ_io_output.cpp | 0 {rename_cpp => phreeqc}/ZedGraph.dll | Bin {rename_cpp => phreeqc}/advection.cpp | 0 {rename_cpp => phreeqc}/basicsubs.cpp | 0 {rename_cpp => phreeqc}/chart_icon.gif | Bin {rename_cpp => phreeqc}/cl1.cpp | 0 {rename_cpp => phreeqc}/cl1mp.cpp | 0 {rename_cpp => phreeqc}/cvdense.cpp | 0 {rename_cpp => phreeqc}/cvdense.h | 0 {rename_cpp => phreeqc}/cvode.cpp | 0 {rename_cpp => phreeqc}/cvode.h | 0 {rename_cpp => phreeqc}/dense.cpp | 0 {rename_cpp => phreeqc}/dense.h | 0 {rename_cpp => phreeqc}/distribution.checklist | 0 {rename_cpp => phreeqc}/distribution.mk | 0 {rename_cpp => phreeqc}/dw.cpp | 0 {rename_cpp => phreeqc}/gases.cpp | 0 {rename_cpp => phreeqc}/global_structures.h | 0 {rename_cpp => phreeqc}/input.cpp | 0 {rename_cpp => phreeqc}/integrate.cpp | 0 {rename_cpp => phreeqc}/inverse.cpp | 0 {rename_cpp => phreeqc}/isotopes.cpp | 0 {rename_cpp => phreeqc}/kinetics.cpp | 0 {rename_cpp => phreeqc}/mainsubs.cpp | 0 {rename_cpp => phreeqc}/model.cpp | 0 {rename_cpp => phreeqc}/newiso.dat | 0 {rename_cpp => phreeqc}/nvector.cpp | 0 {rename_cpp => phreeqc}/nvector.h | 0 {rename_cpp => phreeqc}/nvector_serial.cpp | 0 {rename_cpp => phreeqc}/nvector_serial.h | 0 {rename_cpp => phreeqc}/parse.cpp | 0 {rename_cpp => phreeqc}/phqalloc.cpp | 0 {rename_cpp => phreeqc}/phqalloc.h | 0 {rename_cpp => phreeqc}/phreeqc.rev | 0 {rename_cpp => phreeqc}/phreex.ico | Bin {rename_cpp => phreeqc}/phrqtype.h | 0 {rename_cpp => phreeqc}/pitzer.cpp | 0 {rename_cpp => phreeqc}/pitzer_structures.cpp | 0 {rename_cpp => phreeqc}/prep.cpp | 0 {rename_cpp => phreeqc}/print.cpp | 0 {rename_cpp => phreeqc}/read.cpp | 0 {rename_cpp => phreeqc}/readtr.cpp | 0 {rename_cpp => phreeqc}/revisions | 0 {rename_cpp => phreeqc}/sit.cpp | 0 {rename_cpp => phreeqc}/smalldense.cpp | 0 {rename_cpp => phreeqc}/smalldense.h | 0 {rename_cpp => phreeqc}/spread.cpp | 0 {rename_cpp => phreeqc}/step.cpp | 0 {rename_cpp => phreeqc}/structures.cpp | 0 {rename_cpp => phreeqc}/sundialsmath.cpp | 0 {rename_cpp => phreeqc}/sundialsmath.h | 0 {rename_cpp => phreeqc}/sundialstypes.h | 0 {rename_cpp => phreeqc}/tally.cpp | 0 {rename_cpp => phreeqc}/tidy.cpp | 0 {rename_cpp => phreeqc}/transport.cpp | 0 {rename_cpp => phreeqc}/utilities.cpp | 0 60 files changed, 0 insertions(+), 0 deletions(-) rename {rename_cpp => phreeqc}/Form1.h (100%) rename {rename_cpp => phreeqc}/Form1.resX (100%) rename {rename_cpp => phreeqc}/Makefile (100%) rename {rename_cpp => phreeqc}/NA.h (100%) rename {rename_cpp => phreeqc}/PHRQ_io_output.cpp (100%) rename {rename_cpp => phreeqc}/ZedGraph.dll (100%) rename {rename_cpp => phreeqc}/advection.cpp (100%) rename {rename_cpp => phreeqc}/basicsubs.cpp (100%) rename {rename_cpp => phreeqc}/chart_icon.gif (100%) rename {rename_cpp => phreeqc}/cl1.cpp (100%) rename {rename_cpp => phreeqc}/cl1mp.cpp (100%) rename {rename_cpp => phreeqc}/cvdense.cpp (100%) rename {rename_cpp => phreeqc}/cvdense.h (100%) rename {rename_cpp => phreeqc}/cvode.cpp (100%) rename {rename_cpp => phreeqc}/cvode.h (100%) rename {rename_cpp => phreeqc}/dense.cpp (100%) rename {rename_cpp => phreeqc}/dense.h (100%) rename {rename_cpp => phreeqc}/distribution.checklist (100%) rename {rename_cpp => phreeqc}/distribution.mk (100%) rename {rename_cpp => phreeqc}/dw.cpp (100%) rename {rename_cpp => phreeqc}/gases.cpp (100%) rename {rename_cpp => phreeqc}/global_structures.h (100%) rename {rename_cpp => phreeqc}/input.cpp (100%) rename {rename_cpp => phreeqc}/integrate.cpp (100%) rename {rename_cpp => phreeqc}/inverse.cpp (100%) rename {rename_cpp => phreeqc}/isotopes.cpp (100%) rename {rename_cpp => phreeqc}/kinetics.cpp (100%) rename {rename_cpp => phreeqc}/mainsubs.cpp (100%) rename {rename_cpp => phreeqc}/model.cpp (100%) rename {rename_cpp => phreeqc}/newiso.dat (100%) rename {rename_cpp => phreeqc}/nvector.cpp (100%) rename {rename_cpp => phreeqc}/nvector.h (100%) rename {rename_cpp => phreeqc}/nvector_serial.cpp (100%) rename {rename_cpp => phreeqc}/nvector_serial.h (100%) rename {rename_cpp => phreeqc}/parse.cpp (100%) rename {rename_cpp => phreeqc}/phqalloc.cpp (100%) rename {rename_cpp => phreeqc}/phqalloc.h (100%) rename {rename_cpp => phreeqc}/phreeqc.rev (100%) rename {rename_cpp => phreeqc}/phreex.ico (100%) rename {rename_cpp => phreeqc}/phrqtype.h (100%) rename {rename_cpp => phreeqc}/pitzer.cpp (100%) rename {rename_cpp => phreeqc}/pitzer_structures.cpp (100%) rename {rename_cpp => phreeqc}/prep.cpp (100%) rename {rename_cpp => phreeqc}/print.cpp (100%) rename {rename_cpp => phreeqc}/read.cpp (100%) rename {rename_cpp => phreeqc}/readtr.cpp (100%) rename {rename_cpp => phreeqc}/revisions (100%) rename {rename_cpp => phreeqc}/sit.cpp (100%) rename {rename_cpp => phreeqc}/smalldense.cpp (100%) rename {rename_cpp => phreeqc}/smalldense.h (100%) rename {rename_cpp => phreeqc}/spread.cpp (100%) rename {rename_cpp => phreeqc}/step.cpp (100%) rename {rename_cpp => phreeqc}/structures.cpp (100%) rename {rename_cpp => phreeqc}/sundialsmath.cpp (100%) rename {rename_cpp => phreeqc}/sundialsmath.h (100%) rename {rename_cpp => phreeqc}/sundialstypes.h (100%) rename {rename_cpp => phreeqc}/tally.cpp (100%) rename {rename_cpp => phreeqc}/tidy.cpp (100%) rename {rename_cpp => phreeqc}/transport.cpp (100%) rename {rename_cpp => phreeqc}/utilities.cpp (100%) diff --git a/rename_cpp/Form1.h b/phreeqc/Form1.h similarity index 100% rename from rename_cpp/Form1.h rename to phreeqc/Form1.h diff --git a/rename_cpp/Form1.resX b/phreeqc/Form1.resX similarity index 100% rename from rename_cpp/Form1.resX rename to phreeqc/Form1.resX diff --git a/rename_cpp/Makefile b/phreeqc/Makefile similarity index 100% rename from rename_cpp/Makefile rename to phreeqc/Makefile diff --git a/rename_cpp/NA.h b/phreeqc/NA.h similarity index 100% rename from rename_cpp/NA.h rename to phreeqc/NA.h diff --git a/rename_cpp/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp similarity index 100% rename from rename_cpp/PHRQ_io_output.cpp rename to phreeqc/PHRQ_io_output.cpp diff --git a/rename_cpp/ZedGraph.dll b/phreeqc/ZedGraph.dll similarity index 100% rename from rename_cpp/ZedGraph.dll rename to phreeqc/ZedGraph.dll diff --git a/rename_cpp/advection.cpp b/phreeqc/advection.cpp similarity index 100% rename from rename_cpp/advection.cpp rename to phreeqc/advection.cpp diff --git a/rename_cpp/basicsubs.cpp b/phreeqc/basicsubs.cpp similarity index 100% rename from rename_cpp/basicsubs.cpp rename to phreeqc/basicsubs.cpp diff --git a/rename_cpp/chart_icon.gif b/phreeqc/chart_icon.gif similarity index 100% rename from rename_cpp/chart_icon.gif rename to phreeqc/chart_icon.gif diff --git a/rename_cpp/cl1.cpp b/phreeqc/cl1.cpp similarity index 100% rename from rename_cpp/cl1.cpp rename to phreeqc/cl1.cpp diff --git a/rename_cpp/cl1mp.cpp b/phreeqc/cl1mp.cpp similarity index 100% rename from rename_cpp/cl1mp.cpp rename to phreeqc/cl1mp.cpp diff --git a/rename_cpp/cvdense.cpp b/phreeqc/cvdense.cpp similarity index 100% rename from rename_cpp/cvdense.cpp rename to phreeqc/cvdense.cpp diff --git a/rename_cpp/cvdense.h b/phreeqc/cvdense.h similarity index 100% rename from rename_cpp/cvdense.h rename to phreeqc/cvdense.h diff --git a/rename_cpp/cvode.cpp b/phreeqc/cvode.cpp similarity index 100% rename from rename_cpp/cvode.cpp rename to phreeqc/cvode.cpp diff --git a/rename_cpp/cvode.h b/phreeqc/cvode.h similarity index 100% rename from rename_cpp/cvode.h rename to phreeqc/cvode.h diff --git a/rename_cpp/dense.cpp b/phreeqc/dense.cpp similarity index 100% rename from rename_cpp/dense.cpp rename to phreeqc/dense.cpp diff --git a/rename_cpp/dense.h b/phreeqc/dense.h similarity index 100% rename from rename_cpp/dense.h rename to phreeqc/dense.h diff --git a/rename_cpp/distribution.checklist b/phreeqc/distribution.checklist similarity index 100% rename from rename_cpp/distribution.checklist rename to phreeqc/distribution.checklist diff --git a/rename_cpp/distribution.mk b/phreeqc/distribution.mk similarity index 100% rename from rename_cpp/distribution.mk rename to phreeqc/distribution.mk diff --git a/rename_cpp/dw.cpp b/phreeqc/dw.cpp similarity index 100% rename from rename_cpp/dw.cpp rename to phreeqc/dw.cpp diff --git a/rename_cpp/gases.cpp b/phreeqc/gases.cpp similarity index 100% rename from rename_cpp/gases.cpp rename to phreeqc/gases.cpp diff --git a/rename_cpp/global_structures.h b/phreeqc/global_structures.h similarity index 100% rename from rename_cpp/global_structures.h rename to phreeqc/global_structures.h diff --git a/rename_cpp/input.cpp b/phreeqc/input.cpp similarity index 100% rename from rename_cpp/input.cpp rename to phreeqc/input.cpp diff --git a/rename_cpp/integrate.cpp b/phreeqc/integrate.cpp similarity index 100% rename from rename_cpp/integrate.cpp rename to phreeqc/integrate.cpp diff --git a/rename_cpp/inverse.cpp b/phreeqc/inverse.cpp similarity index 100% rename from rename_cpp/inverse.cpp rename to phreeqc/inverse.cpp diff --git a/rename_cpp/isotopes.cpp b/phreeqc/isotopes.cpp similarity index 100% rename from rename_cpp/isotopes.cpp rename to phreeqc/isotopes.cpp diff --git a/rename_cpp/kinetics.cpp b/phreeqc/kinetics.cpp similarity index 100% rename from rename_cpp/kinetics.cpp rename to phreeqc/kinetics.cpp diff --git a/rename_cpp/mainsubs.cpp b/phreeqc/mainsubs.cpp similarity index 100% rename from rename_cpp/mainsubs.cpp rename to phreeqc/mainsubs.cpp diff --git a/rename_cpp/model.cpp b/phreeqc/model.cpp similarity index 100% rename from rename_cpp/model.cpp rename to phreeqc/model.cpp diff --git a/rename_cpp/newiso.dat b/phreeqc/newiso.dat similarity index 100% rename from rename_cpp/newiso.dat rename to phreeqc/newiso.dat diff --git a/rename_cpp/nvector.cpp b/phreeqc/nvector.cpp similarity index 100% rename from rename_cpp/nvector.cpp rename to phreeqc/nvector.cpp diff --git a/rename_cpp/nvector.h b/phreeqc/nvector.h similarity index 100% rename from rename_cpp/nvector.h rename to phreeqc/nvector.h diff --git a/rename_cpp/nvector_serial.cpp b/phreeqc/nvector_serial.cpp similarity index 100% rename from rename_cpp/nvector_serial.cpp rename to phreeqc/nvector_serial.cpp diff --git a/rename_cpp/nvector_serial.h b/phreeqc/nvector_serial.h similarity index 100% rename from rename_cpp/nvector_serial.h rename to phreeqc/nvector_serial.h diff --git a/rename_cpp/parse.cpp b/phreeqc/parse.cpp similarity index 100% rename from rename_cpp/parse.cpp rename to phreeqc/parse.cpp diff --git a/rename_cpp/phqalloc.cpp b/phreeqc/phqalloc.cpp similarity index 100% rename from rename_cpp/phqalloc.cpp rename to phreeqc/phqalloc.cpp diff --git a/rename_cpp/phqalloc.h b/phreeqc/phqalloc.h similarity index 100% rename from rename_cpp/phqalloc.h rename to phreeqc/phqalloc.h diff --git a/rename_cpp/phreeqc.rev b/phreeqc/phreeqc.rev similarity index 100% rename from rename_cpp/phreeqc.rev rename to phreeqc/phreeqc.rev diff --git a/rename_cpp/phreex.ico b/phreeqc/phreex.ico similarity index 100% rename from rename_cpp/phreex.ico rename to phreeqc/phreex.ico diff --git a/rename_cpp/phrqtype.h b/phreeqc/phrqtype.h similarity index 100% rename from rename_cpp/phrqtype.h rename to phreeqc/phrqtype.h diff --git a/rename_cpp/pitzer.cpp b/phreeqc/pitzer.cpp similarity index 100% rename from rename_cpp/pitzer.cpp rename to phreeqc/pitzer.cpp diff --git a/rename_cpp/pitzer_structures.cpp b/phreeqc/pitzer_structures.cpp similarity index 100% rename from rename_cpp/pitzer_structures.cpp rename to phreeqc/pitzer_structures.cpp diff --git a/rename_cpp/prep.cpp b/phreeqc/prep.cpp similarity index 100% rename from rename_cpp/prep.cpp rename to phreeqc/prep.cpp diff --git a/rename_cpp/print.cpp b/phreeqc/print.cpp similarity index 100% rename from rename_cpp/print.cpp rename to phreeqc/print.cpp diff --git a/rename_cpp/read.cpp b/phreeqc/read.cpp similarity index 100% rename from rename_cpp/read.cpp rename to phreeqc/read.cpp diff --git a/rename_cpp/readtr.cpp b/phreeqc/readtr.cpp similarity index 100% rename from rename_cpp/readtr.cpp rename to phreeqc/readtr.cpp diff --git a/rename_cpp/revisions b/phreeqc/revisions similarity index 100% rename from rename_cpp/revisions rename to phreeqc/revisions diff --git a/rename_cpp/sit.cpp b/phreeqc/sit.cpp similarity index 100% rename from rename_cpp/sit.cpp rename to phreeqc/sit.cpp diff --git a/rename_cpp/smalldense.cpp b/phreeqc/smalldense.cpp similarity index 100% rename from rename_cpp/smalldense.cpp rename to phreeqc/smalldense.cpp diff --git a/rename_cpp/smalldense.h b/phreeqc/smalldense.h similarity index 100% rename from rename_cpp/smalldense.h rename to phreeqc/smalldense.h diff --git a/rename_cpp/spread.cpp b/phreeqc/spread.cpp similarity index 100% rename from rename_cpp/spread.cpp rename to phreeqc/spread.cpp diff --git a/rename_cpp/step.cpp b/phreeqc/step.cpp similarity index 100% rename from rename_cpp/step.cpp rename to phreeqc/step.cpp diff --git a/rename_cpp/structures.cpp b/phreeqc/structures.cpp similarity index 100% rename from rename_cpp/structures.cpp rename to phreeqc/structures.cpp diff --git a/rename_cpp/sundialsmath.cpp b/phreeqc/sundialsmath.cpp similarity index 100% rename from rename_cpp/sundialsmath.cpp rename to phreeqc/sundialsmath.cpp diff --git a/rename_cpp/sundialsmath.h b/phreeqc/sundialsmath.h similarity index 100% rename from rename_cpp/sundialsmath.h rename to phreeqc/sundialsmath.h diff --git a/rename_cpp/sundialstypes.h b/phreeqc/sundialstypes.h similarity index 100% rename from rename_cpp/sundialstypes.h rename to phreeqc/sundialstypes.h diff --git a/rename_cpp/tally.cpp b/phreeqc/tally.cpp similarity index 100% rename from rename_cpp/tally.cpp rename to phreeqc/tally.cpp diff --git a/rename_cpp/tidy.cpp b/phreeqc/tidy.cpp similarity index 100% rename from rename_cpp/tidy.cpp rename to phreeqc/tidy.cpp diff --git a/rename_cpp/transport.cpp b/phreeqc/transport.cpp similarity index 100% rename from rename_cpp/transport.cpp rename to phreeqc/transport.cpp diff --git a/rename_cpp/utilities.cpp b/phreeqc/utilities.cpp similarity index 100% rename from rename_cpp/utilities.cpp rename to phreeqc/utilities.cpp From 2673f81bc76771a4b5243fe54de732890736e532 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 17 Jan 2012 16:51:36 +0000 Subject: [PATCH 0423/1077] Working on ss git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6069 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SScomp.cxx | 431 +++++++++++++++++++++++++++ SScomp.h | 67 +++++ phreeqc/basicsubs.cpp | 2 +- phreeqc/global_structures.h | 14 +- phreeqc/model.cpp | 28 +- phreeqc/pitzer.cpp | 2 +- phreeqc/prep.cpp | 379 +++++++++++++++++++++++- phreeqc/read.cpp | 564 +++++++++++++++++++++++++++++++++++- phreeqc/sit.cpp | 2 +- phreeqc/structures.cpp | 51 +++- 10 files changed, 1501 insertions(+), 39 deletions(-) create mode 100644 SScomp.cxx create mode 100644 SScomp.h diff --git a/SScomp.cxx b/SScomp.cxx new file mode 100644 index 00000000..1f7097c5 --- /dev/null +++ b/SScomp.cxx @@ -0,0 +1,431 @@ +// SScomp.cxx: implementation of the cxxSScomp class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include // assert +#include // std::sort + +#include "Utils.h" // define first +#include "Phreeqc.h" +#include "SScomp.h" +//#include "Dictionary.h" +#include "phqalloc.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// + +cxxSScomp::cxxSScomp(PHRQ_io *io) +: +PHRQ_base(io) + // + // default constructor for cxxSScomp + // +{ + name = ""; + initial_moles = 0; + moles = 0; + init_moles = 0; + delta = 0; + fraction_x = 0; + log10_lambda = 0; + log10_fraction_x = 0; + dn = 0; + dnc = 0; + dnb = 0; +} +#ifdef SKIP +cxxSScomp::cxxSScomp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) +: +PHRQ_base(io) + // + // constructor for cxxSScomp from struct pure_phase + // +{ + this->Set_name(pure_phase_ptr->name); + this->Set_add_formula(pure_phase_ptr->add_formula); + si = pure_phase_ptr->si; + si_org = pure_phase_ptr->si_org; + moles = pure_phase_ptr->moles; + delta = pure_phase_ptr->delta; + initial_moles = pure_phase_ptr->initial_moles; + force_equality = (pure_phase_ptr->force_equality == TRUE); + dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); + precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); +} +#endif +cxxSScomp::~cxxSScomp() +{ +} + +void +cxxSScomp::dump_raw(std::ostream & s_oss, unsigned int indent) const +{ + //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + // Pure_Phase element and attributes + + 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"; +} + +void +cxxSScomp::read_raw(CParser & parser, bool check) +{ + std::string str; + + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(10); + vopts.push_back("name"); // 0 + vopts.push_back("initial_moles"); // 1 + vopts.push_back("moles"); // 2 + vopts.push_back("init_moles"); // 3 + vopts.push_back("delta"); // 4 + 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 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + opt_save = CParser::OPT_ERROR; + bool name_defined(false); + bool initial_moles_defined(false); + bool moles_defined(false); + //bool init_moles_defined(false); + //bool delta_defined(false); + + for (;;) + { + int opt = parser.get_option(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_KEYWORD; + // Allow return to Exchange for more processing + //parser.error_msg("Unknown input in PURE_PHASE read.", PHRQ_io::OT_CONTINUE); + //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + break; + + case 0: // name + if (!(parser.get_iss() >> str)) + { + this->name.clear(); + parser.incr_input_error(); + parser.error_msg("Expected string value for name.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->name = str; + } + name_defined = true; + break; + + case 1: // initial_moles + if (!(parser.get_iss() >> this->initial_moles)) + { + this->initial_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial_moles.", + PHRQ_io::OT_CONTINUE); + } + initial_moles_defined = true; + break; + + case 2: // moles + if (!(parser.get_iss() >> this->moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for moles.", + PHRQ_io::OT_CONTINUE); + } + moles_defined = true; + break; + + case 3: // init_moles + if (!(parser.get_iss() >> this->init_moles)) + { + this->init_moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for init_moles.", + PHRQ_io::OT_CONTINUE); + } + //init_moles_defined = true; + break; + + case 4: // delta + if (!(parser.get_iss() >> this->delta)) + { + this->delta = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for delta.", + PHRQ_io::OT_CONTINUE); + } + //delta_defined = true; + break; + + case 5: // fraction_x + if (!(parser.get_iss() >> this->fraction_x)) + { + this->fraction_x = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for fraction_x.", + PHRQ_io::OT_CONTINUE); + } + //initial_moles_defined = true; + break; + + + case 6: // log10_lambda + if (!(parser.get_iss() >> this->log10_lambda)) + { + this->log10_lambda = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for log10_lambda.", + PHRQ_io::OT_CONTINUE); + } + break; + + case 7: // log10_fraction_x + if (!(parser.get_iss() >> this->log10_fraction_x)) + { + this->log10_fraction_x = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for log10_fraction_x.", + PHRQ_io::OT_CONTINUE); + } + break; + + case 8: // dn + if (!(parser.get_iss() >> this->dn)) + { + this->dn = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for dn.", + PHRQ_io::OT_CONTINUE); + } + break; + case 9: // dnc + if (!(parser.get_iss() >> this->dnc)) + { + this->dnc = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for dnc.", + PHRQ_io::OT_CONTINUE); + } + //dnc_defined = true; + break; + case 10: // dnb + if (!(parser.get_iss() >> this->dnb)) + { + this->dnb = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for dnb.", + PHRQ_io::OT_CONTINUE); + } + //dnc_defined = true; + break; + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + // members that must be defined + if (check) + { + if (name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Name not defined for PPassemblageComp input.", + PHRQ_io::OT_CONTINUE); + } + if (moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Moles not defined for PPassemblageComp input.", + PHRQ_io::OT_CONTINUE); + } + if (initial_moles_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Initial_moles not defined for PPassemblageComp input.", + PHRQ_io::OT_CONTINUE); + } + } +} + +#ifdef USE_MPI +void +cxxSScomp::mpi_pack(std::vector < int >&ints, + std::vector < double >&doubles) +{ + extern cxxDictionary dictionary; + + ints.push_back(dictionary.string2int(this->name)); + ints.push_back(dictionary.string2int(this->add_formula)); + doubles.push_back(this->si); + doubles.push_back(this->si_org); + doubles.push_back(this->moles); + doubles.push_back(this->delta); + doubles.push_back(this->initial_moles); + ints.push_back((int) this->force_equality); + ints.push_back((int) this->dissolve_only); + ints.push_back((int) this->precipitate_only); +} + +void +cxxSScomp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) +{ + extern cxxDictionary dictionary; + int i = *ii; + int d = *dd; + this->name = dictionary.int2stdstring(ints[i++]); + this->add_formula = dictionary.int2stdstring(ints[i++]); + this->si = doubles[d++]; + this->si_org = doubles[d++]; + this->moles = doubles[d++]; + this->delta = doubles[d++]; + this->initial_moles = doubles[d++]; + this->force_equality = (ints[i++] != 0); + this->dissolve_only = (ints[i++] != 0); + this->precipitate_only = (ints[i++] != 0); + *ii = i; + *dd = d; +} +#endif +#ifdef SKIP +void +cxxSScomp::totalize(PHREEQC_PTR_ARG) +{ + this->totals.clear(); + // component structures + if (this->add_formula.size() != 0) + return; + struct phase *phase_ptr; + int l; + phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, this->moles); + } + else + { + assert(false); + } + return; +} +#endif +#ifdef SKIP +void +cxxSScomp::add(const cxxSScomp & addee, double extensive) +{ + double ext1, ext2, f1, f2; + if (extensive == 0.0) + return; + if (addee.name.size() == 0) + return; + // this and addee must have same name + // otherwise generate a new PPassemblagComp with multiply + + ext1 = this->moles; + ext2 = addee.moles * extensive; + if (ext1 + ext2 != 0) + { + f1 = ext1 / (ext1 + ext2); + f2 = ext2 / (ext1 + ext2); + } + else + { + f1 = 0.5; + f2 = 0.5; + } + //char * name; + //char *add_formula; + + if (this->name.size() == 0 && addee.name.size() == 0) + { + return; + } + assert(this->name == addee.name); + if (this->add_formula != addee.add_formula) + { + std::ostringstream oss; + oss << + "Can not mix two Equilibrium_phases with differing add_formulae., " + << this->name; + error_msg(oss.str().c_str(), CONTINUE); + return; + } + //double si; + this->si = this->si * f1 + addee.si * f2; + //double si_org; + this->si_org = this->si_org * f1 + addee.si_org * f2; + //double moles; + this->moles += addee.moles * extensive; + //double delta; + this->delta += addee.delta * extensive; + //double initial_moles; + this->initial_moles += addee.initial_moles * extensive; + //bool force_equality; + //bool dissolve_only; + +} +#endif +void +cxxSScomp::multiply(double extensive) +{ + //char * name; + //char *add_formula; + //double si; + //double moles; + this->moles *= extensive; + //double delta; + this->delta *= extensive; + //double initial_moles; + this->initial_moles *= extensive; + //bool force_equality; + //bool dissolve_only; +} diff --git a/SScomp.h b/SScomp.h new file mode 100644 index 00000000..88af65af --- /dev/null +++ b/SScomp.h @@ -0,0 +1,67 @@ +#if !defined(SSCOMP_H_INCLUDED) +#define SSCOMP_H_INCLUDED + +#include // assert +#include // std::map +#include // std::string +#include // std::list +#include // std::vector + +#include "NameDouble.h" +#include "Phreeqc_class.h" + +class cxxSScomp: public PHRQ_base +{ + + public: + cxxSScomp(PHRQ_io *io=NULL); + ~cxxSScomp(); + + void dump_raw(std::ostream & s_oss, unsigned int indent) const; + void read_raw(CParser & parser, bool check = true); + + const std::string &Get_name() const {return this->name;} + void Set_name(std::string s) {this->name = s;} + + LDBLE Get_initial_moles() const {return this->initial_moles;} + void Set_initial_moles(LDBLE t) {this->initial_moles = t;} + LDBLE Get_moles() const {return this->moles;} + void Set_moles(LDBLE t) {this->moles = t;} + LDBLE Get_init_moles() const {return this->init_moles;} + void Set_init_moles(LDBLE t) {this->init_moles = t;} + LDBLE Get_delta() const {return this->delta;} + void Set_delta(LDBLE t) {this->delta = t;} + LDBLE Get_fraction_x() const {return this->fraction_x;} + void Set_fraction_x(LDBLE t) {this->fraction_x = t;} + LDBLE Get_log10_lambda() const {return this->log10_lambda;} + void Set_log10_lambda(LDBLE t) {this->log10_lambda = t;} + LDBLE Get_log10_fraction_x() const {return this->log10_fraction_x;} + void Set_log10_fraction_x(LDBLE t) {this->log10_fraction_x = t;} + LDBLE Get_dn() const {return this->dn;} + void Set_dn(LDBLE t) {this->dn = t;} + LDBLE Get_dnc() const {return this->dnc;} + void Set_dnc(LDBLE t) {this->dnc = t;} + LDBLE Get_dnb() const {return this->dnb;} + void Set_dnb(LDBLE t) {this->dnb = t;} + + //void add(const cxxSScomp & comp, double extensive); + void multiply(double extensive); + +#ifdef USE_MPI + void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); + void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); +#endif +protected: + std::string name; + //struct phase *phase; + LDBLE initial_moles; + LDBLE moles; + LDBLE init_moles; + LDBLE delta; + LDBLE fraction_x; + LDBLE log10_lambda; + LDBLE log10_fraction_x; + LDBLE dn, dnc, dnb; +}; + +#endif // !defined(SSCOMP_H_INCLUDED) diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index ae58678a..87d300e4 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -2794,7 +2794,7 @@ system_total_elt_secondary(const char *total_name) /* * Look for element */ - for (int j1 = 0; j1 < (size_t) count_elts; j1++) + for (size_t j1 = 0; j1 < (size_t) count_elts; j1++) { if (strcmp(elt_list[j1].elt->name, total_name) == 0) { diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index a8f6eccc..f01f79e9 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -84,7 +84,7 @@ #define SURFACE_CB1 22 #define SURFACE_CB2 23 #define GAS_MOLES 24 -#define S_S_MOLES 25 +#define SS_MOLES 25 #define PITZER_GAMMA 26 #define SLACK 28 /* state */ @@ -648,6 +648,7 @@ struct name_coef const char *name; LDBLE coef; }; +#ifdef SKIP /*---------------------------------------------------------------------- * Solid solution *---------------------------------------------------------------------- */ @@ -692,6 +693,7 @@ struct s_s_comp LDBLE log10_fraction_x; LDBLE dn, dnc, dnb; }; +#endif #ifdef SKIP /*---------------------------------------------------------------------- * Pure-phase assemblage @@ -1073,10 +1075,12 @@ struct unknown const char * exch_comp; //struct pure_phase *pure_phase; const char *pp_assemblage_comp_name; - struct s_s *s_s; - struct s_s_comp *s_s_comp; - int s_s_comp_number; - int s_s_in; + //struct s_s *s_s; + //struct s_s_comp *s_s_comp; + const char * ss_name; + const char * ss_comp_name; + int ss_comp_number; + int ss_in; struct surface_comp *surface_comp; LDBLE related_moles; struct unknown *potential_unknown, *potential_unknown1, diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 2dceb7fd..218f8fbf 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -579,7 +579,7 @@ check_residuals(void) x[i]->description, (double) residual[i]); } } - else if (x[i]->type == S_S_MOLES) + else if (x[i]->type == SS_MOLES) { if (x[i]->s_s_in == FALSE) continue; @@ -1388,7 +1388,7 @@ ineq(int in_kode) * Solid solution */ } - else if (x[i]->type == S_S_MOLES && x[i]->s_s_in == TRUE) + else if (x[i]->type == SS_MOLES && x[i]->s_s_in == TRUE) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(array[i * (count_unknowns + 1)]), @@ -1426,7 +1426,7 @@ ineq(int in_kode) } if (x[i]->type != SOLUTION_PHASE_BOUNDARY && x[i]->type != ALK && - x[i]->type != GAS_MOLES && x[i]->type != S_S_MOLES + x[i]->type != GAS_MOLES && x[i]->type != SS_MOLES /* && x[i]->type != PP */ && x[i]->type != SLACK ) @@ -1773,7 +1773,7 @@ ineq(int in_kode) { for (i = s_s_unknown->number; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) + if (x[i]->type != SS_MOLES) break; if (x[i]->phase->in == TRUE && x[i]->s_s_in == TRUE) { @@ -1835,7 +1835,7 @@ ineq(int in_kode) */ for (i = 0; i < count_unknowns; i++) { - if ((x[i]->type == PP || x[i]->type == S_S_MOLES) + if ((x[i]->type == PP || x[i]->type == SS_MOLES) && pp_column_scale != 1.0) { for (j = 0; j < l_count_rows; j++) @@ -2415,7 +2415,7 @@ mb_s_s(void) } for (i = s_s_unknown->number; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) + if (x[i]->type != SS_MOLES) break; x[i]->s_s_in = x[i]->s_s->s_s_in; } @@ -3108,7 +3108,7 @@ reset(void) */ for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == PP || x[i]->type == S_S_MOLES) + if (x[i]->type == PP || x[i]->type == SS_MOLES) { if (delta[i] < -1e8) @@ -3249,7 +3249,7 @@ reset(void) for (i = 0; i < count_unknowns; i++) { x[i]->delta /= factor; - if (x[i]->type == PP || x[i]->type == S_S_MOLES) + if (x[i]->type == PP || x[i]->type == SS_MOLES) delta[i] /= factor; } @@ -3322,7 +3322,7 @@ reset(void) up = 1.; down = x[i]->moles; } - else if (x[i]->type == S_S_MOLES) + else if (x[i]->type == SS_MOLES) { continue; } @@ -3397,7 +3397,7 @@ reset(void) for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != PP && x[i]->type != S_S_MOLES) + if (x[i]->type != PP && x[i]->type != SS_MOLES) delta[i] *= factor; } @@ -3774,7 +3774,7 @@ reset(void) } } - else if (x[i]->type == S_S_MOLES) + else if (x[i]->type == SS_MOLES) { /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ @@ -4115,7 +4115,7 @@ residuals(void) converge = FALSE; } } - else if (x[i]->type == S_S_MOLES) + else if (x[i]->type == SS_MOLES) { residual[i] = x[i]->f * LOG_10; //if (x[i]->moles <= MIN_TOTAL_SS && iterations > 2) @@ -5361,7 +5361,7 @@ numerical_jacobian(void) reset(); d2 = delta[i]; break; - case S_S_MOLES: + case SS_MOLES: if (x[i]->s_s_in == FALSE) continue; for (j = 0; j < count_unknowns; j++) @@ -5442,7 +5442,7 @@ numerical_jacobian(void) delta[i] = -d2; reset(); break; - case S_S_MOLES: + case SS_MOLES: delta[i] = -d2; reset(); break; diff --git a/phreeqc/pitzer.cpp b/phreeqc/pitzer.cpp index 857ae789..5c3890ca 100644 --- a/phreeqc/pitzer.cpp +++ b/phreeqc/pitzer.cpp @@ -1733,7 +1733,7 @@ Restart: break; case MU: case PP: - case S_S_MOLES: + case SS_MOLES: continue; break; } diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 72f604fb..035744f6 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -6,6 +6,8 @@ #include "Exchange.h" #include "GasPhase.h" #include "PPassemblage.h" +#include "SSassemblage.h" +#include "SS.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: prep(void) @@ -260,7 +262,40 @@ quick_setup(void) { for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == S_S_MOLES) + if (x[i]->type == SS_MOLES) + break; + } + + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + for (size_t k = 0; k < ss_ptrs[j]->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptrs[j]->Get_ss_comps()[k]); + x[i]->moles = comp_ptr->Get_moles(); + if (x[i]->moles <= 0) + { + x[i]->moles = MIN_TOTAL_SS; + comp_ptr->Set_moles(MIN_TOTAL_SS); + } + comp_ptr->Set_initial_moles(x[i]->moles); + x[i]->ln_moles = log(x[i]->moles); + + x[i]->phase->dn = comp_ptr->Get_dn(); + x[i]->phase->dnb = comp_ptr->Get_dnb(); + x[i]->phase->dnc = comp_ptr->Get_dnc(); + x[i]->phase->log10_fraction_x = comp_ptr->Get_log10_fraction_x(); + x[i]->phase->log10_lambda = comp_ptr->Get_log10_lambda(); + i++; + } + } + } +#ifdef SKIP + if (s_s_unknown != NULL) + { + for (i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SS_MOLES) break; } for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) @@ -289,6 +324,7 @@ quick_setup(void) } } } +#endif /* * exchange */ @@ -666,6 +702,223 @@ int Phreeqc:: build_ss_assemblage(void) /* ---------------------------------------------------------------------- */ { +/* + * Put coefficients into lists to sum iaps to test for equilibrium + * Put coefficients into lists to build jacobian for + * mass action equation for component + * mass balance equations for elements contained in solid solutions + */ + //int i, j, k, l, stop; + bool stop; + int row, col; + struct master *master_ptr; + struct rxn_token *rxn_ptr; + //struct s_s *s_s_ptr, *s_s_ptr_old; + //char token[MAX_LENGTH]; + char *ptr; + + if (s_s_unknown == NULL) + return (OK); + cxxSS * ss_ptr_old = NULL; + col = 0; + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SS_MOLES) + continue; + cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + assert(ss_ptr); + if (ss_ptr != ss_ptr_old) + { + col = x[i]->number; + ss_ptr_old = ss_ptr; + } +/* + * Calculate function value (inverse saturation index) + */ + if (x[i]->phase->rxn_x == NULL) + continue; + store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); + } + /* include mole fraction */ + store_mb(&(x[i]->phase->log10_fraction_x), &(x[i]->f), 1.0); + + /* include activity coeficient */ + store_mb(&(x[i]->phase->log10_lambda), &(x[i]->f), 1.0); +/* + * Put coefficients into mass action equations + */ + /* first IAP terms */ + for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + if (rxn_ptr->s->secondary != NULL + && rxn_ptr->s->secondary->in == TRUE) + { + master_ptr = rxn_ptr->s->secondary; + } + else + { + master_ptr = rxn_ptr->s->primary; + } + if (master_ptr == NULL || master_ptr->unknown == NULL) + continue; + store_jacob0(x[i]->number, master_ptr->unknown->number, + rxn_ptr->coef); + } + + if (ss_ptr->Get_a0() != 0.0 || ss_ptr->Get_a1() != 0.0) + { +/* + * For binary solid solution + */ + /* next dnc terms */ + row = x[i]->number * (count_unknowns + 1); + if (x[i]->ss_comp_number == 0) + { + col = x[i]->number; + } + else + { + col = x[i]->number - 1; + } + store_jacob(&(x[i]->phase->dnc), &(array[row + col]), -1); + + /* next dnb terms */ + col++; + store_jacob(&(x[i]->phase->dnb), &(array[row + col]), -1); + } + else + { +/* + * For ideal solid solution + */ + row = x[i]->number * (count_unknowns + 1); + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + if (j != x[i]->ss_comp_number) + { +/* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ + store_jacob(&(x[i]->phase->dn), &(array[row + col + j]), + -1.0); + } + else + { + store_jacob(&(x[i]->phase->dnb), &(array[row + col + j]), + -1.0); + } + } + } +/* + * Put coefficients into mass balance equations + */ + count_elts = 0; + paren_count = 0; + char * token = string_duplicate(x[i]->phase->formula); + ptr = token; + get_elts_in_species(&ptr, 1.0); + free_check_null(token); +/* + * Go through elements in phase + */ +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (int j = 0; j < count_elts; j++) + { + + if (strcmp(elt_list[j].elt->name, "H") == 0 + && mass_hydrogen_unknown != NULL) + { + store_jacob0(mass_hydrogen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, + elt_list[j].coef); + + } + else if (strcmp(elt_list[j].elt->name, "O") == 0 + && mass_oxygen_unknown != NULL) + { + store_jacob0(mass_oxygen_unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, + elt_list[j].coef); + + } + else + { + master_ptr = elt_list[j].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL || master_ptr->in == FALSE) + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element in phase, %s, is not in model.", + x[i]->phase->name); + warning_msg(error_string); + } + if (master_ptr != NULL) + { + master_ptr->s->la = -999.9; + } +/* + * Master species is in model + */ + } + else if (master_ptr->in == TRUE) + { + store_jacob0(master_ptr->unknown->number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], &master_ptr->unknown->delta, + elt_list[j].coef); +/* + * Master species in equation needs to be rewritten + */ + } + else if (master_ptr->in == REWRITE) + { + stop = FALSE; + for (int k = 0; k < count_unknowns; k++) + { + if (x[k]->type != MB) + continue; + for (int l = 0; x[k]->master[l] != NULL; l++) + { + if (x[k]->master[l] == master_ptr) + { + store_jacob0(x[k]->master[0]->unknown-> + number, x[i]->number, + -elt_list[j].coef); + store_sum_deltas(&delta[i], + &x[k]->master[0]->unknown-> + delta, elt_list[j].coef); + stop = TRUE; + break; + } + } + if (stop == TRUE) + break; + } + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ /* * Put coefficients into lists to sum iaps to test for equilibrium * Put coefficients into lists to build jacobian for @@ -686,7 +939,7 @@ build_ss_assemblage(void) col = 0; for (i = 0; i < count_unknowns; i++) { - if (x[i]->type != S_S_MOLES) + if (x[i]->type != SS_MOLES) continue; s_s_ptr = x[i]->s_s; if (s_s_ptr != s_s_ptr_old) @@ -874,7 +1127,7 @@ build_ss_assemblage(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: build_jacobian_sums(int k) @@ -3488,6 +3741,58 @@ int Phreeqc:: setup_ss_assemblage(void) /* ---------------------------------------------------------------------- */ { +/* + * Fill in data for solid solution unknowns (sum of partial pressures) + * in unknown structure + */ + //int i, j; + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); +/* + * One for each component in each solid solution + */ + s_s_unknown = NULL; + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + for (size_t i = 0; i < ss_ptrs[j]->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptrs[j]->Get_ss_comps()[i]); + int l; + struct phase* phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + x[count_unknowns]->type = SS_MOLES; + x[count_unknowns]->description = string_hsave(comp_ptr->Get_name().c_str()); + x[count_unknowns]->moles = 0.0; + if (comp_ptr->Get_moles() <= 0) + { + comp_ptr->Set_moles(MIN_TOTAL_SS); + } + x[count_unknowns]->moles = comp_ptr->Get_moles(); + comp_ptr->Set_initial_moles(x[count_unknowns]->moles); + x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); + x[count_unknowns]->ss_name = string_hsave(ss_ptrs[j]->Get_name().c_str()); + x[count_unknowns]->ss_comp_name = string_hsave(comp_ptr->Get_name().c_str()); + x[count_unknowns]->ss_comp_number = (int) i; + x[count_unknowns]->phase = phase_ptr; + x[count_unknowns]->number = count_unknowns; + x[count_unknowns]->phase->dn = comp_ptr->Get_dn(); + x[count_unknowns]->phase->dnb = comp_ptr->Get_dnb(); + x[count_unknowns]->phase->dnc = comp_ptr->Get_dnc(); + x[count_unknowns]->phase->log10_fraction_x = comp_ptr->Get_log10_fraction_x(); + x[count_unknowns]->phase->log10_lambda =comp_ptr->Get_log10_lambda(); + if (s_s_unknown == NULL) + s_s_unknown = x[count_unknowns]; + count_unknowns++; + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +setup_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ +{ /* * Fill in data for solid solution unknowns (sum of partial pressures) * in unknown structure @@ -3503,7 +3808,7 @@ setup_ss_assemblage(void) { for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) { - x[count_unknowns]->type = S_S_MOLES; + x[count_unknowns]->type = SS_MOLES; x[count_unknowns]->description = string_hsave(use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name); x[count_unknowns]->moles = 0.0; @@ -3540,7 +3845,7 @@ setup_ss_assemblage(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: setup_surface(void) @@ -4926,6 +5231,15 @@ setup_unknowns(void) /* * Count solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + max_unknowns += ss_ptrs[i]->Get_ss_comps().size(); + } + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { /* max_unknowns += 2 * use.Get_ss_assemblage_ptr()->count_s_s; */ @@ -4934,6 +5248,7 @@ setup_unknowns(void) max_unknowns += use.Get_ss_assemblage_ptr()->s_s[i].count_comps; } } +#endif /* * Pitzer/Sit @@ -5751,6 +6066,18 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ /* * Calculate miscibility gaps for solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + if (fabs(tempk - ss_ptrs[i]->Get_tk()) > 0.01) + { + ss_prep(tempk, ss_ptrs[i], FALSE); + } + } + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) @@ -5761,6 +6088,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ } } } +#endif return (OK); } @@ -5865,6 +6193,26 @@ save_model(void) last_model.ss_assemblage = (const char **) free_check_null(last_model.ss_assemblage); if (use.Get_ss_assemblage_ptr() != NULL) + { + size_t count_ss = use.Get_ss_assemblage_ptr()->Get_SSs().size(); + last_model.count_ss_assemblage = count_ss; + last_model.ss_assemblage = + (const char **) PHRQ_malloc(count_ss * sizeof(char *)); + if (last_model.ss_assemblage == NULL) + malloc_error(); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + last_model.ss_assemblage[i] = string_hsave(ss_ptrs[j]->Get_name().c_str()); + } + } + else + { + last_model.count_ss_assemblage = 0; + last_model.ss_assemblage = NULL; + } +#ifdef SKIP + if (use.Get_ss_assemblage_ptr() != NULL) { last_model.count_ss_assemblage = use.Get_ss_assemblage_ptr()->count_s_s; last_model.ss_assemblage = @@ -5883,6 +6231,7 @@ save_model(void) last_model.count_ss_assemblage = 0; last_model.ss_assemblage = NULL; } +#endif /* * save list of phase pointers for pp_assemblage */ @@ -6110,6 +6459,25 @@ check_same_model(void) /* * Check solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + if (last_model.count_ss_assemblage != (int) use.Get_ss_assemblage_ptr()->Get_SSs().size()) + return (FALSE); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + if (last_model.ss_assemblage[i] != string_hsave(ss_ptrs[i]->Get_name().c_str())) + { + return (FALSE); + } + } + } + else + { + if (last_model.ss_assemblage != NULL) + return (FALSE); + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { if (last_model.count_ss_assemblage != @@ -6129,6 +6497,7 @@ check_same_model(void) if (last_model.ss_assemblage != NULL) return (FALSE); } +#endif /* * Check pure_phases */ diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 9c37a3f7..42b6c0b5 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -13,6 +13,9 @@ #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" +#include "SSassemblage.h" +#include "SS.h" +#include "SScomp.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -9204,7 +9207,566 @@ read_user_graph(void) return (return_value); } #endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solid_solutions(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solid solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + //int i, j, n, l; + //int count_s_s, number_s_s, count_comps; + int n_user, n_user_end; + char *ptr; + char *description; + //char token[MAX_LENGTH]; + std::string token; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "component", /* 0 */ + "comp", /* 1 */ + "parms", /* 2 */ + "gugg_nondimensional", /* 3 */ + "gugg_kj", /* 4 */ + "activity_coefficients", /* 5 */ + "distribution_coefficients", /* 6 */ + "miscibility_gap", /* 7 */ + "spinodal_gap", /* 8 */ + "critical_point", /* 9 */ + "alyotropic_point", /* 10 */ + "temp", /* 11 */ + "tempk", /* 12 */ + "tempc", /* 13 */ + "thompson", /* 14 */ + "margules", /* 15 */ + "comp1", /* 16 */ + "comp2" /* 17 */ + }; + int count_opt_list = 18; +/* + * Read ss_assemblage number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + cxxSSassemblage temp_ss_assemblage; + temp_ss_assemblage.Set_n_user(n_user); + temp_ss_assemblage.Set_n_user_end(n_user_end); + temp_ss_assemblage.Set_description(description); + free_check_null(description); + temp_ss_assemblage.Set_new_def(true); + + std::vector comps; + cxxSScomp * comp0_ptr = NULL; + cxxSScomp * comp1_ptr = NULL; + cxxSS * ss_ptr = NULL; +/* + * Set use data to first read + */ + if (!use.Get_ss_assemblage_in()) + { + use.Set_ss_assemblage_in(true); + use.Set_n_ss_assemblage_user(n_user); + } +/* + * Read solid solutions + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLID_SOLUTIONS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; +/* + * New component + */ + case 0: /* component */ + case 1: /* comp */ + { + cxxSScomp comp; + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr); + comp.Set_name(token); + /* + * Read moles of component + */ + + if (copy_token(token, &ptr) == EMPTY) + { + comp.Set_moles(NAN); + } + else + { + int j = sscanf(token.c_str(), SCANFORMAT, &dummy); + comp.Set_moles(dummy); + (LDBLE) dummy; + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + comps.push_back(comp); + } + break; + case 2: /* parms */ + case 3: /* gugg_nondimensional */ + /* + * Read parameters + */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p()[0] = dummy; + } + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p()[1] = dummy; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_A0_A1); + break; + case 4: /* gugg_kj */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p()[0] = dummy; + } + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p()[1] = dummy; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_DIM_GUGG); + break; + case 5: /* activity coefficients */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 4; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 4) + { + error_string = sformatf( + "Expected 4 parameters to calculate a0 and a1 from two activity coefficients, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_GAMMAS); + break; + case 6: /* distribution coefficients */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 4; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 4) + { + error_string = sformatf( + "Expected 4 parameters to calculate a0 and a1 from two distribution coefficients, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_DIST_COEF); + break; + case 7: /* miscibility_gap */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected 2 miscibility gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_MISCIBILITY); + break; + case 8: /* spinodal_gap */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected 2 spinodal gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_SPINODAL); + break; + case 9: /* critical point */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected fraction of component 2 and critical temperature to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_CRITICAL); + break; + case 10: /* alyotropic point */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected fraction of component 2 and sigma pi at alyotropic point to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_ALYOTROPIC); + break; + case 12: /* tempk */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + { + ptr = next_char; + int j = 0; + if (copy_token(token, &ptr) != EMPTY) + { + j = sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Set_tk(dummy); + } + if (j != 1) + { + error_string = sformatf( + "Expected temperature (Kelvin) for parameters, assemblage %d, solid solution %s, using 298.15 K", + n_user, + ss_ptr->Get_name().c_str()); + warning_msg(error_string); + ss_ptr->Set_tk(298.15); + } + } + break; + case 11: /* temp */ + case 13: /* tempc */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + { + ptr = next_char; + int j = 0; + if (copy_token(token, &ptr) != EMPTY) + { + j = sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Set_tk(dummy + 298.15); + } + if (j != 1) + { + error_string = sformatf( + "Expected temperature (Celcius) for parameters, assemblage %d, solid solution %s, using 25 C", + n_user, + ss_ptr->Get_name().c_str()); + warning_msg(error_string); + ss_ptr->Set_tk(298.15); + } + } + break; + case 14: /* Thompson and Waldbaum */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected Wg2 and Wg1 Thompson-Waldbaum parameters to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_WALDBAUM); + break; + case 15: /* Margules */ + if (!ss_ptr) + { + error_msg("Solid solution name has not been defined", CONTINUE); + break; + } + ptr = next_char; + ss_ptr->Get_p().clear(); + for (int i = 0; i < 2; i++) + { + if (copy_token(token, &ptr) != EMPTY) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + ss_ptr->Get_p().push_back(dummy); + } + } + if (ss_ptr->Get_p().size() != 2) + { + error_string = sformatf( + "Expected alpha2 and alpha3 Margules parameters to calculate a0 and a1, assemblage %d, solid solution %s", + n_user, + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + ss_ptr->Set_input_case(cxxSS::SS_PARM_MARGULES); + break; + case 16: /* comp1 */ + + /* + * Read phase name of component + */ + delete comp0_ptr; + comp0_ptr = new cxxSScomp; + ptr = next_char; + copy_token(token, &ptr); + comp0_ptr->Set_name(token); + /* + * Read moles of component + */ + if (copy_token(token, &ptr) == EMPTY) + { + comp0_ptr->Set_moles(NAN); + } + else + { + int j = sscanf(token.c_str(), SCANFORMAT, &dummy); + comp0_ptr->Set_moles(dummy); + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; + case 17: /* comp2 */ + delete comp1_ptr; + comp1_ptr = new cxxSScomp; + /* + * Read phase name of component + */ + ptr = next_char; + copy_token(token, &ptr); + comp1_ptr->Set_name(token); + /* + * Read moles of component + */ + if (copy_token(token, &ptr) == EMPTY) + { + comp1_ptr->Set_moles(NAN); + } + else + { + int j = sscanf(token.c_str(), SCANFORMAT, &dummy); + comp1_ptr->Set_moles(dummy); + if (j != 1) + { + error_msg("Expected moles of solid solution.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + break; +/* + * New solid solution + */ + case OPTION_DEFAULT: + if(ss_ptr) + { + comps.insert(comps.begin(), *comp1_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; + ss_ptr = NULL; + comps.clear(); + delete comp0_ptr, comp1_ptr; + comp0_ptr = comp1_ptr = NULL; + } + ss_ptr = new cxxSS; + /* + * Read solid solution name + */ + ptr = line; + copy_token(token, &ptr); + ss_ptr->Set_name(token); + ss_ptr->Set_total_moles(NAN); + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + + // add last ss and clean up + comps.insert(comps.begin(), *comp1_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; + ss_ptr = NULL; + comps.clear(); + delete comp0_ptr, comp1_ptr; + comp0_ptr = comp1_ptr = NULL; + + // check non ideal ss + std::vector ss_v; + for (size_t i = 0; i < ss_v.size(); i++) + { + if (ss_v[i]->Get_p()[0] != 0.0 || + ss_v[i]->Get_p()[1] != 0.0) + { + if (ss_v[i]->Get_ss_comps().size() != 2) + { + error_string = sformatf( + "Solid solution, %s, is nonideal. Must define exactly two components (-comp1 and -comp2).", + ss_v[i]->Get_name().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + } + } + + // Add to map + Rxn_ss_assemblage_map[n_user] = temp_ss_assemblage; + + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solid_solutions(void) @@ -9763,7 +10325,7 @@ read_solid_solutions(void) (size_t) count_s_s, (size_t) sizeof(struct s_s), s_s_compare); return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_llnl_aqueous_model_parameters(void) diff --git a/phreeqc/sit.cpp b/phreeqc/sit.cpp index 22936a98..9cddb622 100644 --- a/phreeqc/sit.cpp +++ b/phreeqc/sit.cpp @@ -845,7 +845,7 @@ jacobian_sit(void) break; case MU: case PP: - case S_S_MOLES: + case SS_MOLES: continue; break; } diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 89786dd4..5623f588 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -10,6 +10,7 @@ #include "Reaction.h" #include "PPassemblage.h" #include "Use.h" +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -104,14 +105,15 @@ clean_up(void) #endif /* s_s assemblages */ - + Rxn_ss_assemblage_map.clear(); +#ifdef SKIP for (j = 0; j < count_ss_assemblage; j++) { ss_assemblage_free(&ss_assemblage[j]); } ss_assemblage = (struct ss_assemblage *) free_check_null(ss_assemblage); - +#endif /* irreversible reactions */ Rxn_reaction_map.clear(); @@ -375,7 +377,7 @@ clean_up(void) count_surface = 0; //count_gas_phase = 0; count_kinetics = 0; - count_ss_assemblage = 0; + //count_ss_assemblage = 0; count_elements = 0; //count_irrev = 0; @@ -436,13 +438,14 @@ reinitialize(void) count_pp_assemblage = 0; #endif /* s_s assemblages */ - + Rxn_ss_assemblage_map.clear(); +#ifdef SKIP for (j = 0; j < count_ss_assemblage; j++) { ss_assemblage_free(&ss_assemblage[j]); } count_ss_assemblage = 0; - +#endif /* gases */ Rxn_gas_phase_map.clear(); @@ -3233,7 +3236,7 @@ s_store(const char *name, LDBLE l_z, int replace_if_found) return (s_ptr); } - +#ifdef SKIP /* ********************************************************************** * * Routines related to structure "ss_assemblage" @@ -3656,7 +3659,7 @@ s_s_compare(const void *ptr1, const void *ptr2) return (strcmp_nocase(s_s_ptr1->name, s_s_ptr2->name)); } - +#endif /* ********************************************************************** * * Routines related to structure "save_values" @@ -6451,7 +6454,7 @@ cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il) } return (iso); } - +#ifdef SKIP #include "../SSassemblage.h" #include "../SS.h" struct ss_assemblage * Phreeqc:: @@ -6554,7 +6557,7 @@ cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp) } return (s_s_ptr); } - +#endif #include "../Surface.h" struct surface * Phreeqc:: cxxSurface2surface(const cxxSurface * surf) @@ -6958,6 +6961,15 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_GasPhase(use.Get_n_gas_phase_user(), entity_ptr); } } + if (use.Get_ss_assemblage_in()) + { + cxxSSassemblage *entity_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user()); + if (entity_ptr != NULL) + { + sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), entity_ptr); + } + } +#ifdef SKIP if (use.Get_ss_assemblage_in()) { struct ss_assemblage *struct_entity = ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); @@ -6967,6 +6979,7 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), &entity); } } +#endif if (use.Get_kinetics_in()) { struct kinetics *struct_entity = kinetics_bsearch(use.Get_n_kinetics_user(), &n); @@ -7059,12 +7072,20 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) } #endif // SSassemblages + { + std::map::iterator it; + for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + { + sb.Set_SSassemblage(it->second.Get_n_user(), &(it->second)); + } + } +#ifdef SKIP for (i = 0; i < count_ss_assemblage; i++) { cxxSSassemblage entity(&ss_assemblage[i], sb.Get_io()); sb.Set_SSassemblage(ss_assemblage[i].n_user, &entity ); } - +#endif // Surfaces for (i = 0; i < count_surface; i++) { @@ -7172,6 +7193,14 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) } #endif // SSassemblages + { + cxxSSassemblage *entity_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, n); + if (entity_ptr != NULL) + { + sb.Set_SSassemblage(n, entity_ptr); + } + } +#ifdef SKIP { if (ss_assemblage_bsearch(n, &pos) != NULL) { @@ -7180,7 +7209,7 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) sb.Set_SSassemblage(n, &ent); } } - +#endif // Surfaces { if (surface_bsearch(n, &pos) != NULL) From d051a77711e64189d91f0f47e89f6ae252b48345 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 17 Jan 2012 20:39:32 +0000 Subject: [PATCH 0424/1077] compiles and runs solid_solution test case. Need to compile on Linux and run all test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6070 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 3 +- Keywords.h | 1 - PBasic.cpp | 6 +- Phreeqc.cpp | 21 +- Phreeqc.h | 64 +-- ReadClass.cxx | 46 +- SS.cxx | 138 +++++- SS.h | 64 ++- SSassemblage.cxx | 59 ++- SSassemblage.h | 24 +- Use.h | 7 +- phreeqc/basicsubs.cpp | 335 ++++++++++++- phreeqc/global_structures.h | 6 +- phreeqc/kinetics.cpp | 182 +++---- phreeqc/mainsubs.cpp | 90 +++- phreeqc/model.cpp | 476 +++++++++++++++++-- phreeqc/pitzer.cpp | 6 +- phreeqc/prep.cpp | 24 +- phreeqc/print.cpp | 206 +++++++- phreeqc/read.cpp | 16 +- phreeqc/sit.cpp | 14 +- phreeqc/step.cpp | 238 +++++++++- phreeqc/structures.cpp | 42 +- phreeqc/tally.cpp | 115 ++++- phreeqc/tidy.cpp | 912 +++++++++++++++++++++++++++++++++++- phreeqc/transport.cpp | 23 +- 26 files changed, 2759 insertions(+), 359 deletions(-) diff --git a/Keywords.cpp b/Keywords.cpp index 008ddc7e..7878792c 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -118,7 +118,7 @@ std::map::value_type("delete", Keyw std::map::value_type("run_cells", Keywords::KEY_RUN_CELLS), std::map::value_type("reaction_modify", Keywords::KEY_REACTION_MODIFY), std::map::value_type("reaction_temperature_modify", Keywords::KEY_REACTION_TEMPERATURE_MODIFY), -std::map::value_type("solid_solution_modify", Keywords::KEY_SOLID_SOLUTION_MODIFY), +std::map::value_type("solid_solution_modify", Keywords::KEY_SOLID_SOLUTIONS_MODIFY), std::map::value_type("reaction_pressure", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW), @@ -194,7 +194,6 @@ std::map::value_type(Keywords::KEY_DELETE std::map::value_type(Keywords::KEY_RUN_CELLS, "RUN_CELLS"), std::map::value_type(Keywords::KEY_REACTION_MODIFY, "REACTION_MODIFY"), std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), -std::map::value_type(Keywords::KEY_SOLID_SOLUTION_MODIFY, "SOLID_SOLUTION_MODIFY"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") diff --git a/Keywords.h b/Keywords.h index 7077d712..d5429cea 100644 --- a/Keywords.h +++ b/Keywords.h @@ -73,7 +73,6 @@ public: KEY_RUN_CELLS, KEY_REACTION_MODIFY, KEY_REACTION_TEMPERATURE_MODIFY, - KEY_SOLID_SOLUTION_MODIFY, KEY_REACTION_PRESSURE, KEY_REACTION_PRESSURE_RAW, KEY_REACTION_PRESSURE_MODIFY, diff --git a/PBasic.cpp b/PBasic.cpp index 7dc7923f..addf1d17 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2172,7 +2172,7 @@ factor(struct LOC_exec * LINK) case toks_s: { const char * str = stringfactor(STR1, LINK); - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_s_s_comp(str); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_ss_comp(str); } break; @@ -2275,7 +2275,7 @@ factor(struct LOC_exec * LINK) elt_name = NULL; } require(tokrp, LINK); - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sum_match_s_s(mytemplate, elt_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sum_match_ss(mytemplate, elt_name); break; case tokcalc_value: @@ -2576,7 +2576,7 @@ factor(struct LOC_exec * LINK) */ // return total moles - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->list_s_s(s_s_name, composition); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->list_ss(s_s_name, composition); /* * fill in varrec structure diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6dafb4cb..a878f322 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -13,6 +13,7 @@ #include "phqalloc.h" #include "PBasic.h" #include "Temperature.h" +#include "SSassemblage.h" Phreeqc::Phreeqc(PHRQ_io *io) { @@ -245,13 +246,23 @@ size_t Phreeqc::list_components(std::list &list_c) } // solid-solutions + { + std::map::const_iterator cit = Rxn_ss_assemblage_map.begin(); + for (; cit != Rxn_ss_assemblage_map.end(); cit++) + { + cxxSSassemblage entity = cit->second; + entity.totalize(this); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } + } +#ifdef SKIP for (i = 0; i < count_ss_assemblage; i++) { cxxSSassemblage entity(&ss_assemblage[i]); entity.totalize(this); accumulator.add_extensive(entity.Get_totals(), 1.0); } - +#endif // kinetics for (i = 0; i < count_kinetics; i++) { @@ -334,7 +345,7 @@ void Phreeqc::init(void) max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; max_kinetics = MAX_PP_ASSEMBLAGE; - max_ss_assemblage = MAX_PP_ASSEMBLAGE; + //max_ss_assemblage = MAX_PP_ASSEMBLAGE; max_elements = MAX_ELEMENTS; max_elts = MAX_ELTS; @@ -354,7 +365,7 @@ void Phreeqc::init(void) count_surface = 0; //count_gas_phase = 0; count_kinetics = 0; - count_ss_assemblage = 0; + //count_ss_assemblage = 0; count_elements = 0; //count_irrev = 0; @@ -406,7 +417,7 @@ void Phreeqc::init(void) surface = 0; //gas_phase = 0; kinetics = 0; - ss_assemblage = 0; + //ss_assemblage = 0; cell_data = 0; elements = 0; elt_list = 0; @@ -706,7 +717,7 @@ void Phreeqc::init(void) } pitzer_pe = FALSE; - count_pp = count_pg = count_s_s = 0; // used in store_get_equi_reactants + count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants /* * SIT */ diff --git a/Phreeqc.h b/Phreeqc.h index 81aa9ec0..2cf6c8ed 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -91,9 +91,9 @@ public: LDBLE find_gas_comp(const char *gas_comp_name); LDBLE find_gas_p(void); LDBLE find_gas_vm(void); - LDBLE find_misc1(const char *s_s_name); - LDBLE find_misc2(const char *s_s_name); - LDBLE find_s_s_comp(const char *s_s_comp_name); + LDBLE find_misc1(const char *ss_name); + LDBLE find_misc2(const char *ss_name); + LDBLE find_ss_comp(const char *ss_comp_name); LDBLE get_calculate_value(const char *name); char * iso_unit(const char *total_name); LDBLE iso_value(const char *total_name); @@ -109,7 +109,7 @@ public: LDBLE solution_sum_secondary(const char *total_name); LDBLE sum_match_gases(const char *stemplate, const char *name); LDBLE sum_match_species(const char *stemplate, const char *name); - LDBLE sum_match_s_s(const char *stemplate, const char *name); + LDBLE sum_match_ss(const char *stemplate, const char *name); int match_elts_in_species(const char *name, const char *stemplate); int extract_bracket(char **string, char *bracket_string); LDBLE surf_total(const char *total_name, const char *surface_name); @@ -117,14 +117,14 @@ public: LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); - LDBLE list_s_s(std::string s_s_name, cxxNameDouble &composition); + LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); int system_total_elements(void); int system_total_si(void); int system_total_aq(void); int system_total_ex(void); int system_total_surf(void); int system_total_gas(void); - int system_total_s_s(void); + int system_total_ss(void); int system_total_elt(const char *total_name); int system_total_elt_secondary(const char *total_name); LDBLE total(const char *total_name); @@ -133,7 +133,7 @@ public: int system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, - struct ss_assemblage *ss_assemblage_ptr, + cxxSSassemblage *ss_assemblage_ptr, struct surface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); @@ -398,7 +398,7 @@ public: int set_reaction(int i, int use_mix, int use_kinetics); int set_transport(int i, int use_mix, int use_kinetics, int nsaver); int store_get_equi_reactants(int k, int kin_end); - int count_pp, count_pg, count_s_s; + int count_pp, count_pg, count_ss; LDBLE *x0_moles; // mainsubs.cpp ------------------------------- @@ -434,7 +434,7 @@ public: int model(void); int jacobian_sums(void); int mb_gases(void); - int mb_s_s(void); + int mb_ss(void); int mb_sums(void); int molalities(int allow_overflow); int reset(void); @@ -442,11 +442,11 @@ public: int set(int initial); int sum_species(void); int surface_model(void); - LDBLE s_s_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); - LDBLE s_s_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); - LDBLE s_s_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, LDBLE xbaq); int numerical_jacobian(void); void set_inert_moles(void); @@ -457,12 +457,12 @@ public: #endif int calc_gas_pressures(void); int calc_fixed_volume_gas_pressures(void); - int calc_s_s_fractions(void); + int calc_ss_fractions(void); int gammas(LDBLE mu); int initial_guesses(void); int revise_guesses(void); - int s_s_binary(struct s_s *s_s_ptr); - int s_s_ideal(struct s_s *s_s_ptr); + int ss_binary(cxxSS *ss_ptr); + int ss_ideal(cxxSS *ss_ptr); //int remove_unstable_phases; int gas_in; void ineq_init(int max_row_count, int max_column_count); @@ -832,9 +832,9 @@ public: int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); //int add_reaction(struct irrev *irrev_ptr, int step_number, // LDBLE step_fraction); - int add_reaction(cxxReaction *reaction_ptr, int step_number, - LDBLE step_fraction); - int add_ss_assemblage(struct ss_assemblage *ss_assemblage_ptr); + int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); + //int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); + int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); int add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive); int add_surface(struct surface *surface_ptr); @@ -846,7 +846,7 @@ public: //int reaction_calc(struct irrev *irrev_ptr); int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); - int ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr); + int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); // structures.cpp ------------------------------- int clean_up(void); @@ -970,6 +970,7 @@ protected: struct species *s_search(const char *name); struct species *s_store(const char *name, LDBLE z, int replace_if_found); public: +#ifdef SKIP struct ss_assemblage *ss_assemblage_alloc(void); struct ss_assemblage *ss_assemblage_bsearch(int k, int *n); protected: @@ -984,7 +985,7 @@ protected: int ss_assemblage_delete(int n_user_old); public: int ss_assemblage_free(struct ss_assemblage *ss_assemblage_ptr); -protected: + int ss_assemblage_init(struct ss_assemblage *ss_assemblage_ptr, int n_user, int n_user_end, char *description); int ss_assemblage_ptr_to_user(struct ss_assemblage *ss_assemblage_ptr_old, @@ -995,6 +996,8 @@ protected: struct ss_assemblage *ss_assemblage_search(int n_user, int *n); int ss_assemblage_sort(void); static int s_s_compare(const void *ptr1, const void *ptr2); +#endif +protected: struct save_values *save_values_bsearch(struct save_values *k, int *n); static int save_values_compare(const void *ptr1, const void *ptr2); int save_values_sort(void); @@ -1115,8 +1118,8 @@ public: //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); struct solution * cxxSolution2solution(const cxxSolution * sol); struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); - struct ss_assemblage * cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss); - struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp); + //struct ss_assemblage * cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss); + //struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp); struct surface * cxxSurface2surface(const cxxSurface * surf); struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); @@ -1160,7 +1163,8 @@ public: int add_logks(struct logk *logk_ptr, int repeats); LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); int replace_solids_gases(void); - int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); + //int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); + int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); public: @@ -1195,7 +1199,7 @@ public: int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); static LDBLE f_spinodal(LDBLE x, void *); int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); - int s_s_calc_a0_a1(struct s_s *s_s_ptr); + int ss_calc_a0_a1(cxxSS *ss_ptr); // transport.cpp ------------------------------- int transport(void); @@ -1406,10 +1410,10 @@ protected: /*---------------------------------------------------------------------- * Solid solution *---------------------------------------------------------------------- */ - - int count_ss_assemblage; - int max_ss_assemblage; - struct ss_assemblage *ss_assemblage; + std::map Rxn_ss_assemblage_map; + //int count_ss_assemblage; + //int max_ss_assemblage; + //struct ss_assemblage *ss_assemblage; /*---------------------------------------------------------------------- * Pure-phase assemblage *---------------------------------------------------------------------- */ @@ -1644,7 +1648,7 @@ protected: struct unknown *surface_unknown; struct unknown *gas_unknown; struct unknown *slack_unknown; - struct unknown *s_s_unknown; + struct unknown *ss_unknown; std::vector gas_unknowns; /*---------------------------------------------------------------------- * Reaction work space @@ -1909,7 +1913,7 @@ public: N_Vector kinetics_y, kinetics_abstol; void *kinetics_cvode_mem; //struct pp_assemblage *cvode_pp_assemblage_save; - struct ss_assemblage *cvode_ss_assemblage_save; + cxxSSassemblage *cvode_ss_assemblage_save; cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; LDBLE *m_temp; diff --git a/ReadClass.cxx b/ReadClass.cxx index 63807fe7..138105a2 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -394,7 +394,7 @@ read_kinetics_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solid_solutions_raw(void) @@ -490,6 +490,7 @@ read_solid_solutions_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -915,6 +916,7 @@ read_surface_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solid_solutions_modify(void) @@ -1003,6 +1005,7 @@ read_solid_solutions_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_modify(void) @@ -1298,6 +1301,22 @@ delete_entities(void) } // ss_assemblages + if (delete_info.Get_ss_assemblage().Get_defined()) + { + if (delete_info.Get_ss_assemblage().Get_numbers().size() == 0) + { + Rxn_ss_assemblage_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_ss_assemblage().Get_numbers().begin(); it != delete_info.Get_ss_assemblage().Get_numbers().end(); it++) + { + Rxn_ss_assemblage_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_ss_assemblage().Get_defined()) { if (delete_info.Get_ss_assemblage().Get_numbers().size() == 0) @@ -1319,7 +1338,7 @@ delete_entities(void) } } } - +#endif // gas_phases if (delete_info.Get_gas_phase().Get_defined()) { @@ -1774,6 +1793,27 @@ dump_ostream(std::ostream& os) } // ss_assemblages + if (dump_info.Get_bool_ss_assemblage()) + { + if (dump_info.Get_ss_assemblage().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_ss_assemblage_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_ss_assemblage().begin(); it != dump_info.Get_ss_assemblage().end(); it++) + { + cxxSSassemblage *p = Utilities::Rxn_find(Rxn_ss_assemblage_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_ss_assemblage()) { if (dump_info.Get_ss_assemblage().size() == 0) @@ -1798,7 +1838,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // gas_phases if (dump_info.Get_bool_gas_phase()) { diff --git a/SS.cxx b/SS.cxx index 00550f27..ed83e862 100644 --- a/SS.cxx +++ b/SS.cxx @@ -25,20 +25,26 @@ PHRQ_base(io) // default constructor for cxxSS // { - //total_moles = 0; + + total_moles = 0; + dn = 0; a0 = 0; a1 = 0; - ag0 = 0; + LDBLE ag0 = 0; ag1 = 0; + ss_in = false; miscibility = false; - //spinodal = false; - //tk = 25.; + spinodal = false; + tk = 298.15; xb1 = 0; xb2 = 0; - //SS_PARAMETER_TYPE type = SS_PARM_NONE; - //LDBLE p[4]; + input_case = SS_PARM_NONE; + for (int i = 0; i < 4; i++) + { + p.push_back(0); + } } - +#ifdef SKIP cxxSS::cxxSS(struct s_s *s_s_ptr, PHRQ_io *io) : PHRQ_base(io) // @@ -68,7 +74,7 @@ PHRQ_base(io) // comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles; } } - +#endif cxxSS::~cxxSS() { } @@ -127,8 +133,13 @@ cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const //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 << indent1 << "-components " << "\n"; + //this->comps.dump_raw(s_oss, indent + 2); + 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); + } } void @@ -248,13 +259,12 @@ cxxSS::read_raw(CParser & parser, bool check) break; case 4: // components - if (this->comps.read_raw(parser, next_char) != CParser::PARSER_OK) { - parser.incr_input_error(); - parser.error_msg("Expected phase name and moles for comps.", - PHRQ_io::OT_CONTINUE); + cxxSScomp comp(io); + comp.read_raw(parser, false); + this->ss_comps.push_back(comp); } - opt_save = 4; + opt_save = CParser::OPT_DEFAULT; break; case 5: // miscibility @@ -454,7 +464,29 @@ cxxSS::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) *dd = d; } #endif - +void +cxxSS::totalize(PHREEQC_PTR_ARG) +{ + this->totals.clear(); + // component structures + for (size_t i = 0; i < this->ss_comps.size(); i++) + { + struct phase *phase_ptr; + int l; + phase_ptr = P_INSTANCE_POINTER phase_bsearch(ss_comps[i].Get_name().c_str(), &l, FALSE); + if (phase_ptr != NULL) + { + cxxNameDouble phase_formula(phase_ptr->next_elt); + this->totals.add_extensive(phase_formula, ss_comps[i].Get_moles()); + } + else + { + assert(false); + } + } + return; +} +#ifdef SKIP void cxxSS::totalize(PHREEQC_PTR_ARG) { @@ -478,7 +510,48 @@ cxxSS::totalize(PHREEQC_PTR_ARG) } return; } - +#endif +void +cxxSS::add(const cxxSS & addee_in, LDBLE extensive) +{ + if (extensive == 0.0) + return; + if (addee_in.name.size() == 0) + return; + cxxSS addee = addee_in; + for (size_t j = 0; j < addee.Get_ss_comps().size(); j++) + { + size_t i; + for (i = 0; i < this->ss_comps.size(); i++) + { + //look for component in this + if (Utilities::strcmp_nocase(this->ss_comps[i].Get_name().c_str(), + addee.Get_ss_comps()[j].Get_name().c_str()) == 0) + { + double d = this->ss_comps[i].Get_initial_moles() + + addee.Get_ss_comps()[j].Get_initial_moles() * extensive; + this->ss_comps[i].Set_initial_moles(d); + d = this->ss_comps[i].Get_moles() + + addee.Get_ss_comps()[j].Get_moles() * extensive; + this->ss_comps[i].Set_moles(d); + d = this->ss_comps[i].Get_init_moles() + + addee.Get_ss_comps()[j].Get_init_moles() * extensive; + this->ss_comps[i].Set_init_moles(d); + d = this->ss_comps[i].Get_delta() + + addee.Get_ss_comps()[j].Get_delta() * extensive; + this->ss_comps[i].Set_delta(d); + break; + } + } + if (i == this->ss_comps.size()) + { + cxxSScomp comp = addee.Get_ss_comps()[j]; + comp.multiply(extensive); + this->Get_ss_comps().push_back(comp); + } + } +} +#ifdef SKIP void cxxSS::add(const cxxSS & addee, LDBLE extensive) { @@ -497,7 +570,24 @@ cxxSS::add(const cxxSS & addee, LDBLE extensive) //bool miscibility; //LDBLE xb1, xb2; } - +#endif +void +cxxSS::multiply(LDBLE extensive) +{ + size_t i; + for (i = 0; i < this->ss_comps.size(); i++) + { + double d = this->ss_comps[i].Get_initial_moles() * extensive; + this->ss_comps[i].Set_initial_moles(d); + d = this->ss_comps[i].Get_moles() * extensive; + this->ss_comps[i].Set_moles(d); + d = this->ss_comps[i].Get_init_moles() * extensive; + this->ss_comps[i].Set_init_moles(d); + d = this->ss_comps[i].Get_delta() * extensive; + this->ss_comps[i].Set_delta(d); + } +} +#ifdef SKIP void cxxSS::multiply(LDBLE extensive) { @@ -509,3 +599,15 @@ cxxSS::multiply(LDBLE extensive) //bool miscibility; //LDBLE xb1, xb2; } +#endif +cxxSScomp * +cxxSS::Find(const char * comp_name) +{ + + for (size_t i = 0; i < this->ss_comps.size(); i++) + { + if (ss_comps[i].Get_name() == comp_name) + return &(ss_comps[i]); + } + return NULL; +} \ No newline at end of file diff --git a/SS.h b/SS.h index 88aa5984..98babea7 100644 --- a/SS.h +++ b/SS.h @@ -2,20 +2,22 @@ #define SSASSEMBLAGESS_H_INCLUDED #include // assert -#include // std::map +#include #include // std::string #include // std::list #include // std::vector #include "phrqtype.h" #include "NameDouble.h" #include "Phreeqc_class.h" +#include "SScomp.h" + class cxxSS: public PHRQ_base { public: cxxSS(PHRQ_io *io=NULL); - cxxSS(struct s_s *, PHRQ_io *io=NULL); + //cxxSS(struct s_s *, PHRQ_io *io=NULL); ~cxxSS(); enum SS_PARAMETER_TYPE @@ -43,6 +45,7 @@ class cxxSS: public PHRQ_base { return this->name; } + void Set_name (const std::string & s) {this->name = s;} void Set_name (const char * s) { if (s != NULL) @@ -56,34 +59,69 @@ class cxxSS: public PHRQ_base { return (this->totals); }; +#ifdef SKIP const cxxNameDouble & Get_comps() const { return (this->comps); }; - +#endif #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif + cxxSScomp * Find(const char * comp_name); void add(const cxxSS & comp, LDBLE extensive); void multiply(LDBLE extensive); - LDBLE Get_a0() const {return (this->a0);}; - LDBLE Get_a1() const {return (this->a1);}; - LDBLE Get_ag0() const {return (this->ag0);}; - LDBLE Get_ag1() const {return (this->ag1);}; - bool Get_miscibility() const {return (this->miscibility);}; - LDBLE Get_xb1() const {return (this->xb1);}; - LDBLE Get_xb2() const {return (this->xb2);}; + + LDBLE Get_total_moles(void) const {return total_moles;} + void Set_total_moles(LDBLE t) {total_moles = t;} + + LDBLE Get_dn(void) const {return (this->dn);} + void Set_dn(LDBLE t) {this->dn = t;} + + LDBLE Get_a0() const {return (this->a0);} + void Set_a0(LDBLE t) {a0 = t;} + LDBLE Get_a1() const {return (this->a1);} + void Set_a1(LDBLE t) {a1 = t;} + LDBLE Get_ag0() const {return (this->ag0);} + void Set_ag0(LDBLE t) {ag0 = t;} + LDBLE Get_ag1() const {return (this->ag1);} + void Set_ag1(LDBLE t) {ag1 = t;} + bool Get_ss_in() const {return (this->ss_in);} + void Set_ss_in(bool t) {ss_in = t;} + bool Get_miscibility() const {return (this->miscibility);} + void Set_miscibility(bool t) {miscibility = t;} + bool Get_spinodal() const {return (this->spinodal);} + void Set_spinodal(bool t) {spinodal = t;} + LDBLE Get_xb1() const {return (this->xb1);} + void Set_xb1(LDBLE t) {xb1 = t;} + LDBLE Get_xb2() const {return (this->xb2);} + void Set_xb2(LDBLE t) {xb2 = t;} + std::vector & Get_ss_comps(void) {return ss_comps;} + void Set_ss_comps(const std::vector & comps) {ss_comps = comps;} + + LDBLE Get_tk(void) {return this->tk;} + 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 Get_p(void) {return this->p;} + void Set_p(const std::vector & t) {this->p = t;} protected: std::string name; - cxxNameDouble comps; + //cxxNameDouble comps; + LDBLE total_moles; + LDBLE dn; LDBLE a0, a1; LDBLE ag0, ag1; + bool ss_in; bool miscibility; - LDBLE xb1, xb2; + bool spinodal; + LDBLE tk, xb1, xb2; + SS_PARAMETER_TYPE input_case; + std::vector ss_comps; + std::vector p; cxxNameDouble totals; - public: }; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 94f70ffd..d1d480ab 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -27,7 +27,7 @@ cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) : cxxNumKeyword(io) { } - +#ifdef SKIP cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * ss_assemblage_ptr, PHRQ_io * io) // // constructor for cxxSSassemblage from struct SSassemblage @@ -43,16 +43,17 @@ cxxNumKeyword(io) { cxxSS ssSS(&(ss_assemblage_ptr->s_s[i]), this->Get_io()); std::string str(ssSS.Get_name()); - ssAssemblageSSs[str] = ssSS; + SSs[str] = ssSS; } } +#endif cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxSSassemblage > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; - //std::list ssAssemblageSSs; + //std::list SSs; // // Mix // @@ -95,11 +96,11 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const // eltList this->eltList.dump_xml(s_oss, indent + 1); - // ssAssemblageSSs + // SSs s_oss << indent1; s_oss << "::const_iterator it = - ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + SSs.begin(); it != SSs.end(); ++it) { it->dump_xml(s_oss, indent + 2); } @@ -124,9 +125,9 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) int n_user_local = (n_out != NULL) ? *n_out : this->n_user; s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << "\n"; - // ssAssemblageSSs + // SSs for (std::map < std::string, cxxSS >::const_iterator it = - ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + SSs.begin(); it != SSs.end(); ++it) { s_oss << indent1; s_oss << "-solid_solution" << "\n"; @@ -198,9 +199,9 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) CParser reread(is, this->Get_io()); reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - if (this->ssAssemblageSSs.find(ec.Get_name()) != this->ssAssemblageSSs.end()) + if (this->SSs.find(ec.Get_name()) != this->SSs.end()) { - cxxSS & ec1 = this->ssAssemblageSSs.find(ec.Get_name())->second; + cxxSS & ec1 = this->SSs.find(ec.Get_name())->second; ec1.read_raw(reread, false); } else @@ -208,7 +209,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) cxxSS ec1(this->Get_io()); ec1.read_raw(reread, false); std::string str(ec1.Get_name()); - this->ssAssemblageSSs[str] = ec1; + this->SSs[str] = ec1; } } useLastLine = true; @@ -228,9 +229,9 @@ cxxSSassemblage::mpi_pack(std::vector < int >&ints, { /* int n_user; */ ints.push_back(this->n_user); - ints.push_back((int) this->ssAssemblageSSs.size()); + ints.push_back((int) this->SSs.size()); for (std::map < std::string, cxxSS >::iterator it = - this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); + this->SSs.begin(); it != this->SSs.end(); it++) { (*it).second.mpi_pack(ints, doubles); @@ -250,13 +251,13 @@ cxxSSassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) this->description = " "; int count = ints[i++]; - this->ssAssemblageSSs.clear(); + this->SSs.clear(); for (int n = 0; n < count; n++) { cxxSS ssc; ssc.mpi_unpack(ints, &i, doubles, &d); std::string str(ssc.get_name()); - this->ssAssemblageSSs[str] = ssc; + this->SSs[str] = ssc; } *ii = i; *dd = d; @@ -269,7 +270,7 @@ cxxSSassemblage::totalize(PHREEQC_PTR_ARG) this->totals.clear(); // component structures for (std::map < std::string, cxxSS >::iterator it = - ssAssemblageSSs.begin(); it != ssAssemblageSSs.end(); ++it) + SSs.begin(); it != SSs.end(); ++it) { (*it).second.totalize(P_INSTANCE); this->totals.add_extensive((*it).second.Get_totals(), 1.0); @@ -286,12 +287,12 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, LDBLE extensive) return; for (std::map < std::string, cxxSS >::const_iterator itadd = - addee.ssAssemblageSSs.begin(); itadd != addee.ssAssemblageSSs.end(); + addee.SSs.begin(); itadd != addee.SSs.end(); ++itadd) { std::map < std::string, cxxSS >::iterator it = - this->ssAssemblageSSs.find((*itadd).first); - if (it != this->ssAssemblageSSs.end()) + this->SSs.find((*itadd).first); + if (it != this->SSs.end()) { (*it).second.add((*itadd).second, extensive); } @@ -300,8 +301,28 @@ cxxSSassemblage::add(const cxxSSassemblage & addee, LDBLE extensive) cxxSS entity = (*itadd).second; entity.multiply(extensive); std::string str(entity.Get_name()); - this->ssAssemblageSSs[str] = entity; + this->SSs[str] = entity; } } } +std::vector cxxSSassemblage:: +Vectorize(void) +{ + std::vector ss_v; + std::map::iterator it; + for (it = this->SSs.begin(); it != this->SSs.end(); it++) + { + ss_v.push_back(&(it->second)); + } + return ss_v; +} +cxxSS * cxxSSassemblage:: +Find(const std::string &s) +{ + std::map::iterator it; + it = this->SSs.find(s); + if (it != this->SSs.end()) + return &(it->second); + return NULL; +} \ No newline at end of file diff --git a/SSassemblage.h b/SSassemblage.h index 4426e39a..5ed16d35 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -11,6 +11,7 @@ #include "NumKeyword.h" #include "NameDouble.h" #include "Phreeqc_class.h" +#include "SS.h" class cxxSS; @@ -22,7 +23,7 @@ class cxxSSassemblage:public cxxNumKeyword public: cxxSSassemblage(PHRQ_io * io = NULL); - cxxSSassemblage(struct ss_assemblage *, PHRQ_io * io = NULL); + //cxxSSassemblage(struct ss_assemblage *, PHRQ_io * io = NULL); cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); @@ -32,10 +33,6 @@ public: void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; void read_raw(CParser & parser, bool check = true); - const std::map & Get_ssAssemblageSSs() const - { - return this->ssAssemblageSSs; - }; #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); @@ -43,17 +40,18 @@ public: #endif void totalize(PHREEQC_PTR_ARG); - const cxxNameDouble & Get_totals() const - { - return this->totals; - }; - - -protected: + const cxxNameDouble & Get_totals() const {return this->totals;} + std::map < std::string, cxxSS > & Get_SSs(void) {return SSs;} + void Set_SSs(std::map < std::string, cxxSS > & ss) {SSs = ss;} + bool Get_new_def(void) const {return new_def;} + void Set_new_def(bool tf) {new_def = tf;} + std::vector Vectorize(void); void add(const cxxSSassemblage & addee, LDBLE extensive); + cxxSS *Find(const std::string &s); protected: - std::map < std::string, cxxSS > ssAssemblageSSs; + bool new_def; + std::map < std::string, cxxSS > SSs; cxxNameDouble totals; }; diff --git a/Use.h b/Use.h index acc8afa1..db3455ab 100644 --- a/Use.h +++ b/Use.h @@ -7,6 +7,7 @@ class cxxExchange; class cxxGasPhase; class cxxPressure; class cxxTemperature; +class cxxSSassemblage; class cxxUse { @@ -84,7 +85,7 @@ public: cxxTemperature * Get_temperature_ptr(void) const {return this->temperature_ptr;} cxxGasPhase * Get_gas_phase_ptr(void) const {return this->gas_phase_ptr;} struct inverse * Get_inverse_ptr(void) const {return this->inverse_ptr;} - struct ss_assemblage * Get_ss_assemblage_ptr(void) const {return this->ss_assemblage_ptr;} + cxxSSassemblage * Get_ss_assemblage_ptr(void) {return this->ss_assemblage_ptr;} void Set_solution_ptr(struct solution * p) {this->solution_ptr = p;} void Set_pp_assemblage_ptr(cxxPPassemblage * p) {this->pp_assemblage_ptr = p;} @@ -97,7 +98,7 @@ public: void Set_temperature_ptr(cxxTemperature * p) {this->temperature_ptr = p;} void Set_gas_phase_ptr(cxxGasPhase * p) {this->gas_phase_ptr = p;} void Set_inverse_ptr(struct inverse * p) {this->inverse_ptr = p;} - void Set_ss_assemblage_ptr(struct ss_assemblage * p) {this->ss_assemblage_ptr = p;} + void Set_ss_assemblage_ptr(cxxSSassemblage * p) {this->ss_assemblage_ptr = p;} protected: bool solution_in; @@ -147,7 +148,7 @@ protected: bool ss_assemblage_in; int n_ss_assemblage_user; - struct ss_assemblage *ss_assemblage_ptr; + cxxSSassemblage *ss_assemblage_ptr; bool trans_in; bool advect_in; diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 87d300e4..12b218e9 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -6,7 +6,7 @@ #include "../Exchange.h" #include "../GasPhase.h" #include "PPassemblage.h" - +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: activity(const char *species_name) @@ -825,6 +825,95 @@ find_gas_vm(void) } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: +find_misc1(const char *ss_name) +/* ---------------------------------------------------------------------- */ +{ + //int j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0.0); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + if (strcmp_nocase(ss_ptr->Get_name().c_str(), ss_name) == 0) + { + if (ss_ptr->Get_miscibility()) + { + return (ss_ptr->Get_xb1()); + } + else + { + return (1.0); + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_misc2(const char *ss_name) +/* ---------------------------------------------------------------------- */ +{ + //int j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0.0); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + if (strcmp_nocase(ss_ptr->Get_name().c_str(), ss_name) == 0) + { + if (ss_ptr->Get_miscibility()) + { + return (ss_ptr->Get_xb2()); + } + else + { + return (1.0); + } + } + } + return (0); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +find_ss_comp(const char *ss_comp_name) +/* ---------------------------------------------------------------------- */ +{ + //int i, j; + + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + for (size_t i = 0; i < ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + if (strcmp_nocase(comp_ptr->Get_name().c_str(), ss_comp_name) == 0) + { + if (ss_ptr->Get_ss_in()) + { + return (comp_ptr->Get_moles()); + } + else + { + return (0.0); + } + } + } + } + return (0); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: find_misc1(const char *s_s_name) /* ---------------------------------------------------------------------- */ { @@ -892,7 +981,7 @@ find_s_s_comp(const char *s_s_comp_name) (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, s_s_comp_name) == 0) { - if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) { return (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles); } @@ -905,7 +994,7 @@ find_s_s_comp(const char *s_s_comp_name) } return (0); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: get_calculate_value(const char *name) @@ -1276,7 +1365,86 @@ sum_match_species(const char *mytemplate, const char *name) } return (tot); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_ss(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + //int i, j; + LDBLE tot; + struct elt_list *next_elt; + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + tot = 0; + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + if (strcmp_nocase(ss_ptr->Get_name().c_str(), mytemplate) == 0) + { + if (!ss_ptr->Get_ss_in()) + { + tot = 0; + break; + } + for (size_t i = 0; i < ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + if (name == NULL) + { + tot += comp_ptr->Get_moles(); + } + else + { + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + for (next_elt = phase_ptr->next_elt; next_elt->elt != NULL; next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += next_elt->coef * comp_ptr->Get_moles(); + break; + } + } + } + } + break; + } + } + return (tot); +} + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +list_ss(std::string ss_name, cxxNameDouble &composition) +/* ---------------------------------------------------------------------- */ +{ + //int i, j; + + LDBLE tot = 0; + composition.clear(); + if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) + return (0); + + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + if (strcmp_nocase(ss_ptr->Get_name().c_str(), ss_name.c_str()) == 0) + { + for (size_t i = 0; i < ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + composition.add(comp_ptr->Get_name().c_str(), comp_ptr->Get_moles()); + tot += comp_ptr->Get_moles(); + } + break; + } + } + return (tot); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sum_match_s_s(const char *mytemplate, const char *name) @@ -1294,7 +1462,7 @@ sum_match_s_s(const char *mytemplate, const char *name) if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, mytemplate) == 0) { - if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == FALSE) + if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == FALSE) { tot = 0; break; @@ -1353,7 +1521,7 @@ list_s_s(std::string s_s_name, cxxNameDouble &composition) } return (tot); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: match_elts_in_species(const char *name, const char *mytemplate) @@ -1875,7 +2043,7 @@ system_total(const char *total_name, LDBLE * count, char ***names, } else if (strcmp_nocase(total_name, "s_s") == 0) { - system_total_s_s(); + system_total_ss(); } else if (strcmp_nocase(total_name, "gas") == 0) { @@ -2239,6 +2407,42 @@ system_total_gas(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +system_total_ss(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + //int i, k; + +/* + * Solid solutions + */ + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t k = 0; k < ss_ptrs.size(); k++) + { + cxxSS *ss_ptr = ss_ptrs[k]; + for (size_t i = 0; i < ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + sys[count_sys].name = string_duplicate(phase_ptr->name); + sys[count_sys].moles = comp_ptr->Get_moles(); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: system_total_s_s(void) /* ---------------------------------------------------------------------- */ { @@ -2270,7 +2474,7 @@ system_total_s_s(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: system_total_elt(const char *total_name) @@ -2453,11 +2657,55 @@ system_total_elt(const char *total_name) /* * Solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t k = 0; k < ss_ptrs.size(); k++) + { + cxxSS *ss_ptr = ss_ptrs[k]; + if (ss_ptr->Get_ss_in()) + { + for (size_t i = 0; i < ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + count_elts = 0; + paren_count = 0; + add_elt_list(phase_ptr->next_elt, + comp_ptr->Get_moles()); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), + elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, + &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) { - if (use.Get_ss_assemblage_ptr()->s_s[k].s_s_in == TRUE) + if (use.Get_ss_assemblage_ptr()->s_s[k].ss_in == TRUE) { for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; i++) @@ -2495,6 +2743,7 @@ system_total_elt(const char *total_name) } } } +#endif /* * find total in gas phase */ @@ -2725,11 +2974,55 @@ system_total_elt_secondary(const char *total_name) /* * Solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + cxxSS *ss_ptr = ss_ptrs[i]; + if (ss_ptr->Get_ss_in()) + { + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + count_elts = 0; + paren_count = 0; + add_elt_list(phase_ptr->next_sys_total, + comp_ptr->Get_moles()); + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), + elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + sys[count_sys].name = + string_duplicate(phase_ptr->name); + sys[count_sys].moles = elt_list[j].coef; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("s_s"); + count_sys++; + space((void **) ((void *) &sys), count_sys, + &max_sys, sizeof(struct system_species)); + break; + } + } + } + } + } + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) { - if (use.Get_ss_assemblage_ptr()->s_s[k].s_s_in == TRUE) + if (use.Get_ss_assemblage_ptr()->s_s[k].ss_in == TRUE) { for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; i++) @@ -2767,6 +3060,7 @@ system_total_elt_secondary(const char *total_name) } } } +#endif /* * find total in gas phase */ @@ -2879,19 +3173,20 @@ system_species_compare(const void *ptr1, const void *ptr2) return (-1); return (0); } + /* ---------------------------------------------------------------------- */ int Phreeqc:: system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, - struct ss_assemblage *ss_assemblage_ptr, + cxxSSassemblage *ss_assemblage_ptr, struct surface *surface_ptr) /* ---------------------------------------------------------------------- */ { /* * Provides total moles in solid phases */ - int i, j; + int i; count_elts = 0; paren_count = 0; @@ -2913,6 +3208,23 @@ system_total_solids(cxxExchange *exchange_ptr, add_elt_list(surface_ptr->comps[i].totals, 1.0); } } + if (ss_assemblage_ptr != NULL) + { + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + cxxSS *ss_ptr = ss_ptrs[i]; + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + add_elt_list(phase_ptr->next_elt, + comp_ptr->Get_moles()); + } + } + } +#ifdef SKIP if (ss_assemblage_ptr != NULL) { for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) @@ -2925,6 +3237,7 @@ system_total_solids(cxxExchange *exchange_ptr, } } } +#endif if (gas_phase_ptr != NULL) { for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index f01f79e9..a68cc9ad 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -673,7 +673,7 @@ struct s_s LDBLE dn; LDBLE a0, a1; LDBLE ag0, ag1; - int s_s_in; + int ss_in; int miscibility; int spinodal; LDBLE tk, xb1, xb2; @@ -1075,8 +1075,8 @@ struct unknown const char * exch_comp; //struct pure_phase *pure_phase; const char *pp_assemblage_comp_name; - //struct s_s *s_s; - //struct s_s_comp *s_s_comp; + //struct ss *s_s; + //struct ss_comp *s_s_comp; const char * ss_name; const char * ss_comp_name; int ss_comp_number; diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 3afde67f..a7b83725 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -270,7 +270,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, int equal_rate, zero_rate; cxxPPassemblage *pp_assemblage_save = NULL; - struct ss_assemblage *ss_assemblage_save = NULL; + //struct ss_assemblage *ss_assemblage_save = NULL; + cxxSSassemblage *ss_assemblage_save = NULL; LDBLE b31 = 3. / 40., b32 = 9. / 40., b51 = -11. / 54., b53 = -70. / 27., b54 = 35. / 27., @@ -328,6 +329,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, malloc_error(); } #endif +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { ss_assemblage_save = @@ -336,7 +338,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, if (ss_assemblage_save == NULL) malloc_error(); } - +#endif kinetics_ptr = kinetics_bsearch(i, &m); step_bad = step_ok = 0; @@ -427,16 +429,15 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, */ if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage *pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); - cxxPPassemblage * pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_ptr->Get_n_user()); - assert(pp_ptr); - pp_assemblage_save = new cxxPPassemblage(*pp_ptr); + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_pp_assemblage_ptr()->Get_n_user()); + assert(pp_assemblage_ptr); + pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); } - if (ss_assemblage_save != NULL) + if (use.Get_ss_assemblage_ptr() != NULL) { - ss_assemblage_copy(use.Get_ss_assemblage_ptr(), - ss_assemblage_save, - use.Get_ss_assemblage_ptr()->n_user); + cxxSSassemblage * ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_ss_assemblage_ptr()->Get_n_user()); + assert(ss_assemblage_ptr); + ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); } for (j = 0; j < n_reactions; j++) { @@ -521,7 +522,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(ss_assemblage_save); + delete ss_assemblage_save; + ss_assemblage_save = NULL; } goto EQUAL_RATE_OUT; } @@ -566,9 +568,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } /* store k2 in rk_moles */ @@ -651,7 +652,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(ss_assemblage_save); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } goto EQUAL_RATE_OUT; } @@ -686,9 +688,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } /* store k3 in rk_moles */ @@ -770,8 +771,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(ss_assemblage_save); - } + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } goto EQUAL_RATE_OUT; } /* @@ -806,9 +808,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } /* store k4 in rk_moles */ @@ -858,9 +859,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } /* store k5 in rk_moles */ @@ -911,9 +911,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } /* store k6 in rk_moles */ @@ -1013,7 +1012,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(ss_assemblage_save); + delete ss_assemblage_save; + ss_assemblage_save = NULL; } /* * and increase step size ... @@ -1096,8 +1096,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_save = - (struct ss_assemblage *) free_check_null(ss_assemblage_save); + delete ss_assemblage_save; + ss_assemblage_save = NULL; } return (OK); } @@ -1113,7 +1113,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; cxxPPassemblage *pp_assemblage_save = NULL; - struct ss_assemblage *ss_assemblage_save = NULL; + cxxSSassemblage *ss_assemblage_save = NULL; struct kinetics *kinetics_save = NULL; @@ -1151,6 +1151,17 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); } + if (use.Get_ss_assemblage_ptr() != NULL) + { + cxxSSassemblage * ss_assemblage_ptr = (cxxSSassemblage *) use.Get_ss_assemblage_ptr(); + if (ss_assemblage_save) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } + ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { ss_assemblage_save = @@ -1161,6 +1172,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, ss_assemblage_copy(use.Get_ss_assemblage_ptr(), ss_assemblage_save, use.Get_ss_assemblage_ptr()->n_user); } +#endif if (use.Get_kinetics_ptr() != NULL) { kinetics_save = @@ -1324,10 +1336,8 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, - use.Get_ss_assemblage_ptr(), - ss_assemblage_save->n_user); + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } if (kinetics_save != NULL) { @@ -1409,9 +1419,8 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (ss_assemblage_save != NULL) { - ss_assemblage_free(ss_assemblage_save); - ss_assemblage_save = - (struct ss_assemblage *) free_check_null(ss_assemblage_save); + delete ss_assemblage_save; + ss_assemblage_save = NULL; } if (kinetics_save != NULL) { @@ -1710,8 +1719,9 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find ss_assemblage */ - int n_ss_assemblage; - use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); + //int n_ss_assemblage; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, i)); + //use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); //use.Set_n_ss_assemblage(n_ss_assemblage); if (use.Get_ss_assemblage_ptr() != NULL) { @@ -1887,9 +1897,7 @@ set_reaction(int i, int use_mix, int use_kinetics) */ if (use.Get_ss_assemblage_in() == TRUE) { - int n_ss_assemblage; - use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); - //use.Set_n_ss_assemblage(n_ss_assemblage); + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, i)); if (use.Get_ss_assemblage_ptr() == NULL) { error_string = sformatf( "Solid-solution Assemblage %d not found.", @@ -1940,7 +1948,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) int nsaver; struct kinetics *kinetics_ptr; cxxPPassemblage *pp_assemblage_ptr; - struct ss_assemblage *ss_assemblage_ptr; + cxxSSassemblage *ss_assemblage_ptr; cxxUse use_save; int save_old, m, n_reactions /*, nok, nbad */ ; @@ -2064,13 +2072,16 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) saver(); //pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); - ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); + //ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); + ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); if (pp_assemblage_ptr != NULL) { cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); } if (ss_assemblage_ptr != NULL) { + cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); +#ifdef SKIP cvode_ss_assemblage_save = (struct ss_assemblage *) PHRQ_malloc(sizeof(struct ss_assemblage)); @@ -2079,6 +2090,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) ss_assemblage_copy(ss_assemblage_ptr, cvode_ss_assemblage_save, ss_assemblage_ptr->n_user); +#endif } /* allocate space for CVODE */ @@ -2235,9 +2247,8 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } if (use.Get_ss_assemblage_ptr() != NULL) { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(cvode_ss_assemblage_save, - use.Get_ss_assemblage_ptr(), i); + Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); } calc_final_kinetic_reaction(kinetics_ptr); if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == @@ -2287,10 +2298,8 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } if (cvode_ss_assemblage_save != NULL) { - ss_assemblage_free(cvode_ss_assemblage_save); - cvode_ss_assemblage_save = - (struct ss_assemblage *) - free_check_null(cvode_ss_assemblage_save); + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = NULL; } return (OK); } @@ -2325,10 +2334,8 @@ free_cvode(void) } if (cvode_ss_assemblage_save != NULL) { - ss_assemblage_free(cvode_ss_assemblage_save); - cvode_ss_assemblage_save = - (struct ss_assemblage *) - free_check_null(cvode_ss_assemblage_save); + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = NULL; } return (OK); } @@ -2501,9 +2508,10 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find ss_assemblage */ - int n_ss_assemblage; - use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); + //int n_ss_assemblage; + //use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); //use.Set_n_ss_assemblage(n_ss_assemblage); + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, i)); if (use.Get_ss_assemblage_ptr() != NULL) { use.Set_ss_assemblage_in(true); @@ -2550,7 +2558,7 @@ int Phreeqc:: store_get_equi_reactants(int l, int kin_end) /* ---------------------------------------------------------------------- */ { - int i, j, k; + int i, k; if (use.Get_pp_assemblage_in() == TRUE) { @@ -2561,24 +2569,20 @@ store_get_equi_reactants(int l, int kin_end) cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); if (use.Get_gas_phase_in() == TRUE) { - //use.Get_gas_phase_ptr() = gas_phase_bsearch(l, &use.n_gas_phase); use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, l)); } else use.Set_gas_phase_ptr(NULL); if (use.Get_ss_assemblage_in() == TRUE) { - int n_ss_assemblage; - use.Set_ss_assemblage_ptr( - ss_assemblage_bsearch(l, &n_ss_assemblage)); - //use.Set_n_ss_assemblage(n_ss_assemblage); + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, l)); } else use.Set_ss_assemblage_ptr(NULL); if (kin_end == FALSE) { - count_pp = count_s_s = count_pg = 0; + count_pp = count_ss = count_pg = 0; if (use.Get_pp_assemblage_ptr() != NULL) //count_pp = use.Get_pp_assemblage_ptr()->count_comps; count_pp = (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); @@ -2587,6 +2591,16 @@ store_get_equi_reactants(int l, int kin_end) cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); count_pg = (int) gas_phase_ptr->Get_gas_comps().size(); } + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + cxxSS *ss_ptr = ss_ptrs[i]; + count_ss += (int) ss_ptr->Get_ss_comps().size(); + } + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) @@ -2598,7 +2612,8 @@ store_get_equi_reactants(int l, int kin_end) } } } - k = count_pp + count_s_s + count_pg; +#endif + k = count_pp + count_ss + count_pg; x0_moles = NULL; if (k == 0) return (OK); @@ -2635,15 +2650,16 @@ store_get_equi_reactants(int l, int kin_end) } } } - if (count_s_s != 0) + if (count_ss != 0) { - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; - i++) + cxxSS *ss_ptr = ss_ptrs[i]; + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) { - x0_moles[++k] = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + x0_moles[++k] = comp_ptr->Get_moles(); } /*!!!! also miscibility gap comps ?? */ @@ -2682,15 +2698,16 @@ store_get_equi_reactants(int l, int kin_end) gas_phase_ptr->Set_gas_comps(temp_comps); } } - if (count_s_s != 0) + if (count_ss != 0) { - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; - i++) + cxxSS *ss_ptr = ss_ptrs[i]; + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) { - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].initial_moles = - x0_moles[++k]; + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + comp_ptr->Set_initial_moles(x0_moles[++k]); } /*!!!! also miscibility gap comps ?? */ @@ -2756,9 +2773,8 @@ f(integertype N, realtype t, N_Vector y, N_Vector ydot, } if (pThis->use.Get_ss_assemblage_ptr() != NULL) { - pThis->ss_assemblage_free(pThis->use.Get_ss_assemblage_ptr()); - pThis->ss_assemblage_copy(pThis->cvode_ss_assemblage_save, - pThis->use.Get_ss_assemblage_ptr(), n_user); + pThis->Rxn_ss_assemblage_map[pThis->cvode_ss_assemblage_save->Get_n_user()] = *pThis->cvode_ss_assemblage_save; + pThis->use.Set_ss_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_ss_assemblage_map, pThis->cvode_ss_assemblage_save->Get_n_user())); } if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 407aa82a..517cb1aa 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -10,6 +10,7 @@ #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" +#include "SSassemblage.h" #if defined(WINDOWS) || defined(_WINDOWS) #include @@ -71,7 +72,7 @@ initialize(void) max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; max_kinetics = MAX_PP_ASSEMBLAGE; - max_ss_assemblage = MAX_PP_ASSEMBLAGE; + //max_ss_assemblage = MAX_PP_ASSEMBLAGE; max_elements = MAX_ELEMENTS; max_elts = MAX_ELTS; @@ -91,7 +92,7 @@ initialize(void) count_surface = 0; //count_gas_phase = 0; count_kinetics = 0; - count_ss_assemblage = 0; + //count_ss_assemblage = 0; count_elements = 0; //count_irrev = 0; @@ -160,8 +161,8 @@ initialize(void) space((void **) ((void *) &kinetics), INIT, &max_kinetics, sizeof(struct kinetics)); - space((void **) ((void *) &ss_assemblage), INIT, &max_ss_assemblage, - sizeof(struct ss_assemblage)); + //space((void **) ((void *) &ss_assemblage), INIT, &max_ss_assemblage, + // sizeof(struct ss_assemblage)); space((void **) ((void *) &cell_data), INIT, &count_cells, sizeof(struct cell_data)); @@ -705,7 +706,7 @@ initialize(void) solution_phase_boundary_unknown = NULL; surface_unknown = NULL; gas_unknown = NULL; - s_s_unknown = NULL; + ss_unknown = NULL; for (i = 0; i < MAX_LOG_K_INDICES; i++) { trxn.logk[i] = 0; @@ -1006,10 +1007,11 @@ set_use(void) */ if (use.Get_ss_assemblage_in() == TRUE) { - int n_ss_assemblage_user; - use.Set_ss_assemblage_ptr( - ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), - &n_ss_assemblage_user)); + //int n_ss_assemblage_user; + //use.Set_ss_assemblage_ptr( + // ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), + // &n_ss_assemblage_user)); + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user())); if (use.Get_ss_assemblage_ptr() == NULL) { error_string = sformatf( "ss_assemblage %d not found.", @@ -1648,11 +1650,12 @@ saver(void) { n = save.n_ss_assemblage_user; xss_assemblage_save(n); - for (i = save.n_ss_assemblage_user + 1; - i <= save.n_ss_assemblage_user_end; i++) - { - ss_assemblage_duplicate(n, i); - } + Utilities::Rxn_copies(Rxn_ss_assemblage_map, save.n_ss_assemblage_user, save.n_ss_assemblage_user_end); + //for (i = save.n_ss_assemblage_user + 1; + // i <= save.n_ss_assemblage_user_end; i++) + //{ + // ss_assemblage_duplicate(n, i); + //} } if (save.kinetics == TRUE && use.Get_kinetics_in() == TRUE /*&& use.Get_kinetics_ptr() != NULL */) @@ -1820,6 +1823,53 @@ int Phreeqc:: xss_assemblage_save(int n_user) /* ---------------------------------------------------------------------- */ { +/* + * Save ss_assemblage composition into structure ss_assemblage with user + * number n_user. + */ + //int i, j, n; + //int count_comps, count_s_s; + cxxSSassemblage temp_ss_assemblage; + //char token[MAX_LENGTH]; + + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); +/* + * Set ss_assemblage + */ + temp_ss_assemblage.Set_n_user(n_user); + temp_ss_assemblage.Set_n_user_end(n_user); + std::ostringstream msg; + msg << "Solid solution assemblage after simulation " << simulation; + temp_ss_assemblage.Set_description(msg.str().c_str()); + temp_ss_assemblage.Set_new_def(false); + temp_ss_assemblage.Set_SSs(use.Get_ss_assemblage_ptr()->Get_SSs()); + + std::vector ss_ptrs = temp_ss_assemblage.Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + cxxSS *ss_ptr = ss_ptrs[i]; + /* set initial moles for quick setup */ + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + comp_ptr->Set_initial_moles(comp_ptr->Get_moles()); + } + } +/* + * Finish up + */ + Rxn_ss_assemblage_map[n_user] = temp_ss_assemblage; + + use.Set_ss_assemblage_ptr(NULL); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +xss_assemblage_save(int n_user) +/* ---------------------------------------------------------------------- */ +{ /* * Save ss_assemblage composition into structure ss_assemblage with user * number n_user. @@ -1904,6 +1954,7 @@ xss_assemblage_save(int n_user) use.Set_ss_assemblage_ptr(NULL); return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: xpp_assemblage_save(int n_user) @@ -2727,7 +2778,8 @@ copy_use(int i) */ if (use.Get_ss_assemblage_in() == TRUE) { - ss_assemblage_duplicate(use.Get_n_ss_assemblage_user(), i); + //ss_assemblage_duplicate(use.Get_n_ss_assemblage_user(), i); + Utilities::Rxn_copy(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user(), i); save.ss_assemblage = TRUE; save.n_ss_assemblage_user = i; save.n_ss_assemblage_user_end = i; @@ -3185,16 +3237,16 @@ copy_entities(void) { for (j = 0; j < copy_ss_assemblage.count; j++) { - if (ss_assemblage_bsearch(copy_ss_assemblage.n_user[j], &n) != - NULL) + //if (ss_assemblage_bsearch(copy_ss_assemblage.n_user[j], &n) != NULL) + if (Utilities::Rxn_find(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j]) != NULL) { for (i = copy_ss_assemblage.start[j]; i <= copy_ss_assemblage.end[j]; i++) { if (i == copy_ss_assemblage.n_user[j]) continue; - ss_assemblage_duplicate(copy_ss_assemblage.n_user[j], - i); + //ss_assemblage_duplicate(copy_ss_assemblage.n_user[j], i); + Utilities::Rxn_copy(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j], i); } } else diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 218f8fbf..51e9b0a6 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -4,6 +4,7 @@ #include "Exchange.h" #include "GasPhase.h" #include "PPassemblage.h" +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -24,7 +25,7 @@ model(void) * molalities--calculate molalities * mb_sums--calculate mass-balance sums * mb_gases--decide if gas_phase exists - * mb_s_s--decide if solid_solutions exists + * mb_ss--decide if solid_solutions exists * switch_bases--check to see if new basis species is needed * reprep--rewrite equations with new basis species if needed * revise_guesses--revise unknowns to get initial mole balance @@ -80,7 +81,7 @@ model(void) for (;;) { mb_gases(); - mb_s_s(); + mb_ss(); l_kode = 1; while ((r = residuals()) != CONVERGED || remove_unstable_phases == TRUE) @@ -170,7 +171,7 @@ model(void) initial_surface_water(); mb_sums(); mb_gases(); - mb_s_s(); + mb_ss(); /* * Switch bases if necessary */ @@ -188,7 +189,7 @@ model(void) revise_guesses(); mb_sums(); mb_gases(); - mb_s_s(); + mb_ss(); } /* debug species_list_sort(); @@ -581,7 +582,7 @@ check_residuals(void) } else if (x[i]->type == SS_MOLES) { - if (x[i]->s_s_in == FALSE) + if (x[i]->ss_in == FALSE) continue; if (x[i]->moles <= MIN_TOTAL_SS) continue; @@ -1388,7 +1389,7 @@ ineq(int in_kode) * Solid solution */ } - else if (x[i]->type == SS_MOLES && x[i]->s_s_in == TRUE) + else if (x[i]->type == SS_MOLES && x[i]->ss_in == TRUE) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(array[i * (count_unknowns + 1)]), @@ -1769,13 +1770,13 @@ ineq(int in_kode) * Phase must be "in" and moles of solid solution must be >= zero */ - if (s_s_unknown != NULL) + if (ss_unknown != NULL) { - for (i = s_s_unknown->number; i < count_unknowns; i++) + for (i = ss_unknown->number; i < count_unknowns; i++) { if (x[i]->type != SS_MOLES) break; - if (x[i]->phase->in == TRUE && x[i]->s_s_in == TRUE) + if (x[i]->phase->in == TRUE && x[i]->ss_in == TRUE) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(zero[0]), @@ -2282,22 +2283,155 @@ mb_gases(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: -mb_s_s(void) +mb_ss(void) /* ---------------------------------------------------------------------- */ { - int i, j; + //int i, j; LDBLE lp, log10_iap, total_moles; LDBLE iapc, iapb, l_kc, l_kb, lc, lb, xcaq, xbaq, xb, xc; LDBLE sigmapi_aq, sigmapi_solid; LDBLE total_p; - struct s_s *s_s_ptr; struct rxn_token *rxn_ptr; - struct phase *phase_ptr; /* * Determines whether solid solution equation is needed */ - if (s_s_unknown == NULL || use.Get_ss_assemblage_ptr() == NULL) + if (ss_unknown == NULL || use.Get_ss_assemblage_ptr() == NULL) return (OK); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + //for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) + //{ + cxxSS *ss_ptr = ss_ptrs[i]; + total_moles = 0; + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + total_moles += comp_ptr->Get_moles(); + } + if (total_moles > 1e-13) + { + ss_ptr->Set_ss_in(true); + } + else if (ss_ptr->Get_a0() != 0.0 || ss_ptr->Get_a1() != 0.0) + { + int l; + struct phase *phase0_ptr = phase_bsearch(ss_ptr->Get_ss_comps()[0].Get_name().c_str(), &l, FALSE); + struct phase *phase1_ptr = phase_bsearch(ss_ptr->Get_ss_comps()[1].Get_name().c_str(), &l, FALSE); + /* + * Calculate IAPc and IAPb + */ + if (phase0_ptr->rxn_x != NULL) + { + log10_iap = 0; + for (rxn_ptr = phase0_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapc = exp(log10_iap * LOG_10); + } + else + { + iapc = 1e-99; + } + if (phase1_ptr->rxn_x != NULL) + { + log10_iap = 0; + for (rxn_ptr = phase1_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + log10_iap += rxn_ptr->s->la * rxn_ptr->coef; + } + iapb = exp(log10_iap * LOG_10); + } + else + { + iapb = 1e-99; + } + /* + * Calculate sigma pi, aq + */ + sigmapi_aq = iapc + iapb; + /* + * Calculate xc,aq and xb, aq + */ + xcaq = iapc / (iapb + iapc); + xbaq = iapb / (iapb + iapc); + /* + * Get Kc and Kb + */ + l_kc = exp(phase0_ptr->lk * LOG_10); + l_kb = exp(phase1_ptr->lk * LOG_10); + /* + * Solve for xb + */ + xb = ss_root(ss_ptr->Get_a0(), ss_ptr->Get_a1(), l_kc, l_kb, xcaq, xbaq); + /* + * Calculate lambdac and lambdab + */ + xc = 1 - xb; + lc = exp((ss_ptr->Get_a0() - ss_ptr->Get_a1() * (-4 * xb + 3)) * xb * xb); + lb = exp((ss_ptr->Get_a0() + ss_ptr->Get_a1() * (4 * xb - 1)) * xc * xc); + /* + * Calculate sigma pi, solid + */ + sigmapi_solid = xb * lb * l_kb + xc * lc * l_kc; + /* + * If Sigma pi, solid < sigma pi, aq, then use eqns + */ + if (sigmapi_solid < sigmapi_aq) + { + ss_ptr->Set_ss_in(true); + } + else + { + ss_ptr->Set_ss_in(false); + } + } + else + { + /* + * Calculate total mole fraction from solution activities + */ + total_p = 0; + //for (j = 0; j < s_s_ptr->count_comps; j++) + //{ + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + if (phase_ptr->in == TRUE) + { + lp = -phase_ptr->lk; + for (rxn_ptr = phase_ptr->rxn_x->token + 1; + rxn_ptr->s != NULL; rxn_ptr++) + { + lp += rxn_ptr->s->la * rxn_ptr->coef; + } + total_p += exp(lp * LOG_10); + } + } + if (total_p > 1.0) + { + ss_ptr->Set_ss_in(true); + } + else + { + ss_ptr->Set_ss_in(false); + } + } + } + for (int i = ss_unknown->number; i < count_unknowns; i++) + { + if (x[i]->type != SS_MOLES) + break; + cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + //x[i]->ss_in = x[i]->s_s->ss_in; + x[i]->ss_in = ss_ptr->Get_ss_in() ? TRUE : FALSE; + } +#ifdef SKIP for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) { s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[i]); @@ -2308,7 +2442,7 @@ mb_s_s(void) } if (total_moles > 1e-13) { - s_s_ptr->s_s_in = TRUE; + s_s_ptr->ss_in = TRUE; } else if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) { @@ -2376,11 +2510,11 @@ mb_s_s(void) */ if (sigmapi_solid < sigmapi_aq) { - s_s_ptr->s_s_in = TRUE; + s_s_ptr->ss_in = TRUE; } else { - s_s_ptr->s_s_in = FALSE; + s_s_ptr->ss_in = FALSE; } } else @@ -2405,20 +2539,21 @@ mb_s_s(void) } if (total_p > 1.0) { - s_s_ptr->s_s_in = TRUE; + s_s_ptr->ss_in = TRUE; } else { - s_s_ptr->s_s_in = FALSE; + s_s_ptr->ss_in = FALSE; } } } - for (i = s_s_unknown->number; i < count_unknowns; i++) + for (i = ss_unknown->number; i < count_unknowns; i++) { if (x[i]->type != SS_MOLES) break; - x[i]->s_s_in = x[i]->s_s->s_s_in; + x[i]->ss_in = x[i]->s_s->ss_in; } +#endif return (OK); } @@ -2633,7 +2768,7 @@ molalities(int allow_overflow) } calc_gas_pressures(); - calc_s_s_fractions(); + calc_ss_fractions(); return (OK); } @@ -2847,6 +2982,70 @@ calc_gas_pressures(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +calc_ss_fractions(void) +/* ---------------------------------------------------------------------- */ +{ + //int i, k; + LDBLE moles, n_tot; + //struct s_s *s_s_ptr; + +/* + * moles and lambdas for solid solutions + */ + if (ss_unknown == NULL) + return (OK); +/* + * Calculate mole fractions and log lambda and derivative factors + */ + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (size_t i = 0; i < ss_ptrs.size(); i++) + { + cxxSS *ss_ptr = ss_ptrs[i]; + n_tot = 0; + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + moles = comp_ptr->Get_moles(); + if (moles < 0) + { + moles = MIN_TOTAL_SS; + comp_ptr->Set_initial_moles(moles); + } + n_tot += moles; + } + ss_ptr->Set_total_moles(n_tot); + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + moles = comp_ptr->Get_moles(); + if (moles < 0) + { + moles = MIN_TOTAL_SS; + } + comp_ptr->Set_fraction_x(moles / n_tot); + comp_ptr->Set_log10_fraction_x(log10(moles / n_tot)); + + /* all mb and jacobian items must be in x or phase to be static between models */ + phase_ptr->log10_fraction_x = comp_ptr->Get_log10_fraction_x(); + } + if (ss_ptr->Get_a0() != 0.0 || ss_ptr->Get_a1() != 0) + { + ss_binary(ss_ptr); + } + else + { + ss_ideal(ss_ptr); + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: calc_s_s_fractions(void) /* ---------------------------------------------------------------------- */ { @@ -2857,7 +3056,7 @@ calc_s_s_fractions(void) /* * moles and lambdas for solid solutions */ - if (s_s_unknown == NULL) + if (ss_unknown == NULL) return (OK); /* * Calculate mole fractions and log lambda and derivative factors @@ -2904,7 +3103,132 @@ calc_s_s_fractions(void) } return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_binary(cxxSS *ss_ptr) +/* ---------------------------------------------------------------------- */ +{ + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE xb1, xc1; +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = ss_ptr->Get_total_moles(); + cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); + cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); + int l; + struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &l, FALSE); + struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &l, FALSE); + nc = comp0_ptr->Get_moles(); + xc = nc / n_tot; + nb = comp1_ptr->Get_moles(); + xb = nb / n_tot; +/* + * In miscibility gap + */ + l_a0 = ss_ptr->Get_a0(); + l_a1 = ss_ptr->Get_a1(); + if (ss_ptr->Get_miscibility() && xb > ss_ptr->Get_xb1() + && xb < ss_ptr->Get_xb2()) + { + xb1 = ss_ptr->Get_xb1(); + xc1 = 1.0 - xb1; + comp0_ptr->Set_fraction_x(xc1); + comp0_ptr->Set_log10_fraction_x(log10(xc1)); + phase0_ptr->log10_fraction_x = + comp0_ptr->Get_log10_fraction_x(); + + comp1_ptr->Set_fraction_x(xb1); + comp1_ptr->Set_log10_fraction_x(log10(xb1)); + phase1_ptr->log10_fraction_x = + comp1_ptr->Get_log10_fraction_x(); + + comp0_ptr->Set_log10_lambda( + xb1 * xb1 * (l_a0 - l_a1 * (3 - 4 * xb1)) / LOG_10); + phase0_ptr->log10_lambda = + comp0_ptr->Get_log10_lambda(); + + comp1_ptr->Set_log10_lambda( + xc1 * xc1 * (l_a0 + l_a1 * (4 * xb1 - 1)) / LOG_10); + phase1_ptr->log10_lambda = + comp1_ptr->Get_log10_lambda(); + + comp0_ptr->Set_dnb(0); + comp0_ptr->Set_dnc(0); + comp1_ptr->Set_dnb(0); + comp1_ptr->Set_dnc(0); + phase0_ptr->dnb = 0; + phase0_ptr->dnc = 0; + phase1_ptr->dnb = 0; + phase1_ptr->dnc = 0; + } + else + { +/* + * Not in miscibility gap + */ + comp0_ptr->Set_fraction_x(xc); + comp0_ptr->Set_log10_fraction_x(log10(xc)); + phase0_ptr->log10_fraction_x = + comp0_ptr->Get_log10_fraction_x(); + + comp1_ptr->Set_fraction_x(xb); + comp1_ptr->Set_log10_fraction_x(log10(xb)); + phase1_ptr->log10_fraction_x = + comp1_ptr->Get_log10_fraction_x(); + + comp0_ptr->Set_log10_lambda( + xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10); + phase0_ptr->log10_lambda = + comp0_ptr->Get_log10_lambda(); + + comp1_ptr->Set_log10_lambda( + xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10); + phase1_ptr->log10_lambda = + comp1_ptr->Get_log10_lambda(); + + xc2 = xc * xc; + xc3 = xc2 * xc; + xb2 = xb * xb; + xb3 = xb2 * xb; + xb4 = xb3 * xb; + + /* used derivation that did not substitute x2 = 1-x1 */ + + /* first component, df1/dn1 */ + dnc = 2 * l_a0 * xb2 + 12 * l_a1 * xc * xb2 + 6 * l_a1 * xb2; + phase0_ptr->dnc = -xb / nc + dnc / n_tot; + + + /* first component, df1/dn2 */ + dnb = + 1 - 2 * l_a0 * xb + 2 * l_a0 * xb2 + 8 * l_a1 * xc * xb - + 12 * l_a1 * xc * xb2 - 2 * l_a1 * xb + 2 * l_a1 * xb2; + phase0_ptr->dnb = dnb / n_tot; + + /* second component, df2/dn1 */ + dnc = + 1 - 2 * l_a0 * xc + 2 * l_a0 * xc2 - 8 * l_a1 * xb * xc + + 12 * l_a1 * xb * xc2 + 2 * l_a1 * xc - 2 * l_a1 * xc2; + phase1_ptr->dnc = dnc / n_tot; + + /* second component, df2/dn2 */ + dnb = 2 * l_a0 * xc2 + 12 * l_a1 * xb * xc2 - 6 * l_a1 * xc2; + phase1_ptr->dnb = -xc / nb + dnb / n_tot; + + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: s_s_binary(struct s_s *s_s_ptr) @@ -3024,7 +3348,56 @@ s_s_binary(struct s_s *s_s_ptr) } return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_ideal(cxxSS *ss_ptr) +/* ---------------------------------------------------------------------- */ +{ + //int k, j; + LDBLE n_tot, n_tot1; +/* + * component 0 is major component + * component 1 is minor component + * xb is the mole fraction of second component (formerly trace) + * xc is the mole fraction of first component (formerly major) +*/ +/* + * Calculate mole fractions and log lambda and derivative factors + */ + n_tot = ss_ptr->Get_total_moles(); + +/* + * Ideal solid solution + */ + ss_ptr->Set_dn(1.0 / n_tot); + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *compk_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phasek_ptr = phase_bsearch(compk_ptr->Get_name().c_str(), &l, FALSE); + n_tot1 = 0; + for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *compj_ptr = &(ss_ptr->Get_ss_comps()[j]); + if (j != k) + { + n_tot1 += compj_ptr->Get_moles(); + } + } + compk_ptr->Set_log10_lambda(0); + compk_ptr->Set_log10_lambda(0); + + compk_ptr->Set_dnb(-(n_tot1) / (compk_ptr->Get_moles() * n_tot)); + phasek_ptr->dnb = compk_ptr->Get_dnb(); + + compk_ptr->Set_dn(ss_ptr->Get_dn()); + phasek_ptr->dn = ss_ptr->Get_dn(); + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: s_s_ideal(struct s_s *s_s_ptr) @@ -3069,7 +3442,7 @@ s_s_ideal(struct s_s *s_s_ptr) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: reset(void) @@ -3100,7 +3473,7 @@ reset(void) step_up = log(step_size_now); factor = 1.; - if ((pure_phase_unknown != NULL || s_s_unknown != NULL) + if ((pure_phase_unknown != NULL || ss_unknown != NULL) && calculating_deriv == FALSE) { /* @@ -3188,6 +3561,24 @@ reset(void) } delta[i] = 0.0; } + else if (x[i]->ss_comp_name != NULL && delta[i] < -x[i]->phase->delta_max) + // Uses delta_max computed in step + // delta_max is the maximum amount of the mineral that could form based + // on the limiting element in the system + { + f0 = -delta[i] / x[i]->phase->delta_max; + if (f0 > factor) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s, Precipitating too much mineral.\t%f\n", + x[i]->description, (double) f0)); + } + factor = f0; + } + } +#ifdef SKIP else if (x[i]->s_s_comp != NULL && delta[i] < -x[i]->s_s_comp->phase->delta_max) // Uses delta_max computed in step // delta_max is the maximum amount of the mineral that could form based @@ -3205,6 +3596,7 @@ reset(void) factor = f0; } } +#endif } } } @@ -3229,7 +3621,7 @@ reset(void) warning_msg(error_string); } if (pure_phase_unknown != NULL || gas_unknown != NULL - || s_s_unknown != NULL) + || ss_unknown != NULL) { for (i = 0; i < count_unknowns; i++) { @@ -3778,7 +4170,7 @@ reset(void) { /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ - /*if (x[i]->s_s_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE; */ + /*if (x[i]->ss_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE; */ if (debug_model == TRUE) { output_msg(sformatf( @@ -3791,7 +4183,9 @@ reset(void) x[i]->moles -= delta[i]; if (x[i]->moles < MIN_TOTAL_SS && calculating_deriv == FALSE) x[i]->moles = MIN_TOTAL_SS; - x[i]->s_s_comp->moles = x[i]->moles; + cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + cxxSScomp *comp_ptr = ss_ptr->Find(x[i]->ss_comp_name); + comp_ptr->Set_moles(x[i]->moles); /* Pitzer gamma */ } else if (x[i]->type == PITZER_GAMMA) @@ -3814,7 +4208,7 @@ reset(void) * Reset total molalities in mass balance equations */ if (pure_phase_unknown != NULL || gas_unknown != NULL - || s_s_unknown != NULL) + || ss_unknown != NULL) { for (i = 0; i < count_unknowns; i++) { @@ -4120,7 +4514,7 @@ residuals(void) residual[i] = x[i]->f * LOG_10; //if (x[i]->moles <= MIN_TOTAL_SS && iterations > 2) // continue; - if (fabs(residual[i]) > l_toler && x[i]->s_s_in == TRUE) + if (fabs(residual[i]) > l_toler && x[i]->ss_in == TRUE) { if (print_fail) output_msg(sformatf( @@ -5168,7 +5562,7 @@ add_trivial_eqns(int rows, int cols, LDBLE * matrix) #define ZERO_TOL 1.0e-30 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -s_s_root(LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) +ss_root(LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) /* ---------------------------------------------------------------------- */ { int i; @@ -5179,12 +5573,12 @@ s_s_root(LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) */ x0 = 0.0; x1 = 0.0; - y0 = s_s_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + y0 = ss_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); miny = fabs(y0); for (i = 1; i <= 10; i++) { x1 = (LDBLE) i / 10; - y1 = s_s_f(x1, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + y1 = ss_f(x1, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); if (fabs(y1) < miny) { miny = fabs(y1); @@ -5208,21 +5602,21 @@ s_s_root(LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) } else { - xb = s_s_halve(l_a0, l_a1, x0, x1, l_kc, l_kb, xcaq, xbaq); + xb = ss_halve(l_a0, l_a1, x0, x1, l_kc, l_kb, xcaq, xbaq); } return (xb); } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -s_s_halve(LDBLE l_a0, LDBLE l_a1, LDBLE x0, LDBLE x1, LDBLE l_kc, LDBLE l_kb, +ss_halve(LDBLE l_a0, LDBLE l_a1, LDBLE x0, LDBLE x1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) /* ---------------------------------------------------------------------- */ { int i; LDBLE l_x, y0, dx, y; - y0 = s_s_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + y0 = ss_f(x0, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); dx = (x1 - x0); /* * Loop for interval halving @@ -5231,7 +5625,7 @@ s_s_halve(LDBLE l_a0, LDBLE l_a1, LDBLE x0, LDBLE x1, LDBLE l_kc, LDBLE l_kb, { dx *= 0.5; l_x = x0 + dx; - y = s_s_f(l_x, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); + y = ss_f(l_x, l_a0, l_a1, l_kc, l_kb, xcaq, xbaq); if (dx < 1e-8 || y == 0) { break; @@ -5247,7 +5641,7 @@ s_s_halve(LDBLE l_a0, LDBLE l_a1, LDBLE x0, LDBLE x1, LDBLE l_kc, LDBLE l_kb, /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -s_s_f(LDBLE xb, LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, +ss_f(LDBLE xb, LDBLE l_a0, LDBLE l_a1, LDBLE l_kc, LDBLE l_kb, LDBLE xcaq, LDBLE xbaq) /* ---------------------------------------------------------------------- */ { @@ -5362,7 +5756,7 @@ numerical_jacobian(void) d2 = delta[i]; break; case SS_MOLES: - if (x[i]->s_s_in == FALSE) + if (x[i]->ss_in == FALSE) continue; for (j = 0; j < count_unknowns; j++) { @@ -5394,7 +5788,7 @@ numerical_jacobian(void) molalities(TRUE); mb_sums(); /* - mb_s_s(); + mb_ss(); mb_gases(); */ residuals(); @@ -5454,7 +5848,7 @@ numerical_jacobian(void) molalities(TRUE); mb_sums(); mb_gases(); - mb_s_s(); + mb_ss(); residuals(); free_check_null(base); calculating_deriv = FALSE; diff --git a/phreeqc/pitzer.cpp b/phreeqc/pitzer.cpp index 5c3890ca..604d6f7e 100644 --- a/phreeqc/pitzer.cpp +++ b/phreeqc/pitzer.cpp @@ -1817,7 +1817,7 @@ model_pz(void) * molalities--calculate molalities * mb_sums--calculate mass-balance sums * mb_gases--decide if gas_phase exists - * mb_s_s--decide if solid_solutions exists + * mb_ss--decide if solid_solutions exists * switch_bases--check to see if new basis species is needed * reprep--rewrite equations with new basis species if needed * pitzer_revise_guesses--revise unknowns to get initial mole balance @@ -1862,7 +1862,7 @@ model_pz(void) for (;;) { mb_gases(); - mb_s_s(); + mb_ss(); l_kode = 1; while ((r = residuals()) != CONVERGED || remove_unstable_phases == TRUE) @@ -1951,7 +1951,7 @@ model_pz(void) initial_surface_water(); mb_sums(); mb_gases(); - mb_s_s(); + mb_ss(); /* debug species_list_sort(); sum_species(); diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 035744f6..f0ae6f40 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -258,7 +258,7 @@ quick_setup(void) /* * ss_assemblage */ - if (s_s_unknown != NULL) + if (ss_unknown != NULL) { for (i = 0; i < count_unknowns; i++) { @@ -291,7 +291,7 @@ quick_setup(void) } } #ifdef SKIP - if (s_s_unknown != NULL) + if (ss_unknown != NULL) { for (i = 0; i < count_unknowns; i++) { @@ -717,7 +717,7 @@ build_ss_assemblage(void) //char token[MAX_LENGTH]; char *ptr; - if (s_s_unknown == NULL) + if (ss_unknown == NULL) return (OK); cxxSS * ss_ptr_old = NULL; col = 0; @@ -933,7 +933,7 @@ build_ss_assemblage(void) char token[MAX_LENGTH]; char *ptr; - if (s_s_unknown == NULL) + if (ss_unknown == NULL) return (OK); s_s_ptr_old = NULL; col = 0; @@ -2281,7 +2281,7 @@ clear(void) exchange_unknown = NULL; surface_unknown = NULL; gas_unknown = NULL; - s_s_unknown = NULL; + ss_unknown = NULL; /* * Free arrays used in model */ @@ -3751,7 +3751,7 @@ setup_ss_assemblage(void) /* * One for each component in each solid solution */ - s_s_unknown = NULL; + ss_unknown = NULL; std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); for (size_t j = 0; j < ss_ptrs.size(); j++) { @@ -3780,8 +3780,8 @@ setup_ss_assemblage(void) x[count_unknowns]->phase->dnc = comp_ptr->Get_dnc(); x[count_unknowns]->phase->log10_fraction_x = comp_ptr->Get_log10_fraction_x(); x[count_unknowns]->phase->log10_lambda =comp_ptr->Get_log10_lambda(); - if (s_s_unknown == NULL) - s_s_unknown = x[count_unknowns]; + if (ss_unknown == NULL) + ss_unknown = x[count_unknowns]; count_unknowns++; } } @@ -3803,7 +3803,7 @@ setup_ss_assemblage(void) /* * One for each component in each solid solution */ - s_s_unknown = NULL; + ss_unknown = NULL; for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) { for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) @@ -3838,8 +3838,8 @@ setup_ss_assemblage(void) use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_fraction_x; x[count_unknowns]->phase->log10_lambda = use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_lambda; - if (s_s_unknown == NULL) - s_s_unknown = x[count_unknowns]; + if (ss_unknown == NULL) + ss_unknown = x[count_unknowns]; count_unknowns++; } } @@ -6203,7 +6203,7 @@ save_model(void) std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); for (size_t j = 0; j < ss_ptrs.size(); j++) { - last_model.ss_assemblage[i] = string_hsave(ss_ptrs[j]->Get_name().c_str()); + last_model.ss_assemblage[j] = string_hsave(ss_ptrs[j]->Get_name().c_str()); } } else diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 9c8cdafb..18ddd473 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -9,6 +9,7 @@ #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -645,6 +646,130 @@ print_gas_phase(void) int Phreeqc:: print_ss_assemblage(void) /* ---------------------------------------------------------------------- */ +{ + /* + * Prints solid solution composition if present + */ + int i, j; + LDBLE delta_moles; + LDBLE nb, nc, xb, xb1, xb2, xb1moles, xb2moles; + + if (pr.ss_assemblage == FALSE || pr.all == FALSE) + return (OK); + if (use.Get_ss_assemblage_ptr() == NULL) + return (OK); + /* + * Print heading + */ + print_centered("Solid solutions"); + output_msg(sformatf("\n")); + output_msg(sformatf("%-15s %22s %11s %11s %11s\n\n", + "Solid solution", "Component", "Moles", "Delta moles", + "Mole fract")); + /* + * Print solid solutions + */ + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (j = 0; j < (int) ss_ptrs.size(); j++) + { + cxxSS * ss_ptr = ss_ptrs[j]; + if (ss_ptr->Get_ss_in()) + { + /* solid solution name, moles */ + output_msg(sformatf("%-15s %22s %11.2e\n", + ss_ptr->Get_name().c_str(), " ", + (double) ss_ptr->Get_total_moles())); + /* component name, moles, delta moles, mole fraction */ + + for (i = 0; i < (int) ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + if (state != TRANSPORT && state != PHAST) + { + delta_moles = + comp_ptr->Get_moles() - + comp_ptr->Get_initial_moles() - + comp_ptr->Get_delta(); + } + else + { + delta_moles = + comp_ptr->Get_moles() - + comp_ptr->Get_init_moles(); + } + output_msg(sformatf( + "%15s %22s %11.2e %11.2e %11.2e\n", " ", + comp_ptr->Get_name().c_str(), + (double) comp_ptr->Get_moles(), (double) delta_moles, + (double) (comp_ptr->Get_moles() / + ss_ptr->Get_total_moles()))); + } + if (ss_ptr->Get_miscibility()) + { + cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); + cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); + nc = comp0_ptr->Get_moles(); + nb = comp1_ptr->Get_moles(); + xb = nb / (nb + nc); + xb1 = ss_ptr->Get_xb1(); + xb2 = ss_ptr->Get_xb2(); + + if (xb > xb1 && xb < xb2) + { + xb2moles = (xb1 - 1) / xb1 * nb + nc; + xb2moles = xb2moles / ((xb1 - 1) / xb1 * xb2 + (1 - xb2)); + xb1moles = (nb - xb2moles * xb2) / xb1; + output_msg(sformatf( + "\n%14s Solid solution is in miscibility gap\n", + " ")); + output_msg(sformatf( + "%14s End members in pct of %s\n\n", " ", + comp1_ptr->Get_name().c_str())); + output_msg(sformatf("%22s %11g pct %11.2e\n", + " ", (double) xb1, (double) xb1moles)); + output_msg(sformatf("%22s %11g pct %11.2e\n", + " ", (double) xb2, (double) xb2moles)); + } + } + } + else + { + /* solid solution name, moles */ + output_msg(sformatf("%-15s %22s %11.2e\n", + ss_ptr->Get_name().c_str(), " ", + (double) 0.0)); + /* component name, moles, delta moles, mole fraction */ + for (i = 0; i < (int) ss_ptr->Get_ss_comps().size(); i++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); + if (state != TRANSPORT && state != PHAST) + { + delta_moles = + comp_ptr->Get_moles() - + comp_ptr->Get_initial_moles() - + comp_ptr->Get_delta(); + } + else + { + delta_moles = + comp_ptr->Get_moles() - + comp_ptr->Get_init_moles(); + } + output_msg(sformatf( + "%15s %22s %11.2e %11.2e %11.2e\n", " ", + comp_ptr->Get_name().c_str(), + (double) 0, (double) delta_moles, (double) 0)); + } + } + } + output_msg(sformatf("\n")); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ { /* * Prints solid solution composition if present @@ -669,9 +794,11 @@ print_ss_assemblage(void) /* * Print solid solutions */ - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (j = 0; j < ss_ptrs.size(); j++) { - if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + cxxSS * ss_ptr = ss_ptrs[j]; + if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) { /* solid solution name, moles */ output_msg(sformatf("%-15s %22s %11.2e\n", @@ -764,6 +891,7 @@ print_ss_assemblage(void) output_msg(sformatf("\n")); return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_reaction(void) @@ -2270,7 +2398,7 @@ print_using(void) //struct exchange *exchange_ptr; struct surface *surface_ptr; //struct pp_assemblage *pp_assemblage_ptr; - struct ss_assemblage *ss_assemblage_ptr; + //struct ss_assemblage *ss_assemblage_ptr; //struct gas_phase *gas_phase_ptr; //struct irrev *irrev_ptr; struct kinetics *kinetics_ptr; @@ -2342,13 +2470,23 @@ print_using(void) } if (use.Get_ss_assemblage_in() == TRUE) { - ss_assemblage_ptr = + cxxSSassemblage * ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user()); + output_msg(sformatf( + "Using solid solution assemblage %d.\t%s\n", + use.Get_n_ss_assemblage_user(), + ss_assemblage_ptr->Get_description().c_str())); + } +#ifdef SKIP + if (use.Get_ss_assemblage_in() == TRUE) + { + ss_assemblage_ptr = ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); output_msg(sformatf( "Using solid solution assemblage %d.\t%s\n", use.Get_n_ss_assemblage_user(), ss_assemblage_ptr->description)); } +#endif if (use.Get_gas_phase_in() == TRUE) { //gas_phase_ptr = gas_phase_bsearch(use.Get_n_gas_phase_user(), &n); @@ -2480,13 +2618,68 @@ punch_ss_assemblage(void) /* * Prints solid solution composition if present */ - int i, j, k; + int j, k; int found; LDBLE moles; /* * Print solid solutions */ + for (k = 0; k < punch.count_s_s; k++) + { + found = FALSE; + if (use.Get_ss_assemblage_ptr() != NULL) + { + std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); + for (j = 0; j < (int) ss_ptrs.size(); j++) + { + cxxSS * ss_ptr = ss_ptrs[j]; + for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + + if (strcmp_nocase(punch.s_s[k].name, comp_ptr->Get_name().c_str()) == 0) + { + if (ss_ptr->Get_ss_in()) + { + moles = comp_ptr->Get_moles(); + } + else + { + moles = 0; + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), + "%12.4e\t", (double) moles); + } + else + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), + "%20.12e\t", (double) moles); + } + found = TRUE; + break; + } + } + if (found == TRUE) + break; + } + } + if (found == FALSE) + { + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", (double) 0.0); + } + else + { + fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", + (double) 0.0); + } + } + } +#ifdef SKIP for (k = 0; k < punch.count_s_s; k++) { found = FALSE; @@ -2501,7 +2694,7 @@ punch_ss_assemblage(void) (punch.s_s[k].name, use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name) == 0) { - if (use.Get_ss_assemblage_ptr()->s_s[j].s_s_in == TRUE) + if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) { moles = use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; @@ -2541,6 +2734,7 @@ punch_ss_assemblage(void) } } } +#endif return (OK); } diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 42b6c0b5..114d33cf 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -276,7 +276,8 @@ read_input(void) read_kinetics_raw(); break; case Keywords::KEY_SOLID_SOLUTIONS_RAW: - read_solid_solutions_raw(); + //read_solid_solutions_raw(); + Utilities::Rxn_read_raw(Rxn_ss_assemblage_map, this); break; case Keywords::KEY_GAS_PHASE_RAW: //read_gas_phase_raw(); @@ -312,7 +313,7 @@ read_input(void) read_surface_modify(); break; case Keywords::KEY_SOLID_SOLUTIONS_MODIFY: - read_solid_solutions_modify(); + Utilities::Rxn_read_modify(Rxn_ss_assemblage_map, this); break; case Keywords::KEY_GAS_PHASE_MODIFY: //read_gas_phase_modify(); @@ -335,9 +336,6 @@ read_input(void) // keyword[LAST_C_KEYWORD + 22].keycount++; // read_reaction_temperature_modify(); // break; - case Keywords::KEY_SOLID_SOLUTION_MODIFY: - read_solid_solutions_modify(); - break; case Keywords::KEY_REACTION_PRESSURE: read_reaction_pressure(); break; @@ -9733,8 +9731,10 @@ read_solid_solutions(void) } // add last ss and clean up - 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; @@ -10275,7 +10275,7 @@ read_solid_solutions(void) ss_assemblage[n].s_s[number_s_s].a1 = 0.0; ss_assemblage[n].s_s[number_s_s].ag0 = 0.0; ss_assemblage[n].s_s[number_s_s].ag1 = 0.0; - ss_assemblage[n].s_s[number_s_s].s_s_in = FALSE; + ss_assemblage[n].s_s[number_s_s].ss_in = FALSE; ss_assemblage[n].s_s[number_s_s].miscibility = FALSE; ss_assemblage[n].s_s[number_s_s].spinodal = FALSE; ss_assemblage[n].s_s[number_s_s].tk = 298.15; diff --git a/phreeqc/sit.cpp b/phreeqc/sit.cpp index 9cddb622..986501e8 100644 --- a/phreeqc/sit.cpp +++ b/phreeqc/sit.cpp @@ -773,7 +773,8 @@ jacobian_sit(void) LDBLE *base; LDBLE d, d1, d2; int i, j; - +Restart: + int pz_max_unknowns = max_unknowns; if (full_pitzer == TRUE) { molalities(TRUE); @@ -850,6 +851,11 @@ jacobian_sit(void) break; } molalities(TRUE); + if (max_unknowns > pz_max_unknowns) + { + base = (LDBLE *) free_check_null(base); + goto Restart; + } if (full_pitzer == TRUE) sit(); mb_sums(); @@ -923,7 +929,7 @@ model_sit(void) * molalities--calculate molalities * mb_sums--calculate mass-balance sums * mb_gases--decide if gas_phase exists - * mb_s_s--decide if solid_solutions exists + * mb_ss--decide if solid_solutions exists * switch_bases--check to see if new basis species is needed * reprep--rewrite equations with new basis species if needed * sit_revise_guesses--revise unknowns to get initial mole balance @@ -968,7 +974,7 @@ model_sit(void) for (;;) { mb_gases(); - mb_s_s(); + mb_ss(); l_kode = 1; while ((r = residuals()) != CONVERGED || remove_unstable_phases == TRUE) @@ -1057,7 +1063,7 @@ model_sit(void) initial_surface_water(); mb_sums(); mb_gases(); - mb_s_s(); + mb_ss(); /* debug species_list_sort(); sum_species(); diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 73353f7e..fe36c7b5 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -14,6 +14,7 @@ #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -31,7 +32,7 @@ step(LDBLE step_fraction) LDBLE difftemp; int step_number; cxxPPassemblage *pp_assemblage_save = NULL; - struct ss_assemblage *ss_assemblage_save = NULL; + cxxSSassemblage *ss_assemblage_save = NULL; /* * Zero out global solution data */ @@ -65,7 +66,7 @@ step(LDBLE step_fraction) if (use.Get_reaction_ptr() != NULL) { //add_reaction(use.irrev_ptr, step_number, step_fraction); - add_reaction( (cxxReaction *)use.Get_reaction_ptr(), step_number, step_fraction); + add_reaction( use.Get_reaction_ptr(), step_number, step_fraction); } /* * Kinetics @@ -148,6 +149,12 @@ step(LDBLE step_fraction) /* * Solid solutions */ + if (use.Get_ss_assemblage_ptr() != NULL) + { + ss_assemblage_save = new cxxSSassemblage(*use.Get_ss_assemblage_ptr()); + add_ss_assemblage(use.Get_ss_assemblage_ptr()); + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { ss_assemblage_save = @@ -159,6 +166,7 @@ step(LDBLE step_fraction) use.Get_ss_assemblage_ptr()->n_user); add_ss_assemblage(use.Get_ss_assemblage_ptr()); } +#endif /* * Check that elements are available for gas components, * pure phases, and solid solutions @@ -188,6 +196,12 @@ step(LDBLE step_fraction) Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); } + if (use.Get_ss_assemblage_ptr() != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } +#ifdef SKIP if (use.Get_ss_assemblage_ptr() != NULL) { ss_assemblage_free(use.Get_ss_assemblage_ptr()); @@ -198,6 +212,7 @@ step(LDBLE step_fraction) (struct ss_assemblage *) free_check_null(ss_assemblage_save); } +#endif return (MASS_BALANCE); } /* @@ -217,12 +232,12 @@ step(LDBLE step_fraction) delete pp_assemblage_save; pp_assemblage_save = NULL; } - if (ss_assemblage_save != NULL) - { - ss_assemblage_free(ss_assemblage_save); - ss_assemblage_save = - (struct ss_assemblage *) free_check_null(ss_assemblage_save); - } + //if (ss_assemblage_save != NULL) + //{ + // ss_assemblage_free(ss_assemblage_save); + // ss_assemblage_save = + // (struct ss_assemblage *) free_check_null(ss_assemblage_save); + //} // // Solution -1 has sum of solution/mix, exchange, surface, gas_phase @@ -239,14 +254,11 @@ step(LDBLE step_fraction) sys_bin.Set_Solution(-1, soln); if (use.Get_pp_assemblage_in()) { - //cxxPPassemblage pp(use.Get_pp_assemblage_ptr(), phrq_io); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); - sys_bin.Set_PPassemblage(-1, *pp_assemblage_ptr); + sys_bin.Set_PPassemblage(-1, use.Get_pp_assemblage_ptr()); } if (use.Get_ss_assemblage_in()) { - cxxSSassemblage ss(use.Get_ss_assemblage_ptr()); - sys_bin.Set_SSassemblage(-1, ss); + sys_bin.Set_SSassemblage(-1, *use.Get_ss_assemblage_ptr()); } sys_bin.Set_System(-1); sys_bin.Get_System().totalize(PHREEQC_THIS); @@ -277,15 +289,18 @@ step(LDBLE step_fraction) } if (use.Get_ss_assemblage_in()) { - cxxSSassemblage *ss = sys_bin.Get_SSassemblage(-1); - std::map ::const_iterator it; - for (it = ss->Get_ssAssemblageSSs().begin(); it != ss->Get_ssAssemblageSSs().end(); it++) + cxxSSassemblage *ss_assemblage_ptr = sys_bin.Get_SSassemblage(-1); + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + //for (it = ss->Get_ssAssemblageSSs().begin(); it != ss->Get_ssAssemblageSSs().end(); it++) { - cxxNameDouble::const_iterator comp_it; - for (comp_it = (it->second).Get_comps().begin(); comp_it != (it->second).Get_comps().end(); comp_it++) + cxxSS * ss_ptr = ss_ptrs[j]; + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); int n; - struct phase *p_ptr = phase_bsearch((comp_it->first).c_str(), &n, FALSE); + struct phase *p_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &n, FALSE); + struct elt_list *e_ptr; LDBLE min = 1e10; for (e_ptr = p_ptr->next_elt; e_ptr->elt != NULL; e_ptr++) @@ -1261,7 +1276,109 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) } /* ---------------------------------------------------------------------- */ int Phreeqc:: -add_ss_assemblage(struct ss_assemblage *ss_assemblage_ptr) +add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Accumulate solid_solution data in master->totals and _x variables. + */ + int i, j, k; + LDBLE amount_to_add, total; + //struct s_s *s_s_ptr; + struct master *master_ptr; + //char token[MAX_LENGTH]; + char *ptr; + + if (ss_assemblage_ptr == NULL) + return (OK); + count_elts = 0; + paren_count = 0; +/* + * Check that all elements are in solution for phases with greater than zero mass + */ + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (i = 0; i < (int) ss_ptrs.size(); i++) + { + cxxSS * ss_ptr = ss_ptrs[i]; + count_elts = 0; + paren_count = 0; + for (j = 0; j < (int) ss_ptr->Get_ss_comps().size(); j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + int l; + struct phase * phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + + amount_to_add = 0.0; + comp_ptr->Set_delta(0.0); + if (comp_ptr->Get_moles() > 0.0) + { + //strcpy(token, s_s_ptr->comps[j].phase->formula); + char * token = string_duplicate(phase_ptr->formula); + ptr = &(token[0]); + get_elts_in_species(&ptr, 1.0); + free_check_null(token); + for (k = 0; k < count_elts; k++) + { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL_SS) + { + continue; + } + else + { + total = + (-master_ptr->total + 1e-10) / elt_list[k].coef; + if (amount_to_add < total) + { + amount_to_add = total; + } + } + } + } + if (comp_ptr->Get_moles() < amount_to_add) + { + amount_to_add = comp_ptr->Get_moles(); + } + if (amount_to_add > 0.0) + { + comp_ptr->Set_moles(comp_ptr->Get_moles() - amount_to_add); + comp_ptr->Set_delta(amount_to_add); +/* + * Add reaction to totals + */ + for (k = 0; k < count_elts; k++) + { + master_ptr = elt_list[k].elt->primary; + if (master_ptr->s == s_hplus) + { + total_h_x += elt_list[k].coef * amount_to_add; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += elt_list[k].coef * amount_to_add; + } + else + { + master_ptr->total += elt_list[k].coef * amount_to_add; + } + } + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) /* ---------------------------------------------------------------------- */ { /* @@ -1353,7 +1470,7 @@ add_ss_assemblage(struct ss_assemblage *ss_assemblage_ptr) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: add_kinetics(struct kinetics *kinetics_ptr) @@ -1629,6 +1746,83 @@ pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr) return (OK); } #endif + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Check for missing elements + */ + int j, k; + struct master *master_ptr; + + if (ss_assemblage_ptr == NULL) + return (OK); +/* + * Check that all elements are in solution for phases with zero mass + */ + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (j = 0; j < (int) ss_ptrs.size(); j++) + { + cxxSS * ss_ptr = ss_ptrs[j]; + for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + count_elts = 0; + paren_count = 0; + if (comp_ptr->Get_moles() <= 0.0) + { + add_elt_list(phase_ptr->next_elt, 1.0); + for (l = 0; l < count_elts; l++) + { + master_ptr = elt_list[l].elt->primary; + if (master_ptr->s == s_hplus) + { + continue; + } + else if (master_ptr->s == s_h2o) + { + continue; + } + else if (master_ptr->total > MIN_TOTAL_SS) + { + continue; + } + else + { + if (state != ADVECTION && state != TRANSPORT + && state != PHAST) + { + error_string = sformatf( + "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.", + elt_list[l].elt->name, + phase_ptr->name); + warning_msg(error_string); + } + } + /* + * Make la's of all master species for the element small, + * so SI will be small + * and no mass transfer will be calculated + */ + for (k = 0; k < count_master; k++) + { + if (master[k]->elt->primary == master_ptr) + { + master[k]->s->la = -9999.999; + } + } + } + } + } + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr) @@ -1701,7 +1895,7 @@ ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: solution_check(void) diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 5623f588..eb939ab6 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -5679,10 +5679,10 @@ unknown_alloc(void) unknown_ptr->s = NULL; unknown_ptr->exch_comp = NULL; //unknown_ptr->pure_phase = NULL; - unknown_ptr->s_s = NULL; - unknown_ptr->s_s_comp = NULL; - unknown_ptr->s_s_comp_number = 0; - unknown_ptr->s_s_in = FALSE; + unknown_ptr->ss_name = NULL; + unknown_ptr->ss_comp_name = NULL; + unknown_ptr->ss_comp_number = 0; + unknown_ptr->ss_in = FALSE; unknown_ptr->surface_comp = NULL; unknown_ptr->related_moles = 0.0; unknown_ptr->potential_unknown = NULL; @@ -5764,8 +5764,10 @@ system_duplicate(int i, int save_old) if (kinetics_bsearch(i, &n) != NULL) kinetics_duplicate(i, save_old); - if (ss_assemblage_bsearch(i, &n) != NULL) - ss_assemblage_duplicate(i, save_old); + + Utilities::Rxn_copy(Rxn_ss_assemblage_map, i, save_old); + //if (ss_assemblage_bsearch(i, &n) != NULL) + // ss_assemblage_duplicate(i, save_old); return (OK); } @@ -6045,10 +6047,16 @@ entity_exists(char *name, int n_user) } break; case Ss_phase: /* solid_solutions */ + if (Utilities::Rxn_find(Rxn_ss_assemblage_map, n_user) == NULL) + { + return_value = FALSE; + } +#ifdef SKIP if (ss_assemblage_bsearch(n_user, &i) == NULL) { return_value = FALSE; } +#endif break; } return (return_value); @@ -6507,7 +6515,7 @@ cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp) s_s_ptr[j].ag1 = (*it).second.Get_ag1(); //s_s_ptr[j].ag0 = 0; //s_s_ptr[j].ag1 = 0; - s_s_ptr[j].s_s_in = TRUE; + s_s_ptr[j].ss_in = TRUE; s_s_ptr[j].miscibility = (*it).second.Get_miscibility(); //s_s_ptr[j].spinodal = it->spinodal; s_s_ptr[j].spinodal = FALSE; @@ -7291,6 +7299,14 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) } #endif // SSassemblages + { + std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().find(n); + if (it != sb.Get_SSassemblages().end()) + { + Rxn_ss_assemblage_map[n] = it->second; + } + } +#ifdef SKIP { std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().find(n); @@ -7302,7 +7318,7 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); } } - +#endif // Surfaces { std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().find(n); @@ -7420,6 +7436,14 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) } #endif // SSassemblages + { + std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().begin(); + for ( ; it != sb.Get_SSassemblages().end(); it++) + { + Rxn_ss_assemblage_map[it->first] = it->second; + } + } +#ifdef SKIP { std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().begin(); for ( ; it != sb.Get_SSassemblages().end(); it++) @@ -7430,7 +7454,7 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); } } - +#endif // Surfaces { std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().begin(); diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index 706372ce..94999730 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -6,6 +6,7 @@ #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" +#include "SSassemblage.h" /* Calling sequence @@ -383,7 +384,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) //struct pp_assemblage *pp_assemblage_ptr; //struct exchange *exchange_ptr; struct surface *surface_ptr; - struct ss_assemblage *ss_assemblage_ptr; + //struct ss_assemblage *ss_assemblage_ptr; //struct gas_phase *gas_phase_ptr; struct kinetics *kinetics_ptr; struct kinetics_comp *kinetics_comp_ptr; @@ -565,6 +566,50 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; case Ss_phase: + if (n_user[Ss_phase] < 0) + break; + { + /* + * fill an solid solution phase + */ + + cxxSSassemblage * ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, n_user[Ss_phase]); + if (ss_assemblage_ptr == NULL) + break; + found = FALSE; + moles = 0.0; + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (j = 0; j < (int) ss_ptrs.size(); j++) + //for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) + { + cxxSS * ss_ptr = ss_ptrs[j]; + cxxSScomp * comp_ptr; + for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + { + comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + if (phase_ptr->name == tally_table[i].name) + break; + if (strcmp_nocase(phase_ptr->name, tally_table[i].name) == 0) + break; + } + if (k < (int) ss_ptr->Get_ss_comps().size()) + { + moles = comp_ptr->Get_moles(); + found = TRUE; + break; + } + } + if (found == FALSE) + break; + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); + } + break; +#ifdef SKIP /* * fill an solid solution phase */ @@ -601,6 +646,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) add_elt_list(tally_table[i].formula, moles); elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; +#endif case Gas_phase: /* * fill in gas phase @@ -761,9 +807,9 @@ build_tally_table(void) int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; //struct pp_assemblage *pp_assemblage_ptr; //struct pure_phase *pure_phase_ptr; - struct ss_assemblage *ss_assemblage_ptr; - struct s_s *s_s_ptr; - struct s_s_comp *s_s_comp_ptr; + //struct ss_assemblage *ss_assemblage_ptr; + //struct s_s *s_s_ptr; + //struct s_s_comp *s_s_comp_ptr; struct kinetics *kinetics_ptr; struct kinetics_comp *kinetics_comp_ptr; struct phase *phase_ptr; @@ -998,6 +1044,59 @@ build_tally_table(void) * Add solid-solution pure phases */ count_tt_ss_phase = 0; + if (Rxn_ss_assemblage_map.size() > 0) + { + /* + * Go through all components of all solid solutions in solid-solution assemblages + */ + std::map::iterator it; + for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + //for (i = 0; i < count_ss_assemblage; i++) + { + cxxSSassemblage *ss_assemblage_ptr = &(it->second); + //for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (j = 0; j < (int) ss_ptrs.size(); j++) + { + cxxSS * ss_ptr = ss_ptrs[j]; + //for (k = 0; k < s_s_ptr->count_comps; k++) + for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) + { + if (tally_table[l].type == Ss_phase && + tally_table[l].name == phase_ptr->name) + break; + } + if (l < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_ss_phase++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = phase_ptr->name; + tally_table[n].type = Ss_phase; + count_elts = 0; + paren_count = 0; + strcpy(token, phase_ptr->formula); + add_elt_list(phase_ptr->next_elt, 1.0); + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } + } +#ifdef SKIP if (count_ss_assemblage > 0) { /* @@ -1043,6 +1142,7 @@ build_tally_table(void) } } } +#endif /* * Add kinetic reactants */ @@ -1244,10 +1344,17 @@ add_all_components_tally(void) /* * Add solid-solution pure phases */ + std::map::iterator it; + for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + { + add_ss_assemblage(&(it->second)); + } +#ifdef SKIP for (i = 0; i < count_ss_assemblage; i++) { add_ss_assemblage(&ss_assemblage[i]); } +#endif /* * Add elements in kinetic reactions */ diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index b59e0ca2..16d93b7f 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -4,6 +4,8 @@ #include "Exchange.h" #include "GasPhase.h" #include "PPassemblage.h" +#include "SSassemblage.h" + #define ZERO_TOL 1.0e-30 /* ---------------------------------------------------------------------- */ @@ -165,11 +167,12 @@ tidy_model(void) } #endif /* solid solutions */ +#ifdef SKIP if (new_ss_assemblage) { ss_assemblage_sort(); } - +#endif /* surfaces */ if (new_surface) { @@ -1725,6 +1728,204 @@ tidy_pp_assemblage(void) int Phreeqc:: tidy_ss_assemblage(void) /* ---------------------------------------------------------------------- */ +{ + struct phase *phase_ptr; + LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; + LDBLE xb2, xb3, xb4, xc2, xc3; + LDBLE moles; +/* + * Find pointers for pure phases + */ + std::map::iterator it; + for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + { + count_elts = 0; + paren_count = 0; + cxxSSassemblage *ss_assemblage_ptr = &(it->second); + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (size_t j = 0; j < ss_ptrs.size(); j++) + { + cxxSS *ss_ptr = ss_ptrs[j]; + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp * comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + int k1; + phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &k1, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Phase not found in data base, %s, assemblage %d.", + comp_ptr->Get_name().c_str(), + ss_assemblage_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + continue; + } + else + { + //ss_assemblage[i].s_s[j].comps[k].phase = phase_ptr; + phase_ptr->moles_x = 0; + phase_ptr->fraction_x = 0; + } + if (comp_ptr->Get_moles() == NAN) + { + input_error++; + error_string = sformatf( + "Moles of solid solution component not defined, %s, assemblage %d.", + comp_ptr->Get_name().c_str(), + ss_assemblage_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + continue; + } + } + + if (ss_assemblage_ptr->Get_new_def()) + { + /* + * Calculate a0 and a1 first + */ + ss_calc_a0_a1(ss_ptr); + + n_tot = 0; + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp * comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + moles = comp_ptr->Get_moles(); + if (moles <= 0.0) + { + moles = MIN_TOTAL_SS; + comp_ptr->Set_initial_moles(moles); + } + n_tot += moles; + } + + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + { + cxxSScomp * comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + moles = comp_ptr->Get_moles(); + if (moles <= 0.0) + { + moles = MIN_TOTAL_SS; + } + comp_ptr->Set_fraction_x(moles / n_tot); + comp_ptr->Set_log10_fraction_x(log10(moles / n_tot)); + } + l_a0 = ss_ptr->Get_a0(); + l_a1 = ss_ptr->Get_a1(); + +/* + * Binary solid solution + */ + if (l_a0 != 0.0 || l_a1 != 0) + { + ss_ptr->Set_dn(1.0 / n_tot); + nc = ss_ptr->Get_ss_comps()[0].Get_moles(); + //nc = ss_assemblage[i].s_s[j].comps[0].moles; + if (nc == 0) + nc = MIN_TOTAL_SS; + nb = ss_ptr->Get_ss_comps()[1].Get_moles(); + if (nb == 0) + nb = MIN_TOTAL_SS; + xc = nc / n_tot; + xb = nb / n_tot; + + /* lambdas */ + ss_ptr->Get_ss_comps()[0].Set_log10_lambda(xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10); + //ss_assemblage[i].s_s[j].comps[0].log10_lambda = + // xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; + ss_ptr->Get_ss_comps()[1].Set_log10_lambda(xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10); + //ss_assemblage[i].s_s[j].comps[1].log10_lambda = + // xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; + + /* derivatives wrt nc and nb */ + xc2 = xc * xc; + xc3 = xc2 * xc; + xb2 = xb * xb; + xb3 = xb2 * xb; + xb4 = xb3 * xb; + + /* component 1 */ + dnb = + -2 * l_a0 * xb * xc2 - 8 * l_a1 * xb2 * xc2 + + 6 * l_a1 * xb * xc2 - 4 * l_a1 * xc * xb4 - + 8 * l_a1 * xb3 * xc2 - 4 * l_a1 * xb2 * xc3 - + 2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + + 6 * l_a1 * xc * xb2 + 1; + ss_ptr->Get_ss_comps()[0].Set_dnb(dnb / n_tot); + //ss_assemblage[i].s_s[j].comps[0].dnb = dnb / n_tot; + dnc = + 2 * l_a0 * xb3 + 2 * l_a0 * xc * xb2 + 8 * l_a1 * xb4 + + 8 * l_a1 * xc * xb3 - 2 * l_a1 * xb3 - 6 * l_a1 * xc * xb2; + ss_ptr->Get_ss_comps()[0].Set_dnc(-xb / nc + dnc / n_tot); + //ss_assemblage[i].s_s[j].comps[0].dnc = + // -xb / nc + dnc / n_tot; + ss_ptr->Get_ss_comps()[0].Set_dn(1.0 / n_tot); + //ss_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; + + /* component 2 */ + dnb = + 2 * l_a0 * xb * xc2 + 2 * l_a0 * xc3 + + 8 * l_a1 * xb2 * xc2 + 8 * l_a1 * xb * xc3 - + 2 * l_a1 * xb * xc2 - 6 * l_a1 * xc3; + ss_ptr->Get_ss_comps()[1].Set_dnb(-xc / nb + dnb / n_tot); + //ss_assemblage[i].s_s[j].comps[1].dnb = + // -xc / nb + dnb / n_tot; + dnc = + -2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + + 2 * l_a1 * xc * xb2 - 2 * l_a0 * xb * xc2 - + 8 * l_a1 * xb2 * xc2 + 6 * l_a1 * xb * xc2 + 1; + ss_ptr->Get_ss_comps()[1].Set_dnc(dnc / n_tot); + //ss_assemblage[i].s_s[j].comps[1].dnc = dnc / n_tot; + ss_prep(ss_ptr->Get_tk(), ss_ptr, TRUE); + //s_s_prep(ss_assemblage[i].s_s[j].tk, + // &(ss_assemblage[i].s_s[j]), TRUE); + ss_ptr->Get_ss_comps()[1].Set_dn(1.0 / n_tot); + //ss_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; +/* + * Ideal solid solution + */ + } + else + { + ss_ptr->Set_dn(1.0 / n_tot); + //ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; + for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) + //for (k = 0; k < s_s_ptr->count_comps; k++) + { + cxxSScomp * comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + comp_ptr->Set_log10_lambda(0); + //ss_assemblage[i].s_s[j].comps[k].log10_lambda = 0; + moles = comp_ptr->Get_moles(); + //moles = ss_assemblage[i].s_s[j].comps[k].moles; + if (moles <= 0.0) + moles = MIN_TOTAL_SS; + comp_ptr->Set_dnb((n_tot - moles) / (moles * n_tot)); + //ss_assemblage[i].s_s[j].comps[k].dnb = + // (n_tot - moles) / (moles * n_tot); + comp_ptr->Set_dn(1.0 / n_tot); + //ss_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; + } + } + } + } + ss_assemblage_ptr->Set_new_def(false); + //ss_assemblage[i].new_def = FALSE; + +/* + * Duplicate ss_assemblage if necessary + */ + int n_user = ss_assemblage_ptr->Get_n_user(); + int n_user_end = ss_assemblage_ptr->Get_n_user_end(); + Utilities::Rxn_copies(Rxn_ss_assemblage_map, n_user, n_user_end); + ss_assemblage_ptr->Set_n_user_end(n_user); + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_ss_assemblage(void) +/* ---------------------------------------------------------------------- */ { int i, j, k, k1, n_user, last; struct phase *phase_ptr; @@ -1905,7 +2106,7 @@ tidy_ss_assemblage(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_punch(void) @@ -3851,7 +4052,300 @@ tidy_kin_surface(void) } return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ss_prep(LDBLE t, cxxSS *ss_ptr, int print) +/* ---------------------------------------------------------------------- */ +{ + int i, j, k, converged, divisions; + LDBLE r, rt, ag0, ag1, crit_pt; + LDBLE xc, tc; + LDBLE l_x, x0, x1, xsm1, xsm2, xb1, xb2; + LDBLE xc1, xc2; + LDBLE facb1, faca1, spim1, xblm1, acrae, acrael, xliapt, xliapm; + LDBLE xaly, xaly1, xaly2; + LDBLE faca, facb, spialy, facal, facbl; + LDBLE tol; + if (pr.ss_assemblage == FALSE) + print = FALSE; + tol = 1e-6; + r = R_KJ_DEG_MOL; + rt = r * t; + a0 = ss_ptr->Get_ag0() / rt; + a1 = ss_ptr->Get_ag1() / rt; + ss_ptr->Set_a0(a0); + ss_ptr->Set_a1(a1); + ag0 = a0 * rt; + ag1 = a1 * rt; + cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); + cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); + struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &k, FALSE); + struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE); + kc = exp(k_calc(phase0_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + kb = exp(k_calc(phase1_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + //kc = exp(k_calc(ss_ptr->comps[0].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + //kb = exp(k_calc(ss_ptr->comps[1].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); + crit_pt = fabs(a0) + fabs(a1); +/* + * Default, no miscibility or spinodal gaps + */ + ss_ptr->Set_miscibility(false); + ss_ptr->Set_spinodal(false); + xsm1 = 0.5; + xsm2 = 0.5; + xb1 = 0.5; + xb2 = 0.5; + xc1 = 0; + xc2 = 0; + + if (crit_pt >= tol) + { +/* + * Miscibility gap information + */ + if (fabs(a1) < tol) + { + xc = 0.5; + tc = ag0 / (2 * r); + } + else + { + xc = 0.5 + (pow((ag0 * ag0 + 27 * ag1 * ag1), (LDBLE) 0.5) - + ag0) / (18 * ag1); + tc = (12 * ag1 * xc - 6 * ag1 + 2 * ag0) * (xc - xc * xc) / r; + } + if (print == TRUE) + { + error_string = sformatf( "Description of Solid Solution %s", + ss_ptr->Get_name().c_str()); + dup_print(error_string, TRUE); + } + if (print == TRUE) + { + output_msg(sformatf( + "\t Temperature: %g kelvin\n", + (double) t)); + output_msg(sformatf( + "\t A0 (dimensionless): %g\n", + (double) a0)); + output_msg(sformatf( + "\t A1 (dimensionless): %g\n", + (double) a1)); + output_msg(sformatf( + "\t A0 (kJ/mol): %g\n", + (double) ag0)); + output_msg(sformatf( + "\t A1 (kJ/mol): %g\n\n", + (double) ag1)); + } + if (xc < 0 || xc > 1) + { + if (print == TRUE) + output_msg(sformatf( + "No miscibility gap above 0 degrees kelvin.\n")); + } + else + { + if (print == TRUE) + { + output_msg(sformatf( + "\t Critical mole-fraction of component 2: %g\n", + (double) xc)); + output_msg(sformatf( + "\t Critical temperature: %g kelvin\n", + (double) tc)); + output_msg(sformatf( + "\n(The critical temperature calculation assumes that the Guggenheim model\ndefined at %g kelvin is valid at the critical temperature.)\n\n\n", + (double) t)); + } + } +/* + * Calculate miscibility and spinodal gaps + */ + if (tc >= t) + { + + /* search for sign changes */ + x0 = 0; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) + { + + /* find first spinodal pt */ + xsm1 = halve(f_spinodal, x0, x1, tol); + xsm1 = halve(f_spinodal, x0, x1, tol); + ss_ptr->Set_spinodal(true); + + /* find second spinodal pt */ + x0 = x1; + x1 = 1; + if (scan(f_spinodal, &x0, &x1) == TRUE) + { + xsm2 = halve(f_spinodal, x0, x1, tol); + } + else + { + error_msg("Failed to find second spinodal point.", STOP); + } + } + } + } +/* + * Now find Miscibility gap + */ + if (ss_ptr->Get_spinodal()) + { + if (print == TRUE) + output_msg(sformatf( + "\t Spinodal-gap mole fractions, component 2: %g\t%g\n", + (double) xsm1, (double) xsm2)); + converged = FALSE; + if (converged == FALSE) + { + for (i = 1; i < 3; i++) + { + divisions = (int) pow(10., i); + for (j = 0; j < divisions; j++) + { + for (k = divisions; k > 0; k--) + { + xc1 = (LDBLE) j / divisions + 0.001; + xc2 = (LDBLE) k / divisions; + converged = solve_misc(&xc1, &xc2, tol); + if (converged == TRUE) + break; + } + if (converged == TRUE) + break; + } + if (converged == TRUE) + break; + } + } + if (converged == FALSE) + { + error_msg("Failed to find miscibility gap.", STOP); + } + ss_ptr->Set_miscibility(true); + if (xc1 < xc2) + { + xb1 = 1 - xc2; + xb2 = 1 - xc1; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + } + else + { + xb1 = 1 - xc1; + xb2 = 1 - xc2; + } + facb1 = kb * xb1 * exp(xc1 * xc1 * (a0 + a1 * (4 * xb1 - 1))); + faca1 = kc * xc1 * exp(xb1 * xb1 * (a0 - a1 * (3 - 4 * xb1))); + spim1 = log10(faca1 + facb1); + xblm1 = 1. / (1. + faca1 / facb1); + acrae = facb1 / faca1; + acrael = log10(acrae); + xliapt = log10(facb1); + xliapm = log10(faca1); + + if (print == TRUE) + { + output_msg(sformatf( + "\t Miscibility-gap fractions, component 2: %g\t%g\n", + (double) xb1, (double) xb2)); + output_msg(sformatf( + "\n\t\t\tEutectic Point Calculations\n\n")); + output_msg(sformatf( + "\t Aqueous activity ratio (comp2/comp1): %g\n", + (double) acrae)); + output_msg(sformatf( + "\t Log aqueous activity ratio (comp2/comp1): %g\n", + (double) acrael)); + output_msg(sformatf( + "\t Aqueous activity fraction of component 2: %g\n", + (double) xblm1)); + output_msg(sformatf( + "\t Log IAP (component 2): %g\n", + (double) xliapt)); + output_msg(sformatf( + "\t Log IAP (component 1): %g\n", + (double) xliapm)); + output_msg(sformatf( + "\t Log Sum Pi: %g\n", + (double) spim1)); + } + ss_ptr->Set_tk(t); + ss_ptr->Set_xb1(xb1); + ss_ptr->Set_xb2(xb2); + } +/* + * Alyotropic point calculation + */ + xaly = -1.0; + l_x = a0 * a0 + 3 * a1 * a1 + 6 * a1 * log(kb / kc); + if (l_x > 0) + { + if (fabs(l_x - a0 * a0) >= tol) + { + xaly1 = (-(a0 - 3 * a1) + pow(l_x, (LDBLE) 0.5)) / (6 * a1); + xaly2 = (-(a0 - 3 * a1) - pow(l_x, (LDBLE) 0.5)) / (6 * a1); + if (xaly1 >= 0 && xaly1 <= 1) + { + xaly = xaly1; + } + if (xaly2 >= 0 && xaly2 <= 1) + { + xaly = xaly2; + } + } + else + { + xaly = 0.5 + log(kb / kc) / (2 * a0); + } + if (xaly > 0 && xaly < 1) + { + faca = + kc * (1 - + xaly) * exp(xaly * xaly * (a0 - a1 * (3 - 4 * xaly))); + facb = + kb * xaly * exp((1 - xaly) * (1 - xaly) * + (a0 + a1 * (4 * xaly - 1.0))); + spialy = log10(faca + facb); + facal = log10(faca); + facbl = log10(facb); + if (xaly > xb1 && xaly < xb2) + { + if (print == TRUE) + output_msg(sformatf( + "\nLocal minimum in the solidus curve coresponding to a maximum\nin the minimum stoichiometric saturation curve.\n\n")); + } + else + { + if (print == TRUE) + output_msg(sformatf( + "\n\t\t\tAlyotropic Point\n\n")); + } + if (print == TRUE) + { + output_msg(sformatf( + "\t Solid mole fraction of component 2: %g\n", + (double) xaly)); + output_msg(sformatf( + "\t Log IAP (component 2): %g\n", + (double) facbl)); + output_msg(sformatf( + "\t Log IAP (component 1): %g\n", + (double) facal)); + output_msg(sformatf( + "\t Log Sum Pi: %g\n", + (double) spialy)); + } + } + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) @@ -4139,7 +4633,7 @@ s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol) @@ -4454,10 +4948,378 @@ solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol) *xxc2 = xc2; return (converged); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -s_s_calc_a0_a1(struct s_s *s_s_ptr) +ss_calc_a0_a1(cxxSS *ss_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, done; + LDBLE r, rt; + std::vector p; + LDBLE q1, q2, xbq1, xbq2, xb1, xb2, xc1, xc2; + LDBLE r1, r2, pa1, pb1, pa2, pb2, xsm1, xsm2; + LDBLE pn9, pn10, c5, c6, pl9, pl10, pj9, pj10; + LDBLE xc, tc; + LDBLE spialy, azero, phi1, phi2, test; + LDBLE dq1, dq2, denom, ratio, dr1, dr2, x21, x22, x61, x62; + LDBLE l_a0, l_a1, ag0, ag1; + LDBLE wg2, wg1, alpha2, alpha3; + LDBLE l_kc, l_kb; + LDBLE xaly, xcaly, alpha0, alpha1, fx, fx1; + LDBLE tol; + + tol = 1e-6; + rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; + cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); + cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); + int k; + struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &k, FALSE); + struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE); + if (phase0_ptr == NULL || phase1_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Two components were not defined for %s solid solution", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + return (ERROR); + } + l_kc = exp(k_calc(phase0_ptr->rxn->logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) * + LOG_10); + l_kb = exp(k_calc(phase1_ptr->rxn->logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) * + LOG_10); + + p = ss_ptr->Get_p(); + + l_a0 = 0; + l_a1 = 0; + ag0 = 0; + ag1 = 0; + dq2 = 0; + switch (ss_ptr->Get_input_case()) + { + /* + * dimensionless a0 and a1 + */ + case cxxSS::SS_PARM_A0_A1: + l_a0 = p[0]; + l_a1 = p[1]; + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * two activity coefficients + * q1, q2, xbq1, xbq2 + */ + case cxxSS::SS_PARM_GAMMAS: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + done = FALSE; + if (fabs(1 - xbq1) > 0 && q1 > 0) + { + dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); + if (xbq2 <= 0 || xbq2 > 1) + { + l_a0 = dq1; + l_a1 = 0; + done = TRUE; + } + } + if (done == FALSE) + { + if (fabs(xbq2) < 0 || q2 <= 0) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + done = TRUE; + } + } + if (done == FALSE) + { + dq2 = log(q2) / (xbq2 * xbq2); + if (xbq1 < 0. || xbq2 > 1.) + { + l_a0 = dq2; + l_a1 = 0; + done = TRUE; + } + } + if (done == FALSE) + { + denom = 4 * (xbq1 - xbq2) + 2; + if (fabs(denom) >= tol) + { + if (fabs(1 - xbq1) > 0 && q1 > 0) + { + dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); + l_a0 = (dq1 * (3 - 4 * xbq2) + + dq2 * (4 * xbq1 - 1)) / denom; + l_a1 = (dq1 - dq2) / denom; + done = TRUE; + } + } + } + if (done == FALSE) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + } + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * two distribution coefficients + * q1, q2, xbq1, xbq2 + */ + case cxxSS::SS_PARM_DIST_COEF: + q1 = p[0]; + q2 = p[1]; + xbq1 = p[2]; + xbq2 = p[3]; + ratio = l_kc / l_kb; + dr1 = log(q1 / ratio); + x21 = 2 * xbq1 - 1; + if (fabs(xbq1 - xbq2) < tol || xbq2 < 0) + { + l_a0 = dr1 / x21; + l_a1 = 0; + } + else + { + dr2 = log(q2 / ratio); + x22 = 2 * xbq2 - 1; + if (xbq1 < 0.) + { + l_a0 = dr2 / x22; + l_a1 = 0; + } + else + { + x61 = 6 * xbq1 * xbq1 - 6 * xbq1 + 1; + x62 = 6 * xbq2 * xbq2 - 6 * xbq2 + 1; + if (fabs(x22 * x61 - x21 * x62) < tol) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + } + l_a0 = (x61 * dr2 - x62 * dr1) / (x22 * x61 - x21 * x62); + l_a1 = (x21 * dr2 - x22 * dr1) / (x21 * x62 - x22 * x61); + } + } + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from miscibility gap fractions + * q1, q2 + */ + case cxxSS::SS_PARM_MISCIBILITY: + q1 = p[0]; + q2 = p[1]; + xb1 = q1; + xb2 = q2; + xc1 = 1 - xb1; + xc2 = 1 - xb2; + r1 = log(xb1 / xb2); + r2 = log(xc1 / xc2); + pa1 = xc2 * xc2 - xc1 * xc1; + pb1 = + 3 * (xc2 * xc2 - xc1 * xc1) - 4 * (xc2 * xc2 * xc2 - + xc1 * xc1 * xc1); + pa2 = xb2 * xb2 - xb1 * xb1; + pb2 = + -(3 * (xb2 * xb2 - xb1 * xb1) - + 4 * (xb2 * xb2 * xb2 - xb1 * xb1 * xb1)); + l_a0 = (r1 - pb1 / pb2 * r2) / (pa1 - pa2 * pb1 / pb2); + l_a1 = (r1 - pa1 / pa2 * r2) / (pb1 - pb2 * pa1 / pa2); + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from spinodal gap fractions + * q1, q2 + */ + case cxxSS::SS_PARM_SPINODAL: + q1 = p[0]; + q2 = p[1]; + xsm1 = q1; + xsm2 = q2; + pn9 = 1 / xsm1; + pn10 = 1 / xsm2; + c5 = 1 - xsm1; + c6 = 1 - xsm2; + pl9 = 6 * c5 - 12 * c5 * c5; + pl10 = 6 * c6 - 12 * c6 * c6; + pj9 = 2 * c5; + pj10 = 2 * c6; + l_a0 = (pn9 - pl9 / pl10 * pn10) / (pj9 - pl9 / pl10 * pj10); + l_a1 = (pn9 - pj9 / pj10 * pn10) / (pl9 - pj9 / pj10 * pl10); + + /* io = 1 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + /* + * from critical point + * q1, q2 + */ + case cxxSS::SS_PARM_CRITICAL: + xc = p[0]; + tc = p[1]; + r = R_KJ_DEG_MOL; + ag1 = r * tc * (2 * xc - 1) / (12 * xc * xc * (1 - xc) * (1 - xc)); + ag0 = (r * tc / (xc * (1 - xc)) - (12 * xc - 6) * ag1) / 2; + + /* io = 0 */ + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * from alyotropic point + * q1, q2 + */ + case cxxSS::SS_PARM_ALYOTROPIC: + q1 = p[0]; + q2 = p[1]; + xaly = q1; + r = log(l_kb / l_kc); + alpha0 = 2 * xaly - 1; + alpha1 = 6 * xaly * (xaly - 1) + 1; + spialy = pow((LDBLE) 10., q2); + l_a0 = -999.; + l_a1 = -999.; + if (fabs(alpha0) < tol) + { + input_error++; + error_string = sformatf( + "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + } + else + { + azero = 1; + if (fabs(alpha0) > tol) + azero = r / alpha0; + xcaly = 1 - xaly; +/* + * Solve for a0 by Newton's method + */ + for (i = 0; i < 50; i++) + { + phi1 = + xcaly * xcaly * (azero + + (r - azero * alpha0) * (4 * xaly - + 1) / alpha1); + phi2 = + xaly * xaly * (azero + + (3 - 4 * xaly) * (azero * alpha0 - + r) / alpha1); + phi1 = xaly * l_kb * exp(phi1); + phi2 = xcaly * l_kc * exp(phi2); + fx = phi1 + phi2 - spialy; + fx1 = + xcaly * xcaly * (1 - + alpha0 * (4 * xaly - + 1) / alpha1) * phi1 + + xaly * xaly * (1 + + alpha0 * (3 - 4 * xaly) / alpha1) * phi2; + if (fabs(fx1) < 1e-10) + { + input_error++; + error_string = sformatf( + "Could not find A0 and A1 calculation from alyotropic point, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + break; + } + l_a0 = azero - fx / fx1; + test = fabs(l_a0 - azero) + fabs(fx); + azero = l_a0; + if (test < tol) + break; + } + if (i == 50) + { + input_error++; + error_string = sformatf( + "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + } + else + { + l_a1 = (r - l_a0 * alpha0) / alpha1; + + /* io = 0 */ + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + } + + } + break; + /* + * dimensional (kJ/mol) Guggenheim parameters + * ag0, ag1 + */ + case cxxSS::SS_PARM_DIM_GUGG: + ag0 = p[0]; + ag1 = p[1]; + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * Waldbaum-Thompson + * wg2, wg1 + */ + case cxxSS::SS_PARM_WALDBAUM: + wg2 = p[0]; + wg1 = p[1]; + ag0 = (wg2 + wg1) / 2; + ag1 = (wg2 - wg1) / 2; + l_a0 = ag0 / rt; + l_a1 = ag1 / rt; + break; + /* + * Margules + * alpha2, alpha3 + */ + case cxxSS::SS_PARM_MARGULES: + alpha2 = p[0]; + alpha3 = p[1]; + l_a0 = alpha2 + 3 * alpha3 / 4; + l_a1 = alpha3 / 4; + ag0 = l_a0 * rt; + ag1 = l_a1 * rt; + break; + } + + ss_ptr->Set_ag0(ag0); + ss_ptr->Set_ag1(ag1); + ss_ptr->Set_a0(l_a0); + ss_ptr->Set_a1(l_a1); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +ss_calc_a0_a1(cxxSS *ss_ptr) /* ---------------------------------------------------------------------- */ { int i, done; @@ -4475,29 +5337,33 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) LDBLE tol; tol = 1e-6; - rt = s_s_ptr->tk * R_KJ_DEG_MOL; - if (s_s_ptr->comps[0].phase == NULL || s_s_ptr->comps[1].phase == NULL) + rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; + cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); + cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); + struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &k, FALSE); + struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE); + if (ss_ptr->comps[0].phase == NULL || ss_ptr->comps[1].phase == NULL) { input_error++; error_string = sformatf( "Two components were not defined for %s solid solution", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); return (ERROR); } - l_kc = exp(k_calc(s_s_ptr->comps[0].phase->rxn->logk, s_s_ptr->tk, REF_PRES_PASCAL) * + l_kc = exp(k_calc(ss_ptr->comps[0].phase->rxn->logk, ss_ptr->tk, REF_PRES_PASCAL) * LOG_10); - l_kb = exp(k_calc(s_s_ptr->comps[1].phase->rxn->logk, s_s_ptr->tk, REF_PRES_PASCAL) * + l_kb = exp(k_calc(ss_ptr->comps[1].phase->rxn->logk, ss_ptr->tk, REF_PRES_PASCAL) * LOG_10); - p = s_s_ptr->p; + p = ss_ptr->p; l_a0 = 0; l_a1 = 0; ag0 = 0; ag1 = 0; dq2 = 0; - switch (s_s_ptr->input_case) + switch (ss_ptr->input_case) { /* * dimensionless a0 and a1 @@ -4535,7 +5401,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); done = TRUE; } @@ -4570,7 +5436,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); } /* io = 1 */ @@ -4612,7 +5478,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); } l_a0 = (x61 * dr2 - x62 * dr1) / (x22 * x61 - x21 * x62); @@ -4710,7 +5576,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); } else @@ -4746,7 +5612,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "Could not find A0 and A1 calculation from alyotropic point, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); break; } @@ -4761,7 +5627,7 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) input_error++; error_string = sformatf( "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", - s_s_ptr->name); + ss_ptr->name); error_msg(error_string, CONTINUE); } else @@ -4811,13 +5677,13 @@ s_s_calc_a0_a1(struct s_s *s_s_ptr) break; } - s_s_ptr->ag0 = ag0; - s_s_ptr->ag1 = ag1; - s_s_ptr->a0 = l_a0; - s_s_ptr->a1 = l_a1; + ss_ptr->ag0 = ag0; + ss_ptr->ag1 = ag1; + ss_ptr->a0 = l_a0; + ss_ptr->a1 = l_a1; return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_master_isotope(void) diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index ec5a82f8..cd6820fc 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -4,6 +4,7 @@ #include "Exchange.h" #include "GasPhase.h" #include "PPassemblage.h" +#include "SSassemblage.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -1585,7 +1586,7 @@ set_initial_moles(int i) //struct pp_assemblage *pp_assemblage_ptr; //struct gas_phase *gas_phase_ptr; struct kinetics *kinetics_ptr; - struct ss_assemblage *ss_assemblage_ptr; + //struct ss_assemblage *ss_assemblage_ptr; //struct exchange *exchange_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; int j, k, l, n; @@ -1649,6 +1650,25 @@ set_initial_moles(int i) /* * Solid solutions */ + { + cxxSSassemblage *ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); + if (ss_assemblage_ptr != NULL) + { + std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); + for (k = 0; k < (int) ss_ptrs.size(); k++) + //for (k = 0; k < ss_assemblage_ptr->count_s_s; k++) + { + cxxSS * ss_ptr = ss_ptrs[k]; + for (j = 0; j < (int) ss_ptr->Get_ss_comps().size(); j++) + //for (j = 0; j < ss_assemblage_ptr->s_s[k].count_comps; j++) + { + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); + comp_ptr->Set_init_moles(comp_ptr->Get_moles()); + } + } + } + } +#ifdef SKIP ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); if (ss_assemblage_ptr != NULL) { @@ -1659,6 +1679,7 @@ set_initial_moles(int i) ss_assemblage_ptr->s_s[k].comps[j].moles; } } +#endif /* * For interlayer diffusion: add tiny bit of exchanger if absent */ From 02ece436f491cd122ade60778ade9f4443d07520 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 17 Jan 2012 23:35:39 +0000 Subject: [PATCH 0425/1077] 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 --- SS.cxx | 157 ++++++++++++++++++++++++++++++++--------------- SS.h | 2 +- SSassemblage.cxx | 83 ++++++++++++++++++++++++- SScomp.cxx | 32 +++++----- phreeqc/read.cpp | 10 ++- 5 files changed, 213 insertions(+), 71 deletions(-) diff --git a/SS.cxx b/SS.cxx index ed83e862..304df8bf 100644 --- a/SS.cxx +++ b/SS.cxx @@ -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) diff --git a/SS.h b/SS.h index 98babea7..a61be110 100644 --- a/SS.h +++ b/SS.h @@ -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 Get_p(void) {return this->p;} + std::vector & Get_p(void) {return this->p;} void Set_p(const std::vector & t) {this->p = t;} protected: std::string name; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index d1d480ab..f03548e0 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -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 diff --git a/SScomp.cxx b/SScomp.cxx index 1f7097c5..81870cf4 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -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; diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 114d33cf..9e7d0fdc 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -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; From bcdeaf22332ae10f4882767260ca1cae6d81bfa8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 Jan 2012 00:18:13 +0000 Subject: [PATCH 0426/1077] Tony's 17Jan2012 changes to gases, prep, read.cpp Working on bugs in ss. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6074 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 19 +++++++----- SSassemblage.cxx | 2 +- phreeqc/gases.cpp | 2 +- phreeqc/prep.cpp | 2 +- phreeqc/read.cpp | 78 +++++++++++++++++++++++------------------------ 5 files changed, 52 insertions(+), 51 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index 00882443..2762654b 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1259,16 +1259,19 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, } else { - if (true) // (database_file == NULL) + if (false) // don't throw error { - //get_output() << "\t" << m_line_save << "\n"; - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - io->output_msg(msg.str().c_str()); + if (true) // (database_file == NULL) + { + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + error_msg("Unknown option.", PHRQ_io::OT_CONTINUE); + error_msg(m_line_save.c_str(), PHRQ_io::OT_CONTINUE); + incr_input_error(); } - error_msg("Unknown option.", PHRQ_io::OT_CONTINUE); - error_msg(m_line_save.c_str(), PHRQ_io::OT_CONTINUE); - incr_input_error(); j = OPT_ERROR; next_pos = pos_ptr; } diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f03548e0..c3eddd55 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -171,6 +171,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) { opt = opt_save; } + useLastLine = false; switch (opt) { case CParser::OPT_EOF: @@ -184,7 +185,6 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) 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 diff --git a/phreeqc/gases.cpp b/phreeqc/gases.cpp index dfe22908..da997025 100644 --- a/phreeqc/gases.cpp +++ b/phreeqc/gases.cpp @@ -469,7 +469,7 @@ calc_PR(void) { V_m = gas_phase_ptr->Get_volume() / m_sum; P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); - if (iterations > 0 && P < 150) + if (iterations > 0 && P < 150 && V_m < 1.01) { // check for 3-roots... r3[1] = b_sum - R_TK / P; diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index f0ae6f40..7de26d21 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -4421,7 +4421,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) if (V_m) { P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); - if (iterations > 0 && P < 150) + if (iterations > 0 && P < 150 && V_m < 1.01) { // check for 3-roots... r3[1] = b_sum - R_TK / P; diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 9e7d0fdc..a3a46990 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -578,11 +578,11 @@ read_exchange_species(void) "add_logk", /* 16 */ "add_log_k", /* 17 */ "add_constant", /* 18 */ - "delta_v", /* 19 */ - "deltav", /* 20 */ - "vm" /* 21, molar volume, must replace delta_v */ + //"delta_v", /* 19 */ + //"deltav", /* 20 */ + "vm" /* 19, molar volume, must replace delta_v */ }; - int count_opt_list = 22; + int count_opt_list = 18; association = TRUE; s_ptr = NULL; @@ -889,9 +889,9 @@ read_exchange_species(void) s_ptr->count_add_logk++; opt_save = OPTION_DEFAULT; break; - case 19: /* delta_v */ - case 20: /* deltav */ - case 21: /* vm, molar volume */ + //case 19: /* delta_v */ + //case 20: /* deltav */ + case 19: /* vm, molar volume */ if (s_ptr == NULL) { error_string = sformatf( @@ -3024,7 +3024,7 @@ read_delta_v_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) /* * Read analytical expression */ - for (j = 0; j < 8; j++) + for (j = 0; j < 4; j++) { delta_v[j] = 0.0; } @@ -3064,17 +3064,15 @@ read_delta_v_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) else if (strstr(token, "dm3") != NULL) { /* Convert dm3/mol to cm3/mol */ - //*delta_v *= 1E3; factor = 1e3; } else if (strstr(token, "m3") != NULL) { /* Convert m3/mol to cm3/mol */ - //*delta_v *= 1E6; factor = 1e6; } - for (int i = 0; i < 8; i++) + for (int i = 0; i < 4; i++) { delta_v[i] *= factor; } @@ -3654,11 +3652,11 @@ read_phases(void) "t_c", /* 12 */ "p_c", /* 13 */ "omega", /* 14 */ - "delta_v", /* 15 */ - "deltav", /* 16 */ - "vm" /* 17, molar volume, must replace delta_v */ + //"delta_v", /* 15 */ + //"deltav", /* 16 */ + "vm" /* 15, molar volume, must replace delta_v */ }; - int count_opt_list = 18; + int count_opt_list = 16; association = FALSE; /* @@ -3827,9 +3825,9 @@ read_phases(void) read_omega_only(next_char, &phase_ptr->omega); opt_save = OPTION_DEFAULT; break; - case 15: /* delta_v */ - case 16: /* delta_v */ - case 17: /* vm, molar volume */ + //case 15: /* delta_v */ + //case 16: /* delta_v */ + case 15: /* vm, molar volume */ if (phase_ptr == NULL) break; //read_delta_v_only(next_char, &phase_ptr->delta_v[1], @@ -5548,11 +5546,11 @@ read_species(void) /* VP: Density Start */ "millero", /* 21 */ /* VP: Density End */ - "delta_v", /* 22 */ - "deltav", /* 23 */ - "vm" /* 24, molar volume, must replace delta_v */ + //"delta_v", /* 22 */ + //"deltav", /* 23 */ + "vm" /* 22, molar volume, must replace delta_v */ }; - int count_opt_list = 25; + int count_opt_list = 23; association = TRUE; s_ptr = NULL; @@ -5567,8 +5565,8 @@ read_species(void) if (opt == OPTION_DEFAULT) { opt = opt_save; + vm_read = false; } - vm_read = false; switch (opt) { case OPTION_EOF: /* end of file */ @@ -5903,9 +5901,9 @@ read_species(void) break; /* VP: Density End */ - case 22: /* delta_v */ - case 23: /* deltav */ - case 24: /* vm, molar volume */ + //case 22: /* delta_v */ + //case 23: /* deltav */ + case 22: /* vm, molar volume */ if (s_ptr == NULL) { error_string = sformatf( @@ -6296,11 +6294,11 @@ read_surface_species(void) "add_constant", /* 15 */ "cd_music", /* 16 */ "music", /* 17 */ - "delta_v", /* 18 */ - "deltav", /* 19 */ - "vm" + //"delta_v", /* 18 */ + //"deltav", /* 19 */ + "vm" /* 18 */ }; - int count_opt_list = 21; + int count_opt_list = 19; association = TRUE; /* @@ -6572,9 +6570,9 @@ read_surface_species(void) } opt_save = OPTION_DEFAULT; break; - case 18: /* delta_v */ - case 19: /* deltav */ - case 20: /* vm, molar volume */ + //case 18: /* delta_v */ + //case 19: /* deltav */ + case 18: /* vm, molar volume */ if (s_ptr == NULL) { error_string = sformatf( @@ -10702,11 +10700,11 @@ read_named_logk(void) "ln_alpha1000", /* 7 */ "add_logk", /* 8 */ "add_log_k", /* 9 */ - "delta_v", /* 10 */ - "deltav", /* 11 */ - "vm" + //"delta_v", /* 10 */ + //"deltav", /* 11 */ + "vm" /* 10 */ }; - int count_opt_list = 13; + int count_opt_list = 11; logk_ptr = NULL; /* * Read name followed by options @@ -10868,9 +10866,9 @@ read_named_logk(void) logk_ptr->count_add_logk++; opt_save = OPTION_DEFAULT; break; - case 10: /* delta_v */ - case 11: /* deltav */ - case 12: /* vm, molar volume */ + //case 10: /* delta_v */ + //case 11: /* deltav */ + case 10: /* vm, molar volume */ if (logk_ptr == NULL) { error_string = sformatf( From 82bd21f4847c56c4576036b17384af7c2d4aad6b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 Jan 2012 01:18:34 +0000 Subject: [PATCH 0427/1077] Running Linux with new SS git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6075 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 145 ++++++++++++++++++++++------------------------- SS.cxx | 4 +- phreeqc/prep.cpp | 2 +- phreeqc/read.cpp | 10 ++-- phreeqc/tidy.cpp | 3 +- 5 files changed, 78 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index 90a82077..2c18be3d 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,7 @@ COMMON_CXXOBJS = \ SolutionIsotope.o \ SolutionIsotopeList.o \ SSassemblage.o \ + SScomp.o \ SS.o \ StorageBin.o \ StorageBinList.o \ @@ -307,7 +308,7 @@ NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../NameDouble.h ../phreeqc/phqalloc.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../PHRQ_io.h + ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -359,8 +360,8 @@ ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../GasPhase.h ../GasComp.h ../Reaction.h \ - ../Temperature.h ../phreeqc/phqalloc.h + ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -392,7 +393,15 @@ SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SS.h \ + ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SS.h ../SScomp.h \ + ../phreeqc/phqalloc.h +SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ + ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ + ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ + ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../Parser.h ../SScomp.h ../NameDouble.h ../Phreeqc_class.h \ ../phreeqc/phqalloc.h SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ @@ -400,7 +409,7 @@ SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../SS.h ../NameDouble.h ../Phreeqc_class.h \ + ../Parser.h ../SS.h ../NameDouble.h ../Phreeqc_class.h ../SScomp.h \ ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ @@ -410,11 +419,12 @@ StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ ../NameDouble.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ - ../SSassemblage.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SS.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../Reaction.h ../Temperature.h \ + ../phreeqc/phqalloc.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -449,11 +459,11 @@ System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../System.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ - ../SSassemblage.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SS.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../Reaction.h ../Temperature.h + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h \ + ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../Reaction.h ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -469,20 +479,6 @@ Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Parser.h -Calculate_value.o: ../Calculate_value.cpp ../Calculate_value.h \ - ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h ../phreeqc/phrqtype.h -Calculate_values\ .o: ../Calculate_values\ .cpp ../Calculate_values.h \ - ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h ../Parser.h \ - ../phreeqc/phrqtype.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../PBasic.h -Calculate_values.o: ../Calculate_values.cpp ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Calculate_values.h \ - ../Calculate_value.h ../Parser.h ../PBasic.h ChartHandler.o: ../ChartHandler.cpp ChartObject.o: ../ChartObject.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -495,12 +491,11 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ - ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h -CurveObject.o: ../CurveObject.cpp ../CurveObject.h + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h +CurveObject.o: ../CurveObject.cpp ../CurveObject.h ../phreeqc/phrqtype.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../PHRQ_io.h + ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h Keywords.o: ../Keywords.cpp ../Keywords.h -Logk.o: ../Logk.cpp ../Logk.h ../phreeqc/phrqtype.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ @@ -518,7 +513,7 @@ Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ - ../SSassemblage.h ../cxxKinetics.h ../KineticsComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ @@ -527,10 +522,12 @@ PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Parser.h -runner.o: ../runner.cpp ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../PHRQ_io.h ../phreeqc/NA.h +runner.o: ../runner.cpp ../runner.h ../phreeqc/phrqtype.h \ + ../StorageBinList.h ../PHRQ_base.h ../Parser.h ../Keywords.h \ + ../PHRQ_io.h ../phreeqc/NA.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h + ../PHRQ_base.h ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h \ + ../PHRQ_io.h Use.o: ../Use.cpp ../Use.h advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ @@ -551,8 +548,8 @@ basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/../NumKeyword.h ../phreeqc/../ExchComp.h \ ../phreeqc/../NameDouble.h ../phreeqc/../GasPhase.h \ ../phreeqc/../Phreeqc_class.h ../phreeqc/../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h -ChartObject.o: ../phreeqc/ChartObject.cpp + ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ + ../SSassemblage.h ../SS.h ../SScomp.h cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -639,7 +636,7 @@ kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ ../PPassemblage.h ../PPassemblageComp.h ../Surface.h ../SurfaceComp.h \ ../SurfaceCharge.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../SSassemblage.h ../Temperature.h \ + ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../Temperature.h \ ../phreeqc/nvector_serial.h mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ @@ -651,14 +648,7 @@ mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../ExchComp.h ../GasPhase.h \ ../Phreeqc_class.h ../GasComp.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h -model_aw_fraction.o: ../phreeqc/model_aw_fraction.cpp ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -667,14 +657,8 @@ model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ ../NameDouble.h ../Parser.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h -model\ with\ ah2o.o: ../phreeqc/model\ with\ ah2o.cpp ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h nvector_serial.o: ../phreeqc/nvector_serial.cpp \ @@ -724,7 +708,8 @@ prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../SS.h print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -734,7 +719,8 @@ print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h + ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -744,18 +730,18 @@ read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Pressure.h \ ../Temperature.h ../Parser.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../SS.h ../SScomp.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/phrqtype.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../SS.h ../Phreeqc.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../phreeqc/phrqtype.h ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/../Phreeqc_class.h ../phreeqc/../SS.h \ + ../phreeqc/../SScomp.h ../Phreeqc.h ../phreeqc/cvdense.h \ + ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ + ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -784,8 +770,8 @@ step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../StorageBin.h ../System.h ../NameDouble.h ../Phreeqc_class.h \ ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ - ../NameDouble.h ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../Reaction.h + ../SScomp.h ../SS.h ../NameDouble.h ../Temperature.h ../cxxMix.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -796,16 +782,17 @@ structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../Use.h ../phreeqc/../cxxKinetics.h ../phreeqc/../NumKeyword.h \ + ../Use.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../phreeqc/../cxxKinetics.h ../phreeqc/../NumKeyword.h \ ../phreeqc/../KineticsComp.h ../phreeqc/../NameDouble.h \ ../phreeqc/../PHRQ_base.h ../phreeqc/../Solution.h \ ../phreeqc/../SolutionIsotopeList.h ../phreeqc/../SolutionIsotope.h \ ../phreeqc/../Parser.h ../phreeqc/../PHRQ_io.h \ ../phreeqc/../Phreeqc_class.h ../phreeqc/../SolutionIsotopeList.h \ - ../phreeqc/../SSassemblage.h ../phreeqc/../SS.h ../phreeqc/../Surface.h \ - ../phreeqc/../SurfaceComp.h ../phreeqc/../SurfaceCharge.h \ - ../phreeqc/../SurfaceComp.h ../phreeqc/../SurfaceCharge.h \ - ../phreeqc/../StorageBin.h ../phreeqc/../System.h + ../phreeqc/../Surface.h ../phreeqc/../SurfaceComp.h \ + ../phreeqc/../SurfaceCharge.h ../phreeqc/../SurfaceComp.h \ + ../phreeqc/../SurfaceCharge.h ../phreeqc/../StorageBin.h \ + ../phreeqc/../System.h sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ @@ -817,7 +804,8 @@ tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h \ ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ @@ -826,7 +814,8 @@ tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -836,7 +825,7 @@ transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ ../GasPhase.h ../Phreeqc_class.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ diff --git a/SS.cxx b/SS.cxx index 304df8bf..9da77f7c 100644 --- a/SS.cxx +++ b/SS.cxx @@ -30,7 +30,7 @@ PHRQ_base(io) dn = 0; a0 = 0; a1 = 0; - LDBLE ag0 = 0; + ag0 = 0; ag1 = 0; ss_in = false; miscibility = false; @@ -667,4 +667,4 @@ cxxSS::Find(const char * comp_name) return &(ss_comps[i]); } return NULL; -} \ No newline at end of file +} diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 7de26d21..ef45d29d 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -799,7 +799,7 @@ build_ss_assemblage(void) row = x[i]->number * (count_unknowns + 1); for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) { - if (j != x[i]->ss_comp_number) + if ((int) j != x[i]->ss_comp_number) { /* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ store_jacob(&(x[i]->phase->dn), &(array[row + col + j]), diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index a3a46990..404293e8 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -5518,7 +5518,7 @@ read_species(void) struct species *s_ptr; struct elt_list *next_elt; char *ptr, token[MAX_LENGTH]; - bool vm_read; + bool vm_read = false; int return_value, opt, opt_save; char *next_char; const char *opt_list[] = { @@ -9321,7 +9321,6 @@ read_solid_solutions(void) { int j = sscanf(token.c_str(), SCANFORMAT, &dummy); comp.Set_moles(dummy); - (LDBLE) dummy; if (j != 1) { error_msg("Expected moles of solid solution.", CONTINUE); @@ -9717,7 +9716,8 @@ read_solid_solutions(void) delete ss_ptr; ss_ptr = NULL; comps.clear(); - delete comp0_ptr, comp1_ptr; + delete comp0_ptr; + delete comp1_ptr; comp0_ptr = comp1_ptr = NULL; } ss_ptr = new cxxSS; @@ -9728,6 +9728,7 @@ read_solid_solutions(void) copy_token(token, &ptr); ss_ptr->Set_name(token); ss_ptr->Set_total_moles(NAN); + std::cerr << "Read: " << ss_ptr->Get_total_moles() << "\n"; break; } if (return_value == EOF || return_value == KEYWORD) @@ -9744,7 +9745,8 @@ read_solid_solutions(void) delete ss_ptr; ss_ptr = NULL; comps.clear(); - delete comp0_ptr, comp1_ptr; + delete comp0_ptr; + delete comp1_ptr; comp0_ptr = comp1_ptr = NULL; // check non ideal ss diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 16d93b7f..70e55e29 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -5308,8 +5308,9 @@ ss_calc_a0_a1(cxxSS *ss_ptr) ag0 = l_a0 * rt; ag1 = l_a1 * rt; break; + case cxxSS::SS_PARM_NONE: + break; } - ss_ptr->Set_ag0(ag0); ss_ptr->Set_ag1(ag1); ss_ptr->Set_a0(l_a0); From ea54bb8f57902eff992a5468dfc6cb5a464cdcc5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 Jan 2012 01:40:57 +0000 Subject: [PATCH 0428/1077] reworked logic for using previously read line from parser. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6076 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- Exchange.cxx | 2 +- GasPhase.cxx | 2 +- PPassemblage.cxx | 2 +- Parser.cxx | 32 +++++++++++++++++--------------- Parser.h | 4 ++-- Pressure.cxx | 2 +- Reaction.cxx | 2 +- SS.cxx | 2 +- SSassemblage.cxx | 2 +- Surface.cxx | 2 +- Temperature.cxx | 2 +- cxxKinetics.cxx | 2 +- cxxMix.cxx | 2 +- 14 files changed, 31 insertions(+), 29 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 1ed9ed7b..6e3df3b0 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -291,7 +291,7 @@ ChartObject::Read(CParser & parser) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/Exchange.cxx b/Exchange.cxx index b50466e6..130d2765 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -198,7 +198,7 @@ cxxExchange::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } switch (opt) { diff --git a/GasPhase.cxx b/GasPhase.cxx index e5829f31..251ce995 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -313,7 +313,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { CParser::ECHO_OPTION eo = parser.get_echo_file(); parser.set_echo_file(CParser::EO_NONE); - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); parser.set_echo_file(eo); } if (opt == CParser::OPT_DEFAULT) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 257d854b..8cd03798 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -174,7 +174,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/Parser.cxx b/Parser.cxx index 2762654b..0461eae5 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1103,7 +1103,7 @@ CParser::STATUS_TYPE CParser::addPair(std::map < std::string, LDBLE >&totals, int CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::string::iterator & next_char) + std::string::iterator & next_char, bool flag_error) { // // Read a line and check for options @@ -1156,20 +1156,22 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, } else { - if (true) // (database_file == NULL) + if (flag_error) { - //get_output() << "\t" << m_line_save << "\n"; - std::ostringstream msg; - msg << "\t" << m_line_save << "\n"; - io->output_msg(msg.str().c_str()); + if (true) // (database_file == NULL) + { + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + //std::cerr << "Unknown option." << "\n"; + //std::cerr << m_line_save << "\n"; + std::ostringstream err; + err << "Unknown option." << "\n"; + err << m_line_save << "\n"; + error_msg(err.str().c_str()); } - //std::cerr << "Unknown option." << "\n"; - //std::cerr << m_line_save << "\n"; - std::ostringstream err; - err << "Unknown option." << "\n"; - err << m_line_save << "\n"; - error_msg(err.str().c_str()); - j = OPT_ERROR; next_char = m_line.begin(); } @@ -1202,7 +1204,7 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, int CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos) + std::istream::pos_type & next_pos, bool flag_error) { // // Read a line and check for options @@ -1259,7 +1261,7 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, } else { - if (false) // don't throw error + if (flag_error) // don't throw error { if (true) // (database_file == NULL) { diff --git a/Parser.h b/Parser.h index 52368a95..97e630f6 100644 --- a/Parser.h +++ b/Parser.h @@ -121,9 +121,9 @@ class CParser: public PHRQ_base int get_option(const std::vector < std::string > &opt_list, std::istream::pos_type & next_pos); int getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::string::iterator & next_char); + std::string::iterator & next_char, bool flag_error); int getOptionFromLastLine(const std::vector < std::string > &opt_list, - std::istream::pos_type & next_pos); + std::istream::pos_type & next_pos, bool flag_error); std::string & line() diff --git a/Pressure.cxx b/Pressure.cxx index 8a0a94a3..206a191e 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -233,7 +233,7 @@ cxxPressure::read_raw(CParser & parser) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/Reaction.cxx b/Reaction.cxx index 9086ef7b..4a8e19c2 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -172,7 +172,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/SS.cxx b/SS.cxx index 9da77f7c..cfee0428 100644 --- a/SS.cxx +++ b/SS.cxx @@ -199,7 +199,7 @@ cxxSS::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, false); } if (opt == CParser::OPT_DEFAULT) { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index c3eddd55..3e7a102c 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -165,7 +165,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/Surface.cxx b/Surface.cxx index 95cc3d0d..3340026a 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -340,7 +340,7 @@ cxxSurface::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } switch (opt) { diff --git a/Temperature.cxx b/Temperature.cxx index f16b1565..14124098 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -269,7 +269,7 @@ cxxTemperature::read_raw(CParser & parser) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index ef60e559..4497b598 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -275,7 +275,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { diff --git a/cxxMix.cxx b/cxxMix.cxx index 3f5a76e5..ba89c3d5 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -125,7 +125,7 @@ cxxMix::read_raw(CParser & parser) } else { - opt = parser.getOptionFromLastLine(vopts, next_char); + opt = parser.getOptionFromLastLine(vopts, next_char, true); } if (opt == CParser::OPT_DEFAULT) { From 18906cdd2fd4e62732a53d3d5c262f092b42dbac Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 Jan 2012 17:23:36 +0000 Subject: [PATCH 0429/1077] Removed skipped code. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6081 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 25 - PPassemblage.cxx | 22 - PPassemblageComp.cxx | 21 +- Parser.cxx | 37 - Phreeqc.cpp | 16 - Phreeqc.h | 55 -- ReadClass.cxx | 475 ----------- SS.cxx | 89 --- SS.h | 7 +- SSassemblage.cxx | 107 +-- SScomp.cxx | 20 - SurfaceComp.cxx | 32 +- Utils.h | 8 - phreeqc/basicsubs.cpp | 313 -------- phreeqc/global_structures.h | 148 ---- phreeqc/kinetics.cpp | 70 +- phreeqc/mainsubs.cpp | 303 ------- phreeqc/model.cpp | 529 ------------- phreeqc/prep.cpp | 667 ---------------- phreeqc/print.cpp | 194 ----- phreeqc/read.cpp | 799 ------------------- phreeqc/step.cpp | 444 ----------- phreeqc/structures.cpp | 1150 +-------------------------- phreeqc/tally.cpp | 241 ------ phreeqc/tidy.cpp | 1110 +------------------------- phreeqc/transport.cpp | 1486 +---------------------------------- phreeqc/utilities.cpp | 14 - 27 files changed, 23 insertions(+), 8359 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index 251ce995..2845ee45 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -596,31 +596,6 @@ cxxGasPhase::totalize(PHREEQC_PTR_ARG) } return; } -#ifdef SKIP -void -cxxGasPhase::totalize(PHREEQC_PTR_ARG) -{ - this->totals.clear(); - // component structures - for (cxxNameDouble::const_iterator it = this->gasPhaseComps.begin(); - it != this->gasPhaseComps.end(); it++) - { - struct phase *phase_ptr; - int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, it->second); - } - else - { - assert(false); - } - } - return; -} -#endif LDBLE cxxGasPhase::Calc_total_moles(void) { LDBLE tot = 0.0; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 8cd03798..12b97311 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -26,29 +26,7 @@ cxxPPassemblage::cxxPPassemblage(PHRQ_io * io) { eltList.type = cxxNameDouble::ND_ELT_MOLES; } -#ifdef SKIP -cxxPPassemblage::cxxPPassemblage(struct pp_assemblage *pp_assemblage_ptr, PHRQ_io * io) - // - // constructor for cxxPPassemblage from struct PPassemblage - // - : -cxxNumKeyword(io), -eltList(pp_assemblage_ptr->next_elt) -{ - int i; - this->Set_description(pp_assemblage_ptr->description); - n_user = pp_assemblage_ptr->n_user; - n_user_end = pp_assemblage_ptr->n_user_end; - for (i = 0; i < pp_assemblage_ptr->count_comps; i++) - { - cxxPPassemblageComp ppComp(&(pp_assemblage_ptr->pure_phases[i]), this->Get_io()); - //ppAssemblageComps.push_back(ppComp); - std::string str(ppComp.Get_name()); - this->ppAssemblageComps[str] = ppComp; - } -} -#endif cxxPPassemblage::cxxPPassemblage(const std::map < int, cxxPPassemblage > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index a6281774..24ac121a 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -33,26 +33,7 @@ PHRQ_base(io) dissolve_only = false; precipitate_only = false; } -#ifdef SKIP -cxxPPassemblageComp::cxxPPassemblageComp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) -: -PHRQ_base(io) - // - // constructor for cxxPPassemblageComp from struct pure_phase - // -{ - this->Set_name(pure_phase_ptr->name); - this->Set_add_formula(pure_phase_ptr->add_formula); - si = pure_phase_ptr->si; - si_org = pure_phase_ptr->si_org; - moles = pure_phase_ptr->moles; - delta = pure_phase_ptr->delta; - initial_moles = pure_phase_ptr->initial_moles; - force_equality = (pure_phase_ptr->force_equality == TRUE); - dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); - precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); -} -#endif + cxxPPassemblageComp::~cxxPPassemblageComp() { } diff --git a/Parser.cxx b/Parser.cxx index 0461eae5..81a49d37 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -22,8 +22,6 @@ CParser::CParser(PHRQ_io *io): PHRQ_base(io), m_input_stream(std::cin), -//m_output_stream(std::cout), -//m_error_stream(std::cerr), m_input_error(0), m_next_keyword(Keywords::KEY_NONE) { @@ -47,8 +45,6 @@ m_next_keyword(Keywords::KEY_NONE) CParser::CParser(std::istream & input, PHRQ_io *io): PHRQ_base(io), m_input_stream(input), -//m_output_stream(std::cout), -//m_error_stream(std::cerr), m_input_error(0), m_next_keyword(Keywords::KEY_NONE) { @@ -60,39 +56,6 @@ m_next_keyword(Keywords::KEY_NONE) phrq_io_only = false; } -#ifdef SKIP -CParser::CParser(std::istream & input, std::ostream & output, PHRQ_io *io) -: -PHRQ_base(io), -m_input_stream(input), -m_output_stream(output), -m_error_stream(std::cerr), -m_input_error(0), -m_next_keyword(Keywords::KEY_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; -} - -CParser::CParser(std::istream & input, std::ostream & output, std::ostream & error, PHRQ_io *io) -: -PHRQ_base(io), -m_input_stream(input), -m_output_stream(output), -m_error_stream(error), -m_input_error(0), -m_next_keyword(Keywords::KEY_NONE) -{ - m_line_save.reserve(80); - m_line.reserve(80); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; -} -#endif CParser::~CParser() { } diff --git a/Phreeqc.cpp b/Phreeqc.cpp index a878f322..2dc92280 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -207,14 +207,6 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(entity.Get_totals(), 1.0); } } -#ifdef SKIP - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage entity(&pp_assemblage[i], phrq_io); - entity.totalize(this); - accumulator.add_extensive(entity.Get_totals(), 1.0); - } -#endif // exchangers { std::map::const_iterator cit = Rxn_exchange_map.begin(); @@ -255,14 +247,6 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(entity.Get_totals(), 1.0); } } -#ifdef SKIP - for (i = 0; i < count_ss_assemblage; i++) - { - cxxSSassemblage entity(&ss_assemblage[i]); - entity.totalize(this); - accumulator.add_extensive(entity.Get_totals(), 1.0); - } -#endif // kinetics for (i = 0; i < count_kinetics; i++) { diff --git a/Phreeqc.h b/Phreeqc.h index 2cf6c8ed..65eb5a5c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -929,33 +929,6 @@ protected: int phase_delete(int i); struct phase *phase_store(const char *name); public: -#ifdef SKIP - struct pp_assemblage *pp_assemblage_alloc(void); - struct pp_assemblage *pp_assemblage_bsearch(int k, int *n); -protected: - static int pp_assemblage_compare(const void *ptr1, const void *ptr2); -public: - int pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, - int n_user_new); -protected: - int pp_assemblage_copy_to_last(int n, int n_user); - int pp_assemblage_delete(int n_user_old); - int pp_assemblage_duplicate(int n_user_old, int n_user_new); -public: - int pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr); -protected: - int pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, - int n_user_end, char *description); - int pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, - int n_user_new); - struct pp_assemblage *pp_assemblage_replicate(struct pp_assemblage - *pp_assemblage_old_ptr, - int n_user_new); - struct pp_assemblage *pp_assemblage_search(int n_user, int *n); - int pp_assemblage_sort(void); - static int pure_phase_compare(const void *ptr1, const void *ptr2); -#endif struct rate *rate_bsearch(char *ptr, int *j); int rate_free(struct rate *rate_ptr); struct rate *rate_search(const char *name, int *n); @@ -969,34 +942,6 @@ protected: int s_delete(int i); struct species *s_search(const char *name); struct species *s_store(const char *name, LDBLE z, int replace_if_found); -public: -#ifdef SKIP - struct ss_assemblage *ss_assemblage_alloc(void); - struct ss_assemblage *ss_assemblage_bsearch(int k, int *n); -protected: - static int ss_assemblage_compare(const void *ptr1, const void *ptr2); -public: - int ss_assemblage_copy(struct ss_assemblage *ss_assemblage_old_ptr, - struct ss_assemblage *ss_assemblage_new_ptr, - int n_user_new); -protected: - int ss_assemblage_copy_to_last(int n, int n_user); - int ss_assemblage_duplicate(int n_user_old, int n_user_new); - int ss_assemblage_delete(int n_user_old); -public: - int ss_assemblage_free(struct ss_assemblage *ss_assemblage_ptr); - - int ss_assemblage_init(struct ss_assemblage *ss_assemblage_ptr, - int n_user, int n_user_end, char *description); - int ss_assemblage_ptr_to_user(struct ss_assemblage *ss_assemblage_ptr_old, - int n_user_new); - struct ss_assemblage *ss_assemblage_replicate(struct ss_assemblage - *ss_assemblage_old_ptr, - int n_user_new); - struct ss_assemblage *ss_assemblage_search(int n_user, int *n); - int ss_assemblage_sort(void); - static int s_s_compare(const void *ptr1, const void *ptr2); -#endif protected: struct save_values *save_values_bsearch(struct save_values *k, int *n); static int save_values_compare(const void *ptr1, const void *ptr2); diff --git a/ReadClass.cxx b/ReadClass.cxx index 138105a2..db44a425 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -207,102 +207,6 @@ read_surface_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_equilibrium_phases_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads EQUILIBRIUM_PHASES_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = - check_line("equilibrium_phases_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxPPassemblage ex(phrq_io); - ex.read_raw(parser); - //struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); - struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (pp_assemblage_bsearch(pp_assemblage_ptr->n_user, &n) != NULL) - { - pp_assemblage_free(&pp_assemblage[n]); - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], - pp_assemblage_ptr->n_user); - } - else - { - n = count_pp_assemblage++; - if (count_pp_assemblage >= max_pp_assemblage) - { - space((void **) ((void *) &(pp_assemblage)), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - } - pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[n], - pp_assemblage_ptr->n_user); - pp_assemblage_sort(); - } - pp_assemblage_free(pp_assemblage_ptr); - free_check_null(pp_assemblage_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_raw(void) @@ -394,103 +298,6 @@ read_kinetics_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solid_solutions_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads SOLID_SOLUTION_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = - check_line("solid_solution_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxSSassemblage ex; - ex.read_raw(parser); - //struct ss_assemblage *ss_assemblage_ptr = ex.cxxSSassemblage2ss_assemblage(PHREEQC_THIS); - struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (ss_assemblage_bsearch(ss_assemblage_ptr->n_user, &n) != NULL) - { - ss_assemblage_free(&ss_assemblage[n]); - ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[n], - ss_assemblage_ptr->n_user); - } - else - { - n = count_ss_assemblage++; - if (count_ss_assemblage >= max_ss_assemblage) - { - space((void **) ((void *) &(ss_assemblage)), - count_ss_assemblage, &max_ss_assemblage, - sizeof(struct ss_assemblage)); - } - ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[n], - ss_assemblage_ptr->n_user); - ss_assemblage_sort(); - } - ss_assemblage_free(ss_assemblage_ptr); - free_check_null(ss_assemblage_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -735,99 +542,6 @@ read_solution_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_equilibrium_phases_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads equilibrium_phases_modify data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find equilibrium_phases 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++; - error_string = sformatf( "Expected equilibrium_phases number following EQUILIBRIUM_PHASES_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (pp_assemblage_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Equlibrium_phases %d not found for EQUILIBRIUM_PHASES_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxPPassemblage entity(&(pp_assemblage[n]), phrq_io); - entity.read_raw(parser, false); - - // save entity - //struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(PHREEQC_THIS); - struct pp_assemblage *entity_ptr = cxxPPassemblage2pp_assemblage(&entity); - pp_assemblage_free(&(pp_assemblage[n])); - 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[n].new_def = TRUE; - pp_assemblage[n].n_user_end = pp_assemblage[n].n_user; - - pp_assemblage_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_modify(void) @@ -916,96 +630,6 @@ read_surface_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solid_solutions_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads SOLID_SOLUTIONS_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find solid_solutions 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++; - error_string = sformatf( "Expected solid_solutions number following SOLID_SOLUTIONS_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (ss_assemblage_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Solid_solutions %d not found for SOLID_SOLUTIONS_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxSSassemblage entity(&(ss_assemblage[n])); - entity.read_raw(parser, false); - - // save entity - //struct ss_assemblage *entity_ptr = entity.cxxSSassemblage2ss_assemblage(PHREEQC_THIS); - struct ss_assemblage *entity_ptr = cxxSSassemblage2ss_assemblage(&entity); - ss_assemblage_free(&(ss_assemblage[n])); - ss_assemblage_copy(entity_ptr, &(ss_assemblage[n]), entity_ptr->n_user); - free_check_null(ss_assemblage[n].description); - ss_assemblage[n].description = string_duplicate(entity_ptr->description); - ss_assemblage_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_modify(void) @@ -1237,30 +861,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_pp_assemblage().Get_defined()) - { - if (delete_info.Get_pp_assemblage().Get_numbers().size() == 0) - { - for (i = 0; i < count_pp_assemblage; i++) - { - pp_assemblage_delete(pp_assemblage[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_pp_assemblage().Get_numbers().begin(); it != delete_info.Get_pp_assemblage().Get_numbers().end(); it++) - { - - if (pp_assemblage_bsearch(*it, &n) != NULL) - { - pp_assemblage_delete(*it); - } - } - } - } -#endif // exchangers if (delete_info.Get_exchange().Get_defined()) { @@ -1316,29 +916,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_ss_assemblage().Get_defined()) - { - if (delete_info.Get_ss_assemblage().Get_numbers().size() == 0) - { - for (i = 0; i < count_ss_assemblage; i++) - { - ss_assemblage_delete(ss_assemblage[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_ss_assemblage().Get_numbers().begin(); it != delete_info.Get_ss_assemblage().Get_numbers().end(); it++) - { - if (ss_assemblage_bsearch(*it, &n) != NULL) - { - ss_assemblage_delete(*it); - } - } - } - } -#endif // gas_phases if (delete_info.Get_gas_phase().Get_defined()) { @@ -1718,32 +1295,6 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_pp_assemblage()) - { - if (dump_info.Get_pp_assemblage().size() == 0) - { - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage cxxentity(&pp_assemblage[i], phrq_io); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_pp_assemblage().begin(); it != dump_info.Get_pp_assemblage().end(); it++) - { - - if (pp_assemblage_bsearch(*it, &n) != NULL) - { - cxxPPassemblage cxxentity(&pp_assemblage[n], phrq_io); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // exchanges if (dump_info.Get_bool_exchange()) { @@ -1813,32 +1364,6 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_ss_assemblage()) - { - if (dump_info.Get_ss_assemblage().size() == 0) - { - for (i = 0; i < count_ss_assemblage; i++) - { - cxxSSassemblage cxxentity(&ss_assemblage[i]); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_ss_assemblage().begin(); it != dump_info.Get_ss_assemblage().end(); it++) - { - - if (ss_assemblage_bsearch(*it, &n) != NULL) - { - cxxSSassemblage cxxentity(&ss_assemblage[n]); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // gas_phases if (dump_info.Get_bool_gas_phase()) { diff --git a/SS.cxx b/SS.cxx index cfee0428..d07e5888 100644 --- a/SS.cxx +++ b/SS.cxx @@ -44,37 +44,6 @@ PHRQ_base(io) p.push_back(0); } } -#ifdef SKIP -cxxSS::cxxSS(struct s_s *s_s_ptr, PHRQ_io *io) -: -PHRQ_base(io) // - // constructor for cxxSS from struct s_s - // -{ - this->Set_name(s_s_ptr->name); - //total_moles = s_s_ptr->total_moles; - a0 = s_s_ptr->a0; - a1 = s_s_ptr->a1; - ag0 = s_s_ptr->ag0; - ag1 = s_s_ptr->ag1; - miscibility = (s_s_ptr->miscibility == TRUE); - //spinodal = (s_s_ptr->spinodal == TRUE); - //tk = s_s_ptr->tk; - xb1 = s_s_ptr->xb1; - xb2 = s_s_ptr->xb2; - //type = s_s_ptr->input_case; - /* - for (i = 0; i < 4; i++) { - p[i] = s_s_ptr->p[i]; - } - */ - int i; - for (i = 0; i < s_s_ptr->count_comps; i++) - { - comps[s_s_ptr->comps[i].name] = s_s_ptr->comps[i].moles; - } -} -#endif cxxSS::~cxxSS() { } @@ -543,31 +512,6 @@ cxxSS::totalize(PHREEQC_PTR_ARG) } return; } -#ifdef SKIP -void -cxxSS::totalize(PHREEQC_PTR_ARG) -{ - this->totals.clear(); - // component structures - for (cxxNameDouble::const_iterator it = this->comps.begin(); - it != this->comps.end(); it++) - { - struct phase *phase_ptr; - int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(it->first.c_str(), &l, FALSE); - if (phase_ptr != NULL) - { - cxxNameDouble phase_formula(phase_ptr->next_elt); - this->totals.add_extensive(phase_formula, it->second); - } - else - { - assert(false); - } - } - return; -} -#endif void cxxSS::add(const cxxSS & addee_in, LDBLE extensive) { @@ -608,26 +552,6 @@ cxxSS::add(const cxxSS & addee_in, LDBLE extensive) } } } -#ifdef SKIP -void -cxxSS::add(const cxxSS & addee, LDBLE extensive) -{ - if (extensive == 0.0) - return; - if (addee.name.size() == 0) - return; - // this and addee must have same name - // otherwise generate a new PPassemblagComp with multiply - - //char *name; - //cxxNameDouble comps; - this->comps.add_extensive(addee.comps, extensive); - //LDBLE a0, a1; - //LDBLE ag0, ag1; - //bool miscibility; - //LDBLE xb1, xb2; -} -#endif void cxxSS::multiply(LDBLE extensive) { @@ -644,19 +568,6 @@ cxxSS::multiply(LDBLE extensive) this->ss_comps[i].Set_delta(d); } } -#ifdef SKIP -void -cxxSS::multiply(LDBLE extensive) -{ - //char *name; - //cxxNameDouble comps; - this->comps.multiply(extensive); - //LDBLE a0, a1; - //LDBLE ag0, ag1; - //bool miscibility; - //LDBLE xb1, xb2; -} -#endif cxxSScomp * cxxSS::Find(const char * comp_name) { diff --git a/SS.h b/SS.h index a61be110..91014623 100644 --- a/SS.h +++ b/SS.h @@ -59,12 +59,7 @@ class cxxSS: public PHRQ_base { return (this->totals); }; -#ifdef SKIP - const cxxNameDouble & Get_comps() const - { - return (this->comps); - }; -#endif + #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 3e7a102c..60086c45 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -27,26 +27,7 @@ cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) : cxxNumKeyword(io) { } -#ifdef SKIP -cxxSSassemblage::cxxSSassemblage(struct ss_assemblage * ss_assemblage_ptr, PHRQ_io * io) - // - // constructor for cxxSSassemblage from struct SSassemblage - // -: -cxxNumKeyword(io) -{ - int i; - this->Set_description(ss_assemblage_ptr->description); - n_user = ss_assemblage_ptr->n_user; - n_user_end = ss_assemblage_ptr->n_user_end; - for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) - { - cxxSS ssSS(&(ss_assemblage_ptr->s_s[i]), this->Get_io()); - std::string str(ssSS.Get_name()); - SSs[str] = ssSS; - } -} -#endif + cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxSSassemblage > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): @@ -213,92 +194,6 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) break; } } -#ifdef SKIP -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); - - // 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 - { - cxxSS ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - if (this->SSs.find(ec.Get_name()) != this->SSs.end()) - { - cxxSS & ec1 = this->SSs.find(ec.Get_name())->second; - ec1.read_raw(reread, false); - } - else - { - cxxSS ec1(this->Get_io()); - ec1.read_raw(reread, false); - std::string str(ec1.Get_name()); - this->SSs[str] = ec1; - } - } - useLastLine = true; - break; - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } -} -#endif #ifdef USE_MPI /* ---------------------------------------------------------------------- */ void diff --git a/SScomp.cxx b/SScomp.cxx index 81870cf4..d2e20439 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -36,26 +36,6 @@ PHRQ_base(io) dnc = 0; dnb = 0; } -#ifdef SKIP -cxxSScomp::cxxSScomp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) -: -PHRQ_base(io) - // - // constructor for cxxSScomp from struct pure_phase - // -{ - this->Set_name(pure_phase_ptr->name); - this->Set_add_formula(pure_phase_ptr->add_formula); - si = pure_phase_ptr->si; - si_org = pure_phase_ptr->si_org; - moles = pure_phase_ptr->moles; - delta = pure_phase_ptr->delta; - initial_moles = pure_phase_ptr->initial_moles; - force_equality = (pure_phase_ptr->force_equality == TRUE); - dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); - precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); -} -#endif cxxSScomp::~cxxSScomp() { } diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 4d66bebf..bebb1042 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -174,7 +174,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) vopts.push_back("formula"); // 0 vopts.push_back("moles"); // 1 vopts.push_back("la"); // 2 - vopts.push_back("charge_number"); // 3 + vopts.push_back("charge_number_not_used"); // 3 vopts.push_back("charge_balance"); // 4 vopts.push_back("phase_name"); // 5 vopts.push_back("rate_name"); // 6 @@ -257,18 +257,17 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) } la_defined = true; break; -#ifdef SKIP - case 3: // charge_number - if (!(parser.get_iss() >> this->charge_number)) - { - this->charge_number = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for charge_number.", - PHRQ_io::OT_CONTINUE); - } - charge_number_defined = true; + case 3: // charge_number not used + //if (!(parser.get_iss() >> this->charge_number)) + //{ + // this->charge_number = 0; + // parser.incr_input_error(); + // parser.error_msg("Expected integer value for charge_number.", + // PHRQ_io::OT_CONTINUE); + //} + //charge_number_defined = true; break; -#endif + case 4: // charge_balance if (!(parser.get_iss() >> this->charge_balance)) { @@ -397,14 +396,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser.error_msg("La not defined for SurfaceComp input.", PHRQ_io::OT_CONTINUE); } -#ifdef SKIP - if (charge_number_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Charge_number not defined for SurfaceComp input.", - PHRQ_io::OT_CONTINUE); - } -#endif + if (charge_balance_defined == false) { parser.incr_input_error(); diff --git a/Utils.h b/Utils.h index b5d93c27..5ad83065 100644 --- a/Utils.h +++ b/Utils.h @@ -12,14 +12,6 @@ namespace Utilities { const char INDENT[] = " "; -#ifdef SKIP - enum STATUS_TYPE - { - ST_OK = 0, - ST_ERROR = 1 - }; -#endif - //STATUS_TYPE parse_couple(std::string & token); int strcmp_nocase(const char *str1, const char *str2); diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 12b218e9..6206cdd9 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -727,20 +727,6 @@ equi_phase(const char *phase_name) /* * Print pure phase assemblage data */ -#ifdef SKIP - if (j == count_unknowns) - { - /* if not an unknown */ - for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) - { - if (strcmp_nocase - (use.Get_pp_assemblage_ptr()->pure_phases[i].name, phase_name) == 0) - { - return (use.Get_pp_assemblage_ptr()->pure_phases[i].moles); - } - } - } -#endif cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); if (j == count_unknowns) { @@ -911,90 +897,6 @@ find_ss_comp(const char *ss_comp_name) } return (0); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -find_misc1(const char *s_s_name) -/* ---------------------------------------------------------------------- */ -{ - int j; - - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) - return (0.0); - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name) == 0) - { - if (use.Get_ss_assemblage_ptr()->s_s[j].miscibility == TRUE) - { - return (use.Get_ss_assemblage_ptr()->s_s[j].xb1); - } - else - { - return (1.0); - } - } - } - return (0); -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -find_misc2(const char *s_s_name) -/* ---------------------------------------------------------------------- */ -{ - int j; - - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) - return (0.0); - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name) == 0) - { - if (use.Get_ss_assemblage_ptr()->s_s[j].miscibility == TRUE) - { - return (use.Get_ss_assemblage_ptr()->s_s[j].xb2); - } - else - { - return (1.0); - } - } - } - return (0); -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -find_s_s_comp(const char *s_s_comp_name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) - return (0); - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - if (strcmp_nocase - (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, - s_s_comp_name) == 0) - { - if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) - { - return (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles); - } - else - { - return (0.0); - } - } - } - } - return (0); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: get_calculate_value(const char *name) @@ -1444,84 +1346,6 @@ list_ss(std::string ss_name, cxxNameDouble &composition) } return (tot); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -sum_match_s_s(const char *mytemplate, const char *name) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - LDBLE tot; - struct elt_list *next_elt; - - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) - return (0); - tot = 0; - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, mytemplate) == - 0) - { - if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == FALSE) - { - tot = 0; - break; - } - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - if (name == NULL) - { - tot += use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; - } - else - { - for (next_elt = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].phase-> - next_elt; next_elt->elt != NULL; next_elt++) - { - if (strcmp(next_elt->elt->name, name) == 0) - { - tot += - next_elt->coef * - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; - break; - } - } - } - } - break; - } - } - return (tot); -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -list_s_s(std::string s_s_name, cxxNameDouble &composition) -/* ---------------------------------------------------------------------- */ -{ - int i, j; - - LDBLE tot = 0; - composition.clear(); - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) - return (0); - - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - if (strcmp_nocase(use.Get_ss_assemblage_ptr()->s_s[j].name, s_s_name.c_str()) == 0) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - composition.add(use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles); - tot += use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; - } - break; - } - } - return (tot); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: match_elts_in_species(const char *name, const char *mytemplate) @@ -2440,41 +2264,6 @@ system_total_ss(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -system_total_s_s(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides total moles in system and lists of species/phases in sort order - */ - int i, k; - -/* - * Solid solutions - */ - if (use.Get_ss_assemblage_ptr() == NULL) - return (OK); - for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; i++) - { - sys[count_sys].name = - string_duplicate(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. - phase->name); - sys[count_sys].moles = - use.Get_ss_assemblage_ptr()->s_s[k].comps[i].moles; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, &max_sys, - sizeof(struct system_species)); - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: system_total_elt(const char *total_name) @@ -2700,50 +2489,6 @@ system_total_elt(const char *total_name) } } } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) - { - if (use.Get_ss_assemblage_ptr()->s_s[k].ss_in == TRUE) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; - i++) - { - count_elts = 0; - paren_count = 0; - add_elt_list(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. - phase->next_elt, - use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. - moles); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), - elt_list_compare); - elt_list_combine(); - } - for (j = 0; j < count_elts; j++) - { - if (strcmp(elt_list[j].elt->name, total_name) == 0) - { - sys[count_sys].name = - string_duplicate(use.Get_ss_assemblage_ptr()-> - s_s[k].comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, - &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - } -#endif /* * find total in gas phase */ @@ -3017,50 +2762,6 @@ system_total_elt_secondary(const char *total_name) } } } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - for (k = 0; k < use.Get_ss_assemblage_ptr()->count_s_s; k++) - { - if (use.Get_ss_assemblage_ptr()->s_s[k].ss_in == TRUE) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[k].count_comps; - i++) - { - count_elts = 0; - paren_count = 0; - add_elt_list(use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. - phase->next_sys_total, - use.Get_ss_assemblage_ptr()->s_s[k].comps[i]. - moles); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), - elt_list_compare); - elt_list_combine(); - } - for (j = 0; j < count_elts; j++) - { - if (strcmp(elt_list[j].elt->name, total_name) == 0) - { - sys[count_sys].name = - string_duplicate(use.Get_ss_assemblage_ptr()-> - s_s[k].comps[i].phase->name); - sys[count_sys].moles = elt_list[j].coef; - sys_tot += sys[count_sys].moles; - sys[count_sys].type = string_duplicate("s_s"); - count_sys++; - space((void **) ((void *) &sys), count_sys, - &max_sys, sizeof(struct system_species)); - break; - } - } - } - } - } - } -#endif /* * find total in gas phase */ @@ -3224,20 +2925,6 @@ system_total_solids(cxxExchange *exchange_ptr, } } } -#ifdef SKIP - if (ss_assemblage_ptr != NULL) - { - for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) - { - for (j = 0; j < ss_assemblage_ptr->s_s[i].count_comps; j++) - { - add_elt_list(ss_assemblage_ptr->s_s[i].comps[j].phase-> - next_elt, - ss_assemblage_ptr->s_s[i].comps[j].moles); - } - } - } -#endif if (gas_phase_ptr != NULL) { for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index a68cc9ad..f48e126c 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -487,80 +487,7 @@ struct save int n_ss_assemblage_user; int n_ss_assemblage_user_end; }; -#ifdef SKIP -/*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ -struct Use -{ - int solution_in; - int n_solution_user; - int n_solution; - struct solution *solution_ptr; - int pp_assemblage_in; - int n_pp_assemblage_user; - //int n_pp_assemblage; - //struct pp_assemblage *pp_assemblage_ptr; - void *pp_assemblage_ptr; - - int mix_in; - int n_mix_user; - int n_mix; - //struct mix *mix_ptr; - void * mix_ptr; - int n_mix_user_orig; - - int reaction_in; - int n_reaction_user; - //int n_irrev; - //struct irrev *irrev_ptr; - void * reaction_ptr; - - int exchange_in; - int n_exchange_user; - //int n_exchange; - //struct exchange *exchange_ptr; - void * exchange_ptr; - - int kinetics_in; - int n_kinetics_user; - int n_kinetics; - struct kinetics *kinetics_ptr; - - int surface_in; - int n_surface_user; - int n_surface; - struct surface *surface_ptr; - - int pressure_in; - int n_pressure_user; - void *pressure_ptr; - - int temperature_in; - int n_temperature_user; - void *temperature_ptr; - - int inverse_in; - int n_inverse_user; - int n_inverse; - struct inverse *inverse_ptr; - - int gas_phase_in; - int n_gas_phase_user; - //int n_gas_phase; - //struct gas_phase *gas_phase_ptr; - void * gas_phase_ptr; - - int ss_assemblage_in; - int n_ss_assemblage_user; - int n_ss_assemblage; - struct ss_assemblage *ss_assemblage_ptr; - - int trans_in; - int advect_in; -}; -#endif /*---------------------------------------------------------------------- * Copy *---------------------------------------------------------------------- */ @@ -648,81 +575,6 @@ struct name_coef const char *name; LDBLE coef; }; -#ifdef SKIP -/*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ -struct ss_assemblage -{ - int n_user; - int n_user_end; - char *description; - int new_def; - /* int type; */ - /* int solution_equilibria; */ - /* int n_solution; */ - int count_s_s; - struct s_s *s_s; -}; -struct s_s -{ - const char *name; - struct s_s_comp *comps; - int count_comps; - LDBLE total_moles; - LDBLE dn; - LDBLE a0, a1; - LDBLE ag0, ag1; - int ss_in; - int miscibility; - int spinodal; - LDBLE tk, xb1, xb2; - int input_case; - LDBLE p[4]; -}; -struct s_s_comp -{ - const char *name; - struct phase *phase; - LDBLE initial_moles; - LDBLE moles; - LDBLE init_moles; - LDBLE delta; - LDBLE fraction_x; - LDBLE log10_lambda; - LDBLE log10_fraction_x; - LDBLE dn, dnc, dnb; -}; -#endif -#ifdef SKIP -/*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - struct pp_assemblage - { - int n_user; - int n_user_end; - char *description; - int new_def; - struct elt_list *next_elt; - int count_comps; - struct pure_phase *pure_phases; - }; - struct pure_phase - { - struct phase *phase; - const char *name; - const char *add_formula; - LDBLE si; - LDBLE si_org; - LDBLE moles; - LDBLE delta; - LDBLE initial_moles; - int force_equality; - int dissolve_only; - int precipitate_only; -}; -#endif /*---------------------------------------------------------------------- * Species_list *---------------------------------------------------------------------- */ diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index a7b83725..00bc855e 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -319,26 +319,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, { set_reaction(i, NOMIX, TRUE); } -#ifdef SKIP - if (use.Get_pp_assemblage_ptr() != NULL) - { - pp_assemblage_save = - (struct pp_assemblage *) - PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_save == NULL) - malloc_error(); - } -#endif -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - ss_assemblage_save = - (struct ss_assemblage *) - PHRQ_malloc(sizeof(struct ss_assemblage)); - if (ss_assemblage_save == NULL) - malloc_error(); - } -#endif kinetics_ptr = kinetics_bsearch(i, &m); step_bad = step_ok = 0; @@ -1161,18 +1141,6 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - ss_assemblage_save = - (struct ss_assemblage *) - PHRQ_malloc(sizeof(struct ss_assemblage)); - if (ss_assemblage_save == NULL) - malloc_error(); - ss_assemblage_copy(use.Get_ss_assemblage_ptr(), ss_assemblage_save, - use.Get_ss_assemblage_ptr()->n_user); - } -#endif if (use.Get_kinetics_ptr() != NULL) { kinetics_save = @@ -2081,16 +2049,6 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) if (ss_assemblage_ptr != NULL) { cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); -#ifdef SKIP - cvode_ss_assemblage_save = - (struct ss_assemblage *) - PHRQ_malloc(sizeof(struct ss_assemblage)); - if (cvode_ss_assemblage_save == NULL) - malloc_error(); - ss_assemblage_copy(ss_assemblage_ptr, - cvode_ss_assemblage_save, - ss_assemblage_ptr->n_user); -#endif } /* allocate space for CVODE */ @@ -2600,19 +2558,6 @@ store_get_equi_reactants(int l, int kin_end) count_ss += (int) ss_ptr->Get_ss_comps().size(); } } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; - i++) - { - count_s_s++; - } - } - } -#endif k = count_pp + count_ss + count_pg; x0_moles = NULL; if (k == 0) @@ -2634,12 +2579,7 @@ store_get_equi_reactants(int l, int kin_end) x0_moles[++k] = it->second.Get_moles(); } } -#ifdef SKIP - for (j = 0; j < count_pp; j++) - { - x0_moles[++k] = use.Get_pp_assemblage_ptr()->pure_phases[j].moles; - } -#endif + { cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); if (gas_phase_ptr) @@ -2679,13 +2619,7 @@ store_get_equi_reactants(int l, int kin_end) it->second.Set_delta(0.0); } } -#ifdef SKIP - for (j = 0; j < count_pp; j++) - { - use.Get_pp_assemblage_ptr()->pure_phases[j].moles = x0_moles[++k]; - use.Get_pp_assemblage_ptr()->pure_phases[j].delta = 0.0; - } -#endif + { cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); if (gas_phase_ptr && count_pg) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 517cb1aa..eb2f583b 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1827,10 +1827,7 @@ xss_assemblage_save(int n_user) * Save ss_assemblage composition into structure ss_assemblage with user * number n_user. */ - //int i, j, n; - //int count_comps, count_s_s; cxxSSassemblage temp_ss_assemblage; - //char token[MAX_LENGTH]; if (use.Get_ss_assemblage_ptr() == NULL) return (OK); @@ -1864,97 +1861,6 @@ xss_assemblage_save(int n_user) use.Set_ss_assemblage_ptr(NULL); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -xss_assemblage_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save ss_assemblage composition into structure ss_assemblage with user - * number n_user. - */ - int i, j, n; - int count_comps, count_s_s; - struct ss_assemblage temp_ss_assemblage, *ss_assemblage_ptr; - char token[MAX_LENGTH]; - - if (use.Get_ss_assemblage_ptr() == NULL) - return (OK); -/* - * Set ss_assemblage - */ - temp_ss_assemblage.n_user = n_user; - temp_ss_assemblage.n_user_end = n_user; - sprintf(token, "Solid solution assemblage after simulation %d.", - simulation); - temp_ss_assemblage.description = string_duplicate(token); - temp_ss_assemblage.new_def = FALSE; - count_s_s = use.Get_ss_assemblage_ptr()->count_s_s; - temp_ss_assemblage.count_s_s = count_s_s; -/* - * Malloc space for solid solutions - */ - /* ss_assemblage->s_s */ - temp_ss_assemblage.s_s = - (struct s_s *) PHRQ_malloc((size_t) count_s_s * sizeof(struct s_s)); - if (temp_ss_assemblage.s_s == NULL) - malloc_error(); - for (i = 0; i < count_s_s; i++) - { - memcpy(&(temp_ss_assemblage.s_s[i]), - &(use.Get_ss_assemblage_ptr()->s_s[i]), sizeof(struct s_s)); - /* - * Malloc space for solid soution components - */ - count_comps = use.Get_ss_assemblage_ptr()->s_s[i].count_comps; - temp_ss_assemblage.s_s[i].comps = - (struct s_s_comp *) PHRQ_malloc((size_t) count_comps * - sizeof(struct s_s_comp)); - if (temp_ss_assemblage.s_s[i].comps == NULL) - malloc_error(); - memcpy((void *) temp_ss_assemblage.s_s[i].comps, - (void *) use.Get_ss_assemblage_ptr()->s_s[i].comps, - (size_t) count_comps * sizeof(struct s_s_comp)); - - /* set initial moles for quick setup */ - for (j = 0; j < count_comps; j++) - { - temp_ss_assemblage.s_s[i].comps[j].initial_moles = - temp_ss_assemblage.s_s[i].comps[j].moles; - } - } -/* - * Finish up - */ - ss_assemblage_ptr = ss_assemblage_bsearch(n_user, &n); - if (ss_assemblage_ptr == NULL) - { - space((void **) ((void *) &ss_assemblage), count_ss_assemblage, - &max_ss_assemblage, sizeof(struct ss_assemblage)); - n = count_ss_assemblage++; - } - else - { - ss_assemblage_free(&ss_assemblage[n]); - } - memcpy(&ss_assemblage[n], &temp_ss_assemblage, - sizeof(struct ss_assemblage)); - /* sort only if necessary */ - if (n == count_ss_assemblage - 1 && count_ss_assemblage > 1) - { - if (ss_assemblage[n].n_user < ss_assemblage[n - 1].n_user) - { - qsort(ss_assemblage, - (size_t) count_ss_assemblage, - (size_t) sizeof(struct ss_assemblage), - ss_assemblage_compare); - } - } - use.Set_ss_assemblage_ptr(NULL); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: xpp_assemblage_save(int n_user) @@ -1996,92 +1902,6 @@ xpp_assemblage_save(int n_user) use.Set_pp_assemblage_ptr(NULL); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -xpp_assemblage_save(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save pure_phase assemblage into structure pp_assemblage with user - * number n_user. - */ - int count_comps, n, j, i; - struct pp_assemblage temp_pp_assemblage, *pp_assemblage_ptr; - char token[MAX_LENGTH]; - - if (use.Get_pp_assemblage_ptr() == NULL) - return (OK); -/* - * Count pure phases - */ - count_comps = use.Get_pp_assemblage_ptr()->count_comps; - - temp_pp_assemblage.n_user = n_user; - temp_pp_assemblage.n_user_end = n_user; - sprintf(token, "Pure-phase assemblage after simulation %d.", simulation); - temp_pp_assemblage.description = string_duplicate(token); - temp_pp_assemblage.new_def = FALSE; - temp_pp_assemblage.count_comps = count_comps; - temp_pp_assemblage.next_elt = - elt_list_dup(use.Get_pp_assemblage_ptr()->next_elt); -/* - * Malloc space and copy pure phase data - */ - temp_pp_assemblage.pure_phases = - (struct pure_phase *) PHRQ_malloc((size_t) count_comps * - sizeof(struct pure_phase)); - if (temp_pp_assemblage.pure_phases == NULL) - malloc_error(); - memcpy((void *) temp_pp_assemblage.pure_phases, - (void *) use.Get_pp_assemblage_ptr()->pure_phases, - (size_t) count_comps * sizeof(struct pure_phase)); -/* - * Update amounts - */ - i = 0; - for (j = 0; j < count_unknowns; j++) - { - if (x[j]->type != PP) - continue; - temp_pp_assemblage.pure_phases[i].moles = x[j]->moles; - temp_pp_assemblage.pure_phases[i].delta = 0.0; - - /* update unknown ptr, old may be freed later */ - x[j]->pure_phase = &(temp_pp_assemblage.pure_phases[i]); - i++; - } -/* - * Finish up - */ - pp_assemblage_ptr = pp_assemblage_bsearch(n_user, &n); - if (pp_assemblage_ptr == NULL) - { - space((void **) ((void *) &pp_assemblage), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - n = count_pp_assemblage++; - } - else - { - pp_assemblage_free(&pp_assemblage[n]); - } - memcpy(&pp_assemblage[n], &temp_pp_assemblage, - sizeof(struct pp_assemblage)); - /* sort only if necessary */ - if (n == count_pp_assemblage - 1 && count_pp_assemblage > 1) - { - if (pp_assemblage[n].n_user < pp_assemblage[n - 1].n_user) - { - qsort(pp_assemblage, - (size_t) count_pp_assemblage, - (size_t) sizeof(struct pp_assemblage), - pp_assemblage_compare); - } - } - use.Get_pp_assemblage_ptr() = NULL; - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: xsolution_save(int n_user) @@ -2851,62 +2671,6 @@ step_save_exch(int n_user) Rxn_exchange_map[n_user] = temp_exchange; return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -step_save_exch(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Save exchange composition - * - * input: n_user is user exchange number of target - */ - //int i; - bool found; - - if (use.Get_exchange_ptr() == NULL) - return (OK); - //exchange_duplicate(use.Get_exchange_ptr()->n_user, n_user); - //exchange_ptr = exchange_bsearch(n_user, &n); - cxxExchange *temp_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); - assert(temp_ptr); - cxxExchange temp_exchange = *temp_ptr; - - for (int i = 0; i < count_master; i++) - { - if (master[i]->s->type != EX) - continue; - found = false; - std::string e(master[i]->elt->name); - std::map::iterator it = temp_exchange.Get_exchComps().begin(); - for ( ; it != temp_exchange.Get_exchComps().end(); it++) - { - cxxNameDouble nd = it->second.Get_totals(); - nd.multiply(0.0); - cxxNameDouble::iterator nd_it =nd.find(e); - if ((!found) && nd_it != nd.end()) - { - found = true; - LDBLE coef; - if (master[i]->total <= MIN_TOTAL) - { - coef = MIN_TOTAL; - } - else - { - coef = master[i]->total; - } - nd[nd_it->first.c_str()] = coef; - } - it->second.Set_totals(nd); - } - } - - Rxn_exchange_map[n_user] = temp_exchange; - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: step_save_surf(int n_user) @@ -3503,70 +3267,3 @@ save_init(int i) save.n_ss_assemblage_user = i; save.n_ss_assemblage_user_end = i; } -#ifdef SKIP -void Phreeqc:: -use_init(void) -{ - use.Get_solution_in() = FALSE; - use.Get_n_solution_user()= -1; - use.Get_n_solution()= -1; - use.Get_solution_ptr() = NULL; - - use.Get_pp_assemblage_in() = FALSE; - use.Get_n_pp_assemblage_user()= -1; - //use.n_pp_assemblage= -1; - use.Get_pp_assemblage_ptr() = NULL; - - use.Get_mix_in() = FALSE; - use.Get_n_mix_user()= -1; - //use.n_mix= -1; - use.Get_mix_ptr() = NULL; - use.Get_n_mix_user_orig()= -1; - - use.Get_reaction_in() = FALSE; - use.Get_n_reaction_user()= -1; - //use.n_irrev= -1; - use.Get_reaction_ptr() = NULL; - - use.Get_exchange_in() = FALSE; - use.Get_n_exchange_user()= -1; - //use.n_exchange= -1; - use.Get_exchange_ptr() = NULL; - - use.Get_kinetics_in() = FALSE; - use.Get_n_kinetics_user()= -1; - use.n_kinetics= -1; - use.Get_kinetics_ptr() = NULL; - - use.Get_surface_in() = FALSE; - use.Get_n_surface_user()= -1; - use.n_surface= -1; - use.Get_surface_ptr() = NULL; - - use.Get_temperature_in() = FALSE; - use.Get_n_temperature_user()= -1; - use.Get_temperature_ptr() = NULL; - - use.Get_pressure_in() = FALSE; - use.Get_n_pressure_user()= -1; - use.Get_pressure_ptr() = NULL; - - use.Get_inverse_in() = FALSE; - use.Get_n_inverse_user()= -1; - use.n_inverse= -1; - use.Get_inverse_ptr() = NULL; - - use.Get_gas_phase_in() = FALSE; - use.Get_n_gas_phase_user()= -1; - //use.n_gas_phase= -1; - use.Get_gas_phase_ptr() = NULL; - - use.Get_ss_assemblage_in() = FALSE; - use.Get_n_ss_assemblage_user()= -1; - use.n_ss_assemblage= -1; - use.Get_ss_assemblage_ptr() = NULL; - - use.trans_in = FALSE; - use.advect_in = FALSE; -} -#endif \ No newline at end of file diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 51e9b0a6..a18d52c1 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -457,61 +457,6 @@ check_residuals(void) } } } -#ifdef SKIP - else if (x[i]->type == PP) - { - if (x[i]->pure_phase->add_formula == NULL) - { - if (x[i]->dissolve_only == TRUE) - { - if ((residual[i] > epsilon && x[i]->moles > 0.0) - || - ((residual[i] < -epsilon - && (x[i]->pure_phase->initial_moles - x[i]->moles) > - 0))) - { - log_msg(sformatf( - "%20s Dissolve_only pure phase has not converged. \tResidual: %e\n", - x[i]->description, (double) residual[i])); - } - } - else - { - if ((residual[i] >= epsilon - && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) - { - remove_unstable_phases = TRUE; - log_msg(sformatf( - "%20s Pure phase has not converged. \tResidual: %e\n", - x[i]->description, (double) residual[i])); - } - else if (residual[i] <= -epsilon) - { - error_string = sformatf( - "%20s Pure phase has not converged. " - "\tResidual: %e\n", x[i]->description, - (double) residual[i]); - error_msg(error_string, CONTINUE); - } - } - } - else - { - if ((fabs(residual[i]) >= epsilon - && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) - { - log_msg(sformatf( - "%s, Pure phase has not converged. \tResidual: %e\n", - x[i]->description, (double) residual[i])); - error_string = sformatf( - "%s, Pure phase with add formula has not converged.\n\t SI may be a local minimum." - "\tResidual: %e\n", x[i]->description, - (double) residual[i]); - warning_msg(error_string); - } - } - } -#endif else if (x[i]->type == EXCH) { if ( /* stop_program == TRUE || */ @@ -1028,30 +973,6 @@ ineq(int in_kode) } } } -#ifdef SKIP - for (i = 0; i < count_unknowns; i++) - { - - if (x[i]->type == PP && residual[i] > 0e-8 && x[i]->moles > 0 && - x[i]->pure_phase->add_formula == NULL - && x[i]->dissolve_only == FALSE) - { -/* - * Set mass transfer to all of phase - */ - delta[i] = x[i]->moles; - } - else - { - delta[i] = 0.0; - } - if (debug_model == TRUE) - { - output_msg(sformatf( "%6d %-12.12s %10.2e\n", i, - x[i]->description, (double) delta[i])); - } - } -#endif remove_unstable_phases = FALSE; return (OK); } @@ -1307,57 +1228,6 @@ ineq(int in_kode) l_count_rows++; } } -#ifdef SKIP - if (x[i]->type == PP) - { - /* not in model, ignore */ - if (x[i]->pure_phase->phase->in == FALSE) - continue; - if (x[i]->pure_phase->force_equality == TRUE) - continue; - /* Undersaturated and no mass, ignore */ - if (x[i]->f > 0e-8 && x[i]->moles <= 0 - && x[i]->pure_phase->add_formula == NULL) - { - continue; - } - else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE - && (x[i]->moles - x[i]->pure_phase->initial_moles >= 0)) - { - continue; - } - else - { - /* Copy in saturation index equation (has mass or supersaturated) */ - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back_eq[l_count_rows] = i; - if (x[i]->pure_phase->add_formula == NULL - && x[i]->dissolve_only == FALSE) - { - res[l_count_rows] = 1.0; - } -/* - * If infeasible solution on first attempt, remove constraints on IAP - */ - if (pp_scale != 1) - { - for (j = 0; j < count_unknowns + 1; j++) - { - ineq_array[l_count_rows * max_column_count + j] *= - pp_scale; - } - } - - if (in_kode != 1) - { - res[l_count_rows] = 0.0; - } - l_count_rows++; - } - } -#endif else if (x[i]->type == ALK || x[i]->type == SOLUTION_PHASE_BOUNDARY) { /* @@ -1680,35 +1550,6 @@ ineq(int in_kode) } } } -#ifdef SKIP -/* - * No moles of surface - */ - if (use.Get_surface_ptr() != NULL - && (use.Get_surface_ptr()->related_phases == TRUE - || use.Get_surface_ptr()->related_rate == TRUE)) - { - for (i = 0; i < count_unknowns; i++) - { - if ((x[i]->type == SURFACE && x[i]->phase_unknown != NULL && -/* x[i]->phase_unknown->f > 0e-8 && */ - x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && - x[i]->phase_unknown->pure_phase->add_formula == NULL) || - ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 - || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL && -/* x[i-1]->phase_unknown->f > 0e-8 && */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && - x[i - 1]->phase_unknown->pure_phase->add_formula == NULL)) - { - for (j = 0; j < l_count_rows; j++) - { - ineq_array[j * max_column_count + i] = 0.0; - } - } - } - } -#endif /* * No moles of surface */ @@ -2431,129 +2272,6 @@ mb_ss(void) //x[i]->ss_in = x[i]->s_s->ss_in; x[i]->ss_in = ss_ptr->Get_ss_in() ? TRUE : FALSE; } -#ifdef SKIP - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[i]); - total_moles = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) - { - total_moles += s_s_ptr->comps[j].moles; - } - if (total_moles > 1e-13) - { - s_s_ptr->ss_in = TRUE; - } - else if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) - { - /* - * Calculate IAPc and IAPb - */ - if (s_s_ptr->comps[0].phase->rxn_x != NULL) - { - log10_iap = 0; - for (rxn_ptr = s_s_ptr->comps[0].phase->rxn_x->token + 1; - rxn_ptr->s != NULL; rxn_ptr++) - { - log10_iap += rxn_ptr->s->la * rxn_ptr->coef; - } - iapc = exp(log10_iap * LOG_10); - } - else - { - iapc = 1e-99; - } - if (s_s_ptr->comps[1].phase->rxn_x != NULL) - { - log10_iap = 0; - for (rxn_ptr = s_s_ptr->comps[1].phase->rxn_x->token + 1; - rxn_ptr->s != NULL; rxn_ptr++) - { - log10_iap += rxn_ptr->s->la * rxn_ptr->coef; - } - iapb = exp(log10_iap * LOG_10); - } - else - { - iapb = 1e-99; - } - /* - * Calculate sigma pi, aq - */ - sigmapi_aq = iapc + iapb; - /* - * Calculate xc,aq and xb, aq - */ - xcaq = iapc / (iapb + iapc); - xbaq = iapb / (iapb + iapc); - /* - * Get Kc and Kb - */ - l_kc = exp(s_s_ptr->comps[0].phase->lk * LOG_10); - l_kb = exp(s_s_ptr->comps[1].phase->lk * LOG_10); - /* - * Solve for xb - */ - xb = s_s_root(s_s_ptr->a0, s_s_ptr->a1, l_kc, l_kb, xcaq, xbaq); - /* - * Calculate lambdac and lambdab - */ - xc = 1 - xb; - lc = exp((s_s_ptr->a0 - s_s_ptr->a1 * (-4 * xb + 3)) * xb * xb); - lb = exp((s_s_ptr->a0 + s_s_ptr->a1 * (4 * xb - 1)) * xc * xc); - /* - * Calculate sigma pi, solid - */ - sigmapi_solid = xb * lb * l_kb + xc * lc * l_kc; - /* - * If Sigma pi, solid < sigma pi, aq, then use eqns - */ - if (sigmapi_solid < sigmapi_aq) - { - s_s_ptr->ss_in = TRUE; - } - else - { - s_s_ptr->ss_in = FALSE; - } - } - else - { - /* - * Calculate total mole fraction from solution activities - */ - total_p = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) - { - phase_ptr = s_s_ptr->comps[j].phase; - if (phase_ptr->in == TRUE) - { - lp = -phase_ptr->lk; - for (rxn_ptr = s_s_ptr->comps[j].phase->rxn_x->token + 1; - rxn_ptr->s != NULL; rxn_ptr++) - { - lp += rxn_ptr->s->la * rxn_ptr->coef; - } - total_p += exp(lp * LOG_10); - } - } - if (total_p > 1.0) - { - s_s_ptr->ss_in = TRUE; - } - else - { - s_s_ptr->ss_in = FALSE; - } - } - } - for (i = ss_unknown->number; i < count_unknowns; i++) - { - if (x[i]->type != SS_MOLES) - break; - x[i]->ss_in = x[i]->s_s->ss_in; - } -#endif return (OK); } @@ -3043,67 +2761,6 @@ calc_ss_fractions(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_s_s_fractions(void) -/* ---------------------------------------------------------------------- */ -{ - int i, k; - LDBLE moles, n_tot; - struct s_s *s_s_ptr; - -/* - * moles and lambdas for solid solutions - */ - if (ss_unknown == NULL) - return (OK); -/* - * Calculate mole fractions and log lambda and derivative factors - */ - if (use.Get_ss_assemblage_ptr() == NULL) - return (OK); - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[i]); - n_tot = 0; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - moles = s_s_ptr->comps[k].moles; - if (s_s_ptr->comps[k].moles < 0) - { - moles = MIN_TOTAL_SS; - s_s_ptr->comps[k].initial_moles = moles; - } - n_tot += moles; - } - s_s_ptr->total_moles = n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - moles = s_s_ptr->comps[k].moles; - if (s_s_ptr->comps[k].moles < 0) - { - moles = MIN_TOTAL_SS; - } - s_s_ptr->comps[k].fraction_x = moles / n_tot; - s_s_ptr->comps[k].log10_fraction_x = log10(moles / n_tot); - - /* all mb and jacobian items must be in x or phase to be static between models */ - s_s_ptr->comps[k].phase->log10_fraction_x = - s_s_ptr->comps[k].log10_fraction_x; - } - if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0) - { - s_s_binary(s_s_ptr); - } - else - { - s_s_ideal(s_s_ptr); - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_binary(cxxSS *ss_ptr) @@ -3228,127 +2885,6 @@ ss_binary(cxxSS *ss_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -s_s_binary(struct s_s *s_s_ptr) -/* ---------------------------------------------------------------------- */ -{ - LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; - LDBLE xb2, xb3, xb4, xc2, xc3; - LDBLE xb1, xc1; -/* - * component 0 is major component - * component 1 is minor component - * xb is the mole fraction of second component (formerly trace) - * xc is the mole fraction of first component (formerly major) -*/ -/* - * Calculate mole fractions and log lambda and derivative factors - */ - n_tot = s_s_ptr->total_moles; - - nc = s_s_ptr->comps[0].moles; - xc = nc / n_tot; - nb = s_s_ptr->comps[1].moles; - xb = nb / n_tot; -/* - * In miscibility gap - */ - l_a0 = s_s_ptr->a0; - l_a1 = s_s_ptr->a1; - if (s_s_ptr->miscibility == TRUE && xb > s_s_ptr->xb1 - && xb < s_s_ptr->xb2) - { - xb1 = s_s_ptr->xb1; - xc1 = 1.0 - xb1; - s_s_ptr->comps[0].fraction_x = xc1; - s_s_ptr->comps[0].log10_fraction_x = log10(xc1); - s_s_ptr->comps[0].phase->log10_fraction_x = - s_s_ptr->comps[0].log10_fraction_x; - - s_s_ptr->comps[1].fraction_x = xb1; - s_s_ptr->comps[1].log10_fraction_x = log10(xb1); - s_s_ptr->comps[1].phase->log10_fraction_x = - s_s_ptr->comps[1].log10_fraction_x; - - s_s_ptr->comps[0].log10_lambda = - xb1 * xb1 * (l_a0 - l_a1 * (3 - 4 * xb1)) / LOG_10; - s_s_ptr->comps[0].phase->log10_lambda = - s_s_ptr->comps[0].log10_lambda; - - s_s_ptr->comps[1].log10_lambda = - xc1 * xc1 * (l_a0 + l_a1 * (4 * xb1 - 1)) / LOG_10; - s_s_ptr->comps[1].phase->log10_lambda = - s_s_ptr->comps[1].log10_lambda; - - s_s_ptr->comps[0].dnb = 0; - s_s_ptr->comps[0].dnc = 0; - s_s_ptr->comps[1].dnb = 0; - s_s_ptr->comps[1].dnc = 0; - s_s_ptr->comps[0].phase->dnb = 0; - s_s_ptr->comps[0].phase->dnc = 0; - s_s_ptr->comps[1].phase->dnb = 0; - s_s_ptr->comps[1].phase->dnc = 0; - } - else - { -/* - * Not in miscibility gap - */ - s_s_ptr->comps[0].fraction_x = xc; - s_s_ptr->comps[0].log10_fraction_x = log10(xc); - s_s_ptr->comps[0].phase->log10_fraction_x = - s_s_ptr->comps[0].log10_fraction_x; - - s_s_ptr->comps[1].fraction_x = xb; - s_s_ptr->comps[1].log10_fraction_x = log10(xb); - s_s_ptr->comps[1].phase->log10_fraction_x = - s_s_ptr->comps[1].log10_fraction_x; - - s_s_ptr->comps[0].log10_lambda = - xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; - s_s_ptr->comps[0].phase->log10_lambda = - s_s_ptr->comps[0].log10_lambda; - - s_s_ptr->comps[1].log10_lambda = - xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; - s_s_ptr->comps[1].phase->log10_lambda = - s_s_ptr->comps[1].log10_lambda; - - xc2 = xc * xc; - xc3 = xc2 * xc; - xb2 = xb * xb; - xb3 = xb2 * xb; - xb4 = xb3 * xb; - - /* used derivation that did not substitute x2 = 1-x1 */ - - /* first component, df1/dn1 */ - dnc = 2 * l_a0 * xb2 + 12 * l_a1 * xc * xb2 + 6 * l_a1 * xb2; - s_s_ptr->comps[0].phase->dnc = -xb / nc + dnc / n_tot; - - - /* first component, df1/dn2 */ - dnb = - 1 - 2 * l_a0 * xb + 2 * l_a0 * xb2 + 8 * l_a1 * xc * xb - - 12 * l_a1 * xc * xb2 - 2 * l_a1 * xb + 2 * l_a1 * xb2; - s_s_ptr->comps[0].phase->dnb = dnb / n_tot; - - /* second component, df2/dn1 */ - dnc = - 1 - 2 * l_a0 * xc + 2 * l_a0 * xc2 - 8 * l_a1 * xb * xc + - 12 * l_a1 * xb * xc2 + 2 * l_a1 * xc - 2 * l_a1 * xc2; - s_s_ptr->comps[1].phase->dnc = dnc / n_tot; - - /* second component, df2/dn2 */ - dnb = 2 * l_a0 * xc2 + 12 * l_a1 * xb * xc2 - 6 * l_a1 * xc2; - s_s_ptr->comps[1].phase->dnb = -xc / nb + dnb / n_tot; - - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_ideal(cxxSS *ss_ptr) @@ -3397,52 +2933,6 @@ ss_ideal(cxxSS *ss_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -s_s_ideal(struct s_s *s_s_ptr) -/* ---------------------------------------------------------------------- */ -{ - int k, j; - LDBLE n_tot, n_tot1; - -/* - * component 0 is major component - * component 1 is minor component - * xb is the mole fraction of second component (formerly trace) - * xc is the mole fraction of first component (formerly major) -*/ -/* - * Calculate mole fractions and log lambda and derivative factors - */ - n_tot = s_s_ptr->total_moles; - -/* - * Ideal solid solution - */ - s_s_ptr->dn = 1.0 / n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - n_tot1 = 0; - for (j = 0; j < s_s_ptr->count_comps; j++) - { - if (j != k) - { - n_tot1 += s_s_ptr->comps[j].moles; - } - } - s_s_ptr->comps[k].log10_lambda = 0; - s_s_ptr->comps[k].phase->log10_lambda = 0; - - s_s_ptr->comps[k].dnb = -(n_tot1) / (s_s_ptr->comps[k].moles * n_tot); - s_s_ptr->comps[k].phase->dnb = s_s_ptr->comps[k].dnb; - - s_s_ptr->comps[k].dn = s_s_ptr->dn; - s_s_ptr->comps[k].phase->dn = s_s_ptr->dn; - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: reset(void) @@ -3578,25 +3068,6 @@ reset(void) factor = f0; } } -#ifdef SKIP - else if (x[i]->s_s_comp != NULL && delta[i] < -x[i]->s_s_comp->phase->delta_max) - // Uses delta_max computed in step - // delta_max is the maximum amount of the mineral that could form based - // on the limiting element in the system - { - f0 = -delta[i] / x[i]->s_s_comp->phase->delta_max; - if (f0 > factor) - { - if (debug_model == TRUE) - { - output_msg(sformatf( - "%-10.10s, Precipitating too much mineral.\t%f\n", - x[i]->description, (double) f0)); - } - factor = f0; - } - } -#endif } } } diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index ef45d29d..d9d14314 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -290,41 +290,6 @@ quick_setup(void) } } } -#ifdef SKIP - if (ss_unknown != NULL) - { - for (i = 0; i < count_unknowns; i++) - { - if (x[i]->type == SS_MOLES) - break; - } - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - for (k = 0; k < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; k++) - { - x[i]->s_s = &(use.Get_ss_assemblage_ptr()->s_s[j]); - x[i]->s_s_comp = &(use.Get_ss_assemblage_ptr()->s_s[j].comps[k]); - x[i]->s_s_comp_number = j; - x[i]->moles = x[i]->s_s_comp->moles; - if (x[i]->moles <= 0) - { - x[i]->moles = MIN_TOTAL_SS; - x[i]->s_s_comp->moles = MIN_TOTAL_SS; - } - x[i]->s_s_comp->initial_moles = x[i]->moles; - x[i]->ln_moles = log(x[i]->moles); - - x[i]->phase->dn = x[i]->s_s_comp->dn; - x[i]->phase->dnb = x[i]->s_s_comp->dnb; - x[i]->phase->dnc = x[i]->s_s_comp->dnc; - x[i]->phase->log10_fraction_x = - x[i]->s_s_comp->log10_fraction_x; - x[i]->phase->log10_lambda = x[i]->s_s_comp->log10_lambda; - i++; - } - } - } -#endif /* * exchange */ @@ -913,221 +878,6 @@ build_ss_assemblage(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -build_ss_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Put coefficients into lists to sum iaps to test for equilibrium - * Put coefficients into lists to build jacobian for - * mass action equation for component - * mass balance equations for elements contained in solid solutions - */ - int i, j, k, l, stop; - int row, col; - struct master *master_ptr; - struct rxn_token *rxn_ptr; - struct s_s *s_s_ptr, *s_s_ptr_old; - char token[MAX_LENGTH]; - char *ptr; - - if (ss_unknown == NULL) - return (OK); - s_s_ptr_old = NULL; - col = 0; - for (i = 0; i < count_unknowns; i++) - { - if (x[i]->type != SS_MOLES) - continue; - s_s_ptr = x[i]->s_s; - if (s_s_ptr != s_s_ptr_old) - { - col = x[i]->number; - s_s_ptr_old = s_s_ptr; - } -/* - * Calculate function value (inverse saturation index) - */ - if (x[i]->phase->rxn_x == NULL) - continue; - store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) - { - store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); - } - /* include mole fraction */ - store_mb(&(x[i]->phase->log10_fraction_x), &(x[i]->f), 1.0); - - /* include activity coeficient */ - store_mb(&(x[i]->phase->log10_lambda), &(x[i]->f), 1.0); -/* - * Put coefficients into mass action equations - */ - /* first IAP terms */ - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) - { - if (rxn_ptr->s->secondary != NULL - && rxn_ptr->s->secondary->in == TRUE) - { - master_ptr = rxn_ptr->s->secondary; - } - else - { - master_ptr = rxn_ptr->s->primary; - } - if (master_ptr == NULL || master_ptr->unknown == NULL) - continue; - store_jacob0(x[i]->number, master_ptr->unknown->number, - rxn_ptr->coef); - } - - if (s_s_ptr->a0 != 0.0 || s_s_ptr->a1 != 0.0) - { -/* - * For binary solid solution - */ - /* next dnc terms */ - row = x[i]->number * (count_unknowns + 1); - if (x[i]->s_s_comp_number == 0) - { - col = x[i]->number; - } - else - { - col = x[i]->number - 1; - } - store_jacob(&(x[i]->phase->dnc), &(array[row + col]), -1); - - /* next dnb terms */ - col++; - store_jacob(&(x[i]->phase->dnb), &(array[row + col]), -1); - } - else - { -/* - * For ideal solid solution - */ - row = x[i]->number * (count_unknowns + 1); - for (j = 0; j < s_s_ptr->count_comps; j++) - { - if (j != x[i]->s_s_comp_number) - { -/* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ - store_jacob(&(x[i]->phase->dn), &(array[row + col + j]), - -1.0); - } - else - { - store_jacob(&(x[i]->phase->dnb), &(array[row + col + j]), - -1.0); - } - } - } -/* - * Put coefficients into mass balance equations - */ - count_elts = 0; - paren_count = 0; - strcpy(token, x[i]->phase->formula); - ptr = token; - get_elts_in_species(&ptr, 1.0); -/* - * Go through elements in phase - */ -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif - for (j = 0; j < count_elts; j++) - { - - if (strcmp(elt_list[j].elt->name, "H") == 0 - && mass_hydrogen_unknown != NULL) - { - store_jacob0(mass_hydrogen_unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, - elt_list[j].coef); - - } - else if (strcmp(elt_list[j].elt->name, "O") == 0 - && mass_oxygen_unknown != NULL) - { - store_jacob0(mass_oxygen_unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, - elt_list[j].coef); - - } - else - { - master_ptr = elt_list[j].elt->primary; - if (master_ptr->in == FALSE) - { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL || master_ptr->in == FALSE) - { - if (state != ADVECTION && state != TRANSPORT - && state != PHAST) - { - error_string = sformatf( - "Element in phase, %s, is not in model.", - x[i]->phase->name); - warning_msg(error_string); - } - if (master_ptr != NULL) - { - master_ptr->s->la = -999.9; - } -/* - * Master species is in model - */ - } - else if (master_ptr->in == TRUE) - { - store_jacob0(master_ptr->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &master_ptr->unknown->delta, - elt_list[j].coef); -/* - * Master species in equation needs to be rewritten - */ - } - else if (master_ptr->in == REWRITE) - { - stop = FALSE; - for (k = 0; k < count_unknowns; k++) - { - if (x[k]->type != MB) - continue; - for (l = 0; x[k]->master[l] != NULL; l++) - { - if (x[k]->master[l] == master_ptr) - { - store_jacob0(x[k]->master[0]->unknown-> - number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], - &x[k]->master[0]->unknown-> - delta, elt_list[j].coef); - stop = TRUE; - break; - } - } - if (stop == TRUE) - break; - } - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: build_jacobian_sums(int k) @@ -1863,185 +1613,6 @@ build_pure_phases(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -build_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Includes calculation of inverse saturation index in sum_mb. - * Puts coefficients in iap and mass balance equations for each phase. - */ - int i; - int stop, j, k, l; - char token[MAX_LENGTH]; - char *ptr; - struct master *master_ptr; - struct rxn_token *rxn_ptr; -/* - * Build into sums the logic to calculate inverse saturation indices for - * pure phases - */ - if (pure_phase_unknown == NULL) - return (OK); -/* - * Calculate inverse saturation index - */ - for (i = 0; i < count_unknowns; i++) - { - if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) - continue; - if (pure_phase_unknown == NULL) - pure_phase_unknown = x[i]; - - store_mb(&(x[i]->phase->lk), &(x[i]->f), 1.0); - store_mb(&(x[i]->si), &(x[i]->f), 1.0); - - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) - { - store_mb(&(rxn_ptr->s->la), &(x[i]->f), -rxn_ptr->coef); - } - } - for (i = 0; i < count_unknowns; i++) - { -/* - * rxn_x is null if an element in phase is not in solution - */ - if (x[i]->type != PP || x[i]->phase->rxn_x == NULL) - continue; -/* - * Put coefficients into IAP equations - */ - for (rxn_ptr = x[i]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) - { - if (rxn_ptr->s->secondary != NULL - && rxn_ptr->s->secondary->in == TRUE) - { - master_ptr = rxn_ptr->s->secondary; - } - else - { - master_ptr = rxn_ptr->s->primary; - } - if (master_ptr == NULL || master_ptr->unknown == NULL) - continue; - store_jacob0(x[i]->number, master_ptr->unknown->number, - rxn_ptr->coef); - } -/* - * Put coefficients into mass balance equations - */ - count_elts = 0; - paren_count = 0; - if (x[i]->pure_phase->add_formula != NULL) - { - strcpy(token, x[i]->pure_phase->add_formula); - ptr = token; - get_elts_in_species(&ptr, 1.0); - } - else - { - strcpy(token, x[i]->phase->formula); - ptr = token; - get_elts_in_species(&ptr, 1.0); - } -/* - * Go through elements in phase - */ - -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif - for (j = 0; j < count_elts; j++) - { - - if (strcmp(elt_list[j].elt->name, "H") == 0 - && mass_hydrogen_unknown != NULL) - { - store_jacob0(mass_hydrogen_unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_hydrogen_unknown->delta, - elt_list[j].coef); - - } - else if (strcmp(elt_list[j].elt->name, "O") == 0 - && mass_oxygen_unknown != NULL) - { - store_jacob0(mass_oxygen_unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&(delta[i]), &mass_oxygen_unknown->delta, - elt_list[j].coef); - - } - else - { - master_ptr = elt_list[j].elt->primary; - if (master_ptr->in == FALSE) - { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL || master_ptr->in == FALSE) - { - if (state != ADVECTION && state != TRANSPORT - && state != PHAST) - { - error_string = sformatf( - "Element in phase, %s, is not in model.", - x[i]->phase->name); - warning_msg(error_string); - } - if (master_ptr != NULL) - { - master_ptr->s->la = -999.9; - } -/* - * Master species is in model - */ - } - else if (master_ptr->in == TRUE) - { - store_jacob0(master_ptr->unknown->number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], &master_ptr->unknown->delta, - elt_list[j].coef); -/* - * Master species in equation needs to be rewritten - */ - } - else if (master_ptr->in == REWRITE) - { - stop = FALSE; - for (k = 0; k < count_unknowns; k++) - { - if (x[k]->type != MB) - continue; - for (l = 0; x[k]->master[l] != NULL; l++) - { - if (x[k]->master[l] == master_ptr) - { - store_jacob0(x[k]->master[0]->unknown-> - number, x[i]->number, - -elt_list[j].coef); - store_sum_deltas(&delta[i], - &x[k]->master[0]->unknown-> - delta, elt_list[j].coef); - stop = TRUE; - break; - } - } - if (stop == TRUE) - break; - } - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: build_solution_phase_boundaries(void) @@ -3787,65 +3358,6 @@ setup_ss_assemblage(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -setup_ss_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for solid solution unknowns (sum of partial pressures) - * in unknown structure - */ - int i, j; - if (use.Get_ss_assemblage_ptr() == NULL) - return (OK); -/* - * One for each component in each solid solution - */ - ss_unknown = NULL; - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - x[count_unknowns]->type = SS_MOLES; - x[count_unknowns]->description = - string_hsave(use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name); - x[count_unknowns]->moles = 0.0; - if (use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles <= 0) - { - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles = MIN_TOTAL_SS; - } - x[count_unknowns]->moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].initial_moles = - x[count_unknowns]->moles; - x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); - x[count_unknowns]->s_s = &(use.Get_ss_assemblage_ptr()->s_s[j]); - x[count_unknowns]->s_s_comp = - &(use.Get_ss_assemblage_ptr()->s_s[j].comps[i]); - x[count_unknowns]->s_s_comp_number = i; - x[count_unknowns]->phase = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].phase; - x[count_unknowns]->number = count_unknowns; - x[count_unknowns]->phase->dn = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dn; - x[count_unknowns]->phase->dnb = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dnb; - x[count_unknowns]->phase->dnc = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].dnc; - x[count_unknowns]->phase->log10_fraction_x = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_fraction_x; - x[count_unknowns]->phase->log10_lambda = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].log10_lambda; - if (ss_unknown == NULL) - ss_unknown = x[count_unknowns]; - count_unknowns++; - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: setup_surface(void) @@ -4613,51 +4125,6 @@ setup_pure_phases(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -setup_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ - int i; - struct phase *phase_ptr; - LDBLE si_org; -/* - * Fills in data for pure_phase assemglage in unknown structure - */ - - if (use.Get_pp_assemblage_ptr() == NULL) - return (OK); -/* - * Setup unknowns - */ - for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) - { - x[count_unknowns]->type = PP; - x[count_unknowns]->description = - use.Get_pp_assemblage_ptr()->pure_phases[i].name; - x[count_unknowns]->moles = - use.Get_pp_assemblage_ptr()->pure_phases[i].moles; - x[count_unknowns]->phase = phase_ptr = - use.Get_pp_assemblage_ptr()->pure_phases[i].phase; - x[count_unknowns]->si = use.Get_pp_assemblage_ptr()->pure_phases[i].si; - si_org = use.Get_pp_assemblage_ptr()->pure_phases[i].si_org; - /* si_org is used for Peng-Robinson gas, with the fugacity - coefficient added later in adjust_pure_phases, - when rxn_x has been defined for each phase in the model */ - x[count_unknowns]->delta = - use.Get_pp_assemblage_ptr()->pure_phases[i].delta; - x[count_unknowns]->pure_phase = - &(use.Get_pp_assemblage_ptr()->pure_phases[i]); - x[count_unknowns]->dissolve_only = - use.Get_pp_assemblage_ptr()->pure_phases[i].dissolve_only; - if (pure_phase_unknown == NULL) - pure_phase_unknown = x[count_unknowns]; - count_unknowns++; - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: adjust_setup_pure_phases(void) @@ -5239,17 +4706,6 @@ setup_unknowns(void) max_unknowns += ss_ptrs[i]->Get_ss_comps().size(); } } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - /* max_unknowns += 2 * use.Get_ss_assemblage_ptr()->count_s_s; */ - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - max_unknowns += use.Get_ss_assemblage_ptr()->s_s[i].count_comps; - } - } -#endif - /* * Pitzer/Sit */ @@ -6077,18 +5533,6 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ } } } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - if (fabs(tempk - use.Get_ss_assemblage_ptr()->s_s[i].tk) > 0.01) - { - s_s_prep(tempk, &(use.Get_ss_assemblage_ptr()->s_s[i]), FALSE); - } - } - } -#endif return (OK); } @@ -6211,27 +5655,6 @@ save_model(void) last_model.count_ss_assemblage = 0; last_model.ss_assemblage = NULL; } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - last_model.count_ss_assemblage = use.Get_ss_assemblage_ptr()->count_s_s; - last_model.ss_assemblage = - (const char **) PHRQ_malloc((size_t) use.Get_ss_assemblage_ptr()-> - count_s_s * sizeof(char *)); - if (last_model.ss_assemblage == NULL) - malloc_error(); - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - last_model.ss_assemblage[i] = - use.Get_ss_assemblage_ptr()->s_s[i].name; - } - } - else - { - last_model.count_ss_assemblage = 0; - last_model.ss_assemblage = NULL; - } -#endif /* * save list of phase pointers for pp_assemblage */ @@ -6278,43 +5701,6 @@ save_model(void) last_model.add_formula = NULL; last_model.si = NULL; } -#ifdef SKIP - if (use.Get_pp_assemblage_ptr() != NULL) - { - last_model.count_pp_assemblage = use.Get_pp_assemblage_ptr()->count_comps; - last_model.pp_assemblage = - (struct phase **) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> - count_comps * - sizeof(struct phase *)); - if (last_model.pp_assemblage == NULL) - malloc_error(); - last_model.add_formula = - (const char **) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> - count_comps * sizeof(char *)); - if (last_model.add_formula == NULL) - malloc_error(); - last_model.si = - (LDBLE *) PHRQ_malloc((size_t) use.Get_pp_assemblage_ptr()-> - count_comps * sizeof(LDBLE)); - if (last_model.si == NULL) - malloc_error(); - for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) - { - last_model.pp_assemblage[i] = - use.Get_pp_assemblage_ptr()->pure_phases[i].phase; - last_model.add_formula[i] = - use.Get_pp_assemblage_ptr()->pure_phases[i].add_formula; - last_model.si[i] = use.Get_pp_assemblage_ptr()->pure_phases[i].si; - } - } - else - { - last_model.count_pp_assemblage = 0; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - } -#endif /* * save data for surface */ @@ -6477,27 +5863,6 @@ check_same_model(void) if (last_model.ss_assemblage != NULL) return (FALSE); } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - if (last_model.count_ss_assemblage != - use.Get_ss_assemblage_ptr()->count_s_s) - return (FALSE); - for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - { - if (last_model.ss_assemblage[i] != - use.Get_ss_assemblage_ptr()->s_s[i].name) - { - return (FALSE); - } - } - } - else - { - if (last_model.ss_assemblage != NULL) - return (FALSE); - } -#endif /* * Check pure_phases */ @@ -6538,38 +5903,6 @@ check_same_model(void) if (last_model.pp_assemblage != NULL) return (FALSE); } -#ifdef SKIP - if (use.Get_pp_assemblage_ptr() != NULL) - { - if (last_model.count_pp_assemblage != - use.Get_pp_assemblage_ptr()->count_comps) - return (FALSE); - for (i = 0; i < use.Get_pp_assemblage_ptr()->count_comps; i++) - { - if (last_model.pp_assemblage[i] != - use.Get_pp_assemblage_ptr()->pure_phases[i].phase) - { - return (FALSE); - } - if (last_model.add_formula[i] != - use.Get_pp_assemblage_ptr()->pure_phases[i].add_formula) - { - return (FALSE); - } - /* A. Crapsi - if (last_model.si[i] != use.Get_pp_assemblage_ptr()->pure_phases[i].si) - { - return (FALSE); - } - */ - } - } - else - { - if (last_model.pp_assemblage != NULL) - return (FALSE); - } -#endif /* * Check surface */ diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 18ddd473..14eb6f90 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -765,133 +765,6 @@ print_ss_assemblage(void) output_msg(sformatf("\n")); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -print_ss_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - /* - * Prints solid solution composition if present - */ - int i, j; - LDBLE delta_moles; - LDBLE nb, nc, xb, xb1, xb2, xb1moles, xb2moles; - struct s_s *s_s_ptr; - - if (pr.ss_assemblage == FALSE || pr.all == FALSE) - return (OK); - if (use.Get_ss_assemblage_ptr() == NULL) - return (OK); - /* - * Print heading - */ - print_centered("Solid solutions"); - output_msg(sformatf("\n")); - output_msg(sformatf("%-15s %22s %11s %11s %11s\n\n", - "Solid solution", "Component", "Moles", "Delta moles", - "Mole fract")); - /* - * Print solid solutions - */ - std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); - for (j = 0; j < ss_ptrs.size(); j++) - { - cxxSS * ss_ptr = ss_ptrs[j]; - if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) - { - /* solid solution name, moles */ - output_msg(sformatf("%-15s %22s %11.2e\n", - use.Get_ss_assemblage_ptr()->s_s[j].name, " ", - (double) use.Get_ss_assemblage_ptr()->s_s[j].total_moles)); - /* component name, moles, delta moles, mole fraction */ - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - if (state != TRANSPORT && state != PHAST) - { - delta_moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. - initial_moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].delta; - } - else - { - delta_moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].init_moles; - } - output_msg(sformatf( - "%15s %22s %11.2e %11.2e %11.2e\n", " ", - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, - (double) use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. - moles, (double) delta_moles, - (double) (use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. - moles / - use.Get_ss_assemblage_ptr()->s_s[j]. - total_moles))); - } - s_s_ptr = &(use.Get_ss_assemblage_ptr()->s_s[j]); - if (s_s_ptr->miscibility == TRUE) - { - nc = s_s_ptr->comps[0].moles; - nb = s_s_ptr->comps[1].moles; - xb = nb / (nb + nc); - xb1 = s_s_ptr->xb1; - xb2 = s_s_ptr->xb2; - - if (xb > xb1 && xb < xb2) - { - xb2moles = (xb1 - 1) / xb1 * nb + nc; - xb2moles = xb2moles / ((xb1 - 1) / xb1 * xb2 + (1 - xb2)); - xb1moles = (nb - xb2moles * xb2) / xb1; - output_msg(sformatf( - "\n%14s Solid solution is in miscibility gap\n", - " ")); - output_msg(sformatf( - "%14s End members in pct of %s\n\n", " ", - s_s_ptr->comps[1].name)); - output_msg(sformatf("%22s %11g pct %11.2e\n", - " ", (double) xb1, (double) xb1moles)); - output_msg(sformatf("%22s %11g pct %11.2e\n", - " ", (double) xb2, (double) xb2moles)); - } - } - } - else - { - /* solid solution name, moles */ - output_msg(sformatf("%-15s %22s %11.2e\n", - use.Get_ss_assemblage_ptr()->s_s[j].name, " ", - (double) 0.0)); - /* component name, moles, delta moles, mole fraction */ - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; i++) - { - if (state != TRANSPORT && state != PHAST) - { - delta_moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i]. - initial_moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].delta; - } - else - { - delta_moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles - - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].init_moles; - } - output_msg(sformatf( - "%15s %22s %11.2e %11.2e %11.2e\n", " ", - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name, - (double) 0, (double) delta_moles, (double) 0)); - } - } - } - output_msg(sformatf("\n")); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_reaction(void) @@ -2476,17 +2349,6 @@ print_using(void) use.Get_n_ss_assemblage_user(), ss_assemblage_ptr->Get_description().c_str())); } -#ifdef SKIP - if (use.Get_ss_assemblage_in() == TRUE) - { - ss_assemblage_ptr = - ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); - output_msg(sformatf( - "Using solid solution assemblage %d.\t%s\n", - use.Get_n_ss_assemblage_user(), - ss_assemblage_ptr->description)); - } -#endif if (use.Get_gas_phase_in() == TRUE) { //gas_phase_ptr = gas_phase_bsearch(use.Get_n_gas_phase_user(), &n); @@ -2679,62 +2541,6 @@ punch_ss_assemblage(void) } } } -#ifdef SKIP - for (k = 0; k < punch.count_s_s; k++) - { - found = FALSE; - if (use.Get_ss_assemblage_ptr() != NULL) - { - for (j = 0; j < use.Get_ss_assemblage_ptr()->count_s_s; j++) - { - for (i = 0; i < use.Get_ss_assemblage_ptr()->s_s[j].count_comps; - i++) - { - if (strcmp_nocase - (punch.s_s[k].name, - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].name) == 0) - { - if (use.Get_ss_assemblage_ptr()->s_s[j].ss_in == TRUE) - { - moles = - use.Get_ss_assemblage_ptr()->s_s[j].comps[i].moles; - } - else - { - moles = 0; - } - if (punch.high_precision == FALSE) - { - fpunchf(sformatf("s_%s", punch.s_s[k].name), - "%12.4e\t", (double) moles); - } - else - { - fpunchf(sformatf("s_%s", punch.s_s[k].name), - "%20.12e\t", (double) moles); - } - found = TRUE; - break; - } - } - if (found == TRUE) - break; - } - } - if (found == FALSE) - { - if (punch.high_precision == FALSE) - { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", (double) 0.0); - } - else - { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", - (double) 0.0); - } - } - } -#endif return (OK); } diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 404293e8..d09d9968 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -262,37 +262,30 @@ read_input(void) read_solution_raw(); break; case Keywords::KEY_EXCHANGE_RAW: - //read_exchange_raw(); Utilities::Rxn_read_raw(Rxn_exchange_map, this); break; case Keywords::KEY_SURFACE_RAW: read_surface_raw(); break; case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: - //read_equilibrium_phases_raw(); Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, this); break; case Keywords::KEY_KINETICS_RAW: read_kinetics_raw(); break; case Keywords::KEY_SOLID_SOLUTIONS_RAW: - //read_solid_solutions_raw(); Utilities::Rxn_read_raw(Rxn_ss_assemblage_map, this); break; case Keywords::KEY_GAS_PHASE_RAW: - //read_gas_phase_raw(); Utilities::Rxn_read_raw(Rxn_gas_phase_map, this); break; case Keywords::KEY_REACTION_RAW: - //read_reaction_raw(); Utilities::Rxn_read_raw(Rxn_reaction_map, this); break; case Keywords::KEY_MIX_RAW: - //read_mix_raw(); Utilities::Rxn_read_raw(Rxn_mix_map, this); break; case Keywords::KEY_REACTION_TEMPERATURE_RAW: - //read_temperature_raw(); Utilities::Rxn_read_raw(Rxn_temperature_map, this); break; case Keywords::KEY_DUMP: @@ -302,11 +295,9 @@ read_input(void) read_solution_modify(); break; case Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY: - //read_equilibrium_phases_modify(); Utilities::Rxn_read_modify(Rxn_pp_assemblage_map, this); break; case Keywords::KEY_EXCHANGE_MODIFY: - //read_exchange_modify(); Utilities::Rxn_read_modify(Rxn_exchange_map, this); break; case Keywords::KEY_SURFACE_MODIFY: @@ -316,7 +307,6 @@ read_input(void) Utilities::Rxn_read_modify(Rxn_ss_assemblage_map, this); break; case Keywords::KEY_GAS_PHASE_MODIFY: - //read_gas_phase_modify(); Utilities::Rxn_read_modify(Rxn_gas_phase_map, this); break; case Keywords::KEY_KINETICS_MODIFY: @@ -329,7 +319,6 @@ read_input(void) read_run_cells(); break; case Keywords::KEY_REACTION_MODIFY: - //read_reaction_modify(); Utilities::Rxn_read_modify(Rxn_reaction_map, this); break; //case LAST_C_KEYWORD + 22: //reaction_temperature_modify @@ -340,14 +329,8 @@ read_input(void) read_reaction_pressure(); break; case Keywords::KEY_REACTION_PRESSURE_RAW: - //read_reaction_pressure_raw(); Utilities::Rxn_read_raw(Rxn_pressure_map, this); break; -#ifdef SKIP - //case Keywords::KEY_REACTION_PRESSURE_MODIFY: - // read_reaction_pressure_modify(); - // break; -#endif default: error_msg("Error in keyword switch", STOP); break; @@ -4122,228 +4105,6 @@ read_pp_assemblage(void) return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_pure_phases(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads pure phase data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int j, n, l, return_value; - int count_pure_phases; - int n_user, n_user_end; - char *ptr; - char *description; - char token[MAX_LENGTH]; - int opt, opt_save; - char *next_char; - const char *opt_list[] = { - "force_equality" /* 0 */ - }; - int count_opt_list = 1; - - ptr = line; - /* - * Read pp_assemblage number - */ - read_number_description(ptr, &n_user, &n_user_end, &description); - /* - * Find pp_assemblage or realloc space for pp_assemblage - */ - - if (pp_assemblage_search(n_user, &n) != NULL) - { - pp_assemblage_free(&pp_assemblage[n]); - } - else - { - n = count_pp_assemblage++; - space((void **) ((void *) &pp_assemblage), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - } - /* - * Set use data to first read - */ - if (use.Get_pp_assemblage_in() == FALSE) - { - use.Get_pp_assemblage_in() = TRUE; - use.Get_n_pp_assemblage_user() = n_user; - } - - pp_assemblage_init(&(pp_assemblage[n]), n_user, n_user_end, description); - free_check_null(description); - count_pure_phases = 0; - /* - * Read equilibrium phase data - */ - opt_save = OPTION_DEFAULT; - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) - { - opt = opt_save; - } - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in EQUILIBRIUM_PHASES keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* force_equality */ - if (count_pure_phases == 0) - { - error_msg - ("Force_equality defined before equilibrium phase has been defined.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - else - { - pp_assemblage[n].pure_phases[count_pure_phases - - 1].force_equality = - get_true_false(next_char, TRUE); - } - break; - case OPTION_DEFAULT: - /* - * Make space, set default - */ - count_pure_phases++; - pp_assemblage[n].pure_phases = - (struct pure_phase *) PHRQ_realloc(pp_assemblage[n]. - pure_phases, - (size_t) - (count_pure_phases) * - sizeof(struct pure_phase)); - if (pp_assemblage[n].pure_phases == NULL) - malloc_error(); - pp_assemblage[n].pure_phases[count_pure_phases - 1].si = 0.0; - pp_assemblage[n].pure_phases[count_pure_phases - 1].si_org = 0.0; - pp_assemblage[n].pure_phases[count_pure_phases - 1].add_formula = - NULL; - pp_assemblage[n].pure_phases[count_pure_phases - 1].moles = 10.0; - pp_assemblage[n].pure_phases[count_pure_phases - 1].delta = 0.0; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].initial_moles = 0.0; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].force_equality = FALSE; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].dissolve_only = FALSE; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].precipitate_only = FALSE; - /* - * Read name - */ - ptr = line; - copy_token(token, &ptr, &l); - pp_assemblage[n].pure_phases[count_pure_phases - 1].name = - string_hsave(token); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - continue; - /* - * Read saturation index - */ - j = sscanf(token, SCANFORMAT, &dummy); - pp_assemblage[n].pure_phases[count_pure_phases - 1].si = - (LDBLE) dummy; - pp_assemblage[n].pure_phases[count_pure_phases - 1].si_org = - (LDBLE) dummy; - if (j != 1) - { - error_msg("Expected saturation index.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - continue; - } - /* - * Adding a reaction to the phase boundary - */ - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - continue; - if (j == UPPER || j == LOWER) - { - pp_assemblage[n].pure_phases[count_pure_phases - - 1].add_formula = - string_hsave(token); - j = copy_token(token, &ptr, &l); - } - /* - * Read amount - */ - if (j == EMPTY) - continue; - j = sscanf(token, SCANFORMAT, &dummy); - pp_assemblage[n].pure_phases[count_pure_phases - 1].moles = - (LDBLE) dummy; - if (j != 1) - { - error_msg("Expected amount of mineral.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - continue; - } - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - continue; - str_tolower(token); - if (strstr(token, "d") == token) - { - pp_assemblage[n].pure_phases[count_pure_phases - - 1].dissolve_only = TRUE; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].precipitate_only = FALSE; - } else if (strstr(token, "p") == token) - { - pp_assemblage[n].pure_phases[count_pure_phases - - 1].precipitate_only = TRUE; - pp_assemblage[n].pure_phases[count_pure_phases - - 1].dissolve_only = FALSE; - } - else - { - error_msg - ("Unexpected data at end of equilibrium-phase definition.", - CONTINUE); - input_error++; - continue; - } - break; - } - if (return_value == EOF || return_value == KEYWORD) - break; - } - pp_assemblage[n].count_comps = count_pure_phases; - /* - * Sort phases by name (lowercase) - */ - qsort(pp_assemblage[n].pure_phases, - (size_t) count_pure_phases, - (size_t) sizeof(struct pure_phase), pure_phase_compare); - - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_reaction(void) @@ -9772,566 +9533,6 @@ read_solid_solutions(void) return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solid_solutions(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solid solution data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int count_s_s, number_s_s, count_comps; - int n_user, n_user_end; - char *ptr; - char *description; - char token[MAX_LENGTH]; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "component", /* 0 */ - "comp", /* 1 */ - "parms", /* 2 */ - "gugg_nondimensional", /* 3 */ - "gugg_kj", /* 4 */ - "activity_coefficients", /* 5 */ - "distribution_coefficients", /* 6 */ - "miscibility_gap", /* 7 */ - "spinodal_gap", /* 8 */ - "critical_point", /* 9 */ - "alyotropic_point", /* 10 */ - "temp", /* 11 */ - "tempk", /* 12 */ - "tempc", /* 13 */ - "thompson", /* 14 */ - "margules", /* 15 */ - "comp1", /* 16 */ - "comp2" /* 17 */ - }; - int count_opt_list = 18; -/* - * Read ss_assemblage number - */ - number_s_s = 0; - ptr = line; - read_number_description(ptr, &n_user, &n_user_end, &description); -/* - * Find old ss_assemblage or alloc space for new ss_assemblage - */ - if (ss_assemblage_search(n_user, &n) != NULL) - { - ss_assemblage_free(&ss_assemblage[n]); - } - else - { - n = count_ss_assemblage; - space((void **) ((void *) &ss_assemblage), count_ss_assemblage, - &max_ss_assemblage, sizeof(struct ss_assemblage)); - count_ss_assemblage++; - } -/* - * Initialize - */ - ss_assemblage_init(&(ss_assemblage[n]), n_user, n_user_end, - description); - free_check_null(description); -/* - * Set use data to first read - */ - if (!use.Get_ss_assemblage_in()) - { - use.Set_ss_assemblage_in(true); - use.Set_n_ss_assemblage_user(n_user); - } -/* - * Read solid solutions - */ - count_s_s = 0; - count_comps = 0; - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLID_SOLUTIONS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - -/* - * New component - */ - case 0: /* component */ - case 1: /* comp */ - count_comps = ss_assemblage[n].s_s[number_s_s].count_comps++; - ss_assemblage[n].s_s[number_s_s].comps = - (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. - s_s[number_s_s].comps, - (size_t) (count_comps + - 1) * - sizeof(struct s_s_comp)); - if (ss_assemblage[n].s_s[number_s_s].comps == NULL) - malloc_error(); - ss_assemblage[n].s_s[number_s_s].comps[count_comps].initial_moles = 0; - ss_assemblage[n].s_s[number_s_s].comps[count_comps].delta = 0; - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - ss_assemblage[n].s_s[number_s_s].comps[count_comps].name = - string_hsave(token); - /* - * Read moles of component - */ - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - { - ss_assemblage[n].s_s[number_s_s].comps[count_comps].moles = - NAN; - } - else - { - j = sscanf(token, SCANFORMAT, &dummy); - ss_assemblage[n].s_s[number_s_s].comps[count_comps].moles = - (LDBLE) dummy; - if (j != 1) - { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; - case 2: /* parms */ - case 3: /* gugg_nondimensional */ - /* - * Read parameters - */ - - ptr = next_char; - if (copy_token(token, &ptr, &l) != EMPTY) - { - sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[0])); - } - if (copy_token(token, &ptr, &l) != EMPTY) - { - sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[1])); - } - ss_assemblage[n].s_s[number_s_s].input_case = 0; - break; - case 4: /* gugg_kj */ - ptr = next_char; - if (copy_token(token, &ptr, &l) != EMPTY) - { - sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[0])); - } - if (copy_token(token, &ptr, &l) != EMPTY) - { - sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[1])); - } - ss_assemblage[n].s_s[number_s_s].input_case = 7; - break; - case 5: /* activity coefficients */ - ptr = next_char; - j = 0; - for (i = 0; i < 4; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 4) - { - error_string = sformatf( - "Expected 4 parameters to calculate a0 and a1 from two activity coefficients, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 1; - break; - case 6: /* distribution coefficients */ - ptr = next_char; - j = 0; - for (i = 0; i < 4; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 4) - { - error_string = sformatf( - "Expected 4 parameters to calculate a0 and a1 from two distribution coefficients, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 2; - break; - case 7: /* miscibility_gap */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected 2 miscibility gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 3; - break; - case 8: /* spinodal_gap */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected 2 spinodal gap fractions of component 2 to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 4; - break; - case 9: /* critical point */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected fraction of component 2 and critical temperature to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 5; - break; - case 10: /* alyotropic point */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected fraction of component 2 and sigma pi at alyotropic point to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 6; - break; - case 12: /* tempk */ - ptr = next_char; - j = 0; - if (copy_token(token, &ptr, &l) != EMPTY) - { - j = sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].tk)); - } - if (j != 1) - { - error_string = sformatf( - "Expected temperature (Kelvin) for parameters, assemblage %d, solid solution %s, using 298.15 K", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - warning_msg(error_string); - ss_assemblage[n].s_s[number_s_s].tk = 298.15; - } - break; - case 11: /* temp */ - case 13: /* tempc */ - ptr = next_char; - j = 0; - if (copy_token(token, &ptr, &l) != EMPTY) - { - j = sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].tk)); - } - if (j != 1) - { - error_string = sformatf( - "Expected temperature (Celcius) for parameters, assemblage %d, solid solution %s, using 25 C", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - warning_msg(error_string); - ss_assemblage[n].s_s[number_s_s].tk = 25.; - } - ss_assemblage[n].s_s[number_s_s].tk += 273.15; - break; - case 14: /* Thompson and Waldbaum */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected Wg2 and Wg1 Thompson-Waldbaum parameters to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 8; - break; - case 15: /* Margules */ - ptr = next_char; - j = 0; - for (i = 0; i < 2; i++) - { - if (copy_token(token, &ptr, &l) != EMPTY) - { - j += sscanf(token, SCANFORMAT, - &(ss_assemblage[n].s_s[number_s_s].p[i])); - } - } - if (j != 2) - { - error_string = sformatf( - "Expected alpha2 and alpha3 Margules parameters to calculate a0 and a1, assemblage %d, solid solution %s", - ss_assemblage[n].n_user, - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - ss_assemblage[n].s_s[number_s_s].input_case = 9; - break; - case 16: /* comp1 */ - if (count_comps < 2) - { - ss_assemblage[n].s_s[number_s_s].count_comps = 2; - count_comps = 2; - ss_assemblage[n].s_s[number_s_s].comps = - (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. - s_s[number_s_s].comps, - (size_t) (count_comps) * - sizeof(struct s_s_comp)); - if (ss_assemblage[n].s_s[number_s_s].comps == NULL) - malloc_error(); - } - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - ss_assemblage[n].s_s[number_s_s].comps[0].name = - string_hsave(token); - /* - * Read moles of component - */ - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - { - ss_assemblage[n].s_s[number_s_s].comps[0].moles = NAN; - } - else - { - j = sscanf(token, SCANFORMAT, &dummy); - ss_assemblage[n].s_s[number_s_s].comps[0].moles = - (LDBLE) dummy; - if (j != 1) - { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; - case 17: /* comp2 */ - if (count_comps < 2) - { - ss_assemblage[n].s_s[number_s_s].count_comps = 2; - count_comps = 2; - ss_assemblage[n].s_s[number_s_s].comps = - (struct s_s_comp *) PHRQ_realloc(ss_assemblage[n]. - s_s[number_s_s].comps, - (size_t) (count_comps) * - sizeof(struct s_s_comp)); - if (ss_assemblage[n].s_s[number_s_s].comps == NULL) - malloc_error(); - } - /* - * Read phase name of component - */ - ptr = next_char; - copy_token(token, &ptr, &l); - ss_assemblage[n].s_s[number_s_s].comps[1].name = - string_hsave(token); - /* - * Read moles of component - */ - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - { - ss_assemblage[n].s_s[number_s_s].comps[1].moles = NAN; - } - else - { - j = sscanf(token, SCANFORMAT, &dummy); - ss_assemblage[n].s_s[number_s_s].comps[1].moles = - (LDBLE) dummy; - if (j != 1) - { - error_msg("Expected moles of solid solution.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - break; -/* - * New solid solution - */ - case OPTION_DEFAULT: - number_s_s = count_s_s++; - /* - * Make space, set default - */ - - /* realloc space for one s_s */ - ss_assemblage[n].s_s = - (struct s_s *) PHRQ_realloc(ss_assemblage[n].s_s, - (size_t) (count_s_s + - 1) * - sizeof(struct s_s)); - if (ss_assemblage[n].s_s == NULL) - malloc_error(); - - /* malloc space for one component */ - ss_assemblage[n].s_s[number_s_s].comps = - (struct s_s_comp *) PHRQ_malloc((size_t) - sizeof(struct s_s_comp)); - if (ss_assemblage[n].s_s[number_s_s].comps == NULL) - malloc_error(); - count_comps = 0; - ss_assemblage[n].s_s[number_s_s].count_comps = 0; - ss_assemblage[n].s_s[number_s_s].total_moles = 0; - ss_assemblage[n].s_s[number_s_s].dn = 0; - ss_assemblage[n].s_s[number_s_s].a0 = 0.0; - ss_assemblage[n].s_s[number_s_s].a1 = 0.0; - ss_assemblage[n].s_s[number_s_s].ag0 = 0.0; - ss_assemblage[n].s_s[number_s_s].ag1 = 0.0; - ss_assemblage[n].s_s[number_s_s].ss_in = FALSE; - ss_assemblage[n].s_s[number_s_s].miscibility = FALSE; - ss_assemblage[n].s_s[number_s_s].spinodal = FALSE; - ss_assemblage[n].s_s[number_s_s].tk = 298.15; - ss_assemblage[n].s_s[number_s_s].xb1 = 0; - ss_assemblage[n].s_s[number_s_s].xb2 = 0; - ss_assemblage[n].s_s[number_s_s].input_case = 0; - ss_assemblage[n].s_s[number_s_s].p[0] = 0.0; - ss_assemblage[n].s_s[number_s_s].p[1] = 0.0; - ss_assemblage[n].s_s[number_s_s].p[2] = 0.0; - ss_assemblage[n].s_s[number_s_s].p[3] = 0.0; - - ss_assemblage[n].s_s[number_s_s].comps->name = NULL; - ss_assemblage[n].s_s[number_s_s].comps->phase = NULL; - /* - * Read solid solution name - */ - ptr = line; - copy_token(token, &ptr, &l); - ss_assemblage[n].s_s[number_s_s].name = string_hsave(token); - ss_assemblage[n].s_s[number_s_s].total_moles = NAN; - break; - } - if (return_value == EOF || return_value == KEYWORD) - break; - } - for (i = 0; i < ss_assemblage[n].count_s_s; i++) - { - if (ss_assemblage[n].s_s[i].p[0] != 0.0 || - ss_assemblage[n].s_s[i].p[1] != 0.0) - { - if (ss_assemblage[n].s_s[number_s_s].count_comps != 2) - { - error_string = sformatf( - "Solid solution, %s, is nonideal. Must define exactly two components (-comp1 and -comp2).", - ss_assemblage[n].s_s[number_s_s].name); - error_msg(error_string, CONTINUE); - input_error++; - } - } - } -/* - * Sort components by name (lowercase) - */ - - ss_assemblage[n].count_s_s = count_s_s; - qsort(ss_assemblage[n].s_s, - (size_t) count_s_s, (size_t) sizeof(struct s_s), s_s_compare); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_llnl_aqueous_model_parameters(void) diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index fe36c7b5..0833eea0 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -133,19 +133,6 @@ step(LDBLE step_fraction) pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); add_pp_assemblage(pp_assemblage_ptr); } -#ifdef SKIP - if (use.Get_pp_assemblage_ptr() != NULL) - { - pp_assemblage_save = - (struct pp_assemblage *) - PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_save == NULL) - malloc_error(); - pp_assemblage_copy(use.Get_pp_assemblage_ptr(), pp_assemblage_save, - use.Get_pp_assemblage_ptr()->n_user); - add_pp_assemblage(use.Get_pp_assemblage_ptr()); - } -#endif /* * Solid solutions */ @@ -154,19 +141,6 @@ step(LDBLE step_fraction) ss_assemblage_save = new cxxSSassemblage(*use.Get_ss_assemblage_ptr()); add_ss_assemblage(use.Get_ss_assemblage_ptr()); } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - ss_assemblage_save = - (struct ss_assemblage *) - PHRQ_malloc(sizeof(struct ss_assemblage)); - if (ss_assemblage_save == NULL) - malloc_error(); - ss_assemblage_copy(use.Get_ss_assemblage_ptr(), ss_assemblage_save, - use.Get_ss_assemblage_ptr()->n_user); - add_ss_assemblage(use.Get_ss_assemblage_ptr()); - } -#endif /* * Check that elements are available for gas components, * pure phases, and solid solutions @@ -201,18 +175,6 @@ step(LDBLE step_fraction) Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } -#ifdef SKIP - if (use.Get_ss_assemblage_ptr() != NULL) - { - ss_assemblage_free(use.Get_ss_assemblage_ptr()); - ss_assemblage_copy(ss_assemblage_save, use.Get_ss_assemblage_ptr(), - use.Get_ss_assemblage_ptr()->n_user); - ss_assemblage_free(ss_assemblage_save); - ss_assemblage_save = - (struct ss_assemblage *) - free_check_null(ss_assemblage_save); - } -#endif return (MASS_BALANCE); } /* @@ -822,132 +784,6 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add a small amount of each phase if necessary to insure - * all elements exist in solution. - */ - int i, j; - LDBLE amount_to_add, total; - char token[MAX_LENGTH]; - char *ptr; - struct pure_phase *pure_phase_ptr; - struct master *master_ptr; - //struct phase *phase_ptr; - //LDBLE p, t; - - pure_phase_ptr = pp_assemblage_ptr->pure_phases; - - // Should be be done when it gets to prep (modified quick_setup in case same_model). - //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - //{ - // phase_ptr = pure_phase_ptr[j].phase; - // if (/*pure_phase_ptr[j].si_org > 0 && */phase_ptr->p_c > 0 && phase_ptr->t_c > 0) - // { - // p = exp(pure_phase_ptr[j].si_org * LOG_10); - // t = tc_x + 273.15; - // if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) - // { - // calc_PR(&phase_ptr, 1, p, t, 0); - // } - // pure_phase_ptr[j].si = pure_phase_ptr[j].si_org + phase_ptr->pr_si_f; - // } - //} - - if (check_pp_assemblage(pp_assemblage_ptr) == OK) - return (OK); -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - count_elts = 0; - paren_count = 0; -/* - * Check that all elements are in solution for phases with greater than zero mass - */ - pure_phase_ptr = pp_assemblage_ptr->pure_phases; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - { - if (pure_phase_ptr[j].precipitate_only) continue; - count_elts = 0; - paren_count = 0; - amount_to_add = 0.0; - pure_phase_ptr[j].delta = 0.0; - if (pure_phase_ptr[j].add_formula != NULL) - { - strcpy(token, pure_phase_ptr[j].add_formula); - ptr = &(token[0]); - get_elts_in_species(&ptr, 1.0); - } - else - { - strcpy(token, pure_phase_ptr[j].phase->formula); - add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); - } - if (pure_phase_ptr[j].moles > 0.0) - { - for (i = 0; i < count_elts; i++) - { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) - { - continue; - } - else if (master_ptr->s == s_h2o) - { - continue; - } - else if (master_ptr->total > MIN_TOTAL) - { - continue; - } - else - { - total = (-master_ptr->total + 1e-10) / elt_list[i].coef; - if (amount_to_add < total) - { - amount_to_add = total; - } - } - } - if (pure_phase_ptr[j].moles < amount_to_add) - { - amount_to_add = pure_phase_ptr[j].moles; - } - } - if (amount_to_add > 0.0) - { - pure_phase_ptr[j].moles -= amount_to_add; - pure_phase_ptr[j].delta = amount_to_add; -/* - * Add reaction to totals - */ - for (i = 0; i < count_elts; i++) - { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) - { - total_h_x += elt_list[i].coef * amount_to_add; - } - else if (master_ptr->s == s_h2o) - { - total_o_x += elt_list[i].coef * amount_to_add; - } - else - { - master_ptr->total += elt_list[i].coef * amount_to_add; - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) @@ -979,31 +815,6 @@ check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) } return (TRUE); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check list of all elements in pure_phase assemblage to see - * if all are in model. Return true if all are present, - * Return false if one or more is missing. - */ - int j; - struct master *master_ptr; - for (j = 0; pp_assemblage_ptr->next_elt[j].elt != NULL; j++) - { - master_ptr = pp_assemblage_ptr->next_elt[j].elt->primary; - if (master_ptr->s == s_h2o || master_ptr->s == s_hplus) - continue; - if (master_ptr->total > MIN_TOTAL) - continue; - return (FALSE); - } - return (TRUE); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) @@ -1375,102 +1186,6 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Accumulate solid_solution data in master->totals and _x variables. - */ - int i, j, k; - LDBLE amount_to_add, total; - struct s_s *s_s_ptr; - struct master *master_ptr; - char token[MAX_LENGTH]; - char *ptr; - - if (ss_assemblage_ptr == NULL) - return (OK); - count_elts = 0; - paren_count = 0; -/* - * Check that all elements are in solution for phases with greater than zero mass - */ - for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) - { - count_elts = 0; - paren_count = 0; - s_s_ptr = &(ss_assemblage_ptr->s_s[i]); - for (j = 0; j < s_s_ptr->count_comps; j++) - { - amount_to_add = 0.0; - s_s_ptr->comps[j].delta = 0.0; - if (s_s_ptr->comps[j].moles > 0.0) - { - strcpy(token, s_s_ptr->comps[j].phase->formula); - ptr = &(token[0]); - get_elts_in_species(&ptr, 1.0); - for (k = 0; k < count_elts; k++) - { - master_ptr = elt_list[k].elt->primary; - if (master_ptr->s == s_hplus) - { - continue; - } - else if (master_ptr->s == s_h2o) - { - continue; - } - else if (master_ptr->total > MIN_TOTAL_SS) - { - continue; - } - else - { - total = - (-master_ptr->total + 1e-10) / elt_list[k].coef; - if (amount_to_add < total) - { - amount_to_add = total; - } - } - } - } - if (s_s_ptr->comps[j].moles < amount_to_add) - { - amount_to_add = s_s_ptr->comps[j].moles; - } - if (amount_to_add > 0.0) - { - s_s_ptr->comps[j].moles -= amount_to_add; - s_s_ptr->comps[j].delta = amount_to_add; -/* - * Add reaction to totals - */ - for (k = 0; k < count_elts; k++) - { - master_ptr = elt_list[k].elt->primary; - if (master_ptr->s == s_hplus) - { - total_h_x += elt_list[k].coef * amount_to_add; - } - else if (master_ptr->s == s_h2o) - { - total_o_x += elt_list[k].coef * amount_to_add; - } - else - { - master_ptr->total += elt_list[k].coef * amount_to_add; - } - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: add_kinetics(struct kinetics *kinetics_ptr) @@ -1662,91 +1377,6 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i, j, k; - char token[MAX_LENGTH]; - char *ptr; - struct pure_phase *pure_phase_ptr; - struct master *master_ptr; - - if (check_pp_assemblage(pp_assemblage_ptr) == OK) - return (OK); -/* - * Check that all elements are in solution for phases with zero mass - */ - pure_phase_ptr = pp_assemblage_ptr->pure_phases; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - { - count_elts = 0; - paren_count = 0; - if (pure_phase_ptr[j].moles <= 0.0) - { - pure_phase_ptr[j].delta = 0.0; - if (pure_phase_ptr[j].add_formula != NULL) - { - strcpy(token, pure_phase_ptr[j].add_formula); - ptr = &(token[0]); - get_elts_in_species(&ptr, 1.0); - } - else - { - strcpy(token, pure_phase_ptr[j].phase->formula); - add_elt_list(pure_phase_ptr[j].phase->next_elt, 1.0); - } - for (i = 0; i < count_elts; i++) - { - master_ptr = elt_list[i].elt->primary; - if (master_ptr->s == s_hplus) - { - continue; - } - else if (master_ptr->s == s_h2o) - { - continue; - } - else if (master_ptr->total > MIN_TOTAL) - { - continue; - } - else - { - if (state != ADVECTION && state != TRANSPORT - && state != PHAST) - { - error_string = sformatf( - "Element %s is contained in %s (which has 0.0 mass)," - "\t\nbut is not in solution or other phases.", - elt_list[i].elt->name, - pure_phase_ptr[j].phase->name); - warning_msg(error_string); - } -/* - * Make la's of all master species for the element small, so SI will be small - * and no mass transfer will be calculated - */ - for (k = 0; k < count_master; k++) - { - if (master[k]->elt->primary == master_ptr) - { - master[k]->s->la = -9999.999; - } - } - } - } - } - } - return (OK); -} -#endif - /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr) @@ -1822,80 +1452,6 @@ ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_check(struct ss_assemblage *ss_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Check for missing elements - */ - int i, j, k, l; - struct master *master_ptr; - - if (ss_assemblage_ptr == NULL) - return (OK); -/* - * Check that all elements are in solution for phases with zero mass - */ - for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) - { - for (j = 0; j < ss_assemblage_ptr->s_s[i].count_comps; j++) - { - count_elts = 0; - paren_count = 0; - if (ss_assemblage_ptr->s_s[i].comps[j].moles <= 0.0) - { - add_elt_list(ss_assemblage_ptr->s_s[i].comps[j].phase-> - next_elt, 1.0); - for (l = 0; l < count_elts; l++) - { - master_ptr = elt_list[l].elt->primary; - if (master_ptr->s == s_hplus) - { - continue; - } - else if (master_ptr->s == s_h2o) - { - continue; - } - else if (master_ptr->total > MIN_TOTAL_SS) - { - continue; - } - else - { - if (state != ADVECTION && state != TRANSPORT - && state != PHAST) - { - error_string = sformatf( - "Element %s is contained in solid solution %s (which has 0.0 mass),\nbut is not in solution or other phases.", - elt_list[l].elt->name, - ss_assemblage_ptr->s_s[i].comps[j]. - phase->name); - warning_msg(error_string); - } - } - /* - * Make la's of all master species for the element small, - * so SI will be small - * and no mass transfer will be calculated - */ - for (k = 0; k < count_master; k++) - { - if (master[k]->elt->primary == master_ptr) - { - master[k]->s->la = -9999.999; - } - } - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: solution_check(void) diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index eb939ab6..6a638fab 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -96,24 +96,10 @@ clean_up(void) /* pp assemblages */ Rxn_pp_assemblage_map.clear(); -#ifdef SKIP - for (j = 0; j < count_pp_assemblage; j++) - { - pp_assemblage_free(&pp_assemblage[j]); - } - pp_assemblage = (struct pp_assemblage *) free_check_null(pp_assemblage); -#endif /* s_s assemblages */ Rxn_ss_assemblage_map.clear(); -#ifdef SKIP - for (j = 0; j < count_ss_assemblage; j++) - { - ss_assemblage_free(&ss_assemblage[j]); - } - ss_assemblage = - (struct ss_assemblage *) free_check_null(ss_assemblage); -#endif + /* irreversible reactions */ Rxn_reaction_map.clear(); @@ -430,22 +416,10 @@ reinitialize(void) /* pp assemblages */ Rxn_pp_assemblage_map.clear(); -#ifdef SKIP - for (j = 0; j < count_pp_assemblage; j++) - { - pp_assemblage_free(&pp_assemblage[j]); - } - count_pp_assemblage = 0; -#endif + /* s_s assemblages */ Rxn_ss_assemblage_map.clear(); -#ifdef SKIP - for (j = 0; j < count_ss_assemblage; j++) - { - ss_assemblage_free(&ss_assemblage[j]); - } - count_ss_assemblage = 0; -#endif + /* gases */ Rxn_gas_phase_map.clear(); @@ -2218,423 +2192,6 @@ phase_store(const char *name) return (phases[n]); } -#ifdef SKIP -/* ********************************************************************** - * - * Routines related to structure "pp_assemblage" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct pp_assemblage * Phreeqc:: -pp_assemblage_alloc(void) -/* ---------------------------------------------------------------------- */ -{ - struct pp_assemblage *pp_assemblage_ptr; - pp_assemblage_ptr = - (struct pp_assemblage *) PHRQ_malloc(sizeof(struct pp_assemblage)); - if (pp_assemblage_ptr == NULL) - malloc_error(); - pp_assemblage_ptr->n_user = -1; - pp_assemblage_ptr->n_user_end = -1; - pp_assemblage_ptr->description = NULL; - pp_assemblage_ptr->new_def = 0; - pp_assemblage_ptr->next_elt = NULL; - pp_assemblage_ptr->count_comps = 0; - pp_assemblage_ptr->pure_phases = NULL; - return (pp_assemblage_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct pp_assemblage * Phreeqc:: -pp_assemblage_bsearch(int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array pp_assemblage to find user number k. - * Assumes pp_assemblage is in sort order. - * - * Input: k, user number to find. - * - * Output: n, position in array pp_assemblage for user number k. - * - * Return: pointer to pp_assemblage structure for user number k, if found. - * NULL if not found. - */ - void *void_ptr; - if (count_pp_assemblage == 0) - { - *n = -999; - return (NULL); - } - void_ptr = (void *) - bsearch((char *) &k, - (char *) pp_assemblage, - (size_t) count_pp_assemblage, - (size_t) sizeof(struct pp_assemblage), - pp_assemblage_compare_int); - if (void_ptr == NULL) - { - *n = -999; - return (NULL); - } - *n = (int) ((struct pp_assemblage *) void_ptr - pp_assemblage); - return ((struct pp_assemblage *) void_ptr); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct pp_assemblage *pp_assemblage_ptr1, *pp_assemblage_ptr2; - pp_assemblage_ptr1 = (const struct pp_assemblage *) ptr1; - pp_assemblage_ptr2 = (const struct pp_assemblage *) ptr2; - if (pp_assemblage_ptr1->n_user > pp_assemblage_ptr2->n_user) - return (1); - if (pp_assemblage_ptr1->n_user < pp_assemblage_ptr2->n_user) - return (-1); - return (0); - -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -pp_assemblage_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare pp_assemblage user numbers - */ - const int *nptr1; - const struct pp_assemblage *nptr2; - - nptr1 = (const int *) ptr1; - nptr2 = (const struct pp_assemblage *) ptr2; - if (*nptr1 > nptr2->n_user) - return (1); - if (*nptr1 < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_copy(struct pp_assemblage *pp_assemblage_old_ptr, - struct pp_assemblage *pp_assemblage_new_ptr, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies pp_assemblage data from pp_assemblage_old_ptr to pp_assemblage_new_ptr. - * Space for a pp_assemblage_new_ptr must already be malloced. - * Space for list of pure phases in assemblage is malloced here. - */ - int count_comps; - char token[MAX_LENGTH]; -/* - * Store data for structure pp_assemblage - */ - pp_assemblage_new_ptr->n_user = n_user_new; - pp_assemblage_new_ptr->n_user_end = n_user_new; - pp_assemblage_new_ptr->new_def = pp_assemblage_old_ptr->new_def; - sprintf(token, "Pp_Assemblage defined in simulation %d.", simulation); - pp_assemblage_new_ptr->description = string_duplicate(token); - pp_assemblage_new_ptr->next_elt = - elt_list_dup(pp_assemblage_old_ptr->next_elt); -/* - * Count pure phases - */ - count_comps = pp_assemblage_old_ptr->count_comps; - pp_assemblage_new_ptr->count_comps = count_comps; -/* - * Malloc space and copy - */ - pp_assemblage_new_ptr->pure_phases = - (struct pure_phase *) PHRQ_malloc((size_t) count_comps * - sizeof(struct pure_phase)); - if (pp_assemblage_new_ptr->pure_phases == NULL) - malloc_error(); - - memcpy((void *) pp_assemblage_new_ptr->pure_phases, - (void *) pp_assemblage_old_ptr->pure_phases, - (size_t) count_comps * sizeof(struct pure_phase)); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an pp_assemblage definition from position n - * to position count_pp_assemblage. - */ - space((void **) ((void *) &pp_assemblage), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - pp_assemblage_copy(&pp_assemblage[n], - &pp_assemblage[count_pp_assemblage], n_user); - count_pp_assemblage++; - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies pp_assemblage[n_user_old] to old n_user_new space if - * found or to pp_assemblage[count_pp_assemblage] if not found. - * Pp_Assemblage array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct pp_assemblage *pp_assemblage_ptr_old, *pp_assemblage_ptr_new; -/* - * Find n_user_old in structure array pp_assemblage - */ - if (n_user_old == n_user_new) - return (OK); - pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); - if (pp_assemblage_ptr_old == NULL) - { - error_string = sformatf( "Pp_Assemblage %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array pp_assemblage or make new space - */ - sort = FALSE; - pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); - if (pp_assemblage_ptr_new != NULL) - { - pp_assemblage_free(pp_assemblage_ptr_new); - } - else - { - space((void **) ((void *) &pp_assemblage), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - if (n_user_new < pp_assemblage[count_pp_assemblage - 1].n_user) - sort = TRUE; - n_new = count_pp_assemblage++; - } -/* - * Copy data - */ - pp_assemblage_copy(&pp_assemblage[n_old], &pp_assemblage[n_new], - n_user_new); - if (sort == TRUE) - pp_assemblage_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array pp_assemblage. - */ -{ - int i; - int n_old; - struct pp_assemblage *pp_assemblage_ptr_old; -/* - * Find n_user_old in structure array - */ - pp_assemblage_ptr_old = pp_assemblage_bsearch(n_user_old, &n_old); - if (pp_assemblage_ptr_old != NULL) - { - /* - * Delete pp_assemblage - */ - pp_assemblage_free(&pp_assemblage[n_old]); - - for (i = n_old + 1; i < count_pp_assemblage; i++) - { - memcpy((void *) &pp_assemblage[i - 1], - (void *) &pp_assemblage[i], - (size_t) sizeof(struct pp_assemblage)); - } - count_pp_assemblage--; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_free(struct pp_assemblage *pp_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for pp_assemblage structure - */ - if (pp_assemblage_ptr == NULL) - return (ERROR); - - pp_assemblage_ptr->description = - (char *) free_check_null(pp_assemblage_ptr->description); - pp_assemblage_ptr->next_elt = - (struct elt_list *) free_check_null(pp_assemblage_ptr->next_elt); - pp_assemblage_ptr->pure_phases = - (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_init(struct pp_assemblage *pp_assemblage_ptr, int n_user, - int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ -/* - * Provides initial values for a new pp_assemblage - * arguments: - * n position in array pp_assemblage - * n_user user number for pp_assemblage - * return: OK - */ - pp_assemblage_ptr->n_user = n_user; - pp_assemblage_ptr->n_user_end = n_user_end; - pp_assemblage_ptr->new_def = TRUE; - pp_assemblage_ptr->description = string_duplicate(description); - - pp_assemblage_ptr->next_elt = NULL; - pp_assemblage_ptr->count_comps = 0; - pp_assemblage_ptr->pure_phases = - (struct pure_phase *) PHRQ_malloc((size_t) sizeof(struct pure_phase)); - if (pp_assemblage_ptr->pure_phases == NULL) - malloc_error(); - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_ptr_to_user(struct pp_assemblage *pp_assemblage_ptr_old, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies pp_assemblage_ptr_old to old n_user_new space if - * found or to pp_assemblage[count_pp_assemblage] if not found. - * Pp_Assemblage array may not be in sort order after the copy. - */ - int n_new, sort; - struct pp_assemblage *pp_assemblage_ptr_new; -/* - * Find n_user_old in structure array pp_assemblage - */ - if (pp_assemblage_ptr_old == NULL) - { - error_string = sformatf( "Pp_Assemblage pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array pp_assemblage or make new space - */ - sort = FALSE; - pp_assemblage_ptr_new = pp_assemblage_bsearch(n_user_new, &n_new); - if (pp_assemblage_ptr_new == pp_assemblage_ptr_old) - return (OK); - if (pp_assemblage_ptr_new != NULL) - { - pp_assemblage_free(pp_assemblage_ptr_new); - } - else - { - space((void **) ((void *) &pp_assemblage), count_pp_assemblage, - &max_pp_assemblage, sizeof(struct pp_assemblage)); - if (n_user_new < pp_assemblage[count_pp_assemblage - 1].n_user) - sort = TRUE; - n_new = count_pp_assemblage++; - } -/* - * Copy data - */ - pp_assemblage_copy(pp_assemblage_ptr_old, &pp_assemblage[n_new], - n_user_new); - if (sort == TRUE) - pp_assemblage_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct pp_assemblage * Phreeqc:: -pp_assemblage_replicate(struct pp_assemblage *pp_assemblage_old_ptr, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct pp_assemblage *pp_assemblage_ptr; - pp_assemblage_ptr = pp_assemblage_alloc(); - pp_assemblage_copy(pp_assemblage_old_ptr, pp_assemblage_ptr, n_user_new); - return (pp_assemblage_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct pp_assemblage * Phreeqc:: -pp_assemblage_search(int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "pp_assemblage" for user number n_user. - * - * Arguments: - * n_user input, user number - * n output, position in pp_assemblage - * - * Returns: - * if found, the address of the pp_assemblage element - * if not found, NULL - */ - int i; - for (i = 0; i < count_pp_assemblage; i++) - { - if (pp_assemblage[i].n_user == n_user) - { - *n = i; - return (&(pp_assemblage[i])); - } - } -/* - * Pp_Assemblage not found - */ - return (NULL); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pp_assemblage_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of pp_assemblage structures - */ - if (count_pp_assemblage > 0) - { - qsort(pp_assemblage, (size_t) count_pp_assemblage, - (size_t) sizeof(struct pp_assemblage), pp_assemblage_compare); - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pure_phase_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct pure_phase *pure_phase_ptr1, *pure_phase_ptr2; - pure_phase_ptr1 = (const struct pure_phase *) ptr1; - pure_phase_ptr2 = (const struct pure_phase *) ptr2; - return (strcmp_nocase(pure_phase_ptr1->name, pure_phase_ptr2->name)); - -} -#endif /* ********************************************************************** * * Routines related to structure "rates" @@ -3236,430 +2793,6 @@ s_store(const char *name, LDBLE l_z, int replace_if_found) return (s_ptr); } -#ifdef SKIP -/* ********************************************************************** - * - * Routines related to structure "ss_assemblage" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct ss_assemblage * Phreeqc:: -ss_assemblage_alloc(void) -/* ---------------------------------------------------------------------- */ -{ - struct ss_assemblage *ss_assemblage_ptr; - ss_assemblage_ptr = - (struct ss_assemblage *) PHRQ_malloc(sizeof(struct ss_assemblage)); - if (ss_assemblage_ptr == NULL) - malloc_error(); - ss_assemblage_ptr->n_user = -1; - ss_assemblage_ptr->n_user_end = -1; - ss_assemblage_ptr->description = NULL; - ss_assemblage_ptr->new_def = 0; - ss_assemblage_ptr->count_s_s = 0; - ss_assemblage_ptr->s_s = NULL; - return (ss_assemblage_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct ss_assemblage * Phreeqc:: -ss_assemblage_bsearch(int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array ss_assemblage to find user number k. - * Assumes ss_assemblage is in sort order. - * - * Input: k, user number to find. - * - * Output: n, position in array ss_assemblage for user number k. - * - * Return: pointer to ss_assemblage structure for user number k, if found. - * NULL if not found. - */ - void *void_ptr; - if (count_ss_assemblage == 0) - { - *n = -999; - return (NULL); - } - void_ptr = (void *) - bsearch((char *) &k, - (char *) ss_assemblage, - (size_t) count_ss_assemblage, - (size_t) sizeof(struct ss_assemblage), - ss_assemblage_compare_int); - if (void_ptr == NULL) - { - *n = -999; - return (NULL); - } - *n = (int) ((struct ss_assemblage *) void_ptr - ss_assemblage); - return ((struct ss_assemblage *) void_ptr); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct ss_assemblage *ss_assemblage_ptr1, *ss_assemblage_ptr2; - ss_assemblage_ptr1 = (const struct ss_assemblage *) ptr1; - ss_assemblage_ptr2 = (const struct ss_assemblage *) ptr2; - if (ss_assemblage_ptr1->n_user > ss_assemblage_ptr2->n_user) - return (1); - if (ss_assemblage_ptr1->n_user < ss_assemblage_ptr2->n_user) - return (-1); - return (0); - -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -ss_assemblage_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare ss_assemblage user numbers - */ - const int *nptr1; - const struct ss_assemblage *nptr2; - - nptr1 = (const int *) ptr1; - nptr2 = (const struct ss_assemblage *) ptr2; - if (*nptr1 > nptr2->n_user) - return (1); - if (*nptr1 < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_copy(struct ss_assemblage *ss_assemblage_old_ptr, - struct ss_assemblage *ss_assemblage_new_ptr, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies ss_assemblage data from ss_assemblage_old_ptr to ss_assemblage_new_ptr. - * Space for a ss_assemblage_new_ptr must already be malloced. - * Space for list of pure phases in assemblage is malloced here. - */ - int i, count_comps, count_s_s; - char token[MAX_LENGTH]; -/* - * Store data for structure ss_assemblage - */ - memcpy(ss_assemblage_new_ptr, ss_assemblage_old_ptr, - sizeof(struct ss_assemblage)); - ss_assemblage_new_ptr->n_user = n_user_new; - ss_assemblage_new_ptr->n_user_end = n_user_new; - sprintf(token, "ss_assemblage defined in simulation %d.", simulation); - ss_assemblage_new_ptr->description = string_duplicate(token); - ss_assemblage_new_ptr->new_def = FALSE; -/* - * Malloc space for s_s structures and fill - */ - count_s_s = ss_assemblage_old_ptr->count_s_s; - ss_assemblage_new_ptr->s_s = - (struct s_s *) PHRQ_malloc((size_t) count_s_s * sizeof(struct s_s)); - if (ss_assemblage_new_ptr->s_s == NULL) - malloc_error(); - memcpy((void *) ss_assemblage_new_ptr->s_s, - (void *) ss_assemblage_old_ptr->s_s, - (size_t) count_s_s * sizeof(struct s_s)); -/* - * Malloc space for components - */ - for (i = 0; i < count_s_s; i++) - { - count_comps = ss_assemblage_old_ptr->s_s[i].count_comps; - ss_assemblage_new_ptr->s_s[i].comps = - (struct s_s_comp *) PHRQ_malloc((size_t) count_comps * - sizeof(struct s_s_comp)); - if (ss_assemblage_new_ptr->s_s[i].comps == NULL) - malloc_error(); - memcpy((void *) ss_assemblage_new_ptr->s_s[i].comps, - (void *) ss_assemblage_old_ptr->s_s[i].comps, - (size_t) count_comps * sizeof(struct s_s_comp)); - } - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an ss_assemblage definition from position n - * to position count_ss_assemblage. - */ - space((void **) ((void *) &ss_assemblage), count_ss_assemblage, - &max_ss_assemblage, sizeof(struct ss_assemblage)); - ss_assemblage_copy(&ss_assemblage[n], - &ss_assemblage[count_ss_assemblage], n_user); - count_ss_assemblage++; - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies ss_assemblage[n_user_old] to old n_user_new space if - * found or to ss_assemblage[count_ss_assemblage] if not found. - * ss_assemblage array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct ss_assemblage *ss_assemblage_ptr_old, *ss_assemblage_ptr_new; -/* - * Find n_user_old in structure array ss_assemblage - */ - if (n_user_old == n_user_new) - return (OK); - ss_assemblage_ptr_old = ss_assemblage_bsearch(n_user_old, &n_old); - if (ss_assemblage_ptr_old == NULL) - { - error_string = sformatf( "ss_assemblage %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array ss_assemblage or make new space - */ - sort = FALSE; - ss_assemblage_ptr_new = ss_assemblage_bsearch(n_user_new, &n_new); - if (ss_assemblage_ptr_new != NULL) - { - ss_assemblage_free(ss_assemblage_ptr_new); - } - else - { - space((void **) ((void *) &ss_assemblage), count_ss_assemblage, - &max_ss_assemblage, sizeof(struct ss_assemblage)); - if (n_user_new < ss_assemblage[count_ss_assemblage - 1].n_user) - sort = TRUE; - n_new = count_ss_assemblage++; - } -/* - * Copy data - */ - ss_assemblage_copy(&ss_assemblage[n_old], &ss_assemblage[n_new], - n_user_new); - if (sort == TRUE) - ss_assemblage_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array ss_assemblage. - */ -{ - int i; - int n_old; - struct ss_assemblage *ss_assemblage_ptr_old; -/* - * Find n_user_old in structure array - */ - ss_assemblage_ptr_old = ss_assemblage_bsearch(n_user_old, &n_old); - if (ss_assemblage_ptr_old != NULL) - { - /* - * Delete ss_assemblage - */ - ss_assemblage_free(&ss_assemblage[n_old]); - - for (i = n_old + 1; i < count_ss_assemblage; i++) - { - memcpy((void *) &ss_assemblage[i - 1], - (void *) &ss_assemblage[i], - (size_t) sizeof(struct ss_assemblage)); - } - count_ss_assemblage--; - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_free(struct ss_assemblage *ss_assemblage_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Free space allocated for ss_assemblage structure - */ - int i; - - if (ss_assemblage_ptr == NULL) - return (ERROR); - ss_assemblage_ptr->description = - (char *) free_check_null(ss_assemblage_ptr->description); - for (i = 0; i < ss_assemblage_ptr->count_s_s; i++) - { - ss_assemblage_ptr->s_s[i].comps = - (struct s_s_comp *) free_check_null(ss_assemblage_ptr->s_s[i]. - comps); - } - ss_assemblage_ptr->s_s = - (struct s_s *) free_check_null(ss_assemblage_ptr->s_s); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_init(struct ss_assemblage *ss_assemblage_ptr, int n_user, - int n_user_end, char *description) -/* ---------------------------------------------------------------------- */ -{ - ss_assemblage_ptr->n_user = n_user; - ss_assemblage_ptr->n_user_end = n_user_end; - ss_assemblage_ptr->description = string_duplicate(description); - ss_assemblage_ptr->new_def = TRUE; - ss_assemblage_ptr->count_s_s = 0; - ss_assemblage_ptr->s_s = - (struct s_s *) PHRQ_malloc((size_t) sizeof(struct s_s)); - if (ss_assemblage_ptr->s_s == NULL) - malloc_error(); - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_ptr_to_user(struct ss_assemblage *ss_assemblage_ptr_old, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies ss_assemblage_ptr_old to old n_user_new space if - * found or to ss_assemblage[count_ss_assemblage] if not found. - * ss_assemblage array may not be in sort order after the copy. - */ - int n_new, sort; - struct ss_assemblage *ss_assemblage_ptr_new; -/* - * Find n_user_old in structure array ss_assemblage - */ - if (ss_assemblage_ptr_old == NULL) - { - error_string = sformatf( "ss_assemblage pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array ss_assemblage or make new space - */ - sort = FALSE; - ss_assemblage_ptr_new = ss_assemblage_bsearch(n_user_new, &n_new); - if (ss_assemblage_ptr_new == ss_assemblage_ptr_old) - return (OK); - if (ss_assemblage_ptr_new != NULL) - { - ss_assemblage_free(ss_assemblage_ptr_new); - } - else - { - space((void **) ((void *) &ss_assemblage), count_ss_assemblage, - &max_ss_assemblage, sizeof(struct ss_assemblage)); - if (n_user_new < ss_assemblage[count_ss_assemblage - 1].n_user) - sort = TRUE; - n_new = count_ss_assemblage++; - } -/* - * Copy data - */ - ss_assemblage_copy(ss_assemblage_ptr_old, &ss_assemblage[n_new], - n_user_new); - if (sort == TRUE) - ss_assemblage_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct ss_assemblage * Phreeqc:: -ss_assemblage_replicate(struct ss_assemblage *ss_assemblage_old_ptr, - int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct ss_assemblage *ss_assemblage_ptr; - ss_assemblage_ptr = ss_assemblage_alloc(); - ss_assemblage_copy(ss_assemblage_old_ptr, ss_assemblage_ptr, - n_user_new); - return (ss_assemblage_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct ss_assemblage * Phreeqc:: -ss_assemblage_search(int n_user, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "ss_assemblage" for user number n_user. - * - * Arguments: - * n_user input, user number - * n output, position in ss_assemblage - * - * Returns: - * if found, the address of the ss_assemblage element - * if not found, NULL - */ - int i; - for (i = 0; i < count_ss_assemblage; i++) - { - if (ss_assemblage[i].n_user == n_user) - { - *n = i; - return (&(ss_assemblage[i])); - } - } -/* - * ss_assemblage not found - */ - return (NULL); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ss_assemblage_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of ss_assemblage structures - */ - if (count_ss_assemblage > 0) - { - qsort(ss_assemblage, (size_t) count_ss_assemblage, - (size_t) sizeof(struct ss_assemblage), ss_assemblage_compare); - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -s_s_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct s_s *s_s_ptr1, *s_s_ptr2; - s_s_ptr1 = (const struct s_s *) ptr1; - s_s_ptr2 = (const struct s_s *) ptr2; - return (strcmp_nocase(s_s_ptr1->name, s_s_ptr2->name)); - -} -#endif /* ********************************************************************** * * Routines related to structure "save_values" @@ -6051,12 +5184,6 @@ entity_exists(char *name, int n_user) { return_value = FALSE; } -#ifdef SKIP - if (ss_assemblage_bsearch(n_user, &i) == NULL) - { - return_value = FALSE; - } -#endif break; } return (return_value); @@ -6313,67 +5440,6 @@ cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > *el) } return (kinetics_comp_ptr); } -#ifdef SKIP -#include "../PPassemblage.h" -struct pp_assemblage * Phreeqc:: -cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp) - // - // Builds a pp_assemblage structure from instance of cxxPPassemblage - // -{ - struct pp_assemblage *pp_assemblage_ptr = pp_assemblage_alloc(); - - pp_assemblage_ptr->description = string_duplicate (pp->Get_description().c_str()); - pp_assemblage_ptr->n_user = pp->Get_n_user(); - pp_assemblage_ptr->n_user_end = pp->Get_n_user_end(); - pp_assemblage_ptr->new_def = FALSE; - pp_assemblage_ptr->count_comps = (int) pp->Get_ppAssemblageComps().size(); - pp_assemblage_ptr->pure_phases = - (struct pure_phase *) free_check_null(pp_assemblage_ptr->pure_phases); - pp_assemblage_ptr->pure_phases = - cxxPPassemblageComp2pure_phase(&pp->Get_ppAssemblageComps()); - pp_assemblage_ptr->next_elt = cxxNameDouble2elt_list(&pp->Get_eltList()); - return (pp_assemblage_ptr); -} - -#include "../PPassemblageComp.h" -struct pure_phase * Phreeqc:: -cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc) - // - // Builds pure_phase structure from of cxxPPassemblageComp - // -{ - struct pure_phase *pure_phase_ptr = (struct pure_phase *) PHRQ_malloc((size_t) (ppc->size() * sizeof(struct pure_phase))); - if (pure_phase_ptr == NULL) - malloc_error(); - - int i = 0; - for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = ppc->begin(); - it != ppc->end(); ++it) - { - int n; - pure_phase_ptr[i].phase = phase_bsearch((*it).second.Get_name().c_str(), &n, FALSE); - if ((*it).second.Get_name().size() == 0) - pure_phase_ptr[i].name = NULL; - else - pure_phase_ptr[i].name = string_hsave((*it).second.Get_name().c_str()); - if ((*it).second.Get_add_formula().size() == 0) - pure_phase_ptr[i].add_formula = NULL; - else - pure_phase_ptr[i].add_formula = string_hsave((*it).second.Get_add_formula().c_str()); - pure_phase_ptr[i].si = (*it).second.Get_si(); - pure_phase_ptr[i].si_org = (*it).second.Get_si_org(); - pure_phase_ptr[i].moles = (*it).second.Get_moles(); - pure_phase_ptr[i].delta = (*it).second.Get_delta(); - pure_phase_ptr[i].initial_moles = (*it).second.Get_initial_moles(); - pure_phase_ptr[i].force_equality = (int) (*it).second.Get_force_equality(); - pure_phase_ptr[i].dissolve_only = (int) (*it).second.Get_dissolve_only(); - pure_phase_ptr[i].precipitate_only = (int) (*it).second.Get_precipitate_only(); - i++; - } - return (pure_phase_ptr); -} -#endif #include "../Solution.h" struct solution * Phreeqc:: cxxSolution2solution(const cxxSolution * sol) @@ -6462,110 +5528,6 @@ cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il) } return (iso); } -#ifdef SKIP -#include "../SSassemblage.h" -#include "../SS.h" -struct ss_assemblage * Phreeqc:: -cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss) - // - // Builds a ss_assemblage structure from instance of cxxSSassemblage - // -{ - struct ss_assemblage *ss_assemblage_ptr = ss_assemblage_alloc(); - - ss_assemblage_ptr->description = string_duplicate (ss->Get_description().c_str()); - ss_assemblage_ptr->n_user = ss->Get_n_user(); - ss_assemblage_ptr->n_user_end = ss->Get_n_user_end(); - ss_assemblage_ptr->new_def = FALSE; - ss_assemblage_ptr->count_s_s = (int) ss->Get_ssAssemblageSSs().size(); - ss_assemblage_ptr->s_s = cxxSSassemblageSS2s_s(&(ss->Get_ssAssemblageSSs())); - return (ss_assemblage_ptr); -} - -struct s_s * Phreeqc:: -cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp) - // - // Builds s_s structure from of cxxSS - // -{ - - // - // generate s_s structures - // - struct s_s *s_s_ptr = - (struct s_s *) PHRQ_malloc((size_t) (sscomp->size() * sizeof(struct s_s))); - if (s_s_ptr == NULL) - malloc_error(); - int j = 0; - for (std::map < std::string, cxxSS >::const_iterator it = sscomp->begin(); - it != sscomp->end(); ++it) - { - s_s_ptr[j].name = string_hsave((*it).second.Get_name().c_str()); - if ((*it).second.Get_name().size() <= 0) - { - error_msg("Name of a solid solution not defined in solid-solution assemblage. Error in _MODIFY definition?\n", STOP); - } - assert((*it).second.Get_name().size() > 0); - //s_s_ptr[j].total_moles = it->total_moles; - s_s_ptr[j].total_moles = 0; - s_s_ptr[j].dn = 0; - s_s_ptr[j].a0 = (*it).second.Get_a0(); - s_s_ptr[j].a1 = (*it).second.Get_a1(); - s_s_ptr[j].ag0 = (*it).second.Get_ag0(); - s_s_ptr[j].ag1 = (*it).second.Get_ag1(); - //s_s_ptr[j].ag0 = 0; - //s_s_ptr[j].ag1 = 0; - s_s_ptr[j].ss_in = TRUE; - s_s_ptr[j].miscibility = (*it).second.Get_miscibility(); - //s_s_ptr[j].spinodal = it->spinodal; - s_s_ptr[j].spinodal = FALSE; - //s_s_ptr[j].tk = it->tk; - s_s_ptr[j].tk = 273.15; - s_s_ptr[j].xb1 = (*it).second.Get_xb1(); - s_s_ptr[j].xb2 = (*it).second.Get_xb2(); - s_s_ptr[j].input_case = 0; - s_s_ptr[j].p[0] = 0; - s_s_ptr[j].p[1] = 0; - s_s_ptr[j].p[2] = 0; - s_s_ptr[j].p[3] = 0; - // - // generate s_s_comp structures - // - s_s_ptr[j].count_comps = (int) (*it).second.Get_comps().size(); - s_s_ptr[j].comps = NULL; - if ((*it).second.Get_comps().size() > 0) - { - int i = 0; - int n; - struct s_s_comp *s_s_comp_ptr = - (struct s_s_comp *) PHRQ_malloc((size_t) ((*it).second.Get_comps().size() * sizeof(struct s_s_comp))); - if (s_s_comp_ptr == NULL) - malloc_error(); - for (cxxNameDouble::const_iterator itc = (*it).second.Get_comps().begin(); - itc != (*it).second.Get_comps().end(); ++itc) - { - s_s_comp_ptr[i].name = string_hsave(itc->first.c_str()); - assert(itc->first.size() > 0); - s_s_comp_ptr[i].phase = phase_bsearch(itc->first.c_str(), &n, TRUE); - s_s_comp_ptr[i].initial_moles = 0; - s_s_comp_ptr[i].moles = itc->second; - s_s_comp_ptr[i].init_moles = 0; - s_s_comp_ptr[i].delta = 0; - s_s_comp_ptr[i].fraction_x = 0; - s_s_comp_ptr[i].log10_lambda = 0; - s_s_comp_ptr[i].log10_fraction_x = 0; - s_s_comp_ptr[i].dn = 0; - s_s_comp_ptr[i].dnc = 0; - s_s_comp_ptr[i].dnb = 0; - i++; - } - s_s_ptr[j].comps = s_s_comp_ptr; - } - j++; - } - return (s_s_ptr); -} -#endif #include "../Surface.h" struct surface * Phreeqc:: cxxSurface2surface(const cxxSurface * surf) @@ -6932,17 +5894,6 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_PPassemblage(use.Get_n_pp_assemblage_user(), entity_ptr); } } - #ifdef SKIP - if (use.Get_pp_assemblage_in() == TRUE) - { - struct pp_assemblage *struct_entity = pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), &n); - if (struct_entity != NULL) - { - cxxPPassemblage entity(struct_entity, sb.Get_io()); - sb.Set_PPassemblage(use.Get_n_pp_assemblage_user(), &entity); - } - } - #endif if (use.Get_exchange_in()) { cxxExchange *entity_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); @@ -6977,17 +5928,6 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), entity_ptr); } } -#ifdef SKIP - if (use.Get_ss_assemblage_in()) - { - struct ss_assemblage *struct_entity = ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), &n); - if (struct_entity != NULL) - { - cxxSSassemblage entity(struct_entity, sb.Get_io()); - sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), &entity); - } - } -#endif if (use.Get_kinetics_in()) { struct kinetics *struct_entity = kinetics_bsearch(use.Get_n_kinetics_user(), &n); @@ -7072,13 +6012,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) sb.Set_PPassemblage(it->second.Get_n_user(), &(it->second)); } } -#ifdef SKIP - for (i = 0; i < count_pp_assemblage; i++) - { - cxxPPassemblage entity(&pp_assemblage[i], sb.Get_io()); - sb.Set_PPassemblage(pp_assemblage[i].n_user, &entity ); - } -#endif // SSassemblages { std::map::iterator it; @@ -7087,13 +6020,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) sb.Set_SSassemblage(it->second.Get_n_user(), &(it->second)); } } -#ifdef SKIP - for (i = 0; i < count_ss_assemblage; i++) - { - cxxSSassemblage entity(&ss_assemblage[i], sb.Get_io()); - sb.Set_SSassemblage(ss_assemblage[i].n_user, &entity ); - } -#endif // Surfaces for (i = 0; i < count_surface; i++) { @@ -7190,16 +6116,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) sb.Set_PPassemblage(n, entity_ptr); } } -#ifdef SKIP - { - if (pp_assemblage_bsearch(n, &pos) != NULL) - { - //this->PPassemblages[n] = cxxPPassemblage(&(pp_assemblage[pos]), sb.Get_io()); - cxxPPassemblage ent(&(pp_assemblage[pos]), sb.Get_io()); - sb.Set_PPassemblage(n, &ent); - } - } -#endif // SSassemblages { cxxSSassemblage *entity_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, n); @@ -7208,16 +6124,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) sb.Set_SSassemblage(n, entity_ptr); } } -#ifdef SKIP - { - if (ss_assemblage_bsearch(n, &pos) != NULL) - { - //this->SSassemblages[n] = cxxSSassemblage(&(ss_assemblage[pos]), sb.Get_io()); - cxxSSassemblage ent(&(ss_assemblage[pos]), sb.Get_io()); - sb.Set_SSassemblage(n, &ent); - } - } -#endif // Surfaces { if (surface_bsearch(n, &pos) != NULL) @@ -7285,19 +6191,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) Rxn_pp_assemblage_map[n] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxPPassemblage >::const_iterator it = - sb.Get_PPassemblages().find(n); - if (it != sb.Get_PPassemblages().end()) - { - struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&(it->second)); - pp_assemblage_ptr_to_user(pp_assemblage_ptr, it->first); - pp_assemblage_free(pp_assemblage_ptr); - pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); - } - } -#endif // SSassemblages { std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().find(n); @@ -7306,19 +6199,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) Rxn_ss_assemblage_map[n] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxSSassemblage >::const_iterator it = - sb.Get_SSassemblages().find(n); - if (it != sb.Get_SSassemblages().end()) - { - struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&(it->second)); - ss_assemblage_ptr_to_user(ss_assemblage_ptr, it->first); - ss_assemblage_free(ss_assemblage_ptr); - ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); - } - } -#endif // Surfaces { std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().find(n); @@ -7423,18 +6303,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) Rxn_pp_assemblage_map[it->first] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().begin(); - for ( ; it != sb.Get_PPassemblages().end(); it++) - { - struct pp_assemblage *pp_assemblage_ptr = cxxPPassemblage2pp_assemblage(&(it->second)); - pp_assemblage_ptr_to_user(pp_assemblage_ptr, it->first); - pp_assemblage_free(pp_assemblage_ptr); - pp_assemblage_ptr = (struct pp_assemblage *) free_check_null(pp_assemblage_ptr); - } - } -#endif // SSassemblages { std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().begin(); @@ -7443,18 +6311,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) Rxn_ss_assemblage_map[it->first] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxSSassemblage >::const_iterator it = sb.Get_SSassemblages().begin(); - for ( ; it != sb.Get_SSassemblages().end(); it++) - { - struct ss_assemblage *ss_assemblage_ptr = cxxSSassemblage2ss_assemblage(&(it->second)); - ss_assemblage_ptr_to_user(ss_assemblage_ptr, it->first); - ss_assemblage_free(ss_assemblage_ptr); - ss_assemblage_ptr = (struct ss_assemblage *) free_check_null(ss_assemblage_ptr); - } - } -#endif // Surfaces { std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().begin(); diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index 94999730..e9f18e42 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -464,23 +464,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) add_elt_list(reaction_ptr->Get_elementList(), moles); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } -#ifdef SKIP - irrev_ptr = irrev_bsearch(n_user[Reaction], &n); - if (irrev_ptr == NULL) - break; - count_elts = 0; - paren_count = 0; - if (n_buffer == 1) - { - moles = irrev_ptr->steps[0]; - } - else - { - moles = 0.0; - } - add_elt_list(irrev_ptr->elts, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); -#endif break; case Pure_phase: /* @@ -533,12 +516,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) { add_elt_list(comps[j]->Get_totals(), 1.0); } -#ifdef SKIP - for (j = 0; j < exchange_ptr->count_comps; j++) - { - add_elt_list(exchange_ptr->comps[j].totals, 1.0); - } -#endif qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); elt_list_combine(); @@ -609,44 +586,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) elt_list_to_tally_table(tally_table[i].total[n_buffer]); } break; -#ifdef SKIP - /* - * fill an solid solution phase - */ - if (n_user[Ss_phase] < 0) - break; - ss_assemblage_ptr = ss_assemblage_bsearch(n_user[Ss_phase], &n); - if (ss_assemblage_ptr == NULL) - break; - found = FALSE; - moles = 0.0; - for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) - { - for (k = 0; k < ss_assemblage_ptr->s_s[j].count_comps; k++) - { - if (ss_assemblage_ptr->s_s[j].comps[k].phase->name == - tally_table[i].name) - break; - if (strcmp_nocase - (ss_assemblage_ptr->s_s[j].comps[k].phase->name, - tally_table[i].name) == 0) - break; - } - if (k < ss_assemblage_ptr->s_s[j].count_comps) - { - moles = ss_assemblage_ptr->s_s[j].comps[k].moles; - found = TRUE; - break; - } - } - if (found == FALSE) - break; - count_elts = 0; - paren_count = 0; - add_elt_list(tally_table[i].formula, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; -#endif case Gas_phase: /* * fill in gas phase @@ -674,29 +613,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; } -#ifdef SKIP - /* - * fill in gas phase - */ - if (n_user[Gas_phase] < 0) - break; - //gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); - - if (gas_phase_ptr == NULL) - break; - count_elts = 0; - paren_count = 0; - for (j = 0; j < gas_phase_ptr->count_comps; j++) - { - add_elt_list(gas_phase_ptr->comps[j].phase->next_elt, - gas_phase_ptr->comps[j].moles); - } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); - break; -#endif case Kinetics: /* * fill in kinetics @@ -732,16 +648,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) case UnKnown: break; } -#ifdef SKIP - output_msg(sformatf( "Column %d\t%s\tType: %d\n", i, - tally_table[i].name, tally_table[i].type)); - for (j = 0; j < count_tally_table_rows; j++) - { - output_msg(sformatf( "\t%d\t%s\t%e\n", j, - tally_table[i].total[n_buffer][j].name, - (double) tally_table[i].total[n_buffer][j].moles)); - } -#endif } return (OK); @@ -874,20 +780,6 @@ build_tally_table(void) { count_tt_exchange = 0; } -#ifdef SKIP - if (count_exchange > 0) - { - count_tt_exchange = 1; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = string_hsave("Exchange"); - tally_table[n].type = Exchange; - } - else - { - count_tt_exchange = 0; - } -#endif /* * add one for surface */ @@ -984,62 +876,6 @@ build_tally_table(void) } } } -#ifdef SKIP - count_tt_pure_phase = 0; - if (count_pp_assemblage > 0) - { - /* - * Go through all pure phases in pure phase assemblages - */ - for (i = 0; i < count_pp_assemblage; i++) - { - pp_assemblage_ptr = &pp_assemblage[i]; - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - { - pure_phase_ptr = &pp_assemblage_ptr->pure_phases[j]; - /* - * check if already in tally_table - */ - for (k = 1; k < count_tally_table_columns; k++) - { - if (tally_table[k].type == Pure_phase && - tally_table[k].name == pure_phase_ptr->phase->name && - tally_table[k].add_formula == - pure_phase_ptr->add_formula) - break; - } - if (k < count_tally_table_columns) - continue; - /* - * Add to table - */ - count_tt_pure_phase++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = pure_phase_ptr->phase->name; - tally_table[n].type = Pure_phase; - tally_table[n].add_formula = pure_phase_ptr->add_formula; - count_elts = 0; - paren_count = 0; - if (pure_phase_ptr->add_formula != NULL) - { - strcpy(token, pure_phase_ptr->add_formula); - ptr = &(token[0]); - get_elts_in_species(&ptr, 1.0); - } - else - { - strcpy(token, pure_phase_ptr->phase->formula); - add_elt_list(pure_phase_ptr->phase->next_elt, 1.0); - } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } -#endif /* * Add solid-solution pure phases */ @@ -1096,53 +932,6 @@ build_tally_table(void) } } } -#ifdef SKIP - if (count_ss_assemblage > 0) - { - /* - * Go through all components of all solid solutions in solid-solution assemblages - */ - for (i = 0; i < count_ss_assemblage; i++) - { - ss_assemblage_ptr = &ss_assemblage[i]; - for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) - { - s_s_ptr = &ss_assemblage_ptr->s_s[j]; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - s_s_comp_ptr = &s_s_ptr->comps[k]; - /* - * check if already in tally_table - */ - for (l = 1; l < count_tally_table_columns; l++) - { - if (tally_table[l].type == Ss_phase && - tally_table[l].name == s_s_comp_ptr->phase->name) - break; - } - if (l < count_tally_table_columns) - continue; - /* - * Add to table - */ - count_tt_ss_phase++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = s_s_comp_ptr->phase->name; - tally_table[n].type = Ss_phase; - count_elts = 0; - paren_count = 0; - strcpy(token, s_s_comp_ptr->phase->formula); - add_elt_list(s_s_comp_ptr->phase->next_elt, 1.0); - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } - } -#endif /* * Add kinetic reactants */ @@ -1280,12 +1069,6 @@ add_all_components_tally(void) add_reaction(&it->second, 1, 1.0); } } -#ifdef SKIP - for (i = 0; i < count_irrev; i++) - { - add_reaction(&irrev[i], 1, 1.0); - } -#endif /* * Add pure phases */ @@ -1296,12 +1079,6 @@ add_all_components_tally(void) add_pp_assemblage(&(it->second)); } } -#ifdef SKIP - for (i = 0; i < count_pp_assemblage; i++) - { - add_pp_assemblage(&pp_assemblage[i]); - } -#endif /* * Exchangers */ @@ -1312,12 +1089,6 @@ add_all_components_tally(void) add_exchange(&it->second); } } -#ifdef SKIP - for (i = 0; i < count_exchange; i++) - { - add_exchange(&exchange[i]); - } -#endif /* * Surfaces */ @@ -1335,12 +1106,6 @@ add_all_components_tally(void) add_gas_phase(&it->second); } } -#ifdef SKIP - for (i = 0; i < count_gas_phase; i++) - { - add_gas_phase(&gas_phase[i]); - } -#endif /* * Add solid-solution pure phases */ @@ -1349,12 +1114,6 @@ add_all_components_tally(void) { add_ss_assemblage(&(it->second)); } -#ifdef SKIP - for (i = 0; i < count_ss_assemblage; i++) - { - add_ss_assemblage(&ss_assemblage[i]); - } -#endif /* * Add elements in kinetic reactions */ diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 70e55e29..04e8874b 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -159,20 +159,7 @@ tidy_model(void) qsort(phases, (size_t) count_phases, (size_t) sizeof(struct phase *), phase_compare); } -#ifdef SKIP -/* pure_phases */ - if (new_pp_assemblage) - { - pp_assemblage_sort(); - } -#endif -/* solid solutions */ -#ifdef SKIP - if (new_ss_assemblage) - { - ss_assemblage_sort(); - } -#endif + /* surfaces */ if (new_surface) { @@ -1623,107 +1610,6 @@ tidy_pp_assemblage(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_pp_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, l, n_user, first, last; - struct phase *phase_ptr; - LDBLE coef; - char *ptr; -/* - * Find pointers for pure phases - */ - for (i = 0; i < count_pp_assemblage; i++) - { - count_elts = 0; - paren_count = 0; - coef = 1.0; - pp_assemblage[i].new_def = FALSE; - for (j = 0; j < pp_assemblage[i].count_comps; j++) - { - phase_ptr = - phase_bsearch(pp_assemblage[i].pure_phases[j].name, &k, - FALSE); - if (phase_ptr == NULL) - { - input_error++; - error_string = sformatf( "Phase not found in data base, %s.", - pp_assemblage[i].pure_phases[j].name); - error_msg(error_string, CONTINUE); - continue; - } - else - { - pp_assemblage[i].pure_phases[j].phase = phase_ptr; - add_elt_list(phase_ptr->next_elt, coef); - - } - if (pp_assemblage[i].pure_phases[j].add_formula != NULL) - { - first = count_elts; - phase_ptr = - phase_bsearch(pp_assemblage[i].pure_phases[j]. - add_formula, &k, FALSE); - if (phase_ptr != NULL) - { - pp_assemblage[i].pure_phases[j].add_formula = - phase_ptr->formula; - } - { - char * temp_add = string_duplicate(pp_assemblage[i].pure_phases[j].add_formula); - ptr = temp_add; - get_elts_in_species(&ptr, coef); - free_check_null(temp_add); - } - /* check that all elements are in the database */ - for (l = first; l < count_elts; l++) - { - if (elt_list[l].elt->master == NULL) - { - input_error++; - error_string = sformatf( - "Element \"%s\" in alternative phase for \"%s\" in EQUILIBRIUM_PHASES not found in database.", - elt_list[l].elt->name, - pp_assemblage[i].pure_phases[j].name); - error_msg(error_string, CONTINUE); - } - } - } - } - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - pp_assemblage[i].next_elt = - (struct elt_list *) free_check_null(pp_assemblage[i].next_elt); - pp_assemblage[i].next_elt = elt_list_save(); - -/* - * Store list with all elements in phases and add formulae - */ - -/* - * Duplicate pure phases if necessary - */ - if (pp_assemblage[i].n_user_end > pp_assemblage[i].n_user) - { - n_user = pp_assemblage[i].n_user; - last = pp_assemblage[i].n_user_end; - pp_assemblage[i].n_user_end = pp_assemblage[i].n_user; - for (j = n_user + 1; j <= last; j++) - { - pp_assemblage_duplicate(n_user, j); - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_ss_assemblage(void) @@ -1921,192 +1807,6 @@ tidy_ss_assemblage(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_ss_assemblage(void) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, k1, n_user, last; - struct phase *phase_ptr; - struct s_s *s_s_ptr; - LDBLE nb, nc, n_tot, xb, xc, dnb, dnc, l_a0, l_a1; - LDBLE xb2, xb3, xb4, xc2, xc3; - LDBLE moles; -/* - * Find pointers for pure phases - */ - for (i = 0; i < count_ss_assemblage; i++) - { - count_elts = 0; - paren_count = 0; - for (j = 0; j < ss_assemblage[i].count_s_s; j++) - { - for (k = 0; k < ss_assemblage[i].s_s[j].count_comps; k++) - { - phase_ptr = - phase_bsearch(ss_assemblage[i].s_s[j].comps[k].name, - &k1, FALSE); - if (phase_ptr == NULL) - { - input_error++; - error_string = sformatf( - "Phase not found in data base, %s, assemblage %d.", - ss_assemblage[i].s_s[j].comps[k].name, - ss_assemblage[i].n_user); - error_msg(error_string, CONTINUE); - ss_assemblage[i].s_s[j].comps[k].phase = NULL; - continue; - } - else - { - ss_assemblage[i].s_s[j].comps[k].phase = phase_ptr; - ss_assemblage[i].s_s[j].comps[k].phase->moles_x = 0; - ss_assemblage[i].s_s[j].comps[k].phase->fraction_x = 0; - } - if (ss_assemblage[i].s_s[j].comps[k].moles == NAN) - { - input_error++; - error_string = sformatf( - "Moles of solid solution component not defined, %s, assemblage %d.", - ss_assemblage[i].s_s[j].comps[k].name, - ss_assemblage[i].n_user); - error_msg(error_string, CONTINUE); - continue; - } - } - - if (ss_assemblage[i].new_def == TRUE) - { - /* - * Calculate a0 and a1 first - */ - s_s_calc_a0_a1(&(ss_assemblage[i].s_s[j])); - s_s_ptr = &(ss_assemblage[i].s_s[j]); - - n_tot = 0; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - moles = ss_assemblage[i].s_s[j].comps[k].moles; - if (ss_assemblage[i].s_s[j].comps[k].moles <= 0.0) - { - moles = MIN_TOTAL_SS; - ss_assemblage[i].s_s[j].comps[k].initial_moles = - moles; - } - n_tot += moles; - } - - for (k = 0; k < s_s_ptr->count_comps; k++) - { - moles = ss_assemblage[i].s_s[j].comps[k].moles; - if (ss_assemblage[i].s_s[j].comps[k].moles <= 0.0) - { - moles = MIN_TOTAL_SS; - } - ss_assemblage[i].s_s[j].comps[k].fraction_x = - moles / n_tot; - ss_assemblage[i].s_s[j].comps[k].log10_fraction_x = - log10(moles / n_tot); - } - l_a0 = ss_assemblage[i].s_s[j].a0; - l_a1 = ss_assemblage[i].s_s[j].a1; - -/* - * Binary solid solution - */ - if (l_a0 != 0.0 || l_a1 != 0) - { - ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; - nc = ss_assemblage[i].s_s[j].comps[0].moles; - if (nc == 0) - nc = MIN_TOTAL_SS; - nb = ss_assemblage[i].s_s[j].comps[1].moles; - if (nb == 0) - nb = MIN_TOTAL_SS; - xc = nc / n_tot; - xb = nb / n_tot; - - /* lambdas */ - ss_assemblage[i].s_s[j].comps[0].log10_lambda = - xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; - ss_assemblage[i].s_s[j].comps[1].log10_lambda = - xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; - - /* derivatives wrt nc and nb */ - xc2 = xc * xc; - xc3 = xc2 * xc; - xb2 = xb * xb; - xb3 = xb2 * xb; - xb4 = xb3 * xb; - - /* component 1 */ - dnb = - -2 * l_a0 * xb * xc2 - 8 * l_a1 * xb2 * xc2 + - 6 * l_a1 * xb * xc2 - 4 * l_a1 * xc * xb4 - - 8 * l_a1 * xb3 * xc2 - 4 * l_a1 * xb2 * xc3 - - 2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + - 6 * l_a1 * xc * xb2 + 1; - ss_assemblage[i].s_s[j].comps[0].dnb = dnb / n_tot; - dnc = - 2 * l_a0 * xb3 + 2 * l_a0 * xc * xb2 + 8 * l_a1 * xb4 + - 8 * l_a1 * xc * xb3 - 2 * l_a1 * xb3 - 6 * l_a1 * xc * xb2; - ss_assemblage[i].s_s[j].comps[0].dnc = - -xb / nc + dnc / n_tot; - ss_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; - - /* component 2 */ - dnb = - 2 * l_a0 * xb * xc2 + 2 * l_a0 * xc3 + - 8 * l_a1 * xb2 * xc2 + 8 * l_a1 * xb * xc3 - - 2 * l_a1 * xb * xc2 - 6 * l_a1 * xc3; - ss_assemblage[i].s_s[j].comps[1].dnb = - -xc / nb + dnb / n_tot; - dnc = - -2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + - 2 * l_a1 * xc * xb2 - 2 * l_a0 * xb * xc2 - - 8 * l_a1 * xb2 * xc2 + 6 * l_a1 * xb * xc2 + 1; - ss_assemblage[i].s_s[j].comps[1].dnc = dnc / n_tot; - - s_s_prep(ss_assemblage[i].s_s[j].tk, - &(ss_assemblage[i].s_s[j]), TRUE); - ss_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; -/* - * Ideal solid solution - */ - } - else - { - ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; - for (k = 0; k < s_s_ptr->count_comps; k++) - { - ss_assemblage[i].s_s[j].comps[k].log10_lambda = 0; - moles = ss_assemblage[i].s_s[j].comps[k].moles; - if (moles <= 0.0) - moles = MIN_TOTAL_SS; - ss_assemblage[i].s_s[j].comps[k].dnb = - (n_tot - moles) / (moles * n_tot); - ss_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; - } - } - } - } - ss_assemblage[i].new_def = FALSE; - -/* - * Duplicate ss_assemblage if necessary - */ - n_user = ss_assemblage[i].n_user; - last = ss_assemblage[i].n_user_end; - ss_assemblage[i].n_user_end = ss_assemblage[i].n_user; - for (j = n_user + 1; j <= last; j++) - { - ss_assemblage_duplicate(n_user, j); - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_punch(void) @@ -3465,157 +3165,6 @@ tidy_min_exchange(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_min_exchange(void) -/* ---------------------------------------------------------------------- */ -/* - * If exchanger is related to mineral, exchanger amount is - * set in proportion - */ -{ - int k, n, jj; - struct pp_assemblage *pp_a_ptr; - //struct exch_comp *comp_ptr; - //struct master *master_ptr; - char *ptr; - LDBLE conc; - - //for (i = 0; i < count_exchange; i++) - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) - { - cxxExchange * exchange_ptr = &(it->second); - if (!exchange_ptr->Get_new_def()) - continue; - if (exchange_ptr->Get_n_user() < 0) - continue; - n = exchange_ptr->Get_n_user(); - //for (j = 0; j < exchange[i].count_comps; j++) - std::vector comps = exchange_ptr->Vectorize(); - // check elements - for (size_t j = 0; j < comps.size(); j++) - { - cxxExchComp * comp_ptr = comps[j]; - if (comp_ptr->Get_phase_name().size() == 0) - continue; - - - /* First find exchange master species */ - cxxNameDouble nd = comps[j]->Get_totals(); - cxxNameDouble::iterator kit = nd.begin(); - bool found_exchange = false; - for (; kit != nd.end(); kit++) - { - /* Find master species */ - struct element *elt_ptr = element_store(kit->first.c_str()); - if (elt_ptr == NULL || elt_ptr->master == NULL) - { - input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", - kit->first.c_str()); - error_msg(error_string, CONTINUE); - continue; - } - if (elt_ptr->master->type == EX) - { - found_exchange = true;; - } - } - if (!found_exchange) - { - input_error++; - error_string = sformatf( - "Exchange formula does not contain an exchange master species, %s", - comp_ptr->Get_formula().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find the mineral on which exchanger depends... */ - if ((pp_a_ptr = pp_assemblage_bsearch(n, &k)) == NULL) - { - input_error++; - error_string = sformatf( - "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", - n, comp_ptr->Get_formula().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - for (k = 0; k < pp_a_ptr->count_comps; k++) - { - if (strcmp_nocase - (comp_ptr->Get_phase_name().c_str(), - pp_a_ptr->pure_phases[k].name) == 0) - { - break; - } - } - if (k == pp_a_ptr->count_comps) - { - input_error++; - error_string = sformatf( - "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", - comp_ptr->Get_phase_name().c_str(), comp_ptr->Get_formula().c_str(), n); - error_msg(error_string, CONTINUE); - continue; - } - /* use database name for phase */ - comp_ptr->Set_phase_name(pp_a_ptr->pure_phases[k].phase->name); - /* make exchanger concentration proportional to mineral ... */ - conc = pp_a_ptr->pure_phases[k].moles * comp_ptr->Get_phase_proportion(); - count_elts = 0; - paren_count = 0; - { - char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); - ptr = temp_formula; - get_elts_in_species(&ptr, conc); - free_check_null(temp_formula); - } - comp_ptr->Set_totals(elt_list_NameDouble()); -/* - * make sure exchange elements are in phase - */ - count_elts = 0; - paren_count = 0; - { - char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); - ptr = temp_formula; - get_elts_in_species(&ptr, -comp_ptr->Get_phase_proportion()); - free_check_null(temp_formula); - } - { - char * temp_formula = string_duplicate(pp_a_ptr->pure_phases[k].phase->formula); - ptr = temp_formula; - get_elts_in_species(&ptr, 1.0); - free_check_null(temp_formula); - } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - for (jj = 0; jj < count_elts; jj++) - { - if (elt_list[jj].elt->primary->s->type != EX - && elt_list[jj].coef < 0) - { - input_error++; - error_string = sformatf( - "Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", - comp_ptr->Get_formula().c_str(), - (double) comp_ptr->Get_phase_proportion(), - pp_a_ptr->pure_phases[k].phase->name, - pp_a_ptr->pure_phases[k].phase->formula); - error_msg(error_string, CONTINUE); - break; - } - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -4345,295 +3894,6 @@ ss_prep(LDBLE t, cxxSS *ss_ptr, int print) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print) -/* ---------------------------------------------------------------------- */ -{ - int i, j, k, converged, divisions; - LDBLE r, rt, ag0, ag1, crit_pt; - LDBLE xc, tc; - LDBLE l_x, x0, x1, xsm1, xsm2, xb1, xb2; - LDBLE xc1, xc2; - LDBLE facb1, faca1, spim1, xblm1, acrae, acrael, xliapt, xliapm; - LDBLE xaly, xaly1, xaly2; - LDBLE faca, facb, spialy, facal, facbl; - LDBLE tol; - - if (pr.ss_assemblage == FALSE) - print = FALSE; - tol = 1e-6; - r = R_KJ_DEG_MOL; - rt = r * t; - a0 = s_s_ptr->ag0 / rt; - a1 = s_s_ptr->ag1 / rt; - s_s_ptr->a0 = a0; - s_s_ptr->a1 = a1; - ag0 = a0 * rt; - ag1 = a1 * rt; - kc = exp(k_calc(s_s_ptr->comps[0].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); - kb = exp(k_calc(s_s_ptr->comps[1].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); - crit_pt = fabs(a0) + fabs(a1); -/* - * Default, no miscibility or spinodal gaps - */ - s_s_ptr->miscibility = FALSE; - s_s_ptr->spinodal = FALSE; - xsm1 = 0.5; - xsm2 = 0.5; - xb1 = 0.5; - xb2 = 0.5; - xc1 = 0; - xc2 = 0; - - if (crit_pt >= tol) - { -/* - * Miscibility gap information - */ - if (fabs(a1) < tol) - { - xc = 0.5; - tc = ag0 / (2 * r); - } - else - { - xc = 0.5 + (pow((ag0 * ag0 + 27 * ag1 * ag1), (LDBLE) 0.5) - - ag0) / (18 * ag1); - tc = (12 * ag1 * xc - 6 * ag1 + 2 * ag0) * (xc - xc * xc) / r; - } - if (print == TRUE) - { - error_string = sformatf( "Description of Solid Solution %s", - s_s_ptr->name); - dup_print(error_string, TRUE); - } - if (print == TRUE) - { - output_msg(sformatf( - "\t Temperature: %g kelvin\n", - (double) t)); - output_msg(sformatf( - "\t A0 (dimensionless): %g\n", - (double) a0)); - output_msg(sformatf( - "\t A1 (dimensionless): %g\n", - (double) a1)); - output_msg(sformatf( - "\t A0 (kJ/mol): %g\n", - (double) ag0)); - output_msg(sformatf( - "\t A1 (kJ/mol): %g\n\n", - (double) ag1)); - } - if (xc < 0 || xc > 1) - { - if (print == TRUE) - output_msg(sformatf( - "No miscibility gap above 0 degrees kelvin.\n")); - } - else - { - if (print == TRUE) - { - output_msg(sformatf( - "\t Critical mole-fraction of component 2: %g\n", - (double) xc)); - output_msg(sformatf( - "\t Critical temperature: %g kelvin\n", - (double) tc)); - output_msg(sformatf( - "\n(The critical temperature calculation assumes that the Guggenheim model\ndefined at %g kelvin is valid at the critical temperature.)\n\n\n", - (double) t)); - } - } -/* - * Calculate miscibility and spinodal gaps - */ - if (tc >= t) - { - - /* search for sign changes */ - x0 = 0; - x1 = 1; - if (scan(f_spinodal, &x0, &x1) == TRUE) - { - - /* find first spinodal pt */ - xsm1 = halve(f_spinodal, x0, x1, tol); - xsm1 = halve(f_spinodal, x0, x1, tol); - s_s_ptr->spinodal = TRUE; - - /* find second spinodal pt */ - x0 = x1; - x1 = 1; - if (scan(f_spinodal, &x0, &x1) == TRUE) - { - xsm2 = halve(f_spinodal, x0, x1, tol); - } - else - { - error_msg("Failed to find second spinodal point.", STOP); - } - } - } - } -/* - * Now find Miscibility gap - */ - if (s_s_ptr->spinodal == TRUE) - { - if (print == TRUE) - output_msg(sformatf( - "\t Spinodal-gap mole fractions, component 2: %g\t%g\n", - (double) xsm1, (double) xsm2)); - converged = FALSE; - if (converged == FALSE) - { - for (i = 1; i < 3; i++) - { - divisions = (int) pow(10., i); - for (j = 0; j < divisions; j++) - { - for (k = divisions; k > 0; k--) - { - xc1 = (LDBLE) j / divisions + 0.001; - xc2 = (LDBLE) k / divisions; - converged = solve_misc(&xc1, &xc2, tol); - if (converged == TRUE) - break; - } - if (converged == TRUE) - break; - } - if (converged == TRUE) - break; - } - } - if (converged == FALSE) - { - error_msg("Failed to find miscibility gap.", STOP); - } - s_s_ptr->miscibility = TRUE; - if (xc1 < xc2) - { - xb1 = 1 - xc2; - xb2 = 1 - xc1; - xc1 = 1 - xb1; - xc2 = 1 - xb2; - } - else - { - xb1 = 1 - xc1; - xb2 = 1 - xc2; - } - facb1 = kb * xb1 * exp(xc1 * xc1 * (a0 + a1 * (4 * xb1 - 1))); - faca1 = kc * xc1 * exp(xb1 * xb1 * (a0 - a1 * (3 - 4 * xb1))); - spim1 = log10(faca1 + facb1); - xblm1 = 1. / (1. + faca1 / facb1); - acrae = facb1 / faca1; - acrael = log10(acrae); - xliapt = log10(facb1); - xliapm = log10(faca1); - - if (print == TRUE) - { - output_msg(sformatf( - "\t Miscibility-gap fractions, component 2: %g\t%g\n", - (double) xb1, (double) xb2)); - output_msg(sformatf( - "\n\t\t\tEutectic Point Calculations\n\n")); - output_msg(sformatf( - "\t Aqueous activity ratio (comp2/comp1): %g\n", - (double) acrae)); - output_msg(sformatf( - "\t Log aqueous activity ratio (comp2/comp1): %g\n", - (double) acrael)); - output_msg(sformatf( - "\t Aqueous activity fraction of component 2: %g\n", - (double) xblm1)); - output_msg(sformatf( - "\t Log IAP (component 2): %g\n", - (double) xliapt)); - output_msg(sformatf( - "\t Log IAP (component 1): %g\n", - (double) xliapm)); - output_msg(sformatf( - "\t Log Sum Pi: %g\n", - (double) spim1)); - } - s_s_ptr->tk = t; - s_s_ptr->xb1 = xb1; - s_s_ptr->xb2 = xb2; - } -/* - * Alyotropic point calculation - */ - xaly = -1.0; - l_x = a0 * a0 + 3 * a1 * a1 + 6 * a1 * log(kb / kc); - if (l_x > 0) - { - if (fabs(l_x - a0 * a0) >= tol) - { - xaly1 = (-(a0 - 3 * a1) + pow(l_x, (LDBLE) 0.5)) / (6 * a1); - xaly2 = (-(a0 - 3 * a1) - pow(l_x, (LDBLE) 0.5)) / (6 * a1); - if (xaly1 >= 0 && xaly1 <= 1) - { - xaly = xaly1; - } - if (xaly2 >= 0 && xaly2 <= 1) - { - xaly = xaly2; - } - } - else - { - xaly = 0.5 + log(kb / kc) / (2 * a0); - } - if (xaly > 0 && xaly < 1) - { - faca = - kc * (1 - - xaly) * exp(xaly * xaly * (a0 - a1 * (3 - 4 * xaly))); - facb = - kb * xaly * exp((1 - xaly) * (1 - xaly) * - (a0 + a1 * (4 * xaly - 1.0))); - spialy = log10(faca + facb); - facal = log10(faca); - facbl = log10(facb); - if (xaly > xb1 && xaly < xb2) - { - if (print == TRUE) - output_msg(sformatf( - "\nLocal minimum in the solidus curve coresponding to a maximum\nin the minimum stoichiometric saturation curve.\n\n")); - } - else - { - if (print == TRUE) - output_msg(sformatf( - "\n\t\t\tAlyotropic Point\n\n")); - } - if (print == TRUE) - { - output_msg(sformatf( - "\t Solid mole fraction of component 2: %g\n", - (double) xaly)); - output_msg(sformatf( - "\t Log IAP (component 2): %g\n", - (double) facbl)); - output_msg(sformatf( - "\t Log IAP (component 1): %g\n", - (double) facal)); - output_msg(sformatf( - "\t Log Sum Pi: %g\n", - (double) spialy)); - } - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol) @@ -5317,374 +4577,6 @@ ss_calc_a0_a1(cxxSS *ss_ptr) ss_ptr->Set_a1(l_a1); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -ss_calc_a0_a1(cxxSS *ss_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i, done; - LDBLE r, rt, *p; - LDBLE q1, q2, xbq1, xbq2, xb1, xb2, xc1, xc2; - LDBLE r1, r2, pa1, pb1, pa2, pb2, xsm1, xsm2; - LDBLE pn9, pn10, c5, c6, pl9, pl10, pj9, pj10; - LDBLE xc, tc; - LDBLE spialy, azero, phi1, phi2, test; - LDBLE dq1, dq2, denom, ratio, dr1, dr2, x21, x22, x61, x62; - LDBLE l_a0, l_a1, ag0, ag1; - LDBLE wg2, wg1, alpha2, alpha3; - LDBLE l_kc, l_kb; - LDBLE xaly, xcaly, alpha0, alpha1, fx, fx1; - LDBLE tol; - - tol = 1e-6; - rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; - cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); - cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); - struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &k, FALSE); - struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE); - if (ss_ptr->comps[0].phase == NULL || ss_ptr->comps[1].phase == NULL) - { - input_error++; - error_string = sformatf( - "Two components were not defined for %s solid solution", - ss_ptr->name); - error_msg(error_string, CONTINUE); - return (ERROR); - } - l_kc = exp(k_calc(ss_ptr->comps[0].phase->rxn->logk, ss_ptr->tk, REF_PRES_PASCAL) * - LOG_10); - l_kb = exp(k_calc(ss_ptr->comps[1].phase->rxn->logk, ss_ptr->tk, REF_PRES_PASCAL) * - LOG_10); - - p = ss_ptr->p; - - l_a0 = 0; - l_a1 = 0; - ag0 = 0; - ag1 = 0; - dq2 = 0; - switch (ss_ptr->input_case) - { - /* - * dimensionless a0 and a1 - */ - case 0: - l_a0 = p[0]; - l_a1 = p[1]; - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - /* - * two activity coefficients - * q1, q2, xbq1, xbq2 - */ - case 1: - q1 = p[0]; - q2 = p[1]; - xbq1 = p[2]; - xbq2 = p[3]; - done = FALSE; - if (fabs(1 - xbq1) > 0 && q1 > 0) - { - dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); - if (xbq2 <= 0 || xbq2 > 1) - { - l_a0 = dq1; - l_a1 = 0; - done = TRUE; - } - } - if (done == FALSE) - { - if (fabs(xbq2) < 0 || q2 <= 0) - { - input_error++; - error_string = sformatf( - "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - done = TRUE; - } - } - if (done == FALSE) - { - dq2 = log(q2) / (xbq2 * xbq2); - if (xbq1 < 0. || xbq2 > 1.) - { - l_a0 = dq2; - l_a1 = 0; - done = TRUE; - } - } - if (done == FALSE) - { - denom = 4 * (xbq1 - xbq2) + 2; - if (fabs(denom) >= tol) - { - if (fabs(1 - xbq1) > 0 && q1 > 0) - { - dq1 = log(q1) / ((1 - xbq1) * (1 - xbq1)); - l_a0 = (dq1 * (3 - 4 * xbq2) + - dq2 * (4 * xbq1 - 1)) / denom; - l_a1 = (dq1 - dq2) / denom; - done = TRUE; - } - } - } - if (done == FALSE) - { - input_error++; - error_string = sformatf( - "No solution possible for A0 and A1 calculation from two activity coefficients, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - } - /* io = 1 */ - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - /* - * two distribution coefficients - * q1, q2, xbq1, xbq2 - */ - case 2: - q1 = p[0]; - q2 = p[1]; - xbq1 = p[2]; - xbq2 = p[3]; - ratio = l_kc / l_kb; - dr1 = log(q1 / ratio); - x21 = 2 * xbq1 - 1; - if (fabs(xbq1 - xbq2) < tol || xbq2 < 0) - { - l_a0 = dr1 / x21; - l_a1 = 0; - } - else - { - dr2 = log(q2 / ratio); - x22 = 2 * xbq2 - 1; - if (xbq1 < 0.) - { - l_a0 = dr2 / x22; - l_a1 = 0; - } - else - { - x61 = 6 * xbq1 * xbq1 - 6 * xbq1 + 1; - x62 = 6 * xbq2 * xbq2 - 6 * xbq2 + 1; - if (fabs(x22 * x61 - x21 * x62) < tol) - { - input_error++; - error_string = sformatf( - "No solution possible for A0 and A1 calculation from two distribution coefficients, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - } - l_a0 = (x61 * dr2 - x62 * dr1) / (x22 * x61 - x21 * x62); - l_a1 = (x21 * dr2 - x22 * dr1) / (x21 * x62 - x22 * x61); - } - } - - /* io = 1 */ - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - /* - * from miscibility gap fractions - * q1, q2 - */ - case 3: - q1 = p[0]; - q2 = p[1]; - xb1 = q1; - xb2 = q2; - xc1 = 1 - xb1; - xc2 = 1 - xb2; - r1 = log(xb1 / xb2); - r2 = log(xc1 / xc2); - pa1 = xc2 * xc2 - xc1 * xc1; - pb1 = - 3 * (xc2 * xc2 - xc1 * xc1) - 4 * (xc2 * xc2 * xc2 - - xc1 * xc1 * xc1); - pa2 = xb2 * xb2 - xb1 * xb1; - pb2 = - -(3 * (xb2 * xb2 - xb1 * xb1) - - 4 * (xb2 * xb2 * xb2 - xb1 * xb1 * xb1)); - l_a0 = (r1 - pb1 / pb2 * r2) / (pa1 - pa2 * pb1 / pb2); - l_a1 = (r1 - pa1 / pa2 * r2) / (pb1 - pb2 * pa1 / pa2); - - /* io = 1 */ - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - /* - * from spinodal gap fractions - * q1, q2 - */ - case 4: - q1 = p[0]; - q2 = p[1]; - xsm1 = q1; - xsm2 = q2; - pn9 = 1 / xsm1; - pn10 = 1 / xsm2; - c5 = 1 - xsm1; - c6 = 1 - xsm2; - pl9 = 6 * c5 - 12 * c5 * c5; - pl10 = 6 * c6 - 12 * c6 * c6; - pj9 = 2 * c5; - pj10 = 2 * c6; - l_a0 = (pn9 - pl9 / pl10 * pn10) / (pj9 - pl9 / pl10 * pj10); - l_a1 = (pn9 - pj9 / pj10 * pn10) / (pl9 - pj9 / pj10 * pl10); - - /* io = 1 */ - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - /* - * from critical point - * q1, q2 - */ - case 5: - xc = p[0]; - tc = p[1]; - r = R_KJ_DEG_MOL; - ag1 = r * tc * (2 * xc - 1) / (12 * xc * xc * (1 - xc) * (1 - xc)); - ag0 = (r * tc / (xc * (1 - xc)) - (12 * xc - 6) * ag1) / 2; - - /* io = 0 */ - l_a0 = ag0 / rt; - l_a1 = ag1 / rt; - break; - /* - * from alyotropic point - * q1, q2 - */ - case 6: - q1 = p[0]; - q2 = p[1]; - xaly = q1; - r = log(l_kb / l_kc); - alpha0 = 2 * xaly - 1; - alpha1 = 6 * xaly * (xaly - 1) + 1; - spialy = pow((LDBLE) 10., q2); - l_a0 = -999.; - l_a1 = -999.; - if (fabs(alpha0) < tol) - { - input_error++; - error_string = sformatf( - "No solution possible for A0 and A1 calculation from alyotropic point, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - } - else - { - azero = 1; - if (fabs(alpha0) > tol) - azero = r / alpha0; - xcaly = 1 - xaly; -/* - * Solve for a0 by Newton's method - */ - for (i = 0; i < 50; i++) - { - phi1 = - xcaly * xcaly * (azero + - (r - azero * alpha0) * (4 * xaly - - 1) / alpha1); - phi2 = - xaly * xaly * (azero + - (3 - 4 * xaly) * (azero * alpha0 - - r) / alpha1); - phi1 = xaly * l_kb * exp(phi1); - phi2 = xcaly * l_kc * exp(phi2); - fx = phi1 + phi2 - spialy; - fx1 = - xcaly * xcaly * (1 - - alpha0 * (4 * xaly - - 1) / alpha1) * phi1 + - xaly * xaly * (1 + - alpha0 * (3 - 4 * xaly) / alpha1) * phi2; - if (fabs(fx1) < 1e-10) - { - input_error++; - error_string = sformatf( - "Could not find A0 and A1 calculation from alyotropic point, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - break; - } - l_a0 = azero - fx / fx1; - test = fabs(l_a0 - azero) + fabs(fx); - azero = l_a0; - if (test < tol) - break; - } - if (i == 50) - { - input_error++; - error_string = sformatf( - "Too many iterations, could not find A0 and A1 calculation from alyotropic point, %s.\n", - ss_ptr->name); - error_msg(error_string, CONTINUE); - } - else - { - l_a1 = (r - l_a0 * alpha0) / alpha1; - - /* io = 0 */ - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - } - - } - break; - /* - * dimensional (kJ/mol) Guggenheim parameters - * ag0, ag1 - */ - case 7: - ag0 = p[0]; - ag1 = p[1]; - l_a0 = ag0 / rt; - l_a1 = ag1 / rt; - break; - /* - * Waldbaum-Thompson - * wg2, wg1 - */ - case 8: - wg2 = p[0]; - wg1 = p[1]; - ag0 = (wg2 + wg1) / 2; - ag1 = (wg2 - wg1) / 2; - l_a0 = ag0 / rt; - l_a1 = ag1 / rt; - break; - /* - * Margules - * alpha2, alpha3 - */ - case 9: - alpha2 = p[0]; - alpha3 = p[1]; - l_a0 = alpha2 + 3 * alpha3 / 4; - l_a1 = alpha3 / 4; - ag0 = l_a0 * rt; - ag1 = l_a1 * rt; - break; - } - - ss_ptr->ag0 = ag0; - ss_ptr->ag1 = ag1; - ss_ptr->a0 = l_a0; - ss_ptr->a1 = l_a1; - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_master_isotope(void) diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index cd6820fc..430fd879 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -194,25 +194,12 @@ transport(void) } */ -#ifdef SKIP - mix_ptr = &mix[0]; - for (i = 0; i < count_mix; i++) - mix_free(mix_ptr++); - count_mix = 2 * count_cells; -#endif Rxn_mix_map.clear(); /* * stagnant mix factors go in mix[0 .. count_cells] */ -#ifdef SKIP - mix = (struct mix *) PHRQ_realloc(mix, - (size_t) count_mix * - sizeof(struct mix)); - if (mix == NULL) - malloc_error(); - memset(mix, 0, sizeof(struct mix) * count_mix); -#endif + } /* * mix[] is extended in init_mix(), to accommodate column mix factors @@ -804,60 +791,9 @@ transport(void) Dispersion_mix_map.clear(); if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { - //mix_ptr = &mix[0]; - //for (i = 0; i < count_mix; i++) - // mix_free(mix_ptr++); Rxn_mix_map.clear(); - //count_mix = 0; } - //else - //{ - //if (nmix > 0) - //{ - //mix_ptr = &mix[count_mix - count_cells]; - //for (i = count_mix - count_cells; i < count_mix; i++) - //mix_free(mix_ptr++); - //count_mix -= count_cells; - //mix = - // (struct mix *) PHRQ_realloc(mix, - // (size_t) (count_mix + - // 1) * - // sizeof(struct mix)); - //if (mix == NULL) - // malloc_error(); - //} - //} -#ifdef SKIP -/* - * free mix structures - */ - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) - { - mix_ptr = &mix[0]; - for (i = 0; i < count_mix; i++) - mix_free(mix_ptr++); - count_mix = 0; - } - else - { - if (nmix > 0) - { - mix_ptr = &mix[count_mix - count_cells]; - for (i = count_mix - count_cells; i < count_mix; i++) - mix_free(mix_ptr++); - - count_mix -= count_cells; - mix = - (struct mix *) PHRQ_realloc(mix, - (size_t) (count_mix + - 1) * - sizeof(struct mix)); - if (mix == NULL) - malloc_error(); - } - } -#endif if (heat_nmix > 0) { heat_mix_array = (LDBLE *) free_check_null(heat_mix_array); @@ -1083,200 +1019,6 @@ init_mix(void) //m = (LDBLE *) free_check_null(m); return (l_nmix); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -init_mix(void) -/* ---------------------------------------------------------------------- */ -{ - LDBLE dav, lav, mixf, maxmix, corr_disp, diffc_here, mD; - int i, n, l_nmix, count_comps, max_mix; - LDBLE *m; - - m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); - if (m == NULL) - malloc_error(); - if (multi_Dflag == TRUE) - diffc_here = 0.0; - else - diffc_here = diffc_tr; -/* - * Define mixing factors among inner cells - */ - corr_disp = 1.; - if (correct_disp == TRUE && ishift != 0) - { - if (bcon_first == 3) - corr_disp += 1. / count_cells; - if (bcon_last == 3) - corr_disp += 1. / count_cells; - } - maxmix = 0.0; - for (i = 1; i < count_cells; i++) - { - lav = (cell_data[i - 1].length + cell_data[i].length) / 2; - if (ishift != 0) - dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; - else - dav = 0; - - mixf = - (diffc_here * timest / lav + - dav) * corr_disp / cell_data[i].length; - if (mixf > maxmix) - maxmix = mixf; - m[i] = mixf; /* m[i] has mixf with lower cell */ - if (multi_Dflag == TRUE) - { - mD = diffc_max * timest / (lav * lav); - if (mD > maxmix) - maxmix = mD; - } - } -/* - * Also for boundary cells - */ - if (bcon_first == 1) - { - lav = cell_data[0].length; - if (ishift != 0) - dav = cell_data[0].disp; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) / lav; - if (mixf > maxmix) - maxmix = mixf; - m[0] = 2 * mixf; - if (multi_Dflag == TRUE) - { - mD = diffc_max * timest / (lav * lav); - if (mD > maxmix) - maxmix = mD; - } - } - else - m[0] = 0; - - if (bcon_last == 1) - { - lav = cell_data[count_cells - 1].length; - if (ishift != 0) - dav = cell_data[count_cells - 1].disp; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) / lav; - if (mixf > maxmix) - maxmix = mixf; - m[count_cells] = 2 * mixf; - if (multi_Dflag == TRUE) - { - mD = diffc_max * timest / (lav * lav); - if (mD > maxmix) - maxmix = mD; - } - } - else - m[count_cells] = 0; - -/* - * Find number of mixes - */ - if (maxmix == 0) - { - l_nmix = 0; - if (multi_Dflag == TRUE && mcd_substeps > 1 - && stag_data->count_stag > 0) - l_nmix = (int) ceil(mcd_substeps); - } - else - { - if ((bcon_first == 1) || (bcon_last == 1)) - l_nmix = 1 + (int) floor(4.5 * maxmix); - else - l_nmix = 1 + (int) floor(3.0 * maxmix); - - if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) - { - if (l_nmix < 2) - l_nmix = 2; - } - if (multi_Dflag == TRUE && mcd_substeps > 1) - l_nmix = (int) ceil(l_nmix * mcd_substeps); - - for (i = 0; i <= count_cells; i++) - m[i] /= l_nmix; - } - /* - * Fill mix structure - */ - if (l_nmix != 0) - { - mix = - (struct mix *) PHRQ_realloc(mix, - (size_t) (count_mix + - count_cells) * - sizeof(struct mix)); - if (mix == NULL) - malloc_error(); - count_mix += count_cells; - for (n = count_mix - count_cells; n < count_mix; n++) - { - mix[n].description = NULL; - mix[n].count_comps = 3; - mix[n].comps = - (struct mix_comp *) PHRQ_malloc((size_t) 3 * - sizeof(struct mix_comp)); - if (mix[n].comps == NULL) - malloc_error(); - } - - n = count_mix - count_cells; -/* - * max_mix brings n_user outside range of active cells - * mix[n].n_user = mix[n].n_user_end = -999 has same effect - * but max_mix keeps mix in sort order in case mix_bsearch - * is used - */ - if (n - 1 <= 0) - max_mix = 1; - else - max_mix = mix[n - 1].n_user + 1; - - if (max_mix < count_cells * (stag_data->count_stag + 1) + 1) - max_mix = count_cells * (stag_data->count_stag + 1) + 1; - - for (i = 1; i <= count_cells; i++) - { - dav = 0; - count_comps = 0; - mix[n].description = (char *) free_check_null(mix[n].description); - mix[n].description = string_duplicate(" "); -/* - * again, max_mix brings n_user outside range of active cells, etc... - */ - mix[n].n_user = max_mix + i; - mix[n].n_user_end = max_mix + i; - - mix[n].comps[count_comps].n_solution = i - 1; - mix[n].comps[count_comps].fraction = m[i - 1]; - dav += m[i - 1]; - count_comps++; - mix[n].comps[count_comps].n_solution = i + 1; - mix[n].comps[count_comps].fraction = m[i]; - dav += m[i]; - count_comps++; - mix[n].comps[count_comps].n_solution = i; - mix[n].comps[count_comps].fraction = 1.0 - dav; - - n++; - } - } - m = (LDBLE *) free_check_null(m); - return (l_nmix); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) @@ -1583,11 +1325,7 @@ int Phreeqc:: set_initial_moles(int i) /* ---------------------------------------------------------------------- */ { - //struct pp_assemblage *pp_assemblage_ptr; - //struct gas_phase *gas_phase_ptr; struct kinetics *kinetics_ptr; - //struct ss_assemblage *ss_assemblage_ptr; - //struct exchange *exchange_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; int j, k, l, n; /* @@ -1601,30 +1339,15 @@ set_initial_moles(int i) it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) { - //gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; it->second.Set_initial_moles(it->second.Get_moles()); if (it->second.Get_initial_moles() < 0) it->second.Set_initial_moles(0.0); } } } -#ifdef SKIP - pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); - if (pp_assemblage_ptr != NULL) - { - for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - { - pp_assemblage_ptr->pure_phases[j].initial_moles = - pp_assemblage_ptr->pure_phases[j].moles; - if (pp_assemblage_ptr->pure_phases[j].initial_moles < 0) - pp_assemblage_ptr->pure_phases[j].initial_moles = 0; - } - } -#endif /* * Gas phase */ - //gas_phase_ptr = gas_phase_bsearch(i, &n); { cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, i); if (gas_phase_ptr != NULL) @@ -1632,7 +1355,6 @@ set_initial_moles(int i) std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t l = 0; l < gc.size(); l++) { - //gas_phase_ptr->comps[j].initial_moles = gas_phase_ptr->comps[j].moles; gc[l].Set_initial_moles(gc[l].Get_moles()); } gas_phase_ptr->Set_gas_comps(gc); @@ -1656,11 +1378,9 @@ set_initial_moles(int i) { std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); for (k = 0; k < (int) ss_ptrs.size(); k++) - //for (k = 0; k < ss_assemblage_ptr->count_s_s; k++) { cxxSS * ss_ptr = ss_ptrs[k]; for (j = 0; j < (int) ss_ptr->Get_ss_comps().size(); j++) - //for (j = 0; j < ss_assemblage_ptr->s_s[k].count_comps; j++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); comp_ptr->Set_init_moles(comp_ptr->Get_moles()); @@ -1668,22 +1388,9 @@ set_initial_moles(int i) } } } -#ifdef SKIP - ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); - if (ss_assemblage_ptr != NULL) - { - for (k = 0; k < ss_assemblage_ptr->count_s_s; k++) - { - for (j = 0; j < ss_assemblage_ptr->s_s[k].count_comps; j++) - ss_assemblage_ptr->s_s[k].comps[j].init_moles = - ss_assemblage_ptr->s_s[k].comps[j].moles; - } - } -#endif /* * For interlayer diffusion: add tiny bit of exchanger if absent */ - //exchange_ptr = exchange_bsearch(i, &n); cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, i); if (interlayer_Dflag && exchange_ptr == NULL) { @@ -1720,47 +1427,6 @@ set_initial_moles(int i) initial_exchangers(TRUE); state = TRANSPORT; } -#ifdef SKIP - exchange_ptr = exchange_bsearch(i, &n); - if (interlayer_Dflag && exchange_ptr == NULL) - { - n = count_exchange++; - space((void **) ((void *) &exchange), count_exchange, &max_exchange, - sizeof(struct exchange)); - exchange_init(&(exchange[n]), i, i, - "Interlayer diffusion: added 2e-10 moles X-"); - use.Get_exchange_in() = TRUE; - use.Get_n_exchange_user() = i; - exchange[n].new_def = TRUE; - exchange[n].solution_equilibria = TRUE; - exchange[n].n_solution = i; - exchange[n].n_user = exchange[n].n_user_end = i; - count_elts = 0; - paren_count = 0; - strcpy(token, "X"); - ptr = token; - get_elts_in_species(&ptr, 2e-10); - ptr = token; - get_token(&ptr, token1, &exchange[n].comps[0].formula_z, &l); - exchange[n].comps[0].formula_totals = elt_list_save(); - exchange[n].comps[0].moles = 2e-10; - exchange[n].comps[0].totals = elt_list_save(); - exchange[n].comps[0].charge_balance = 0.0; - exchange[n].count_comps = 1; - if (n == count_exchange - 1 && count_exchange > 1) - { - if (exchange[n].n_user < exchange[n - 1].n_user) - { - qsort(exchange, - (size_t) count_exchange, - (size_t) sizeof(struct exchange), exchange_compare); - } - } - state = INITIAL_EXCHANGE; - initial_exchangers(TRUE); - state = TRANSPORT; - } -#endif return (OK); } @@ -3433,1124 +3099,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) V_M_il = (struct V_M *) free_check_null(V_M_il); return (il_calcs); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) -/* ---------------------------------------------------------------------- */ -{ - /* mole transfer of the individual master_species: - * Eqn 1: - * J_ij = DDt * (A_ij / lav) * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) - * regular column, stagnant FALSE: - * D_i = temperature-corrected Dw - * A_ij = A_icell * A_jcell - * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / - * (length_icell / 2) - * lav = A_icell + A_jcell - * grad(c) is concentration difference in icell and jcell, - for activity corrections see Appelo & Wersin, 2007. - * stagnant TRUE: - * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) - * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por - * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; - * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. - * Interlayer diffusion (IL) takes the gradient in the equivalent concentrations on X-. - surface area A for IL: - stagnant: mixf_il is mixf * por_il / por. - por_il = interlayer porosity, from -interlayer_D true 'por_il'. - por = total porosity, from -multi_D true 'multi_Dpor'. - **nov. 12, 2011**: - mixf is corrected, * (1 - por_il / por). - new_pf = (por - por_il)^(-multi_Dn). - in regular column, A is calc'd from (free + DL porewater) and cell-length. - for IL: A * por_il / (por - por_il). - - por_il is entered as a single value. It is limited to 0.999 * por. - por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) - - IL-water = (free + DL porewater) * por_il / (por - por_il). - */ - int i, i_max, j, j_max, k, k_il, l, only_counter, il_calcs; - int i1; - LDBLE lav, A1, A2, A_ij, A_ij_il, ddlm, aq1, aq2, mixf_il; - LDBLE dl_s, dl_aq1, dl_aq2, c_dl, visc1, visc2, dum, dum2, tort1, tort2; - LDBLE por_il1, por_il2, por_il12; - LDBLE c, Dz2c, Dz2c_dl, Dz2c_il, aq_il1, aq_il2; - LDBLE cec1, cec2, cec12, rc1, rc2; - struct V_M - { - LDBLE grad, D, z, Dz, Dzc, Dzc_dl, g_dl; - int o_c; - } *V_M, *V_M_il; - struct surface *s_ptr1, *s_ptr2; - struct surface_charge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; - struct exchange *ex_ptr1, *ex_ptr2; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - - V_M = V_M_il = NULL; - /* check for immediate return and interlayer diffusion calcs... */ - if (interlayer_Dflag) - { - il_calcs = 1; - if (icell == 0 && cell_data[0].por_il < interlayer_Dpor_lim) - il_calcs = 0; - else if (icell == count_cells && - cell_data[count_cells - 1].por_il < interlayer_Dpor_lim) - il_calcs = 0; - else if (icell > 0 - && (cell_data[icell - 1].por_il < interlayer_Dpor_lim - || cell_data[jcell - 1].por_il < interlayer_Dpor_lim)) - il_calcs = 0; - } - else - il_calcs = 0; - - if (stagnant) - { - if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim - || cell_data[jcell - 1].por < multi_Dpor_lim)) - return (OK); - } - else - { /* regular column... */ - if (icell == 0) - { - if (!il_calcs && cell_data[0].por < multi_Dpor_lim) - return (OK); - } - else if (icell == count_cells) - { - if (!il_calcs && cell_data[count_cells - 1].por < multi_Dpor_lim) - return (OK); - } - else - { - if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim - || cell_data[jcell - 1].por < multi_Dpor_lim)) - return (OK); - } - } - - /* do the calcs */ - aq1 = solution_bsearch(icell, &i, TRUE)->mass_water; - aq2 = solution_bsearch(jcell, &i, TRUE)->mass_water; - /* - * check if DL calculations must be made, find amounts of water... - */ - s_charge_ptr1 = s_charge_ptr2 = NULL; - s_ptr1 = s_ptr2 = NULL; - dl_s = dl_aq1 = dl_aq2 = 0.0; - visc1 = visc2 = 1.0; - only_counter = FALSE; - - s_ptr1 = surface_bsearch(icell, &i); - if (s_ptr1 != NULL) - { - if (s_ptr1->dl_type != NO_DL) - { - if (s_ptr1->only_counter_ions) - only_counter = TRUE; - /* find the one (and only one...) immobile surface comp with DL... */ - for (i = 0; i < s_ptr1->count_comps; i++) - { - if (s_ptr1->comps[i].Dw == 0) - { - s_charge_ptr1 = &s_ptr1->charge[s_ptr1->comps[i].charge]; - dl_aq1 = s_charge_ptr1->mass_water; - visc1 = s_ptr1->DDL_viscosity; - /* check for more comps with Dw = 0 */ - for (j = i + 1; j < s_ptr1->count_comps; j++) - { - if (s_ptr1->comps[j].Dw == 0 - && s_ptr1->comps[j].charge != - s_ptr1->comps[i].charge) - { - if (!warn_fixed_Surf) - { - k = (int) strcspn(s_ptr1->comps[i].formula, "_"); - strncpy(token1, s_ptr1->comps[i].formula, k); - token1[k] = '\0'; - sprintf(token, - "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); - warning_msg(token); - warn_fixed_Surf = 1; - } - break; - } - } - break; - } - } - } - } - s_ptr2 = surface_bsearch(jcell, &i); - if (s_ptr2 != NULL) - { - if (s_ptr2->dl_type != NO_DL) - { - if (s_ptr2->only_counter_ions) - only_counter = TRUE; - for (i = 0; i < s_ptr2->count_comps; i++) - { - if (s_ptr2->comps[i].Dw == 0) - { - s_charge_ptr2 = &s_ptr2->charge[s_ptr2->comps[i].charge]; - dl_aq2 = s_charge_ptr2->mass_water; - visc2 = s_ptr2->DDL_viscosity; - /* check for more comps with Dw = 0 */ - for (j = i + 1; j < s_ptr2->count_comps; j++) - { - if (s_ptr2->comps[j].Dw == 0 - && s_ptr2->comps[j].charge != - s_ptr2->comps[i].charge) - { - if (!warn_fixed_Surf) - { - k = (int) strcspn(s_ptr2->comps[i].formula, "_"); - strncpy(token1, s_ptr2->comps[i].formula, k); - token1[k] = '\0'; - sprintf(token, - "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); - warning_msg(token); - warn_fixed_Surf = 1; - } - break; - } - } - break; - } - } - } - } - if (!stagnant) - { - if (icell == 0) - visc1 = visc2; - else if (icell == count_cells) - visc2 = visc1; - } - /* in each cell: DL surface = mass_water_DL / (cell_length) - free pore surface = mass_water_free / (cell_length) - determine DL surface as a fraction of the total pore surface... */ - if (dl_aq1 > 0) - dl_s = dl_aq1 / (dl_aq1 + aq1); - if (dl_aq2 > 0) - { - dum = dl_aq2 / (dl_aq2 + aq2); - if (dl_aq1 > 0) - /* average the 2... */ - dl_s = (dl_s + dum) / 2; - else - /* there is one DL surface... */ - dl_s = dum; - } - - por_il1 = por_il2 = por_il12 = 0.0; - cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; - if (il_calcs) - { - /* find interlayer porosity por_il, - make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). - Find amounts of IL water and cec. - Must do this separately, since por and por_il are in cell_data structure. */ - if (icell == 0) - { - por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * - cell_data[0].por_il; - por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * - cell_data[0].por_il; - if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) - /* take the average... */ - por_il12 = (por_il1 + por_il2) / 2; - else - /* at column ends, take the clay... */ - por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[0].por) - por_il12 = 0.999 * cell_data[0].por; - - if (por_il2 > 0.999 * cell_data[0].por) - por_il2 = 0.999 * cell_data[0].por; - aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[0].por - por_il2); - /* Assume interlayer water is proportional with CEC... */ - aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; - } - else if (icell == count_cells) - { - por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * - cell_data[count_cells - 1].por_il; - por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * - cell_data[count_cells - 1].por_il; - if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) - por_il12 = (por_il1 + por_il2) / 2; - else - por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[count_cells - 1].por) - por_il12 = 0.999 * cell_data[count_cells - 1].por; - - if (por_il1 > 0.999 * cell_data[count_cells - 1].por) - por_il1 = 0.999 * cell_data[count_cells - 1].por; - aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[count_cells - 1].por - por_il1); - aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / - sol_D[count_cells].exch_total; - } - else - { - por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * - cell_data[icell - 1].por_il; - por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * - cell_data[jcell - 1].por_il; - - if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) - por_il12 = (por_il1 + por_il2) / 2; - else - por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[icell - 1].por || por_il12 > 0.999 * cell_data[jcell - 1].por) - por_il12 = (cell_data[icell - 1].por >= cell_data[jcell - 1].por ? - 0.999 * cell_data[jcell - 1].por : - 0.999 * cell_data[icell - 1].por); - aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[icell - 1].por - por_il1); - aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[jcell - 1].por - por_il2); -/* former code... */ - //aq_il1 = (aq1 + dl_aq1) * cell_data[icell - 1].por_il / - // cell_data[icell - 1].por; - //aq_il2 = (aq2 + dl_aq2) * cell_data[jcell - 1].por_il / - // cell_data[jcell - 1].por; -/* end */ - } - if (por_il12 == 0) - il_calcs = 0; - else - { - dum = sol_D[icell].exch_total; - dum2 = sol_D[jcell].exch_total; - rc1 = (dum2 > dum ? dum / dum2 : 1); - rc2 = (dum > dum2 ? dum2 / dum : 1); - if (sol_D[icell].exch_total > 3e-10) - cec1 = dum / aq_il1; - else - cec1 = 2e-10; - if (sol_D[jcell].exch_total > 3e-10) - cec2 = dum2 / aq_il2; - else - cec2 = 2e-10; - /* and the largest for calculating the mass transfer... */ - cec12 = (cec1 > cec2 ? cec1 : cec2); - } - } - - /* In stagnant calc's, find mixf_il for IL diffusion, correct mixf. - In regular column, find surface areas A and A_il */ - tort1 = tort2 = lav = 1.0; - A_ij = A_ij_il = mixf_il = 0.0; - if (stagnant) - { - mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); - dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? - cell_data[icell - 1].por : cell_data[jcell - 1].por); - if (il_calcs) - { - mixf_il = mixf * por_il12 / interlayer_tortf; - dum -= por_il12; - } - mixf *= (dum * pow(dum, multi_Dn)); -/* former code... */ - //mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); - //dum = (cell_data[icell - 1].por_il <= cell_data[jcell - 1].por_il ? - // cell_data[icell - 1].por_il : cell_data[jcell - 1].por_il); - //mixf_il = mixf * dum / interlayer_tortf; - //dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? - // cell_data[icell - 1].por : cell_data[jcell - 1].por); - //mixf *= dum * pow(dum, multi_Dn); -/* end */ - } - else - { /* regular column... */ - if (icell == 0) - { - tort1 = tort2 = pow(cell_data[0].por, -multi_Dn); - lav = cell_data[0].length; - A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); - if (il_calcs) - A_ij_il = - A_ij * por_il12 / ((cell_data[0].por - por_il12) * - interlayer_tortf); - A_ij /= tort1; - } - else if (icell == count_cells) - { - tort1 = tort2 = pow(cell_data[count_cells - 1].por, -multi_Dn); - lav = cell_data[count_cells - 1].length; - A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); - if (il_calcs) - A_ij_il = A_ij * por_il12 / - ((cell_data[count_cells - 1].por - por_il12) * interlayer_tortf); - A_ij /= tort2; - } - else - { - tort1 = pow(cell_data[icell - 1].por, -multi_Dn); - tort2 = pow(cell_data[jcell - 1].por, -multi_Dn); - A1 = (aq1 + dl_aq1) / (cell_data[icell - 1].length * - 0.5 * cell_data[icell - 1].length); - A2 = (aq2 + dl_aq2) / (cell_data[jcell - 1].length * - 0.5 * cell_data[jcell - 1].length); - if (il_calcs) - { - dum = A1 * por_il12 / - ((cell_data[icell - 1].por - por_il12) * interlayer_tortf); - dum2 = A2 * por_il12 / - ((cell_data[jcell - 1].por - por_il12) * interlayer_tortf); - A_ij_il = dum * dum2 / (dum + dum2); - } - A1 /= tort1; - A2 /= tort2; - A_ij = A1 * A2 / (A1 + A2); -/* former code... */ - //A1 = aq1 / (cell_data[icell - 1].length * - // 0.5 * cell_data[icell - 1].length); - //A2 = aq2 / (cell_data[jcell - 1].length * - // 0.5 * cell_data[jcell - 1].length); - //dum = A1 * cell_data[icell - 1].por_il / - // (cell_data[icell - 1].por * interlayer_tortf); - //dum2 = A2 * cell_data[jcell - 1].por_il / - // (cell_data[jcell - 1].por * interlayer_tortf); - //A_ij_il = dum * dum2 / (dum + dum2); - //A1 /= tort1; - //A2 /= tort2; - //A_ij = A1 * A2 / (A1 + A2); - - //A1 = dl_aq1 / (cell_data[icell - 1].length * - // 0.5 * cell_data[icell - 1].length); - //A2 = dl_aq2 / (cell_data[jcell - 1].length * - // 0.5 * cell_data[jcell - 1].length); - //dum = A1 * cell_data[icell - 1].por_il / - // (cell_data[icell - 1].por * interlayer_tortf); - //dum2 = A2 * cell_data[jcell - 1].por_il / - // (cell_data[jcell - 1].por * interlayer_tortf); - //if (dum + dum2 > 0) - //{ - // A_ij_il += dum * dum2 / (dum + dum2); - // A1 /= tort1; - // A2 /= tort2; - // A_ij += (A1 * A2 / (A1 + A2)); - //} -/* end */ - } - } - /* diffuse... */ - J_ij_count_spec = 0; - J_ij_sum = 0.0; - /* - * malloc sufficient space... - */ - k = sol_D[icell].count_spec + sol_D[jcell].count_spec; - - J_ij = (struct J_ij *) free_check_null(J_ij); - J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); - if (J_ij == NULL) - malloc_error(); - - V_M = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); - if (V_M == NULL) - malloc_error(); - - for (i = 0; i < k; i++) - { - J_ij[i].tot1 = 0.0; - V_M[i].grad = 0.0; - V_M[i].D = 0.0; - V_M[i].Dz = 0.0; - V_M[i].Dzc = 0.0; - V_M[i].Dzc_dl = 0.0; - V_M[i].g_dl = 1.0; - V_M[i].o_c = 1; - } - Dz2c = Dz2c_dl = Dz2c_il = 0.0; - - if (il_calcs) - { - /* also for interlayer cations */ - k = sol_D[icell].count_exch_spec + sol_D[jcell].count_exch_spec; - - J_ij_il = (struct J_ij *) free_check_null(J_ij_il); - J_ij_il = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); - if (J_ij_il == NULL) - malloc_error(); - - V_M_il = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); - if (V_M_il == NULL) - malloc_error(); - for (i = 0; i < k; i++) - { - J_ij_il[i].tot1 = 0.0; - V_M_il[i].grad = 0.0; - V_M_il[i].D = 0.0; - V_M_il[i].Dz = 0.0; - V_M_il[i].Dzc = 0.0; - V_M_il[i].Dzc_dl = 0.0; - V_M_il[i].g_dl = 1.0; - V_M_il[i].o_c = 1; - } - } - /* - * coefficients in Eqn (1)... - */ - i = j = k = k_il = 0; - i_max = sol_D[icell].count_spec; - j_max = sol_D[jcell].count_spec; - - while (i < i_max || j < j_max) - { - if (j == j_max - || (i < i_max - && strcmp(sol_D[icell].spec[i].name, - sol_D[jcell].spec[j].name) < 0)) - { - /* species 'name' is only in icell */ - if (il_calcs && sol_D[icell].spec[i].type == EX) - { - J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); - V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; - V_M_il[k_il].z = sol_D[icell].spec[i].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * sol_D[icell].spec[i].c * cec12 / (2 * - V_M_il - [k_il]. - z); - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ - k_il++; - } - else - { - J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); - V_M[k].D = sol_D[icell].spec[i].Dwt; - V_M[k].z = sol_D[icell].spec[i].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = V_M[k].Dz * sol_D[icell].spec[i].c / 2; - if (dl_s > 0) - { - s_charge_ptr = - (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - for (l = 0; l < s_charge_ptr->count_g; l++) - { - if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) - == TRUE) - { - if (only_counter) - { - if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) - || (s_charge_ptr->la_psi > 0 - && V_M[k].z > 0)) - { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - V_M[k].g_dl = 1.0; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2; - } - } - else - { - if (dl_aq1 > 0) - { - V_M[k].g_dl = - (1 + - s_charge_ptr->g[l].g * aq1 / - dl_aq1) * - sol_D[icell].spec[i].erm_ddl; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2 * V_M[k].g_dl; - } - else - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2; - } - break; - } - } - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; - } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ - k++; - } - if (i < i_max) - i++; - } - else if (i == i_max - || (j < j_max - && strcmp(sol_D[icell].spec[i].name, - sol_D[jcell].spec[j].name) > 0)) - { - /* species 'name' is only in jcell */ - if (il_calcs && sol_D[jcell].spec[j].type == EX) - { - J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); - V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; - V_M_il[k_il].z = sol_D[jcell].spec[j].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * sol_D[jcell].spec[j].c * cec12 / (2 * - V_M_il - [k_il]. - z); - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = sol_D[jcell].spec[j].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ - k_il++; - } - else - { - J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); - V_M[k].D = sol_D[jcell].spec[j].Dwt; - V_M[k].z = sol_D[jcell].spec[j].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = V_M[k].Dz * sol_D[jcell].spec[j].c / 2; - if (dl_s > 0) - { - s_charge_ptr = - (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - for (l = 0; l < s_charge_ptr->count_g; l++) - { - if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) - == TRUE) - { - if (only_counter) - { - if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) - || (s_charge_ptr->la_psi > 0 - && V_M[k].z > 0)) - { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - V_M[k].g_dl = 1.0; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2; - } - } - else - { - if (dl_aq2 > 0) - { - V_M[k].g_dl = - (1 + - s_charge_ptr->g[l].g * aq2 / - dl_aq2) * - sol_D[jcell].spec[j].erm_ddl; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2 * V_M[k].g_dl; - } - else - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2; - } - break; - } - } - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; - } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ - k++; - } - if (j < j_max) - j++; - } - else if (strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) - == 0) - { - /* species 'name' is in both cells */ - if (il_calcs && sol_D[icell].spec[i].type == EX) - { - J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); - if (sol_D[icell].spec[i].Dwt == 0 - || sol_D[jcell].spec[j].Dwt == 0) - V_M_il[k_il].D = 0.0; - else - V_M_il[k_il].D = - (sol_D[icell].spec[i].Dwt + - sol_D[jcell].spec[j].Dwt) / 2; - - V_M_il[k_il].z = sol_D[icell].spec[i].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + - sol_D[jcell].spec[j].c * cec2) / (2 * - V_M_il - [k_il]. - z); - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ - k_il++; - } - else - { - J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); - if (sol_D[icell].spec[i].Dwt == 0 - || sol_D[jcell].spec[j].Dwt == 0) - V_M[k].D = 0.0; - else - V_M[k].D = - (sol_D[icell].spec[i].Dwt + - sol_D[jcell].spec[j].Dwt) / 2; - - V_M[k].z = sol_D[icell].spec[i].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = - V_M[k].Dz * (sol_D[icell].spec[i].c + - sol_D[jcell].spec[j].c) / 2; - /* Dzc[k] = Dz[k] * (sol_D[icell].spec[i].c > sol_D[jcell].spec[j].c ? sol_D[icell].spec[i].c : sol_D[jcell].spec[j].c); - */ - if (dl_s > 0) - { - c_dl = 0.0; - if (dl_aq1 > 0) - { - for (l = 0; l < s_charge_ptr1->count_g; l++) - { - if (equal - (s_charge_ptr1->g[l].charge, V_M[k].z, - G_TOL) == TRUE) - { - if (only_counter) - { - if ((s_charge_ptr1->la_psi < 0 - && V_M[k].z < 0) - || (s_charge_ptr1->la_psi > 0 - && V_M[k].z > 0)) - { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - V_M[k].g_dl = 1.0; - c_dl = sol_D[icell].spec[i].c / 2; - } - } - else - { - V_M[k].g_dl = - (1 + - s_charge_ptr1->g[l].g * aq1 / - dl_aq1) * - sol_D[icell].spec[i].erm_ddl; - c_dl = - sol_D[icell].spec[i].c / 2 * - V_M[k].g_dl; - } - break; - } - } - } - else - c_dl = sol_D[icell].spec[i].c / 2; - - if (dl_aq2 > 0) - { - for (l = 0; l < s_charge_ptr2->count_g; l++) - { - if (equal - (s_charge_ptr2->g[l].charge, V_M[k].z, - G_TOL) == TRUE) - { - if (only_counter) - { - if ((s_charge_ptr2->la_psi < 0 - && V_M[k].z < 0) - || (s_charge_ptr2->la_psi > 0 - && V_M[k].z > 0)) - { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - dum = 1.0; - c_dl += - sol_D[jcell].spec[j].c / 2 * dum; - V_M[k].g_dl = - (V_M[k].g_dl + dum) / 2; - } - } - else - { - dum = - (1 + - s_charge_ptr2->g[l].g * aq2 / - dl_aq2) * - sol_D[jcell].spec[j].erm_ddl; - c_dl += sol_D[jcell].spec[j].c / 2 * dum; - V_M[k].g_dl = (V_M[k].g_dl + dum) / 2; - } - break; - } - } - } - else if (V_M[k].o_c == 1) - c_dl += sol_D[jcell].spec[j].c / 2; - - V_M[k].Dzc_dl = V_M[k].Dz * c_dl; - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; - } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = - (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); - ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; - if (fabs(ddlm) > 1e-10) - V_M[k].grad *= - (1 + - (sol_D[jcell].spec[j].lg - - sol_D[icell].spec[i].lg) / ddlm); - k++; - } - if (i < i_max) - i++; - if (j < j_max) - j++; - } - } - /* - * fill in J_ij... - */ - if (Dz2c == 0) - k = 0; - J_ij_count_spec = i_max = k; - J_ij_sum = 0; - c = c_dl = 0.0; - for (i = 0; i < i_max; i++) - { - c += V_M[i].Dz * V_M[i].grad; - c_dl += V_M[i].o_c * V_M[i].Dz * V_M[i].g_dl * V_M[i].grad; - } - for (i = 0; i < i_max; i++) - { - J_ij[i].tot1 = -V_M[i].D * V_M[i].grad + c * V_M[i].Dzc / Dz2c; - J_ij[i].tot1 *= (1 - dl_s); - if (Dz2c_dl > 0) - { - dum = - (-V_M[i].D * V_M[i].g_dl * V_M[i].grad + - c_dl * V_M[i].Dzc_dl / Dz2c_dl) * (2 / (visc1 + visc2)); - if ((J_ij[i].tot1 <= 0 && dum <= 0) - || (J_ij[i].tot1 > 0 && dum > 0)) - { - J_ij[i].tot1 += V_M[i].o_c * dum * dl_s; - } - } - /* - * multiply with timestep... - * for stagnant, DDt = 1, the timestep is in mixf. - * NOTE (for stagnant). The timestep calculated in init_mix for MCD (by PHREEQC) must be equal - * or smaller than the timestep taken (by the user) for calculating mixf in MIX. - * Make this timestep small enough, consider the largest Dw in phreeqd.dat (usually H+). - * Dw used for calculating mixf must be given as default_Dw in the input file. - */ - if (stagnant) - J_ij[i].tot1 *= mixf; - else - J_ij[i].tot1 *= A_ij * DDt; - J_ij_sum += V_M[i].z * J_ij[i].tot1; - J_ij[i].tot2 = J_ij[i].tot1; - } - /* - * calculate interlayer mass transfer... - */ - if (il_calcs && Dz2c_il != 0 && k_il > 0) - { - ex_ptr1 = exchange_bsearch(icell, &i); - ex_ptr2 = exchange_bsearch(jcell, &i); - c = 0.0; - i_max = k_il; - for (i = 0; i < i_max; i++) - c += V_M_il[i].Dz * V_M_il[i].grad; - for (i = 0; i < i_max; i++) - { - J_ij_il[i].tot1 = -V_M_il[i].D * V_M_il[i].grad + - c * V_M_il[i].Dzc / Dz2c_il; - if (stagnant) - J_ij_il[i].tot1 *= mixf_il; - else - J_ij_il[i].tot1 *= A_ij_il * DDt; - J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; - J_ij_il[i].tot2 = J_ij_il[i].tot1; - } - - /* express the transfer in elemental moles... */ - tot1_h = tot1_o = tot2_h = tot2_o = 0.0; - m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * - sizeof(struct M_S)); - if (m_s == NULL) - malloc_error(); - for (i1 = 0; i1 < count_elements; i1++) - { - m_s[i1].name = NULL; - m_s[i1].tot1 = 0; - m_s[i1].tot2 = 0; - } - count_m_s = 0; - fill_m_s(J_ij_il, k_il); - - /* do the mass transfer... */ - if (icell > 0 || stagnant) - { - for (k = 0; k < ex_ptr1->count_comps; k++) - { - i_max = 0; - for (i = 0;; i++) - { - if (ex_ptr1->comps[k].totals[i].elt == NULL) - break; - if (strcmp("X", ex_ptr1->comps[k].totals[i].elt->name) == - 0) - i_max = 1; - } - if (i_max) - break; - } - if (k < ex_ptr1->count_comps) - { - /* transfer O and H... */ - for (i = 0;; i++) - { - if (ex_ptr1->comps[k].totals[i].elt == NULL) - break; - if (strcmp("H", ex_ptr1->comps[k].totals[i].elt->name) == - 0) - { - if (ex_ptr1->comps[k].totals[i].coef < rc1 * tot1_h) - { - tot1_h -= ex_ptr1->comps[k].totals[i].coef; - ex_ptr1->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_h; - tot1_h *= (1 - rc1); - } - } - else if (strcmp - ("O", - ex_ptr1->comps[k].totals[i].elt->name) == 0) - { - if (ex_ptr1->comps[k].totals[i].coef < rc1 * tot1_o) - { - tot1_o -= ex_ptr1->comps[k].totals[i].coef; - ex_ptr1->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_o; - tot1_o *= (1 - rc1); - } - } - } - /* transfer other elements... */ - j_max = 0; /* if j_max turns true, reallocate the exchange structure */ - for (j = 0; j < count_m_s; j++) - { - i_max = 0; - for (i = 0;; i++) - { - if (ex_ptr1->comps[k].totals[i].elt == NULL) - { - i_max = i; - break; - } - if (strcmp - (m_s[j].name, - ex_ptr1->comps[k].totals[i].elt->name) == 0) - break; - } - if (i_max) - { - /* new exchange element must be added... */ - ex_ptr1->comps[k].totals = - (struct elt_list *) PHRQ_realloc(ex_ptr1-> - comps[k].totals, - (size_t) (i + - 2) * - sizeof(struct - elt_list)); - ex_ptr1->comps[k].formula_totals = - (struct elt_list *) PHRQ_realloc(ex_ptr1-> - comps[k]. - formula_totals, - (size_t) (i + - 2) * - sizeof(struct - elt_list)); - /* fill in new element, next = NULL */ - ex_ptr1->comps[k].totals[i].elt = - element_store(m_s[j].name); - ex_ptr1->comps[k].totals[i + 1].elt = NULL; - - j_max = i_max; - } - /* rc1 part goes to exchange species... */ - if (ex_ptr1->comps[k].totals[i].coef < rc1 * m_s[j].tot1) - { - m_s[j].tot1 -= ex_ptr1->comps[k].totals[i].coef; - ex_ptr1->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr1->comps[k].totals[i].coef -= rc1 * m_s[j].tot1; - m_s[j].tot1 *= (1 - rc1); - } - } - if (j_max) - { - qsort(ex_ptr1->comps[k].totals, (size_t) j_max + 1, - (size_t) sizeof(struct elt_list), elt_list_compare); - } - } - } - if (icell < count_cells || stagnant) - { - for (k = 0; k < ex_ptr2->count_comps; k++) - { - i_max = 0; - for (i = 0;; i++) - { - if (ex_ptr2->comps[k].totals[i].elt == NULL) - break; - if (strcmp("X", ex_ptr2->comps[k].totals[i].elt->name) == - 0) - i_max = 1; - } - if (i_max) - break; - } - if (k < ex_ptr2->count_comps) - { - /* transfer O and H... */ - for (i = 0;; i++) - { - if (ex_ptr2->comps[k].totals[i].elt == NULL) - break; - if (strcmp("H", ex_ptr2->comps[k].totals[i].elt->name) == - 0) - { - if (ex_ptr2->comps[k].totals[i].coef < -rc2 * tot2_h) - { - tot2_h += ex_ptr2->comps[k].totals[i].coef; - ex_ptr2->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_h; - tot2_h *= (1 - rc2); - } - } - else if (strcmp - ("O", - ex_ptr2->comps[k].totals[i].elt->name) == 0) - { - if (ex_ptr2->comps[k].totals[i].coef < -rc2 * tot2_o) - { - tot2_o += ex_ptr2->comps[k].totals[i].coef; - ex_ptr2->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_o; - tot2_o *= (1 - rc2); - } - } - } - /* transfer other elements... */ - j_max = 0; /* if j_max turns true, reallocate the exchange structure */ - for (j = 0; j < count_m_s; j++) - { - i_max = 0; - for (i = 0;; i++) - { - if (ex_ptr2->comps[k].totals[i].elt == NULL) - { - i_max = i; - break; - } - if (strcmp - (m_s[j].name, - ex_ptr2->comps[k].totals[i].elt->name) == 0) - break; - } - if (i_max) - { - /* new exchange element must be added... */ - ex_ptr2->comps[k].totals = - (struct elt_list *) PHRQ_realloc(ex_ptr2-> - comps[k].totals, - (size_t) (i + - 2) * - sizeof(struct - elt_list)); - ex_ptr2->comps[k].formula_totals = - (struct elt_list *) PHRQ_realloc(ex_ptr2-> - comps[k]. - formula_totals, - (size_t) (i + - 2) * - sizeof(struct - elt_list)); - /* fill in new element, next = NULL */ - ex_ptr2->comps[k].totals[i].elt = - element_store(m_s[j].name); - ex_ptr2->comps[k].totals[i].coef = 0.0; - ex_ptr2->comps[k].totals[i + 1].elt = NULL; - - j_max = i_max; - } - /* rc2 part goes to exchange species... */ - if (ex_ptr2->comps[k].totals[i].coef < -rc2 * m_s[j].tot2) - { - m_s[j].tot2 += ex_ptr2->comps[k].totals[i].coef; - ex_ptr2->comps[k].totals[i].coef = 0; - } - else - { - ex_ptr2->comps[k].totals[i].coef += rc2 * m_s[j].tot2; - m_s[j].tot2 *= (1 - rc2); - } - } - if (j_max) - { - qsort(ex_ptr2->comps[k].totals, (size_t) j_max + 1, - (size_t) sizeof(struct elt_list), elt_list_compare); - } - } - } - } - /* appt 3 July 07, improved convergence without transporting charge imbalance */ - J_ij_sum = 0; - V_M = (struct V_M *) free_check_null(V_M); - if (il_calcs) - V_M_il = (struct V_M *) free_check_null(V_M_il); - return (il_calcs); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: disp_surf(LDBLE DDt) @@ -4635,60 +3183,30 @@ disp_surf(LDBLE DDt) * step 2a. Dispersive mixing of mobile surfaces from column cells i2 < i1... */ if (i1 <= count_cells) - //mix_ptr = &mix[count_mix - count_cells + i1 - 1]; mix_ptr = Utilities::Rxn_find(Dispersion_mix_map, i1); else - //mix_ptr = &mix[count_mix - 1]; mix_ptr = Utilities::Rxn_find(Dispersion_mix_map, count_cells); - //std::map::const_iterator cit; - //for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) std::vector num; std::vector frac; mix_ptr->Vectorize(num, frac); for(size_t i3 = 0; i3 < num.size(); i3++) - //for (j = 0; j < mix_ptr->count_comps; j++) { if (i1 <= count_cells) { - //if (mix_ptr->comps[j].n_solution == i2) - //if (cit->first == i2) if (num[i3] == i2) { - //mixf = mixf_store = mix_ptr->comps[j].fraction; - //mixf = mixf_store = cit->second; mixf = mixf_store = frac[i3]; break; } } - //else if (mix_ptr->comps[j].n_solution == i1) - //else if (cit->first == i1) else if (num[i3] == i1) { - //mixf = mixf_store = mix_ptr->comps[j].fraction; - //mixf = mixf_store = cit->second; mixf = mixf_store = frac[i3]; break; } } -#ifdef SKIP - for (j = 0; j < mix_ptr->count_comps; j++) - { - if (i1 <= count_cells) - { - if (mix_ptr->comps[j].n_solution == i2) - { - mixf = mixf_store = mix_ptr->comps[j].fraction; - break; - } - } - else if (mix_ptr->comps[j].n_solution == i1) - { - mixf = mixf_store = mix_ptr->comps[j].fraction; - break; - } - } -#endif + /* step 1b. If cell i1 has no surface, get the mobile comps from surface i2... */ if (surface[n1].n_user == -99) { diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index 66b90827..dc553828 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -45,20 +45,6 @@ add_elt_list(const cxxNameDouble & nd, LDBLE coef) elt_list[count_elts].coef = cit->second * coef; count_elts++; } -#ifdef SKIP - for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; - elt_list_ptr1++) - { - if (count_elts >= max_elts) - { - space((void **) ((void *) &elt_list), count_elts, &max_elts, - sizeof(struct elt_list)); - } - elt_list[count_elts].elt = elt_list_ptr1->elt; - elt_list[count_elts].coef = elt_list_ptr1->coef * coef; - count_elts++; - } -#endif return (OK); } From dd06c2eaf2cf8348fc0a2f6d332e80cf4be464fd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jan 2012 00:56:16 +0000 Subject: [PATCH 0430/1077] Runs most kinetics, kinsurf is a problem. git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6084 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 17 +- KineticsComp.h | 24 +- PHRQ_io.cpp | 1 + Phreeqc.cpp | 22 +- Phreeqc.h | 22 +- Reaction.cxx | 2 +- Reaction.h | 2 +- ReadClass.cxx | 64 +- Use.h | 7 +- cxxKinetics.cxx | 454 ++++++++- cxxKinetics.h | 40 +- phreeqc/advection.cpp | 5 +- phreeqc/basicsubs.cpp | 26 +- phreeqc/global_structures.h | 3 +- phreeqc/kinetics.cpp | 1737 ++++++++++++++++++++++++++++++++++- phreeqc/mainsubs.cpp | 124 ++- phreeqc/print.cpp | 403 +++++++- phreeqc/read.cpp | 497 +++++++++- phreeqc/step.cpp | 62 +- phreeqc/structures.cpp | 76 +- phreeqc/tally.cpp | 217 ++++- phreeqc/tidy.cpp | 370 +++++++- phreeqc/transport.cpp | 26 +- 23 files changed, 3973 insertions(+), 228 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 9d2c9162..7dc3edf0 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -27,12 +27,13 @@ PHRQ_base(io) // { tol = 1e-8; - m = 0.0; - m0 = 0.0; + m = -1; + m0 = -1; moles = 0.0; + initial_moles = 0; namecoef.type = cxxNameDouble::ND_NAME_COEF; } - +#ifdef SKIP cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr, PHRQ_io *io) // // constructor for cxxKineticsComp from struct kinetics_comp @@ -51,7 +52,7 @@ namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) this->d_params.push_back(kinetics_comp_ptr->d_params[i]); } } - +#endif cxxKineticsComp::~cxxKineticsComp() { } @@ -118,8 +119,8 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const // Kinetics_Comp element and attributes - s_oss << indent0 << "-rate_name " << this-> - rate_name << "\n"; + //s_oss << indent0 << "-rate_name " << this-> + // rate_name << "\n"; s_oss << indent1 << "-tol " << this->tol << "\n"; s_oss << indent1 << "-m " << this->m << "\n"; s_oss << indent1 << "-m0 " << this->m0 << "\n"; @@ -160,7 +161,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) if (vopts.empty()) { vopts.reserve(10); - vopts.push_back("rate_name"); // 0 + vopts.push_back("rate_name_not_used"); // 0 vopts.push_back("tol"); // 1 vopts.push_back("m"); // 2 vopts.push_back("m0"); // 3 @@ -205,7 +206,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; - case 0: // rate_name + case 0: // rate_name not used if (!(parser.get_iss() >> str)) { this->rate_name.clear(); diff --git a/KineticsComp.h b/KineticsComp.h index 231f4cb5..3ab179b1 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -35,12 +35,20 @@ public: this->rate_name.clear(); } - const cxxNameDouble &Get_namecoef(void) const {return namecoef;}; - LDBLE Get_tol(void) const {return tol;}; - LDBLE Get_m(void) const {return m;}; - LDBLE Get_m0(void) const {return m0;}; - LDBLE Get_moles(void) const {return moles;}; - const std::vector < LDBLE > &Get_d_params(void) const {return d_params;}; + cxxNameDouble &Get_namecoef(void) {return namecoef;} + void Set_namecoef(const cxxNameDouble nd) {namecoef = nd;} + LDBLE Get_tol(void) const {return tol;} + void Set_tol(LDBLE t) {tol = t;} + LDBLE Get_m(void) const {return m;} + void Set_m(LDBLE t) {m = t;} + LDBLE Get_m0(void) const {return m0;} + void Set_m0(LDBLE t) {m0 = t;} + LDBLE Get_moles(void) const {return moles;} + void Set_moles(LDBLE t) {moles = t;} + LDBLE Get_initial_moles(void) const {return initial_moles;} + void Set_initial_moles(LDBLE t) {initial_moles = t;} + std::vector < LDBLE > &Get_d_params(void) {return d_params;}; + std::vector < std::string > &Get_c_params(void) {return c_params;}; #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); @@ -56,7 +64,9 @@ public: LDBLE m; LDBLE m0; LDBLE moles; - std::vector < LDBLE >d_params; + LDBLE initial_moles; + std::vector< LDBLE > d_params; + std::vector< std::string > c_params; public: diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index d43f3be3..74f17cd6 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -75,6 +75,7 @@ output_msg(const char * str) { (*output_ostream) << str; } + output_flush(); } // ---------------------------------------------------------------------- */ // log ostream methods diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 2dc92280..00bec549 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -248,13 +248,23 @@ size_t Phreeqc::list_components(std::list &list_c) } } // kinetics + { + std::map::iterator it = Rxn_kinetics_map.begin(); + for (; it != Rxn_kinetics_map.end(); it++) + { + calc_dummy_kinetic_reaction_tally(&(it->second)); + cxxKinetics entity = it->second; + accumulator.add_extensive(entity.Get_totals(), 1.0); + } + } +#ifdef SKIP for (i = 0; i < count_kinetics; i++) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); cxxKinetics entity(&kinetics[i], phrq_io); accumulator.add_extensive(entity.Get_totals(), 1.0); } - +#endif // Put in all primaries cxxNameDouble::iterator it; for (it = accumulator.begin(); it != accumulator.end(); it++) @@ -328,7 +338,7 @@ void Phreeqc::init(void) //max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; + //max_kinetics = MAX_PP_ASSEMBLAGE; //max_ss_assemblage = MAX_PP_ASSEMBLAGE; max_elements = MAX_ELEMENTS; @@ -348,7 +358,7 @@ void Phreeqc::init(void) //count_exchange = 0; count_surface = 0; //count_gas_phase = 0; - count_kinetics = 0; + //count_kinetics = 0; //count_ss_assemblage = 0; count_elements = 0; @@ -400,7 +410,7 @@ void Phreeqc::init(void) //exchange = 0; surface = 0; //gas_phase = 0; - kinetics = 0; + //kinetics = 0; //ss_assemblage = 0; cell_data = 0; elements = 0; @@ -554,7 +564,7 @@ void Phreeqc::init(void) initial_total_time = 0; rate_m = 0; rate_m0 = 0; - rate_p = NULL; + //rate_p = NULL; rate_time = 0; rate_sim_time_start = 0; rate_sim_time_end = 0; @@ -718,7 +728,7 @@ void Phreeqc::init(void) //dbg_exchange = exchange; dbg_surface = surface; //dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; + //dbg_kinetics = kinetics; //dbg_irrev = irrev; //dbg_mix = mix; dbg_master = master; diff --git a/Phreeqc.h b/Phreeqc.h index 65eb5a5c..19df3991 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -390,8 +390,8 @@ public: realtype uround, void *jac_data, long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - int calc_final_kinetic_reaction(struct kinetics *kinetics_ptr); - int calc_kinetic_reaction(struct kinetics *kinetics_ptr, + int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); + int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step); int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction); @@ -825,7 +825,7 @@ public: //int add_exchange(struct exchange *exchange_ptr); int add_exchange(cxxExchange *exchange_ptr); int add_gas_phase(cxxGasPhase *gas_phase_ptr); - int add_kinetics(struct kinetics *kinetics_ptr); + int add_kinetics(cxxKinetics *kinetics_ptr); //int add_mix(struct mix *mix_ptr); int add_mix(cxxMix * mix_ptr); //int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); @@ -872,6 +872,7 @@ public: struct inverse *inverse_search(int n_user, int *n); int inverse_sort(void); public: +#ifdef SKIP struct kinetics *kinetics_alloc(void); struct kinetics *kinetics_bsearch(int k, int *n); protected: @@ -895,6 +896,8 @@ protected: int n_user_new); struct kinetics *kinetics_search(int n_user, int *n, int print); int kinetics_sort(void); +#endif +protected: struct logk *logk_alloc(void); int logk_copy2orig(struct logk *logk_ptr); struct logk *logk_store(char *name, int replace_if_found); @@ -1050,8 +1053,8 @@ public: // convert class to struct (structures.cpp) //struct mix * cxxMix2mix(const cxxMix *mx); - struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); - struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); + //struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); + //struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); //struct exchange * cxxExchange2exchange(const cxxExchange * ex); //struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); //struct master * Get_exch_master(const cxxExchComp * ec); @@ -1084,7 +1087,7 @@ public: /* tally.cpp */ void add_all_components_tally(void); int build_tally_table(void); - int calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr); + int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); int diff_tally_table(void); int extend_tally_table(void); int free_tally_table(void); @@ -1293,11 +1296,13 @@ protected: /* ---------------------------------------------------------------------- * Kinetics * ---------------------------------------------------------------------- */ - + std::map Rxn_kinetics_map; +#ifdef SKIP struct kinetics *kinetics; struct kinetics *dbg_kinetics; int count_kinetics; int max_kinetics; +#endif int count_save_values; struct save_values *save_values; @@ -1622,8 +1627,9 @@ protected: struct rate *rates; int count_rates; - LDBLE rate_m, rate_m0, *rate_p, rate_time, rate_sim_time_start, + LDBLE rate_m, rate_m0, /* *rate_p, */ rate_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + std::vector rate_p; int count_rate_p; /* ---------------------------------------------------------------------- * USER PRINT COMMANDS diff --git a/Reaction.cxx b/Reaction.cxx index 4a8e19c2..1da3832b 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -307,7 +307,7 @@ cxxReaction::read_raw(CParser & parser, const bool check) } } int cxxReaction:: -Get_actualSteps(void) const +Get_reaction_steps(void) const { if (equalIncrements) { diff --git a/Reaction.h b/Reaction.h index 99676f9e..ca404ebc 100644 --- a/Reaction.h +++ b/Reaction.h @@ -27,7 +27,7 @@ class cxxReaction:public cxxNumKeyword cxxNameDouble &Get_reactantList(void) {return this->reactantList;} std::vector < LDBLE > &Get_steps(void) {return this->steps;} void Set_steps(std::vector &v) {steps = v;} - int Get_actualSteps(void) const; + int Get_reaction_steps(void) const; int Get_countSteps(void) const {return this->countSteps;} void Set_countSteps(int i) {countSteps = i;} bool Get_equalIncrements(void) const {return this->equalIncrements;} diff --git a/ReadClass.cxx b/ReadClass.cxx index db44a425..74c2a39c 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -207,6 +207,7 @@ read_surface_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_raw(void) @@ -298,6 +299,7 @@ read_kinetics_raw(void) if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -630,6 +632,7 @@ read_surface_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics_modify(void) @@ -718,6 +721,7 @@ read_kinetics_modify(void) if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: streamify_to_next_keyword(std::istringstream & lines) @@ -932,7 +936,23 @@ delete_entities(void) } } } - // kineticss + // kinetics + if (delete_info.Get_kinetics().Get_defined()) + { + if (delete_info.Get_kinetics().Get_numbers().size() == 0) + { + Rxn_kinetics_map.clear(); + } + else + { + std::set < int >::iterator it; + for (it = delete_info.Get_kinetics().Get_numbers().begin(); it != delete_info.Get_kinetics().Get_numbers().end(); it++) + { + Rxn_kinetics_map.erase(*it); + } + } + } +#ifdef SKIP if (delete_info.Get_kinetics().Get_defined()) { if (delete_info.Get_kinetics().Get_numbers().size() == 0) @@ -954,6 +974,7 @@ delete_entities(void) } } } +#endif // mixes if (delete_info.Get_mix().Get_defined()) { @@ -1029,9 +1050,9 @@ run_as_cells(void) { struct save save_data; LDBLE kin_time; - int count_steps, use_mix, m; + int count_steps, use_mix; char token[2 * MAX_LENGTH]; - struct kinetics *kinetics_ptr; + //struct kinetics *kinetics_ptr; state = REACTION; if (run_info.Get_cells().Get_numbers().size() == 0 || @@ -1069,14 +1090,14 @@ run_as_cells(void) count_steps = 1; if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { - int count = ((cxxReaction *) use.Get_reaction_ptr())->Get_actualSteps(); + int count = ((cxxReaction *) use.Get_reaction_ptr())->Get_reaction_steps(); if (count > count_steps) count_steps = count; } if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) { - if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) - count_steps = abs(use.Get_kinetics_ptr()->count_steps); + if (use.Get_kinetics_ptr()->Get_reaction_steps() > count_steps) + count_steps = use.Get_kinetics_ptr()->Get_reaction_steps(); } if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) { @@ -1138,6 +1159,10 @@ run_as_cells(void) // runner kin_time not defined else { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); + kin_time = kinetics_ptr->Current_step((incremental_reactions==TRUE), reaction_step); + +#ifdef SKIP kinetics_ptr = kinetics_bsearch(-2, &m); if (incremental_reactions == FALSE) { @@ -1191,6 +1216,7 @@ run_as_cells(void) } } } +#endif } } if (incremental_reactions == FALSE || @@ -1232,7 +1258,8 @@ run_as_cells(void) memcpy(&save, &save_data, sizeof(struct save)); if (use.Get_kinetics_in() == TRUE) { - kinetics_duplicate(-2, use.Get_n_kinetics_user()); + //kinetics_duplicate(-2, use.Get_n_kinetics_user()); + Utilities::Rxn_copy(Rxn_kinetics_map, -2, use.Get_n_kinetics_user()); } saver(); } @@ -1387,6 +1414,27 @@ dump_ostream(std::ostream& os) } // kinetics + if (dump_info.Get_bool_kinetics()) + { + if (dump_info.Get_kinetics().size() == 0) + { + Utilities::Rxn_dump_raw(Rxn_kinetics_map, os, 0); + } + else + { + std::set < int >::iterator it; + for (it = dump_info.Get_kinetics().begin(); it != dump_info.Get_kinetics().end(); it++) + { + cxxKinetics *p = Utilities::Rxn_find(Rxn_kinetics_map, *it); + + if (p != NULL) + { + p->dump_raw(os, 0); + } + } + } + } +#ifdef SKIP if (dump_info.Get_bool_kinetics()) { if (dump_info.Get_kinetics().size() == 0) @@ -1411,7 +1459,7 @@ dump_ostream(std::ostream& os) } } } - +#endif // mix if (dump_info.Get_bool_mix()) { diff --git a/Use.h b/Use.h index db3455ab..ae00f9e3 100644 --- a/Use.h +++ b/Use.h @@ -8,6 +8,7 @@ class cxxGasPhase; class cxxPressure; class cxxTemperature; class cxxSSassemblage; +class cxxKinetics; class cxxUse { @@ -79,7 +80,7 @@ public: cxxMix * Get_mix_ptr(void) const {return this->mix_ptr;} cxxReaction * Get_reaction_ptr(void) const {return this->reaction_ptr;} cxxExchange * Get_exchange_ptr(void) const {return this->exchange_ptr;} - struct kinetics * Get_kinetics_ptr(void) const {return this->kinetics_ptr;} + cxxKinetics * Get_kinetics_ptr(void) const {return this->kinetics_ptr;} struct surface * Get_surface_ptr(void) const {return this->surface_ptr;} cxxPressure * Get_pressure_ptr(void) const {return this->pressure_ptr;} cxxTemperature * Get_temperature_ptr(void) const {return this->temperature_ptr;} @@ -92,7 +93,7 @@ public: void Set_mix_ptr(cxxMix * p) {this->mix_ptr = p;} void Set_reaction_ptr(cxxReaction * p) {this->reaction_ptr = p;} void Set_exchange_ptr(cxxExchange * p) {this->exchange_ptr = p;} - void Set_kinetics_ptr(struct kinetics * p) {this->kinetics_ptr = p;} + void Set_kinetics_ptr(cxxKinetics * p) {this->kinetics_ptr = p;} void Set_surface_ptr(struct surface * p) {this->surface_ptr = p;} void Set_pressure_ptr(cxxPressure * p) {this->pressure_ptr = p;} void Set_temperature_ptr(cxxTemperature * p) {this->temperature_ptr = p;} @@ -124,7 +125,7 @@ protected: bool kinetics_in; int n_kinetics_user; - struct kinetics *kinetics_ptr; + cxxKinetics *kinetics_ptr; bool surface_in; int n_surface_user; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 4497b598..0a43303a 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -35,9 +35,10 @@ cxxKinetics::cxxKinetics(PHRQ_io *io) cvode_steps = 100; cvode_order = 5; totals.type = cxxNameDouble::ND_ELT_MOLES; - equal_steps = 0; + equalIncrements = false; + count = 0; } - +#ifdef SKIP cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr, PHRQ_io *io) // // constructor for cxxKinetics from struct kinetics @@ -80,6 +81,7 @@ totals(kinetics_ptr->totals) this->steps.push_back(kinetics_ptr->steps[i]); } } +#endif cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) @@ -186,26 +188,32 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co s_oss << "-cvode_order " << this->cvode_order << "\n"; // kineticsComps structures - for (std::list < cxxKineticsComp >::const_iterator it = - kineticsComps.begin(); it != kineticsComps.end(); ++it) + + //for (std::list < cxxKineticsComp >::const_iterator it = + // kineticsComps.begin(); it != kineticsComps.end(); ++it) + for (size_t k = 0; k < this->kinetics_comps.size(); k++) { s_oss << indent1; - s_oss << "-component" << "\n"; - (*it).dump_raw(s_oss, indent + 2); + s_oss << "-component " << this->kinetics_comps[k].Get_rate_name() << "\n"; + this->kinetics_comps[k].dump_raw(s_oss, indent + 2); } // totals s_oss << indent1; - s_oss << "-totals " << "\n"; + s_oss << "-totals " << "\n"; this->totals.dump_raw(s_oss, indent + 2); // equal_steps s_oss << indent1; - s_oss << "-equal_steps " << this->equal_steps << "\n"; + s_oss << "-equalIncrements " << this->equalIncrements << "\n"; + + // equal_steps + s_oss << indent1; + s_oss << "-count " << this->count << "\n"; // steps s_oss << indent1; - s_oss << "-steps " << "\n"; + s_oss << "-steps " << "\n"; { int i = 0; s_oss << indent2; @@ -224,7 +232,295 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co } return; } +void +cxxKinetics::read_raw(CParser & parser, bool check) +{ + LDBLE d; + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(15); + vopts.push_back("step_divide"); + vopts.push_back("rk"); + vopts.push_back("bad_step_max"); + vopts.push_back("use_cvode"); + vopts.push_back("component"); + vopts.push_back("totals"); + vopts.push_back("steps"); + vopts.push_back("cvode_steps"); + vopts.push_back("cvode_order"); + vopts.push_back("equalIncrements"); + vopts.push_back("count"); + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + bool useLastLine(false); + std::vector < LDBLE > temp_steps; + + // Read kinetics number and description + this->read_number_description(parser); + + opt_save = CParser::OPT_ERROR; + bool step_divide_defined(false); + bool rk_defined(false); + bool bad_step_max_defined(false); + bool use_cvode_defined(false); + bool cvode_steps_defined(false); + bool cvode_order_defined(false); + bool steps_defined(false); + bool equalIncrements_defined(false); + bool count_defined(false); + + for (;;) + { + int opt; + if (useLastLine == false) + { + opt = parser.get_option(vopts, next_char); + } + else + { + opt = parser.getOptionFromLastLine(vopts, next_char, true); + } + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + useLastLine = false; + 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 KINETICS_COMP_RAW keyword.", + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + break; + + case 0: // step_divide + if (!(parser.get_iss() >> this->step_divide)) + { + this->step_divide = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for step_divide.", + PHRQ_io::OT_CONTINUE); + } + step_divide_defined = true; + break; + + case 1: // rk + if (!(parser.get_iss() >> this->rk)) + { + this->rk = 3; + parser.incr_input_error(); + parser.error_msg("Expected integer value for rk.", + PHRQ_io::OT_CONTINUE); + } + rk_defined = true; + break; + + case 2: // bad_step_max + if (!(parser.get_iss() >> this->bad_step_max)) + { + this->bad_step_max = 500; + parser.incr_input_error(); + parser.error_msg("Expected integer value for bad_step_max.", + PHRQ_io::OT_CONTINUE); + } + bad_step_max_defined = true; + break; + + case 3: // use_cvode + if (!(parser.get_iss() >> this->use_cvode)) + { + this->use_cvode = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for use_cvode.", + PHRQ_io::OT_CONTINUE); + } + use_cvode_defined = true; + break; + + case 4: // component + { + std::string str; + if (!(parser.get_iss() >> str)) + { + parser.incr_input_error(); + parser.error_msg("Expected string value for component name.", + PHRQ_io::OT_CONTINUE); + } + else + { + cxxKineticsComp temp_comp(this->io); + temp_comp.Set_rate_name(str.c_str()); + cxxKineticsComp *comp_ptr = this->Find(str); + if (comp_ptr) + { + temp_comp = *comp_ptr; + } + temp_comp.read_raw(parser, false); + if (comp_ptr) + { + for (size_t j = 0; j < this->kinetics_comps.size(); j++) + { + if (Utilities::strcmp_nocase(this->kinetics_comps[j].Get_rate_name().c_str(), str.c_str()) == 0) + { + this->kinetics_comps[j] = temp_comp; + } + } + } + else + { + this->kinetics_comps.push_back(temp_comp); + } + useLastLine = true; + } + } + break; + + case 5: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for KineticsComp totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 5; + break; + + case 6: // steps + while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) + { + //sscanf(token.c_str(), "%lf", &d); + //this->steps.push_back(d); + std::istringstream iss(token); + if (!(iss >> d)) + { + parser.incr_input_error(); + parser.error_msg("Expected numeric value for steps.", + PHRQ_io::OT_CONTINUE); + } + else + { + temp_steps.push_back(d); + steps_defined = true; + } + } + opt_save = 6; + break; + + case 7: // cvode_steps + if (!(parser.get_iss() >> this->cvode_steps)) + { + this->cvode_steps = 100; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_steps.", + PHRQ_io::OT_CONTINUE); + } + cvode_steps_defined = true; + break; + + case 8: // cvode_order + if (!(parser.get_iss() >> this->cvode_order)) + { + this->cvode_order = 5; + parser.incr_input_error(); + parser.error_msg("Expected integer value for cvode_order.", + PHRQ_io::OT_CONTINUE); + } + cvode_order_defined = true; + + break; + case 9: // equalIncrements + if (!(parser.get_iss() >> this->equalIncrements)) + { + this->use_cvode = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for equalIncrements.", + PHRQ_io::OT_CONTINUE); + } + equalIncrements_defined = true; + break; + case 10: // count + if (!(parser.get_iss() >> this->count)) + { + this->count = 0; + parser.incr_input_error(); + parser.error_msg("Expected integer value for count.", + PHRQ_io::OT_CONTINUE); + } + count_defined = true; + break; + + } + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + if (steps_defined) + { + this->steps = temp_steps; + } + if (check) + { + // members that must be defined + if (step_divide_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Step_divide not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (rk_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Rk not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (bad_step_max_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (use_cvode_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (cvode_steps_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (cvode_order_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", + PHRQ_io::OT_CONTINUE); + } + // disable to remain backward compatible with PHAST restart files? + //if (equal_steps_defined == false) + //{ + // parser.incr_input_error(); + // parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", + // PHRQ_io::OT_CONTINUE); + //} + } +} +#ifdef SKIP void cxxKinetics::read_raw(CParser & parser, bool check) { @@ -357,11 +653,12 @@ cxxKinetics::read_raw(CParser & parser, bool check) reread.set_echo_file(CParser::EO_NONE); reread.set_echo_stream(CParser::EO_NONE); - std::list < cxxKineticsComp >::iterator kit; + //std::list < cxxKineticsComp >::iterator kit; bool found = false; - for (kit = this->kineticsComps.begin(); kit != this->kineticsComps.end(); kit++) + size_t k; + for (k = 0; k < this->kineticsComps.size(); k++) { - if (kit->Get_rate_name() == ec.Get_rate_name()) + if (this->kineticsComps[k].Get_rate_name() == ec.Get_rate_name()) { found = true; break; @@ -369,7 +666,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) } if (found) { - kit->read_raw(reread, false); + this->kineticsComps[k].read_raw(reread, false); } else { @@ -523,7 +820,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) //} } } - +#endif #ifdef USE_MPI void cxxKinetics::mpi_pack(std::vector < int >&ints, @@ -603,6 +900,50 @@ cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) if (extensive == 0.0) return; //std::map < std::string, cxxKineticsComp> kineticsComps; + for (size_t i_add = 0; i_add < addee.kinetics_comps.size(); i_add++) + { + bool found(false); + size_t i; + for (i = 0; i < this->kinetics_comps.size(); i++) + { + if (this->kinetics_comps[i].Get_rate_name() == addee.kinetics_comps[i_add].Get_rate_name()) + { + found = true; + break; + } + } + if (found) + { + this->kinetics_comps[i].add(addee.kinetics_comps[i_add], extensive); + } + else + { + cxxKineticsComp entity = addee.kinetics_comps[i_add]; + entity.multiply(extensive); + this->kinetics_comps.push_back(entity); + } + } + this->steps = addee.steps; + this->step_divide = addee.step_divide; + this->rk = addee.rk; + this->bad_step_max = addee.bad_step_max; + this->use_cvode = addee.use_cvode; + this->cvode_steps = addee.cvode_steps; + this->cvode_order = addee.cvode_order; + this->equalIncrements = addee.equalIncrements; + this->count = addee.count; +} +#ifdef SKIP +void +cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) + // + // Add to existing ppassemblage to "this" ppassemblage + // +{ + if (extensive == 0.0) + return; + //std::map < std::string, cxxKineticsComp> kineticsComps; + for (size_t i = 0; i < kineticsComps.size(); i++) for (std::list < cxxKineticsComp >::const_iterator itadd = addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); ++itadd) @@ -645,7 +986,84 @@ cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) this->cvode_order = addee.cvode_order; this->equal_steps = addee.equal_steps; } -//cxxNameDouble & cxxKinetics::get_totals(void) -//{ -// return this->totals; -//} +#endif +cxxKineticsComp * cxxKinetics:: +Find(const std::string &s) +{ + for (size_t i = 0; i < this->kinetics_comps.size(); i++) + { + if (Utilities::strcmp_nocase(this->kinetics_comps[i].Get_rate_name().c_str(), s.c_str()) == 0) + { + return & (this->kinetics_comps[i]); + } + } + return NULL; +} +int cxxKinetics:: +Get_reaction_steps(void) const +{ + if(equalIncrements) + { + return count; + } + return ((int) steps.size()); +} +LDBLE cxxKinetics:: +Current_step(bool incremental_reactions, int reaction_step) const +{ + if (this->steps.size() == 0) + return 1; + LDBLE kin_time = 1; + if (!incremental_reactions) + { + if (!this->equalIncrements) + { + if (reaction_step > (int) this->steps.size()) + { + kin_time = this->steps[this->steps.size() - 1]; + } + else + { + kin_time = this->steps[reaction_step - 1]; + } + } + else + { + if (reaction_step > this->count) + { + kin_time = this->steps[0]; + } + else + { + kin_time = (LDBLE) reaction_step * this->steps[0] / ((LDBLE) (this->count)); + } + } + } + else + { + /* incremental reactions */ + if (!this->equalIncrements) + { + if (reaction_step > (int) this->steps.size()) + { + kin_time = this->steps[this->steps.size() - 1]; + } + else + { + kin_time = this->steps[reaction_step - 1]; + } + } + else + { + if (reaction_step > this->count) + { + kin_time = 0; + } + else + { + kin_time = this->steps[0] / ((LDBLE) (this->count)); + } + } + } + return kin_time; +} \ No newline at end of file diff --git a/cxxKinetics.h b/cxxKinetics.h index e1758f7b..af051407 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -17,7 +17,7 @@ class cxxKinetics:public cxxNumKeyword public: cxxKinetics(PHRQ_io *io=NULL); - cxxKinetics(struct kinetics *, PHRQ_io *io=NULL); + //cxxKinetics(struct kinetics *, PHRQ_io *io=NULL); cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxKinetics(); @@ -31,17 +31,29 @@ class cxxKinetics:public cxxNumKeyword //bool Get_related_phases(void) const; //bool Get_related_rate(void) const; - const std::vector < LDBLE > &Get_steps(void) const {return steps;}; - LDBLE Get_step_divide(void) const {return step_divide;}; + std::vector < LDBLE > &Get_steps(void) {return steps;} + LDBLE Get_step_divide(void) const {return step_divide;} + void Set_step_divide(LDBLE t) {step_divide = t;} int Get_rk(void) const {return rk;}; - int Get_bad_step_max(void) const {return bad_step_max;}; - bool Get_use_cvode(void) const {return use_cvode;}; - int Get_cvode_steps(void) const {return cvode_steps;}; - int Get_cvode_order(void) const {return cvode_order;}; - const std::list < cxxKineticsComp > &Get_kineticsComps(void) const {return kineticsComps;}; - const cxxNameDouble & Get_totals(void) const {return this->totals;}; - int Get_equal_steps(void) const {return equal_steps;}; - + void Set_rk(int t) {rk = t;} + int Get_bad_step_max(void) const {return bad_step_max;} + void Set_bad_step_max(int t) {bad_step_max = t;} + bool Get_use_cvode(void) const {return use_cvode;} + void Set_use_cvode(bool tf) {use_cvode = tf;} + int Get_cvode_steps(void) const {return cvode_steps;} + void Set_cvode_steps(int t) {cvode_steps = t;} + int Get_cvode_order(void) const {return cvode_order;} + void Set_cvode_order(int t) {cvode_order = t;} + std::vector < cxxKineticsComp > &Get_kinetics_comps(void) {return kinetics_comps;} + cxxNameDouble & Get_totals(void) {return this->totals;} + void Set_totals(const cxxNameDouble &nd) {totals = nd;} + bool Get_equalIncrements(void) const {return equalIncrements;} + void Set_equalIncrements(bool tf) {equalIncrements = tf;} + int Get_count(void) const {return count;} + void Set_count(int i) {count = i;} + int Get_reaction_steps(void) const; + cxxKineticsComp * Find(const std::string &str); + LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const; #ifdef USE_MPI void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); @@ -51,9 +63,10 @@ class cxxKinetics:public cxxNumKeyword void add(const cxxKinetics & addee, LDBLE extensive); protected: - std::list < cxxKineticsComp > kineticsComps; + std::vector < cxxKineticsComp > kinetics_comps; std::vector < LDBLE >steps; - int equal_steps; + int count; + bool equalIncrements; cxxNameDouble totals; LDBLE step_divide; int rk; @@ -61,7 +74,6 @@ class cxxKinetics:public cxxNumKeyword bool use_cvode; int cvode_steps; int cvode_order; - }; #endif // !defined(CXXKINETICS_H_INCLUDED) diff --git a/phreeqc/advection.cpp b/phreeqc/advection.cpp index feaa3379..3888184f 100644 --- a/phreeqc/advection.cpp +++ b/phreeqc/advection.cpp @@ -1,5 +1,7 @@ +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ @@ -36,7 +38,8 @@ advection(void) { for (i = 1; i <= count_ad_cells; i++) { - if (kinetics_bsearch(i, &n) != NULL) + //if (kinetics_bsearch(i, &n) != NULL) + if (Utilities::Rxn_find(Rxn_kinetics_map, i) == NULL) { input_error++; error_string = sformatf( diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 6206cdd9..066aeba4 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -7,6 +7,7 @@ #include "../GasPhase.h" #include "PPassemblage.h" #include "SSassemblage.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: activity(const char *species_name) @@ -974,7 +975,30 @@ get_calculate_value(const char *name) } return (calculate_value_ptr->value); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +kinetics_moles(const char *kinetics_name) +/* ---------------------------------------------------------------------- */ +{ + if (use.Get_kinetics_in() == FALSE || use.Get_kinetics_ptr() == NULL) + return (0); + for (size_t i = 0; i < use.Get_kinetics_ptr()->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp *kinetics_comp_ptr = &(use.Get_kinetics_ptr()->Get_kinetics_comps()[i]); + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), kinetics_name) == 0) + { + return (kinetics_comp_ptr->Get_m()); + } + } + + error_string = sformatf( "No data for rate %s in KINETICS keyword.", + kinetics_name); + warning_msg(error_string); + return (0); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: kinetics_moles(const char *kinetics_name) @@ -998,7 +1022,7 @@ kinetics_moles(const char *kinetics_name) warning_msg(error_string); return (0); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: log_activity(const char *species_name) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index f48e126c..f2817011 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -409,6 +409,7 @@ struct Charge_Group LDBLE z; LDBLE eq; }; +#ifdef SKIP /* ---------------------------------------------------------------------- * Kinetics * ---------------------------------------------------------------------- */ @@ -446,7 +447,7 @@ struct kinetics_comp int count_d_params; LDBLE *d_params; }; - +#endif /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 00bc855e..68f46e39 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -15,7 +15,7 @@ #include "GasPhase.h" #include "SSassemblage.h" #include "Temperature.h" - +#include "cxxKinetics.h" #include #include #include "nvector_serial.h" /* definitions of type N_Vector and macro */ @@ -38,7 +38,98 @@ #define MAX_DIVIDE 2 #define KINETICS_TOL 1e-8; +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * determine rates and + * a list of elements and amounts in + * the reaction. + */ + int j, return_value; + LDBLE coef; + char l_command[] = "run"; + struct rate *rate_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + return_value = OK; + count_elts = 0; + paren_count = 0; + rate_time = time_step; +/* t1 = clock(); */ + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + coef = 0.0; +/* + * Send command to basic interpreter + */ + rate_ptr = rate_search(kinetics_comp_ptr->Get_rate_name().c_str(), &j); + if (rate_ptr == NULL) + { + error_string = sformatf( "Rate not found for %s", + kinetics_comp_ptr->Get_rate_name().c_str()); + error_msg(error_string, STOP); + } + else + { + rate_moles = NAN; + rate_m = kinetics_comp_ptr->Get_m(); + rate_m0 = kinetics_comp_ptr->Get_m0(); + rate_p = kinetics_comp_ptr->Get_d_params(); + count_rate_p = (int) kinetics_comp_ptr->Get_d_params().size(); + if (rate_ptr->new_def == TRUE) + { + if (basic_compile + (rates[j].commands, &rates[j].linebase, &rates[j].varbase, + &rates[j].loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in rate %s.", + kinetics_comp_ptr->Get_rate_name().c_str()); + error_msg(error_string, STOP); + } + + rate_ptr->new_def = FALSE; + } + if (basic_run + (l_command, rates[j].linebase, rates[j].varbase, + rates[j].loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in rate %s.", + kinetics_comp_ptr->Get_rate_name().c_str()); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Moles of reaction not SAVE'd for %s.", + kinetics_comp_ptr->Get_rate_name().c_str()); + error_msg(error_string, STOP); + } + else + { + + coef = rate_moles; + } + } +/* + * Accumulate moles of reaction for component + */ + kinetics_comp_ptr->Set_moles(kinetics_comp_ptr->Get_moles() + coef); + if (coef == 0.0) + continue; + } +/* t2=clock(); + printf("secs in reac %e, t2 %e\n", t2-t1, t1); + */ + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) @@ -129,7 +220,124 @@ calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) */ return (return_value); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * using extrapolated values, which were + * stored in moles in run_kinetics + */ + //int i, j, k; + LDBLE coef; + //char token[MAX_LENGTH]; + struct phase *phase_ptr; + struct master *master_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + kinetics_ptr->Get_totals().clear(); + count_elts = 0; + paren_count = 0; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + if (kinetics_comp_ptr->Get_moles() > m_temp[i]) + { + kinetics_comp_ptr->Set_moles(m_temp[i]); + kinetics_comp_ptr->Set_m(0); + } + coef = kinetics_comp_ptr->Get_moles(); + if (coef == 0.0) + continue; +/* + * Reactant is a pure phase, copy formula into token + */ + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); + for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) + { + std::string name = it->first; + LDBLE coef1 = it->second; + phase_ptr = NULL; + int k; + phase_ptr = phase_bsearch(name.c_str(), &k, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, + coef *coef1); + } + else + { + char * temp_name = string_duplicate(name.c_str()); + char * ptr = temp_name; + get_elts_in_species(&ptr, coef * coef1); + free_check_null(temp_name); + } + } + if (use.Get_exchange_ptr() != NULL + && ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate()) + { + cxxExchange * exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); + std::map::iterator it = exchange_ptr->Get_exchComps().begin(); + for ( ; it != exchange_ptr->Get_exchComps().end(); it++) + { + std::string name(it->second.Get_rate_name()); + if (name.size() > 0) + { + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), + name.c_str()) == 0) + { + /* found kinetics component */ + add_elt_list(it->second.Get_formula_totals(), -coef*it->second.Get_phase_proportion()); + } + } + } + + } + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->related_rate == TRUE) + { + for (int j = 0; j < use.Get_surface_ptr()->count_comps; j++) + { + if (use.Get_surface_ptr()->comps[j].rate_name != NULL) + { + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), + use.Get_surface_ptr()->comps[j].rate_name) == 0) + { + /* found kinetics component */ + char * temp_formula = string_duplicate(use.Get_surface_ptr()->comps[j].formula); + char *ptr = temp_formula; +/* Surface = 0 when m becomes low ... + */ + if (0.9 * use.Get_surface_ptr()->comps[j].phase_proportion * + (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) + { + master_ptr = master_bsearch(ptr); + master_ptr->total = 0.0; + } + else + { + get_elts_in_species(&ptr, + -coef * + use.Get_surface_ptr()->comps[j]. + phase_proportion); + } + free_check_null(temp_formula); + } + } + } + } + } + kinetics_ptr->Set_totals(elt_list_NameDouble()); + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) @@ -246,7 +454,865 @@ calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) kinetics_ptr->totals = elt_list_save(); return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Runge-Kutta-Fehlberg method; 6 evaluations of the derivative + * give O(h^5) global error and error estimate + * calc_kinetic_reaction(.., ..) calculates moles of intermediate derivatives; + * these are calc'd for the whole step h. + * calc_final_kinetic reaction(..) translates moles to PHREEQC reaction. + */ + int k, save_old; + int l_bad, step_bad, step_ok; + int n_reactions; + LDBLE h, h_old, h_sum; + LDBLE *rk_moles; + LDBLE l_error, error_max, safety, moles_max, moles_reduction; + cxxKinetics *kinetics_ptr; + int equal_rate, zero_rate; + + cxxPPassemblage *pp_assemblage_save = NULL; + //struct ss_assemblage *ss_assemblage_save = NULL; + cxxSSassemblage *ss_assemblage_save = NULL; + + LDBLE b31 = 3. / 40., b32 = 9. / 40., + b51 = -11. / 54., b53 = -70. / 27., b54 = 35. / 27., + b61 = 1631. / 55296., b62 = 175. / 512., b63 = 575. / 13824., b64 = + 44275. / 110592., b65 = 253. / 4096., c1 = 37. / 378., c3 = + 250. / 621., c4 = 125. / 594., c6 = 512. / 1771., dc5 = + -277. / 14336.; + LDBLE dc1 = c1 - 2825. / 27648., dc3 = c3 - 18575. / 48384., dc4 = + c4 - 13525. / 55296., dc6 = c6 - 0.25; +/* + * Save kinetics i and solution i, if necessary + */ + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); + //kinetics_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); + if (nsaver != i) + { + solution_duplicate(i, save_old); + } + +/* + * Malloc some space + */ + //if (kinetics_bsearch(i, &m) == NULL) + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + if (kinetics_ptr == NULL) + return (OK); + n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); + rk_moles = + (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); + if (rk_moles == NULL) + malloc_error(); + + /*if (use_mix != NOMIX) last_model.force_prep = TRUE; */ + set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); + run_reactions_iterations += iterations; + + saver(); + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, NOMIX, TRUE, i); + } + else if (state == ADVECTION) + { + set_advection(i, NOMIX, TRUE, i); + } + else if (state == REACTION) + { + set_reaction(i, NOMIX, TRUE); + } + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + + step_bad = step_ok = 0; + l_bad = FALSE; + h_sum = 0.; + h = h_old = kin_time; + moles_max = 0.1; + moles_reduction = 1.0; + safety = 0.7; + if (kinetics_ptr->Get_rk() < 1) + kinetics_ptr->Set_rk(1); + else if (kinetics_ptr->Get_rk() > 3) + kinetics_ptr->Set_rk(6); + + if (kinetics_ptr->Get_rk() == 6) + equal_rate = FALSE; + else + equal_rate = TRUE; +/* + * if step_divide > 1, initial timestep is divided + * if < 1, step_divide indicates maximal reaction... + */ + if (kinetics_ptr->Get_step_divide() > 1.0) + { + h = h_old = kin_time / kinetics_ptr->Get_step_divide(); + equal_rate = FALSE; + } + else if (kinetics_ptr->Get_step_divide() < 1.0) + moles_max = kinetics_ptr->Get_step_divide(); + + rate_sim_time = rate_sim_time_start + h_sum; + + status(0, NULL); + while (h_sum < kin_time) + { + + if (step_bad > kinetics_ptr->Get_bad_step_max()) + { + error_string = sformatf( + "Bad RK steps > %d. Please decrease (time)step or increase -bad_step_max.", + kinetics_ptr->Get_bad_step_max()); + error_msg(error_string, STOP); + } + + MOLES_TOO_LARGE: + if (moles_reduction > 1.0) + { + h_old = h; + h = safety * h / (1.0 + moles_reduction); + moles_reduction = 1.0; + equal_rate = FALSE; + l_bad = TRUE; + } +/* + * find k1 + */ + if (l_bad == TRUE) + { + //for (j = 0; j < n_reactions; j++) + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + rk_moles[j] *= (h / h_old); + kinetics_comp_ptr->Set_moles(rk_moles[j] * 0.2); + kinetics_comp_ptr->Set_m(m_temp[j]); + } + l_bad = FALSE; + } + else + { +/* + * define pointers for calc_kinetic_, they are lost after saver()... + */ + if (state == TRANSPORT || state == PHAST) + { + set_transport(i, NOMIX, TRUE, i); + } + else if (state == ADVECTION) + { + set_advection(i, NOMIX, TRUE, i); + } + else if (state == REACTION) + { + set_reaction(i, NOMIX, TRUE); + } + /* + * Moles of minerals and solid solutions may change to make positive + * concentrations. Reactions may take out more than is present in + * solution. + */ + if (use.Get_pp_assemblage_ptr() != NULL) + { + cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_pp_assemblage_ptr()->Get_n_user()); + assert(pp_assemblage_ptr); + pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + cxxSSassemblage * ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_ss_assemblage_ptr()->Get_n_user()); + assert(ss_assemblage_ptr); + ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.); + m_temp[j] = kinetics_comp_ptr->Get_m(); + } + + rate_sim_time = rate_sim_time_start + h_sum; + calc_kinetic_reaction(kinetics_ptr, h); + + /* store k1 in rk_moles ... */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (moles_reduction * moles_max < fabs(kinetics_comp_ptr->Get_moles())) + { + moles_reduction = fabs(kinetics_comp_ptr->Get_moles()) / moles_max; + } + /* define reaction for calculating k2 ... */ + rk_moles[j] = kinetics_comp_ptr->Get_moles(); + kinetics_comp_ptr->Set_moles(kinetics_comp_ptr->Get_moles() * 0.2); + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + } +/* + * Quit rk with rk = 1 and equal rates ... + */ + if (kinetics_ptr->Get_rk() == 1 && equal_rate) + { + zero_rate = TRUE; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(rk_moles[j]); + if (fabs(kinetics_comp_ptr->Get_moles()) > MIN_TOTAL) + zero_rate = FALSE; + } + + if (zero_rate == FALSE) + { + calc_final_kinetic_reaction(kinetics_ptr); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 1.e-30) + kinetics_comp_ptr->Set_m(0); + kinetics_comp_ptr->Set_moles(0.); + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == + MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + calc_kinetic_reaction(kinetics_ptr, h); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (fabs(rk_moles[j] - kinetics_comp_ptr->Get_moles()) > + kinetics_comp_ptr->Get_tol()) + { + equal_rate = FALSE; + break; + } + } + } + if (zero_rate || equal_rate) + { + /* removing the following line causes different results for + example 6 distributed with the program */ + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } + goto EQUAL_RATE_OUT; + } + else + { + kinetics_ptr->Set_rk(3); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.2 * rk_moles[j]); + } + } + } +/* + * Continue with rk ... + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; + +/* + * find k2 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_moles(0.); + } + rate_sim_time = rate_sim_time_start + h_sum + 0.2 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + + /* store k2 in rk_moles */ + k = n_reactions; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (moles_reduction * moles_max < + fabs(kinetics_comp_ptr->Get_moles())) + { + moles_reduction = + fabs(kinetics_comp_ptr->Get_moles()) / moles_max; + } + /* define reaction for calculating k3 */ + rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); + + kinetics_comp_ptr->Set_moles(b31 * rk_moles[j] + + b32 * rk_moles[k + j]); +/* + * check for equal_rate ... + */ + if (equal_rate + && fabs(rk_moles[j] - rk_moles[k + j]) > + kinetics_comp_ptr->Get_tol()) + { + equal_rate = FALSE; + } + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 2 and equal rates ... + */ + if (kinetics_ptr->Get_rk() == 2 && equal_rate) + { + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles( + 0.3 * rk_moles[j] + 0.7 * rk_moles[k + j]); + } + calc_final_kinetic_reaction(kinetics_ptr); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 1.e-30) + kinetics_comp_ptr->Set_m(0); + kinetics_comp_ptr->Set_moles(0.); + } + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (fabs(rk_moles[j] - kinetics_comp_ptr->Get_moles()) > + kinetics_comp_ptr->Get_tol()) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate) + kinetics_ptr->Set_rk(1); + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k3 + */ + + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m (m_temp[j] - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_moles(0.); + } + rate_sim_time = rate_sim_time_start + h_sum + 0.3 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + + /* store k3 in rk_moles */ + k = 2 * n_reactions; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (moles_reduction * moles_max < + fabs(kinetics_comp_ptr->Get_moles())) + { + moles_reduction = + fabs(kinetics_comp_ptr->Get_moles()) / moles_max; + } + /* define reaction for calculating k4 ... */ + rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); + + kinetics_comp_ptr->Set_moles(0.3 * rk_moles[j] + - 0.9 * rk_moles[n_reactions + j] + 1.2 * rk_moles[k + j]); +/* + * check for equal_rate ... + */ + if (equal_rate + && fabs(rk_moles[j] - rk_moles[k + j]) > + kinetics_comp_ptr->Get_tol()) + equal_rate = FALSE; + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; +/* + * Quit rk with rk = 3 and equal rates ... + */ + if (kinetics_ptr->Get_rk() == 3 && equal_rate) + { + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.5 * rk_moles[j] + - 1.5 * rk_moles[n_reactions + j] + 2 * rk_moles[k + j]); + } + calc_final_kinetic_reaction(kinetics_ptr); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 1.e-30) + kinetics_comp_ptr->Set_m(0.); + kinetics_comp_ptr->Set_moles(0.); + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (fabs(rk_moles[j] - kinetics_comp_ptr->Get_moles()) > + kinetics_comp_ptr->Get_tol()) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate) + kinetics_ptr->Set_rk(1); + + saver(); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } + goto EQUAL_RATE_OUT; + } +/* + * Continue runge_kutta.. + */ + + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k4 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_moles(0.); + } + rate_sim_time = rate_sim_time_start + h_sum + 0.6 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + + /* store k4 in rk_moles */ + k = 3 * n_reactions; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (moles_reduction * moles_max < + fabs(kinetics_comp_ptr->Get_moles())) + { + moles_reduction = + fabs(kinetics_comp_ptr->Get_moles()) / moles_max; + } + + /* define reaction for calculating k5 */ + rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); + kinetics_comp_ptr->Set_moles(b51 * rk_moles[j] + + 2.5 * rk_moles[n_reactions + j] + + b53 * rk_moles[2 * n_reactions + j] + b54 * rk_moles[k + j]); + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k5 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_moles(0.); + } + rate_sim_time = rate_sim_time_start + h_sum + h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + + /* store k5 in rk_moles */ + k = 4 * n_reactions; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (moles_reduction * moles_max < + fabs(kinetics_comp_ptr->Get_moles())) + { + moles_reduction = + fabs(kinetics_comp_ptr->Get_moles()) / moles_max; + } + + /* define reaction for calculating k6 */ + rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); + kinetics_comp_ptr->Set_moles(b61 * rk_moles[j] + + b62 * rk_moles[n_reactions + j] + + b63 * rk_moles[2 * n_reactions + j] + + b64 * rk_moles[3 * n_reactions + j] + b65 * rk_moles[k + j]); + } + if (moles_reduction > 1.0) + goto MOLES_TOO_LARGE; + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * find k6 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_moles(0.); + } + rate_sim_time = rate_sim_time_start + h_sum + 0.875 * h; + calc_kinetic_reaction(kinetics_ptr, h); + + /* Reset to values of last saver() */ + if (pp_assemblage_save != NULL) + { + Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); + } + if (ss_assemblage_save != NULL) + { + Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); + } + + /* store k6 in rk_moles */ + k = 5 * n_reactions; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); + } + +/* + * Evaluate error + */ + error_max = 0.; + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + l_error = fabs(dc1 * rk_moles[j] + + dc3 * rk_moles[2 * n_reactions + j] + + dc4 * rk_moles[3 * n_reactions + j] + + dc5 * rk_moles[4 * n_reactions + j] + + dc6 * rk_moles[5 * n_reactions + j]); + + /* tol is in moles/l */ + l_error /= kinetics_comp_ptr->Get_tol(); + if (l_error > error_max) + error_max = l_error; + } + +/* + * repeat with smaller step + */ +/* printf("timest %g ; error_max %g\n", h, error_max); */ + if (error_max > 1) + { + h_old = h; + if (step_ok == 0) + h = h * safety / error_max; + else + h = h * safety * pow(error_max, (LDBLE) -0.25); + l_bad = TRUE; + step_bad++; + } + else + { +/* + * OK, calculate result + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(c1 * rk_moles[j] + + c3 * rk_moles[2 * n_reactions + j] + + c4 * rk_moles[3 * n_reactions + j] + + c6 * rk_moles[5 * n_reactions + j]); + } + calc_final_kinetic_reaction(kinetics_ptr); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_temp[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 1.e-30) + kinetics_comp_ptr->Set_m(0); + kinetics_comp_ptr->Set_moles(0.); + } + + if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) + { + run_reactions_iterations += iterations; + moles_reduction = 9; + goto MOLES_TOO_LARGE; + } + run_reactions_iterations += iterations; +/* + * Move next calc'n to rk = 1 when initial rate equals final rate ... + */ + calc_kinetic_reaction(kinetics_ptr, h); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (fabs(rk_moles[j] - kinetics_comp_ptr->Get_moles()) > + kinetics_comp_ptr->Get_tol()) + { + equal_rate = FALSE; + break; + } + } + if (equal_rate && kinetics_ptr->Get_rk() < 6) + kinetics_ptr->Set_rk(1); + + saver(); + + step_ok++; + h_sum += h; + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } +/* + * and increase step size ... + */ + if (h_sum < kin_time) + { + if (error_max > 0.000577) + { + h = h * safety * pow(error_max, (LDBLE) -0.2e0); + } + else + { + h *= 4; + } + if (h > (kin_time - h_sum)) + h = (kin_time - h_sum); + } + } +#if !defined(PHREEQCI_GUI) +#ifndef PHREEQ98 + if (pr.status == TRUE && status_on == TRUE + && (int) (1e3 / CLOCKS_PER_SEC * ((float) clock() - status_timer)) > status_interval) + { + char str[MAX_LENGTH]; + backspace_screen(37); + sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, + step_ok, (int) (100 * h_sum / kin_time)); + screen_msg(sformatf("%-37s", str)); + } +#endif +#endif + } + + EQUAL_RATE_OUT: + +/* + * Run one more time to get distribution of species + */ + if (state >= REACTION || nsaver != i) + { + set_and_run_wrapper(i, NOMIX, FALSE, nsaver, 0.); + run_reactions_iterations += iterations; + } +/* saver(); */ /* reset for printing */ + if (use_mix == DISP) + { + //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; + use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); + use.Set_mix_in(true); + use.Set_n_mix_user(i); + } + else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) + { + //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use.Get_mix_ptr() != NULL) + { + use.Set_mix_in(true); + use.Set_n_mix_user(i); + } + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) + { + solution_duplicate(save_old, i); + } + rk_moles = (LDBLE *) free_check_null(rk_moles); + + rate_sim_time = rate_sim_time_start + kin_time; + use.Set_kinetics_in(true); + + /* Free space */ + + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } + return (OK); +} + +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, @@ -266,7 +1332,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE h, h_old, h_sum; LDBLE *rk_moles; LDBLE l_error, error_max, safety, moles_max, moles_reduction; - struct kinetics *kinetics_ptr; + cxxKinetics *kinetics_ptr; int equal_rate, zero_rate; cxxPPassemblage *pp_assemblage_save = NULL; @@ -285,7 +1351,8 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, * Save kinetics i and solution i, if necessary */ save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); - kinetics_duplicate(i, save_old); + //kinetics_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); if (nsaver != i) { solution_duplicate(i, save_old); @@ -294,7 +1361,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, /* * Malloc some space */ - if (kinetics_bsearch(i, &m) == NULL) + //if (kinetics_bsearch(i, &m) == NULL) + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i) + if (kinetics_ptr == NULL) return (OK); n_reactions = kinetics[m].count_comps; rk_moles = @@ -1081,7 +2150,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, @@ -1094,7 +2163,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, LDBLE small_pe_step, small_step; cxxPPassemblage *pp_assemblage_save = NULL; cxxSSassemblage *ss_assemblage_save = NULL; - struct kinetics *kinetics_save = NULL; + cxxKinetics *kinetics_save = NULL; small_pe_step = 5.; @@ -1143,12 +2212,15 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (use.Get_kinetics_ptr() != NULL) { + kinetics_save = new cxxKinetics(*use.Get_kinetics_ptr()); +#ifdef SKIP kinetics_save = (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); if (kinetics_save == NULL) malloc_error(); kinetics_copy(use.Get_kinetics_ptr(), kinetics_save, use.Get_kinetics_ptr()->n_user); +#endif } if (pitzer_model == TRUE || sit_model == TRUE) @@ -1309,9 +2381,8 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (kinetics_save != NULL) { - kinetics_free(use.Get_kinetics_ptr()); - kinetics_copy(kinetics_save, use.Get_kinetics_ptr(), - kinetics_save->n_user); + Rxn_kinetics_map[kinetics_save->Get_n_user()] = *kinetics_save; + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, kinetics_save->Get_n_user())); } } set_and_run_attempt = j; @@ -1340,7 +2411,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, ("Numerical method failed with this set of convergence parameters.\n"); } if (converge == FALSE && use.Get_kinetics_ptr() != NULL - && use.Get_kinetics_ptr()->use_cvode == TRUE) + && use.Get_kinetics_ptr()->Get_use_cvode()) { error_string = sformatf( "Numerical method failed on all parameter combinations, retrying integration"); @@ -1392,8 +2463,8 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (kinetics_save != NULL) { - kinetics_free(kinetics_save); - kinetics_save = (struct kinetics *) free_check_null(kinetics_save); + delete kinetics_save; + kinetics_save = NULL; } if (converge == MASS_BALANCE) { @@ -1508,8 +2579,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) * use_kinetics --true or false flag to calculate kinetic reactions * nsaver --user number to store solution */ - int n; - cell = i; reaction_step = 1; /* @@ -1669,7 +2738,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find gas */ - //use.Get_gas_phase_ptr() = gas_phase_bsearch(i, &use.n_gas_phase); use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, i)); if (use.Get_gas_phase_ptr() != NULL) { @@ -1687,10 +2755,7 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find ss_assemblage */ - //int n_ss_assemblage; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, i)); - //use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); - //use.Set_n_ss_assemblage(n_ss_assemblage); if (use.Get_ss_assemblage_ptr() != NULL) { use.Set_ss_assemblage_in(true); @@ -1712,11 +2777,10 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) save.kinetics = FALSE; if (use_kinetics == TRUE) { - use.Set_kinetics_ptr(kinetics_bsearch(i, &n)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); if (use.Get_kinetics_ptr() != NULL) { use.Set_n_kinetics_user(i); - //use.Set_n_kinetics(n); use.Set_kinetics_in(true); save.kinetics = TRUE; save.n_kinetics_user = i; @@ -1878,9 +2942,7 @@ set_reaction(int i, int use_mix, int use_kinetics) */ if (use_kinetics == TRUE && use.Get_kinetics_in() == TRUE) { - int n_kinetics; - use.Set_kinetics_ptr(kinetics_bsearch(i, &n_kinetics)); - //use.Set_n_kinetics(n_kinetics); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); if (use.Get_kinetics_ptr() == NULL) { error_string = sformatf( "KINETICS %d not found.", i); @@ -1899,7 +2961,368 @@ set_reaction(int i, int use_mix, int use_kinetics) */ return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Kinetics calculations + * Rates and moles of each reaction are calculated in calc_kinetic_reaction + * Total number of moles in reaction is stored in kinetics[i].totals + */ + int converge, m_iter; + int pr_all_save; + int nsaver; + cxxKinetics *kinetics_ptr; + cxxPPassemblage *pp_assemblage_ptr; + cxxSSassemblage *ss_assemblage_ptr; + cxxUse use_save; + int save_old, n_reactions /*, nok, nbad */ ; + + /* CVODE definitions */ + realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; + long int iopt[OPT_SIZE]; + int flag; +/* + * Set nsaver + */ + run_reactions_iterations = 0; + kin_time_x = kin_time; + nsaver = i; + if (state == TRANSPORT || state == PHAST) + { + if (use_mix == DISP) + { + nsaver = -2; + } + else if (use_mix == STAG) + { + nsaver = -2 - i; + } + } + if (state == ADVECTION) + { + nsaver = -2; + } +/* + * Check that reaction exists for this cell .. + */ + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + if (kin_time <= 0 || + (state == REACTION && use.Get_kinetics_in() == FALSE) || + (state == TRANSPORT && kinetics_ptr == NULL) || + (state == PHAST && kinetics_ptr == NULL) || + (state == ADVECTION && kinetics_ptr == NULL)) + { + converge = + set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + run_reactions_iterations += iterations; + } + else + { +/* + * Save moles of kinetic reactants for printout... + */ + //kinetics_ptr = kinetics_bsearch(i, &n); + size_t count_comps = kinetics_ptr->Get_kinetics_comps().size(); + m_temp = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); + if (m_temp == NULL) + malloc_error(); + + m_original = + (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); + if (m_original == NULL) + malloc_error(); + + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + m_original[j] = kinetics_comp_ptr->Get_m(); + m_temp[j] = kinetics_comp_ptr->Get_m(); + } +/* +* Start the loop for timestepping ... + * Use either Runge-Kutta-Fehlberg, or final result extrapolation + */ + pr_all_save = pr.all; + pr.all = FALSE; +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * (if (incremental_reactions == FALSE || reaction_step == 1) + */ + store_get_equi_reactants(i, FALSE); + if (!kinetics_ptr->Get_use_cvode()) + { +/* in case dispersivity is not wanted.. + if (multi_Dflag) + rk_kinetics(i, kin_time, NOMIX, nsaver, step_fraction); + else + */ + rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); + } + else + { + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); + if (nsaver != i) + { + solution_duplicate(i, save_old); + } + for (int j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + +/* + * Do mix first + */ + //kinetics_ptr = kinetics_bsearch(i, &m); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); + cvode_n_user = i; + cvode_kinetics_ptr = (void *) kinetics_ptr; + cvode_n_reactions = n_reactions; + cvode_rate_sim_time_start = rate_sim_time_start; + cvode_rate_sim_time = rate_sim_time; + + if (multi_Dflag) + converge = set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + else + converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + saver(); + pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); + ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); + if (pp_assemblage_ptr != NULL) + { + cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (ss_assemblage_ptr != NULL) + { + cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } + + /* allocate space for CVODE */ + kinetics_machEnv = M_EnvInit_Serial(n_reactions); + kinetics_machEnv->phreeqc_ptr = this; + kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (kinetics_y == NULL) + malloc_error(); + cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_last_good_y == NULL) + malloc_error(); + cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_prev_good_y == NULL) + malloc_error(); + kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); + if (kinetics_abstol == NULL) + malloc_error(); + +/* + * Set y to 0.0 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.0); + Ith(kinetics_y, j + 1) = 0.0; + Ith(kinetics_abstol, j + 1) = kinetics_comp_ptr->Get_tol(); + /*Ith(abstol,j+1) = 1e-8; */ + /* m_temp[j] = kinetics_ptr->comps[j].m; */ + } + reltol = 0.0; + + /* Call CVodeMalloc to initialize CVODE: + + NEQ is the problem size = number of equations + f is the user's right hand side function in y'=f(t,y) + T0 is the initial time + y is the initial dependent variable vector + BDF specifies the Backward Differentiation Formula + NEWTON specifies a Newton iteration + SV specifies scalar relative and vector absolute tolerances + &reltol is a pointer to the scalar relative tolerance + abstol is the absolute tolerance vector + FALSE indicates there are no optional inputs in iopt and ropt + iopt is an array used to communicate optional integer input and output + ropt is an array used to communicate optional real input and output + + A pointer to CVODE problem memory is returned and stored in cvode_mem. */ + /* Don't know what this does */ + /* + iopt[SLDET] = TRUE; + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); + iopt[MXSTEP] is maximum number of steps that CVODE tries. + */ + iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); + iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, + &reltol, kinetics_abstol, this, NULL, TRUE, iopt, + ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + t = 0; + tout = kin_time; + /*ropt[HMAX] = tout/10.; */ + /*ropt[HMIN] = 1e-17; */ + use_save = use; + flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); + rate_sim_time = rate_sim_time_start + t; + /* + printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", + t, Ith(y,1), Ith(y,2), Ith(y,3)); + */ + m_iter = 0; + sum_t = 0; + RESTART: + while (flag != SUCCESS) + { + sum_t += cvode_last_good_time; + error_string = sformatf( + "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", + (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); + warning_msg(error_string); +#ifdef DEBUG_KINETICS + if (m_iter > 5) + dump_kinetics_stderr(cell_no); +#endif + + cvode_last_good_time = 0; + if (++m_iter >= kinetics_ptr->Get_bad_step_max()) + { + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + error_msg("Repeated restart of integration.", STOP); + } + tout1 = tout - sum_t; + t = 0; + N_VScale(1.0, cvode_last_good_y, kinetics_y); + for (int j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); + iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, + SV, &reltol, kinetics_abstol, this, NULL, + TRUE, iopt, ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + flag = + CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); + /* + error_string = sformatf( "CVode failed, flag=%d.\n", flag); + error_msg(error_string, STOP); + */ + } + /* + odeint(&ystart[-1], n_reactions, 0, kin_time, kinetics_ptr->comps[0].tol, kin_time/kinetics_ptr->step_divide, 0.0, &nok, &nbad, i, nsaver ); + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(Ith(kinetics_y, j + 1)); + kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_moles(m_original[j]); + kinetics_comp_ptr->Set_m(0.0); + } + } + if (use.Get_pp_assemblage_ptr() != NULL) + { + Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); + } + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == + MASS_BALANCE) + { + /*error_msg("FAIL 2 after successful integration in CVode", CONTINUE); */ + warning_msg("FAIL 2 after successful integration in CVode"); + flag = -1; + goto RESTART; + } + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) + { + solution_duplicate(save_old, i); + } + free_cvode(); + use.Set_mix_in(use_save.Get_mix_in()); + use.Set_mix_ptr(use_save.Get_mix_ptr()); + } + + rate_sim_time = rate_sim_time_start + kin_time; + store_get_equi_reactants(i, TRUE); + pr.all = pr_all_save; + + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); +/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0; + */ } + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + } + iterations = run_reactions_iterations; + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = NULL; + } + if (cvode_ss_assemblage_save != NULL) + { + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = NULL; + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) @@ -1917,6 +3340,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) struct kinetics *kinetics_ptr; cxxPPassemblage *pp_assemblage_ptr; cxxSSassemblage *ss_assemblage_ptr; + cxxKinetics *kinetics_ptr; cxxUse use_save; int save_old, m, n_reactions /*, nok, nbad */ ; @@ -2261,7 +3685,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: free_cvode(void) @@ -2312,7 +3736,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) * use_kinetics --true or false flag to calculate kinetic reactions * nsaver --user number to store solution */ - int n; cell = i; reaction_step = 1; @@ -2491,11 +3914,10 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) save.kinetics = FALSE; if (use_kinetics == TRUE) { - use.Set_kinetics_ptr(kinetics_bsearch(i, &n)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); if (use.Get_kinetics_ptr() != NULL) { use.Set_n_kinetics_user(i); - //use.Set_n_kinetics(n); use.Set_kinetics_in(true); save.kinetics = TRUE; save.n_kinetics_user = i; @@ -2655,8 +4077,92 @@ store_get_equi_reactants(int l, int kin_end) } return (OK); } +void Phreeqc:: +f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data) +{ + int n_reactions, n_user; + LDBLE step_fraction; + cxxKinetics *kinetics_ptr; + Phreeqc *pThis = (Phreeqc *) f_data; + pThis->cvode_error = FALSE; + n_reactions = pThis->cvode_n_reactions; + n_user = pThis->cvode_n_user; + kinetics_ptr = (cxxKinetics *) pThis->cvode_kinetics_ptr; + step_fraction = pThis->cvode_step_fraction; + pThis->rate_sim_time = pThis->cvode_rate_sim_time; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_comp_ptr->Set_moles(Ith(y, i + 1)); + kinetics_comp_ptr->Set_m(pThis->m_original[i] - Ith(y, i + 1)); + if (kinetics_comp_ptr->Get_m() < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_comp_ptr->Set_moles(pThis->m_original[i]); + kinetics_comp_ptr->Set_m(0.0); + } + } + pThis->calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->use.Get_ss_assemblage_ptr() != NULL) + { + pThis->Rxn_ss_assemblage_map[pThis->cvode_ss_assemblage_save->Get_n_user()] = *pThis->cvode_ss_assemblage_save; + pThis->use.Set_ss_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_ss_assemblage_map, pThis->cvode_ss_assemblage_save->Get_n_user())); + } + + if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) + { + pThis->run_reactions_iterations += pThis->iterations; + pThis->cvode_error = TRUE; + /* + error_msg("Mass balance error in f", CONTINUE); + */ + return; + } + if (pThis->cvode_test == TRUE) + { + return; + } + pThis->run_reactions_iterations += pThis->iterations; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + kinetics_comp_ptr->Set_moles(0.0); + } + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + /* + dydx[i + 1] = kinetics_ptr->comps[i].moles; + */ + Ith(ydot, i + 1) = kinetics_comp_ptr->Get_moles(); + } + return; +} +#ifdef SKIP void Phreeqc:: f(integertype N, realtype t, N_Vector y, N_Vector ydot, void *f_data) @@ -2739,14 +4245,187 @@ f(integertype N, realtype t, N_Vector y, N_Vector ydot, } return; } - +#endif /* static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, N_Vector y, N_Vector fy, N_Vector ewt, realtype h, realtype uround, void *jac_data, long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); */ +void Phreeqc:: +Jac(integertype N, DenseMat J, RhsFn f, void *f_data, + realtype t, N_Vector y, N_Vector fy, N_Vector ewt, + realtype h, realtype uround, void *jac_data, + long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, + N_Vector vtemp3) +{ + int count_cvode_errors; + int j, n_reactions, n_user; + LDBLE *initial_rates, del; + cxxKinetics *kinetics_ptr; + LDBLE step_fraction; + Phreeqc *pThis = (Phreeqc *) f_data; + + pThis->cvode_error = FALSE; + n_reactions = pThis->cvode_n_reactions; + n_user = pThis->cvode_n_user; + kinetics_ptr = (cxxKinetics *) pThis->cvode_kinetics_ptr; + step_fraction = pThis->cvode_step_fraction; + pThis->rate_sim_time = pThis->cvode_rate_sim_time; + + initial_rates = + (LDBLE *) pThis->PHRQ_malloc ((size_t) n_reactions * sizeof(LDBLE)); + if (initial_rates == NULL) + pThis->malloc_error(); + + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + /* + kinetics_ptr->comps[i].moles = y[i + 1]; + kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; + */ + kinetics_comp_ptr->Set_moles(Ith(y, i + 1)); + kinetics_comp_ptr->Set_m(pThis->m_original[i] - Ith(y, i + 1)); + if (kinetics_comp_ptr->Get_m() < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_comp_ptr->Set_moles(pThis->m_original[i]); + kinetics_comp_ptr->Set_m(0.0); + } + } + pThis->calc_final_kinetic_reaction(kinetics_ptr); + /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) + { + pThis->run_reactions_iterations += pThis->iterations; + pThis->cvode_error = TRUE; + /* + error_msg("Mass balance error in jacobian", CONTINUE); + */ + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; + } + pThis->run_reactions_iterations += pThis->iterations; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + kinetics_comp_ptr->Set_moles(0.0); + } + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + initial_rates[i] = kinetics_comp_ptr->Get_moles(); + } + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + /* calculate reaction up to current time */ + del = 1e-12; + pThis->cvode_error = TRUE; + count_cvode_errors = 0; + while (pThis->cvode_error == TRUE) + { + del /= 10.; + for (j = 0; j < n_reactions; j++) + { + /* + kinetics_ptr->comps[j].moles = y[j + 1]; + kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; + */ + kinetics_comp_ptr->Set_moles(Ith(y, j + 1)); + kinetics_comp_ptr->Set_m(pThis->m_original[j] - Ith(y, j + 1)); + if (kinetics_comp_ptr->Get_m() < 0) + { + /* + NOTE: y is not correct if it is greater than m_original + However, it seems to work to let y wander off, but use + .moles as the correct integral. + It does not work to reset Y to m_original, presumably + because the rational extrapolation gets screwed up. + */ + + /* + Ith(y,i + 1) = m_original[i]; + */ + kinetics_comp_ptr->Set_moles(pThis->m_original[i]); + kinetics_comp_ptr->Set_m(0.0); + } + } + + /* Add small amount of ith reaction */ + //kinetics_ptr->comps[i].m -= del; + kinetics_comp_ptr->Set_m(kinetics_comp_ptr->Get_m() - del); + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_m(0); + } + kinetics_comp_ptr->Set_moles(kinetics_comp_ptr->Get_moles() + del); + pThis->calc_final_kinetic_reaction(kinetics_ptr); + if (pThis->use.Get_pp_assemblage_ptr() != NULL) + { + pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; + pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); + } + if (pThis->set_and_run_wrapper + (n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) + { + count_cvode_errors++; + pThis->cvode_error = TRUE; + if (count_cvode_errors > 30) + { + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; + } + pThis->run_reactions_iterations += pThis->iterations; + continue; + } + pThis->cvode_error = FALSE; + pThis->run_reactions_iterations += pThis->iterations; + /*kinetics_ptr->comps[i].moles -= del; */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.0); + } + pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); + + /* calculate new rates for df/dy[i] */ + /* dfdx[i + 1] = 0.0; */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + IJth(J, j + 1, i + 1) = + (kinetics_comp_ptr->Get_moles() - initial_rates[j]) / del; + } + } + } + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + kinetics_comp_ptr->Set_moles(0); + } + initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); + return; +} +#ifdef SKIP void Phreeqc:: Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, N_Vector y, N_Vector fy, N_Vector ewt, @@ -2908,7 +4587,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); return; } - +#endif void Phreeqc:: cvode_init(void) { diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index eb2f583b..c3da9ceb 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -6,11 +6,12 @@ #include "PBasic.h" #include "Temperature.h" #include "Exchange.h" -#include "ExchComp.h" +//#include "ExchComp.h" #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" +#include "cxxKinetics.h" #if defined(WINDOWS) || defined(_WINDOWS) #include @@ -71,7 +72,7 @@ initialize(void) //max_exchange = MAX_PP_ASSEMBLAGE; max_surface = MAX_PP_ASSEMBLAGE; //max_gas_phase = MAX_PP_ASSEMBLAGE; - max_kinetics = MAX_PP_ASSEMBLAGE; + //max_kinetics = MAX_PP_ASSEMBLAGE; //max_ss_assemblage = MAX_PP_ASSEMBLAGE; max_elements = MAX_ELEMENTS; @@ -91,7 +92,7 @@ initialize(void) //count_exchange = 0; count_surface = 0; //count_gas_phase = 0; - count_kinetics = 0; + //count_kinetics = 0; //count_ss_assemblage = 0; count_elements = 0; @@ -158,8 +159,8 @@ initialize(void) //space((void **) ((void *) &gas_phase), INIT, &max_gas_phase, // sizeof(struct gas_phase)); - space((void **) ((void *) &kinetics), INIT, &max_kinetics, - sizeof(struct kinetics)); + //space((void **) ((void *) &kinetics), INIT, &max_kinetics, + // sizeof(struct kinetics)); //space((void **) ((void *) &ss_assemblage), INIT, &max_ss_assemblage, // sizeof(struct ss_assemblage)); @@ -382,7 +383,7 @@ initialize(void) initial_total_time = 0; rate_m = 0; rate_m0 = 0; - rate_p = NULL; + //rate_p = NULL; rate_time = 0; rate_sim_time_start = 0; rate_sim_time_end = 0; @@ -594,7 +595,7 @@ initialize(void) //dbg_exchange = exchange; dbg_surface = surface; //dbg_pp_assemblage = pp_assemblage; - dbg_kinetics = kinetics; + //dbg_kinetics = kinetics; //dbg_irrev = irrev; //dbg_mix = mix; dbg_master = master; @@ -916,10 +917,7 @@ set_use(void) */ if (use.Get_kinetics_in() == TRUE) { - int n_kinetics; - use.Set_kinetics_ptr( - kinetics_bsearch(use.Get_n_kinetics_user(), &n_kinetics)); - //use.Set_n_kinetics(n_kinetics); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); if (use.Get_kinetics_ptr() == NULL) { error_string = sformatf( "Kinetics %d not found.", @@ -1400,11 +1398,11 @@ reactions(void) * mixture, * or irreversible reaction. */ - int count_steps, use_mix, m; + int count_steps, use_mix; char token[2 * MAX_LENGTH]; struct save save_data; LDBLE kin_time; - struct kinetics *kinetics_ptr; + cxxKinetics *kinetics_ptr; state = REACTION; /* last_model.force_prep = TRUE; */ @@ -1418,13 +1416,15 @@ reactions(void) if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { cxxReaction *reaction_ptr = (cxxReaction *) use.Get_reaction_ptr(); - if (reaction_ptr->Get_actualSteps() > count_steps) - count_steps = reaction_ptr->Get_actualSteps(); + if (reaction_ptr->Get_reaction_steps() > count_steps) + count_steps = reaction_ptr->Get_reaction_steps(); } if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) { - if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) - count_steps = abs(use.Get_kinetics_ptr()->count_steps); + //if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) + // count_steps = abs(use.Get_kinetics_ptr()->count_steps); + if (use.Get_kinetics_ptr()->Get_reaction_steps() > count_steps) + count_steps = use.Get_kinetics_ptr()->Get_reaction_steps(); } if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) { @@ -1466,9 +1466,13 @@ reactions(void) * Determine time step for kinetics */ kin_time = 0.0; + if (use.Get_kinetics_in() == TRUE) { - kinetics_ptr = kinetics_bsearch(-2, &m); + //kinetics_ptr = kinetics_bsearch(-2, &m); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); + kin_time = kinetics_ptr->Current_step((incremental_reactions==TRUE), reaction_step); +#ifdef SKIP if (incremental_reactions == FALSE) { if (kinetics_ptr->count_steps > 0) @@ -1528,6 +1532,7 @@ reactions(void) } } } +#endif } if (incremental_reactions == FALSE || (incremental_reactions == TRUE && reaction_step == 1)) @@ -1566,10 +1571,16 @@ reactions(void) * save end of reaction */ memcpy(&save, &save_data, sizeof(struct save)); + if (use.Get_kinetics_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_kinetics_map, -2, use.Get_n_kinetics_user()); + } +#ifdef SKIP if (use.Get_kinetics_in() == TRUE) { kinetics_duplicate(-2, use.Get_n_kinetics_user()); } +#endif saver(); /* free_model_allocs(); */ @@ -1651,12 +1662,31 @@ saver(void) n = save.n_ss_assemblage_user; xss_assemblage_save(n); Utilities::Rxn_copies(Rxn_ss_assemblage_map, save.n_ss_assemblage_user, save.n_ss_assemblage_user_end); - //for (i = save.n_ss_assemblage_user + 1; - // i <= save.n_ss_assemblage_user_end; i++) - //{ - // ss_assemblage_duplicate(n, i); - //} } + if (save.kinetics == TRUE && use.Get_kinetics_in() == TRUE + /*&& use.Get_kinetics_ptr() != NULL */) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); + } + else if (use.Get_kinetics_in() != FALSE) + { + //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); + } + if (use.Get_kinetics_ptr() != NULL) + { + n = use.Get_kinetics_ptr()->Get_n_user(); + for (i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) + { + //kinetics_duplicate(n, i); + Utilities::Rxn_copy(Rxn_kinetics_map, n, i); + } + } + } +#ifdef SKIP if (save.kinetics == TRUE && use.Get_kinetics_in() == TRUE /*&& use.Get_kinetics_ptr() != NULL */) { @@ -1677,6 +1707,7 @@ saver(void) } } } +#endif return (OK); } /* ---------------------------------------------------------------------- */ @@ -2538,6 +2569,19 @@ copy_use(int i) /* * Find kinetics */ + if (use.Get_kinetics_in() == TRUE) + { + //kinetics_duplicate(use.Get_n_kinetics_user(), i); + Utilities::Rxn_copy(Rxn_kinetics_map, use.Get_n_kinetics_user(), i); + save.kinetics = TRUE; + save.n_kinetics_user = i; + save.n_kinetics_user_end = i; + } + else + { + save.kinetics = FALSE; + } +#ifdef SKIP if (use.Get_kinetics_in() == TRUE) { kinetics_duplicate(use.Get_n_kinetics_user(), i); @@ -2549,6 +2593,7 @@ copy_use(int i) { save.kinetics = FALSE; } +#endif /* * Find surface */ @@ -2683,7 +2728,7 @@ step_save_surf(int n_user) * * input: n_user is user solution number of target */ - int i, j, k, n, m; + int i, j, k, n; struct surface *surface_ptr; /* * Malloc space for solution data @@ -2719,7 +2764,29 @@ step_save_surf(int n_user) /* * Update grams */ - /*if (surface_ptr->edl == TRUE && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) { */ + if ((surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) + { + for (j = 0; j < surface_ptr->count_comps; j++) + { + if (surface_ptr->comps[j].rate_name != NULL) + { + cxxKinetics *kinetics_ptr = use.Get_kinetics_ptr(); + for (size_t m = 0; m < kinetics_ptr->Get_kinetics_comps().size(); m++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[m]); + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), + surface_ptr->comps[j].rate_name) != 0) + continue; + surface_ptr->charge[surface_ptr->comps[j].charge].grams = + kinetics_comp_ptr->Get_m(); + break; + } + } + } + } +#ifdef SKIP if ((surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) { @@ -2740,6 +2807,7 @@ step_save_surf(int n_user) } } } +#endif return (OK); } @@ -2977,14 +3045,14 @@ copy_entities(void) { for (j = 0; j < copy_kinetics.count; j++) { - if (kinetics_bsearch(copy_kinetics.n_user[j], &n) != NULL) + if (Utilities::Rxn_find(Rxn_kinetics_map, copy_kinetics.n_user[j]) != NULL) { for (i = copy_kinetics.start[j]; i <= copy_kinetics.end[j]; i++) { if (i == copy_kinetics.n_user[j]) continue; - kinetics_duplicate(copy_kinetics.n_user[j], i); + Utilities::Rxn_copy(Rxn_kinetics_map, copy_kinetics.n_user[j], i); } } else @@ -3001,7 +3069,6 @@ copy_entities(void) { for (j = 0; j < copy_ss_assemblage.count; j++) { - //if (ss_assemblage_bsearch(copy_ss_assemblage.n_user[j], &n) != NULL) if (Utilities::Rxn_find(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j]) != NULL) { for (i = copy_ss_assemblage.start[j]; @@ -3009,7 +3076,6 @@ copy_entities(void) { if (i == copy_ss_assemblage.n_user[j]) continue; - //ss_assemblage_duplicate(copy_ss_assemblage.n_user[j], i); Utilities::Rxn_copy(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j], i); } } diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 14eb6f90..9d5e5ee7 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -10,7 +10,7 @@ #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" - +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: array_print(LDBLE * array_l, int row_count, int column_count, @@ -94,7 +94,7 @@ int Phreeqc:: punch_all(void) /* ---------------------------------------------------------------------- */ { - int i; + //int i; //#ifndef PHREEQ98 /* if not PHREEQ98 use the standard declaration */ // if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE) && user_graph->commands == NULL) @@ -113,11 +113,13 @@ punch_all(void) //#else /* if PHREEQ98 execute punch_user_graph first, that is, before punch.in and pr.punch is checked */ if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); } else if (use.Get_kinetics_in() != FALSE) { - use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); } #if defined PHREEQ98 if (pr.user_graph == TRUE) @@ -830,6 +832,218 @@ print_reaction(void) print_kinetics(void) /* ---------------------------------------------------------------------- */ { +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + //int i, j; + LDBLE sim_time; + cxxKinetics *kinetics_ptr; + if (pr.kinetics == FALSE || pr.all == FALSE) + return (OK); + if (state < REACTION) + return (OK); + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); + } + else + { + //kinetics_ptr = kinetics_bsearch(-2, &i); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); + } + } + if (kinetics_ptr == NULL) + return (OK); +/* + * determine time step + */ + if (state == TRANSPORT || state == PHAST) + { + kin_time_x = timest; + } + else if (state == ADVECTION) + { + kin_time_x = advection_kin_time; + } + sim_time = 0.; + if (run_info.Get_run_cells()) + { + sim_time = rate_sim_time; + } + else + { + if (incremental_reactions == TRUE) + { + if (!kinetics_ptr->Get_equalIncrements()) + { + for (int i = 0; i < reaction_step; i++) + { + if (i < (int) kinetics_ptr->Get_steps().size()) + { + sim_time += kinetics_ptr->Get_steps()[i]; + } + else + { + sim_time += kinetics_ptr->Get_steps().back(); + } + } + } + else + { + if (reaction_step > kinetics_ptr->Get_count()) + { + sim_time = kinetics_ptr->Get_steps().front(); + } + else + { + sim_time = + reaction_step * kinetics_ptr->Get_steps().front() / + ((LDBLE) (kinetics_ptr->Get_count())); + } + } + } +#ifdef SKIP + if (incremental_reactions == TRUE) + { + //if (kinetics_ptr->count_steps > 0) + if (!kinetics_ptr->Get_equalIncrements()) + { + for (i = 0; i < reaction_step; i++) + { + if (i < kinetics_ptr->count_steps) + { + sim_time += kinetics_ptr->steps[i]; + } + else + { + sim_time += + kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; + } + } + } + else if (kinetics_ptr->count_steps < 0) + { + if (reaction_step > -kinetics_ptr->count_steps) + { + sim_time = kinetics_ptr->steps[0]; + } + else + { + sim_time = + reaction_step * kinetics_ptr->steps[0] / + ((LDBLE) (-kinetics_ptr->count_steps)); + } + } + } +#endif + } +/* + * Print amount of reaction + */ + if (phast == FALSE) + { + output_msg(sformatf("Kinetics %d.\t%s\n\n", + use.Get_n_kinetics_user(), kinetics_ptr->Get_description().c_str())); + } + else + { + output_msg(sformatf("Kinetics.\n\n")); + } +/* + * Print reaction + */ + if (state == TRANSPORT) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) (initial_total_time + transport_step * timest))); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == ADVECTION) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) (initial_total_time + + advection_step * advection_kin_time))); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == PHAST) + { + output_msg(sformatf("\tTime: %g seconds\n", + (double) rate_sim_time_end)); + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else if (state == REACTION) + { + if (incremental_reactions == FALSE) + { + output_msg(sformatf("\tTime step: %g seconds\n\n", + (double) kin_time_x)); + } + else + { + output_msg(sformatf( + "\tTime step: %g seconds (Incremented time: %g seconds)\n\n", + (double) kin_time_x, (double) sim_time)); + } + } + output_msg(sformatf("\t%-15s%12s%12s %-15s%12s\n\n", + "Rate name", "Delta Moles", "Total Moles", "Reactant", + "Coefficient")); + //for (i = 0; i < kinetics_ptr->count_comps; i++) + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + if (state != TRANSPORT && state != PHAST) + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + kinetics_comp_ptr->Get_rate_name().c_str(), + (double) -kinetics_comp_ptr->Get_moles(), + (double) kinetics_comp_ptr->Get_m())); + } + else + { + output_msg(sformatf("\t%-15s%12.3e%12.3e", + kinetics_comp_ptr->Get_rate_name().c_str(), + (double) (kinetics_comp_ptr->Get_m() - + kinetics_comp_ptr->Get_initial_moles()), + (double) kinetics_comp_ptr->Get_m())); + } + //for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); + for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) + { + std::string name = it->first; + LDBLE coef = it->second; + if (it == kinetics_comp_ptr->Get_namecoef().begin()) + { + output_msg(sformatf(" %-15s%12g\n", + name.c_str(), + (double) coef)); + } + else + { + output_msg(sformatf("\t%39s %-15s%12g\n", " ", + name.c_str(), + (double) coef)); + } + } + } + output_msg(sformatf("\n")); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ + int Phreeqc:: +print_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ /* * prints kinetic reaction, * should be called only on final kinetic step @@ -995,7 +1209,7 @@ print_kinetics(void) output_msg(sformatf("\n")); return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_master_reactions(void) @@ -2200,7 +2414,63 @@ print_totals(void) return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +print_user_print(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Print with user defined BASIC print routine + */ + cxxKinetics *kinetics_ptr; + char l_command[] = "run"; + + if (pr.user_print == FALSE || pr.all == FALSE) + return (OK); + if (user_print->commands == NULL) + return (OK); + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + kinetics_ptr = use.Get_kinetics_ptr(); + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); + } + else + { + //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); + } + } + print_centered("User print"); + if (user_print->new_def == TRUE) + { + /* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */ + if (basic_compile + (user_print->commands, &user_print->linebase, + &user_print->varbase, &user_print->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + user_print->new_def = FALSE; + } + if (basic_run + (l_command, user_print->linebase, user_print->varbase, + user_print->loopbase) != 0) + { + error_msg("Fatal Basic error in USER_PRINT.", STOP); + } + output_msg(sformatf("\n")); + if (use.Get_kinetics_in() == TRUE) + { + use.Set_kinetics_ptr(kinetics_ptr); + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: print_user_print(void) @@ -2256,7 +2526,7 @@ print_user_print(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_using(void) @@ -2274,7 +2544,7 @@ print_using(void) //struct ss_assemblage *ss_assemblage_ptr; //struct gas_phase *gas_phase_ptr; //struct irrev *irrev_ptr; - struct kinetics *kinetics_ptr; + //struct kinetics *kinetics_ptr; int n; if (pr.use == FALSE || pr.all == FALSE) @@ -2380,16 +2650,19 @@ print_using(void) } if (use.Get_kinetics_in() == TRUE) { + cxxKinetics * kinetics_ptr; if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &n); + //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &n); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); } else { - kinetics_ptr = kinetics_bsearch(-2, &n); + //kinetics_ptr = kinetics_bsearch(-2, &n); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); } output_msg(sformatf("Using kinetics %d.\t%s\n", - use.Get_n_kinetics_user(), kinetics_ptr->description)); + use.Get_n_kinetics_user(), kinetics_ptr->Get_description().c_str())); } output_msg(sformatf("\n")); return (OK); @@ -2897,6 +3170,37 @@ punch_identifiers(void) if (state == REACTION && incremental_reactions == TRUE && use.Get_kinetics_ptr() != NULL) { + if (!use.Get_kinetics_ptr()->Get_equalIncrements()) + { + reaction_time = 0.0; + for (i = 0; i < reaction_step; i++) + { + //if (i < use.Get_kinetics_ptr()->count_steps) + if (i < (int) use.Get_kinetics_ptr()->Get_steps().size()) + { + reaction_time += use.Get_kinetics_ptr()->Get_steps()[i]; + } + else + { + reaction_time += + use.Get_kinetics_ptr()->Get_steps().back(); + } + } + } + else + { + if (reaction_step > use.Get_kinetics_ptr()->Get_count()) + { + reaction_time = use.Get_kinetics_ptr()->Get_steps().front(); + } + else + { + reaction_time = + reaction_step * use.Get_kinetics_ptr()->Get_steps().front() / + ((LDBLE) (use.Get_kinetics_ptr()->Get_count())); + } + } +#ifdef SKIP if (use.Get_kinetics_ptr()->count_steps > 0) { reaction_time = 0.0; @@ -2926,6 +3230,7 @@ punch_identifiers(void) ((LDBLE) (-use.Get_kinetics_ptr()->count_steps)); } } +#endif } if (state == REACTION) { @@ -3140,7 +3445,80 @@ punch_saturation_indices(void) } return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * prints kinetic reaction, + * should be called only on final kinetic step + */ + //int i, j; + cxxKinetics *kinetics_ptr; + LDBLE moles, delta_moles; + kinetics_ptr = NULL; + if (use.Get_kinetics_in() == TRUE) + { + if (state == TRANSPORT || state == PHAST || state == ADVECTION) + { + //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); + } + else + { + //kinetics_ptr = kinetics_bsearch(-2, &i); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); + } + } + for (int i = 0; i < punch.count_kinetics; i++) + { + moles = 0.0; + delta_moles = 0.0; + if (kinetics_ptr != NULL) + { + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (strcmp_nocase + (punch.kinetics[i].name, + kinetics_comp_ptr->Get_rate_name().c_str()) == 0) + { + if (state != TRANSPORT && state != PHAST) + { + moles = kinetics_comp_ptr->Get_m(); + delta_moles = - kinetics_comp_ptr->Get_moles(); + } + else + { + moles = kinetics_comp_ptr->Get_m(); + delta_moles = + kinetics_comp_ptr->Get_m() - + kinetics_comp_ptr->Get_initial_moles(); + } + break; + } + } + } + if (punch.high_precision == FALSE) + { + fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t", + (double) moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t", + (double) -delta_moles); + } + else + { + fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t", + (double) moles); + fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t", + (double) -delta_moles); + } + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_kinetics(void) @@ -3159,7 +3537,8 @@ punch_kinetics(void) { if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); } else { @@ -3211,7 +3590,7 @@ punch_kinetics(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_user_punch(void) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index d09d9968..9694ac6e 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -14,8 +14,7 @@ #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" -#include "SS.h" -#include "SScomp.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -271,7 +270,8 @@ read_input(void) Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, this); break; case Keywords::KEY_KINETICS_RAW: - read_kinetics_raw(); + //read_kinetics_raw(); + Utilities::Rxn_read_raw(Rxn_kinetics_map, this); break; case Keywords::KEY_SOLID_SOLUTIONS_RAW: Utilities::Rxn_read_raw(Rxn_ss_assemblage_map, this); @@ -310,7 +310,8 @@ read_input(void) Utilities::Rxn_read_modify(Rxn_gas_phase_map, this); break; case Keywords::KEY_KINETICS_MODIFY: - read_kinetics_modify(); + //read_kinetics_modify(); + Utilities::Rxn_read_modify(Rxn_kinetics_map, this); break; case Keywords::KEY_DELETE: read_delete(); @@ -2115,7 +2116,490 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) inverse_ptr->count_phases++; return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_kinetics(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads kinetics data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ +/* + * Read kinetics + */ + char *ptr; + char *description; + std::string token; + int n_user, n_user_end; + LDBLE step; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "tol", /* 0 */ + "m", /* 1 */ + "m0", /* 2 */ + "parms", /* 3 */ + "formula", /* 4 */ + "steps", /* 5 */ + "step_divide", /* 6 */ + "parameters", /* 7 */ + "runge-kutta", /* 8 */ + "runge_kutta", /* 9 */ + "rk", /* 10 */ + "bad_step_max", /* 11 */ + "cvode", /* 12 */ + "cvode_steps", /* 13 */ + "cvode_order", /* 14 */ + "time_steps" /* 15 */ + }; + int count_opt_list = 16; + +/* + * Read kinetics number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + cxxKinetics temp_kinetics; + temp_kinetics.Set_n_user(n_user); + temp_kinetics.Set_n_user_end(n_user_end); + temp_kinetics.Set_description(description); + description = (char *) free_check_null(description); + cxxKineticsComp *kinetics_comp_ptr = NULL; +/* + * Set use data to first read + */ + if (use.Get_kinetics_in() == FALSE) + { + use.Set_kinetics_in(true); + use.Set_n_kinetics_user(n_user); + } +/* + * Read kinetics data + */ + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: /* allocate space, read new name */ + if (kinetics_comp_ptr) + { + temp_kinetics.Get_kinetics_comps().push_back(*kinetics_comp_ptr); + delete kinetics_comp_ptr; + } + kinetics_comp_ptr = new cxxKineticsComp; + ptr = line; + copy_token(token, &ptr); + kinetics_comp_ptr->Set_rate_name(token.c_str()); + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in KINETICS keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* tolerance */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char) == DIGIT) + { + kinetics_comp_ptr->Set_tol(strtod(token.c_str(), &ptr)); + } + else + { + error_string = sformatf( + "Expecting numerical value for tolerance, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 1: /* m */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char) == DIGIT) + { + kinetics_comp_ptr->Set_m(strtod(token.c_str(), &ptr)); + } + else + { + error_string = sformatf( + "Expecting numerical value for moles of reactant (m), but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 2: /* m0 */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + prev_next_char = next_char; + if (copy_token(token, &next_char) == DIGIT) + { + kinetics_comp_ptr->Set_m0(strtod(token.c_str(), &ptr)); + } + else + { + error_string = sformatf( + "Expecting numerical value for initial moles of reactant (m0), but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 3: /* parms */ + case 7: /* parameters */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + int j; + while ((j = copy_token(token, &next_char)) != EMPTY) + { + /* + * Store a LDBLE parameter + */ + if (j == DIGIT) + { + kinetics_comp_ptr->Get_d_params().push_back(strtod(token.c_str(), &ptr)); + } + else + { + /* + * Store a character parameter + */ + kinetics_comp_ptr->Get_c_params().push_back(token); + } + } + } + break; + case 4: /* formula */ + if (kinetics_comp_ptr == NULL) + { + error_string = sformatf( "No rate name has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + /* + * Store reactant name, default coefficient + */ + ptr = next_char; + bool have_name = false; + std::string name; + LDBLE coef; + while (copy_token(token, &ptr) != EMPTY) + { + coef = 1; + if (isalpha((int) token[0]) || (token[0] == '(') + || (token[0] == '[')) + { + if (have_name) + { + kinetics_comp_ptr->Get_namecoef().add(name.c_str(), coef); + } + name = token; + have_name = true; + } + else + { + if (!have_name) + { + error_string = sformatf( "No phase or chemical formula has been defined."); + error_msg(error_string, CONTINUE); + input_error++; + } + /* + * Store relative coefficient + */ + int j = sscanf(token.c_str(), SCANFORMAT, &coef); + + if (j == 1) + { + kinetics_comp_ptr->Get_namecoef().add(name.c_str(), coef); + have_name = false; + } + else + { + error_msg + ("Reading relative coefficient of reactant.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + } + } + } + if (have_name) + { + kinetics_comp_ptr->Get_namecoef().add(name.c_str(), coef); + } + } + break; + case 5: /* steps */ + case 15: /* time_steps */ + /* + * Read one or more kinetics time increments + */ + { + int j; + while ((j = copy_token(token, &next_char)) == DIGIT) + { + /* Read next step increment(s) */ + /* multiple, equal timesteps 15 aug. 2005 */ + if (Utilities::replace("*", " ", token)) + { + int k; + if (sscanf(token.c_str(), "%d" SCANFORMAT, &k, &step) == 2) + { + for (int i = 0; i < k; i++) + { + temp_kinetics.Get_steps().push_back(step); + } + } + else + { + input_error++; + error_msg + ("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", + CONTINUE); + } + } + else + { + step = strtod(token.c_str(), &ptr); + temp_kinetics.Get_steps().push_back(step); + } + } + if (j == EMPTY) + break; + /* + * Read number of increments + */ + if (temp_kinetics.Get_steps().size() != 1) + { + error_msg + ("To define equal time increments, only one total time should be defined.", + CONTINUE); + input_error++; + break; + } + temp_kinetics.Set_equalIncrements(true); + do + { + int i = 1; + j = sscanf(token.c_str(), "%d", &i); + if (j == 1) + { + temp_kinetics.Set_count(abs(i)); + break; + } + else if (j == 1 && i < 0) + { + error_msg + ("Expecting positive number for number of equal " + "time increments for kinetics.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + while (copy_token(token, &next_char) != EMPTY); + } + break; + case 6: /* step_divide */ + if (copy_token(token, &next_char) == DIGIT) + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_kinetics.Set_step_divide(dummy); + } + else + { + error_string = sformatf( + "Expecting numerical value for step_divide."); + error_msg(error_string, CONTINUE); + input_error++; + } + break; + case 8: /* runge-kutta */ + case 9: /* runge_kutta */ + case 10: /* rk */ + { + int j = copy_token(token, &next_char); + if (j == DIGIT) + { + temp_kinetics.Set_rk((int) strtod(token.c_str(), &ptr)); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting order for Runge-Kutta method."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 11: /* bad_step_max */ + { + int j = copy_token(token, &next_char); + if (j == DIGIT) + { + temp_kinetics.Set_bad_step_max((int) strtod(token.c_str(), &ptr)); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( "Expecting maximal bad steps number."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 12: /* cvode */ + temp_kinetics.Set_use_cvode(get_true_false(next_char, TRUE) == TRUE); + break; + case 13: /* cvode_steps */ + { + int j = copy_token(token, &next_char); + if (j == DIGIT) + { + temp_kinetics.Set_cvode_steps((int) strtod(token.c_str(), &ptr)); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting maximum number of steps for one call to cvode."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + case 14: /* cvode_order */ + { + int j = copy_token(token, &next_char); + if (j == DIGIT) + { + temp_kinetics.Set_cvode_order((int) strtod(token.c_str(), &ptr)); + } + else if (j == EMPTY) + { + } + else + { + error_string = sformatf( + "Expecting number of terms (order) used in cvode (1-5)."); + error_msg(error_string, CONTINUE); + input_error++; + } + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + + // save last comp + if (kinetics_comp_ptr) + { + temp_kinetics.Get_kinetics_comps().push_back(*kinetics_comp_ptr); + delete kinetics_comp_ptr; + } +/* + * Default reactant + */ + for (size_t i = 0; i < temp_kinetics.Get_kinetics_comps().size(); i++) + { + cxxKineticsComp *kinetics_comp_ptr = &(temp_kinetics.Get_kinetics_comps()[i]); + if (kinetics_comp_ptr->Get_namecoef().size() == 0) + { + kinetics_comp_ptr->Get_namecoef().add(kinetics_comp_ptr->Get_rate_name().c_str(), 1.0); + } + } +/* + * Default 1 sec + */ + if (temp_kinetics.Get_steps().size() == 0) + { + temp_kinetics.Get_steps().push_back(1.0); + } +/* + * set defaults for moles + */ + for (size_t i = 0; i < temp_kinetics.Get_kinetics_comps().size(); i++) + { + cxxKineticsComp *kinetics_comp_ptr = &(temp_kinetics.Get_kinetics_comps()[i]); + if (kinetics_comp_ptr->Get_m0() < 0) + { + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_m0(1); + } + else + { + kinetics_comp_ptr->Set_m0(kinetics_comp_ptr->Get_m()); + } + } + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_m(kinetics_comp_ptr->Get_m0()); + } + } + Rxn_kinetics_map[n_user] = temp_kinetics; + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_kinetics(void) @@ -2659,7 +3143,7 @@ read_kinetics(void) } return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE * Phreeqc:: read_list_doubles(char **ptr, int *count_doubles) @@ -4354,7 +4838,7 @@ read_reaction_steps(cxxReaction *reaction_ptr) /* * Read number of equal increments, store as negative integer */ - if (reaction_ptr->Get_actualSteps() != 1) + if (reaction_ptr->Get_reaction_steps() != 1) { error_msg ("To define equal increments, only one reaction increment should be defined.", @@ -9489,7 +9973,6 @@ read_solid_solutions(void) copy_token(token, &ptr); ss_ptr->Set_name(token); ss_ptr->Set_total_moles(NAN); - std::cerr << "Read: " << ss_ptr->Get_total_moles() << "\n"; break; } if (return_value == EOF || return_value == KEYWORD) diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 0833eea0..d3060cf1 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -15,6 +15,7 @@ #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -855,7 +856,7 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) } else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) { - if (step_number > (int) reaction_ptr->Get_actualSteps()) + if (step_number > (int) reaction_ptr->Get_reaction_steps()) { step_x = reaction_ptr->Get_steps()[0]; } @@ -863,7 +864,7 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) { step_x = reaction_ptr->Get_steps()[0] * ((LDBLE) step_number) / - ((LDBLE) (reaction_ptr->Get_actualSteps())); + ((LDBLE) (reaction_ptr->Get_reaction_steps())); } } else @@ -876,9 +877,9 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) /* Incremental reactions */ if (!reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) { - if (step_number > (int) reaction_ptr->Get_actualSteps()) + if (step_number > (int) reaction_ptr->Get_reaction_steps()) { - step_x = reaction_ptr->Get_steps()[reaction_ptr->Get_actualSteps() - 1]; + step_x = reaction_ptr->Get_steps()[reaction_ptr->Get_reaction_steps() - 1]; } else { @@ -887,13 +888,13 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) } else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) { - if (step_number > (int) reaction_ptr->Get_actualSteps()) + if (step_number > (int) reaction_ptr->Get_reaction_steps()) { step_x = 0; } else { - step_x = reaction_ptr->Get_steps()[0] / ((LDBLE) (reaction_ptr->Get_actualSteps())); + step_x = reaction_ptr->Get_steps()[0] / ((LDBLE) (reaction_ptr->Get_reaction_steps())); } } else @@ -1188,6 +1189,54 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +add_kinetics(cxxKinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Add kinetic reaction + */ + //int i; + struct master *master_ptr; +/* + * Add reaction to totals + */ + if (kinetics_ptr->Get_totals().size() == 0) + return (OK); + cxxNameDouble::iterator it = kinetics_ptr->Get_totals().begin(); + for (; it != kinetics_ptr->Get_totals().end(); it++) + { + LDBLE coef = it->second; + struct element *elt_ptr = element_store(it->first.c_str()); + if (elt_ptr == NULL || (master_ptr = elt_ptr->primary) == NULL) + { + input_error++; + error_string = sformatf( + "Element %s in kinetic reaction not found in database.", + it->first.c_str()); + error_msg(error_string, STOP); + } + if (master_ptr->s == s_hplus) + { + total_h_x += coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += coef; + } + else + { + master_ptr->total += coef; + if(master_ptr->total < 0.0) + { + fprintf(stderr, "Negative total\n"); + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: add_kinetics(struct kinetics *kinetics_ptr) /* ---------------------------------------------------------------------- */ { @@ -1227,6 +1276,7 @@ add_kinetics(struct kinetics *kinetics_ptr) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: gas_phase_check(cxxGasPhase *gas_phase_ptr) diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 6a638fab..c92b7918 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -11,6 +11,7 @@ #include "PPassemblage.h" #include "Use.h" #include "SSassemblage.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -140,11 +141,14 @@ clean_up(void) Rxn_gas_phase_map.clear(); /* kinetics */ + Rxn_kinetics_map.clear(); +#ifdef SKIP for (j = 0; j < count_kinetics; j++) { kinetics_free(&kinetics[j]); } kinetics = (struct kinetics *) free_check_null(kinetics); +#endif /* rates */ for (j = 0; j < count_rates; j++) @@ -362,7 +366,7 @@ clean_up(void) //count_exchange = 0; count_surface = 0; //count_gas_phase = 0; - count_kinetics = 0; + //count_kinetics = 0; //count_ss_assemblage = 0; count_elements = 0; @@ -424,12 +428,14 @@ reinitialize(void) Rxn_gas_phase_map.clear(); /* kinetics */ + Rxn_kinetics_map.clear(); +#ifdef SKIP for (j = 0; j < count_kinetics; j++) { kinetics_free(&kinetics[j]); } count_kinetics = 0; - +#endif /* irreversible reactions */ Rxn_reaction_map.clear(); @@ -970,6 +976,7 @@ inverse_sort(void) } return (OK); } +#ifdef SKIP /* ********************************************************************** * * Routines related to structure "kinetics" @@ -1491,7 +1498,7 @@ kinetics_sort(void) } return (OK); } - +#endif /* ********************************************************************** * * Routines related to structure "master" @@ -4884,8 +4891,6 @@ system_duplicate(int i, int save_old) if (solution_bsearch(i, &n, TRUE) != NULL) solution_duplicate(i, save_old); - //if (pp_assemblage_bsearch(i, &n) != NULL) - // pp_assemblage_duplicate(i, save_old); Utilities::Rxn_copy(Rxn_pp_assemblage_map, i, save_old); Utilities::Rxn_copy(Rxn_exchange_map, i, save_old); @@ -4895,12 +4900,13 @@ system_duplicate(int i, int save_old) Utilities::Rxn_copy(Rxn_gas_phase_map, i, save_old); + Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); +#ifdef SKIP if (kinetics_bsearch(i, &n) != NULL) kinetics_duplicate(i, save_old); - +#endif Utilities::Rxn_copy(Rxn_ss_assemblage_map, i, save_old); - //if (ss_assemblage_bsearch(i, &n) != NULL) - // ss_assemblage_duplicate(i, save_old); + return (OK); } @@ -5174,7 +5180,7 @@ entity_exists(char *name, int n_user) } break; case Kinetics: /* Kinetics */ - if (kinetics_bsearch(n_user, &i) == NULL) + if (Utilities::Rxn_find(Rxn_kinetics_map, n_user) == NULL) { return_value = FALSE; } @@ -5334,6 +5340,7 @@ copier_init(struct copier *copier_ptr) (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); return (OK); } +#ifdef SKIP #include "../cxxKinetics.h" struct kinetics * Phreeqc:: cxxKinetics2kinetics(const cxxKinetics * kin) @@ -5440,6 +5447,7 @@ cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > *el) } return (kinetics_comp_ptr); } +#endif #include "../Solution.h" struct solution * Phreeqc:: cxxSolution2solution(const cxxSolution * sol) @@ -5928,6 +5936,15 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_SSassemblage(use.Get_n_ss_assemblage_user(), entity_ptr); } } + if (use.Get_kinetics_in()) + { + cxxKinetics *entity_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); + if (entity_ptr != NULL) + { + sb.Set_Kinetics(use.Get_n_kinetics_user(), entity_ptr); + } + } +#ifdef SKIP if (use.Get_kinetics_in()) { struct kinetics *struct_entity = kinetics_bsearch(use.Get_n_kinetics_user(), &n); @@ -5937,6 +5954,7 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_Kinetics(use.Get_n_kinetics_user(), &entity); } } +#endif if (use.Get_reaction_in()) { cxxReaction *entity = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); @@ -5998,12 +6016,20 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) } // Kinetics + { + std::map::iterator it; + for (it = Rxn_kinetics_map.begin(); it != Rxn_kinetics_map.end(); it++) + { + sb.Set_Kinetics(it->second.Get_n_user(), &(it->second)); + } + } +#ifdef SKIP for (i = 0; i < count_kinetics; i++) { cxxKinetics entity(&kinetics[i], sb.Get_io()); sb.Set_Kinetics(kinetics[i].n_user, &entity ); } - +#endif // PPassemblages { std::map::iterator it; @@ -6099,6 +6125,14 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) } // Kinetics + { + cxxKinetics *entity_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n); + if (entity_ptr != NULL) + { + sb.Set_Kinetics(n, entity_ptr); + } + } +#ifdef SKIP { if (kinetics_bsearch(n, &pos) != NULL) { @@ -6107,7 +6141,7 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) sb.Set_Kinetics(n, &ent ); } } - +#endif // PPassemblages { cxxPPassemblage *entity_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); @@ -6172,6 +6206,14 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) } // Kinetics + { + std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().find(n); + if (it != sb.Get_Kinetics().end()) + { + Rxn_kinetics_map[n] = it->second; + } + } +#ifdef SKIP { std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().find(n); if (it != sb.Get_Kinetics().end()) @@ -6182,7 +6224,7 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); } } - +#endif // PPassemblages { std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().find(n); @@ -6284,6 +6326,14 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) } // Kinetics + { + std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().begin(); + for ( ; it != sb.Get_Kinetics().end(); it++) + { + Rxn_kinetics_map[it->first] = it->second; + } + } +#ifdef SKIP { std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().begin(); for ( ; it != sb.Get_Kinetics().end(); it++) @@ -6294,7 +6344,7 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); } } - +#endif // PPassemblages { std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().begin(); diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index e9f18e42..ccdfb0d8 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -7,7 +7,7 @@ #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" - +#include "cxxKinetics.h" /* Calling sequence @@ -386,8 +386,8 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) struct surface *surface_ptr; //struct ss_assemblage *ss_assemblage_ptr; //struct gas_phase *gas_phase_ptr; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; + //struct kinetics *kinetics_ptr; + //struct kinetics_comp *kinetics_comp_ptr; int found; LDBLE moles; char *ptr; @@ -614,31 +614,34 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) break; } case Kinetics: - /* - * fill in kinetics - */ - if (n_user[Kinetics] < 0) - break; - kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); - if (kinetics_ptr == NULL) - break; - kinetics_comp_ptr = NULL; - for (j = 0; j < kinetics_ptr->count_comps; j++) { - kinetics_comp_ptr = &kinetics_ptr->comps[j]; - if (kinetics_comp_ptr->rate_name == tally_table[i].name) + /* + * fill in kinetics + */ + if (n_user[Kinetics] < 0) break; - if (strcmp_nocase - (kinetics_comp_ptr->rate_name, tally_table[i].name) == 0) + //kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n_user[Kinetics]); + if (kinetics_ptr == NULL) break; + cxxKineticsComp * kinetics_comp_ptr = NULL; + for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) + { + kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + if (string_hsave(kinetics_comp_ptr->Get_rate_name().c_str()) == tally_table[i].name) + break; + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), tally_table[i].name) == 0) + break; + } + if (j >= (int) kinetics_ptr->Get_kinetics_comps().size()) + break; + moles = kinetics_comp_ptr->Get_m(); + count_elts = 0; + paren_count = 0; + add_elt_list(tally_table[i].formula, moles); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); } - if (j >= kinetics_ptr->count_comps) - break; - moles = kinetics_comp_ptr->m; - count_elts = 0; - paren_count = 0; - add_elt_list(tally_table[i].formula, moles); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; case Mix: break; @@ -707,7 +710,7 @@ build_tally_table(void) * Also calculates a number greater than all user numbers and * stores in global variable first_user_number. */ - int i, j, k, l, n, p, save_print_use; + int j, k, l, n, p, save_print_use; int count_tt_reaction, count_tt_exchange, count_tt_surface, count_tt_gas_phase; int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; @@ -716,8 +719,8 @@ build_tally_table(void) //struct ss_assemblage *ss_assemblage_ptr; //struct s_s *s_s_ptr; //struct s_s_comp *s_s_comp_ptr; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; + //struct kinetics *kinetics_ptr; + //struct kinetics_comp *kinetics_comp_ptr; struct phase *phase_ptr; @@ -936,6 +939,73 @@ build_tally_table(void) * Add kinetic reactants */ count_tt_kinetics = 0; + if (Rxn_kinetics_map.size() > 0) + { + std::map::iterator it; + for (it = Rxn_kinetics_map.begin(); it != Rxn_kinetics_map.end(); it++) + { + cxxKinetics *kinetics_ptr = &(it->second); + for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + /* + * check if already in tally_table + */ + for (l = 1; l < count_tally_table_columns; l++) + { + if (tally_table[l].type == Kinetics && + tally_table[l].name == string_hsave(kinetics_comp_ptr->Get_rate_name().c_str())) + break; + } + if (l < count_tally_table_columns) + continue; + /* + * Add to table + */ + count_tt_kinetics++; + n = count_tally_table_columns; + extend_tally_table(); + tally_table[n].name = string_hsave(kinetics_comp_ptr->Get_rate_name().c_str()); + tally_table[n].type = Kinetics; + /* + * get formula for kinetic component + */ + count_elts = 0; + paren_count = 0; + phase_ptr = NULL; + //if (kinetics_ptr->comps[j].count_list == 1) + if (kinetics_comp_ptr->Get_namecoef().size() == 1) + { + //strcpy(token, kinetics_ptr->comps[j].list[0].name); + strcpy(token, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str()); + phase_ptr = phase_bsearch(token, &p, FALSE); + } + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, 1.0); + } + else + { + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); + //for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) + for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) + { + std::string name = it->first; + LDBLE coef = it->second; + char * temp_name = string_duplicate(name.c_str()); + ptr = temp_name; + get_elts_in_species(&ptr, 1.0 * coef); + free_check_null(temp_name); + } + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + tally_table[n].formula = elt_list_save(); + } + } + } +#ifdef SKIP if (count_kinetics > 0) { for (i = 0; i < count_kinetics; i++) @@ -998,6 +1068,7 @@ build_tally_table(void) } } } +#endif #ifdef SKIP /* * Debug print for table definition @@ -1117,21 +1188,88 @@ add_all_components_tally(void) /* * Add elements in kinetic reactions */ + { + std::map::iterator it = Rxn_kinetics_map.begin(); + for ( ; it != Rxn_kinetics_map.end(); it++) + { + calc_dummy_kinetic_reaction_tally(&(it->second)); + add_kinetics(&(it->second)); + } + } +#ifdef SKIP for (i = 0; i < count_kinetics; i++) { calc_dummy_kinetic_reaction_tally(&kinetics[i]); add_kinetics(&kinetics[i]); } +#endif /* * reset pr.use */ pr.use = save_print_use; return; } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) +calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components and add positive amount of each reactant + */ + LDBLE coef; + //char token[MAX_LENGTH]; + char *ptr; + struct phase *phase_ptr; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ + //free_check_null(kinetics_ptr->totals); + kinetics_ptr->Get_totals().clear(); + count_elts = 0; + paren_count = 0; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + coef = 1.0; +/* + * Reactant is a pure phase, copy formula into token + */ + phase_ptr = NULL; + if (kinetics_comp_ptr->Get_namecoef().size() == 1) + { + std::string name = kinetics_comp_ptr->Get_namecoef().begin()->first; + int j; + phase_ptr = phase_bsearch(name.c_str(), &j, FALSE); + } + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, coef); + } + else + { + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); + for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) + { + std::string name = it->first; + char * temp_name = string_duplicate(name.c_str()); + ptr = temp_name; + get_elts_in_species(&ptr, coef); + free_check_null(temp_name); + } + } + + } + //kinetics_ptr->totals = elt_list_save(); + kinetics_ptr->Set_totals(elt_list_NameDouble()); + + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr) /* ---------------------------------------------------------------------- */ { /* @@ -1146,7 +1284,8 @@ calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) * Go through list and generate list of elements and * coefficient of elements in reaction */ - free_check_null(kinetics_ptr->totals); + //free_check_null(kinetics_ptr->totals); + kinetics_ptr->Get_totals().clear(); count_elts = 0; paren_count = 0; for (i = 0; i < kinetics_ptr->count_comps; i++) @@ -1181,7 +1320,7 @@ calc_dummy_kinetic_reaction_tally(struct kinetics *kinetics_ptr) return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: extend_tally_table(void) @@ -1256,6 +1395,21 @@ set_reaction_temperature(int n_user, LDBLE tc) int Phreeqc:: set_kinetics_time(int n_user, LDBLE step) /* ---------------------------------------------------------------------- */ +{ + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n_user); + + if (kinetics_ptr == NULL) + return (ERROR); + kinetics_ptr->Get_steps().clear(); + kinetics_ptr->Get_steps().push_back(step); + kinetics_ptr->Set_equalIncrements(false); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_kinetics_time(int n_user, LDBLE step) +/* ---------------------------------------------------------------------- */ { int n; struct kinetics *kinetics_ptr; @@ -1267,3 +1421,4 @@ set_kinetics_time(int n_user, LDBLE step) kinetics_ptr->count_steps = 1; return (OK); } +#endif \ No newline at end of file diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 04e8874b..2dfe21f4 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -5,7 +5,7 @@ #include "GasPhase.h" #include "PPassemblage.h" #include "SSassemblage.h" - +#include "cxxKinetics.h" #define ZERO_TOL 1.0e-30 /* ---------------------------------------------------------------------- */ @@ -13,7 +13,7 @@ int Phreeqc:: tidy_model(void) /* ---------------------------------------------------------------------- */ { - int i, j; + int i; int n_user, last; int new_named_logk; /* @@ -173,13 +173,13 @@ tidy_model(void) phases[i]->pr_p = 0.0; phases[i]->pr_phi = 1.0; } - +#ifdef SKIP /* kinetics */ if (new_kinetics) { kinetics_sort(); } - +#endif /* named_log_k */ if (new_named_logk) { @@ -289,18 +289,13 @@ tidy_model(void) */ if (new_kinetics) { - for (i = 0; i < count_kinetics; i++) + std::map::iterator it; + for (it = Rxn_kinetics_map.begin(); it != Rxn_kinetics_map.end(); it++) { - if (kinetics[i].n_user_end > kinetics[i].n_user) - { - n_user = kinetics[i].n_user; - last = kinetics[i].n_user_end; - kinetics[i].n_user_end = kinetics[i].n_user; - for (j = n_user + 1; j <= last; j++) - { - kinetics_duplicate(n_user, j); - } - } + n_user = it->second.Get_n_user(); + last = it->second.Get_n_user_end(); + it->second.Set_n_user_end(n_user); + Utilities::Rxn_copies(Rxn_kinetics_map, n_user, last); } } @@ -2906,6 +2901,117 @@ tidy_isotopes(void) int Phreeqc:: tidy_kin_exchange(void) /* ---------------------------------------------------------------------- */ +/* + * If exchanger is related to mineral, exchanger amount is + * set in proportion + */ +{ + //int k; + cxxKinetics *kinetics_ptr; + char *ptr; + LDBLE conc; + + std::map::iterator it = Rxn_exchange_map.begin(); + for ( ; it != Rxn_exchange_map.end(); it++) + { + cxxExchange * exchange_ptr = &(it->second); + if (!exchange_ptr->Get_new_def()) + continue; + if (exchange_ptr->Get_n_user() < 0) + continue; + std::vector comps = exchange_ptr->Vectorize(); + // check elements + for (size_t j = 0; j < comps.size(); j++) + { + if (comps[j]->Get_rate_name().size() == 0) + continue; + /* First find exchange master species */ + cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble::iterator kit = nd.begin(); + bool found_exchange = false; + for (; kit != nd.end(); kit++) + { + /* Find master species */ + struct element *elt_ptr = element_store(kit->first.c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + elt_ptr->name); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_ptr->master->type == EX) + found_exchange = true;; + } + if (!found_exchange) + { + input_error++; + error_string = sformatf( + "Exchange formula does not contain an exchange master species, %s", + comps[j]->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find associated kinetic reaction ... */ + if ((kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, exchange_ptr->Get_n_user())) == NULL) + { + input_error++; + error_string = sformatf( + "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", + exchange_ptr->Get_n_user(), comps[j]->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + size_t k; + for (k = 0; k < kinetics_ptr->Get_kinetics_comps().size(); k++) + { + if (strcmp_nocase + (comps[j]->Get_rate_name().c_str(), + kinetics_ptr->Get_kinetics_comps()[k].Get_rate_name().c_str()) == 0) + { + break; + } + } + if (k == kinetics_ptr->Get_kinetics_comps().size()) + { + input_error++; + error_string = sformatf( + "Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", + comps[j]->Get_rate_name().c_str(), comps[j]->Get_formula().c_str(), exchange_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + continue; + } + + /* use database name for phase */ + comps[j]->Set_rate_name(kinetics_ptr->Get_kinetics_comps()[k].Get_rate_name().c_str()); + + /* make exchanger concentration proportional to mineral ... */ + conc = kinetics_ptr->Get_kinetics_comps()[k].Get_m() * comps[j]->Get_phase_proportion(); + + count_elts = 0; + paren_count = 0; + { + char * temp_formula = string_duplicate(comps[j]->Get_formula().c_str()); + ptr = temp_formula; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comps[j]->Set_totals(elt_list_NameDouble()); +/* + * No check on availability of exchange elements + */ + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_kin_exchange(void) +/* ---------------------------------------------------------------------- */ /* * If exchanger is related to mineral, exchanger amount is * set in proportion @@ -3014,6 +3120,7 @@ tidy_kin_exchange(void) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_min_exchange(void) @@ -3374,7 +3481,239 @@ tidy_min_surface(void) } return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_kin_surface(void) +/* ---------------------------------------------------------------------- */ +/* + * If surface is related to mineral, surface amount is + * set in proportion + */ +{ + int i, j, n, jj, l; + cxxKinetics *kinetics_ptr; + struct surface_comp *comp_ptr; + struct master *master_ptr; + struct phase *phase_ptr; + //char token[MAX_LENGTH]; + char *ptr; + LDBLE conc; + struct elt_list *elt_list_kinetics; + int count_elts_kinetics; + n = -999; + comp_ptr = NULL; + for (i = 0; i < count_surface; i++) + { + if (surface[i].new_def == FALSE) + continue; + if (surface[i].n_user < 0) + continue; + for (j = 0; j < surface[i].count_comps; j++) + { + if (surface[i].comps[j].rate_name == NULL) + continue; + comp_ptr = &surface[i].comps[j]; + comp_ptr->master = NULL; + n = surface[i].n_user; + + /* First find surface master species */ + int k; + for (k = 0; comp_ptr->totals[k].elt != NULL; k++) + { + /* Find master species */ + master_ptr = comp_ptr->totals[k].elt->master; + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( "Master species not in data " + "base for %s, skipping element.", + comp_ptr->totals[k].elt->name); + error_msg(error_string, CONTINUE); + continue; + } + if (master_ptr->type != SURF) + continue; + comp_ptr->master = master_ptr; + break; + } + if (comp_ptr->master == NULL) + { + input_error++; + error_string = sformatf( + "Surface formula does not contain a surface master species, %s", + comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + + /* Now find the kinetic reaction on which surface depends... */ + //if ((kinetics_ptr = kinetics_bsearch(n, &k)) == NULL) + if ((kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n)) == NULL) + { + input_error++; + error_string = sformatf( + "Kinetics %d must be defined to use surface related to kinetic reaction, %s", + n, comp_ptr->formula); + error_msg(error_string, CONTINUE); + continue; + } + for (k = 0; k < (int) kinetics_ptr->Get_kinetics_comps().size(); k++) + { + cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); + if (strcmp_nocase + (comp_ptr->rate_name, + kin_comp_ptr->Get_rate_name().c_str()) == 0) + { + break; + } + } + if (k == (int) kinetics_ptr->Get_kinetics_comps().size()) + { + input_error++; + error_string = sformatf( + "Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", + comp_ptr->rate_name, comp_ptr->formula, n); + error_msg(error_string, CONTINUE); + continue; + } + cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); + /* use database name for phase */ + comp_ptr->rate_name = string_hsave(kin_comp_ptr->Get_rate_name().c_str()); + + /* make surface concentration proportional to mineral ... */ + conc = kin_comp_ptr->Get_m() * comp_ptr->phase_proportion; + +/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ + { + char * temp_formula = string_duplicate(comp_ptr->formula); + ptr = temp_formula; + count_elts = 0; + paren_count = 0; + get_elts_in_species(&ptr, conc); + free_check_null(temp_formula); + } + comp_ptr->totals = + (struct elt_list *) free_check_null(comp_ptr->totals); + comp_ptr->totals = elt_list_save(); + + /* area */ + surface[i].charge[comp_ptr->charge].grams = + kin_comp_ptr->Get_m(); + } +/* + * check on elements + */ + /* Go through each kinetic reaction, add all related surface compositions + * check for negative values + */ + if (surface[i].related_rate == FALSE) + continue; + //kinetics_ptr = kinetics_bsearch(n, &k); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n); + for (size_t k = 0; k < kinetics_ptr->Get_kinetics_comps().size(); k++) + { + cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); + count_elts = 0; + paren_count = 0; + + /* added in kinetics formula */ + cxxNameDouble::iterator jit = kin_comp_ptr->Get_namecoef().begin(); + //for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) + for (; jit != kin_comp_ptr->Get_namecoef().end(); jit++) + { + std::string name = jit->first; + LDBLE coef = jit->second; + phase_ptr = NULL; + phase_ptr = phase_bsearch(name.c_str(), &jj, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, 1.0); + } + else + { + char * temp_name = string_duplicate(name.c_str()); + ptr = temp_name; + get_elts_in_species(&ptr, coef); + free_check_null(temp_name); + } + } + /* save kinetics formula */ + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + elt_list_kinetics = elt_list_save(); + count_elts_kinetics = count_elts; + + /* get surface formulas */ + count_elts = 0; + paren_count = 0; + for (j = 0; j < surface[i].count_comps; j++) + { + comp_ptr = &surface[i].comps[j]; + if (comp_ptr->rate_name == NULL) + continue; + if (strcmp_nocase + (comp_ptr->rate_name, + kin_comp_ptr->Get_rate_name().c_str()) == 0) + { + char * temp_formula = string_duplicate( comp_ptr->formula); + ptr = temp_formula; + get_elts_in_species(&ptr, + -1 * comp_ptr->phase_proportion); + free_check_null(temp_formula); + } + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + for (j = 0; j < count_elts; j++) + { + if (elt_list[j].elt->primary->s->type <= H2O) + { + for (l = 0; l < count_elts_kinetics; l++) + { + if (elt_list[j].elt == elt_list_kinetics[l].elt) + { + break; + } + } + if (l == count_elts_kinetics) + { + input_error++; + error_string = sformatf( + "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", + comp_ptr->formula, + (double) comp_ptr->phase_proportion, + comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } + else if (fabs(elt_list[j].coef) > + fabs(elt_list_kinetics[l].coef)) + { + input_error++; + error_string = sformatf( + "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", + comp_ptr->formula, + (double) comp_ptr->phase_proportion, + comp_ptr->rate_name, elt_list[j].elt->name); + error_msg(error_string, CONTINUE); + } + } + } + elt_list_kinetics = + (struct elt_list *) free_check_null(elt_list_kinetics); + } + } + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_kin_surface(void) @@ -3601,6 +3940,7 @@ tidy_kin_surface(void) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_prep(LDBLE t, cxxSS *ss_ptr, int print) diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index 430fd879..8202c518 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -5,7 +5,7 @@ #include "GasPhase.h" #include "PPassemblage.h" #include "SSassemblage.h" - +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: transport(void) @@ -513,7 +513,8 @@ transport(void) rate_sim_time = rate_sim_time_start + kin_time; /* halftime kinetics for resident water in first cell ... */ - if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) + //if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) + if (Utilities::Rxn_find(Rxn_kinetics_map, first_c) != NULL && count_cells > 1) { cell_no = first_c; kin_time = kin_time_save / 2; @@ -1024,7 +1025,7 @@ int Phreeqc:: mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) /* ---------------------------------------------------------------------- */ { - int j, n, k, l; + int j, n, k; LDBLE t_imm; struct solution *ptr_imm, *ptr_m; /* @@ -1078,7 +1079,8 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); if (multi_Dflag == TRUE) fill_spec(cell_no); - use.Set_kinetics_ptr(kinetics_bsearch(i, &l)); + //use.Set_kinetics_ptr(kinetics_bsearch(i, &l)); + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); if (use.Get_kinetics_ptr() != NULL) { use.Set_n_kinetics_user(i); @@ -1325,9 +1327,9 @@ int Phreeqc:: set_initial_moles(int i) /* ---------------------------------------------------------------------- */ { - struct kinetics *kinetics_ptr; + cxxKinetics *kinetics_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; - int j, k, l, n; + int j, k, l; /* * Pure phase assemblage */ @@ -1363,11 +1365,17 @@ set_initial_moles(int i) /* * Kinetics */ - kinetics_ptr = kinetics_bsearch(i, &n); + //kinetics_ptr = kinetics_bsearch(i, &n); + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); if (kinetics_ptr != NULL) { - for (j = 0; j < kinetics_ptr->count_comps; j++) - kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; + //for (j = 0; j < kinetics_ptr->count_comps; j++) + // kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; + for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_initial_moles(kinetics_comp_ptr->Get_m()); + } } /* * Solid solutions From 02f2e2532ee659d234641aeb61f75c6f63fa958f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jan 2012 17:29:29 +0000 Subject: [PATCH 0431/1077] Fixed bug in jacobian calculation for Cvode git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6087 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 +- phreeqc/kinetics.cpp | 25 +++++++++++++------------ phreeqc/step.cpp | 4 ---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 74f17cd6..9b4af7bc 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -75,7 +75,7 @@ output_msg(const char * str) { (*output_ostream) << str; } - output_flush(); + //output_flush(); } // ---------------------------------------------------------------------- */ // log ostream methods diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 68f46e39..514a9fa5 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -4260,7 +4260,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, N_Vector vtemp3) { int count_cvode_errors; - int j, n_reactions, n_user; + int n_reactions, n_user; LDBLE *initial_rates, del; cxxKinetics *kinetics_ptr; LDBLE step_fraction; @@ -4336,7 +4336,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, } for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + cxxKineticsComp * kinetics_comp_i_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); /* calculate reaction up to current time */ del = 1e-12; pThis->cvode_error = TRUE; @@ -4344,15 +4344,16 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, while (pThis->cvode_error == TRUE) { del /= 10.; - for (j = 0; j < n_reactions; j++) + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { + cxxKineticsComp * kinetics_comp_j_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); /* kinetics_ptr->comps[j].moles = y[j + 1]; kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; */ - kinetics_comp_ptr->Set_moles(Ith(y, j + 1)); - kinetics_comp_ptr->Set_m(pThis->m_original[j] - Ith(y, j + 1)); - if (kinetics_comp_ptr->Get_m() < 0) + kinetics_comp_j_ptr->Set_moles(Ith(y, j + 1)); + kinetics_comp_j_ptr->Set_m(pThis->m_original[j] - Ith(y, j + 1)); + if (kinetics_comp_i_ptr->Get_m() < 0) { /* NOTE: y is not correct if it is greater than m_original @@ -4365,19 +4366,19 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, /* Ith(y,i + 1) = m_original[i]; */ - kinetics_comp_ptr->Set_moles(pThis->m_original[i]); - kinetics_comp_ptr->Set_m(0.0); + kinetics_comp_i_ptr->Set_moles(pThis->m_original[i]); + kinetics_comp_i_ptr->Set_m(0.0); } } /* Add small amount of ith reaction */ //kinetics_ptr->comps[i].m -= del; - kinetics_comp_ptr->Set_m(kinetics_comp_ptr->Get_m() - del); - if (kinetics_comp_ptr->Get_m() < 0) + kinetics_comp_i_ptr->Set_m(kinetics_comp_i_ptr->Get_m() - del); + if (kinetics_comp_i_ptr->Get_m() < 0) { - kinetics_comp_ptr->Set_m(0); + kinetics_comp_i_ptr->Set_m(0); } - kinetics_comp_ptr->Set_moles(kinetics_comp_ptr->Get_moles() + del); + kinetics_comp_i_ptr->Set_moles(kinetics_comp_i_ptr->Get_moles() + del); pThis->calc_final_kinetic_reaction(kinetics_ptr); if (pThis->use.Get_pp_assemblage_ptr() != NULL) { diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index d3060cf1..d21c3c0e 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -1226,10 +1226,6 @@ add_kinetics(cxxKinetics *kinetics_ptr) else { master_ptr->total += coef; - if(master_ptr->total < 0.0) - { - fprintf(stderr, "Negative total\n"); - } } } return (OK); From 23121d787663166d9506a0e9cdd6e05e8af5c6da Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jan 2012 18:21:18 +0000 Subject: [PATCH 0432/1077] Initialize PBasic structures. Fixed logic bug with kin_time in Advection git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6088 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ PBasic.h | 3 +++ phreeqc/advection.cpp | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index addf1d17..5c9f3293 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1634,6 +1634,7 @@ LDBLE PBasic:: realfactor(struct LOC_exec *LINK) { valrec n; + valrec_init(&n); n = factor(LINK); if (n.stringval) @@ -1645,6 +1646,7 @@ char * PBasic:: strfactor(struct LOC_exec * LINK) { valrec n; + valrec_init(&n); n = factor(LINK); if (!n.stringval) @@ -1657,6 +1659,7 @@ char * PBasic:: stringfactor(char * Result, struct LOC_exec * LINK) { valrec n; + valrec_init(&n); n = factor(LINK); if (!n.stringval) @@ -1671,6 +1674,7 @@ const char * PBasic:: stringfactor(std::string & Result, struct LOC_exec * LINK) { valrec n; + valrec_init(&n); n = factor(LINK); if (!n.stringval) @@ -1691,6 +1695,7 @@ LDBLE PBasic:: realexpr(struct LOC_exec *LINK) { valrec n; + valrec_init(&n); n = expr(LINK); if (n.stringval) @@ -1702,6 +1707,7 @@ char * PBasic:: strexpr(struct LOC_exec * LINK) { valrec n; + valrec_init(&n); n = expr(LINK); if (!n.stringval) @@ -1714,6 +1720,7 @@ char * PBasic:: stringexpr(char * Result, struct LOC_exec * LINK) { valrec n; + valrec_init(&n); n = expr(LINK); if (!n.stringval) @@ -1856,6 +1863,7 @@ factor(struct LOC_exec * LINK) varrec *v; tokenrec *facttok; valrec n; + valrec_init(&n); long i, j, m; tokenrec *tok, *tok1; char *l_s; @@ -3235,6 +3243,8 @@ valrec PBasic:: upexpr(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); n = factor(LINK); while (LINK->t != NULL && LINK->t->kind == tokup) @@ -3271,6 +3281,8 @@ valrec PBasic:: term(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); int k; n = upexpr(LINK); @@ -3323,6 +3335,8 @@ valrec PBasic:: sexpr(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); int k, m; n = term(LINK); @@ -3367,6 +3381,8 @@ valrec PBasic:: relexpr(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); bool f; int k; @@ -3440,6 +3456,8 @@ valrec PBasic:: andexpr(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); n = relexpr(LINK); while (LINK->t != NULL && LINK->t->kind == tokand) @@ -3457,6 +3475,8 @@ valrec PBasic:: expr(struct LOC_exec * LINK) { valrec n, n2; + valrec_init(&n); + valrec_init(&n2); int k; n = andexpr(LINK); @@ -3755,6 +3775,7 @@ void PBasic:: cmdsave(struct LOC_exec *LINK) { valrec n; + valrec_init(&n); while (!iseos(LINK)) { if ((unsigned long) LINK->t->kind < 32 && @@ -4027,6 +4048,7 @@ cmdprint(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); char STR1[256] = {0}; semiflag = false; @@ -4061,6 +4083,7 @@ void PBasic:: cmdpunch(struct LOC_exec *LINK) { valrec n; + valrec_init(&n); /* char STR1[256]; */ while (!iseos(LINK)) @@ -4118,6 +4141,7 @@ cmdgraph_x(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -4153,6 +4177,7 @@ cmdgraph_y(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -4188,6 +4213,7 @@ cmdgraph_sy(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -4889,6 +4915,9 @@ void PBasic:: exec(void) { struct LOC_exec V; + V.gotoflag = false; + V.elseflag = false; + V.t = NULL; char STR1[256] = {0}; try @@ -5231,6 +5260,8 @@ cmdplot_xy(struct LOC_exec *LINK) { bool semiflag; valrec n[2]; + valrec_init(&n[0]); + valrec_init(&n[1]); char STR[2][256]; int i = 0; semiflag = false; @@ -5320,6 +5351,7 @@ cmdgraph_x(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -5367,6 +5399,7 @@ cmdgraph_y(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -5431,6 +5464,7 @@ cmdgraph_sy(struct LOC_exec *LINK) { bool semiflag; valrec n; + valrec_init(&n); semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -6228,6 +6262,12 @@ _EscIO(int code) P_ioresult = code; return _Escape(-10); } +void PBasic:: +valrec_init(valrec *v) +{ + v->stringval = false; + v->UU.val = 0.0; +}; const std::map::value_type temp_tokens[] = { std::map::value_type("+", PBasic::tokplus), diff --git a/PBasic.h b/PBasic.h index de6a5e1d..d2f84d5b 100644 --- a/PBasic.h +++ b/PBasic.h @@ -334,6 +334,9 @@ public: void Set_hInfiniteLoop(HANDLE h) {hInfiniteLoop = h;}; #endif int free_dim_stringvar(varrec *varbase); + + void valrec_init(valrec *v); + void exec(void); int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); void restoredata(void); diff --git a/phreeqc/advection.cpp b/phreeqc/advection.cpp index 3888184f..7f69accf 100644 --- a/phreeqc/advection.cpp +++ b/phreeqc/advection.cpp @@ -39,7 +39,7 @@ advection(void) for (i = 1; i <= count_ad_cells; i++) { //if (kinetics_bsearch(i, &n) != NULL) - if (Utilities::Rxn_find(Rxn_kinetics_map, i) == NULL) + if (Utilities::Rxn_find(Rxn_kinetics_map, i) != NULL) { input_error++; error_string = sformatf( From 5f058aecb2ff2f11a733fde040277f6ae43a94b6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jan 2012 18:45:13 +0000 Subject: [PATCH 0433/1077] memory initialization for cvode Latest test cases without kinetics struct git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6089 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/kinetics.cpp | 7 ++++++- phreeqc/step.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 514a9fa5..cc9e7ea2 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -3126,7 +3126,12 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); if (kinetics_abstol == NULL) malloc_error(); - + for (int j = 0; j < n_reactions; j++) + { + Ith(cvode_last_good_y, j + 1) = 0.0; + Ith(cvode_prev_good_y, j + 1) = 0.0; + Ith(kinetics_abstol, j + 1) = 0.0; + } /* * Set y to 0.0 */ diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index d21c3c0e..7cd79e8c 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -1196,7 +1196,7 @@ add_kinetics(cxxKinetics *kinetics_ptr) * Add kinetic reaction */ //int i; - struct master *master_ptr; + struct master *master_ptr = NULL; /* * Add reaction to totals */ From 50ba9dbe4306bc13210887ab67b78b4241251526 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jan 2012 22:55:02 +0000 Subject: [PATCH 0434/1077] Made minor class of valrec git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6090 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 54 +++++++++++++++--------------------------------------- PBasic.h | 22 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 5c9f3293..ab947702 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1634,8 +1634,6 @@ LDBLE PBasic:: realfactor(struct LOC_exec *LINK) { valrec n; - valrec_init(&n); - n = factor(LINK); if (n.stringval) tmerr(": found characters, not a number"); @@ -1646,8 +1644,6 @@ char * PBasic:: strfactor(struct LOC_exec * LINK) { valrec n; - valrec_init(&n); - n = factor(LINK); if (!n.stringval) //tmerr(": chemical name is not enclosed in \" \"" ); @@ -1659,7 +1655,6 @@ char * PBasic:: stringfactor(char * Result, struct LOC_exec * LINK) { valrec n; - valrec_init(&n); n = factor(LINK); if (!n.stringval) @@ -1674,7 +1669,6 @@ const char * PBasic:: stringfactor(std::string & Result, struct LOC_exec * LINK) { valrec n; - valrec_init(&n); n = factor(LINK); if (!n.stringval) @@ -1695,7 +1689,6 @@ LDBLE PBasic:: realexpr(struct LOC_exec *LINK) { valrec n; - valrec_init(&n); n = expr(LINK); if (n.stringval) @@ -1707,7 +1700,6 @@ char * PBasic:: strexpr(struct LOC_exec * LINK) { valrec n; - valrec_init(&n); n = expr(LINK); if (!n.stringval) @@ -1720,7 +1712,6 @@ char * PBasic:: stringexpr(char * Result, struct LOC_exec * LINK) { valrec n; - valrec_init(&n); n = expr(LINK); if (!n.stringval) @@ -1863,7 +1854,7 @@ factor(struct LOC_exec * LINK) varrec *v; tokenrec *facttok; valrec n; - valrec_init(&n); + long i, j, m; tokenrec *tok, *tok1; char *l_s; @@ -3243,8 +3234,6 @@ valrec PBasic:: upexpr(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); n = factor(LINK); while (LINK->t != NULL && LINK->t->kind == tokup) @@ -3281,8 +3270,7 @@ valrec PBasic:: term(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); + int k; n = upexpr(LINK); @@ -3335,8 +3323,7 @@ valrec PBasic:: sexpr(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); + int k, m; n = term(LINK); @@ -3381,8 +3368,7 @@ valrec PBasic:: relexpr(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); + bool f; int k; @@ -3456,8 +3442,6 @@ valrec PBasic:: andexpr(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); n = relexpr(LINK); while (LINK->t != NULL && LINK->t->kind == tokand) @@ -3475,8 +3459,7 @@ valrec PBasic:: expr(struct LOC_exec * LINK) { valrec n, n2; - valrec_init(&n); - valrec_init(&n2); + int k; n = andexpr(LINK); @@ -3775,7 +3758,7 @@ void PBasic:: cmdsave(struct LOC_exec *LINK) { valrec n; - valrec_init(&n); + while (!iseos(LINK)) { if ((unsigned long) LINK->t->kind < 32 && @@ -4048,7 +4031,7 @@ cmdprint(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + char STR1[256] = {0}; semiflag = false; @@ -4083,7 +4066,7 @@ void PBasic:: cmdpunch(struct LOC_exec *LINK) { valrec n; - valrec_init(&n); + /* char STR1[256]; */ while (!iseos(LINK)) @@ -4141,7 +4124,7 @@ cmdgraph_x(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -4177,7 +4160,7 @@ cmdgraph_y(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -4213,7 +4196,7 @@ cmdgraph_sy(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + char STR1[256]; semiflag = false; while (!iseos(LINK)) @@ -5260,8 +5243,7 @@ cmdplot_xy(struct LOC_exec *LINK) { bool semiflag; valrec n[2]; - valrec_init(&n[0]); - valrec_init(&n[1]); + char STR[2][256]; int i = 0; semiflag = false; @@ -5351,7 +5333,7 @@ cmdgraph_x(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -5399,7 +5381,7 @@ cmdgraph_y(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -5464,7 +5446,7 @@ cmdgraph_sy(struct LOC_exec *LINK) { bool semiflag; valrec n; - valrec_init(&n); + semiflag = false; ChartObject *chart = PhreeqcPtr->chart_handler.Get_current_chart(); @@ -6262,12 +6244,6 @@ _EscIO(int code) P_ioresult = code; return _Escape(-10); } -void PBasic:: -valrec_init(valrec *v) -{ - v->stringval = false; - v->UU.val = 0.0; -}; const std::map::value_type temp_tokens[] = { std::map::value_type("+", PBasic::tokplus), diff --git a/PBasic.h b/PBasic.h index d2f84d5b..847546c1 100644 --- a/PBasic.h +++ b/PBasic.h @@ -90,6 +90,24 @@ typedef struct linerec struct linerec *next; } linerec; +class valrec +{ +public: + valrec() + { + stringval = false; + UU.val = 0; + } + ~valrec() {} + bool stringval; + union + { + LDBLE val; + char *sval; + } UU; +}; + +#ifdef SKIP typedef struct valrec { bool stringval; @@ -99,7 +117,7 @@ typedef struct valrec char *sval; } UU; } valrec; - +#endif typedef struct looprec { struct looprec *next; @@ -335,8 +353,6 @@ public: #endif int free_dim_stringvar(varrec *varbase); - void valrec_init(valrec *v); - void exec(void); int basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase); void restoredata(void); From 20b360fec9311fb7586623dc2603c28e39db0603 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 27 Jan 2012 05:33:26 +0000 Subject: [PATCH 0435/1077] modified for warnings in 2010 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6147 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index 0089c2d0..da220ac5 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -175,6 +175,10 @@ protected: std::list istream_list; std::list delete_istream_list; + std::string m_line; + std::string m_line_save; + std::string accumulated; + #if defined(_MSC_VER) /* reset warning C4251 */ #pragma warning(default:4251) @@ -182,9 +186,6 @@ protected: // input data members Keywords::KEYWORDS m_next_keyword; - std::string m_line; - std::string m_line_save; - std::string accumulated; bool accumulate; LINE_TYPE m_line_type; }; From 91f650a5e9d5dd2b694bcdb6205a3db5329f732e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 6 Mar 2012 23:42:49 +0000 Subject: [PATCH 0436/1077] Merged ErrorHandling 6119-6268 changes. All reactant structs have been removed. Tony's pressure uses mu in pressure term of log_k. Test cases run, discriminant check at 1e-8. Still want to optimize out some k_temp calls and checks for same T, P, mu. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6269 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 8 - ChartHandler.h | 2 +- ChartObject.cpp | 4 - ChartObject.h | 45 - CurveObject.cpp | 4 - CurveObject.h | 11 - ExchComp.cxx | 136 +- ExchComp.h | 28 +- Exchange.cxx | 226 +-- Exchange.h | 17 +- GasComp.cxx | 61 +- GasComp.h | 7 +- GasPhase.cxx | 129 +- GasPhase.h | 16 +- ISolution.cxx | 18 +- ISolution.h | 46 +- ISolutionComp.cxx | 197 ++- ISolutionComp.h | 20 +- KineticsComp.cxx | 87 +- KineticsComp.h | 8 +- Makefile | 555 ++++---- NameDouble.cxx | 144 +- NameDouble.h | 54 +- NumKeyword.cxx | 71 +- NumKeyword.h | 11 +- PBasic.cpp | 90 +- PBasic.h | 16 +- PHRQ_io.cpp | 355 +++-- PHRQ_io.h | 49 +- PPassemblage.cxx | 87 +- PPassemblage.h | 9 +- PPassemblageComp.cxx | 86 +- PPassemblageComp.h | 3 +- Parser.cxx | 71 +- Parser.h | 6 +- Phreeqc.cpp | 447 +++--- Phreeqc.h | 336 ++--- Pressure.cxx | 11 +- Reaction.cxx | 25 +- ReadClass.cxx | 719 +--------- SS.cxx | 144 +- SS.h | 19 +- SSassemblage.cxx | 46 +- SSassemblage.h | 7 +- SScomp.cxx | 150 +- SScomp.h | 9 +- Solution.cxx | 1008 ++------------ Solution.h | 199 +-- SolutionIsotope.cxx | 354 +++-- SolutionIsotope.h | 53 +- SolutionIsotopeList.cxx | 86 -- SolutionIsotopeList.h | 32 - StorageBin.cxx | 110 +- StorageBin.h | 6 +- StorageBinList.cpp | 7 - StorageBinList.h | 2 +- Surface.cxx | 533 +++---- Surface.h | 84 +- SurfaceCharge.cxx | 246 ++-- SurfaceCharge.h | 114 +- SurfaceComp.cxx | 277 ++-- SurfaceComp.h | 47 +- System.cxx | 2 +- System.h | 12 +- Temperature.cxx | 10 +- Use.h | 14 +- Utils.cxx | 20 + Utils.h | 24 +- class_main.cpp | 13 - cxxKinetics.cxx | 463 +----- cxxKinetics.h | 8 +- cxxMix.cxx | 7 +- dumper.h | 2 +- phreeqc/PHRQ_io_output.cpp | 437 ++++-- phreeqc/advection.cpp | 16 +- phreeqc/basicsubs.cpp | 432 +++--- phreeqc/cl1mp.cpp | 1 - phreeqc/cvode.cpp | 10 +- phreeqc/gases.cpp | 26 +- phreeqc/global_structures.h | 282 +--- phreeqc/input.cpp | 3 - phreeqc/integrate.cpp | 783 ++++------- phreeqc/inverse.cpp | 723 +++++----- phreeqc/isotopes.cpp | 35 +- phreeqc/kinetics.cpp | 1798 +----------------------- phreeqc/mainsubs.cpp | 957 +++---------- phreeqc/model.cpp | 618 ++++---- phreeqc/phqalloc.cpp | 5 - phreeqc/pitzer.cpp | 43 +- phreeqc/prep.cpp | 1548 ++++++++++++--------- phreeqc/print.cpp | 872 +++--------- phreeqc/read.cpp | 2420 ++++++++++++++------------------ phreeqc/sit.cpp | 43 +- phreeqc/spread.cpp | 744 +++++----- phreeqc/step.cpp | 295 ++-- phreeqc/structures.cpp | 2629 ++--------------------------------- phreeqc/tally.cpp | 338 ++--- phreeqc/tidy.cpp | 1115 ++++----------- phreeqc/transport.cpp | 2148 +++++++++------------------- phreeqc/utilities.cpp | 329 +++-- runner.cpp | 6 - 101 files changed, 8767 insertions(+), 18212 deletions(-) delete mode 100644 SolutionIsotopeList.cxx delete mode 100644 SolutionIsotopeList.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 03725a21..e711f0a3 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -120,14 +120,6 @@ ChartHandler::End_timer() for ( ; it != chart_map.end(); it++) { - //{ - // std::vector::iterator cit = it->second->Get_Curves().begin(); - // size_t i; - // for (i = 0; i < it->second->Get_Curves().size(); i ++) - // { - // std::cerr << "Curve " << i << ", number of points " << it->second->Get_Curves()[i]->Get_x().size() << "\n"; - // } - //} size_t i = 0; it->second->Rate_free(); if (it->second->Get_form_started()) diff --git a/ChartHandler.h b/ChartHandler.h index 331a3f6b..3ea25228 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -14,7 +14,7 @@ class ChartHandler: public PHRQ_base public: ChartHandler(PHRQ_io *io = NULL); - ~ChartHandler(); + virtual ~ChartHandler(); size_t Get_chart_count() { diff --git a/ChartObject.cpp b/ChartObject.cpp index 6e3df3b0..f215ffa8 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -468,9 +468,6 @@ ChartObject::OpenCSVFile(std::string file_name) return false; } - //std::ostringstream oss_out; - //std::ostringstream oss_err; - //CParser parser(f_csv, oss_out, oss_err, this->Get_io()); CParser parser(f_csv, this->Get_io()); parser.set_echo_file(CParser::EO_NONE); @@ -744,7 +741,6 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) // Add to list of new plotxy curves this->new_plotxy_curves.push_back(new_curve); - //std::cerr << revised_line << "\n"; cmd_line = revised_line; } void diff --git a/ChartObject.h b/ChartObject.h index 7f102579..5daf0c2e 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -19,7 +19,6 @@ class ChartObject:public cxxNumKeyword ChartObject(int i, PHRQ_io *io=NULL); ~ChartObject(); - // new_ug bool Get_new_ug() { return this->new_ug; @@ -28,7 +27,6 @@ class ChartObject:public cxxNumKeyword { this->new_ug = b; } - // bool FirstCallToUSER_GRAPH; void Set_FirstCallToUSER_GRAPH(bool b) { this->FirstCallToUSER_GRAPH = b; @@ -37,67 +35,50 @@ class ChartObject:public cxxNumKeyword { return this->FirstCallToUSER_GRAPH; } - // int update_time_chart; int Get_update_time_chart() { return (this->update_time_chart); } - // PanelHeight int Get_PanelHeight() { return (this->PanelHeight); } - // PanelWidth int Get_PanelWidth() { return (this->PanelWidth); } - // Symbol_map - // std::vector Color_vector; - - // std::string chart_title; std::string &Get_chart_title() { return this->chart_title; } - // std::vector axis_titles; std::vector &Get_axis_titles() { return this->axis_titles; } - // LDBLE axis_scale_x[5]; LDBLE *Get_axis_scale_x() { return this->axis_scale_x; } - // LDBLE axis_scale_y[5]; LDBLE *Get_axis_scale_y() { return this->axis_scale_y; } - // LDBLE axis_scale_y2[5]; LDBLE *Get_axis_scale_y2() { return this->axis_scale_y2; } - // int chart_type; int Get_chart_type() { return this->chart_type; } - // bool graph_initial_solutions; bool Get_graph_initial_solutions() { return this->graph_initial_solutions; } - // bool connect_simulations; bool Get_connect_simulations() { return this->connect_simulations; } - // int shifts_as_points; - - // int colnr; void Set_colnr(int i) { this->colnr = i; @@ -106,7 +87,6 @@ class ChartObject:public cxxNumKeyword { return (this->colnr); } - // int ColumnOffset; void Set_ColumnOffset(int i) { this->ColumnOffset = i; @@ -115,7 +95,6 @@ class ChartObject:public cxxNumKeyword { return (this->ColumnOffset); } - // bool AddSeries; void Set_AddSeries(bool b) { this->AddSeries = b; @@ -124,7 +103,6 @@ class ChartObject:public cxxNumKeyword { return this->AddSeries; } - // int prev_advection_step; void Set_prev_advection_step(int i) { this->prev_advection_step = i; @@ -133,7 +111,6 @@ class ChartObject:public cxxNumKeyword { return (this->prev_advection_step); } - // int prev_transport_step; void Set_prev_transport_step(int i) { this->prev_transport_step = i; @@ -142,7 +119,6 @@ class ChartObject:public cxxNumKeyword { return (this->prev_transport_step); } - // int prev_sim_no; void Set_prev_sim_no(int i) { this->prev_sim_no = i; @@ -151,7 +127,6 @@ class ChartObject:public cxxNumKeyword { return this->prev_sim_no; } - // bool end_timer; void Set_end_timer(bool b) { this->end_timer = b; @@ -160,7 +135,6 @@ class ChartObject:public cxxNumKeyword { return this->end_timer; } - // bool end_timer; void Set_done(bool b) { this->done = b; @@ -169,17 +143,14 @@ class ChartObject:public cxxNumKeyword { return this->done; } - // std::vector CurvesCSV; std::vector &Get_CurvesCSV() { return this->CurvesCSV; } - // std::vector Curves; std::vector &Get_Curves() { return this->Curves; } - // bool curve_added; void Set_curve_added(bool tf) { this->curve_added = tf; @@ -188,7 +159,6 @@ class ChartObject:public cxxNumKeyword { return this->curve_added; } - // bool point_added; void Set_point_added(bool tf) { this->point_added = tf; @@ -197,27 +167,20 @@ class ChartObject:public cxxNumKeyword { return this->point_added; } - // struct rate user_graph; struct rate *Get_user_graph() { return this->user_graph; } - // C++ for rate struct - // std::string rate_name; - // std::list rate_command_list; std::list &Get_rate_command_list() { return this->rate_command_list; } - // bool rate_new_def; void Set_rate_new_def(bool tf); bool Get_rate_new_def() { return this->rate_new_def; } - // int default_symbol; - //LDBLE graph_x; void Set_graph_x(LDBLE d) { this->graph_x = d; @@ -226,27 +189,22 @@ class ChartObject:public cxxNumKeyword { return this->graph_x; } - //std::map graph_y; std::map &Get_graph_y() { return this->graph_y; } - //std::map secondary_y; std::map &Get_secondary_y() { return this->secondary_y; } - //std::vector new_plotxy_curves; std::vector &Get_new_plotxy_curves() { return this->new_plotxy_curves; } - //std::vector new_headings; std::vector &Get_new_headings() { return this->new_headings; } - // bool active; void Set_active(bool tf) { this->active = tf; @@ -255,7 +213,6 @@ class ChartObject:public cxxNumKeyword { return this->active; } - // bool detach; void Set_detach(bool tf) { this->detach = tf; @@ -264,7 +221,6 @@ class ChartObject:public cxxNumKeyword { return this->detach; } - // bool chart_started; bool Get_form_started() { return this->form_started; @@ -375,7 +331,6 @@ class ChartObject:public cxxNumKeyword public: int usingResource; - }; #endif // MULTICHART #endif // !defined(CHARTOBJECT_H_INCLUDED) diff --git a/CurveObject.cpp b/CurveObject.cpp index 6f3a1ead..504c4658 100644 --- a/CurveObject.cpp +++ b/CurveObject.cpp @@ -18,10 +18,6 @@ CurveObject::CurveObject() { x.clear(); y.clear(); - //this->npoints_plot = 0; - //this->npoints = 0; - //this->nxy = 0; - //this->prev_npoints = 0; this->id = ""; this->symbol = ""; this->color = ""; diff --git a/CurveObject.h b/CurveObject.h index c826bb6a..d491fd36 100644 --- a/CurveObject.h +++ b/CurveObject.h @@ -65,20 +65,9 @@ public: { return this->y_axis; } - //void Set_npoints_plot(int f) - //{ - // this->npoints_plot = f; - //} - //int Get_npoints_plot(void) - //{ - // return this->npoints_plot; - //} protected: - //float *x, *y; std::vector x, y; - //int nxy, npoints, npoints_plot, prev_npoints; - std::string id, color, symbol; int y_axis; LDBLE line_w, symbol_size; diff --git a/ExchComp.cxx b/ExchComp.cxx index 3327cd69..eaaff96d 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -12,11 +12,8 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "ExchComp.h" -//#include "Dictionary.h" #include "phqalloc.h" - - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -27,14 +24,10 @@ cxxExchComp::cxxExchComp(PHRQ_io *io) // : PHRQ_base(io) { - moles = 0.0; - formula_totals.type = cxxNameDouble::ND_ELT_MOLES; totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; charge_balance = 0.0; - //phase_name = NULL; phase_proportion = 0.0; - //rate_name = NULL; formula_z = 0.0; } #ifdef SKIP @@ -106,7 +99,6 @@ cxxExchComp::~cxxExchComp() void cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -122,7 +114,6 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; s_oss << indent0 << "formula_z=\"" << this-> formula_z << "\"" << "\n"; - s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; s_oss << indent0 << "charge_balance=\"" << this-> charge_balance << "\"" << "\n"; @@ -142,17 +133,11 @@ cxxExchComp::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0; s_oss << "totals.dump_xml(s_oss, indent + 1); - - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); } void cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -164,38 +149,29 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); // Exch_Comp element and attributes - - s_oss << indent0 << "-formula " << this->formula << "\n"; - //s_oss << indent1 << "# critical values" << "\n"; // totals - s_oss << indent1; + s_oss << indent0 << "# EXCHANGE_MODIFY candidate identifiers #\n"; + s_oss << indent0; s_oss << "-totals" << "\n"; - this->totals.dump_raw(s_oss, indent + 2); + this->totals.dump_raw(s_oss, indent + 1); - s_oss << indent1 << "-charge_balance " << this->charge_balance << "\n"; + s_oss << indent0 << "-charge_balance " << this->charge_balance << "\n"; //s_oss << indent1 << "# Noncritical values" << "\n"; - s_oss << indent1 << "-moles " << this->moles << "\n"; - s_oss << indent1 << "-la " << this->la << "\n"; + s_oss << indent0 << "-la " << this->la << "\n"; if (this->phase_name.size() != 0) { - s_oss << indent1 << "-phase_name " << this->phase_name << "\n"; + s_oss << indent0 << "-phase_name " << this->phase_name << "\n"; } if (this->rate_name.size() != 0) { - s_oss << indent1 << "-rate_name " << this->rate_name << "\n"; + s_oss << indent0 << "-rate_name " << this->rate_name << "\n"; } - s_oss << indent1 << "-phase_proportion " << this->phase_proportion << "\n"; - s_oss << indent1 << "-formula_z " << this->formula_z << "\n"; - - // formula_totals - s_oss << indent1; - s_oss << "-formula_totals" << "\n"; - this->formula_totals.dump_raw(s_oss, indent + 2); - + s_oss << indent0 << "-phase_proportion " << this->phase_proportion << "\n"; + s_oss << indent0 << "-formula_z " << this->formula_z << "\n"; } void @@ -225,8 +201,6 @@ cxxExchComp::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool formula_defined(false); - bool moles_defined(false); bool la_defined(false); bool charge_balance_defined(false); bool formula_z_defined(false); @@ -249,34 +223,14 @@ cxxExchComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in EXCH_COMP read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // formula - if (!(parser.get_iss() >> str)) - { - this->formula.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for formula.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->formula = str; - } - formula_defined = true; + warning_msg("-formula ignored. Defined with -component."); break; case 1: // moles - if (!(parser.get_iss() >> this->moles)) - { - this->moles = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for moles.", - PHRQ_io::OT_CONTINUE); - } - moles_defined = true; + parser.warning_msg("-moles is an obsolete identifier"); break; case 2: // la @@ -365,16 +319,7 @@ cxxExchComp::read_raw(CParser & parser, bool check) break; case 9: // formula_totals - if (this->formula_totals.read_raw(parser, next_char) != - CParser::PARSER_OK) - { - parser.incr_input_error(); - parser. - error_msg - ("Expected element name and molality for ExchComp formula totals.", - PHRQ_io::OT_CONTINUE); - } - opt_save = 9; + parser.warning_msg("-formula_totals is an obsolete identifier"); break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -383,18 +328,6 @@ cxxExchComp::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (formula_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Formula not defined for ExchComp input.", - PHRQ_io::OT_CONTINUE); - } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for ExchComp input.", - PHRQ_io::OT_CONTINUE); - } if (la_defined == false) { parser.incr_input_error(); @@ -418,29 +351,16 @@ cxxExchComp::read_raw(CParser & parser, bool check) void cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) { - LDBLE ext1, ext2, f1, f2; + LDBLE f1, f2; if (extensive == 0.0) return; if (addee.formula.size() == 0) return; // this and addee must have same formula // otherwise generate a new exchcomp with multiply + f1 = 0.5; + f2 = 0.5; - ext1 = this->moles; - ext2 = addee.moles * extensive; - if (ext1 + ext2 != 0) - { - f1 = ext1 / (ext1 + ext2); - f2 = ext2 / (ext1 + ext2); - } - else - { - f1 = 0.5; - f2 = 0.5; - } - - //char * formula; - //cxxNameDouble formula_totals; if (this->formula.size() == 0 && addee.formula.size() == 0) { return; @@ -450,17 +370,10 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) if (this->formula.size() == 0 && addee.formula.size() != 0) { this->formula = addee.formula; - this->formula_totals = addee.formula_totals; } - //LDBLE moles; - this->moles += addee.moles * extensive; - //cxxNameDouble totals; this->totals.add_extensive(addee.totals, extensive); - //LDBLE la; this->la = f1 * this->la + f2 * addee.la; - //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; - //char *phase_name; if (this->phase_name != addee.phase_name) { @@ -469,7 +382,6 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) "Can not mix two exchange components with same formula and different related phases, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //input_error++; return; } else if (this->phase_name.size() != 0) @@ -477,7 +389,6 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } - //char *rate_name; if (this->rate_name != addee.rate_name) { std::ostringstream oss; @@ -485,12 +396,10 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) "Can not mix two exchange components with same formula and different related kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //input_error++; return; } else if (this->rate_name.size() != 0) { - //LDBLE phase_proportion; this->phase_proportion = this->phase_proportion * f1 + addee.phase_proportion * f2; } @@ -502,26 +411,15 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) "Can not mix exchange components related to phase with exchange components related to kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); - //input_error++; return; } } void cxxExchComp::multiply(LDBLE extensive) -{ - //char * formula; - //LDBLE moles; - this->moles *= extensive; - //cxxNameDouble formula_totals; - //cxxNameDouble totals; +{ this->totals.multiply(extensive); - //LDBLE la; - //LDBLE charge_balance; - this->charge_balance *= extensive; - //char *phase_name; - //LDBLE phase_proportion; + this->charge_balance *= extensive; this->phase_proportion *= extensive; - //LDBLE formula_z; } #ifdef USE_MPI diff --git a/ExchComp.h b/ExchComp.h index 0271dfcf..e29cf7d4 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -14,7 +14,7 @@ class cxxExchComp: public PHRQ_base public: cxxExchComp(PHRQ_io *io=NULL); - ~cxxExchComp(); + virtual ~cxxExchComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -33,14 +33,6 @@ class cxxExchComp: public PHRQ_base else this->formula.clear(); } - LDBLE Get_moles() const - { - return this->moles; - } - void Set_moles(LDBLE d) - { - this->moles = d; - } LDBLE Get_la() const { return this->la; @@ -107,22 +99,7 @@ class cxxExchComp: public PHRQ_base { this->totals = nd; } - void Set_formula_totals(struct elt_list *e_l, int count) - { - this->formula_totals = cxxNameDouble(e_l, count); - } - void Set_formula_totals(struct elt_list *e_l) - { - this->formula_totals = cxxNameDouble(e_l); - } - void Set_formula_totals(cxxNameDouble nd) - { - this->formula_totals = nd; - } - cxxNameDouble & Get_totals() {return (this->totals);} - cxxNameDouble & Get_formula_totals(void) {return this->formula_totals;} - void add(const cxxExchComp & comp, LDBLE extensive); void multiply(LDBLE extensive); @@ -134,8 +111,7 @@ class cxxExchComp: public PHRQ_base #endif protected: std::string formula; - LDBLE moles; - cxxNameDouble formula_totals; + // EXCHANGE_MODIFY candidates cxxNameDouble totals; LDBLE la; LDBLE charge_balance; diff --git a/Exchange.cxx b/Exchange.cxx index 130d2765..80e9a6d6 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -58,16 +58,15 @@ cxxNumKeyword(io) cxxExchange::~cxxExchange() { } - bool cxxExchange::Get_related_phases() const { - for (std::map < std::string, cxxExchComp >::const_iterator it = - this->exchComps.begin(); it != this->exchComps.end(); ++it) + for (size_t i = 0; i < this->exchange_comps.size(); i++) { - if ((*it).second.Get_phase_name().size() == 0) - continue; - return (true); + if (this->exchange_comps[i].Get_phase_name().size() > 0) + { + return (true); + } } return (false); } @@ -75,12 +74,12 @@ cxxExchange::Get_related_phases() const bool cxxExchange::Get_related_rate() const { - for (std::map < std::string, cxxExchComp >::const_iterator it = - this->exchComps.begin(); it != this->exchComps.end(); ++it) + for (size_t i = 0; i < this->exchange_comps.size(); i++) { - if ((*it).second.Get_rate_name().size() == 0) - continue; - return (true); + if (this->exchange_comps[i].Get_rate_name().size() > 0) + { + return (true); + } } return (false); } @@ -88,7 +87,38 @@ cxxExchange::Get_related_rate() const void cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; + unsigned int i; + s_oss.precision(DBL_DIG - 1); + std::string indent0(""), indent1(""), indent2(""); + for (i = 0; i < indent; ++i) + indent0.append(Utilities::INDENT); + for (i = 0; i < indent + 1; ++i) + indent1.append(Utilities::INDENT); + for (i = 0; i < indent + 2; ++i) + indent2.append(Utilities::INDENT); + + // Exchange element and attributes + s_oss << indent0; + s_oss << " + pitzer_exchange_gammas << "\"" << "\n"; + + // components + s_oss << indent1; + s_oss << "exchange_comps.size(); j++) + { + this->exchange_comps[j].dump_xml(s_oss, indent + 2); + } + + return; +} +#ifdef SKIP +void +cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const +{ unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -118,11 +148,10 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const return; } - +#endif void cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing exchange message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -136,32 +165,34 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Exchange element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "EXCHANGE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << indent1 << "# EXCHANGE_MODIFY candidate identifiers #\n"; s_oss << indent1; - s_oss << "-new_def " << this->new_def << "\n"; - - s_oss << indent1; - s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << "\n"; - - s_oss << indent1; - s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; - - s_oss << indent1; - s_oss << "-n_solution " << this->n_solution << "\n"; - - // exchComps structures - for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin(); - it != exchComps.end(); ++it) + s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << "\n"; + // exchComps + for (size_t i = 0; i < this->exchange_comps.size(); i++) { s_oss << indent1; - s_oss << "-component" << "\n"; - (*it).second.dump_raw(s_oss, indent + 2); + s_oss << "-component " << this->exchange_comps[i].Get_formula() << "\n"; + this->exchange_comps[i].dump_raw(s_oss, indent + 2); } + s_oss << indent1 << "# EXCHANGE_MODIFY candidates with new_def=true #\n"; + s_oss << indent1; + s_oss << "-new_def " << this->new_def << "\n"; + s_oss << indent1; + s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; + s_oss << indent1; + s_oss << "-n_solution " << this->n_solution << "\n"; + + s_oss << indent1 << "# Exchange workspace variables #\n"; + s_oss << indent1; + s_oss << "-totals" << "\n"; + this->totals.dump_raw(s_oss, indent + 1); + return; } - void cxxExchange::read_raw(CParser & parser, bool check) { @@ -174,7 +205,8 @@ cxxExchange::read_raw(CParser & parser, bool check) vopts.push_back("exchange_gammas"); // 2 vopts.push_back("new_def"); // 3 vopts.push_back("solution_equilibria"); // 4 - vopts.push_back("n_solution"); // 4 + vopts.push_back("n_solution"); // 5 + vopts.push_back("totals"); // 6 } std::istream::pos_type ptr; @@ -200,6 +232,7 @@ cxxExchange::read_raw(CParser & parser, bool check) { opt = parser.getOptionFromLastLine(vopts, next_char, true); } + useLastLine = false; switch (opt) { case CParser::OPT_EOF: @@ -212,7 +245,6 @@ cxxExchange::read_raw(CParser & parser, bool check) parser.error_msg("Unknown input in EXCH_COMP_RAW keyword.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; break; case 0: // pitzer_exchange_gammas @@ -227,34 +259,43 @@ cxxExchange::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } pitzer_exchange_gammas_defined = true; - useLastLine = false; break; case 1: // component { - cxxExchComp ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - if (this->exchComps.find(ec.Get_formula()) != this->exchComps.end()) + std::string str; + if (!(parser.get_iss() >> str)) { - cxxExchComp & comp = this->exchComps.find(ec.Get_formula())->second; - comp.read_raw(reread, false); + parser.incr_input_error(); + parser.error_msg("Expected string value for component name.", + PHRQ_io::OT_CONTINUE); } else { - cxxExchComp ec1(this->Get_io()); - ec1.read_raw(reread, false); - std::string str(ec1.Get_formula()); - this->exchComps[str] = ec1; + cxxExchComp temp_comp(this->io); + temp_comp.Set_formula(str.c_str()); + cxxExchComp *comp_ptr = this->Find_comp(str); + if (comp_ptr) + { + temp_comp = *comp_ptr; + } + temp_comp.read_raw(parser, check); + if (comp_ptr) + { + for (size_t j = 0; j < this->exchange_comps.size(); j++) + { + if (Utilities::strcmp_nocase(this->exchange_comps[j].Get_formula().c_str(), str.c_str()) == 0) + { + this->exchange_comps[j] = temp_comp; + } + } + } + else + { + this->exchange_comps.push_back(temp_comp); + } + useLastLine = true; } } - useLastLine = true; break; case 3: // new_def if (!(parser.get_iss() >> this->new_def)) @@ -266,7 +307,6 @@ cxxExchange::read_raw(CParser & parser, bool check) ("Expected boolean value for new_def.", PHRQ_io::OT_CONTINUE); } - useLastLine = false; break; case 4: // solution_equilibria if (!(parser.get_iss() >> this->solution_equilibria)) @@ -278,7 +318,6 @@ cxxExchange::read_raw(CParser & parser, bool check) ("Expected boolean value for solution_equilibria.", PHRQ_io::OT_CONTINUE); } - useLastLine = false; break; case 5: // n_solution if (!(parser.get_iss() >> this->n_solution)) @@ -290,7 +329,18 @@ cxxExchange::read_raw(CParser & parser, bool check) ("Expected integer value for n_solution.", PHRQ_io::OT_CONTINUE); } - useLastLine = false; + break; + case 6: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for Exchange totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 6; break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -308,6 +358,7 @@ cxxExchange::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } } + this->Sort_comps(); } void cxxExchange::add(const cxxExchange & addee, LDBLE extensive) @@ -318,20 +369,20 @@ cxxExchange::add(const cxxExchange & addee, LDBLE extensive) // exchComps if (extensive == 0.0) return; - for (std::map < std::string, cxxExchComp >::const_iterator itadd = - addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd) + for (size_t i = 0; i < addee.exchange_comps.size(); i++) { - std::map < std::string, cxxExchComp >::iterator it = this->exchComps.find((*itadd).first); - if (it != this->exchComps.end()) + size_t j; + for (j = 0; j < this->Get_exchange_comps().size(); j++) + if (addee.exchange_comps[i].Get_formula() == this->exchange_comps[j].Get_formula()) { - (*it).second.add((*itadd).second, extensive); + this->exchange_comps[j].add(addee.exchange_comps[i], extensive); + break; } - else + if (j == this->exchange_comps.size()) { - cxxExchComp exc = (*itadd).second; + cxxExchComp exc = addee.exchange_comps[i]; exc.multiply(extensive); - //exc.add(*itadd, extensive); - this->exchComps[(*itadd).first] = exc; + this->exchange_comps.push_back(exc); } } this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; @@ -387,11 +438,10 @@ cxxExchange::totalize() { this->totals.clear(); // component structures - for (std::map < std::string, cxxExchComp >::iterator it = exchComps.begin(); - it != exchComps.end(); ++it) + for (size_t i = 0; i < this->exchange_comps.size(); i++) { - this->totals.add_extensive((*it).second.Get_totals(), 1.0); - this->totals.add("Charge", (*it).second.Get_charge_balance()); + this->totals.add_extensive(this->exchange_comps[i].Get_totals(), 1.0); + this->totals.add("Charge", this->exchange_comps[i].Get_charge_balance()); } return; } @@ -405,42 +455,42 @@ cxxExchange::Set_pitzer_exchange_gammas(bool b) { this->pitzer_exchange_gammas = b; } - -std::map < std::string, cxxExchComp > & -cxxExchange::Get_exchComps(void) -{ - return (this->exchComps); -} - const cxxNameDouble & cxxExchange::Get_totals() const { return totals; } -cxxExchComp *cxxExchange::ExchComp_find(std::string s) +cxxExchComp *cxxExchange::Find_comp(std::string s) { - std::map::iterator it = this->exchComps.begin(); - for ( ; it != this->exchComps.end(); it++) + for (size_t i = 0; i < this->exchange_comps.size(); i++) { - cxxNameDouble nd(it->second.Get_totals()); + cxxNameDouble nd(this->exchange_comps[i].Get_totals()); cxxNameDouble::iterator nd_it; for (nd_it = nd.begin(); nd_it != nd.end(); nd_it++) { if(nd_it->first == s) { - return (&it->second); + return (&(this->exchange_comps[i])); } } } return NULL; } -std::vector cxxExchange::Vectorize(void) +void cxxExchange:: +Sort_comps(void) { - std::vector vlist; - std::map::iterator it = exchComps.begin(); - for ( ; it != this->exchComps.end(); it++) + // sort comps { - vlist.push_back(&it->second); + std::map comp_map; + for (size_t i = 0; i < this->exchange_comps.size(); i++) + { + comp_map[this->exchange_comps[i].Get_formula()] = this->exchange_comps[i]; + } + this->exchange_comps.clear(); + std::map::iterator it; + for (it = comp_map.begin(); it != comp_map.end(); it++) + { + this->exchange_comps.push_back(it->second); + } } - return vlist; -} \ No newline at end of file +} diff --git a/Exchange.h b/Exchange.h index 8221f846..be9876d3 100644 --- a/Exchange.h +++ b/Exchange.h @@ -37,14 +37,14 @@ public: void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;} int Get_n_solution(void) const {return this->n_solution;} void Set_n_solution(int i) {this->n_solution = i;} - cxxExchComp *ExchComp_find(std::string s); - - std::map < std::string, cxxExchComp > &Get_exchComps(void); + cxxExchComp *Find_comp(std::string s); + std::vector & Get_exchange_comps(void) {return this->exchange_comps;} + void Set_exchange_comps(std::vector &c) {this->exchange_comps = c;} + void Sort_comps(void); void totalize(); const cxxNameDouble & Get_totals() const; - std::vector Vectorize(void); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); @@ -56,11 +56,16 @@ protected: void dump_xml(std::ostream & os, unsigned int indent = 0) const; protected: + // EXCHANGE_MODIFY candidates + std::vector exchange_comps; + bool pitzer_exchange_gammas; + + // EXCHANGE_MODIFY candidates with new_def=true bool new_def; bool solution_equilibria; int n_solution; - std::map < std::string, cxxExchComp > exchComps; - bool pitzer_exchange_gammas; + + // exchange workspace variables cxxNameDouble totals; public: diff --git a/GasComp.cxx b/GasComp.cxx index 2c6e842d..1e3b3370 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -1,4 +1,4 @@ -// ExchComp.cxx: implementation of the cxxExchComp class. +// GasComp.cxx: implementation of the cxxGasComp class. // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG @@ -38,7 +38,6 @@ cxxGasComp::~cxxGasComp() void cxxGasComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -48,21 +47,14 @@ cxxGasComp::dump_raw(std::ostream & s_oss, unsigned int indent) const indent1.append(Utilities::INDENT); for (i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); - /* - std::string phase_name; - std::string name; - LDBLE p_read; - LDBLE moles; - LDBLE initial_moles; // Exch_Comp element and attributes - */ - s_oss << indent0 << "-phase_name " << this->phase_name << "\n"; - //s_oss << indent0 << "-name " << this->name << "\n"; - s_oss << indent0 << "-p_read " << this->p_read << "\n"; - s_oss << indent0 << "-moles " << this->moles << "\n"; - s_oss << indent0 << "-initial_moles " << this->initial_moles << "\n"; + s_oss << indent0 << "# GAS_PHASE_MODIFY candidate identifiers #\n"; + s_oss << indent0 << "-moles " << this->moles << "\n"; - //s_oss << indent1 << "# critical values" << "\n"; + s_oss << indent0 << "# GAS_PHASE_MODIFY candidate identifiers with new_def=true #\n"; + s_oss << indent0 << "-p_read " << this->p_read << "\n"; + s_oss << indent0 << "# GasComp workspace variables #\n"; + s_oss << indent0 << "-initial_moles " << this->initial_moles << "\n"; } bool @@ -88,16 +80,11 @@ cxxGasComp::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool phase_name_defined(false); bool moles_defined(false); int opt; for (;;) { opt = parser.get_option(vopts, next_char); - //if (opt == CParser::OPT_DEFAULT) - //{ - // opt = opt_save; - //} switch (opt) { @@ -109,37 +96,14 @@ cxxGasComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in EXCH_COMP read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // phase_name - if (!(parser.get_iss() >> str)) - { - this->phase_name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for phase_name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->phase_name = str; - } - phase_name_defined = true; + output_msg("-phase_name is obsolete. Define with -component\n"); break; case 1: // name - if (!(parser.get_iss() >> str)) - { - this->phase_name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->phase_name = str; - } + output_msg("-name is obsolete. Define with -component\n"); break; case 2: // p_read @@ -179,12 +143,6 @@ cxxGasComp::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (phase_name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Phase_name not defined for GasComp input.", - PHRQ_io::OT_CONTINUE); - } if (moles_defined == false) { parser.incr_input_error(); @@ -218,7 +176,6 @@ cxxGasComp::add(const cxxGasComp & addee, LDBLE extensive) assert(this->phase_name == addee.phase_name); - //LDBLE moles; this->p_read += addee.p_read * extensive; this->moles += addee.moles * extensive; this->initial_moles += addee.initial_moles * extensive; diff --git a/GasComp.h b/GasComp.h index 2063c2aa..3973d25d 100644 --- a/GasComp.h +++ b/GasComp.h @@ -15,7 +15,7 @@ class cxxGasComp: public PHRQ_base public: cxxGasComp(PHRQ_io *io=NULL); - ~cxxGasComp(); + virtual ~cxxGasComp(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; @@ -40,8 +40,11 @@ class cxxGasComp: public PHRQ_base #endif protected: std::string phase_name; - LDBLE p_read; + // GAS_PHASE_MODIFY candidates LDBLE moles; + // GAS_PHASE_MODIFY candidates with new_def=true + LDBLE p_read; + // internal workspace LDBLE initial_moles; }; diff --git a/GasPhase.cxx b/GasPhase.cxx index 2845ee45..0bfb6a33 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -25,7 +25,7 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) // : cxxNumKeyword(io) { - new_def = true; + new_def = false; solution_equilibria = false; n_solution = -999; type = cxxGasPhase::GP_PRESSURE; @@ -182,7 +182,6 @@ cxxGasPhase::~cxxGasPhase() void cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -217,7 +216,6 @@ cxxGasPhase::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing gas_phase message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -231,36 +229,43 @@ cxxGasPhase::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // GasPhase element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "GAS_PHASE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "GAS_PHASE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << indent1 << "# GAS_PHASE_MODIFY candidate identifiers #\n"; s_oss << indent1; - s_oss << "-new_def " << this->new_def << "\n"; + s_oss << "-type " << this->type << "\n"; s_oss << indent1; - s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; + s_oss << "-total_p " << this->total_p << "\n"; s_oss << indent1; - s_oss << "-n_solution " << this->n_solution << "\n"; - s_oss << indent1; - s_oss << "-type " << this->type << "\n"; - s_oss << indent1; - s_oss << "-total_p " << this->total_p << "\n"; - s_oss << indent1; - s_oss << "-total_moles " << this->total_moles << "\n"; - s_oss << indent1; - s_oss << "-volume " << this->volume << "\n"; - s_oss << indent1; - s_oss << "-v_m " << this->v_m << "\n"; - s_oss << indent1; - s_oss << "-pr_in " << (this->pr_in ? 1 : 0) << "\n"; - s_oss << indent1; - s_oss << "-temperature " << this->temperature << "\n"; - + s_oss << "-volume " << this->volume << "\n"; // gasPhaseComps for (size_t i = 0 ; i < this->gas_comps.size(); i++) { s_oss << indent1; - s_oss << "-component" << "\n"; + s_oss << "-component " << this->gas_comps[i].Get_phase_name() << "\n"; this->gas_comps[i].dump_raw(s_oss, indent + 2); } + + s_oss << indent1 << "# GAS_PHASE_MODIFY candidate identifiers with new_def=true #\n"; + s_oss << indent1; + s_oss << "-new_def " << this->new_def << "\n"; + s_oss << indent1; + s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; + s_oss << indent1; + s_oss << "-n_solution " << this->n_solution << "\n"; + s_oss << indent1; + s_oss << "-temperature " << this->temperature << "\n"; + + s_oss << indent1 << "# GasPhase workspace variables #\n"; + s_oss << indent1; + s_oss << "-total_moles " << this->total_moles << "\n"; + s_oss << indent1; + s_oss << "-v_m " << this->v_m << "\n"; + s_oss << indent1; + s_oss << "-pr_in " << (this->pr_in ? 1 : 0) << "\n"; + s_oss << indent1; + s_oss << "-totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 2); } void @@ -284,6 +289,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) vopts.push_back("n_solution"); //9 vopts.push_back("total_moles"); //10 vopts.push_back("temperature"); //11 + vopts.push_back("totals"); //12 } std::istream::pos_type ptr; @@ -337,7 +343,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) case 0: // type if (!(parser.get_iss() >> i)) - //if (!(parser.get_iss() >> (cxxGasPhase::GP_TYPE) this->type)) { this->type = cxxGasPhase::GP_PRESSURE; parser.incr_input_error(); @@ -388,38 +393,44 @@ cxxGasPhase::read_raw(CParser & parser, bool check) v_m_defined = true; useLastLine = false; break; - case 4: // component { - cxxGasComp gc; - //bool tf = gc.read_raw(parser, next_char); - //if (!tf - if (!gc.read_raw(parser, false)) + std::string str; + if (!(parser.get_iss() >> str)) { parser.incr_input_error(); - parser.error_msg - ("Expected gas component information.", - PHRQ_io::OT_CONTINUE); + parser.error_msg("Expected string value for component name.", + PHRQ_io::OT_CONTINUE); } else { - size_t i; - for (i = 0; i < this->gas_comps.size(); i++) + cxxGasComp temp_comp(io); + temp_comp.Set_phase_name(str); + cxxGasComp * comp_ptr = this->Find_comp(str.c_str()); + if (comp_ptr) { - if (this->gas_comps[i].Get_phase_name() == gc.Get_phase_name()) + temp_comp = *comp_ptr; + } + temp_comp.read_raw(parser, false); + if (comp_ptr) + { + for (size_t j = 0; j < this->gas_comps.size(); j++) { - this->gas_comps[i] = gc; - break; + if (Utilities::strcmp_nocase(this->gas_comps[j].Get_phase_name().c_str(), str.c_str()) == 0) + { + this->gas_comps[j] = temp_comp; + } } } - if (i >= this->gas_comps.size()) + else { - this->gas_comps.push_back(gc); + this->gas_comps.push_back(temp_comp); } + useLastLine = true; } - //opt_save = 4; - useLastLine = true; } + + opt_save = CParser::OPT_DEFAULT; break; case 6: // pr_in if (!(parser.get_iss() >> i)) @@ -486,6 +497,18 @@ cxxGasPhase::read_raw(CParser & parser, bool check) } useLastLine = false; break; + case 12: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for GasPhase totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 12; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -511,18 +534,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", PHRQ_io::OT_CONTINUE); } - if (v_m_defined == false) - { - parser.incr_input_error(); - parser.error_msg("V_m not defined for GAS_PHASE_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (pr_in_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Pr_in not defined for GAS_PHASE_RAW input.", - PHRQ_io::OT_CONTINUE); - } } } @@ -605,3 +616,15 @@ LDBLE cxxGasPhase::Calc_total_moles(void) } return tot; } +cxxGasComp * +cxxGasPhase::Find_comp(const char * comp_name) +{ + for (size_t i = 0; i < this->gas_comps.size(); i++) + { + if (Utilities::strcmp_nocase(this->gas_comps[i].Get_phase_name().c_str(), comp_name) == 0) + { + return &(this->gas_comps[i]); + } + } + return NULL; +} \ No newline at end of file diff --git a/GasPhase.h b/GasPhase.h index a229cbdc..c22eb156 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -72,22 +72,28 @@ class cxxGasPhase:public cxxNumKeyword LDBLE Get_temperature(void) {return (LDBLE) temperature;}; void Set_temperature(LDBLE t) {temperature = t;}; LDBLE Calc_total_moles(void); + cxxGasComp *Find_comp(const char * comp_name); protected: void add(const cxxGasPhase & addee, LDBLE extensive); protected: + // candidate variables for GAS_PHASE_MODIFY + GP_TYPE type; + LDBLE total_p; + LDBLE volume; + std::vector gas_comps; + + // GAS_PHASE_MODIFY with new_def=true variables bool new_def; bool solution_equilibria; int n_solution; - GP_TYPE type; - LDBLE total_p; + LDBLE temperature; + + // internal variables LDBLE total_moles; - LDBLE volume; LDBLE v_m; bool pr_in; - LDBLE temperature; - std::vector gas_comps; cxxNameDouble totals; }; diff --git a/ISolution.cxx b/ISolution.cxx index 527216a6..620cd9a2 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -23,14 +23,21 @@ cxxISolution::cxxISolution(PHRQ_io *io) : -cxxSolution(io), +//cxxSolution(io), units("mMol/kgw") { - density = 1.0; - default_pe = -1; - pes = NULL; -} + default_pe = "pe"; + cxxChemRxn temp_pe_reactions; + pe_reactions[default_pe] = temp_pe_reactions; +} +//cxxISolution::cxxISolution(const cxxISolution *is_old) +//{ +// units = is_old->units; +// comps = is_old->comps; +// pe_reactions = is_old->pe_reactions; +// default_pe = is_old->default_pe; +//} cxxISolution::~cxxISolution() { //// ToDo //pe_data_free(this->pes); @@ -393,7 +400,6 @@ cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const assert(this->pe.size() > 0); assert(this->default_pe >= 0); assert(this->pe.size() > (unsigned int) this->default_pe); - //this->pe[this->default_pe].dump_xml(os, indent + 1); for (i = 0; i < indent + 1; ++i) os << Utilities::INDENT; diff --git a/ISolution.h b/ISolution.h index 34836fe8..caea078e 100644 --- a/ISolution.h +++ b/ISolution.h @@ -12,34 +12,18 @@ #include #include "ISolutionComp.h" -#include "Solution.h" - -class cxxISolution:public cxxSolution +#include "PHRQ_base.h" +#include "NameDouble.h" +#include "global_structures.h" +class cxxISolution: public PHRQ_base { public: cxxISolution(PHRQ_io *io=NULL); - ~cxxISolution(); - //static cxxISolution& read(CParser& parser); - //void add(cxxISolutionComp conc) { this->concs.push_back(conc); } - - LDBLE Get_density() const - { - return this->density; - } - void Set_density(LDBLE l_density) - { - this->density = l_density; - } - - std::string Get_units() const - { - return units; - } - void Set_units(std::string l_units) - { - units = l_units; - } + cxxISolution(const cxxISolution *is); + virtual ~cxxISolution(); + std::string Get_units() const {return units;} + void Set_units(std::string l_units) {units = l_units;} void Set_units(const char * l_units) { if (l_units != NULL) @@ -47,19 +31,21 @@ class cxxISolution:public cxxSolution else this->units.clear(); } - - //char * get_redox()const {return this->pe[this->default_pe].get_name();} + std::string Get_default_pe() const {return default_pe;} + void Set_default_pe(std::string pe) {default_pe = pe;} + std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;} + void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;} + std::map < std::string, cxxChemRxn > &Get_pe_reactions(void) {return this->pe_reactions;} + void Set_pe_reactions(std::map < std::string, cxxChemRxn > &pe) {this->pe_reactions = pe;} //void dump_xml(std::ostream& os, unsigned int indent = 0)const; //void ConvertUnits(PHREEQC_PTR_ARG); protected: friend class cxxISolutionComp; // for this->pe access - LDBLE density; std::string units; std::map < std::string, cxxISolutionComp > comps; - struct pe_data *pes; - int default_pe; - + std::map pe_reactions; + std::string default_pe; }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 2547bed8..3e57ed45 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -4,40 +4,19 @@ #include #include "Utils.h" -#include "Phreeqc.h" #include "ISolutionComp.h" - +#include "Parser.h" +#include "Solution.h" #include "phqalloc.h" cxxISolutionComp::cxxISolutionComp(PHRQ_io *io): PHRQ_base(io), -description(NULL), moles(0.0), input_conc(0.0), -units(NULL), -equation_name(NULL), -phase_si(0.0), -n_pe(-1), -as(NULL), +phase_si(0.0), gfw(0.0) { } -cxxISolutionComp::cxxISolutionComp(struct conc *conc_ptr, PHRQ_io *io) -: PHRQ_base(io) -{ - this->Set_description(conc_ptr->description); - moles = conc_ptr->moles; - input_conc = conc_ptr->input_conc; - this->Set_units(conc_ptr->units); - this->Set_equation_name(conc_ptr->equation_name); - phase_si = conc_ptr->phase_si; - n_pe = conc_ptr->n_pe; - this->Set_as(conc_ptr->as); - gfw = conc_ptr->gfw; - //skip = conc_ptr->skip; - //phase = conc_ptr->phase; -} - cxxISolutionComp::~cxxISolutionComp(void) { } @@ -126,8 +105,6 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) return; } #endif - - #ifdef SKIP cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, cxxISolution & solution) @@ -278,7 +255,6 @@ cxxISolutionComp::STATUS_TYPE cxxISolutionComp::read(CParser & parser, return cxxISolutionComp::OK; } #endif - #ifdef SKIP void cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const @@ -298,3 +274,170 @@ cxxISolutionComp::dump_xml(std::ostream & s_oss, unsigned int indent) const cons s_oss << "\">" << "\n"; } #endif +/* ---------------------------------------------------------------------- */ +CParser::STATUS_TYPE cxxISolutionComp:: +read(const char *line_in, cxxSolution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Remove space between "kg" and "solution" or "water" in units + */ + std::string line = line_in; + Utilities::replace("Kg", "kg", line); + Utilities::replace("KG", "kg", line); + while (Utilities::replace("kg ", "kg", line) == TRUE); +/* + * Read master species list for mass balance equation + */ + std::string master_list; + std::string token; + std::string::iterator b = line.begin(); + std::string::iterator e = line.end(); + { + int j; + while (((j = CParser::copy_token(token, b, e)) == CParser::TT_UPPER) || + (token[0] == '[') || + (Utilities::strcmp_nocase(token.c_str(), "ph") == 0) || + (Utilities::strcmp_nocase(token.c_str(), "pe") == 0)) + { + Utilities::replace("(+", "(", token); + if (master_list.size() > 0) + master_list.append(" "); + master_list.append(token); + } + } + if (master_list.size() == 0) + { + error_msg + ("No element or master species given for concentration input.", + PHRQ_io::OT_CONTINUE); + return (CParser::PARSER_ERROR); + } + this->Set_description(master_list.c_str()); +/* + * Determine if reading alkalinity, allow equivalents for units + */ + bool alk; + Utilities::str_tolower(master_list); + if (strstr(master_list.c_str(), "alk") == master_list.c_str()) + { + alk = true; + } + else + { + alk = false; + } +/* + * Read concentration + */ + { + LDBLE dummy; + int j = sscanf(token.c_str(), SCANFORMAT, &dummy); + if (j == 0) + { + std::ostringstream errstr; + errstr << "Concentration data error for " << master_list << " in solution input."; + error_msg(errstr.str().c_str(), PHRQ_io::OT_CONTINUE); + return (CParser::PARSER_ERROR); + } + else + { + this->Set_input_conc(dummy); + } + if ((j = CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); + } +/* + * Read optional data + */ + std::string token1 = token; + +/* + * Check for units info + */ + CParser parser(this->io); + if (parser.check_units(token1, alk, false, solution_ptr->Get_initial_data()->Get_units().c_str(), false) == CParser::PARSER_OK) + { + if (parser.check_units(token1, alk, false, solution_ptr->Get_initial_data()->Get_units().c_str(), true) == CParser::PARSER_OK) + { + this->units = token1; + if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); + } + else + { + return (CParser::PARSER_ERROR); + } + } +/* + * Check for "as" followed by formula to be used for gfw + */ + token1 = token; + Utilities::str_tolower(token1); + if (strcmp(token1.c_str(), "as") == 0) + { + CParser::copy_token(token, b, e); + this->as = token; + if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); +/* + * Check for "gfw" followed by gram formula weight + */ + } + else if (strcmp(token1.c_str(), "gfw") == 0 || strcmp(token1.c_str(), "gfm") == 0) + { + if (CParser::copy_token(token, b, e) != DIGIT) + { + error_msg("Expecting gram formula weight.", PHRQ_io::OT_CONTINUE); + return (CParser::PARSER_ERROR); + } + else + { + sscanf(token.c_str(), SCANFORMAT, &this->gfw); + if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); + } + } +/* + * Check for redox couple for pe + */ + if (Utilities::strcmp_nocase(token.c_str(), "pe") == 0) + { + this->pe_reaction = token; + if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); + } + else if (strstr(token.c_str(), "/") != NULL) + { + if (parser.parse_couple(token) == CParser::PARSER_OK) + { + this->pe_reaction = token; + if ((CParser::copy_token(token, b, e)) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); + } + else + { + return (CParser::PARSER_ERROR); + } + } +/* + * Must have phase + */ + this->equation_name = token; + if (CParser::copy_token(token, b, e) == CParser::TT_EMPTY) + return (CParser::PARSER_OK); +/* + * Check for saturation index + */ + { + int j = sscanf(token.c_str(), SCANFORMAT, + &(this->phase_si)); + if (j != 1) + { + error_msg("Expected saturation index.", PHRQ_io::OT_CONTINUE); + return (CParser::PARSER_ERROR); + } + } + return (CParser::PARSER_OK); + +} \ No newline at end of file diff --git a/ISolutionComp.h b/ISolutionComp.h index 43cc7bbe..389f76c1 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -13,12 +13,11 @@ class cxxISolutionComp: public PHRQ_base { public: cxxISolutionComp(PHRQ_io *io=NULL); - cxxISolutionComp(struct conc *conc_ptr, PHRQ_io *io=NULL); - ~cxxISolutionComp(void); + virtual ~cxxISolutionComp(void); public: - //STATUS_TYPE read(CParser& parser, CSolution& sol); + CParser::STATUS_TYPE read(const char *line, cxxSolution *solution_ptr); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -85,16 +84,14 @@ class cxxISolutionComp: public PHRQ_base { this->phase_si = l_phase_si; } - - int Get_n_pe() const + std::string Get_pe_reaction() const { - return this->n_pe; + return this->pe_reaction; } - void Set_n_pe(int l_n_pe) + void Set_pe_reaction(const std::string & pe_r) { - this->n_pe = l_n_pe; + this->pe_reaction = pe_r; } - const std::string &Get_as() const { return this->as; @@ -106,8 +103,6 @@ class cxxISolutionComp: public PHRQ_base else this->as.clear(); } - - //LDBLE get_gfw()const {return this->gfw;} LDBLE Get_gfw() const { return this->gfw; @@ -116,7 +111,6 @@ class cxxISolutionComp: public PHRQ_base { this->gfw = l_gfw; } - //void Set_gfw(PHREEQC_PTR_ARG); bool operator<(const cxxISolutionComp & conc) const { @@ -130,7 +124,7 @@ class cxxISolutionComp: public PHRQ_base std::string units; std::string equation_name; LDBLE phase_si; - int n_pe; + std::string pe_reaction; std::string as; LDBLE gfw; }; diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 7dc3edf0..481ffea6 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -13,8 +13,6 @@ //#include "Dictionary.h" #include "phqalloc.h" - - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -33,26 +31,6 @@ PHRQ_base(io) initial_moles = 0; namecoef.type = cxxNameDouble::ND_NAME_COEF; } -#ifdef SKIP -cxxKineticsComp::cxxKineticsComp(struct kinetics_comp *kinetics_comp_ptr, PHRQ_io *io) - // - // constructor for cxxKineticsComp from struct kinetics_comp - // - : -PHRQ_base(io), -namecoef(kinetics_comp_ptr->list, kinetics_comp_ptr->count_list) -{ - this->Set_rate_name(kinetics_comp_ptr->rate_name); - tol = kinetics_comp_ptr->tol; - m = kinetics_comp_ptr->m; - m0 = kinetics_comp_ptr->m0; - moles = kinetics_comp_ptr->moles; - for (int i = 0; i < kinetics_comp_ptr->count_d_params; i++) - { - this->d_params.push_back(kinetics_comp_ptr->d_params[i]); - } -} -#endif cxxKineticsComp::~cxxKineticsComp() { } @@ -61,7 +39,6 @@ cxxKineticsComp::~cxxKineticsComp() void cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -106,7 +83,6 @@ cxxKineticsComp::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing kinetics_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -118,13 +94,10 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); // Kinetics_Comp element and attributes - - //s_oss << indent0 << "-rate_name " << this-> - // rate_name << "\n"; + s_oss << indent1 << "# KINETICS_MODIFY candidate identifiers #\n"; s_oss << indent1 << "-tol " << this->tol << "\n"; s_oss << indent1 << "-m " << this->m << "\n"; s_oss << indent1 << "-m0 " << this->m0 << "\n"; - s_oss << indent1 << "-moles " << this->moles << "\n"; // namecoef s_oss << indent1; @@ -150,6 +123,10 @@ cxxKineticsComp::dump_raw(std::ostream & s_oss, unsigned int indent) const } s_oss << "\n"; } + + s_oss << indent1 << "# KineticsComp workspace variables #\n"; + s_oss << indent1 << "-moles " << this->moles << "\n"; + s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n"; } void @@ -168,6 +145,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) vopts.push_back("moles"); // 4 vopts.push_back("namecoef"); // 5 vopts.push_back("d_params"); // 6 + vopts.push_back("initial_moles"); // 7 } std::istream::pos_type ptr; @@ -177,7 +155,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) std::vector < LDBLE > temp_d_params; opt_save = CParser::OPT_ERROR; - bool rate_name_defined(false); bool tol_defined(false); bool m_defined(false); bool m0_defined(false); @@ -202,23 +179,10 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Kinetics for more processing - //parser.error_msg("Unknown input in KINETICS_COMP read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // rate_name not used - if (!(parser.get_iss() >> str)) - { - this->rate_name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for rate_name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->rate_name = str; - } - rate_name_defined = true; + parser.warning_msg("Rate_name ignored. Define in -comp."); break; case 1: // tol @@ -266,7 +230,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) moles_defined = true; break; - case 5: // namecoef if (this->namecoef.read_raw(parser, next_char) != CParser::PARSER_OK) @@ -289,6 +252,16 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) d_params_defined = true; } opt_save = 6; + break; + case 7: // initial_moles + if (!(parser.get_iss() >> this->initial_moles)) + { + this->moles = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for initial_moles.", + PHRQ_io::OT_CONTINUE); + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -301,12 +274,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (rate_name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Rate_name not defined for KineticsComp input.", - PHRQ_io::OT_CONTINUE); - } if (tol_defined == false) { parser.incr_input_error(); @@ -325,12 +292,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) parser.error_msg("M0 not defined for KineticsComp input.", PHRQ_io::OT_CONTINUE); } - if (moles_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Moles not defined for KineticsComp input.", - PHRQ_io::OT_CONTINUE); - } } } @@ -388,30 +349,16 @@ cxxKineticsComp::add(const cxxKineticsComp & addee, LDBLE extensive) { return; } - //char * rate_name; assert(this->rate_name == addee.rate_name); - //cxxNameDouble namecoef; - //LDBLE tol; - //LDBLE m; this->m += addee.m * extensive; - //LDBLE m0; this->m0 += addee.m0 * extensive; - //LDBLE moles; this->moles += addee.moles * extensive; - //std::vector d_params; } void cxxKineticsComp::multiply(LDBLE extensive) { - //char * rate_name; - //cxxNameDouble namecoef; - //LDBLE tol; - //LDBLE m; this->m *= extensive; - //LDBLE m0; this->m0 *= extensive; - //LDBLE moles; this->moles *= extensive; - //std::vector d_params; } diff --git a/KineticsComp.h b/KineticsComp.h index 3ab179b1..843f296d 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -15,7 +15,7 @@ class cxxKineticsComp: public PHRQ_base public: cxxKineticsComp(PHRQ_io *io=NULL); cxxKineticsComp(struct kinetics_comp *, PHRQ_io *io=NULL); - ~cxxKineticsComp(); + virtual ~cxxKineticsComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; @@ -59,14 +59,16 @@ public: protected: std::string rate_name; + // KINETICS_MODIFY candidates cxxNameDouble namecoef; //stoichiometry of reaction LDBLE tol; LDBLE m; LDBLE m0; + std::vector< LDBLE > d_params; + std::vector< std::string > c_params; // Not used + // kinetics workspace variables LDBLE moles; LDBLE initial_moles; - std::vector< LDBLE > d_params; - std::vector< std::string > c_params; public: diff --git a/Makefile b/Makefile index 2c18be3d..e39c6b96 100644 --- a/Makefile +++ b/Makefile @@ -105,17 +105,17 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 2 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC2 VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC2 VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -199,7 +199,6 @@ COMMON_CXXOBJS = \ runner.o \ Solution.o \ SolutionIsotope.o \ - SolutionIsotopeList.o \ SSassemblage.o \ SScomp.o \ SS.o \ @@ -234,62 +233,74 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../cxxKinetics.h ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../cxxKinetics.h ../KineticsComp.h \ + ../phreeqc/phqalloc.h cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../Exchange.h ../ExchComp.h ../phreeqc/phqalloc.h ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../ExchComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../ExchComp.h ../phreeqc/phqalloc.h GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../GasComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../GasComp.h \ + ../phreeqc/phqalloc.h GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../GasPhase.h ../NameDouble.h ../Phreeqc_class.h \ - ../GasComp.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../GasPhase.h ../GasComp.h ../phreeqc/phqalloc.h ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../ISolutionComp.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../ISolutionComp.h ../Solution.h \ + ../ISolution.h ../phreeqc/phqalloc.h ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../ISolution.h ../ISolutionComp.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../Phreeqc_class.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../ISolution.h ../ISolutionComp.h \ ../phreeqc/phqalloc.h KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ @@ -297,25 +308,35 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../KineticsComp.h ../NameDouble.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../KineticsComp.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../NameDouble.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h ../ISolutionComp.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h + ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h ../Utils.h \ + ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ + ../phreeqc/NA.h Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ @@ -323,42 +344,47 @@ PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ - ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../PPassemblageComp.h ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../PPassemblage.h ../PPassemblageComp.h ../NameDouble.h \ - ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../PPassemblage.h ../PPassemblageComp.h \ + ../phreeqc/phqalloc.h Pressure.o: ../Pressure.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Reaction.h ../NameDouble.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../Reaction.h ../phreeqc/phqalloc.h ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Phreeqc_class.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../NameDouble.h ../Exchange.h ../ExchComp.h \ - ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../PPassemblage.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h ../GasComp.h \ ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h @@ -367,63 +393,60 @@ Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ - ../NameDouble.h ../Phreeqc_class.h ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../Solution.h ../ISolution.h ../ISolutionComp.h ../phreeqc/phqalloc.h SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SolutionIsotope.h ../phreeqc/phqalloc.h -SolutionIsotopeList.o: ../SolutionIsotopeList.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../SolutionIsotope.h ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SSassemblage.h ../NameDouble.h ../Phreeqc_class.h ../SS.h ../SScomp.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ ../phreeqc/phqalloc.h SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../SScomp.h ../NameDouble.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SScomp.h \ ../phreeqc/phqalloc.h SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../SS.h ../NameDouble.h ../Phreeqc_class.h ../SScomp.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SS.h \ + ../SScomp.h ../phreeqc/phqalloc.h StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../NameDouble.h ../StorageBin.h ../System.h ../Phreeqc_class.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ - ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../Reaction.h ../Temperature.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../StorageBin.h ../System.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Reaction.h ../Temperature.h \ ../phreeqc/phqalloc.h SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ @@ -431,54 +454,56 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SurfaceCharge.h ../NameDouble.h ../Phreeqc_class.h \ - ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ - ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../SurfaceCharge.h \ - ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../System.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h \ - ../SolutionIsotopeList.h ../SolutionIsotope.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ - ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../Reaction.h ../Temperature.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../System.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Reaction.h ../Temperature.h Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h \ - ../Temperature.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Temperature.h ../phreeqc/phqalloc.h Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ChartHandler.o: ../ChartHandler.cpp ChartObject.o: ../ChartObject.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -486,42 +511,48 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h CurveObject.o: ../CurveObject.cpp ../CurveObject.h ../phreeqc/phrqtype.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h Keywords.o: ../Keywords.cpp ../Keywords.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Phreeqc.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ - ../Use.h ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h + ../phreeqc/global_structures.h ../Surface.h ../NumKeyword.h \ + ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ + ../Keywords.h ../PHRQ_io.h ../SurfaceCharge.h ../phreeqc/NA.h \ + ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../phreeqc/phqalloc.h ../Utils.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../NameDouble.h ../Parser.h ../Solution.h ../SolutionIsotopeList.h \ - ../SolutionIsotope.h ../Phreeqc_class.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../GasPhase.h ../GasComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ - ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../phreeqc/phqalloc.h ../PBasic.h \ + ../Temperature.h PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h runner.o: ../runner.cpp ../runner.h ../phreeqc/phrqtype.h \ ../StorageBinList.h ../PHRQ_base.h ../Parser.h ../Keywords.h \ ../PHRQ_io.h ../phreeqc/NA.h @@ -529,40 +560,50 @@ StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ ../PHRQ_base.h ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h \ ../PHRQ_io.h Use.o: ../Use.cpp ../Use.h -advection.o: ../phreeqc/advection.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h +advection.o: ../phreeqc/advection.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/../PBasic.h ../phreeqc/../Exchange.h \ - ../phreeqc/../NumKeyword.h ../phreeqc/../ExchComp.h \ - ../phreeqc/../NameDouble.h ../phreeqc/../GasPhase.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../NameDouble.h ../Phreeqc_class.h \ - ../SSassemblage.h ../SS.h ../SScomp.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../phreeqc/../NameDouble.h \ + ../phreeqc/../PBasic.h ../phreeqc/../PHRQ_base.h \ + ../phreeqc/../Exchange.h ../phreeqc/../NumKeyword.h \ + ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ + ../phreeqc/../GasPhase.h ../phreeqc/../Phreeqc_class.h \ + ../phreeqc/../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Parser.h cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -570,14 +611,18 @@ cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h @@ -586,79 +631,95 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../GasPhase.h ../NameDouble.h ../Parser.h ../Phreeqc_class.h \ - ../GasComp.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../GasPhase.h ../GasComp.h input.o: ../phreeqc/input.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h ../SolutionIsotope.h isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../StorageBin.h ../System.h ../NameDouble.h \ - ../Phreeqc_class.h ../Reaction.h ../cxxKinetics.h ../KineticsComp.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h ../cxxMix.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../Temperature.h \ - ../phreeqc/nvector_serial.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ + ../KineticsComp.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ + ../cxxMix.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../Temperature.h ../phreeqc/nvector_serial.h mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../ExchComp.h ../GasPhase.h \ - ../Phreeqc_class.h ../GasComp.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h -model.o: ../phreeqc/model.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../Parser.h ../GasPhase.h ../Phreeqc_class.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../ISolution.h ../ISolutionComp.h +model.o: ../phreeqc/model.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../Solution.h ../ISolution.h ../ISolutionComp.h nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h nvector_serial.o: ../phreeqc/nvector_serial.cpp \ @@ -670,68 +731,84 @@ parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../Parser.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../SS.h + ../SS.h ../SScomp.h ../SS.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../ISolution.h ../ISolutionComp.h read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Pressure.h \ - ../Temperature.h ../Parser.h ../cxxMix.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Pressure.h ../Temperature.h ../Parser.h \ + ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../SS.h ../SScomp.h + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ ../phreeqc/phrqtype.h ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ @@ -741,15 +818,19 @@ readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../phreeqc/phqalloc.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ + ../phreeqc/NA.h ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../Parser.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/sundialsmath.h @@ -758,41 +839,41 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ + ../Utils.h ../Phreeqc.h step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Parser.h \ - ../StorageBin.h ../System.h ../NameDouble.h ../Phreeqc_class.h \ - ../Solution.h ../SolutionIsotopeList.h ../SolutionIsotope.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ + ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../StorageBin.h \ + ../System.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../SS.h ../NameDouble.h ../Temperature.h ../cxxMix.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ + ../cxxKinetics.h ../KineticsComp.h structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Temperature.h ../cxxMix.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../Use.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../phreeqc/../cxxKinetics.h ../phreeqc/../NumKeyword.h \ - ../phreeqc/../KineticsComp.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../PHRQ_base.h ../phreeqc/../Solution.h \ - ../phreeqc/../SolutionIsotopeList.h ../phreeqc/../SolutionIsotope.h \ - ../phreeqc/../Parser.h ../phreeqc/../PHRQ_io.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../SolutionIsotopeList.h \ - ../phreeqc/../Surface.h ../phreeqc/../SurfaceComp.h \ - ../phreeqc/../SurfaceCharge.h ../phreeqc/../SurfaceComp.h \ - ../phreeqc/../SurfaceCharge.h ../phreeqc/../StorageBin.h \ - ../phreeqc/../System.h + ../Use.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ + ../KineticsComp.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ + ../phreeqc/../StorageBin.h ../phreeqc/../System.h \ + ../phreeqc/../NameDouble.h ../phreeqc/../PHRQ_base.h \ + ../phreeqc/../Phreeqc_class.h ../phreeqc/../PHRQ_io.h sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ @@ -801,39 +882,49 @@ tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h \ - ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h ../GasComp.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../Parser.h ../Phreeqc.h ../phreeqc/phqalloc.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h ../GasPhase.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ + ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../ISolution.h ../ISolutionComp.h transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../phreeqc/global_structures.h ../phreeqc/NA.h ../Parser.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../NameDouble.h \ - ../GasPhase.h ../Phreeqc_class.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h -utilities.o: ../phreeqc/utilities.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../phreeqc/global_structures.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../NameDouble.h ../Parser.h ../Exchange.h \ - ../ExchComp.h ../NameDouble.h + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h +utilities.o: ../phreeqc/utilities.cpp ../Utils.h ../Phreeqc.h \ + ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ + ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ + ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ + ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ + ../NameDouble.h ../Exchange.h ../ExchComp.h ../Solution.h ../ISolution.h \ + ../ISolutionComp.h # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug diff --git a/NameDouble.cxx b/NameDouble.cxx index 7f533f32..9278c389 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -14,6 +14,7 @@ #include "NameDouble.h" //#include "Dictionary.h" #include "phqalloc.h" +#include "ISolutionComp.h" ////////////////////////////////////////////////////////////////////// @@ -81,18 +82,19 @@ cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, LDBLE factor) } this->type = old.type; } -cxxNameDouble::cxxNameDouble(struct conc *tots) +cxxNameDouble::cxxNameDouble(std::map < std::string, cxxISolutionComp > &comps) // - // constructor for cxxNameDouble from list of elt_list + // constructor for cxxNameDouble from map of cxxISolutionComp // { - int i; - for (i = 0; tots[i].description != NULL; i++) + std::map < std::string, cxxISolutionComp >::iterator it; + for (it = comps.begin(); it != comps.end(); it++) { - (*this)[tots[i].description] = tots[i].moles; + (*this)[it->first] = it->second.Get_moles(); } this->type = ND_ELT_MOLES; } +#ifdef SKIP cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, cxxNameDouble::ND_TYPE l_type) // @@ -108,22 +110,7 @@ cxxNameDouble::cxxNameDouble(struct master_activity *ma, int count, } this->type = l_type; } -/* -cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) - // - // constructor for cxxNameDouble from list of elt_list - // -{ - int i; - for (i = 0; i < count; i++) - { - if (nc[i].name == NULL) - continue; - (*this)[nc[i].name] = nc[i].coef; - } - this->type = ND_NAME_COEF; -} -*/ +#endif cxxNameDouble::cxxNameDouble(struct name_coef *nc, int count) // // constructor for cxxNameDouble from list of elt_list @@ -155,7 +142,6 @@ cxxNameDouble::~cxxNameDouble() void cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""); @@ -200,7 +186,6 @@ cxxNameDouble::dump_xml(std::ostream & s_oss, unsigned int indent) const void cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing exch_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""); @@ -210,7 +195,7 @@ cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { s_oss << indent0; - s_oss << it->first << " " << it->second << "\n"; + s_oss << Utilities::pad_right(it->first, 29 - indent0.size()) << it->second << "\n"; } } @@ -218,15 +203,10 @@ CParser::STATUS_TYPE cxxNameDouble::read_raw(CParser & parser, std::istream::pos_type & pos) { std::string token; - //char * - // ctoken; LDBLE d; CParser::TOKEN_TYPE j; - - //m_line_iss.seekg(pos); - j = parser.copy_token(token, pos); if (j == CParser::TT_EMPTY) @@ -248,7 +228,6 @@ cxxNameDouble::add_extensive(const cxxNameDouble & addee, LDBLE factor) { if (factor == 0) return; - //assert(factor > 0.0); for (cxxNameDouble::const_iterator it = addee.begin(); it != addee.end(); it++) { @@ -305,13 +284,89 @@ cxxNameDouble::add_log_activities(const cxxNameDouble & addee, LDBLE f1, } else { - //LDBLE a2 = pow(10. it->second); - //(*this)[it->first] = log10(f2 * a2); (*this)[it->first] = it->second + log10(f2); } } } +cxxNameDouble +cxxNameDouble::Simplify_redox(void) +{ + // remove individual redox states from totals + cxxNameDouble &nd = *this; + std::set list_of_elements; + cxxNameDouble::const_iterator it; + for (it = nd.begin(); it != nd.end(); ++it) + { + std::string current_ename(it->first); + std::basic_string < char >::size_type indexCh; + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") + continue; + list_of_elements.insert(current_ename); + } + cxxNameDouble new_totals; + new_totals.type = cxxNameDouble::ND_ELT_MOLES; + std::set::iterator nt_it = list_of_elements.begin(); + for( ; nt_it != list_of_elements.end(); nt_it++) + { + new_totals[(*nt_it).c_str()] = nd.Get_total_element((*nt_it).c_str()); + } + return new_totals; +} +void +cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) +{ + // update original master_activities using just computed factors + cxxNameDouble::iterator it; + LDBLE lg_f = log10(f); + std::string redox_name = str; + redox_name.append("("); + + for (it = this->begin(); it != this->end(); it++) + { + if (it->first == str) + { + // Found exact match + it->second += lg_f; + } + else + { + // no exact match, current is element name, need to find all valences + if (strstr(it->first.c_str(), redox_name.c_str()) == it->first.c_str()) + { + it->second += lg_f; + } + } + } +} +LDBLE +cxxNameDouble::Get_total_element(const char *string) const +{ + cxxNameDouble::const_iterator it; + LDBLE d = 0.0; + for (it = this->begin(); it != this->end(); ++it) + { + // C++ way to do it + std::string ename(string); + std::string current_ename(it->first); + std::basic_string < char >::size_type indexCh; + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + if (current_ename == ename) + { + d += it->second; + } + } + return (d); +} void cxxNameDouble::add(const char *token, LDBLE total) // @@ -452,37 +507,12 @@ cxxNameDouble::mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd) error_msg("Name in NameDouble was not defined in dictionary?\n", STOP); } - //ints.push_back(n); ints[i++] = n; - //doubles.push_back(it->second); doubles[d++] = it->second; } *ii = i; *dd = d; } - -//void -//cxxNameDouble::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -//{ -// int i = *ii; -// int d = *dd; -// extern cxxDictionary dictionary; -// this->clear(); -// int count = ints[i++]; -// for (int j = 0; j < count; j++) -// { -// int n = ints[i++]; -// assert(n >= 0); -// std::string * str = dictionary.int2string(n); -// if (str != NULL) -// { -// char *cstr = string_hsave(str->c_str()); -// (*this)[cstr] = doubles[d++]; -// } -// } -// *ii = i; -// *dd = d; -//} void cxxNameDouble::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { diff --git a/NameDouble.h b/NameDouble.h index 096ff82e..cf7eaabc 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -9,6 +9,7 @@ class Phreeqc; #include "Parser.h" #include "phrqtype.h" +class cxxISolutionComp; class cxxNameDouble:public std::map < std::string, LDBLE > @@ -26,50 +27,39 @@ class cxxNameDouble:public cxxNameDouble(); cxxNameDouble(struct elt_list *); cxxNameDouble(struct elt_list *, int count); - cxxNameDouble(struct conc *); - cxxNameDouble(struct master_activity *ma, int count, ND_TYPE); + cxxNameDouble(std::map < std::string, cxxISolutionComp > &comps); + cxxNameDouble(struct name_coef *nc, int count); cxxNameDouble(const cxxNameDouble & old, LDBLE factor); - ~ - cxxNameDouble(); + ~cxxNameDouble(); - void - dump_xml(std::ostream & s_oss, unsigned int indent) const; - void - dump_raw(std::ostream & s_oss, unsigned int indent) const; - CParser::STATUS_TYPE - read_raw(CParser & parser, std::istream::pos_type & pos); - void - add_extensive(const cxxNameDouble & old, LDBLE factor); - void - add_intensive(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); - void - add_log_activities(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); - void - add(const char *key, LDBLE total); - void - multiply(LDBLE factor); - void - merge_redox(const cxxNameDouble & source); + LDBLE Get_total_element(const char *string) const; + cxxNameDouble Simplify_redox(void); + void Multiply_activities_redox(std::string, LDBLE f); - std::vector< std::pair > - sort_second(void); + void dump_xml(std::ostream & s_oss, unsigned int indent) const; + void dump_raw(std::ostream & s_oss, unsigned int indent) const; + CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type & pos); + void add_extensive(const cxxNameDouble & old, LDBLE factor); + void add_intensive(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); + void add_log_activities(const cxxNameDouble & addee, LDBLE fthis, LDBLE f2); + void add(const char *key, LDBLE total); + void multiply(LDBLE factor); + void merge_redox(const cxxNameDouble & source); + + std::vector< std::pair > sort_second(void); void insert(const char *str, LDBLE d) { (*this)[str] = d; } - void - mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void - mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd); - void - mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); + void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); + void mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd); + void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); - enum ND_TYPE - type; + enum ND_TYPE type; }; diff --git a/NumKeyword.cxx b/NumKeyword.cxx index fb454e7c..5604fb2f 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -7,6 +7,7 @@ #include "NumKeyword.h" #include "Parser.h" +#include "Utils.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -50,32 +51,6 @@ cxxNumKeyword::read_number_description(CParser & parser) // skip keyword parser.copy_token(keyword, ptr); - /* - std::istream::pos_type ptr1 = ptr; - std::string::size_type pos; - std::string token; - if (parser.copy_token(token, ptr) != CParser::TT_DIGIT) - { - this->n_user = 1; - this->n_user_end = 1; - } - else - { - std::istringstream iss(token); - iss >> this->n_user; - this->n_user_end = this->n_user; - std::string token1; - iss >> token1; - if ((pos = token1.find_first_of("-")) != std::string::npos) - { - token1.replace(pos, 1, " "); - std::istringstream iss1(token1); - iss1 >> this->n_user_end; - // ptr1 = ptr; - } - } - */ - // skip whitespace while (::isspace(parser.get_iss().peek())) parser.get_iss().ignore(); @@ -150,3 +125,47 @@ cxxNumKeyword::read_number_description(std::istream & is) std::getline(is, this->description); } +void +cxxNumKeyword::read_number_description(const std::string & line_in) +{ + std::string keyword, token; + //std::istream::pos_type ptr; + + std::string line = line_in; + std::string::iterator b = line.begin(); + std::string::iterator e = line.end(); + // skip keyword + CParser::copy_token(keyword, b, e); + + // read number + if (CParser::copy_token(token, b, e) == CParser::TT_DIGIT) + { + Utilities::replace("-", " ", token); + int j = sscanf(token.c_str(), "%d%d", &this->n_user, &this->n_user_end); + if (j == 0) + { + this->n_user = this->n_user_end = 1; + } + else if (j == 1) + { + this->n_user_end = this->n_user; + } + if (this->n_user_end < this->n_user) + { + this->n_user_end = this->n_user; + } + } + else + { + this->n_user = this->n_user_end = 1; + } + + // skip whitespace + std::string::iterator ic; + this->description.clear(); + for (ic = b; ic != e; ic++) + { + this->description += *ic; + } + trim_left(this->description); +} diff --git a/NumKeyword.h b/NumKeyword.h index 3355f334..f795c4e9 100644 --- a/NumKeyword.h +++ b/NumKeyword.h @@ -15,11 +15,6 @@ class cxxNumKeyword: public PHRQ_base { return this->description; } - - //char *Get_description() const - //{ - // return string_duplicate(this->description.c_str()); - //} void Set_description(std::string str) { this->description = str; @@ -47,6 +42,10 @@ class cxxNumKeyword: public PHRQ_base { this->n_user_end = user_end; } + void Set_n_user_both(int user_end) + { + this->n_user = this->n_user_end = user_end; + } bool operator<(const cxxNumKeyword & key) const { @@ -56,7 +55,7 @@ class cxxNumKeyword: public PHRQ_base virtual void dump_xml(std::ostream & os, unsigned int indent = 0) const; void read_number_description(CParser & parser); - + void read_number_description(const std::string & line_in); protected: int n_user; int n_user_end; diff --git a/PBasic.cpp b/PBasic.cpp index ab947702..58e3eedc 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -11,6 +11,8 @@ #include "Phreeqc.h" #include "phqalloc.h" #include "NameDouble.h" +#include "Utils.h" +#include "Solution.h" /* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ @@ -115,9 +117,6 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } else { - //char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, - // (int) P_ioresult); - //warning_msg(error_string); char * error_string = PhreeqcPtr->sformatf("%d/%d", (int) P_escapecode, (int) P_ioresult); warning_msg(error_string); @@ -1489,6 +1488,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokpressure: output_msg("PRESSURE"); break; + case tokeps_r: + output_msg("EPS_R"); // dielectric constant + break; } l_buf = l_buf->next; } @@ -1849,8 +1851,7 @@ valrec PBasic:: factor(struct LOC_exec * LINK) { char string[MAX_LENGTH] = {0}; - struct solution *soln_ptr; - int nn; + cxxSolution *soln_ptr; varrec *v; tokenrec *facttok; valrec n; @@ -1868,7 +1869,6 @@ factor(struct LOC_exec * LINK) struct save_values s_v, *s_v_ptr; int k; LDBLE TEMP; - //char STR1[256] = {0}, STR2[256] = {0}; std::string STR1, STR2; const char *elt_name, *surface_name, *mytemplate, *name; varrec *count_varrec = NULL, *names_varrec = NULL, *types_varrec = @@ -1878,7 +1878,6 @@ factor(struct LOC_exec * LINK) int arg_num; LDBLE count_species; const char *string1, *string2; - //char *ptr; if (LINK->t == NULL) snerr(": missing variable or command"); @@ -2295,10 +2294,11 @@ factor(struct LOC_exec * LINK) } else { - soln_ptr = PhreeqcPtr->solution_bsearch(PhreeqcPtr->use.Get_n_solution_user(), &nn, TRUE); + soln_ptr = Utilities::Rxn_find(PhreeqcPtr->Rxn_solution_map, + PhreeqcPtr->use.Get_n_solution_user()); if (soln_ptr != NULL) { - n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->description); + n.UU.sval = PhreeqcPtr->string_duplicate(soln_ptr->Get_description().c_str()); } else { @@ -2315,7 +2315,7 @@ factor(struct LOC_exec * LINK) { if (PhreeqcPtr->use.Get_solution_ptr() != NULL) { - n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.Get_solution_ptr()->description); + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->use.Get_solution_ptr()->Get_description().c_str()); } else { @@ -2349,9 +2349,7 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - //PhreeqcPtr->string_trim_left(string1); trim_left(STR1); - //n.UU.sval = PhreeqcPtr->string_duplicate(string1); n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; @@ -2360,8 +2358,6 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - //PhreeqcPtr->string_trim_right(string1); - //n.UU.sval = PhreeqcPtr->string_duplicate(string1); trim_right(STR1); n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; @@ -2371,8 +2367,6 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - //PhreeqcPtr->string_trim(string1); - //n.UU.sval = PhreeqcPtr->string_duplicate(string1); STR1 = trim(STR1); n.UU.sval = PhreeqcPtr->string_duplicate(STR1.c_str()); break; @@ -2389,8 +2383,6 @@ factor(struct LOC_exec * LINK) require(toklp, LINK); string1 = stringfactor(STR1, LINK); require(tokrp, LINK); - //PhreeqcPtr->string_trim(string1); - //n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(string1); trim(STR1); n.UU.sval = (parse_all) ? PhreeqcPtr->string_duplicate("unknown") : PhreeqcPtr->iso_unit(STR1.c_str()); break; @@ -2413,8 +2405,6 @@ factor(struct LOC_exec * LINK) */ if (LINK->t != NULL && LINK->t->kind == tokcomma) { - /*int c; */ - /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ /* return number of species */ LINK->t = LINK->t->next; count_varrec = LINK->t->UU.vp; @@ -2573,8 +2563,6 @@ factor(struct LOC_exec * LINK) /* * Call subroutine */ - // return total moles - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->list_ss(s_s_name, composition); /* @@ -2830,7 +2818,7 @@ factor(struct LOC_exec * LINK) } else if (PhreeqcPtr->state < REACTION) { - n.UU.val = PhreeqcPtr->use.Get_solution_ptr()->n_user; + n.UU.val = PhreeqcPtr->use.Get_solution_ptr()->Get_n_user(); } else { @@ -3060,6 +3048,9 @@ factor(struct LOC_exec * LINK) case tokgas_vm: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->find_gas_vm(); break; + case tokeps_r: + n.UU.val = PhreeqcPtr->eps_r; + break; case toklog10: n.UU.val = log10(realfactor(LINK)); break; @@ -3146,40 +3137,6 @@ factor(struct LOC_exec * LINK) PhreeqcPtr->PHRQ_free(l_s); break; -// case tokmid_: -// n.stringval = true; -// require(toklp, LINK); -// n.UU.sval = strexpr(LINK); -// require(tokcomma, LINK); -// i = intexpr(LINK); -// if (i < 1) -// i = 1; -// j = (int) strlen(n.UU.sval); -// if (LINK->t != NULL && LINK->t->kind == tokcomma) -// { -// LINK->t = LINK->t->next; -// j = intexpr(LINK); -// } -// if (j > (int) strlen(n.UU.sval) - i + 1) -// j = (int) strlen(n.UU.sval) - i + 1; -// if (i > (int) strlen(n.UU.sval)) -// *n.UU.sval = '\0'; -// else -// { -// if (j + 1 > 256) -// { -// warning_msg("String too long in factor\n"); -///* -// STR1 = (char *) PhreeqcPtr->PHRQ_realloc (STR1, j + 1); -// if (STR1 == NULL) -// PhreeqcPtr->malloc_error (); -//*/ -// } -// sprintf(STR1, "%.*s", (int) j, n.UU.sval + i - 1); -// strcpy(n.UU.sval, STR1); -// } -// require(tokrp, LINK); -// break; case tokmid_: n.stringval = true; require(toklp, LINK); @@ -5418,14 +5375,6 @@ cmdgraph_y(struct LOC_exec *LINK) // Add a new curve if necessary if ((int) chart->Get_Curves().size() == chart->Get_colnr()) { - //if (chart->Get_new_headings().size() > 0) - //{ - // // remove x heading - // if (chart->Get_colnr() == chart->Get_ColumnOffset()) - // { - // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - // } - //} if (chart->Get_new_headings().size() > 0) { chart->Add_curve(false, chart->Get_new_headings()[0]); @@ -5482,14 +5431,6 @@ cmdgraph_sy(struct LOC_exec *LINK) // Add a new curve if necessary if ((int) chart->Get_Curves().size() == chart->Get_colnr()) { - //if (chart->Get_new_headings().size() > 0) - //{ - // // remove x heading - // if (chart->Get_colnr() == chart->Get_ColumnOffset()) - // { - // chart->Get_new_headings().erase(chart->Get_new_headings().begin()); - // } - //} if (chart->Get_new_headings().size() > 0) { chart->Add_curve(false, chart->Get_new_headings()[0]); @@ -6406,7 +6347,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("pr_phi", PBasic::tokpr_phi), std::map::value_type("gas_p", PBasic::tokgas_p), std::map::value_type("gas_vm", PBasic::tokgas_vm), - std::map::value_type("pressure", PBasic::tokpressure) + std::map::value_type("pressure", PBasic::tokpressure), + std::map::value_type("eps_r", PBasic::tokeps_r) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 847546c1..d8ab2d3a 100644 --- a/PBasic.h +++ b/PBasic.h @@ -107,17 +107,6 @@ public: } UU; }; -#ifdef SKIP -typedef struct valrec -{ - bool stringval; - union - { - LDBLE val; - char *sval; - } UU; -} valrec; -#endif typedef struct looprec { struct looprec *next; @@ -145,7 +134,7 @@ class PBasic: public PHRQ_base { public: PBasic(Phreeqc *ptr, PHRQ_io *phrq_io=NULL); - ~PBasic(); + virtual ~PBasic(); enum BASIC_TOKEN { @@ -312,7 +301,8 @@ public: tokgas_p, tokgas_vm, tokpressure, - tokerase + tokerase, + tokeps_r }; #if !defined(PHREEQCI_GUI) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 9b4af7bc..5561a7af 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -15,10 +15,13 @@ PHRQ_io(void) { output_ostream = NULL; log_ostream = NULL; - punch_ostream = NULL; + punch_ostream = NULL; +#ifdef ERROR_OSTREAM error_ostream = NULL; +#else + error_file = NULL; +#endif dump_ostream = NULL; - //screen_ostream = NULL; io_error_count = 0; output_on = true; @@ -160,6 +163,7 @@ punch_msg(const char * str) // ---------------------------------------------------------------------- */ // error file methods // ---------------------------------------------------------------------- */ +#ifdef ERROR_OSTREAM /* ---------------------------------------------------------------------- */ bool PHRQ_io:: error_open(const char *file_name, std::ios_base::openmode mode) @@ -205,20 +209,204 @@ error_msg(const char *err_str, bool stop) io_error_count++; if (error_ostream != NULL && error_on) { - (*error_ostream) << err_str; - error_ostream->flush(); + //(*error_ostream) << err_str; + screen_msg(err_str); + error_flush(); } if (stop) { if (error_ostream != NULL && error_on) { - (*error_ostream) << "Stopping.\n"; + //(*error_ostream) << "Stopping.\n"; + screen_msg("Stopping.\n"); error_ostream->flush(); } output_msg("Stopping.\n"); log_msg("Stopping.\n"); } } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (error_ostream != NULL && error_on) + { + //(*error_ostream) << err_str << "\n"; + std::string err_stdstr(err_str); + err_stdstr.append("\n"); + screen_msg(err_stdstr.c_str()); + error_ostream->flush(); + } + std::ostringstream warn_str; + warn_str << err_str << "\n"; + log_msg(warn_str.str().c_str()); + log_flush(); + output_msg(warn_str.str().c_str()); + output_flush(); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str, bool force_print) +/* ---------------------------------------------------------------------- */ +{ + clock_t t2 = 0; + if (!force_print) + { + t2 = clock(); + if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) + { + return; + } + else + { + status_timer = t2; + } + } + + if (error_ostream != NULL && (screen_on || force_print)) + { + (*error_ostream) << str; + } + if (force_print) + error_ostream->flush(); +} +#endif +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + std::string stdstr(str); + if (error_ostream != NULL && screen_on) + { + //(*error_ostream) << stdstr; + fprintf(error_file, "%s", str); + } +} +#else +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +error_open(const char *file_name, const char * mode) +/* ---------------------------------------------------------------------- */ +{ + if (file_name != NULL) + { + if ((error_file = fopen(file_name, mode)) == NULL) + { + error_file = stderr; + return false; + } + } + else + { + error_file = stderr; + } + return true; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_file) + { + fflush(error_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&error_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + + io_error_count++; + if (error_file != NULL && error_on) + { + //(*error_file) << err_str; + screen_msg(err_str); + error_flush(); + } + if (stop) + { + if (error_file != NULL && error_on) + { + //(*error_file) << "Stopping.\n"; + screen_msg("Stopping.\n"); + fflush(error_file); + } + output_msg("Stopping.\n"); + log_msg("Stopping.\n"); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (error_file != NULL && error_on) + { + //(*error_file) << err_str << "\n"; + std::string err_stdstr(err_str); + err_stdstr.append("\n"); + screen_msg(err_stdstr.c_str()); + error_flush(); + } + std::ostringstream warn_str; + warn_str << err_str << "\n"; + log_msg(warn_str.str().c_str()); + log_flush(); + output_msg(warn_str.str().c_str()); + output_flush(); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str, bool force_print) +/* ---------------------------------------------------------------------- */ +{ + clock_t t2 = 0; + if (!force_print) + { + t2 = clock(); + if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) + { + return; + } + else + { + status_timer = t2; + } + } + + if (error_ostream != NULL && (screen_on || force_print)) + { + (*error_ostream) << str; + } + if (force_print) + error_ostream->flush(); +} +#endif +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + std::string stdstr(str); + if (error_file != NULL && screen_on) + { + fprintf(error_file, "%s", str); + } +} +#endif // ---------------------------------------------------------------------- */ // dump ostream methods // ---------------------------------------------------------------------- */ @@ -260,85 +448,6 @@ dump_msg(const char * str) (*dump_ostream) << str; } } -///* ---------------------------------------------------------------------- */ -//void PHRQ_io:: -//dump_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (dump_ostream && dump_on) -// { -// dump_ostream->seekp(0, std::ios_base::beg); -// } -//} -///* ---------------------------------------------------------------------- */ -//bool PHRQ_io:: -//dump_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (dump_ostream) -// { -// if (std::ofstream *ofs = dynamic_cast(dump_ostream)) -// { -// return ofs->is_open(); -// } -// return true; -// } -// return false; -//} -#ifdef SKIP -// ---------------------------------------------------------------------- */ -// screen ostream methods -// ---------------------------------------------------------------------- */ -/* ---------------------------------------------------------------------- */ -bool PHRQ_io:: -screen_open(const char *file_name, std::ios_base::openmode mode) -/* ---------------------------------------------------------------------- */ -{ - if ((screen_ostream = new std::ofstream(file_name, mode)) == NULL) - { - return false; // error - } - return true; -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_flush(void) -/* ---------------------------------------------------------------------- */ -{ - if (screen_ostream) - { - screen_ostream->flush(); - } -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_close(void) -/* ---------------------------------------------------------------------- */ -{ - safe_close(&screen_ostream); -} -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_msg(const char * str) -/* ---------------------------------------------------------------------- */ -{ - if (screen_ostream != NULL && screen_on) - { - (*screen_ostream) << str; - } -} -#endif -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_msg(const char * str) -/* ---------------------------------------------------------------------- */ -{ - if (error_ostream != NULL && screen_on) - { - (*error_ostream) << str; - } -} - int PHRQ_io:: istream_getc(void *cookie) //istream_getc is *** static *** { @@ -354,23 +463,7 @@ istream_getc(void *cookie) //istream_getc is *** static *** } return EOF; } -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -warning_msg(const char *err_str) -/* ---------------------------------------------------------------------- */ -{ - if (error_ostream != NULL && error_on) - { - (*error_ostream) << err_str << "\n"; - error_ostream->flush(); - } - std::ostringstream warn_str; - warn_str << err_str << "\n"; - log_msg(warn_str.str().c_str()); - log_flush(); - output_msg(warn_str.str().c_str()); - output_flush(); -} + /* ---------------------------------------------------------------------- */ void PHRQ_io:: fpunchf(const char *name, const char *format, double d) @@ -429,9 +522,12 @@ close_ostreams(void) streams.insert(output_ostream); streams.insert(log_ostream); streams.insert(punch_ostream); +#ifdef ERROR_OSTREAM streams.insert(error_ostream); +#else + safe_close(&error_file); +#endif streams.insert(dump_ostream); - //streams.insert(screen_ostream); std::set::iterator it = streams.begin(); for (; it != streams.end(); it++) @@ -443,9 +539,12 @@ close_ostreams(void) output_ostream = NULL; log_ostream = NULL; punch_ostream = NULL; +#ifdef ERROR_OSTREAM error_ostream = NULL; +#else + error_file = NULL; +#endif dump_ostream = NULL; - //screen_ostream = NULL; } //safe_close is static method /* ---------------------------------------------------------------------- */ @@ -455,13 +554,26 @@ safe_close(std::ostream **stream_ptr) { if (*stream_ptr != &std::cerr && *stream_ptr != &std::cout && + *stream_ptr != &std::clog && *stream_ptr != NULL) { delete *stream_ptr; *stream_ptr = NULL; } } - +void PHRQ_io:: +safe_close(FILE **file_ptr) +/* ---------------------------------------------------------------------- */ +{ + if (*file_ptr != NULL && + *file_ptr != stderr && + *file_ptr != stdout && + *file_ptr != stdin ) + { + fclose(*file_ptr); + *file_ptr = NULL; + } +} /* ---------------------------------------------------------------------- */ void PHRQ_io:: echo_msg(const char * str) @@ -567,27 +679,8 @@ get_line(void) */ continue_loop = false; - - //if (!m_input_stream.eof()) - ////{ - //// error_msg("Reading input file.", OT_CONTINUE); - //// error_msg("istream::get() returned an error.", OT_STOP); - ////} - ////else - //{ - // //{{MOD - // m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); - // //}}MOD - // m_next_keyword = Keywords::KEY_END; - // return LT_EOF; - //} if (get_logical_line(cookie) == LT_EOF) { - //if (!m_input_stream.eof()) - //{ - // error_msg("Reading input file.", OT_CONTINUE); - // error_msg("istream::get() returned an error.", OT_STOP); - //} //pop next file this->pop_istream(); continue_loop = true; @@ -643,9 +736,6 @@ get_line(void) } // add new include file to stack - //ptr = line; - //copy_token(stdtoken, &ptr); - std::string::iterator beg = m_line.begin(); std::string::iterator end = m_line.end(); CParser::copy_token(stdtoken, beg, end); @@ -662,8 +752,6 @@ get_line(void) std::ifstream *next_stream = new std::ifstream(file_name.c_str(), std::ios_base::in); if (!next_stream->is_open()) { - // error opening file - // error_string = sformatf( "Could not open include file %s", file_name); std::ostringstream errstr; errstr << "Could not open include file " << file_name; error_msg(errstr.str().c_str(), OT_STOP); @@ -698,8 +786,6 @@ get_logical_line(void * cookie) if (!cookie) return LT_EOF; m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); - - //while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) while ((j = istream_getc(cookie)) != EOF) { c = (char) j; @@ -716,9 +802,6 @@ get_logical_line(void * cookie) m_line_save += c; } while ((j = istream_getc(cookie)) != EOF); - //while ((j = - // m_input_stream.get()) != std::char_traits < - // char >::eof()); } if (c == ';') break; @@ -730,7 +813,6 @@ get_logical_line(void * cookie) { pos = (int) m_line_save.size(); m_line_save += c; - //while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) while ((j = PHRQ_io::istream_getc(cookie)) != EOF) { c = (char) j; @@ -744,11 +826,6 @@ get_logical_line(void * cookie) { // remove '\\' m_line_save = m_line_save.substr(0,pos); - //for (; pos < m_line_save.size(); pos++) - //{ - // m_line_save[pos] = m_line_save[pos + 1]; - //} - //m_line_save.erase(m_line_save.size() - 1, 1); break; } m_line_save += c; diff --git a/PHRQ_io.h b/PHRQ_io.h index da220ac5..bd97b094 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -11,6 +11,7 @@ #include #include #include "Keywords.h" +#include class PhreeqcStop : std::exception { @@ -40,6 +41,7 @@ public: // methods static int istream_getc(void *cookie); static void safe_close(std::ostream **stream_ptr); + static void safe_close(FILE **file_ptr); void close_ostreams(void); void Set_io_error_count(int i) {this->io_error_count = i;}; int Get_io_error_count(void) {return this->io_error_count;}; @@ -66,31 +68,43 @@ public: void log_flush(void); void log_close(void); virtual void log_msg(const char * str); - void Set_log_ostream(std::ostream * out) {this->log_ostream = out;}; - std::ostream *Get_log_ostream(void) {return this->log_ostream;}; - void Set_log_on(bool tf) {this->log_on = tf;}; - bool Get_log_on(void) {return this->log_on;}; + void Set_log_ostream(std::ostream * out) {this->log_ostream = out;} + std::ostream *Get_log_ostream(void) {return this->log_ostream;} + void Set_log_on(bool tf) {this->log_on = tf;} + bool Get_log_on(void) {return this->log_on;} // punch_ostream virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void punch_flush(void); void punch_close(void); virtual void punch_msg(const char * str); - void Set_punch_ostream(std::ostream * out) {this->punch_ostream = out;}; - std::ostream *Get_punch_ostream(void) {return this->punch_ostream;}; - void Set_punch_on(bool tf) {this->punch_on = tf;}; - bool Get_punch_on(void) {return this->punch_on;}; + void Set_punch_ostream(std::ostream * out) {this->punch_ostream = out;} + std::ostream *Get_punch_ostream(void) {return this->punch_ostream;} + void Set_punch_on(bool tf) {this->punch_on = tf;} + bool Get_punch_on(void) {return this->punch_on;} // error_ostream +#ifdef ERROR_OSTREAM bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void error_flush(void); void error_close(void); virtual void error_msg(const char * str, bool stop=false); - void Set_error_ostream(std::ostream * out) {this->error_ostream = out;}; - std::ostream *Get_error_ostream(void) {return this->error_ostream;}; - void Set_error_on(bool tf) {this->error_on = tf;}; - bool Get_error_on(void) {return this->error_on;}; + void Set_error_ostream(std::ostream * out) {this->error_ostream = out;} + std::ostream *Get_error_ostream(void) {return this->error_ostream;} + void Set_error_on(bool tf) {this->error_on = tf;} + bool Get_error_on(void) {return this->error_on;} virtual void warning_msg(const char *err_str); +#else + bool error_open(const char *file_name, const char * mode = "w"); + void error_flush(void); + void error_close(void); + virtual void error_msg(const char * str, bool stop=false); + void Set_error_file(FILE * out) {this->error_file = out;} + FILE *Get_error_file(void) {return this->error_file;} + void Set_error_on(bool tf) {this->error_on = tf;} + bool Get_error_on(void) {return this->error_on;} + virtual void warning_msg(const char *err_str); +#endif // dump_ostream bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); @@ -108,13 +122,7 @@ public: virtual void fpunchf(const char *name, const char *format, int d); virtual void fpunchf_end_row(const char *format); - // screen_ostream - //bool screen_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); - //void screen_flush(void); - //void screen_close(void); virtual void screen_msg(const char * str); - //void Set_screen_ostream(std::ostream * out) {this->screen_ostream = out;}; - //std::ostream *Get_screen_ostream(void) {return this->screen_ostream;}; void Set_screen_on(bool tf) {this->screen_on = tf;}; bool Get_screen_on(void) {return this->screen_on;}; @@ -153,9 +161,12 @@ protected: std::ostream *output_ostream; std::ostream *log_ostream; std::ostream *punch_ostream; +#ifdef ERROR_OSTREAM std::ostream *error_ostream; +#else + FILE * error_file; +#endif std::ostream *dump_ostream; - //std::ostream *screen_ostream; int io_error_count; bool output_on; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 12b97311..5cafdf41 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -57,7 +57,6 @@ cxxPPassemblage::~cxxPPassemblage() void cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -88,7 +87,6 @@ cxxPPassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const void cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing PPassemblage message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -105,20 +103,23 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << "EQUILIBRIUM_PHASES_RAW " << n_user_local << " " << this-> description << "\n"; - // eltList - s_oss << indent1; - s_oss << "-eltList " << "\n"; - this->eltList.dump_raw(s_oss, indent + 2); - - // ppAssemblagComps + s_oss << indent1 << "# EXCHANGE_MODIFY candidates; use new_def=true #\n"; + s_oss << indent1 << "-new_def " << this->new_def << "\n"; for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { s_oss << indent1; - s_oss << "-component" << "\n"; + s_oss << "-component " << (*it).second.Get_name() << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } + s_oss << indent1; + s_oss << "-eltList # List of all elements in phases and alternate reactions\n"; + this->eltList.dump_raw(s_oss, indent + 2); + + s_oss << indent1 << "# PPassemblage workspace variables #\n"; + s_oss << indent1 << "-assemblage_totals" << "\n"; + this->assemblage_totals.dump_raw(s_oss, indent + 1); } void @@ -130,6 +131,8 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) vopts.reserve(15); vopts.push_back("eltlist"); // 0 vopts.push_back("component"); // 1 + vopts.push_back("new_def"); // 2 + vopts.push_back("assemblage_totals"); // 3 } std::istream::pos_type ptr; @@ -158,6 +161,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) { opt = opt_save; } + useLastLine = false; switch (opt) { case CParser::OPT_EOF: @@ -185,39 +189,57 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) } opt_save = 0; break; - case 1: // component { - cxxPPassemblageComp ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - if (this->pp_assemblage_comps.find(ec.Get_name()) != this->pp_assemblage_comps.end()) + std::string str; + if (!(parser.get_iss() >> str)) { - cxxPPassemblageComp & comp = this->pp_assemblage_comps.find(ec.Get_name())->second; - comp.read_raw(reread, false); + parser.incr_input_error(); + parser.error_msg("Expected string value for component name.", + PHRQ_io::OT_CONTINUE); } else { - cxxPPassemblageComp ppComp1(this->Get_io()); - ppComp1.read_raw(reread, false); - std::string str(ppComp1.Get_name()); - this->pp_assemblage_comps[str] = ppComp1; + cxxPPassemblageComp temp_comp(this->io); + temp_comp.Set_name(str.c_str()); + cxxPPassemblageComp *comp_ptr = this->Find(str); + if (comp_ptr) + { + temp_comp = *comp_ptr; + } + temp_comp.read_raw(parser, check); + this->pp_assemblage_comps[str] = temp_comp; + useLastLine = true; } } - useLastLine = true; + break; + case 2: // new_def + if (!(parser.get_iss() >> this->new_def)) + { + this->new_def = false; + parser.incr_input_error(); + parser. + error_msg + ("Expected boolean value for new_def.", + PHRQ_io::OT_CONTINUE); + } + break; + case 3: // assemblage_totals + if (this->assemblage_totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for PPassemblage totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 3; break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined } #ifdef USE_MPI @@ -265,21 +287,19 @@ cxxPPassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) *dd = d; } #endif - void cxxPPassemblage::totalize(PHREEQC_PTR_ARG) { - this->totals.clear(); + this->assemblage_totals.clear(); // component structures for (std::map < std::string, cxxPPassemblageComp >::iterator it = pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { (*it).second.totalize(P_INSTANCE); - this->totals.add_extensive((*it).second.Get_totals(), 1.0); + this->assemblage_totals.add_extensive((*it).second.Get_totals(), 1.0); } return; } - void cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) // @@ -288,7 +308,6 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) { if (extensive == 0.0) return; - //std::list ppAssemblageComps; for (std::map < std::string, cxxPPassemblageComp >::const_iterator itadd = addee.pp_assemblage_comps.begin(); itadd != addee.pp_assemblage_comps.end(); ++itadd) { diff --git a/PPassemblage.h b/PPassemblage.h index 9ae894e9..321184ca 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -17,7 +17,6 @@ class cxxPPassemblage:public cxxNumKeyword public: cxxPPassemblage(PHRQ_io * io=NULL); - //cxxPPassemblage(struct pp_assemblage *, PHRQ_io * io=NULL); cxxPPassemblage(const std::map < int, cxxPPassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io=NULL); ~cxxPPassemblage(); @@ -26,9 +25,9 @@ class cxxPPassemblage:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - const cxxNameDouble & Get_totals() const + const cxxNameDouble & Get_assemblage_totals() const { - return this->totals; + return this->assemblage_totals; }; const cxxNameDouble & Get_eltList() const { @@ -62,8 +61,8 @@ protected: protected: bool new_def; std::map pp_assemblage_comps; - cxxNameDouble eltList; - cxxNameDouble totals; + cxxNameDouble eltList; // list of elements in phases (and alternate reactions) + cxxNameDouble assemblage_totals; // after totalize, total moles of elements in the PPassemblage }; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 24ac121a..0df9ac0f 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -41,7 +41,6 @@ cxxPPassemblageComp::~cxxPPassemblageComp() void cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -55,8 +54,7 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const // Pure_Phase element and attributes s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; - s_oss << indent0 << "add_formula=\"" << this-> - add_formula << "\"" << "\n"; + s_oss << indent0 << "add_formula=\"" << this->add_formula << "\"" << "\n"; s_oss << indent0 << "si=\"" << this->si << "\"" << "\n"; s_oss << indent0 << "si_org=\"" << this->si_org << "\"" << "\n"; s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; @@ -75,7 +73,6 @@ cxxPPassemblageComp::dump_xml(std::ostream & s_oss, unsigned int indent) const void cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -87,19 +84,21 @@ cxxPPassemblageComp::dump_raw(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); // Pure_Phase element and attributes - - if (this->name.size() != 0) - s_oss << indent0 << "-name " << this->name << "\n"; + s_oss << indent1 << "# EQUILIBRIUM_PHASES_MODIFY candidate identifiers #\n"; if (this->add_formula.size() != 0) s_oss << indent1 << "-add_formula " << this->add_formula << "\n"; s_oss << indent1 << "-si " << this->si << "\n"; - s_oss << indent1 << "-si_org " << this->si_org << "\n"; s_oss << indent1 << "-moles " << this->moles << "\n"; - s_oss << indent1 << "-delta " << this->delta << "\n"; - s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n"; s_oss << indent1 << "-force_equality " << this->force_equality << "\n"; s_oss << indent1 << "-dissolve_only " << this->dissolve_only << "\n"; s_oss << indent1 << "-precipitate_only " << this->precipitate_only << "\n"; + + s_oss << indent1 << "# PPassemblage workspace variables #\n"; + s_oss << indent1 << "-si_org " << this->si_org << "\n"; + s_oss << indent1 << "-delta " << this->delta << "\n"; + s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n"; + s_oss << indent1 << "-totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 2); } void @@ -121,6 +120,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) vopts.push_back("force_equality"); // 7 vopts.push_back("precipitate_only"); // 8 vopts.push_back("si_org"); // 9 + vopts.push_back("totals"); // 10 } std::istream::pos_type ptr; @@ -129,7 +129,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool name_defined(false); bool si_defined(false); bool si_org_defined(false); bool moles_defined(false); @@ -157,23 +156,10 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in PURE_PHASE read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->name = str; - } - name_defined = true; + parser.warning_msg("-name ignored. Name is defined with -component."); break; case 1: // add_formula @@ -285,6 +271,17 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) } si_org_defined = true; break; + case 10: // totals + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for Surface totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 10; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -292,12 +289,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) // members that must be defined if (check) { - if (name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Name not defined for PPassemblageComp input.", - PHRQ_io::OT_CONTINUE); - } if (si_defined == false) { parser.incr_input_error(); @@ -328,15 +319,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) parser.error_msg("Dissolve_only not defined for PPassemblageComp input.", PHRQ_io::OT_CONTINUE); } - /* don't check to maintain backward compatibility - if (precipitate_only_defined == false) - { - parser.incr_input_error(); - parser. - error_msg("Precipitate_only not defined for PPassemblageComp input.", - PHRQ_io::OT_CONTINUE); - } - */ if (force_equality_defined == false) { parser.incr_input_error(); @@ -344,12 +326,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) ("Force_equality not defined for PPassemblageComp input.", PHRQ_io::OT_CONTINUE); } - if (si_org_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Si_org not defined for PPassemblageComp input.", - PHRQ_io::OT_CONTINUE); - } } } @@ -439,8 +415,6 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, LDBLE extensive) f1 = 0.5; f2 = 0.5; } - //char * name; - //char *add_formula; if (this->name.size() == 0 && addee.name.size() == 0) { @@ -456,33 +430,17 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, LDBLE extensive) error_msg(oss.str().c_str(), CONTINUE); return; } - //LDBLE si; this->si = this->si * f1 + addee.si * f2; - //LDBLE si_org; this->si_org = this->si_org * f1 + addee.si_org * f2; - //LDBLE moles; this->moles += addee.moles * extensive; - //LDBLE delta; this->delta += addee.delta * extensive; - //LDBLE initial_moles; this->initial_moles += addee.initial_moles * extensive; - //bool force_equality; - //bool dissolve_only; - } void cxxPPassemblageComp::multiply(LDBLE extensive) { - //char * name; - //char *add_formula; - //LDBLE si; - //LDBLE moles; this->moles *= extensive; - //LDBLE delta; this->delta *= extensive; - //LDBLE initial_moles; this->initial_moles *= extensive; - //bool force_equality; - //bool dissolve_only; } diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 9f30d6db..6626043d 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -15,8 +15,7 @@ class cxxPPassemblageComp: public PHRQ_base public: cxxPPassemblageComp(PHRQ_io *io=NULL); - //cxxPPassemblageComp(struct pure_phase *, PHRQ_io *io=NULL); - ~cxxPPassemblageComp(); + virtual ~cxxPPassemblageComp(); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; diff --git a/Parser.cxx b/Parser.cxx index 81a49d37..d530ad1f 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -350,54 +350,10 @@ PHRQ_io::LINE_TYPE CParser::get_logical_line() bool CParser::check_key(std::string::iterator begin, std::string::iterator end) { -// static std::map < std::string, KEY_TYPE > s_keyword_map; -// if (s_keyword_map.size() == 0) -// { -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("solution_raw", -// KT_SOLUTION_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("exchange_raw", -// KT_EXCHANGE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("gas_phase_raw", -// KT_GASPHASE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("kinetics_raw", -// KT_KINETICS_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("equilibrium_phases_raw", -// KT_PPASSEMBLAGE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("solid_solutions_raw", -// KT_SSASSEMBLAGE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("surface_raw", -// KT_SURFACE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("reaction_temperature_raw", -// KT_TEMPERATURE_RAW)); -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("reaction_raw", -// KT_REACTION_RAW)); -//#if defined MULTICHART -// s_keyword_map.insert(std::map < std::string, -// KEY_TYPE >::value_type("user_graph", -// KT_USER_GRAPH)); -//#endif -// } - std::string lowercase; copy_token(lowercase, begin, end); std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), tolower); - - //m_next_keyword = Keywords::KEY_NONE; - //std::map < std::string, KEY_TYPE >::iterator map_iter = - // s_keyword_map.find(lowercase); - //if (map_iter == s_keyword_map.end()) - // return false; - //m_next_keyword = (*map_iter).second; m_next_keyword = Keywords::Keyword_search(lowercase); if (m_next_keyword == Keywords::KEY_NONE) { @@ -405,7 +361,6 @@ CParser::check_key(std::string::iterator begin, std::string::iterator end) } return true; } -#ifdef SKIP CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, bool alkalinity, bool check_compatibility, @@ -512,7 +467,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, { std::ostringstream err; err << "Unknown unit, " << tot_units; - error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); + this->error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; } @@ -530,7 +485,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, { if (print) { - warning_msg + this->warning_msg ("Alkalinity given in moles, assumed to be equivalents."); } replace("Mol", "eq", tot_units); @@ -539,7 +494,7 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, { if (print) { - error_msg("Only alkalinity can be entered in equivalents.", + this->error_msg("Only alkalinity can be entered in equivalents.", PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; @@ -573,11 +528,10 @@ CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, std::ostringstream err; err << "Units for master species, " << tot_units << ", are not compatible with default units, " << str << "."; - error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); + this->error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); } return PARSER_ERROR; } -#endif CParser::TOKEN_TYPE CParser::token_type(const std::string & token) { if (!token.empty()) @@ -695,10 +649,7 @@ CParser::get_option(const std::vector < std::string > &opt_list, // int j; int /* opt_l, */ opt; - //char *opt_ptr; std::string::iterator opt_ptr; - - // char option[MAX_LENGTH]; std::string option; fprintf(stderr, "Did not think this get_option was called\n"); @@ -1042,7 +993,6 @@ CParser::STATUS_TYPE CParser::addPair(std::map < std::string, LDBLE >&totals, std::istream::pos_type & pos) { std::string token; - //char * ctoken; LDBLE d; CParser::TOKEN_TYPE j; @@ -1058,8 +1008,6 @@ CParser::STATUS_TYPE CParser::addPair(std::map < std::string, LDBLE >&totals, { return PARSER_ERROR; } - //ctoken = string_hsave(token.c_str()); - //totals[ctoken] = d; totals[token] = d; return PARSER_OK; } @@ -1073,10 +1021,7 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, // int j; int /* opt_l, */ opt; - //char *opt_ptr; std::string::iterator opt_ptr; - - // char option[MAX_LENGTH]; std::string option; // @@ -1110,7 +1055,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - //get_output() << "\t" << m_line_save << "\n"; std::ostringstream msg; msg << "\t" << m_line_save << "\n"; io->output_msg(msg.str().c_str()); @@ -1123,13 +1067,10 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // (database_file == NULL) { - //get_output() << "\t" << m_line_save << "\n"; std::ostringstream msg; msg << "\t" << m_line_save << "\n"; io->output_msg(msg.str().c_str()); } - //std::cerr << "Unknown option." << "\n"; - //std::cerr << m_line_save << "\n"; std::ostringstream err; err << "Unknown option." << "\n"; err << m_line_save << "\n"; @@ -1215,7 +1156,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - //get_output() << "\t" << m_line_save << "\n"; std::ostringstream msg; msg << "\t" << m_line_save << "\n"; io->output_msg(msg.str().c_str()); @@ -1228,7 +1168,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // (database_file == NULL) { - //get_output() << "\t" << m_line_save << "\n"; std::ostringstream msg; msg << "\t" << m_line_save << "\n"; io->output_msg(msg.str().c_str()); @@ -1259,7 +1198,6 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { - //get_output() << "\t" << m_line_save << "\n"; std::ostringstream msg; msg << "\t" << m_line_save << "\n"; io->output_msg(msg.str().c_str()); @@ -1340,7 +1278,6 @@ bool CParser::get_true_false(std::istream::pos_type & pos, bool def) CParser::TOKEN_TYPE CParser::get_rest_of_line(std::string &token) { token.clear(); - //std::istringstream::pos_type pos = m_line_iss.tellg(); int j; while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) { diff --git a/Parser.h b/Parser.h index 97e630f6..7c062220 100644 --- a/Parser.h +++ b/Parser.h @@ -106,9 +106,9 @@ class CParser: public PHRQ_base // bool check_key(const std::string::iterator ptr); bool check_key(std::string::iterator begin, std::string::iterator end); - //STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, - // bool check_compatibility, - // const std::string & default_units, bool print); + STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, + bool check_compatibility, + const std::string & default_units, bool print); //KEY_TYPE next_keyword() const diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 00bec549..566567eb 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -125,7 +125,6 @@ Phreeqc::Phreeqc(PHRQ_io *io) // phqalloc.c // print.c - status_on = FALSE; sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); if (sformatf_buffer == NULL) malloc_error(); @@ -177,13 +176,14 @@ size_t Phreeqc::list_components(std::list &list_c) //accumulator.add("H", 1); //accumulator.add("O", 1); - int i; - // solutions - for (i = 0; i < count_solution; i++) { - cxxSolution entity(solution[i], phrq_io); - accumulator.add_extensive(entity.Get_totals(), 1.0); + std::map::const_iterator cit = Rxn_solution_map.begin(); + for (; cit != Rxn_solution_map.end(); cit++) + { + cxxSolution entity(cit->second); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } } // irreversible reactions @@ -204,7 +204,7 @@ size_t Phreeqc::list_components(std::list &list_c) { cxxPPassemblage entity = cit->second; entity.totalize(this); - accumulator.add_extensive(entity.Get_totals(), 1.0); + accumulator.add_extensive(entity.Get_eltList(), 1.0); } } // exchangers @@ -219,13 +219,15 @@ size_t Phreeqc::list_components(std::list &list_c) } // surfaces - for (i = 0; i < count_surface; i++) { - cxxSurface entity(&surface[i], phrq_io); - entity.totalize(); - accumulator.add_extensive(entity.Get_totals(), 1.0); + std::map::const_iterator cit = Rxn_surface_map.begin(); + for (; cit != Rxn_surface_map.end(); cit++) + { + cxxSurface entity = cit->second; + entity.totalize(); + accumulator.add_extensive(entity.Get_totals(), 1.0); + } } - // gas phases { std::map::const_iterator cit = Rxn_gas_phase_map.begin(); @@ -257,14 +259,6 @@ size_t Phreeqc::list_components(std::list &list_c) accumulator.add_extensive(entity.Get_totals(), 1.0); } } -#ifdef SKIP - for (i = 0; i < count_kinetics; i++) - { - calc_dummy_kinetic_reaction_tally(&kinetics[i]); - cxxKinetics entity(&kinetics[i], phrq_io); - accumulator.add_extensive(entity.Get_totals(), 1.0); - } -#endif // Put in all primaries cxxNameDouble::iterator it; for (it = accumulator.begin(); it != accumulator.end(); it++) @@ -275,8 +269,6 @@ size_t Phreeqc::list_components(std::list &list_c) struct master *master_ptr = master_bsearch_primary(string); if (master_ptr == NULL) continue; if (master_ptr->type != AQ) continue; - //std::string name(master_ptr->elt->name); - //char accumulator.add(master_ptr->elt->name, 1); } // print list @@ -333,14 +325,6 @@ void Phreeqc::init(void) LOG_10 = log(10.0); - max_solution = MAX_SOLUTION; - //max_pp_assemblage = MAX_PP_ASSEMBLAGE; - //max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - //max_gas_phase = MAX_PP_ASSEMBLAGE; - //max_kinetics = MAX_PP_ASSEMBLAGE; - //max_ss_assemblage = MAX_PP_ASSEMBLAGE; - max_elements = MAX_ELEMENTS; max_elts = MAX_ELTS; max_line = MAX_LINE; @@ -353,252 +337,212 @@ void Phreeqc::init(void) max_logk = MAX_S; max_master_isotope = MAX_ELTS; - count_solution = 0; - //count_pp_assemblage = 0; - //count_exchange = 0; - count_surface = 0; - //count_gas_phase = 0; - //count_kinetics = 0; - //count_ss_assemblage = 0; - - count_elements = 0; - //count_irrev = 0; - count_master = 0; - //count_mix = 0; - count_phases = 0; - count_s = 0; - count_logk = 0; - count_master_isotope = 0; + count_elements = 0; + count_master = 0; + count_phases = 0; + count_s = 0; + count_logk = 0; + count_master_isotope = 0; /* * Initialize advection */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; - advection_punch = 0; - advection_kin_time = 0.0; + advection_punch = 0; + advection_kin_time = 0.0; advection_kin_time_defined = FALSE; - advection_print = 0; - advection_warnings = TRUE; + advection_print = 0; + advection_warnings = TRUE; /* * Initialize transport */ - count_cells = 1; - count_shifts = 1; + count_cells = 1; + count_shifts = 1; ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; + bcon_first = bcon_last = 3; + diffc = 0.3e-9; + simul_tr = 0; + tempr = 2.0; + heat_diffc = -0.1; + timest = 0.0; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + interlayer_tortf = 100.0; + interlayer_Dpor = 0.1; /* !!!! count_stag = 0; */ - mcd_substeps = 1.0; + mcd_substeps = 1.0; print_modulus = 1; punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; + dump_modulus = 0; + dump_in = FALSE; + transport_warnings = TRUE; - //pp_assemblage = 0; - //exchange = 0; - surface = 0; - //gas_phase = 0; - //kinetics = 0; - //ss_assemblage = 0; - cell_data = 0; - elements = 0; - elt_list = 0; + cell_data = 0; + elements = 0; + elt_list = 0; + inverse = 0; + count_inverse = 0; + line = 0; + line_save = 0; - inverse = 0; - count_inverse = 0; + master = 0; - //irrev = 0; - - line = 0; - line_save = 0; - - master = 0; - - mb_unknowns = 0; - - //mix = 0; - //count_mix = 0; + mb_unknowns = 0; /* !!!! */ - stag_data = 0; + stag_data = 0; + phases = 0; + trxn.token = 0; + s = 0; + logk = 0; + master_isotope = 0; - phases = 0; + title_x = NULL; + //pe_x = NULL; + description_x = NULL; + units_x = NULL; + s_x = NULL; - trxn.token = 0; + sum_mb1 = NULL; + sum_mb2 = NULL; + sum_jacob0 = NULL; + sum_jacob1 = NULL; + sum_jacob2 = NULL; + sum_delta = NULL; - s = 0; - - logk = 0; - - master_isotope = 0; - - solution = 0; - - - title_x = NULL; - pe_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; - - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; - - isotopes_x = 0; + //isotopes_x = 0; x = NULL; max_unknowns = 0; - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; + array = NULL; + delta = NULL; + residual = NULL; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; - logk_hash_table = 0; + logk_hash_table = 0; master_isotope_hash_table = 0; - elements_hash_table = 0; - species_hash_table = 0; - phases_hash_table = 0; -/* - * Initialize use pointers - */ - //use.Get_solution_in() = FALSE; - //use.Get_pp_assemblage_in() = FALSE; - //use.Get_mix_in() = FALSE; - //use.Get_reaction_in() = FALSE; + elements_hash_table = 0; + species_hash_table = 0; + phases_hash_table = 0; /* * Initialize punch */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; - punch.count_molalities = 0; + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; + punch.count_molalities = 0; - punch.molalities = 0; - punch.count_activities = 0; + punch.molalities = 0; + punch.count_activities = 0; - punch.activities = 0; + punch.activities = 0; punch.count_pure_phases = 0; - punch.pure_phases = 0; - punch.count_si = 0; + punch.pure_phases = 0; + punch.count_si = 0; - punch.si = 0; - punch.count_gases = 0; + punch.si = 0; + punch.count_gases = 0; - punch.gases = 0; - punch.count_s_s = 0; + punch.gases = 0; + punch.count_s_s = 0; punch.s_s = 0; - punch.count_kinetics = 0; - punch.kinetics = 0; + punch.count_kinetics = 0; + punch.kinetics = 0; - punch.count_isotopes = 0; - punch.isotopes = 0; + punch.count_isotopes = 0; + punch.isotopes = 0; punch.count_calculate_values = 0; - punch.calculate_values = 0; + punch.calculate_values = 0; - count_save_values = 0; - save_values = 0; + count_save_values = 0; + save_values = 0; - punch.inverse = TRUE; - - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; + punch.inverse = TRUE; + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; /* * last model */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; + last_model.exchange = NULL; + last_model.gas_phase = NULL; last_model.ss_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; + last_model.kinetics = NULL; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.surface_comp = NULL; last_model.surface_charge = NULL; /* * rates */ - rates = 0; - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - //rate_p = NULL; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; + rates = 0; + count_rates = 0; + initial_total_time = 0; + rate_m = 0; + rate_m0 = 0; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; /* * user_print, user_punch */ - user_print = 0; - user_punch = 0; - user_punch_headings = 0; + user_print = 0; + user_punch = 0; + user_punch_headings = 0; user_punch_count_headings = 0; /* Initialize llnl aqueous model parameters */ - llnl_temp = 0; - llnl_count_temp = 0; + llnl_temp = 0; + llnl_count_temp = 0; - llnl_adh = 0; - llnl_count_adh = 0; + llnl_adh = 0; + llnl_count_adh = 0; - llnl_bdh = 0; - llnl_count_bdh = 0; + llnl_bdh = 0; + llnl_count_bdh = 0; - llnl_bdot = 0; - llnl_count_bdot = 0; + llnl_bdot = 0; + llnl_count_bdot = 0; - llnl_co2_coefs = 0; - llnl_count_co2_coefs = 0; + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; - change_surf = 0; - change_surf_count = 0; + change_surf = 0; + change_surf_count = 0; /* Initialize print here, not in global.h */ pr.all = TRUE; @@ -650,31 +594,31 @@ void Phreeqc::init(void) dump_file_name = NULL; /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; - calculate_value = 0; + calculate_value = 0; calculate_value_hash_table = 0; /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - isotope_ratio = 0; + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + isotope_ratio = 0; isotope_ratio_hash_table = 0; /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - isotope_alpha = 0; + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + isotope_alpha = 0; isotope_alpha_hash_table = 0; - phreeqc_mpi_myself = 0; + phreeqc_mpi_myself = 0; copy_solution.n_user = copy_solution.start = copy_solution.end = 0; copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0; + copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0; copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; copy_mix.n_user = copy_mix.start = copy_mix.end = 0; @@ -683,7 +627,7 @@ void Phreeqc::init(void) copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0; set_forward_output_to_log(FALSE); - simulation = 0; + simulation = 0; /* * cvode */ @@ -692,48 +636,40 @@ void Phreeqc::init(void) /* * Pitzer */ - pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; - use_etheta = TRUE; - pitz_params = 0; + pitzer_model = FALSE; + max_pitz_param = 100; + count_pitz_param = 0; + use_etheta = TRUE; + pitz_params = 0; - max_theta_param = 100; - count_theta_param = 0; - theta_params = 0; + max_theta_param = 100; + count_theta_param = 0; + theta_params = 0; - ICON = TRUE; - OTEMP = 0.0; + ICON = TRUE; + OTEMP = 0.0; for (i = 0; i < 23; i++) { - BK[i] = 0.0; - DK[i] = 0.0; + BK[i] = 0.0; + DK[i] = 0.0; } - pitzer_pe = FALSE; + pitzer_pe = FALSE; count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants /* * SIT */ - sit_model = FALSE; - max_sit_param = 100; - count_sit_param = 0; - sit_params = 0; + sit_model = FALSE; + max_sit_param = 100; + count_sit_param = 0; + sit_params = 0; /* * to facilitate debuging */ - //dbg_use = &use; - dbg_solution = solution; - //dbg_exchange = exchange; - dbg_surface = surface; - //dbg_pp_assemblage = pp_assemblage; - //dbg_kinetics = kinetics; - //dbg_irrev = irrev; - //dbg_mix = mix; - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; + dbg_master = master; + calculating_deriv = FALSE; + numerical_deriv = FALSE; zeros = 0; zeros_max = 1; @@ -743,7 +679,6 @@ void Phreeqc::init(void) cell_porosity = 0; cell_saturation = 0; - charge_group = NULL; print_density = 0; /* basic.c */ @@ -765,10 +700,10 @@ void Phreeqc::init(void) reading_db = FALSE; /* integrate.c */ - z = 0; - xd = 0; - alpha = 0; - surface_charge_ptr = NULL; + z_global = 0; + xd_global = 0; + alpha_global = 0; + /* inverse.c */ max_row_count = 50; max_column_count = 50; diff --git a/Phreeqc.h b/Phreeqc.h index 19df3991..9079c9d3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -14,6 +14,9 @@ #include #include #include +#ifdef HASH +#include +#endif #include #include #include @@ -32,6 +35,7 @@ #include "Pressure.h" #include "cxxMix.h" #include "Use.h" +#include "Surface.h" class cxxNameDouble; class cxxKinetics; @@ -45,12 +49,10 @@ class cxxPPassemblage; class cxxPPassemblageComp; class cxxReaction; class cxxSolution; -class cxxSolutionIsotopeList; +class cxxISolutionComp; +class cxxSolutionIsotope; class cxxSSassemblage; class cxxSS; -class cxxSurface; -class cxxSurfaceCharge; -class cxxSurfaceComp; class cxxStorageBin; #include "global_structures.h" @@ -129,12 +131,11 @@ public: int system_total_elt_secondary(const char *total_name); LDBLE total(const char *total_name); LDBLE total_mole(const char *total_name); - //int system_total_solids(struct exchange *exchange_ptr, int system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, cxxSSassemblage *ss_assemblage_ptr, - struct surface *surface_ptr); + cxxSurface *surface_ptr); static LDBLE f_rho(LDBLE rho_old, void *cookie); static LDBLE f_Vm(LDBLE v1, void *cookie); @@ -173,9 +174,7 @@ public: LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); // class_main.cpp ------------------------------- -#ifdef DOS int write_banner(void); -#endif /* default.cpp */ public: @@ -186,9 +185,6 @@ public: std::istream **input_cookie, int log); /* PHRQ_io_output.cpp */ - //bool screen_open(const char *file_name); - //void screen_flush(void); - //void screen_close(void); void screen_msg(const char * str); void echo_msg(const char *err_str); @@ -200,40 +196,30 @@ public: bool dump_open(const char *file_name); void dump_flush(void); void dump_close(void); - //void dump_rewind(void); - //bool dump_isopen(void); void dump_msg(const char * str); // log_ostream bool log_open(const char *file_name); void log_flush(void); void log_close(void); - //void log_rewind(void); - //bool log_isopen(void); void log_msg(const char * str); // error_ostream bool error_open(const char *file_name); void error_flush(void); void error_close(void); - //void error_rewind(void); - //bool error_isopen(void); void error_msg(const char * str, bool stop=false); // output_ostream bool output_open(const char *file_name); void output_flush(void); void output_close(void); - //void output_rewind(void); - //bool output_isopen(void); void output_msg(const char * str); // punch_ostream bool punch_open(const char *file_name); void punch_flush(void); void punch_close(void); - //void punch_rewind(void); - //bool punch_isopen(void); void punch_msg(const char * str); void fpunchf_heading(const char *name); @@ -262,15 +248,15 @@ public: int calc_all_g(void); int calc_init_g(void); int initial_surface_water(void); - int sum_diffuse_layer(struct surface_charge *surface_charge_ptr1); + int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); int calc_all_donnan(void); int calc_init_donnan(void); LDBLE g_function(LDBLE x_value); LDBLE midpnt(LDBLE x1, LDBLE x2, int n); void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy); - LDBLE qromb_midpnt(LDBLE x1, LDBLE x2); - LDBLE calc_psi_avg(LDBLE surf_chrg_eq); + LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); + LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); int calc_all_donnan_music(void); int calc_init_donnan_music(void); @@ -282,9 +268,9 @@ public: int check_isotopes(struct inverse *inv_ptr); int check_solns(struct inverse *inv_ptr); int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); - struct isotope *get_isotope(struct solution *solution_ptr, const char *elt); - struct conc *get_inv_total(struct solution *solution_ptr, const char *elt); + struct isotope **isotope_unknowns); + cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); + LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); int post_mortem(void); bool test_cl1_solution(void); @@ -299,14 +285,15 @@ public: int print_model(struct inverse *inv_ptr); int punch_model_heading(struct inverse *inv_ptr); int punch_model(struct inverse *inv_ptr); - void print_isotope(FILE * netpath_file, struct solution *solution_ptr, + void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, const char *elt, const char *string); - void print_total(FILE * netpath_file, struct solution *solution_ptr, + void print_total(FILE * netpath_file, cxxSolution *solution_ptr, const char *elt, const char *string); - void print_total_multi(FILE * netpath_file, struct solution *solution_ptr, + void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, const char *string, const char *elt0, const char *elt1, const char *elt2, const char *elt3, const char *elt4); + void print_total_pat(FILE * netpath_file, const char *elt, const char *string); int range(struct inverse *inv_ptr, unsigned long cur_bits); @@ -317,9 +304,7 @@ public: int setup_inverse(struct inverse *inv_ptr); int set_initial_solution(int n_user_old, int n_user_new); int set_ph_c(struct inverse *inv_ptr, - int i, - struct solution *soln_ptr_orig, - int n_user_new, + int i, cxxSolution *soln_ptr_orig, int n_user_new, LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); int shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, int *k, int *l, int *m, int *n, @@ -333,10 +318,10 @@ public: int write_optimize_names(struct inverse *inv_ptr); // isotopes.cpp ------------------------------- - int add_isotopes(struct solution *solution_ptr); + int add_isotopes(cxxSolution &solution_ptr); int calculate_values(void); int calculate_isotope_moles(struct element *elt_ptr, - struct solution *solution_ptr, LDBLE total_moles); + cxxSolution *solution_ptr, LDBLE total_moles); LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); int from_pcil(struct master_isotope *master_isotope_ptr); int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); @@ -423,7 +408,6 @@ public: int do_initialize(void); int do_status(void); void save_init(int i); - //void use_init(void); int copy_use(int i); int set_use(void); @@ -463,7 +447,6 @@ public: int revise_guesses(void); int ss_binary(cxxSS *ss_ptr); int ss_ideal(cxxSS *ss_ptr); - //int remove_unstable_phases; int gas_in; void ineq_init(int max_row_count, int max_column_count); @@ -550,16 +533,16 @@ public: int build_min_surface(void); LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); LDBLE calc_delta_v(reaction * r_ptr, bool phase); - //LDBLE calc_PR(struct phase **phase_ptrs, int n_g, LDBLE P, LDBLE TK, LDBLE V_m); LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); LDBLE calc_PR(); int calc_vm(LDBLE tc, LDBLE pa); int change_hydrogen_in_elt_list(LDBLE charge); int clear(void); - int convert_units(struct solution *solution_ptr); + //int convert_units(struct solution *solution_ptr); + int convert_units(cxxSolution *solution_ptr); LDBLE a_aa_sum, b2, b_sum, R_TK; LDBLE f_Vm(LDBLE v1); - struct unknown *find_surface_charge_unknown(char *str_ptr, int plane); + struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); struct master **get_list_master_ptrs(char *ptr, struct master *master_ptr); int inout(void); @@ -575,7 +558,7 @@ public: int setup_fixed_volume_gas(void); int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, - struct reaction **pe_rxn); + const std::string &pe_rxn); int setup_pure_phases(void); int adjust_setup_pure_phases(void); int setup_related_surface(void); @@ -622,7 +605,7 @@ public: int print_user_print(void); int punch_all(void); int print_alkalinity(void); - int print_diffuse_layer(struct surface_charge *surface_charge_ptr); + int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); int print_eh(void); int print_reaction(void); int print_kinetics(void); @@ -650,7 +633,7 @@ public: // read.cpp ------------------------------- int read_input(void); - int read_conc(int n, int count_mass_balance, char *str); + int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); int *read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list); int read_log_k_only(char *ptr, LDBLE * log_k); @@ -660,8 +643,8 @@ public: int read_number_description(char *ptr, int *n_user, int *n_user_end, char **description, int allow_negative=FALSE); int check_key(const char *str); - int check_units(char * tot_units, int alkalinity, int check_compatibility, - const char *default_units, int print); + int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, + const char *default_units, bool print); int find_option(const char *item, int *n, const char **list, int count_list, int exact); int get_option(const char **opt_list, int count_opt_list, char **next_char); @@ -677,7 +660,7 @@ public: int read_debug(void); int read_delta_h_only(char *ptr, LDBLE * delta_h, DELTA_H_UNIT * units); - int read_delta_v_only(char *ptr, LDBLE * delta_v, + int read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units); int read_llnl_aqueous_model_parameters(void); int read_exchange(void); @@ -703,13 +686,10 @@ public: int read_named_logk(void); int read_phases(void); int read_print(void); - //int read_pure_phases(void); int read_pp_assemblage(void); int read_rates(void); int read_reaction(void); - //int read_reaction_reactants(struct irrev *irrev_ptr); int read_reaction_reactants(cxxReaction *reaction_ptr); - //int read_reaction_steps(struct irrev *irrev_ptr); int read_reaction_steps(cxxReaction *reaction_ptr); int read_solid_solutions(void); int read_temperature(void); @@ -720,7 +700,7 @@ public: int read_selected_output(void); int read_solution(void); int read_species(void); - int read_surf(void); + int read_surface(void); int read_surface_master_species(void); int read_surface_species(void); int read_use(void); @@ -737,27 +717,7 @@ public: int cleanup_after_parser(CParser &parser); // ReadClass.cxx - int read_generic(Keywords::KEYWORDS key); - int read_solution_raw(void); - //int read_exchange_raw(void); - int read_surface_raw(void); - //int read_equilibrium_phases_raw(void); - int read_kinetics_raw(void); - int read_solid_solutions_raw(void); - //int read_gas_phase_raw(void); - //int read_reaction_raw(void); - //int read_mix_raw(void); - //int read_temperature_raw(void); int read_dump(void); - int read_solution_modify(void); - //int read_equilibrium_phases_modify(void); - //int read_exchange_modify(void); - int read_surface_modify(void); - int read_solid_solutions_modify(void); - //int read_gas_phase_modify(void); - int read_kinetics_modify(void); - //int read_reaction_modify(void); - //int read_reaction_temperature_modify(void); int read_delete(void); int read_run_cells(void); int streamify_to_next_keyword(std::istringstream & lines); @@ -822,28 +782,19 @@ public: // step.cpp ------------------------------- int step(LDBLE step_fraction); int xsolution_zero(void); - //int add_exchange(struct exchange *exchange_ptr); int add_exchange(cxxExchange *exchange_ptr); int add_gas_phase(cxxGasPhase *gas_phase_ptr); int add_kinetics(cxxKinetics *kinetics_ptr); - //int add_mix(struct mix *mix_ptr); int add_mix(cxxMix * mix_ptr); - //int add_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - //int add_reaction(struct irrev *irrev_ptr, int step_number, - // LDBLE step_fraction); int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - //int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); - int add_solution(struct solution *solution_ptr, LDBLE extensive, + int add_solution(cxxSolution *solution_ptr, LDBLE extensive, LDBLE intensive); - int add_surface(struct surface *surface_ptr); - //int check_pp_assemblage(struct pp_assemblage *pp_assemblage_ptr); + int add_surface(cxxSurface *surface_ptr); int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); int gas_phase_check(cxxGasPhase *gas_phase_ptr); - //int pp_assemblage_check(struct pp_assemblage *pp_assemblage_ptr); int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); - //int reaction_calc(struct irrev *irrev_ptr); int reaction_calc(cxxReaction *reaction_ptr); int solution_check(void); int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); @@ -871,32 +822,6 @@ public: static int inverse_isotope_compare(const void *ptr1, const void *ptr2); struct inverse *inverse_search(int n_user, int *n); int inverse_sort(void); -public: -#ifdef SKIP - struct kinetics *kinetics_alloc(void); - struct kinetics *kinetics_bsearch(int k, int *n); -protected: - int kinetics_delete(int n_user_old); - int kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, - struct kinetics_comp *kinetics_comp_old_ptr); - static int kinetics_compare(const void *ptr1, const void *ptr2); -public: - int kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new); -protected: - int kinetics_copy_to_last(int n, int n_user); - int kinetics_duplicate(int n_user_old, int n_user_new); - int kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, - char *description); -public: - int kinetics_free(struct kinetics *kinetics_ptr); -protected: - int kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new); - struct kinetics *kinetics_replicate(struct kinetics *kinetics_old_ptr, - int n_user_new); - struct kinetics *kinetics_search(int n_user, int *n, int print); - int kinetics_sort(void); -#endif protected: struct logk *logk_alloc(void); int logk_copy2orig(struct logk *logk_ptr); @@ -910,15 +835,6 @@ public: struct master *master_bsearch_primary(const char *ptr); struct master *master_bsearch_secondary(char *ptr); struct master *master_search(char *ptr, int *n); - //struct mix *mix_bsearch(int k, int *n); - //int mix_copy(struct mix *mix_old_ptr, - //struct mix *mix_new_ptr, int n_user_new); - //int mix_delete(int n_user_old); - //int mix_duplicate(int n_user_old, int n_user_new); - //int mix_free(struct mix *mix_ptr); - //struct mix *mix_search(int n_user, int *n, int print); - //int mix_ptr_to_user(struct mix *mix_ptr_old, int n_user_new); - //int mix_sort(void); struct pe_data *pe_data_alloc(void); public: struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); @@ -950,56 +866,16 @@ protected: static int save_values_compare(const void *ptr1, const void *ptr2); int save_values_sort(void); int save_values_store(struct save_values *s_v); - static int conc_compare(const void *ptr1, const void *ptr2); - int conc_init(struct conc *conc_ptr); static int isotope_compare(const void *ptr1, const void *ptr2); -public: - struct solution *solution_alloc(void); - struct solution *solution_bsearch(int k, int *n, int print); - struct solution *solution_copy(struct solution *solution_old_ptr, - int n_user_new); -protected: - int solution_copy_to_last(int n, int n_user_new); - int solution_duplicate(int n_user_old, int n_user_new); - int solution_delete(int n_user_old); - int solution_delete_n(int n); - int solution_free(struct solution *solution_ptr); - int solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new); - struct solution *solution_replicate(struct solution *solution_old_ptr, - int n_user_new); - int solution_sort(void); static int species_list_compare_alk(const void *ptr1, const void *ptr2); static int species_list_compare_master(const void *ptr1, const void *ptr2); int species_list_sort(void); struct Change_Surf *change_surf_alloc(int count); public: - struct surface *surface_alloc(void); - struct surface *surface_bsearch(int k, int *n); -protected: struct master *surface_get_psi_master(const char *name, int plane); - static int surface_comp_compare(const void *ptr1, const void *ptr2); - static int surface_charge_compare(const void *ptr1, const void *ptr2); - struct surface_charge * surface_charge_duplicate(struct surface_charge *charge_old_ptr); - int surface_charge_free(struct surface_charge *charge); - static int surface_compare(const void *ptr1, const void *ptr2); -public: - int surface_copy(struct surface *surface_old_ptr, - struct surface *surface_new_ptr, int n_user_new); -protected: - int surface_copy_to_last(int n, int n_user); - int surface_delete(int n_user_old); - int surface_duplicate(int n_user_old, int n_user_new); -public: - int surface_free(struct surface *surface_ptr); - int surface_init(struct surface *surface_ptr, int n_user, int n_user_end, - char *description); - int surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new); - struct surface *surface_replicate(struct surface *surface_old_ptr, - int n_user_new); - struct surface *surface_search(int n_user, int *n, int print); - int surface_sort(void); int system_duplicate(int i, int save_old); int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); int trxn_combine(void); int trxn_copy(struct reaction *rxn_ptr); @@ -1012,24 +888,16 @@ public: int unknown_delete(int i); int unknown_free(struct unknown *unknown_ptr); int entity_exists(char *name, int n_user); - - //static int exchange_compare_int(const void *ptr1, const void *ptr2); - //static int gas_phase_compare_int(const void *ptr1, const void *ptr2); static int inverse_compare(const void *ptr1, const void *ptr2); int inverse_free(struct inverse *inverse_ptr); - //static int irrev_compare(const void *ptr1, const void *ptr2); - //static int irrev_compare_int(const void *ptr1, const void *ptr2); static int kinetics_compare_int(const void *ptr1, const void *ptr2); int logk_init(struct logk *logk_ptr); static int master_compare_string(const void *ptr1, const void *ptr2); int master_free(struct master *master_ptr); - //static int mix_compare(const void *ptr1, const void *ptr2); - //static int mix_compare_int(const void *ptr1, const void *ptr2); struct phase *phase_alloc(void); static int phase_compare_string(const void *ptr1, const void *ptr2); int phase_free(struct phase *phase_ptr); int phase_init(struct phase *phase_ptr); - //static int pp_assemblage_compare_int(const void *ptr1, const void *ptr2); static int rate_compare(const void *ptr1, const void *ptr2); static int rate_compare_string(const void *ptr1, const void *ptr2); struct species *s_alloc(void); @@ -1040,8 +908,6 @@ public: static int solution_compare_int(const void *ptr1, const void *ptr2); static int species_list_compare(const void *ptr1, const void *ptr2); static int surface_compare_int(const void *ptr1, const void *ptr2); - //static int temperature_compare(const void *ptr1, const void *ptr2); - //static int temperature_compare_int(const void *ptr1, const void *ptr2); static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); #ifdef PHREEQCI_GUI @@ -1050,29 +916,6 @@ public: #if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) extern void MergeFinalize(void); #endif - - // convert class to struct (structures.cpp) - //struct mix * cxxMix2mix(const cxxMix *mx); - //struct kinetics *cxxKinetics2kinetics(const cxxKinetics * kin); - //struct kinetics_comp * cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > * el); - //struct exchange * cxxExchange2exchange(const cxxExchange * ex); - //struct exch_comp * cxxExchComp2exch_comp(const std::map < std::string, cxxExchComp > * el); - //struct master * Get_exch_master(const cxxExchComp * ec); - //struct gas_phase * cxxGasPhase2gas_phase(const cxxGasPhase * gp); - //struct gas_comp * cxxGasPhaseComp2gas_comp(const cxxGasPhase * gp); - //struct temperature * cxxTemperature2temperature(const cxxTemperature *temp); - //struct pp_assemblage * cxxPPassemblage2pp_assemblage(const cxxPPassemblage * pp); - //struct pure_phase * cxxPPassemblageComp2pure_phase(const std::map < std::string, cxxPPassemblageComp > * ppc); - //struct irrev * cxxReaction2irrev(const cxxReaction * rxn); - struct solution * cxxSolution2solution(const cxxSolution * sol); - struct isotope * cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il); - //struct ss_assemblage * cxxSSassemblage2ss_assemblage(const cxxSSassemblage * ss); - //struct s_s * cxxSSassemblageSS2s_s(const std::map < std::string, cxxSS > * sscomp); - struct surface * cxxSurface2surface(const cxxSurface * surf); - struct surface_comp * cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc); - struct surface_charge * cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch); - - struct conc * cxxNameDouble2conc(const cxxNameDouble *nd); struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); @@ -1111,7 +954,6 @@ public: int add_logks(struct logk *logk_ptr, int repeats); LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); int replace_solids_gases(void); - //int s_s_prep(LDBLE t, struct s_s *s_s_ptr, int print); int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); @@ -1152,9 +994,9 @@ public: // transport.cpp ------------------------------- int transport(void); int set_initial_moles(int i); - int sum_surface_comp(struct surface *source1, LDBLE f1, - struct surface *source2, int k, LDBLE f2, - struct surface *target, LDBLE new_Dw); + cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, + cxxSurface *source2, std::string charge_name, LDBLE f2, + LDBLE new_Dw); int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, LDBLE new_Dw, int cell); LDBLE viscosity(void); @@ -1165,11 +1007,10 @@ public: static int sort_species_name(const void *ptr1, const void *ptr2); int disp_surf(LDBLE stagkin_time); int diff_stag_surf(int mobile_cell); - int check_surfaces(struct surface *surface_ptr1, - struct surface *surface_ptr2); - int mobile_surface_copy(struct surface *surface_old_ptr, - struct surface *surf_ptr1, int n_user_new, - int move_old); + int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); + cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, + int n_user_new, + bool move_old); int init_mix(void); int init_heat_mix(int nmix); int heat_mix(int heat_nmix); @@ -1185,6 +1026,7 @@ protected: LDBLE calc_alk(struct reaction *rxn_ptr); public: LDBLE calc_rho_0(LDBLE tc, LDBLE pa); + LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); int compute_gfw(const char *string, LDBLE * gfw); #if defined PHREEQ98 int copy_title(char *token_ptr, char **ptr, int *length); @@ -1213,7 +1055,7 @@ public: protected: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); - int status(int count, const char *str); + int status(int count, const char *str, bool kinetics = false); void str_tolower(char *str); void str_toupper(char *str); static int strcmp_nocase(const char *str1, const char *str2); @@ -1222,6 +1064,9 @@ public: char *string_duplicate(const char *token); const char *string_hsave(const char *str); void strings_map_clear(); +#ifdef HASH + void strings_hash_clear(); +#endif protected: char *string_pad(const char *str, int i); int string_trim(char *str); @@ -1262,6 +1107,7 @@ protected: int same_model; int same_temperature; int same_pressure; + bool same_mu; struct punch punch; /* ---------------------------------------------------------------------- * Temperatures @@ -1280,11 +1126,8 @@ protected: int g_iterations; LDBLE G_TOL; - struct surface *surface; - struct surface *dbg_surface; - int count_surface; - int max_surface; - struct Charge_Group *charge_group; + std::map Rxn_surface_map; + std::map charge_group_map; int change_surf_count; struct Change_Surf *change_surf; @@ -1297,31 +1140,22 @@ protected: * Kinetics * ---------------------------------------------------------------------- */ std::map Rxn_kinetics_map; -#ifdef SKIP - struct kinetics *kinetics; - struct kinetics *dbg_kinetics; - int count_kinetics; - int max_kinetics; -#endif - - int count_save_values; - struct save_values *save_values; /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ - + int count_save_values; + struct save_values *save_values; struct save save; + /*---------------------------------------------------------------------- * Use *---------------------------------------------------------------------- */ cxxUse use; - //struct Use use; - //struct Use *dbg_use; + /*---------------------------------------------------------------------- * Copy *---------------------------------------------------------------------- */ - struct copier copy_solution; struct copier copy_pp_assemblage; struct copier copy_exchange; @@ -1361,24 +1195,19 @@ protected: * Solid solution *---------------------------------------------------------------------- */ std::map Rxn_ss_assemblage_map; - //int count_ss_assemblage; - //int max_ss_assemblage; - //struct ss_assemblage *ss_assemblage; + /*---------------------------------------------------------------------- * Pure-phase assemblage *---------------------------------------------------------------------- */ std::map Rxn_pp_assemblage_map; - //int count_pp_assemblage; - //int max_pp_assemblage; - //struct pp_assemblage *pp_assemblage; - //struct pp_assemblage *dbg_pp_assemblage; + /*---------------------------------------------------------------------- * Species_list *---------------------------------------------------------------------- */ - int count_species_list; int max_species_list; struct species_list *species_list; + /*---------------------------------------------------------------------- * Jacobian and Mass balance lists *---------------------------------------------------------------------- */ @@ -1410,12 +1239,8 @@ protected: /*---------------------------------------------------------------------- * Solution *---------------------------------------------------------------------- */ - - struct solution **solution; - struct solution **dbg_solution; - int count_solution; - int max_solution; - + std::map Rxn_solution_map; + std::vector unnumbered_solutions; struct iso *iso_defaults; int count_iso_defaults; @@ -1444,18 +1269,17 @@ protected: LDBLE mass_water_surfaces_x; LDBLE mass_water_bulk_x; char *units_x; - struct pe_data *pe_x; - int count_isotopes_x; - struct isotope *isotopes_x; - int default_pe_x; - /* int diffuse_layer_x;*/ - enum DIFFUSE_LAYER_TYPE dl_type_x; + std::map < std::string, cxxChemRxn > pe_x; + std::map isotopes_x; + std::string default_pe_x; + cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; LDBLE total_carbon; LDBLE total_co2; LDBLE total_alkalinity; LDBLE gfw_water; LDBLE step_x; LDBLE kin_time_x; + /*---------------------------------------------------------------------- * Transport data *---------------------------------------------------------------------- */ @@ -1547,6 +1371,7 @@ protected: struct species **s; int count_s; int max_s; + std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; struct species **s_x; int count_s_x; @@ -1559,21 +1384,22 @@ protected: struct species *s_co3; struct species *s_h2; struct species *s_o2; + /*---------------------------------------------------------------------- * Phases *---------------------------------------------------------------------- */ - struct phase **phases; int count_phases; int max_phases; + /*---------------------------------------------------------------------- * Master species *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ struct master **dbg_master; int count_master; int max_master; + /*---------------------------------------------------------------------- * Unknowns *---------------------------------------------------------------------- */ @@ -1600,10 +1426,10 @@ protected: struct unknown *slack_unknown; struct unknown *ss_unknown; std::vector gas_unknowns; + /*---------------------------------------------------------------------- * Reaction work space *---------------------------------------------------------------------- */ - struct reaction_temp trxn; /* structure array of working space while reading equations species names are in "temp_strings" */ int count_trxn; /* number of reactants in trxn = position of next */ @@ -1612,25 +1438,26 @@ protected: struct unknown_list *mb_unknowns; int count_mb_unknowns; int max_mb_unknowns; + /* ---------------------------------------------------------------------- * Print * ---------------------------------------------------------------------- */ - struct prints pr; - int status_on, status_interval; - float status_timer; + bool status_on; + clock_t status_interval; + clock_t status_timer; int count_warnings; /* ---------------------------------------------------------------------- * RATES * ---------------------------------------------------------------------- */ - struct rate *rates; int count_rates; - LDBLE rate_m, rate_m0, /* *rate_p, */ rate_time, rate_sim_time_start, + LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; std::vector rate_p; int count_rate_p; + /* ---------------------------------------------------------------------- * USER PRINT COMMANDS * ---------------------------------------------------------------------- */ @@ -1721,7 +1548,7 @@ protected: char *selected_output_file_name; char *dump_file_name; int remove_unstable_phases; - + std::string screen_string; #ifdef PHREEQCI_GUI struct spread_sheet g_spread_sheet; #endif @@ -1732,6 +1559,9 @@ protected: */ std::map strings_map; +#ifdef HASH + std::hash_map strings_hash; +#endif HashTable *elements_hash_table; HashTable *species_hash_table; HashTable *phases_hash_table; @@ -1781,7 +1611,14 @@ protected: struct system_species *sys; int count_sys, max_sys; LDBLE sys_tot; +#ifdef PHREEQC2 LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE eps_r; // relative dielectric permittivity +#else + LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; + LDBLE eps_r; // relative dielectric permittivity + LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av +#endif LDBLE solution_mass, solution_volume; LDBLE f_rho(LDBLE rho_old); @@ -1818,8 +1655,7 @@ protected: /* integrate.cpp ------------------------------- */ LDBLE midpoint_sv; - LDBLE z, xd, alpha; - struct surface_charge *surface_charge_ptr; + LDBLE z_global, xd_global, alpha_global; int max_row_count, max_column_count; int carbon; const char **col_name, **row_name; @@ -1863,7 +1699,6 @@ public: M_Env kinetics_machEnv; N_Vector kinetics_y, kinetics_abstol; void *kinetics_cvode_mem; - //struct pp_assemblage *cvode_pp_assemblage_save; cxxSSassemblage *cvode_ss_assemblage_save; cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; @@ -1872,7 +1707,6 @@ public: /* model.cpp ------------------------------- */ LDBLE min_value; - /* LDBLE model_min_value; */ LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; int *inv_iu, *inv_is, *back_eq; int normal_max, ineq_array_max, res_max, cu_max, zero_max, diff --git a/Pressure.cxx b/Pressure.cxx index 206a191e..de48aeb4 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -52,9 +52,6 @@ cxxPressure::read(CParser & parser) bool done = false; for (;;) { - // new line - //LINE_TYPE check_line(const std::string & str, bool allow_empty, - // bool allow_eof, bool allow_keyword, bool print); std::istream::pos_type ptr; std::istream::pos_type next_char = 0; std::string token, str; @@ -152,7 +149,6 @@ cxxPressure::read(CParser & parser) void cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -168,15 +164,15 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << "REACTION_PRESSURE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-count " << this->count << "\n"; + s_oss << "-count " << this->count << "\n"; s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << "\n"; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; // Temperature element and attributes s_oss << indent1; - s_oss << "-pressures " << "\n"; + s_oss << "-pressures" << "\n"; { int i = 0; s_oss << indent2; @@ -323,7 +319,6 @@ cxxPressure::read_raw(CParser & parser) void cxxPressure::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); diff --git a/Reaction.cxx b/Reaction.cxx index 1da3832b..71818b6e 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -37,7 +37,6 @@ cxxReaction::~cxxReaction() void cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -72,7 +71,6 @@ cxxReaction::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing irrev message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -86,21 +84,14 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Reaction element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "REACTION_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "REACTION_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-units " << this->units << "\n"; - - s_oss << indent1; - s_oss << "-reactant_list " << "\n"; + s_oss << "-reactant_list" << "\n"; this->reactantList.dump_raw(s_oss, indent + 2); s_oss << indent1; - s_oss << "-element_list " << "\n"; - this->elementList.dump_raw(s_oss, indent + 2); - - s_oss << indent1; - s_oss << "-steps " << "\n"; + s_oss << "-steps" << "\n"; { int i = 0; s_oss << indent2; @@ -119,12 +110,18 @@ cxxReaction::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con } s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << "\n"; + s_oss << "-count_steps " << this->countSteps << "\n"; s_oss << indent1; - s_oss << "-count_steps " << this->countSteps << "\n"; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; + s_oss << indent1; + s_oss << "-units " << this->units << "\n"; + s_oss << indent1 << "# REACTION workspace variables #\n"; + s_oss << indent1; + s_oss << "-element_list" << "\n"; + this->elementList.dump_raw(s_oss, indent + 2); } void diff --git a/ReadClass.cxx b/ReadClass.cxx index 74c2a39c..f88ee32b 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -22,284 +22,9 @@ #include "dumper.h" #include "runner.h" #include "cxxMix.h" +#include "Surface.h" #include "phqalloc.h" - - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solution_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads SOLUTION_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("solution_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - - cxxSolution sol(phrq_io); - sol.read_raw(parser); - //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); - struct solution *soln_ptr = cxxSolution2solution(&sol); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (solution_bsearch(soln_ptr->n_user, &n, FALSE) != NULL) - { - solution_free(solution[n]); - solution[n] = soln_ptr; - } - else - { - n = count_solution++; - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - solution[n] = soln_ptr; - solution_sort(); - } - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_surface_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads SURFACE_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("surface_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxSurface ex(phrq_io); - ex.read_raw(parser); - //struct surface *surface_ptr = ex.cxxSurface2surface(PHREEQC_THIS); - struct surface *surface_ptr = cxxSurface2surface(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (surface_bsearch(surface_ptr->n_user, &n) != NULL) - { - surface_free(&surface[n]); - surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); - } - else - { - n = count_surface++; - if (count_surface >= max_surface) - { - space((void **) ((void *) &(surface)), count_surface, - &max_surface, sizeof(struct surface)); - } - surface_copy(surface_ptr, &surface[n], surface_ptr->n_user); - surface_sort(); - } - surface_free(surface_ptr); - free_check_null(surface_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_kinetics_raw(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads KINETICS_RAW data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - /* - * Accumulate lines in std string - */ - std::string keywordLines(""); - - keywordLines.append(line); - keywordLines.append("\n"); -/* - * Read additonal lines - */ - int save_echo_input = pr.echo_input; - pr.echo_input = FALSE; - for (;;) - { - return_value = check_line("kinetics_raw", TRUE, TRUE, TRUE, FALSE); - /* empty, eof, keyword, print */ - if (return_value == EOF || return_value == KEYWORD) - break; - keywordLines.append(line); - keywordLines.append("\n"); - } - pr.echo_input = save_echo_input; - - std::istringstream iss_in(keywordLines); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - //For testing, need to read line to get started - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - cxxKinetics ex(phrq_io); - ex.read_raw(parser); - //struct kinetics *kinetics_ptr = ex.cxxKinetics2kinetics(PHREEQC_THIS); - struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&ex); - int n; - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - if (kinetics_bsearch(kinetics_ptr->n_user, &n) != NULL) - { - kinetics_free(&kinetics[n]); - kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); - } - else - { - n = count_kinetics++; - if (count_kinetics >= max_kinetics) - { - space((void **) ((void *) &(kinetics)), count_kinetics, - &max_kinetics, sizeof(struct kinetics)); - } - kinetics_copy(kinetics_ptr, &kinetics[n], kinetics_ptr->n_user); - kinetics_sort(); - } - kinetics_free(kinetics_ptr); - free_check_null(kinetics_ptr); - - // Need to output the next keyword - if (return_value == KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_dump(void) @@ -450,280 +175,6 @@ read_run_cells(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: -read_solution_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution_modify data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find solution 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++; - error_string = sformatf( "Expected solution number following SOLUTION_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - - if (solution_bsearch(n_user, &n, FALSE) == NULL) - { - input_error++; - error_string = sformatf( "Solution %d not found for SOLUTION_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - cxxSolution sol(solution[n], phrq_io); - - // Clear activities so we can know what was read - sol.clear_master_activity(); - - sol.read_raw(parser, false); - - cxxSolution orig(solution[n], phrq_io ); - - sol.modify_activities(orig); - - //struct solution *soln_ptr = sol.cxxSolution2solution(PHREEQC_THIS); - struct solution *soln_ptr = cxxSolution2solution(&sol); - - /* - * This is not quite right, may not produce sort order, forced sort - */ - - solution_free(solution[n]); - solution[n] = soln_ptr; - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_surface_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads SURFACE_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find surface 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++; - error_string = sformatf( "Expected surface number following SURFACE_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (surface_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Surface %d not found for SURFACE_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxSurface entity(&(surface[n]), phrq_io); - entity.read_raw(parser, false); - - // save entity - //struct surface *entity_ptr = entity.cxxSurface2surface(PHREEQC_THIS); - struct surface *entity_ptr = cxxSurface2surface(&entity); - surface_free(&(surface[n])); - surface_copy(entity_ptr, &(surface[n]), entity_ptr->n_user); - free_check_null(surface[n].description); - surface[n].description = string_duplicate(entity_ptr->description); - surface_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_kinetics_modify(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads KINETICS_MODIFY data block - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int return_value; - - // find kinetics 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++; - error_string = sformatf( "Expected kinetics number following KINETICS_MODIFY.\n%s\n", line_save); - error_msg(error_string, CONTINUE); - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - return (ERROR); - } - else - { - sscanf(token,"%d", &n_user); - } - /* - * Make parser - */ - std::istringstream iss_in; - return_value = streamify_to_next_keyword(iss_in); - CParser parser(iss_in, phrq_io); - assert(!reading_database()); - - //For testing, need to read line to get started - parser.set_echo_file(CParser::EO_NONE); - std::vector < std::string > vopts; - std::istream::pos_type next_char; - parser.get_option(vopts, next_char); - - if (pr.echo_input == FALSE) - { - parser.set_echo_file(CParser::EO_NONE); - } - else - { - parser.set_echo_file(CParser::EO_NOKEYWORDS); - } - - if (kinetics_bsearch(n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Kinetics %d not found for KINETICS_MODIFY.\n", n_user); - error_msg(error_string, CONTINUE); - return (ERROR); - } - - // read entity - cxxKinetics entity(&(kinetics[n]), phrq_io); - entity.read_raw(parser, false); - - // save entity - //struct kinetics *entity_ptr = entity.cxxKinetics2kinetics(PHREEQC_THIS); - struct kinetics *entity_ptr = cxxKinetics2kinetics(&entity); - kinetics_free(&(kinetics[n])); - kinetics_copy(entity_ptr, &(kinetics[n]), entity_ptr->n_user); - free_check_null(kinetics[n].description); - kinetics[n].description = string_duplicate(entity_ptr->description); - kinetics_free(entity_ptr); - free_check_null(entity_ptr); - - // Need to output the next keyword - if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); - return (return_value); -} -#endif -/* ---------------------------------------------------------------------- */ -int Phreeqc:: streamify_to_next_keyword(std::istringstream & lines) /* ---------------------------------------------------------------------- */ { @@ -761,7 +212,6 @@ streamify_to_next_keyword(std::istringstream & lines) } lines.str(accumulate); - //std::cerr << accumulate; pr.echo_input = save_echo_input; if (j == EOF) return (OPTION_EOF); if (j == KEYWORD) return (OPTION_KEYWORD); @@ -809,7 +259,7 @@ int Phreeqc:: delete_entities(void) /* ---------------------------------------------------------------------- */ { - int i, n, return_value; + int return_value; return_value = OK; if (!delete_info.Get_solution().Get_defined() && !delete_info.Get_pp_assemblage().Get_defined() && @@ -831,20 +281,14 @@ delete_entities(void) { if (delete_info.Get_solution().Get_numbers().size() == 0) { - for (i = 0; i < count_solution; i++) - { - solution_delete_n(i); - } + Rxn_solution_map.clear(); } else { std::set < int >::iterator it; for (it = delete_info.Get_solution().Get_numbers().begin(); it != delete_info.Get_solution().Get_numbers().end(); it++) { - if (solution_bsearch(*it, &n, FALSE) != NULL) - { - solution_delete_n(n); - } + Rxn_solution_map.erase(*it); } } } @@ -886,24 +330,17 @@ delete_entities(void) { if (delete_info.Get_surface().Get_numbers().size() == 0) { - for (i = 0; i < count_surface; i++) - { - surface_delete(surface[i].n_user); - } + Rxn_surface_map.clear(); } else { std::set < int >::iterator it; for (it = delete_info.Get_surface().Get_numbers().begin(); it != delete_info.Get_surface().Get_numbers().end(); it++) { - if (surface_bsearch(*it, &n) != NULL) - { - surface_delete(*it); - } + Rxn_surface_map.erase(*it); } } } - // ss_assemblages if (delete_info.Get_ss_assemblage().Get_defined()) { @@ -952,29 +389,6 @@ delete_entities(void) } } } -#ifdef SKIP - if (delete_info.Get_kinetics().Get_defined()) - { - if (delete_info.Get_kinetics().Get_numbers().size() == 0) - { - for (i = 0; i < count_kinetics; i++) - { - kinetics_delete(kinetics[i].n_user); - } - } - else - { - std::set < int >::iterator it; - for (it = delete_info.Get_kinetics().Get_numbers().begin(); it != delete_info.Get_kinetics().Get_numbers().end(); it++) - { - if (kinetics_bsearch(*it, &n) != NULL) - { - kinetics_delete(*it); - } - } - } - } -#endif // mixes if (delete_info.Get_mix().Get_defined()) { @@ -1052,7 +466,6 @@ run_as_cells(void) LDBLE kin_time; int count_steps, use_mix; char token[2 * MAX_LENGTH]; - //struct kinetics *kinetics_ptr; state = REACTION; if (run_info.Get_cells().Get_numbers().size() == 0 || @@ -1090,7 +503,7 @@ run_as_cells(void) count_steps = 1; if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { - int count = ((cxxReaction *) use.Get_reaction_ptr())->Get_reaction_steps(); + int count = use.Get_reaction_ptr()->Get_reaction_steps(); if (count > count_steps) count_steps = count; } @@ -1101,7 +514,7 @@ run_as_cells(void) } if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) { - int count = ((cxxTemperature *) use.Get_temperature_ptr())->Get_countTemps(); + int count = use.Get_temperature_ptr()->Get_countTemps(); if (count > count_steps) { count_steps = count; @@ -1109,7 +522,7 @@ run_as_cells(void) } if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) { - int count = ((cxxPressure *) use.Get_pressure_ptr())->Get_count(); + int count = use.Get_pressure_ptr()->Get_count(); if (count > count_steps) { count_steps = count; @@ -1161,62 +574,6 @@ run_as_cells(void) { cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); kin_time = kinetics_ptr->Current_step((incremental_reactions==TRUE), reaction_step); - -#ifdef SKIP - kinetics_ptr = kinetics_bsearch(-2, &m); - if (incremental_reactions == FALSE) - { - if (kinetics_ptr->count_steps > 0) - { - if (reaction_step > kinetics_ptr->count_steps) - { - kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } - else - { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - kin_time = kinetics_ptr->steps[0]; - } - else - { - kin_time = reaction_step * kinetics_ptr->steps[0] / ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } - else - { - /* incremental reactions */ - if (kinetics_ptr->count_steps > 0) - { - if (reaction_step > kinetics_ptr->count_steps) - { - kin_time = kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } - else - { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - kin_time = 0; - } - else - { - kin_time = - kinetics_ptr->steps[0] / ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } -#endif } } if (incremental_reactions == FALSE || @@ -1258,7 +615,6 @@ run_as_cells(void) memcpy(&save, &save_data, sizeof(struct save)); if (use.Get_kinetics_in() == TRUE) { - //kinetics_duplicate(-2, use.Get_n_kinetics_user()); Utilities::Rxn_copy(Rxn_kinetics_map, -2, use.Get_n_kinetics_user()); } saver(); @@ -1274,28 +630,22 @@ void Phreeqc:: dump_ostream(std::ostream& os) /* ---------------------------------------------------------------------- */ { - int i, n; - // solutions if (dump_info.Get_bool_solution()) { if (dump_info.Get_solution().size() == 0) { - for (i = 0; i < count_solution; i++) - { - cxxSolution cxxsoln(solution[i], phrq_io); - cxxsoln.dump_raw(os,0); - } + Utilities::Rxn_dump_raw(Rxn_solution_map, os, 0); } else { std::set < int >::iterator it; for (it = dump_info.Get_solution().begin(); it != dump_info.Get_solution().end(); it++) { - if (solution_bsearch(*it, &n, FALSE) != NULL) + cxxSolution *p = Utilities::Rxn_find(Rxn_solution_map, *it); + if (p != NULL) { - cxxSolution cxxsoln(solution[n], phrq_io); - cxxsoln.dump_raw(os,0); + p->dump_raw(os, 0); } } } @@ -1349,27 +699,22 @@ dump_ostream(std::ostream& os) { if (dump_info.Get_surface().size() == 0) { - for (i = 0; i < count_surface; i++) - { - cxxSurface cxxentity(&surface[i], phrq_io); - cxxentity.dump_raw(os,0); - } + Utilities::Rxn_dump_raw(Rxn_surface_map, os, 0); } else { std::set < int >::iterator it; for (it = dump_info.Get_surface().begin(); it != dump_info.Get_surface().end(); it++) { + cxxSurface *p = Utilities::Rxn_find(Rxn_surface_map, *it); - if (surface_bsearch(*it, &n) != NULL) + if (p != NULL) { - cxxSurface cxxentity(&surface[n], phrq_io); - cxxentity.dump_raw(os,0); + p->dump_raw(os, 0); } } } } - // ss_assemblages if (dump_info.Get_bool_ss_assemblage()) { @@ -1434,32 +779,6 @@ dump_ostream(std::ostream& os) } } } -#ifdef SKIP - if (dump_info.Get_bool_kinetics()) - { - if (dump_info.Get_kinetics().size() == 0) - { - for (i = 0; i < count_kinetics; i++) - { - cxxKinetics cxxentity(&kinetics[i], phrq_io); - cxxentity.dump_raw(os,0); - } - } - else - { - std::set < int >::iterator it; - for (it = dump_info.Get_kinetics().begin(); it != dump_info.Get_kinetics().end(); it++) - { - - if (kinetics_bsearch(*it, &n) != NULL) - { - cxxKinetics cxxentity(&kinetics[n], phrq_io); - cxxentity.dump_raw(os,0); - } - } - } - } -#endif // mix if (dump_info.Get_bool_mix()) { @@ -1581,15 +900,11 @@ read_user_graph_handler(void) */ std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); - //std::ostringstream oss_out; - //std::ostringstream oss_err; - //CParser parser(iss_in, oss_out, oss_err, phrq_io); CParser parser(iss_in, phrq_io); //For testing, need to read line to get started std::vector < std::string > vopts; std::istream::pos_type next_char; - //parser.get_option(vopts, next_char); if (pr.echo_input == FALSE) { diff --git a/SS.cxx b/SS.cxx index d07e5888..2ffa2431 100644 --- a/SS.cxx +++ b/SS.cxx @@ -52,7 +52,6 @@ cxxSS::~cxxSS() void cxxSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -81,7 +80,6 @@ cxxSS::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing s_s message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""); @@ -89,26 +87,37 @@ cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const indent0.append(Utilities::INDENT); for (i = 0; i < indent + 1; ++i) indent1.append(Utilities::INDENT); - // S_S element and attributes - //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"; + s_oss << indent0 << "# SOLID_SOLUTION_MODIFY candidate identifiers #\n"; for (size_t i = 0; i < this->ss_comps.size(); i++) { - s_oss << indent0 << "-component " << this->ss_comps[i].Get_name() << "\n"; + s_oss << indent0 << "-component " << this->ss_comps[i].Get_name() << "\n"; this->ss_comps[i].dump_raw(s_oss, indent + 1); } + + s_oss << indent0 << "# SOLID_SOLUTION_MODIFY candidate identifiers with new_def=true #\n"; + s_oss << indent0 << "-tk " << this->tk << "\n"; + s_oss << indent0 << "-input_case " << this->input_case << "\n"; + s_oss << indent0 << "-p " << + p[0] << "\t" << + p[1] << "\t" << + p[2] << "\t" << + p[3] << "\n"; + + s_oss << indent0 << "# solid solution workspace variables #\n"; + s_oss << indent0 << "-ag0 " << this->ag0 << "\n"; + s_oss << indent0 << "-ag1 " << this->ag1 << "\n"; + s_oss << indent0 << "-a0 " << this->a0 << "\n"; + s_oss << indent0 << "-a1 " << this->a1 << "\n"; + s_oss << indent0 << "-xb1 " << this->xb1 << "\n"; + s_oss << indent0 << "-xb2 " << this->xb2 << "\n"; + s_oss << indent0 << "-miscibility " << this->miscibility << "\n"; + s_oss << indent0 << "-spinodal " << this->spinodal << "\n"; + s_oss << indent0 << "-ss_in " << this->ss_in << "\n"; + s_oss << indent0 << "-total_moles " << this->total_moles << "\n"; + s_oss << indent0 << "-dn " << this->dn << "\n"; + s_oss << indent0 << "-totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 1); } void @@ -120,7 +129,7 @@ cxxSS::read_raw(CParser & parser, bool check) if (vopts.empty()) { vopts.reserve(10); - vopts.push_back("ss_name_not_used"); // 0 + vopts.push_back("ss_name"); // 0 vopts.push_back("total_moles"); // 1 vopts.push_back("a0"); // 2 vopts.push_back("a1"); // 3 @@ -134,10 +143,10 @@ cxxSS::read_raw(CParser & parser, bool check) 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 + vopts.push_back("p"); //14 + vopts.push_back("ss_in"); //15 + vopts.push_back("totals"); //16 + vopts.push_back("dn"); //17 } std::istream::pos_type ptr; @@ -146,19 +155,20 @@ cxxSS::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool name_defined(false); - //bool total_moles_defined(false); bool a0_defined(false); bool a1_defined(false); bool ag0_defined(false); bool ag1_defined(false); bool miscibility_defined(false); - //bool spinodal_defined(false); - //bool tk_defined(false); bool xb1_defined(false); bool xb2_defined(false); bool useLastLine = false; + for (size_t i = this->Get_p().size(); i < 4; i++) + { + this->p.push_back(0.0); + } + for (;;) { int opt; @@ -185,23 +195,10 @@ cxxSS::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in S_S read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name not used - if (!(parser.get_iss() >> str)) - { - this->name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->name = str; - } - name_defined = true; + parser.warning_msg("-ss_name not used, defined in -solid_solution"); opt_save = CParser::OPT_DEFAULT; break; @@ -212,7 +209,6 @@ cxxSS::read_raw(CParser & parser, bool check) 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; @@ -300,7 +296,6 @@ cxxSS::read_raw(CParser & parser, bool check) 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; @@ -311,7 +306,6 @@ cxxSS::read_raw(CParser & parser, bool check) 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; @@ -376,10 +370,50 @@ cxxSS::read_raw(CParser & parser, bool check) this->input_case = (cxxSS::SS_PARAMETER_TYPE) i; } } - //spinodal_defined = true; opt_save = CParser::OPT_DEFAULT; break; + case 14: // p + { + this->p.clear(); + this->p.assign(4, 0.0); + for (int i = 0; i < 4; i++) + { + if (!(parser.get_iss() >> this->p[i])) + parser.error_msg("Expected 4 parameters."); + } + } + break; + case 15: // ss_in + { + if (!(parser.get_iss() >> this->ss_in)) + { + this->ss_in = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for ss_in.", + PHRQ_io::OT_CONTINUE); + } + } + break; + case 16: // totals + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser.error_msg + ("Expected element name and molality for cxxSS totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 16; + break; + case 17: // dn + if (!(parser.get_iss() >> this->dn)) + { + this->dn = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for dn.", PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -387,18 +421,6 @@ cxxSS::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Name not defined for SSassemblageSS input.", - PHRQ_io::OT_CONTINUE); - } - /* - if (total_moles_defined == false) { - parser.incr_input_error(); - parser.error_msg("Total_moles not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); - } - */ if (a0_defined == false) { parser.incr_input_error(); @@ -429,16 +451,6 @@ cxxSS::read_raw(CParser & parser, bool check) parser.error_msg("Miscibility not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); } - /* - if (spinodal_defined == false) { - parser.incr_input_error(); - parser.error_msg("Spinodal not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); - } - if (tk_defined == false) { - parser.incr_input_error(); - parser.error_msg("Tk not defined for SSassemblageSS input.", PHRQ_io::OT_CONTINUE); - } - */ if (xb1_defined == false) { parser.incr_input_error(); diff --git a/SS.h b/SS.h index 91014623..3440f740 100644 --- a/SS.h +++ b/SS.h @@ -17,8 +17,7 @@ class cxxSS: public PHRQ_base public: cxxSS(PHRQ_io *io=NULL); - //cxxSS(struct s_s *, PHRQ_io *io=NULL); - ~cxxSS(); + virtual ~cxxSS(); enum SS_PARAMETER_TYPE { @@ -104,18 +103,22 @@ class cxxSS: public PHRQ_base void Set_p(const std::vector & t) {this->p = t;} protected: std::string name; - //cxxNameDouble comps; - LDBLE total_moles; - LDBLE dn; - LDBLE a0, a1; + // candidates for SOLID_SOLUTION_MODIFY LDBLE ag0, ag1; - bool ss_in; + std::vector ss_comps; + + // SOLID_SOLUTION keyword data + LDBLE a0, a1; bool miscibility; bool spinodal; LDBLE tk, xb1, xb2; SS_PARAMETER_TYPE input_case; - std::vector ss_comps; std::vector p; + + // workspace variable + LDBLE total_moles; + LDBLE dn; + bool ss_in; cxxNameDouble totals; public: diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 60086c45..f4025f7b 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -26,6 +26,7 @@ cxxSSassemblage::cxxSSassemblage(PHRQ_io * io) // : cxxNumKeyword(io) { + new_def = false; } cxxSSassemblage::cxxSSassemblage(const std::map < int, @@ -34,7 +35,6 @@ cxxSSassemblage::cxxSSassemblage(const std::map < int, cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; - //std::list SSs; // // Mix // @@ -59,7 +59,6 @@ cxxSSassemblage::~cxxSSassemblage() void cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -90,7 +89,6 @@ cxxSSassemblage::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing SSassemblage message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -104,16 +102,26 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) // SSassemblage element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "SOLID_SOLUTIONS_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << indent1 << "# SOLID_SOLUTION_MODIFY candidate identifiers #\n"; // SSs for (std::map < std::string, cxxSS >::const_iterator it = SSs.begin(); it != SSs.end(); ++it) { s_oss << indent1; - s_oss << "-solid_solution " << it->first << "\n"; + s_oss << "-solid_solution " << it->first << "\n"; (*it).second.dump_raw(s_oss, indent + 2); } + + s_oss << indent1 << "# SOLID_SOLUTION candidate identifiers with new_def=true #\n"; + s_oss << indent1; + s_oss << "-new_def " << this->new_def << "\n"; + + s_oss << indent1 << "# solid solution workspace variables #\n"; + s_oss << indent1; + s_oss << "-SSassemblage_totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 2); } void cxxSSassemblage::read_raw(CParser & parser, bool check) @@ -123,6 +131,8 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) { vopts.reserve(10); vopts.push_back("solid_solution"); // 0 + vopts.push_back("ssassemblage_totals"); // 1 + vopts.push_back("new_def"); // 2 } std::istream::pos_type ptr; @@ -189,6 +199,32 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) } useLastLine = true; break; + case 1: // totals + if (this->totals.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for SSassemblage totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 1; + break; + case 2: // new_def + { + int i; + if (!(parser.get_iss() >> i)) + { + parser.incr_input_error(); + parser.error_msg("Expected 0/1 for new_def.", PHRQ_io::OT_CONTINUE); + } + else + { + this->new_def = (i == 0) ? false : true; + } + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; diff --git a/SSassemblage.h b/SSassemblage.h index 5ed16d35..1838f7fb 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -23,7 +23,6 @@ class cxxSSassemblage:public cxxNumKeyword public: cxxSSassemblage(PHRQ_io * io = NULL); - //cxxSSassemblage(struct ss_assemblage *, PHRQ_io * io = NULL); cxxSSassemblage(const std::map < int, cxxSSassemblage > &entity_map, cxxMix & mx, int n_user, PHRQ_io * io = NULL); ~cxxSSassemblage(); @@ -50,10 +49,12 @@ public: cxxSS *Find(const std::string &s); protected: - bool new_def; + // SOLID_SOLUTION_MODIFY candidate std::map < std::string, cxxSS > SSs; + // SOLID_SOLUTION keyword data + bool new_def; + // internal variables cxxNameDouble totals; - }; #endif // !defined(SSASSEMBLAGE_H_INCLUDED) diff --git a/SScomp.cxx b/SScomp.cxx index d2e20439..f2e8554a 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -10,7 +10,6 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SScomp.h" -//#include "Dictionary.h" #include "phqalloc.h" ////////////////////////////////////////////////////////////////////// @@ -36,6 +35,26 @@ PHRQ_base(io) dnc = 0; dnb = 0; } +#ifdef SKIP +cxxSScomp::cxxSScomp(struct pure_phase * pure_phase_ptr, PHRQ_io *io) +: +PHRQ_base(io) + // + // constructor for cxxSScomp from struct pure_phase + // +{ + this->Set_name(pure_phase_ptr->name); + this->Set_add_formula(pure_phase_ptr->add_formula); + si = pure_phase_ptr->si; + si_org = pure_phase_ptr->si_org; + moles = pure_phase_ptr->moles; + delta = pure_phase_ptr->delta; + initial_moles = pure_phase_ptr->initial_moles; + force_equality = (pure_phase_ptr->force_equality == TRUE); + dissolve_only = (pure_phase_ptr->dissolve_only == TRUE); + precipitate_only = (pure_phase_ptr->precipitate_only == TRUE); +} +#endif cxxSScomp::~cxxSScomp() { } @@ -43,7 +62,6 @@ cxxSScomp::~cxxSScomp() void cxxSScomp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing pure_phase message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -54,22 +72,19 @@ cxxSScomp::dump_raw(std::ostream & s_oss, unsigned int indent) const for (i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); - // Pure_Phase element and attributes + s_oss << indent1 << "# SOLID_SOLUTION_MODIFY candidate identifiers #\n"; + s_oss << indent1 << "-moles " << this->moles << "\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 << 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"; + s_oss << indent1 << "# Solid solution workspace variables #\n"; + s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n"; + s_oss << indent1 << "-init_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"; } void @@ -81,7 +96,7 @@ cxxSScomp::read_raw(CParser & parser, bool check) if (vopts.empty()) { vopts.reserve(10); - vopts.push_back("name_not_used"); // 0 + vopts.push_back("name"); // 0 vopts.push_back("initial_moles"); // 1 vopts.push_back("moles"); // 2 vopts.push_back("init_moles"); // 3 @@ -89,9 +104,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_not_used"); // 8 - vopts.push_back("dnc_not_used"); // 9 - vopts.push_back("dnb_not_used"); // 10 + vopts.push_back("dn"); // 8 + vopts.push_back("dnc"); // 9 + vopts.push_back("dnb"); // 10 } std::istream::pos_type ptr; @@ -100,11 +115,8 @@ cxxSScomp::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool name_defined(false); bool initial_moles_defined(false); bool moles_defined(false); - //bool init_moles_defined(false); - //bool delta_defined(false); for (;;) { @@ -124,23 +136,10 @@ cxxSScomp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Exchange for more processing - //parser.error_msg("Unknown input in PURE_PHASE read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->name = str; - } - name_defined = true; + parser.error_msg("-Name ignored. Define with -component."); break; case 1: // initial_moles @@ -173,7 +172,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for init_moles.", PHRQ_io::OT_CONTINUE); } - //init_moles_defined = true; break; case 4: // delta @@ -184,7 +182,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for delta.", PHRQ_io::OT_CONTINUE); } - //delta_defined = true; break; case 5: // fraction_x @@ -195,7 +192,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for fraction_x.", PHRQ_io::OT_CONTINUE); } - //initial_moles_defined = true; break; @@ -236,7 +232,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for dnc.", PHRQ_io::OT_CONTINUE); } - //dnc_defined = true; break; case 10: // dnb if (!(parser.get_iss() >> this->dnb)) @@ -246,7 +241,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for dnb.", PHRQ_io::OT_CONTINUE); } - //dnc_defined = true; break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -255,12 +249,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) // members that must be defined if (check) { - if (name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Name not defined for PPassemblageComp input.", - PHRQ_io::OT_CONTINUE); - } if (moles_defined == false) { parser.incr_input_error(); @@ -338,74 +326,10 @@ cxxSScomp::totalize(PHREEQC_PTR_ARG) return; } #endif -#ifdef SKIP -void -cxxSScomp::add(const cxxSScomp & addee, double extensive) -{ - double ext1, ext2, f1, f2; - if (extensive == 0.0) - return; - if (addee.name.size() == 0) - return; - // this and addee must have same name - // otherwise generate a new PPassemblagComp with multiply - - ext1 = this->moles; - ext2 = addee.moles * extensive; - if (ext1 + ext2 != 0) - { - f1 = ext1 / (ext1 + ext2); - f2 = ext2 / (ext1 + ext2); - } - else - { - f1 = 0.5; - f2 = 0.5; - } - //char * name; - //char *add_formula; - - if (this->name.size() == 0 && addee.name.size() == 0) - { - return; - } - assert(this->name == addee.name); - if (this->add_formula != addee.add_formula) - { - std::ostringstream oss; - oss << - "Can not mix two Equilibrium_phases with differing add_formulae., " - << this->name; - error_msg(oss.str().c_str(), CONTINUE); - return; - } - //double si; - this->si = this->si * f1 + addee.si * f2; - //double si_org; - this->si_org = this->si_org * f1 + addee.si_org * f2; - //double moles; - this->moles += addee.moles * extensive; - //double delta; - this->delta += addee.delta * extensive; - //double initial_moles; - this->initial_moles += addee.initial_moles * extensive; - //bool force_equality; - //bool dissolve_only; - -} -#endif void cxxSScomp::multiply(double extensive) { - //char * name; - //char *add_formula; - //double si; - //double moles; this->moles *= extensive; - //double delta; this->delta *= extensive; - //double initial_moles; this->initial_moles *= extensive; - //bool force_equality; - //bool dissolve_only; } diff --git a/SScomp.h b/SScomp.h index 88af65af..8eabc758 100644 --- a/SScomp.h +++ b/SScomp.h @@ -15,7 +15,7 @@ class cxxSScomp: public PHRQ_base public: cxxSScomp(PHRQ_io *io=NULL); - ~cxxSScomp(); + virtual ~cxxSScomp(); void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); @@ -44,7 +44,6 @@ class cxxSScomp: public PHRQ_base LDBLE Get_dnb() const {return this->dnb;} void Set_dnb(LDBLE t) {this->dnb = t;} - //void add(const cxxSScomp & comp, double extensive); void multiply(double extensive); #ifdef USE_MPI @@ -53,9 +52,11 @@ class cxxSScomp: public PHRQ_base #endif protected: std::string name; - //struct phase *phase; - LDBLE initial_moles; + // SOLID_SOLUTION_MODIFY candidate identifier LDBLE moles; + + // Solid solution workspace variables + LDBLE initial_moles; LDBLE init_moles; LDBLE delta; LDBLE fraction_x; diff --git a/Solution.cxx b/Solution.cxx index ac495b0e..f6a2c38d 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -29,9 +29,11 @@ cxxSolution::cxxSolution(PHRQ_io * io) // // default constructor for cxxSolution // -: cxxNumKeyword(io), -isotopes(io) +: cxxNumKeyword(io) { + this->io = io; + this->new_def = false; + this->patm = 1.0; this->tc = 25.0; this->ph = 7.0; this->pe = 4.0; @@ -40,63 +42,58 @@ isotopes(io) this->total_h = 111.1; this->total_o = 55.55; this->cb = 0.0; + this->density = 1.0; this->mass_water = 1.0; this->total_alkalinity = 0.0; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + this->initial_data = NULL; } - -cxxSolution::cxxSolution(struct solution * solution_ptr, PHRQ_io * io) - // - // constructor for cxxSolution from struct solution - // -: -cxxNumKeyword(io), -totals(solution_ptr->totals), -master_activity(solution_ptr->master_activity, -solution_ptr->count_master_activity, -cxxNameDouble::ND_SPECIES_LA), -species_gamma(solution_ptr->species_gamma, solution_ptr->count_species_gamma, cxxNameDouble::ND_SPECIES_GAMMA), -isotopes(solution_ptr, io) +cxxSolution::cxxSolution(const cxxSolution &old_sol) { - - this->Set_description(solution_ptr->description); - this->n_user = solution_ptr->n_user; - this->n_user_end = solution_ptr->n_user_end; - this->tc = solution_ptr->tc; - this->ph = solution_ptr->ph; - this->pe = solution_ptr->solution_pe; - this->mu = solution_ptr->mu; - this->ah2o = solution_ptr->ah2o; - this->total_h = solution_ptr->total_h; - this->total_o = solution_ptr->total_o; - this->cb = solution_ptr->cb; - this->mass_water = solution_ptr->mass_water; - this->total_alkalinity = solution_ptr->total_alkalinity; - - // Totals filled in constructor, just save description and moles - - // Isotopes - /* - for (i = 0; i < solution_ptr->count_isotopes; i++) { - cxxSolutionIsotope iso(&solution_ptr->isotopes[i]); - isotopes.push_back(iso); - } - */ - // Master_activity in constructor - // Species_gamma in constructor + *this = old_sol; } - - -cxxSolution::cxxSolution(const std::map < int, cxxSolution > &solutions, +const cxxSolution & +cxxSolution::operator =(const cxxSolution &rhs) +{ + if (this != &rhs) + { + this->io = rhs.io; + this->n_user = rhs.n_user; + this->n_user_end = rhs.n_user_end; + this->description = rhs.description; + this->new_def = rhs.new_def; + this->patm = rhs.patm; + this->tc = rhs.tc; + this->ph = rhs.ph; + this->pe = rhs.pe; + this->mu = rhs.mu; + this->ah2o = rhs.ah2o; + this->total_h = rhs.total_h; + this->total_o = rhs.total_o; + this->density = rhs.density; + this->cb = rhs.cb; + this->mass_water = rhs.mass_water; + this->total_alkalinity = rhs.total_alkalinity; + this->totals = rhs.totals; + this->master_activity = rhs.master_activity; + this->species_gamma = rhs.species_gamma; + this->isotopes = rhs.isotopes; + if (rhs.initial_data != NULL) + this->initial_data = new cxxISolution(*rhs.initial_data); + else + this->initial_data = NULL; + } + return *this; +} +cxxSolution::cxxSolution(std::map < int, cxxSolution > &solutions, cxxMix & mix, int l_n_user, PHRQ_io * io) // // constructor for cxxSolution from mixture of solutions // : -cxxNumKeyword(io), -isotopes(io) +cxxNumKeyword(io) { // @@ -128,12 +125,12 @@ isotopes(io) } cxxSolution::~cxxSolution() { + delete this->initial_data; } void cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""); @@ -146,9 +143,6 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0; s_oss << "new_def << "\"" << "\n"; - s_oss << indent1; s_oss << "soln_n_user=\"" << this->n_user << "\" " << "\n"; @@ -194,36 +188,9 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const // master_activity map this->master_activity.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\"" ; - s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << "\n"; - } - } - */ + // species_gamma map this->species_gamma.dump_xml(s_oss, indent + 1); - /* - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent1; - s_oss << "first << "\"" ; - s_oss << " m_a_la=\"" << it->second << "\"" ; - s_oss << "\">" << "\n"; - } - } - */ - - for (std::list < cxxSolutionIsotope >::const_iterator it = - this->isotopes.begin(); it != isotopes.end(); ++it) - { - it->dump_xml(s_oss, indent + 1); - } // End of solution s_oss << indent0; @@ -235,7 +202,6 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const void cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing solution message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -249,95 +215,77 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con // Solution element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SOLUTION_RAW " << n_user_local << " " << this->description << "\n"; - - //s_oss << "# Critical values" << "\n"; + s_oss << "SOLUTION_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-temp " << this->tc << "\n"; + s_oss << "-temp " << this->tc << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_h " << this->total_h << "\n"; + s_oss << "-total_h " << this->total_h << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_o " << this->total_o << "\n"; + s_oss << "-total_o " << this->total_o << "\n"; // new identifier s_oss << indent1; - s_oss << "-cb " << this->cb << "\n"; + s_oss << "-cb " << this->cb << "\n"; + + // new identifier + s_oss << indent1; + s_oss << "-density " << this->density << "\n"; // soln_total conc structures s_oss << indent1; s_oss << "-totals" << "\n"; this->totals.dump_raw(s_oss, indent + 2); - //s_oss << "# Optional critical values" << "\n"; - // Isotopes s_oss << indent1; - s_oss << "-Isotopes" << "\n"; { - for (std::list < cxxSolutionIsotope >::const_iterator it = - this->isotopes.begin(); it != isotopes.end(); ++it) + for (std::map < std::string, cxxSolutionIsotope >::const_iterator it = + this->isotopes.begin(); it != isotopes.end(); ++it) { - it->dump_raw(s_oss, indent + 2); + s_oss << indent1 << "-Isotope" << "\n"; + it->second.dump_raw(s_oss, indent + 2); } } s_oss << indent1; - s_oss << "-pH " << this->ph << "\n"; + s_oss << "-pH " << this->ph << "\n"; s_oss << indent1; - s_oss << "-pe " << this->pe << "\n"; + s_oss << "-pe " << this->pe << "\n"; // new identifier s_oss << indent1; - s_oss << "-mu " << this->mu << "\n"; + s_oss << "-mu " << this->mu << "\n"; // new identifier s_oss << indent1; - s_oss << "-ah2o " << this->ah2o << "\n"; + s_oss << "-ah2o " << this->ah2o << "\n"; // new identifier s_oss << indent1; - s_oss << "-mass_water " << this->mass_water << "\n"; + s_oss << "-mass_water " << this->mass_water << "\n"; // new identifier s_oss << indent1; - s_oss << "-total_alkalinity " << this->total_alkalinity << "\n"; + s_oss << "-total_alkalinity " << this->total_alkalinity << "\n"; // master_activity map s_oss << indent1; s_oss << "-activities" << "\n"; this->master_activity.dump_raw(s_oss, indent + 2); - /* - { - for (std::map ::const_iterator it = master_activity.begin(); it != master_activity.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << "\n"; - } - } - */ + // species_gamma map s_oss << indent1; s_oss << "-gammas" << "\n"; this->species_gamma.dump_raw(s_oss, indent + 2); - /* - { - { - for (std::map ::const_iterator it = species_gamma.begin(); it != species_gamma.end(); ++it) { - s_oss << indent2; - s_oss << it->first << " " << it->second << "\n"; - } - } - } - */ return; } - void cxxSolution::read_raw(CParser & parser, bool check) { @@ -366,15 +314,22 @@ cxxSolution::read_raw(CParser & parser, bool check) vopts.push_back("total_alk"); // 18 vopts.push_back("cb"); // 19 vopts.push_back("charge_balance"); // 20 + vopts.push_back("density"); // 21 } + // Used if it is modify + cxxNameDouble simple_original_totals = this->totals.Simplify_redox(); + cxxNameDouble original_activities(this->master_activity); + + this->master_activity.clear(); + std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; int opt_save; // Read solution number and description - this->read_number_description(parser); + this->read_number_description(parser.line()); opt_save = CParser::OPT_ERROR; bool tc_defined(false); @@ -411,14 +366,6 @@ cxxSolution::read_raw(CParser & parser, bool check) continue; case 0: // totals - //if (this->totals.read_raw(parser, next_char) != - // CParser::PARSER_OK) - //{ - // parser.incr_input_error(); - // parser. - // error_msg("Expected element name and moles for totals.", - // PHRQ_io::OT_CONTINUE); - //} { cxxNameDouble temp_totals; if (temp_totals.read_raw(parser, next_char) != CParser::PARSER_OK) @@ -462,24 +409,24 @@ cxxSolution::read_raw(CParser & parser, bool check) opt_save = 2; break; - case 3: // isotopes + case 3: // isotope { - cxxSolutionIsotope iso(this->Get_io()); - if (iso.read_raw(parser, next_char) != CParser::PARSER_OK) + std::string name; + if (!(parser.get_iss() >> name)) { parser.incr_input_error(); - parser.error_msg("Expected data for isotopes.", + parser.error_msg("Expected character value for isotope name.", PHRQ_io::OT_CONTINUE); } else { - if (iso.Get_isotope_name().size() != 0) - { - this->isotopes.push_back(iso); - } + cxxSolutionIsotope iso(this->Get_io()); + iso.Set_isotope_name(name.c_str()); + iso.read_raw(parser, check); + this->isotopes[name] = iso; } } - opt_save = 3; + opt_save = CParser::OPT_DEFAULT; break; case 4: // temp @@ -610,7 +557,16 @@ cxxSolution::read_raw(CParser & parser, bool check) cb_defined = true; opt_save = CParser::OPT_DEFAULT; break; - + case 21: // density + if (!(parser.get_iss() >> this->density)) + { + this->density = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for density.", + PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -682,9 +638,34 @@ cxxSolution::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } } + + // Update activities + if (original_activities.size() > 0) + { + + cxxNameDouble simple_this_totals = this->totals.Simplify_redox(); + cxxNameDouble::iterator it = simple_original_totals.begin(); + for ( ; it != simple_original_totals.end(); it++) + { + cxxNameDouble::iterator jit = simple_this_totals.find(it->first); + if (jit != simple_this_totals.end()) + { + if (it->second != 0) + { + LDBLE f = jit->second / it->second; + if (f != 1) + { + original_activities.Multiply_activities_redox(it->first, f); + } + } + } + } + original_activities.merge_redox(this->master_activity); + this->master_activity = original_activities; + } + return; } - void cxxSolution::zero() { @@ -696,6 +677,7 @@ cxxSolution::zero() this->total_h = 0.0; this->total_o = 0.0; this->cb = 0.0; + this->density = 1.0; this->mass_water = 0.0; this->total_alkalinity = 0.0; this->totals.type = cxxNameDouble::ND_ELT_MOLES; @@ -723,12 +705,13 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->total_h += addee.total_h * extensive; this->total_o += addee.total_o * extensive; this->cb += addee.cb * extensive; + this->density = f1 * this->density + f2 * addee.density; this->mass_water += addee.mass_water * extensive; this->total_alkalinity += addee.total_alkalinity * extensive; this->totals.add_extensive(addee.totals, extensive); this->master_activity.add_log_activities(addee.master_activity, f1, f2); this->species_gamma.add_intensive(addee.species_gamma, f1, f2); - this->isotopes.add(addee.isotopes, f2, extensive); + this->Add_isotopes(addee.isotopes, f2, extensive); } void @@ -745,7 +728,7 @@ cxxSolution::multiply(LDBLE extensive) this->mass_water *= extensive; this->total_alkalinity *= extensive; this->totals.multiply(extensive); - this->isotopes.multiply(extensive); + this->Multiply_isotopes(extensive); } LDBLE @@ -761,6 +744,7 @@ cxxSolution::Get_total(char *string) const return (it->second); } } +#ifdef SKIP LDBLE cxxSolution::Get_total_element(const char *string) const { @@ -784,6 +768,7 @@ cxxSolution::Get_total_element(const char *string) const } return (d); } +#endif void cxxSolution::Set_total(char *string, LDBLE d) @@ -1087,738 +1072,45 @@ cxxSolution::Set_master_activity(char *string, LDBLE d) { this->master_activity[string] = d; } -#ifdef SKIP void -cxxSolution::modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original) -// -// Estimate activities after solution_modify -// +cxxSolution::Add_isotopes(const std::map < std::string, cxxSolutionIsotope > & old, LDBLE intensive, LDBLE extensive) { - // Note: any master_activities in "this" have been read in SOLUTION_MODIFY - - // to standardize, convert element to valence state if needed - // for original activity list (probably not needed) - cxxNameDouble orig_master_activity(original.Get_master_activity()); - cxxNameDouble::const_iterator it; - bool redo=true; - while (redo) + for (std::map < std::string, cxxSolutionIsotope >::const_iterator itold = old.begin(); itold != old.end(); ++itold) { - redo = false; - for (it = orig_master_activity.begin(); it != orig_master_activity.end(); it++) + std::map < std::string, cxxSolutionIsotope >::iterator it_this; + it_this = this->isotopes.find(itold->first); + if (it_this != this->isotopes.end()) { - struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); - if (master_ptr != NULL) - { - if (master_ptr->primary == TRUE) - { - struct master *master_ptr_secondary = P_INSTANCE_POINTER master_bsearch_secondary(master_ptr->elt->name); + LDBLE t = it_this->second.Get_total(); + t += itold->second.Get_total() * extensive; + it_this->second.Set_total(t); - // redox element erase and replace - if (master_ptr_secondary != master_ptr) - { - LDBLE d = it->second; - orig_master_activity.erase(orig_master_activity.find(master_ptr->elt->name)); - orig_master_activity[master_ptr_secondary->elt->name] = d; - redo = true; - break; - } - } - } - else - { - error_msg("Could not find master species in modify_activities.", STOP); - } - } - } + t = it_this->second.Get_ratio(); + t += itold->second.Get_ratio() * intensive; + it_this->second.Set_ratio(t); - // also for modified activity list - cxxNameDouble mod_master_activity(this->master_activity); - redo=true; - while (redo) - { - redo = false; - for (it = mod_master_activity.begin(); it != mod_master_activity.end(); it++) - { - struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); - if (master_ptr != NULL) - { - if (master_ptr->primary == TRUE) - { - struct master *master_ptr_secondary = P_INSTANCE_POINTER master_bsearch_secondary(master_ptr->elt->name); - - // redox element erase and replace - if (master_ptr_secondary != master_ptr) - { - LDBLE d = it->second; - mod_master_activity.erase(mod_master_activity.find(master_ptr->elt->name)); - mod_master_activity[master_ptr_secondary->elt->name] = d; - redo = true; - break; - } - } - } - else - { - error_msg("Could not find master species in modify_activities.", STOP); - } - } - } - - // go through totals - for (it = this->totals.begin(); it != this->totals.end(); ++it) - { - // find element name - struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(it->first.c_str()); - struct master *master_primary_ptr = master_ptr->elt->primary; - char * ename = master_ptr->elt->primary->elt->name; - char * secondary_name; - if (master_ptr->primary == TRUE) - { - struct master *m_ptr = P_INSTANCE_POINTER master_bsearch_secondary(ename); - secondary_name = m_ptr->elt->name; + t = it_this->second.Get_ratio_uncertainty(); + t += itold->second.Get_ratio_uncertainty() * intensive; + it_this->second.Set_ratio_uncertainty(t); + it_this->second.Set_ratio_uncertainty_defined(it_this->second.Get_ratio_uncertainty_defined() + || itold->second.Get_ratio_uncertainty_defined()); } else { - secondary_name = master_ptr->elt->name; + cxxSolutionIsotope iso(itold->second); + iso.Set_total(itold->second.Get_total() * extensive); + this->Get_isotopes()[iso.Get_isotope_name()] = iso; } - if (strcmp(ename, "H") == 0 || strcmp(ename, "O") == 0) continue; - - LDBLE d_mod, d_orig; - d_mod = this->Get_total_element(ename); - if (d_mod <= 0) continue; - - d_orig = original.Get_total_element(ename); - if (d_orig <= 0) - { - // add estimate for la based on concentration if not in list - if (mod_master_activity.find(secondary_name) == mod_master_activity.end()) - { - mod_master_activity[secondary_name] = log10(d_mod) - 2.0; - } - continue; - } - - // case where total for both orig and modified are greater than 0 - LDBLE lratio = log10(d_mod / d_orig); - - int j; - j = master_primary_ptr->number; - int j_first = j + 1; - int j_last = P_INSTANCE_POINTER count_master; - - // non redox element - if ( (j+1 >= P_INSTANCE_POINTER count_master) || (P_INSTANCE_POINTER master[j+1]->elt->primary != master_primary_ptr) ) - { - j_first = j; - j_last = j+1; - } - - for (j = j_first ; j < j_last; j++) - { - if (P_INSTANCE_POINTER master[j]->elt->primary != master_primary_ptr) break; - - if (mod_master_activity.find(P_INSTANCE_POINTER master[j]->elt->name) == mod_master_activity.end()) - { - // has not been defined in SOLUTION_MODIFY - cxxNameDouble::const_iterator it1; - it1 = orig_master_activity.find(P_INSTANCE_POINTER master[j]->elt->name); - if (it1 != orig_master_activity.end()) - { - LDBLE d = it1->second; - mod_master_activity[P_INSTANCE_POINTER master[j]->elt->name] = d + lratio; - } - else - // Has total, but no activity, should not happen - { - mod_master_activity[P_INSTANCE_POINTER master[j]->elt->name] = log10(d_mod) - 2.0; - } - } - } - } - - // merge activities - this->master_activity = orig_master_activity; - - for (it = mod_master_activity.begin(); it != mod_master_activity.end(); it++) - { - this->master_activity[it->first] = it->second; } } -#endif void -cxxSolution::modify_activities(const cxxSolution & original) -// -// Estimate activities after solution_modify -// +cxxSolution::Multiply_isotopes(LDBLE extensive) { - // Note: any master_activities in "this" have been read in SOLUTION_MODIFY - cxxNameDouble factor; - cxxNameDouble updated_orig_activities(original.Get_master_activity()); - cxxNameDouble::const_iterator it; - cxxNameDouble::const_iterator orig_it; - - // Calculate a factor of log10(new tot/old tot) for each element or element redox state in current totals - for (it = this->totals.begin(); it != this->totals.end(); it++) + std::map < std::string, cxxSolutionIsotope>::iterator it; + for (it = this->isotopes.begin(); it != this->isotopes.end(); it++) { - orig_it = original.Get_totals().find(it->first); - if (orig_it != original.Get_totals().end()) - { - // element or valence state in both - if (it->second > 0 && orig_it->second > 0) - { - factor[it->first] = log10(it->second / orig_it->second); - } - } - else - { - - std::string ename; - std::basic_string < char >::size_type indexCh; - indexCh = it->first.find("("); - if (indexCh != std::string::npos) - { - // valence in current and element in original - ename = it->first.substr(0, indexCh); - LDBLE orig_tot = original.Get_total_element(ename.c_str()); - LDBLE tot = this->Get_total_element(ename.c_str()); - if (tot > 0 && orig_tot > 0) - { - factor[ename] = log10(tot/orig_tot); - } - } - else - { - // element in current and valence in original - ename = it->first; - LDBLE orig_tot = original.Get_total_element(ename.c_str()); - if (it->second > 0 && orig_tot > 0) - { - factor[ename] = log10(it->second/orig_tot); - } - } - } + LDBLE total = it->second.Get_total(); + total *= extensive; + it->second.Set_total(total); } - - // update original master_activities using just computed factors - for (it = factor.begin(); it != factor.end(); it++) - { - orig_it = original.Get_master_activity().find(it->first); - if (orig_it != original.Get_master_activity().end()) - { - // Found exact match - LDBLE d = orig_it->second + it->second; - updated_orig_activities[it->first.c_str()] = d; - } - else - { - // no exact match, current is element name, need to find all valences - orig_it = original.Get_master_activity().begin(); - std::string v_name = it->first; - v_name.append("("); - for ( ; orig_it != original.Get_master_activity().end(); orig_it++) - { - if (strstr(orig_it->first.c_str(), v_name.c_str()) == orig_it->first.c_str()) - { - LDBLE d = orig_it->second + it->second; - updated_orig_activities[orig_it->first.c_str()] = d; - } - } - } - } - - // Merge any new master_activities, which overwrites updated originals - updated_orig_activities.merge_redox(this->Get_master_activity()); - - // Set activities to updated, merged activities - this->master_activity.clear(); - this->master_activity = updated_orig_activities; - -} -void -cxxSolution::Simplify_totals() -{ - // remove individual redox states from totals - std::set list_of_elements; - cxxNameDouble::iterator it; - for (it = this->totals.begin(); it != this->totals.end(); ++it) - { - std::string current_ename(it->first); - std::basic_string < char >::size_type indexCh; - indexCh = current_ename.find("("); - if (indexCh != std::string::npos) - { - current_ename = current_ename.substr(0, indexCh); - } - if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") - continue; - list_of_elements.insert(current_ename); - } - - cxxNameDouble new_totals; - new_totals.type = cxxNameDouble::ND_ELT_MOLES; - std::set::iterator nt_it = list_of_elements.begin(); - for( ; nt_it != list_of_elements.end(); nt_it++) - { - new_totals[(*nt_it).c_str()] = this->Get_total_element((*nt_it).c_str()); - } - this->totals = new_totals; -} -void -cxxSolution::Update(const cxxNameDouble &nd) -{ - // assumes - // nd has H, O, Charge, and totals, without any valence states - - // remove individual redox states from solution totals - this->Simplify_totals(); - - // process special cases and calculate factors - cxxNameDouble factor; - cxxNameDouble::const_iterator it; - for (it = nd.begin(); it != nd.end(); ++it) - { - if (it->first == "H") - { - this->total_h = it->second; - } - else if (it->first == "O") - { - this->total_o = it->second; - } - else if (it->first == "Charge") - { - this->cb = it->second; - } - else - { - cxxNameDouble::iterator sol_it = this->totals.find(it->first.c_str()); - if (sol_it != this->totals.end()) - { - if (it->second != 0 && sol_it->second != 0) - { - factor[it->first.c_str()] = log10(it->second/sol_it->second); - } - this->totals[it->first.c_str()] = it->second; - } - } - } - - // update original master_activities using just computed factors - - cxxNameDouble updated_activities(this->master_activity); - for (it = factor.begin(); it != factor.end(); it++) - { - std::string v_name = it->first; - v_name.append("("); - - cxxNameDouble::iterator sol_it = this->totals.begin(); - for ( ; sol_it != this->totals.end(); sol_it++) - { - // Exact match - if ( it->first == sol_it->first) - { - LDBLE d = sol_it->second + it->second; - updated_activities[it->first.c_str()] = d; - } - else if (strstr(v_name.c_str(), sol_it->first.c_str()) == sol_it->first.c_str()) - { - LDBLE d = sol_it->second + it->second; - updated_activities[sol_it->first.c_str()] = d; - } - } - } - // Set activities to updated, merged activities - this->master_activity.clear(); - this->master_activity = updated_activities; -} - -//#include "ISolution.h" -//#include "Exchange.h" -//#include "Surface.h" -//#include "PPassemblage.h" -//#include "cxxKinetics.h" -//#include "SSassemblage.h" -//#include "GasPhase.h" -//#include "Reaction.h" -//#include "Temperature.h" -//#include "StorageBin.h" -//#include "NumKeyword.h" -//#include // std::cout std::cerr -////#include -//#include -//#include -//void -//test_classes(void) -//{ -// -// -// -// -// int i; -// /* -// std::map Solutions; -// cxxSolution soln(solution[0]); -// Solutions[solution[0]->n_user] = soln; -// bool b = Utilities::exists(Solutions, 1); -// */ -// /* -// cxxEntityMap x; -// cxxSolution soln(solution[0]); -// cxxNumKeyword nk; -// x[solution[0]->n_user] = soln; -// */ -// std::ostringstream msg; -// status_on = FALSE; -// std::cout << "\n" << "TEST CLASSES" << "\n"; -// for (i = 0; i < count_solution; i++) -// { -// if (solution[i]->new_def == TRUE) -// { -// std::cout << "Solution new_def " << solution[i]-> -// n_user << "\n"; -// cxxISolution sol(solution[i]); -// solution_free(solution[i]); -// solution[i] = NULL; -// solution[i] = sol.cxxISolution2solution(); -// struct solution *soln_ptr; -// soln_ptr = solution[i]; -// soln_ptr = solution[i]; -// } -// else -// { -// std::cout << "Solution " << solution[i]->n_user << "\n"; -// std::ostringstream oss; -// cxxSolution sol(solution[i]); -// solution_free(solution[i]); -// solution[i] = NULL; -// sol.dump_raw(oss, 0); -// -// //std::fstream myfile("t"); -// //CParser cparser(myfile, std::cout, std::cerr); -// cxxSolution sol1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// -// sol1.read_raw(cparser); -// -// solution[i] = sol1.cxxSolution2solution(); -// } -// } -// for (i = 0; i < count_exchange; i++) -// { -// if (exchange[i].new_def != TRUE) -// { -// std::cout << "Exchange " << exchange[i].n_user << "\n"; -// std::ostringstream oss; -// cxxExchange ex(&(exchange[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// cxxExchange ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// -// struct exchange *exchange_ptr = ex1.cxxExchange2exchange(); -// exchange_free(&exchange[i]); -// exchange_copy(exchange_ptr, &exchange[i], exchange_ptr->n_user); -// exchange_free(exchange_ptr); -// free_check_null(exchange_ptr); -// } -// } -// for (i = 0; i < count_surface; i++) -// { -// if (surface[i].new_def != TRUE) -// { -// std::cout << "Surface " << surface[i].n_user << "\n"; -// std::ostringstream oss; -// cxxSurface ex(&(surface[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxSurface ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// -// struct surface *surface_ptr = ex1.cxxSurface2surface(); -// surface_free(&surface[i]); -// surface_copy(surface_ptr, &surface[i], surface_ptr->n_user); -// surface_free(surface_ptr); -// free_check_null(surface_ptr); -// -// } -// -// } -// for (i = 0; i < count_pp_assemblage; i++) -// { -// if (pp_assemblage[i].new_def != TRUE) -// { -// std::cout << "PPassemblage " << pp_assemblage[i]. -// n_user << "\n"; -// std::ostringstream oss; -// cxxPPassemblage ex(&(pp_assemblage[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxPPassemblage ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// -// struct pp_assemblage *pp_assemblage_ptr = -// ex1.cxxPPassemblage2pp_assemblage(); -// pp_assemblage_free(&pp_assemblage[i]); -// pp_assemblage_copy(pp_assemblage_ptr, &pp_assemblage[i], -// pp_assemblage_ptr->n_user); -// pp_assemblage_free(pp_assemblage_ptr); -// free_check_null(pp_assemblage_ptr); -// -// } -// -// } -// for (i = 0; i < count_kinetics; i++) -// { -// std::cout << "Kinetics " << kinetics[i].n_user << "\n"; -// std::ostringstream oss; -// cxxKinetics ex(&(kinetics[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxKinetics ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// -// ex1.read_raw(cparser); -// -// struct kinetics *kinetics_ptr = ex1.cxxKinetics2kinetics(); -// kinetics_free(&kinetics[i]); -// kinetics_copy(kinetics_ptr, &kinetics[i], kinetics_ptr->n_user); -// kinetics_free(kinetics_ptr); -// free_check_null(kinetics_ptr); -// } -// for (i = 0; i < count_ss_assemblage; i++) -// { -// if (ss_assemblage[i].new_def != TRUE) -// { -// std::cout << "Solid solution " << ss_assemblage[i]. -// n_user << "\n"; -// std::ostringstream oss; -// cxxSSassemblage ex(&(ss_assemblage[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxSSassemblage ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// -// struct ss_assemblage *ss_assemblage_ptr = -// ex1.cxxSSassemblage2ss_assemblage(); -// ss_assemblage_free(&ss_assemblage[i]); -// ss_assemblage_copy(ss_assemblage_ptr, &ss_assemblage[i], -// ss_assemblage_ptr->n_user); -// ss_assemblage_free(ss_assemblage_ptr); -// free_check_null(ss_assemblage_ptr); -// -// } -// -// } -// for (i = 0; i < count_gas_phase; i++) -// { -// if (gas_phase[i].new_def != TRUE) -// { -// std::cout << "Gas phase " << gas_phase[i].n_user << "\n"; -// std::ostringstream oss; -// cxxGasPhase ex(&(gas_phase[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxGasPhase ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// -// struct gas_phase *gas_phase_ptr = ex1.cxxGasPhase2gas_phase(); -// gas_phase_free(&gas_phase[i]); -// gas_phase_copy(gas_phase_ptr, &gas_phase[i], -// gas_phase_ptr->n_user); -// gas_phase_free(gas_phase_ptr); -// free_check_null(gas_phase_ptr); -// -// } -// -// } -// for (i = 0; i < count_irrev; i++) -// { -// std::cout << "Reaction " << irrev[i].n_user << "\n"; -// std::ostringstream oss; -// cxxReaction ex(&(irrev[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxReaction ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// struct irrev *irrev_ptr = ex1.cxxReaction2irrev(); -// -// irrev_free(&irrev[i]); -// irrev_copy(irrev_ptr, &irrev[i], irrev_ptr->n_user); -// -// irrev_free(irrev_ptr); -// free_check_null(irrev_ptr); -// -// } -// for (i = 0; i < count_mix; i++) -// { -// std::cout << "Mix " << mix[i].n_user << "\n"; -// std::ostringstream oss; -// cxxMix ex(&(mix[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxMix ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// struct mix *mix_ptr = ex1.cxxMix2mix(); -// -// mix_free(&mix[i]); -// mix_copy(mix_ptr, &mix[i], mix_ptr->n_user); -// -// mix_free(mix_ptr); -// free_check_null(mix_ptr); -// -// } -// for (i = 0; i < count_temperature; i++) -// { -// std::cout << "Temperature " << temperature[i].n_user << "\n"; -// std::ostringstream oss; -// cxxTemperature ex(&(temperature[i])); -// ex.dump_raw(oss, 0); -// //std::cerr << oss.str(); -// -// -// cxxTemperature ex1; -// std::string keyInput = oss.str(); -// std::istringstream iss(keyInput); -// -// CParser cparser(iss, oss, std::cerr); -// //For testing, need to read line to get started -// std::vector < std::string > vopts; -// std::istream::pos_type next_char; -// cparser.get_option(vopts, next_char); -// -// ex1.read_raw(cparser); -// struct temperature *temperature_ptr = -// ex1.cxxTemperature2temperature(); -// -// temperature_free(&temperature[i]); -// temperature_copy(temperature_ptr, &temperature[i], -// temperature_ptr->n_user); -// -// temperature_free(temperature_ptr); -// free_check_null(temperature_ptr); -// -// } -// /* -// { -// // get all c storage -// cxxStorageBin cstorage; -// cstorage.import_phreeqc(); -// //std::ostringstream oss; -// //cstorage.dump_raw(oss, 0); -// //write it out -// std::fstream myfile; -// myfile.open("tfile", std::ios_base::out); -// cstorage.dump_raw(myfile, 0); -// myfile.close(); -// } -// { -// // empty storage bin -// cxxStorageBin cstorage; -// // fstream -// std::fstream myfile; -// myfile.open("tfile", std::ios_base::in); -// // ostream -// std::ostringstream oss; -// // parser -// CParser cparser(myfile, oss, std::cerr); -// cstorage.read_raw(cparser); -// //std::cerr << oss.str(); -// -// // read it back -// } -// */ -//} +} \ No newline at end of file diff --git a/Solution.h b/Solution.h index ebc3c836..4e34a6ed 100644 --- a/Solution.h +++ b/Solution.h @@ -7,11 +7,13 @@ #include // std::vector #include #include "NumKeyword.h" -#include "SolutionIsotopeList.h" +//#include "SolutionIsotopeList.h" +#include "SolutionIsotope.h" #include "NameDouble.h" #include "PHRQ_base.h" #include "PHRQ_io.h" #include "Phreeqc_class.h" +#include "ISolution.h" class cxxMix; class cxxSolution:public cxxNumKeyword @@ -19,139 +21,84 @@ class cxxSolution:public cxxNumKeyword public: cxxSolution(PHRQ_io *io=NULL); - cxxSolution(struct solution *, PHRQ_io *io=NULL); - cxxSolution( const std::map < int, cxxSolution > &solution_map, + cxxSolution(const cxxSolution &old_sol); + const cxxSolution & operator = (const cxxSolution &rhs); + cxxSolution(std::map < int, cxxSolution > &solution_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); - ~cxxSolution(); + virtual ~cxxSolution(); - LDBLE Get_tc() const - { - return this->tc; - } - void Set_tc(LDBLE l_tc) - { - this->tc = l_tc; - } - - LDBLE Get_ph() const - { - return this->ph; - } - void Set_ph(LDBLE pH) - { - this->ph = pH; - } - - LDBLE Get_pe() const - { - return this->pe; - } - void Set_pe(LDBLE l_pe) - { - this->pe = l_pe; - } - - LDBLE Get_mu() const - { - return this->mu; - } - void Set_mu(LDBLE l_mu) - { - this->mu = l_mu; - } - - LDBLE Get_ah2o() const - { - return this->ah2o; - } - void Set_ah2o(LDBLE l_ah2o) - { - this->ah2o = l_ah2o; - } - - LDBLE Get_total_h() const - { - return this->total_h; - } - void Set_total_h(LDBLE l_total_h) - { - this->total_h = l_total_h; - } - - LDBLE Get_total_o() const - { - return this->total_o; - } - void Set_total_o(LDBLE l_total_o) - { - this->total_o = l_total_o; - } - - LDBLE Get_cb() const - { - return this->cb; - } - void Set_cb(LDBLE l_cb) - { - this->cb = l_cb; - } - - LDBLE Get_mass_water() const - { - return this->mass_water; - } - void Set_mass_water(LDBLE l_mass_water) - { - this->mass_water = l_mass_water; - } - - LDBLE Get_total_alkalinity() const - { - return this->total_alkalinity; - } - void Set_total_alkalinity(LDBLE l_total_alkalinity) - { - this->total_alkalinity = l_total_alkalinity; - } - - LDBLE Get_total(char *string) const; - LDBLE Get_total_element(const char *string) const; - void Set_total(char *string, LDBLE value); - - const cxxNameDouble & Get_totals(void) const - { - return this->totals; - } + bool Get_new_def() const {return this->new_def;} + void Set_new_def(bool p) {this->new_def = p;} + LDBLE Get_patm() const {return this->patm;} + void Set_patm(LDBLE p) {this->patm = p;} + LDBLE Get_tc() const {return this->tc;} + void Set_tc(LDBLE l_tc) {this->tc = l_tc;} + LDBLE Get_ph() const {return this->ph;} + void Set_ph(LDBLE pH) {this->ph = pH;} + LDBLE Get_pe() const {return this->pe;} + void Set_pe(LDBLE l_pe) {this->pe = l_pe;} + LDBLE Get_mu() const {return this->mu;} + void Set_mu(LDBLE l_mu) {this->mu = l_mu;} + LDBLE Get_ah2o() const {return this->ah2o;} + void Set_ah2o(LDBLE l_ah2o) {this->ah2o = l_ah2o;} + LDBLE Get_total_h() const {return this->total_h;} + void Set_total_h(LDBLE l_total_h) {this->total_h = l_total_h;} + LDBLE Get_total_o() const {return this->total_o;} + void Set_total_o(LDBLE l_total_o) {this->total_o = l_total_o;} + LDBLE Get_cb() const {return this->cb;} + void Set_cb(LDBLE l_cb) {this->cb = l_cb;} + LDBLE Get_density() const {return this->density;} + void Set_density(LDBLE l_density) {this->density = l_density;} + LDBLE Get_mass_water() const {return this->mass_water;} + void Set_mass_water(LDBLE l_mass_water) {this->mass_water = l_mass_water;} + LDBLE Get_total_alkalinity() const {return this->total_alkalinity;} + void Set_total_alkalinity(LDBLE l_total_alkalinity) {this->total_alkalinity = l_total_alkalinity;} + cxxNameDouble & Get_totals(void) {return this->totals;} void Set_totals(cxxNameDouble & nd) { this->totals = nd; this->totals.type = cxxNameDouble::ND_ELT_MOLES; } - void clear_totals() + cxxNameDouble & Get_master_activity(void) {return this->master_activity;} + cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;} + std::map < std::string, cxxSolutionIsotope > & Get_isotopes(void) {return this->isotopes;} + void Set_isotopes(const std::map < std::string, cxxSolutionIsotope > &iso ) {this->isotopes = iso;} + cxxISolution *Get_initial_data() {return this->initial_data;} + void Set_initial_data(const cxxISolution * id) { - this->totals.clear(); + if (this->initial_data != NULL) + delete this->initial_data; + this->initial_data = new cxxISolution(*id); } - void clear_master_activity() + void Create_initial_data() { - this->master_activity.clear(); + delete initial_data; + initial_data = new cxxISolution; + } + void Destroy_initial_data() + { + delete initial_data; + initial_data = NULL; } - const cxxNameDouble & Get_master_activity(void) const - { - return this->master_activity; - } - const cxxNameDouble & Get_species_gamma(void) const - { - return this->species_gamma; - } - LDBLE Get_master_activity(char *string) const; - void Set_master_activity(char *string, LDBLE value); - const cxxSolutionIsotopeList & Get_isotopes(void) const {return isotopes;}; + void clear_totals() {this->totals.clear();} + void clear_master_activity() {this->master_activity.clear();} + + void zero(); + void add(const cxxSolution & addee, LDBLE extensive); + void Add_isotopes(const std::map < std::string, cxxSolutionIsotope > &old, LDBLE intensive, LDBLE extensive); + void multiply(LDBLE extensive); + void Multiply_isotopes(LDBLE extensive); + // not checked + void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; + LDBLE Get_master_activity(char *string) const; + void Set_master_activity(char *string, LDBLE value); + LDBLE Get_total(char *string) const; + LDBLE Get_total_element(const char *string) const; + void Set_total(char *string, LDBLE value); void read_raw(CParser & parser, bool check = true); - void multiply(LDBLE extensive); - //void modify_activities(PHREEQC_PTR_ARG_COMMA const cxxSolution & original); void modify_activities(const cxxSolution & original); void Simplify_totals(); void Update(const cxxNameDouble &nd); @@ -164,11 +111,8 @@ class cxxSolution:public cxxNumKeyword #endif protected: - void zero(); - void add(const cxxSolution & addee, LDBLE extensive); - // not checked - void dump_xml(std::ostream & os, unsigned int indent = 0) const; - + bool new_def; + LDBLE patm; LDBLE tc; LDBLE ph; LDBLE pe; @@ -178,13 +122,14 @@ class cxxSolution:public cxxNumKeyword LDBLE total_o; LDBLE cb; LDBLE mass_water; + LDBLE density; LDBLE total_alkalinity; cxxNameDouble totals; - //std::list isotopes; cxxNameDouble master_activity; cxxNameDouble species_gamma; - cxxSolutionIsotopeList isotopes; - + //cxxSolutionIsotopeList isotopes; + std::map < std::string, cxxSolutionIsotope > isotopes; + cxxISolution *initial_data; }; #endif // !defined(SOLUTION_H_INCLUDED) diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index a082f919..7ced2531 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -22,63 +22,13 @@ isotope_number(0.0) ratio = -9999.9; ratio_uncertainty = 1; ratio_uncertainty_defined = false; + x_ratio_uncertainty = 0; + coef = 0; } - -cxxSolutionIsotope::cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io) -: -PHRQ_base(io) -{ - isotope_number = isotope_ptr->isotope_number; - this->Set_elt_name(isotope_ptr->elt_name); - std::ostringstream name; - name << isotope_ptr->isotope_number << isotope_ptr->elt_name; - this->Set_isotope_name(name.str().c_str()); - total = isotope_ptr->total; - ratio = isotope_ptr->ratio; - ratio_uncertainty = isotope_ptr->ratio_uncertainty; -} - - cxxSolutionIsotope::~cxxSolutionIsotope(void) { } -#ifdef SKIP_OR_MOVE_TO_STRUCTURES -struct isotope * -cxxSolutionIsotope::list2isotope(PHREEQC_PTR_ARG_COMMA std::list < cxxSolutionIsotope > &isolist) - // takes a std::list of cxxSolutionIsotope structures - // returns array of isotope structures -{ - struct isotope *iso; - if (isolist.size() <= 0) - { - return NULL; - } - else - { - iso = - (struct isotope *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((isolist.size()) * sizeof(struct isotope))); - if (iso == NULL) - P_INSTANCE_POINTER malloc_error(); - int i = 0; - for (std::list < cxxSolutionIsotope >::iterator it = isolist.begin(); - it != isolist.end(); ++it) - { - iso[i].isotope_number = it->isotope_number; - iso[i].elt_name = P_INSTANCE_POINTER string_hsave(it->elt_name.c_str()); - iso[i].total = it->total; - iso[i].ratio = it->ratio; - iso[i].ratio_uncertainty = it->ratio_uncertainty; - iso[i].master = it->master(P_INSTANCE); - iso[i].primary = it->primary(P_INSTANCE); - i++; - } - } - return (iso); -} -#endif - void cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const { @@ -127,82 +77,197 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const std::string indent0(""); for (i = 0; i < indent; ++i) indent0.append(Utilities::INDENT); + std::string indent1 = indent0; + indent1.append(Utilities::INDENT); s_oss << indent0; - s_oss << this->isotope_name << " "; - s_oss << this->isotope_number << " "; - s_oss << this->elt_name << " "; - s_oss << this->total << " "; - s_oss << this->ratio << " "; - if (this->ratio_uncertainty != NAN) + s_oss << indent0 << "-isotope_number " << this->isotope_number << "\n"; + s_oss << indent0 << "-elt_name " << this->elt_name << "\n"; + s_oss << indent0 << "-total " << this->total << "\n"; + s_oss << indent0 << "-ratio " << this->ratio << "\n"; + s_oss << indent0 << "-ratio_uncertainty_defined " << this->ratio_uncertainty_defined << "\n"; + if (this->ratio_uncertainty_defined) { - s_oss << this->ratio_uncertainty << " "; + s_oss << indent0 << "-ratio_uncertainty " << this->ratio_uncertainty << "\n"; } - s_oss << "\n"; + s_oss << indent0 << "-x_ratio_uncertainty " << this->x_ratio_uncertainty << "\n"; + s_oss << indent0 << "-coef " << this->coef << "\n"; } - -CParser::STATUS_TYPE cxxSolutionIsotope::read_raw(CParser & parser, std::istream::pos_type next_char ) +void cxxSolutionIsotope::read_raw(CParser & parser, bool check ) { + static std::vector < std::string > vopts; + if (vopts.empty()) + { + vopts.reserve(21); + vopts.push_back("isotope_number"); // 0 + vopts.push_back("elt_name"); // 1 + vopts.push_back("total"); // 2 + vopts.push_back("ratio"); // 3 + vopts.push_back("ratio_uncertainty_defined"); // 4 + vopts.push_back("ratio_uncertainty"); // 5 + vopts.push_back("x_ratio_uncertainty"); // 6 + vopts.push_back("coef"); // 7 + } + + std::istream::pos_type ptr; + std::istream::pos_type next_char; std::string token; - CParser::TOKEN_TYPE j; + int opt_save; - // isotope_name - j = parser.copy_token(token, next_char); + opt_save = CParser::OPT_ERROR; + bool isotope_number_defined(false); + bool elt_name_defined(false); + bool total_defined(false); + bool ratio_defined(false); - if (j == CParser::TT_EMPTY) + for (;;) { - this->isotope_name.clear(); - return (CParser::PARSER_OK); - } - this->Set_isotope_name(token.c_str()); + int opt = parser.get_option(vopts, next_char); + if (opt == CParser::OPT_DEFAULT) + { + opt = opt_save; + } + + opt_save = CParser::OPT_DEFAULT; + 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 isotopes of SOLUTION_RAW keyword.", + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + continue; - // isotope_number - if (!(parser.get_iss() >> isotope_number)) - { - return CParser::PARSER_ERROR; - } + case 0: // isotope_number + if (!(parser.get_iss() >> this->isotope_number)) + { + this->isotope_number = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for isotope_number.", + PHRQ_io::OT_CONTINUE); + } + isotope_number_defined = true; + break; - // elt_name - if (!(parser.get_iss() >> token)) - { - return CParser::PARSER_ERROR; - } - this->Set_elt_name(token.c_str()); + case 1: // elt_name + if (!(parser.get_iss() >> this->elt_name)) + { + this->elt_name.clear(); + parser.incr_input_error(); + parser.error_msg("Expected character value for elt_name.", + PHRQ_io::OT_CONTINUE); + } + elt_name_defined = true; + break; - // total - if (!(parser.get_iss() >> this->total)) - { - return CParser::PARSER_ERROR; - } + case 2: // total + if (!(parser.get_iss() >> this->total)) + { + this->total = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total.", + PHRQ_io::OT_CONTINUE); + } + total_defined = true; + break; - // ratio - if (!(parser.get_iss() >> this->ratio)) - { - return CParser::PARSER_ERROR; - } + case 3: // ratio + if (!(parser.get_iss() >> this->ratio)) + { + this->ratio = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ratio.", + PHRQ_io::OT_CONTINUE); + } + total_defined = true; + break; - // ratio_uncertainty - j = parser.peek_token(); - if (j == CParser::TT_EMPTY) - { - this->ratio_uncertainty = NAN; - } - else if (j != CParser::TT_DIGIT) - { - parser.incr_input_error(); - parser. - error_msg("Expected numeric value for mass of water in solution.", - PHRQ_io::OT_CONTINUE); - } - else - { - parser.get_iss() >> this->ratio_uncertainty; - this->ratio_uncertainty_defined = true; - } + case 4: // ratio_uncertainty_defined + if (!(parser.get_iss() >> this->ratio_uncertainty_defined)) + { + this->ratio_uncertainty_defined = 0; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for ratio_uncertainty_defined.", + PHRQ_io::OT_CONTINUE); + } + break; - return CParser::PARSER_OK; + case 5: // ratio_uncertainty + if (!(parser.get_iss() >> this->ratio_uncertainty)) + { + this->ratio_uncertainty = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ratio_uncertainty.", + PHRQ_io::OT_CONTINUE); + } + ratio_uncertainty_defined = true; + break; + + case 6: // x_ratio_uncertainty + if (!(parser.get_iss() >> this->x_ratio_uncertainty)) + { + this->x_ratio_uncertainty = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for x_ratio_uncertainty.", + PHRQ_io::OT_CONTINUE); + } + break; + case 7: // coef + if (!(parser.get_iss() >> this->coef)) + { + this->coef = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for coef.", + PHRQ_io::OT_CONTINUE); + } + break; + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + if (check) + { + // all members must be defined + if (isotope_number_defined == false) + { + parser.incr_input_error(); + parser.error_msg("isotope_number not defined for isotopes SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (elt_name_defined == false) + { + parser.incr_input_error(); + parser.error_msg("elt_name not defined for isotopes SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (total_defined == false) + { + parser.incr_input_error(); + parser.error_msg("total not defined for isotopes SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (ratio_defined == false) + { + parser.incr_input_error(); + parser.error_msg("ratio not defined for isotopes SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (ratio_uncertainty_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("ratio_uncertainty not defined for isotopes SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + } + return; } - bool cxxSolutionIsotope::operator<(const cxxSolutionIsotope & isotope) const { @@ -234,70 +299,3 @@ cxxSolutionIsotope::multiply(LDBLE extensive) this->total *= extensive; } -#ifdef SKIP -cxxSolutionIsotope::STATUS cxxSolutionIsotope::read(CParser & parser) -{ - if (!(parser.get_iss() >> this->isotope_number)) - { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected isotope name to" - " begin with an isotopic number.", - PHRQ_io::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - - // read and save element name - std::istringstream::int_type c = parser.get_iss().peek(); - if (c == std::char_traits < char >::eof() || !(::isupper(c))) - { - parser.error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - parser.incr_input_error(); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - if (!(parser.get_iss() >> this->elt_name)) - { - // should never get here - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - assert(!this->elt_name.empty() &&::isupper(this->elt_name[0])); - - // read and store isotope ratio - if (!(parser.get_iss() >> this->ratio)) - { - assert(parser.get_iss().fail()); - parser.incr_input_error(); - parser.error_msg("Expected numeric value for isotope ratio.", - PHRQ_io::OT_CONTINUE); - return ERROR; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - - // read and store isotope ratio - this->ratio_uncertainty_defined = false; - if (!(parser.get_iss() >> this->ratio_uncertainty)) - { - if (!parser.get_iss().eof()) - { - parser.incr_input_error(); - parser. - error_msg - ("Expected numeric value for uncertainty in isotope ratio.", - PHRQ_io::OT_CONTINUE); - return ERROR; - } - } - else - { - this->ratio_uncertainty_defined = true; - } - assert(parser.get_iss().good() || parser.get_iss().eof()); - return OK; -} - - -#endif diff --git a/SolutionIsotope.h b/SolutionIsotope.h index ab698914..b8cf73ae 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -11,12 +11,13 @@ class cxxSolutionIsotope: public PHRQ_base public: cxxSolutionIsotope(PHRQ_io *io=NULL); cxxSolutionIsotope(struct isotope *isotope_ptr, PHRQ_io *io=NULL); - ~cxxSolutionIsotope(void); + virtual ~cxxSolutionIsotope(void); void dump_xml(std::ostream & os, unsigned int indent) const; void dump_raw(std::ostream & os, unsigned int indent) const; - CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type next_char); + //CParser::STATUS_TYPE read_raw(CParser & parser, std::istream::pos_type next_char); + void read_raw(CParser & parser, bool check); LDBLE Get_isotope_number() const { @@ -26,10 +27,7 @@ class cxxSolutionIsotope: public PHRQ_base { this->isotope_number = d; } - const std::string &Get_elt_name() const - { - return this->elt_name; - } + const std::string &Get_elt_name() const {return this->elt_name;} void Set_elt_name(const char *cstring) { if (cstring != NULL) @@ -37,10 +35,8 @@ class cxxSolutionIsotope: public PHRQ_base else this->elt_name.clear(); } - const std::string &Get_isotope_name() const - { - return this->isotope_name; - } + + const std::string &Get_isotope_name() const {return this->isotope_name;} void Set_isotope_name(const char *cstring) { if (cstring != NULL) @@ -48,29 +44,23 @@ class cxxSolutionIsotope: public PHRQ_base else this->isotope_name.clear(); } - LDBLE Get_total() const - { - return this->total; - } - void Set_total(LDBLE d) - { - this->total = d; - } - LDBLE Get_ratio() const - { - return this->ratio; - } + LDBLE Get_total() const {return this->total;} + void Set_total(LDBLE d) {this->total = d;} - LDBLE Get_ratio_uncertainty() const - { - return this->ratio_uncertainty; - } + LDBLE Get_ratio() const {return this->ratio;} + void Set_ratio(LDBLE t) {this->ratio = t;} - bool Get_ratio_uncertainty_defined() const - { - return this->ratio_uncertainty_defined; - } + LDBLE Get_ratio_uncertainty() const {return this->ratio_uncertainty;} + void Set_ratio_uncertainty(LDBLE t) {this->ratio_uncertainty = t;} + + LDBLE Get_x_ratio_uncertainty() const {return this->x_ratio_uncertainty;} + void Set_x_ratio_uncertainty(LDBLE t) {this->x_ratio_uncertainty = t;} + + bool Get_ratio_uncertainty_defined() const {return this->ratio_uncertainty_defined;} + void Set_ratio_uncertainty_defined(bool tf) {this->ratio_uncertainty_defined = tf;} + LDBLE Get_coef() const {return this->coef;} + void Set_coef(LDBLE t) {this->coef = t;} bool operator<(const cxxSolutionIsotope & conc) const; void add(const cxxSolutionIsotope & isotope_ptr, LDBLE intensive, @@ -78,7 +68,6 @@ class cxxSolutionIsotope: public PHRQ_base void multiply(LDBLE extensive); protected: - friend class cxxSolutionIsotopeList; LDBLE isotope_number; std::string elt_name; std::string isotope_name; @@ -86,5 +75,7 @@ class cxxSolutionIsotope: public PHRQ_base LDBLE ratio; LDBLE ratio_uncertainty; bool ratio_uncertainty_defined; + LDBLE x_ratio_uncertainty; + LDBLE coef; /* coefficient of element in phase */ }; #endif // SOLUTIONISOTOPE_H_INCLUDED diff --git a/SolutionIsotopeList.cxx b/SolutionIsotopeList.cxx deleted file mode 100644 index e90417d7..00000000 --- a/SolutionIsotopeList.cxx +++ /dev/null @@ -1,86 +0,0 @@ -#include "Utils.h" // define first -#include // assert -#include // std::sort - -#include "Phreeqc.h" -#include "SolutionIsotopeList.h" -#include "phqalloc.h" - - - -cxxSolutionIsotopeList::cxxSolutionIsotopeList(PHRQ_io * io) -: -PHRQ_base(io) - // - // default constructor for cxxSolution - // -{ -} - -cxxSolutionIsotopeList::cxxSolutionIsotopeList(struct solution *solution_ptr, PHRQ_io * io) -: -PHRQ_base(io) -{ - int i; - // Isotopes - for (i = 0; i < solution_ptr->count_isotopes; i++) - { - cxxSolutionIsotope iso(&solution_ptr->isotopes[i], this->Get_io()); - (*this).push_back(iso); - } -} - -cxxSolutionIsotopeList::~cxxSolutionIsotopeList() - // - // default destructor for cxxSolution - // -{ -} -void -cxxSolutionIsotopeList::add(cxxSolutionIsotopeList old, LDBLE intensive, - LDBLE extensive) -{ - for (cxxSolutionIsotopeList::const_iterator itold = old.begin(); - itold != old.end(); ++itold) - { - //for (std::list ::const_iterator itold = old.isotopes.begin(); itold != old.isotopes.end(); ++itold) { - bool found = false; - for (cxxSolutionIsotopeList::iterator it = this->begin(); - it != this->end(); ++it) - { - //for (std::list ::iterator it = this->isotopes.begin(); it != this->isotopes.end(); ++it) { - if ((it->isotope_number == itold->isotope_number) && - (it->elt_name == itold->elt_name) && - (it->isotope_name == itold->isotope_name)) - { - it->total += itold->total * extensive; - it->ratio += itold->ratio * intensive; - it->ratio_uncertainty += itold->ratio_uncertainty * intensive; - it->ratio_uncertainty_defined = (it->ratio_uncertainty_defined - || itold-> - ratio_uncertainty_defined); - found = true; - break; - } - } - if (!found) - { - cxxSolutionIsotope iso(this->Get_io()); - iso.total = itold->total * extensive; - iso.ratio = itold->ratio * intensive; - iso.ratio_uncertainty = itold->ratio_uncertainty * intensive; - iso.ratio_uncertainty_defined = itold->ratio_uncertainty_defined; - this->push_back(iso); - } - } -} -void -cxxSolutionIsotopeList::multiply(LDBLE extensive) -{ - for (cxxSolutionIsotopeList::iterator it = this->begin(); - it != this->end(); ++it) - { - it->total *= extensive; - } -} - diff --git a/SolutionIsotopeList.h b/SolutionIsotopeList.h deleted file mode 100644 index aff54b89..00000000 --- a/SolutionIsotopeList.h +++ /dev/null @@ -1,32 +0,0 @@ -#if !defined(SOLUTIONISOTOPELIST_H_INCLUDED) -#define SOLUTIONISOTOPELIST_H_INCLUDED - -#include // assert -#include // std::string -#include // std::list - -#include "SolutionIsotope.h" - -class cxxSolutionIsotopeList:public - std::list < cxxSolutionIsotope >, public PHRQ_base -{ - -public: - cxxSolutionIsotopeList(PHRQ_io *io=NULL); - - cxxSolutionIsotopeList(struct solution *solution_ptr, PHRQ_io *io=NULL); - - ~cxxSolutionIsotopeList(); - - void add(cxxSolutionIsotopeList oldlist, LDBLE intensive, LDBLE extensive); - void multiply(LDBLE extensive); - -protected: - - -public: - - -}; - -#endif // !defined(SOLUTIONISOTOPELIST_H_INCLUDED) diff --git a/StorageBin.cxx b/StorageBin.cxx index 7f75d2d0..b09b440e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -363,7 +363,6 @@ cxxStorageBin::Get_Pressures() const void cxxStorageBin::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -399,8 +398,6 @@ void cxxStorageBin::dump_raw(std::ostream & s_oss, unsigned int indent) const { // Dump all data - - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; s_oss.precision(DBL_DIG - 1); // Solutions @@ -439,7 +436,6 @@ cxxStorageBin::dump_raw(std::ostream & s_oss, int n, unsigned int indent, int *n { // Dump one user number, optionally change number from n to n_out int n_user_local = (n_out != NULL) ? *n_out : n; - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; s_oss.precision(DBL_DIG - 1); // Solutions @@ -519,25 +515,10 @@ cxxStorageBin::read_raw(CParser & parser) { switch (parser.next_keyword()) { - //case CParser::KT_END: - //case CParser::KT_EOF: - //case CParser::KT_NONE: case Keywords::KEY_END: case Keywords::KEY_NONE: goto END_OF_SIMULATION_INPUT; break; - /* - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11, - KT_TEMPERATURE_RAW = 12, - KT_REACTION_RAW = 13 - */ - //case CParser::KT_SOLUTION_RAW: case Keywords::KEY_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); @@ -545,8 +526,6 @@ cxxStorageBin::read_raw(CParser & parser) Solutions[entity.Get_n_user()] = entity; } break; - - //case CParser::KT_EXCHANGE_RAW: case Keywords::KEY_EXCHANGE_RAW: { cxxExchange entity(this->Get_io()); @@ -554,8 +533,6 @@ cxxStorageBin::read_raw(CParser & parser) Exchangers[entity.Get_n_user()] = entity; } break; - - //case CParser::KT_GASPHASE_RAW: case Keywords::KEY_GAS_PHASE_RAW: { cxxGasPhase entity(this->Get_io()); @@ -563,8 +540,6 @@ cxxStorageBin::read_raw(CParser & parser) GasPhases[entity.Get_n_user()] = entity; } break; - - //case CParser::KT_KINETICS_RAW: case Keywords::KEY_KINETICS_RAW: { cxxKinetics entity(this->Get_io()); @@ -636,8 +611,6 @@ cxxStorageBin::read_raw_keyword(CParser & parser) switch (parser.next_keyword()) { - //case CParser::KT_NONE: - //case CParser::KT_END: case Keywords::KEY_NONE: case Keywords::KEY_END: while ((i = @@ -648,19 +621,7 @@ cxxStorageBin::read_raw_keyword(CParser & parser) break; // PHRQ_io::LT_EOF; } break; - /*case CParser::KT_EOF: - break;*/ - /* - KT_SOLUTION_RAW = 5, - KT_EXCHANGE_RAW = 6, - KT_GASPHASE_RAW = 7, - KT_KINETICS_RAW = 8, - KT_PPASSEMBLAGE_RAW = 9, - KT_SSASSEMBLAGE_RAW = 10, - KT_SURFACE_RAW = 11, - KT_TEMPERATURE_RAW = 12, - KT_REACTION_RAW = 13 - */ + case Keywords::KEY_SOLUTION_RAW: { cxxSolution entity(this->Get_io()); @@ -757,71 +718,6 @@ cxxStorageBin::read_raw_keyword(CParser & parser) return (entity_number); //PHRQ_io::LT_OK; } -//void -//cxxStorageBin::add(struct system *system_ptr) -// // -// // add data from a system structure -// // -//{ -// -// // Solutions -// if (system_ptr->solution != NULL) -// { -// this->Solutions[system_ptr->solution->n_user] = -// cxxSolution(system_ptr->solution, this->Get_io()); -// } -// -// // Exchangers -// if (system_ptr->exchange != NULL) -// { -// this->Exchangers[system_ptr->exchange->n_user] = -// cxxExchange(system_ptr->exchange, this->Get_io()); -// } -// -// // GasPhases -// if (system_ptr->gas_phase != NULL) -// { -// this->GasPhases[system_ptr->gas_phase->n_user] = -// cxxGasPhase(system_ptr->gas_phase, this->Get_io()); -// } -// -// // Kinetics -// if (system_ptr->kinetics != NULL) -// { -// this->Kinetics[system_ptr->kinetics->n_user] = -// cxxKinetics(system_ptr->kinetics, this->Get_io()); -// } -// -// // PPassemblages -// if (system_ptr->pp_assemblage != NULL) -// { -// this->PPassemblages[system_ptr->pp_assemblage->n_user] = -// cxxPPassemblage(system_ptr->pp_assemblage, this->Get_io()); -// } -// -// // SSassemblages -// if (system_ptr->ss_assemblage != NULL) -// { -// this->SSassemblages[system_ptr->ss_assemblage->n_user] = -// cxxSSassemblage(system_ptr->ss_assemblage); -// } -// -// // Surfaces -// if (system_ptr->surface != NULL) -// { -// this->Surfaces[system_ptr->surface->n_user] = -// cxxSurface(system_ptr->surface, this->Get_io()); -// } -// -// // struct system not used -// //// Mixes -// //if (system_ptr->mix != NULL) -// //{ -// // this->Mixes[system_ptr->mix->n_user] = -// // cxxMix(system_ptr->mix, this->Get_io()); -// //} -//} - void cxxStorageBin::Remove(int n) { @@ -878,6 +774,7 @@ cxxStorageBin::Clear(void) // PPassemblage this->PPassemblages.clear(); + // SSassemblage this->SSassemblages.clear(); // Surface @@ -894,7 +791,6 @@ cxxStorageBin::Clear(void) // Pressure this->Pressures.clear(); - } #ifdef SKIP cxxSolution * @@ -1169,11 +1065,9 @@ cxxStorageBin::mpi_send(int n, int task_number) int position = 0; MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - //MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - //MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); if (d > 0) { MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, diff --git a/StorageBin.h b/StorageBin.h index 65565675..b701ed71 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -25,7 +25,7 @@ class cxxStorageBin: public PHRQ_base public: cxxStorageBin(PHRQ_io *io=NULL); - ~cxxStorageBin(); + virtual ~cxxStorageBin(); void Remove(int n); void Clear(void); @@ -120,10 +120,6 @@ class cxxStorageBin: public PHRQ_base std::map < int, cxxSSassemblage > SSassemblages; std::map < int, cxxSurface > Surfaces; - //bool b = exists (Solutions, 5); - // Initial classes - //std::map ISolutions; - // Reaction classes std::map < int, cxxMix > Mixes; std::map < int, cxxReaction > Reactions; diff --git a/StorageBinList.cpp b/StorageBinList.cpp index b5d52991..b4c5dfb4 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -32,13 +32,6 @@ StorageBinListItem::StorageBinListItem(CParser & parser) { break; } - else - { - // ignore characters like RUN - //parser.error_msg("Expected single number or range of numbers.", - // PHRQ_io::OT_CONTINUE); - //break; - } } } } diff --git a/StorageBinList.h b/StorageBinList.h index a60c021a..cf2ce771 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -28,7 +28,7 @@ class StorageBinList: public PHRQ_base public: StorageBinList(PHRQ_io *io=NULL); StorageBinList(CParser & parser, PHRQ_io *io=NULL); - ~StorageBinList(void); + virtual ~StorageBinList(void); bool Read(CParser & parser); void SetAll(bool tf); void TransferAll(StorageBinListItem &source); diff --git a/Surface.cxx b/Surface.cxx index 3340026a..26d23d72 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -24,65 +24,25 @@ cxxSurface::cxxSurface(PHRQ_io *io) // : cxxNumKeyword(io) { + new_def = false; type = DDL; dl_type = NO_DL; sites_units = SITES_ABSOLUTE; - //diffuse_layer = false; - //edl = false; only_counter_ions = false; - //donnan = false; thickness = 1e-8; debye_lengths = 0.0; DDL_viscosity = 1.0; DDL_limit = 0.8; transport = false; + solution_equilibria = false; + n_solution = -999; } - -cxxSurface::cxxSurface(struct surface *surface_ptr, PHRQ_io *io) - // - // constructor for cxxSurface from struct surface - // - : -cxxNumKeyword(io) -{ - int i; - - this->Set_description(surface_ptr->description); - n_user = surface_ptr->n_user; - n_user_end = surface_ptr->n_user_end; - type = surface_ptr->type; - dl_type = surface_ptr->dl_type; - sites_units = surface_ptr->sites_units; - //diffuse_layer = (surface_ptr->diffuse_layer == TRUE); - //edl = (surface_ptr->edl == TRUE); - only_counter_ions = (surface_ptr->only_counter_ions == TRUE); - //donnan = (surface_ptr->donnan == TRUE); - thickness = surface_ptr->thickness; - debye_lengths = surface_ptr->debye_lengths; - DDL_viscosity = surface_ptr->DDL_viscosity; - DDL_limit = surface_ptr->DDL_limit; - transport = (surface_ptr->transport == TRUE); - // Surface components - for (i = 0; i < surface_ptr->count_comps; i++) - { - cxxSurfaceComp ec(&(surface_ptr->comps[i]), this->Get_io()); - std::string str(ec.Get_formula()); - surfaceComps[str] = ec; - } - // Surface charge - for (i = 0; i < surface_ptr->count_charge; i++) - { - cxxSurfaceCharge ec(&(surface_ptr->charge[i]), this->Get_io()); - std::string str(ec.Get_name()); - surfaceCharges[str] = ec; - } -} - -cxxSurface::cxxSurface(const std::map < int, cxxSurface > &entities, +cxxSurface::cxxSurface(std::map < int, cxxSurface > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; + this->new_def = false; type = DDL; dl_type = NO_DL; sites_units = SITES_ABSOLUTE; @@ -92,8 +52,10 @@ cxxNumKeyword(io) DDL_viscosity = 1.0; DDL_limit = 0.8; transport = false; + solution_equilibria = false; + n_solution = -999; // -// Mix exchangers +// Mix surfaces // const std::map < int, LDBLE >&mixcomps = mix.Get_mixComps(); std::map < int, LDBLE >::const_iterator it; @@ -101,9 +63,7 @@ cxxNumKeyword(io) { if (entities.find(it->first) != entities.end()) { - const cxxSurface *entity_ptr = - &(entities.find(it->first)->second); - this->add(*entity_ptr, it->second); + this->add(entities.find(it->first)->second, it->second); } } } @@ -115,10 +75,9 @@ cxxSurface::~cxxSurface() bool cxxSurface::Get_related_phases() const { - for (std::map < std::string, cxxSurfaceComp >::const_iterator it = - this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + for (size_t i = 0; i != this->surface_comps.size(); i++) { - if ((*it).second.Get_phase_name().size() == 0) + if (this->surface_comps[i].Get_phase_name().size() == 0) continue; return (true); } @@ -128,20 +87,18 @@ cxxSurface::Get_related_phases() const bool cxxSurface::Get_related_rate() const { - for (std::map < std::string, cxxSurfaceComp >::const_iterator it = - this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) + for (size_t i = 0; i != this->surface_comps.size(); i++) { - if ((*it).second.Get_rate_name().size() == 0) + if (this->surface_comps[i].Get_rate_name().size() == 0) continue; return (true); } return (false); } - +#ifdef SKIP void cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -157,11 +114,9 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << "diffuse_layer << "\"" << "\n"; s_oss << "surface_type=\"" << this->type << "\"" << "\n"; s_oss << indent1; - //s_oss << "edl=\"" << this->edl << "\"" << "\n"; s_oss << "dl_type=\"" << this->dl_type << "\"" << "\n"; s_oss << indent1; @@ -171,9 +126,6 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << "only_counter_ions=\"" << this-> only_counter_ions << "\"" << "\n"; - //s_oss << indent1; - //s_oss << "donnan=\"" << this->donnan << "\"" << "\n"; - s_oss << indent1; s_oss << "thickness=\"" << this->thickness << "\"" << "\n"; @@ -203,18 +155,17 @@ cxxSurface::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "::const_iterator it = - surfaceCharges.begin(); it != surfaceCharges.end(); ++it) + surface_charges.begin(); it != surface_charges.end(); ++it) { (*it).second.dump_xml(s_oss, indent + 2); } return; } - +#endif void cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing surface message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -228,59 +179,56 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons // Surface element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << "\n"; - + s_oss << "SURFACE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << indent1 << "# SURFACE_MODIFY candidate identifiers #\n"; s_oss << indent1; - //s_oss << "-diffuse_layer " << this->diffuse_layer << "\n"; - s_oss << "-type " << this->type << "\n"; - + s_oss << "-type " << this->type << "\n"; s_oss << indent1; - //s_oss << "-edl " << this->edl << "\n"; - s_oss << "-dl_type " << this->dl_type << "\n"; - + s_oss << "-dl_type " << this->dl_type << "\n"; s_oss << indent1; - s_oss << "-sites_units " << this->sites_units << "\n"; - + s_oss << "-only_counter_ions " << this->only_counter_ions << "\n"; s_oss << indent1; - s_oss << "-only_counter_ions " << this->only_counter_ions << "\n"; - - //s_oss << indent1; - //s_oss << "-donnan " << this->donnan << "\n"; - + s_oss << "-thickness " << this->thickness << "\n"; s_oss << indent1; - s_oss << "-thickness " << this->thickness << "\n"; - + s_oss << "-debye_lengths " << this->debye_lengths << "\n"; s_oss << indent1; - s_oss << "-debye_lengths " << this->debye_lengths << "\n"; - + s_oss << "-DDL_viscosity " << this->DDL_viscosity << "\n"; s_oss << indent1; - s_oss << "-DDL_viscosity " << this->DDL_viscosity << "\n"; - - s_oss << indent1; - s_oss << "-DDL_limit " << this->DDL_limit << "\n"; - - s_oss << indent1; - s_oss << "-transport " << this->transport << "\n"; - - // surfaceComps structures - for (std::map < std::string, cxxSurfaceComp >::const_iterator it = - surfaceComps.begin(); it != surfaceComps.end(); ++it) + s_oss << "-DDL_limit " << this->DDL_limit << "\n"; + // surfaceComps + for (size_t i = 0; i != this->surface_comps.size(); i++) { + const cxxSurfaceComp * comp_ptr = &(this->surface_comps[i]); s_oss << indent1; - s_oss << "-component" << "\n"; - (*it).second.dump_raw(s_oss, indent + 2); + s_oss << "-component " << comp_ptr->Get_formula() << "\n"; + comp_ptr->dump_raw(s_oss, indent + 2); } - // surface charge structures + // surface charge + for (size_t i = 0; i != this->surface_charges.size(); i++) { - for (std::map < std::string, cxxSurfaceCharge >::const_iterator it = - surfaceCharges.begin(); it != surfaceCharges.end(); ++it) - { - s_oss << indent1; - s_oss << "-charge_component " << "\n"; - (*it).second.dump_raw(s_oss, indent + 2); - } + const cxxSurfaceCharge * charge_ptr = &(this->surface_charges[i]); + s_oss << indent1; + s_oss << "-charge_component " << charge_ptr->Get_name() << "\n"; + charge_ptr->dump_raw(s_oss, indent + 2); } + s_oss << indent1 << "# SURFACE_MODIFY candidates with new_def=true #\n"; + s_oss << indent1; + s_oss << "-new_def " << this->new_def << "\n"; + s_oss << indent1; + s_oss << "-sites_units " << this->sites_units << "\n"; + s_oss << indent1; + s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; + s_oss << indent1; + s_oss << "-n_solution " << this->n_solution << "\n"; + + s_oss << indent1 << "# Surface workspace variables #\n"; + s_oss << indent1; + s_oss << "-transport " << this->transport << "\n"; + s_oss << indent1; + s_oss << "-totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 2); + return; } @@ -306,6 +254,10 @@ cxxSurface::read_raw(CParser & parser, bool check) vopts.push_back("ddl_viscosity"); // 11 vopts.push_back("ddl_limit"); // 12 vopts.push_back("transport"); // 13 + vopts.push_back("new_def"); // 14 + vopts.push_back("solution_equilibria"); // 15 + vopts.push_back("n_solution"); // 16 + vopts.push_back("totals"); // 17 } std::istream::pos_type ptr; @@ -318,10 +270,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->read_number_description(parser); opt_save = CParser::OPT_ERROR; - //bool diffuse_layer_defined(false); - //bool edl_defined(false); bool only_counter_ions_defined(false); - //bool donnan_defined(false); bool thickness_defined(false); bool type_defined(false); bool dl_type_defined(false); @@ -342,6 +291,7 @@ cxxSurface::read_raw(CParser & parser, bool check) { opt = parser.getOptionFromLastLine(vopts, next_char, true); } + useLastLine = false; switch (opt) { case CParser::OPT_EOF: @@ -354,39 +304,18 @@ cxxSurface::read_raw(CParser & parser, bool check) parser.error_msg("Unknown input in SURFACE keyword.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; break; case 0: // diffuse_layer parser.incr_input_error(); parser.error_msg("Diffuse layer is obsolete, use -type.", PHRQ_io::OT_CONTINUE); - /* - if (!(parser.get_iss() >> this->diffuse_layer)) - { - this->diffuse_layer = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for diffuse_layer.", PHRQ_io::OT_CONTINUE); - } - diffuse_layer_defined = true; - */ - useLastLine = false; break; case 1: // edl parser.incr_input_error(); parser.error_msg("-edl is obsolete, use -type.", PHRQ_io::OT_CONTINUE); - /* - if (!(parser.get_iss() >> this->edl)) - { - this->edl = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for edl.", PHRQ_io::OT_CONTINUE); - } - edl_defined = true; - */ - useLastLine = false; break; case 2: // only_counter_ions @@ -399,23 +328,12 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } only_counter_ions_defined = true; - useLastLine = false; break; case 3: // donnan parser.incr_input_error(); parser.error_msg("-Donnan is obsolete, use -dl_type.", PHRQ_io::OT_CONTINUE); - /* - if (!(parser.get_iss() >> this->donnan)) - { - this->donnan = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for donnan.", PHRQ_io::OT_CONTINUE); - } - donnan_defined = true; - */ - useLastLine = false; break; case 4: // thickness @@ -427,62 +345,80 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } thickness_defined = true; - useLastLine = false; break; - case 5: // component { - cxxSurfaceComp ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - if (this->surfaceComps.find(ec.Get_formula()) != this->surfaceComps.end()) + std::string str; + if (!(parser.get_iss() >> str)) { - cxxSurfaceComp & comp = this->surfaceComps.find(ec.Get_formula())->second; - comp.read_raw(reread, false); + parser.incr_input_error(); + parser.error_msg("Expected string value for component name.", + PHRQ_io::OT_CONTINUE); } else { - cxxSurfaceComp ec1(this->Get_io()); - ec1.read_raw(reread, false); - std::string str(ec1.Get_formula()); - this->surfaceComps[str] = ec1; + cxxSurfaceComp temp_comp(this->io); + temp_comp.Set_formula(str.c_str()); + cxxSurfaceComp *comp_ptr = this->Find_comp(str); + if (comp_ptr) + { + temp_comp = *comp_ptr; + } + temp_comp.read_raw(parser, check); + if (comp_ptr) + { + for (size_t j = 0; j < this->surface_comps.size(); j++) + { + if (Utilities::strcmp_nocase(this->surface_comps[j].Get_formula().c_str(), str.c_str()) == 0) + { + this->surface_comps[j] = temp_comp; + } + } + } + else + { + this->surface_comps.push_back(temp_comp); + } + useLastLine = true; } } - useLastLine = true; break; - case 6: // charge_component { - cxxSurfaceCharge ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - if (this->surfaceCharges.find(ec.Get_name()) != this->surfaceCharges.end()) + std::string str; + if (!(parser.get_iss() >> str)) { - cxxSurfaceCharge & comp = this->surfaceCharges.find(ec.Get_name())->second; - comp.read_raw(reread, false); + parser.incr_input_error(); + parser.error_msg("Expected string value for charge name.", + PHRQ_io::OT_CONTINUE); } else { - cxxSurfaceCharge ec1(this->Get_io()); - ec1.read_raw(reread, false); - std::string str(ec1.Get_name()); - this->surfaceCharges[str] = ec1; + cxxSurfaceCharge temp_charge(this->io); + temp_charge.Set_name(str.c_str()); + cxxSurfaceCharge *charge_ptr = this->Find_charge(str); + if (charge_ptr) + { + temp_charge = *charge_ptr; + } + temp_charge.read_raw(parser, check); + if (charge_ptr) + { + for (size_t j = 0; j < this->surface_charges.size(); j++) + { + if (Utilities::strcmp_nocase(this->surface_charges[j].Get_name().c_str(), str.c_str()) == 0) + { + this->surface_charges[j] = temp_charge; + } + } + } + else + { + this->surface_charges.push_back(temp_charge); + } + useLastLine = true; } - } + } useLastLine = true; break; case 7: // type @@ -496,7 +432,6 @@ cxxSurface::read_raw(CParser & parser, bool check) } this->type = (SURFACE_TYPE) i; type_defined = true; - useLastLine = false; break; case 8: // dl_type i = 0; @@ -509,7 +444,6 @@ cxxSurface::read_raw(CParser & parser, bool check) } this->dl_type = (DIFFUSE_LAYER_TYPE) i; dl_type_defined = true; - useLastLine = false; break; case 9: // sites_units i = 0; @@ -522,7 +456,6 @@ cxxSurface::read_raw(CParser & parser, bool check) } this->sites_units = (SITES_UNITS) i; sites_units_defined = true; - useLastLine = false; break; case 10: // debye_lengths @@ -534,7 +467,6 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } debye_lengths_defined = true; - useLastLine = false; break; case 11: // DDL_viscosity @@ -546,7 +478,6 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } DDL_viscosity_defined = true; - useLastLine = false; break; case 12: // DDL_limit @@ -558,7 +489,6 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } DDL_limit_defined = true; - useLastLine = false; break; case 13: // transport @@ -570,26 +500,55 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } transport_defined = true; - useLastLine = false; + break; + + case 14: // new_def + if (!(parser.get_iss() >> this->new_def)) + { + this->new_def = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for new_def.", + PHRQ_io::OT_CONTINUE); + } + break; + + case 15: // new_def + if (!(parser.get_iss() >> this->solution_equilibria)) + { + this->solution_equilibria = false; + parser.incr_input_error(); + parser.error_msg("Expected boolean value for solution_equilibria.", + PHRQ_io::OT_CONTINUE); + } + break; + + case 16: // n_solution + if (!(parser.get_iss() >> this->n_solution)) + { + this->n_solution = -999; + parser.incr_input_error(); + parser.error_msg("Expected integer value for n_solution.", + PHRQ_io::OT_CONTINUE); + } + break; + case 17: // totals + if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected element name and molality for Surface totals.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 17; break; } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } if (check) { // members that must be defined - /* - if (diffuse_layer_defined == false) { - parser.incr_input_error(); - parser.error_msg("Diffuse_layer not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); - } - if (edl_defined == false) { - parser.incr_input_error(); - parser.error_msg("Edl not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); - } - */ if (only_counter_ions_defined == false) { parser.incr_input_error(); @@ -597,12 +556,6 @@ cxxSurface::read_raw(CParser & parser, bool check) error_msg("Only_counter_ions not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); } - /* - if (donnan_defined == false) { - parser.incr_input_error(); - parser.error_msg("Donnan not defined for SURFACE_RAW input.", PHRQ_io::OT_CONTINUE); - } - */ if (thickness_defined == false) { parser.incr_input_error(); @@ -652,6 +605,7 @@ cxxSurface::read_raw(CParser & parser, bool check) PHRQ_io::OT_CONTINUE); } } + this->Sort_comps(); } #ifdef USE_MPI @@ -668,20 +622,17 @@ cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) { (*it).second.mpi_pack(ints, doubles); } - ints.push_back((int) this->surfaceCharges.size()); + ints.push_back((int) this->surface_charges.size()); for (std::map < std::string, cxxSurfaceCharge >::iterator it = - this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) + this->surface_charges.begin(); it != this->surface_charges.end(); it++) { (*it).second.mpi_pack(ints, doubles); } - //ints.push_back((int) this->diffuse_layer); - //ints.push_back((int) this->edl); ints.push_back((int) this->type); ints.push_back((int) this->dl_type); ints.push_back((int) this->sites_units); ints.push_back((int) this->only_counter_ions); - //ints.push_back((int) this->donnan); doubles.push_back(this->thickness); doubles.push_back(this->debye_lengths); doubles.push_back(this->DDL_viscosity); @@ -696,7 +647,6 @@ cxxSurface::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { int i = *ii; int d = *dd; - /* int n_user; */ this->n_user = ints[i++]; this->n_user_end = this->n_user; this->description = " "; @@ -711,21 +661,18 @@ cxxSurface::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) this->surfaceComps[str] = sc; } count = ints[i++]; - this->surfaceCharges.clear(); + this->surface_charges.clear(); for (int n = 0; n < count; n++) { cxxSurfaceCharge sc; sc.mpi_unpack(ints, &i, doubles, &d); std::string str(sc.get_name()); - this->surfaceCharges[str] = sc; + this->surface_charges[str] = sc; } - //this->diffuse_layer = (bool) ints[i++]; - //this->edl = (bool) ints[i++]; this->type = (SURFACE_TYPE) ints[i++]; this->dl_type = (DIFFUSE_LAYER_TYPE) ints[i++]; this->sites_units = (SITES_UNITS) ints[i++]; this->only_counter_ions = (ints[i++] == TRUE); - //this->donnan = (bool) ints[i++]; this->thickness = doubles[d++]; this->debye_lengths = doubles[d++]; this->DDL_viscosity = doubles[d++]; @@ -741,80 +688,152 @@ cxxSurface::totalize() { this->totals.clear(); // component structures - for (std::map < std::string, cxxSurfaceComp >::const_iterator it = - surfaceComps.begin(); it != surfaceComps.end(); ++it) + for (size_t i = 0; i != this->surface_comps.size(); i++) { - this->totals.add_extensive((*it).second.Get_totals(), 1.0); - this->totals.add("Charge", (*it).second.Get_charge_balance()); + cxxSurfaceComp * comp_ptr = &(this->surface_comps[i]); + this->totals.add_extensive(comp_ptr->Get_totals(), 1.0); + this->totals.add("Charge", comp_ptr->Get_charge_balance()); } return; } - void -cxxSurface::add(const cxxSurface & addee, LDBLE extensive) +cxxSurface::add(const cxxSurface & addee_in, LDBLE extensive) // - // Add surface to "this" exchange + // Add surface to "this" surface // { + cxxSurface addee = addee_in; if (extensive == 0.0) return; - if (this->surfaceComps.size() == 0) + if (this->surface_comps.size() == 0) { - //enum SURFACE_TYPE type; - this->type = addee.type; - //enum DIFFUSE_LAYER_TYPE dl_type; - this->dl_type = addee.dl_type; - //enum SITES_UNITS sites_units; - this->sites_units = addee.sites_units; - //bool only_counter_ions; this->only_counter_ions = addee.only_counter_ions; - //LDBLE thickness; + this->dl_type = addee.dl_type; + this->type = addee.type; + this->sites_units = addee.sites_units; this->thickness = addee.thickness; - //LDBLE debye_lengths; this->debye_lengths = addee.debye_lengths; - //LDBLE DDL_viscosity; this->DDL_viscosity = addee.DDL_viscosity; - //LDBLE DDL_limit; this->DDL_limit = addee.DDL_limit; - //bool transport; + this->solution_equilibria = addee.solution_equilibria; + this->n_solution = addee.n_solution; this->transport = addee.transport; } - //std::map surfaceComps; - for (std::map < std::string, cxxSurfaceComp >::const_iterator itadd = - addee.surfaceComps.begin(); itadd != addee.surfaceComps.end(); - ++itadd) + for (size_t i_add = 0; i_add < addee.Get_surface_comps().size(); i_add++) { - std::map < std::string, cxxSurfaceComp >::iterator it = this->surfaceComps.find((*itadd).first); - if (it != this->surfaceComps.end()) + const cxxSurfaceComp & comp_add_ptr = addee.Get_surface_comps()[i_add]; + size_t i_this; + for (i_this = 0; i_this < this->surface_comps.size(); i_this++) { - (*it).second.add((*itadd).second, extensive); + cxxSurfaceComp & comp_this_ptr = this->surface_comps[i_this]; + if(comp_add_ptr.Get_formula() == comp_this_ptr.Get_formula()) + { + comp_this_ptr.add(addee.surface_comps[i_add], extensive); + break; + } } - else + if (i_this == this->surface_comps.size()) { - cxxSurfaceComp entity = (*itadd).second; + + cxxSurfaceComp entity = comp_add_ptr; entity.multiply(extensive); - std::string str(entity.Get_formula()); - this->surfaceComps[str] = entity; + this->surface_comps.push_back(entity); } } - - //std::map < std::string, cxxSurfaceCharge > surfaceCharges; - for (std::map < std::string, cxxSurfaceCharge >::const_iterator itadd = - addee.surfaceCharges.begin(); itadd != addee.surfaceCharges.end(); - ++itadd) + for (size_t i_add = 0; i_add < addee.Get_surface_charges().size(); i_add++) { - std::map < std::string, cxxSurfaceCharge >::iterator it = this->surfaceCharges.find((*itadd).first); - if (it != this->surfaceCharges.end()) + const cxxSurfaceCharge & charge_add_ptr = addee.Get_surface_charges()[i_add]; + + size_t i_this; + for (i_this = 0; i_this < this->surface_charges.size(); i_this++) { - (*it).second.add( (*itadd).second, extensive); + cxxSurfaceCharge & charge_this_ptr = this->Get_surface_charges()[i_this]; + if(charge_add_ptr.Get_name() == charge_this_ptr.Get_name()) + { + charge_this_ptr.add(addee.surface_charges[i_add], extensive); + break; + } } - else + if (i_this == this->surface_charges.size()) { - cxxSurfaceCharge entity = (*itadd).second; + + cxxSurfaceCharge entity = charge_add_ptr; entity.multiply(extensive); - std::string str(entity.Get_name()); - this->surfaceCharges[str] = entity; + this->surface_charges.push_back(entity); + } + } +} + +void +cxxSurface::multiply(LDBLE extensive) + // + // Add surface to "this" surface + // +{ + + for (size_t i = 0; i < this->surface_comps.size(); i++) + { + cxxSurfaceComp *comp_ptr = &(this->surface_comps[i]); + comp_ptr->multiply(extensive); + } + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + cxxSurfaceCharge *charge_ptr = &(this->surface_charges[i]); + charge_ptr->multiply(extensive); + } +} +cxxSurfaceComp * cxxSurface:: +Find_comp(std::string str) +{ + for (size_t i = 0; i < this->surface_comps.size(); i++) + { + if (Utilities::strcmp_nocase(str.c_str(), this->surface_comps[i].Get_formula().c_str()) == 0) + return &(this->surface_comps[i]); + } + return NULL; +} + +cxxSurfaceCharge * cxxSurface:: +Find_charge(std::string str) +{ + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + if (Utilities::strcmp_nocase(str.c_str(), this->surface_charges[i].Get_name().c_str()) == 0) + return &(this->surface_charges[i]); + } + return NULL; +} +void cxxSurface:: +Sort_comps(void) +{ + // sort comps + { + std::map comp_map; + for (size_t i = 0; i < this->surface_comps.size(); i++) + { + comp_map[this->surface_comps[i].Get_formula()] = this->surface_comps[i]; + } + this->surface_comps.clear(); + std::map::iterator it; + for (it = comp_map.begin(); it != comp_map.end(); it++) + { + this->surface_comps.push_back(it->second); + } + } + + // sort charge too + { + std::map charge_map; + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + charge_map[this->surface_charges[i].Get_name()] = this->surface_charges[i]; + } + this->surface_charges.clear(); + std::map::iterator it; + for (it = charge_map.begin(); it != charge_map.end(); it++) + { + this->surface_charges.push_back(it->second); } } } diff --git a/Surface.h b/Surface.h index 2ae15390..c11a93ea 100644 --- a/Surface.h +++ b/Surface.h @@ -15,29 +15,28 @@ class cxxMix; class cxxSurface:public cxxNumKeyword { - public: +public: + enum SURFACE_TYPE + { UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC, CCM }; + enum DIFFUSE_LAYER_TYPE + { NO_DL, BORKOVEK_DL, DONNAN_DL }; + enum SITES_UNITS + { SITES_ABSOLUTE, SITES_DENSITY }; + cxxSurface(PHRQ_io *io=NULL); - cxxSurface(struct surface *, PHRQ_io *io=NULL); - cxxSurface(const std::map < int, cxxSurface > &entity_map, cxxMix & mx, + cxxSurface(std::map < int, cxxSurface > &entity_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxSurface(); - 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, int *n_out=NULL) const; - void read_raw(CParser & parser, bool check = true); - bool Get_related_phases(void) const; - bool Get_related_rate(void) const; - void totalize(); - - const cxxNameDouble & Get_totals() const - { - return this->totals; - }; + cxxSurfaceComp *Find_comp(std::string str); + cxxSurfaceCharge *Find_charge(const std::string str); + void Sort_comps(); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); @@ -45,24 +44,46 @@ class cxxSurface:public cxxNumKeyword #endif void add(const cxxSurface & addee, LDBLE extensive); - const std::map < std::string, cxxSurfaceComp > & Get_surfaceComps() const {return this->surfaceComps;}; - const std::map < std::string, cxxSurfaceCharge > & Get_surfaceCharges() const {return this->surfaceCharges;}; - SURFACE_TYPE Get_type(void) const {return this->type;}; - DIFFUSE_LAYER_TYPE Get_dl_type(void) const {return dl_type;}; - SITES_UNITS Get_sites_units(void) const {return sites_units;}; - bool Get_only_counter_ions(void) const {return only_counter_ions;}; - LDBLE Get_thickness(void) const {return thickness;}; - LDBLE Get_debye_lengths(void) const {return debye_lengths;}; - LDBLE Get_DDL_viscosity(void) const {return DDL_viscosity;}; - LDBLE Get_DDL_limit(void) const {return DDL_limit;}; - bool Get_transport(void) const {return transport;}; + void multiply(LDBLE extensive); + + std::vector < cxxSurfaceComp > & Get_surface_comps() {return this->surface_comps;} + void Set_surface_comps(std::vector < cxxSurfaceComp > &sc) {this->surface_comps = sc;} + std::vector < cxxSurfaceCharge > & Get_surface_charges() {return this->surface_charges;} + void Set_surface_charges(std::vector < cxxSurfaceCharge > &sc) {this->surface_charges = sc;} + bool Get_new_def(void) {return new_def;} + void Set_new_def(bool tf) {new_def = tf;} + SURFACE_TYPE Get_type(void) const {return this->type;} + void Set_type(SURFACE_TYPE t) {this->type = t;} + DIFFUSE_LAYER_TYPE Get_dl_type(void) const {return dl_type;} + void Set_dl_type(DIFFUSE_LAYER_TYPE t) {dl_type = t;} + SITES_UNITS Get_sites_units(void) const {return sites_units;} + void Set_sites_units(SITES_UNITS u) {sites_units = u;} + bool Get_only_counter_ions(void) const {return only_counter_ions;} + void Set_only_counter_ions(bool tf) {only_counter_ions = tf;} + LDBLE Get_thickness(void) const {return thickness;} + void Set_thickness(LDBLE t) {thickness = t;} + LDBLE Get_debye_lengths(void) const {return debye_lengths;} + void Set_debye_lengths(LDBLE t) {debye_lengths = t;} + LDBLE Get_DDL_viscosity(void) const {return DDL_viscosity;} + void Set_DDL_viscosity(LDBLE t) {DDL_viscosity = t;} + LDBLE Get_DDL_limit(void) const {return DDL_limit;} + void Set_DDL_limit(LDBLE t) {DDL_limit = t;} + bool Get_transport(void) const {return transport;} + void Set_transport(bool tf) {transport = tf;} + cxxNameDouble & Get_totals() {return this->totals;} + void Get_totals(cxxNameDouble &nd) {this->totals = nd;} + bool Get_solution_equilibria(void) {return solution_equilibria;} + void Set_solution_equilibria(bool tf) {solution_equilibria = tf;} + int Get_n_solution(void) {return n_solution;} + void Set_n_solution(int i) {n_solution = i;} protected: - std::map < std::string, cxxSurfaceComp > surfaceComps; - std::map < std::string, cxxSurfaceCharge > surfaceCharges; - enum SURFACE_TYPE type; - enum DIFFUSE_LAYER_TYPE dl_type; - enum SITES_UNITS sites_units; + std::vector < cxxSurfaceComp > surface_comps; + std::vector < cxxSurfaceCharge > surface_charges; + bool new_def; + SURFACE_TYPE type; + DIFFUSE_LAYER_TYPE dl_type; + SITES_UNITS sites_units; bool only_counter_ions; LDBLE thickness; LDBLE debye_lengths; @@ -70,7 +91,8 @@ protected: LDBLE DDL_limit; bool transport; cxxNameDouble totals; - + bool solution_equilibria; + int n_solution; }; #endif // !defined(SURFACE_H_INCLUDED) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 64b119a8..458387d7 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -10,7 +10,6 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SurfaceCharge.h" -//#include "Dictionary.h" #include "phqalloc.h" @@ -30,60 +29,18 @@ PHRQ_base(io) charge_balance = 0.0; mass_water = 0.0; la_psi = 0.0; - la_psi1 = 0.0; - la_psi2 = 0.0; capacitance[0] = 1.0; capacitance[1] = 5.0; + sigma0 = sigma1 = sigma2 = sigmaddl = 0; diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES; } - -cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr, PHRQ_io *io) -// -// constructor for cxxSurfaceCharge from struct surface_charge -// -: -PHRQ_base(io), -diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals) -{ - this->Set_name(surf_charge_ptr->name); - specific_area = surf_charge_ptr->specific_area; - grams = surf_charge_ptr->grams; - charge_balance = surf_charge_ptr->charge_balance; - mass_water = surf_charge_ptr->mass_water; - la_psi = surf_charge_ptr->la_psi; - la_psi1 = surf_charge_ptr->la_psi1; - la_psi2 = surf_charge_ptr->la_psi2; - capacitance[0] = surf_charge_ptr->capacitance[0]; - capacitance[1] = surf_charge_ptr->capacitance[1]; -} - cxxSurfaceCharge::~cxxSurfaceCharge() { } -//struct master * -//cxxSurfaceCharge::get_psi_master() -//{ -// struct master *master_ptr = NULL; -// std::string str = this->name; -// -// str.append("_psi"); -// master_ptr = master_bsearch(str.c_str()); -// if (master_ptr == NULL) -// { -// std::ostringstream error_oss; -// error_oss << "Surface charge psi_master not found." << this-> -// name << "\n"; -// //Utilities::error_msg(error_oss.str(), CONTINUE); -// error_msg(error_oss.str().c_str(), CONTINUE); -// } -// return (master_ptr); -//} - void cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -95,7 +52,6 @@ cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); // Surf_Charge element and attributes - s_oss << indent0 << "name=\"" << this->name << "\"" << "\n"; s_oss << indent0 << "specific_area=\"" << this-> specific_area << "\"" << "\n"; @@ -105,8 +61,6 @@ cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent0 << "mass_water=\"" << this-> mass_water << "\"" << "\n"; s_oss << indent0 << "la_psi=\"" << this->la_psi << "\"" << "\n"; - s_oss << indent0 << "la_psi1=\"" << this->la_psi1 << "\"" << "\n"; - s_oss << indent0 << "la_psi2=\"" << this->la_psi2 << "\"" << "\n"; s_oss << indent0 << "capacitance=\"" << this-> capacitance[0] << " " << this->capacitance[0] << "\"" << "\n"; @@ -120,7 +74,6 @@ cxxSurfaceCharge::dump_xml(std::ostream & s_oss, unsigned int indent) const void cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -132,31 +85,32 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const indent2.append(Utilities::INDENT); // Surf_Charge element and attributes - - s_oss << indent0 << "-name " << this->name << "\n"; - s_oss << indent1 << "-specific_area " << this-> - specific_area << "\n"; - s_oss << indent1 << "-grams " << this->grams << "\n"; - s_oss << indent1 << "-charge_balance " << this-> - charge_balance << "\n"; - s_oss << indent1 << "-mass_water " << this-> - mass_water << "\n"; - s_oss << indent1 << "-la_psi " << this-> - la_psi << "\n"; - s_oss << indent1 << "-la_psi1 " << this-> - la_psi1 << "\n"; - s_oss << indent1 << "-la_psi2 " << this-> - la_psi2 << "\n"; - s_oss << indent1 << "-capacitance0 " << this-> - capacitance[0] << "\n"; - s_oss << indent1 << "-capacitance1 " << this-> - capacitance[1] << "\n"; - + s_oss << indent0 << "# SURFACE_MODIFY candidate identifiers #\n"; + s_oss << indent0 << "-specific_area " << this->specific_area << "\n"; + s_oss << indent0 << "-grams " << this->grams << "\n"; + s_oss << indent0 << "-charge_balance " << this->charge_balance << "\n"; + s_oss << indent0 << "-mass_water " << this->mass_water << "\n"; + s_oss << indent0 << "-la_psi " << this->la_psi << "\n"; + s_oss << indent0 << "-capacitance0 " << this->capacitance[0] << "\n"; + s_oss << indent0 << "-capacitance1 " << this->capacitance[1] << "\n"; // totals - s_oss << indent1; + s_oss << indent0; s_oss << "-diffuse_layer_totals" << "\n"; - this->diffuse_layer_totals.dump_raw(s_oss, indent + 2); + this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); + s_oss << indent0 << "# Surface workspace variables #\n"; + s_oss << indent0 << "-sigma0 " << this->sigma0 << "\n"; + s_oss << indent0 << "-sigma1 " << this->sigma1 << "\n"; + s_oss << indent0 << "-sigma2 " << this->sigma2 << "\n"; + s_oss << indent0 << "-sigmaddl " << this->sigmaddl << "\n"; + std::map::const_iterator git; + for (git = this->g_map.begin(); git != g_map.end(); git++) + { + s_oss << indent0 << "-g_map " << git->first << "\t"; + s_oss << git->second.Get_g() << "\t"; + s_oss << git->second.Get_dg() << "\t"; + s_oss << git->second.Get_psi_to_z() << "\n"; + } } void @@ -167,7 +121,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) static std::vector < std::string > vopts; if (vopts.empty()) { - vopts.reserve(10); + vopts.reserve(15); vopts.push_back("name"); // 0 vopts.push_back("specific_area"); // 1 vopts.push_back("grams"); // 2 @@ -179,6 +133,11 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) vopts.push_back("la_psi2"); // 8 vopts.push_back("capacitance0"); // 9 vopts.push_back("capacitance1"); // 10 + vopts.push_back("sigma0"); // 11 + vopts.push_back("sigma1"); // 12 + vopts.push_back("sigma2"); // 13 + vopts.push_back("sigmaddl"); // 14 + vopts.push_back("g_map"); // 14 } std::istream::pos_type ptr; @@ -187,16 +146,14 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool name_defined(false); bool specific_area_defined(false); bool grams_defined(false); bool charge_balance_defined(false); bool mass_water_defined(false); bool la_psi_defined(false); - bool la_psi1_defined(false); - bool la_psi2_defined(false); bool capacitance0_defined(false); bool capacitance1_defined(false); + bool g_map_first(true); for (;;) { @@ -216,23 +173,10 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_CHARGE read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // name - if (!(parser.get_iss() >> str)) - { - this->name.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for name.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->name = str; - } - name_defined = true; + warning_msg("-name ignored. Defined with -charge_component."); break; case 1: // specific_area @@ -307,25 +251,11 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) break; case 7: // la_psi1 - if (!(parser.get_iss() >> this->la_psi1)) - { - this->la_psi1 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la_psi1.", - PHRQ_io::OT_CONTINUE); - } - la_psi1_defined = true; + parser.warning_msg("-la_psi1 identifier not used"); break; case 8: // la_psi2 - if (!(parser.get_iss() >> this->la_psi2)) - { - this->la_psi2 = 0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for la_psi.", - PHRQ_io::OT_CONTINUE); - } - la_psi2_defined = true; + parser.warning_msg("-la_psi2 identifier not used"); break; case 9: // capacitance0 @@ -349,7 +279,69 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) } capacitance1_defined = true; break; - + case 11: // sigma0 + if (!(parser.get_iss() >> this->sigma0)) + { + this->sigma0 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sigma0.", + PHRQ_io::OT_CONTINUE); + } + break; + case 12: // sigma1 + if (!(parser.get_iss() >> this->sigma1)) + { + this->sigma1 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sigma1.", + PHRQ_io::OT_CONTINUE); + } + break; + case 13: // sigma2 + if (!(parser.get_iss() >> this->sigma2)) + { + this->sigma2 = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sigma2.", + PHRQ_io::OT_CONTINUE); + } + break; + case 14: // sigmaddl + if (!(parser.get_iss() >> this->sigmaddl)) + { + this->sigmaddl = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for sigmaddl.", + PHRQ_io::OT_CONTINUE); + } + break; + case 15: // g_map + { + if (g_map_first) + { + this->g_map.clear(); + g_map_first = false; + } + LDBLE z, dummy; + if (!(parser.get_iss() >> z)) + break; + cxxSurfDL temp_surf_dl; + this->g_map[z] = temp_surf_dl; + std::map::iterator git = g_map.find(z); + if (!(parser.get_iss() >> dummy)) + break; + else + git->second.Set_g(dummy); + if (!(parser.get_iss() >> dummy)) + break; + else + git->second.Set_dg(dummy); + if (!(parser.get_iss() >> dummy)) + break; + else + git->second.Set_psi_to_z(dummy); + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -357,12 +349,6 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (name_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Name not defined for SurfaceCharge input.", - PHRQ_io::OT_CONTINUE); - } if (specific_area_defined == false) { parser.incr_input_error(); @@ -394,18 +380,6 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) parser.error_msg("La_psi not defined for SurfaceCharge input.", PHRQ_io::OT_CONTINUE); } - if (la_psi1_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La_psi1 not defined for SurfaceCharge input.", - PHRQ_io::OT_CONTINUE); - } - if (la_psi2_defined == false) - { - parser.incr_input_error(); - parser.error_msg("La_psi2 not defined for SurfaceCharge input.", - PHRQ_io::OT_CONTINUE); - } if (capacitance0_defined == false) { parser.incr_input_error(); @@ -467,15 +441,7 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, LDBLE extensive) { if (extensive == 0.0) return; - //char * name; - //LDBLE specific_area; - //LDBLE grams; - //LDBLE charge_balance; - //LDBLE mass_water; - //LDBLE la_psi, la_psi1, la_psi2; - //LDBLE capacitance[2]; - //char * name; if (this->name.size() == 0 && addee.name.size() == 0) { return; @@ -495,39 +461,23 @@ cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, LDBLE extensive) f1 = 0.5; f2 = 0.5; } - - //LDBLE specific_area; this->specific_area = f1 * this->specific_area + f2 * addee.specific_area; - //LDBLE grams; this->grams += addee.grams * extensive; - //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; - //LDBLE mass_water; this->mass_water += addee.mass_water * extensive; - //LDBLE la_psi, la_psi1, la_psi2; this->la_psi = this->la_psi * f1 + addee.la_psi * f2; - this->la_psi1 = this->la_psi1 * f1 + addee.la_psi1 * f2; - this->la_psi2 = this->la_psi2 * f1 + addee.la_psi2 * f2; - //LDBLE capacitance[2]; this->capacitance[0] = this->capacitance[0] * f1 + this->capacitance[0] * f2; this->capacitance[1] = this->capacitance[1] * f1 + this->capacitance[1] * f2; + this->diffuse_layer_totals.add_extensive(addee.diffuse_layer_totals, extensive); } void cxxSurfaceCharge::multiply(LDBLE extensive) { - //char * name; - //LDBLE specific_area; - //LDBLE grams; this->grams *= extensive; - //LDBLE charge_balance; this->charge_balance *= extensive; - //LDBLE mass_water; this->mass_water *= extensive; - //LDBLE la_psi, la_psi1, la_psi2; - //LDBLE capacitance[2]; - //cxxNameDouble diffuse_layer_totals; this->diffuse_layer_totals.multiply(extensive); } diff --git a/SurfaceCharge.h b/SurfaceCharge.h index df9014f0..99154f76 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -10,7 +10,56 @@ #include "NameDouble.h" #include "Phreeqc_class.h" #include "PHRQ_base.h" +class cxxSpeciesDL +{ +public: + cxxSpeciesDL() + { + g_moles = dg_g_moles = dx_moles = dh2o_moles = drelated_moles = 0; + } + LDBLE Get_g_moles(void) const {return g_moles;} + void Set_g_moles(LDBLE t) {g_moles = t;} + LDBLE Get_dg_g_moles(void) const {return dg_g_moles;} + void Set_dg_g_moles(LDBLE t) {dg_g_moles = t;} + LDBLE Get_dx_moles(void) const {return dx_moles;} + void Set_dx_moles(LDBLE t) {dx_moles = t;} + LDBLE Get_dh2o_moles(void) const {return dh2o_moles;} + void Set_dh2o_moles(LDBLE t) {dh2o_moles = t;} + LDBLE Get_drelated_moles(void) const {return drelated_moles;} + void Set_drelated_moles(LDBLE t) {drelated_moles = t;} + LDBLE *Get_g_moles_address(void) {return &g_moles;} + LDBLE *Get_dg_g_moles_address(void) {return &dg_g_moles;} + LDBLE *Get_dx_moles_address(void) {return &dx_moles;} + LDBLE *Get_dh2o_moles_address(void) {return &dh2o_moles;} + LDBLE *Get_drelated_moles_address(void) {return &drelated_moles;} + + +protected: + LDBLE g_moles; + LDBLE dg_g_moles; /* g_moles*dgterm */ + LDBLE dx_moles; + LDBLE dh2o_moles; /* moles*g*Ws/Waq */ + LDBLE drelated_moles; /* for related phase */ +}; +class cxxSurfDL +{ +public: + cxxSurfDL() + { + g = dg = psi_to_z = 0; + } + LDBLE Get_g(void) const {return g;} + void Set_g(LDBLE t) {g = t;} + LDBLE Get_dg(void) const {return dg;} + void Set_dg(LDBLE t) {dg = t;} + LDBLE Get_psi_to_z(void) const {return psi_to_z;} + void Set_psi_to_z(LDBLE t) {psi_to_z = t;} +protected: + LDBLE g; + LDBLE dg; + LDBLE psi_to_z; +}; class cxxSurfaceCharge: public PHRQ_base { @@ -18,25 +67,12 @@ public: cxxSurfaceCharge(PHRQ_io *io=NULL); cxxSurfaceCharge(struct surface_charge *, PHRQ_io *io=NULL); - ~cxxSurfaceCharge(); - + virtual ~cxxSurfaceCharge(); struct master *Get_psi_master(); - void dump_xml(std::ostream & os, unsigned int indent = 0) const; - void dump_raw(std::ostream & s_oss, unsigned int indent) const; - void read_raw(CParser & parser, bool check = true); - - const std::string &Get_name() const {return this->name;}; - void Set_name(const char * s) - { - if (s != NULL) - this->name = std::string(s); - else - this->name.clear(); - } void add(const cxxSurfaceCharge & comp, LDBLE extensive); void multiply(LDBLE extensive); @@ -44,30 +80,48 @@ public: void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - LDBLE Get_specific_area() const {return this->specific_area;}; - LDBLE Get_grams() const {return this->grams;}; - LDBLE Get_charge_balance() const {return this->charge_balance;}; - LDBLE Get_mass_water() const {return this->mass_water;}; - LDBLE Get_la_psi() const {return this->la_psi;}; - LDBLE Get_la_psi1() const {return this->la_psi1;}; - LDBLE Get_la_psi2() const {return this->la_psi2;}; - LDBLE Get_capacitance0() const {return this->capacitance[0];}; - LDBLE Get_capacitance1() const {return this->capacitance[1];}; - const cxxNameDouble & Get_diffuse_layer_totals(void) const {return this->diffuse_layer_totals;}; + + const std::string &Get_name() const {return this->name;} + void Set_name(const char * f) {this->name = f ? f : "";} + LDBLE Get_specific_area() const {return this->specific_area;} + void Set_specific_area(LDBLE d) {this->specific_area = d;} + LDBLE Get_grams() const {return this->grams;} + void Set_grams(LDBLE d) {this->grams = d;} + LDBLE Get_charge_balance() const {return this->charge_balance;} + void Set_charge_balance(LDBLE d) {this->charge_balance = d;} + LDBLE Get_mass_water() const {return this->mass_water;} + void Set_mass_water(LDBLE d) {this->mass_water = d;} + LDBLE Get_la_psi() const {return this->la_psi;} + void Set_la_psi(LDBLE d) {this->la_psi = d;} + LDBLE Get_capacitance0() const {return this->capacitance[0];} + void Set_capacitance0(LDBLE d) {this->capacitance[0] = d;} + LDBLE Get_capacitance1() const {return this->capacitance[1];} + void Set_capacitance1(LDBLE d) {this->capacitance[1] = d;} + LDBLE Get_sigma0() const {return this->sigma0;} + void Set_sigma0(LDBLE d) {this->sigma0 = d;} + LDBLE Get_sigma1() const {return this->sigma1;} + void Set_sigma1(LDBLE d) {this->sigma1 = d;} + LDBLE Get_sigma2() const {return this->sigma2;} + void Set_sigma2(LDBLE d) {this->sigma2 = d;} + LDBLE Get_sigmaddl() const {return this->sigmaddl;} + void Set_sigmaddl(LDBLE d) {this->sigmaddl = d;} + const cxxNameDouble & Get_diffuse_layer_totals(void) const {return this->diffuse_layer_totals;} + void Set_diffuse_layer_totals(cxxNameDouble & nd) {this->diffuse_layer_totals = nd;} + std::map &Get_g_map(void) {return g_map;} + void Set_g_map(std::map & t) {g_map = t;} + protected: std::string name; LDBLE specific_area; LDBLE grams; LDBLE charge_balance; LDBLE mass_water; - LDBLE la_psi, la_psi1, la_psi2; + LDBLE la_psi; LDBLE capacitance[2]; - //std::map g; - //char * psi_master_name; cxxNameDouble diffuse_layer_totals; - -public: - + // workspace variables + LDBLE sigma0, sigma1, sigma2, sigmaddl; + std::map g_map; }; #endif // !defined(SURFACECHARGE_H_INCLUDED) diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index bebb1042..37c9c8ea 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -10,10 +10,8 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "SurfaceComp.h" -//#include "Dictionary.h" #include "phqalloc.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -25,38 +23,14 @@ PHRQ_base(io) // default constructor for cxxSurfaceComp // { - formula_totals.type = cxxNameDouble::ND_ELT_MOLES; formula_z = 0.0; moles = 0.0; totals.type = cxxNameDouble::ND_ELT_MOLES; la = 0.0; - //charge_number = -99; charge_balance = 0; phase_proportion = 0.0; Dw = 0.0; } - -cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr, PHRQ_io *io) -// -// constructor for cxxSurfaceComp from struct surface_comp -// -: -PHRQ_base(io), -formula_totals(surf_comp_ptr->formula_totals), -totals(surf_comp_ptr->totals) -{ - this->Set_formula(surf_comp_ptr->formula); - formula_z = surf_comp_ptr->formula_z; - moles = surf_comp_ptr->moles; - la = surf_comp_ptr->la; - //charge_number = surf_comp_ptr->charge; - charge_balance = surf_comp_ptr->cb; - this->Set_phase_name(surf_comp_ptr->phase_name); - phase_proportion = surf_comp_ptr->phase_proportion; - this->Set_rate_name(surf_comp_ptr->rate_name); - Dw = surf_comp_ptr->Dw; -} - cxxSurfaceComp::~cxxSurfaceComp() { } @@ -64,7 +38,6 @@ cxxSurfaceComp::~cxxSurfaceComp() void cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -77,44 +50,32 @@ cxxSurfaceComp::dump_xml(std::ostream & s_oss, unsigned int indent) const // Surf_Comp element and attributes - s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; - s_oss << indent0 << "formula_z=\"" << this-> - formula_z << "\"" << "\n"; + //s_oss << indent0 << "formula=\"" << this->formula << "\"" << "\n"; + s_oss << indent0 << "formula_z=\"" << this->formula_z << "\"" << "\n"; s_oss << indent0 << "moles=\"" << this->moles << "\"" << "\n"; s_oss << indent0 << "la=\"" << this->la << "\"" << "\n"; - //s_oss << indent0 << "charge_number=\"" << this->charge_number << "\"" << "\n"; - s_oss << indent0 << "charge_balance=\"" << this-> - charge_balance << "\"" << "\n"; + s_oss << indent0 << "charge_balance=\"" << this->charge_balance << "\"" << "\n"; + s_oss << indent0 << "phase_proportion=\"" << this->phase_proportion << "\"" << "\n"; + s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << "\n"; + s_oss << indent0 << "charge_name=\"" << this->charge_name << "\"" << "\n"; if (this->phase_name.size() != 0) { - s_oss << indent0 << "phase_name=\"" << this-> - phase_name << "\"" << "\n"; + s_oss << indent0 << "phase_name=\"" << this->phase_name << "\"" << "\n"; } if (this->rate_name.size() != 0) { - s_oss << indent0 << "rate_name=\"" << this-> - rate_name << "\"" << "\n"; + s_oss << indent0 << "rate_name=\"" << this->rate_name << "\"" << "\n"; } - s_oss << indent0 << "phase_proportion=\"" << this-> - phase_proportion << "\"" << "\n"; - s_oss << indent0 << "Dw=\"" << this->Dw << "\"" << "\n"; - - // formula_totals - s_oss << indent0; - s_oss << "formula_totals.dump_xml(s_oss, indent + 1); // totals s_oss << indent0; s_oss << "totals.dump_xml(s_oss, indent + 1); - } void cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const { - //const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -125,41 +86,27 @@ cxxSurfaceComp::dump_raw(std::ostream & s_oss, unsigned int indent) const for (i = 0; i < indent + 2; ++i) indent2.append(Utilities::INDENT); - // Surf_Comp element and attributes - - s_oss << indent0 << "-formula " << this-> - formula << "\n"; - s_oss << indent1 << "-formula_z " << this-> - formula_z << "\n"; - s_oss << indent1 << "-moles " << this->moles << "\n"; - s_oss << indent1 << "-la " << this->la << "\n"; - //s_oss << indent1 << "-charge_number " << this->charge_number << "\n"; - s_oss << indent1 << "-charge_balance " << this-> - charge_balance << "\n"; + s_oss << indent0 << "# SURFACE_MODIFY candidate identifiers #\n"; + s_oss << indent0 << "-formula_z " << this->formula_z << "\n"; + s_oss << indent0 << "-moles " << this->moles << "\n"; + s_oss << indent0 << "-la " << this->la << "\n"; + s_oss << indent0 << "-charge_balance " << this->charge_balance << "\n"; if (this->phase_name.size() != 0) { - s_oss << indent1 << "-phase_name " << this-> - phase_name << "\n"; + s_oss << indent0 << "-phase_name " << this->phase_name << "\n"; } if (this->rate_name.size() != 0) { - s_oss << indent1 << "-rate_name " << this-> - rate_name << "\n"; + s_oss << indent0 << "-rate_name " << this->rate_name << "\n"; } - s_oss << indent1 << "-phase_proportion " << this-> - phase_proportion << "\n"; - s_oss << indent1 << "-Dw " << this->Dw << "\n"; - - // formula_totals - s_oss << indent1; - s_oss << "-formula_totals" << "\n"; - this->formula_totals.dump_raw(s_oss, indent + 2); - + s_oss << indent0 << "-phase_proportion " << this->phase_proportion << "\n"; + s_oss << indent0 << "-Dw " << this->Dw << "\n"; + s_oss << indent0 << "-charge_name " << this->charge_name << "\n"; + s_oss << indent0 << "-master_element " << this->master_element << "\n"; // totals - s_oss << indent1; + s_oss << indent0; s_oss << "-totals" << "\n"; - this->totals.dump_raw(s_oss, indent + 2); - + this->totals.dump_raw(s_oss, indent + 1); } void @@ -170,11 +117,11 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) static std::vector < std::string > vopts; if (vopts.empty()) { - vopts.reserve(10); + vopts.reserve(15); vopts.push_back("formula"); // 0 vopts.push_back("moles"); // 1 vopts.push_back("la"); // 2 - vopts.push_back("charge_number_not_used"); // 3 + vopts.push_back("charge_number"); // 3 vopts.push_back("charge_balance"); // 4 vopts.push_back("phase_name"); // 5 vopts.push_back("rate_name"); // 6 @@ -183,6 +130,8 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) vopts.push_back("formula_z"); // 9 vopts.push_back("formula_totals"); // 10 vopts.push_back("dw"); // 11 + vopts.push_back("charge_name"); // 12 + vopts.push_back("master_element"); // 13 } std::istream::pos_type ptr; @@ -191,13 +140,15 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) int opt_save; opt_save = CParser::OPT_ERROR; - bool formula_defined(false); + + bool master_element_defined(false); + bool charge_name_defined(false); bool moles_defined(false); bool la_defined(false); - //bool charge_number_defined(false); bool charge_balance_defined(false); bool formula_z_defined(false); bool Dw_defined(false); + bool totals_defined(false); for (;;) { @@ -217,23 +168,10 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) case CParser::OPT_ERROR: opt = CParser::OPT_KEYWORD; // Allow return to Surface for more processing - //parser.error_msg("Unknown input in SURF_COMP read.", PHRQ_io::OT_CONTINUE); - //parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); break; case 0: // formula - if (!(parser.get_iss() >> str)) - { - this->formula.clear(); - parser.incr_input_error(); - parser.error_msg("Expected string value for formula.", - PHRQ_io::OT_CONTINUE); - } - else - { - this->formula = str; - } - formula_defined = true; + output_msg("-formula is obsolete in surface comp raw"); break; case 1: // moles @@ -258,14 +196,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) la_defined = true; break; case 3: // charge_number not used - //if (!(parser.get_iss() >> this->charge_number)) - //{ - // this->charge_number = 0; - // parser.incr_input_error(); - // parser.error_msg("Expected integer value for charge_number.", - // PHRQ_io::OT_CONTINUE); - //} - //charge_number_defined = true; + parser.warning_msg("-charge_number identifier is obsolete."); break; case 4: // charge_balance @@ -328,6 +259,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) ("Expected element name and molality for SurfaceComp totals.", PHRQ_io::OT_CONTINUE); } + totals_defined = true; opt_save = 8; break; @@ -343,16 +275,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) break; case 10: // formula_totals - if (this->formula_totals.read_raw(parser, next_char) != - CParser::PARSER_OK) - { - parser.incr_input_error(); - parser. - error_msg - ("Expected element name and molality for SurfaceComp formula totals.", - PHRQ_io::OT_CONTINUE); - } - opt_save = 10; + parser.warning_msg("-formula_totals is an obsolete identifier."); break; case 11: // Dw @@ -365,6 +288,34 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) } Dw_defined = true; break; + case 12: // charge_name + if (!(parser.get_iss() >> str)) + { + this->charge_name.clear(); + parser.incr_input_error(); + parser.error_msg("Expected string value for charge_name.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->charge_name = str; + } + charge_name_defined = true; + break; + case 13: // master_element + if (!(parser.get_iss() >> str)) + { + this->master_element.clear(); + parser.incr_input_error(); + parser.error_msg("Expected string value for master_element.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->master_element = str; + } + master_element_defined = true; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -372,10 +323,10 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) if (check) { // members that must be defined - if (formula_defined == false) + if (charge_name_defined == false) { parser.incr_input_error(); - parser.error_msg("Formula not defined for SurfaceComp input.", + parser.error_msg("Charge_name not defined for SurfaceComp input.", PHRQ_io::OT_CONTINUE); } if (formula_z_defined == false) @@ -409,6 +360,18 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) parser.error_msg("Dw not defined for SurfaceComp input.", PHRQ_io::OT_CONTINUE); } + if (master_element_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Master_element name not defined for SurfaceComp input.", + PHRQ_io::OT_CONTINUE); + } + if (totals_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Totals not defined for SurfaceComp input.", + PHRQ_io::OT_CONTINUE); + } } } @@ -425,7 +388,6 @@ cxxSurfaceComp::mpi_pack(std::vector < int >&ints, doubles.push_back(this->moles); this->totals.mpi_pack(ints, doubles); doubles.push_back(this->la); - //ints.push_back(charge_number); doubles.push_back(this->charge_balance); ints.push_back(dictionary.string2int(this->phase_name)); doubles.push_back(this->phase_proportion); @@ -445,7 +407,6 @@ cxxSurfaceComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) this->moles = doubles[d++]; this->totals.mpi_unpack(ints, &i, doubles, &d); this->la = doubles[d++]; - //this->charge_number = ints[i++]; this->charge_balance = doubles[d++]; this->phase_name = dictionary.int2stdstring(ints[i++]); this->phase_proportion = doubles[d++]; @@ -463,8 +424,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) if (addee.formula.size() == 0) return; - //char * formula; - //cxxNameDouble formula_totals; if (this->formula.size() == 0 && addee.formula.size() == 0) { return; @@ -474,7 +433,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) if (this->formula.size() == 0 && addee.formula.size() != 0) { this->formula = addee.formula; - this->formula_totals = addee.formula_totals; } // this and addee must have same formula @@ -492,19 +450,10 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) f1 = 0.5; f2 = 0.5; } - //LDBLE formula_z; - - //LDBLE moles; this->moles += addee.moles * extensive; - //cxxNameDouble totals; this->totals.add_extensive(addee.totals, extensive); - //LDBLE la; this->la = f1 * this->la + f2 * addee.la; - //int charge_number; - //LDBLE charge_balance; this->charge_balance += addee.charge_balance * extensive; - //char *phase_name; - if (this->phase_name != addee.phase_name) { std::ostringstream oss; @@ -520,7 +469,6 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) this->phase_proportion * f1 + addee.phase_proportion * f2; } - //char *rate_name; if (this->rate_name != addee.rate_name) { std::ostringstream oss; @@ -546,84 +494,15 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) error_msg(oss.str().c_str(), CONTINUE); return; } - //LDBLE Dw; } void cxxSurfaceComp::multiply(LDBLE extensive) { - //char * formula; - //cxxNameDouble formula_totals; - //LDBLE formula_z; - //LDBLE moles; this->moles *= extensive; - //cxxNameDouble totals; + this->totals.multiply(extensive); - //LDBLE la; - //int charge_number; - //LDBLE charge_balance; + this->charge_balance *= extensive; - //char *phase_name; - //LDBLE phase_proportion; - //char *rate_name; - //LDBLE Dw; -} -const std::string & -cxxSurfaceComp::Get_phase_name() const -{ - return this->phase_name; -} -void -cxxSurfaceComp::Set_phase_name(const char * f) -{ - if (f != NULL) - this->phase_name = std::string(f); - else - this->phase_name.clear(); -} -const std::string & -cxxSurfaceComp::Get_rate_name() const -{ - return this->rate_name; -} -void -cxxSurfaceComp::Set_rate_name(const char * f) -{ - if (f != NULL) - this->rate_name = std::string(f); - else - this->rate_name.clear(); -} -const std::string & -cxxSurfaceComp::Get_formula() const -{ - return this->formula; -} -void -cxxSurfaceComp::Set_formula(const char * f) -{ - if (f != NULL) - this->formula = std::string(f); - else - this->formula.clear(); -} -LDBLE -cxxSurfaceComp::Get_charge_balance() const -{ - return this->charge_balance; -} -void -cxxSurfaceComp::Set_charge_balance(LDBLE d) -{ - this->charge_balance = d; -} -const cxxNameDouble & -cxxSurfaceComp::Get_totals() const -{ - return (this->totals); -} -const cxxNameDouble & -cxxSurfaceComp::Get_formula_totals() const -{ - return (this->formula_totals); } + diff --git a/SurfaceComp.h b/SurfaceComp.h index f0637061..8da6bda3 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -15,30 +15,39 @@ class cxxSurfaceComp: public PHRQ_base public: cxxSurfaceComp(PHRQ_io *io=NULL); - cxxSurfaceComp(struct surface_comp *, PHRQ_io *io=NULL); - ~cxxSurfaceComp(); + virtual ~cxxSurfaceComp(); - const std::string &Get_phase_name() const; - void Set_phase_name(const char * f); - const std::string &Get_rate_name() const; - void Set_rate_name(const char * f); - const std::string &Get_formula() const; - void Set_formula(const char * f); - LDBLE Get_charge_balance() const; - void Set_charge_balance(LDBLE d); void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const; void read_raw(CParser & parser, bool check = true); - const cxxNameDouble & Get_totals() const; - const cxxNameDouble & Get_formula_totals() const; - LDBLE Get_formula_z(void) const {return formula_z;}; - LDBLE Get_moles(void) const {return moles;}; - LDBLE Get_la(void) const {return la;}; - LDBLE Get_phase_proportion(void) const {return phase_proportion;}; - LDBLE Get_Dw(void) const {return Dw;}; void add(const cxxSurfaceComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + const std::string &Get_formula() const {return this->formula;} + void Set_formula(const char * f) {this->formula = f ? f : "";} + LDBLE Get_formula_z(void) const {return formula_z;}; + void Set_formula_z(LDBLE t) {this->formula_z = t;} + LDBLE Get_moles(void) const {return moles;} + void Set_moles(LDBLE t) {this->moles = t;} + cxxNameDouble & Get_totals() {return (this->totals);} + void Set_totals(cxxNameDouble & nd) {this->totals = nd;} + LDBLE Get_la(void) const {return la;}; + void Set_la(LDBLE t) {this->la = t;} + LDBLE Get_charge_balance() const {return this->charge_balance;} + void Set_charge_balance(LDBLE d) {this->charge_balance = d;} + const std::string &Get_charge_name() const {return this->charge_name;} + void Set_charge_name(const char * f) {this->charge_name = f ? f : "";} + const std::string &Get_phase_name() const {return this->phase_name;} + void Set_phase_name(const char * f) {this->phase_name = f ? f : "";} + LDBLE Get_phase_proportion(void) const {return phase_proportion;} + void Set_phase_proportion(LDBLE d) {this->phase_proportion = d;} + const std::string &Get_rate_name() const {return this->rate_name;} + void Set_rate_name(const char * f) {this->rate_name = f ? f : "";} + LDBLE Get_Dw(void) const {return Dw;} + void Set_Dw(LDBLE d) {this->Dw = d;} + const std::string &Get_master_element() const {return this->master_element;} + void Set_master_element(const char * f) {this->master_element = f ? f : "";} + #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); @@ -46,17 +55,17 @@ public: protected: std::string formula; - cxxNameDouble formula_totals; LDBLE formula_z; LDBLE moles; cxxNameDouble totals; LDBLE la; - //int charge_number; + std::string charge_name; LDBLE charge_balance; std::string phase_name; LDBLE phase_proportion; std::string rate_name; LDBLE Dw; + std::string master_element; public: }; diff --git a/System.cxx b/System.cxx index 40ce26b1..4c1a753e 100644 --- a/System.cxx +++ b/System.cxx @@ -74,7 +74,7 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) if (this->ppassemblage != NULL) { this->ppassemblage->totalize(P_INSTANCE); - this->totals.add_extensive(this->ppassemblage->Get_totals(), 1.0); + this->totals.add_extensive(this->ppassemblage->Get_assemblage_totals(), 1.0); } if (this->gasphase != NULL) { diff --git a/System.h b/System.h index b1860f78..879e82ef 100644 --- a/System.h +++ b/System.h @@ -1,15 +1,5 @@ #if !defined(SYSTEM_H_INCLUDED) #define SYSTEM_H_INCLUDED -//#include "Solution.h" -//#include "Exchange.h" -//#include "GasPhase.h" -//#include "cxxKinetics.h" -//#include "PPassemblage.h" -//#include "SSassemblage.h" -//#include "Surface.h" -//#include "cxxMix.h" -//#include "Reaction.h" -//#include "Temperature.h" #include "NameDouble.h" #include "PHRQ_base.h" #include "Phreeqc_class.h" @@ -29,7 +19,7 @@ class cxxSystem: public PHRQ_base { public: cxxSystem(PHRQ_io *io=NULL); - ~cxxSystem(void); + virtual ~cxxSystem(void); void Initialize(void); void Set_Solution(cxxSolution * entity) { diff --git a/Temperature.cxx b/Temperature.cxx index 14124098..7a04aea1 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -36,7 +36,6 @@ cxxTemperature::~cxxTemperature() void cxxTemperature::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -187,7 +186,6 @@ cxxTemperature::read(CParser & parser) void cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing temperature message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -200,18 +198,18 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "REACTION_TEMPERATURE_RAW " << n_user_local << " " << this->description << "\n"; s_oss << indent1; - s_oss << "-count_temps " << this->Get_countTemps() << "\n"; + s_oss << "-count_temps " << this->Get_countTemps() << "\n"; s_oss << indent1; - s_oss << "-equal_increments " << this->equalIncrements << "\n"; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; // Temperature element and attributes s_oss << indent1; - s_oss << "-temps " << "\n"; + s_oss << "-temps " << "\n"; { int i = 0; s_oss << indent2; diff --git a/Use.h b/Use.h index ae00f9e3..90a22a5c 100644 --- a/Use.h +++ b/Use.h @@ -9,6 +9,8 @@ class cxxPressure; class cxxTemperature; class cxxSSassemblage; class cxxKinetics; +class cxxSurface; +class cxxSolution; class cxxUse { @@ -75,26 +77,26 @@ public: void Set_n_inverse_user(int i) {n_inverse_user = i;} void Set_n_ss_assemblage_user(int i) {n_ss_assemblage_user = i;} - struct solution * Get_solution_ptr(void) const {return this->solution_ptr;} + cxxSolution * Get_solution_ptr(void) const {return this->solution_ptr;} cxxPPassemblage * Get_pp_assemblage_ptr(void) const {return this->pp_assemblage_ptr;} cxxMix * Get_mix_ptr(void) const {return this->mix_ptr;} cxxReaction * Get_reaction_ptr(void) const {return this->reaction_ptr;} cxxExchange * Get_exchange_ptr(void) const {return this->exchange_ptr;} cxxKinetics * Get_kinetics_ptr(void) const {return this->kinetics_ptr;} - struct surface * Get_surface_ptr(void) const {return this->surface_ptr;} + cxxSurface * Get_surface_ptr(void) const {return this->surface_ptr;} cxxPressure * Get_pressure_ptr(void) const {return this->pressure_ptr;} cxxTemperature * Get_temperature_ptr(void) const {return this->temperature_ptr;} cxxGasPhase * Get_gas_phase_ptr(void) const {return this->gas_phase_ptr;} struct inverse * Get_inverse_ptr(void) const {return this->inverse_ptr;} cxxSSassemblage * Get_ss_assemblage_ptr(void) {return this->ss_assemblage_ptr;} - void Set_solution_ptr(struct solution * p) {this->solution_ptr = p;} + void Set_solution_ptr(cxxSolution * p) {this->solution_ptr = p;} void Set_pp_assemblage_ptr(cxxPPassemblage * p) {this->pp_assemblage_ptr = p;} void Set_mix_ptr(cxxMix * p) {this->mix_ptr = p;} void Set_reaction_ptr(cxxReaction * p) {this->reaction_ptr = p;} void Set_exchange_ptr(cxxExchange * p) {this->exchange_ptr = p;} void Set_kinetics_ptr(cxxKinetics * p) {this->kinetics_ptr = p;} - void Set_surface_ptr(struct surface * p) {this->surface_ptr = p;} + void Set_surface_ptr(cxxSurface * p) {this->surface_ptr = p;} void Set_pressure_ptr(cxxPressure * p) {this->pressure_ptr = p;} void Set_temperature_ptr(cxxTemperature * p) {this->temperature_ptr = p;} void Set_gas_phase_ptr(cxxGasPhase * p) {this->gas_phase_ptr = p;} @@ -104,7 +106,7 @@ public: protected: bool solution_in; int n_solution_user; - struct solution *solution_ptr; + cxxSolution *solution_ptr; bool pp_assemblage_in; int n_pp_assemblage_user; @@ -129,7 +131,7 @@ protected: bool surface_in; int n_surface_user; - struct surface *surface_ptr; + cxxSurface *surface_ptr; bool pressure_in; int n_pressure_user; diff --git a/Utils.cxx b/Utils.cxx index ee311679..881fec5a 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -56,6 +56,26 @@ Utilities::str_tolower(std::string & str) std::transform(str.begin(), str.end(), str.begin(), tolower); } +//////////////////////////////////////////////////////////////////////////// +void +Utilities::str_toupper(std::string & str) +//////////////////////////////////////////////////////////////////////////// +{ + std::transform(str.begin(), str.end(), str.begin(), toupper); +} +//////////////////////////////////////////////////////////////////////////// +std::string +Utilities::pad_right(const std::string & str, size_t l) +//////////////////////////////////////////////////////////////////////////// +{ + std::string new_str(str); + size_t length = new_str.size(); + if (length < l) + { + new_str = new_str.insert(length, l - length, ' '); + } + return new_str; +} //////////////////////////////////////////////////////////////////////////// diff --git a/Utils.h b/Utils.h index 5ad83065..a30bd298 100644 --- a/Utils.h +++ b/Utils.h @@ -18,20 +18,18 @@ namespace Utilities int strcmp_nocase_arg1(const char *str1, const char *str2); void str_tolower(std::string & str); - + void str_toupper(std::string & str); + std::string pad_right(const std::string & str, size_t l); bool replace(const char *str1, const char *str2, std::string & str); void squeeze_white(std::string & s_l); LDBLE get_nan(void); - //void error_msg(const std::string&, const int stopflag); - // operations on maps of entities (Solution, Exchange, ...) template < typename T > void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) { - //std :: map < int, T > :: const_iterator it; typename T::const_iterator it; for (it = b.begin(); it != b.end(); ++it) { @@ -39,10 +37,6 @@ namespace Utilities } return; } - //template < typename T > bool exists(const T & b, int i) - //{ - // return (b.find(i) != b.end()); - //} template < typename T > T * Rxn_find(std::map < int, T > &b, int i) @@ -76,12 +70,6 @@ namespace Utilities } } - /* - template - bool exists (std::map b, int i){ - return (b.find(i) != b.end());} - */ - template < typename T > void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end) { @@ -108,7 +96,6 @@ namespace Utilities T entity(phreeqc_cookie->Get_phrq_io()); CParser parser(phreeqc_cookie->Get_phrq_io()); - //if (phreeqc_cookie->pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); entity.read_raw(parser); // Store @@ -148,12 +135,5 @@ namespace Utilities return phreeqc_cookie->cleanup_after_parser(parser); } - - /* - template - bool exists (std::map b, int i){ - return (b.find(i) != b.end());} - */ - } #endif // UTILITIES_H_INCLUDED diff --git a/class_main.cpp b/class_main.cpp index 77618e7c..bfdcfdb6 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -98,7 +98,6 @@ main_method(int argc, char *argv[]) errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); if (errors != 0) { - //clean_up(); return errors; } #ifdef DOS @@ -111,7 +110,6 @@ main_method(int argc, char *argv[]) errors = do_initialize(); if (errors != 0) { - //clean_up(); return errors; } /* @@ -123,7 +121,6 @@ main_method(int argc, char *argv[]) if (errors != 0) { - //clean_up(); return errors; } @@ -137,7 +134,6 @@ main_method(int argc, char *argv[]) if (errors != 0) { - //clean_up(); return errors; } /* @@ -146,19 +142,11 @@ main_method(int argc, char *argv[]) errors = do_status(); if (errors != 0) { - //clean_up(); return errors; } - - - //clean_up(); - //close_input_files(); - //close_output_files(); - return 0; } -#ifdef DOS /* ---------------------------------------------------------------------- */ int Phreeqc:: write_banner(void) @@ -202,4 +190,3 @@ write_banner(void) return 0; } -#endif diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 0a43303a..49c61762 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -1,4 +1,4 @@ -// Kinetics.cxx: implementation of the cxxKinetics class. +// cxxKinetics.cxx: implementation of the cxxKinetics class. // ////////////////////////////////////////////////////////////////////// #ifdef _DEBUG @@ -7,17 +7,13 @@ #include // assert #include // std::sort -#include "Utils.h" // define first +#include "Utils.h" #include "Phreeqc.h" - #include "cxxKinetics.h" #include "cxxMix.h" - #include "phqalloc.h" - #include "PHRQ_io.h" - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -38,50 +34,6 @@ cxxKinetics::cxxKinetics(PHRQ_io *io) equalIncrements = false; count = 0; } -#ifdef SKIP -cxxKinetics::cxxKinetics(struct kinetics *kinetics_ptr, PHRQ_io *io) - // - // constructor for cxxKinetics from struct kinetics - // - : -cxxNumKeyword(io), -totals(kinetics_ptr->totals) -{ - int i; - - this->Set_description(kinetics_ptr->description); - n_user = kinetics_ptr->n_user; - n_user_end = kinetics_ptr->n_user_end; - step_divide = kinetics_ptr->step_divide; - rk = kinetics_ptr->rk; - bad_step_max = kinetics_ptr->bad_step_max; - use_cvode = (kinetics_ptr->use_cvode == TRUE); - cvode_steps = kinetics_ptr->cvode_steps; - cvode_order = kinetics_ptr->cvode_order; - - // kinetics components - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - cxxKineticsComp ec(&(kinetics_ptr->comps[i]), this->Get_io()); - std::string str(ec.Get_rate_name()); - //this->kineticsComps[str] = ec; - this->kineticsComps.push_back(ec); - } - - // steps - int n = kinetics_ptr->count_steps; - this->equal_steps = 0; - if (kinetics_ptr->count_steps < 0) - { - this->equal_steps = -kinetics_ptr->count_steps; - n = 1; - } - for (i = 0; i < n; i++) - { - this->steps.push_back(kinetics_ptr->steps[i]); - } -} -#endif cxxKinetics::cxxKinetics(const std::map < int, cxxKinetics > &entities, cxxMix & mix, int l_n_user, PHRQ_io *io): cxxNumKeyword(io) @@ -118,7 +70,6 @@ cxxKinetics::~cxxKinetics() void cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -153,7 +104,6 @@ cxxKinetics::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) const { - //const char ERR_MESSAGE[] = "Packing kinetics message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -167,49 +117,43 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co // Kinetics element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "KINETICS_RAW " << n_user_local << " " << this->description << "\n"; + s_oss << "KINETICS_RAW " << n_user_local << " " << this->description << "\n"; + + s_oss << indent1 << "# KINETICS_MODIFY candidate identifiers #\n"; s_oss << indent1; - s_oss << "-step_divide " << this->step_divide << "\n"; + s_oss << "-step_divide " << this->step_divide << "\n"; s_oss << indent1; - s_oss << "-rk " << this->rk << "\n"; + s_oss << "-rk " << this->rk << "\n"; s_oss << indent1; - s_oss << "-bad_step_max " << this->bad_step_max << "\n"; + s_oss << "-bad_step_max " << this->bad_step_max << "\n"; s_oss << indent1; - s_oss << "-use_cvode " << this->use_cvode << "\n"; + s_oss << "-use_cvode " << this->use_cvode << "\n"; s_oss << indent1; - s_oss << "-cvode_steps " << this->cvode_steps << "\n"; + s_oss << "-cvode_steps " << this->cvode_steps << "\n"; s_oss << indent1; - s_oss << "-cvode_order " << this->cvode_order << "\n"; + s_oss << "-cvode_order " << this->cvode_order << "\n"; // kineticsComps structures - - //for (std::list < cxxKineticsComp >::const_iterator it = - // kineticsComps.begin(); it != kineticsComps.end(); ++it) for (size_t k = 0; k < this->kinetics_comps.size(); k++) { s_oss << indent1; - s_oss << "-component " << this->kinetics_comps[k].Get_rate_name() << "\n"; + s_oss << "-component " << this->kinetics_comps[k].Get_rate_name() << "\n"; this->kinetics_comps[k].dump_raw(s_oss, indent + 2); } - // totals + // equal_steps s_oss << indent1; - s_oss << "-totals " << "\n"; - this->totals.dump_raw(s_oss, indent + 2); + s_oss << "-equalIncrements " << this->equalIncrements << "\n"; // equal_steps s_oss << indent1; - s_oss << "-equalIncrements " << this->equalIncrements << "\n"; - - // equal_steps - s_oss << indent1; - s_oss << "-count " << this->count << "\n"; + s_oss << "-count " << this->count << "\n"; // steps s_oss << indent1; @@ -230,6 +174,12 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co } s_oss << "\n"; } + + s_oss << indent1 << "# KINETICS workspace variables #\n"; + // totals + s_oss << indent1; + s_oss << "-totals " << "\n"; + this->totals.dump_raw(s_oss, indent + 2); return; } void @@ -250,7 +200,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) vopts.push_back("steps"); vopts.push_back("cvode_steps"); vopts.push_back("cvode_order"); - vopts.push_back("equalIncrements"); + vopts.push_back("equalincrements"); vopts.push_back("count"); } @@ -403,8 +353,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) case 6: // steps while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - //sscanf(token.c_str(), "%lf", &d); - //this->steps.push_back(d); std::istringstream iss(token); if (!(iss >> d)) { @@ -511,316 +459,8 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", PHRQ_io::OT_CONTINUE); } - // disable to remain backward compatible with PHAST restart files? - //if (equal_steps_defined == false) - //{ - // parser.incr_input_error(); - // parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", - // PHRQ_io::OT_CONTINUE); - //} } } -#ifdef SKIP -void -cxxKinetics::read_raw(CParser & parser, bool check) -{ - - LDBLE d; - static std::vector < std::string > vopts; - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("step_divide"); - vopts.push_back("rk"); - vopts.push_back("bad_step_max"); - vopts.push_back("use_cvode"); - vopts.push_back("component"); - vopts.push_back("totals"); - vopts.push_back("steps"); - vopts.push_back("cvode_steps"); - vopts.push_back("cvode_order"); - vopts.push_back("equal_steps"); - } - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - int opt_save; - bool useLastLine(false); - std::vector < LDBLE > temp_steps; - - // Read kinetics number and description - this->read_number_description(parser); - - opt_save = CParser::OPT_ERROR; - bool step_divide_defined(false); - bool rk_defined(false); - bool bad_step_max_defined(false); - bool use_cvode_defined(false); - bool cvode_steps_defined(false); - bool cvode_order_defined(false); - bool steps_defined(false); - bool equal_steps_defined(false); - - for (;;) - { - int opt; - if (useLastLine == false) - { - opt = parser.get_option(vopts, next_char); - } - else - { - opt = parser.getOptionFromLastLine(vopts, next_char, true); - } - 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 KINETICS_COMP_RAW keyword.", - PHRQ_io::OT_CONTINUE); - parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; - break; - - case 0: // step_divide - if (!(parser.get_iss() >> this->step_divide)) - { - this->step_divide = 1.0; - parser.incr_input_error(); - parser.error_msg("Expected numeric value for step_divide.", - PHRQ_io::OT_CONTINUE); - } - step_divide_defined = true; - useLastLine = false; - break; - - case 1: // rk - if (!(parser.get_iss() >> this->rk)) - { - this->rk = 3; - parser.incr_input_error(); - parser.error_msg("Expected integer value for rk.", - PHRQ_io::OT_CONTINUE); - } - rk_defined = true; - useLastLine = false; - break; - - case 2: // bad_step_max - if (!(parser.get_iss() >> this->bad_step_max)) - { - this->bad_step_max = 500; - parser.incr_input_error(); - parser.error_msg("Expected integer value for bad_step_max.", - PHRQ_io::OT_CONTINUE); - } - bad_step_max_defined = true; - useLastLine = false; - break; - - case 3: // use_cvode - if (!(parser.get_iss() >> this->use_cvode)) - { - this->use_cvode = false; - parser.incr_input_error(); - parser.error_msg("Expected boolean value for use_cvode.", - PHRQ_io::OT_CONTINUE); - } - use_cvode_defined = true; - useLastLine = false; - break; - - case 4: // component - { - cxxKineticsComp ec(this->Get_io()); - - // preliminary read - parser.set_accumulate(true); - ec.read_raw(parser, false); - parser.set_accumulate(false); - std::istringstream is(parser.get_accumulated()); - CParser reread(is, this->Get_io()); - reread.set_echo_file(CParser::EO_NONE); - reread.set_echo_stream(CParser::EO_NONE); - - //std::list < cxxKineticsComp >::iterator kit; - bool found = false; - size_t k; - for (k = 0; k < this->kineticsComps.size(); k++) - { - if (this->kineticsComps[k].Get_rate_name() == ec.Get_rate_name()) - { - found = true; - break; - } - } - if (found) - { - this->kineticsComps[k].read_raw(reread, false); - } - else - { - cxxKineticsComp ec1(this->Get_io()); - ec1.read_raw(reread, false); - std::string str(ec1.Get_rate_name()); - this->kineticsComps.push_back(ec1); - } - /* - if (this->kineticsComps.find(ec.get_rate_name()) != this->kineticsComps.end()) - { - cxxKineticsComp & comp = this->kineticsComps.find(ec.get_rate_name())->second; - comp.read_raw(reread, false); - } - else - { - cxxKineticsComp ec1; - ec1.read_raw(reread, false); - std::string str(ec1.get_rate_name()); - this->kineticsComps[str] = ec1; - } - */ - } - useLastLine = true; - break; - - case 5: // totals - if (this->totals.read_raw(parser, next_char) != - CParser::PARSER_OK) - { - parser.incr_input_error(); - parser. - error_msg - ("Expected element name and molality for KineticsComp totals.", - PHRQ_io::OT_CONTINUE); - } - opt_save = 5; - useLastLine = false; - break; - - case 6: // steps - while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) - { - //sscanf(token.c_str(), "%lf", &d); - //this->steps.push_back(d); - std::istringstream iss(token); - if (!(iss >> d)) - { - parser.incr_input_error(); - parser.error_msg("Expected numeric value for steps.", - PHRQ_io::OT_CONTINUE); - } - else - { - temp_steps.push_back(d); - steps_defined = true; - } - } - opt_save = 6; - useLastLine = false; - break; - - case 7: // cvode_steps - if (!(parser.get_iss() >> this->cvode_steps)) - { - this->cvode_steps = 100; - parser.incr_input_error(); - parser.error_msg("Expected integer value for cvode_steps.", - PHRQ_io::OT_CONTINUE); - } - cvode_steps_defined = true; - useLastLine = false; - break; - - case 8: // cvode_order - if (!(parser.get_iss() >> this->cvode_order)) - { - this->cvode_order = 5; - parser.incr_input_error(); - parser.error_msg("Expected integer value for cvode_order.", - PHRQ_io::OT_CONTINUE); - } - cvode_order_defined = true; - useLastLine = false; - break; - case 9: // equal steps - if (!(parser.get_iss() >> this->equal_steps)) - { - this->equal_steps = 0; - parser.incr_input_error(); - parser.error_msg("Expected integer value for equal_steps.", - PHRQ_io::OT_CONTINUE); - } - equal_steps_defined = true; - useLastLine = false; - break; - - } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) - break; - } - if (steps_defined) - { - this->steps = temp_steps; - } - if (check) - { - // members that must be defined - if (step_divide_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Step_divide not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (rk_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Rk not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (bad_step_max_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Bad_step_max not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (use_cvode_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (cvode_steps_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_steps not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (cvode_order_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Cvode_order not defined for KINETICS_RAW input.", - PHRQ_io::OT_CONTINUE); - } - // disable to remain backward compatible with PHAST restart files? - //if (equal_steps_defined == false) - //{ - // parser.incr_input_error(); - // parser.error_msg("Equal_steps not defined for KINETICS_RAW input.", - // PHRQ_io::OT_CONTINUE); - //} - } -} -#endif #ifdef USE_MPI void cxxKinetics::mpi_pack(std::vector < int >&ints, @@ -870,8 +510,6 @@ cxxKinetics::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) { cxxKineticsComp kc; kc.mpi_unpack(ints, &i, doubles, &d); - //std::string str(kc.get_rate_name()); - //this->kineticsComps[str] = kc; this->kineticsComps.push_back(kc); } n = ints[i++]; @@ -899,7 +537,6 @@ cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) { if (extensive == 0.0) return; - //std::map < std::string, cxxKineticsComp> kineticsComps; for (size_t i_add = 0; i_add < addee.kinetics_comps.size(); i_add++) { bool found(false); @@ -933,60 +570,6 @@ cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) this->equalIncrements = addee.equalIncrements; this->count = addee.count; } -#ifdef SKIP -void -cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) - // - // Add to existing ppassemblage to "this" ppassemblage - // -{ - if (extensive == 0.0) - return; - //std::map < std::string, cxxKineticsComp> kineticsComps; - for (size_t i = 0; i < kineticsComps.size(); i++) - for (std::list < cxxKineticsComp >::const_iterator itadd = - addee.kineticsComps.begin(); itadd != addee.kineticsComps.end(); - ++itadd) - { - bool found(false); - std::list < cxxKineticsComp >::iterator it; - for (it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) - { - if ((*it).Get_rate_name() == (*itadd).Get_rate_name()) - { - found = true; - break; - } - } - - //std::map < std::string, cxxKineticsComp >::iterator it = this->kineticsComps.find((*itadd).first); - if (found) - { - (*it).add((*itadd), extensive); - } - else - { - cxxKineticsComp entity = (*itadd); - entity.multiply(extensive); - this->kineticsComps.push_back(entity); - } - } - //std::vector steps; - this->steps = addee.steps; - //cxxNameDouble totals; - //LDBLE step_divide; - this->step_divide = addee.step_divide; - //int rk; - this->rk = addee.rk; - //int bad_step_max; - this->bad_step_max = addee.bad_step_max; - //bool use_cvode; - this->use_cvode = addee.use_cvode; - this->cvode_steps = addee.cvode_steps; - this->cvode_order = addee.cvode_order; - this->equal_steps = addee.equal_steps; -} -#endif cxxKineticsComp * cxxKinetics:: Find(const std::string &s) { @@ -1066,4 +649,4 @@ Current_step(bool incremental_reactions, int reaction_step) const } } return kin_time; -} \ No newline at end of file +} diff --git a/cxxKinetics.h b/cxxKinetics.h index af051407..62c1bf7f 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -17,7 +17,6 @@ class cxxKinetics:public cxxNumKeyword public: cxxKinetics(PHRQ_io *io=NULL); - //cxxKinetics(struct kinetics *, PHRQ_io *io=NULL); cxxKinetics(const std::map < int, cxxKinetics > &entity_map, cxxMix & mx, int n_user, PHRQ_io *io=NULL); ~cxxKinetics(); @@ -28,9 +27,6 @@ class cxxKinetics:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); - //bool Get_related_phases(void) const; - //bool Get_related_rate(void) const; - std::vector < LDBLE > &Get_steps(void) {return steps;} LDBLE Get_step_divide(void) const {return step_divide;} void Set_step_divide(LDBLE t) {step_divide = t;} @@ -63,17 +59,19 @@ class cxxKinetics:public cxxNumKeyword void add(const cxxKinetics & addee, LDBLE extensive); protected: + // KINETICS_MODIFY candidates std::vector < cxxKineticsComp > kinetics_comps; std::vector < LDBLE >steps; int count; bool equalIncrements; - cxxNameDouble totals; LDBLE step_divide; int rk; int bad_step_max; bool use_cvode; int cvode_steps; int cvode_order; + // internal variables + cxxNameDouble totals; }; #endif // !defined(CXXKINETICS_H_INCLUDED) diff --git a/cxxMix.cxx b/cxxMix.cxx index ba89c3d5..9caddb78 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -13,8 +13,6 @@ #include "cxxMix.h" #include "phqalloc.h" - - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -35,7 +33,6 @@ cxxMix::~cxxMix() void cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -70,7 +67,6 @@ cxxMix::dump_xml(std::ostream & s_oss, unsigned int indent) const const void cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const { - //const char ERR_MESSAGE[] = "Packing mix message: %s, element not found\n"; unsigned int i; s_oss.precision(DBL_DIG - 1); std::string indent0(""), indent1(""), indent2(""); @@ -84,7 +80,7 @@ cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const // Mix element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "MIX " << n_user_local << " " << this->description << "\n"; + s_oss << "MIX " << n_user_local << " " << this->description << "\n"; for (std::map < int, LDBLE >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) @@ -175,7 +171,6 @@ cxxMix::read_raw(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } - // members that must be defined } void cxxMix::Vectorize(std::vector &n, std::vector &f) { diff --git a/dumper.h b/dumper.h index 721b39b3..832e7bd5 100644 --- a/dumper.h +++ b/dumper.h @@ -12,7 +12,7 @@ class dumper: public PHRQ_base public: dumper(PHRQ_io *io=NULL); dumper(CParser & parser, PHRQ_io *io=NULL); - ~dumper(void); + virtual ~dumper(void); bool Read(CParser & parser); void SetAll(bool tf); std::string Get_file_name(void) { return(this->file_name); }; diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index af13bb9b..250cf2b8 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -26,6 +26,7 @@ warning_msg(const char *err_str) std::ostringstream msg; msg << "WARNING: " << err_str; phrq_io->warning_msg(msg.str().c_str()); + status_on = false; } return OK; @@ -156,7 +157,7 @@ fpunchf_end_row(const char *format) } return OK; } - +#ifdef ERROR_OSTREAM /* ---------------------------------------------------------------------- */ int Phreeqc:: process_file_names(int argc, char *argv[], std::istream **db_cookie, @@ -198,10 +199,6 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, { phrq_io->error_open(NULL); } -/* - * For now, set screen ostream to error ostream - */ - //phrq_io->Set_screen_ostream(phrq_io->Get_error_ostream()); /* * Open user-input file */ @@ -329,10 +326,6 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, } local_database_file->close(); delete local_database_file; - //if (local_database_file != NULL) - //{ - // if (phrq_io) phrq_io->Set_database_file(local_database_file); - //} screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); @@ -355,6 +348,198 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, } return 0; } +#else +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log) +/* ---------------------------------------------------------------------- */ +{ + int l; + char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; + char query[2 * MAX_LENGTH]; + char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; + char *env_ptr; + char *ptr; +/* + * Prepare error handling + */ + try { + if (phrq_io == NULL) + { + std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; + } +/* + * Prep for get_line + */ + max_line = MAX_LINE; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); +/* + * Open error ostream + */ + if (argc > 4) + { + if (!phrq_io->error_open(argv[4])) + { + error_string = sformatf( "Error opening file, %s.", argv[4]); + warning_msg(error_string); + } + } + else + { + phrq_io->error_open(NULL); + } +/* + * Open user-input file + */ + strcpy(query, "Name of input file?"); + std::ifstream * local_input_stream = NULL; + if (argc <= 1) + { + default_name[0] = '\0'; + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); + } + else + { + strcpy(default_name, argv[1]); + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); + } + screen_msg(sformatf("Input file: %s\n\n", default_name)); + strcpy(in_file, default_name); +/* + * Open file for output + */ + strcpy(query, "Name of output file?"); + ptr = default_name; + copy_token(token, &ptr, &l); + strcat(token, ".out"); + std::ofstream * local_output_stream; + if (argc <= 1) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, false); + } + else if (argc == 2) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + else if (argc >= 3) + { + strcpy(token, argv[2]); + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + screen_msg(sformatf("Output file: %s\n\n", token)); + strcpy(out_file, token); + phrq_io->Set_output_ostream(local_output_stream); +/* + * Open log file + */ + if (log == TRUE) + { + if (!phrq_io->log_open("phreeqc.log")) + { + error_msg("Can't open log file, phreeqc.log.", STOP); + } + } +/* + * Read input file for DATABASE keyword + */ + if (local_input_stream->is_open()) + { + phrq_io->push_istream(local_input_stream); + if (get_line() == KEYWORD) + { + ptr = line; + copy_token(token, &ptr, &l); + if (strcmp_nocase(token, "database") == 0) + { +#ifdef PHREEQ98 + user_database = string_duplicate(prefix_database_dir(ptr)); +#else + user_database = string_duplicate(ptr); +#endif + if (string_trim(user_database) == EMPTY) + { + warning_msg("DATABASE file name is missing; default database will be used."); + user_database = (char *) free_check_null(user_database); + } + } + } + phrq_io->pop_istream(); + } + else + { + delete local_input_stream; + error_string = sformatf( "Error opening file, %s.", in_file); + error_msg(error_string, STOP); + } + +/* + * Open data base + */ + strcpy(query, "Name of database file?"); + env_ptr = getenv("PHREEQC_DATABASE"); + if (user_database != NULL) + { + strcpy(token, user_database); + } + else if (env_ptr != NULL) + { + strcpy(token, env_ptr); + } + else + { + strcpy(token, default_data_base); + } + + std::ifstream * local_database_file; + if (argc <= 1) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, false); + } + else if (argc < 4) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + else if (argc >= 4) + { + if (user_database == NULL) + { + strcpy(token, argv[3]); + } + else + { +#ifndef PHREEQCI_GUI + warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); +#endif + } + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + local_database_file->close(); + delete local_database_file; + screen_msg(sformatf("Database file: %s\n\n", token)); + strcpy(db_file, token); + + output_msg(sformatf(" Input file: %s\n", in_file)); + output_msg(sformatf(" Output file: %s\n", out_file)); + output_msg(sformatf("Database file: %s\n\n", token)); + /* + * local cleanup + */ + user_database = (char *) free_check_null(user_database); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + *db_cookie = new std::ifstream(db_file, std::ios_base::in); + *input_cookie = new std::ifstream(in_file, std::ios_base::in); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} +#endif /* ---------------------------------------------------------------------- */ std::ifstream * Phreeqc:: open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) @@ -363,9 +548,11 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, char name[MAX_LENGTH]; std::ifstream *new_stream; int l; - - //std::ostream * screen_file_save = phrq_io->Get_screen_ostream(); - std::ostream * error_file_save = phrq_io->Get_error_ostream(); +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif for (;;) { @@ -375,9 +562,12 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, strcpy(name, default_name); if (!batch ) { - //phrq_io->Set_screen_ostream(&std::cerr); +#ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); - screen_msg(sformatf("%s\n", query));; +#else + phrq_io->Set_error_file(stderr); +#endif + screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') { screen_msg(sformatf("Default: %s\n", default_name)); @@ -396,11 +586,13 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, new_stream = new std::ifstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { - //phrq_io->Set_screen_ostream(&std::cerr); +#ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); screen_msg(error_string); - //screen_flush(); error_flush(); batch = FALSE; continue; @@ -410,8 +602,12 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, strncpy(default_name, name, MAX_LENGTH); if (!batch ) { - //phrq_io->Set_screen_ostream(screen_file_save); - phrq_io->Set_error_ostream(error_file_save); + //phrq_io->Set_error_ostream(error_file_save); +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif } return (new_stream); } @@ -423,10 +619,12 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode char name[MAX_LENGTH]; std::ofstream *new_stream; int l; - - //std::ostream * screen_file_save = phrq_io->Get_screen_ostream(); - std::ostream * error_file_save = phrq_io->Get_error_ostream(); - +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif + for (;;) { /* @@ -435,9 +633,13 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode strcpy(name, default_name); if (!batch ) { - //phrq_io->Set_screen_ostream(&std::cerr); +#ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); - screen_msg(sformatf("%s\n", query));; +#else + phrq_io->Set_error_file(stderr); +#endif + + screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') { screen_msg(sformatf("Default: %s\n", default_name)); @@ -456,11 +658,13 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode new_stream = new std::ofstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { - //phrq_io->Set_screen_ostream(&std::cerr); +#ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); - screen_msg( error_string); - //screen_flush(); + screen_msg(error_string); error_flush(); batch = FALSE; continue; @@ -470,39 +674,86 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode strncpy(default_name, name, MAX_LENGTH); if (!batch ) { - //phrq_io->Set_screen_ostream(screen_file_save); - phrq_io->Set_error_ostream(error_file_save); +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif } return (new_stream); } -// ---------------------------------------------------------------------- */ -// screen ostream methods -// ---------------------------------------------------------------------- */ #ifdef SKIP /* ---------------------------------------------------------------------- */ -bool Phreeqc:: -screen_open(const char *file_name) +std::ofstream * Phreeqc:: +open_output_file(char *query, char *default_name, std::ios_base::openmode mode, bool batch) /* ---------------------------------------------------------------------- */ { - if (phrq_io) + char name[MAX_LENGTH]; + std::ofstream *new_stream; + int l; +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif + + + for (;;) { - return this->phrq_io->screen_open(file_name); +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif + screen_msg(sformatf("%s\n", query)); + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ofstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif + + error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + screen_msg(error_string); + error_flush(); + batch = FALSE; + continue; + } + break; } - return false; -} -/* ---------------------------------------------------------------------- */ -void Phreeqc:: -screen_flush(void) -/* ---------------------------------------------------------------------- */ -{ - if (phrq_io) this->phrq_io->screen_flush(); -} -/* ---------------------------------------------------------------------- */ -void Phreeqc:: -screen_close(void) -/* ---------------------------------------------------------------------- */ -{ - if (phrq_io) this->phrq_io->screen_close(); + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif + } + return (new_stream); } #endif /* ---------------------------------------------------------------------- */ @@ -539,22 +790,7 @@ dump_close(void) { if (phrq_io) this->phrq_io->dump_close(); } -///* ---------------------------------------------------------------------- */ -//void Phreeqc:: -//dump_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) this->phrq_io->dump_rewind(); -//} -///* ---------------------------------------------------------------------- */ -//bool Phreeqc:: -//dump_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) -// return this->phrq_io->dump_isopen(); -// return false; -//} + /* ---------------------------------------------------------------------- */ void Phreeqc:: dump_msg(const char * str) @@ -589,22 +825,7 @@ error_close(void) { if (phrq_io) this->phrq_io->error_close(); } -///* ---------------------------------------------------------------------- */ -//void Phreeqc:: -//error_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) this->phrq_io->error_rewind(); -//} -///* ---------------------------------------------------------------------- */ -//bool Phreeqc:: -//error_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) -// return this->phrq_io->error_isopen(); -// return false; -//} + /* ---------------------------------------------------------------------- */ void Phreeqc:: error_msg(const char *err_str, bool stop) @@ -624,6 +845,7 @@ error_msg(const char *err_str, bool stop) { phrq_io->screen_msg("\n"); } + status_on = false; phrq_io->error_msg(msg.str().c_str(), stop); } @@ -659,22 +881,7 @@ log_close(void) { if (phrq_io) this->phrq_io->log_close(); } -///* ---------------------------------------------------------------------- */ -//void Phreeqc:: -//log_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) this->phrq_io->log_rewind(); -//} -///* ---------------------------------------------------------------------- */ -//bool Phreeqc:: -//log_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) -// return this->phrq_io->log_isopen(); -// return false; -//} + /* ---------------------------------------------------------------------- */ void Phreeqc:: log_msg(const char * str) @@ -709,22 +916,6 @@ output_close(void) { if (phrq_io) this->phrq_io->output_close(); } -///* ---------------------------------------------------------------------- */ -//void Phreeqc:: -//output_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) this->phrq_io->output_rewind(); -//} -///* ---------------------------------------------------------------------- */ -//bool Phreeqc:: -//output_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) -// return this->phrq_io->output_isopen(); -// return false; -//} /* ---------------------------------------------------------------------- */ void Phreeqc:: output_msg(const char * str) @@ -769,22 +960,6 @@ punch_close(void) { if (phrq_io) this->phrq_io->punch_close(); } -///* ---------------------------------------------------------------------- */ -//void Phreeqc:: -//punch_rewind(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) this->phrq_io->punch_rewind(); -//} -///* ---------------------------------------------------------------------- */ -//bool Phreeqc:: -//punch_isopen(void) -///* ---------------------------------------------------------------------- */ -//{ -// if (phrq_io) -// return this->phrq_io->punch_isopen(); -// return false; -//} /* ---------------------------------------------------------------------- */ void Phreeqc:: punch_msg(const char * str) diff --git a/phreeqc/advection.cpp b/phreeqc/advection.cpp index 7f69accf..276cb1a4 100644 --- a/phreeqc/advection.cpp +++ b/phreeqc/advection.cpp @@ -2,6 +2,7 @@ #include "Phreeqc.h" #include "phqalloc.h" #include "cxxKinetics.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ @@ -9,7 +10,7 @@ int Phreeqc:: advection(void) /* ---------------------------------------------------------------------- */ { - int i, n; + int i; LDBLE kin_time; /* * Calculate advection @@ -21,7 +22,8 @@ advection(void) */ for (i = 0; i <= count_ad_cells; i++) { - if (solution_bsearch(i, &n, TRUE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, i) == NULL) + //if (solution_bsearch(i, &n, TRUE) == NULL) { input_error++; error_string = sformatf( @@ -38,7 +40,6 @@ advection(void) { for (i = 1; i <= count_ad_cells; i++) { - //if (kinetics_bsearch(i, &n) != NULL) if (Utilities::Rxn_find(Rxn_kinetics_map, i) != NULL) { input_error++; @@ -82,7 +83,8 @@ advection(void) */ for (i = count_ad_cells; i > 0; i--) { - solution_duplicate(i - 1, i); + //solution_duplicate(i - 1, i); + Utilities::Rxn_copy(Rxn_solution_map, i -1, i); } /* * Equilibrate and (or) mix @@ -115,10 +117,12 @@ advection(void) print_all(); } if (i > 1) - solution_duplicate(-2, i - 1); + Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); + //solution_duplicate(-2, i - 1); saver(); } - solution_duplicate(-2, count_ad_cells); + Utilities::Rxn_copy(Rxn_solution_map, -2, count_ad_cells); + //solution_duplicate(-2, count_ad_cells); rate_sim_time_start += kin_time; } initial_total_time += rate_sim_time_start; diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 066aeba4..9b9b5d3b 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -1,6 +1,7 @@ #include "Phreeqc.h" #include "phqalloc.h" +#include "Utils.h" #include "../NameDouble.h" #include "../PBasic.h" #include "../Exchange.h" @@ -8,6 +9,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Parser.h" /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: activity(const char *species_name) @@ -133,8 +135,7 @@ calc_SC(void) return (SC); } - -/* VP: Density Start */ +#ifdef PHREEQC2 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_dens(void) @@ -153,14 +154,13 @@ calc_dens(void) LDBLE solution_mass, solution_volume; */ LDBLE rho_new, rho_old; - LDBLE e_T, M_T; + LDBLE M_T; LDBLE a, b, c, d, e, f; LDBLE phi_0_i, b_v_i, s_v_i, PHI_v, B_v, S_v; /* LDBLE k, I_m, I_v; LDBLE AA_basic, BB, CC; */ - LDBLE k; LDBLE gfw; int l_z; struct species *s_ptr; @@ -173,7 +173,6 @@ calc_dens(void) rho_new = rho_0; rho_old = 0.0; - e_T = 0.0; M_T = 0.0; I_m = 0.0; PHI_v = 0.0; @@ -221,40 +220,19 @@ calc_dens(void) PHI_v += (species_list[i].s->moles * phi_0_i); B_v += (species_list[i].s->moles * b_v_i); S_v += (species_list[i].s->moles * l_z * (s_v_i * l_z / 2)); - - if (l_z == 0) e_T += (species_list[i].s->moles * 2); /* For uncharged species like H4SiO4 (times 2 because e_T is divided by 2 later on) */ - else e_T += (species_list[i].s->moles * l_z); M_T += (species_list[i].s->moles * gfw); I_m += (species_list[i].s->moles * (l_z * l_z)); } /* If pure water then return rho_0 */ if (PHI_v == 0) - return rho_0; + return rho_0; solution_mass = mass_water_aq_x * 1000 + M_T; - e_T /= 2; - M_T /= e_T; I_m /= 2; - PHI_v /= e_T; - B_v /= e_T; - S_v /= e_T; - - k = e_T / I_m; - AA_basic = k * (M_T - rho_0 * PHI_v); - BB_basic = -k * rho_0 * S_v; - CC = -k * rho_0 * B_v; - -/* DP: Replace Pickard iteration with interval halving */ -#ifdef SKIP - do { - rho_old = rho_new; - solution_volume = solution_mass / rho_new / 1000; - if (solution_volume != 0) I_v = I_m / solution_volume; - rho_new = AA_basic * I_v + BB_basic * exp(1.5 * log(I_v)) + CC * exp(2 * log(I_v)); /* exp/log is used for exponentiation */ - rho_new = rho_new / 1000 + rho_0; - } while ((fabs(rho_new - rho_old) > 1.0e-6) && (rho_new < 1.99999)); -#endif + AA_basic = M_T - rho_0 * PHI_v; + BB_basic = -rho_0 * S_v; + CC = -rho_0 * B_v; rho_new = halve(f_rho, 0.5, 2.0, 1e-7); /* DP: End Replace Pickard iteration with interval halving */ @@ -276,14 +254,127 @@ f_rho(LDBLE rho_old, void *cookie) pThis = (Phreeqc *) cookie; pThis->solution_volume = pThis->solution_mass / rho_old / 1000; - I_v = 1.0; + rho = 1e3; if (pThis->solution_volume != 0) - I_v = pThis->I_m / pThis->solution_volume; - rho = I_v * (pThis->AA_basic + pThis->BB_basic * sqrt(I_v) + pThis->CC * (I_v)); + { + I_v = pThis->I_m / pThis->solution_volume; // Ionic Strength in mol/L + rho = (pThis->AA_basic + pThis->BB_basic * sqrt(I_v) + pThis->CC * I_v) / pThis->solution_volume; + } rho = rho / 1000 + pThis->rho_0; return (rho - rho_old); } +#else +/* VP: Density Start */ +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_dens(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates density based on the formulas and parameters from Millero, + * 2000. + * + * Millero, F.J. (2000) The equation of state of lakes. Aquatic geochemistry + * volume 6, pages 1-17 + */ + int i; + LDBLE M_T, rho_new, gfw; + /* 2 options: original VP, assign the volumes of species with zero molar volume to their master species, + but this doubles counts of complexes with -Vm defined. And, cation-OH and H-anion + complexes are counted once. Also, must add H+ and OH-... */ + //struct species *s_ptr; + //V_solutes = M_T = 0.0; + //for (i = 0; i < count_species_list; i++) + //{ + // if (species_list[i].s->type != AQ && species_list[i].s->type != HPLUS) + // continue; + + // //if (species_list[i].master_s->secondary != NULL) + // // gfw = species_list[i].master_s->secondary->gfw; + // //else + // // gfw = species_list[i].master_s->primary->gfw; + + // /* OH-... */ + // if (!strcmp(species_list[i].s->name, "OH-")) + // s_ptr = s_search("OH-"); + // else if (species_list[i].s->logk[vm_tc] == 0) + // { + // s_ptr = species_list[i].master_s; + // if (s_ptr->secondary) + // gfw = s_ptr->secondary->gfw; + // else + // gfw = s_ptr->primary->gfw; + // } + // else + // { + // s_ptr = species_list[i].s; + // compute_gfw(species_list[i].s->name, &gfw); + // } + + // /* Special case: CO3-2 species */ + // if (strcmp(s_ptr->name, "CO3-2") == 0) + // { + // if (strstr(species_list[i].s->name, "HCO3") != NULL) + // { + // s_ptr = s_search("HCO3-"); + // } else if (strstr(species_list[i].s->name, "CO3") != NULL) + // { + // compute_gfw("CO3-2", &gfw); + // } + // } + // if (!gfw || !strcmp(species_list[i].s->name, "CO2")) /* CO2, H+ and OH- */ + // compute_gfw(species_list[i].s->name, &gfw); + + // M_T += (species_list[i].s->moles * gfw); + // V_solutes += species_list[i].s->moles * s_ptr->logk[vm_tc]; + //} + + /* 2nd option, use species_x, vm = 0 for complexes with undefined volume... */ + V_solutes = M_T = 0.0; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) + continue; + + compute_gfw(s_x[i]->name, &gfw); + M_T += s_x[i]->moles * gfw; + V_solutes += s_x[i]->moles * s_x[i]->logk[vm_tc]; + } + /* If pure water then return rho_0 */ + if (M_T == 0) + return rho_0; + + M_T /= 1e3; + solution_mass = mass_water_aq_x + M_T; + V_solutes = M_T - rho_0 * V_solutes / 1e3; + + rho_new = halve(f_rho, 0.5, 2.0, 1e-7); + if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999; + + return rho_new; +} +/* VP: Density End */ +/* DP: Function for interval halving */ + +LDBLE Phreeqc:: +f_rho(LDBLE rho_old, void *cookie) +/* ---------------------------------------------------------------------- */ +{ + LDBLE rho = 1.0; + Phreeqc * pThis; + + pThis = (Phreeqc *) cookie; + + pThis->solution_volume = pThis->solution_mass / rho_old; + if (pThis->solution_volume != 0) + { + rho = pThis->V_solutes / pThis->solution_volume; + } + rho = rho + pThis->rho_0; + return (rho - rho_old); +} +#endif /* DP: End function for interval halving */ /* ---------------------------------------------------------------------- */ @@ -411,7 +502,6 @@ calc_surface_charge(const char *surface_name) } return (charge); } - /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: diff_layer_total(const char *total_name, const char *surface_name) @@ -420,17 +510,14 @@ diff_layer_total(const char *total_name, const char *surface_name) /* * Provides total moles in DDL layer */ - int i, j, k, count_g; - struct surface_charge *surface_charge_ptr1; - char name[MAX_LENGTH], token[MAX_LENGTH]; - char surface_name_local[MAX_LENGTH]; - char *ptr; + cxxSurfaceCharge *surface_charge_ptr1; + std::string name, token, surface_name_local; struct master *master_ptr; LDBLE mass_water_surface; LDBLE molality, moles_excess, moles_surface, charge; - if (use.Get_surface_ptr() == NULL || (dl_type_x == NO_DL && + if (use.Get_surface_ptr() == NULL || (dl_type_x == cxxSurface::NO_DL && strcmp_nocase("psi", total_name) != 0 && strcmp_nocase("psi1", total_name) != 0 && strcmp_nocase("psi2", total_name) != 0 && @@ -450,36 +537,36 @@ diff_layer_total(const char *total_name, const char *surface_name) /* * Find surface... */ - i = 0; + int j; for (j = 0; j < count_unknowns; j++) { - /*if (use.Get_surface_ptr()->edl == TRUE) { */ - if (use.Get_surface_ptr()->type == DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); + name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); } - else if (use.Get_surface_ptr()->type == CD_MUSIC) + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); + name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); } else { if (x[j]->type != SURFACE) continue; - strcpy(token, x[j]->master[0]->elt->name); - replace("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); + token = x[j]->master[0]->elt->name; + Utilities::replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + CParser::copy_token(token, b, e); } if (surface_name != NULL) { - if (strcmp(name, surface_name) == 0) + if (strcmp(name.c_str(), surface_name) == 0) break; } else @@ -489,24 +576,22 @@ diff_layer_total(const char *total_name, const char *surface_name) } if (j >= count_unknowns) return (0); - strcpy(surface_name_local, name); + surface_name_local = name; /* * Psi, charge, sigma */ if (strcmp_nocase("psi", total_name) == 0) { - /*if (use.Get_surface_ptr()->edl == TRUE) { */ - if (use.Get_surface_ptr()->type == DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { return ((LDBLE) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ)); } - else if (use.Get_surface_ptr()->type == CD_MUSIC) + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { master_ptr = surface_get_psi_master(surface_name, SURF_PSI); if (master_ptr != NULL) { - /*return((LDBLE) (-x[j]->surface_charge->psi_master->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ)); */ return ((LDBLE) (-master_ptr->s->la * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ)); @@ -551,30 +636,30 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("charge", total_name) == 0) { - if (use.Get_surface_ptr()->type == DDL && dl_type_x == NO_DL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL && dl_type_x == cxxSurface::NO_DL) { return ((LDBLE) (x[j]->f)); } - else if (use.Get_surface_ptr()->type == CD_MUSIC) + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) - (x[j]->surface_charge->sigma0 * - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) / F_C_MOL)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((charge_ptr->Get_sigma0() * + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL)); } else { - return (calc_surface_charge(surface_name_local)); + return (calc_surface_charge(surface_name_local.c_str())); } } else if (strcmp_nocase("charge1", total_name) == 0) { - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) - (x[j]->surface_charge->sigma1 * - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) / F_C_MOL)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((charge_ptr->Get_sigma1() * + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL)); } else { @@ -583,12 +668,12 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("charge2", total_name) == 0) { - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) - (x[j]->surface_charge->sigma2 * - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) / F_C_MOL)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((charge_ptr->Get_sigma2() * + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL)); } else { @@ -597,32 +682,33 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("sigma", total_name) == 0) { - if (use.Get_surface_ptr()->type == DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { - if (dl_type_x != NO_DL) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + if (dl_type_x != cxxSurface::NO_DL) { - charge = calc_surface_charge(surface_name_local); + charge = calc_surface_charge(surface_name_local.c_str()); } else { charge = x[j]->f; } - if ((x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) > 0) + if ((charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) > 0) { - return ((LDBLE) - (charge * F_C_MOL / - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams))); + return ((charge * F_C_MOL / + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()))); } else { return (0); } } - else if (use.Get_surface_ptr()->type == CD_MUSIC) + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) (x[j]->surface_charge->sigma0)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((LDBLE) (charge_ptr->Get_sigma0())); } else { @@ -631,9 +717,10 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("sigma1", total_name) == 0) { - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) (x[j]->surface_charge->sigma1)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((LDBLE) (charge_ptr->Get_sigma1())); } else { @@ -642,9 +729,10 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("sigma2", total_name) == 0) { - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - return ((LDBLE) (x[j]->surface_charge->sigma2)); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return ((LDBLE) (charge_ptr->Get_sigma2())); } else { @@ -653,9 +741,10 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("water", total_name) == 0) { - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { - return (x[j]->surface_charge->mass_water); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + return (charge_ptr->Get_mass_water()); } else { @@ -665,43 +754,43 @@ diff_layer_total(const char *total_name, const char *surface_name) /* * find total moles of each element in diffuse layer... */ - surface_charge_ptr1 = x[j]->surface_charge; - mass_water_surface = surface_charge_ptr1->mass_water; - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) + surface_charge_ptr1 = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + if (surface_charge_ptr1) { - if (s_x[j]->type > HPLUS) - continue; - molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; + mass_water_surface = surface_charge_ptr1->Get_mass_water(); + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + LDBLE g = surface_charge_ptr1->Get_g_map()[s_x[j]->z].Get_g(); - moles_excess = - mass_water_aq_x * molality * (surface_charge_ptr1->g[count_g].g * - s_x[j]->erm_ddl + + moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - - 1)); - moles_surface = mass_water_surface * molality + moles_excess; + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + moles_surface = mass_water_surface * molality + moles_excess; /* * Accumulate elements in diffuse layer */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), Phreeqc:: elt_list_compare); - elt_list_combine(); - } + add_elt_list(s_x[j]->next_elt, moles_surface); + } + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), Phreeqc:: elt_list_compare); + elt_list_combine(); + } /* * Return totals */ - for (j = 0; j < count_elts; j++) - { - if (strcmp(elt_list[j].elt->name, total_name) == 0) + for (j = 0; j < count_elts; j++) { - return ((LDBLE) elt_list[j].coef); + if (strcmp(elt_list[j].elt->name, total_name) == 0) + { + return ((LDBLE) elt_list[j].coef); + } } } return (0); @@ -728,7 +817,7 @@ equi_phase(const char *phase_name) /* * Print pure phase assemblage data */ - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); if (j == count_unknowns) { /* if not an unknown */ @@ -761,7 +850,7 @@ find_gas_comp(const char *gas_comp_name) if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) return (0); - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { if (strcmp_nocase(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), gas_comp_name) == 0) @@ -782,7 +871,7 @@ find_gas_p(void) { if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) return (0); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { if (gas_unknown == NULL) @@ -799,7 +888,7 @@ find_gas_vm(void) { if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) return (0); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { if (gas_unknown == NULL) @@ -815,8 +904,6 @@ LDBLE Phreeqc:: find_misc1(const char *ss_name) /* ---------------------------------------------------------------------- */ { - //int j; - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) return (0.0); std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); @@ -843,8 +930,6 @@ LDBLE Phreeqc:: find_misc2(const char *ss_name) /* ---------------------------------------------------------------------- */ { - //int j; - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) return (0.0); std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); @@ -871,8 +956,6 @@ LDBLE Phreeqc:: find_ss_comp(const char *ss_comp_name) /* ---------------------------------------------------------------------- */ { - //int i, j; - if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) return (0); @@ -926,15 +1009,7 @@ get_calculate_value(const char *name) error_msg(error_string, CONTINUE); return (MISSING); } - //if (calculate_value_ptr->calculated == FALSE) - //{ - // error_string = sformatf( - // "Calculated value used before it has been calculated, %s.\nCalculated values are evalutated in the order in which they were defined.", - // name); - // input_error++; - // error_msg(error_string, CONTINUE); - // return (MISSING); - //} + char l_command[] = "run"; PBasic interp(this, this->phrq_io); if (calculate_value_ptr->new_def == TRUE) @@ -998,31 +1073,7 @@ kinetics_moles(const char *kinetics_name) warning_msg(error_string); return (0); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -kinetics_moles(const char *kinetics_name) -/* ---------------------------------------------------------------------- */ -{ - int i; - if (use.Get_kinetics_in() == FALSE || use.Get_kinetics_ptr() == NULL) - return (0); - for (i = 0; i < use.Get_kinetics_ptr()->count_comps; i++) - { - if (strcmp_nocase - (use.Get_kinetics_ptr()->comps[i].rate_name, kinetics_name) == 0) - { - return (use.Get_kinetics_ptr()->comps[i].m); - } - } - - error_string = sformatf( "No data for rate %s in KINETICS keyword.", - kinetics_name); - warning_msg(error_string); - return (0); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: log_activity(const char *species_name) @@ -1227,7 +1278,7 @@ sum_match_gases(const char *mytemplate, const char *name) if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL) return (0); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); tot = 0; for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { @@ -1296,7 +1347,6 @@ LDBLE Phreeqc:: sum_match_ss(const char *mytemplate, const char *name) /* ---------------------------------------------------------------------- */ { - //int i, j; LDBLE tot; struct elt_list *next_elt; @@ -1346,8 +1396,6 @@ LDBLE Phreeqc:: list_ss(std::string ss_name, cxxNameDouble &composition) /* ---------------------------------------------------------------------- */ { - //int i, j; - LDBLE tot = 0; composition.clear(); if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL) @@ -2237,7 +2285,7 @@ system_total_gas(void) */ if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), @@ -2261,7 +2309,6 @@ system_total_ss(void) /* * Provides total moles in system and lists of species/phases in sort order */ - //int i, k; /* * Solid solutions @@ -2296,7 +2343,7 @@ system_total_elt(const char *total_name) /* * Provides total moles in system and lists of species/phases in sort order */ - int i, j, k, count_g; + int i, j, k; LDBLE molality, moles_excess, moles_surface, mass_water_surface; char name[MAX_LENGTH]; @@ -2363,7 +2410,7 @@ system_total_elt(const char *total_name) } } } - if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL) { /* * Find position of component in surface charge data @@ -2373,12 +2420,13 @@ system_total_elt(const char *total_name) { if (x[k]->type != SURFACE_CB) continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[k]->surface_charge); i++; /* * Loop through all surface components, calculate each H2O surface (diffuse layer), * H2O aq, and H2O bulk (diffuse layers plus aqueous). */ - mass_water_surface = x[k]->surface_charge->mass_water; + mass_water_surface = charge_ptr->Get_mass_water(); count_elts = 0; paren_count = 0; for (j = 0; j < count_s_x; j++) @@ -2386,10 +2434,9 @@ system_total_elt(const char *total_name) if (s_x[j]->type > HPLUS) continue; molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; moles_excess = mass_water_aq_x * molality * - (x[k]->surface_charge->g[count_g].g * s_x[j]->erm_ddl + + (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * s_x[j]->erm_ddl + mass_water_surface / mass_water_aq_x * (s_x[j]->erm_ddl - 1)); moles_surface = mass_water_surface * molality + moles_excess; @@ -2430,7 +2477,7 @@ system_total_elt(const char *total_name) */ if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < count_unknowns; i++) { if (x[i]->type != PP) @@ -2518,7 +2565,7 @@ system_total_elt(const char *total_name) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { struct phase *phase_ptr = @@ -2566,7 +2613,7 @@ system_total_elt_secondary(const char *total_name) /* * Provides total moles in system and lists of species/phases in sort order */ - int i, j, k, l, count_g; + int i, j, k, l; LDBLE molality, moles_excess, moles_surface, mass_water_surface, sum, coef; char name[MAX_LENGTH]; @@ -2634,7 +2681,7 @@ system_total_elt_secondary(const char *total_name) } } } - if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL) { /* * Find position of component in surface charge data @@ -2644,12 +2691,13 @@ system_total_elt_secondary(const char *total_name) { if (x[k]->type != SURFACE_CB) continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[k]->surface_charge); i++; /* * Loop through all surface components, calculate each H2O surface (diffuse layer), * H2O aq, and H2O bulk (diffuse layers plus aqueous). */ - mass_water_surface = x[k]->surface_charge->mass_water; + mass_water_surface = charge_ptr->Get_mass_water(); sum = 0; for (j = 0; j < count_s_x; j++) { @@ -2671,10 +2719,9 @@ system_total_elt_secondary(const char *total_name) if (s_x[j]->type > H2O) continue; molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; moles_excess = mass_water_aq_x * molality * - x[k]->surface_charge->g[count_g].g; + charge_ptr->Get_g_map()[s_x[j]->z].Get_g(); moles_surface = mass_water_surface * molality + moles_excess; sum += moles_surface * coef; @@ -2701,13 +2748,11 @@ system_total_elt_secondary(const char *total_name) */ if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < count_unknowns; i++) { if (x[i]->type != PP) continue; - //if (x[i]->pure_phase->add_formula != NULL) - // continue; std::map::iterator it; it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); if (it->second.Get_add_formula().size() > 0) @@ -2791,7 +2836,7 @@ system_total_elt_secondary(const char *total_name) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { struct phase *phase_ptr = @@ -2905,14 +2950,12 @@ system_total_solids(cxxExchange *exchange_ptr, cxxPPassemblage *pp_assemblage_ptr, cxxGasPhase *gas_phase_ptr, cxxSSassemblage *ss_assemblage_ptr, - struct surface *surface_ptr) + cxxSurface *surface_ptr) /* ---------------------------------------------------------------------- */ { /* * Provides total moles in solid phases */ - int i; - count_elts = 0; paren_count = 0; /* @@ -2920,17 +2963,16 @@ system_total_solids(cxxExchange *exchange_ptr, */ if (exchange_ptr != NULL) { - std::map::iterator it = exchange_ptr->Get_exchComps().begin(); - for ( ; it != exchange_ptr->Get_exchComps().end(); it++) + for (size_t i = 0; i < exchange_ptr->Get_exchange_comps().size(); i++) { - add_elt_list(it->second.Get_totals(), 1.0); + add_elt_list(exchange_ptr->Get_exchange_comps()[i].Get_totals(), 1.0); } } if (surface_ptr != NULL) { - for (i = 0; i < surface_ptr->count_comps; i++) + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { - add_elt_list(surface_ptr->comps[i].totals, 1.0); + add_elt_list(surface_ptr->Get_surface_comps()[i].Get_totals(), 1.0); } } if (ss_assemblage_ptr != NULL) @@ -2953,6 +2995,7 @@ system_total_solids(cxxExchange *exchange_ptr, { for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { + int i; struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &i, FALSE); add_elt_list(phase_ptr->next_elt, gas_phase_ptr->Get_gas_comps()[j].Get_moles()); @@ -2969,11 +3012,6 @@ system_total_solids(cxxExchange *exchange_ptr, add_elt_list(phase_ptr->next_elt, it->second.Get_moles()); } - //for (i = 0; i < pp_assemblage_ptr->count_comps; i++) - //{ - // add_elt_list(pp_assemblage_ptr->pure_phases[i].phase->next_elt, - // pp_assemblage_ptr->pure_phases[i].moles); - //} } if (count_elts > 0) diff --git a/phreeqc/cl1mp.cpp b/phreeqc/cl1mp.cpp index 573dfc10..5ea0a8fa 100644 --- a/phreeqc/cl1mp.cpp +++ b/phreeqc/cl1mp.cpp @@ -4,7 +4,6 @@ #include #include -//#define Phreeqc:: Phreeqc:: #include "Phreeqc.h" #include "phqalloc.h" #include "phrqtype.h" diff --git a/phreeqc/cvode.cpp b/phreeqc/cvode.cpp index 2abf8cc7..33dd970e 100644 --- a/phreeqc/cvode.cpp +++ b/phreeqc/cvode.cpp @@ -3291,16 +3291,12 @@ CVHandleFailure(CVodeMem cv_mem, int kflag) { case REP_ERR_FAIL: { - //sprintf(error_string_long, MSG_ERR_FAILS, (double) tn, (double) h); - //CVMEM warning_msg(error_string_long); char * error_string = CVMEM sformatf(MSG_ERR_FAILS, (double) tn, (double) h); CVMEM warning_msg(error_string); } return (ERR_FAILURE); case REP_CONV_FAIL: { - //sprintf(error_string_long, MSG_CONV_FAILS, (double) tn, (double) h); - //CVMEM warning_msg(error_string_long); char * error_string = CVMEM sformatf(MSG_CONV_FAILS, (double) tn, (double) h); CVMEM warning_msg(error_string); } @@ -3308,16 +3304,12 @@ CVHandleFailure(CVodeMem cv_mem, int kflag) return (CONV_FAILURE); case SETUP_FAILED: { - //sprintf(error_string_long, MSG_SETUP_FAILED, (double) tn); - //CVMEM warning_msg(error_string_long); char * error_string = CVMEM sformatf(MSG_SETUP_FAILED, (double) tn); CVMEM warning_msg(error_string); } return (SETUP_FAILURE); case SOLVE_FAILED: - { - //sprintf(error_string_long, MSG_SOLVE_FAILED, (double) tn); - //CVMEM warning_msg(error_string_long); + { char * error_string = CVMEM sformatf(MSG_SOLVE_FAILED, (double) tn); CVMEM warning_msg(error_string); } diff --git a/phreeqc/gases.cpp b/phreeqc/gases.cpp index da997025..424dce84 100644 --- a/phreeqc/gases.cpp +++ b/phreeqc/gases.cpp @@ -9,24 +9,21 @@ setup_fixed_volume_gas(void) * Fill in data for gas phase unknown (sum of partial pressures) * in unknown structure */ - //int i; if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); /* * One for each gas component */ gas_unknowns.clear(); gas_unknown = NULL; gas_phase_ptr->Set_total_moles(0); - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { const cxxGasComp *comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); int j; struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_phase_name().c_str(), &j, FALSE); x[count_unknowns]->type = GAS_MOLES; - //x[count_unknowns]->description = string_hsave("gas moles"); x[count_unknowns]->description = phase_ptr->name; x[count_unknowns]->phase = phase_ptr; x[count_unknowns]->moles = comp_ptr->Get_moles(); @@ -35,7 +32,6 @@ setup_fixed_volume_gas(void) x[count_unknowns]->moles = MIN_TOTAL; } x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); - //x[count_unknowns]->gas_phase = use.Get_gas_phase_ptr(); gas_unknowns.push_back(x[count_unknowns]); gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + x[count_unknowns]->moles); x[count_unknowns]->phase->moles_x = x[count_unknowns]->moles; @@ -61,19 +57,15 @@ build_fixed_volume_gas(void) * sum of partial pressures equation and * mass balance equations for elements contained in gases */ - //int i, j; int row, col; struct master *master_ptr; struct rxn_token *rxn_ptr; - //struct gas_comp *gas_comp_ptr; - //struct phase *phase_ptr; struct unknown *unknown_ptr; LDBLE coef, coef_elt; if (gas_unknown == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { const cxxGasComp *comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); @@ -127,7 +119,6 @@ build_fixed_volume_gas(void) if (unknown_ptr != NULL) { coef = elt_list[j].coef; - //store_mb(&(gas_comp_ptr->phase->moles_x), &(unknown_ptr->f), coef); store_mb(&(gas_unknowns[i]->moles), &(unknown_ptr->f), coef); if (debug_prep == TRUE) { @@ -203,8 +194,6 @@ build_fixed_volume_gas(void) "Element needed for gas component, %s, is not in model.", phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; continue; } if (debug_prep == TRUE) @@ -226,8 +215,6 @@ build_fixed_volume_gas(void) } col = master_ptr->unknown->number; coef = coef_elt * rxn_ptr->coef; - //store_jacob(&(gas_comp_ptr->phase->moles_x), - // &(array[row + col]), coef); store_jacob(&(gas_unknowns[i]->moles), &(array[row + col]), coef); if (debug_prep == TRUE) @@ -271,8 +258,6 @@ build_fixed_volume_gas(void) "Element in species, %s, in phase, %s, is not in model.", rxn_ptr->s->name, phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; } else { @@ -311,8 +296,6 @@ build_fixed_volume_gas(void) "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; } col = master_ptr->unknown->number; coef = rxn_ptr->coef; @@ -356,7 +339,6 @@ calc_PR(void) pr_si_f = log10(phi_i) - Delta_V_i * (P - 1) / (2.303 * R * TK); */ { - //int i, i1; LDBLE T_c, P_c; LDBLE A, B, B_r, /*b2,*/ kk, oo, a_aa, T_r; LDBLE m_sum, /*b_sum, a_aa_sum,*/ a_aa_sum2; @@ -378,7 +360,7 @@ calc_PR(void) { error_msg("No gas unknowns.", STOP); } - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); for (i = 0; i < gas_unknowns.size(); i++) { @@ -613,7 +595,7 @@ calc_fixed_volume_gas_pressures(void) */ if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); gas_phase_ptr->Set_total_moles(0); for (i = 0; i < gas_unknowns.size(); i++) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index f2817011..e90a7af9 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -1,14 +1,14 @@ #ifndef _INC_GLOBAL_STRUCTURES_H #define _INC_GLOBAL_STRUCTURES_H +#include "Surface.h" /* ---------------------------------------------------------------------- * #define DEFINITIONS * ---------------------------------------------------------------------- */ #ifndef NAN # define NAN -99999999 #endif -#define MISSING -9999.999 -//#define NA -98.765 /* NA = not available */ -#include "NA.h" +#define MISSING -9999.999 +#include "NA.h" /* NA = not available */ #define F_C_MOL 96493.5 /* C/mol or joule/volt-eq */ #define F_KJ_V_EQ 96.4935 /* kJ/volt-eq */ @@ -16,11 +16,12 @@ #define R_LITER_ATM 0.0820597 /* L-atm/deg-mol */ #define R_KCAL_DEG_MOL 0.00198726 /* kcal/deg-mol */ #define R_KJ_DEG_MOL 0.00831470 /* kJ/deg-mol */ -#define EPSILON 78.5 /* dialectric constant, dimensionless */ +#define EPSILON 78.5 /* dialectric constant, dimensionless. Is calculated as eps_r(P, T) in calc_dielectrics. Update the code?? */ #define EPSILON_ZERO 8.854e-12 /* permittivity of free space, C/V-m = C**2/m-J */ #define JOULES_PER_CALORIE 4.1840 #define PASCAL_PER_ATM 1.01325E5 /* conversion from atm to Pa */ #define AVOGADRO 6.02252e23 /* atoms / mole */ +#define pi 3.14159265358979 #define TRUE 1 #define FALSE 0 @@ -121,7 +122,6 @@ #define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in an equation */ #define MAX_PHASES 500 /* initial guess of number of phases defined */ -#define MAX_SOLUTION 10 /* The maximum number of solutions allowed */ #define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ #define MAX_STRINGS 3000 #define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ @@ -152,12 +152,6 @@ // typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; typedef enum { cm3_per_mol } DELTA_V_UNIT; -enum SURFACE_TYPE -{ UNKNOWN_DL, NO_EDL, DDL, CD_MUSIC, CCM }; -enum DIFFUSE_LAYER_TYPE -{ NO_DL, BORKOVEK_DL, DONNAN_DL }; -enum SITES_UNITS -{ SITES_ABSOLUTE, SITES_DENSITY }; enum entity_type { Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, Kinetics, Mix, Temperature, Pressure, UnKnown @@ -177,7 +171,11 @@ typedef enum { vm0, /* read: molar volume at tc = 0 */ vm1, /* read: coef * tc */ vm2, /* read: coef * tc * tc */ - kappa, /* read: compressibility coef * P */ + vm3, /* read: coef for I (ionic strength) */ + vm4, /* read: coef for I * tc */ + vm5, /* read: coef for I * tc * tc */ + kappa, /* read: compression constant, cm3/mol/atm */ + b_Av, /* read: b in z^2 * A_v * log(1 + b * I^0.5) / (2 * b), 0 if -Millero is used */ MAX_LOG_K_INDICES /* Keep this definition at the end of the enum */ } LOG_K_INDICES; /* HSEARCH(3C) */ @@ -251,12 +249,10 @@ struct model const char **add_formula; LDBLE *si; - /*int diffuse_layer; */ - /*int edl; */ - enum DIFFUSE_LAYER_TYPE dl_type; - enum SURFACE_TYPE surface_type; + cxxSurface::DIFFUSE_LAYER_TYPE dl_type; + cxxSurface::SURFACE_TYPE surface_type; int only_counter_ions; - /*int donnan; */ + LDBLE thickness; int count_surface_comp; const char **surface_comp; @@ -325,74 +321,6 @@ struct punch int charge_balance; int percent_error; }; -/* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ -struct surface -{ - int n_user; - int n_user_end; - int new_def; - /*int diffuse_layer; */ - /*int edl; */ - int only_counter_ions; - /*int donnan; */ - enum DIFFUSE_LAYER_TYPE dl_type; - enum SURFACE_TYPE type; - enum SITES_UNITS sites_units; - LDBLE thickness; - LDBLE debye_lengths; - LDBLE DDL_viscosity; /* viscosity relative to pure water */ - LDBLE DDL_limit; /* limits DDL water to this fraction of bulk water */ - char *description; - int solution_equilibria; - int n_solution; - int count_comps; - struct surface_comp *comps; - int count_charge; - struct surface_charge *charge; - int related_phases; - int related_rate; - int transport; /* transports comp's and charges if true */ -}; -struct surface_comp -{ - const char *formula; - struct elt_list *formula_totals; - LDBLE formula_z; - LDBLE moles; - struct master *master; - struct elt_list *totals; - LDBLE la; - int charge; - LDBLE cb; - const char *phase_name; - LDBLE phase_proportion; - const char *rate_name; - LDBLE Dw; /* diffusion coefficient in water, used in MCD. No transport if 0 */ -}; -struct surface_charge -{ - const char *name; - LDBLE specific_area; - LDBLE grams; - LDBLE charge_balance; - LDBLE mass_water; - struct elt_list *diffuse_layer_totals; - int count_g; - struct surface_diff_layer *g; /* stores g and dg/dXd for each ionic charge */ - LDBLE la_psi, la_psi1, la_psi2; - LDBLE psi, psi1, psi2; - LDBLE capacitance[2]; - LDBLE sigma0, sigma1, sigma2, sigmaddl; -}; -struct surface_diff_layer -{ - LDBLE charge; - LDBLE g; - LDBLE dg; - LDBLE psi_to_z; -}; struct Change_Surf { @@ -409,45 +337,7 @@ struct Charge_Group LDBLE z; LDBLE eq; }; -#ifdef SKIP -/* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ -struct kinetics -{ - int n_user; - int n_user_end; - char *description; - int count_comps; - struct kinetics_comp *comps; - int count_steps; - LDBLE *steps; - LDBLE step_divide; - /*char *units; */ - struct elt_list *totals; - int rk; - int bad_step_max; - int use_cvode; - int cvode_order; - int cvode_steps; -}; -struct kinetics_comp -{ - const char *rate_name; - struct name_coef *list; - int count_list; - /* struct phase *phase; */ - LDBLE tol; - LDBLE m; - LDBLE initial_moles; - LDBLE m0; - LDBLE moles; - int count_c_params; - const char **c_params; - int count_d_params; - LDBLE *d_params; -}; -#endif + /*---------------------------------------------------------------------- * Save *---------------------------------------------------------------------- */ @@ -606,62 +496,6 @@ struct list2 LDBLE coef; }; -/*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - struct solution - { - int new_def; - int n_user; - int n_user_end; - char *description; - LDBLE tc; - LDBLE ph; - LDBLE solution_pe; - LDBLE mu; - LDBLE ah2o; - LDBLE density; - LDBLE total_h; - LDBLE total_o; - LDBLE cb; - LDBLE mass_water; - LDBLE total_alkalinity; - const char *units; - struct pe_data *pe; - int default_pe; - struct conc *totals; - struct master_activity *master_activity; - int count_master_activity; - int count_isotopes; - struct isotope *isotopes; - struct master_activity *species_gamma; - int count_species_gamma; - LDBLE patm; - }; - struct master_activity - { - const char *description; - LDBLE la; - }; - struct conc - { - const char *description; - /*int skip; */ - LDBLE moles; - LDBLE input_conc; - const char *units; - const char *equation_name; - struct phase *phase; - LDBLE phase_si; - int n_pe; - const char *as; - LDBLE gfw; - }; - struct pe_data - { - const char *name; - struct reaction *rxn; - }; struct isotope { LDBLE isotope_number; @@ -751,6 +585,63 @@ struct rxn_token LDBLE coef; const char *name; }; +class cxxChemRxn +{ +public: + cxxChemRxn(void) + { + for (size_t i = 0; i < MAX_LOG_K_INDICES; i++) + { + logk[i] = 0.0; + } + for (size_t i = 0; i < 3; i++) + { + dz[i] =0.0; + } + } + cxxChemRxn(struct reaction *rxn) + { + for (size_t i = 0; i < MAX_LOG_K_INDICES; i++) + { + logk[i] = rxn->logk[i]; + } + for (size_t i = 0; i < 3; i++) + { + dz[i] = rxn->dz[i]; + } + struct rxn_token *next_token; + next_token = rxn->token; + while (next_token->s != NULL) + { + this->tokens.push_back(*next_token++); + } + } + ~cxxChemRxn(void) {} + LDBLE *Get_logk(void) {return this->logk;} + void Set_logk(LDBLE *d) + { + for (size_t i = 0; i < MAX_LOG_K_INDICES; i++) + { + logk[i] = d[i]; + } + + } + LDBLE *Get_dz(void) {return this->dz;} + void Set_dz(LDBLE *d) + { + for (size_t i = 0; i < 3; i++) + { + dz[i] = d[i]; + } + } + std::vector &Get_tokens(void) {return this->tokens;} + void Set_tokens(const std::vector &t) {this->tokens = t;} + +protected: + LDBLE logk[MAX_LOG_K_INDICES]; + LDBLE dz[3]; + std::vector tokens; +}; /*---------------------------------------------------------------------- * Species *---------------------------------------------------------------------- */ @@ -774,10 +665,10 @@ struct species LDBLE o; /* stoichiometric coefficient of O in species */ LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */ LDBLE lk; /* log10 k at working temperature */ - LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analytical expression */ + LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analytical expression + volume terms */ /* VP: Density Start */ - LDBLE millero[6]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ -/* VP: Density End */ + LDBLE millero[7]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ + /* VP: Density End */ DELTA_H_UNIT original_units; /* enum with original delta H units */ int count_add_logk; struct name_coef *add_logk; @@ -801,8 +692,6 @@ struct species struct reaction *rxn_x; /* reaction to be used in model */ LDBLE tot_g_moles; /* (1 + sum(g)) * moles */ LDBLE tot_dh2o_moles; /* sum(moles*g*Ws/Waq) */ - struct species_diff_layer *diff_layer; /* information related to diffuse layer factors for each - surface */ LDBLE cd_music[5]; LDBLE dz[3]; DELTA_V_UNIT original_deltav_units; @@ -819,16 +708,6 @@ struct logk LDBLE log_k_original[MAX_LOG_K_INDICES]; /* log kt0, delh, 5 coefficients analalytical expression */ DELTA_V_UNIT original_deltav_units; }; -struct species_diff_layer -{ - struct surface_charge *charge; - int count_g; - LDBLE g_moles; - LDBLE dg_g_moles; /* g_moles*dgterm */ - LDBLE dx_moles; - LDBLE dh2o_moles; /* moles*g*Ws/Waq */ - LDBLE drelated_moles; /* for related phase */ -}; /*---------------------------------------------------------------------- * Phases @@ -899,8 +778,7 @@ struct phase master species */ struct reaction *rxn_secondary; /* reaction writes master species in terms of secondary master species */ - struct reaction **pe_rxn; /* e- written in terms of redox couple (or e-), points - to location */ + const char * pe_rxn; int minor_isotope; }; /*---------------------------------------------------------------------- @@ -920,28 +798,22 @@ struct unknown struct master **master; struct phase *phase; LDBLE si; - //struct gas_phase *gas_phase; int n_gas_phase_user; - struct conc *total; struct species *s; - //struct exch_comp *exch_comp; const char * exch_comp; - //struct pure_phase *pure_phase; const char *pp_assemblage_comp_name; - //struct ss *s_s; - //struct ss_comp *s_s_comp; const char * ss_name; const char * ss_comp_name; int ss_comp_number; int ss_in; - struct surface_comp *surface_comp; + const char *surface_comp; + const char *surface_charge; LDBLE related_moles; struct unknown *potential_unknown, *potential_unknown1, *potential_unknown2; int count_comp_unknowns; struct unknown **comp_unknowns; /* list for CD_MUSIC of comps that contribute to 0 plane mass-balance term */ struct unknown *phase_unknown; - struct surface_charge *surface_charge; LDBLE mass_water; int dissolve_only; LDBLE inert_moles; diff --git a/phreeqc/input.cpp b/phreeqc/input.cpp index 7622fe97..9198f198 100644 --- a/phreeqc/input.cpp +++ b/phreeqc/input.cpp @@ -27,7 +27,6 @@ check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) /* ---------------------------------------------------------------------- */ { - //assert(get_istream() != NULL); if (phrq_io->get_istream() == NULL) return EOF; if (reading_database()) @@ -101,10 +100,8 @@ get_line(void) { PHRQ_io::LINE_TYPE j = phrq_io->get_line(); // check_key sets next_keyword - //int return_value = check_key(parser.line().c_str()); next_keyword = phrq_io->Get_m_next_keyword(); - // copy parser line to line and line_save // make sure there is enough space size_t l1 = strlen(phrq_io->Get_m_line().c_str()) + 1; diff --git a/phreeqc/integrate.cpp b/phreeqc/integrate.cpp index a8f88865..194db5a4 100644 --- a/phreeqc/integrate.cpp +++ b/phreeqc/integrate.cpp @@ -1,6 +1,7 @@ #include "Phreeqc.h" #include "phqalloc.h" - +#include "Utils.h" +#include "Solution.h" #define MAX_QUAD 20 #define K_POLY 5 @@ -10,9 +11,7 @@ int Phreeqc:: calc_all_g(void) /* ---------------------------------------------------------------------- */ { - int i, j, k; int converge, converge1; - int count_g, count_charge; LDBLE new_g, xd1; LDBLE epsilon; @@ -32,124 +31,111 @@ calc_all_g(void) } converge = TRUE; - count_charge = 0; - for (j = 0; j < count_unknowns; j++) + + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; if (debug_diffuse_layer == TRUE) output_msg(sformatf( "Calc_all_g, X[%d]\n", j)); - surface_charge_ptr = x[j]->surface_charge; - count_g = 1; - x[j]->surface_charge->g[0].charge = 0.0; - x[j]->surface_charge->g[0].g = 0.0; - x[j]->surface_charge->g[0].dg = 0.0; - xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + std::map temp_g_map; + cxxSurfDL temp_g; + charge_ptr->Get_g_map()[0] = temp_g; + temp_g_map[0] = temp_g; + xd_global = exp(-2 * x[j]->master[0]->s->la * LOG_10); /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ /* 1000 J/kJ and 1000 L/m**3 */ - alpha = - sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * + alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); /* * calculate g for given surface for each species */ - for (i = 0; i < count_s_x; i++) + for (int i = 0; i < count_s_x; i++) { if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) - { - if (equal - (x[j]->surface_charge->g[k].charge, s_x[i]->z, - G_TOL) == TRUE) - { - s_x[i]->diff_layer[count_charge].charge = - x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - break; - } - } - if (k < count_g) + if (temp_g_map.find(s_x[i]->z) != temp_g_map.end()) continue; - - if (x[j]->surface_charge->grams > 0.0) + z_global = s_x[i]->z; + if (charge_ptr->Get_grams() > 0.0) { - z = s_x[i]->z; - if ((use.Get_surface_ptr()->only_counter_ions == FALSE) || - (((x[j]->master[0]->s->la > 0) && (z < 0)) - || ((x[j]->master[0]->s->la < 0) && (z > 0)))) + + if ((use.Get_surface_ptr()->Get_only_counter_ions() == false) || + (((x[j]->master[0]->s->la > 0) && (z_global < 0)) + || ((x[j]->master[0]->s->la < 0) && (z_global > 0)))) { - if (xd > 0.1) + if (xd_global > 0.1) { - new_g = qromb_midpnt(1.0, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, xd_global); } - else if (xd > 0.01) + else if (xd_global > 0.01) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, xd_global); } - else if (xd > 0.001) + else if (xd_global > 0.001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, xd_global); } - else if (xd > 0.0001) + else if (xd_global > 0.0001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, xd_global); } - else if (xd > 0.00001) + else if (xd_global > 0.00001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, .0001); - new_g += qromb_midpnt(0.0001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, .0001); + new_g += qromb_midpnt(charge_ptr, 0.0001, xd_global); } - else if (xd > 0.000001) + else if (xd_global > 0.000001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, .0001); - new_g += qromb_midpnt(0.0001, .00001); - new_g += qromb_midpnt(0.00001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, .0001); + new_g += qromb_midpnt(charge_ptr, 0.0001, .00001); + new_g += qromb_midpnt(charge_ptr, 0.00001, xd_global); } - else if (xd > 0.0000001) + else if (xd_global > 0.0000001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, .0001); - new_g += qromb_midpnt(0.0001, .00001); - new_g += qromb_midpnt(0.00001, .000001); - new_g += qromb_midpnt(0.000001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, .0001); + new_g += qromb_midpnt(charge_ptr, 0.0001, .00001); + new_g += qromb_midpnt(charge_ptr, 0.00001, .000001); + new_g += qromb_midpnt(charge_ptr, 0.000001, xd_global); } - else if (xd > 0.00000001) + else if (xd_global > 0.00000001) { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, .0001); - new_g += qromb_midpnt(0.0001, .00001); - new_g += qromb_midpnt(0.00001, .000001); - new_g += qromb_midpnt(0.000001, .0000001); - new_g += qromb_midpnt(0.0000001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, .0001); + new_g += qromb_midpnt(charge_ptr, 0.0001, .00001); + new_g += qromb_midpnt(charge_ptr, 0.00001, .000001); + new_g += qromb_midpnt(charge_ptr, 0.000001, .0000001); + new_g += qromb_midpnt(charge_ptr, 0.0000001, xd_global); } else { - new_g = qromb_midpnt(1.0, 0.1); - new_g += qromb_midpnt(0.1, 0.01); - new_g += qromb_midpnt(0.01, .001); - new_g += qromb_midpnt(0.001, .0001); - new_g += qromb_midpnt(0.0001, .00001); - new_g += qromb_midpnt(0.00001, .000001); - new_g += qromb_midpnt(0.000001, .0000001); - new_g += qromb_midpnt(0.0000001, .00000001); - new_g += qromb_midpnt(0.00000001, xd); + new_g = qromb_midpnt(charge_ptr, 1.0, 0.1); + new_g += qromb_midpnt(charge_ptr, 0.1, 0.01); + new_g += qromb_midpnt(charge_ptr, 0.01, .001); + new_g += qromb_midpnt(charge_ptr, 0.001, .0001); + new_g += qromb_midpnt(charge_ptr, 0.0001, .00001); + new_g += qromb_midpnt(charge_ptr, 0.00001, .000001); + new_g += qromb_midpnt(charge_ptr, 0.000001, .0000001); + new_g += qromb_midpnt(charge_ptr, 0.0000001, .00000001); + new_g += qromb_midpnt(charge_ptr, 0.00000001, xd_global); } } else @@ -161,23 +147,19 @@ calc_all_g(void) { new_g = 0.0; } - if ((use.Get_surface_ptr()->only_counter_ions == TRUE) && new_g < 0) + if ((use.Get_surface_ptr()->Get_only_counter_ions()) && new_g < 0) new_g = 0; - x[j]->surface_charge->g[count_g].charge = s_x[i]->z; converge1 = TRUE; if (fabs(new_g) >= 1.) { - if (fabs - ((new_g - x[j]->surface_charge->g[count_g].g) / new_g) > - epsilon) + if (fabs((new_g - charge_ptr->Get_g_map()[z_global].Get_g()) / new_g) > epsilon) { converge1 = FALSE; } } else { - if (fabs(new_g - x[j]->surface_charge->g[count_g].g) > - epsilon) + if (fabs(new_g - charge_ptr->Get_g_map()[z_global].Get_g()) > epsilon) { converge1 = FALSE; } @@ -189,105 +171,90 @@ calc_all_g(void) { output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[count_g]. - charge, - (double) x[j]->surface_charge->g[count_g].g, + (double) z_global, + (double) charge_ptr->Get_g_map()[z_global].Get_g(), (double) new_g, - (double) (new_g - - x[j]->surface_charge->g[count_g].g))); + (double) (new_g - charge_ptr->Get_g_map()[z_global].Get_g()))); } } - x[j]->surface_charge->g[count_g].g = new_g; + charge_ptr->Get_g_map()[z_global].Set_g(new_g); if (new_g == 0) { - x[j]->surface_charge->g[count_g].dg = 0; + charge_ptr->Get_g_map()[z_global].Set_dg(0.); } else { - if (x[j]->surface_charge->grams > 0.0) + if (charge_ptr->Get_grams() > 0.0) { - x[j]->surface_charge->g[count_g].dg = - surface_charge_ptr->grams * - surface_charge_ptr->specific_area * alpha * - g_function(xd) / F_C_MOL; - x[j]->surface_charge->g[count_g].dg *= + LDBLE dg = charge_ptr->Get_grams() * + charge_ptr->Get_specific_area() * alpha_global * + g_function(xd_global) / F_C_MOL; + dg *= -2. / (exp(x[j]->master[0]->s->la * LOG_10) * exp(x[j]->master[0]->s->la * LOG_10)); - if ((xd - 1) < 0.0) + if ((xd_global - 1) < 0.0) { - x[j]->surface_charge->g[count_g].dg *= -1.0; + dg *= -1.0; } - if (fabs(x[j]->surface_charge->g[count_g].dg) < 1e-8) + + if (fabs(dg) < 1e-8) { xd1 = exp(-2 * 1e-3 * LOG_10); - - - new_g = qromb_midpnt(1.0, xd1); - x[j]->surface_charge->g[count_g].dg = new_g / .001; + new_g = qromb_midpnt(charge_ptr, 1.0, xd1); + dg = new_g / .001; } + charge_ptr->Get_g_map()[z_global].Set_dg(dg); } else { - x[j]->surface_charge->g[count_g].dg = 0.0; + charge_ptr->Get_g_map()[z_global].Set_dg(0.0); } } - s_x[i]->diff_layer[count_charge].charge = x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = count_g; - count_g++; - + temp_g_map[z_global] = charge_ptr->Get_g_map()[z_global]; } if (debug_diffuse_layer == TRUE) { - output_msg(sformatf( - "\nSurface component %d: charge,\tg,\tdg/dlny,\txd\n", - count_charge)); - for (i = 0; i < count_g; i++) + output_msg(sformatf("\nSurface component %d: charge,\tg,\tdg/dlny,\txd\n", + (int) charge_ptr->Get_g_map().size())); + std::map::iterator it; + for (it = charge_ptr->Get_g_map().begin(); it != charge_ptr->Get_g_map().end(); it++) { output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg, - (double) xd)); + (double) it->first, + (double) it->second.Get_g(), + (double) it->second.Get_dg(), + (double) xd_global)); } } - count_charge++; } return (converge); } - /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: g_function(LDBLE x_value) /* ---------------------------------------------------------------------- */ { LDBLE sum, return_value, sum1; - int i, j; + int i; LDBLE ln_x_value; if (equal(x_value, 1.0, G_TOL * 100) == TRUE) return (0.0); sum = 0.0; ln_x_value = log(x_value); - for (j = 0; j < use.Get_surface_ptr()->charge[0].count_g; j++) + + cxxSurfaceCharge *charge_ptr = &(use.Get_surface_ptr()->Get_surface_charges()[0]); + std::map::iterator it = charge_ptr->Get_g_map().begin(); + for ( ; it != charge_ptr->Get_g_map().end(); it++) { - use.Get_surface_ptr()->charge[0].g[j].psi_to_z = - exp(ln_x_value * use.Get_surface_ptr()->charge[0].g[j].charge) - 1.0; + it->second.Set_psi_to_z(exp(ln_x_value * it->first) - 1.0); } for (i = 0; i < count_s_x; i++) { if (s_x[i]->type < H2O && s_x[i]->z != 0.0) { - for (j = 0; j < use.Get_surface_ptr()->charge[0].count_g; j++) - { - if (use.Get_surface_ptr()->charge[0].g[j].charge == s_x[i]->z) - { - sum += - s_x[i]->moles * - use.Get_surface_ptr()->charge[0].g[j].psi_to_z; - break; - } - } + sum += s_x[i]->moles * charge_ptr->Get_g_map()[s_x[i]->z].Get_psi_to_z(); } } if (sum < 0.0) @@ -318,11 +285,10 @@ g_function(LDBLE x_value) } return_value = - (exp(ln_x_value * z) - + (exp(ln_x_value * z_global) - 1) / sqrt((x_value * x_value * mass_water_aq_x * sum)); return (return_value); } - /* ---------------------------------------------------------------------- */ void Phreeqc:: polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy) @@ -435,7 +401,7 @@ midpnt(LDBLE x1, LDBLE x2, int n) /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -qromb_midpnt(LDBLE x1, LDBLE x2) +qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2) /* ---------------------------------------------------------------------- */ { LDBLE ss, dss; @@ -451,7 +417,7 @@ qromb_midpnt(LDBLE x1, LDBLE x2) if (fabs(sv[j] - sv[j - 1]) <= G_TOL * fabs(sv[j])) { - sv[j] *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + sv[j] *= charge_ptr->Get_grams() * charge_ptr->Get_specific_area() * alpha_global / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ if ((x2 - 1) < 0.0) sv[j] *= -1.0; if (debug_diffuse_layer == TRUE) @@ -467,7 +433,7 @@ qromb_midpnt(LDBLE x1, LDBLE x2) polint(&h[j - K_POLY], &sv[j - K_POLY], K_POLY, 0.0, &ss, &dss); if (fabs(dss) <= G_TOL * fabs(ss) || fabs(dss) < G_TOL) { - ss *= surface_charge_ptr->grams * surface_charge_ptr->specific_area * alpha / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + ss *= charge_ptr->Get_grams() * charge_ptr->Get_specific_area() * alpha_global / F_C_MOL; /* (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ if ((x2 - 1) < 0.0) ss *= -1.0; if (debug_diffuse_layer == TRUE) @@ -485,138 +451,90 @@ qromb_midpnt(LDBLE x1, LDBLE x2) error_msg(error_string, STOP); return (-999.9); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_init_g(void) /* ---------------------------------------------------------------------- */ { - int i, j, k; - int count_g, count_charge; - if (use.Get_surface_ptr() == NULL) return (OK); - /* * calculate g for each surface */ - count_charge = 0; - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; - count_g = 0; - if (x[j]->surface_charge->g != NULL) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + xd_global = exp(-2 * x[j]->master[0]->s->la * LOG_10); + /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ + /* second 1000 is liters/m**3 */ + alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + 1000.0 * tk_x * 0.5); + + if (charge_ptr->Get_g_map().size() == 0) { - count_g = x[j]->surface_charge->count_g; - } - if (count_g == 0) - { - x[j]->surface_charge->g = - (struct surface_diff_layer *) PHRQ_malloc((size_t) - sizeof(struct - surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) - malloc_error(); - x[j]->surface_charge->g[0].charge = 0.0; - x[j]->surface_charge->g[0].g = 0.0; - x[j]->surface_charge->g[0].dg = 0.0; - xd = exp(-2 * x[j]->master[0]->s->la * LOG_10); - /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ - /* second 1000 is liters/m**3 */ - alpha = - sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * - 1000.0 * tk_x * 0.5); + cxxSurfDL temp_g; + charge_ptr->Get_g_map()[0.0] = temp_g; } /* * calculate g for given surface for each species */ - count_g = 1; - for (i = 0; i < count_s_x; i++) + for (int i = 0; i < count_s_x; i++) { if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) - { - if (equal - (x[j]->surface_charge->g[k].charge, s_x[i]->z, - G_TOL) == TRUE) - { - s_x[i]->diff_layer[count_charge].charge = - x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - break; - } - } - if (k >= count_g) - { - - /* malloc space to save g for charge */ - x[j]->surface_charge->g = - (struct surface_diff_layer *) PHRQ_realloc(x[j]-> - surface_charge-> - g, - (size_t) - (count_g + - 1) * - sizeof(struct - surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) - malloc_error(); + if (charge_ptr->Get_g_map().find(s_x[i]->z) == charge_ptr->Get_g_map().end()) + { + cxxSurfDL temp_g; /* save g for charge */ - x[j]->surface_charge->g[count_g].charge = s_x[i]->z; - if (x[j]->surface_charge->grams > 0.0) + if (charge_ptr->Get_grams() > 0.0) { - x[j]->surface_charge->g[count_g].g = - 2 * alpha * sqrt(mu_x) * (pow(xd, s_x[i]->z / 2.0) - - 1) * - surface_charge_ptr->grams * - surface_charge_ptr->specific_area / F_C_MOL; - x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; - if ((use.Get_surface_ptr()->only_counter_ions == TRUE) && - x[j]->surface_charge->g[count_g].g < 0) + temp_g.Set_g(2 * alpha_global * sqrt(mu_x) * (pow(xd_global, s_x[i]->z / 2.0) - 1) * + charge_ptr->Get_grams() * + charge_ptr->Get_specific_area() / F_C_MOL); + temp_g.Set_dg(-s_x[i]->z); + if (use.Get_surface_ptr()->Get_only_counter_ions() && + temp_g.Get_g() < 0) { - x[j]->surface_charge->g[count_g].g = 0; - x[j]->surface_charge->g[count_g].dg = 0; + temp_g.Set_g(0); + temp_g.Set_dg(0); } } else { - x[j]->surface_charge->g[count_g].g = 0.0; - x[j]->surface_charge->g[count_g].dg = -s_x[i]->z; + temp_g.Set_g(0); + temp_g.Set_dg(-s_x[i]->z); } - /* save g for species */ - s_x[i]->diff_layer[count_charge].charge = - x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = count_g; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - count_g++; + charge_ptr->Get_g_map()[s_x[i]->z] = temp_g; + } + + { + int is = s_x[i]->number; + assert (is < (int) s_diff_layer.size()); + // species found in diff_layer + s_diff_layer[is][charge_ptr->Get_name()].Set_g_moles(0); + s_diff_layer[is][charge_ptr->Get_name()].Set_dg_g_moles(0); } } if (debug_diffuse_layer == TRUE) { output_msg(sformatf( "\nSurface component %d: charge,\tg,\tdg\n", - count_charge)); - for (i = 0; i < count_g; i++) + (int) charge_ptr->Get_g_map().size())); + std::map::iterator it; + for (it = charge_ptr->Get_g_map().begin(); it != charge_ptr->Get_g_map().end(); it++) { output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg)); + (double) it->first, + (double) it->second.Get_g(), + (double) it->second.Get_dg())); } } - count_charge++; - x[j]->surface_charge->count_g = count_g; } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: initial_surface_water(void) @@ -628,10 +546,8 @@ initial_surface_water(void) * diffuse layer water + aqueous solution water = bulk water. * Ionic strength is fixed, so diffuse-layer water will not change */ - int i; LDBLE debye_length, b, r, rd, ddl_limit, rd_limit, fraction, sum_surfs, l_s; LDBLE damp_aq; - /* * Debye length = 1/k = sqrt[eta*eta_zero*R*T/(2*F**2*mu_x*1000)], Dzombak and Morel, p 36 * @@ -642,34 +558,35 @@ initial_surface_water(void) debye_length = sqrt(debye_length); /* ddl is at most the fraction ddl_limit of bulk water */ - ddl_limit = use.Get_surface_ptr()->DDL_limit; + ddl_limit = use.Get_surface_ptr()->Get_DDL_limit(); /* * Loop through all surface components, calculate each H2O surface (diffuse layer), * H2O aq, and H2O bulk (diffuse layers plus aqueous). */ - if (use.Get_surface_ptr()->debye_lengths > 0) + if (use.Get_surface_ptr()->Get_debye_lengths() > 0) { sum_surfs = 0.0; - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); sum_surfs += - x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams; + charge_ptr->Get_specific_area() * + charge_ptr->Get_grams(); } - rd = debye_length * use.Get_surface_ptr()->debye_lengths; - use.Get_surface_ptr()->thickness = rd; + rd = debye_length * use.Get_surface_ptr()->Get_debye_lengths(); + use.Get_surface_ptr()->Set_thickness(rd); if (state == INITIAL_SURFACE) { /* distribute water over DDL (rd) and free pore (r - rd) */ /* find r: free pore (m3) = pi * (r - rd)^2 * L, where L = A / (2*pi*r), A = sum_surfs = sum of the surface areas */ - b = -2 * (rd + use.Get_solution_ptr()->mass_water / (1000 * sum_surfs)); + b = -2 * (rd + use.Get_solution_ptr()->Get_mass_water() / (1000 * sum_surfs)); r = 0.5 * (-b + sqrt(b * b - 4 * rd * rd)); /* DDL (m3) = pi * (r^2 - (r - rd)^2) * L */ rd_limit = (1 - sqrt(1 - ddl_limit)) * r; @@ -677,25 +594,26 @@ initial_surface_water(void) if (rd > rd_limit) { mass_water_surfaces_x = - use.Get_solution_ptr()->mass_water * ddl_limit / (1 - + use.Get_solution_ptr()->Get_mass_water() * ddl_limit / (1 - ddl_limit); r = 0.002 * (mass_water_surfaces_x + - use.Get_solution_ptr()->mass_water) / sum_surfs; + use.Get_solution_ptr()->Get_mass_water()) / sum_surfs; rd_limit = (1 - sqrt(1 - ddl_limit)) * r; - use.Get_surface_ptr()->thickness = rd = rd_limit; + rd = rd_limit; + use.Get_surface_ptr()->Set_thickness(rd); } else mass_water_surfaces_x = (r * r / pow(r - rd, 2) - - 1) * use.Get_solution_ptr()->mass_water; - for (i = 0; i < count_unknowns; i++) + 1) * use.Get_solution_ptr()->Get_mass_water(); + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; - l_s = x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams; - x[i]->surface_charge->mass_water = - mass_water_surfaces_x * l_s / sum_surfs; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + l_s =charge_ptr->Get_specific_area() * + charge_ptr->Get_grams(); + charge_ptr->Set_mass_water(mass_water_surfaces_x * l_s / sum_surfs); } } else @@ -704,7 +622,8 @@ initial_surface_water(void) rd_limit = (1 - sqrt(1 - ddl_limit)) * r; if (rd > rd_limit) { - use.Get_surface_ptr()->thickness = rd = rd_limit; + rd = rd_limit; + use.Get_surface_ptr()->Set_thickness(rd); fraction = ddl_limit; } else @@ -716,14 +635,14 @@ initial_surface_water(void) damp_aq = 0.5; mass_water_surfaces_x = damp_aq * fraction * mass_water_bulk_x + (1 - damp_aq) * mass_water_surfaces_x; - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; - l_s = x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams; - x[i]->surface_charge->mass_water = - mass_water_surfaces_x * l_s / sum_surfs; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + l_s = charge_ptr->Get_specific_area() * + charge_ptr->Get_grams(); + charge_ptr->Set_mass_water(mass_water_surfaces_x * l_s / sum_surfs); } } } @@ -731,19 +650,19 @@ initial_surface_water(void) { /* take constant thickness of, default 1e-8 m (100 Angstroms) */ mass_water_surfaces_x = 0.0; - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; - x[i]->surface_charge->mass_water = - x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams * use.Get_surface_ptr()->thickness * - 1000; - mass_water_surfaces_x += x[i]->surface_charge->mass_water; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + charge_ptr->Set_mass_water(charge_ptr->Get_specific_area() * + charge_ptr->Get_grams() * use.Get_surface_ptr()->Get_thickness() * + 1000); + mass_water_surfaces_x += charge_ptr->Get_mass_water(); } } - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; else { @@ -756,13 +675,11 @@ initial_surface_water(void) return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) +sum_diffuse_layer(cxxSurfaceCharge *charge_ptr) /* ---------------------------------------------------------------------- */ { - int i, j, count_g; LDBLE mass_water_surface; LDBLE molality, moles_excess, moles_surface; @@ -771,44 +688,20 @@ sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) /* * Find position of component in list of components */ - i = 0; - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) - { - if (&(use.Get_surface_ptr()->charge[j]) == surface_charge_ptr1) - { - i = j; - break; - } - } - if (j >= use.Get_surface_ptr()->count_charge) - { - error_string = sformatf( - "In sum_diffuse_layer, component not found, %s.", - surface_charge_ptr1->name); - error_msg(error_string, STOP); - } /* * Loop through all surface components, calculate each H2O surface (diffuse layer), * H2O aq, and H2O bulk (diffuse layers plus aqueous). */ count_elts = 0; paren_count = 0; - mass_water_surface = surface_charge_ptr1->mass_water; - for (j = 0; j < count_s_x; j++) + mass_water_surface = charge_ptr->Get_mass_water(); + for (int j = 0; j < count_s_x; j++) { if (s_x[j]->type > HPLUS) continue; molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; -#ifdef SKIP - moles_excess = mass_water_bulk_x * -/* s_x[j]->diff_layer[i].charge->g[count_g].g * molality; */ - surface_charge_ptr1->g[count_g].g * molality; -#endif - moles_excess = - mass_water_aq_x * molality * surface_charge_ptr1->g[count_g].g; - + moles_excess = mass_water_aq_x * molality * charge_ptr->Get_g_map()[s_x[j]->z].Get_g(); moles_surface = mass_water_surface * molality + moles_excess; /* * Accumulate elements in diffuse layer @@ -825,25 +718,20 @@ sum_diffuse_layer(struct surface_charge *surface_charge_ptr1) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_all_donnan(void) /* ---------------------------------------------------------------------- */ { - int i, j, k; - int count_g, count_charge, converge, cd_m; - char name[MAX_LENGTH]; + bool converge; + int cd_m; LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif, var1; LDBLE cz, cm, cp; if (use.Get_surface_ptr() == NULL) return (OK); -/* if (use.Get_surface_ptr()->type == CD_MUSIC) - return (calc_all_donnan_music()); - */ f_sinh = - sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); cz = cm = 1.0; cp = 1.0; @@ -851,48 +739,32 @@ calc_all_donnan(void) * calculate g for each surface... */ converge = TRUE; - count_charge = 0; - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); if (debug_diffuse_layer == TRUE) output_msg(sformatf( "Calc_all_g, X[%d]\n", j)); /* * sum eq of each charge number in solution... */ - count_g = x[j]->surface_charge->count_g; - for (i = 0; i < count_g; i++) + std::map::iterator it; + for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { - charge_group[i].eq = 0.0; + it->second = 0.0; } - for (i = 0; i < count_s_x; i++) + charge_group_map.clear(); + for (int i = 0; i < count_s_x; i++) { if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) - { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) - { -#ifdef SKIP - if (s_x[i]->z > 0) - cz = s_x[i]->z * pow(cp, s_x[i]->z); - else - cz = s_x[i]->z * pow(cm, -s_x[i]->z); - charge_group[k].eq += cz * s_x[i]->moles; -#endif - charge_group[k].eq += - s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; - break; - } - } + charge_group_map[s_x[i]->z] += s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; } /* find surface charge from potential... */ - A_surf = - x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; - if (use.Get_surface_ptr()->type == CD_MUSIC) + A_surf = charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ f_psi = f_psi / 2; @@ -918,118 +790,87 @@ calc_all_donnan(void) surf_chrg_eq2 = A_surf * f_sinh * sinh(f_psi2) / F_C_MOL; /* find psi_avg that matches surface charge... */ - psi_avg = calc_psi_avg(surf_chrg_eq); - psi_avg2 = calc_psi_avg(surf_chrg_eq2); + psi_avg = calc_psi_avg(charge_ptr, surf_chrg_eq); + psi_avg2 = calc_psi_avg(charge_ptr, surf_chrg_eq2); /*output_msg(sformatf( "psi's %e %e %e\n", f_psi, psi_avg, surf_chrg_eq)); */ /* fill in g's */ - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + ratio_aq = charge_ptr->Get_mass_water() / mass_water_aq_x; - for (k = 0; k < count_g; k++) + for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { - x[j]->surface_charge->g[k].charge = charge_group[k].z; -#ifdef SKIP - if (charge_group[k].z > 0) - cz = pow(cp, charge_group[k].z); - else - cz = pow(cm, -charge_group[k].z); - new_g = cz * (exp(-charge_group[k].z * psi_avg)) - 1; - if (new_g < -ratio_aq) - new_g = -ratio_aq + G_TOL * 1e-5; - new_g2 = cz * (exp(-charge_group[k].z * psi_avg2)) - 1; - if (new_g2 < -ratio_aq) - new_g2 = -ratio_aq + G_TOL * 1e-5; -#endif - new_g = ratio_aq * (exp(cd_m * charge_group[k].z * psi_avg) - 1); - if (use.Get_surface_ptr()->only_counter_ions && - ((surf_chrg_eq < 0 && charge_group[k].z < 0) - || (surf_chrg_eq > 0 && charge_group[k].z > 0))) + LDBLE z = it->first; + new_g = ratio_aq * (exp(cd_m * z * psi_avg) - 1); + if (use.Get_surface_ptr()->Get_only_counter_ions() && + ((surf_chrg_eq < 0 && z < 0) + || (surf_chrg_eq > 0 && z > 0))) new_g = -ratio_aq; if (new_g <= -ratio_aq) new_g = -ratio_aq + G_TOL * 1e-3; - new_g2 = ratio_aq * (exp(cd_m * charge_group[k].z * psi_avg2) - 1); - if (use.Get_surface_ptr()->only_counter_ions && - ((surf_chrg_eq < 0 && charge_group[k].z < 0) - || (surf_chrg_eq > 0 && charge_group[k].z > 0))) + new_g2 = ratio_aq * (exp(cd_m * z * psi_avg2) - 1); + if (use.Get_surface_ptr()->Get_only_counter_ions() && + ((surf_chrg_eq < 0 && z < 0) + || (surf_chrg_eq > 0 && z > 0))) new_g2 = -ratio_aq; if (new_g2 <= -ratio_aq) new_g2 = -ratio_aq + G_TOL * 1e-3; if (fabs(new_g) >= 1) { - if (fabs((new_g - x[j]->surface_charge->g[k].g) / new_g) > - convergence_tolerance) + if (fabs((new_g - charge_ptr->Get_g_map()[z].Get_g()) / new_g) > convergence_tolerance) { converge = FALSE; } } else { - if (fabs(new_g - x[j]->surface_charge->g[k].g) > - convergence_tolerance) + if (fabs(new_g - charge_ptr->Get_g_map()[z].Get_g()) > convergence_tolerance) { converge = FALSE; } } - x[j]->surface_charge->g[k].g = new_g; + charge_ptr->Get_g_map()[z].Set_g(new_g); if (new_g != 0) { - x[j]->surface_charge->g[k].dg = (new_g2 - new_g) / dif; + charge_ptr->Get_g_map()[z].Set_dg((new_g2 - new_g) / dif); } else { - x[j]->surface_charge->g[k].dg = -charge_group[k].z; + charge_ptr->Get_g_map()[z].Set_dg(-z); } /* save g for species */ - for (i = 0; i < count_s_x; i++) - { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) - { - s_x[i]->diff_layer[count_charge].charge = - x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - } - } } if (debug_diffuse_layer == TRUE) { - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); -/* surf_chrg_eq = calc_surface_charge(name); - */ + std::string name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); output_msg(sformatf( "\nDonnan all on %s (%d): charge, \tg, \tdg, Psi_surface = %8f V. \n", - name, count_charge, + name.c_str(), (int) charge_ptr->Get_g_map().size(), x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ)); - for (i = 0; i < count_g; i++) + for (std::map::iterator i_it = charge_ptr->Get_g_map().begin(); + i_it != charge_ptr->Get_g_map().end(); i_it++) { output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg)); + (double) i_it->first, + (double) i_it->second.Get_g(), + (double) i_it->second.Get_dg())); } } - count_charge++; } return (converge); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_init_donnan(void) /* ---------------------------------------------------------------------- */ { - int i, j, k; - int count_g, count_charge; - char name[MAX_LENGTH]; LDBLE f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; if (use.Get_surface_ptr() == NULL) return (OK); -/* if (use.Get_surface_ptr()->type == CD_MUSIC) - return (calc_init_donnan_music()); - */ f_sinh = + f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); if (convergence_tolerance >= 1e-8) @@ -1043,68 +884,35 @@ calc_init_donnan(void) /* * sum eq of each charge number in solution... */ - charge_group = (struct Charge_Group *) free_check_null(charge_group); - charge_group = - (struct Charge_Group *) PHRQ_malloc((size_t) - sizeof(struct Charge_Group)); - if (charge_group == NULL) - malloc_error(); - charge_group[0].z = 0.0; - charge_group[0].eq = 0.0; + charge_group_map.clear(); + charge_group_map[0.0] = 0.0; - count_g = 1; - for (i = 0; i < count_s_x; i++) + for (int i = 0; i < count_s_x; i++) { if (s_x[i]->type > HPLUS) continue; - for (k = 0; k < count_g; k++) + if (charge_group_map.find(s_x[i]->z) != charge_group_map.end()) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) - { - charge_group[k].eq += - s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; - break; - } + charge_group_map.find(s_x[i]->z)->second += s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; } - if (k >= count_g) + else { - charge_group = - (struct Charge_Group *) PHRQ_realloc(charge_group, - (size_t) (count_g + - 1) * - sizeof(struct - Charge_Group)); - if (charge_group == NULL) - malloc_error(); - charge_group[count_g].z = s_x[i]->z; - charge_group[count_g].eq = - s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; - - count_g++; + charge_group_map[s_x[i]->z] = s_x[i]->z * s_x[i]->moles * s_x[i]->erm_ddl; } } /* * calculate g for each surface... */ - count_charge = 0; - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; - surface_charge_ptr = x[j]->surface_charge; - - x[j]->surface_charge->g = - (struct surface_diff_layer *) PHRQ_malloc((size_t) count_g * - sizeof(struct - surface_diff_layer)); - if (x[j]->surface_charge->g == NULL) - malloc_error(); - x[j]->surface_charge->count_g = count_g; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + charge_ptr->Get_g_map().clear(); /* find surface charge from potential... */ - A_surf = - x[j]->surface_charge->specific_area * x[j]->surface_charge->grams; - if (use.Get_surface_ptr()->type == CD_MUSIC) + A_surf = charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ f_psi = f_psi / 2; @@ -1115,81 +923,76 @@ calc_init_donnan(void) /* find psi_avg that matches surface charge... */ /* psi_avg = calc_psi_avg (0); appt 7/9/8... may have to change above one */ - psi_avg = calc_psi_avg(0 * surf_chrg_eq); + psi_avg = calc_psi_avg(charge_ptr, 0 * surf_chrg_eq); /* fill in g's */ - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + ratio_aq = charge_ptr->Get_mass_water() / mass_water_aq_x; - for (k = 0; k < count_g; k++) + std::map::iterator kit; + for (kit = charge_group_map.begin(); kit != charge_group_map.end(); kit++) { - x[j]->surface_charge->g[k].charge = charge_group[k].z; - x[j]->surface_charge->g[k].g = - ratio_aq * (exp(-charge_group[k].z * psi_avg) - 1); - if (use.Get_surface_ptr()->only_counter_ions - && ((surf_chrg_eq < 0 && charge_group[k].z < 0) - || (surf_chrg_eq > 0 && charge_group[k].z > 0))) - x[j]->surface_charge->g[k].g = -ratio_aq; - if (x[j]->surface_charge->g[k].g != 0) + LDBLE z = kit->first; + LDBLE eq = kit->second; + + charge_ptr->Get_g_map()[z].Set_g(ratio_aq * (exp(-z * psi_avg) - 1)); + + if (use.Get_surface_ptr()->Get_only_counter_ions() + && ((surf_chrg_eq < 0 && z < 0) + || (surf_chrg_eq > 0 && z > 0))) + charge_ptr->Get_g_map()[z].Set_g(-ratio_aq); + + if (charge_ptr->Get_g_map()[z].Get_g() != 0) { - x[j]->surface_charge->g[k].dg = - -A_surf * f_sinh * cosh(f_psi) / (charge_group[k].eq * - F_C_MOL); + charge_ptr->Get_g_map()[z].Set_dg(-A_surf * f_sinh * cosh(f_psi) / + (eq * F_C_MOL)); } else { - x[j]->surface_charge->g[k].dg = -charge_group[k].z; + charge_ptr->Get_g_map()[z].Set_dg(-z); } + /* save g for species */ - for (i = 0; i < count_s_x; i++) + for (int i = 0; i < count_s_x; i++) { - if (equal(charge_group[k].z, s_x[i]->z, G_TOL) == TRUE) - { - s_x[i]->diff_layer[count_charge].charge = - x[j]->surface_charge; - s_x[i]->diff_layer[count_charge].count_g = k; - s_x[i]->diff_layer[count_charge].g_moles = 0.0; - s_x[i]->diff_layer[count_charge].dg_g_moles = 0.0; - } + int is = s_x[i]->number; + assert (is < (int) s_diff_layer.size()); + + s_diff_layer[is][charge_ptr->Get_name()].Set_g_moles(0.0); + s_diff_layer[is][charge_ptr->Get_name()].Set_dg_g_moles(0.0); } } if (debug_diffuse_layer == TRUE) { - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); -/* surf_chrg_eq = calc_surface_charge(name); - */ + std::string name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); output_msg(sformatf( "\nDonnan init on %s : charge, \tg, \tdg, Psi_surface = %8f V. \n", - name, + name.c_str(), x[j]->master[0]->s->la * 2 * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ)); - for (i = 0; i < count_g; i++) + for (std::map::iterator i_it = charge_ptr->Get_g_map().begin(); + i_it != charge_ptr->Get_g_map().end(); i_it++) { output_msg(sformatf( "\t%12f\t%12.4e\t%12.4e\n", - (double) x[j]->surface_charge->g[i].charge, - (double) x[j]->surface_charge->g[i].g, - (double) x[j]->surface_charge->g[i].dg)); + (double) i_it->first, + (double) i_it->second.Get_g(), + (double) i_it->second.Get_dg())); } } - count_charge++; } return (OK); } - /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -calc_psi_avg(LDBLE surf_chrg_eq) +calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq) /* ---------------------------------------------------------------------- */ { /* * calculate the average (F * Psi / RT) that lets the DL charge counter the surface charge */ - int i, l_iter, count_g; LDBLE fd, fd1, p, temp, ratio_aq; -/* LDBLE dif; - */ - count_g = surface_charge_ptr->count_g; - ratio_aq = surface_charge_ptr->mass_water / mass_water_aq_x; + + ratio_aq = charge_ptr->Get_mass_water() / mass_water_aq_x; p = 0; if (surf_chrg_eq == 0 || ratio_aq == 0) return (0.0); @@ -1203,26 +1006,26 @@ calc_psi_avg(LDBLE surf_chrg_eq) * Elsewhere in PHREEQC, g is the excess, after subtraction of conc's for p = 0: * g(p) = (exp(-p *z_i) - 1) * ratio_aq */ - l_iter = 0; + int l_iter = 0; do { fd = surf_chrg_eq; fd1 = 0.0; - for (i = 1; i < count_g; i++) + std::map::iterator it; + for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { -/* if (use.Get_surface_ptr()->type == CD_MUSIC) - temp = exp(-charge_group[i].z * p); - else - */ /* multiply with ratio_aq for multiplier options cp and cm - in calc_all_donnan (not used now)... */ - temp = exp(-charge_group[i].z * p) * ratio_aq; + LDBLE z = it->first; + LDBLE eq = it->second; + /* multiply with ratio_aq for multiplier options cp and cm + in calc_all_donnan (not used now)... */ + temp = exp(-z * p) * ratio_aq; - if (use.Get_surface_ptr()->only_counter_ions && - ((surf_chrg_eq < 0 && charge_group[i].z < 0) - || (surf_chrg_eq > 0 && charge_group[i].z > 0))) + if (use.Get_surface_ptr()->Get_only_counter_ions() && + ((surf_chrg_eq < 0 && z < 0) + || (surf_chrg_eq > 0 && z > 0))) temp = 0.0; - fd += charge_group[i].eq * temp; - fd1 -= charge_group[i].z * charge_group[i].eq * temp; + fd += eq * temp; + fd1 -= z * eq * temp; } fd /= -fd1; p += (fd > 1) ? 1 : ((fd < -1) ? -1 : fd); @@ -1233,7 +1036,7 @@ calc_psi_avg(LDBLE surf_chrg_eq) { error_string = sformatf( "\nToo many iterations in subroutine calc_psi_avg; surface charge = %12.4e; surface water = %12.4e.\n", - (double) surf_chrg_eq, (double) surface_charge_ptr->mass_water); + (double) surf_chrg_eq, (double) charge_ptr->Get_mass_water()); error_msg(error_string, STOP); } } diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index 82713097..db805194 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -1,5 +1,8 @@ #include "Phreeqc.h" #include "phqalloc.h" +#include "Utils.h" +#include "Solution.h" +#include "SolutionIsotope.h" #define MAX_MODELS 20 @@ -49,7 +52,7 @@ inverse_models(void) print1 = TRUE; state = INVERSE; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; for (n = 0; n < count_inverse; n++) { @@ -160,7 +163,7 @@ setup_inverse(struct inverse *inv_ptr) LDBLE f, coef, cb, conc; char token[MAX_LENGTH]; struct phase *phase_ptr; - struct solution *solution_ptr; + cxxSolution *solution_ptr; struct reaction *rxn_ptr; struct master *master_ptr; /* @@ -400,7 +403,7 @@ setup_inverse(struct inverse *inv_ptr) for (i = 0; i < inv_ptr->count_solns; i++) { xsolution_zero(); - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); if (solution_ptr == NULL) { error_string = sformatf( "Solution number %d not found.", @@ -408,21 +411,22 @@ setup_inverse(struct inverse *inv_ptr) error_msg(error_string, STOP); } /* write master species concentrations */ - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - master_ptr->total += solution_ptr->totals[j].moles; + master_ptr = master_bsearch(jit->first.c_str()); + master_ptr->total += jit->second; /* List elements not included in model */ if (master_ptr->in < 0) { error_string = sformatf( "%s is included in solution %d, but is not included as a mass-balance constraint.", - solution_ptr->totals[j].description, + jit->first.c_str(), inv_ptr->solns[i]); warning_msg(error_string); } } - master_alk->total = solution_ptr->total_alkalinity; + master_alk->total = solution_ptr->Get_total_alkalinity(); f = 1.0; if (i == (inv_ptr->count_solns - 1)) { @@ -650,16 +654,16 @@ setup_inverse(struct inverse *inv_ptr) */ for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); if (i < inv_ptr->count_solns - 1) { array[count_rows * max_column_count + i] = - 1.0 / gfw_water * solution_ptr->mass_water; + 1.0 / gfw_water * solution_ptr->Get_mass_water(); } else { array[count_rows * max_column_count + inv_ptr->count_solns - 1] = - -1.0 / gfw_water * solution_ptr->mass_water; + -1.0 / gfw_water * solution_ptr->Get_mass_water(); } } /* coefficient for water uncertainty */ @@ -922,20 +926,22 @@ setup_inverse(struct inverse *inv_ptr) { for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr = solution_bsearch(inv_ptr->solns[i], &k, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { column = col_isotopes + (i * inv_ptr->count_isotope_unknowns) + j; master_ptr = inv_ptr->isotope_unknowns[j].master; isotope_number = inv_ptr->isotope_unknowns[j].isotope_number; - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (solution_ptr->isotopes[k].master == master_ptr && - solution_ptr->isotopes[k].isotope_number == + struct master *master_kit = master_bsearch(kit->second.Get_elt_name().c_str()); + if (master_kit == master_ptr && + kit->second.Get_isotope_number() == isotope_number) { - coef = solution_ptr->isotopes[k].x_ratio_uncertainty; + coef = kit->second.Get_x_ratio_uncertainty(); /* scale epsilon in optimization equation */ @@ -946,9 +952,8 @@ setup_inverse(struct inverse *inv_ptr) array[count_rows * max_column_count + column] = 1.0; array[count_rows * max_column_count + i] = -coef; sprintf(token, "%d%s %s", - (int) solution_ptr->isotopes[k]. - isotope_number, - solution_ptr->isotopes[k].elt_name, "eps+"); + (int) kit->second.Get_isotope_number(), + kit->second.Get_elt_name().c_str(), "eps+"); row_name[count_rows] = string_hsave(token); count_rows++; @@ -957,9 +962,8 @@ setup_inverse(struct inverse *inv_ptr) array[count_rows * max_column_count + column] = -1.0; array[count_rows * max_column_count + i] = -coef; sprintf(token, "%d%s %s", - (int) solution_ptr->isotopes[k]. - isotope_number, - solution_ptr->isotopes[k].elt_name, "eps-"); + (int) kit->second.Get_isotope_number(), + kit->second.Get_elt_name().c_str(), "eps-"); row_name[count_rows] = string_hsave(token); count_rows++; break; @@ -1052,7 +1056,6 @@ setup_inverse(struct inverse *inv_ptr) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: solve_inverse(struct inverse *inv_ptr) @@ -1740,7 +1743,6 @@ bit_print(unsigned long bits, int l) output_msg(sformatf( "\n")); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: print_model(struct inverse *inv_ptr) @@ -1752,7 +1754,7 @@ print_model(struct inverse *inv_ptr) int i, j, k; int column; int print_msg; - struct solution *solution_ptr; + cxxSolution *solution_ptr; struct master *master_ptr; struct isotope *isotope_ptr; LDBLE d1, d2, d3, d4; @@ -1772,23 +1774,24 @@ print_model(struct inverse *inv_ptr) { if (equal(inv_delta1[i], 0.0, toler) == TRUE) continue; - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); xsolution_zero(); - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - master_ptr->total = solution_ptr->totals[j].moles; + master_ptr = master_bsearch(jit->first.c_str()); + master_ptr->total = jit->second; } output_msg(sformatf( "\nSolution %d: %s\n", inv_ptr->solns[i], - solution_ptr->description)); + solution_ptr->Get_description().c_str())); output_msg(sformatf( "\n%15.15s %12.12s %12.12s %12.12s\n", " ", "Input", "Delta", "Input+Delta")); - master_alk->total = solution_ptr->total_alkalinity; + master_alk->total = solution_ptr->Get_total_alkalinity(); if (inv_ptr->carbon == TRUE) { - d1 = solution_ptr->ph; + d1 = solution_ptr->Get_ph(); d2 = inv_delta1[col_ph + i] / inv_delta1[i]; d3 = d1 + d2; if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) @@ -1864,14 +1867,15 @@ print_model(struct inverse *inv_ptr) /* adjustments to solution isotope composition */ for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { if (inv_ptr->isotope_unknowns[j].elt_name != - solution_ptr->isotopes[k].elt_name || + string_hsave(kit->second.Get_elt_name().c_str()) || inv_ptr->isotope_unknowns[j].isotope_number != - solution_ptr->isotopes[k].isotope_number) + kit->second.Get_isotope_number()) continue; - d1 = solution_ptr->isotopes[k].ratio; + d1 = kit->second.Get_ratio(); d2 = inv_delta1[col_isotopes + i * inv_ptr->count_isotope_unknowns + j] / inv_delta1[i]; @@ -1896,11 +1900,11 @@ print_model(struct inverse *inv_ptr) if (d3 > max_pct) max_pct = d3; } */ - if (solution_ptr->isotopes[k].x_ratio_uncertainty > 0) + if (kit->second.Get_x_ratio_uncertainty() > 0) { scaled_error += fabs(d2) / - solution_ptr->isotopes[k].x_ratio_uncertainty; + kit->second.Get_x_ratio_uncertainty(); /* debug output_msg(sformatf( "%e\t%e\t%e\n", fabs(d2) / solution_ptr->isotopes[k].x_ratio_uncertainty , fabs(d2), solution_ptr->isotopes[k].x_ratio_uncertainty)); */ @@ -2065,7 +2069,6 @@ print_model(struct inverse *inv_ptr) output_flush(); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_model_heading(struct inverse *inv_ptr) @@ -3112,9 +3115,9 @@ int Phreeqc:: carbon_derivs(struct inverse *inv_ptr) /* ---------------------------------------------------------------------- */ { - int i, j, k, n, temp; + int i, j, temp; LDBLE c_uncertainty, d_carbon, alk_plus, alk_minus; - struct solution *solution_ptr_orig, *solution_ptr; + cxxSolution *solution_ptr_orig, *solution_ptr; inv_ptr->dalk_dph = (LDBLE *) free_check_null(inv_ptr->dalk_dph); inv_ptr->dalk_dph = @@ -3130,7 +3133,7 @@ carbon_derivs(struct inverse *inv_ptr) for (i = 0; i < inv_ptr->count_solns; i++) { - solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &n, TRUE); + solution_ptr_orig = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); if (solution_ptr_orig == NULL) { error_string = sformatf( "Solution %d for inverse " @@ -3156,13 +3159,13 @@ carbon_derivs(struct inverse *inv_ptr) } else if (c_uncertainty > 0.0) { - for (k = 0; solution_ptr_orig->totals[k].description != NULL; k++) + cxxNameDouble::iterator kit = solution_ptr_orig->Get_totals().begin(); + for ( ; kit != solution_ptr_orig->Get_totals().end(); kit++) { - if (strcmp(solution_ptr_orig->totals[k].description, "C(4)") - == 0) + if (strcmp(kit->first.c_str(), "C(4)") == 0) { - d_carbon = solution_ptr_orig->totals[k].moles / - solution_ptr_orig->mass_water * c_uncertainty; + d_carbon = kit->second / + solution_ptr_orig->Get_mass_water() * c_uncertainty; break; } @@ -3188,10 +3191,10 @@ carbon_derivs(struct inverse *inv_ptr) /* * dAlk/dpH */ - solution_ptr = solution_bsearch(-5, &n, TRUE); - alk_plus = solution_ptr->total_alkalinity; - solution_ptr = solution_bsearch(-4, &n, TRUE); - alk_minus = solution_ptr->total_alkalinity; + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -5); + alk_plus = solution_ptr->Get_total_alkalinity(); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -4); + alk_minus = solution_ptr->Get_total_alkalinity(); inv_ptr->dalk_dph[i] = (alk_plus - alk_minus) / (2.0 * inv_ptr->ph_uncertainties[i]); /* @@ -3199,10 +3202,10 @@ carbon_derivs(struct inverse *inv_ptr) */ if (d_carbon != 0) { - solution_ptr = solution_bsearch(-3, &n, TRUE); - alk_plus = solution_ptr->total_alkalinity; - solution_ptr = solution_bsearch(-2, &n, TRUE); - alk_minus = solution_ptr->total_alkalinity; + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -3); + alk_plus = solution_ptr->Get_total_alkalinity(); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -2); + alk_minus = solution_ptr->Get_total_alkalinity(); inv_ptr->dalk_dc[i] = (alk_plus - alk_minus) / (2.0 * d_carbon); } else @@ -3218,39 +3221,45 @@ carbon_derivs(struct inverse *inv_ptr) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: set_ph_c(struct inverse *inv_ptr, int i, - struct solution *solution_ptr_orig, + cxxSolution *solution_ptr_orig, int n_user_new, LDBLE d_carbon, LDBLE ph_factor, LDBLE c_factor) /* ---------------------------------------------------------------------- */ { - int j, n_user_orig; - struct solution *solution_ptr; - struct conc *conc_ptr; + int n_user_orig; + cxxSolution *solution_ptr; n_user_orig = inv_ptr->solns[i]; - solution_duplicate(n_user_orig, n_user_new); - solution_ptr = solution_bsearch(n_user_new, &j, TRUE); - solution_ptr->new_def = TRUE; - solution_ptr->n_user_end = n_user_new; - solution_ptr->ph += inv_ptr->ph_uncertainties[i] * ph_factor; - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + Utilities::Rxn_copy(Rxn_solution_map, n_user_orig, n_user_new); + + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user_new); + solution_ptr->Set_new_def(true); + solution_ptr->Create_initial_data(); + solution_ptr->Set_n_user_end(n_user_new); + LDBLE ph = solution_ptr->Get_ph(); + ph += inv_ptr->ph_uncertainties[i] * ph_factor; + solution_ptr->Set_ph(ph); + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - conc_ptr = &solution_ptr->totals[j]; - conc_ptr->input_conc = - conc_ptr->moles / solution_ptr_orig->mass_water; - conc_ptr->units = string_hsave("Mol/kgw"); - if (strcmp(conc_ptr->description, "C(4)") == 0) + cxxISolutionComp temp_comp; + temp_comp.Set_description(jit->first.c_str()); + temp_comp.Set_input_conc(jit->second / solution_ptr_orig->Get_mass_water()); + temp_comp.Set_units("Mol/kgw"); + if (strcmp(jit->first.c_str(), "C(4)") == 0) { - conc_ptr->input_conc += d_carbon * c_factor; + LDBLE c = temp_comp.Get_input_conc(); + c += d_carbon * c_factor; + temp_comp.Set_input_conc(c); } + solution_ptr->Get_initial_data()->Get_comps()[jit->first] = temp_comp; } + solution_ptr->Get_totals().clear(); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: isotope_balance_equation(struct inverse *inv_ptr, int row, int n) @@ -3267,8 +3276,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) int column; LDBLE f; struct master *primary_ptr; - struct solution *solution_ptr; - struct isotope *isotope_ptr; + cxxSolution *solution_ptr; /* * Determine primary master species and isotope number for * isotope mass-balance equation @@ -3312,57 +3320,60 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) } /* mixing fraction term */ - solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - isotope_ptr = solution_ptr->isotopes; - for (j = 0; j < solution_ptr->count_isotopes; j++) + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); + std::map < std::string, cxxSolutionIsotope >::iterator jit = solution_ptr->Get_isotopes().begin(); + for ( ; jit != solution_ptr->Get_isotopes().end(); jit++) { - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) + struct master *primary_jit = master_bsearch_primary(jit->second.Get_elt_name().c_str()); + if (primary_jit == primary_ptr && + jit->second.Get_isotope_number() == isotope_number) { array[row * max_column_count + i] += - f * isotope_ptr[j].total * isotope_ptr[j].ratio; + f * jit->second.Get_total() * jit->second.Get_ratio(); } } /* epsilon of total moles of element valence * ratio */ - for (j = 0; j < solution_ptr->count_isotopes; j++) + jit = solution_ptr->Get_isotopes().begin(); + for ( ; jit != solution_ptr->Get_isotopes().end(); jit++) { - /* What to do with H and O, skip for now ??? */ if (primary_ptr == s_hplus->primary || primary_ptr == s_h2o->primary) continue; - - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) + struct master *master_jit = master_bsearch(jit->second.Get_elt_name().c_str()); + struct master *primary_jit = master_bsearch_primary(jit->second.Get_elt_name().c_str()); + if (primary_jit == primary_ptr && + jit->second.Get_isotope_number() == isotope_number) { - /* find column of master for solution i */ for (k = 0; k < inv_ptr->count_elts; k++) { - if (isotope_ptr[j].master == inv_ptr->elts[k].master) + if (master_jit == inv_ptr->elts[k].master) break; } column = col_epsilon + (k * inv_ptr->count_solns) + i; array[row * max_column_count + column] += - f * isotope_ptr[j].ratio; + f * jit->second.Get_ratio(); } } /* epsilon of ratio * total of element valence */ - for (j = 0; j < solution_ptr->count_isotopes; j++) + jit = solution_ptr->Get_isotopes().begin(); + for ( ; jit != solution_ptr->Get_isotopes().end(); jit++) { - - if (isotope_ptr[j].primary == primary_ptr && - isotope_ptr[j].isotope_number == isotope_number) + struct master *master_jit = master_bsearch(jit->second.Get_elt_name().c_str()); + struct master *primary_jit = master_bsearch_primary(jit->second.Get_elt_name().c_str()); + if (primary_jit == primary_ptr && + jit->second.Get_isotope_number() == isotope_number) { /* find column of epsilon for ratio of valence */ for (k = 0; k < inv_ptr->count_isotope_unknowns; k++) { - if (isotope_ptr[j].master == + if (master_jit == inv_ptr->isotope_unknowns[k].master - && isotope_ptr[j].isotope_number == + && jit->second.Get_isotope_number() == inv_ptr->isotope_unknowns[k].isotope_number) { column = @@ -3371,7 +3382,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) } } array[row * max_column_count + column] += - f * isotope_ptr[j].total; + f * jit->second.Get_total(); } } } @@ -3382,7 +3393,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) { if (inv_ptr->phases[i].count_isotopes <= 0) continue; - isotope_ptr = inv_ptr->phases[i].isotopes; + struct isotope *isotope_ptr = inv_ptr->phases[i].isotopes; for (j = 0; j < inv_ptr->phases[i].count_isotopes; j++) { if (isotope_ptr[j].primary == primary_ptr && @@ -3402,7 +3413,6 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) } return OK; } - /* ---------------------------------------------------------------------- */ int Phreeqc:: count_isotope_unknowns(struct inverse *inv_ptr, @@ -3508,7 +3518,6 @@ count_isotope_unknowns(struct inverse *inv_ptr, *isotope_unknowns = isotopes; return (count_isotopes); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: check_isotopes(struct inverse *inv_ptr) @@ -3522,7 +3531,7 @@ check_isotopes(struct inverse *inv_ptr) int err, found_isotope; LDBLE isotope_number; struct master *master_ptr, *primary_ptr; - struct solution *solution_ptr; + cxxSolution *solution_ptr; struct phase *phase_ptr; char token[MAX_LENGTH]; @@ -3531,7 +3540,7 @@ check_isotopes(struct inverse *inv_ptr) */ for (j = 0; j < inv_ptr->count_solns; j++) { - solution_ptr = solution_bsearch(inv_ptr->solns[j], &i, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[j]); xsolution_zero(); add_solution(solution_ptr, 1.0, 1.0); /* @@ -3544,10 +3553,12 @@ check_isotopes(struct inverse *inv_ptr) primary_ptr = master_bsearch(inv_ptr->isotopes[i].elt_name); isotope_number = inv_ptr->isotopes[i].isotope_number; found_isotope = FALSE; - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (solution_ptr->isotopes[k].primary == primary_ptr && - solution_ptr->isotopes[k].isotope_number == + struct master *primary_kit = master_bsearch_primary(kit->second.Get_elt_name().c_str()); + if (primary_kit == primary_ptr && + kit->second.Get_isotope_number() == isotope_number) { found_isotope = TRUE; @@ -3571,7 +3582,7 @@ check_isotopes(struct inverse *inv_ptr) { error_string = sformatf( "In solution %d, isotope ratio(s) are needed for element: %g%s.", - solution_ptr->n_user, (double) isotope_number, + solution_ptr->Get_n_user(), (double) isotope_number, primary_ptr->elt->name); error_msg(error_string, CONTINUE); input_error++; @@ -3581,9 +3592,12 @@ check_isotopes(struct inverse *inv_ptr) /* * Go through solution isotopes and set uncertainties */ - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - solution_ptr->isotopes[k].x_ratio_uncertainty = NAN; + struct master *master_kit = master_bsearch(kit->second.Get_elt_name().c_str()); + struct master *primary_kit = master_bsearch_primary(kit->second.Get_elt_name().c_str()); + kit->second.Set_x_ratio_uncertainty(NAN); /* * Search for secondary or primary master in inverse uncertainties */ @@ -3591,12 +3605,12 @@ check_isotopes(struct inverse *inv_ptr) for (i = 0; i < inv_ptr->count_i_u; i++) { master_ptr = master_bsearch(inv_ptr->i_u[i].elt_name); - if (master_ptr == solution_ptr->isotopes[k].master) + if (master_ptr == master_kit) { ii = i; break; } - if (master_ptr == solution_ptr->isotopes[k].primary) + if (master_ptr == primary_kit) { ii = i; } @@ -3610,48 +3624,45 @@ check_isotopes(struct inverse *inv_ptr) if (j < inv_ptr->i_u[i].count_uncertainties && inv_ptr->i_u[i].uncertainties[j] != NAN) { - solution_ptr->isotopes[k].x_ratio_uncertainty = - inv_ptr->i_u[i].uncertainties[j]; + kit->second.Set_x_ratio_uncertainty(inv_ptr->i_u[i].uncertainties[j]); /* use solution-defined uncertainties second */ } - else if (solution_ptr->isotopes[k].ratio_uncertainty != NAN) + else if (kit->second.Get_ratio_uncertainty() != NAN) { - solution_ptr->isotopes[k].x_ratio_uncertainty = - solution_ptr->isotopes[k].ratio_uncertainty; + kit->second.Set_x_ratio_uncertainty( + kit->second.Get_ratio_uncertainty()); /* use isotope defaults third */ } else { sprintf(token, "%g%s", - (double) solution_ptr->isotopes[k].isotope_number, - solution_ptr->isotopes[k].elt_name); + (double) kit->second.Get_isotope_number(), + kit->second.Get_elt_name().c_str()); for (l = 0; l < count_iso_defaults; l++) { if (strcmp(token, iso_defaults[l].name) == 0) { - solution_ptr->isotopes[k].x_ratio_uncertainty = - iso_defaults[l].uncertainty; + kit->second.Set_x_ratio_uncertainty( + iso_defaults[l].uncertainty); error_string = sformatf( "Solution %d, element %g%s: default isotope ratio uncertainty is used, %g.", - solution_ptr->n_user, - (double) solution_ptr->isotopes[k]. - isotope_number, - solution_ptr->isotopes[k].elt_name, - (double) solution_ptr->isotopes[k]. - x_ratio_uncertainty); + solution_ptr->Get_n_user(), + (double) kit->second.Get_isotope_number(), + kit->second.Get_elt_name().c_str(), + kit->second.Get_x_ratio_uncertainty()); warning_msg(error_string); break; } } } - if (solution_ptr->isotopes[k].x_ratio_uncertainty == NAN) + if (kit->second.Get_x_ratio_uncertainty() == NAN) { error_string = sformatf( "In solution %d, isotope ratio uncertainty is needed for element: %g%s.", - solution_ptr->n_user, - (double) solution_ptr->isotopes[k].isotope_number, - solution_ptr->isotopes[k].elt_name); + solution_ptr->Get_n_user(), + (double) kit->second.Get_isotope_number(), + kit->second.Get_elt_name().c_str()); error_msg(error_string, CONTINUE); input_error++; } @@ -3710,7 +3721,6 @@ check_isotopes(struct inverse *inv_ptr) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: phase_isotope_inequalities(struct inverse *inv_ptr) @@ -3896,21 +3906,20 @@ void Phreeqc:: dump_netpath(struct inverse *inverse_ptr) /* ---------------------------------------------------------------------- */ { - int i, j, l; - char string[MAX_LENGTH]; + int j; + std::string string; char *ptr; - /*if (netpath_dumped) return; */ if (inverse_ptr->netpath == NULL) return; /* open file */ - strcpy(string, inverse_ptr->netpath); - if (replace(".lon", ".lon", string) != TRUE) + string = inverse_ptr->netpath; + if (replace(".lon", ".lon", string) != true) { - strcat(string, ".lon"); + string.append(".lon"); } - netpath_file = fopen(string, "w"); + netpath_file = fopen(string.c_str(), "w"); if (netpath_file == NULL) { error_string = sformatf( "Can't open file, %s.", inverse_ptr->netpath); @@ -3923,24 +3932,26 @@ dump_netpath(struct inverse *inverse_ptr) "2.14 # File format\n"); /* write out each solution */ - for (i = 0; i < count_solution; i++) + std::map::iterator it = Rxn_solution_map.begin(); + for ( ; it != Rxn_solution_map.end(); it++) { - if (solution[i]->n_user < 0) + if (it->second.Get_n_user() < 0) continue; /* flags and description */ - ptr = solution[i]->description; - j = copy_token(string, &ptr, &l); + char * description = string_duplicate(it->second.Get_description().c_str()); + ptr = description; + j = copy_token(string, &ptr); if (j != EMPTY) { - sprintf(string, "%s", solution[i]->description); + string = sformatf("%s", description); } else { - sprintf(string, "Solution %d", solution[i]->n_user); + string = sformatf("Solution %d", it->second.Get_n_user()); } - fprintf(netpath_file, "4020%s\n", string); - + fprintf(netpath_file, "4020%s\n", string.c_str()); + description = (char *) free_check_null(description); /* lat/lon */ fprintf(netpath_file, " # Lat/lon\n"); @@ -3948,12 +3959,12 @@ dump_netpath(struct inverse *inverse_ptr) /* well number */ fprintf(netpath_file, "%15d # Well number\n", - solution[i]->n_user); + it->second.Get_n_user()); /* total number of wells */ fprintf(netpath_file, "%15d # Total wells\n", - count_solution); + Rxn_solution_map.size()); /* address */ fprintf(netpath_file, @@ -3970,90 +3981,90 @@ dump_netpath(struct inverse *inverse_ptr) /* temperature */ fprintf(netpath_file, "%15g # Temperature\n", - (double) solution[i]->tc); + (double) it->second.Get_tc()); /* pH */ fprintf(netpath_file, "%15g # pH\n", - (double) solution[i]->ph); + (double) it->second.Get_ph()); /* DO */ - print_total(netpath_file, solution[i], "O(0)", "Dissolved Oxygen"); + print_total(netpath_file, &(it->second), "O(0)", "Dissolved Oxygen"); /* TDIC */ - print_total(netpath_file, solution[i], "C(4)", "TDIC"); + print_total(netpath_file, &(it->second), "C(4)", "TDIC"); /* Tritium */ - print_isotope(netpath_file, solution[i], "3H(1)", "Tritium"); + print_isotope(netpath_file, &(it->second), "3H(1)", "Tritium"); /* H2S */ - print_total(netpath_file, solution[i], "S(-2)", "H2S"); + print_total(netpath_file, &(it->second), "S(-2)", "H2S"); /* Calcium */ - print_total(netpath_file, solution[i], "Ca", "Calcium"); + print_total(netpath_file, &(it->second), "Ca", "Calcium"); /* Eh */ fprintf(netpath_file, "%15g # Eh\n", - (double) (0.059 * solution[i]->solution_pe)); + (double) (0.059 * it->second.Get_pe())); /* Magnesium */ - print_total(netpath_file, solution[i], "Mg", "Magnesium"); + print_total(netpath_file, &(it->second), "Mg", "Magnesium"); /* Sodium */ - print_total(netpath_file, solution[i], "Na", "Sodium"); + print_total(netpath_file, &(it->second), "Na", "Sodium"); /* Potassium */ - print_total(netpath_file, solution[i], "K", "Potassium"); + print_total(netpath_file, &(it->second), "K", "Potassium"); /* Chloride */ - print_total(netpath_file, solution[i], "Cl", "Chloride"); + print_total(netpath_file, &(it->second), "Cl", "Chloride"); /* Sulfate */ - print_total(netpath_file, solution[i], "S(6)", "Sulfate"); + print_total(netpath_file, &(it->second), "S(6)", "Sulfate"); /* Fluoride */ - print_total(netpath_file, solution[i], "F", "Fluoride"); + print_total(netpath_file, &(it->second), "F", "Fluoride"); /* Silica */ - print_total(netpath_file, solution[i], "Si", "Silica"); + print_total(netpath_file, &(it->second), "Si", "Silica"); /* Bromide */ - print_total(netpath_file, solution[i], "Br", "Bromide"); + print_total(netpath_file, &(it->second), "Br", "Bromide"); /* Boron */ - print_total(netpath_file, solution[i], "B", "Boron"); + print_total(netpath_file, &(it->second), "B", "Boron"); /* Barium */ - print_total(netpath_file, solution[i], "Ba", "Barium"); + print_total(netpath_file, &(it->second), "Ba", "Barium"); /* Lithium */ - print_total(netpath_file, solution[i], "Li", "Lithium"); + print_total(netpath_file, &(it->second), "Li", "Lithium"); /* Strontium */ - print_total(netpath_file, solution[i], "Sr", "Strontium"); + print_total(netpath_file, &(it->second), "Sr", "Strontium"); /* Iron */ - print_total_multi(netpath_file, solution[i], "Iron", "Fe", "Fe(2)", + print_total_multi(netpath_file, &(it->second), "Iron", "Fe", "Fe(2)", "Fe(3)", "", ""); /* Manganese */ - print_total_multi(netpath_file, solution[i], "Manganese", "Mn", + print_total_multi(netpath_file, &(it->second), "Manganese", "Mn", "Mn(2)", "Mn(3)", "Mn(6)", "Mn(7)"); /* Nitrate */ - print_total(netpath_file, solution[i], "N(5)", "Nitrate"); + print_total(netpath_file, &(it->second), "N(5)", "Nitrate"); /* Ammonium */ - print_total_multi(netpath_file, solution[i], "Ammonium", "N(-3)", + print_total_multi(netpath_file, &(it->second), "Ammonium", "N(-3)", "Amm", "", "", ""); /* Phosphate */ - print_total(netpath_file, solution[i], "P", "Phosphate"); + print_total(netpath_file, &(it->second), "P", "Phosphate"); /* DOC */ - print_total_multi(netpath_file, solution[i], "DOC", "Fulvate", + print_total_multi(netpath_file, &(it->second), "DOC", "Fulvate", "Humate", "", "", ""); /* Sp. Cond. */ @@ -4065,45 +4076,45 @@ dump_netpath(struct inverse *inverse_ptr) " # Density\n"); /* Delta C-13 TDIC */ - print_isotope(netpath_file, solution[i], "13C(4)", "Delta C-13 TDIC"); + print_isotope(netpath_file, &(it->second), "13C(4)", "Delta C-13 TDIC"); /* C-14 TDIC */ - print_isotope(netpath_file, solution[i], "14C(4)", "C-14 TDIC"); + print_isotope(netpath_file, &(it->second), "14C(4)", "C-14 TDIC"); /* Delta S-34 (SO4) */ - print_isotope(netpath_file, solution[i], "34S(6)", + print_isotope(netpath_file, &(it->second), "34S(6)", "Delta S-34 (SO4)"); /* Delta S-34 (H2S) */ - print_isotope(netpath_file, solution[i], "34S(-2)", + print_isotope(netpath_file, &(it->second), "34S(-2)", "Delta S-34 (H2S)"); /* Delta Deuterium */ - print_isotope(netpath_file, solution[i], "2H(1)", "Delta Deuterium"); + print_isotope(netpath_file, &(it->second), "2H(1)", "Delta Deuterium"); /* Delta O-18 */ - print_isotope(netpath_file, solution[i], "18O(-2)", "Delta O-18"); + print_isotope(netpath_file, &(it->second), "18O(-2)", "Delta O-18"); /* CH4 (aq) */ - print_total(netpath_file, solution[i], "C(-4)", "CH4 (aq)"); + print_total(netpath_file, &(it->second), "C(-4)", "CH4 (aq)"); /* Sr 87/86 */ - print_isotope(netpath_file, solution[i], "87Sr", "Sr 87/86"); + print_isotope(netpath_file, &(it->second), "87Sr", "Sr 87/86"); /* Al */ - print_total(netpath_file, solution[i], "Al", "Alumninum"); + print_total(netpath_file, &(it->second), "Al", "Alumninum"); /* N2 (aq) */ - print_total(netpath_file, solution[i], "N(0)", "N2 (aq)"); + print_total(netpath_file, &(it->second), "N(0)", "N2 (aq)"); /* N-15 of N2 (aq) */ - print_isotope(netpath_file, solution[i], "15N(0)", "N-15 of N2 (aq)"); + print_isotope(netpath_file, &(it->second), "15N(0)", "N-15 of N2 (aq)"); /* N-15 of Nitrate */ - print_isotope(netpath_file, solution[i], "15N(5)", "N-15 of Nitrate"); + print_isotope(netpath_file, &(it->second), "15N(5)", "N-15 of Nitrate"); /* N-15 of Ammonium */ - print_isotope(netpath_file, solution[i], "15N(-3)", + print_isotope(netpath_file, &(it->second), "15N(-3)", "N-15 of Ammonium"); /* Formation */ @@ -4118,47 +4129,41 @@ dump_netpath(struct inverse *inverse_ptr) } return; } - /* ---------------------------------------------------------------------- */ -struct conc * Phreeqc:: -get_inv_total(struct solution *solution_ptr, const char *elt) +LDBLE Phreeqc:: +get_inv_total(cxxSolution *solution_ptr, const char *elt) /* ---------------------------------------------------------------------- */ { - int i; - - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - if (strcmp(elt, solution_ptr->totals[i].description) == 0) - return (&solution_ptr->totals[i]); + if (strcmp(elt, jit->first.c_str()) == 0) + return jit->second; } - return (NULL); + return (0); } - /* ---------------------------------------------------------------------- */ -struct isotope * Phreeqc:: -get_isotope(struct solution *solution_ptr, const char *elt) +cxxSolutionIsotope *Phreeqc::get_isotope(cxxSolution *solution_ptr, const char *elt) /* ---------------------------------------------------------------------- */ { - int i; - - for (i = 0; i < solution_ptr->count_isotopes; i++) + std::string str_elt = elt; + std::map::iterator it; + it = solution_ptr->Get_isotopes().find(str_elt); + if (it != solution_ptr->Get_isotopes().end()) { - if (strcmp(elt, solution_ptr->isotopes[i].isotope_name) == 0) - return (&solution_ptr->isotopes[i]); + return &(it->second); } return (NULL); } - /* ---------------------------------------------------------------------- */ void Phreeqc:: -print_total(FILE * l_netpath_file, struct solution *solution_ptr, +print_total(FILE * l_netpath_file, cxxSolution *solution_ptr, const char *elt, const char *string) /* ---------------------------------------------------------------------- */ { - struct conc *tot_ptr; - tot_ptr = get_inv_total(solution_ptr, elt); - if (tot_ptr == NULL) + LDBLE moles = get_inv_total(solution_ptr, elt); + if (moles == 0) { fprintf(l_netpath_file, " # %s\n", @@ -4168,18 +4173,17 @@ print_total(FILE * l_netpath_file, struct solution *solution_ptr, { fprintf(l_netpath_file, "%15g # %s\n", - (double) (1000 * tot_ptr->moles / solution_ptr->mass_water), + (double) (1000 * moles / solution_ptr->Get_mass_water()), string); } } - /* ---------------------------------------------------------------------- */ void Phreeqc:: -print_isotope(FILE * l_netpath_file, struct solution *solution_ptr, +print_isotope(FILE * l_netpath_file, cxxSolution *solution_ptr, const char *elt, const char *string) /* ---------------------------------------------------------------------- */ { - struct isotope *iso_ptr; + cxxSolutionIsotope *iso_ptr; iso_ptr = get_isotope(solution_ptr, elt); if (iso_ptr == NULL) { @@ -4191,19 +4195,18 @@ print_isotope(FILE * l_netpath_file, struct solution *solution_ptr, { fprintf(l_netpath_file, "%15g # %s\n", - (double) iso_ptr->ratio, string); + (double) iso_ptr->Get_ratio(), string); } } - /* ---------------------------------------------------------------------- */ void Phreeqc:: -print_total_multi(FILE * l_netpath_file, struct solution *solution_ptr, +print_total_multi(FILE * l_netpath_file, cxxSolution *solution_ptr, const char *string, const char *elt0, const char *elt1, const char *elt2, const char *elt3, const char *elt4) /* ---------------------------------------------------------------------- */ { char elts[5][MAX_LENGTH]; - struct conc *tot_ptr; + LDBLE moles; LDBLE sum; int i, found; @@ -4218,14 +4221,14 @@ print_total_multi(FILE * l_netpath_file, struct solution *solution_ptr, found = FALSE; for (i = 0; i < 5; i++) { - tot_ptr = get_inv_total(solution_ptr, elts[i]); - if (tot_ptr == NULL) + moles = get_inv_total(solution_ptr, elts[i]); + if (moles == 0) { continue; } else { - sum += tot_ptr->moles; + sum += moles; found = TRUE; } } @@ -4239,11 +4242,10 @@ print_total_multi(FILE * l_netpath_file, struct solution *solution_ptr, { fprintf(l_netpath_file, "%15g # %s\n", - (double) (1000 * sum / solution_ptr->mass_water), string); + (double) (1000 * sum / solution_ptr->Get_mass_water()), string); } return; } - /* ---------------------------------------------------------------------- */ int Phreeqc:: dump_netpath_pat(struct inverse *inv_ptr) @@ -4253,12 +4255,10 @@ dump_netpath_pat(struct inverse *inv_ptr) * Prints model */ int i, j, k; - struct solution *solution_ptr, *solution_ptr_orig; + cxxSolution *solution_ptr, *solution_ptr_orig; struct master *master_ptr; LDBLE d1, d2, d3; - char string[MAX_LENGTH], string1[MAX_LENGTH], token[MAX_LENGTH]; - char *ptr, *str_ptr; - int l; + char *ptr; LDBLE sum, sum1, sum_iso, d; LDBLE *array_save, *l_delta_save; int count_unknowns_save, max_row_count_save, max_column_count_save, temp, @@ -4295,26 +4295,26 @@ dump_netpath_pat(struct inverse *inv_ptr) { if (equal(inv_delta1[i], 0.0, toler) == TRUE) continue; - solution_ptr_orig = solution_bsearch(inv_ptr->solns[i], &j, TRUE); - - solution_duplicate(solution_ptr_orig->n_user, -6); - solution_ptr = solution_bsearch(-6, &j, TRUE); + solution_ptr_orig = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); + Utilities::Rxn_copy(Rxn_solution_map, solution_ptr_orig->Get_n_user(), -6); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -6); xsolution_zero(); /* Adjust pH */ if (inv_ptr->carbon == TRUE) { - d1 = solution_ptr->ph; + d1 = solution_ptr->Get_ph(); d2 = inv_delta1[col_ph + i] / inv_delta1[i]; d3 = d1 + d2; - solution_ptr->ph = d3; + solution_ptr->Set_ph(d3); } /* put original totals in master */ - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - master_ptr->total = solution_ptr->totals[j].moles; + master_ptr = master_bsearch(jit->first.c_str()); + master_ptr->total = jit->second; } /* ignore alkalinity */ @@ -4333,12 +4333,14 @@ dump_netpath_pat(struct inverse *inv_ptr) } /* put updated total back in solution */ - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + cxxNameDouble nd; + jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - master_ptr = master_bsearch(solution_ptr->totals[j].description); - solution_ptr->totals[j].moles = master_ptr->total; + master_ptr = master_bsearch(jit->first.c_str()); + nd[jit->first] = master_ptr->total; } - + solution_ptr->Set_totals(nd); /* update isotopes in solution */ if (inv_ptr->count_isotopes > 0) @@ -4346,19 +4348,20 @@ dump_netpath_pat(struct inverse *inv_ptr) /* adjustments to solution isotope composition */ for (j = 0; j < inv_ptr->count_isotope_unknowns; j++) { - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { if (inv_ptr->isotope_unknowns[j].elt_name != - solution_ptr->isotopes[k].elt_name || + string_hsave(kit->second.Get_elt_name().c_str()) || inv_ptr->isotope_unknowns[j].isotope_number != - solution_ptr->isotopes[k].isotope_number) + kit->second.Get_isotope_number()) continue; - d1 = solution_ptr->isotopes[k].ratio; + d1 = kit->second.Get_ratio(); d2 = inv_delta1[col_isotopes + i * inv_ptr->count_isotope_unknowns + j] / inv_delta1[i]; d3 = d1 + d2; - solution_ptr->isotopes[k].ratio = d3; + kit->second.Set_ratio(d3); } } } @@ -4373,24 +4376,26 @@ dump_netpath_pat(struct inverse *inv_ptr) pr.all = temp; pr.punch = temp_punch; phrq_io->Set_punch_on(pr.punch == TRUE); - solution_ptr = solution_bsearch(-7, &j, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, -7); /* Header */ - ptr = solution_ptr_orig->description; - if (copy_token(string, &ptr, &l) != EMPTY) + char * description = string_duplicate(solution_ptr_orig->Get_description().c_str()); + ptr = description; + std::string string; + if (copy_token(string, &ptr) != EMPTY) { fprintf(netpath_file, "%d. %s\n", count_inverse_models, - solution_ptr_orig->description); + solution_ptr_orig->Get_description().c_str()); } else { fprintf(netpath_file, "%d. Solution %d\n", count_inverse_models, - solution_ptr_orig->n_user); + solution_ptr_orig->Get_n_user()); } /* bookkeeping */ count_pat_solutions++; - solnmap[count_current_solutions][0] = solution_ptr_orig->n_user; + solnmap[count_current_solutions][0] = solution_ptr_orig->Get_n_user(); solnmap[count_current_solutions][1] = count_pat_solutions; count_current_solutions++; @@ -4414,19 +4419,20 @@ dump_netpath_pat(struct inverse *inv_ptr) print_total_pat(netpath_file, "Mn", "MN"); print_total_pat(netpath_file, "N", "N"); print_total_pat(netpath_file, "P", "P"); - fprintf(netpath_file, "%14g # TEMP\n", (double) solution_ptr->tc); + fprintf(netpath_file, "%14g # TEMP\n", (double) solution_ptr->Get_tc()); print_total_pat(netpath_file, "S(-2)", "H2S"); print_total_pat(netpath_file, "S(6)", "SO4"); /* N15 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "15N") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "15N") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4471,7 +4477,7 @@ dump_netpath_pat(struct inverse *inv_ptr) } /* pH */ - fprintf(netpath_file, "%14g # PH\n", (double) solution_ptr->ph); + fprintf(netpath_file, "%14g # PH\n", (double) solution_ptr->Get_ph()); /*H2CO3* */ d = 1000 * (molality("H2CO3") + molality("CO2")); @@ -4517,12 +4523,13 @@ dump_netpath_pat(struct inverse *inv_ptr) /*C13 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "13C") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "13C") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4539,12 +4546,13 @@ dump_netpath_pat(struct inverse *inv_ptr) /*C14 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "14C") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "14C") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4561,13 +4569,14 @@ dump_netpath_pat(struct inverse *inv_ptr) /*SR87 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "87Sr") != + if (strstr(kit->second.Get_isotope_name().c_str(), "87Sr") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4583,12 +4592,13 @@ dump_netpath_pat(struct inverse *inv_ptr) /*D*/ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "2H") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "2H") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4604,24 +4614,25 @@ dump_netpath_pat(struct inverse *inv_ptr) /*O-18 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "18O") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "18O") != NULL) { - if (strcmp(solution_ptr->isotopes[k].elt_name, "O(-2)") == 0) + if (strcmp(kit->second.Get_elt_name().c_str(), "O(-2)") == 0) { - d = solution_ptr->total_o - total("O(0)"); + d = solution_ptr->Get_total_o() - total("O(0)"); } - else if (strcmp(solution_ptr->isotopes[k].elt_name, "H(1)") + else if (strcmp(kit->second.Get_elt_name().c_str(), "H(1)") == 0) { - d = solution_ptr->total_h - total("H(0)"); + d = solution_ptr->Get_total_h() - total("H(0)"); } else { - d = total(solution_ptr->isotopes[k].elt_name); + d = total(kit->second.Get_elt_name().c_str()); } - sum_iso += solution_ptr->isotopes[k].ratio * d; + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4637,12 +4648,13 @@ dump_netpath_pat(struct inverse *inv_ptr) /*TRITIUM*/ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "3H") != NULL) + if (strstr(kit->second.Get_isotope_name().c_str(), "3H") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4659,13 +4671,14 @@ dump_netpath_pat(struct inverse *inv_ptr) /*34SSO4 */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "34S(6)") != + if (strstr(kit->second.Get_isotope_name().c_str(), "34S(6)") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4682,13 +4695,14 @@ dump_netpath_pat(struct inverse *inv_ptr) /*34SH2S */ sum_iso = 0; sum = 0; - for (k = 0; k < solution_ptr->count_isotopes; k++) + kit = solution_ptr->Get_isotopes().begin(); + for ( ; kit != solution_ptr->Get_isotopes().end(); kit++) { - if (strstr(solution_ptr->isotopes[k].isotope_name, "34S(-2)") != + if (strstr(kit->second.Get_isotope_name().c_str(), "34S(-2)") != NULL) { - d = total(solution_ptr->isotopes[k].elt_name); - sum_iso += solution_ptr->isotopes[k].ratio * d; + d = total(kit->second.Get_elt_name().c_str()); + sum_iso += kit->second.Get_ratio() * d; sum += d; } } @@ -4716,23 +4730,24 @@ dump_netpath_pat(struct inverse *inv_ptr) /* * Open model file */ - strcpy(string, inv_ptr->pat); + std::string string; + string = inv_ptr->pat; replace(".pat", "", string); - string_trim(string); - sprintf(string1, "%s-%d.mod", string, count_inverse_models); - model_file = fopen(string1, "w"); + trim(string); + std::string string1 = sformatf("%s-%d.mod", string.c_str(), count_inverse_models); + model_file = fopen(string1.c_str(), "w"); if (model_file == NULL) { - error_string = sformatf( "Can't open file, %s.", string); + error_string = sformatf( "Can't open file, %s.", string.c_str()); error_msg(error_string, STOP); } - add_to_file("model.fil", string1); + add_to_file("model.fil", string1.c_str()); /* * Write header */ - fprintf(model_file, "%s\n", string); + fprintf(model_file, "%s\n", string.c_str()); /* * Write well numbers @@ -4770,9 +4785,9 @@ dump_netpath_pat(struct inverse *inv_ptr) { if (master[j]->in == TRUE) { - strcpy(string, master[j]->elt->name); - str_toupper(string); - fprintf(model_file, " %-2s", string); + string = master[j]->elt->name; + Utilities::str_toupper(string); + fprintf(model_file, " %-2s", string.c_str()); } } fprintf(model_file, " %-2s", "RS"); @@ -4781,23 +4796,23 @@ dump_netpath_pat(struct inverse *inv_ptr) */ for (j = 0; j < inv_ptr->count_isotopes; j++) { - sprintf(string, "%d%s", (int) inv_ptr->isotopes[j].isotope_number, + string = sformatf("%d%s", (int) inv_ptr->isotopes[j].isotope_number, inv_ptr->isotopes[j].elt_name); - if (strcmp(string, "13C") == 0) + if (strcmp(string.c_str(), "13C") == 0) fprintf(model_file, " %-2s", "I1"); - if (strcmp(string, "14C") == 0) + if (strcmp(string.c_str(), "14C") == 0) fprintf(model_file, " %-2s", "I2"); - if (strcmp(string, "34S") == 0) + if (strcmp(string.c_str(), "34S") == 0) fprintf(model_file, " %-2s", "I3"); - if (strcmp(string, "87Sr") == 0) + if (strcmp(string.c_str(), "87Sr") == 0) fprintf(model_file, " %-2s", "I4"); - if (strcmp(string, "15N") == 0) + if (strcmp(string.c_str(), "15N") == 0) fprintf(model_file, " %-2s", "I9"); - if (strcmp(string, "2H") == 0) + if (strcmp(string.c_str(), "2H") == 0) fprintf(model_file, " %-2s", "D "); - if (strcmp(string, "3H") == 0) + if (strcmp(string.c_str(), "3H") == 0) fprintf(model_file, " %-2s", "TR"); - if (strcmp(string, "18O") == 0) + if (strcmp(string.c_str(), "18O") == 0) fprintf(model_file, " %-2s", "18"); } @@ -4832,45 +4847,44 @@ dump_netpath_pat(struct inverse *inv_ptr) /* * Write phase name and constraints */ - strncpy(string, inv_ptr->phases[i].name, (size_t) 8); - str_ptr = string_pad(string, 10); - str_ptr[10] = '\0'; + string = inv_ptr->phases[i].name; + string = string.substr(0,8); + string = Utilities::pad_right(string, 8); if (inv_ptr->phases[i].force == TRUE) { - str_ptr[8] = 'F'; + string += 'F'; } else { - str_ptr[8] = ' '; + string += ' '; } switch (inv_ptr->phases[i].constraint) { case EITHER: - str_ptr[9] = ' '; + string += ' '; break; case PRECIPITATE: if (exch == TRUE) { - str_ptr[9] = '+'; + string += '+'; } else { - str_ptr[9] = '-'; + string += '-'; } break; case DISSOLVE: if (exch == TRUE) { - str_ptr[9] = '-'; + string += '-'; } else { - str_ptr[9] = '+'; + string += '+'; } break; } - fprintf(model_file, "%-10s", str_ptr); - str_ptr = (char *) free_check_null(str_ptr); + fprintf(model_file, "%-10s", string.c_str()); /* * Write stoichiometry */ @@ -4889,19 +4903,21 @@ dump_netpath_pat(struct inverse *inv_ptr) continue; if (strcmp(master_ptr->elt->name, "E") == 0) continue; - strcpy(string, master_ptr->elt->name); + string = master_ptr->elt->name; + if (strcmp(master_ptr->elt->name, "X") == 0) { - strcpy(string, "Na"); + string = "Na"; f = 1.0; } - str_toupper(string); - fprintf(model_file, " %-2s%12.7f", string, + Utilities::str_toupper(string); + fprintf(model_file, " %-2s%12.7f", string.c_str(), (double) (next_elt->coef * f)); } /* * Calculate RS */ + std::string token; sum = 0; for (rxn_ptr = inv_ptr->phases[i].phase->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++) @@ -4926,13 +4942,14 @@ dump_netpath_pat(struct inverse *inv_ptr) } else { - strcpy(string, rxn_ptr->s->secondary->elt->name); + string = rxn_ptr->s->secondary->elt->name; replace("(", " ", string); replace(")", " ", string); - ptr = string; - copy_token(token, &ptr, &l); - copy_token(string1, &ptr, &l); - sscanf(string1, SCANFORMAT, &f); + std::string::iterator b = string.begin(); + std::string::iterator e = string.end(); + CParser::copy_token(token, b, e); + CParser::copy_token(string1, b, e); + sscanf(string1.c_str(), SCANFORMAT, &f); sum += f * rxn_ptr->coef; } } @@ -4964,26 +4981,26 @@ dump_netpath_pat(struct inverse *inv_ptr) } } d3 = d1 + d2; - sprintf(string, "%d%s", (int) isotope_ptr[k].isotope_number, + string = sformatf("%d%s", (int) isotope_ptr[k].isotope_number, isotope_ptr[k].elt_name); - if (strcmp(string, "13C") == 0) + if (strcmp(string.c_str(), "13C") == 0) fprintf(model_file, " %-2s%12.7f", "I1", (double) d3); - if (strcmp(string, "14C") == 0) + if (strcmp(string.c_str(), "14C") == 0) fprintf(model_file, " %-2s%12.7f", "I2", (double) d3); - if (strcmp(string, "34S") == 0) + if (strcmp(string.c_str(), "34S") == 0) { fprintf(model_file, " %-2s%12.7f", "I3", (double) d3); fprintf(model_file, " %-2s%12.7f", "I7", 0.0); } - if (strcmp(string, "87Sr") == 0) + if (strcmp(string.c_str(), "87Sr") == 0) fprintf(model_file, " %-2s%12.7f", "I4", (double) d3); - if (strcmp(string, "15N") == 0) + if (strcmp(string.c_str(), "15N") == 0) fprintf(model_file, " %-2s%12.7f", "I9", (double) d3); - if (strcmp(string, "2H") == 0) + if (strcmp(string.c_str(), "2H") == 0) fprintf(model_file, " %-2s%12.7f", "D ", (double) d3); - if (strcmp(string, "3H") == 0) + if (strcmp(string.c_str(), "3H") == 0) fprintf(model_file, " %-2s%12.7f", "TR", (double) d3); - if (strcmp(string, "18O") == 0) + if (strcmp(string.c_str(), "18O") == 0) fprintf(model_file, " %-2s%12.7f", "18", (double) d3); } /* @@ -5038,7 +5055,6 @@ dump_netpath_pat(struct inverse *inv_ptr) state = INVERSE; return (OK); } - /* ---------------------------------------------------------------------- */ void Phreeqc:: print_total_pat(FILE * l_netpath_file, const char *elt, const char *string) @@ -5059,25 +5075,26 @@ print_total_pat(FILE * l_netpath_file, const char *elt, const char *string) fprintf(l_netpath_file, "%14g%1s # %s\n", (double) d, " ", string); } } - /* ---------------------------------------------------------------------- */ int Phreeqc:: set_initial_solution(int n_user_old, int n_user_new) /* ---------------------------------------------------------------------- */ { - int j; - struct solution *solution_ptr; - struct conc *conc_ptr; - - solution_duplicate(n_user_old, n_user_new); - solution_ptr = solution_bsearch(n_user_new, &j, TRUE); - solution_ptr->new_def = TRUE; - solution_ptr->n_user_end = n_user_new; - for (j = 0; solution_ptr->totals[j].description != NULL; j++) + cxxSolution *solution_ptr; + Utilities::Rxn_copy(Rxn_solution_map, n_user_old, n_user_new); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user_new); + solution_ptr->Set_new_def(true); + if (solution_ptr->Get_initial_data() == NULL) + solution_ptr->Create_initial_data(); + solution_ptr->Set_n_user_end(n_user_new); + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - conc_ptr = &solution_ptr->totals[j]; - conc_ptr->input_conc = conc_ptr->moles / solution_ptr->mass_water; - conc_ptr->units = string_hsave("Mol/kgw"); + cxxISolutionComp temp_comp; + temp_comp.Set_description(jit->first.c_str()); + temp_comp.Set_input_conc(jit->second / solution_ptr->Get_mass_water()); + temp_comp.Set_units("Mol/kgw"); + solution_ptr->Get_initial_data()->Get_comps()[jit->first.c_str()] = temp_comp; } return (OK); } diff --git a/phreeqc/isotopes.cpp b/phreeqc/isotopes.cpp index 883eace2..729f0310 100644 --- a/phreeqc/isotopes.cpp +++ b/phreeqc/isotopes.cpp @@ -1,5 +1,6 @@ #include "Phreeqc.h" #include "phqalloc.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ @@ -456,11 +457,10 @@ read_isotope_alphas(void) /* ---------------------------------------------------------------------- */ int Phreeqc:: -add_isotopes(struct solution *solution_ptr) +add_isotopes(cxxSolution &solution_ref) /* ---------------------------------------------------------------------- */ { int i; - const char *ptr; struct master_isotope *master_isotope_ptr; LDBLE total_moles; /* @@ -474,26 +474,26 @@ add_isotopes(struct solution *solution_ptr) if (master_isotope_ptr != NULL) { total_moles = total_h_x; - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + calculate_isotope_moles(master_isotope_ptr->elt, &solution_ref, total_moles); } master_isotope_ptr = master_isotope_search("O"); if (master_isotope_ptr != NULL) { total_moles = total_o_x; - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + calculate_isotope_moles(master_isotope_ptr->elt, &solution_ref, total_moles); } - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + cxxNameDouble::iterator it = solution_ref.Get_totals().begin(); + for ( ; it != solution_ref.Get_totals().end(); it++) { - ptr = solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); + master_isotope_ptr = master_isotope_search(it->first.c_str()); if (master_isotope_ptr == NULL) continue; if (master_isotope_ptr->minor_isotope == FALSE) { total_moles = total(master_isotope_ptr->name); - calculate_isotope_moles(master_isotope_ptr->elt, solution_ptr, + calculate_isotope_moles(master_isotope_ptr->elt, &solution_ref, total_moles); } } @@ -515,12 +515,11 @@ add_isotopes(struct solution *solution_ptr) /* ---------------------------------------------------------------------- */ int Phreeqc:: calculate_isotope_moles(struct element *elt_ptr, - struct solution *solution_ptr, LDBLE total_moles) + cxxSolution *solution_ptr, LDBLE total_moles) /* ---------------------------------------------------------------------- */ { int i, j, l_iter; int count_isotopes, total_is_major; - const char *ptr; struct master_isotope *master_isotope_ptr, *master_isotope_ptr1; struct master_isotope list[MAX_ELTS]; LDBLE m_major, tot; @@ -565,10 +564,10 @@ calculate_isotope_moles(struct element *elt_ptr, } count_isotopes++; } - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + std::map::iterator it = solution_ptr->Get_initial_data()->Get_comps().begin(); + for ( ; it != solution_ptr->Get_initial_data()->Get_comps().end(); it++) { - ptr = solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); + master_isotope_ptr = master_isotope_search(it->first.c_str()); if (master_isotope_ptr == NULL) continue; if (master_isotope_ptr->elt != elt_ptr) @@ -672,16 +671,16 @@ calculate_isotope_moles(struct element *elt_ptr, { total_o_x = m_major; } - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + cxxNameDouble nd(solution_ptr->Get_totals()); + cxxNameDouble::iterator iit = solution_ptr->Get_totals().begin(); + for ( ; iit != solution_ptr->Get_totals().end(); iit++) { - ptr = solution_ptr->totals[i].description; - master_isotope_ptr = master_isotope_search(ptr); + master_isotope_ptr = master_isotope_search(iit->first.c_str()); if (master_isotope_ptr == NULL) continue; if (master_isotope_ptr->elt != elt_ptr) continue; - solution_ptr->totals[i].moles = master_isotope_ptr->moles; - solution_ptr->totals[i].input_conc = master_isotope_ptr->moles; + nd[iit->first] = master_isotope_ptr->moles; } return (OK); diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index cc9e7ea2..afa11379 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -129,98 +129,6 @@ calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step) */ return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_kinetic_reaction(struct kinetics *kinetics_ptr, LDBLE time_step) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components to - * determine rates and - * a list of elements and amounts in - * the reaction. - */ - int i, j, return_value; - LDBLE coef; - char l_command[] = "run"; - struct rate *rate_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - return_value = OK; - count_elts = 0; - paren_count = 0; - rate_time = time_step; - -/* t1 = clock(); */ - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - coef = 0.0; -/* - * Send command to basic interpreter - */ - rate_ptr = rate_search(kinetics_ptr->comps[i].rate_name, &j); - if (rate_ptr == NULL) - { - error_string = sformatf( "Rate not found for %s", - kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - else - { - rate_moles = NAN; - rate_m = kinetics_ptr->comps[i].m; - rate_m0 = kinetics_ptr->comps[i].m0; - rate_p = kinetics_ptr->comps[i].d_params; - count_rate_p = kinetics_ptr->comps[i].count_d_params; - if (rate_ptr->new_def == TRUE) - { - if (basic_compile - (rates[j].commands, &rates[j].linebase, &rates[j].varbase, - &rates[j].loopbase) != 0) - { - error_string = sformatf( "Fatal Basic error in rate %s.", - kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - - rate_ptr->new_def = FALSE; - } - if (basic_run - (l_command, rates[j].linebase, rates[j].varbase, - rates[j].loopbase) != 0) - { - error_string = sformatf( "Fatal Basic error in rate %s.", - kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - if (rate_moles == NAN) - { - error_string = sformatf( "Moles of reaction not SAVE'd for %s.", - kinetics_ptr->comps[i].rate_name); - error_msg(error_string, STOP); - } - else - { - - coef = rate_moles; - } - } -/* - * Accumulate moles of reaction for component - */ - kinetics_ptr->comps[i].moles += coef; - if (coef == 0.0) - continue; - } -/* t2=clock(); - printf("secs in reac %e, t2 %e\n", t2-t1, t1); - */ - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) @@ -231,9 +139,7 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) * using extrapolated values, which were * stored in moles in run_kinetics */ - //int i, j, k; LDBLE coef; - //char token[MAX_LENGTH]; struct phase *phase_ptr; struct master *master_ptr; /* @@ -279,14 +185,12 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) } } if (use.Get_exchange_ptr() != NULL - && ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate()) + && use.Get_exchange_ptr()->Get_related_rate()) { - cxxExchange * exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); - std::map::iterator it = exchange_ptr->Get_exchComps().begin(); - for ( ; it != exchange_ptr->Get_exchComps().end(); it++) + cxxExchange * exchange_ptr = use.Get_exchange_ptr(); + for(size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - std::string name(it->second.Get_rate_name()); - + std::string name(exchange_ptr->Get_exchange_comps()[j].Get_rate_name()); if (name.size() > 0) { if (strcmp_nocase @@ -294,28 +198,32 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) name.c_str()) == 0) { /* found kinetics component */ - add_elt_list(it->second.Get_formula_totals(), -coef*it->second.Get_phase_proportion()); + char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str()); + char * ptr = formula; + get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()); + free_check_null(formula); } } } } - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->related_rate == TRUE) + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_related_rate()) { - for (int j = 0; j < use.Get_surface_ptr()->count_comps; j++) + for (size_t j = 0; j < use.Get_surface_ptr()->Get_surface_comps().size(); j++) { - if (use.Get_surface_ptr()->comps[j].rate_name != NULL) + cxxSurfaceComp *surface_comp_ptr = &(use.Get_surface_ptr()->Get_surface_comps()[j]); + if (surface_comp_ptr->Get_rate_name().size() > 0) { if (strcmp_nocase (kinetics_comp_ptr->Get_rate_name().c_str(), - use.Get_surface_ptr()->comps[j].rate_name) == 0) + surface_comp_ptr->Get_rate_name().c_str()) == 0) { /* found kinetics component */ - char * temp_formula = string_duplicate(use.Get_surface_ptr()->comps[j].formula); + char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); char *ptr = temp_formula; /* Surface = 0 when m becomes low ... */ - if (0.9 * use.Get_surface_ptr()->comps[j].phase_proportion * + if (0.9 * surface_comp_ptr->Get_phase_proportion() * (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) { master_ptr = master_bsearch(ptr); @@ -323,10 +231,7 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) } else { - get_elts_in_species(&ptr, - -coef * - use.Get_surface_ptr()->comps[j]. - phase_proportion); + get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()); } free_check_null(temp_formula); } @@ -337,124 +242,6 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) kinetics_ptr->Set_totals(elt_list_NameDouble()); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_final_kinetic_reaction(struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components to - * using extrapolated values, which were - * stored in moles in run_kinetics - */ - int i, j, k; - LDBLE coef; - char token[MAX_LENGTH]; - struct phase *phase_ptr; - struct master *master_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - kinetics_ptr->totals = - (struct elt_list *) free_check_null(kinetics_ptr->totals); - count_elts = 0; - paren_count = 0; - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - if (kinetics_ptr->comps[i].moles > m_temp[i]) - { - kinetics_ptr->comps[i].moles = m_temp[i]; - kinetics_ptr->comps[i].m = 0; - } - coef = kinetics_ptr->comps[i].moles; - if (coef == 0.0) - continue; -/* - * Reactant is a pure phase, copy formula into token - */ - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) - { - phase_ptr = NULL; - strcpy(token, kinetics_ptr->comps[i].list[j].name); - phase_ptr = phase_bsearch(token, &k, FALSE); - if (phase_ptr != NULL) - { - add_elt_list(phase_ptr->next_elt, - coef * kinetics_ptr->comps[i].list[j].coef); - } - else - { - char * temp_name = string_duplicate(kinetics_ptr->comps[i].list[j].name); - char * ptr = temp_name; - get_elts_in_species(&ptr, - coef * - kinetics_ptr->comps[i].list[j].coef); - free_check_null(temp_name); - } - } - if (use.Get_exchange_ptr() != NULL - //&& use.Get_exchange_ptr()->related_rate == TRUE) - && ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate()) - { - cxxExchange * exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); - std::map::iterator it = exchange_ptr->Get_exchComps().begin(); - for ( ; it != exchange_ptr->Get_exchComps().end(); it++) - { - std::string name(it->second.Get_rate_name()); - - if (name.size() > 0) - { - if (strcmp_nocase - (kinetics_ptr->comps[i].rate_name, - name.c_str()) == 0) - { - /* found kinetics component */ - add_elt_list(it->second.Get_formula_totals(), -coef*it->second.Get_phase_proportion()); - } - } - } - - } - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->related_rate == TRUE) - { - for (j = 0; j < use.Get_surface_ptr()->count_comps; j++) - { - if (use.Get_surface_ptr()->comps[j].rate_name != NULL) - { - if (strcmp_nocase - (kinetics_ptr->comps[i].rate_name, - use.Get_surface_ptr()->comps[j].rate_name) == 0) - { - /* found kinetics component */ - char * temp_formula = string_duplicate(use.Get_surface_ptr()->comps[j].formula); - char *ptr = temp_formula; -/* Surface = 0 when m becomes low ... - */ - if (0.9 * use.Get_surface_ptr()->comps[j].phase_proportion * - (kinetics_ptr->comps[i].m) < MIN_RELATED_SURFACE) - { - master_ptr = master_bsearch(ptr); - master_ptr->total = 0.0; - } - else - { - get_elts_in_species(&ptr, - -coef * - use.Get_surface_ptr()->comps[j]. - phase_proportion); - } - free_check_null(temp_formula); - } - } - } - } - } - kinetics_ptr->totals = elt_list_save(); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -479,7 +266,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, int equal_rate, zero_rate; cxxPPassemblage *pp_assemblage_save = NULL; - //struct ss_assemblage *ss_assemblage_save = NULL; cxxSSassemblage *ss_assemblage_save = NULL; LDBLE b31 = 3. / 40., b32 = 9. / 40., @@ -494,17 +280,15 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, * Save kinetics i and solution i, if necessary */ save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); - //kinetics_duplicate(i, save_old); Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); if (nsaver != i) { - solution_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_solution_map, i, save_old); } /* * Malloc some space */ - //if (kinetics_bsearch(i, &m) == NULL) kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); if (kinetics_ptr == NULL) return (OK); @@ -589,7 +373,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, */ if (l_bad == TRUE) { - //for (j = 0; j < n_reactions; j++) for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); @@ -1242,845 +1025,13 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, h = (kin_time - h_sum); } } -#if !defined(PHREEQCI_GUI) -#ifndef PHREEQ98 - if (pr.status == TRUE && status_on == TRUE - && (int) (1e3 / CLOCKS_PER_SEC * ((float) clock() - status_timer)) > status_interval) { char str[MAX_LENGTH]; - backspace_screen(37); sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad, step_ok, (int) (100 * h_sum / kin_time)); - screen_msg(sformatf("%-37s", str)); + status(0, str, true); } -#endif -#endif - } - - EQUAL_RATE_OUT: - -/* - * Run one more time to get distribution of species - */ - if (state >= REACTION || nsaver != i) - { - set_and_run_wrapper(i, NOMIX, FALSE, nsaver, 0.); - run_reactions_iterations += iterations; - } -/* saver(); */ /* reset for printing */ - if (use_mix == DISP) - { - //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; - use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); - use.Set_mix_in(true); - use.Set_n_mix_user(i); - } - else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) - { - //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); - use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); - if (use.Get_mix_ptr() != NULL) - { - use.Set_mix_in(true); - use.Set_n_mix_user(i); - } - } -/* - * Restore solution i, if necessary - */ - if (nsaver != i) - { - solution_duplicate(save_old, i); - } - rk_moles = (LDBLE *) free_check_null(rk_moles); - - rate_sim_time = rate_sim_time_start + kin_time; - use.Set_kinetics_in(true); - - /* Free space */ - - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } - return (OK); -} - #ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Runge-Kutta-Fehlberg method; 6 evaluations of the derivative - * give O(h^5) global error and error estimate - * calc_kinetic_reaction(.., ..) calculates moles of intermediate derivatives; - * these are calc'd for the whole step h. - * calc_final_kinetic reaction(..) translates moles to PHREEQC reaction. - */ - int j, k, m, save_old; - int l_bad, step_bad, step_ok; - int n_reactions; - LDBLE h, h_old, h_sum; - LDBLE *rk_moles; - LDBLE l_error, error_max, safety, moles_max, moles_reduction; - cxxKinetics *kinetics_ptr; - int equal_rate, zero_rate; - - cxxPPassemblage *pp_assemblage_save = NULL; - //struct ss_assemblage *ss_assemblage_save = NULL; - cxxSSassemblage *ss_assemblage_save = NULL; - - LDBLE b31 = 3. / 40., b32 = 9. / 40., - b51 = -11. / 54., b53 = -70. / 27., b54 = 35. / 27., - b61 = 1631. / 55296., b62 = 175. / 512., b63 = 575. / 13824., b64 = - 44275. / 110592., b65 = 253. / 4096., c1 = 37. / 378., c3 = - 250. / 621., c4 = 125. / 594., c6 = 512. / 1771., dc5 = - -277. / 14336.; - LDBLE dc1 = c1 - 2825. / 27648., dc3 = c3 - 18575. / 48384., dc4 = - c4 - 13525. / 55296., dc6 = c6 - 0.25; -/* - * Save kinetics i and solution i, if necessary - */ - save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); - //kinetics_duplicate(i, save_old); - Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); - if (nsaver != i) - { - solution_duplicate(i, save_old); - } - -/* - * Malloc some space - */ - //if (kinetics_bsearch(i, &m) == NULL) - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i) - if (kinetics_ptr == NULL) - return (OK); - n_reactions = kinetics[m].count_comps; - rk_moles = - (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); - if (rk_moles == NULL) - malloc_error(); - - /*if (use_mix != NOMIX) last_model.force_prep = TRUE; */ - set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); - run_reactions_iterations += iterations; - - saver(); - if (state == TRANSPORT || state == PHAST) - { - set_transport(i, NOMIX, TRUE, i); - } - else if (state == ADVECTION) - { - set_advection(i, NOMIX, TRUE, i); - } - else if (state == REACTION) - { - set_reaction(i, NOMIX, TRUE); - } - kinetics_ptr = kinetics_bsearch(i, &m); - - step_bad = step_ok = 0; - l_bad = FALSE; - h_sum = 0.; - h = h_old = kin_time; - moles_max = 0.1; - moles_reduction = 1.0; - safety = 0.7; - if (kinetics_ptr->rk < 1) - kinetics_ptr->rk = 1; - else if (kinetics_ptr->rk > 3) - kinetics_ptr->rk = 6; - - if (kinetics_ptr->rk == 6) - equal_rate = FALSE; - else - equal_rate = TRUE; -/* - * if step_divide > 1, initial timestep is divided - * if < 1, step_divide indicates maximal reaction... - */ - if (kinetics_ptr->step_divide > 1.0) - { - h = h_old = kin_time / kinetics_ptr->step_divide; - equal_rate = FALSE; - } - else if (kinetics_ptr->step_divide < 1.0) - moles_max = kinetics_ptr->step_divide; - - rate_sim_time = rate_sim_time_start + h_sum; - - status(0, NULL); - while (h_sum < kin_time) - { - - if (step_bad > kinetics_ptr->bad_step_max) - { - error_string = sformatf( - "Bad RK steps > %d. Please decrease (time)step or increase -bad_step_max.", - kinetics_ptr->bad_step_max); - error_msg(error_string, STOP); - } - - MOLES_TOO_LARGE: - if (moles_reduction > 1.0) - { - h_old = h; - h = safety * h / (1.0 + moles_reduction); - moles_reduction = 1.0; - equal_rate = FALSE; - l_bad = TRUE; - } -/* - * find k1 - */ - if (l_bad == TRUE) - { - for (j = 0; j < n_reactions; j++) - { - rk_moles[j] *= (h / h_old); - kinetics_ptr->comps[j].moles = rk_moles[j] * 0.2; - kinetics_ptr->comps[j].m = m_temp[j]; - } - l_bad = FALSE; - } - else - { -/* - * define pointers for calc_kinetic_, they are lost after saver()... - */ - if (state == TRANSPORT || state == PHAST) - { - set_transport(i, NOMIX, TRUE, i); - } - else if (state == ADVECTION) - { - set_advection(i, NOMIX, TRUE, i); - } - else if (state == REACTION) - { - set_reaction(i, NOMIX, TRUE); - } - /* - * Moles of minerals and solid solutions may change to make positive - * concentrations. Reactions may take out more than is present in - * solution. - */ - if (use.Get_pp_assemblage_ptr() != NULL) - { - cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_pp_assemblage_ptr()->Get_n_user()); - assert(pp_assemblage_ptr); - pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); - } - if (use.Get_ss_assemblage_ptr() != NULL) - { - cxxSSassemblage * ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_ss_assemblage_ptr()->Get_n_user()); - assert(ss_assemblage_ptr); - ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); - } - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = 0.; - m_temp[j] = kinetics_ptr->comps[j].m; - } - - rate_sim_time = rate_sim_time_start + h_sum; - calc_kinetic_reaction(kinetics_ptr, h); - - /* store k1 in rk_moles ... */ - for (j = 0; j < n_reactions; j++) - { - if (moles_reduction * moles_max < - fabs(kinetics_ptr->comps[j].moles)) - { - moles_reduction = - fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k2 ... */ - rk_moles[j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles *= 0.2; - } - if (moles_reduction > 1.0) - goto MOLES_TOO_LARGE; - } -/* - * Quit rk with rk = 1 and equal rates ... - */ - if (kinetics_ptr->rk == 1 && equal_rate) - { - zero_rate = TRUE; - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = rk_moles[j]; - if (fabs(kinetics_ptr->comps[j].moles) > MIN_TOTAL) - zero_rate = FALSE; - } - - if (zero_rate == FALSE) - { - calc_final_kinetic_reaction(kinetics_ptr); - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) - kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == - MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; - calc_kinetic_reaction(kinetics_ptr, h); - for (j = 0; j < n_reactions; j++) - { - if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > - kinetics_ptr->comps[j].tol) - { - equal_rate = FALSE; - break; - } - } - } - if (zero_rate || equal_rate) - { - /* removing the following line causes different results for - example 6 distributed with the program */ - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } - goto EQUAL_RATE_OUT; - } - else - { - kinetics_ptr->rk = 3; - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = 0.2 * rk_moles[j]; - } - } - } -/* - * Continue with rk ... - */ - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; - -/* - * find k2 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.2 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) - { - Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - - /* store k2 in rk_moles */ - k = n_reactions; - for (j = 0; j < n_reactions; j++) - { - if (moles_reduction * moles_max < - fabs(kinetics_ptr->comps[j].moles)) - { - moles_reduction = - fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k3 */ - rk_moles[k + j] = kinetics_ptr->comps[j].moles; - - kinetics_ptr->comps[j].moles = b31 * rk_moles[j] - + b32 * rk_moles[k + j]; -/* - * check for equal_rate ... - */ - if (equal_rate - && fabs(rk_moles[j] - rk_moles[k + j]) > - kinetics_ptr->comps[j].tol) - { - equal_rate = FALSE; - } - } - if (moles_reduction > 1.0) - goto MOLES_TOO_LARGE; -/* - * Quit rk with rk = 2 and equal rates ... - */ - if (kinetics_ptr->rk == 2 && equal_rate) - { - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = - 0.3 * rk_moles[j] + 0.7 * rk_moles[k + j]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) - kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j = 0; j < n_reactions; j++) - { - if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > - kinetics_ptr->comps[j].tol) - { - equal_rate = FALSE; - break; - } - } - if (equal_rate) - kinetics_ptr->rk = 1; - - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - goto EQUAL_RATE_OUT; - } -/* - * Continue runge_kutta.. - */ - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k3 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.3 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) - { - Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - - /* store k3 in rk_moles */ - k = 2 * n_reactions; - for (j = 0; j < n_reactions; j++) - { - if (moles_reduction * moles_max < - fabs(kinetics_ptr->comps[j].moles)) - { - moles_reduction = - fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - /* define reaction for calculating k4 ... */ - rk_moles[k + j] = kinetics_ptr->comps[j].moles; - - kinetics_ptr->comps[j].moles = 0.3 * rk_moles[j] - - 0.9 * rk_moles[n_reactions + j] + 1.2 * rk_moles[k + j]; -/* - * check for equal_rate ... - */ - if (equal_rate - && fabs(rk_moles[j] - rk_moles[k + j]) > - kinetics_ptr->comps[j].tol) - equal_rate = FALSE; - } - if (moles_reduction > 1.0) - goto MOLES_TOO_LARGE; -/* - * Quit rk with rk = 3 and equal rates ... - */ - if (kinetics_ptr->rk == 3 && equal_rate) - { - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = 0.5 * rk_moles[j] - - 1.5 * rk_moles[n_reactions + j] + 2 * rk_moles[k + j]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) - kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j = 0; j < n_reactions; j++) - { - if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > - kinetics_ptr->comps[j].tol) - { - equal_rate = FALSE; - break; - } - } - if (equal_rate) - kinetics_ptr->rk = 1; - - saver(); - - /* Free space */ - - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } - goto EQUAL_RATE_OUT; - } -/* - * Continue runge_kutta.. - */ - - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k4 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.6 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) - { - Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - - /* store k4 in rk_moles */ - k = 3 * n_reactions; - for (j = 0; j < n_reactions; j++) - { - if (moles_reduction * moles_max < - fabs(kinetics_ptr->comps[j].moles)) - { - moles_reduction = - fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - - /* define reaction for calculating k5 */ - rk_moles[k + j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = b51 * rk_moles[j] - + 2.5 * rk_moles[n_reactions + j] - + b53 * rk_moles[2 * n_reactions + j] + b54 * rk_moles[k + j]; - } - if (moles_reduction > 1.0) - goto MOLES_TOO_LARGE; - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k5 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) - { - Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - - /* store k5 in rk_moles */ - k = 4 * n_reactions; - for (j = 0; j < n_reactions; j++) - { - if (moles_reduction * moles_max < - fabs(kinetics_ptr->comps[j].moles)) - { - moles_reduction = - fabs(kinetics_ptr->comps[j].moles) / moles_max; - } - - /* define reaction for calculating k6 */ - rk_moles[k + j] = kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = b61 * rk_moles[j] - + b62 * rk_moles[n_reactions + j] - + b63 * rk_moles[2 * n_reactions + j] - + b64 * rk_moles[3 * n_reactions + j] + b65 * rk_moles[k + j]; - } - if (moles_reduction > 1.0) - goto MOLES_TOO_LARGE; - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * find k6 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - kinetics_ptr->comps[j].moles = 0.; - } - rate_sim_time = rate_sim_time_start + h_sum + 0.875 * h; - calc_kinetic_reaction(kinetics_ptr, h); - - /* Reset to values of last saver() */ - if (pp_assemblage_save != NULL) - { - Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); - } - if (ss_assemblage_save != NULL) - { - Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); - } - - /* store k6 in rk_moles */ - k = 5 * n_reactions; - for (j = 0; j < n_reactions; j++) - { - rk_moles[k + j] = kinetics_ptr->comps[j].moles; - } - -/* - * Evaluate error - */ - error_max = 0.; - for (j = 0; j < n_reactions; j++) - { - l_error = fabs(dc1 * rk_moles[j] - + dc3 * rk_moles[2 * n_reactions + j] - + dc4 * rk_moles[3 * n_reactions + j] - + dc5 * rk_moles[4 * n_reactions + j] - + dc6 * rk_moles[5 * n_reactions + j]); - - /* tol is in moles/l */ - l_error /= kinetics_ptr->comps[j].tol; - if (l_error > error_max) - error_max = l_error; - } - -/* - * repeat with smaller step - */ -/* printf("timest %g ; error_max %g\n", h, error_max); */ - if (error_max > 1) - { - h_old = h; - if (step_ok == 0) - h = h * safety / error_max; - else - h = h * safety * pow(error_max, (LDBLE) -0.25); - l_bad = TRUE; - step_bad++; - } - else - { -/* - * OK, calculate result - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = c1 * rk_moles[j] - + c3 * rk_moles[2 * n_reactions + j] - + c4 * rk_moles[3 * n_reactions + j] - + c6 * rk_moles[5 * n_reactions + j]; - } - calc_final_kinetic_reaction(kinetics_ptr); - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].m = - m_temp[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 1.e-30) - kinetics_ptr->comps[j].m = 0; - kinetics_ptr->comps[j].moles = 0.; - } - - if (set_and_run_wrapper(i, NOMIX, TRUE, i, 0.) == MASS_BALANCE) - { - run_reactions_iterations += iterations; - moles_reduction = 9; - goto MOLES_TOO_LARGE; - } - run_reactions_iterations += iterations; -/* - * Move next calc'n to rk = 1 when initial rate equals final rate ... - */ - calc_kinetic_reaction(kinetics_ptr, h); - for (j = 0; j < n_reactions; j++) - { - if (fabs(rk_moles[j] - kinetics_ptr->comps[j].moles) > - kinetics_ptr->comps[j].tol) - { - equal_rate = FALSE; - break; - } - } - if (equal_rate && kinetics_ptr->rk < 6) - kinetics_ptr->rk = 1; - - saver(); - - step_ok++; - h_sum += h; - /* Free space */ - - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } -/* - * and increase step size ... - */ - if (h_sum < kin_time) - { - if (error_max > 0.000577) - { - h = h * safety * pow(error_max, (LDBLE) -0.2e0); - } - else - { - h *= 4; - } - if (h > (kin_time - h_sum)) - h = (kin_time - h_sum); - } - } #if !defined(PHREEQCI_GUI) #ifndef PHREEQ98 if (pr.status == TRUE && status_on == TRUE @@ -2093,6 +1044,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, screen_msg(sformatf("%-37s", str)); } #endif +#endif #endif } @@ -2109,14 +1061,12 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, /* saver(); */ /* reset for printing */ if (use_mix == DISP) { - //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); use.Set_mix_in(true); use.Set_n_mix_user(i); } else if ((use_mix == STAG || use_mix == TRUE) && state == TRANSPORT) { - //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); if (use.Get_mix_ptr() != NULL) { @@ -2129,7 +1079,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, */ if (nsaver != i) { - solution_duplicate(save_old, i); + Utilities::Rxn_copy(Rxn_solution_map, save_old, i); } rk_moles = (LDBLE *) free_check_null(rk_moles); @@ -2150,7 +1100,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, } return (OK); } -#endif + /* ---------------------------------------------------------------------- */ int Phreeqc:: set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, @@ -2192,7 +1142,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); if (pp_assemblage_save) { delete pp_assemblage_save; @@ -2202,7 +1152,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (use.Get_ss_assemblage_ptr() != NULL) { - cxxSSassemblage * ss_assemblage_ptr = (cxxSSassemblage *) use.Get_ss_assemblage_ptr(); + cxxSSassemblage * ss_assemblage_ptr = use.Get_ss_assemblage_ptr(); if (ss_assemblage_save) { delete ss_assemblage_save; @@ -2213,14 +1163,6 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, if (use.Get_kinetics_ptr() != NULL) { kinetics_save = new cxxKinetics(*use.Get_kinetics_ptr()); -#ifdef SKIP - kinetics_save = - (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); - if (kinetics_save == NULL) - malloc_error(); - kinetics_copy(use.Get_kinetics_ptr(), kinetics_save, - use.Get_kinetics_ptr()->n_user); -#endif } if (pitzer_model == TRUE || sit_model == TRUE) @@ -2424,7 +1366,6 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, * write to error.inp what failed to converge. */ std::ofstream error_input("error.inp"); - //cxxStorageBin error_bin(PHREEQC_THIS_COMMA &use, phrq_io); cxxStorageBin error_bin; Use2cxxStorageBin(error_bin); error_bin.dump_raw(error_input, 0); @@ -2488,7 +1429,7 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, * nsaver --user number to store solution * step_fraction--fraction of irreversible reaction to add */ - int n,n2, converge; + int converge; if (state == TRANSPORT || state == PHAST) { set_transport(i, use_mix, use_kinetics, nsaver); @@ -2514,17 +1455,15 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, /* * Always use solution, exchange, and surface -1 */ - use.Set_solution_ptr(solution_bsearch(-1, &n, TRUE)); - + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, -1)); /* new */ if (use.Get_exchange_ptr() != NULL) { - //use.Get_exchange_ptr() = exchange_bsearch(-1, &n1); use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, -1)); } if (use.Get_surface_ptr() != NULL) { - use.Set_surface_ptr(surface_bsearch(-1, &n2)); + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, -1)); } /* @@ -2532,7 +1471,7 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { /* @@ -2549,16 +1488,17 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, /* end new */ if (use.Get_surface_ptr() != NULL) { - dl_type_x = use.Get_surface_ptr()->dl_type; + dl_type_x = use.Get_surface_ptr()->Get_dl_type(); } - if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL) + if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL) { converge = surface_model(); } else { prep(); - k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + same_pressure = false; + k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); set(FALSE); converge = model(); } @@ -2589,7 +1529,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) use.Set_mix_in(false); if (use_mix == DISP) { - //use.Get_mix_ptr() = &mix[count_mix - count_cells + i - 1]; use.Set_mix_ptr(Utilities::Rxn_find(Dispersion_mix_map, i)); use.Set_mix_in(true); use.Set_n_mix_user(i); @@ -2597,7 +1536,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) } else if (use_mix == STAG && multi_Dflag != TRUE) { - //use.Get_mix_ptr() = mix_search(i, &use.n_mix, FALSE); use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); if (use.Get_mix_ptr() != NULL) { @@ -2607,9 +1545,7 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) } else { - int n_solution; - use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { error_string = sformatf( "Solution %d not found.", @@ -2622,9 +1558,7 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) } else { - int n_solution; - use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { error_string = sformatf( "Solution %d not found.", @@ -2640,8 +1574,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find pure phase assemblage */ - - //use.Get_pp_assemblage_ptr() = pp_assemblage_bsearch(i, &use.n_pp_assemblage); use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, i)); if (use.Get_pp_assemblage_ptr() != NULL) { @@ -2659,7 +1591,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find irreversible reaction */ - //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); if (use.Get_reaction_ptr() != NULL) { @@ -2673,7 +1604,6 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find exchange */ - //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); if (use.Get_exchange_ptr() != NULL) { @@ -2692,9 +1622,7 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) /* * Find surface */ - int n_surface; - use.Set_surface_ptr(surface_bsearch(i, &n_surface)); - //use.Set_n_surface(n_surface); + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); if (use.Get_surface_ptr() != NULL) { use.Set_surface_in(true); @@ -2707,7 +1635,7 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) { use.Set_surface_in(false); save.surface = FALSE; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; } /* * Find temperature; temp retardation is done in step @@ -2815,7 +1743,6 @@ set_reaction(int i, int use_mix, int use_kinetics) use.Set_solution_ptr(NULL); if (use_mix == TRUE && use.Get_mix_in() == TRUE) { - //use.Get_mix_ptr() = mix_bsearch(i, &use.n_mix); use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); if (use.Get_mix_ptr() == NULL) { @@ -2825,9 +1752,7 @@ set_reaction(int i, int use_mix, int use_kinetics) } else { - int n_solution; - use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { error_string = sformatf( "Solution %d not found.", i); @@ -2852,7 +1777,6 @@ set_reaction(int i, int use_mix, int use_kinetics) */ if (use.Get_reaction_in() == TRUE) { - //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); if (use.Get_reaction_ptr() == NULL) { @@ -2865,7 +1789,6 @@ set_reaction(int i, int use_mix, int use_kinetics) */ if (use.Get_exchange_in() == TRUE) { - //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); if (use.Get_exchange_ptr() == NULL) { @@ -2876,12 +1799,10 @@ set_reaction(int i, int use_mix, int use_kinetics) /* * Find surface */ - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; if (use.Get_surface_in() == TRUE) { - int n_surface; - use.Set_surface_ptr(surface_bsearch(i, &n_surface)); - //use.Set_n_surface(n_surface); + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); if (use.Get_surface_ptr() == NULL) { error_string = sformatf( "SURFACE %d not found.", i); @@ -3029,7 +1950,6 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) /* * Save moles of kinetic reactants for printout... */ - //kinetics_ptr = kinetics_bsearch(i, &n); size_t count_comps = kinetics_ptr->Get_kinetics_comps().size(); m_temp = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); if (m_temp == NULL) @@ -3071,7 +1991,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); if (nsaver != i) { - solution_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_solution_map, i, save_old); } for (int j = 0; j < OPT_SIZE; j++) { @@ -3082,7 +2002,6 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) /* * Do mix first */ - //kinetics_ptr = kinetics_bsearch(i, &m); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); cvode_n_user = i; @@ -3293,7 +2212,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) */ if (nsaver != i) { - solution_duplicate(save_old, i); + Utilities::Rxn_copy(Rxn_solution_map, save_old, i); } free_cvode(); use.Set_mix_in(use_save.Get_mix_in()); @@ -3327,370 +2246,6 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) -/* ---------------------------------------------------------------------- */ -{ -/* - * Kinetics calculations - * Rates and moles of each reaction are calculated in calc_kinetic_reaction - * Total number of moles in reaction is stored in kinetics[i].totals - */ - - int j, n, converge, m_iter; - int pr_all_save; - int nsaver; - struct kinetics *kinetics_ptr; - cxxPPassemblage *pp_assemblage_ptr; - cxxSSassemblage *ss_assemblage_ptr; - cxxKinetics *kinetics_ptr; - cxxUse use_save; - int save_old, m, n_reactions /*, nok, nbad */ ; - - /* CVODE definitions */ - realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; - long int iopt[OPT_SIZE]; - int flag; -/* - * Set nsaver - */ - run_reactions_iterations = 0; - kin_time_x = kin_time; - nsaver = i; - if (state == TRANSPORT || state == PHAST) - { - if (use_mix == DISP) - { - nsaver = -2; - } - else if (use_mix == STAG) - { - nsaver = -2 - i; - } - } - if (state == ADVECTION) - { - nsaver = -2; - } -/* - * Check that reaction exists for this cell .. - */ - if (kin_time <= 0 || - (state == REACTION && use.Get_kinetics_in() == FALSE) || - (state == TRANSPORT && kinetics_bsearch(i, &n) == NULL) || - (state == PHAST && kinetics_bsearch(i, &n) == NULL) || - (state == ADVECTION && kinetics_bsearch(i, &n) == NULL)) - { - converge = - set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); - if (converge == MASS_BALANCE) - error_msg - ("Negative concentration in system. Stopping calculation.", - STOP); - run_reactions_iterations += iterations; - } - else - { -/* - * Save moles of kinetic reactants for printout... - */ - kinetics_ptr = kinetics_bsearch(i, &n); - - m_temp = - (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * - sizeof(LDBLE)); - if (m_temp == NULL) - malloc_error(); - - m_original = - (LDBLE *) PHRQ_malloc((size_t) kinetics_ptr->count_comps * - sizeof(LDBLE)); - if (m_original == NULL) - malloc_error(); - - for (j = 0; j < kinetics_ptr->count_comps; j++) - { - m_original[j] = kinetics_ptr->comps[j].m; - m_temp[j] = kinetics_ptr->comps[j].m; - } -/* -* Start the loop for timestepping ... - * Use either Runge-Kutta-Fehlberg, or final result extrapolation - */ - pr_all_save = pr.all; - pr.all = FALSE; -/* - * This condition makes output equal for incremental_reactions TRUE/FALSE... - * (if (incremental_reactions == FALSE || reaction_step == 1) - */ - store_get_equi_reactants(i, FALSE); - if (kinetics_ptr->use_cvode == FALSE) - { -/* in case dispersivity is not wanted.. - if (multi_Dflag) - rk_kinetics(i, kin_time, NOMIX, nsaver, step_fraction); - else - */ rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); - } - else - { - save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); - if (nsaver != i) - { - solution_duplicate(i, save_old); - } - for (j = 0; j < OPT_SIZE; j++) - { - iopt[j] = 0; - ropt[j] = 0; - } - -/* - * Do mix first - */ - kinetics_ptr = kinetics_bsearch(i, &m); - n_reactions = kinetics_ptr->count_comps; - cvode_n_user = i; - cvode_kinetics_ptr = (void *) kinetics_ptr; - cvode_n_reactions = n_reactions; - cvode_rate_sim_time_start = rate_sim_time_start; - cvode_rate_sim_time = rate_sim_time; - - if (multi_Dflag) - converge = set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - else - converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); - if (converge == MASS_BALANCE) - error_msg - ("Negative concentration in system. Stopping calculation.", - STOP); - saver(); - //pp_assemblage_ptr = pp_assemblage_bsearch(i, &n); - pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); - //ss_assemblage_ptr = ss_assemblage_bsearch(i, &n); - ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); - if (pp_assemblage_ptr != NULL) - { - cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); - } - if (ss_assemblage_ptr != NULL) - { - cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); - } - - /* allocate space for CVODE */ - kinetics_machEnv = M_EnvInit_Serial(n_reactions); - kinetics_machEnv->phreeqc_ptr = this; - kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (kinetics_y == NULL) - malloc_error(); - cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_last_good_y == NULL) - malloc_error(); - cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ - if (cvode_prev_good_y == NULL) - malloc_error(); - kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); - if (kinetics_abstol == NULL) - malloc_error(); - -/* - * Set y to 0.0 - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = 0.0; - Ith(kinetics_y, j + 1) = 0.0; - Ith(kinetics_abstol, j + 1) = kinetics_ptr->comps[j].tol; - /*Ith(abstol,j+1) = 1e-8; */ - /* m_temp[j] = kinetics_ptr->comps[j].m; */ - } - reltol = 0.0; - - /* Call CVodeMalloc to initialize CVODE: - - NEQ is the problem size = number of equations - f is the user's right hand side function in y'=f(t,y) - T0 is the initial time - y is the initial dependent variable vector - BDF specifies the Backward Differentiation Formula - NEWTON specifies a Newton iteration - SV specifies scalar relative and vector absolute tolerances - &reltol is a pointer to the scalar relative tolerance - abstol is the absolute tolerance vector - FALSE indicates there are no optional inputs in iopt and ropt - iopt is an array used to communicate optional integer input and output - ropt is an array used to communicate optional real input and output - - A pointer to CVODE problem memory is returned and stored in cvode_mem. */ - /* Don't know what this does */ - /* - iopt[SLDET] = TRUE; - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); - cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); - iopt[MXSTEP] is maximum number of steps that CVODE tries. - */ - iopt[MXSTEP] = kinetics_ptr->cvode_steps; - iopt[MAXORD] = kinetics_ptr->cvode_order; - kinetics_cvode_mem = - CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, - &reltol, kinetics_abstol, this, NULL, TRUE, iopt, - ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) - malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - flag = CVDense(kinetics_cvode_mem, Jac, this); - if (flag != SUCCESS) - { - error_msg("CVDense failed.", STOP); - } - t = 0; - tout = kin_time; - /*ropt[HMAX] = tout/10.; */ - /*ropt[HMIN] = 1e-17; */ - use_save = use; - flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); - rate_sim_time = rate_sim_time_start + t; - /* - printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", - t, Ith(y,1), Ith(y,2), Ith(y,3)); - */ - m_iter = 0; - sum_t = 0; - RESTART: - while (flag != SUCCESS) - { - sum_t += cvode_last_good_time; - error_string = sformatf( - "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", - (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); - warning_msg(error_string); -#ifdef DEBUG_KINETICS - if (m_iter > 5) - dump_kinetics_stderr(cell_no); -#endif - - cvode_last_good_time = 0; - if (++m_iter >= kinetics_ptr->bad_step_max) - { - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - error_msg("Repeated restart of integration.", STOP); - } - tout1 = tout - sum_t; - t = 0; - N_VScale(1.0, cvode_last_good_y, kinetics_y); - for (j = 0; j < OPT_SIZE; j++) - { - iopt[j] = 0; - ropt[j] = 0; - } - CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ - iopt[MXSTEP] = kinetics_ptr->cvode_steps; - iopt[MAXORD] = kinetics_ptr->cvode_order; - kinetics_cvode_mem = - CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, - SV, &reltol, kinetics_abstol, this, NULL, - TRUE, iopt, ropt, kinetics_machEnv); - if (kinetics_cvode_mem == NULL) - malloc_error(); - - /* Call CVDense to specify the CVODE dense linear solver with the - user-supplied Jacobian routine Jac. */ - flag = CVDense(kinetics_cvode_mem, Jac, this); - if (flag != SUCCESS) - { - error_msg("CVDense failed.", STOP); - } - flag = - CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); - /* - error_string = sformatf( "CVode failed, flag=%d.\n", flag); - error_msg(error_string, STOP); - */ - } - /* - odeint(&ystart[-1], n_reactions, 0, kin_time, kinetics_ptr->comps[0].tol, kin_time/kinetics_ptr->step_divide, 0.0, &nok, &nbad, i, nsaver ); - */ - for (j = 0; j < n_reactions; j++) - { - kinetics_ptr->comps[j].moles = Ith(kinetics_y, j + 1); - kinetics_ptr->comps[j].m = - m_original[j] - kinetics_ptr->comps[j].moles; - if (kinetics_ptr->comps[j].m < 0) - { - kinetics_ptr->comps[j].moles = m_original[j]; - kinetics_ptr->comps[j].m = 0.0; - } - } - if (use.Get_pp_assemblage_ptr() != NULL) - { - Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; - use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); - } - if (use.Get_ss_assemblage_ptr() != NULL) - { - Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; - use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); - } - calc_final_kinetic_reaction(kinetics_ptr); - if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == - MASS_BALANCE) - { - /*error_msg("FAIL 2 after successful integration in CVode", CONTINUE); */ - warning_msg("FAIL 2 after successful integration in CVode"); - flag = -1; - goto RESTART; - } - for (j = 0; j < kinetics_ptr->count_comps; j++) - { - kinetics_ptr->comps[j].m = - m_original[j] - kinetics_ptr->comps[j].moles; - } -/* - * Restore solution i, if necessary - */ - if (nsaver != i) - { - solution_duplicate(save_old, i); - } - free_cvode(); - use.Set_mix_in(use_save.Get_mix_in()); - use.Set_mix_ptr(use_save.Get_mix_ptr()); - } - - rate_sim_time = rate_sim_time_start + kin_time; - store_get_equi_reactants(i, TRUE); - pr.all = pr_all_save; - - kinetics_ptr = kinetics_bsearch(i, &n); - for (j = 0; j < kinetics_ptr->count_comps; j++) - { - kinetics_ptr->comps[j].moles = - m_original[j] - kinetics_ptr->comps[j].m; -/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0; - */ } - m_temp = (LDBLE *) free_check_null(m_temp); - m_original = (LDBLE *) free_check_null(m_original); - } - iterations = run_reactions_iterations; - if (cvode_pp_assemblage_save != NULL) - { - delete cvode_pp_assemblage_save; - cvode_pp_assemblage_save = NULL; - } - if (cvode_ss_assemblage_save != NULL) - { - delete cvode_ss_assemblage_save; - cvode_ss_assemblage_save = NULL; - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: free_cvode(void) @@ -3760,9 +2315,7 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) } else { - int n_solution; - use.Set_solution_ptr(solution_bsearch(i, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { error_string = sformatf( "Solution %d not found.", @@ -3778,8 +2331,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find pure phase assemblage */ - - //use.Get_pp_assemblage_ptr() = pp_assemblage_bsearch(i, &use.n_pp_assemblage); use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, i)); if (use.Get_pp_assemblage_ptr() != NULL) { @@ -3797,7 +2348,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find irreversible reaction */ - //use.irrev_ptr = irrev_bsearch(i, &use.n_irrev); use.Set_reaction_ptr(Utilities::Rxn_find(Rxn_reaction_map, i)); if (use.Get_reaction_ptr() != NULL) { @@ -3811,7 +2361,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find exchange */ - //use.Get_exchange_ptr() = exchange_bsearch(i, &use.n_exchange); use.Set_exchange_ptr(Utilities::Rxn_find(Rxn_exchange_map, i)); if (use.Get_exchange_ptr() != NULL) { @@ -3830,9 +2379,7 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find surface */ - int n_surface; - use.Set_surface_ptr(surface_bsearch(i, &n_surface)); - //use.Set_n_surface(n_surface); + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); if (use.Get_surface_ptr() != NULL) { use.Set_surface_in(true); @@ -3845,7 +2392,7 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) { use.Set_surface_in(false); save.surface = FALSE; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; } /* * Find temperature; temp retardation is done in step @@ -3876,7 +2423,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find gas */ - //use.Get_gas_phase_ptr() = gas_phase_bsearch(i, &use.n_gas_phase); use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, i)); if (use.Get_gas_phase_ptr() != NULL) { @@ -3894,9 +2440,6 @@ set_advection(int i, int use_mix, int use_kinetics, int nsaver) /* * Find ss_assemblage */ - //int n_ss_assemblage; - //use.Set_ss_assemblage_ptr(ss_assemblage_bsearch(i, &n_ss_assemblage)); - //use.Set_n_ss_assemblage(n_ss_assemblage); use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, i)); if (use.Get_ss_assemblage_ptr() != NULL) { @@ -3951,7 +2494,7 @@ store_get_equi_reactants(int l, int kin_end) } else use.Set_pp_assemblage_ptr(NULL); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); if (use.Get_gas_phase_in() == TRUE) { use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, l)); @@ -3969,11 +2512,10 @@ store_get_equi_reactants(int l, int kin_end) { count_pp = count_ss = count_pg = 0; if (use.Get_pp_assemblage_ptr() != NULL) - //count_pp = use.Get_pp_assemblage_ptr()->count_comps; count_pp = (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); count_pg = (int) gas_phase_ptr->Get_gas_comps().size(); } if (use.Get_ss_assemblage_ptr() != NULL) @@ -4008,7 +2550,7 @@ store_get_equi_reactants(int l, int kin_end) } { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr) { for (size_t l = 0; l < gas_phase_ptr->Get_gas_comps().size(); l++) @@ -4048,7 +2590,7 @@ store_get_equi_reactants(int l, int kin_end) } { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr && count_pg) { std::vector temp_comps(gas_phase_ptr->Get_gas_comps()); @@ -4167,90 +2709,7 @@ f(integertype N, realtype t, N_Vector y, N_Vector ydot, } return; } -#ifdef SKIP -void Phreeqc:: -f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data) -{ - int i, n_reactions, n_user; - LDBLE step_fraction; - struct kinetics *kinetics_ptr; - Phreeqc *pThis = (Phreeqc *) f_data; - pThis->cvode_error = FALSE; - n_reactions = pThis->cvode_n_reactions; - n_user = pThis->cvode_n_user; - kinetics_ptr = (struct kinetics *) pThis->cvode_kinetics_ptr; - step_fraction = pThis->cvode_step_fraction; - pThis->rate_sim_time = pThis->cvode_rate_sim_time; - - for (i = 0; i < n_reactions; i++) - { - /* - kinetics_ptr->comps[i].moles = y[i + 1]; - kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; - */ - kinetics_ptr->comps[i].moles = Ith(y, i + 1); - kinetics_ptr->comps[i].m = pThis->m_original[i] - Ith(y, i + 1); - if (kinetics_ptr->comps[i].m < 0) - { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = pThis->m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - pThis->calc_final_kinetic_reaction(kinetics_ptr); - /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ - if (pThis->use.Get_pp_assemblage_ptr() != NULL) - { - pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; - pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); - } - if (pThis->use.Get_ss_assemblage_ptr() != NULL) - { - pThis->Rxn_ss_assemblage_map[pThis->cvode_ss_assemblage_save->Get_n_user()] = *pThis->cvode_ss_assemblage_save; - pThis->use.Set_ss_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_ss_assemblage_map, pThis->cvode_ss_assemblage_save->Get_n_user())); - } - - if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) - { - pThis->run_reactions_iterations += pThis->iterations; - pThis->cvode_error = TRUE; - /* - error_msg("Mass balance error in f", CONTINUE); - */ - return; - } - if (pThis->cvode_test == TRUE) - { - return; - } - pThis->run_reactions_iterations += pThis->iterations; - for (i = 0; i < n_reactions; i++) - { - kinetics_ptr->comps[i].moles = 0.0; - } - pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); - for (i = 0; i < n_reactions; i++) - { - /* - dydx[i + 1] = kinetics_ptr->comps[i].moles; - */ - Ith(ydot, i + 1) = kinetics_ptr->comps[i].moles; - } - return; -} -#endif /* static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, N_Vector y, N_Vector fy, N_Vector ewt, realtype h, @@ -4377,7 +2836,6 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, } /* Add small amount of ith reaction */ - //kinetics_ptr->comps[i].m -= del; kinetics_comp_i_ptr->Set_m(kinetics_comp_i_ptr->Get_m() - del); if (kinetics_comp_i_ptr->Get_m() < 0) { @@ -4431,169 +2889,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data, initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); return; } -#ifdef SKIP -void Phreeqc:: -Jac(integertype N, DenseMat J, RhsFn f, void *f_data, - realtype t, N_Vector y, N_Vector fy, N_Vector ewt, - realtype h, realtype uround, void *jac_data, - long int *nfePtr, N_Vector vtemp1, N_Vector vtemp2, - N_Vector vtemp3) -{ - int count_cvode_errors; - int i, j, n_reactions, n_user; - LDBLE *initial_rates, del; - struct kinetics *kinetics_ptr; - LDBLE step_fraction; - Phreeqc *pThis = (Phreeqc *) f_data; - - pThis->cvode_error = FALSE; - n_reactions = pThis->cvode_n_reactions; - n_user = pThis->cvode_n_user; - kinetics_ptr = (struct kinetics *) pThis->cvode_kinetics_ptr; - step_fraction = pThis->cvode_step_fraction; - pThis->rate_sim_time = pThis->cvode_rate_sim_time; - - initial_rates = - (LDBLE *) pThis->PHRQ_malloc ((size_t) n_reactions * sizeof(LDBLE)); - if (initial_rates == NULL) - pThis->malloc_error(); - - for (i = 0; i < n_reactions; i++) - { - /* - kinetics_ptr->comps[i].moles = y[i + 1]; - kinetics_ptr->comps[i].m = m_original[i] - y[i + 1]; - */ - kinetics_ptr->comps[i].moles = Ith(y, i + 1); - kinetics_ptr->comps[i].m = pThis->m_original[i] - Ith(y, i + 1); - if (kinetics_ptr->comps[i].m < 0) - { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = pThis->m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - pThis->calc_final_kinetic_reaction(kinetics_ptr); - /* if (set_and_run(n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) { */ - if (pThis->use.Get_pp_assemblage_ptr() != NULL) - { - pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; - pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); - } - if (pThis->set_and_run_wrapper(n_user, FALSE, TRUE, n_user, 0.0) == MASS_BALANCE) - { - pThis->run_reactions_iterations += pThis->iterations; - pThis->cvode_error = TRUE; - /* - error_msg("Mass balance error in jacobian", CONTINUE); - */ - initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); - return; - } - pThis->run_reactions_iterations += pThis->iterations; - for (i = 0; i < n_reactions; i++) - kinetics_ptr->comps[i].moles = 0.0; - pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); - for (i = 0; i < n_reactions; i++) - { - initial_rates[i] = kinetics_ptr->comps[i].moles; - } - for (i = 0; i < n_reactions; i++) - { - /* calculate reaction up to current time */ - del = 1e-12; - pThis->cvode_error = TRUE; - count_cvode_errors = 0; - while (pThis->cvode_error == TRUE) - { - del /= 10.; - for (j = 0; j < n_reactions; j++) - { - /* - kinetics_ptr->comps[j].moles = y[j + 1]; - kinetics_ptr->comps[j].m = m_original[j] - y[j + 1]; - */ - kinetics_ptr->comps[j].moles = Ith(y, j + 1); - kinetics_ptr->comps[j].m = pThis->m_original[j] - Ith(y, j + 1); - if (kinetics_ptr->comps[i].m < 0) - { - /* - NOTE: y is not correct if it is greater than m_original - However, it seems to work to let y wander off, but use - .moles as the correct integral. - It does not work to reset Y to m_original, presumably - because the rational extrapolation gets screwed up. - */ - - /* - Ith(y,i + 1) = m_original[i]; - */ - kinetics_ptr->comps[i].moles = pThis->m_original[i]; - kinetics_ptr->comps[i].m = 0.0; - } - } - - /* Add small amount of ith reaction */ - kinetics_ptr->comps[i].m -= del; - if (kinetics_ptr->comps[i].m < 0) - { - kinetics_ptr->comps[i].m = 0; - } - kinetics_ptr->comps[i].moles += del; - pThis->calc_final_kinetic_reaction(kinetics_ptr); - if (pThis->use.Get_pp_assemblage_ptr() != NULL) - { - pThis->Rxn_pp_assemblage_map[pThis->cvode_pp_assemblage_save->Get_n_user()] = *pThis->cvode_pp_assemblage_save; - pThis->use.Set_pp_assemblage_ptr(Utilities::Rxn_find(pThis->Rxn_pp_assemblage_map, pThis->cvode_pp_assemblage_save->Get_n_user())); - } - if (pThis->set_and_run_wrapper - (n_user, FALSE, TRUE, n_user, step_fraction) == MASS_BALANCE) - { - count_cvode_errors++; - pThis->cvode_error = TRUE; - if (count_cvode_errors > 30) - { - initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); - return; - } - pThis->run_reactions_iterations += pThis->iterations; - continue; - } - pThis->cvode_error = FALSE; - pThis->run_reactions_iterations += pThis->iterations; - /*kinetics_ptr->comps[i].moles -= del; */ - for (j = 0; j < n_reactions; j++) - kinetics_ptr->comps[j].moles = 0.0; - pThis->calc_kinetic_reaction(kinetics_ptr, 1.0); - - /* calculate new rates for df/dy[i] */ - /* dfdx[i + 1] = 0.0; */ - for (j = 0; j < n_reactions; j++) - { - IJth(J, j + 1, i + 1) = - (kinetics_ptr->comps[j].moles - initial_rates[j]) / del; - } - } - } - for (i = 0; i < n_reactions; i++) - { - kinetics_ptr->comps[i].moles = 0; - } - initial_rates = (LDBLE *) pThis->free_check_null(initial_rates); - return; -} -#endif void Phreeqc:: cvode_init(void) { diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index c3da9ceb..768ea13f 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -6,12 +6,12 @@ #include "PBasic.h" #include "Temperature.h" #include "Exchange.h" -//#include "ExchComp.h" #include "GasPhase.h" #include "Reaction.h" #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" #if defined(WINDOWS) || defined(_WINDOWS) #include @@ -67,14 +67,6 @@ initialize(void) LOG_10 = log(10.0); /* Use space for all memory allocation */ - max_solution = MAX_SOLUTION; - //max_pp_assemblage = MAX_PP_ASSEMBLAGE; - //max_exchange = MAX_PP_ASSEMBLAGE; - max_surface = MAX_PP_ASSEMBLAGE; - //max_gas_phase = MAX_PP_ASSEMBLAGE; - //max_kinetics = MAX_PP_ASSEMBLAGE; - //max_ss_assemblage = MAX_PP_ASSEMBLAGE; - max_elements = MAX_ELEMENTS; max_elts = MAX_ELTS; max_line = MAX_LINE; @@ -86,19 +78,8 @@ initialize(void) max_trxn = MAX_TRXN; max_logk = MAX_S; max_master_isotope = MAX_ELTS; - - count_solution = 0; - //count_pp_assemblage = 0; - //count_exchange = 0; - count_surface = 0; - //count_gas_phase = 0; - //count_kinetics = 0; - //count_ss_assemblage = 0; - count_elements = 0; - //count_irrev = 0; count_master = 0; - //count_mix = 0; count_phases = 0; count_s = 0; count_logk = 0; @@ -147,23 +128,6 @@ initialize(void) /* * Allocate space */ - //space((void **) ((void *) &pp_assemblage), INIT, &max_pp_assemblage, - // sizeof(struct pp_assemblage)); - - //space((void **) ((void *) &exchange), INIT, &max_exchange, - // sizeof(struct exchange)); - - space((void **) ((void *) &surface), INIT, &max_surface, - sizeof(struct surface)); - - //space((void **) ((void *) &gas_phase), INIT, &max_gas_phase, - // sizeof(struct gas_phase)); - - //space((void **) ((void *) &kinetics), INIT, &max_kinetics, - // sizeof(struct kinetics)); - - //space((void **) ((void *) &ss_assemblage), INIT, &max_ss_assemblage, - // sizeof(struct ss_assemblage)); space((void **) ((void *) &cell_data), INIT, &count_cells, sizeof(struct cell_data)); @@ -174,7 +138,6 @@ initialize(void) space((void **) ((void *) &elt_list), INIT, &max_elts, sizeof(struct elt_list)); - inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); if (inverse == NULL) malloc_error(); @@ -189,10 +152,6 @@ initialize(void) space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, sizeof(struct unknown_list)); - //mix = (struct mix *) PHRQ_malloc((size_t) sizeof(struct mix)); - //if (mix == NULL) - // malloc_error(); - //count_mix = 0; /* !!!! */ stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data)); if (stag_data == NULL) @@ -214,15 +173,7 @@ initialize(void) space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, sizeof(struct master_isotope *)); - - solution = - (struct solution **) PHRQ_malloc((size_t) MAX_SOLUTION * - sizeof(struct solution *)); - if (solution == NULL) - malloc_error(); - title_x = NULL; - pe_x = NULL; description_x = NULL; units_x = NULL; s_x = NULL; @@ -234,11 +185,6 @@ initialize(void) sum_jacob2 = NULL; sum_delta = NULL; /* SRC ADDED */ - count_isotopes_x = 0; - isotopes_x = - (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); - if (isotopes_x == NULL) - malloc_error(); x = NULL; max_unknowns = 0; @@ -261,10 +207,6 @@ initialize(void) hcreate_multi((unsigned) max_elements, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); hcreate_multi((unsigned) max_phases, &phases_hash_table); -/* - * Initialize use pointers - */ - //use_init(); /* * Initialize punch */ @@ -365,8 +307,8 @@ initialize(void) last_model.pp_assemblage = NULL; last_model.add_formula = NULL; last_model.si = NULL; - last_model.dl_type = NO_DL; - last_model.surface_type = UNKNOWN_DL; + last_model.dl_type = cxxSurface::NO_DL; + last_model.surface_type = cxxSurface::UNKNOWN_DL; last_model.only_counter_ions = FALSE; last_model.thickness = 1e-8; last_model.count_surface_comp = -1; @@ -383,7 +325,6 @@ initialize(void) initial_total_time = 0; rate_m = 0; rate_m0 = 0; - //rate_p = NULL; rate_time = 0; rate_sim_time_start = 0; rate_sim_time_end = 0; @@ -590,14 +531,6 @@ initialize(void) /* * to facilitate debuging */ - //dbg_use = &use; - dbg_solution = solution; - //dbg_exchange = exchange; - dbg_surface = surface; - //dbg_pp_assemblage = pp_assemblage; - //dbg_kinetics = kinetics; - //dbg_irrev = irrev; - //dbg_mix = mix; dbg_master = master; calculating_deriv = FALSE; numerical_deriv = FALSE; @@ -613,10 +546,8 @@ initialize(void) cell_porosity = 0; cell_saturation = 0; - charge_group = NULL; print_density = 0; - same_model = FALSE; same_temperature = FALSE; same_pressure = FALSE; @@ -643,7 +574,6 @@ initialize(void) ph_x = 0; solution_pe_x = 0; mu_x = 0; - ah2o_x = 0; density_x = 0; total_h_x = 0; total_o_x = 0; @@ -652,8 +582,7 @@ initialize(void) mass_water_aq_x = 0; mass_water_surfaces_x = 0; mass_water_bulk_x = 0; - default_pe_x = 0; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; total_carbon = 0; total_co2 = 0; total_alkalinity = 0; @@ -718,11 +647,10 @@ initialize(void) } count_trxn = 0; count_mb_unknowns = 0; - status_on = TRUE; - status_timer = (float) clock(); + status_on = true; + status_timer = clock(); status_interval = 0; count_rate_p = 0; - //strcpy(error_string,""); reaction_step = 0; transport_step = 0; transport_start = 0; @@ -760,15 +688,19 @@ initialize(void) count_sys = 0; max_sys = 0; sys_tot = 0; +#ifdef PHREEQC2 AA_basic = 0; BB_basic = 0; CC = 0; I_m = 0; + eps_r = EPSILON; +#endif rho_0 = 0; solution_mass = 0; solution_volume = 0; patm_x = 1; /* Initialize pressure of component x to 1 atm */ + ah2o_x = 1.0; /* model_min_value = 0; */ @@ -826,12 +758,9 @@ set_use(void) /* * Find solution */ - if (use.Get_solution_in() == TRUE) + if (use.Get_solution_in()) { - int n_solution; - use.Set_solution_ptr( - solution_bsearch(use.Get_n_solution_user(), &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, use.Get_n_solution_user())); if (use.Get_solution_ptr() == NULL) { error_string = sformatf( "Solution %d not found.", @@ -845,7 +774,6 @@ set_use(void) if (use.Get_mix_in() == TRUE) { use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user())); - //use.Get_mix_ptr() =(void *) Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); use.Set_n_mix_user_orig(use.Get_n_mix_user()); if (use.Get_mix_ptr() == NULL) { @@ -864,9 +792,6 @@ set_use(void) if (use.Get_pp_assemblage_in() == TRUE) { use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user())); - //use.Get_pp_assemblage_ptr() = - // pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), - // &use.n_pp_assemblage); if (use.Get_pp_assemblage_ptr() == NULL) { error_string = sformatf( "Pure phase assemblage %d not found.", @@ -932,12 +857,10 @@ set_use(void) /* * Find surface */ - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; if (use.Get_surface_in() == TRUE) { - int n_surface; - use.Set_surface_ptr(surface_bsearch(use.Get_n_surface_user(), &n_surface)); - //use.Set_n_surface(n_surface); + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user())); if (use.Get_surface_ptr() == NULL) { error_string = sformatf( "Surface %d not found.", @@ -987,7 +910,6 @@ set_use(void) */ if (use.Get_gas_phase_in() == TRUE) { - //use.Get_gas_phase_ptr() = gas_phase_bsearch(use.Get_n_gas_phase_user(), &use.n_gas_phase); use.Set_gas_phase_ptr(Utilities::Rxn_find(Rxn_gas_phase_map, use.Get_n_gas_phase_user())); if (use.Get_gas_phase_ptr() == NULL) { @@ -1005,10 +927,6 @@ set_use(void) */ if (use.Get_ss_assemblage_in() == TRUE) { - //int n_ss_assemblage_user; - //use.Set_ss_assemblage_ptr( - // ss_assemblage_bsearch(use.Get_n_ss_assemblage_user(), - // &n_ss_assemblage_user)); use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user())); if (use.Get_ss_assemblage_ptr() == NULL) { @@ -1029,7 +947,6 @@ set_use(void) */ return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: initial_solutions(int print) @@ -1039,18 +956,20 @@ initial_solutions(int print) * Go through list of solutions, make initial solution calculations * for any marked "new". */ - int i, converge, converge1; - int n, last, n_user, print1; + int converge, converge1; + int last, n_user, print1; char token[2 * MAX_LENGTH]; state = INITIAL_SOLUTION; set_use(); print1 = TRUE; - dl_type_x = NO_DL; - for (n = 0; n < count_solution; n++) + dl_type_x = cxxSurface::NO_DL; + std::map::iterator it = Rxn_solution_map.begin(); + for ( ; it != Rxn_solution_map.end(); it++) { + cxxSolution &solution_ref = it->second; initial_solution_isotopes = FALSE; - if (solution[n] != NULL && solution[n]->new_def == TRUE) + if (solution_ref.Get_new_def()) { if (print1 == TRUE && print == TRUE) { @@ -1061,12 +980,12 @@ initial_solutions(int print) if (print == TRUE) { sprintf(token, "Initial solution %d.\t%.350s", - solution[n]->n_user, solution[n]->description); + solution_ref.Get_n_user(), solution_ref.Get_description().c_str()); dup_print(token, FALSE); } - use.Set_solution_ptr(solution[n]); + use.Set_solution_ptr(&solution_ref); prep(); - k_temp(solution[n]->tc, solution[n]->patm); + k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); set(TRUE); always_full_pitzer = FALSE; converge = model(); @@ -1080,7 +999,7 @@ initial_solutions(int print) } converge1 = check_residuals(); sum_species(); - add_isotopes(solution[n]); + add_isotopes(solution_ref); punch_all(); print_all(); /* free_model_allocs(); */ @@ -1089,30 +1008,19 @@ initial_solutions(int print) error_msg("Model failed to converge for initial solution.", STOP); } - n_user = solution[n]->n_user; - last = solution[n]->n_user_end; + n_user = solution_ref.Get_n_user(); + last = solution_ref.Get_n_user_end(); /* copy isotope data */ - if (solution[n]->count_isotopes > 0) + if (solution_ref.Get_isotopes().size() > 0) { - count_isotopes_x = solution[n]->count_isotopes; - isotopes_x = - (struct isotope *) PHRQ_realloc(isotopes_x, - (size_t) count_isotopes_x - * sizeof(struct isotope)); - if (isotopes_x == NULL) - malloc_error(); - memcpy(isotopes_x, solution[n]->isotopes, - (size_t) count_isotopes_x * sizeof(struct isotope)); + isotopes_x = solution_ref.Get_isotopes(); } else { - count_isotopes_x = 0; + isotopes_x.clear(); } xsolution_save(n_user); - for (i = n_user + 1; i <= last; i++) - { - solution_duplicate(n_user, i); - } + Utilities::Rxn_copies(Rxn_solution_map, n_user, last); } } initial_solution_isotopes = FALSE; @@ -1135,7 +1043,7 @@ initial_exchangers(int print) state = INITIAL_EXCHANGE; set_use(); print1 = TRUE; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; std::map::iterator it = Rxn_exchange_map.begin(); for ( ; it != Rxn_exchange_map.end(); it++) { @@ -1161,7 +1069,7 @@ initial_exchangers(int print) dup_print(token, FALSE); } use.Set_exchange_ptr(exchange_ptr); - use.Set_solution_ptr(solution_bsearch(exchange_ptr->Get_n_solution(), &i, TRUE)); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, exchange_ptr->Get_n_solution())); if (use.Get_solution_ptr() == NULL) { error_msg @@ -1170,7 +1078,7 @@ initial_exchangers(int print) } prep(); - k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); set(TRUE); converge = model(); converge1 = check_residuals(); @@ -1189,7 +1097,6 @@ initial_exchangers(int print) } for (i = n_user + 1; i <= last; i++) { - //exchange_duplicate(n_user, i); Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); } } @@ -1205,7 +1112,7 @@ initial_gas_phases(int print) * for any marked "new" that are defined to be in equilibrium with a * solution. */ - int i, converge, converge1; + int converge, converge1; int last, n_user, print1; char token[2 * MAX_LENGTH]; struct phase *phase_ptr; @@ -1216,10 +1123,9 @@ initial_gas_phases(int print) state = INITIAL_GAS_PHASE; set_use(); print1 = TRUE; - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; std::map::iterator it = Rxn_gas_phase_map.begin(); for ( ; it != Rxn_gas_phase_map.end(); it++) - //for (n = 0; n < count_gas_phase; n++) { cxxGasPhase *gas_phase_ptr = &it->second; if (!gas_phase_ptr->Get_new_def()) @@ -1244,10 +1150,9 @@ initial_gas_phases(int print) } /* Try to obtain a solution pointer */ - use.Set_solution_ptr( - solution_bsearch(gas_phase_ptr->Get_n_solution(), &i, TRUE)); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, gas_phase_ptr->Get_n_solution())); prep(); - k_temp(use.Get_solution_ptr()->tc, use.Get_solution_ptr()->patm); + k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); set(TRUE); converge = model(); converge1 = check_residuals(); @@ -1262,11 +1167,8 @@ initial_gas_phases(int print) gas_phase_ptr->Set_total_p(0); gas_phase_ptr->Set_total_moles(0); for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) { cxxGasComp * gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); - //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); - //phase_ptr = gas_comp_ptr->phase; int k; phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); if (phase_ptr->in == TRUE) @@ -1291,14 +1193,14 @@ initial_gas_phases(int print) phase_ptr->moles_x = 0; } } - if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->patm) > 5) + if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->Get_patm()) > 5) { sprintf(token, "WARNING: While initializing gas phase composition by equilibrating:\n%s (%.2f atm) %s (%.2f atm).\n%s.", " Gas phase pressure", (double) gas_phase_ptr->Get_total_p(), "is not equal to solution-pressure", - (double) use.Get_solution_ptr()->patm, + (double) use.Get_solution_ptr()->Get_patm(), " Pressure effects on solubility may be incorrect"); dup_print(token, FALSE); } @@ -1326,21 +1228,22 @@ initial_surfaces(int print) * for any marked "new" that are defined to be in equilibrium with a * solution. */ - int i; - int n, last, n_user, print1; - char token[2 * MAX_LENGTH]; + int last, n_user, print1; state = INITIAL_SURFACE; set_use(); print1 = TRUE; - for (n = 0; n < count_surface; n++) + + std::map::iterator it = Rxn_surface_map.begin(); + for ( ; it != Rxn_surface_map.end(); it++) { - if (surface[n].new_def != TRUE) + cxxSurface * surface_ptr = &it->second; + if (!surface_ptr->Get_new_def()) continue; - n_user = surface[n].n_user; - last = surface[n].n_user_end; - surface[n].n_user_end = n_user; - if (surface[n].solution_equilibria == TRUE) + n_user = surface_ptr->Get_n_user(); + last = surface_ptr->Get_n_user_end(); + surface_ptr->Set_n_user_end(n_user); + if (surface_ptr->Get_solution_equilibria()) { if (print1 == TRUE && print == TRUE) { @@ -1351,14 +1254,13 @@ initial_surfaces(int print) } if (print == TRUE) { - sprintf(token, "Surface %d.\t%.350s", - surface[n].n_user, surface[n].description); - dup_print(token, FALSE); + std::ostringstream msg; + msg << "Surface " << n_user << ".\t" << surface_ptr->Get_description().c_str(); + dup_print(msg.str().c_str(), FALSE); } - use.Set_surface_ptr(&(surface[n])); - dl_type_x = use.Get_surface_ptr()->dl_type; - use.Set_solution_ptr( - solution_bsearch(surface[n].n_solution, &i, TRUE)); + use.Set_surface_ptr(surface_ptr); + dl_type_x = use.Get_surface_ptr()->Get_dl_type(); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, surface_ptr->Get_n_solution())); if (use.Get_solution_ptr() == NULL) { error_msg @@ -1373,14 +1275,10 @@ initial_surfaces(int print) xsurface_save(n_user); /* free_model_allocs(); */ } - for (i = n_user + 1; i <= last; i++) - { - surface_duplicate(n_user, i); - } + Utilities::Rxn_copies(Rxn_surface_map, n_user, last); } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: reactions(void) @@ -1415,20 +1313,18 @@ reactions(void) count_steps = 1; if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { - cxxReaction *reaction_ptr = (cxxReaction *) use.Get_reaction_ptr(); + cxxReaction *reaction_ptr = use.Get_reaction_ptr(); if (reaction_ptr->Get_reaction_steps() > count_steps) count_steps = reaction_ptr->Get_reaction_steps(); } if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) { - //if (abs(use.Get_kinetics_ptr()->count_steps) > count_steps) - // count_steps = abs(use.Get_kinetics_ptr()->count_steps); if (use.Get_kinetics_ptr()->Get_reaction_steps() > count_steps) count_steps = use.Get_kinetics_ptr()->Get_reaction_steps(); } if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) { - int count = ((cxxTemperature *) use.Get_temperature_ptr())->Get_countTemps(); + int count = use.Get_temperature_ptr()->Get_countTemps(); if (count > count_steps) { count_steps = count; @@ -1436,7 +1332,7 @@ reactions(void) } if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) { - int count = ((cxxPressure *) use.Get_pressure_ptr())->Get_count(); + int count = use.Get_pressure_ptr()->Get_count(); if (count > count_steps) { count_steps = count; @@ -1469,70 +1365,8 @@ reactions(void) if (use.Get_kinetics_in() == TRUE) { - //kinetics_ptr = kinetics_bsearch(-2, &m); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); kin_time = kinetics_ptr->Current_step((incremental_reactions==TRUE), reaction_step); -#ifdef SKIP - if (incremental_reactions == FALSE) - { - if (kinetics_ptr->count_steps > 0) - { - if (reaction_step > kinetics_ptr->count_steps) - { - kin_time = - kinetics_ptr->steps[kinetics_ptr->count_steps - - 1]; - } - else - { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - kin_time = kinetics_ptr->steps[0]; - } - else - { - kin_time = - reaction_step * kinetics_ptr->steps[0] / - ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } - else - { - /* incremental reactions */ - if (kinetics_ptr->count_steps > 0) - { - if (reaction_step > kinetics_ptr->count_steps) - { - kin_time = - kinetics_ptr->steps[kinetics_ptr->count_steps - - 1]; - } - else - { - kin_time = kinetics_ptr->steps[reaction_step - 1]; - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - kin_time = 0; - } - else - { - kin_time = - kinetics_ptr->steps[0] / - ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } -#endif } if (incremental_reactions == FALSE || (incremental_reactions == TRUE && reaction_step == 1)) @@ -1575,12 +1409,6 @@ reactions(void) { Utilities::Rxn_copy(Rxn_kinetics_map, -2, use.Get_n_kinetics_user()); } -#ifdef SKIP - if (use.Get_kinetics_in() == TRUE) - { - kinetics_duplicate(-2, use.Get_n_kinetics_user()); - } -#endif saver(); /* free_model_allocs(); */ @@ -1613,7 +1441,7 @@ saver(void) xsolution_save(n); for (i = save.n_solution_user + 1; i <= save.n_solution_user_end; i++) { - solution_duplicate(n, i); + Utilities::Rxn_copy(Rxn_solution_map, n, i); } } if (save.pp_assemblage == TRUE) @@ -1621,11 +1449,6 @@ saver(void) n = save.n_pp_assemblage_user; xpp_assemblage_save(n); Utilities::Rxn_copies(Rxn_pp_assemblage_map, save.n_pp_assemblage_user, save.n_pp_assemblage_user_end); - //for (i = save.n_pp_assemblage_user + 1; - // i <= save.n_pp_assemblage_user_end; i++) - //{ - // pp_assemblage_duplicate(n, i); - //} } if (save.exchange == TRUE) { @@ -1633,7 +1456,6 @@ saver(void) xexchange_save(n); for (i = save.n_exchange_user + 1; i <= save.n_exchange_user_end; i++) { - //exchange_duplicate(n, i); Utilities::Rxn_copy(Rxn_exchange_map, n, i); } } @@ -1641,10 +1463,7 @@ saver(void) { n = save.n_surface_user; xsurface_save(n); - for (i = save.n_surface_user + 1; i <= save.n_surface_user_end; i++) - { - surface_duplicate(n, i); - } + Utilities::Rxn_copies(Rxn_surface_map, n, save.n_surface_user_end); } if (save.gas_phase == TRUE) { @@ -1653,7 +1472,6 @@ saver(void) for (i = save.n_gas_phase_user + 1; i <= save.n_gas_phase_user_end; i++) { - //gas_phase_duplicate(n, i); Utilities::Rxn_copy(Rxn_gas_phase_map, n, i); } } @@ -1668,12 +1486,10 @@ saver(void) { if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); } else if (use.Get_kinetics_in() != FALSE) { - //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); } if (use.Get_kinetics_ptr() != NULL) @@ -1681,33 +1497,10 @@ saver(void) n = use.Get_kinetics_ptr()->Get_n_user(); for (i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) { - //kinetics_duplicate(n, i); Utilities::Rxn_copy(Rxn_kinetics_map, n, i); } } } -#ifdef SKIP - if (save.kinetics == TRUE && use.Get_kinetics_in() == TRUE - /*&& use.Get_kinetics_ptr() != NULL */) - { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) - { - use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); - } - else if (use.Get_kinetics_in() != FALSE) - { - use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); - } - if (use.Get_kinetics_ptr() != NULL) - { - n = use.Get_kinetics_ptr()->n_user; - for (i = save.n_kinetics_user; i <= save.n_kinetics_user_end; i++) - { - kinetics_duplicate(n, i); - } - } - } -#endif return (OK); } /* ---------------------------------------------------------------------- */ @@ -1722,13 +1515,12 @@ xexchange_save(int n_user) int i, j; char token[MAX_LENGTH]; int count_comps; - //struct exchange temp_exchange, *exchange_ptr; LDBLE charge; if (use.Get_exchange_ptr() == NULL) return (OK); - cxxExchange temp_exchange = *((cxxExchange *) use.Get_exchange_ptr()); + cxxExchange temp_exchange = *use.Get_exchange_ptr(); /* * Store data for structure exchange */ @@ -1739,7 +1531,7 @@ xexchange_save(int n_user) temp_exchange.Set_description(token); temp_exchange.Set_solution_equilibria(false); temp_exchange.Set_n_solution(-999); - temp_exchange.Get_exchComps().clear(); + temp_exchange.Get_exchange_comps().clear(); /* * Write exch_comp structure for each exchange component @@ -1749,14 +1541,13 @@ xexchange_save(int n_user) { if (x[i]->type == EXCH) { - const cxxExchComp *comp_ptr = ((cxxExchange *) use.Get_exchange_ptr())->ExchComp_find(x[i]->exch_comp); + const cxxExchComp *comp_ptr = use.Get_exchange_ptr()->Find_comp(x[i]->exch_comp); if (!comp_ptr) { assert(false); } cxxExchComp xcomp = *comp_ptr; xcomp.Set_la(x[i]->master[0]->s->la); - xcomp.Set_moles(0); /* * Save element concentrations on exchanger */ @@ -1789,8 +1580,7 @@ xexchange_save(int n_user) output_msg(sformatf( "Exchange charge_balance: %e\n", charge)); */ /* update unknown pointer */ - //x[i]->exch_comp = &(temp_exchange.comps[count_comps]); - temp_exchange.Get_exchComps()[x[i]->exch_comp] = xcomp; + temp_exchange.Get_exchange_comps().push_back(xcomp); } } /* @@ -1810,22 +1600,15 @@ xgas_save(int n_user) * Save gas composition into structure gas_phase with user * number n_user. */ - //int count_comps, n, i; - //struct gas_phase temp_gas_phase, *gas_phase_ptr; char token[MAX_LENGTH]; if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); cxxGasPhase temp_gas_phase(*gas_phase_ptr); -/* - * Count gases - */ - //size_t count_comps = gas_phase_ptr->Get_gasPhaseComps().size(); /* * Store in gas_phase */ - temp_gas_phase.Set_n_user(n_user); temp_gas_phase.Set_n_user_end(n_user); sprintf(token, "Gas phase after simulation %d.", simulation); @@ -1902,7 +1685,7 @@ xpp_assemblage_save(int n_user) * number n_user. */ std::string token; - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); if (use.Get_pp_assemblage_ptr() == NULL) return (OK); @@ -1944,53 +1727,36 @@ xsolution_save(int n_user) * * input: n_user is user solution number of target */ - int i, j, n; - int count_mass_balance, count_master_activity; - int max_mass_balance, max_master_activity; - struct solution *solution_ptr; struct master *master_i_ptr, *master_ptr; /* * Malloc space for solution data */ - solution_ptr = solution_alloc(); - - max_mass_balance = MAX_MASS_BALANCE; - max_master_activity = MAX_MASS_BALANCE; - - solution_ptr->n_user = n_user; - solution_ptr->n_user_end = n_user; - solution_ptr->new_def = FALSE; - solution_ptr->description = string_duplicate(description_x); - solution_ptr->tc = tc_x; - solution_ptr->patm = patm_x; - solution_ptr->ph = ph_x; - solution_ptr->solution_pe = solution_pe_x; - solution_ptr->mu = mu_x; - solution_ptr->ah2o = ah2o_x; - solution_ptr->density = density_x; - solution_ptr->total_h = total_h_x; - solution_ptr->total_o = total_o_x; - solution_ptr->cb = cb_x; /* cb_x does not include surface charge sfter sum_species */ - /* does include surface charge after step */ - - solution_ptr->mass_water = mass_water_aq_x; - solution_ptr->total_alkalinity = total_alkalinity; - /*solution_ptr->total_co2 = total_co2; */ - solution_ptr->units = moles_per_kilogram_string; + cxxSolution temp_solution; + temp_solution.Set_n_user_both(n_user); + temp_solution.Set_new_def(false); + temp_solution.Set_description(description_x); + temp_solution.Set_tc(tc_x); + temp_solution.Set_patm(patm_x); + temp_solution.Set_ph(ph_x); + temp_solution.Set_pe(solution_pe_x); + temp_solution.Set_mu(mu_x); + temp_solution.Set_ah2o(ah2o_x); + temp_solution.Set_density(density_x); + temp_solution.Set_total_h(total_h_x); + temp_solution.Set_total_o(total_o_x); + temp_solution.Set_cb(cb_x); /* cb_x does not include surface charge sfter sum_species */ + /* does include surface charge after step */ + temp_solution.Set_mass_water(mass_water_aq_x); + temp_solution.Set_total_alkalinity(total_alkalinity); /* * Copy pe data */ - - pe_data_free(solution_ptr->pe); - /*solution_ptr->pe = pe_data_dup(pe_x); */ - solution_ptr->pe = pe_data_alloc(); - solution_ptr->default_pe = 0; /* * Add in minor isotopes if initial solution calculation */ if (initial_solution_isotopes == TRUE) { - for (i = 0; i < count_master_isotope; i++) + for (int i = 0; i < count_master_isotope; i++) { if (master_isotope[i]->moles > 0) { @@ -2031,38 +1797,7 @@ xsolution_save(int n_user) /* * Copy totals data */ - count_mass_balance = 0; - count_master_activity = 0; - for (i = 0; i < count_master; i++) - { - if (master[i]->in == FALSE) - continue; - if (master[i]->s->type == EX || - master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) - continue; - if (master[i]->s == s_hplus) - continue; - if (master[i]->s == s_h2o) - continue; -/* - * Save list of log activities - */ - if (master[i]->in != FALSE) - { - count_master_activity++; - } - } - solution_ptr->master_activity = - (struct master_activity *) PHRQ_realloc(solution_ptr-> - master_activity, - (size_t) - (count_master_activity + - 1) * - sizeof(struct - master_activity)); - solution_ptr->count_master_activity = count_master_activity; - count_master_activity = 0; - for (i = 0; i < count_master; i++) + for (int i = 0; i < count_master; i++) { if (master[i]->s->type == EX || master[i]->s->type == SURF || master[i]->s->type == SURF_PSI) @@ -2076,16 +1811,7 @@ xsolution_save(int n_user) */ if (master[i]->in != FALSE) { - solution_ptr->master_activity[count_master_activity].description = - master[i]->elt->name; - solution_ptr->master_activity[count_master_activity++].la = - master[i]->s->la; - /* - if (count_master_activity + 2 >= max_master_activity) { - space ((void *) &(solution_ptr->master_activity), count_master_activity + 2, - &max_master_activity, sizeof (struct master_activity)); - } - */ + temp_solution.Get_master_activity()[master[i]->elt->name] = master[i]->s->la; } if (master[i]->total <= MIN_TOTAL) { @@ -2093,150 +1819,45 @@ xsolution_save(int n_user) master[i]->total_primary = 0.0; continue; } -/* if (master[i]->total <= 0.0) continue; */ /* * Save list of concentrations */ - solution_ptr->totals[count_mass_balance].description = - master[i]->elt->name; - solution_ptr->totals[count_mass_balance].input_conc = - master[i]->total; - solution_ptr->totals[count_mass_balance].moles = master[i]->total; - solution_ptr->totals[count_mass_balance].units = solution_ptr->units; - solution_ptr->totals[count_mass_balance].equation_name = NULL; - solution_ptr->totals[count_mass_balance].n_pe = 0; - solution_ptr->totals[count_mass_balance].phase = NULL; - solution_ptr->totals[count_mass_balance].phase_si = 0.0; - solution_ptr->totals[count_mass_balance].as = NULL; - solution_ptr->totals[count_mass_balance].gfw = master[i]->elt->primary->elt->gfw; - count_mass_balance++; -/* - * Make space - */ - if (count_mass_balance + 2 >= max_mass_balance) - { - space((void **) ((void *) &(solution_ptr->totals)), - count_mass_balance + 2, &max_mass_balance, - sizeof(struct conc)); - } + temp_solution.Get_totals()[master[i]->elt->name] = master[i]->total; } if (pitzer_model == TRUE || sit_model == TRUE) { - i = 0; - for (j = 0; j < count_s; j++) + for (int j = 0; j < count_s_x; j++) { - if (s[j]->lg != 0.0) - i++; - } - solution_ptr->species_gamma = - (struct master_activity *) PHRQ_realloc(solution_ptr-> - species_gamma, - (size_t) (i * - sizeof(struct - master_activity))); - i = 0; - for (j = 0; j < count_s; j++) - { - if (s[j]->lg != 0.0) + if (s_x[j]->lg != 0.0) { - solution_ptr->species_gamma[i].la = s[j]->lg; - solution_ptr->species_gamma[i].description = s[j]->name; - i++; + temp_solution.Get_species_gamma()[s_x[j]->name] = s_x[j]->lg; } } - solution_ptr->count_species_gamma = i; } - else - { - solution_ptr->species_gamma = NULL; - solution_ptr->count_species_gamma = 0; - } -/* - * Mark end of totals - */ - solution_ptr->totals[count_mass_balance].description = NULL; - count_mass_balance++; - solution_ptr->master_activity[count_master_activity].description = NULL; - count_master_activity++; - solution_ptr->totals = - (struct conc *) PHRQ_realloc(solution_ptr->totals, - (size_t) count_mass_balance * - sizeof(struct conc)); - if (solution_ptr->totals == NULL) - malloc_error(); - solution_ptr->master_activity = - (struct master_activity *) PHRQ_realloc(solution_ptr-> - master_activity, - (size_t) - count_master_activity * - sizeof(struct - master_activity)); - if (solution_ptr->master_activity == NULL) - malloc_error(); - solution_ptr->count_master_activity = count_master_activity; /* * Save isotope data */ - if (count_isotopes_x > 0) + temp_solution.Set_isotopes(isotopes_x); + std::map< std::string, cxxSolutionIsotope >::iterator it; + for (it = temp_solution.Get_isotopes().begin(); it != temp_solution.Get_isotopes().end(); it++) { - solution_ptr->count_isotopes = count_isotopes_x; - solution_ptr->isotopes = - (struct isotope *) PHRQ_realloc(solution_ptr->isotopes, - (size_t) count_isotopes_x * - sizeof(struct isotope)); - if (solution_ptr->isotopes == NULL) - malloc_error(); - memcpy(solution_ptr->isotopes, isotopes_x, - (size_t) count_isotopes_x * sizeof(struct isotope)); - for (i = 0; i < count_isotopes_x; i++) + struct master *iso_master_ptr = master_bsearch(it->second.Get_elt_name().c_str()); + it->second.Set_total(iso_master_ptr->total); + if (iso_master_ptr == s_hplus->secondary) { - solution_ptr->isotopes[i].total = - solution_ptr->isotopes[i].master->total; - if (solution_ptr->isotopes[i].master == s_hplus->secondary) - { - solution_ptr->isotopes[i].total = - 2 * mass_water_aq_x / gfw_water; - } - if (solution_ptr->isotopes[i].master == s_h2o->secondary) - { - solution_ptr->isotopes[i].total = mass_water_aq_x / gfw_water; - } + it->second.Set_total(2 * mass_water_aq_x / gfw_water); + } + if (iso_master_ptr == s_h2o->secondary) + { + it->second.Set_total(mass_water_aq_x / gfw_water); } - } - else - { - solution_ptr->count_isotopes = 0; - solution_ptr->isotopes = - (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = NULL; } /* - * Save solution in solution + * Save solution */ - if (solution_bsearch(n_user, &n, FALSE) != NULL) - { - solution_free(solution[n]); - } - else - { - n = count_solution++; - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - } - solution[n] = solution_ptr; - /* sort only if necessary */ - if (count_solution > 1 - && (solution[count_solution - 1]->n_user < - solution[count_solution - 2]->n_user)) - { - solution_sort(); - } + Rxn_solution_map[n_user] = temp_solution; return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: xsurface_save(int n_user) @@ -2246,58 +1867,27 @@ xsurface_save(int n_user) * Save surface data into structure surface with user * number n_user. */ - int i, j, n, last_charge; - int count_comps, count_charge; - char token[MAX_LENGTH]; - struct surface temp_surface, *surface_ptr; LDBLE charge; if (use.Get_surface_ptr() == NULL) return (OK); /* * Store data for structure surface */ - memcpy(&temp_surface, use.Get_surface_ptr(), sizeof(struct surface)); - temp_surface.n_user = n_user; - temp_surface.n_user_end = n_user; - temp_surface.new_def = FALSE; - temp_surface.dl_type = dl_type_x; - sprintf(token, "Surface assemblage after simulation %d.", simulation); - temp_surface.description = string_duplicate(token); - temp_surface.solution_equilibria = FALSE; - temp_surface.n_solution = -10; -/* - * Allocate space to pointer comps - */ + cxxSurface temp_surface = *use.Get_surface_ptr(); + temp_surface.Set_n_user(n_user); + temp_surface.Set_n_user_end(n_user); + temp_surface.Set_new_def(false); + temp_surface.Set_dl_type(dl_type_x); + temp_surface.Set_solution_equilibria(false); + temp_surface.Set_n_solution(-999); - count_comps = use.Get_surface_ptr()->count_comps; - count_charge = use.Get_surface_ptr()->count_charge; - temp_surface.count_comps = count_comps; - temp_surface.comps = - (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * - sizeof(struct surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - /*if (temp_surface.edl == FALSE) { */ - if (temp_surface.type == NO_EDL) + if (temp_surface.Get_type() == cxxSurface::NO_EDL) { - temp_surface.charge = NULL; - temp_surface.count_charge = 0; - } - else - { - temp_surface.count_charge = count_charge; - temp_surface.charge = - (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * - sizeof(struct - surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); + temp_surface.Get_surface_charges().clear(); } /* * Write surface_comp structure for each surf component into comps_ptr */ - count_comps = 0; - count_charge = 0; /* * Initial entry of surface sites is random * Charge balance numbering follows the initial entry @@ -2305,34 +1895,21 @@ xsurface_save(int n_user) * Now when we save, the site order differs from the charge order * last_charge sets up logic to renumber charge balance equations. */ - last_charge = -1; - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type == SURFACE) { - memcpy(&temp_surface.comps[count_comps], x[i]->surface_comp, - sizeof(struct surface_comp)); - - temp_surface.comps[count_comps].master = x[i]->master[0]; - temp_surface.comps[count_comps].la = x[i]->master[0]->s->la; - /* temp_surface.comps[count_comps].formula = NULL; */ - temp_surface.comps[count_comps].moles = 0.; - if (x[i]->surface_comp->charge == last_charge) - { - temp_surface.comps[count_comps].charge = count_charge - 1; - } - else - { - temp_surface.comps[count_comps].charge = count_charge; - } - last_charge = x[i]->surface_comp->charge; + cxxSurfaceComp *comp_ptr = temp_surface.Find_comp(x[i]->surface_comp); + assert(comp_ptr); + comp_ptr->Set_la(x[i]->master[0]->s->la); + comp_ptr->Set_moles(0.); /* * Save element concentrations on surface */ count_elts = 0; paren_count = 0; charge = 0.0; - for (j = 0; j < count_species_list; j++) + for (int j = 0; j < count_species_list; j++) { if (species_list[j].master_s == x[i]->master[0]->s) { @@ -2341,160 +1918,68 @@ xsurface_save(int n_user) charge += species_list[j].s->moles * species_list[j].s->z; } } - temp_surface.comps[count_comps].totals = elt_list_save(); - temp_surface.comps[count_comps].formula_totals = - elt_list_dup(x[i]->surface_comp->formula_totals); - temp_surface.comps[count_comps].cb = charge; - - /* update unknown pointer */ - x[i]->surface_comp = &(temp_surface.comps[count_comps]); - count_comps++; - } - else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->type == DDL) - { - memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, - sizeof(struct surface_charge)); - temp_surface.charge[count_charge].charge_balance = x[i]->f; - temp_surface.charge[count_charge].mass_water = - x[i]->surface_charge->mass_water; - temp_surface.charge[count_charge].diffuse_layer_totals = NULL; - temp_surface.charge[count_charge].count_g = 0; - temp_surface.charge[count_charge].g = NULL; -/* - * Added code to save g - */ - - if (x[i]->surface_charge->count_g > - 0 /*&& use.Get_surface_ptr()->type != CD_MUSIC */ ) { - temp_surface.charge[count_charge].count_g = - x[i]->surface_charge->count_g; - temp_surface.charge[count_charge].g = - (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]-> - surface_charge-> - count_g * - sizeof(struct - surface_diff_layer)); - if (temp_surface.charge[count_charge].g == NULL) - malloc_error(); - memcpy(temp_surface.charge[count_charge].g, - x[i]->surface_charge->g, - (size_t) x[i]->surface_charge->count_g * - sizeof(struct surface_diff_layer)); + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); } - - /*temp_surface.charge[count_charge].psi_master = x[i]->master[0]; */ - temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; + comp_ptr->Set_charge_balance(charge); + } + else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + { + cxxSurfaceCharge *charge_ptr = temp_surface.Find_charge(x[i]->surface_charge); + assert(charge_ptr); + charge_ptr->Set_charge_balance(x[i]->f); + charge_ptr->Set_la_psi(x[i]->master[0]->s->la); /* * Store moles from diffuse_layer */ - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { - sum_diffuse_layer(x[i]->surface_charge); - temp_surface.charge[count_charge].diffuse_layer_totals = - elt_list_save(); + sum_diffuse_layer(charge_ptr); + cxxNameDouble nd = elt_list_NameDouble(); + charge_ptr->Set_diffuse_layer_totals(nd); } - - /* update unknown pointer */ - x[i]->surface_charge = &(temp_surface.charge[count_charge]); - x[i]->surface_comp = x[i - 1]->surface_comp; - - count_charge++; } else if (x[i]->type == SURFACE_CB - && use.Get_surface_ptr()->type == CD_MUSIC) + && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - memcpy(&temp_surface.charge[count_charge], x[i]->surface_charge, - sizeof(struct surface_charge)); - if (dl_type_x != NO_DL) + cxxSurfaceCharge *charge_ptr = temp_surface.Find_charge(x[i]->surface_charge); + assert(charge_ptr); + if (dl_type_x != cxxSurface::NO_DL) { - temp_surface.charge[count_charge].charge_balance = - (x[i]->surface_charge->sigma0 + - x[i]->surface_charge->sigma1 + - x[i]->surface_charge->sigma2 + - x[i]->surface_charge->sigmaddl) - * (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams) / F_C_MOL; + charge_ptr->Set_charge_balance( + (charge_ptr->Get_sigma0() + + charge_ptr->Get_sigma1() + + charge_ptr->Get_sigma2() + + charge_ptr->Get_sigmaddl()) + * (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL); } else { - temp_surface.charge[count_charge].charge_balance = - (x[i]->surface_charge->sigma0 + - x[i]->surface_charge->sigma1 + - x[i]->surface_charge->sigma2) - * (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams) / F_C_MOL; + charge_ptr->Set_charge_balance( + (charge_ptr->Get_sigma0() + + charge_ptr->Get_sigma1() + + charge_ptr->Get_sigma2()) + * (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL); } - temp_surface.charge[count_charge].mass_water = - x[i]->surface_charge->mass_water; - temp_surface.charge[count_charge].diffuse_layer_totals = NULL; - temp_surface.charge[count_charge].count_g = 0; - temp_surface.charge[count_charge].g = NULL; -/* - * Added code to save g - */ - - if (x[i]->surface_charge->count_g > 0) - { - temp_surface.charge[count_charge].count_g = - x[i]->surface_charge->count_g; - temp_surface.charge[count_charge].g = - (struct surface_diff_layer *) PHRQ_malloc((size_t) x[i]-> - surface_charge-> - count_g * - sizeof(struct - surface_diff_layer)); - if (temp_surface.charge[count_charge].g == NULL) - malloc_error(); - memcpy(temp_surface.charge[count_charge].g, - x[i]->surface_charge->g, - (size_t) x[i]->surface_charge->count_g * - sizeof(struct surface_diff_layer)); - } - - /*temp_surface.charge[count_charge].psi_master = x[i]->master[0]; */ - temp_surface.charge[count_charge].la_psi = x[i]->master[0]->s->la; + charge_ptr->Set_la_psi(x[i]->master[0]->s->la); /* * Store moles from diffuse_layer */ - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { - sum_diffuse_layer(x[i]->surface_charge); - temp_surface.charge[count_charge].diffuse_layer_totals = - elt_list_save(); + sum_diffuse_layer(charge_ptr); + cxxNameDouble nd = elt_list_NameDouble(); + charge_ptr->Set_diffuse_layer_totals(nd); } - - /* update unknown pointer */ - x[i]->surface_charge = &(temp_surface.charge[count_charge]); - x[i]->surface_comp = x[i - 1]->surface_comp; - - count_charge++; } } /* * Finish up */ - surface_ptr = surface_bsearch(n_user, &n); - if (surface_ptr == NULL) - { - n = count_surface++; - space((void **) ((void *) &surface), count_surface, &max_surface, - sizeof(struct surface)); - } - else - { - surface_free(&surface[n]); - } - memcpy(&surface[n], &temp_surface, sizeof(struct surface)); - if (n == count_surface - 1 && count_surface > 1) - { - if (surface[n].n_user < surface[n - 1].n_user) - { - qsort(surface, - (size_t) count_surface, - (size_t) sizeof(struct surface), surface_compare); - } - } + Rxn_surface_map[n_user] = temp_surface; use.Set_surface_ptr(NULL); return (OK); } @@ -2515,7 +2000,7 @@ copy_use(int i) */ if (use.Get_solution_in() == TRUE) { - solution_duplicate(use.Get_n_solution_user(), i); + Utilities::Rxn_copy(Rxn_solution_map, use.Get_n_solution_user(), i); } /* * Always save solution to i, mixing or not @@ -2528,7 +2013,6 @@ copy_use(int i) */ if (use.Get_pp_assemblage_in() == TRUE) { - //pp_assemblage_duplicate(use.Get_n_pp_assemblage_user(), i); Utilities::Rxn_copy(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user(), i); save.pp_assemblage = TRUE; save.n_pp_assemblage_user = i; @@ -2571,7 +2055,6 @@ copy_use(int i) */ if (use.Get_kinetics_in() == TRUE) { - //kinetics_duplicate(use.Get_n_kinetics_user(), i); Utilities::Rxn_copy(Rxn_kinetics_map, use.Get_n_kinetics_user(), i); save.kinetics = TRUE; save.n_kinetics_user = i; @@ -2581,26 +2064,13 @@ copy_use(int i) { save.kinetics = FALSE; } -#ifdef SKIP - if (use.Get_kinetics_in() == TRUE) - { - kinetics_duplicate(use.Get_n_kinetics_user(), i); - save.kinetics = TRUE; - save.n_kinetics_user = i; - save.n_kinetics_user_end = i; - } - else - { - save.kinetics = FALSE; - } -#endif /* * Find surface */ - dl_type_x = NO_DL; + dl_type_x = cxxSurface::NO_DL; if (use.Get_surface_in() == TRUE) { - surface_duplicate(use.Get_n_surface_user(), i); + Utilities::Rxn_copy(Rxn_surface_map, use.Get_n_surface_user(), i); save.surface = TRUE; save.n_surface_user = i; save.n_surface_user_end = i; @@ -2628,7 +2098,6 @@ copy_use(int i) */ if (use.Get_gas_phase_in() == TRUE) { - //gas_phase_duplicate(use.Get_n_gas_phase_user(), i); Utilities::Rxn_copy(Rxn_gas_phase_map, use.Get_n_gas_phase_user(), i); save.gas_phase = TRUE; save.n_gas_phase_user = i; @@ -2643,7 +2112,6 @@ copy_use(int i) */ if (use.Get_ss_assemblage_in() == TRUE) { - //ss_assemblage_duplicate(use.Get_n_ss_assemblage_user(), i); Utilities::Rxn_copy(Rxn_ss_assemblage_map, use.Get_n_ss_assemblage_user(), i); save.ss_assemblage = TRUE; save.n_ss_assemblage_user = i; @@ -2665,7 +2133,6 @@ step_save_exch(int n_user) * * input: n_user is user exchange number of target */ - //int i; bool found; if (use.Get_exchange_ptr() == NULL) @@ -2677,10 +2144,9 @@ step_save_exch(int n_user) // Set all totals to 0.0 cxxExchange temp_exchange = *temp_ptr; { - std::map::iterator it = temp_exchange.Get_exchComps().begin(); - for ( ; it != temp_exchange.Get_exchComps().end(); it++) + for (size_t i = 0; i < temp_exchange.Get_exchange_comps().size(); i++) { - it->second.Get_totals().multiply(0.0); + temp_exchange.Get_exchange_comps()[i].Get_totals().multiply(0.0); } } @@ -2691,10 +2157,9 @@ step_save_exch(int n_user) continue; found = false; std::string e(master[i]->elt->name); - std::map::iterator it = temp_exchange.Get_exchComps().begin(); - for ( ; it != temp_exchange.Get_exchComps().end(); it++) + for (size_t j = 0; j < temp_exchange.Get_exchange_comps().size(); j++) { - cxxNameDouble *nd = &(it->second.Get_totals()); + cxxNameDouble *nd = &(temp_exchange.Get_exchange_comps()[j].Get_totals()); cxxNameDouble::iterator nd_it = nd->find(e); if (nd_it != nd->end()) { @@ -2728,48 +2193,44 @@ step_save_surf(int n_user) * * input: n_user is user solution number of target */ - int i, j, k, n; - struct surface *surface_ptr; - /* - * Malloc space for solution data - */ if (use.Get_surface_ptr() == NULL) return (OK); - surface_duplicate(use.Get_surface_ptr()->n_user, n_user); - surface_ptr = surface_bsearch(n_user, &n); - for (i = 0; i < count_master; i++) + Utilities::Rxn_copy(Rxn_surface_map, use.Get_surface_ptr()->Get_n_user(), n_user); + cxxSurface *surface_ptr = Utilities::Rxn_find(Rxn_surface_map, n_user); + for (int i = 0; i < count_master; i++) { if (master[i]->s->type != SURF) continue; - for (j = 0; j < surface_ptr->count_comps; j++) + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { - for (k = 0; surface_ptr->comps[j].totals[k].elt != NULL; k++) + cxxSurfaceComp * comp_ptr = &(surface_ptr->Get_surface_comps()[j]); + cxxNameDouble & totals = comp_ptr->Get_totals(); + if (totals.find(master[i]->elt->name) == totals.end()) { - if (surface_ptr->comps[j].totals[k].elt == master[i]->elt) + continue; + } + else + { + LDBLE coef = master[i]->total; + if (master[i]->total <= MIN_TOTAL) { - if (master[i]->total <= MIN_TOTAL) - { - surface_ptr->comps[j].totals[k].coef = MIN_TOTAL; - } - else - { - surface_ptr->comps[j].totals[k].coef = - master[i]->total; - } - break; + coef = MIN_TOTAL; } + totals[master[i]->elt->name] = coef; + break; } } } /* * Update grams */ - if ((surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) - && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) + if ((surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) + && surface_ptr->Get_related_rate() && use.Get_kinetics_ptr() != NULL) { - for (j = 0; j < surface_ptr->count_comps; j++) + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { - if (surface_ptr->comps[j].rate_name != NULL) + cxxSurfaceComp *surface_comp_ptr = &(surface_ptr->Get_surface_comps()[j]); + if (surface_comp_ptr->Get_rate_name().size() > 0) { cxxKinetics *kinetics_ptr = use.Get_kinetics_ptr(); for (size_t m = 0; m < kinetics_ptr->Get_kinetics_comps().size(); m++) @@ -2777,46 +2238,23 @@ step_save_surf(int n_user) cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[m]); if (strcmp_nocase (kinetics_comp_ptr->Get_rate_name().c_str(), - surface_ptr->comps[j].rate_name) != 0) + surface_comp_ptr->Get_rate_name().c_str()) != 0) continue; - surface_ptr->charge[surface_ptr->comps[j].charge].grams = - kinetics_comp_ptr->Get_m(); + cxxSurfaceCharge *charge_ptr = surface_ptr->Find_charge(surface_comp_ptr->Get_charge_name()); + charge_ptr->Set_grams(kinetics_comp_ptr->Get_m()); break; } } } } -#ifdef SKIP - if ((surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) - && surface_ptr->related_rate == TRUE && use.Get_kinetics_ptr() != NULL) - { - for (j = 0; j < surface_ptr->count_comps; j++) - { - if (surface_ptr->comps[j].rate_name != NULL) - { - for (m = 0; m < use.Get_kinetics_ptr()->count_comps; m++) - { - if (strcmp_nocase - (use.Get_kinetics_ptr()->comps[m].rate_name, - surface_ptr->comps[j].rate_name) != 0) - continue; - surface_ptr->charge[surface_ptr->comps[j].charge].grams = - use.Get_kinetics_ptr()->comps[m].m; - break; - } - } - } - } -#endif return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: copy_entities(void) /* ---------------------------------------------------------------------- */ { - int i, j, n, return_value; + int i, j, return_value; int verbose; verbose = FALSE; @@ -2825,14 +2263,14 @@ copy_entities(void) { for (j = 0; j < copy_solution.count; j++) { - if (solution_bsearch(copy_solution.n_user[j], &n, FALSE) != NULL) + if (Utilities::Rxn_find(Rxn_solution_map, copy_solution.n_user[j]) != NULL) { for (i = copy_solution.start[j]; i <= copy_solution.end[j]; i++) { if (i == copy_solution.n_user[j]) continue; - solution_duplicate(copy_solution.n_user[j], i); + Utilities::Rxn_copy(Rxn_solution_map, copy_solution.n_user[j], i); } } else @@ -2849,7 +2287,6 @@ copy_entities(void) { for (j = 0; j < copy_pp_assemblage.count; j++) { - //if (pp_assemblage_bsearch(copy_pp_assemblage.n_user[j], &n) != NULL) if (Utilities::Rxn_find(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j]) != NULL) { for (i = copy_pp_assemblage.start[j]; @@ -2857,7 +2294,6 @@ copy_entities(void) { if (i == copy_pp_assemblage.n_user[j]) continue; - //pp_assemblage_duplicate(copy_pp_assemblage.n_user[j], i); Utilities::Rxn_copy(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j], i); } } @@ -2875,14 +2311,12 @@ copy_entities(void) { for (j = 0; j < copy_reaction.count; j++) { - //if (irrev_bsearch(copy_irrev.n_user[j], &n) != NULL) if (Utilities::Rxn_find(Rxn_reaction_map, copy_reaction.n_user[j]) != NULL) { for (i = copy_reaction.start[j]; i <= copy_reaction.end[j]; i++) { if (i == copy_reaction.n_user[j]) continue; - //irrev_duplicate(copy_irrev.n_user[j], i); Utilities::Rxn_copy(Rxn_reaction_map, copy_reaction.n_user[j], i); } } @@ -2949,13 +2383,13 @@ copy_entities(void) { for (j = 0; j < copy_surface.count; j++) { - if (surface_bsearch(copy_surface.n_user[j], &n) != NULL) + if (Utilities::Rxn_find(Rxn_surface_map, copy_surface.n_user[j]) != NULL) { for (i = copy_surface.start[j]; i <= copy_surface.end[j]; i++) { if (i == copy_surface.n_user[j]) continue; - surface_duplicate(copy_surface.n_user[j], i); + Utilities::Rxn_copy(Rxn_surface_map, copy_surface.n_user[j], i); } } else @@ -3136,7 +2570,7 @@ run_simulations(void) /* ---------------------------------------------------------------------- */ { char token[MAX_LENGTH]; -#ifdef SKIP +#ifdef SKIP_KEEP #if defined(WIN32) unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); @@ -3294,7 +2728,8 @@ do_status(void) screen_msg("\n"); } dup_print("End of run.", TRUE); - screen_msg("\nEnd of Run.\n"); + screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", + (double) clock() / CLOCKS_PER_SEC)); } catch (PhreeqcStop e) { diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index a18d52c1..3d824a95 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -1,3 +1,4 @@ +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "cxxMix.h" @@ -5,6 +6,7 @@ #include "GasPhase.h" #include "PPassemblage.h" #include "SSassemblage.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -40,7 +42,9 @@ model(void) int count_infeasible, count_basis_change; int debug_model_save; int mass_water_switch_save; + LDBLE old_mu; + same_mu = true; set_inert_moles(); /* debug_model = TRUE; */ /* debug_prep = TRUE; */ @@ -95,6 +99,7 @@ model(void) } #endif iterations++; + old_mu = mu_x; if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { @@ -159,6 +164,13 @@ model(void) } reset(); } +#ifndef PHREEQC2 + if (fabs(old_mu - mu_x) > 1e-3 * mu_x) + { + same_mu = false; + old_mu = mu_x; + } +#endif gammas(mu_x); if (molalities(FALSE) == ERROR) { @@ -166,8 +178,8 @@ model(void) /* adjust_step_size(); */ } if (use.Get_surface_ptr() != NULL && - use.Get_surface_ptr()->dl_type != NO_DL && - use.Get_surface_ptr()->related_phases == TRUE) + use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && + use.Get_surface_ptr()->Get_related_phases()) initial_surface_water(); mb_sums(); mb_gases(); @@ -183,8 +195,8 @@ model(void) gammas(mu_x); molalities(TRUE); if (use.Get_surface_ptr() != NULL && - use.Get_surface_ptr()->dl_type != NO_DL && - use.Get_surface_ptr()->related_phases == TRUE) + use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && + use.Get_surface_ptr()->Get_related_phases()) initial_surface_water(); revise_guesses(); mb_sums(); @@ -337,7 +349,7 @@ check_residuals(void) error_msg(error_string, CONTINUE); } } - else if (x[i]->type == MU && pitzer_model == FALSE && sit_model == FALSE) + else if (x[i]->type == MU /*&& pitzer_model == FALSE && sit_model == FALSE*/) { if (fabs(residual[i]) >= epsilon * mu_x * @@ -403,10 +415,9 @@ check_residuals(void) } else if (x[i]->type == PP) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); if (comp_ptr->Get_add_formula().size() == 0) - //if (x[i]->pure_phase->add_formula == NULL) { if (x[i]->dissolve_only == TRUE) { @@ -491,7 +502,8 @@ check_residuals(void) else if (x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) { - if ((x[i]->surface_charge->grams > MIN_RELATED_SURFACE + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if ((charge_ptr->Get_grams() > MIN_RELATED_SURFACE && fabs(residual[i]) > epsilon) /* || stop_program == TRUE */ ) { @@ -549,7 +561,6 @@ check_residuals(void) } return (return_value); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: gammas(LDBLE mu) @@ -562,7 +573,7 @@ gammas(LDBLE mu) int i, j; int ifirst, ilast; LDBLE d1, d2, d3, f, a_llnl, b_llnl, bdot_llnl, log_g_co2, dln_g_co2, c2_llnl; - LDBLE s1, s2, s3; + LDBLE c1, c2, a, b; LDBLE muhalf, equiv; /* Initialize */ @@ -574,6 +585,8 @@ gammas(LDBLE mu) /* * compute temperature dependence of a and b for debye-huckel */ +#ifdef PHREEQC2 + LDBLE s1, s2, s3; s1 = 374.11 - tc_x; s2 = pow(s1, (LDBLE) 1.0 / (LDBLE) 3.0); s3 = 1.0 + 0.1342489 * s2 - 3.946263e-03 * s1; @@ -600,6 +613,14 @@ gammas(LDBLE mu) */ a = 1824827.7 * s3 / (c1 * c1 * c1); b = 50.2905 * s3 / c1; +#else + // a and b are calc'd in calc_dielectrics(tc_x, patm_x); + if (!same_mu) + k_temp(tc_x, patm_x); + same_mu = true; + a = DH_A; + b = DH_B; +#endif /* * LLNL temperature dependence */ @@ -820,7 +841,7 @@ gammas(LDBLE mu) break; } } - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { /* mole fraction */ equiv = 1.0; @@ -896,7 +917,6 @@ gammas(LDBLE mu) } return (OK); } - /* ------------------------------------------------------------------------------- */ int Phreeqc:: ineq(int in_kode) @@ -935,7 +955,7 @@ ineq(int in_kode) /* * Special case for removing unstable phases */ - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); cxxPPassemblageComp * comp_ptr; if (remove_unstable_phases == TRUE) @@ -977,7 +997,7 @@ ineq(int in_kode) return (OK); } /* - * Pitzer model does not have activity of water or mu + * Pitzer model does not have activity of water //or mu */ if (pitzer_model == TRUE || sit_model == TRUE) { @@ -985,7 +1005,7 @@ ineq(int in_kode) { if ((x[i]->type == AH2O && full_pitzer == FALSE) || (x[i]->type == MH && pitzer_model == TRUE && pitzer_pe == FALSE) || - x[i]->type == MU || + /*x[i]->type == MU ||*/ (x[i]->type == PITZER_GAMMA && full_pitzer == FALSE)) { for (j = 0; j < count_unknowns; j++) @@ -1318,24 +1338,29 @@ ineq(int in_kode) && x[i]->moles <= MIN_RELATED_SURFACE) continue; if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 - || x[i]->type == SURFACE_CB2) && - /* x[i-1]->phase_unknown == NULL && */ - /* x[i-1]->moles <= MIN_RELATED_SURFACE) continue; */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) - continue; + || x[i]->type == SURFACE_CB2) ) + { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() <= MIN_RELATED_SURFACE) + { + continue; + } + } if (x[i]->type == SURFACE && x[i]->phase_unknown != NULL && -/* x[i]->phase_unknown->f > 0e-8 && */ x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && comp_ptr->Get_add_formula().size() == 0) continue; if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 - || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL && -/* x[i-1]->phase_unknown->f > 0e-8 && */ -/* x[i-1]->phase_unknown->moles <= MIN_RELATED_SURFACE && */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && - comp_ptr1->Get_add_formula().size() == 0) - continue; + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL) + { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() <= MIN_RELATED_SURFACE && + comp_ptr1->Get_add_formula().size() == 0) + { + continue; + } + } memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(array[i * (count_unknowns + 1)]), (size_t) (count_unknowns + 1) * sizeof(LDBLE)); @@ -1495,10 +1520,8 @@ ineq(int in_kode) * No moles of exchanger */ if (use.Get_exchange_ptr() != NULL - //&& (use.Get_exchange_ptr()->related_phases == TRUE - // || use.Get_exchange_ptr()->related_rate == TRUE)) - && (((cxxExchange *) use.Get_exchange_ptr())->Get_related_phases() || - ((cxxExchange *) use.Get_exchange_ptr())->Get_related_rate())) + && (use.Get_exchange_ptr()->Get_related_phases() || + use.Get_exchange_ptr()->Get_related_rate())) { for (i = 0; i < count_unknowns; i++) { @@ -1515,8 +1538,8 @@ ineq(int in_kode) * No moles of surface */ if (use.Get_surface_ptr() != NULL - && (use.Get_surface_ptr()->related_phases == TRUE - || use.Get_surface_ptr()->related_rate == TRUE)) + && (use.Get_surface_ptr()->Get_related_phases() + || use.Get_surface_ptr()->Get_related_rate())) { for (i = 0; i < count_unknowns; i++) { @@ -1532,15 +1555,21 @@ ineq(int in_kode) { comp_ptr1 = pp_assemblage_ptr->Find(x[i-1]->phase_unknown->phase->name); } + LDBLE grams = 0; + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) + && x[i - 1]->phase_unknown != NULL) + { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + grams = charge_ptr->Get_grams(); + } if ((x[i]->type == SURFACE && x[i]->phase_unknown != NULL && -/* x[i]->phase_unknown->f > 0e-8 && */ x[i]->phase_unknown->moles <= MIN_RELATED_SURFACE && comp_ptr->Get_add_formula().size() == 0) || ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) && x[i - 1]->phase_unknown != NULL && -/* x[i-1]->phase_unknown->f > 0e-8 && */ - x[i]->surface_charge->grams <= MIN_RELATED_SURFACE && + grams <= MIN_RELATED_SURFACE && comp_ptr1->Get_add_formula().size() == 0)) { for (j = 0; j < l_count_rows; j++) @@ -1555,15 +1584,22 @@ ineq(int in_kode) */ if (use.Get_surface_ptr() != NULL) { + LDBLE grams = 0;; for (i = 0; i < count_unknowns; i++) { + if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 + || x[i]->type == SURFACE_CB2) && x[i - 1]->phase_unknown == NULL) + { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + grams = charge_ptr->Get_grams(); + } if ((x[i]->type == SURFACE && x[i]->phase_unknown == NULL && x[i]->moles <= MIN_RELATED_SURFACE) || ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) && x[i - 1]->phase_unknown == NULL - && x[i]->surface_charge->grams <= MIN_RELATED_SURFACE)) + && grams <= MIN_RELATED_SURFACE)) { for (j = 0; j < l_count_rows; j++) { @@ -1772,7 +1808,6 @@ ineq(int in_kode) { return_code = ERROR; return_code = 2; - //error_msg("Too many iterations in Cl1. Should not have done this.", STOP); warning_msg("Too many iterations in Cl1. Should not have done this."); } else @@ -2016,20 +2051,25 @@ jacobian_sums(void) /* * Surface charge balance */ - if (surface_unknown != NULL && dl_type_x == NO_DL) + if (surface_unknown != NULL && dl_type_x == cxxSurface::NO_DL) { sinh_constant = sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); for (i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE_CB && x[i]->surface_charge->grams > 0) + cxxSurfaceCharge *charge_ptr = NULL; + if (x[i]->type == SURFACE_CB) + { + charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + } + if (x[i]->type == SURFACE_CB && charge_ptr->Get_grams() > 0) { for (j = 0; j < count_unknowns; j++) { array[x[i]->number * (count_unknowns + 1) + j] *= - F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()); } array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= sinh_constant * sqrt(mu_x) * @@ -2098,7 +2138,7 @@ mb_gases(void) gas_in = FALSE; if (gas_unknown == NULL || use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { if (gas_unknown->f > gas_phase_ptr->Get_total_p() + 1e-7 || @@ -2127,7 +2167,6 @@ int Phreeqc:: mb_ss(void) /* ---------------------------------------------------------------------- */ { - //int i, j; LDBLE lp, log10_iap, total_moles; LDBLE iapc, iapb, l_kc, l_kb, lc, lb, xcaq, xbaq, xb, xc; LDBLE sigmapi_aq, sigmapi_solid; @@ -2141,8 +2180,6 @@ mb_ss(void) std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); for (size_t i = 0; i < ss_ptrs.size(); i++) { - //for (i = 0; i < use.Get_ss_assemblage_ptr()->count_s_s; i++) - //{ cxxSS *ss_ptr = ss_ptrs[i]; total_moles = 0; for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) @@ -2236,8 +2273,6 @@ mb_ss(void) * Calculate total mole fraction from solution activities */ total_p = 0; - //for (j = 0; j < s_s_ptr->count_comps; j++) - //{ for (size_t j = 0; j < ss_ptr->Get_ss_comps().size(); j++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); @@ -2269,7 +2304,6 @@ mb_ss(void) if (x[i]->type != SS_MOLES) break; cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); - //x[i]->ss_in = x[i]->s_s->ss_in; x[i]->ss_in = ss_ptr->Get_ss_in() ? TRUE : FALSE; } return (OK); @@ -2285,7 +2319,7 @@ molalities(int allow_overflow) * Calculates lm and moles from lk, lg, and la's of master species * Adjusts lm of h2 and o2. */ - int i, j, count_g; + int i, j; LDBLE total_g; struct rxn_token *rxn_ptr; /* @@ -2298,7 +2332,7 @@ molalities(int allow_overflow) master[i]->s->la = master[i]->s->lm + master[i]->s->lg; } } - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { s_h2o->tot_g_moles = s_h2o->moles; s_h2o->tot_dh2o_moles = 0.0; @@ -2335,14 +2369,6 @@ molalities(int allow_overflow) else { s_x[i]->moles = under(s_x[i]->lm) * mass_water_aq_x; - //output_msg(sformatf("%s \t%e\n", s_x[i]->name, s_x[i]->moles)); - /* - if (_isnan(s_x[i]->moles)) - { - fprintf(stderr,"molalities moles %s %e\n", s_x[i]->name, s_x[i]->moles); - exit(4); - } - */ if (s_x[i]->moles / mass_water_aq_x > 100) { log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", @@ -2361,38 +2387,38 @@ molalities(int allow_overflow) /* * other terms for diffuse layer model */ - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->type == CD_MUSIC - && dl_type_x != NO_DL) + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC + && dl_type_x != cxxSurface::NO_DL) calc_all_donnan(); + for (i = 0; i < count_s_x; i++) { if (s_x[i]->type > HPLUS && s_x[i]->type != EX && s_x[i]->type != SURF) continue; - if (use.Get_surface_ptr() != NULL && dl_type_x != NO_DL + if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL && s_x[i]->type <= HPLUS) { total_g = 0.0; s_x[i]->tot_dh2o_moles = 0.0; - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { - count_g = s_x[i]->diff_layer[j].count_g; + int is = s_x[i]->number; + cxxSurfaceCharge & charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; /* * partially corrected formulation assumes mass of water in diffuse layer * is insignificant. Excess is calculated on the basis of moles_water_aq_x * instead of moles_water_bulk. */ /* revised eq. 61 */ - s_x[i]->diff_layer[j].g_moles = - s_x[i]->moles * s_x[i]->erm_ddl * - (s_x[i]->diff_layer[j].charge->g[count_g].g + - s_x[i]->diff_layer[j].charge->mass_water / - mass_water_aq_x); + s_diff_layer[is][charge_ref.Get_name()].Set_g_moles(s_x[i]->moles * s_x[i]->erm_ddl * + (charge_ref.Get_g_map()[s_x[i]->z].Get_g() + + charge_ref.Get_mass_water() / + mass_water_aq_x)); if (s_x[i]->moles > 1e-30) { - s_x[i]->diff_layer[j].dg_g_moles = - s_x[i]->dg * s_x[i]->diff_layer[j].g_moles / - s_x[i]->moles; + s_diff_layer[is][charge_ref.Get_name()].Set_dg_g_moles(s_x[i]->dg * s_diff_layer[is][charge_ref.Get_name()].Get_g_moles() / + s_x[i]->moles); } /* @@ -2401,28 +2427,26 @@ molalities(int allow_overflow) * the jacobian for species i */ total_g += - s_x[i]->diff_layer[j].charge->g[count_g].g + - s_x[i]->diff_layer[j].charge->mass_water / + charge_ref.Get_g_map()[s_x[i]->z].Get_g() + + charge_ref.Get_mass_water() / mass_water_aq_x; - /* revised eq. 63, second term */ /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ - s_x[i]->diff_layer[j].dx_moles = + s_diff_layer[is][charge_ref.Get_name()].Set_dx_moles( s_x[i]->moles * s_x[i]->erm_ddl * - s_x[i]->diff_layer[j].charge->g[count_g].dg; - + charge_ref.Get_g_map()[s_x[i]->z].Get_dg()); /* revised eq. 63, third term */ - s_x[i]->diff_layer[j].dh2o_moles = + s_diff_layer[is][charge_ref.Get_name()].Set_dh2o_moles( -s_x[i]->moles * s_x[i]->erm_ddl * - s_x[i]->diff_layer[j].charge->mass_water / - mass_water_aq_x; - s_x[i]->tot_dh2o_moles += s_x[i]->diff_layer[j].dh2o_moles; + charge_ref.Get_mass_water() / + mass_water_aq_x); + s_x[i]->tot_dh2o_moles += s_diff_layer[is][charge_ref.Get_name()].Get_dh2o_moles(); /* surface related to phase */ - s_x[i]->diff_layer[j].drelated_moles = + s_diff_layer[is][charge_ref.Get_name()].Set_drelated_moles( s_x[i]->moles * s_x[i]->erm_ddl * - use.Get_surface_ptr()->charge[j].specific_area * - use.Get_surface_ptr()->thickness / mass_water_aq_x; + charge_ref.Get_specific_area() * + use.Get_surface_ptr()->Get_thickness() / mass_water_aq_x); } s_x[i]->tot_g_moles = s_x[i]->moles * (1 + total_g /* s_x[i]->erm_ddl */ ); @@ -2446,47 +2470,50 @@ molalities(int allow_overflow) (double) s_x[i]->moles, (double) s_x[i]->tot_g_moles)); output_msg(sformatf( "\tg\n")); - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { - count_g = s_x[i]->diff_layer[j].count_g; + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; output_msg(sformatf( "\t%e", - (double) s_x[i]->diff_layer[j].charge-> - g[count_g].g)); + (double) charge_ref.Get_g_map()[s_x[i]->z].Get_g())); } output_msg(sformatf( "\n\tg_moles\n")); - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + int is = s_x[i]->number; output_msg(sformatf( "\t%e", - (double) s_x[i]->diff_layer[j].g_moles)); + (double) s_diff_layer[is][charge_ref.Get_name()].Get_g_moles())); } output_msg(sformatf( "\n\tdg\n")); - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { - count_g = s_x[i]->diff_layer[j].count_g; + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; output_msg(sformatf( "\t%e", - (double) s_x[i]->diff_layer[j].charge-> - g[count_g].dg)); + (double) charge_ref.Get_g_map()[s_x[i]->z].Get_dg())); } output_msg(sformatf( "\n\tdx_moles\n")); - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { + int is = s_x[i]->number; + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; output_msg(sformatf( "\t%e", - (double) s_x[i]->diff_layer[j].dx_moles)); + (double) s_diff_layer[is][charge_ref.Get_name()].Get_dx_moles())); } output_msg(sformatf( "\n\tdh2o_moles\t%e\n", (double) s_x[i]->tot_dh2o_moles)); - for (j = 0; j < use.Get_surface_ptr()->count_charge; j++) + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + int is = s_x[i]->number; output_msg(sformatf( "\t%e", - (double) s_x[i]->diff_layer[j].dh2o_moles)); + s_diff_layer[is][charge_ref.Get_name()].Get_dh2o_moles())); } output_msg(sformatf( "\n")); } } } - - calc_gas_pressures(); - calc_ss_fractions(); + calc_gas_pressures(); + calc_ss_fractions(); return (OK); } @@ -2498,9 +2525,6 @@ calc_gas_pressures(void) int n_g = 0; LDBLE lp, V_m = 0; struct rxn_token *rxn_ptr; - //struct gas_comp *gas_comp_ptr; - //struct phase *phase_ptr; - //struct phase **phase_ptrs; std::vector phase_ptrs; bool PR = false, pr_done = false; /* @@ -2508,7 +2532,7 @@ calc_gas_pressures(void) */ if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) { if (iterations > 2) @@ -2521,22 +2545,18 @@ calc_gas_pressures(void) gas_phase_ptr->Set_total_moles(0); } - //phase_ptrs = new phase *[gas_phase_ptr->Get_gas_comps().size()]; for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { const cxxGasComp * gas_comp_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); int j; struct phase *phase_ptr = phase_bsearch(gas_comp_ptr->Get_phase_name().c_str(), &j, FALSE); - //phase_ptr = use.Get_gas_phase_ptr()->comps[i].phase; if (phase_ptr->in == TRUE) { phase_ptrs.push_back(phase_ptr); - //phase_ptrs[i] = phase_ptr; if (!PR && phase_ptr->t_c > 0 && phase_ptr->p_c > 0) PR = true; n_g++; } - //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); if (iterations > 2 && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) { gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + phase_ptr->moles_x); @@ -2604,7 +2624,6 @@ calc_gas_pressures(void) } gas_phase_ptr->Set_total_moles(0); - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) std::vector gas_comps; for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { @@ -2668,11 +2687,8 @@ calc_gas_pressures(void) if (gas_phase_ptr->Get_total_p() > 1500) { gas_phase_ptr->Set_total_moles(0); - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { - //gas_comp_ptr = &(use.Get_gas_phase_ptr()->comps[i]); - //phase_ptr = use.Get_gas_phase_ptr()->comps[i].phase; const cxxGasComp *gas_comp = &(gas_phase_ptr->Get_gas_comps()[i]); int j; struct phase *phase_ptr = phase_bsearch(gas_comp->Get_phase_name().c_str(), &j, FALSE); @@ -2703,10 +2719,7 @@ int Phreeqc:: calc_ss_fractions(void) /* ---------------------------------------------------------------------- */ { - //int i, k; LDBLE moles, n_tot; - //struct s_s *s_s_ptr; - /* * moles and lambdas for solid solutions */ @@ -2890,7 +2903,6 @@ int Phreeqc:: ss_ideal(cxxSS *ss_ptr) /* ---------------------------------------------------------------------- */ { - //int k, j; LDBLE n_tot, n_tot1; /* @@ -2944,7 +2956,7 @@ reset(void) * Updates unknowns with deltas */ - int i, j; + int i; int converge; LDBLE up, down; LDBLE d; @@ -2957,7 +2969,7 @@ reset(void) /* * Calculate interphase mass transfers */ - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); cxxPPassemblageComp * comp_ptr; step_up = log(step_size_now); @@ -3294,10 +3306,11 @@ reset(void) /* surface */ if (x[i]->type == SURFACE) { + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); old_moles = x[i]->moles; if (x[i]->phase_unknown != NULL) { - x[i]->moles = x[i]->surface_comp->phase_proportion * + x[i]->moles = comp_ptr->Get_phase_proportion() * (x[i]->phase_unknown->moles - delta[x[i]->phase_unknown->number]); if (x[i]->phase_unknown->moles - @@ -3315,7 +3328,7 @@ reset(void) x[i]->master[0]->s->la = log10(x[i]->moles) - 5.; } } - else if (x[i]->surface_comp->phase_name != NULL) + else if (comp_ptr->Get_phase_name().size() > 0) { /* probably initial surface calculation */ if (x[i]->moles <= MIN_RELATED_SURFACE) @@ -3359,21 +3372,22 @@ reset(void) || x[i]->type == SURFACE_CB2) { d = delta[i] / LOG_10; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); if (x[i]->phase_unknown != NULL) { - x[i]->surface_charge->grams = /* !!!! x[i]->surface_comp->phase_proportion * */ + charge_ptr->Set_grams( (x[i]->phase_unknown->moles - - delta[x[i]->phase_unknown->number]); - if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) + delta[x[i]->phase_unknown->number])); + if (charge_ptr->Get_grams() <= MIN_RELATED_SURFACE) { - x[i]->surface_charge->grams = 0.0; + charge_ptr->Set_grams(0.0); } } - if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) + if (charge_ptr->Get_grams() <= MIN_RELATED_SURFACE) { - x[i]->surface_charge->grams = 0.0; + charge_ptr->Set_grams(0.0); } - x[i]->related_moles = x[i]->surface_charge->grams; + x[i]->related_moles = charge_ptr->Get_grams(); if (debug_model == TRUE) { output_msg(sformatf( @@ -3387,9 +3401,9 @@ reset(void) x[i]->master[0]->s->la += d; /* recalculate g's for component */ - if (dl_type_x != NO_DL - && (use.Get_surface_ptr()->type == DDL - || (use.Get_surface_ptr()->type == CD_MUSIC + if (dl_type_x != cxxSurface::NO_DL + && (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL + || (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC && x[i]->type == SURFACE_CB2))) { if (debug_diffuse_layer == TRUE) @@ -3398,30 +3412,30 @@ reset(void) "\ncharge, old g, new g, dg*delta," " dg, delta\n")); } - for (j = 0; j < x[i]->surface_charge->count_g; j++) + std::map::iterator jit; + for (jit = charge_ptr->Get_g_map().begin(); jit != charge_ptr->Get_g_map().end(); jit++) { if (debug_diffuse_layer == TRUE) { output_msg(sformatf( - "%12f\t%12.4e\t%12.4e\t%12.4e\t%12.4e\t%12.4e\n", - (double) x[i]->surface_charge->g[j]. - charge, - (double) x[i]->surface_charge->g[j].g, - (double) x[i]->surface_charge->g[j].g + - (double) (x[i]->surface_charge->g[j].dg * + "\t%12.4e\t%12.4e\t%12.4e\t%12.4e\t%12.4e\n", + + (double) jit->second.Get_g(), + (double) jit->second.Get_g() + + (double) (jit->second.Get_dg() * delta[i]), - (double) (x[i]->surface_charge->g[j].dg * + (double) (jit->second.Get_dg() * delta[i]), - (double) x[i]->surface_charge->g[j].dg, + (double) jit->second.Get_dg(), (double) delta[i])); } - if (use.Get_surface_ptr()->dl_type != DONNAN_DL) + if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) { - x[i]->surface_charge->g[j].g += - x[i]->surface_charge->g[j].dg * delta[i]; + jit->second.Set_g(jit->second.Get_g() + + jit->second.Get_dg() * delta[i]); } } - if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + if (use.Get_surface_ptr()->Get_dl_type() == cxxSurface::DONNAN_DL) { calc_all_donnan(); } @@ -3463,8 +3477,6 @@ reset(void) } else if (x[i]->type == MU) { - - /*if (fabs(delta[i]) > epsilon * mu_x ) converge=FALSE; */ // using straight ionic strength equation { mu_calc = 0.5 * mu_unknown->f / mass_water_aq_x; @@ -3494,7 +3506,6 @@ reset(void) k_temp(tc_x, patm_x); } } - //if (mu_x > 50) mu_x = 50; if (mu_x <= 1e-8) { mu_x = 1e-8; @@ -3553,7 +3564,7 @@ reset(void) mass_water_aq_x *= d; mass_water_bulk_x = mass_water_aq_x + mass_water_surfaces_x; - if (debug_model == TRUE && dl_type_x != NO_DL) + if (debug_model == TRUE && dl_type_x != cxxSurface::NO_DL) { output_msg(sformatf( "mass_water bulk: %e\taq: %e\tsurfaces: %e\n", @@ -3565,7 +3576,7 @@ reset(void) /*appt */ if (use.Get_surface_ptr() != NULL) { - if (use.Get_surface_ptr()->debye_lengths > 0) + if (use.Get_surface_ptr()->Get_debye_lengths() > 0) x[i]->master[0]->s->moles = mass_water_bulk_x / gfw_water; } @@ -3612,7 +3623,7 @@ reset(void) } else if (x[i]->type == GAS_MOLES) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ /*if (gas_in == TRUE && fabs(residual[i]) > epsilon) converge=FALSE; */ if (debug_model == TRUE) @@ -3707,7 +3718,6 @@ reset(void) converge = FALSE; return (converge); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: residuals(void) @@ -3726,8 +3736,8 @@ residuals(void) struct master *master_ptr, *master_ptr1, *master_ptr2; LDBLE sigmaddl, negfpsirt; int print_fail; - - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + std::vector cd_psi; + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); print_fail = FALSE; sum_residual = 0.0; sigmaddl = 0; @@ -3793,7 +3803,7 @@ residuals(void) converge = FALSE; } } - else if (x[i]->type == MU && pitzer_model == FALSE && sit_model == FALSE) + else if (x[i]->type == MU /*&& pitzer_model == FALSE && sit_model == FALSE*/) { // Using straight ionic strength equation { @@ -3810,7 +3820,6 @@ residuals(void) } else if (x[i]->type == AH2O) { - /*if (pitzer_model == TRUE && full_pitzer == FALSE) continue; */ if (dampen_ah2o) { // a = 0.017; Y = sum(m(i)); X = Mw (mass of water) @@ -3840,6 +3849,15 @@ residuals(void) "Failed Residual %d: %s %d %e\n", iterations, x[i]->description, i, residual[i])); converge = FALSE; +#ifndef PHREEQC2 + ah2o_x = exp(s_h2o->la * LOG_10); + /* recalculate k's if pressure changes > 0.005 atm by ah2o change... */ + if ((use.Get_solution_ptr()->Get_patm() < p_sat && fabs(patm_x - p_sat) > 5e-3) || + fabs(ah2o_x - ah2o_x0) > (5e-3 / p_sat)) + { + k_temp(tc_x, patm_x); + } +#endif } } else if (x[i]->type == MH @@ -3959,7 +3977,7 @@ residuals(void) } else if (x[i]->type == GAS_MOLES) { - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) { @@ -3967,7 +3985,6 @@ residuals(void) } else { - //residual[i] = x[i]->gas_phase->total_p - x[i]->f; residual[i] = gas_phase_ptr->Get_total_p() - x[i]->f; } @@ -3983,8 +4000,6 @@ residuals(void) else if (x[i]->type == SS_MOLES) { residual[i] = x[i]->f * LOG_10; - //if (x[i]->moles <= MIN_TOTAL_SS && iterations > 2) - // continue; if (fabs(residual[i]) > l_toler && x[i]->ss_in == TRUE) { if (print_fail) @@ -4062,18 +4077,19 @@ residuals(void) converge = FALSE; } } - else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->type == DDL) + else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { /*sinh_constant = 0.1174; */ sinh_constant = sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); /* if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { */ - if (x[i]->surface_charge->grams == 0) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() == 0) { residual[i] = 0.0; } - else if (dl_type_x != NO_DL) + else if (dl_type_x != cxxSurface::NO_DL) { residual[i] = -x[i]->f; } @@ -4087,13 +4103,13 @@ residuals(void) residual[i] = sinh_constant * sqrt(mu_x) * sinh(x[i]->master[0]->s->la * LOG_10) - - x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + x[i]->f * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()); } if (debug_model == TRUE) { output_msg(sformatf( "Charge/Potential\n")); - if (x[i]->surface_charge->grams > 0) + if (charge_ptr->Get_grams() > 0) { output_msg(sformatf( "\tSum of surface charge %e eq\n", @@ -4107,10 +4123,10 @@ residuals(void) (double) x[i]->f)); } output_msg(sformatf( "\t grams %g\n", - (double) x[i]->surface_charge->grams)); + (double) charge_ptr->Get_grams())); output_msg(sformatf( "\tCharge from potential %e eq\n", - (double) (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams / F_C_MOL * + (double) (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams() / F_C_MOL * sinh_constant * sqrt(mu_x) * sinh(x[i]->master[0]->s->la * LOG_10)))); output_msg(sformatf( "\t FPsi/2RT %e\n", @@ -4122,7 +4138,7 @@ residuals(void) output_msg(sformatf( "\t Sqrt(mu_x) %e\n", sqrt(mu_x))); } - if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + if (charge_ptr->Get_grams() > MIN_RELATED_SURFACE && fabs(residual[i]) > l_toler) { if (print_fail) @@ -4133,9 +4149,10 @@ residuals(void) } } else if (x[i]->type == SURFACE_CB - && use.Get_surface_ptr()->type == CD_MUSIC) + && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - if (x[i]->surface_charge->grams == 0) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() == 0) { residual[i] = 0.0; } @@ -4144,23 +4161,23 @@ residuals(void) /* sum is in moles of charge */ /*psi = pow(10, x[i]->surface_charge->psi_master->s->la); */ /* = exp(-Fpsi/RT) */ master_ptr = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI); master_ptr1 = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI1); master_ptr2 = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI2); - x[i]->surface_charge->psi = - -(master_ptr->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / - F_KJ_V_EQ; - x[i]->surface_charge->psi1 = - -(master_ptr1->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / - F_KJ_V_EQ; - x[i]->surface_charge->psi2 = - -(master_ptr2->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / - F_KJ_V_EQ; + + cd_psi.clear(); + + cd_psi.push_back(-(master_ptr->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ); + cd_psi.push_back(-(master_ptr1->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ); + cd_psi.push_back(-(master_ptr2->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x / + F_KJ_V_EQ); sum = 0; for (j = 0; j < x[i]->count_comp_unknowns; j++) { @@ -4168,18 +4185,18 @@ residuals(void) x[i]->comp_unknowns[j]->moles * x[i]->comp_unknowns[j]->master[0]->s->z; } - x[i]->surface_charge->sigma0 = + charge_ptr->Set_sigma0( (x[i]->f + - sum) * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + sum) * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())); /* f is in moles */ /* eqns A-3 */ residual[i] = - x[i]->surface_charge->sigma0 - - x[i]->surface_charge->capacitance[0] * - (x[i]->surface_charge->psi - x[i]->surface_charge->psi1); + charge_ptr->Get_sigma0() - + charge_ptr->Get_capacitance0() * + (cd_psi[0] - cd_psi[1]); } - if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + if (charge_ptr->Get_grams() > MIN_RELATED_SURFACE && fabs(residual[i]) > l_toler) { if (print_fail) @@ -4191,7 +4208,8 @@ residuals(void) } else if (x[i]->type == SURFACE_CB1) { - if (x[i]->surface_charge->grams == 0) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() == 0) { residual[i] = 0.0; } @@ -4199,16 +4217,16 @@ residuals(void) { /* eqns A-4 */ /*psi = pow(10, x[i]->surface_charge->psi_master1->s->la); */ /* = exp(-Fpsi/RT) */ - x[i]->surface_charge->sigma1 = - x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + charge_ptr->Set_sigma1( + x[i]->f * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())); residual[i] = - (x[i]->surface_charge->sigma0 + - x[i]->surface_charge->sigma1) - - x[i]->surface_charge->capacitance[1] * - (x[i]->surface_charge->psi1 - x[i]->surface_charge->psi2); + (charge_ptr->Get_sigma0() + + charge_ptr->Get_sigma1()) - + charge_ptr->Get_capacitance1() * + (cd_psi[1] - cd_psi[2]); } - if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + if (charge_ptr->Get_grams() > MIN_RELATED_SURFACE && fabs(residual[i]) > l_toler) { if (print_fail) @@ -4220,11 +4238,12 @@ residuals(void) } else if (x[i]->type == SURFACE_CB2) { - if (x[i]->surface_charge->grams == 0) + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() == 0) { residual[i] = 0.0; } - else if (dl_type_x != NO_DL) + else if (dl_type_x != cxxSurface::NO_DL) { sum = 0; sum1 = 0; @@ -4236,22 +4255,23 @@ residuals(void) } if (s_x[j]->type < H2O) { - sum1 += s_x[j]->z * s_x[j]->diff_layer->g_moles; + int is = s_x[j]->number; + sum1 += s_x[j]->z * s_x[j]->z * s_diff_layer[is][charge_ptr->Get_name()].Get_g_moles(); } } - x[i]->surface_charge->sigma2 = - sum * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); - x[i]->surface_charge->sigmaddl = + charge_ptr->Set_sigma2( + sum * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())); + charge_ptr->Set_sigmaddl( (x[i]->f - - sum) * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + sum) * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())); residual[i] = - x[i]->f + (x[i]->surface_charge->sigma0 + - x[i]->surface_charge->sigma1) * - (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams) / F_C_MOL; + x[i]->f + (charge_ptr->Get_sigma0() + + charge_ptr->Get_sigma1()) * + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL; /* residual[i] = sum + (x[i]->surface_charge->sigma0 + x[i]->surface_charge->sigma1) * (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams) / F_C_MOL */ } else @@ -4266,7 +4286,7 @@ residuals(void) * ~ 0.1174 at 25C */ master_ptr2 = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI2); negfpsirt = master_ptr2->s->la * LOG_10; sum = 0; @@ -4298,9 +4318,9 @@ residuals(void) } /*output_msg(sformatf( "Negative sum, iteration %d\n", iterations)); */ } - x[i]->surface_charge->sigma2 = - x[i]->f * F_C_MOL / (x[i]->surface_charge->specific_area * - x[i]->surface_charge->grams); + charge_ptr->Set_sigma2( + x[i]->f * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())); if ((negfpsirt) < 0) { sigmaddl = -0.5 * sinh_constant * sqrt(sum); @@ -4309,29 +4329,29 @@ residuals(void) { sigmaddl = 0.5 * sinh_constant * sqrt(sum); } - x[i]->surface_charge->sigmaddl = sigmaddl; + charge_ptr->Set_sigmaddl(sigmaddl); residual[i] = - (x[i]->surface_charge->sigma0 + - x[i]->surface_charge->sigma1 + - x[i]->surface_charge->sigma2) + sigmaddl; + (charge_ptr->Get_sigma0() + + charge_ptr->Get_sigma1() + + charge_ptr->Get_sigma2()) + sigmaddl; } if (debug_model == TRUE) { master_ptr = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI); master_ptr1 = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI1); master_ptr2 = - surface_get_psi_master(x[i]->surface_charge->name, + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI2); output_msg(sformatf( "CD_music Charge/Potential 2\n")); output_msg(sformatf( "\tgrams %g\n", - (double) x[i]->surface_charge->grams)); + (double) charge_ptr->Get_grams())); output_msg(sformatf( "\tCapacitances %g\t%g\n", - (double) x[i]->surface_charge->capacitance[0], - x[i]->surface_charge->capacitance[1])); + (double) charge_ptr->Get_capacitance0(), + charge_ptr->Get_capacitance1())); output_msg(sformatf( "\t-F/(RT) %g\n", (double) -F_KJ_V_EQ / (R_KJ_DEG_MOL * tk_x))); output_msg(sformatf( "\tResidual 0 %14e\n", @@ -4343,34 +4363,34 @@ residuals(void) output_msg(sformatf( "\texp(-FPsi0/RT) %14e", (double) pow((LDBLE) 10., master_ptr->s->la))); output_msg(sformatf( "\tPsi0 %14e\n", - (double) x[i]->surface_charge->psi)); + (double) cd_psi[0])); output_msg(sformatf( "\texp(-FPsi1/RT) %14e", (double) pow((LDBLE) 10., master_ptr1->s->la))); output_msg(sformatf( "\tPsi1 %14e\n", - (double) x[i]->surface_charge->psi1)); + (double) cd_psi[1])); output_msg(sformatf( "\texp(-FPsi2/RT) %14e", (double) pow((LDBLE) 10., master_ptr2->s->la))); output_msg(sformatf( "\tPsi2 %14e\n", - (double) x[i]->surface_charge->psi2)); + (double) cd_psi[2])); output_msg(sformatf( "\tf 0 %14e", (double) master_ptr->unknown->f)); output_msg(sformatf( "\tsigma 0 %14e\n", - (double) x[i]->surface_charge->sigma0)); + (double) charge_ptr->Get_sigma0())); output_msg(sformatf( "\tf 1 %14e", (double) master_ptr1->unknown->f)); output_msg(sformatf( "\tsigma 1 %14e\n", - (double) x[i]->surface_charge->sigma1)); + (double) charge_ptr->Get_sigma1())); output_msg(sformatf( "\tf 2 %14e", (double) master_ptr2->unknown->f)); output_msg(sformatf( "\tsigma 2 %14e\n", - (double) x[i]->surface_charge->sigma2)); + (double) charge_ptr->Get_sigma2())); output_msg(sformatf( "\tsigma ddl %14e\n", (double) sigmaddl)); output_msg(sformatf( "\texp sum %14e\n", (double) sum)); } - if (x[i]->surface_charge->grams > MIN_RELATED_SURFACE + if (charge_ptr->Get_grams() > MIN_RELATED_SURFACE && fabs(residual[i]) > l_toler) { if (print_fail) @@ -4408,7 +4428,7 @@ set(int initial) * Revises guesses whether initial is true or not */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; /* * Set initial log concentrations to zero */ @@ -4427,25 +4447,28 @@ set(int initial) * Set master species activities */ - tc_x = solution_ptr->tc; + tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; - - patm_x = solution_ptr->patm; +#ifdef PHREEQC2 + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) +#else + //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) +#endif /* * H+, e-, H2O */ - mass_water_aq_x = solution_ptr->mass_water; - mu_x = solution_ptr->mu; + mass_water_aq_x = solution_ptr->Get_mass_water(); + mu_x = solution_ptr->Get_mu(); s_h2o->moles = mass_water_aq_x / gfw_water; - s_h2o->la = log10(solution_ptr->ah2o); - s_hplus->la = -solution_ptr->ph; + s_h2o->la = log10(solution_ptr->Get_ah2o()); + s_hplus->la = -solution_ptr->Get_ph(); s_hplus->lm = s_hplus->la; s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; - s_eminus->la = -solution_ptr->solution_pe; + s_eminus->la = -solution_ptr->Get_pe(); if (initial == TRUE) initial_guesses(); - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) initial_surface_water(); revise_guesses(); return (OK); @@ -4461,12 +4484,12 @@ initial_guesses(void) * ionic strength */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; solution_ptr = use.Get_solution_ptr(); mu_x = s_hplus->moles + - exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + exp((solution_ptr->Get_ph() - 14.) * LOG_10) * mass_water_aq_x; mu_x /= mass_water_aq_x; s_h2o->la = 0.0; for (i = 0; i < count_unknowns; i++) @@ -4534,6 +4557,9 @@ revise_guesses(void) LDBLE d; max_iter = 10; +#ifndef PHREEQC2 + same_mu = false; +#endif gammas(mu_x); l_iter = 0; repeat = TRUE; @@ -4690,6 +4716,9 @@ revise_guesses(void) { mu_x = 1e-8; } +#ifndef PHREEQC2 + same_mu = false; +#endif gammas(mu_x); return (OK); } @@ -4715,7 +4744,11 @@ sum_species(void) */ ph_x = -s_hplus->la; solution_pe_x = -s_eminus->la; +#ifdef PHREEQC2 ah2o_x = exp(s_h2o->la * LOG_10); +#else + //ah2o_x = exp(s_h2o->la * LOG_10); +#endif density_x = 1.0; if (s_o2 != NULL) s_o2->moles = under(s_o2->lm) * mass_water_aq_x; @@ -4749,7 +4782,7 @@ sum_species(void) if (use.Get_surface_ptr() != NULL) { - if (use.Get_surface_ptr()->debye_lengths > 0 && state >= REACTION + if (use.Get_surface_ptr()->Get_debye_lengths() > 0 && state >= REACTION && s_x[i]->type == H2O) { total_h_x -= 2 * mass_water_surfaces_x / gfw_water; @@ -4812,7 +4845,6 @@ sum_species(void) calculate_values(); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: surface_model(void) @@ -4821,8 +4853,8 @@ surface_model(void) /* * Use extra iterative loop to converge on g_factors */ - int i, n, debug_diffuse_layer_save, debug_model_save; - struct solution *solution_ptr; + int i, debug_diffuse_layer_save, debug_model_save; + cxxSolution *solution_ptr; LDBLE prev_aq_x; /* * Allocate space for g factors for diffuse layer in surface complexation @@ -4837,48 +4869,48 @@ surface_model(void) { same_model = check_same_model(); } - if (dl_type_x != NO_DL && same_model == FALSE) + if (dl_type_x != cxxSurface::NO_DL && same_model == FALSE) { + s_diff_layer.clear(); for (i = 0; i < count_s; i++) { - s[i]->diff_layer = - (struct species_diff_layer *) free_check_null(s[i]-> - diff_layer); - s[i]->diff_layer = - (struct species_diff_layer *) PHRQ_malloc((size_t) use.Get_surface_ptr()-> - count_charge * - sizeof(struct - species_diff_layer)); - if (s[i]->diff_layer == NULL) - malloc_error(); + std::map < std::string, cxxSpeciesDL > dl; + s_diff_layer.push_back(dl); + for (size_t j = 0; j < use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSpeciesDL species_dl; + std::string name = use.Get_surface_ptr()->Get_surface_charges()[j].Get_name(); + s_diff_layer.back()[name] = species_dl; + } } } - if (state >= REACTION && dl_type_x != NO_DL) + if (state >= REACTION && dl_type_x != cxxSurface::NO_DL) { if (use.Get_mix_ptr() != NULL) { mass_water_bulk_x = 0.0; std::map::const_iterator cit; - for (cit = (( cxxMix *) use.Get_mix_ptr())->Get_mixComps().begin(); cit != (( cxxMix *) use.Get_mix_ptr())->Get_mixComps().end(); cit++) + for (cit = use.Get_mix_ptr()->Get_mixComps().begin(); cit != use.Get_mix_ptr()->Get_mixComps().end(); cit++) { - solution_ptr = solution_bsearch(cit->first, &n, TRUE); - mass_water_bulk_x += solution_ptr->mass_water * cit->second; + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, cit->first); + mass_water_bulk_x += solution_ptr->Get_mass_water() * cit->second; } } else { - mass_water_bulk_x = use.Get_solution_ptr()->mass_water; + mass_water_bulk_x = use.Get_solution_ptr()->Get_mass_water(); } - for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) { - mass_water_bulk_x += use.Get_surface_ptr()->charge[i].mass_water; - if (use.Get_surface_ptr()->debye_lengths > 0) - use.Get_surface_ptr()->charge[i].mass_water = 0.0; + cxxSurfaceCharge *charge_ptr = &(use.Get_surface_ptr()->Get_surface_charges()[i]); + mass_water_bulk_x += charge_ptr->Get_mass_water(); + if (use.Get_surface_ptr()->Get_debye_lengths() > 0) + charge_ptr->Set_mass_water(0.0); } } prep(); k_temp(tc_x, patm_x); - if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + if (use.Get_surface_ptr()->Get_dl_type() == cxxSurface::DONNAN_DL) { initial_surface_water(); calc_init_donnan(); @@ -4887,7 +4919,7 @@ surface_model(void) { calc_init_g(); } - if (state >= REACTION && use.Get_surface_ptr()->new_def == FALSE) + if (state >= REACTION && !use.Get_surface_ptr()->Get_new_def()) { set(FALSE); } @@ -4899,20 +4931,23 @@ surface_model(void) return (ERROR); g_iterations = 0; - if (use.Get_surface_ptr()->dl_type == DONNAN_DL) + if (use.Get_surface_ptr()->Get_dl_type() == cxxSurface::DONNAN_DL) { do { g_iterations++; prev_aq_x = mass_water_aq_x; +#ifndef PHREEQC2 + same_mu = false; +#endif k_temp(tc_x, patm_x); gammas(mu_x); molalities(TRUE); mb_sums(); if (model() == ERROR) return (ERROR); - if (use.Get_surface_ptr()->related_phases != TRUE - && use.Get_surface_ptr()->related_rate != TRUE) + if (!use.Get_surface_ptr()->Get_related_phases() + && !use.Get_surface_ptr()->Get_related_rate()) initial_surface_water(); if (debug_model == TRUE) { @@ -4935,14 +4970,18 @@ surface_model(void) debug_model = TRUE; debug_diffuse_layer = TRUE; } +#ifndef PHREEQC2 + same_mu = false; +#else k_temp(tc_x, patm_x); +#endif gammas(mu_x); molalities(TRUE); mb_sums(); if (model() == ERROR) return (ERROR); - if (use.Get_surface_ptr()->related_phases != TRUE - && use.Get_surface_ptr()->related_rate != TRUE) + if (!use.Get_surface_ptr()->Get_related_phases() + && !use.Get_surface_ptr()->Get_related_rate()) initial_surface_water(); if (debug_model == TRUE) { @@ -4966,7 +5005,6 @@ surface_model(void) debug_model = debug_model_save; return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: free_model_allocs(void) @@ -4995,7 +5033,6 @@ free_model_allocs(void) sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); sum_delta = (struct list2 *) free_check_null(sum_delta); - charge_group = (struct Charge_Group *) free_check_null(charge_group); return (OK); } @@ -5140,16 +5177,19 @@ numerical_jacobian(void) LDBLE *base; LDBLE d, d1, d2; int i, j; - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (! (numerical_deriv || - (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->type == CD_MUSIC) || + (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) || (gas_phase_ptr != NULL && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) )) return(OK); calculating_deriv = TRUE; +#ifndef PHREEQC2 + same_mu = false; +#endif gammas(mu_x); molalities(TRUE); mb_sums(); @@ -5214,6 +5254,10 @@ numerical_jacobian(void) case MU: d2 = d * mu_x; mu_x += d2; +#ifndef PHREEQC2 + if (fabs(d2 / mu_x) > 1e-3) + same_mu = false; +#endif gammas(mu_x); break; case PP: @@ -5289,7 +5333,7 @@ numerical_jacobian(void) { /*output_msg(sformatf( "Zero diagonal for MH\n")); */ array[i * (count_unknowns + 1) + i] = - exp(s_h2->lm * LOG_10) * 2; + under(s_h2->lm) * 2; } break; case PITZER_GAMMA: @@ -5301,6 +5345,10 @@ numerical_jacobian(void) break; case MU: mu_x -= d2; +#ifndef PHREEQC2 + if (fabs(d2 / mu_x) > 1e-3) + same_mu = false; +#endif gammas(mu_x); break; case PP: @@ -5407,7 +5455,7 @@ set_inert_moles(void) { int j; if (use.Get_pp_assemblage_ptr() == NULL) return; - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (j = 0; j < count_unknowns; j++) { @@ -5427,7 +5475,7 @@ unset_inert_moles() { int j; if (use.Get_pp_assemblage_ptr() == NULL) return; - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (j = 0; j < count_unknowns; j++) { if (x[j]->type != PP) continue; diff --git a/phreeqc/phqalloc.cpp b/phreeqc/phqalloc.cpp index 3746b942..52da5482 100644 --- a/phreeqc/phqalloc.cpp +++ b/phreeqc/phqalloc.cpp @@ -111,9 +111,6 @@ PHRQ_free_all(void) ostrm << s_pTail->pNext->szFileName << "(" << s_pTail->pNext->nLine; ostrm << ") " << (void *) (s_pTail->pNext + 1) << ": freed in PHRQ_free_all\n"; output_msg(ostrm.str().c_str()); - //output_msg(sformatf("%s(%d) %p: freed in PHRQ_free_all\n", - // s_pTail->pNext->szFileName, s_pTail->pNext->nLine, - // (void *) (s_pTail->pNext + 1))); free(s_pTail->pNext->szFileName); #endif free(s_pTail->pNext); @@ -124,8 +121,6 @@ PHRQ_free_all(void) ostrm << s_pTail->szFileName << "(" << s_pTail->nLine; ostrm << ") " << (void *) (s_pTail + 1) << ": freed in PHRQ_free_all\n"; output_msg(ostrm.str().c_str()); - //output_msg(sformatf( "%s(%d) %p: freed in PHRQ_free_all\n", - // s_pTail->szFileName, s_pTail->nLine, (void *) (s_pTail + 1))); free(s_pTail->szFileName); #endif free(s_pTail); diff --git a/phreeqc/pitzer.cpp b/phreeqc/pitzer.cpp index 604d6f7e..78d1e558 100644 --- a/phreeqc/pitzer.cpp +++ b/phreeqc/pitzer.cpp @@ -1,6 +1,7 @@ #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" +#include "Solution.h" #define PITZER @@ -941,6 +942,7 @@ pitzer(void) } } I = XI / 2.0e0; + I = mu_x; // Added equation for MU /* C C EQUATION (8) @@ -1382,7 +1384,7 @@ set_pz(int initial) * Revises guesses whether initial is true or not */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; /* * Set initial log concentrations to zero */ @@ -1404,24 +1406,28 @@ set_pz(int initial) * Set master species activities */ - tc_x = solution_ptr->tc; + tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; - patm_x = solution_ptr->patm; +#ifdef PHREEQC2 + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) +#else + //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) +#endif /* * H+, e-, H2O */ - mass_water_aq_x = solution_ptr->mass_water; - mu_x = solution_ptr->mu; + mass_water_aq_x = solution_ptr->Get_mass_water(); + mu_x = solution_ptr->Get_mu(); s_h2o->moles = mass_water_aq_x / gfw_water; - s_h2o->la = log10(solution_ptr->ah2o); + s_h2o->la = log10(solution_ptr->Get_ah2o()); AW = pow((LDBLE) 10.0, s_h2o->la); - s_hplus->la = -solution_ptr->ph; + s_hplus->la = -solution_ptr->Get_ph(); s_hplus->lm = s_hplus->la; s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; - s_eminus->la = -solution_ptr->solution_pe; + s_eminus->la = -solution_ptr->Get_pe(); if (initial == TRUE) pitzer_initial_guesses(); - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) initial_surface_water(); pitzer_revise_guesses(); return (OK); @@ -1437,12 +1443,12 @@ pitzer_initial_guesses(void) * ionic strength */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; solution_ptr = use.Get_solution_ptr(); mu_x = s_hplus->moles + - exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + exp((solution_ptr->Get_ph() - 14.) * LOG_10) * mass_water_aq_x; mu_x /= mass_water_aq_x; s_h2o->la = 0.0; for (i = 0; i < count_unknowns; i++) @@ -1732,6 +1738,10 @@ Restart: x[i]->moles += d2; break; case MU: + d2 = d * mu_x; + mu_x += d2; + gammas(mu_x); + break; case PP: case SS_MOLES: continue; @@ -1781,6 +1791,10 @@ Restart: mass_water_aq_x /= (1 + d); x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; break; + case MU: + mu_x -= d2; + gammas(mu_x); + break; case GAS_MOLES: if (gas_in == FALSE) continue; @@ -1946,8 +1960,8 @@ model_pz(void) } molalities(TRUE); if (use.Get_surface_ptr() != NULL && - use.Get_surface_ptr()->dl_type != NO_DL && - use.Get_surface_ptr()->related_phases == TRUE) + use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && + use.Get_surface_ptr()->Get_related_phases()) initial_surface_water(); mb_sums(); mb_gases(); @@ -2188,8 +2202,7 @@ gammas_pz() { s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); } - //if (use.Get_exchange_ptr()->pitzer_exchange_gammas == TRUE) - if (((cxxExchange *) use.Get_exchange_ptr())->Get_pitzer_exchange_gammas()) + if (use.Get_exchange_ptr()->Get_pitzer_exchange_gammas()) { /* Assume equal gamma's of solute and exchangeable species... */ for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index d9d14314..b71073dd 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -8,6 +8,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "SS.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: prep(void) @@ -23,7 +24,7 @@ prep(void) * Routine builds a set of lists for calculating mass balance and * for building jacobian. */ - struct solution *solution_ptr; + cxxSolution *solution_ptr; if (state >= REACTION) { @@ -45,7 +46,7 @@ prep(void) STOP); } description_x = (char *) free_check_null(description_x); - description_x = string_duplicate(solution_ptr->description); + description_x = string_duplicate(solution_ptr->Get_description().c_str()); /* * Allocate space for unknowns * Must allocate all necessary space before pointers to @@ -136,9 +137,7 @@ quick_setup(void) * been accumulated in array master, usually by subroutine step. * Updates essential information for the model. */ - int i, j, k, l; - char token[MAX_LENGTH], name[MAX_LENGTH]; - + int i, j, k; for (i = 0; i < count_master; i++) { if (master[i]->s->type == SURF_PSI) @@ -163,7 +162,7 @@ quick_setup(void) /* * Reaction: pH for charge balance */ - ph_unknown->moles = use.Get_solution_ptr()->cb; + ph_unknown->moles = use.Get_solution_ptr()->Get_cb(); /* * Reaction: pe for total hydrogen */ @@ -174,7 +173,7 @@ quick_setup(void) /*#define COMBINE_CHARGE */ #ifdef COMBINE mass_hydrogen_unknown->moles = - use.Get_solution_ptr()->total_h - 2 * use.Get_solution_ptr()->total_o; + use.Get_solution_ptr()->Get_total_h() - 2 * use.Get_solution_ptr()->Get_total_o(); #else mass_hydrogen_unknown->moles = use.Get_solution_ptr()->total_h; #endif @@ -184,7 +183,7 @@ quick_setup(void) */ if (mass_oxygen_unknown != NULL) { - mass_oxygen_unknown->moles = use.Get_solution_ptr()->total_o; + mass_oxygen_unknown->moles = use.Get_solution_ptr()->Get_total_o(); } /* @@ -195,7 +194,7 @@ quick_setup(void) { if (x[i]->type == PP) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); std::map::iterator it; it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); @@ -218,25 +217,20 @@ quick_setup(void) */ if (gas_unknown != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if ((gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) && numerical_fixed_volume && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume)) { - //for (i = 0; i < use.Get_gas_phase_ptr()->count_comps; i++) - //{ for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); - //int k; - //struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); gas_unknowns[i]->moles = gc_ptr->Get_moles(); if (gas_unknowns[i]->moles <= 0) gas_unknowns[i]->moles = MIN_TOTAL; gas_unknowns[i]->phase->pr_in = false; gas_unknowns[i]->phase->pr_phi = 1.0; gas_unknowns[i]->phase->pr_p = 0; - //gas_unknowns[i]->gas_phase = use.Get_gas_phase_ptr(); } same_pressure = FALSE; } @@ -251,7 +245,6 @@ quick_setup(void) if (gas_unknown->moles <= 0) gas_unknown->moles = MIN_TOTAL; gas_unknown->ln_moles = log(gas_unknown->moles); - //gas_unknown->gas_phase = gas_phase_ptr; } } @@ -312,13 +305,13 @@ quick_setup(void) { if (x[i]->type == SURFACE_CB) { - x[i]->surface_charge = &(use.Get_surface_ptr()->charge[j]); - x[i]->related_moles = x[i]->surface_charge->grams; - x[i]->mass_water = use.Get_surface_ptr()->charge[j++].mass_water; - x[i]->surface_comp = x[i - 1]->surface_comp; - + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + x[i]->related_moles = charge_ptr->Get_grams(); + x[i]->mass_water = charge_ptr->Get_mass_water(); +#ifdef DEBUG /* test that charge and surface match */ - char * temp_formula = string_duplicate(x[i]->surface_comp->formula); + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); char * ptr = temp_formula; copy_token(token, &ptr, &l); char * ptr1 = token; @@ -326,48 +319,42 @@ quick_setup(void) ptr1 = strchr(name, '_'); if (ptr1 != NULL) ptr1[0] = '\0'; - if (strcmp(name, x[i]->surface_charge->name) != 0) + if (strcmp(name, charge_ptr->Get_name().c_str()) != 0) { free_check_null(temp_formula); error_string = sformatf( "Internal error: Surface charge name %s does not match surface component name %s\nTry alphabetical order for surfaces in SURFACE", - x[i]->surface_charge->name, - x[i]->surface_comp->formula); + charge_ptr->Get_name().c_str(), + comp_ptr->Get_formula().c_str()); error_msg(error_string, STOP); } free_check_null(temp_formula); - +#endif /* moles picked up from master->total */ } else if (x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) { - /* - charge = use.Get_surface_ptr()->comps[i].charge; - x[count_unknowns]->surface_charge = &use.Get_surface_ptr()->charge[charge]; - */ - x[i]->surface_charge = x[i - 1]->surface_charge; - x[i]->related_moles = x[i]->surface_charge->grams; - x[i]->mass_water = x[i]->surface_charge->mass_water; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + x[i]->related_moles = charge_ptr->Get_grams(); + x[i]->mass_water = charge_ptr->Get_mass_water(); } else if (x[i]->type == SURFACE) { - x[i]->surface_comp = &(use.Get_surface_ptr()->comps[k++]); /* moles picked up from master->total except for surfaces related to kinetic minerals ... */ - if (x[i]->surface_comp->rate_name != NULL) + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + if (comp_ptr->Get_rate_name().size() > 0) { - for (l = 0; x[i]->surface_comp->totals[l].elt != NULL; - l++) + cxxNameDouble::iterator lit; + for (lit = comp_ptr->Get_totals().begin(); lit != comp_ptr->Get_totals().end(); lit++) { - if (x[i]->surface_comp->totals[l].elt->master->type != - SURF) + struct element *elt_ptr = element_store(lit->first.c_str()); + struct master *master_ptr = elt_ptr->master; + if (master_ptr->type != SURF) continue; - if (strcmp_nocase - (x[i]->description, - x[i]->surface_comp->totals[l].elt->name) == 0) + if (strcmp_nocase(x[i]->description, lit->first.c_str()) == 0) { - x[i]->moles = x[i]->surface_comp->totals[l].coef; - /* printf("%s moles %e\n", x[i]->description, x[i]->moles); */ + x[i]->moles = lit->second; } } } @@ -393,18 +380,15 @@ build_gas_phase(void) * sum of partial pressures equation and * mass balance equations for elements contained in gases */ - //int i, j; int row, col; struct master *master_ptr; struct rxn_token *rxn_ptr; - //struct gas_comp *gas_comp_ptr; - //struct phase *phase_ptr; struct unknown *unknown_ptr; LDBLE coef, coef_elt; if (gas_unknown == NULL) return (OK); - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) @@ -538,8 +522,6 @@ build_gas_phase(void) "Element needed for gas component, %s, is not in model.", phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; continue; } if (debug_prep == TRUE) @@ -604,8 +586,6 @@ build_gas_phase(void) "Element in species, %s, in phase, %s, is not in model.", rxn_ptr->s->name, phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; } else { @@ -644,8 +624,6 @@ build_gas_phase(void) "Element, %s, in phase, %s, is not in model.", master_ptr->elt->name, phase_ptr->name); warning_msg(error_string); - //error_msg(error_string, CONTINUE); - //input_error++; } col = master_ptr->unknown->number; coef = rxn_ptr->coef; @@ -673,13 +651,10 @@ build_ss_assemblage(void) * mass action equation for component * mass balance equations for elements contained in solid solutions */ - //int i, j, k, l, stop; bool stop; int row, col; struct master *master_ptr; struct rxn_token *rxn_ptr; - //struct s_s *s_s_ptr, *s_s_ptr_old; - //char token[MAX_LENGTH]; char *ptr; if (ss_unknown == NULL) @@ -916,7 +891,7 @@ build_jacobian_sums(int k) /* * Add extra terms for change in dg/dx in diffuse layer model */ - if (s[k]->type >= H2O || dl_type_x == NO_DL) + if (s[k]->type >= H2O || dl_type_x == cxxSurface::NO_DL) { continue; } @@ -948,8 +923,8 @@ build_jacobian_sums(int k) { if (x[j]->type != SURFACE_CB) continue; - /*if (x[j]->type < SURFACE_CB || x[j]->type > SURFACE_CB1) continue; */ - source = &s[k]->diff_layer[count_g].dx_moles; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + source = s_diff_layer[k][charge_ptr->Get_name()].Get_dx_moles_address(); target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + x[j]->number]); store_jacob(source, target, coef); @@ -960,7 +935,7 @@ build_jacobian_sums(int k) mb_unknowns[i].unknown->number, x[j]->number)); } count_g++; - if (count_g >= use.Get_surface_ptr()->count_charge) + if (count_g >= (int) use.Get_surface_ptr()->Get_surface_charges().size()) break; } @@ -970,10 +945,10 @@ build_jacobian_sums(int k) { if (x[j]->type != SURFACE_CB) continue; - /*if (x[j]->type < SURFACE_CB || x[j]->type > SURFACE_CB1) continue; */ - + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); /* has related phase */ - if (x[j - 1]->surface_comp->phase_name == NULL) + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[j - 1]->surface_comp); + if (comp_ptr->Get_phase_name().size() == 0) continue; /* now find the related phase */ @@ -981,14 +956,13 @@ build_jacobian_sums(int k) { if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == - x[j - 1]->surface_comp->phase_name) + if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) break; } if (kk >= 0) { - source = &s[k]->diff_layer[count_g].drelated_moles; + source = s_diff_layer[k][charge_ptr->Get_name()].Get_drelated_moles_address(); target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + x[kk]->number]); store_jacob(source, target, coef); @@ -1002,7 +976,7 @@ build_jacobian_sums(int k) } } count_g++; - if (count_g >= use.Get_surface_ptr()->count_charge) + if (count_g >= (int) use.Get_surface_ptr()->Get_surface_charges().size()) break; } @@ -1014,9 +988,10 @@ build_jacobian_sums(int k) { if (x[j]->type != SURFACE_CB) continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); if (mb_unknowns[i].unknown->number == x[j]->number) { - source = &s[k]->diff_layer[count_g].dx_moles; + source = s_diff_layer[k][charge_ptr->Get_name()].Get_dx_moles_address(); target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + x[j]->number]); store_jacob(source, target, coef); @@ -1031,25 +1006,21 @@ build_jacobian_sums(int k) /* term for related phase */ /* has related phase */ - if (x[j - 1]->surface_comp->phase_name != NULL) + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[j - 1]->surface_comp); + if (comp_ptr->Get_phase_name().size() > 0) { - /* now find the related phase */ for (kk = count_unknowns - 1; kk >= 0; kk--) { if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == - x[j - 1]->surface_comp->phase_name) + if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) break; } if (kk >= 0) { - source = - &s[k]->diff_layer[count_g].drelated_moles; - target = - &(array - [mb_unknowns[i].unknown->number * + source = s_diff_layer[k][charge_ptr->Get_name()].Get_drelated_moles_address(); + target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + x[kk]->number]); store_jacob(source, target, coef); if (debug_prep == TRUE) @@ -1066,7 +1037,7 @@ build_jacobian_sums(int k) if (mass_oxygen_unknown != NULL) { /* term for water, for same surfaces */ - source = &s[k]->diff_layer[count_g].dh2o_moles; + source = s_diff_layer[k][charge_ptr->Get_name()].Get_dh2o_moles_address(); target = &(array[mb_unknowns[i].unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number]); @@ -1083,7 +1054,7 @@ build_jacobian_sums(int k) break; } count_g++; - if (count_g >= use.Get_surface_ptr()->count_charge) + if (count_g >= (int) use.Get_surface_ptr()->Get_surface_charges().size()) break; } } @@ -1328,7 +1299,7 @@ build_model(void) build_species_list(i); } } - if (dl_type_x != NO_DL && (pitzer_model == TRUE || sit_model == TRUE)) + if (dl_type_x != cxxSurface::NO_DL && (pitzer_model == TRUE || sit_model == TRUE)) { error_msg("-diffuse_layer option not available for Pizer or SIT model", STOP); @@ -1336,7 +1307,7 @@ build_model(void) /* * Sum diffuse layer water into hydrogen and oxygen mass balances */ - if (dl_type_x != NO_DL && state >= REACTION) + if (dl_type_x != cxxSurface::NO_DL && state >= REACTION) { for (i = 0; i < count_unknowns; i++) { @@ -1344,7 +1315,7 @@ build_model(void) { #ifndef COMBINE store_mb(&(x[i]->mass_water), - &(mass_hydrogen_unknown->f), 2 / gfw_water); + &(mass_hydrogen_unknwon->f), 2 / gfw_water); #endif if (mass_oxygen_unknown != NULL) { @@ -1394,7 +1365,7 @@ build_model(void) coef_e = trxn_find_coef("e-", 1); if (equal(coef_e, 0.0, TOL) == FALSE) { - trxn_add(pe_x[default_pe_x].rxn, coef_e, TRUE); + trxn_add(pe_x[default_pe_x.c_str()], coef_e, TRUE); } /* * Rewrite reaction to current master species @@ -1438,9 +1409,6 @@ build_pure_phases(void) * Includes calculation of inverse saturation index in sum_mb. * Puts coefficients in iap and mass balance equations for each phase. */ - //int i; - //int stop, j, k, l; - //char token[MAX_LENGTH]; bool stop; std::string token; char *ptr; @@ -1453,7 +1421,7 @@ build_pure_phases(void) if (pure_phase_unknown == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Calculate inverse saturation index */ @@ -1792,7 +1760,7 @@ clear(void) /* * Resets information for setting up a new model */ - struct solution *solution_ptr; + cxxSolution *solution_ptr; /* * Clear species solution-dependent data */ @@ -1805,9 +1773,18 @@ clear(void) /* * Set pe structure */ - pe_data_free(pe_x); - pe_x = pe_data_dup(solution_ptr->pe); - default_pe_x = solution_ptr->default_pe; + pe_x.clear(); + default_pe_x.clear(); + if (solution_ptr->Get_initial_data()) + { + pe_x = solution_ptr->Get_initial_data()->Get_pe_reactions(); + default_pe_x = solution_ptr->Get_initial_data()->Get_default_pe(); + } + else + { + default_pe_x = "pe"; + } + /* * Clear master species solution-dependent data */ @@ -1815,7 +1792,14 @@ clear(void) { master[i]->in = FALSE; master[i]->unknown = NULL; - master[i]->pe_rxn = &(pe_x[solution_ptr->default_pe].rxn); + if (solution_ptr->Get_initial_data()) + { + master[i]->pe_rxn = string_hsave(solution_ptr->Get_initial_data()->Get_default_pe().c_str()); + } + else + { + master[i]->pe_rxn = string_hsave("pe"); + } /* * copy primary reaction to secondary reaction */ @@ -1860,7 +1844,175 @@ clear(void) return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +convert_units(cxxSolution *solution_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Converts solution concentrations to moles/kg water + * Uses totals.input conc to calculate totals.moles. + */ + LDBLE sum_solutes; + struct master *master_ptr; + std::string token; + if (!solution_ptr->Get_new_def() || !solution_ptr->Get_initial_data()) + { + input_error++; + error_msg("Missing data for convert_units"); + } +/* + * Convert units + */ + sum_solutes = exp(-solution_ptr->Get_ph() * LOG_10); + cxxISolution *initial_data_ptr = solution_ptr->Get_initial_data(); + std::map::iterator jit = initial_data_ptr->Get_comps().begin(); + for ( ; jit != initial_data_ptr->Get_comps().end(); jit++) + { + cxxISolutionComp &comp_ref = jit->second; + LDBLE moles; + master_ptr = master_bsearch(comp_ref.Get_description().c_str()); + if (master_ptr != NULL) + { + if (master_ptr->minor_isotope == TRUE) + continue; + } + // initially store 0.0 for totals + solution_ptr->Get_totals()[comp_ref.Get_description()] = 0.0; + + if (strcmp(comp_ref.Get_description().c_str(), "H(1)") == 0 || + strcmp(comp_ref.Get_description().c_str(), "E") == 0) + { + continue; + } + if (comp_ref.Get_input_conc() <= 0) + continue; +/* + * Get gfw + */ + /* use given gfw if gfw > 0.0 */ + /* use formula give with "as" */ + if (comp_ref.Get_gfw() <= 0.0) + { + if (comp_ref.Get_as().size() > 0) + { + /* use given chemical formula to calculate gfw */ + if (compute_gfw(comp_ref.Get_as().c_str(), &dummy) == ERROR) + { + error_string = sformatf( "Could not compute gfw, %s.", + comp_ref.Get_as().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + } + else + { + comp_ref.Set_gfw(dummy); + } + if (strcmp(comp_ref.Get_description().c_str(), "Alkalinity") == 0 && + strcmp(comp_ref.Get_as().c_str(), "CaCO3") == 0) + { + comp_ref.Set_gfw(comp_ref.Get_gfw() / 2.0); + error_string = sformatf( + "Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.", + (double) comp_ref.Get_gfw()); + warning_msg(error_string); + } + /* use gfw of master species */ + } + else + { + char * temp_desc = string_duplicate(comp_ref.Get_description().c_str()); + char *ptr = temp_desc; + copy_token(token, &ptr); + master_ptr = master_bsearch(token.c_str()); + free_check_null(temp_desc); + if (master_ptr != NULL) + { + /* use gfw for element redox state */ + comp_ref.Set_gfw(master_ptr->gfw); + } + else + { + error_string = sformatf( "Could not find gfw, %s.", + comp_ref.Get_description().c_str()); + error_msg(error_string, CONTINUE); + input_error++; + continue; + } + } + } +/* + * Convert liters to kg solution + */ + moles = comp_ref.Get_input_conc(); + if (strstr(initial_data_ptr->Get_units().c_str(), "/l") != NULL) + { + moles *= 1.0 / (solution_ptr->Get_density()); + } +/* + * Convert milli or micro + */ + char c = comp_ref.Get_units()[0]; + if (c == 'm') + { + moles *= 1e-3; + } + else if (c == 'u') + { + moles *= 1e-6; + } +/* + * Sum grams of solute, convert from moles necessary + */ + if (strstr(comp_ref.Get_units().c_str(), "g/kgs") != NULL || + strstr(comp_ref.Get_units().c_str(), "g/l") != NULL) + { + sum_solutes += moles; + } + else if (strstr(comp_ref.Get_units().c_str(), "Mol/kgs") != NULL || + strstr(comp_ref.Get_units().c_str(), "Mol/l") != NULL || + strstr(comp_ref.Get_units().c_str(), "eq/l") != NULL) + { + sum_solutes += moles * comp_ref.Get_gfw(); + } +/* + * Convert grams to moles, if necessary + */ + if (strstr(comp_ref.Get_units().c_str(), "g/") != NULL && comp_ref.Get_gfw() != 0.0) + { + moles /= comp_ref.Get_gfw(); + } + solution_ptr->Get_totals()[comp_ref.Get_description()] = moles; + } +/* + * Convert /kgs to /kgw + */ + if (strstr(initial_data_ptr->Get_units().c_str(), "kgs") != NULL || + strstr(initial_data_ptr->Get_units().c_str(), "/l") != NULL) + { + mass_water_aq_x = 1.0 - 1e-3 * sum_solutes; + cxxNameDouble::iterator it; + for (it = solution_ptr->Get_totals().begin(); it != solution_ptr->Get_totals().end(); it++) + { + it->second = it->second / mass_water_aq_x; + } + } +/* + * Scale by mass of water in solution + */ + mass_water_aq_x = solution_ptr->Get_mass_water(); + cxxNameDouble::iterator it; + for (it = solution_ptr->Get_totals().begin(); it != solution_ptr->Get_totals().end(); it++) + { + it->second = it->second * mass_water_aq_x; + } + + initial_data_ptr->Set_units(moles_per_kilogram_string); + + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: convert_units(struct solution *solution_ptr) @@ -2014,7 +2166,7 @@ convert_units(struct solution *solution_ptr) return (OK); } - +#endif /* ---------------------------------------------------------------------- */ struct master ** Phreeqc:: get_list_master_ptrs(char *ptr, struct master *master_ptr) @@ -2251,7 +2403,7 @@ mb_for_species_aq(int n) */ if (mass_hydrogen_unknown != NULL) { - if (dl_type_x != NO_DL && state >= REACTION) + if (dl_type_x != cxxSurface::NO_DL && state >= REACTION) { #ifdef COMBINE store_mb_unknowns(mass_hydrogen_unknown, &s[n]->tot_g_moles, @@ -2274,7 +2426,7 @@ mb_for_species_aq(int n) } if (mass_oxygen_unknown != NULL) { - if (dl_type_x != NO_DL && state >= REACTION) + if (dl_type_x != cxxSurface::NO_DL && state >= REACTION) { store_mb_unknowns(mass_oxygen_unknown, &s[n]->tot_g_moles, s[n]->o, &s[n]->dg_total_g); @@ -2288,18 +2440,20 @@ mb_for_species_aq(int n) /* * Sum diffuse layer charge into (surface + DL) charge balance */ - if (use.Get_surface_ptr() != NULL && s[n]->type < H2O && dl_type_x != NO_DL) + if (use.Get_surface_ptr() != NULL && s[n]->type < H2O && dl_type_x != cxxSurface::NO_DL) { j = 0; for (i = 0; i < count_unknowns; i++) { if (x[i]->type == SURFACE_CB) { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); unknown_ptr = x[i]; - if (use.Get_surface_ptr()->type == CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) unknown_ptr = x[i + 2]; - store_mb_unknowns(unknown_ptr, &s[n]->diff_layer[j].g_moles, - s[n]->z, &s[n]->diff_layer[j].dg_g_moles); + + store_mb_unknowns(unknown_ptr, s_diff_layer[n][charge_ptr->Get_name()].Get_g_moles_address(), + s[n]->z, s_diff_layer[n][charge_ptr->Get_name()].Get_dg_g_moles_address()); j++; } } @@ -2340,7 +2494,7 @@ mb_for_species_aq(int n) { continue; } - if (dl_type_x != NO_DL && state >= REACTION) + if (dl_type_x != cxxSurface::NO_DL && state >= REACTION) { store_mb_unknowns(master_ptr->unknown, &s[n]->tot_g_moles, @@ -2446,7 +2600,6 @@ mb_for_species_ex(int n) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: mb_for_species_surf(int n) @@ -2469,7 +2622,7 @@ mb_for_species_surf(int n) /* * Include in charge balance, if diffuse_layer_x == FALSE */ - if (charge_balance_unknown != NULL && dl_type_x == NO_DL) + if (charge_balance_unknown != NULL && dl_type_x == cxxSurface::NO_DL) { store_mb_unknowns(charge_balance_unknown, &s[n]->moles, s[n]->z, &s[n]->dg); @@ -2516,14 +2669,14 @@ mb_for_species_surf(int n) * SURF_PSI, sum surface species in (surface + DL) charge balance */ if (master_ptr->s->type == SURF_PSI - && use.Get_surface_ptr()->type != CD_MUSIC) + && use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) { store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->z, &s[n]->dg); continue; } if (master_ptr->s->type == SURF_PSI - && use.Get_surface_ptr()->type == CD_MUSIC) + && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { store_mb_unknowns(master_ptr->unknown, &s[n]->moles, s[n]->dz[0], &s[n]->dg); @@ -2575,7 +2728,6 @@ mb_for_species_surf(int n) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: reprep(void) @@ -2725,8 +2877,8 @@ write_mass_action_eqn_x(int stop) trxn.token[i].coef, FALSE); if (equal(coef_e, 0.0, TOL) == FALSE) { - trxn_add(*(trxn.token[i].s->secondary->pe_rxn), - trxn.token[i].coef * coef_e, FALSE); + cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; + trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); } } } @@ -2746,13 +2898,12 @@ add_potential_factor(void) * the work required to bring charged ions to the surface */ int i; - char token[MAX_LENGTH]; + std::string token; LDBLE sum_z; struct master *master_ptr; struct unknown *unknown_ptr; - /*if (use.Get_surface_ptr()->edl == FALSE) return(OK); */ - if (use.Get_surface_ptr()->type != DDL) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) return (OK); sum_z = 0.0; master_ptr = NULL; @@ -2791,12 +2942,12 @@ add_potential_factor(void) input_error++; return (ERROR); } - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); if (unknown_ptr == NULL) { error_string = sformatf( - "No potential unknown found for surface species %s.", token); + "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ @@ -2839,12 +2990,11 @@ add_cd_music_factors(int n) * of the cd_music model */ int i; - char token[MAX_LENGTH]; + std::string token; struct master *master_ptr; struct unknown *unknown_ptr; - /*if (use.Get_surface_ptr()->edl == FALSE) return(OK); */ - if (use.Get_surface_ptr()->type != CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) return (OK); master_ptr = NULL; /* @@ -2877,7 +3027,7 @@ add_cd_music_factors(int n) input_error++; return (ERROR); } - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; /* * Plane 0 */ @@ -2885,7 +3035,7 @@ add_cd_music_factors(int n) if (unknown_ptr == NULL) { error_string = sformatf( - "No potential unknown found for surface species %s.", token); + "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ @@ -2914,7 +3064,7 @@ add_cd_music_factors(int n) if (unknown_ptr == NULL) { error_string = sformatf( - "No potential unknown found for surface species %s.", token); + "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ @@ -2933,7 +3083,7 @@ add_cd_music_factors(int n) if (unknown_ptr == NULL) { error_string = sformatf( - "No potential unknown found for surface species %s.", token); + "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ @@ -2959,12 +3109,12 @@ add_surface_charge_balance(void) */ int i; char *ptr; - char token[MAX_LENGTH]; + std::string token; struct master *master_ptr; struct unknown *unknown_ptr; - if (use.Get_surface_ptr()->type != DDL) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) return (OK); master_ptr = NULL; /* @@ -2987,12 +3137,12 @@ add_surface_charge_balance(void) /* * Find potential unknown for surface species */ - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); if (unknown_ptr == NULL) { error_string = sformatf( - "No potential unknown found for surface species %s.", token); + "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ @@ -3018,12 +3168,12 @@ add_cd_music_charge_balances(int n) * the work required to bring charged ions to the surface */ int i; - char token[MAX_LENGTH]; + std::string token; struct master *master_ptr; struct unknown *unknown_ptr; - if (use.Get_surface_ptr()->type != CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) return (OK); master_ptr = NULL; /* @@ -3046,7 +3196,7 @@ add_cd_music_charge_balances(int n) /* * Find potential unknown for plane 0 */ - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3061,7 +3211,7 @@ add_cd_music_charge_balances(int n) /* * Find potential unknown for plane 1 */ - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; unknown_ptr = find_surface_charge_unknown(token, SURF_PSI1); master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3076,7 +3226,7 @@ add_cd_music_charge_balances(int n) /* * Find potential unknown for plane 2 */ - strcpy(token, master_ptr->elt->name); + token = master_ptr->elt->name; unknown_ptr = find_surface_charge_unknown(token, SURF_PSI2); master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3148,24 +3298,21 @@ setup_exchange(void) /* * Fill in data for exchanger in unknowns structures */ - //int i, j; struct master *master_ptr; struct master **master_ptr_list; if (use.Get_exchange_ptr() == NULL) return (OK); - std::vector comps = ((cxxExchange *) use.Get_exchange_ptr())->Vectorize(); - for (size_t j = 0; j < comps.size(); j++) + for (size_t j = 0; j < use.Get_exchange_ptr()->Get_exchange_comps().size(); j++) { - cxxExchComp * comp_ptr = comps[j]; - cxxNameDouble nd(comp_ptr->Get_totals()); + cxxExchComp & comp_ref = use.Get_exchange_ptr()->Get_exchange_comps()[j]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); for ( ; it != nd.end(); it++) { /* * Find master species */ - //master_ptr = use.Get_exchange_ptr()->comps[j].totals[i].elt->master; element * elt_ptr = element_store(it->first.c_str()); if (elt_ptr == NULL || elt_ptr->master == NULL) { @@ -3219,10 +3366,9 @@ setup_gas_phase(void) * Fill in data for gas phase unknown (sum of partial pressures) * in unknown structure */ - //int i; if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && ( gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) { @@ -3243,7 +3389,6 @@ setup_gas_phase(void) if (x[count_unknowns]->moles <= 0) x[count_unknowns]->moles = MIN_TOTAL; x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); - //x[count_unknowns]->gas_phase = use.Get_gas_phase_ptr(); gas_unknown = x[count_unknowns]; count_unknowns++; return (OK); @@ -3316,7 +3461,6 @@ setup_ss_assemblage(void) * Fill in data for solid solution unknowns (sum of partial pressures) * in unknown structure */ - //int i, j; if (use.Get_ss_assemblage_ptr() == NULL) return (OK); /* @@ -3366,31 +3510,28 @@ setup_surface(void) /* * Fill in data for surface assemblage in unknown structure */ - int i, j, k, plane; - struct master *master_ptr; struct master **master_ptr_list; - struct unknown *unknown_ptr, **unknown_target; - char token[MAX_LENGTH], cb_suffix[MAX_LENGTH], psi_suffix[MAX_LENGTH], - mass_balance_name[MAX_LENGTH]; - const char *name1, *name2; - int mb_unknown_number, type; + int mb_unknown_number; if (use.Get_surface_ptr() == NULL) return (OK); - for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) { + cxxSurfaceComp *comp_ptr = &(use.Get_surface_ptr()->Get_surface_comps()[i]); /* * Find master species for each surface, setup unknown structure */ - for (j = 0; use.Get_surface_ptr()->comps[i].totals[j].elt != NULL; j++) + cxxNameDouble::iterator jit; + for (jit = comp_ptr->Get_totals().begin(); jit != comp_ptr->Get_totals().end(); jit++) { - master_ptr = use.Get_surface_ptr()->comps[i].totals[j].elt->master; + struct element *elt_ptr = element_store(jit->first.c_str()); + struct master *master_ptr = elt_ptr->master; if (master_ptr == NULL) { error_string = sformatf( "Master species not in data base for %s, skipping element.", - use.Get_surface_ptr()->comps[i].totals[j].elt->name); + elt_ptr->name); warning_msg(error_string); continue; } @@ -3410,7 +3551,6 @@ setup_surface(void) /* * Set flags */ - use.Get_surface_ptr()->comps[i].master = master_ptr; master_ptr_list = unknown_alloc_master(); master_ptr_list[0] = master_ptr; master_ptr->in = TRUE; @@ -3418,26 +3558,24 @@ setup_surface(void) * Setup mass balance unknown */ x[count_unknowns]->type = SURFACE; - x[count_unknowns]->description = - use.Get_surface_ptr()->comps[i].totals[j].elt->name; + x[count_unknowns]->description = string_hsave(jit->first.c_str()); x[count_unknowns]->number = count_unknowns; - x[count_unknowns]->surface_comp = &(use.Get_surface_ptr()->comps[i]); + x[count_unknowns]->surface_comp = string_hsave(comp_ptr->Get_formula().c_str()); x[count_unknowns]->master = master_ptr_list; x[count_unknowns]->master[0]->unknown = x[count_unknowns]; - x[count_unknowns]->moles = - use.Get_surface_ptr()->comps[i].totals[j].coef; + x[count_unknowns]->moles = jit->second; if (surface_unknown == NULL) surface_unknown = x[count_unknowns]; x[count_unknowns]->potential_unknown = NULL; count_unknowns++; /*if (use.Get_surface_ptr()->edl == FALSE) continue; */ - if (use.Get_surface_ptr()->type == DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { /* * Setup surface-potential unknown */ - strcpy(token, master_ptr->elt->name); - unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + std::string token = master_ptr->elt->name; + struct unknown *unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); if (unknown_ptr != NULL) { x[count_unknowns - 1]->potential_unknown = unknown_ptr; @@ -3448,25 +3586,22 @@ setup_surface(void) * Find master species */ replace("_CB", "_psi", token); - master_ptr = master_bsearch(token); + master_ptr = master_bsearch(token.c_str()); master_ptr_list = unknown_alloc_master(); master_ptr_list[0] = master_ptr; master_ptr->in = TRUE; /* * Find surface charge structure */ + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()-> + Find_charge(comp_ptr->Get_charge_name()); x[count_unknowns]->type = SURFACE_CB; - k = use.Get_surface_ptr()->comps[i].charge; - x[count_unknowns]->surface_charge = - &use.Get_surface_ptr()->charge[k]; - x[count_unknowns]->related_moles = - x[count_unknowns]->surface_charge->grams; - x[count_unknowns]->mass_water = - use.Get_surface_ptr()->charge[k].mass_water; + x[count_unknowns]->surface_charge = string_hsave(charge_ptr->Get_name().c_str()); + x[count_unknowns]->related_moles = charge_ptr->Get_grams(); + x[count_unknowns]->mass_water = charge_ptr->Get_mass_water(); replace("_psi", "_CB", token); - x[count_unknowns]->description = string_hsave(token); + x[count_unknowns]->description = string_hsave(token.c_str()); x[count_unknowns]->master = master_ptr_list; - /*use.Get_surface_ptr()->charge[k].psi_master = x[count_unknowns]->master[0]; */ x[count_unknowns]->master[0]->unknown = x[count_unknowns]; x[count_unknowns]->moles = 0.0; x[count_unknowns - 1]->potential_unknown = @@ -3476,20 +3611,22 @@ setup_surface(void) count_unknowns++; } } - else if (use.Get_surface_ptr()->type == CD_MUSIC) + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { /* * Setup 3 surface-potential unknowns */ mb_unknown_number = count_unknowns - 1; - strcpy(token, master_ptr->elt->name); - strcpy(mass_balance_name, token); + std::string token(master_ptr->elt->name); + std::string mass_balance_name(token); + int plane; for (plane = SURF_PSI; plane <= SURF_PSI2; plane++) { - strcpy(cb_suffix, "_CB"); - strcpy(psi_suffix, "_psi"); + std::string cb_suffix("_CB"); + std::string psi_suffix("_psi"); + struct unknown **unknown_target; unknown_target = NULL; - type = SURFACE_CB; + int type = SURFACE_CB; switch (plane) { case SURF_PSI: @@ -3498,21 +3635,19 @@ setup_surface(void) &(x[mb_unknown_number]->potential_unknown); break; case SURF_PSI1: - strcat(cb_suffix, "b"); - strcat(psi_suffix, "b"); + cb_suffix.append("b"); + psi_suffix.append("b"); type = SURFACE_CB1; - unknown_target = - &(x[mb_unknown_number]->potential_unknown1); + unknown_target = &(x[mb_unknown_number]->potential_unknown1); break; case SURF_PSI2: - strcat(cb_suffix, "d"); - strcat(psi_suffix, "d"); + cb_suffix.append("d"); + psi_suffix.append("d"); type = SURFACE_CB2; - unknown_target = - &(x[mb_unknown_number]->potential_unknown2); + unknown_target = &(x[mb_unknown_number]->potential_unknown2); break; } - unknown_ptr = find_surface_charge_unknown(token, plane); + struct unknown *unknown_ptr = find_surface_charge_unknown(token, plane); if (unknown_ptr != NULL) { *unknown_target = unknown_ptr; @@ -3522,24 +3657,22 @@ setup_surface(void) /* * Find master species */ - replace(cb_suffix, psi_suffix, token); - master_ptr = master_bsearch(token); + replace(cb_suffix.c_str(), psi_suffix.c_str(), token); + master_ptr = master_bsearch(token.c_str()); master_ptr_list = unknown_alloc_master(); master_ptr_list[0] = master_ptr; master_ptr->in = TRUE; /* * Find surface charge structure */ + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()-> + Find_charge(comp_ptr->Get_charge_name()); x[count_unknowns]->type = type; - k = use.Get_surface_ptr()->comps[i].charge; - x[count_unknowns]->surface_charge = - &use.Get_surface_ptr()->charge[k]; - x[count_unknowns]->related_moles = - x[count_unknowns]->surface_charge->grams; - x[count_unknowns]->mass_water = - use.Get_surface_ptr()->charge[k].mass_water; - replace(psi_suffix, cb_suffix, token); - x[count_unknowns]->description = string_hsave(token); + x[count_unknowns]->surface_charge = string_hsave(charge_ptr->Get_name().c_str()); + x[count_unknowns]->related_moles = charge_ptr->Get_grams(); + x[count_unknowns]->mass_water = charge_ptr->Get_mass_water(); + replace(psi_suffix.c_str(), cb_suffix.c_str(), token); + x[count_unknowns]->description = string_hsave(token.c_str()); x[count_unknowns]->master = master_ptr_list; /* * Find surface charge structure @@ -3571,21 +3704,12 @@ setup_surface(void) } } /* Add SURFACE unknown to a list for SURF_PSI */ - unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); - unknown_ptr->comp_unknowns = - (struct unknown **) PHRQ_realloc(unknown_ptr-> - comp_unknowns, - (size_t) ((unknown_ptr-> - count_comp_unknowns - + - 1) * - sizeof(struct - unknown - *))); + struct unknown *unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); + unknown_ptr->comp_unknowns = (struct unknown **) PHRQ_realloc(unknown_ptr->comp_unknowns, + (size_t) ((unknown_ptr->count_comp_unknowns + 1) * sizeof(struct unknown *))); if (unknown_ptr->comp_unknowns == NULL) malloc_error(); - unknown_ptr->comp_unknowns[unknown_ptr-> - count_comp_unknowns++] = + unknown_ptr->comp_unknowns[unknown_ptr->count_comp_unknowns++] = x[mb_unknown_number]; } } @@ -3593,43 +3717,46 @@ setup_surface(void) /* * check related phases */ - if (use.Get_surface_ptr()->related_phases == TRUE) + if (use.Get_surface_ptr()->Get_related_phases()) { - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; - for (j = 0; j < count_unknowns; j++) + cxxSurfaceComp *comp_i_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE) continue; if (x[j]->potential_unknown != x[i]) continue; - if (x[j]->surface_comp->phase_name != - x[i]->surface_comp->phase_name) + cxxSurfaceComp *comp_j_ptr = use.Get_surface_ptr()->Find_comp(x[j]->surface_comp); + std::string name1, name2; + if (comp_j_ptr->Get_phase_name() != + comp_i_ptr->Get_phase_name()) { - if (x[i]->surface_comp->phase_name == NULL) + if (comp_i_ptr->Get_phase_name().size() == 0) { - name1 = string_hsave("None"); + name1 = "None"; } else { - name1 = x[i]->surface_comp->phase_name; + name1 = comp_i_ptr->Get_phase_name(); } - if (x[j]->surface_comp->phase_name == NULL) + if (comp_j_ptr->Get_phase_name().size() == 0) { - name2 = string_hsave("None"); + name2 = "None"; } else { - name2 = x[j]->surface_comp->phase_name; + name2 = comp_j_ptr->Get_phase_name(); } input_error++; + error_string = sformatf( "All surface sites for a single component must be related to the same phase.\n\tSite: %s is related to %s, Site: %s is related to %s", - x[i]->surface_comp->master->s->name, name1, - x[j]->surface_comp->master->s->name, name2); - + comp_i_ptr->Get_master_element().c_str(), name1.c_str(), + comp_j_ptr->Get_master_element().c_str(), name2.c_str()); error_msg(error_string, CONTINUE); } } @@ -3638,43 +3765,45 @@ setup_surface(void) /* * check related kinetics */ - if (use.Get_surface_ptr()->related_rate == TRUE) + if (use.Get_surface_ptr()->Get_related_rate()) { - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) continue; - for (j = 0; j < count_unknowns; j++) + cxxSurfaceComp *comp_i_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE) continue; if (x[j]->potential_unknown != x[i]) continue; - if (x[j]->surface_comp->rate_name != - x[i]->surface_comp->rate_name) + cxxSurfaceComp *comp_j_ptr = use.Get_surface_ptr()->Find_comp(x[j]->surface_comp); + if (comp_j_ptr->Get_rate_name() != + comp_i_ptr->Get_rate_name()) { - if (x[i]->surface_comp->rate_name == NULL) + std::string name1, name2; + if (comp_i_ptr->Get_rate_name().size() == 0) { - name1 = string_hsave("None"); + name1 = "None"; } else { - name1 = x[i]->surface_comp->rate_name; + name1 = comp_i_ptr->Get_rate_name(); } - if (x[j]->surface_comp->rate_name == NULL) + if (comp_j_ptr->Get_rate_name().size() == 0) { - name2 = string_hsave("None"); + name2 = "None"; } else { - name2 = x[j]->surface_comp->rate_name; + name2 = comp_j_ptr->Get_rate_name(); } input_error++; error_string = sformatf( "All surface sites for a single component must be related to the same kinetic reaction.\n\tSite: %s is related to %s, Site: %s is related to %s", - x[i]->surface_comp->master->s->name, name1, - x[j]->surface_comp->master->s->name, name2); - + comp_i_ptr->Get_master_element().c_str(), name1.c_str(), + comp_j_ptr->Get_master_element().c_str(), name2.c_str()); error_msg(error_string, CONTINUE); } } @@ -3682,10 +3811,9 @@ setup_surface(void) } return (OK); } - /* ---------------------------------------------------------------------- */ struct unknown * Phreeqc:: -find_surface_charge_unknown(char *str_ptr, int plane) +find_surface_charge_unknown(std::string &str, int plane) /* ---------------------------------------------------------------------- */ { /* @@ -3693,39 +3821,36 @@ find_surface_charge_unknown(char *str_ptr, int plane) * Returns NULL if this unknown not in unknown list else * returns a pointer to the potential unknown */ - int i; - char *ptr; - char token[MAX_LENGTH]; - - replace("_", " ", str_ptr); - ptr = str_ptr; - copy_token(token, &ptr, &i); + std::string token; + Utilities::replace("_", " ", str); + std::string::iterator b = str.begin(); + std::string::iterator e = str.end(); + CParser::copy_token(token, b, e); if (plane == SURF_PSI) { - strcat(token, "_CB"); + token.append("_CB"); } else if (plane == SURF_PSI1) { - strcat(token, "_CBb"); + token.append("_CBb"); } else if (plane == SURF_PSI2) { - strcat(token, "_CBd"); + token.append("_CBd"); } - strcpy(str_ptr, token); - for (i = 0; i < count_unknowns; i++) + str = token; + for (int i = 0; i < count_unknowns; i++) { - if (strcmp(token, x[i]->description) == 0) + if (strcmp(str.c_str(), x[i]->description) == 0) { return (x[i]); } } return (NULL); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn) +setup_master_rxn(struct master **master_ptr_list, const std::string &pe_rxn) /* ---------------------------------------------------------------------- */ { /* @@ -3793,7 +3918,7 @@ setup_master_rxn(struct master **master_ptr_list, struct reaction **pe_rxn) */ } } - master_ptr->pe_rxn = pe_rxn; + master_ptr->pe_rxn = string_hsave(pe_rxn.c_str()); } return (OK); } @@ -3834,7 +3959,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) LDBLE disct, vinit, v1, ddp, dp_dv, dp_dv2; int it; struct phase *phase_ptr, *phase_ptr1; - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); bool halved; R_TK = R * TK; m_sum = b_sum = a_aa_sum = 0.0; @@ -3947,7 +4072,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) 27. * r3[3] * r3[3]; //if (iterations > 50) // it = 0; // debug - if (disct > 0) + if (disct > 1e-8) { // 3-roots, find the largest P... it = 0; @@ -4073,13 +4198,13 @@ LDBLE Phreeqc:: f_Vm(LDBLE v1, void *cookie) /* ---------------------------------------------------------------------- */ { + LDBLE ff; Phreeqc * pThis; - pThis = (Phreeqc *) cookie; - LDBLE dp_dv = -pThis->R_TK / ((v1 - pThis->b_sum) * (v1 - pThis->b_sum)) + - pThis->a_aa_sum * (2 * v1 + 2 * pThis->b_sum) / - ((v1 * (v1 + 2. * pThis->b_sum) - pThis->b2) * (v1 * (v1 + 2. * pThis->b_sum) - pThis->b2)); + ff = v1 * (v1 + 2 * pThis->b_sum) - pThis->b2; + LDBLE dp_dv = -pThis->R_TK / pow(v1 - pThis->b_sum, 2) + + pThis->a_aa_sum * 2 * (v1 + pThis->b_sum) / (ff * ff); return dp_dv; } @@ -4095,7 +4220,7 @@ setup_pure_phases(void) if (use.Get_pp_assemblage_ptr() == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Setup unknowns */ @@ -4139,7 +4264,7 @@ adjust_setup_pure_phases(void) if (use.Get_pp_assemblage_ptr() == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Adjust si for gases */ @@ -4155,7 +4280,7 @@ adjust_setup_pure_phases(void) if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { p = exp(si_org * LOG_10); - t = use.Get_solution_ptr()->tc + 273.15; + t = use.Get_solution_ptr()->Get_tc() + 273.15; if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) { calc_PR(phase_ptrs, p, t, 0); @@ -4174,48 +4299,58 @@ setup_solution(void) /* * Fills in data in unknown structure for the solution */ - int l, i, j; struct master *master_ptr; - struct solution *solution_ptr; + cxxSolution *solution_ptr; char *ptr; - char token[MAX_LENGTH]; + std::string token; struct master_isotope *master_isotope_ptr; struct phase *phase_ptr; solution_ptr = use.Get_solution_ptr(); count_unknowns = 0; - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + + /* + * Treat minor isotopes as special in initial solution calculation + */ + if (solution_ptr->Get_initial_data()) { - /* solution_ptr->totals[i].skip = FALSE; */ - char * temp_desc = string_duplicate(solution_ptr->totals[i].description); - ptr = temp_desc; - copy_token(token, &ptr, &l); - master_ptr = master_bsearch(token); - /* - * Treat minor isotopes as special in initial solution calculation - */ - if ((state == INITIAL_SOLUTION) && (master_ptr != NULL) - && (master_ptr->minor_isotope == TRUE) - && (initial_solution_isotopes == FALSE)) + std::map::iterator comp_it = solution_ptr->Get_initial_data()->Get_comps().begin(); + for ( ; comp_it != solution_ptr->Get_initial_data()->Get_comps().end(); comp_it++) { - master_isotope_ptr = master_isotope_search(token); - if (master_isotope_ptr != NULL) + master_ptr = master_bsearch(comp_it->first.c_str()); + if ((master_ptr != NULL) + && (master_ptr->minor_isotope == TRUE) + && (initial_solution_isotopes == FALSE)) { - master_isotope_ptr->ratio = - solution_ptr->totals[i].input_conc; + master_isotope_ptr = master_isotope_search(comp_it->first.c_str()); + if (master_isotope_ptr != NULL) + { + master_isotope_ptr->ratio = comp_it->second.Get_input_conc(); + } } - /* solution_ptr->totals[i].skip = TRUE; */ - free_check_null(temp_desc); - continue; } + } + cxxNameDouble::iterator it = solution_ptr->Get_totals().begin(); + for ( ; it != solution_ptr->Get_totals().end(); it++) + { + cxxISolutionComp *comp_ptr = NULL; + if (solution_ptr->Get_initial_data()) + { + std::map::iterator comp_it; + comp_it = solution_ptr->Get_initial_data()->Get_comps().find(it->first.c_str()); + comp_ptr = &(comp_it->second); + } + char * temp_desc = string_duplicate(it->first.c_str()); + ptr = temp_desc; + copy_token(token, &ptr); + master_ptr = master_bsearch(token.c_str()); /* * Check that total not <= zero */ - if (solution_ptr->totals[i].input_conc <= 0.0) + if (it->second <= 0.0) { - if (strcmp(token, "H(1)") != 0 && strcmp(token, "E") != 0) + if (strcmp(token.c_str(), "H(1)") != 0 && strcmp(token.c_str(), "E") != 0) { - /* solution_ptr->totals[i].skip = TRUE; */ free_check_null(temp_desc); continue; } @@ -4223,13 +4358,12 @@ setup_solution(void) /* * Find master species */ - master_ptr = master_bsearch(token); + master_ptr = master_bsearch(token.c_str()); if (master_ptr == NULL) { - /* solution_ptr->totals[i].skip = TRUE; */ error_string = sformatf( "Master species not in data base for %s, skipping element.", - solution_ptr->totals[i].description); + it->first.c_str()); warning_msg(error_string); free_check_null(temp_desc); continue; @@ -4239,7 +4373,7 @@ setup_solution(void) /* solution_ptr->totals[i].skip = TRUE; */ error_string = sformatf( "Only aqueous concentrations are allowed in solution data, ignoring %s.", - solution_ptr->totals[i].description); + it->first.c_str()); warning_msg(error_string); free_check_null(temp_desc); continue; @@ -4248,29 +4382,34 @@ setup_solution(void) * Store list of master species pointers, set master[i].in and master[i].rxn for list */ x[count_unknowns]->master = get_list_master_ptrs(ptr, master_ptr); - setup_master_rxn(x[count_unknowns]->master, - &(pe_x[solution_ptr->totals[i].n_pe].rxn)); + if (comp_ptr) + { + setup_master_rxn(x[count_unknowns]->master, comp_ptr->Get_pe_reaction()); + } + else + { + setup_master_rxn(x[count_unknowns]->master, "pe"); + } /* * Set default unknown data */ x[count_unknowns]->type = MB; - x[count_unknowns]->description = solution_ptr->totals[i].description; - x[count_unknowns]->total = &(solution_ptr->totals[i]); - for (j = 0; x[count_unknowns]->master[j] != NULL; j++) + x[count_unknowns]->description = string_hsave(it->first.c_str()); + for (int j = 0; x[count_unknowns]->master[j] != NULL; j++) { x[count_unknowns]->master[j]->unknown = x[count_unknowns]; } - x[count_unknowns]->moles = solution_ptr->totals[i].moles; + x[count_unknowns]->moles = it->second; /* * Set pointers */ free_check_null(temp_desc); - temp_desc = string_duplicate(solution_ptr->totals[i].description); + temp_desc = string_duplicate(it->first.c_str()); ptr = temp_desc; - copy_token(token, &ptr, &l); - str_tolower(token); - if (strstr(token, "alk") != NULL) + copy_token(token, &ptr); + Utilities::str_tolower(token); + if (strstr(token.c_str(), "alk") != NULL) { if (alkalinity_unknown == NULL) { @@ -4283,7 +4422,7 @@ setup_solution(void) input_error++; } } - else if (strcmp(token, "c") == 0 || strcmp(token, "c(4)") == 0) + else if (strcmp(token.c_str(), "c") == 0 || strcmp(token.c_str(), "c(4)") == 0) { if (carbon_unknown == NULL) { @@ -4295,7 +4434,7 @@ setup_solution(void) input_error++; } } - else if (strcmp(token, "h(1)") == 0) + else if (strcmp(token.c_str(), "h(1)") == 0) { if (ph_unknown == NULL) { @@ -4307,7 +4446,7 @@ setup_solution(void) input_error++; } } - else if (strcmp(token, "e") == 0) + else if (strcmp(token.c_str(), "e") == 0) { if (pe_unknown == NULL) { @@ -4323,13 +4462,13 @@ setup_solution(void) /* * Charge balance unknown */ - if (solution_ptr->totals[i].equation_name != NULL) + if (comp_ptr && comp_ptr->Get_equation_name().size() > 0) { - char * temp_eq_name = string_duplicate(solution_ptr->totals[i].equation_name); + char * temp_eq_name = string_duplicate(comp_ptr->Get_equation_name().c_str()); ptr = temp_eq_name; - copy_token(token, &ptr, &l); - str_tolower(token); - if (strstr(token, "charge") != NULL) + copy_token(token, &ptr); + Utilities::str_tolower(token); + if (strstr(token.c_str(), "charge") != NULL) { if (charge_balance_unknown == NULL) { @@ -4337,7 +4476,7 @@ setup_solution(void) x[count_unknowns]->type = CB; if (charge_balance_unknown == ph_unknown) { - x[count_unknowns]->moles = solution_ptr->cb; + x[count_unknowns]->moles = solution_ptr->Get_cb(); } } else @@ -4352,20 +4491,18 @@ setup_solution(void) /* * Solution phase boundaries */ - solution_ptr->totals[i].phase = - phase_bsearch(solution_ptr->totals[i].equation_name, &l, - FALSE); - if (solution_ptr->totals[i].phase == NULL) + int l; + phase_ptr = phase_bsearch(comp_ptr->Get_equation_name().c_str(), &l, FALSE); + if (phase_ptr == NULL) { error_string = sformatf( "Expected a mineral name, %s.", - solution_ptr->totals[i].equation_name); + comp_ptr->Get_equation_name().c_str()); error_msg(error_string, CONTINUE); input_error++; } x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; - phase_ptr = solution_ptr->totals[i].phase; x[count_unknowns]->phase = phase_ptr; - x[count_unknowns]->si = solution_ptr->totals[i].phase_si; + x[count_unknowns]->si = comp_ptr->Get_phase_si(); /* For Peng-Robinson gas, the fugacity coefficient is added later in adjust_setup_solution, when rxn_x has been defined for each phase in the model */ @@ -4432,7 +4569,7 @@ setup_solution(void) } } } - if (pitzer_model == FALSE && sit_model == FALSE) + //if (pitzer_model == FALSE && sit_model == FALSE) { /* * Ionic strength @@ -4442,7 +4579,6 @@ setup_solution(void) x[count_unknowns]->type = MU; x[count_unknowns]->number = count_unknowns; x[count_unknowns]->moles = 0.0; - mu_unknown = x[count_unknowns]; count_unknowns++; } /* @@ -4467,7 +4603,7 @@ setup_solution(void) ph_unknown = x[count_unknowns]; ph_unknown->description = string_hsave("pH"); ph_unknown->type = CB; - ph_unknown->moles = solution_ptr->cb; + ph_unknown->moles = solution_ptr->Get_cb(); ph_unknown->number = count_unknowns; ph_unknown->master = unknown_alloc_master(); ph_unknown->master[0] = s_hplus->primary; @@ -4483,7 +4619,7 @@ setup_solution(void) mass_hydrogen_unknown->type = MH; #ifdef COMBINE mass_hydrogen_unknown->moles = - solution_ptr->total_h - 2 * solution_ptr->total_o; + solution_ptr->Get_total_h() - 2 * solution_ptr->Get_total_o(); #else mass_hydrogen_unknown->moles = solution_ptr->total_h; #endif @@ -4498,7 +4634,7 @@ setup_solution(void) mass_oxygen_unknown = x[count_unknowns]; mass_oxygen_unknown->description = string_hsave("Oxygen"); mass_oxygen_unknown->type = MH2O; - mass_oxygen_unknown->moles = solution_ptr->total_o; + mass_oxygen_unknown->moles = solution_ptr->Get_total_o(); mass_oxygen_unknown->number = count_unknowns; mass_oxygen_unknown->master = unknown_alloc_master(); mass_oxygen_unknown->master[0] = s_h2o->primary; @@ -4543,27 +4679,13 @@ adjust_setup_solution(void) std::vector phase_ptrs; if (x[i]->type == SOLUTION_PHASE_BOUNDARY) { - //solution_ptr->totals[i].phase = - // phase_bsearch(solution_ptr->totals[i].equation_name, &l, - // FALSE); - //if (solution_ptr->totals[i].phase == NULL) - //{ - // error_string = sformatf( "Expected a mineral name, %s.", - // solution_ptr->totals[i].equation_name); - // error_msg(error_string, CONTINUE); - // input_error++; - //} x[count_unknowns]->type = SOLUTION_PHASE_BOUNDARY; - //phase_ptr = solution_ptr->totals[i].phase; - //x[count_unknowns]->phase = phase_ptr; - //x[count_unknowns]->si = solution_ptr->totals[i].phase_si; - phase_ptr = x[i]->phase; phase_ptrs.push_back(phase_ptr); if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { p = exp(x[i]->si * LOG_10); - t = use.Get_solution_ptr()->tc + 273.15; + t = use.Get_solution_ptr()->Get_tc() + 273.15; if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) { calc_PR(phase_ptrs, p, t, 0); @@ -4602,7 +4724,7 @@ setup_unknowns(void) * Counts unknowns and allocates space for unknown structures */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; solution_ptr = use.Get_solution_ptr(); /* @@ -4612,8 +4734,14 @@ setup_unknowns(void) /* * Count mass balance in solution */ - for (i = 0; solution_ptr->totals[i].description != NULL; i++) - max_unknowns++; + if (solution_ptr->Get_initial_data()) + { + max_unknowns += solution_ptr->Get_initial_data()->Get_comps().size(); + } + else + { + max_unknowns += solution_ptr->Get_totals().size(); + } /* * Add 5 for ionic strength, activity of water, charge balance, total H, total O */ @@ -4623,27 +4751,19 @@ setup_unknowns(void) */ if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); max_unknowns += (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); - //max_unknowns += use.Get_pp_assemblage_ptr()->count_comps; - -/* - for (i = 0; use.Get_pp_assemblage_ptr()->pure_phases[i].name != NULL; i++ ) { - max_unknowns++; - } - */ } /* * Count exchange */ if (use.Get_exchange_ptr() != NULL) { - cxxExchange *exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); - std::vector comps = exchange_ptr->Vectorize(); - for (size_t j = 0; j < comps.size(); j++) + cxxExchange *exchange_ptr = use.Get_exchange_ptr(); + for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - cxxExchComp * comp_ptr = comps[j]; - cxxNameDouble nd(comp_ptr->Get_totals()); + cxxExchComp & comp_ref = exchange_ptr->Get_exchange_comps()[j]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); for ( ; it != nd.end(); it++) { @@ -4667,16 +4787,15 @@ setup_unknowns(void) */ if (use.Get_surface_ptr() != NULL) { - if (use.Get_surface_ptr()->type != CD_MUSIC) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) { - max_unknowns += - use.Get_surface_ptr()->count_comps + use.Get_surface_ptr()->count_charge; + max_unknowns += (int) use.Get_surface_ptr()->Get_surface_comps().size() + + (int) use.Get_surface_ptr()->Get_surface_charges().size(); } else { - max_unknowns += - use.Get_surface_ptr()->count_comps + - 4 * use.Get_surface_ptr()->count_charge; + max_unknowns += use.Get_surface_ptr()->Get_surface_comps().size() + + 4 * (int) use.Get_surface_ptr()->Get_surface_charges().size(); } } /* @@ -4684,7 +4803,7 @@ setup_unknowns(void) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) { @@ -4995,7 +5114,6 @@ switch_bases(void) } return (return_value); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_redox(void) @@ -5006,20 +5124,17 @@ tidy_redox(void) * defined in analytical data * */ - int i, j, l; - char *ptr; - char token[MAX_LENGTH], tok1[MAX_LENGTH], tok2[MAX_LENGTH]; - struct pe_data *pe_data_ptr; + std::string token, tok1, tok2; struct master *master_ptr1, *master_ptr2; /* * Keep valences of oxygen and hydrogen in model, if not already in */ - for (i = 0; i < count_master; i++) + for (int i = 0; i < count_master; i++) { if (master[i]->primary == TRUE && (master[i]->s == s_hplus || master[i]->s == s_h2o)) { - j = i + 1; + int j = i + 1; while (j < count_master && master[j]->elt->primary == master[i]) { if (master[j]->in == FALSE && master[j]->s != master[i]->s) @@ -5034,28 +5149,31 @@ tidy_redox(void) /* * Writes equations for e- for each redox couple used in solution n */ - for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) + std::map::iterator it; + for (it = pe_x.begin(); it != pe_x.end(); it++) { - if (strcmp_nocase_arg1(pe_data_ptr->name, "pe") == 0) + if (strcmp_nocase(it->first.c_str(), "pe") == 0) { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); + cxxChemRxn temp_rxn(s_eminus->rxn); + it->second = temp_rxn; } else { - strcpy(token, pe_data_ptr->name); + token = it->first; replace("/", " ", token); - ptr = token; + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + /* * Get redox states and elements from redox couple */ - copy_token(tok1, &ptr, &l); - copy_token(tok2, &ptr, &l); + CParser::copy_token(tok1, b, e); + CParser::copy_token(tok2, b, e); /* * Find master species */ - master_ptr1 = master_bsearch(tok1); - master_ptr2 = master_bsearch(tok2); + master_ptr1 = master_bsearch(tok1.c_str()); + master_ptr2 = master_bsearch(tok2.c_str()); if (master_ptr1 != NULL && master_ptr2 != NULL) { rewrite_master_to_secondary(master_ptr1, master_ptr2); @@ -5067,59 +5185,60 @@ tidy_redox(void) else { error_string = sformatf( - "Can not find master species for redox couple, %s.", - pe_data_ptr->name); + "Cannot find master species for redox couple, %s.", + it->first.c_str()); error_msg(error_string, STOP); } if (inout() == FALSE) { error_string = sformatf( "Analytical data missing for redox couple, %s\n\t Using pe instead.", - pe_data_ptr->name); + it->first.c_str()); warning_msg(error_string); - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup(s_eminus->rxn); - pe_data_ptr->name = pe_x[0].name; + cxxChemRxn temp_rxn(s_eminus->rxn); + it->second = temp_rxn; } else { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_alloc(count_trxn + 1); - trxn_copy(pe_data_ptr->rxn); + struct reaction *rxn = rxn_alloc(count_trxn + 1); + trxn_copy(rxn); + cxxChemRxn temp_rxn(rxn); + it->second = temp_rxn; + rxn_free(rxn); } } } /* * Rewrite equations to master species that are "in" the model */ - for (pe_data_ptr = pe_x; pe_data_ptr->name != NULL; pe_data_ptr++) + for (it = pe_x.begin(); it != pe_x.end(); it++) { count_trxn = 0; - trxn_add(pe_data_ptr->rxn, 1.0, FALSE); + trxn_add(it->second, 1.0, FALSE); if (write_mass_action_eqn_x(CONTINUE) == FALSE) { error_string = sformatf( "Could not rewrite redox " "couple equation for %s\n\t Possibly missing data for one " - "of the redox states.", pe_data_ptr->name); + "of the redox states.", it->first.c_str()); warning_msg(error_string); error_string = sformatf( "Using pe instead of %s.", - pe_data_ptr->name); + it->first.c_str()); warning_msg(error_string); - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_dup(pe_x[0].rxn); - pe_data_ptr->name = pe_x[0].name; + cxxChemRxn temp_rxn(s_eminus->rxn); + it->second = temp_rxn; } else { - rxn_free(pe_data_ptr->rxn); - pe_data_ptr->rxn = rxn_alloc(count_trxn + 1); - trxn_copy(pe_data_ptr->rxn); + struct reaction *rxn = rxn_alloc(count_trxn + 1); + trxn_copy(rxn); + cxxChemRxn temp_rxn(rxn); + it->second = temp_rxn; + rxn_free(rxn); } } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: write_mb_eqn_x(void) @@ -5370,7 +5489,7 @@ calc_delta_v(reaction *r_ptr, bool phase) } return d_v; } - +#ifdef PHREEQC2 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) @@ -5409,13 +5528,6 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) if (r_ptr->token[i].s->logk[kappa]) { kp_t = r_ptr->token[i].s->logk[kappa]; - //if (r_ptr->token[i].s->z > 0) - //{ - // /* correct kappa of cations for temperature, but kappa should be <= 0, Table 43.6 */ - // kp_t += 4e-5 * (tc - 25); - // if (kp_t > 0) - // kp_t = 0; - //} d_v += kp_t * pa; } } @@ -5428,7 +5540,7 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); } - +#ifdef SKIP_THIS_VM /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_vm(LDBLE tc, LDBLE pa) @@ -5478,6 +5590,168 @@ calc_vm(LDBLE tc, LDBLE pa) } return OK; } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_vm(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculate molar volumes for aqueous species, using the millero parm's. + * Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm. + */ + LDBLE I_v; + + /* S_v * I_v^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221, + Use mu_x for the volume averaged Iv, the difference is negligible for mu < 10....*/ + //if (mu_x > 0.7) + //{ + // calc_dens(); + // I_v = I_m / solution_volume; + //} + //else + I_v = mu_x; + + LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(I_v); + for (int i = 0; i < count_s_x; i++) + { + if (!strcmp(s_x[i]->name, "H2O")) + { + s_x[i]->logk[vm_tc] = 18.016 / rho_0; + continue; + } + if (!s_x[i]->logk[vm0]) + continue; + /* the volume terms... */ + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->logk[kappa] * pa; + + /* the ionic strength term * Iv^0.5... */ + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * Sv_I; + /* plus the volume terms * Iv, take mu_x for Iv... */ + //s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x; + + /* for calculating delta_v of the reaction... */ + s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; + } + return OK; +} +#else +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ +/* + * calculate log_k for a single phase, correct for pressure + * see calc_vm (below) for details. + */ + + reaction *r_ptr = (p_ptr->rxn_x ? p_ptr->rxn_x :\ + (p_ptr->rxn_s ? p_ptr->rxn_s : NULL)); + if (!r_ptr) + return 0.0; + if (!r_ptr->logk[vm0]) + return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); + + LDBLE tc = TK - 273.15; + LDBLE d_v = 0.0; + + for (size_t i = 0; r_ptr->token[i].name; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H2O")) + { + d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); + } + else if (r_ptr->token[i].s->logk[vm0]) + { + d_v += r_ptr->token[i].coef * + (r_ptr->token[i].s->logk[vm0] + + (r_ptr->token[i].s->logk[vm1] + r_ptr->token[i].s->logk[vm2] * tc) * tc + + (r_ptr->token[i].s->logk[vm3] + + (r_ptr->token[i].s->logk[vm4] + r_ptr->token[i].s->logk[vm5] * tc) * tc) * mu_x); + if (r_ptr->token[i].s->logk[b_Av] == 0) + d_v += r_ptr->token[i].s->z * r_ptr->token[i].s->z * 0.5 * DH_Av * sqrt(mu_x); + else + { + LDBLE b = (r_ptr->token[i].s->logk[b_Av] < 1e-5 ? + 1e-5 : r_ptr->token[i].s->logk[b_Av]); + d_v += r_ptr->token[i].s->z * r_ptr->token[i].s->z * 0.5 * DH_Av * + log(1 + b * sqrt(mu_x)) / b; + } + if (pa > 1) + d_v -= r_ptr->token[i].s->logk[kappa] * (pa - 1.0); + } + } + d_v -= p_ptr->logk[vm0] + (p_ptr->logk[vm1] * tc + p_ptr->logk[vm2] * tc) * tc - + p_ptr->logk[kappa] * (pa - 1.0); + r_ptr->logk[delta_v] = d_v; + if (!strcmp(r_ptr->token[0].name, "H2O(g)")) + r_ptr->logk[delta_v] = 0.0; + + return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_vm(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculate molar volumes for aqueous species with a Redlich type eqn: + Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I - kappaC * (pa - 1). + * Vm0(tc) = millero[0] + millero[1] * tc + millero[2] * tc^2 + * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. + Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av from calc_dielectrics(tc, pa). + if b_Av != 0, I^0.5 is constrained to ln(1 + b_Av * I^0.5) / b_Av. + (b_Av = logk[vm0 + 7]). + * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 + * kappaC = compression constant, cm3/mol/atm. + + * Read.cpp copies millero[0..6] into logk[vm0 + 0..6], or reads logk[vm0 + 0..7] directly with -Vm. + */ + for (int i = 0; i < count_s_x; i++) + { + if (!strcmp(s_x[i]->name, "H2O")) + { + s_x[i]->logk[vm_tc] = 18.016 / rho_0; + continue; + } + if (!s_x[i]->logk[vm0]) + continue; + /* the volume terms... */ + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; + if (pa > 1.0) + s_x[i]->rxn_x->logk[vm_tc] -= s_x[i]->logk[kappa] * (pa - 1.0); + + if (s_x[i]->z) + { + /* the ionic strength term * I^0.5... */ + if (s_x[i]->logk[b_Av] == 0) + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x); + else + { + /* limit the Debye-Hueckel slope by b... */ + LDBLE b = (s_x[i]->logk[b_Av] < 1e-5 ? 1e-5 : s_x[i]->logk[b_Av]); + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * + log(1 + b * sqrt(mu_x)) / b; + } + } + /* plus the volume terms * I... */ + s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->logk[vm3] + (s_x[i]->logk[vm4] + s_x[i]->logk[vm5] * tc) * tc) * mu_x; + + /* for calculating delta_v of the reaction... */ + s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; + } + return OK; +} +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ @@ -5486,8 +5760,13 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ /* * Calculates log k's for all species and pure_phases */ +#ifndef PHREEQC2 + if (same_model == TRUE && same_temperature == TRUE && same_pressure == TRUE && same_mu) + return (OK); +#else if (same_model == TRUE && same_temperature == TRUE && same_pressure == TRUE) return (OK); +#endif int i; LDBLE tempk = tc + 273.15; /* @@ -5495,6 +5774,10 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ */ /* calculate relative molar volumes for tc... */ rho_0 = calc_rho_0(tc, pa); +#ifndef PHREEQC2 + pa = patm_x; + calc_dielectrics(tc_x, pa); +#endif calc_vm(tc, pa); for (i = 0; i < count_s_x; i++) @@ -5514,9 +5797,16 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ { if (phases[i]->in == TRUE) { +#ifdef PHREEQC2 phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc + phases[i]->logk[vm2] * tc * tc); phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); +#else + phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - + (phases[i]->logk[vm0] + (phases[i]->logk[vm1] + phases[i]->logk[vm2] * tc) * tc - + phases[i]->logk[kappa] * (pa - 1)); + phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); +#endif } } /* @@ -5610,7 +5900,7 @@ save_model(void) (struct phase **) free_check_null(last_model.gas_phase); if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); last_model.count_gas_phase = (int) gas_phase_ptr->Get_gas_comps().size(); last_model.gas_phase = (struct phase **) PHRQ_malloc((size_t) last_model.count_gas_phase * @@ -5665,7 +5955,7 @@ save_model(void) last_model.si = (LDBLE *) free_check_null(last_model.si); if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); last_model.count_pp_assemblage = (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size(); last_model.pp_assemblage = (struct phase **) PHRQ_malloc((size_t) last_model.count_pp_assemblage * @@ -5711,36 +6001,36 @@ save_model(void) if (use.Get_surface_ptr() != NULL) { /* comps */ - last_model.count_surface_comp = use.Get_surface_ptr()->count_comps; + last_model.count_surface_comp = (int) use.Get_surface_ptr()->Get_surface_comps().size(); last_model.surface_comp = - (const char **) PHRQ_malloc((size_t) use.Get_surface_ptr()->count_comps * + (const char **) PHRQ_malloc(use.Get_surface_ptr()->Get_surface_comps().size() * sizeof(char *)); if (last_model.surface_comp == NULL) malloc_error(); - for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) { - last_model.surface_comp[i] = use.Get_surface_ptr()->comps[i].formula; + last_model.surface_comp[i] = string_hsave(use.Get_surface_ptr()->Get_surface_comps()[i].Get_formula().c_str()); } /* charge */ - last_model.count_surface_charge = use.Get_surface_ptr()->count_charge; + last_model.count_surface_charge = (int) use.Get_surface_ptr()->Get_surface_charges().size(); last_model.surface_charge = - (const char **) PHRQ_malloc((size_t) use.Get_surface_ptr()->count_charge * + (const char **) PHRQ_malloc( use.Get_surface_ptr()->Get_surface_charges().size() * sizeof(char *)); if (last_model.surface_charge == NULL) malloc_error(); - for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) { - last_model.surface_charge[i] = use.Get_surface_ptr()->charge[i].name; + last_model.surface_charge[i] = string_hsave(use.Get_surface_ptr()->Get_surface_charges()[i].Get_name().c_str()); } - last_model.dl_type = use.Get_surface_ptr()->dl_type; + last_model.dl_type = use.Get_surface_ptr()->Get_dl_type(); /*last_model.edl = use.Get_surface_ptr()->edl; */ - last_model.surface_type = use.Get_surface_ptr()->type; + last_model.surface_type = use.Get_surface_ptr()->Get_type(); } else { - last_model.dl_type = NO_DL; + last_model.dl_type = cxxSurface::NO_DL; /*last_model.edl = -1; */ - last_model.surface_type = UNKNOWN_DL; + last_model.surface_type = cxxSurface::UNKNOWN_DL; last_model.count_surface_comp = 0; last_model.surface_comp = NULL; last_model.count_surface_charge = 0; @@ -5820,7 +6110,7 @@ check_same_model(void) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (last_model.gas_phase == NULL) return (FALSE); if (last_model.count_gas_phase != (int) gas_phase_ptr->Get_gas_comps().size()) @@ -5868,7 +6158,7 @@ check_same_model(void) */ if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); if (last_model.count_pp_assemblage != (int) pp_assemblage_ptr->Get_pp_assemblage_comps().size()) return (FALSE); @@ -5908,28 +6198,28 @@ check_same_model(void) */ if (use.Get_surface_ptr() != NULL) { - if (last_model.count_surface_comp != use.Get_surface_ptr()->count_comps) + if (last_model.count_surface_comp != (int) use.Get_surface_ptr()->Get_surface_comps().size()) return (FALSE); - if (last_model.count_surface_charge != use.Get_surface_ptr()->count_charge) + if (last_model.count_surface_charge != (int) use.Get_surface_ptr()->Get_surface_charges().size()) return (FALSE); - if (last_model.dl_type != use.Get_surface_ptr()->dl_type) + if (last_model.dl_type != use.Get_surface_ptr()->Get_dl_type()) return (FALSE); /*if (last_model.edl != use.Get_surface_ptr()->edl) return(FALSE); */ - if (last_model.surface_type != use.Get_surface_ptr()->type) + if (last_model.surface_type != use.Get_surface_ptr()->Get_type()) return (FALSE); /* if (last_model.only_counter_ions != use.Get_surface_ptr()->only_counter_ions) return(FALSE); */ - for (i = 0; i < use.Get_surface_ptr()->count_comps; i++) + for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) { if (last_model.surface_comp[i] != - use.Get_surface_ptr()->comps[i].formula) + string_hsave(use.Get_surface_ptr()->Get_surface_comps()[i].Get_formula().c_str())) return (FALSE); } - for (i = 0; i < use.Get_surface_ptr()->count_charge; i++) + for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) { if (last_model.surface_charge[i] != - use.Get_surface_ptr()->charge[i].name) + string_hsave(use.Get_surface_ptr()->Get_surface_charges()[i].Get_name().c_str())) return (FALSE); } } @@ -5954,14 +6244,13 @@ build_min_exch(void) */ int j, k, jj; int row; - //struct exch_comp *comp_ptr; struct master *master_ptr; struct unknown *unknown_ptr; LDBLE coef; if (use.Get_exchange_ptr() == NULL) return (OK); - cxxExchange *ex_ptr = (cxxExchange *) use.Get_exchange_ptr(); + cxxExchange *ex_ptr = use.Get_exchange_ptr(); int n_user = ex_ptr->Get_n_user(); cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, n_user); if (exchange_ptr == NULL) @@ -5974,14 +6263,13 @@ build_min_exch(void) n_user = exchange_ptr->Get_n_user(); if (!exchange_ptr->Get_related_phases()) return (OK); - std::vector comps = exchange_ptr->Vectorize(); - for (size_t i = 0; i < comps.size(); i++) + for (size_t i = 0; i < exchange_ptr->Get_exchange_comps().size(); i++) { - cxxExchComp * comp_ptr = comps[i]; - if (comp_ptr->Get_phase_name().size() == 0) + cxxExchComp & comp_ref = exchange_ptr->Get_exchange_comps()[i]; + if (comp_ref.Get_phase_name().size() == 0) continue; // Find exchange master - cxxNameDouble nd(comp_ptr->Get_totals()); + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); struct master *exchange_master = NULL; for ( ; it != nd.end(); it++) @@ -5998,7 +6286,7 @@ build_min_exch(void) input_error++; error_string = sformatf( "Did not find master exchange species for %s", - comp_ptr->Get_formula().c_str()); + comp_ref.Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -6014,8 +6302,7 @@ build_min_exch(void) { if (x[k]->type != PP) continue; - //if (x[k]->phase->name == exchange[n].comps[i].phase_name) - if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + if (x[k]->phase->name == string_hsave(comp_ref.Get_phase_name().c_str())) break; } if (j == -1) @@ -6034,15 +6321,20 @@ build_min_exch(void) /* charge balance */ store_jacob0(charge_balance_unknown->number, x[k]->number, - comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + comp_ref.Get_formula_z() * comp_ref.Get_phase_proportion()); store_sum_deltas(&delta[k], &charge_balance_unknown->delta, - -comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + -comp_ref.Get_formula_z() * comp_ref.Get_phase_proportion()); /* mole balance balance */ count_elts = 0; paren_count = 0; - add_elt_list(comp_ptr->Get_formula_totals(), 1.0); + { + char * formula = string_duplicate(comp_ref.Get_formula().c_str()); + char * ptr = formula; + get_elts_in_species(&ptr, 1.0); + free_check_null(formula); + } #ifdef COMBINE change_hydrogen_in_elt_list(0); #endif @@ -6054,7 +6346,7 @@ build_min_exch(void) input_error++; error_string = sformatf( "Did not find unknown for exchange related to mineral %s", - comp_ptr->Get_phase_name().c_str()); + comp_ref.Get_phase_name().c_str()); error_msg(error_string, STOP); } if (master_ptr->in == FALSE) @@ -6066,12 +6358,150 @@ build_min_exch(void) if (equal (x[j]->moles, x[k]->moles * elt_list[jj].coef * - comp_ptr->Get_phase_proportion(), + comp_ref.Get_phase_proportion(), 5.0 * convergence_tolerance) == FALSE) { error_string = sformatf( "Resetting number of sites in exchanger %s (=%e) to be consistent with moles of phase %s (=%e).\n%s", master_ptr->s->name, (double) x[j]->moles, + comp_ref.Get_phase_name().c_str(), + (double) (x[k]->moles * elt_list[jj].coef * + comp_ref.Get_phase_proportion()), + "\tHas equilibrium_phase assemblage been redefined?\n"); + warning_msg(error_string); + x[j]->moles = + x[k]->moles * elt_list[jj].coef * + comp_ref.Get_phase_proportion(); + } + } + coef = elt_list[jj].coef; + if (master_ptr->s == s_hplus) + { + row = mass_hydrogen_unknown->number; + unknown_ptr = mass_hydrogen_unknown; + } + else if (master_ptr->s == s_h2o) + { + row = mass_oxygen_unknown->number; + unknown_ptr = mass_oxygen_unknown; + } + else + { + row = master_ptr->unknown->number; + unknown_ptr = master_ptr->unknown; + } + store_jacob0(row, x[k]->number, + coef * comp_ref.Get_phase_proportion()); + store_sum_deltas(&delta[k], &unknown_ptr->delta, + -coef * comp_ref.Get_phase_proportion()); + } + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +build_min_surface(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Defines proportionality factor between mineral and surface to + * jacob0 + */ + if (use.Get_surface_ptr() == NULL) + return (OK); + cxxSurface *surface_ptr = use.Get_surface_ptr(); + if (!surface_ptr->Get_related_phases()) + return (OK); + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) + { + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); + if (comp_ptr->Get_phase_name().size() == 0) + continue; + struct element *elt_ptr = element_store(comp_ptr->Get_master_element().c_str()); + /* find unknown number */ + int j; + for (j = count_unknowns - 1; j >= 0; j--) + { + if (x[j]->type != SURFACE) + continue; + if (x[j]->master[0] == elt_ptr->master) + break; + } + int k; + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + break; + } + if (j == -1) + { + input_error++; + error_string = sformatf( + "Did not find unknown for master surface species %s", + elt_ptr->master->s->name); + error_msg(error_string, CONTINUE); + } + if (j == -1 || k == -1) + continue; + + /* update grams == moles in this case */ + if (j < count_unknowns - 1 && x[j + 1]->type == SURFACE_CB) + { + store_sum_deltas(&delta[k], &(x[j + 1]->related_moles), -1.0); + } + + /* charge balance */ + store_jacob0(charge_balance_unknown->number, x[k]->number, + comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + store_sum_deltas(&delta[k], &charge_balance_unknown->delta, + -comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); + count_elts = 0; + paren_count = 0; + + if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) + { + /* Add formula for CD_MUSIC */ + char * formula = string_duplicate(comp_ptr->Get_formula().c_str()); + char *ptr1 = formula; + get_elts_in_species(&ptr1, 1.0); + free_check_null(formula); + } + else + { + /* Add master species for non CD_MUSIC */ + add_elt_list(x[j]->master[0]->s->next_elt, 1.0); + } +#ifdef COMBINE + change_hydrogen_in_elt_list(0); +#endif + for (int jj = 0; jj < count_elts; jj++) + { + struct master * master_ptr = elt_list[jj].elt->primary; + if (master_ptr->in == FALSE) + { + master_ptr = master_ptr->s->secondary; + } + if (master_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Did not find unknown for surface related to mineral %s", + comp_ptr->Get_phase_name().c_str()); + error_msg(error_string, STOP); + } + if (master_ptr->s->type == SURF) + { + if (equal + (x[j]->moles, + x[k]->moles * elt_list[jj].coef * + comp_ptr->Get_phase_proportion(), + 5.0 * convergence_tolerance) == FALSE) + { + error_string = sformatf( + "Resetting number of sites in surface %s (=%e) to be consistent with moles of phase %s (=%e).\n%s", + master_ptr->s->name, (double) x[j]->moles, comp_ptr->Get_phase_name().c_str(), (double) (x[k]->moles * elt_list[jj].coef * comp_ptr->Get_phase_proportion()), @@ -6082,7 +6512,9 @@ build_min_exch(void) comp_ptr->Get_phase_proportion(); } } - coef = elt_list[jj].coef; + LDBLE coef = elt_list[jj].coef; + int row; + struct unknown *unknown_ptr; if (master_ptr->s == s_hplus) { row = mass_hydrogen_unknown->number; @@ -6103,162 +6535,10 @@ build_min_exch(void) store_sum_deltas(&delta[k], &unknown_ptr->delta, -coef * comp_ptr->Get_phase_proportion()); } - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -build_min_surface(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Defines proportionality factor between mineral and surface to - * jacob0 - */ - int i, j, k, n, jj, row; - struct elt_list *next_elt; - struct surface_comp *comp_ptr; - struct unknown *unknown_ptr; - struct master *master_ptr; - LDBLE coef; - - if (use.Get_surface_ptr() == NULL) - return (OK); - if (surface_bsearch(use.Get_surface_ptr()->n_user, &n) == NULL) - { - input_error++; - error_string = sformatf( "Surface %d not found.", - use.Get_surface_ptr()->n_user); - error_msg(error_string, CONTINUE); - } - if (surface[n].related_phases == FALSE) - return (OK); - for (i = 0; i < surface[n].count_comps; i++) - { - if (surface[n].comps[i].phase_name == NULL) - continue; - - /* find unknown number */ - for (j = count_unknowns - 1; j >= 0; j--) - { - if (x[j]->type != SURFACE) - continue; - if (x[j]->master[0] == surface[n].comps[i].master) - break; - } - for (k = count_unknowns - 1; k >= 0; k--) - { - if (x[k]->type != PP) - continue; - if (x[k]->phase->name == surface[n].comps[i].phase_name) - break; - } - if (j == -1) - { - input_error++; - error_string = sformatf( - "Did not find unknown for master surface species %s", - surface[n].comps[i].master->s->name); - error_msg(error_string, CONTINUE); - } - if (j == -1 || k == -1) - continue; - - comp_ptr = x[j]->surface_comp; - - if (surface[n].type == CD_MUSIC) - { - /* Add formula for CD_MUSIC */ - next_elt = comp_ptr->formula_totals; - } - else - { - /* Add master species for non CD_MUSIC */ - next_elt = x[j]->master[0]->s->next_elt; - } - - - /* update grams == moles in this case */ - if (j < count_unknowns - 1 && x[j + 1]->type == SURFACE_CB) - { - store_sum_deltas(&delta[k], &(x[j + 1]->related_moles), -1.0); - } - - /* charge balance */ - store_jacob0(charge_balance_unknown->number, x[k]->number, - comp_ptr->formula_z * comp_ptr->phase_proportion); - store_sum_deltas(&delta[k], &charge_balance_unknown->delta, - -comp_ptr->formula_z * comp_ptr->phase_proportion); - - - count_elts = 0; - paren_count = 0; - add_elt_list(next_elt, 1.0); -#ifdef COMBINE - change_hydrogen_in_elt_list(0); -#endif - for (jj = 0; jj < count_elts; jj++) - { - master_ptr = elt_list[jj].elt->primary; - if (master_ptr->in == FALSE) - { - master_ptr = master_ptr->s->secondary; - } - if (master_ptr == NULL) - { - input_error++; - error_string = sformatf( - "Did not find unknown for surface related to mineral %s", - surface[n].comps[i].phase_name); - error_msg(error_string, STOP); - } - if (master_ptr->s->type == SURF) - { - if (equal - (x[j]->moles, - x[k]->moles * elt_list[jj].coef * - comp_ptr->phase_proportion, - 5.0 * convergence_tolerance) == FALSE) - { - error_string = sformatf( - "Resetting number of sites in surface %s (=%e) to be consistent with moles of phase %s (=%e).\n%s", - master_ptr->s->name, (double) x[j]->moles, - comp_ptr->phase_name, - (double) (x[k]->moles * elt_list[jj].coef * - comp_ptr->phase_proportion), - "\tHas equilibrium_phase assemblage been redefined?\n"); - warning_msg(error_string); - x[j]->moles = - x[k]->moles * elt_list[jj].coef * - comp_ptr->phase_proportion; - } - } - coef = elt_list[jj].coef; - if (master_ptr->s == s_hplus) - { - row = mass_hydrogen_unknown->number; - unknown_ptr = mass_hydrogen_unknown; - } - else if (master_ptr->s == s_h2o) - { - row = mass_oxygen_unknown->number; - unknown_ptr = mass_oxygen_unknown; - } - else - { - row = master_ptr->unknown->number; - unknown_ptr = master_ptr->unknown; - } - store_jacob0(row, x[k]->number, - coef * comp_ptr->phase_proportion); - store_sum_deltas(&delta[k], &unknown_ptr->delta, - -coef * comp_ptr->phase_proportion); - } } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: setup_related_surface(void) @@ -6267,56 +6547,60 @@ setup_related_surface(void) /* * Fill in data for surface assemblage in unknown structure */ - int i, k; - struct surface_comp *comp_ptr; - if (use.Get_surface_ptr() == NULL) return (OK); - if (use.Get_surface_ptr()->related_phases == FALSE) + if (!use.Get_surface_ptr()->Get_related_phases()) return (OK); - for (i = 0; i < count_unknowns; i++) + for (int i = 0; i < count_unknowns; i++) { - if (x[i]->type == SURFACE && x[i]->surface_comp->phase_name != NULL) + if (x[i]->type == SURFACE) { - for (k = count_unknowns - 1; k >= 0; k--) + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + if (comp_ptr->Get_phase_name().size() > 0) { - if (x[k]->type != PP) + int k; + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + break; + } + if (k == -1) continue; - if (x[k]->phase->name == x[i]->surface_comp->phase_name) - break; - } - if (k == -1) - continue; - comp_ptr = x[i]->surface_comp; - x[i]->phase_unknown = x[k]; + x[i]->phase_unknown = x[k]; /* !!!!! */ - x[i]->moles = x[k]->moles * comp_ptr->phase_proportion; + x[i]->moles = x[k]->moles * comp_ptr->Get_phase_proportion(); - } - else if (x[i]->type == SURFACE_CB - && x[i - 1]->surface_comp->phase_name != NULL) - { - for (k = count_unknowns - 1; k >= 0; k--) - { - if (x[k]->type != PP) - continue; - if (x[k]->phase->name == x[i]->surface_comp->phase_name) - break; } - if (k == -1) - continue; + } + else if (x[i]->type == SURFACE_CB) + { + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i-1]->surface_comp); + if (comp_ptr->Get_phase_name().size() > 0) + { + cxxSurfaceComp *comp_i_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); + int k; + for (k = count_unknowns - 1; k >= 0; k--) + { + if (x[k]->type != PP) + continue; + if (x[k]->phase->name == string_hsave(comp_i_ptr->Get_phase_name().c_str())) + break; + } + if (k == -1) + continue; - comp_ptr = x[i]->surface_comp; - x[i]->phase_unknown = x[k]; -/* !!!! Added for security, not checked... */ - x[i]->related_moles = x[k]->moles * comp_ptr->phase_proportion; + x[i]->phase_unknown = x[k]; + /* !!!! Added for security, not checked... */ + x[i]->related_moles = x[k]->moles * comp_i_ptr->Get_phase_proportion(); + } } } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: change_hydrogen_in_elt_list(LDBLE charge) diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 9d5e5ee7..da07498b 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -11,6 +11,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: array_print(LDBLE * array_l, int row_count, int column_count, @@ -94,8 +95,6 @@ int Phreeqc:: punch_all(void) /* ---------------------------------------------------------------------- */ { - //int i; - //#ifndef PHREEQ98 /* if not PHREEQ98 use the standard declaration */ // if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE) && user_graph->commands == NULL) // return (OK); @@ -113,12 +112,10 @@ punch_all(void) //#else /* if PHREEQ98 execute punch_user_graph first, that is, before punch.in and pr.punch is checked */ if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); } else if (use.Get_kinetics_in() != FALSE) { - //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); } #if defined PHREEQ98 @@ -134,7 +131,6 @@ punch_all(void) #endif if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) return (OK); -//#endif punch_identifiers(); punch_totals(); punch_molalities(); @@ -160,17 +156,15 @@ punch_all(void) return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -print_diffuse_layer(struct surface_charge *surface_charge_ptr1) +print_diffuse_layer(cxxSurfaceCharge *charge_ptr) /* ---------------------------------------------------------------------- */ { /* * Prints total moles of each element in diffuse layer * Remove comment to print total moles of each species */ - int i, j, count_g; LDBLE mass_water_surface, r, sum_surfs; LDBLE molality, moles_excess, moles_surface, d; @@ -179,22 +173,22 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) /* * Find position of component in surface charge data */ - i = 0; + int j; for (j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; - if (x[j]->surface_charge == surface_charge_ptr1) + cxxSurfaceCharge * charge_ptr_search = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + if (charge_ptr->Get_name() == charge_ptr_search->Get_name()) { break; } - i++; } if (j >= count_unknowns) { error_string = sformatf( "In print_diffuse_layer: component not found, %s.", - surface_charge_ptr1->name); + charge_ptr->Get_name().c_str()); error_msg(error_string, STOP); } /* @@ -204,7 +198,7 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) if (mass_water_surfaces_x != 0) { - d = 100 * surface_charge_ptr1->mass_water / mass_water_surfaces_x; + d = 100 * charge_ptr->Get_mass_water() / mass_water_surfaces_x; } else { @@ -212,22 +206,23 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) } output_msg(sformatf( "\tWater in diffuse layer: %8.3e kg, %4.1f%% of total DDL-water.\n", - (double) surface_charge_ptr1->mass_water, (double) d)); - if (use.Get_surface_ptr()->debye_lengths > 0) + (double) charge_ptr->Get_mass_water(), (double) d)); + if (use.Get_surface_ptr()->Get_debye_lengths() > 0) { sum_surfs = 0.0; for (j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; + cxxSurfaceCharge * charge_ptr_search = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); sum_surfs += - x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams; + charge_ptr_search->Get_specific_area() * + charge_ptr_search->Get_grams(); } r = 0.002 * mass_water_bulk_x / sum_surfs; output_msg(sformatf( "\tRadius of total pore: %8.3e m; of free pore: %8.3e m.\n", - (double) r, (double) (r - use.Get_surface_ptr()->thickness))); + (double) r, (double) (r - use.Get_surface_ptr()->Get_thickness()))); } if (debug_diffuse_layer == TRUE) @@ -237,7 +232,7 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) output_msg(sformatf( "\n\tSpecies \t Moles \tMoles excess\t g\n")); } - mass_water_surface = surface_charge_ptr1->mass_water; + mass_water_surface = charge_ptr->Get_mass_water(); count_elts = 0; paren_count = 0; for (j = 0; j < count_s_x; j++) @@ -245,19 +240,16 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) if (s_x[j]->type > HPLUS) continue; molality = under(s_x[j]->lm); - count_g = s_x[j]->diff_layer[i].count_g; - moles_excess = - mass_water_aq_x * molality * (surface_charge_ptr1->g[count_g].g * - s_x[j]->erm_ddl + - mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - - 1)); + moles_excess = mass_water_aq_x * molality * (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * + s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); moles_surface = mass_water_surface * molality + moles_excess; if (debug_diffuse_layer == TRUE) { output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", s_x[j]->name, moles_surface, moles_excess, - s_x[j]->diff_layer[i].charge->g[count_g].g)); + charge_ptr->Get_g_map()[s_x[j]->z].Get_g())); } /* * Accumulate elements in diffuse layer @@ -278,7 +270,7 @@ print_diffuse_layer(struct surface_charge *surface_charge_ptr1) /* * Print totals */ - if (use.Get_surface_ptr()->dl_type != DONNAN_DL) + if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) { output_msg(sformatf( "\n\tTotal moles in diffuse layer (excluding water)\n\n")); @@ -386,7 +378,6 @@ print_exchange(void) * Print moles of each exchange species */ int i; - //struct exchange *exchange_ptr; cxxExchange * exchange_ptr; const char *name, *name1; struct master *master_ptr; @@ -394,7 +385,7 @@ print_exchange(void) /* * Print exchange data */ - exchange_ptr = (cxxExchange *) use.Get_exchange_ptr(); + exchange_ptr = use.Get_exchange_ptr(); if (exchange_ptr == NULL || pr.exchange == FALSE || pr.all == FALSE) return (OK); @@ -434,22 +425,22 @@ print_exchange(void) output_msg(sformatf("%-14s%12.3e mol", name, (double) master_ptr->unknown->moles)); cxxExchange *exchange_ptr = (cxxExchange *) (use.Get_exchange_ptr()); - const cxxExchComp *exch_comp = exchange_ptr->ExchComp_find(master_ptr->unknown->exch_comp); - assert(exch_comp); - if (exch_comp->Get_phase_name().size() > 0) + const cxxExchComp *exchange_comp_ptr = exchange_ptr->Find_comp(master_ptr->unknown->exch_comp); + assert(exchange_comp_ptr); + if (exchange_comp_ptr->Get_phase_name().size() > 0) { output_msg(sformatf("\t[%g (mol %s)/(mol %s)]", - (double) exch_comp->Get_phase_proportion(), - exch_comp->Get_formula().c_str(), - exch_comp->Get_phase_name().c_str())); + (double) exchange_comp_ptr->Get_phase_proportion(), + exchange_comp_ptr->Get_formula().c_str(), + exchange_comp_ptr->Get_phase_name().c_str())); } - else if (exch_comp->Get_rate_name().size() > 0) + else if (exchange_comp_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( "\t[%g (mol %s)/(mol kinetic reactant %s)]", - (double) exch_comp->Get_phase_proportion(), - exch_comp->Get_formula().c_str(), - exch_comp->Get_rate_name().c_str())); + (double) exchange_comp_ptr->Get_phase_proportion(), + exchange_comp_ptr->Get_formula().c_str(), + exchange_comp_ptr->Get_rate_name().c_str())); } output_msg(sformatf("\n\n")); /* Heading for species */ @@ -508,7 +499,6 @@ print_gas_phase(void) /* * Prints gas phase composition if present */ - //int j; LDBLE lp, moles, initial_moles, delta_moles; struct rxn_token *rxn_ptr; char info[MAX_LENGTH]; @@ -519,7 +509,7 @@ print_gas_phase(void) if (use.Get_gas_phase_ptr() == NULL) return (OK); - cxxGasPhase *gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_v_m() >= 0.01) PR = true; if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) @@ -543,7 +533,6 @@ print_gas_phase(void) * Print heading */ print_centered("Gas phase"); - //output_msg(OUTPUT_MESSAGE, "\n"); output_msg(sformatf("Total pressure: %5.2f atmospheres", (double) gas_phase_ptr->Get_total_p())); if (PR) @@ -576,7 +565,6 @@ print_gas_phase(void) "log P", "P", "Initial", "Final", "Delta")); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - //for (j = 0; j < use.Get_gas_phase_ptr()->count_comps; j++) { /* * Calculate partial pressure @@ -784,7 +772,7 @@ print_reaction(void) return (OK); if (state == TRANSPORT && transport_step == 0) return (OK); - reaction_ptr = (cxxReaction *) use.Get_reaction_ptr(); + reaction_ptr = use.Get_reaction_ptr(); /* * Print amount of reaction */ @@ -798,12 +786,9 @@ print_reaction(void) */ output_msg(sformatf("\t%-15s%10s\n", " ", "Relative")); output_msg(sformatf("\t%-15s%10s\n\n", "Reactant", "moles")); - //for (i = 0; i < irrev_ptr->count_list; i++) cxxNameDouble::const_iterator cit = reaction_ptr->Get_reactantList().begin(); for ( ; cit != reaction_ptr->Get_reactantList().end(); cit++) { - //output_msg(sformatf("\t%-15s%13.5f\n", - // irrev_ptr->list[i].name, (double) irrev_ptr->list[i].coef)); output_msg(sformatf("\t%-15s%13.5f\n", cit->first.c_str(), (double) cit->second)); } @@ -814,7 +799,6 @@ print_reaction(void) output_msg(sformatf("\t%-15s%10s\n", " ", "Relative")); output_msg(sformatf("\t%-15s%10s\n", "Element", "moles")); - //for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) cit = reaction_ptr->Get_elementList().begin(); for ( ; cit != reaction_ptr->Get_elementList().end(); cit++) { @@ -836,7 +820,6 @@ print_kinetics(void) * prints kinetic reaction, * should be called only on final kinetic step */ - //int i, j; LDBLE sim_time; cxxKinetics *kinetics_ptr; if (pr.kinetics == FALSE || pr.all == FALSE) @@ -848,12 +831,10 @@ print_kinetics(void) { if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); } else { - //kinetics_ptr = kinetics_bsearch(-2, &i); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); } } @@ -907,40 +888,6 @@ print_kinetics(void) } } } -#ifdef SKIP - if (incremental_reactions == TRUE) - { - //if (kinetics_ptr->count_steps > 0) - if (!kinetics_ptr->Get_equalIncrements()) - { - for (i = 0; i < reaction_step; i++) - { - if (i < kinetics_ptr->count_steps) - { - sim_time += kinetics_ptr->steps[i]; - } - else - { - sim_time += - kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - sim_time = kinetics_ptr->steps[0]; - } - else - { - sim_time = - reaction_step * kinetics_ptr->steps[0] / - ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } -#endif } /* * Print amount of reaction @@ -996,7 +943,6 @@ print_kinetics(void) output_msg(sformatf("\t%-15s%12s%12s %-15s%12s\n\n", "Rate name", "Delta Moles", "Total Moles", "Reactant", "Coefficient")); - //for (i = 0; i < kinetics_ptr->count_comps; i++) for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) { cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); @@ -1015,7 +961,6 @@ print_kinetics(void) kinetics_comp_ptr->Get_initial_moles()), (double) kinetics_comp_ptr->Get_m())); } - //for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) { @@ -1039,177 +984,6 @@ print_kinetics(void) return (OK); } #ifdef SKIP -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -print_kinetics(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints kinetic reaction, - * should be called only on final kinetic step - */ - int i, j; - LDBLE sim_time; - struct kinetics *kinetics_ptr; - if (pr.kinetics == FALSE || pr.all == FALSE) - return (OK); - if (state < REACTION) - return (OK); - kinetics_ptr = NULL; - if (use.Get_kinetics_in() == TRUE) - { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) - { - kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); - } - else - { - kinetics_ptr = kinetics_bsearch(-2, &i); - } - } - if (kinetics_ptr == NULL) - return (OK); -/* - * determine time step - */ - if (state == TRANSPORT || state == PHAST) - { - kin_time_x = timest; - } - else if (state == ADVECTION) - { - kin_time_x = advection_kin_time; - } - sim_time = 0.; - if (run_info.Get_run_cells()) - { - sim_time = rate_sim_time; - } - else - { - if (incremental_reactions == TRUE) - { - if (kinetics_ptr->count_steps > 0) - { - for (i = 0; i < reaction_step; i++) - { - if (i < kinetics_ptr->count_steps) - { - sim_time += kinetics_ptr->steps[i]; - } - else - { - sim_time += - kinetics_ptr->steps[kinetics_ptr->count_steps - 1]; - } - } - } - else if (kinetics_ptr->count_steps < 0) - { - if (reaction_step > -kinetics_ptr->count_steps) - { - sim_time = kinetics_ptr->steps[0]; - } - else - { - sim_time = - reaction_step * kinetics_ptr->steps[0] / - ((LDBLE) (-kinetics_ptr->count_steps)); - } - } - } - } -/* - * Print amount of reaction - */ - if (phast == FALSE) - { - output_msg(sformatf("Kinetics %d.\t%s\n\n", - use.Get_n_kinetics_user(), kinetics_ptr->description)); - } - else - { - output_msg(sformatf("Kinetics.\n\n")); - } -/* - * Print reaction - */ - if (state == TRANSPORT) - { - output_msg(sformatf("\tTime: %g seconds\n", - (double) (initial_total_time + transport_step * timest))); - output_msg(sformatf("\tTime step: %g seconds\n\n", - (double) kin_time_x)); - } - else if (state == ADVECTION) - { - output_msg(sformatf("\tTime: %g seconds\n", - (double) (initial_total_time + - advection_step * advection_kin_time))); - output_msg(sformatf("\tTime step: %g seconds\n\n", - (double) kin_time_x)); - } - else if (state == PHAST) - { - output_msg(sformatf("\tTime: %g seconds\n", - (double) rate_sim_time_end)); - output_msg(sformatf("\tTime step: %g seconds\n\n", - (double) kin_time_x)); - } - else if (state == REACTION) - { - if (incremental_reactions == FALSE) - { - output_msg(sformatf("\tTime step: %g seconds\n\n", - (double) kin_time_x)); - } - else - { - output_msg(sformatf( - "\tTime step: %g seconds (Incremented time: %g seconds)\n\n", - (double) kin_time_x, (double) sim_time)); - } - } - output_msg(sformatf("\t%-15s%12s%12s %-15s%12s\n\n", - "Rate name", "Delta Moles", "Total Moles", "Reactant", - "Coefficient")); - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - if (state != TRANSPORT && state != PHAST) - { - output_msg(sformatf("\t%-15s%12.3e%12.3e", - kinetics_ptr->comps[i].rate_name, - (double) -kinetics_ptr->comps[i].moles, - (double) kinetics_ptr->comps[i].m)); - } - else - { - output_msg(sformatf("\t%-15s%12.3e%12.3e", - kinetics_ptr->comps[i].rate_name, - (double) (kinetics_ptr->comps[i].m - - kinetics_ptr->comps[i].initial_moles), - (double) kinetics_ptr->comps[i].m)); - } - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) - { - if (j == 0) - { - output_msg(sformatf(" %-15s%12g\n", - kinetics_ptr->comps[i].list[j].name, - (double) kinetics_ptr->comps[i].list[j].coef)); - } - else - { - output_msg(sformatf("\t%39s %-15s%12g\n", " ", - kinetics_ptr->comps[i].list[j].name, - (double) kinetics_ptr->comps[i].list[j].coef)); - } - } - } - output_msg(sformatf("\n")); - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_master_reactions(void) @@ -1255,7 +1029,7 @@ print_master_reactions(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_mix(void) @@ -1264,10 +1038,8 @@ print_mix(void) /* * prints definition of mixing, solution number and multiplier */ - int n; - //struct mix *mix_ptr; cxxMix * mix_ptr; - struct solution *solution_ptr; + cxxSolution *solution_ptr; if (pr.use == FALSE || pr.all == FALSE) return (OK); @@ -1275,17 +1047,15 @@ print_mix(void) return (OK); if (state == TRANSPORT) { - //mix_ptr = mix_bsearch(use.Get_n_mix_user(), &i); mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); } else { - //mix_ptr = mix_bsearch(use.Get_n_mix_user_orig(), &i); mix_ptr = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user_orig()); } if (mix_ptr == NULL) { - mix_ptr = (cxxMix *) use.Get_mix_ptr(); + mix_ptr = use.Get_mix_ptr(); } /* * Print mixture data @@ -1308,7 +1078,7 @@ print_mix(void) std::map::const_iterator cit; for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) { - solution_ptr = solution_bsearch(cit->first, &n, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, cit->first); if (solution_ptr == NULL) { input_error++; @@ -1316,7 +1086,7 @@ print_mix(void) } output_msg(sformatf("\t%11.3e Solution %d\t%-55s\n", (double) cit->second, - cit->first, solution[n]->description)); + cit->first, solution_ptr->Get_description().c_str())); } output_msg(sformatf("\n")); return (OK); @@ -1367,7 +1137,6 @@ print_saturation_indices(void) struct rxn_token *rxn_ptr; struct reaction *reaction_ptr; const char *pr_in; - //bool PR = false, DV = false, PR_inprint, gas = true; bool PR_inprint, gas = true; if (pr.saturation_indices == FALSE || pr.all == FALSE) @@ -1375,13 +1144,12 @@ print_saturation_indices(void) if (state == INITIAL_SOLUTION) { iap = 0; - for (rxn_ptr = pe_x[default_pe_x].rxn->token + 1; rxn_ptr->s != NULL; - rxn_ptr++) + for (size_t tok = 1; tok < pe_x[default_pe_x].Get_tokens().size(); tok++) { - iap += rxn_ptr->coef * rxn_ptr->s->la; + iap += pe_x[default_pe_x].Get_tokens()[tok].coef * pe_x[default_pe_x].Get_tokens()[tok].s->la; /* fprintf(output,"\t%s\t%f\t%f\n", rxn_ptr->s->name, rxn_ptr->coef, rxn_ptr->s->la ); */ } - lk = k_calc(pe_x[default_pe_x].rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); + lk = k_calc(pe_x[default_pe_x].Get_logk(), tk_x, patm_x * PASCAL_PER_ATM); la_eminus = lk + iap; /* fprintf(output,"\t%s\t%f\n", "pe", si ); */ } @@ -1392,7 +1160,7 @@ print_saturation_indices(void) /* If a fixed pressure gas-phase disappeared, no PR for the SI's of gases... */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { if (gas_unknown == NULL || gas_unknown->moles < 1e-12) @@ -1425,7 +1193,6 @@ print_saturation_indices(void) PR_inprint = true; phases[i]->pr_in = false; } - //lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); reaction_ptr->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc_x + phases[i]->logk[vm2] * tc_x * tc_x); lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); @@ -1445,41 +1212,18 @@ print_saturation_indices(void) } } si = -lk + iap; - //if (gas && phases[i]->pr_in && phases[i]->pr_p) - //{ - // pr_in = "**"; - // PR = true; - //} - //else if (fabs(reaction_ptr->logk[delta_v]) > 0.01 && patm_x > 1) - //{ - // pr_in = "* "; - // DV = true; - //} - //else - pr_in = " "; + pr_in = " "; output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, phases[i]->formula)); - //if (fabs(reaction_ptr->logk[delta_v]) > 0.01 && patm_x > 1) - // output_msg(sformatf("\t%s%6.2f%s", - // " Delta_V ", reaction_ptr->logk[delta_v], " cm3/mol")); if (gas && phases[i]->pr_in && phases[i]->pr_p) output_msg(sformatf("\t%s%5.1f%s%5.3f%s", " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); output_msg("\n"); } - //if (DV) - // output_msg(sformatf("\t%24s %s\n", - // "* ", "with Delta_V * (P - 1) / 2.3RT.")); - //if (PR) - // output_msg(sformatf("\t%24s %s\n", - // "**", "SI from Peng-Robinson fugacity - Delta_V * (P - 1) / 2.3RT.")); - //if (PR || DV) - // output_msg("\n"); - //else - output_msg("\n\n"); + output_msg("\n\n"); return (OK); } @@ -1496,7 +1240,6 @@ print_pp_assemblage(void) char token[MAX_LENGTH]; struct rxn_token *rxn_ptr; struct phase *phase_ptr; - //bool PR = false, PR_inprint; bool PR_inprint; const char *pr_in; @@ -1504,7 +1247,7 @@ print_pp_assemblage(void) return (OK); if (pure_phase_unknown == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Print heading */ @@ -1563,13 +1306,7 @@ print_pp_assemblage(void) si = -x[j]->phase->lk + iap; output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) x[j]->phase->lk); */ - //if (phase_ptr->pr_in && phase_ptr->pr_p) - //{ - // pr_in = "**"; - // PR = true; - //} - //else - pr_in = " "; + pr_in = " "; output_msg(sformatf("%-14s%8.2f%2s%7.2f %8.2f", x[j]->phase->name, (double) si, pr_in, (double) iap, (double) lk)); @@ -1611,9 +1348,6 @@ print_pp_assemblage(void) comp_ptr->Get_add_formula().c_str(), " is reactant", token)); } } - //if (PR) - // output_msg(sformatf("%25s %s\n", - // "**", "SI from Peng-Robinson fugacity - Delta(V) * (P - 1) / 2.3RT.")); output_msg("\n"); return (OK); } @@ -1737,7 +1471,6 @@ print_species(void) output_msg(sformatf("\n")); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: print_surface(void) @@ -1748,19 +1481,17 @@ print_surface(void) * grams and specific area, moles of each species on surface sites, * and description of diffuse layer if applicable. */ - int i, j, k; - struct surface *surface_ptr; - char name[MAX_LENGTH], token[MAX_LENGTH]; + cxxSurface *surface_ptr; + std::string name, token; struct master *master_ptr; LDBLE molfrac, charge; - char *ptr; /* * Print surface speciation */ surface_ptr = use.Get_surface_ptr(); if (surface_ptr == NULL || pr.surface == FALSE || pr.all == FALSE) return (OK); - if (surface_ptr->type == CD_MUSIC) + if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) return (print_surface_cd_music()); if (state >= REACTION) @@ -1772,55 +1503,57 @@ print_surface(void) */ s_h2o->lm = s_h2o->la; - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { /*if (use.Get_surface_ptr()->edl == TRUE) { */ - if (use.Get_surface_ptr()->type == DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) { if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); + name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); } else { if (x[j]->type != SURFACE) continue; - strcpy(token, x[j]->master[0]->elt->name); - replace("_", " ", token); - ptr = token; - copy_token(name, &ptr, &k); + token = x[j]->master[0]->elt->name; + Utilities::replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + CParser::copy_token(name, b, e); } - output_msg(sformatf("%-14s\n", name)); + output_msg(sformatf("%-14s\n", name.c_str())); /* * Description of surface */ - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { output_msg(sformatf( "\t%11.3e Surface + diffuse layer charge, eq\n", (double) x[j]->f)); } /*if (use.Get_surface_ptr()->edl == TRUE && diffuse_layer_x == FALSE) { */ - if (use.Get_surface_ptr()->type == DDL && dl_type_x == NO_DL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL && dl_type_x == cxxSurface::NO_DL) { charge = x[j]->f; } else { - charge = calc_surface_charge(name); + charge = calc_surface_charge(name.c_str()); } output_msg(sformatf("\t%11.3e Surface charge, eq\n", (double) charge)); if (x[j]->type == SURFACE_CB) { - if ((x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) > 0) + cxxSurfaceCharge * charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); + if ((charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) > 0) { output_msg(sformatf("\t%11.3e sigma, C/m**2\n", (double) (charge * F_C_MOL / - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams)))); + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams())))); } else { @@ -1833,49 +1566,50 @@ print_surface(void) (double) (x[j]->master[0]->s->la * (-2) * LOG_10))); output_msg(sformatf("\t%11.3e exp(-F*psi/RT)\n", exp(x[j]->master[0]->s->la * (-2) * LOG_10))); - if (x[j]->surface_comp->phase_name != NULL) + cxxSurfaceComp * comp_ptr = surface_ptr->Find_comp(x[j]->surface_comp); + if (comp_ptr->Get_phase_name().size() > 0) { output_msg(sformatf( "\t%11.3e specific area, m**2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->phase_name)); + (double) charge_ptr->Get_specific_area(), + comp_ptr->Get_phase_name().c_str())); output_msg(sformatf( "\t%11.3e m**2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * - x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->phase_name)); + (double) (charge_ptr->Get_grams() * + charge_ptr->Get_specific_area()), + (double) charge_ptr->Get_grams(), + comp_ptr->Get_phase_name().c_str())); } - else if (x[j]->surface_comp->rate_name != NULL) + else if (comp_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( "\t%11.3e specific area, m**2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->rate_name)); + (double) charge_ptr->Get_specific_area(), + comp_ptr->Get_rate_name().c_str())); output_msg(sformatf( "\t%11.3e m**2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * - x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->rate_name)); + (double) (charge_ptr->Get_grams() * + charge_ptr->Get_specific_area()), + (double) charge_ptr->Get_grams(), + comp_ptr->Get_rate_name().c_str())); } else { output_msg(sformatf( "\t%11.3e specific area, m**2/g\n", - (double) x[j]->surface_charge->specific_area)); + (double) charge_ptr->Get_specific_area())); output_msg(sformatf("\t%11.3e m**2 for %11.3e g\n\n", - (double) (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams), - (double) x[j]->surface_charge->grams)); + (double) (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()), + (double) charge_ptr->Get_grams())); } - if (dl_type_x != NO_DL) - print_diffuse_layer(x[j]->surface_charge); + if (dl_type_x != cxxSurface::NO_DL) + print_diffuse_layer(charge_ptr); output_msg(sformatf("\n")); /* * Heading for species */ - for (k = j - 1; k < count_unknowns; k++) + for (int k = j - 1; k < count_unknowns; k++) { if (x[k]->type != SURFACE) continue; @@ -1886,18 +1620,19 @@ print_surface(void) x[k]->master[0]->elt->name)); output_msg(sformatf("\t%11.3e moles", (double) x[k]->moles)); - if (x[k]->surface_comp->phase_name != NULL) + cxxSurfaceComp * comp_k_ptr = surface_ptr->Find_comp(x[k]->surface_comp); + if (comp_k_ptr->Get_phase_name().size() > 0) { output_msg(sformatf("\t[%g mol/(mol %s)]\n", - (double) x[k]->surface_comp->phase_proportion, - x[k]->surface_comp->phase_name)); + (double) comp_k_ptr->Get_phase_proportion(), + comp_k_ptr->Get_phase_name().c_str())); } - else if (x[k]->surface_comp->rate_name != NULL) + else if (comp_k_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( "\t[%g mol/(mol kinetic reactant %s)]\n", - (double) x[k]->surface_comp->phase_proportion, - x[k]->surface_comp->rate_name)); + (double) comp_k_ptr->Get_phase_proportion(), + comp_k_ptr->Get_rate_name().c_str())); } else { @@ -1908,7 +1643,7 @@ print_surface(void) output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (i = 0; i < count_species_list; i++) + for (int i = 0; i < count_species_list; i++) { if (species_list[i].master_s != master_ptr->s) continue; @@ -1940,7 +1675,7 @@ print_surface(void) } else { - k = j; + int k = j; master_ptr = x[k]->master[0]; output_msg(sformatf("%-14s\n", x[k]->master[0]->elt->name)); output_msg(sformatf("\t%11.3e moles\n", @@ -1950,7 +1685,7 @@ print_surface(void) output_msg(sformatf("\t%-15s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (i = 0; i < count_species_list; i++) + for (int i = 0; i < count_species_list; i++) { if (species_list[i].master_s != master_ptr->s) continue; @@ -1992,14 +1727,11 @@ print_surface_cd_music(void) * grams and specific area, moles of each species on surface sites, * and description of diffuse layer if applicable. */ - int i, j, k; - struct surface *surface_ptr; - char name[MAX_LENGTH]; + cxxSurface *surface_ptr; + std::string name; struct master *master_ptr, *master_ptr0, *master_ptr1, *master_ptr2; struct unknown *unknown_ptr0, *unknown_ptr1, *unknown_ptr2; LDBLE molfrac, charge0, charge1, charge2, sum; - - /* * Print surface speciation */ @@ -2016,47 +1748,48 @@ print_surface_cd_music(void) */ s_h2o->lm = s_h2o->la; - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { if (x[j]->type != SURFACE_CB) continue; - strcpy(name, x[j]->master[0]->elt->name); - replace("_psi", "", name); - output_msg(sformatf("%-14s\n", name)); + name = x[j]->master[0]->elt->name; + Utilities::replace("_psi", "", name); + output_msg(sformatf("%-14s\n", name.c_str())); + cxxSurfaceCharge * charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); /* * Description of surface */ - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { output_msg(sformatf( "\t%11.3e Surface + diffuse layer charge, eq\n\n", - (double) (x[j + 2]->f + (x[j]->surface_charge->sigma0 + x[j]->surface_charge->sigma1) * (x[j]->surface_charge->specific_area * x[j]->surface_charge->grams) / F_C_MOL))); + (double) (x[j + 2]->f + (charge_ptr->Get_sigma0() + charge_ptr->Get_sigma1()) * (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()) / F_C_MOL))); } master_ptr0 = - surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI); + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI); master_ptr1 = - surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI1); + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI1); master_ptr2 = - surface_get_psi_master(x[j]->surface_charge->name, SURF_PSI2); + surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI2); unknown_ptr0 = x[master_ptr0->unknown->number]; unknown_ptr1 = x[master_ptr1->unknown->number]; unknown_ptr2 = x[master_ptr2->unknown->number]; charge0 = unknown_ptr0->f; charge1 = unknown_ptr1->f; - if (dl_type_x != NO_DL) + if (dl_type_x != cxxSurface::NO_DL) { charge2 = - x[j]->surface_charge->sigma2 * - (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) / F_C_MOL; + charge_ptr->Get_sigma2() * + (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) / F_C_MOL; } else { charge2 = unknown_ptr2->f; } sum = 0; - for (k = 0; k < x[j]->count_comp_unknowns; k++) + for (int k = 0; k < x[j]->count_comp_unknowns; k++) { sum += x[j]->comp_unknowns[k]->moles * @@ -2073,21 +1806,21 @@ print_surface_cd_music(void) (double) (charge0 + sum + charge1 + charge2))); if (x[j]->type == SURFACE_CB) { - if ((x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams) > 0) + if ((charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()) > 0) { output_msg(sformatf( "\t%11.3e sigma, plane 0, C/m**2\n", - (double) x[j]->surface_charge->sigma0)); + (double) charge_ptr->Get_sigma0())); output_msg(sformatf( "\t%11.3e sigma, plane 1, C/m**2\n", - (double) x[j]->surface_charge->sigma1)); + (double) charge_ptr->Get_sigma1())); output_msg(sformatf( "\t%11.3e sigma, plane 2, C/m**2\n", - (double) x[j]->surface_charge->sigma2)); + (double) charge_ptr->Get_sigma2())); output_msg(sformatf( "\t%11.3e sigma, diffuse layer, C/m**2\n\n", - (double) x[j]->surface_charge->sigmaddl)); + (double) charge_ptr->Get_sigmaddl())); } else { @@ -2108,53 +1841,53 @@ print_surface_cd_music(void) (double) (exp(master_ptr2->s->la * LOG_10)))); output_msg(sformatf("\t%11.3e capacitance 0-1, F/m^2\n", - (double) (x[j]->surface_charge->capacitance[0]))); + (double) (charge_ptr->Get_capacitance0()))); output_msg(sformatf("\t%11.3e capacitance 1-2, F/m^2\n", - (double) (x[j]->surface_charge->capacitance[1]))); - - if (x[j]->surface_comp->phase_name != NULL) + (double) (charge_ptr->Get_capacitance1()))); + cxxSurfaceComp * comp_ptr = surface_ptr->Find_comp(x[j]->surface_comp); + if (comp_ptr->Get_phase_name().size() > 0) { output_msg(sformatf( "\t%11.3e specific area, m^2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->phase_name)); + (double) charge_ptr->Get_specific_area(), + comp_ptr->Get_phase_name().c_str())); output_msg(sformatf( "\t%11.3e m^2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * - x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->phase_name)); + (double) (charge_ptr->Get_grams() * + charge_ptr->Get_specific_area()), + (double) charge_ptr->Get_grams(), + comp_ptr->Get_phase_name().c_str())); } - else if (x[j]->surface_comp->rate_name != NULL) + else if (comp_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( "\t%11.3e specific area, m^2/mol %s\n", - (double) x[j]->surface_charge->specific_area, - x[j]->surface_comp->rate_name)); + (double) charge_ptr->Get_specific_area(), + comp_ptr->Get_rate_name().c_str())); output_msg(sformatf( "\t%11.3e m^2 for %11.3e moles of %s\n\n", - (double) (x[j]->surface_charge->grams * - x[j]->surface_charge->specific_area), - (double) x[j]->surface_charge->grams, - x[j]->surface_comp->rate_name)); + (double) (charge_ptr->Get_grams() * + charge_ptr->Get_specific_area()), + (double) charge_ptr->Get_grams(), + comp_ptr->Get_rate_name().c_str())); } else { output_msg(sformatf( "\t%11.3e specific area, m^2/g\n", - (double) x[j]->surface_charge->specific_area)); + (double) charge_ptr->Get_specific_area())); output_msg(sformatf("\t%11.3e m^2 for %11.3e g\n\n", - (double) (x[j]->surface_charge->specific_area * - x[j]->surface_charge->grams), - (double) x[j]->surface_charge->grams)); + (double) (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()), + (double) charge_ptr->Get_grams())); } - if (dl_type_x != NO_DL) - print_diffuse_layer(x[j]->surface_charge); + if (dl_type_x != cxxSurface::NO_DL) + print_diffuse_layer(charge_ptr); output_msg(sformatf("\n")); /* * Heading for species */ - for (k = j - 1; k < count_unknowns; k++) + for (int k = j - 1; k < count_unknowns; k++) { if (x[k]->type != SURFACE) continue; @@ -2165,18 +1898,19 @@ print_surface_cd_music(void) x[k]->master[0]->elt->name)); output_msg(sformatf("\t%11.3e moles", (double) x[k]->moles)); - if (x[k]->surface_comp->phase_name != NULL) + cxxSurfaceComp * comp_k_ptr = surface_ptr->Find_comp(x[k]->surface_comp); + if (comp_k_ptr->Get_phase_name().size() > 0) { output_msg(sformatf("\t[%g mol/(mol %s)]\n", - (double) x[k]->surface_comp->phase_proportion, - x[k]->surface_comp->phase_name)); + (double) comp_k_ptr->Get_phase_proportion(), + comp_k_ptr->Get_phase_name().c_str())); } - else if (x[k]->surface_comp->rate_name != NULL) + else if (comp_k_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( "\t[%g mol/(mol kinetic reactant %s)]\n", - (double) x[k]->surface_comp->phase_proportion, - x[k]->surface_comp->rate_name)); + (double) comp_k_ptr->Get_phase_proportion(), + comp_k_ptr->Get_rate_name().c_str())); } else { @@ -2187,7 +1921,7 @@ print_surface_cd_music(void) output_msg(sformatf("\t%-20s%12s%12s%12s%12s\n\n", "Species", "Moles", "Fraction", "Molality", "Molality")); - for (i = 0; i < count_species_list; i++) + for (int i = 0; i < count_species_list; i++) { if (species_list[i].master_s != master_ptr->s) continue; @@ -2243,7 +1977,7 @@ print_totals(void) if (x[i] == alkalinity_unknown) { output_msg(sformatf("\t%-15s%12.3e%12.3e\n", - x[i]->total->description, + "Alkalinity", (double) (x[i]->f / mass_water_aq_x), (double) x[i]->f)); pure_water = FALSE; @@ -2436,12 +2170,10 @@ print_user_print(void) kinetics_ptr = use.Get_kinetics_ptr(); if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user())); } else { - //use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); } } @@ -2470,63 +2202,7 @@ print_user_print(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -print_user_print(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Print with user defined BASIC print routine - */ - int i; - struct kinetics *kinetics_ptr; - char l_command[] = "run"; - - if (pr.user_print == FALSE || pr.all == FALSE) - return (OK); - if (user_print->commands == NULL) - return (OK); - kinetics_ptr = NULL; - if (use.Get_kinetics_in() == TRUE) - { - kinetics_ptr = use.Get_kinetics_ptr(); - if (state == TRANSPORT || state == PHAST || state == ADVECTION) - { - use.Set_kinetics_ptr(kinetics_bsearch(use.Get_n_kinetics_user(), &i)); - } - else - { - use.Set_kinetics_ptr(kinetics_bsearch(-2, &i)); - } - } - print_centered("User print"); - if (user_print->new_def == TRUE) - { - /* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */ - if (basic_compile - (user_print->commands, &user_print->linebase, - &user_print->varbase, &user_print->loopbase) != 0) - { - error_msg("Fatal Basic error in USER_PRINT.", STOP); - } - user_print->new_def = FALSE; - } - if (basic_run - (l_command, user_print->linebase, user_print->varbase, - user_print->loopbase) != 0) - { - error_msg("Fatal Basic error in USER_PRINT.", STOP); - } - output_msg(sformatf("\n")); - if (use.Get_kinetics_in() == TRUE) - { - use.Set_kinetics_ptr(kinetics_ptr); - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: print_using(void) @@ -2535,17 +2211,8 @@ print_using(void) /* * Print entities used in calculation */ - //struct mix *mix_ptr; cxxMix * mix_ptr; - struct solution *solution_ptr; - //struct exchange *exchange_ptr; - struct surface *surface_ptr; - //struct pp_assemblage *pp_assemblage_ptr; - //struct ss_assemblage *ss_assemblage_ptr; - //struct gas_phase *gas_phase_ptr; - //struct irrev *irrev_ptr; - //struct kinetics *kinetics_ptr; - int n; + cxxSolution *solution_ptr; if (pr.use == FALSE || pr.all == FALSE) return (OK); @@ -2566,7 +2233,7 @@ print_using(void) } if (mix_ptr == NULL) { - mix_ptr = (cxxMix *) use.Get_mix_ptr(); + mix_ptr = use.Get_mix_ptr(); } if (mix_ptr != NULL) { @@ -2585,28 +2252,27 @@ print_using(void) } else { - solution_ptr = solution_bsearch(use.Get_n_solution_user(), &n, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, use.Get_n_solution_user()); output_msg(sformatf("Using solution %d.\t%s\n", - use.Get_n_solution_user(), solution_ptr->description)); + use.Get_n_solution_user(), solution_ptr->Get_description().c_str())); } /* * Exchange and surface */ - if (use.Get_exchange_in() == TRUE) + if (use.Get_exchange_in()) { cxxExchange *exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); output_msg(sformatf("Using exchange %d.\t%s\n", use.Get_n_exchange_user(), exchange_ptr->Get_description().c_str())); } - if (use.Get_surface_in() == TRUE) + if (use.Get_surface_in()) { - surface_ptr = surface_bsearch(use.Get_n_surface_user(), &n); + cxxSurface *surface_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); output_msg(sformatf("Using surface %d.\t%s\n", - use.Get_n_surface_user(), surface_ptr->description)); + use.Get_n_surface_user(), surface_ptr->Get_description().c_str())); } if (use.Get_pp_assemblage_in() == TRUE) { - //pp_assemblage_ptr = pp_assemblage_bsearch(use.Get_n_pp_assemblage_user(), &n); cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_pp_assemblage_user()); output_msg(sformatf("Using pure phase assemblage %d.\t%s\n", use.Get_n_pp_assemblage_user(), pp_assemblage_ptr->Get_description().c_str())); @@ -2619,46 +2285,42 @@ print_using(void) use.Get_n_ss_assemblage_user(), ss_assemblage_ptr->Get_description().c_str())); } - if (use.Get_gas_phase_in() == TRUE) + if (use.Get_gas_phase_in()) { - //gas_phase_ptr = gas_phase_bsearch(use.Get_n_gas_phase_user(), &n); cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, use.Get_n_gas_phase_user()); output_msg(sformatf("Using gas phase %d.\t%s\n", use.Get_n_gas_phase_user(), gas_phase_ptr->Get_description().c_str())); } - if (use.Get_temperature_in() == TRUE) + if (use.Get_temperature_in()) { cxxTemperature *temperature_ptr = Utilities::Rxn_find(Rxn_temperature_map, use.Get_n_temperature_user()); output_msg(sformatf("Using temperature %d.\t%s\n", use.Get_n_temperature_user(), temperature_ptr->Get_description().c_str())); } - if (use.Get_pressure_in() == TRUE) + if (use.Get_pressure_in()) { cxxPressure *pressure_ptr = Utilities::Rxn_find(Rxn_pressure_map, use.Get_n_pressure_user()); output_msg(sformatf("Using pressure %d.\t%s\n", use.Get_n_pressure_user(), pressure_ptr->Get_description().c_str())); } - if (use.Get_reaction_in() == TRUE) + if (use.Get_reaction_in()) { if (state != TRANSPORT || transport_step > 0) { - //irrev_ptr = irrev_bsearch(use.n_irrev_user, &n); cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); output_msg(sformatf("Using reaction %d.\t%s\n", use.Get_n_reaction_user(), reaction_ptr->Get_description().c_str())); } } - if (use.Get_kinetics_in() == TRUE) + if (use.Get_kinetics_in()) { cxxKinetics * kinetics_ptr; if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &n); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); } else { - //kinetics_ptr = kinetics_bsearch(-2, &n); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); } output_msg(sformatf("Using kinetics %d.\t%s\n", @@ -2685,7 +2347,7 @@ punch_gas_phase(void) p = 0.0; total_moles = 0.0; volume = 0.0; - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (gas_unknown != NULL && use.Get_gas_phase_ptr() != NULL) { if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) @@ -2719,7 +2381,6 @@ punch_gas_phase(void) if (gas_phase_ptr != NULL && punch.gases[i].phase != NULL) { for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - //for (j = 0; j < use.Get_gas_phase_ptr()->count_comps; j++) { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]); int k; @@ -2939,7 +2600,7 @@ punch_pp_assemblage(void) */ int i, j; LDBLE moles, delta_moles; - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < punch.count_pure_phases; i++) { delta_moles = 0; @@ -3088,7 +2749,7 @@ punch_identifiers(void) } else if (state < REACTION) { - fpunchf(PHAST_NULL("soln"), dformat, use.Get_solution_ptr()->n_user); + fpunchf(PHAST_NULL("soln"), dformat, use.Get_solution_ptr()->Get_n_user()); } else { @@ -3126,44 +2787,6 @@ punch_identifiers(void) fpunchf(PHAST_NULL("dist_x"), dformat, -99); } } - /* - //if (punch.time == TRUE) - //{ - // if (state == REACTION && incremental_reactions == TRUE - // && use.Get_kinetics_ptr() != NULL) - // { - // if (use.Get_kinetics_ptr()->count_steps > 0) - // { - // kin_time_x = 0.; - // for (i = 0; i < reaction_step; i++) - // { - // if (i < use.Get_kinetics_ptr()->count_steps) - // { - // kin_time_x += use.Get_kinetics_ptr()->steps[i]; - // } - // else - // { - // kin_time_x += - // use.Get_kinetics_ptr()->steps[use.Get_kinetics_ptr()-> - // count_steps - 1]; - // } - // } - // } - // else if (use.Get_kinetics_ptr()->count_steps < 0) - // { - // if (reaction_step > -use.Get_kinetics_ptr()->count_steps) - // { - // kin_time_x = use.Get_kinetics_ptr()->steps[0]; - // } - // else - // { - // kin_time_x = - // reaction_step * use.Get_kinetics_ptr()->steps[0] / - // ((LDBLE) (-use.Get_kinetics_ptr()->count_steps)); - // } - // } - // } - */ if (punch.time == TRUE) { LDBLE reaction_time = kin_time_x; @@ -3175,7 +2798,6 @@ punch_identifiers(void) reaction_time = 0.0; for (i = 0; i < reaction_step; i++) { - //if (i < use.Get_kinetics_ptr()->count_steps) if (i < (int) use.Get_kinetics_ptr()->Get_steps().size()) { reaction_time += use.Get_kinetics_ptr()->Get_steps()[i]; @@ -3200,37 +2822,6 @@ punch_identifiers(void) ((LDBLE) (use.Get_kinetics_ptr()->Get_count())); } } -#ifdef SKIP - if (use.Get_kinetics_ptr()->count_steps > 0) - { - reaction_time = 0.0; - for (i = 0; i < reaction_step; i++) - { - if (i < use.Get_kinetics_ptr()->count_steps) - { - reaction_time += use.Get_kinetics_ptr()->steps[i]; - } - else - { - reaction_time += - use.Get_kinetics_ptr()->steps[use.Get_kinetics_ptr()->count_steps - 1]; - } - } - } - else if (use.Get_kinetics_ptr()->count_steps < 0) - { - if (reaction_step > -use.Get_kinetics_ptr()->count_steps) - { - reaction_time = use.Get_kinetics_ptr()->steps[0]; - } - else - { - reaction_time = - reaction_step * use.Get_kinetics_ptr()->steps[0] / - ((LDBLE) (-use.Get_kinetics_ptr()->count_steps)); - } - } -#endif } if (state == REACTION) { @@ -3454,7 +3045,6 @@ punch_kinetics(void) * prints kinetic reaction, * should be called only on final kinetic step */ - //int i, j; cxxKinetics *kinetics_ptr; LDBLE moles, delta_moles; @@ -3463,12 +3053,10 @@ punch_kinetics(void) { if (state == TRANSPORT || state == PHAST || state == ADVECTION) { - //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); } else { - //kinetics_ptr = kinetics_bsearch(-2, &i); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); } } @@ -3518,79 +3106,6 @@ punch_kinetics(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -punch_kinetics(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * prints kinetic reaction, - * should be called only on final kinetic step - */ - int i, j; - struct kinetics *kinetics_ptr; - LDBLE moles, delta_moles; - - kinetics_ptr = NULL; - if (use.Get_kinetics_in() == TRUE) - { - if (state == TRANSPORT || state == PHAST || state == ADVECTION) - { - //kinetics_ptr = kinetics_bsearch(use.Get_n_kinetics_user(), &i); - kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); - } - else - { - kinetics_ptr = kinetics_bsearch(-2, &i); - } - } - for (i = 0; i < punch.count_kinetics; i++) - { - moles = 0.0; - delta_moles = 0.0; - if (kinetics_ptr != NULL) - { - for (j = 0; j < kinetics_ptr->count_comps; j++) - { - if (strcmp_nocase - (punch.kinetics[i].name, - kinetics_ptr->comps[j].rate_name) == 0) - { - if (state != TRANSPORT && state != PHAST) - { - moles = kinetics_ptr->comps[j].m; - delta_moles = -kinetics_ptr->comps[j].moles; - } - else - { - moles = kinetics_ptr->comps[j].m; - delta_moles = - kinetics_ptr->comps[j].m - - kinetics_ptr->comps[j].initial_moles; - } - break; - } - } - } - if (punch.high_precision == FALSE) - { - fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t", - (double) moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t", - (double) -delta_moles); - } - else - { - fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t", - (double) moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t", - (double) -delta_moles); - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_user_punch(void) @@ -3833,54 +3348,9 @@ punch_user_graph(void) } #endif // MULTICHART -//char * Phreeqc:: -//sformatf(const char *format, ...) -//{ -//#if defined(HDF5_CREATE) || defined SWIG_SHARED_OBJ -// static char l_scratch[240]; -// va_list args; -// -// va_start(args, format); -// if (vsprintf(l_scratch, format, args) > 239) -// { -// error_msg("buffer overwrite in sformatf", STOP); -// } -// va_end(args); -// return l_scratch; -//#else -// return NULL; -//#endif -//} - -//std::string Phreeqc:: -//sformatf(const char *format, ...) -//{ -// -// -// size_t max = 240; -// char * l_scratch = NULL; -// bool success = false; -// do -// { -// va_list args; -// va_start(args, format); -// l_scratch = (char *) PHRQ_realloc(l_scratch, max * sizeof(char)); -// success = (vsnprintf(l_scratch, max, format, args) > 0); -// va_end(args); -// max *= 2; -// } -// while (!success); -// -// std::string str(l_scratch); -// l_scratch = (char *) free_check_null(l_scratch); -// return str; -// -//} char * Phreeqc:: sformatf(const char *format, ...) { - - bool success = false; do { diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 9694ac6e..3311f0a2 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -15,6 +15,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -98,13 +99,11 @@ read_input(void) break; case Keywords::KEY_SOLUTION: /* Read solution data */ read_solution(); - solution_sort(); break; case Keywords::KEY_PHASES: read_phases(); break; case Keywords::KEY_EQUILIBRIUM_PHASES: - //read_pure_phases(); read_pp_assemblage(); break; case Keywords::KEY_REACTION: @@ -135,7 +134,7 @@ read_input(void) read_surface_master_species(); break; case Keywords::KEY_SURFACE: - read_surf(); + read_surface(); break; case Keywords::KEY_REACTION_TEMPERATURE: read_temperature(); @@ -257,20 +256,19 @@ read_input(void) case Keywords::KEY_SIT: read_sit(); break; - case Keywords::KEY_SOLUTION_RAW: - read_solution_raw(); + case Keywords::KEY_SOLUTION_RAW: + Utilities::Rxn_read_raw(Rxn_solution_map, this); break; case Keywords::KEY_EXCHANGE_RAW: Utilities::Rxn_read_raw(Rxn_exchange_map, this); break; - case Keywords::KEY_SURFACE_RAW: - read_surface_raw(); + case Keywords::KEY_SURFACE_RAW: + Utilities::Rxn_read_raw(Rxn_surface_map, this); break; case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, this); break; case Keywords::KEY_KINETICS_RAW: - //read_kinetics_raw(); Utilities::Rxn_read_raw(Rxn_kinetics_map, this); break; case Keywords::KEY_SOLID_SOLUTIONS_RAW: @@ -292,7 +290,7 @@ read_input(void) read_dump(); break; case Keywords::KEY_SOLUTION_MODIFY: - read_solution_modify(); + Utilities::Rxn_read_modify(Rxn_solution_map, this); break; case Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY: Utilities::Rxn_read_modify(Rxn_pp_assemblage_map, this); @@ -301,7 +299,7 @@ read_input(void) Utilities::Rxn_read_modify(Rxn_exchange_map, this); break; case Keywords::KEY_SURFACE_MODIFY: - read_surface_modify(); + Utilities::Rxn_read_modify(Rxn_surface_map, this); break; case Keywords::KEY_SOLID_SOLUTIONS_MODIFY: Utilities::Rxn_read_modify(Rxn_ss_assemblage_map, this); @@ -310,7 +308,6 @@ read_input(void) Utilities::Rxn_read_modify(Rxn_gas_phase_map, this); break; case Keywords::KEY_KINETICS_MODIFY: - //read_kinetics_modify(); Utilities::Rxn_read_modify(Rxn_kinetics_map, this); break; case Keywords::KEY_DELETE: @@ -340,186 +337,6 @@ read_input(void) END_OF_SIMULATION_INPUT: return (OK); } -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_conc(int n, int count_mass_balance, char *str) -/* ---------------------------------------------------------------------- */ -{ - int j, l; - int alk; - int count_redox_states; - - char *ptr; - char token[MAX_LENGTH], token1[MAX_LENGTH]; -/* - * Set defaults - */ - /* - solution[n]->totals[count_mass_balance].equation_name = NULL; - solution[n]->totals[count_mass_balance].phase = NULL; - solution[n]->totals[count_mass_balance].phase_si = 0.0; - solution[n]->totals[count_mass_balance].units=NULL; - solution[n]->totals[count_mass_balance].n_pe=-1; - solution[n]->totals[count_mass_balance].as=NULL; - solution[n]->totals[count_mass_balance].gfw= 0.0; - */ - conc_init(&(solution[n]->totals[count_mass_balance])); - -/* - * Remove space between "kg" and "solution" or "water" in units - */ - replace("Kg", "kg", str); - replace("KG", "kg", str); - while (replace("kg ", "kg", str) == TRUE); - ptr = str; -/* - * Read master species list for mass balance equation - */ - token1[0] = '\0'; - count_redox_states = 0; - while (((j = copy_token(token, &ptr, &l)) == UPPER) || - (token[0] == '[') || - (strcmp_nocase_arg1(token, "ph") == 0) || - (strcmp_nocase_arg1(token, "pe") == 0)) - { - count_redox_states++; - replace("(+", "(", token); - if (count_redox_states > 1) - strcat(token1, " "); - strcat(token1, token); - } - if (count_redox_states == 0) - { - input_error++; - error_msg - ("No element or master species given for concentration input.", - CONTINUE); - return (ERROR); - } - solution[n]->totals[count_mass_balance].description = - string_hsave(token1); -/* - * Determine if reading alkalinity, allow equivalents for units - */ - str_tolower(token1); - if (strstr(token1, "alk") == token1) - { - alk = TRUE; - } - else - { - alk = FALSE; - } -/* - * Read concentration - */ - - j = sscanf(token, SCANFORMAT, - &(solution[n]->totals[count_mass_balance].input_conc)); - if (j == 0) - { - error_string = sformatf( - "Concentration data error for %s in solution input.", token1); - error_msg(error_string, CONTINUE); - return (ERROR); - } - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); -/* - * Read optional data - */ - strcpy(token1, token); -/* - * Check for units info - */ - if (check_units(token1, alk, FALSE, solution[n]->units, FALSE) == OK) - { - if (check_units(token1, alk, FALSE, solution[n]->units, TRUE) == OK) - { - solution[n]->totals[count_mass_balance].units = - string_hsave(token1); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); - } - else - { - return (ERROR); - } - } -/* - * Check for "as" followed by formula to be used for gfw - */ - strcpy(token1, token); - str_tolower(token1); - if (strcmp(token1, "as") == 0) - { - copy_token(token, &ptr, &l); - solution[n]->totals[count_mass_balance].as = string_hsave(token); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); -/* - * Check for "gfw" followed by gram formula weight - */ - } - else if (strcmp(token1, "gfw") == 0 || strcmp(token1, "gfm") == 0) - { - if (copy_token(token, &ptr, &l) != DIGIT) - { - error_msg("Expecting gram formula weight.", CONTINUE); - return (ERROR); - } - else - { - sscanf(token, SCANFORMAT, - &(solution[n]->totals[count_mass_balance].gfw)); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); - } - } -/* - * Check for redox couple for pe - */ - if (strcmp_nocase_arg1(token, "pe") == 0) - { - solution[n]->totals[count_mass_balance].n_pe = - pe_data_store(&(solution[n]->pe), token); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); - } - else if (strstr(token, "/") != NULL) - { - if (parse_couple(token) == OK) - { - solution[n]->totals[count_mass_balance].n_pe = - pe_data_store(&(solution[n]->pe), token); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); - } - else - { - return (ERROR); - } - } -/* - * Must have phase - */ - solution[n]->totals[count_mass_balance].equation_name = - string_hsave(token); - if ((j = copy_token(token, &ptr, &l)) == EMPTY) - return (OK); -/* - * Check for saturation index - */ - j = sscanf(token, SCANFORMAT, - &(solution[n]->totals[count_mass_balance].phase_si)); - if (j != 1) - { - error_msg("Expected saturation index.", CONTINUE); - return (ERROR); - } - return (OK); -} - /* ---------------------------------------------------------------------- */ int Phreeqc:: read_exchange_species(void) @@ -562,8 +379,6 @@ read_exchange_species(void) "add_logk", /* 16 */ "add_log_k", /* 17 */ "add_constant", /* 18 */ - //"delta_v", /* 19 */ - //"deltav", /* 20 */ "vm" /* 19, molar volume, must replace delta_v */ }; int count_opt_list = 18; @@ -873,8 +688,6 @@ read_exchange_species(void) s_ptr->count_add_logk++; opt_save = OPTION_DEFAULT; break; - //case 19: /* delta_v */ - //case 20: /* deltav */ case 19: /* vm, molar volume */ if (s_ptr == NULL) { @@ -885,7 +698,7 @@ read_exchange_species(void) input_error++; break; } - read_delta_v_only(next_char, &s_ptr->logk[vm0], + read_vm_only(next_char, &s_ptr->logk[vm0], &s_ptr->original_deltav_units); opt_save = OPTION_DEFAULT; break; @@ -1011,13 +824,10 @@ read_exchange(void) * ERROR if error occurred reading data * */ - int i, j, l; int n_user, n_user_end; LDBLE conc; char *ptr; char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - //struct exchange *exchange_ptr; int return_value, opt; char *next_char; @@ -1046,7 +856,7 @@ read_exchange(void) * Default values + n_user, description */ cxxExchange temp_exchange; - cxxExchComp *comp = NULL; + cxxExchComp *comp_ptr = NULL; temp_exchange.Set_new_def(true); temp_exchange.Set_n_user(n_user); temp_exchange.Set_n_user_end(n_user_end); @@ -1088,11 +898,12 @@ read_exchange(void) */ for (;;) { - i = copy_token(token, &next_char, &l); + std::string token; + int i = copy_token(token, &next_char); if (i == DIGIT) { int n_solution; - sscanf(token, "%d", &n_solution); + sscanf(token.c_str(), "%d", &n_solution); temp_exchange.Set_n_solution(n_solution); temp_exchange.Set_new_def(true); temp_exchange.Set_solution_equilibria(true); @@ -1116,154 +927,154 @@ read_exchange(void) get_true_false(next_char, TRUE) == TRUE); break; case OPTION_DEFAULT: - ptr = line; - i = copy_token(token, &ptr, &l); - /* - * Species formula is stored in token - */ - if (i != UPPER && token[0] != '[') - { /* maybe a bit more clear? */ - error_string = sformatf( - "Expected exchanger name to begin with a capital letter, but found:\n %s", - line_save); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - delete comp; - comp = new cxxExchComp; - comp->Set_formula(token); - //exchange[n].comps[count_comps].formula = string_hsave(token); - prev_next_char = ptr; - i = copy_token(token1, &ptr, &l); - if (i == DIGIT) { + std::string token; + ptr = line; + int i = copy_token(token, &ptr); /* - * Read exchange concentration - */ - - /* exchanger conc. is read directly .. */ - if (sscanf(token1, SCANFORMAT, &conc) < 1) - { - error_string = sformatf( - "Expected concentration of exchanger, but found:\n %s", - line_save); + * Species formula is stored in token + */ + if (i != UPPER && token[0] != '[') + { /* maybe a bit more clear? */ + error_string = sformatf( + "Expected exchanger name to begin with a capital letter, but found:\n %s", + line_save); error_msg(error_string, CONTINUE); input_error++; break; } + cxxExchComp temp_comp; + temp_exchange.Get_exchange_comps().push_back(temp_comp); + comp_ptr = &(temp_exchange.Get_exchange_comps().back()); + comp_ptr->Set_formula(token.c_str()); prev_next_char = ptr; - j = copy_token(token1, &ptr, &l); - if (j == UPPER || j == LOWER) + std::string token1; + i = copy_token(token1, &ptr); + if (i == DIGIT) { - comp->Set_rate_name(token1); - if (copy_token(token1, &ptr, &l) != DIGIT) + /* + * Read exchange concentration + */ + + /* exchanger conc. is read directly .. */ + if (sscanf(token1.c_str(), SCANFORMAT, &conc) < 1) { error_string = sformatf( - "Expected a coefficient to relate exchange to kinetic reaction, but found:\n %s", + "Expected concentration of exchanger, but found:\n %s", + line_save); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + prev_next_char = ptr; + int j = copy_token(token1, &ptr); + if (j == UPPER || j == LOWER) + { + comp_ptr->Set_rate_name(token1.c_str()); + if (copy_token(token1, &ptr) != DIGIT) + { + error_string = sformatf( + "Expected a coefficient to relate exchange to kinetic reaction, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + LDBLE p; + sscanf(token1.c_str(), SCANFORMAT, &p); + comp_ptr->Set_phase_proportion(p); + } + /* + * Read equilibrium phase name or kinetics rate name + */ + } + else if (i != EMPTY) + { + + /* exchanger conc. is related to mineral or kinetics */ + comp_ptr->Set_phase_name(token1.c_str()); + prev_next_char = ptr; + int j = copy_token(token1, &ptr); + if (j != DIGIT) + { + if (token1[0] == 'K' || token1[0] == 'k') + { + comp_ptr->Set_rate_name(comp_ptr->Get_phase_name().c_str()); + comp_ptr->Set_phase_name(""); + } + else if (token1[0] != 'E' && token1[0] != 'e') + { + error_string = sformatf( + "Character string expected to be 'equilibrium_phase' or 'kinetics'\n to relate exchange to mineral or kinetic reaction, but found:\n %s", + prev_next_char); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + prev_next_char = ptr; + j = copy_token(token1, &ptr); + } + + + if (j != DIGIT) + { + error_string = sformatf( + "Expected a coefficient to relate exchanger to mineral or kinetic reaction, but found:\n %s", prev_next_char); error_msg(error_string, CONTINUE); input_error++; break; } LDBLE p; - sscanf(token1, SCANFORMAT, &p); - comp->Set_phase_proportion(p); + sscanf(token1.c_str(), SCANFORMAT, &p); + comp_ptr->Set_phase_proportion(p); + /* real conc must be defined in tidy_model */ + conc = 1.0; } - /* - * Read equilibrium phase name or kinetics rate name - */ - } - else if (i != EMPTY) - { - - /* exchanger conc. is related to mineral or kinetics */ - comp->Set_phase_name(token1); - prev_next_char = ptr; - j = copy_token(token1, &ptr, &l); - if (j != DIGIT) + else { - if (token1[0] == 'K' || token1[0] == 'k') - { - comp->Set_rate_name(comp->Get_phase_name().c_str()); - comp->Set_phase_name(""); - } - else if (token1[0] != 'E' && token1[0] != 'e') - { - error_string = sformatf( - "Character string expected to be 'equilibrium_phase' or 'kinetics'\n to relate exchange to mineral or kinetic reaction, but found:\n %s", - prev_next_char); - error_msg(error_string, CONTINUE); - input_error++; - break; - } - prev_next_char = ptr; - j = copy_token(token1, &ptr, &l); - } - - - if (j != DIGIT) - { - error_string = sformatf( - "Expected a coefficient to relate exchanger to mineral or kinetic reaction, but found:\n %s", - prev_next_char); - error_msg(error_string, CONTINUE); + error_msg + ("Expected concentration of exchanger, mineral name, or kinetic reaction name.", + CONTINUE); + error_msg(line_save, CONTINUE); input_error++; break; } - LDBLE p; - sscanf(token1, SCANFORMAT, &p); - comp->Set_phase_proportion(p); - /* real conc must be defined in tidy_model */ - conc = 1.0; + /* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + char * formula = string_duplicate(token.c_str()); + ptr = formula; + get_elts_in_species(&ptr, conc); + + /* + * save formula for adjusting number of exchange sites + */ + ptr = formula; + char *name = string_duplicate(token.c_str()); + name[0] = '\0'; + LDBLE z; + int l; + get_token(&ptr, name, &z, &l); + comp_ptr->Set_formula_z(z); + free_check_null(formula); + free_check_null(name); + /* + * Save elt_list + */ + comp_ptr->Set_totals(elt_list_NameDouble()); + comp_ptr->Set_charge_balance(0.0); } - else - { - error_msg - ("Expected concentration of exchanger, mineral name, or kinetic reaction name.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - /* - * Accumulate elements in elt_list - */ - count_elts = 0; - paren_count = 0; - ptr = token; - get_elts_in_species(&ptr, conc); - /* - * save formula for adjusting number of exchange sites - */ - ptr = token; - LDBLE z; - get_token(&ptr, token1, &z, &l); - comp->Set_formula_z(z); - comp->Set_formula_totals(elt_list_NameDouble()); - /* - * Save elt_list - */ - comp->Set_moles(conc); - comp->Set_totals(elt_list_NameDouble()); - comp->Set_charge_balance(0.0); - temp_exchange.Get_exchComps()[comp->Get_formula()] = *comp; } if (return_value == EOF || return_value == KEYWORD) break; } Rxn_exchange_map[n_user] = temp_exchange; - - //if (n_user_end > n_user) - //{ - // for (int i = n_user + 1; i <= n_user_end; i++) - // { - // Utilities::Rxn_copy(Rxn_exchange_map, n_user, i); - // } - //} - delete comp; return (return_value); } + /* ---------------------------------------------------------------------- */ int Phreeqc:: read_exchange_master_species(void) @@ -1392,7 +1203,6 @@ read_gas_phase(void) char *ptr; char *description; char token[MAX_LENGTH]; - //struct gas_phase *gas_phase_ptr; cxxGasPhase temp_gas_phase; int return_value, opt; char *next_char; @@ -1982,7 +1792,6 @@ read_inv_isotopes(struct inverse *inverse_ptr, char *ptr) inverse_ptr->count_i_u++; return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: read_inv_phases(struct inverse *inverse_ptr, char *ptr) @@ -1992,7 +1801,7 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) int count_isotopes; char token[MAX_LENGTH], token1[MAX_LENGTH]; char *ptr1; - struct isotope *isotopes; + std::vector isotopes; /* * Read phase name */ @@ -2014,12 +1823,9 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) inverse_ptr->phases[inverse_ptr->count_phases].constraint = EITHER; inverse_ptr->phases[inverse_ptr->count_phases].force = FALSE; count_isotopes = 0; - isotopes = (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); - if (isotopes == NULL) - malloc_error(); - for (;;) { + cxxSolutionIsotope temp_isotope; j = copy_token(token, &ptr, &l); if (j == EMPTY) break; @@ -2044,17 +1850,11 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) /* * read isotope data */ - isotopes = - (struct isotope *) PHRQ_realloc(isotopes, - (size_t) (count_isotopes + - 1) * - sizeof(struct isotope)); - if (isotopes == NULL) - malloc_error(); ptr1 = token; /* isotope number */ - get_num(&ptr1, &(isotopes[count_isotopes].isotope_number)); + get_num(&ptr1, &dummy); + temp_isotope.Set_isotope_number(dummy); if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { error_string = sformatf( "Expecting element name: %s.", ptr1); @@ -2065,7 +1865,7 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) } /* element name */ - isotopes[count_isotopes].elt_name = string_hsave(ptr1); + temp_isotope.Set_elt_name(ptr1); /* ratio */ j = copy_token(token, &ptr, &l); @@ -2076,7 +1876,8 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) input_error++; break; } - sscanf(token, SCANFORMAT, &(isotopes[count_isotopes].ratio)); + sscanf(token, SCANFORMAT, &dummy); + temp_isotope.Set_ratio(dummy); /* read and store isotope ratio uncertainty */ prev_next_char = ptr; @@ -2089,10 +1890,10 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) error_msg(error_string, CONTINUE); continue; } - sscanf(token, SCANFORMAT, - &(isotopes[count_isotopes].ratio_uncertainty)); - - count_isotopes++; + sscanf(token, SCANFORMAT, &dummy); + temp_isotope.Set_ratio_uncertainty(dummy); + temp_isotope.Set_ratio_uncertainty_defined(true); + isotopes.push_back(temp_isotope); } else { @@ -2101,17 +1902,33 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) warning_msg(error_string); } } - if (count_isotopes > 0) + if (isotopes.size() > 0) { - inverse_ptr->phases[inverse_ptr->count_phases].isotopes = isotopes; - inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = - count_isotopes; + inverse_ptr->phases[inverse_ptr->count_phases].isotopes = + (struct isotope *) PHRQ_malloc(isotopes.size() * sizeof(struct isotope)); + for (size_t i = 0; i < isotopes.size(); i++) + { + struct isotope *iso_ptr = &(inverse_ptr->phases[inverse_ptr->count_phases].isotopes[i]); + iso_ptr->isotope_number = isotopes[i].Get_isotope_number(); + iso_ptr->elt_name = string_hsave(isotopes[i].Get_elt_name().c_str()); + iso_ptr->isotope_name = string_hsave(isotopes[i].Get_isotope_name().c_str()); + iso_ptr->total = isotopes[i].Get_total(); + iso_ptr->ratio = isotopes[i].Get_ratio(); + if (isotopes[i].Get_ratio_uncertainty_defined()) + iso_ptr->ratio_uncertainty = isotopes[i].Get_ratio_uncertainty(); + else + iso_ptr->ratio_uncertainty = NAN; + iso_ptr->x_ratio_uncertainty = isotopes[i].Get_x_ratio_uncertainty(); + iso_ptr->coef = isotopes[i].Get_coef(); + iso_ptr->master = NULL; + iso_ptr->primary = NULL; + } + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = isotopes.size(); } else { inverse_ptr->phases[inverse_ptr->count_phases].isotopes = NULL; inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = 0; - isotopes = (struct isotope *) free_check_null(isotopes); } inverse_ptr->count_phases++; return (OK); @@ -2599,551 +2416,6 @@ read_kinetics(void) Rxn_kinetics_map[n_user] = temp_kinetics; return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_kinetics(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads kinetics data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ -/* - * Read kinetics - */ - int i, j, k, l, count_comps, count_steps, count_list; - char *ptr; - char *description; - char token[MAX_LENGTH]; - int n; - int n_user, n_user_end; - struct kinetics *kinetics_ptr; - struct kinetics_comp *kinetics_comp_ptr; - LDBLE step, coef; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "tol", /* 0 */ - "m", /* 1 */ - "m0", /* 2 */ - "parms", /* 3 */ - "formula", /* 4 */ - "steps", /* 5 */ - "step_divide", /* 6 */ - "parameters", /* 7 */ - "runge-kutta", /* 8 */ - "runge_kutta", /* 9 */ - "rk", /* 10 */ - "bad_step_max", /* 11 */ - "cvode", /* 12 */ - "cvode_steps", /* 13 */ - "cvode_order", /* 14 */ - "time_steps" /* 15 */ - }; - int count_opt_list = 16; - -/* - * Read kinetics number - */ - ptr = line; - read_number_description(ptr, &n_user, &n_user_end, &description); - -/* - * Find space for kinetics data - */ - kinetics_ptr = kinetics_search(n_user, &n, FALSE); - if (kinetics_ptr != NULL) - { - kinetics_free(kinetics_ptr); - } - else - { - space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, - sizeof(struct kinetics)); - n = count_kinetics++; - } -/* - * Set use data to first read - */ - if (use.Get_kinetics_in() == FALSE) - { - use.Set_kinetics_in(true); - use.Set_n_kinetics_user(n_user); - } -/* - * Initialize - */ - kinetics_init(&(kinetics[n]), n_user, n_user_end, description); - free_check_null(description); - kinetics_ptr = &kinetics[n]; - - count_steps = 0; -/* - * Read kinetics data - */ - return_value = UNKNOWN; - kinetics_comp_ptr = NULL; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_DEFAULT: /* allocate space, read new name */ - count_comps = kinetics_ptr->count_comps++; - kinetics_ptr->comps = - (struct kinetics_comp *) PHRQ_realloc(kinetics_ptr->comps, - (size_t) (count_comps + - 1) * - sizeof(struct - kinetics_comp)); - if (kinetics_ptr->comps == NULL) - malloc_error(); - kinetics_ptr->comps[count_comps].moles = 0; - ptr = line; - copy_token(token, &ptr, &l); - kinetics_ptr->comps[count_comps].rate_name = string_hsave(token); - kinetics_ptr->comps[count_comps].tol = 1e-8; - kinetics_ptr->comps[count_comps].m0 = -1.0; - kinetics_ptr->comps[count_comps].m = -1.0; - kinetics_ptr->comps[count_comps].count_c_params = 0; - - kinetics_comp_ptr = &kinetics_ptr->comps[count_comps]; - kinetics_comp_ptr->d_params = - (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (kinetics_comp_ptr->d_params == NULL) - malloc_error(); - kinetics_comp_ptr->count_d_params = 0; - - kinetics_comp_ptr->c_params = - (const char **) PHRQ_malloc(sizeof(char *)); - if (kinetics_comp_ptr->c_params == NULL) - malloc_error(); - kinetics_comp_ptr->count_c_params = 0; - - kinetics_comp_ptr->count_list = 0; - kinetics_comp_ptr->list = - (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); - if (kinetics_comp_ptr->list == NULL) - malloc_error(); - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in KINETICS keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* tolerance */ - if (kinetics_comp_ptr == NULL) - { - error_string = sformatf( "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } - else - { - prev_next_char = next_char; - if (copy_token(token, &next_char, &l) == DIGIT) - { - kinetics_comp_ptr->tol = strtod(token, &ptr); - } - else - { - error_string = sformatf( - "Expecting numerical value for tolerance, but found:\n %s", - prev_next_char); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 1: /* m */ - if (kinetics_comp_ptr == NULL) - { - error_string = sformatf( "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } - else - { - prev_next_char = next_char; - if (copy_token(token, &next_char, &l) == DIGIT) - { - kinetics_comp_ptr->m = strtod(token, &ptr); - } - else - { - error_string = sformatf( - "Expecting numerical value for moles of reactant (m), but found:\n %s", - prev_next_char); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 2: /* m0 */ - if (kinetics_comp_ptr == NULL) - { - error_string = sformatf( "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } - else - { - prev_next_char = next_char; - if (copy_token(token, &next_char, &l) == DIGIT) - { - kinetics_comp_ptr->m0 = strtod(token, &ptr); - } - else - { - error_string = sformatf( - "Expecting numerical value for initial moles of reactant (m0), but found:\n %s", - prev_next_char); - error_msg(error_string, CONTINUE); - input_error++; - } - } - break; - case 3: /* parms */ - case 7: /* parameters */ - if (kinetics_comp_ptr == NULL) - { - error_string = sformatf( "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } - else - { - while ((j = copy_token(token, &next_char, &l)) != EMPTY) - { - /* - * Store a LDBLE parameter - */ - if (j == DIGIT) - { - kinetics_comp_ptr->d_params = - (LDBLE *) PHRQ_realloc(kinetics_comp_ptr-> - d_params, - (size_t) - (kinetics_comp_ptr-> - count_d_params + - 1) * sizeof(LDBLE)); - if (kinetics_comp_ptr->d_params == NULL) - malloc_error(); - kinetics_comp_ptr->d_params[kinetics_comp_ptr-> - count_d_params] = - strtod(token, &ptr); - kinetics_comp_ptr->count_d_params++; - } - else - { - /* - * Store a character parameter - */ - kinetics_comp_ptr->c_params = - (const char **) PHRQ_realloc(kinetics_comp_ptr-> - c_params, - (size_t) - (kinetics_comp_ptr-> - count_c_params + - 1) * sizeof(char *)); - if (kinetics_comp_ptr->c_params == NULL) - malloc_error(); - kinetics_comp_ptr->c_params[kinetics_comp_ptr-> - count_c_params] = - string_hsave(token); - kinetics_comp_ptr->count_c_params++; - } - } - } - break; - case 4: /* formula */ - if (kinetics_comp_ptr == NULL) - { - error_string = sformatf( "No rate name has been defined."); - error_msg(error_string, CONTINUE); - input_error++; - } - else - { - /* - * Store reactant name, default coefficient - */ - ptr = next_char; - while (copy_token(token, &ptr, &l) != EMPTY) - { - if (isalpha((int) token[0]) || (token[0] == '(') - || (token[0] == '[')) - { - count_list = kinetics_comp_ptr->count_list++; - kinetics_comp_ptr->list = - (struct name_coef *) - PHRQ_realloc(kinetics_comp_ptr->list, - (size_t) (count_list + - 1) * - sizeof(struct name_coef)); - if (kinetics_comp_ptr->list == NULL) - malloc_error(); - kinetics_comp_ptr->list[count_list].name = - string_hsave(token); - kinetics_comp_ptr->list[count_list].coef = 1.0; - } - else - { - /* - * Store relative coefficient - */ - j = sscanf(token, SCANFORMAT, &coef); - if (j == 1) - { - count_list = kinetics_comp_ptr->count_list - 1; - kinetics_comp_ptr->list[count_list].coef = coef; - } - else - { - error_msg - ("Reading relative coefficient of reactant.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - } - } - } - } - break; - case 5: /* steps */ - case 15: /* time_steps */ - /* - * Read one or more kinetics time increments - */ - while ((j = copy_token(token, &next_char, &l)) == DIGIT) - { - /* Read next step increment(s) */ -/* multiple, equal timesteps 15 aug. 2005 */ - if (replace("*", " ", token) == TRUE) - { - if (sscanf(token, "%d" SCANFORMAT, &k, &step) == 2) - { - for (i = 0; i < k; i++) - { - count_steps++; - kinetics_ptr->steps = - (LDBLE *) PHRQ_realloc(kinetics_ptr->steps, - (size_t) count_steps * - sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) - malloc_error(); - kinetics_ptr->steps[kinetics_ptr->count_steps] = - step; - kinetics_ptr->count_steps = count_steps; - } - } - else - { - input_error++; - error_msg - ("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", - CONTINUE); - } - } - else - { - step = strtod(token, &ptr); - count_steps++; - kinetics_ptr->steps = - (LDBLE *) PHRQ_realloc(kinetics_ptr->steps, - (size_t) count_steps * - sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) - malloc_error(); - kinetics_ptr->steps[kinetics_ptr->count_steps] = step; - kinetics_ptr->count_steps = count_steps; - } - } - if (j == EMPTY) - break; - /* - * Read number of increments - */ - if (kinetics_ptr->count_steps != 1) - { - error_msg - ("To define equal time increments, only one total time should be defined.", - CONTINUE); - input_error++; - break; - } - do - { - j = sscanf(token, "%d", &i); - if (j == 1 && i > 0) - { - kinetics_ptr->count_steps = -i; - break; - } - else if (j == 1 && i <= 0) - { - error_msg - ("Expecting positive number for number of equal " - "time increments for kinetics.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - while (copy_token(token, &next_char, &l) != EMPTY); - break; - case 6: /* step_divide */ - if (copy_token(token, &next_char, &l) == DIGIT) - { - sscanf(token, SCANFORMAT, &kinetics_ptr->step_divide); - } - else - { - error_string = sformatf( - "Expecting numerical value for step_divide."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 8: /* runge-kutta */ - case 9: /* runge_kutta */ - case 10: /* rk */ - j = copy_token(token, &next_char, &l); - if (j == DIGIT) - { - kinetics_ptr->rk = (int) strtod(token, &ptr); - } - else if (j == EMPTY) - { - } - else - { - error_string = sformatf( - "Expecting order for Runge-Kutta method."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 11: /* bad_step_max */ - j = copy_token(token, &next_char, &l); - if (j == DIGIT) - { - kinetics_ptr->bad_step_max = (int) strtod(token, &ptr); - } - else if (j == EMPTY) - { - } - else - { - error_string = sformatf( "Expecting maximal bad steps number."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 12: /* cvode */ - kinetics[n].use_cvode = get_true_false(next_char, TRUE); - break; - case 13: /* cvode_steps */ - j = copy_token(token, &next_char, &l); - if (j == DIGIT) - { - kinetics_ptr->cvode_steps = (int) strtod(token, &ptr); - } - else if (j == EMPTY) - { - } - else - { - error_string = sformatf( - "Expecting maximum number of steps for one call to cvode."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - case 14: /* cvode_order */ - j = copy_token(token, &next_char, &l); - if (j == DIGIT) - { - kinetics_ptr->cvode_order = (int) strtod(token, &ptr); - } - else if (j == EMPTY) - { - } - else - { - error_string = sformatf( - "Expecting number of terms (order) used in cvode (1-5)."); - error_msg(error_string, CONTINUE); - input_error++; - } - break; - } - if (return_value == EOF || return_value == KEYWORD) - break; - } - -/* - * Default reactant - */ - for (i = 0; i < kinetics[n].count_comps; i++) - { - if (kinetics[n].comps[i].count_list == 0) - { - kinetics[n].comps[i].list[0].name = - kinetics_ptr->comps[i].rate_name; - kinetics[n].comps[i].list[0].coef = 1; - kinetics[n].comps[i].count_list = 1; - } - } -/* - * Default 1 sec - */ - if (kinetics[n].count_steps == 0) - { - kinetics[n].count_steps = 1; - kinetics[n].steps[0] = 1.0; - } -/* - * set defaults for moles - */ - for (i = 0; i < kinetics[n].count_comps; i++) - { - if (kinetics[n].comps[i].m0 < 0) - { - if (kinetics[n].comps[i].m < 0) - { - kinetics[n].comps[i].m0 = 1; - } - else - { - kinetics[n].comps[i].m0 = kinetics[n].comps[i].m; - } - } - if (kinetics[n].comps[i].m < 0) - { - kinetics[n].comps[i].m = kinetics[n].comps[i].m0; - } - } - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ LDBLE * Phreeqc:: read_list_doubles(char **ptr, int *count_doubles) @@ -3483,7 +2755,7 @@ read_omega_only(char *ptr, LDBLE *omega) /* ---------------------------------------------------------------------- */ int Phreeqc:: -read_delta_v_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) +read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) /* ---------------------------------------------------------------------- */ { int j, l; @@ -3491,13 +2763,13 @@ read_delta_v_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) /* * Read analytical expression */ - for (j = 0; j < 4; j++) + for (j = 0; j < 8; j++) { delta_v[j] = 0.0; } - j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT /*SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT*/, - &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3])/*, - &(delta_v[4]), &(delta_v[5]), &(delta_v[6]), &(delta_v[7])*/); + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3]), + &(delta_v[4]), &(delta_v[5]), &(delta_v[6]), &(delta_v[7])); if (j < 1) { input_error++; @@ -3652,15 +2924,15 @@ read_millero_abcdef (char *ptr, LDBLE * abcdef) { int j; /* - * Read a, b, c, d, e and f parameters for Millero density model. + * Read a, b, c, d, e, f, and kappa parameters for Millero density model. */ - for (j = 0; j < 6; j++) + for (j = 0; j < 7; j++) { abcdef[j] = 0.0; } j = - sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, - &(abcdef[0]), &(abcdef[1]), &(abcdef[2]), &(abcdef[3]), &(abcdef[4]), &(abcdef[5])); + sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + &(abcdef[0]), &(abcdef[1]), &(abcdef[2]), &(abcdef[3]), &(abcdef[4]), &(abcdef[5]), &(abcdef[6])); if (j < 1) { input_error++; @@ -3923,7 +3195,6 @@ read_mix(void) char *ptr; char token[MAX_LENGTH]; char *description; - //struct mix *mix_ptr; cxxMix temp_mix; /* @@ -4009,6 +3280,7 @@ read_mix(void) return (return_value); } + /* ---------------------------------------------------------------------- */ int Phreeqc:: read_number_description(char *ptr, int *n_user, @@ -4119,8 +3391,6 @@ read_phases(void) "t_c", /* 12 */ "p_c", /* 13 */ "omega", /* 14 */ - //"delta_v", /* 15 */ - //"deltav", /* 16 */ "vm" /* 15, molar volume, must replace delta_v */ }; int count_opt_list = 16; @@ -4292,13 +3562,10 @@ read_phases(void) read_omega_only(next_char, &phase_ptr->omega); opt_save = OPTION_DEFAULT; break; - //case 15: /* delta_v */ - //case 16: /* delta_v */ case 15: /* vm, molar volume */ if (phase_ptr == NULL) break; - //read_delta_v_only(next_char, &phase_ptr->delta_v[1], - read_delta_v_only(next_char, &(phase_ptr->logk[vm0]), + read_vm_only(next_char, &(phase_ptr->logk[vm0]), &phase_ptr->original_deltav_units); phase_ptr->delta_v[1] = phase_ptr->logk[vm0]; opt_save = OPTION_DEFAULT; @@ -4418,14 +3685,11 @@ read_pp_assemblage(void) * ERROR if error occurred reading data * */ - //int j, n, l, return_value; int j; int return_value; - //int count_pure_phases; int n_user, n_user_end; char *ptr; char *description; - //char token[MAX_LENGTH]; std::string token; int opt, opt_save; char *next_char; @@ -4815,11 +4079,11 @@ read_reaction_steps(cxxReaction *reaction_ptr) */ token1 = token; token1.append("/l"); - char * t1 = string_duplicate(token1.c_str()); - if (check_units(t1, FALSE, FALSE, NULL, FALSE) == OK) + std::string t1 = token1; + if (check_units(t1, false, false, NULL, false) == OK) { replace("/l", "", t1); - if (strstr(t1, "Mol") == NULL) + if (strstr(t1.c_str(), "Mol") == NULL) { error_string = sformatf( "Units of steps not in moles, %s.", token.c_str()); error_msg(error_string, CONTINUE); @@ -4828,7 +4092,7 @@ read_reaction_steps(cxxReaction *reaction_ptr) } else { - reaction_ptr->Set_units(t1); + reaction_ptr->Set_units(t1.c_str()); } if (copy_token(token, &ptr) == EMPTY) { @@ -5405,7 +4669,331 @@ read_selected_output(void) return (return_value); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solution(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads solution data + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int n_user, n_user_end; + char *description; + int return_value, opt; + char *next_char; + const char *opt_list[] = { + "temp", /* 0 */ + "temperature", /* 1 */ + "dens", /* 2 */ + "density", /* 3 */ + "units", /* 4 */ + "redox", /* 5 */ + "ph", /* 6 */ + "pe", /* 7 */ + "unit", /* 8 */ + "isotope", /* 9 */ + "water", /* 10 */ + "press", /* 11 */ + "pressure" /* 12 */ + }; + int count_opt_list = 13; +/* + * Read solution number and description + */ + char *ptr; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + cxxSolution temp_solution; + temp_solution.Set_new_def(true); + temp_solution.Create_initial_data(); + cxxISolution *isoln_ptr = temp_solution.Get_initial_data(); + CParser parser(this->phrq_io); + + temp_solution.Set_n_user(n_user); + temp_solution.Set_n_user_end(n_user_end); + temp_solution.Set_description(description); + free_check_null(description); + + if (!use.Get_solution_in()) + { + use.Set_solution_in(true); + use.Set_n_solution_user(n_user); + } + +/* + * Read concentration data + */ + std::string token; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + ptr = next_char; + if (copy_token(token, &ptr) == CParser::TT_DIGIT) + { + opt = 9; + } + } + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SOLUTION keyword.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* temperature */ + case 1: + if (sscanf(next_char, SCANFORMAT, &dummy) == 1) + { + temp_solution.Set_tc(dummy); + } + break; + case 2: /* density */ + case 3: + { + sscanf(next_char, SCANFORMAT, &dummy); + temp_solution.Set_density(dummy); + } + break; + case 4: /* units */ + case 8: /* unit */ + if (copy_token(token, &next_char) == CParser::TT_EMPTY) + break; + { + if (check_units(token, false, false, "mMol/kgw", false) == CParser::PARSER_OK) + { + isoln_ptr->Set_units(token); + } + else + { + input_error++; + } + } + break; + case 5: /* redox */ + if (copy_token(token, &next_char) == CParser::TT_EMPTY) + break; + if (parser.parse_couple(token) == CParser::PARSER_OK) + { + isoln_ptr->Set_default_pe(token); + cxxChemRxn temp_chem_reaction; + isoln_ptr->Get_pe_reactions()[token] = temp_chem_reaction; + } + else + { + input_error++; + } + break; + case 6: /* ph */ + { + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(line, &temp_solution) == CParser::PARSER_ERROR) + { + input_error++; + break; + } + + temp_solution.Set_ph(temp_comp.Get_input_conc()); + + if (temp_comp.Get_equation_name().size() == 0) + { + break; + + } + temp_comp.Set_description("H(1)"); + isoln_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; + } + break; + case 7: /* pe */ + { + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(line, &temp_solution) == CParser::PARSER_ERROR) + { + input_error++; + break; + } + temp_solution.Set_pe(temp_comp.Get_input_conc()); + if (temp_comp.Get_equation_name().size() == 0) + { + break; + } + temp_comp.Set_description("E"); + isoln_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; + } + break; + case 9: /* isotope */ + { + cxxSolutionIsotope temp_isotope; + if (copy_token(token, &next_char) != CParser::TT_DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + continue; + } + temp_isotope.Set_isotope_name(token.c_str()); + /* read and save element name */ + { + char *temp_iso_name = string_duplicate(token.c_str()); + char *ptr1 = temp_iso_name; + get_num(&ptr1, &dummy); + temp_isotope.Set_isotope_number(dummy); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) + { + error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + return (CParser::PARSER_ERROR); + } + temp_isotope.Set_elt_name(ptr1); + } + /* read and store isotope ratio */ + if (copy_token(token, &next_char) != CParser::TT_DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_isotope.Set_ratio(dummy); + temp_isotope.Set_ratio_uncertainty(NAN); + + /* read and store isotope ratio uncertainty */ + int j; + if ((j = copy_token(token, &next_char)) != CParser::TT_EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + continue; + } + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_isotope.Set_ratio_uncertainty(dummy); + temp_isotope.Set_ratio_uncertainty_defined(true); + } + temp_solution.Get_isotopes()[temp_isotope.Get_isotope_name()] = temp_isotope; + } + break; + case 10: /* water */ + { + int j = copy_token(token, &next_char); + if (j == EMPTY) + { + temp_solution.Set_mass_water(1.0); + } + else if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for mass of water in solution."); + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_solution.Set_mass_water(dummy); + } + } + break; + case 11: /* pressure */ + case 12: + { + if (sscanf(next_char, SCANFORMAT, &dummy) != 1) + { + temp_solution.Set_patm(1); + } + else + { + temp_solution.Set_patm(dummy); + } + } + break; + case OPTION_DEFAULT: +/* + * Read concentration + */ + { + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(line, &temp_solution) == CParser::PARSER_ERROR) + { + input_error++; + break; + } + isoln_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; + if (temp_comp.Get_pe_reaction().size() > 0) + { + cxxChemRxn temp_chem_reaction; + isoln_ptr->Get_pe_reactions()[temp_comp.Get_pe_reaction()] = temp_chem_reaction; + } + } + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } +/* + * fix up default units and default pe + */ + std::map < std::string, cxxISolutionComp >::iterator it; + for (it = isoln_ptr->Get_comps().begin(); it != isoln_ptr->Get_comps().end(); it++) + { + token = it->first; + Utilities::str_tolower(token); + if (it->second.Get_units().size() == 0) + { + it->second.Set_units(isoln_ptr->Get_units().c_str()); + } + else + { + bool alk = false; + if (strstr(token.c_str(), "alk") == token.c_str()) + alk = true; + std::string token1 = it->second.Get_units(); + if (check_units(token1, alk, true, isoln_ptr->Get_units().c_str(), true) == CParser::PARSER_ERROR) + { + input_error++; + } + else + { + it->second.Set_units(token1.c_str()); + } + } + if (it->second.Get_pe_reaction().size() == 0) + { + it->second.Set_pe_reaction(isoln_ptr->Get_default_pe()); + } + } + Rxn_solution_map[n_user] = temp_solution; + + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solution(void) @@ -5683,9 +5271,22 @@ read_solution(void) break; case 11: /* pressure */ case 12: - if (sscanf(next_char, SCANFORMAT, &(solution[n]->patm)) != 1) + j = copy_token(token, &next_char, &l); + if (j == EMPTY) { - solution[n]->patm = 1; + solution[n]->patm = 1.0; + } + else if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for pressure (atm) of solution."); + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token, SCANFORMAT, &dummy); + solution[n]->patm = (LDBLE) dummy; } break; case OPTION_DEFAULT: @@ -5749,7 +5350,7 @@ read_solution(void) solution[n]->count_isotopes = count_isotopes; return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_species(void) @@ -5791,8 +5392,6 @@ read_species(void) /* VP: Density Start */ "millero", /* 21 */ /* VP: Density End */ - //"delta_v", /* 22 */ - //"deltav", /* 23 */ "vm" /* 22, molar volume, must replace delta_v */ }; int count_opt_list = 23; @@ -6139,15 +5738,13 @@ read_species(void) if (!vm_read) { /* copy millero parms into logk, for calculating pressure dependency... */ - for (i = 0; i < 3; i++) + for (i = 0; i < 7; i++) s_ptr->logk[vm0 + i] = s_ptr->millero[i]; + s_ptr->logk[vm0 + i] = 0; } opt_save = OPTION_DEFAULT; break; /* VP: Density End */ - - //case 22: /* delta_v */ - //case 23: /* deltav */ case 22: /* vm, molar volume */ if (s_ptr == NULL) { @@ -6158,9 +5755,10 @@ read_species(void) input_error++; break; } - read_delta_v_only(next_char, &s_ptr->logk[vm0], + read_vm_only(next_char, &s_ptr->logk[vm0], &s_ptr->original_deltav_units); vm_read = true; + print_density = OK; opt_save = OPTION_DEFAULT; break; case OPTION_DEFAULT: @@ -6539,8 +6137,6 @@ read_surface_species(void) "add_constant", /* 15 */ "cd_music", /* 16 */ "music", /* 17 */ - //"delta_v", /* 18 */ - //"deltav", /* 19 */ "vm" /* 18 */ }; int count_opt_list = 19; @@ -6815,19 +6411,17 @@ read_surface_species(void) } opt_save = OPTION_DEFAULT; break; - //case 18: /* delta_v */ - //case 19: /* deltav */ case 18: /* vm, molar volume */ - if (s_ptr == NULL) + if (s_ptr == NULL) { error_string = sformatf( "No reaction defined before option, %s.", - opt_list[opt]); + opt_list[opt]); error_msg(error_string, CONTINUE); input_error++; break; } - read_delta_v_only(next_char, &s_ptr->logk[vm0], + read_vm_only(next_char, &s_ptr->logk[vm0], &s_ptr->original_deltav_units); opt_save = OPTION_DEFAULT; break; @@ -6918,10 +6512,9 @@ read_surface_species(void) } return (return_value); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -read_surf(void) +read_surface(void) /* ---------------------------------------------------------------------- */ { /* @@ -6937,16 +6530,11 @@ read_surf(void) * ERROR if error occurred reading data * */ - int i, j, n, l; - int count_comps, count_charge; int n_user, n_user_end; - LDBLE conc, area, grams, thickness; + LDBLE conc; char *ptr, *ptr1; char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH], name[MAX_LENGTH]; - struct surface *surface_ptr; - struct surface_charge *charge_ptr; - struct surface_comp *comp_ptr; + std::string token, token1, name; int return_value, opt; char *next_char; @@ -6980,24 +6568,13 @@ read_surf(void) */ ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); - /* - * Find space for surface data - */ - surface_ptr = surface_search(n_user, &n, FALSE); - if (surface_ptr != NULL) - { - surface_free(&surface[n]); - } - else - { - n = count_surface++; - space((void **) ((void *) &surface), count_surface, &max_surface, - sizeof(struct surface)); - } - /* - * Initialize - */ - surface_init(&(surface[n]), n_user, n_user_end, description); + cxxSurface temp_surface; + cxxSurfaceComp *comp_ptr = NULL; + cxxSurfaceCharge *charge_ptr = NULL; + temp_surface.Set_new_def(true); + temp_surface.Set_n_user(n_user); + temp_surface.Set_n_user_end(n_user_end); + temp_surface.Set_description(description); free_check_null(description); if (use.Get_surface_in() == FALSE) @@ -7008,11 +6585,7 @@ read_surf(void) /* * Read surface data */ - count_charge = 0; - count_comps = 0; return_value = UNKNOWN; - comp_ptr = NULL; - charge_ptr = NULL; for (;;) { opt = get_option(opt_list, count_opt_list, &next_char); @@ -7034,11 +6607,13 @@ read_surf(void) case 14: /* equilibrium */ for (;;) { - i = copy_token(token, &next_char, &l); + int i = copy_token(token, &next_char); if (i == DIGIT) { - sscanf(token, "%d", &surface[n].n_solution); - surface[n].solution_equilibria = TRUE; + int j; + sscanf(token.c_str(), "%d", &j); + temp_surface.Set_solution_equilibria(true); + temp_surface.Set_n_solution(j); break; } if (i == EMPTY) @@ -7054,117 +6629,122 @@ read_surf(void) break; case 2: /* diffuse_layer */ case 3: - surface[n].thickness = 1e-8; - surface[n].dl_type = BORKOVEK_DL; - sscanf(next_char, SCANFORMAT, &surface[n].thickness); - /* surface[n].thickness = thickness; - } - */ break; + { + temp_surface.Set_thickness(1e-8); + temp_surface.Set_dl_type(cxxSurface::BORKOVEK_DL); + int j = sscanf(next_char, SCANFORMAT, &dummy); + if (j == 1) + { + temp_surface.Set_thickness(dummy); + } + } + break; case 4: /* no electrostatic */ case 5: - /*surface[n].edl = FALSE; */ - surface[n].type = NO_EDL; + temp_surface.Set_type(cxxSurface::NO_EDL); break; case 6: - surface[n].only_counter_ions = TRUE; + temp_surface.Set_only_counter_ions(get_true_false(next_char, TRUE) == TRUE); break; case 7: /* donnan for DL conc's */ - surface[n].dl_type = DONNAN_DL; - /*surface[n].diffuse_layer = TRUE; */ - thickness = 0.0; - for (;;) { - i = copy_token(token, &next_char, &l); - if (i == DIGIT) + temp_surface.Set_dl_type(cxxSurface::DONNAN_DL); + LDBLE thickness = 0.0; + for (;;) { - sscanf(token, SCANFORMAT, &surface[n].thickness); - thickness = 1; - continue; - } - else if (i != EMPTY) - { - if (token[0] == 'D' || token[0] == 'd') + int i = copy_token(token, &next_char); + if (i == DIGIT) { - if (thickness != 0) - { - error_msg - ("You must enter EITHER thickness OR Debye lengths (1/k),\n and relative DDL viscosity, DDL limit.\nCorrect is (for example): -donnan 1e-8 viscosity 0.5\n or (default values): -donnan debye_lengths 1 viscosity 1 limit 0.8", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - j = copy_token(token1, &next_char, &l); - if (j == DIGIT) - { - sscanf(token1, SCANFORMAT, - &surface[n].debye_lengths); - continue; - } - else if (j != EMPTY) - { - error_msg - ("Expected number of Debye lengths (1/k).", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_surface.Set_thickness(dummy); + thickness = 1; + continue; } - else if (token[0] == 'V' || token[0] == 'v') + else if (i != EMPTY) { - j = copy_token(token1, &next_char, &l); - if (j == DIGIT) + if (token[0] == 'D' || token[0] == 'd') { - sscanf(token1, SCANFORMAT, - &surface[n].DDL_viscosity); - continue; + if (thickness != 0) + { + error_msg + ("You must enter EITHER thickness OR Debye lengths (1/k),\n and relative DDL viscosity, DDL limit.\nCorrect is (for example): -donnan 1e-8 viscosity 0.5\n or (default values): -donnan debye_lengths 1 viscosity 1 limit 0.8", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + int j = copy_token(token1, &next_char); + if (j == DIGIT) + { + sscanf(token1.c_str(), SCANFORMAT, &dummy); + temp_surface.Set_debye_lengths(dummy); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number of Debye lengths (1/k).", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } } - else if (j != EMPTY) + else if (token[0] == 'V' || token[0] == 'v') + { + int j = copy_token(token1, &next_char); + if (j == DIGIT) + { + sscanf(token1.c_str(), SCANFORMAT, &dummy); + temp_surface.Set_DDL_viscosity(dummy); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number for relative DDL viscosity.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else if (token[0] == 'L' || token[0] == 'l') + { + int j = copy_token(token1, &next_char); + if (j == DIGIT) + { + sscanf(token1.c_str(), SCANFORMAT, &dummy); + temp_surface.Set_DDL_limit(dummy); + continue; + } + else if (j != EMPTY) + { + error_msg + ("Expected number for maximum of DDL water as fraction of bulk water.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + else { error_msg - ("Expected number for relative DDL viscosity.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - else if (token[0] == 'L' || token[0] == 'l') - { - j = copy_token(token1, &next_char, &l); - if (j == DIGIT) - { - sscanf(token1, SCANFORMAT, &surface[n].DDL_limit); - continue; - } - else if (j != EMPTY) - { - error_msg - ("Expected number for maximum of DDL water as fraction of bulk water.", - CONTINUE); + ("Expected diffuse layer thickness (m) or Debye lengths (1/k) for \n\tcalculating the thickness, and relative DDL viscosity and DDL limit.\nCorrect is (for example): -donnan 1e-8 visc 0.5\n or (default values): -donnan debye_lengths 1 visc 1 lim 0.8", + CONTINUE); error_msg(line_save, CONTINUE); input_error++; break; } } else - { - error_msg - ("Expected diffuse layer thickness (m) or Debye lengths (1/k) for \n\tcalculating the thickness, and relative DDL viscosity and DDL limit.\nCorrect is (for example): -donnan 1e-8 visc 0.5\n or (default values): -donnan debye_lengths 1 visc 1 lim 0.8", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; break; - } } - else - break; } break; case 8: /* cd_music */ - /*surface[n].edl = FALSE; */ - surface[n].type = CD_MUSIC; + temp_surface.Set_type(cxxSurface::CD_MUSIC); break; case 9: /* capacitances */ /* @@ -7179,49 +6759,56 @@ read_surf(void) input_error++; break; } - copy_token(token1, &next_char, &l); - if (sscanf(token1, SCANFORMAT, &grams) == 1) + copy_token(token1, &next_char); + if (sscanf(token1.c_str(), SCANFORMAT, &dummy) == 1) { - charge_ptr->capacitance[0] = grams; + charge_ptr->Set_capacitance0(dummy); } - copy_token(token1, &next_char, &l); - if (sscanf(token1, SCANFORMAT, &grams) == 1) + copy_token(token1, &next_char); + if (sscanf(token1.c_str(), SCANFORMAT, &dummy) == 1) { - charge_ptr->capacitance[1] = grams; + charge_ptr->Set_capacitance1(dummy); } break; case 10: /* sites */ case 11: /* sites_units */ case 15: /* site_units */ - j = copy_token(token1, &next_char, &l); - if (token1[0] == 'A' || token1[0] == 'a') { - surface[n].sites_units = SITES_ABSOLUTE; - } - else if (token1[0] == 'D' || token1[0] == 'd') - { - surface[n].sites_units = SITES_DENSITY; - } - else - { - error_msg - ("Character string expected to be 'Absolute' or 'Density' to define the units of the first item in the definition of a surface component.\n", - CONTINUE); - input_error++; - break; + int j = copy_token(token1, &next_char); + if (j != EMPTY && (token1[0] == 'A' || token1[0] == 'a')) + { + temp_surface.Set_sites_units(cxxSurface::SITES_ABSOLUTE); + } + else if (j != EMPTY && (token1[0] == 'D' || token1[0] == 'd')) + { + temp_surface.Set_sites_units(cxxSurface::SITES_DENSITY); + } + else + { + error_msg + ("Character string expected to be 'Absolute' or 'Density' to define the units of the first item in the definition of a surface component.\n", + CONTINUE); + input_error++; + break; + } } break; + // CCM not implemented yet case 12: /* constant_capacitance */ case 13: /* ccm */ - surface[n].type = CCM; - copy_token(token1, &next_char, &l); - if (sscanf(token1, SCANFORMAT, &(charge_ptr->capacitance[0])) != 1) + temp_surface.Set_type(cxxSurface::CCM); + copy_token(token1, &next_char); + if (sscanf(token1.c_str(), SCANFORMAT, &dummy) != 1) { error_msg("Expected capacitance for constant_capacitance model.\n", CONTINUE); input_error++; break; } + else + { + charge_ptr->Set_capacitance0(dummy); + } /* constant capacitance model not implemented yet */ error_msg("Constant capacitance model not implemented.", CONTINUE); @@ -7232,322 +6819,241 @@ read_surf(void) /* * Read surface component */ - ptr = line; - i = copy_token(token, &ptr, &l); - if (i != UPPER && token[0] != '[') { - error_msg - ("Expected surface name to begin with a capital letter.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - /* - * Realloc space for new surface component - */ - surface[n].comps = - (struct surface_comp *) PHRQ_realloc(surface[n].comps, - (size_t) (count_comps + - 1) * - sizeof(struct - surface_comp)); - if (surface[n].comps == NULL) - malloc_error(); - surface[n].comps[count_comps].formula = string_hsave(token); - surface[n].comps[count_comps].formula_totals = NULL; - surface[n].comps[count_comps].formula_z = 0.0; - surface[n].comps[count_comps].moles = 0; - surface[n].comps[count_comps].la = 0; - surface[n].comps[count_comps].charge = 0; - surface[n].comps[count_comps].cb = 0; - surface[n].comps[count_comps].phase_name = NULL; - surface[n].comps[count_comps].phase_proportion = 0; - surface[n].comps[count_comps].rate_name = NULL; - comp_ptr = &(surface[n].comps[count_comps]); - surface[n].comps[count_comps].Dw = 0; - i = copy_token(token1, &ptr, &l); - if (i == DIGIT) - { - /* - * Read surface concentration - */ - /* surface concentration is read directly */ - if (sscanf(token1, SCANFORMAT, &conc) < 1) + ptr = line; + int i = copy_token(token, &ptr); + if (i != UPPER && token[0] != '[') { - error_msg("Expected number of surface sites in moles.", - CONTINUE); + error_msg + ("Expected surface name to begin with a capital letter.", + CONTINUE); error_msg(line_save, CONTINUE); input_error++; break; } - surface[n].comps[count_comps].moles = conc; - /* - * Read equilibrium phase name or kinetics rate name - */ - } - else if (i != EMPTY) - { - /* surface conc. is related to mineral or kinetics */ - surface[n].comps[count_comps].phase_name = - string_hsave(token1); - j = copy_token(token1, &ptr, &l); + cxxSurfaceComp temp_comp; + temp_surface.Get_surface_comps().push_back(temp_comp); + comp_ptr = &(temp_surface.Get_surface_comps().back()); + comp_ptr->Set_formula(token.c_str()); - /* read optional 'equilibrium_phases' or 'kinetics' */ - if (j == DIGIT) + i = copy_token(token1, &ptr); + if (i == DIGIT) { - surface[n].related_phases = TRUE; - } - else - { - if (token1[0] == 'K' || token1[0] == 'k') + /* + * Read surface concentration + */ + /* surface concentration is read directly */ + if (sscanf(token1.c_str(), SCANFORMAT, &conc) < 1) { - surface[n].comps[count_comps].rate_name = - surface[n].comps[count_comps].phase_name; - surface[n].comps[count_comps].phase_name = NULL; - surface[n].related_rate = TRUE; - } - else if (token1[0] == 'E' || token1[0] == 'e') - { - surface[n].related_phases = TRUE; - surface[n].comps[count_comps].rate_name = NULL; - } - else - { - error_msg - ("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate surface to mineral or kinetic reaction.\n", - CONTINUE); + error_msg("Expected number of surface sites in moles.", + CONTINUE); + error_msg(line_save, CONTINUE); input_error++; break; } - j = copy_token(token1, &ptr, &l); + comp_ptr->Set_moles(conc); + /* + * Read equilibrium phase name or kinetics rate name + */ } + else if (i != EMPTY) + { - /* read proportion */ - if (j != DIGIT) - { - error_msg - ("Expected a coefficient to relate surface to mineral or kinetic reaction.\n", - CONTINUE); - input_error++; - break; - } - sscanf(token1, SCANFORMAT, - &surface[n].comps[count_comps].phase_proportion); - /* real conc must be defined in tidy_model */ - conc = 1.0; - } - else - { - error_msg - ("Expected concentration of surface, mineral name, or kinetic reaction name.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - /* - * Accumulate elements in elt_list - */ - count_elts = 0; - paren_count = 0; - ptr1 = token; - get_elts_in_species(&ptr1, conc); + /* surface conc. is related to mineral or kinetics */ + comp_ptr->Set_phase_name(token1.c_str()); + int j = copy_token(token1, &ptr); - /* - * save formula for adjusting number of exchange sites - */ - - ptr1 = token; - get_token(&ptr1, token1, - &surface[n].comps[count_comps].formula_z, &l); - surface[n].comps[count_comps].formula_totals = elt_list_save(); - surface[n].comps[count_comps].totals = elt_list_save(); - /* - * Search for charge structure - */ - ptr1 = token; - get_elt(&ptr1, name, &l); - ptr1 = strchr(name, '_'); - if (ptr1 != NULL) - ptr1[0] = '\0'; - for (i = 0; i < count_charge; i++) - { - if (strcmp(surface[n].charge[i].name, name) == 0) - break; - } - if (i >= count_charge) - { - surface[n].charge = - (struct surface_charge *) PHRQ_realloc(surface[n].charge, - (size_t) - (count_charge + - 1) * - sizeof(struct - surface_charge)); - if (surface[n].charge == NULL) - malloc_error(); - i = count_charge; - surface[n].charge[i].name = string_hsave(name); - if (surface[n].comps[count_comps].phase_name == NULL - && surface[n].comps[count_comps].rate_name == NULL) - { - surface[n].charge[i].specific_area = 600.0; - surface[n].charge[i].grams = 0.0; - } - else - { - surface[n].charge[i].specific_area = 0.0; - surface[n].charge[i].grams = 1.0; - } - surface[n].charge[i].charge_balance = 0.0; - surface[n].charge[i].mass_water = 0.0; - surface[n].charge[i].diffuse_layer_totals = NULL; - surface[n].charge[i].count_g = 0; - surface[n].charge[i].g = NULL; - surface[n].charge[i].la_psi = 0; - surface[n].charge[i].la_psi1 = 0; - surface[n].charge[i].la_psi2 = 0; - surface[n].charge[i].psi = 0; - surface[n].charge[i].psi1 = 0; - surface[n].charge[i].psi2 = 0; - surface[n].charge[i].capacitance[0] = 1.0; - surface[n].charge[i].capacitance[1] = 5.0; - surface[n].charge[i].sigma0 = 0; - surface[n].charge[i].sigma1 = 0; - surface[n].charge[i].sigma2 = 0; - surface[n].charge[i].sigmaddl = 0; - count_charge++; - } - charge_ptr = &(surface[n].charge[i]); - surface[n].comps[count_comps].charge = i; - count_comps++; - /* - * Read surface area (m2/g) - */ - copy_token(token1, &ptr, &l); - if (sscanf(token1, SCANFORMAT, &area) == 1) - { - surface[n].charge[i].specific_area = area; - } - else - { - break; - } - /* - * Read grams of solid (g) - */ - copy_token(token1, &ptr, &l); - if (sscanf(token1, SCANFORMAT, &grams) == 1) - { - surface[n].charge[i].grams = grams; - } - /* read Dw */ - copy_token(token1, &ptr, &l); - str_tolower(token1); - if (strcmp(token1, "dw") == 0) - { - j = copy_token(token1, &ptr, &l); - if (j != DIGIT) - { - error_msg - ("Expected surface diffusion coefficient (m2/s).\n", - CONTINUE); - input_error++; - break; - } - else - { - sscanf(token1, SCANFORMAT, - &surface[n].comps[count_comps - 1].Dw); - if (surface[n].comps[count_comps - 1].Dw > 0) + /* read optional 'equilibrium_phases' or 'kinetics' */ + if (j != DIGIT) { - surface[n].transport = TRUE; - if (surface[n].related_rate == TRUE - || surface[n].related_phases == TRUE) + if (token1[0] == 'K' || token1[0] == 'k') + { + comp_ptr->Set_rate_name(comp_ptr->Get_phase_name().c_str()); + comp_ptr->Set_phase_name(NULL); + } + else if (token1[0] == 'E' || token1[0] == 'e') + { + comp_ptr->Set_rate_name(NULL); + } + else { error_msg - ("Can't transport surfaces related to phases or rates (yet).", - CONTINUE); + ("Character string expected to be 'equilibrium_phase' or 'kinetics' to relate surface to mineral or kinetic reaction.\n", + CONTINUE); input_error++; + break; } + j = copy_token(token1, &ptr); } + + /* read proportion */ + if (j != DIGIT) + { + error_msg + ("Expected a coefficient to relate surface to mineral or kinetic reaction.\n", + CONTINUE); + input_error++; + break; + } + sscanf(token1.c_str(), SCANFORMAT, &dummy); + comp_ptr->Set_phase_proportion(dummy); + /* real conc must be defined in tidy_model */ + conc = 1.0; + } + else + { + error_msg + ("Expected concentration of surface, mineral name, or kinetic reaction name.", + CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; break; } + /* + * Accumulate elements in elt_list + */ + count_elts = 0; + paren_count = 0; + char * formula = string_duplicate(token.c_str()); + ptr1 = formula; + get_elts_in_species(&ptr1, conc); + /* + * save formula for adjusting number of exchange sites + */ + ptr1 = formula; + int l; + // name is work space + char * name = string_duplicate(formula); + name[0] = '\0'; + get_token(&ptr1, name, &dummy, &l); + comp_ptr->Set_formula_z(dummy); + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); + /* + * Search for charge structure + */ + ptr1 = formula; + get_elt(&ptr1, name, &l); + ptr1 = strchr(name, '_'); + if (ptr1 != NULL) + ptr1[0] = '\0'; + charge_ptr = temp_surface.Find_charge(name); + if (charge_ptr == NULL) + { + cxxSurfaceCharge temp_charge; + temp_charge.Set_name(name); + if (comp_ptr->Get_phase_name().size() == 0 + && comp_ptr->Get_rate_name().size() == 0) + { + temp_charge.Set_specific_area(600.0); + temp_charge.Set_grams(0.0); + } + else + { + temp_charge.Set_specific_area(0.0); + temp_charge.Set_grams(1.0); + } + temp_surface.Get_surface_charges().push_back(temp_charge); + charge_ptr = temp_surface.Find_charge(name); + } + comp_ptr->Set_charge_name(name); + /* + * Read surface area (m2/g) + */ + copy_token(token1, &ptr); + if (sscanf(token1.c_str(), SCANFORMAT, &dummy) == 1) + { + charge_ptr->Set_specific_area(dummy); + } + else + { + break; + } + /* + * Read grams of solid (g) + */ + copy_token(token1, &ptr); + if (sscanf(token1.c_str(), SCANFORMAT, &dummy) == 1) + { + charge_ptr->Set_grams(dummy); + } + /* read Dw */ + copy_token(token1, &ptr); + Utilities::str_tolower(token1); + if (strcmp(token1.c_str(), "dw") == 0) + { + int j = copy_token(token1, &ptr); + if (j != DIGIT) + { + error_msg + ("Expected surface diffusion coefficient (m2/s).\n", + CONTINUE); + input_error++; + break; + } + else + { + sscanf(token1.c_str(), SCANFORMAT, &dummy); + comp_ptr->Set_Dw(dummy); + if (dummy > 0) + { + temp_surface.Set_transport(true); + if (temp_surface.Get_related_rate() + || temp_surface.Get_related_phases()) + { + error_msg + ("Can't transport surfaces related to phases or rates (yet).", + CONTINUE); + input_error++; + } + } + break; + } + } } break; - } if (return_value == EOF || return_value == KEYWORD) break; } - surface[n].count_comps = count_comps; - surface[n].count_charge = count_charge; - /* sort charge */ - qsort(surface[n].charge, - (size_t) surface[n].count_charge, - (size_t) sizeof(struct surface_charge), surface_charge_compare); - - /* renumber charge variable in comps */ - for (i = 0; i < surface[n].count_comps; i++) - { - char * temp_formula = string_duplicate(surface[n].comps[i].formula); - ptr = temp_formula; - copy_token(token, &ptr, &l); - ptr1 = token; - get_elt(&ptr1, name, &l); - ptr1 = strchr(name, '_'); - if (ptr1 != NULL) - ptr1[0] = '\0'; - for (j = 0; j < surface[n].count_charge; j++) - { - if (strcmp(surface[n].charge[j].name, name) == 0) - { - surface[n].comps[i].charge = j; - break; - } - } - free_check_null(temp_formula); - assert(j < surface[n].count_charge); - } + // Sort comps and charge + temp_surface.Sort_comps(); /* * copy Dw > 0 to all comps with the same charge structure, check edl & dif for surface transport */ - if (surface[n].transport == TRUE) + if (temp_surface.Get_transport()) { - /* - if (surface[n].edl == FALSE || surface[n].diffuse_layer == FALSE) { - surface[n].edl = TRUE; - surface[n].diffuse_layer = TRUE; - warning_msg("Can't transport without edl and diffuse layer, set to true"); - } - */ - if (surface[n].type <= NO_EDL) + if (temp_surface.Get_type() <= cxxSurface::NO_EDL) { input_error++; error_msg ("Must use default Dzombak and Morel or -cd_music for surface transport.", CONTINUE); } - if (surface[n].dl_type <= NO_DL) + if (temp_surface.Get_dl_type() <= cxxSurface::NO_DL) { input_error++; error_msg ("Must use -donnan or -diffuse_layer for surface transport.", CONTINUE); } - for (i = 0; i < count_comps; i++) + for (size_t i = 0; i < temp_surface.Get_surface_comps().size(); i++) { - if (surface[n].comps[i].Dw > 0) + comp_ptr = &(temp_surface.Get_surface_comps()[i]); + if (comp_ptr->Get_Dw() > 0) { - for (j = 0; j < count_comps; j++) + std::string name = comp_ptr->Get_charge_name(); + for (size_t j = 0; j < temp_surface.Get_surface_comps().size(); j++) { - if (surface[n].comps[j].charge == - surface[n].comps[i].charge) - surface[n].comps[j].Dw = surface[n].comps[i].Dw; + cxxSurfaceComp *comp_ptr1 = &(temp_surface.Get_surface_comps()[j]); + std::string name1 = comp_ptr1->Get_charge_name(); + if (name == name1) + { + comp_ptr1->Set_Dw(comp_ptr->Get_Dw()); + } } } } @@ -7555,16 +7061,16 @@ read_surf(void) /* * Make sure surface area is defined */ - /*if (surface[n].edl == TRUE) { */ - if (surface[n].type == DDL || surface[n].type == CD_MUSIC) + if (temp_surface.Get_type() == cxxSurface::DDL || temp_surface.Get_type() == cxxSurface::CD_MUSIC) { - for (i = 0; i < count_charge; i++) + for (size_t i = 0; i < temp_surface.Get_surface_charges().size(); i++) { - if (surface[n].charge[i].grams * - surface[n].charge[i].specific_area <= 0) + charge_ptr = &(temp_surface.Get_surface_charges()[i]); + if (charge_ptr->Get_grams() * + charge_ptr->Get_specific_area() <= 0) { error_string = sformatf( "Surface area not defined for %s.\n", - surface[n].charge[i].name); + charge_ptr->Get_name().c_str()); error_msg(error_string, CONTINUE); input_error++; } @@ -7573,36 +7079,36 @@ read_surf(void) /* * Logical checks */ - if (surface[n].type == UNKNOWN_DL) + if (temp_surface.Get_type() == cxxSurface::UNKNOWN_DL) { error_string = sformatf( "Unknown surface type.\n"); error_msg(error_string, CONTINUE); input_error++; } - else if (surface[n].type == NO_EDL) + else if (temp_surface.Get_type() == cxxSurface::NO_EDL) { - if (surface[n].dl_type != NO_DL) + if (temp_surface.Get_dl_type() != cxxSurface::NO_DL) { error_string = sformatf( "No electrostatic term calculations do not allow calculation of the diffuse layer composition.\n"); warning_msg(error_string); - surface[n].dl_type = NO_DL; + temp_surface.Set_dl_type(cxxSurface::NO_DL); } } - else if (surface[n].type == DDL) + else if (temp_surface.Get_type() == cxxSurface::DDL) { /* all values of dl_type are valid */ } - else if (surface[n].type == CD_MUSIC) + else if (temp_surface.Get_type() == cxxSurface::CD_MUSIC) { - if (surface[n].dl_type == BORKOVEK_DL) + if (temp_surface.Get_dl_type() == cxxSurface::BORKOVEK_DL) { error_string = sformatf( "Borkovec and Westall diffuse layer calculation is not allowed with a CD_MUSIC surface.\n\tUsing Donnan diffuse layer calculation."); warning_msg(error_string); - surface[n].dl_type = DONNAN_DL; + temp_surface.Set_dl_type(cxxSurface::DONNAN_DL); } - if (surface[n].debye_lengths > 0) + if (temp_surface.Get_debye_lengths() > 0) { error_msg ("Variable DDL thickness is not permitted in CD_MUSIC. Fix DDL thickness\n\tfor example (default value): -donnan 1e-8", @@ -7610,9 +7116,10 @@ read_surf(void) input_error++; } } + temp_surface.Sort_comps(); + Rxn_surface_map[n_user] = temp_surface; return (return_value); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: read_surface_master_species(void) @@ -8227,19 +7734,6 @@ read_debug(void) LDBLE ct; sscanf(next_char, SCANFORMAT, &ct); convergence_tolerance = ct; - //if (punch.high_precision == TRUE) - //{ - // if (ct < 1e-12) - // { - // convergence_tolerance = ct; - // } - //} - //else - //{ - // { - // convergence_tolerance = ct; - // } - //} } break; case 15: /* numerical_derivatives */ @@ -8545,7 +8039,163 @@ check_key(const char *str) } return (FALSE); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, + const char *default_units, bool print) +/* ---------------------------------------------------------------------- */ +{ +#define NUNITS (sizeof(units) / sizeof(char *)) +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity TRUE if alkalinity, FALSE if any other total, + * check_compatibility TRUE check alk and default units, FALSE otherwise + * default_units character string of default units (check /L, /kg, etc) + * print TRUE print warning messages + * Output: + * tot_units standard form for unit + */ + const char *units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + Utilities::squeeze_white(tot_units); + Utilities::str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + size_t pos; + if ((pos = tot_units.find("/l")) != std::string::npos) + { + tot_units = tot_units.substr(0, pos + 2); + } + else if ((pos = tot_units.find("/kgs")) != std::string::npos) + { + tot_units = tot_units.substr(0, pos + 4); + } + else if ((pos = tot_units.find("/kgw")) != std::string::npos) + { + tot_units = tot_units.substr(0, pos + 4); + } +/* + * Check if unit in list + */ + bool found = false; + size_t i; + for (i = 0; i < NUNITS; i++) + { + if (strcmp(tot_units.c_str(), units[i]) == 0) + { + found = true; + break; + } + } + if (!found) + { + if (print) + { + error_string = sformatf( "Unknown unit, %s.", tot_units.c_str()); + error_msg(error_string, CONTINUE); + } + return (ERROR); + } + +/* + * Check if units are compatible with default_units + */ + if (!check_compatibility) + return (OK); +/* + * Special cases for alkalinity + */ + if (alkalinity && strstr(tot_units.c_str(), "Mol") != NULL) + { + if (print == TRUE) + { + error_string = sformatf( + "Alkalinity given in moles, assumed to be equivalents."); + warning_msg(error_string); + } + replace("Mol", "eq", tot_units); + } + if (!alkalinity && strstr(tot_units.c_str(), "eq") != NULL) + { + if (print) + { + error_msg("Only alkalinity can be entered in equivalents.", + CONTINUE); + } + return (ERROR); + } +/* + * See if default_units are compatible with tot_units + */ + if (strstr(default_units, "/l") && strstr(tot_units.c_str(), "/l")) + return (OK); + if (strstr(default_units, "/kgs") && strstr(tot_units.c_str(), "/kgs")) + return (OK); + if (strstr(default_units, "/kgw") && strstr(tot_units.c_str(), "/kgw")) + return (OK); + + std::string string = default_units; + Utilities::replace("kgs", "kg solution", string); + Utilities::replace("kgs", "kg solution", tot_units); + Utilities::replace("kgw", "kg water", string); + Utilities::replace("kgw", "kg water", tot_units); + Utilities::replace("/l", "/L", string); + Utilities::replace("Mol", "mol", string); + Utilities::replace("/l", "/L", tot_units); + Utilities::replace("Mol", "mol", tot_units); + if (print == TRUE) + { + error_string = sformatf( + "Units for master species, %s, are not compatible with default units, %s.", + tot_units.c_str(), string.c_str()); + error_msg(error_string, CONTINUE); + } + return (ERROR); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: check_units(char *tot_units, int alkalinity, int check_compatibility, @@ -8704,7 +8354,7 @@ check_units(char *tot_units, int alkalinity, int check_compatibility, } return (ERROR); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: find_option(const char *item, int *n, const char **list, int count_list, int exact) @@ -9466,12 +9116,9 @@ read_solid_solutions(void) * ERROR if error occurred reading data * */ - //int i, j, n, l; - //int count_s_s, number_s_s, count_comps; int n_user, n_user_end; char *ptr; char *description; - //char token[MAX_LENGTH]; std::string token; int return_value, opt; @@ -9972,7 +9619,7 @@ read_solid_solutions(void) ptr = line; copy_token(token, &ptr); ss_ptr->Set_name(token); - ss_ptr->Set_total_moles(NAN); + ss_ptr->Set_total_moles(0.0); break; } if (return_value == EOF || return_value == KEYWORD) @@ -10386,8 +10033,6 @@ read_named_logk(void) "ln_alpha1000", /* 7 */ "add_logk", /* 8 */ "add_log_k", /* 9 */ - //"delta_v", /* 10 */ - //"deltav", /* 11 */ "vm" /* 10 */ }; int count_opt_list = 11; @@ -10552,8 +10197,6 @@ read_named_logk(void) logk_ptr->count_add_logk++; opt_save = OPTION_DEFAULT; break; - //case 10: /* delta_v */ - //case 11: /* deltav */ case 10: /* vm, molar volume */ if (logk_ptr == NULL) { @@ -10564,7 +10207,7 @@ read_named_logk(void) input_error++; break; } - read_delta_v_only(next_char, &logk_ptr->log_k[vm0], + read_vm_only(next_char, &logk_ptr->log_k[vm0], &logk_ptr->original_deltav_units); logk_copy2orig(logk_ptr); opt_save = OPTION_DEFAULT; @@ -10694,14 +10337,6 @@ read_copy(void) { n_user_end = n_user_start; } - if (n_user_start < 0) - { - //error_msg("Target index number must be a positive integer.", - // CONTINUE); - //error_msg(line_save, CONTINUE); - //input_error++; - //return (ERROR); - } } else { @@ -10811,7 +10446,6 @@ read_reaction_pressure(void) /* * Make parser */ - //CParser parser(*phrq_io->get_istream(), this->phrq_io); CParser parser(this->phrq_io); if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); atm.read(parser); @@ -10859,18 +10493,9 @@ read_reaction_pressure_raw(void) assert(!reading_database()); cxxPressure atm(this->phrq_io); - //char *ptr = line; - //char *description; - //int n_user, n_user_end; - //read_number_description(ptr, &n_user, &n_user_end, &description); - //atm.Set_n_user(n_user); - //atm.Set_n_user_end(n_user); - //atm.Set_description(description); - //free_check_null(description); /* * Make parser */ - //CParser parser(*phrq_io->get_istream(), this->phrq_io); CParser parser(this->phrq_io); if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); atm.read_raw(parser); @@ -10955,7 +10580,6 @@ read_temperature(void) /* * Make parser */ - //CParser parser(*phrq_io->get_istream(), this->phrq_io); CParser parser(this->phrq_io); if (pr.echo_input == FALSE) parser.set_echo_file(CParser::EO_NONE); t_react.read(parser); diff --git a/phreeqc/sit.cpp b/phreeqc/sit.cpp index 986501e8..4cf20b09 100644 --- a/phreeqc/sit.cpp +++ b/phreeqc/sit.cpp @@ -1,7 +1,7 @@ #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" - +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -353,6 +353,7 @@ sit(void) } } I = XI / 2.0e0; + I = mu_x; // Added equation for MU DI = sqrt(I); /* C @@ -494,7 +495,7 @@ set_sit(int initial) * Revises guesses whether initial is true or not */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; /* * Set initial log concentrations to zero */ @@ -515,23 +516,27 @@ set_sit(int initial) /* * Set master species activities */ - tc_x = solution_ptr->tc; + tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; - patm_x = solution_ptr->patm; +#ifdef PHREEQC2 + patm_x = solution_ptr->Get_patm(); +#else + //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) +#endif /* * H+, e-, H2O */ - mass_water_aq_x = solution_ptr->mass_water; - mu_x = solution_ptr->mu; + mass_water_aq_x = solution_ptr->Get_mass_water(); + mu_x = solution_ptr->Get_mu(); s_h2o->moles = mass_water_aq_x / gfw_water; - s_h2o->la = log10(solution_ptr->ah2o); + s_h2o->la = log10(solution_ptr->Get_ah2o()); AW = pow((LDBLE) 10.0E0, s_h2o->la); - s_hplus->la = -solution_ptr->ph; + s_hplus->la = -solution_ptr->Get_ph(); s_hplus->lm = s_hplus->la; s_hplus->moles = exp(s_hplus->lm * LOG_10) * mass_water_aq_x; - s_eminus->la = -solution_ptr->solution_pe; + s_eminus->la = -solution_ptr->Get_pe(); if (initial == TRUE) sit_initial_guesses(); - if (dl_type_x != NO_DL) initial_surface_water(); + if (dl_type_x != cxxSurface::NO_DL) initial_surface_water(); sit_revise_guesses(); return (OK); } @@ -546,12 +551,12 @@ sit_initial_guesses(void) * ionic strength */ int i; - struct solution *solution_ptr; + cxxSolution *solution_ptr; solution_ptr = use.Get_solution_ptr(); mu_x = s_hplus->moles + - exp((solution_ptr->ph - 14.) * LOG_10) * mass_water_aq_x; + exp((solution_ptr->Get_ph() - 14.) * LOG_10) * mass_water_aq_x; mu_x /= mass_water_aq_x; s_h2o->la = 0.0; for (i = 0; i < count_unknowns; i++) @@ -845,6 +850,10 @@ Restart: x[i]->moles += d2; break; case MU: + d2 = d * mu_x; + mu_x += d2; + gammas(mu_x); + break; case PP: case SS_MOLES: continue; @@ -894,6 +903,10 @@ Restart: mass_water_aq_x /= (1 + d); x[i]->master[0]->s->moles = mass_water_aq_x / gfw_water; break; + case MU: + mu_x -= d2; + gammas(mu_x); + break; case GAS_MOLES: if (gas_in == FALSE) continue; @@ -1058,8 +1071,8 @@ model_sit(void) } molalities(TRUE); if (use.Get_surface_ptr() != NULL && - use.Get_surface_ptr()->dl_type != NO_DL && - use.Get_surface_ptr()->related_phases == TRUE) + use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && + use.Get_surface_ptr()->Get_related_phases() == TRUE) initial_surface_water(); mb_sums(); mb_gases(); @@ -1305,7 +1318,7 @@ gammas_sit() { s_x[i]->lg = log10(fabs(s_x[i]->equiv) / s_x[i]->alk); } - if (((cxxExchange *) use.Get_exchange_ptr())->Get_pitzer_exchange_gammas()) + if (use.Get_exchange_ptr()->Get_pitzer_exchange_gammas()) { /* Assume equal gamma's of solute and exchangeable species... */ for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 2e35841c..99831892 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -1,6 +1,8 @@ typedef unsigned char boolean; #include "Phreeqc.h" #include "phqalloc.h" +#include "Solution.h" +#include "Utils.h" #define STRING 11 #define NUMBER 12 @@ -12,7 +14,6 @@ typedef unsigned char boolean; #define OPTION_ERROR -3 #define OPTION_DEFAULT -4 #define OPT_1 -5 - /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solution_spread(void) @@ -32,10 +33,8 @@ read_solution_spread(void) * */ struct spread_row *heading, *row_ptr, *units; - int i, j, l, j1, num, count; - int strings, numbers; + int count, strings, numbers; int spread_lines; - char token[MAX_LENGTH], token1[MAX_LENGTH]; char *ptr; struct defaults soln_defaults; int return_value, opt; @@ -72,8 +71,7 @@ read_solution_spread(void) /* fill in soln_defaults.iso */ soln_defaults.count_iso = count_iso_defaults; - soln_defaults.iso = - (struct iso *) PHRQ_malloc((size_t) soln_defaults.count_iso * + soln_defaults.iso = (struct iso *) PHRQ_malloc((size_t) soln_defaults.count_iso * sizeof(struct iso)); if (soln_defaults.iso == NULL) malloc_error(); @@ -85,20 +83,21 @@ read_solution_spread(void) units = NULL; return_value = UNKNOWN; spread_lines = 0; + CParser parser(this->phrq_io); /* * Loop on solutions */ for (;;) { + std::string token, token1; opt = get_option(opt_list, count_opt_list, &next_char); if (spread_lines == 0 && opt != OPTION_DEFAULT) { row_ptr = string_to_spread_row(line); - count = 0; ptr = line; - numbers = 0; - strings = 0; - while (((j = copy_token(token, &ptr, &l)) != EMPTY)) + count = numbers = strings = 0; + int j; + while (((j = copy_token(token, &ptr)) != EMPTY)) { count++; if (j == UPPER || j == LOWER) @@ -110,13 +109,13 @@ read_solution_spread(void) * Is 2nd token all number */ ptr = line; - copy_token(token, &ptr, &l); - j = copy_token(token, &ptr, &l); - num = FALSE; + copy_token(token, &ptr); + j = copy_token(token, &ptr); + bool num = false; if (j == DIGIT) { - strtod(token, &ptr); - j1 = copy_token(token1, &ptr, &l); + strtod(token.c_str(), &ptr); + int j1 = copy_token(token1, &ptr); if (j1 != EMPTY) { num = FALSE; @@ -131,7 +130,7 @@ read_solution_spread(void) * Starts with hyphen */ ptr = line; - copy_token(token, &ptr, &l); + copy_token(token, &ptr); if (token[0] == '-') { opt = opt; @@ -234,7 +233,7 @@ read_solution_spread(void) { numbers = 0; strings = 0; - for (i = 0; i < heading->count; i++) + for (int i = 0; i < heading->count; i++) { if (row_ptr->type_vector[i] == STRING) { @@ -267,12 +266,12 @@ read_solution_spread(void) break; case 4: /* units */ case 8: /* unit */ - if (copy_token(token, &next_char, &l) == EMPTY) + if (copy_token(token, &next_char) == EMPTY) break; { if (check_units(token, FALSE, FALSE, NULL, TRUE) == OK) { - soln_defaults.units = string_hsave(token); + soln_defaults.units = string_hsave(token.c_str()); } else { @@ -281,11 +280,11 @@ read_solution_spread(void) } break; case 5: /* redox */ - if (copy_token(token, &next_char, &l) == EMPTY) + if (copy_token(token, &next_char) == EMPTY) break; - if (parse_couple(token) == OK) + if (parser.parse_couple(token) == OK) { - soln_defaults.redox = string_hsave(token); + soln_defaults.redox = string_hsave(token.c_str()); } else { @@ -293,18 +292,18 @@ read_solution_spread(void) } break; case 6: /* ph */ - copy_token(token, &next_char, &l); - sscanf(token, SCANFORMAT, &(soln_defaults.ph)); - if (copy_token(token, &next_char, &l) != EMPTY) + copy_token(token, &next_char); + sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.ph)); + if (copy_token(token, &next_char) != EMPTY) { warning_msg ("Not possible to use phase name or saturation index in definition of default pH in SOLUTION_SPREAD."); } break; case 7: /* pe */ - copy_token(token, &next_char, &l); - sscanf(token, SCANFORMAT, &(soln_defaults.pe)); - if (copy_token(token, &next_char, &l) != EMPTY) + copy_token(token, &next_char); + sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.pe)); + if (copy_token(token, &next_char) != EMPTY) { warning_msg ("Not possible to use phase name or saturation index in definition of default pe in SOLUTION_SPREAD."); @@ -313,127 +312,137 @@ read_solution_spread(void) case 11: /* isotope_uncertainty */ case 12: /* uncertainty */ case 13: /* uncertainties */ - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - error_string = sformatf( "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - for (i = 0; i < soln_defaults.count_iso; i++) - { - if (strcmp(token, soln_defaults.iso[i].name) == 0) - { - break; - } - } - if (i == soln_defaults.count_iso) - { - soln_defaults.iso = - (struct iso *) PHRQ_realloc(soln_defaults.iso, - (size_t) (i + - 1) * - sizeof(struct iso)); - if (soln_defaults.iso == NULL) - malloc_error(); - soln_defaults.iso[i].name = string_hsave(token); - soln_defaults.iso[i].value = NAN; - soln_defaults.iso[i].uncertainty = NAN; - soln_defaults.count_iso++; - } - - /* read and store isotope ratio uncertainty */ - if ((j = copy_token(token, &next_char, &l)) != EMPTY) - { - if (j != DIGIT) + if (copy_token(token, &next_char) != DIGIT) { input_error++; - error_string = sformatf( - "Expected numeric value for uncertainty in isotope ratio."); + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); error_msg(error_string, CONTINUE); continue; } + int i; + for (i = 0; i < soln_defaults.count_iso; i++) + { + if (strcmp(token.c_str(), soln_defaults.iso[i].name) == 0) + { + break; + } + } + if (i == soln_defaults.count_iso) + { + soln_defaults.iso = + (struct iso *) PHRQ_realloc(soln_defaults.iso, + (size_t) (i + + 1) * + sizeof(struct iso)); + if (soln_defaults.iso == NULL) + malloc_error(); + soln_defaults.iso[i].name = string_hsave(token.c_str()); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } + + /* read and store isotope ratio uncertainty */ + int j; + if ((j = copy_token(token, &next_char)) != EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + else + { + sscanf(token.c_str(), SCANFORMAT, + &(soln_defaults.iso[i].uncertainty)); + } + } else { - sscanf(token, SCANFORMAT, - &(soln_defaults.iso[i].uncertainty)); + soln_defaults.iso[i].uncertainty = NAN; } } - else - { - soln_defaults.iso[i].uncertainty = NAN; - } break; case 10: /* water */ - j = copy_token(token, &next_char, &l); - if (j != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } - else - { - sscanf(token, SCANFORMAT, &(soln_defaults.water)); - } - break; - case 9: /* isotope */ - if (copy_token(token, &next_char, &l) != DIGIT) - { - input_error++; - error_string = sformatf( "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - for (i = 0; i < soln_defaults.count_iso; i++) - { - if (strcmp(token, soln_defaults.iso[i].name) == 0) - { - break; - } - } - if (i == soln_defaults.count_iso) - { - soln_defaults.iso = - (struct iso *) PHRQ_realloc(soln_defaults.iso, - (size_t) (i + - 1) * - sizeof(struct iso)); - if (soln_defaults.iso == NULL) - malloc_error(); - soln_defaults.iso[i].name = string_hsave(token); - soln_defaults.iso[i].value = NAN; - soln_defaults.iso[i].uncertainty = NAN; - soln_defaults.count_iso++; - } - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for default isotope ratio."); - error_msg(error_string, CONTINUE); - break; - } - sscanf(token, SCANFORMAT, &(soln_defaults.iso[i].value)); - /* read and store isotope ratio uncertainty */ - if ((j = copy_token(token, &next_char, &l)) != EMPTY) { + int j = copy_token(token, &next_char); if (j != DIGIT) { input_error++; error_string = sformatf( - "Expected numeric value for uncertainty in isotope ratio."); + "Expected numeric value for mass of water in solution."); error_msg(error_string, CONTINUE); - continue; } else { - sscanf(token, SCANFORMAT, - &(soln_defaults.iso[i].uncertainty)); + sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.water)); + } + } + break; + case 9: /* isotope */ + { + if (copy_token(token, &next_char) != DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" + " begin with an isotopic number."); + error_msg(error_string, CONTINUE); + continue; + } + int i; + for (i = 0; i < soln_defaults.count_iso; i++) + { + if (strcmp(token.c_str(), soln_defaults.iso[i].name) == 0) + { + break; + } + } + if (i == soln_defaults.count_iso) + { + soln_defaults.iso = + (struct iso *) PHRQ_realloc(soln_defaults.iso, + (size_t) (i + + 1) * + sizeof(struct iso)); + if (soln_defaults.iso == NULL) + malloc_error(); + soln_defaults.iso[i].name = string_hsave(token.c_str()); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } + /* read and store isotope ratio */ + if (copy_token(token, &next_char) != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for default isotope ratio."); + error_msg(error_string, CONTINUE); + break; + } + sscanf(token.c_str(), SCANFORMAT, &(soln_defaults.iso[i].value)); + /* read and store isotope ratio uncertainty */ + int j; + if ((j = copy_token(token, &next_char)) != EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, CONTINUE); + continue; + } + else + { + sscanf(token.c_str(), SCANFORMAT, + &(soln_defaults.iso[i].uncertainty)); + } } } break; @@ -442,12 +451,14 @@ read_solution_spread(void) break; case 100: /* read headings */ heading = string_to_spread_row(line); - for (i = 0; i < heading->count; i++) { - while (replace(" ", "", heading->char_vector[i]) == TRUE); - while (replace(",", "_", heading->char_vector[i]) == TRUE); + int i; + for (i = 0; i < heading->count; i++) + { + while (replace(" ", "", heading->char_vector[i]) == TRUE); + while (replace(",", "_", heading->char_vector[i]) == TRUE); + } } - break; } if (return_value == EOF || return_value == KEYWORD) @@ -466,24 +477,17 @@ read_solution_spread(void) soln_defaults.iso = (struct iso *) free_check_null(soln_defaults.iso); return (return_value); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: spread_row_to_solution(struct spread_row *heading, struct spread_row *units, struct spread_row *data, struct defaults defaults) /* ---------------------------------------------------------------------- */ { - int i, j, n, l; Keywords::KEYWORDS next_keyword_save; int n_user, n_user_end; - int default_pe, alk; - int count_isotopes; - int max_mass_balance, count_mass_balance; - char *ptr, *ptr1; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - char string[2 * MAX_LENGTH]; - LDBLE l_dummy; + std::string description; + std::string token, token1, string; + CParser parser(this->phrq_io); int return_value, opt; char *next_char; @@ -501,98 +505,89 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, "water", /* 10 */ "description", /* 11 */ "desc", /* 12 */ - "descriptor" /* 13 */ + "descriptor", /* 13 */ + "pressure" /* 14 */ }; - int count_opt_list = 14; + int count_opt_list = 15; /* * look for solution number */ - n_user = -1; - n_user_end = -1; - description = string_duplicate(""); - for (i = 0; i < heading->count; i++) + n_user = n_user_end = -1; { - if (strcmp_nocase(heading->char_vector[i], "number") == 0) + int i; + for (i = 0; i < heading->count; i++) { - break; + if (strcmp_nocase(heading->char_vector[i], "number") == 0) + { + break; + } } - } - if (i == heading->count || data->type_vector[i] == EMPTY - || data->count <= i) - { - n_user = -1; - } - else if (data->type_vector[i] == STRING) - { - input_error++; - error_string = sformatf( + if (i == heading->count || data->type_vector[i] == EMPTY + || data->count <= i) + { + n_user = -1; + } + else if (data->type_vector[i] == STRING) + { + input_error++; + error_string = sformatf( "Expected solution number or number range in 'number' column, found: %s.", data->char_vector[i]); - error_msg(error_string, CONTINUE); - } - else - { - strcpy(string, "solution_s "); - strcat(string, data->char_vector[i]); - ptr = string; - description = (char *) free_check_null(description); - next_keyword_save = next_keyword; - next_keyword = Keywords::KEY_SOLUTION_SPREAD; - read_number_description(ptr, &n_user, &n_user_end, &description); - next_keyword = next_keyword_save; + error_msg(error_string, CONTINUE); + } + else + { + string = "solution_s "; + string.append( data->char_vector[i] ); + next_keyword_save = next_keyword; + next_keyword = Keywords::KEY_SOLUTION_SPREAD; + cxxNumKeyword nk; + nk.read_number_description(string); + n_user = nk.Get_n_user(); + n_user_end = nk.Get_n_user_end(); + description = nk.Get_description(); + next_keyword = next_keyword_save; + } } /* * set up solution */ - - if (n_user >= 0 && solution_bsearch(n_user, &n, FALSE) != NULL) - { - solution_free(solution[n]); - } - else - { - n = count_solution++; - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - } - solution[n] = solution_alloc(); - - solution[n]->n_user = n_user; - solution[n]->n_user_end = n_user_end; + + cxxSolution temp_solution; + temp_solution.Set_n_user(n_user); + temp_solution.Set_n_user_end(n_user_end); + temp_solution.Set_new_def(true); + temp_solution.Create_initial_data(); + cxxISolution * initial_data_ptr = temp_solution.Get_initial_data(); if (use.Get_solution_in() == FALSE) { use.Set_solution_in(true); use.Set_n_solution_user(n_user); } - max_mass_balance = MAX_MASS_BALANCE; /* * Set default ph, temp, density, pe, units */ - solution[n]->description = description; - solution[n]->tc = defaults.temp; - solution[n]->patm = defaults.pressure; - solution[n]->ph = defaults.ph; - solution[n]->density = defaults.density; - solution[n]->solution_pe = defaults.pe; - solution[n]->mass_water = defaults.water; - solution[n]->ah2o = 1.0; - solution[n]->mu = 1e-7; - solution[n]->cb = 0.0; - default_pe = 0; - solution[n]->units = defaults.units; - solution[n]->totals[0].description = NULL; - count_mass_balance = 0; - count_isotopes = 0; - default_pe = pe_data_store(&(solution[n]->pe), defaults.redox); + temp_solution.Set_description(description); + temp_solution.Set_tc(defaults.temp); + temp_solution.Set_patm(defaults.pressure); + temp_solution.Set_ph(defaults.ph); + temp_solution.Set_density(defaults.density); + temp_solution.Set_pe(defaults.pe); + temp_solution.Set_mass_water(defaults.water); + temp_solution.Set_ah2o(1.0); + temp_solution.Set_mu(1e-7); + initial_data_ptr->Set_units(defaults.units); + initial_data_ptr->Set_default_pe(defaults.redox); + { + cxxChemRxn temp_chem_reaction; + initial_data_ptr->Get_pe_reactions()[defaults.redox] = temp_chem_reaction; + } /* * Read concentration data */ return_value = UNKNOWN; - for (i = 0; i < heading->count; i++) + for (int i = 0; i < heading->count; i++) { if (strcmp_nocase(heading->char_vector[i], "number") == 0) continue; @@ -608,27 +603,28 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, */ if (heading->type_vector[i] == EMPTY) continue; - strcpy(string, heading->char_vector[i]); - strcat(string, " "); + string = heading->char_vector[i]; + string.append(" "); /* * Copy in concentration data */ if (i >= data->count || data->type_vector[i] == EMPTY) continue; - strcat(string, data->char_vector[i]); - strcat(string, " "); + string.append(data->char_vector[i]); + string.append(" "); /* * Copy in concentration data */ if (units != NULL && i < units->count && units->type_vector[i] != EMPTY) { - strcat(string, units->char_vector[i]); + string.append(units->char_vector[i]); } /* * Parse string just like read_solution input */ - next_char = string; + char * char_string = string_duplicate(string.c_str()); + next_char = char_string; opt = get_option_string(opt_list, count_opt_list, &next_char); if (opt == OPTION_DEFAULT && heading->type_vector[i] == NUMBER) { @@ -649,21 +645,22 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; case 0: /* temperature */ case 1: - sscanf(next_char, SCANFORMAT, &(solution[n]->tc)); + sscanf(next_char, SCANFORMAT, &dummy); + temp_solution.Set_tc(dummy); break; case 2: /* density */ case 3: - sscanf(next_char, SCANFORMAT, &(solution[n]->density)); + sscanf(next_char, SCANFORMAT, &dummy); + temp_solution.Set_density(dummy); break; case 4: /* units */ case 8: /* unit */ - if (copy_token(token, &next_char, &l) == EMPTY) + if (copy_token(token, &next_char) == EMPTY) break; { - if (check_units(token, FALSE, FALSE, solution[n]->units, TRUE) == - OK) + if (check_units(token, false, false, initial_data_ptr->Get_units().c_str(), true) == OK) { - solution[n]->units = string_hsave(token); + initial_data_ptr->Set_units(token); } else { @@ -672,11 +669,13 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, } break; case 5: /* redox */ - if (copy_token(token, &next_char, &l) == EMPTY) + if (copy_token(token, &next_char) == EMPTY) break; - if (parse_couple(token) == OK) + if (parser.parse_couple(token) == OK) { - default_pe = pe_data_store(&(solution[n]->pe), token); + initial_data_ptr->Set_default_pe(token); + cxxChemRxn temp_chem_reaction; + initial_data_ptr->Get_pe_reactions()[token] = temp_chem_reaction; } else { @@ -684,229 +683,214 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, } break; case 6: /* ph */ - next_char = string; - if (read_conc(n, count_mass_balance, next_char) == ERROR) { - input_error++; - break; + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(char_string, &temp_solution) == CParser::PARSER_ERROR) + { + input_error++; + break; + } + + temp_solution.Set_ph(temp_comp.Get_input_conc()); + if (temp_comp.Get_equation_name().size() == 0) + { + break; + + } + temp_comp.Set_description("H(1)"); + initial_data_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; } - solution[n]->ph = - solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL) - { - break; - } - solution[n]->totals[count_mass_balance].description = - string_hsave("H(1)"); - count_mass_balance++; break; case 7: /* pe */ - next_char = string; - if (read_conc(n, count_mass_balance, next_char) == ERROR) { - input_error++; - break; + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(char_string, &temp_solution) == CParser::PARSER_ERROR) + { + input_error++; + break; + } + temp_solution.Set_pe(temp_comp.Get_input_conc()); + if (temp_comp.Get_equation_name().size() == 0) + { + break; + } + temp_comp.Set_description("E"); + initial_data_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; } - solution[n]->solution_pe = - solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL) - { - break; - } - solution[n]->totals[count_mass_balance].description = - string_hsave("E"); - count_mass_balance++; break; case 9: /* isotope */ - next_char = string; - if (copy_token(token, &next_char, &l) != DIGIT) { - input_error++; - error_string = sformatf( "Expected isotope name to" + next_char = char_string; + cxxSolutionIsotope temp_isotope; + if (copy_token(token, &next_char) != CParser::TT_DIGIT) + { + input_error++; + error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - solution[n]->isotopes = - (struct isotope *) PHRQ_realloc(solution[n]->isotopes, - (size_t) (count_isotopes + - 1) * - sizeof(struct isotope)); - if (solution[n]->isotopes == NULL) - malloc_error(); - /* read and save element name */ - ptr1 = token; - get_num(&ptr1, - &(solution[n]->isotopes[count_isotopes].isotope_number)); - if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) - { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return (ERROR); - } - solution[n]->isotopes[count_isotopes].elt_name = - string_hsave(ptr1); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + continue; + } + temp_isotope.Set_isotope_name(token.c_str()); - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, - &(solution[n]->isotopes[count_isotopes].ratio)); - - /* read and store isotope ratio uncertainty */ - /* first choice is next column */ - if ((i + 1) < heading->count && - (strcmp_nocase(heading->char_vector[i + 1], "uncertainty") == - 0 - || strcmp_nocase(heading->char_vector[i + 1], - "isotope_uncertainty") == 0 - || strcmp_nocase(heading->char_vector[i + 1], - "uncertainties") == 0) - && (i + 1) < data->count - && data->type_vector[i + 1] == NUMBER) - { - solution[n]->isotopes[count_isotopes].ratio_uncertainty = - data->d_vector[i + 1]; - } - else - { - next_char = string; - copy_token(token, &next_char, &l); - for (j = 0; j < defaults.count_iso; j++) + /* read and save element name */ { - if (strcmp(token, defaults.iso[j].name) == 0) + char *temp_iso_name = string_duplicate(token.c_str()); + char *ptr1 = temp_iso_name; + get_num(&ptr1, &dummy); + temp_isotope.Set_isotope_number(dummy); + if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) { - solution[n]->isotopes[count_isotopes]. - ratio_uncertainty = defaults.iso[j].uncertainty; - break; + error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + return (CParser::PARSER_ERROR); } + temp_isotope.Set_elt_name(ptr1); } - if (j == defaults.count_iso) + /* read and store isotope ratio */ + if (copy_token(token, &next_char) != CParser::TT_DIGIT) { - solution[n]->isotopes[count_isotopes].ratio_uncertainty = - NAN; + input_error++; + error_string = sformatf( + "Expected numeric value for isotope ratio."); + error_msg(error_string, CONTINUE); + continue; } + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_isotope.Set_ratio(dummy); + temp_isotope.Set_ratio_uncertainty(NAN); + + /* read and store isotope ratio uncertainty */ + int j; + if ((j = copy_token(token, &next_char)) != CParser::TT_EMPTY) + { + if (j != DIGIT) + { + input_error++; + error_string = sformatf( + "Expected numeric value for uncertainty in isotope ratio."); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + continue; + } + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_isotope.Set_ratio_uncertainty(dummy); + } + temp_solution.Get_isotopes()[temp_isotope.Get_isotope_name()] = temp_isotope; } - count_isotopes++; break; case 10: /* water */ - j = copy_token(token, &next_char, &l); - if (j == EMPTY) { - solution[n]->mass_water = 1.0; - } - else if (j != DIGIT) - { - input_error++; - error_string = sformatf( + next_char = char_string; + int j = copy_token(token, &next_char); + if (j == EMPTY) + { + temp_solution.Set_mass_water(1.0); + } + else if (j != DIGIT) + { + input_error++; + error_string = sformatf( "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } - else - { - sscanf(token, SCANFORMAT, &l_dummy); - solution[n]->mass_water = (LDBLE) l_dummy; + error_msg(error_string, CONTINUE); + } + else + { + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_solution.Set_mass_water(dummy); + } } break; case 11: /* description */ case 12: /* desc */ case 13: /* descriptor */ - solution[n]->description = - (char *) free_check_null(solution[n]->description); - solution[n]->description = string_duplicate(next_char); + { + temp_solution.Set_description(next_char); + } + break; + case 14: /* pressure */ + { + next_char = char_string; + if (sscanf(next_char, SCANFORMAT, &dummy) != 1) + { + temp_solution.Set_patm(1); + } + else + { + temp_solution.Set_patm(dummy); + } + } break; case OPTION_DEFAULT: /* * Read concentration */ - next_char = string; - if (copy_token(token, &next_char, &l) == LOWER) - continue; - next_char = string; - if (read_conc(n, count_mass_balance, next_char) == ERROR) { + next_char = char_string; + if (copy_token(token, &next_char) == LOWER) + continue; + cxxISolutionComp temp_comp(this->phrq_io); + if (temp_comp.read(char_string, &temp_solution) == CParser::PARSER_ERROR) + { #ifdef SKIP - input_error++; - break; + input_error++; + break; #endif + } + initial_data_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp; + if (temp_comp.Get_pe_reaction().size() > 0) + { + cxxChemRxn temp_chem_reaction; + initial_data_ptr->Get_pe_reactions()[temp_comp.Get_pe_reaction()] = temp_chem_reaction; + } } - count_mass_balance++; break; } - if (count_mass_balance + 1 >= max_mass_balance) - { - space((void **) ((void *) &(solution[n]->totals)), - count_mass_balance + 1, &max_mass_balance, - sizeof(struct conc)); - } + free_check_null(char_string); if (return_value == EOF || return_value == KEYWORD) break; } -/* - * Sort totals by description - */ - qsort(solution[n]->totals, - (size_t) count_mass_balance, - (size_t) sizeof(struct conc), conc_compare); /* * fix up default units and default pe */ - for (i = 0; i < count_mass_balance; i++) + std::map < std::string, cxxISolutionComp >::iterator it; + for (it = initial_data_ptr->Get_comps().begin(); it != initial_data_ptr->Get_comps().end(); it++) { - strcpy(token, solution[n]->totals[i].description); - str_tolower(token); - if (solution[n]->totals[i].units == NULL) + token = it->first; + Utilities::str_tolower(token); + if (it->second.Get_units().size() == 0) { - solution[n]->totals[i].units = solution[n]->units; + it->second.Set_units(initial_data_ptr->Get_units().c_str()); } else { - alk = FALSE; - if (strstr(token, "alk") == token) - alk = TRUE; - strcpy(token1, solution[n]->totals[i].units); - if (check_units(token1, alk, TRUE, solution[n]->units, TRUE) == - ERROR) + bool alk = false; + if (strstr(token.c_str(), "alk") == token.c_str()) + alk = true; + std::string token1 = it->second.Get_units(); + if (check_units(token1, alk, true, initial_data_ptr->Get_units().c_str(), true) == CParser::PARSER_ERROR) { input_error++; } else { - solution[n]->totals[i].units = string_hsave(token1); + it->second.Set_units(token1.c_str()); } } - if (solution[n]->totals[i].n_pe < 0) + if (it->second.Get_pe_reaction().size() == 0) { - solution[n]->totals[i].n_pe = default_pe; + it->second.Set_pe_reaction(initial_data_ptr->Get_default_pe()); } } - solution[n]->default_pe = default_pe; -/* - * Mark end of solution - */ - solution[n]->totals[count_mass_balance].description = NULL; - solution[n]->count_isotopes = count_isotopes; - if (count_isotopes > 0) + if (n_user >= 0) { - qsort(solution[n]->isotopes, - (size_t) count_isotopes, - (size_t) sizeof(struct isotope), isotope_compare); + Rxn_solution_map[n_user] = temp_solution; } else { - solution[n]->isotopes = - (struct isotope *) free_check_null(solution[n]->isotopes); + unnumbered_solutions.push_back(temp_solution); } return (return_value); } - /* ---------------------------------------------------------------------- */ struct spread_row * Phreeqc:: string_to_spread_row(char *string) diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 7cd79e8c..0dbb40a5 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -49,7 +49,7 @@ step(LDBLE step_fraction) */ if (use.Get_mix_ptr() != NULL) { - add_mix((cxxMix *) use.Get_mix_ptr()); + add_mix(use.Get_mix_ptr()); } else if (use.Get_solution_ptr() != NULL) { @@ -66,7 +66,6 @@ step(LDBLE step_fraction) */ if (use.Get_reaction_ptr() != NULL) { - //add_reaction(use.irrev_ptr, step_number, step_fraction); add_reaction( use.Get_reaction_ptr(), step_number, step_fraction); } /* @@ -81,7 +80,7 @@ step(LDBLE step_fraction) */ if (use.Get_exchange_ptr() != NULL) { - add_exchange((cxxExchange *) use.Get_exchange_ptr()); + add_exchange(use.Get_exchange_ptr()); } /* * Surface @@ -95,7 +94,7 @@ step(LDBLE step_fraction) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); add_gas_phase(gas_phase_ptr); } /* @@ -103,7 +102,7 @@ step(LDBLE step_fraction) */ if (use.Get_temperature_ptr() != NULL) { - cxxTemperature *t_ptr = (cxxTemperature *) use.Get_temperature_ptr(); + cxxTemperature *t_ptr = use.Get_temperature_ptr(); tc_x = t_ptr->Temperature_for_step(step_number); } if ((state == TRANSPORT) && (transport_step != 0) && @@ -118,7 +117,7 @@ step(LDBLE step_fraction) */ if (use.Get_pressure_ptr() != NULL) { - cxxPressure *p_ptr = (cxxPressure *) use.Get_pressure_ptr(); + cxxPressure *p_ptr = use.Get_pressure_ptr(); patm_x = p_ptr->Pressure_for_step(step_number); } /* @@ -130,7 +129,7 @@ step(LDBLE step_fraction) */ if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); add_pp_assemblage(pp_assemblage_ptr); } @@ -148,12 +147,12 @@ step(LDBLE step_fraction) */ if (use.Get_gas_phase_ptr() != NULL) { - cxxGasPhase * gas_phase_ptr = (cxxGasPhase *) use.Get_gas_phase_ptr(); + cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); gas_phase_check(gas_phase_ptr); } if (use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = (cxxPPassemblage *) use.Get_pp_assemblage_ptr(); + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); pp_assemblage_check(pp_assemblage_ptr); } if (use.Get_ss_assemblage_ptr() != NULL) @@ -189,19 +188,9 @@ step(LDBLE step_fraction) */ if (pp_assemblage_save != NULL) { - //pp_assemblage_free(pp_assemblage_save); - //pp_assemblage_save = - // (struct pp_assemblage *) free_check_null(pp_assemblage_save); delete pp_assemblage_save; pp_assemblage_save = NULL; } - //if (ss_assemblage_save != NULL) - //{ - // ss_assemblage_free(ss_assemblage_save); - // ss_assemblage_save = - // (struct ss_assemblage *) free_check_null(ss_assemblage_save); - //} - // // Solution -1 has sum of solution/mix, exchange, surface, gas_phase // reaction, kinetics @@ -210,10 +199,8 @@ step(LDBLE step_fraction) if (use.Get_pp_assemblage_in() || use.Get_ss_assemblage_in()) { cxxStorageBin sys_bin(phrq_io); - //cxxSolution soln(PHREEQC_THIS_COMMA -1, phrq_io); - int n; - struct solution *sol = solution_bsearch(-1, &n, false); - cxxSolution soln(sol, phrq_io); + cxxSolution *sol = Utilities::Rxn_find(Rxn_solution_map, -1); + cxxSolution soln(*sol); sys_bin.Set_Solution(-1, soln); if (use.Get_pp_assemblage_in()) { @@ -255,7 +242,6 @@ step(LDBLE step_fraction) cxxSSassemblage *ss_assemblage_ptr = sys_bin.Get_SSassemblage(-1); std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); for (size_t j = 0; j < ss_ptrs.size(); j++) - //for (it = ss->Get_ssAssemblageSSs().begin(); it != ss->Get_ssAssemblageSSs().end(); it++) { cxxSS * ss_ptr = ss_ptrs[j]; for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) @@ -307,7 +293,7 @@ xsolution_zero(void) ph_x = 0.0; solution_pe_x = 0.0; mu_x = 0.0; - ah2o_x = 0.0; + ah2o_x = 1.0; density_x = 0.0; total_h_x = 0.0; total_o_x = 0.0; @@ -337,10 +323,9 @@ xsolution_zero(void) */ return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: -add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) +add_solution(cxxSolution *solution_ptr, LDBLE extensive, LDBLE intensive) /* ---------------------------------------------------------------------- */ { /* @@ -349,49 +334,43 @@ add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) * extensive is multiplication factor for solution * intensive is fraction of all multiplication factors for all solutions */ - int i; struct master *master_ptr; struct species *species_ptr; /* * Add solution to global variables */ - tc_x += solution_ptr->tc * intensive; - ph_x += solution_ptr->ph * intensive; - patm_x += solution_ptr->patm * intensive; - // - //k_temp(tc_x, patm_x); - solution_pe_x += solution_ptr->solution_pe * intensive; - mu_x += solution_ptr->mu * intensive; - ah2o_x += solution_ptr->ah2o * intensive; - density_x += solution_ptr->density * intensive; + tc_x += solution_ptr->Get_tc() * intensive; + ph_x += solution_ptr->Get_ph() * intensive; + patm_x += solution_ptr->Get_patm() * intensive; + solution_pe_x += solution_ptr->Get_pe() * intensive; + mu_x += solution_ptr->Get_mu() * intensive; + ah2o_x += solution_ptr->Get_ah2o() * intensive; + density_x += solution_ptr->Get_density() * intensive; - total_h_x += solution_ptr->total_h * extensive; - total_o_x += solution_ptr->total_o * extensive; - cb_x += solution_ptr->cb * extensive; - mass_water_aq_x += solution_ptr->mass_water * extensive; + total_h_x += solution_ptr->Get_total_h() * extensive; + total_o_x += solution_ptr->Get_total_o() * extensive; + cb_x += solution_ptr->Get_cb() * extensive; + mass_water_aq_x += solution_ptr->Get_mass_water() * extensive; /* * Copy totals data into primary master species */ - for (i = 0; solution_ptr->totals[i].description != NULL; i++) + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) { - master_ptr = - master_bsearch_primary(solution_ptr->totals[i].description); - master_ptr->total += solution_ptr->totals[i].moles * extensive; + master_ptr = master_bsearch_primary(jit->first.c_str()); + master_ptr->total += jit->second * extensive; } /* * Accumulate initial guesses for activities */ - /*for (i=0; solution_ptr->master_activity[i].description != NULL; i++) { */ - for (i = 0; i < solution_ptr->count_master_activity; i++) + jit = solution_ptr->Get_master_activity().begin(); + for ( ; jit != solution_ptr->Get_master_activity().end(); jit++) { - if (solution_ptr->master_activity[i].description != NULL) { - master_ptr = - master_bsearch(solution_ptr->master_activity[i].description); + master_ptr = master_bsearch(jit->first.c_str()); if (master_ptr != NULL) { - master_ptr->s->la += - solution_ptr->master_activity[i].la * intensive; + master_ptr->s->la += jit->second * intensive; } } } @@ -400,14 +379,13 @@ add_solution(struct solution *solution_ptr, LDBLE extensive, LDBLE intensive) */ if (pitzer_model == TRUE || sit_model == TRUE) { - for (i = 0; i < solution_ptr->count_species_gamma; i++) + jit = solution_ptr->Get_species_gamma().begin(); + for ( ; jit != solution_ptr->Get_species_gamma().end(); jit++) { - species_ptr = - s_search(solution_ptr->species_gamma[i].description); + species_ptr = s_search(jit->first.c_str()); if (species_ptr != NULL) { - species_ptr->lg += - solution_ptr->species_gamma[i].la * intensive; + species_ptr->lg += jit->second * intensive; } } } @@ -428,13 +406,11 @@ add_exchange(cxxExchange *exchange_ptr) /* * Add element concentrations on exchanger to master species totals */ - std::vector comps = exchange_ptr->Vectorize(); - for (size_t i = 0; i < comps.size(); i++) + for (size_t i = 0; i < exchange_ptr->Get_exchange_comps().size(); i++) { - cxxExchComp *comp_ptr = comps[i]; - cxxNameDouble nd(comp_ptr->Get_totals()); + cxxExchComp comp_ref = exchange_ptr->Get_exchange_comps()[i]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); - //for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) for ( ; it != nd.end(); it++) { struct element *elt_ptr = element_store(it->first.c_str()); @@ -467,51 +443,48 @@ add_exchange(cxxExchange *exchange_ptr) } else { - for (size_t i = 0; i < comps.size(); i++) + for (size_t i = 0; i < exchange_ptr->Get_exchange_comps().size(); i++) { - cxxExchComp *comp_ptr = comps[i]; - cxxNameDouble nd(comp_ptr->Get_totals()); + cxxExchComp &comp_ref = exchange_ptr->Get_exchange_comps()[i]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); - //for (j = 0; exchange_ptr->comps[i].totals[j].elt != NULL; j++) for ( ; it != nd.end(); it++) { struct element *elt_ptr = element_store(it->first.c_str()); assert(elt_ptr->master); if (elt_ptr->master->type == EX) { - elt_ptr->master->s->la = comps[i]->Get_la(); + elt_ptr->master->s->la = comp_ref.Get_la(); } } - - //exchange_ptr->comps[i].master->s->la = exchange_ptr->comps[i].la; - cb_x += comps[i]->Get_charge_balance(); + cb_x += comp_ref.Get_charge_balance(); } } return (OK); } /* ---------------------------------------------------------------------- */ int Phreeqc:: -add_surface(struct surface *surface_ptr) +add_surface(cxxSurface *surface_ptr) /* ---------------------------------------------------------------------- */ { /* * Accumulate surface data in master->totals and _x variables. */ - int i, j; - struct master *master_ptr; - if (surface_ptr == NULL) return (OK); /* * Add element concentrations on surface to master species totals */ - dl_type_x = surface_ptr->dl_type; - for (i = 0; i < surface_ptr->count_comps; i++) + dl_type_x = surface_ptr->Get_dl_type(); + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { - /*if(surface_ptr->edl == FALSE) { */ - if (surface_ptr->type == NO_EDL) + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); + struct element *elt_ptr = element_store(comp_ptr->Get_master_element().c_str()); + struct master *master_i_ptr = elt_ptr->master; + + if (surface_ptr->Get_type() == cxxSurface::NO_EDL) { - cb_x += surface_ptr->comps[i].cb; + cb_x += comp_ptr->Get_charge_balance(); } #ifdef SKIP_MUSIC if (surface_ptr->type == CD_MUSIC) @@ -519,81 +492,76 @@ add_surface(struct surface *surface_ptr) cb_x += surface_ptr->comps[i].cb; } #endif - if (surface_ptr->new_def == FALSE) + if (!surface_ptr->Get_new_def()) { - surface_ptr->comps[i].master->s->la = surface_ptr->comps[i].la; + master_i_ptr->s->la = comp_ptr->Get_la(); } /* * Add surface and specifically sorbed elements */ - for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) + cxxNameDouble::iterator jit; + for (jit = comp_ptr->Get_totals().begin(); jit != comp_ptr->Get_totals().end(); jit++) { - master_ptr = surface_ptr->comps[i].totals[j].elt->primary; - if (master_ptr == NULL) + LDBLE coef = jit->second; + struct element *elt_j_ptr = element_store(jit->first.c_str()); + struct master *master_j_ptr = elt_j_ptr->primary; + if (master_j_ptr == NULL) { input_error++; error_string = sformatf( "Element not defined in database, %s.", - surface_ptr->comps[i].totals[j].elt->name); + elt_j_ptr->name); error_msg(error_string, STOP); } - if (master_ptr->s == s_hplus) + if (master_j_ptr->s == s_hplus) { - total_h_x += surface_ptr->comps[i].totals[j].coef; + total_h_x += coef; } - else if (master_ptr->s == s_h2o) + else if (master_j_ptr->s == s_h2o) { - total_o_x += surface_ptr->comps[i].totals[j].coef; + total_o_x += coef; } else { - master_ptr->total += surface_ptr->comps[i].totals[j].coef; + master_j_ptr->total += coef; } } } - /*if (surface_ptr->edl == FALSE) return(OK); */ - if (surface_ptr->type != DDL && surface_ptr->type != CD_MUSIC) + if (surface_ptr->Get_type() != cxxSurface::DDL && surface_ptr->Get_type() != cxxSurface::CD_MUSIC) return (OK); - for (i = 0; i < surface_ptr->count_charge; i++) + for (size_t i = 0; i < surface_ptr->Get_surface_charges().size(); i++) { - /*if (surface_ptr->edl == TRUE) { */ - /*cb_x += surface_ptr->charge[i].charge_balance; */ - if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) + cxxSurfaceCharge *charge_ptr = &(surface_ptr->Get_surface_charges()[i]); + if (surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) { - cb_x += surface_ptr->charge[i].charge_balance; + cb_x += charge_ptr->Get_charge_balance(); } - if (surface_ptr->new_def == FALSE) + if (!surface_ptr->Get_new_def()) { - master_ptr = - surface_get_psi_master(surface_ptr->charge[i].name, SURF_PSI); - master_ptr->s->la = surface_ptr->charge[i].la_psi; - /*surface_ptr->charge[i].psi_master->s->la = surface_ptr->charge[i].la_psi; */ + struct master *master_ptr = surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI); + master_ptr->s->la = charge_ptr->Get_la_psi(); } /* * Add diffuse layer elements (including water in Debye layer) */ - if (surface_ptr->dl_type != NO_DL && surface_ptr->new_def == FALSE) + if (surface_ptr->Get_dl_type() != cxxSurface::NO_DL && !surface_ptr->Get_new_def()) { - for (j = 0; - surface_ptr->charge[i].diffuse_layer_totals[j].elt != NULL; - j++) + cxxNameDouble::const_iterator jit; + for (jit = charge_ptr->Get_diffuse_layer_totals().begin(); jit != charge_ptr->Get_diffuse_layer_totals().end(); jit++) { - master_ptr = - surface_ptr->charge[i].diffuse_layer_totals[j].elt-> - primary; - if (master_ptr->s == s_hplus) + LDBLE coef = jit->second; + struct element *elt_j_ptr = element_store(jit->first.c_str()); + struct master * master_j_ptr = elt_j_ptr->master; + if (master_j_ptr->s == s_hplus) { - total_h_x += - surface_ptr->charge[i].diffuse_layer_totals[j].coef; + total_h_x += coef; } - else if (master_ptr->s == s_h2o) + else if (master_j_ptr->s == s_h2o) { - total_o_x += - surface_ptr->charge[i].diffuse_layer_totals[j].coef; + total_o_x += coef; } else { - master_ptr->total += - surface_ptr->charge[i].diffuse_layer_totals[j].coef; + master_j_ptr->total += coef; } } } @@ -609,9 +577,8 @@ add_mix(cxxMix *mix_ptr) * calls add_solution to accumulate all data in master->totals * and other variables. */ - int n; LDBLE sum_fractions, intensive, extensive; - struct solution *solution_ptr; + cxxSolution *solution_ptr; int count_positive; LDBLE sum_positive; @@ -634,7 +601,7 @@ add_mix(cxxMix *mix_ptr) } for (it = mix_ptr->Get_mixComps().begin(); it != mix_ptr->Get_mixComps().end(); it++) { - solution_ptr = solution_bsearch(it->first, &n, TRUE); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, it->first); if (solution_ptr == NULL) { input_error++; @@ -670,28 +637,7 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr) LDBLE amount_to_add, total; char token[MAX_LENGTH]; char *ptr; - //struct pure_phase *pure_phase_ptr; struct master *master_ptr; - //struct phase *phase_ptr; - //LDBLE p, t; - - //pure_phase_ptr = pp_assemblage_ptr->pure_phases; - - // Should be be done when it gets to prep (modified quick_setup in case same_model). - //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) - //{ - // phase_ptr = pure_phase_ptr[j].phase; - // if (/*pure_phase_ptr[j].si_org > 0 && */phase_ptr->p_c > 0 && phase_ptr->t_c > 0) - // { - // p = exp(pure_phase_ptr[j].si_org * LOG_10); - // t = tc_x + 273.15; - // if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) - // { - // calc_PR(&phase_ptr, 1, p, t, 0); - // } - // pure_phase_ptr[j].si = pure_phase_ptr[j].si_org + phase_ptr->pr_si_f; - // } - //} if (check_pp_assemblage(pp_assemblage_ptr) == OK) return (OK); @@ -842,7 +788,6 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) */ if (incremental_reactions == FALSE) { - //if (irrev_ptr->count_steps > 0) if (!reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0 ) { if (step_number > (int) reaction_ptr->Get_steps().size()) @@ -905,7 +850,6 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) /* * Convert units */ - //c = irrev_ptr->units[0]; c = reaction_ptr->Get_units().c_str()[0]; if (c == 'm') { @@ -922,7 +866,6 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) /* * Add reaction to totals */ - //for (i = 0; irrev_ptr->elts[i].elt != NULL; i++) cxxNameDouble::const_iterator it = reaction_ptr->Get_elementList().begin(); for ( ; it != reaction_ptr->Get_elementList().end(); it++) { @@ -962,10 +905,8 @@ reaction_calc(cxxReaction *reaction_ptr) * determine a list of elements and amounts in * the reaction. */ - //int i, j, int return_value; LDBLE coef; - //char token[MAX_LENGTH]; char *ptr; struct phase *phase_ptr; /* @@ -992,7 +933,6 @@ reaction_calc(cxxReaction *reaction_ptr) } else { - //ptr = &(token[0]); char * token = string_duplicate(it->first.c_str()); ptr = token; get_elts_in_species(&ptr, coef); @@ -1014,7 +954,6 @@ reaction_calc(cxxReaction *reaction_ptr) return_value = ERROR; } } - //irrev_ptr->elts = elt_list_save(); reaction_ptr->Set_elementList(elt_list_NameDouble()); return (return_value); @@ -1028,19 +967,15 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) * Accumulate gas data in master->totals and _x variables. */ int i; - - //struct gas_comp *gas_comp_ptr; struct master *master_ptr; if (gas_phase_ptr == NULL) return (OK); - //gas_comp_ptr = gas_phase_ptr->comps; /* * calculate reaction */ count_elts = 0; paren_count = 0; - //for (i = 0; i < gas_phase_ptr->count_comps; i++) for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); @@ -1096,9 +1031,7 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) */ int i, j, k; LDBLE amount_to_add, total; - //struct s_s *s_s_ptr; struct master *master_ptr; - //char token[MAX_LENGTH]; char *ptr; if (ss_assemblage_ptr == NULL) @@ -1124,7 +1057,6 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr) comp_ptr->Set_delta(0.0); if (comp_ptr->Get_moles() > 0.0) { - //strcpy(token, s_s_ptr->comps[j].phase->formula); char * token = string_duplicate(phase_ptr->formula); ptr = &(token[0]); get_elts_in_species(&ptr, 1.0); @@ -1195,7 +1127,6 @@ add_kinetics(cxxKinetics *kinetics_ptr) /* * Add kinetic reaction */ - //int i; struct master *master_ptr = NULL; /* * Add reaction to totals @@ -1230,49 +1161,6 @@ add_kinetics(cxxKinetics *kinetics_ptr) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -add_kinetics(struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Add kinetic reaction - */ - int i; - struct master *master_ptr; -/* - * Add reaction to totals - */ - if (kinetics_ptr->totals == NULL) - return (OK); - for (i = 0; kinetics_ptr->totals[i].elt != NULL; i++) - { - master_ptr = kinetics_ptr->totals[i].elt->primary; - if (master_ptr == NULL) - { - input_error++; - error_string = sformatf( - "Element %s in kinetic reaction not found in database.", - kinetics_ptr->totals[i].elt->name); - error_msg(error_string, STOP); - } - if (master_ptr->s == s_hplus) - { - total_h_x += kinetics_ptr->totals[i].coef; - } - else if (master_ptr->s == s_h2o) - { - total_o_x += kinetics_ptr->totals[i].coef; - } - else - { - master_ptr->total += kinetics_ptr->totals[i].coef; - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: gas_phase_check(cxxGasPhase *gas_phase_ptr) @@ -1281,19 +1169,14 @@ gas_phase_check(cxxGasPhase *gas_phase_ptr) /* * Check for missing elements */ - //int i, j; - - //struct gas_comp *gas_comp_ptr; struct master *master_ptr; if (gas_phase_ptr == NULL) return (OK); - //gas_comp_ptr = gas_phase_ptr->comps; /* * Check that all elements are in solution for phases with zero mass */ for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) - //for (i = 0; i < gas_phase_ptr->count_comps; i++) { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); int k; @@ -1343,11 +1226,8 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr) /* * Check for missing elements */ - //int i, j, k; - //char token[MAX_LENGTH]; std::string token; char *ptr; - //struct pure_phase *pure_phase_ptr; struct master *master_ptr; if (check_pp_assemblage(pp_assemblage_ptr) == OK) @@ -1376,7 +1256,6 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr) else { token = phase_ptr->formula; - //strcpy(token, pure_phase_ptr[j].phase->formula); add_elt_list(phase_ptr->next_elt, 1.0); } for (int i = 0; i < count_elts; i++) diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index c92b7918..6b331f55 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -12,6 +12,9 @@ #include "Use.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Surface.h" +#include "Solution.h" + /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -27,7 +30,7 @@ clean_up(void) #endif description_x = (char *) free_check_null(description_x); - isotopes_x = (struct isotope *) free_check_null(isotopes_x); + isotopes_x.clear(); moles_per_kilogram_string = (char *) free_check_null(moles_per_kilogram_string); pe_string = (char *) free_check_null(pe_string); @@ -77,20 +80,10 @@ clean_up(void) elements = (struct element **) free_check_null(elements); /* solutions */ - - for (j = 0; j < count_solution; j++) - { - solution_free(solution[j]); - } - solution = (struct solution **) free_check_null(solution); + Rxn_solution_map.clear(); /* surfaces */ - - for (j = 0; j < count_surface; j++) - { - surface_free(&surface[j]); - } - surface = (struct surface *) free_check_null(surface); + Rxn_surface_map.clear(); /* exchange */ Rxn_exchange_map.clear(); @@ -142,13 +135,6 @@ clean_up(void) /* kinetics */ Rxn_kinetics_map.clear(); -#ifdef SKIP - for (j = 0; j < count_kinetics; j++) - { - kinetics_free(&kinetics[j]); - } - kinetics = (struct kinetics *) free_check_null(kinetics); -#endif /* rates */ for (j = 0; j < count_rates; j++) @@ -177,8 +163,7 @@ clean_up(void) /* global solution */ - pe_data_free(pe_x); - pe_x = NULL; + pe_x.clear(); /* species_list */ @@ -243,10 +228,6 @@ clean_up(void) rate_free(user_graph); user_graph = (struct rate *) free_check_null(user_graph); user_graph_headings = (char **) free_check_null(user_graph_headings); -#ifndef PHREEQ98 - //if (u_g) - // DeleteCurves(); -#endif #endif /* master_isotope */ for (i = 0; i < count_master_isotope; i++) @@ -314,7 +295,11 @@ clean_up(void) phases_hash_table = NULL; /* strings */ +#ifdef HASH + strings_hash_clear(); +#else strings_map_clear(); +#endif /* delete basic interpreter */ basic_free(); @@ -361,23 +346,12 @@ clean_up(void) MergeFinalize(); #endif - count_solution = 0; - //count_pp_assemblage = 0; - //count_exchange = 0; - count_surface = 0; - //count_gas_phase = 0; - //count_kinetics = 0; - //count_ss_assemblage = 0; - count_elements = 0; - //count_irrev = 0; count_master = 0; - //count_mix = 0; count_phases = 0; count_s = 0; count_logk = 0; count_master_isotope = 0; - count_rates = 0; count_inverse = 0; count_save_values = 0; @@ -399,21 +373,11 @@ int Phreeqc:: reinitialize(void) /* ---------------------------------------------------------------------- */ { - int j; /* solutions */ - for (j = 0; j < count_solution; j++) - { - solution_free(solution[j]); - } - count_solution = 0; + Rxn_solution_map.clear(); /* surfaces */ - - for (j = 0; j < count_surface; j++) - { - surface_free(&surface[j]); - } - count_surface = 0; + Rxn_surface_map.clear(); /* exchange */ Rxn_exchange_map.clear(); @@ -429,13 +393,7 @@ reinitialize(void) /* kinetics */ Rxn_kinetics_map.clear(); -#ifdef SKIP - for (j = 0; j < count_kinetics; j++) - { - kinetics_free(&kinetics[j]); - } - count_kinetics = 0; -#endif + /* irreversible reactions */ Rxn_reaction_map.clear(); @@ -976,529 +934,7 @@ inverse_sort(void) } return (OK); } -#ifdef SKIP -/* ********************************************************************** - * - * Routines related to structure "kinetics" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct kinetics * Phreeqc:: -kinetics_alloc(void) -/* ---------------------------------------------------------------------- */ -{ - struct kinetics *kinetics_ptr; - kinetics_ptr = (struct kinetics *) PHRQ_malloc(sizeof(struct kinetics)); - if (kinetics_ptr == NULL) - malloc_error(); - kinetics_ptr->n_user = -1; - kinetics_ptr->n_user_end = -1; - kinetics_ptr->description = NULL; - kinetics_ptr->count_comps = 0; - kinetics_ptr->comps = NULL; - kinetics_ptr->count_steps = 0; - kinetics_ptr->steps = NULL; - kinetics_ptr->totals = NULL; - kinetics_ptr->rk = 0; - kinetics_ptr->bad_step_max = 0; - kinetics_ptr->use_cvode = FALSE; - return (kinetics_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct kinetics * Phreeqc:: -kinetics_bsearch(int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search kinetics to find if user kinetics number k exists. - * Kinetics is assumed to be in sort order by user number. - */ - void *void_ptr; - if (count_kinetics == 0) - { - *n = -999; - return (NULL); - } - void_ptr = (void *) - bsearch((char *) &k, - (char *) kinetics, - (size_t) count_kinetics, - (size_t) sizeof(struct kinetics), kinetics_compare_int); - if (void_ptr == NULL) - { - *n = -999; - return (NULL); - } - *n = (int) ((struct kinetics *) void_ptr - kinetics); - return ((struct kinetics *) void_ptr); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct kinetics *kinetics_ptr1, *kinetics_ptr2; - kinetics_ptr1 = (const struct kinetics *) ptr1; - kinetics_ptr2 = (const struct kinetics *) ptr2; - if (kinetics_ptr1->n_user > kinetics_ptr2->n_user) - return (1); - if (kinetics_ptr1->n_user < kinetics_ptr2->n_user) - return (-1); - return (0); - -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -kinetics_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare kinetics user numbers - */ - const int *nptr1; - const struct kinetics *nptr2; - - nptr1 = (const int *) ptr1; - nptr2 = (const struct kinetics *) ptr2; - if (*nptr1 > nptr2->n_user) - return (1); - if (*nptr1 < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_copy(struct kinetics *kinetics_old_ptr, - struct kinetics *kinetics_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies kinetics data from kinetics_old_ptr to new location, kinetics_new_ptr. - * Space for the kinetics_new_ptr structure must already be malloced. - * Space for kinetics components is malloced here. - */ - char token[MAX_LENGTH]; - int count_steps, i; -/* - * copy old to new - */ - memcpy(kinetics_new_ptr, kinetics_old_ptr, sizeof(struct kinetics)); -/* - * Store data for structure kinetics - */ - kinetics_new_ptr->n_user = n_user_new; - kinetics_new_ptr->n_user_end = n_user_new; - sprintf(token, "Kinetics defined in simulation %d.", simulation); - kinetics_new_ptr->description = string_duplicate(token); - kinetics_new_ptr->totals = NULL; - kinetics_new_ptr->totals = elt_list_dup(kinetics_old_ptr->totals); -/* - * Copy time steps - */ - if (kinetics_new_ptr->count_steps > 0) - { - count_steps = kinetics_new_ptr->count_steps; - } - else if (kinetics_new_ptr->count_steps < 0) - { - count_steps = 1; - } - else - { - count_steps = 0; - } - if (count_steps > 0) - { - kinetics_new_ptr->steps = - (LDBLE *) PHRQ_malloc((size_t) (count_steps * sizeof(LDBLE))); - if (kinetics_new_ptr->steps == NULL) - malloc_error(); - memcpy(kinetics_new_ptr->steps, kinetics_old_ptr->steps, - (size_t) count_steps * sizeof(LDBLE)); - } -/* - * Copy kinetic components - */ - if (kinetics_new_ptr->count_comps > 0) - { - kinetics_new_ptr->comps = - (struct kinetics_comp *) PHRQ_malloc((size_t) kinetics_old_ptr-> - count_comps * - sizeof(struct - kinetics_comp)); - if (kinetics_new_ptr->comps == NULL) - malloc_error(); - } - else - { - kinetics_new_ptr->comps = NULL; - } - for (i = 0; i < kinetics_old_ptr->count_comps; i++) - { - kinetics_comp_duplicate(&kinetics_new_ptr->comps[i], - &kinetics_old_ptr->comps[i]); - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_comp_duplicate(struct kinetics_comp *kinetics_comp_new_ptr, - struct kinetics_comp *kinetics_comp_old_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies kinetics comp data from kinetics_comp_old_ptr to new location - * Space for the new structure must already be allocated - */ - memcpy(kinetics_comp_new_ptr, kinetics_comp_old_ptr, - sizeof(struct kinetics_comp)); -/* - * Kinetics character parameters - */ - if (kinetics_comp_new_ptr->count_c_params > 0) - { - kinetics_comp_new_ptr->c_params = - (const char **) - PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_c_params) * - sizeof(char *)); - if (kinetics_comp_new_ptr->c_params == NULL) - malloc_error(); - memcpy(kinetics_comp_new_ptr->c_params, - kinetics_comp_old_ptr->c_params, - (size_t) (kinetics_comp_old_ptr->count_c_params) * - sizeof(char *)); - } - else - { - kinetics_comp_new_ptr->c_params = NULL; - } -/* - * Kinetics LDBLE parameters - */ - if (kinetics_comp_new_ptr->count_d_params > 0) - { - kinetics_comp_new_ptr->d_params = - (LDBLE *) - PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_d_params) * - sizeof(LDBLE)); - if (kinetics_comp_new_ptr->d_params == NULL) - malloc_error(); - memcpy(kinetics_comp_new_ptr->d_params, - kinetics_comp_old_ptr->d_params, - (size_t) (kinetics_comp_old_ptr->count_d_params) * - sizeof(LDBLE)); - } - else - { - kinetics_comp_new_ptr->d_params = - (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); - } -/* - * Kinetics list of formulae - */ - if (kinetics_comp_new_ptr->count_list > 0) - { - kinetics_comp_new_ptr->list = - (struct name_coef *) - PHRQ_malloc((size_t) (kinetics_comp_old_ptr->count_list) * - sizeof(struct name_coef)); - if (kinetics_comp_new_ptr->list == NULL) - malloc_error(); - memcpy(kinetics_comp_new_ptr->list, kinetics_comp_old_ptr->list, - (size_t) (kinetics_comp_old_ptr->count_list) * - sizeof(struct name_coef)); - } - else - { - kinetics_comp_new_ptr->d_params = NULL; - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an kinetics definition from position n to position count_kinetics. - * New kinetics structure is given user number n_user. - */ - space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, - sizeof(struct kinetics)); - kinetics_copy(&kinetics[n], &kinetics[count_kinetics], n_user); - count_kinetics++; - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array kinetics. - */ -{ - int i; - int n_old; - struct kinetics *kinetics_ptr_old; -/* - * Find n_user_old in structure array - */ - kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); - if (kinetics_ptr_old != NULL) - { - /* - * Delete kinetics - */ - kinetics_free(&kinetics[n_old]); - - for (i = n_old + 1; i < count_kinetics; i++) - { - memcpy((void *) &kinetics[i - 1], (void *) &kinetics[i], - (size_t) sizeof(struct kinetics)); - } - count_kinetics--; - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies kinetics[n_user_old] to old n_user_new space if - * found or to kinetics[count_kinetics] if not found. - * Kinetics array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct kinetics *kinetics_ptr_old, *kinetics_ptr_new; -/* - * Find n_user_old in structure array kinetics - */ - if (n_user_old == n_user_new) - return (OK); - kinetics_ptr_old = kinetics_bsearch(n_user_old, &n_old); - if (kinetics_ptr_old == NULL) - { - error_string = sformatf( "Kinetics %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array kinetics or make new space - */ - sort = FALSE; - kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); - if (kinetics_ptr_new != NULL) - { - kinetics_free(kinetics_ptr_new); - } - else - { - space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, - sizeof(struct kinetics)); - if (n_user_new < kinetics[count_kinetics - 1].n_user) - sort = TRUE; - n_new = count_kinetics++; - } -/* - * Copy data - */ - kinetics_copy(&kinetics[n_old], &kinetics[n_new], n_user_new); - if (sort == TRUE) - kinetics_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_free(struct kinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ - int i; -/* - * Frees all data associated with kinetics structure. - */ - if (kinetics_ptr == NULL) - return (ERROR); -/* - * Free space allocated for kinetics structure - */ - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - kinetics_ptr->comps[i].c_params = - (const char **) free_check_null(kinetics_ptr->comps[i].c_params); - kinetics_ptr->comps[i].d_params = - (LDBLE *) free_check_null(kinetics_ptr->comps[i].d_params); - kinetics_ptr->comps[i].list = - (struct name_coef *) free_check_null(kinetics_ptr->comps[i].list); - } - kinetics_ptr->description = - (char *) free_check_null(kinetics_ptr->description); - kinetics_ptr->steps = (LDBLE *) free_check_null(kinetics_ptr->steps); - kinetics_ptr->comps = - (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); - kinetics_ptr->totals = - (struct elt_list *) free_check_null(kinetics_ptr->totals); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_init(struct kinetics *kinetics_ptr, int n_user, int n_user_end, - char *description) -/* ---------------------------------------------------------------------- */ -{ - if (kinetics_ptr == NULL) - return (ERROR); - kinetics_ptr->n_user = n_user; - kinetics_ptr->n_user_end = n_user_end; - kinetics_ptr->description = string_duplicate(description); - kinetics_ptr->count_comps = 0; - kinetics_ptr->comps = - (struct kinetics_comp *) PHRQ_malloc((size_t) - sizeof(struct kinetics_comp)); - if (kinetics_ptr->comps == NULL) - malloc_error(); - kinetics_ptr->count_steps = 0; - kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); - if (kinetics_ptr->steps == NULL) - malloc_error(); - kinetics_ptr->step_divide = 1.0; - /*kinetics_ptr->units = string_hsave("sec"); */ - kinetics_ptr->totals = NULL; - kinetics_ptr->rk = 3; - kinetics_ptr->bad_step_max = 500; - kinetics_ptr->use_cvode = FALSE; - kinetics_ptr->cvode_order = 5; - kinetics_ptr->cvode_steps = 100; - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_ptr_to_user(struct kinetics *kinetics_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies kinetics_ptr_old to old n_user_new space if - * found or to kinetics[count_kinetics] if not found. - * Kinetics array may not be in sort order after the copy. - */ - int n_new, sort; - struct kinetics *kinetics_ptr_new; -/* - * Find n_user_old in structure array kinetics - */ - if (kinetics_ptr_old == NULL) - { - error_string = sformatf( "Kinetics pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array kinetics or make new space - */ - sort = FALSE; - kinetics_ptr_new = kinetics_bsearch(n_user_new, &n_new); - if (kinetics_ptr_new == kinetics_ptr_old) - return (OK); - if (kinetics_ptr_new != NULL) - { - kinetics_free(kinetics_ptr_new); - } - else - { - space((void **) ((void *) &kinetics), count_kinetics, &max_kinetics, - sizeof(struct kinetics)); - if (n_user_new < kinetics[count_kinetics - 1].n_user) - sort = TRUE; - n_new = count_kinetics++; - } -/* - * Copy data - */ - kinetics_copy(kinetics_ptr_old, &kinetics[n_new], n_user_new); - if (sort == TRUE) - kinetics_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct kinetics * Phreeqc:: -kinetics_replicate(struct kinetics *kinetics_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct kinetics *kinetics_ptr; - kinetics_ptr = kinetics_alloc(); - kinetics_copy(kinetics_old_ptr, kinetics_ptr, n_user_new); - return (kinetics_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct kinetics * Phreeqc:: -kinetics_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Does linear search for user number n_user. - * Returns pointer to kinetics structure and position number, n, - * in kinetics array if found. - * Returns NULL if not found. - */ - int i; - for (i = 0; i < count_kinetics; i++) - { - if (n_user == kinetics[i].n_user) - { - break; - } - } - if (i >= count_kinetics) - { - if (print == TRUE) - { - error_string = sformatf( "Kinetics %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return (NULL); - } - *n = i; - return (&kinetics[i]); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -kinetics_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of kinetics structures - */ - if (count_kinetics > 0) - { - qsort(kinetics, (size_t) count_kinetics, - (size_t) sizeof(struct kinetics), kinetics_compare); - } - return (OK); -} -#endif /* ********************************************************************** * * Routines related to structure "master" @@ -1783,145 +1219,6 @@ master_search(char *ptr, int *n) } return (NULL); } -/* ********************************************************************** - * - * Routines related to structure "pe_data" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -struct pe_data * Phreeqc:: -pe_data_alloc(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocate and initialize an array of struct pe_data - */ - struct pe_data *pe_data_ptr; - char token[MAX_LENGTH]; - - pe_data_ptr = - (struct pe_data *) PHRQ_malloc((size_t) (2 * sizeof(struct pe_data))); - if (pe_data_ptr == NULL) - malloc_error(); - pe_data_ptr[0].name = pe_string; - if (s_eminus != NULL && s_eminus->rxn != NULL) - { - pe_data_ptr[0].rxn = rxn_dup(s_eminus->rxn); - } - else - { - pe_data_ptr[0].rxn = rxn_alloc(3); - if (pe_data_ptr[0].rxn == NULL) - malloc_error(); - strcpy(token, "e-"); - s_eminus = s_store(token, -1.0, FALSE); - pe_data_ptr[0].rxn->token[0].s = s_eminus; - pe_data_ptr[0].rxn->token[0].coef = -1.0; - pe_data_ptr[0].rxn->token[1].s = s_eminus; - pe_data_ptr[0].rxn->token[1].coef = -1.0; - pe_data_ptr[0].rxn->token[2].s = NULL; - pe_data_ptr[0].rxn->dz[0] = 0.0; - pe_data_ptr[0].rxn->dz[1] = 0.0; - pe_data_ptr[0].rxn->dz[2] = 0.0; - } - pe_data_ptr[1].name = NULL; - pe_data_ptr[1].rxn = NULL; - - return (pe_data_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct pe_data * Phreeqc:: -pe_data_dup(struct pe_data *pe_ptr_old) -/* ---------------------------------------------------------------------- */ -{ -/* - * Allocate space and copy data from pe_ptr_old into the new space. - * Returns pointer to new space. - */ - int i, count_pe; - struct pe_data *pe_ptr_new; -/* - * Count pe data and copy into new structure - */ - if (pe_ptr_old == NULL) - return (ERROR); - for (i = 0; pe_ptr_old[i].name != NULL; i++); - count_pe = i + 1; - pe_ptr_new = - (struct pe_data *) PHRQ_malloc((size_t) count_pe * - sizeof(struct pe_data)); - if (pe_ptr_new == NULL) - malloc_error(); - memcpy((void *) pe_ptr_new, (void *) pe_ptr_old, - (size_t) count_pe * sizeof(struct pe_data)); - for (i = 0; i < count_pe - 1; i++) - { - pe_ptr_new[i].rxn = rxn_dup(pe_ptr_old[i].rxn); - } - pe_ptr_new[count_pe - 1].rxn = NULL; - return (pe_ptr_new); -} - -/* ---------------------------------------------------------------------- */ -struct pe_data * Phreeqc:: -pe_data_free(struct pe_data *pe_data_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all data for pe_data_ptr, including pe_data_ptr. - */ - int i; - - if (pe_data_ptr == NULL) - return (ERROR); - for (i = 0; pe_data_ptr[i].name != NULL; i++) - { - rxn_free(pe_data_ptr[i].rxn); - } - pe_data_ptr = (struct pe_data *) free_check_null(pe_data_ptr); - return (NULL); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -pe_data_store(struct pe_data **pe, const char *token) -/* ---------------------------------------------------------------------- */ -{ -/* - * Find pe name in current list of pe_data structures - * or allocate new pe_data structure - */ - int i; - struct pe_data *pe_data_ptr; -/* - * Search for pe in list - */ - pe_data_ptr = *pe; - for (i = 0; pe_data_ptr[i].name != NULL; i++) - { - if (strcmp(token, pe_data_ptr[i].name) == 0) - { - return (i); - } - } -/* - * Save new struct pe_data in array - */ - *pe = - (struct pe_data *) PHRQ_realloc((void *) *pe, - (size_t) (i + - 2) * - sizeof(struct pe_data)); - if (*pe == NULL) - malloc_error(); - pe_data_ptr = *pe; - pe_data_ptr[i].name = string_hsave(token); - pe_data_ptr[i].rxn = NULL; - pe_data_ptr[i + 1].name = NULL; - return (i); -} - /* ********************************************************************** * * Routines related to structure "phases" @@ -2606,8 +1903,6 @@ s_free(struct species *s_ptr) rxn_free(s_ptr->rxn); rxn_free(s_ptr->rxn_s); rxn_free(s_ptr->rxn_x); - s_ptr->diff_layer = - (struct species_diff_layer *) free_check_null(s_ptr->diff_layer); return (OK); } @@ -2677,7 +1972,6 @@ s_init(struct species *s_ptr) s_ptr->rxn_x = NULL; s_ptr->tot_g_moles = 0; s_ptr->tot_dh2o_moles = 0; - s_ptr->diff_layer = NULL; for (i = 0; i < 5; i++) { s_ptr->cd_music[i] = 0.0; @@ -2938,44 +2232,6 @@ save_values_store(struct save_values *s_v) } return (OK); } - -/* ********************************************************************** - * - * Routines related to structure "solution" - * - * ********************************************************************** */ -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -conc_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct conc *conc_ptr1, *conc_ptr2; - conc_ptr1 = (const struct conc *) ptr1; - conc_ptr2 = (const struct conc *) ptr2; - return (strcmp_nocase(conc_ptr1->description, conc_ptr2->description)); - -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -conc_init(struct conc *conc_ptr) -/* ---------------------------------------------------------------------- */ -{ - if (conc_ptr == NULL) - return (ERROR); - conc_ptr->description = NULL; - conc_ptr->equation_name = NULL; - conc_ptr->moles = 0; - conc_ptr->input_conc = 0; - conc_ptr->phase = NULL; - conc_ptr->phase_si = 0.0; - conc_ptr->units = NULL; - conc_ptr->n_pe = -1; - conc_ptr->as = NULL; - conc_ptr->gfw = 0.0; - return OK; -} - /* ---------------------------------------------------------------------- */ int Phreeqc:: isotope_compare(const void *ptr1, const void *ptr2) @@ -2999,533 +2255,6 @@ isotope_compare(const void *ptr1, const void *ptr2) } return (0); } - -/* ---------------------------------------------------------------------- */ -struct solution * Phreeqc:: -solution_alloc(void) -/* ---------------------------------------------------------------------- */ -/* - * Allocates space to a solution structure - * arguments - * input: none - * return: pointer to a solution structure - */ -{ - int max_mass_balance; - struct solution *solution_ptr; - solution_ptr = (struct solution *) PHRQ_malloc(sizeof(struct solution)); - if (solution_ptr == NULL) - malloc_error(); -/* - * set pointers in structure to NULL - */ - solution_ptr->new_def = TRUE; - solution_ptr->n_user = -1; - solution_ptr->n_user_end = -1; - solution_ptr->description = NULL; - solution_ptr->tc = 0; - solution_ptr->patm = 0; - solution_ptr->ph = 0; - solution_ptr->solution_pe = 0; - solution_ptr->mu = 0; - solution_ptr->ah2o = 0; - solution_ptr->density = 0; - solution_ptr->total_h = 0; - solution_ptr->total_o = 0; - solution_ptr->cb = 0; - solution_ptr->mass_water = 0; - solution_ptr->total_alkalinity = 0; - solution_ptr->units = NULL; -/* - * Initial allocation of space for pe's - */ - solution_ptr->pe = pe_data_alloc(); - solution_ptr->default_pe = 0; -/* - * Initial allocation of space for totals - */ - max_mass_balance = MAX_MASS_BALANCE; - space((void **) ((void *) &(solution_ptr->totals)), INIT, - &max_mass_balance, sizeof(struct conc)); - solution_ptr->totals[0].description = NULL; -/* - * Master activities - */ - space((void **) ((void *) &(solution_ptr->master_activity)), INIT, - &max_mass_balance, sizeof(struct master_activity)); - solution_ptr->master_activity[0].description = NULL; -/* - * Initial allocation of space for isotopes - */ - solution_ptr->isotopes = - (struct isotope *) PHRQ_malloc(sizeof(struct isotope)); - if (solution_ptr->isotopes == NULL) - malloc_error(); - solution_ptr->count_isotopes = 0; -/* - * Initial allocation of space for species_gamma - */ - solution_ptr->species_gamma = NULL; - solution_ptr->count_species_gamma = 0; - - return (solution_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct solution * Phreeqc:: -solution_bsearch(int k, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of solution solution array to find user number k. - * Assumes array solution is in sort order. - * - * Input: k user number to find. - * print, TRUE print warning if solution not found. - * Output: n, position of solution ptr in solution array. - * Return: pointer to solution structure if found - * NULL if not found. - */ - void *void_ptr; - void_ptr = NULL; - if (count_solution > 0) - { - void_ptr = (void *) - bsearch((char *) &k, - (char *) solution, - (size_t) count_solution, - (size_t) sizeof(struct solution *), solution_compare_int); - } - if (void_ptr == NULL && print == TRUE) - { - error_string = sformatf( "Solution %d not found.", k); - error_msg(error_string, CONTINUE); - } - if (void_ptr == NULL) - { - *n = -999; - return (NULL); - } - - *n = (int) ((struct solution **) void_ptr - solution); - return (*(struct solution **) void_ptr); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare solution user numbers - */ - const struct solution *nptr1; - const struct solution *nptr2; - - nptr1 = *(const struct solution **) ptr1; - nptr2 = *(const struct solution **) ptr2; - if (nptr1->n_user > nptr2->n_user) - return (1); - if (nptr1->n_user < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare solution user number to an integer - */ - const int *nptr1; - const struct solution *nptr2; - - nptr1 = (const int *) ptr1; - nptr2 = *(const struct solution **) ptr2; - if (*nptr1 > nptr2->n_user) - return (1); - if (*nptr1 < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -struct solution * Phreeqc:: -solution_copy(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies solution data to new structure. - * Space for new structure is malloced here. - * - * Input: solution_old_ptr, pointer to structure to be copied. - * n_user_new, user number to give to the new solution. - * - * Return: pointer to new solution structure. - */ - int i; - int count_totals, count_master_activity; - struct solution *solution_new_ptr; -/* - * malloc space for new solution structure - */ - solution_new_ptr = - (struct solution *) PHRQ_malloc(sizeof(struct solution)); - if (solution_new_ptr == NULL) - malloc_error(); -/* - * Copy solution data, but set pointers pe and totals to NULL - */ - memcpy((void *) solution_new_ptr, (void *) solution_old_ptr, - (size_t) sizeof(struct solution)); - solution_new_ptr->n_user = n_user_new; - solution_new_ptr->n_user_end = n_user_new; - solution_new_ptr->description = - string_duplicate(solution_old_ptr->description); -/* - * Count totals data and malloc space - */ - for (i = 0; solution_old_ptr->totals[i].description != NULL; i++); - count_totals = i + 1; - solution_new_ptr->totals = - (struct conc *) PHRQ_malloc((size_t) count_totals * - sizeof(struct conc)); - if (solution_new_ptr->totals == NULL) - malloc_error(); -/* - * Copy totals data - */ - memcpy((void *) solution_new_ptr->totals, - (void *) solution_old_ptr->totals, - (size_t) count_totals * sizeof(struct conc)); -/* - * Count master activity guesses and malloc space - */ - count_master_activity = solution_old_ptr->count_master_activity; - solution_new_ptr->master_activity = - (struct master_activity *) PHRQ_malloc((size_t) count_master_activity - * - sizeof(struct - master_activity)); - if (solution_new_ptr->master_activity == NULL) - malloc_error(); -/* - * Copy master activity guesses - */ - memcpy((void *) solution_new_ptr->master_activity, - (void *) solution_old_ptr->master_activity, - (size_t) count_master_activity * sizeof(struct master_activity)); -/* - * malloc space for species gammas - */ - if (solution_old_ptr->count_species_gamma > 0) - { - solution_new_ptr->species_gamma = - (struct master_activity *) PHRQ_malloc((size_t) - solution_old_ptr-> - count_species_gamma * - sizeof(struct - master_activity)); - if (solution_new_ptr->species_gamma == NULL) - malloc_error(); - /* - * Copy species gammas - */ - memcpy((void *) solution_new_ptr->species_gamma, - (void *) solution_old_ptr->species_gamma, - (size_t) solution_old_ptr->count_species_gamma * - sizeof(struct master_activity)); - solution_new_ptr->count_species_gamma = - solution_old_ptr->count_species_gamma; - } - else - { - solution_new_ptr->species_gamma = NULL; - solution_new_ptr->count_species_gamma = 0; - } -/* - * Copy pe data - */ - solution_new_ptr->pe = pe_data_dup(solution_old_ptr->pe); -/* - * Malloc and copy isotope data - */ - if (solution_old_ptr->count_isotopes > 0) - { - solution_new_ptr->count_isotopes = solution_old_ptr->count_isotopes; - solution_new_ptr->isotopes = - (struct isotope *) PHRQ_malloc((size_t) solution_old_ptr-> - count_isotopes * - sizeof(struct isotope)); - if (solution_new_ptr->isotopes == NULL) - malloc_error(); - memcpy(solution_new_ptr->isotopes, solution_old_ptr->isotopes, - (size_t) solution_old_ptr->count_isotopes * - sizeof(struct isotope)); - } - else - { - solution_new_ptr->count_isotopes = 0; - solution_new_ptr->isotopes = NULL; - } -/* - * Return pointer to new structure - */ - return (solution_new_ptr); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_copy_to_last(int n, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies solution from pointer solution[n]. Makes new structure - * and saves pointer in solution[count_solution]. - */ - /* Make sure solution array is large enough */ - if (count_solution + 1 >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - /* malloc space and copy solution */ - solution[count_solution] = solution_copy(solution[n], n_user_new); - count_solution++; - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees structure if it does - * Copies structure for solution[n_user_old] to new space - * Saves pointer in old position if it existed, no sort necessary - * Otherwise saves in count_solution position, sort may be necessary - * Solution array is in sort order on exit - */ - int n, n_old, n_new, sort; - struct solution *solution_old_ptr, *solution_new_ptr; -/* - * Find solution n_user_old - */ - if (n_user_old == n_user_new) - return (OK); - solution_old_ptr = solution_bsearch(n_user_old, &n_old, TRUE); - if (solution_old_ptr == NULL) - { - error_string = sformatf( "Solution %d not found.", n_user_old); - error_msg(error_string, STOP); - } -/* - * Check if solution n_user_new already exists - */ - solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); - if (solution_new_ptr != NULL) - { - n = n_new; - solution_free(solution_new_ptr); - sort = FALSE; - } - else - { - n = count_solution; - count_solution++; - if (n_user_new > solution[n - 1]->n_user) - { - sort = FALSE; - } - else - { - sort = TRUE; - } - } - solution[n] = solution_copy(solution_old_ptr, n_user_new); -/* - * Make sure surface array is large enough - */ - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } -/* - * Sort solution if necessary - */ - if (sort == TRUE) - solution_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_delete(int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete a solution structure: free memory and renumber solution. - */ - struct solution *solution_ptr; - int j, n; - solution_ptr = solution_bsearch(n_user, &n, FALSE); - if (solution_ptr != NULL) - { - solution_free(solution[n]); - for (j = n; j < (count_solution - 1); j++) - { - solution[j] = solution[j + 1]; - } - count_solution--; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_delete_n(int n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Delete a solution structure: free memory and renumber solution. - */ - int j; - if (n >= 0 && n < count_solution) - { - solution_free(solution[n]); - for (j = n; j < (count_solution - 1); j++) - { - solution[j] = solution[j + 1]; - } - count_solution--; - } - return (OK); -} -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_free(struct solution *solution_ptr) -/* ---------------------------------------------------------------------- */ -{ - if (solution_ptr == NULL) - return (OK); -/* - * Free all memory unique to a solution structure, free solution_ptr too. - */ - solution_ptr->description = - (char *) free_check_null(solution_ptr->description); -/* Free struct conc array */ - solution_ptr->totals = - (struct conc *) free_check_null(solution_ptr->totals); - solution_ptr->master_activity = - (struct master_activity *) free_check_null(solution_ptr-> - master_activity); - solution_ptr->species_gamma = - (struct master_activity *) free_check_null(solution_ptr-> - species_gamma); - solution_ptr->count_species_gamma = 0; -/* Free struct pe_data array */ - pe_data_free(solution_ptr->pe); -/* Free isotope data */ - solution_ptr->isotopes = - (struct isotope *) free_check_null(solution_ptr->isotopes); -/* Free struct solution */ - solution_ptr = (struct solution *) free_check_null(solution_ptr); - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_ptr_to_user(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees structure if it does - * Copies structure for solution[n_user_old] to new space - * Saves pointer in old position if it existed, no sort necessary - * Otherwise saves in count_solution position, sort may be necessary - * Solution array is in sort order on exit - */ - int n, n_new, sort; - struct solution *solution_new_ptr; -/* - * Find solution n_user_old - */ - if (solution_old_ptr == NULL) - { - error_string = sformatf( "Solution pointer is NULL."); - error_msg(error_string, STOP); - } -/* - * Check if solution n_user_new already exists - */ - solution_new_ptr = solution_bsearch(n_user_new, &n_new, FALSE); - if (solution_new_ptr == solution_old_ptr) - return (OK); - if (solution_new_ptr != NULL) - { - n = n_new; - solution_free(solution_new_ptr); - sort = FALSE; - } - else - { - n = count_solution; - count_solution++; - /* - * Make sure surface array is large enough - */ - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - if (n_user_new > solution[n - 1]->n_user) - { - sort = FALSE; - } - else - { - sort = TRUE; - } - } - solution[n] = solution_copy(solution_old_ptr, n_user_new); -/* - * Sort solution if necessary - */ - if (sort == TRUE) - solution_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct solution * Phreeqc:: -solution_replicate(struct solution *solution_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - return (solution_copy(solution_old_ptr, n_user_new)); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -solution_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of pointers to solution structures, solution. - */ - if (count_solution > 0) - { - qsort(solution, - (size_t) count_solution, - (size_t) sizeof(struct solution *), solution_compare); - } - return (OK); -} - /* ********************************************************************** * * Routines related to structure "species_list" @@ -3730,601 +2459,34 @@ change_surf_alloc(int count) return (change_surf); } - -/* ---------------------------------------------------------------------- */ -struct surface * Phreeqc:: -surface_alloc(void) -/* ---------------------------------------------------------------------- */ -{ - struct surface *surface_ptr; - surface_ptr = (struct surface *) PHRQ_malloc(sizeof(struct surface)); - if (surface_ptr == NULL) - malloc_error(); - surface_ptr->n_user = -1; - surface_ptr->n_user_end = -1; - surface_ptr->new_def = 0; - surface_ptr->only_counter_ions = 0; - surface_ptr->dl_type = BORKOVEK_DL; - surface_ptr->type = UNKNOWN_DL; - surface_ptr->sites_units = SITES_ABSOLUTE; - surface_ptr->thickness = 0; - surface_ptr->debye_lengths = 0; - surface_ptr->DDL_viscosity = 0; /* viscosity relative to pure water */ - surface_ptr->DDL_limit = 0; /* limits DDL water to this fraction of bulk water */ - surface_ptr->description = NULL; - surface_ptr->solution_equilibria = 0; - surface_ptr->n_solution = 0; - surface_ptr->count_comps = 0; - surface_ptr->comps = NULL; - surface_ptr->count_charge = 0; - surface_ptr->charge = NULL; - surface_ptr->related_phases = 0; - surface_ptr->related_rate = 0; - surface_ptr->transport = 0; /* transports comp's and charges if true */ - return (surface_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct surface * Phreeqc:: -surface_bsearch(int k, int *n) -/* ---------------------------------------------------------------------- */ -{ -/* - * Binary search of array surface to find user number k. - * Assumes array surface is in sort order. - * - * Input: k, user number to find. - * Output: n, position in array surface of user number k. - * Return: pointer to surface structure if found, - * NULL if not found. - */ - void *void_ptr; - if (count_surface == 0) - { - *n = -999; - return (NULL); - } - void_ptr = (void *) - bsearch((char *) &k, - (char *) surface, - (size_t) count_surface, - (size_t) sizeof(struct surface), surface_compare_int); - if (void_ptr == NULL) - { - *n = -999; - return (NULL); - } - *n = (int) ((struct surface *) void_ptr - surface); - return ((struct surface *) void_ptr); -} - /* ---------------------------------------------------------------------- */ struct master * Phreeqc:: surface_get_psi_master(const char *name, int plane) /* ---------------------------------------------------------------------- */ { struct master *master_ptr; - char token[MAX_LENGTH]; + std::string token; if (name == NULL) return (NULL); - strcpy(token, name); - strcat(token, "_psi"); + token = name; + token.append("_psi"); switch (plane) { case SURF_PSI: break; case SURF_PSI1: - strcat(token, "b"); + token.append("b"); break; case SURF_PSI2: - strcat(token, "d"); + token.append("d"); break; default: error_msg("Unknown plane for surface_get_psi_master", STOP); } - master_ptr = master_bsearch(token); + master_ptr = master_bsearch(token.c_str()); return (master_ptr); } - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_comp_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct surface_comp *surface_comp_ptr1, *surface_comp_ptr2; - surface_comp_ptr1 = (const struct surface_comp *) ptr1; - surface_comp_ptr2 = (const struct surface_comp *) ptr2; - return (strcmp_nocase - (surface_comp_ptr1->master->elt->name, - surface_comp_ptr2->master->elt->name)); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_charge_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct surface_charge *surface_charge_ptr1, *surface_charge_ptr2; - surface_charge_ptr1 = (const struct surface_charge *) ptr1; - surface_charge_ptr2 = (const struct surface_charge *) ptr2; - return (strcmp_nocase - (surface_charge_ptr1->name, surface_charge_ptr2->name)); -} - - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_compare(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ - const struct surface *surface_ptr1, *surface_ptr2; - surface_ptr1 = (const struct surface *) ptr1; - surface_ptr2 = (const struct surface *) ptr2; - if (surface_ptr1->n_user > surface_ptr2->n_user) - return (1); - if (surface_ptr1->n_user < surface_ptr2->n_user) - return (-1); - return (0); - -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -surface_compare_int(const void *ptr1, const void *ptr2) -/* ---------------------------------------------------------------------- */ -{ -/* - * Compare surface user numbers to integer - */ - const int *nptr1; - const struct surface *nptr2; - - nptr1 = (const int *) ptr1; - nptr2 = (const struct surface *) ptr2; - if (*nptr1 > nptr2->n_user) - return (1); - if (*nptr1 < nptr2->n_user) - return (-1); - return (0); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_copy(struct surface *surface_old_ptr, - struct surface *surface_new_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies data from surface_old_ptr to surface_new_ptr. - * Space for a surface structure must already be malloced. - * User number of new surface structure is n_user. - */ - int count_comps, count_charge, i; - char token[MAX_LENGTH]; -/* - * Store data for structure surface - */ - memcpy(surface_new_ptr, surface_old_ptr, sizeof(struct surface)); - count_comps = surface_old_ptr->count_comps; - count_charge = surface_old_ptr->count_charge; - surface_new_ptr->n_user = n_user_new; - surface_new_ptr->n_user_end = n_user_new; - surface_new_ptr->new_def = surface_old_ptr->new_def; - sprintf(token, "Surface defined in simulation %d.", simulation); - surface_new_ptr->description = string_duplicate(token); - surface_new_ptr->solution_equilibria = FALSE; - surface_new_ptr->n_solution = -10; -/* - * Write surface_comp structure for each surface component - */ - surface_new_ptr->comps = - (struct surface_comp *) PHRQ_malloc((size_t) (count_comps) * - sizeof(struct surface_comp)); - if (surface_new_ptr->comps == NULL) - malloc_error(); - memcpy(surface_new_ptr->comps, surface_old_ptr->comps, - (size_t) (count_comps) * sizeof(struct surface_comp)); - for (i = 0; i < count_comps; i++) - { - surface_new_ptr->comps[i].formula_totals = - elt_list_dup(surface_old_ptr->comps[i].formula_totals); - surface_new_ptr->comps[i].totals = - elt_list_dup(surface_old_ptr->comps[i].totals); - } -/* - * Write surface_charge structure for each surface - */ - /*if (surface_old_ptr->edl == TRUE) { */ - if (surface_old_ptr->type == DDL || surface_old_ptr->type == CD_MUSIC) - { - surface_new_ptr->charge = - (struct surface_charge *) PHRQ_malloc((size_t) (count_charge) * - sizeof(struct - surface_charge)); - if (surface_new_ptr->charge == NULL) - malloc_error(); - memcpy(surface_new_ptr->charge, surface_old_ptr->charge, - (size_t) (count_charge) * sizeof(struct surface_charge)); - for (i = 0; i < count_charge; i++) - { - surface_new_ptr->charge[i].diffuse_layer_totals = - elt_list_dup(surface_old_ptr->charge[i].diffuse_layer_totals); - surface_new_ptr->charge[i].g = NULL; - } - } - else - { - surface_new_ptr->count_charge = 0; - surface_new_ptr->charge = NULL; - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct surface_charge * Phreeqc:: -surface_charge_duplicate(struct surface_charge *charge_old_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Duplicates data from surface_old_ptr - * Space is malloced. - */ - struct surface_charge *charge; -/* - * Write surface_charge structure for each surface - */ - charge = - (struct surface_charge *) PHRQ_malloc(sizeof(struct surface_charge)); - if (charge == NULL) - malloc_error(); - memcpy(charge, charge_old_ptr, sizeof(struct surface_charge)); - charge->diffuse_layer_totals = - elt_list_dup(charge_old_ptr->diffuse_layer_totals); - charge->count_g = 0; - charge->g = NULL; - return (charge); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_charge_free(struct surface_charge *charge) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all space related to surface_charge - */ - if (charge == NULL) - return (ERROR); - charge->diffuse_layer_totals = - (struct elt_list *) free_check_null(charge->diffuse_layer_totals); - charge->g = (struct surface_diff_layer *) free_check_null(charge->g); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_copy_to_last(int n, int n_user) -/* ---------------------------------------------------------------------- */ -{ -/* - * Copies an surface definition to position count_surface. - */ - space((void **) ((void *) &surface), count_surface, &max_surface, - sizeof(struct surface)); - surface_copy(&surface[n], &surface[count_surface], n_user); - count_surface++; - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_duplicate(int n_user_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies surface[n_user_old] to old n_user_new space if - * found or to surface[count_surface] if not found. - * Surface array may not be in sort order after the copy. - */ - int n_old, n_new, sort; - struct surface *surface_ptr_old, *surface_ptr_new; -/* - * Find n_user_old in structure array surface - */ - if (n_user_old == n_user_new) - return (OK); - surface_ptr_old = surface_bsearch(n_user_old, &n_old); - if (surface_ptr_old == NULL) - { - error_string = sformatf( "Surface %d not found.", n_user_old); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array surface or make new space - */ - sort = FALSE; - surface_ptr_new = surface_bsearch(n_user_new, &n_new); - if (surface_ptr_new != NULL) - { - surface_free(surface_ptr_new); - } - else - { - space((void **) ((void *) &surface), count_surface, &max_surface, - sizeof(struct surface)); - if (n_user_new < surface[count_surface - 1].n_user) - sort = TRUE; - n_new = count_surface++; - } -/* - * Copy data - */ - surface_copy(&surface[n_old], &surface[n_new], n_user_new); - if (sort == TRUE) - surface_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_delete(int n_user_old) -/* ---------------------------------------------------------------------- */ -/* - * Frees space for user number n_user_old, removes structure from - * array surface. - */ -{ - int i; - int n_old; - struct surface *surface_ptr_old; -/* - * Find n_user_old in structure array - */ - surface_ptr_old = surface_bsearch(n_user_old, &n_old); - if (surface_ptr_old != NULL) - { - /* - * Delete surface - */ - surface_free(&surface[n_old]); - - for (i = n_old + 1; i < count_surface; i++) - { - memcpy((void *) &surface[i - 1], (void *) &surface[i], - (size_t) sizeof(struct surface)); - } - count_surface--; - } - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_free(struct surface *surface_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Frees all space related to surface_ptr, but not surface_ptr. - */ - int k; - - if (surface_ptr == NULL) - return (ERROR); - surface_ptr->description = - (char *) free_check_null(surface_ptr->description); -/* - * totals, then comps - */ - for (k = 0; k < surface_ptr->count_comps; k++) - { - surface_ptr->comps[k].formula_totals = - (struct elt_list *) free_check_null(surface_ptr->comps[k]. - formula_totals); - surface_ptr->comps[k].totals = - (struct elt_list *) free_check_null(surface_ptr->comps[k].totals); - } - surface_ptr->comps = - (struct surface_comp *) free_check_null(surface_ptr->comps); -/* - * diffuse_layer_totals and g, then charge - */ - /*if (surface_ptr->edl == TRUE) { */ - if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) - { - for (k = 0; k < surface_ptr->count_charge; k++) - { - surface_ptr->charge[k].diffuse_layer_totals = - (struct elt_list *) free_check_null(surface_ptr->charge[k]. - diffuse_layer_totals); - surface_ptr->charge[k].g = - (struct surface_diff_layer *) free_check_null(surface_ptr-> - charge[k].g); - } - } - surface_ptr->charge = - (struct surface_charge *) free_check_null(surface_ptr->charge); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_init(struct surface *surface_ptr, int n_user, int n_user_end, - char *description) -/* ---------------------------------------------------------------------- */ -{ - - if (surface_ptr == NULL) - return (ERROR); - - surface_ptr->n_user = n_user; - surface_ptr->n_user_end = n_user_end; - surface_ptr->new_def = TRUE; - surface_ptr->dl_type = NO_DL; - surface_ptr->sites_units = SITES_ABSOLUTE; - /*surface_ptr->edl = TRUE; */ - surface_ptr->type = DDL; - surface_ptr->only_counter_ions = FALSE; - /*surface_ptr->donnan = FALSE; */ - surface_ptr->thickness = 1e-8; - surface_ptr->debye_lengths = 0.0; - surface_ptr->DDL_viscosity = 1.0; - surface_ptr->DDL_limit = 0.8; - surface_ptr->description = string_duplicate(description); - surface_ptr->solution_equilibria = FALSE; - surface_ptr->n_solution = -999; - surface_ptr->transport = FALSE; -/* - * Malloc one surface_comp structure - */ - surface_ptr->count_comps = 0; - surface_ptr->comps = - (struct surface_comp *) PHRQ_malloc((size_t) - sizeof(struct surface_comp)); - if (surface_ptr->comps == NULL) - malloc_error(); - surface_ptr->comps[0].master = NULL; - surface_ptr->comps[0].totals = NULL; - surface_ptr->comps[0].phase_name = NULL; - surface_ptr->comps[0].rate_name = NULL; - surface_ptr->comps[0].charge = -1; - surface_ptr->comps[0].moles = 0; - surface_ptr->comps[0].cb = 0; - surface_ptr->comps[0].Dw = 0; -/* - * Malloc one charge structure - */ - surface_ptr->count_charge = 0; - surface_ptr->charge = - (struct surface_charge *) PHRQ_malloc((size_t) - sizeof(struct surface_charge)); - if (surface_ptr->charge == NULL) - malloc_error(); - - surface_ptr->related_phases = FALSE; - surface_ptr->related_rate = FALSE; - - return (OK); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_ptr_to_user(struct surface *surface_ptr_old, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ -/* - * Checks if n_user_new exists, and frees space if it does - * Copies surface_ptr_old to old n_user_new space if - * found or to surface[count_surface] if not found. - * Surface array may not be in sort order after the copy. - */ - int n_new, sort; - struct surface *surface_ptr_new; -/* - * Find n_user_old in structure array surface - */ - if (surface_ptr_old == NULL) - { - error_string = sformatf( "Surface pointer is NULL."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } -/* - * Find n_user_new in structure array surface or make new space - */ - sort = FALSE; - surface_ptr_new = surface_bsearch(n_user_new, &n_new); - if (surface_ptr_new == surface_ptr_old) - return (OK); - if (surface_ptr_new != NULL) - { - surface_free(surface_ptr_new); - } - else - { - space((void **) ((void *) &surface), count_surface, &max_surface, - sizeof(struct surface)); - if (n_user_new < surface[count_surface - 1].n_user) - sort = TRUE; - n_new = count_surface++; - } -/* - * Copy data - */ - surface_copy(surface_ptr_old, &surface[n_new], n_user_new); - if (sort == TRUE) - surface_sort(); - return (OK); -} - -/* ---------------------------------------------------------------------- */ -struct surface * Phreeqc:: -surface_replicate(struct surface *surface_old_ptr, int n_user_new) -/* ---------------------------------------------------------------------- */ -{ - struct surface *surface_ptr; - surface_ptr = surface_alloc(); - surface_copy(surface_old_ptr, surface_ptr, n_user_new); - return (surface_ptr); -} - -/* ---------------------------------------------------------------------- */ -struct surface * Phreeqc:: -surface_search(int n_user, int *n, int print) -/* ---------------------------------------------------------------------- */ -{ -/* Linear search of the structure array "surface" for user number n_user. - * - * Arguments: - * n_user input, user number. - * n output, position in surface. - * - * Returns: - * if found, pointer to surface structure - * if not found, NULL - */ - int i; - for (i = 0; i < count_surface; i++) - { - if (n_user == surface[i].n_user) - { - break; - } - } - if (i >= count_surface) - { - if (print == TRUE) - { - error_string = sformatf( "Surface %d not found.", n_user); - error_msg(error_string, CONTINUE); - } - *n = -999; - return (NULL); - } - *n = i; - return (&surface[i]); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -surface_sort(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Sort array of surface structures - */ - if (count_surface > 0) - { - qsort(surface, (size_t) count_surface, - (size_t) sizeof(struct surface), surface_compare); - } - return (OK); -} - /* ********************************************************************** * * Routines related to structure "trxn" @@ -4340,6 +2502,69 @@ rxn_token_temp_compare(const void *ptr1, const void *ptr2) rxn_token_temp_ptr2 = (const struct rxn_token_temp *) ptr2; return (strcmp(rxn_token_temp_ptr1->name, rxn_token_temp_ptr2->name)); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine) +/* ---------------------------------------------------------------------- */ +{ +/* + * Adds reactions together. + * + * Global variable count_trxn determines which position in trxn is used. + * If count_trxn=0, then the equation effectively is copied into trxn. + * If count_trxn>0, then new equation is added to existing equation. + * + * Arguments: + * *r_ptr points to rxn structure to add. + * + * coef added equation is multiplied by coef. + * combine if TRUE, reaction is reaction is sorted and + * like terms combined. + */ +/* + * Accumulate log k for reaction + */ + if (count_trxn == 0) + { + for (int i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] = r_ptr.Get_logk()[i]; + } + for (int i = 0; i < 3; i++) + { + trxn.dz[i] = r_ptr.Get_dz()[i]; + } + } + else + { + for (int i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] += coef * (r_ptr.Get_logk()[i]); + } + for (int i = 0; i < 3; i++) + { + trxn.dz[i] += coef * r_ptr.Get_dz()[i]; + } + } +/* + * Copy equation into work space + */ + for (size_t j = 0; j < r_ptr.Get_tokens().size(); j++) + { + if (count_trxn + 1 >= max_trxn) + { + space((void **) ((void *) &(trxn.token)), count_trxn + 1, + &max_trxn, sizeof(struct rxn_token_temp)); + } + trxn.token[count_trxn].name = r_ptr.Get_tokens()[j].name; + trxn.token[count_trxn].s = r_ptr.Get_tokens()[j].s; + trxn.token[count_trxn].coef = coef * r_ptr.Get_tokens()[j].coef; + count_trxn++; + } + if (combine == TRUE) + trxn_combine(); + return (OK); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -4814,11 +3039,8 @@ unknown_alloc(void) unknown_ptr->master = NULL; unknown_ptr->phase = NULL; unknown_ptr->si = 0.0; - //unknown_ptr->gas_phase = NULL; - unknown_ptr->total = NULL; unknown_ptr->s = NULL; unknown_ptr->exch_comp = NULL; - //unknown_ptr->pure_phase = NULL; unknown_ptr->ss_name = NULL; unknown_ptr->ss_comp_name = NULL; unknown_ptr->ss_comp_number = 0; @@ -4886,25 +3108,18 @@ int Phreeqc:: system_duplicate(int i, int save_old) /* ---------------------------------------------------------------------- */ { - int n; - - if (solution_bsearch(i, &n, TRUE) != NULL) - solution_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_solution_map, i, save_old); Utilities::Rxn_copy(Rxn_pp_assemblage_map, i, save_old); Utilities::Rxn_copy(Rxn_exchange_map, i, save_old); - if (surface_bsearch(i, &n) != NULL) - surface_duplicate(i, save_old); + Utilities::Rxn_copy(Rxn_surface_map, i, save_old); Utilities::Rxn_copy(Rxn_gas_phase_map, i, save_old); Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old); -#ifdef SKIP - if (kinetics_bsearch(i, &n) != NULL) - kinetics_duplicate(i, save_old); -#endif + Utilities::Rxn_copy(Rxn_ss_assemblage_map, i, save_old); return (OK); @@ -5122,20 +3337,18 @@ entity_exists(char *name, int n_user) return_value = 2; break; case Solution: /* Solution */ - if (solution_bsearch(n_user, &i, FALSE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, n_user) == NULL) { return_value = FALSE; } break; case Pure_phase: /* Pure phases */ - //if (pp_assemblage_bsearch(n_user, &i) == NULL) if (Utilities::Rxn_find(Rxn_pp_assemblage_map, n_user) == NULL) { return_value = FALSE; } break; case Reaction: /* Reaction */ - //if (irrev_bsearch(n_user, &i) == NULL) if (Utilities::Rxn_find(Rxn_reaction_map, n_user) == NULL) { return_value = FALSE; @@ -5146,10 +3359,6 @@ entity_exists(char *name, int n_user) { return_value = FALSE; } - //if (mix_bsearch(n_user, &i) == NULL) - //{ - // return_value = FALSE; - //} break; case Exchange: /* Ex */ if (Utilities::Rxn_find(Rxn_exchange_map, n_user) == NULL) @@ -5158,7 +3367,7 @@ entity_exists(char *name, int n_user) } break; case Surface: /* Surface */ - if (surface_bsearch(n_user, &i) == NULL) + if (Utilities::Rxn_find(Rxn_surface_map, n_user) == NULL) { return_value = FALSE; } @@ -5340,531 +3549,6 @@ copier_init(struct copier *copier_ptr) (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); return (OK); } -#ifdef SKIP -#include "../cxxKinetics.h" -struct kinetics * Phreeqc:: -cxxKinetics2kinetics(const cxxKinetics * kin) - // - // Builds a kinetics structure from instance of cxxKinetics - // -{ - if (kin == NULL) return NULL; - struct kinetics *kinetics_ptr = kinetics_alloc(); - - kinetics_ptr->description = string_duplicate (kin->Get_description().c_str()); - kinetics_ptr->n_user = kin->Get_n_user(); - kinetics_ptr->n_user_end = kin->Get_n_user_end(); - kinetics_ptr->step_divide = kin->Get_step_divide(); - kinetics_ptr->rk = kin->Get_rk(); - kinetics_ptr->bad_step_max = kin->Get_bad_step_max(); - kinetics_ptr->use_cvode = (int) kin->Get_use_cvode(); - kinetics_ptr->cvode_steps = kin->Get_cvode_steps(); - kinetics_ptr->cvode_order = kin->Get_cvode_order(); - - // totals - kinetics_ptr->totals = cxxNameDouble2elt_list(&(kin->Get_totals())); - - // comps - kinetics_ptr->count_comps = (int) kin->Get_kineticsComps().size(); - kinetics_ptr->comps = - (struct kinetics_comp *) free_check_null(kinetics_ptr->comps); - kinetics_ptr->comps = cxxKineticsComp2kinetics_comp(&(kin->Get_kineticsComps())); - - // steps - if (kin->Get_equal_steps() == 0) - { - kinetics_ptr->count_steps = (int) kin->Get_steps().size(); - } - else - { - kinetics_ptr->count_steps = -kin->Get_equal_steps(); - } - kinetics_ptr->steps = (LDBLE *) free_check_null(kinetics_ptr->steps); - if (kin->Get_steps().size() > 0) - { - kinetics_ptr->steps = (LDBLE *) PHRQ_malloc((size_t) (kin->Get_steps().size() * sizeof(LDBLE))); - if (kinetics_ptr->steps == NULL) - malloc_error(); - std::copy(kin->Get_steps().begin(), kin->Get_steps().end(), - kinetics_ptr->steps); - /* - int i = 0; - for (std::vector::iterator it = this->steps.begin(); it != this->steps.end(); it++) { - kinetics_ptr->steps[i] = *it; - } - */ - } - return (kinetics_ptr); -} - -struct kinetics_comp * Phreeqc:: -cxxKineticsComp2kinetics_comp(const std::list < cxxKineticsComp > *el) - // - // Builds kinetics_comp structure from of cxxKineticsComp - // -{ - if (el == NULL) return NULL; - struct kinetics_comp *kinetics_comp_ptr = - (struct kinetics_comp *) - PHRQ_malloc((size_t) (el->size() * sizeof(struct kinetics_comp))); - if (kinetics_comp_ptr == NULL) - malloc_error(); - - int i = 0; - for (std::list < cxxKineticsComp >::const_iterator it = el->begin(); - it != el->end(); ++it) - { - if ((*it).Get_rate_name().size() == 0) - kinetics_comp_ptr[i].rate_name = NULL; - else - kinetics_comp_ptr[i].rate_name = string_hsave((*it).Get_rate_name().c_str()); - kinetics_comp_ptr[i].list = cxxNameDouble2name_coef(&((*it).Get_namecoef())); - kinetics_comp_ptr[i].count_list = (int) (*it).Get_namecoef().size(); - kinetics_comp_ptr[i].tol = (*it).Get_tol(); - kinetics_comp_ptr[i].m = (*it).Get_m(); - kinetics_comp_ptr[i].initial_moles = 0.; - kinetics_comp_ptr[i].m0 = (*it).Get_m0(); - kinetics_comp_ptr[i].moles = (*it).Get_moles(); - kinetics_comp_ptr[i].count_c_params = 0; - kinetics_comp_ptr[i].c_params = NULL; -/* - kinetics_comp_ptr[i].count_d_params = 0; - kinetics_comp_ptr[i].d_params = NULL; -*/ - - kinetics_comp_ptr[i].count_d_params = (int) (*it).Get_d_params().size(); - kinetics_comp_ptr[i].d_params = NULL; - if ((*it).Get_d_params().size() > 0) - { - kinetics_comp_ptr[i].d_params = (LDBLE *) - PHRQ_malloc((size_t) ((*it).Get_d_params().size() * sizeof(LDBLE))); - if (kinetics_comp_ptr[i].d_params == NULL) - malloc_error(); - std::copy((*it).Get_d_params().begin(), (*it).Get_d_params().end(), - kinetics_comp_ptr[i].d_params); - } - i++; - } - return (kinetics_comp_ptr); -} -#endif -#include "../Solution.h" -struct solution * Phreeqc:: -cxxSolution2solution(const cxxSolution * sol) - // - // Builds a solution structure from instance of cxxSolution - // -{ - - struct solution *solution_ptr = solution_alloc(); - - solution_ptr->description = string_duplicate (sol->Get_description().c_str()); - solution_ptr->n_user = sol->Get_n_user(); - solution_ptr->n_user_end = sol->Get_n_user_end(); - solution_ptr->new_def = FALSE; - solution_ptr->tc = sol->Get_tc(); - solution_ptr->ph = sol->Get_ph(); - solution_ptr->solution_pe = sol->Get_pe(); - solution_ptr->mu = sol->Get_mu(); - solution_ptr->ah2o = sol->Get_ah2o(); - solution_ptr->total_h = sol->Get_total_h(); - solution_ptr->total_o = sol->Get_total_o(); - solution_ptr->cb = sol->Get_cb(); - solution_ptr->mass_water = sol->Get_mass_water(); - solution_ptr->total_alkalinity = sol->Get_total_alkalinity(); - solution_ptr->density = 1.0; - solution_ptr->units = moles_per_kilogram_string; - solution_ptr->default_pe = 0; - // pe_data - - // totals - solution_ptr->totals = - (struct conc *) free_check_null(solution_ptr->totals); - solution_ptr->totals = cxxNameDouble2conc(&sol->Get_totals()); - - - // master_activity - solution_ptr->master_activity = - (struct master_activity *) free_check_null(solution_ptr->master_activity); - solution_ptr->master_activity = cxxNameDouble2master_activity(&sol->Get_master_activity()); - solution_ptr->count_master_activity = - (int) sol->Get_master_activity().size() + 1; - - // species_gamma - solution_ptr->species_gamma = cxxNameDouble2master_activity(&sol->Get_species_gamma()); - solution_ptr->count_species_gamma = (int) sol->Get_species_gamma().size(); - - // isotopes - solution_ptr->isotopes = - (struct isotope *) free_check_null(solution_ptr->isotopes); - //solution_ptr->isotopes = cxxSolutionIsotope::list2isotope(this->isotopes); - solution_ptr->isotopes = cxxSolutionIsotopeList2isotope(&sol->Get_isotopes()); - solution_ptr->count_isotopes = (int) sol->Get_isotopes().size(); - - return (solution_ptr); -} - -#include "../SolutionIsotopeList.h" -struct isotope * Phreeqc:: -cxxSolutionIsotopeList2isotope(const cxxSolutionIsotopeList * il) -{ - struct isotope *iso; - if (il->size() <= 0) - { - return NULL; - } - else - { - iso = - (struct isotope *) PHRQ_malloc((size_t) ((il->size()) * sizeof(struct isotope))); - if (iso == NULL) - malloc_error(); - int i = 0; - for (cxxSolutionIsotopeList::const_iterator it = il->begin(); - it != il->end(); ++it) - { - iso[i].isotope_number = it->Get_isotope_number(); - iso[i].elt_name = string_hsave(it->Get_elt_name().c_str()); - iso[i].total = it->Get_total(); - iso[i].ratio = it->Get_ratio(); - iso[i].ratio_uncertainty = it->Get_ratio_uncertainty(); - iso[i].master = master_bsearch(it->Get_elt_name().c_str()); - const char * str = string_hsave(it->Get_elt_name().c_str()); - iso[i].primary = master_bsearch_primary(str); - i++; - } - } - return (iso); -} -#include "../Surface.h" -struct surface * Phreeqc:: -cxxSurface2surface(const cxxSurface * surf) - // - // Builds a surface structure from instance of cxxSurface - // -{ - struct surface *surface_ptr = surface_alloc(); - - surface_ptr->description = string_duplicate (surf->Get_description().c_str()); - surface_ptr->n_user = surf->Get_n_user(); - surface_ptr->n_user_end = surf->Get_n_user_end(); - surface_ptr->new_def = FALSE; - surface_ptr->type = surf->Get_type(); - surface_ptr->dl_type = surf->Get_dl_type(); - surface_ptr->sites_units = surf->Get_sites_units(); - surface_ptr->only_counter_ions = surf->Get_only_counter_ions(); - surface_ptr->thickness = surf->Get_thickness(); - surface_ptr->debye_lengths = 1.0; - surface_ptr->solution_equilibria = FALSE; - surface_ptr->n_solution = -2; - surface_ptr->related_phases = (int) surf->Get_related_phases(); - surface_ptr->related_rate = (int) surf->Get_related_rate(); - surface_ptr->transport = surf->Get_transport(); - surface_ptr->debye_lengths = surf->Get_debye_lengths(); - surface_ptr->DDL_viscosity = surf->Get_DDL_viscosity(); - surface_ptr->DDL_limit = surf->Get_DDL_limit(); - - // Surface comps - surface_ptr->count_comps = (int) surf->Get_surfaceComps().size(); - surface_ptr->comps = - (struct surface_comp *) free_check_null(surface_ptr->comps); - surface_ptr->comps = - cxxSurfaceComp2surface_comp(&surf->Get_surfaceComps()); - - // Surface charge - surface_ptr->charge = - (struct surface_charge *) free_check_null(surface_ptr->charge); - - //if (surface_ptr->edl == TRUE) { - if (surface_ptr->type == DDL || surface_ptr->type == CD_MUSIC) - { - surface_ptr->count_charge = (int) surf->Get_surfaceCharges().size(); - surface_ptr->charge = - cxxSurfaceCharge2surface_charge(&surf->Get_surfaceCharges()); - } - else - { - surface_ptr->count_charge = 0; - } - // Need to fill in charge (number) in comps list - if (surface_ptr->type != NO_EDL) - { - int i, j; - for (i = 0; i < surface_ptr->count_comps; i++) - { - char token[MAX_LENGTH], name[MAX_LENGTH]; - int l; - strcpy(token, surface_ptr->comps[i].formula); - char *ptr1 = token; - get_elt(&ptr1, name, &l); - ptr1 = strchr(name, '_'); - if (ptr1 != NULL) - { - ptr1[0] = '\0'; - } - const char *charge_name = string_hsave(name); - - for (j = 0; j < surface_ptr->count_charge; j++) - { - if (charge_name == surface_ptr->charge[j].name) - { - surface_ptr->comps[i].charge = j; - break; - } - } - assert(j < surface_ptr->count_charge); - } - } - - return (surface_ptr); -} - -#include "../SurfaceComp.h" -struct surface_comp * Phreeqc:: -cxxSurfaceComp2surface_comp(const std::map < std::string, cxxSurfaceComp > * sc) - // - // Builds surface_comp structure from of cxxSurfaceComp - // -{ - struct surface_comp *surf_comp_ptr = - (struct surface_comp *) PHRQ_malloc((size_t) (sc->size() * sizeof(struct surface_comp))); - if (surf_comp_ptr == NULL) - malloc_error(); - - int i = 0; - for (std::map < std::string, cxxSurfaceComp >::const_iterator it = sc->begin(); - it != sc->end(); ++it) - { - surf_comp_ptr[i].formula = string_hsave((*it).second.Get_formula().c_str()); - assert((*it).second.Get_formula().size() > 0); - surf_comp_ptr[i].formula_totals = cxxNameDouble2elt_list(&(*it).second.Get_formula_totals()); - surf_comp_ptr[i].formula_z = (*it).second.Get_formula_z(); - surf_comp_ptr[i].moles = (*it).second.Get_moles(); - surf_comp_ptr[i].master = cxxNameDouble2surface_master(&(*it).second.Get_totals()); - surf_comp_ptr[i].totals = cxxNameDouble2elt_list(&(*it).second.Get_totals()); - surf_comp_ptr[i].la = (*it).second.Get_la(); - //surf_comp_ptr[i].charge = it->charge_number; - surf_comp_ptr[i].cb = (*it).second.Get_charge_balance(); - if ((*it).second.Get_phase_name().size() == 0) - surf_comp_ptr[i].phase_name = NULL; - else - surf_comp_ptr[i].phase_name = string_hsave((*it).second.Get_phase_name().c_str()); - surf_comp_ptr[i].phase_proportion = (*it).second.Get_phase_proportion(); - if ((*it).second.Get_rate_name().size() == 0) - surf_comp_ptr[i].rate_name = NULL; - else - surf_comp_ptr[i].rate_name = string_hsave((*it).second.Get_rate_name().c_str()); - surf_comp_ptr[i].Dw = (*it).second.Get_Dw(); - i++; - } - return (surf_comp_ptr); -} - -#include "../SurfaceCharge.h" -struct surface_charge * Phreeqc:: -cxxSurfaceCharge2surface_charge(const std::map < std::string, cxxSurfaceCharge > * s_ch) - // - // Builds surface_charge structure from of cxxSurfaceCharge - // -{ - struct surface_charge *surf_charge_ptr = - (struct surface_charge *) PHRQ_malloc((size_t) (s_ch->size() * sizeof(struct surface_charge))); - if (surf_charge_ptr == NULL) - malloc_error(); - - int i = 0; - for (std::map < std::string, cxxSurfaceCharge >::const_iterator it = s_ch->begin(); - it != s_ch->end(); ++it) - { - surf_charge_ptr[i].name = string_hsave((*it).second.Get_name().c_str()); - assert((*it).second.Get_name().size() > 0); - surf_charge_ptr[i].specific_area = (*it).second.Get_specific_area(); - surf_charge_ptr[i].grams = (*it).second.Get_grams(); - surf_charge_ptr[i].charge_balance = (*it).second.Get_charge_balance(); - surf_charge_ptr[i].mass_water = (*it).second.Get_mass_water(); - surf_charge_ptr[i].la_psi = (*it).second.Get_la_psi(); - surf_charge_ptr[i].la_psi1 = (*it).second.Get_la_psi1(); - surf_charge_ptr[i].la_psi2 = (*it).second.Get_la_psi2(); - surf_charge_ptr[i].capacitance[0] = (*it).second.Get_capacitance0(); - surf_charge_ptr[i].capacitance[1] = (*it).second.Get_capacitance1(); - surf_charge_ptr[i].sigma0 = 0; - surf_charge_ptr[i].sigma1 = 0; - surf_charge_ptr[i].sigma2 = 0; - surf_charge_ptr[i].sigmaddl = 0; - surf_charge_ptr[i].diffuse_layer_totals = cxxNameDouble2elt_list(&(*it).second.Get_diffuse_layer_totals()); - surf_charge_ptr[i].count_g = 0; - surf_charge_ptr[i].g = NULL; - i++; - } - return (surf_charge_ptr); -} - -struct master * Phreeqc:: -cxxNameDouble2surface_master(const cxxNameDouble * totals) -{ - struct master *master_ptr = NULL; - for (cxxNameDouble::const_iterator it = totals->begin(); - it != totals->end(); it++) - { - /* Find master species */ - const char *eltName = string_hsave(it->first.c_str()); - assert(it->first.size() > 0); - struct element *elt_ptr = element_store(eltName); - if (elt_ptr->master == NULL) - { - std::ostringstream error_oss; - error_oss << "Master species not in data base for " << elt_ptr-> - name << "\n"; - error_msg(error_oss.str().c_str(), CONTINUE); - return (NULL); - } - if (elt_ptr->master->type != SURF) - continue; - master_ptr = elt_ptr->master; - break; - } - if (master_ptr == NULL) - { - std::ostringstream error_oss; - error_oss << - "Surface formula does not contain a surface master species, " << "\n"; - //this->formula << "\n"; - error_msg(error_oss.str().c_str(), CONTINUE); - } - return (master_ptr); -} -struct conc * Phreeqc:: -cxxNameDouble2conc(const cxxNameDouble * nd) - // for Solutions, not ISolutions - // takes a map of (elt name, moles) - // returns list of conc structures -{ - struct conc *c; - assert(nd->type == cxxNameDouble::ND_ELT_MOLES); - c = (struct conc *) - PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct conc))); - if (c == NULL) - malloc_error(); - int i = 0; - for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) - { - c[i].description = string_hsave(it->first.c_str()); - c[i].moles = it->second; - c[i].input_conc = it->second; - c[i].units = NULL; - c[i].equation_name = NULL; - c[i].phase_si = 0.0; - c[i].n_pe = 0; - c[i].as = NULL; - c[i].gfw = 0.0; - //c[i].skip = 0; - c[i].phase = NULL; - i++; - } - c[i].description = NULL; - return (c); -} - -struct name_coef * Phreeqc:: -cxxNameDouble2name_coef(const cxxNameDouble * nd) - // - // Builds a name_coef structure from instance of cxxNameDouble - // -{ - if (nd == NULL) return NULL; - assert(nd->type == cxxNameDouble::ND_NAME_COEF); - struct name_coef *name_coef_ptr = - (struct name_coef *) PHRQ_malloc((size_t) ((nd->size()) * sizeof(struct name_coef))); - if (name_coef_ptr == NULL) - malloc_error(); - int i = 0; - for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) - { - name_coef_ptr[i].name = string_hsave(it->first.c_str()); - name_coef_ptr[i].coef = it->second; - i++; - } - return (name_coef_ptr); -} - -struct elt_list * Phreeqc:: -cxxNameDouble2elt_list(const cxxNameDouble * nd) - // - // Builds a exch_comp structure from instance of cxxNameDouble - // -{ - if (nd == NULL) return NULL; - assert(nd->type == cxxNameDouble::ND_ELT_MOLES); - struct elt_list *elt_list_ptr = - (struct elt_list *) - PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct elt_list))); - if (elt_list_ptr == NULL) - malloc_error(); - int i = 0; - for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); ++it) - { - elt_list_ptr[i].elt = element_store(it->first.c_str()); - elt_list_ptr[i].coef = it->second; - i++; - } - elt_list_ptr[i].elt = NULL; - elt_list_ptr[i].coef = 0; - return (elt_list_ptr); -} - -struct master_activity * Phreeqc:: -cxxNameDouble2master_activity(const cxxNameDouble * nd) - // - // Builds a list of master_activity structures from instance of cxxNameDouble - // -{ - int i = 0; - assert(nd->type == cxxNameDouble::ND_SPECIES_LA - || nd->type == cxxNameDouble::ND_SPECIES_GAMMA); - struct master_activity *master_activity_ptr = NULL; - switch (nd->type) - { - case cxxNameDouble::ND_SPECIES_LA: - { - master_activity_ptr = - (struct master_activity *) PHRQ_malloc((size_t) ((nd->size() + 1) * sizeof(struct master_activity))); - if (master_activity_ptr == NULL) - malloc_error(); - for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); - it++) - { - master_activity_ptr[i].description = string_hsave(it->first.c_str()); - master_activity_ptr[i].la = it->second; - i++; - } - } - master_activity_ptr[i].description = NULL; - break; - case cxxNameDouble::ND_SPECIES_GAMMA: - { - if (nd->size() > 0) - { - master_activity_ptr = - (struct master_activity *) PHRQ_malloc((size_t) ((nd->size()) * sizeof(struct master_activity))); - if (master_activity_ptr == NULL) - malloc_error(); - for (cxxNameDouble::const_iterator it = nd->begin(); it != nd->end(); - it++) - { - master_activity_ptr[i].description = string_hsave(it->first.c_str()); - master_activity_ptr[i].la = it->second; - i++; - } - } - } - break; - case cxxNameDouble::ND_ELT_MOLES: - case cxxNameDouble::ND_NAME_COEF: - break; - } - return (master_activity_ptr); -} - #include "../StorageBin.h" void Phreeqc:: @@ -5872,11 +3556,7 @@ Use2cxxStorageBin(cxxStorageBin & sb) { //Add everything from use structure to storagebin sb - int n; sb.Get_system().Set_io(sb.Get_io()); - - //struct Use *use_ptr = &use; - //cxxUse *use_ptr = &use; if (use.Get_mix_in()) { cxxMix *entity = Utilities::Rxn_find(Rxn_mix_map, use.Get_n_mix_user()); @@ -5887,11 +3567,10 @@ Use2cxxStorageBin(cxxStorageBin & sb) } else if (use.Get_solution_in()) { - struct solution *struct_entity = solution_bsearch(use.Get_n_solution_user(), &n, FALSE); - if (struct_entity != NULL) + cxxSolution *entity = Utilities::Rxn_find(Rxn_solution_map, use.Get_n_solution_user()); + if (entity != NULL) { - cxxSolution entity(struct_entity, sb.Get_io()); - sb.Set_Solution(use.Get_n_solution_user(), &entity); + sb.Set_Solution(use.Get_n_solution_user(), entity); } } if (use.Get_pp_assemblage_in()) @@ -5907,17 +3586,15 @@ Use2cxxStorageBin(cxxStorageBin & sb) cxxExchange *entity_ptr = Utilities::Rxn_find(Rxn_exchange_map, use.Get_n_exchange_user()); if (entity_ptr != NULL) { - //cxxExchange entity(struct_entity, sb.Get_io()); sb.Set_Exchange(use.Get_n_exchange_user(), entity_ptr); } } if (use.Get_surface_in()) { - struct surface *struct_entity = surface_bsearch(use.Get_n_surface_user(), &n); - if (struct_entity != NULL) + cxxSurface *entity_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + if (entity_ptr != NULL) { - cxxSurface entity(struct_entity, sb.Get_io()); - sb.Set_Surface(use.Get_n_surface_user(), &entity); + sb.Set_Surface(use.Get_n_surface_user(), entity_ptr); } } if (use.Get_gas_phase_in()) @@ -5944,17 +3621,6 @@ Use2cxxStorageBin(cxxStorageBin & sb) sb.Set_Kinetics(use.Get_n_kinetics_user(), entity_ptr); } } -#ifdef SKIP - if (use.Get_kinetics_in()) - { - struct kinetics *struct_entity = kinetics_bsearch(use.Get_n_kinetics_user(), &n); - if (struct_entity != NULL) - { - cxxKinetics entity(struct_entity, sb.Get_io()); - sb.Set_Kinetics(use.Get_n_kinetics_user(), &entity); - } - } -#endif if (use.Get_reaction_in()) { cxxReaction *entity = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); @@ -5988,16 +3654,14 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) // equivalent to old import_phreeqc. // { - int i; - // Solutions - for (i = 0; i < count_solution; i++) { - //sb.getSolutions()[solution[i]->n_user] = cxxSolution(solution[i], sb.Get_io()); - cxxSolution ent(solution[i], sb.Get_io()); - sb.Set_Solution(solution[i]->n_user, ent); + std::map::iterator it; + for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) + { + sb.Set_Solution(it->second.Get_n_user(), &(it->second)); + } } - // Exchangers { std::map::iterator it; @@ -6023,13 +3687,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) sb.Set_Kinetics(it->second.Get_n_user(), &(it->second)); } } -#ifdef SKIP - for (i = 0; i < count_kinetics; i++) - { - cxxKinetics entity(&kinetics[i], sb.Get_io()); - sb.Set_Kinetics(kinetics[i].n_user, &entity ); - } -#endif // PPassemblages { std::map::iterator it; @@ -6047,12 +3704,13 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb) } } // Surfaces - for (i = 0; i < count_surface; i++) { - cxxSurface entity(&surface[i], sb.Get_io()); - sb.Set_Surface(surface[i].n_user, &entity ); + std::map::iterator it; + for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) + { + sb.Set_Surface(it->second.Get_n_user(), &(it->second)); + } } - // Mixes { std::map::iterator it; @@ -6096,16 +3754,14 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) // copy phreeqc reactants numbered n to StorageBin sb // { - int pos; - // Solutions { - solution_bsearch(n, &pos, TRUE); - //sb.getSolutions()[n] = cxxSolution(solution[pos], sb.Get_io()); - cxxSolution ent(solution[pos], sb.Get_io()); - sb.Set_Solution(n, ent); + cxxSolution *entity_ptr = Utilities::Rxn_find(Rxn_solution_map, n); + if (entity_ptr != NULL) + { + sb.Set_Solution(n, entity_ptr); + } } - // Exchangers { cxxExchange *entity_ptr = Utilities::Rxn_find(Rxn_exchange_map, n); @@ -6132,16 +3788,6 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) sb.Set_Kinetics(n, entity_ptr); } } -#ifdef SKIP - { - if (kinetics_bsearch(n, &pos) != NULL) - { - //this->Kinetics[n] = cxxKinetics(&(kinetics[pos]), sb.Get_io()); - cxxKinetics ent(&(kinetics[pos]), sb.Get_io()); - sb.Set_Kinetics(n, &ent ); - } - } -#endif // PPassemblages { cxxPPassemblage *entity_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); @@ -6160,11 +3806,10 @@ phreeqc2cxxStorageBin(cxxStorageBin & sb, int n) } // Surfaces { - if (surface_bsearch(n, &pos) != NULL) + cxxSurface *entity_ptr = Utilities::Rxn_find(Rxn_surface_map, n); + if (entity_ptr != NULL) { - //this->Surfaces[n] = cxxSurface(&(surface[pos]), sb.Get_io()); - cxxSurface ent(&(surface[pos]), sb.Get_io()); - sb.Set_Surface(n, &ent); + sb.Set_Surface(n, entity_ptr); } } } @@ -6180,13 +3825,9 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) std::map < int, cxxSolution >::const_iterator it = sb.Get_Solutions().find(n); if (it != sb.Get_Solutions().end()) { - struct solution *solution_old_ptr = cxxSolution2solution(&(it->second)); - solution_ptr_to_user(solution_old_ptr, it->first); - solution_free(solution_old_ptr); - solution_old_ptr = (struct solution *) free_check_null(solution_old_ptr); + Rxn_solution_map[n] = it->second; } } - // Exchangers { std::map < int, cxxExchange >::const_iterator it = sb.Get_Exchangers().find(n); @@ -6213,18 +3854,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) Rxn_kinetics_map[n] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().find(n); - if (it != sb.Get_Kinetics().end()) - { - struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&(it->second)); - kinetics_ptr_to_user(kinetics_ptr, it->first); - kinetics_free(kinetics_ptr); - kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); - } - } -#endif // PPassemblages { std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().find(n); @@ -6246,13 +3875,9 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb, int n) std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().find(n); if (it != sb.Get_Surfaces().end()) { - struct surface *surface_ptr = cxxSurface2surface(&(it->second)); - surface_ptr_to_user(surface_ptr, it->first); - surface_free(surface_ptr); - surface_ptr = (struct surface *) free_check_null(surface_ptr); + Rxn_surface_map[n] = it->second; } } - // Mixes { std::map < int, cxxMix >::const_iterator it = sb.Get_Mixes().find(n); @@ -6296,17 +3921,12 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) { // Solutions { - std::map < int, cxxSolution >::const_iterator it = sb.Get_Solutions().begin(); - for ( ; it != sb.Get_Solutions().end(); it ++) + for ( ; it != sb.Get_Solutions().end(); it++) { - struct solution *solution_old_ptr = cxxSolution2solution(&(it->second)); - solution_ptr_to_user(solution_old_ptr, it->first); - solution_free(solution_old_ptr); - solution_old_ptr = (struct solution *) free_check_null(solution_old_ptr); + Rxn_solution_map[it->first] = it->second; } } - // Exchangers { std::map < int, cxxExchange >::const_iterator it = sb.Get_Exchangers().begin(); @@ -6333,18 +3953,6 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) Rxn_kinetics_map[it->first] = it->second; } } -#ifdef SKIP - { - std::map < int, cxxKinetics >::const_iterator it = sb.Get_Kinetics().begin(); - for ( ; it != sb.Get_Kinetics().end(); it++) - { - struct kinetics *kinetics_ptr = cxxKinetics2kinetics(&(it->second)); - kinetics_ptr_to_user(kinetics_ptr, it->first); - kinetics_free(kinetics_ptr); - kinetics_ptr = (struct kinetics *) free_check_null(kinetics_ptr); - } - } -#endif // PPassemblages { std::map < int, cxxPPassemblage >::const_iterator it = sb.Get_PPassemblages().begin(); @@ -6366,10 +3974,7 @@ cxxStorageBin2phreeqc(cxxStorageBin & sb) std::map < int, cxxSurface >::const_iterator it = sb.Get_Surfaces().begin(); for ( ; it != sb.Get_Surfaces().end(); it++) { - struct surface *surface_ptr = cxxSurface2surface(&(it->second)); - surface_ptr_to_user(surface_ptr, it->first); - surface_free(surface_ptr); - surface_ptr = (struct surface *) free_check_null(surface_ptr); + Rxn_surface_map[it->first] = it->second; } } // Mixes diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index ccdfb0d8..32de9714 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -8,6 +8,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" /* Calling sequence @@ -111,18 +112,6 @@ get_all_components(void) j++; } } -#ifdef SKIP - output_msg( "List of Components:\n" ); - for (i = 0; i < tally_count_component; i++) - { - output_msg(sformatf( "\t%d\t%s\n", i + 1, buffer[i].name)); - /* - for (j=0; buffer[i].name[j] != '\0'; j++) { - names[i * length + j] = buffer[i].name[j]; - } - */ - } -#endif /* * Return value */ @@ -378,23 +367,13 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) * Routine accumulates elements from all solutions, phases, gas phases, * exchangers, and surfaces. */ - int i, j, k, n; - struct solution *solution_ptr; - //struct irrev *irrev_ptr; - //struct pp_assemblage *pp_assemblage_ptr; - //struct exchange *exchange_ptr; - struct surface *surface_ptr; - //struct ss_assemblage *ss_assemblage_ptr; - //struct gas_phase *gas_phase_ptr; - //struct kinetics *kinetics_ptr; - //struct kinetics_comp *kinetics_comp_ptr; int found; LDBLE moles; char *ptr; /* * Cycle through tally table columns */ - for (i = 0; i < count_tally_table_columns; i++) + for (int i = 0; i < count_tally_table_columns; i++) { switch (tally_table[i].type) { @@ -404,41 +383,44 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) */ if (n_user[Solution] < 0 || n_buffer == 0) break; - if (i == 0) { - solution_ptr = solution_bsearch(index_conservative, &n, TRUE); - } - else if (i == 1) - { - solution_ptr = solution_bsearch(n_user[Solution], &n, TRUE); - } - else - { - solution_ptr = NULL; - error_msg - ("Solution is not in first two columns of tally_table", - STOP); - } - if (solution_ptr == NULL) - break; - xsolution_zero(); - add_solution(solution_ptr, 1.0, 1.0); - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_master; j++) - { - if (master[j]->total > 0.0) + cxxSolution *solution_ptr; + if (i == 0) { - char * temp_name = string_duplicate(master[j]->elt->primary->elt->name); - ptr = temp_name; - get_elts_in_species(&ptr, master[j]->total); - free_check_null(temp_name); + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, index_conservative); } + else if (i == 1) + { + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user[Solution]); + } + else + { + solution_ptr = NULL; + error_msg + ("Solution is not in first two columns of tally_table", + STOP); + } + if (solution_ptr == NULL) + break; + xsolution_zero(); + add_solution(solution_ptr, 1.0, 1.0); + count_elts = 0; + paren_count = 0; + for (int j = 0; j < count_master; j++) + { + if (master[j]->total > 0.0) + { + char * temp_name = string_duplicate(master[j]->elt->primary->elt->name); + ptr = temp_name; + get_elts_in_species(&ptr, master[j]->total); + free_check_null(temp_name); + } + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; case Reaction: /* @@ -473,10 +455,8 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) break; { cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n_user[Pure_phase]); - //pp_assemblage_ptr = pp_assemblage_bsearch(n_user[Pure_phase], &n); if (pp_assemblage_ptr == NULL) break; - //for (j = 0; j < pp_assemblage_ptr->count_comps; j++) std::map::iterator it; it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) @@ -504,17 +484,14 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) */ if (n_user[Exchange] < 0) break; - //exchange_ptr = exchange_bsearch(n_user[Exchange], &n); cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, n_user[Exchange]); if (exchange_ptr == NULL) break; count_elts = 0; paren_count = 0; - std::vector comps = exchange_ptr->Vectorize(); - //for (j = 0; j < exchange_ptr->count_comps; j++) - for (j = 0; j < (int) comps.size(); j++) + for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - add_elt_list(comps[j]->Get_totals(), 1.0); + add_elt_list(exchange_ptr->Get_exchange_comps()[j].Get_totals(), 1.0); } qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); @@ -528,19 +505,21 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) */ if (n_user[Surface] < 0) break; - surface_ptr = surface_bsearch(n_user[Surface], &n); - if (surface_ptr == NULL) - break; - count_elts = 0; - paren_count = 0; - for (j = 0; j < surface_ptr->count_comps; j++) { - add_elt_list(surface_ptr->comps[j].totals, 1.0); + cxxSurface * surface_ptr = Utilities::Rxn_find(Rxn_surface_map, n_user[Surface]); + if (surface_ptr == NULL) + break; + count_elts = 0; + paren_count = 0; + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) + { + add_elt_list(surface_ptr->Get_surface_comps()[j].Get_totals(), 1.0); + } + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + elt_list_to_tally_table(tally_table[i].total[n_buffer]); } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - elt_list_to_tally_table(tally_table[i].total[n_buffer]); break; case Ss_phase: if (n_user[Ss_phase] < 0) @@ -556,12 +535,12 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) found = FALSE; moles = 0.0; std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); - for (j = 0; j < (int) ss_ptrs.size(); j++) - //for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) + for (size_t j = 0; j < ss_ptrs.size(); j++) { cxxSS * ss_ptr = ss_ptrs[j]; cxxSScomp * comp_ptr; - for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + size_t k; + for (k = 0; k < ss_ptr->Get_ss_comps().size(); k++) { comp_ptr = &(ss_ptr->Get_ss_comps()[k]); int l; @@ -571,7 +550,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) if (strcmp_nocase(phase_ptr->name, tally_table[i].name) == 0) break; } - if (k < (int) ss_ptr->Get_ss_comps().size()) + if (k < ss_ptr->Get_ss_comps().size()) { moles = comp_ptr->Get_moles(); found = TRUE; @@ -593,7 +572,6 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) if (n_user[Gas_phase] < 0) break; { - //gas_phase_ptr = gas_phase_bsearch(n_user[Gas_phase], &n); cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, n_user[Gas_phase]); if (gas_phase_ptr == NULL) break; @@ -602,6 +580,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) const std::vector *gc = &(gas_phase_ptr->Get_gas_comps()); for (size_t l = 0; l < gc->size(); l++) { + int k; struct phase *phase_ptr = phase_bsearch((*gc)[l].Get_phase_name().c_str(), &k, FALSE); add_elt_list(phase_ptr->next_elt, @@ -620,12 +599,12 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) */ if (n_user[Kinetics] < 0) break; - //kinetics_ptr = kinetics_bsearch(n_user[Kinetics], &n); cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n_user[Kinetics]); if (kinetics_ptr == NULL) break; cxxKineticsComp * kinetics_comp_ptr = NULL; - for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) + size_t j; + for (j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); if (string_hsave(kinetics_comp_ptr->Get_rate_name().c_str()) == tally_table[i].name) @@ -634,7 +613,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) (kinetics_comp_ptr->Get_rate_name().c_str(), tally_table[i].name) == 0) break; } - if (j >= (int) kinetics_ptr->Get_kinetics_comps().size()) + if (j >= kinetics_ptr->Get_kinetics_comps().size()) break; moles = kinetics_comp_ptr->Get_m(); count_elts = 0; @@ -714,16 +693,7 @@ build_tally_table(void) int count_tt_reaction, count_tt_exchange, count_tt_surface, count_tt_gas_phase; int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; - //struct pp_assemblage *pp_assemblage_ptr; - //struct pure_phase *pure_phase_ptr; - //struct ss_assemblage *ss_assemblage_ptr; - //struct s_s *s_s_ptr; - //struct s_s_comp *s_s_comp_ptr; - //struct kinetics *kinetics_ptr; - //struct kinetics_comp *kinetics_comp_ptr; struct phase *phase_ptr; - - char token[MAX_LENGTH]; char *ptr; /* @@ -755,7 +725,6 @@ build_tally_table(void) /* * add one for reactions */ - //if (count_irrev > 0) if (Rxn_reaction_map.size() > 0) { count_tt_reaction = 1; @@ -786,7 +755,7 @@ build_tally_table(void) /* * add one for surface */ - if (count_surface > 0) + if (Rxn_surface_map.size() > 0) { count_tt_surface = 1; n = count_tally_table_columns; @@ -801,7 +770,6 @@ build_tally_table(void) /* * add one for gases */ - //if (count_gas_phase > 0) if (Rxn_gas_phase_map.size() > 0) { count_tt_gas_phase = 1; @@ -818,17 +786,14 @@ build_tally_table(void) * Count pure phases */ count_tt_pure_phase = 0; - //if (count_pp_assemblage > 0) if (Rxn_pp_assemblage_map.size() > 0) { /* * Go through all pure phases in pure phase assemblages */ - //for (i = 0; i < count_pp_assemblage; i++) std::map::iterator it; for (it = Rxn_pp_assemblage_map.begin(); it != Rxn_pp_assemblage_map.end(); it++) { - //pp_assemblage_ptr = &pp_assemblage[i]; cxxPPassemblage * pp_assemblage_ptr = &(it->second); std::map::iterator jit; jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); @@ -890,15 +855,12 @@ build_tally_table(void) */ std::map::iterator it; for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) - //for (i = 0; i < count_ss_assemblage; i++) { cxxSSassemblage *ss_assemblage_ptr = &(it->second); - //for (j = 0; j < ss_assemblage_ptr->count_s_s; j++) std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); for (j = 0; j < (int) ss_ptrs.size(); j++) { cxxSS * ss_ptr = ss_ptrs[j]; - //for (k = 0; k < s_s_ptr->count_comps; k++) for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); @@ -973,10 +935,8 @@ build_tally_table(void) count_elts = 0; paren_count = 0; phase_ptr = NULL; - //if (kinetics_ptr->comps[j].count_list == 1) if (kinetics_comp_ptr->Get_namecoef().size() == 1) { - //strcpy(token, kinetics_ptr->comps[j].list[0].name); strcpy(token, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str()); phase_ptr = phase_bsearch(token, &p, FALSE); } @@ -987,7 +947,6 @@ build_tally_table(void) else { cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); - //for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) { std::string name = it->first; @@ -1005,70 +964,7 @@ build_tally_table(void) } } } -#ifdef SKIP - if (count_kinetics > 0) - { - for (i = 0; i < count_kinetics; i++) - { - kinetics_ptr = &kinetics[i]; - for (j = 0; j < kinetics_ptr->count_comps; j++) - { - kinetics_comp_ptr = &kinetics_ptr->comps[j]; - /* - * check if already in tally_table - */ - for (l = 1; l < count_tally_table_columns; l++) - { - if (tally_table[l].type == Kinetics && - tally_table[l].name == kinetics_comp_ptr->rate_name) - break; - } - if (l < count_tally_table_columns) - continue; - /* - * Add to table - */ - count_tt_kinetics++; - n = count_tally_table_columns; - extend_tally_table(); - tally_table[n].name = kinetics_comp_ptr->rate_name; - tally_table[n].type = Kinetics; - /* - * get formula for kinetic component - */ - count_elts = 0; - paren_count = 0; - phase_ptr = NULL; - if (kinetics_ptr->comps[j].count_list == 1) - { - strcpy(token, kinetics_ptr->comps[j].list[0].name); - phase_ptr = phase_bsearch(token, &p, FALSE); - } - if (phase_ptr != NULL) - { - add_elt_list(phase_ptr->next_elt, 1.0); - } - else - { - for (k = 0; k < kinetics_ptr->comps[j].count_list; k++) - { - char * temp_name = string_duplicate(kinetics_ptr->comps[j].list[k].name); - ptr = temp_name; - get_elts_in_species(&ptr, - 1.0 * - kinetics_ptr->comps[j].list[k]. - coef); - free_check_null(temp_name); - } - } - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - tally_table[n].formula = elt_list_save(); - } - } - } -#endif + #ifdef SKIP /* * Debug print for table definition @@ -1110,25 +1006,24 @@ add_all_components_tally(void) * Also calculates a number greater than all user numbers and * stores in global variable first_user_number. */ - int i, save_print_use; + int save_print_use; save_print_use = pr.use; pr.use = FALSE; /* * Delete solutions less than -1 */ - while (count_solution > 0 && solution[0]->n_user < -1) - { - i = solution[0]->n_user; - solution_delete(i); - } + /* * add all solutions */ xsolution_zero(); - for (i = 0; i < count_solution; i++) { - add_solution(solution[i], 1.0 / solution[i]->mass_water, 1.0); + std::map::iterator it = Rxn_solution_map.begin(); + for (; it != Rxn_solution_map.end(); it++) + { + add_solution(&it->second, 1.0 / it->second.Get_mass_water(), 1.0); + } } /* * add all irrev reactions @@ -1163,9 +1058,12 @@ add_all_components_tally(void) /* * Surfaces */ - for (i = 0; i < count_surface; i++) { - add_surface(&surface[i]); + std::map::iterator it = Rxn_surface_map.begin(); + for (; it != Rxn_surface_map.end(); it++) + { + add_surface(&it->second); + } } /* * Gases @@ -1180,10 +1078,12 @@ add_all_components_tally(void) /* * Add solid-solution pure phases */ - std::map::iterator it; - for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) { - add_ss_assemblage(&(it->second)); + std::map::iterator it; + for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + { + add_ss_assemblage(&(it->second)); + } } /* * Add elements in kinetic reactions @@ -1196,13 +1096,6 @@ add_all_components_tally(void) add_kinetics(&(it->second)); } } -#ifdef SKIP - for (i = 0; i < count_kinetics; i++) - { - calc_dummy_kinetic_reaction_tally(&kinetics[i]); - add_kinetics(&kinetics[i]); - } -#endif /* * reset pr.use */ @@ -1218,14 +1111,12 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr) * Go through kinetic components and add positive amount of each reactant */ LDBLE coef; - //char token[MAX_LENGTH]; char *ptr; struct phase *phase_ptr; /* * Go through list and generate list of elements and * coefficient of elements in reaction */ - //free_check_null(kinetics_ptr->totals); kinetics_ptr->Get_totals().clear(); count_elts = 0; paren_count = 0; @@ -1259,68 +1150,11 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr) free_check_null(temp_name); } } - } - //kinetics_ptr->totals = elt_list_save(); kinetics_ptr->Set_totals(elt_list_NameDouble()); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Go through kinetic components and add positive amount of each reactant - */ - int i, j; - LDBLE coef; - char token[MAX_LENGTH]; - char *ptr; - struct phase *phase_ptr; -/* - * Go through list and generate list of elements and - * coefficient of elements in reaction - */ - //free_check_null(kinetics_ptr->totals); - kinetics_ptr->Get_totals().clear(); - count_elts = 0; - paren_count = 0; - for (i = 0; i < kinetics_ptr->count_comps; i++) - { - coef = 1.0; -/* - * Reactant is a pure phase, copy formula into token - */ - phase_ptr = NULL; - if (kinetics_ptr->comps[i].count_list == 1) - { - strcpy(token, kinetics_ptr->comps[i].list[0].name); - phase_ptr = phase_bsearch(token, &j, FALSE); - } - if (phase_ptr != NULL) - { - add_elt_list(phase_ptr->next_elt, coef); - } - else - { - for (j = 0; j < kinetics_ptr->comps[i].count_list; j++) - { - char * temp_name = string_duplicate(kinetics_ptr->comps[i].list[j].name); - ptr = temp_name; - get_elts_in_species(&ptr, coef); - free_check_null(temp_name); - } - } - - } - kinetics_ptr->totals = elt_list_save(); - - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: extend_tally_table(void) @@ -1405,20 +1239,4 @@ set_kinetics_time(int n_user, LDBLE step) kinetics_ptr->Set_equalIncrements(false); return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -set_kinetics_time(int n_user, LDBLE step) -/* ---------------------------------------------------------------------- */ -{ - int n; - struct kinetics *kinetics_ptr; - kinetics_ptr = kinetics_bsearch(n_user, &n); - if (kinetics_ptr == NULL) - return (ERROR); - kinetics_ptr->steps[0] = step; - kinetics_ptr->count_steps = 1; - return (OK); -} -#endif \ No newline at end of file diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 2dfe21f4..c5b5682c 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -6,6 +6,8 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" + #define ZERO_TOL 1.0e-30 /* ---------------------------------------------------------------------- */ @@ -160,12 +162,6 @@ tidy_model(void) } -/* surfaces */ - if (new_surface) - { - surface_sort(); - } - /* reset Peng-Robinson parms... */ for (i = 0; i < count_phases; i++) { @@ -173,13 +169,7 @@ tidy_model(void) phases[i]->pr_p = 0.0; phases[i]->pr_phi = 1.0; } -#ifdef SKIP -/* kinetics */ - if (new_kinetics) - { - kinetics_sort(); - } -#endif + /* named_log_k */ if (new_named_logk) { @@ -893,14 +883,12 @@ tidy_gas_phase(void) /* ---------------------------------------------------------------------- */ { int n_user, last; - //struct phase *phase_ptr, **phase_ptrs; LDBLE P, V_m; bool PR; /* * Find all gases for each gas_phase in phase list */ std::map::iterator it = Rxn_gas_phase_map.begin(); - //for (i = 0; i < count_gas_phase; i++) for ( ; it != Rxn_gas_phase_map.end(); it++) { cxxGasPhase *gas_phase_ptr = &(it->second); @@ -909,7 +897,6 @@ tidy_gas_phase(void) gas_phase_ptr->Set_new_def(false); PR = false; P = 0.0; - //n_g = 0; std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gc.size(); j++) { @@ -926,7 +913,6 @@ tidy_gas_phase(void) } else { - //gas_phase[i].comps[j].phase = phase_ptr; if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) PR = true; } @@ -988,15 +974,11 @@ tidy_gas_phase(void) } } gas_phase_ptr->Set_gas_comps(gc); - //gas_phase[i].pr_in = PR; gas_phase_ptr->Set_pr_in(PR); if (PR && P > 0) { std::vector phase_ptrs; - //phase_ptrs = new phase *[gas_phase[i].count_comps]; - //for (j = 0; j < gas_phase[i].count_comps; j++) - //std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { int k; @@ -1005,15 +987,10 @@ tidy_gas_phase(void) continue; phase_ptr->moles_x = gc[j].Get_p_read() / P; phase_ptrs.push_back(phase_ptr); - //phase_ptrs[n_g] = gas_phase[i].comps[j].phase; - //n_g++; } V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); gas_phase_ptr->Set_v_m(V_m); gas_phase_ptr->Set_total_p(P); - //V_m = 1.0; - //for (j = 0; j < gas_phase[i].count_comps; j++) - //{ std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { @@ -1030,7 +1007,6 @@ tidy_gas_phase(void) } } gas_phase_ptr->Set_gas_comps(gc); - //delete phase_ptrs; } /* * Duplicate gas phase, only if not solution equilibria @@ -1042,7 +1018,6 @@ tidy_gas_phase(void) gas_phase_ptr->Set_n_user_end(n_user); for (int j = n_user + 1; j <= last; j++) { - //gas_phase_duplicate(n_user, j); Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); } } @@ -1520,8 +1495,6 @@ int Phreeqc:: tidy_pp_assemblage(void) /* ---------------------------------------------------------------------- */ { - //int i, j, k, l, n_user, first, last; - //struct phase *phase_ptr; LDBLE coef; char *ptr; /* @@ -1553,9 +1526,7 @@ tidy_pp_assemblage(void) } else { - //pp_assemblage[i].pure_phases[j].phase = phase_ptr; add_elt_list(phase_ptr->next_elt, coef); - } if (it->second.Get_add_formula().size() > 0) { @@ -1563,7 +1534,6 @@ tidy_pp_assemblage(void) phase_ptr = phase_bsearch(it->second.Get_add_formula().c_str(), &k, FALSE); if (phase_ptr != NULL) { - //pp_assemblage[i].pure_phases[j].add_formula = phase_ptr->formula; it->second.Set_add_formula(phase_ptr->formula); } { @@ -1644,7 +1614,6 @@ tidy_ss_assemblage(void) } else { - //ss_assemblage[i].s_s[j].comps[k].phase = phase_ptr; phase_ptr->moles_x = 0; phase_ptr->fraction_x = 0; } @@ -1701,7 +1670,6 @@ tidy_ss_assemblage(void) { ss_ptr->Set_dn(1.0 / n_tot); nc = ss_ptr->Get_ss_comps()[0].Get_moles(); - //nc = ss_assemblage[i].s_s[j].comps[0].moles; if (nc == 0) nc = MIN_TOTAL_SS; nb = ss_ptr->Get_ss_comps()[1].Get_moles(); @@ -1712,11 +1680,7 @@ tidy_ss_assemblage(void) /* lambdas */ ss_ptr->Get_ss_comps()[0].Set_log10_lambda(xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10); - //ss_assemblage[i].s_s[j].comps[0].log10_lambda = - // xb * xb * (l_a0 - l_a1 * (3 - 4 * xb)) / LOG_10; ss_ptr->Get_ss_comps()[1].Set_log10_lambda(xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10); - //ss_assemblage[i].s_s[j].comps[1].log10_lambda = - // xc * xc * (l_a0 + l_a1 * (4 * xb - 1)) / LOG_10; /* derivatives wrt nc and nb */ xc2 = xc * xc; @@ -1733,15 +1697,11 @@ tidy_ss_assemblage(void) 2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + 6 * l_a1 * xc * xb2 + 1; ss_ptr->Get_ss_comps()[0].Set_dnb(dnb / n_tot); - //ss_assemblage[i].s_s[j].comps[0].dnb = dnb / n_tot; dnc = 2 * l_a0 * xb3 + 2 * l_a0 * xc * xb2 + 8 * l_a1 * xb4 + 8 * l_a1 * xc * xb3 - 2 * l_a1 * xb3 - 6 * l_a1 * xc * xb2; ss_ptr->Get_ss_comps()[0].Set_dnc(-xb / nc + dnc / n_tot); - //ss_assemblage[i].s_s[j].comps[0].dnc = - // -xb / nc + dnc / n_tot; ss_ptr->Get_ss_comps()[0].Set_dn(1.0 / n_tot); - //ss_assemblage[i].s_s[j].comps[0].dn = 1.0 / n_tot; /* component 2 */ dnb = @@ -1749,19 +1709,13 @@ tidy_ss_assemblage(void) 8 * l_a1 * xb2 * xc2 + 8 * l_a1 * xb * xc3 - 2 * l_a1 * xb * xc2 - 6 * l_a1 * xc3; ss_ptr->Get_ss_comps()[1].Set_dnb(-xc / nb + dnb / n_tot); - //ss_assemblage[i].s_s[j].comps[1].dnb = - // -xc / nb + dnb / n_tot; dnc = -2 * l_a0 * xc * xb2 - 8 * l_a1 * xc * xb3 + 2 * l_a1 * xc * xb2 - 2 * l_a0 * xb * xc2 - 8 * l_a1 * xb2 * xc2 + 6 * l_a1 * xb * xc2 + 1; ss_ptr->Get_ss_comps()[1].Set_dnc(dnc / n_tot); - //ss_assemblage[i].s_s[j].comps[1].dnc = dnc / n_tot; ss_prep(ss_ptr->Get_tk(), ss_ptr, TRUE); - //s_s_prep(ss_assemblage[i].s_s[j].tk, - // &(ss_assemblage[i].s_s[j]), TRUE); ss_ptr->Get_ss_comps()[1].Set_dn(1.0 / n_tot); - //ss_assemblage[i].s_s[j].comps[1].dn = 1.0 / n_tot; /* * Ideal solid solution */ @@ -1769,29 +1723,20 @@ tidy_ss_assemblage(void) else { ss_ptr->Set_dn(1.0 / n_tot); - //ss_assemblage[i].s_s[j].dn = 1.0 / n_tot; for (size_t k = 0; k < ss_ptr->Get_ss_comps().size(); k++) - //for (k = 0; k < s_s_ptr->count_comps; k++) { cxxSScomp * comp_ptr = &(ss_ptr->Get_ss_comps()[k]); comp_ptr->Set_log10_lambda(0); - //ss_assemblage[i].s_s[j].comps[k].log10_lambda = 0; moles = comp_ptr->Get_moles(); - //moles = ss_assemblage[i].s_s[j].comps[k].moles; if (moles <= 0.0) moles = MIN_TOTAL_SS; comp_ptr->Set_dnb((n_tot - moles) / (moles * n_tot)); - //ss_assemblage[i].s_s[j].comps[k].dnb = - // (n_tot - moles) / (moles * n_tot); comp_ptr->Set_dn(1.0 / n_tot); - //ss_assemblage[i].s_s[j].comps[k].dn = 1.0 / n_tot; } } } } ss_assemblage_ptr->Set_new_def(false); - //ss_assemblage[i].new_def = FALSE; - /* * Duplicate ss_assemblage if necessary */ @@ -2368,7 +2313,6 @@ tidy_species(void) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_surface(void) @@ -2378,83 +2322,81 @@ tidy_surface(void) * After all of data are read, fill in master species for surface comps * Sort surface */ - int i, j, k; char *ptr1; - struct surface *surface_ptr; - struct master *master_ptr; - - for (k = 0; k < count_surface; k++) + cxxSurface *surface_ptr; + std::map::iterator kit; + for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) { - surface_ptr = &surface[k]; - - for (i = 0; i < surface_ptr->count_comps; i++) + surface_ptr = &(kit->second); + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); /* * Find master species for each surface */ - for (j = 0; surface_ptr->comps[i].totals[j].elt != NULL; j++) + cxxNameDouble::iterator jit = comp_ptr->Get_totals().begin(); + for ( ; jit != comp_ptr->Get_totals().end(); jit++ ) { - master_ptr = surface_ptr->comps[i].totals[j].elt->master; + struct element *elt_ptr = element_store(jit->first.c_str()); + struct master *master_ptr = elt_ptr->master; if (master_ptr == NULL) { input_error++; error_string = sformatf( "Master species not in data base for %s, " "skipping element.", - surface_ptr->comps[i].totals[j].elt->name); + elt_ptr->name); error_msg(error_string, CONTINUE); continue; } if (master_ptr->type != SURF) continue; + comp_ptr->Set_master_element(elt_ptr->name); /* * Set flags */ - surface_ptr->comps[i].master = master_ptr; + cxxSurfaceCharge *charge_ptr = surface_ptr->Find_charge(comp_ptr->Get_charge_name()); /* * Calculate moles of sites */ - if (surface_ptr->new_def == TRUE - && surface_ptr->sites_units == SITES_DENSITY - && surface_ptr->comps[i].phase_name == NULL) + if (surface_ptr->Get_new_def() + && surface_ptr->Get_sites_units() == cxxSurface::SITES_DENSITY + && comp_ptr->Get_phase_name().size() == 0) { - surface_ptr->comps[i].moles = - surface_ptr->comps[i].moles * 1.0e18 * - surface_ptr->charge[surface_ptr->comps[i].charge]. - specific_area * - surface_ptr->charge[surface_ptr->comps[i].charge]. - grams / AVOGADRO; + if (charge_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Surface type is incompatible with site units for %s.", + comp_ptr->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + comp_ptr->Set_moles( + comp_ptr->Get_moles() * 1.0e18 * + charge_ptr->Get_specific_area() * + charge_ptr->Get_grams() / AVOGADRO); /* * Calculate totals */ count_elts = 0; paren_count = 0; { - char * temp_formula = string_duplicate(surface_ptr->comps[i].formula); + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); ptr1 = temp_formula; - get_elts_in_species(&ptr1, surface_ptr->comps[i].moles); + get_elts_in_species(&ptr1, comp_ptr->Get_moles()); free_check_null(temp_formula); } - surface_ptr->comps[i].formula_totals = - (struct elt_list *) free_check_null(surface_ptr-> - comps[i]. - formula_totals); - surface_ptr->comps[i].formula_totals = elt_list_save(); - surface_ptr->comps[i].totals = - (struct elt_list *) free_check_null(surface_ptr-> - comps[i].totals); - surface_ptr->comps[i].totals = elt_list_save(); + { + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); + } } - if (surface_ptr->type == CD_MUSIC) + if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) { - /* - surface_ptr->charge[surface_ptr->comps[i].charge].charge_balance += surface_ptr->comps[i].moles*surface_ptr->comps[i].master->s->z; - */ - surface_ptr->charge[surface_ptr->comps[i].charge]. - charge_balance += - surface_ptr->comps[i].moles * - surface_ptr->comps[i].formula_z; - + charge_ptr->Set_charge_balance(charge_ptr->Get_charge_balance() + + comp_ptr->Get_moles() * + comp_ptr->Get_formula_z()); } break; } @@ -2473,30 +2415,35 @@ tidy_surface(void) /* * Check that all surface comps have a corresponding master */ - for (i = 0; i < surface_ptr->count_comps; i++) + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { - if (surface_ptr->comps[i].master == NULL) + if (surface_ptr->Get_surface_comps()[i].Get_master_element().size() == 0) { input_error++; error_string = sformatf( "No surface master species for surface component %s, ", - surface_ptr->comps[i].formula); + surface_ptr->Get_surface_comps()[i].Get_formula().c_str()); error_msg(error_string, CONTINUE); } } /* * Sort components */ - if (get_input_errors() == 0) + std::map comp_map; + for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { - qsort(surface[k].comps, - (size_t) surface_ptr->count_comps, - (size_t) sizeof(struct surface_comp), surface_comp_compare); + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); + comp_map[comp_ptr->Get_formula()] = *comp_ptr; + } + std::map::iterator it = comp_map.begin(); + surface_ptr->Get_surface_comps().clear(); + for ( ; it != comp_map.end(); it++) + { + surface_ptr->Get_surface_comps().push_back(it->second); } } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_solutions(void) @@ -2506,110 +2453,79 @@ tidy_solutions(void) * Define n_user for any solutions read by solution_spread that * don't have n_user defined */ - int i, l, n, last; - struct conc *tot_ptr; - char *ptr; struct master *master_ptr; - char token[MAX_LENGTH]; - for (n = 0; n < count_solution; n++) + + /* + * Calculate solution numbers + */ + if (unnumbered_solutions.size() > 0) { - /* - * Check that elements are in database - */ - if (solution[n] != NULL && solution[n]->new_def == TRUE) + int last = 0; + std::map::iterator jit; + for (jit = Rxn_solution_map.begin(); jit != Rxn_solution_map.end(); jit++) { - /* - * Sort totals by description - */ - i = 0; - while (solution[n]->totals[i].description != NULL) - i++; - qsort(solution[n]->totals, - (size_t) i, (size_t) sizeof(struct conc), conc_compare); - /* - * sort isotopes - */ - if (solution[n]->count_isotopes > 0) + if (jit->second.Get_n_user() > last) + last = jit->second.Get_n_user(); + if (jit->second.Get_n_user_end() > last) + last = jit->second.Get_n_user_end(); + } + if (save.solution == TRUE) + { + if (save.n_solution_user > last) + last = save.n_solution_user; + if (save.n_solution_user_end > last) + last = save.n_solution_user_end; + } + // put unnumbered solutions in map + for (size_t i = 0; i < unnumbered_solutions.size(); i++) + { + unnumbered_solutions[i].Set_n_user_both(++last); + Rxn_solution_map[last] = unnumbered_solutions[i]; + } + unnumbered_solutions.clear(); + } + /* + * Check that elements are in database + */ + std::map::iterator it; + for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) + { + cxxSolution &solution_ref = it->second; + if (solution_ref.Get_new_def()) + { + cxxISolution *initial_data_ptr = solution_ref.Get_initial_data(); + std::map::iterator iit = initial_data_ptr->Get_comps().begin(); + for ( ; iit != initial_data_ptr->Get_comps().end(); iit++) { - qsort(solution[n]->isotopes, - (size_t) solution[n]->count_isotopes, - (size_t) sizeof(struct isotope), isotope_compare); - } - else - { - solution[n]->isotopes = - (struct isotope *) free_check_null(solution[n]->isotopes); - } - for (i = 0; solution[n]->totals[i].description != NULL; i++) - { - tot_ptr = &(solution[n]->totals[i]); - if (strcmp(tot_ptr->description, "H(1)") == 0 || - strcmp(tot_ptr->description, "E") == 0) + cxxISolutionComp &comp_ref = iit->second; + if (strcmp(comp_ref.Get_description().c_str(), "H(1)") == 0 || + strcmp(comp_ref.Get_description().c_str(), "E") == 0) { - tot_ptr->moles = 0.0; + comp_ref.Set_moles(0.0); continue; } - { - char * temp_desc = string_duplicate(tot_ptr->description); - ptr = temp_desc; - copy_token(token, &ptr, &l); - free_check_null(temp_desc); - } - master_ptr = master_bsearch(token); + std::string token; + std::string description = comp_ref.Get_description(); + std::string::iterator b = description.begin(); + std::string::iterator e = description.end(); + CParser::copy_token(token, b, e); + + master_ptr = master_bsearch(token.c_str()); if (master_ptr == NULL) { error_string = sformatf( "Could not find element in database, %s.\n\tConcentration is set to zero.", - tot_ptr->description); + comp_ref.Get_description().c_str()); warning_msg(error_string); - tot_ptr->input_conc = 0.0; + comp_ref.Set_input_conc(0.0); continue; } } } } - /* - * Calculate solution numbers - */ - for (n = 0; n < count_solution; n++) - { - if (solution[n] != NULL && solution[n]->new_def == TRUE - && solution[n]->n_user < 0) - { - last = 0; - for (i = 0; i < count_solution; i++) - { - if (solution[i]->n_user > last) - last = solution[i]->n_user; - if (solution[i]->n_user_end > last) - last = solution[i]->n_user_end; - } - if (save.solution == TRUE) - { - if (save.n_solution_user > last) - last = save.n_solution_user; - if (save.n_solution_user_end > last) - last = save.n_solution_user_end; - } - for (i = 0; i < count_solution; i++) - { - if (solution[i]->new_def == TRUE && solution[i]->n_user < 0) - { - solution[i]->n_user = ++last; - solution[i]->n_user_end = last; - if (use.Get_solution_in() && (use.Get_n_solution_user() == -1)) - { - use.Set_n_solution_user(last); - } - } - } - break; - } - } - solution_sort(); + return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: species_rxn_to_trxn(struct species *s_ptr) @@ -2680,7 +2596,6 @@ phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_isotopes(void) @@ -2689,70 +2604,52 @@ tidy_isotopes(void) /* * Isotope ratios for each element or element valence state */ - int i, j, k, l, n; - int count_isotopes, primary_number, count_primary; LDBLE isotope_number; struct master *master_ptr, *primary_ptr; - struct solution *solution_ptr; - struct isotope *new_isotopes; - struct isotope *primary_isotopes; - char token[MAX_LENGTH]; - primary_number = 0; + int primary_number = 0; primary_ptr = NULL; - for (n = 0; n < count_solution; n++) + std::map::iterator it; + for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) { - if (solution[n]->new_def != TRUE) + std::map new_isotopes; + cxxSolution &solution_ref = it->second; + if (!solution_ref.Get_new_def()) continue; - if (solution[n]->count_isotopes == 0) + if (solution_ref.Get_isotopes().size() == 0) continue; - solution_ptr = solution[n]; - primary_isotopes = - (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); - if (primary_isotopes == NULL) - malloc_error(); - count_primary = 0; - new_isotopes = - (struct isotope *) PHRQ_malloc((size_t) (sizeof(struct isotope))); - if (new_isotopes == NULL) - malloc_error(); - count_isotopes = 0; + + std::map primary_isotopes; /* * Make list of primary master species for isotopes */ - for (i = 0; i < solution_ptr->count_isotopes; i++) + std::map < std::string, cxxSolutionIsotope >::iterator kit = solution_ref.Get_isotopes().begin(); + for ( ; kit != solution_ref.Get_isotopes().end(); kit++) { - master_ptr = - master_bsearch_primary(solution_ptr->isotopes[i].elt_name); - isotope_number = solution_ptr->isotopes[i].isotope_number; + cxxSolutionIsotope &isotope_ref = kit->second; + master_ptr = master_bsearch_primary(isotope_ref.Get_elt_name().c_str()); + isotope_number = isotope_ref.Get_isotope_number(); if (master_ptr == NULL) { input_error++; error_string = sformatf( "In isotope calculation: element not defined: %s.", - solution_ptr->isotopes[i].elt_name); + isotope_ref.Get_elt_name().c_str()); error_msg(error_string, CONTINUE); continue; } - for (j = 0; j < count_primary; j++) + std::ostringstream iso_name_str; + iso_name_str << (int) isotope_number << master_ptr->elt->name; + + std::map < std::string, cxxSolutionIsotope >::iterator jit; + jit = primary_isotopes.find(iso_name_str.str().c_str()); + if (jit == primary_isotopes.end()) { - if (primary_isotopes[j].master == master_ptr && - primary_isotopes[j].isotope_number == isotope_number) - break; - } - if (j == count_primary) - { - primary_isotopes = - (struct isotope *) PHRQ_realloc(primary_isotopes, - (size_t) (count_primary + - 1) * - sizeof(struct isotope)); - if (primary_isotopes == NULL) - malloc_error(); - primary_isotopes[count_primary].master = master_ptr; - primary_isotopes[count_primary].isotope_number = - isotope_number; - count_primary++; + cxxSolutionIsotope temp_isotope; + temp_isotope.Set_isotope_name(iso_name_str.str().c_str()); + temp_isotope.Set_elt_name(master_ptr->elt->name); + temp_isotope.Set_isotope_number(isotope_number); + primary_isotopes[iso_name_str.str().c_str()] = temp_isotope; } } if (get_input_errors() > 0) @@ -2760,33 +2657,29 @@ tidy_isotopes(void) /* * Go through all redox states of the list of primary species and isotope number */ - for (j = 0; j < count_primary; j++) + for (kit = primary_isotopes.begin(); kit != primary_isotopes.end(); kit++) { - /* find index number of master species, set flag to FALSE */ - master_ptr = primary_isotopes[j].master; - isotope_number = primary_isotopes[j].isotope_number; - for (k = 0; k < count_master; k++) + master_ptr = master_bsearch(kit->second.Get_elt_name().c_str()); + isotope_number = kit->second.Get_isotope_number(); + for (int k = 0; k < count_master; k++) { - if (master[k] == master_ptr) - { - primary_number = k; - primary_ptr = master[k]; - } master[k]->isotope = FALSE; } + primary_number = master_ptr->number; + primary_ptr = master_ptr; /* go through isotopes of solution and fill in master species */ - for (l = 0; l < solution_ptr->count_isotopes; l++) + std::map < std::string, cxxSolutionIsotope >::iterator lit = solution_ref.Get_isotopes().begin(); + for ( ; lit != solution_ref.Get_isotopes().end(); lit++) { - master_ptr = - master_bsearch(solution_ptr->isotopes[l].elt_name); + master_ptr = master_bsearch(lit->second.Get_elt_name().c_str()); if (master_ptr == NULL) { input_error++; error_string = sformatf( "In isotope calculation: element not defined: %s.", - solution_ptr->isotopes[l].elt_name); + lit->second.Get_elt_name().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -2794,45 +2687,38 @@ tidy_isotopes(void) /* only fill for pertinent isotope */ if (master_ptr->elt->primary != primary_ptr) continue; - if (solution_ptr->isotopes[l].isotope_number != - isotope_number) + if (lit->second.Get_isotope_number() != isotope_number) continue; /* for primary, fill in ratio for all secondary species */ - if (master_ptr->primary == TRUE - && master_ptr->s->secondary != NULL) + if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL) { - for (k = primary_number + 1; k < count_master; k++) + for (int k = primary_number + 1; k < count_master; k++) { if (master[k]->elt->primary != primary_ptr) break; - master[k]->isotope_ratio = - solution_ptr->isotopes[l].ratio; - master[k]->isotope_ratio_uncertainty = - solution_ptr->isotopes[l].ratio_uncertainty; + master[k]->isotope_ratio = lit->second.Get_ratio(); + master[k]->isotope_ratio_uncertainty = lit->second.Get_ratio_uncertainty(); if (master[k]->isotope == TRUE) { error_string = sformatf( "In isotope calculation: redefinition of isotope ratio for %s.", - solution_ptr->isotopes[l].elt_name); + lit->second.Get_elt_name().c_str()); error_msg(error_string, CONTINUE); } master[k]->isotope = TRUE; } - - /* for secondary and non redox, set ratio */ } + /* for secondary and non redox, set ratio */ else { - master_ptr->isotope_ratio = - solution_ptr->isotopes[l].ratio; - master_ptr->isotope_ratio_uncertainty = - solution_ptr->isotopes[l].ratio_uncertainty; + master_ptr->isotope_ratio = lit->second.Get_ratio(); + master_ptr->isotope_ratio_uncertainty = lit->second.Get_ratio_uncertainty(); if (master_ptr->isotope == TRUE) { error_string = sformatf( "In isotope calculation: redefinition of isotope ratio for %s.", - solution_ptr->isotopes[l].elt_name); + lit->second.Get_elt_name().c_str()); error_msg(error_string, CONTINUE); } master_ptr->isotope = TRUE; @@ -2841,14 +2727,12 @@ tidy_isotopes(void) /* * Write new isotope structure */ - for (k = 0; k < count_master; k++) + for (int k = 0; k < count_master; k++) { /* skip primary master species of redox elements */ - if (master[k]->primary == TRUE - && master[k]->s->secondary != NULL) + if (master[k]->primary == TRUE && master[k]->s->secondary != NULL) continue; - if (master[k]->elt->primary == primary_ptr - && master[k]->isotope == FALSE) + if (master[k]->elt->primary == primary_ptr && master[k]->isotope == FALSE) { input_error++; error_string = sformatf( @@ -2861,38 +2745,23 @@ tidy_isotopes(void) } if (master[k]->isotope == FALSE) continue; - new_isotopes = - (struct isotope *) PHRQ_realloc(new_isotopes, - (size_t) (count_isotopes - + - 1) * - sizeof(struct isotope)); - if (new_isotopes == NULL) - malloc_error(); - new_isotopes[count_isotopes].master = master[k]; - new_isotopes[count_isotopes].primary = primary_ptr; - new_isotopes[count_isotopes].isotope_number = isotope_number; - new_isotopes[count_isotopes].elt_name = master[k]->elt->name; - new_isotopes[count_isotopes].total = 0; - new_isotopes[count_isotopes].ratio = master[k]->isotope_ratio; - new_isotopes[count_isotopes].ratio_uncertainty = - master[k]->isotope_ratio_uncertainty; - sprintf(token, "%d%s", (int) isotope_number, + cxxSolutionIsotope temp_iso; + temp_iso.Set_isotope_number(isotope_number); + temp_iso.Set_elt_name(master[k]->elt->name); + temp_iso.Set_total(0); + temp_iso.Set_ratio(master[k]->isotope_ratio); + temp_iso.Set_ratio_uncertainty(master[k]->isotope_ratio_uncertainty); + if (master[k]->isotope_ratio_uncertainty != NAN) + { + temp_iso.Set_ratio_uncertainty_defined(true); + } + std::string token = sformatf("%d%s", (int) isotope_number, master[k]->elt->name); - new_isotopes[count_isotopes].isotope_name = - string_hsave(token); - count_isotopes++; + temp_iso.Set_isotope_name(token.c_str()); + new_isotopes[token] = temp_iso; } } - primary_isotopes = - (struct isotope *) free_check_null(primary_isotopes); - solution_ptr->isotopes = - (struct isotope *) free_check_null(solution_ptr->isotopes); - solution_ptr->isotopes = new_isotopes; - solution_ptr->count_isotopes = count_isotopes; - qsort(solution_ptr->isotopes, - (size_t) count_isotopes, - (size_t) sizeof(struct isotope), isotope_compare); + solution_ref.Set_isotopes(new_isotopes); } return (OK); @@ -2906,7 +2775,6 @@ tidy_kin_exchange(void) * set in proportion */ { - //int k; cxxKinetics *kinetics_ptr; char *ptr; LDBLE conc; @@ -2919,14 +2787,14 @@ tidy_kin_exchange(void) continue; if (exchange_ptr->Get_n_user() < 0) continue; - std::vector comps = exchange_ptr->Vectorize(); // check elements - for (size_t j = 0; j < comps.size(); j++) + for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - if (comps[j]->Get_rate_name().size() == 0) + cxxExchComp & comp_ref = exchange_ptr->Get_exchange_comps()[j]; + if (comp_ref.Get_rate_name().size() == 0) continue; /* First find exchange master species */ - cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble nd = comp_ref.Get_totals(); cxxNameDouble::iterator kit = nd.begin(); bool found_exchange = false; for (; kit != nd.end(); kit++) @@ -2950,7 +2818,7 @@ tidy_kin_exchange(void) input_error++; error_string = sformatf( "Exchange formula does not contain an exchange master species, %s", - comps[j]->Get_formula().c_str()); + comp_ref.Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -2961,7 +2829,7 @@ tidy_kin_exchange(void) input_error++; error_string = sformatf( "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", - exchange_ptr->Get_n_user(), comps[j]->Get_formula().c_str()); + exchange_ptr->Get_n_user(), comp_ref.Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -2969,7 +2837,7 @@ tidy_kin_exchange(void) for (k = 0; k < kinetics_ptr->Get_kinetics_comps().size(); k++) { if (strcmp_nocase - (comps[j]->Get_rate_name().c_str(), + (comp_ref.Get_rate_name().c_str(), kinetics_ptr->Get_kinetics_comps()[k].Get_rate_name().c_str()) == 0) { break; @@ -2980,26 +2848,26 @@ tidy_kin_exchange(void) input_error++; error_string = sformatf( "Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", - comps[j]->Get_rate_name().c_str(), comps[j]->Get_formula().c_str(), exchange_ptr->Get_n_user()); + comp_ref.Get_rate_name().c_str(), comp_ref.Get_formula().c_str(), exchange_ptr->Get_n_user()); error_msg(error_string, CONTINUE); continue; } /* use database name for phase */ - comps[j]->Set_rate_name(kinetics_ptr->Get_kinetics_comps()[k].Get_rate_name().c_str()); + comp_ref.Set_rate_name(kinetics_ptr->Get_kinetics_comps()[k].Get_rate_name().c_str()); /* make exchanger concentration proportional to mineral ... */ - conc = kinetics_ptr->Get_kinetics_comps()[k].Get_m() * comps[j]->Get_phase_proportion(); + conc = kinetics_ptr->Get_kinetics_comps()[k].Get_m() * comp_ref.Get_phase_proportion(); count_elts = 0; paren_count = 0; { - char * temp_formula = string_duplicate(comps[j]->Get_formula().c_str()); + char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); ptr = temp_formula; get_elts_in_species(&ptr, conc); free_check_null(temp_formula); } - comps[j]->Set_totals(elt_list_NameDouble()); + comp_ref.Set_totals(elt_list_NameDouble()); /* * No check on availability of exchange elements */ @@ -3007,120 +2875,6 @@ tidy_kin_exchange(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_kin_exchange(void) -/* ---------------------------------------------------------------------- */ -/* - * If exchanger is related to mineral, exchanger amount is - * set in proportion - */ -{ - int k; - struct kinetics *kinetics_ptr; - //struct exch_comp *comp_ptr; - //struct master *master_ptr; - char *ptr; - LDBLE conc; - - //for (i = 0; i < count_exchange; i++) - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) - { - cxxExchange * exchange_ptr = &(it->second); - if (!exchange_ptr->Get_new_def()) - continue; - if (exchange_ptr->Get_n_user() < 0) - continue; - std::vector comps = exchange_ptr->Vectorize(); - // check elements - for (size_t j = 0; j < comps.size(); j++) - { - if (comps[j]->Get_rate_name().size() == 0) - continue; - /* First find exchange master species */ - cxxNameDouble nd = comps[j]->Get_totals(); - cxxNameDouble::iterator kit = nd.begin(); - bool found_exchange = false; - for (; kit != nd.end(); kit++) - { - /* Find master species */ - struct element *elt_ptr = element_store(kit->first.c_str()); - if (elt_ptr == NULL || elt_ptr->master == NULL) - { - input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", - elt_ptr->name); - error_msg(error_string, CONTINUE); - continue; - } - if (elt_ptr->master->type == EX) - found_exchange = true;; - } - if (!found_exchange) - { - input_error++; - error_string = sformatf( - "Exchange formula does not contain an exchange master species, %s", - comps[j]->Get_formula().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find associated kinetic reaction ... */ - if ((kinetics_ptr = kinetics_bsearch(exchange_ptr->Get_n_user(), &k)) == NULL) - { - input_error++; - error_string = sformatf( - "Kinetics %d must be defined to use exchange related to kinetic reaction, %s", - exchange_ptr->Get_n_user(), comps[j]->Get_formula().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - for (k = 0; k < kinetics_ptr->count_comps; k++) - { - if (strcmp_nocase - (comps[j]->Get_rate_name().c_str(), - kinetics_ptr->comps[k].rate_name) == 0) - { - break; - } - } - if (k == kinetics_ptr->count_comps) - { - input_error++; - error_string = sformatf( - "Kinetic reaction, %s, related to exchanger, %s, not found in KINETICS %d", - comps[j]->Get_rate_name().c_str(), comps[j]->Get_formula().c_str(), exchange_ptr->Get_n_user()); - error_msg(error_string, CONTINUE); - continue; - } - - /* use database name for phase */ - comps[j]->Set_rate_name(kinetics_ptr->comps[k].rate_name); - - /* make exchanger concentration proportional to mineral ... */ - conc = kinetics_ptr->comps[k].m * comps[j]->Get_phase_proportion(); - - count_elts = 0; - paren_count = 0; - { - char * temp_formula = string_duplicate(comps[j]->Get_formula().c_str()); - ptr = temp_formula; - get_elts_in_species(&ptr, conc); - free_check_null(temp_formula); - } - comps[j]->Set_totals(elt_list_NameDouble()); -/* - * No check on availability of exchange elements - */ - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_min_exchange(void) @@ -3131,13 +2885,9 @@ tidy_min_exchange(void) */ { int n, jj; - //struct pp_assemblage *pp_a_ptr; - //struct exch_comp *comp_ptr; - //struct master *master_ptr; char *ptr; LDBLE conc; - //for (i = 0; i < count_exchange; i++) std::map::iterator it = Rxn_exchange_map.begin(); for ( ; it != Rxn_exchange_map.end(); it++) { @@ -3147,18 +2897,14 @@ tidy_min_exchange(void) if (exchange_ptr->Get_n_user() < 0) continue; n = exchange_ptr->Get_n_user(); - //for (j = 0; j < exchange[i].count_comps; j++) - std::vector comps = exchange_ptr->Vectorize(); // check elements - for (size_t j = 0; j < comps.size(); j++) + for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - cxxExchComp * comp_ptr = comps[j]; - if (comp_ptr->Get_phase_name().size() == 0) + cxxExchComp & comp_ref = exchange_ptr->Get_exchange_comps()[j]; + if (comp_ref.Get_phase_name().size() == 0) continue; - - /* First find exchange master species */ - cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble nd = comp_ref.Get_totals(); cxxNameDouble::iterator kit = nd.begin(); bool found_exchange = false; for (; kit != nd.end(); kit++) @@ -3184,7 +2930,7 @@ tidy_min_exchange(void) input_error++; error_string = sformatf( "Exchange formula does not contain an exchange master species, %s", - comp_ptr->Get_formula().c_str()); + comp_ref.Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -3195,7 +2941,7 @@ tidy_min_exchange(void) input_error++; error_string = sformatf( "Equilibrium_phases %d must be defined to use exchange related to mineral phase, %s", - n, comp_ptr->Get_formula().c_str()); + n, comp_ref.Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -3203,7 +2949,7 @@ tidy_min_exchange(void) jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); for ( ; jit != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); jit++) { - if (strcmp_nocase(comp_ptr->Get_phase_name().c_str(), jit->first.c_str()) == 0) + if (strcmp_nocase(comp_ref.Get_phase_name().c_str(), jit->first.c_str()) == 0) { break; } @@ -3213,32 +2959,32 @@ tidy_min_exchange(void) input_error++; error_string = sformatf( "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", - comp_ptr->Get_phase_name().c_str(), comp_ptr->Get_formula().c_str(), n); + comp_ref.Get_phase_name().c_str(), comp_ref.Get_formula().c_str(), n); error_msg(error_string, CONTINUE); continue; } /* use database name for phase */ - comp_ptr->Set_phase_name(jit->first.c_str()); + comp_ref.Set_phase_name(jit->first.c_str()); /* make exchanger concentration proportional to mineral ... */ - conc = jit->second.Get_moles() * comp_ptr->Get_phase_proportion(); + conc = jit->second.Get_moles() * comp_ref.Get_phase_proportion(); count_elts = 0; paren_count = 0; { - char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); ptr = temp_formula; get_elts_in_species(&ptr, conc); free_check_null(temp_formula); } - comp_ptr->Set_totals(elt_list_NameDouble()); + comp_ref.Set_totals(elt_list_NameDouble()); /* * make sure exchange elements are in phase */ count_elts = 0; paren_count = 0; { - char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str()); ptr = temp_formula; - get_elts_in_species(&ptr, -comp_ptr->Get_phase_proportion()); + get_elts_in_species(&ptr, -comp_ref.Get_phase_proportion()); free_check_null(temp_formula); } int l; @@ -3260,8 +3006,8 @@ tidy_min_exchange(void) input_error++; error_string = sformatf( "Stoichiometry of exchanger, %s * %g mol sites/mol phase,\n\tmust be a subset of the related phase %s, %s.", - comp_ptr->Get_formula().c_str(), - (double) comp_ptr->Get_phase_proportion(), + comp_ref.Get_formula().c_str(), + (double) comp_ref.Get_phase_proportion(), phase_ptr->name, phase_ptr->formula); error_msg(error_string, CONTINUE); @@ -3272,7 +3018,6 @@ tidy_min_exchange(void) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_min_surface(void) @@ -3282,66 +3027,62 @@ tidy_min_surface(void) * set in proportion */ { - int i, j, k, n, jj; - //struct pp_assemblage *pp_a_ptr; - struct surface_comp *comp_ptr; - struct master *master_ptr; - char *ptr; - LDBLE conc; - - for (i = 0; i < count_surface; i++) + std::map::iterator kit; + for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) { - if (surface[i].new_def == FALSE) + cxxSurface *surface_ptr = &(kit->second); + if (!surface_ptr->Get_new_def()) continue; - if (surface[i].n_user < 0) + if (surface_ptr->Get_n_user() < 0) continue; - for (j = 0; j < surface[i].count_comps; j++) + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { - if (surface[i].comps[j].phase_name == NULL) + cxxSurfaceComp *surface_comp_ptr = &(surface_ptr->Get_surface_comps()[j]); + cxxSurfaceCharge *surface_charge_ptr = surface_ptr->Find_charge(surface_comp_ptr->Get_charge_name()); + if (surface_comp_ptr->Get_phase_name().size() == 0) continue; - comp_ptr = &surface[i].comps[j]; - comp_ptr->master = NULL; - n = surface[i].n_user; + int n = surface_ptr->Get_n_user(); /* First find surface master species */ - for (k = 0; comp_ptr->totals[k].elt != NULL; k++) + cxxNameDouble::iterator it; + for (it = surface_comp_ptr->Get_totals().begin(); it != surface_comp_ptr->Get_totals().end(); it++) { /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; + struct element *elt_ptr = element_store(it->first.c_str()); + struct master *master_ptr = elt_ptr->master; if (master_ptr == NULL) { input_error++; error_string = sformatf( "Master species not in data " "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); + elt_ptr->name); error_msg(error_string, CONTINUE); continue; } if (master_ptr->type != SURF) continue; - comp_ptr->master = master_ptr; + surface_comp_ptr->Set_master_element(elt_ptr->name); break; } - if (comp_ptr->master == NULL) + if (surface_comp_ptr->Get_master_element().size() == 0) { input_error++; error_string = sformatf( "Surface formula does not contain a surface master species, %s", - comp_ptr->formula); + surface_comp_ptr->Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } /* Now find the mineral on which surface depends... */ cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, n); - //if ((pp_a_ptr = pp_assemblage_bsearch(n, &k)) == NULL) if (pp_assemblage_ptr == NULL) { input_error++; error_string = sformatf( "Equilibrium_phases %d must be defined to use surface related to mineral phase, %s", - n, comp_ptr->formula); + n, surface_comp_ptr->Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -3349,9 +3090,7 @@ tidy_min_surface(void) jit = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); for ( ; jit != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); jit++) { - //for (k = 0; k < pp_a_ptr->count_comps; k++) - //{ - if (strcmp_nocase(comp_ptr->phase_name, + if (strcmp_nocase(surface_comp_ptr->Get_phase_name().c_str(), jit->first.c_str()) == 0) { break; @@ -3362,7 +3101,7 @@ tidy_min_surface(void) input_error++; error_string = sformatf( "Mineral, %s, related to surface, %s, not found in Equilibrium_Phases %d", - comp_ptr->phase_name, comp_ptr->formula, n); + surface_comp_ptr->Get_phase_name().c_str(), surface_comp_ptr->Get_formula().c_str(), n); error_msg(error_string, CONTINUE); continue; } @@ -3373,34 +3112,33 @@ tidy_min_surface(void) input_error++; error_string = sformatf( "Mineral, %s, related to surface, %s, not found in database.", - jit->first.c_str(), comp_ptr->formula); + jit->first.c_str(), surface_comp_ptr->Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } /* use database name for phase */ - //comp_ptr->phase_name = pp_a_ptr->pure_phases[k].phase->name; - //comp_ptr->phase_name = string_hsave(jit->first.c_str()); - comp_ptr->phase_name = phase_ptr->name; + surface_comp_ptr->Set_phase_name(phase_ptr->name); /* make surface concentration proportional to mineral ... */ - conc = jit->second.Get_moles() * comp_ptr->phase_proportion; + LDBLE conc = jit->second.Get_moles() * surface_comp_ptr->Get_phase_proportion(); #ifdef SKIP_MUSIC comp_ptr->cb = conc * comp_ptr->formula_z; #endif /* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ { - char * temp_formula = string_duplicate(comp_ptr->formula); - ptr = temp_formula; + char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); + char *ptr = temp_formula; count_elts = 0; paren_count = 0; get_elts_in_species(&ptr, conc); free_check_null(temp_formula); } - comp_ptr->totals = - (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); + { + cxxNameDouble nd = elt_list_NameDouble(); + surface_comp_ptr->Set_totals(nd); + } /* area */ - surface[i].charge[comp_ptr->charge].grams = jit->second.Get_moles(); + surface_charge_ptr->Set_grams(jit->second.Get_moles()); /* * make sure surface elements are in phase * logically necessary for mass balance and to avoid negative concentrations when dissolving phase @@ -3409,39 +3147,38 @@ tidy_min_surface(void) paren_count = 0; { char * temp_formula = string_duplicate(phase_ptr->formula); - ptr = temp_formula; + char * ptr = temp_formula; get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } - for (jj = 0; jj < surface[i].count_comps; jj++) + for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) { - if (comp_ptr->charge != surface[i].comps[jj].charge) + cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]); continue; - if (surface[i].type == CD_MUSIC) + if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) { - char * temp_formula = string_duplicate(surface[i].comps[jj].formula); - ptr = temp_formula; + char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str()); + char *ptr = temp_formula; get_elts_in_species(&ptr, - -surface[i].comps[jj]. - phase_proportion); + -comp_jj_ptr->Get_phase_proportion()); free_check_null(temp_formula); } else { - if (surface[i].comps[jj].master->s->z != 0.0) + struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); + if (elt_ptr->master->s->z != 0.0) { input_error++; error_string = sformatf( "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", - surface[i].comps[jj].master->s->name); + elt_ptr->master->s->name); error_msg(error_string, CONTINUE); } { - char * temp_name = string_duplicate(surface[i].comps[jj].master->s->name); - ptr = temp_name; + char * temp_name = string_duplicate(elt_ptr->master->s->name); + char *ptr = temp_name; get_elts_in_species(&ptr, - -surface[i].comps[jj]. - phase_proportion); + -comp_jj_ptr->Get_phase_proportion()); free_check_null(temp_name); } } @@ -3456,21 +3193,22 @@ tidy_min_surface(void) Further, if you precipitate Ca-Mont, make SurfCa, desorb all the Ca, then dissolve the "Ca-Mont", you must remove SurfCa, or you will end up with Ca in solution. H and O are excluded */ - for (jj = 0; jj < count_elts; jj++) + for (int jj = 0; jj < count_elts; jj++) { if (elt_list[jj].elt->primary->s->type != SURF && elt_list[jj].coef < 0 && elt_list[jj].elt->primary->s != s_hplus && elt_list[jj].elt->primary->s != s_h2o) { + struct element *elt_ptr = element_store(surface_comp_ptr->Get_master_element().c_str()); input_error++; error_string = sformatf( "Element %s in sum of surface sites,\n" "\tincluding %s * %g mol sites/mol phase,\n" "\texceeds stoichiometry in the related phase %s, %s.", elt_list[jj].elt->name, - comp_ptr->master->s->name, - (double) comp_ptr->phase_proportion, + elt_ptr->master->s->name, + (double) surface_comp_ptr->Get_phase_proportion(), phase_ptr->name, phase_ptr->formula); error_msg(error_string, CONTINUE); @@ -3490,71 +3228,66 @@ tidy_kin_surface(void) * set in proportion */ { - int i, j, n, jj, l; cxxKinetics *kinetics_ptr; - struct surface_comp *comp_ptr; - struct master *master_ptr; struct phase *phase_ptr; - //char token[MAX_LENGTH]; - char *ptr; - LDBLE conc; struct elt_list *elt_list_kinetics; int count_elts_kinetics; - n = -999; - comp_ptr = NULL; - for (i = 0; i < count_surface; i++) + std::map::iterator it; + for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) { - if (surface[i].new_def == FALSE) + cxxSurface *surface_ptr = &(it->second); + int n = surface_ptr->Get_n_user(); + if (!surface_ptr->Get_new_def()) continue; - if (surface[i].n_user < 0) + if (surface_ptr->Get_n_user() < 0) continue; - for (j = 0; j < surface[i].count_comps; j++) + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { - if (surface[i].comps[j].rate_name == NULL) + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[j]); + if (comp_ptr->Get_rate_name().size() == 0) continue; - comp_ptr = &surface[i].comps[j]; - comp_ptr->master = NULL; - n = surface[i].n_user; + comp_ptr->Set_master_element(""); /* First find surface master species */ int k; - for (k = 0; comp_ptr->totals[k].elt != NULL; k++) + cxxNameDouble::iterator kit; + for (kit = comp_ptr->Get_totals().begin(); kit != comp_ptr->Get_totals().end(); kit++) { /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; + struct element *elt_ptr = element_store(kit->first.c_str()); + struct master *master_ptr = elt_ptr->master; if (master_ptr == NULL) { input_error++; error_string = sformatf( "Master species not in data " "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); + elt_ptr->name); error_msg(error_string, CONTINUE); continue; } if (master_ptr->type != SURF) continue; - comp_ptr->master = master_ptr; + comp_ptr->Set_master_element(elt_ptr->name); break; } - if (comp_ptr->master == NULL) + if (comp_ptr->Get_master_element().size() == 0) { input_error++; error_string = sformatf( "Surface formula does not contain a surface master species, %s", - comp_ptr->formula); + comp_ptr->Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } /* Now find the kinetic reaction on which surface depends... */ - //if ((kinetics_ptr = kinetics_bsearch(n, &k)) == NULL) if ((kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n)) == NULL) { input_error++; error_string = sformatf( "Kinetics %d must be defined to use surface related to kinetic reaction, %s", - n, comp_ptr->formula); + n, comp_ptr->Get_formula().c_str()); error_msg(error_string, CONTINUE); continue; } @@ -3562,7 +3295,7 @@ tidy_kin_surface(void) { cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); if (strcmp_nocase - (comp_ptr->rate_name, + (comp_ptr->Get_rate_name().c_str(), kin_comp_ptr->Get_rate_name().c_str()) == 0) { break; @@ -3573,33 +3306,35 @@ tidy_kin_surface(void) input_error++; error_string = sformatf( "Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", - comp_ptr->rate_name, comp_ptr->formula, n); + comp_ptr->Get_rate_name().c_str(), comp_ptr->Get_formula().c_str(), n); error_msg(error_string, CONTINUE); continue; } cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); /* use database name for phase */ - comp_ptr->rate_name = string_hsave(kin_comp_ptr->Get_rate_name().c_str()); + comp_ptr->Set_rate_name(kin_comp_ptr->Get_rate_name().c_str()); /* make surface concentration proportional to mineral ... */ - conc = kin_comp_ptr->Get_m() * comp_ptr->phase_proportion; + LDBLE conc = kin_comp_ptr->Get_m() * comp_ptr->Get_phase_proportion(); /* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ { - char * temp_formula = string_duplicate(comp_ptr->formula); - ptr = temp_formula; + char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str()); + char *ptr = temp_formula; count_elts = 0; paren_count = 0; get_elts_in_species(&ptr, conc); free_check_null(temp_formula); } - comp_ptr->totals = - (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); + { + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); + } /* area */ - surface[i].charge[comp_ptr->charge].grams = - kin_comp_ptr->Get_m(); + + cxxSurfaceCharge *charge_ptr = surface_ptr->Find_charge(comp_ptr->Get_charge_name()); + charge_ptr->Set_grams(kin_comp_ptr->Get_m()); } /* * check on elements @@ -3607,9 +3342,8 @@ tidy_kin_surface(void) /* Go through each kinetic reaction, add all related surface compositions * check for negative values */ - if (surface[i].related_rate == FALSE) + if (!surface_ptr->Get_related_rate()) continue; - //kinetics_ptr = kinetics_bsearch(n, &k); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n); for (size_t k = 0; k < kinetics_ptr->Get_kinetics_comps().size(); k++) { @@ -3619,12 +3353,12 @@ tidy_kin_surface(void) /* added in kinetics formula */ cxxNameDouble::iterator jit = kin_comp_ptr->Get_namecoef().begin(); - //for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) for (; jit != kin_comp_ptr->Get_namecoef().end(); jit++) { std::string name = jit->first; LDBLE coef = jit->second; phase_ptr = NULL; + int jj; phase_ptr = phase_bsearch(name.c_str(), &jj, FALSE); if (phase_ptr != NULL) { @@ -3633,7 +3367,7 @@ tidy_kin_surface(void) else { char * temp_name = string_duplicate(name.c_str()); - ptr = temp_name; + char * ptr = temp_name; get_elts_in_species(&ptr, coef); free_check_null(temp_name); } @@ -3651,19 +3385,20 @@ tidy_kin_surface(void) /* get surface formulas */ count_elts = 0; paren_count = 0; - for (j = 0; j < surface[i].count_comps; j++) + cxxSurfaceComp *comp_ptr_save = NULL; + for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { - comp_ptr = &surface[i].comps[j]; - if (comp_ptr->rate_name == NULL) + cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[j]); + if (comp_ptr->Get_rate_name().size() == 0) continue; + comp_ptr_save = comp_ptr; if (strcmp_nocase - (comp_ptr->rate_name, + (comp_ptr->Get_rate_name().c_str(), kin_comp_ptr->Get_rate_name().c_str()) == 0) { - char * temp_formula = string_duplicate( comp_ptr->formula); - ptr = temp_formula; - get_elts_in_species(&ptr, - -1 * comp_ptr->phase_proportion); + char * temp_formula = string_duplicate( comp_ptr->Get_formula().c_str()); + char *ptr = temp_formula; + get_elts_in_species(&ptr, -1 * comp_ptr->Get_phase_proportion()); free_check_null(temp_formula); } } @@ -3673,10 +3408,11 @@ tidy_kin_surface(void) (size_t) sizeof(struct elt_list), elt_list_compare); elt_list_combine(); } - for (j = 0; j < count_elts; j++) + for (int j = 0; j < count_elts; j++) { if (elt_list[j].elt->primary->s->type <= H2O) { + int l; for (l = 0; l < count_elts_kinetics; l++) { if (elt_list[j].elt == elt_list_kinetics[l].elt) @@ -3689,9 +3425,9 @@ tidy_kin_surface(void) input_error++; error_string = sformatf( "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", - comp_ptr->formula, - (double) comp_ptr->phase_proportion, - comp_ptr->rate_name, elt_list[j].elt->name); + comp_ptr_save->Get_formula().c_str(), + (double) comp_ptr_save->Get_phase_proportion(), + comp_ptr_save->Get_rate_name().c_str(), elt_list[j].elt->name); error_msg(error_string, CONTINUE); } else if (fabs(elt_list[j].coef) > @@ -3700,9 +3436,9 @@ tidy_kin_surface(void) input_error++; error_string = sformatf( "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", - comp_ptr->formula, - (double) comp_ptr->phase_proportion, - comp_ptr->rate_name, elt_list[j].elt->name); + comp_ptr_save->Get_formula().c_str(), + (double) comp_ptr_save->Get_phase_proportion(), + comp_ptr_save->Get_rate_name().c_str(), elt_list[j].elt->name); error_msg(error_string, CONTINUE); } } @@ -3713,234 +3449,6 @@ tidy_kin_surface(void) } return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_kin_surface(void) -/* ---------------------------------------------------------------------- */ -/* - * If surface is related to mineral, surface amount is - * set in proportion - */ -{ - int i, j, k, n, jj, l; - struct kinetics *kinetics_ptr; - struct surface_comp *comp_ptr; - struct master *master_ptr; - struct phase *phase_ptr; - char token[MAX_LENGTH]; - char *ptr; - LDBLE conc; - struct elt_list *elt_list_kinetics; - int count_elts_kinetics; - - n = -999; - comp_ptr = NULL; - for (i = 0; i < count_surface; i++) - { - if (surface[i].new_def == FALSE) - continue; - if (surface[i].n_user < 0) - continue; - for (j = 0; j < surface[i].count_comps; j++) - { - if (surface[i].comps[j].rate_name == NULL) - continue; - comp_ptr = &surface[i].comps[j]; - comp_ptr->master = NULL; - n = surface[i].n_user; - - /* First find surface master species */ - - for (k = 0; comp_ptr->totals[k].elt != NULL; k++) - { - /* Find master species */ - master_ptr = comp_ptr->totals[k].elt->master; - if (master_ptr == NULL) - { - input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", - comp_ptr->totals[k].elt->name); - error_msg(error_string, CONTINUE); - continue; - } - if (master_ptr->type != SURF) - continue; - comp_ptr->master = master_ptr; - break; - } - if (comp_ptr->master == NULL) - { - input_error++; - error_string = sformatf( - "Surface formula does not contain a surface master species, %s", - comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - - /* Now find the kinetic reaction on which surface depends... */ - if ((kinetics_ptr = kinetics_bsearch(n, &k)) == NULL) - { - input_error++; - error_string = sformatf( - "Kinetics %d must be defined to use surface related to kinetic reaction, %s", - n, comp_ptr->formula); - error_msg(error_string, CONTINUE); - continue; - } - for (k = 0; k < kinetics_ptr->count_comps; k++) - { - if (strcmp_nocase - (comp_ptr->rate_name, - kinetics_ptr->comps[k].rate_name) == 0) - { - break; - } - } - if (k == kinetics_ptr->count_comps) - { - input_error++; - error_string = sformatf( - "Kinetic reaction, %s, related to surface, %s, not found in Kinetics %d", - comp_ptr->rate_name, comp_ptr->formula, n); - error_msg(error_string, CONTINUE); - continue; - } - - /* use database name for phase */ - comp_ptr->rate_name = kinetics_ptr->comps[k].rate_name; - - /* make surface concentration proportional to mineral ... */ - conc = kinetics_ptr->comps[k].m * comp_ptr->phase_proportion; - -/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */ - { - char * temp_formula = string_duplicate(comp_ptr->formula); - ptr = temp_formula; - count_elts = 0; - paren_count = 0; - get_elts_in_species(&ptr, conc); - free_check_null(temp_formula); - } - comp_ptr->totals = - (struct elt_list *) free_check_null(comp_ptr->totals); - comp_ptr->totals = elt_list_save(); - - /* area */ - surface[i].charge[comp_ptr->charge].grams = - kinetics_ptr->comps[k].m; - } -/* - * check on elements - */ - /* Go through each kinetic reaction, add all related surface compositions - * check for negative values - */ - if (surface[i].related_rate == FALSE) - continue; - kinetics_ptr = kinetics_bsearch(n, &k); - for (k = 0; k < kinetics_ptr->count_comps; k++) - { - count_elts = 0; - paren_count = 0; - - /* added in kinetics formula */ - for (j = 0; j < kinetics_ptr->comps[k].count_list; j++) - { - phase_ptr = NULL; - strcpy(token, kinetics_ptr->comps[k].list[j].name); - phase_ptr = phase_bsearch(token, &jj, FALSE); - if (phase_ptr != NULL) - { - add_elt_list(phase_ptr->next_elt, 1.0); - } - else - { - char * temp_name = string_duplicate(kinetics_ptr->comps[k].list[j].name); - ptr = temp_name; - get_elts_in_species(&ptr, - kinetics_ptr->comps[k].list[j].coef); - free_check_null(temp_name); - } - } - /* save kinetics formula */ - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - elt_list_kinetics = elt_list_save(); - count_elts_kinetics = count_elts; - - /* get surface formulas */ - count_elts = 0; - paren_count = 0; - for (j = 0; j < surface[i].count_comps; j++) - { - comp_ptr = &surface[i].comps[j]; - if (comp_ptr->rate_name == NULL) - continue; - if (strcmp_nocase - (comp_ptr->rate_name, - kinetics_ptr->comps[k].rate_name) == 0) - { - char * temp_formula = string_duplicate( comp_ptr->formula); - ptr = temp_formula; - get_elts_in_species(&ptr, - -1 * comp_ptr->phase_proportion); - free_check_null(temp_formula); - } - } - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - for (j = 0; j < count_elts; j++) - { - if (elt_list[j].elt->primary->s->type <= H2O) - { - for (l = 0; l < count_elts_kinetics; l++) - { - if (elt_list[j].elt == elt_list_kinetics[l].elt) - { - break; - } - } - if (l == count_elts_kinetics) - { - input_error++; - error_string = sformatf( - "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tElement %s is not present in reactant formula.", - comp_ptr->formula, - (double) comp_ptr->phase_proportion, - comp_ptr->rate_name, elt_list[j].elt->name); - error_msg(error_string, CONTINUE); - } - else if (fabs(elt_list[j].coef) > - fabs(elt_list_kinetics[l].coef)) - { - input_error++; - error_string = sformatf( - "Stoichiometry of surface, %s * %g mol sites/mol reactant,\n\tmust be a subset of the formula defined for the related reactant %s.\n\tCoefficient of element %s in surface exceeds amount present in reactant formula.", - comp_ptr->formula, - (double) comp_ptr->phase_proportion, - comp_ptr->rate_name, elt_list[j].elt->name); - error_msg(error_string, CONTINUE); - } - } - } - elt_list_kinetics = - (struct elt_list *) free_check_null(elt_list_kinetics); - } - } - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: ss_prep(LDBLE t, cxxSS *ss_ptr, int print) @@ -3973,8 +3481,6 @@ ss_prep(LDBLE t, cxxSS *ss_ptr, int print) struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE); kc = exp(k_calc(phase0_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); kb = exp(k_calc(phase1_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); - //kc = exp(k_calc(ss_ptr->comps[0].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); - //kb = exp(k_calc(ss_ptr->comps[1].phase->rxn->logk, t, REF_PRES_PASCAL) * LOG_10); crit_pt = fabs(a0) + fabs(a1); /* * Default, no miscibility or spinodal gaps @@ -5063,7 +4569,7 @@ reset_last_model(void) last_model.add_formula = (const char **) free_check_null(last_model.add_formula); last_model.si = (LDBLE *) free_check_null(last_model.si); - last_model.dl_type = NO_DL; + last_model.dl_type = cxxSurface::NO_DL; last_model.count_surface_comp = 0; last_model.surface_comp = (const char **) free_check_null(last_model.surface_comp); @@ -5081,11 +4587,6 @@ tidy_exchange(void) * set in proportion */ { - //int i, j, k; - //struct exch_comp *comp_ptr; - //struct master *master_ptr; - - //for (i = 0; i < count_exchange; i++) std::map::iterator it = Rxn_exchange_map.begin(); for ( ; it != Rxn_exchange_map.end(); it++) { @@ -5094,24 +4595,20 @@ tidy_exchange(void) continue; if (exchange_ptr->Get_n_user() < 0) continue; - //for (j = 0; j < exchange[i].count_comps; j++) - std::vector comps = exchange_ptr->Vectorize(); // check elements - for (size_t j = 0; j < comps.size(); j++) + for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { - cxxExchComp * comp_ptr = comps[j]; - if (comp_ptr->Get_phase_name().size() > 0) + cxxExchComp & comp_ref = exchange_ptr->Get_exchange_comps()[j]; + if (comp_ref.Get_phase_name().size() > 0) continue; - if (comp_ptr->Get_rate_name().size() > 0) + if (comp_ref.Get_rate_name().size() > 0) continue; /* Check elements */ - cxxNameDouble nd = comps[j]->Get_totals(); + cxxNameDouble nd = comp_ref.Get_totals(); cxxNameDouble::iterator kit = nd.begin(); for (; kit != nd.end(); kit++) { - /* Find master species */ - //master_ptr = comp_ptr->totals[k].elt->primary; /* Find master species */ struct element *elt_ptr = element_store(kit->first.c_str()); if (elt_ptr == NULL || elt_ptr->master == NULL) diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index 8202c518..df4c43f4 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -6,21 +6,21 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: transport(void) /* ---------------------------------------------------------------------- */ { int i, j, k, n; - int j_imm, n_m, n_imm; + int j_imm; LDBLE b, f, mix_f_m, mix_f_imm; LDBLE water_m, water_imm; int first_c, last_c, b_c; int max_iter; char token[MAX_LENGTH]; LDBLE kin_time, stagkin_time, kin_time_save; - //struct mix *mix_ptr; - struct surface *surf_ptr, *surf_ptr1; + int punch_boolean; LDBLE step_fraction; LDBLE cb_tol; @@ -38,7 +38,7 @@ transport(void) /* check column solutions */ for (i = 1; i <= count_cells; i++) { - use.Set_solution_ptr(solution_bsearch(i, &n, TRUE)); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { input_error++; @@ -48,7 +48,7 @@ transport(void) error_msg(error_string, CONTINUE); } else - cell_data[i - 1].temp = use.Get_solution_ptr()->tc; + cell_data[i - 1].temp = use.Get_solution_ptr()->Get_tc(); } if (multi_Dflag) @@ -70,7 +70,7 @@ transport(void) } } /* check solution 0 */ - if (solution_bsearch(0, &n, FALSE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, 0) == NULL) { if (ishift == 1) { @@ -80,11 +80,11 @@ transport(void) error_msg(error_string, CONTINUE); } else - solution_duplicate(1, 0); + Utilities::Rxn_copy(Rxn_solution_map, 1, 0); } /* check solution count_cells */ - if (solution_bsearch(count_cells + 1, &n, FALSE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, count_cells + 1) == NULL) { if (ishift == -1) { @@ -95,7 +95,7 @@ transport(void) error_msg(error_string, CONTINUE); } else - solution_duplicate(count_cells, count_cells + 1); + Utilities::Rxn_copy(Rxn_solution_map, count_cells, count_cells + 1); } /* * Initialize temperature in stagnant cells ... @@ -105,11 +105,9 @@ transport(void) for (i = 1; i <= count_cells; i++) { k = i + 1 + n * count_cells; - int n_solution; - use.Set_solution_ptr(solution_bsearch(k, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, k)); if (use.Get_solution_ptr() != NULL) - cell_data[k - 1].temp = use.Get_solution_ptr()->tc; + cell_data[k - 1].temp = use.Get_solution_ptr()->Get_tc(); } } /* @@ -125,7 +123,7 @@ transport(void) set_initial_moles(i); cell_no = i; set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->transport == TRUE) + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_transport()) transp_surf = TRUE; if (transp_surf && !multi_Dflag) { @@ -158,11 +156,8 @@ transport(void) { k = i + 1 + n * count_cells; cell_no = k; - int n_solution; - - if (solution_bsearch(k, &n_solution, FALSE) != 0) + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { - //use.Set_n_solution(n_solution); set_initial_moles(k); set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); if (multi_Dflag == TRUE) @@ -259,38 +254,24 @@ transport(void) { j = i; j_imm = j + (1 + count_cells); - if (solution_bsearch(j, &n_m, TRUE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, j) == NULL) error_msg ("Could not find mobile cell solution in TRANSPORT.", STOP); - if (solution_bsearch(j_imm, &n_imm, TRUE) == NULL) + if (Utilities::Rxn_find(Rxn_solution_map, j_imm) == NULL) error_msg ("Could not find immobile cell solution in TRANSPORT.", STOP); - water_m = solution[n_m]->mass_water; - water_imm = solution[n_imm]->mass_water; + water_m = Utilities::Rxn_find(Rxn_solution_map, j)->Get_mass_water(); + water_imm = Utilities::Rxn_find(Rxn_solution_map, j_imm)->Get_mass_water(); /* * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 */ { cxxMix temp_mix; - //mix[n].comps = - // (struct mix_comp *) PHRQ_malloc((size_t) 2 * - // sizeof(struct mix_comp)); - //if (mix[n].comps == NULL) - // malloc_error(); - //mix[n].count_comps = 2; - //mix[n].description = string_duplicate(" "); - //mix[n].n_user = j; - //mix[n].n_user_end = j; temp_mix.Set_n_user(j); temp_mix.Set_n_user_end(j); - - //mix[n].comps[0].n_solution = j; - //mix[n].comps[0].fraction = 1 - mix_f_m; temp_mix.Add(j, 1 - mix_f_m); - //mix[n].comps[1].n_solution = j_imm; - //mix[n].comps[1].fraction = mix_f_m * water_m / water_imm; temp_mix.Add(j_imm, mix_f_m * water_m / water_imm); Rxn_mix_map[j] = temp_mix; n++; @@ -300,23 +281,9 @@ transport(void) */ { cxxMix temp_mix; - //mix[n].comps = - // (struct mix_comp *) PHRQ_malloc((size_t) 2 * - // sizeof(struct mix_comp)); - //if (mix[n].comps == NULL) - // malloc_error(); - //mix[n].count_comps = 2; - //mix[n].description = string_duplicate(" "); - //mix[n].n_user = j_imm; - //mix[n].n_user_end = j_imm; temp_mix.Set_n_user(j_imm); temp_mix.Set_n_user_end(j_imm); - - //mix[n].comps[0].n_solution = j_imm; - //mix[n].comps[0].fraction = 1 - mix_f_imm; temp_mix.Add(j_imm, 1 - mix_f_imm); - //mix[n].comps[1].n_solution = j; - //mix[n].comps[1].fraction = mix_f_imm * water_imm / water_m; temp_mix.Add(j, mix_f_imm * water_imm / water_m); Rxn_mix_map[j_imm] = temp_mix; n++; @@ -353,7 +320,7 @@ transport(void) * Set initial moles of phases */ for (i = 1; i <= count_cells; i++) - set_initial_moles(i); + set_initial_moles(i); /* * Also stagnant cells */ @@ -363,10 +330,8 @@ transport(void) { k = i + 1 + n * count_cells; cell_no = k; - int n_solution; - if (solution_bsearch(k, &n_solution, FALSE) != 0) + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { - //use.Set_n_solution(n_solution); set_initial_moles(k); } } @@ -436,13 +401,10 @@ transport(void) fill_spec(i); /* punch and output file */ - int n_solution; if ((ishift == 0) && (j == nmix) && ((stag_data->count_stag == 0) - || solution_bsearch(i + 1 + count_cells, - &n_solution, FALSE) == 0)) + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { - //use.Set_n_solution(n_solution); if ((cell_data[i - 1].punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); @@ -451,16 +413,14 @@ transport(void) print_all(); } if (i > 1) - solution_duplicate(-2, i - 1); + Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); saver(); /* maybe sorb a surface component... */ if ((ishift == 0) && (j == nmix) && ((stag_data->count_stag == 0) - || solution_bsearch(i + 1 + count_cells, - &n_solution, FALSE) == 0)) + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { - //use.Set_n_solution(n_solution); if (change_surf_count > 0) { for (k = 0; k < change_surf_count; k++) @@ -478,7 +438,7 @@ transport(void) } } } - solution_duplicate(-2, count_cells); + Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each diffusive/dispersive step ... */ @@ -513,7 +473,6 @@ transport(void) rate_sim_time = rate_sim_time_start + kin_time; /* halftime kinetics for resident water in first cell ... */ - //if (kinetics_bsearch(first_c, &i) != NULL && count_cells > 1) if (Utilities::Rxn_find(Rxn_kinetics_map, first_c) != NULL && count_cells > 1) { cell_no = first_c; @@ -525,7 +484,7 @@ transport(void) /* for each cell in column */ for (i = last_c; i != (first_c - ishift); i -= ishift) - solution_duplicate(i - ishift, i); + Utilities::Rxn_copy(Rxn_solution_map, i - ishift, i); /* if boundary_solutions must be flushed by the flux from the column... if (ishift == 1 && bcon_last == 3) @@ -541,35 +500,35 @@ transport(void) if ((ishift == 1 && i == last_c + 1 && bcon_last != 3) || (ishift == -1 && i == last_c - 1 && bcon_first != 3)) continue; - int n_surface; - if ((surf_ptr = - surface_bsearch(i - ishift, &n_surface)) == NULL) + cxxSurface * surface_ptr = Utilities::Rxn_find(Rxn_surface_map, i - ishift); + if (surface_ptr == NULL) { - if ((surface_bsearch(i, &n_surface) != NULL) && + if ((Utilities::Rxn_find(Rxn_surface_map,i) != NULL) && ((i == 0 && bcon_first == 3) - || (i == count_cells + 1 && bcon_last == 3))) - surface_delete(i); + || (i == count_cells + 1 && bcon_last == 3))) + { + Rxn_surface_map.erase(i); + } continue; } - if (surf_ptr->transport) + if (surface_ptr->Get_transport()) { - if ((surf_ptr1 = - surface_bsearch(i, &n_surface)) == NULL) + cxxSurface * surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i); + if (surface_ptr1 == NULL) { - n = count_surface++; - space((void **) ((void *) &surface), - count_surface, &max_surface, - sizeof(struct surface)); - surf_ptr1 = &surface[n]; - surf_ptr1->count_comps = 0; + cxxSurface surf; + surf.Set_n_user(i); + surf.Set_n_user_end(i); + Rxn_surface_map[i] = surf; } if (i == first_c) - mobile_surface_copy(surf_ptr, surf_ptr1, i, - FALSE); + { + Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, false); + } else - mobile_surface_copy(surf_ptr, surf_ptr1, i, TRUE); - if (surface[n].n_user < surface[n - 1].n_user) - surface_sort(); + { + Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, true); + } } } } @@ -610,11 +569,8 @@ transport(void) fill_spec(i); if (iterations > max_iter) max_iter = iterations; - int n_solution; if ((nmix == 0) && ((stag_data->count_stag == 0) || - (solution_bsearch - (i + 1 + count_cells, &n_solution, - FALSE) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if ((cell_data[i - 1].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -629,9 +585,7 @@ transport(void) /* maybe sorb a surface component... */ if ((nmix == 0) && ((stag_data->count_stag == 0) || - (solution_bsearch - (i + 1 + count_cells, &n_solution, - FALSE) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -719,11 +673,8 @@ transport(void) run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); - int n_solution; if ((j == nmix) && ((stag_data->count_stag == 0) || - (solution_bsearch - (i + 1 + count_cells, &n_solution, - FALSE) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if ((cell_data[i - 1].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -733,14 +684,12 @@ transport(void) print_all(); } if (i > 1) - solution_duplicate(-2, i - 1); + Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); saver(); /* maybe sorb a surface component... */ if ((j == nmix) && ((stag_data->count_stag == 0) || - (solution_bsearch - (i + 1 + count_cells, &n_solution, - FALSE) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -759,7 +708,7 @@ transport(void) } } } - solution_duplicate(-2, count_cells); + Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each diffusive/dispersive step ... */ @@ -780,11 +729,8 @@ transport(void) if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) dump(); } -#ifdef DOS screen_msg("\n"); -#else - screen_msg(sformatf("%s%-80s", "\n", " "));; -#endif + /* free_model_allocs(); */ /* * free mix structures @@ -827,11 +773,6 @@ init_mix(void) { m.push_back(0); } - //LDBLE *m; - - //m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); - //if (m == NULL) - // malloc_error(); if (multi_Dflag == TRUE) diffc_here = 0.0; else @@ -949,75 +890,31 @@ init_mix(void) if (l_nmix != 0) { - //mix = (struct mix *) PHRQ_realloc(mix, - // (size_t) (count_mix + - // count_cells) * - // sizeof(struct mix)); - //if (mix == NULL) - // malloc_error(); - //count_mix += count_cells; - //for (n = count_mix - count_cells; n < count_mix; n++) - //{ - //mix[n].description = NULL; - //mix[n].count_comps = 3; - //mix[n].comps = - // (struct mix_comp *) PHRQ_malloc((size_t) 3 * - // sizeof(struct mix_comp)); - //if (mix[n].comps == NULL) - // malloc_error(); - //} - - //n = count_mix - count_cells; /* * max_mix brings n_user outside range of active cells * mix[n].n_user = mix[n].n_user_end = -999 has same effect * but max_mix keeps mix in sort order in case mix_bsearch * is used */ - //if (n - 1 <= 0) - //{ - // max_mix = 1; - //else - // max_mix = mix[n - 1].n_user + 1; - - //if (max_mix < count_cells * (stag_data->count_stag + 1) + 1) - // max_mix = count_cells * (stag_data->count_stag + 1) + 1; - for (i = 1; i <= count_cells; i++) { cxxMix temp_mix; dav = 0; - //count_comps = 0; - //mix[n].description = (char *) free_check_null(mix[n].description); - //mix[n].description = string_duplicate(" "); /* * again, max_mix brings n_user outside range of active cells, etc... */ - //mix[n].n_user = max_mix + i; - //mix[n].n_user_end = max_mix + i; temp_mix.Set_n_user(i); temp_mix.Set_n_user_end(i); - - //mix[n].comps[count_comps].n_solution = i - 1; - //mix[n].comps[count_comps].fraction = m[i - 1]; temp_mix.Add(i - 1, m[i - 1]); dav += m[i - 1]; - //count_comps++; - //mix[n].comps[count_comps].n_solution = i + 1; - //mix[n].comps[count_comps].fraction = m[i]; temp_mix.Add(i + 1, m[i]); dav += m[i]; - //count_comps++; - //mix[n].comps[count_comps].n_solution = i; - //mix[n].comps[count_comps].fraction = 1.0 - dav; temp_mix.Add(i, 1.0 - dav); Dispersion_mix_map[i] = temp_mix; - //n++; } } - //m = (LDBLE *) free_check_null(m); return (l_nmix); } /* ---------------------------------------------------------------------- */ @@ -1027,31 +924,30 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) { int j, n, k; LDBLE t_imm; - struct solution *ptr_imm, *ptr_m; + cxxSolution *ptr_imm, *ptr_m; /* * Kinetics in transport cell is done while transporting */ for (n = 1; n <= stag_data->count_stag; n++) { k = i + 1 + n * count_cells; - int n_solution; - if ((ptr_imm = solution_bsearch(k, &n_solution, FALSE)) != NULL) + if ((ptr_imm = Utilities::Rxn_find(Rxn_solution_map, k)) != NULL) { if (n == 1) { if (heat_nmix > 0) { - ptr_m = solution_bsearch(i, &n_solution, FALSE); + ptr_m = Utilities::Rxn_find(Rxn_solution_map, i); t_imm = - heat_mix_f_imm * ptr_m->tc + (1 - + heat_mix_f_imm * ptr_m->Get_tc() + (1 - heat_mix_f_imm) * - ptr_imm->tc; - ptr_m->tc = - heat_mix_f_m * ptr_imm->tc + (1 - + ptr_imm->Get_tc(); + ptr_m->Set_tc( + heat_mix_f_m * ptr_imm->Get_tc() + (1 - heat_mix_f_m) * - ptr_m->tc; - cell_data[i - 1].temp = ptr_m->tc; - cell_data[k - 1].temp = ptr_imm->tc = t_imm; + ptr_m->Get_tc()); + cell_data[i - 1].temp = ptr_m->Get_tc(); + cell_data[k - 1].temp= t_imm = ptr_imm->Get_tc(); /* equilibrate again ... */ cell_no = i; set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); @@ -1079,7 +975,6 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); if (multi_Dflag == TRUE) fill_spec(cell_no); - //use.Set_kinetics_ptr(kinetics_bsearch(i, &l)); use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); if (use.Get_kinetics_ptr() != NULL) { @@ -1147,12 +1042,11 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) for (n = 1; n <= stag_data->count_stag; n++) { k = i + 1 + n * count_cells; - int n_solution; - if (solution_bsearch(k, &n_solution, FALSE) != 0) + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { - solution_duplicate(-2 - k, k); + Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); if (n == 1) - solution_duplicate(-2, i); + Utilities::Rxn_copy(Rxn_solution_map, -2, i); } } return (OK); @@ -1164,7 +1058,7 @@ init_heat_mix(int l_nmix) /* ---------------------------------------------------------------------- */ { LDBLE lav, mixf, maxmix, corr_disp; - int i, j, k, n; + int i, k, n; int l_heat_nmix; LDBLE t0; /* @@ -1176,7 +1070,7 @@ init_heat_mix(int l_nmix) return (0); l_heat_nmix = 0; - t0 = solution_bsearch(0, &n, FALSE)->tc; + t0 = Utilities::Rxn_find(Rxn_solution_map, 0)->Get_tc(); for (i = 0; i < count_cells; i++) { if (fabs(cell_data[i].temp - t0) > 1.0) @@ -1187,14 +1081,14 @@ init_heat_mix(int l_nmix) } if (l_heat_nmix == 0) { - if (fabs(solution_bsearch(count_cells + 1, &n, FALSE)->tc - t0) > 1.0) + if (fabs(Utilities::Rxn_find(Rxn_solution_map, count_cells + 1)->Get_tc() - t0) > 1.0) l_heat_nmix = 1; for (n = 1; n <= stag_data->count_stag; n++) { for (i = 1; i < count_cells; i++) { k = i + 1 + n * count_cells; - if (solution_bsearch(k, &j, FALSE) != 0) + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { if (fabs(cell_data[k - 1].temp - t0) > 1.0) { @@ -1296,10 +1190,10 @@ heat_mix(int l_heat_nmix) int i, j; for (i = 1; i <= count_cells; i++) - temp1[i] = solution_bsearch(i, &j, FALSE)->tc; - temp1[0] = solution_bsearch(0, &j, FALSE)->tc; + temp1[i] = Utilities::Rxn_find(Rxn_solution_map, i)->Get_tc(); + temp1[0] = Utilities::Rxn_find(Rxn_solution_map, 0)->Get_tc(); temp1[count_cells + 1] = - solution_bsearch((count_cells + 1), &j, FALSE)->tc; + Utilities::Rxn_find(Rxn_solution_map, (count_cells + 1))->Get_tc(); for (i = 1; i <= l_heat_nmix; i++) { @@ -1316,7 +1210,7 @@ heat_mix(int l_heat_nmix) for (i = 1; i <= count_cells; i++) { cell_data[i - 1].temp = temp1[i]; - solution_bsearch(i, &j, FALSE)->tc = temp1[i]; + Utilities::Rxn_find(Rxn_solution_map, i)->Set_tc(temp1[i]); } return (OK); @@ -1365,12 +1259,9 @@ set_initial_moles(int i) /* * Kinetics */ - //kinetics_ptr = kinetics_bsearch(i, &n); kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); if (kinetics_ptr != NULL) { - //for (j = 0; j < kinetics_ptr->count_comps; j++) - // kinetics_ptr->comps[j].initial_moles = kinetics_ptr->comps[j].m; for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); @@ -1403,8 +1294,7 @@ set_initial_moles(int i) if (interlayer_Dflag && exchange_ptr == NULL) { cxxExchange temp_exchange; - temp_exchange.Set_n_user(i); - temp_exchange.Set_n_user_end(i); + temp_exchange.Set_n_user_both(i); temp_exchange.Set_description("Interlayer diffusion: added 2e-10 moles X-"); use.Set_exchange_in(true); use.Set_n_exchange_user(i); @@ -1424,11 +1314,9 @@ set_initial_moles(int i) get_token(&ptr, token1, &z, &l); comp.Set_formula(token1); comp.Set_formula_z(z); - comp.Set_formula_totals(elt_list_NameDouble()); - comp.Set_moles(2e-10); comp.Set_totals(elt_list_NameDouble()); comp.Set_charge_balance(0.0); - temp_exchange.Get_exchComps()[token1] = comp; + temp_exchange.Get_exchange_comps().push_back(comp); Rxn_exchange_map[i] = temp_exchange; state = INITIAL_EXCHANGE; @@ -1566,7 +1454,7 @@ fill_spec(int l_cell_no) if (transport_step == 0 && !x_max_done) { x_max_done = true; - dum = master_ptr->total / solution_bsearch(l_cell_no, &i2, TRUE)->mass_water; + dum = master_ptr->total / Utilities::Rxn_find(Rxn_solution_map, l_cell_no)->Get_mass_water(); if (dum > sol_D[1].x_max) sol_D[1].x_max = dum; } @@ -1643,7 +1531,6 @@ sort_species_name(const void *ptr1, const void *ptr2) return (strcmp(nptr1->s->name, nptr2->s->name)); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: multi_D(LDBLE DDt, int mobile_cell, int stagnant) @@ -1657,7 +1544,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) * mobile cell (with, for example, 1 kg water) * Define properties of each interface only 1 time with MIX. */ - int icell, jcell, i, j, k, l, n, length, length2, il_calcs; + int icell, jcell, i, l, n, length, length2, il_calcs; int i1; int first_c, last_c; char token[MAX_LENGTH]; @@ -1673,13 +1560,11 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) /* * find the mix ptr for icell and go along the cells that mix with it */ - //use.Get_mix_ptr() = mix_search(icell, &use.n_mix, FALSE); use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); if (use.Get_mix_ptr() == NULL) continue; first_c = 0; - //last_c = use.Get_mix_ptr()->count_comps - 1; - last_c = (int) (((cxxMix *) use.Get_mix_ptr())->Get_mixComps().size() - 1); + last_c = (int) (use.Get_mix_ptr()->Get_mixComps().size() - 1); } else { /* regular column... */ @@ -1697,19 +1582,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) { if (stagnant) { - std::vector n_solution; - std::vector fraction; - ((cxxMix *) use.Get_mix_ptr())->Vectorize(n_solution, fraction); - //std::map::const_iterator cit; - //for (cit = ((cxxMix *) use.Get_mix_ptr())->Get_mixComps().begin(); cit != ((cxxMix *) use.Get_mix_ptr())->Get_mixComps().end(); cit++) - //{ - // n_solution.push_back(cit->first); - // fraction.push_back(cit->second); - //} - //if ((jcell = use.Get_mix_ptr()->comps[i].n_solution) <= icell) + std::vector n_solution; + std::vector fraction; + (use.Get_mix_ptr())->Vectorize(n_solution, fraction); + if ((jcell = n_solution[i]) <= icell) continue; - //mixf = use.Get_mix_ptr()->comps[i].fraction; mixf = fraction[i]; if (mcd_substeps > 1) @@ -1751,65 +1629,49 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) */ if (i > 0 || stagnant) { - int n_solution; - use.Set_solution_ptr(solution_bsearch(icell, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); - use.Get_solution_ptr()->total_h -= tot1_h; - use.Get_solution_ptr()->total_o -= tot1_o; - use.Get_solution_ptr()->cb -= J_ij_sum; + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); + use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); + use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); + use.Get_solution_ptr()->Set_cb(use.Get_solution_ptr()->Get_cb() - J_ij_sum); for (l = 0; l < count_m_s; l++) { temp = 0.0; length = (int) strlen(m_s[l].name); - for (j = 0; - use.Get_solution_ptr()->totals[j].description != NULL; j++) + cxxNameDouble::iterator it; + for (it = use.Get_solution_ptr()->Get_totals().begin(); + it != use.Get_solution_ptr()->Get_totals().end(); it++) { + LDBLE moles = it->second; length2 = - (int) (size_t) strcspn(use.Get_solution_ptr()-> - totals[j].description, - "("); + (int) (size_t) strcspn(it->first.c_str(), "("); if (strncmp (m_s[l].name, - use.Get_solution_ptr()->totals[j].description, + it->first.c_str(), length) == 0 && length == length2) { - if (use.Get_solution_ptr()->totals[j].moles < - m_s[l].tot1) + if (moles < m_s[l].tot1) { - temp = use.Get_solution_ptr()->totals[j].moles; - use.Get_solution_ptr()->totals[j].moles = 0; + temp = moles; + it->second = 0.0; /* see if other redox states have more moles... */ - for (k = 1; - use.Get_solution_ptr()->totals[j + - k]. - description != NULL; k++) + cxxNameDouble::iterator kit = it; + kit++; + for ( ; kit != use.Get_solution_ptr()->Get_totals().end(); kit++) { - length2 = - (int) (size_t) strcspn(use.Get_solution_ptr()-> - totals[j + k]. - description, - "("); - if (strncmp - (m_s[l].name, - use.Get_solution_ptr()->totals[j + - k]. - description, length) == 0 + length2 = (int) (size_t) strcspn( + kit->first.c_str(), "("); + if (strncmp(m_s[l].name, + kit->first.c_str(), length) == 0 && length == length2) { - temp += - use.Get_solution_ptr()->totals[j + - k].moles; + temp += kit->second; if (temp < m_s[l].tot1) { - use.Get_solution_ptr()->totals[j + - k]. - moles = 0; + kit->second = 0; } else { - use.Get_solution_ptr()->totals[j + - k]. - moles = temp - m_s[l].tot1; + kit->second = temp - m_s[l].tot1; temp = 0.0; break; } @@ -1825,100 +1687,74 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } else - use.Get_solution_ptr()->totals[j].moles -= - m_s[l].tot1; + it->second -= m_s[l].tot1; break; } } - if (use.Get_solution_ptr()->totals[j].description == NULL) + if (it == use.Get_solution_ptr()->Get_totals().end()) { - use.Get_solution_ptr()->totals = - (struct conc *) PHRQ_realloc(use.Get_solution_ptr()-> - totals, - (size_t) (j + - 2) * - sizeof(struct conc)); - use.Get_solution_ptr()->totals[j].description = - string_hsave(m_s[l].name); - use.Get_solution_ptr()->totals[j].moles = -m_s[l].tot1; - if (use.Get_solution_ptr()->totals[j].moles < 0) + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = -m_s[l].tot1; + if (-m_s[l].tot1 < 0) { - if (use.Get_solution_ptr()->totals[j].moles < -1e-12) + if (-m_s[l].tot1 < -1e-12) { sprintf(token, "Negative concentration in MCD: added %.2e moles %s in cell %d", - (double) -use.Get_solution_ptr()-> - totals[j].moles, m_s[l].name, icell); + (double) m_s[l].tot1, m_s[l].name, icell); warning_msg(token); } - use.Get_solution_ptr()->totals[j].moles = 0; + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = 0; } - use.Get_solution_ptr()->totals[j + 1].description = NULL; } } } if (i < count_cells || stagnant) { - int n_solution; - use.Set_solution_ptr( - solution_bsearch(jcell, &n_solution, FALSE)); - //use.Set_n_solution(n_solution); - use.Get_solution_ptr()->total_h += tot2_h; - use.Get_solution_ptr()->total_o += tot2_o; - use.Get_solution_ptr()->cb += J_ij_sum; + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, jcell)); + dummy = use.Get_solution_ptr()->Get_total_h(); + use.Get_solution_ptr()->Set_total_h(dummy + tot2_h); + dummy = use.Get_solution_ptr()->Get_total_o(); + use.Get_solution_ptr()->Set_total_o(dummy + tot2_o); + dummy = use.Get_solution_ptr()->Get_cb(); + use.Get_solution_ptr()->Set_cb(dummy + J_ij_sum); for (l = 0; l < count_m_s; l++) { temp = 0.0; length = (int) strlen(m_s[l].name); - for (j = 0; - use.Get_solution_ptr()->totals[j].description != NULL; j++) + cxxNameDouble::iterator it; + for (it = use.Get_solution_ptr()->Get_totals().begin(); + it != use.Get_solution_ptr()->Get_totals().end(); it++) { - length2 = - (int) (size_t) strcspn(use.Get_solution_ptr()-> - totals[j].description, - "("); - if (strncmp - (m_s[l].name, - use.Get_solution_ptr()->totals[j].description, - length) == 0 && length == length2) + length2 = (int) (size_t) strcspn( + it->first.c_str(), "("); + if (strncmp(m_s[l].name, + it->first.c_str(), length) == 0 + && length == length2) { - if (use.Get_solution_ptr()->totals[j].moles < - -m_s[l].tot2) + if (it->second < -m_s[l].tot2) { - temp = use.Get_solution_ptr()->totals[j].moles; - use.Get_solution_ptr()->totals[j].moles = 0; + temp = it->second; + it->second = 0; /* see if other redox states have more moles... */ - for (k = 1; - use.Get_solution_ptr()->totals[j + - k]. - description != NULL; k++) + cxxNameDouble::iterator kit = it; + kit++; + for ( ; kit != use.Get_solution_ptr()->Get_totals().end(); kit++) { - length2 = - (int) (size_t) strcspn(use.Get_solution_ptr()-> - totals[j + k]. - description, - "("); + length2 = (int) (size_t) strcspn( + kit->first.c_str(), "("); if (strncmp (m_s[l].name, - use.Get_solution_ptr()->totals[j + - k]. - description, length) == 0 + kit->first.c_str(), length) == 0 && length == length2) { - temp += - use.Get_solution_ptr()->totals[j + - k].moles; + temp += kit->second; if (temp < -m_s[l].tot2) { - use.Get_solution_ptr()->totals[j + - k]. - moles = 0; + kit->second = 0; } else { - use.Get_solution_ptr()->totals[j + - k]. - moles = temp + m_s[l].tot2; + kit->second = temp + m_s[l].tot2; temp = 0.0; break; } @@ -1935,35 +1771,24 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } else - use.Get_solution_ptr()->totals[j].moles += - m_s[l].tot2; + it->second += m_s[l].tot2; break; } } - if (use.Get_solution_ptr()->totals[j].description == NULL) + if (it == use.Get_solution_ptr()->Get_totals().end()) { - use.Get_solution_ptr()->totals = - (struct conc *) PHRQ_realloc(use.Get_solution_ptr()-> - totals, - (size_t) (j + - 2) * - sizeof(struct conc)); - use.Get_solution_ptr()->totals[j].description = - string_hsave(m_s[l].name); - use.Get_solution_ptr()->totals[j].moles = m_s[l].tot2; - if (use.Get_solution_ptr()->totals[j].moles < 0) + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = m_s[l].tot2; + if (m_s[l].tot2 < 0) { - if (use.Get_solution_ptr()->totals[j].moles < -1e-12) + if (m_s[l].tot2 < -1e-12) { sprintf(token, "Negative concentration in MCD: added %.4e moles %s in cell %d", - (double) -use.Get_solution_ptr()-> - totals[j].moles, m_s[l].name, jcell); + (double) -m_s[l].tot2, m_s[l].name, jcell); warning_msg(token); } - use.Get_solution_ptr()->totals[j].moles = 0; + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = 0; } - use.Get_solution_ptr()->totals[j + 1].description = NULL; } } } @@ -2069,7 +1894,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) IL-water = (free + DL porewater) * por_il / (por - por_il). */ - int i, i_max, j, j_max, k, k_il, l, only_counter, il_calcs; + int i, i_max, j, j_max, k, k_il, only_counter, il_calcs; int i1; LDBLE lav, A1, A2, A_ij, A_ij_il, ddlm, aq1, aq2, mixf_il; LDBLE dl_s, dl_aq1, dl_aq2, c_dl, visc1, visc2, dum, dum2, tort1, tort2; @@ -2081,9 +1906,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) LDBLE grad, D, z, Dz, Dzc, Dzc_dl, g_dl; int o_c; } *V_M, *V_M_il; - struct surface *s_ptr1, *s_ptr2; - struct surface_charge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; - //struct exchange *ex_ptr1, *ex_ptr2; + cxxSurface *s_ptr1, *s_ptr2; + cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; char token[MAX_LENGTH], token1[MAX_LENGTH]; V_M = V_M_il = NULL; @@ -2131,8 +1955,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } /* do the calcs */ - aq1 = solution_bsearch(icell, &i, TRUE)->mass_water; - aq2 = solution_bsearch(jcell, &i, TRUE)->mass_water; + aq1 = Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mass_water(); + aq2 = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mass_water(); /* * check if DL calculations must be made, find amounts of water... */ @@ -2142,36 +1966,38 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) visc1 = visc2 = 1.0; only_counter = FALSE; - s_ptr1 = surface_bsearch(icell, &i); + s_ptr1 = Utilities::Rxn_find(Rxn_surface_map, icell); if (s_ptr1 != NULL) { - if (s_ptr1->dl_type != NO_DL) + if (s_ptr1->Get_dl_type() != cxxSurface::NO_DL) { - if (s_ptr1->only_counter_ions) + if (s_ptr1->Get_only_counter_ions()) only_counter = TRUE; /* find the one (and only one...) immobile surface comp with DL... */ - for (i = 0; i < s_ptr1->count_comps; i++) + for (i = 0; i < (int) s_ptr1->Get_surface_comps().size(); i++) { - if (s_ptr1->comps[i].Dw == 0) + cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); + if (comp_i_ptr->Get_Dw() == 0) { - s_charge_ptr1 = &s_ptr1->charge[s_ptr1->comps[i].charge]; - dl_aq1 = s_charge_ptr1->mass_water; - visc1 = s_ptr1->DDL_viscosity; + s_charge_ptr1 = s_ptr1->Find_charge(comp_i_ptr->Get_charge_name()); + dl_aq1 = s_charge_ptr1->Get_mass_water(); + visc1 = s_ptr1->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < s_ptr1->count_comps; j++) + for (j = i + 1; j < (int) s_ptr1->Get_surface_comps().size(); j++) { - if (s_ptr1->comps[j].Dw == 0 - && s_ptr1->comps[j].charge != - s_ptr1->comps[i].charge) + cxxSurfaceComp * comp_j_ptr = &(s_ptr1->Get_surface_comps()[j]); + if (comp_j_ptr->Get_Dw() == 0 + && (comp_j_ptr->Get_charge_name() != + comp_i_ptr->Get_charge_name())) { if (!warn_fixed_Surf) { - k = (int) strcspn(s_ptr1->comps[i].formula, "_"); - strncpy(token1, s_ptr1->comps[i].formula, k); + k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); + token1); warning_msg(token); warn_fixed_Surf = 1; } @@ -2183,31 +2009,33 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } } - s_ptr2 = surface_bsearch(jcell, &i); + s_ptr2 = Utilities::Rxn_find(Rxn_surface_map, jcell); if (s_ptr2 != NULL) { - if (s_ptr2->dl_type != NO_DL) + if (s_ptr2->Get_dl_type() != cxxSurface::NO_DL) { - if (s_ptr2->only_counter_ions) + if (s_ptr2->Get_only_counter_ions()) only_counter = TRUE; - for (i = 0; i < s_ptr2->count_comps; i++) + for (i = 0; i < (int) s_ptr2->Get_surface_comps().size(); i++) { - if (s_ptr2->comps[i].Dw == 0) + cxxSurfaceComp * comp_i_ptr = &(s_ptr2->Get_surface_comps()[i]); + if (comp_i_ptr->Get_Dw() == 0) { - s_charge_ptr2 = &s_ptr2->charge[s_ptr2->comps[i].charge]; - dl_aq2 = s_charge_ptr2->mass_water; - visc2 = s_ptr2->DDL_viscosity; + s_charge_ptr2 = s_ptr2->Find_charge(comp_i_ptr->Get_charge_name()); + dl_aq2 = s_charge_ptr2->Get_mass_water(); + visc2 = s_ptr2->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < s_ptr2->count_comps; j++) + for (j = i + 1; j < (int) s_ptr2->Get_surface_comps().size(); j++) { - if (s_ptr2->comps[j].Dw == 0 - && s_ptr2->comps[j].charge != - s_ptr2->comps[i].charge) + cxxSurfaceComp * comp_j_ptr = &(s_ptr2->Get_surface_comps()[j]); + if (comp_j_ptr->Get_Dw() == 0 + && (comp_j_ptr->Get_charge_name() != + comp_i_ptr->Get_charge_name())) { if (!warn_fixed_Surf) { - k = (int) strcspn(s_ptr2->comps[i].formula, "_"); - strncpy(token1, s_ptr2->comps[i].formula, k); + k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", @@ -2315,12 +2143,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) (cell_data[icell - 1].por - por_il1); aq_il2 = (aq2 + dl_aq2) * por_il2 / (cell_data[jcell - 1].por - por_il2); -/* former code... */ - //aq_il1 = (aq1 + dl_aq1) * cell_data[icell - 1].por_il / - // cell_data[icell - 1].por; - //aq_il2 = (aq2 + dl_aq2) * cell_data[jcell - 1].por_il / - // cell_data[jcell - 1].por; -/* end */ } if (por_il12 == 0) il_calcs = 0; @@ -2358,15 +2180,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) dum -= por_il12; } mixf *= (dum * pow(dum, multi_Dn)); -/* former code... */ - //mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); - //dum = (cell_data[icell - 1].por_il <= cell_data[jcell - 1].por_il ? - // cell_data[icell - 1].por_il : cell_data[jcell - 1].por_il); - //mixf_il = mixf * dum / interlayer_tortf; - //dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? - // cell_data[icell - 1].por : cell_data[jcell - 1].por); - //mixf *= dum * pow(dum, multi_Dn); -/* end */ } else { /* regular column... */ @@ -2410,36 +2223,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) A1 /= tort1; A2 /= tort2; A_ij = A1 * A2 / (A1 + A2); -/* former code... */ - //A1 = aq1 / (cell_data[icell - 1].length * - // 0.5 * cell_data[icell - 1].length); - //A2 = aq2 / (cell_data[jcell - 1].length * - // 0.5 * cell_data[jcell - 1].length); - //dum = A1 * cell_data[icell - 1].por_il / - // (cell_data[icell - 1].por * interlayer_tortf); - //dum2 = A2 * cell_data[jcell - 1].por_il / - // (cell_data[jcell - 1].por * interlayer_tortf); - //A_ij_il = dum * dum2 / (dum + dum2); - //A1 /= tort1; - //A2 /= tort2; - //A_ij = A1 * A2 / (A1 + A2); - - //A1 = dl_aq1 / (cell_data[icell - 1].length * - // 0.5 * cell_data[icell - 1].length); - //A2 = dl_aq2 / (cell_data[jcell - 1].length * - // 0.5 * cell_data[jcell - 1].length); - //dum = A1 * cell_data[icell - 1].por_il / - // (cell_data[icell - 1].por * interlayer_tortf); - //dum2 = A2 * cell_data[jcell - 1].por_il / - // (cell_data[jcell - 1].por * interlayer_tortf); - //if (dum + dum2 > 0) - //{ - // A_ij_il += dum * dum2 / (dum + dum2); - // A1 /= tort1; - // A2 /= tort2; - // A_ij += (A1 * A2 / (A1 + A2)); - //} -/* end */ } } /* diffuse... */ @@ -2536,17 +2319,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) V_M[k].Dzc = V_M[k].Dz * sol_D[icell].spec[i].c / 2; if (dl_s > 0) { - s_charge_ptr = - (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - for (l = 0; l < s_charge_ptr->count_g; l++) + s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; + LDBLE g = s_charge_ptr->Get_g_map()[V_M[k].z].Get_g(); { - if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) - == TRUE) { if (only_counter) { - if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) - || (s_charge_ptr->la_psi > 0 + if ((s_charge_ptr->Get_la_psi() < 0 && V_M[k].z < 0) + || (s_charge_ptr->Get_la_psi() > 0 && V_M[k].z > 0)) { V_M[k].o_c = 0; @@ -2566,8 +2346,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { V_M[k].g_dl = (1 + - s_charge_ptr->g[l].g * aq1 / - dl_aq1) * + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; V_M[k].Dzc_dl = V_M[k].Dz * sol_D[icell].spec[i].c / @@ -2575,10 +2354,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2; + V_M[k].Dz * sol_D[icell].spec[i].c / 2; } - break; + //break; } } Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; @@ -2620,17 +2398,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) V_M[k].Dzc = V_M[k].Dz * sol_D[jcell].spec[j].c / 2; if (dl_s > 0) { - s_charge_ptr = - (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - for (l = 0; l < s_charge_ptr->count_g; l++) + s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; + LDBLE g = s_charge_ptr->Get_g_map()[V_M[k].z].Get_g(); { - if (equal(s_charge_ptr->g[l].charge, V_M[k].z, G_TOL) - == TRUE) { if (only_counter) { - if ((s_charge_ptr->la_psi < 0 && V_M[k].z < 0) - || (s_charge_ptr->la_psi > 0 + if ((s_charge_ptr->Get_la_psi() < 0 && V_M[k].z < 0) + || (s_charge_ptr->Get_la_psi() > 0 && V_M[k].z > 0)) { V_M[k].o_c = 0; @@ -2650,7 +2425,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { V_M[k].g_dl = (1 + - s_charge_ptr->g[l].g * aq2 / + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; V_M[k].Dzc_dl = @@ -2662,7 +2437,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) V_M[k].Dz * sol_D[jcell].spec[j].c / 2; } - break; + //break; } } Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; @@ -2724,17 +2499,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) c_dl = 0.0; if (dl_aq1 > 0) { - for (l = 0; l < s_charge_ptr1->count_g; l++) + LDBLE g = s_charge_ptr1->Get_g_map()[V_M[k].z].Get_g(); { - if (equal - (s_charge_ptr1->g[l].charge, V_M[k].z, - G_TOL) == TRUE) { if (only_counter) { - if ((s_charge_ptr1->la_psi < 0 + if ((s_charge_ptr1->Get_la_psi() < 0 && V_M[k].z < 0) - || (s_charge_ptr1->la_psi > 0 + || (s_charge_ptr1->Get_la_psi() > 0 && V_M[k].z > 0)) { V_M[k].o_c = 0; @@ -2750,14 +2522,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { V_M[k].g_dl = (1 + - s_charge_ptr1->g[l].g * aq1 / + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; c_dl = sol_D[icell].spec[i].c / 2 * V_M[k].g_dl; } - break; + //break; } } } @@ -2766,17 +2538,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dl_aq2 > 0) { - for (l = 0; l < s_charge_ptr2->count_g; l++) + LDBLE g = s_charge_ptr2->Get_g_map()[V_M[k].z].Get_g(); { - if (equal - (s_charge_ptr2->g[l].charge, V_M[k].z, - G_TOL) == TRUE) { if (only_counter) { - if ((s_charge_ptr2->la_psi < 0 + if ((s_charge_ptr2->Get_la_psi() < 0 && V_M[k].z < 0) - || (s_charge_ptr2->la_psi > 0 + || (s_charge_ptr2->Get_la_psi() > 0 && V_M[k].z > 0)) { V_M[k].o_c = 0; @@ -2795,13 +2564,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { dum = (1 + - s_charge_ptr2->g[l].g * aq2 / + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; c_dl += sol_D[jcell].spec[j].c / 2 * dum; V_M[k].g_dl = (V_M[k].g_dl + dum) / 2; } - break; + //break; } } } @@ -2914,12 +2683,10 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* do the mass transfer... */ if (icell > 0 || stagnant) { - std::vector comps = ex_ptr1->Vectorize(); size_t k; - //for (k = 0; k < ex_ptr1->count_comps; k++) - for (k = 0; k < comps.size(); k++) + for (k = 0; k < ex_ptr1->Get_exchange_comps().size(); k++) { - cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble nd(ex_ptr1->Get_exchange_comps()[k].Get_totals()); cxxNameDouble::iterator it = nd.begin(); i_max = 0; for (; it != nd.end(); it++) @@ -2931,10 +2698,10 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) break; } - if (k < comps.size()) + if (k < ex_ptr1->Get_exchange_comps().size()) { - cxxExchComp *comp_ptr = comps[k]; - cxxNameDouble nd(comps[k]->Get_totals()); + cxxExchComp &comp_ref = ex_ptr1->Get_exchange_comps()[k]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); /* transfer O and H... */ for (; it != nd.end(); it++) @@ -2946,13 +2713,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < rc1 * tot1_h) { tot1_h -= coef; - //ex_ptr1->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert("H", 0); + comp_ref.Get_totals().insert("H", 0); } else { - comp_ptr->Get_totals().insert("H", coef - rc1 * tot1_h); - //ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_h; + comp_ref.Get_totals().insert("H", coef - rc1 * tot1_h); tot1_h *= (1 - rc1); } } @@ -2961,13 +2726,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < rc1 * tot1_o) { tot1_o -= coef; - //ex_ptr1->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert("O", 0); + comp_ref.Get_totals().insert("O", 0); } else { - comp_ptr->Get_totals().insert("O", coef - rc1 * tot1_o); - //ex_ptr1->comps[k].totals[i].coef -= rc1 * tot1_o; + comp_ref.Get_totals().insert("O", coef - rc1 * tot1_o); tot1_o *= (1 - rc1); } } @@ -2977,9 +2740,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) for (j = 0; j < count_m_s; j++) { // Make sure list includes each element - comps[k]->Get_totals().add(m_s[j].name, 0); + comp_ref.Get_totals().add(m_s[j].name, 0); - cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); for (; it != nd.end(); it++) { @@ -2992,13 +2755,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < rc1 * m_s[j].tot1) { m_s[j].tot1 -= coef; - //ex_ptr1->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert(m_s[j].name, 0); + comp_ref.Get_totals().insert(m_s[j].name, 0); } else { - comp_ptr->Get_totals().insert(m_s[j].name, coef - rc1 * m_s[j].tot1); - //ex_ptr1->comps[k].totals[i].coef -= rc1 * m_s[j].tot1; + comp_ref.Get_totals().insert(m_s[j].name, coef - rc1 * m_s[j].tot1); m_s[j].tot1 *= (1 - rc1); } } @@ -3007,12 +2768,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } if (icell < count_cells || stagnant) { - std::vector comps = ex_ptr2->Vectorize(); size_t k; - //for (k = 0; k < ex_ptr1->count_comps; k++) - for (k = 0; k < comps.size(); k++) + for (k = 0; k < ex_ptr2->Get_exchange_comps().size(); k++) { - cxxNameDouble nd(comps[k]->Get_totals()); + cxxExchComp &comp_ref = ex_ptr2->Get_exchange_comps()[k]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); i_max = 0; for (; it != nd.end(); it++) @@ -3023,14 +2783,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (i_max) break; } - if (k < comps.size()) + if (k < ex_ptr2->Get_exchange_comps().size()) { - cxxExchComp *comp_ptr = comps[k]; - cxxNameDouble nd(comps[k]->Get_totals()); + cxxExchComp &comp_ref = ex_ptr2->Get_exchange_comps()[k]; + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); /* transfer O and H... */ for (; it != nd.end(); it++) - //for (i = 0;; i++) { struct element *elt_ptr = element_store(it->first.c_str()); LDBLE coef = it->second; @@ -3040,13 +2799,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < -rc2 * tot2_h) { tot2_h += coef; - //ex_ptr2->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert("H", 0); + comp_ref.Get_totals().insert("H", 0); } else { - comp_ptr->Get_totals().insert("H", coef + rc2 * tot2_h); - //ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_h; + comp_ref.Get_totals().insert("H", coef + rc2 * tot2_h); tot2_h *= (1 - rc2); } } @@ -3055,25 +2812,22 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < -rc2 * tot2_o) { tot2_o += coef; - //ex_ptr2->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert("O", 0); + comp_ref.Get_totals().insert("O", 0); } else { - comp_ptr->Get_totals().insert("O", coef + rc2 * tot2_o); - //ex_ptr2->comps[k].totals[i].coef += rc2 * tot2_o; + comp_ref.Get_totals().insert("O", coef + rc2 * tot2_o); tot2_o *= (1 - rc2); } } } /* transfer other elements... */ - //j_max = 0; /* if j_max turns true, reallocate the exchange structure */ for (j = 0; j < count_m_s; j++) { // Make sure list includes each element - comps[k]->Get_totals().add(m_s[j].name, 0); + comp_ref.Get_totals().add(m_s[j].name, 0); - cxxNameDouble nd(comps[k]->Get_totals()); + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); for (; it != nd.end(); it++) { @@ -3086,13 +2840,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (coef < -rc2 * m_s[j].tot2) { m_s[j].tot2 += coef; - //ex_ptr2->comps[k].totals[i].coef = 0; - comp_ptr->Get_totals().insert(m_s[j].name, 0); + comp_ref.Get_totals().insert(m_s[j].name, 0); } else { - comp_ptr->Get_totals().insert(m_s[j].name, coef + rc2 * m_s[j].tot2); - //ex_ptr2->comps[k].totals[i].coef += rc2 * m_s[j].tot2; + comp_ref.Get_totals().insert(m_s[j].name, coef + rc2 * m_s[j].tot2); m_s[j].tot2 *= (1 - rc2); } } @@ -3128,13 +2880,12 @@ disp_surf(LDBLE DDt) * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. */ { - int i, i1, i2, j, k, k1, n, n1, n2, temp_count_surface; + int i, i1, i2, k, k1, n1, n2; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store, mcd_mixf; LDBLE lav, A_ij, por, Dp1, Dp2; - //struct mix *mix_ptr; cxxMix * mix_ptr; - struct surface *surface_ptr1, *surface_ptr2; + cxxSurface *surface_ptr1, *surface_ptr2; LDBLE viscos_f; /* * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) @@ -3142,16 +2893,16 @@ disp_surf(LDBLE DDt) viscos_f = viscosity(); viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); - n1 = count_surface; + n1 = 0; n2 = n1 + 1; - temp_count_surface = count_surface + 2; - space((void **) ((void *) &surface), temp_count_surface, &max_surface, - sizeof(struct surface)); - surface[n1].count_comps = surface[n1 + 1].count_comps = 0; + + cxxSurface surface_n1, surface_n2; + cxxSurface *surface_n2_ptr; + + std::map Rxn_temp_surface_map; for (i1 = 1; i1 <= count_cells + 1; i1++) { - if (i1 <= count_cells && cell_data[i1 - 1].por < multi_Dpor_lim) continue; @@ -3166,21 +2917,25 @@ disp_surf(LDBLE DDt) /* * step 1. define surface n1 from cell i1, if it exists... */ - surface[n1].n_user = surface[n1 + 1].n_user = -99; - if ((surface_ptr1 = surface_bsearch(i1, &n)) != NULL) - surface_copy(surface_ptr1, &surface[n1], i1); + surface_n1.Set_n_user(-99); + surface_n2.Set_n_user(-99); - surface_ptr2 = surface_bsearch(i2, &n); + surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i1); + if (surface_ptr1 != NULL) + { + surface_n1 = *surface_ptr1; + } + surface_ptr2 = Utilities::Rxn_find(Rxn_surface_map, i2); surf1 = surf2 = 0; if (surface_ptr2 != NULL) { - if (surface_ptr2->transport == TRUE) + if (surface_ptr2->Get_transport()) surf2 = 1; } if (surface_ptr1 != NULL) { - if (surface_ptr1->transport == TRUE) + if (surface_ptr1->Get_transport()) surf1 = 1; } @@ -3216,16 +2971,15 @@ disp_surf(LDBLE DDt) } /* step 1b. If cell i1 has no surface, get the mobile comps from surface i2... */ - if (surface[n1].n_user == -99) + if (surface_n1.Get_n_user() == -99) { - mobile_surface_copy(surface_ptr2, &surface[n1], i1, FALSE); + surface_n1 = mobile_surface_copy(surface_ptr2, i1, false); /* limit charges to 1... */ - if (surface[n1].count_charge > 1) + if (surface_n1.Get_surface_charges().size() > 1) { - if (sum_surface_comp - (&surface[n1], 0, &surface[n1], 0, 1, &surface[n1], - surface[n1].comps[0].Dw) == ERROR) - return (ERROR); + std::string charge_name = surface_n1.Get_surface_charges()[0].Get_name(); + surface_n1 = sum_surface_comp(&surface_n1, 0, + &surface_n1, charge_name, 1, surface_n1.Get_surface_comps()[0].Get_Dw()); } f1 = 0; } @@ -3235,34 +2989,31 @@ disp_surf(LDBLE DDt) f2 = 1; if (i2 > 0 || bcon_first == 1) { - for (k = count_surface + 2; k < temp_count_surface; k++) + surface_n2_ptr = Utilities::Rxn_find(Rxn_temp_surface_map, i2); + if (surface_n2_ptr != NULL) { - if (surface[k].n_user == i2) - { - n2 = k; - break; - } + surface_n2 = *surface_n2_ptr; } + /* if not found... */ - if (k == temp_count_surface) + else { - n2 = n1 + 1; /* copy it from surface_ptr2... */ if (surface_ptr2 != NULL) - surface_copy(surface_ptr2, &surface[n2], i2); + { + surface_n2 = *surface_ptr2; + surface_n2.Set_n_user_both(i2); + } else { /* or make it a mobile copy of the surface in cell i1... */ - mobile_surface_copy(surface_ptr1, &surface[n2], i2, - FALSE); + surface_n2 = mobile_surface_copy(surface_ptr1, i2, false); /* limit charges to 1... */ - if (surface[n2].count_charge > 1) + if (surface_n2.Get_surface_charges().size() > 1) { - if (sum_surface_comp - (&surface[n2], 0, &surface[n2], 0, 1, - &surface[n2], - surface[n2].comps[0].Dw) == ERROR) - return (ERROR); + std::string charge_name = surface_n2.Get_surface_charges()[0].Get_name(); + surface_n2 = sum_surface_comp(&surface_n2, 0, &surface_n2, charge_name, 1, + surface_n2.Get_surface_comps()[0].Get_Dw()); } f2 = 0; } @@ -3276,17 +3027,14 @@ disp_surf(LDBLE DDt) { por = cell_data[0].por; lav = cell_data[0].length / 2; - A_ij = - solution_bsearch(1, &n, - TRUE)->mass_water / cell_data[0].length; + A_ij = Utilities::Rxn_find(Rxn_solution_map, 1)->Get_mass_water() / cell_data[0].length; } else if (i1 == count_cells + 1) { por = cell_data[count_cells - 1].por; lav = cell_data[count_cells - 1].length / 2; A_ij = - solution_bsearch(count_cells, &n, - TRUE)->mass_water / + Utilities::Rxn_find(Rxn_solution_map, count_cells)->Get_mass_water() / cell_data[count_cells - 1].length; } else @@ -3295,19 +3043,11 @@ disp_surf(LDBLE DDt) lav = (cell_data[i1 - 1].length + cell_data[i2 - 1].length) / 2; A_ij = - solution_bsearch(i1, &n, - TRUE)->mass_water / (cell_data[i1 - - 1]. - length * - cell_data[i1 - - 1].por); + Utilities::Rxn_find(Rxn_solution_map, i1)->Get_mass_water() / + (cell_data[i1 - 1].length * cell_data[i1 - 1].por); A_ij += - solution_bsearch(i2, &n, - TRUE)->mass_water / (cell_data[i2 - - 1]. - length * - cell_data[i2 - - 1].por); + Utilities::Rxn_find(Rxn_solution_map, i2)->Get_mass_water() / + (cell_data[i2 - 1].length * cell_data[i2 - 1].por); A_ij /= 2; A_ij *= (cell_data[i1 - 1].por < @@ -3320,15 +3060,19 @@ disp_surf(LDBLE DDt) /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < surface_ptr2->count_comps; k++) + for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) { - if (surface_ptr2->comps[k].Dw == 0) + cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); + std::string charge_name = comp_k_ptr->Get_charge_name(); + if (comp_k_ptr->Get_Dw() == 0) continue; + charge_done = FALSE; for (k1 = 0; k1 < k; k1++) { - if (surface_ptr2->comps[k1].charge == - surface_ptr2->comps[k].charge) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); + if (comp_k_ptr->Get_charge_name() == + comp_k1_ptr->Get_charge_name()) { charge_done = TRUE; break; @@ -3341,18 +3085,18 @@ disp_surf(LDBLE DDt) mcd_mixf = 0; if (multi_Dflag) { - Dp2 = surface_ptr2->comps[k].Dw * pow(por, multi_Dn); + Dp2 = comp_k_ptr->Get_Dw() * pow(por, multi_Dn); Dp1 = 0; - if (surface_ptr1 != NULL && surface_ptr1->transport) + if (surface_ptr1 != NULL && surface_ptr1->Get_transport()) { - for (k1 = 0; k1 < surface_ptr1->count_comps; k1++) + for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) { - if (elt_list_compare - (surface_ptr1->comps[k1].totals, - surface_ptr2->comps[k].totals) != 0) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); + if (strcmp(comp_k1_ptr->Get_formula().c_str(), + comp_k_ptr->Get_formula().c_str()) != 0) continue; Dp1 = - surface_ptr1->comps[k].Dw * + comp_k1_ptr->Get_Dw() * pow(cell_data[i1 - 1].por, multi_Dn); break; } @@ -3371,36 +3115,33 @@ disp_surf(LDBLE DDt) mixf = 0.99999999; if (i1 <= count_cells) { - if (sum_surface_comp - (&surface[n1], f1, surface_ptr2, k, mixf, - &surface[n1], - surface_ptr2->comps[k].Dw) == ERROR) - return (ERROR); + surface_n1 = sum_surface_comp(&surface_n1, f1, surface_ptr2, charge_name, mixf, + surface_ptr2->Get_surface_comps()[k].Get_Dw()); f1 = 1; } if (i2 > 0) { - if (sum_surface_comp - (&surface[n2], f2, surface_ptr2, k, -mixf, - &surface[n2], - surface_ptr2->comps[k].Dw) == ERROR) - return (ERROR); + surface_n2 = sum_surface_comp(&surface_n2, f2, surface_ptr2, charge_name, -mixf, + surface_ptr2->Get_surface_comps()[k].Get_Dw()); f2 = 1; } - surface[n1].n_user = i1; + surface_n1.Set_n_user_both(i1); } } if (surf1) { - for (k = 0; k < surface_ptr1->count_comps; k++) + for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) { - if (surface_ptr1->comps[k].Dw == 0) + cxxSurfaceComp * comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); + std::string charge_name = comp_k_ptr->Get_charge_name(); + if (comp_k_ptr->Get_Dw() == 0) continue; charge_done = FALSE; for (k1 = 0; k1 < k; k1++) { - if (surface_ptr1->comps[k1].charge == - surface_ptr1->comps[k].charge) + cxxSurfaceComp * comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); + if (comp_k_ptr->Get_charge_name() == + comp_k1_ptr->Get_charge_name()) { charge_done = TRUE; break; @@ -3414,25 +3155,25 @@ disp_surf(LDBLE DDt) if (multi_Dflag) { if (i1 <= count_cells) - Dp1 = - surface_ptr1->comps[k].Dw * - pow(cell_data[i1 - 1].por, multi_Dn); - else - Dp1 = - surface_ptr1->comps[k].Dw * pow(por, - multi_Dn); - Dp2 = 0; - if (surface_ptr2 != NULL && surface_ptr2->transport) { - for (k1 = 0; k1 < surface_ptr2->count_comps; k1++) + Dp1 = + comp_k_ptr->Get_Dw() * + pow(cell_data[i1 - 1].por, multi_Dn); + } + else + { + Dp1 = comp_k_ptr->Get_Dw() * pow(por, multi_Dn); + } + Dp2 = 0; + if (surface_ptr2 != NULL && surface_ptr2->Get_transport()) + { + for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) { - if (elt_list_compare - (surface_ptr2->comps[k1].totals, - surface_ptr1->comps[k].totals) != 0) + cxxSurfaceComp * comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); + if (strcmp(comp_k1_ptr->Get_formula().c_str(), + comp_k_ptr->Get_formula().c_str()) != 0) continue; - Dp2 = - surface_ptr2->comps[k].Dw * pow(por, - multi_Dn); + Dp2 = comp_k1_ptr->Get_Dw() * pow(por, multi_Dn); break; } } @@ -3450,23 +3191,19 @@ disp_surf(LDBLE DDt) mixf = 0.99999999; if (i2 > 0) { - if (sum_surface_comp - (&surface[n2], f2, surface_ptr1, k, mixf, - &surface[n2], - surface_ptr1->comps[k].Dw) == ERROR) - return (ERROR); + surface_n2 = sum_surface_comp + (&surface_n2, f2, surface_ptr1, charge_name, mixf, + surface_ptr1->Get_surface_comps()[k].Get_Dw()); f2 = 1; } if (i1 <= count_cells) { - if (sum_surface_comp - (&surface[n1], f1, surface_ptr1, k, -mixf, - &surface[n1], - surface_ptr1->comps[k].Dw) == ERROR) - return (ERROR); + surface_n1 = sum_surface_comp + (&surface_n1, f1, surface_ptr1, charge_name, -mixf, + surface_ptr1->Get_surface_comps()[k].Get_Dw()); f1 = 1; } - surface[n2].n_user = i2; + surface_n2.Set_n_user_both(i2); } } } @@ -3474,92 +3211,71 @@ disp_surf(LDBLE DDt) /* * Step 3. copy surface[n1] and [n2] in a new temporary surface... */ - if (surface[n1].n_user == -99) + if (surface_n1.Get_n_user() == -99) continue; - n = temp_count_surface++; - - space((void **) ((void *) &surface), temp_count_surface, - &max_surface, sizeof(struct surface)); - surface_copy(&surface[n1], &surface[n], i1); - - surface[n1].n_user = -99; - surface[n].n_user = surface[n].n_user_end = i1; - surface_free(&surface[n1]); - surface[n1].count_comps = 0; - if (n2 == n1 + 1 && surface[n2].n_user == i2) + Rxn_temp_surface_map[i1] = surface_n1; { - n = temp_count_surface++; + cxxSurface t; + surface_n1 = t; + } + surface_n1.Set_n_user_both(-99); - space((void **) ((void *) &surface), temp_count_surface, - &max_surface, sizeof(struct surface)); - surface_copy(&surface[n2], &surface[n], i2); - - surface[n2].n_user = -99; - surface[n].n_user = surface[n].n_user_end = i2; - surface_free(&surface[n1 + 1]); - surface[n1 + 1].count_comps = 0; + if (surface_n2.Get_n_user() == i2) + { + surface_n2.Set_n_user_both(i2); + Rxn_temp_surface_map[i2] = surface_n2; + { + cxxSurface t; + surface_n2 = t; + } + surface_n2.Set_n_user_both(-99); } } /* * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... */ n2 = 0; - - for (j = count_surface + 2; j < temp_count_surface; j++) + std::map::iterator jit = Rxn_temp_surface_map.begin(); + for ( ; jit != Rxn_temp_surface_map.end(); jit++) { - i = surface[j].n_user; - if ((i == 0 && bcon_first == 1) - || (i == count_cells + 1 && bcon_last == 1)) + i = jit->first; + assert (i == jit->second.Get_n_user()); + if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) { - surface_free(&surface[j]); - surface[j].count_comps = 0; continue; } if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag)) { - surface_ptr1 = surface_bsearch(i, &n); + surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i); if (surface_ptr1 != NULL) { - surface_free(surface_ptr1); - surface_copy(&surface[j], surface_ptr1, i); + Rxn_surface_map[i] = jit->second; } else { - surface_copy(&surface[j], &surface[count_surface + n2], i); - n2++; + //Add to map + Rxn_surface_map[i] = jit->second; } } - surface_free(&surface[j]); - surface[j].count_comps = 0; } - count_surface += n2; - if (n2 > 0) - qsort(surface, (size_t) count_surface, - (size_t) sizeof(struct surface), surface_compare); return (OK); } /* ---------------------------------------------------------------------- */ -int Phreeqc:: -sum_surface_comp(struct surface *source1, LDBLE f1, struct surface *source2, - int k, LDBLE f2, struct surface *target, LDBLE new_Dw) +cxxSurface Phreeqc:: +sum_surface_comp(cxxSurface *source1, LDBLE f1, cxxSurface *source2, + std::string charge_name, LDBLE f2, LDBLE new_Dw) /* ---------------------------------------------------------------------- */ { /* * Takes fraction f1 of the 1st surface, adds fraction f2 of the 2nd surface's comps[k] and its charge. * The result goes in target */ - int i, i1, i2; - int new_n_user, found, charge_in; - struct surface temp_surface, *surface_ptr; - - struct surface *surface_ptr1, *surface_ptr2; - char token[MAX_LENGTH]; - int count_comps, count_comps1; - int count_charge, count_charge1, charge1, charge2; - + int new_n_user; + cxxSurface *surface_ptr1, *surface_ptr2; + std::string token; /* * Find surfaces */ @@ -3567,283 +3283,74 @@ sum_surface_comp(struct surface *source1, LDBLE f1, struct surface *source2, if (surface_ptr1 == NULL) { error_string = sformatf( "Null pointer for surface 1 in sum_surface."); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); input_error++; return (ERROR); } surface_ptr2 = source2; - - if (check_surfaces(source1, source2) == ERROR) - return (ERROR); /* * Store data for structure surface */ - new_n_user = surface_ptr1->n_user; - surface_copy(surface_ptr1, &temp_surface, new_n_user); - sprintf(token, "Copy"); - temp_surface.description = - (char *) free_check_null(temp_surface.description); - temp_surface.description = string_duplicate(token); - temp_surface.solution_equilibria = FALSE; - temp_surface.n_solution = -99; + new_n_user = surface_ptr1->Get_n_user(); + cxxSurface temp_surface(*surface_ptr1); + temp_surface.Set_n_user_both(new_n_user); + temp_surface.Set_description("Copy"); + temp_surface.Set_solution_equilibria(false); + temp_surface.Set_n_solution(-99); /* * Multiply component compositions by f1 */ - for (i = 0; i < surface_ptr1->count_comps; i++) - { - temp_surface.comps[i].moles *= f1; - temp_surface.comps[i].cb *= f1; - count_elts = 0; - add_elt_list(surface_ptr1->comps[i].totals, f1); - temp_surface.comps[i].totals = - (struct elt_list *) free_check_null(temp_surface.comps[i].totals); - temp_surface.comps[i].totals = elt_list_save(); - } - if (temp_surface.type != NO_EDL) - { - for (i = 0; i < surface_ptr1->count_charge; i++) - { - temp_surface.charge[i].grams *= f1; - temp_surface.charge[i].charge_balance *= f1; - temp_surface.charge[i].mass_water *= f1; - temp_surface.charge[i].g = NULL; - temp_surface.charge[i].count_g = 0; - count_elts = 0; - if (surface_ptr1->charge[i].diffuse_layer_totals != NULL) - { - add_elt_list(surface_ptr1->charge[i].diffuse_layer_totals, - f1); - temp_surface.charge[i].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[i]. - diffuse_layer_totals); - temp_surface.charge[i].g = - (struct surface_diff_layer *) - free_check_null(temp_surface.charge[i].g); - temp_surface.charge[i].diffuse_layer_totals = elt_list_save(); - } - else - { - temp_surface.charge[i].diffuse_layer_totals = NULL; - } - } - } + temp_surface.multiply(f1); /* * Add in surface_ptr2 */ + // Only components with same charge as component k + cxxSurface addee(*surface_ptr2); + addee.Get_surface_comps().clear(); + addee.Get_surface_charges().clear(); - count_comps = count_comps1 = surface_ptr1->count_comps; - count_charge = count_charge1 = surface_ptr1->count_charge; - - charge2 = surface_ptr2->comps[k].charge; - charge_in = FALSE; - for (i2 = 0; i2 < surface_ptr2->count_comps; i2++) + for (std::vector::iterator it = surface_ptr2->Get_surface_comps().begin(); + it != surface_ptr2->Get_surface_comps().end(); it++) { - - if (surface_ptr2->comps[i2].charge != charge2) - continue; - /* - * handle comps... - */ - found = FALSE; - for (i1 = 0; i1 < count_comps1; i1++) + if (it->Get_charge_name() == charge_name) { - - /* see if first surface contains the 2nd surface's component */ - if (surface_ptr2->comps[i2].formula == - surface_ptr1->comps[i1].formula) - { - found = TRUE; - if ((surface_ptr1->comps[i1].phase_name != NULL - && surface_ptr2->comps[i2].phase_name == NULL) - || (surface_ptr1->comps[i1].phase_name == NULL - && surface_ptr2->comps[i2].phase_name != NULL)) - { - error_string = sformatf( - "Surfaces differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - else if (surface_ptr1->comps[i1].phase_name != NULL - && surface_ptr2->comps[i2].phase_name != NULL - && strcmp_nocase(surface_ptr1->comps[i1].phase_name, - surface_ptr2->comps[i2]. - phase_name) != 0) - { - error_string = sformatf( - "Surfaces differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - if ((surface_ptr1->comps[i1].rate_name != NULL - && surface_ptr2->comps[i2].rate_name == NULL) - || (surface_ptr1->comps[i1].rate_name == NULL - && surface_ptr2->comps[i2].rate_name != NULL)) - { - error_string = sformatf( - "Surfaces differ in use of related rate (sites proportional to moles of a kinetic reactant). Can not mix."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - else if (surface_ptr1->comps[i1].rate_name != NULL - && surface_ptr2->comps[i2].rate_name != NULL - && strcmp_nocase(surface_ptr1->comps[i1].rate_name, - surface_ptr2->comps[i2]. - rate_name) != 0) - { - error_string = sformatf( - "Surfaces differ in use of related rates (sites proportional to moles of a kinetic reactant). Can not mix."); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - temp_surface.comps[i1].moles += - surface_ptr2->comps[i2].moles * f2; - count_elts = 0; - add_elt_list(temp_surface.comps[i1].totals, 1.0); - add_elt_list(surface_ptr2->comps[i2].totals, f2); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - temp_surface.comps[i1].totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i1].totals); - temp_surface.comps[i1].totals = elt_list_save(); - temp_surface.comps[i1].formula_totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i1]. - formula_totals); - temp_surface.comps[i1].formula_totals = elt_list_save(); - temp_surface.comps[i1].Dw = new_Dw; - charge1 = temp_surface.comps[i1].charge; - break; - } + addee.Get_surface_comps().push_back(*it); } - /* sum charge structures if not yet done... */ - if (found && temp_surface.type != NO_EDL && !charge_in) + } + for (std::vector::iterator it = surface_ptr2->Get_surface_charges().begin(); + it != surface_ptr2->Get_surface_charges().end(); it++) + { + if (it->Get_name() == charge_name) { - temp_surface.charge[charge1].grams += - surface_ptr2->charge[charge2].grams * f2; - temp_surface.charge[charge1].charge_balance += - surface_ptr2->charge[charge2].charge_balance * f2; - temp_surface.charge[charge1].mass_water += - surface_ptr2->charge[charge2].mass_water * f2; - count_elts = 0; - add_elt_list(temp_surface.charge[charge1].diffuse_layer_totals, - 1.0); - add_elt_list(surface_ptr2->charge[charge2].diffuse_layer_totals, - f2); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - temp_surface.charge[charge1].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[charge1]. - diffuse_layer_totals); - temp_surface.charge[charge1].diffuse_layer_totals = - elt_list_save(); - charge_in = TRUE; - } - - if (found == FALSE) - { - - /* 2nd surface's component not in 1st surface */ - temp_surface.comps = - (struct surface_comp *) PHRQ_realloc(temp_surface.comps, - (size_t) (count_comps + - 1) * - sizeof(struct - surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - memcpy(&temp_surface.comps[count_comps], - &surface_ptr2->comps[i2], sizeof(struct surface_comp)); - temp_surface.comps[count_comps].moles *= f2; - temp_surface.comps[count_comps].cb *= f2; - count_elts = 0; - add_elt_list(surface_ptr2->comps[i2].totals, f2); - temp_surface.comps[count_comps].totals = elt_list_save(); - temp_surface.comps[count_comps].formula_totals = elt_list_save(); - temp_surface.comps[i1].Dw = new_Dw; - count_comps++; - - /* sum charge structures if not yet done... */ - if (temp_surface.type != NO_EDL && !charge_in) - { - - temp_surface.charge = - (struct surface_charge *) PHRQ_realloc(temp_surface. - charge, - (size_t) - (count_charge + - 1) * - sizeof(struct - surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); - memcpy(&temp_surface.charge[count_charge], - &surface_ptr2->charge[charge2], - sizeof(struct surface_charge)); - temp_surface.charge[count_charge].grams *= f2; - temp_surface.charge[count_charge].charge_balance *= f2; - temp_surface.charge[count_charge].mass_water *= f2; - temp_surface.charge[count_charge].g = NULL; - temp_surface.charge[count_charge].count_g = 0; - count_elts = 0; - add_elt_list(surface_ptr2-> - charge[surface_ptr2->comps[k].charge]. - diffuse_layer_totals, f2); - temp_surface.charge[count_charge].diffuse_layer_totals = - elt_list_save(); - count_charge++; - charge_in = TRUE; - } - temp_surface.comps[count_comps - 1].charge = count_charge - 1; + addee.Get_surface_charges().push_back(*it); } } - temp_surface.count_comps = count_comps; - temp_surface.count_charge = count_charge; - temp_surface.transport = FALSE; - for (i = 0; i < count_comps; i++) + if (f2 == 0) + f2 = 1e-30; + temp_surface.add(addee, f2); + temp_surface.Set_transport(false); + for (size_t i = 0; i < temp_surface.Get_surface_comps().size(); i++) { - if (temp_surface.comps[i].Dw > 0) + if (temp_surface.Get_surface_comps()[i].Get_charge_name() == charge_name) { - temp_surface.transport = TRUE; - break; + temp_surface.Get_surface_comps()[i].Set_Dw(new_Dw); + } + if (temp_surface.Get_surface_comps()[i].Get_Dw() > 0) + { + temp_surface.Set_transport(true); } } - /* * Finish up */ - surface_ptr = target; - if (surface_ptr == NULL) - { - error_string = sformatf( "Target surface is NULL in sum_surface_comp"); - error_msg(error_string, CONTINUE); - input_error++; - return (ERROR); - } - surface_free(surface_ptr); - surface_copy(&temp_surface, surface_ptr, new_n_user); - surface_free(&temp_surface); - return (OK); + temp_surface.Sort_comps(); + return (temp_surface); } /* ---------------------------------------------------------------------- */ int Phreeqc:: -check_surfaces(struct surface *surface_ptr1, struct surface *surface_ptr2) +check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) /* ---------------------------------------------------------------------- */ { /* checks if surfaces can be mixed... @@ -3851,64 +3358,62 @@ check_surfaces(struct surface *surface_ptr1, struct surface *surface_ptr2) int n_user1, n_user2, return_code; return_code = OK; - n_user1 = surface_ptr1->n_user; - n_user2 = surface_ptr2->n_user; + n_user1 = surface_ptr1->Get_n_user(); + n_user2 = surface_ptr2->Get_n_user(); - /*if (surface_ptr1->diffuse_layer != surface_ptr2->diffuse_layer) { */ - if (surface_ptr1->dl_type != surface_ptr2->dl_type) + if (surface_ptr1->Get_dl_type() != surface_ptr2->Get_dl_type()) { error_string = sformatf( - "Surfaces %d and %d differ in definition of diffuse layer. Can not mix.", + "Surfaces %d and %d differ in definition of diffuse layer. Cannot mix.", n_user1, n_user2); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); return_code = ERROR; input_error++; } - /*if (surface_ptr1->edl != surface_ptr2->edl) { */ - if (surface_ptr1->type != surface_ptr2->type) + + if (surface_ptr1->Get_type() != surface_ptr2->Get_type()) { error_string = sformatf( "Surfaces %d and %d differ in use of electrical double layer. Can not mix.", n_user1, n_user2); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); return_code = ERROR; input_error++; } - if (surface_ptr1->only_counter_ions != surface_ptr2->only_counter_ions) + if (surface_ptr1->Get_only_counter_ions() != surface_ptr2->Get_only_counter_ions()) { error_string = sformatf( "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Can not mix.", n_user1, n_user2); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); return_code = ERROR; input_error++; } - if (surface_ptr1->related_phases != surface_ptr2->related_phases) + if (surface_ptr1->Get_related_phases() != surface_ptr2->Get_related_phases()) { error_string = sformatf( "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix.", n_user1, n_user2); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); return_code = ERROR; input_error++; } - if (surface_ptr1->related_rate != surface_ptr2->related_rate) + if (surface_ptr1->Get_related_rate() != surface_ptr2->Get_related_rate()) { error_string = sformatf( "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Can not mix.", n_user1, n_user2); - error_msg(error_string, CONTINUE); + error_msg(error_string, STOP); return_code = ERROR; input_error++; } return (return_code); } - /* ---------------------------------------------------------------------- */ -int Phreeqc:: -mobile_surface_copy(struct surface *surface_old_ptr, - struct surface *surf_ptr1, int n_user_new, int move_old) +cxxSurface Phreeqc:: +mobile_surface_copy(cxxSurface *surface_old_ptr, + int n_user_new, bool move_old) /* ---------------------------------------------------------------------- */ { /* @@ -3918,275 +3423,123 @@ mobile_surface_copy(struct surface *surface_old_ptr, * which will modify pointers and surface numbers. * User number of new surface structure is n_user_new, structure is freed when n_user_new is already defined */ - int count_comps, count_charge, new_charge, n_user_old, charge_done; - int i, i1, i2, j, k, k1, n; - char token[MAX_LENGTH]; - struct surface temp_surface, *surf_ptr; + cxxSurface temp_surface(*surface_old_ptr); /* * Store moving surface's properties in temp_surface */ - temp_surface.n_user = temp_surface.n_user_end = n_user_new; - temp_surface.new_def = surface_old_ptr->new_def; - sprintf(token, "Surface defined in simulation %d.", simulation); - temp_surface.description = string_duplicate(token); - temp_surface.dl_type = surface_old_ptr->dl_type; - temp_surface.type = surface_old_ptr->type; - temp_surface.only_counter_ions = surface_old_ptr->only_counter_ions; - temp_surface.thickness = surface_old_ptr->thickness; - temp_surface.debye_lengths = surface_old_ptr->debye_lengths; - temp_surface.DDL_viscosity = surface_old_ptr->DDL_viscosity; - temp_surface.DDL_limit = surface_old_ptr->DDL_limit; - temp_surface.solution_equilibria = FALSE; - temp_surface.n_solution = -99; - temp_surface.related_phases = surface_old_ptr->related_phases; - temp_surface.related_rate = surface_old_ptr->related_rate; - temp_surface.transport = TRUE; + temp_surface.Set_n_user_both(n_user_new); + std::ostringstream desc; + desc << "Surface defined in simulation " << simulation << "."; + temp_surface.Set_description(desc.str().c_str()); + temp_surface.Set_solution_equilibria(false); + temp_surface.Set_transport(true); - temp_surface.comps = - (struct surface_comp *) PHRQ_malloc(sizeof(struct surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - temp_surface.charge = - (struct surface_charge *) PHRQ_malloc(sizeof(struct surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); - count_comps = surface_old_ptr->count_comps; - count_charge = surface_old_ptr->count_charge; + size_t count_comps = surface_old_ptr->Get_surface_comps().size(); + int i1, i2; i1 = i2 = 0; + temp_surface.Get_surface_comps().clear(); + temp_surface.Get_surface_charges().clear(); /* see if comps must be moved, Dw > 0 */ - for (i = 0; i < count_comps; i++) + for (size_t i = 0; i < count_comps; i++) { - if (surface_old_ptr->comps[i].Dw > 0) + cxxSurfaceComp &comp_ref = surface_old_ptr->Get_surface_comps()[i]; + if (comp_ref.Get_Dw() > 0) { i1++; - if (i1 > 1) - { - temp_surface.comps = - (struct surface_comp *) PHRQ_realloc(temp_surface.comps, - (size_t) i1 * - sizeof(struct - surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - } - memcpy(&temp_surface.comps[i1 - 1], &surface_old_ptr->comps[i], - sizeof(struct surface_comp)); - temp_surface.comps[i1 - 1].totals = - elt_list_dup(surface_old_ptr->comps[i].totals); - temp_surface.comps[i1 - 1].formula_totals = - elt_list_dup(surface_old_ptr->comps[i].formula_totals); - /* charge structure */ - new_charge = TRUE; - for (j = 0; j < i; j++) - { - if (surface_old_ptr->comps[j].charge == - surface_old_ptr->comps[i].charge) - { - temp_surface.comps[i1 - 1].charge = i2 - 1; - new_charge = FALSE; - break; - } - } - if (new_charge) + // copy comp + temp_surface.Get_surface_comps().push_back(comp_ref); + + // copy charge, if needed + cxxSurfaceCharge *charge_ptr = temp_surface.Find_charge(comp_ref.Get_charge_name()); + if (charge_ptr == NULL) { i2++; - if (i2 > 1) - { - temp_surface.charge = - (struct surface_charge *) PHRQ_realloc(temp_surface. - charge, - (size_t) i2 * - sizeof(struct - surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); - } - memcpy(&temp_surface.charge[i2 - 1], - &surface_old_ptr->charge[surface_old_ptr->comps[i]. - charge], - (size_t) sizeof(struct surface_charge)); - temp_surface.charge[i2 - 1].diffuse_layer_totals = - elt_list_dup(surface_old_ptr-> - charge[surface_old_ptr->comps[i].charge]. - diffuse_layer_totals); - temp_surface.charge[i2 - 1].g = NULL; - - temp_surface.comps[i1 - 1].charge = i2 - 1; + cxxSurfaceCharge *old_charge_ptr = surface_old_ptr->Find_charge(comp_ref.Get_charge_name()); + temp_surface.Get_surface_charges().push_back(*old_charge_ptr); } } } - temp_surface.count_comps = i1; - temp_surface.count_charge = i2; + if (i1 > 0) { /* OK, store moved parts from old surface, but first: get immobile surface comps from new surface... */ - if ((surf_ptr = surface_bsearch(n_user_new, &n)) != NULL) + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, n_user_new); + if (surf_ptr != NULL) { - for (k = 0; k < surf_ptr->count_comps; k++) + for (size_t k = 0; k < surf_ptr->Get_surface_comps().size(); k++) { - if (surf_ptr->comps[k].Dw > 0) + cxxSurfaceComp &comp_ref = surf_ptr->Get_surface_comps()[k]; + if (comp_ref.Get_Dw() > 0) continue; - charge_done = FALSE; - for (k1 = 0; k1 < k; k1++) + bool charge_done(false); + for (size_t k1 = 0; k1 < k; k1++) { - if (surf_ptr->comps[k1].charge == - surf_ptr->comps[k].charge) + if (surf_ptr->Get_surface_comps()[k1].Get_charge_name() == + comp_ref.Get_charge_name()) { - charge_done = TRUE; + charge_done = true; break; } } if (charge_done) continue; - - if (sum_surface_comp - (&temp_surface, 1, surf_ptr, k, 1, &temp_surface, - 0) == ERROR) - return (ERROR); + temp_surface = sum_surface_comp(&temp_surface, 1, surf_ptr, comp_ref.Get_charge_name(), 1, 0); } } - if (surf_ptr1->count_comps > 0) - surface_free(surf_ptr1); - surface_copy(&temp_surface, surf_ptr1, n_user_new); + // Return value is temp_surface + temp_surface.Set_n_user_both(n_user_new); } - + /* delete moved parts from old surface */ if (move_old && i1 > 0) { - n_user_old = surface_old_ptr->n_user; - if (i1 != count_comps) + cxxSurface replace_old(temp_surface); + int n_user_old = surface_old_ptr->Get_n_user(); + if ((size_t) i1 != count_comps) { /* redefine old surface with only unmovable comps (Dw = 0) */ /* other temp_surface members were set above */ - temp_surface.n_user = temp_surface.n_user_end = n_user_old; - temp_surface.transport = FALSE; - - for (i = 0; i < temp_surface.count_comps; i++) - { - temp_surface.comps[i].totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i].totals); - temp_surface.comps[i].formula_totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i]. - formula_totals); - } - for (i = 0; i < temp_surface.count_charge; i++) - { - temp_surface.charge[i].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[i]. - diffuse_layer_totals); - temp_surface.charge[i].g = - (struct surface_diff_layer *) - free_check_null(temp_surface.charge[i].g); - } - temp_surface.comps = - (struct surface_comp *) PHRQ_realloc(temp_surface.comps, - sizeof(struct - surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - temp_surface.charge = - (struct surface_charge *) PHRQ_realloc(temp_surface.charge, - sizeof(struct - surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); + replace_old.Set_n_user_both(n_user_old); + replace_old.Set_transport(false); + replace_old.Get_surface_comps().clear(); + replace_old.Get_surface_charges().clear(); i1 = i2 = 0; - for (i = 0; i < count_comps; i++) + for (size_t i = 0; i < count_comps; i++) { - if (surface_old_ptr->comps[i].Dw == 0) + if (surface_old_ptr->Get_surface_comps()[i].Get_Dw() == 0) { i1++; - if (i1 > 1) - { - temp_surface.comps = - (struct surface_comp *) - PHRQ_realloc(temp_surface.comps, - (size_t) i1 * - sizeof(struct surface_comp)); - if (temp_surface.comps == NULL) - malloc_error(); - } - memcpy(&temp_surface.comps[i1 - 1], - &surface_old_ptr->comps[i], - (size_t) sizeof(struct surface_comp)); - temp_surface.comps[i1 - 1].totals = - elt_list_dup(surface_old_ptr->comps[i].totals); - temp_surface.comps[i1 - 1].formula_totals = - elt_list_dup(surface_old_ptr->comps[i]. - formula_totals); + // copy surface comp + cxxSurfaceComp & comp_ref = surface_old_ptr->Get_surface_comps()[i]; + replace_old.Get_surface_comps().push_back(comp_ref); + cxxSurfaceCharge *charge_ptr = replace_old.Find_charge(comp_ref.Get_charge_name()); - /* charge structure */ - new_charge = TRUE; - for (j = 0; j < i; j++) - { - if (surface_old_ptr->comps[j].charge == - surface_old_ptr->comps[i].charge) - { - temp_surface.comps[i1 - 1].charge = i2 - 1; - new_charge = FALSE; - break; - } - } - if (new_charge) + // copy surface charge if necessary + if (charge_ptr == NULL) { i2++; - if (i2 > 1) - { - temp_surface.charge = - (struct surface_charge *) - PHRQ_realloc(temp_surface.charge, - (size_t) i2 * - sizeof(struct surface_charge)); - if (temp_surface.charge == NULL) - malloc_error(); - } - memcpy(&temp_surface.charge[i2 - 1], - &surface_old_ptr->charge[surface_old_ptr-> - comps[i].charge], - (size_t) sizeof(struct surface_charge)); - temp_surface.charge[i2 - 1].diffuse_layer_totals = - elt_list_dup(surface_old_ptr-> - charge[surface_old_ptr->comps[i]. - charge].diffuse_layer_totals); - temp_surface.charge[i2 - 1].g = NULL; - - temp_surface.comps[i1 - 1].charge = i2 - 1; + cxxSurfaceCharge *old_charge_ptr = surface_old_ptr->Find_charge(comp_ref.Get_charge_name()); + replace_old.Get_surface_charges().push_back(*old_charge_ptr); } } } - temp_surface.count_comps = i1; - temp_surface.count_charge = i2; - if (i1 > 0) + if (replace_old.Get_surface_comps().size() == 0) { - temp_surface.related_phases = temp_surface.related_rate = - FALSE; - for (i = 0; i < i1; i++) - { - if (surface_old_ptr->comps[i].phase_name != NULL) - temp_surface.related_phases = TRUE; - if (surface_old_ptr->comps[i].rate_name != NULL) - temp_surface.related_rate = TRUE; - } + Rxn_surface_map.erase(surface_old_ptr->Get_n_user()); + } + else + { + replace_old.Sort_comps(); + Rxn_surface_map[surface_old_ptr->Get_n_user()] = replace_old; } - surface_free(surface_old_ptr); - surface_copy(&temp_surface, surface_old_ptr, n_user_old); - } - else - { - surface_sort(); - surface_delete(n_user_old); } } - - surface_free(&temp_surface); - return (OK); + temp_surface.Sort_comps(); + return (temp_surface); } /* ---------------------------------------------------------------------- */ @@ -4202,13 +3555,12 @@ diff_stag_surf(int mobile_cell) * for any cell in MCD, need only include the mixing factors for higher numbered cells. */ { - int i, i1, i2, j, k, k1, n, n1, n2, ns, temp_count_surface; + int i, i1, i2, k, k1, n1, n2, ns; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store; LDBLE Dp1, Dp2; - //struct mix *mix_ptr; cxxMix *mix_ptr; - struct surface *surface_ptr1, *surface_ptr2; + cxxSurface *surface_ptr1, *surface_ptr2; LDBLE viscos_f; /* * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) @@ -4216,12 +3568,10 @@ diff_stag_surf(int mobile_cell) viscos_f = viscosity(); viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); - n1 = count_surface; - n2 = n1 + 1; - temp_count_surface = count_surface + 2; - space((void **) ((void *) &surface), temp_count_surface, &max_surface, - sizeof(struct surface)); - surface[n1].count_comps = surface[n1 + 1].count_comps = 0; + cxxSurface surface_n1, surface_n2; + cxxSurface *surface_n1_ptr = &surface_n1; + cxxSurface *surface_n2_ptr; + std::map Rxn_temp_surface_map; for (ns = 0; ns < stag_data->count_stag; ns++) { @@ -4232,114 +3582,99 @@ diff_stag_surf(int mobile_cell) if (cell_data[i1 - 1].por < multi_Dpor_lim) continue; - surface[n1].n_user = surface[n1 + 1].n_user = -99; - surface_ptr1 = surface_bsearch(i1, &n); - + surface_n1.Set_n_user_both(-99); + surface_n2.Set_n_user_both(-99); + surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i1); /* * step 2a. mix surfaces... */ - //mix_ptr = mix_search(i1, &n, FALSE); mix_ptr = Utilities::Rxn_find(Rxn_mix_map, i1); if (mix_ptr == NULL) continue; - //for (j = 0; j < mix_ptr->count_comps; j++) - //std::map::const_iterator cit; - //for (cit = mix_ptr->Get_mixComps().begin(); cit != mix_ptr->Get_mixComps().end(); cit++) std::vector num; std::vector frac; mix_ptr->Vectorize(num, frac); for (size_t i3 = 0; i3 < num.size(); i3++) { - - //if ((i2 = mix_ptr->comps[j].n_solution) <= i1) - //if ((i2 = cit->first) <= i1) if ((i2 = num[i3]) <= i1) continue; if (cell_data[i2 - 1].por < multi_Dpor_lim) continue; - surface_ptr2 = surface_bsearch(i2, &n); - + surface_ptr2 = Utilities::Rxn_find(Rxn_surface_map, i2); surf1 = surf2 = 0; if (surface_ptr2 != NULL) { - if (surface_ptr2->transport == TRUE) + if (surface_ptr2->Get_transport()) surf2 = 1; } if (surface_ptr1 != NULL) { - if (surface_ptr1->transport == TRUE) + if (surface_ptr1->Get_transport()) surf1 = 1; } if (!surf1 && !surf2) continue; - - //mixf = mixf_store = mix_ptr->comps[j].fraction; - //mixf = mixf_store = cit->second; mixf = mixf_store = frac[i3];; /* find the (possibly modified) surface in cell i1... */ f1 = 1; - for (k = count_surface + 2; k < temp_count_surface; k++) + surface_n1_ptr = Utilities::Rxn_find(Rxn_temp_surface_map, i1); + if (surface_n1_ptr != NULL) { - if (surface[k].n_user == i1) - { - n1 = k; - break; - } + surface_n1 = *surface_n1_ptr; + n1 = 0; } /* if not found... */ - if (k == temp_count_surface) + else { - n1 = count_surface; /* copy it from surface_ptr1... */ if (surface_ptr1 != NULL) - surface_copy(surface_ptr1, &surface[n1], i1); + { + surface_n1 = *surface_ptr1; + } else { /* or make it a mobile copy of the surface in cell i2... */ - mobile_surface_copy(surface_ptr2, &surface[n1], i1, - FALSE); + surface_n1 = mobile_surface_copy(surface_ptr2, i1, false); + /* limit comps to 1... */ - if (surface[n1].count_comps > 1) + if (surface_n1.Get_surface_charges().size() > 1) { - if (sum_surface_comp - (&surface[n1], 0, &surface[n1], 0, 1, - &surface[n1], surface[n1].comps[0].Dw) == ERROR) - return (ERROR); + std::string charge_name = surface_n1.Get_surface_charges()[0].Get_name(); + surface_n1 = sum_surface_comp(&surface_n1, 0, &surface_n1, charge_name, 1, + surface_n1.Get_surface_comps()[0].Get_Dw()); } f1 = 0; } } /* find the (possibly modified) surface in cell i2... */ f2 = 1; - for (k = count_surface + 2; k < temp_count_surface; k++) + surface_n2_ptr = Utilities::Rxn_find(Rxn_temp_surface_map, i2); + + if (surface_n2_ptr != NULL) { - if (surface[k].n_user == i2) - { - n2 = k; - break; - } + surface_n2 = *surface_n2_ptr; } /* if not found... */ - if (k == temp_count_surface) + else { - n2 = count_surface + 1; + n2 = 1; /* copy it from surface_ptr2... */ if (surface_ptr2 != NULL) - surface_copy(surface_ptr2, &surface[n2], i2); + { + surface_n2 = *surface_ptr2; + } else { /* or make it a mobile copy of the surface in cell i1... */ - mobile_surface_copy(surface_ptr1, &surface[n2], i2, - FALSE); + surface_n2 = mobile_surface_copy(surface_ptr1, i2, false); /* limit comps to 1... */ - if (surface[n2].count_comps > 1) + if (surface_n2.Get_surface_charges().size() > 1) { - if (sum_surface_comp - (&surface[n2], 0, &surface[n2], 0, 1, - &surface[n2], surface[n2].comps[0].Dw) == ERROR) - return (ERROR); + std::string charge_name = surface_n2.Get_surface_charges()[0].Get_name(); + surface_n2 = sum_surface_comp(&surface_n2, 0, &surface_n2, charge_name, 1, + surface_n2.Get_surface_comps()[0].Get_Dw()); } f2 = 0; } @@ -4361,15 +3696,18 @@ diff_stag_surf(int mobile_cell) /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < surface_ptr2->count_comps; k++) + for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) { - if (surface_ptr2->comps[k].Dw == 0) + cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); + std::string charge_name = comp_k_ptr->Get_charge_name(); + if (comp_k_ptr->Get_Dw() == 0) continue; charge_done = FALSE; for (k1 = 0; k1 < k; k1++) { - if (surface_ptr2->comps[k1].charge == - surface_ptr2->comps[k].charge) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); + if (comp_k_ptr->Get_charge_name() == + comp_k1_ptr->Get_charge_name()) { charge_done = TRUE; break; @@ -4381,20 +3719,19 @@ diff_stag_surf(int mobile_cell) /* find diffusion coefficients of surfaces... */ if (multi_Dflag) { - Dp2 = - surface_ptr2->comps[k].Dw * + Dp2 = comp_k_ptr->Get_Dw() * pow(cell_data[i2 - 1].por, multi_Dn) * viscos_f; Dp1 = 0; if (surf1) { - for (k1 = 0; k1 < surface_ptr1->count_comps; k1++) + for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) { - if (elt_list_compare - (surface_ptr1->comps[k1].totals, - surface_ptr2->comps[k].totals) != 0) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); + if (strcmp(comp_k1_ptr->Get_formula().c_str(), + comp_k_ptr->Get_formula().c_str()) != 0) continue; Dp1 = - surface_ptr1->comps[k1].Dw * + comp_k1_ptr->Get_Dw() * pow(cell_data[i1 - 1].por, multi_Dn) * viscos_f; break; @@ -4405,37 +3742,36 @@ diff_stag_surf(int mobile_cell) /* and adapt the mixing factor... */ mixf = mixf_store * Dp2; - mixf /= solution_bsearch(i2, &n, FALSE)->mass_water; + mixf /= Utilities::Rxn_find(Rxn_solution_map, i2)->Get_mass_water(); } if (mixf < 1e-8) mixf = 0; if (mixf > 0.99999999) mixf = 0.99999999; - if (sum_surface_comp - (&surface[n1], f1, surface_ptr2, k, mixf, - &surface[n1], surface_ptr2->comps[k].Dw) == ERROR) - return (ERROR); + surface_n1 = sum_surface_comp(&surface_n1, f1, surface_ptr2, charge_name, mixf, + surface_ptr2->Get_surface_comps()[k].Get_Dw()); f1 = 1; - if (sum_surface_comp - (&surface[n2], f2, surface_ptr2, k, -mixf, - &surface[n2], surface_ptr2->comps[k].Dw) == ERROR) - return (ERROR); + surface_n2 = sum_surface_comp(&surface_n2, f2, surface_ptr2, charge_name, -mixf, + surface_ptr2->Get_surface_comps()[k].Get_Dw()); } } if (surf1) { - for (k = 0; k < surface_ptr1->count_comps; k++) + for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) { - if (surface_ptr1->comps[k].Dw == 0) + cxxSurfaceComp *comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); + std::string charge_name = comp_k_ptr->Get_charge_name(); + if (comp_k_ptr->Get_Dw() == 0) continue; charge_done = FALSE; for (k1 = 0; k1 < k; k1++) { - if (surface_ptr1->comps[k1].charge == - surface_ptr1->comps[k].charge) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); + if (comp_k_ptr->Get_charge_name() == + comp_k1_ptr->Get_charge_name()) { charge_done = TRUE; break; @@ -4448,20 +3784,20 @@ diff_stag_surf(int mobile_cell) if (multi_Dflag) { Dp1 = - surface_ptr1->comps[k].Dw * + comp_k_ptr->Get_Dw() * pow(cell_data[i1 - 1].por, multi_Dn) * viscos_f; Dp2 = 0; if (surf2) { - for (k1 = 0; k1 < surface_ptr2->count_comps; k1++) + for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) { - if (elt_list_compare - (surface_ptr2->comps[k1].totals, - surface_ptr1->comps[k].totals) != 0) + cxxSurfaceComp *comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); + if (strcmp(comp_k1_ptr->Get_formula().c_str(), + comp_k_ptr->Get_formula().c_str()) != 0) continue; Dp2 = - surface_ptr2->comps[k1].Dw * + comp_k1_ptr->Get_Dw() * pow(cell_data[i2 - 1].por, multi_Dn) * viscos_f; break; @@ -4472,377 +3808,153 @@ diff_stag_surf(int mobile_cell) /* and adapt the mixing factor... */ mixf = mixf_store * Dp1; - mixf /= solution_bsearch(i1, &n, FALSE)->mass_water; + mixf /= Utilities::Rxn_find(Rxn_solution_map, i1)->Get_mass_water(); } if (mixf < 1e-8) mixf = 0; if (mixf > 0.99999999) mixf = 0.99999999; - if (sum_surface_comp - (&surface[n2], f2, surface_ptr1, k, mixf, - &surface[n2], surface_ptr1->comps[k].Dw) == ERROR) - return (ERROR); + surface_n2 = sum_surface_comp(&surface_n2, f2, surface_ptr1, charge_name, mixf, + surface_ptr1->Get_surface_comps()[k].Get_Dw()); f2 = 1; - if (sum_surface_comp - (&surface[n1], f1, surface_ptr1, k, -mixf, - &surface[n1], surface_ptr1->comps[k].Dw) == ERROR) - return (ERROR); + surface_n1 = sum_surface_comp(&surface_n1, f1, surface_ptr1, charge_name, -mixf, + surface_ptr1->Get_surface_comps()[k].Get_Dw()); } } /* * Step 3. copy surface[n1] and [n2] in a new temporary surface... */ - if (surface[n1].n_user == -99) + if (surface_n1.Get_n_user() == -99) continue; - if (n1 == count_surface) - { - n = temp_count_surface++; + surface_n1.Set_n_user_both(i1); + Rxn_temp_surface_map[i1] = surface_n1; - space((void **) ((void *) &surface), temp_count_surface, - &max_surface, sizeof(struct surface)); - surface_copy(&surface[n1], &surface[n], i1); - - surface_free(&surface[n1]); - surface[n1].count_comps = 0; - } - else - n1 = count_surface; - - if (n2 == count_surface + 1) - { - n = temp_count_surface++; - - space((void **) ((void *) &surface), temp_count_surface, - &max_surface, sizeof(struct surface)); - surface_copy(&surface[n2], &surface[n], i2); - - surface_free(&surface[n2]); - surface[n2].count_comps = 0; - } - else - n2 = count_surface + 1; + assert(surface_n2.Get_n_user() != -99); + assert(surface_n2.Get_n_user() == i2); + surface_n2.Set_n_user_both(i2); + Rxn_temp_surface_map[i2] = surface_n2; } } /* * Step 4. Diffusion is done. New surfaces can be copied in the cells... */ - n2 = 0; - - for (j = count_surface + 2; j < temp_count_surface; j++) + std::map::iterator jit = Rxn_temp_surface_map.begin(); + for ( ; jit != Rxn_temp_surface_map.end(); jit++) { - i = surface[j].n_user; - if ((i == 0 && bcon_first == 1) - || (i == count_cells + 1 && bcon_last == 1)) + i = jit->first; + assert (i = jit->second.Get_n_user()); + if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) { - surface_free(&surface[j]); - surface[j].count_comps = 0; continue; } if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag)) { - surface_ptr1 = surface_bsearch(i, &n); + surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i); if (surface_ptr1 != NULL) { - surface_free(surface_ptr1); - surface_copy(&surface[j], surface_ptr1, i); + Rxn_surface_map[i] = jit->second; } else { - surface_copy(&surface[j], &surface[count_surface + n2], i); - n2++; + //Add to map + Rxn_surface_map[i] = jit->second; } } - surface_free(&surface[j]); - surface[j].count_comps = 0; } - count_surface += n2; - if (n2 > 0) - qsort(surface, (size_t) count_surface, - (size_t) sizeof(struct surface), surface_compare); - return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, LDBLE new_Dw, int l_cell) /* ---------------------------------------------------------------------- */ { - int i, i1, j, k, k1, n, length, length1, cn, cn1, charge_in; - char string[MAX_LENGTH]; - struct surface temp_surface, *surf_ptr; + cxxSurface *surface_ptr; - if ((surf_ptr = surface_bsearch(l_cell, &n)) == ERROR) + if ((surface_ptr = Utilities::Rxn_find(Rxn_surface_map, l_cell)) == NULL) return (OK); - + if (surface_ptr->Find_charge(comp_name) == NULL) + return (OK); + // Assume comp_name is charge name + std::string old_charge_name = comp_name; + std::string new_charge_name = new_comp_name; if (fraction > 0.99999999) fraction = 0.99999999; - length = (int) strlen(comp_name); - length1 = (int) strlen(new_comp_name); - for (k = 0; k < surf_ptr->count_comps; k++) - { - if (strncmp(comp_name, surf_ptr->comps[k].formula, length) == 0) - break; - } - if (k == surf_ptr->count_comps) - return (OK); - surface_copy(surf_ptr, &temp_surface, l_cell); + cxxSurface temp_surface(*surface_ptr); - for (k1 = 0; k1 < temp_surface.count_comps; k1++) - { - if (strncmp(new_comp_name, temp_surface.comps[k1].formula, length1) - == 0) - break; - } + cxxSurface change; - charge_in = FALSE; - if (k1 == temp_surface.count_comps) + for (size_t i = 0; i < temp_surface.Get_surface_comps().size(); i++) { - /* new_comp_name absent */ - /* rename the comps... */ - for (i = 0; i < temp_surface.count_comps; i++) + cxxSurfaceComp *comp_ptr = &(temp_surface.Get_surface_comps()[i]); + std::string charge_name = comp_ptr->Get_charge_name(); + if (charge_name == old_charge_name) { - if (temp_surface.comps[i].charge != temp_surface.comps[k].charge) - continue; - - strcpy(string, temp_surface.comps[i].formula); - replace(comp_name, new_comp_name, string); - temp_surface.comps[i].formula = string_hsave(string); - - temp_surface.comps[i].moles *= fraction; - - count_elts = 0; - add_elt_list(temp_surface.comps[i].totals, fraction); - temp_surface.comps[i].totals = - (struct elt_list *) free_check_null(temp_surface.comps[i]. - totals); - temp_surface.comps[i].totals = elt_list_save(); -/* appt, is this correct ? */ - temp_surface.comps[i].formula_totals = - (struct elt_list *) free_check_null(temp_surface.comps[i]. - formula_totals); - temp_surface.comps[i].formula_totals = elt_list_save(); - - /* rename surface comp in element list */ - for (j = 0; temp_surface.comps[i].totals[j].elt != NULL; j++) + cxxSurfaceComp comp(*comp_ptr); + comp.multiply(fraction); + std::string std_comp_name = comp_ptr->Get_formula(); + Utilities::replace(comp_name, new_comp_name, std_comp_name); + comp.Set_formula(std_comp_name.c_str()); + comp.Set_charge_name(new_comp_name); + cxxNameDouble nd; + cxxNameDouble::iterator it; + for (it = comp.Get_totals().begin(); it != comp.Get_totals().end(); it++) { - if (strncmp - (comp_name, temp_surface.comps[i].totals[j].elt->name, - length) == 0) - { - strcpy(string, temp_surface.comps[i].totals[j].elt->name); - replace(comp_name, new_comp_name, string); - temp_surface.comps[i].totals[j].elt = - element_store(string); - } - } - for (j = 0; temp_surface.comps[i].formula_totals[j].elt != NULL; - j++) - { - if (strncmp - (comp_name, - temp_surface.comps[i].formula_totals[j].elt->name, - length) == 0) - { - strcpy(string, - temp_surface.comps[i].formula_totals[j].elt->name); - replace(comp_name, new_comp_name, string); - temp_surface.comps[i].formula_totals[j].elt = - element_store(string); - } - } - /* add charge */ - if (!charge_in) - { - cn = temp_surface.comps[i].charge; - - temp_surface.charge[cn].grams *= fraction; - temp_surface.charge[cn].charge_balance *= fraction; - temp_surface.charge[cn].mass_water *= fraction; - - count_elts = 0; - add_elt_list(temp_surface.charge[cn].diffuse_layer_totals, - fraction); - temp_surface.charge[cn].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[cn]. - diffuse_layer_totals); - temp_surface.charge[cn].diffuse_layer_totals = - elt_list_save(); - - strcpy(string, temp_surface.charge[cn].name); - replace(comp_name, new_comp_name, string); - temp_surface.charge[cn].name = string_hsave(string); - /* renaming charge psi_master seems unnecessary... */ - charge_in = TRUE; - } - temp_surface.comps[i].Dw = new_Dw; - } - - /* add remainder of old comp and charge */ - if (fraction < 1) - sum_surface_comp(&temp_surface, 1, surf_ptr, k, 1 - fraction, - &temp_surface, surf_ptr->comps[k].Dw); - } - else - { - /* new_comp_name is already in surface */ - cn = surf_ptr->comps[k].charge; - for (i = 0; i < surf_ptr->count_comps; i++) - { - - if (surf_ptr->comps[i].charge != cn) - continue; - - strcpy(string, surf_ptr->comps[i].formula); - replace(comp_name, new_comp_name, string); - - /* add comps to new_comps */ - for (i1 = 0; i1 < temp_surface.count_comps; i1++) - { - - if (strcmp(string, temp_surface.comps[i1].formula) != 0) - continue; - - temp_surface.comps[i1].moles += - surf_ptr->comps[i].moles * fraction; - temp_surface.comps[i].moles -= - surf_ptr->comps[i].moles * fraction; - - /* rename surface comp in element list */ - for (j = 0; temp_surface.comps[i].totals[j].elt != NULL; j++) - { - if (strncmp - (comp_name, temp_surface.comps[i].totals[j].elt->name, - length) == 0) - { - strcpy(string, - temp_surface.comps[i].totals[j].elt->name); - replace(comp_name, new_comp_name, string); - temp_surface.comps[i].totals[j].elt = - element_store(string); - } - } - for (j = 0; - temp_surface.comps[i].formula_totals[j].elt != NULL; j++) - { - if (strncmp - (comp_name, - temp_surface.comps[i].formula_totals[j].elt->name, - length) == 0) - { - strcpy(string, - temp_surface.comps[i].formula_totals[j].elt-> - name); - replace(comp_name, new_comp_name, string); - temp_surface.comps[i].formula_totals[j].elt = - element_store(string); - } - } - count_elts = 0; - add_elt_list(temp_surface.comps[i1].totals, 1.0); - add_elt_list(temp_surface.comps[i].totals, fraction); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } - temp_surface.comps[i1].totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i1].totals); - temp_surface.comps[i1].totals = elt_list_save(); - temp_surface.comps[i1].formula_totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i1]. - formula_totals); - temp_surface.comps[i1].formula_totals = elt_list_save(); - temp_surface.comps[i1].Dw = new_Dw; - - count_elts = 0; - add_elt_list(surf_ptr->comps[i].totals, 1.0 - fraction); - temp_surface.comps[i].totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i].totals); - temp_surface.comps[i].totals = elt_list_save(); - temp_surface.comps[i].formula_totals = - (struct elt_list *) free_check_null(temp_surface. - comps[i]. - formula_totals); - temp_surface.comps[i].formula_totals = elt_list_save(); - - /* add charge */ - if (!charge_in) - { - cn1 = temp_surface.comps[i1].charge; - temp_surface.charge[cn1].grams += - surf_ptr->charge[cn].grams * fraction; - temp_surface.charge[cn1].charge_balance += - surf_ptr->charge[cn].charge_balance * fraction; - temp_surface.charge[cn1].mass_water += - surf_ptr->charge[cn].mass_water * fraction; - - temp_surface.charge[cn].grams -= - surf_ptr->charge[cn].grams * fraction; - temp_surface.charge[cn].charge_balance -= - surf_ptr->charge[cn].charge_balance * fraction; - temp_surface.charge[cn].mass_water -= - surf_ptr->charge[cn].mass_water * fraction; - - count_elts = 0; - add_elt_list(temp_surface.charge[cn1]. - diffuse_layer_totals, 1.0); - add_elt_list(surf_ptr->charge[cn].diffuse_layer_totals, - fraction); - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), - elt_list_compare); - elt_list_combine(); - } - temp_surface.charge[cn1].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[cn1]. - diffuse_layer_totals); - temp_surface.charge[cn1].diffuse_layer_totals = - elt_list_save(); - - count_elts = 0; - add_elt_list(surf_ptr->charge[cn].diffuse_layer_totals, - 1.0 - fraction); - temp_surface.charge[cn].diffuse_layer_totals = - (struct elt_list *) free_check_null(temp_surface. - charge[cn]. - diffuse_layer_totals); - temp_surface.charge[cn].diffuse_layer_totals = - elt_list_save(); - - charge_in = TRUE; - } + std::string tot_name(it->first); + Utilities::replace(comp_name, new_comp_name, tot_name); + nd[tot_name] = it->second; } + comp.Set_totals(nd); + change.Get_surface_comps().push_back(comp); + comp_ptr->multiply(1 - fraction); } } - - temp_surface.transport = FALSE; - for (i = 0; i < temp_surface.count_comps; i++) + for (size_t i = 0; i < temp_surface.Get_surface_charges().size(); i++) { - if (temp_surface.comps[i].Dw > 0) - temp_surface.transport = TRUE; + cxxSurfaceCharge *charge_ptr = &(temp_surface.Get_surface_charges()[i]); + std::string charge_name = charge_ptr->Get_name(); + if (charge_name == old_charge_name) + { + cxxSurfaceCharge charge(*charge_ptr); + charge.multiply(fraction); + std::string std_charge_name = charge_ptr->Get_name(); + Utilities::replace(comp_name, new_comp_name, std_charge_name); + charge.Set_name(std_charge_name.c_str()); + change.Get_surface_charges().push_back(charge); + charge_ptr->multiply(1 - fraction); + } } - surface_free(surf_ptr); - surface_copy(&temp_surface, surf_ptr, l_cell); - surface_free(&temp_surface); - - return (OK); + temp_surface.add(change, 1.0); + // change Dw + for (size_t i = 0; i < temp_surface.Get_surface_comps().size(); i++) + { + cxxSurfaceComp *comp_ptr = &(temp_surface.Get_surface_comps()[i]); + std::string charge_name = comp_ptr->Get_charge_name(); + if (charge_name == new_charge_name) + { + comp_ptr->Set_Dw(new_Dw); + } + } + temp_surface.Set_transport(false); + for (size_t i = 0; i < temp_surface.Get_surface_comps().size(); i++) + { + if (temp_surface.Get_surface_comps()[i].Get_Dw() > 0) + { + temp_surface.Set_transport(true); + break; + } + } + temp_surface.Sort_comps(); + Rxn_surface_map[l_cell] = temp_surface; + return OK; } + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: viscosity(void) diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index dc553828..f58cd1f3 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -1,7 +1,9 @@ +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "NameDouble.h" #include "Exchange.h" +#include "Solution.h" #include /* ---------------------------------------------------------------------- */ @@ -79,6 +81,7 @@ calc_alk(struct reaction * rxn_ptr) } return (return_value); } +#ifdef PHREEQC2 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_rho_0(LDBLE tc, LDBLE pa) @@ -102,6 +105,83 @@ calc_rho_0(LDBLE tc, LDBLE pa) return (1e-3 * rho_0); } +#else +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_rho_0(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ + /* Density of pure water + Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + + interpolation 0 - 300 oC, 0.006 - 1000 atm... + */ + LDBLE T = tc + 273.15; // note... the new temp scale is + 273.16. Should be changed everywhere. + LDBLE p0 = 9.99843e2 + tc * ( 1.58729e-2 + tc * (-5.90233e-3 + tc * ( 1.96602e-5 + tc * -3.77118E-08))); + LDBLE p1 = 5.15090e-2 + tc * (-3.65419e-4 + tc * ( 5.36431e-6 + tc * (-2.74401e-8 + tc * 6.26304E-11))); + LDBLE p2 = -5.50294e-6 + tc * ( 1.07699e-7 + tc * (-2.05409e-9 + tc * ( 1.30238e-11 + tc * -3.20982E-14))); + + /* The minimal pressure equals the saturation pressure... */ + p_sat = exp(11.6702 - 3816.44 / (T - 46.13)) * ah2o_x; + ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x + if (pa < p_sat || (use.Get_solution_ptr() && use.Get_solution_ptr()->Get_patm() < p_sat)) + { + pa = p_sat; + } + patm_x = pa; + rho_0 = p0 + pa * (p1 + pa * p2); + + /* compressibility, d(ln(rho)) / d(P), 1/atm... */ + kappa_0 = (p1 + 2 * pa * p2) / rho_0; + + /* for tc < 99, P < 3 atm, use the more accurate eqn. 2.6... */ + if (tc <= 99 && pa < 3.0) + { + LDBLE Tc = 647.096, th = 1 - T / Tc; + LDBLE b1 = 1.99274064, b2 = 1.09965342, b3 = -0.510839303, + b4 = -1.75493479, b5 = -45.5170352, b6 = -6.7469445e5; + rho_0 = 322.0 * (1.0 + b1 * pow(th, (LDBLE) 1./3.) + b2 * pow(th, (LDBLE) 2./3.) + b3 * pow(th, (LDBLE) 5./3.) +\ + b4 * pow(th, (LDBLE) 16./3.) + b5 * pow(th, (LDBLE) 43./3.) + b6 * pow(th, (LDBLE) 110./3)); + } + + return (rho_0 / 1e3); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_dielectrics(LDBLE tc, LDBLE pa) +/* ---------------------------------------------------------------------- */ +{ + /* Relative dielectric constant of pure water, eps as a function of (P, T) + Bradley and Pitzer, 1979, JPC 83, 1599. + (newer data in Fernandez et al., 1995, JPCRD 24, 33, + and Fernandez et al., 1997, JPCRD 26, 1125, show its correctness) + + d(eps)/d(P), Debye-Hueckel A and B, and Av (for Av, see Pitzer et al., 1984, JPCRD 13, p. 4) + */ + LDBLE T = tc + 273.15; + LDBLE u1 = 3.4279e2, u2 = -5.0866e-3, u3 = 9.469e-7, u4 = -2.0525, + u5 = 3.1159e3, u6 = -1.8289e2, u7 = -8.0325e3, u8 = 4.2142e6, + u9 = 2.1417; + LDBLE d1000 = u1 * exp(T * (u2 + T * u3)); // relative dielectric constant at 1000 bar + LDBLE c = u4 + u5 / (u6 + T); + LDBLE b = u7 + u8 / T + u9 * T; + pa *= 1.01325; // pa in bar + eps_r = d1000 + c * log((b + pa) / (b + 1e3)); // relative dielectric constant + + /* qe^2 / (eps_r * kB * T) = 4.803204e-10**2 / 1.38065e-16 / (eps_r * T) + = 1.671008e-3 (esu^2 / (erg/K)) / (eps_r * T) */ + LDBLE e2_DkT = 1.671008e-3 / (eps_r * T); + + DH_B = sqrt(8 * pi * AVOGADRO * e2_DkT * rho_0 / 1e3); // Debye length kappa, 1/cm + + DH_A = DH_B * e2_DkT / (2. * LOG_10); //(mol/kg)^-0.5 + + /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ + DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pa) / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 + + DH_B /= 1e8; // kappa, 1/Angstrom + + return (OK); +} +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -277,7 +357,6 @@ copy_token(std::string &token, char **ptr) /* c != ',' && */ c != ';' && c != '\0') { - //token_ptr[i] = c; c_char[0] = c; token.append(c_char); (*ptr)++; @@ -1059,6 +1138,54 @@ string_duplicate(const char *token) strcpy(str, token); return (str); } +#ifdef HASH +/* ---------------------------------------------------------------------- */ +const char * Phreeqc:: +string_hsave(const char *str) +/* ---------------------------------------------------------------------- */ +{ +/* + * Save character string str + * + * Arguments: + * str input string to save. + * + * Returns: + * starting address of saved string (str) + */ + std::hash_map::const_iterator it; + it = strings_hash.find(str); + if (it != strings_hash.end()) + { + return (it->second->c_str()); + } + + std::string *stdstr = new std::string(str); + strings_map[*stdstr] = stdstr; + return(stdstr->c_str()); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +strings_hash_clear() +/* ---------------------------------------------------------------------- */ +{ +/* + * Save character string str + * + * Arguments: + * str input string to save. + * + * Returns: + * starting address of saved string (str) + */ + std::hash_map::iterator it; + for (it = strings_hash.begin(); it != strings_hash.end(); it++) + { + delete it->second; + } + strings_hash.clear(); +} +#else /* ---------------------------------------------------------------------- */ const char * Phreeqc:: string_hsave(const char *str) @@ -1084,6 +1211,7 @@ string_hsave(const char *str) strings_map[*stdstr] = stdstr; return(stdstr->c_str()); } +#endif /* ---------------------------------------------------------------------- */ void Phreeqc:: strings_map_clear() @@ -1129,125 +1257,111 @@ under(LDBLE xval) return (pow ((LDBLE) 10.0, xval)); /* return (exp(xval * LOG_10)) */; } - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -backspace_screen(int spaces) -/* ---------------------------------------------------------------------- */ -{ - int i; - char token[MAX_LENGTH]; - for (i = 0; i < spaces; i++) - { - token[i] = '\b'; - } - token[i] = '\0'; - screen_msg(sformatf("%s", token)); - return (OK); -} - #ifndef PHREEQCI_GUI /* ---------------------------------------------------------------------- */ int Phreeqc:: -status(int count, const char *str) +status(int count, const char *str, bool rk_string) /* ---------------------------------------------------------------------- */ { static int spinner; char sim_str[20]; char state_str[45]; char spin_str[2]; - float t2; -/* char all[MAX_LENGTH]; */ + clock_t t2; + + #ifdef PHREEQ98 if (ProcessMessages) ApplicationProcessMessages(); if (stop_calculations == TRUE) error_msg("Execution canceled by user.", STOP); #endif - if (pr.status == FALSE || phast == TRUE) return (OK); - t2 = (float) clock(); + + if (state == INITIALIZE) + { + screen_string = sformatf("\n%-80s", "Initializing..."); + screen_msg(screen_string.c_str()); + return (OK); + } + t2 = clock(); if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) return (OK); else status_timer = t2; - sprintf(sim_str, "Simulation %d.", simulation); - sprintf(state_str, " "); - sprintf(spin_str, " "); - if (state == INITIALIZE) + switch (state) { - screen_msg(sformatf("\n%-80s", "Initializing...")); - - status_on = TRUE; - return (OK); - } -/* - * If str is defined print it - */ - if (str != NULL) - { - if (status_on == TRUE) + case INITIALIZE: + break; + case TRANSPORT: + if (str != NULL) { - backspace_screen(80); - } - else - { - status_on = TRUE; - } -#ifdef DOS - backspace_screen(80); - /* if (state == TRANSPORT ) backspace_screen(80); */ - screen_msg(sformatf("%-79s", str)); -#else - screen_msg(sformatf("%-80s", str)); -#endif - } - else if (state != TRANSPORT && state != PHAST) - { - if (state == INITIAL_SOLUTION) - { - sprintf(state_str, "Initial solution %d.", - use.Get_solution_ptr()->n_user); - } - else if (state == INITIAL_EXCHANGE) - { - //sprintf(state_str, "Initial exchange %d.", - // (cxxExchange *) use.Get_exchange_ptr()->n_user); - sprintf(state_str, "Initial exchange %d.", - ((cxxExchange *) (use.Get_exchange_ptr()))->Get_n_user()); - } - else if (state == INITIAL_SURFACE) - { - sprintf(state_str, "Initial surface %d.", - use.Get_surface_ptr()->n_user); - } - else if (state == INVERSE) - { - sprintf(state_str, "Inverse %d. Models = %d.", - use.Get_inverse_ptr()->n_user, count); - } - else if (state == REACTION) - { - if (use.Get_kinetics_in() == TRUE) + if (rk_string) { - sprintf(state_str, "Kinetic step %d.", reaction_step); + + screen_string = screen_string.substr(0, 43); + screen_string.append(str); + screen_msg(screen_string.c_str()); } else { - sprintf(state_str, "Reaction step %d.", reaction_step); + screen_string = "\r"; + screen_string.append(str); + screen_msg(screen_string.c_str()); } } - else if (state == ADVECTION || state == TRANSPORT) + case PHAST: + break; + default: + // if str not NULL, print it + if (str != NULL && !rk_string) { - if (state == ADVECTION) + screen_string = "\r"; + screen_string.append(str); + screen_msg(screen_string.c_str()); + } + else + // print state + { + std::string stdstr; + if (str != NULL && rk_string) { - sprintf(state_str, "Advection, shift %d.", advection_step); + stdstr = str; } - else if (state == TRANSPORT) + sprintf(sim_str, "\rSimulation %d.", simulation); + sprintf(state_str, " "); + sprintf(spin_str, " "); + switch (state) { - sprintf(state_str, "Transport, shift %d.", transport_step); + default: + break; + case INITIAL_SOLUTION: + sprintf(state_str, "Initial solution %d.", use.Get_solution_ptr()->Get_n_user()); + break; + case INITIAL_EXCHANGE: + sprintf(state_str, "Initial exchange %d.", use.Get_exchange_ptr()->Get_n_user()); + break; + case INITIAL_SURFACE: + sprintf(state_str, "Initial surface %d.", use.Get_surface_ptr()->Get_n_user()); + break; + case INVERSE: + sprintf(state_str, "Inverse %d. Models = %d.", use.Get_inverse_ptr()->n_user, count); + break; + case REACTION: + if (use.Get_kinetics_in() == TRUE) + { + sprintf(state_str, "Kinetic step %d.", reaction_step); + } + else + { + sprintf(state_str, "Reaction step %d.", reaction_step); + } + break; + case ADVECTION: + sprintf(state_str, "Advection, shift %d.", advection_step); + break; } spinner++; if (spinner == 1) @@ -1263,38 +1377,19 @@ status(int count, const char *str) spin_str[0] = '\\'; spinner = 0; } + if (use.Get_kinetics_in() == TRUE) + { + screen_string = sformatf("%-15s%-27s%38s", sim_str, state_str, stdstr.c_str()); + screen_msg(screen_string.c_str()); + } + else + { + screen_string = sformatf("%-15s%-27s%1s%37s", sim_str, state_str, spin_str, stdstr.c_str()); + screen_msg(screen_string.c_str()); + } } - if (status_on == TRUE) - { - backspace_screen(80); - } - else - { - status_on = TRUE; - } - if (use.Get_kinetics_in() == TRUE) - { -#ifdef DOS - backspace_screen(80); - screen_msg(sformatf("%-15s%-27s%37s", sim_str, state_str, - " ")); -#else - screen_msg(sformatf("%-15s%-27s%38s", sim_str, state_str, - " ")); -#endif - - } - else - { -#ifdef DOS - backspace_screen(80); - screen_msg(sformatf("%-15s%-27s%1s%36s", sim_str, - state_str, spin_str, " ")); -#else - screen_msg(sformatf("%-15s%-27s%1s%37s", sim_str, - state_str, spin_str, " ")); -#endif - } + status_on = true; + break; } return (OK); } diff --git a/runner.cpp b/runner.cpp index c36ea8ad..5e454c70 100644 --- a/runner.cpp +++ b/runner.cpp @@ -63,12 +63,6 @@ bool runner::Read(CParser & parser) opt_save = opt; } - //// Read dump entity list of numbers or number ranges for line, store in item - //if (opt >= 0 && opt <= 1) - //{ - - //} - // Process other identifiers std::set < int >::iterator it; switch (opt) From a35fb059dd9022180df9796d2d95e4581b33710d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Mar 2012 05:14:19 +0000 Subject: [PATCH 0437/1077] fixed memory leak caused by duplicate numbered solutions (see ex12 -- solution 0) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6270 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 3311f0a2..29e49631 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -4989,6 +4989,10 @@ read_solution(void) it->second.Set_pe_reaction(isoln_ptr->Get_default_pe()); } } + if (Rxn_solution_map.find(n_user) != Rxn_solution_map.end()) + { + Rxn_solution_map.erase(Rxn_solution_map.find(n_user)); + } Rxn_solution_map[n_user] = temp_solution; return (return_value); From fd26a7edb1ce044d19c5449504adb2512f42350b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 7 Mar 2012 05:43:33 +0000 Subject: [PATCH 0438/1077] fixed memory leak caused by duplicate numbered solutions (see ex12 -- solution 0) (previous fix was just a band-aid) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6271 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 3 +++ phreeqc/read.cpp | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index f6a2c38d..05197918 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -51,6 +51,7 @@ cxxSolution::cxxSolution(PHRQ_io * io) this->initial_data = NULL; } cxxSolution::cxxSolution(const cxxSolution &old_sol) +: initial_data(NULL) { *this = old_sol; } @@ -80,6 +81,8 @@ cxxSolution::operator =(const cxxSolution &rhs) this->master_activity = rhs.master_activity; this->species_gamma = rhs.species_gamma; this->isotopes = rhs.isotopes; + if (this->initial_data) + delete initial_data; if (rhs.initial_data != NULL) this->initial_data = new cxxISolution(*rhs.initial_data); else diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 29e49631..3311f0a2 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -4989,10 +4989,6 @@ read_solution(void) it->second.Set_pe_reaction(isoln_ptr->Get_default_pe()); } } - if (Rxn_solution_map.find(n_user) != Rxn_solution_map.end()) - { - Rxn_solution_map.erase(Rxn_solution_map.find(n_user)); - } Rxn_solution_map[n_user] = temp_solution; return (return_value); From c892ae27f93c54084c5c428b388797770a4b5217 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 29 Mar 2012 02:47:43 +0000 Subject: [PATCH 0439/1077] BasicObj git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6308 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 6 ++++-- PBasic.h | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 58e3eedc..d61f6f8d 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,7 +1,7 @@ #if defined(WIN32) #include #if defined(PHREEQCI_GUI) -#include "resource.h" +#include "../../resource.h" #endif #else #define _ASSERTE assert @@ -58,8 +58,10 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io) parse_whole_program = true; #if defined(PHREEQCI_GUI) hInfiniteLoop = 0; -#endif + nIDErrPrompt = 0; +#else nIDErrPrompt = (PBasic::IDErr)0; +#endif nErrLineNumber = 0; // Basic commands initialized at bottom of file } diff --git a/PBasic.h b/PBasic.h index d8ab2d3a..456f7dc1 100644 --- a/PBasic.h +++ b/PBasic.h @@ -338,6 +338,10 @@ public: int Get_nErrLineNumber(void) const {return nErrLineNumber;}; void Set_nErrLineNumber(int i) {nErrLineNumber = i;}; #if defined(PHREEQCI_GUI) + UINT Get_nIDErrPrompt(void)const {return nIDErrPrompt;}; + void Set_nIDErrPrompt(UINT u) {nIDErrPrompt = u;}; + int Get_P_escapecode(void)const {return P_escapecode;}; + void Set_P_escapecode(int code) {P_escapecode = code;}; HANDLE Get_hInfiniteLoop(void) const {return hInfiniteLoop;}; void Set_hInfiniteLoop(HANDLE h) {hInfiniteLoop = h;}; #endif From 4b5f269224040774da5512d29f368c810ea3ea82 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 29 Mar 2012 04:22:37 +0000 Subject: [PATCH 0440/1077] updated to use windows malloc debug git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6309 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/phqalloc.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phreeqc/phqalloc.cpp b/phreeqc/phqalloc.cpp index 52da5482..d8b82906 100644 --- a/phreeqc/phqalloc.cpp +++ b/phreeqc/phqalloc.cpp @@ -243,7 +243,11 @@ PHRQ_malloc(size_t size) #endif /* ---------------------------------------------------------------------- */ { +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + return _malloc_dbg(size, _NORMAL_BLOCK, szFileName, nLine); +#else return malloc(size); +#endif } /* ---------------------------------------------------------------------- */ @@ -251,7 +255,11 @@ void Phreeqc:: PHRQ_free(void *ptr) /* ---------------------------------------------------------------------- */ { +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + _free_dbg(ptr, _NORMAL_BLOCK); +#else free(ptr); +#endif } /* ---------------------------------------------------------------------- */ @@ -270,7 +278,11 @@ PHRQ_calloc(size_t num, size_t size) #endif /* ---------------------------------------------------------------------- */ { +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + return _calloc_dbg(num, size, _NORMAL_BLOCK, szFileName, nLine); +#else return calloc(num, size); +#endif } /* ---------------------------------------------------------------------- */ @@ -282,6 +294,10 @@ PHRQ_realloc(void *ptr, size_t size) #endif /* ---------------------------------------------------------------------- */ { +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + return _realloc_dbg(ptr, size, _NORMAL_BLOCK, szFileName, nLine); +#else return realloc(ptr, size); +#endif } #endif /* USE_PHRQ_ALLOC */ From 4f70c3947b771a6c21516ccb629bfb74634f243c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 00:17:31 +0000 Subject: [PATCH 0441/1077] added const versions git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6316 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Surface.cxx | 10 ++++++++++ Surface.h | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Surface.cxx b/Surface.cxx index 26d23d72..2121cb87 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -804,6 +804,16 @@ Find_charge(std::string str) } return NULL; } +const cxxSurfaceCharge * cxxSurface:: +Find_charge(std::string str)const +{ + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + if (Utilities::strcmp_nocase(str.c_str(), this->surface_charges[i].Get_name().c_str()) == 0) + return &(this->surface_charges[i]); + } + return NULL; +} void cxxSurface:: Sort_comps(void) { diff --git a/Surface.h b/Surface.h index c11a93ea..b2cf3c4b 100644 --- a/Surface.h +++ b/Surface.h @@ -36,6 +36,7 @@ public: void totalize(); cxxSurfaceComp *Find_comp(std::string str); cxxSurfaceCharge *Find_charge(const std::string str); + const cxxSurfaceCharge *Find_charge(const std::string str)const; void Sort_comps(); #ifdef USE_MPI @@ -47,6 +48,7 @@ public: void multiply(LDBLE extensive); std::vector < cxxSurfaceComp > & Get_surface_comps() {return this->surface_comps;} + const std::vector < cxxSurfaceComp > & Get_surface_comps()const {return this->surface_comps;} void Set_surface_comps(std::vector < cxxSurfaceComp > &sc) {this->surface_comps = sc;} std::vector < cxxSurfaceCharge > & Get_surface_charges() {return this->surface_charges;} void Set_surface_charges(std::vector < cxxSurfaceCharge > &sc) {this->surface_charges = sc;} @@ -72,9 +74,9 @@ public: void Set_transport(bool tf) {transport = tf;} cxxNameDouble & Get_totals() {return this->totals;} void Get_totals(cxxNameDouble &nd) {this->totals = nd;} - bool Get_solution_equilibria(void) {return solution_equilibria;} + bool Get_solution_equilibria(void)const {return solution_equilibria;} void Set_solution_equilibria(bool tf) {solution_equilibria = tf;} - int Get_n_solution(void) {return n_solution;} + int Get_n_solution(void)const {return n_solution;} void Set_n_solution(int i) {n_solution = i;} protected: From 54d517d477b46caf7c73fbc1834403f91d1603d7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 02:54:35 +0000 Subject: [PATCH 0442/1077] added const versions git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6319 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.h | 2 ++ cxxKinetics.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/KineticsComp.h b/KineticsComp.h index 843f296d..747003e5 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -36,6 +36,7 @@ public: } cxxNameDouble &Get_namecoef(void) {return namecoef;} + const cxxNameDouble &Get_namecoef(void)const {return namecoef;} void Set_namecoef(const cxxNameDouble nd) {namecoef = nd;} LDBLE Get_tol(void) const {return tol;} void Set_tol(LDBLE t) {tol = t;} @@ -48,6 +49,7 @@ public: LDBLE Get_initial_moles(void) const {return initial_moles;} void Set_initial_moles(LDBLE t) {initial_moles = t;} std::vector < LDBLE > &Get_d_params(void) {return d_params;}; + const std::vector < LDBLE > &Get_d_params(void)const {return d_params;}; std::vector < std::string > &Get_c_params(void) {return c_params;}; #ifdef USE_MPI diff --git a/cxxKinetics.h b/cxxKinetics.h index 62c1bf7f..ce4d8c3d 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -28,6 +28,7 @@ class cxxKinetics:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); std::vector < LDBLE > &Get_steps(void) {return steps;} + const std::vector < LDBLE > &Get_steps(void)const {return steps;} LDBLE Get_step_divide(void) const {return step_divide;} void Set_step_divide(LDBLE t) {step_divide = t;} int Get_rk(void) const {return rk;}; @@ -41,6 +42,7 @@ class cxxKinetics:public cxxNumKeyword int Get_cvode_order(void) const {return cvode_order;} void Set_cvode_order(int t) {cvode_order = t;} std::vector < cxxKineticsComp > &Get_kinetics_comps(void) {return kinetics_comps;} + const std::vector < cxxKineticsComp > &Get_kinetics_comps(void)const {return kinetics_comps;} cxxNameDouble & Get_totals(void) {return this->totals;} void Set_totals(const cxxNameDouble &nd) {totals = nd;} bool Get_equalIncrements(void) const {return equalIncrements;} From 1ad10142ab8679012dfa0dbee7324b550e520099 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 03:55:12 +0000 Subject: [PATCH 0443/1077] added serializing code for selected_output file name git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6322 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 3311f0a2..633007e3 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -4352,6 +4352,7 @@ read_selected_output(void) input_error++; error_msg(error_string, CONTINUE); } + selected_output_file_name = string_duplicate(file_name); } opt_save = OPTION_ERROR; break; From 3df08dd0f1836f85ea74c5eb2dab119d02d7f735 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 21:49:57 +0000 Subject: [PATCH 0444/1077] made iso_defaults public and static git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6324 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 58 +- Phreeqc.h | 1865 ----------------------------------- phreeqc/global_structures.h | 7 + 3 files changed, 23 insertions(+), 1907 deletions(-) delete mode 100644 Phreeqc.h diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 566567eb..2f87ff1e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -15,6 +15,21 @@ #include "Temperature.h" #include "SSassemblage.h" +const struct const_iso Phreeqc::iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} +}; + +const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso)); + Phreeqc::Phreeqc(PHRQ_io *io) { if (io) @@ -43,42 +58,8 @@ Phreeqc::Phreeqc(PHRQ_io *io) sit_IPRSNT = NULL; sit_M = NULL; - struct const_iso - { - const char *name; - LDBLE value; - LDBLE uncertainty; - }; - - - struct const_iso temp_iso_defaults[] = { - {"13C", -10, 1}, - {"13C(4)", -10, 1}, - {"13C(-4)", -50, 5}, - {"34S", 10, 1}, - {"34S(6)", 10, 1}, - {"34S(-2)", -30, 5}, - {"2H", -28, 1}, - {"18O", -5, .1}, - {"87Sr", .71, .01}, - {"11B", 20, 5} - }; - int temp_count_iso_defaults = - (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); - - count_iso_defaults = temp_count_iso_defaults; - iso_defaults = new iso[count_iso_defaults]; - - int i; - for (i = 0; i < temp_count_iso_defaults; i++) - { - iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); - iso_defaults[i].value = temp_iso_defaults[i].value; - iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; - } - // counters for enum KEYWORDS - for (i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) { keycount.push_back(0); } @@ -150,13 +131,6 @@ Phreeqc::~Phreeqc(void) this->phrq_io->close_ostreams(); } - int i; - for (i = 0; i < count_iso_defaults; i++) - { - iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); - } - delete[] iso_defaults; - free_check_null(default_data_base); free_check_null(sformatf_buffer); diff --git a/Phreeqc.h b/Phreeqc.h deleted file mode 100644 index 9079c9d3..00000000 --- a/Phreeqc.h +++ /dev/null @@ -1,1865 +0,0 @@ -#ifndef _INC_PHREEQC_H -#define _INC_PHREEQC_H -#if defined(WIN32) -#include -#endif -#if defined(WIN32_MEMORY_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif -/* ---------------------------------------------------------------------- -* INCLUDE FILES -* ---------------------------------------------------------------------- */ -#include -#include -#include -#include -#ifdef HASH -#include -#endif -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "cvdense.h" -#include "runner.h" -#include "dumper.h" -#include "PHRQ_io.h" -#ifdef MULTICHART -#include "ChartHandler.h" -#endif -#include "Keywords.h" -#include "Pressure.h" -#include "cxxMix.h" -#include "Use.h" -#include "Surface.h" - -class cxxNameDouble; -class cxxKinetics; -//class cxxMix; -class cxxKineticsComp; -class cxxExchange; -class cxxExchComp; -class cxxGasPhase; -class cxxTemperature; -class cxxPPassemblage; -class cxxPPassemblageComp; -class cxxReaction; -class cxxSolution; -class cxxISolutionComp; -class cxxSolutionIsotope; -class cxxSSassemblage; -class cxxSS; -class cxxStorageBin; - -#include "global_structures.h" -class PBasic; - -class Phreeqc -{ -public: - Phreeqc(PHRQ_io *io = NULL); - ~Phreeqc(void); - -public: - // - // Phreeqc class methods - // - - // advection.cpp ------------------------------- - int advection(void); - - // basicsubs.cpp ------------------------------- - int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); - int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); - void basic_free(void); - - LDBLE activity(const char *species_name); - LDBLE activity_coefficient(const char *species_name); - LDBLE log_activity_coefficient(const char *species_name); - LDBLE calc_SC(void); - /* VP: Density Start */ - LDBLE calc_dens(void); - /* VP: Density End */ - LDBLE calc_logk_n(const char *name); - LDBLE calc_logk_p(const char *name); - LDBLE calc_logk_s(const char *name); - LDBLE calc_surface_charge(const char *surface_name); - LDBLE diff_layer_total(const char *total_name, const char *surface_name); - LDBLE equi_phase(const char *phase_name); - LDBLE find_gas_comp(const char *gas_comp_name); - LDBLE find_gas_p(void); - LDBLE find_gas_vm(void); - LDBLE find_misc1(const char *ss_name); - LDBLE find_misc2(const char *ss_name); - LDBLE find_ss_comp(const char *ss_comp_name); - LDBLE get_calculate_value(const char *name); - char * iso_unit(const char *total_name); - LDBLE iso_value(const char *total_name); - LDBLE kinetics_moles(const char *kinetics_name); - LDBLE log_activity(const char *species_name); - LDBLE log_molality(const char *species_name); - LDBLE molality(const char *species_name); - LDBLE pressure(void); - LDBLE pr_pressure(const char *phase_name); - LDBLE pr_phi(const char *phase_name); - LDBLE saturation_ratio(const char *phase_name); - int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); - LDBLE solution_sum_secondary(const char *total_name); - LDBLE sum_match_gases(const char *stemplate, const char *name); - LDBLE sum_match_species(const char *stemplate, const char *name); - LDBLE sum_match_ss(const char *stemplate, const char *name); - int match_elts_in_species(const char *name, const char *stemplate); - int extract_bracket(char **string, char *bracket_string); - LDBLE surf_total(const char *total_name, const char *surface_name); - static int system_species_compare(const void *ptr1, const void *ptr2); - LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); - std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); - LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); - int system_total_elements(void); - int system_total_si(void); - int system_total_aq(void); - int system_total_ex(void); - int system_total_surf(void); - int system_total_gas(void); - int system_total_ss(void); - int system_total_elt(const char *total_name); - int system_total_elt_secondary(const char *total_name); - LDBLE total(const char *total_name); - LDBLE total_mole(const char *total_name); - int system_total_solids(cxxExchange *exchange_ptr, - cxxPPassemblage *pp_assemblage_ptr, - cxxGasPhase *gas_phase_ptr, - cxxSSassemblage *ss_assemblage_ptr, - cxxSurface *surface_ptr); - - static LDBLE f_rho(LDBLE rho_old, void *cookie); - static LDBLE f_Vm(LDBLE v1, void *cookie); - // chart.cpp -#if defined PHREEQ98 - void DeleteCurves(void); - void ExtractCurveInfo(char *line, int curvenr); - void GridChar(char *s, char *a); - void MallocCurves(int nc, int ncxy); - int OpenCSVFile(char file_name[MAX_LENGTH]); - void SaveCurvesToFile(char file_name[MAX_LENGTH]); - void PlotXY(char *x, char *y); - void ReallocCurves(int new_nc); - void ReallocCurveXY(int i); - void SetAxisScale(char *a, int j, char *token, int true_); - void SetAxisTitles(char *s, int i); - void SetChartTitle(char *s); - void start_chart(bool end); -#endif - - // cl1.cpp ------------------------------- - int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q, - int *kode, LDBLE toler, - int *iter, LDBLE * x, LDBLE * res, LDBLE * error, - LDBLE * cu, int *iu, int *s, int check); - void cl1_space(int check, int n2d, int klm, int nklmd); - - // cl1mp.cpp ------------------------------- - int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - - // class_main.cpp ------------------------------- - int write_banner(void); - - /* default.cpp */ -public: - int close_input_files(void); - int close_output_files(void); - static int istream_getc(void *cookie); - int process_file_names(int argc, char *argv[], std::istream **db_cookie, - std::istream **input_cookie, int log); - - /* PHRQ_io_output.cpp */ - void screen_msg(const char * str); - - void echo_msg(const char *err_str); - int warning_msg(const char *err_str); - void set_forward_output_to_log(int value); - int get_forward_output_to_log(void); - - // dump_ostream - bool dump_open(const char *file_name); - void dump_flush(void); - void dump_close(void); - void dump_msg(const char * str); - - // log_ostream - bool log_open(const char *file_name); - void log_flush(void); - void log_close(void); - void log_msg(const char * str); - - // error_ostream - bool error_open(const char *file_name); - void error_flush(void); - void error_close(void); - void error_msg(const char * str, bool stop=false); - - // output_ostream - bool output_open(const char *file_name); - void output_flush(void); - void output_close(void); - void output_msg(const char * str); - - // punch_ostream - bool punch_open(const char *file_name); - void punch_flush(void); - void punch_close(void); - void punch_msg(const char * str); - - void fpunchf_heading(const char *name); - void fpunchf(const char *name, const char *format, double d); - void fpunchf(const char *name, const char *format, char * d); - void fpunchf(const char *name, const char *format, int d); - void fpunchf_user(int user_index, const char *format, double d); - void fpunchf_user(int user_index, const char *format, char * d); - int fpunchf_end_row(const char *format); - - // dw.cpp ------------------------------- - int BB(LDBLE T); - LDBLE PS(LDBLE T); - LDBLE VLEST(LDBLE T); - int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); - int QQ(LDBLE T, LDBLE D); - LDBLE BASE(LDBLE D); - - // input.cpp ------------------------------- - int reading_database(void); - void set_reading_database(int reading_database); - int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); - - // integrate.cpp ------------------------------- - int calc_all_g(void); - int calc_init_g(void); - int initial_surface_water(void); - int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); - int calc_all_donnan(void); - int calc_init_donnan(void); - LDBLE g_function(LDBLE x_value); - LDBLE midpnt(LDBLE x1, LDBLE x2, int n); - void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); - LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); - LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); - int calc_all_donnan_music(void); - int calc_init_donnan_music(void); - - // inverse.cpp ------------------------------- - int inverse_models(void); - int add_to_file(const char *filename, const char *string); - int bit_print(unsigned long bits, int l); - int carbon_derivs(struct inverse *inv_ptr); - int check_isotopes(struct inverse *inv_ptr); - int check_solns(struct inverse *inv_ptr); - int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); - cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); - LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); - int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); - int post_mortem(void); - bool test_cl1_solution(void); - unsigned long get_bits(unsigned long bits, int position, int number); - unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); - void dump_netpath(struct inverse *inv_ptr); - int dump_netpath_pat(struct inverse *inv_ptr); - int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); - int phase_isotope_inequalities(struct inverse *inv_ptr); - int print_model(struct inverse *inv_ptr); - int punch_model_heading(struct inverse *inv_ptr); - int punch_model(struct inverse *inv_ptr); - void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); - - void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); - int range(struct inverse *inv_ptr, unsigned long cur_bits); - int save_bad(unsigned long bits); - int save_good(unsigned long bits); - int save_minimal(unsigned long bits); - unsigned long set_bit(unsigned long bits, int position, int value); - int setup_inverse(struct inverse *inv_ptr); - int set_initial_solution(int n_user_old, int n_user_new); - int set_ph_c(struct inverse *inv_ptr, - int i, cxxSolution *soln_ptr_orig, int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); - int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); - int solve_inverse(struct inverse *inv_ptr); - int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); - int subset_bad(unsigned long bits); - int subset_minimal(unsigned long bits); - int superset_minimal(unsigned long bits); - int write_optimize_names(struct inverse *inv_ptr); - - // isotopes.cpp ------------------------------- - int add_isotopes(cxxSolution &solution_ptr); - int calculate_values(void); - int calculate_isotope_moles(struct element *elt_ptr, - cxxSolution *solution_ptr, LDBLE total_moles); - LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); - int from_pcil(struct master_isotope *master_isotope_ptr); - int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_tu(struct master_isotope *master_isotope_ptr); - struct calculate_value *calculate_value_alloc(void); - int calculate_value_free(struct calculate_value *calculate_value_ptr); - struct calculate_value *calculate_value_search(const char *name); - struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); - struct isotope_alpha *isotope_alpha_alloc(void); - struct isotope_alpha *isotope_alpha_search(const char *name); - struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); - struct isotope_ratio *isotope_ratio_alloc(void); - struct isotope_ratio *isotope_ratio_search(const char *name); - struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_alloc(void); - struct master_isotope *master_isotope_search(const char *name); - int print_initial_solution_isotopes(void); - int print_isotope_ratios(void); - int print_isotope_alphas(void); - int punch_isotopes(void); - int punch_calculate_values(void); - int read_calculate_values(void); - int read_isotopes(void); - int read_isotope_ratios(void); - int read_isotope_alphas(void); - int calculate_value_init(struct calculate_value *calculate_value_ptr); - int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); - int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); - int master_isotope_init(struct master_isotope *master_isotope_ptr); - - // kinetics.cpp ------------------------------- - void cvode_init(void); - int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); - int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_advection(int i, int use_mix, int use_kinetics, int nsaver); - int free_cvode(void); -public: - static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); - static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - - int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); - int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, - LDBLE time_step); - int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); - int set_reaction(int i, int use_mix, int use_kinetics); - int set_transport(int i, int use_mix, int use_kinetics, int nsaver); - int store_get_equi_reactants(int k, int kin_end); - int count_pp, count_pg, count_ss; - LDBLE *x0_moles; - - // mainsubs.cpp ------------------------------- - std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - int copy_entities(void); - void initialize(void); - int initial_exchangers(int print); - int initial_gas_phases(int print); - int initial_solutions(int print); - int step_save_exch(int n_user); - int step_save_surf(int n_user); - int initial_surfaces(int print); - int reactions(void); - int saver(void); - int xsolution_save(int k_user); - int xexchange_save(int n_user); - int xgas_save(int n_user); - int xpp_assemblage_save(int n_user); - int xss_assemblage_save(int n_user); - int xsurface_save(int n_user); - int do_initialize(void); - int do_status(void); - void save_init(int i); - int copy_use(int i); - int set_use(void); - - // model.cpp ------------------------------- - int check_residuals(void); - int free_model_allocs(void); - int ineq(int kode); - int model(void); - int jacobian_sums(void); - int mb_gases(void); - int mb_ss(void); - int mb_sums(void); - int molalities(int allow_overflow); - int reset(void); - int residuals(void); - int set(int initial); - int sum_species(void); - int surface_model(void); - LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); - LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); - LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); - int numerical_jacobian(void); - void set_inert_moles(void); - void unset_inert_moles(void); -#ifdef SLNQ - int add_trivial_eqns(int rows, int cols, LDBLE * matrix); - //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -#endif - int calc_gas_pressures(void); - int calc_fixed_volume_gas_pressures(void); - int calc_ss_fractions(void); - int gammas(LDBLE mu); - int initial_guesses(void); - int revise_guesses(void); - int ss_binary(cxxSS *ss_ptr); - int ss_ideal(cxxSS *ss_ptr); - int gas_in; - void ineq_init(int max_row_count, int max_column_count); - - // parse.cpp ------------------------------- - int check_eqn(int association); - int get_charge(char *charge, LDBLE * z); - int get_elt(char **t_ptr, char *element, int *i); - int get_elts_in_species(char **t_ptr, LDBLE coef); - int get_num(char **t_ptr, LDBLE * num); - int get_secondary_in_species(char **t_ptr, LDBLE coef); - int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - int get_coef(LDBLE * coef, char **eqnaddr); - int get_secondary(char **t_ptr, char *element, int *i); - int get_species(char **ptr); - - // phqalloc.cpp ------------------------------- -public: -#if !defined(NDEBUG) - void *PHRQ_malloc(size_t, const char *, int); - void *PHRQ_calloc(size_t, size_t, const char *, int); - void *PHRQ_realloc(void *, size_t, const char *, int); -#else - void *PHRQ_malloc(size_t); - void *PHRQ_calloc(size_t, size_t); - void *PHRQ_realloc(void *, size_t); -#endif - void PHRQ_free(void *ptr); - void PHRQ_free_all(void); - -public: - - // pitzer.cpp ------------------------------- - struct pitz_param *pitz_param_read(char *string, int n); - int pitz_param_search(struct pitz_param *pzp_ptr); - int sit_param_search(struct pitz_param *pzp_ptr); - struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); - struct theta_param *theta_param_alloc(void); - int theta_param_init(struct theta_param *theta_param_ptr); - int gammas_pz(void); - int model_pz(void); - int pitzer(void); - int pitzer_clean_up(void); - int pitzer_init(void); - int pitzer_tidy(void); - int read_pitzer(void); - int set_pz(int initial); - int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_pz(void); - int ISPEC(const char *name); - LDBLE G(LDBLE Y); - LDBLE GP(LDBLE Y); - int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); - int BDK(LDBLE X); - int pitzer_initial_guesses(void); - int pitzer_revise_guesses(void); - int PTEMP(LDBLE TK); - LDBLE JAY(LDBLE X); - LDBLE JPRIME(LDBLE Y); - int jacobian_pz(void); - - // pitzer_structures.cpp ------------------------------- - struct pitz_param *pitz_param_alloc(void); - int pitz_param_init(struct pitz_param *pitz_param_ptr); - struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); - int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); - - // prep.cpp ------------------------------- - int add_potential_factor(void); - int add_cd_music_factors(int n); - int add_surface_charge_balance(void); - int add_cd_music_charge_balances(int i); - int build_gas_phase(void); - int build_fixed_volume_gas(void); - int build_jacobian_sums(int k); - int build_mb_sums(void); - int build_min_exch(void); - int build_model(void); - int build_pure_phases(void); - int build_ss_assemblage(void); - int build_solution_phase_boundaries(void); - int build_species_list(int n); - int build_min_surface(void); - LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); - LDBLE calc_delta_v(reaction * r_ptr, bool phase); - LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); - LDBLE calc_PR(); - int calc_vm(LDBLE tc, LDBLE pa); - int change_hydrogen_in_elt_list(LDBLE charge); - int clear(void); - //int convert_units(struct solution *solution_ptr); - int convert_units(cxxSolution *solution_ptr); - LDBLE a_aa_sum, b2, b_sum, R_TK; - LDBLE f_Vm(LDBLE v1); - struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); - struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); - int inout(void); - int is_special(struct species *spec); - int mb_for_species_aq(int n); - int mb_for_species_ex(int n); - int mb_for_species_surf(int n); - int quick_setup(void); - int resetup_master(void); - int save_model(void); - int setup_exchange(void); - int setup_gas_phase(void); - int setup_fixed_volume_gas(void); - int setup_slack(void); - int setup_master_rxn(struct master **master_ptr_list, - const std::string &pe_rxn); - int setup_pure_phases(void); - int adjust_setup_pure_phases(void); - int setup_related_surface(void); - int setup_ss_assemblage(void); - int setup_solution(void); - int adjust_setup_solution(void); - int setup_surface(void); - int setup_unknowns(void); - int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); - int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); - int store_jacob0(int row, int column, LDBLE coef); - int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); - int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); - int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); - int tidy_redox(void); - struct master **unknown_alloc_master(void); - int write_mb_eqn_x(void); - int write_mb_for_species_list(int n); - int write_mass_action_eqn_x(int stop); - - int check_same_model(void); - int k_temp(LDBLE tc, LDBLE pa); - LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); - int prep(void); - int reprep(void); - int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); - int switch_bases(void); - int write_phase_sys_total(int n); - - // print.cpp ------------------------------- - char *sformatf(const char *format, ...); - int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); - int print_all(void); - int print_exchange(void); - int print_gas_phase(void); - int print_master_reactions(void); - int print_reaction(struct reaction *rxn_ptr); - int print_species(void); - int print_surface(void); - int print_user_print(void); - int punch_all(void); - int print_alkalinity(void); - int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); - int print_eh(void); - int print_reaction(void); - int print_kinetics(void); - int print_mix(void); - int print_pp_assemblage(void); - int print_ss_assemblage(void); - int print_saturation_indices(void); - int print_surface_cd_music(void); - int print_totals(void); - int print_using(void); - /*int print_user_print(void);*/ - int punch_gas_phase(void); - int punch_identifiers(void); - int punch_kinetics(void); - int punch_molalities(void); - int punch_activities(void); - int punch_pp_assemblage(void); - int punch_ss_assemblage(void); - int punch_saturation_indices(void); - int punch_totals(void); - int punch_user_punch(void); -#if defined MULTICHART - int punch_user_graph(void); -#endif - - // read.cpp ------------------------------- - int read_input(void); - int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); - int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); - int read_log_k_only(char *ptr, LDBLE * log_k); - int read_t_c_only(char *ptr, LDBLE *t_c); - int read_p_c_only(char *ptr, LDBLE * p_c); - int read_omega_only(char *ptr, LDBLE *omega); - int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description, int allow_negative=FALSE); - int check_key(const char *str); - int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, - const char *default_units, bool print); - int find_option(const char *item, int *n, const char **list, int count_list, - int exact); - int get_option(const char **opt_list, int count_opt_list, char **next_char); - int get_true_false(char *string, int default_value); - - int add_psi_master_species(char *token); - int read_advection(void); - int read_analytical_expression_only(char *ptr, LDBLE * log_k); - /* VP: Density Start */ - int read_millero_abcdef (char *ptr, LDBLE * abcdef); - /* VP: Density End */ - int read_copy(void); - int read_debug(void); - int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); - int read_vm_only(char *ptr, LDBLE * delta_v, - DELTA_V_UNIT * units); - int read_llnl_aqueous_model_parameters(void); - int read_exchange(void); - int read_exchange_master_species(void); - int read_exchange_species(void); - int read_gas_phase(void); - int read_incremental_reactions(void); - int read_inverse(void); - int read_inv_balances(struct inverse *inverse_ptr, char *next_char); - int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); - int read_inv_phases(struct inverse *inverse_ptr, char *next_char); - int read_kinetics(void); - int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); - LDBLE *read_list_doubles(char **ptr, int *count_doubles); - int *read_list_ints(char **ptr, int *count_ints, int positive); - int *read_list_t_f(char **ptr, int *count_ints); - int read_master_species(void); - int read_mix(void); - int read_named_logk(void); - int read_phases(void); - int read_print(void); - int read_pp_assemblage(void); - int read_rates(void); - int read_reaction(void); - int read_reaction_reactants(cxxReaction *reaction_ptr); - int read_reaction_steps(cxxReaction *reaction_ptr); - int read_solid_solutions(void); - int read_temperature(void); - int read_reaction_temps(struct temperature *temperature_ptr); - int read_reaction_pressure(void); - int read_reaction_pressure_raw(void); - int read_save(void); - int read_selected_output(void); - int read_solution(void); - int read_species(void); - int read_surface(void); - int read_surface_master_species(void); - int read_surface_species(void); - int read_use(void); - int read_title(void); - int read_user_print(void); - int read_user_punch(void); -#if defined PHREEQ98 - int read_user_graph(void); -#endif -#if defined MULTICHART - int read_user_graph_handler(); -#endif - int next_keyword_or_option(const char **opt_list, int count_opt_list); - int cleanup_after_parser(CParser &parser); - - // ReadClass.cxx - int read_dump(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); - - // readtr.cpp ------------------------------- - int read_transport(void); - int dump(void); - int dump_exchange(int k); - int dump_gas_phase(int k); - int dump_kinetics(int k); - int dump_mix(int k); - int dump_pp_assemblage(int k); - int dump_reaction(int k); - int dump_ss_assemblage(int k); - int dump_solution(int k); - int dump_surface(int k); - int dump_cpp(void); - int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - - // sit.cpp ------------------------------- - int gammas_sit(void); - int model_sit(void); - int sit(void); - int sit_clean_up(void); - int sit_init(void); - int sit_tidy(void); - int read_sit(void); - int set_sit(int initial); - int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_sit(void); - int sit_ISPEC(const char *name); - /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ - int sit_initial_guesses(void); - int sit_revise_guesses(void); - int PTEMP_SIT(LDBLE tk); - int jacobian_sit(void); - - // spread.cpp ------------------------------- - int read_solution_spread(void); - int copy_token_tab(char *token_ptr, char **ptr, int *length); - int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); - int spread_row_free(struct spread_row *spread_row_ptr); - int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); - struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI - void add_row(struct spread_row *spread_row_ptr); - void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); - void free_spread(void); - struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - - // step.cpp ------------------------------- - int step(LDBLE step_fraction); - int xsolution_zero(void); - int add_exchange(cxxExchange *exchange_ptr); - int add_gas_phase(cxxGasPhase *gas_phase_ptr); - int add_kinetics(cxxKinetics *kinetics_ptr); - int add_mix(cxxMix * mix_ptr); - int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); - int add_solution(cxxSolution *solution_ptr, LDBLE extensive, - LDBLE intensive); - int add_surface(cxxSurface *surface_ptr); - int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int gas_phase_check(cxxGasPhase *gas_phase_ptr); - int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); - int reaction_calc(cxxReaction *reaction_ptr); - int solution_check(void); - int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); - - // structures.cpp ------------------------------- - int clean_up(void); - int reinitialize(void); - int copier_add(struct copier *copier_ptr, int n_user, int start, int end); - int copier_free(struct copier *copier_ptr); - int copier_init(struct copier *copier_ptr); - static int element_compare(const void *ptr1, const void *ptr2); -public: - struct element *element_store(const char *element); - int elt_list_combine(void); - static int elt_list_compare(const void *ptr1, const void *ptr2); -protected: - struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); - int elt_list_print(struct elt_list *elt_list_ptr); - struct elt_list *elt_list_save(void); - cxxNameDouble elt_list_NameDouble(void); -public: - enum entity_type get_entity_enum(char *name); - struct inverse *inverse_alloc(void); - int inverse_delete(int i); - static int inverse_isotope_compare(const void *ptr1, const void *ptr2); - struct inverse *inverse_search(int n_user, int *n); - int inverse_sort(void); -protected: - struct logk *logk_alloc(void); - int logk_copy2orig(struct logk *logk_ptr); - struct logk *logk_store(char *name, int replace_if_found); - struct logk *logk_search(const char *name); - struct master *master_alloc(void); - static int master_compare(const void *ptr1, const void *ptr2); - int master_delete(char *ptr); -public: - struct master *master_bsearch(const char *ptr); - struct master *master_bsearch_primary(const char *ptr); - struct master *master_bsearch_secondary(char *ptr); - struct master *master_search(char *ptr, int *n); - struct pe_data *pe_data_alloc(void); -public: - struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); - struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -protected: - int pe_data_store(struct pe_data **pe, const char *token); -public: - struct phase *phase_bsearch(const char *ptr, int *j, int print); -protected: - static int phase_compare(const void *ptr1, const void *ptr2); - int phase_delete(int i); - struct phase *phase_store(const char *name); -public: - struct rate *rate_bsearch(char *ptr, int *j); - int rate_free(struct rate *rate_ptr); - struct rate *rate_search(const char *name, int *n); - int rate_sort(void); - struct reaction *rxn_alloc(int ntokens); - struct reaction *rxn_dup(struct reaction *rxn_ptr_old); - LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); - int rxn_free(struct reaction *rxn_ptr); - int rxn_print(struct reaction *rxn_ptr); - static int s_compare(const void *ptr1, const void *ptr2); - int s_delete(int i); - struct species *s_search(const char *name); - struct species *s_store(const char *name, LDBLE z, int replace_if_found); -protected: - struct save_values *save_values_bsearch(struct save_values *k, int *n); - static int save_values_compare(const void *ptr1, const void *ptr2); - int save_values_sort(void); - int save_values_store(struct save_values *s_v); - static int isotope_compare(const void *ptr1, const void *ptr2); - static int species_list_compare_alk(const void *ptr1, const void *ptr2); - static int species_list_compare_master(const void *ptr1, const void *ptr2); - int species_list_sort(void); - struct Change_Surf *change_surf_alloc(int count); -public: - struct master *surface_get_psi_master(const char *name, int plane); - int system_duplicate(int i, int save_old); - int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); - int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_combine(void); - int trxn_copy(struct reaction *rxn_ptr); - LDBLE trxn_find_coef(const char *str, int start); - int trxn_print(void); - int trxn_reverse_k(void); - int trxn_sort(void); - int trxn_swap(const char *token); - struct unknown *unknown_alloc(void); - int unknown_delete(int i); - int unknown_free(struct unknown *unknown_ptr); - int entity_exists(char *name, int n_user); - static int inverse_compare(const void *ptr1, const void *ptr2); - int inverse_free(struct inverse *inverse_ptr); - static int kinetics_compare_int(const void *ptr1, const void *ptr2); - int logk_init(struct logk *logk_ptr); - static int master_compare_string(const void *ptr1, const void *ptr2); - int master_free(struct master *master_ptr); - struct phase *phase_alloc(void); - static int phase_compare_string(const void *ptr1, const void *ptr2); - int phase_free(struct phase *phase_ptr); - int phase_init(struct phase *phase_ptr); - static int rate_compare(const void *ptr1, const void *ptr2); - static int rate_compare_string(const void *ptr1, const void *ptr2); - struct species *s_alloc(void); - int s_free(struct species *s_ptr); - int s_init(struct species *s_ptr); - static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); - static int solution_compare(const void *ptr1, const void *ptr2); - static int solution_compare_int(const void *ptr1, const void *ptr2); - static int species_list_compare(const void *ptr1, const void *ptr2); - static int surface_compare_int(const void *ptr1, const void *ptr2); - static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); - int trxn_multiply(LDBLE coef); -#ifdef PHREEQCI_GUI - extern void free_spread(void); -#endif -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - extern void MergeFinalize(void); -#endif - struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); - struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); - struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); - struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); - - void Use2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb); - - /* tally.cpp */ - void add_all_components_tally(void); - int build_tally_table(void); - int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); - int diff_tally_table(void); - int extend_tally_table(void); - int free_tally_table(void); - int fill_tally_table(int *n_user, int index_conservative, int n_buffer); - int get_tally_table_rows_columns(int *rows, int *columns); - int get_tally_table_column_heading(int column, int *type, char *string); - int get_tally_table_row_heading(int column, char *string); - int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); - int zero_tally_table(void); - int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); - int get_all_components(void); - int print_tally_table(void); - int set_reaction_moles(int n_user, LDBLE moles); - int set_reaction_temperature(int n_user, LDBLE tc); - int set_kinetics_time(int n_user, LDBLE step); - - // tidy.cpp ------------------------------- - int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); - int add_logks(struct logk *logk_ptr, int repeats); - LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); - int replace_solids_gases(void); - int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); - int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); - int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -public: - int tidy_punch(void); - int tidy_model(void); - int check_species_input(void); - LDBLE coef_in_master(struct master *master_ptr); - int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); - int reset_last_model(void); - int rewrite_eqn_to_primary(void); - int rewrite_eqn_to_secondary(void); - int species_rxn_to_trxn(struct species *s_ptr); - int tidy_logk(void); - int tidy_exchange(void); - int tidy_min_exchange(void); - int tidy_kin_exchange(void); - int tidy_gas_phase(void); - int tidy_inverse(void); - int tidy_isotopes(void); - int tidy_isotope_ratios(void); - int tidy_isotope_alphas(void); - int tidy_kin_surface(void); - int tidy_master_isotope(void); - int tidy_min_surface(void); - int tidy_phases(void); - int tidy_pp_assemblage(void); - int tidy_solutions(void); - int tidy_ss_assemblage(void); - int tidy_species(void); - int tidy_surface(void); - int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); - static LDBLE f_spinodal(LDBLE x, void *); - int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); - int ss_calc_a0_a1(cxxSS *ss_ptr); - - // transport.cpp ------------------------------- - int transport(void); - int set_initial_moles(int i); - cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, - cxxSurface *source2, std::string charge_name, LDBLE f2, - LDBLE new_Dw); - int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, - LDBLE new_Dw, int cell); - LDBLE viscosity(void); - int multi_D(LDBLE DDt, int mobile_cell, int stagnant); - int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); - int fill_spec(int cell_no); - int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); - static int sort_species_name(const void *ptr1, const void *ptr2); - int disp_surf(LDBLE stagkin_time); - int diff_stag_surf(int mobile_cell); - int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); - cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, - int n_user_new, - bool move_old); - int init_mix(void); - int init_heat_mix(int nmix); - int heat_mix(int heat_nmix); - int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); - - // utilities.cpp ------------------------------- -public: - int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); - int add_elt_list(const cxxNameDouble & nd, LDBLE coef); -protected: - int backspace_screen(int spaces); - LDBLE calc_alk(struct reaction *rxn_ptr); -public: - LDBLE calc_rho_0(LDBLE tc, LDBLE pa); - LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); - int compute_gfw(const char *string, LDBLE * gfw); -#if defined PHREEQ98 - int copy_title(char *token_ptr, char **ptr, int *length); -#endif - int copy_token(char *token_ptr, char **ptr, int *length); - int copy_token(std::string &token, char **ptr); - int dup_print(const char *ptr, int emphasis); - int equal(LDBLE a, LDBLE b, LDBLE eps); -public: - void *free_check_null(void *ptr); -protected: - void free_hash_strings(HashTable * Table); - int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); - int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); - void hdestroy_multi(HashTable * HashTable_ptr); - ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); - int islegit(const char c); -public: - void malloc_error(void); -protected: - int parse_couple(char *token); - int print_centered(const char *string); -public: - static int replace(const char *str1, const char *str2, char *str); - static bool replace(const char *str1, const char *str2, std::string & str); -protected: - void space(void **ptr, int i, int *max, int struct_size); - void squeeze_white(char *s_l); - int status(int count, const char *str, bool kinetics = false); - void str_tolower(char *str); - void str_toupper(char *str); - static int strcmp_nocase(const char *str1, const char *str2); - int strcmp_nocase_arg1(const char *str1, const char *str2); -public: - char *string_duplicate(const char *token); - const char *string_hsave(const char *str); - void strings_map_clear(); -#ifdef HASH - void strings_hash_clear(); -#endif -protected: - char *string_pad(const char *str, int i); - int string_trim(char *str); - int string_trim_right(char *str); - int string_trim_left(char *str); - static LDBLE under(LDBLE xval); - void zero_double(LDBLE * target, int n); - int get_input_errors(void); -#ifdef PHREEQ98 - void AddToCEntry(char *a, int l, int i); - void ApplicationProcessMessages(void); - int copy_title(char *token_ptr, char **ptr, int *length); - extern int clean_up_null(void); -#endif - int isamong(char c, const char *s_l); - Address Hash_multi(HashTable * Table, const char *Key); - void ExpandTable_multi(HashTable * Table); -public: - int main_method(int argc, char *argv[]); - void set_phast(int); - size_t list_components(std::list &list_c); - PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} -protected: - void init(void); - - // - //Data members - // -protected: - PHRQ_io *phrq_io; - PHRQ_io ioInstance; - - /* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ - - struct model last_model; - int same_model; - int same_temperature; - int same_pressure; - bool same_mu; - struct punch punch; - /* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ - - std::map Rxn_temperature_map; - - /* ---------------------------------------------------------------------- - * Pressures - * ---------------------------------------------------------------------- */ - std::map Rxn_pressure_map; - - /* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ - - int g_iterations; - LDBLE G_TOL; - std::map Rxn_surface_map; - std::map charge_group_map; - int change_surf_count; - struct Change_Surf *change_surf; - - /* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ - std::map Rxn_exchange_map; - - /* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ - std::map Rxn_kinetics_map; - - /*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ - int count_save_values; - struct save_values *save_values; - struct save save; - - /*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ - cxxUse use; - - /*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ - struct copier copy_solution; - struct copier copy_pp_assemblage; - struct copier copy_exchange; - struct copier copy_surface; - struct copier copy_ss_assemblage; - struct copier copy_gas_phase; - struct copier copy_kinetics; - struct copier copy_mix; - struct copier copy_reaction; - struct copier copy_temperature; - struct copier copy_pressure; - - /*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ - - struct inverse *inverse; - int count_inverse; - - /*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ - std::map Rxn_mix_map; - std::map Dispersion_mix_map; - - /*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ - std::map Rxn_reaction_map; - - /*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ - std::map Rxn_gas_phase_map; - - /*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ - std::map Rxn_ss_assemblage_map; - - /*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - std::map Rxn_pp_assemblage_map; - - /*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ - int count_species_list; - int max_species_list; - struct species_list *species_list; - - /*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ - - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ - /*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - std::map Rxn_solution_map; - std::vector unnumbered_solutions; - struct iso *iso_defaults; - int count_iso_defaults; - - /*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ - char *title_x; - int new_x; - char *description_x; - LDBLE tc_x; - LDBLE tk_x; - LDBLE patm_x; - bool numerical_fixed_volume; - bool force_numerical_fixed_volume; - bool switch_numerical; - LDBLE ph_x; - LDBLE solution_pe_x; - LDBLE mu_x; - LDBLE ah2o_x; - LDBLE density_x; - LDBLE total_h_x; - LDBLE total_o_x; - LDBLE cb_x; - LDBLE total_ions_x; - LDBLE mass_water_aq_x; - LDBLE mass_water_surfaces_x; - LDBLE mass_water_bulk_x; - char *units_x; - std::map < std::string, cxxChemRxn > pe_x; - std::map isotopes_x; - std::string default_pe_x; - cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; - LDBLE total_carbon; - LDBLE total_co2; - LDBLE total_alkalinity; - LDBLE gfw_water; - LDBLE step_x; - LDBLE kin_time_x; - - /*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ - int count_cells; - int count_shifts; - int ishift; - int bcon_first; - int bcon_last; - int correct_disp; - LDBLE tempr; - LDBLE timest; - int simul_tr; - LDBLE diffc; - LDBLE heat_diffc; - int cell; - LDBLE mcd_substeps; - struct stag_data *stag_data; - int print_modulus; - int punch_modulus; - int dump_in; - int dump_modulus; - int transport_warnings; - struct cell_data *cell_data; - int multi_Dflag; /* signals calc'n of multicomponent diffusion */ - int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ - LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ - LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ - LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ - LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ - LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ - LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, - Dp = Dw * (multi_Dpor)^multi_Dn */ - LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, - Dpil = Dw / interlayer_tortf */ - - int cell_no; - /*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ - int count_ad_cells; - int count_ad_shifts; - int print_ad_modulus; - int punch_ad_modulus; - int *advection_punch, *advection_print; - LDBLE advection_kin_time; - LDBLE advection_kin_time_defined; - int advection_warnings; - - /*---------------------------------------------------------------------- - * Tidy data - *---------------------------------------------------------------------- */ - int new_model, new_exchange, new_pp_assemblage, new_surface, - new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, - new_pitzer; - - /*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ - - struct element **elements; - int count_elements; - int max_elements; - struct element *element_h_one; - - /*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ - - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ - int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; - /*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ - - /*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ - - struct logk **logk; - int count_logk; - int max_logk; - - char *moles_per_kilogram_string; - char *pe_string; - - struct species **s; - int count_s; - int max_s; - std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; - - struct species **s_x; - int count_s_x; - int max_s_x; - - struct species *s_h2o; - struct species *s_hplus; - struct species *s_h3oplus; - struct species *s_eminus; - struct species *s_co3; - struct species *s_h2; - struct species *s_o2; - - /*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ - struct phase **phases; - int count_phases; - int max_phases; - - /*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; - - /*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ - - struct unknown **x; - int count_unknowns; - int max_unknowns; - - struct unknown *ah2o_unknown; - struct unknown *alkalinity_unknown; - struct unknown *carbon_unknown; - struct unknown *charge_balance_unknown; - struct unknown *exchange_unknown; - struct unknown *mass_hydrogen_unknown; - struct unknown *mass_oxygen_unknown; - struct unknown *mb_unknown; - struct unknown *mu_unknown; - struct unknown *pe_unknown; - struct unknown *ph_unknown; - struct unknown *pure_phase_unknown; - struct unknown *solution_phase_boundary_unknown; - struct unknown *surface_unknown; - struct unknown *gas_unknown; - struct unknown *slack_unknown; - struct unknown *ss_unknown; - std::vector gas_unknowns; - - /*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ - struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; - - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; - - /* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ - struct prints pr; - bool status_on; - clock_t status_interval; - clock_t status_timer; - int count_warnings; - - /* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ - struct rate *rates; - int count_rates; - LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, - rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; - std::vector rate_p; - int count_rate_p; - - /* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ - struct rate *user_print; - struct rate *user_punch; - const char **user_punch_headings; - int user_punch_count_headings; - int n_user_punch_index; - -#if defined PHREEQ98 - struct rate *user_graph; - char **user_graph_headings; - int user_graph_count_headings; -#endif -#if defined MULTICHART - ChartHandler chart_handler; -#endif - - /* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ - const char * error_string; - int simulation; - int state; - int reaction_step; - int transport_step; - int transport_start; - int advection_step; - int stop_program; - int incremental_reactions; - - int count_strings; - int max_strings; - - LDBLE *array; - LDBLE *delta; - LDBLE *residual; - - int input_error; - - Keywords::KEYWORDS next_keyword; - int parse_error; - int paren_count; - int iterations; - int gamma_iterations; - int run_reactions_iterations; - - int max_line; - char *line; - char *line_save; - - LDBLE LOG_10; - - int debug_model; - int debug_prep; - int debug_set; - int debug_diffuse_layer; - int debug_inverse; - - LDBLE inv_tol_default; - int itmax; - int max_tries; - LDBLE ineq_tol; - LDBLE convergence_tolerance; - LDBLE step_size; - LDBLE pe_step_size; - LDBLE step_size_now; - LDBLE pe_step_size_now; - LDBLE pp_scale; - LDBLE pp_column_scale; - int diagonal_scale; /* 0 not used, 1 used */ - int mass_water_switch; - int delay_mass_water; - bool dampen_ah2o; - bool slack; - LDBLE censor; - int aqueous_only; - int negative_concentrations; - int calculating_deriv; - int numerical_deriv; - - int count_total_steps; - int phast; - LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; - int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, - llnl_count_co2_coefs; - - char *selected_output_file_name; - char *dump_file_name; - int remove_unstable_phases; - std::string screen_string; -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif - - /* ---------------------------------------------------------------------- */ - /* - * Hash definitions - */ - - std::map strings_map; -#ifdef HASH - std::hash_map strings_hash; -#endif - HashTable *elements_hash_table; - HashTable *species_hash_table; - HashTable *phases_hash_table; - HashTable *logk_hash_table; - HashTable *master_isotope_hash_table; - -#if defined(PHREEQCI_GUI) -#include "../../phreeqci_gui.h" -#endif /* defined(PHREEQCI_GUI) */ - /* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ - struct name_coef match_tokens[50]; - int count_match_tokens; - int count_master_isotope; - struct master_isotope **master_isotope; - int max_master_isotope; - int initial_solution_isotopes; - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; - HashTable *calculate_value_hash_table; - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; - HashTable *isotope_ratio_hash_table; - int count_isotope_alpha; - struct isotope_alpha **isotope_alpha; - int max_isotope_alpha; - HashTable *isotope_alpha_hash_table; - int phreeqc_mpi_myself; - int first_read_input; - char *user_database; - - int have_punch_name; - /* VP: Density Start */ - int print_density; - /* VP: Density End */ - - LDBLE *zeros; - int zeros_max; - - LDBLE cell_pore_volume; - LDBLE cell_porosity; - LDBLE cell_volume; - LDBLE cell_saturation; - struct system_species *sys; - int count_sys, max_sys; - LDBLE sys_tot; -#ifdef PHREEQC2 - LDBLE AA_basic, BB_basic, CC, I_m, rho_0; - LDBLE eps_r; // relative dielectric permittivity -#else - LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; - LDBLE eps_r; // relative dielectric permittivity - LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av -#endif - LDBLE solution_mass, solution_volume; - LDBLE f_rho(LDBLE rho_old); - - /* phqalloc.cpp ------------------------------- */ - PHRQMemHeader *s_pTail; - std::stringstream merged_database_stream; - std::stringstream merged_input_stream; - - /* Basic */ - PBasic * basic_interpreter; - - /* cl1.cpp ------------------------------- */ - LDBLE *x_arg, *res_arg, *scratch; - int x_arg_max, res_arg_max, scratch_max; - - /* dw.cpp ------------------------------- */ - /* COMMON /QQQQ/ */ - LDBLE Q0, Q5; - LDBLE GASCON, TZ, AA; - LDBLE Z, DZ, Y; - LDBLE G1, G2, GF; - LDBLE B1, B2, B1T, B2T, B1TT, B2TT; - - /* input.cpp ------------------------------- */ - int add_char_to_line(int *i, char c); - int check_line_impl(const char *string, int allow_empty, - int allow_eof, int allow_keyword, int print); - int get_line(void); - int get_logical_line(void *cookie, int *l); - int read_database(void); - int run_simulations(void); - int check_line_return; - int reading_db; - - /* integrate.cpp ------------------------------- */ - LDBLE midpoint_sv; - LDBLE z_global, xd_global, alpha_global; - int max_row_count, max_column_count; - int carbon; - const char **col_name, **row_name; - int count_rows, count_optimize; - int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; - int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; - LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; - LDBLE *min_delta, *max_delta; - int *iu, *is; - int klmd, nklmd, n2d, kode, iter; - LDBLE toler, error, max_pct, scaled_error; - struct master *master_alk; - int *row_back, *col_back; - unsigned long *good, *bad, *minimal; - int max_good, max_bad, max_minimal; - int count_good, count_bad, count_minimal, count_calls; - unsigned long soln_bits, phase_bits, current_bits, temp_bits; - - /* inverse.cpp ------------------------------- */ - FILE *netpath_file; - int count_inverse_models, count_pat_solutions; - int min_position[32], max_position[32], now[32]; - - /* kinetics.cpp ------------------------------- */ -public: - void *cvode_kinetics_ptr; - int cvode_test; - int cvode_error; - int cvode_n_user; - int cvode_n_reactions; - realtype cvode_step_fraction; - realtype cvode_rate_sim_time; - realtype cvode_rate_sim_time_start; - realtype cvode_last_good_time; - realtype cvode_prev_good_time; - N_Vector cvode_last_good_y; - N_Vector cvode_prev_good_y; - M_Env kinetics_machEnv; - N_Vector kinetics_y, kinetics_abstol; - void *kinetics_cvode_mem; - cxxSSassemblage *cvode_ss_assemblage_save; - cxxPPassemblage *cvode_pp_assemblage_save; - LDBLE *m_original; - LDBLE *m_temp; - int set_and_run_attempt; - - /* model.cpp ------------------------------- */ - LDBLE min_value; - LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; - int *inv_iu, *inv_is, *back_eq; - int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; - - /* phrq_io_output.cpp ------------------------------- */ - int forward_output_to_log; - - /* phreeqc_files.cpp ------------------------------- */ - char *default_data_base; -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; -#endif - - /* Pitzer */ - int pitzer_model, sit_model, pitzer_pe; - int full_pitzer, always_full_pitzer, ICON, IC; - LDBLE COSMOT; - LDBLE AW; - LDBLE VP, DW0; - struct pitz_param **pitz_params; - int count_pitz_param, max_pitz_param; - struct pitz_param **sit_params; - int count_sit_param, max_sit_param; - int DW(LDBLE T); - LDBLE DC(LDBLE T); - struct theta_param **theta_params; - int count_theta_param, max_theta_param; - int use_etheta; - LDBLE OTEMP; - LDBLE A0; - struct species **spec, **cations, **anions, **neutrals; - int count_cations, count_anions, count_neutrals; - int MAXCATIONS, FIRSTANION, MAXNEUTRAL; - struct pitz_param *mcb0, *mcb1, *mcc0; - int *IPRSNT; - LDBLE *M, *LGAMMA; - LDBLE BK[23], DK[23]; - -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif - LDBLE dummy; - - /* print.cpp ------------------------------- */ -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif - - /* read.cpp */ - char *prev_next_char; -#if defined PHREEQ98 - int shifts_as_points; -#endif - - /* read_class.cxx */ - dumper dump_info; - StorageBinList delete_info; - runner run_info; - char * sformatf_buffer; - size_t sformatf_buffer_size; - - /* readtr.cpp */ - std::string dump_file_name_cpp; - - /* sit.cpp ------------------------------- */ - LDBLE sit_A0; - int sit_count_cations, sit_count_anions, sit_count_neutrals; - int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; - int *sit_IPRSNT; - LDBLE *sit_M, *sit_LGAMMA; - - /* tidy.cpp ------------------------------- */ - LDBLE a0, a1, kc, kb; - - /* tally.cpp ------------------------------- */ - struct tally_buffer *t_buffer; - int tally_count_component; - struct tally *tally_table; - int count_tally_table_columns; - int count_tally_table_rows; - - /* transport.cpp ------------------------------- */ - struct sol_D *sol_D; - struct sol_D *sol_D_dbg; - struct J_ij *J_ij, *J_ij_il; - int J_ij_count_spec; - - struct M_S *m_s; - int count_m_s; - LDBLE tot1_h, tot1_o, tot2_h, tot2_o; - LDBLE diffc_max, diffc_tr, J_ij_sum; - int transp_surf; - LDBLE *heat_mix_array; - LDBLE *temp1, *temp2; - int nmix, heat_nmix; - LDBLE heat_mix_f_imm, heat_mix_f_m; - int warn_MCD_X, warn_fixed_Surf; - -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif - - friend class PBasic; - friend class ChartObject; - friend class IPhreeqc; - friend class TestIPhreeqc; - friend class TestSelectedOutput; - - std::vector keycount; // used to mark keywords that have been read - -#endif /* _INC_PHREEQC_H */ -#ifndef _INC_ISFINITE_H -#define _INC_ISFINITE_H - /********************************* - isfinite handling - (Note: Should NOT be guarded) - **********************************/ - -#if defined (PHREEQ98) || defined (_MSC_VER) -# define HAVE_FINITE -# define finite _finite -#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ -# if defined(DJGPP) -# define HAVE_FINITE -# endif -#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ - -#if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) -#elif defined(HAVE_FINITE) -# define PHR_ISFINITE(x) finite(x) -#elif defined(HAVE_ISNAN) -# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) -#else -# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) -#endif - -}; -#endif diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index e90a7af9..9e776e85 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -1075,5 +1075,12 @@ struct theta_param LDBLE ethetap; }; +struct const_iso +{ + const char *name; + LDBLE value; + LDBLE uncertainty; +}; + #endif /* _INC_GLOBAL_STRUCTURES_H */ From c8c82a99428c2a6595d2f7814a3638695be1d170 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 22:04:19 +0000 Subject: [PATCH 0445/1077] resurrected Phreeqc.h; Don't know how it was deleted git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6325 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1863 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1863 insertions(+) create mode 100644 Phreeqc.h diff --git a/Phreeqc.h b/Phreeqc.h new file mode 100644 index 00000000..b8389df3 --- /dev/null +++ b/Phreeqc.h @@ -0,0 +1,1863 @@ +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif +/* ---------------------------------------------------------------------- +* INCLUDE FILES +* ---------------------------------------------------------------------- */ +#include +#include +#include +#include +#ifdef HASH +#include +#endif +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "cvdense.h" +#include "runner.h" +#include "dumper.h" +#include "PHRQ_io.h" +#ifdef MULTICHART +#include "ChartHandler.h" +#endif +#include "Keywords.h" +#include "Pressure.h" +#include "cxxMix.h" +#include "Use.h" +#include "Surface.h" + +class cxxNameDouble; +class cxxKinetics; +//class cxxMix; +class cxxKineticsComp; +class cxxExchange; +class cxxExchComp; +class cxxGasPhase; +class cxxTemperature; +class cxxPPassemblage; +class cxxPPassemblageComp; +class cxxReaction; +class cxxSolution; +class cxxISolutionComp; +class cxxSolutionIsotope; +class cxxSSassemblage; +class cxxSS; +class cxxStorageBin; + +#include "global_structures.h" +class PBasic; + +class Phreeqc +{ +public: + Phreeqc(PHRQ_io *io = NULL); + ~Phreeqc(void); + +public: + // + // Phreeqc class methods + // + + // advection.cpp ------------------------------- + int advection(void); + + // basicsubs.cpp ------------------------------- + int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); + int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); + void basic_free(void); + + LDBLE activity(const char *species_name); + LDBLE activity_coefficient(const char *species_name); + LDBLE log_activity_coefficient(const char *species_name); + LDBLE calc_SC(void); + /* VP: Density Start */ + LDBLE calc_dens(void); + /* VP: Density End */ + LDBLE calc_logk_n(const char *name); + LDBLE calc_logk_p(const char *name); + LDBLE calc_logk_s(const char *name); + LDBLE calc_surface_charge(const char *surface_name); + LDBLE diff_layer_total(const char *total_name, const char *surface_name); + LDBLE equi_phase(const char *phase_name); + LDBLE find_gas_comp(const char *gas_comp_name); + LDBLE find_gas_p(void); + LDBLE find_gas_vm(void); + LDBLE find_misc1(const char *ss_name); + LDBLE find_misc2(const char *ss_name); + LDBLE find_ss_comp(const char *ss_comp_name); + LDBLE get_calculate_value(const char *name); + char * iso_unit(const char *total_name); + LDBLE iso_value(const char *total_name); + LDBLE kinetics_moles(const char *kinetics_name); + LDBLE log_activity(const char *species_name); + LDBLE log_molality(const char *species_name); + LDBLE molality(const char *species_name); + LDBLE pressure(void); + LDBLE pr_pressure(const char *phase_name); + LDBLE pr_phi(const char *phase_name); + LDBLE saturation_ratio(const char *phase_name); + int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); + LDBLE solution_sum_secondary(const char *total_name); + LDBLE sum_match_gases(const char *stemplate, const char *name); + LDBLE sum_match_species(const char *stemplate, const char *name); + LDBLE sum_match_ss(const char *stemplate, const char *name); + int match_elts_in_species(const char *name, const char *stemplate); + int extract_bracket(char **string, char *bracket_string); + LDBLE surf_total(const char *total_name, const char *surface_name); + static int system_species_compare(const void *ptr1, const void *ptr2); + LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); + std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); + LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); + int system_total_elements(void); + int system_total_si(void); + int system_total_aq(void); + int system_total_ex(void); + int system_total_surf(void); + int system_total_gas(void); + int system_total_ss(void); + int system_total_elt(const char *total_name); + int system_total_elt_secondary(const char *total_name); + LDBLE total(const char *total_name); + LDBLE total_mole(const char *total_name); + int system_total_solids(cxxExchange *exchange_ptr, + cxxPPassemblage *pp_assemblage_ptr, + cxxGasPhase *gas_phase_ptr, + cxxSSassemblage *ss_assemblage_ptr, + cxxSurface *surface_ptr); + + static LDBLE f_rho(LDBLE rho_old, void *cookie); + static LDBLE f_Vm(LDBLE v1, void *cookie); + // chart.cpp +#if defined PHREEQ98 + void DeleteCurves(void); + void ExtractCurveInfo(char *line, int curvenr); + void GridChar(char *s, char *a); + void MallocCurves(int nc, int ncxy); + int OpenCSVFile(char file_name[MAX_LENGTH]); + void SaveCurvesToFile(char file_name[MAX_LENGTH]); + void PlotXY(char *x, char *y); + void ReallocCurves(int new_nc); + void ReallocCurveXY(int i); + void SetAxisScale(char *a, int j, char *token, int true_); + void SetAxisTitles(char *s, int i); + void SetChartTitle(char *s); + void start_chart(bool end); +#endif + + // cl1.cpp ------------------------------- + int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); + void cl1_space(int check, int n2d, int klm, int nklmd); + + // cl1mp.cpp ------------------------------- + int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + + // class_main.cpp ------------------------------- + int write_banner(void); + + /* default.cpp */ +public: + int close_input_files(void); + int close_output_files(void); + static int istream_getc(void *cookie); + int process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log); + + /* PHRQ_io_output.cpp */ + void screen_msg(const char * str); + + void echo_msg(const char *err_str); + int warning_msg(const char *err_str); + void set_forward_output_to_log(int value); + int get_forward_output_to_log(void); + + // dump_ostream + bool dump_open(const char *file_name); + void dump_flush(void); + void dump_close(void); + void dump_msg(const char * str); + + // log_ostream + bool log_open(const char *file_name); + void log_flush(void); + void log_close(void); + void log_msg(const char * str); + + // error_ostream + bool error_open(const char *file_name); + void error_flush(void); + void error_close(void); + void error_msg(const char * str, bool stop=false); + + // output_ostream + bool output_open(const char *file_name); + void output_flush(void); + void output_close(void); + void output_msg(const char * str); + + // punch_ostream + bool punch_open(const char *file_name); + void punch_flush(void); + void punch_close(void); + void punch_msg(const char * str); + + void fpunchf_heading(const char *name); + void fpunchf(const char *name, const char *format, double d); + void fpunchf(const char *name, const char *format, char * d); + void fpunchf(const char *name, const char *format, int d); + void fpunchf_user(int user_index, const char *format, double d); + void fpunchf_user(int user_index, const char *format, char * d); + int fpunchf_end_row(const char *format); + + // dw.cpp ------------------------------- + int BB(LDBLE T); + LDBLE PS(LDBLE T); + LDBLE VLEST(LDBLE T); + int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); + int QQ(LDBLE T, LDBLE D); + LDBLE BASE(LDBLE D); + + // input.cpp ------------------------------- + int reading_database(void); + void set_reading_database(int reading_database); + int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + + // integrate.cpp ------------------------------- + int calc_all_g(void); + int calc_init_g(void); + int initial_surface_water(void); + int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); + int calc_all_donnan(void); + int calc_init_donnan(void); + LDBLE g_function(LDBLE x_value); + LDBLE midpnt(LDBLE x1, LDBLE x2, int n); + void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); + LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); + LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); + int calc_all_donnan_music(void); + int calc_init_donnan_music(void); + + // inverse.cpp ------------------------------- + int inverse_models(void); + int add_to_file(const char *filename, const char *string); + int bit_print(unsigned long bits, int l); + int carbon_derivs(struct inverse *inv_ptr); + int check_isotopes(struct inverse *inv_ptr); + int check_solns(struct inverse *inv_ptr); + int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); + cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); + LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); + int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); + int post_mortem(void); + bool test_cl1_solution(void); + unsigned long get_bits(unsigned long bits, int position, int number); + unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); + void dump_netpath(struct inverse *inv_ptr); + int dump_netpath_pat(struct inverse *inv_ptr); + int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); + int phase_isotope_inequalities(struct inverse *inv_ptr); + int print_model(struct inverse *inv_ptr); + int punch_model_heading(struct inverse *inv_ptr); + int punch_model(struct inverse *inv_ptr); + void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); + + void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); + int range(struct inverse *inv_ptr, unsigned long cur_bits); + int save_bad(unsigned long bits); + int save_good(unsigned long bits); + int save_minimal(unsigned long bits); + unsigned long set_bit(unsigned long bits, int position, int value); + int setup_inverse(struct inverse *inv_ptr); + int set_initial_solution(int n_user_old, int n_user_new); + int set_ph_c(struct inverse *inv_ptr, + int i, cxxSolution *soln_ptr_orig, int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); + int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); + int solve_inverse(struct inverse *inv_ptr); + int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); + int subset_bad(unsigned long bits); + int subset_minimal(unsigned long bits); + int superset_minimal(unsigned long bits); + int write_optimize_names(struct inverse *inv_ptr); + + // isotopes.cpp ------------------------------- + int add_isotopes(cxxSolution &solution_ptr); + int calculate_values(void); + int calculate_isotope_moles(struct element *elt_ptr, + cxxSolution *solution_ptr, LDBLE total_moles); + LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); + int from_pcil(struct master_isotope *master_isotope_ptr); + int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_tu(struct master_isotope *master_isotope_ptr); + struct calculate_value *calculate_value_alloc(void); + int calculate_value_free(struct calculate_value *calculate_value_ptr); + struct calculate_value *calculate_value_search(const char *name); + struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); + struct isotope_alpha *isotope_alpha_alloc(void); + struct isotope_alpha *isotope_alpha_search(const char *name); + struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); + struct isotope_ratio *isotope_ratio_alloc(void); + struct isotope_ratio *isotope_ratio_search(const char *name); + struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_alloc(void); + struct master_isotope *master_isotope_search(const char *name); + int print_initial_solution_isotopes(void); + int print_isotope_ratios(void); + int print_isotope_alphas(void); + int punch_isotopes(void); + int punch_calculate_values(void); + int read_calculate_values(void); + int read_isotopes(void); + int read_isotope_ratios(void); + int read_isotope_alphas(void); + int calculate_value_init(struct calculate_value *calculate_value_ptr); + int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); + int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); + int master_isotope_init(struct master_isotope *master_isotope_ptr); + + // kinetics.cpp ------------------------------- + void cvode_init(void); + int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); + int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_advection(int i, int use_mix, int use_kinetics, int nsaver); + int free_cvode(void); +public: + static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); + static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + + int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); + int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, + LDBLE time_step); + int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); + int set_reaction(int i, int use_mix, int use_kinetics); + int set_transport(int i, int use_mix, int use_kinetics, int nsaver); + int store_get_equi_reactants(int k, int kin_end); + int count_pp, count_pg, count_ss; + LDBLE *x0_moles; + + // mainsubs.cpp ------------------------------- + std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + int copy_entities(void); + void initialize(void); + int initial_exchangers(int print); + int initial_gas_phases(int print); + int initial_solutions(int print); + int step_save_exch(int n_user); + int step_save_surf(int n_user); + int initial_surfaces(int print); + int reactions(void); + int saver(void); + int xsolution_save(int k_user); + int xexchange_save(int n_user); + int xgas_save(int n_user); + int xpp_assemblage_save(int n_user); + int xss_assemblage_save(int n_user); + int xsurface_save(int n_user); + int do_initialize(void); + int do_status(void); + void save_init(int i); + int copy_use(int i); + int set_use(void); + + // model.cpp ------------------------------- + int check_residuals(void); + int free_model_allocs(void); + int ineq(int kode); + int model(void); + int jacobian_sums(void); + int mb_gases(void); + int mb_ss(void); + int mb_sums(void); + int molalities(int allow_overflow); + int reset(void); + int residuals(void); + int set(int initial); + int sum_species(void); + int surface_model(void); + LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); + LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); + LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); + int numerical_jacobian(void); + void set_inert_moles(void); + void unset_inert_moles(void); +#ifdef SLNQ + int add_trivial_eqns(int rows, int cols, LDBLE * matrix); + //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif + int calc_gas_pressures(void); + int calc_fixed_volume_gas_pressures(void); + int calc_ss_fractions(void); + int gammas(LDBLE mu); + int initial_guesses(void); + int revise_guesses(void); + int ss_binary(cxxSS *ss_ptr); + int ss_ideal(cxxSS *ss_ptr); + int gas_in; + void ineq_init(int max_row_count, int max_column_count); + + // parse.cpp ------------------------------- + int check_eqn(int association); + int get_charge(char *charge, LDBLE * z); + int get_elt(char **t_ptr, char *element, int *i); + int get_elts_in_species(char **t_ptr, LDBLE coef); + int get_num(char **t_ptr, LDBLE * num); + int get_secondary_in_species(char **t_ptr, LDBLE coef); + int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + int get_coef(LDBLE * coef, char **eqnaddr); + int get_secondary(char **t_ptr, char *element, int *i); + int get_species(char **ptr); + + // phqalloc.cpp ------------------------------- +public: +#if !defined(NDEBUG) + void *PHRQ_malloc(size_t, const char *, int); + void *PHRQ_calloc(size_t, size_t, const char *, int); + void *PHRQ_realloc(void *, size_t, const char *, int); +#else + void *PHRQ_malloc(size_t); + void *PHRQ_calloc(size_t, size_t); + void *PHRQ_realloc(void *, size_t); +#endif + void PHRQ_free(void *ptr); + void PHRQ_free_all(void); + +public: + + // pitzer.cpp ------------------------------- + struct pitz_param *pitz_param_read(char *string, int n); + int pitz_param_search(struct pitz_param *pzp_ptr); + int sit_param_search(struct pitz_param *pzp_ptr); + struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); + struct theta_param *theta_param_alloc(void); + int theta_param_init(struct theta_param *theta_param_ptr); + int gammas_pz(void); + int model_pz(void); + int pitzer(void); + int pitzer_clean_up(void); + int pitzer_init(void); + int pitzer_tidy(void); + int read_pitzer(void); + int set_pz(int initial); + int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_pz(void); + int ISPEC(const char *name); + LDBLE G(LDBLE Y); + LDBLE GP(LDBLE Y); + int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); + int BDK(LDBLE X); + int pitzer_initial_guesses(void); + int pitzer_revise_guesses(void); + int PTEMP(LDBLE TK); + LDBLE JAY(LDBLE X); + LDBLE JPRIME(LDBLE Y); + int jacobian_pz(void); + + // pitzer_structures.cpp ------------------------------- + struct pitz_param *pitz_param_alloc(void); + int pitz_param_init(struct pitz_param *pitz_param_ptr); + struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); + int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + + // prep.cpp ------------------------------- + int add_potential_factor(void); + int add_cd_music_factors(int n); + int add_surface_charge_balance(void); + int add_cd_music_charge_balances(int i); + int build_gas_phase(void); + int build_fixed_volume_gas(void); + int build_jacobian_sums(int k); + int build_mb_sums(void); + int build_min_exch(void); + int build_model(void); + int build_pure_phases(void); + int build_ss_assemblage(void); + int build_solution_phase_boundaries(void); + int build_species_list(int n); + int build_min_surface(void); + LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); + LDBLE calc_delta_v(reaction * r_ptr, bool phase); + LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(); + int calc_vm(LDBLE tc, LDBLE pa); + int change_hydrogen_in_elt_list(LDBLE charge); + int clear(void); + //int convert_units(struct solution *solution_ptr); + int convert_units(cxxSolution *solution_ptr); + LDBLE a_aa_sum, b2, b_sum, R_TK; + LDBLE f_Vm(LDBLE v1); + struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); + struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); + int inout(void); + int is_special(struct species *spec); + int mb_for_species_aq(int n); + int mb_for_species_ex(int n); + int mb_for_species_surf(int n); + int quick_setup(void); + int resetup_master(void); + int save_model(void); + int setup_exchange(void); + int setup_gas_phase(void); + int setup_fixed_volume_gas(void); + int setup_slack(void); + int setup_master_rxn(struct master **master_ptr_list, + const std::string &pe_rxn); + int setup_pure_phases(void); + int adjust_setup_pure_phases(void); + int setup_related_surface(void); + int setup_ss_assemblage(void); + int setup_solution(void); + int adjust_setup_solution(void); + int setup_surface(void); + int setup_unknowns(void); + int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); + int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); + int store_jacob0(int row, int column, LDBLE coef); + int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); + int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); + int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); + int tidy_redox(void); + struct master **unknown_alloc_master(void); + int write_mb_eqn_x(void); + int write_mb_for_species_list(int n); + int write_mass_action_eqn_x(int stop); + + int check_same_model(void); + int k_temp(LDBLE tc, LDBLE pa); + LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); + int prep(void); + int reprep(void); + int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); + int switch_bases(void); + int write_phase_sys_total(int n); + + // print.cpp ------------------------------- + char *sformatf(const char *format, ...); + int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); + int print_all(void); + int print_exchange(void); + int print_gas_phase(void); + int print_master_reactions(void); + int print_reaction(struct reaction *rxn_ptr); + int print_species(void); + int print_surface(void); + int print_user_print(void); + int punch_all(void); + int print_alkalinity(void); + int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); + int print_eh(void); + int print_reaction(void); + int print_kinetics(void); + int print_mix(void); + int print_pp_assemblage(void); + int print_ss_assemblage(void); + int print_saturation_indices(void); + int print_surface_cd_music(void); + int print_totals(void); + int print_using(void); + /*int print_user_print(void);*/ + int punch_gas_phase(void); + int punch_identifiers(void); + int punch_kinetics(void); + int punch_molalities(void); + int punch_activities(void); + int punch_pp_assemblage(void); + int punch_ss_assemblage(void); + int punch_saturation_indices(void); + int punch_totals(void); + int punch_user_punch(void); +#if defined MULTICHART + int punch_user_graph(void); +#endif + + // read.cpp ------------------------------- + int read_input(void); + int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); + int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); + int read_log_k_only(char *ptr, LDBLE * log_k); + int read_t_c_only(char *ptr, LDBLE *t_c); + int read_p_c_only(char *ptr, LDBLE * p_c); + int read_omega_only(char *ptr, LDBLE *omega); + int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description, int allow_negative=FALSE); + int check_key(const char *str); + int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, + const char *default_units, bool print); + int find_option(const char *item, int *n, const char **list, int count_list, + int exact); + int get_option(const char **opt_list, int count_opt_list, char **next_char); + int get_true_false(char *string, int default_value); + + int add_psi_master_species(char *token); + int read_advection(void); + int read_analytical_expression_only(char *ptr, LDBLE * log_k); + /* VP: Density Start */ + int read_millero_abcdef (char *ptr, LDBLE * abcdef); + /* VP: Density End */ + int read_copy(void); + int read_debug(void); + int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); + int read_vm_only(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); + int read_llnl_aqueous_model_parameters(void); + int read_exchange(void); + int read_exchange_master_species(void); + int read_exchange_species(void); + int read_gas_phase(void); + int read_incremental_reactions(void); + int read_inverse(void); + int read_inv_balances(struct inverse *inverse_ptr, char *next_char); + int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); + int read_inv_phases(struct inverse *inverse_ptr, char *next_char); + int read_kinetics(void); + int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); + LDBLE *read_list_doubles(char **ptr, int *count_doubles); + int *read_list_ints(char **ptr, int *count_ints, int positive); + int *read_list_t_f(char **ptr, int *count_ints); + int read_master_species(void); + int read_mix(void); + int read_named_logk(void); + int read_phases(void); + int read_print(void); + int read_pp_assemblage(void); + int read_rates(void); + int read_reaction(void); + int read_reaction_reactants(cxxReaction *reaction_ptr); + int read_reaction_steps(cxxReaction *reaction_ptr); + int read_solid_solutions(void); + int read_temperature(void); + int read_reaction_temps(struct temperature *temperature_ptr); + int read_reaction_pressure(void); + int read_reaction_pressure_raw(void); + int read_save(void); + int read_selected_output(void); + int read_solution(void); + int read_species(void); + int read_surface(void); + int read_surface_master_species(void); + int read_surface_species(void); + int read_use(void); + int read_title(void); + int read_user_print(void); + int read_user_punch(void); +#if defined PHREEQ98 + int read_user_graph(void); +#endif +#if defined MULTICHART + int read_user_graph_handler(); +#endif + int next_keyword_or_option(const char **opt_list, int count_opt_list); + int cleanup_after_parser(CParser &parser); + + // ReadClass.cxx + int read_dump(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); + + // readtr.cpp ------------------------------- + int read_transport(void); + int dump(void); + int dump_exchange(int k); + int dump_gas_phase(int k); + int dump_kinetics(int k); + int dump_mix(int k); + int dump_pp_assemblage(int k); + int dump_reaction(int k); + int dump_ss_assemblage(int k); + int dump_solution(int k); + int dump_surface(int k); + int dump_cpp(void); + int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + + // sit.cpp ------------------------------- + int gammas_sit(void); + int model_sit(void); + int sit(void); + int sit_clean_up(void); + int sit_init(void); + int sit_tidy(void); + int read_sit(void); + int set_sit(int initial); + int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_sit(void); + int sit_ISPEC(const char *name); + /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ + int sit_initial_guesses(void); + int sit_revise_guesses(void); + int PTEMP_SIT(LDBLE tk); + int jacobian_sit(void); + + // spread.cpp ------------------------------- + int read_solution_spread(void); + int copy_token_tab(char *token_ptr, char **ptr, int *length); + int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); + int spread_row_free(struct spread_row *spread_row_ptr); + int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); + struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI + void add_row(struct spread_row *spread_row_ptr); + void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); + void free_spread(void); + struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + + // step.cpp ------------------------------- + int step(LDBLE step_fraction); + int xsolution_zero(void); + int add_exchange(cxxExchange *exchange_ptr); + int add_gas_phase(cxxGasPhase *gas_phase_ptr); + int add_kinetics(cxxKinetics *kinetics_ptr); + int add_mix(cxxMix * mix_ptr); + int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); + int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); + int add_solution(cxxSolution *solution_ptr, LDBLE extensive, + LDBLE intensive); + int add_surface(cxxSurface *surface_ptr); + int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int gas_phase_check(cxxGasPhase *gas_phase_ptr); + int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); + int reaction_calc(cxxReaction *reaction_ptr); + int solution_check(void); + int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); + + // structures.cpp ------------------------------- + int clean_up(void); + int reinitialize(void); + int copier_add(struct copier *copier_ptr, int n_user, int start, int end); + int copier_free(struct copier *copier_ptr); + int copier_init(struct copier *copier_ptr); + static int element_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + static int elt_list_compare(const void *ptr1, const void *ptr2); +protected: + struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); + int elt_list_print(struct elt_list *elt_list_ptr); + struct elt_list *elt_list_save(void); + cxxNameDouble elt_list_NameDouble(void); +public: + enum entity_type get_entity_enum(char *name); + struct inverse *inverse_alloc(void); + int inverse_delete(int i); + static int inverse_isotope_compare(const void *ptr1, const void *ptr2); + struct inverse *inverse_search(int n_user, int *n); + int inverse_sort(void); +protected: + struct logk *logk_alloc(void); + int logk_copy2orig(struct logk *logk_ptr); + struct logk *logk_store(char *name, int replace_if_found); + struct logk *logk_search(const char *name); + struct master *master_alloc(void); + static int master_compare(const void *ptr1, const void *ptr2); + int master_delete(char *ptr); +public: + struct master *master_bsearch(const char *ptr); + struct master *master_bsearch_primary(const char *ptr); + struct master *master_bsearch_secondary(char *ptr); + struct master *master_search(char *ptr, int *n); + struct pe_data *pe_data_alloc(void); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +protected: + int pe_data_store(struct pe_data **pe, const char *token); +public: + struct phase *phase_bsearch(const char *ptr, int *j, int print); +protected: + static int phase_compare(const void *ptr1, const void *ptr2); + int phase_delete(int i); + struct phase *phase_store(const char *name); +public: + struct rate *rate_bsearch(char *ptr, int *j); + int rate_free(struct rate *rate_ptr); + struct rate *rate_search(const char *name, int *n); + int rate_sort(void); + struct reaction *rxn_alloc(int ntokens); + struct reaction *rxn_dup(struct reaction *rxn_ptr_old); + LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); + int rxn_free(struct reaction *rxn_ptr); + int rxn_print(struct reaction *rxn_ptr); + static int s_compare(const void *ptr1, const void *ptr2); + int s_delete(int i); + struct species *s_search(const char *name); + struct species *s_store(const char *name, LDBLE z, int replace_if_found); +protected: + struct save_values *save_values_bsearch(struct save_values *k, int *n); + static int save_values_compare(const void *ptr1, const void *ptr2); + int save_values_sort(void); + int save_values_store(struct save_values *s_v); + static int isotope_compare(const void *ptr1, const void *ptr2); + static int species_list_compare_alk(const void *ptr1, const void *ptr2); + static int species_list_compare_master(const void *ptr1, const void *ptr2); + int species_list_sort(void); + struct Change_Surf *change_surf_alloc(int count); +public: + struct master *surface_get_psi_master(const char *name, int plane); + int system_duplicate(int i, int save_old); + int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); + int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_combine(void); + int trxn_copy(struct reaction *rxn_ptr); + LDBLE trxn_find_coef(const char *str, int start); + int trxn_print(void); + int trxn_reverse_k(void); + int trxn_sort(void); + int trxn_swap(const char *token); + struct unknown *unknown_alloc(void); + int unknown_delete(int i); + int unknown_free(struct unknown *unknown_ptr); + int entity_exists(char *name, int n_user); + static int inverse_compare(const void *ptr1, const void *ptr2); + int inverse_free(struct inverse *inverse_ptr); + static int kinetics_compare_int(const void *ptr1, const void *ptr2); + int logk_init(struct logk *logk_ptr); + static int master_compare_string(const void *ptr1, const void *ptr2); + int master_free(struct master *master_ptr); + struct phase *phase_alloc(void); + static int phase_compare_string(const void *ptr1, const void *ptr2); + int phase_free(struct phase *phase_ptr); + int phase_init(struct phase *phase_ptr); + static int rate_compare(const void *ptr1, const void *ptr2); + static int rate_compare_string(const void *ptr1, const void *ptr2); + struct species *s_alloc(void); + int s_free(struct species *s_ptr); + int s_init(struct species *s_ptr); + static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int solution_compare(const void *ptr1, const void *ptr2); + static int solution_compare_int(const void *ptr1, const void *ptr2); + static int species_list_compare(const void *ptr1, const void *ptr2); + static int surface_compare_int(const void *ptr1, const void *ptr2); + static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); + int trxn_multiply(LDBLE coef); +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + extern void MergeFinalize(void); +#endif + struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); + struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); + struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); + struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + + void Use2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb); + + /* tally.cpp */ + void add_all_components_tally(void); + int build_tally_table(void); + int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); + int diff_tally_table(void); + int extend_tally_table(void); + int free_tally_table(void); + int fill_tally_table(int *n_user, int index_conservative, int n_buffer); + int get_tally_table_rows_columns(int *rows, int *columns); + int get_tally_table_column_heading(int column, int *type, char *string); + int get_tally_table_row_heading(int column, char *string); + int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); + int zero_tally_table(void); + int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); + int get_all_components(void); + int print_tally_table(void); + int set_reaction_moles(int n_user, LDBLE moles); + int set_reaction_temperature(int n_user, LDBLE tc); + int set_kinetics_time(int n_user, LDBLE step); + + // tidy.cpp ------------------------------- + int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); + int add_logks(struct logk *logk_ptr, int repeats); + LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); + int replace_solids_gases(void); + int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); + int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); + int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: + int tidy_punch(void); + int tidy_model(void); + int check_species_input(void); + LDBLE coef_in_master(struct master *master_ptr); + int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); + int reset_last_model(void); + int rewrite_eqn_to_primary(void); + int rewrite_eqn_to_secondary(void); + int species_rxn_to_trxn(struct species *s_ptr); + int tidy_logk(void); + int tidy_exchange(void); + int tidy_min_exchange(void); + int tidy_kin_exchange(void); + int tidy_gas_phase(void); + int tidy_inverse(void); + int tidy_isotopes(void); + int tidy_isotope_ratios(void); + int tidy_isotope_alphas(void); + int tidy_kin_surface(void); + int tidy_master_isotope(void); + int tidy_min_surface(void); + int tidy_phases(void); + int tidy_pp_assemblage(void); + int tidy_solutions(void); + int tidy_ss_assemblage(void); + int tidy_species(void); + int tidy_surface(void); + int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); + static LDBLE f_spinodal(LDBLE x, void *); + int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); + int ss_calc_a0_a1(cxxSS *ss_ptr); + + // transport.cpp ------------------------------- + int transport(void); + int set_initial_moles(int i); + cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, + cxxSurface *source2, std::string charge_name, LDBLE f2, + LDBLE new_Dw); + int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, + LDBLE new_Dw, int cell); + LDBLE viscosity(void); + int multi_D(LDBLE DDt, int mobile_cell, int stagnant); + int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); + int fill_spec(int cell_no); + int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); + static int sort_species_name(const void *ptr1, const void *ptr2); + int disp_surf(LDBLE stagkin_time); + int diff_stag_surf(int mobile_cell); + int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); + cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, + int n_user_new, + bool move_old); + int init_mix(void); + int init_heat_mix(int nmix); + int heat_mix(int heat_nmix); + int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + // utilities.cpp ------------------------------- +public: + int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list(const cxxNameDouble & nd, LDBLE coef); +protected: + int backspace_screen(int spaces); + LDBLE calc_alk(struct reaction *rxn_ptr); +public: + LDBLE calc_rho_0(LDBLE tc, LDBLE pa); + LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); + int compute_gfw(const char *string, LDBLE * gfw); +#if defined PHREEQ98 + int copy_title(char *token_ptr, char **ptr, int *length); +#endif + int copy_token(char *token_ptr, char **ptr, int *length); + int copy_token(std::string &token, char **ptr); + int dup_print(const char *ptr, int emphasis); + int equal(LDBLE a, LDBLE b, LDBLE eps); +public: + void *free_check_null(void *ptr); +protected: + void free_hash_strings(HashTable * Table); + int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); + int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); + void hdestroy_multi(HashTable * HashTable_ptr); + ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); + int islegit(const char c); +public: + void malloc_error(void); +protected: + int parse_couple(char *token); + int print_centered(const char *string); +public: + static int replace(const char *str1, const char *str2, char *str); + static bool replace(const char *str1, const char *str2, std::string & str); + static int strcmp_nocase(const char *str1, const char *str2); + static int strcmp_nocase_arg1(const char *str1, const char *str2); +protected: + void space(void **ptr, int i, int *max, int struct_size); + void squeeze_white(char *s_l); + int status(int count, const char *str, bool kinetics = false); + void str_tolower(char *str); + void str_toupper(char *str); +public: + char *string_duplicate(const char *token); + const char *string_hsave(const char *str); + void strings_map_clear(); +#ifdef HASH + void strings_hash_clear(); +#endif +protected: + char *string_pad(const char *str, int i); + int string_trim(char *str); + int string_trim_right(char *str); + int string_trim_left(char *str); + static LDBLE under(LDBLE xval); + void zero_double(LDBLE * target, int n); + int get_input_errors(void); +#ifdef PHREEQ98 + void AddToCEntry(char *a, int l, int i); + void ApplicationProcessMessages(void); + int copy_title(char *token_ptr, char **ptr, int *length); + extern int clean_up_null(void); +#endif + int isamong(char c, const char *s_l); + Address Hash_multi(HashTable * Table, const char *Key); + void ExpandTable_multi(HashTable * Table); +public: + int main_method(int argc, char *argv[]); + void set_phast(int); + size_t list_components(std::list &list_c); + PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} +protected: + void init(void); + + // + //Data members + // +protected: + PHRQ_io *phrq_io; + PHRQ_io ioInstance; + + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ + + struct model last_model; + int same_model; + int same_temperature; + int same_pressure; + bool same_mu; + struct punch punch; + /* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ + + std::map Rxn_temperature_map; + + /* ---------------------------------------------------------------------- + * Pressures + * ---------------------------------------------------------------------- */ + std::map Rxn_pressure_map; + + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + + int g_iterations; + LDBLE G_TOL; + std::map Rxn_surface_map; + std::map charge_group_map; + int change_surf_count; + struct Change_Surf *change_surf; + + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + std::map Rxn_exchange_map; + + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + std::map Rxn_kinetics_map; + + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + int count_save_values; + struct save_values *save_values; + struct save save; + + /*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ + cxxUse use; + + /*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_ss_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_reaction; + struct copier copy_temperature; + struct copier copy_pressure; + + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + struct inverse *inverse; + int count_inverse; + + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + std::map Rxn_mix_map; + std::map Dispersion_mix_map; + + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + std::map Rxn_reaction_map; + + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + std::map Rxn_gas_phase_map; + + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + std::map Rxn_ss_assemblage_map; + + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + std::map Rxn_pp_assemblage_map; + + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + int count_species_list; + int max_species_list; + struct species_list *species_list; + + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + std::map Rxn_solution_map; + std::vector unnumbered_solutions; + + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE patm_x; + bool numerical_fixed_volume; + bool force_numerical_fixed_volume; + bool switch_numerical; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + std::map < std::string, cxxChemRxn > pe_x; + std::map isotopes_x; + std::string default_pe_x; + cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; + + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ + + int cell_no; + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; + + /*---------------------------------------------------------------------- + * Tidy data + *---------------------------------------------------------------------- */ + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, + new_pitzer; + + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; + + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; + /*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ + + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + + struct logk **logk; + int count_logk; + int max_logk; + + char *moles_per_kilogram_string; + char *pe_string; + + struct species **s; + int count_s; + int max_s; + std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; + + struct species **s_x; + int count_s_x; + int max_s_x; + + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; + + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + struct phase **phases; + int count_phases; + int max_phases; + + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; + + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + + struct unknown **x; + int count_unknowns; + int max_unknowns; + + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *slack_unknown; + struct unknown *ss_unknown; + std::vector gas_unknowns; + + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; + + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; + + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + struct prints pr; + bool status_on; + clock_t status_interval; + clock_t status_timer; + int count_warnings; + + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + std::vector rate_p; + int count_rate_p; + + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + const char **user_punch_headings; + int user_punch_count_headings; + int n_user_punch_index; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + ChartHandler chart_handler; +#endif + + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + const char * error_string; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; + + int count_strings; + int max_strings; + + LDBLE *array; + LDBLE *delta; + LDBLE *residual; + + int input_error; + + Keywords::KEYWORDS next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; + + int max_line; + char *line; + char *line_save; + + LDBLE LOG_10; + + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; + + LDBLE inv_tol_default; + int itmax; + int max_tries; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + bool dampen_ah2o; + bool slack; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; + + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; + + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; + std::string screen_string; +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ + + std::map strings_map; +#ifdef HASH + std::hash_map strings_hash; +#endif + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + struct name_coef match_tokens[50]; + int count_match_tokens; + int count_master_isotope; + struct master_isotope **master_isotope; + int max_master_isotope; + int initial_solution_isotopes; + int count_calculate_value; + struct calculate_value **calculate_value; + int max_calculate_value; + HashTable *calculate_value_hash_table; + int count_isotope_ratio; + struct isotope_ratio **isotope_ratio; + int max_isotope_ratio; + HashTable *isotope_ratio_hash_table; + int count_isotope_alpha; + struct isotope_alpha **isotope_alpha; + int max_isotope_alpha; + HashTable *isotope_alpha_hash_table; + int phreeqc_mpi_myself; + int first_read_input; + char *user_database; + + int have_punch_name; + /* VP: Density Start */ + int print_density; + /* VP: Density End */ + + LDBLE *zeros; + int zeros_max; + + LDBLE cell_pore_volume; + LDBLE cell_porosity; + LDBLE cell_volume; + LDBLE cell_saturation; + struct system_species *sys; + int count_sys, max_sys; + LDBLE sys_tot; +#ifdef PHREEQC2 + LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE eps_r; // relative dielectric permittivity +#else + LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; + LDBLE eps_r; // relative dielectric permittivity + LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av +#endif + LDBLE solution_mass, solution_volume; + LDBLE f_rho(LDBLE rho_old); + + /* phqalloc.cpp ------------------------------- */ + PHRQMemHeader *s_pTail; + std::stringstream merged_database_stream; + std::stringstream merged_input_stream; + + /* Basic */ + PBasic * basic_interpreter; + + /* cl1.cpp ------------------------------- */ + LDBLE *x_arg, *res_arg, *scratch; + int x_arg_max, res_arg_max, scratch_max; + + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + LDBLE Q0, Q5; + LDBLE GASCON, TZ, AA; + LDBLE Z, DZ, Y; + LDBLE G1, G2, GF; + LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + + /* input.cpp ------------------------------- */ + int add_char_to_line(int *i, char c); + int check_line_impl(const char *string, int allow_empty, + int allow_eof, int allow_keyword, int print); + int get_line(void); + int get_logical_line(void *cookie, int *l); + int read_database(void); + int run_simulations(void); + int check_line_return; + int reading_db; + + /* integrate.cpp ------------------------------- */ + LDBLE midpoint_sv; + LDBLE z_global, xd_global, alpha_global; + int max_row_count, max_column_count; + int carbon; + const char **col_name, **row_name; + int count_rows, count_optimize; + int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; + int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; + LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; + LDBLE *min_delta, *max_delta; + int *iu, *is; + int klmd, nklmd, n2d, kode, iter; + LDBLE toler, error, max_pct, scaled_error; + struct master *master_alk; + int *row_back, *col_back; + unsigned long *good, *bad, *minimal; + int max_good, max_bad, max_minimal; + int count_good, count_bad, count_minimal, count_calls; + unsigned long soln_bits, phase_bits, current_bits, temp_bits; + + /* inverse.cpp ------------------------------- */ + FILE *netpath_file; + int count_inverse_models, count_pat_solutions; + int min_position[32], max_position[32], now[32]; + + /* kinetics.cpp ------------------------------- */ +public: + void *cvode_kinetics_ptr; + int cvode_test; + int cvode_error; + int cvode_n_user; + int cvode_n_reactions; + realtype cvode_step_fraction; + realtype cvode_rate_sim_time; + realtype cvode_rate_sim_time_start; + realtype cvode_last_good_time; + realtype cvode_prev_good_time; + N_Vector cvode_last_good_y; + N_Vector cvode_prev_good_y; + M_Env kinetics_machEnv; + N_Vector kinetics_y, kinetics_abstol; + void *kinetics_cvode_mem; + cxxSSassemblage *cvode_ss_assemblage_save; + cxxPPassemblage *cvode_pp_assemblage_save; + LDBLE *m_original; + LDBLE *m_temp; + int set_and_run_attempt; + + /* model.cpp ------------------------------- */ + LDBLE min_value; + LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; + int *inv_iu, *inv_is, *back_eq; + int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; + + /* phrq_io_output.cpp ------------------------------- */ + int forward_output_to_log; + + /* phreeqc_files.cpp ------------------------------- */ + char *default_data_base; +#ifdef PHREEQ98 + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; +#endif + + /* Pitzer */ + int pitzer_model, sit_model, pitzer_pe; + int full_pitzer, always_full_pitzer, ICON, IC; + LDBLE COSMOT; + LDBLE AW; + LDBLE VP, DW0; + struct pitz_param **pitz_params; + int count_pitz_param, max_pitz_param; + struct pitz_param **sit_params; + int count_sit_param, max_sit_param; + int DW(LDBLE T); + LDBLE DC(LDBLE T); + struct theta_param **theta_params; + int count_theta_param, max_theta_param; + int use_etheta; + LDBLE OTEMP; + LDBLE A0; + struct species **spec, **cations, **anions, **neutrals; + int count_cations, count_anions, count_neutrals; + int MAXCATIONS, FIRSTANION, MAXNEUTRAL; + struct pitz_param *mcb0, *mcb1, *mcc0; + int *IPRSNT; + LDBLE *M, *LGAMMA; + LDBLE BK[23], DK[23]; + +#ifdef PHREEQ98 + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; +#endif + LDBLE dummy; + + /* print.cpp ------------------------------- */ +#ifdef PHREEQ98 + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; +#endif + + /* read.cpp */ + char *prev_next_char; +#if defined PHREEQ98 + int shifts_as_points; +#endif + + /* read_class.cxx */ + dumper dump_info; + StorageBinList delete_info; + runner run_info; + char * sformatf_buffer; + size_t sformatf_buffer_size; + + /* readtr.cpp */ + std::string dump_file_name_cpp; + + /* sit.cpp ------------------------------- */ + LDBLE sit_A0; + int sit_count_cations, sit_count_anions, sit_count_neutrals; + int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; + int *sit_IPRSNT; + LDBLE *sit_M, *sit_LGAMMA; + + /* tidy.cpp ------------------------------- */ + LDBLE a0, a1, kc, kb; + + /* tally.cpp ------------------------------- */ + struct tally_buffer *t_buffer; + int tally_count_component; + struct tally *tally_table; + int count_tally_table_columns; + int count_tally_table_rows; + + /* transport.cpp ------------------------------- */ + struct sol_D *sol_D; + struct sol_D *sol_D_dbg; + struct J_ij *J_ij, *J_ij_il; + int J_ij_count_spec; + + struct M_S *m_s; + int count_m_s; + LDBLE tot1_h, tot1_o, tot2_h, tot2_o; + LDBLE diffc_max, diffc_tr, J_ij_sum; + int transp_surf; + LDBLE *heat_mix_array; + LDBLE *temp1, *temp2; + int nmix, heat_nmix; + LDBLE heat_mix_f_imm, heat_mix_f_m; + int warn_MCD_X, warn_fixed_Surf; + +#ifdef PHREEQ98 + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; +#endif + + friend class PBasic; + friend class ChartObject; + friend class IPhreeqc; + friend class TestIPhreeqc; + friend class TestSelectedOutput; + + std::vector keycount; // used to mark keywords that have been read + +#endif /* _INC_PHREEQC_H */ +#ifndef _INC_ISFINITE_H +#define _INC_ISFINITE_H + /********************************* + isfinite handling + (Note: Should NOT be guarded) + **********************************/ + +#if defined (PHREEQ98) || defined (_MSC_VER) +# define HAVE_FINITE +# define finite _finite +#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ +# if defined(DJGPP) +# define HAVE_FINITE +# endif +#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ + +#if defined(HAVE_ISFINITE) +# define PHR_ISFINITE(x) isfinite(x) +#elif defined(HAVE_FINITE) +# define PHR_ISFINITE(x) finite(x) +#elif defined(HAVE_ISNAN) +# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) +#else +# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) +#endif + +public: + static const struct const_iso iso_defaults[]; + static const int count_iso_defaults; +}; +#endif From c98ac9ac53b92412ed2ada03ad38166e051bad3e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 22:14:49 +0000 Subject: [PATCH 0446/1077] trying to fix loss of history with Phreeqc.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6326 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1863 ----------------------------------------------------- 1 file changed, 1863 deletions(-) delete mode 100644 Phreeqc.h diff --git a/Phreeqc.h b/Phreeqc.h deleted file mode 100644 index b8389df3..00000000 --- a/Phreeqc.h +++ /dev/null @@ -1,1863 +0,0 @@ -#ifndef _INC_PHREEQC_H -#define _INC_PHREEQC_H -#if defined(WIN32) -#include -#endif -#if defined(WIN32_MEMORY_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif -/* ---------------------------------------------------------------------- -* INCLUDE FILES -* ---------------------------------------------------------------------- */ -#include -#include -#include -#include -#ifdef HASH -#include -#endif -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "cvdense.h" -#include "runner.h" -#include "dumper.h" -#include "PHRQ_io.h" -#ifdef MULTICHART -#include "ChartHandler.h" -#endif -#include "Keywords.h" -#include "Pressure.h" -#include "cxxMix.h" -#include "Use.h" -#include "Surface.h" - -class cxxNameDouble; -class cxxKinetics; -//class cxxMix; -class cxxKineticsComp; -class cxxExchange; -class cxxExchComp; -class cxxGasPhase; -class cxxTemperature; -class cxxPPassemblage; -class cxxPPassemblageComp; -class cxxReaction; -class cxxSolution; -class cxxISolutionComp; -class cxxSolutionIsotope; -class cxxSSassemblage; -class cxxSS; -class cxxStorageBin; - -#include "global_structures.h" -class PBasic; - -class Phreeqc -{ -public: - Phreeqc(PHRQ_io *io = NULL); - ~Phreeqc(void); - -public: - // - // Phreeqc class methods - // - - // advection.cpp ------------------------------- - int advection(void); - - // basicsubs.cpp ------------------------------- - int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); - int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); - void basic_free(void); - - LDBLE activity(const char *species_name); - LDBLE activity_coefficient(const char *species_name); - LDBLE log_activity_coefficient(const char *species_name); - LDBLE calc_SC(void); - /* VP: Density Start */ - LDBLE calc_dens(void); - /* VP: Density End */ - LDBLE calc_logk_n(const char *name); - LDBLE calc_logk_p(const char *name); - LDBLE calc_logk_s(const char *name); - LDBLE calc_surface_charge(const char *surface_name); - LDBLE diff_layer_total(const char *total_name, const char *surface_name); - LDBLE equi_phase(const char *phase_name); - LDBLE find_gas_comp(const char *gas_comp_name); - LDBLE find_gas_p(void); - LDBLE find_gas_vm(void); - LDBLE find_misc1(const char *ss_name); - LDBLE find_misc2(const char *ss_name); - LDBLE find_ss_comp(const char *ss_comp_name); - LDBLE get_calculate_value(const char *name); - char * iso_unit(const char *total_name); - LDBLE iso_value(const char *total_name); - LDBLE kinetics_moles(const char *kinetics_name); - LDBLE log_activity(const char *species_name); - LDBLE log_molality(const char *species_name); - LDBLE molality(const char *species_name); - LDBLE pressure(void); - LDBLE pr_pressure(const char *phase_name); - LDBLE pr_phi(const char *phase_name); - LDBLE saturation_ratio(const char *phase_name); - int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); - LDBLE solution_sum_secondary(const char *total_name); - LDBLE sum_match_gases(const char *stemplate, const char *name); - LDBLE sum_match_species(const char *stemplate, const char *name); - LDBLE sum_match_ss(const char *stemplate, const char *name); - int match_elts_in_species(const char *name, const char *stemplate); - int extract_bracket(char **string, char *bracket_string); - LDBLE surf_total(const char *total_name, const char *surface_name); - static int system_species_compare(const void *ptr1, const void *ptr2); - LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); - std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); - LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); - int system_total_elements(void); - int system_total_si(void); - int system_total_aq(void); - int system_total_ex(void); - int system_total_surf(void); - int system_total_gas(void); - int system_total_ss(void); - int system_total_elt(const char *total_name); - int system_total_elt_secondary(const char *total_name); - LDBLE total(const char *total_name); - LDBLE total_mole(const char *total_name); - int system_total_solids(cxxExchange *exchange_ptr, - cxxPPassemblage *pp_assemblage_ptr, - cxxGasPhase *gas_phase_ptr, - cxxSSassemblage *ss_assemblage_ptr, - cxxSurface *surface_ptr); - - static LDBLE f_rho(LDBLE rho_old, void *cookie); - static LDBLE f_Vm(LDBLE v1, void *cookie); - // chart.cpp -#if defined PHREEQ98 - void DeleteCurves(void); - void ExtractCurveInfo(char *line, int curvenr); - void GridChar(char *s, char *a); - void MallocCurves(int nc, int ncxy); - int OpenCSVFile(char file_name[MAX_LENGTH]); - void SaveCurvesToFile(char file_name[MAX_LENGTH]); - void PlotXY(char *x, char *y); - void ReallocCurves(int new_nc); - void ReallocCurveXY(int i); - void SetAxisScale(char *a, int j, char *token, int true_); - void SetAxisTitles(char *s, int i); - void SetChartTitle(char *s); - void start_chart(bool end); -#endif - - // cl1.cpp ------------------------------- - int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q, - int *kode, LDBLE toler, - int *iter, LDBLE * x, LDBLE * res, LDBLE * error, - LDBLE * cu, int *iu, int *s, int check); - void cl1_space(int check, int n2d, int klm, int nklmd); - - // cl1mp.cpp ------------------------------- - int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - - // class_main.cpp ------------------------------- - int write_banner(void); - - /* default.cpp */ -public: - int close_input_files(void); - int close_output_files(void); - static int istream_getc(void *cookie); - int process_file_names(int argc, char *argv[], std::istream **db_cookie, - std::istream **input_cookie, int log); - - /* PHRQ_io_output.cpp */ - void screen_msg(const char * str); - - void echo_msg(const char *err_str); - int warning_msg(const char *err_str); - void set_forward_output_to_log(int value); - int get_forward_output_to_log(void); - - // dump_ostream - bool dump_open(const char *file_name); - void dump_flush(void); - void dump_close(void); - void dump_msg(const char * str); - - // log_ostream - bool log_open(const char *file_name); - void log_flush(void); - void log_close(void); - void log_msg(const char * str); - - // error_ostream - bool error_open(const char *file_name); - void error_flush(void); - void error_close(void); - void error_msg(const char * str, bool stop=false); - - // output_ostream - bool output_open(const char *file_name); - void output_flush(void); - void output_close(void); - void output_msg(const char * str); - - // punch_ostream - bool punch_open(const char *file_name); - void punch_flush(void); - void punch_close(void); - void punch_msg(const char * str); - - void fpunchf_heading(const char *name); - void fpunchf(const char *name, const char *format, double d); - void fpunchf(const char *name, const char *format, char * d); - void fpunchf(const char *name, const char *format, int d); - void fpunchf_user(int user_index, const char *format, double d); - void fpunchf_user(int user_index, const char *format, char * d); - int fpunchf_end_row(const char *format); - - // dw.cpp ------------------------------- - int BB(LDBLE T); - LDBLE PS(LDBLE T); - LDBLE VLEST(LDBLE T); - int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); - int QQ(LDBLE T, LDBLE D); - LDBLE BASE(LDBLE D); - - // input.cpp ------------------------------- - int reading_database(void); - void set_reading_database(int reading_database); - int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); - - // integrate.cpp ------------------------------- - int calc_all_g(void); - int calc_init_g(void); - int initial_surface_water(void); - int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); - int calc_all_donnan(void); - int calc_init_donnan(void); - LDBLE g_function(LDBLE x_value); - LDBLE midpnt(LDBLE x1, LDBLE x2, int n); - void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); - LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); - LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); - int calc_all_donnan_music(void); - int calc_init_donnan_music(void); - - // inverse.cpp ------------------------------- - int inverse_models(void); - int add_to_file(const char *filename, const char *string); - int bit_print(unsigned long bits, int l); - int carbon_derivs(struct inverse *inv_ptr); - int check_isotopes(struct inverse *inv_ptr); - int check_solns(struct inverse *inv_ptr); - int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); - cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); - LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); - int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); - int post_mortem(void); - bool test_cl1_solution(void); - unsigned long get_bits(unsigned long bits, int position, int number); - unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); - void dump_netpath(struct inverse *inv_ptr); - int dump_netpath_pat(struct inverse *inv_ptr); - int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); - int phase_isotope_inequalities(struct inverse *inv_ptr); - int print_model(struct inverse *inv_ptr); - int punch_model_heading(struct inverse *inv_ptr); - int punch_model(struct inverse *inv_ptr); - void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); - - void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); - int range(struct inverse *inv_ptr, unsigned long cur_bits); - int save_bad(unsigned long bits); - int save_good(unsigned long bits); - int save_minimal(unsigned long bits); - unsigned long set_bit(unsigned long bits, int position, int value); - int setup_inverse(struct inverse *inv_ptr); - int set_initial_solution(int n_user_old, int n_user_new); - int set_ph_c(struct inverse *inv_ptr, - int i, cxxSolution *soln_ptr_orig, int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); - int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); - int solve_inverse(struct inverse *inv_ptr); - int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); - int subset_bad(unsigned long bits); - int subset_minimal(unsigned long bits); - int superset_minimal(unsigned long bits); - int write_optimize_names(struct inverse *inv_ptr); - - // isotopes.cpp ------------------------------- - int add_isotopes(cxxSolution &solution_ptr); - int calculate_values(void); - int calculate_isotope_moles(struct element *elt_ptr, - cxxSolution *solution_ptr, LDBLE total_moles); - LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); - int from_pcil(struct master_isotope *master_isotope_ptr); - int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_tu(struct master_isotope *master_isotope_ptr); - struct calculate_value *calculate_value_alloc(void); - int calculate_value_free(struct calculate_value *calculate_value_ptr); - struct calculate_value *calculate_value_search(const char *name); - struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); - struct isotope_alpha *isotope_alpha_alloc(void); - struct isotope_alpha *isotope_alpha_search(const char *name); - struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); - struct isotope_ratio *isotope_ratio_alloc(void); - struct isotope_ratio *isotope_ratio_search(const char *name); - struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_alloc(void); - struct master_isotope *master_isotope_search(const char *name); - int print_initial_solution_isotopes(void); - int print_isotope_ratios(void); - int print_isotope_alphas(void); - int punch_isotopes(void); - int punch_calculate_values(void); - int read_calculate_values(void); - int read_isotopes(void); - int read_isotope_ratios(void); - int read_isotope_alphas(void); - int calculate_value_init(struct calculate_value *calculate_value_ptr); - int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); - int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); - int master_isotope_init(struct master_isotope *master_isotope_ptr); - - // kinetics.cpp ------------------------------- - void cvode_init(void); - int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); - int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_advection(int i, int use_mix, int use_kinetics, int nsaver); - int free_cvode(void); -public: - static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); - static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - - int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); - int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, - LDBLE time_step); - int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); - int set_reaction(int i, int use_mix, int use_kinetics); - int set_transport(int i, int use_mix, int use_kinetics, int nsaver); - int store_get_equi_reactants(int k, int kin_end); - int count_pp, count_pg, count_ss; - LDBLE *x0_moles; - - // mainsubs.cpp ------------------------------- - std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - int copy_entities(void); - void initialize(void); - int initial_exchangers(int print); - int initial_gas_phases(int print); - int initial_solutions(int print); - int step_save_exch(int n_user); - int step_save_surf(int n_user); - int initial_surfaces(int print); - int reactions(void); - int saver(void); - int xsolution_save(int k_user); - int xexchange_save(int n_user); - int xgas_save(int n_user); - int xpp_assemblage_save(int n_user); - int xss_assemblage_save(int n_user); - int xsurface_save(int n_user); - int do_initialize(void); - int do_status(void); - void save_init(int i); - int copy_use(int i); - int set_use(void); - - // model.cpp ------------------------------- - int check_residuals(void); - int free_model_allocs(void); - int ineq(int kode); - int model(void); - int jacobian_sums(void); - int mb_gases(void); - int mb_ss(void); - int mb_sums(void); - int molalities(int allow_overflow); - int reset(void); - int residuals(void); - int set(int initial); - int sum_species(void); - int surface_model(void); - LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); - LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); - LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); - int numerical_jacobian(void); - void set_inert_moles(void); - void unset_inert_moles(void); -#ifdef SLNQ - int add_trivial_eqns(int rows, int cols, LDBLE * matrix); - //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -#endif - int calc_gas_pressures(void); - int calc_fixed_volume_gas_pressures(void); - int calc_ss_fractions(void); - int gammas(LDBLE mu); - int initial_guesses(void); - int revise_guesses(void); - int ss_binary(cxxSS *ss_ptr); - int ss_ideal(cxxSS *ss_ptr); - int gas_in; - void ineq_init(int max_row_count, int max_column_count); - - // parse.cpp ------------------------------- - int check_eqn(int association); - int get_charge(char *charge, LDBLE * z); - int get_elt(char **t_ptr, char *element, int *i); - int get_elts_in_species(char **t_ptr, LDBLE coef); - int get_num(char **t_ptr, LDBLE * num); - int get_secondary_in_species(char **t_ptr, LDBLE coef); - int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - int get_coef(LDBLE * coef, char **eqnaddr); - int get_secondary(char **t_ptr, char *element, int *i); - int get_species(char **ptr); - - // phqalloc.cpp ------------------------------- -public: -#if !defined(NDEBUG) - void *PHRQ_malloc(size_t, const char *, int); - void *PHRQ_calloc(size_t, size_t, const char *, int); - void *PHRQ_realloc(void *, size_t, const char *, int); -#else - void *PHRQ_malloc(size_t); - void *PHRQ_calloc(size_t, size_t); - void *PHRQ_realloc(void *, size_t); -#endif - void PHRQ_free(void *ptr); - void PHRQ_free_all(void); - -public: - - // pitzer.cpp ------------------------------- - struct pitz_param *pitz_param_read(char *string, int n); - int pitz_param_search(struct pitz_param *pzp_ptr); - int sit_param_search(struct pitz_param *pzp_ptr); - struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); - struct theta_param *theta_param_alloc(void); - int theta_param_init(struct theta_param *theta_param_ptr); - int gammas_pz(void); - int model_pz(void); - int pitzer(void); - int pitzer_clean_up(void); - int pitzer_init(void); - int pitzer_tidy(void); - int read_pitzer(void); - int set_pz(int initial); - int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_pz(void); - int ISPEC(const char *name); - LDBLE G(LDBLE Y); - LDBLE GP(LDBLE Y); - int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); - int BDK(LDBLE X); - int pitzer_initial_guesses(void); - int pitzer_revise_guesses(void); - int PTEMP(LDBLE TK); - LDBLE JAY(LDBLE X); - LDBLE JPRIME(LDBLE Y); - int jacobian_pz(void); - - // pitzer_structures.cpp ------------------------------- - struct pitz_param *pitz_param_alloc(void); - int pitz_param_init(struct pitz_param *pitz_param_ptr); - struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); - int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); - - // prep.cpp ------------------------------- - int add_potential_factor(void); - int add_cd_music_factors(int n); - int add_surface_charge_balance(void); - int add_cd_music_charge_balances(int i); - int build_gas_phase(void); - int build_fixed_volume_gas(void); - int build_jacobian_sums(int k); - int build_mb_sums(void); - int build_min_exch(void); - int build_model(void); - int build_pure_phases(void); - int build_ss_assemblage(void); - int build_solution_phase_boundaries(void); - int build_species_list(int n); - int build_min_surface(void); - LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); - LDBLE calc_delta_v(reaction * r_ptr, bool phase); - LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); - LDBLE calc_PR(); - int calc_vm(LDBLE tc, LDBLE pa); - int change_hydrogen_in_elt_list(LDBLE charge); - int clear(void); - //int convert_units(struct solution *solution_ptr); - int convert_units(cxxSolution *solution_ptr); - LDBLE a_aa_sum, b2, b_sum, R_TK; - LDBLE f_Vm(LDBLE v1); - struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); - struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); - int inout(void); - int is_special(struct species *spec); - int mb_for_species_aq(int n); - int mb_for_species_ex(int n); - int mb_for_species_surf(int n); - int quick_setup(void); - int resetup_master(void); - int save_model(void); - int setup_exchange(void); - int setup_gas_phase(void); - int setup_fixed_volume_gas(void); - int setup_slack(void); - int setup_master_rxn(struct master **master_ptr_list, - const std::string &pe_rxn); - int setup_pure_phases(void); - int adjust_setup_pure_phases(void); - int setup_related_surface(void); - int setup_ss_assemblage(void); - int setup_solution(void); - int adjust_setup_solution(void); - int setup_surface(void); - int setup_unknowns(void); - int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); - int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); - int store_jacob0(int row, int column, LDBLE coef); - int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); - int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); - int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); - int tidy_redox(void); - struct master **unknown_alloc_master(void); - int write_mb_eqn_x(void); - int write_mb_for_species_list(int n); - int write_mass_action_eqn_x(int stop); - - int check_same_model(void); - int k_temp(LDBLE tc, LDBLE pa); - LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); - int prep(void); - int reprep(void); - int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); - int switch_bases(void); - int write_phase_sys_total(int n); - - // print.cpp ------------------------------- - char *sformatf(const char *format, ...); - int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); - int print_all(void); - int print_exchange(void); - int print_gas_phase(void); - int print_master_reactions(void); - int print_reaction(struct reaction *rxn_ptr); - int print_species(void); - int print_surface(void); - int print_user_print(void); - int punch_all(void); - int print_alkalinity(void); - int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); - int print_eh(void); - int print_reaction(void); - int print_kinetics(void); - int print_mix(void); - int print_pp_assemblage(void); - int print_ss_assemblage(void); - int print_saturation_indices(void); - int print_surface_cd_music(void); - int print_totals(void); - int print_using(void); - /*int print_user_print(void);*/ - int punch_gas_phase(void); - int punch_identifiers(void); - int punch_kinetics(void); - int punch_molalities(void); - int punch_activities(void); - int punch_pp_assemblage(void); - int punch_ss_assemblage(void); - int punch_saturation_indices(void); - int punch_totals(void); - int punch_user_punch(void); -#if defined MULTICHART - int punch_user_graph(void); -#endif - - // read.cpp ------------------------------- - int read_input(void); - int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); - int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); - int read_log_k_only(char *ptr, LDBLE * log_k); - int read_t_c_only(char *ptr, LDBLE *t_c); - int read_p_c_only(char *ptr, LDBLE * p_c); - int read_omega_only(char *ptr, LDBLE *omega); - int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description, int allow_negative=FALSE); - int check_key(const char *str); - int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, - const char *default_units, bool print); - int find_option(const char *item, int *n, const char **list, int count_list, - int exact); - int get_option(const char **opt_list, int count_opt_list, char **next_char); - int get_true_false(char *string, int default_value); - - int add_psi_master_species(char *token); - int read_advection(void); - int read_analytical_expression_only(char *ptr, LDBLE * log_k); - /* VP: Density Start */ - int read_millero_abcdef (char *ptr, LDBLE * abcdef); - /* VP: Density End */ - int read_copy(void); - int read_debug(void); - int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); - int read_vm_only(char *ptr, LDBLE * delta_v, - DELTA_V_UNIT * units); - int read_llnl_aqueous_model_parameters(void); - int read_exchange(void); - int read_exchange_master_species(void); - int read_exchange_species(void); - int read_gas_phase(void); - int read_incremental_reactions(void); - int read_inverse(void); - int read_inv_balances(struct inverse *inverse_ptr, char *next_char); - int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); - int read_inv_phases(struct inverse *inverse_ptr, char *next_char); - int read_kinetics(void); - int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); - LDBLE *read_list_doubles(char **ptr, int *count_doubles); - int *read_list_ints(char **ptr, int *count_ints, int positive); - int *read_list_t_f(char **ptr, int *count_ints); - int read_master_species(void); - int read_mix(void); - int read_named_logk(void); - int read_phases(void); - int read_print(void); - int read_pp_assemblage(void); - int read_rates(void); - int read_reaction(void); - int read_reaction_reactants(cxxReaction *reaction_ptr); - int read_reaction_steps(cxxReaction *reaction_ptr); - int read_solid_solutions(void); - int read_temperature(void); - int read_reaction_temps(struct temperature *temperature_ptr); - int read_reaction_pressure(void); - int read_reaction_pressure_raw(void); - int read_save(void); - int read_selected_output(void); - int read_solution(void); - int read_species(void); - int read_surface(void); - int read_surface_master_species(void); - int read_surface_species(void); - int read_use(void); - int read_title(void); - int read_user_print(void); - int read_user_punch(void); -#if defined PHREEQ98 - int read_user_graph(void); -#endif -#if defined MULTICHART - int read_user_graph_handler(); -#endif - int next_keyword_or_option(const char **opt_list, int count_opt_list); - int cleanup_after_parser(CParser &parser); - - // ReadClass.cxx - int read_dump(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); - - // readtr.cpp ------------------------------- - int read_transport(void); - int dump(void); - int dump_exchange(int k); - int dump_gas_phase(int k); - int dump_kinetics(int k); - int dump_mix(int k); - int dump_pp_assemblage(int k); - int dump_reaction(int k); - int dump_ss_assemblage(int k); - int dump_solution(int k); - int dump_surface(int k); - int dump_cpp(void); - int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - - // sit.cpp ------------------------------- - int gammas_sit(void); - int model_sit(void); - int sit(void); - int sit_clean_up(void); - int sit_init(void); - int sit_tidy(void); - int read_sit(void); - int set_sit(int initial); - int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_sit(void); - int sit_ISPEC(const char *name); - /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ - int sit_initial_guesses(void); - int sit_revise_guesses(void); - int PTEMP_SIT(LDBLE tk); - int jacobian_sit(void); - - // spread.cpp ------------------------------- - int read_solution_spread(void); - int copy_token_tab(char *token_ptr, char **ptr, int *length); - int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); - int spread_row_free(struct spread_row *spread_row_ptr); - int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); - struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI - void add_row(struct spread_row *spread_row_ptr); - void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); - void free_spread(void); - struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - - // step.cpp ------------------------------- - int step(LDBLE step_fraction); - int xsolution_zero(void); - int add_exchange(cxxExchange *exchange_ptr); - int add_gas_phase(cxxGasPhase *gas_phase_ptr); - int add_kinetics(cxxKinetics *kinetics_ptr); - int add_mix(cxxMix * mix_ptr); - int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); - int add_solution(cxxSolution *solution_ptr, LDBLE extensive, - LDBLE intensive); - int add_surface(cxxSurface *surface_ptr); - int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int gas_phase_check(cxxGasPhase *gas_phase_ptr); - int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); - int reaction_calc(cxxReaction *reaction_ptr); - int solution_check(void); - int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); - - // structures.cpp ------------------------------- - int clean_up(void); - int reinitialize(void); - int copier_add(struct copier *copier_ptr, int n_user, int start, int end); - int copier_free(struct copier *copier_ptr); - int copier_init(struct copier *copier_ptr); - static int element_compare(const void *ptr1, const void *ptr2); -public: - struct element *element_store(const char *element); - int elt_list_combine(void); - static int elt_list_compare(const void *ptr1, const void *ptr2); -protected: - struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); - int elt_list_print(struct elt_list *elt_list_ptr); - struct elt_list *elt_list_save(void); - cxxNameDouble elt_list_NameDouble(void); -public: - enum entity_type get_entity_enum(char *name); - struct inverse *inverse_alloc(void); - int inverse_delete(int i); - static int inverse_isotope_compare(const void *ptr1, const void *ptr2); - struct inverse *inverse_search(int n_user, int *n); - int inverse_sort(void); -protected: - struct logk *logk_alloc(void); - int logk_copy2orig(struct logk *logk_ptr); - struct logk *logk_store(char *name, int replace_if_found); - struct logk *logk_search(const char *name); - struct master *master_alloc(void); - static int master_compare(const void *ptr1, const void *ptr2); - int master_delete(char *ptr); -public: - struct master *master_bsearch(const char *ptr); - struct master *master_bsearch_primary(const char *ptr); - struct master *master_bsearch_secondary(char *ptr); - struct master *master_search(char *ptr, int *n); - struct pe_data *pe_data_alloc(void); -public: - struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); - struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -protected: - int pe_data_store(struct pe_data **pe, const char *token); -public: - struct phase *phase_bsearch(const char *ptr, int *j, int print); -protected: - static int phase_compare(const void *ptr1, const void *ptr2); - int phase_delete(int i); - struct phase *phase_store(const char *name); -public: - struct rate *rate_bsearch(char *ptr, int *j); - int rate_free(struct rate *rate_ptr); - struct rate *rate_search(const char *name, int *n); - int rate_sort(void); - struct reaction *rxn_alloc(int ntokens); - struct reaction *rxn_dup(struct reaction *rxn_ptr_old); - LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); - int rxn_free(struct reaction *rxn_ptr); - int rxn_print(struct reaction *rxn_ptr); - static int s_compare(const void *ptr1, const void *ptr2); - int s_delete(int i); - struct species *s_search(const char *name); - struct species *s_store(const char *name, LDBLE z, int replace_if_found); -protected: - struct save_values *save_values_bsearch(struct save_values *k, int *n); - static int save_values_compare(const void *ptr1, const void *ptr2); - int save_values_sort(void); - int save_values_store(struct save_values *s_v); - static int isotope_compare(const void *ptr1, const void *ptr2); - static int species_list_compare_alk(const void *ptr1, const void *ptr2); - static int species_list_compare_master(const void *ptr1, const void *ptr2); - int species_list_sort(void); - struct Change_Surf *change_surf_alloc(int count); -public: - struct master *surface_get_psi_master(const char *name, int plane); - int system_duplicate(int i, int save_old); - int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); - int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_combine(void); - int trxn_copy(struct reaction *rxn_ptr); - LDBLE trxn_find_coef(const char *str, int start); - int trxn_print(void); - int trxn_reverse_k(void); - int trxn_sort(void); - int trxn_swap(const char *token); - struct unknown *unknown_alloc(void); - int unknown_delete(int i); - int unknown_free(struct unknown *unknown_ptr); - int entity_exists(char *name, int n_user); - static int inverse_compare(const void *ptr1, const void *ptr2); - int inverse_free(struct inverse *inverse_ptr); - static int kinetics_compare_int(const void *ptr1, const void *ptr2); - int logk_init(struct logk *logk_ptr); - static int master_compare_string(const void *ptr1, const void *ptr2); - int master_free(struct master *master_ptr); - struct phase *phase_alloc(void); - static int phase_compare_string(const void *ptr1, const void *ptr2); - int phase_free(struct phase *phase_ptr); - int phase_init(struct phase *phase_ptr); - static int rate_compare(const void *ptr1, const void *ptr2); - static int rate_compare_string(const void *ptr1, const void *ptr2); - struct species *s_alloc(void); - int s_free(struct species *s_ptr); - int s_init(struct species *s_ptr); - static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); - static int solution_compare(const void *ptr1, const void *ptr2); - static int solution_compare_int(const void *ptr1, const void *ptr2); - static int species_list_compare(const void *ptr1, const void *ptr2); - static int surface_compare_int(const void *ptr1, const void *ptr2); - static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); - int trxn_multiply(LDBLE coef); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - extern void MergeFinalize(void); -#endif - struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); - struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); - struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); - struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); - - void Use2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb); - - /* tally.cpp */ - void add_all_components_tally(void); - int build_tally_table(void); - int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); - int diff_tally_table(void); - int extend_tally_table(void); - int free_tally_table(void); - int fill_tally_table(int *n_user, int index_conservative, int n_buffer); - int get_tally_table_rows_columns(int *rows, int *columns); - int get_tally_table_column_heading(int column, int *type, char *string); - int get_tally_table_row_heading(int column, char *string); - int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); - int zero_tally_table(void); - int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); - int get_all_components(void); - int print_tally_table(void); - int set_reaction_moles(int n_user, LDBLE moles); - int set_reaction_temperature(int n_user, LDBLE tc); - int set_kinetics_time(int n_user, LDBLE step); - - // tidy.cpp ------------------------------- - int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); - int add_logks(struct logk *logk_ptr, int repeats); - LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); - int replace_solids_gases(void); - int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); - int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); - int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -public: - int tidy_punch(void); - int tidy_model(void); - int check_species_input(void); - LDBLE coef_in_master(struct master *master_ptr); - int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); - int reset_last_model(void); - int rewrite_eqn_to_primary(void); - int rewrite_eqn_to_secondary(void); - int species_rxn_to_trxn(struct species *s_ptr); - int tidy_logk(void); - int tidy_exchange(void); - int tidy_min_exchange(void); - int tidy_kin_exchange(void); - int tidy_gas_phase(void); - int tidy_inverse(void); - int tidy_isotopes(void); - int tidy_isotope_ratios(void); - int tidy_isotope_alphas(void); - int tidy_kin_surface(void); - int tidy_master_isotope(void); - int tidy_min_surface(void); - int tidy_phases(void); - int tidy_pp_assemblage(void); - int tidy_solutions(void); - int tidy_ss_assemblage(void); - int tidy_species(void); - int tidy_surface(void); - int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); - static LDBLE f_spinodal(LDBLE x, void *); - int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); - int ss_calc_a0_a1(cxxSS *ss_ptr); - - // transport.cpp ------------------------------- - int transport(void); - int set_initial_moles(int i); - cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, - cxxSurface *source2, std::string charge_name, LDBLE f2, - LDBLE new_Dw); - int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, - LDBLE new_Dw, int cell); - LDBLE viscosity(void); - int multi_D(LDBLE DDt, int mobile_cell, int stagnant); - int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); - int fill_spec(int cell_no); - int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); - static int sort_species_name(const void *ptr1, const void *ptr2); - int disp_surf(LDBLE stagkin_time); - int diff_stag_surf(int mobile_cell); - int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); - cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, - int n_user_new, - bool move_old); - int init_mix(void); - int init_heat_mix(int nmix); - int heat_mix(int heat_nmix); - int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); - - // utilities.cpp ------------------------------- -public: - int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); - int add_elt_list(const cxxNameDouble & nd, LDBLE coef); -protected: - int backspace_screen(int spaces); - LDBLE calc_alk(struct reaction *rxn_ptr); -public: - LDBLE calc_rho_0(LDBLE tc, LDBLE pa); - LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); - int compute_gfw(const char *string, LDBLE * gfw); -#if defined PHREEQ98 - int copy_title(char *token_ptr, char **ptr, int *length); -#endif - int copy_token(char *token_ptr, char **ptr, int *length); - int copy_token(std::string &token, char **ptr); - int dup_print(const char *ptr, int emphasis); - int equal(LDBLE a, LDBLE b, LDBLE eps); -public: - void *free_check_null(void *ptr); -protected: - void free_hash_strings(HashTable * Table); - int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); - int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); - void hdestroy_multi(HashTable * HashTable_ptr); - ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); - int islegit(const char c); -public: - void malloc_error(void); -protected: - int parse_couple(char *token); - int print_centered(const char *string); -public: - static int replace(const char *str1, const char *str2, char *str); - static bool replace(const char *str1, const char *str2, std::string & str); - static int strcmp_nocase(const char *str1, const char *str2); - static int strcmp_nocase_arg1(const char *str1, const char *str2); -protected: - void space(void **ptr, int i, int *max, int struct_size); - void squeeze_white(char *s_l); - int status(int count, const char *str, bool kinetics = false); - void str_tolower(char *str); - void str_toupper(char *str); -public: - char *string_duplicate(const char *token); - const char *string_hsave(const char *str); - void strings_map_clear(); -#ifdef HASH - void strings_hash_clear(); -#endif -protected: - char *string_pad(const char *str, int i); - int string_trim(char *str); - int string_trim_right(char *str); - int string_trim_left(char *str); - static LDBLE under(LDBLE xval); - void zero_double(LDBLE * target, int n); - int get_input_errors(void); -#ifdef PHREEQ98 - void AddToCEntry(char *a, int l, int i); - void ApplicationProcessMessages(void); - int copy_title(char *token_ptr, char **ptr, int *length); - extern int clean_up_null(void); -#endif - int isamong(char c, const char *s_l); - Address Hash_multi(HashTable * Table, const char *Key); - void ExpandTable_multi(HashTable * Table); -public: - int main_method(int argc, char *argv[]); - void set_phast(int); - size_t list_components(std::list &list_c); - PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} -protected: - void init(void); - - // - //Data members - // -protected: - PHRQ_io *phrq_io; - PHRQ_io ioInstance; - - /* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ - - struct model last_model; - int same_model; - int same_temperature; - int same_pressure; - bool same_mu; - struct punch punch; - /* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ - - std::map Rxn_temperature_map; - - /* ---------------------------------------------------------------------- - * Pressures - * ---------------------------------------------------------------------- */ - std::map Rxn_pressure_map; - - /* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ - - int g_iterations; - LDBLE G_TOL; - std::map Rxn_surface_map; - std::map charge_group_map; - int change_surf_count; - struct Change_Surf *change_surf; - - /* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ - std::map Rxn_exchange_map; - - /* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ - std::map Rxn_kinetics_map; - - /*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ - int count_save_values; - struct save_values *save_values; - struct save save; - - /*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ - cxxUse use; - - /*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ - struct copier copy_solution; - struct copier copy_pp_assemblage; - struct copier copy_exchange; - struct copier copy_surface; - struct copier copy_ss_assemblage; - struct copier copy_gas_phase; - struct copier copy_kinetics; - struct copier copy_mix; - struct copier copy_reaction; - struct copier copy_temperature; - struct copier copy_pressure; - - /*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ - - struct inverse *inverse; - int count_inverse; - - /*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ - std::map Rxn_mix_map; - std::map Dispersion_mix_map; - - /*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ - std::map Rxn_reaction_map; - - /*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ - std::map Rxn_gas_phase_map; - - /*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ - std::map Rxn_ss_assemblage_map; - - /*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - std::map Rxn_pp_assemblage_map; - - /*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ - int count_species_list; - int max_species_list; - struct species_list *species_list; - - /*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ - - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ - /*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - std::map Rxn_solution_map; - std::vector unnumbered_solutions; - - /*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ - char *title_x; - int new_x; - char *description_x; - LDBLE tc_x; - LDBLE tk_x; - LDBLE patm_x; - bool numerical_fixed_volume; - bool force_numerical_fixed_volume; - bool switch_numerical; - LDBLE ph_x; - LDBLE solution_pe_x; - LDBLE mu_x; - LDBLE ah2o_x; - LDBLE density_x; - LDBLE total_h_x; - LDBLE total_o_x; - LDBLE cb_x; - LDBLE total_ions_x; - LDBLE mass_water_aq_x; - LDBLE mass_water_surfaces_x; - LDBLE mass_water_bulk_x; - char *units_x; - std::map < std::string, cxxChemRxn > pe_x; - std::map isotopes_x; - std::string default_pe_x; - cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; - LDBLE total_carbon; - LDBLE total_co2; - LDBLE total_alkalinity; - LDBLE gfw_water; - LDBLE step_x; - LDBLE kin_time_x; - - /*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ - int count_cells; - int count_shifts; - int ishift; - int bcon_first; - int bcon_last; - int correct_disp; - LDBLE tempr; - LDBLE timest; - int simul_tr; - LDBLE diffc; - LDBLE heat_diffc; - int cell; - LDBLE mcd_substeps; - struct stag_data *stag_data; - int print_modulus; - int punch_modulus; - int dump_in; - int dump_modulus; - int transport_warnings; - struct cell_data *cell_data; - int multi_Dflag; /* signals calc'n of multicomponent diffusion */ - int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ - LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ - LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ - LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ - LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ - LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ - LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, - Dp = Dw * (multi_Dpor)^multi_Dn */ - LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, - Dpil = Dw / interlayer_tortf */ - - int cell_no; - /*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ - int count_ad_cells; - int count_ad_shifts; - int print_ad_modulus; - int punch_ad_modulus; - int *advection_punch, *advection_print; - LDBLE advection_kin_time; - LDBLE advection_kin_time_defined; - int advection_warnings; - - /*---------------------------------------------------------------------- - * Tidy data - *---------------------------------------------------------------------- */ - int new_model, new_exchange, new_pp_assemblage, new_surface, - new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, - new_pitzer; - - /*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ - - struct element **elements; - int count_elements; - int max_elements; - struct element *element_h_one; - - /*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ - - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ - int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; - /*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ - - /*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ - - struct logk **logk; - int count_logk; - int max_logk; - - char *moles_per_kilogram_string; - char *pe_string; - - struct species **s; - int count_s; - int max_s; - std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; - - struct species **s_x; - int count_s_x; - int max_s_x; - - struct species *s_h2o; - struct species *s_hplus; - struct species *s_h3oplus; - struct species *s_eminus; - struct species *s_co3; - struct species *s_h2; - struct species *s_o2; - - /*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ - struct phase **phases; - int count_phases; - int max_phases; - - /*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; - - /*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ - - struct unknown **x; - int count_unknowns; - int max_unknowns; - - struct unknown *ah2o_unknown; - struct unknown *alkalinity_unknown; - struct unknown *carbon_unknown; - struct unknown *charge_balance_unknown; - struct unknown *exchange_unknown; - struct unknown *mass_hydrogen_unknown; - struct unknown *mass_oxygen_unknown; - struct unknown *mb_unknown; - struct unknown *mu_unknown; - struct unknown *pe_unknown; - struct unknown *ph_unknown; - struct unknown *pure_phase_unknown; - struct unknown *solution_phase_boundary_unknown; - struct unknown *surface_unknown; - struct unknown *gas_unknown; - struct unknown *slack_unknown; - struct unknown *ss_unknown; - std::vector gas_unknowns; - - /*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ - struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; - - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; - - /* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ - struct prints pr; - bool status_on; - clock_t status_interval; - clock_t status_timer; - int count_warnings; - - /* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ - struct rate *rates; - int count_rates; - LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, - rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; - std::vector rate_p; - int count_rate_p; - - /* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ - struct rate *user_print; - struct rate *user_punch; - const char **user_punch_headings; - int user_punch_count_headings; - int n_user_punch_index; - -#if defined PHREEQ98 - struct rate *user_graph; - char **user_graph_headings; - int user_graph_count_headings; -#endif -#if defined MULTICHART - ChartHandler chart_handler; -#endif - - /* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ - const char * error_string; - int simulation; - int state; - int reaction_step; - int transport_step; - int transport_start; - int advection_step; - int stop_program; - int incremental_reactions; - - int count_strings; - int max_strings; - - LDBLE *array; - LDBLE *delta; - LDBLE *residual; - - int input_error; - - Keywords::KEYWORDS next_keyword; - int parse_error; - int paren_count; - int iterations; - int gamma_iterations; - int run_reactions_iterations; - - int max_line; - char *line; - char *line_save; - - LDBLE LOG_10; - - int debug_model; - int debug_prep; - int debug_set; - int debug_diffuse_layer; - int debug_inverse; - - LDBLE inv_tol_default; - int itmax; - int max_tries; - LDBLE ineq_tol; - LDBLE convergence_tolerance; - LDBLE step_size; - LDBLE pe_step_size; - LDBLE step_size_now; - LDBLE pe_step_size_now; - LDBLE pp_scale; - LDBLE pp_column_scale; - int diagonal_scale; /* 0 not used, 1 used */ - int mass_water_switch; - int delay_mass_water; - bool dampen_ah2o; - bool slack; - LDBLE censor; - int aqueous_only; - int negative_concentrations; - int calculating_deriv; - int numerical_deriv; - - int count_total_steps; - int phast; - LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; - int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, - llnl_count_co2_coefs; - - char *selected_output_file_name; - char *dump_file_name; - int remove_unstable_phases; - std::string screen_string; -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif - - /* ---------------------------------------------------------------------- */ - /* - * Hash definitions - */ - - std::map strings_map; -#ifdef HASH - std::hash_map strings_hash; -#endif - HashTable *elements_hash_table; - HashTable *species_hash_table; - HashTable *phases_hash_table; - HashTable *logk_hash_table; - HashTable *master_isotope_hash_table; - -#if defined(PHREEQCI_GUI) -#include "../../phreeqci_gui.h" -#endif /* defined(PHREEQCI_GUI) */ - /* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ - struct name_coef match_tokens[50]; - int count_match_tokens; - int count_master_isotope; - struct master_isotope **master_isotope; - int max_master_isotope; - int initial_solution_isotopes; - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; - HashTable *calculate_value_hash_table; - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; - HashTable *isotope_ratio_hash_table; - int count_isotope_alpha; - struct isotope_alpha **isotope_alpha; - int max_isotope_alpha; - HashTable *isotope_alpha_hash_table; - int phreeqc_mpi_myself; - int first_read_input; - char *user_database; - - int have_punch_name; - /* VP: Density Start */ - int print_density; - /* VP: Density End */ - - LDBLE *zeros; - int zeros_max; - - LDBLE cell_pore_volume; - LDBLE cell_porosity; - LDBLE cell_volume; - LDBLE cell_saturation; - struct system_species *sys; - int count_sys, max_sys; - LDBLE sys_tot; -#ifdef PHREEQC2 - LDBLE AA_basic, BB_basic, CC, I_m, rho_0; - LDBLE eps_r; // relative dielectric permittivity -#else - LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; - LDBLE eps_r; // relative dielectric permittivity - LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av -#endif - LDBLE solution_mass, solution_volume; - LDBLE f_rho(LDBLE rho_old); - - /* phqalloc.cpp ------------------------------- */ - PHRQMemHeader *s_pTail; - std::stringstream merged_database_stream; - std::stringstream merged_input_stream; - - /* Basic */ - PBasic * basic_interpreter; - - /* cl1.cpp ------------------------------- */ - LDBLE *x_arg, *res_arg, *scratch; - int x_arg_max, res_arg_max, scratch_max; - - /* dw.cpp ------------------------------- */ - /* COMMON /QQQQ/ */ - LDBLE Q0, Q5; - LDBLE GASCON, TZ, AA; - LDBLE Z, DZ, Y; - LDBLE G1, G2, GF; - LDBLE B1, B2, B1T, B2T, B1TT, B2TT; - - /* input.cpp ------------------------------- */ - int add_char_to_line(int *i, char c); - int check_line_impl(const char *string, int allow_empty, - int allow_eof, int allow_keyword, int print); - int get_line(void); - int get_logical_line(void *cookie, int *l); - int read_database(void); - int run_simulations(void); - int check_line_return; - int reading_db; - - /* integrate.cpp ------------------------------- */ - LDBLE midpoint_sv; - LDBLE z_global, xd_global, alpha_global; - int max_row_count, max_column_count; - int carbon; - const char **col_name, **row_name; - int count_rows, count_optimize; - int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; - int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; - LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; - LDBLE *min_delta, *max_delta; - int *iu, *is; - int klmd, nklmd, n2d, kode, iter; - LDBLE toler, error, max_pct, scaled_error; - struct master *master_alk; - int *row_back, *col_back; - unsigned long *good, *bad, *minimal; - int max_good, max_bad, max_minimal; - int count_good, count_bad, count_minimal, count_calls; - unsigned long soln_bits, phase_bits, current_bits, temp_bits; - - /* inverse.cpp ------------------------------- */ - FILE *netpath_file; - int count_inverse_models, count_pat_solutions; - int min_position[32], max_position[32], now[32]; - - /* kinetics.cpp ------------------------------- */ -public: - void *cvode_kinetics_ptr; - int cvode_test; - int cvode_error; - int cvode_n_user; - int cvode_n_reactions; - realtype cvode_step_fraction; - realtype cvode_rate_sim_time; - realtype cvode_rate_sim_time_start; - realtype cvode_last_good_time; - realtype cvode_prev_good_time; - N_Vector cvode_last_good_y; - N_Vector cvode_prev_good_y; - M_Env kinetics_machEnv; - N_Vector kinetics_y, kinetics_abstol; - void *kinetics_cvode_mem; - cxxSSassemblage *cvode_ss_assemblage_save; - cxxPPassemblage *cvode_pp_assemblage_save; - LDBLE *m_original; - LDBLE *m_temp; - int set_and_run_attempt; - - /* model.cpp ------------------------------- */ - LDBLE min_value; - LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; - int *inv_iu, *inv_is, *back_eq; - int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; - - /* phrq_io_output.cpp ------------------------------- */ - int forward_output_to_log; - - /* phreeqc_files.cpp ------------------------------- */ - char *default_data_base; -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; -#endif - - /* Pitzer */ - int pitzer_model, sit_model, pitzer_pe; - int full_pitzer, always_full_pitzer, ICON, IC; - LDBLE COSMOT; - LDBLE AW; - LDBLE VP, DW0; - struct pitz_param **pitz_params; - int count_pitz_param, max_pitz_param; - struct pitz_param **sit_params; - int count_sit_param, max_sit_param; - int DW(LDBLE T); - LDBLE DC(LDBLE T); - struct theta_param **theta_params; - int count_theta_param, max_theta_param; - int use_etheta; - LDBLE OTEMP; - LDBLE A0; - struct species **spec, **cations, **anions, **neutrals; - int count_cations, count_anions, count_neutrals; - int MAXCATIONS, FIRSTANION, MAXNEUTRAL; - struct pitz_param *mcb0, *mcb1, *mcc0; - int *IPRSNT; - LDBLE *M, *LGAMMA; - LDBLE BK[23], DK[23]; - -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif - LDBLE dummy; - - /* print.cpp ------------------------------- */ -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif - - /* read.cpp */ - char *prev_next_char; -#if defined PHREEQ98 - int shifts_as_points; -#endif - - /* read_class.cxx */ - dumper dump_info; - StorageBinList delete_info; - runner run_info; - char * sformatf_buffer; - size_t sformatf_buffer_size; - - /* readtr.cpp */ - std::string dump_file_name_cpp; - - /* sit.cpp ------------------------------- */ - LDBLE sit_A0; - int sit_count_cations, sit_count_anions, sit_count_neutrals; - int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; - int *sit_IPRSNT; - LDBLE *sit_M, *sit_LGAMMA; - - /* tidy.cpp ------------------------------- */ - LDBLE a0, a1, kc, kb; - - /* tally.cpp ------------------------------- */ - struct tally_buffer *t_buffer; - int tally_count_component; - struct tally *tally_table; - int count_tally_table_columns; - int count_tally_table_rows; - - /* transport.cpp ------------------------------- */ - struct sol_D *sol_D; - struct sol_D *sol_D_dbg; - struct J_ij *J_ij, *J_ij_il; - int J_ij_count_spec; - - struct M_S *m_s; - int count_m_s; - LDBLE tot1_h, tot1_o, tot2_h, tot2_o; - LDBLE diffc_max, diffc_tr, J_ij_sum; - int transp_surf; - LDBLE *heat_mix_array; - LDBLE *temp1, *temp2; - int nmix, heat_nmix; - LDBLE heat_mix_f_imm, heat_mix_f_m; - int warn_MCD_X, warn_fixed_Surf; - -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif - - friend class PBasic; - friend class ChartObject; - friend class IPhreeqc; - friend class TestIPhreeqc; - friend class TestSelectedOutput; - - std::vector keycount; // used to mark keywords that have been read - -#endif /* _INC_PHREEQC_H */ -#ifndef _INC_ISFINITE_H -#define _INC_ISFINITE_H - /********************************* - isfinite handling - (Note: Should NOT be guarded) - **********************************/ - -#if defined (PHREEQ98) || defined (_MSC_VER) -# define HAVE_FINITE -# define finite _finite -#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ -# if defined(DJGPP) -# define HAVE_FINITE -# endif -#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ - -#if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) -#elif defined(HAVE_FINITE) -# define PHR_ISFINITE(x) finite(x) -#elif defined(HAVE_ISNAN) -# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) -#else -# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) -#endif - -public: - static const struct const_iso iso_defaults[]; - static const int count_iso_defaults; -}; -#endif From 96294247acb6af414af97902ccab3d7776ede47f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 22:24:25 +0000 Subject: [PATCH 0447/1077] trying to fix loss of history with Phreeqc.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6327 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 58 +- Phreeqc.h | 1865 +++++++++++++++++++++++++++++++++++ phreeqc/global_structures.h | 7 - 3 files changed, 1907 insertions(+), 23 deletions(-) create mode 100644 Phreeqc.h diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 2f87ff1e..566567eb 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -15,21 +15,6 @@ #include "Temperature.h" #include "SSassemblage.h" -const struct const_iso Phreeqc::iso_defaults[] = { - {"13C", -10, 1}, - {"13C(4)", -10, 1}, - {"13C(-4)", -50, 5}, - {"34S", 10, 1}, - {"34S(6)", 10, 1}, - {"34S(-2)", -30, 5}, - {"2H", -28, 1}, - {"18O", -5, .1}, - {"87Sr", .71, .01}, - {"11B", 20, 5} -}; - -const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso)); - Phreeqc::Phreeqc(PHRQ_io *io) { if (io) @@ -58,8 +43,42 @@ Phreeqc::Phreeqc(PHRQ_io *io) sit_IPRSNT = NULL; sit_M = NULL; + struct const_iso + { + const char *name; + LDBLE value; + LDBLE uncertainty; + }; + + + struct const_iso temp_iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} + }; + int temp_count_iso_defaults = + (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); + + count_iso_defaults = temp_count_iso_defaults; + iso_defaults = new iso[count_iso_defaults]; + + int i; + for (i = 0; i < temp_count_iso_defaults; i++) + { + iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); + iso_defaults[i].value = temp_iso_defaults[i].value; + iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; + } + // counters for enum KEYWORDS - for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + for (i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) { keycount.push_back(0); } @@ -131,6 +150,13 @@ Phreeqc::~Phreeqc(void) this->phrq_io->close_ostreams(); } + int i; + for (i = 0; i < count_iso_defaults; i++) + { + iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); + } + delete[] iso_defaults; + free_check_null(default_data_base); free_check_null(sformatf_buffer); diff --git a/Phreeqc.h b/Phreeqc.h new file mode 100644 index 00000000..9079c9d3 --- /dev/null +++ b/Phreeqc.h @@ -0,0 +1,1865 @@ +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif +/* ---------------------------------------------------------------------- +* INCLUDE FILES +* ---------------------------------------------------------------------- */ +#include +#include +#include +#include +#ifdef HASH +#include +#endif +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "cvdense.h" +#include "runner.h" +#include "dumper.h" +#include "PHRQ_io.h" +#ifdef MULTICHART +#include "ChartHandler.h" +#endif +#include "Keywords.h" +#include "Pressure.h" +#include "cxxMix.h" +#include "Use.h" +#include "Surface.h" + +class cxxNameDouble; +class cxxKinetics; +//class cxxMix; +class cxxKineticsComp; +class cxxExchange; +class cxxExchComp; +class cxxGasPhase; +class cxxTemperature; +class cxxPPassemblage; +class cxxPPassemblageComp; +class cxxReaction; +class cxxSolution; +class cxxISolutionComp; +class cxxSolutionIsotope; +class cxxSSassemblage; +class cxxSS; +class cxxStorageBin; + +#include "global_structures.h" +class PBasic; + +class Phreeqc +{ +public: + Phreeqc(PHRQ_io *io = NULL); + ~Phreeqc(void); + +public: + // + // Phreeqc class methods + // + + // advection.cpp ------------------------------- + int advection(void); + + // basicsubs.cpp ------------------------------- + int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); + int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); + void basic_free(void); + + LDBLE activity(const char *species_name); + LDBLE activity_coefficient(const char *species_name); + LDBLE log_activity_coefficient(const char *species_name); + LDBLE calc_SC(void); + /* VP: Density Start */ + LDBLE calc_dens(void); + /* VP: Density End */ + LDBLE calc_logk_n(const char *name); + LDBLE calc_logk_p(const char *name); + LDBLE calc_logk_s(const char *name); + LDBLE calc_surface_charge(const char *surface_name); + LDBLE diff_layer_total(const char *total_name, const char *surface_name); + LDBLE equi_phase(const char *phase_name); + LDBLE find_gas_comp(const char *gas_comp_name); + LDBLE find_gas_p(void); + LDBLE find_gas_vm(void); + LDBLE find_misc1(const char *ss_name); + LDBLE find_misc2(const char *ss_name); + LDBLE find_ss_comp(const char *ss_comp_name); + LDBLE get_calculate_value(const char *name); + char * iso_unit(const char *total_name); + LDBLE iso_value(const char *total_name); + LDBLE kinetics_moles(const char *kinetics_name); + LDBLE log_activity(const char *species_name); + LDBLE log_molality(const char *species_name); + LDBLE molality(const char *species_name); + LDBLE pressure(void); + LDBLE pr_pressure(const char *phase_name); + LDBLE pr_phi(const char *phase_name); + LDBLE saturation_ratio(const char *phase_name); + int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); + LDBLE solution_sum_secondary(const char *total_name); + LDBLE sum_match_gases(const char *stemplate, const char *name); + LDBLE sum_match_species(const char *stemplate, const char *name); + LDBLE sum_match_ss(const char *stemplate, const char *name); + int match_elts_in_species(const char *name, const char *stemplate); + int extract_bracket(char **string, char *bracket_string); + LDBLE surf_total(const char *total_name, const char *surface_name); + static int system_species_compare(const void *ptr1, const void *ptr2); + LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); + std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); + LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); + int system_total_elements(void); + int system_total_si(void); + int system_total_aq(void); + int system_total_ex(void); + int system_total_surf(void); + int system_total_gas(void); + int system_total_ss(void); + int system_total_elt(const char *total_name); + int system_total_elt_secondary(const char *total_name); + LDBLE total(const char *total_name); + LDBLE total_mole(const char *total_name); + int system_total_solids(cxxExchange *exchange_ptr, + cxxPPassemblage *pp_assemblage_ptr, + cxxGasPhase *gas_phase_ptr, + cxxSSassemblage *ss_assemblage_ptr, + cxxSurface *surface_ptr); + + static LDBLE f_rho(LDBLE rho_old, void *cookie); + static LDBLE f_Vm(LDBLE v1, void *cookie); + // chart.cpp +#if defined PHREEQ98 + void DeleteCurves(void); + void ExtractCurveInfo(char *line, int curvenr); + void GridChar(char *s, char *a); + void MallocCurves(int nc, int ncxy); + int OpenCSVFile(char file_name[MAX_LENGTH]); + void SaveCurvesToFile(char file_name[MAX_LENGTH]); + void PlotXY(char *x, char *y); + void ReallocCurves(int new_nc); + void ReallocCurveXY(int i); + void SetAxisScale(char *a, int j, char *token, int true_); + void SetAxisTitles(char *s, int i); + void SetChartTitle(char *s); + void start_chart(bool end); +#endif + + // cl1.cpp ------------------------------- + int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); + void cl1_space(int check, int n2d, int klm, int nklmd); + + // cl1mp.cpp ------------------------------- + int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + + // class_main.cpp ------------------------------- + int write_banner(void); + + /* default.cpp */ +public: + int close_input_files(void); + int close_output_files(void); + static int istream_getc(void *cookie); + int process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log); + + /* PHRQ_io_output.cpp */ + void screen_msg(const char * str); + + void echo_msg(const char *err_str); + int warning_msg(const char *err_str); + void set_forward_output_to_log(int value); + int get_forward_output_to_log(void); + + // dump_ostream + bool dump_open(const char *file_name); + void dump_flush(void); + void dump_close(void); + void dump_msg(const char * str); + + // log_ostream + bool log_open(const char *file_name); + void log_flush(void); + void log_close(void); + void log_msg(const char * str); + + // error_ostream + bool error_open(const char *file_name); + void error_flush(void); + void error_close(void); + void error_msg(const char * str, bool stop=false); + + // output_ostream + bool output_open(const char *file_name); + void output_flush(void); + void output_close(void); + void output_msg(const char * str); + + // punch_ostream + bool punch_open(const char *file_name); + void punch_flush(void); + void punch_close(void); + void punch_msg(const char * str); + + void fpunchf_heading(const char *name); + void fpunchf(const char *name, const char *format, double d); + void fpunchf(const char *name, const char *format, char * d); + void fpunchf(const char *name, const char *format, int d); + void fpunchf_user(int user_index, const char *format, double d); + void fpunchf_user(int user_index, const char *format, char * d); + int fpunchf_end_row(const char *format); + + // dw.cpp ------------------------------- + int BB(LDBLE T); + LDBLE PS(LDBLE T); + LDBLE VLEST(LDBLE T); + int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); + int QQ(LDBLE T, LDBLE D); + LDBLE BASE(LDBLE D); + + // input.cpp ------------------------------- + int reading_database(void); + void set_reading_database(int reading_database); + int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + + // integrate.cpp ------------------------------- + int calc_all_g(void); + int calc_init_g(void); + int initial_surface_water(void); + int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); + int calc_all_donnan(void); + int calc_init_donnan(void); + LDBLE g_function(LDBLE x_value); + LDBLE midpnt(LDBLE x1, LDBLE x2, int n); + void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); + LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); + LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); + int calc_all_donnan_music(void); + int calc_init_donnan_music(void); + + // inverse.cpp ------------------------------- + int inverse_models(void); + int add_to_file(const char *filename, const char *string); + int bit_print(unsigned long bits, int l); + int carbon_derivs(struct inverse *inv_ptr); + int check_isotopes(struct inverse *inv_ptr); + int check_solns(struct inverse *inv_ptr); + int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); + cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); + LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); + int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); + int post_mortem(void); + bool test_cl1_solution(void); + unsigned long get_bits(unsigned long bits, int position, int number); + unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); + void dump_netpath(struct inverse *inv_ptr); + int dump_netpath_pat(struct inverse *inv_ptr); + int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); + int phase_isotope_inequalities(struct inverse *inv_ptr); + int print_model(struct inverse *inv_ptr); + int punch_model_heading(struct inverse *inv_ptr); + int punch_model(struct inverse *inv_ptr); + void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); + + void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); + int range(struct inverse *inv_ptr, unsigned long cur_bits); + int save_bad(unsigned long bits); + int save_good(unsigned long bits); + int save_minimal(unsigned long bits); + unsigned long set_bit(unsigned long bits, int position, int value); + int setup_inverse(struct inverse *inv_ptr); + int set_initial_solution(int n_user_old, int n_user_new); + int set_ph_c(struct inverse *inv_ptr, + int i, cxxSolution *soln_ptr_orig, int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); + int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); + int solve_inverse(struct inverse *inv_ptr); + int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); + int subset_bad(unsigned long bits); + int subset_minimal(unsigned long bits); + int superset_minimal(unsigned long bits); + int write_optimize_names(struct inverse *inv_ptr); + + // isotopes.cpp ------------------------------- + int add_isotopes(cxxSolution &solution_ptr); + int calculate_values(void); + int calculate_isotope_moles(struct element *elt_ptr, + cxxSolution *solution_ptr, LDBLE total_moles); + LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); + int from_pcil(struct master_isotope *master_isotope_ptr); + int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_tu(struct master_isotope *master_isotope_ptr); + struct calculate_value *calculate_value_alloc(void); + int calculate_value_free(struct calculate_value *calculate_value_ptr); + struct calculate_value *calculate_value_search(const char *name); + struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); + struct isotope_alpha *isotope_alpha_alloc(void); + struct isotope_alpha *isotope_alpha_search(const char *name); + struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); + struct isotope_ratio *isotope_ratio_alloc(void); + struct isotope_ratio *isotope_ratio_search(const char *name); + struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_alloc(void); + struct master_isotope *master_isotope_search(const char *name); + int print_initial_solution_isotopes(void); + int print_isotope_ratios(void); + int print_isotope_alphas(void); + int punch_isotopes(void); + int punch_calculate_values(void); + int read_calculate_values(void); + int read_isotopes(void); + int read_isotope_ratios(void); + int read_isotope_alphas(void); + int calculate_value_init(struct calculate_value *calculate_value_ptr); + int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); + int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); + int master_isotope_init(struct master_isotope *master_isotope_ptr); + + // kinetics.cpp ------------------------------- + void cvode_init(void); + int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); + int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_advection(int i, int use_mix, int use_kinetics, int nsaver); + int free_cvode(void); +public: + static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); + static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + + int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); + int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, + LDBLE time_step); + int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); + int set_reaction(int i, int use_mix, int use_kinetics); + int set_transport(int i, int use_mix, int use_kinetics, int nsaver); + int store_get_equi_reactants(int k, int kin_end); + int count_pp, count_pg, count_ss; + LDBLE *x0_moles; + + // mainsubs.cpp ------------------------------- + std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + int copy_entities(void); + void initialize(void); + int initial_exchangers(int print); + int initial_gas_phases(int print); + int initial_solutions(int print); + int step_save_exch(int n_user); + int step_save_surf(int n_user); + int initial_surfaces(int print); + int reactions(void); + int saver(void); + int xsolution_save(int k_user); + int xexchange_save(int n_user); + int xgas_save(int n_user); + int xpp_assemblage_save(int n_user); + int xss_assemblage_save(int n_user); + int xsurface_save(int n_user); + int do_initialize(void); + int do_status(void); + void save_init(int i); + int copy_use(int i); + int set_use(void); + + // model.cpp ------------------------------- + int check_residuals(void); + int free_model_allocs(void); + int ineq(int kode); + int model(void); + int jacobian_sums(void); + int mb_gases(void); + int mb_ss(void); + int mb_sums(void); + int molalities(int allow_overflow); + int reset(void); + int residuals(void); + int set(int initial); + int sum_species(void); + int surface_model(void); + LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); + LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); + LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); + int numerical_jacobian(void); + void set_inert_moles(void); + void unset_inert_moles(void); +#ifdef SLNQ + int add_trivial_eqns(int rows, int cols, LDBLE * matrix); + //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif + int calc_gas_pressures(void); + int calc_fixed_volume_gas_pressures(void); + int calc_ss_fractions(void); + int gammas(LDBLE mu); + int initial_guesses(void); + int revise_guesses(void); + int ss_binary(cxxSS *ss_ptr); + int ss_ideal(cxxSS *ss_ptr); + int gas_in; + void ineq_init(int max_row_count, int max_column_count); + + // parse.cpp ------------------------------- + int check_eqn(int association); + int get_charge(char *charge, LDBLE * z); + int get_elt(char **t_ptr, char *element, int *i); + int get_elts_in_species(char **t_ptr, LDBLE coef); + int get_num(char **t_ptr, LDBLE * num); + int get_secondary_in_species(char **t_ptr, LDBLE coef); + int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + int get_coef(LDBLE * coef, char **eqnaddr); + int get_secondary(char **t_ptr, char *element, int *i); + int get_species(char **ptr); + + // phqalloc.cpp ------------------------------- +public: +#if !defined(NDEBUG) + void *PHRQ_malloc(size_t, const char *, int); + void *PHRQ_calloc(size_t, size_t, const char *, int); + void *PHRQ_realloc(void *, size_t, const char *, int); +#else + void *PHRQ_malloc(size_t); + void *PHRQ_calloc(size_t, size_t); + void *PHRQ_realloc(void *, size_t); +#endif + void PHRQ_free(void *ptr); + void PHRQ_free_all(void); + +public: + + // pitzer.cpp ------------------------------- + struct pitz_param *pitz_param_read(char *string, int n); + int pitz_param_search(struct pitz_param *pzp_ptr); + int sit_param_search(struct pitz_param *pzp_ptr); + struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); + struct theta_param *theta_param_alloc(void); + int theta_param_init(struct theta_param *theta_param_ptr); + int gammas_pz(void); + int model_pz(void); + int pitzer(void); + int pitzer_clean_up(void); + int pitzer_init(void); + int pitzer_tidy(void); + int read_pitzer(void); + int set_pz(int initial); + int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_pz(void); + int ISPEC(const char *name); + LDBLE G(LDBLE Y); + LDBLE GP(LDBLE Y); + int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); + int BDK(LDBLE X); + int pitzer_initial_guesses(void); + int pitzer_revise_guesses(void); + int PTEMP(LDBLE TK); + LDBLE JAY(LDBLE X); + LDBLE JPRIME(LDBLE Y); + int jacobian_pz(void); + + // pitzer_structures.cpp ------------------------------- + struct pitz_param *pitz_param_alloc(void); + int pitz_param_init(struct pitz_param *pitz_param_ptr); + struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); + int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + + // prep.cpp ------------------------------- + int add_potential_factor(void); + int add_cd_music_factors(int n); + int add_surface_charge_balance(void); + int add_cd_music_charge_balances(int i); + int build_gas_phase(void); + int build_fixed_volume_gas(void); + int build_jacobian_sums(int k); + int build_mb_sums(void); + int build_min_exch(void); + int build_model(void); + int build_pure_phases(void); + int build_ss_assemblage(void); + int build_solution_phase_boundaries(void); + int build_species_list(int n); + int build_min_surface(void); + LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); + LDBLE calc_delta_v(reaction * r_ptr, bool phase); + LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(); + int calc_vm(LDBLE tc, LDBLE pa); + int change_hydrogen_in_elt_list(LDBLE charge); + int clear(void); + //int convert_units(struct solution *solution_ptr); + int convert_units(cxxSolution *solution_ptr); + LDBLE a_aa_sum, b2, b_sum, R_TK; + LDBLE f_Vm(LDBLE v1); + struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); + struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); + int inout(void); + int is_special(struct species *spec); + int mb_for_species_aq(int n); + int mb_for_species_ex(int n); + int mb_for_species_surf(int n); + int quick_setup(void); + int resetup_master(void); + int save_model(void); + int setup_exchange(void); + int setup_gas_phase(void); + int setup_fixed_volume_gas(void); + int setup_slack(void); + int setup_master_rxn(struct master **master_ptr_list, + const std::string &pe_rxn); + int setup_pure_phases(void); + int adjust_setup_pure_phases(void); + int setup_related_surface(void); + int setup_ss_assemblage(void); + int setup_solution(void); + int adjust_setup_solution(void); + int setup_surface(void); + int setup_unknowns(void); + int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); + int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); + int store_jacob0(int row, int column, LDBLE coef); + int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); + int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); + int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); + int tidy_redox(void); + struct master **unknown_alloc_master(void); + int write_mb_eqn_x(void); + int write_mb_for_species_list(int n); + int write_mass_action_eqn_x(int stop); + + int check_same_model(void); + int k_temp(LDBLE tc, LDBLE pa); + LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); + int prep(void); + int reprep(void); + int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); + int switch_bases(void); + int write_phase_sys_total(int n); + + // print.cpp ------------------------------- + char *sformatf(const char *format, ...); + int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); + int print_all(void); + int print_exchange(void); + int print_gas_phase(void); + int print_master_reactions(void); + int print_reaction(struct reaction *rxn_ptr); + int print_species(void); + int print_surface(void); + int print_user_print(void); + int punch_all(void); + int print_alkalinity(void); + int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); + int print_eh(void); + int print_reaction(void); + int print_kinetics(void); + int print_mix(void); + int print_pp_assemblage(void); + int print_ss_assemblage(void); + int print_saturation_indices(void); + int print_surface_cd_music(void); + int print_totals(void); + int print_using(void); + /*int print_user_print(void);*/ + int punch_gas_phase(void); + int punch_identifiers(void); + int punch_kinetics(void); + int punch_molalities(void); + int punch_activities(void); + int punch_pp_assemblage(void); + int punch_ss_assemblage(void); + int punch_saturation_indices(void); + int punch_totals(void); + int punch_user_punch(void); +#if defined MULTICHART + int punch_user_graph(void); +#endif + + // read.cpp ------------------------------- + int read_input(void); + int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); + int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); + int read_log_k_only(char *ptr, LDBLE * log_k); + int read_t_c_only(char *ptr, LDBLE *t_c); + int read_p_c_only(char *ptr, LDBLE * p_c); + int read_omega_only(char *ptr, LDBLE *omega); + int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description, int allow_negative=FALSE); + int check_key(const char *str); + int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, + const char *default_units, bool print); + int find_option(const char *item, int *n, const char **list, int count_list, + int exact); + int get_option(const char **opt_list, int count_opt_list, char **next_char); + int get_true_false(char *string, int default_value); + + int add_psi_master_species(char *token); + int read_advection(void); + int read_analytical_expression_only(char *ptr, LDBLE * log_k); + /* VP: Density Start */ + int read_millero_abcdef (char *ptr, LDBLE * abcdef); + /* VP: Density End */ + int read_copy(void); + int read_debug(void); + int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); + int read_vm_only(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); + int read_llnl_aqueous_model_parameters(void); + int read_exchange(void); + int read_exchange_master_species(void); + int read_exchange_species(void); + int read_gas_phase(void); + int read_incremental_reactions(void); + int read_inverse(void); + int read_inv_balances(struct inverse *inverse_ptr, char *next_char); + int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); + int read_inv_phases(struct inverse *inverse_ptr, char *next_char); + int read_kinetics(void); + int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); + LDBLE *read_list_doubles(char **ptr, int *count_doubles); + int *read_list_ints(char **ptr, int *count_ints, int positive); + int *read_list_t_f(char **ptr, int *count_ints); + int read_master_species(void); + int read_mix(void); + int read_named_logk(void); + int read_phases(void); + int read_print(void); + int read_pp_assemblage(void); + int read_rates(void); + int read_reaction(void); + int read_reaction_reactants(cxxReaction *reaction_ptr); + int read_reaction_steps(cxxReaction *reaction_ptr); + int read_solid_solutions(void); + int read_temperature(void); + int read_reaction_temps(struct temperature *temperature_ptr); + int read_reaction_pressure(void); + int read_reaction_pressure_raw(void); + int read_save(void); + int read_selected_output(void); + int read_solution(void); + int read_species(void); + int read_surface(void); + int read_surface_master_species(void); + int read_surface_species(void); + int read_use(void); + int read_title(void); + int read_user_print(void); + int read_user_punch(void); +#if defined PHREEQ98 + int read_user_graph(void); +#endif +#if defined MULTICHART + int read_user_graph_handler(); +#endif + int next_keyword_or_option(const char **opt_list, int count_opt_list); + int cleanup_after_parser(CParser &parser); + + // ReadClass.cxx + int read_dump(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); + + // readtr.cpp ------------------------------- + int read_transport(void); + int dump(void); + int dump_exchange(int k); + int dump_gas_phase(int k); + int dump_kinetics(int k); + int dump_mix(int k); + int dump_pp_assemblage(int k); + int dump_reaction(int k); + int dump_ss_assemblage(int k); + int dump_solution(int k); + int dump_surface(int k); + int dump_cpp(void); + int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + + // sit.cpp ------------------------------- + int gammas_sit(void); + int model_sit(void); + int sit(void); + int sit_clean_up(void); + int sit_init(void); + int sit_tidy(void); + int read_sit(void); + int set_sit(int initial); + int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_sit(void); + int sit_ISPEC(const char *name); + /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ + int sit_initial_guesses(void); + int sit_revise_guesses(void); + int PTEMP_SIT(LDBLE tk); + int jacobian_sit(void); + + // spread.cpp ------------------------------- + int read_solution_spread(void); + int copy_token_tab(char *token_ptr, char **ptr, int *length); + int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); + int spread_row_free(struct spread_row *spread_row_ptr); + int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); + struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI + void add_row(struct spread_row *spread_row_ptr); + void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); + void free_spread(void); + struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + + // step.cpp ------------------------------- + int step(LDBLE step_fraction); + int xsolution_zero(void); + int add_exchange(cxxExchange *exchange_ptr); + int add_gas_phase(cxxGasPhase *gas_phase_ptr); + int add_kinetics(cxxKinetics *kinetics_ptr); + int add_mix(cxxMix * mix_ptr); + int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); + int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); + int add_solution(cxxSolution *solution_ptr, LDBLE extensive, + LDBLE intensive); + int add_surface(cxxSurface *surface_ptr); + int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int gas_phase_check(cxxGasPhase *gas_phase_ptr); + int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); + int reaction_calc(cxxReaction *reaction_ptr); + int solution_check(void); + int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); + + // structures.cpp ------------------------------- + int clean_up(void); + int reinitialize(void); + int copier_add(struct copier *copier_ptr, int n_user, int start, int end); + int copier_free(struct copier *copier_ptr); + int copier_init(struct copier *copier_ptr); + static int element_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + static int elt_list_compare(const void *ptr1, const void *ptr2); +protected: + struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); + int elt_list_print(struct elt_list *elt_list_ptr); + struct elt_list *elt_list_save(void); + cxxNameDouble elt_list_NameDouble(void); +public: + enum entity_type get_entity_enum(char *name); + struct inverse *inverse_alloc(void); + int inverse_delete(int i); + static int inverse_isotope_compare(const void *ptr1, const void *ptr2); + struct inverse *inverse_search(int n_user, int *n); + int inverse_sort(void); +protected: + struct logk *logk_alloc(void); + int logk_copy2orig(struct logk *logk_ptr); + struct logk *logk_store(char *name, int replace_if_found); + struct logk *logk_search(const char *name); + struct master *master_alloc(void); + static int master_compare(const void *ptr1, const void *ptr2); + int master_delete(char *ptr); +public: + struct master *master_bsearch(const char *ptr); + struct master *master_bsearch_primary(const char *ptr); + struct master *master_bsearch_secondary(char *ptr); + struct master *master_search(char *ptr, int *n); + struct pe_data *pe_data_alloc(void); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +protected: + int pe_data_store(struct pe_data **pe, const char *token); +public: + struct phase *phase_bsearch(const char *ptr, int *j, int print); +protected: + static int phase_compare(const void *ptr1, const void *ptr2); + int phase_delete(int i); + struct phase *phase_store(const char *name); +public: + struct rate *rate_bsearch(char *ptr, int *j); + int rate_free(struct rate *rate_ptr); + struct rate *rate_search(const char *name, int *n); + int rate_sort(void); + struct reaction *rxn_alloc(int ntokens); + struct reaction *rxn_dup(struct reaction *rxn_ptr_old); + LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); + int rxn_free(struct reaction *rxn_ptr); + int rxn_print(struct reaction *rxn_ptr); + static int s_compare(const void *ptr1, const void *ptr2); + int s_delete(int i); + struct species *s_search(const char *name); + struct species *s_store(const char *name, LDBLE z, int replace_if_found); +protected: + struct save_values *save_values_bsearch(struct save_values *k, int *n); + static int save_values_compare(const void *ptr1, const void *ptr2); + int save_values_sort(void); + int save_values_store(struct save_values *s_v); + static int isotope_compare(const void *ptr1, const void *ptr2); + static int species_list_compare_alk(const void *ptr1, const void *ptr2); + static int species_list_compare_master(const void *ptr1, const void *ptr2); + int species_list_sort(void); + struct Change_Surf *change_surf_alloc(int count); +public: + struct master *surface_get_psi_master(const char *name, int plane); + int system_duplicate(int i, int save_old); + int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); + int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_combine(void); + int trxn_copy(struct reaction *rxn_ptr); + LDBLE trxn_find_coef(const char *str, int start); + int trxn_print(void); + int trxn_reverse_k(void); + int trxn_sort(void); + int trxn_swap(const char *token); + struct unknown *unknown_alloc(void); + int unknown_delete(int i); + int unknown_free(struct unknown *unknown_ptr); + int entity_exists(char *name, int n_user); + static int inverse_compare(const void *ptr1, const void *ptr2); + int inverse_free(struct inverse *inverse_ptr); + static int kinetics_compare_int(const void *ptr1, const void *ptr2); + int logk_init(struct logk *logk_ptr); + static int master_compare_string(const void *ptr1, const void *ptr2); + int master_free(struct master *master_ptr); + struct phase *phase_alloc(void); + static int phase_compare_string(const void *ptr1, const void *ptr2); + int phase_free(struct phase *phase_ptr); + int phase_init(struct phase *phase_ptr); + static int rate_compare(const void *ptr1, const void *ptr2); + static int rate_compare_string(const void *ptr1, const void *ptr2); + struct species *s_alloc(void); + int s_free(struct species *s_ptr); + int s_init(struct species *s_ptr); + static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int solution_compare(const void *ptr1, const void *ptr2); + static int solution_compare_int(const void *ptr1, const void *ptr2); + static int species_list_compare(const void *ptr1, const void *ptr2); + static int surface_compare_int(const void *ptr1, const void *ptr2); + static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); + int trxn_multiply(LDBLE coef); +#ifdef PHREEQCI_GUI + extern void free_spread(void); +#endif +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + extern void MergeFinalize(void); +#endif + struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); + struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); + struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); + struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + + void Use2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb); + + /* tally.cpp */ + void add_all_components_tally(void); + int build_tally_table(void); + int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); + int diff_tally_table(void); + int extend_tally_table(void); + int free_tally_table(void); + int fill_tally_table(int *n_user, int index_conservative, int n_buffer); + int get_tally_table_rows_columns(int *rows, int *columns); + int get_tally_table_column_heading(int column, int *type, char *string); + int get_tally_table_row_heading(int column, char *string); + int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); + int zero_tally_table(void); + int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); + int get_all_components(void); + int print_tally_table(void); + int set_reaction_moles(int n_user, LDBLE moles); + int set_reaction_temperature(int n_user, LDBLE tc); + int set_kinetics_time(int n_user, LDBLE step); + + // tidy.cpp ------------------------------- + int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); + int add_logks(struct logk *logk_ptr, int repeats); + LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); + int replace_solids_gases(void); + int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); + int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); + int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: + int tidy_punch(void); + int tidy_model(void); + int check_species_input(void); + LDBLE coef_in_master(struct master *master_ptr); + int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); + int reset_last_model(void); + int rewrite_eqn_to_primary(void); + int rewrite_eqn_to_secondary(void); + int species_rxn_to_trxn(struct species *s_ptr); + int tidy_logk(void); + int tidy_exchange(void); + int tidy_min_exchange(void); + int tidy_kin_exchange(void); + int tidy_gas_phase(void); + int tidy_inverse(void); + int tidy_isotopes(void); + int tidy_isotope_ratios(void); + int tidy_isotope_alphas(void); + int tidy_kin_surface(void); + int tidy_master_isotope(void); + int tidy_min_surface(void); + int tidy_phases(void); + int tidy_pp_assemblage(void); + int tidy_solutions(void); + int tidy_ss_assemblage(void); + int tidy_species(void); + int tidy_surface(void); + int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); + static LDBLE f_spinodal(LDBLE x, void *); + int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); + int ss_calc_a0_a1(cxxSS *ss_ptr); + + // transport.cpp ------------------------------- + int transport(void); + int set_initial_moles(int i); + cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, + cxxSurface *source2, std::string charge_name, LDBLE f2, + LDBLE new_Dw); + int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, + LDBLE new_Dw, int cell); + LDBLE viscosity(void); + int multi_D(LDBLE DDt, int mobile_cell, int stagnant); + int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); + int fill_spec(int cell_no); + int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); + static int sort_species_name(const void *ptr1, const void *ptr2); + int disp_surf(LDBLE stagkin_time); + int diff_stag_surf(int mobile_cell); + int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); + cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, + int n_user_new, + bool move_old); + int init_mix(void); + int init_heat_mix(int nmix); + int heat_mix(int heat_nmix); + int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + // utilities.cpp ------------------------------- +public: + int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list(const cxxNameDouble & nd, LDBLE coef); +protected: + int backspace_screen(int spaces); + LDBLE calc_alk(struct reaction *rxn_ptr); +public: + LDBLE calc_rho_0(LDBLE tc, LDBLE pa); + LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); + int compute_gfw(const char *string, LDBLE * gfw); +#if defined PHREEQ98 + int copy_title(char *token_ptr, char **ptr, int *length); +#endif + int copy_token(char *token_ptr, char **ptr, int *length); + int copy_token(std::string &token, char **ptr); + int dup_print(const char *ptr, int emphasis); + int equal(LDBLE a, LDBLE b, LDBLE eps); +public: + void *free_check_null(void *ptr); +protected: + void free_hash_strings(HashTable * Table); + int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); + int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); + void hdestroy_multi(HashTable * HashTable_ptr); + ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); + int islegit(const char c); +public: + void malloc_error(void); +protected: + int parse_couple(char *token); + int print_centered(const char *string); +public: + static int replace(const char *str1, const char *str2, char *str); + static bool replace(const char *str1, const char *str2, std::string & str); +protected: + void space(void **ptr, int i, int *max, int struct_size); + void squeeze_white(char *s_l); + int status(int count, const char *str, bool kinetics = false); + void str_tolower(char *str); + void str_toupper(char *str); + static int strcmp_nocase(const char *str1, const char *str2); + int strcmp_nocase_arg1(const char *str1, const char *str2); +public: + char *string_duplicate(const char *token); + const char *string_hsave(const char *str); + void strings_map_clear(); +#ifdef HASH + void strings_hash_clear(); +#endif +protected: + char *string_pad(const char *str, int i); + int string_trim(char *str); + int string_trim_right(char *str); + int string_trim_left(char *str); + static LDBLE under(LDBLE xval); + void zero_double(LDBLE * target, int n); + int get_input_errors(void); +#ifdef PHREEQ98 + void AddToCEntry(char *a, int l, int i); + void ApplicationProcessMessages(void); + int copy_title(char *token_ptr, char **ptr, int *length); + extern int clean_up_null(void); +#endif + int isamong(char c, const char *s_l); + Address Hash_multi(HashTable * Table, const char *Key); + void ExpandTable_multi(HashTable * Table); +public: + int main_method(int argc, char *argv[]); + void set_phast(int); + size_t list_components(std::list &list_c); + PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} +protected: + void init(void); + + // + //Data members + // +protected: + PHRQ_io *phrq_io; + PHRQ_io ioInstance; + + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ + + struct model last_model; + int same_model; + int same_temperature; + int same_pressure; + bool same_mu; + struct punch punch; + /* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ + + std::map Rxn_temperature_map; + + /* ---------------------------------------------------------------------- + * Pressures + * ---------------------------------------------------------------------- */ + std::map Rxn_pressure_map; + + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + + int g_iterations; + LDBLE G_TOL; + std::map Rxn_surface_map; + std::map charge_group_map; + int change_surf_count; + struct Change_Surf *change_surf; + + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + std::map Rxn_exchange_map; + + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + std::map Rxn_kinetics_map; + + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + int count_save_values; + struct save_values *save_values; + struct save save; + + /*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ + cxxUse use; + + /*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_ss_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_reaction; + struct copier copy_temperature; + struct copier copy_pressure; + + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + struct inverse *inverse; + int count_inverse; + + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + std::map Rxn_mix_map; + std::map Dispersion_mix_map; + + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + std::map Rxn_reaction_map; + + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + std::map Rxn_gas_phase_map; + + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + std::map Rxn_ss_assemblage_map; + + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + std::map Rxn_pp_assemblage_map; + + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + int count_species_list; + int max_species_list; + struct species_list *species_list; + + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + std::map Rxn_solution_map; + std::vector unnumbered_solutions; + struct iso *iso_defaults; + int count_iso_defaults; + + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE patm_x; + bool numerical_fixed_volume; + bool force_numerical_fixed_volume; + bool switch_numerical; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + std::map < std::string, cxxChemRxn > pe_x; + std::map isotopes_x; + std::string default_pe_x; + cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; + + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ + + int cell_no; + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; + + /*---------------------------------------------------------------------- + * Tidy data + *---------------------------------------------------------------------- */ + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, + new_pitzer; + + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; + + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; + /*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ + + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + + struct logk **logk; + int count_logk; + int max_logk; + + char *moles_per_kilogram_string; + char *pe_string; + + struct species **s; + int count_s; + int max_s; + std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; + + struct species **s_x; + int count_s_x; + int max_s_x; + + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; + + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + struct phase **phases; + int count_phases; + int max_phases; + + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; + + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + + struct unknown **x; + int count_unknowns; + int max_unknowns; + + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *slack_unknown; + struct unknown *ss_unknown; + std::vector gas_unknowns; + + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; + + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; + + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + struct prints pr; + bool status_on; + clock_t status_interval; + clock_t status_timer; + int count_warnings; + + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + std::vector rate_p; + int count_rate_p; + + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + const char **user_punch_headings; + int user_punch_count_headings; + int n_user_punch_index; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + ChartHandler chart_handler; +#endif + + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + const char * error_string; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; + + int count_strings; + int max_strings; + + LDBLE *array; + LDBLE *delta; + LDBLE *residual; + + int input_error; + + Keywords::KEYWORDS next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; + + int max_line; + char *line; + char *line_save; + + LDBLE LOG_10; + + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; + + LDBLE inv_tol_default; + int itmax; + int max_tries; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + bool dampen_ah2o; + bool slack; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; + + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; + + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; + std::string screen_string; +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ + + std::map strings_map; +#ifdef HASH + std::hash_map strings_hash; +#endif + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + struct name_coef match_tokens[50]; + int count_match_tokens; + int count_master_isotope; + struct master_isotope **master_isotope; + int max_master_isotope; + int initial_solution_isotopes; + int count_calculate_value; + struct calculate_value **calculate_value; + int max_calculate_value; + HashTable *calculate_value_hash_table; + int count_isotope_ratio; + struct isotope_ratio **isotope_ratio; + int max_isotope_ratio; + HashTable *isotope_ratio_hash_table; + int count_isotope_alpha; + struct isotope_alpha **isotope_alpha; + int max_isotope_alpha; + HashTable *isotope_alpha_hash_table; + int phreeqc_mpi_myself; + int first_read_input; + char *user_database; + + int have_punch_name; + /* VP: Density Start */ + int print_density; + /* VP: Density End */ + + LDBLE *zeros; + int zeros_max; + + LDBLE cell_pore_volume; + LDBLE cell_porosity; + LDBLE cell_volume; + LDBLE cell_saturation; + struct system_species *sys; + int count_sys, max_sys; + LDBLE sys_tot; +#ifdef PHREEQC2 + LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE eps_r; // relative dielectric permittivity +#else + LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; + LDBLE eps_r; // relative dielectric permittivity + LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av +#endif + LDBLE solution_mass, solution_volume; + LDBLE f_rho(LDBLE rho_old); + + /* phqalloc.cpp ------------------------------- */ + PHRQMemHeader *s_pTail; + std::stringstream merged_database_stream; + std::stringstream merged_input_stream; + + /* Basic */ + PBasic * basic_interpreter; + + /* cl1.cpp ------------------------------- */ + LDBLE *x_arg, *res_arg, *scratch; + int x_arg_max, res_arg_max, scratch_max; + + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + LDBLE Q0, Q5; + LDBLE GASCON, TZ, AA; + LDBLE Z, DZ, Y; + LDBLE G1, G2, GF; + LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + + /* input.cpp ------------------------------- */ + int add_char_to_line(int *i, char c); + int check_line_impl(const char *string, int allow_empty, + int allow_eof, int allow_keyword, int print); + int get_line(void); + int get_logical_line(void *cookie, int *l); + int read_database(void); + int run_simulations(void); + int check_line_return; + int reading_db; + + /* integrate.cpp ------------------------------- */ + LDBLE midpoint_sv; + LDBLE z_global, xd_global, alpha_global; + int max_row_count, max_column_count; + int carbon; + const char **col_name, **row_name; + int count_rows, count_optimize; + int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; + int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; + LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; + LDBLE *min_delta, *max_delta; + int *iu, *is; + int klmd, nklmd, n2d, kode, iter; + LDBLE toler, error, max_pct, scaled_error; + struct master *master_alk; + int *row_back, *col_back; + unsigned long *good, *bad, *minimal; + int max_good, max_bad, max_minimal; + int count_good, count_bad, count_minimal, count_calls; + unsigned long soln_bits, phase_bits, current_bits, temp_bits; + + /* inverse.cpp ------------------------------- */ + FILE *netpath_file; + int count_inverse_models, count_pat_solutions; + int min_position[32], max_position[32], now[32]; + + /* kinetics.cpp ------------------------------- */ +public: + void *cvode_kinetics_ptr; + int cvode_test; + int cvode_error; + int cvode_n_user; + int cvode_n_reactions; + realtype cvode_step_fraction; + realtype cvode_rate_sim_time; + realtype cvode_rate_sim_time_start; + realtype cvode_last_good_time; + realtype cvode_prev_good_time; + N_Vector cvode_last_good_y; + N_Vector cvode_prev_good_y; + M_Env kinetics_machEnv; + N_Vector kinetics_y, kinetics_abstol; + void *kinetics_cvode_mem; + cxxSSassemblage *cvode_ss_assemblage_save; + cxxPPassemblage *cvode_pp_assemblage_save; + LDBLE *m_original; + LDBLE *m_temp; + int set_and_run_attempt; + + /* model.cpp ------------------------------- */ + LDBLE min_value; + LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; + int *inv_iu, *inv_is, *back_eq; + int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; + + /* phrq_io_output.cpp ------------------------------- */ + int forward_output_to_log; + + /* phreeqc_files.cpp ------------------------------- */ + char *default_data_base; +#ifdef PHREEQ98 + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; +#endif + + /* Pitzer */ + int pitzer_model, sit_model, pitzer_pe; + int full_pitzer, always_full_pitzer, ICON, IC; + LDBLE COSMOT; + LDBLE AW; + LDBLE VP, DW0; + struct pitz_param **pitz_params; + int count_pitz_param, max_pitz_param; + struct pitz_param **sit_params; + int count_sit_param, max_sit_param; + int DW(LDBLE T); + LDBLE DC(LDBLE T); + struct theta_param **theta_params; + int count_theta_param, max_theta_param; + int use_etheta; + LDBLE OTEMP; + LDBLE A0; + struct species **spec, **cations, **anions, **neutrals; + int count_cations, count_anions, count_neutrals; + int MAXCATIONS, FIRSTANION, MAXNEUTRAL; + struct pitz_param *mcb0, *mcb1, *mcc0; + int *IPRSNT; + LDBLE *M, *LGAMMA; + LDBLE BK[23], DK[23]; + +#ifdef PHREEQ98 + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; +#endif + LDBLE dummy; + + /* print.cpp ------------------------------- */ +#ifdef PHREEQ98 + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; +#endif + + /* read.cpp */ + char *prev_next_char; +#if defined PHREEQ98 + int shifts_as_points; +#endif + + /* read_class.cxx */ + dumper dump_info; + StorageBinList delete_info; + runner run_info; + char * sformatf_buffer; + size_t sformatf_buffer_size; + + /* readtr.cpp */ + std::string dump_file_name_cpp; + + /* sit.cpp ------------------------------- */ + LDBLE sit_A0; + int sit_count_cations, sit_count_anions, sit_count_neutrals; + int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; + int *sit_IPRSNT; + LDBLE *sit_M, *sit_LGAMMA; + + /* tidy.cpp ------------------------------- */ + LDBLE a0, a1, kc, kb; + + /* tally.cpp ------------------------------- */ + struct tally_buffer *t_buffer; + int tally_count_component; + struct tally *tally_table; + int count_tally_table_columns; + int count_tally_table_rows; + + /* transport.cpp ------------------------------- */ + struct sol_D *sol_D; + struct sol_D *sol_D_dbg; + struct J_ij *J_ij, *J_ij_il; + int J_ij_count_spec; + + struct M_S *m_s; + int count_m_s; + LDBLE tot1_h, tot1_o, tot2_h, tot2_o; + LDBLE diffc_max, diffc_tr, J_ij_sum; + int transp_surf; + LDBLE *heat_mix_array; + LDBLE *temp1, *temp2; + int nmix, heat_nmix; + LDBLE heat_mix_f_imm, heat_mix_f_m; + int warn_MCD_X, warn_fixed_Surf; + +#ifdef PHREEQ98 + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; +#endif + + friend class PBasic; + friend class ChartObject; + friend class IPhreeqc; + friend class TestIPhreeqc; + friend class TestSelectedOutput; + + std::vector keycount; // used to mark keywords that have been read + +#endif /* _INC_PHREEQC_H */ +#ifndef _INC_ISFINITE_H +#define _INC_ISFINITE_H + /********************************* + isfinite handling + (Note: Should NOT be guarded) + **********************************/ + +#if defined (PHREEQ98) || defined (_MSC_VER) +# define HAVE_FINITE +# define finite _finite +#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ +# if defined(DJGPP) +# define HAVE_FINITE +# endif +#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ + +#if defined(HAVE_ISFINITE) +# define PHR_ISFINITE(x) isfinite(x) +#elif defined(HAVE_FINITE) +# define PHR_ISFINITE(x) finite(x) +#elif defined(HAVE_ISNAN) +# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) +#else +# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) +#endif + +}; +#endif diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index 9e776e85..e90a7af9 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -1075,12 +1075,5 @@ struct theta_param LDBLE ethetap; }; -struct const_iso -{ - const char *name; - LDBLE value; - LDBLE uncertainty; -}; - #endif /* _INC_GLOBAL_STRUCTURES_H */ From 69711a425a0b0b74dd755b299c65356c35ab066f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 22:36:01 +0000 Subject: [PATCH 0448/1077] made iso_defaults public and static This is really just 6324 without deleting Phreeqc.h and keeping the history. In order to keep the history you need to do a reverse merge. see http://stackoverflow.com/questions/2863028/recover-a-folder-or-file-in-tortoisesvn-whilst-also-retaining-all-history answer attached: Do a "reverse merge": 1.Ensure that your working copy is updated to HEAD and completely clean (not strictly necessary, but always a good idea before trying to merge) 2.Right click on the folder and select TortoiseSVN > Merge... 3.Select "Merge a range of revisions" and hit "Next" 4.The URL to merge from is the repo path for your current directory (ie. the one containing the deleted file) 5.The revision range to merge is the revision in which you deleted the file (show log might help here) 6.Be sure to select "Reverse merge" 7.Hit "Next" 8.All the default merge options should be sufficient, so hit "Merge" The file should now be added and still retain all of its previous history. Explanation: This "rolls back" the revision containing the deletion, but adds the merge information to the directory properties. SVN can track the original file through this metadata. On the command line you would to do a backwards merge of the revision in which you deleted it: svn merge -c - path/containing/file Note the hyphen before the rev number (ie. a "negative" revision nunber). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6328 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 58 ++++++++++--------------------------- Phreeqc.h | 12 ++++---- phreeqc/global_structures.h | 7 +++++ 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 566567eb..2f87ff1e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -15,6 +15,21 @@ #include "Temperature.h" #include "SSassemblage.h" +const struct const_iso Phreeqc::iso_defaults[] = { + {"13C", -10, 1}, + {"13C(4)", -10, 1}, + {"13C(-4)", -50, 5}, + {"34S", 10, 1}, + {"34S(6)", 10, 1}, + {"34S(-2)", -30, 5}, + {"2H", -28, 1}, + {"18O", -5, .1}, + {"87Sr", .71, .01}, + {"11B", 20, 5} +}; + +const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso)); + Phreeqc::Phreeqc(PHRQ_io *io) { if (io) @@ -43,42 +58,8 @@ Phreeqc::Phreeqc(PHRQ_io *io) sit_IPRSNT = NULL; sit_M = NULL; - struct const_iso - { - const char *name; - LDBLE value; - LDBLE uncertainty; - }; - - - struct const_iso temp_iso_defaults[] = { - {"13C", -10, 1}, - {"13C(4)", -10, 1}, - {"13C(-4)", -50, 5}, - {"34S", 10, 1}, - {"34S(6)", 10, 1}, - {"34S(-2)", -30, 5}, - {"2H", -28, 1}, - {"18O", -5, .1}, - {"87Sr", .71, .01}, - {"11B", 20, 5} - }; - int temp_count_iso_defaults = - (sizeof(temp_iso_defaults) / sizeof(struct const_iso)); - - count_iso_defaults = temp_count_iso_defaults; - iso_defaults = new iso[count_iso_defaults]; - - int i; - for (i = 0; i < temp_count_iso_defaults; i++) - { - iso_defaults[i].name = string_duplicate(temp_iso_defaults[i].name); - iso_defaults[i].value = temp_iso_defaults[i].value; - iso_defaults[i].uncertainty = temp_iso_defaults[i].uncertainty; - } - // counters for enum KEYWORDS - for (i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) { keycount.push_back(0); } @@ -150,13 +131,6 @@ Phreeqc::~Phreeqc(void) this->phrq_io->close_ostreams(); } - int i; - for (i = 0; i < count_iso_defaults; i++) - { - iso_defaults[i].name = (char *) free_check_null((void *) iso_defaults[i].name); - } - delete[] iso_defaults; - free_check_null(default_data_base); free_check_null(sformatf_buffer); diff --git a/Phreeqc.h b/Phreeqc.h index 9079c9d3..96d08488 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -910,9 +910,6 @@ public: static int surface_compare_int(const void *ptr1, const void *ptr2); static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); -#ifdef PHREEQCI_GUI - extern void free_spread(void); -#endif #if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) extern void MergeFinalize(void); #endif @@ -1052,14 +1049,14 @@ protected: public: static int replace(const char *str1, const char *str2, char *str); static bool replace(const char *str1, const char *str2, std::string & str); + static int strcmp_nocase(const char *str1, const char *str2); + static int strcmp_nocase_arg1(const char *str1, const char *str2); protected: void space(void **ptr, int i, int *max, int struct_size); void squeeze_white(char *s_l); int status(int count, const char *str, bool kinetics = false); void str_tolower(char *str); void str_toupper(char *str); - static int strcmp_nocase(const char *str1, const char *str2); - int strcmp_nocase_arg1(const char *str1, const char *str2); public: char *string_duplicate(const char *token); const char *string_hsave(const char *str); @@ -1241,8 +1238,6 @@ protected: *---------------------------------------------------------------------- */ std::map Rxn_solution_map; std::vector unnumbered_solutions; - struct iso *iso_defaults; - int count_iso_defaults; /*---------------------------------------------------------------------- * Global solution @@ -1861,5 +1856,8 @@ public: # define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) #endif +public: + static const struct const_iso iso_defaults[]; + static const int count_iso_defaults; }; #endif diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index e90a7af9..9e776e85 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -1075,5 +1075,12 @@ struct theta_param LDBLE ethetap; }; +struct const_iso +{ + const char *name; + LDBLE value; + LDBLE uncertainty; +}; + #endif /* _INC_GLOBAL_STRUCTURES_H */ From 7c3f0b5baf355b16a91c0856bed146c74e3bddfc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Mar 2012 23:44:01 +0000 Subject: [PATCH 0449/1077] changed implementation of trim_left trim_right and trim. see http://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring Note: some previous uses of trim were erroneous (see tokiso_unit) since it had to be used like this: s = trim(s); can now be used like trim(s) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6330 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 33 +++++++++++++++++---------------- dumper.cpp | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Parser.h b/Parser.h index 7c062220..a32b1b0b 100644 --- a/Parser.h +++ b/Parser.h @@ -10,6 +10,10 @@ #include // std::istringstream std::ostringstream #include // std::ostream #include // std::istream +#include // std::isspace +#include // std::find_if +#include // std::ptr_fun std::not1 + #include "PHRQ_base.h" #include "Keywords.h" #include "PHRQ_io.h" @@ -269,22 +273,19 @@ class CParser: public PHRQ_base }; // Global functions -inline std::string trim_right(const std::string &source , const std::string& t = " \t") -{ - std::string str = source; - return str.erase( str.find_last_not_of(t) + 1); -} - -inline std::string trim_left( const std::string& source, const std::string& t = " \t") -{ - std::string str = source; - return str.erase(0 , source.find_first_not_of(t) ); -} - -inline std::string trim(const std::string& source, const std::string& t = " \t") -{ - std::string str = source; - return trim_left( trim_right( str , t) , t ); +static inline std::string &trim_left(std::string &s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + return s; +} +static inline std::string &trim_right(std::string &s) +{ + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + return s; +} +static inline std::string &trim(std::string &s) +{ + return trim_left(trim_right(s)); } #endif // PARSER_H_INCLUDED diff --git a/dumper.cpp b/dumper.cpp index 723a02f8..51936c67 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -216,7 +216,7 @@ bool dumper::Read(CParser & parser) break; case 0: //file std::getline(parser.get_iss(), this->file_name); - this->file_name = trim(this->file_name, " \t"); + trim(this->file_name); if (this->file_name.size() == 0) { this->file_name = "dump.out"; From 33eabd03e37c704a86ef8e76afbb49d55de723cb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 31 Mar 2012 01:27:31 +0000 Subject: [PATCH 0450/1077] SOLUTION_SPREAD git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6331 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/mainsubs.cpp | 19 +++++++++++++------ phreeqc/spread.cpp | 25 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 768ea13f..cd3d6107 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -461,14 +461,16 @@ initialize(void) dump_file_name = NULL; #ifdef PHREEQCI_GUI - g_spread_sheet.heading = NULL; - g_spread_sheet.units = NULL; - g_spread_sheet.count_rows = 0; - g_spread_sheet.rows = NULL; - g_spread_sheet.defaults.units = NULL; + g_spread_sheet.heading = NULL; + g_spread_sheet.units = NULL; + g_spread_sheet.count_rows = 0; + g_spread_sheet.rows = NULL; + g_spread_sheet.defaults.units = NULL; g_spread_sheet.defaults.count_iso = 0; - g_spread_sheet.defaults.iso = NULL; + g_spread_sheet.defaults.iso = NULL; + g_spread_sheet.defaults.redox = NULL; #endif + /* calculate_value */ max_calculate_value = MAX_ELTS; count_calculate_value = 0; @@ -2590,6 +2592,11 @@ run_simulations(void) #if defined PHREEQ98 AddSeries = !connect_simulations; #endif + +#if defined PHREEQCI_GUI + sprintf(token, "\nSimulation %d\n", simulation); + screen_msg(token); +#endif sprintf(token, "Reading input data for simulation %d.", simulation); dup_print(token, TRUE); diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 99831892..8c09a4cb 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -69,6 +69,11 @@ read_solution_spread(void) soln_defaults.water = 1.0; soln_defaults.pressure = 1.0; +#ifdef PHREEQCI_GUI + free_spread(); +#endif + + /* fill in soln_defaults.iso */ soln_defaults.count_iso = count_iso_defaults; soln_defaults.iso = (struct iso *) PHRQ_malloc((size_t) soln_defaults.count_iso * @@ -466,9 +471,15 @@ read_solution_spread(void) } #ifdef PHREEQCI_GUI if (heading) + { + assert(g_spread_sheet.heading == NULL); g_spread_sheet.heading = copy_row(heading); + } if (units) + { + assert(g_spread_sheet.units == NULL); g_spread_sheet.units = copy_row(units); + } copy_defaults(&g_spread_sheet.defaults, &soln_defaults); #endif spread_row_free(heading); @@ -1206,20 +1217,24 @@ free_spread(void) { spread_row_free(g_spread_sheet.rows[i]); } - g_spread_sheet.rows = free_check_null(g_spread_sheet.rows); + g_spread_sheet.rows = (spread_row**)free_check_null(g_spread_sheet.rows); for (i = 0; i < g_spread_sheet.defaults.count_iso; i++) { g_spread_sheet.defaults.iso[i].name = - free_check_null(g_spread_sheet.defaults.iso[i].name); + (const char *)free_check_null((void*)g_spread_sheet.defaults.iso[i].name); } g_spread_sheet.defaults.iso = - free_check_null(g_spread_sheet.defaults.iso); + (struct iso*)free_check_null(g_spread_sheet.defaults.iso); g_spread_sheet.defaults.redox = - free_check_null(g_spread_sheet.defaults.redox); + (const char *)free_check_null((void*)g_spread_sheet.defaults.redox); g_spread_sheet.defaults.units = - free_check_null(g_spread_sheet.defaults.units); + (const char *)free_check_null((void*)g_spread_sheet.defaults.units); + + g_spread_sheet.heading = 0; + g_spread_sheet.count_rows = 0; + g_spread_sheet.defaults.count_iso = 0; } /* ---------------------------------------------------------------------- */ From 0574952b9caa792339e03935736c88689d672095 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:03:10 +0000 Subject: [PATCH 0451/1077] added const version of Get_temps git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6348 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Temperature.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Temperature.h b/Temperature.h index 96acf6e3..2d6c0733 100644 --- a/Temperature.h +++ b/Temperature.h @@ -24,6 +24,7 @@ class cxxTemperature:public cxxNumKeyword int read(CParser & parser); LDBLE Temperature_for_step(int step_number); std::vector & Get_temps(void) {return temps;} + const std::vector & Get_temps(void)const {return temps;} int Get_countTemps(void) const; void Set_countTemps(int i) {countTemps = i;} bool Get_equalIncrements(void) const {return equalIncrements;} From 02460252f7998ac93ed0840b9c6088e642d76442 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:03:43 +0000 Subject: [PATCH 0452/1077] added const version of Get_SSs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6349 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SSassemblage.h | 1 + 1 file changed, 1 insertion(+) diff --git a/SSassemblage.h b/SSassemblage.h index 1838f7fb..5d6a6632 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -41,6 +41,7 @@ public: const cxxNameDouble & Get_totals() const {return this->totals;} std::map < std::string, cxxSS > & Get_SSs(void) {return SSs;} + const std::map < std::string, cxxSS > & Get_SSs(void)const {return SSs;} void Set_SSs(std::map < std::string, cxxSS > & ss) {SSs = ss;} bool Get_new_def(void) const {return new_def;} void Set_new_def(bool tf) {new_def = tf;} From 82d4997468ce61a27996e6a5aff1f96d03a8e08b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:04:16 +0000 Subject: [PATCH 0453/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6350 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SS.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/SS.h b/SS.h index 3440f740..31b09de5 100644 --- a/SS.h +++ b/SS.h @@ -93,13 +93,15 @@ class cxxSS: public PHRQ_base LDBLE Get_xb2() const {return (this->xb2);} void Set_xb2(LDBLE t) {xb2 = t;} std::vector & Get_ss_comps(void) {return ss_comps;} + const std::vector & Get_ss_comps(void)const {return ss_comps;} void Set_ss_comps(const std::vector & comps) {ss_comps = comps;} - LDBLE Get_tk(void) {return this->tk;} + LDBLE Get_tk(void)const {return this->tk;} void Set_tk(LDBLE t) {this->tk = t;} - SS_PARAMETER_TYPE Get_input_case(void) {return this->input_case;} + SS_PARAMETER_TYPE Get_input_case(void)const {return this->input_case;} void Set_input_case(SS_PARAMETER_TYPE t) {this->input_case = t;} - std::vector & Get_p(void) {return this->p;} + std::vector & Get_p(void) {return this->p;} + const std::vector & Get_p(void)const {return this->p;} void Set_p(const std::vector & t) {this->p = t;} protected: std::string name; From d2577f8b46ad5c081ba469a274eb229c7d547659 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:04:52 +0000 Subject: [PATCH 0454/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6351 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Solution.h b/Solution.h index 4e34a6ed..32ffcf80 100644 --- a/Solution.h +++ b/Solution.h @@ -53,7 +53,8 @@ class cxxSolution:public cxxNumKeyword void Set_mass_water(LDBLE l_mass_water) {this->mass_water = l_mass_water;} LDBLE Get_total_alkalinity() const {return this->total_alkalinity;} void Set_total_alkalinity(LDBLE l_total_alkalinity) {this->total_alkalinity = l_total_alkalinity;} - cxxNameDouble & Get_totals(void) {return this->totals;} + cxxNameDouble & Get_totals(void) {return this->totals;} + const cxxNameDouble & Get_totals(void)const {return this->totals;} void Set_totals(cxxNameDouble & nd) { this->totals = nd; @@ -61,9 +62,11 @@ class cxxSolution:public cxxNumKeyword } cxxNameDouble & Get_master_activity(void) {return this->master_activity;} cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;} - std::map < std::string, cxxSolutionIsotope > & Get_isotopes(void) {return this->isotopes;} + 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;} cxxISolution *Get_initial_data() {return this->initial_data;} + const cxxISolution *Get_initial_data()const {return this->initial_data;} void Set_initial_data(const cxxISolution * id) { if (this->initial_data != NULL) From 7347290a286a2489d05b86eef4c6e754be02741e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:05:30 +0000 Subject: [PATCH 0455/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6352 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Reaction.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Reaction.h b/Reaction.h index ca404ebc..ea15340c 100644 --- a/Reaction.h +++ b/Reaction.h @@ -25,7 +25,9 @@ class cxxReaction:public cxxNumKeyword const cxxNameDouble &Get_elementList(void) const {return this->elementList;} void Set_elementList(cxxNameDouble nd) {this->elementList = nd;} cxxNameDouble &Get_reactantList(void) {return this->reactantList;} + const cxxNameDouble &Get_reactantList(void)const {return this->reactantList;} std::vector < LDBLE > &Get_steps(void) {return this->steps;} + const std::vector < LDBLE > &Get_steps(void)const {return this->steps;} void Set_steps(std::vector &v) {steps = v;} int Get_reaction_steps(void) const; int Get_countSteps(void) const {return this->countSteps;} From 8ea8082fa4912e09c6d07428ec294745255cb9b4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 00:07:42 +0000 Subject: [PATCH 0456/1077] added const version of Get_pp_assemblage_comps git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6353 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PPassemblage.h b/PPassemblage.h index 321184ca..053876b2 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -38,6 +38,10 @@ class cxxPPassemblage:public cxxNumKeyword { return this->pp_assemblage_comps; }; + const std::map & Get_pp_assemblage_comps() const + { + return this->pp_assemblage_comps; + }; void Set_pp_assemblage_comps(std::map & c) { this->pp_assemblage_comps = c; From 8e9a4e0c3e95984ccfc75638f635bb2d106c2e77 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 04:53:03 +0000 Subject: [PATCH 0457/1077] made istream_getc static; made some routines virtual; added virtual getc method; git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6355 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 38 ++++++++++++++++++-------------------- PHRQ_io.h | 16 ++++++++-------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 5561a7af..52ae2071 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -67,7 +67,7 @@ void PHRQ_io:: output_close(void) /* ---------------------------------------------------------------------- */ { - safe_close(&log_ostream); + safe_close(&output_ostream); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -449,11 +449,10 @@ dump_msg(const char * str) } } int PHRQ_io:: -istream_getc(void *cookie) //istream_getc is *** static *** +getc(void) { - if (cookie) + if (std::istream* is = get_istream()) { - std::istream* is = (std::istream*)cookie; int n = is->get(); if (n == 13 && is->peek() == 10) { @@ -654,15 +653,13 @@ get_line(void) int i; bool empty; std::string stdtoken; - void *cookie; bool continue_loop = true;; PHRQ_io::LINE_TYPE return_value; // loop for include files for (;;) { - cookie = this->get_istream(); - if (cookie == NULL) + if (this->get_istream() == NULL) { break; } @@ -679,7 +676,7 @@ get_line(void) */ continue_loop = false; - if (get_logical_line(cookie) == LT_EOF) + if (get_logical_line() == LT_EOF) { //pop next file this->pop_istream(); @@ -754,7 +751,12 @@ get_line(void) { std::ostringstream errstr; errstr << "Could not open include file " << file_name; +#if defined(PHREEQCI_GUI) + warning_msg(errstr.str().c_str()); + continue; +#else error_msg(errstr.str().c_str(), OT_STOP); +#endif } this->push_istream(next_stream); continue; @@ -775,18 +777,14 @@ get_line(void) OK otherwise */ PHRQ_io::LINE_TYPE PHRQ_io:: -get_logical_line(void * cookie) +get_logical_line(void) { - int - j; - unsigned int - pos; - char - c; - if (!cookie) - return LT_EOF; + int j; + unsigned int pos; + char c; + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); - while ((j = istream_getc(cookie)) != EOF) + while ((j = getc()) != EOF) { c = (char) j; if (c == '#') @@ -801,7 +799,7 @@ get_logical_line(void * cookie) } m_line_save += c; } - while ((j = istream_getc(cookie)) != EOF); + while ((j = getc()) != EOF); } if (c == ';') break; @@ -813,7 +811,7 @@ get_logical_line(void * cookie) { pos = (int) m_line_save.size(); m_line_save += c; - while ((j = PHRQ_io::istream_getc(cookie)) != EOF) + while ((j = getc()) != EOF) { c = (char) j; if (c == '\\') diff --git a/PHRQ_io.h b/PHRQ_io.h index bd97b094..6465d14e 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -13,7 +13,7 @@ #include "Keywords.h" #include -class PhreeqcStop : std::exception +class PhreeqcStop : public std::exception { }; @@ -39,7 +39,6 @@ public: virtual ~ PHRQ_io(); // methods - static int istream_getc(void *cookie); static void safe_close(std::ostream **stream_ptr); static void safe_close(FILE **file_ptr); void close_ostreams(void); @@ -64,7 +63,7 @@ public: bool Get_output_on(void) {return this->output_on;}; // log_ostream - bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void log_flush(void); void log_close(void); virtual void log_msg(const char * str); @@ -85,7 +84,7 @@ public: // error_ostream #ifdef ERROR_OSTREAM - bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void error_flush(void); void error_close(void); virtual void error_msg(const char * str, bool stop=false); @@ -95,7 +94,7 @@ public: bool Get_error_on(void) {return this->error_on;} virtual void warning_msg(const char *err_str); #else - bool error_open(const char *file_name, const char * mode = "w"); + virtual bool error_open(const char *file_name, const char * mode = "w"); void error_flush(void); void error_close(void); virtual void error_msg(const char * str, bool stop=false); @@ -107,10 +106,10 @@ public: #endif // dump_ostream - bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void dump_flush(void); void dump_close(void); - void dump_msg(const char * str); + virtual void dump_msg(const char * str); void Set_dump_ostream(std::ostream * out) {this->dump_ostream = out;}; std::ostream *Get_dump_ostream(void) {return this->dump_ostream;}; void Set_dump_on(bool tf) {this->dump_on = tf;}; @@ -127,8 +126,9 @@ public: bool Get_screen_on(void) {return this->screen_on;}; // input methods + virtual int getc(void); LINE_TYPE get_line(void); - LINE_TYPE get_logical_line(void * cookie); + LINE_TYPE get_logical_line(void); bool check_key(std::string::iterator begin, std::string::iterator end); std::string & Get_m_line() {return m_line;} std::string & Get_m_line_save() {return m_line_save;} From 733d093f4944d610dab82463a3ab1c4ff4459bda Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 04:54:09 +0000 Subject: [PATCH 0458/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6356 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Exchange.h b/Exchange.h index be9876d3..adbf5b40 100644 --- a/Exchange.h +++ b/Exchange.h @@ -39,6 +39,7 @@ public: void Set_n_solution(int i) {this->n_solution = i;} cxxExchComp *Find_comp(std::string s); std::vector & Get_exchange_comps(void) {return this->exchange_comps;} + const std::vector & Get_exchange_comps(void)const {return this->exchange_comps;} void Set_exchange_comps(std::vector &c) {this->exchange_comps = c;} void Sort_comps(void); From 0e640f45cf98c9659bae20ed5b588cc753e10c93 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 04:54:37 +0000 Subject: [PATCH 0459/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6357 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ExchComp.h b/ExchComp.h index e29cf7d4..45941d0b 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -100,6 +100,7 @@ class cxxExchComp: public PHRQ_base this->totals = nd; } cxxNameDouble & Get_totals() {return (this->totals);} + const cxxNameDouble & Get_totals()const {return (this->totals);} void add(const cxxExchComp & comp, LDBLE extensive); void multiply(LDBLE extensive); From 828eaf16d3817beaa8f1b4f94bbd31f95efe0d11 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 05:04:41 +0000 Subject: [PATCH 0460/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6358 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 +- GasPhase.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index 0bfb6a33..fcb6f990 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -607,7 +607,7 @@ cxxGasPhase::totalize(PHREEQC_PTR_ARG) } return; } -LDBLE cxxGasPhase::Calc_total_moles(void) +LDBLE cxxGasPhase::Calc_total_moles(void)const { LDBLE tot = 0.0; for (size_t i = 0; i < this->gas_comps.size(); i++) diff --git a/GasPhase.h b/GasPhase.h index c22eb156..cfc2239d 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -46,11 +46,13 @@ class cxxGasPhase:public cxxNumKeyword return this->totals; }; std::vector & Get_gas_comps(void) {return gas_comps;}; + const std::vector & Get_gas_comps(void)const {return gas_comps;}; void Set_gas_comps(const std::vector v) {gas_comps = v;}; GP_TYPE Get_type(void) const {return type;}; void Set_type(GP_TYPE t) {type = t;}; LDBLE Get_total_p(void) const {return total_p;}; + void Set_total_p(LDBLE t) {total_p = t;}; LDBLE Get_volume(void) const {return volume;}; void Set_volume(LDBLE v) {volume = v;}; LDBLE Get_v_m(void) const {return v_m;}; @@ -65,13 +67,11 @@ class cxxGasPhase:public cxxNumKeyword void Set_solution_equilibria(bool tf) {this->solution_equilibria = tf;}; int Get_n_solution(void) const {return this->n_solution;}; void Set_n_solution(int i) {this->n_solution = i;}; - LDBLE Get_total_moles(void) {return (LDBLE) total_moles;}; + LDBLE Get_total_moles(void)const {return total_moles;}; void Set_total_moles(LDBLE t) {total_moles = t;}; - LDBLE Get_total_p(void) {return (LDBLE) total_p;}; - void Set_total_p(LDBLE t) {total_p = t;}; - LDBLE Get_temperature(void) {return (LDBLE) temperature;}; + LDBLE Get_temperature(void)const {return temperature;}; void Set_temperature(LDBLE t) {temperature = t;}; - LDBLE Calc_total_moles(void); + LDBLE Calc_total_moles(void)const; cxxGasComp *Find_comp(const char * comp_name); protected: From 6a92166384472cf1f1fddb6e519f0e1256715722 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 05:05:14 +0000 Subject: [PATCH 0461/1077] const modifications git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6359 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ISolution.h b/ISolution.h index caea078e..47b64872 100644 --- a/ISolution.h +++ b/ISolution.h @@ -34,6 +34,7 @@ class cxxISolution: public PHRQ_base std::string Get_default_pe() const {return default_pe;} void Set_default_pe(std::string pe) {default_pe = pe;} std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;} + const std::map < std::string, cxxISolutionComp > &Get_comps(void)const {return this->comps;} void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;} std::map < std::string, cxxChemRxn > &Get_pe_reactions(void) {return this->pe_reactions;} void Set_pe_reactions(std::map < std::string, cxxChemRxn > &pe) {this->pe_reactions = pe;} From ae7c893c88f80a68cf35b5784e865fdb83f8bdfe Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 05:07:46 +0000 Subject: [PATCH 0462/1077] added initialization code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6360 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 2f87ff1e..1ec44812 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -496,6 +496,7 @@ void Phreeqc::init(void) user_punch = 0; user_punch_headings = 0; user_punch_count_headings = 0; + n_user_punch_index = 0; /* Initialize llnl aqueous model parameters */ From ae27e8a374aa856e88ccb454360a17118362d76d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 4 Apr 2012 20:44:17 +0000 Subject: [PATCH 0463/1077] added init code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6361 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tally.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index 32de9714..9706810e 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -538,7 +538,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) for (size_t j = 0; j < ss_ptrs.size(); j++) { cxxSS * ss_ptr = ss_ptrs[j]; - cxxSScomp * comp_ptr; + cxxSScomp * comp_ptr = NULL; size_t k; for (k = 0; k < ss_ptr->Get_ss_comps().size(); k++) { From a512faafbefa6ee1a2af14568482c9f9f14c6cc0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 5 Apr 2012 03:38:52 +0000 Subject: [PATCH 0464/1077] setup for ERROR_OSTREAM git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6364 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 8 +++++++- PHRQ_io.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 52ae2071..416e2776 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -279,11 +279,17 @@ screen_msg(const char * str) /* ---------------------------------------------------------------------- */ { std::string stdstr(str); +#if defined(ERROR_OSTREAM) if (error_ostream != NULL && screen_on) { - //(*error_ostream) << stdstr; + (*error_ostream) << stdstr; + } +#else + if (error_file != NULL && screen_on) + { fprintf(error_file, "%s", str); } +#endif } #else /* ---------------------------------------------------------------------- */ diff --git a/PHRQ_io.h b/PHRQ_io.h index 6465d14e..b5249d24 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -13,6 +13,8 @@ #include "Keywords.h" #include +#define ERROR_OSTREAM + class PhreeqcStop : public std::exception { }; From 6167acc9cb4e4fbd89e5bd5aaed93df68092c544 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Apr 2012 04:06:49 +0000 Subject: [PATCH 0465/1077] sped up pitz_param/sit_param reading; added memory debug code for string_duplicate git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6391 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1863 --------------------------------- phreeqc/pitzer.cpp | 39 +- phreeqc/pitzer_structures.cpp | 164 +-- phreeqc/sit.cpp | 28 +- phreeqc/utilities.cpp | 9 + 5 files changed, 99 insertions(+), 2004 deletions(-) delete mode 100644 Phreeqc.h diff --git a/Phreeqc.h b/Phreeqc.h deleted file mode 100644 index 96d08488..00000000 --- a/Phreeqc.h +++ /dev/null @@ -1,1863 +0,0 @@ -#ifndef _INC_PHREEQC_H -#define _INC_PHREEQC_H -#if defined(WIN32) -#include -#endif -#if defined(WIN32_MEMORY_DEBUG) -#define _CRTDBG_MAP_ALLOC -#include -#endif -/* ---------------------------------------------------------------------- -* INCLUDE FILES -* ---------------------------------------------------------------------- */ -#include -#include -#include -#include -#ifdef HASH -#include -#endif -#include -#include -#include -#include -#include -#include -#include "phrqtype.h" -#include "cvdense.h" -#include "runner.h" -#include "dumper.h" -#include "PHRQ_io.h" -#ifdef MULTICHART -#include "ChartHandler.h" -#endif -#include "Keywords.h" -#include "Pressure.h" -#include "cxxMix.h" -#include "Use.h" -#include "Surface.h" - -class cxxNameDouble; -class cxxKinetics; -//class cxxMix; -class cxxKineticsComp; -class cxxExchange; -class cxxExchComp; -class cxxGasPhase; -class cxxTemperature; -class cxxPPassemblage; -class cxxPPassemblageComp; -class cxxReaction; -class cxxSolution; -class cxxISolutionComp; -class cxxSolutionIsotope; -class cxxSSassemblage; -class cxxSS; -class cxxStorageBin; - -#include "global_structures.h" -class PBasic; - -class Phreeqc -{ -public: - Phreeqc(PHRQ_io *io = NULL); - ~Phreeqc(void); - -public: - // - // Phreeqc class methods - // - - // advection.cpp ------------------------------- - int advection(void); - - // basicsubs.cpp ------------------------------- - int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); - int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); - void basic_free(void); - - LDBLE activity(const char *species_name); - LDBLE activity_coefficient(const char *species_name); - LDBLE log_activity_coefficient(const char *species_name); - LDBLE calc_SC(void); - /* VP: Density Start */ - LDBLE calc_dens(void); - /* VP: Density End */ - LDBLE calc_logk_n(const char *name); - LDBLE calc_logk_p(const char *name); - LDBLE calc_logk_s(const char *name); - LDBLE calc_surface_charge(const char *surface_name); - LDBLE diff_layer_total(const char *total_name, const char *surface_name); - LDBLE equi_phase(const char *phase_name); - LDBLE find_gas_comp(const char *gas_comp_name); - LDBLE find_gas_p(void); - LDBLE find_gas_vm(void); - LDBLE find_misc1(const char *ss_name); - LDBLE find_misc2(const char *ss_name); - LDBLE find_ss_comp(const char *ss_comp_name); - LDBLE get_calculate_value(const char *name); - char * iso_unit(const char *total_name); - LDBLE iso_value(const char *total_name); - LDBLE kinetics_moles(const char *kinetics_name); - LDBLE log_activity(const char *species_name); - LDBLE log_molality(const char *species_name); - LDBLE molality(const char *species_name); - LDBLE pressure(void); - LDBLE pr_pressure(const char *phase_name); - LDBLE pr_phi(const char *phase_name); - LDBLE saturation_ratio(const char *phase_name); - int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); - LDBLE solution_sum_secondary(const char *total_name); - LDBLE sum_match_gases(const char *stemplate, const char *name); - LDBLE sum_match_species(const char *stemplate, const char *name); - LDBLE sum_match_ss(const char *stemplate, const char *name); - int match_elts_in_species(const char *name, const char *stemplate); - int extract_bracket(char **string, char *bracket_string); - LDBLE surf_total(const char *total_name, const char *surface_name); - static int system_species_compare(const void *ptr1, const void *ptr2); - LDBLE system_total(const char *total_name, LDBLE * count, char ***names, - char ***types, LDBLE ** moles); - std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); - LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); - int system_total_elements(void); - int system_total_si(void); - int system_total_aq(void); - int system_total_ex(void); - int system_total_surf(void); - int system_total_gas(void); - int system_total_ss(void); - int system_total_elt(const char *total_name); - int system_total_elt_secondary(const char *total_name); - LDBLE total(const char *total_name); - LDBLE total_mole(const char *total_name); - int system_total_solids(cxxExchange *exchange_ptr, - cxxPPassemblage *pp_assemblage_ptr, - cxxGasPhase *gas_phase_ptr, - cxxSSassemblage *ss_assemblage_ptr, - cxxSurface *surface_ptr); - - static LDBLE f_rho(LDBLE rho_old, void *cookie); - static LDBLE f_Vm(LDBLE v1, void *cookie); - // chart.cpp -#if defined PHREEQ98 - void DeleteCurves(void); - void ExtractCurveInfo(char *line, int curvenr); - void GridChar(char *s, char *a); - void MallocCurves(int nc, int ncxy); - int OpenCSVFile(char file_name[MAX_LENGTH]); - void SaveCurvesToFile(char file_name[MAX_LENGTH]); - void PlotXY(char *x, char *y); - void ReallocCurves(int new_nc); - void ReallocCurveXY(int i); - void SetAxisScale(char *a, int j, char *token, int true_); - void SetAxisTitles(char *s, int i); - void SetChartTitle(char *s); - void start_chart(bool end); -#endif - - // cl1.cpp ------------------------------- - int cl1(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q, - int *kode, LDBLE toler, - int *iter, LDBLE * x, LDBLE * res, LDBLE * error, - LDBLE * cu, int *iu, int *s, int check); - void cl1_space(int check, int n2d, int klm, int nklmd); - - // cl1mp.cpp ------------------------------- - int cl1mp(int k, int l, int m, int n, - int nklmd, int n2d, - LDBLE * q_arg, - int *kode, LDBLE toler, - int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, - LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); - - // class_main.cpp ------------------------------- - int write_banner(void); - - /* default.cpp */ -public: - int close_input_files(void); - int close_output_files(void); - static int istream_getc(void *cookie); - int process_file_names(int argc, char *argv[], std::istream **db_cookie, - std::istream **input_cookie, int log); - - /* PHRQ_io_output.cpp */ - void screen_msg(const char * str); - - void echo_msg(const char *err_str); - int warning_msg(const char *err_str); - void set_forward_output_to_log(int value); - int get_forward_output_to_log(void); - - // dump_ostream - bool dump_open(const char *file_name); - void dump_flush(void); - void dump_close(void); - void dump_msg(const char * str); - - // log_ostream - bool log_open(const char *file_name); - void log_flush(void); - void log_close(void); - void log_msg(const char * str); - - // error_ostream - bool error_open(const char *file_name); - void error_flush(void); - void error_close(void); - void error_msg(const char * str, bool stop=false); - - // output_ostream - bool output_open(const char *file_name); - void output_flush(void); - void output_close(void); - void output_msg(const char * str); - - // punch_ostream - bool punch_open(const char *file_name); - void punch_flush(void); - void punch_close(void); - void punch_msg(const char * str); - - void fpunchf_heading(const char *name); - void fpunchf(const char *name, const char *format, double d); - void fpunchf(const char *name, const char *format, char * d); - void fpunchf(const char *name, const char *format, int d); - void fpunchf_user(int user_index, const char *format, double d); - void fpunchf_user(int user_index, const char *format, char * d); - int fpunchf_end_row(const char *format); - - // dw.cpp ------------------------------- - int BB(LDBLE T); - LDBLE PS(LDBLE T); - LDBLE VLEST(LDBLE T); - int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); - int QQ(LDBLE T, LDBLE D); - LDBLE BASE(LDBLE D); - - // input.cpp ------------------------------- - int reading_database(void); - void set_reading_database(int reading_database); - int check_line(const char *string, int allow_empty, int allow_eof, - int allow_keyword, int print); - - // integrate.cpp ------------------------------- - int calc_all_g(void); - int calc_init_g(void); - int initial_surface_water(void); - int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); - int calc_all_donnan(void); - int calc_init_donnan(void); - LDBLE g_function(LDBLE x_value); - LDBLE midpnt(LDBLE x1, LDBLE x2, int n); - void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, - LDBLE * dy); - LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); - LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); - int calc_all_donnan_music(void); - int calc_init_donnan_music(void); - - // inverse.cpp ------------------------------- - int inverse_models(void); - int add_to_file(const char *filename, const char *string); - int bit_print(unsigned long bits, int l); - int carbon_derivs(struct inverse *inv_ptr); - int check_isotopes(struct inverse *inv_ptr); - int check_solns(struct inverse *inv_ptr); - int count_isotope_unknowns(struct inverse *inv_ptr, - struct isotope **isotope_unknowns); - cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); - LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); - int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); - int post_mortem(void); - bool test_cl1_solution(void); - unsigned long get_bits(unsigned long bits, int position, int number); - unsigned long minimal_solve(struct inverse *inv_ptr, - unsigned long minimal_bits); - void dump_netpath(struct inverse *inv_ptr); - int dump_netpath_pat(struct inverse *inv_ptr); - int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, - int model_size); - int phase_isotope_inequalities(struct inverse *inv_ptr); - int print_model(struct inverse *inv_ptr); - int punch_model_heading(struct inverse *inv_ptr); - int punch_model(struct inverse *inv_ptr); - void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total(FILE * netpath_file, cxxSolution *solution_ptr, - const char *elt, const char *string); - void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, - const char *string, const char *elt0, - const char *elt1, const char *elt2, const char *elt3, - const char *elt4); - - void print_total_pat(FILE * netpath_file, const char *elt, - const char *string); - int range(struct inverse *inv_ptr, unsigned long cur_bits); - int save_bad(unsigned long bits); - int save_good(unsigned long bits); - int save_minimal(unsigned long bits); - unsigned long set_bit(unsigned long bits, int position, int value); - int setup_inverse(struct inverse *inv_ptr); - int set_initial_solution(int n_user_old, int n_user_new); - int set_ph_c(struct inverse *inv_ptr, - int i, cxxSolution *soln_ptr_orig, int n_user_new, - LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); - int shrink(struct inverse *inv_ptr, LDBLE * array_in, - LDBLE * array_out, int *k, int *l, int *m, int *n, - unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, - int *row_back_l); - int solve_inverse(struct inverse *inv_ptr); - int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); - int subset_bad(unsigned long bits); - int subset_minimal(unsigned long bits); - int superset_minimal(unsigned long bits); - int write_optimize_names(struct inverse *inv_ptr); - - // isotopes.cpp ------------------------------- - int add_isotopes(cxxSolution &solution_ptr); - int calculate_values(void); - int calculate_isotope_moles(struct element *elt_ptr, - cxxSolution *solution_ptr, LDBLE total_moles); - LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); - int from_pcil(struct master_isotope *master_isotope_ptr); - int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); - int from_tu(struct master_isotope *master_isotope_ptr); - struct calculate_value *calculate_value_alloc(void); - int calculate_value_free(struct calculate_value *calculate_value_ptr); - struct calculate_value *calculate_value_search(const char *name); - struct calculate_value *calculate_value_store(const char *name, - int replace_if_found); - struct isotope_alpha *isotope_alpha_alloc(void); - struct isotope_alpha *isotope_alpha_search(const char *name); - struct isotope_alpha *isotope_alpha_store(const char *name, - int replace_if_found); - struct isotope_ratio *isotope_ratio_alloc(void); - struct isotope_ratio *isotope_ratio_search(const char *name); - struct isotope_ratio *isotope_ratio_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_store(const char *name, - int replace_if_found); - struct master_isotope *master_isotope_alloc(void); - struct master_isotope *master_isotope_search(const char *name); - int print_initial_solution_isotopes(void); - int print_isotope_ratios(void); - int print_isotope_alphas(void); - int punch_isotopes(void); - int punch_calculate_values(void); - int read_calculate_values(void); - int read_isotopes(void); - int read_isotope_ratios(void); - int read_isotope_alphas(void); - int calculate_value_init(struct calculate_value *calculate_value_ptr); - int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); - int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); - int master_isotope_init(struct master_isotope *master_isotope_ptr); - - // kinetics.cpp ------------------------------- - void cvode_init(void); - int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); - int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, - LDBLE step_fraction); - int set_advection(int i, int use_mix, int use_kinetics, int nsaver); - int free_cvode(void); -public: - static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, - void *f_data); - static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, - N_Vector y, N_Vector fy, N_Vector ewt, realtype h, - realtype uround, void *jac_data, long int *nfePtr, - N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); - - int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); - int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, - LDBLE time_step); - int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, - LDBLE step_fraction); - int set_reaction(int i, int use_mix, int use_kinetics); - int set_transport(int i, int use_mix, int use_kinetics, int nsaver); - int store_get_equi_reactants(int k, int kin_end); - int count_pp, count_pg, count_ss; - LDBLE *x0_moles; - - // mainsubs.cpp ------------------------------- - std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); - int copy_entities(void); - void initialize(void); - int initial_exchangers(int print); - int initial_gas_phases(int print); - int initial_solutions(int print); - int step_save_exch(int n_user); - int step_save_surf(int n_user); - int initial_surfaces(int print); - int reactions(void); - int saver(void); - int xsolution_save(int k_user); - int xexchange_save(int n_user); - int xgas_save(int n_user); - int xpp_assemblage_save(int n_user); - int xss_assemblage_save(int n_user); - int xsurface_save(int n_user); - int do_initialize(void); - int do_status(void); - void save_init(int i); - int copy_use(int i); - int set_use(void); - - // model.cpp ------------------------------- - int check_residuals(void); - int free_model_allocs(void); - int ineq(int kode); - int model(void); - int jacobian_sums(void); - int mb_gases(void); - int mb_ss(void); - int mb_sums(void); - int molalities(int allow_overflow); - int reset(void); - int residuals(void); - int set(int initial); - int sum_species(void); - int surface_model(void); - LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, - LDBLE xbaq); - LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, - LDBLE kb, LDBLE xcaq, LDBLE xbaq); - LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, - LDBLE xcaq, LDBLE xbaq); - int numerical_jacobian(void); - void set_inert_moles(void); - void unset_inert_moles(void); -#ifdef SLNQ - int add_trivial_eqns(int rows, int cols, LDBLE * matrix); - //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -#endif - int calc_gas_pressures(void); - int calc_fixed_volume_gas_pressures(void); - int calc_ss_fractions(void); - int gammas(LDBLE mu); - int initial_guesses(void); - int revise_guesses(void); - int ss_binary(cxxSS *ss_ptr); - int ss_ideal(cxxSS *ss_ptr); - int gas_in; - void ineq_init(int max_row_count, int max_column_count); - - // parse.cpp ------------------------------- - int check_eqn(int association); - int get_charge(char *charge, LDBLE * z); - int get_elt(char **t_ptr, char *element, int *i); - int get_elts_in_species(char **t_ptr, LDBLE coef); - int get_num(char **t_ptr, LDBLE * num); - int get_secondary_in_species(char **t_ptr, LDBLE coef); - int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); - int get_coef(LDBLE * coef, char **eqnaddr); - int get_secondary(char **t_ptr, char *element, int *i); - int get_species(char **ptr); - - // phqalloc.cpp ------------------------------- -public: -#if !defined(NDEBUG) - void *PHRQ_malloc(size_t, const char *, int); - void *PHRQ_calloc(size_t, size_t, const char *, int); - void *PHRQ_realloc(void *, size_t, const char *, int); -#else - void *PHRQ_malloc(size_t); - void *PHRQ_calloc(size_t, size_t); - void *PHRQ_realloc(void *, size_t); -#endif - void PHRQ_free(void *ptr); - void PHRQ_free_all(void); - -public: - - // pitzer.cpp ------------------------------- - struct pitz_param *pitz_param_read(char *string, int n); - int pitz_param_search(struct pitz_param *pzp_ptr); - int sit_param_search(struct pitz_param *pzp_ptr); - struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); - struct theta_param *theta_param_alloc(void); - int theta_param_init(struct theta_param *theta_param_ptr); - int gammas_pz(void); - int model_pz(void); - int pitzer(void); - int pitzer_clean_up(void); - int pitzer_init(void); - int pitzer_tidy(void); - int read_pitzer(void); - int set_pz(int initial); - int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_pz(void); - int ISPEC(const char *name); - LDBLE G(LDBLE Y); - LDBLE GP(LDBLE Y); - int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, - LDBLE * ethetap); - int BDK(LDBLE X); - int pitzer_initial_guesses(void); - int pitzer_revise_guesses(void); - int PTEMP(LDBLE TK); - LDBLE JAY(LDBLE X); - LDBLE JPRIME(LDBLE Y); - int jacobian_pz(void); - - // pitzer_structures.cpp ------------------------------- - struct pitz_param *pitz_param_alloc(void); - int pitz_param_init(struct pitz_param *pitz_param_ptr); - struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); - int pitz_param_copy(struct pitz_param *old_ptr, - struct pitz_param *new_ptr); - - // prep.cpp ------------------------------- - int add_potential_factor(void); - int add_cd_music_factors(int n); - int add_surface_charge_balance(void); - int add_cd_music_charge_balances(int i); - int build_gas_phase(void); - int build_fixed_volume_gas(void); - int build_jacobian_sums(int k); - int build_mb_sums(void); - int build_min_exch(void); - int build_model(void); - int build_pure_phases(void); - int build_ss_assemblage(void); - int build_solution_phase_boundaries(void); - int build_species_list(int n); - int build_min_surface(void); - LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); - LDBLE calc_delta_v(reaction * r_ptr, bool phase); - LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); - LDBLE calc_PR(); - int calc_vm(LDBLE tc, LDBLE pa); - int change_hydrogen_in_elt_list(LDBLE charge); - int clear(void); - //int convert_units(struct solution *solution_ptr); - int convert_units(cxxSolution *solution_ptr); - LDBLE a_aa_sum, b2, b_sum, R_TK; - LDBLE f_Vm(LDBLE v1); - struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); - struct master **get_list_master_ptrs(char *ptr, - struct master *master_ptr); - int inout(void); - int is_special(struct species *spec); - int mb_for_species_aq(int n); - int mb_for_species_ex(int n); - int mb_for_species_surf(int n); - int quick_setup(void); - int resetup_master(void); - int save_model(void); - int setup_exchange(void); - int setup_gas_phase(void); - int setup_fixed_volume_gas(void); - int setup_slack(void); - int setup_master_rxn(struct master **master_ptr_list, - const std::string &pe_rxn); - int setup_pure_phases(void); - int adjust_setup_pure_phases(void); - int setup_related_surface(void); - int setup_ss_assemblage(void); - int setup_solution(void); - int adjust_setup_solution(void); - int setup_surface(void); - int setup_unknowns(void); - int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, - LDBLE * gamma_source); - int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); - int store_jacob0(int row, int column, LDBLE coef); - int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); - int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, - LDBLE coef, LDBLE * gamma_ptr); - int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); - int tidy_redox(void); - struct master **unknown_alloc_master(void); - int write_mb_eqn_x(void); - int write_mb_for_species_list(int n); - int write_mass_action_eqn_x(int stop); - - int check_same_model(void); - int k_temp(LDBLE tc, LDBLE pa); - LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); - int prep(void); - int reprep(void); - int rewrite_master_to_secondary(struct master *master_ptr1, - struct master *master_ptr2); - int switch_bases(void); - int write_phase_sys_total(int n); - - // print.cpp ------------------------------- - char *sformatf(const char *format, ...); - int array_print(LDBLE * array_l, int row_count, int column_count, - int max_column_count); - int print_all(void); - int print_exchange(void); - int print_gas_phase(void); - int print_master_reactions(void); - int print_reaction(struct reaction *rxn_ptr); - int print_species(void); - int print_surface(void); - int print_user_print(void); - int punch_all(void); - int print_alkalinity(void); - int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); - int print_eh(void); - int print_reaction(void); - int print_kinetics(void); - int print_mix(void); - int print_pp_assemblage(void); - int print_ss_assemblage(void); - int print_saturation_indices(void); - int print_surface_cd_music(void); - int print_totals(void); - int print_using(void); - /*int print_user_print(void);*/ - int punch_gas_phase(void); - int punch_identifiers(void); - int punch_kinetics(void); - int punch_molalities(void); - int punch_activities(void); - int punch_pp_assemblage(void); - int punch_ss_assemblage(void); - int punch_saturation_indices(void); - int punch_totals(void); - int punch_user_punch(void); -#if defined MULTICHART - int punch_user_graph(void); -#endif - - // read.cpp ------------------------------- - int read_input(void); - int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); - int *read_list_ints_range(char **ptr, int *count_ints, int positive, - int *int_list); - int read_log_k_only(char *ptr, LDBLE * log_k); - int read_t_c_only(char *ptr, LDBLE *t_c); - int read_p_c_only(char *ptr, LDBLE * p_c); - int read_omega_only(char *ptr, LDBLE *omega); - int read_number_description(char *ptr, int *n_user, int *n_user_end, - char **description, int allow_negative=FALSE); - int check_key(const char *str); - int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, - const char *default_units, bool print); - int find_option(const char *item, int *n, const char **list, int count_list, - int exact); - int get_option(const char **opt_list, int count_opt_list, char **next_char); - int get_true_false(char *string, int default_value); - - int add_psi_master_species(char *token); - int read_advection(void); - int read_analytical_expression_only(char *ptr, LDBLE * log_k); - /* VP: Density Start */ - int read_millero_abcdef (char *ptr, LDBLE * abcdef); - /* VP: Density End */ - int read_copy(void); - int read_debug(void); - int read_delta_h_only(char *ptr, LDBLE * delta_h, - DELTA_H_UNIT * units); - int read_vm_only(char *ptr, LDBLE * delta_v, - DELTA_V_UNIT * units); - int read_llnl_aqueous_model_parameters(void); - int read_exchange(void); - int read_exchange_master_species(void); - int read_exchange_species(void); - int read_gas_phase(void); - int read_incremental_reactions(void); - int read_inverse(void); - int read_inv_balances(struct inverse *inverse_ptr, char *next_char); - int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); - int read_inv_phases(struct inverse *inverse_ptr, char *next_char); - int read_kinetics(void); - int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc, const char **opt_list, - int count_opt_list, int *opt); - LDBLE *read_list_doubles(char **ptr, int *count_doubles); - int *read_list_ints(char **ptr, int *count_ints, int positive); - int *read_list_t_f(char **ptr, int *count_ints); - int read_master_species(void); - int read_mix(void); - int read_named_logk(void); - int read_phases(void); - int read_print(void); - int read_pp_assemblage(void); - int read_rates(void); - int read_reaction(void); - int read_reaction_reactants(cxxReaction *reaction_ptr); - int read_reaction_steps(cxxReaction *reaction_ptr); - int read_solid_solutions(void); - int read_temperature(void); - int read_reaction_temps(struct temperature *temperature_ptr); - int read_reaction_pressure(void); - int read_reaction_pressure_raw(void); - int read_save(void); - int read_selected_output(void); - int read_solution(void); - int read_species(void); - int read_surface(void); - int read_surface_master_species(void); - int read_surface_species(void); - int read_use(void); - int read_title(void); - int read_user_print(void); - int read_user_punch(void); -#if defined PHREEQ98 - int read_user_graph(void); -#endif -#if defined MULTICHART - int read_user_graph_handler(); -#endif - int next_keyword_or_option(const char **opt_list, int count_opt_list); - int cleanup_after_parser(CParser &parser); - - // ReadClass.cxx - int read_dump(void); - int read_delete(void); - int read_run_cells(void); - int streamify_to_next_keyword(std::istringstream & lines); - int dump_entities(void); - int delete_entities(void); - int run_as_cells(void); - void dump_ostream(std::ostream& os); - - // readtr.cpp ------------------------------- - int read_transport(void); - int dump(void); - int dump_exchange(int k); - int dump_gas_phase(int k); - int dump_kinetics(int k); - int dump_mix(int k); - int dump_pp_assemblage(int k); - int dump_reaction(int k); - int dump_ss_assemblage(int k); - int dump_solution(int k); - int dump_surface(int k); - int dump_cpp(void); - int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, - int *count_alloc); - - // sit.cpp ------------------------------- - int gammas_sit(void); - int model_sit(void); - int sit(void); - int sit_clean_up(void); - int sit_init(void); - int sit_tidy(void); - int read_sit(void); - int set_sit(int initial); - int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_sit(void); - int sit_ISPEC(const char *name); - /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ - int sit_initial_guesses(void); - int sit_revise_guesses(void); - int PTEMP_SIT(LDBLE tk); - int jacobian_sit(void); - - // spread.cpp ------------------------------- - int read_solution_spread(void); - int copy_token_tab(char *token_ptr, char **ptr, int *length); - int get_option_string(const char **opt_list, int count_opt_list, - char **next_char); - int spread_row_free(struct spread_row *spread_row_ptr); - int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); - struct spread_row *string_to_spread_row(char *string); -#ifdef PHREEQCI_GUI - void add_row(struct spread_row *spread_row_ptr); - void copy_defaults(struct defaults *dest_ptr, - struct defaults *src_ptr); - void free_spread(void); - struct spread_row *copy_row(struct spread_row *spread_row_ptr); -#endif - - // step.cpp ------------------------------- - int step(LDBLE step_fraction); - int xsolution_zero(void); - int add_exchange(cxxExchange *exchange_ptr); - int add_gas_phase(cxxGasPhase *gas_phase_ptr); - int add_kinetics(cxxKinetics *kinetics_ptr); - int add_mix(cxxMix * mix_ptr); - int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); - int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); - int add_solution(cxxSolution *solution_ptr, LDBLE extensive, - LDBLE intensive); - int add_surface(cxxSurface *surface_ptr); - int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); - int gas_phase_check(cxxGasPhase *gas_phase_ptr); - int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); - int reaction_calc(cxxReaction *reaction_ptr); - int solution_check(void); - int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); - - // structures.cpp ------------------------------- - int clean_up(void); - int reinitialize(void); - int copier_add(struct copier *copier_ptr, int n_user, int start, int end); - int copier_free(struct copier *copier_ptr); - int copier_init(struct copier *copier_ptr); - static int element_compare(const void *ptr1, const void *ptr2); -public: - struct element *element_store(const char *element); - int elt_list_combine(void); - static int elt_list_compare(const void *ptr1, const void *ptr2); -protected: - struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); - int elt_list_print(struct elt_list *elt_list_ptr); - struct elt_list *elt_list_save(void); - cxxNameDouble elt_list_NameDouble(void); -public: - enum entity_type get_entity_enum(char *name); - struct inverse *inverse_alloc(void); - int inverse_delete(int i); - static int inverse_isotope_compare(const void *ptr1, const void *ptr2); - struct inverse *inverse_search(int n_user, int *n); - int inverse_sort(void); -protected: - struct logk *logk_alloc(void); - int logk_copy2orig(struct logk *logk_ptr); - struct logk *logk_store(char *name, int replace_if_found); - struct logk *logk_search(const char *name); - struct master *master_alloc(void); - static int master_compare(const void *ptr1, const void *ptr2); - int master_delete(char *ptr); -public: - struct master *master_bsearch(const char *ptr); - struct master *master_bsearch_primary(const char *ptr); - struct master *master_bsearch_secondary(char *ptr); - struct master *master_search(char *ptr, int *n); - struct pe_data *pe_data_alloc(void); -public: - struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); - struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); -protected: - int pe_data_store(struct pe_data **pe, const char *token); -public: - struct phase *phase_bsearch(const char *ptr, int *j, int print); -protected: - static int phase_compare(const void *ptr1, const void *ptr2); - int phase_delete(int i); - struct phase *phase_store(const char *name); -public: - struct rate *rate_bsearch(char *ptr, int *j); - int rate_free(struct rate *rate_ptr); - struct rate *rate_search(const char *name, int *n); - int rate_sort(void); - struct reaction *rxn_alloc(int ntokens); - struct reaction *rxn_dup(struct reaction *rxn_ptr_old); - LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); - int rxn_free(struct reaction *rxn_ptr); - int rxn_print(struct reaction *rxn_ptr); - static int s_compare(const void *ptr1, const void *ptr2); - int s_delete(int i); - struct species *s_search(const char *name); - struct species *s_store(const char *name, LDBLE z, int replace_if_found); -protected: - struct save_values *save_values_bsearch(struct save_values *k, int *n); - static int save_values_compare(const void *ptr1, const void *ptr2); - int save_values_sort(void); - int save_values_store(struct save_values *s_v); - static int isotope_compare(const void *ptr1, const void *ptr2); - static int species_list_compare_alk(const void *ptr1, const void *ptr2); - static int species_list_compare_master(const void *ptr1, const void *ptr2); - int species_list_sort(void); - struct Change_Surf *change_surf_alloc(int count); -public: - struct master *surface_get_psi_master(const char *name, int plane); - int system_duplicate(int i, int save_old); - int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); - int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); - int trxn_combine(void); - int trxn_copy(struct reaction *rxn_ptr); - LDBLE trxn_find_coef(const char *str, int start); - int trxn_print(void); - int trxn_reverse_k(void); - int trxn_sort(void); - int trxn_swap(const char *token); - struct unknown *unknown_alloc(void); - int unknown_delete(int i); - int unknown_free(struct unknown *unknown_ptr); - int entity_exists(char *name, int n_user); - static int inverse_compare(const void *ptr1, const void *ptr2); - int inverse_free(struct inverse *inverse_ptr); - static int kinetics_compare_int(const void *ptr1, const void *ptr2); - int logk_init(struct logk *logk_ptr); - static int master_compare_string(const void *ptr1, const void *ptr2); - int master_free(struct master *master_ptr); - struct phase *phase_alloc(void); - static int phase_compare_string(const void *ptr1, const void *ptr2); - int phase_free(struct phase *phase_ptr); - int phase_init(struct phase *phase_ptr); - static int rate_compare(const void *ptr1, const void *ptr2); - static int rate_compare_string(const void *ptr1, const void *ptr2); - struct species *s_alloc(void); - int s_free(struct species *s_ptr); - int s_init(struct species *s_ptr); - static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); - static int solution_compare(const void *ptr1, const void *ptr2); - static int solution_compare_int(const void *ptr1, const void *ptr2); - static int species_list_compare(const void *ptr1, const void *ptr2); - static int surface_compare_int(const void *ptr1, const void *ptr2); - static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); - int trxn_multiply(LDBLE coef); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - extern void MergeFinalize(void); -#endif - struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); - struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); - struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); - struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); - - void Use2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb); - void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); - void cxxStorageBin2phreeqc(cxxStorageBin & sb); - - /* tally.cpp */ - void add_all_components_tally(void); - int build_tally_table(void); - int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); - int diff_tally_table(void); - int extend_tally_table(void); - int free_tally_table(void); - int fill_tally_table(int *n_user, int index_conservative, int n_buffer); - int get_tally_table_rows_columns(int *rows, int *columns); - int get_tally_table_column_heading(int column, int *type, char *string); - int get_tally_table_row_heading(int column, char *string); - int store_tally_table(LDBLE * array, int row_dim, int col_dim, - LDBLE fill_factor); - int zero_tally_table(void); - int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); - int get_all_components(void); - int print_tally_table(void); - int set_reaction_moles(int n_user, LDBLE moles); - int set_reaction_temperature(int n_user, LDBLE tc); - int set_kinetics_time(int n_user, LDBLE step); - - // tidy.cpp ------------------------------- - int add_other_logk(LDBLE * source_k, int count_add_logk, - struct name_coef *add_logk); - int add_logks(struct logk *logk_ptr, int repeats); - LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); - int replace_solids_gases(void); - int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); - int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); - int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); -public: - int tidy_punch(void); - int tidy_model(void); - int check_species_input(void); - LDBLE coef_in_master(struct master *master_ptr); - int phase_rxn_to_trxn(struct phase *phase_ptr, - struct reaction *rxn_ptr); - int reset_last_model(void); - int rewrite_eqn_to_primary(void); - int rewrite_eqn_to_secondary(void); - int species_rxn_to_trxn(struct species *s_ptr); - int tidy_logk(void); - int tidy_exchange(void); - int tidy_min_exchange(void); - int tidy_kin_exchange(void); - int tidy_gas_phase(void); - int tidy_inverse(void); - int tidy_isotopes(void); - int tidy_isotope_ratios(void); - int tidy_isotope_alphas(void); - int tidy_kin_surface(void); - int tidy_master_isotope(void); - int tidy_min_surface(void); - int tidy_phases(void); - int tidy_pp_assemblage(void); - int tidy_solutions(void); - int tidy_ss_assemblage(void); - int tidy_species(void); - int tidy_surface(void); - int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); - static LDBLE f_spinodal(LDBLE x, void *); - int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); - int ss_calc_a0_a1(cxxSS *ss_ptr); - - // transport.cpp ------------------------------- - int transport(void); - int set_initial_moles(int i); - cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, - cxxSurface *source2, std::string charge_name, LDBLE f2, - LDBLE new_Dw); - int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, - LDBLE new_Dw, int cell); - LDBLE viscosity(void); - int multi_D(LDBLE DDt, int mobile_cell, int stagnant); - int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); - int fill_spec(int cell_no); - int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); - static int sort_species_name(const void *ptr1, const void *ptr2); - int disp_surf(LDBLE stagkin_time); - int diff_stag_surf(int mobile_cell); - int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); - cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, - int n_user_new, - bool move_old); - int init_mix(void); - int init_heat_mix(int nmix); - int heat_mix(int heat_nmix); - int mix_stag(int i, LDBLE stagkin_time, int punch, - LDBLE step_fraction_kin); - - // utilities.cpp ------------------------------- -public: - int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); - int add_elt_list(const cxxNameDouble & nd, LDBLE coef); -protected: - int backspace_screen(int spaces); - LDBLE calc_alk(struct reaction *rxn_ptr); -public: - LDBLE calc_rho_0(LDBLE tc, LDBLE pa); - LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); - int compute_gfw(const char *string, LDBLE * gfw); -#if defined PHREEQ98 - int copy_title(char *token_ptr, char **ptr, int *length); -#endif - int copy_token(char *token_ptr, char **ptr, int *length); - int copy_token(std::string &token, char **ptr); - int dup_print(const char *ptr, int emphasis); - int equal(LDBLE a, LDBLE b, LDBLE eps); -public: - void *free_check_null(void *ptr); -protected: - void free_hash_strings(HashTable * Table); - int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); - int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); - void hdestroy_multi(HashTable * HashTable_ptr); - ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); - int islegit(const char c); -public: - void malloc_error(void); -protected: - int parse_couple(char *token); - int print_centered(const char *string); -public: - static int replace(const char *str1, const char *str2, char *str); - static bool replace(const char *str1, const char *str2, std::string & str); - static int strcmp_nocase(const char *str1, const char *str2); - static int strcmp_nocase_arg1(const char *str1, const char *str2); -protected: - void space(void **ptr, int i, int *max, int struct_size); - void squeeze_white(char *s_l); - int status(int count, const char *str, bool kinetics = false); - void str_tolower(char *str); - void str_toupper(char *str); -public: - char *string_duplicate(const char *token); - const char *string_hsave(const char *str); - void strings_map_clear(); -#ifdef HASH - void strings_hash_clear(); -#endif -protected: - char *string_pad(const char *str, int i); - int string_trim(char *str); - int string_trim_right(char *str); - int string_trim_left(char *str); - static LDBLE under(LDBLE xval); - void zero_double(LDBLE * target, int n); - int get_input_errors(void); -#ifdef PHREEQ98 - void AddToCEntry(char *a, int l, int i); - void ApplicationProcessMessages(void); - int copy_title(char *token_ptr, char **ptr, int *length); - extern int clean_up_null(void); -#endif - int isamong(char c, const char *s_l); - Address Hash_multi(HashTable * Table, const char *Key); - void ExpandTable_multi(HashTable * Table); -public: - int main_method(int argc, char *argv[]); - void set_phast(int); - size_t list_components(std::list &list_c); - PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} -protected: - void init(void); - - // - //Data members - // -protected: - PHRQ_io *phrq_io; - PHRQ_io ioInstance; - - /* ---------------------------------------------------------------------- - * STRUCTURES - * ---------------------------------------------------------------------- */ - - struct model last_model; - int same_model; - int same_temperature; - int same_pressure; - bool same_mu; - struct punch punch; - /* ---------------------------------------------------------------------- - * Temperatures - * ---------------------------------------------------------------------- */ - - std::map Rxn_temperature_map; - - /* ---------------------------------------------------------------------- - * Pressures - * ---------------------------------------------------------------------- */ - std::map Rxn_pressure_map; - - /* ---------------------------------------------------------------------- - * Surface - * --------------------------------------------------------------------- */ - - int g_iterations; - LDBLE G_TOL; - std::map Rxn_surface_map; - std::map charge_group_map; - int change_surf_count; - struct Change_Surf *change_surf; - - /* ---------------------------------------------------------------------- - * Exchange - * ---------------------------------------------------------------------- */ - std::map Rxn_exchange_map; - - /* ---------------------------------------------------------------------- - * Kinetics - * ---------------------------------------------------------------------- */ - std::map Rxn_kinetics_map; - - /*---------------------------------------------------------------------- - * Save - *---------------------------------------------------------------------- */ - int count_save_values; - struct save_values *save_values; - struct save save; - - /*---------------------------------------------------------------------- - * Use - *---------------------------------------------------------------------- */ - cxxUse use; - - /*---------------------------------------------------------------------- - * Copy - *---------------------------------------------------------------------- */ - struct copier copy_solution; - struct copier copy_pp_assemblage; - struct copier copy_exchange; - struct copier copy_surface; - struct copier copy_ss_assemblage; - struct copier copy_gas_phase; - struct copier copy_kinetics; - struct copier copy_mix; - struct copier copy_reaction; - struct copier copy_temperature; - struct copier copy_pressure; - - /*---------------------------------------------------------------------- - * Inverse - *---------------------------------------------------------------------- */ - - struct inverse *inverse; - int count_inverse; - - /*---------------------------------------------------------------------- - * Mix - *---------------------------------------------------------------------- */ - std::map Rxn_mix_map; - std::map Dispersion_mix_map; - - /*---------------------------------------------------------------------- - * Irreversible reaction - *---------------------------------------------------------------------- */ - std::map Rxn_reaction_map; - - /*---------------------------------------------------------------------- - * Gas phase - *---------------------------------------------------------------------- */ - std::map Rxn_gas_phase_map; - - /*---------------------------------------------------------------------- - * Solid solution - *---------------------------------------------------------------------- */ - std::map Rxn_ss_assemblage_map; - - /*---------------------------------------------------------------------- - * Pure-phase assemblage - *---------------------------------------------------------------------- */ - std::map Rxn_pp_assemblage_map; - - /*---------------------------------------------------------------------- - * Species_list - *---------------------------------------------------------------------- */ - int count_species_list; - int max_species_list; - struct species_list *species_list; - - /*---------------------------------------------------------------------- - * Jacobian and Mass balance lists - *---------------------------------------------------------------------- */ - - int count_sum_jacob0; /* number of elements in sum_jacob0 */ - int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ - struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ - - int count_sum_mb1; /* number of elements in sum_mb1 */ - int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ - struct list1 *sum_mb1; /* array of pointers to sources and targets for mass - balance summations with coef = 1.0 */ - int count_sum_jacob1; /* number of elements in sum_jacob1 */ - int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ - struct list1 *sum_jacob1; /* array of pointers to sources and targets for array - equations with coef = 1.0 */ - int count_sum_mb2; /* number of elements in sum_mb2 */ - int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ - struct list2 *sum_mb2; /* array of coefficients and pointers to sources and - targets for mass balance summations with coef != 1.0 */ - int count_sum_jacob2; /* number of elements in sum_jacob2 */ - int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ - struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and - targets, coef != 1.0 */ - int count_sum_delta; /* number of elements in sum_delta */ - int max_sum_delta; /* calculated maximum number of elements in sum_delta */ - struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for - summing deltas for mass balance equations */ - /*---------------------------------------------------------------------- - * Solution - *---------------------------------------------------------------------- */ - std::map Rxn_solution_map; - std::vector unnumbered_solutions; - - /*---------------------------------------------------------------------- - * Global solution - *---------------------------------------------------------------------- */ - char *title_x; - int new_x; - char *description_x; - LDBLE tc_x; - LDBLE tk_x; - LDBLE patm_x; - bool numerical_fixed_volume; - bool force_numerical_fixed_volume; - bool switch_numerical; - LDBLE ph_x; - LDBLE solution_pe_x; - LDBLE mu_x; - LDBLE ah2o_x; - LDBLE density_x; - LDBLE total_h_x; - LDBLE total_o_x; - LDBLE cb_x; - LDBLE total_ions_x; - LDBLE mass_water_aq_x; - LDBLE mass_water_surfaces_x; - LDBLE mass_water_bulk_x; - char *units_x; - std::map < std::string, cxxChemRxn > pe_x; - std::map isotopes_x; - std::string default_pe_x; - cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; - LDBLE total_carbon; - LDBLE total_co2; - LDBLE total_alkalinity; - LDBLE gfw_water; - LDBLE step_x; - LDBLE kin_time_x; - - /*---------------------------------------------------------------------- - * Transport data - *---------------------------------------------------------------------- */ - int count_cells; - int count_shifts; - int ishift; - int bcon_first; - int bcon_last; - int correct_disp; - LDBLE tempr; - LDBLE timest; - int simul_tr; - LDBLE diffc; - LDBLE heat_diffc; - int cell; - LDBLE mcd_substeps; - struct stag_data *stag_data; - int print_modulus; - int punch_modulus; - int dump_in; - int dump_modulus; - int transport_warnings; - struct cell_data *cell_data; - int multi_Dflag; /* signals calc'n of multicomponent diffusion */ - int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ - LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ - LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ - LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ - LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ - LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ - LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, - Dp = Dw * (multi_Dpor)^multi_Dn */ - LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, - Dpil = Dw / interlayer_tortf */ - - int cell_no; - /*---------------------------------------------------------------------- - * Advection data - *---------------------------------------------------------------------- */ - int count_ad_cells; - int count_ad_shifts; - int print_ad_modulus; - int punch_ad_modulus; - int *advection_punch, *advection_print; - LDBLE advection_kin_time; - LDBLE advection_kin_time_defined; - int advection_warnings; - - /*---------------------------------------------------------------------- - * Tidy data - *---------------------------------------------------------------------- */ - int new_model, new_exchange, new_pp_assemblage, new_surface, - new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, - new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, - new_pitzer; - - /*---------------------------------------------------------------------- - * Elements - *---------------------------------------------------------------------- */ - - struct element **elements; - int count_elements; - int max_elements; - struct element *element_h_one; - - /*---------------------------------------------------------------------- - * Element List - *---------------------------------------------------------------------- */ - - struct elt_list *elt_list; /* structure array of working space while reading equations - names are in "strings", initially in input order */ - int count_elts; /* number of elements in elt_list = position of next */ - int max_elts; - /*---------------------------------------------------------------------- - * Reaction - *---------------------------------------------------------------------- */ - - /*---------------------------------------------------------------------- - * Species - *---------------------------------------------------------------------- */ - - struct logk **logk; - int count_logk; - int max_logk; - - char *moles_per_kilogram_string; - char *pe_string; - - struct species **s; - int count_s; - int max_s; - std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; - - struct species **s_x; - int count_s_x; - int max_s_x; - - struct species *s_h2o; - struct species *s_hplus; - struct species *s_h3oplus; - struct species *s_eminus; - struct species *s_co3; - struct species *s_h2; - struct species *s_o2; - - /*---------------------------------------------------------------------- - * Phases - *---------------------------------------------------------------------- */ - struct phase **phases; - int count_phases; - int max_phases; - - /*---------------------------------------------------------------------- - * Master species - *---------------------------------------------------------------------- */ - struct master **master; /* structure array of master species */ - struct master **dbg_master; - int count_master; - int max_master; - - /*---------------------------------------------------------------------- - * Unknowns - *---------------------------------------------------------------------- */ - - struct unknown **x; - int count_unknowns; - int max_unknowns; - - struct unknown *ah2o_unknown; - struct unknown *alkalinity_unknown; - struct unknown *carbon_unknown; - struct unknown *charge_balance_unknown; - struct unknown *exchange_unknown; - struct unknown *mass_hydrogen_unknown; - struct unknown *mass_oxygen_unknown; - struct unknown *mb_unknown; - struct unknown *mu_unknown; - struct unknown *pe_unknown; - struct unknown *ph_unknown; - struct unknown *pure_phase_unknown; - struct unknown *solution_phase_boundary_unknown; - struct unknown *surface_unknown; - struct unknown *gas_unknown; - struct unknown *slack_unknown; - struct unknown *ss_unknown; - std::vector gas_unknowns; - - /*---------------------------------------------------------------------- - * Reaction work space - *---------------------------------------------------------------------- */ - struct reaction_temp trxn; /* structure array of working space while reading equations - species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; - - struct unknown_list *mb_unknowns; - int count_mb_unknowns; - int max_mb_unknowns; - - /* ---------------------------------------------------------------------- - * Print - * ---------------------------------------------------------------------- */ - struct prints pr; - bool status_on; - clock_t status_interval; - clock_t status_timer; - int count_warnings; - - /* ---------------------------------------------------------------------- - * RATES - * ---------------------------------------------------------------------- */ - struct rate *rates; - int count_rates; - LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, - rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; - std::vector rate_p; - int count_rate_p; - - /* ---------------------------------------------------------------------- - * USER PRINT COMMANDS - * ---------------------------------------------------------------------- */ - struct rate *user_print; - struct rate *user_punch; - const char **user_punch_headings; - int user_punch_count_headings; - int n_user_punch_index; - -#if defined PHREEQ98 - struct rate *user_graph; - char **user_graph_headings; - int user_graph_count_headings; -#endif -#if defined MULTICHART - ChartHandler chart_handler; -#endif - - /* ---------------------------------------------------------------------- - * GLOBAL DECLARATIONS - * ---------------------------------------------------------------------- */ - const char * error_string; - int simulation; - int state; - int reaction_step; - int transport_step; - int transport_start; - int advection_step; - int stop_program; - int incremental_reactions; - - int count_strings; - int max_strings; - - LDBLE *array; - LDBLE *delta; - LDBLE *residual; - - int input_error; - - Keywords::KEYWORDS next_keyword; - int parse_error; - int paren_count; - int iterations; - int gamma_iterations; - int run_reactions_iterations; - - int max_line; - char *line; - char *line_save; - - LDBLE LOG_10; - - int debug_model; - int debug_prep; - int debug_set; - int debug_diffuse_layer; - int debug_inverse; - - LDBLE inv_tol_default; - int itmax; - int max_tries; - LDBLE ineq_tol; - LDBLE convergence_tolerance; - LDBLE step_size; - LDBLE pe_step_size; - LDBLE step_size_now; - LDBLE pe_step_size_now; - LDBLE pp_scale; - LDBLE pp_column_scale; - int diagonal_scale; /* 0 not used, 1 used */ - int mass_water_switch; - int delay_mass_water; - bool dampen_ah2o; - bool slack; - LDBLE censor; - int aqueous_only; - int negative_concentrations; - int calculating_deriv; - int numerical_deriv; - - int count_total_steps; - int phast; - LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; - int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, - llnl_count_co2_coefs; - - char *selected_output_file_name; - char *dump_file_name; - int remove_unstable_phases; - std::string screen_string; -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif - - /* ---------------------------------------------------------------------- */ - /* - * Hash definitions - */ - - std::map strings_map; -#ifdef HASH - std::hash_map strings_hash; -#endif - HashTable *elements_hash_table; - HashTable *species_hash_table; - HashTable *phases_hash_table; - HashTable *logk_hash_table; - HashTable *master_isotope_hash_table; - -#if defined(PHREEQCI_GUI) -#include "../../phreeqci_gui.h" -#endif /* defined(PHREEQCI_GUI) */ - /* ---------------------------------------------------------------------- - * ISOTOPES - * ---------------------------------------------------------------------- */ - struct name_coef match_tokens[50]; - int count_match_tokens; - int count_master_isotope; - struct master_isotope **master_isotope; - int max_master_isotope; - int initial_solution_isotopes; - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; - HashTable *calculate_value_hash_table; - int count_isotope_ratio; - struct isotope_ratio **isotope_ratio; - int max_isotope_ratio; - HashTable *isotope_ratio_hash_table; - int count_isotope_alpha; - struct isotope_alpha **isotope_alpha; - int max_isotope_alpha; - HashTable *isotope_alpha_hash_table; - int phreeqc_mpi_myself; - int first_read_input; - char *user_database; - - int have_punch_name; - /* VP: Density Start */ - int print_density; - /* VP: Density End */ - - LDBLE *zeros; - int zeros_max; - - LDBLE cell_pore_volume; - LDBLE cell_porosity; - LDBLE cell_volume; - LDBLE cell_saturation; - struct system_species *sys; - int count_sys, max_sys; - LDBLE sys_tot; -#ifdef PHREEQC2 - LDBLE AA_basic, BB_basic, CC, I_m, rho_0; - LDBLE eps_r; // relative dielectric permittivity -#else - LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; - LDBLE eps_r; // relative dielectric permittivity - LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av -#endif - LDBLE solution_mass, solution_volume; - LDBLE f_rho(LDBLE rho_old); - - /* phqalloc.cpp ------------------------------- */ - PHRQMemHeader *s_pTail; - std::stringstream merged_database_stream; - std::stringstream merged_input_stream; - - /* Basic */ - PBasic * basic_interpreter; - - /* cl1.cpp ------------------------------- */ - LDBLE *x_arg, *res_arg, *scratch; - int x_arg_max, res_arg_max, scratch_max; - - /* dw.cpp ------------------------------- */ - /* COMMON /QQQQ/ */ - LDBLE Q0, Q5; - LDBLE GASCON, TZ, AA; - LDBLE Z, DZ, Y; - LDBLE G1, G2, GF; - LDBLE B1, B2, B1T, B2T, B1TT, B2TT; - - /* input.cpp ------------------------------- */ - int add_char_to_line(int *i, char c); - int check_line_impl(const char *string, int allow_empty, - int allow_eof, int allow_keyword, int print); - int get_line(void); - int get_logical_line(void *cookie, int *l); - int read_database(void); - int run_simulations(void); - int check_line_return; - int reading_db; - - /* integrate.cpp ------------------------------- */ - LDBLE midpoint_sv; - LDBLE z_global, xd_global, alpha_global; - int max_row_count, max_column_count; - int carbon; - const char **col_name, **row_name; - int count_rows, count_optimize; - int col_phases, col_redox, col_epsilon, col_ph, col_water, - col_isotopes, col_phase_isotopes; - int row_mb, row_fract, row_charge, row_carbon, row_isotopes, - row_epsilon, row_isotope_epsilon, row_water; - LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, - *delta_save; - LDBLE *min_delta, *max_delta; - int *iu, *is; - int klmd, nklmd, n2d, kode, iter; - LDBLE toler, error, max_pct, scaled_error; - struct master *master_alk; - int *row_back, *col_back; - unsigned long *good, *bad, *minimal; - int max_good, max_bad, max_minimal; - int count_good, count_bad, count_minimal, count_calls; - unsigned long soln_bits, phase_bits, current_bits, temp_bits; - - /* inverse.cpp ------------------------------- */ - FILE *netpath_file; - int count_inverse_models, count_pat_solutions; - int min_position[32], max_position[32], now[32]; - - /* kinetics.cpp ------------------------------- */ -public: - void *cvode_kinetics_ptr; - int cvode_test; - int cvode_error; - int cvode_n_user; - int cvode_n_reactions; - realtype cvode_step_fraction; - realtype cvode_rate_sim_time; - realtype cvode_rate_sim_time_start; - realtype cvode_last_good_time; - realtype cvode_prev_good_time; - N_Vector cvode_last_good_y; - N_Vector cvode_prev_good_y; - M_Env kinetics_machEnv; - N_Vector kinetics_y, kinetics_abstol; - void *kinetics_cvode_mem; - cxxSSassemblage *cvode_ss_assemblage_save; - cxxPPassemblage *cvode_pp_assemblage_save; - LDBLE *m_original; - LDBLE *m_temp; - int set_and_run_attempt; - - /* model.cpp ------------------------------- */ - LDBLE min_value; - LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; - int *inv_iu, *inv_is, *back_eq; - int normal_max, ineq_array_max, res_max, cu_max, zero_max, - delta1_max, iu_max, is_max, back_eq_max; - - /* phrq_io_output.cpp ------------------------------- */ - int forward_output_to_log; - - /* phreeqc_files.cpp ------------------------------- */ - char *default_data_base; -#ifdef PHREEQ98 - int outputlinenr; - char *LogFileNameC; - char progress_str[512]; -#endif - - /* Pitzer */ - int pitzer_model, sit_model, pitzer_pe; - int full_pitzer, always_full_pitzer, ICON, IC; - LDBLE COSMOT; - LDBLE AW; - LDBLE VP, DW0; - struct pitz_param **pitz_params; - int count_pitz_param, max_pitz_param; - struct pitz_param **sit_params; - int count_sit_param, max_sit_param; - int DW(LDBLE T); - LDBLE DC(LDBLE T); - struct theta_param **theta_params; - int count_theta_param, max_theta_param; - int use_etheta; - LDBLE OTEMP; - LDBLE A0; - struct species **spec, **cations, **anions, **neutrals; - int count_cations, count_anions, count_neutrals; - int MAXCATIONS, FIRSTANION, MAXNEUTRAL; - struct pitz_param *mcb0, *mcb1, *mcc0; - int *IPRSNT; - LDBLE *M, *LGAMMA; - LDBLE BK[23], DK[23]; - -#ifdef PHREEQ98 - int connect_simulations, graph_initial_solutions; - int shifts_as_points; - int chart_type; - int ShowChart; - int RowOffset, ColumnOffset; -#endif - LDBLE dummy; - - /* print.cpp ------------------------------- */ -#ifdef PHREEQ98 - int colnr, rownr; - int graph_initial_solutions; - int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ - /* int shifts_as_points; */ - int chart_type; - int AddSeries; - int FirstCallToUSER_GRAPH; -#endif - - /* read.cpp */ - char *prev_next_char; -#if defined PHREEQ98 - int shifts_as_points; -#endif - - /* read_class.cxx */ - dumper dump_info; - StorageBinList delete_info; - runner run_info; - char * sformatf_buffer; - size_t sformatf_buffer_size; - - /* readtr.cpp */ - std::string dump_file_name_cpp; - - /* sit.cpp ------------------------------- */ - LDBLE sit_A0; - int sit_count_cations, sit_count_anions, sit_count_neutrals; - int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; - int *sit_IPRSNT; - LDBLE *sit_M, *sit_LGAMMA; - - /* tidy.cpp ------------------------------- */ - LDBLE a0, a1, kc, kb; - - /* tally.cpp ------------------------------- */ - struct tally_buffer *t_buffer; - int tally_count_component; - struct tally *tally_table; - int count_tally_table_columns; - int count_tally_table_rows; - - /* transport.cpp ------------------------------- */ - struct sol_D *sol_D; - struct sol_D *sol_D_dbg; - struct J_ij *J_ij, *J_ij_il; - int J_ij_count_spec; - - struct M_S *m_s; - int count_m_s; - LDBLE tot1_h, tot1_o, tot2_h, tot2_o; - LDBLE diffc_max, diffc_tr, J_ij_sum; - int transp_surf; - LDBLE *heat_mix_array; - LDBLE *temp1, *temp2; - int nmix, heat_nmix; - LDBLE heat_mix_f_imm, heat_mix_f_m; - int warn_MCD_X, warn_fixed_Surf; - -#ifdef PHREEQ98 - int AutoLoadOutputFile, CreateToC; - int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; - int outputlinenr; - int stop_calculations; - char err_str98[80]; -#endif - - friend class PBasic; - friend class ChartObject; - friend class IPhreeqc; - friend class TestIPhreeqc; - friend class TestSelectedOutput; - - std::vector keycount; // used to mark keywords that have been read - -#endif /* _INC_PHREEQC_H */ -#ifndef _INC_ISFINITE_H -#define _INC_ISFINITE_H - /********************************* - isfinite handling - (Note: Should NOT be guarded) - **********************************/ - -#if defined (PHREEQ98) || defined (_MSC_VER) -# define HAVE_FINITE -# define finite _finite -#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ -# if defined(DJGPP) -# define HAVE_FINITE -# endif -#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ - -#if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) -#elif defined(HAVE_FINITE) -# define PHR_ISFINITE(x) finite(x) -#elif defined(HAVE_ISNAN) -# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) -#else -# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) -#endif - -public: - static const struct const_iso iso_defaults[]; - static const int count_iso_defaults; -}; -#endif diff --git a/phreeqc/pitzer.cpp b/phreeqc/pitzer.cpp index 78d1e558..62174214 100644 --- a/phreeqc/pitzer.cpp +++ b/phreeqc/pitzer.cpp @@ -581,7 +581,7 @@ read_pitzer(void) * number of cells; * number of shifts; */ - int n, j; + int n; struct pitz_param *pzp_ptr; pitz_param_type pzp_type; @@ -636,35 +636,7 @@ read_pitzer(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - j = pitz_param_search(pzp_ptr); - if (j < 0) - { - if (count_pitz_param >= max_pitz_param) - { - space((void **) ((void *) &pitz_params), - count_pitz_param, &max_pitz_param, - sizeof(struct pitz_param *)); - } - - pitz_params[count_pitz_param] = pzp_ptr; - count_pitz_param++; - } - else - { - if (pitz_params[j]->species[2] != NULL) - { - error_string = sformatf( "Redefinition of parameter, %s %s %s\n", - pitz_params[j]->species[0], pitz_params[j]->species[1], pitz_params[j]->species[2]); - } - else - { - error_string = sformatf( "Redefinition of parameter, %s %s\n", - pitz_params[j]->species[0], pitz_params[j]->species[1]); - } - warning_msg(error_string); - pitz_params[j] = (struct pitz_param *) free_check_null(pitz_params[j]); - pitz_params[j] = pzp_ptr; - } + pitz_param_store(pzp_ptr); } break; case OPTION_ERROR: @@ -1882,12 +1854,7 @@ model_pz(void) || remove_unstable_phases == TRUE) { #if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == - WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } + PhreeqcIWait(this); #endif iterations++; if (iterations > itmax - 1 && debug_model == FALSE diff --git a/phreeqc/pitzer_structures.cpp b/phreeqc/pitzer_structures.cpp index 6414089e..d8149a70 100644 --- a/phreeqc/pitzer_structures.cpp +++ b/phreeqc/pitzer_structures.cpp @@ -1,6 +1,8 @@ #include "Phreeqc.h" #include "phqalloc.h" +#include +#include /* ********************************************************************** * @@ -132,11 +134,9 @@ pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr) return (OK); } -#include -#include /* ---------------------------------------------------------------------- */ -int Phreeqc:: -pitz_param_search(struct pitz_param *pzp_ptr) +void Phreeqc:: +pitz_param_store(struct pitz_param *pzp_ptr) /* ---------------------------------------------------------------------- */ { /* @@ -145,56 +145,57 @@ pitz_param_search(struct pitz_param *pzp_ptr) */ int i; if (pzp_ptr == NULL) - return -1; + return; if (pzp_ptr->type == TYPE_Other) - return -1; - - std::list new_parm; + return; + std::set< std::string > header; for (i = 0; i < 3; i++) { - if (pzp_ptr->species[i] != NULL) new_parm.push_back(pzp_ptr->species[i]); + if (pzp_ptr->species[i] != NULL) header.insert(pzp_ptr->species[i]); } - new_parm.sort(); + std::string key; + std::set< std::string >::iterator it = header.begin(); + for(; it != header.end(); ++it) + { + key += (*it); + key += " "; + } + std::map< std::string, size_t>::iterator jit = pitz_param_map.find(key); + if (jit != pitz_param_map.end()) + { + if (pzp_ptr->species[2] != NULL) + { + error_string = sformatf( "Redefinition of parameter, %s %s %s\n", + pzp_ptr->species[0], pzp_ptr->species[1], pzp_ptr->species[2]); + } + else + { + error_string = sformatf( "Redefinition of parameter, %s %s\n", + pzp_ptr->species[0], pzp_ptr->species[1]); + } + warning_msg(error_string); + pitz_params[(*jit).second] = (struct pitz_param *) free_check_null(pitz_params[(*jit).second]); + pitz_params[(*jit).second] = pzp_ptr; + } + else + { + if (count_pitz_param >= max_pitz_param) + { + space((void **) ((void *) &pitz_params), + count_pitz_param, &max_pitz_param, + sizeof(struct pitz_param *)); + } - for (i = 0; i < count_pitz_param; i++) - { - if (pitz_params[i]->type != pzp_ptr->type) continue; - std::list old_parm; - int j; - for (j = 0; j < 3; j++) - { - if (pitz_params[i]->species[j] != NULL) old_parm.push_back(pitz_params[i]->species[j]); - } - old_parm.sort(); - if (old_parm.size() != new_parm.size()) continue; - bool found = true; - std::list::iterator nit = new_parm.begin(); - std::list::iterator oit = old_parm.begin(); - while (nit != new_parm.end()) - { - if (*nit != *oit) - { - found = false; - break; - } - nit++; - oit++; - } - if (found) break; + pitz_params[count_pitz_param] = pzp_ptr; + pitz_param_map[key] = count_pitz_param; + count_pitz_param++; } - if (i >= count_pitz_param) - { - return -1; - } - return i; } - -#include /* ---------------------------------------------------------------------- */ -int Phreeqc:: -sit_param_search(struct pitz_param *pzp_ptr) +void Phreeqc:: +sit_param_store(struct pitz_param *pzp_ptr) /* ---------------------------------------------------------------------- */ { /* @@ -203,49 +204,52 @@ sit_param_search(struct pitz_param *pzp_ptr) */ int i; if (pzp_ptr == NULL) - return -1; + return; if (pzp_ptr->type == TYPE_Other) - return -1; - - std::list new_parm; + return; + std::set< std::string > header; for (i = 0; i < 3; i++) { - if (pzp_ptr->species[i] != NULL) new_parm.push_back(pzp_ptr->species[i]); + if (pzp_ptr->species[i] != NULL) header.insert(pzp_ptr->species[i]); } - new_parm.sort(); + std::string key; + std::set< std::string >::iterator it = header.begin(); + for(; it != header.end(); ++it) + { + key += (*it); + key += " "; + } + std::map< std::string, size_t>::iterator jit = sit_param_map.find(key); + if (jit != sit_param_map.end()) + { + if (pzp_ptr->species[2] != NULL) + { + error_string = sformatf( "Redefinition of parameter, %s %s %s\n", + pzp_ptr->species[0], pzp_ptr->species[1], pzp_ptr->species[2]); + } + else + { + error_string = sformatf( "Redefinition of parameter, %s %s\n", + pzp_ptr->species[0], pzp_ptr->species[1]); + } + warning_msg(error_string); + sit_params[(*jit).second] = (struct pitz_param *) free_check_null(sit_params[(*jit).second]); + sit_params[(*jit).second] = pzp_ptr; + } + else + { + if (count_sit_param >= max_sit_param) + { + space((void **) ((void *) &sit_params), + count_sit_param, &max_sit_param, + sizeof(struct pitz_param *)); + } - for (i = 0; i < count_sit_param; i++) - { - if (sit_params[i]->type != pzp_ptr->type) continue; - std::list old_parm; - int j; - for (j = 0; j < 3; j++) - { - if (sit_params[i]->species[j] != NULL) old_parm.push_back(sit_params[i]->species[j]); - } - old_parm.sort(); - if (old_parm.size() != new_parm.size()) continue; - bool found = true; - std::list::iterator nit = new_parm.begin(); - std::list::iterator oit = old_parm.begin(); - while (nit != new_parm.end()) - { - if (*nit != *oit) - { - found = false; - break; - } - nit++; - oit++; - } - if (found) break; + sit_params[count_sit_param] = pzp_ptr; + sit_param_map[key] = count_sit_param; + count_sit_param++; } - if (i >= count_sit_param) - { - return -1; - } - return i; } /* ********************************************************************** diff --git a/phreeqc/sit.cpp b/phreeqc/sit.cpp index 4cf20b09..f224eac9 100644 --- a/phreeqc/sit.cpp +++ b/phreeqc/sit.cpp @@ -159,7 +159,7 @@ read_sit(void) * number of cells; * number of shifts; */ - int n, j; + int n; struct pitz_param *pzp_ptr; pitz_param_type pzp_type; @@ -198,24 +198,7 @@ read_sit(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - j = sit_param_search(pzp_ptr); - if (j < 0) - { - if (count_sit_param >= max_sit_param) - { - space((void **) ((void *) &sit_params), - count_sit_param, &max_sit_param, - sizeof(struct pitz_param *)); - } - - sit_params[count_sit_param] = pzp_ptr; - count_sit_param++; - } - else - { - sit_params[j] = (struct pitz_param *) free_check_null(sit_params[j]); - sit_params[j] = pzp_ptr; - } + sit_param_store(pzp_ptr); } break; case OPTION_ERROR: @@ -993,12 +976,7 @@ model_sit(void) || remove_unstable_phases == TRUE) { #if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == - WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } + PhreeqcIWait(this); #endif iterations++; if (iterations > itmax - 1 && debug_model == FALSE diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index f58cd1f3..ef51063a 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -1123,7 +1123,11 @@ strcmp_nocase_arg1(const char *str1, const char *str2) /* ---------------------------------------------------------------------- */ char * Phreeqc:: +#if _DEBUG +_string_duplicate(const char *token, const char *szFileName, int nLine) +#else string_duplicate(const char *token) +#endif /* ---------------------------------------------------------------------- */ { int l; @@ -1132,7 +1136,12 @@ string_duplicate(const char *token) if (token == NULL) return NULL; l = (int) strlen(token); +#if _DEBUG + str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); +#else str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); +#endif + if (str == NULL) malloc_error(); strcpy(str, token); From 4309bd451a226d3f6961dd85e69bd1b06a128535 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Apr 2012 04:08:00 +0000 Subject: [PATCH 0466/1077] minor cleanup of reading code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6392 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/input.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/phreeqc/input.cpp b/phreeqc/input.cpp index 9198f198..f0ed1419 100644 --- a/phreeqc/input.cpp +++ b/phreeqc/input.cpp @@ -27,8 +27,6 @@ check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print) /* ---------------------------------------------------------------------- */ { - if (phrq_io->get_istream() == NULL) - return EOF; if (reading_database()) print = FALSE; return check_line_impl(string, allow_empty, allow_eof, allow_keyword, From ac861bde626ae08bebc61ff03acbfe2dcb9f0613 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Apr 2012 04:10:11 +0000 Subject: [PATCH 0467/1077] replaced WaitForSingleObject w/ PhreeqcIWait; git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6393 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/integrate.cpp | 7 +------ phreeqc/model.cpp | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/phreeqc/integrate.cpp b/phreeqc/integrate.cpp index 194db5a4..1d6c080b 100644 --- a/phreeqc/integrate.cpp +++ b/phreeqc/integrate.cpp @@ -382,12 +382,7 @@ midpnt(LDBLE x1, LDBLE x2, int n) for (j = 1; j <= it; j++) { #if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == - WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } + PhreeqcIWait(this); #endif sum += g_function(xv); xv += ddel; diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 3d824a95..0e612918 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -91,12 +91,7 @@ model(void) || remove_unstable_phases == TRUE) { #if defined(PHREEQCI_GUI) - if (WaitForSingleObject(g_hKill /*g_eventKill */ , 0) == - WAIT_OBJECT_0) - { - error_msg("Execution canceled by user.", CONTINUE); - RaiseException(USER_CANCELED_RUN, 0, 0, NULL); - } + PhreeqcIWait(this); #endif iterations++; old_mu = mu_x; From 4d8f789347ee979d2e2b181ef7a69e7d262012e8 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Apr 2012 04:13:11 +0000 Subject: [PATCH 0468/1077] added memory cleanup code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6394 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 416e2776..cac4f7a2 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -757,6 +757,7 @@ get_line(void) { std::ostringstream errstr; errstr << "Could not open include file " << file_name; + delete next_stream; #if defined(PHREEQCI_GUI) warning_msg(errstr.str().c_str()); continue; From 07fdb2cb33161bc474d13d355c3ffc846dca8877 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Apr 2012 04:14:27 +0000 Subject: [PATCH 0469/1077] added memory cleanup code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6395 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 633007e3..fdbefe11 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -3206,6 +3206,8 @@ read_mix(void) temp_mix.Set_n_user(n_user); temp_mix.Set_n_user_end(n_user); temp_mix.Set_description(description); + free_check_null(description); + /* * Set use data to first read */ @@ -4352,6 +4354,7 @@ read_selected_output(void) input_error++; error_msg(error_string, CONTINUE); } + selected_output_file_name = (char*)free_check_null(selected_output_file_name); selected_output_file_name = string_duplicate(file_name); } opt_save = OPTION_ERROR; @@ -6940,6 +6943,7 @@ read_surface(void) if (ptr1 != NULL) ptr1[0] = '\0'; charge_ptr = temp_surface.Find_charge(name); + formula = (char*)free_check_null(formula); if (charge_ptr == NULL) { cxxSurfaceCharge temp_charge; @@ -6959,6 +6963,7 @@ read_surface(void) charge_ptr = temp_surface.Find_charge(name); } comp_ptr->Set_charge_name(name); + name = (char*)free_check_null(name); /* * Read surface area (m2/g) */ From cce0fe2547877ff0391952ee2bc050496adeff0e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 00:00:13 +0000 Subject: [PATCH 0470/1077] fix for level 4 warning level git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6437 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.cxx | 4 ++-- phreeqc/read.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 5604fb2f..5d8981af 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -59,7 +59,7 @@ cxxNumKeyword::read_number_description(CParser & parser) if (::isdigit(parser.get_iss().peek()) || parser.get_iss().peek() == '-') { parser.get_iss() >> this->n_user; - char ch = parser.get_iss().peek(); + char ch = (char)parser.get_iss().peek(); if (ch == '-') { parser.get_iss() >> ch; // eat '-' @@ -104,7 +104,7 @@ cxxNumKeyword::read_number_description(std::istream & is) if (::isdigit(is.peek())) { is >> this->n_user; - char ch = is.peek(); + char ch = (char)is.peek(); if (ch == '-') { is >> ch; // eat '-' diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index fdbefe11..7b71c062 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -2149,7 +2149,7 @@ read_kinetics(void) ptr = next_char; bool have_name = false; std::string name; - LDBLE coef; + LDBLE coef = 1; while (copy_token(token, &ptr) != EMPTY) { coef = 1; From 969e5df5f64a5e88e1ca8e44644f27a040c5507c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 01:43:06 +0000 Subject: [PATCH 0471/1077] trying to recover Phreeqc.h w/ history git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6444 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1863 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1863 insertions(+) create mode 100644 Phreeqc.h diff --git a/Phreeqc.h b/Phreeqc.h new file mode 100644 index 00000000..96d08488 --- /dev/null +++ b/Phreeqc.h @@ -0,0 +1,1863 @@ +#ifndef _INC_PHREEQC_H +#define _INC_PHREEQC_H +#if defined(WIN32) +#include +#endif +#if defined(WIN32_MEMORY_DEBUG) +#define _CRTDBG_MAP_ALLOC +#include +#endif +/* ---------------------------------------------------------------------- +* INCLUDE FILES +* ---------------------------------------------------------------------- */ +#include +#include +#include +#include +#ifdef HASH +#include +#endif +#include +#include +#include +#include +#include +#include +#include "phrqtype.h" +#include "cvdense.h" +#include "runner.h" +#include "dumper.h" +#include "PHRQ_io.h" +#ifdef MULTICHART +#include "ChartHandler.h" +#endif +#include "Keywords.h" +#include "Pressure.h" +#include "cxxMix.h" +#include "Use.h" +#include "Surface.h" + +class cxxNameDouble; +class cxxKinetics; +//class cxxMix; +class cxxKineticsComp; +class cxxExchange; +class cxxExchComp; +class cxxGasPhase; +class cxxTemperature; +class cxxPPassemblage; +class cxxPPassemblageComp; +class cxxReaction; +class cxxSolution; +class cxxISolutionComp; +class cxxSolutionIsotope; +class cxxSSassemblage; +class cxxSS; +class cxxStorageBin; + +#include "global_structures.h" +class PBasic; + +class Phreeqc +{ +public: + Phreeqc(PHRQ_io *io = NULL); + ~Phreeqc(void); + +public: + // + // Phreeqc class methods + // + + // advection.cpp ------------------------------- + int advection(void); + + // basicsubs.cpp ------------------------------- + int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); + int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); + void basic_free(void); + + LDBLE activity(const char *species_name); + LDBLE activity_coefficient(const char *species_name); + LDBLE log_activity_coefficient(const char *species_name); + LDBLE calc_SC(void); + /* VP: Density Start */ + LDBLE calc_dens(void); + /* VP: Density End */ + LDBLE calc_logk_n(const char *name); + LDBLE calc_logk_p(const char *name); + LDBLE calc_logk_s(const char *name); + LDBLE calc_surface_charge(const char *surface_name); + LDBLE diff_layer_total(const char *total_name, const char *surface_name); + LDBLE equi_phase(const char *phase_name); + LDBLE find_gas_comp(const char *gas_comp_name); + LDBLE find_gas_p(void); + LDBLE find_gas_vm(void); + LDBLE find_misc1(const char *ss_name); + LDBLE find_misc2(const char *ss_name); + LDBLE find_ss_comp(const char *ss_comp_name); + LDBLE get_calculate_value(const char *name); + char * iso_unit(const char *total_name); + LDBLE iso_value(const char *total_name); + LDBLE kinetics_moles(const char *kinetics_name); + LDBLE log_activity(const char *species_name); + LDBLE log_molality(const char *species_name); + LDBLE molality(const char *species_name); + LDBLE pressure(void); + LDBLE pr_pressure(const char *phase_name); + LDBLE pr_phi(const char *phase_name); + LDBLE saturation_ratio(const char *phase_name); + int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); + LDBLE solution_sum_secondary(const char *total_name); + LDBLE sum_match_gases(const char *stemplate, const char *name); + LDBLE sum_match_species(const char *stemplate, const char *name); + LDBLE sum_match_ss(const char *stemplate, const char *name); + int match_elts_in_species(const char *name, const char *stemplate); + int extract_bracket(char **string, char *bracket_string); + LDBLE surf_total(const char *total_name, const char *surface_name); + static int system_species_compare(const void *ptr1, const void *ptr2); + LDBLE system_total(const char *total_name, LDBLE * count, char ***names, + char ***types, LDBLE ** moles); + std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); + LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); + int system_total_elements(void); + int system_total_si(void); + int system_total_aq(void); + int system_total_ex(void); + int system_total_surf(void); + int system_total_gas(void); + int system_total_ss(void); + int system_total_elt(const char *total_name); + int system_total_elt_secondary(const char *total_name); + LDBLE total(const char *total_name); + LDBLE total_mole(const char *total_name); + int system_total_solids(cxxExchange *exchange_ptr, + cxxPPassemblage *pp_assemblage_ptr, + cxxGasPhase *gas_phase_ptr, + cxxSSassemblage *ss_assemblage_ptr, + cxxSurface *surface_ptr); + + static LDBLE f_rho(LDBLE rho_old, void *cookie); + static LDBLE f_Vm(LDBLE v1, void *cookie); + // chart.cpp +#if defined PHREEQ98 + void DeleteCurves(void); + void ExtractCurveInfo(char *line, int curvenr); + void GridChar(char *s, char *a); + void MallocCurves(int nc, int ncxy); + int OpenCSVFile(char file_name[MAX_LENGTH]); + void SaveCurvesToFile(char file_name[MAX_LENGTH]); + void PlotXY(char *x, char *y); + void ReallocCurves(int new_nc); + void ReallocCurveXY(int i); + void SetAxisScale(char *a, int j, char *token, int true_); + void SetAxisTitles(char *s, int i); + void SetChartTitle(char *s); + void start_chart(bool end); +#endif + + // cl1.cpp ------------------------------- + int cl1(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q, + int *kode, LDBLE toler, + int *iter, LDBLE * x, LDBLE * res, LDBLE * error, + LDBLE * cu, int *iu, int *s, int check); + void cl1_space(int check, int n2d, int klm, int nklmd); + + // cl1mp.cpp ------------------------------- + int cl1mp(int k, int l, int m, int n, + int nklmd, int n2d, + LDBLE * q_arg, + int *kode, LDBLE toler, + int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error, + LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg); + + // class_main.cpp ------------------------------- + int write_banner(void); + + /* default.cpp */ +public: + int close_input_files(void); + int close_output_files(void); + static int istream_getc(void *cookie); + int process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log); + + /* PHRQ_io_output.cpp */ + void screen_msg(const char * str); + + void echo_msg(const char *err_str); + int warning_msg(const char *err_str); + void set_forward_output_to_log(int value); + int get_forward_output_to_log(void); + + // dump_ostream + bool dump_open(const char *file_name); + void dump_flush(void); + void dump_close(void); + void dump_msg(const char * str); + + // log_ostream + bool log_open(const char *file_name); + void log_flush(void); + void log_close(void); + void log_msg(const char * str); + + // error_ostream + bool error_open(const char *file_name); + void error_flush(void); + void error_close(void); + void error_msg(const char * str, bool stop=false); + + // output_ostream + bool output_open(const char *file_name); + void output_flush(void); + void output_close(void); + void output_msg(const char * str); + + // punch_ostream + bool punch_open(const char *file_name); + void punch_flush(void); + void punch_close(void); + void punch_msg(const char * str); + + void fpunchf_heading(const char *name); + void fpunchf(const char *name, const char *format, double d); + void fpunchf(const char *name, const char *format, char * d); + void fpunchf(const char *name, const char *format, int d); + void fpunchf_user(int user_index, const char *format, double d); + void fpunchf_user(int user_index, const char *format, char * d); + int fpunchf_end_row(const char *format); + + // dw.cpp ------------------------------- + int BB(LDBLE T); + LDBLE PS(LDBLE T); + LDBLE VLEST(LDBLE T); + int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); + int QQ(LDBLE T, LDBLE D); + LDBLE BASE(LDBLE D); + + // input.cpp ------------------------------- + int reading_database(void); + void set_reading_database(int reading_database); + int check_line(const char *string, int allow_empty, int allow_eof, + int allow_keyword, int print); + + // integrate.cpp ------------------------------- + int calc_all_g(void); + int calc_init_g(void); + int initial_surface_water(void); + int sum_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr1); + int calc_all_donnan(void); + int calc_init_donnan(void); + LDBLE g_function(LDBLE x_value); + LDBLE midpnt(LDBLE x1, LDBLE x2, int n); + void polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, + LDBLE * dy); + LDBLE qromb_midpnt(cxxSurfaceCharge *charge_ptr, LDBLE x1, LDBLE x2); + LDBLE calc_psi_avg(cxxSurfaceCharge *charge_ptr, LDBLE surf_chrg_eq); + int calc_all_donnan_music(void); + int calc_init_donnan_music(void); + + // inverse.cpp ------------------------------- + int inverse_models(void); + int add_to_file(const char *filename, const char *string); + int bit_print(unsigned long bits, int l); + int carbon_derivs(struct inverse *inv_ptr); + int check_isotopes(struct inverse *inv_ptr); + int check_solns(struct inverse *inv_ptr); + int count_isotope_unknowns(struct inverse *inv_ptr, + struct isotope **isotope_unknowns); + cxxSolutionIsotope *get_isotope(cxxSolution *solution_ptr, const char *elt); + LDBLE get_inv_total(cxxSolution *solution_ptr, const char *elt); + int isotope_balance_equation(struct inverse *inv_ptr, int row, int n); + int post_mortem(void); + bool test_cl1_solution(void); + unsigned long get_bits(unsigned long bits, int position, int number); + unsigned long minimal_solve(struct inverse *inv_ptr, + unsigned long minimal_bits); + void dump_netpath(struct inverse *inv_ptr); + int dump_netpath_pat(struct inverse *inv_ptr); + int next_set_phases(struct inverse *inv_ptr, int first_of_model_size, + int model_size); + int phase_isotope_inequalities(struct inverse *inv_ptr); + int print_model(struct inverse *inv_ptr); + int punch_model_heading(struct inverse *inv_ptr); + int punch_model(struct inverse *inv_ptr); + void print_isotope(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total(FILE * netpath_file, cxxSolution *solution_ptr, + const char *elt, const char *string); + void print_total_multi(FILE * netpath_file, cxxSolution *solution_ptr, + const char *string, const char *elt0, + const char *elt1, const char *elt2, const char *elt3, + const char *elt4); + + void print_total_pat(FILE * netpath_file, const char *elt, + const char *string); + int range(struct inverse *inv_ptr, unsigned long cur_bits); + int save_bad(unsigned long bits); + int save_good(unsigned long bits); + int save_minimal(unsigned long bits); + unsigned long set_bit(unsigned long bits, int position, int value); + int setup_inverse(struct inverse *inv_ptr); + int set_initial_solution(int n_user_old, int n_user_new); + int set_ph_c(struct inverse *inv_ptr, + int i, cxxSolution *soln_ptr_orig, int n_user_new, + LDBLE d_alk, LDBLE ph_factor, LDBLE alk_factor); + int shrink(struct inverse *inv_ptr, LDBLE * array_in, + LDBLE * array_out, int *k, int *l, int *m, int *n, + unsigned long cur_bits, LDBLE * delta_l, int *col_back_l, + int *row_back_l); + int solve_inverse(struct inverse *inv_ptr); + int solve_with_mask(struct inverse *inv_ptr, unsigned long cur_bits); + int subset_bad(unsigned long bits); + int subset_minimal(unsigned long bits); + int superset_minimal(unsigned long bits); + int write_optimize_names(struct inverse *inv_ptr); + + // isotopes.cpp ------------------------------- + int add_isotopes(cxxSolution &solution_ptr); + int calculate_values(void); + int calculate_isotope_moles(struct element *elt_ptr, + cxxSolution *solution_ptr, LDBLE total_moles); + LDBLE convert_isotope(struct master_isotope *master_isotope_ptr, LDBLE ratio); + int from_pcil(struct master_isotope *master_isotope_ptr); + int from_permil(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_pct(struct master_isotope *master_isotope_ptr, LDBLE major_total); + int from_tu(struct master_isotope *master_isotope_ptr); + struct calculate_value *calculate_value_alloc(void); + int calculate_value_free(struct calculate_value *calculate_value_ptr); + struct calculate_value *calculate_value_search(const char *name); + struct calculate_value *calculate_value_store(const char *name, + int replace_if_found); + struct isotope_alpha *isotope_alpha_alloc(void); + struct isotope_alpha *isotope_alpha_search(const char *name); + struct isotope_alpha *isotope_alpha_store(const char *name, + int replace_if_found); + struct isotope_ratio *isotope_ratio_alloc(void); + struct isotope_ratio *isotope_ratio_search(const char *name); + struct isotope_ratio *isotope_ratio_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_store(const char *name, + int replace_if_found); + struct master_isotope *master_isotope_alloc(void); + struct master_isotope *master_isotope_search(const char *name); + int print_initial_solution_isotopes(void); + int print_isotope_ratios(void); + int print_isotope_alphas(void); + int punch_isotopes(void); + int punch_calculate_values(void); + int read_calculate_values(void); + int read_isotopes(void); + int read_isotope_ratios(void); + int read_isotope_alphas(void); + int calculate_value_init(struct calculate_value *calculate_value_ptr); + int isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr); + int isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr); + int master_isotope_init(struct master_isotope *master_isotope_ptr); + + // kinetics.cpp ------------------------------- + void cvode_init(void); + int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); + int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, + LDBLE step_fraction); + int set_advection(int i, int use_mix, int use_kinetics, int nsaver); + int free_cvode(void); +public: + static void f(integertype N, realtype t, N_Vector y, N_Vector ydot, + void *f_data); + static void Jac(integertype N, DenseMat J, RhsFn f, void *f_data, realtype t, + N_Vector y, N_Vector fy, N_Vector ewt, realtype h, + realtype uround, void *jac_data, long int *nfePtr, + N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3); + + int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); + int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, + LDBLE time_step); + int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, + LDBLE step_fraction); + int set_reaction(int i, int use_mix, int use_kinetics); + int set_transport(int i, int use_mix, int use_kinetics, int nsaver); + int store_get_equi_reactants(int k, int kin_end); + int count_pp, count_pg, count_ss; + LDBLE *x0_moles; + + // mainsubs.cpp ------------------------------- + std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); + int copy_entities(void); + void initialize(void); + int initial_exchangers(int print); + int initial_gas_phases(int print); + int initial_solutions(int print); + int step_save_exch(int n_user); + int step_save_surf(int n_user); + int initial_surfaces(int print); + int reactions(void); + int saver(void); + int xsolution_save(int k_user); + int xexchange_save(int n_user); + int xgas_save(int n_user); + int xpp_assemblage_save(int n_user); + int xss_assemblage_save(int n_user); + int xsurface_save(int n_user); + int do_initialize(void); + int do_status(void); + void save_init(int i); + int copy_use(int i); + int set_use(void); + + // model.cpp ------------------------------- + int check_residuals(void); + int free_model_allocs(void); + int ineq(int kode); + int model(void); + int jacobian_sums(void); + int mb_gases(void); + int mb_ss(void); + int mb_sums(void); + int molalities(int allow_overflow); + int reset(void); + int residuals(void); + int set(int initial); + int sum_species(void); + int surface_model(void); + LDBLE ss_root(LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, LDBLE xcaq, + LDBLE xbaq); + LDBLE ss_halve(LDBLE a0, LDBLE a1, LDBLE x0, LDBLE x1, LDBLE kc, + LDBLE kb, LDBLE xcaq, LDBLE xbaq); + LDBLE ss_f(LDBLE xb, LDBLE a0, LDBLE a1, LDBLE kc, LDBLE kb, + LDBLE xcaq, LDBLE xbaq); + int numerical_jacobian(void); + void set_inert_moles(void); + void unset_inert_moles(void); +#ifdef SLNQ + int add_trivial_eqns(int rows, int cols, LDBLE * matrix); + //int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +#endif + int calc_gas_pressures(void); + int calc_fixed_volume_gas_pressures(void); + int calc_ss_fractions(void); + int gammas(LDBLE mu); + int initial_guesses(void); + int revise_guesses(void); + int ss_binary(cxxSS *ss_ptr); + int ss_ideal(cxxSS *ss_ptr); + int gas_in; + void ineq_init(int max_row_count, int max_column_count); + + // parse.cpp ------------------------------- + int check_eqn(int association); + int get_charge(char *charge, LDBLE * z); + int get_elt(char **t_ptr, char *element, int *i); + int get_elts_in_species(char **t_ptr, LDBLE coef); + int get_num(char **t_ptr, LDBLE * num); + int get_secondary_in_species(char **t_ptr, LDBLE coef); + int parse_eq(char *eqn, struct elt_list **elt_ptr, int association); + int get_coef(LDBLE * coef, char **eqnaddr); + int get_secondary(char **t_ptr, char *element, int *i); + int get_species(char **ptr); + + // phqalloc.cpp ------------------------------- +public: +#if !defined(NDEBUG) + void *PHRQ_malloc(size_t, const char *, int); + void *PHRQ_calloc(size_t, size_t, const char *, int); + void *PHRQ_realloc(void *, size_t, const char *, int); +#else + void *PHRQ_malloc(size_t); + void *PHRQ_calloc(size_t, size_t); + void *PHRQ_realloc(void *, size_t); +#endif + void PHRQ_free(void *ptr); + void PHRQ_free_all(void); + +public: + + // pitzer.cpp ------------------------------- + struct pitz_param *pitz_param_read(char *string, int n); + int pitz_param_search(struct pitz_param *pzp_ptr); + int sit_param_search(struct pitz_param *pzp_ptr); + struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); + struct theta_param *theta_param_alloc(void); + int theta_param_init(struct theta_param *theta_param_ptr); + int gammas_pz(void); + int model_pz(void); + int pitzer(void); + int pitzer_clean_up(void); + int pitzer_init(void); + int pitzer_tidy(void); + int read_pitzer(void); + int set_pz(int initial); + int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_pz(void); + int ISPEC(const char *name); + LDBLE G(LDBLE Y); + LDBLE GP(LDBLE Y); + int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, + LDBLE * ethetap); + int BDK(LDBLE X); + int pitzer_initial_guesses(void); + int pitzer_revise_guesses(void); + int PTEMP(LDBLE TK); + LDBLE JAY(LDBLE X); + LDBLE JPRIME(LDBLE Y); + int jacobian_pz(void); + + // pitzer_structures.cpp ------------------------------- + struct pitz_param *pitz_param_alloc(void); + int pitz_param_init(struct pitz_param *pitz_param_ptr); + struct pitz_param *pitz_param_duplicate(struct pitz_param *old_ptr); + int pitz_param_copy(struct pitz_param *old_ptr, + struct pitz_param *new_ptr); + + // prep.cpp ------------------------------- + int add_potential_factor(void); + int add_cd_music_factors(int n); + int add_surface_charge_balance(void); + int add_cd_music_charge_balances(int i); + int build_gas_phase(void); + int build_fixed_volume_gas(void); + int build_jacobian_sums(int k); + int build_mb_sums(void); + int build_min_exch(void); + int build_model(void); + int build_pure_phases(void); + int build_ss_assemblage(void); + int build_solution_phase_boundaries(void); + int build_species_list(int n); + int build_min_surface(void); + LDBLE calc_lk_phase(phase * p_ptr, LDBLE TK, LDBLE pa); + LDBLE calc_delta_v(reaction * r_ptr, bool phase); + LDBLE calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m); + LDBLE calc_PR(); + int calc_vm(LDBLE tc, LDBLE pa); + int change_hydrogen_in_elt_list(LDBLE charge); + int clear(void); + //int convert_units(struct solution *solution_ptr); + int convert_units(cxxSolution *solution_ptr); + LDBLE a_aa_sum, b2, b_sum, R_TK; + LDBLE f_Vm(LDBLE v1); + struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); + struct master **get_list_master_ptrs(char *ptr, + struct master *master_ptr); + int inout(void); + int is_special(struct species *spec); + int mb_for_species_aq(int n); + int mb_for_species_ex(int n); + int mb_for_species_surf(int n); + int quick_setup(void); + int resetup_master(void); + int save_model(void); + int setup_exchange(void); + int setup_gas_phase(void); + int setup_fixed_volume_gas(void); + int setup_slack(void); + int setup_master_rxn(struct master **master_ptr_list, + const std::string &pe_rxn); + int setup_pure_phases(void); + int adjust_setup_pure_phases(void); + int setup_related_surface(void); + int setup_ss_assemblage(void); + int setup_solution(void); + int adjust_setup_solution(void); + int setup_surface(void); + int setup_unknowns(void); + int store_dn(int k, LDBLE * source, int row, LDBLE coef_in, + LDBLE * gamma_source); + int store_jacob(LDBLE * source, LDBLE * target, LDBLE coef); + int store_jacob0(int row, int column, LDBLE coef); + int store_mb(LDBLE * source, LDBLE * target, LDBLE coef); + int store_mb_unknowns(struct unknown *unknown_ptr, LDBLE * LDBLE_ptr, + LDBLE coef, LDBLE * gamma_ptr); + int store_sum_deltas(LDBLE * source, LDBLE * target, LDBLE coef); + int tidy_redox(void); + struct master **unknown_alloc_master(void); + int write_mb_eqn_x(void); + int write_mb_for_species_list(int n); + int write_mass_action_eqn_x(int stop); + + int check_same_model(void); + int k_temp(LDBLE tc, LDBLE pa); + LDBLE k_calc(LDBLE * logk, LDBLE tempk, LDBLE presPa); + int prep(void); + int reprep(void); + int rewrite_master_to_secondary(struct master *master_ptr1, + struct master *master_ptr2); + int switch_bases(void); + int write_phase_sys_total(int n); + + // print.cpp ------------------------------- + char *sformatf(const char *format, ...); + int array_print(LDBLE * array_l, int row_count, int column_count, + int max_column_count); + int print_all(void); + int print_exchange(void); + int print_gas_phase(void); + int print_master_reactions(void); + int print_reaction(struct reaction *rxn_ptr); + int print_species(void); + int print_surface(void); + int print_user_print(void); + int punch_all(void); + int print_alkalinity(void); + int print_diffuse_layer(cxxSurfaceCharge *surface_charge_ptr); + int print_eh(void); + int print_reaction(void); + int print_kinetics(void); + int print_mix(void); + int print_pp_assemblage(void); + int print_ss_assemblage(void); + int print_saturation_indices(void); + int print_surface_cd_music(void); + int print_totals(void); + int print_using(void); + /*int print_user_print(void);*/ + int punch_gas_phase(void); + int punch_identifiers(void); + int punch_kinetics(void); + int punch_molalities(void); + int punch_activities(void); + int punch_pp_assemblage(void); + int punch_ss_assemblage(void); + int punch_saturation_indices(void); + int punch_totals(void); + int punch_user_punch(void); +#if defined MULTICHART + int punch_user_graph(void); +#endif + + // read.cpp ------------------------------- + int read_input(void); + int read_conc(cxxSolution *solution_ptr, int count_mass_balance, char *str); + int *read_list_ints_range(char **ptr, int *count_ints, int positive, + int *int_list); + int read_log_k_only(char *ptr, LDBLE * log_k); + int read_t_c_only(char *ptr, LDBLE *t_c); + int read_p_c_only(char *ptr, LDBLE * p_c); + int read_omega_only(char *ptr, LDBLE *omega); + int read_number_description(char *ptr, int *n_user, int *n_user_end, + char **description, int allow_negative=FALSE); + int check_key(const char *str); + int check_units(std::string &tot_units, bool alkalinity, bool check_compatibility, + const char *default_units, bool print); + int find_option(const char *item, int *n, const char **list, int count_list, + int exact); + int get_option(const char **opt_list, int count_opt_list, char **next_char); + int get_true_false(char *string, int default_value); + + int add_psi_master_species(char *token); + int read_advection(void); + int read_analytical_expression_only(char *ptr, LDBLE * log_k); + /* VP: Density Start */ + int read_millero_abcdef (char *ptr, LDBLE * abcdef); + /* VP: Density End */ + int read_copy(void); + int read_debug(void); + int read_delta_h_only(char *ptr, LDBLE * delta_h, + DELTA_H_UNIT * units); + int read_vm_only(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); + int read_llnl_aqueous_model_parameters(void); + int read_exchange(void); + int read_exchange_master_species(void); + int read_exchange_species(void); + int read_gas_phase(void); + int read_incremental_reactions(void); + int read_inverse(void); + int read_inv_balances(struct inverse *inverse_ptr, char *next_char); + int read_inv_isotopes(struct inverse *inverse_ptr, char *ptr); + int read_inv_phases(struct inverse *inverse_ptr, char *next_char); + int read_kinetics(void); + int read_line_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + int read_lines_doubles(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc, const char **opt_list, + int count_opt_list, int *opt); + LDBLE *read_list_doubles(char **ptr, int *count_doubles); + int *read_list_ints(char **ptr, int *count_ints, int positive); + int *read_list_t_f(char **ptr, int *count_ints); + int read_master_species(void); + int read_mix(void); + int read_named_logk(void); + int read_phases(void); + int read_print(void); + int read_pp_assemblage(void); + int read_rates(void); + int read_reaction(void); + int read_reaction_reactants(cxxReaction *reaction_ptr); + int read_reaction_steps(cxxReaction *reaction_ptr); + int read_solid_solutions(void); + int read_temperature(void); + int read_reaction_temps(struct temperature *temperature_ptr); + int read_reaction_pressure(void); + int read_reaction_pressure_raw(void); + int read_save(void); + int read_selected_output(void); + int read_solution(void); + int read_species(void); + int read_surface(void); + int read_surface_master_species(void); + int read_surface_species(void); + int read_use(void); + int read_title(void); + int read_user_print(void); + int read_user_punch(void); +#if defined PHREEQ98 + int read_user_graph(void); +#endif +#if defined MULTICHART + int read_user_graph_handler(); +#endif + int next_keyword_or_option(const char **opt_list, int count_opt_list); + int cleanup_after_parser(CParser &parser); + + // ReadClass.cxx + int read_dump(void); + int read_delete(void); + int read_run_cells(void); + int streamify_to_next_keyword(std::istringstream & lines); + int dump_entities(void); + int delete_entities(void); + int run_as_cells(void); + void dump_ostream(std::ostream& os); + + // readtr.cpp ------------------------------- + int read_transport(void); + int dump(void); + int dump_exchange(int k); + int dump_gas_phase(int k); + int dump_kinetics(int k); + int dump_mix(int k); + int dump_pp_assemblage(int k); + int dump_reaction(int k); + int dump_ss_assemblage(int k); + int dump_solution(int k); + int dump_surface(int k); + int dump_cpp(void); + int read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, + int *count_alloc); + + // sit.cpp ------------------------------- + int gammas_sit(void); + int model_sit(void); + int sit(void); + int sit_clean_up(void); + int sit_init(void); + int sit_tidy(void); + int read_sit(void); + int set_sit(int initial); + int calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); + int check_gammas_sit(void); + int sit_ISPEC(const char *name); + /*int DH_AB (LDBLE TK, LDBLE *A, LDBLE *B);*/ + int sit_initial_guesses(void); + int sit_revise_guesses(void); + int PTEMP_SIT(LDBLE tk); + int jacobian_sit(void); + + // spread.cpp ------------------------------- + int read_solution_spread(void); + int copy_token_tab(char *token_ptr, char **ptr, int *length); + int get_option_string(const char **opt_list, int count_opt_list, + char **next_char); + int spread_row_free(struct spread_row *spread_row_ptr); + int spread_row_to_solution(struct spread_row *heading, + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); + struct spread_row *string_to_spread_row(char *string); +#ifdef PHREEQCI_GUI + void add_row(struct spread_row *spread_row_ptr); + void copy_defaults(struct defaults *dest_ptr, + struct defaults *src_ptr); + void free_spread(void); + struct spread_row *copy_row(struct spread_row *spread_row_ptr); +#endif + + // step.cpp ------------------------------- + int step(LDBLE step_fraction); + int xsolution_zero(void); + int add_exchange(cxxExchange *exchange_ptr); + int add_gas_phase(cxxGasPhase *gas_phase_ptr); + int add_kinetics(cxxKinetics *kinetics_ptr); + int add_mix(cxxMix * mix_ptr); + int add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction); + int add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr); + int add_solution(cxxSolution *solution_ptr, LDBLE extensive, + LDBLE intensive); + int add_surface(cxxSurface *surface_ptr); + int check_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr); + int gas_phase_check(cxxGasPhase *gas_phase_ptr); + int pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr); + int reaction_calc(cxxReaction *reaction_ptr); + int solution_check(void); + int ss_assemblage_check(cxxSSassemblage *ss_assemblage_ptr); + + // structures.cpp ------------------------------- + int clean_up(void); + int reinitialize(void); + int copier_add(struct copier *copier_ptr, int n_user, int start, int end); + int copier_free(struct copier *copier_ptr); + int copier_init(struct copier *copier_ptr); + static int element_compare(const void *ptr1, const void *ptr2); +public: + struct element *element_store(const char *element); + int elt_list_combine(void); + static int elt_list_compare(const void *ptr1, const void *ptr2); +protected: + struct elt_list *elt_list_dup(struct elt_list *elt_list_ptr_old); + int elt_list_print(struct elt_list *elt_list_ptr); + struct elt_list *elt_list_save(void); + cxxNameDouble elt_list_NameDouble(void); +public: + enum entity_type get_entity_enum(char *name); + struct inverse *inverse_alloc(void); + int inverse_delete(int i); + static int inverse_isotope_compare(const void *ptr1, const void *ptr2); + struct inverse *inverse_search(int n_user, int *n); + int inverse_sort(void); +protected: + struct logk *logk_alloc(void); + int logk_copy2orig(struct logk *logk_ptr); + struct logk *logk_store(char *name, int replace_if_found); + struct logk *logk_search(const char *name); + struct master *master_alloc(void); + static int master_compare(const void *ptr1, const void *ptr2); + int master_delete(char *ptr); +public: + struct master *master_bsearch(const char *ptr); + struct master *master_bsearch_primary(const char *ptr); + struct master *master_bsearch_secondary(char *ptr); + struct master *master_search(char *ptr, int *n); + struct pe_data *pe_data_alloc(void); +public: + struct pe_data *pe_data_dup(struct pe_data *pe_ptr_old); + struct pe_data *pe_data_free(struct pe_data *pe_data_ptr); +protected: + int pe_data_store(struct pe_data **pe, const char *token); +public: + struct phase *phase_bsearch(const char *ptr, int *j, int print); +protected: + static int phase_compare(const void *ptr1, const void *ptr2); + int phase_delete(int i); + struct phase *phase_store(const char *name); +public: + struct rate *rate_bsearch(char *ptr, int *j); + int rate_free(struct rate *rate_ptr); + struct rate *rate_search(const char *name, int *n); + int rate_sort(void); + struct reaction *rxn_alloc(int ntokens); + struct reaction *rxn_dup(struct reaction *rxn_ptr_old); + LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); + int rxn_free(struct reaction *rxn_ptr); + int rxn_print(struct reaction *rxn_ptr); + static int s_compare(const void *ptr1, const void *ptr2); + int s_delete(int i); + struct species *s_search(const char *name); + struct species *s_store(const char *name, LDBLE z, int replace_if_found); +protected: + struct save_values *save_values_bsearch(struct save_values *k, int *n); + static int save_values_compare(const void *ptr1, const void *ptr2); + int save_values_sort(void); + int save_values_store(struct save_values *s_v); + static int isotope_compare(const void *ptr1, const void *ptr2); + static int species_list_compare_alk(const void *ptr1, const void *ptr2); + static int species_list_compare_master(const void *ptr1, const void *ptr2); + int species_list_sort(void); + struct Change_Surf *change_surf_alloc(int count); +public: + struct master *surface_get_psi_master(const char *name, int plane); + int system_duplicate(int i, int save_old); + int trxn_add(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine); + int trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine); + int trxn_combine(void); + int trxn_copy(struct reaction *rxn_ptr); + LDBLE trxn_find_coef(const char *str, int start); + int trxn_print(void); + int trxn_reverse_k(void); + int trxn_sort(void); + int trxn_swap(const char *token); + struct unknown *unknown_alloc(void); + int unknown_delete(int i); + int unknown_free(struct unknown *unknown_ptr); + int entity_exists(char *name, int n_user); + static int inverse_compare(const void *ptr1, const void *ptr2); + int inverse_free(struct inverse *inverse_ptr); + static int kinetics_compare_int(const void *ptr1, const void *ptr2); + int logk_init(struct logk *logk_ptr); + static int master_compare_string(const void *ptr1, const void *ptr2); + int master_free(struct master *master_ptr); + struct phase *phase_alloc(void); + static int phase_compare_string(const void *ptr1, const void *ptr2); + int phase_free(struct phase *phase_ptr); + int phase_init(struct phase *phase_ptr); + static int rate_compare(const void *ptr1, const void *ptr2); + static int rate_compare_string(const void *ptr1, const void *ptr2); + struct species *s_alloc(void); + int s_free(struct species *s_ptr); + int s_init(struct species *s_ptr); + static int ss_assemblage_compare_int(const void *ptr1, const void *ptr2); + static int solution_compare(const void *ptr1, const void *ptr2); + static int solution_compare_int(const void *ptr1, const void *ptr2); + static int species_list_compare(const void *ptr1, const void *ptr2); + static int surface_compare_int(const void *ptr1, const void *ptr2); + static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); + int trxn_multiply(LDBLE coef); +#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) + extern void MergeFinalize(void); +#endif + struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); + struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); + struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); + struct master * cxxNameDouble2surface_master(const cxxNameDouble * totals); + + void Use2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb); + void phreeqc2cxxStorageBin(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb, int n); + void cxxStorageBin2phreeqc(cxxStorageBin & sb); + + /* tally.cpp */ + void add_all_components_tally(void); + int build_tally_table(void); + int calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr); + int diff_tally_table(void); + int extend_tally_table(void); + int free_tally_table(void); + int fill_tally_table(int *n_user, int index_conservative, int n_buffer); + int get_tally_table_rows_columns(int *rows, int *columns); + int get_tally_table_column_heading(int column, int *type, char *string); + int get_tally_table_row_heading(int column, char *string); + int store_tally_table(LDBLE * array, int row_dim, int col_dim, + LDBLE fill_factor); + int zero_tally_table(void); + int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); + int get_all_components(void); + int print_tally_table(void); + int set_reaction_moles(int n_user, LDBLE moles); + int set_reaction_temperature(int n_user, LDBLE tc); + int set_kinetics_time(int n_user, LDBLE step); + + // tidy.cpp ------------------------------- + int add_other_logk(LDBLE * source_k, int count_add_logk, + struct name_coef *add_logk); + int add_logks(struct logk *logk_ptr, int repeats); + LDBLE halve(LDBLE f(LDBLE x, void *), LDBLE x0, LDBLE x1, LDBLE tol); + int replace_solids_gases(void); + int ss_prep(LDBLE t, cxxSS *ss_ptr, int print); + int select_log_k_expression(LDBLE * source_k, LDBLE * target_k); + int slnq(int n, LDBLE * a, LDBLE * delta, int ncols, int print); +public: + int tidy_punch(void); + int tidy_model(void); + int check_species_input(void); + LDBLE coef_in_master(struct master *master_ptr); + int phase_rxn_to_trxn(struct phase *phase_ptr, + struct reaction *rxn_ptr); + int reset_last_model(void); + int rewrite_eqn_to_primary(void); + int rewrite_eqn_to_secondary(void); + int species_rxn_to_trxn(struct species *s_ptr); + int tidy_logk(void); + int tidy_exchange(void); + int tidy_min_exchange(void); + int tidy_kin_exchange(void); + int tidy_gas_phase(void); + int tidy_inverse(void); + int tidy_isotopes(void); + int tidy_isotope_ratios(void); + int tidy_isotope_alphas(void); + int tidy_kin_surface(void); + int tidy_master_isotope(void); + int tidy_min_surface(void); + int tidy_phases(void); + int tidy_pp_assemblage(void); + int tidy_solutions(void); + int tidy_ss_assemblage(void); + int tidy_species(void); + int tidy_surface(void); + int scan(LDBLE f(LDBLE x, void *), LDBLE * xx0, LDBLE * xx1); + static LDBLE f_spinodal(LDBLE x, void *); + int solve_misc(LDBLE * xxc1, LDBLE * xxc2, LDBLE tol); + int ss_calc_a0_a1(cxxSS *ss_ptr); + + // transport.cpp ------------------------------- + int transport(void); + int set_initial_moles(int i); + cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, + cxxSurface *source2, std::string charge_name, LDBLE f2, + LDBLE new_Dw); + int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, + LDBLE new_Dw, int cell); + LDBLE viscosity(void); + int multi_D(LDBLE DDt, int mobile_cell, int stagnant); + int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); + int fill_spec(int cell_no); + int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); + static int sort_species_name(const void *ptr1, const void *ptr2); + int disp_surf(LDBLE stagkin_time); + int diff_stag_surf(int mobile_cell); + int check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2); + cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, + int n_user_new, + bool move_old); + int init_mix(void); + int init_heat_mix(int nmix); + int heat_mix(int heat_nmix); + int mix_stag(int i, LDBLE stagkin_time, int punch, + LDBLE step_fraction_kin); + + // utilities.cpp ------------------------------- +public: + int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list(const cxxNameDouble & nd, LDBLE coef); +protected: + int backspace_screen(int spaces); + LDBLE calc_alk(struct reaction *rxn_ptr); +public: + LDBLE calc_rho_0(LDBLE tc, LDBLE pa); + LDBLE calc_dielectrics(LDBLE tc, LDBLE pa); + int compute_gfw(const char *string, LDBLE * gfw); +#if defined PHREEQ98 + int copy_title(char *token_ptr, char **ptr, int *length); +#endif + int copy_token(char *token_ptr, char **ptr, int *length); + int copy_token(std::string &token, char **ptr); + int dup_print(const char *ptr, int emphasis); + int equal(LDBLE a, LDBLE b, LDBLE eps); +public: + void *free_check_null(void *ptr); +protected: + void free_hash_strings(HashTable * Table); + int get_token(char **eqnaddr, char *string, LDBLE * z, int *l); + int hcreate_multi(unsigned Count, HashTable ** HashTable_ptr); + void hdestroy_multi(HashTable * HashTable_ptr); + ENTRY *hsearch_multi(HashTable * Table, ENTRY item, ACTION action); + int islegit(const char c); +public: + void malloc_error(void); +protected: + int parse_couple(char *token); + int print_centered(const char *string); +public: + static int replace(const char *str1, const char *str2, char *str); + static bool replace(const char *str1, const char *str2, std::string & str); + static int strcmp_nocase(const char *str1, const char *str2); + static int strcmp_nocase_arg1(const char *str1, const char *str2); +protected: + void space(void **ptr, int i, int *max, int struct_size); + void squeeze_white(char *s_l); + int status(int count, const char *str, bool kinetics = false); + void str_tolower(char *str); + void str_toupper(char *str); +public: + char *string_duplicate(const char *token); + const char *string_hsave(const char *str); + void strings_map_clear(); +#ifdef HASH + void strings_hash_clear(); +#endif +protected: + char *string_pad(const char *str, int i); + int string_trim(char *str); + int string_trim_right(char *str); + int string_trim_left(char *str); + static LDBLE under(LDBLE xval); + void zero_double(LDBLE * target, int n); + int get_input_errors(void); +#ifdef PHREEQ98 + void AddToCEntry(char *a, int l, int i); + void ApplicationProcessMessages(void); + int copy_title(char *token_ptr, char **ptr, int *length); + extern int clean_up_null(void); +#endif + int isamong(char c, const char *s_l); + Address Hash_multi(HashTable * Table, const char *Key); + void ExpandTable_multi(HashTable * Table); +public: + int main_method(int argc, char *argv[]); + void set_phast(int); + size_t list_components(std::list &list_c); + PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} +protected: + void init(void); + + // + //Data members + // +protected: + PHRQ_io *phrq_io; + PHRQ_io ioInstance; + + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ + + struct model last_model; + int same_model; + int same_temperature; + int same_pressure; + bool same_mu; + struct punch punch; + /* ---------------------------------------------------------------------- + * Temperatures + * ---------------------------------------------------------------------- */ + + std::map Rxn_temperature_map; + + /* ---------------------------------------------------------------------- + * Pressures + * ---------------------------------------------------------------------- */ + std::map Rxn_pressure_map; + + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + + int g_iterations; + LDBLE G_TOL; + std::map Rxn_surface_map; + std::map charge_group_map; + int change_surf_count; + struct Change_Surf *change_surf; + + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + std::map Rxn_exchange_map; + + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + std::map Rxn_kinetics_map; + + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + int count_save_values; + struct save_values *save_values; + struct save save; + + /*---------------------------------------------------------------------- + * Use + *---------------------------------------------------------------------- */ + cxxUse use; + + /*---------------------------------------------------------------------- + * Copy + *---------------------------------------------------------------------- */ + struct copier copy_solution; + struct copier copy_pp_assemblage; + struct copier copy_exchange; + struct copier copy_surface; + struct copier copy_ss_assemblage; + struct copier copy_gas_phase; + struct copier copy_kinetics; + struct copier copy_mix; + struct copier copy_reaction; + struct copier copy_temperature; + struct copier copy_pressure; + + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + struct inverse *inverse; + int count_inverse; + + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + std::map Rxn_mix_map; + std::map Dispersion_mix_map; + + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + std::map Rxn_reaction_map; + + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + std::map Rxn_gas_phase_map; + + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + std::map Rxn_ss_assemblage_map; + + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + std::map Rxn_pp_assemblage_map; + + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + int count_species_list; + int max_species_list; + struct species_list *species_list; + + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + + int count_sum_jacob0; /* number of elements in sum_jacob0 */ + int max_sum_jacob0; /* calculated maximum number of elements in sum_jacob0 */ + struct list0 *sum_jacob0; /* array of pointers to targets and coefficients for array */ + + int count_sum_mb1; /* number of elements in sum_mb1 */ + int max_sum_mb1; /* calculated maximum number of elements in sum_mb1 */ + struct list1 *sum_mb1; /* array of pointers to sources and targets for mass + balance summations with coef = 1.0 */ + int count_sum_jacob1; /* number of elements in sum_jacob1 */ + int max_sum_jacob1; /* calculated maximum number of elements in sum_jacob1 */ + struct list1 *sum_jacob1; /* array of pointers to sources and targets for array + equations with coef = 1.0 */ + int count_sum_mb2; /* number of elements in sum_mb2 */ + int max_sum_mb2; /* calculated maximum number of elements in sum_mb2 */ + struct list2 *sum_mb2; /* array of coefficients and pointers to sources and + targets for mass balance summations with coef != 1.0 */ + int count_sum_jacob2; /* number of elements in sum_jacob2 */ + int max_sum_jacob2; /* calculated maximum number of elements in sum_jacob2 */ + struct list2 *sum_jacob2; /* array of coefficients and pointers to sources and + targets, coef != 1.0 */ + int count_sum_delta; /* number of elements in sum_delta */ + int max_sum_delta; /* calculated maximum number of elements in sum_delta */ + struct list2 *sum_delta; /* array of pointers to sources, targets and coefficients for + summing deltas for mass balance equations */ + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + std::map Rxn_solution_map; + std::vector unnumbered_solutions; + + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + char *title_x; + int new_x; + char *description_x; + LDBLE tc_x; + LDBLE tk_x; + LDBLE patm_x; + bool numerical_fixed_volume; + bool force_numerical_fixed_volume; + bool switch_numerical; + LDBLE ph_x; + LDBLE solution_pe_x; + LDBLE mu_x; + LDBLE ah2o_x; + LDBLE density_x; + LDBLE total_h_x; + LDBLE total_o_x; + LDBLE cb_x; + LDBLE total_ions_x; + LDBLE mass_water_aq_x; + LDBLE mass_water_surfaces_x; + LDBLE mass_water_bulk_x; + char *units_x; + std::map < std::string, cxxChemRxn > pe_x; + std::map isotopes_x; + std::string default_pe_x; + cxxSurface::DIFFUSE_LAYER_TYPE dl_type_x; + LDBLE total_carbon; + LDBLE total_co2; + LDBLE total_alkalinity; + LDBLE gfw_water; + LDBLE step_x; + LDBLE kin_time_x; + + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + int count_cells; + int count_shifts; + int ishift; + int bcon_first; + int bcon_last; + int correct_disp; + LDBLE tempr; + LDBLE timest; + int simul_tr; + LDBLE diffc; + LDBLE heat_diffc; + int cell; + LDBLE mcd_substeps; + struct stag_data *stag_data; + int print_modulus; + int punch_modulus; + int dump_in; + int dump_modulus; + int transport_warnings; + struct cell_data *cell_data; + int multi_Dflag; /* signals calc'n of multicomponent diffusion */ + int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ + LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ + LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ + LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ + LDBLE interlayer_Dpor_lim; /* limiting interlayer porosity where transport stops */ + LDBLE multi_Dn; /* exponent to calculate pore water diffusion coefficient, + Dp = Dw * (multi_Dpor)^multi_Dn */ + LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, + Dpil = Dw / interlayer_tortf */ + + int cell_no; + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + int count_ad_cells; + int count_ad_shifts; + int print_ad_modulus; + int punch_ad_modulus; + int *advection_punch, *advection_print; + LDBLE advection_kin_time; + LDBLE advection_kin_time_defined; + int advection_warnings; + + /*---------------------------------------------------------------------- + * Tidy data + *---------------------------------------------------------------------- */ + int new_model, new_exchange, new_pp_assemblage, new_surface, + new_reaction, new_temperature, new_mix, new_solution, new_gas_phase, + new_inverse, new_punch, new_ss_assemblage, new_kinetics, new_copy, + new_pitzer; + + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + + struct element **elements; + int count_elements; + int max_elements; + struct element *element_h_one; + + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + + struct elt_list *elt_list; /* structure array of working space while reading equations + names are in "strings", initially in input order */ + int count_elts; /* number of elements in elt_list = position of next */ + int max_elts; + /*---------------------------------------------------------------------- + * Reaction + *---------------------------------------------------------------------- */ + + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + + struct logk **logk; + int count_logk; + int max_logk; + + char *moles_per_kilogram_string; + char *pe_string; + + struct species **s; + int count_s; + int max_s; + std::vector< std::map < std::string, cxxSpeciesDL > > s_diff_layer; + + struct species **s_x; + int count_s_x; + int max_s_x; + + struct species *s_h2o; + struct species *s_hplus; + struct species *s_h3oplus; + struct species *s_eminus; + struct species *s_co3; + struct species *s_h2; + struct species *s_o2; + + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + struct phase **phases; + int count_phases; + int max_phases; + + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + struct master **master; /* structure array of master species */ + struct master **dbg_master; + int count_master; + int max_master; + + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + + struct unknown **x; + int count_unknowns; + int max_unknowns; + + struct unknown *ah2o_unknown; + struct unknown *alkalinity_unknown; + struct unknown *carbon_unknown; + struct unknown *charge_balance_unknown; + struct unknown *exchange_unknown; + struct unknown *mass_hydrogen_unknown; + struct unknown *mass_oxygen_unknown; + struct unknown *mb_unknown; + struct unknown *mu_unknown; + struct unknown *pe_unknown; + struct unknown *ph_unknown; + struct unknown *pure_phase_unknown; + struct unknown *solution_phase_boundary_unknown; + struct unknown *surface_unknown; + struct unknown *gas_unknown; + struct unknown *slack_unknown; + struct unknown *ss_unknown; + std::vector gas_unknowns; + + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + struct reaction_temp trxn; /* structure array of working space while reading equations + species names are in "temp_strings" */ + int count_trxn; /* number of reactants in trxn = position of next */ + int max_trxn; + + struct unknown_list *mb_unknowns; + int count_mb_unknowns; + int max_mb_unknowns; + + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + struct prints pr; + bool status_on; + clock_t status_interval; + clock_t status_timer; + int count_warnings; + + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + struct rate *rates; + int count_rates; + LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, + rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; + std::vector rate_p; + int count_rate_p; + + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + struct rate *user_print; + struct rate *user_punch; + const char **user_punch_headings; + int user_punch_count_headings; + int n_user_punch_index; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + ChartHandler chart_handler; +#endif + + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + const char * error_string; + int simulation; + int state; + int reaction_step; + int transport_step; + int transport_start; + int advection_step; + int stop_program; + int incremental_reactions; + + int count_strings; + int max_strings; + + LDBLE *array; + LDBLE *delta; + LDBLE *residual; + + int input_error; + + Keywords::KEYWORDS next_keyword; + int parse_error; + int paren_count; + int iterations; + int gamma_iterations; + int run_reactions_iterations; + + int max_line; + char *line; + char *line_save; + + LDBLE LOG_10; + + int debug_model; + int debug_prep; + int debug_set; + int debug_diffuse_layer; + int debug_inverse; + + LDBLE inv_tol_default; + int itmax; + int max_tries; + LDBLE ineq_tol; + LDBLE convergence_tolerance; + LDBLE step_size; + LDBLE pe_step_size; + LDBLE step_size_now; + LDBLE pe_step_size_now; + LDBLE pp_scale; + LDBLE pp_column_scale; + int diagonal_scale; /* 0 not used, 1 used */ + int mass_water_switch; + int delay_mass_water; + bool dampen_ah2o; + bool slack; + LDBLE censor; + int aqueous_only; + int negative_concentrations; + int calculating_deriv; + int numerical_deriv; + + int count_total_steps; + int phast; + LDBLE *llnl_temp, *llnl_adh, *llnl_bdh, *llnl_bdot, *llnl_co2_coefs; + int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, + llnl_count_co2_coefs; + + char *selected_output_file_name; + char *dump_file_name; + int remove_unstable_phases; + std::string screen_string; +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ + + std::map strings_map; +#ifdef HASH + std::hash_map strings_hash; +#endif + HashTable *elements_hash_table; + HashTable *species_hash_table; + HashTable *phases_hash_table; + HashTable *logk_hash_table; + HashTable *master_isotope_hash_table; + +#if defined(PHREEQCI_GUI) +#include "../../phreeqci_gui.h" +#endif /* defined(PHREEQCI_GUI) */ + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + struct name_coef match_tokens[50]; + int count_match_tokens; + int count_master_isotope; + struct master_isotope **master_isotope; + int max_master_isotope; + int initial_solution_isotopes; + int count_calculate_value; + struct calculate_value **calculate_value; + int max_calculate_value; + HashTable *calculate_value_hash_table; + int count_isotope_ratio; + struct isotope_ratio **isotope_ratio; + int max_isotope_ratio; + HashTable *isotope_ratio_hash_table; + int count_isotope_alpha; + struct isotope_alpha **isotope_alpha; + int max_isotope_alpha; + HashTable *isotope_alpha_hash_table; + int phreeqc_mpi_myself; + int first_read_input; + char *user_database; + + int have_punch_name; + /* VP: Density Start */ + int print_density; + /* VP: Density End */ + + LDBLE *zeros; + int zeros_max; + + LDBLE cell_pore_volume; + LDBLE cell_porosity; + LDBLE cell_volume; + LDBLE cell_saturation; + struct system_species *sys; + int count_sys, max_sys; + LDBLE sys_tot; +#ifdef PHREEQC2 + LDBLE AA_basic, BB_basic, CC, I_m, rho_0; + LDBLE eps_r; // relative dielectric permittivity +#else + LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; + LDBLE eps_r; // relative dielectric permittivity + LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av +#endif + LDBLE solution_mass, solution_volume; + LDBLE f_rho(LDBLE rho_old); + + /* phqalloc.cpp ------------------------------- */ + PHRQMemHeader *s_pTail; + std::stringstream merged_database_stream; + std::stringstream merged_input_stream; + + /* Basic */ + PBasic * basic_interpreter; + + /* cl1.cpp ------------------------------- */ + LDBLE *x_arg, *res_arg, *scratch; + int x_arg_max, res_arg_max, scratch_max; + + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + LDBLE Q0, Q5; + LDBLE GASCON, TZ, AA; + LDBLE Z, DZ, Y; + LDBLE G1, G2, GF; + LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + + /* input.cpp ------------------------------- */ + int add_char_to_line(int *i, char c); + int check_line_impl(const char *string, int allow_empty, + int allow_eof, int allow_keyword, int print); + int get_line(void); + int get_logical_line(void *cookie, int *l); + int read_database(void); + int run_simulations(void); + int check_line_return; + int reading_db; + + /* integrate.cpp ------------------------------- */ + LDBLE midpoint_sv; + LDBLE z_global, xd_global, alpha_global; + int max_row_count, max_column_count; + int carbon; + const char **col_name, **row_name; + int count_rows, count_optimize; + int col_phases, col_redox, col_epsilon, col_ph, col_water, + col_isotopes, col_phase_isotopes; + int row_mb, row_fract, row_charge, row_carbon, row_isotopes, + row_epsilon, row_isotope_epsilon, row_water; + LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + *delta_save; + LDBLE *min_delta, *max_delta; + int *iu, *is; + int klmd, nklmd, n2d, kode, iter; + LDBLE toler, error, max_pct, scaled_error; + struct master *master_alk; + int *row_back, *col_back; + unsigned long *good, *bad, *minimal; + int max_good, max_bad, max_minimal; + int count_good, count_bad, count_minimal, count_calls; + unsigned long soln_bits, phase_bits, current_bits, temp_bits; + + /* inverse.cpp ------------------------------- */ + FILE *netpath_file; + int count_inverse_models, count_pat_solutions; + int min_position[32], max_position[32], now[32]; + + /* kinetics.cpp ------------------------------- */ +public: + void *cvode_kinetics_ptr; + int cvode_test; + int cvode_error; + int cvode_n_user; + int cvode_n_reactions; + realtype cvode_step_fraction; + realtype cvode_rate_sim_time; + realtype cvode_rate_sim_time_start; + realtype cvode_last_good_time; + realtype cvode_prev_good_time; + N_Vector cvode_last_good_y; + N_Vector cvode_prev_good_y; + M_Env kinetics_machEnv; + N_Vector kinetics_y, kinetics_abstol; + void *kinetics_cvode_mem; + cxxSSassemblage *cvode_ss_assemblage_save; + cxxPPassemblage *cvode_pp_assemblage_save; + LDBLE *m_original; + LDBLE *m_temp; + int set_and_run_attempt; + + /* model.cpp ------------------------------- */ + LDBLE min_value; + LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; + int *inv_iu, *inv_is, *back_eq; + int normal_max, ineq_array_max, res_max, cu_max, zero_max, + delta1_max, iu_max, is_max, back_eq_max; + + /* phrq_io_output.cpp ------------------------------- */ + int forward_output_to_log; + + /* phreeqc_files.cpp ------------------------------- */ + char *default_data_base; +#ifdef PHREEQ98 + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; +#endif + + /* Pitzer */ + int pitzer_model, sit_model, pitzer_pe; + int full_pitzer, always_full_pitzer, ICON, IC; + LDBLE COSMOT; + LDBLE AW; + LDBLE VP, DW0; + struct pitz_param **pitz_params; + int count_pitz_param, max_pitz_param; + struct pitz_param **sit_params; + int count_sit_param, max_sit_param; + int DW(LDBLE T); + LDBLE DC(LDBLE T); + struct theta_param **theta_params; + int count_theta_param, max_theta_param; + int use_etheta; + LDBLE OTEMP; + LDBLE A0; + struct species **spec, **cations, **anions, **neutrals; + int count_cations, count_anions, count_neutrals; + int MAXCATIONS, FIRSTANION, MAXNEUTRAL; + struct pitz_param *mcb0, *mcb1, *mcc0; + int *IPRSNT; + LDBLE *M, *LGAMMA; + LDBLE BK[23], DK[23]; + +#ifdef PHREEQ98 + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; +#endif + LDBLE dummy; + + /* print.cpp ------------------------------- */ +#ifdef PHREEQ98 + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; +#endif + + /* read.cpp */ + char *prev_next_char; +#if defined PHREEQ98 + int shifts_as_points; +#endif + + /* read_class.cxx */ + dumper dump_info; + StorageBinList delete_info; + runner run_info; + char * sformatf_buffer; + size_t sformatf_buffer_size; + + /* readtr.cpp */ + std::string dump_file_name_cpp; + + /* sit.cpp ------------------------------- */ + LDBLE sit_A0; + int sit_count_cations, sit_count_anions, sit_count_neutrals; + int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; + int *sit_IPRSNT; + LDBLE *sit_M, *sit_LGAMMA; + + /* tidy.cpp ------------------------------- */ + LDBLE a0, a1, kc, kb; + + /* tally.cpp ------------------------------- */ + struct tally_buffer *t_buffer; + int tally_count_component; + struct tally *tally_table; + int count_tally_table_columns; + int count_tally_table_rows; + + /* transport.cpp ------------------------------- */ + struct sol_D *sol_D; + struct sol_D *sol_D_dbg; + struct J_ij *J_ij, *J_ij_il; + int J_ij_count_spec; + + struct M_S *m_s; + int count_m_s; + LDBLE tot1_h, tot1_o, tot2_h, tot2_o; + LDBLE diffc_max, diffc_tr, J_ij_sum; + int transp_surf; + LDBLE *heat_mix_array; + LDBLE *temp1, *temp2; + int nmix, heat_nmix; + LDBLE heat_mix_f_imm, heat_mix_f_m; + int warn_MCD_X, warn_fixed_Surf; + +#ifdef PHREEQ98 + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; +#endif + + friend class PBasic; + friend class ChartObject; + friend class IPhreeqc; + friend class TestIPhreeqc; + friend class TestSelectedOutput; + + std::vector keycount; // used to mark keywords that have been read + +#endif /* _INC_PHREEQC_H */ +#ifndef _INC_ISFINITE_H +#define _INC_ISFINITE_H + /********************************* + isfinite handling + (Note: Should NOT be guarded) + **********************************/ + +#if defined (PHREEQ98) || defined (_MSC_VER) +# define HAVE_FINITE +# define finite _finite +#else /*defined (PHREEQ98) || defined (_MSC_VER)*/ +# if defined(DJGPP) +# define HAVE_FINITE +# endif +#endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ + +#if defined(HAVE_ISFINITE) +# define PHR_ISFINITE(x) isfinite(x) +#elif defined(HAVE_FINITE) +# define PHR_ISFINITE(x) finite(x) +#elif defined(HAVE_ISNAN) +# define PHR_ISFINITE(x) ( ((x) == 0.0) || ((!isnan(x)) && ((x) != (2.0 * (x)))) ) +#else +# define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) +#endif + +public: + static const struct const_iso iso_defaults[]; + static const int count_iso_defaults; +}; +#endif From e972c511f0693dcd83dfd2b8fb5317af074257ba Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 01:49:12 +0000 Subject: [PATCH 0472/1077] trying to recover Phreeqc.h w/ history this should have been -r 6391 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6445 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 96d08488..2df3a441 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -480,8 +480,8 @@ public: // pitzer.cpp ------------------------------- struct pitz_param *pitz_param_read(char *string, int n); - int pitz_param_search(struct pitz_param *pzp_ptr); - int sit_param_search(struct pitz_param *pzp_ptr); + void pitz_param_store(struct pitz_param *pzp_ptr); + void sit_param_store(struct pitz_param *pzp_ptr); struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); struct theta_param *theta_param_alloc(void); int theta_param_init(struct theta_param *theta_param_ptr); @@ -1058,7 +1058,11 @@ protected: void str_tolower(char *str); void str_toupper(char *str); public: +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + char *_string_duplicate(const char *token, const char *szFileName, int nLine); +#else char *string_duplicate(const char *token); +#endif const char *string_hsave(const char *str); void strings_map_clear(); #ifdef HASH @@ -1726,8 +1730,10 @@ public: LDBLE VP, DW0; struct pitz_param **pitz_params; int count_pitz_param, max_pitz_param; + std::map< std::string, size_t > pitz_param_map; struct pitz_param **sit_params; int count_sit_param, max_sit_param; + std::map< std::string, size_t > sit_param_map; int DW(LDBLE T); LDBLE DC(LDBLE T); struct theta_param **theta_params; @@ -1860,4 +1866,13 @@ public: static const struct const_iso iso_defaults[]; static const int count_iso_defaults; }; + +#if defined(PHREEQCI_GUI) +void PhreeqcIWait(Phreeqc *phreeqc); +#endif + +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) +#define string_duplicate(s) _string_duplicate(s, __FILE__, __LINE__) +#endif + #endif From 495a2200709e23881a72583a302116f9b1edbcba Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 02:21:16 +0000 Subject: [PATCH 0473/1077] merged in http://internalbrr.cr.usgs.gov/svn_GW/phreeqcpp/branches/ErrorHandling 6269-6445 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6446 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 250 ----------------------------- Makefile | 73 +++++++-- PHRQ_io.cpp | 21 +-- Phreeqc.h | 21 ++- phreeqc/basicsubs.cpp | 339 ++++++++++++++++++++++++++++++++++++++- phreeqc/cl1.cpp | 66 +++++++- phreeqc/cl1mp.cpp | 1 + phreeqc/gases.cpp | 25 +-- phreeqc/kinetics.cpp | 2 +- phreeqc/mainsubs.cpp | 21 ++- phreeqc/model.cpp | 111 +++++-------- phreeqc/pitzer.cpp | 15 +- phreeqc/prep.cpp | 84 +++++----- phreeqc/read.cpp | 358 ------------------------------------------ phreeqc/sit.cpp | 14 +- phreeqc/step.cpp | 1 - phreeqc/transport.cpp | 32 ++-- phreeqc/utilities.cpp | 12 +- 18 files changed, 630 insertions(+), 816 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 620cd9a2..e9e91b16 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -18,12 +18,8 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// -//static std::map ss_map; -//std::map& cxxISolution::s_map = ss_map; - cxxISolution::cxxISolution(PHRQ_io *io) : -//cxxSolution(io), units("mMol/kgw") { default_pe = "pe"; @@ -31,16 +27,8 @@ units("mMol/kgw") pe_reactions[default_pe] = temp_pe_reactions; } -//cxxISolution::cxxISolution(const cxxISolution *is_old) -//{ -// units = is_old->units; -// comps = is_old->comps; -// pe_reactions = is_old->pe_reactions; -// default_pe = is_old->default_pe; -//} cxxISolution::~cxxISolution() { - //// ToDo //pe_data_free(this->pes); } #ifdef SKIP_OR_MOVE_TO_STRUCTURES @@ -135,244 +123,6 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) } #endif -#ifdef SKIP -cxxISolution & cxxISolution::read(CParser & parser) -{ - static - std::vector < - std::string > - vopts; - if (vopts.empty()) - { - vopts.reserve(11); - vopts.push_back("temp"); // 0 - vopts.push_back("temperature"); // 1 - vopts.push_back("dens"); // 2 - vopts.push_back("density"); // 3 - vopts.push_back("units"); // 4 - vopts.push_back("redox"); // 5 - vopts.push_back("ph"); // 6 - vopts.push_back("pe"); // 7 - vopts.push_back("unit"); // 8 - vopts.push_back("isotope"); // 9 - vopts.push_back("water"); // 10 - } - // const int count_opt_list = vopts.size(); - - cxxISolution - numkey; - - // Read solution number and description - numkey.read_number_description(parser); - - // Malloc space for solution data - //// g_solution_map[numkey.n_user()] = numkey; - s_map[numkey.n_user()] = numkey; - - std::istream::pos_type ptr; - std::istream::pos_type next_char; - std::string token; - CParser::TOKEN_TYPE j; - - cxxISolution & sol = s_map[numkey.n_user()]; - int - default_pe = 0; - - for (;;) - { - int - opt = parser.get_option(vopts, next_char); - if (opt == CParser::OPTION_DEFAULT) - { - ptr = next_char; - if (parser.copy_token(token, ptr) == CParser::TT_DIGIT) - { - opt = 9; - } - } - - switch (opt) - { - case CParser::OPTION_EOF: - break; - case CParser::OPTION_KEYWORD: - break; - case CParser::OPTION_ERROR: - opt = CParser::OPTION_EOF; - CParser::error_msg("Unknown input in SOLUTION keyword.", - PHRQ_io::OT_CONTINUE); - CParser::error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - break; - - case 0: // temp - case 1: // temperature - if (!(parser.get_iss() >> sol.tc)) - { - sol.tc = 25; - } - break; - - case 2: // dens - case 3: // density - parser.get_iss() >> sol.density; - break; - - case 4: // units - case 8: // unit - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) - break; - if (parser.check_units(token, false, false, sol.units, true) == - CParser::OK) - { - sol.units = token; - } - else - { - parser.incr_input_error(); - } - break; - - case 5: // redox - if (parser.copy_token(token, next_char) == CParser::TT_EMPTY) - break; - if (parser.parse_couple(token) == CParser::OK) - { - default_pe = cxxPe_Data::store(sol.pe, token); - } - else - { - parser.incr_input_error(); - } - break; - - case 6: // ph - { - cxxISolutionComp - conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) - { - parser.incr_input_error(); - break; - } - sol.ph = conc.get_input_conc(); - if (conc.get_equation_name().empty()) - { - break; - } - conc.Set_description("H(1)"); - sol.add(conc); - } - break; - - case 7: // pe - { - cxxISolutionComp - conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) - { - parser.incr_input_error(); - break; - } - sol.solution_pe = conc.get_input_conc(); - if (conc.get_equation_name().empty()) - { - break; - } - conc.Set_description("E"); - sol.add(conc); - } - break; - - case 9: // isotope - { - cxxIsotope - isotope; - if (isotope.read(parser) == cxxIsotope::OK) - { - sol.add(isotope); - } - } - break; - - case 10: // water - j = parser.copy_token(token, next_char); - if (j == CParser::TT_EMPTY) - { - sol.mass_water = 1.0; - } - else if (j != CParser::TT_DIGIT) - { - parser.incr_input_error(); - parser. - error_msg - ("Expected numeric value for mass of water in solution.", - PHRQ_io::OT_CONTINUE); - } - else - { - std::istringstream(token) >> sol.mass_water; - } - break; - - case CParser::OPTION_DEFAULT: - { - // Read concentration - cxxISolutionComp - conc; - if (conc.read(parser, sol) == cxxISolutionComp::ERROR) - { - parser.incr_input_error(); - } - else - { - sol.add(conc); - } - } - break; - } - if (opt == CParser::OPTION_EOF || opt == CParser::OPTION_KEYWORD) - break; - } - // - // fix up default units and default pe - // - std::string token1; - std::vector < cxxISolutionComp >::iterator iter = sol.totals.begin(); - for (; iter != sol.totals.end(); ++iter) - { - token = (*iter).Get_description(); - Utilities::str_tolower(token); - if ((*iter).get_units().empty()) - { - (*iter).set_units(sol.units); - } - else - { - bool - alk = false; - if (token.find("alk") == 0) - alk = true; - token1 = (*iter).get_units(); - if (parser. - check_units(token1, alk, true, sol.get_units(), - true) == CParser::ERROR) - { - parser.incr_input_error(); - } - else - { - (*iter).set_units(token1); - } - } - if ((*iter).get_n_pe() < 0) - { - (*iter).set_n_pe(default_pe); - } - } - sol.default_pe = default_pe; - return sol; -} -#endif #ifdef SKIP void cxxISolution::dump_xml(std::ostream & os, unsigned int indent) const const diff --git a/Makefile b/Makefile index e39c6b96..2d29e5fb 100644 --- a/Makefile +++ b/Makefile @@ -32,10 +32,20 @@ Release: class_release release: class_release Class_release: class_release +Debug_64: class_debug_64 +debug_64: class_debug_64 +Class_debug_64: class_debug_64 -CLASS_DEBUG_DIR = Class_debug +Release_64: class_release_64 +release_64: class_release_64 +Class_release_64: class_release_64 + + +CLASS_DEBUG_DIR = Class_debug CLASS_DIR = Class_release -MAKEFILE = Makefile +CLASS_DEBUG_64_DIR = Class_debug_64 +CLASS_64_DIR = Class_release_64 +MAKEFILE = Makefile # ----------------------------------------------------------------------------- # fixes shared object lookup error(SIGFPE floating point exception) @@ -54,6 +64,15 @@ class_debug: class_release: mkdir -p $(CLASS_DIR) cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) +.PHONY : Class_debug_64 +class_debug_64: + mkdir -p $(CLASS_DEBUG_64_DIR) + cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) + +.PHONY : Class_release_64 +class_release_64: + mkdir -p $(CLASS_64_DIR) + cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) # Recursive make begins here # @@ -89,23 +108,23 @@ class_release: # ----------------------------------------------------------------------------- # #define gmp for inverse modeling # comment the following lines to remove multiprecision option -INVERSE_CL1MP=TRUE -ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o -# CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a -endif # ----------------------------------------------------------------------------- #efence for debugging EFENCE_LIB=-L$(HOME)/packages/efence # ----------------------------------------------------------------------------- -# 2 Versions +# 4 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC2 + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ @@ -115,12 +134,38 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC2 + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_DEBUG_64) + DEFINES = -DUSE_PHRQ_ALLOC # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE_64) + DEFINES = -DNDEBUG # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../phreeqc INCLUDES = -I../phreeqc -I.. CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) -# CXXFLAGS = -Wall -pedantic -p $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif @@ -927,7 +972,7 @@ utilities.o: ../phreeqc/utilities.cpp ../Utils.h ../Phreeqc.h \ ../ISolutionComp.h # ----------------------------------------------------------------------------- clean: - rm -rf Class_release Class_debug + rm -rf Class_release Class_debug Class_release_64 Class_debug_64 dependencies: mkdir -p $(CLASS_DEBUG_DIR) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index cac4f7a2..41691d94 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -13,11 +13,11 @@ PHRQ_io:: PHRQ_io(void) { - output_ostream = NULL; - log_ostream = NULL; + output_ostream = NULL; + log_ostream = NULL; punch_ostream = NULL; #ifdef ERROR_OSTREAM - error_ostream = NULL; + error_ostream = NULL; #else error_file = NULL; #endif @@ -237,7 +237,7 @@ warning_msg(const char *err_str) err_stdstr.append("\n"); screen_msg(err_stdstr.c_str()); error_ostream->flush(); - } + } std::ostringstream warn_str; warn_str << err_str << "\n"; log_msg(warn_str.str().c_str()); @@ -365,7 +365,7 @@ warning_msg(const char *err_str) err_stdstr.append("\n"); screen_msg(err_stdstr.c_str()); error_flush(); - } + } std::ostringstream warn_str; warn_str << err_str << "\n"; log_msg(warn_str.str().c_str()); @@ -709,7 +709,7 @@ get_line(void) this->accumulated.append("\n"); } // - // New line character encountered + // New line character encountered // return_value = (empty ? LT_EMPTY : LT_OK); @@ -717,7 +717,7 @@ get_line(void) if (continue_loop) continue; // // Determine return_value - // + // if (return_value == LT_OK) { if (check_key(m_line.begin(), m_line.end())) @@ -743,25 +743,26 @@ get_line(void) std::string::iterator end = m_line.end(); CParser::copy_token(stdtoken, beg, end); Utilities::str_tolower(stdtoken); - if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) || + if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) || (strstr(stdtoken.c_str(),"include_file") == stdtoken.c_str())) { std::string file_name; file_name.assign(beg, end); file_name = trim(file_name); - + if (file_name.size() > 0) { std::ifstream *next_stream = new std::ifstream(file_name.c_str(), std::ios_base::in); if (!next_stream->is_open()) { std::ostringstream errstr; - errstr << "Could not open include file " << file_name; + errstr << "\n*********** Could not open include file " << file_name << ". ***********\n\n"; delete next_stream; #if defined(PHREEQCI_GUI) warning_msg(errstr.str().c_str()); continue; #else + output_msg(errstr.str().c_str()); error_msg(errstr.str().c_str(), OT_STOP); #endif } diff --git a/Phreeqc.h b/Phreeqc.h index 2df3a441..b4e08ec8 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1099,17 +1099,23 @@ protected: protected: PHRQ_io *phrq_io; PHRQ_io ioInstance; + int same_model; + //int same_temperature; + //int same_pressure; + //bool same_mu; + + LDBLE current_tc; + LDBLE current_pa; + LDBLE current_mu; + bool mu_terms_in_logk; /* ---------------------------------------------------------------------- * STRUCTURES * ---------------------------------------------------------------------- */ struct model last_model; - int same_model; - int same_temperature; - int same_pressure; - bool same_mu; struct punch punch; + /* ---------------------------------------------------------------------- * Temperatures * ---------------------------------------------------------------------- */ @@ -1252,6 +1258,7 @@ protected: LDBLE tc_x; LDBLE tk_x; LDBLE patm_x; + LDBLE last_patm_x; bool numerical_fixed_volume; bool force_numerical_fixed_volume; bool switch_numerical; @@ -1573,8 +1580,8 @@ protected: /* ---------------------------------------------------------------------- * ISOTOPES * ---------------------------------------------------------------------- */ - struct name_coef match_tokens[50]; - int count_match_tokens; + //struct name_coef match_tokens[50]; + //int count_match_tokens; int count_master_isotope; struct master_isotope **master_isotope; int max_master_isotope; @@ -1614,7 +1621,7 @@ protected: LDBLE AA_basic, BB_basic, CC, I_m, rho_0; LDBLE eps_r; // relative dielectric permittivity #else - LDBLE V_solutes, rho_0, kappa_0, p_sat, ah2o_x0; + LDBLE V_solutes, rho_0, kappa_0, p_sat/*, ah2o_x0*/; LDBLE eps_r; // relative dielectric permittivity LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av #endif diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 9b9b5d3b..90c70d9b 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -1423,6 +1423,242 @@ int Phreeqc:: match_elts_in_species(const char *name, const char *mytemplate) /* ---------------------------------------------------------------------- */ { +/* + * Makes a list of elements with their coefficients, stores elements + * in elt_list at position count_elts. Global variable count_elts is + * updated with each stored element. Also uses static global variable + * paren_count. + * + * Arguments: + * **t_ptr input, point in token string to start looking + * output, is next position to start looking + * coef input, coefficient to multiply subscripts by + */ + int i, i1, l, case_no, match; + char c, c1; + char *ptr, *ptr1; + LDBLE d; + char element[MAX_LENGTH]; + char token[MAX_LENGTH], equal_list[MAX_LENGTH]; + char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH]; + char str[2]; + + strcpy(token, name); + squeeze_white(token); + replace("(+", "(", token); + if (strstr("token", "++") != NULL) + { + replace("++++++", "+6", token); + replace("+++++", "+5", token); + replace("++++", "+4", token); + replace("+++", "+3", token); + replace("++", "+2", token); + } + if (strstr("token", "--") != NULL) + { + replace("------", "-6", token); + replace("-----", "-5", token); + replace("----", "-4", token); + replace("---", "-3", token); + replace("--", "-2", token); + } + + ptr = token; + std::vector< std::pair > match_vector; + while ((c = *ptr) != '\0') + { + c1 = *(ptr + 1); + str[0] = c; + str[1] = '\0'; +/* + * New element + */ + if (isupper((int) c) || (c == 'e' && c1 == '-') || (c == '[')) + { + /* + * Get new element and subscript + */ + if (get_elt(&ptr, element, &l) == ERROR) + { + return (ERROR); + } + if (get_num(&ptr, &d) == ERROR) + { + return (ERROR); + } + std::pair pr(element, d); + match_vector.push_back(pr); + } + else + { + std::pair pr(str, 1.0); + match_vector.push_back(pr); + ptr += 1; + } + } + /* + * Replace elements with first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) + { + replace("{", "", equal_list); + replace("}", "", equal_list); + while (replace(",", " ", equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list from template + */ + std::string elt_name; + if (copy_token(elt_name, &ptr1) == EMPTY) + { + error_string = sformatf( + "Expecting a nonempty list of element names in isotope sum. %s", + mytemplate); + error_msg(error_string, CONTINUE); + return (ERROR); + } + std::string replace_name = elt_name; + /* + * Replace in species all equivalent names from template + */ + while (copy_token(elt_name, &ptr1) != EMPTY) + { + for (i = 0; i < (int) match_vector.size(); i++) + { + if (elt_name == match_vector[i].first) + { + match_vector[i].first = replace_name; + } + } + } + } + /* + * Combine contiguous elements + */ + i1 = 0; + for (i = 1; i < (int) match_vector.size(); i++) + { + if ((isupper((int) (match_vector[i].first[0])) != FALSE) + && (match_vector[i].first == match_vector[i1].first)) + { + match_vector[i1].second += match_vector[i].second; + } + else + { + i1++; + match_vector[i1].first = match_vector[i].first; + match_vector[i1].second = match_vector[i].second; + } + } + int count_match_tokens = i1 + 1; + /* + * write out string + */ + token[0] = '\0'; + for (i = 0; i < count_match_tokens; i++) + { + strcat(token, match_vector[i].first.c_str()); + if (match_vector[i].second != 1.0) + { + sprintf(token1, "%g", (double) match_vector[i].second); + strcat(token, token1); + } + } + /* + * Write a template name using first of equivalent elements + */ + strcpy(template1, mytemplate); + squeeze_white(template1); + ptr = template1; + while (extract_bracket(&ptr, equal_list) == TRUE) + { + strcpy(equal_list1, equal_list); + replace("{", "", equal_list); + replace("}", "", equal_list); + while (replace(",", " ", equal_list) == TRUE); + ptr1 = equal_list; + /* + * Get first name in a list + */ + std::string elt_name; + if (copy_token(elt_name, &ptr1) == EMPTY) + { + error_string = sformatf( + "Expecting a nonempty list of element names in isotope sum. %s", + mytemplate); + error_msg(error_string, CONTINUE); + return (ERROR); + } + replace(equal_list1, elt_name.c_str(), template1); + squeeze_white(template1); + ptr = template1; + } + /* + * Compare string + */ + /* Cases: 0 exact match + * 1 leading wild card + * 2 trailing wild card + * 3 leading and trailing wild card + */ + case_no = 0; + if (template1[0] == '*') + case_no = 1; + l = (int) strlen(template1); + if (template1[l - 1] == '*') + { + if (case_no != 1) + { + case_no = 2; + } + else + { + case_no = 3; + } + } + while (replace("*", "", template1)); + match = FALSE; + switch (case_no) + { + case 0: + /* exact match */ + if (strcmp(token, template1) == 0) + match = TRUE; + break; + case 1: + /* leading wild card */ + if ((ptr = strstr(token, template1)) == NULL) + { + match = FALSE; + } + else + { + if (strcmp(ptr, template1) == 0) + match = TRUE; + } + break; + case 2: + /* trailing wild card */ + if (strstr(token, template1) == token) + match = TRUE; + break; + case 3: + /* trailing wild card */ + if (strstr(token, template1) != NULL) + match = TRUE; + break; + } + return (match); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +match_elts_in_species(const char *name, const char *mytemplate) +/* ---------------------------------------------------------------------- */ +{ /* * Makes a list of elements with their coefficients, stores elements * in elt_list at position count_elts. Global variable count_elts is @@ -1648,7 +1884,7 @@ match_elts_in_species(const char *name, const char *mytemplate) } return (match); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: extract_bracket(char **string, char *bracket_string) @@ -1673,7 +1909,106 @@ extract_bracket(char **string, char *bracket_string) *string += 1; return (TRUE); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +surf_total(const char *total_name, const char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in LDBLE layer + */ + int j; + if (use.Get_surface_ptr() == NULL) + return (0); + +/* + * Find surface... + */ + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE) + continue; + + std::string token; + token = x[j]->master[0]->elt->name; + replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + std::string name; + CParser::copy_token(name, b, e); + if (surface_name != NULL) + { + if (strcmp(name.c_str(), surface_name) == 0) + break; + } + else + { + break; + } + } + if (j >= count_unknowns) + return (0); +/* + * find total moles for redox state + */ + LDBLE t = 0; + bool redox = false; + if (strstr(total_name, "(") != NULL) + { + redox = true; + } + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type != SURF) + continue; + + std::string token; + struct rxn_token *rxn_ptr; + for (rxn_ptr = s_x[j]->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++) + { + if (redox && rxn_ptr->s->secondary) + { + token = rxn_ptr->s->secondary->elt->name; + } + else if (!redox && rxn_ptr->s->secondary) + { + token = rxn_ptr->s->secondary->elt->primary->elt->name; + } + else if (!redox && rxn_ptr->s->primary) + { + token = rxn_ptr->s->primary->elt->name; + } + else + { + continue; + } + if (strcmp(token.c_str(), total_name) == 0) + { + t += rxn_ptr->coef * s_x[j]->moles; + break; + } + else + // sum all sites in case total_name is a surface name without underscore + { + if (rxn_ptr->s->type == SURF) + { + if (token.find("_") != std::string::npos) + { + token = token.substr(0, token.find("_")); + } + if (strcmp(token.c_str(), total_name) == 0) + { + t += rxn_ptr->coef * s_x[j]->moles; + break; + } + } + } + } + } + return t; +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: surf_total(const char *total_name, const char *surface_name) @@ -1760,7 +2095,7 @@ surf_total(const char *total_name, const char *surface_name) } return (0); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: total(const char *total_name) diff --git a/phreeqc/cl1.cpp b/phreeqc/cl1.cpp index 97712778..958718d3 100644 --- a/phreeqc/cl1.cpp +++ b/phreeqc/cl1.cpp @@ -2,7 +2,10 @@ #include #include #include - +//#define USE_GMP +#if defined(USE_GMP) +#include +#endif #include "Phreeqc.h" #include "phqalloc.h" @@ -31,8 +34,8 @@ cl1(int k, int l, int m, int n, LDBLE xmin, xmax; int iout = 0; // static i runs faster on windows - int i, j; - LDBLE l_z; + register int i, j; + register LDBLE l_z; int maxit, n1, n2; LDBLE pivot; int ia, ii, kk, nk, js; @@ -42,7 +45,20 @@ cl1(int k, int l, int m, int n, LDBLE zu, zv; LDBLE tpivot; int klm, jmn, nkl, jpn; - LDBLE cuv, sum; + LDBLE cuv; +#if defined(USE_GMP) + mpf_set_default_prec(256); + mpf_t sum; + mpf_t z_mpf; + mpf_t q_mpf; + mpf_t d_mpf; + mpf_init(sum); + mpf_init(z_mpf); + mpf_init(q_mpf); + mpf_init(d_mpf); +#else + long double sum; +#endif int klm1; int q_dim, cu_dim; int kode_arg; @@ -298,7 +314,11 @@ cl1(int k, int l, int m, int n, #endif for (j = js; j < n1; ++j) { - sum = 0.; +#if defined(USE_GMP) + mpf_set_d(sum, 0.0); +#else + sum = 0.; +#endif for (i = 0; i < klm; ++i) { ii = q2[i * q_dim + n1].ival; @@ -310,9 +330,21 @@ cl1(int k, int l, int m, int n, { l_z = l_cu[ii - 1]; } - sum += q2[i * q_dim + j].dval * l_z; +#if defined(USE_GMP) + mpf_set_d(z_mpf, l_z); + mpf_set_d(q_mpf, q2[i * q_dim + j].dval); + mpf_mul(d_mpf, z_mpf, q_mpf); + mpf_add(sum, sum, d_mpf); +#else + sum += (long double) q2[i * q_dim + j].dval * (long double) l_z; +#endif + } +#if defined(USE_GMP) + q2[klm * q_dim + j].dval = mpf_get_d(sum); +#else q2[klm * q_dim + j].dval = sum; +#endif } for (j = js; j < n; ++j) { @@ -686,7 +718,11 @@ cl1(int k, int l, int m, int n, #ifdef DEBUG_CL1 output_msg(sformatf( "L590\n")); #endif +#if defined(USE_GMP) + mpf_set_d(sum, 0.0); +#else sum = 0.; +#endif for (j = 0; j < n; ++j) { l_x[j] = 0.; @@ -718,7 +754,13 @@ cl1(int k, int l, int m, int n, if (ii >= n1 && ii <= nk) { /* * DBLE(Q(I,N1)) */ - sum += q2[i * q_dim + n].dval; +#if defined(USE_GMP) + mpf_set_d(q_mpf, q2[i * q_dim + n].dval); + mpf_add(sum, sum, d_mpf); +#else + sum += (long double) q2[i * q_dim + n].dval; +#endif + } } } @@ -726,7 +768,17 @@ cl1(int k, int l, int m, int n, #ifdef DEBUG_CL1 output_msg(sformatf( "L640\n")); #endif +#if defined(USE_GMP) + *l_error = mpf_get_d(sum); +#else *l_error = sum; +#endif +#if defined(USE_GMP) + mpf_clear(sum); + mpf_clear(z_mpf); + mpf_clear(q_mpf); + mpf_clear(d_mpf); +#endif /* * Check calculation */ diff --git a/phreeqc/cl1mp.cpp b/phreeqc/cl1mp.cpp index 5ea0a8fa..170f7006 100644 --- a/phreeqc/cl1mp.cpp +++ b/phreeqc/cl1mp.cpp @@ -22,6 +22,7 @@ cl1mp(int k, int l, int m, int n, int *iter, LDBLE * x_arg, LDBLE * res_arg, LDBLE * error_arg, LDBLE * cu_arg, int *iu, int *s, int check, LDBLE censor_arg) { + mpf_set_default_prec(256); /* System generated locals */ union double_or_int { diff --git a/phreeqc/gases.cpp b/phreeqc/gases.cpp index 424dce84..5e290e1c 100644 --- a/phreeqc/gases.cpp +++ b/phreeqc/gases.cpp @@ -41,7 +41,7 @@ setup_fixed_volume_gas(void) { gas_unknown = gas_unknowns[0]; } - same_pressure = FALSE; + //same_pressure = FALSE; return (OK); } @@ -367,7 +367,8 @@ calc_PR(void) m_sum += gas_unknowns[i]->moles; phase_ptr = gas_unknowns[i]->phase; if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - continue; + error_msg("Cannot calculate a mixture of ideal and Peng_Robinson gases,\n please define Tc and Pc for the active gases in PHASES.", STOP); + //continue; if (!phase_ptr->pr_a) { T_c = phase_ptr->t_c; @@ -404,16 +405,16 @@ calc_PR(void) { a_aa_sum2 = 0.0; phase_ptr = gas_unknowns[i]->phase; - if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - continue; + //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + // continue; b_sum += phase_ptr->fraction_x * phase_ptr->pr_b; size_t i1; struct phase *phase_ptr1; for (i1 = 0; i1 < gas_unknowns.size(); i1++) { phase_ptr1 = gas_unknowns[i1]->phase; - if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) - continue; + //if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) + // continue; if (phase_ptr1->fraction_x == 0) continue; a_aa = sqrt(phase_ptr->pr_a * phase_ptr->pr_alpha * @@ -503,7 +504,7 @@ calc_PR(void) // accept a (possible) whobble in the curve... // error_msg("No convergence when calculating P in Peng-Robinson.", STOP); } - if (V_m < v1) + if (V_m < v1 && it < 40) P = R_TK / (v1 - b_sum) - a_aa_sum / (v1 * (v1 + 2 * b_sum) - b2); } } @@ -558,11 +559,11 @@ calc_PR(void) } phase_ptr->pr_p = phase_ptr->fraction_x * P; - if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - { - phase_ptr->pr_phi = 1; - continue; - } + //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + //{ + // phase_ptr->pr_phi = 1; + // continue; + //} rz = P * V_m / R_TK; A = a_aa_sum * P / (R_TK * R_TK); B = b_sum * P / R_TK; diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index afa11379..2ff98a49 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -1497,7 +1497,7 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, else { prep(); - same_pressure = false; + //same_pressure = false; k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); set(FALSE); converge = model(); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index cd3d6107..1f74394b 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -551,8 +551,13 @@ initialize(void) print_density = 0; same_model = FALSE; - same_temperature = FALSE; - same_pressure = FALSE; + //same_temperature = FALSE; + //same_pressure = FALSE; + current_tc = NAN; + current_pa = NAN; + current_mu = NAN; + mu_terms_in_logk = true; + g_iterations = -1; G_TOL = 1e-8; save_init(-1); @@ -674,12 +679,12 @@ initialize(void) pe_step_size_now = pe_step_size; count_total_steps = 0; remove_unstable_phases = FALSE; - for (i = 0; i < 50; i++) - { - match_tokens[i].name = NULL; - match_tokens[i].coef = 0; - } - count_match_tokens = 0; + //for (i = 0; i < 50; i++) + //{ + // match_tokens[i].name = NULL; + // match_tokens[i].coef = 0; + //} + //count_match_tokens = 0; initial_solution_isotopes = FALSE; full_pitzer = FALSE; always_full_pitzer = FALSE; diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 0e612918..65e05b95 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -44,7 +44,7 @@ model(void) int mass_water_switch_save; LDBLE old_mu; - same_mu = true; + //same_mu = true; set_inert_moles(); /* debug_model = TRUE; */ /* debug_prep = TRUE; */ @@ -159,13 +159,6 @@ model(void) } reset(); } -#ifndef PHREEQC2 - if (fabs(old_mu - mu_x) > 1e-3 * mu_x) - { - same_mu = false; - old_mu = mu_x; - } -#endif gammas(mu_x); if (molalities(FALSE) == ERROR) { @@ -429,7 +422,7 @@ check_residuals(void) } else { - if ((residual[i] >= epsilon + if ((residual[i] >= epsilon * 100 && x[i]->moles > 0.0) /* || stop_program == TRUE */ ) { remove_unstable_phases = TRUE; @@ -610,9 +603,7 @@ gammas(LDBLE mu) b = 50.2905 * s3 / c1; #else // a and b are calc'd in calc_dielectrics(tc_x, patm_x); - if (!same_mu) - k_temp(tc_x, patm_x); - same_mu = true; + k_temp(tc_x, patm_x); a = DH_A; b = DH_B; #endif @@ -2140,7 +2131,7 @@ mb_gases(void) gas_unknown->moles > MIN_TOTAL) { gas_in = TRUE; - patm_x = gas_phase_ptr->Get_total_p(); + //patm_x = gas_phase_ptr->Get_total_p(); } } @@ -2359,7 +2350,6 @@ molalities(int allow_overflow) else if (s_x[i]->type == SURF) { s_x[i]->moles = exp(s_x[i]->lm * LOG_10); /* formerly * mass water */ - } else { @@ -2602,16 +2592,6 @@ calc_gas_pressures(void) V_m = 1.0; calc_PR(phase_ptrs, 0, tk_x, V_m); pr_done = true; - - if (fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) - { - same_pressure = FALSE; - if (V_m < 0.07) - patm_x = (1. * patm_x + gas_phase_ptr->Get_total_p()) / 2; - else - patm_x = gas_phase_ptr->Get_total_p(); - k_temp(tc_x, patm_x); - } } else { gas_phase_ptr->Set_total_p(0); @@ -2696,15 +2676,6 @@ calc_gas_pressures(void) } gas_phase_ptr->Set_total_p(1500.0); } - if (iterations > 1 && fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) - { - same_pressure = FALSE; - if (gas_phase_ptr->Get_total_p() > 1e3) - patm_x = (3 * patm_x + gas_phase_ptr->Get_total_p()) / 4; - else - patm_x = (1 * patm_x + gas_phase_ptr->Get_total_p()) / 2; - k_temp(tc_x, patm_x); - } } return (OK); @@ -3495,11 +3466,6 @@ reset(void) else { mu_x += delta[i]; - if (patm_x > 1 && fabs(delta[i]) > 1e-3 * mu_x) - { - same_model = false; - k_temp(tc_x, patm_x); - } } if (mu_x <= 1e-8) { @@ -3522,6 +3488,7 @@ reset(void) (double) delta[i], "delta/c", (double) d)); } s_h2o->la += d; + ah2o_x = exp(s_h2o->la * LOG_10); /* pe */ } else if (x[i]->type == MH) @@ -3633,15 +3600,27 @@ reset(void) x[i]->moles += delta[i]; if (x[i]->moles < MIN_TOTAL) x[i]->moles = MIN_TOTAL; - if (x[i] == gas_unknown && gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && - (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) - && numerical_fixed_volume && !calculating_deriv) - { - patm_x = gas_phase_ptr->Get_total_p(); - k_temp(tc_x, patm_x); + !calculating_deriv) + { + if (debug_model == TRUE) + { + output_msg(sformatf( + "%-10.10s %-9s%10.2e %-9s%10.2e %-6s%10.2e\n", + "Pressure", "old P", + (double) last_patm_x, "new P", + (double) gas_phase_ptr->Get_total_p(), "iter P", + (double) patm_x)); + } + patm_x = gas_phase_ptr->Get_total_p(); + if (patm_x < 1e-10 && patm_x < p_sat) + { + patm_x = ( 1 * patm_x + p_sat) / 2.0; + } + if (patm_x > 1500) + patm_x = 1500; } - + last_patm_x = patm_x; } else if (x[i]->type == SS_MOLES) { @@ -3844,15 +3823,6 @@ residuals(void) "Failed Residual %d: %s %d %e\n", iterations, x[i]->description, i, residual[i])); converge = FALSE; -#ifndef PHREEQC2 - ah2o_x = exp(s_h2o->la * LOG_10); - /* recalculate k's if pressure changes > 0.005 atm by ah2o change... */ - if ((use.Get_solution_ptr()->Get_patm() < p_sat && fabs(patm_x - p_sat) > 5e-3) || - fabs(ah2o_x - ah2o_x0) > (5e-3 / p_sat)) - { - k_temp(tc_x, patm_x); - } -#endif } } else if (x[i]->type == MH @@ -3991,6 +3961,15 @@ residuals(void) x[i]->description, i, residual[i])); converge = FALSE; } + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && + (fabs(last_patm_x - patm_x) > 0.001 || fabs(last_patm_x - gas_phase_ptr->Get_total_p()) > 0.001) + && !calculating_deriv) + { + if (print_fail) + output_msg(sformatf("Failed pressure test %d: %e %e %e\n", iterations, last_patm_x, patm_x, + gas_phase_ptr->Get_total_p())); + converge = FALSE; + } } else if (x[i]->type == SS_MOLES) { @@ -4447,7 +4426,7 @@ set(int initial) #ifdef PHREEQC2 patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) #else - //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) #endif /* @@ -4552,9 +4531,6 @@ revise_guesses(void) LDBLE d; max_iter = 10; -#ifndef PHREEQC2 - same_mu = false; -#endif gammas(mu_x); l_iter = 0; repeat = TRUE; @@ -4711,9 +4687,6 @@ revise_guesses(void) { mu_x = 1e-8; } -#ifndef PHREEQC2 - same_mu = false; -#endif gammas(mu_x); return (OK); } @@ -4739,6 +4712,7 @@ sum_species(void) */ ph_x = -s_hplus->la; solution_pe_x = -s_eminus->la; + ah2o_x = exp(s_h2o->la * LOG_10); #ifdef PHREEQC2 ah2o_x = exp(s_h2o->la * LOG_10); #else @@ -4932,9 +4906,6 @@ surface_model(void) { g_iterations++; prev_aq_x = mass_water_aq_x; -#ifndef PHREEQC2 - same_mu = false; -#endif k_temp(tc_x, patm_x); gammas(mu_x); molalities(TRUE); @@ -4966,7 +4937,7 @@ surface_model(void) debug_diffuse_layer = TRUE; } #ifndef PHREEQC2 - same_mu = false; + //same_mu = false; #else k_temp(tc_x, patm_x); #endif @@ -5183,7 +5154,7 @@ numerical_jacobian(void) calculating_deriv = TRUE; #ifndef PHREEQC2 - same_mu = false; + //same_mu = false; #endif gammas(mu_x); molalities(TRUE); @@ -5249,10 +5220,6 @@ numerical_jacobian(void) case MU: d2 = d * mu_x; mu_x += d2; -#ifndef PHREEQC2 - if (fabs(d2 / mu_x) > 1e-3) - same_mu = false; -#endif gammas(mu_x); break; case PP: @@ -5340,10 +5307,6 @@ numerical_jacobian(void) break; case MU: mu_x -= d2; -#ifndef PHREEQC2 - if (fabs(d2 / mu_x) > 1e-3) - same_mu = false; -#endif gammas(mu_x); break; case PP: diff --git a/phreeqc/pitzer.cpp b/phreeqc/pitzer.cpp index 62174214..a4a612cf 100644 --- a/phreeqc/pitzer.cpp +++ b/phreeqc/pitzer.cpp @@ -1383,7 +1383,7 @@ set_pz(int initial) #ifdef PHREEQC2 patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) #else - //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) #endif /* * H+, e-, H2O @@ -1645,6 +1645,7 @@ jacobian_pz(void) Restart: int pz_max_unknowns = max_unknowns; + //k_temp(tc_x, patm_x); if (full_pitzer == TRUE) { molalities(TRUE); @@ -1682,6 +1683,8 @@ Restart: d2 = d1; break; case PITZER_GAMMA: + if (!full_pitzer) + continue; x[i]->s->lg += d; d2 = d; break; @@ -1710,8 +1713,10 @@ Restart: x[i]->moles += d2; break; case MU: + //continue; d2 = d * mu_x; mu_x += d2; + //k_temp(tc_x, patm_x); gammas(mu_x); break; case PP: @@ -1765,6 +1770,7 @@ Restart: break; case MU: mu_x -= d2; + //k_temp(tc_x, patm_x); gammas(mu_x); break; case GAS_MOLES: @@ -2031,13 +2037,9 @@ check_gammas_pz(void) converge = FALSE; } } - if (fabs(old_mu - mu_x) > 1e-3 * mu_x) - { - same_model = false; - k_temp(tc_x, patm_x); - } if (fabs(old_mu - mu_x) > tol) converge = FALSE; + if ((pow((LDBLE) 10.0, s_h2o->la) - AW) > tol) converge = FALSE; return converge; @@ -2054,6 +2056,7 @@ gammas_pz() int i, j; LDBLE coef; /* Initialize */ + k_temp(tc_x, patm_x); /* * Calculate activity coefficients */ diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index b71073dd..802978f4 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -232,7 +232,6 @@ quick_setup(void) gas_unknowns[i]->phase->pr_phi = 1.0; gas_unknowns[i]->phase->pr_p = 0; } - same_pressure = FALSE; } else { @@ -2772,7 +2771,6 @@ reprep(void) * Build model again */ build_model(); - same_model = FALSE; k_temp(tc_x, patm_x); return (OK); @@ -3973,7 +3971,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) m_sum += phase_ptr->moles_x; } if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - continue; + error_msg("Cannot calculate a mixture of ideal and Peng_Robinson gases,\n please define Tc and Pc for the active gases in PHASES.", STOP); + //continue; if (!phase_ptr->pr_a) { T_c = phase_ptr->t_c; @@ -4014,14 +4013,14 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) { a_aa_sum2 = 0.0; phase_ptr = phase_ptrs[i]; - if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - continue; + //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + // continue; b_sum += phase_ptr->fraction_x * phase_ptr->pr_b; for (i1 = 0; i1 < n_g; i1++) { phase_ptr1 = phase_ptrs[i1]; - if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) - continue; + //if (phase_ptr1->t_c == 0.0 || phase_ptr1->p_c == 0.0) + // continue; if (phase_ptr1->fraction_x == 0) continue; a_aa = sqrt(phase_ptr->pr_a * phase_ptr->pr_alpha * @@ -4072,7 +4071,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) 27. * r3[3] * r3[3]; //if (iterations > 50) // it = 0; // debug - if (disct > 1e-8) + if (disct > 0) { // 3-roots, find the largest P... it = 0; @@ -4112,7 +4111,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) // accept a (possible) whobble in the curve... // error_msg("No convergence when calculating P in Peng-Robinson.", STOP); } - if (V_m < v1) + if (V_m < v1 && it < 40) P = R_TK / (v1 - b_sum) - a_aa_sum / (v1 * (v1 + 2 * b_sum) - b2); } } @@ -4162,11 +4161,11 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) continue; } phase_ptr->pr_p = phase_ptr->fraction_x * P; - if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - { - phase_ptr->pr_phi = 1; - continue; - } + //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) + //{ + // phase_ptr->pr_phi = 1; + // continue; + //} rz = P * V_m / R_TK; A = a_aa_sum * P / (R_TK * R_TK); B = b_sum * P / R_TK; @@ -4181,6 +4180,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) // for initial equilibrations, adapt log_k of the gas phase... if (state < REACTION) { + rho_0 = calc_rho_0(TK - 273.15, P); + calc_dielectrics(TK - 273.15, P); phase_ptr->lk = calc_lk_phase(phase_ptr, TK, P); } phase_ptr->pr_in = true; @@ -4280,6 +4281,7 @@ adjust_setup_pure_phases(void) if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { p = exp(si_org * LOG_10); + patm_x = p; t = use.Get_solution_ptr()->Get_tc() + 273.15; if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) { @@ -4685,6 +4687,7 @@ adjust_setup_solution(void) if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { p = exp(x[i]->si * LOG_10); + patm_x = p; t = use.Get_solution_ptr()->Get_tc() + 273.15; if (!phase_ptr->pr_in || p != phase_ptr->pr_p || t != phase_ptr->pr_tk) { @@ -5747,7 +5750,8 @@ calc_vm(LDBLE tc, LDBLE pa) s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->logk[vm3] + (s_x[i]->logk[vm4] + s_x[i]->logk[vm5] * tc) * tc) * mu_x; /* for calculating delta_v of the reaction... */ - s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; + //s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; + s_x[i]->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; } return OK; } @@ -5761,11 +5765,11 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ * Calculates log k's for all species and pure_phases */ #ifndef PHREEQC2 - if (same_model == TRUE && same_temperature == TRUE && same_pressure == TRUE && same_mu) - return (OK); + if (tc == current_tc && pa == current_pa && ((fabs(mu_x - current_mu) < 1e-3 * mu_x) || !mu_terms_in_logk)) + return OK; #else - if (same_model == TRUE && same_temperature == TRUE && same_pressure == TRUE) - return (OK); + if (tc == current_tc && pa == current_pa) + return OK; #endif int i; LDBLE tempk = tc + 273.15; @@ -5780,14 +5784,15 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ #endif calc_vm(tc, pa); + mu_terms_in_logk = false; for (i = 0; i < count_s_x; i++) { if (s_x[i]->rxn_x->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); - - if (same_model && same_temperature && s_x[i]->rxn_x->logk[delta_v] == 0) + if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) continue; + mu_terms_in_logk = true; s_x[i]->lk = k_calc(s_x[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); } /* @@ -5805,6 +5810,8 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - (phases[i]->logk[vm0] + (phases[i]->logk[vm1] + phases[i]->logk[vm2] * tc) * tc - phases[i]->logk[kappa] * (pa - 1)); + if (phases[i]->rxn_x->logk[delta_v]) + mu_terms_in_logk = true; phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); #endif } @@ -5823,6 +5830,11 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ } } } + + current_tc = tc; + current_pa = pa; + current_mu = mu_x; + return (OK); } @@ -6036,6 +6048,12 @@ save_model(void) last_model.count_surface_charge = 0; last_model.surface_charge = NULL; } + + current_tc = NAN; + current_pa = NAN; + current_mu = NAN; + mu_terms_in_logk = true; + return (OK); } @@ -6051,32 +6069,8 @@ check_same_model(void) if (last_model.force_prep == TRUE) { last_model.force_prep = FALSE; - same_temperature = FALSE; - same_pressure = FALSE; return (FALSE); } -/* - * Check temperature - */ - if (fabs(tc_x - last_model.temperature) < 0.05) - { - same_temperature = TRUE; - } - else - { - same_temperature = FALSE; - } -/* - * Check pressure - */ - if (fabs(patm_x - last_model.pressure) < 0.01) - { - same_pressure = TRUE; - } - else - { - same_pressure = FALSE; - } /* * Check master species */ diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 7b71c062..d349a7bd 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -4997,364 +4997,6 @@ read_solution(void) return (return_value); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -read_solution(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Reads solution data - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ - int i, j, n, l; - int n_user, n_user_end; - int default_pe, alk; - int count_isotopes; - int max_mass_balance, count_mass_balance; - char *ptr, *ptr1; - char *description; - char token[MAX_LENGTH], token1[MAX_LENGTH]; - - int return_value, opt; - char *next_char; - const char *opt_list[] = { - "temp", /* 0 */ - "temperature", /* 1 */ - "dens", /* 2 */ - "density", /* 3 */ - "units", /* 4 */ - "redox", /* 5 */ - "ph", /* 6 */ - "pe", /* 7 */ - "unit", /* 8 */ - "isotope", /* 9 */ - "water", /* 10 */ - "press", /* 11 */ - "pressure" /* 12 */ - }; - int count_opt_list = 13; -/* - * Read solution number and description - */ - ptr = line; - read_number_description(ptr, &n_user, &n_user_end, &description); -/* - * Malloc space for solution data - */ - if (solution_bsearch(n_user, &n, FALSE) != NULL) - { - solution_free(solution[n]); - } - else - { - n = count_solution++; - if (count_solution >= max_solution) - { - space((void **) ((void *) &(solution)), count_solution, - &max_solution, sizeof(struct solution *)); - } - } - solution[n] = solution_alloc(); - - solution[n]->n_user = n_user; - solution[n]->n_user_end = n_user_end; - if (use.Get_solution_in() == FALSE) - { - use.Set_solution_in(true); - use.Set_n_solution_user(n_user); - } - max_mass_balance = MAX_MASS_BALANCE; -/* - * Set default ph, temp, density, pe, units - */ - solution[n]->description = description; - solution[n]->tc = 25.0; - solution[n]->patm = 1; - solution[n]->ph = 7.0; - solution[n]->density = 1.0; - solution[n]->solution_pe = 4.0; - solution[n]->mass_water = 1.0; - solution[n]->ah2o = 1.0; - solution[n]->mu = 1e-7; - solution[n]->cb = 0.0; - solution[n]->count_master_activity = 0; - default_pe = 0; - solution[n]->units = string_hsave("mMol/kgw"); - solution[n]->totals[0].description = NULL; - count_mass_balance = 0; - count_isotopes = 0; -/* - * Read concentration data - */ - return_value = UNKNOWN; - for (;;) - { - opt = get_option(opt_list, count_opt_list, &next_char); - if (opt == OPTION_DEFAULT) - { - ptr = next_char; - if (copy_token(token, &ptr, &l) == DIGIT) - { - opt = 9; - } - } - switch (opt) - { - case OPTION_EOF: /* end of file */ - return_value = EOF; - break; - case OPTION_KEYWORD: /* keyword */ - return_value = KEYWORD; - break; - case OPTION_ERROR: - input_error++; - error_msg("Unknown input in SOLUTION keyword.", CONTINUE); - error_msg(line_save, CONTINUE); - break; - case 0: /* temperature */ - case 1: - if (sscanf(next_char, SCANFORMAT, &(solution[n]->tc)) != 1) - { - solution[n]->tc = 25; - } - break; - case 2: /* density */ - case 3: - sscanf(next_char, SCANFORMAT, &(solution[n]->density)); - break; - case 4: /* units */ - case 8: /* unit */ - if (copy_token(token, &next_char, &l) == EMPTY) - break; - { - if (check_units(token, FALSE, FALSE, solution[n]->units, TRUE) == - OK) - { - solution[n]->units = string_hsave(token); - } - else - { - input_error++; - } - } - break; - case 5: /* redox */ - if (copy_token(token, &next_char, &l) == EMPTY) - break; - if (parse_couple(token) == OK) - { - default_pe = pe_data_store(&(solution[n]->pe), token); - } - else - { - input_error++; - } - break; - case 6: /* ph */ - if (read_conc(n, count_mass_balance, line) == ERROR) - { - input_error++; - break; - } - solution[n]->ph = - solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL) - { - break; - } - solution[n]->totals[count_mass_balance].description = - string_hsave("H(1)"); - count_mass_balance++; - break; - case 7: /* pe */ - if (read_conc(n, count_mass_balance, line) == ERROR) - { - input_error++; - break; - } - solution[n]->solution_pe = - solution[n]->totals[count_mass_balance].input_conc; - if (solution[n]->totals[count_mass_balance].equation_name == NULL) - { - break; - } - solution[n]->totals[count_mass_balance].description = - string_hsave("E"); - count_mass_balance++; - break; - case 9: /* isotope */ - if (copy_token(token, &next_char, &l) != DIGIT) - { - input_error++; - error_string = sformatf( "Expected isotope name to" - " begin with an isotopic number."); - error_msg(error_string, CONTINUE); - continue; - } - solution[n]->isotopes = - (struct isotope *) PHRQ_realloc(solution[n]->isotopes, - (size_t) (count_isotopes + - 1) * - sizeof(struct isotope)); - if (solution[n]->isotopes == NULL) - malloc_error(); - - /* read and save element name */ - ptr1 = token; - get_num(&ptr1, - &(solution[n]->isotopes[count_isotopes].isotope_number)); - if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE) - { - error_msg("Expecting element name.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return (ERROR); - } - solution[n]->isotopes[count_isotopes].elt_name = - string_hsave(ptr1); - - /* read and store isotope ratio */ - if (copy_token(token, &next_char, &l) != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, - &(solution[n]->isotopes[count_isotopes].ratio)); - - solution[n]->isotopes[count_isotopes].ratio_uncertainty = NAN; - - /* read and store isotope ratio uncertainty */ - if ((j = copy_token(token, &next_char, &l)) != EMPTY) - { - if (j != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for uncertainty in isotope ratio."); - error_msg(error_string, CONTINUE); - continue; - } - sscanf(token, SCANFORMAT, - &(solution[n]->isotopes[count_isotopes]. - ratio_uncertainty)); - } - count_isotopes++; - break; - case 10: /* water */ - j = copy_token(token, &next_char, &l); - if (j == EMPTY) - { - solution[n]->mass_water = 1.0; - } - else if (j != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for mass of water in solution."); - error_msg(error_string, CONTINUE); - } - else - { - sscanf(token, SCANFORMAT, &dummy); - solution[n]->mass_water = (LDBLE) dummy; - } - break; - case 11: /* pressure */ - case 12: - j = copy_token(token, &next_char, &l); - if (j == EMPTY) - { - solution[n]->patm = 1.0; - } - else if (j != DIGIT) - { - input_error++; - error_string = sformatf( - "Expected numeric value for pressure (atm) of solution."); - error_msg(error_string, CONTINUE); - } - else - { - sscanf(token, SCANFORMAT, &dummy); - solution[n]->patm = (LDBLE) dummy; - } - break; - case OPTION_DEFAULT: -/* - * Read concentration - */ - if (read_conc(n, count_mass_balance, line) == ERROR) - { - input_error++; - break; - } - count_mass_balance++; - break; - } - if (count_mass_balance + 1 >= max_mass_balance) - { - space((void **) ((void *) &(solution[n]->totals)), - count_mass_balance + 1, &max_mass_balance, - sizeof(struct conc)); - } - if (return_value == EOF || return_value == KEYWORD) - break; - } -/* - * fix up default units and default pe - */ - for (i = 0; i < count_mass_balance; i++) - { - strcpy(token, solution[n]->totals[i].description); - str_tolower(token); - if (solution[n]->totals[i].units == NULL) - { - solution[n]->totals[i].units = solution[n]->units; - } - else - { - alk = FALSE; - if (strstr(token, "alk") == token) - alk = TRUE; - strcpy(token1, solution[n]->totals[i].units); - if (check_units(token1, alk, TRUE, solution[n]->units, TRUE) == - ERROR) - { - input_error++; - } - else - { - solution[n]->totals[i].units = string_hsave(token1); - } - } - if (solution[n]->totals[i].n_pe < 0) - { - solution[n]->totals[i].n_pe = default_pe; - } - } - solution[n]->default_pe = default_pe; -/* - * Mark end of solution - */ - solution[n]->totals[count_mass_balance].description = NULL; - solution[n]->count_isotopes = count_isotopes; - return (return_value); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_species(void) diff --git a/phreeqc/sit.cpp b/phreeqc/sit.cpp index f224eac9..b34024fb 100644 --- a/phreeqc/sit.cpp +++ b/phreeqc/sit.cpp @@ -504,7 +504,7 @@ set_sit(int initial) #ifdef PHREEQC2 patm_x = solution_ptr->Get_patm(); #else - //patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) #endif /* * H+, e-, H2O @@ -763,6 +763,7 @@ jacobian_sit(void) int i, j; Restart: int pz_max_unknowns = max_unknowns; + //k_temp(tc_x, patm_x); if (full_pitzer == TRUE) { molalities(TRUE); @@ -800,6 +801,8 @@ Restart: d2 = d1; break; case PITZER_GAMMA: + if (!full_pitzer) + continue; x[i]->s->lg += d; d2 = d; break; @@ -833,8 +836,10 @@ Restart: x[i]->moles += d2; break; case MU: + //continue; d2 = d * mu_x; mu_x += d2; + //k_temp(tc_x, patm_x); gammas(mu_x); break; case PP: @@ -888,6 +893,7 @@ Restart: break; case MU: mu_x -= d2; + //k_temp(tc_x, patm_x); gammas(mu_x); break; case GAS_MOLES: @@ -1157,11 +1163,6 @@ check_gammas_sit(void) { converge = FALSE; } - if (fabs(old_mu - mu_x) > 1e-3 * mu_x) - { - same_model = false; - k_temp(tc_x, patm_x); - } t = pow((LDBLE) 10.0, s_h2o->la); if ((pow((LDBLE) 10.0, s_h2o->la) - AW) > tol) { @@ -1181,6 +1182,7 @@ gammas_sit() int i, j; LDBLE coef; /* Initialize */ + k_temp(tc_x, patm_x); /* * Calculate activity coefficients */ diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 0dbb40a5..8fb4f5fe 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -1015,7 +1015,6 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) } if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE && fabs(gas_phase_ptr->Get_total_p() - patm_x) > 0.01) { - same_pressure = FALSE; patm_x = gas_phase_ptr->Get_total_p(); k_temp(tc_x, patm_x); } diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index df4c43f4..c846ba2e 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -1439,8 +1439,8 @@ fill_spec(int l_cell_no) continue; } dum2 = s_ptr->moles * dum; /* equivalent fraction */ - sol_D[l_cell_no].spec[count_spec].name = - string_hsave(s_ptr->name); + sol_D[l_cell_no].spec[count_spec].name = s_ptr->name; + //string_hsave(s_ptr->name); sol_D[l_cell_no].spec[count_spec].type = EX; sol_D[l_cell_no].spec[count_spec].c = dum2; sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg - log10(dum); @@ -1466,8 +1466,8 @@ fill_spec(int l_cell_no) break; } /* copy its name and Dw and charge... */ - sol_D[l_cell_no].spec[count_spec].aq_name = - string_hsave(s_ptr2->name); + sol_D[l_cell_no].spec[count_spec].aq_name = s_ptr2->name; + //string_hsave(s_ptr2->name); sol_D[l_cell_no].spec[count_spec].z = s_ptr2->z; if (s_ptr2->dw == 0) sol_D[l_cell_no].spec[count_spec].Dwt = @@ -1484,7 +1484,8 @@ fill_spec(int l_cell_no) lm = s_ptr->lm; if (lm > MIN_LM) { - sol_D[l_cell_no].spec[count_spec].name = string_hsave(s_ptr->name); + //sol_D[l_cell_no].spec[count_spec].name = string_hsave(s_ptr->name); + sol_D[l_cell_no].spec[count_spec].name = s_ptr->name; sol_D[l_cell_no].spec[count_spec].type = AQ; sol_D[l_cell_no].spec[count_spec].c = s_ptr->moles / mass_water_aq_x; @@ -1847,7 +1848,8 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) } if (l == count_m_s) { - m_s[l].name = string_hsave(elt_list[k].elt->name); + //m_s[l].name = string_hsave(elt_list[k].elt->name); + m_s[l].name = elt_list[k].elt->name; m_s[l].tot1 = elt_list[k].coef * l_J_ij[j].tot1; m_s[l].tot2 = elt_list[k].coef * l_J_ij[j].tot2; count_m_s++; @@ -2297,7 +2299,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is only in icell */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + //J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + J_ij_il[k_il].name = sol_D[icell].spec[i].name; V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; V_M_il[k_il].z = sol_D[icell].spec[i].z; V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; @@ -2312,7 +2315,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + //J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + J_ij[k].name = sol_D[icell].spec[i].name; V_M[k].D = sol_D[icell].spec[i].Dwt; V_M[k].z = sol_D[icell].spec[i].z; V_M[k].Dz = V_M[k].D * V_M[k].z; @@ -2376,7 +2380,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is only in jcell */ if (il_calcs && sol_D[jcell].spec[j].type == EX) { - J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); + //J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); + J_ij_il[k_il].name = sol_D[jcell].spec[j].name; V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; V_M_il[k_il].z = sol_D[jcell].spec[j].z; V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; @@ -2391,7 +2396,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); + //J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); + J_ij[k].name = sol_D[jcell].spec[j].name; V_M[k].D = sol_D[jcell].spec[j].Dwt; V_M[k].z = sol_D[jcell].spec[j].z; V_M[k].Dz = V_M[k].D * V_M[k].z; @@ -2455,7 +2461,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is in both cells */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + //J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); + J_ij_il[k_il].name = sol_D[icell].spec[i].name; if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) V_M_il[k_il].D = 0.0; @@ -2478,7 +2485,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + //J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); + J_ij[k].name = sol_D[icell].spec[i].name; if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) V_M[k].D = 0.0; diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index ef51063a..bade5d74 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -121,14 +121,20 @@ calc_rho_0(LDBLE tc, LDBLE pa) LDBLE p2 = -5.50294e-6 + tc * ( 1.07699e-7 + tc * (-2.05409e-9 + tc * ( 1.30238e-11 + tc * -3.20982E-14))); /* The minimal pressure equals the saturation pressure... */ - p_sat = exp(11.6702 - 3816.44 / (T - 46.13)) * ah2o_x; - ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x + if (ah2o_x <= 1.0) + p_sat = exp(11.6702 - 3816.44 / (T - 46.13)) * ah2o_x; + else + p_sat = exp(11.6702 - 3816.44 / (T - 46.13)); + //ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x if (pa < p_sat || (use.Get_solution_ptr() && use.Get_solution_ptr()->Get_patm() < p_sat)) { pa = p_sat; } - patm_x = pa; + if (!use.Get_gas_phase_in()) + patm_x = pa; rho_0 = p0 + pa * (p1 + pa * p2); + if (rho_0 < 0.01) + rho_0 = 0.01; /* compressibility, d(ln(rho)) / d(P), 1/atm... */ kappa_0 = (p1 + 2 * pa * p2) / rho_0; From 2f10f2e70da7eaf53ca0375901e1266dd69eddcf Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 04:13:02 +0000 Subject: [PATCH 0474/1077] fix for level 4 warning level git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6447 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/cl1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/cl1.cpp b/phreeqc/cl1.cpp index 958718d3..96017f17 100644 --- a/phreeqc/cl1.cpp +++ b/phreeqc/cl1.cpp @@ -343,7 +343,7 @@ cl1(int k, int l, int m, int n, #if defined(USE_GMP) q2[klm * q_dim + j].dval = mpf_get_d(sum); #else - q2[klm * q_dim + j].dval = sum; + q2[klm * q_dim + j].dval = (double)sum; #endif } for (j = js; j < n; ++j) @@ -771,7 +771,7 @@ cl1(int k, int l, int m, int n, #if defined(USE_GMP) *l_error = mpf_get_d(sum); #else - *l_error = sum; + *l_error = (double)sum; #endif #if defined(USE_GMP) mpf_clear(sum); From 67b089f8a6d6152449d36c42c2a3e33c0024d5f0 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 22:48:45 +0000 Subject: [PATCH 0475/1077] changed ifdefs for string_duplicate git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6460 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/utilities.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index bade5d74..652a4deb 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -1129,7 +1129,7 @@ strcmp_nocase_arg1(const char *str1, const char *str2) /* ---------------------------------------------------------------------- */ char * Phreeqc:: -#if _DEBUG +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) _string_duplicate(const char *token, const char *szFileName, int nLine) #else string_duplicate(const char *token) @@ -1142,7 +1142,7 @@ string_duplicate(const char *token) if (token == NULL) return NULL; l = (int) strlen(token); -#if _DEBUG +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); #else str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); From a718706e9129fc0fdd80c1ca7d92eaf08b8dbff3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 11 Apr 2012 23:08:29 +0000 Subject: [PATCH 0476/1077] fixed string_duplicate leaks git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6461 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 2 ++ phreeqc/spread.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index d349a7bd..af1fdd66 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -4868,9 +4868,11 @@ read_solution(void) error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); error_msg(line_save, PHRQ_io::OT_CONTINUE); input_error++; + temp_iso_name = (char*)free_check_null(temp_iso_name); return (CParser::PARSER_ERROR); } temp_isotope.Set_elt_name(ptr1); + temp_iso_name = (char*)free_check_null(temp_iso_name); } /* read and store isotope ratio */ if (copy_token(token, &next_char) != CParser::TT_DIGIT) diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 8c09a4cb..4bebbc93 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -754,9 +754,12 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE); error_msg(line_save, PHRQ_io::OT_CONTINUE); input_error++; + temp_iso_name = (char*)free_check_null(temp_iso_name); + char_string = (char*)free_check_null(char_string); return (CParser::PARSER_ERROR); } temp_isotope.Set_elt_name(ptr1); + temp_iso_name = (char*)free_check_null(temp_iso_name); } /* read and store isotope ratio */ if (copy_token(token, &next_char) != CParser::TT_DIGIT) From 9c1a63dc87110eb93ec3f3e0ed6d8f4a57389ef3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Apr 2012 16:59:51 +0000 Subject: [PATCH 0477/1077] Bug with key in pitzer parameters. Needed type, in addition to ions to make the key unique. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6464 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/pitzer_structures.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/phreeqc/pitzer_structures.cpp b/phreeqc/pitzer_structures.cpp index d8149a70..6fd15e9c 100644 --- a/phreeqc/pitzer_structures.cpp +++ b/phreeqc/pitzer_structures.cpp @@ -154,13 +154,15 @@ pitz_param_store(struct pitz_param *pzp_ptr) { if (pzp_ptr->species[i] != NULL) header.insert(pzp_ptr->species[i]); } - std::string key; + + std::ostringstream key_str; + key_str << pzp_ptr->type << " "; std::set< std::string >::iterator it = header.begin(); for(; it != header.end(); ++it) { - key += (*it); - key += " "; + key_str << *it << " "; } + std::string key = key_str.str().c_str(); std::map< std::string, size_t>::iterator jit = pitz_param_map.find(key); if (jit != pitz_param_map.end()) { From bf96306cba188a3f46155f1a91bef7adcc7553f3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Apr 2012 18:10:01 +0000 Subject: [PATCH 0478/1077] output file was closed before free_all, no messages appeared. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6466 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1ec44812..67b80c88 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -125,16 +125,16 @@ Phreeqc::~Phreeqc(void) { clean_up(); - if (phrq_io == &ioInstance) - { - this->phrq_io->clear_istream(); - this->phrq_io->close_ostreams(); - } free_check_null(default_data_base); free_check_null(sformatf_buffer); PHRQ_free_all(); + if (phrq_io == &ioInstance) + { + this->phrq_io->clear_istream(); + this->phrq_io->close_ostreams(); + } } void Phreeqc::set_phast(int tf) From 8e0844ed260a7e47047b3cd2653f073bdb1d6e3d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 13 Apr 2012 17:08:59 +0000 Subject: [PATCH 0479/1077] Fixed memory all memory leaks from mytest. Modified ss_r to run on Windows. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6475 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 1 + phreeqc/inverse.cpp | 1 + phreeqc/kinetics.cpp | 24 ++++++++++++++++-------- phreeqc/spread.cpp | 6 ++++++ phreeqc/step.cpp | 15 +++++++++++++++ phreeqc/structures.cpp | 4 ++++ 7 files changed, 45 insertions(+), 8 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 67b80c88..da3eb220 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -631,6 +631,7 @@ void Phreeqc::init(void) pitzer_pe = FALSE; count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants + x0_moles = NULL; /* * SIT */ @@ -746,6 +747,7 @@ void Phreeqc::init(void) /* kinetics.c */ m_original = NULL; m_temp = NULL; + rk_moles = NULL; /* pitzer.c */ A0 = 0; diff --git a/Phreeqc.h b/Phreeqc.h index b4e08ec8..7c07c903 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1709,6 +1709,7 @@ public: cxxPPassemblage *cvode_pp_assemblage_save; LDBLE *m_original; LDBLE *m_temp; + LDBLE *rk_moles; int set_and_run_attempt; /* model.cpp ------------------------------- */ diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index db805194..5b2b1114 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -4392,6 +4392,7 @@ dump_netpath_pat(struct inverse *inv_ptr) fprintf(netpath_file, "%d. Solution %d\n", count_inverse_models, solution_ptr_orig->Get_n_user()); } + description = (char *) free_check_null(description); /* bookkeeping */ count_pat_solutions++; diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 2ff98a49..83c6b252 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -260,7 +260,6 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, int l_bad, step_bad, step_ok; int n_reactions; LDBLE h, h_old, h_sum; - LDBLE *rk_moles; LDBLE l_error, error_max, safety, moles_max, moles_reduction; cxxKinetics *kinetics_ptr; int equal_rate, zero_rate; @@ -293,10 +292,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, if (kinetics_ptr == NULL) return (OK); n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); - rk_moles = - (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); - if (rk_moles == NULL) - malloc_error(); + rk_moles = (LDBLE *) free_check_null(rk_moles); + rk_moles = (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE)); + if (rk_moles == NULL) malloc_error(); /*if (use_mix != NOMIX) last_model.force_prep = TRUE; */ set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction); @@ -1388,6 +1386,16 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, pr.use = TRUE; sum_species(); print_all(); + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } error_string = sformatf( "Numerical method failed on all combinations of convergence parameters"); error_msg(error_string, STOP); @@ -2528,12 +2536,12 @@ store_get_equi_reactants(int l, int kin_end) } } k = count_pp + count_ss + count_pg; - x0_moles = NULL; + if (k == 0) return (OK); + x0_moles = (LDBLE *) free_check_null(x0_moles); x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE)); - if (x0_moles == NULL) - malloc_error(); + if (x0_moles == NULL) malloc_error(); for (i = 0; i < k; i++) { x0_moles[i] = 0.0; diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 4bebbc93..926837ad 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -739,6 +739,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); error_msg(error_string, PHRQ_io::OT_CONTINUE); + free_check_null(char_string); continue; } temp_isotope.Set_isotope_name(token.c_str()); @@ -768,6 +769,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, error_string = sformatf( "Expected numeric value for isotope ratio."); error_msg(error_string, CONTINUE); + free_check_null(char_string); continue; } sscanf(token.c_str(), SCANFORMAT, &dummy); @@ -784,6 +786,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, error_string = sformatf( "Expected numeric value for uncertainty in isotope ratio."); error_msg(error_string, PHRQ_io::OT_CONTINUE); + free_check_null(char_string); continue; } sscanf(token.c_str(), SCANFORMAT, &dummy); @@ -841,7 +844,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, { next_char = char_string; if (copy_token(token, &next_char) == LOWER) + { + free_check_null(char_string); continue; + } cxxISolutionComp temp_comp(this->phrq_io); if (temp_comp.read(char_string, &temp_solution) == CParser::PARSER_ERROR) { diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 8fb4f5fe..484ec2b3 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -175,6 +175,16 @@ step(LDBLE step_fraction) Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } + if (pp_assemblage_save != NULL) + { + delete pp_assemblage_save; + pp_assemblage_save = NULL; + } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } return (MASS_BALANCE); } /* @@ -191,6 +201,11 @@ step(LDBLE step_fraction) delete pp_assemblage_save; pp_assemblage_save = NULL; } + if (ss_assemblage_save != NULL) + { + delete ss_assemblage_save; + ss_assemblage_save = NULL; + } // // Solution -1 has sum of solution/mix, exchange, surface, gas_phase // reaction, kinetics diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 6b331f55..28584af9 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -135,6 +135,10 @@ clean_up(void) /* kinetics */ Rxn_kinetics_map.clear(); + x0_moles = (LDBLE *) free_check_null(x0_moles); + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + rk_moles = (LDBLE *) free_check_null(rk_moles); /* rates */ for (j = 0; j < count_rates; j++) From 3d2e4ae4beedbc319b7cc7cea78a787ce254b3bb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 19 Apr 2012 18:35:14 +0000 Subject: [PATCH 0480/1077] Removed Phreeqc_class.h. Replaced all PHREEQC_PTR, P_INSTANCE, p_instance1. Now uses Phreeqc * phreeqc_ptr for Phreeqc cookies. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6509 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 8 ++++---- ChartHandler.h | 5 ++--- ChartObject.cpp | 7 +++---- ChartObject.h | 6 +++--- GasPhase.cxx | 4 ++-- GasPhase.h | 3 +-- ISolution.cxx | 6 +++--- ISolution.h | 2 +- ISolutionComp.cxx | 20 ++++++++++---------- PPassemblage.cxx | 4 ++-- PPassemblage.h | 3 +-- PPassemblageComp.cxx | 4 ++-- PPassemblageComp.h | 3 +-- Phreeqc_class.h | 14 -------------- ReadClass.cxx | 3 +-- SS.cxx | 4 ++-- SS.h | 3 +-- SSassemblage.cxx | 4 ++-- SSassemblage.h | 3 +-- SScomp.cxx | 4 ++-- SScomp.h | 1 - Solution.cxx | 6 +++--- Solution.h | 2 -- StorageBin.cxx | 44 ++++++++++++++++++++++---------------------- Surface.cxx | 1 - SurfaceCharge.h | 1 - SurfaceComp.h | 1 - System.cxx | 10 +++++----- System.h | 3 +-- phreeqc/print.cpp | 2 +- phreeqc/step.cpp | 2 +- 31 files changed, 77 insertions(+), 106 deletions(-) delete mode 100644 Phreeqc_class.h diff --git a/ChartHandler.cpp b/ChartHandler.cpp index e711f0a3..bb5299d5 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -36,7 +36,7 @@ ChartHandler::~ChartHandler() } } void -ChartHandler::Punch_user_graph(PHREEQC_PTR_ARG) +ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) { std::map::iterator it = this->chart_map.begin(); for ( ; it != chart_map.end(); it++) @@ -46,14 +46,14 @@ ChartHandler::Punch_user_graph(PHREEQC_PTR_ARG) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) System::Threading::Thread::Sleep(1); this->current_chart = it->second; - P_INSTANCE_POINTER punch_user_graph(); + phreeqc_ptr-> punch_user_graph(); System::Threading::Interlocked::Exchange(it->second->usingResource, 0); } } } bool -ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) +ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) { int n_user; std::string token; @@ -76,7 +76,7 @@ ChartHandler::Read(PHREEQC_PTR_ARG_COMMA CParser &parser) { chart_map[n_user] = new ChartObject(this->Get_io()); it = this->chart_map.find(n_user); - it->second->Set_phreeqc(P_INSTANCE); + it->second->Set_phreeqc(phreeqc_ptr); } // Read/update ChartObject diff --git a/ChartHandler.h b/ChartHandler.h index 3ea25228..33bba098 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -7,7 +7,6 @@ #include "Parser.h" #include "ChartObject.h" #include "PHRQ_base.h" -#include "Phreeqc_class.h" class ChartHandler: public PHRQ_base { @@ -28,8 +27,8 @@ public: { return timer; } - bool Read(PHREEQC_PTR_ARG_COMMA CParser &parser); - void Punch_user_graph(PHREEQC_PTR_ARG); + bool Read(Phreeqc * phreeqc_ptr, CParser &parser); + void Punch_user_graph(Phreeqc * phreeqc_ptr); bool End_timer(); bool dump(std::ostream & oss, unsigned int indent); protected: diff --git a/ChartObject.cpp b/ChartObject.cpp index f215ffa8..492e8037 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -12,7 +12,6 @@ #include #include #include -#include "Phreeqc_class.h" #include "Phreeqc.h" #include "phqalloc.h" @@ -755,7 +754,7 @@ ChartObject::Set_rate_struct(void) oss << *it << "\n"; } this->Rate_free(); - this->user_graph->commands = (char *) P_INSTANCE_POINTER PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); + this->user_graph->commands = (char *) phreeqc_ptr-> PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); ::strcpy(this->user_graph->commands, oss.str().c_str()); this->user_graph->new_def = this->rate_new_def; this->user_graph->loopbase = NULL; @@ -987,12 +986,12 @@ ChartObject::Rate_free(void) { - user_graph->commands = (char *) P_INSTANCE_POINTER free_check_null(user_graph->commands); + user_graph->commands = (char *) phreeqc_ptr-> free_check_null(user_graph->commands); if (user_graph->linebase != NULL) { char cmd[] = "new; quit"; - P_INSTANCE_POINTER basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase); + phreeqc_ptr-> basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase); user_graph->linebase = NULL; user_graph->varbase = NULL; user_graph->loopbase = NULL; diff --git a/ChartObject.h b/ChartObject.h index 5daf0c2e..43c18067 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -227,11 +227,11 @@ class ChartObject:public cxxNumKeyword } void Set_phreeqc(Phreeqc * ptr) { - this->p_instance1 = ptr; + this->phreeqc_ptr = ptr; } Phreeqc * Get_phreeqc() { - return this->p_instance1; + return this->phreeqc_ptr; } bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); @@ -326,7 +326,7 @@ class ChartObject:public cxxNumKeyword bool active; bool detach; bool form_started; - class Phreeqc * p_instance1; + class Phreeqc * phreeqc_ptr; public: int usingResource; diff --git a/GasPhase.cxx b/GasPhase.cxx index fcb6f990..f012ce93 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -586,7 +586,7 @@ cxxGasPhase::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) } #endif void -cxxGasPhase::totalize(PHREEQC_PTR_ARG) +cxxGasPhase::totalize(Phreeqc * phreeqc_ptr) { this->totals.clear(); // component structures @@ -594,7 +594,7 @@ cxxGasPhase::totalize(PHREEQC_PTR_ARG) { struct phase *phase_ptr; int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->gas_comps[i].Get_phase_name().c_str(), &l, FALSE); + phase_ptr = phreeqc_ptr-> phase_bsearch(this->gas_comps[i].Get_phase_name().c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/GasPhase.h b/GasPhase.h index cfc2239d..7796c999 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -9,7 +9,6 @@ #include "phrqtype.h" #include "NumKeyword.h" #include "NameDouble.h" -#include "Phreeqc_class.h" #include "GasComp.h" class cxxMix; @@ -39,7 +38,7 @@ class cxxGasPhase:public cxxNumKeyword void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const { diff --git a/ISolution.cxx b/ISolution.cxx index e9e91b16..7a36cd45 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -33,7 +33,7 @@ cxxISolution::~cxxISolution() #ifdef SKIP_OR_MOVE_TO_STRUCTURES void -cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) +cxxISolution::ConvertUnits(Phreeqc * phreeqc_ptr) // // Converts from input units to moles per kilogram water // @@ -44,7 +44,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) this->comps.begin(); for (; iter != this->comps.end(); ++iter) { - struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(iter->first.c_str()); + struct master *master_ptr = phreeqc_ptr-> master_bsearch(iter->first.c_str()); if (master_ptr != NULL && (master_ptr->minor_isotope == TRUE)) continue; //if (iter->second.Get_description() == "H(1)" || iter->second.Get_description() == "E") continue; @@ -65,7 +65,7 @@ cxxISolution::ConvertUnits(PHREEQC_PTR_ARG) * Convert to moles */ //set gfw for element - iter->second.set_gfw(P_INSTANCE); + iter->second.set_gfw(phreeqc_ptr); // convert to moles if (iter->second.get_units().find("g/") != std::string::npos) { diff --git a/ISolution.h b/ISolution.h index 47b64872..d2e42f61 100644 --- a/ISolution.h +++ b/ISolution.h @@ -39,7 +39,7 @@ class cxxISolution: public PHRQ_base std::map < std::string, cxxChemRxn > &Get_pe_reactions(void) {return this->pe_reactions;} void Set_pe_reactions(std::map < std::string, cxxChemRxn > &pe) {this->pe_reactions = pe;} //void dump_xml(std::ostream& os, unsigned int indent = 0)const; - //void ConvertUnits(PHREEQC_PTR_ARG); + //void ConvertUnits(Phreeqc * phreeqc_ptr); protected: friend class cxxISolutionComp; // for this->pe access diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 3e57ed45..356bd4e0 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -23,7 +23,7 @@ cxxISolutionComp::~cxxISolutionComp(void) #ifdef SKIP_OR_MOVE_TO_STRUCTURES struct conc * -cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < std::string, +cxxISolutionComp::cxxISolutionComp2conc(Phreeqc * phreeqc_ptr, const std::map < std::string, cxxISolutionComp > &totals) // for ISolutions // takes a std::vector cxxISolutionComp structures @@ -31,27 +31,27 @@ cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < s { struct conc *c; c = (struct conc *) - P_INSTANCE_POINTER PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); + phreeqc_ptr-> PHRQ_malloc((size_t) ((totals.size() + 1) * sizeof(struct conc))); if (c == NULL) - P_INSTANCE_POINTER malloc_error(); + phreeqc_ptr-> malloc_error(); int i = 0; for (std::map < std::string, cxxISolutionComp >::const_iterator it = totals.begin(); it != totals.end(); ++it) { - c[i].description = P_INSTANCE_POINTER string_duplicate(it->second.description.c_str()); + c[i].description = phreeqc_ptr-> string_duplicate(it->second.description.c_str()); c[i].moles = it->second.moles; c[i].input_conc = it->second.input_conc; if (it->second.units.size() == 0) c[i].units = NULL; else - c[i].units = P_INSTANCE_POINTER string_hsave(it->second.units.c_str()); + c[i].units = phreeqc_ptr-> string_hsave(it->second.units.c_str()); if (it->second.equation_name.size() == 0) c[i].equation_name = NULL; else - c[i].equation_name = P_INSTANCE_POINTER string_hsave(it->second.equation_name.c_str()); + c[i].equation_name = phreeqc_ptr-> string_hsave(it->second.equation_name.c_str()); c[i].phase_si = it->second.phase_si; c[i].n_pe = it->second.n_pe; - c[i].as = P_INSTANCE_POINTER string_hsave(it->second.as.c_str()); + c[i].as = phreeqc_ptr-> string_hsave(it->second.as.c_str()); c[i].gfw = it->second.gfw; //c[i].skip = 0; c[i].phase = NULL; @@ -64,7 +64,7 @@ cxxISolutionComp::cxxISolutionComp2conc(PHREEQC_PTR_ARG_COMMA const std::map < s #ifdef SKIP_OR_MOVE_TO_STRUCTURES void -cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) +cxxISolutionComp::set_gfw(Phreeqc * phreeqc_ptr) { // return gfw if (this->gfw > 0.0) @@ -74,7 +74,7 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) { /* use given chemical formula to calculate gfw */ LDBLE l_gfw; - if (P_INSTANCE_POINTER compute_gfw(this->as.c_str(), &l_gfw) == ERROR) + if (phreeqc_ptr-> compute_gfw(this->as.c_str(), &l_gfw) == ERROR) { std::ostringstream oss; oss << "Could not compute gfw, " << this->as; @@ -92,7 +92,7 @@ cxxISolutionComp::set_gfw(PHREEQC_PTR_ARG) } /* use gfw of master species */ std::string str(this->description); - struct master *master_ptr = P_INSTANCE_POINTER master_bsearch(str.c_str()); + struct master *master_ptr = phreeqc_ptr-> master_bsearch(str.c_str()); if (master_ptr != NULL) { /* use gfw for element redox state */ diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 5cafdf41..5b98a3ad 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -288,14 +288,14 @@ cxxPPassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) } #endif void -cxxPPassemblage::totalize(PHREEQC_PTR_ARG) +cxxPPassemblage::totalize(Phreeqc * phreeqc_ptr) { this->assemblage_totals.clear(); // component structures for (std::map < std::string, cxxPPassemblageComp >::iterator it = pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { - (*it).second.totalize(P_INSTANCE); + (*it).second.totalize(phreeqc_ptr); this->assemblage_totals.add_extensive((*it).second.Get_totals(), 1.0); } return; diff --git a/PPassemblage.h b/PPassemblage.h index 053876b2..14738123 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -9,7 +9,6 @@ #include "NumKeyword.h" #include "PPassemblageComp.h" -#include "Phreeqc_class.h" class cxxMix; class cxxPPassemblage:public cxxNumKeyword @@ -55,7 +54,7 @@ class cxxPPassemblage:public cxxNumKeyword void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); protected: void add(const cxxPPassemblage & addee, LDBLE extensive); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0df9ac0f..7a736feb 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -370,7 +370,7 @@ cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) #endif void -cxxPPassemblageComp::totalize(PHREEQC_PTR_ARG) +cxxPPassemblageComp::totalize(Phreeqc * phreeqc_ptr) { this->totals.clear(); // component structures @@ -378,7 +378,7 @@ cxxPPassemblageComp::totalize(PHREEQC_PTR_ARG) return; struct phase *phase_ptr; int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &l, FALSE); + phase_ptr = phreeqc_ptr-> phase_bsearch(this->name.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 6626043d..ce68aec1 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -8,7 +8,6 @@ #include // std::vector #include "NameDouble.h" -#include "Phreeqc_class.h" class cxxPPassemblageComp: public PHRQ_base { @@ -38,7 +37,7 @@ class cxxPPassemblageComp: public PHRQ_base this->add_formula.clear(); } - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const {return (this->totals);} void Get_totals(cxxNameDouble & nd) {this->totals = nd;} LDBLE Get_si() const {return this->si;} diff --git a/Phreeqc_class.h b/Phreeqc_class.h deleted file mode 100644 index f1bac4b8..00000000 --- a/Phreeqc_class.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _INC_PHREEQC_CLASS_H -#define _INC_PHREEQC_CLASS_H - -#define P_INSTANCE p_instance1 -#define P_INSTANCE_COMMA p_instance1, -#define P_INSTANCE_POINTER p_instance1-> -#define PHREEQC_PTR_ARG Phreeqc *p_instance1 -#define PHREEQC_PTR_ARG_COMMA Phreeqc *p_instance1, -#define PHREEQC_THIS this -#define PHREEQC_THIS_COMMA this, -#define PHREEQC_NAME_SPACE Phreeqc:: - -#endif /* _INC_PHREEQC_CLASS_H */ - diff --git a/ReadClass.cxx b/ReadClass.cxx index f88ee32b..f54b57dc 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -7,7 +7,6 @@ #include "Utils.h" #include "Phreeqc.h" -#include "Phreeqc_class.h" #include "Parser.h" #include "Solution.h" #include "Exchange.h" @@ -917,7 +916,7 @@ read_user_graph_handler(void) assert(!reading_database()); - bool success = chart_handler.Read(PHREEQC_THIS_COMMA parser); + bool success = chart_handler.Read(this, parser); // Need to output the next keyword if (return_value == OPTION_KEYWORD) echo_msg(sformatf( "\t%s\n", line)); diff --git a/SS.cxx b/SS.cxx index 2ffa2431..c957af73 100644 --- a/SS.cxx +++ b/SS.cxx @@ -503,7 +503,7 @@ cxxSS::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) } #endif void -cxxSS::totalize(PHREEQC_PTR_ARG) +cxxSS::totalize(Phreeqc * phreeqc_ptr) { this->totals.clear(); // component structures @@ -511,7 +511,7 @@ cxxSS::totalize(PHREEQC_PTR_ARG) { struct phase *phase_ptr; int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(ss_comps[i].Get_name().c_str(), &l, FALSE); + phase_ptr = phreeqc_ptr-> phase_bsearch(ss_comps[i].Get_name().c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/SS.h b/SS.h index 31b09de5..1896c881 100644 --- a/SS.h +++ b/SS.h @@ -8,7 +8,6 @@ #include // std::vector #include "phrqtype.h" #include "NameDouble.h" -#include "Phreeqc_class.h" #include "SScomp.h" @@ -53,7 +52,7 @@ class cxxSS: public PHRQ_base this->name.clear(); } - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const { return (this->totals); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index f4025f7b..79ca92c6 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -275,14 +275,14 @@ cxxSSassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) #endif void -cxxSSassemblage::totalize(PHREEQC_PTR_ARG) +cxxSSassemblage::totalize(Phreeqc * phreeqc_ptr) { this->totals.clear(); // component structures for (std::map < std::string, cxxSS >::iterator it = SSs.begin(); it != SSs.end(); ++it) { - (*it).second.totalize(P_INSTANCE); + (*it).second.totalize(phreeqc_ptr); this->totals.add_extensive((*it).second.Get_totals(), 1.0); } return; diff --git a/SSassemblage.h b/SSassemblage.h index 5d6a6632..58cad0b0 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -10,7 +10,6 @@ #include "NumKeyword.h" #include "NameDouble.h" -#include "Phreeqc_class.h" #include "SS.h" class cxxSS; @@ -37,7 +36,7 @@ public: void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const {return this->totals;} std::map < std::string, cxxSS > & Get_SSs(void) {return SSs;} diff --git a/SScomp.cxx b/SScomp.cxx index f2e8554a..3af1f166 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -305,7 +305,7 @@ cxxSScomp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) #endif #ifdef SKIP void -cxxSScomp::totalize(PHREEQC_PTR_ARG) +cxxSScomp::totalize(Phreeqc * phreeqc_ptr) { this->totals.clear(); // component structures @@ -313,7 +313,7 @@ cxxSScomp::totalize(PHREEQC_PTR_ARG) return; struct phase *phase_ptr; int l; - phase_ptr = P_INSTANCE_POINTER phase_bsearch(this->name.c_str(), &l, FALSE); + phase_ptr = phreeqc_ptr-> phase_bsearch(this->name.c_str(), &l, FALSE); if (phase_ptr != NULL) { cxxNameDouble phase_formula(phase_ptr->next_elt); diff --git a/SScomp.h b/SScomp.h index 8eabc758..a26ea1d7 100644 --- a/SScomp.h +++ b/SScomp.h @@ -8,7 +8,6 @@ #include // std::vector #include "NameDouble.h" -#include "Phreeqc_class.h" class cxxSScomp: public PHRQ_base { diff --git a/Solution.cxx b/Solution.cxx index 05197918..578f8cc2 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -934,7 +934,7 @@ cxxSolution::mpi_send(int task_number) /* int count_isotopes; */ /* struct isotope *isotopes; */ - if (P_INSTANCE_POINTER input_error > 0) + if (phreeqc_ptr-> input_error > 0) { std::string errstr("Stopping due to errors\n"); error_msg(errstr.c_str(), STOP); @@ -950,7 +950,7 @@ cxxSolution::mpi_send(int task_number) MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; - buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); + buffer = phreeqc_ptr-> PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* @@ -998,7 +998,7 @@ cxxSolution::mpi_recv(int task_number) MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); - void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); + void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* diff --git a/Solution.h b/Solution.h index 32ffcf80..91ed692d 100644 --- a/Solution.h +++ b/Solution.h @@ -7,12 +7,10 @@ #include // std::vector #include #include "NumKeyword.h" -//#include "SolutionIsotopeList.h" #include "SolutionIsotope.h" #include "NameDouble.h" #include "PHRQ_base.h" #include "PHRQ_io.h" -#include "Phreeqc_class.h" #include "ISolution.h" class cxxMix; diff --git a/StorageBin.cxx b/StorageBin.cxx index b09b440e..27c6e8fb 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -829,7 +829,7 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) error_string = sformatf( "Solution %d not found in mix_cxxSolutions.", it->first); error_msg(error_string, CONTINUE); - P_INSTANCE_POINTER input_error++; + phreeqc_ptr-> input_error++; return (NULL); } intensive = it->second / extensive; @@ -841,22 +841,22 @@ cxxStorageBin::mix_cxxSolutions(cxxMix & mixmap) #ifdef SKIP_OR_MOVE_TO_STRUCTURES struct system * -cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) +cxxStorageBin::cxxStorageBin2system(Phreeqc * phreeqc_ptr, int n) // // make a system from storagebin // { struct system *system_ptr = - (struct system *) P_INSTANCE_POINTER PHRQ_malloc(sizeof(struct system)); + (struct system *) phreeqc_ptr-> PHRQ_malloc(sizeof(struct system)); if (system_ptr == NULL) - P_INSTANCE_POINTER malloc_error(); + phreeqc_ptr-> malloc_error(); // Solutions if (this->getSolution(n) != NULL) { - //system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(P_INSTANCE); - system_ptr->solution = P_INSTANCE_POINTER cxxSolution2solution(this->getSolution(n)); + //system_ptr->solution = (this->getSolution(n))->cxxSolution2solution(phreeqc_ptr); + system_ptr->solution = phreeqc_ptr-> cxxSolution2solution(this->getSolution(n)); } else { @@ -866,8 +866,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Exchangers if (this->getExchange(n) != NULL) { - //system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(P_INSTANCE); - system_ptr->exchange = P_INSTANCE_POINTER cxxExchange2exchange(this->getExchange(n)); + //system_ptr->exchange = (this->getExchange(n))->cxxExchange2exchange(phreeqc_ptr); + system_ptr->exchange = phreeqc_ptr-> cxxExchange2exchange(this->getExchange(n)); } else { @@ -877,8 +877,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // GasPhases if (this->getGasPhase(n) != NULL) { - //system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(P_INSTANCE); - system_ptr->gas_phase = P_INSTANCE_POINTER cxxGasPhase2gas_phase(this->getGasPhase(n)); + //system_ptr->gas_phase = (this->getGasPhase(n))->cxxGasPhase2gas_phase(phreeqc_ptr); + system_ptr->gas_phase = phreeqc_ptr-> cxxGasPhase2gas_phase(this->getGasPhase(n)); } else { @@ -888,8 +888,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Kinetics if (this->getKinetics(n) != NULL) { - //system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(P_INSTANCE); - system_ptr->kinetics = P_INSTANCE_POINTER cxxKinetics2kinetics(this->getKinetics(n)); + //system_ptr->kinetics = (this->getKinetics(n))->cxxKinetics2kinetics(phreeqc_ptr); + system_ptr->kinetics = phreeqc_ptr-> cxxKinetics2kinetics(this->getKinetics(n)); } else @@ -901,9 +901,9 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) if (this->getPPassemblage(n) != NULL) { //system_ptr->pp_assemblage = - // (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(P_INSTANCE); + // (this->getPPassemblage(n))->cxxPPassemblage2pp_assemblage(phreeqc_ptr); system_ptr->pp_assemblage = - P_INSTANCE_POINTER cxxPPassemblage2pp_assemblage(this->getPPassemblage(n)); + phreeqc_ptr-> cxxPPassemblage2pp_assemblage(this->getPPassemblage(n)); } else { @@ -914,9 +914,9 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) if (this->getSSassemblage(n) != NULL) { //system_ptr->ss_assemblage = - // (this->getSSassemblage(n))->cxxSSassemblage2ss_assemblage(P_INSTANCE); + // (this->getSSassemblage(n))->cxxSSassemblage2ss_assemblage(phreeqc_ptr); system_ptr->ss_assemblage = - P_INSTANCE_POINTER cxxSSassemblage2ss_assemblage((this->getSSassemblage(n))); + phreeqc_ptr-> cxxSSassemblage2ss_assemblage((this->getSSassemblage(n))); } else { @@ -926,8 +926,8 @@ cxxStorageBin::cxxStorageBin2system(PHREEQC_PTR_ARG_COMMA int n) // Surfaces if (this->getSurface(n) != NULL) { - //system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(P_INSTANCE); - system_ptr->surface = P_INSTANCE_POINTER cxxSurface2surface((this->getSurface(n))); + //system_ptr->surface = (this->getSurface(n))->cxxSurface2surface(phreeqc_ptr); + system_ptr->surface = phreeqc_ptr-> cxxSurface2surface((this->getSurface(n))); } else { @@ -1040,7 +1040,7 @@ cxxStorageBin::mpi_send(int n, int task_number) MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size); max_size += member_size + 10; - void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); + void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); @@ -1092,7 +1092,7 @@ cxxStorageBin::mpi_recv(int task_number) MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); - void *buffer = P_INSTANCE_POINTER PHRQ_malloc(max_size); + void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); if (buffer == NULL) malloc_error(); /* @@ -1223,7 +1223,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); - P_INSTANCE_POINTER input_error++; + phreeqc_ptr-> input_error++; return (NULL); } new_exch_ptr->set_pitzer_exchange_gammas(old_exch_ptr-> @@ -1244,7 +1244,7 @@ cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) error_string = sformatf( "Exchange %d not found in mix_cxxExchange.", it_mix->first); error_msg(error_string, CONTINUE); - P_INSTANCE_POINTER input_error++; + phreeqc_ptr-> input_error++; return (NULL); } // Add exchange components to vector ec_vector diff --git a/Surface.cxx b/Surface.cxx index 2121cb87..a3a4b86c 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -6,7 +6,6 @@ #endif #include // assert #include // std::sort -#include "Phreeqc_class.h" #include "Utils.h" // define first #include "Phreeqc.h" #include "Surface.h" diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 99154f76..6426b786 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -8,7 +8,6 @@ #include // std::vector #include "NameDouble.h" -#include "Phreeqc_class.h" #include "PHRQ_base.h" class cxxSpeciesDL { diff --git a/SurfaceComp.h b/SurfaceComp.h index 8da6bda3..3857592e 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -6,7 +6,6 @@ #include // std::string #include // std::list #include // std::vector -#include "Phreeqc_class.h" #include "NameDouble.h" class cxxSurfaceComp: public PHRQ_base diff --git a/System.cxx b/System.cxx index 4c1a753e..1a276b8d 100644 --- a/System.cxx +++ b/System.cxx @@ -50,7 +50,7 @@ cxxSystem::Initialize(void) this->pressure = NULL; } void -cxxSystem::totalize(PHREEQC_PTR_ARG) +cxxSystem::totalize(Phreeqc * phreeqc_ptr) { //initialize this->totals.clear(); @@ -73,22 +73,22 @@ cxxSystem::totalize(PHREEQC_PTR_ARG) } if (this->ppassemblage != NULL) { - this->ppassemblage->totalize(P_INSTANCE); + this->ppassemblage->totalize(phreeqc_ptr); this->totals.add_extensive(this->ppassemblage->Get_assemblage_totals(), 1.0); } if (this->gasphase != NULL) { - this->gasphase->totalize(P_INSTANCE); + this->gasphase->totalize(phreeqc_ptr); this->totals.add_extensive(this->gasphase->Get_totals(), 1.0); } if (this->ssassemblage != NULL) { - this->ssassemblage->totalize(P_INSTANCE); + this->ssassemblage->totalize(phreeqc_ptr); this->totals.add_extensive(this->ssassemblage->Get_totals(), 1.0); } if (this->surface != NULL) { - this->ssassemblage->totalize(P_INSTANCE); + this->ssassemblage->totalize(phreeqc_ptr); this->totals.add_extensive(this->surface->Get_totals(), 1.0); } return; diff --git a/System.h b/System.h index 879e82ef..328ed235 100644 --- a/System.h +++ b/System.h @@ -2,7 +2,6 @@ #define SYSTEM_H_INCLUDED #include "NameDouble.h" #include "PHRQ_base.h" -#include "Phreeqc_class.h" class cxxSolution; class cxxExchange; class cxxGasPhase; @@ -65,7 +64,7 @@ public: { this->pressure = entity; } - void totalize(PHREEQC_PTR_ARG); + void totalize(Phreeqc * phreeqc_ptr); cxxNameDouble &Get_Totals(void) { return this->totals; diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index da07498b..9e14eea0 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -126,7 +126,7 @@ punch_all(void) #elif defined MULTICHART if (pr.user_graph == TRUE) { - chart_handler.Punch_user_graph(PHREEQC_THIS); + chart_handler.Punch_user_graph(this); } #endif if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 484ec2b3..96991062 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -226,7 +226,7 @@ step(LDBLE step_fraction) sys_bin.Set_SSassemblage(-1, *use.Get_ss_assemblage_ptr()); } sys_bin.Set_System(-1); - sys_bin.Get_System().totalize(PHREEQC_THIS); + sys_bin.Get_System().totalize(this); cxxNameDouble sys_tots = sys_bin.Get_System().Get_Totals(); if (use.Get_pp_assemblage_in()) { From 3eb956bdf078b843f91099372056c93479f6a61d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 19 Apr 2012 22:19:46 +0000 Subject: [PATCH 0481/1077] removed dependency on phrqtype.h by using a template for addPair removed unnecessary Phreeqc.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6512 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.cxx | 7 +++---- Parser.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Parser.cxx b/Parser.cxx index d530ad1f..8e6c3b17 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -13,7 +13,6 @@ #include "Utils.h" #include #include "Parser.h" -#include "Phreeqc.h" #include "PHRQ_io.h" ////////////////////////////////////////////////////////////////////// @@ -989,12 +988,12 @@ CParser::STATUS_TYPE CParser::parse_couple(std::string & token) return PARSER_OK; } -CParser::STATUS_TYPE CParser::addPair(std::map < std::string, LDBLE >&totals, +template +CParser::STATUS_TYPE CParser::addPair(std::map < std::string, T >&totals, std::istream::pos_type & pos) { std::string token; - LDBLE - d; + T d; CParser::TOKEN_TYPE j; m_line_iss.seekg(pos); diff --git a/Parser.h b/Parser.h index a32b1b0b..3b7e135d 100644 --- a/Parser.h +++ b/Parser.h @@ -3,7 +3,6 @@ #if defined(WIN32) #include #endif -#include "phrqtype.h" #include // std::string #include // std::map #include // std::vector @@ -247,7 +246,8 @@ class CParser: public PHRQ_base STATUS_TYPE parse_couple(std::string & token); - STATUS_TYPE addPair(std::map < std::string, LDBLE >&totals, + template + STATUS_TYPE addPair(std::map < std::string, T >&totals, std::istream::pos_type & pos); protected: From 59016d1ced930efc4552362ca35c51b9ed4e44d7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 01:43:57 +0000 Subject: [PATCH 0482/1077] added GNUmakefile which rebuilds dependencies during each compile the dependencies are stored in each configurations .deps directory git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6513 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GNUmakefile | 388 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 388 insertions(+) create mode 100644 GNUmakefile diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 00000000..8487e8d6 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,388 @@ +# Makefile for PHREEQCPP +# +# Generates object files and executables for 2 versions of PHREEQCPP +# Release +# Debug +# +# Serial verisons: Release Debug +# +# Makefile sets CFG variable, cd's to appropriate directory, runs Makefile recursively +# Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC +# + +PROGRAM = phreeqcpp + +CFG1 :=`uname` +CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") +ifeq ($(CFG), CYGWIN) + SPOOL=> + SPOOL2=2>&1 +else + SPOOL=>& + SPOOL2= +endif + +all: class_release class_debug + +Debug: class_debug +debug: class_debug +Class_debug: class_debug + +Release: class_release +release: class_release +Class_release: class_release + +Debug_64: class_debug_64 +debug_64: class_debug_64 +Class_debug_64: class_debug_64 + +Release_64: class_release_64 +release_64: class_release_64 +Class_release_64: class_release_64 + + +CLASS_DEBUG_DIR = Class_debug +CLASS_DIR = Class_release +CLASS_DEBUG_64_DIR = Class_debug_64 +CLASS_64_DIR = Class_release_64 +MAKEFILE = GNUmakefile +DEPDIR = .deps + +# ----------------------------------------------------------------------------- +# fixes shared object lookup error(SIGFPE floating point exception) +HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) + + +######################### +#### Serial Versions #### +######################### +.PHONY : Class_debug +class_debug: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) + +.PHONY : Class_release +class_release: + mkdir -p $(CLASS_DIR) + cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) +.PHONY : Class_debug_64 +class_debug_64: + mkdir -p $(CLASS_DEBUG_64_DIR) + cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) + +.PHONY : Class_release_64 +class_release_64: + mkdir -p $(CLASS_64_DIR) + cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) + +# Recursive make begins here +# +# ============================================================================= +# Significant suffixes [assuming Fortran 90 (.f90) source code]: +# Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: +# ============================================================================= + +#SRC = ../phreeqc +.SUFFIXES : .o .c .cxx .cpp + +# compilers + +# ----------------------------------------------------------------------------- +.c.o : + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po + +.cxx.o : + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po + +.cpp.o : + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po + +# ----------------------------------------------------------------------------- +#hdf options +#HDF5_ROOT=$(HOME)/../../usr +#HDF5_INCLUDES=-I$(HDF5_ROOT)/src +#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread + +# ----------------------------------------------------------------------------- +# #define compile options + +# ----------------------------------------------------------------------------- +# #define gmp for inverse modeling +# comment the following lines to remove multiprecision option + +# ----------------------------------------------------------------------------- +#efence for debugging +EFENCE_LIB=-L$(HOME)/packages/efence + +# ----------------------------------------------------------------------------- +# 4 Versions +# ----------------------------------------------------------------------------- +ifeq ($(CFG), CLASS_DEBUG) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_DEBUG_64) + DEFINES = -DUSE_PHRQ_ALLOC # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE_64) + DEFINES = -DNDEBUG # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../phreeqc + INCLUDES = -I../phreeqc -I.. + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +# ----------------------------------------------------------------------------- +# + +COMMON_COBJS = \ + advection.o \ + basicsubs.o \ + cl1.o \ + cvdense.o \ + cvode.o \ + dense.o \ + dw.o \ + gases.o \ + input.o \ + integrate.o \ + inverse.o \ + isotopes.o \ + kinetics.o \ + mainsubs.o \ + model.o \ + nvector.o \ + nvector_serial.o \ + parse.o \ + PHRQ_io_output.o \ + phqalloc.o \ + pitzer.o \ + pitzer_structures.o \ + prep.o \ + print.o \ + read.o \ + readtr.o \ + sit.o \ + smalldense.o \ + spread.o \ + step.o \ + structures.o \ + sundialsmath.o \ + tally.o \ + tidy.o \ + transport.o \ + utilities.o + +MAIN_FILE = main.o + +CLASS_FILES = \ + class_main.o \ + Phreeqc.o + + +COMMON_CXXOBJS = \ + dumper.o \ + Exchange.o \ + ExchComp.o \ + GasPhase.o \ + GasComp.o \ + ISolution.o \ + ISolutionComp.o \ + Keywords.o \ + KineticsComp.o \ + cxxKinetics.o \ + cxxMix.o \ + NameDouble.o \ + NumKeyword.o \ + Parser.o \ + PBasic.o \ + PHRQ_base.o \ + PHRQ_io.o \ + PPassemblageComp.o \ + PPassemblage.o \ + Pressure.o \ + Reaction.o \ + ReadClass.o \ + runner.o \ + Solution.o \ + SolutionIsotope.o \ + SSassemblage.o \ + SScomp.o \ + SS.o \ + StorageBin.o \ + StorageBinList.o \ + Surface.o \ + SurfaceCharge.o \ + SurfaceComp.o \ + System.o \ + Temperature.o \ + Use.o \ + Utils.o + +# ----------------------------------------------------------------------------- +# Assign dependents to target on dependency line & link options on command +# line. Command line is initiated with a tab. ($@ is an internal macro for +# the current target.) + +${PROGRAM} : ${OBJECT_FILES} +# ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} + ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} + @echo; echo Done making for phreeqcpp +# ----------------------------------------------------------------------------- +# Module dependency list +# ----------------------------------------------------------------------------- +# +# CXX files +# +-include $(DEPDIR)/cxxKinetics.Po +-include $(DEPDIR)/cxxMix.Po +-include $(DEPDIR)/Exchange.Po +-include $(DEPDIR)/ExchComp.Po +-include $(DEPDIR)/GasComp.Po +-include $(DEPDIR)/GasPhase.Po +-include $(DEPDIR)/ISolutionComp.Po +-include $(DEPDIR)/ISolution.Po +-include $(DEPDIR)/KineticsComp.Po +-include $(DEPDIR)/NameDouble.Po +-include $(DEPDIR)/NumKeyword.Po +-include $(DEPDIR)/Parser.Po +-include $(DEPDIR)/PHRQ_base.Po +-include $(DEPDIR)/PPassemblageComp.Po +-include $(DEPDIR)/PPassemblage.Po +-include $(DEPDIR)/Pressure.Po +-include $(DEPDIR)/Reaction.Po +-include $(DEPDIR)/ReadClass.Po +-include $(DEPDIR)/Solution.Po +-include $(DEPDIR)/SolutionIsotope.Po +-include $(DEPDIR)/SSassemblage.Po +-include $(DEPDIR)/SScomp.Po +-include $(DEPDIR)/SS.Po +-include $(DEPDIR)/StorageBin.Po +-include $(DEPDIR)/SurfaceCharge.Po +-include $(DEPDIR)/SurfaceComp.Po +-include $(DEPDIR)/Surface.Po +-include $(DEPDIR)/System.Po +-include $(DEPDIR)/Temperature.Po +-include $(DEPDIR)/Utils.Po +-include $(DEPDIR)/ChartHandler.Po +-include $(DEPDIR)/ChartObject.Po +-include $(DEPDIR)/class_main.Po +-include $(DEPDIR)/CurveObject.Po +-include $(DEPDIR)/dumper.Po +-include $(DEPDIR)/Keywords.Po +-include $(DEPDIR)/PBasic.Po +-include $(DEPDIR)/Phreeqc.Po +-include $(DEPDIR)/PHRQ_io.Po +-include $(DEPDIR)/runner.Po +-include $(DEPDIR)/StorageBinList.Po +-include $(DEPDIR)/Use.Po +-include $(DEPDIR)/advection.Po +-include $(DEPDIR)/basicsubs.o +-include $(DEPDIR)/cl1.Po +-include $(DEPDIR)/cl1mp.Po +-include $(DEPDIR)/cvdense.Po +-include $(DEPDIR)/cvode.Po +-include $(DEPDIR)/dense.Po +-include $(DEPDIR)/dw.Po +-include $(DEPDIR)/gases.Po +-include $(DEPDIR)/input.Po +-include $(DEPDIR)/integrate.Po +-include $(DEPDIR)/inverse.Po +-include $(DEPDIR)/isotopes.Po +-include $(DEPDIR)/kinetics.Po +-include $(DEPDIR)/mainsubs.Po +-include $(DEPDIR)/model.Po +-include $(DEPDIR)/nvector.Po +-include $(DEPDIR)/nvector_serial.Po +-include $(DEPDIR)/parse.Po +-include $(DEPDIR)/phqalloc.Po +-include $(DEPDIR)/PHRQ_io_output.Po +-include $(DEPDIR)/pitzer.Po +-include $(DEPDIR)/pitzer_structures.Po +-include $(DEPDIR)/prep.Po +-include $(DEPDIR)/print.Po +-include $(DEPDIR)/read.Po +-include $(DEPDIR)/readtr.Po +-include $(DEPDIR)/sit.Po +-include $(DEPDIR)/smalldense.Po +-include $(DEPDIR)/spread.Po +-include $(DEPDIR)/step.Po +-include $(DEPDIR)/structures.Po +-include $(DEPDIR)/sundialsmath.Po +-include $(DEPDIR)/tally.Po +-include $(DEPDIR)/tidy.Po +-include $(DEPDIR)/transport.Po +-include $(DEPDIR)/utilities.Po + +# ----------------------------------------------------------------------------- +clean: + rm -rf Class_release Class_debug Class_release_64 Class_debug_64 + +dependencies: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + +tester: + cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + svn status -q ../mytest + svn status -q ../examples + +#ld-option +# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) +comma=, +ld-option = $(shell if $(CC) $(1) \ + -nostdlib -o /dev/null -xc /dev/null \ + > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) + +# ============================================================================= +# End of makefile. +# ============================================================================= From eace3df0fb70381d7ebfa776db8e59bdbb768b3f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 02:57:55 +0000 Subject: [PATCH 0483/1077] removed Utils.h dependency git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6514 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 41691d94..b895c84c 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -1,5 +1,4 @@ #include -#include "Utils.h" #include "PHRQ_io.h" #include "Parser.h" @@ -742,7 +741,7 @@ get_line(void) std::string::iterator beg = m_line.begin(); std::string::iterator end = m_line.end(); CParser::copy_token(stdtoken, beg, end); - Utilities::str_tolower(stdtoken); + std::transform(stdtoken.begin(), stdtoken.end(), stdtoken.begin(), ::tolower); if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) || (strstr(stdtoken.c_str(),"include_file") == stdtoken.c_str())) { From a4d8672a6bfdd6b3b36df9cdff71d5c2b3e3cfbb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 03:55:39 +0000 Subject: [PATCH 0484/1077] made get_line and get_logical_line virtual git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6515 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PHRQ_io.h b/PHRQ_io.h index b5249d24..d0a0e2a0 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -129,8 +129,8 @@ public: // input methods virtual int getc(void); - LINE_TYPE get_line(void); - LINE_TYPE get_logical_line(void); + virtual LINE_TYPE get_line(void); + virtual LINE_TYPE get_logical_line(void); bool check_key(std::string::iterator begin, std::string::iterator end); std::string & Get_m_line() {return m_line;} std::string & Get_m_line_save() {return m_line_save;} From aa8047e1348052455ed009c1e1854acfa3986e0a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 03:57:31 +0000 Subject: [PATCH 0485/1077] minor formatting git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6516 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Utils.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utils.cxx b/Utils.cxx index 881fec5a..5dbc18af 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -3,7 +3,7 @@ #endif #include // ::tolower #include // ::tolower -#include //std::transform +#include // std::transform #include // std::cout std::cerr #include From 74c97b0e7614b3766c54b4bf7904d73b36022f59 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 03:59:14 +0000 Subject: [PATCH 0486/1077] removed dependencies Phreeqc.h and Parser.h from Utils.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6517 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.h | 6 ++- Phreeqc.h | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ SS.cxx | 1 + Utils.h | 114 +--------------------------------------------- 4 files changed, 124 insertions(+), 114 deletions(-) diff --git a/ISolutionComp.h b/ISolutionComp.h index 389f76c1..e7b8753b 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -5,9 +5,13 @@ #include // std::map #include #include -#include "PHRQ_base.h" +#include "phrqtype.h" // LDBLE +#include "Parser.h" // CParser +#include "PHRQ_base.h" // PHRQ_base // forward declarations +class cxxSolution; class cxxISolution; // reqd for read and dump_xml +class PHRQ_io; class cxxISolutionComp: public PHRQ_base { diff --git a/Phreeqc.h b/Phreeqc.h index 7c07c903..dc1805b7 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1875,6 +1875,123 @@ public: static const int count_iso_defaults; }; +namespace Utilities +{ + LDBLE get_nan(void); + + // operations on maps of entities (Solution, Exchange, ...) + template < typename T > + void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) + { + typename T::const_iterator it; + for (it = b.begin(); it != b.end(); ++it) + { + it->second.dump_raw(s_oss, indent); + } + return; + } + + template < typename T > + T * Rxn_find(std::map < int, T > &b, int i) + { + if (b.find(i) != b.end()) + { + return (&(b.find(i)->second)); + } + else + { + return (NULL); + } + } + + template < typename T > + T * Rxn_copy(std::map < int, T > &b, int i, int j) + { + typename std::map < int, T >::iterator it; + it = b.find(i); + if (it != b.end()) + { + b[j] = it->second; + it = b.find(j); + it->second.Set_n_user(j); + it->second.Set_n_user_end(j); + return &(it->second); + } + else + { + return (NULL); + } + } + + template < typename T > + void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end) + { + if (n_user_end <= n_user) return; + typename std::map < int, T >::iterator it; + it = b.find(n_user); + if (it != b.end()) + { + for (int j = n_user + 1; j <= n_user_end; j++) + { + b[j] = it->second; + it = b.find(j); + it->second.Set_n_user(j); + it->second.Set_n_user_end(j); + } + } + } + template < typename T > + int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + { + typename std::map < int, T >::iterator it; + assert(!phreeqc_cookie->reading_database()); + + T entity(phreeqc_cookie->Get_phrq_io()); + + CParser parser(phreeqc_cookie->Get_phrq_io()); + entity.read_raw(parser); + + // Store + if (entity.Get_base_error_count() == 0) + { + m[entity.Get_n_user()] = entity; + } + + // Make copies if necessary + Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end()); + return phreeqc_cookie->cleanup_after_parser(parser); + } + + template < typename T > + int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + { + typename std::map < int, T >::iterator it; + + CParser parser(phreeqc_cookie->Get_phrq_io()); + + std::string key_name; + std::string::iterator b = parser.line().begin(); + std::string::iterator e = parser.line().end(); + CParser::copy_token(key_name, b, e); + + cxxNumKeyword nk; + nk.read_number_description(parser); + T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user()); + if (!entity_ptr) + { + std::ostringstream errstr; + errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n"; + phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP); + } + + entity_ptr->read_raw(parser, false); + + return phreeqc_cookie->cleanup_after_parser(parser); + } + +} // namespace Utilities + + #if defined(PHREEQCI_GUI) void PhreeqcIWait(Phreeqc *phreeqc); #endif diff --git a/SS.cxx b/SS.cxx index c957af73..63d5e50d 100644 --- a/SS.cxx +++ b/SS.cxx @@ -7,6 +7,7 @@ #include // assert #include // std::sort +#include "Phreeqc.h" #include "Utils.h" // define first #include "SS.h" //#include "Dictionary.h" diff --git a/Utils.h b/Utils.h index a30bd298..c227fb8b 100644 --- a/Utils.h +++ b/Utils.h @@ -1,12 +1,11 @@ #if !defined(UTILITIES_H_INCLUDED) #define UTILITIES_H_INCLUDED -#include "Phreeqc.h" + #include #include // std::istringstream std::ostringstream #include // std::ostream #include // std::istream #include // std::map -#include "Parser.h" namespace Utilities { @@ -24,116 +23,5 @@ namespace Utilities void squeeze_white(std::string & s_l); - LDBLE get_nan(void); - - // operations on maps of entities (Solution, Exchange, ...) - template < typename T > - void Rxn_dump_raw(const T & b, std::ostream & s_oss, unsigned int indent) - { - typename T::const_iterator it; - for (it = b.begin(); it != b.end(); ++it) - { - it->second.dump_raw(s_oss, indent); - } - return; - } - - template < typename T > - T * Rxn_find(std::map < int, T > &b, int i) - { - if (b.find(i) != b.end()) - { - return (&(b.find(i)->second)); - } - else - { - return (NULL); - } - } - - template < typename T > - T * Rxn_copy(std::map < int, T > &b, int i, int j) - { - typename std::map < int, T >::iterator it; - it = b.find(i); - if (it != b.end()) - { - b[j] = it->second; - it = b.find(j); - it->second.Set_n_user(j); - it->second.Set_n_user_end(j); - return &(it->second); - } - else - { - return (NULL); - } - } - - template < typename T > - void Rxn_copies(std::map < int, T > &b, int n_user, int n_user_end) - { - if (n_user_end <= n_user) return; - typename std::map < int, T >::iterator it; - it = b.find(n_user); - if (it != b.end()) - { - for (int j = n_user + 1; j <= n_user_end; j++) - { - b[j] = it->second; - it = b.find(j); - it->second.Set_n_user(j); - it->second.Set_n_user_end(j); - } - } - } - template < typename T > - int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie) - { - typename std::map < int, T >::iterator it; - assert(!phreeqc_cookie->reading_database()); - - T entity(phreeqc_cookie->Get_phrq_io()); - - CParser parser(phreeqc_cookie->Get_phrq_io()); - entity.read_raw(parser); - - // Store - if (entity.Get_base_error_count() == 0) - { - m[entity.Get_n_user()] = entity; - } - - // Make copies if necessary - Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end()); - return phreeqc_cookie->cleanup_after_parser(parser); - } - - template < typename T > - int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie) - { - typename std::map < int, T >::iterator it; - - CParser parser(phreeqc_cookie->Get_phrq_io()); - - std::string key_name; - std::string::iterator b = parser.line().begin(); - std::string::iterator e = parser.line().end(); - CParser::copy_token(key_name, b, e); - - cxxNumKeyword nk; - nk.read_number_description(parser); - T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user()); - if (!entity_ptr) - { - std::ostringstream errstr; - errstr << "Could not find " << key_name << " " << nk.Get_n_user() << " to modify.\n"; - phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP); - } - - entity_ptr->read_raw(parser, false); - - return phreeqc_cookie->cleanup_after_parser(parser); - } } #endif // UTILITIES_H_INCLUDED From fbe3108bb06e1da6e8a9e78d91baee241afd417d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 05:01:32 +0000 Subject: [PATCH 0487/1077] removed Phreeqc_class.h from dependencies git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6521 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 136 +++++++++++++++++++++++++++---------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/Makefile b/Makefile index 2d29e5fb..eda516e9 100644 --- a/Makefile +++ b/Makefile @@ -278,7 +278,7 @@ cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../cxxKinetics.h ../KineticsComp.h \ ../phreeqc/phqalloc.h @@ -287,7 +287,7 @@ cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h @@ -296,7 +296,7 @@ Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../Exchange.h ../ExchComp.h ../phreeqc/phqalloc.h @@ -305,7 +305,7 @@ ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../ExchComp.h ../phreeqc/phqalloc.h @@ -314,7 +314,7 @@ GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../GasComp.h \ ../phreeqc/phqalloc.h @@ -323,7 +323,7 @@ GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../GasPhase.h ../GasComp.h ../phreeqc/phqalloc.h @@ -333,7 +333,7 @@ ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../ISolutionComp.h ../Solution.h \ ../ISolution.h ../phreeqc/phqalloc.h @@ -343,7 +343,7 @@ ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../ISolution.h ../ISolutionComp.h \ ../phreeqc/phqalloc.h @@ -353,7 +353,7 @@ KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../KineticsComp.h ../phreeqc/phqalloc.h NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ @@ -362,7 +362,7 @@ NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h ../ISolutionComp.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ @@ -371,7 +371,7 @@ NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ ../phreeqc/NA.h Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -379,7 +379,7 @@ Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h @@ -389,7 +389,7 @@ PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../PPassemblageComp.h ../phreeqc/phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ @@ -398,7 +398,7 @@ PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../PPassemblage.h ../PPassemblageComp.h \ ../phreeqc/phqalloc.h @@ -407,7 +407,7 @@ Pressure.o: ../Pressure.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h @@ -416,7 +416,7 @@ Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../Reaction.h ../phreeqc/phqalloc.h @@ -426,7 +426,7 @@ ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Solution.h ../ISolution.h \ ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../PPassemblage.h \ @@ -438,7 +438,7 @@ Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../Solution.h ../ISolution.h ../ISolutionComp.h ../phreeqc/phqalloc.h @@ -448,7 +448,7 @@ SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../SolutionIsotope.h ../phreeqc/phqalloc.h SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ @@ -457,7 +457,7 @@ SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ ../phreeqc/phqalloc.h @@ -466,7 +466,7 @@ SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SScomp.h \ ../phreeqc/phqalloc.h @@ -475,7 +475,7 @@ SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SS.h \ ../SScomp.h ../phreeqc/phqalloc.h @@ -485,7 +485,7 @@ StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../StorageBin.h ../System.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ @@ -499,7 +499,7 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ @@ -508,10 +508,10 @@ SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -Surface.o: ../Surface.cxx ../Phreeqc_class.h ../Utils.h ../Phreeqc.h \ +Surface.o: ../Surface.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ @@ -525,7 +525,7 @@ System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../System.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ @@ -538,7 +538,7 @@ Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Temperature.h ../phreeqc/phqalloc.h Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -546,7 +546,7 @@ Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ChartHandler.o: ../ChartHandler.cpp @@ -556,7 +556,7 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ @@ -569,7 +569,7 @@ dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ Keywords.o: ../Keywords.cpp ../Keywords.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ ../phreeqc/global_structures.h ../Surface.h ../NumKeyword.h \ - ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h ../Parser.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h \ ../Keywords.h ../PHRQ_io.h ../SurfaceCharge.h ../phreeqc/NA.h \ ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ @@ -582,7 +582,7 @@ Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ @@ -595,7 +595,7 @@ PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h runner.o: ../runner.cpp ../runner.h ../phreeqc/phrqtype.h \ @@ -611,7 +611,7 @@ advection.o: ../phreeqc/advection.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../ISolution.h \ @@ -621,14 +621,14 @@ basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../phreeqc/../NameDouble.h \ ../phreeqc/../PBasic.h ../phreeqc/../PHRQ_base.h \ ../phreeqc/../Exchange.h ../phreeqc/../NumKeyword.h \ ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../GasPhase.h ../phreeqc/../Phreeqc_class.h \ + ../phreeqc/../GasPhase.h ../phreeqc/\ ../phreeqc/../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ ../Parser.h @@ -637,7 +637,7 @@ cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h @@ -646,7 +646,7 @@ cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h @@ -656,7 +656,7 @@ cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ @@ -665,7 +665,7 @@ cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ @@ -676,7 +676,7 @@ dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -684,7 +684,7 @@ gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../GasPhase.h ../GasComp.h @@ -694,7 +694,7 @@ input.o: ../phreeqc/input.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -702,7 +702,7 @@ integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ @@ -712,7 +712,7 @@ inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ @@ -722,7 +722,7 @@ isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h @@ -732,7 +732,7 @@ kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ @@ -746,7 +746,7 @@ mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -759,7 +759,7 @@ model.o: ../phreeqc/model.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ @@ -776,7 +776,7 @@ parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h @@ -785,7 +785,7 @@ phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ @@ -794,7 +794,7 @@ PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -802,7 +802,7 @@ pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ @@ -813,7 +813,7 @@ pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -821,7 +821,7 @@ prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -834,7 +834,7 @@ print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -846,7 +846,7 @@ read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Pressure.h ../Temperature.h ../Parser.h \ @@ -857,13 +857,13 @@ read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ ../phreeqc/phrqtype.h ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/../Phreeqc_class.h ../phreeqc/../SS.h \ + ../phreeqc/../PHRQ_io.h ../phreeqc/../phreeqc/../SS.h \ ../phreeqc/../SScomp.h ../Phreeqc.h ../phreeqc/cvdense.h \ ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ ../phreeqc/NA.h ../phreeqc/phqalloc.h sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ @@ -871,7 +871,7 @@ sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ @@ -884,7 +884,7 @@ spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ @@ -894,7 +894,7 @@ step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../StorageBin.h \ @@ -909,7 +909,7 @@ structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -918,7 +918,7 @@ structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ ../KineticsComp.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ ../phreeqc/../StorageBin.h ../phreeqc/../System.h \ ../phreeqc/../NameDouble.h ../phreeqc/../PHRQ_base.h \ - ../phreeqc/../Phreeqc_class.h ../phreeqc/../PHRQ_io.h + ../phreeqc/../phreeqc/../PHRQ_io.h sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ @@ -927,7 +927,7 @@ tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ @@ -939,7 +939,7 @@ tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -952,7 +952,7 @@ transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ @@ -965,7 +965,7 @@ utilities.o: ../phreeqc/utilities.cpp ../Utils.h ../Phreeqc.h \ ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../Phreeqc_class.h ../NameDouble.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ ../NameDouble.h ../Exchange.h ../ExchComp.h ../Solution.h ../ISolution.h \ From 2ca408ed31031f5df57882ddc3c3a07596832713 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 20 Apr 2012 05:18:15 +0000 Subject: [PATCH 0488/1077] updated for linux (added headers) added build dirs to ignore list git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6522 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.h | 6 ++++-- NumKeyword.cxx | 1 + PHRQ_io.cpp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ISolutionComp.h b/ISolutionComp.h index e7b8753b..ef88e620 100644 --- a/ISolutionComp.h +++ b/ISolutionComp.h @@ -1,16 +1,18 @@ #if !defined(ISOLUTIONCOMP_H_INCLUDED) #define ISOLUTIONCOMP_H_INCLUDED +#include // ::strcmp #include -#include // std::map +#include // std::map #include #include #include "phrqtype.h" // LDBLE #include "Parser.h" // CParser #include "PHRQ_base.h" // PHRQ_base + // forward declarations class cxxSolution; -class cxxISolution; // reqd for read and dump_xml +class cxxISolution; // reqd for read and dump_xml class PHRQ_io; class cxxISolutionComp: public PHRQ_base diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 5d8981af..39beab4b 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -5,6 +5,7 @@ // ////////////////////////////////////////////////////////////////////// +#include // ::sscanf #include "NumKeyword.h" #include "Parser.h" #include "Utils.h" diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index b895c84c..a4f438d2 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -1,3 +1,4 @@ +#include // ::strstr #include #include "PHRQ_io.h" #include "Parser.h" From f1e2ecdda2c13f16739800cf60f7959ee83e3388 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Apr 2012 18:17:47 +0000 Subject: [PATCH 0489/1077] Tony's changes 20120423. Changed to supcrit for phreeqc.dat and pitzer.dat. Updated test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6528 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 12 ++- PBasic.h | 3 +- PHRQ_io.cpp | 4 +- Phreeqc.h | 10 +++ phreeqc/basicsubs.cpp | 21 ++++++ phreeqc/global_structures.h | 15 ++-- phreeqc/prep.cpp | 143 ++++++++++++++++++++++++------------ phreeqc/print.cpp | 11 ++- phreeqc/read.cpp | 138 +++++++++++++++++++++++++++++----- phreeqc/utilities.cpp | 71 +++++++++++------- 10 files changed, 318 insertions(+), 110 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index d61f6f8d..1cd5d344 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1493,6 +1493,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokeps_r: output_msg("EPS_R"); // dielectric constant break; + case tokvm: + output_msg("VM"); // mole volume of aqueous solute + break; } l_buf = l_buf->next; } @@ -3056,6 +3059,12 @@ factor(struct LOC_exec * LINK) case toklog10: n.UU.val = log10(realfactor(LINK)); break; + case tokvm: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str); + } + break; case toksin: n.UU.val = sin(realfactor(LINK)); @@ -6350,7 +6359,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("gas_p", PBasic::tokgas_p), std::map::value_type("gas_vm", PBasic::tokgas_vm), std::map::value_type("pressure", PBasic::tokpressure), - std::map::value_type("eps_r", PBasic::tokeps_r) + std::map::value_type("eps_r", PBasic::tokeps_r), + std::map::value_type("vm", PBasic::tokvm) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 456f7dc1..4213c483 100644 --- a/PBasic.h +++ b/PBasic.h @@ -302,7 +302,8 @@ public: tokgas_vm, tokpressure, tokerase, - tokeps_r + tokeps_r, + tokvm }; #if !defined(PHREEQCI_GUI) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index a4f438d2..743730fa 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -1,4 +1,3 @@ -#include // ::strstr #include #include "PHRQ_io.h" #include "Parser.h" @@ -756,7 +755,8 @@ get_line(void) if (!next_stream->is_open()) { std::ostringstream errstr; - errstr << "\n*********** Could not open include file " << file_name << ". ***********\n\n"; + errstr << "\n*********** Could not open include file " << file_name + <<".\n Please, write the full path to this file. ***********\n\n"; delete next_stream; #if defined(PHREEQCI_GUI) warning_msg(errstr.str().c_str()); diff --git a/Phreeqc.h b/Phreeqc.h index dc1805b7..9b54f97c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -80,6 +80,7 @@ public: LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); + LDBLE aqueous_vm(const char *species_name); LDBLE calc_SC(void); /* VP: Density Start */ LDBLE calc_dens(void); @@ -660,8 +661,11 @@ public: int read_debug(void); int read_delta_h_only(char *ptr, LDBLE * delta_h, DELTA_H_UNIT * units); + int read_aq_species_vm_parms(char *ptr, LDBLE * delta_v); int read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units); + int read_phase_vm(char *ptr, LDBLE * delta_v, + DELTA_V_UNIT * units); int read_llnl_aqueous_model_parameters(void); int read_exchange(void); int read_exchange_master_species(void); @@ -1624,6 +1628,9 @@ protected: LDBLE V_solutes, rho_0, kappa_0, p_sat/*, ah2o_x0*/; LDBLE eps_r; // relative dielectric permittivity LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av + LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume + LDBLE ZBrn; // Born function (-1/eps_r + 1) * 41.84004, for supcrt calc'n of molal volume + LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume #endif LDBLE solution_mass, solution_volume; LDBLE f_rho(LDBLE rho_old); @@ -1999,5 +2006,8 @@ void PhreeqcIWait(Phreeqc *phreeqc); #if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) #define string_duplicate(s) _string_duplicate(s, __FILE__, __LINE__) #endif +#if defined(_DEBUG) + char * _string_duplicate(const char *token, const char *szFileName, int nLine); +#endif #endif diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 90c70d9b..21506cea 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -78,6 +78,26 @@ log_activity_coefficient(const char *species_name) return (g); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +aqueous_vm(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE g; + + s_ptr = s_search(species_name); + if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + { + g = s_ptr->logk[vm_tc]; + } + else + { + g = 0; + } + return (g); +} + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_SC(void) @@ -899,6 +919,7 @@ find_gas_vm(void) // also for non-PR gas phases... return (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()); } + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: find_misc1(const char *ss_name) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index 9e776e85..77cdc543 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -167,15 +167,12 @@ typedef enum { T_A5, T_A6, delta_v, /* set in calc_delta_v: calculated molar volume-change of the reaction */ - vm_tc, /* set in k_temp: calculated molar volume of the species at tc */ - vm0, /* read: molar volume at tc = 0 */ - vm1, /* read: coef * tc */ - vm2, /* read: coef * tc * tc */ - vm3, /* read: coef for I (ionic strength) */ - vm4, /* read: coef for I * tc */ - vm5, /* read: coef for I * tc * tc */ - kappa, /* read: compression constant, cm3/mol/atm */ - b_Av, /* read: b in z^2 * A_v * log(1 + b * I^0.5) / (2 * b), 0 if -Millero is used */ + vm_tc, /* set in calc_vm: calculated molal volume of the species at tc */ + vm0, /* read: molar volume of a phase */ + vma1, vma2, vma3, vma4, /* read: a1..a4 from supcrt, see calc_vm */ + wref, /* from supcrt */ + b_Av, /* b in z^2 * A_v * log(1 + b * I^0.5) / (2 * b) */ + vmi1, vmi2, vmi3, /* ionic strength terms: (i1 + i2/(TK - 228) + i3(TK)) * I. i3 not used */ MAX_LOG_K_INDICES /* Keep this definition at the end of the enum */ } LOG_K_INDICES; /* HSEARCH(3C) */ diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 802978f4..590f1d73 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -5654,46 +5654,71 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) (p_ptr->rxn_s ? p_ptr->rxn_s : NULL)); if (!r_ptr) return 0.0; - if (!r_ptr->logk[vm0]) + if (!r_ptr->logk[vm0]) // in case Vm of the phase is 0... return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); - LDBLE tc = TK - 273.15; + LDBLE tc = TK - 273.15, pb = pa * 1.01325; LDBLE d_v = 0.0; + species * s_ptr; for (size_t i = 0; r_ptr->token[i].name; i++) { if (!r_ptr->token[i].s) continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) + s_ptr = r_ptr->token[i].s; + if (!strcmp(s_ptr->name, "H+")) continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) + if (!strcmp(s_ptr->name, "e-")) continue; - if (!strcmp(r_ptr->token[i].s->name, "H2O")) + if (!strcmp(s_ptr->name, "H2O")) { - d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); + d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); + continue; } - else if (r_ptr->token[i].s->logk[vm0]) + else if (s_ptr->logk[vma1]) { + /* supcrt volume at I = 0... */ d_v += r_ptr->token[i].coef * - (r_ptr->token[i].s->logk[vm0] + - (r_ptr->token[i].s->logk[vm1] + r_ptr->token[i].s->logk[vm2] * tc) * tc + - (r_ptr->token[i].s->logk[vm3] + - (r_ptr->token[i].s->logk[vm4] + r_ptr->token[i].s->logk[vm5] * tc) * tc) * mu_x); - if (r_ptr->token[i].s->logk[b_Av] == 0) - d_v += r_ptr->token[i].s->z * r_ptr->token[i].s->z * 0.5 * DH_Av * sqrt(mu_x); - else + (s_ptr->logk[vma1] + s_ptr->logk[vma2] / (2600. + pb) + + s_ptr->logk[vma3] / (TK - 228.) + s_ptr->logk[vma2] / (2600. + pb) / (TK - 228.)); + //if (dgdP && s_ptr->z) + //{ + // LDBLE re = s_ptr->z * s_ptr->z / (s_ptr->logk[wref] / 1.66027e5 + s_ptr->z / 3.082); + // LDBLE Z3 = fabs(pow(s_ptr->z, 3)) / re / re - s_ptr->z / 9.498724; + // d_v += r_ptr->token[i].coef * ZBrn * 1.66027e5 * Z3 * dgdP; + //} + if (s_ptr->z) { - LDBLE b = (r_ptr->token[i].s->logk[b_Av] < 1e-5 ? - 1e-5 : r_ptr->token[i].s->logk[b_Av]); - d_v += r_ptr->token[i].s->z * r_ptr->token[i].s->z * 0.5 * DH_Av * - log(1 + b * sqrt(mu_x)) / b; + /* the ionic strength term * I^0.5... */ + if (s_ptr->logk[b_Av] == 0) + d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt(mu_x); + else + { + /* limit the Debye-Hueckel slope by b... */ + LDBLE b = (s_ptr->logk[b_Av] < 1e-5 ? 1e-5 : s_ptr->logk[b_Av]); + d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * + log(1 + b * sqrt(mu_x)) / b; + } + /* plus the volume terms * I... */ + LDBLE bi = s_ptr->logk[vmi1] + s_ptr->logk[vmi2] / (TK - 228.); // + s_x[i]->logk[vmi3] * TK); + d_v += bi * mu_x; } - if (pa > 1) - d_v -= r_ptr->token[i].s->logk[kappa] * (pa - 1.0); } + else if (s_x[i]->millero[0]) + { + /* Millero volume at I = 0... */ + d_v += s_ptr->millero[0] + tc * (s_ptr->millero[1] + tc * s_ptr->millero[2]); + if (s_ptr->z) + { + /* the ionic strength terms... */ + d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt(mu_x) + + (s_ptr->millero[3] + tc * (s_ptr->millero[4] + tc * s_ptr->millero[5])) * mu_x; + } + } + else + continue; } - d_v -= p_ptr->logk[vm0] + (p_ptr->logk[vm1] * tc + p_ptr->logk[vm2] * tc) * tc - - p_ptr->logk[kappa] * (pa - 1.0); + d_v -= p_ptr->logk[vm0]; r_ptr->logk[delta_v] = d_v; if (!strcmp(r_ptr->token[0].name, "H2O(g)")) r_ptr->logk[delta_v] = 0.0; @@ -5708,17 +5733,15 @@ calc_vm(LDBLE tc, LDBLE pa) { /* * Calculate molar volumes for aqueous species with a Redlich type eqn: - Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I - kappaC * (pa - 1). - * Vm0(tc) = millero[0] + millero[1] * tc + millero[2] * tc^2 + Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I. + * Vm0(tc) is calc'd using supcrt parms, or from millero[0] + millero[1] * tc + millero[2] * tc^2 * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av from calc_dielectrics(tc, pa). if b_Av != 0, I^0.5 is constrained to ln(1 + b_Av * I^0.5) / b_Av. - (b_Av = logk[vm0 + 7]). + * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228), or * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 - * kappaC = compression constant, cm3/mol/atm. - - * Read.cpp copies millero[0..6] into logk[vm0 + 0..6], or reads logk[vm0 + 0..7] directly with -Vm. */ + LDBLE pb = pa * 1.01325, TK = tc + 273.15; for (int i = 0; i < count_s_x; i++) { if (!strcmp(s_x[i]->name, "H2O")) @@ -5726,28 +5749,52 @@ calc_vm(LDBLE tc, LDBLE pa) s_x[i]->logk[vm_tc] = 18.016 / rho_0; continue; } - if (!s_x[i]->logk[vm0]) - continue; - /* the volume terms... */ - s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; - if (pa > 1.0) - s_x[i]->rxn_x->logk[vm_tc] -= s_x[i]->logk[kappa] * (pa - 1.0); - - if (s_x[i]->z) + if (s_x[i]->logk[vma1]) { - /* the ionic strength term * I^0.5... */ - if (s_x[i]->logk[b_Av] == 0) - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x); - else + /* supcrt volume at I = 0... */ + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vma1] + s_x[i]->logk[vma2] / (2600. + pb) + + s_x[i]->logk[vma3] / (TK - 228.) + s_x[i]->logk[vma4] / (2600. + pb) / (TK - 228.) - + s_x[i]->logk[wref] * QBrn; + /* A (small) correction by Shock et al., 1992, for 155 < tc < 255, P_sat < P < 1e3. + The vma1..a4 and wref numbers are refitted for major cations and anions on xpts, + probably invalidates the correction. */ + //if (dgdP && s_x[i]->z) + //{ + // LDBLE re = s_x[i]->z * s_x[i]->z / (s_x[i]->logk[wref] / 1.66027e5 + s_x[i]->z / 3.082); + // LDBLE Z3 = fabs(pow(s_x[i]->z, 3)) / re / re - s_x[i]->z / 9.498724; + // s_x[i]->rxn_x->logk[vm_tc] += ZBrn * 1.66027e5 * Z3 * dgdP; + //} + if (s_x[i]->z) { - /* limit the Debye-Hueckel slope by b... */ - LDBLE b = (s_x[i]->logk[b_Av] < 1e-5 ? 1e-5 : s_x[i]->logk[b_Av]); - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * - log(1 + b * sqrt(mu_x)) / b; + /* the ionic strength term * I^0.5... */ + if (s_x[i]->logk[b_Av] == 0) + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x); + else + { + /* limit the Debye-Hueckel slope by b... */ + LDBLE b = (s_x[i]->logk[b_Av] < 1e-5 ? 1e-5 : s_x[i]->logk[b_Av]); + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * + log(1 + b * sqrt(mu_x)) / b; + } + /* plus the volume terms * I... */ + LDBLE bi = s_x[i]->logk[vmi1] + s_x[i]->logk[vmi2] / (TK - 228.); // + s_x[i]->logk[vmi3] * TK); + s_x[i]->rxn_x->logk[vm_tc] += bi * mu_x; + } + // perhaps, add a term for neutral species * tot molality... + } + else if (s_x[i]->millero[0]) + { + /* Millero volume at I = 0... */ + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->millero[0] + tc * (s_x[i]->millero[1] + tc * s_x[i]->millero[2]); + if (s_x[i]->z) + { + /* the ionic strength terms... */ + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x) + + (s_x[i]->millero[3] + tc * (s_x[i]->millero[4] + tc * s_x[i]->millero[5])) * mu_x; } } - /* plus the volume terms * I... */ - s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->logk[vm3] + (s_x[i]->logk[vm4] + s_x[i]->logk[vm5] * tc) * tc) * mu_x; + else + continue; /* for calculating delta_v of the reaction... */ //s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; @@ -5781,6 +5828,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ #ifndef PHREEQC2 pa = patm_x; calc_dielectrics(tc_x, pa); + calc_dielectrics(tc, pa); #endif calc_vm(tc, pa); @@ -5808,8 +5856,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); #else phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - - (phases[i]->logk[vm0] + (phases[i]->logk[vm1] + phases[i]->logk[vm2] * tc) * tc - - phases[i]->logk[kappa] * (pa - 1)); + phases[i]->logk[vm0]; if (phases[i]->rxn_x->logk[delta_v]) mu_terms_in_logk = true; phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 9e14eea0..02381f13 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -1194,7 +1194,7 @@ print_saturation_indices(void) phases[i]->pr_in = false; } reaction_ptr->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - - (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc_x + phases[i]->logk[vm2] * tc_x * tc_x); + phases[i]->logk[vm0]; lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); if (PR_inprint) phases[i]->pr_in = true; @@ -1378,9 +1378,9 @@ print_species(void) { if (ICON == TRUE) { - output_msg(sformatf("%67s%11s\n", "MacInnes", "MacInnes")); - output_msg(sformatf("\t%-15s%12s%12s%10s%10s%10s\n", " ", - " ", "MacInnes", "Log ", "Log ", "Log ")); + output_msg(sformatf("%60s%10s\n", "MacInnes", "MacInnes")); + output_msg(sformatf("%40s%10s%10s%10s%10s\n", + "MacInnes", "Log", "Log", "Log", "mole V")); } else { @@ -1391,8 +1391,7 @@ print_species(void) } else { - output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n", " ", - " ", " ", "Log ", "Log ", "Log ", "mole V")); + output_msg(sformatf("%50s%10s%10s%10s\n", "Log", "Log", "Log", "mole V")); } output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n\n", "Species", "Molality", "Activity", "Molality", "Activity", "Gamma", "cm3/mol")); diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index af1fdd66..038b0bd4 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -2752,7 +2752,46 @@ read_omega_only(char *ptr, LDBLE *omega) } return OK; } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) +/* ---------------------------------------------------------------------- */ +{ + int j; + /* + * Read supcrt parms and Ionic strength terms + */ + for (j = 0; j < 9; j++) + { + delta_v[j] = 0.0; + } + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + /* a1..a4 */ + &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3]), + /* wref */ + &(delta_v[4]), + /* b_Av */ + &(delta_v[5]), + /* c1..c3 */ + &(delta_v[6]), &(delta_v[7]), &(delta_v[8])); + if (j < 1) + { + input_error++; + error_msg("Expecting numeric values for calculating the species' molar volume from the supcrt database.", + CONTINUE); + return (ERROR); + } + /* multiply with factors. a1 is in cal/mol/bar. a2 in cal/mol, a3, a4 in cal K/mol + 41.84004 converts cal/mol/bar to cm3/mol. */ + delta_v[0] *= 41.84004e-1; + delta_v[1] *= 41.84004e2; + delta_v[2] *= 41.84004; + delta_v[3] *= 41.84004e4; + /* wref in cal/mol/bar */ + delta_v[4] *= 1e5; + return (OK); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) @@ -2773,7 +2812,7 @@ read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) if (j < 1) { input_error++; - error_msg("Expecting numeric values for the species' molar volume, vm.", + error_msg("Expecting numeric value for the phase's molar volume, vm.", CONTINUE); return (ERROR); } @@ -2811,7 +2850,73 @@ read_vm_only(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) factor = 1e6; } - for (int i = 0; i < 4; i++) + for (int i = 0; i < 8; i++) + { + delta_v[i] *= factor; + } + } + return (OK); +} + +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_phase_vm(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) +/* ---------------------------------------------------------------------- */ +{ + int j, l; + char token[MAX_LENGTH]; + /* + * Read analytical expression + */ + for (j = 0; j < 1; j++) + { + delta_v[j] = 0.0; + } + j = sscanf(ptr, SCANFORMAT /*SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT*/, + &(delta_v[0])/*, &(delta_v[1]), &(delta_v[2]), &(delta_v[3]), + &(delta_v[4]), &(delta_v[5]), &(delta_v[6]), &(delta_v[7])*/); + if (j < 1) + { + input_error++; + error_msg("Expecting numeric value for the phase's molar volume, vm.", + CONTINUE); + return (ERROR); + } + /* + * Read delta V units + */ + *units = cm3_per_mol; + do + { + j = copy_token(token, &ptr, &l); + } while (j == DIGIT); + + if (j == EMPTY) + { + return (OK); + } + + LDBLE factor = 1.0; + if (j == UPPER || j == LOWER) + { + str_tolower(token); + if (strstr(token, "cm3") != NULL) + { + /* cm3/mol */ + ; + } + else if (strstr(token, "dm3") != NULL) + { + /* Convert dm3/mol to cm3/mol */ + factor = 1e3; + } + else if (strstr(token, "m3") != NULL) + { + /* Convert m3/mol to cm3/mol */ + factor = 1e6; + } + + for (int i = 0; i < 1; i++) { delta_v[i] *= factor; } @@ -3567,7 +3672,7 @@ read_phases(void) case 15: /* vm, molar volume */ if (phase_ptr == NULL) break; - read_vm_only(next_char, &(phase_ptr->logk[vm0]), + read_phase_vm(next_char, &(phase_ptr->logk[vm0]), &phase_ptr->original_deltav_units); phase_ptr->delta_v[1] = phase_ptr->logk[vm0]; opt_save = OPTION_DEFAULT; @@ -5012,7 +5117,7 @@ read_species(void) struct species *s_ptr; struct elt_list *next_elt; char *ptr, token[MAX_LENGTH]; - bool vm_read = false; + //bool vm_read = false; int return_value, opt, opt_save; char *next_char; const char *opt_list[] = { @@ -5040,7 +5145,7 @@ read_species(void) /* VP: Density Start */ "millero", /* 21 */ /* VP: Density End */ - "vm" /* 22, molar volume, must replace delta_v */ + "vm" /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */ }; int count_opt_list = 23; @@ -5057,7 +5162,7 @@ read_species(void) if (opt == OPTION_DEFAULT) { opt = opt_save; - vm_read = false; + //vm_read = false; } switch (opt) { @@ -5383,17 +5488,17 @@ read_species(void) break; } print_density = read_millero_abcdef (next_char, &(s_ptr->millero[0])); - if (!vm_read) - { - /* copy millero parms into logk, for calculating pressure dependency... */ - for (i = 0; i < 7; i++) - s_ptr->logk[vm0 + i] = s_ptr->millero[i]; - s_ptr->logk[vm0 + i] = 0; - } + //if (!vm_read) + //{ + ///* copy millero parms into logk, for calculating pressure dependency... */ + // for (i = 0; i < 7; i++) + // s_ptr->logk[vm0 + i] = s_ptr->millero[i]; + // s_ptr->logk[vm0 + i] = 0; + //} opt_save = OPTION_DEFAULT; break; /* VP: Density End */ - case 22: /* vm, molar volume */ + case 22: /* vm, supcrt parms + Ionic strength terms */ if (s_ptr == NULL) { error_string = sformatf( @@ -5403,9 +5508,8 @@ read_species(void) input_error++; break; } - read_vm_only(next_char, &s_ptr->logk[vm0], - &s_ptr->original_deltav_units); - vm_read = true; + read_aq_species_vm_parms(next_char, &s_ptr->logk[vma1]); + //vm_read = true; print_density = OK; opt_save = OPTION_DEFAULT; break; diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index 652a4deb..060210bc 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -115,11 +115,18 @@ calc_rho_0(LDBLE tc, LDBLE pa) Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + interpolation 0 - 300 oC, 0.006 - 1000 atm... */ - LDBLE T = tc + 273.15; // note... the new temp scale is + 273.16. Should be changed everywhere. - LDBLE p0 = 9.99843e2 + tc * ( 1.58729e-2 + tc * (-5.90233e-3 + tc * ( 1.96602e-5 + tc * -3.77118E-08))); - LDBLE p1 = 5.15090e-2 + tc * (-3.65419e-4 + tc * ( 5.36431e-6 + tc * (-2.74401e-8 + tc * 6.26304E-11))); - LDBLE p2 = -5.50294e-6 + tc * ( 1.07699e-7 + tc * (-2.05409e-9 + tc * ( 1.30238e-11 + tc * -3.20982E-14))); - + LDBLE T = tc + 273.15; + //eqn. 2.6... + LDBLE Tc = 647.096, th = 1 - T / Tc; + LDBLE b1 = 1.99274064, b2 = 1.09965342, b3 = -0.510839303, + b4 = -1.75493479, b5 = -45.5170352, b6 = -6.7469445e5; + rho_0 = 322.0 * (1.0 + b1 * pow(th, (LDBLE) 1./3.) + b2 * pow(th, (LDBLE) 2./3.) + b3 * pow(th, (LDBLE) 5./3.) +\ + b4 * pow(th, (LDBLE) 16./3.) + b5 * pow(th, (LDBLE) 43./3.) + b6 * pow(th, (LDBLE) 110./3)); + //pressure... + LDBLE p0 = 5.1880000E-02 + tc * (-4.1885519E-04 + tc * ( 6.6780748E-06 + tc * (-3.6648699E-08 + tc * 8.3501912E-11))); + LDBLE p1 = -6.0251348E-06 + tc * ( 3.6696407E-07 + tc * (-9.2056269E-09 + tc * ( 6.7024182E-11 + tc * -1.5947241E-13))); + LDBLE p2 = -2.2983596E-09 + tc * (-4.0133819E-10 + tc * ( 1.2619821E-11 + tc * (-9.8952363E-14 + tc * 2.3363281E-16))); + LDBLE p3 = 7.0517647E-11 + tc * ( 6.8566831E-12 + tc * (-2.2829750E-13 + tc * ( 1.8113313E-15 + tc * -4.2475324E-18))); /* The minimal pressure equals the saturation pressure... */ if (ah2o_x <= 1.0) p_sat = exp(11.6702 - 3816.44 / (T - 46.13)) * ah2o_x; @@ -132,22 +139,13 @@ calc_rho_0(LDBLE tc, LDBLE pa) } if (!use.Get_gas_phase_in()) patm_x = pa; - rho_0 = p0 + pa * (p1 + pa * p2); + pa -= (p_sat - 1e-6); + rho_0 += pa * (p0 + pa * (p1 + pa * (p2 + sqrt(pa) * p3))); if (rho_0 < 0.01) - rho_0 = 0.01; + rho_0 = 0.01; /* compressibility, d(ln(rho)) / d(P), 1/atm... */ - kappa_0 = (p1 + 2 * pa * p2) / rho_0; - - /* for tc < 99, P < 3 atm, use the more accurate eqn. 2.6... */ - if (tc <= 99 && pa < 3.0) - { - LDBLE Tc = 647.096, th = 1 - T / Tc; - LDBLE b1 = 1.99274064, b2 = 1.09965342, b3 = -0.510839303, - b4 = -1.75493479, b5 = -45.5170352, b6 = -6.7469445e5; - rho_0 = 322.0 * (1.0 + b1 * pow(th, (LDBLE) 1./3.) + b2 * pow(th, (LDBLE) 2./3.) + b3 * pow(th, (LDBLE) 5./3.) +\ - b4 * pow(th, (LDBLE) 16./3.) + b5 * pow(th, (LDBLE) 43./3.) + b6 * pow(th, (LDBLE) 110./3)); - } + kappa_0 = (p0 + pa * (2 * p1 + pa * (3 * p2 + sqrt(pa) * 3.5 * p3))) / rho_0; return (rho_0 / 1e3); } @@ -185,6 +183,27 @@ calc_dielectrics(LDBLE tc, LDBLE pa) DH_B /= 1e8; // kappa, 1/Angstrom + /* the Born functions, * 41.84 to give molal volumes in cm3/mol... */ + ZBrn = (- 1 / eps_r + 1.0) * 41.84004; + QBrn = c / (b + pa) / eps_r / eps_r * 41.84004; + /* dgdP from subroutine gShok2 in supcrt92, g is neglected here (at TK < 300)... + and, dgdP is small. Better, adapt Wref to experimental Vm's */ + dgdP = 0; + //if (tc > 150 && rho_0 < 1.0) + //{ + // LDBLE sc[7] = {1, -0.2037662e+01, 0.5747000e-02, -0.6557892e-05, + // 0.6107361e+01, -0.1074377e-01, 0.1268348e-04}; + // LDBLE csc[4] = {1, 0.3666666e+02, -0.1504956e-9, 0.5017997e-13}; + // LDBLE sa = sc[1] + tc * (sc[2] + tc * sc[3]); + // LDBLE sb = sc[4] + tc * (sc[5] + tc * sc[6]); + + // dgdP = - sa * sb * pow(1.0 - rho_0, sb - 1.0) * rho_0 * kappa_0 / 1.01325; + + // LDBLE ft = pow((tc - 155.0)/300.0, 4.8) + csc[1] * pow((tc - 155.0)/300.0, 16.0); + // LDBLE dfdP = ft * (-3.0 * csc[2] * pow(1000.0 - pa, 2) - 4.0 * csc[3] * pow(1000.0 - pa, 3)); + // dgdP -= dfdP; + //} + return (OK); } #endif @@ -1129,11 +1148,11 @@ strcmp_nocase_arg1(const char *str1, const char *str2) /* ---------------------------------------------------------------------- */ char * Phreeqc:: -#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) -_string_duplicate(const char *token, const char *szFileName, int nLine) -#else +//#if _DEBUG +//_string_duplicate(const char *token, const char *szFileName, int nLine) +//#else string_duplicate(const char *token) -#endif +//#endif /* ---------------------------------------------------------------------- */ { int l; @@ -1142,11 +1161,11 @@ string_duplicate(const char *token) if (token == NULL) return NULL; l = (int) strlen(token); -#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) - str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); -#else +//#if _DEBUG +// str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); +//#else str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); -#endif +//#endif if (str == NULL) malloc_error(); From 54c328a3e18a60b6e385be1c62f21fb18d5df2fd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 26 Apr 2012 16:14:18 +0000 Subject: [PATCH 0490/1077] equal_increments synonym in Kinetics. Increased max_tries in mainsubs for responding thread. removed extra calc_dielectrics in prep Tony's modifications to examples. New examples densities, phi_Angus, CO2_K_H. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6534 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 4 +++- phreeqc/mainsubs.cpp | 2 +- phreeqc/prep.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 49c61762..860aef0d 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -149,7 +149,7 @@ cxxKinetics::dump_raw(std::ostream & s_oss, unsigned int indent, int * n_out) co // equal_steps s_oss << indent1; - s_oss << "-equalIncrements " << this->equalIncrements << "\n"; + s_oss << "-equal_increments " << this->equalIncrements << "\n"; // equal_steps s_oss << indent1; @@ -202,6 +202,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) vopts.push_back("cvode_order"); vopts.push_back("equalincrements"); vopts.push_back("count"); + vopts.push_back("equal_increments"); } std::istream::pos_type ptr; @@ -392,6 +393,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) break; case 9: // equalIncrements + case 11: // equal_increments if (!(parser.get_iss() >> this->equalIncrements)) { this->use_cvode = false; diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 1f74394b..809fd17f 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -38,7 +38,7 @@ initialize(void) debug_diffuse_layer = FALSE; debug_inverse = FALSE; itmax = 100; - max_tries = 100; + max_tries = 1000; #ifdef USE_LONG_DOUBLE /* from float.h, sets tolerance for cl1 routine */ ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 590f1d73..23adf9bf 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -5827,7 +5827,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ rho_0 = calc_rho_0(tc, pa); #ifndef PHREEQC2 pa = patm_x; - calc_dielectrics(tc_x, pa); + //calc_dielectrics(tc_x, pa); calc_dielectrics(tc, pa); #endif calc_vm(tc, pa); From 2e6e2bc3ab8f4fabf0baed3ff764a53c149f874d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 27 Apr 2012 21:45:02 +0000 Subject: [PATCH 0491/1077] re-added malloc_dbg for string_duplicate git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6539 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/utilities.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index 060210bc..cf5327bb 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -1148,11 +1148,11 @@ strcmp_nocase_arg1(const char *str1, const char *str2) /* ---------------------------------------------------------------------- */ char * Phreeqc:: -//#if _DEBUG -//_string_duplicate(const char *token, const char *szFileName, int nLine) -//#else +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) +_string_duplicate(const char *token, const char *szFileName, int nLine) +#else string_duplicate(const char *token) -//#endif +#endif /* ---------------------------------------------------------------------- */ { int l; @@ -1161,11 +1161,11 @@ string_duplicate(const char *token) if (token == NULL) return NULL; l = (int) strlen(token); -//#if _DEBUG -// str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); -//#else +#if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) + str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); +#else str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); -//#endif +#endif if (str == NULL) malloc_error(); From 6a865f6555fdf862ed2d850d540629925bfd6596 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 28 Apr 2012 04:25:59 +0000 Subject: [PATCH 0492/1077] fixed minor assert git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6541 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/transport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index c846ba2e..473a9608 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -3855,7 +3855,7 @@ diff_stag_surf(int mobile_cell) for ( ; jit != Rxn_temp_surface_map.end(); jit++) { i = jit->first; - assert (i = jit->second.Get_n_user()); + assert(i == jit->second.Get_n_user()); if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) { continue; From cbba2c248dca0f64f41f785036b186191be1e8a2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 28 Apr 2012 04:28:06 +0000 Subject: [PATCH 0493/1077] added const versions for ChartHandler/ChartObject made ExtractCurveInfo static in order to use in phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6542 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.h | 6 +++++- ChartObject.cpp | 11 ++++++----- ChartObject.h | 14 +++++++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChartHandler.h b/ChartHandler.h index 33bba098..e8d5c0f2 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -15,7 +15,7 @@ public: ChartHandler(PHRQ_io *io = NULL); virtual ~ChartHandler(); - size_t Get_chart_count() + size_t Get_chart_count()const { return this->chart_map.size(); } @@ -23,6 +23,10 @@ public: { return this->current_chart; } + const ChartObject * Get_current_chart()const + { + return this->current_chart; + } bool Get_timer() { return timer; diff --git a/ChartObject.cpp b/ChartObject.cpp index 492e8037..0fd6b62d 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -433,7 +433,9 @@ ChartObject::Read(CParser & parser) if (cmd_lower.find("plot_xy") != std::string::npos) { //Curves are created in Basic cmds - ExtractCurveInfo(cmd); // truncates cmd + CurveObject new_curve = ExtractCurveInfo(cmd); // truncates cmd + // Add to list of new plotxy curves + this->new_plotxy_curves.push_back(new_curve); } this->rate_command_list.push_back(cmd); } @@ -605,13 +607,13 @@ ChartObject::OpenCSVFile(std::string file_name) return true; } -void +CurveObject ChartObject::ExtractCurveInfo(std::string & cmd_line) { /* plot_xy x, tot("Cl"), color = Red, symbol = Circle, symbol_size = 0.0, line_w = 1.0, y_axis = 2 */ // Make copy of cmd_line - int curvenr = (int) this->Curves.size(); + //int curvenr = (int) this->Curves.size(); std::string str_line = cmd_line; // Massage line @@ -738,9 +740,8 @@ ChartObject::ExtractCurveInfo(std::string & cmd_line) } } - // Add to list of new plotxy curves - this->new_plotxy_curves.push_back(new_curve); cmd_line = revised_line; + return new_curve; } void ChartObject::Set_rate_struct(void) diff --git a/ChartObject.h b/ChartObject.h index 43c18067..57c9f2b0 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -171,6 +171,10 @@ class ChartObject:public cxxNumKeyword { return this->user_graph; } + const struct rate *Get_user_graph()const + { + return this->user_graph; + } std::list &Get_rate_command_list() { return this->rate_command_list; @@ -205,6 +209,10 @@ class ChartObject:public cxxNumKeyword { return this->new_headings; } + const std::vector &Get_new_headings()const + { + return this->new_headings; + } void Set_active(bool tf) { this->active = tf; @@ -233,12 +241,16 @@ class ChartObject:public cxxNumKeyword { return this->phreeqc_ptr; } + const std::list& Get_rate_command_list_original()const + { + return this->rate_command_list_original; + } bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); bool Set_axis_scale(CParser & parser); bool Read(CParser & parser); bool OpenCSVFile(std::string fn); - void ExtractCurveInfo(std::string & str_line); + static CurveObject ExtractCurveInfo(std::string & str_line); void Set_rate_struct(void); void PlotXY(std::string x, std::string y); bool start_chart(void); From 07e9545fad8e8b57d46aa8f7568c375c2107c9eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 1 May 2012 15:13:07 +0000 Subject: [PATCH 0494/1077] clearloops after basic_run to avoid memory leak. PBasic.cpp. dump_entities checks for pr.dump. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6544 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 6 ++++++ ReadClass.cxx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 1cd5d344..95b709d1 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -291,6 +291,12 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) /* exit(EXIT_SUCCESS); */ PhreeqcPtr->PHRQ_free(inbuf); + + // Cleanup after run + clearvars(); + clearloops(); + restoredata(); + return (P_escapecode); } diff --git a/ReadClass.cxx b/ReadClass.cxx index f54b57dc..d5674080 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -223,7 +223,7 @@ int Phreeqc:: dump_entities(void) /* ---------------------------------------------------------------------- */ { - if (!dump_info.Get_on()) + if (!dump_info.Get_on() || pr.dump == FALSE) { return(OK); } From 204108a629c2abc687611a2cd78e06b4406dc0ae Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 1 May 2012 15:22:41 +0000 Subject: [PATCH 0495/1077] Latest examples header file for Linux PHRQ_io.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6546 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 743730fa..30eb8d3f 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -8,6 +8,7 @@ #include #include #include +#include PHRQ_io:: PHRQ_io(void) From d07b45cc10248ab19cc684e7207b5ac539dbdd7c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 May 2012 17:08:14 +0000 Subject: [PATCH 0496/1077] Revised logic for surf related to phase Adds/removes formula given in SURFACE warns in tidy if (1) element not in mineral formula (2) Not using master species (3) charge balance master species git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6550 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/prep.cpp | 19 ++++++++++++++----- phreeqc/tidy.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 23adf9bf..e4cac181 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -6386,8 +6386,8 @@ build_min_exch(void) { input_error++; error_string = sformatf( - "Did not find unknown for exchange related to mineral %s", - comp_ref.Get_phase_name().c_str()); + "Did not find unknown for %s, exchange related to mineral %s", + elt_list[jj].elt->primary->elt->name, comp_ref.Get_phase_name().c_str()); error_msg(error_string, STOP); } if (master_ptr->in == FALSE) @@ -6500,7 +6500,7 @@ build_min_surface(void) -comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); count_elts = 0; paren_count = 0; - +#ifdef SKIP if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) { /* Add formula for CD_MUSIC */ @@ -6514,6 +6514,15 @@ build_min_surface(void) /* Add master species for non CD_MUSIC */ add_elt_list(x[j]->master[0]->s->next_elt, 1.0); } +#endif + // + { + /* Add specified formula for all types of surfaces */ + char * formula = string_duplicate(comp_ptr->Get_formula().c_str()); + char *ptr1 = formula; + get_elts_in_species(&ptr1, 1.0); + free_check_null(formula); + } #ifdef COMBINE change_hydrogen_in_elt_list(0); #endif @@ -6528,8 +6537,8 @@ build_min_surface(void) { input_error++; error_string = sformatf( - "Did not find unknown for surface related to mineral %s", - comp_ptr->Get_phase_name().c_str()); + "Did not find unknown for %s, surface related to mineral %s", + elt_list[jj].elt->primary->elt->name, comp_ptr->Get_phase_name().c_str()); error_msg(error_string, STOP); } if (master_ptr->s->type == SURF) diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index c5b5682c..cc1d7fdb 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -3151,6 +3151,7 @@ tidy_min_surface(void) get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } +#ifdef SKIP for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) { cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]); @@ -3183,6 +3184,38 @@ tidy_min_surface(void) } } } +#endif + // Revise logic for surface related to mineral + for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) + { + cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]); + // Use formula for all types of surfaces + { + char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str()); + char *ptr = temp_formula; + get_elts_in_species(&ptr, + -comp_jj_ptr->Get_phase_proportion()); + + + // Warn if not master species and charge balanced + struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); + if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) + { + error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", + elt_ptr->master->s->name); + warning_msg(error_string); + } + else + if (elt_ptr->master->s->z != 0.0) + { + error_string = sformatf( + "Master species of surface, %s, should be uncharged for surface related to equilibrium_phase.", + elt_ptr->master->s->name); + warning_msg(error_string); + } + free_check_null(temp_formula); + } + } qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); elt_list_combine(); @@ -3197,21 +3230,22 @@ tidy_min_surface(void) { if (elt_list[jj].elt->primary->s->type != SURF && elt_list[jj].coef < 0 - && elt_list[jj].elt->primary->s != s_hplus - && elt_list[jj].elt->primary->s != s_h2o) + //&& elt_list[jj].elt->primary->s != s_hplus + //&& elt_list[jj].elt->primary->s != s_h2o + ) { struct element *elt_ptr = element_store(surface_comp_ptr->Get_master_element().c_str()); - input_error++; error_string = sformatf( "Element %s in sum of surface sites,\n" - "\tincluding %s * %g mol sites/mol phase,\n" - "\texceeds stoichiometry in the related phase %s, %s.", + "\t including %s * %g mol sites/mol phase,\n" + "\t exceeds stoichiometry in the related phase %s, %s.", elt_list[jj].elt->name, elt_ptr->master->s->name, (double) surface_comp_ptr->Get_phase_proportion(), phase_ptr->name, phase_ptr->formula); - error_msg(error_string, CONTINUE); + warning_msg(error_string); + warning_msg("The mismatch in stoichiometry may cause mass-balance errors or unwanted redox reactions."); break; } } From 3f982ac5456ff66c76863a84bc565318eda87035 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 May 2012 19:22:05 +0000 Subject: [PATCH 0497/1077] Don't check zero charge for CD_MUSIC master species in surface related to charge. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6552 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tidy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index cc1d7fdb..783bc55e 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -3206,10 +3206,10 @@ tidy_min_surface(void) warning_msg(error_string); } else - if (elt_ptr->master->s->z != 0.0) + if (elt_ptr->master->s->z != 0.0 && surface_ptr->Get_type() != cxxSurface::CD_MUSIC) { error_string = sformatf( - "Master species of surface, %s, should be uncharged for surface related to equilibrium_phase.", + "Suggest master species of surface, %s, be uncharged for surface related to equilibrium_phase.", elt_ptr->master->s->name); warning_msg(error_string); } From 0eef11872d28cc82bd9e4faf4f0ad7262dd86d50 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 2 May 2012 20:04:50 +0000 Subject: [PATCH 0498/1077] Modified for new handling of surf related to phase. Input files now have charge balanced formula. Not checking cdmusic surfaces for surface master species as formula or charge balanced surface master species. deleted error.inp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6553 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tidy.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 783bc55e..969214f2 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -3196,24 +3196,27 @@ tidy_min_surface(void) get_elts_in_species(&ptr, -comp_jj_ptr->Get_phase_proportion()); + if (surface_ptr->Get_type() != cxxSurface::CD_MUSIC) + { - // Warn if not master species and charge balanced - struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); - if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) - { - error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", - elt_ptr->master->s->name); - warning_msg(error_string); - } - else - if (elt_ptr->master->s->z != 0.0 && surface_ptr->Get_type() != cxxSurface::CD_MUSIC) - { - error_string = sformatf( + // Warn if not master species and charge balanced + struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); + if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) + { + error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", + elt_ptr->master->s->name); + warning_msg(error_string); + } + else + if (elt_ptr->master->s->z != 0.0) + { + error_string = sformatf( "Suggest master species of surface, %s, be uncharged for surface related to equilibrium_phase.", elt_ptr->master->s->name); - warning_msg(error_string); - } - free_check_null(temp_formula); + warning_msg(error_string); + } + free_check_null(temp_formula); + } } } qsort(elt_list, (size_t) count_elts, From 693e36ce93d95bc335a93c449c9ffe7cde073d1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 17 May 2012 20:54:17 +0000 Subject: [PATCH 0499/1077] Tony's changes through May 16. New databases. new example rho_CaNaCl new source integrate, mainsubs, model, PHRQ_io_output, utilities. New fm examples, input, intro, refs. My changes to Basic.fm. New manual examples ex2b and ex22. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6563 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/PHRQ_io_output.cpp | 4 ++++ phreeqc/integrate.cpp | 20 +++++++++++++++----- phreeqc/mainsubs.cpp | 7 ++++--- phreeqc/model.cpp | 10 ++++++++-- phreeqc/utilities.cpp | 2 +- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index 250cf2b8..0e3f4dbb 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -593,6 +593,10 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, #endif error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); screen_msg(error_string); +#ifdef NPP + error_msg(sformatf( "\nERROR: Can't open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP); + break; +#endif error_flush(); batch = FALSE; continue; diff --git a/phreeqc/integrate.cpp b/phreeqc/integrate.cpp index 1d6c080b..73c688ae 100644 --- a/phreeqc/integrate.cpp +++ b/phreeqc/integrate.cpp @@ -46,7 +46,9 @@ calc_all_g(void) xd_global = exp(-2 * x[j]->master[0]->s->la * LOG_10); /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ /* 1000 J/kJ and 1000 L/m**3 */ - alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * + //alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * + // tk_x * 0.5); + alpha_global = sqrt(eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); /* * calculate g for given surface for each species @@ -464,7 +466,9 @@ calc_init_g(void) xd_global = exp(-2 * x[j]->master[0]->s->la * LOG_10); /* alpha = 0.02935 @ 25; (ee0RT/2)**1/2, (L/mol)**1/2 C / m**2 */ /* second 1000 is liters/m**3 */ - alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + //alpha_global = sqrt(EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + // 1000.0 * tk_x * 0.5); + alpha_global = sqrt(eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * 1000.0 * tk_x * 0.5); if (charge_ptr->Get_g_map().size() == 0) @@ -548,7 +552,9 @@ initial_surface_water(void) * * 1000 converts kJ to J; 1000 converts Liters to meter**3; debye_length is in meters. */ - debye_length = (EPSILON * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) + //debye_length = (EPSILON * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) + // / (2. * F_C_MOL * F_C_MOL * mu_x * 1000.); + debye_length = (eps_r * EPSILON_ZERO * R_KJ_DEG_MOL * 1000.0 * tk_x) / (2. * F_C_MOL * F_C_MOL * mu_x * 1000.); debye_length = sqrt(debye_length); @@ -726,7 +732,9 @@ calc_all_donnan(void) if (use.Get_surface_ptr() == NULL) return (OK); - f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + //f_sinh = sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + // tk_x * mu_x); + f_sinh = sqrt(8000.0 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); cz = cm = 1.0; cp = 1.0; @@ -866,7 +874,9 @@ calc_init_donnan(void) if (use.Get_surface_ptr() == NULL) return (OK); f_sinh = - sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + //sqrt(8000.0 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * + // tk_x * mu_x); + sqrt(8000.0 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); if (convergence_tolerance >= 1e-8) { diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 809fd17f..c3c18225 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2739,9 +2739,10 @@ do_status(void) #endif screen_msg("\n"); } - dup_print("End of run.", TRUE); - screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", - (double) clock() / CLOCKS_PER_SEC)); + pr.headings = TRUE; + LDBLE ext = (double) clock() / CLOCKS_PER_SEC; + dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE); + screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext)); } catch (PhreeqcStop e) { diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 65e05b95..dc6d8c69 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -2040,7 +2040,9 @@ jacobian_sums(void) if (surface_unknown != NULL && dl_type_x == cxxSurface::NO_DL) { sinh_constant = - sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * + //sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * + // 1000); + sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); for (i = 0; i < count_unknowns; i++) { @@ -4055,7 +4057,9 @@ residuals(void) { /*sinh_constant = 0.1174; */ sinh_constant = - sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + //sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + // tk_x * 1000); + sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); /* if (x[i]->surface_charge->grams <= MIN_RELATED_SURFACE) { */ cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); @@ -4254,6 +4258,8 @@ residuals(void) sinh_constant = sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); + sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + tk_x * 1000); /* * sinh_constant is (8 e e0 R T 1000)**1/2 * = sqrt(8*EPSILON*EPSILON_ZERO*(R_KJ_DEG_MOL*1000)*t_x*1000) diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index cf5327bb..461ba8d1 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -186,7 +186,7 @@ calc_dielectrics(LDBLE tc, LDBLE pa) /* the Born functions, * 41.84 to give molal volumes in cm3/mol... */ ZBrn = (- 1 / eps_r + 1.0) * 41.84004; QBrn = c / (b + pa) / eps_r / eps_r * 41.84004; - /* dgdP from subroutine gShok2 in supcrt92, g is neglected here (at TK < 300)... + /* dgdP from subroutine gShok2 in supcrt92, g is neglected here (at tc < 300)... and, dgdP is small. Better, adapt Wref to experimental Vm's */ dgdP = 0; //if (tc > 150 && rho_0 < 1.0) From 94460826edd3b521eb6fc1d056989b733e1cea96 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 22 May 2012 20:00:52 +0000 Subject: [PATCH 0500/1077] Added toggle background. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6579 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index af14fe82..46674cc4 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -33,6 +33,7 @@ namespace zdg_ui2 { symbol_use = 0; Y2 = false; phreeqc_done = false; + background = true; } public: Form1(ChartObject *ptr) @@ -45,6 +46,7 @@ namespace zdg_ui2 { Y2 = false; phreeqc_done = false; Y2show = false; + background = true; } static void ThreadForm(Object^ data) { @@ -129,6 +131,7 @@ namespace zdg_ui2 { int col_use, symbol_use; bool Y2, Y2show; static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; + bool background; void DefineCurves(GraphPane ^myPane, int init) { @@ -363,7 +366,14 @@ namespace zdg_ui2 { // Fill the axis background with a gradient //myPane->Chart->Fill = gcnew Fill( Color::White, Color::LightYellow, 45.0f ); /* FromArgb(255, 255, 224) */ - myPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + if (this->background) + { + myPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + } + else + { + myPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + } // normalize pane size... myPane->BaseDimension = 8.0F; @@ -469,6 +479,11 @@ namespace zdg_ui2 { item2->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SaveCurves ); menuStrip->Items->Insert(0, item2 ); + ToolStripMenuItem ^item3 = gcnew ToolStripMenuItem(); + item3->Text = L"Toggle Background"; + item3->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleBackground ); + menuStrip->Items->Insert(0, item3 ); + } void form_error_msg( std::string estring ) @@ -675,6 +690,21 @@ namespace zdg_ui2 { { // Here we get notification everytime the user zooms } + + void ToggleBackground( System::Object ^sender, System::EventArgs ^e ) + { + this->background = !this->background; + if (this->background) + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + } + else + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + } + zg1->Refresh(); + } + private: void timer1_Tick(System::Object ^sender, System::EventArgs ^e ) { LineItem ^curve; From 1510698e75110ee940b4f94f47ca7949bc917643 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 22 May 2012 23:30:37 +0000 Subject: [PATCH 0501/1077] Write image without red hints in boxes. Toggle hints. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6582 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 67 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 46674cc4..e74d5da7 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -34,7 +34,7 @@ namespace zdg_ui2 { Y2 = false; phreeqc_done = false; background = true; - + hints = true; } public: Form1(ChartObject *ptr) { @@ -47,6 +47,7 @@ namespace zdg_ui2 { phreeqc_done = false; Y2show = false; background = true; + hints = true; } static void ThreadForm(Object^ data) { @@ -132,6 +133,10 @@ namespace zdg_ui2 { bool Y2, Y2show; static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; bool background; + bool hints; + + ZedGraph::GraphObjList ^GOL_no_hints; + ZedGraph::GraphObjList ^GOL_hints; void DefineCurves(GraphPane ^myPane, int init) { @@ -397,6 +402,8 @@ namespace zdg_ui2 { DefineCurves(myPane, 0); // Add text boxes with instructions... + GOL_no_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); + TextObj ^text; text = gcnew TextObj( L" Click right mouse for options... \0", @@ -415,6 +422,16 @@ namespace zdg_ui2 { text->ZOrder = ZOrder::H_BehindAll; myPane->GraphObjList->Add( text ); + GOL_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); + if (this->hints) + { + myPane->GraphObjList = GOL_hints; + } + else + { + myPane->GraphObjList = GOL_no_hints; + } + // Enable scrollbars if needed... /*z1->IsShowHScrollBar = true; z1->IsShowVScrollBar = true; @@ -469,21 +486,36 @@ namespace zdg_ui2 { System::Windows::Forms::ContextMenuStrip ^menuStrip, Point mousePt, ZedGraphControl::ContextMenuObjectState objState ) { + + // removes Copy + menuStrip->Items->RemoveAt(0); + // removes Save Image As + menuStrip->Items->RemoveAt(0); + ToolStripMenuItem ^item = gcnew ToolStripMenuItem(); item->Text = L"Zoom: left mouse + drag\nPan: middle mouse + drag"; menuStrip->Items->Insert(5, item ); - menuStrip->Items->RemoveAt(0); - ToolStripMenuItem ^item2 = gcnew ToolStripMenuItem(); - item2->Text = L"Save Data to File..."; - item2->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SaveCurves ); - menuStrip->Items->Insert(0, item2 ); - ToolStripMenuItem ^item3 = gcnew ToolStripMenuItem(); item3->Text = L"Toggle Background"; item3->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleBackground ); menuStrip->Items->Insert(0, item3 ); + ToolStripMenuItem ^item5 = gcnew ToolStripMenuItem(); + item5->Text = L"Toggle Hints"; + item5->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleHints ); + menuStrip->Items->Insert(0, item5 ); + + ToolStripMenuItem ^item2 = gcnew ToolStripMenuItem(); + item2->Text = L"Save Data to File..."; + item2->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SaveCurves ); + menuStrip->Items->Insert(0, item2 ); + + ToolStripMenuItem ^item4 = gcnew ToolStripMenuItem(); + item4->Text = L"Save Image As..."; + item4->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SaveImage ); + menuStrip->Items->Insert(0, item4 ); + } void form_error_msg( std::string estring ) @@ -705,6 +737,27 @@ namespace zdg_ui2 { zg1->Refresh(); } + void ToggleHints( System::Object ^sender, System::EventArgs ^e ) + { + this->hints = !this->hints; + if (this->hints) + { + zg1->GraphPane->GraphObjList = GOL_hints; + } + else + { + zg1->GraphPane->GraphObjList = GOL_no_hints; + } + zg1->Refresh(); + } + void SaveImage( System::Object ^sender, System::EventArgs ^e ) + { + ZedGraph::GraphObjList ^copy = gcnew ZedGraph::GraphObjList(zg1->GraphPane->GraphObjList); + zg1->GraphPane->GraphObjList = GOL_no_hints; + zg1->SaveAs(); + zg1->GraphPane->GraphObjList = copy; + } + private: void timer1_Tick(System::Object ^sender, System::EventArgs ^e ) { LineItem ^curve; From b984ef5a61de15031396b12ef3b1b17f7f51c466 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 23 May 2012 15:18:27 +0000 Subject: [PATCH 0502/1077] Tony added function DH and Qbrn. Added Cyan, Brown, Lime, Gray. NPP def for PHRQ_io_output git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6583 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 4 ++++ PBasic.cpp | 30 +++++++++++++++++++++++++++++- PBasic.h | 6 +++++- phreeqc/Form1.h | 2 +- phreeqc/PHRQ_io_output.cpp | 4 +++- 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 0fd6b62d..3348e4e5 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -55,6 +55,10 @@ cxxNumKeyword(io) Color_vector.push_back("Magenta"); Color_vector.push_back("Yellow"); Color_vector.push_back("Black"); + Color_vector.push_back("Cyan"); + Color_vector.push_back("Brown"); + Color_vector.push_back("Lime"); + Color_vector.push_back("Gray"); chart_title.clear(); axis_titles.clear(); diff --git a/PBasic.cpp b/PBasic.cpp index 95b709d1..9000abe3 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1502,6 +1502,18 @@ listtokens(FILE * f, tokenrec * l_buf) case tokvm: output_msg("VM"); // mole volume of aqueous solute break; + case tokdh_a: + output_msg("DH_A"); // Debye-Hueckel A + break; + case tokdh_b: + output_msg("DH_B"); // Debye-Hueckel B + break; + case tokdh_av: + output_msg("DH_Av"); // Debye-Hueckel Av + break; + case tokqbrn: + output_msg("QBrn"); // Q_Born, d(eps_r)/d(P)/(eps_r^2) + break; } l_buf = l_buf->next; } @@ -3062,6 +3074,18 @@ factor(struct LOC_exec * LINK) case tokeps_r: n.UU.val = PhreeqcPtr->eps_r; break; + case tokdh_a: + n.UU.val = PhreeqcPtr->DH_A; + break; + case tokdh_b: + n.UU.val = PhreeqcPtr->DH_B; + break; + case tokdh_av: + n.UU.val = PhreeqcPtr->DH_Av; + break; + case tokqbrn: + n.UU.val = PhreeqcPtr->QBrn; + break; case toklog10: n.UU.val = log10(realfactor(LINK)); break; @@ -6366,7 +6390,11 @@ const std::map::value_type temp_tokens[] std::map::value_type("gas_vm", PBasic::tokgas_vm), std::map::value_type("pressure", PBasic::tokpressure), std::map::value_type("eps_r", PBasic::tokeps_r), - std::map::value_type("vm", PBasic::tokvm) + std::map::value_type("vm", PBasic::tokvm), + std::map::value_type("dh_a", PBasic::tokdh_a), + std::map::value_type("dh_b", PBasic::tokdh_b), + std::map::value_type("dh_av", PBasic::tokdh_av), + std::map::value_type("qbrn", PBasic::tokqbrn) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 4213c483..2075b883 100644 --- a/PBasic.h +++ b/PBasic.h @@ -303,7 +303,11 @@ public: tokpressure, tokerase, tokeps_r, - tokvm + tokvm, + tokdh_a, + tokdh_b, + tokdh_av, + tokqbrn }; #if !defined(PHREEQCI_GUI) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index e74d5da7..f3291604 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -131,7 +131,7 @@ namespace zdg_ui2 { private: PointPairList ^list; int col_use, symbol_use; bool Y2, Y2show; - static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black" }; + static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black", "Cyan", "Brown", "Lime", "Gray" }; bool background; bool hints; diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index 0e3f4dbb..ee0a9a0b 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -328,7 +328,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, delete local_database_file; screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); - +#ifdef NPP + output_msg(sformatf("Using PHREEQC: version 3.beta, compiled on May 22, 2012\n")); +#endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); output_msg(sformatf("Database file: %s\n\n", token)); From 6dd55677f509d5d7f8b5baf912ac5bf650f96ddd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 24 May 2012 01:16:21 +0000 Subject: [PATCH 0503/1077] Added -batch option to USER_GRAPH. Finally got emf working. Has a memory error somewhere. Heap gets corrupted when running debug mode and -batch fn defined. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6584 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 60 +++++++++++ ChartObject.h | 29 ++++- phreeqc/Form1.h | 275 ++++++++++++++++++++++-------------------------- 3 files changed, 211 insertions(+), 153 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 3348e4e5..b7365ff6 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -105,6 +105,9 @@ cxxNumKeyword(io) form_started = false; active = true; detach = false; + + batch_background = true; + batch = ChO_NO_BATCH; } ChartObject::~ChartObject() @@ -257,6 +260,7 @@ ChartObject::Read(CParser & parser) vopts.push_back("clear"); // 13 vopts.push_back("detach"); // 14 vopts.push_back("active"); // 15 + vopts.push_back("batch"); // 16 } std::istream::pos_type ptr; @@ -414,6 +418,62 @@ ChartObject::Read(CParser & parser) this->active = parser.get_true_false(next_char, true); break; /* End of modifications */ + case 16: /* batch */ + { + this->batch = ChartObject::ChO_BATCH_ONLY; + + std::string file_name; + if (parser.copy_token(file_name, next_char) != CParser::TT_EMPTY) + { + //Get suffix from file_name + size_t ssi = file_name.rfind('.'); + if (ssi == std::string::npos) + { + std::ostringstream estream; + estream << "Batch file name must have suffix emf, phg, jpg, gif, tiff, or bmp."; + error_msg(estream.str().c_str(), CONTINUE); + break; + } + + std::string suffix = file_name.substr(ssi + 1); + Utilities::str_tolower(suffix); + if (suffix == "emf") + this->batch = ChartObject::ChO_EMF; + else if (suffix == "png") + this->batch = ChartObject::ChO_PNG; + else if (suffix == "jpg") + this->batch = ChartObject::ChO_JPG; + else if (suffix == "gif") + this->batch = ChartObject::ChO_GIF; + else if (suffix == "tiff") + this->batch = ChartObject::ChO_TIFF; + else if (suffix == "bmp") + this->batch = ChartObject::ChO_BMP; + else if (suffix == "jpeg") + this->batch = ChartObject::ChO_JPG; + else + { + std::ostringstream estream; + estream << "Batch file name must have suffix emf, phg, jpg, jpeg, gif, tiff, or bmp."; + error_msg(estream.str().c_str(), CONTINUE); + break; + } + this->batch_fn = file_name; + + // Get background bool + parser.copy_token(token, next_char); + if (token.size() > 0) + { + Utilities::str_tolower(token); + if (token[0] == 'f') + { + this->batch_background = false; + } + } + } + + } + break; case CParser::OPT_DEFAULT: // Read Basic commands { if (!new_command_lines) diff --git a/ChartObject.h b/ChartObject.h index 57c9f2b0..44d981dc 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -19,6 +19,17 @@ class ChartObject:public cxxNumKeyword ChartObject(int i, PHRQ_io *io=NULL); ~ChartObject(); + enum chart_batch_type + { ChO_NO_BATCH = -1, + ChO_BATCH_ONLY = 0, + ChO_EMF = 1, + ChO_PNG = 2, + ChO_JPG = 3, + ChO_GIF = 4, + ChO_TIFF = 5, + ChO_BMP = 6 + }; + bool Get_new_ug() { return this->new_ug; @@ -51,6 +62,14 @@ class ChartObject:public cxxNumKeyword { return this->chart_title; } + std::string Get_batch_fn() + { + return this->batch_fn; + } + void Set_batch_fn(std::string fn) + { + this->batch_fn = fn; + } std::vector &Get_axis_titles() { return this->axis_titles; @@ -245,7 +264,6 @@ class ChartObject:public cxxNumKeyword { return this->rate_command_list_original; } - bool Set_axis_scale(std::vector, std::vector types, std::ostringstream &); bool Set_axis_scale(CParser & parser); bool Read(CParser & parser); @@ -271,6 +289,11 @@ class ChartObject:public cxxNumKeyword int y_axis = 1, std::string color = ""); void dump(std::ostream & s_oss, unsigned int indent); + + chart_batch_type Get_batch(void) {return this->batch;} + void Set_batch(chart_batch_type bt) {this->batch = bt;} + bool Get_batch_background(void) {return this->batch_background;} + void Set_batch_background(bool tf) {this->batch_background = tf;} protected: bool new_ug; @@ -340,6 +363,10 @@ class ChartObject:public cxxNumKeyword bool form_started; class Phreeqc * phreeqc_ptr; + bool batch_background; + std::string batch_fn; + chart_batch_type batch; + public: int usingResource; diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index f3291604..21c54a7b 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -1,15 +1,21 @@ #pragma once +#include #include #define P_INSTANCE_POINTER1 phreeqc_ptr-> + namespace zdg_ui2 { using namespace System; //using namespace System::ComponentModel; using namespace System::Resources; using namespace System::Windows::Forms; using namespace System::Drawing; + using namespace System::Drawing::Imaging; using namespace System::Threading; using namespace ZedGraph; - + //using namespace System::Runtime::InteropServices; + //[DllImport("gdi32.dll")] + ////extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::Text::StringBuilder* hNULL); + //extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, String^ hNULL); // Form1 is only used with MULTICHART public ref class ChartObj : public System::Object { @@ -757,7 +763,117 @@ namespace zdg_ui2 { zg1->SaveAs(); zg1->GraphPane->GraphObjList = copy; } + void BatchSaveImage( ) + { + ChartObject *chart = this->chartobject_ptr; + assert(chart->Get_batch() > 0); + // Save GraphObjList + ZedGraph::GraphObjList ^GOL_copy = gcnew ZedGraph::GraphObjList(zg1->GraphPane->GraphObjList); + // Don't write red hint boxes + zg1->GraphPane->GraphObjList = GOL_no_hints; + + // Set background + if (chart->Get_batch_background()) + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + } + else + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + } + + // Save the graph + if (this->zg1) + { + ImageFormat ^format = ImageFormat::Png; + switch (chart->Get_batch()) + { + case 2: + format = ImageFormat::Png; + break; + case 3: + format = ImageFormat::Gif; + break; + case 4: + format = ImageFormat::Jpeg; + break; + case 5: + format = ImageFormat::Tiff; + break; + case 6: + format = ImageFormat::Bmp; + break; + default: + break; + } + switch (chart->Get_batch()) + { + case 1: // emf + //SaveEmfFile( ); + { + //using namespace System::Runtime::InteropServices; + //[DllImport("user32.dll")] + ////extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::Text::StringBuilder* hNULL); + //extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::String* hNULL); + System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); + //System::Drawing::Graphics ^g = this->zg1->CreateGraphics(); + //IntPtr hdc = g->GetHdc(); + //System::Drawing::Imaging::Metafile ^metaFile = gcnew System::Drawing::Imaging::Metafile(hdc, EmfType::EmfPlusOnly); + System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); + //Graphics ^gMeta = Graphics::FromImage(metaFile); + //zg1->MasterPane->Draw(gMeta); + //System::IO::FileStream ^mySream = gcnew System::IO::FileStream(fn, System::IO::FileMode::Create); + //metaFile->Save(chart->Get_batch_fn()); + //ClipboardMetafileHelper.SaveEnhMetafileToFile(metaFile, fileName ); + //System::Runtime::InteropServices::ClipboardMetafileHelper->SaveEnhMetafileToFile(metaFile, fileName ); + metaFile->Save(fn); + + //IntPtr hEMF; + //hEMF = metaFile->GetHenhmetafile(); // invalidates mf + //if (!hEMF.Equals(gcnew IntPtr(0))) + //{ + // System::Text::StringBuilder ^filename = gcnew System::Text::StringBuilder("test.emf", 250); + // //System::Text::StringBuilder temp = new System::Text::StringBuilder(filename); + // System::IO::FileStream ^myStream = gcnew System::IO::FileStream("phreeqc.png", System::IO::FileMode::Create); + // System::Text::StringBuilder x1("test.emf"); + // CopyEnhMetaFile(hEMF, "test.emf"); + //} + //DeleteEnhMetaFile(hEMF); + //g->ReleaseHdc(hdc); + } + break; + case 2: // bitmaps + case 3: + case 4: + case 5: + case 6: + { + System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); + System::IO::FileStream ^myStream = gcnew System::IO::FileStream(fn, System::IO::FileMode::Create); + zg1->MasterPane->GetImage()->Save( myStream, format); + myStream->Close(); + } + default: + break; + } + } + +#if 0 + // reset GraphObjList + zg1->GraphPane->GraphObjList = GOL_copy; + + // reset background + if (this->background) + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + } + else + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + } +#endif + } private: void timer1_Tick(System::Object ^sender, System::EventArgs ^e ) { LineItem ^curve; @@ -885,43 +1001,18 @@ namespace zdg_ui2 { chart->Set_done(true); phreeqc_done = true; - //std::string str; - // - - //System::Runtime::Serialization::SerializationInfo ^info; - ////System::Runtime::Serialization::SerializationInfo ^info = gcnew System::Runtime::Serialization::SerializationInfo(); - ////System::Runtime::Serialization::StreamingContext context; - //System::IO::Stream ^strm = System::IO::File::Create("serialize"); - //zg1->GraphPane->GetObjectData(info, strm); - // - //this->ToString(info->ToString(), str); - //std::cerr << str; - + int batch = chart->Get_batch(); + if (chart->Get_batch() > 0) { - //// Debugging check - //std::vector Curves = chart->Get_CurvesCSV(); - //size_t i; - //for (i = 0; i < chart->Get_Curves().size(); i++) - //{ - // Curves.push_back(chart->Get_Curves()[i]); - //} - //for (i = 0; i < (size_t) zg1->GraphPane->CurveList->Count; i++) - //{ - // if (zg1->GraphPane->CurveList[i]->Points->Count != - // Curves[i]->Get_x().size()) - // { - // std::cerr << "Form: " << i << "\t" << zg1->GraphPane->CurveList[i]->Points->Count << std::endl; - // std::cerr << "Curves: " << i << "\t" << Curves[i]->Get_x().size() << std::endl; - // //form_error_msg("Did not plot all points. Why?"); - // } - // assert (zg1->GraphPane->CurveList[i]->Points->Count == - // Curves[i]->Get_x().size()); - //} + BatchSaveImage(); } + //unlock thread before setting chartobject_ptr to NULL System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; + if (batch >= 0) + this->Close(); return; } @@ -931,126 +1022,6 @@ namespace zdg_ui2 { return; } - private: void timer1_Tick_old(System::Object ^sender, System::EventArgs ^e ) - { - LineItem ^curve; - ChartObject *chart = this->chartobject_ptr; - if (chart == NULL) return; - //std::cerr << "timer1_Tick." << std::endl; - //lock for thread - while (0 != System::Threading::Interlocked::Exchange(chart->usingResource, 1)) - System::Threading::Thread::Sleep(1); - - std::vector Curves; - size_t i; - for (i = 0; i < chart->Get_CurvesCSV().size(); i++) - { - Curves.push_back(chart->Get_CurvesCSV()[i]); - } - for (i = 0; i < chart->Get_Curves().size(); i++) - { - Curves.push_back(chart->Get_Curves()[i]); - } - - if ( ((Environment::TickCount - tickStart ) > this->chartobject_ptr->Get_update_time_chart()) - || chart->Get_end_timer() ) { - if (this->chartobject_ptr->Get_curve_added()) - { - DefineCurves(zg1->GraphPane, zg1->GraphPane->CurveList->Count); - - } - else if (this->chartobject_ptr->Get_point_added()) - { - // Add points to curves ... - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - // Get the PointPairList - IPointListEdit ^ip = (IPointListEdit^) curve->Points; - if ((size_t) ip->Count < Curves[i]->Get_x().size()) - { - - if (Curves[i]->Get_y_axis() == 2) - Y2 = true; - else - Y2 = false; - for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) - { - if ((LogX && Curves[i]->Get_x()[i2] <=0) - || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) - || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) - continue; - else - ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); - } - } - } - - /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ - if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - if (Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1] > max) - max = Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1]; - } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->XAxis->Scale->Max = max; - } - if ((fabs(chart->Get_axis_scale_y()[1] - NA) < 1e-3) && zg1->GraphPane->YAxis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - if (curve->IsY2Axis) continue; - if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) - max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; - } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->YAxis->Scale->Max = max; - } - if ((fabs(chart->Get_axis_scale_y2()[1] - NA) < 1e-3) && zg1->GraphPane->Y2Axis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - if (!curve->IsY2Axis) continue; - if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) - max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; - } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->Y2Axis->Scale->Max = max; - } - - zg1->AxisChange(); - zg1->Refresh(); - tickStart = Environment::TickCount; - } - } - chart->Set_point_added(false); - if (chart->Get_end_timer()) - { - //std::cerr << "Form got end_timer message." << std::endl; - zg1->Refresh(); - timer1->Stop(); - chart->Set_done(true); - phreeqc_done = true; - //unlock thread - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); - this->phreeqc_ptr = NULL; - this->chartobject_ptr = NULL; - //std::cerr << "Form released thread, pointers null." << std::endl; - } - else - { - //unlock thread - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); - } - return; - } void ToString(System::String^ src, std::string& dest) { using namespace System::Runtime::InteropServices; From 4a8e2ca9dd6a6cdbc6286c90a607bc5e778c7384 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 24 May 2012 05:20:49 +0000 Subject: [PATCH 0504/1077] fixed heap error: HEAP[phreeqcpp.exe]: HEAP: Free Heap block XXXXXXX modified at XXXXXXX after it was freed Windows has triggered a breakpoint in phreeqcpp.exe. This may be due to a corruption of the heap, which indicates a bug in phreeqcpp.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while phreeqcpp.exe has focus. Contains temporary code before cleanup git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6585 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 4 ++++ phreeqc/Form1.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index b7365ff6..e1ce3834 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -112,6 +112,10 @@ cxxNumKeyword(io) ChartObject::~ChartObject() { + while (0 != System::Threading::Interlocked::Exchange(this->usingResource, 1)) + { + System::Threading::Thread::Sleep(1); + } this->Rate_free(); delete this->user_graph; diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 21c54a7b..00cb9323 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -816,18 +816,18 @@ namespace zdg_ui2 { //[DllImport("user32.dll")] ////extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::Text::StringBuilder* hNULL); //extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::String* hNULL); - System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); +// COMMENT: {5/23/2012 10:25:57 PM} System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); //System::Drawing::Graphics ^g = this->zg1->CreateGraphics(); //IntPtr hdc = g->GetHdc(); //System::Drawing::Imaging::Metafile ^metaFile = gcnew System::Drawing::Imaging::Metafile(hdc, EmfType::EmfPlusOnly); - System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); +// COMMENT: {5/23/2012 10:25:53 PM} System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); //Graphics ^gMeta = Graphics::FromImage(metaFile); //zg1->MasterPane->Draw(gMeta); //System::IO::FileStream ^mySream = gcnew System::IO::FileStream(fn, System::IO::FileMode::Create); //metaFile->Save(chart->Get_batch_fn()); //ClipboardMetafileHelper.SaveEnhMetafileToFile(metaFile, fileName ); //System::Runtime::InteropServices::ClipboardMetafileHelper->SaveEnhMetafileToFile(metaFile, fileName ); - metaFile->Save(fn); +// COMMENT: {5/23/2012 10:25:45 PM} metaFile->Save(fn); //IntPtr hEMF; //hEMF = metaFile->GetHenhmetafile(); // invalidates mf @@ -841,6 +841,32 @@ namespace zdg_ui2 { //} //DeleteEnhMetaFile(hEMF); //g->ReleaseHdc(hdc); + +#if 1 + System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); + System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); + metaFile->Save(fn); +#else + System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); + + System::Drawing::Bitmap ^bm = gcnew System::Drawing::Bitmap(1, 1); + System::Drawing::Graphics ^g = System::Drawing::Graphics::FromImage(bm); + IntPtr hdc = g->GetHdc(); + + System::IO::Stream ^stream = gcnew System::IO::MemoryStream(); + + System::Drawing::Imaging::Metafile ^metafile = gcnew Metafile(stream, hdc, this->zg1->MasterPane->Rect, System::Drawing::Imaging::MetafileFrameUnit::Pixel, System::Drawing::Imaging::EmfType::EmfOnly); + + System::Drawing::Graphics ^metafileGraphics = System::Drawing::Graphics::FromImage(metafile); + metafileGraphics->TranslateTransform( -this->zg1->MasterPane->Rect.Left, -this->zg1->MasterPane->Rect.Top ); + metafileGraphics->PageUnit = System::Drawing::GraphicsUnit::Pixel; + + System::Drawing::PointF *P = new System::Drawing::PointF(this->zg1->MasterPane->Rect.Width, this->zg1->MasterPane->Rect.Height); + //System::Drawing::PointF *PA[] = new System::Drawing::PointF[] { P }; + //metafileGraphics.TransformPoints( CoordinateSpace.Page, CoordinateSpace.Device, PA ); + + metafile->Save(fn); +#endif } break; case 2: // bitmaps @@ -1002,7 +1028,7 @@ namespace zdg_ui2 { phreeqc_done = true; int batch = chart->Get_batch(); - if (chart->Get_batch() > 0) + if (batch > 0) { BatchSaveImage(); } @@ -1012,7 +1038,9 @@ namespace zdg_ui2 { this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; if (batch >= 0) + { this->Close(); + } return; } From 0fcfb42a584f4f116a5e303dbd37b9f09d14d217 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 24 May 2012 05:26:57 +0000 Subject: [PATCH 0505/1077] Cleanup of temporary code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6586 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 67 ------------------------------------------------- 1 file changed, 67 deletions(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 00cb9323..e9aacdfb 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -810,63 +810,10 @@ namespace zdg_ui2 { switch (chart->Get_batch()) { case 1: // emf - //SaveEmfFile( ); { - //using namespace System::Runtime::InteropServices; - //[DllImport("user32.dll")] - ////extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::Text::StringBuilder* hNULL); - //extern IntPtr CopyEnhMetaFileA(IntPtr hemfSrc, System::String* hNULL); -// COMMENT: {5/23/2012 10:25:57 PM} System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); - //System::Drawing::Graphics ^g = this->zg1->CreateGraphics(); - //IntPtr hdc = g->GetHdc(); - //System::Drawing::Imaging::Metafile ^metaFile = gcnew System::Drawing::Imaging::Metafile(hdc, EmfType::EmfPlusOnly); -// COMMENT: {5/23/2012 10:25:53 PM} System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); - //Graphics ^gMeta = Graphics::FromImage(metaFile); - //zg1->MasterPane->Draw(gMeta); - //System::IO::FileStream ^mySream = gcnew System::IO::FileStream(fn, System::IO::FileMode::Create); - //metaFile->Save(chart->Get_batch_fn()); - //ClipboardMetafileHelper.SaveEnhMetafileToFile(metaFile, fileName ); - //System::Runtime::InteropServices::ClipboardMetafileHelper->SaveEnhMetafileToFile(metaFile, fileName ); -// COMMENT: {5/23/2012 10:25:45 PM} metaFile->Save(fn); - - //IntPtr hEMF; - //hEMF = metaFile->GetHenhmetafile(); // invalidates mf - //if (!hEMF.Equals(gcnew IntPtr(0))) - //{ - // System::Text::StringBuilder ^filename = gcnew System::Text::StringBuilder("test.emf", 250); - // //System::Text::StringBuilder temp = new System::Text::StringBuilder(filename); - // System::IO::FileStream ^myStream = gcnew System::IO::FileStream("phreeqc.png", System::IO::FileMode::Create); - // System::Text::StringBuilder x1("test.emf"); - // CopyEnhMetaFile(hEMF, "test.emf"); - //} - //DeleteEnhMetaFile(hEMF); - //g->ReleaseHdc(hdc); - -#if 1 System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); System::Drawing::Imaging::Metafile ^metaFile = this->zg1->MasterPane->GetMetafile(); metaFile->Save(fn); -#else - System::String ^fn = gcnew System::String(chart->Get_batch_fn().c_str()); - - System::Drawing::Bitmap ^bm = gcnew System::Drawing::Bitmap(1, 1); - System::Drawing::Graphics ^g = System::Drawing::Graphics::FromImage(bm); - IntPtr hdc = g->GetHdc(); - - System::IO::Stream ^stream = gcnew System::IO::MemoryStream(); - - System::Drawing::Imaging::Metafile ^metafile = gcnew Metafile(stream, hdc, this->zg1->MasterPane->Rect, System::Drawing::Imaging::MetafileFrameUnit::Pixel, System::Drawing::Imaging::EmfType::EmfOnly); - - System::Drawing::Graphics ^metafileGraphics = System::Drawing::Graphics::FromImage(metafile); - metafileGraphics->TranslateTransform( -this->zg1->MasterPane->Rect.Left, -this->zg1->MasterPane->Rect.Top ); - metafileGraphics->PageUnit = System::Drawing::GraphicsUnit::Pixel; - - System::Drawing::PointF *P = new System::Drawing::PointF(this->zg1->MasterPane->Rect.Width, this->zg1->MasterPane->Rect.Height); - //System::Drawing::PointF *PA[] = new System::Drawing::PointF[] { P }; - //metafileGraphics.TransformPoints( CoordinateSpace.Page, CoordinateSpace.Device, PA ); - - metafile->Save(fn); -#endif } break; case 2: // bitmaps @@ -885,20 +832,6 @@ namespace zdg_ui2 { } } -#if 0 - // reset GraphObjList - zg1->GraphPane->GraphObjList = GOL_copy; - - // reset background - if (this->background) - { - zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); - } - else - { - zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); - } -#endif } private: void timer1_Tick(System::Object ^sender, System::EventArgs ^e ) { From c9dfe6164042a50288b5d3b4ff710e0867fdb862 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 24 May 2012 16:28:13 +0000 Subject: [PATCH 0506/1077] Rewrote -batch of USER_GRAPH to handle filenames with spaces. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6587 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/ChartObject.cpp b/ChartObject.cpp index e1ce3834..ce59449c 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -422,6 +422,89 @@ ChartObject::Read(CParser & parser) this->active = parser.get_true_false(next_char, true); break; /* End of modifications */ + case 16: /* batch */ + { + this->batch = ChartObject::ChO_BATCH_ONLY; + std::string rest_of_line, lc_rest_of_line; + parser.get_rest_of_line(rest_of_line); + lc_rest_of_line = rest_of_line; + Utilities::str_tolower(lc_rest_of_line); + + std::vector file_types; + file_types.push_back(".emf"); + file_types.push_back(".png"); + file_types.push_back(".jpg"); + file_types.push_back(".gif"); + file_types.push_back(".tiff"); + file_types.push_back(".bmp"); + file_types.push_back(".jpeg"); + + size_t first, last; + size_t i; + for (i = 0; i < file_types.size(); i++) + { + first = lc_rest_of_line.rfind(file_types[i].c_str()); + if (first != std::string::npos) + { + break; + } + } + if (i >= file_types.size()) + { + std::ostringstream estream; + estream << "Batch file name must have suffix emf, png, jpg, jpeg, gif, tiff, or bmp."; + error_msg(estream.str().c_str(), CONTINUE); + break; + } + switch (i) + { + case 0: + this->batch = ChartObject::ChO_EMF; + last = first + 4; + break; + case 1: + this->batch = ChartObject::ChO_PNG; + last = first + 4; + break; + case 2: + this->batch = ChartObject::ChO_JPG; + last = first + 4; + break; + case 3: + this->batch = ChartObject::ChO_GIF; + last = first + 4; + break; + case 4: + this->batch = ChartObject::ChO_TIFF; + last = first + 5; + break; + case 5: + this->batch = ChartObject::ChO_BMP; + last = first + 4; + break; + case 6: + this->batch = ChartObject::ChO_JPG; + last = first + 5; + break; + } + + this->batch_fn = rest_of_line.substr(0, last); + if (last+1 < rest_of_line.size()) + { + token = rest_of_line.substr(last); + token = trim(token); + if (token.size() > 0) + { + Utilities::str_tolower(token); + if (token[0] == 'f') + { + this->batch_background = false; + } + } + } + } + break; +#ifdef SKIP case 16: /* batch */ { this->batch = ChartObject::ChO_BATCH_ONLY; @@ -478,6 +561,7 @@ ChartObject::Read(CParser & parser) } break; +#endif case CParser::OPT_DEFAULT: // Read Basic commands { if (!new_command_lines) From 692cd611bd9b94c85456b121985f43a974bd0860 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 24 May 2012 22:01:04 +0000 Subject: [PATCH 0507/1077] added const methods git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6588 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.h | 110 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 87 insertions(+), 23 deletions(-) diff --git a/ChartObject.h b/ChartObject.h index 44d981dc..2bac49ba 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -30,7 +30,7 @@ class ChartObject:public cxxNumKeyword ChO_BMP = 6 }; - bool Get_new_ug() + bool Get_new_ug()const { return this->new_ug; } @@ -42,19 +42,19 @@ class ChartObject:public cxxNumKeyword { this->FirstCallToUSER_GRAPH = b; } - bool Get_FirstCallToUSER_GRAPH() + bool Get_FirstCallToUSER_GRAPH()const { return this->FirstCallToUSER_GRAPH; } - int Get_update_time_chart() + int Get_update_time_chart()const { return (this->update_time_chart); } - int Get_PanelHeight() + int Get_PanelHeight()const { return (this->PanelHeight); } - int Get_PanelWidth() + int Get_PanelWidth()const { return (this->PanelWidth); } @@ -62,6 +62,10 @@ class ChartObject:public cxxNumKeyword { return this->chart_title; } + const std::string &Get_chart_title()const + { + return this->chart_title; + } std::string Get_batch_fn() { return this->batch_fn; @@ -74,35 +78,59 @@ class ChartObject:public cxxNumKeyword { return this->axis_titles; } + const std::vector &Get_axis_titles()const + { + return this->axis_titles; + } LDBLE *Get_axis_scale_x() { return this->axis_scale_x; } + const LDBLE *Get_axis_scale_x()const + { + return this->axis_scale_x; + } LDBLE *Get_axis_scale_y() { return this->axis_scale_y; } + const LDBLE *Get_axis_scale_y()const + { + return this->axis_scale_y; + } LDBLE *Get_axis_scale_y2() { return this->axis_scale_y2; } - int Get_chart_type() + const LDBLE *Get_axis_scale_y2()const + { + return this->axis_scale_y2; + } + int Get_chart_type()const { return this->chart_type; } - bool Get_graph_initial_solutions() + bool Get_graph_initial_solutions()const { return this->graph_initial_solutions; } - bool Get_connect_simulations() + void Set_graph_initial_solutions(bool val) + { + this->graph_initial_solutions = val; + } + bool Get_connect_simulations()const { return this->connect_simulations; } + void Set_connect_simulations(bool val) + { + this->connect_simulations = val; + } void Set_colnr(int i) { this->colnr = i; } - int Get_colnr() + int Get_colnr()const { return (this->colnr); } @@ -110,7 +138,7 @@ class ChartObject:public cxxNumKeyword { this->ColumnOffset = i; } - int Get_ColumnOffset() + int Get_ColumnOffset()const { return (this->ColumnOffset); } @@ -118,15 +146,23 @@ class ChartObject:public cxxNumKeyword { this->AddSeries = b; } - bool Get_AddSeries() + bool Get_AddSeries()const { return this->AddSeries; } + std::vector< std::string > Get_csv_file_names()const + { + return this->csv_file_names; + } + void Get_csv_file_names(std::vector< std::string > names) + { + this->csv_file_names = names; + } void Set_prev_advection_step(int i) { this->prev_advection_step = i; } - int Get_prev_advection_step() + int Get_prev_advection_step()const { return (this->prev_advection_step); } @@ -134,7 +170,7 @@ class ChartObject:public cxxNumKeyword { this->prev_transport_step = i; } - int Get_prev_transport_step() + int Get_prev_transport_step()const { return (this->prev_transport_step); } @@ -142,7 +178,7 @@ class ChartObject:public cxxNumKeyword { this->prev_sim_no = i; } - int Get_prev_sim_no(void) + int Get_prev_sim_no(void)const { return this->prev_sim_no; } @@ -150,7 +186,7 @@ class ChartObject:public cxxNumKeyword { this->end_timer = b; } - bool Get_end_timer() + bool Get_end_timer()const { return this->end_timer; } @@ -158,7 +194,7 @@ class ChartObject:public cxxNumKeyword { this->done = b; } - bool Get_done() + bool Get_done()const { return this->done; } @@ -166,15 +202,23 @@ class ChartObject:public cxxNumKeyword { return this->CurvesCSV; } + const std::vector &Get_CurvesCSV()const + { + return this->CurvesCSV; + } std::vector &Get_Curves() { return this->Curves; } + const std::vector &Get_Curves()const + { + return this->Curves; + } void Set_curve_added(bool tf) { this->curve_added = tf; } - bool Get_curve_added() + bool Get_curve_added()const { return this->curve_added; } @@ -182,7 +226,7 @@ class ChartObject:public cxxNumKeyword { this->point_added = tf; } - bool Get_point_added() + bool Get_point_added()const { return this->point_added; } @@ -198,9 +242,13 @@ class ChartObject:public cxxNumKeyword { return this->rate_command_list; } + const std::list &Get_rate_command_list()const + { + return this->rate_command_list; + } void Set_rate_new_def(bool tf); - bool Get_rate_new_def() + bool Get_rate_new_def()const { return this->rate_new_def; } @@ -208,7 +256,7 @@ class ChartObject:public cxxNumKeyword { this->graph_x = d; } - LDBLE Get_graph_x() + LDBLE Get_graph_x()const { return this->graph_x; } @@ -216,14 +264,26 @@ class ChartObject:public cxxNumKeyword { return this->graph_y; } + const std::map &Get_graph_y()const + { + return this->graph_y; + } std::map &Get_secondary_y() { return this->secondary_y; } + const std::map &Get_secondary_y()const + { + return this->secondary_y; + } std::vector &Get_new_plotxy_curves() { return this->new_plotxy_curves; } + const std::vector &Get_new_plotxy_curves()const + { + return this->new_plotxy_curves; + } std::vector &Get_new_headings() { return this->new_headings; @@ -236,7 +296,7 @@ class ChartObject:public cxxNumKeyword { this->active = tf; } - bool Get_active() + bool Get_active()const { return this->active; } @@ -244,11 +304,11 @@ class ChartObject:public cxxNumKeyword { this->detach = tf; } - bool Get_detach() + bool Get_detach()const { return this->detach; } - bool Get_form_started() + bool Get_form_started()const { return this->form_started; } @@ -260,6 +320,10 @@ class ChartObject:public cxxNumKeyword { return this->phreeqc_ptr; } + const Phreeqc * Get_phreeqc()const + { + return this->phreeqc_ptr; + } const std::list& Get_rate_command_list_original()const { return this->rate_command_list_original; From d369d0f7fdac5dfa57aa622f10649ffa2a80b9af Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 24 May 2012 22:03:41 +0000 Subject: [PATCH 0508/1077] added __cplusplus_cli defines for methods that require CLR for faster linkage with USER_GRAPH editing in phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6589 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 16 ++++++++++++++++ Phreeqc.h | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index bb5299d5..d597363a 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -43,11 +43,15 @@ ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) { if (it->second->Get_active()) { +#if defined(__cplusplus_cli) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) System::Threading::Thread::Sleep(1); +#endif this->current_chart = it->second; phreeqc_ptr-> punch_user_graph(); +#if defined(__cplusplus_cli) System::Threading::Interlocked::Exchange(it->second->usingResource, 0); +#endif } } } @@ -80,8 +84,10 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) } // Read/update ChartObject +#if defined(__cplusplus_cli) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) System::Threading::Thread::Sleep(1); +#endif { it->second->Read(parser); current_chart_n_user = n_user; @@ -96,15 +102,19 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) it->second->Rate_free(); } +#if defined(__cplusplus_cli) // Release lock System::Threading::Interlocked::Exchange(it->second->usingResource, 0); +#endif // if detached, wait for thread to acknowledge and then erase chart if (it->second->Get_detach()) { while (it->second->Get_form_started() && it->second->Get_done() != true) { +#if defined(__cplusplus_cli) System::Threading::Thread::Sleep(1); +#endif } delete it->second; this->chart_map.erase(it); @@ -124,19 +134,25 @@ ChartHandler::End_timer() it->second->Rate_free(); if (it->second->Get_form_started()) { +#if defined(__cplusplus_cli) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1) && i < max_tries) { i++; System::Threading::Thread::Sleep(1); } +#endif it->second->Set_end_timer(true); +#if defined(__cplusplus_cli) System::Threading::Interlocked::Exchange(it->second->usingResource, 0); +#endif size_t i2 = 0; while (it->second->Get_done() != true && i2 < max_tries) { i2++; +#if defined(__cplusplus_cli) System::Threading::Thread::Sleep(1); +#endif } if (i >= max_tries || i2 >= max_tries) { diff --git a/Phreeqc.h b/Phreeqc.h index 9b54f97c..d3512740 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1484,6 +1484,16 @@ protected: #endif #if defined MULTICHART ChartHandler chart_handler; +public: + ChartHandler& Get_ChartHandler(void) + { + return chart_handler; + } + const ChartHandler& Get_ChartHandler(void)const + { + return chart_handler; + } +protected: #endif /* ---------------------------------------------------------------------- From c1886eb20f3d7c65a064795434ac293ef9affaed Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 26 May 2012 00:48:31 +0000 Subject: [PATCH 0509/1077] fixed for phreeqci (basic renumber) modified listtokens to put single quotes around strings containing double quotes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6590 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 9000abe3..c0900711 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -870,7 +870,14 @@ listtokens(FILE * f, tokenrec * l_buf) break; case tokstr: - output_msg(PhreeqcPtr->sformatf("\"%s\"", l_buf->UU.sp)); + if (strchr(l_buf->UU.sp, '\"')) + { + output_msg(PhreeqcPtr->sformatf("\'%s\'", l_buf->UU.sp)); + } + else + { + output_msg(PhreeqcPtr->sformatf("\"%s\"", l_buf->UU.sp)); + } break; case toksnerr: @@ -3998,7 +4005,7 @@ cmdrenum(struct LOC_exec *LINK) } else { -#if defined(PHREEQC_GUI) +#if defined(PHREEQCI_GUI) if (phreeqci_gui) { _snprintf(tok->sz_num, tok->n_sz, "%ld", l1->num2); From e55ff96bfb1ce67b555e45c00845f767f2c44690 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 May 2012 22:47:26 +0000 Subject: [PATCH 0510/1077] Tony's latest water properties in utilities.cpp. Got rid of form2 in project files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6597 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/utilities.cpp | 84 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index 461ba8d1..4fd95891 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -111,6 +111,7 @@ LDBLE Phreeqc:: calc_rho_0(LDBLE tc, LDBLE pa) /* ---------------------------------------------------------------------- */ { +#ifdef SKIP /* Density of pure water Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + interpolation 0 - 300 oC, 0.006 - 1000 atm... @@ -148,6 +149,85 @@ calc_rho_0(LDBLE tc, LDBLE pa) kappa_0 = (p0 + pa * (2 * p1 + pa * (3 * p2 + sqrt(pa) * 3.5 * p3))) / rho_0; return (rho_0 / 1e3); +#endif +//#ifdef SKIP + /* Calculate the density and compressibility of pure water, + IAPWS, IF97, region 1, 273 < Tk < 623, p_sat < p < 1e8 Pascal. + Seems to give somewhat better rho's and kappa's for p < 2e3 than above, + but may give densities < 0 outside the limits, e.g. tc = 250, p = 2.5e3... */ + + /* The minimal pressure equals the saturation pressure... */ + double tk = tc + 273.15; + p_sat = exp(11.6702 - 3816.44 / (tk - 46.13)); + if (ah2o_x <= 1.0) + p_sat *= ah2o_x; + //ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x + if (pa < p_sat || (use.Get_solution_ptr() && use.Get_solution_ptr()->Get_patm() < p_sat)) + { + pa = p_sat; + } + if (!use.Get_gas_phase_in()) + patm_x = pa; + double pasc = pa * 1.01325e5; + double Rg = 0.461526e3; //J / kg / K + double Tref = 1386.0, Pref = 16.53e6; // K, Pa + double t_t = Tref / tk, p_p = pasc / Pref; + double ni[34] = {0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, + -0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3, + 0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1, + -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3, + 0.47661393906987e-4, -0.44141845330846e-5, -0.72694996297594e-15, -0.31679644845054e-4, + -0.28270797985312e-5, -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6, + -0.14341729937924e-12, -0.40516996860117e-6, -0.12734301741641e-8, -0.17424871230634e-9, + -0.68762131295531e-18, 0.14478307828521e-19, 0.26335781662795e-22, -0.11947622640071e-22, + 0.18228094581404e-23, -0.93537087292458e-25}; + int ii[34] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32}; + int jj[34] = {-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, + 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41}; + /* v (m3/kg) = dG/dp = + (p_p * Rg * tk / pasc) * Sum_i (-ni[i] * ii[i] * (7.1 - p_p)^(ii[i] - 1) * (t_t - 1.222)^jj[i]) + kappa_0 (1 / Pa) = -1/v * dv/dp = -1/v * d2G/dp2 = + -1 / (v * Pref) * Sum_i (ni[i] * ii[i] * (ii[i] - 1) * (7.1 - p_p)^(ii[i] - 2) * (t_t - 1.222)^jj[i]) */ + + double v = -ni[11] - (7.1 - p_p) * (ni[15] * ii[15] + ni[20] * ii[20] * (7.1 - p_p)); + double dvdp = ni[15] * ii[15] + ni[20] * ii[20] * (ii[20] - 1) * (7.1 - p_p); + for (int i = 8; i < 34; i++) + { + if (i == 11 || i == 15 || i == 20) + continue; + if (ii[i] == 1) + { + if (jj[i] == 1) + v -= ni[i] * (t_t - 1.222); + else + v -= ni[i] * pow(t_t - 1.222, jj[i]); + } + else if (ii[i] == 2) + { + if (jj[i] == 1) + { + v -= ni[i] * ii[i] * (7.1 - p_p) * (t_t - 1.222); + dvdp += ni[i] * ii[i] * (ii[i] - 1) * (t_t - 1.222); + } + else + { + v -= ni[i] * ii[i] * (7.1 - p_p) * pow(t_t - 1.222, jj[i]); + dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(t_t - 1.222, jj[i]); + } + } + else + { + v -= ni[i] * ii[i] * pow(7.1 - p_p, ii[i] - 1) * pow(t_t - 1.222, jj[i]); + dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(7.1 - p_p, ii[i] - 2) * pow(t_t - 1.222, jj[i]); + } + } + if (v < 0) + error_msg("Calculating negative densities:\n Pressure and/or Temperature are outside the model's domain.\n", TRUE); + kappa_0 = -dvdp / v / Pref * 1.01325e5; // compressibility, 1/atm + rho_0 = 1e-3 / (v * (p_p * Rg * tk / pasc)); // density, kg/L + return rho_0; +//#endif } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -174,14 +254,14 @@ calc_dielectrics(LDBLE tc, LDBLE pa) = 1.671008e-3 (esu^2 / (erg/K)) / (eps_r * T) */ LDBLE e2_DkT = 1.671008e-3 / (eps_r * T); - DH_B = sqrt(8 * pi * AVOGADRO * e2_DkT * rho_0 / 1e3); // Debye length kappa, 1/cm + DH_B = sqrt(8 * pi * AVOGADRO * e2_DkT * rho_0 / 1e3); // Debye length kappa, 1/cm(mol/kg)^-0.5 DH_A = DH_B * e2_DkT / (2. * LOG_10); //(mol/kg)^-0.5 /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pa) / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 - DH_B /= 1e8; // kappa, 1/Angstrom + DH_B /= 1e8; // kappa, 1/Angstrom(mol/kg)^-0.5 /* the Born functions, * 41.84 to give molal volumes in cm3/mol... */ ZBrn = (- 1 / eps_r + 1.0) * 41.84004; From 50907986be85390977ef0b2f3499f4015d7aa2cc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 May 2012 15:54:28 +0000 Subject: [PATCH 0511/1077] Updated tally table to include Alkalinity and secondary master species (solutions only). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6608 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + phreeqc/tally.cpp | 179 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index d3512740..580d199d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -943,6 +943,7 @@ public: LDBLE fill_factor); int zero_tally_table(void); int elt_list_to_tally_table(struct tally_buffer *buffer_ptr); + int master_to_tally_table(struct tally_buffer *buffer_ptr); int get_all_components(void); int print_tally_table(void); int set_reaction_moles(int n_user, LDBLE moles); diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index 9706810e..a56998a1 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -56,14 +56,97 @@ store_tally_table(LDBLE *array, int row_dim, int col_dim, LDBLE fill_factor) stores conservative mixing (column 0) stores reaction (column 1) difference between slot 1 and slot 0 for - all other intities (columns 2-n) + all other entities (columns 2-n) Finalization: ------------- int free_tally_table(void); Frees space */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_all_components(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Counts components in any defined solution, gas_phase, exchanger, + * surface, or pure_phase_assemblage + * + * Returns n_comp, which is total, including H, O, elements, and Charge + * names contains character strings with names of components + */ + int i, j; +/* + * Accumulate all aqueous components + */ + add_all_components_tally(); + // add secondary master species + for (i = 0; i < count_master; i++) + { + if (master[i]->total > 0.0 && master[i]->s->type == AQ && master[i]->primary == TRUE) + { + for (int j = i + 1; j < count_master; j++) + { + if (master[j]->elt->primary == master[i]) + { + master[j]->total = 1.0; + } + else + { + break; + } + } + } + } + + +/* + * Count components + Alkalinity + */ + tally_count_component = 1; + for (i = 0; i < count_master; i++) + { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) + { + tally_count_component++; + } + } +/* + * Put information in buffer. + * Buffer contains an entry for every primary master + * species that can be used in the transport problem. + */ + t_buffer = + (struct tally_buffer *) PHRQ_malloc((size_t) tally_count_component * + sizeof(struct tally_buffer)); + + // store alkalinity + j = 0; + t_buffer[j].name = string_hsave("Alkalinity"); + t_buffer[j].master = master_bsearch("Alkalinity"); + t_buffer[j].gfw = t_buffer[j].master->elt->gfw; + j++; + + + for (i = 0; i < count_master; i++) + { + if (master[i]->total > 0.0 && master[i]->s->type == AQ) + { + t_buffer[j].name = master[i]->elt->name; + t_buffer[j].master = master[i]; + t_buffer[j].gfw = master[i]->elt->gfw; + j++; + } + } + /* + * Return value + */ + /**n_comp = count_component;*/ + count_tally_table_rows = tally_count_component; + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: get_all_components(void) @@ -119,7 +202,7 @@ get_all_components(void) count_tally_table_rows = tally_count_component; return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: store_tally_table(LDBLE * l_array, int row_dim, int col_dim, LDBLE fill_factor) @@ -369,7 +452,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) */ int found; LDBLE moles; - char *ptr; + //char *ptr; /* * Cycle through tally table columns */ @@ -378,6 +461,54 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) switch (tally_table[i].type) { case Solution: +/* + * fill solution + */ + if (n_user[Solution] < 0 || n_buffer == 0) + break; + { + cxxSolution *solution_ptr = NULL;; + if (i == 0) + { + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, index_conservative); + } + else if (i == 1) + { + solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user[Solution]); + } + else + { + error_msg("Solution is not in first two columns of tally_table", STOP); + } + if (solution_ptr == NULL) + break; + /* + * Add secondary master species + */ + + + xsolution_zero(); + + // adds primary master species + add_solution(solution_ptr, 1.0, 1.0); + + // adds secondary master species + cxxNameDouble::iterator jit = solution_ptr->Get_totals().begin(); + for ( ; jit != solution_ptr->Get_totals().end(); jit++) + { + struct master *master_ptr = master_bsearch(jit->first.c_str()); + master_ptr->total = jit->second; + } + + // Fill table + master_to_tally_table(tally_table[i].total[n_buffer]); + + // Add alkalinity + tally_table[i].total[n_buffer][0].moles = solution_ptr->Get_total_alkalinity(); + } + break; +#ifdef SKIP + case Solution: /* * fill solution */ @@ -422,6 +553,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) elt_list_to_tally_table(tally_table[i].total[n_buffer]); } break; +#endif case Reaction: /* * fill reaction @@ -677,6 +809,47 @@ elt_list_to_tally_table(struct tally_buffer *buffer_ptr) return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +master_to_tally_table(struct tally_buffer *buffer_ptr) +/* ---------------------------------------------------------------------- */ +{ + int i, j; + for (i = 0; i < count_tally_table_rows; i++) + { + buffer_ptr[i].moles = 0.0; + } + /* + * copy element list amounts to buffer in tally table + * for column number + */ + for (j = 0; j < count_master; j++) + { + if (master[j]->total <= 0) + continue; + if (master[j]->elt->primary->s == s_h2o) + continue; + if (master[j]->elt->primary->s == s_hplus) + continue; + if (master[j]->elt->primary->s == s_h3oplus) + continue; + if (master[j]->elt->primary->type != AQ) + continue; + for (i = 0; i < count_tally_table_rows; i++) + { + if (master[j] == buffer_ptr[i].master) + { + buffer_ptr[i].moles = master[j]->total; + break; + } + } + if (i >= count_tally_table_rows) + { + error_msg("Should not be here in master_to_tally_table", STOP); + } + } + return (OK); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: build_tally_table(void) From a8b09b7a93c37ccb4309e56db909704ec12229f6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 May 2012 22:44:48 +0000 Subject: [PATCH 0512/1077] tsv updated in code. ex2b updated. through example 2 in examples.fm. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6616 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 4 +++- phreeqc/read.cpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index ce59449c..6ec51c3e 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -265,6 +265,7 @@ ChartObject::Read(CParser & parser) vopts.push_back("detach"); // 14 vopts.push_back("active"); // 15 vopts.push_back("batch"); // 16 + vopts.push_back("plot_tsv_file"); // 17 } std::istream::pos_type ptr; @@ -405,6 +406,7 @@ ChartObject::Read(CParser & parser) this->connect_simulations = parser.get_true_false(next_char, true); break; case 12: /* plot_csv_file */ + case 17: /* plot_tsv_file */ { std::string file_name; parser.get_rest_of_line(file_name); @@ -1360,7 +1362,7 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) // csv files for (i = 0; i < this->csv_file_names.size(); i++) { - oss << indent1 << "-plot_csv_file " << this->csv_file_names[i] << "\n"; + oss << indent1 << "-plot_tsv_file " << this->csv_file_names[i] << "\n"; } // headings diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 038b0bd4..fe59a7be 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -8633,8 +8633,9 @@ read_user_graph(void) "grid_offset", /* 10 */ "connect_simulations", /* 11 */ "plot_csv_file" /* 12 */ + "plot_tsv_file" /* 13 */ }; - int count_opt_list = 13; + int count_opt_list = 14; int i; opt_save = OPTION_DEFAULT; From dcc27441b37f4390a9bddec09b6145dddf065cfd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Jun 2012 22:46:52 +0000 Subject: [PATCH 0513/1077] Calculate equiv for surface and exchange in tidy. Master species may not be defined as EX or SURF if other surface or exchange speices are defined first. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6628 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 8 +++++++- phreeqc/tidy.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index fe59a7be..54e429b6 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -354,7 +354,7 @@ read_exchange_species(void) struct species *s_ptr; struct elt_list *next_elt; struct rxn_token *token_ptr; - LDBLE exchange_coef; + //LDBLE exchange_coef; LDBLE offset; int return_value, opt, opt_save; @@ -744,6 +744,8 @@ read_exchange_species(void) trxn.token[0].s->o = next_elt->coef; } } +#ifdef SKIP + // Need to do this in tidy species in case X- is not first species read. /* * Find valence of cation from coefficients of reaction components * Changed to be coefficient of exchanger @@ -757,6 +759,7 @@ read_exchange_species(void) } } trxn.token[0].s->equiv = exchange_coef; +#endif /* * Malloc space for species reaction */ @@ -6218,6 +6221,8 @@ read_surface_species(void) trxn.token[0].s->o = next_elt->coef; } } +#ifdef SKIP + // need to do this in tidy in case surface master species not yet defined /* * Find coefficient of surface in rxn, store in equiv */ @@ -6231,6 +6236,7 @@ read_surface_species(void) } if (trxn.token[0].s->equiv == 0.0) trxn.token[0].s->equiv = 1.0; +#endif /* * Malloc space for species reaction */ diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 969214f2..ecf67c37 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -2310,6 +2310,55 @@ tidy_species(void) } } } + if (s[i]->type == EX) + { +/* + * Find valence of cation from coefficients of reaction components + * Changed to be coefficient of exchanger + */ + double exchange_coef = 0.0; + for (j = 1; s[i]->next_elt[j].elt != NULL; j++) + { + if (s[i]->next_elt[j].elt->master->s->type == EX) + { + exchange_coef = s[i]->next_elt[j].coef; + break; + } + } + if (exchange_coef == 0.0) + { + input_error++; + error_string = sformatf( + "No exchange species found in equation for %s.\n", s[i]->name); + error_msg(error_string, CONTINUE); + continue; + } + s[i]->equiv = exchange_coef; + } + if (s[i]->type == SURF) + { + double surface_coef = 0.0; + /* + * Find coefficient of surface in rxn, store in equiv + */ + for (j = 1; s[i]->next_elt[j].elt != NULL; j++) + { + if (s[i]->next_elt[j].elt->master->s->type == SURF) + { + surface_coef = s[i]->next_elt[j].coef; + break; + } + } + if (surface_coef == 0.0) + { + input_error++; + error_string = sformatf( + "No surface species found in equation for %s.\n", s[i]->name); + error_msg(error_string, CONTINUE); + continue; + } + s[i]->equiv = surface_coef; + } } return (OK); } From bd328e5841f073a58b24e3c7208568c35f051f88 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Jun 2012 15:32:41 +0000 Subject: [PATCH 0514/1077] Revised method of calculating equiv for EX and SURF in tity_species git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6629 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tidy.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index ecf67c37..2c53982b 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -2317,11 +2317,11 @@ tidy_species(void) * Changed to be coefficient of exchanger */ double exchange_coef = 0.0; - for (j = 1; s[i]->next_elt[j].elt != NULL; j++) + for (j = 1; s[i]->rxn_s->token[j].s != NULL; j++) { - if (s[i]->next_elt[j].elt->master->s->type == EX) + if (s[i]->rxn_s->token[j].s->type == EX) { - exchange_coef = s[i]->next_elt[j].coef; + exchange_coef = s[i]->rxn_s->token[j].coef; break; } } @@ -2341,11 +2341,11 @@ tidy_species(void) /* * Find coefficient of surface in rxn, store in equiv */ - for (j = 1; s[i]->next_elt[j].elt != NULL; j++) + for (j = 1; s[i]->rxn_s->token[j].s != NULL; j++) { - if (s[i]->next_elt[j].elt->master->s->type == SURF) + if (s[i]->rxn_s->token[j].s->type == SURF) { - surface_coef = s[i]->next_elt[j].coef; + surface_coef = s[i]->rxn_s->token[j].coef; break; } } From f45f490ed8eac1dcaf50fe2d168c92ac81b33825 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Jun 2012 22:11:42 +0000 Subject: [PATCH 0515/1077] Trying to optimize calculate values. With isotopes, all the isotope ratios and isotope alphas are kind of slow. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6631 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/isotopes.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 2 deletions(-) diff --git a/phreeqc/isotopes.cpp b/phreeqc/isotopes.cpp index 729f0310..307269ad 100644 --- a/phreeqc/isotopes.cpp +++ b/phreeqc/isotopes.cpp @@ -870,6 +870,7 @@ punch_calculate_values(void) int i; LDBLE result; struct calculate_value *calculate_value_ptr; + char l_command[] = "run"; if (punch.in == FALSE || punch.calculate_values == FALSE) return (OK); @@ -880,6 +881,43 @@ punch_calculate_values(void) result = MISSING; calculate_value_ptr = calculate_value_search(punch.calculate_values[i].name); + if (calculate_value_ptr->calculated == FALSE) + { + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) + { + if (basic_compile + (calculate_value_ptr->commands, &calculate_value_ptr->linebase, + &calculate_value_ptr->varbase, + &calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run + (l_command, calculate_value_ptr->linebase, + calculate_value_ptr->varbase, calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + else + { + calculate_value_ptr->calculated = TRUE; + calculate_value_ptr->value = rate_moles; + } + } if (calculate_value_ptr != NULL) { result = calculate_value_ptr->value; @@ -1046,7 +1084,6 @@ print_isotope_alphas(void) output_msg(sformatf( "\n")); return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: calculate_values(void) @@ -1068,7 +1105,189 @@ calculate_values(void) calculate_value[j]->calculated = FALSE; calculate_value[j]->value = MISSING; } +#ifdef SKIP + for (j = 0; j < count_calculate_value; j++) + { + calculate_value_ptr = calculate_value[j]; + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) + { + if (basic_compile + (calculate_value[j]->commands, &calculate_value[j]->linebase, + &calculate_value[j]->varbase, + &calculate_value[j]->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run + (l_command, calculate_value[j]->linebase, + calculate_value[j]->varbase, calculate_value[j]->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value[j]->name); + error_msg(error_string, STOP); + } + else + { + calculate_value[j]->calculated = TRUE; + calculate_value[j]->value = rate_moles; + } + } +#endif + if (pr.isotope_ratios == TRUE) + { + for (j = 0; j < count_isotope_ratio; j++) + { + isotope_ratio_ptr = isotope_ratio[j]; + master_isotope_ptr = + master_isotope_search(isotope_ratio_ptr->isotope_name); + if (master_isotope_ptr->master->s->in == FALSE) continue; + calculate_value_ptr = calculate_value_search(isotope_ratio_ptr->name); + if (calculate_value_ptr->calculated == FALSE) + { + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) + { + if (basic_compile + (calculate_value_ptr->commands, &calculate_value_ptr->linebase, + &calculate_value_ptr->varbase, + &calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run + (l_command, calculate_value_ptr->linebase, + calculate_value_ptr->varbase, calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + else + { + calculate_value_ptr->calculated = TRUE; + calculate_value_ptr->value = rate_moles; + } + } + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->value == MISSING) + { + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + } + else + { + isotope_ratio_ptr->ratio = calculate_value_ptr->value; + isotope_ratio_ptr->converted_ratio = + convert_isotope(master_isotope_ptr, + calculate_value_ptr->value); + } + } + } + if (pr.isotope_alphas == TRUE) + { + for (j = 0; j < count_isotope_alpha; j++) + { + isotope_alpha_ptr = isotope_alpha[j]; + calculate_value_ptr = calculate_value_search(isotope_alpha_ptr->name); + /* + * Calculate converted isotope ratio + */ + if (calculate_value_ptr->calculated == FALSE) + { + rate_moles = NAN; + if (calculate_value_ptr->new_def == TRUE) + { + if (basic_compile + (calculate_value_ptr->commands, &calculate_value_ptr->linebase, + &calculate_value_ptr->varbase, + &calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( + "Fatal Basic error in CALCULATE_VALUES %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + calculate_value_ptr->new_def = FALSE; + } + if (basic_run + (l_command, calculate_value_ptr->linebase, + calculate_value_ptr->varbase, calculate_value_ptr->loopbase) != 0) + { + error_string = sformatf( "Fatal Basic error in calculate_value %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + if (rate_moles == NAN) + { + error_string = sformatf( "Calculated value not SAVE'd for %s.", + calculate_value_ptr->name); + error_msg(error_string, STOP); + } + else + { + calculate_value_ptr->calculated = TRUE; + calculate_value_ptr->value = rate_moles; + } + } + if (calculate_value_ptr->value == MISSING) + { + isotope_alpha_ptr->value = MISSING; + } + else + { + isotope_alpha_ptr->value = calculate_value_ptr->value; + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calculate_values(void) +/* ---------------------------------------------------------------------- */ +{ + int j; + struct calculate_value *calculate_value_ptr; + struct isotope_ratio *isotope_ratio_ptr; + struct isotope_alpha *isotope_alpha_ptr; + struct master_isotope *master_isotope_ptr; + char l_command[] = "run"; + + /* + * initialize ratios as missing + */ + for (j = 0; j < count_calculate_value; j++) + { + calculate_value[j]->calculated = FALSE; + calculate_value[j]->value = MISSING; + } for (j = 0; j < count_calculate_value; j++) { calculate_value_ptr = calculate_value[j]; @@ -1147,7 +1366,7 @@ calculate_values(void) } return (OK); } - +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: convert_isotope(struct master_isotope * master_isotope_ptr, LDBLE ratio) From 5c55175307ed61cda576e899238dc6659c25cec7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 7 Jun 2012 00:21:16 +0000 Subject: [PATCH 0516/1077] MMS friend added git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6640 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.h b/Phreeqc.h index 580d199d..0563f5d4 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1858,6 +1858,7 @@ public: friend class IPhreeqc; friend class TestIPhreeqc; friend class TestSelectedOutput; + friend class IPhreeqcMMS; std::vector keycount; // used to mark keywords that have been read From 2222bd964444ec23a416fa804b3cd8405f3c5625 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Jun 2012 00:33:37 +0000 Subject: [PATCH 0517/1077] Added check on residual > MIN_TOTAL for MB equations. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6642 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index dc6d8c69..e0dbc3b6 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -296,7 +296,7 @@ check_residuals(void) { if (x[i]->type == MB || x[i]->type == ALK) { - if (fabs(residual[i]) >= epsilon * x[i]->moles + if (fabs(residual[i]) >= epsilon * x[i]->moles && fabs(residual[i]) > MIN_TOTAL && x[i]->moles > MIN_TOTAL /* || stop_program == TRUE */ ) { error_string = sformatf( @@ -3729,7 +3729,7 @@ residuals(void) if (x[i]->type == MB) { residual[i] = x[i]->moles - x[i]->f; - if ((fabs(residual[i]) > l_toler * x[i]->moles + if ((fabs(residual[i]) > l_toler * x[i]->moles && fabs(residual[i]) > MIN_TOTAL && x[i]->moles > MIN_TOTAL) || x[i]->moles < 0) { if (print_fail) From 7413759ae28da4e9f77c7af79c7e7a0d46c1f391 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Jun 2012 15:20:39 +0000 Subject: [PATCH 0518/1077] csv to tsv git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6645 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 6ec51c3e..f1f3fa92 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -618,7 +618,7 @@ ChartObject::OpenCSVFile(std::string file_name) if (!f_csv.is_open()) { std::ostringstream estream; - estream << "Could not open csv file for USER_GRAPH " << file_name << "\n Please, give the full path + filename."; + estream << "Could not open tsv file for USER_GRAPH " << file_name << "\n Please, give the full path + filename."; error_msg(estream.str().c_str(), CONTINUE); return false; } From 77b082d0e81c623b1ae74efaab32c95c03ccbd13 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 13 Jun 2012 16:55:54 +0000 Subject: [PATCH 0519/1077] Fixed handling of pressure for solution_spread. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6664 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/spread.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 926837ad..78d01ade 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -54,9 +54,10 @@ read_solution_spread(void) "isotope_uncertainty", /* 11 */ "uncertainty", /* 12 */ "uncertainties", /* 13 */ - "pressure" /* 14 */ + "pressure", /* 14 */ + "press" /* 15 */ }; - int count_opt_list = 15; + int count_opt_list = 16; /* * Initialize defaults */ @@ -205,6 +206,7 @@ read_solution_spread(void) } break; case 14: /* pressure */ + case 15: /* press */ sscanf(next_char, SCANFORMAT, &(soln_defaults.pressure)); break; } @@ -517,9 +519,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, "description", /* 11 */ "desc", /* 12 */ "descriptor", /* 13 */ - "pressure" /* 14 */ + "pressure", /* 14 */ + "press" /* 15 */ }; - int count_opt_list = 15; + int count_opt_list = 16; /* * look for solution number @@ -825,13 +828,9 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, } break; case 14: /* pressure */ + case 15: /* press */ { - next_char = char_string; - if (sscanf(next_char, SCANFORMAT, &dummy) != 1) - { - temp_solution.Set_patm(1); - } - else + if (sscanf(next_char, SCANFORMAT, &dummy) == 1) { temp_solution.Set_patm(dummy); } From fc2d4425fbdd098c67bc5cd94a5b8f0355d22785 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 13 Jun 2012 23:15:49 +0000 Subject: [PATCH 0520/1077] Added SOLUTION_MIX m-n keyword that mixes solutions without doing a full reaction calculation. Results of mix are stored as SOLUTION m-n. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6665 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 6 ++- Keywords.h | 1 + Phreeqc.h | 3 ++ Solution.cxx | 2 + phreeqc/mainsubs.cpp | 24 ++++++++++ phreeqc/read.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 141 insertions(+), 2 deletions(-) diff --git a/Keywords.cpp b/Keywords.cpp index 7878792c..267e139f 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -122,7 +122,8 @@ std::map::value_type("solid_solution_modi std::map::value_type("reaction_pressure", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW), -std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY) +std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY), +std::map::value_type("solution_mix", Keywords::KEY_SOLUTION_MIX) }; std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); @@ -196,6 +197,7 @@ std::map::value_type(Keywords::KEY_REACTI std::map::value_type(Keywords::KEY_REACTION_TEMPERATURE_MODIFY, "REACTION_TEMPERATURE_MODIFY"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), -std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY") +std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY"), +std::map::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX") }; std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); diff --git a/Keywords.h b/Keywords.h index d5429cea..33ac8d09 100644 --- a/Keywords.h +++ b/Keywords.h @@ -76,6 +76,7 @@ public: KEY_REACTION_PRESSURE, KEY_REACTION_PRESSURE_RAW, KEY_REACTION_PRESSURE_MODIFY, + KEY_SOLUTION_MIX, KEY_COUNT_KEYWORDS // must be last in list }; diff --git a/Phreeqc.h b/Phreeqc.h index 0563f5d4..9f4a6052 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -395,6 +395,7 @@ public: int initial_exchangers(int print); int initial_gas_phases(int print); int initial_solutions(int print); + int solution_mix(void); int step_save_exch(int n_user); int step_save_surf(int n_user); int initial_surfaces(int print); @@ -687,6 +688,7 @@ public: int *read_list_t_f(char **ptr, int *count_ints); int read_master_species(void); int read_mix(void); + int read_solution_mix(void); int read_named_logk(void); int read_phases(void); int read_print(void); @@ -1192,6 +1194,7 @@ protected: *---------------------------------------------------------------------- */ std::map Rxn_mix_map; std::map Dispersion_mix_map; + std::map Rxn_solution_mix_map; /*---------------------------------------------------------------------- * Irreversible reaction diff --git a/Solution.cxx b/Solution.cxx index 578f8cc2..594c6d4b 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -686,6 +686,8 @@ cxxSolution::zero() this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; + this->patm = 1.0; + this->initial_data = NULL; } void diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index c3c18225..f982b9b5 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1035,6 +1035,25 @@ initial_solutions(int print) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +solution_mix() +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through list of solution_mix, mix, save solutions + */ + std::map::iterator it; + for (it = Rxn_solution_mix_map.begin(); it != Rxn_solution_mix_map.end(); it++) + { + int i = 1; + cxxSolution sol(Rxn_solution_map, it->second, it->second.Get_n_user(), this->phrq_io); + Rxn_solution_map[it->second.Get_n_user()] = sol; + Utilities::Rxn_copies(Rxn_solution_map, it->second.Get_n_user(), it->second.Get_n_user_end()); + } + Rxn_solution_mix_map.clear(); + return OK; +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: initial_exchangers(int print) /* ---------------------------------------------------------------------- */ { @@ -2626,6 +2645,11 @@ run_simulations(void) */ if (new_solution) initial_solutions(TRUE); +/* + * Calculate mixed solutions + */ + if (Rxn_solution_mix_map.size() > 0) + solution_mix(); /* * Calculate distribution for exchangers */ diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 54e429b6..54a73869 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -112,6 +112,9 @@ read_input(void) case Keywords::KEY_MIX: read_mix(); break; + case Keywords::KEY_SOLUTION_MIX: + read_solution_mix(); + break; case Keywords::KEY_USE: read_use(); break; @@ -3390,6 +3393,110 @@ read_mix(void) return (return_value); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_solution_mix(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads mixing fractions + */ + int n_user, n_user_end; + int return_value; + int n_solution; + LDBLE fraction; + int j, i, l; + char *ptr; + char token[MAX_LENGTH]; + char *description; + cxxMix temp_mix; + +/* + * Read mix number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + temp_mix.Set_n_user(n_user); + temp_mix.Set_n_user_end(n_user_end); + temp_mix.Set_description(description); + free_check_null(description); +#ifdef SKIP +/* + * Set use data to first read + */ + if (use.Get_mix_in() == FALSE) + { + use.Set_mix_in(true); + use.Set_n_mix_user(n_user); + } +#endif +/* + * Read mixture data + */ + for (;;) + { + return_value = check_line("Mix raw data", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + { + break; + } + ptr = line; +/* + * Read n_user + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, "%d ", &n_solution); + } + else + { + input_error++; + error_msg("Expected a solution number in mix_raw input.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Read fraction for solution + */ + copy_token(token, &ptr, &l); + j = sscanf(token, SCANFORMAT, &fraction); + if (j != 1) + { + input_error++; + error_msg("Expected a mixing fraction.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } + +/* + * Save data + */ + temp_mix.Add(n_solution ,fraction); + } + if (temp_mix.Get_mixComps().size() == 0) + { + input_error++; + error_msg + ("Must define at least one solution number and mixing fraction for MIX_RAW input.", + CONTINUE); + } + Rxn_solution_mix_map[n_user] = temp_mix; +#ifdef SKIP + // copy if needed + if (n_user_end > n_user) + { + int i; + for (i = n_user + 1; i <= n_user_end; i++) + { + Utilities::Rxn_copy(Rxn_mix_map, n_user, i); + } + } +#endif + return (return_value); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: From 232bb18fad5e39deab24a599effb4dce6f33f211 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Jun 2012 22:11:34 +0000 Subject: [PATCH 0521/1077] Added time unit to advection, kinetics, transport, and run_cells git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6684 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Utils.cxx | 43 ++++++++++++++++ Utils.h | 2 +- phreeqc/read.cpp | 126 ++++++++++++++++++++++++++++----------------- phreeqc/readtr.cpp | 20 +++++-- runner.cpp | 19 +++++++ 5 files changed, 158 insertions(+), 52 deletions(-) diff --git a/Utils.cxx b/Utils.cxx index 5dbc18af..5e011032 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -111,7 +111,50 @@ Utilities::squeeze_white(std::string & s_l) } s_l = str; } +//////////////////////////////////////////////////////////////////////////// +double +Utilities::convert_time(double t, std::string in, std::string out) +//////////////////////////////////////////////////////////////////////////// +{ + Utilities::str_tolower(in); + // convert t to seconds + if (in.substr(0,1) == "m") + { + t = t * 60.; + } + if (in.substr(0,1) == "h") + { + t = t * 3600.; + } + if (in.substr(0,1) == "d") + { + t = t * 3600. * 24.; + } + if (in.substr(0,1) == "y") + { + t = t * 3600. * 24. * 365.25; + } + // convert to ouput units + if (out.substr(0,1) == "m") + { + t = t / 60.; + } + if (out.substr(0,1) == "h") + { + t = t / 3600.; + } + if (out.substr(0,1) == "d") + { + t = t / ( 3600. * 24.); + } + if (out.substr(0,1) == "y") + { + t = t / (3600. * 24. * 365.25); + } + return t; + +} //+NAN LDBLE: 7ff8000000000000 //-NAN LDBLE: fff8000000000000 /* diff --git a/Utils.h b/Utils.h index c227fb8b..c51603ac 100644 --- a/Utils.h +++ b/Utils.h @@ -22,6 +22,6 @@ namespace Utilities bool replace(const char *str1, const char *str2, std::string & str); void squeeze_white(std::string & s_l); - + double convert_time(double t, std::string in, std::string out); } #endif // UTILITIES_H_INCLUDED diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 54a73869..52d091d7 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -1999,6 +1999,7 @@ read_kinetics(void) temp_kinetics.Set_description(description); description = (char *) free_check_null(description); cxxKineticsComp *kinetics_comp_ptr = NULL; + std::string stdunits; /* * Set use data to first read */ @@ -2210,68 +2211,80 @@ read_kinetics(void) */ { int j; - while ((j = copy_token(token, &next_char)) == DIGIT) + while ((j = copy_token(token, &next_char)) != EMPTY) { - /* Read next step increment(s) */ - /* multiple, equal timesteps 15 aug. 2005 */ - if (Utilities::replace("*", " ", token)) + if (j == DIGIT) { - int k; - if (sscanf(token.c_str(), "%d" SCANFORMAT, &k, &step) == 2) + /* Read next step increment(s) */ + /* multiple, equal timesteps 15 aug. 2005 */ + if (Utilities::replace("*", " ", token)) { - for (int i = 0; i < k; i++) + int k; + if (sscanf(token.c_str(), "%d" SCANFORMAT, &k, &step) == 2) { - temp_kinetics.Get_steps().push_back(step); + for (int i = 0; i < k; i++) + { + temp_kinetics.Get_steps().push_back(step); + } + } + else + { + input_error++; + error_msg + ("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", + CONTINUE); } } else { - input_error++; - error_msg - ("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n", - CONTINUE); + step = strtod(token.c_str(), &ptr); + temp_kinetics.Get_steps().push_back(step); } } else { - step = strtod(token.c_str(), &ptr); - temp_kinetics.Get_steps().push_back(step); + Utilities::str_tolower(token); + if (token.substr(0,1) == "i" ) + { + /* + * Read number of increments + */ + if (temp_kinetics.Get_steps().size() != 1) + { + error_msg + ("To define equal time increments, only one total time should be defined.", + CONTINUE); + input_error++; + break; + } + temp_kinetics.Set_equalIncrements(true); + do + { + int i = 1; + j = sscanf(token.c_str(), "%d", &i); + if (j == 1) + { + temp_kinetics.Set_count(abs(i)); + break; + } + else if (j == 1 && i < 0) + { + error_msg + ("Expecting positive number for number of equal " + "time increments for kinetics.", CONTINUE); + error_msg(line_save, CONTINUE); + input_error++; + break; + } + } + while (copy_token(token, &next_char) != EMPTY); + } + else + { + stdunits = token; + } } } - if (j == EMPTY) - break; - /* - * Read number of increments - */ - if (temp_kinetics.Get_steps().size() != 1) - { - error_msg - ("To define equal time increments, only one total time should be defined.", - CONTINUE); - input_error++; - break; - } - temp_kinetics.Set_equalIncrements(true); - do - { - int i = 1; - j = sscanf(token.c_str(), "%d", &i); - if (j == 1) - { - temp_kinetics.Set_count(abs(i)); - break; - } - else if (j == 1 && i < 0) - { - error_msg - ("Expecting positive number for number of equal " - "time increments for kinetics.", CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - break; - } - } - while (copy_token(token, &next_char) != EMPTY); } break; case 6: /* step_divide */ @@ -2397,6 +2410,14 @@ read_kinetics(void) { temp_kinetics.Get_steps().push_back(1.0); } + else if (stdunits.size() > 0) + { + std::vector::iterator it; + for (it = temp_kinetics.Get_steps().begin(); it != temp_kinetics.Get_steps().end(); it++) + { + *it = Utilities::convert_time(*it, stdunits, "s"); + } + } /* * set defaults for moles */ @@ -7384,6 +7405,15 @@ read_advection(void) case 7: /* time_step */ case 8: /* timest */ sscanf(next_char, SCANFORMAT, &advection_kin_time); + { + std::string token; + int j = copy_token(token, &next_char); + j = copy_token(token, &next_char); + if (j == UPPER || j == LOWER) + { + advection_kin_time = Utilities::convert_time(advection_kin_time, token, "s"); + } + } advection_kin_time_defined = TRUE; opt_save = OPTION_DEFAULT; break; diff --git a/phreeqc/readtr.cpp b/phreeqc/readtr.cpp index 17765fec..cf11ffb3 100644 --- a/phreeqc/readtr.cpp +++ b/phreeqc/readtr.cpp @@ -7,6 +7,7 @@ typedef unsigned char boolean; #include "Phreeqc.h" #include "phqalloc.h" +#include "Utils.h" #define OPTION_EOF -1 @@ -273,12 +274,25 @@ read_transport(void) } opt_save = OPTION_DEFAULT; break; - case 5: /* timest */ + case 5: /* timest */ case 14: /* time_step */ if (copy_token(token, &next_char, &l) == DIGIT) sscanf(token, SCANFORMAT, ×t); - if (copy_token(token, &next_char, &l) == DIGIT) - sscanf(token, SCANFORMAT, &mcd_substeps); + { + std::string stdtoken; + j = copy_token(stdtoken, &next_char); + if (j == UPPER || j == LOWER) + { + timest = Utilities::convert_time(timest, stdtoken, "s"); + j = copy_token(stdtoken, &next_char); + } + if (j == DIGIT) + { + sscanf(stdtoken.c_str(), SCANFORMAT, &mcd_substeps); + } + } + //if (copy_token(token, &next_char, &l) == DIGIT) + // sscanf(token, SCANFORMAT, &mcd_substeps); if (mcd_substeps < 1) { mcd_substeps = 1.0; diff --git a/runner.cpp b/runner.cpp index 5e454c70..9bec59af 100644 --- a/runner.cpp +++ b/runner.cpp @@ -1,6 +1,7 @@ #include "runner.h" #include "Parser.h" #include "NA.h" +#include "Utils.h" runner::runner(PHRQ_io *io) : PHRQ_base(io) @@ -99,6 +100,15 @@ bool runner::Read(CParser & parser) parser.error_msg("Expected start_time for RUN_CELLS.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + break; + } + { + std::string token; + if (parser.get_iss() >> token) + { + token = trim(token); + this->start_time = Utilities::convert_time(this->start_time, token, "s"); + } } break; case 3: //time_step @@ -110,6 +120,15 @@ bool runner::Read(CParser & parser) parser.error_msg("Expected time_step for RUN_CELLS.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + break; + } + { + std::string token; + if (parser.get_iss() >> token) + { + token = trim(token); + this->time_step = Utilities::convert_time(this->time_step, token, "s"); + } } break; default: From 782106e4a6153798307355db02820632c0ef1941 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jul 2012 16:33:00 +0000 Subject: [PATCH 0522/1077] Tony's changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6762 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 9 ++++++++- PBasic.h | 3 ++- phreeqc/prep.cpp | 6 ++---- phreeqc/utilities.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index c0900711..767dc6c9 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1521,6 +1521,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokqbrn: output_msg("QBrn"); // Q_Born, d(eps_r)/d(P)/(eps_r^2) break; + case tokkappa: + output_msg("kappa"); // compressibility of pure water, d(rho)/d(P) / rho + break; } l_buf = l_buf->next; } @@ -3093,6 +3096,9 @@ factor(struct LOC_exec * LINK) case tokqbrn: n.UU.val = PhreeqcPtr->QBrn; break; + case tokkappa: + n.UU.val = PhreeqcPtr->kappa_0; + break; case toklog10: n.UU.val = log10(realfactor(LINK)); break; @@ -6401,7 +6407,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("dh_a", PBasic::tokdh_a), std::map::value_type("dh_b", PBasic::tokdh_b), std::map::value_type("dh_av", PBasic::tokdh_av), - std::map::value_type("qbrn", PBasic::tokqbrn) + std::map::value_type("qbrn", PBasic::tokqbrn), + std::map::value_type("kappa", PBasic::tokkappa) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 2075b883..28ef0e68 100644 --- a/PBasic.h +++ b/PBasic.h @@ -307,7 +307,8 @@ public: tokdh_a, tokdh_b, tokdh_av, - tokqbrn + tokqbrn, + tokkappa }; #if !defined(PHREEQCI_GUI) diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index e4cac181..5fe37849 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -5767,14 +5767,13 @@ calc_vm(LDBLE tc, LDBLE pa) if (s_x[i]->z) { /* the ionic strength term * I^0.5... */ - if (s_x[i]->logk[b_Av] == 0) + if (s_x[i]->logk[b_Av] < 1e-5) s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x); else { /* limit the Debye-Hueckel slope by b... */ - LDBLE b = (s_x[i]->logk[b_Av] < 1e-5 ? 1e-5 : s_x[i]->logk[b_Av]); s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * - log(1 + b * sqrt(mu_x)) / b; + log(1 + s_x[i]->logk[b_Av] * sqrt(mu_x)) / s_x[i]->logk[b_Av]; } /* plus the volume terms * I... */ LDBLE bi = s_x[i]->logk[vmi1] + s_x[i]->logk[vmi2] / (TK - 228.); // + s_x[i]->logk[vmi3] * TK); @@ -5797,7 +5796,6 @@ calc_vm(LDBLE tc, LDBLE pa) continue; /* for calculating delta_v of the reaction... */ - //s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; s_x[i]->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; } return OK; diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index 4fd95891..b0c2e43c 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -111,7 +111,7 @@ LDBLE Phreeqc:: calc_rho_0(LDBLE tc, LDBLE pa) /* ---------------------------------------------------------------------- */ { -#ifdef SKIP +//#ifdef SKIP /* Density of pure water Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + interpolation 0 - 300 oC, 0.006 - 1000 atm... @@ -149,8 +149,8 @@ calc_rho_0(LDBLE tc, LDBLE pa) kappa_0 = (p0 + pa * (2 * p1 + pa * (3 * p2 + sqrt(pa) * 3.5 * p3))) / rho_0; return (rho_0 / 1e3); -#endif -//#ifdef SKIP +//#endif +#ifdef SKIP /* Calculate the density and compressibility of pure water, IAPWS, IF97, region 1, 273 < Tk < 623, p_sat < p < 1e8 Pascal. Seems to give somewhat better rho's and kappa's for p < 2e3 than above, @@ -227,7 +227,7 @@ calc_rho_0(LDBLE tc, LDBLE pa) kappa_0 = -dvdp / v / Pref * 1.01325e5; // compressibility, 1/atm rho_0 = 1e-3 / (v * (p_p * Rg * tk / pasc)); // density, kg/L return rho_0; -//#endif +#endif } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -254,12 +254,12 @@ calc_dielectrics(LDBLE tc, LDBLE pa) = 1.671008e-3 (esu^2 / (erg/K)) / (eps_r * T) */ LDBLE e2_DkT = 1.671008e-3 / (eps_r * T); - DH_B = sqrt(8 * pi * AVOGADRO * e2_DkT * rho_0 / 1e3); // Debye length kappa, 1/cm(mol/kg)^-0.5 + DH_B = sqrt(8 * pi * AVOGADRO * e2_DkT * rho_0 / 1e3); // Debye length parameter, 1/cm(mol/kg)^-0.5 DH_A = DH_B * e2_DkT / (2. * LOG_10); //(mol/kg)^-0.5 /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ - DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pa) / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 + DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pa) * 1.01325 / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 DH_B /= 1e8; // kappa, 1/Angstrom(mol/kg)^-0.5 From 01495bfb4b3875256021de155a516bc6d6368f60 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jul 2012 00:24:26 +0000 Subject: [PATCH 0523/1077] changes reqd for merge version git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6764 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- phreeqc/PHRQ_io_output.cpp | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 9f4a6052..4a5ede5c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -917,7 +917,7 @@ public: static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); #if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) - extern void MergeFinalize(void); + void MergeFinalize(void); #endif struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index ee0a9a0b..c87f3133 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -64,10 +64,6 @@ extern void HDFWriteHyperSlabV(const char *name, const char *format, va_list argptr); #endif -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) -extern int Merge_fpunchf(const int length, const char *format, - va_list argptr); -#endif void Phreeqc:: fpunchf_heading(const char *name) { From 66f3b9b80220056a5080046437e89b5f9381ee43 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jul 2012 00:50:41 +0000 Subject: [PATCH 0524/1077] PHRQ_io::error_msg now throws on STOP git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6769 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 30eb8d3f..ff434503 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -223,6 +223,8 @@ error_msg(const char *err_str, bool stop) } output_msg("Stopping.\n"); log_msg("Stopping.\n"); + + throw PhreeqcStop(); } } /* ---------------------------------------------------------------------- */ From 8823f0ff2fe9b08d3bb2e89d8ba272e7e506c868 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jul 2012 16:23:02 +0000 Subject: [PATCH 0525/1077] Added STATIC_VOPTS to make vopts static, not static unless defined. Guy had problems with static variables with OpenMP. Also removed other static variables fpunchf_user s_warning and buffer, spread length, utilities spinner. Put in Phreeqc.h. Removed static fnbuf from Pbasic.cpp, put in Pbasic.h. I think only static variables are in Keywords.h and are necessary for initialization. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6770 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 5 ++++- ExchComp.cxx | 4 ++++ Exchange.cxx | 4 ++++ GasComp.cxx | 4 ++++ GasPhase.cxx | 4 ++++ KineticsComp.cxx | 4 ++++ PBasic.cpp | 1 - PBasic.h | 1 + PPassemblage.cxx | 4 ++++ PPassemblageComp.cxx | 4 ++++ Phreeqc.cpp | 6 ++++++ Phreeqc.h | 6 ++++++ Pressure.cxx | 4 ++++ Reaction.cxx | 4 ++++ SS.cxx | 4 ++++ SSassemblage.cxx | 4 ++++ SScomp.cxx | 4 ++++ Solution.cxx | 4 ++++ SolutionIsotope.cxx | 4 ++++ StorageBinList.cpp | 4 ++++ Surface.cxx | 4 ++++ SurfaceCharge.cxx | 4 ++++ SurfaceComp.cxx | 4 ++++ Temperature.cxx | 4 ++++ cxxKinetics.cxx | 4 ++++ cxxMix.cxx | 4 ++++ dumper.cpp | 4 ++++ phreeqc/PHRQ_io_output.cpp | 20 ++++++++------------ phreeqc/spread.cpp | 18 +++++++++--------- phreeqc/utilities.cpp | 1 - runner.cpp | 4 ++++ 31 files changed, 126 insertions(+), 24 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index f1f3fa92..da143596 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -243,8 +243,11 @@ ChartObject::Set_axis_scale(CParser & parser) bool ChartObject::Read(CParser & parser) { - +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(20); diff --git a/ExchComp.cxx b/ExchComp.cxx index eaaff96d..43352c27 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -179,7 +179,11 @@ cxxExchComp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/Exchange.cxx b/Exchange.cxx index 80e9a6d6..6875edf1 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -196,7 +196,11 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxExchange::read_raw(CParser & parser, bool check) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/GasComp.cxx b/GasComp.cxx index 1e3b3370..c84be2a3 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -62,7 +62,11 @@ cxxGasComp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/GasPhase.cxx b/GasPhase.cxx index f012ce93..7f409d3c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -273,7 +273,11 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { int i; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 481ffea6..9eb6c6e8 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -134,7 +134,11 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/PBasic.cpp b/PBasic.cpp index 767dc6c9..59137bbe 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -5854,7 +5854,6 @@ P_maxpos(FILE * f) char * PBasic:: P_trimname(register char * fn, register int len) { - static char fnbuf[256]; register char *cp = fnbuf; while (--len >= 0 && *fn && !isspace((int) *fn)) diff --git a/PBasic.h b/PBasic.h index 28ef0e68..3a295f93 100644 --- a/PBasic.h +++ b/PBasic.h @@ -505,6 +505,7 @@ protected: bool phreeqci_gui; bool parse_all; /* true, most function values set to 1 for testing compilation */ bool parse_whole_program; + char fnbuf[256]; #if defined(PHREEQCI_GUI) HANDLE hInfiniteLoop; UINT nIDErrPrompt; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 5b98a3ad..4c8de92b 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -125,7 +125,11 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxPPassemblage::read_raw(CParser & parser, bool check) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 7a736feb..0b59bf49 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -106,7 +106,11 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index da3eb220..7253df6c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -497,6 +497,9 @@ void Phreeqc::init(void) user_punch_headings = 0; user_punch_count_headings = 0; n_user_punch_index = 0; + fpunchf_user_s_warning = 0; + + spread_length = 10; /* Initialize llnl aqueous model parameters */ @@ -806,6 +809,9 @@ void Phreeqc::init(void) /* model.c */ gas_in = FALSE; + /* utilities.c */ + spinner = 0; + count_strings = 0; #ifdef MULTICHART chart_handler.Set_io(phrq_io); diff --git a/Phreeqc.h b/Phreeqc.h index 4a5ede5c..74a960dc 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1481,6 +1481,9 @@ protected: int user_punch_count_headings; int n_user_punch_index; + int fpunchf_user_s_warning; + char fpunchf_user_buffer[80]; + #if defined PHREEQ98 struct rate *user_graph; char **user_graph_headings; @@ -1576,6 +1579,7 @@ protected: #ifdef PHREEQCI_GUI struct spread_sheet g_spread_sheet; #endif + int spread_length; /* ---------------------------------------------------------------------- */ /* @@ -1855,6 +1859,8 @@ public: int stop_calculations; char err_str98[80]; #endif + /* utilities.cpp ------------------------------- */ + int spinner; friend class PBasic; friend class ChartObject; diff --git a/Pressure.cxx b/Pressure.cxx index de48aeb4..cb022b83 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -198,7 +198,11 @@ cxxPressure::read_raw(CParser & parser) bool cleared_once = false; LDBLE d; CParser::TOKEN_TYPE k; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(5); diff --git a/Reaction.cxx b/Reaction.cxx index 71818b6e..650c86c2 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -131,7 +131,11 @@ cxxReaction::read_raw(CParser & parser, const bool check) int j; LDBLE d; CParser::TOKEN_TYPE k; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/SS.cxx b/SS.cxx index 63d5e50d..3aed0870 100644 --- a/SS.cxx +++ b/SS.cxx @@ -126,7 +126,11 @@ cxxSS::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 79ca92c6..4b20add6 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -126,7 +126,11 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxSSassemblage::read_raw(CParser & parser, bool check) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/SScomp.cxx b/SScomp.cxx index 3af1f166..d6a1e07d 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -92,7 +92,11 @@ cxxSScomp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(10); diff --git a/Solution.cxx b/Solution.cxx index 594c6d4b..43d73948 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -292,7 +292,11 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxSolution::read_raw(CParser & parser, bool check) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(21); diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 7ced2531..2c8cba6b 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -95,7 +95,11 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const } void cxxSolutionIsotope::read_raw(CParser & parser, bool check ) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(21); diff --git a/StorageBinList.cpp b/StorageBinList.cpp index b4c5dfb4..d880b7b6 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -138,7 +138,11 @@ void StorageBinList::SetAll(bool tf) bool StorageBinList::Read(CParser & parser) { bool return_value(true); +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(20); diff --git a/Surface.cxx b/Surface.cxx index a3a4b86c..697bab9a 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -234,7 +234,11 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons void cxxSurface::read_raw(CParser & parser, bool check) { +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif int i = 0; if (vopts.empty()) { diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 458387d7..629bd87a 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -118,7 +118,11 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 37c9c8ea..a1039a0f 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -114,7 +114,11 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) { std::string str; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/Temperature.cxx b/Temperature.cxx index 7a04aea1..1cdeab62 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -236,7 +236,11 @@ cxxTemperature::read_raw(CParser & parser) // clear steps for modify operation, if pressures are read bool cleared_once = false; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 860aef0d..1483959c 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -187,7 +187,11 @@ cxxKinetics::read_raw(CParser & parser, bool check) { LDBLE d; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/cxxMix.cxx b/cxxMix.cxx index 9caddb78..cc9817a0 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -95,7 +95,11 @@ cxxMix::read_raw(CParser & parser) int i; LDBLE d; +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(15); diff --git a/dumper.cpp b/dumper.cpp index 51936c67..a3a0fdae 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -33,7 +33,11 @@ void dumper::SetAll(bool tf) bool dumper::Read(CParser & parser) { bool return_value(true); +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(20); diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index c87f3133..7d3a2c53 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -91,8 +91,6 @@ fpunchf(const char *name, const char *format, int d) void Phreeqc:: fpunchf_user(int user_index, const char *format, double d) { - static int s_warning = 0; - static char buffer[80]; const char *name; // check headings @@ -102,16 +100,16 @@ fpunchf_user(int user_index, const char *format, double d) } else { - if (s_warning == 0) + if (fpunchf_user_s_warning == 0) { error_string = sformatf( "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); warning_msg(error_string); - s_warning = 1; + fpunchf_user_s_warning = 1; } - sprintf(buffer, "no_heading_%d", + sprintf(fpunchf_user_buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); - name = buffer; + name = fpunchf_user_buffer; } if (phrq_io) phrq_io->fpunchf(name, format, (double) d); } @@ -119,8 +117,6 @@ fpunchf_user(int user_index, const char *format, double d) void Phreeqc:: fpunchf_user(int user_index, const char *format, char * d) { - static int s_warning = 0; - static char buffer[80]; const char *name; // check headings @@ -130,16 +126,16 @@ fpunchf_user(int user_index, const char *format, char * d) } else { - if (s_warning == 0) + if (fpunchf_user_s_warning == 0) { error_string = sformatf( "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); warning_msg(error_string); - s_warning = 1; + fpunchf_user_s_warning = 1; } - sprintf(buffer, "no_heading_%d", + sprintf(fpunchf_user_buffer, "no_heading_%d", (user_index - user_punch_count_headings) + 1); - name = buffer; + name = fpunchf_user_buffer; } if (phrq_io) phrq_io->fpunchf(name, format, d); } diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 78d01ade..ad370ffc 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -916,7 +916,7 @@ string_to_spread_row(char *string) /* ---------------------------------------------------------------------- */ { int j, l; - static int length = 10; /* possible memory error if length of line is smaller than previous line */ + /* possible memory error if length of line is smaller than previous line */ char *token; char *ptr; struct spread_row *spread_row_ptr; @@ -931,15 +931,15 @@ string_to_spread_row(char *string) if (spread_row_ptr == NULL) malloc_error(); spread_row_ptr->char_vector = - (char **) PHRQ_malloc((size_t) length * sizeof(char *)); + (char **) PHRQ_malloc((size_t) spread_length * sizeof(char *)); if (spread_row_ptr->char_vector == NULL) malloc_error(); spread_row_ptr->d_vector = - (LDBLE *) PHRQ_malloc((size_t) length * sizeof(LDBLE)); + (LDBLE *) PHRQ_malloc((size_t) spread_length * sizeof(LDBLE)); if (spread_row_ptr->d_vector == NULL) malloc_error(); spread_row_ptr->type_vector = - (int *) PHRQ_malloc((size_t) length * sizeof(int)); + (int *) PHRQ_malloc((size_t) spread_length * sizeof(int)); if (spread_row_ptr->type_vector == NULL) malloc_error(); spread_row_ptr->count = 0; @@ -952,25 +952,25 @@ string_to_spread_row(char *string) */ for (;;) { - if (spread_row_ptr->count + 1 > length) + if (spread_row_ptr->count + 1 > spread_length) { - length *= 2; + spread_length *= 2; spread_row_ptr->char_vector = (char **) PHRQ_realloc(spread_row_ptr->char_vector, - (size_t) length * sizeof(char *)); + (size_t) spread_length * sizeof(char *)); if (spread_row_ptr->char_vector == NULL) malloc_error(); spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, - (size_t) length * sizeof(LDBLE)); + (size_t) spread_length * sizeof(LDBLE)); if (spread_row_ptr->d_vector == NULL) malloc_error(); spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, - (size_t) length * sizeof(int)); + (size_t) spread_length * sizeof(int)); if (spread_row_ptr->type_vector == NULL) malloc_error(); } diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index b0c2e43c..d0e5a404 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -1377,7 +1377,6 @@ int Phreeqc:: status(int count, const char *str, bool rk_string) /* ---------------------------------------------------------------------- */ { - static int spinner; char sim_str[20]; char state_str[45]; char spin_str[2]; diff --git a/runner.cpp b/runner.cpp index 9bec59af..03c33ef3 100644 --- a/runner.cpp +++ b/runner.cpp @@ -28,7 +28,11 @@ bool runner::Read(CParser & parser) { bool return_value(true); +#if defined(STATIC_VOPTS) static std::vector < std::string > vopts; +#else + std::vector < std::string > vopts; +#endif if (vopts.empty()) { vopts.reserve(20); From 0ca9654356c878fc258b74cde217d6e3a979ac10 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Jul 2012 16:39:13 +0000 Subject: [PATCH 0526/1077] Reversed logic to NO_STATIC_VOPTS, default is now static vopts. No changes to Makefile or project needed now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6771 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 6 +++--- ExchComp.cxx | 6 +++--- Exchange.cxx | 6 +++--- GasComp.cxx | 6 +++--- GasPhase.cxx | 6 +++--- KineticsComp.cxx | 6 +++--- PPassemblage.cxx | 6 +++--- PPassemblageComp.cxx | 6 +++--- Pressure.cxx | 6 +++--- Reaction.cxx | 6 +++--- SS.cxx | 6 +++--- SSassemblage.cxx | 6 +++--- SScomp.cxx | 6 +++--- Solution.cxx | 6 +++--- SolutionIsotope.cxx | 6 +++--- StorageBinList.cpp | 6 +++--- Surface.cxx | 6 +++--- SurfaceCharge.cxx | 6 +++--- SurfaceComp.cxx | 6 +++--- Temperature.cxx | 6 +++--- cxxKinetics.cxx | 6 +++--- cxxMix.cxx | 6 +++--- dumper.cpp | 6 +++--- runner.cpp | 6 +++--- 24 files changed, 72 insertions(+), 72 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index da143596..4b2c58e1 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -243,10 +243,10 @@ ChartObject::Set_axis_scale(CParser & parser) bool ChartObject::Read(CParser & parser) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/ExchComp.cxx b/ExchComp.cxx index 43352c27..25ae0c2c 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -179,10 +179,10 @@ cxxExchComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Exchange.cxx b/Exchange.cxx index 6875edf1..06e314ff 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -196,10 +196,10 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxExchange::read_raw(CParser & parser, bool check) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/GasComp.cxx b/GasComp.cxx index c84be2a3..c6da042b 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -62,10 +62,10 @@ cxxGasComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/GasPhase.cxx b/GasPhase.cxx index 7f409d3c..8b15ad0f 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -273,10 +273,10 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { int i; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 9eb6c6e8..e7824a33 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -134,10 +134,10 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 4c8de92b..05b97e11 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -125,10 +125,10 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxPPassemblage::read_raw(CParser & parser, bool check) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0b59bf49..6d69f728 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -106,10 +106,10 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Pressure.cxx b/Pressure.cxx index cb022b83..6531a994 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -198,10 +198,10 @@ cxxPressure::read_raw(CParser & parser) bool cleared_once = false; LDBLE d; CParser::TOKEN_TYPE k; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Reaction.cxx b/Reaction.cxx index 650c86c2..298f0074 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -131,10 +131,10 @@ cxxReaction::read_raw(CParser & parser, const bool check) int j; LDBLE d; CParser::TOKEN_TYPE k; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/SS.cxx b/SS.cxx index 3aed0870..04e8ba1f 100644 --- a/SS.cxx +++ b/SS.cxx @@ -126,10 +126,10 @@ cxxSS::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 4b20add6..68710afe 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -126,10 +126,10 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxSSassemblage::read_raw(CParser & parser, bool check) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/SScomp.cxx b/SScomp.cxx index d6a1e07d..fad17289 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -92,10 +92,10 @@ cxxSScomp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Solution.cxx b/Solution.cxx index 43d73948..983bfedd 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -292,10 +292,10 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxSolution::read_raw(CParser & parser, bool check) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 2c8cba6b..6d752720 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -95,10 +95,10 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const } void cxxSolutionIsotope::read_raw(CParser & parser, bool check ) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/StorageBinList.cpp b/StorageBinList.cpp index d880b7b6..239f0660 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -138,10 +138,10 @@ void StorageBinList::SetAll(bool tf) bool StorageBinList::Read(CParser & parser) { bool return_value(true); -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Surface.cxx b/Surface.cxx index 697bab9a..4083775e 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -234,10 +234,10 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons void cxxSurface::read_raw(CParser & parser, bool check) { -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif int i = 0; if (vopts.empty()) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 629bd87a..8203c52a 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -118,10 +118,10 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index a1039a0f..057a4aca 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -114,10 +114,10 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/Temperature.cxx b/Temperature.cxx index 1cdeab62..767d1a8a 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -236,10 +236,10 @@ cxxTemperature::read_raw(CParser & parser) // clear steps for modify operation, if pressures are read bool cleared_once = false; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 1483959c..feecb581 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -187,10 +187,10 @@ cxxKinetics::read_raw(CParser & parser, bool check) { LDBLE d; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/cxxMix.cxx b/cxxMix.cxx index cc9817a0..d62c1852 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -95,10 +95,10 @@ cxxMix::read_raw(CParser & parser) int i; LDBLE d; -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/dumper.cpp b/dumper.cpp index a3a0fdae..d723a5c3 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -33,10 +33,10 @@ void dumper::SetAll(bool tf) bool dumper::Read(CParser & parser) { bool return_value(true); -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { diff --git a/runner.cpp b/runner.cpp index 03c33ef3..e1c3319c 100644 --- a/runner.cpp +++ b/runner.cpp @@ -28,10 +28,10 @@ bool runner::Read(CParser & parser) { bool return_value(true); -#if defined(STATIC_VOPTS) - static std::vector < std::string > vopts; -#else +#if defined(NO_STATIC_VOPTS) std::vector < std::string > vopts; +#else + static std::vector < std::string > vopts; #endif if (vopts.empty()) { From b664e431340e9ecd2dc0e53826a0e3f76ef2f13b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Jul 2012 15:22:23 +0000 Subject: [PATCH 0527/1077] Removed unneeded declaration. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6772 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/mainsubs.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index f982b9b5..401dbf1e 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1044,7 +1044,6 @@ solution_mix() std::map::iterator it; for (it = Rxn_solution_mix_map.begin(); it != Rxn_solution_mix_map.end(); it++) { - int i = 1; cxxSolution sol(Rxn_solution_map, it->second, it->second.Get_n_user(), this->phrq_io); Rxn_solution_map[it->second.Get_n_user()] = sol; Utilities::Rxn_copies(Rxn_solution_map, it->second.Get_n_user(), it->second.Get_n_user_end()); From f069c8e57d70a25ec04939b58b1843c2fbe831eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 12 Jul 2012 22:10:02 +0000 Subject: [PATCH 0528/1077] renamed c files. updated project. moved PHAST_IPhreeqc to IPhreeqcPhast removed const from StorageBin getters. Fixed some compile errors. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6776 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 3 +-- StorageBin.cxx | 44 ++++++++++++++++++++++---------------------- StorageBin.h | 22 +++++++++++----------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 983bfedd..1d2a1a52 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -95,8 +95,7 @@ cxxSolution::cxxSolution(std::map < int, cxxSolution > &solutions, // // constructor for cxxSolution from mixture of solutions // - : -cxxNumKeyword(io) +: cxxNumKeyword(io) { // diff --git a/StorageBin.cxx b/StorageBin.cxx index 27c6e8fb..f6927774 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -304,58 +304,58 @@ cxxStorageBin::Remove_Pressure(int n_user) Pressures.erase(n_user); } -const std::map < int, cxxSolution > & -cxxStorageBin::Get_Solutions() const +std::map < int, cxxSolution > & +cxxStorageBin::Get_Solutions() { return this->Solutions; } -const std::map < int, cxxExchange > & -cxxStorageBin::Get_Exchangers() const +std::map < int, cxxExchange > & +cxxStorageBin::Get_Exchangers() { return this->Exchangers; } -const std::map < int, cxxGasPhase > & -cxxStorageBin::Get_GasPhases() const +std::map < int, cxxGasPhase > & +cxxStorageBin::Get_GasPhases() { return this->GasPhases; } -const std::map < int, cxxKinetics > & -cxxStorageBin::Get_Kinetics() const +std::map < int, cxxKinetics > & +cxxStorageBin::Get_Kinetics() { return this->Kinetics; } -const std::map < int, cxxPPassemblage > & -cxxStorageBin::Get_PPassemblages() const +std::map < int, cxxPPassemblage > & +cxxStorageBin::Get_PPassemblages() { return this->PPassemblages; } -const std::map < int, cxxSSassemblage > & -cxxStorageBin::Get_SSassemblages() const +std::map < int, cxxSSassemblage > & +cxxStorageBin::Get_SSassemblages() { return this->SSassemblages; } -const std::map < int, cxxSurface > & -cxxStorageBin::Get_Surfaces() const +std::map < int, cxxSurface > & +cxxStorageBin::Get_Surfaces() { return this->Surfaces; } -const std::map < int, cxxMix > & -cxxStorageBin::Get_Mixes() const +std::map < int, cxxMix > & +cxxStorageBin::Get_Mixes() { return this->Mixes; } -const std::map < int, cxxReaction > & -cxxStorageBin::Get_Reactions() const +std::map < int, cxxReaction > & +cxxStorageBin::Get_Reactions() { return this->Reactions; } -const std::map < int, cxxTemperature > & -cxxStorageBin::Get_Temperatures() const +std::map < int, cxxTemperature > & +cxxStorageBin::Get_Temperatures() { return this->Temperatures; } -const std::map < int, cxxPressure > & -cxxStorageBin::Get_Pressures() const +std::map < int, cxxPressure > & +cxxStorageBin::Get_Pressures() { return this->Pressures; } diff --git a/StorageBin.h b/StorageBin.h index b701ed71..c2ff2fd5 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -93,17 +93,17 @@ class cxxStorageBin: public PHRQ_base //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); - const std::map < int, cxxSolution > &Get_Solutions() const; - const std::map < int, cxxExchange > &Get_Exchangers() const; - const std::map < int, cxxGasPhase > &Get_GasPhases() const; - const std::map < int, cxxKinetics > &Get_Kinetics() const; - const std::map < int, cxxPPassemblage > &Get_PPassemblages() const; - const std::map < int, cxxSSassemblage > &Get_SSassemblages() const; - const std::map < int, cxxSurface > &Get_Surfaces() const; - const std::map < int, cxxMix > &Get_Mixes() const; - const std::map < int, cxxReaction > &Get_Reactions() const; - const std::map < int, cxxTemperature > &Get_Temperatures() const; - const std::map < int, cxxPressure > &Get_Pressures() const; + std::map < int, cxxSolution > &Get_Solutions(); + std::map < int, cxxExchange > &Get_Exchangers(); + std::map < int, cxxGasPhase > &Get_GasPhases(); + std::map < int, cxxKinetics > &Get_Kinetics(); + std::map < int, cxxPPassemblage > &Get_PPassemblages(); + std::map < int, cxxSSassemblage > &Get_SSassemblages(); + std::map < int, cxxSurface > &Get_Surfaces(); + std::map < int, cxxMix > &Get_Mixes(); + std::map < int, cxxReaction > &Get_Reactions(); + std::map < int, cxxTemperature > &Get_Temperatures(); + std::map < int, cxxPressure > &Get_Pressures(); cxxSystem & Get_system(void) {return system;}; #ifdef USE_MPI From 3295cd5b832fae54ce0d603748889ed3aedfebe3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 12 Jul 2012 23:23:57 +0000 Subject: [PATCH 0529/1077] Deleted ifdef skips git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6777 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 66 +---------------------------------------------------- 1 file changed, 1 insertion(+), 65 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index ff434503..76162e32 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -247,51 +247,15 @@ warning_msg(const char *err_str) output_msg(warn_str.str().c_str()); output_flush(); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_msg(const char * str, bool force_print) -/* ---------------------------------------------------------------------- */ -{ - clock_t t2 = 0; - if (!force_print) - { - t2 = clock(); - if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) - { - return; - } - else - { - status_timer = t2; - } - } - - if (error_ostream != NULL && (screen_on || force_print)) - { - (*error_ostream) << str; - } - if (force_print) - error_ostream->flush(); -} -#endif /* ---------------------------------------------------------------------- */ void PHRQ_io:: screen_msg(const char * str) /* ---------------------------------------------------------------------- */ { - std::string stdstr(str); -#if defined(ERROR_OSTREAM) if (error_ostream != NULL && screen_on) { - (*error_ostream) << stdstr; + (*error_ostream) << str; } -#else - if (error_file != NULL && screen_on) - { - fprintf(error_file, "%s", str); - } -#endif } #else /* ---------------------------------------------------------------------- */ @@ -375,34 +339,6 @@ warning_msg(const char *err_str) output_msg(warn_str.str().c_str()); output_flush(); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -void PHRQ_io:: -screen_msg(const char * str, bool force_print) -/* ---------------------------------------------------------------------- */ -{ - clock_t t2 = 0; - if (!force_print) - { - t2 = clock(); - if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) - { - return; - } - else - { - status_timer = t2; - } - } - - if (error_ostream != NULL && (screen_on || force_print)) - { - (*error_ostream) << str; - } - if (force_print) - error_ostream->flush(); -} -#endif /* ---------------------------------------------------------------------- */ void PHRQ_io:: screen_msg(const char * str) From 81521287cf790d8c1f90108c3a1b107e02848e8b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 13 Jul 2012 15:14:25 +0000 Subject: [PATCH 0530/1077] Tony's fix for reaction in transport.cpp Used Sleep(5) instead of Sleep(1) throughout. Removed timeout on detaching charts. It will just hang if something goes wrong. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6779 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 35 ++++++++++++++++++++--------------- ChartObject.cpp | 2 +- Keywords.cpp | 4 ++-- Keywords.h | 4 ++-- phreeqc/Form1.h | 7 +++---- phreeqc/transport.cpp | 13 +++++++++++-- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index d597363a..73f3a15e 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -45,7 +45,7 @@ ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) { #if defined(__cplusplus_cli) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); #endif this->current_chart = it->second; phreeqc_ptr-> punch_user_graph(); @@ -86,7 +86,7 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) // Read/update ChartObject #if defined(__cplusplus_cli) while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); #endif { it->second->Read(parser); @@ -113,7 +113,7 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) while (it->second->Get_form_started() && it->second->Get_done() != true) { #if defined(__cplusplus_cli) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); #endif } delete it->second; @@ -125,20 +125,22 @@ bool ChartHandler::End_timer() { - size_t max_tries = 1000; + size_t max_tries = 6000; // 1 h, but not used std::map::iterator it = this->chart_map.begin(); - + if (chart_map.size() > 0) screen_msg("Detaching charts...");; + size_t i(0), i2(0); for ( ; it != chart_map.end(); it++) { - size_t i = 0; + i = 0; it->second->Rate_free(); if (it->second->Get_form_started()) { #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1) && i < max_tries) + while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) { + //if (i > max_tries) break; i++; - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(60); } #endif it->second->Set_end_timer(true); @@ -146,20 +148,23 @@ ChartHandler::End_timer() System::Threading::Interlocked::Exchange(it->second->usingResource, 0); #endif - size_t i2 = 0; - while (it->second->Get_done() != true && i2 < max_tries) + i2 = 0; + while (it->second->Get_done() != true) { + //if (i2 > max_tries) break; i2++; #if defined(__cplusplus_cli) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(60); #endif } - if (i >= max_tries || i2 >= max_tries) - { - error_msg("Chart did not respond.", CONTINUE); - } + //if (i >= max_tries || i2 >= max_tries) + //{ + // error_msg("\nChart did not respond.", CONTINUE); + //} } } + //if (chart_map.size() > 0 && i < max_tries && i2 < max_tries) + screen_msg("\rCharts detached. \n"); this->timer = false; return true; diff --git a/ChartObject.cpp b/ChartObject.cpp index 4b2c58e1..7f64ccb6 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -114,7 +114,7 @@ ChartObject::~ChartObject() { while (0 != System::Threading::Interlocked::Exchange(this->usingResource, 1)) { - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); } this->Rate_free(); delete this->user_graph; diff --git a/Keywords.cpp b/Keywords.cpp index 267e139f..9ea46303 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -126,7 +126,7 @@ std::map::value_type("reaction_pressure_m std::map::value_type("solution_mix", Keywords::KEY_SOLUTION_MIX) }; -std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); +const std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); const std::map::value_type temp_keyword_names[] = { std::map::value_type(Keywords::KEY_NONE, "UNKNOWN"), @@ -200,4 +200,4 @@ std::map::value_type(Keywords::KEY_REACTI std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY"), std::map::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX") }; -std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); +const std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); diff --git a/Keywords.h b/Keywords.h index 33ac8d09..613a4173 100644 --- a/Keywords.h +++ b/Keywords.h @@ -86,8 +86,8 @@ public: static KEYWORDS Keyword_search(std::string key); static const std::string & Keyword_name_search(KEYWORDS key); - static std::map phreeqc_keywords; - static std::map phreeqc_keyword_names; + static const std::map phreeqc_keywords; + static const std::map phreeqc_keyword_names; }; #endif // _INC_KEYWORDS_H \ No newline at end of file diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index e9aacdfb..e899d461 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -403,7 +403,7 @@ namespace zdg_ui2 { // lock thread while (0 != System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 1)) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); DefineCurves(myPane, 0); @@ -841,7 +841,7 @@ namespace zdg_ui2 { //lock for thread while (0 != System::Threading::Interlocked::Exchange(chart->usingResource, 1)) - System::Threading::Thread::Sleep(1); + System::Threading::Thread::Sleep(5); if (this->chartobject_ptr->Get_curve_added()) { @@ -1011,6 +1011,7 @@ namespace zdg_ui2 { /// void InitializeComponent() { + //System::Threading::Thread::Sleep(5000); this->components = (gcnew System::ComponentModel::Container()); this->zg1 = (gcnew ZedGraph::ZedGraphControl()); this->timer1 = (gcnew System::Windows::Forms::Timer( this->components )); @@ -1059,7 +1060,5 @@ namespace zdg_ui2 { this->ResumeLayout(false); } #pragma endregion - - }; } \ No newline at end of file diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index 473a9608..b1b01023 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -212,8 +212,17 @@ transport(void) kin_time_save = kin_time; /* Reaction defined for a shift... */ - if (ishift == 0 && nmix == 1) - step_fraction = 1.0; + //if (ishift == 0 && nmix == 1) + // step_fraction = 1.0; + //else + // step_fraction = 1.0 / (1.0 + nmix); + if (!ishift) + { + if (nmix < 2) + step_fraction = 1.0; + else + step_fraction = 1.0 / nmix; + } else step_fraction = 1.0 / (1.0 + nmix); /* From 64024732db8ac464e21d8746b1137027a7b00aee Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 13 Jul 2012 19:32:08 +0000 Subject: [PATCH 0531/1077] Don't print chart detached unless there are charts. Missing error message when mix solution not found. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6781 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 6 ++++-- phreeqc/step.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 73f3a15e..fa1fffe0 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -163,8 +163,10 @@ ChartHandler::End_timer() //} } } - //if (chart_map.size() > 0 && i < max_tries && i2 < max_tries) - screen_msg("\rCharts detached. \n"); + if (chart_map.size() > 0) + { + screen_msg("\rCharts detached. \n"); + } this->timer = false; return true; diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 96991062..c9f4b12d 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -619,6 +619,9 @@ add_mix(cxxMix *mix_ptr) solution_ptr = Utilities::Rxn_find(Rxn_solution_map, it->first); if (solution_ptr == NULL) { + error_string = sformatf( "Mix solution not found, %d.", + it->first); + error_msg(error_string, CONTINUE); input_error++; continue; } From 87c00324fa14ffc6ee077b9c091d16e83f4d143c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Jul 2012 14:45:14 +0000 Subject: [PATCH 0532/1077] Avoiding null pointer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6782 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/step.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index c9f4b12d..c8793882 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -891,12 +891,14 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) LDBLE coef = it->second; if (elt_ptr == NULL) { + assert (false); } master_ptr = elt_ptr->primary; if (master_ptr == NULL) { - assert (false); + // error msg has been called in reaction_calc + continue; } if (master_ptr->s == s_hplus) { From a826fa57fd2b0e54e468c17d0103e627b97d6924 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Jul 2012 22:20:03 +0000 Subject: [PATCH 0533/1077] Added Update method, removed unused prototypes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6790 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 38 +++++++++++++++++++++++++++++++++++++- Solution.h | 6 +++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 1d2a1a52..a8faa359 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -673,6 +673,42 @@ cxxSolution::read_raw(CParser & parser, bool check) return; } void +cxxSolution::Update(const cxxNameDouble &const_nd) +{ + // const_nd is updated totals + cxxNameDouble simple_original_totals = this->totals.Simplify_redox(); + cxxNameDouble original_activities(this->master_activity); + + this->master_activity.clear(); + + // Update activities + if (original_activities.size() > 0) + { + cxxNameDouble nd = const_nd; + cxxNameDouble simple_this_totals = nd.Simplify_redox(); + cxxNameDouble::iterator it = simple_original_totals.begin(); + for ( ; it != simple_original_totals.end(); it++) + { + cxxNameDouble::iterator jit = simple_this_totals.find(it->first); + if (jit != simple_this_totals.end()) + { + if (it->second != 0) + { + LDBLE f = jit->second / it->second; + if (f != 1) + { + original_activities.Multiply_activities_redox(it->first, f); + } + } + } + } + original_activities.merge_redox(this->master_activity); + this->master_activity = original_activities; + } + + return; +} +void cxxSolution::zero() { this->tc = 0.0; @@ -740,7 +776,7 @@ cxxSolution::multiply(LDBLE extensive) } LDBLE -cxxSolution::Get_total(char *string) const +cxxSolution::Get_total(const char *string) const { cxxNameDouble::const_iterator it = this->totals.find(string); if (it == this->totals.end()) diff --git a/Solution.h b/Solution.h index 91ed692d..b48db4fe 100644 --- a/Solution.h +++ b/Solution.h @@ -96,12 +96,12 @@ class cxxSolution:public cxxNumKeyword LDBLE Get_master_activity(char *string) const; void Set_master_activity(char *string, LDBLE value); - LDBLE Get_total(char *string) const; + LDBLE Get_total(const char *string) const; LDBLE Get_total_element(const char *string) const; void Set_total(char *string, LDBLE value); void read_raw(CParser & parser, bool check = true); - void modify_activities(const cxxSolution & original); - void Simplify_totals(); + //void modify_activities(const cxxSolution & original); + //void Simplify_totals(); void Update(const cxxNameDouble &nd); #ifdef USE_MPI From 065f7ea3466445ebcd72b0428a31936847d24c9d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 17 Jul 2012 01:06:46 +0000 Subject: [PATCH 0534/1077] BUG FIX: runs that threw didn't close the input file(s) and do_status was never called. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6792 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/mainsubs.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 401dbf1e..68f6439e 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2754,12 +2754,7 @@ do_status(void) if (pr.status == TRUE) { -#if defined(PHREEQCI_GUI) - state = -1; - status(0, "\r\nDone."); -#else status(0, "\nDone."); -#endif screen_msg("\n"); } pr.headings = TRUE; From b0b007ca92ba9ea9b670bd424a735f68fa733a91 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 17 Jul 2012 17:12:50 +0000 Subject: [PATCH 0535/1077] const static vopts git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6793 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 51 ++++++++++++++++----------------- ChartObject.h | 1 + ExchComp.cxx | 33 +++++++++------------ ExchComp.h | 2 +- Exchange.cxx | 27 +++++++----------- Exchange.h | 1 + GasComp.cxx | 23 ++++++--------- GasComp.h | 1 + GasPhase.cxx | 40 +++++++++++--------------- GasPhase.h | 1 + KineticsComp.cxx | 28 +++++++----------- KineticsComp.h | 2 +- PPassemblage.cxx | 22 ++++++-------- PPassemblage.h | 2 +- PPassemblageComp.cxx | 35 +++++++++-------------- PPassemblageComp.h | 2 +- Pressure.cxx | 20 +++++-------- Pressure.h | 2 +- Reaction.cxx | 26 +++++++---------- Reaction.h | 2 +- SS.cxx | 49 ++++++++++++++----------------- SS.h | 1 + SSassemblage.cxx | 20 +++++-------- SSassemblage.h | 1 + SScomp.cxx | 35 +++++++++-------------- SScomp.h | 1 + Solution.cxx | 58 +++++++++++++++++-------------------- Solution.h | 1 + SolutionIsotope.cxx | 29 +++++++------------ SolutionIsotope.h | 1 + StorageBinList.cpp | 50 ++++++++++++++------------------ StorageBinList.h | 1 + Surface.cxx | 49 ++++++++++++++----------------- Surface.h | 1 + SurfaceCharge.cxx | 44 +++++++++++++--------------- SurfaceCharge.h | 1 + SurfaceComp.cxx | 41 +++++++++++--------------- SurfaceComp.h | 1 + Temperature.cxx | 19 ++++--------- Temperature.h | 2 +- cxxKinetics.cxx | 37 +++++++++++------------- cxxKinetics.h | 1 + cxxMix.cxx | 12 ++------ cxxMix.h | 1 + dumper.cpp | 68 ++++++++++++++++++++------------------------ dumper.h | 1 + runner.cpp | 26 +++++++---------- runner.h | 1 + 48 files changed, 369 insertions(+), 504 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 7f64ccb6..e244169c 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -243,34 +243,7 @@ ChartObject::Set_axis_scale(CParser & parser) bool ChartObject::Read(CParser & parser) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(20); - vopts.push_back("start"); // 0 - vopts.push_back("end"); // 1 - vopts.push_back("heading"); // 2 - vopts.push_back("headings"); // 3 - vopts.push_back("chart_title"); // 4 - vopts.push_back("axis_titles"); // 5 - vopts.push_back("axis_scale"); // 6 - vopts.push_back("initial_solutions"); // 7 - vopts.push_back("plot_concentration_vs"); // 8 - vopts.push_back("shifts_as_points"); // 9 - vopts.push_back("grid_offset"); // 10 - vopts.push_back("connect_simulations"); // 11 - vopts.push_back("plot_csv_file"); // 12 - vopts.push_back("clear"); // 13 - vopts.push_back("detach"); // 14 - vopts.push_back("active"); // 15 - vopts.push_back("batch"); // 16 - vopts.push_back("plot_tsv_file"); // 17 - } std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -1418,4 +1391,28 @@ ChartObject::dump(std::ostream & oss, unsigned int indent) bool form_started; */ } + +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("start"), // 0 + std::vector< std::string >::value_type("end"), // 1 + std::vector< std::string >::value_type("heading"), // 2 + std::vector< std::string >::value_type("headings"), // 3 + std::vector< std::string >::value_type("chart_title"), // 4 + std::vector< std::string >::value_type("axis_titles"), // 5 + std::vector< std::string >::value_type("axis_scale"), // 6 + std::vector< std::string >::value_type("initial_solutions"), // 7 + std::vector< std::string >::value_type("plot_concentration_vs"), // 8 + std::vector< std::string >::value_type("shifts_as_points"), // 9 + std::vector< std::string >::value_type("grid_offset"), // 10 + std::vector< std::string >::value_type("connect_simulations"), // 11 + std::vector< std::string >::value_type("plot_csv_file"), // 12 + std::vector< std::string >::value_type("clear"), // 13 + std::vector< std::string >::value_type("detach"), // 14 + std::vector< std::string >::value_type("active"), // 15 + std::vector< std::string >::value_type("batch"), // 16 + std::vector< std::string >::value_type("plot_tsv_file") // 17 +}; +const std::vector< std::string > ChartObject::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); + + #endif // MULTICHART \ No newline at end of file diff --git a/ChartObject.h b/ChartObject.h index 2bac49ba..91b530f0 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -430,6 +430,7 @@ class ChartObject:public cxxNumKeyword bool batch_background; std::string batch_fn; chart_batch_type batch; + const static std::vector < std::string > vopts; public: int usingResource; diff --git a/ExchComp.cxx b/ExchComp.cxx index 25ae0c2c..a1262519 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -179,26 +179,6 @@ cxxExchComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("formula"); // 0 - vopts.push_back("moles"); // 1 - vopts.push_back("la"); // 2 - vopts.push_back("charge_balance"); // 3 - vopts.push_back("phase_name"); // 4 - vopts.push_back("rate_name"); // 5 - vopts.push_back("formula_z"); // 6 - vopts.push_back("phase_proportion"); // 7 - vopts.push_back("totals"); // 8 - vopts.push_back("formula_totals"); // 9 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -464,3 +444,16 @@ cxxExchComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) *dd = d; } #endif +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("formula"), // 0 + std::vector< std::string >::value_type("moles"), // 1 + std::vector< std::string >::value_type("la"), // 2 + std::vector< std::string >::value_type("charge_balance"), // 3 + std::vector< std::string >::value_type("phase_name"), // 4 + std::vector< std::string >::value_type("rate_name"), // 5 + std::vector< std::string >::value_type("formula_z"), // 6 + std::vector< std::string >::value_type("phase_proportion"), // 7 + std::vector< std::string >::value_type("totals"), // 8 + std::vector< std::string >::value_type("formula_totals") // 9 +}; +const std::vector< std::string > cxxExchComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/ExchComp.h b/ExchComp.h index 45941d0b..c2ea9494 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -120,7 +120,7 @@ class cxxExchComp: public PHRQ_base LDBLE phase_proportion; std::string rate_name; LDBLE formula_z; // charge on formula - + const static std::vector < std::string > vopts; public: }; diff --git a/Exchange.cxx b/Exchange.cxx index 06e314ff..5eea0aaf 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -196,23 +196,6 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxExchange::read_raw(CParser & parser, bool check) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("pitzer_exchange_gammas"); // 0 - vopts.push_back("component"); // 1 - vopts.push_back("exchange_gammas"); // 2 - vopts.push_back("new_def"); // 3 - vopts.push_back("solution_equilibria"); // 4 - vopts.push_back("n_solution"); // 5 - vopts.push_back("totals"); // 6 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -498,3 +481,13 @@ Sort_comps(void) } } } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("pitzer_exchange_gammas"), // 0 + std::vector< std::string >::value_type("component"), // 1 + std::vector< std::string >::value_type("exchange_gammas"), // 2 + std::vector< std::string >::value_type("new_def"), // 3 + std::vector< std::string >::value_type("solution_equilibria"), // 4 + std::vector< std::string >::value_type("n_solution"), // 5 + std::vector< std::string >::value_type("totals") // 6 +}; +const std::vector< std::string > cxxExchange::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/Exchange.h b/Exchange.h index adbf5b40..44f48f9d 100644 --- a/Exchange.h +++ b/Exchange.h @@ -68,6 +68,7 @@ protected: // exchange workspace variables cxxNameDouble totals; + const static std::vector < std::string > vopts; public: }; diff --git a/GasComp.cxx b/GasComp.cxx index c6da042b..af3973b8 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -62,20 +62,6 @@ cxxGasComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("phase_name"); // 0 - vopts.push_back("name"); // 1 - vopts.push_back("p_read"); // 2 - vopts.push_back("moles"); // 3 - vopts.push_back("initial_moles"); // 4 - } int errors = parser.get_input_error(); std::istream::pos_type ptr; @@ -192,4 +178,11 @@ cxxGasComp::multiply(LDBLE extensive) this->moles *= extensive; this->initial_moles *= extensive; } - +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("phase_name"), // 0 + std::vector< std::string >::value_type("name"), // 1 + std::vector< std::string >::value_type("p_read"), // 2 + std::vector< std::string >::value_type("moles"), // 3 + std::vector< std::string >::value_type("initial_moles") // 4 +}; +const std::vector< std::string > cxxGasComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/GasComp.h b/GasComp.h index 3973d25d..e4ab7663 100644 --- a/GasComp.h +++ b/GasComp.h @@ -46,6 +46,7 @@ class cxxGasComp: public PHRQ_base LDBLE p_read; // internal workspace LDBLE initial_moles; + const static std::vector < std::string > vopts; }; #endif // !defined(GASCOMP_H_INCLUDED) diff --git a/GasPhase.cxx b/GasPhase.cxx index 8b15ad0f..5774651a 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -273,28 +273,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { int i; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("type"); //0 - vopts.push_back("total_p"); //1 - vopts.push_back("volume"); //2 - vopts.push_back("v_m"); //3 - vopts.push_back("component"); //4 - vopts.push_back("pressure"); //5 - vopts.push_back("pr_in"); //6 - vopts.push_back("new_def"); //7 - vopts.push_back("solution_equilibria"); //8 - vopts.push_back("n_solution"); //9 - vopts.push_back("total_moles"); //10 - vopts.push_back("temperature"); //11 - vopts.push_back("totals"); //12 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -631,4 +609,20 @@ cxxGasPhase::Find_comp(const char * comp_name) } } return NULL; -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("type"), //0 + std::vector< std::string >::value_type("total_p"), //1 + std::vector< std::string >::value_type("volume"), //2 + std::vector< std::string >::value_type("v_m"), //3 + std::vector< std::string >::value_type("component"), //4 + std::vector< std::string >::value_type("pressure"), //5 + std::vector< std::string >::value_type("pr_in"), //6 + std::vector< std::string >::value_type("new_def"), //7 + std::vector< std::string >::value_type("solution_equilibria"), //8 + std::vector< std::string >::value_type("n_solution"), //9 + std::vector< std::string >::value_type("total_moles"), //10 + std::vector< std::string >::value_type("temperature"), //11 + std::vector< std::string >::value_type("totals") //12 +}; +const std::vector< std::string > cxxGasPhase::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/GasPhase.h b/GasPhase.h index 7796c999..d703cfe9 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -94,6 +94,7 @@ protected: LDBLE v_m; bool pr_in; cxxNameDouble totals; + const static std::vector < std::string > vopts; }; #endif // !defined(GASPHASE_H_INCLUDED) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index e7824a33..a764e5e0 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -134,23 +134,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("rate_name_not_used"); // 0 - vopts.push_back("tol"); // 1 - vopts.push_back("m"); // 2 - vopts.push_back("m0"); // 3 - vopts.push_back("moles"); // 4 - vopts.push_back("namecoef"); // 5 - vopts.push_back("d_params"); // 6 - vopts.push_back("initial_moles"); // 7 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -366,3 +349,14 @@ cxxKineticsComp::multiply(LDBLE extensive) this->m0 *= extensive; this->moles *= extensive; } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("rate_name_not_used"), // 0 + std::vector< std::string >::value_type("tol"), // 1 + std::vector< std::string >::value_type("m"), // 2 + std::vector< std::string >::value_type("m0"), // 3 + std::vector< std::string >::value_type("moles"), // 4 + std::vector< std::string >::value_type("namecoef"), // 5 + std::vector< std::string >::value_type("d_params"), // 6 + std::vector< std::string >::value_type("initial_moles") // 7 +}; +const std::vector< std::string > cxxKineticsComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/KineticsComp.h b/KineticsComp.h index 747003e5..9fdcfbad 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -71,7 +71,7 @@ public: // kinetics workspace variables LDBLE moles; LDBLE initial_moles; - + const static std::vector < std::string > vopts; public: }; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 05b97e11..5864cb75 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -125,19 +125,6 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxPPassemblage::read_raw(CParser & parser, bool check) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("eltlist"); // 0 - vopts.push_back("component"); // 1 - vopts.push_back("new_def"); // 2 - vopts.push_back("assemblage_totals"); // 3 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -359,4 +346,11 @@ Find(const std::string name_in) } } return comp; -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("eltlist"), // 0 + std::vector< std::string >::value_type("component"), // 1 + std::vector< std::string >::value_type("new_def"), // 2 + std::vector< std::string >::value_type("assemblage_totals") // 3 +}; +const std::vector< std::string > cxxPPassemblage::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/PPassemblage.h b/PPassemblage.h index 14738123..6e29930b 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -66,7 +66,7 @@ protected: std::map pp_assemblage_comps; cxxNameDouble eltList; // list of elements in phases (and alternate reactions) cxxNameDouble assemblage_totals; // after totalize, total moles of elements in the PPassemblage - + const static std::vector < std::string > vopts; }; #endif // !defined(PPASSEMBLAGE_H_INCLUDED) diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 6d69f728..5dc30aec 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -106,27 +106,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("name"); // 0 - vopts.push_back("add_formula"); // 1 - vopts.push_back("si"); // 2 - vopts.push_back("moles"); // 3 - vopts.push_back("delta"); // 4 - vopts.push_back("initial_moles"); // 5 - vopts.push_back("dissolve_only"); // 6 - vopts.push_back("force_equality"); // 7 - vopts.push_back("precipitate_only"); // 8 - vopts.push_back("si_org"); // 9 - vopts.push_back("totals"); // 10 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -448,3 +427,17 @@ cxxPPassemblageComp::multiply(LDBLE extensive) this->delta *= extensive; this->initial_moles *= extensive; } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("name"), // 0 + std::vector< std::string >::value_type("add_formula"), // 1 + std::vector< std::string >::value_type("si"), // 2 + std::vector< std::string >::value_type("moles"), // 3 + std::vector< std::string >::value_type("delta"), // 4 + std::vector< std::string >::value_type("initial_moles"), // 5 + std::vector< std::string >::value_type("dissolve_only"), // 6 + std::vector< std::string >::value_type("force_equality"), // 7 + std::vector< std::string >::value_type("precipitate_only"), // 8 + std::vector< std::string >::value_type("si_org"), // 9 + std::vector< std::string >::value_type("totals") // 10 +}; +const std::vector< std::string > cxxPPassemblageComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/PPassemblageComp.h b/PPassemblageComp.h index ce68aec1..254e130e 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -78,7 +78,7 @@ protected: bool dissolve_only; bool precipitate_only; cxxNameDouble totals; - + const static std::vector < std::string > vopts; public: }; diff --git a/Pressure.cxx b/Pressure.cxx index 6531a994..b91249da 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -198,18 +198,6 @@ cxxPressure::read_raw(CParser & parser) bool cleared_once = false; LDBLE d; CParser::TOKEN_TYPE k; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(5); - vopts.push_back("pressures"); //0 - vopts.push_back("equal_increments"); //1 - vopts.push_back("count"); //2 - } std::istream::pos_type ptr; std::istream::pos_type next_char = 0; @@ -407,4 +395,10 @@ Get_count(void) const return this->count; } return (int) this->pressures.size(); -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("pressures"), //0 + std::vector< std::string >::value_type("equal_increments"), //1 + std::vector< std::string >::value_type("count") //2 +}; +const std::vector< std::string > cxxPressure::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/Pressure.h b/Pressure.h index da9fe36f..fc7209fe 100644 --- a/Pressure.h +++ b/Pressure.h @@ -33,7 +33,7 @@ protected: std::vector < LDBLE >pressures; int count; bool equalIncrements; - + const static std::vector < std::string > vopts; }; #endif // !defined(PRESSURE_H_INCLUDED) diff --git a/Reaction.cxx b/Reaction.cxx index 298f0074..44252814 100644 --- a/Reaction.cxx +++ b/Reaction.cxx @@ -131,21 +131,6 @@ cxxReaction::read_raw(CParser & parser, const bool check) int j; LDBLE d; CParser::TOKEN_TYPE k; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("units"); //0 - vopts.push_back("reactant_list"); //1 - vopts.push_back("element_list"); //2 - vopts.push_back("steps"); //3 - vopts.push_back("equal_increments"); //4 - vopts.push_back("count_steps"); //5 - } // clear steps for modify operation, if steps are read bool cleared_once = false; @@ -315,4 +300,13 @@ Get_reaction_steps(void) const return this->countSteps; } return (int) this->steps.size(); -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("units"), //0 + std::vector< std::string >::value_type("reactant_list"), //1 + std::vector< std::string >::value_type("element_list"), //2 + std::vector< std::string >::value_type("steps"), //3 + std::vector< std::string >::value_type("equal_increments"), //4 + std::vector< std::string >::value_type("count_steps") //5 +}; +const std::vector< std::string > cxxReaction::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/Reaction.h b/Reaction.h index ea15340c..d03cef64 100644 --- a/Reaction.h +++ b/Reaction.h @@ -51,7 +51,7 @@ protected: int countSteps; bool equalIncrements; std::string units; - + const static std::vector < std::string > vopts; }; #endif // !defined(REACTION_H_INCLUDED) diff --git a/SS.cxx b/SS.cxx index 04e8ba1f..d692d38b 100644 --- a/SS.cxx +++ b/SS.cxx @@ -126,34 +126,6 @@ cxxSS::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("ss_name"); // 0 - vopts.push_back("total_moles"); // 1 - vopts.push_back("a0"); // 2 - vopts.push_back("a1"); // 3 - vopts.push_back("components"); // 4 - vopts.push_back("miscibility"); // 5 - vopts.push_back("spinodal"); // 6 - vopts.push_back("tk"); // 7 - vopts.push_back("xb1"); // 8 - 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("p"); //14 - vopts.push_back("ss_in"); //15 - vopts.push_back("totals"); //16 - vopts.push_back("dn"); //17 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -596,3 +568,24 @@ cxxSS::Find(const char * comp_name) } return NULL; } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("ss_name"), // 0 + std::vector< std::string >::value_type("total_moles"), // 1 + std::vector< std::string >::value_type("a0"), // 2 + std::vector< std::string >::value_type("a1"), // 3 + std::vector< std::string >::value_type("components"), // 4 + std::vector< std::string >::value_type("miscibility"), // 5 + std::vector< std::string >::value_type("spinodal"), // 6 + std::vector< std::string >::value_type("tk"), // 7 + std::vector< std::string >::value_type("xb1"), // 8 + std::vector< std::string >::value_type("xb2"), // 9 + std::vector< std::string >::value_type("ag0"), // 10 + std::vector< std::string >::value_type("ag1"), // 11 + std::vector< std::string >::value_type("component"), // 12 + std::vector< std::string >::value_type("input_case"), //13 + std::vector< std::string >::value_type("p"), //14 + std::vector< std::string >::value_type("ss_in"), //15 + std::vector< std::string >::value_type("totals"), //16 + std::vector< std::string >::value_type("dn") //17 +}; +const std::vector< std::string > cxxSS::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/SS.h b/SS.h index 1896c881..24932d0d 100644 --- a/SS.h +++ b/SS.h @@ -121,6 +121,7 @@ protected: LDBLE dn; bool ss_in; cxxNameDouble totals; + const static std::vector < std::string > vopts; public: }; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 68710afe..4c554b98 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -126,18 +126,6 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) void cxxSSassemblage::read_raw(CParser & parser, bool check) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("solid_solution"); // 0 - vopts.push_back("ssassemblage_totals"); // 1 - vopts.push_back("new_def"); // 2 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -339,4 +327,10 @@ Find(const std::string &s) if (it != this->SSs.end()) return &(it->second); return NULL; -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("solid_solution"), // 0 + std::vector< std::string >::value_type("ssassemblage_totals"), // 1 + std::vector< std::string >::value_type("new_def") // 2 +}; +const std::vector< std::string > cxxSSassemblage::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/SSassemblage.h b/SSassemblage.h index 58cad0b0..1a514836 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -55,6 +55,7 @@ protected: bool new_def; // internal variables cxxNameDouble totals; + const static std::vector < std::string > vopts; }; #endif // !defined(SSASSEMBLAGE_H_INCLUDED) diff --git a/SScomp.cxx b/SScomp.cxx index fad17289..15ec60f0 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -92,27 +92,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(10); - vopts.push_back("name"); // 0 - vopts.push_back("initial_moles"); // 1 - vopts.push_back("moles"); // 2 - vopts.push_back("init_moles"); // 3 - vopts.push_back("delta"); // 4 - 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"); // 10 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -337,3 +316,17 @@ cxxSScomp::multiply(double extensive) this->delta *= extensive; this->initial_moles *= extensive; } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("name"), // 0 + std::vector< std::string >::value_type("initial_moles"), // 1 + std::vector< std::string >::value_type("moles"), // 2 + std::vector< std::string >::value_type("init_moles"), // 3 + std::vector< std::string >::value_type("delta"), // 4 + std::vector< std::string >::value_type("fraction_x"), // 5 + std::vector< std::string >::value_type("log10_lambda"), // 6 + std::vector< std::string >::value_type("log10_fraction_x"), // 7 + std::vector< std::string >::value_type("dn"), // 8 + std::vector< std::string >::value_type("dnc"), // 9 + std::vector< std::string >::value_type("dnb") // 10 +}; +const std::vector< std::string > cxxSScomp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/SScomp.h b/SScomp.h index a26ea1d7..0b0f4b55 100644 --- a/SScomp.h +++ b/SScomp.h @@ -62,6 +62,7 @@ protected: LDBLE log10_lambda; LDBLE log10_fraction_x; LDBLE dn, dnc, dnb; + const static std::vector < std::string > vopts; }; #endif // !defined(SSCOMP_H_INCLUDED) diff --git a/Solution.cxx b/Solution.cxx index a8faa359..8deb02db 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -291,37 +291,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con void cxxSolution::read_raw(CParser & parser, bool check) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(21); - vopts.push_back("totals"); // 0 - vopts.push_back("activities"); // 1 - vopts.push_back("gammas"); // 2 - vopts.push_back("isotopes"); // 3 - vopts.push_back("temp"); // 4 - vopts.push_back("tc_avoid_conflict_with_technetium"); // 5 - vopts.push_back("temperature"); // 6 - vopts.push_back("ph"); // 7 - vopts.push_back("pe"); // 8 - vopts.push_back("mu"); // 9 - vopts.push_back("ionic_strength"); // 10 - vopts.push_back("ah2o"); // 11 - vopts.push_back("activity_water"); // 12 - vopts.push_back("total_h"); // 13 - vopts.push_back("total_o"); // 14 - vopts.push_back("mass_water"); // 15 - vopts.push_back("mass_h2o"); // 16 - vopts.push_back("total_alkalinity"); // 17 - vopts.push_back("total_alk"); // 18 - vopts.push_back("cb"); // 19 - vopts.push_back("charge_balance"); // 20 - vopts.push_back("density"); // 21 - } // Used if it is modify cxxNameDouble simple_original_totals = this->totals.Simplify_redox(); @@ -1157,4 +1126,29 @@ cxxSolution::Multiply_isotopes(LDBLE extensive) total *= extensive; it->second.Set_total(total); } -} \ No newline at end of file +} +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("totals"), // 0 + std::vector< std::string >::value_type("activities"), // 1 + std::vector< std::string >::value_type("gammas"), // 2 + std::vector< std::string >::value_type("isotopes"), // 3 + std::vector< std::string >::value_type("temp"), // 4 + std::vector< std::string >::value_type("tc_avoid_conflict_with_technetium"), // 5 + std::vector< std::string >::value_type("temperature"), // 6 + std::vector< std::string >::value_type("ph"), // 7 + std::vector< std::string >::value_type("pe"), // 8 + std::vector< std::string >::value_type("mu"), // 9 + std::vector< std::string >::value_type("ionic_strength"), // 10 + std::vector< std::string >::value_type("ah2o"), // 11 + std::vector< std::string >::value_type("activity_water"), // 12 + std::vector< std::string >::value_type("total_h"), // 13 + std::vector< std::string >::value_type("total_o"), // 14 + std::vector< std::string >::value_type("mass_water"), // 15 + std::vector< std::string >::value_type("mass_h2o"), // 16 + std::vector< std::string >::value_type("total_alkalinity"), // 17 + std::vector< std::string >::value_type("total_alk"), // 18 + std::vector< std::string >::value_type("cb"), // 19 + std::vector< std::string >::value_type("charge_balance"), // 20 + std::vector< std::string >::value_type("density") // 21 +}; +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/Solution.h b/Solution.h index b48db4fe..74f23e0a 100644 --- a/Solution.h +++ b/Solution.h @@ -131,6 +131,7 @@ class cxxSolution:public cxxNumKeyword //cxxSolutionIsotopeList isotopes; std::map < std::string, cxxSolutionIsotope > isotopes; cxxISolution *initial_data; + const static std::vector < std::string > vopts; }; #endif // !defined(SOLUTION_H_INCLUDED) diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 6d752720..4ce3dc95 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -95,23 +95,6 @@ cxxSolutionIsotope::dump_raw(std::ostream & s_oss, unsigned int indent) const } void cxxSolutionIsotope::read_raw(CParser & parser, bool check ) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(21); - vopts.push_back("isotope_number"); // 0 - vopts.push_back("elt_name"); // 1 - vopts.push_back("total"); // 2 - vopts.push_back("ratio"); // 3 - vopts.push_back("ratio_uncertainty_defined"); // 4 - vopts.push_back("ratio_uncertainty"); // 5 - vopts.push_back("x_ratio_uncertainty"); // 6 - vopts.push_back("coef"); // 7 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -302,4 +285,14 @@ cxxSolutionIsotope::multiply(LDBLE extensive) { this->total *= extensive; } - +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("isotope_number"), // 0 + std::vector< std::string >::value_type("elt_name"), // 1 + std::vector< std::string >::value_type("total"), // 2 + std::vector< std::string >::value_type("ratio"), // 3 + std::vector< std::string >::value_type("ratio_uncertainty_defined"), // 4 + std::vector< std::string >::value_type("ratio_uncertainty"), // 5 + std::vector< std::string >::value_type("x_ratio_uncertainty"), // 6 + std::vector< std::string >::value_type("coef") // 7 +}; +const std::vector< std::string > cxxSolutionIsotope::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/SolutionIsotope.h b/SolutionIsotope.h index b8cf73ae..ff83b876 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -77,5 +77,6 @@ class cxxSolutionIsotope: public PHRQ_base bool ratio_uncertainty_defined; LDBLE x_ratio_uncertainty; LDBLE coef; /* coefficient of element in phase */ + const static std::vector < std::string > vopts; }; #endif // SOLUTIONISOTOPE_H_INCLUDED diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 239f0660..53a37660 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -138,34 +138,6 @@ void StorageBinList::SetAll(bool tf) bool StorageBinList::Read(CParser & parser) { bool return_value(true); -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(20); - vopts.push_back("solution"); - vopts.push_back("pp_assemblage"); - vopts.push_back("equilibrium_phases"); - vopts.push_back("exchange"); - vopts.push_back("surface"); - vopts.push_back("ss_assemblage"); - vopts.push_back("solid_solution"); - vopts.push_back("solid_solutions"); - vopts.push_back("gas_phase"); - vopts.push_back("kinetics"); - vopts.push_back("mix"); - vopts.push_back("reaction"); - vopts.push_back("temperature"); - vopts.push_back("all"); // 13 - vopts.push_back("cell"); - vopts.push_back("cells"); // 15 - vopts.push_back("reaction_temperature"); - vopts.push_back("pressure"); //17 - vopts.push_back("reaction_pressure"); //18 - } std::istream::pos_type next_char; std::string token; @@ -329,3 +301,25 @@ void StorageBinList::TransferAll(StorageBinListItem &source) this->pressure.Augment(*it); } } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("solution"), // 0 + std::vector< std::string >::value_type("pp_assemblage"), // 1 + std::vector< std::string >::value_type("equilibrium_phases"), // 2 + std::vector< std::string >::value_type("exchange"), // 3 + std::vector< std::string >::value_type("surface"), // 4 + std::vector< std::string >::value_type("ss_assemblage"), // 5 + std::vector< std::string >::value_type("solid_solution"), // 6 + std::vector< std::string >::value_type("solid_solutions"), // 7 + std::vector< std::string >::value_type("gas_phase"), // 8 + std::vector< std::string >::value_type("kinetics"), // 9 + std::vector< std::string >::value_type("mix"), // 10 + std::vector< std::string >::value_type("reaction"), // 11 + std::vector< std::string >::value_type("temperature"), // 12 + std::vector< std::string >::value_type("all"), // 13 + std::vector< std::string >::value_type("cell"), // 14 + std::vector< std::string >::value_type("cells"), // 15 + std::vector< std::string >::value_type("reaction_temperature"), // 16 + std::vector< std::string >::value_type("pressure"), // 17 + std::vector< std::string >::value_type("reaction_pressure") // 18 +}; +const std::vector< std::string > StorageBinList::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/StorageBinList.h b/StorageBinList.h index cf2ce771..0825bb19 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -56,6 +56,7 @@ protected: StorageBinListItem reaction; StorageBinListItem temperature; StorageBinListItem pressure; + const static std::vector < std::string > vopts; }; diff --git a/Surface.cxx b/Surface.cxx index 4083775e..f730d36b 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -234,35 +234,7 @@ cxxSurface::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) cons void cxxSurface::read_raw(CParser & parser, bool check) { -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif int i = 0; - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("diffuse_layer"); // 0 - vopts.push_back("edl"); // 1 - vopts.push_back("only_counter_ions"); // 2 - vopts.push_back("donnan"); // 3 - vopts.push_back("thickness"); // 4 - vopts.push_back("component"); // 5 - vopts.push_back("charge_component"); // 6 - vopts.push_back("type "); // 7 - vopts.push_back("dl_type"); // 8 - vopts.push_back("sites_units"); // 9 - vopts.push_back("debye_lengths"); // 10 - vopts.push_back("ddl_viscosity"); // 11 - vopts.push_back("ddl_limit"); // 12 - vopts.push_back("transport"); // 13 - vopts.push_back("new_def"); // 14 - vopts.push_back("solution_equilibria"); // 15 - vopts.push_back("n_solution"); // 16 - vopts.push_back("totals"); // 17 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -850,3 +822,24 @@ Sort_comps(void) } } } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("diffuse_layer"), // 0 + std::vector< std::string >::value_type("edl"), // 1 + std::vector< std::string >::value_type("only_counter_ions"), // 2 + std::vector< std::string >::value_type("donnan"), // 3 + std::vector< std::string >::value_type("thickness"), // 4 + std::vector< std::string >::value_type("component"), // 5 + std::vector< std::string >::value_type("charge_component"), // 6 + std::vector< std::string >::value_type("type "), // 7 + std::vector< std::string >::value_type("dl_type"), // 8 + std::vector< std::string >::value_type("sites_units"), // 9 + std::vector< std::string >::value_type("debye_lengths"), // 10 + std::vector< std::string >::value_type("ddl_viscosity"), // 11 + std::vector< std::string >::value_type("ddl_limit"), // 12 + std::vector< std::string >::value_type("transport"), // 13 + std::vector< std::string >::value_type("new_def"), // 14 + std::vector< std::string >::value_type("solution_equilibria"), // 15 + std::vector< std::string >::value_type("n_solution"), // 16 + std::vector< std::string >::value_type("totals") // 17 +}; +const std::vector< std::string > cxxSurface::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/Surface.h b/Surface.h index b2cf3c4b..08333023 100644 --- a/Surface.h +++ b/Surface.h @@ -95,6 +95,7 @@ protected: cxxNameDouble totals; bool solution_equilibria; int n_solution; + const static std::vector < std::string > vopts; }; #endif // !defined(SURFACE_H_INCLUDED) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 8203c52a..3c5dba4f 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -118,31 +118,6 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("name"); // 0 - vopts.push_back("specific_area"); // 1 - vopts.push_back("grams"); // 2 - vopts.push_back("charge_balance"); // 3 - vopts.push_back("mass_water"); // 4 - vopts.push_back("la_psi"); // 5 - vopts.push_back("diffuse_layer_totals"); // 6 - vopts.push_back("la_psi1"); // 7 - vopts.push_back("la_psi2"); // 8 - vopts.push_back("capacitance0"); // 9 - vopts.push_back("capacitance1"); // 10 - vopts.push_back("sigma0"); // 11 - vopts.push_back("sigma1"); // 12 - vopts.push_back("sigma2"); // 13 - vopts.push_back("sigmaddl"); // 14 - vopts.push_back("g_map"); // 14 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -485,3 +460,22 @@ cxxSurfaceCharge::multiply(LDBLE extensive) this->mass_water *= extensive; this->diffuse_layer_totals.multiply(extensive); } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("name"), // 0 + std::vector< std::string >::value_type("specific_area"), // 1 + std::vector< std::string >::value_type("grams"), // 2 + std::vector< std::string >::value_type("charge_balance"), // 3 + std::vector< std::string >::value_type("mass_water"), // 4 + std::vector< std::string >::value_type("la_psi"), // 5 + std::vector< std::string >::value_type("diffuse_layer_totals"), // 6 + std::vector< std::string >::value_type("la_psi1"), // 7 + std::vector< std::string >::value_type("la_psi2"), // 8 + std::vector< std::string >::value_type("capacitance0"), // 9 + std::vector< std::string >::value_type("capacitance1"), // 10 + std::vector< std::string >::value_type("sigma0"), // 11 + std::vector< std::string >::value_type("sigma1"), // 12 + std::vector< std::string >::value_type("sigma2"), // 13 + std::vector< std::string >::value_type("sigmaddl"), // 14 + std::vector< std::string >::value_type("g_map") // 15 +}; +const std::vector< std::string > cxxSurfaceCharge::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 6426b786..b3204267 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -121,6 +121,7 @@ protected: // workspace variables LDBLE sigma0, sigma1, sigma2, sigmaddl; std::map g_map; + const static std::vector < std::string > vopts; }; #endif // !defined(SURFACECHARGE_H_INCLUDED) diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 057a4aca..8dfefb3a 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -114,29 +114,6 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) { std::string str; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("formula"); // 0 - vopts.push_back("moles"); // 1 - vopts.push_back("la"); // 2 - vopts.push_back("charge_number"); // 3 - vopts.push_back("charge_balance"); // 4 - vopts.push_back("phase_name"); // 5 - vopts.push_back("rate_name"); // 6 - vopts.push_back("phase_proportion"); // 7 - vopts.push_back("totals"); // 8 - vopts.push_back("formula_z"); // 9 - vopts.push_back("formula_totals"); // 10 - vopts.push_back("dw"); // 11 - vopts.push_back("charge_name"); // 12 - vopts.push_back("master_element"); // 13 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -509,4 +486,20 @@ cxxSurfaceComp::multiply(LDBLE extensive) this->charge_balance *= extensive; } - +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("formula"), // 0 + std::vector< std::string >::value_type("moles"), // 1 + std::vector< std::string >::value_type("la"), // 2 + std::vector< std::string >::value_type("charge_number"), // 3 + std::vector< std::string >::value_type("charge_balance"), // 4 + std::vector< std::string >::value_type("phase_name"), // 5 + std::vector< std::string >::value_type("rate_name"), // 6 + std::vector< std::string >::value_type("phase_proportion"), // 7 + std::vector< std::string >::value_type("totals"), // 8 + std::vector< std::string >::value_type("formula_z"), // 9 + std::vector< std::string >::value_type("formula_totals"), // 10 + std::vector< std::string >::value_type("dw"), // 11 + std::vector< std::string >::value_type("charge_name"), // 12 + std::vector< std::string >::value_type("master_element") // 13 +}; +const std::vector< std::string > cxxSurfaceComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/SurfaceComp.h b/SurfaceComp.h index 3857592e..dc324f7e 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -65,6 +65,7 @@ protected: std::string rate_name; LDBLE Dw; std::string master_element; + const static std::vector < std::string > vopts; public: }; diff --git a/Temperature.cxx b/Temperature.cxx index 767d1a8a..bc5a5666 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -236,19 +236,6 @@ cxxTemperature::read_raw(CParser & parser) // clear steps for modify operation, if pressures are read bool cleared_once = false; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("temps"); //0 - vopts.push_back("equal_increments"); //1 - vopts.push_back("count_temps"); //2 - } - std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; @@ -420,3 +407,9 @@ Get_countTemps(void) const } return (int) this->temps.size(); } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("temps"), //0 + std::vector< std::string >::value_type("equal_increments"), //1 + std::vector< std::string >::value_type("count_temps") //2 +}; +const std::vector< std::string > cxxTemperature::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/Temperature.h b/Temperature.h index 2d6c0733..f9d546c1 100644 --- a/Temperature.h +++ b/Temperature.h @@ -34,7 +34,7 @@ protected: std::vector < LDBLE >temps; int countTemps; bool equalIncrements; - + const static std::vector < std::string > vopts; }; #endif // !defined(TEMPERATURE_H_INCLUDED) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index feecb581..369fa882 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -187,27 +187,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) { LDBLE d; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - vopts.push_back("step_divide"); - vopts.push_back("rk"); - vopts.push_back("bad_step_max"); - vopts.push_back("use_cvode"); - vopts.push_back("component"); - vopts.push_back("totals"); - vopts.push_back("steps"); - vopts.push_back("cvode_steps"); - vopts.push_back("cvode_order"); - vopts.push_back("equalincrements"); - vopts.push_back("count"); - vopts.push_back("equal_increments"); - } + std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -656,3 +636,18 @@ Current_step(bool incremental_reactions, int reaction_step) const } return kin_time; } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("step_divide"), // 0 + std::vector< std::string >::value_type("rk"), // 1 + std::vector< std::string >::value_type("bad_step_max"), // 2 + std::vector< std::string >::value_type("use_cvode"), // 3 + std::vector< std::string >::value_type("component"), // 4 + std::vector< std::string >::value_type("totals"), // 5 + std::vector< std::string >::value_type("steps"), // 6 + std::vector< std::string >::value_type("cvode_steps"), // 7 + std::vector< std::string >::value_type("cvode_order"), // 8 + std::vector< std::string >::value_type("equalincrements"), // 9 + std::vector< std::string >::value_type("count"), // 10 + std::vector< std::string >::value_type("equal_increments") // 11 +}; +const std::vector< std::string > cxxKinetics::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/cxxKinetics.h b/cxxKinetics.h index ce4d8c3d..bf02091c 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -74,6 +74,7 @@ class cxxKinetics:public cxxNumKeyword int cvode_order; // internal variables cxxNameDouble totals; + const static std::vector < std::string > vopts; }; #endif // !defined(CXXKINETICS_H_INCLUDED) diff --git a/cxxMix.cxx b/cxxMix.cxx index d62c1852..404f1f6d 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -95,15 +95,6 @@ cxxMix::read_raw(CParser & parser) int i; LDBLE d; -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(15); - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -186,4 +177,5 @@ void cxxMix::Vectorize(std::vector &n, std::vector &f) n.push_back(it->first); f.push_back(it->second); } -} \ No newline at end of file +} +const std::vector< std::string > cxxMix::vopts; \ No newline at end of file diff --git a/cxxMix.h b/cxxMix.h index 97871bc7..6d27a2fd 100644 --- a/cxxMix.h +++ b/cxxMix.h @@ -51,6 +51,7 @@ class cxxMix:public cxxNumKeyword protected: friend class cxxStorageBin; std::map < int, LDBLE >mixComps; + const static std::vector < std::string > vopts; }; diff --git a/dumper.cpp b/dumper.cpp index d723a5c3..2d708e43 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -33,43 +33,6 @@ void dumper::SetAll(bool tf) bool dumper::Read(CParser & parser) { bool return_value(true); -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(20); - vopts.push_back("file"); // 0 - vopts.push_back("append"); // 1 - vopts.push_back("all"); // 2 - vopts.push_back("cell"); // 3 - vopts.push_back("cells"); // 4 - vopts.push_back("solution"); // 5 - vopts.push_back("solutions"); // 6 - vopts.push_back("pp_assemblage"); - vopts.push_back("pp_assemblages"); - vopts.push_back("equilibrium_phase"); - vopts.push_back("equilibrium_phases"); // 10 - vopts.push_back("exchange"); - vopts.push_back("surface"); - vopts.push_back("ss_assemblage"); - vopts.push_back("solid_solution"); - vopts.push_back("solid_solutions"); // 15 - vopts.push_back("gas_phase"); - vopts.push_back("gas_phases"); - vopts.push_back("kinetics"); // 18 - vopts.push_back("mix"); // 19 - vopts.push_back("reaction"); // 20 - vopts.push_back("reactions"); // 21 - vopts.push_back("temperature"); // 22 - vopts.push_back("reaction_temperature"); // 23 - vopts.push_back("reaction_temperatures"); // 24 - vopts.push_back("pressure"); // 25 - vopts.push_back("reaction_pressure"); // 26 - vopts.push_back("reaction_pressures"); // 27 - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -275,3 +238,34 @@ bool dumper::Get_bool_any(void) Get_bool_pressure() ); } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("file"), // 0 + std::vector< std::string >::value_type("append"), // 1 + std::vector< std::string >::value_type("all"), // 2 + std::vector< std::string >::value_type("cell"), // 3 + std::vector< std::string >::value_type("cells"), // 4 + std::vector< std::string >::value_type("solution"), // 5 + std::vector< std::string >::value_type("solutions"), // 6 + std::vector< std::string >::value_type("pp_assemblage"), // 7 + std::vector< std::string >::value_type("pp_assemblages"), // 8 + std::vector< std::string >::value_type("equilibrium_phase"), // 9 + std::vector< std::string >::value_type("equilibrium_phases"), // 10 + std::vector< std::string >::value_type("exchange"), // 11 + std::vector< std::string >::value_type("surface"), // 12 + std::vector< std::string >::value_type("ss_assemblage"), // 13 + std::vector< std::string >::value_type("solid_solution"), // 14 + std::vector< std::string >::value_type("solid_solutions"), // 15 + std::vector< std::string >::value_type("gas_phase"), // 16 + std::vector< std::string >::value_type("gas_phases"), // 17 + std::vector< std::string >::value_type("kinetics"), // 18 + std::vector< std::string >::value_type("mix"), // 19 + std::vector< std::string >::value_type("reaction"), // 20 + std::vector< std::string >::value_type("reactions"), // 21 + std::vector< std::string >::value_type("temperature"), // 22 + std::vector< std::string >::value_type("reaction_temperature"), // 23 + std::vector< std::string >::value_type("reaction_temperatures"), // 24 + std::vector< std::string >::value_type("pressure"), // 25 + std::vector< std::string >::value_type("reaction_pressure"), // 26 + std::vector< std::string >::value_type("reaction_pressures") // 27 +}; +const std::vector< std::string > dumper::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/dumper.h b/dumper.h index 832e7bd5..063af4e0 100644 --- a/dumper.h +++ b/dumper.h @@ -49,6 +49,7 @@ protected: bool append; bool on; StorageBinList binList; + const static std::vector < std::string > vopts; }; #endif // !defined(DUMPER_H_INCLUDED) diff --git a/runner.cpp b/runner.cpp index e1c3319c..ddbb124b 100644 --- a/runner.cpp +++ b/runner.cpp @@ -28,22 +28,6 @@ bool runner::Read(CParser & parser) { bool return_value(true); -#if defined(NO_STATIC_VOPTS) - std::vector < std::string > vopts; -#else - static std::vector < std::string > vopts; -#endif - if (vopts.empty()) - { - vopts.reserve(20); - vopts.push_back("cell"); - vopts.push_back("cells"); - vopts.push_back("start_time"); - vopts.push_back("time_step"); - vopts.push_back("time_steps"); - vopts.push_back("step"); - vopts.push_back("steps"); - } std::istream::pos_type ptr; std::istream::pos_type next_char; @@ -155,3 +139,13 @@ bool runner::Read(CParser & parser) } return(return_value); } +const std::vector< std::string >::value_type temp_vopts[] = { + std::vector< std::string >::value_type("cell"), // 0 + std::vector< std::string >::value_type("cells"), // 1 + std::vector< std::string >::value_type("start_time"), // 2 + std::vector< std::string >::value_type("time_step"), // 3 + std::vector< std::string >::value_type("time_steps"), // 4 + std::vector< std::string >::value_type("step"), // 5 + std::vector< std::string >::value_type("steps") // 6 +}; +const std::vector< std::string > runner::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/runner.h b/runner.h index 5cc2e61b..86049879 100644 --- a/runner.h +++ b/runner.h @@ -26,5 +26,6 @@ protected: LDBLE start_time; StorageBinListItem cells; bool run_cells; + const static std::vector < std::string > vopts; }; #endif // !defined(RUNNER_H_INCLUDED) From ad3e78e2f591eb9b0e1ea853216896b2317b059a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 18 Jul 2012 19:15:04 +0000 Subject: [PATCH 0536/1077] Added Basic functions GFW and SOLN_VOL. Added test case gfw in mytest and added to Makefile git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6796 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 23 +++++++++++++++++++++-- PBasic.h | 4 +++- Phreeqc.h | 3 ++- phreeqc/basicsubs.cpp | 31 +++++++++++++++++++++++++++++++ phreeqc/print.cpp | 2 ++ 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 59137bbe..a36e06ba 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1522,7 +1522,13 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("QBrn"); // Q_Born, d(eps_r)/d(P)/(eps_r^2) break; case tokkappa: - output_msg("kappa"); // compressibility of pure water, d(rho)/d(P) / rho + output_msg("KAPPA"); // compressibility of pure water, d(rho)/d(P) / rho + break; + case tokgfw: + output_msg("GFW"); // gram formula weight of a formula + break; + case toksoln_vol: + output_msg("SOLN_VOL"); // volume of solution break; } l_buf = l_buf->next; @@ -3099,6 +3105,17 @@ factor(struct LOC_exec * LINK) case tokkappa: n.UU.val = PhreeqcPtr->kappa_0; break; + case tokgfw: + { + const char * str = stringfactor(STR1, LINK); + LDBLE gfw; + PhreeqcPtr->compute_gfw(str, &gfw); + n.UU.val = (parse_all) ? 1 : gfw; + } + break; + case toksoln_vol: + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_solution_volume(); + break; case toklog10: n.UU.val = log10(realfactor(LINK)); break; @@ -6407,7 +6424,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("dh_b", PBasic::tokdh_b), std::map::value_type("dh_av", PBasic::tokdh_av), std::map::value_type("qbrn", PBasic::tokqbrn), - std::map::value_type("kappa", PBasic::tokkappa) + std::map::value_type("kappa", PBasic::tokkappa), + std::map::value_type("gfw", PBasic::tokgfw), + std::map::value_type("soln_vol", PBasic::toksoln_vol) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 3a295f93..f25f6aed 100644 --- a/PBasic.h +++ b/PBasic.h @@ -308,7 +308,9 @@ public: tokdh_b, tokdh_av, tokqbrn, - tokkappa + tokkappa, + tokgfw, + toksoln_vol }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 74a960dc..b999534f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -140,6 +140,8 @@ public: static LDBLE f_rho(LDBLE rho_old, void *cookie); static LDBLE f_Vm(LDBLE v1, void *cookie); + LDBLE calc_solution_volume(void); + // chart.cpp #if defined PHREEQ98 void DeleteCurves(void); @@ -1651,7 +1653,6 @@ protected: LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume #endif LDBLE solution_mass, solution_volume; - LDBLE f_rho(LDBLE rho_old); /* phqalloc.cpp ------------------------------- */ PHRQMemHeader *s_pTail; diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 21506cea..0db46c5f 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -395,6 +395,37 @@ f_rho(LDBLE rho_old, void *cookie) return (rho - rho_old); } #endif +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_solution_volume(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates solution volume based on sum of mass of element plus density + */ + LDBLE total_mass = 0; + LDBLE gfw; + compute_gfw("H", &gfw); + total_mass = total_h_x * gfw; + compute_gfw("O", &gfw); + total_mass += total_o_x * gfw; + + for (int i = 0; i < count_master; i++) + { + if (master[i]->s->type != AQ) continue; + struct master *master_ptr = master[i]; + if (master_ptr->primary == TRUE) + { + total_mass += master_ptr->total_primary * master_ptr->gfw; + //if (master_ptr->total_primary > 0) + // std::cerr << master_ptr->elt->name << " " << master_ptr->total_primary << "\n"; + } + } + LDBLE rho = calc_dens(); + LDBLE vol = 1e-3 * total_mass / rho; + return (vol); + +} /* DP: End function for interval halving */ /* ---------------------------------------------------------------------- */ diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 02381f13..6fb898a0 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -2086,6 +2086,8 @@ print_totals(void) (double) dens)); if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program's limit)")); else output_msg(sformatf("\n")); + output_msg(sformatf("%45s%9.5f\n", " Volume (L) = ", + (double) calc_solution_volume())); } /* VP: Density End */ output_msg(sformatf("%45s%7.3f\n", "Activity of water = ", From aa903967fe067d4e7e2b311c2b8e7ee1c5012cfe Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 20 Jul 2012 15:35:45 +0000 Subject: [PATCH 0537/1077] bug in totmol(water) removed -selected_output in SELECTED_OUTPUT bug in read_selected_output with opt_save. Went through all opt_save's. Need to check if my changes (adding opt_save = opt_default before loop causes any problems. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6802 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/basicsubs.cpp | 2 +- phreeqc/read.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 0db46c5f..845cb412 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -2241,7 +2241,7 @@ total_mole(const char *total_name) { if (strcmp_nocase(total_name, "water") == 0) { - return (mass_water_aq_x / gfw_water * 1000.); + return (mass_water_aq_x / gfw_water); } else if (strcmp_nocase(total_name, "charge") == 0) { diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 52d091d7..78baf669 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -384,7 +384,7 @@ read_exchange_species(void) "add_constant", /* 18 */ "vm" /* 19, molar volume, must replace delta_v */ }; - int count_opt_list = 18; + int count_opt_list = 20; association = TRUE; s_ptr = NULL; @@ -400,6 +400,7 @@ read_exchange_species(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -1563,9 +1564,11 @@ read_inverse(void) break; case 20: /* mineral_water */ inverse[n].mineral_water = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 22: /* multiple_precision */ inverse[n].mp = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 23: /* mp_tolerance */ j = sscanf(next_char, SCANFORMAT, &inv_tol); @@ -1573,6 +1576,7 @@ read_inverse(void) { inverse[n].mp_tolerance = fabs(inv_tol); } + opt_save = OPTION_ERROR; break; case 24: /* censor_mp */ j = sscanf(next_char, SCANFORMAT, &inv_tol); @@ -1580,6 +1584,7 @@ read_inverse(void) { inverse[n].mp_censor = fabs(inv_tol); } + opt_save = OPTION_ERROR; break; case 25: /* lon_netpath */ /*copy_token(file_name, &next_char, &l); */ @@ -3647,6 +3652,7 @@ read_phases(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -3972,6 +3978,7 @@ read_pp_assemblage(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -4730,6 +4737,7 @@ read_selected_output(void) case 12: /* inverse */ case 16: /* inverse_modeling */ punch.inverse = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 13: /* kinetic_reactants */ case 14: /* kinetics */ @@ -4825,52 +4833,66 @@ read_selected_output(void) punch.water = value; punch.charge_balance = value; punch.percent_error = value; + opt_save = OPTION_ERROR; break; case 18: /* simulation */ case 19: /* sim */ punch.sim = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 20: /* state */ punch.state = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 21: /* solution */ case 22: /* soln */ punch.soln = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 23: /* distance */ case 24: /* dist */ punch.dist = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 25: /* time */ punch.time = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 26: /* step */ punch.step = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 27: /* reaction */ case 28: /* rxn */ punch.rxn = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 29: /* temperature */ case 30: /* temp */ punch.temp = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 31: /* ph */ punch.ph = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 32: /* pe */ punch.pe = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 33: /* alkalinity */ case 34: /* alk */ punch.alk = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 35: /* ionic strength */ case 36: /* mu */ punch.mu = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 37: /* water */ punch.water = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 38: /* high_precision */ punch.high_precision = get_true_false(next_char, TRUE); @@ -4878,19 +4900,25 @@ read_selected_output(void) { convergence_tolerance = 1e-12; } + opt_save = OPTION_ERROR; break; case 39: /* user_punch */ punch.user_punch = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 42: /* charge_balance */ punch.charge_balance = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 43: /* percent_error */ punch.percent_error = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; case 44: /* selected_out */ case 45: /* selected_output */ - pr.punch = get_true_false(next_char, TRUE); + warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); + //pr.punch = get_true_false(next_char, TRUE); + opt_save = OPTION_ERROR; break; } if (return_value == EOF || return_value == KEYWORD) @@ -5295,6 +5323,7 @@ read_species(void) opt = opt_save; //vm_read = false; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -6038,6 +6067,7 @@ read_surface_species(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -7039,6 +7069,7 @@ read_surface_master_species(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -7352,6 +7383,7 @@ read_advection(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -8455,6 +8487,7 @@ read_rates(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -8574,6 +8607,7 @@ read_user_print(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -8670,6 +8704,7 @@ read_user_punch(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ @@ -9947,6 +9982,7 @@ read_named_logk(void) { opt = opt_save; } + opt_save = OPTION_DEFAULT; switch (opt) { case OPTION_EOF: /* end of file */ From e20fd6af4dfaeb52169b6e66585d4971e1418d37 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 21 Jul 2012 02:26:06 +0000 Subject: [PATCH 0538/1077] modified to use auto_ptr for early termination memory cleanup git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6805 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/kinetics.cpp | 54 ++++++++------------------------------------ 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 83c6b252..7a75d275 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -18,6 +18,7 @@ #include "cxxKinetics.h" #include #include +#include #include "nvector_serial.h" /* definitions of type N_Vector and macro */ /* NV_Ith_S, prototypes for N_VNew, N_VFree */ /* These macros are defined in order to write code which exactly matches @@ -1109,9 +1110,9 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; - cxxPPassemblage *pp_assemblage_save = NULL; - cxxSSassemblage *ss_assemblage_save = NULL; - cxxKinetics *kinetics_save = NULL; + std::auto_ptr pp_assemblage_save(NULL); + std::auto_ptr ss_assemblage_save(NULL); + std::auto_ptr kinetics_save(NULL); small_pe_step = 5.; @@ -1141,26 +1142,16 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, if (use.Get_pp_assemblage_ptr() != NULL) { cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); - if (pp_assemblage_save) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + pp_assemblage_save.reset(new cxxPPassemblage(*pp_assemblage_ptr)); } if (use.Get_ss_assemblage_ptr() != NULL) { cxxSSassemblage * ss_assemblage_ptr = use.Get_ss_assemblage_ptr(); - if (ss_assemblage_save) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } - ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + ss_assemblage_save.reset(new cxxSSassemblage(*ss_assemblage_ptr)); } if (use.Get_kinetics_ptr() != NULL) { - kinetics_save = new cxxKinetics(*use.Get_kinetics_ptr()); + kinetics_save.reset(new cxxKinetics(*use.Get_kinetics_ptr())); } if (pitzer_model == TRUE || sit_model == TRUE) @@ -1309,17 +1300,17 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } if (j > 0) { - if (pp_assemblage_save != NULL) + if (pp_assemblage_save.get() != NULL) { Rxn_pp_assemblage_map[pp_assemblage_save->Get_n_user()] = *pp_assemblage_save; use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, pp_assemblage_save->Get_n_user())); } - if (ss_assemblage_save != NULL) + if (ss_assemblage_save.get() != NULL) { Rxn_ss_assemblage_map[ss_assemblage_save->Get_n_user()] = *ss_assemblage_save; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, ss_assemblage_save->Get_n_user())); } - if (kinetics_save != NULL) + if (kinetics_save.get() != NULL) { Rxn_kinetics_map[kinetics_save->Get_n_user()] = *kinetics_save; use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, kinetics_save->Get_n_user())); @@ -1386,35 +1377,10 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, pr.use = TRUE; sum_species(); print_all(); - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } error_string = sformatf( "Numerical method failed on all combinations of convergence parameters"); error_msg(error_string, STOP); } - if (pp_assemblage_save != NULL) - { - delete pp_assemblage_save; - pp_assemblage_save = NULL; - } - if (ss_assemblage_save != NULL) - { - delete ss_assemblage_save; - ss_assemblage_save = NULL; - } - if (kinetics_save != NULL) - { - delete kinetics_save; - kinetics_save = NULL; - } if (converge == MASS_BALANCE) { return (MASS_BALANCE); From 06cc39e84d9f10a60fdcb0f202acd3c257cfc6f2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Jul 2012 16:51:26 +0000 Subject: [PATCH 0539/1077] Added new keywords to mix SOLUTION, EXCHANGE, GAS_PHASE, KINETICS, EQUILIBRIUM_PHASES, SOLID_SOLUTIONS, SURFACE Replaced can not with cannot. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6811 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 6 +-- GasPhase.cxx | 4 +- Keywords.cpp | 19 ++++++- Keywords.h | 6 +++ PPassemblageComp.cxx | 2 +- Phreeqc.h | 23 ++++++++- SurfaceComp.cxx | 6 +-- phreeqc/basicsubs.cpp | 4 +- phreeqc/inverse.cpp | 2 +- phreeqc/isotopes.cpp | 2 +- phreeqc/mainsubs.cpp | 11 ++++- phreeqc/prep.cpp | 6 +-- phreeqc/read.cpp | 112 ++++++++++++++++++++++++++++++++++++++++-- phreeqc/tidy.cpp | 4 +- phreeqc/transport.cpp | 8 +-- 15 files changed, 183 insertions(+), 32 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index a1262519..33ded036 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -363,7 +363,7 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix two exchange components with same formula and different related phases, " + "Cannot mix two exchange components with same formula and different related phases, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; @@ -377,7 +377,7 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix two exchange components with same formula and different related kinetics, " + "Cannot mix two exchange components with same formula and different related kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; @@ -392,7 +392,7 @@ cxxExchComp::add(const cxxExchComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix exchange components related to phase with exchange components related to kinetics, " + "Cannot mix exchange components related to phase with exchange components related to kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; diff --git a/GasPhase.cxx b/GasPhase.cxx index 5774651a..c4af6d8d 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -78,7 +78,7 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, if (this->type != entity_ptr->type) { std::ostringstream oss; - oss << "Can not mix two gas_phases with differing types."; + oss << "Cannot mix two gas_phases with differing types."; error_msg(oss.str().c_str(), CONTINUE); return; } @@ -160,7 +160,7 @@ cxxNumKeyword(io) if (this->type != entity_ptr->type) { std::ostringstream oss; - oss << "Can not mix two gas_phases with differing types."; + oss << "Cannot mix two gas_phases with differing types."; error_msg(oss.str().c_str(), CONTINUE); //input_error++; return; diff --git a/Keywords.cpp b/Keywords.cpp index 9ea46303..8eb4a2d2 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -198,6 +198,23 @@ std::map::value_type(Keywords::KEY_REACTI std::map::value_type(Keywords::KEY_REACTION_PRESSURE, "REACTION_PRESSURE"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY"), -std::map::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX") +std::map::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX"), +std::map::value_type(Keywords::KEY_SOLUTION_MIX, "MIX_SOLUTION"), +std::map::value_type(Keywords::KEY_EXCHANGE_MIX, "EXCHANGE_MIX"), +std::map::value_type(Keywords::KEY_EXCHANGE_MIX, "MIX_EXCHANGE"), +std::map::value_type(Keywords::KEY_GAS_PHASE_MIX, "GAS_PHASE_MIX"), +std::map::value_type(Keywords::KEY_GAS_PHASE_MIX, "MIX_GAS_PHASE"), +std::map::value_type(Keywords::KEY_KINETICS_MIX, "KINETICS_MIX"), +std::map::value_type(Keywords::KEY_KINETICS_MIX, "MIX_KINETICS"), +std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASES_MIX"), +std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "MIX_EQUILIBRIUM_PHASES"), +std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASE_MIX"), +std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "MIX_EQUILIBRIUM_PHASE"), +std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "SOLID_SOLUTION_MIX"), +std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "MIX_SOLID_SOLUTION"), +std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "SOLID_SOLUTIONS_MIX"), +std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "MIX_SOLID_SOLUTIONS"), +std::map::value_type(Keywords::KEY_SURFACE_MIX, "SURFACE_MIX"), +std::map::value_type(Keywords::KEY_SURFACE_MIX, "MIX_SURFACE") }; const std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); diff --git a/Keywords.h b/Keywords.h index 613a4173..7c5e3740 100644 --- a/Keywords.h +++ b/Keywords.h @@ -77,6 +77,12 @@ public: KEY_REACTION_PRESSURE_RAW, KEY_REACTION_PRESSURE_MODIFY, KEY_SOLUTION_MIX, + KEY_EXCHANGE_MIX, + KEY_GAS_PHASE_MIX, + KEY_KINETICS_MIX, + KEY_PPASSEMBLAGE_MIX, + KEY_SSASSEMBLAGE_MIX, + KEY_SURFACE_MIX, KEY_COUNT_KEYWORDS // must be last in list }; diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 5dc30aec..35e22ecf 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -408,7 +408,7 @@ cxxPPassemblageComp::add(const cxxPPassemblageComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix two Equilibrium_phases with differing add_formulae., " + "Cannot mix two Equilibrium_phases with differing add_formulae., " << this->name; error_msg(oss.str().c_str(), CONTINUE); return; diff --git a/Phreeqc.h b/Phreeqc.h index b999534f..38f2e40f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -690,7 +690,8 @@ public: int *read_list_t_f(char **ptr, int *count_ints); int read_master_species(void); int read_mix(void); - int read_solution_mix(void); + int read_entity_mix(std::map &mix_map); + //int read_solution_mix(void); int read_named_logk(void); int read_phases(void); int read_print(void); @@ -1197,7 +1198,12 @@ protected: std::map Rxn_mix_map; std::map Dispersion_mix_map; std::map Rxn_solution_mix_map; - + std::map Rxn_exchange_mix_map; + std::map Rxn_gas_phase_mix_map; + std::map Rxn_kinetics_mix_map; + std::map Rxn_pp_assemblage_mix_map; + std::map Rxn_ss_assemblage_mix_map; + std::map Rxn_surface_mix_map; /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ @@ -2018,6 +2024,19 @@ namespace Utilities return phreeqc_cookie->cleanup_after_parser(parser); } + template < typename T > + void Rxn_mix(std::map &mix_map, std::map < int, T > &entity_map, Phreeqc * phreeqc_cookie) + { + std::map::iterator mix_it; + for (mix_it = mix_map.begin(); mix_it != mix_map.end(); mix_it++) + { + T entity(entity_map, mix_it->second, mix_it->second.Get_n_user(), phreeqc_cookie->Get_phrq_io()); + entity_map[mix_it->second.Get_n_user()] = entity; + Utilities::Rxn_copies(entity_map, mix_it->second.Get_n_user(), mix_it->second.Get_n_user_end()); + } + mix_map.clear(); + } + } // namespace Utilities diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 8dfefb3a..86ba5731 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -439,7 +439,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix two Surface components with same formula and different related phases, " + "Cannot mix two Surface components with same formula and different related phases, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; @@ -454,7 +454,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix two exchange components with same formula and different related kinetics, " + "Cannot mix two exchange components with same formula and different related kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; @@ -470,7 +470,7 @@ cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) { std::ostringstream oss; oss << - "Can not mix exchange components related to phase with exchange components related to kinetics, " + "Cannot mix exchange components related to phase with exchange components related to kinetics, " << this->formula; error_msg(oss.str().c_str(), CONTINUE); return; diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 845cb412..552b2afb 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -2178,7 +2178,7 @@ total(const char *total_name) return (cb_x / mass_water_aq_x); } /* - sprintf (error_string, "Can not find definition for master species, %s.", + sprintf (error_string, "Cannot find definition for master species, %s.", total_name); warning_msg (error_string); */ @@ -2248,7 +2248,7 @@ total_mole(const char *total_name) return (cb_x); } /* - sprintf (error_string, "Can not find definition for master species, %s.", + sprintf (error_string, "Cannot find definition for master species, %s.", total_name); warning_msg (error_string); */ diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index 5b2b1114..01c1b19f 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -1381,7 +1381,7 @@ minimal_solve(struct inverse *inv_ptr, unsigned long minimal_bits) } /* - * minimal_bits can not be superset of a minimal model, but + * minimal_bits cannot be superset of a minimal model, but * could be subset of one of the sets of minerals with no feasible solution * If it is a subset, then replace mineral and go on to next */ diff --git a/phreeqc/isotopes.cpp b/phreeqc/isotopes.cpp index 307269ad..05cfc83d 100644 --- a/phreeqc/isotopes.cpp +++ b/phreeqc/isotopes.cpp @@ -529,7 +529,7 @@ calculate_isotope_moles(struct element *elt_ptr, if (total_moles <= 0) { error_string = sformatf( - "Can not calculate molality of isotopes, molality of element is zero, %s", + "Cannot calculate molality of isotopes, molality of element is zero, %s", elt_ptr->name); warning_msg(error_string); return (ERROR); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 68f6439e..9394cb32 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2647,8 +2647,15 @@ run_simulations(void) /* * Calculate mixed solutions */ - if (Rxn_solution_mix_map.size() > 0) - solution_mix(); + //if (Rxn_solution_mix_map.size() > 0) + // solution_mix(); + Utilities::Rxn_mix(Rxn_solution_mix_map, Rxn_solution_map, this); + Utilities::Rxn_mix(Rxn_exchange_mix_map, Rxn_exchange_map, this); + Utilities::Rxn_mix(Rxn_gas_phase_mix_map, Rxn_gas_phase_map, this); + Utilities::Rxn_mix(Rxn_kinetics_mix_map, Rxn_kinetics_map, this); + Utilities::Rxn_mix(Rxn_pp_assemblage_mix_map, Rxn_pp_assemblage_map, this); + Utilities::Rxn_mix(Rxn_ss_assemblage_mix_map, Rxn_ss_assemblage_map, this); + Utilities::Rxn_mix(Rxn_surface_mix_map, Rxn_surface_map, this); /* * Calculate distribution for exchangers */ diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 5fe37849..d263a283 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -3869,7 +3869,7 @@ setup_master_rxn(struct master **master_ptr_list, const std::string &pe_rxn) if (master_ptr->s == s_h2o) { error_string = sformatf( - "Can not enter concentration data for O(-2),\n\tdissolved oxygen is O(0),\n\tfor mass of water, use -water identifier."); + "Cannot enter concentration data for O(-2),\n\tdissolved oxygen is O(0),\n\tfor mass of water, use -water identifier."); error_msg(error_string, CONTINUE); input_error++; continue; @@ -4649,7 +4649,7 @@ setup_solution(void) (ph_unknown == charge_balance_unknown) && (alkalinity_unknown != NULL)) { - error_msg("pH adustment can not attain charge balance" + error_msg("pH adustment cannot attain charge balance" " when alkalinity is fixed.", CONTINUE); input_error++; } @@ -4657,7 +4657,7 @@ setup_solution(void) (alkalinity_unknown->type == CB || alkalinity_unknown->type == SOLUTION_PHASE_BOUNDARY)) { - error_msg("Alkalinity can not be used with charge balance" + error_msg("Alkalinity cannot be used with charge balance" " or solution phase boundary constraints.", CONTINUE); input_error++; } diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 78baf669..aebf139b 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -113,7 +113,26 @@ read_input(void) read_mix(); break; case Keywords::KEY_SOLUTION_MIX: - read_solution_mix(); + //read_solution_mix(); + read_entity_mix(Rxn_solution_mix_map); + break; + case Keywords::KEY_EXCHANGE_MIX: + read_entity_mix(Rxn_exchange_mix_map); + break; + case Keywords::KEY_GAS_PHASE_MIX: + read_entity_mix(Rxn_gas_phase_mix_map); + break; + case Keywords::KEY_KINETICS_MIX: + read_entity_mix(Rxn_kinetics_mix_map); + break; + case Keywords::KEY_PPASSEMBLAGE_MIX: + read_entity_mix(Rxn_pp_assemblage_mix_map); + break; + case Keywords::KEY_SSASSEMBLAGE_MIX: + read_entity_mix(Rxn_ss_assemblage_mix_map); + break; + case Keywords::KEY_SURFACE_MIX: + read_entity_mix(Rxn_surface_mix_map); break; case Keywords::KEY_USE: read_use(); @@ -2455,7 +2474,7 @@ read_list_doubles(char **ptr, int *count_doubles) { /* * Reads a list of LDBLE numbers until end of line is reached or - * a LDBLE can not be read from a token. + * a LDBLE cannot be read from a token. * * Arguments: * ptr entry: points to line to read from @@ -2509,7 +2528,7 @@ read_list_ints(char **ptr, int *count_ints, int positive) { /* * Reads a list of int numbers until end of line is reached or - * an int can not be read from a token. + * an int cannot be read from a token. * * Arguments: * ptr entry: points to line to read from @@ -2569,7 +2588,7 @@ read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list) { /* * Reads a list of int numbers until end of line is reached or - * an int can not be read from a token. + * an int cannot be read from a token. * * Arguments: * ptr entry: points to line to read from @@ -3421,6 +3440,89 @@ read_mix(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +read_entity_mix(std::map &mix_map) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads mixing fractions + */ + int n_user, n_user_end; + int return_value; + int n_solution; + LDBLE fraction; + int j, i, l; + char *ptr; + char token[MAX_LENGTH]; + char *description; + cxxMix temp_mix; + +/* + * Read mix number + */ + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + temp_mix.Set_n_user(n_user); + temp_mix.Set_n_user_end(n_user_end); + temp_mix.Set_description(description); + free_check_null(description); +/* + * Read mixture data + */ + for (;;) + { + return_value = check_line("Mix raw data", FALSE, TRUE, TRUE, TRUE); + /* empty, eof, keyword, print */ + if (return_value == EOF || return_value == KEYWORD) + { + break; + } + ptr = line; +/* + * Read n_user + */ + i = copy_token(token, &ptr, &l); + if (i == DIGIT) + { + sscanf(token, "%d ", &n_solution); + } + else + { + input_error++; + error_msg("Expected a number in mix input.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Read fraction for entity + */ + copy_token(token, &ptr, &l); + j = sscanf(token, SCANFORMAT, &fraction); + if (j != 1) + { + input_error++; + error_msg("Expected a mixing fraction.", CONTINUE); + error_msg(line_save, CONTINUE); + continue; + } +/* + * Save data + */ + temp_mix.Add(n_solution ,fraction); + } + if (temp_mix.Get_mixComps().size() == 0) + { + input_error++; + error_msg + ("Must define at least one number and mixing fraction for mix input.", + CONTINUE); + } + mix_map[n_user] = temp_mix; + return (return_value); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: read_solution_mix(void) /* ---------------------------------------------------------------------- */ { @@ -3523,7 +3625,7 @@ read_solution_mix(void) #endif return (return_value); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_number_description(char *ptr, int *n_user, diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 2c53982b..b9eec35b 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -360,7 +360,7 @@ tidy_model(void) else if (s_hplus != NULL && s_h3oplus != NULL) { input_error++; - error_msg("Can not define both H+ and H3O+ in solution_species.", + error_msg("Cannot define both H+ and H3O+ in solution_species.", STOP); } if (s_hplus->primary == NULL) @@ -925,7 +925,7 @@ tidy_gas_phase(void) { input_error++; error_string = sformatf( - "Gas phase %d: can not use '-equilibrium' option with fixed pressure gas phase.", + "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", gas_phase_ptr->Get_n_user()); error_msg(error_string, CONTINUE); } diff --git a/phreeqc/transport.cpp b/phreeqc/transport.cpp index b1b01023..7fdac262 100644 --- a/phreeqc/transport.cpp +++ b/phreeqc/transport.cpp @@ -3391,7 +3391,7 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_type() != surface_ptr2->Get_type()) { error_string = sformatf( - "Surfaces %d and %d differ in use of electrical double layer. Can not mix.", + "Surfaces %d and %d differ in use of electrical double layer. Cannot mix.", n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; @@ -3400,7 +3400,7 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_only_counter_ions() != surface_ptr2->Get_only_counter_ions()) { error_string = sformatf( - "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Can not mix.", + "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Cannot mix.", n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; @@ -3409,7 +3409,7 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_related_phases() != surface_ptr2->Get_related_phases()) { error_string = sformatf( - "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Can not mix.", + "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Cannot mix.", n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; @@ -3418,7 +3418,7 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_related_rate() != surface_ptr2->Get_related_rate()) { error_string = sformatf( - "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Can not mix.", + "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Cannot mix.", n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; From 601510140f8965d74011e164dfe163448757c38c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Jul 2012 18:19:29 +0000 Subject: [PATCH 0540/1077] Fixed bugs with mixing calculations (keywords not set up right). Added mixes test case. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6812 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Keywords.cpp b/Keywords.cpp index 8eb4a2d2..c17be459 100644 --- a/Keywords.cpp +++ b/Keywords.cpp @@ -123,8 +123,24 @@ std::map::value_type("reaction_pressure", std::map::value_type("reaction_pressures", Keywords::KEY_REACTION_PRESSURE), std::map::value_type("reaction_pressure_raw", Keywords::KEY_REACTION_PRESSURE_RAW), std::map::value_type("reaction_pressure_modify", Keywords::KEY_REACTION_PRESSURE_MODIFY), -std::map::value_type("solution_mix", Keywords::KEY_SOLUTION_MIX) - +std::map::value_type("solution_mix", Keywords::KEY_SOLUTION_MIX), +std::map::value_type("mix_solution", Keywords::KEY_SOLUTION_MIX), +std::map::value_type("exchange_mix", Keywords::KEY_EXCHANGE_MIX), +std::map::value_type("mix_exchange", Keywords::KEY_EXCHANGE_MIX), +std::map::value_type("gas_phase_mix", Keywords::KEY_GAS_PHASE_MIX), +std::map::value_type("mix_gas_phase", Keywords::KEY_GAS_PHASE_MIX), +std::map::value_type("kinetics_mix", Keywords::KEY_KINETICS_MIX), +std::map::value_type("mix_kinetics", Keywords::KEY_KINETICS_MIX), +std::map::value_type("equilibrium_phases_mix", Keywords::KEY_PPASSEMBLAGE_MIX), +std::map::value_type("mix_equilibrium_phases", Keywords::KEY_PPASSEMBLAGE_MIX), +std::map::value_type("equilibrium_phase_mix", Keywords::KEY_PPASSEMBLAGE_MIX), +std::map::value_type("mix_equilibrium_phase", Keywords::KEY_PPASSEMBLAGE_MIX), +std::map::value_type("solid_solutions_mix", Keywords::KEY_SSASSEMBLAGE_MIX), +std::map::value_type("mix_solid_solutions", Keywords::KEY_SSASSEMBLAGE_MIX), +std::map::value_type("solid_solution_mix", Keywords::KEY_SSASSEMBLAGE_MIX), +std::map::value_type("mix_solid_solution", Keywords::KEY_SSASSEMBLAGE_MIX), +std::map::value_type("surface_mix", Keywords::KEY_SURFACE_MIX), +std::map::value_type("mix_surface", Keywords::KEY_SURFACE_MIX) }; const std::map Keywords::phreeqc_keywords(temp_keywords, temp_keywords + sizeof temp_keywords / sizeof temp_keywords[0]); @@ -199,22 +215,11 @@ std::map::value_type(Keywords::KEY_REACTI std::map::value_type(Keywords::KEY_REACTION_PRESSURE_RAW, "REACTION_PRESSURE_RAW"), std::map::value_type(Keywords::KEY_REACTION_PRESSURE_MODIFY, "REACTION_PRESSURE_MODIFY"), std::map::value_type(Keywords::KEY_SOLUTION_MIX, "SOLUTION_MIX"), -std::map::value_type(Keywords::KEY_SOLUTION_MIX, "MIX_SOLUTION"), std::map::value_type(Keywords::KEY_EXCHANGE_MIX, "EXCHANGE_MIX"), -std::map::value_type(Keywords::KEY_EXCHANGE_MIX, "MIX_EXCHANGE"), std::map::value_type(Keywords::KEY_GAS_PHASE_MIX, "GAS_PHASE_MIX"), -std::map::value_type(Keywords::KEY_GAS_PHASE_MIX, "MIX_GAS_PHASE"), std::map::value_type(Keywords::KEY_KINETICS_MIX, "KINETICS_MIX"), -std::map::value_type(Keywords::KEY_KINETICS_MIX, "MIX_KINETICS"), -std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASES_MIX"), -std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "MIX_EQUILIBRIUM_PHASES"), -std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASE_MIX"), -std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "MIX_EQUILIBRIUM_PHASE"), -std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "SOLID_SOLUTION_MIX"), -std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "MIX_SOLID_SOLUTION"), +std::map::value_type(Keywords::KEY_PPASSEMBLAGE_MIX, "EQUILIBRIUM_PHASES_MIX"), std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "SOLID_SOLUTIONS_MIX"), -std::map::value_type(Keywords::KEY_SSASSEMBLAGE_MIX, "MIX_SOLID_SOLUTIONS"), -std::map::value_type(Keywords::KEY_SURFACE_MIX, "SURFACE_MIX"), -std::map::value_type(Keywords::KEY_SURFACE_MIX, "MIX_SURFACE") +std::map::value_type(Keywords::KEY_SURFACE_MIX, "SURFACE_MIX") }; const std::map Keywords::phreeqc_keyword_names(temp_keyword_names, temp_keyword_names + sizeof temp_keyword_names / sizeof temp_keyword_names[0]); From c6c27b033c2ceebe23e8586f3a1a136fa4b242a5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Jul 2012 18:52:15 +0000 Subject: [PATCH 0541/1077] Allow negative numbers on entity mixes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6813 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NumKeyword.cxx | 11 ++++++++++- phreeqc/mainsubs.cpp | 2 ++ phreeqc/read.cpp | 11 ++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/NumKeyword.cxx b/NumKeyword.cxx index 39beab4b..0dae9df6 100644 --- a/NumKeyword.cxx +++ b/NumKeyword.cxx @@ -141,7 +141,16 @@ cxxNumKeyword::read_number_description(const std::string & line_in) // read number if (CParser::copy_token(token, b, e) == CParser::TT_DIGIT) { - Utilities::replace("-", " ", token); + if (token[0] == '-') + { + token = token.substr(1); + Utilities::replace("-", " ", token); + token = "-" + token; + } + else + { + Utilities::replace("-", " ", token); + } int j = sscanf(token.c_str(), "%d%d", &this->n_user, &this->n_user_end); if (j == 0) { diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 9394cb32..f808a9d2 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1033,6 +1033,7 @@ initial_solutions(int print) initial_solution_isotopes = FALSE; return (OK); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: solution_mix() @@ -1051,6 +1052,7 @@ solution_mix() Rxn_solution_mix_map.clear(); return OK; } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: initial_exchangers(int print) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index aebf139b..da80bf04 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -3446,26 +3446,19 @@ read_entity_mix(std::map &mix_map) /* * Reads mixing fractions */ - int n_user, n_user_end; int return_value; int n_solution; LDBLE fraction; int j, i, l; char *ptr; char token[MAX_LENGTH]; - char *description; cxxMix temp_mix; /* * Read mix number */ ptr = line; - read_number_description(ptr, &n_user, &n_user_end, &description); - - temp_mix.Set_n_user(n_user); - temp_mix.Set_n_user_end(n_user_end); - temp_mix.Set_description(description); - free_check_null(description); + temp_mix.read_number_description(line); /* * Read mixture data */ @@ -3517,7 +3510,7 @@ read_entity_mix(std::map &mix_map) ("Must define at least one number and mixing fraction for mix input.", CONTINUE); } - mix_map[n_user] = temp_mix; + mix_map[temp_mix.Get_n_user()] = temp_mix; return (return_value); } #ifdef SKIP From c0463f6f035cf350fc82f28e3a9dab1aff38478c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Jul 2012 22:35:37 +0000 Subject: [PATCH 0542/1077] Does initial conditions, but is really slow. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6814 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + phreeqc/mainsubs.cpp | 28 ++++++++++++++++------------ phreeqc/read.cpp | 38 +++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 38f2e40f..62b65cab 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -393,6 +393,7 @@ public: std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); std::ofstream * open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); int copy_entities(void); + void do_mixes(void); void initialize(void); int initial_exchangers(int print); int initial_gas_phases(int print); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index f808a9d2..2ef860d7 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2646,18 +2646,6 @@ run_simulations(void) */ if (new_solution) initial_solutions(TRUE); -/* - * Calculate mixed solutions - */ - //if (Rxn_solution_mix_map.size() > 0) - // solution_mix(); - Utilities::Rxn_mix(Rxn_solution_mix_map, Rxn_solution_map, this); - Utilities::Rxn_mix(Rxn_exchange_mix_map, Rxn_exchange_map, this); - Utilities::Rxn_mix(Rxn_gas_phase_mix_map, Rxn_gas_phase_map, this); - Utilities::Rxn_mix(Rxn_kinetics_mix_map, Rxn_kinetics_map, this); - Utilities::Rxn_mix(Rxn_pp_assemblage_mix_map, Rxn_pp_assemblage_map, this); - Utilities::Rxn_mix(Rxn_ss_assemblage_mix_map, Rxn_ss_assemblage_map, this); - Utilities::Rxn_mix(Rxn_surface_mix_map, Rxn_surface_map, this); /* * Calculate distribution for exchangers */ @@ -2701,6 +2689,11 @@ run_simulations(void) * run */ run_as_cells(); +/* + * Calculate mixes + */ + do_mixes(); + /* * Copy */ @@ -2808,3 +2801,14 @@ save_init(int i) save.n_ss_assemblage_user = i; save.n_ss_assemblage_user_end = i; } +void +Phreeqc::do_mixes(void) +{ + Utilities::Rxn_mix(Rxn_solution_mix_map, Rxn_solution_map, this); + Utilities::Rxn_mix(Rxn_exchange_mix_map, Rxn_exchange_map, this); + Utilities::Rxn_mix(Rxn_gas_phase_mix_map, Rxn_gas_phase_map, this); + Utilities::Rxn_mix(Rxn_kinetics_mix_map, Rxn_kinetics_map, this); + Utilities::Rxn_mix(Rxn_pp_assemblage_mix_map, Rxn_pp_assemblage_map, this); + Utilities::Rxn_mix(Rxn_ss_assemblage_mix_map, Rxn_ss_assemblage_map, this); + Utilities::Rxn_mix(Rxn_surface_mix_map, Rxn_surface_map, this); +} \ No newline at end of file diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index da80bf04..f2b7b6ed 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -10328,27 +10328,27 @@ read_copy(void) if (i == DIGIT) { sscanf(token, "%d", &n_user); - if (n_user < 0) - { - error_msg("Source index number must be a positive integer.", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return (ERROR); - } - if (strstr(token, "-") != NULL) - { - error_msg - ("COPY does not accept a range of numbers for source index", - CONTINUE); - error_msg(line_save, CONTINUE); - input_error++; - return (ERROR); - } + //if (n_user < 0) + //{ + // error_msg("Source index number must be a positive integer.", + // CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + // return (ERROR); + //} + //if (strstr(token, "-") != NULL) + //{ + // error_msg + // ("COPY does not accept a range of numbers for source index", + // CONTINUE); + // error_msg(line_save, CONTINUE); + // input_error++; + // return (ERROR); + //} } else { - error_msg("Source index number must be a positive integer.", + error_msg("Source index number must be an integer.", CONTINUE); error_msg(line_save, CONTINUE); input_error++; @@ -10369,7 +10369,7 @@ read_copy(void) } else { - error_msg("Target index number must be a positive integer.", + error_msg("Target index number must be an integer.", CONTINUE); error_msg(line_save, CONTINUE); input_error++; From 1f52826bafd18c2148a6285e680552028e25f3d4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 25 Jul 2012 20:45:01 +0000 Subject: [PATCH 0543/1077] Have initial conditions working. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6817 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 6 +++--- PPassemblage.cxx | 4 ++-- phreeqc/tidy.cpp | 43 +++++++++++++++++++++++-------------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 5eea0aaf..e3e1327c 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -169,7 +169,7 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1 << "# EXCHANGE_MODIFY candidate identifiers #\n"; s_oss << indent1; - s_oss << "-exchange_gammas " << this->pitzer_exchange_gammas << "\n"; + s_oss << "-exchange_gammas " << (this->pitzer_exchange_gammas ? 1 : 0) << "\n"; // exchComps for (size_t i = 0; i < this->exchange_comps.size(); i++) { @@ -180,9 +180,9 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1 << "# EXCHANGE_MODIFY candidates with new_def=true #\n"; s_oss << indent1; - s_oss << "-new_def " << this->new_def << "\n"; + s_oss << "-new_def " << 0 << "\n"; s_oss << indent1; - s_oss << "-solution_equilibria " << this->solution_equilibria << "\n"; + s_oss << "-solution_equilibria " << 0 << "\n"; s_oss << indent1; s_oss << "-n_solution " << this->n_solution << "\n"; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 5864cb75..fec0a180 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -105,7 +105,7 @@ cxxPPassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << indent1 << "# EXCHANGE_MODIFY candidates; use new_def=true #\n"; - s_oss << indent1 << "-new_def " << this->new_def << "\n"; + s_oss << indent1 << "-new_def " << 0 << "\n"; for (std::map < std::string, cxxPPassemblageComp >::const_iterator it = pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) { @@ -211,7 +211,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser. error_msg - ("Expected boolean value for new_def.", + ("Expected boolean value for new_def in PPassemblage.", PHRQ_io::OT_CONTINUE); } break; diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index b9eec35b..cfeaeba9 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -60,33 +60,33 @@ tidy_model(void) { new_model = TRUE; } - if (keycount[Keywords::KEY_EQUILIBRIUM_PHASES] > 0 || + if (keycount[Keywords::KEY_EQUILIBRIUM_PHASES] > 0 /*|| keycount[Keywords::KEY_EQUILIBRIUM_PHASES_RAW] > 0 || - keycount[Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY]) + keycount[Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY]*/) { new_pp_assemblage = TRUE; /*"pure_phases" */ } - if (keycount[Keywords::KEY_SURFACE] > 0 || + if (keycount[Keywords::KEY_SURFACE] > 0 /*|| keycount[Keywords::KEY_SURFACE_RAW] > 0 || - keycount[Keywords::KEY_SURFACE_MODIFY]) + keycount[Keywords::KEY_SURFACE_MODIFY]*/) { new_surface = TRUE; /*"surface" */ } - if (keycount[Keywords::KEY_EXCHANGE] > 0 || - keycount[Keywords::KEY_SURFACE_RAW] > 0 || - keycount[Keywords::KEY_SURFACE_MODIFY]) + if (keycount[Keywords::KEY_EXCHANGE] > 0 /*|| + keycount[Keywords::KEY_EXCHANGE_RAW] > 0 || + keycount[Keywords::KEY_EXCHANGE_MODIFY]*/) { new_exchange = TRUE; /*"exchange" */ } - if (keycount[Keywords::KEY_REACTION] > 0 || + if (keycount[Keywords::KEY_REACTION] > 0 /*|| keycount[Keywords::KEY_REACTION_RAW] > 0 || - keycount[Keywords::KEY_REACTION_MODIFY]) + keycount[Keywords::KEY_REACTION_MODIFY]*/) { new_reaction = TRUE; /*"reaction" */ } - if (keycount[Keywords::KEY_REACTION_TEMPERATURE] > 0 || + if (keycount[Keywords::KEY_REACTION_TEMPERATURE] > 0 /*|| keycount[Keywords::KEY_REACTION_TEMPERATURE_RAW] > 0 || - keycount[Keywords::KEY_REACTION_TEMPERATURE_MODIFY]) + keycount[Keywords::KEY_REACTION_TEMPERATURE_MODIFY]*/) { new_temperature = TRUE; /*"reacton_temperature" */ } @@ -96,27 +96,27 @@ tidy_model(void) new_mix = TRUE; /*"mix" */ } if (keycount[Keywords::KEY_SOLUTION] > 0 || - keycount[Keywords::KEY_SOLUTION_SPREAD] > 0 || + keycount[Keywords::KEY_SOLUTION_SPREAD] > 0 /*|| keycount[Keywords::KEY_SOLUTION_RAW] > 0 || - keycount[Keywords::KEY_SOLUTION_MODIFY]) + keycount[Keywords::KEY_SOLUTION_MODIFY]*/) { /*"solution" */ new_solution = TRUE; } - if (keycount[Keywords::KEY_GAS_PHASE] > 0 || + if (keycount[Keywords::KEY_GAS_PHASE] > 0 /*|| keycount[Keywords::KEY_GAS_PHASE_RAW] > 0 || - keycount[Keywords::KEY_GAS_PHASE_MODIFY]) + keycount[Keywords::KEY_GAS_PHASE_MODIFY]*/) { new_gas_phase = TRUE; /*"gas_phase" */ } - if (keycount[Keywords::KEY_SOLID_SOLUTIONS] > 0 || + if (keycount[Keywords::KEY_SOLID_SOLUTIONS] > 0 /*|| keycount[Keywords::KEY_SOLID_SOLUTIONS_RAW] > 0 || - keycount[Keywords::KEY_SOLID_SOLUTIONS_MODIFY]) + keycount[Keywords::KEY_SOLID_SOLUTIONS_MODIFY]*/) { new_ss_assemblage = TRUE; /*"solid_solutions" */ } - if (keycount[Keywords::KEY_KINETICS] > 0 || + if (keycount[Keywords::KEY_KINETICS] > 0 /*|| keycount[Keywords::KEY_KINETICS_RAW] > 0 || - keycount[Keywords::KEY_KINETICS_MODIFY]) + keycount[Keywords::KEY_KINETICS_MODIFY]*/) { new_kinetics = TRUE; /*"kinetics" */ } @@ -1504,6 +1504,7 @@ tidy_pp_assemblage(void) it = Rxn_pp_assemblage_map.begin(); for ( ; it != Rxn_pp_assemblage_map.end(); it++) { + if (!it->second.Get_new_def()) continue; cxxPPassemblage *pp_assemblage_ptr = &(it->second); count_elts = 0; paren_count = 0; @@ -1590,6 +1591,7 @@ tidy_ss_assemblage(void) std::map::iterator it; for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) { + if (!it->second.Get_new_def()) continue; count_elts = 0; paren_count = 0; cxxSSassemblage *ss_assemblage_ptr = &(it->second); @@ -2376,6 +2378,7 @@ tidy_surface(void) std::map::iterator kit; for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) { + if (!kit->second.Get_new_def()) continue; surface_ptr = &(kit->second); for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { @@ -3323,11 +3326,11 @@ tidy_kin_surface(void) for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) { cxxSurface *surface_ptr = &(it->second); - int n = surface_ptr->Get_n_user(); if (!surface_ptr->Get_new_def()) continue; if (surface_ptr->Get_n_user() < 0) continue; + int n = surface_ptr->Get_n_user(); for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[j]); From 0440b0c7c2ae8fed4cfdcf36d8c7cd021539b6a1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 26 Jul 2012 15:32:06 +0000 Subject: [PATCH 0544/1077] Think restart files should work, but cannot test yet. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6818 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 63 +++++++++++++++++++++++++++++++++++++++++++++++++- StorageBin.h | 8 +++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/StorageBin.cxx b/StorageBin.cxx index f6927774..1d84ffc4 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -62,11 +62,13 @@ cxxStorageBin::Set_Solution(int n_user, cxxSolution * entity) if (entity == NULL) return; Solutions[n_user] = *entity; + Solutions.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Set_Solution(int n_user, cxxSolution & entity) { Solutions[n_user] = entity; + Solutions.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Solution(int n_user) @@ -89,6 +91,13 @@ cxxStorageBin::Set_Exchange(int n_user, cxxExchange * entity) if (entity == NULL) return; Exchangers[n_user] = *entity; + Exchangers.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Exchange(int n_user, cxxExchange & entity) +{ + Exchangers[n_user] = entity; + Exchangers.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Exchange(int n_user) @@ -111,11 +120,13 @@ cxxStorageBin::Set_PPassemblage(int n_user, cxxPPassemblage * entity) if (entity == NULL) return; PPassemblages[n_user] = *entity; + PPassemblages.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Set_PPassemblage(int n_user, cxxPPassemblage & entity) { PPassemblages[n_user] = entity; + PPassemblages.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_PPassemblage(int n_user) @@ -138,6 +149,13 @@ cxxStorageBin::Set_GasPhase(int n_user, cxxGasPhase * entity) if (entity == NULL) return; GasPhases[n_user] = *entity; + GasPhases.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_GasPhase(int n_user, cxxGasPhase & entity) +{ + GasPhases[n_user] = entity; + GasPhases.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_GasPhase(int n_user) @@ -160,11 +178,13 @@ cxxStorageBin::Set_SSassemblage(int n_user, cxxSSassemblage * entity) if (entity == NULL) return; SSassemblages[n_user] = *entity; + SSassemblages.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Set_SSassemblage(int n_user, cxxSSassemblage & entity) { SSassemblages[n_user] = entity; + SSassemblages.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_SSassemblage(int n_user) @@ -187,6 +207,13 @@ cxxStorageBin::Set_Kinetics(int n_user, cxxKinetics * entity) if (entity == NULL) return; Kinetics[n_user] = *entity; + Kinetics.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Kinetics(int n_user, cxxKinetics & entity) +{ + Kinetics[n_user] = entity; + Kinetics.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Kinetics(int n_user) @@ -209,6 +236,13 @@ cxxStorageBin::Set_Surface(int n_user, cxxSurface * entity) if (entity == NULL) return; Surfaces[n_user] = *entity; + Surfaces.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Surface(int n_user, cxxSurface & entity) +{ + Surfaces[n_user] = entity; + Surfaces.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Surface(int n_user) @@ -231,6 +265,13 @@ cxxStorageBin::Set_Mix(int n_user, cxxMix * entity) if (entity == NULL) return; Mixes[n_user] = *entity; + Mixes.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Mix(int n_user, cxxMix & entity) +{ + Mixes[n_user] = entity; + Mixes.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Mix(int n_user) @@ -253,6 +294,13 @@ cxxStorageBin::Set_Reaction(int n_user, cxxReaction * entity) if (entity == NULL) return; Reactions[n_user] = *entity; + Reactions.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Reaction(int n_user, cxxReaction & entity) +{ + Reactions[n_user] = entity; + Reactions.find(n_user)->second.Set_n_user_both(n_user); } void cxxStorageBin::Remove_Reaction(int n_user) @@ -276,8 +324,14 @@ cxxStorageBin::Set_Temperature(int n_user, cxxTemperature * entity) if (entity == NULL) return; Temperatures[n_user] = *entity; + Temperatures.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Temperature(int n_user, cxxTemperature & entity) +{ + Temperatures[n_user] = entity; + Temperatures.find(n_user)->second.Set_n_user_both(n_user); } - void cxxStorageBin::Remove_Temperature(int n_user) { @@ -296,6 +350,13 @@ cxxStorageBin::Set_Pressure(int n_user, cxxPressure * entity) if (entity == NULL) return; Pressures[n_user] = *entity; + Pressures.find(n_user)->second.Set_n_user_both(n_user); +} +void +cxxStorageBin::Set_Pressure(int n_user, cxxPressure & entity) +{ + Pressures[n_user] = entity; + Pressures.find(n_user)->second.Set_n_user_both(n_user); } void diff --git a/StorageBin.h b/StorageBin.h index c2ff2fd5..d64be7dd 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -37,6 +37,7 @@ class cxxStorageBin: public PHRQ_base cxxExchange *Get_Exchange(int n_user); void Set_Exchange(int n_user, cxxExchange * entity); + void Set_Exchange(int n_user, cxxExchange & entity); void Remove_Exchange(int n_user); cxxPPassemblage *Get_PPassemblage(int n_user); @@ -46,6 +47,7 @@ class cxxStorageBin: public PHRQ_base cxxGasPhase *Get_GasPhase(int n_user); void Set_GasPhase(int n_user, cxxGasPhase * entity); + void Set_GasPhase(int n_user, cxxGasPhase & entity); void Remove_GasPhase(int n_user); cxxSSassemblage *Get_SSassemblage(int n_user); @@ -55,26 +57,32 @@ class cxxStorageBin: public PHRQ_base cxxKinetics *Get_Kinetics(int n_user); void Set_Kinetics(int n_user, cxxKinetics * entity); + void Set_Kinetics(int n_user, cxxKinetics & entity); void Remove_Kinetics(int n_user); cxxSurface *Get_Surface(int n_user); void Set_Surface(int n_user, cxxSurface * entity); + void Set_Surface(int n_user, cxxSurface & entity); void Remove_Surface(int n_user); cxxMix *Get_Mix(int n_user); void Set_Mix(int n_user, cxxMix * entity); + void Set_Mix(int n_user, cxxMix & entity); void Remove_Mix(int n_user); cxxReaction *Get_Reaction(int n_user); void Set_Reaction(int n_user, cxxReaction * entity); + void Set_Reaction(int n_user, cxxReaction & entity); void Remove_Reaction(int n_user); cxxTemperature *Get_Temperature(int n_user); void Set_Temperature(int n_user, cxxTemperature * entity); + void Set_Temperature(int n_user, cxxTemperature & entity); void Remove_Temperature(int n_user); cxxPressure *Get_Pressure(int n_user); void Set_Pressure(int n_user, cxxPressure * entity); + void Set_Pressure(int n_user, cxxPressure & entity); void Remove_Pressure(int n_user); cxxSystem &Get_System(void); From d3a8fab539e2f5e20aaecf84051d3dbdbd3344c9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 27 Jul 2012 07:32:09 +0000 Subject: [PATCH 0545/1077] added const version of Get_pressures; added reaction_pressure to error_msg list; git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6821 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Pressure.h | 1 + phreeqc/read.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Pressure.h b/Pressure.h index fc7209fe..31e2ee38 100644 --- a/Pressure.h +++ b/Pressure.h @@ -24,6 +24,7 @@ class cxxPressure:public cxxNumKeyword void read_raw(CParser & parser); LDBLE Pressure_for_step(int step_number); std::vector & Get_pressures(void) {return pressures;} + const std::vector & Get_pressures(void)const {return pressures;} int Get_count(void) const; void Set_count(int i) {count = i;} bool Get_equalIncrements(void) const {return equalIncrements;} diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index f2b7b6ed..f46ada85 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -10313,7 +10313,7 @@ read_copy(void) default: input_error++; error_msg - ("Expecting keyword solution, mix, kinetics, reaction, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions, or cell.", + ("Expecting keyword solution, mix, kinetics, reaction, reaction_pressure, reaction_temperature, equilibrium_phases, exchange, surface, gas_phase, or solid_solutions, or cell.", CONTINUE); error_msg(line_save, CONTINUE); check_line("End of use", FALSE, TRUE, TRUE, TRUE); From a7acb6fff3b9e65c906b156801641a69b7f66e9c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 1 Aug 2012 04:24:39 +0000 Subject: [PATCH 0546/1077] added trys between System::Threading::Interlocked::CompareExchange and System::Threading::Interlocked::Exchange git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6825 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 57 ++++++-- ChartObject.cpp | 7 +- phreeqc/Form1.h | 370 +++++++++++++++++++++++++---------------------- 3 files changed, 244 insertions(+), 190 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index fa1fffe0..54dbe50b 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -44,11 +44,24 @@ ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) if (it->second->Get_active()) { #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 4)) + { + ::OutputDebugString("Sleeping 4\n"); System::Threading::Thread::Sleep(5); + } #endif - this->current_chart = it->second; - phreeqc_ptr-> punch_user_graph(); + try + { + this->current_chart = it->second; + phreeqc_ptr-> punch_user_graph(); + } + catch (...) + { +#if defined(__cplusplus_cli) + System::Threading::Interlocked::Exchange(it->second->usingResource, 0); +#endif + throw; + } #if defined(__cplusplus_cli) System::Threading::Interlocked::Exchange(it->second->usingResource, 0); #endif @@ -85,23 +98,36 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) // Read/update ChartObject #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 5)) + { + ::OutputDebugString("Sleeping 5\n"); System::Threading::Thread::Sleep(5); + } #endif + try { - it->second->Read(parser); - current_chart_n_user = n_user; - current_chart = it->second; - u_g_defined = true; - } + { + it->second->Read(parser); + current_chart_n_user = n_user; + current_chart = it->second; + u_g_defined = true; + } - // if detached, set timer_end and free - if (it->second->Get_detach() && it->second->Get_form_started()) + // if detached, set timer_end and free + if (it->second->Get_detach() && it->second->Get_form_started()) + { + it->second->Set_end_timer(true); + it->second->Rate_free(); + } + } + catch(...) { - it->second->Set_end_timer(true); - it->second->Rate_free(); +#if defined(__cplusplus_cli) + // Release lock + System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + throw; +#endif } - #if defined(__cplusplus_cli) // Release lock System::Threading::Interlocked::Exchange(it->second->usingResource, 0); @@ -136,8 +162,9 @@ ChartHandler::End_timer() if (it->second->Get_form_started()) { #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::Exchange(it->second->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 6)) { + ::OutputDebugString("Sleeping 6\n"); //if (i > max_tries) break; i++; System::Threading::Thread::Sleep(60); diff --git a/ChartObject.cpp b/ChartObject.cpp index e244169c..134bddb8 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -112,8 +112,9 @@ cxxNumKeyword(io) ChartObject::~ChartObject() { - while (0 != System::Threading::Interlocked::Exchange(this->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(this->usingResource, 0, 7)) { + ::OutputDebugString("Sleeping 7\n"); System::Threading::Thread::Sleep(5); } this->Rate_free(); @@ -316,7 +317,9 @@ ChartObject::Read(CParser & parser) { std::string tok; parser.get_rest_of_line(tok); - CParser::copy_title(this->chart_title, tok.begin(), tok.end()); + std::string::iterator b = tok.begin(); + std::string::iterator e = tok.end(); + CParser::copy_title(this->chart_title, b, e); } break; case 5: /* axis titles */ diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index e899d461..71ab1ed1 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -402,76 +402,89 @@ namespace zdg_ui2 { GraphPane ^myPane = z1->GraphPane; // lock thread - while (0 != System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(this->chartobject_ptr->usingResource, 0, 2)) + { + ::OutputDebugString("Sleeping 2\n"); System::Threading::Thread::Sleep(5); - - DefineCurves(myPane, 0); - - // Add text boxes with instructions... - GOL_no_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); - - TextObj ^text; - text = gcnew TextObj( - L" Click right mouse for options... \0", - 0.01f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); - text->FontSpec->StringAlignment = StringAlignment::Near; - text->FontSpec->Size = 10; - text->FontSpec->FontColor = Color::Red; - text->ZOrder = ZOrder::H_BehindAll; - myPane->GraphObjList->Add( text ); - text = gcnew TextObj( - L" Press Alt + F4 to quit", - 0.81f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); - text->FontSpec->StringAlignment = StringAlignment::Near; - text->FontSpec->Size = 10; - text->FontSpec->FontColor = Color::Red; - text->ZOrder = ZOrder::H_BehindAll; - myPane->GraphObjList->Add( text ); - - GOL_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); - if (this->hints) - { - myPane->GraphObjList = GOL_hints; - } - else - { - myPane->GraphObjList = GOL_no_hints; } - // Enable scrollbars if needed... - /*z1->IsShowHScrollBar = true; - z1->IsShowVScrollBar = true; - z1->IsAutoScrollRange = true; - z1->IsScrollY2 = true;*/ + try + { - // OPTIONAL: Show tooltips when the mouse hovers over a point - z1->IsShowPointValues = false; - z1->PointValueEvent += gcnew ZedGraphControl::PointValueHandler( this, - &Form1::MyPointValueHandler ); + DefineCurves(myPane, 0); - // OPTIONAL: Add a custom context menu item - z1->ContextMenuBuilder += gcnew ZedGraphControl::ContextMenuBuilderEventHandler( - this, &Form1::MyContextMenuBuilder ); + // Add text boxes with instructions... + GOL_no_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); - // OPTIONAL: Handle the Zoom Event - z1->ZoomEvent += gcnew ZedGraphControl::ZoomEventHandler( this, - &Form1::MyZoomEvent ); + TextObj ^text; + text = gcnew TextObj( + L" Click right mouse for options... \0", + 0.01f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); + text->FontSpec->StringAlignment = StringAlignment::Near; + text->FontSpec->Size = 10; + text->FontSpec->FontColor = Color::Red; + text->ZOrder = ZOrder::H_BehindAll; + myPane->GraphObjList->Add( text ); + text = gcnew TextObj( + L" Press Alt + F4 to quit", + 0.81f, 0.99f, CoordType::PaneFraction, AlignH::Left, AlignV::Bottom ); + text->FontSpec->StringAlignment = StringAlignment::Near; + text->FontSpec->Size = 10; + text->FontSpec->FontColor = Color::Red; + text->ZOrder = ZOrder::H_BehindAll; + myPane->GraphObjList->Add( text ); - // Size the control to fit the window - SetSize(); + GOL_hints = gcnew ZedGraph::GraphObjList(myPane->GraphObjList); + if (this->hints) + { + myPane->GraphObjList = GOL_hints; + } + else + { + myPane->GraphObjList = GOL_no_hints; + } - // Tell ZedGraph to calculate the axis ranges - // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets - // up the proper scrolling parameters + // Enable scrollbars if needed... + /*z1->IsShowHScrollBar = true; + z1->IsShowVScrollBar = true; + z1->IsAutoScrollRange = true; + z1->IsScrollY2 = true;*/ - z1->AxisChange(); - // Make sure the Graph gets redrawn - z1->Invalidate(); - timer1->Interval = this->chartobject_ptr->Get_update_time_chart(); - timer1->Enabled = true; - timer1->Start(); + // OPTIONAL: Show tooltips when the mouse hovers over a point + z1->IsShowPointValues = false; + z1->PointValueEvent += gcnew ZedGraphControl::PointValueHandler( this, + &Form1::MyPointValueHandler ); - tickStart = Environment::TickCount; + // OPTIONAL: Add a custom context menu item + z1->ContextMenuBuilder += gcnew ZedGraphControl::ContextMenuBuilderEventHandler( + this, &Form1::MyContextMenuBuilder ); + + // OPTIONAL: Handle the Zoom Event + z1->ZoomEvent += gcnew ZedGraphControl::ZoomEventHandler( this, + &Form1::MyZoomEvent ); + + // Size the control to fit the window + SetSize(); + + // Tell ZedGraph to calculate the axis ranges + // Note that you MUST call this after enabling IsAutoScrollRange, since AxisChange() sets + // up the proper scrolling parameters + + z1->AxisChange(); + // Make sure the Graph gets redrawn + z1->Invalidate(); + timer1->Interval = this->chartobject_ptr->Get_update_time_chart(); + timer1->Enabled = true; + timer1->Start(); + + tickStart = Environment::TickCount; + } + catch (...) + { + //unlock thread + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + throw; + } //unlock thread System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); @@ -840,141 +853,152 @@ namespace zdg_ui2 { if (chart == NULL) return; //lock for thread - while (0 != System::Threading::Interlocked::Exchange(chart->usingResource, 1)) + while (0 != System::Threading::Interlocked::CompareExchange(chart->usingResource, 0, 3)) + { + ::OutputDebugString("Sleeping 3\n"); System::Threading::Thread::Sleep(5); - - if (this->chartobject_ptr->Get_curve_added()) - { - DefineCurves(zg1->GraphPane, zg1->GraphPane->CurveList->Count); } - else if (this->chartobject_ptr->Get_point_added()) - { - // Make list of curves - std::vector Curves; - size_t j; - for (j = 0; j < chart->Get_CurvesCSV().size(); j++) + try + { + if (this->chartobject_ptr->Get_curve_added()) { - Curves.push_back(chart->Get_CurvesCSV()[j]); + DefineCurves(zg1->GraphPane, zg1->GraphPane->CurveList->Count); } - for (j = 0; j < chart->Get_Curves().size(); j++) + else if (this->chartobject_ptr->Get_point_added()) { - Curves.push_back(chart->Get_Curves()[j]); - } - // Add points to curves ... - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - // Get the PointPairList - IPointListEdit ^ip = (IPointListEdit^) curve->Points; - if ((size_t) ip->Count < Curves[i]->Get_x().size()) + + // Make list of curves + std::vector Curves; + size_t j; + for (j = 0; j < chart->Get_CurvesCSV().size(); j++) { - if (Curves[i]->Get_y_axis() == 2) - Y2 = true; - else - Y2 = false; - for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + Curves.push_back(chart->Get_CurvesCSV()[j]); + } + for (j = 0; j < chart->Get_Curves().size(); j++) + { + Curves.push_back(chart->Get_Curves()[j]); + } + // Add points to curves ... + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + // Get the PointPairList + IPointListEdit ^ip = (IPointListEdit^) curve->Points; + if ((size_t) ip->Count < Curves[i]->Get_x().size()) { - if ((LogX && Curves[i]->Get_x()[i2] <=0) - || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) - || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) - continue; + if (Curves[i]->Get_y_axis() == 2) + Y2 = true; else - ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + Y2 = false; + for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + { + if ((LogX && Curves[i]->Get_x()[i2] <=0) + || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + continue; + else + ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + } } } - } - // Add points to curves ... + // Add points to curves ... - //size_t i, k; - //k = 0; - //for (i = 0; i < Curves.size(); i++) - //{ - // if (Curves[i]->Get_x().size() == 0) continue; - // curve = (LineItem ^) zg1->GraphPane->CurveList[k++]; - // // Get the PointPairList - // IPointListEdit ^ip = (IPointListEdit^) curve->Points; - // if ((size_t) ip->Count < Curves[i]->Get_x().size()) - // { - // if (Curves[i]->Get_y_axis() == 2) - // Y2 = true; - // else - // Y2 = false; - // for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) - // { - // if ((LogX && Curves[i]->Get_x()[i2] <=0) - // || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) - // || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) - // continue; - // else - // ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); - // } - // } - //} - /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ - if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + //size_t i, k; + //k = 0; + //for (i = 0; i < Curves.size(); i++) + //{ + // if (Curves[i]->Get_x().size() == 0) continue; + // curve = (LineItem ^) zg1->GraphPane->CurveList[k++]; + // // Get the PointPairList + // IPointListEdit ^ip = (IPointListEdit^) curve->Points; + // if ((size_t) ip->Count < Curves[i]->Get_x().size()) + // { + // if (Curves[i]->Get_y_axis() == 2) + // Y2 = true; + // else + // Y2 = false; + // for ( size_t i2 = ip->Count; i2 < Curves[i]->Get_x().size(); i2++ ) + // { + // if ((LogX && Curves[i]->Get_x()[i2] <=0) + // || (LogY && !Y2 && Curves[i]->Get_y()[i2] <=0) + // || (LogY2 && Y2 && Curves[i]->Get_y()[i2] <=0)) + // continue; + // else + // ip->Add(Curves[i]->Get_x()[i2], Curves[i]->Get_y()[i2] ); + // } + // } + //} + /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ + if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) { - if (Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1] > max) - max = Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1]; + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + if (Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1] > max) + max = Curves[i]->Get_x()[Curves[i]->Get_x().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->XAxis->Scale->Max = max; } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->XAxis->Scale->Max = max; - } - if ((fabs(chart->Get_axis_scale_y()[1] - NA) < 1e-3) && zg1->GraphPane->YAxis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + if ((fabs(chart->Get_axis_scale_y()[1] - NA) < 1e-3) && zg1->GraphPane->YAxis->Type == AxisType::Log) { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - if (curve->IsY2Axis) continue; - if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) - max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->YAxis->Scale->Max = max; } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->YAxis->Scale->Max = max; - } - if ((fabs(chart->Get_axis_scale_y2()[1] - NA) < 1e-3) && zg1->GraphPane->Y2Axis->Type == AxisType::Log) - { - double max = -1e99; - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + if ((fabs(chart->Get_axis_scale_y2()[1] - NA) < 1e-3) && zg1->GraphPane->Y2Axis->Type == AxisType::Log) { - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - if (!curve->IsY2Axis) continue; - if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) - max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + double max = -1e99; + for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) + { + curve = (LineItem ^) zg1->GraphPane->CurveList[i]; + if (!curve->IsY2Axis) continue; + if (Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1] > max) + max = Curves[i]->Get_y()[Curves[i]->Get_y().size() - 1]; + } + max += pow(10.0, log10(max / 3)); + zg1->GraphPane->Y2Axis->Scale->Max = max; } - max += pow(10.0, log10(max / 3)); - zg1->GraphPane->Y2Axis->Scale->Max = max; + zg1->AxisChange(); + zg1->Refresh(); + } + + chart->Set_point_added(false); + if (chart->Get_end_timer()) + { + timer1->Stop(); + chart->Set_done(true); + phreeqc_done = true; + + int batch = chart->Get_batch(); + if (batch > 0) + { + BatchSaveImage(); + } + + //unlock thread before setting chartobject_ptr to NULL + System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + this->phreeqc_ptr = NULL; + this->chartobject_ptr = NULL; + if (batch >= 0) + { + this->Close(); + } + return; } - zg1->AxisChange(); - zg1->Refresh(); } - - chart->Set_point_added(false); - if (chart->Get_end_timer()) + catch(...) { - timer1->Stop(); - chart->Set_done(true); - phreeqc_done = true; - - int batch = chart->Get_batch(); - if (batch > 0) - { - BatchSaveImage(); - } - - //unlock thread before setting chartobject_ptr to NULL System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); - this->phreeqc_ptr = NULL; - this->chartobject_ptr = NULL; - if (batch >= 0) - { - this->Close(); - } - return; + throw; } //unlock thread From 54ec7c4a1a8bbff4a59064318cb5f33b3511dc92 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Aug 2012 19:14:38 +0000 Subject: [PATCH 0547/1077] Removed toggle hints and toggle background Added Chart options... git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6826 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 158 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 146 insertions(+), 12 deletions(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 71ab1ed1..52a1ab00 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -41,6 +41,7 @@ namespace zdg_ui2 { phreeqc_done = false; background = true; hints = true; + grid = true; } public: Form1(ChartObject *ptr) { @@ -54,6 +55,7 @@ namespace zdg_ui2 { Y2show = false; background = true; hints = true; + grid = true; } static void ThreadForm(Object^ data) { @@ -138,8 +140,7 @@ namespace zdg_ui2 { int col_use, symbol_use; bool Y2, Y2show; static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black", "Cyan", "Brown", "Lime", "Gray" }; - bool background; - bool hints; + bool background, hints, grid; ZedGraph::GraphObjList ^GOL_no_hints; ZedGraph::GraphObjList ^GOL_hints; @@ -380,10 +381,14 @@ namespace zdg_ui2 { if (this->background) { myPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + myPane->XAxis->MajorGrid->IsVisible = true; + myPane->YAxis->MajorGrid->IsVisible = true; } else { myPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + myPane->XAxis->MajorGrid->IsVisible = false; + myPane->YAxis->MajorGrid->IsVisible = false; } // normalize pane size... @@ -516,14 +521,14 @@ namespace zdg_ui2 { menuStrip->Items->Insert(5, item ); ToolStripMenuItem ^item3 = gcnew ToolStripMenuItem(); - item3->Text = L"Toggle Background"; - item3->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleBackground ); + item3->Text = L"Chart options..."; + item3->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::SetChartOptions ); menuStrip->Items->Insert(0, item3 ); - ToolStripMenuItem ^item5 = gcnew ToolStripMenuItem(); - item5->Text = L"Toggle Hints"; - item5->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleHints ); - menuStrip->Items->Insert(0, item5 ); + //ToolStripMenuItem ^item5 = gcnew ToolStripMenuItem(); + //item5->Text = L"Toggle Hints"; + //item5->Click += gcnew System::EventHandler(this, &zdg_ui2::Form1::ToggleHints ); + //menuStrip->Items->Insert(0, item5 ); ToolStripMenuItem ^item2 = gcnew ToolStripMenuItem(); item2->Text = L"Save Data to File..."; @@ -741,24 +746,140 @@ namespace zdg_ui2 { { // Here we get notification everytime the user zooms } - +#ifdef SKIP void ToggleBackground( System::Object ^sender, System::EventArgs ^e ) { this->background = !this->background; if (this->background) { zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; } else { zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; } zg1->Refresh(); } - - void ToggleHints( System::Object ^sender, System::EventArgs ^e ) +#endif + void SetChartOptions( System::Object ^sender, System::EventArgs ^e ) { - this->hints = !this->hints; + // Create form + Form ^graphOptions = gcnew Form; + graphOptions->Text = "Chart options"; + //graphOptions->CenterToParent(); + graphOptions->BringToFront(); + graphOptions->SetBounds(0, 0, 255, 230); + //graphOptions->AutoSize = true; + + // done button for Form + Button^ button1 = gcnew Button; + button1->DialogResult = System::Windows::Forms::DialogResult::OK; + button1->Text = "Done"; + button1->Location = System::Drawing::Point(75, 160); + graphOptions->Controls->Add(button1); + graphOptions->AcceptButton = button1; + + // cancel button for Form + Button^ button2 = gcnew Button; + button2->DialogResult = System::Windows::Forms::DialogResult::Cancel; + button2->Text = "Cancel"; + button2->Location = System::Drawing::Point(155, 160); + graphOptions->Controls->Add(button2); + graphOptions->CancelButton = button2; + + // Check box for hints + CheckBox ^cb1 = gcnew CheckBox; + cb1->Appearance = Appearance::Normal; + cb1->ThreeState = false; + cb1->AutoCheck = true; + cb1->Location = System::Drawing::Point(5, 10); + if (this->hints) + { + cb1->CheckState = CheckState::Checked; + } + else + { + cb1->CheckState = CheckState::Unchecked; + } + cb1->Text = "Show hints"; + cb1->Visible = true; + graphOptions->Controls->Add(cb1); + + // Check box for background color + CheckBox ^cb2 = gcnew CheckBox; + cb2->Appearance = Appearance::Normal; + cb2->ThreeState = false; + cb2->AutoCheck = true; + cb2->Location = System::Drawing::Point(5, 60); + + if (this->background) + { + cb2->CheckState = CheckState::Checked; + } + else + { + cb2->CheckState = CheckState::Unchecked; + } + cb2->Text = "Show colored background"; + cb2->AutoSize = true; + //cb2->TextBox->Width = 250; + //cb2->SetBounds(5, 60, 150, 20); + cb2->Visible = true; + graphOptions->Controls->Add(cb2); + + // checkbox for grid + CheckBox ^cb3 = gcnew CheckBox; + cb3->Appearance = Appearance::Normal; + cb3->ThreeState = false; + cb3->AutoCheck = true; + cb3->Location = System::Drawing::Point(5, 110); + + if (this->grid) + { + cb3->CheckState = CheckState::Checked; + } + else + { + cb3->CheckState = CheckState::Unchecked; + } + cb3->Text = "Show grid lines"; + cb3->Visible = true; + graphOptions->Controls->Add(cb3); + + if (graphOptions->ShowDialog() == System::Windows::Forms::DialogResult::OK) + { + this->hints = (cb1->CheckState == CheckState::Checked); + this->background = (cb2->CheckState == CheckState::Checked); + this->grid = (cb3->CheckState == CheckState::Checked); + } + + //this->background = !this->background; + if (this->background) + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + //zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; + //zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; + } + else + { + zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + //zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; + //zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; + } + if (this->grid) + { + zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; + } + else + { + zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; + } if (this->hints) { zg1->GraphPane->GraphObjList = GOL_hints; @@ -769,6 +890,19 @@ namespace zdg_ui2 { } zg1->Refresh(); } + //void ToggleHints( System::Object ^sender, System::EventArgs ^e ) + //{ + // this->hints = !this->hints; + // if (this->hints) + // { + // zg1->GraphPane->GraphObjList = GOL_hints; + // } + // else + // { + // zg1->GraphPane->GraphObjList = GOL_no_hints; + // } + // zg1->Refresh(); + //} void SaveImage( System::Object ^sender, System::EventArgs ^e ) { ZedGraph::GraphObjList ^copy = gcnew ZedGraph::GraphObjList(zg1->GraphPane->GraphObjList); From baf456635622e5e93f07a2bf39a026bec9344eb9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Aug 2012 20:03:47 +0000 Subject: [PATCH 0548/1077] Added second logical in batch. First is color, second is grid. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6827 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 79 +++++++++++-------------------------------------- ChartObject.h | 4 +++ phreeqc/Form1.h | 58 +++++++++++------------------------- 3 files changed, 40 insertions(+), 101 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 134bddb8..7604f9a9 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -107,6 +107,7 @@ cxxNumKeyword(io) detach = false; batch_background = true; + batch_grid = true; batch = ChO_NO_BATCH; } @@ -474,75 +475,31 @@ ChartObject::Read(CParser & parser) { token = rest_of_line.substr(last); token = trim(token); - if (token.size() > 0) + std::string tf; + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + + CParser::copy_token(tf, b, e); + if (tf.size() > 0) { - Utilities::str_tolower(token); - if (token[0] == 'f') + Utilities::str_tolower(tf); + if (tf[0] == 'f') { this->batch_background = false; } } + CParser::copy_token(tf, b, e); + if (tf.size() > 0) + { + Utilities::str_tolower(tf); + if (tf[0] == 'f') + { + this->batch_grid = false; + } + } } } break; -#ifdef SKIP - case 16: /* batch */ - { - this->batch = ChartObject::ChO_BATCH_ONLY; - - std::string file_name; - if (parser.copy_token(file_name, next_char) != CParser::TT_EMPTY) - { - //Get suffix from file_name - size_t ssi = file_name.rfind('.'); - if (ssi == std::string::npos) - { - std::ostringstream estream; - estream << "Batch file name must have suffix emf, phg, jpg, gif, tiff, or bmp."; - error_msg(estream.str().c_str(), CONTINUE); - break; - } - - std::string suffix = file_name.substr(ssi + 1); - Utilities::str_tolower(suffix); - if (suffix == "emf") - this->batch = ChartObject::ChO_EMF; - else if (suffix == "png") - this->batch = ChartObject::ChO_PNG; - else if (suffix == "jpg") - this->batch = ChartObject::ChO_JPG; - else if (suffix == "gif") - this->batch = ChartObject::ChO_GIF; - else if (suffix == "tiff") - this->batch = ChartObject::ChO_TIFF; - else if (suffix == "bmp") - this->batch = ChartObject::ChO_BMP; - else if (suffix == "jpeg") - this->batch = ChartObject::ChO_JPG; - else - { - std::ostringstream estream; - estream << "Batch file name must have suffix emf, phg, jpg, jpeg, gif, tiff, or bmp."; - error_msg(estream.str().c_str(), CONTINUE); - break; - } - this->batch_fn = file_name; - - // Get background bool - parser.copy_token(token, next_char); - if (token.size() > 0) - { - Utilities::str_tolower(token); - if (token[0] == 'f') - { - this->batch_background = false; - } - } - } - - } - break; -#endif case CParser::OPT_DEFAULT: // Read Basic commands { if (!new_command_lines) diff --git a/ChartObject.h b/ChartObject.h index 91b530f0..5e7e2eb0 100644 --- a/ChartObject.h +++ b/ChartObject.h @@ -358,6 +358,9 @@ class ChartObject:public cxxNumKeyword void Set_batch(chart_batch_type bt) {this->batch = bt;} bool Get_batch_background(void) {return this->batch_background;} void Set_batch_background(bool tf) {this->batch_background = tf;} + + bool Get_batch_grid(void) {return this->batch_grid;} + void Set_batch_grid(bool tf) {this->batch_grid = tf;} protected: bool new_ug; @@ -428,6 +431,7 @@ class ChartObject:public cxxNumKeyword class Phreeqc * phreeqc_ptr; bool batch_background; + bool batch_grid; std::string batch_fn; chart_batch_type batch; const static std::vector < std::string > vopts; diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 52a1ab00..f0e08473 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -381,16 +381,21 @@ namespace zdg_ui2 { if (this->background) { myPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); + } + else + { + myPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); + } + if (this->grid) + { myPane->XAxis->MajorGrid->IsVisible = true; myPane->YAxis->MajorGrid->IsVisible = true; } else { - myPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); myPane->XAxis->MajorGrid->IsVisible = false; myPane->YAxis->MajorGrid->IsVisible = false; } - // normalize pane size... myPane->BaseDimension = 8.0F; // increase bottom margin to accommodate text options... @@ -746,25 +751,6 @@ namespace zdg_ui2 { { // Here we get notification everytime the user zooms } -#ifdef SKIP - void ToggleBackground( System::Object ^sender, System::EventArgs ^e ) - { - this->background = !this->background; - if (this->background) - { - zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); - zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; - zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; - } - else - { - zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); - zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; - zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; - } - zg1->Refresh(); - } -#endif void SetChartOptions( System::Object ^sender, System::EventArgs ^e ) { // Create form @@ -857,18 +843,13 @@ namespace zdg_ui2 { this->grid = (cb3->CheckState == CheckState::Checked); } - //this->background = !this->background; if (this->background) { zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::FromArgb(255, 255, 230), 45.0f ); - //zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; - //zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; } else { zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); - //zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; - //zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; } if (this->grid) { @@ -890,19 +871,6 @@ namespace zdg_ui2 { } zg1->Refresh(); } - //void ToggleHints( System::Object ^sender, System::EventArgs ^e ) - //{ - // this->hints = !this->hints; - // if (this->hints) - // { - // zg1->GraphPane->GraphObjList = GOL_hints; - // } - // else - // { - // zg1->GraphPane->GraphObjList = GOL_no_hints; - // } - // zg1->Refresh(); - //} void SaveImage( System::Object ^sender, System::EventArgs ^e ) { ZedGraph::GraphObjList ^copy = gcnew ZedGraph::GraphObjList(zg1->GraphPane->GraphObjList); @@ -929,7 +897,17 @@ namespace zdg_ui2 { { zg1->GraphPane->Chart->Fill = gcnew Fill( Color::White, Color::White, 45.0f ); } - + // Set grid + if (chart->Get_batch_grid()) + { + zg1->GraphPane->XAxis->MajorGrid->IsVisible = true; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = true; + } + else + { + zg1->GraphPane->XAxis->MajorGrid->IsVisible = false; + zg1->GraphPane->YAxis->MajorGrid->IsVisible = false; + } // Save the graph if (this->zg1) { From 1f8d86089ae4ba2674a51dd9e259b59ebc29575b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Aug 2012 22:54:37 +0000 Subject: [PATCH 0549/1077] fixed location, resizing, tab order. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6831 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index f0e08473..b7134253 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -756,26 +756,11 @@ namespace zdg_ui2 { // Create form Form ^graphOptions = gcnew Form; graphOptions->Text = "Chart options"; - //graphOptions->CenterToParent(); graphOptions->BringToFront(); - graphOptions->SetBounds(0, 0, 255, 230); - //graphOptions->AutoSize = true; - - // done button for Form - Button^ button1 = gcnew Button; - button1->DialogResult = System::Windows::Forms::DialogResult::OK; - button1->Text = "Done"; - button1->Location = System::Drawing::Point(75, 160); - graphOptions->Controls->Add(button1); - graphOptions->AcceptButton = button1; - - // cancel button for Form - Button^ button2 = gcnew Button; - button2->DialogResult = System::Windows::Forms::DialogResult::Cancel; - button2->Text = "Cancel"; - button2->Location = System::Drawing::Point(155, 160); - graphOptions->Controls->Add(button2); - graphOptions->CancelButton = button2; + graphOptions->MinimumSize = System::Drawing::Size(255, 230); + graphOptions->MaximumSize = System::Drawing::Size(255, 230); + graphOptions->Size = System::Drawing::Size(255, 230); + graphOptions->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent; // Check box for hints CheckBox ^cb1 = gcnew CheckBox; @@ -812,8 +797,6 @@ namespace zdg_ui2 { } cb2->Text = "Show colored background"; cb2->AutoSize = true; - //cb2->TextBox->Width = 250; - //cb2->SetBounds(5, 60, 150, 20); cb2->Visible = true; graphOptions->Controls->Add(cb2); @@ -836,6 +819,23 @@ namespace zdg_ui2 { cb3->Visible = true; graphOptions->Controls->Add(cb3); + // done button for Form + Button^ button1 = gcnew Button; + button1->DialogResult = System::Windows::Forms::DialogResult::OK; + button1->Text = "Done"; + button1->Location = System::Drawing::Point(75, 160); + graphOptions->Controls->Add(button1); + graphOptions->AcceptButton = button1; + + // cancel button for Form + Button^ button2 = gcnew Button; + button2->DialogResult = System::Windows::Forms::DialogResult::Cancel; + button2->Text = "Cancel"; + button2->Location = System::Drawing::Point(155, 160); + graphOptions->Controls->Add(button2); + graphOptions->CancelButton = button2; + + if (graphOptions->ShowDialog() == System::Windows::Forms::DialogResult::OK) { this->hints = (cb1->CheckState == CheckState::Checked); From 545dbd1081d04e3ac47c36333ba24a399abdd1cd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 2 Aug 2012 15:43:57 +0000 Subject: [PATCH 0550/1077] Added some status_on = true in status. Limited temperature to 350 for calculation of rho_0 and dielectric constant; added warning message. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6832 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + phreeqc/mainsubs.cpp | 1 + phreeqc/utilities.cpp | 22 +++++++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 62b65cab..3d56cd12 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1659,6 +1659,7 @@ protected: LDBLE ZBrn; // Born function (-1/eps_r + 1) * 41.84004, for supcrt calc'n of molal volume LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume #endif + int need_temp_msg; LDBLE solution_mass, solution_volume; /* phqalloc.cpp ------------------------------- */ diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 2ef860d7..87fe29b6 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -703,6 +703,7 @@ initialize(void) eps_r = EPSILON; #endif rho_0 = 0; + need_temp_msg = 0; solution_mass = 0; solution_volume = 0; diff --git a/phreeqc/utilities.cpp b/phreeqc/utilities.cpp index d0e5a404..4322ebfd 100644 --- a/phreeqc/utilities.cpp +++ b/phreeqc/utilities.cpp @@ -116,6 +116,18 @@ calc_rho_0(LDBLE tc, LDBLE pa) Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + interpolation 0 - 300 oC, 0.006 - 1000 atm... */ + if (tc > 350.) + { + if (need_temp_msg < 1) + { + std::ostringstream w_msg; + w_msg << "Fitting range for density of pure water is 0-300 C.\n"; + w_msg << "Using temperature of 350 C for density and dielectric calculation."; + warning_msg(w_msg.str().c_str()); + need_temp_msg++; + } + tc = 350.; + } LDBLE T = tc + 273.15; //eqn. 2.6... LDBLE Tc = 647.096, th = 1 - T / Tc; @@ -240,6 +252,10 @@ calc_dielectrics(LDBLE tc, LDBLE pa) and Fernandez et al., 1997, JPCRD 26, 1125, show its correctness) + d(eps)/d(P), Debye-Hueckel A and B, and Av (for Av, see Pitzer et al., 1984, JPCRD 13, p. 4) */ + if (tc > 350.) + { + tc = 350.; + } LDBLE T = tc + 273.15; LDBLE u1 = 3.4279e2, u2 = -5.0866e-3, u3 = 9.469e-7, u4 = -2.0525, u5 = 3.1159e3, u6 = -1.8289e2, u7 = -8.0325e3, u8 = 4.2142e6, @@ -1382,7 +1398,6 @@ status(int count, const char *str, bool rk_string) char spin_str[2]; clock_t t2; - #ifdef PHREEQ98 if (ProcessMessages) ApplicationProcessMessages(); @@ -1396,6 +1411,7 @@ status(int count, const char *str, bool rk_string) { screen_string = sformatf("\n%-80s", "Initializing..."); screen_msg(screen_string.c_str()); + status_on = true; return (OK); } t2 = clock(); @@ -1424,6 +1440,7 @@ status(int count, const char *str, bool rk_string) screen_string.append(str); screen_msg(screen_string.c_str()); } + status_on = true; } case PHAST: break; @@ -1433,8 +1450,7 @@ status(int count, const char *str, bool rk_string) { screen_string = "\r"; screen_string.append(str); - screen_msg(screen_string.c_str()); - } + screen_msg(screen_string.c_str()); } else // print state { From 1a1950c46e34b80c7b60d7535c4fba15eb9be8d0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 2 Aug 2012 16:21:12 +0000 Subject: [PATCH 0551/1077] Added total_h and total_o to tally table. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6833 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tally.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index a56998a1..6a4f65bf 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -102,9 +102,9 @@ get_all_components(void) /* - * Count components + Alkalinity + * Count components + Alkalinity + total_h + total_o */ - tally_count_component = 1; + tally_count_component = 3; for (i = 0; i < count_master; i++) { if (master[i]->total > 0.0 && master[i]->s->type == AQ) @@ -128,6 +128,17 @@ get_all_components(void) t_buffer[j].gfw = t_buffer[j].master->elt->gfw; j++; + // store total_h + t_buffer[j].name = string_hsave("Total_H"); + t_buffer[j].master = NULL; + compute_gfw("H", &(t_buffer[j].gfw)); + j++; + + // store total_o + t_buffer[j].name = string_hsave("Total_O"); + t_buffer[j].master = NULL; + compute_gfw("O", &(t_buffer[j].gfw)); + j++; for (i = 0; i < count_master; i++) { @@ -505,6 +516,12 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) // Add alkalinity tally_table[i].total[n_buffer][0].moles = solution_ptr->Get_total_alkalinity(); + + // Add total_h + tally_table[i].total[n_buffer][1].moles = solution_ptr->Get_total_h(); + + // Add total_o + tally_table[i].total[n_buffer][2].moles = solution_ptr->Get_total_o(); } break; #ifdef SKIP From e5177c6029abdd4053b9b1b848f8a3802daa709f Mon Sep 17 00:00:00 2001 From: Richard M Webb Date: Thu, 2 Aug 2012 16:33:47 +0000 Subject: [PATCH 0552/1077] void null pointer for master git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6834 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tally.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/phreeqc/tally.cpp b/phreeqc/tally.cpp index 6a4f65bf..23899ec9 100644 --- a/phreeqc/tally.cpp +++ b/phreeqc/tally.cpp @@ -811,11 +811,14 @@ elt_list_to_tally_table(struct tally_buffer *buffer_ptr) continue; for (i = 0; i < count_tally_table_rows; i++) { - if (elt_list[j].elt->primary == - buffer_ptr[i].master->elt->primary) + if (buffer_ptr[i].master != NULL) { - buffer_ptr[i].moles = elt_list[j].coef; - break; + if (elt_list[j].elt->primary == + buffer_ptr[i].master->elt->primary) + { + buffer_ptr[i].moles = elt_list[j].coef; + break; + } } } if (i >= count_tally_table_rows) From 31c1ae8664d6a4f4da747269580df0d96325b96a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 5 Aug 2012 18:04:34 +0000 Subject: [PATCH 0553/1077] Optimizing activity update git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6855 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ NameDouble.h | 2 +- Solution.cxx | 69 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index 9278c389..9c87f980 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -289,6 +289,85 @@ cxxNameDouble::add_log_activities(const cxxNameDouble & addee, LDBLE f1, } } cxxNameDouble +cxxNameDouble::Simplify_redox(void) const +{ + cxxNameDouble const &nd = *this; + std::basic_string < char >::size_type indexCh; + cxxNameDouble new_totals; + new_totals.type = cxxNameDouble::ND_ELT_MOLES; + { + std::string current_ename; + cxxNameDouble::const_iterator it; + + // make list of elements in new_totals + for (it = nd.begin(); it != nd.end(); ++it) + { + current_ename = it->first; + if (it->first.size() < 4) + { + current_ename = it->first; + } + else + { + indexCh = current_ename.find("("); + if (indexCh != std::string::npos) + { + current_ename = current_ename.substr(0, indexCh); + } + else + { + current_ename = it->first; + } + } + if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") + continue; + new_totals[current_ename] = 0; + } + } + + // sum totals for elements + { + cxxNameDouble::const_iterator old_it = nd.begin(); + cxxNameDouble::iterator new_it = new_totals.begin(); + std::string old_ename; + while (old_it != nd.end() && new_it != new_totals.end()) + { + if (old_it->first.size() < 4) + { + old_ename = old_it->first; + } + else + { + indexCh = old_it->first.find("("); + if (indexCh != std::string::npos) + { + old_ename = old_ename.substr(0, indexCh); + } + else + { + old_ename = old_it->first; + } + } + int j = strcmp(new_it->first.c_str(), old_ename.c_str()); + if (j < 0) + { + new_it++; + } + else if (j == 0) + { + new_it->second += old_it->second; + old_it++; + } + else + { + old_it++; + } + } + } + return new_totals; +} +#ifdef SKIP +cxxNameDouble cxxNameDouble::Simplify_redox(void) { // remove individual redox states from totals @@ -318,6 +397,7 @@ cxxNameDouble::Simplify_redox(void) } return new_totals; } +#endif void cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) { diff --git a/NameDouble.h b/NameDouble.h index cf7eaabc..4105da9a 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -34,7 +34,7 @@ class cxxNameDouble:public ~cxxNameDouble(); LDBLE Get_total_element(const char *string) const; - cxxNameDouble Simplify_redox(void); + cxxNameDouble Simplify_redox(void) const; void Multiply_activities_redox(std::string, LDBLE f); void dump_xml(std::ostream & s_oss, unsigned int indent) const; diff --git a/Solution.cxx b/Solution.cxx index 8deb02db..e1c328b5 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -643,6 +643,74 @@ cxxSolution::read_raw(CParser & parser, bool check) } void cxxSolution::Update(const cxxNameDouble &const_nd) +{ + if (this->master_activity.size() > 0) + { + cxxNameDouble simple_original = this->totals.Simplify_redox(); + cxxNameDouble simple_new = const_nd.Simplify_redox(); + + // make factors + { + cxxNameDouble::iterator it = simple_new.begin(); + for ( ; it != simple_new.end(); it++) + { + cxxNameDouble::iterator jit = simple_original.find(it->first); + if (jit != simple_original.end()) + { + if (it->second != 0 && jit->second > 0) + { + it->second = log10(jit->second / it->second); + } + } + else + { + it->second = 0; + } + } + } + + // simple_new now has factors for master activities + // Now add factors to activities + { + cxxNameDouble::iterator activity_it = this->master_activity.begin(); + cxxNameDouble::iterator total_it = simple_new.begin(); + std::string activity_ename; + std::basic_string < char >::size_type indexCh; + while (activity_it != master_activity.end() && total_it != simple_new.end()) + { + activity_ename = activity_it->first; + if (activity_ename.size() > 3) + { + indexCh = activity_ename.find("("); + if (indexCh != std::string::npos) + { + activity_ename = activity_ename.substr(0, indexCh); + } + } + int j = strcmp(total_it->first.c_str(), activity_ename.c_str()); + if (j < 0) + { + total_it++; + } + else if (j == 0) + { + if (total_it->second > 0) + { + activity_it->second += total_it->second; + } + activity_it++; + } + else + { + activity_it++; + } + } + } + } +} +#ifdef SKIP +void +cxxSolution::Update(const cxxNameDouble &const_nd) { // const_nd is updated totals cxxNameDouble simple_original_totals = this->totals.Simplify_redox(); @@ -677,6 +745,7 @@ cxxSolution::Update(const cxxNameDouble &const_nd) return; } +#endif void cxxSolution::zero() { From 8b0481a1eedf48c7d04bcac0253a3030044dbdb7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 5 Aug 2012 19:12:28 +0000 Subject: [PATCH 0554/1077] Working on efficiency of updating Solution.cxx Need to revise solution_modify. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6856 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 73 +++++++++++++++++++++++++++++++++++----------------- Solution.h | 2 ++ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index e1c328b5..cc891645 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -642,41 +642,62 @@ cxxSolution::read_raw(CParser & parser, bool check) return; } void +cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &const_nd) +{ + // H, O, charge, totals, and activities of solution are updated + this->total_h = h_tot; + this->total_o = o_tot; + this->cb = charge; + + this->Update(const_nd); +} +void cxxSolution::Update(const cxxNameDouble &const_nd) { - if (this->master_activity.size() > 0) - { - cxxNameDouble simple_original = this->totals.Simplify_redox(); - cxxNameDouble simple_new = const_nd.Simplify_redox(); + // Totals and activities of solution are updated + // nd does not have H, O, charge + cxxNameDouble simple_original = this->totals.Simplify_redox(); + cxxNameDouble simple_new = const_nd.Simplify_redox(); - // make factors + // make factors + cxxNameDouble factors; + { + cxxNameDouble::iterator it = simple_new.begin(); + cxxNameDouble::iterator jit = simple_original.begin(); + while (it != simple_new.end() && jit != simple_original.end()) { - cxxNameDouble::iterator it = simple_new.begin(); - for ( ; it != simple_new.end(); it++) + int j = strcmp(it->first.c_str(), jit->first.c_str()); + if (j < 0) { - cxxNameDouble::iterator jit = simple_original.find(it->first); - if (jit != simple_original.end()) + it++; + } + else if (j == 0) + { + if (jit->second != it->second) { - if (it->second != 0 && jit->second > 0) + if (it->second > 0 && jit->second > 0) { - it->second = log10(jit->second / it->second); + factors[it->first] = log10(jit->second / it->second); } } - else - { - it->second = 0; - } + it++; + jit++; + } + else + { + jit++; } } + // simple_new now has factors for master activities // Now add factors to activities { cxxNameDouble::iterator activity_it = this->master_activity.begin(); - cxxNameDouble::iterator total_it = simple_new.begin(); + cxxNameDouble::iterator factors_it = factors.begin(); std::string activity_ename; std::basic_string < char >::size_type indexCh; - while (activity_it != master_activity.end() && total_it != simple_new.end()) + while (activity_it != master_activity.end() && factors_it != factors.end()) { activity_ename = activity_it->first; if (activity_ename.size() > 3) @@ -687,17 +708,14 @@ cxxSolution::Update(const cxxNameDouble &const_nd) activity_ename = activity_ename.substr(0, indexCh); } } - int j = strcmp(total_it->first.c_str(), activity_ename.c_str()); + int j = strcmp(factors_it->first.c_str(), activity_ename.c_str()); if (j < 0) { - total_it++; + factors_it++; } else if (j == 0) { - if (total_it->second > 0) - { - activity_it->second += total_it->second; - } + activity_it->second += factors_it->second; activity_it++; } else @@ -707,6 +725,15 @@ cxxSolution::Update(const cxxNameDouble &const_nd) } } } + + // update other totals + { + cxxNameDouble::iterator it; + for (it = simple_new.begin(); it != simple_new.end(); it++) + { + simple_original[it->first] = it->second; + } + } } #ifdef SKIP void diff --git a/Solution.h b/Solution.h index 74f23e0a..fb3f917c 100644 --- a/Solution.h +++ b/Solution.h @@ -103,6 +103,8 @@ class cxxSolution:public cxxNumKeyword //void modify_activities(const cxxSolution & original); //void Simplify_totals(); void Update(const cxxNameDouble &nd); + void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); + void Update_activities(const cxxNameDouble &old_tot, const cxxNameDouble &new_tot); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); From 881ca8f2b605dde753f319fc319e8f5890624664 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 6 Aug 2012 18:35:40 +0000 Subject: [PATCH 0555/1077] debugging and optimizing git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6857 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 1 + NameDouble.cxx | 53 ++++-- Solution.cxx | 429 ++++++++++++++++++++++++++++++++++++++++++++++- Solution.h | 2 +- phreeqc/step.cpp | 2 +- 5 files changed, 468 insertions(+), 19 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index e3e1327c..35a6a3e1 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -37,6 +37,7 @@ cxxNumKeyword(io) { this->n_user = this->n_user_end = l_n_user; this->pitzer_exchange_gammas = true; + this->new_def = false; // // Mix exchangers // diff --git a/NameDouble.cxx b/NameDouble.cxx index 9c87f980..8c5fd5d9 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -297,6 +297,7 @@ cxxNameDouble::Simplify_redox(void) const new_totals.type = cxxNameDouble::ND_ELT_MOLES; { std::string current_ename; + std::string const *ename_ptr; cxxNameDouble::const_iterator it; // make list of elements in new_totals @@ -305,23 +306,24 @@ cxxNameDouble::Simplify_redox(void) const current_ename = it->first; if (it->first.size() < 4) { - current_ename = it->first; + ename_ptr = &(it->first); } else { - indexCh = current_ename.find("("); + indexCh = it->first.find("("); if (indexCh != std::string::npos) { - current_ename = current_ename.substr(0, indexCh); + current_ename = it->first.substr(0, indexCh); + ename_ptr = &(current_ename); } else { - current_ename = it->first; + ename_ptr = &(it->first); } } if (current_ename == "H" || current_ename == "O" || current_ename == "Charge") continue; - new_totals[current_ename] = 0; + new_totals[*ename_ptr] = 0; } } @@ -330,25 +332,27 @@ cxxNameDouble::Simplify_redox(void) const cxxNameDouble::const_iterator old_it = nd.begin(); cxxNameDouble::iterator new_it = new_totals.begin(); std::string old_ename; + std::string const *old_ename_ptr; while (old_it != nd.end() && new_it != new_totals.end()) { if (old_it->first.size() < 4) { - old_ename = old_it->first; + old_ename_ptr = &old_it->first; } else { indexCh = old_it->first.find("("); if (indexCh != std::string::npos) { - old_ename = old_ename.substr(0, indexCh); + old_ename = old_it->first.substr(0, indexCh); + old_ename_ptr = &old_ename; } else { - old_ename = old_it->first; + old_ename_ptr = &old_it->first; } } - int j = strcmp(new_it->first.c_str(), old_ename.c_str()); + int j = strcmp(new_it->first.c_str(), old_ename_ptr->c_str()); if (j < 0) { new_it++; @@ -407,6 +411,35 @@ cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) std::string redox_name = str; redox_name.append("("); + for (it = this->begin(); it != this->end(); it++) + { + if (str[0] > it->first[0]) continue; + if (it->first == str) + { + // Found exact match + it->second += lg_f; + } + else + { + // no exact match, current is element name, need to find all valences + if (strstr(it->first.c_str(), redox_name.c_str()) == it->first.c_str()) + { + it->second += lg_f; + } + } + if (str[0] < it->first[0]) break; + } +} +#ifdef SKIP +void +cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) +{ + // update original master_activities using just computed factors + cxxNameDouble::iterator it; + LDBLE lg_f = log10(f); + std::string redox_name = str; + redox_name.append("("); + for (it = this->begin(); it != this->end(); it++) { if (it->first == str) @@ -424,6 +457,7 @@ cxxNameDouble::Multiply_activities_redox(std::string str, LDBLE f) } } } +#endif LDBLE cxxNameDouble::Get_total_element(const char *string) const { @@ -539,7 +573,6 @@ cxxNameDouble::merge_redox(const cxxNameDouble & source) // Put in elt name (*this)[elt_name] = sit->second; } - } } struct DblCmp { diff --git a/Solution.cxx b/Solution.cxx index cc891645..f7befd82 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -288,6 +288,350 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con return; } + +#ifdef USE_REVISED_READ_RAW +void +cxxSolution::read_raw(CParser & parser, bool check) +{ + + // Used if it is modify + cxxNameDouble original_totals = this->totals; + cxxNameDouble original_activities(this->master_activity); + + this->master_activity.clear(); + + std::istream::pos_type ptr; + std::istream::pos_type next_char; + std::string token; + int opt_save; + + // Read solution number and description + this->read_number_description(parser.line()); + + opt_save = CParser::OPT_ERROR; + bool tc_defined(false); + bool ph_defined(false); + bool pe_defined(false); + bool mu_defined(false); + bool ah2o_defined(false); + bool total_h_defined(false); + bool total_o_defined(false); + bool cb_defined(false); + bool mass_water_defined(false); + bool total_alkalinity_defined(false); + + for (;;) + { + int opt = parser.get_option(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 SOLUTION_RAW keyword.", + PHRQ_io::OT_CONTINUE); + parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); + continue; + + case 0: // totals + { + cxxNameDouble temp_totals; + if (temp_totals.read_raw(parser, next_char) != CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg("Expected element name and moles for totals.", + PHRQ_io::OT_CONTINUE); + } + else + { + this->totals.merge_redox(temp_totals); + } + } + opt_save = 0; + break; + + case 1: // activities + if (this->master_activity.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected species name and log activity for activities.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 1; + break; + + case 2: // gammas + if (this->species_gamma.read_raw(parser, next_char) != + CParser::PARSER_OK) + { + parser.incr_input_error(); + parser. + error_msg + ("Expected species name and activity coefficient for gammas.", + PHRQ_io::OT_CONTINUE); + } + opt_save = 2; + break; + + case 3: // isotope + { + std::string name; + if (!(parser.get_iss() >> name)) + { + parser.incr_input_error(); + parser.error_msg("Expected character value for isotope name.", + PHRQ_io::OT_CONTINUE); + } + else + { + cxxSolutionIsotope iso(this->Get_io()); + iso.Set_isotope_name(name.c_str()); + iso.read_raw(parser, check); + this->isotopes[name] = iso; + } + } + opt_save = CParser::OPT_DEFAULT; + break; + + case 4: // temp + case 5: // tc_avoid_conflict_with_technetium + case 6: // temperature + if (!(parser.get_iss() >> this->tc)) + { + this->tc = 25.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for temperature.", + PHRQ_io::OT_CONTINUE); + } + tc_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 7: // ph + if (!(parser.get_iss() >> this->ph)) + { + this->ph = 7.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pH.", + PHRQ_io::OT_CONTINUE); + } + ph_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 8: // pe + if (!(parser.get_iss() >> this->pe)) + { + this->pe = 4.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pe.", + PHRQ_io::OT_CONTINUE); + } + pe_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 9: // mu + case 10: // ionic_strength + if (!(parser.get_iss() >> this->mu)) + { + this->mu = 1e-7; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for ionic strength.", + PHRQ_io::OT_CONTINUE); + } + mu_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 11: // ah2o + case 12: // activity_water + if (!(parser.get_iss() >> this->ah2o)) + { + this->ah2o = 1.0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for activity of water.", + PHRQ_io::OT_CONTINUE); + } + ah2o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 13: // total_h + if (!(parser.get_iss() >> this->total_h)) + { + this->total_h = 111.1; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total hydrogen.", + PHRQ_io::OT_CONTINUE); + } + total_h_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 14: // total_o + if (!(parser.get_iss() >> this->total_o)) + { + this->total_o = 55.55; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for total oxygen.", + PHRQ_io::OT_CONTINUE); + } + total_o_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 15: // mass_water + case 16: // mass_h2o + if (!(parser.get_iss() >> this->mass_water)) + { + this->mass_water = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for mass of water.", + PHRQ_io::OT_CONTINUE); + } + mass_water_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 17: // total_alkalinity + case 18: // total_alk + if (!(parser.get_iss() >> this->total_alkalinity)) + { + this->total_alkalinity = 0; + parser.incr_input_error(); + parser. + error_msg("Expected numeric value for total_alkalinity.", + PHRQ_io::OT_CONTINUE); + } + total_alkalinity_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + + case 19: // cb + case 20: // charge_balance + if (!(parser.get_iss() >> this->cb)) + { + this->cb = 0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for charge balance.", + PHRQ_io::OT_CONTINUE); + } + cb_defined = true; + opt_save = CParser::OPT_DEFAULT; + break; + case 21: // density + if (!(parser.get_iss() >> this->density)) + { + this->density = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for density.", + PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; + } + + if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) + break; + } + if (check) + { + // all members must be defined + if (tc_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (ph_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pH not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (pe_defined == false) + { + parser.incr_input_error(); + parser.error_msg("pe not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (mu_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Ionic strength not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (ah2o_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Activity of water not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (total_h_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total hydrogen not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (total_o_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Total oxygen not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (cb_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Charge balance not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (mass_water_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Temp not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (total_alkalinity_defined == false) + { + parser.incr_input_error(); + parser. + error_msg("Total alkalinity not defined for SOLUTION_RAW input.", + PHRQ_io::OT_CONTINUE); + } + } + + // Update activities + + if (original_activities.size() > 0) + { + cxxNameDouble new_activities = this->master_activity; + this->master_activity = original_activities; + this->Update_activities(original_totals); + cxxNameDouble::iterator it = new_activities.begin(); + for ( ; it != new_activities.end(); it++) + { + this->master_activity[it->first] = it->second; + } + } + return; +} +#endif void cxxSolution::read_raw(CParser & parser, bool check) { @@ -641,6 +985,7 @@ cxxSolution::read_raw(CParser & parser, bool check) return; } + void cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &const_nd) { @@ -652,12 +997,13 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->Update(const_nd); } void -cxxSolution::Update(const cxxNameDouble &const_nd) +cxxSolution::Update_activities(const cxxNameDouble &original_tot) { // Totals and activities of solution are updated // nd does not have H, O, charge - cxxNameDouble simple_original = this->totals.Simplify_redox(); - cxxNameDouble simple_new = const_nd.Simplify_redox(); + cxxNameDouble simple_original = original_tot.Simplify_redox(); + // totals after read + cxxNameDouble simple_new = this->totals.Simplify_redox(); // make factors cxxNameDouble factors; @@ -725,15 +1071,84 @@ cxxSolution::Update(const cxxNameDouble &const_nd) } } } +} +void +cxxSolution::Update(const cxxNameDouble &const_nd) +{ + // const_nd is a list of new totals, assumed to be inclusive of all elements + // Totals and activities of solution are updated + // nd does not have H, O, charge + cxxNameDouble simple_original = this->totals.Simplify_redox(); + cxxNameDouble simple_new = const_nd.Simplify_redox(); - // update other totals + cxxNameDouble factors; { - cxxNameDouble::iterator it; - for (it = simple_new.begin(); it != simple_new.end(); it++) + // make factors + cxxNameDouble::iterator it = simple_new.begin(); + cxxNameDouble::iterator jit = simple_original.begin(); + while (it != simple_new.end() && jit != simple_original.end()) { - simple_original[it->first] = it->second; + int j = strcmp(it->first.c_str(), jit->first.c_str()); + if (j < 0) + { + it++; + } + else if (j == 0) + { + if (jit->second != it->second) + { + if (it->second > 0 && jit->second > 0) + { + factors[it->first] = log10(jit->second / it->second); + } + } + it++; + jit++; + } + else + { + jit++; + } + } + + // simple_new now has factors for master activities + // Now add log factors to log activities + { + cxxNameDouble::iterator activity_it = this->master_activity.begin(); + cxxNameDouble::iterator factors_it = factors.begin(); + std::string activity_ename; + std::basic_string < char >::size_type indexCh; + while (activity_it != master_activity.end() && factors_it != factors.end()) + { + activity_ename = activity_it->first; + if (activity_ename.size() > 3) + { + indexCh = activity_ename.find("("); + if (indexCh != std::string::npos) + { + activity_ename = activity_ename.substr(0, indexCh); + } + } + int j = strcmp(factors_it->first.c_str(), activity_ename.c_str()); + if (j < 0) + { + factors_it++; + } + else if (j == 0) + { + activity_it->second += factors_it->second; + activity_it++; + } + else + { + activity_it++; + } + } } } + + // update totals + this->totals = simple_new; } #ifdef SKIP void diff --git a/Solution.h b/Solution.h index fb3f917c..b529728a 100644 --- a/Solution.h +++ b/Solution.h @@ -104,7 +104,7 @@ class cxxSolution:public cxxNumKeyword //void Simplify_totals(); void Update(const cxxNameDouble &nd); void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); - void Update_activities(const cxxNameDouble &old_tot, const cxxNameDouble &new_tot); + void Update_activities(const cxxNameDouble &original_tot); #ifdef USE_MPI void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index c8793882..7a8b2811 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -308,7 +308,7 @@ xsolution_zero(void) ph_x = 0.0; solution_pe_x = 0.0; mu_x = 0.0; - ah2o_x = 1.0; + ah2o_x = 0.0; density_x = 0.0; total_h_x = 0.0; total_o_x = 0.0; From 5e62aeb2465bf31301a438e4bff464a8707363a6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Aug 2012 23:02:55 +0000 Subject: [PATCH 0556/1077] Runs, getting xyz file right, checking results. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6864 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 212 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) diff --git a/ReadClass.cxx b/ReadClass.cxx index d5674080..e097a1f7 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -456,6 +456,217 @@ delete_entities(void) delete_info.SetAll(false); return (OK); } +#ifdef USE_OPTIMIZED_BUT_NOT_MUCH +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +run_as_cells(void) +/* ---------------------------------------------------------------------- */ +{ + struct save save_data; + LDBLE kin_time; + int count_steps, use_mix; + char token[2 * MAX_LENGTH]; + + state = REACTION; + if (run_info.Get_cells().Get_numbers().size() == 0 || + !(run_info.Get_cells().Get_defined())) return(OK); + + // running cells + run_info.Set_run_cells(true); + + dup_print("Beginning of run as cells.", TRUE); + LDBLE initial_total_time_save; + if (run_info.Get_start_time() != NA) + { + initial_total_time_save = run_info.Get_start_time(); + } + else + { + initial_total_time_save = initial_total_time; + } + + std::set < int >::iterator it = run_info.Get_cells().Get_numbers().begin(); + + for ( ; it != run_info.Get_cells().Get_numbers().end(); it++) + { + int i = *it; + if (i < 0) continue; + initial_total_time = initial_total_time_save; + cxxKinetics *kinetics_ptr = NULL; +/* + * Run reaction step + */ + /* + * Find maximum number of steps + */ + dup_print("Beginning of batch-reaction calculations.", TRUE); + count_steps = 1; + if (cxxReaction *rxn_ptr = Utilities::Rxn_find(Rxn_reaction_map, i)) + { + int count = rxn_ptr->Get_reaction_steps(); + if (count > count_steps) + count_steps = count; + } + if (cxxKinetics *rxn_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i)) + { + kinetics_ptr = rxn_ptr; + if (rxn_ptr->Get_reaction_steps() > count_steps) + count_steps = rxn_ptr->Get_reaction_steps(); + } + if (cxxTemperature *rxn_ptr = Utilities::Rxn_find(Rxn_temperature_map, i)) + { + int count = rxn_ptr->Get_countTemps(); + if (count > count_steps) + { + count_steps = count; + } + } + if (cxxPressure *rxn_ptr = Utilities::Rxn_find(Rxn_pressure_map, i)) + { + int count = rxn_ptr->Get_count(); + if (count > count_steps) + { + count_steps = count; + } + } + count_total_steps = count_steps; + if (count_steps > 1) + { + state = ADVECTION; + set_advection(i, TRUE, TRUE, i); + /* + * save data for saving solutions + */ + memcpy(&save_data, &save, sizeof(struct save)); + /* + *Copy everything to -2 + */ + copy_use(-2); + rate_sim_time_start = 0; + rate_sim_time = 0; + for (reaction_step = 1; reaction_step <= count_steps; reaction_step++) + { + sprintf(token, "Reaction step %d.", reaction_step); + if (reaction_step > 1 && incremental_reactions == FALSE) + { + copy_use(-2); + } + set_initial_moles(-2); + dup_print(token, FALSE); + /* + * Determine time step for kinetics + */ + kin_time = 0.0; + if (use.Get_kinetics_in() == TRUE) + { + // runner kin_time + // equivalent to kin_time in count_steps + if (run_info.Get_time_step() != NA) + { + if (incremental_reactions == FALSE) + { + /* not incremental reactions */ + kin_time = reaction_step * run_info.Get_time_step() / ((LDBLE) count_steps); + } + else + { + /* incremental reactions */ + kin_time = run_info.Get_time_step() / ((LDBLE) count_steps); + } + } + // runner kin_time not defined + else + { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); + kin_time = kinetics_ptr->Current_step((incremental_reactions==TRUE), reaction_step); + } + } + if (incremental_reactions == FALSE || + (incremental_reactions == TRUE && reaction_step == 1)) + { + use_mix = TRUE; + } + else + { + use_mix = FALSE; + } + /* + * Run reaction step + */ + run_reactions(-2, kin_time, use_mix, 1.0); + if (incremental_reactions == TRUE) + { + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start; + } + else + { + rate_sim_time = kin_time; + } + punch_all(); + print_all(); + /* saves back into -2 */ + if (reaction_step < count_steps) + { + saver(); + } + } + /* + * save end of reaction + */ + memcpy(&save, &save_data, sizeof(struct save)); + if (use.Get_kinetics_in() == TRUE) + { + Utilities::Rxn_copy(Rxn_kinetics_map, -2, use.Get_n_kinetics_user()); + } + saver(); + } + else + // only 1 step, no worries about incremental reactions + { + state = TRANSPORT; + + rate_sim_time_start = 0; + rate_sim_time = 0; + reaction_step = 1; + + sprintf(token, "Reaction step %d.", reaction_step); + + dup_print(token, FALSE); + /* + * Determine time step for kinetics + */ + kin_time = 0.0; + if (kinetics_ptr) + { + // runner kin_time + // equivalent to kin_time in count_steps + if (run_info.Get_time_step() != NA) + { + kin_time = run_info.Get_time_step(); + } + // runner kin_time not defined + else + { + kin_time = kinetics_ptr->Get_steps()[0]; + } + } + /* + * Run reaction step + */ + use_mix = TRUE; + run_reactions(i, kin_time, use_mix, 1.0); + rate_sim_time = kin_time; + saver(); + } + } + initial_total_time += rate_sim_time; + run_info.Get_cells().Set_defined(false); + // not running cells + run_info.Set_run_cells(false); + return (OK); +} +#else /* ---------------------------------------------------------------------- */ int Phreeqc:: run_as_cells(void) @@ -624,6 +835,7 @@ run_as_cells(void) run_info.Set_run_cells(false); return (OK); } +#endif /* ---------------------------------------------------------------------- */ void Phreeqc:: dump_ostream(std::ostream& os) From fb36b693389787f40d0f8fb8c356783d6b8155c0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 Aug 2012 02:02:22 +0000 Subject: [PATCH 0557/1077] Deleted dead code in reaction module. Started implementing HDF. Runs to initial phreeqc and crashes on writing dummy selected output. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6868 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/PHRQ_io_output.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index 7d3a2c53..fbb909a5 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -59,10 +59,10 @@ get_forward_output_to_log(void) return forward_output_to_log; } -#if defined(HDF5_CREATE) -extern void HDFWriteHyperSlabV(const char *name, const char *format, - va_list argptr); -#endif +//#if defined(HDF5_CREATE) +//extern void HDFWriteHyperSlabV(const char *name, const char *format, +// va_list argptr); +//#endif void Phreeqc:: fpunchf_heading(const char *name) From d96dc80f27ab3de5d1f7f304faf27fe35463b1a5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Aug 2012 15:11:11 +0000 Subject: [PATCH 0558/1077] Runs ex4 correctly. Think all output, including hdf is correct. Skipped updating activities. OK? git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6872 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index f7befd82..2d42458e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -994,7 +994,9 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->total_o = o_tot; this->cb = charge; - this->Update(const_nd); + // Don't bother to update activities? + //this->Update(const_nd); + this->totals = const_nd; } void cxxSolution::Update_activities(const cxxNameDouble &original_tot) @@ -1099,7 +1101,7 @@ cxxSolution::Update(const cxxNameDouble &const_nd) { if (it->second > 0 && jit->second > 0) { - factors[it->first] = log10(jit->second / it->second); + factors[it->first] = log10(it->second / jit->second); } } it++; @@ -1110,7 +1112,6 @@ cxxSolution::Update(const cxxNameDouble &const_nd) jit++; } } - // simple_new now has factors for master activities // Now add log factors to log activities { @@ -1121,6 +1122,16 @@ cxxSolution::Update(const cxxNameDouble &const_nd) while (activity_it != master_activity.end() && factors_it != factors.end()) { activity_ename = activity_it->first; + if (factors_it->first[0] < activity_ename[0]) + { + factors_it++; + continue; + } + else if (factors_it->first[0] > activity_ename[0]) + { + activity_it++; + continue; + } if (activity_ename.size() > 3) { indexCh = activity_ename.find("("); From c352283a9fa735e7dc1f1889562e126652e7cd2d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Aug 2012 20:42:51 +0000 Subject: [PATCH 0559/1077] Updated to Tony's latest. Amm.dat and Pitzer.dat have extra terms. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6897 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/global_structures.h | 2 +- phreeqc/prep.cpp | 66 +++++++++++++++++++++++-------------- phreeqc/read.cpp | 9 ++--- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index 77cdc543..fb52f070 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -172,7 +172,7 @@ typedef enum { vma1, vma2, vma3, vma4, /* read: a1..a4 from supcrt, see calc_vm */ wref, /* from supcrt */ b_Av, /* b in z^2 * A_v * log(1 + b * I^0.5) / (2 * b) */ - vmi1, vmi2, vmi3, /* ionic strength terms: (i1 + i2/(TK - 228) + i3(TK)) * I. i3 not used */ + vmi1, vmi2, vmi3, vmi4, /* ionic strength terms: (i1 + i2/(TK - 228) + i3 * (TK - 228) ) * I^i4 */ MAX_LOG_K_INDICES /* Keep this definition at the end of the enum */ } LOG_K_INDICES; /* HSEARCH(3C) */ diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index d263a283..ad2b0fd6 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -5657,7 +5657,8 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) if (!r_ptr->logk[vm0]) // in case Vm of the phase is 0... return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); - LDBLE tc = TK - 273.15, pb = pa * 1.01325; + LDBLE tc = TK - 273.15; + LDBLE pb_s = 2600. + pa * 1.01325, TK_s = tc + 45.15, sqrt_mu = sqrt(mu_x); LDBLE d_v = 0.0; species * s_ptr; @@ -5679,8 +5680,9 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) { /* supcrt volume at I = 0... */ d_v += r_ptr->token[i].coef * - (s_ptr->logk[vma1] + s_ptr->logk[vma2] / (2600. + pb) + - s_ptr->logk[vma3] / (TK - 228.) + s_ptr->logk[vma2] / (2600. + pb) / (TK - 228.)); + (s_ptr->logk[vma1] + s_ptr->logk[vma2] / pb_s + + (s_ptr->logk[vma3] + s_ptr->logk[vma4] / pb_s) / TK_s - + s_ptr->logk[wref] * QBrn); //if (dgdP && s_ptr->z) //{ // LDBLE re = s_ptr->z * s_ptr->z / (s_ptr->logk[wref] / 1.66027e5 + s_ptr->z / 3.082); @@ -5688,20 +5690,25 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) // d_v += r_ptr->token[i].coef * ZBrn * 1.66027e5 * Z3 * dgdP; //} if (s_ptr->z) - { + { /* the ionic strength term * I^0.5... */ - if (s_ptr->logk[b_Av] == 0) - d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt(mu_x); + if (s_ptr->logk[b_Av] < 1e-5) + d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt_mu; else { /* limit the Debye-Hueckel slope by b... */ - LDBLE b = (s_ptr->logk[b_Av] < 1e-5 ? 1e-5 : s_ptr->logk[b_Av]); d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * - log(1 + b * sqrt(mu_x)) / b; + sqrt_mu / (1 + s_ptr->logk[b_Av] * DH_B * sqrt_mu); } /* plus the volume terms * I... */ - LDBLE bi = s_ptr->logk[vmi1] + s_ptr->logk[vmi2] / (TK - 228.); // + s_x[i]->logk[vmi3] * TK); - d_v += bi * mu_x; + if (s_ptr->logk[vmi1] != 0.0 || s_ptr->logk[vmi2] != 0.0 || s_ptr->logk[vmi3] != 0.0) + { + LDBLE bi = s_ptr->logk[vmi1] + s_ptr->logk[vmi2] / TK_s + s_ptr->logk[vmi3] * TK_s; + if (s_ptr->logk[vmi4] == 1.0) + d_v += bi * mu_x; + else + d_v += bi * pow(mu_x, s_ptr->logk[vmi4]); + } } } else if (s_x[i]->millero[0]) @@ -5711,7 +5718,7 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) if (s_ptr->z) { /* the ionic strength terms... */ - d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt(mu_x) + + d_v += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt_mu + (s_ptr->millero[3] + tc * (s_ptr->millero[4] + tc * s_ptr->millero[5])) * mu_x; } } @@ -5733,15 +5740,17 @@ calc_vm(LDBLE tc, LDBLE pa) { /* * Calculate molar volumes for aqueous species with a Redlich type eqn: - Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I. + Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I^(b4). * Vm0(tc) is calc'd using supcrt parms, or from millero[0] + millero[1] * tc + millero[2] * tc^2 * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. - Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av from calc_dielectrics(tc, pa). - if b_Av != 0, I^0.5 is constrained to ln(1 + b_Av * I^0.5) / b_Av. - * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228), or + Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av. + If b_Av != 0, the extended DH formula is used: I^0.5 /(1 + b_Av * DH_B * I^0.5). + DH_Av and DH_B are from calc_dielectrics(tc, pa). + * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228) + logk[vmi3] * (TK - 228). + * b4 = logk[vmi4], or * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 */ - LDBLE pb = pa * 1.01325, TK = tc + 273.15; + LDBLE pb_s = 2600. + pa * 1.01325, TK_s = tc + 45.15, sqrt_mu = sqrt(mu_x); for (int i = 0; i < count_s_x; i++) { if (!strcmp(s_x[i]->name, "H2O")) @@ -5752,8 +5761,8 @@ calc_vm(LDBLE tc, LDBLE pa) if (s_x[i]->logk[vma1]) { /* supcrt volume at I = 0... */ - s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vma1] + s_x[i]->logk[vma2] / (2600. + pb) + - s_x[i]->logk[vma3] / (TK - 228.) + s_x[i]->logk[vma4] / (2600. + pb) / (TK - 228.) - + s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vma1] + s_x[i]->logk[vma2] / pb_s + + (s_x[i]->logk[vma3] + s_x[i]->logk[vma4] / pb_s) / TK_s - s_x[i]->logk[wref] * QBrn; /* A (small) correction by Shock et al., 1992, for 155 < tc < 255, P_sat < P < 1e3. The vma1..a4 and wref numbers are refitted for major cations and anions on xpts, @@ -5768,18 +5777,27 @@ calc_vm(LDBLE tc, LDBLE pa) { /* the ionic strength term * I^0.5... */ if (s_x[i]->logk[b_Av] < 1e-5) - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x); + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt_mu; else { /* limit the Debye-Hueckel slope by b... */ + /* pitzer... */ + //s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * + // log(1 + s_x[i]->logk[b_Av] * sqrt(mu_x)) / s_x[i]->logk[b_Av]; + /* extended DH... */ s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * - log(1 + s_x[i]->logk[b_Av] * sqrt(mu_x)) / s_x[i]->logk[b_Av]; + sqrt_mu / (1 + s_x[i]->logk[b_Av] * DH_B * sqrt_mu); } /* plus the volume terms * I... */ - LDBLE bi = s_x[i]->logk[vmi1] + s_x[i]->logk[vmi2] / (TK - 228.); // + s_x[i]->logk[vmi3] * TK); - s_x[i]->rxn_x->logk[vm_tc] += bi * mu_x; + if (s_x[i]->logk[vmi1] != 0.0 || s_x[i]->logk[vmi2] != 0.0 || s_x[i]->logk[vmi3] != 0.0) + { + LDBLE bi = s_x[i]->logk[vmi1] + s_x[i]->logk[vmi2] / TK_s + s_x[i]->logk[vmi3] * TK_s; + if (s_x[i]->logk[vmi4] == 1.0) + s_x[i]->rxn_x->logk[vm_tc] += bi * mu_x; + else + s_x[i]->rxn_x->logk[vm_tc] += bi * pow(mu_x, s_x[i]->logk[vmi4]); + } } - // perhaps, add a term for neutral species * tot molality... } else if (s_x[i]->millero[0]) { @@ -5788,7 +5806,7 @@ calc_vm(LDBLE tc, LDBLE pa) if (s_x[i]->z) { /* the ionic strength terms... */ - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt(mu_x) + + s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * 0.5 * DH_Av * sqrt_mu + (s_x[i]->millero[3] + tc * (s_x[i]->millero[4] + tc * s_x[i]->millero[5])) * mu_x; } } diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index f46ada85..8177dadc 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -2816,15 +2816,16 @@ read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) { delta_v[j] = 0.0; } - j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + delta_v[9] = 1.0; + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, /* a1..a4 */ &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3]), /* wref */ &(delta_v[4]), /* b_Av */ &(delta_v[5]), - /* c1..c3 */ - &(delta_v[6]), &(delta_v[7]), &(delta_v[8])); + /* c1..c4 */ + &(delta_v[6]), &(delta_v[7]), &(delta_v[8]), &(delta_v[9])); if (j < 1) { input_error++; @@ -5012,7 +5013,7 @@ read_selected_output(void) case 44: /* selected_out */ case 45: /* selected_output */ warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); - //pr.punch = get_true_false(next_char, TRUE); + pr.punch = get_true_false(next_char, TRUE); opt_save = OPTION_ERROR; break; } From 3b42a98f5c11dbd7d4658db84ab4977a03c4dea1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Aug 2012 23:50:33 +0000 Subject: [PATCH 0560/1077] (int) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6909 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/inverse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index 01c1b19f..a9d458c2 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -3964,7 +3964,7 @@ dump_netpath(struct inverse *inverse_ptr) /* total number of wells */ fprintf(netpath_file, "%15d # Total wells\n", - Rxn_solution_map.size()); + (int) Rxn_solution_map.size()); /* address */ fprintf(netpath_file, From e1ef00c519a241d84d310d335478557c0a1acdd6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Aug 2012 14:21:47 +0000 Subject: [PATCH 0561/1077] Tony's changes for dates git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6923 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 16 ++++++++++++---- phreeqc/PHRQ_io_output.cpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index bfdcfdb6..0c9083a0 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -14,7 +14,7 @@ /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ -int +int main(int argc, char *argv[]) /* * Main program for PHREEQC @@ -40,7 +40,7 @@ main(int argc, char *argv[]) #endif #ifdef SKIP //Set the x86 floating-point control word according to what -//exceptions you want to trap. +//exceptions you want to trap. _clearfp(); //Always call _clearfp before setting the control //word //Because the second parameter in the following call is 0, it @@ -52,9 +52,9 @@ unsigned int cw = _controlfp(0, 0); //Get the default control //exception is //blocked from being generating. cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE| EM_DENORMAL|EM_INVALID); -//For any bit in the second parameter (mask) that is 1, the +//For any bit in the second parameter (mask) that is 1, the //corresponding bit in the first parameter is used to update -//the control word. +//the control word. unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. //MCW_EM is defined in float.h. //Restore the original value when done: @@ -160,7 +160,11 @@ write_banner(void) " º º\n"); /* version */ +#ifdef NPP + len = sprintf(buffer, "* PHREEQC-%s *", "3.beta"); +#else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); +#endif indent = (44 - len) / 2; screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' ')); @@ -180,7 +184,11 @@ write_banner(void) /* date */ +#ifdef NPP + len = sprintf(buffer, "%s", "July 19, 2012"); +#else len = sprintf(buffer, "%s", "@VER_DATE@"); +#endif indent = (44 - len) / 2; screen_msg(sformatf("%14cº%*c%s%*cº\n", ' ', indent, ' ', buffer, 44 - indent - len, ' ')); diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index fbb909a5..40e84a89 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -321,7 +321,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.beta, compiled on May 22, 2012\n")); + output_msg(sformatf("Using PHREEQC: version 3.beta, compiled on August 6, 2012\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); From 3503962fd4ff0816dbfca381ffc32d5859f00d9a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 28 Aug 2012 15:07:28 +0000 Subject: [PATCH 0562/1077] bug with saturaation curve pressure. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6924 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index e0dbc3b6..7f500e5c 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -3615,10 +3615,10 @@ reset(void) (double) patm_x)); } patm_x = gas_phase_ptr->Get_total_p(); - if (patm_x < 1e-10 && patm_x < p_sat) - { - patm_x = ( 1 * patm_x + p_sat) / 2.0; - } + //if (patm_x < 1e-10 && patm_x < p_sat) + //{ + // patm_x = ( 1 * patm_x + p_sat) / 2.0; + //} if (patm_x > 1500) patm_x = 1500; } From 83f7c0c49a748b30be968d78b35c983366a5e5b7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Aug 2012 00:04:09 +0000 Subject: [PATCH 0563/1077] Adjusted convergence for small numbers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6931 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 7f500e5c..e8654f9f 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -296,7 +296,7 @@ check_residuals(void) { if (x[i]->type == MB || x[i]->type == ALK) { - if (fabs(residual[i]) >= epsilon * x[i]->moles && fabs(residual[i]) > MIN_TOTAL + if (fabs(residual[i]) >= epsilon * x[i]->moles && fabs(residual[i]) > sqrt(fabs(x[i]->moles) * MIN_TOTAL) && x[i]->moles > MIN_TOTAL /* || stop_program == TRUE */ ) { error_string = sformatf( @@ -3729,8 +3729,11 @@ residuals(void) if (x[i]->type == MB) { residual[i] = x[i]->moles - x[i]->f; - if ((fabs(residual[i]) > l_toler * x[i]->moles && fabs(residual[i]) > MIN_TOTAL - && x[i]->moles > MIN_TOTAL) || x[i]->moles < 0) + if ((fabs(residual[i]) > l_toler * x[i]->moles && + fabs(residual[i]) > sqrt(fabs(x[i]->moles) * MIN_TOTAL) && + x[i]->moles > MIN_TOTAL) + || + x[i]->moles < 0) { if (print_fail) output_msg(sformatf( From 475cf8f1a058ed2401a821ef0a34ae797a52c7c8 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 30 Aug 2012 22:28:13 +0000 Subject: [PATCH 0564/1077] added some (parse_all) logic to avoid crashes in phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6944 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index a36e06ba..0e51b783 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2779,11 +2779,11 @@ factor(struct LOC_exec * LINK) } else if (PhreeqcPtr->state == TRANSPORT) { - n.UU.val = PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; } else if (PhreeqcPtr->state == ADVECTION) { - n.UU.val = (LDBLE) PhreeqcPtr->use.Get_n_solution_user(); + n.UU.val = (parse_all) ? 1 : (LDBLE) PhreeqcPtr->use.Get_n_solution_user(); } else { @@ -2843,6 +2843,11 @@ factor(struct LOC_exec * LINK) break; case tokcell_no: + if (parse_all) + { + n.UU.val = 1; + break; + } if (PhreeqcPtr->state == TRANSPORT) { n.UU.val = PhreeqcPtr->cell_no; @@ -2870,7 +2875,6 @@ factor(struct LOC_exec * LINK) n.UU.val = PhreeqcPtr->use.Get_n_solution_user(); } } - if (parse_all) n.UU.val = 1; break; case toksim_no: From d0d48fca3a8242aaa4ebce4db522064308f87955 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 30 Aug 2012 22:29:09 +0000 Subject: [PATCH 0565/1077] added additional initializing code to g_spread_sheet git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6945 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/spread.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index ad370ffc..23a33c63 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -1241,6 +1241,7 @@ free_spread(void) (const char *)free_check_null((void*)g_spread_sheet.defaults.units); g_spread_sheet.heading = 0; + g_spread_sheet.units = 0; g_spread_sheet.count_rows = 0; g_spread_sheet.defaults.count_iso = 0; } @@ -1337,6 +1338,7 @@ copy_defaults(struct defaults *dest_ptr, struct defaults *src_ptr) dest_ptr->temp = src_ptr->temp; dest_ptr->units = string_duplicate(src_ptr->units); dest_ptr->water = src_ptr->water; + dest_ptr->pressure = src_ptr->pressure; } #endif From 4c2e8c33c0ea85b64914b62158af6f43bcbe308a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 12 Sep 2012 15:46:31 +0000 Subject: [PATCH 0566/1077] Modified to tidy exchange, gas_phase, ppassemblage, solution, ssassemblage, and surface when _raw or _modify are read. Set new_def for each. Had problem with equilibrium_phases as shown in eq_phase_mod test case. Probably will add amdtreat test case from which it was derived. Tony revised density calculation. Toyed with the following when testing for amdtreat in Copy equations to optimize into ineq_array //if (x[i]->f > 1e-14/*0e-8*/ && x[i]->moles <= 0 checked for a null pointer in prep (could happen when _modify used). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6967 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 2 +- GasPhase.cxx | 1 + PPassemblage.cxx | 1 + SSassemblage.cxx | 1 + Solution.cxx | 1 + Surface.cxx | 1 + phreeqc/basicsubs.cpp | 16 +++++++++------- phreeqc/model.cpp | 1 + phreeqc/prep.cpp | 7 +++++++ phreeqc/tidy.cpp | 24 ++++++++++++------------ 10 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 35a6a3e1..f7bda656 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -205,7 +205,7 @@ cxxExchange::read_raw(CParser & parser, bool check) // Read exchange number and description this->read_number_description(parser); - + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; bool pitzer_exchange_gammas_defined(false); diff --git a/GasPhase.cxx b/GasPhase.cxx index c4af6d8d..0519a2b2 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -282,6 +282,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) // Read gas_phase number and description this->read_number_description(parser); + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; bool type_defined(false); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index fec0a180..b11b9ff7 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -134,6 +134,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) // Read PPassemblage number and description this->read_number_description(parser); + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 4c554b98..cc0c194a 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -136,6 +136,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) // Read SSassemblage number and description this->read_number_description(parser); + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; diff --git a/Solution.cxx b/Solution.cxx index 2d42458e..a3640bc9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -307,6 +307,7 @@ cxxSolution::read_raw(CParser & parser, bool check) // Read solution number and description this->read_number_description(parser.line()); + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; bool tc_defined(false); diff --git a/Surface.cxx b/Surface.cxx index f730d36b..c97bf194 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -243,6 +243,7 @@ cxxSurface::read_raw(CParser & parser, bool check) // Read surface number and description this->read_number_description(parser); + this->Set_new_def(true); opt_save = CParser::OPT_ERROR; bool only_counter_ions_defined(false); diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 552b2afb..796cc327 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -298,7 +298,7 @@ calc_dens(void) * volume 6, pages 1-17 */ int i; - LDBLE M_T, rho_new, gfw; + LDBLE M_T, /*rho_new,*/ gfw; /* 2 options: original VP, assign the volumes of species with zero molar volume to their master species, but this doubles counts of complexes with -Vm defined. And, cation-OH and H-anion complexes are counted once. Also, must add H+ and OH-... */ @@ -364,15 +364,17 @@ calc_dens(void) /* If pure water then return rho_0 */ if (M_T == 0) return rho_0; + else + return rho_0 * (1e3 + M_T / mass_water_aq_x) / (rho_0 * V_solutes / mass_water_aq_x + 1e3); - M_T /= 1e3; - solution_mass = mass_water_aq_x + M_T; - V_solutes = M_T - rho_0 * V_solutes / 1e3; + //M_T /= 1e3; + //solution_mass = mass_water_aq_x + M_T; + //V_solutes = M_T - rho_0 * V_solutes / 1e3; - rho_new = halve(f_rho, 0.5, 2.0, 1e-7); - if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999; + //rho_new = halve(f_rho, 0.5, 2.0, 1e-7); + //if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999; - return rho_new; + //return rho_new; } /* VP: Density End */ /* DP: Function for interval halving */ diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index e8654f9f..f627f68f 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -1193,6 +1193,7 @@ ineq(int in_kode) if (it->second.Get_force_equality()) continue; /* Undersaturated and no mass, ignore */ + //if (x[i]->f > 1e-14/*0e-8*/ && x[i]->moles <= 0 if (x[i]->f > 0e-8 && x[i]->moles <= 0 && it->second.Get_add_formula().size() == 0) { diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index ad2b0fd6..49ff658d 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -1518,6 +1518,13 @@ build_pure_phases(void) else { master_ptr = elt_list[j].elt->primary; + if (master_ptr == NULL) + { + error_string = sformatf( + "Element undefined, %s.", + elt_list[j].elt->name); + error_msg(error_string, STOP); + } if (master_ptr->in == FALSE) { master_ptr = master_ptr->s->secondary; diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index cfeaeba9..6f2ac225 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -60,21 +60,21 @@ tidy_model(void) { new_model = TRUE; } - if (keycount[Keywords::KEY_EQUILIBRIUM_PHASES] > 0 /*|| + if (keycount[Keywords::KEY_EQUILIBRIUM_PHASES] > 0 || keycount[Keywords::KEY_EQUILIBRIUM_PHASES_RAW] > 0 || - keycount[Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY]*/) + keycount[Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY]) { new_pp_assemblage = TRUE; /*"pure_phases" */ } - if (keycount[Keywords::KEY_SURFACE] > 0 /*|| + if (keycount[Keywords::KEY_SURFACE] > 0 || keycount[Keywords::KEY_SURFACE_RAW] > 0 || - keycount[Keywords::KEY_SURFACE_MODIFY]*/) + keycount[Keywords::KEY_SURFACE_MODIFY]) { new_surface = TRUE; /*"surface" */ } - if (keycount[Keywords::KEY_EXCHANGE] > 0 /*|| + if (keycount[Keywords::KEY_EXCHANGE] > 0 || keycount[Keywords::KEY_EXCHANGE_RAW] > 0 || - keycount[Keywords::KEY_EXCHANGE_MODIFY]*/) + keycount[Keywords::KEY_EXCHANGE_MODIFY]) { new_exchange = TRUE; /*"exchange" */ } @@ -96,21 +96,21 @@ tidy_model(void) new_mix = TRUE; /*"mix" */ } if (keycount[Keywords::KEY_SOLUTION] > 0 || - keycount[Keywords::KEY_SOLUTION_SPREAD] > 0 /*|| + keycount[Keywords::KEY_SOLUTION_SPREAD] > 0 || keycount[Keywords::KEY_SOLUTION_RAW] > 0 || - keycount[Keywords::KEY_SOLUTION_MODIFY]*/) + keycount[Keywords::KEY_SOLUTION_MODIFY]) { /*"solution" */ new_solution = TRUE; } - if (keycount[Keywords::KEY_GAS_PHASE] > 0 /*|| + if (keycount[Keywords::KEY_GAS_PHASE] > 0 || keycount[Keywords::KEY_GAS_PHASE_RAW] > 0 || - keycount[Keywords::KEY_GAS_PHASE_MODIFY]*/) + keycount[Keywords::KEY_GAS_PHASE_MODIFY]) { new_gas_phase = TRUE; /*"gas_phase" */ } - if (keycount[Keywords::KEY_SOLID_SOLUTIONS] > 0 /*|| + if (keycount[Keywords::KEY_SOLID_SOLUTIONS] > 0 || keycount[Keywords::KEY_SOLID_SOLUTIONS_RAW] > 0 || - keycount[Keywords::KEY_SOLID_SOLUTIONS_MODIFY]*/) + keycount[Keywords::KEY_SOLID_SOLUTIONS_MODIFY]) { new_ss_assemblage = TRUE; /*"solid_solutions" */ } From d13ffaa60cc89b16009ec048026b82480042e272 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 25 Sep 2012 19:52:32 +0000 Subject: [PATCH 0567/1077] Fixed Dieke's Viet Nam problem, la was limited to -300, now can go lower. Added test problem DanPhuong and database LangmuirAs_wateq4f.dat git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6979 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index f627f68f..1faa15e6 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -3329,8 +3329,8 @@ reset(void) "delta", (double) delta[i], "delta/c", (double) d)); } x[i]->master[0]->s->la += d; - if (x[i]->master[0]->s->la < (double) (DBL_MIN_10_EXP + 10)) - x[i]->master[0]->s->la = (double) (DBL_MIN_10_EXP + 10); + //if (x[i]->master[0]->s->la < (double) (DBL_MIN_10_EXP + 10)) + // x[i]->master[0]->s->la = (double) (DBL_MIN_10_EXP + 10); /* * Surface charge balance From 03d70eeb53d9fe910c27777e2b53f053231f1032 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 2 Oct 2012 18:40:10 +0000 Subject: [PATCH 0568/1077] Set pr.headings true in class_main.cpp pr.headings not reset in do_status. pr.headings not changed for IPhreeqc call to do_status. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7002 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 1 + phreeqc/mainsubs.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/class_main.cpp b/class_main.cpp index 0c9083a0..ad3f5cbc 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -139,6 +139,7 @@ main_method(int argc, char *argv[]) /* * Display successful status */ + pr.headings = TRUE; errors = do_status(); if (errors != 0) { diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 87fe29b6..f0a658c9 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2760,7 +2760,7 @@ do_status(void) status(0, "\nDone."); screen_msg("\n"); } - pr.headings = TRUE; + //pr.headings = TRUE; // set in class_main; not set for IPhreeqc LDBLE ext = (double) clock() / CLOCKS_PER_SEC; dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE); screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext)); From e3638b346c200678a2b90afb733a7ee1f617a1e7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 11 Oct 2012 00:39:07 +0000 Subject: [PATCH 0569/1077] Revised phreeqc constructor, init, and initialize. All data members are now initialized in init. Almost all allocation is in initialize. There is a little bit of duplication in initialize, but not much. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7005 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 956 ++++++++++++++++++++++++++++++++++++++++++- Phreeqc.h | 60 ++- phreeqc/gases.cpp | 1 - phreeqc/kinetics.cpp | 1 - phreeqc/mainsubs.cpp | 313 +++++++++++++- phreeqc/model.cpp | 8 +- 6 files changed, 1294 insertions(+), 45 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 7253df6c..18213e2f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -29,7 +29,7 @@ const struct const_iso Phreeqc::iso_defaults[] = { }; const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso)); - +#ifdef SKIP Phreeqc::Phreeqc(PHRQ_io *io) { if (io) @@ -120,7 +120,7 @@ Phreeqc::Phreeqc(PHRQ_io *io) init(); } - +#endif Phreeqc::~Phreeqc(void) { @@ -259,6 +259,7 @@ size_t Phreeqc::list_components(std::list &list_c) } return(list_c.size()); } +#ifdef SKIP void Phreeqc::init(void) { int i; @@ -822,3 +823,954 @@ void Phreeqc::init(void) return; } +#endif +Phreeqc::Phreeqc(PHRQ_io *io) +{ + // phrq_io + if (io) + { + this->phrq_io = io; + } + else + { + this->phrq_io = &this->ioInstance; + } + // auto PHRQ_io ioInstance; + + // initialize data members + init(); +} +void Phreeqc::init(void) +{ + same_model = FALSE; + current_tc = NAN; + current_pa = NAN; + current_mu = NAN; + mu_terms_in_logk = true; + + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ +/* + * last model + */ + last_model.force_prep = TRUE; + last_model.temperature = -100; + last_model.pressure = 0; + last_model.count_exchange = -1; + last_model.exchange = NULL; + last_model.count_kinetics = -1; + last_model.kinetics = NULL; + last_model.count_gas_phase = -1; + last_model.gas_phase = NULL; + last_model.count_ss_assemblage = -1; + last_model.ss_assemblage = NULL; + last_model.count_pp_assemblage = -1; + last_model.pp_assemblage = NULL; + last_model.add_formula = NULL; + last_model.si = NULL; + last_model.dl_type = cxxSurface::NO_DL; + last_model.surface_type = cxxSurface::UNKNOWN_DL; + last_model.only_counter_ions = FALSE; + last_model.thickness = 1e-8; + last_model.count_surface_comp = -1; + last_model.surface_comp = NULL; + last_model.count_surface_charge = -1; + last_model.surface_charge = NULL; + + //struct punch punch; +/* + * Initialize punch + */ + punch.in = FALSE; + punch.count_totals = 0; + punch.totals = 0; + punch.count_molalities = 0; + punch.molalities = 0; + punch.count_activities = 0; + punch.activities = 0; + punch.count_pure_phases = 0; + punch.pure_phases = 0; + punch.count_si = 0; + punch.si = 0; + punch.count_gases = 0; + punch.gases = 0; + punch.count_s_s = 0; + punch.s_s = 0; + punch.count_kinetics = 0; + punch.kinetics = 0; + punch.count_isotopes = 0; + punch.isotopes = 0; + punch.count_calculate_values = 0; + punch.calculate_values = 0; + punch.inverse = TRUE; + punch.sim = TRUE; + punch.state = TRUE; + punch.soln = TRUE; + punch.dist = TRUE; + punch.time = TRUE; + punch.step = TRUE; + punch.rxn = FALSE; + punch.temp = FALSE; + punch.ph = TRUE; + punch.pe = TRUE; + punch.alk = FALSE; + punch.mu = FALSE; + punch.water = FALSE; + punch.high_precision = FALSE; + punch.user_punch = TRUE; + punch.charge_balance = FALSE; + punch.percent_error = FALSE; + + // auto Rxn_temperature_map; + // auto Rxn_pressure_map; + + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + g_iterations = -1; + G_TOL = 1e-8; + // auto Rxn_surface_map; + // auto charge_group_map; + change_surf_count = 0; + change_surf = NULL; + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + // auto Rxn_exchange_map; + + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + // auto Rxn_kinetics_map; + + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + count_save_values = 0; + save_values = NULL; + save_init(-1); // set initial save values + + // auto use + + // copier structures + copy_solution.n_user = copy_solution.start = copy_solution.end = 0; + copy_solution.count = copy_solution.max = 0; + copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; + copy_pp_assemblage.count = copy_pp_assemblage.max = 0; + copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; + copy_exchange.count = copy_exchange.max = 0; + copy_surface.n_user = copy_surface.start = copy_surface.end = 0; + copy_surface.count = copy_surface.max = 0; + copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0; + copy_ss_assemblage.count = copy_ss_assemblage.max = 0; + copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; + copy_gas_phase.count = copy_gas_phase.max = 0; + copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; + copy_kinetics.count = copy_kinetics.max = 0; + copy_mix.n_user = copy_mix.start = copy_mix.end = 0; + copy_mix.count = copy_mix.max = 0; + copy_reaction.n_user = copy_reaction.start = copy_reaction.end = 0; + copy_reaction.count = copy_reaction.max = 0; + copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; + copy_temperature.count = copy_temperature.max = 0; + copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0; + copy_pressure.count = copy_pressure.max = 0; + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + inverse = NULL; + count_inverse = 0; + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + // auto Rxn_mix_map; + // auto Dispersion_mix_map; + // auto Rxn_solution_mix_map; + // auto Rxn_exchange_mix_map; + // auto Rxn_gas_phase_mix_map; + // auto Rxn_kinetics_mix_map; + // auto Rxn_pp_assemblage_mix_map; + // auto Rxn_ss_assemblage_mix_map; + // auto Rxn_surface_mix_map; + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + // auto Rxn_reaction_map; + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + // auto Rxn_gas_phase_map; + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + // auto Rxn_ss_assemblage_map; + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + // auto Rxn_pp_assemblage_map; + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + count_species_list = 0; + max_species_list = 0; + species_list = NULL; + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + count_sum_jacob0 = 0; + max_sum_jacob0 = 0; + sum_jacob0 = NULL; + count_sum_mb1 = 0; + max_sum_mb1 = 0; + sum_mb1 = NULL; + count_sum_jacob1 = 0; + max_sum_jacob1 = 0; + sum_jacob1 = NULL; + count_sum_mb2 = 0; + max_sum_mb2 = 0; + sum_mb2 = NULL; + count_sum_jacob2 = 0; + max_sum_jacob2 = 0; + sum_jacob2 = NULL; + count_sum_delta = 0; + max_sum_delta = 0; + sum_delta = NULL; + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + // auto Rxn_solution_map; + // auto unnumbered_solutions; + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + title_x = NULL; + new_x = FALSE; + description_x = NULL; + tc_x = 0; + tk_x = 0; + patm_x = 1; + last_patm_x = 1; + numerical_fixed_volume = false; + force_numerical_fixed_volume = false; + switch_numerical = false; + ph_x = 0; + solution_pe_x = 0; + mu_x = 0; + ah2o_x = 1.0; + density_x = 0; + total_h_x = 0; + total_o_x = 0; + cb_x = 0; + total_ions_x = 0; + mass_water_aq_x = 0; + mass_water_surfaces_x = 0; + mass_water_bulk_x = 0; + units_x = NULL; + // auto pe_x + // auto isotopes_x + // auto default_pe_x + dl_type_x = cxxSurface::NO_DL; + total_carbon = 0; + total_co2 = 0; + total_alkalinity = 0; + gfw_water = 0; + step_x = 0; + kin_time_x = 0; + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + correct_disp = FALSE; + tempr = 2.0; + timest = 0.0; + simul_tr = 0; + diffc = 0.3e-9; + heat_diffc = -0.1; + cell = 0; + mcd_substeps = 1.0; + stag_data = NULL; + print_modulus = 1; + punch_modulus = 1; + dump_in = FALSE; + dump_modulus = 0; + transport_warnings = TRUE; + cell_data = FALSE; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + default_Dw = 0; + multi_Dpor = 0; + interlayer_Dpor = 0.1; + multi_Dpor_lim = 0; + interlayer_Dpor_lim = 0; + multi_Dn = 0; + interlayer_tortf = 100.0; + cell_no = 0; + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + advection_punch = NULL; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = NULL; + advection_warnings = TRUE; + /*---------------------------------------------------------------------- + * Tidy data + *---------------------------------------------------------------------- */ + new_model = TRUE; + new_exchange = FALSE; + new_pp_assemblage = FALSE; + new_surface = FALSE; + new_reaction = FALSE; + new_temperature = FALSE; + new_mix = FALSE; + new_solution = FALSE; + new_gas_phase = FALSE; + new_inverse = FALSE; + new_punch = FALSE; + new_ss_assemblage = FALSE; + new_kinetics = FALSE; + new_copy = FALSE; + new_pitzer = FALSE; + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + elements = NULL; + count_elements = 0; + max_elements = MAX_ELEMENTS; + element_h_one = NULL; + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + elt_list = NULL; + count_elts = 0; + max_elts = MAX_ELTS; + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + logk = NULL; + count_logk = 0; + max_logk = MAX_S; + moles_per_kilogram_string= NULL; + pe_string = NULL; + s = NULL; + count_s = 0; + max_s = MAX_S; + // auto s_diff_layer; + s_x = NULL; + count_s_x = 0; + max_s_x = 0; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + phases = NULL; + count_phases = 0; + max_phases = MAX_PHASES; + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + master = NULL; + dbg_master = NULL; + count_master = 0; + max_master = MAX_MASTER; + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + x = NULL; + count_unknowns = 0; + max_unknowns = 0; + ah2o_unknown = NULL; + alkalinity_unknown = NULL; + carbon_unknown = NULL; + charge_balance_unknown = NULL; + exchange_unknown = NULL; + mass_hydrogen_unknown = NULL; + mass_oxygen_unknown = NULL; + mb_unknown = NULL; + mu_unknown = NULL; + pe_unknown = NULL; + ph_unknown = NULL; + pure_phase_unknown = NULL; + solution_phase_boundary_unknown = NULL; + surface_unknown = NULL; + gas_unknown = NULL; + slack_unknown = NULL; + ss_unknown = NULL; + // auto gas_unknowns; + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + // struct trxn; + trxn.token = 0; + for (int i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] = 0; + } + for (int i = 0; i < 3; i++) + { + trxn.dz[i] = 0; + } + count_trxn = 0; + max_trxn = MAX_TRXN; + + mb_unknowns = NULL; + count_mb_unknowns = 0; + max_mb_unknowns = MAX_TRXN; + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.ss_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + pr.status = TRUE; + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + status_on = true; + status_interval = 0; + status_timer = clock(); + count_warnings = 0; + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + rates = NULL; + count_rates = 0; + rate_m = 0; + rate_m0 = 0; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + // auto rate_p + count_rate_p = 0; + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + user_print = NULL; + user_punch = NULL; + user_punch_headings = NULL; + user_punch_count_headings = 0; + n_user_punch_index = 0; + fpunchf_user_s_warning = 0; + fpunchf_user_buffer[0] = 0; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + // auto chart_handler; + chart_handler.Set_io(phrq_io); +#endif + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + error_string = NULL; + simulation = 0; + int state = INITIALIZE; + reaction_step = 0; + transport_step = 0; + transport_start = 0; + advection_step = 0; + stop_program = FALSE; + incremental_reactions = FALSE; + count_strings = 0; + max_strings = MAX_STRINGS; + array = NULL; + delta = NULL; + residual = NULL; + input_error = 0; + next_keyword = Keywords::KEY_NONE; + parse_error = 0; + paren_count = 0; + iterations = 0; + gamma_iterations = 0; + run_reactions_iterations= 0; + max_line = MAX_LINE; + line = NULL; + line_save = NULL; + LOG_10 = log(10.0); + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif + itmax = 100; + max_tries = 1000; +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif + convergence_tolerance = 1e-8; + step_size = 100.; + pe_step_size = 10.; + step_size_now = step_size; + pe_step_size_now = pe_step_size; + pp_scale = 1.0; + pp_column_scale = 1.0; + diagonal_scale = FALSE; + mass_water_switch = FALSE; + delay_mass_water = FALSE; + dampen_ah2o = false; + slack = false; + censor = 0.0; + aqueous_only = 0; + negative_concentrations = FALSE; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + count_total_steps = 0; + phast = FALSE; + llnl_temp = 0; + llnl_count_temp = 0; + llnl_adh = 0; + llnl_count_adh = 0; + llnl_bdh = 0; + llnl_count_bdh = 0; + llnl_bdot = 0; + llnl_count_bdot = 0; + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; + selected_output_file_name = NULL; + dump_file_name = NULL; + remove_unstable_phases = FALSE; + // auto screen_string; +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + spread_length = 10; + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ + // auto strings_map; +#ifdef HASH + // auto strings_hash; +#endif + elements_hash_table = NULL; + species_hash_table = NULL; + phases_hash_table = NULL; + logk_hash_table = NULL; + master_isotope_hash_table = NULL; + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + count_master_isotope = 0; + master_isotope = NULL; + max_master_isotope = MAX_ELTS; + initial_solution_isotopes = FALSE; + count_calculate_value = 0; + calculate_value = NULL; + max_calculate_value = MAX_ELTS; + calculate_value_hash_table = NULL; + count_isotope_ratio = 0; + isotope_ratio = 0; + max_isotope_ratio = MAX_ELTS; + isotope_ratio_hash_table = 0; + count_isotope_alpha = 0; + isotope_alpha = 0; + max_isotope_alpha = MAX_ELTS; + isotope_alpha_hash_table = 0; + + + phreeqc_mpi_myself = 0; + first_read_input = TRUE; + user_database = NULL; + have_punch_name = FALSE; + print_density = 0; + zeros = NULL; + zeros_max = 1; + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + sys = NULL; + count_sys = 0; + max_sys = 0; + sys_tot = 0; +#ifdef PHREEQC2 + AA_basic = 0; + BB_basic = 0; + CC = 0; + I_m = 0; + rho_0 = 0; + eps_r = EPSILON; +#else + V_solutes = 0.0; + rho_0 = 0; + kappa_0 = 0.0; + p_sat = 0.0; + eps_r = EPSILON; + DH_A = 0.0; + DH_B = 0.0; + DH_Av = 0.0; + QBrn = 0.0; + ZBrn = 0.0; + dgdP = 0.0; +#endif + need_temp_msg = 0; + solution_mass = 0; + solution_volume = 0; + /* phqalloc.cpp ------------------------------- */ + s_pTail = NULL; + /* Basic */ + basic_interpreter = NULL; + /* cl1.cpp ------------------------------- */ + x_arg = NULL; + res_arg = NULL; + scratch = NULL; + x_arg_max = 0; + res_arg_max = 0; + scratch_max = 0; + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + Q0 = 0; + Q5 = 0; + GASCON = 0.461522e0; + TZ = 647.073e0; + AA = 1.e0; + Z = 0; + DZ = 0; + Y = 0; + G1 = 11.e0; + G2 = 44.333333333333e0; + GF = 3.5e0; + B1 = 0; + B2 = 0; + B1T = 0; + B2T = 0; + B1TT = 0; + B2TT = 0; + /* gases.cpp ------------------------------- */ + a_aa_sum = 0; + b2 = 0; + b_sum = 0; + R_TK = 0; + /* input.cpp ------------------------------- */ + check_line_return = 0; + reading_db = FALSE; + /* integrate.cpp ------------------------------- */ + midpoint_sv = 0; + z_global = 0; + xd_global = 0; + alpha_global = 0; + /* integrate.cpp ------------------------------- */ + max_row_count = 50; + max_column_count = 50; + carbon = FALSE; + col_name = NULL; + row_name = NULL; + count_rows = 0; + count_optimize = 0; + col_phases = 0; + col_redox = 0; + col_epsilon = 0; + col_ph = 0; + col_water = 0; + col_isotopes = 0; + col_phase_isotopes = 0; + row_mb = 0; + row_fract = 0; + row_charge = 0; + row_carbon = 0; + row_isotopes = 0; + row_epsilon = 0; + row_isotope_epsilon = 0; + row_water = 0; + inv_zero = NULL; + array1 = 0; + inv_res = NULL; + inv_delta1 = NULL; + delta2 = NULL; + delta3 = NULL; + inv_cu = NULL; + delta_save = NULL; + min_delta = NULL; + max_delta = NULL; + inv_iu = NULL; + inv_is = NULL; + klmd = 0; + nklmd = 0; + n2d = 0; + kode = 0; + iter = 0; + toler = 0; + error = 0; + max_pct = 0; + scaled_error = 0; + master_alk = NULL; + row_back = NULL; + col_back = NULL; + good = NULL; + bad = NULL; + minimal = NULL; + max_good = 0; + max_bad = 0; + max_minimal = 0; + count_good = 0; + count_bad = 0; + count_minimal = 0; + count_calls = 0; + soln_bits = 0; + phase_bits = 0; + current_bits = 0; + temp_bits = 0; + netpath_file = NULL; + count_inverse_models = 0; + count_pat_solutions = 0; + for (int i = 0; i < 32; i++) + { + min_position[i] = 0; + max_position[i] = 0; + now[i] = 0; + } + /* kinetics.cpp ------------------------------- */ + count_pp = count_pg = count_ss = 0; + cvode_kinetics_ptr = NULL; + cvode_test = FALSE; + cvode_error = FALSE; + cvode_n_user = -99; + cvode_n_reactions = -99; + cvode_step_fraction = 0.0; + cvode_rate_sim_time = 0.0; + cvode_rate_sim_time_start = 0.0; + cvode_last_good_time = 0.0; + cvode_prev_good_time = 0.0; + cvode_last_good_y = NULL; + cvode_prev_good_y = NULL; + kinetics_machEnv = NULL; + kinetics_y = NULL; + kinetics_abstol = NULL; + kinetics_cvode_mem = NULL; + cvode_pp_assemblage_save= NULL; + cvode_ss_assemblage_save= NULL; + m_original = NULL; + m_temp = NULL; + rk_moles = NULL; + set_and_run_attempt = 0; + x0_moles = NULL; + /* model.cpp ------------------------------- */ + gas_in = FALSE; + min_value = 1e-10; + normal = NULL; + ineq_array = NULL; + res = NULL; + cu = NULL; + zero = NULL; + delta1 = NULL; + iu = NULL; + is = NULL; + back_eq = NULL; + normal_max = 0; + ineq_array_max = 0; + res_max = 0; + cu_max = 0; + zero_max = 0; + delta1_max = 0; + iu_max = 0; + is_max = 0; + back_eq_max = 0; + /* phrq_io_output.cpp ------------------------------- */ + forward_output_to_log = 0; + /* phreeqc_files.cpp ------------------------------- */ + default_data_base = string_duplicate("phreeqc.dat"); +#ifdef PHREEQ98 + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; +#endif + /* Pitzer */ + pitzer_model = FALSE; + sit_model = FALSE; + pitzer_pe = FALSE; + full_pitzer = FALSE; + always_full_pitzer = FALSE; + ICON = TRUE; + IC = -1; + COSMOT = 0; + AW = 0; + VP = 0; + DW0 = 0; + pitz_params = NULL; + count_pitz_param = 0; + max_pitz_param = 100; + // auto pitz_param_map + theta_params = 0; + count_theta_param = 0; + max_theta_param = 100; + use_etheta = TRUE; + OTEMP = 0.0; + A0 = 0; + spec = NULL; + cations = NULL; + anions = NULL; + neutrals = NULL; + count_cations = 0; + count_anions = 0; + count_neutrals = 0; + MAXCATIONS = 0; + FIRSTANION = 0; + MAXNEUTRAL = 0; + mcb0 = NULL; + mcb1 = NULL; + mcc0 = NULL; + IPRSNT = NULL; + M = NULL; + LGAMMA = NULL; + for (int i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } +#ifdef PHREEQ98 + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; +#endif + dummy = 0; + /* print.cpp ------------------------------- */ + sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); + if (sformatf_buffer == NULL) + malloc_error(); + sformatf_buffer_size = 256; +#ifdef PHREEQ98 + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; +#endif + /* read.cpp */ + prev_next_char = NULL; +#if defined PHREEQ98 + int shifts_as_points; +#endif + /* read_class.cxx */ + // auto dump_info + // auto delete_info + // auto run_info + run_info.Set_io(phrq_io); + /* readtr.cpp */ + // auto dump_file_name_cpp; + /* sit.cpp ------------------------------- */ + sit_params = NULL; + count_sit_param = 0; + max_sit_param = 100; + // auto sit_param_map + sit_A0 = 0; + sit_count_cations = 0; + sit_count_anions = 0; + sit_count_neutrals = 0; + sit_MAXCATIONS = 0; + sit_FIRSTANION = 0; + sit_MAXNEUTRAL = 0; + sit_IPRSNT = NULL; + sit_M = NULL; + sit_LGAMMA = NULL; + /* tidy.cpp ------------------------------- */ + a0 = 0; + a1 = 0; + kc = 0; + kb = 0; + /* tally.cpp ------------------------------- */ + t_buffer = NULL; + tally_count_component = 0; + tally_table = NULL; + count_tally_table_columns = 0; + count_tally_table_rows = 0; + /* transport.cpp ------------------------------- */ + sol_D = NULL; + sol_D_dbg = NULL; + J_ij = NULL; + J_ij_il = NULL; + J_ij_count_spec = 0; + m_s = NULL; + count_m_s = 0; + tot1_h = 0; + tot1_o = 0; + tot2_h = 0; + tot2_o = 0; + diffc_max = 0; + diffc_tr = 0; + J_ij_sum = 0; + transp_surf = FALSE; + heat_mix_array = NULL; + temp1 = NULL; + temp2 = NULL; + nmix = 0; + heat_nmix = 0; + heat_mix_f_imm = 0; + heat_mix_f_m = 0; + warn_MCD_X = 0; + warn_fixed_Surf = 0; +#ifdef PHREEQ98 + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; +#endif + /* utilities.cpp ------------------------------- */ + spinner = 0; + // keycount; + for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + { + keycount.push_back(0); + } + + return; +} diff --git a/Phreeqc.h b/Phreeqc.h index 3d56cd12..d67d70a0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -246,6 +246,13 @@ public: void set_reading_database(int reading_database); int check_line(const char *string, int allow_empty, int allow_eof, int allow_keyword, int print); + int add_char_to_line(int *i, char c); + int check_line_impl(const char *string, int allow_empty, + int allow_eof, int allow_keyword, int print); + int get_line(void); + int get_logical_line(void *cookie, int *l); + int read_database(void); + int run_simulations(void); // integrate.cpp ------------------------------- int calc_all_g(void); @@ -386,8 +393,6 @@ public: int set_reaction(int i, int use_mix, int use_kinetics); int set_transport(int i, int use_mix, int use_kinetics, int nsaver); int store_get_equi_reactants(int k, int kin_end); - int count_pp, count_pg, count_ss; - LDBLE *x0_moles; // mainsubs.cpp ------------------------------- std::ifstream * open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch); @@ -452,7 +457,6 @@ public: int revise_guesses(void); int ss_binary(cxxSS *ss_ptr); int ss_ideal(cxxSS *ss_ptr); - int gas_in; void ineq_init(int max_row_count, int max_column_count); // parse.cpp ------------------------------- @@ -499,7 +503,9 @@ public: int read_pitzer(void); int set_pz(int initial); int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); - int check_gammas_pz(void); + int check_gammas_pz(void); + LDBLE DC(LDBLE T); + int DW(LDBLE T); int ISPEC(const char *name); LDBLE G(LDBLE Y); LDBLE GP(LDBLE Y); @@ -545,7 +551,6 @@ public: int clear(void); //int convert_units(struct solution *solution_ptr); int convert_units(cxxSolution *solution_ptr); - LDBLE a_aa_sum, b2, b_sum, R_TK; LDBLE f_Vm(LDBLE v1); struct unknown *find_surface_charge_unknown(std::string &str_ptr, int plane); struct master **get_list_master_ptrs(char *ptr, @@ -777,9 +782,9 @@ public: char **next_char); int spread_row_free(struct spread_row *spread_row_ptr); int spread_row_to_solution(struct spread_row *heading, - struct spread_row *units, - struct spread_row *data, - struct defaults defaults); + struct spread_row *units, + struct spread_row *data, + struct defaults defaults); struct spread_row *string_to_spread_row(char *string); #ifdef PHREEQCI_GUI void add_row(struct spread_row *spread_row_ptr); @@ -1111,9 +1116,6 @@ protected: PHRQ_io *phrq_io; PHRQ_io ioInstance; int same_model; - //int same_temperature; - //int same_pressure; - //bool same_mu; LDBLE current_tc; LDBLE current_pa; @@ -1664,8 +1666,6 @@ protected: /* phqalloc.cpp ------------------------------- */ PHRQMemHeader *s_pTail; - std::stringstream merged_database_stream; - std::stringstream merged_input_stream; /* Basic */ PBasic * basic_interpreter; @@ -1682,20 +1682,18 @@ protected: LDBLE G1, G2, GF; LDBLE B1, B2, B1T, B2T, B1TT, B2TT; + /* gases.cpp ------------------------------- */ + LDBLE a_aa_sum, b2, b_sum, R_TK; + /* input.cpp ------------------------------- */ - int add_char_to_line(int *i, char c); - int check_line_impl(const char *string, int allow_empty, - int allow_eof, int allow_keyword, int print); - int get_line(void); - int get_logical_line(void *cookie, int *l); - int read_database(void); - int run_simulations(void); int check_line_return; int reading_db; /* integrate.cpp ------------------------------- */ LDBLE midpoint_sv; LDBLE z_global, xd_global, alpha_global; + + /* inverse.cpp ------------------------------- */ int max_row_count, max_column_count; int carbon; const char **col_name, **row_name; @@ -1704,10 +1702,10 @@ protected: col_isotopes, col_phase_isotopes; int row_mb, row_fract, row_charge, row_carbon, row_isotopes, row_epsilon, row_isotope_epsilon, row_water; - LDBLE *inv_zero, *array1, *res, *inv_delta1, *delta2, *delta3, *inv_cu, + LDBLE *inv_zero, *array1, *inv_res, *inv_delta1, *delta2, *delta3, *inv_cu, *delta_save; LDBLE *min_delta, *max_delta; - int *iu, *is; + int *inv_iu, *inv_is; int klmd, nklmd, n2d, kode, iter; LDBLE toler, error, max_pct, scaled_error; struct master *master_alk; @@ -1716,14 +1714,13 @@ protected: int max_good, max_bad, max_minimal; int count_good, count_bad, count_minimal, count_calls; unsigned long soln_bits, phase_bits, current_bits, temp_bits; - - /* inverse.cpp ------------------------------- */ FILE *netpath_file; int count_inverse_models, count_pat_solutions; int min_position[32], max_position[32], now[32]; /* kinetics.cpp ------------------------------- */ public: + int count_pp, count_pg, count_ss; void *cvode_kinetics_ptr; int cvode_test; int cvode_error; @@ -1741,15 +1738,18 @@ public: void *kinetics_cvode_mem; cxxSSassemblage *cvode_ss_assemblage_save; cxxPPassemblage *cvode_pp_assemblage_save; +protected: LDBLE *m_original; LDBLE *m_temp; LDBLE *rk_moles; int set_and_run_attempt; + LDBLE *x0_moles; /* model.cpp ------------------------------- */ + int gas_in; LDBLE min_value; - LDBLE *normal, *ineq_array, *inv_res, *cu, *zero, *delta1; - int *inv_iu, *inv_is, *back_eq; + LDBLE *normal, *ineq_array, *res, *cu, *zero, *delta1; + int *iu, *is, *back_eq; int normal_max, ineq_array_max, res_max, cu_max, zero_max, delta1_max, iu_max, is_max, back_eq_max; @@ -1773,11 +1773,6 @@ public: struct pitz_param **pitz_params; int count_pitz_param, max_pitz_param; std::map< std::string, size_t > pitz_param_map; - struct pitz_param **sit_params; - int count_sit_param, max_sit_param; - std::map< std::string, size_t > sit_param_map; - int DW(LDBLE T); - LDBLE DC(LDBLE T); struct theta_param **theta_params; int count_theta_param, max_theta_param; int use_etheta; @@ -1828,6 +1823,9 @@ public: std::string dump_file_name_cpp; /* sit.cpp ------------------------------- */ + struct pitz_param **sit_params; + int count_sit_param, max_sit_param; + std::map< std::string, size_t > sit_param_map; LDBLE sit_A0; int sit_count_cations, sit_count_anions, sit_count_neutrals; int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; diff --git a/phreeqc/gases.cpp b/phreeqc/gases.cpp index 5e290e1c..ec13799e 100644 --- a/phreeqc/gases.cpp +++ b/phreeqc/gases.cpp @@ -41,7 +41,6 @@ setup_fixed_volume_gas(void) { gas_unknown = gas_unknowns[0]; } - //same_pressure = FALSE; return (OK); } diff --git a/phreeqc/kinetics.cpp b/phreeqc/kinetics.cpp index 7a75d275..4f0c4e9b 100644 --- a/phreeqc/kinetics.cpp +++ b/phreeqc/kinetics.cpp @@ -1471,7 +1471,6 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, else { prep(); - //same_pressure = false; k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); set(FALSE); converge = model(); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index f0a658c9..384700b6 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -16,7 +16,7 @@ #if defined(WINDOWS) || defined(_WINDOWS) #include #endif - +#ifdef SKIP /* ---------------------------------------------------------------------- */ void Phreeqc:: initialize(void) @@ -551,8 +551,6 @@ initialize(void) print_density = 0; same_model = FALSE; - //same_temperature = FALSE; - //same_pressure = FALSE; current_tc = NAN; current_pa = NAN; current_mu = NAN; @@ -714,7 +712,316 @@ initialize(void) return; } +#endif +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +initialize(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Initialize global variables + */ + struct logk *logk_ptr; + char token[MAX_LENGTH]; + moles_per_kilogram_string = string_duplicate("Mol/kgw"); + pe_string = string_duplicate("pe"); +/* + * Initialize advection + */ + advection_punch = (int *) PHRQ_malloc(sizeof(int)); + if (advection_punch == NULL) + malloc_error(); + advection_punch[0] = TRUE; + advection_print = (int *) PHRQ_malloc(sizeof(int)); + if (advection_print == NULL) + malloc_error(); + advection_print[0] = TRUE; +/* + * Allocate space + */ + space((void **) ((void *) &cell_data), INIT, &count_cells, + sizeof(struct cell_data)); + + space((void **) ((void *) &elements), INIT, &max_elements, + sizeof(struct element *)); + + space((void **) ((void *) &elt_list), INIT, &max_elts, + sizeof(struct elt_list)); + + inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); + if (inverse == NULL) malloc_error(); + count_inverse = 0; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); + + space((void **) ((void *) &master), INIT, &max_master, + sizeof(struct master *)); + + space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, + sizeof(struct unknown_list)); + + // one stag_data + stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data)); + if (stag_data == NULL) + malloc_error(); + stag_data->count_stag = 0; + stag_data->exch_f = 0; + stag_data->th_m = 0; + stag_data->th_im = 0; + + space((void **) ((void *) &phases), INIT, &max_phases, + sizeof(struct phase *)); + + space((void **) ((void *) &trxn.token), INIT, &max_trxn, + sizeof(struct rxn_token_temp)); + + space((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); + + space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); + + space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, + sizeof(struct master_isotope *)); + +/* + * Create hash tables + */ + hcreate_multi((unsigned) max_logk, &logk_hash_table); + hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); + hcreate_multi((unsigned) max_elements, &elements_hash_table); + hcreate_multi((unsigned) max_s, &species_hash_table); + hcreate_multi((unsigned) max_phases, &phases_hash_table); +/* + * Initialize punch + */ + punch.in = FALSE; + punch.new_def = FALSE; + + // one punch.totals + punch.count_totals = 0; + punch.totals = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.totals == NULL) + malloc_error(); + + // one punch.molalities + punch.count_molalities = 0; + punch.molalities = + (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.molalities == NULL) + malloc_error(); + + // one punch.activities + punch.count_activities = 0; + punch.activities = + (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); + if (punch.activities == NULL) + malloc_error(); + + // one punch.pure_phases + punch.count_pure_phases = 0; + punch.pure_phases = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.pure_phases == NULL) + malloc_error(); + + // one punch.si + punch.count_si = 0; + punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.si == NULL) + malloc_error(); + + // one punch.gases + punch.count_gases = 0; + punch.gases = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.gases == NULL) + malloc_error(); + + // one punch.s_s + punch.count_s_s = 0; + punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.s_s == NULL) + malloc_error(); + + // one punch.kinetics + punch.count_kinetics = 0; + punch.kinetics = + (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); + if (punch.kinetics == NULL) + malloc_error(); + + // one punch.isotopes + punch.count_isotopes = 0; + punch.isotopes = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.isotopes == NULL) + malloc_error(); + + // one punch.calculate_values + punch.count_calculate_values = 0; + punch.calculate_values = + (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); + if (punch.calculate_values == NULL) + malloc_error(); + + // one save_values + save_values = + (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); + if (save_values == NULL) + malloc_error(); + + // one rate + rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); + if (rates == NULL) + malloc_error(); + + // user_print + user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_print == NULL) + malloc_error(); + user_print->commands = NULL; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + + // user_punch + user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_punch == NULL) + malloc_error(); + user_punch->commands = NULL; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + user_punch_headings = (const char **) PHRQ_malloc(sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + user_punch_count_headings = 0; +#if defined PHREEQ98 +/* + * user_graph + */ + user_graph = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); + if (user_graph == NULL) + malloc_error(); + user_graph->commands = NULL; + user_graph->linebase = NULL; + user_graph->varbase = NULL; + user_graph->loopbase = NULL; + user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); + if (user_graph_headings == NULL) + malloc_error(); + user_graph_count_headings = 0; +#endif + /* + Initialize llnl aqueous model parameters + */ + llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_temp == NULL) + malloc_error(); + llnl_count_temp = 0; + llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_adh == NULL) + malloc_error(); + llnl_count_adh = 0; + llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdh == NULL) + malloc_error(); + llnl_count_bdh = 0; + llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_bdot == NULL) + malloc_error(); + llnl_count_bdot = 0; + llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (llnl_co2_coefs == NULL) + malloc_error(); + llnl_count_co2_coefs = 0; + // new PBasic + basic_interpreter = new PBasic(this, phrq_io); + // allocate one change_surf + change_surf = + (struct Change_Surf *) + PHRQ_malloc((size_t) (2 * sizeof(struct Change_Surf))); + if (change_surf == NULL) + malloc_error(); + change_surf[0].cell_no = -99; + change_surf[0].next = TRUE; + change_surf[1].cell_no = -99; + change_surf[1].next = FALSE; + +#ifdef PHREEQCI_GUI + g_spread_sheet.heading = NULL; + g_spread_sheet.units = NULL; + g_spread_sheet.count_rows = 0; + g_spread_sheet.rows = NULL; + g_spread_sheet.defaults.units = NULL; + g_spread_sheet.defaults.count_iso = 0; + g_spread_sheet.defaults.iso = NULL; + g_spread_sheet.defaults.redox = NULL; +#endif + + /* calculate_value */ + max_calculate_value = MAX_ELTS; + count_calculate_value = 0; + space((void **) ((void *) &calculate_value), INIT, &max_calculate_value, + sizeof(struct calculate_value *)); + hcreate_multi((unsigned) max_calculate_value, + &calculate_value_hash_table); + + /* isotope_ratio */ + max_isotope_ratio = MAX_ELTS; + count_isotope_ratio = 0; + space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, + sizeof(struct isotope_ratio *)); + hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); + + /* isotope_value */ + max_isotope_alpha = MAX_ELTS; + count_isotope_alpha = 0; + space((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, + sizeof(struct isotope_alpha *)); + hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); + + /* + * define constant named log_k + */ + strcpy(token, "XconstantX"); + logk_ptr = logk_store(token, TRUE); + strcpy(token, "1.0"); + read_log_k_only(token, &logk_ptr->log_k[0]); + + // allocate space for copier + copier_init(©_solution); + copier_init(©_pp_assemblage); + copier_init(©_exchange); + copier_init(©_surface); + copier_init(©_ss_assemblage); + copier_init(©_gas_phase); + copier_init(©_kinetics); + copier_init(©_mix); + copier_init(©_reaction); + copier_init(©_temperature); + copier_init(©_pressure); + + // Initialize cvode + cvode_init(); + + // Allocate space for pitzer + pitzer_init(); + + // Allocate space for sit + sit_init(); + + // Allocate zeros + zeros = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + if (zeros == NULL) + malloc_error(); + zeros[0] = 0.0; + zeros_max = 1; + + return; +} /* ---------------------------------------------------------------------- */ int Phreeqc:: set_use(void) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 1faa15e6..a1ef8016 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -44,7 +44,6 @@ model(void) int mass_water_switch_save; LDBLE old_mu; - //same_mu = true; set_inert_moles(); /* debug_model = TRUE; */ /* debug_prep = TRUE; */ @@ -4946,9 +4945,7 @@ surface_model(void) debug_model = TRUE; debug_diffuse_layer = TRUE; } -#ifndef PHREEQC2 - //same_mu = false; -#else +#ifdef PHREEQC2 k_temp(tc_x, patm_x); #endif gammas(mu_x); @@ -5163,9 +5160,6 @@ numerical_jacobian(void) return(OK); calculating_deriv = TRUE; -#ifndef PHREEQC2 - //same_mu = false; -#endif gammas(mu_x); molalities(TRUE); mb_sums(); From ed73e17fd8f225e7d97f13c6379d8b887c95c306 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 11 Oct 2012 23:30:56 +0000 Subject: [PATCH 0570/1077] Working on copy constructor. Roughed in Pitzer, need to do Sit and TRANSPORT. Test git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7009 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1329 ++++++++++++++++++++++++++++++++++- Phreeqc.h | 4 + phreeqc/global_structures.h | 1 - phreeqc/mainsubs.cpp | 1 - phreeqc/structures.cpp | 61 ++ 5 files changed, 1392 insertions(+), 4 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 18213e2f..e431889a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -307,7 +307,6 @@ void Phreeqc::init(void) max_mb_unknowns = MAX_TRXN; max_phases = MAX_PHASES; max_s = MAX_S; - max_strings = MAX_STRINGS; max_trxn = MAX_TRXN; max_logk = MAX_S; max_master_isotope = MAX_ELTS; @@ -1318,7 +1317,6 @@ void Phreeqc::init(void) stop_program = FALSE; incremental_reactions = FALSE; count_strings = 0; - max_strings = MAX_STRINGS; array = NULL; delta = NULL; residual = NULL; @@ -1774,3 +1772,1330 @@ void Phreeqc::init(void) return; } +/*-----------------------------------------------------*/ +Phreeqc::Phreeqc(const Phreeqc &src) +{ + this->phrq_io = src.phrq_io; + this->init(); + this->initialize(); + InternalCopy(&src); +} +void +Phreeqc::InternalCopy(const Phreeqc *pSrc) +{ + // phrq_io + /* + if (io) + { + this->phrq_io = io; + } + else + { + this->phrq_io = &this->ioInstance; + } + */ + + same_model = FALSE; + current_tc = pSrc->current_tc; + current_pa = pSrc->current_pa; + current_mu = pSrc->current_mu; + mu_terms_in_logk = pSrc->mu_terms_in_logk; + + /* ---------------------------------------------------------------------- + * STRUCTURES + * ---------------------------------------------------------------------- */ +/* + * last model + */ + //-- skip last model, accept init + +/* + * Initialize punch + */ + //-- skip punch, accept init + + Rxn_temperature_map = pSrc->Rxn_temperature_map; + Rxn_pressure_map = pSrc->Rxn_pressure_map; + + /* ---------------------------------------------------------------------- + * Surface + * --------------------------------------------------------------------- */ + g_iterations = -1; + G_TOL = 1e-8; + Rxn_surface_map = pSrc->Rxn_surface_map; + // auto charge_group_map; + /* + change_surf_count = 0; + change_surf = NULL; + */ + /* ---------------------------------------------------------------------- + * Exchange + * ---------------------------------------------------------------------- */ + Rxn_exchange_map = pSrc->Rxn_exchange_map; + + /* ---------------------------------------------------------------------- + * Kinetics + * ---------------------------------------------------------------------- */ + Rxn_kinetics_map = pSrc->Rxn_kinetics_map; + + /*---------------------------------------------------------------------- + * Save + *---------------------------------------------------------------------- */ + count_save_values = 0; + /* + save_values = NULL; + save_init(-1); // set initial save values + */ + + // auto use + + // copier structures + //-- skip copier, accept init + + /*---------------------------------------------------------------------- + * Inverse + *---------------------------------------------------------------------- */ + + /* + inverse = NULL; + */ + count_inverse = 0; + /*---------------------------------------------------------------------- + * Mix + *---------------------------------------------------------------------- */ + // auto Rxn_mix_map; + // auto Dispersion_mix_map; + // auto Rxn_solution_mix_map; + // auto Rxn_exchange_mix_map; + // auto Rxn_gas_phase_mix_map; + // auto Rxn_kinetics_mix_map; + // auto Rxn_pp_assemblage_mix_map; + // auto Rxn_ss_assemblage_mix_map; + // auto Rxn_surface_mix_map; + /*---------------------------------------------------------------------- + * Irreversible reaction + *---------------------------------------------------------------------- */ + Rxn_reaction_map = pSrc->Rxn_reaction_map; + /*---------------------------------------------------------------------- + * Gas phase + *---------------------------------------------------------------------- */ + Rxn_gas_phase_map = pSrc->Rxn_gas_phase_map; + /*---------------------------------------------------------------------- + * Solid solution + *---------------------------------------------------------------------- */ + Rxn_ss_assemblage_map = pSrc->Rxn_ss_assemblage_map; + /*---------------------------------------------------------------------- + * Pure-phase assemblage + *---------------------------------------------------------------------- */ + Rxn_pp_assemblage_map = pSrc->Rxn_pp_assemblage_map; + /*---------------------------------------------------------------------- + * Species_list + *---------------------------------------------------------------------- */ + /* + count_species_list = 0; + max_species_list = 0; + species_list = NULL; + */ + /*---------------------------------------------------------------------- + * Jacobian and Mass balance lists + *---------------------------------------------------------------------- */ + /* + count_sum_jacob0 = 0; + max_sum_jacob0 = 0; + sum_jacob0 = NULL; + count_sum_mb1 = 0; + max_sum_mb1 = 0; + sum_mb1 = NULL; + count_sum_jacob1 = 0; + max_sum_jacob1 = 0; + sum_jacob1 = NULL; + count_sum_mb2 = 0; + max_sum_mb2 = 0; + sum_mb2 = NULL; + count_sum_jacob2 = 0; + max_sum_jacob2 = 0; + sum_jacob2 = NULL; + count_sum_delta = 0; + max_sum_delta = 0; + sum_delta = NULL; + */ + /*---------------------------------------------------------------------- + * Solution + *---------------------------------------------------------------------- */ + Rxn_solution_map = pSrc->Rxn_solution_map; + // auto Rxn_solution_map; + // auto unnumbered_solutions; + /*---------------------------------------------------------------------- + * Global solution + *---------------------------------------------------------------------- */ + /* + title_x = NULL; + new_x = FALSE; + description_x = NULL; + tc_x = 0; + tk_x = 0; + patm_x = 1; + last_patm_x = 1; + numerical_fixed_volume = false; + force_numerical_fixed_volume = false; + switch_numerical = false; + ph_x = 0; + solution_pe_x = 0; + mu_x = 0; + ah2o_x = 1.0; + density_x = 0; + total_h_x = 0; + total_o_x = 0; + cb_x = 0; + total_ions_x = 0; + mass_water_aq_x = 0; + mass_water_surfaces_x = 0; + mass_water_bulk_x = 0; + units_x = NULL; + */ + // auto pe_x + // auto isotopes_x + // auto default_pe_x + /* + dl_type_x = cxxSurface::NO_DL; + total_carbon = 0; + total_co2 = 0; + total_alkalinity = 0; + gfw_water = 0; + step_x = 0; + kin_time_x = 0; + */ + /*---------------------------------------------------------------------- + * Transport data + *---------------------------------------------------------------------- */ + /* + count_cells = 1; + count_shifts = 1; + ishift = 1; + bcon_first = bcon_last = 3; + correct_disp = FALSE; + tempr = 2.0; + timest = 0.0; + simul_tr = 0; + diffc = 0.3e-9; + heat_diffc = -0.1; + cell = 0; + mcd_substeps = 1.0; + stag_data = NULL; + print_modulus = 1; + punch_modulus = 1; + dump_in = FALSE; + dump_modulus = 0; + transport_warnings = TRUE; + cell_data = FALSE; + multi_Dflag = FALSE; + interlayer_Dflag = FALSE; + default_Dw = 0; + multi_Dpor = 0; + interlayer_Dpor = 0.1; + multi_Dpor_lim = 0; + interlayer_Dpor_lim = 0; + multi_Dn = 0; + interlayer_tortf = 100.0; + cell_no = 0; + */ + /*---------------------------------------------------------------------- + * Advection data + *---------------------------------------------------------------------- */ + /* + count_ad_cells = 1; + count_ad_shifts = 1; + print_ad_modulus = 1; + punch_ad_modulus = 1; + advection_punch = NULL; + advection_kin_time = 0.0; + advection_kin_time_defined = FALSE; + advection_print = NULL; + advection_warnings = TRUE; + */ + /*---------------------------------------------------------------------- + * Tidy data + *---------------------------------------------------------------------- */ + /* + new_model = TRUE; + new_exchange = FALSE; + new_pp_assemblage = FALSE; + new_surface = FALSE; + new_reaction = FALSE; + new_temperature = FALSE; + new_mix = FALSE; + new_solution = FALSE; + new_gas_phase = FALSE; + new_inverse = FALSE; + new_punch = FALSE; + new_ss_assemblage = FALSE; + new_kinetics = FALSE; + new_copy = FALSE; + new_pitzer = FALSE; + */ + /*---------------------------------------------------------------------- + * Elements + *---------------------------------------------------------------------- */ + for (int i = 0; i < pSrc->count_elements; i++) + { + string_hsave(pSrc->elements[i]->name); + struct element *elt_ptr = element_store(pSrc->elements[i]->name); + elt_ptr->gfw = pSrc->elements[i]->gfw; + } + element_h_one = element_store("H(1)"); + /* + elements = NULL; + count_elements = 0; + max_elements = MAX_ELEMENTS; + element_h_one = NULL; + */ + /*---------------------------------------------------------------------- + * Element List + *---------------------------------------------------------------------- */ + /* + elt_list = NULL; + count_elts = 0; + max_elts = MAX_ELTS; + */ + /*---------------------------------------------------------------------- + * Species + *---------------------------------------------------------------------- */ + /* + logk = NULL; + count_logk = 0; + max_logk = MAX_S; + moles_per_kilogram_string= NULL; + pe_string = NULL; + s = NULL; + count_s = 0; + max_s = MAX_S; + // auto s_diff_layer; + s_x = NULL; + count_s_x = 0; + max_s_x = 0; + s_h2o = NULL; + s_hplus = NULL; + s_h3oplus = NULL; + s_eminus = NULL; + s_co3 = NULL; + s_h2 = NULL; + s_o2 = NULL; + */ + // logk +#ifdef SKIP + count_logk = pSrc->count_logk; + max_logk = pSrc->max_logk; + logk = (struct logk **) free_check_null(logk); + logk = (struct logk **) PHRQ_malloc((size_t) max_logk * sizeof(struct logk *)); + if (logk == NULL) malloc_error(); + for (int i = 0; i < count_logk; i++) + { + logk[i] = (struct logk *) PHRQ_malloc((size_t) max_logk * sizeof(struct logk)); + memcpy(logk[i], pSrc->logk[i], sizeof(struct logk)); + logk[i]->name = string_hsave(pSrc->logk[i]->name); + logk[i]->add_logk = NULL; + if (logk[i]->count_add_logk > 0) + { + logk[i]->add_logk = (struct name_coef *) PHRQ_malloc((size_t) logk[i]->count_add_logk * sizeof(struct name_coef)); + if (logk[i]->add_logk == NULL) malloc_error(); + for (int j = 0; j < logk[i]->count_add_logk; j++) + { + logk[i]->add_logk[j].coef = pSrc->logk[i]->add_logk[j].coef; + logk[i]->add_logk[j].name = string_hsave( pSrc->logk[i]->add_logk[j].name); + } + } + } +#endif + for (int i = 0; i < pSrc->count_logk; i++) + { + char * name = string_duplicate(pSrc->logk[i]->name); + struct logk *logk_ptr = logk_store(name, FALSE); + free_check_null(name); + memcpy(logk_ptr, pSrc->logk[i], sizeof(struct logk)); + logk_ptr->name = string_hsave(pSrc->logk[i]->name); + logk_ptr->add_logk = NULL; + if (logk_ptr->count_add_logk > 0) + { + logk_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->logk[i]->count_add_logk * sizeof(struct name_coef)); + if (logk[i]->add_logk == NULL) malloc_error(); + for (int j = 0; j < logk_ptr->count_add_logk; j++) + { + logk_ptr->add_logk[j].coef = pSrc->logk[i]->add_logk[j].coef; + logk_ptr->add_logk[j].name = string_hsave( pSrc->logk[i]->add_logk[j].name); + } + } + } + // s, species + for (int i = 0; i < pSrc->count_s; i++) + { + struct species *s_ptr = s_store(pSrc->s[i]->name, pSrc->s[i]->z, FALSE); + memcpy(s_ptr, pSrc->s[i], sizeof(struct species)); + s_ptr->name = string_hsave(pSrc->s[i]->name); + // fix up all pointers + s_ptr->mole_balance = NULL; + if (pSrc->s[i]->mole_balance != NULL) + { + s_ptr->mole_balance = string_hsave(pSrc->s[i]->mole_balance); + } + //add_logk + s_ptr->add_logk = NULL; + if (s_ptr->count_add_logk > 0) + { + s_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) s_ptr->count_add_logk * sizeof(struct name_coef)); + if (s_ptr->add_logk == NULL) malloc_error(); + for (int j = 0; j < s_ptr->count_add_logk; j++) + { + s_ptr->add_logk[j].coef = pSrc->s[i]->add_logk[j].coef; + s_ptr->add_logk[j].name = string_hsave( pSrc->s[i]->add_logk[j].name); + } + } + //next_elt + cxxNameDouble next_elt(pSrc->s[i]->next_elt); + s_ptr->next_elt = NameDouble2elt_list(next_elt); + //next_secondary + cxxNameDouble next_secondary(pSrc->s[i]->next_secondary); + s_ptr->next_secondary = NameDouble2elt_list(next_secondary); + //next_sys_total + cxxNameDouble next_sys_total(pSrc->s[i]->next_sys_total); + s_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + //rxn + if (pSrc->s[i]->rxn != NULL) + { + cxxChemRxn rxn(pSrc->s[i]->rxn); + s_ptr->rxn = cxxChemRxn2rxn(rxn); + //s_ptr->rxn = rxn_copy_operator(pSrc->s[i]->rxn); + } + //rxn_s + if (pSrc->s[i]->rxn_s != NULL) + { + cxxChemRxn rxn_s(pSrc->s[i]->rxn_s); + s_ptr->rxn_s = cxxChemRxn2rxn(rxn_s); + } + //rxn_x + if (pSrc->s[i]->rxn_x != NULL) + { + cxxChemRxn rxn_x(pSrc->s[i]->rxn_x); + s_ptr->rxn_x = cxxChemRxn2rxn(rxn_x); + } + } + s_h2o = s_search("H2O"); + s_hplus = s_search("H+"); + s_h3oplus = s_search("H3O+"); + s_eminus = s_search("e-"); + s_co3 = s_search("CO3-2"); + s_h2 = s_search("H2"); + s_o2 = s_search("O2"); + /*---------------------------------------------------------------------- + * Phases + *---------------------------------------------------------------------- */ + /* + phases = NULL; + count_phases = 0; + max_phases = MAX_PHASES; + */ +#ifdef SKIP + count_phases = pSrc->count_phases; + max_phases = pSrc->max_phases; + phases = (struct phase **) free_check_null(phases); + phases = (struct phase **) PHRQ_malloc((size_t) max_phases * sizeof(struct phase *)); + if (phases == NULL) malloc_error(); + for (int i = 0; i < count_phases; i++) + { + phases[i] = (struct phase *) PHRQ_malloc( sizeof(struct phase)); + if (phases[i] == NULL) malloc_error(); + memcpy(phases[i], pSrc->phases[i], sizeof(struct phase)); + // clean up pointers + phases[i]->name = string_hsave(pSrc->phases[i]->name); + phases[i]->formula = string_hsave(pSrc->phases[i]->formula); + //add_logk + phases[i]->add_logk = NULL; + if (phases[i]->count_add_logk > 0) + { + phases[i]->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->phases[i]->count_add_logk * sizeof(struct name_coef)); + if (phases[i]->add_logk == NULL) malloc_error(); + for (int j = 0; j < phases[i]->count_add_logk; j++) + { + phases[i]->add_logk[j].coef = pSrc->phases[i]->add_logk[j].coef; + phases[i]->add_logk[j].name = string_hsave( pSrc->phases[i]->add_logk[j].name); + } + } + //next_elt + cxxNameDouble next_elt(pSrc->phases[i]->next_elt); + phases[i]->next_elt = NameDouble2elt_list(next_elt); + //next_sys_total + cxxNameDouble next_sys_total(pSrc->phases[i]->next_sys_total); + phases[i]->next_sys_total = NameDouble2elt_list(next_sys_total); + //rxn + cxxChemRxn rxn(pSrc->phases[i]->rxn); + phases[i]->rxn = cxxChemRxn2rxn(rxn); + //rxn_s + cxxChemRxn rxn_s(pSrc->phases[i]->rxn_s); + phases[i]->rxn_s = cxxChemRxn2rxn(rxn_s); + //rxn_x + cxxChemRxn rxn_x(pSrc->phases[i]->rxn_x); + phases[i]->rxn_x = cxxChemRxn2rxn(rxn_x); + } +#endif + for (int i = 0; i < pSrc->count_phases; i++) + { + struct phase *phase_ptr = phase_store(pSrc->phases[i]->name); + memcpy(phase_ptr, pSrc->phases[i], sizeof(struct phase)); + // clean up pointers + phase_ptr->name = string_hsave(pSrc->phases[i]->name); + phase_ptr->formula = string_hsave(pSrc->phases[i]->formula); + //add_logk + phase_ptr->add_logk = NULL; + if (phase_ptr->count_add_logk > 0) + { + phase_ptr->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->phases[i]->count_add_logk * sizeof(struct name_coef)); + if (phase_ptr->add_logk == NULL) malloc_error(); + for (int j = 0; j < phase_ptr->count_add_logk; j++) + { + phase_ptr->add_logk[j].coef = pSrc->phases[i]->add_logk[j].coef; + phase_ptr->add_logk[j].name = string_hsave( pSrc->phases[i]->add_logk[j].name); + } + } + //next_elt + cxxNameDouble next_elt(pSrc->phases[i]->next_elt); + phase_ptr->next_elt = NameDouble2elt_list(next_elt); + //next_sys_total + cxxNameDouble next_sys_total(pSrc->phases[i]->next_sys_total); + phase_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + //rxn + if (pSrc->phases[i]->rxn != NULL) + { + cxxChemRxn rxn(pSrc->phases[i]->rxn); + phase_ptr->rxn = cxxChemRxn2rxn(rxn); + } + //rxn_s + if (pSrc->phases[i]->rxn_s != NULL) + { + cxxChemRxn rxn_s(pSrc->phases[i]->rxn_s); + phase_ptr->rxn_s = cxxChemRxn2rxn(rxn_s); + } + //rxn_x + if (pSrc->phases[i]->rxn_x != NULL) + { + cxxChemRxn rxn_x(pSrc->phases[i]->rxn_x); + phase_ptr->rxn_x = cxxChemRxn2rxn(rxn_x); + } + } + /*---------------------------------------------------------------------- + * Master species + *---------------------------------------------------------------------- */ + /* + master = NULL; + dbg_master = NULL; + count_master = 0; + max_master = MAX_MASTER; + */ + count_master = pSrc->count_master; + max_master = pSrc->max_master; + master = (struct master **) free_check_null(master); + master = (struct master **) PHRQ_malloc((size_t) max_master * sizeof(struct master *)); + if (master == NULL) malloc_error(); + dbg_master = master; + for (int i = 0; i < count_master; i++) + { + master[i] = (struct master *) PHRQ_malloc( sizeof(struct master)); + if (master[i] == NULL) malloc_error(); + memcpy(master[i], pSrc->master[i], sizeof(struct master)); + // clean up pointers + master[i]->gfw_formula = NULL; + if (pSrc->master[i]->gfw_formula != NULL) + { + master[i]->gfw_formula = string_hsave(pSrc->master[i]->gfw_formula); + } + master[i]->elt = element_store(pSrc->master[i]->elt->name); + master[i]->unknown = NULL; + master[i]->s = s_store(pSrc->master[i]->s->name, pSrc->master[i]->s->z, false); + //rxn_primary + if (pSrc->master[i]->rxn_primary != NULL) + { + cxxChemRxn rxn_primary(pSrc->master[i]->rxn_primary); + master[i]->rxn_primary = cxxChemRxn2rxn(rxn_primary); + } + //rxn_secondary + if (pSrc->master[i]->rxn_secondary != NULL) + { + cxxChemRxn rxn_secondary(pSrc->master[i]->rxn_secondary); + master[i]->rxn_secondary = cxxChemRxn2rxn(rxn_secondary); + } + } + /*---------------------------------------------------------------------- + * Unknowns + *---------------------------------------------------------------------- */ + /* + x = NULL; + count_unknowns = 0; + max_unknowns = 0; + ah2o_unknown = NULL; + alkalinity_unknown = NULL; + carbon_unknown = NULL; + charge_balance_unknown = NULL; + exchange_unknown = NULL; + mass_hydrogen_unknown = NULL; + mass_oxygen_unknown = NULL; + mb_unknown = NULL; + mu_unknown = NULL; + pe_unknown = NULL; + ph_unknown = NULL; + pure_phase_unknown = NULL; + solution_phase_boundary_unknown = NULL; + surface_unknown = NULL; + gas_unknown = NULL; + slack_unknown = NULL; + ss_unknown = NULL; + */ + // auto gas_unknowns; + /*---------------------------------------------------------------------- + * Reaction work space + *---------------------------------------------------------------------- */ + // struct trxn; + /* + trxn.token = 0; + for (int i = 0; i < MAX_LOG_K_INDICES; i++) + { + trxn.logk[i] = 0; + } + for (int i = 0; i < 3; i++) + { + trxn.dz[i] = 0; + } + count_trxn = 0; + max_trxn = MAX_TRXN; + */ + /* + mb_unknowns = NULL; + count_mb_unknowns = 0; + max_mb_unknowns = MAX_TRXN; + */ + /* ---------------------------------------------------------------------- + * Print + * ---------------------------------------------------------------------- */ + /* + pr.all = TRUE; + pr.initial_solutions = TRUE; + pr.initial_exchangers = TRUE; + pr.reactions = TRUE; + pr.gas_phase = TRUE; + pr.ss_assemblage = TRUE; + pr.pp_assemblage = TRUE; + pr.surface = TRUE; + pr.exchange = TRUE; + pr.kinetics = TRUE; + pr.totals = TRUE; + pr.eh = TRUE; + pr.species = TRUE; + pr.saturation_indices = TRUE; + pr.irrev = TRUE; + pr.mix = TRUE; + pr.reaction = TRUE; + pr.use = TRUE; + pr.logfile = FALSE; + pr.punch = TRUE; + pr.status = TRUE; + pr.inverse = TRUE; + pr.dump = TRUE; + pr.user_print = TRUE; + pr.headings = TRUE; + pr.user_graph = TRUE; + pr.echo_input = TRUE; + pr.warnings = 100; + pr.initial_isotopes = TRUE; + pr.isotope_ratios = TRUE; + pr.isotope_alphas = TRUE; + pr.hdf = FALSE; + pr.alkalinity = FALSE; + */ + pr = pSrc->pr; + status_on = pSrc->status_on; + status_interval = pSrc->status_interval; + status_timer = clock(); + count_warnings = 0; + /* ---------------------------------------------------------------------- + * RATES + * ---------------------------------------------------------------------- */ + /* + rates = NULL; + count_rates = 0; + rate_m = 0; + rate_m0 = 0; + rate_time = 0; + rate_sim_time_start = 0; + rate_sim_time_end = 0; + rate_sim_time = 0; + rate_moles = 0; + initial_total_time = 0; + // auto rate_p + count_rate_p = 0; + */ + rates = (struct rate *) free_check_null(rates); + count_rates = pSrc->count_rates; + if (count_rates > 0) + { + rates = (struct rate *) PHRQ_malloc((size_t) count_rates * sizeof(struct rate)); + if (rates == NULL) malloc_error(); + for (int i = 0; i < count_rates; i++) + { + rates[i].name = string_hsave(pSrc->rates[i].name); + rates[i].commands = string_duplicate(pSrc->rates[i].commands); + rates[i].new_def = TRUE; + rates[i].linebase = NULL; + rates[i].varbase = NULL; + rates[i].loopbase = NULL; + } + } + /* ---------------------------------------------------------------------- + * USER PRINT COMMANDS + * ---------------------------------------------------------------------- */ + /* + user_print = NULL; + */ + { + user_print->name = NULL; + user_print->commands = NULL; + if (pSrc->user_print->commands != NULL) + { + user_print->commands = string_duplicate(pSrc->user_print->commands); + } + user_print->new_def = TRUE; + user_print->linebase = NULL; + user_print->varbase = NULL; + user_print->loopbase = NULL; + } + /* + user_punch = NULL; + */ + { + user_punch->name = NULL; + user_punch->commands = NULL; + if (pSrc->user_punch->commands != NULL) + { + user_punch->commands = string_duplicate(pSrc->user_punch->commands); + } + user_punch->new_def = TRUE; + user_punch->linebase = NULL; + user_punch->varbase = NULL; + user_punch->loopbase = NULL; + } + /* + user_punch_headings = NULL; + user_punch_count_headings = 0; + */ + user_punch_count_headings = pSrc->user_punch_count_headings; + if (user_punch_count_headings > 0) + { + user_punch_headings = (const char **) free_check_null(user_punch_headings); + user_punch_headings = (const char **) PHRQ_malloc((size_t) user_punch_count_headings * sizeof(char *)); + if (user_punch_headings == NULL) malloc_error(); + for (int i = 0; i < user_punch_count_headings; i++) + { + user_punch_headings[i] = string_hsave(pSrc->user_punch_headings[i]); + } + } + n_user_punch_index = pSrc->n_user_punch_index; + fpunchf_user_s_warning = pSrc->fpunchf_user_s_warning; + //fpunchf_user_buffer[0] = 0; + +#if defined PHREEQ98 + struct rate *user_graph; + char **user_graph_headings; + int user_graph_count_headings; +#endif +#if defined MULTICHART + // auto chart_handler; + chart_handler.Set_io(phrq_io); +#endif + /* ---------------------------------------------------------------------- + * GLOBAL DECLARATIONS + * ---------------------------------------------------------------------- */ + /* + error_string = NULL; + simulation = 0; + int state = INITIALIZE; + reaction_step = 0; + transport_step = 0; + transport_start = 0; + advection_step = 0; + stop_program = FALSE; + incremental_reactions = FALSE; + count_strings = 0; + array = NULL; + delta = NULL; + residual = NULL; + input_error = 0; + next_keyword = Keywords::KEY_NONE; + parse_error = 0; + paren_count = 0; + iterations = 0; + gamma_iterations = 0; + run_reactions_iterations= 0; + max_line = MAX_LINE; + line = NULL; + line_save = NULL; + LOG_10 = log(10.0); + debug_model = FALSE; + debug_prep = FALSE; + debug_set = FALSE; + debug_diffuse_layer = FALSE; + debug_inverse = FALSE; + */ +#ifdef SKIP +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); +#else + inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); +#endif +#endif + inv_tol_default = pSrc->inv_tol_default; + itmax = pSrc->itmax; + max_tries = pSrc->max_tries; +#ifdef SKIP +#ifdef USE_LONG_DOUBLE + /* from float.h, sets tolerance for cl1 routine */ + ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#else + ineq_tol = pow((double) 10, (double) -DBL_DIG); +#endif +#endif + ineq_tol = pSrc->ineq_tol; + convergence_tolerance = pSrc->convergence_tolerance; + step_size = pSrc->step_size; + pe_step_size = pSrc->pe_step_size; + step_size_now = step_size; + pe_step_size_now = pe_step_size; + pp_scale = pSrc->pp_scale; + pp_column_scale = pSrc->pp_column_scale; + diagonal_scale = pSrc->diagonal_scale; + mass_water_switch = pSrc->mass_water_switch; + delay_mass_water = pSrc->delay_mass_water; + dampen_ah2o = pSrc->dampen_ah2o; + slack = pSrc->slack; + censor = pSrc->censor; + aqueous_only = pSrc->aqueous_only; + negative_concentrations = pSrc->negative_concentrations; + calculating_deriv = FALSE; + numerical_deriv = FALSE; + count_total_steps = 0; + phast = FALSE; + /* + llnl_temp = 0; + llnl_count_temp = 0; + llnl_adh = 0; + llnl_count_adh = 0; + llnl_bdh = 0; + llnl_count_bdh = 0; + llnl_bdot = 0; + llnl_count_bdot = 0; + llnl_co2_coefs = 0; + llnl_count_co2_coefs = 0; + */ + llnl_count_temp = pSrc->llnl_count_temp; + if (llnl_count_temp > 0) + { + llnl_temp = (LDBLE *) PHRQ_malloc((size_t) llnl_count_temp * sizeof(LDBLE)); + if (llnl_temp == NULL) malloc_error(); + memcpy(llnl_temp, pSrc->llnl_temp, (size_t) llnl_count_temp * sizeof(LDBLE)); + } + llnl_count_adh = pSrc->llnl_count_adh; + if (llnl_count_adh > 0) + { + llnl_adh = (LDBLE *) PHRQ_malloc((size_t) llnl_count_adh * sizeof(LDBLE)); + if (llnl_adh == NULL) malloc_error(); + memcpy(llnl_adh, pSrc->llnl_adh, (size_t) llnl_count_adh * sizeof(LDBLE)); + } + llnl_count_bdh = pSrc->llnl_count_bdh; + if (llnl_count_bdh > 0) + { + llnl_bdh = (LDBLE *) PHRQ_malloc((size_t) llnl_count_bdh * sizeof(LDBLE)); + if (llnl_bdh == NULL) malloc_error(); + memcpy(llnl_bdh, pSrc->llnl_bdh, (size_t) llnl_count_bdh * sizeof(LDBLE)); + } + llnl_count_bdot = pSrc->llnl_count_bdot; + if (llnl_count_bdot > 0) + { + llnl_bdot = (LDBLE *) PHRQ_malloc((size_t) llnl_count_bdot * sizeof(LDBLE)); + if (llnl_bdot == NULL) malloc_error(); + memcpy(llnl_bdot, pSrc->llnl_bdot, (size_t) llnl_count_bdot * sizeof(LDBLE)); + } + llnl_count_co2_coefs = pSrc->llnl_count_co2_coefs; + if (llnl_count_co2_coefs > 0) + { + llnl_co2_coefs = (LDBLE *) PHRQ_malloc((size_t) llnl_count_co2_coefs * sizeof(LDBLE)); + if (llnl_co2_coefs == NULL) malloc_error(); + memcpy(llnl_co2_coefs, pSrc->llnl_co2_coefs, (size_t) llnl_count_co2_coefs * sizeof(LDBLE)); + } + //selected_output_file_name = NULL; + //dump_file_name = NULL; + //remove_unstable_phases = FALSE; + // auto screen_string; +#ifdef PHREEQCI_GUI + struct spread_sheet g_spread_sheet; +#endif + spread_length = 10; + /* ---------------------------------------------------------------------- */ + /* + * Hash definitions + */ + // auto strings_map; +#ifdef HASH + // auto strings_hash; +#endif + /* + elements_hash_table = NULL; + species_hash_table = NULL; + phases_hash_table = NULL; + logk_hash_table = NULL; + master_isotope_hash_table = NULL; + */ + /* ---------------------------------------------------------------------- + * ISOTOPES + * ---------------------------------------------------------------------- */ + /* + count_master_isotope = 0; + master_isotope = NULL; + max_master_isotope = MAX_ELTS; + */ + for (int i = 0; i < pSrc->count_master_isotope; i++) + { + struct master_isotope *master_isotope_ptr = master_isotope_store(pSrc->master_isotope[i]->name, FALSE); + memcpy(master_isotope_ptr, pSrc->master_isotope[i], sizeof(struct master_isotope)); + int n; + char * name = string_duplicate(pSrc->master_isotope[i]->master->elt->name); + master_isotope_ptr->master = master_search(name, &n); + if (master_isotope_ptr->master == NULL) + { + error_msg("Error in copy constructor for master_isotope.", STOP); + } + master_isotope_ptr->elt = element_store(pSrc->master_isotope[i]->elt->name); + master_isotope_ptr->units = string_hsave(pSrc->master_isotope[i]->units); + } + initial_solution_isotopes = pSrc->initial_solution_isotopes; + /* + count_calculate_value = 0; + calculate_value = NULL; + max_calculate_value = MAX_ELTS; + calculate_value_hash_table = NULL; + */ + for (int i = 0; i < pSrc->count_calculate_value; i++) + { + struct calculate_value *calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); + memcpy(calculate_value_ptr, pSrc->calculate_value[i], sizeof(struct calculate_value)); + calculate_value_ptr->value = pSrc->calculate_value[i]->value; + calculate_value_ptr->commands = string_duplicate(pSrc->calculate_value[i]->commands); + calculate_value_ptr->new_def = TRUE; + calculate_value_ptr->calculated = FALSE; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + } + /* + count_isotope_ratio = 0; + isotope_ratio = 0; + max_isotope_ratio = MAX_ELTS; + isotope_ratio_hash_table = 0; + */ + for (int i = 0; i < pSrc->count_isotope_ratio; i++) + { + struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); + isotope_ratio_ptr->isotope_name = string_hsave(pSrc->isotope_ratio[i]->isotope_name); + isotope_ratio_ptr->ratio = 0; + isotope_ratio_ptr->converted_ratio = -999.9; + } + /* + count_isotope_alpha = 0; + isotope_alpha = 0; + max_isotope_alpha = MAX_ELTS; + isotope_alpha_hash_table = 0; + */ + for (int i = 0; i < pSrc->count_isotope_alpha; i++) + { + struct isotope_alpha *isotope_alpha_ptr = isotope_alpha_store(pSrc->isotope_alpha[i]->name, FALSE); + isotope_alpha_ptr->named_logk = string_hsave(pSrc->isotope_alpha[i]->named_logk); + isotope_alpha_ptr->value = -999.9; + } + + phreeqc_mpi_myself = 0; + first_read_input = TRUE; + user_database = string_duplicate(pSrc->user_database); + have_punch_name = pSrc->have_punch_name; + print_density = pSrc->print_density; +#ifdef SKIP + zeros = NULL; + zeros_max = 1; + cell_pore_volume = 0; + cell_volume = 0; + cell_porosity = 0; + cell_saturation = 0; + sys = NULL; + count_sys = 0; + max_sys = 0; + sys_tot = 0; + +#ifdef PHREEQC2 + AA_basic = 0; + BB_basic = 0; + CC = 0; + I_m = 0; + rho_0 = 0; + eps_r = EPSILON; +#else + V_solutes = 0.0; + rho_0 = 0; + kappa_0 = 0.0; + p_sat = 0.0; + eps_r = EPSILON; + DH_A = 0.0; + DH_B = 0.0; + DH_Av = 0.0; + QBrn = 0.0; + ZBrn = 0.0; + dgdP = 0.0; +#endif + need_temp_msg = 0; + solution_mass = 0; + solution_volume = 0; + /* phqalloc.cpp ------------------------------- */ + s_pTail = NULL; + /* Basic */ + basic_interpreter = NULL; + /* cl1.cpp ------------------------------- */ + x_arg = NULL; + res_arg = NULL; + scratch = NULL; + x_arg_max = 0; + res_arg_max = 0; + scratch_max = 0; + /* dw.cpp ------------------------------- */ + /* COMMON /QQQQ/ */ + Q0 = 0; + Q5 = 0; + GASCON = 0.461522e0; + TZ = 647.073e0; + AA = 1.e0; + Z = 0; + DZ = 0; + Y = 0; + G1 = 11.e0; + G2 = 44.333333333333e0; + GF = 3.5e0; + B1 = 0; + B2 = 0; + B1T = 0; + B2T = 0; + B1TT = 0; + B2TT = 0; + /* gases.cpp ------------------------------- */ + a_aa_sum = 0; + b2 = 0; + b_sum = 0; + R_TK = 0; + /* input.cpp ------------------------------- */ + check_line_return = 0; + reading_db = FALSE; + /* integrate.cpp ------------------------------- */ + midpoint_sv = 0; + z_global = 0; + xd_global = 0; + alpha_global = 0; + /* inverse.cpp ------------------------------- */ + max_row_count = 50; + max_column_count = 50; + carbon = FALSE; + col_name = NULL; + row_name = NULL; + count_rows = 0; + count_optimize = 0; + col_phases = 0; + col_redox = 0; + col_epsilon = 0; + col_ph = 0; + col_water = 0; + col_isotopes = 0; + col_phase_isotopes = 0; + row_mb = 0; + row_fract = 0; + row_charge = 0; + row_carbon = 0; + row_isotopes = 0; + row_epsilon = 0; + row_isotope_epsilon = 0; + row_water = 0; + inv_zero = NULL; + array1 = 0; + inv_res = NULL; + inv_delta1 = NULL; + delta2 = NULL; + delta3 = NULL; + inv_cu = NULL; + delta_save = NULL; + min_delta = NULL; + max_delta = NULL; + inv_iu = NULL; + inv_is = NULL; + klmd = 0; + nklmd = 0; + n2d = 0; + kode = 0; + iter = 0; + toler = 0; + error = 0; + max_pct = 0; + scaled_error = 0; + master_alk = NULL; + row_back = NULL; + col_back = NULL; + good = NULL; + bad = NULL; + minimal = NULL; + max_good = 0; + max_bad = 0; + max_minimal = 0; + count_good = 0; + count_bad = 0; + count_minimal = 0; + count_calls = 0; + soln_bits = 0; + phase_bits = 0; + current_bits = 0; + temp_bits = 0; + netpath_file = NULL; + count_inverse_models = 0; + count_pat_solutions = 0; + for (int i = 0; i < 32; i++) + { + min_position[i] = 0; + max_position[i] = 0; + now[i] = 0; + } + /* kinetics.cpp ------------------------------- */ + count_pp = count_pg = count_ss = 0; + cvode_kinetics_ptr = NULL; + cvode_test = FALSE; + cvode_error = FALSE; + cvode_n_user = -99; + cvode_n_reactions = -99; + cvode_step_fraction = 0.0; + cvode_rate_sim_time = 0.0; + cvode_rate_sim_time_start = 0.0; + cvode_last_good_time = 0.0; + cvode_prev_good_time = 0.0; + cvode_last_good_y = NULL; + cvode_prev_good_y = NULL; + kinetics_machEnv = NULL; + kinetics_y = NULL; + kinetics_abstol = NULL; + kinetics_cvode_mem = NULL; + cvode_pp_assemblage_save= NULL; + cvode_ss_assemblage_save= NULL; + m_original = NULL; + m_temp = NULL; + rk_moles = NULL; + set_and_run_attempt = 0; + x0_moles = NULL; + /* model.cpp ------------------------------- */ + gas_in = FALSE; + min_value = 1e-10; + normal = NULL; + ineq_array = NULL; + res = NULL; + cu = NULL; + zero = NULL; + delta1 = NULL; + iu = NULL; + is = NULL; + back_eq = NULL; + normal_max = 0; + ineq_array_max = 0; + res_max = 0; + cu_max = 0; + zero_max = 0; + delta1_max = 0; + iu_max = 0; + is_max = 0; + back_eq_max = 0; + /* phrq_io_output.cpp ------------------------------- */ + forward_output_to_log = 0; + /* phreeqc_files.cpp ------------------------------- */ + default_data_base = string_duplicate("phreeqc.dat"); +#ifdef PHREEQ98 + int outputlinenr; + char *LogFileNameC; + char progress_str[512]; +#endif +#endif + /* Pitzer */ + pitzer_model = pSrc->pitzer_model; + sit_model = pSrc->sit_model; + pitzer_pe = pSrc->pitzer_pe; +#ifdef SKIP + full_pitzer = FALSE; + always_full_pitzer = FALSE; + ICON = TRUE; + IC = -1; + COSMOT = 0; + AW = 0; + VP = 0; + DW0 = 0; +#endif +#ifdef TODO_PITZER +#endif + + /* + pitz_params = NULL; + count_pitz_param = 0; + max_pitz_param = 100; + */ + for (int i = 0; i < pSrc->count_pitz_param; i++) + { + pitz_param_store(pSrc->pitz_params[i]); + } + + // auto pitz_param_map + /* + theta_params = 0; + count_theta_param = 0; + max_theta_param = 100; + use_etheta = TRUE; + OTEMP = 0.0; + A0 = 0; + spec = NULL; + cations = NULL; + anions = NULL; + neutrals = NULL; + count_cations = 0; + count_anions = 0; + count_neutrals = 0; + MAXCATIONS = 0; + FIRSTANION = 0; + MAXNEUTRAL = 0; + mcb0 = NULL; + mcb1 = NULL; + mcc0 = NULL; + IPRSNT = NULL; + M = NULL; + LGAMMA = NULL; + for (int i = 0; i < 23; i++) + { + BK[i] = 0.0; + DK[i] = 0.0; + } + */ + pitzer_tidy(); + +#ifdef PHREEQ98 + int connect_simulations, graph_initial_solutions; + int shifts_as_points; + int chart_type; + int ShowChart; + int RowOffset, ColumnOffset; +#endif + dummy = 0; + /* print.cpp ------------------------------- */ + /* + sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); + if (sformatf_buffer == NULL) + malloc_error(); + sformatf_buffer_size = 256; + */ +#ifdef PHREEQ98 + int colnr, rownr; + int graph_initial_solutions; + int prev_advection_step, prev_transport_step; /*, prev_reaction_step */ + /* int shifts_as_points; */ + int chart_type; + int AddSeries; + int FirstCallToUSER_GRAPH; +#endif + /* read.cpp */ + prev_next_char = NULL; +#if defined PHREEQ98 + int shifts_as_points; +#endif + /* read_class.cxx */ + // auto dump_info + // auto delete_info + // auto run_info + /* + run_info.Set_io(phrq_io); + */ + /* readtr.cpp */ + // auto dump_file_name_cpp; + /* sit.cpp ------------------------------- */ +#ifdef TODO_SIT + sit_params = NULL; + count_sit_param = 0; + max_sit_param = 100; + // auto sit_param_map + sit_A0 = 0; + sit_count_cations = 0; + sit_count_anions = 0; + sit_count_neutrals = 0; + sit_MAXCATIONS = 0; + sit_FIRSTANION = 0; + sit_MAXNEUTRAL = 0; + sit_IPRSNT = NULL; + sit_M = NULL; + sit_LGAMMA = NULL; +#endif +#ifdef SKIP + /* tidy.cpp ------------------------------- */ + a0 = 0; + a1 = 0; + kc = 0; + kb = 0; + /* tally.cpp ------------------------------- */ + t_buffer = NULL; + tally_count_component = 0; + tally_table = NULL; + count_tally_table_columns = 0; + count_tally_table_rows = 0; +#endif + /* transport.cpp ------------------------------- */ +#ifdef TODO_transport + sol_D = NULL; + sol_D_dbg = NULL; + J_ij = NULL; + J_ij_il = NULL; + J_ij_count_spec = 0; + m_s = NULL; + count_m_s = 0; + tot1_h = 0; + tot1_o = 0; + tot2_h = 0; + tot2_o = 0; + diffc_max = 0; + diffc_tr = 0; + J_ij_sum = 0; + transp_surf = FALSE; + heat_mix_array = NULL; + temp1 = NULL; + temp2 = NULL; + nmix = 0; + heat_nmix = 0; + heat_mix_f_imm = 0; + heat_mix_f_m = 0; + warn_MCD_X = 0; + warn_fixed_Surf = 0; +#endif +#ifdef PHREEQ98 + int AutoLoadOutputFile, CreateToC; + int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; + int outputlinenr; + int stop_calculations; + char err_str98[80]; +#endif +#ifdef SKIP + /* utilities.cpp ------------------------------- */ + spinner = 0; + // keycount; + for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + { + keycount.push_back(0); + } +#endif + this->tidy_model(); + return; +} diff --git a/Phreeqc.h b/Phreeqc.h index d67d70a0..9f4df466 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -62,6 +62,8 @@ class Phreeqc { public: Phreeqc(PHRQ_io *io = NULL); + Phreeqc(const Phreeqc &src); + void InternalCopy(const Phreeqc *pSrc); ~Phreeqc(void); public: @@ -830,6 +832,7 @@ protected: int elt_list_print(struct elt_list *elt_list_ptr); struct elt_list *elt_list_save(void); cxxNameDouble elt_list_NameDouble(void); + struct elt_list * NameDouble2elt_list(const cxxNameDouble &nd); public: enum entity_type get_entity_enum(char *name); struct inverse *inverse_alloc(void); @@ -869,6 +872,7 @@ public: int rate_sort(void); struct reaction *rxn_alloc(int ntokens); struct reaction *rxn_dup(struct reaction *rxn_ptr_old); + struct reaction * cxxChemRxn2rxn(cxxChemRxn &cr); LDBLE rxn_find_coef(struct reaction *r_ptr, const char *str); int rxn_free(struct reaction *rxn_ptr); int rxn_print(struct reaction *rxn_ptr); diff --git a/phreeqc/global_structures.h b/phreeqc/global_structures.h index fb52f070..c22aeed6 100644 --- a/phreeqc/global_structures.h +++ b/phreeqc/global_structures.h @@ -123,7 +123,6 @@ an equation */ #define MAX_PHASES 500 /* initial guess of number of phases defined */ #define MAX_S 500 /* default estimate for maximum number of species in aqueous model */ -#define MAX_STRINGS 3000 #define MAX_SUM_JACOB0 50 /* list used to calculate jacobian */ #define MAX_SUM_JACOB1 500 /* list used to calculate jacobian */ #define MAX_SUM_JACOB2 500 /* list used to calculate jacobian */ diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 384700b6..2f98ff10 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -74,7 +74,6 @@ initialize(void) max_mb_unknowns = MAX_TRXN; max_phases = MAX_PHASES; max_s = MAX_S; - max_strings = MAX_STRINGS; max_trxn = MAX_TRXN; max_logk = MAX_S; max_master_isotope = MAX_ELTS; diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 28584af9..f5d56b96 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -662,6 +662,29 @@ elt_list_save(void) elt_list_ptr[count_elts].elt = NULL; return (elt_list_ptr); } +/* ---------------------------------------------------------------------- */ +struct elt_list * Phreeqc:: +NameDouble2elt_list(const cxxNameDouble &nd) +/* ---------------------------------------------------------------------- */ +{ +/* + * Takes NameDouble allocates space and fills new elt_list struct + */ + struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((nd.size() + 1) * sizeof(struct elt_list)); + if (elt_list_ptr == NULL) + malloc_error(); + cxxNameDouble::const_iterator it = nd.begin(); + int i = 0; + for( ; it != nd.end(); it++) + { + elt_list_ptr[i].elt = element_store(it->first.c_str()); + elt_list_ptr[i].coef = it->second; + i++; + } + elt_list_ptr[i].elt = NULL; + elt_list_ptr[i].coef = 0; + return (elt_list_ptr); +} /* ********************************************************************** * * Routines related to structure "inverse" @@ -1734,7 +1757,45 @@ rxn_dup(struct reaction *rxn_ptr_old) return (rxn_ptr_new); } +/* ---------------------------------------------------------------------- */ +struct reaction * Phreeqc:: +cxxChemRxn2rxn(cxxChemRxn &cr) +/* ---------------------------------------------------------------------- */ +{ +/* + * mallocs space for a reaction and copies the cxxChemRxn to a struct reaction + * + * Return: rxn_ptr_new, pointer to new structure + */ + for (int i = 0; i < cr.Get_tokens().size(); i++) + { + cr.Get_tokens()[i].s = s_store(cr.Get_tokens()[i].s->name, cr.Get_tokens()[i].s->z, FALSE); + if (cr.Get_tokens()[i].name != NULL) + { + cr.Get_tokens()[i].name = string_hsave(cr.Get_tokens()[i].name); + } + else + { + cr.Get_tokens()[i].name = string_hsave(cr.Get_tokens()[i].s->name); + } + } + count_trxn = 0; + trxn_add(cr, 1.0, 1); + + struct reaction *rxn_ptr_new = rxn_alloc(count_trxn + 1); + trxn_copy(rxn_ptr_new); + + // cleanup pointers for copy operator name, and s may point into another instance + + for (int i = 0; rxn_ptr_new->token[i].s != NULL; i++) + { + rxn_ptr_new->token[i].name = string_hsave(rxn_ptr_new->token[i].name); + double z = rxn_ptr_new->token[i].s->z; + rxn_ptr_new->token[i].s = s_store(rxn_ptr_new->token[i].name, z, false); + } + return (rxn_ptr_new); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: rxn_find_coef(struct reaction * r_ptr, const char *str) From d4721e493ea4a2579c9fb1ba08953fd5ce9c4f2f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Oct 2012 00:39:14 +0000 Subject: [PATCH 0571/1077] Wrote rebalance_load for MPI_Bcast However, now need 4 configurations for IPhreeqc Debug/Release USE_MPI. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7036 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 2 +- ExchComp.h | 2 +- Exchange.cxx | 2 +- Exchange.h | 2 +- GasPhase.cxx | 2 +- GasPhase.h | 2 +- KineticsComp.cxx | 2 +- KineticsComp.h | 2 +- NameDouble.cxx | 2 +- NameDouble.h | 3 +- PPassemblage.cxx | 2 +- PPassemblage.h | 2 +- PPassemblageComp.cxx | 2 +- PPassemblageComp.h | 2 +- SS.cxx | 2 +- SS.h | 2 +- SSassemblage.cxx | 2 +- SSassemblage.h | 2 +- SScomp.cxx | 2 +- SScomp.h | 2 +- Solution.cxx | 2 +- Solution.h | 2 +- StorageBin.cxx | 82 +++++++++++++++++++++++++++++++++++++++++++- Surface.cxx | 2 +- Surface.h | 2 +- SurfaceCharge.cxx | 2 +- SurfaceCharge.h | 2 +- SurfaceComp.cxx | 2 +- SurfaceComp.h | 2 +- cxxKinetics.cxx | 2 +- cxxKinetics.h | 2 +- 31 files changed, 112 insertions(+), 31 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 33ded036..722157d2 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -406,7 +406,7 @@ cxxExchComp::multiply(LDBLE extensive) this->phase_proportion *= extensive; } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxExchComp::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/ExchComp.h b/ExchComp.h index c2ea9494..33a838a1 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -106,7 +106,7 @@ class cxxExchComp: public PHRQ_base void multiply(LDBLE extensive); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/Exchange.cxx b/Exchange.cxx index f7bda656..79ea2ca9 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -375,7 +375,7 @@ cxxExchange::add(const cxxExchange & addee, LDBLE extensive) } this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP /* ---------------------------------------------------------------------- */ void cxxExchange::mpi_pack(std::vector < int >&ints, diff --git a/Exchange.h b/Exchange.h index 44f48f9d..031b4c79 100644 --- a/Exchange.h +++ b/Exchange.h @@ -47,7 +47,7 @@ public: const cxxNameDouble & Get_totals() const; -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/GasPhase.cxx b/GasPhase.cxx index 0519a2b2..d0ff2a0d 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -520,7 +520,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxGasPhase::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/GasPhase.h b/GasPhase.h index d703cfe9..02d9f4e7 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -33,7 +33,7 @@ class cxxGasPhase:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/KineticsComp.cxx b/KineticsComp.cxx index a764e5e0..4839b40d 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -282,7 +282,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxKineticsComp::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/KineticsComp.h b/KineticsComp.h index 9fdcfbad..52742259 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -52,7 +52,7 @@ public: const std::vector < LDBLE > &Get_d_params(void)const {return d_params;}; std::vector < std::string > &Get_c_params(void) {return c_params;}; -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); #endif diff --git a/NameDouble.cxx b/NameDouble.cxx index 8c5fd5d9..255b11b4 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -589,7 +589,7 @@ cxxNameDouble::sort_second(void) return myvec; } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxNameDouble::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/NameDouble.h b/NameDouble.h index 4105da9a..0491bbcb 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -54,10 +54,11 @@ class cxxNameDouble:public { (*this)[str] = d; } - +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); +#endif enum ND_TYPE type; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index b11b9ff7..b347aad9 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -234,7 +234,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP /* ---------------------------------------------------------------------- */ void cxxPPassemblage::mpi_pack(std::vector < int >&ints, diff --git a/PPassemblage.h b/PPassemblage.h index 6e29930b..9fa5ba10 100644 --- a/PPassemblage.h +++ b/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); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 35e22ecf..2ea55bed 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -312,7 +312,7 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/PPassemblageComp.h b/PPassemblageComp.h index 254e130e..d6e9e33a 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -62,7 +62,7 @@ class cxxPPassemblageComp: public PHRQ_base void add(const cxxPPassemblageComp & comp, LDBLE extensive); void multiply(LDBLE extensive); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/SS.cxx b/SS.cxx index d692d38b..6f2198da 100644 --- a/SS.cxx +++ b/SS.cxx @@ -443,7 +443,7 @@ cxxSS::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxSS::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/SS.h b/SS.h index 24932d0d..0ef1571d 100644 --- a/SS.h +++ b/SS.h @@ -58,7 +58,7 @@ class cxxSS: public PHRQ_base return (this->totals); }; -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/SSassemblage.cxx b/SSassemblage.cxx index cc0c194a..7818a682 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -223,7 +223,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) break; } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP /* ---------------------------------------------------------------------- */ void cxxSSassemblage::mpi_pack(std::vector < int >&ints, diff --git a/SSassemblage.h b/SSassemblage.h index 1a514836..dcece5a9 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -32,7 +32,7 @@ public: void read_raw(CParser & parser, bool check = true); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/SScomp.cxx b/SScomp.cxx index 15ec60f0..b9c9e203 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -247,7 +247,7 @@ cxxSScomp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxSScomp::mpi_pack(std::vector < int >&ints, std::vector < double >&doubles) diff --git a/SScomp.h b/SScomp.h index 0b0f4b55..5b61faa8 100644 --- a/SScomp.h +++ b/SScomp.h @@ -45,7 +45,7 @@ class cxxSScomp: public PHRQ_base void multiply(double extensive); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); #endif diff --git a/Solution.cxx b/Solution.cxx index a3640bc9..63a57b0a 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1326,7 +1326,7 @@ cxxSolution::Get_master_activity(char *string) const } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP /* ---------------------------------------------------------------------- */ void cxxSolution::mpi_pack(std::vector < int >&ints, diff --git a/Solution.h b/Solution.h index b529728a..793a6983 100644 --- a/Solution.h +++ b/Solution.h @@ -106,7 +106,7 @@ class cxxSolution:public cxxNumKeyword void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); void Update_activities(const cxxNameDouble &original_tot); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); void mpi_send(int task_number); diff --git a/StorageBin.cxx b/StorageBin.cxx index 1d84ffc4..6568c9a8 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -998,7 +998,7 @@ cxxStorageBin::cxxStorageBin2system(Phreeqc * phreeqc_ptr, int n) } #endif -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxStorageBin::mpi_send(int n, int task_number) { @@ -1581,3 +1581,83 @@ cxxStorageBin::Set_System(int i) this->system.Set_Pressure(Utilities::Rxn_find(this->Pressures, i)); } } +#ifdef USE_MPI +void +cxxStorageBin::mpi_send(int n, int task_number) +{ + // + // Send data for system n to task_number + // + + std::ostringstream raw_stream; + + // Solution + if (this->Get_Solution(n) != NULL) + { + this->Get_Solution(n)->dump_raw(raw_stream, 0); + } + + // Exchanger + if (this->Get_Exchange(n) != NULL) + { + this->Get_Exchange(n)->dump_raw(raw_stream, 0); + } + + // GasPhase + if (this->Get_GasPhase(n) != NULL) + { + this->Get_GasPhase(n)->dump_raw(raw_stream, 0); + } + + // Kinetics + if (this->Get_Kinetics(n) != NULL) + { + this->Get_Kinetics(n)->dump_raw(raw_stream, 0); + } + + // PPassemblages + if (this->Get_PPassemblage(n) != NULL) + { + this->Get_PPassemblage(n)->dump_raw(raw_stream, 0); + } + + // SSassemblages + if (this->Get_SSassemblage(n) != NULL) + { + this->Get_SSassemblage(n)->dump_raw(raw_stream, 0); + } + + // Surfaces + if (this->Get_Surface(n) != NULL) + { + this->Get_Surface(n)->dump_raw(raw_stream, 0); + } + + // Send string + int size = raw_stream.str().size(); + MPI_Send(&size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); + MPI_Send((void *) raw_stream.str().c_str(), size, MPI_CHARACTER, task_number, 0, MPI_COMM_WORLD); +} +void +cxxStorageBin::mpi_recv(int task_number) +{ + // + // Recieve raw data from task_number + // + + MPI_Status mpi_status; + int size; + MPI_Recv(&size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); + + std::vector raw_buffer; + raw_buffer.resize(size + 1); + MPI_Recv((void *) raw_buffer.data(), size, MPI_CHARACTER, task_number, 0, MPI_COMM_WORLD, &mpi_status); + raw_buffer[size] = '\0'; + + std::istringstream raw_stream(raw_buffer.data()); + CParser parser(raw_stream); + parser.set_echo_file(CParser::EO_NONE); + parser.set_echo_stream(CParser::EO_NONE); + this->read_raw(parser); +} +#endif \ No newline at end of file diff --git a/Surface.cxx b/Surface.cxx index c97bf194..7009abf6 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -584,7 +584,7 @@ cxxSurface::read_raw(CParser & parser, bool check) this->Sort_comps(); } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP /* ---------------------------------------------------------------------- */ void cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/Surface.h b/Surface.h index 08333023..bcf16388 100644 --- a/Surface.h +++ b/Surface.h @@ -39,7 +39,7 @@ public: const cxxSurfaceCharge *Find_charge(const std::string str)const; void Sort_comps(); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 3c5dba4f..2e09c3fc 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -374,7 +374,7 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxSurfaceCharge::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/SurfaceCharge.h b/SurfaceCharge.h index b3204267..772de64a 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -75,7 +75,7 @@ public: void add(const cxxSurfaceCharge & comp, LDBLE extensive); void multiply(LDBLE extensive); -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 86ba5731..040ecaa5 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -356,7 +356,7 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxSurfaceComp::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/SurfaceComp.h b/SurfaceComp.h index dc324f7e..6a264993 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -47,7 +47,7 @@ public: const std::string &Get_master_element() const {return this->master_element;} void Set_master_element(const char * f) {this->master_element = f ? f : "";} -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); #endif diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 369fa882..32b7193b 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -447,7 +447,7 @@ cxxKinetics::read_raw(CParser & parser, bool check) } } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxKinetics::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) diff --git a/cxxKinetics.h b/cxxKinetics.h index bf02091c..ffcb873a 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -53,7 +53,7 @@ class cxxKinetics:public cxxNumKeyword cxxKineticsComp * Find(const std::string &str); LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const; -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); #endif From e13a4d80399c79bd49be394ef17230d64236575c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Oct 2012 21:45:30 +0000 Subject: [PATCH 0572/1077] Think rewrite of rebalance is working, need to fix zone chemistry file for mpi. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7037 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- Solution.cxx | 5 +++-- StorageBin.cxx | 4 ++-- StorageBin.h | 2 +- phreeqc/structures.cpp | 2 +- phreeqc/tidy.cpp | 45 ++++++++++++++++++++++-------------------- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 9f4df466..bee41187 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -929,7 +929,7 @@ public: static int surface_compare_int(const void *ptr1, const void *ptr2); static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +#if defined(USE_MPI_SKIP) && defined(HDF5_CREATE) && defined(MERGE_FILES) void MergeFinalize(void); #endif struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); diff --git a/Solution.cxx b/Solution.cxx index 63a57b0a..45a96960 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -6,7 +6,7 @@ #endif -#ifdef USE_MPI +#ifdef USE_MPI_SKIP //MPICH seems to require mpi.h to be first #include #endif @@ -97,12 +97,12 @@ cxxSolution::cxxSolution(std::map < int, cxxSolution > &solutions, // : cxxNumKeyword(io) { - // // Zero out solution data // this->zero(); this->n_user = this->n_user_end = l_n_user; + this->new_def = false; // // Mix solutions // @@ -124,6 +124,7 @@ cxxSolution::cxxSolution(std::map < int, cxxSolution > &solutions, this->add(*cxxsoln_ptr1, it->second); } } + } cxxSolution::~cxxSolution() { diff --git a/StorageBin.cxx b/StorageBin.cxx index 6568c9a8..77535f2e 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -4,7 +4,7 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#ifdef USE_MPI +#ifdef USE_MPI_SKIP //MPICH seems to require mpi.h to be first #include #endif @@ -1581,7 +1581,7 @@ cxxStorageBin::Set_System(int i) this->system.Set_Pressure(Utilities::Rxn_find(this->Pressures, i)); } } -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void cxxStorageBin::mpi_send(int n, int task_number) { diff --git a/StorageBin.h b/StorageBin.h index d64be7dd..1af2370b 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -114,7 +114,7 @@ class cxxStorageBin: public PHRQ_base std::map < int, cxxPressure > &Get_Pressures(); cxxSystem & Get_system(void) {return system;}; -#ifdef USE_MPI +#ifdef USE_MPI_SKIP void mpi_send(int n, int task_number); void mpi_recv(int task_number); #endif diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index f5d56b96..ba31db62 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -346,7 +346,7 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); -#if defined(USE_MPI) && defined(HDF5_CREATE) && defined(MERGE_FILES) +#if defined(USE_MPI_SKIP) && defined(HDF5_CREATE) && defined(MERGE_FILES) MergeFinalize(); #endif diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 6f2ac225..2c4dff09 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -2546,36 +2546,39 @@ tidy_solutions(void) if (solution_ref.Get_new_def()) { cxxISolution *initial_data_ptr = solution_ref.Get_initial_data(); - std::map::iterator iit = initial_data_ptr->Get_comps().begin(); - for ( ; iit != initial_data_ptr->Get_comps().end(); iit++) + if (initial_data_ptr != NULL) { - cxxISolutionComp &comp_ref = iit->second; - if (strcmp(comp_ref.Get_description().c_str(), "H(1)") == 0 || - strcmp(comp_ref.Get_description().c_str(), "E") == 0) + std::map::iterator iit = initial_data_ptr->Get_comps().begin(); + for ( ; iit != initial_data_ptr->Get_comps().end(); iit++) { - comp_ref.Set_moles(0.0); - continue; - } - std::string token; - std::string description = comp_ref.Get_description(); - std::string::iterator b = description.begin(); - std::string::iterator e = description.end(); - CParser::copy_token(token, b, e); + cxxISolutionComp &comp_ref = iit->second; + if (strcmp(comp_ref.Get_description().c_str(), "H(1)") == 0 || + strcmp(comp_ref.Get_description().c_str(), "E") == 0) + { + comp_ref.Set_moles(0.0); + continue; + } + std::string token; + std::string description = comp_ref.Get_description(); + std::string::iterator b = description.begin(); + std::string::iterator e = description.end(); + CParser::copy_token(token, b, e); - master_ptr = master_bsearch(token.c_str()); - if (master_ptr == NULL) - { - error_string = sformatf( + master_ptr = master_bsearch(token.c_str()); + if (master_ptr == NULL) + { + error_string = sformatf( "Could not find element in database, %s.\n\tConcentration is set to zero.", comp_ref.Get_description().c_str()); - warning_msg(error_string); - comp_ref.Set_input_conc(0.0); - continue; + warning_msg(error_string); + comp_ref.Set_input_conc(0.0); + continue; + } } } } } - + return (OK); } /* ---------------------------------------------------------------------- */ From 98baecfe0ddb10481d5a2b1c3edad9206f4c6a94 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Oct 2012 21:55:04 +0000 Subject: [PATCH 0573/1077] Added two new functions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7038 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 26 +++++++++- PBasic.h | 4 +- Phreeqc.h | 2 + phreeqc/basicsubs.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 0e51b783..d1f1669c 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1283,6 +1283,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("EQUI"); break; + case tokequi_delta: + output_msg("EQUI_DELTA"); + break; + case tokgas: output_msg("GAS"); break; @@ -1295,6 +1299,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("KIN"); break; + case tokkin_delta: + output_msg("KIN_DELTA"); + break; + case toks_s: output_msg("S_S"); break; @@ -2192,6 +2200,13 @@ factor(struct LOC_exec * LINK) } break; + case tokequi_delta: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->equi_phase_delta(str); + } + break; + case tokkin: { const char * str = stringfactor(STR1, LINK); @@ -2199,6 +2214,13 @@ factor(struct LOC_exec * LINK) } break; + case tokkin_delta: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->kinetics_moles_delta(str); + } + break; + case tokgas: { const char * str = stringfactor(STR1, LINK); @@ -6430,7 +6452,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("qbrn", PBasic::tokqbrn), std::map::value_type("kappa", PBasic::tokkappa), std::map::value_type("gfw", PBasic::tokgfw), - std::map::value_type("soln_vol", PBasic::toksoln_vol) + std::map::value_type("soln_vol", PBasic::toksoln_vol), + std::map::value_type("equi_delta", PBasic::tokequi_delta), + std::map::value_type("kin_delta", PBasic::tokkin_delta) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index f25f6aed..97451760 100644 --- a/PBasic.h +++ b/PBasic.h @@ -310,7 +310,9 @@ public: tokqbrn, tokkappa, tokgfw, - toksoln_vol + toksoln_vol, + tokequi_delta, + tokkin_delta }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index bee41187..9cec9ffd 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -93,6 +93,7 @@ public: LDBLE calc_surface_charge(const char *surface_name); LDBLE diff_layer_total(const char *total_name, const char *surface_name); LDBLE equi_phase(const char *phase_name); + LDBLE equi_phase_delta(const char *phase_name); LDBLE find_gas_comp(const char *gas_comp_name); LDBLE find_gas_p(void); LDBLE find_gas_vm(void); @@ -103,6 +104,7 @@ public: char * iso_unit(const char *total_name); LDBLE iso_value(const char *total_name); LDBLE kinetics_moles(const char *kinetics_name); + LDBLE kinetics_moles_delta(const char *kinetics_name); LDBLE log_activity(const char *species_name); LDBLE log_molality(const char *species_name); LDBLE molality(const char *species_name); diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 796cc327..353af799 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -896,6 +896,76 @@ equi_phase(const char *phase_name) } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: +equi_phase_delta(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + int j; + + if (use.Get_pp_assemblage_in() == FALSE || use.Get_pp_assemblage_ptr() == NULL) + return (0); + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + if (strcmp_nocase(x[j]->pp_assemblage_comp_name, phase_name) == 0) + { + break; + } + } +/* + * Print pure phase assemblage data + */ + cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); + if (j == count_unknowns) + { + /* if not an unknown */ + std::map::iterator it; + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + { + if (strcmp_nocase + (it->second.Get_name().c_str(), phase_name) == 0) + { + cxxPPassemblageComp * comp_ptr = &(it->second); + if (state != TRANSPORT && state != PHAST) + { + //LDBLE moles = it->second.Get_moles(); + //LDBLE delta_moles = moles - comp_ptr->Get_moles() - + // comp_ptr->Get_delta(); + return(0); + } + else + { + LDBLE moles = it->second.Get_moles(); + LDBLE delta_moles = moles - comp_ptr->Get_initial_moles(); + return(delta_moles); + } + } + } + } + else + { + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + if (state != TRANSPORT && state != PHAST) + { + LDBLE moles = x[j]->moles; + LDBLE delta_moles = + x[j]->moles - comp_ptr->Get_moles() - + comp_ptr->Get_delta(); + return(delta_moles); + } + else + { + LDBLE moles = x[j]->moles; + LDBLE delta_moles = + x[j]->moles - comp_ptr->Get_initial_moles(); + return(delta_moles); + } + } + return (0); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: find_gas_comp(const char *gas_comp_name) /* ---------------------------------------------------------------------- */ { @@ -1127,7 +1197,44 @@ kinetics_moles(const char *kinetics_name) warning_msg(error_string); return (0); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +kinetics_moles_delta(const char *kinetics_name) +/* ---------------------------------------------------------------------- */ +{ + if (use.Get_kinetics_in() == FALSE || use.Get_kinetics_ptr() == NULL) + return (0); + for (size_t i = 0; i < use.Get_kinetics_ptr()->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp *kinetics_comp_ptr = &(use.Get_kinetics_ptr()->Get_kinetics_comps()[i]); + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), kinetics_name) == 0) + { + //return (kinetics_comp_ptr->Get_m()); + + if (state != TRANSPORT && state != PHAST) + { + //LDBLE moles = kinetics_comp_ptr->Get_m(); + LDBLE delta_moles = - kinetics_comp_ptr->Get_moles(); + return delta_moles; + } + else + { + //moles = kinetics_comp_ptr->Get_m(); + LDBLE delta_moles = + kinetics_comp_ptr->Get_m() - + kinetics_comp_ptr->Get_initial_moles(); + return delta_moles; + } + } + } + + //error_string = sformatf( "No data for rate %s in KINETICS keyword.", + // kinetics_name); + //warning_msg(error_string); + return (0); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: log_activity(const char *species_name) From 63a1879a3d027fec44c92ad7f38c81cef37516c4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Oct 2012 19:23:57 +0000 Subject: [PATCH 0574/1077] Finished zone flow chemistry write for MPI. Not tested. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7042 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/read.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index 8177dadc..a01c3826 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -1953,7 +1953,7 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) iso_ptr->master = NULL; iso_ptr->primary = NULL; } - inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = isotopes.size(); + inverse_ptr->phases[inverse_ptr->count_phases].count_isotopes = (int) isotopes.size(); } else { @@ -10563,7 +10563,7 @@ cleanup_after_parser(CParser &parser) size_t l = (l1 > l2) ? l1 : l2; if (l >= (size_t) max_line) { - max_line = l * 2; + max_line = (int) l * 2; line_save = (char *) PHRQ_realloc(line_save, (size_t) max_line * sizeof(char)); if (line_save == NULL) From 9d4bb2e173ec072ca5f82f83a53849fe4596b415 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Oct 2012 23:16:27 +0000 Subject: [PATCH 0575/1077] PHREEQC should now have no USE_MPI Also no MERGE_FILES in PHREEQC Not sure about deallocates in worker_closef git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7045 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 38 ----- ExchComp.h | 5 - Exchange.cxx | 46 ------ Exchange.h | 4 - GasPhase.cxx | 48 ------ GasPhase.h | 5 - KineticsComp.cxx | 41 ----- KineticsComp.h | 4 - NameDouble.cxx | 60 +------ NameDouble.h | 5 - PPassemblage.cxx | 45 ------ PPassemblage.h | 4 - PPassemblageComp.cxx | 40 ----- PPassemblageComp.h | 5 - Phreeqc.h | 4 +- SS.cxx | 36 ----- SS.h | 4 - SSassemblage.cxx | 43 ----- SSassemblage.h | 4 - SScomp.cxx | 39 ----- SScomp.h | 4 - Solution.cxx | 282 --------------------------------- Solution.h | 7 - StorageBin.cxx | 345 ----------------------------------------- StorageBin.h | 5 +- Surface.cxx | 75 --------- Surface.h | 5 - SurfaceCharge.cxx | 41 ----- SurfaceCharge.h | 5 - SurfaceComp.cxx | 41 ----- SurfaceComp.h | 5 - cxxKinetics.cxx | 68 -------- cxxKinetics.h | 4 - phreeqc/input.cpp | 2 +- phreeqc/inverse.cpp | 4 +- phreeqc/prep.cpp | 16 +- phreeqc/structures.cpp | 4 - 37 files changed, 14 insertions(+), 1379 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 722157d2..4ebd1f07 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -406,44 +406,6 @@ cxxExchComp::multiply(LDBLE extensive) this->phase_proportion *= extensive; } -#ifdef USE_MPI_SKIP -void -cxxExchComp::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - ints.push_back(dictionary.string2int(this->formula)); - doubles.push_back(this->moles); - this->formula_totals.mpi_pack(ints, doubles); - this->totals.mpi_pack(ints, doubles); - doubles.push_back(this->la); - doubles.push_back(this->charge_balance); - ints.push_back(dictionary.string2int(this->phase_name)); - doubles.push_back(this->phase_proportion); - ints.push_back(dictionary.string2int(this->rate_name)); - doubles.push_back(this->formula_z); -} - -void -cxxExchComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->formula = dictionary.int2stdstring(ints[i++]); - this->moles = doubles[d++]; - this->formula_totals.mpi_unpack(ints, &i, doubles, &d); - this->totals.mpi_unpack(ints, &i, doubles, &d); - this->la = doubles[d++]; - this->charge_balance = doubles[d++]; - this->phase_name = dictionary.int2stdstring(ints[i++]); - this->phase_proportion = doubles[d++]; - this->rate_name = dictionary.int2stdstring(ints[i++]); - this->formula_z = doubles[d++]; - *ii = i; - *dd = d; -} -#endif const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("formula"), // 0 std::vector< std::string >::value_type("moles"), // 1 diff --git a/ExchComp.h b/ExchComp.h index 33a838a1..a0d4fe65 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -105,11 +105,6 @@ class cxxExchComp: public PHRQ_base void add(const cxxExchComp & comp, LDBLE extensive); void multiply(LDBLE extensive); - -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif protected: std::string formula; // EXCHANGE_MODIFY candidates diff --git a/Exchange.cxx b/Exchange.cxx index 79ea2ca9..7a849213 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -375,52 +375,6 @@ cxxExchange::add(const cxxExchange & addee, LDBLE extensive) } this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; } -#ifdef USE_MPI_SKIP -/* ---------------------------------------------------------------------- */ -void -cxxExchange::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -/* ---------------------------------------------------------------------- */ -{ - /* int n_user; */ - ints.push_back(this->n_user); - - ints.push_back((int) this->pitzer_exchange_gammas); - ints.push_back((int) this->exchComps.size()); - for (std::map < std::string, cxxExchComp >::iterator it = this->exchComps.begin(); - it != this->exchComps.end(); it++) - { - (*it).second.mpi_pack(ints, doubles); - } -} - -/* ---------------------------------------------------------------------- */ -void -cxxExchange::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -/* ---------------------------------------------------------------------- */ -{ - int i = *ii; - int d = *dd; - /* int n_user; */ - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - - - this->pitzer_exchange_gammas = (ints[i++] == TRUE); - int count = ints[i++]; - this->exchComps.clear(); - for (int n = 0; n < count; n++) - { - cxxExchComp ec; - ec.mpi_unpack(ints, &i, doubles, &d); - std::string str(ec.get_formula()); - this->exchComps[str] = ec; - } - *ii = i; - *dd = d; -} -#endif void cxxExchange::totalize() { diff --git a/Exchange.h b/Exchange.h index 031b4c79..81c694cf 100644 --- a/Exchange.h +++ b/Exchange.h @@ -47,10 +47,6 @@ public: const cxxNameDouble & Get_totals() const; -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif protected: void add(const cxxExchange & addee, LDBLE extensive); // not written diff --git a/GasPhase.cxx b/GasPhase.cxx index d0ff2a0d..8e969239 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -520,54 +520,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxGasPhase::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - ints.push_back(this->n_user); - this->gasPhaseComps.mpi_pack(ints, doubles); - if (this->type == cxxGasPhase::GP_PRESSURE) - { - ints.push_back(0); - } - else - { - ints.push_back(1); - } - doubles.push_back(this->total_p); - doubles.push_back(this->volume); - doubles.push_back(this->v_m); - ints.push_back((pr_in) ? 1 : 0); -} - -void -cxxGasPhase::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - int i = *ii; - int d = *dd; - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - this->gasPhaseComps.mpi_unpack(ints, &i, doubles, &d); - int n = ints[i++]; - if (n == 0) - { - this->type = cxxGasPhase::GP_PRESSURE; - } - else - { - this->type = cxxGasPhase::GP_VOLUME; - } - this->total_p = doubles[d++]; - this->volume = doubles[d++]; - this->v_m = doubles[d++]; - n = ints[i++]; - this->pr_in = (n == 1) ? true : false; - *ii = i; - *dd = d; -} -#endif void cxxGasPhase::totalize(Phreeqc * phreeqc_ptr) { diff --git a/GasPhase.h b/GasPhase.h index 02d9f4e7..d3664041 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -33,11 +33,6 @@ class cxxGasPhase:public cxxNumKeyword void read_raw(CParser & parser, bool check = true); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif - void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 4839b40d..e2b2dc53 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -282,47 +282,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxKineticsComp::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - ints.push_back(dictionary.string2int(this->rate_name)); - this->namecoef.mpi_pack(ints, doubles); - doubles.push_back(this->tol); - doubles.push_back(this->m); - doubles.push_back(this->m0); - doubles.push_back(this->moles); - ints.push_back((int) this->d_params.size()); - for (std::vector < LDBLE >::iterator it = this->d_params.begin(); - it != this->d_params.end(); it++) - { - doubles.push_back(*it); - } -} -void -cxxKineticsComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->rate_name = dictionary.int2stdstring(ints[i++]); - this->namecoef.mpi_unpack(ints, &i, doubles, &d); - this->tol = doubles[d++]; - this->m = doubles[d++]; - this->m0 = doubles[d++]; - this->moles = doubles[d++]; - int n = ints[i++]; - this->d_params.clear(); - for (int j = 0; j < n; j++) - { - this->d_params.push_back(doubles[d++]); - } - *ii = i; - *dd = d; -} -#endif void cxxKineticsComp::add(const cxxKineticsComp & addee, LDBLE extensive) { diff --git a/KineticsComp.h b/KineticsComp.h index 52742259..704c8d17 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -52,10 +52,6 @@ public: const std::vector < LDBLE > &Get_d_params(void)const {return d_params;}; std::vector < std::string > &Get_c_params(void) {return c_params;}; -#ifdef USE_MPI_SKIP - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); -#endif void add(const cxxKineticsComp & comp, LDBLE extensive); void multiply(LDBLE extensive); diff --git a/NameDouble.cxx b/NameDouble.cxx index 255b11b4..c6a64027 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -589,62 +589,4 @@ cxxNameDouble::sort_second(void) return myvec; } -#ifdef USE_MPI_SKIP -void -cxxNameDouble::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - ints.push_back((int) (*this).size()); - for (const_iterator it = (*this).begin(); it != (*this).end(); it++) - { - int n = dictionary.string2int(it->first); - ints.push_back(n); - doubles.push_back(it->second); - } -} -void -cxxNameDouble::mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - int i = *ii; - int d = *dd; - extern cxxDictionary dictionary; - //ints.push_back( (*this).size() ); - ints[i++] = (int) this->size(); - for (const_iterator it = this->begin(); it != this->end(); it++) - { - int n = dictionary.string2int(it->first); - if (n < 0) - { - std::cerr << it->first << "\n"; - error_msg("Name in NameDouble was not defined in dictionary?\n", - STOP); - } - ints[i++] = n; - doubles[d++] = it->second; - } - *ii = i; - *dd = d; -} -void -cxxNameDouble::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - int i = *ii; - int d = *dd; - extern cxxDictionary dictionary; - this->clear(); - int count = ints[i++]; - for (int j = 0; j < count; j++) - { - int n = ints[i++]; - assert(n >= 0); - std::string str = dictionary.int2stdstring(n); - if (str.size() != 0) - { - (*this)[str] = doubles[d++]; - } - } - *ii = i; - *dd = d; -} -#endif + diff --git a/NameDouble.h b/NameDouble.h index 0491bbcb..cae4cbda 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -54,11 +54,6 @@ class cxxNameDouble:public { (*this)[str] = d; } -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_pack(int *ints, int *ii, LDBLE *doubles, int *dd); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif enum ND_TYPE type; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index b347aad9..5ca7982d 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -234,51 +234,6 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -/* ---------------------------------------------------------------------- */ -void -cxxPPassemblage::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -/* ---------------------------------------------------------------------- */ -{ - /* int n_user; */ - ints.push_back(this->n_user); - ints.push_back((int) this->ppAssemblageComps.size()); - for (std::map < std::string, cxxPPassemblageComp >::iterator it = - this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); - it++) - { - (*it).second.mpi_pack(ints, doubles); - } - this->eltList.mpi_pack(ints, doubles); -} - -/* ---------------------------------------------------------------------- */ -void -cxxPPassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -/* ---------------------------------------------------------------------- */ -{ - int i = *ii; - int d = *dd; - /* int n_user; */ - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - - int count = ints[i++]; - this->ppAssemblageComps.clear(); - for (int n = 0; n < count; n++) - { - cxxPPassemblageComp ppc; - ppc.mpi_unpack(ints, &i, doubles, &d); - std::string str(ppc.get_name()); - this->ppAssemblageComps[str] = ppc; - } - this->eltList.mpi_unpack(ints, &i, doubles, &d); - *ii = i; - *dd = d; -} -#endif void cxxPPassemblage::totalize(Phreeqc * phreeqc_ptr) { diff --git a/PPassemblage.h b/PPassemblage.h index 9fa5ba10..7fadd9a3 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -49,10 +49,6 @@ class cxxPPassemblage:public cxxNumKeyword void Set_new_def(bool tf) {this->new_def = tf;} cxxPPassemblageComp *Find(const std::string name); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif void totalize(Phreeqc * phreeqc_ptr); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 2ea55bed..3bd2b185 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -312,46 +312,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxPPassemblageComp::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - - ints.push_back(dictionary.string2int(this->name)); - ints.push_back(dictionary.string2int(this->add_formula)); - doubles.push_back(this->si); - doubles.push_back(this->si_org); - doubles.push_back(this->moles); - doubles.push_back(this->delta); - doubles.push_back(this->initial_moles); - ints.push_back((int) this->force_equality); - ints.push_back((int) this->dissolve_only); - ints.push_back((int) this->precipitate_only); -} - -void -cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->name = dictionary.int2stdstring(ints[i++]); - this->add_formula = dictionary.int2stdstring(ints[i++]); - this->si = doubles[d++]; - this->si_org = doubles[d++]; - this->moles = doubles[d++]; - this->delta = doubles[d++]; - this->initial_moles = doubles[d++]; - this->force_equality = (ints[i++] != 0); - this->dissolve_only = (ints[i++] != 0); - this->precipitate_only = (ints[i++] != 0); - *ii = i; - *dd = d; -} -#endif - void cxxPPassemblageComp::totalize(Phreeqc * phreeqc_ptr) { diff --git a/PPassemblageComp.h b/PPassemblageComp.h index d6e9e33a..fa01a0c0 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -58,14 +58,9 @@ class cxxPPassemblageComp: public PHRQ_base bool Get_precipitate_only() const {return this->precipitate_only;} void Set_precipitate_only(bool tf) {this->precipitate_only = tf;} - void add(const cxxPPassemblageComp & comp, LDBLE extensive); void multiply(LDBLE extensive); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif protected: std::string name; std::string add_formula; diff --git a/Phreeqc.h b/Phreeqc.h index 9cec9ffd..a7fff436 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -931,9 +931,7 @@ public: static int surface_compare_int(const void *ptr1, const void *ptr2); static int rxn_token_temp_compare(const void *ptr1, const void *ptr2); int trxn_multiply(LDBLE coef); -#if defined(USE_MPI_SKIP) && defined(HDF5_CREATE) && defined(MERGE_FILES) - void MergeFinalize(void); -#endif + struct elt_list * cxxNameDouble2elt_list(const cxxNameDouble * nd); struct name_coef * cxxNameDouble2name_coef(const cxxNameDouble * nd); struct master_activity * cxxNameDouble2master_activity(const cxxNameDouble * nd); diff --git a/SS.cxx b/SS.cxx index 6f2198da..5c607af4 100644 --- a/SS.cxx +++ b/SS.cxx @@ -443,42 +443,6 @@ cxxSS::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxSS::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - ints.push_back(dictionary.string2int(this->name)); - this->comps.mpi_pack(ints, doubles); - doubles.push_back(this->a0); - doubles.push_back(this->a1); - doubles.push_back(this->ag0); - doubles.push_back(this->ag1); - ints.push_back((int) this->miscibility); - doubles.push_back(this->xb1); - doubles.push_back(this->xb2); -} - -void -cxxSS::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->name = dictionary.int2stdstring(ints[i++]); - this->comps.mpi_unpack(ints, &i, doubles, &d); - this->a0 = doubles[d++]; - this->a1 = doubles[d++]; - this->ag0 = doubles[d++]; - this->ag1 = doubles[d++]; - this->miscibility = (ints[i++] != 0); - this->xb1 = doubles[d++]; - this->xb2 = doubles[d++]; - *ii = i; - *dd = d; -} -#endif void cxxSS::totalize(Phreeqc * phreeqc_ptr) { diff --git a/SS.h b/SS.h index 0ef1571d..67277148 100644 --- a/SS.h +++ b/SS.h @@ -58,10 +58,6 @@ class cxxSS: public PHRQ_base return (this->totals); }; -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif cxxSScomp * Find(const char * comp_name); void add(const cxxSS & comp, LDBLE extensive); diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 7818a682..e50913bf 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -223,49 +223,6 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) break; } } -#ifdef USE_MPI_SKIP -/* ---------------------------------------------------------------------- */ -void -cxxSSassemblage::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -/* ---------------------------------------------------------------------- */ -{ - /* int n_user; */ - ints.push_back(this->n_user); - ints.push_back((int) this->SSs.size()); - for (std::map < std::string, cxxSS >::iterator it = - this->SSs.begin(); it != this->SSs.end(); - it++) - { - (*it).second.mpi_pack(ints, doubles); - } -} - -/* ---------------------------------------------------------------------- */ -void -cxxSSassemblage::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -/* ---------------------------------------------------------------------- */ -{ - int i = *ii; - int d = *dd; - /* int n_user; */ - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - - int count = ints[i++]; - this->SSs.clear(); - for (int n = 0; n < count; n++) - { - cxxSS ssc; - ssc.mpi_unpack(ints, &i, doubles, &d); - std::string str(ssc.get_name()); - this->SSs[str] = ssc; - } - *ii = i; - *dd = d; -} -#endif void cxxSSassemblage::totalize(Phreeqc * phreeqc_ptr) diff --git a/SSassemblage.h b/SSassemblage.h index dcece5a9..909f0f0f 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -32,10 +32,6 @@ public: void read_raw(CParser & parser, bool check = true); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif void totalize(Phreeqc * phreeqc_ptr); const cxxNameDouble & Get_totals() const {return this->totals;} diff --git a/SScomp.cxx b/SScomp.cxx index b9c9e203..0c14376c 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -247,45 +247,6 @@ cxxSScomp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxSScomp::mpi_pack(std::vector < int >&ints, - std::vector < double >&doubles) -{ - extern cxxDictionary dictionary; - - ints.push_back(dictionary.string2int(this->name)); - ints.push_back(dictionary.string2int(this->add_formula)); - doubles.push_back(this->si); - doubles.push_back(this->si_org); - doubles.push_back(this->moles); - doubles.push_back(this->delta); - doubles.push_back(this->initial_moles); - ints.push_back((int) this->force_equality); - ints.push_back((int) this->dissolve_only); - ints.push_back((int) this->precipitate_only); -} - -void -cxxSScomp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->name = dictionary.int2stdstring(ints[i++]); - this->add_formula = dictionary.int2stdstring(ints[i++]); - this->si = doubles[d++]; - this->si_org = doubles[d++]; - this->moles = doubles[d++]; - this->delta = doubles[d++]; - this->initial_moles = doubles[d++]; - this->force_equality = (ints[i++] != 0); - this->dissolve_only = (ints[i++] != 0); - this->precipitate_only = (ints[i++] != 0); - *ii = i; - *dd = d; -} -#endif #ifdef SKIP void cxxSScomp::totalize(Phreeqc * phreeqc_ptr) diff --git a/SScomp.h b/SScomp.h index 5b61faa8..afacc0e7 100644 --- a/SScomp.h +++ b/SScomp.h @@ -45,10 +45,6 @@ class cxxSScomp: public PHRQ_base void multiply(double extensive); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < double >&doubles); - void mpi_unpack(int *ints, int *ii, double *doubles, int *dd); -#endif protected: std::string name; // SOLID_SOLUTION_MODIFY candidate identifier diff --git a/Solution.cxx b/Solution.cxx index 45a96960..198e848b 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -5,11 +5,6 @@ #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif - -#ifdef USE_MPI_SKIP -//MPICH seems to require mpi.h to be first -#include -#endif #include #include // assert #include // std::sort @@ -1327,283 +1322,6 @@ cxxSolution::Get_master_activity(char *string) const } } -#ifdef USE_MPI_SKIP -/* ---------------------------------------------------------------------- */ -void -cxxSolution::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -/* ---------------------------------------------------------------------- */ -{ -/* - * Make list of list of ints and doubles from solution structure - * This list is not the complete structure, but only enough - * for batch-reaction, advection, and transport calculations - */ - ints.push_back(this->n_user); - doubles.push_back(this->tc); - doubles.push_back(this->ph); - doubles.push_back(this->pe); - doubles.push_back(this->mu); - doubles.push_back(this->ah2o); - doubles.push_back(this->total_h); - doubles.push_back(this->total_o); - doubles.push_back(this->cb); - doubles.push_back(this->mass_water); - doubles.push_back(this->total_alkalinity); -/* - * struct conc *totals; -*/ - this->totals.mpi_pack(ints, doubles); -/* - * struct master_activity *master_activity; - */ - this->master_activity.mpi_pack(ints, doubles); -/* - * struct master_activity *species_gamma - */ - this->species_gamma.mpi_pack(ints, doubles); - - /* - position = 0; - int i = ints.size(); - int int_array[i]; - int d = doubles.size(); - LDBLE double_array[d]; - for (int j = 0; j < i; j++) { - int_array[j] = ints[j]; - } - for (int j = 0; j < d; j++) { - double_array[j] = ints[j]; - } - MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); - MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); - - buffer = (void *) free_check_null(buffer); - */ -} - -/* ---------------------------------------------------------------------- */ -void -cxxSolution::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -/* ---------------------------------------------------------------------- */ -{ - int i = *ii; - int d = *dd; - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - this->tc = doubles[d++]; - this->ph = doubles[d++]; - this->pe = doubles[d++]; - this->mu = doubles[d++]; - this->ah2o = doubles[d++]; - this->total_h = doubles[d++]; - this->total_o = doubles[d++]; - this->cb = doubles[d++]; - this->mass_water = doubles[d++]; - this->total_alkalinity = doubles[d++]; -/* - * struct conc *totals; -*/ - this->totals.mpi_unpack(ints, &i, doubles, &d); -/* - * struct master_activity *master_activity; - */ - this->master_activity.mpi_unpack(ints, &i, doubles, &d); -/* - * struct master_activity *species_gamma; - */ - this->species_gamma.mpi_unpack(ints, &i, doubles, &d); - - *ii = i; - *dd = d; -} - -/* ---------------------------------------------------------------------- */ -void -cxxSolution::mpi_send(int task_number) -/* ---------------------------------------------------------------------- */ -{ - //int count_totals, count_totals_position, count_activity, count_activity_position; - int max_size, member_size, position; - //int ints[MESSAGE_MAX_NUMBERS]; - //LDBLE doubles[MESSAGE_MAX_NUMBERS]; - void *buffer; - std::vector < int >ints; - std::vector < LDBLE >doubles; -/* - * Make list of list of ints and doubles from solution structure - * This list is not the complete structure, but only enough - * for batch-reaction, advection, and transport calculations - */ - ints.push_back(this->n_user); - /* int n_user_end; */ - /* char *description; */ - doubles.push_back(this->tc); - doubles.push_back(this->ph); - doubles.push_back(this->pe); - doubles.push_back(this->mu); - doubles.push_back(this->ah2o); - doubles.push_back(this->total_h); - doubles.push_back(this->total_o); - doubles.push_back(this->cb); - doubles.push_back(this->mass_water); - doubles.push_back(this->total_alkalinity); -/* - * struct conc *totals; -*/ - this->totals.mpi_pack(ints, doubles); -/* - * struct master_activity *master_activity; - */ - this->master_activity.mpi_pack(ints, doubles); -/* - * struct master_activity *species_gamma - */ - this->species_gamma.mpi_pack(ints, doubles); - - /* int count_isotopes; */ - /* struct isotope *isotopes; */ - if (phreeqc_ptr-> input_error > 0) - { - std::string errstr("Stopping due to errors\n"); - error_msg(errstr.c_str(), STOP); - } -/* - * Malloc space for a buffer - */ - max_size = 0; - //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_INT, MPI_COMM_WORLD, &member_size); - MPI_Pack_size((int) ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size); - max_size += member_size; - //MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_DOUBLE, MPI_COMM_WORLD, &member_size); - MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, - &member_size); - max_size += member_size + 10; - buffer = phreeqc_ptr-> PHRQ_malloc(max_size); - if (buffer == NULL) - malloc_error(); -/* - * Send message to processor - */ - position = 0; - int i = (int) ints.size(); - int *int_array = new int[i]; - int d = (int) doubles.size(); - LDBLE *double_array = new LDBLE[d]; - for (int j = 0; j < i; j++) - { - int_array[j] = ints[j]; - } - for (int j = 0; j < d; j++) - { - double_array[j] = doubles[j]; - } - - MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); - MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, - MPI_COMM_WORLD); - MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, - MPI_COMM_WORLD); - MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); - - buffer = (void *) free_check_null(buffer); - delete[]int_array; - delete[]double_array; -} - -/* ---------------------------------------------------------------------- */ -void -cxxSolution::mpi_recv(int task_number) -/* ---------------------------------------------------------------------- */ -{ - MPI_Status mpi_status; -/* - * Malloc space for a buffer - */ - int max_size; - // buffer size - - MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, - &mpi_status); - void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); - if (buffer == NULL) - malloc_error(); - /* - * Recieve solution - */ - MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, - &mpi_status); - int position = 0; - int msg_size; - MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); - - /* Unpack ints */ - int count_ints; - MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, - MPI_COMM_WORLD); - int *ints = new int[count_ints]; - MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, - MPI_COMM_WORLD); - - /* Unpack doubles */ - int count_doubles; - MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, - MPI_COMM_WORLD); - LDBLE *doubles = new LDBLE[count_doubles]; - MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, - MPI_DOUBLE, MPI_COMM_WORLD); - buffer = free_check_null(buffer); -/* - * Make list of list of ints and doubles from solution structure - * This list is not the complete structure, but only enough - * for batch-reaction, advection, and transport calculations - */ - int i = 0; - int d = 0; - /* int new_def; */ - /* solution_ptr->new_def = FALSE; */ - /* int n_user; */ - this->n_user = ints[i++]; - /* int n_user_end; */ - this->n_user_end = this->n_user; - - /*debugging */ - //this->description = (char *) free_check_null(this->description); - //this->description = string_duplicate(" "); - this->description = " "; - this->tc = doubles[d++]; - this->ph = doubles[d++]; - this->pe = doubles[d++]; - this->mu = doubles[d++]; - this->ah2o = doubles[d++]; - this->total_h = doubles[d++]; - this->total_o = doubles[d++]; - this->cb = doubles[d++]; - this->mass_water = doubles[d++]; - this->total_alkalinity = 0; -/* - * struct conc *totals; -*/ - this->totals.mpi_unpack(ints, &i, doubles, &d); -/* - * struct master_activity *master_activity; - */ - this->master_activity.mpi_unpack(ints, &i, doubles, &d); -/* - * struct master_activity *species_gamma; - */ - this->species_gamma.mpi_unpack(ints, &i, doubles, &d); - delete[]ints; - delete[]doubles; -} -#endif void cxxSolution::Set_master_activity(char *string, LDBLE d) { diff --git a/Solution.h b/Solution.h index 793a6983..de8812fa 100644 --- a/Solution.h +++ b/Solution.h @@ -106,13 +106,6 @@ class cxxSolution:public cxxNumKeyword void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); void Update_activities(const cxxNameDouble &original_tot); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); - void mpi_send(int task_number); - void mpi_recv(int task_number); -#endif - protected: bool new_def; LDBLE patm; diff --git a/StorageBin.cxx b/StorageBin.cxx index 77535f2e..e6756126 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -4,10 +4,6 @@ #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif -#ifdef USE_MPI_SKIP -//MPICH seems to require mpi.h to be first -#include -#endif #include #include // std::cout std::cerr #include // assert @@ -998,267 +994,6 @@ cxxStorageBin::cxxStorageBin2system(Phreeqc * phreeqc_ptr, int n) } #endif -#ifdef USE_MPI_SKIP -void -cxxStorageBin::mpi_send(int n, int task_number) -{ - // - // Send data for system n to task_number - // - std::vector < int >ints; - std::vector < LDBLE >doubles; - - // Solution - if (this->getSolution(n) != NULL) - { - ints.push_back(1); - this->getSolution(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed Solution" << "\n"; - - // Exchanger - if (this->getExchange(n) != NULL) - { - ints.push_back(1); - this->getExchange(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed Exchange" << "\n"; - - // GasPhase - if (this->getGasPhase(n) != NULL) - { - ints.push_back(1); - this->getGasPhase(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed GasPhase" << "\n"; - - // Kinetics - if (this->getKinetics(n) != NULL) - { - ints.push_back(1); - this->getKinetics(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed Kinetics" << "\n"; - - // PPassemblages - if (this->getPPassemblage(n) != NULL) - { - ints.push_back(1); - this->getPPassemblage(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed PPassemblage" << "\n"; - - // SSassemblages - if (this->getSSassemblage(n) != NULL) - { - ints.push_back(1); - this->getSSassemblage(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed SSassemblage" << "\n"; - - // Surfaces - if (this->getSurface(n) != NULL) - { - ints.push_back(1); - this->getSurface(n)->mpi_pack(ints, doubles); - } - else - { - ints.push_back(0); - } - //std::cerr << "Packed Surface" << "\n"; - - // Pack data - int max_size = 0; - int member_size = 0; - MPI_Pack_size((int) ints.size() + 10, MPI_INT, MPI_COMM_WORLD, - &member_size); - max_size += member_size; - MPI_Pack_size((int) doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, - &member_size); - max_size += member_size + 10; - void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); - if (buffer == NULL) - malloc_error(); - - // Convert to arrays - int i = (int) ints.size(); - //int int_array[i]; - int d = (int) doubles.size(); - //LDBLE double_array[d]; - /* - for (int j = 0; j < i; j++) { - int_array[j] = ints[j]; - //std::cerr << "Sending ints " << j << " value " << ints[j] << "\n"; - } - for (int j = 0; j < d; j++) { - double_array[j] = doubles[j]; - //std::cerr << "Sending doubles " << j << " value " << doubles[j] << "\n"; - } - */ - /* - * Send message to processor - */ - int position = 0; - MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); - MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - MPI_Pack(&(ints.front()), i, MPI_INT, buffer, max_size, &position, - MPI_COMM_WORLD); - MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD); - if (d > 0) - { - MPI_Pack(&(doubles.front()), d, MPI_DOUBLE, buffer, max_size, - &position, MPI_COMM_WORLD); - } - MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD); - - buffer = (void *) free_check_null(buffer); -} - -/* ---------------------------------------------------------------------- */ -void -cxxStorageBin::mpi_recv(int task_number) -/* ---------------------------------------------------------------------- */ -{ - MPI_Status mpi_status; -/* - * Malloc space for a buffer - */ - int max_size; - // buffer size - - MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, - &mpi_status); - void *buffer = phreeqc_ptr-> PHRQ_malloc(max_size); - if (buffer == NULL) - malloc_error(); - /* - * Recieve system - */ - MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, - &mpi_status); - int position = 0; - int msg_size; - MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size); - - /* Unpack ints */ - int count_ints; - MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, - MPI_COMM_WORLD); - int *ints = new int[count_ints]; - MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, - MPI_COMM_WORLD); - - /* Unpack doubles */ - int count_doubles; - MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, - MPI_COMM_WORLD); - LDBLE *doubles = new LDBLE[count_doubles]; - if (count_doubles > 0) - { - MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, - MPI_DOUBLE, MPI_COMM_WORLD); - } - buffer = free_check_null(buffer); - /* - * Make list of list of ints and doubles from solution structure - * This list is not the complete structure, but only enough - * for batch-reaction, advection, and transport calculations - */ - int i = 0; - int d = 0; - - // Solution - if (ints[i++] != 0) - { - cxxSolution entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setSolution(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked Solution" << "\n"; - - // Exchanger - if (ints[i++] != 0) - { - cxxExchange entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setExchange(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked Exchange" << "\n"; - - // GasPhase - if (ints[i++] != 0) - { - cxxGasPhase entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setGasPhase(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked GasPhase" << "\n"; - - // Kinetics - if (ints[i++] != 0) - { - cxxKinetics entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setKinetics(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked Kinetics" << "\n"; - - // PPassemblage - if (ints[i++] != 0) - { - cxxPPassemblage entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setPPassemblage(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked PPassemblage" << "\n"; - - // SSassemblage - if (ints[i++] != 0) - { - cxxSSassemblage entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setSSassemblage(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked SSassemblage" << "\n"; - - // Surfaces - if (ints[i++] != 0) - { - cxxSurface entity; - entity.mpi_unpack(ints, &i, doubles, &d); - this->setSurface(entity.Get_n_user(), &entity); - } - //std::cerr << "Unpacked Surface" << "\n"; - - delete[]ints; - delete[]doubles; -} -#endif #ifdef SKIP cxxExchange * cxxStorageBin::mix_cxxExchange(cxxMix & mixmap) @@ -1581,83 +1316,3 @@ cxxStorageBin::Set_System(int i) this->system.Set_Pressure(Utilities::Rxn_find(this->Pressures, i)); } } -#ifdef USE_MPI_SKIP -void -cxxStorageBin::mpi_send(int n, int task_number) -{ - // - // Send data for system n to task_number - // - - std::ostringstream raw_stream; - - // Solution - if (this->Get_Solution(n) != NULL) - { - this->Get_Solution(n)->dump_raw(raw_stream, 0); - } - - // Exchanger - if (this->Get_Exchange(n) != NULL) - { - this->Get_Exchange(n)->dump_raw(raw_stream, 0); - } - - // GasPhase - if (this->Get_GasPhase(n) != NULL) - { - this->Get_GasPhase(n)->dump_raw(raw_stream, 0); - } - - // Kinetics - if (this->Get_Kinetics(n) != NULL) - { - this->Get_Kinetics(n)->dump_raw(raw_stream, 0); - } - - // PPassemblages - if (this->Get_PPassemblage(n) != NULL) - { - this->Get_PPassemblage(n)->dump_raw(raw_stream, 0); - } - - // SSassemblages - if (this->Get_SSassemblage(n) != NULL) - { - this->Get_SSassemblage(n)->dump_raw(raw_stream, 0); - } - - // Surfaces - if (this->Get_Surface(n) != NULL) - { - this->Get_Surface(n)->dump_raw(raw_stream, 0); - } - - // Send string - int size = raw_stream.str().size(); - MPI_Send(&size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD); - MPI_Send((void *) raw_stream.str().c_str(), size, MPI_CHARACTER, task_number, 0, MPI_COMM_WORLD); -} -void -cxxStorageBin::mpi_recv(int task_number) -{ - // - // Recieve raw data from task_number - // - - MPI_Status mpi_status; - int size; - MPI_Recv(&size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status); - - std::vector raw_buffer; - raw_buffer.resize(size + 1); - MPI_Recv((void *) raw_buffer.data(), size, MPI_CHARACTER, task_number, 0, MPI_COMM_WORLD, &mpi_status); - raw_buffer[size] = '\0'; - - std::istringstream raw_stream(raw_buffer.data()); - CParser parser(raw_stream); - parser.set_echo_file(CParser::EO_NONE); - parser.set_echo_stream(CParser::EO_NONE); - this->read_raw(parser); -} -#endif \ No newline at end of file diff --git a/StorageBin.h b/StorageBin.h index 1af2370b..e93111e9 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -114,10 +114,7 @@ class cxxStorageBin: public PHRQ_base std::map < int, cxxPressure > &Get_Pressures(); cxxSystem & Get_system(void) {return system;}; -#ifdef USE_MPI_SKIP - void mpi_send(int n, int task_number); - void mpi_recv(int task_number); -#endif + protected: // Tidied classes std::map < int, cxxSolution > Solutions; diff --git a/Surface.cxx b/Surface.cxx index 7009abf6..6948fda3 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -584,81 +584,6 @@ cxxSurface::read_raw(CParser & parser, bool check) this->Sort_comps(); } -#ifdef USE_MPI_SKIP -/* ---------------------------------------------------------------------- */ -void -cxxSurface::mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles) -/* ---------------------------------------------------------------------- */ -{ - /* int n_user; */ - ints.push_back(this->n_user); - ints.push_back((int) this->surfaceComps.size()); - for (std::map < std::string, cxxSurfaceComp >::iterator it = - this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) - { - (*it).second.mpi_pack(ints, doubles); - } - ints.push_back((int) this->surface_charges.size()); - for (std::map < std::string, cxxSurfaceCharge >::iterator it = - this->surface_charges.begin(); it != this->surface_charges.end(); it++) - { - (*it).second.mpi_pack(ints, doubles); - } - ints.push_back((int) this->type); - ints.push_back((int) this->dl_type); - ints.push_back((int) this->sites_units); - - ints.push_back((int) this->only_counter_ions); - doubles.push_back(this->thickness); - doubles.push_back(this->debye_lengths); - doubles.push_back(this->DDL_viscosity); - doubles.push_back(this->DDL_limit); - ints.push_back((int) this->transport); -} - -/* ---------------------------------------------------------------------- */ -void -cxxSurface::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -/* ---------------------------------------------------------------------- */ -{ - int i = *ii; - int d = *dd; - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - - int count = ints[i++]; - this->surfaceComps.clear(); - for (int n = 0; n < count; n++) - { - cxxSurfaceComp sc; - sc.mpi_unpack(ints, &i, doubles, &d); - std::string str(sc.get_formula()); - this->surfaceComps[str] = sc; - } - count = ints[i++]; - this->surface_charges.clear(); - for (int n = 0; n < count; n++) - { - cxxSurfaceCharge sc; - sc.mpi_unpack(ints, &i, doubles, &d); - std::string str(sc.get_name()); - this->surface_charges[str] = sc; - } - this->type = (SURFACE_TYPE) ints[i++]; - this->dl_type = (DIFFUSE_LAYER_TYPE) ints[i++]; - this->sites_units = (SITES_UNITS) ints[i++]; - this->only_counter_ions = (ints[i++] == TRUE); - this->thickness = doubles[d++]; - this->debye_lengths = doubles[d++]; - this->DDL_viscosity = doubles[d++]; - this->DDL_limit = doubles[d++]; - this->transport = (ints[i++] == TRUE); - *ii = i; - *dd = d; -} -#endif - void cxxSurface::totalize() { diff --git a/Surface.h b/Surface.h index bcf16388..a1edb99c 100644 --- a/Surface.h +++ b/Surface.h @@ -39,11 +39,6 @@ public: const cxxSurfaceCharge *Find_charge(const std::string str)const; void Sort_comps(); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif - void add(const cxxSurface & addee, LDBLE extensive); void multiply(LDBLE extensive); diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 2e09c3fc..142ab454 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -374,47 +374,6 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxSurfaceCharge::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - - ints.push_back(dictionary.string2int(this->name)); - doubles.push_back(this->specific_area); - doubles.push_back(this->grams); - doubles.push_back(this->charge_balance); - doubles.push_back(this->mass_water); - doubles.push_back(this->la_psi); - doubles.push_back(this->la_psi1); - doubles.push_back(this->la_psi2); - doubles.push_back(this->capacitance[0]); - doubles.push_back(this->capacitance[1]); - this->diffuse_layer_totals.mpi_pack(ints, doubles); -} - -void -cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->name = dictionary.int2stdstring(ints[i++]); - this->specific_area = doubles[d++]; - this->grams = doubles[d++]; - this->charge_balance = doubles[d++]; - this->mass_water = doubles[d++]; - this->la_psi = doubles[d++]; - this->la_psi1 = doubles[d++]; - this->la_psi2 = doubles[d++]; - this->capacitance[0] = doubles[d++]; - this->capacitance[1] = doubles[d++]; - this->diffuse_layer_totals.mpi_unpack(ints, &i, doubles, &d); - *ii = i; - *dd = d; -} -#endif void cxxSurfaceCharge::add(const cxxSurfaceCharge & addee, LDBLE extensive) { diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 772de64a..3cb7b9ad 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -75,11 +75,6 @@ public: void add(const cxxSurfaceCharge & comp, LDBLE extensive); void multiply(LDBLE extensive); -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif - const std::string &Get_name() const {return this->name;} void Set_name(const char * f) {this->name = f ? f : "";} LDBLE Get_specific_area() const {return this->specific_area;} diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index 040ecaa5..bfb9f15a 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -356,47 +356,6 @@ cxxSurfaceComp::read_raw(CParser & parser, bool check) } } -#ifdef USE_MPI_SKIP -void -cxxSurfaceComp::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - extern cxxDictionary dictionary; - - ints.push_back(dictionary.string2int(this->formula)); - doubles.push_back(this->formula_z); - this->formula_totals.mpi_pack(ints, doubles); - doubles.push_back(this->moles); - this->totals.mpi_pack(ints, doubles); - doubles.push_back(this->la); - doubles.push_back(this->charge_balance); - ints.push_back(dictionary.string2int(this->phase_name)); - doubles.push_back(this->phase_proportion); - ints.push_back(dictionary.string2int(this->rate_name)); - doubles.push_back(this->Dw); -} - -void -cxxSurfaceComp::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - extern cxxDictionary dictionary; - int i = *ii; - int d = *dd; - this->formula = dictionary.int2stdstring(ints[i++]); - this->formula_z = doubles[d++]; - this->formula_totals.mpi_unpack(ints, &i, doubles, &d); - this->moles = doubles[d++]; - this->totals.mpi_unpack(ints, &i, doubles, &d); - this->la = doubles[d++]; - this->charge_balance = doubles[d++]; - this->phase_name = dictionary.int2stdstring(ints[i++]); - this->phase_proportion = doubles[d++]; - this->rate_name = dictionary.int2stdstring(ints[i++]); - this->Dw = doubles[d++]; - *ii = i; - *dd = d; -} -#endif void cxxSurfaceComp::add(const cxxSurfaceComp & addee, LDBLE extensive) { diff --git a/SurfaceComp.h b/SurfaceComp.h index 6a264993..6bd14eb7 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -47,11 +47,6 @@ public: const std::string &Get_master_element() const {return this->master_element;} void Set_master_element(const char * f) {this->master_element = f ? f : "";} -#ifdef USE_MPI_SKIP - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif - protected: std::string formula; LDBLE formula_z; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 32b7193b..32f74439 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -447,74 +447,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) } } } -#ifdef USE_MPI_SKIP -void -cxxKinetics::mpi_pack(std::vector < int >&ints, - std::vector < LDBLE >&doubles) -{ - ints.push_back(this->n_user); - ints.push_back((int) this->kineticsComps.size()); - std::list < cxxKineticsComp >::iterator it; - for (it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) - { - (*it).mpi_pack(ints, doubles); - } - /* - for (std::map < std::string, cxxKineticsComp >::iterator it = - this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) - { - (*it).second.mpi_pack(ints, doubles); - } - */ - ints.push_back((int) this->steps.size()); - for (std::vector < LDBLE >::iterator it = this->steps.begin(); - it != this->steps.end(); it++) - { - doubles.push_back(*it); - } - doubles.push_back(this->step_divide); - ints.push_back(this->rk); - ints.push_back(this->bad_step_max); - ints.push_back(this->use_cvode); - ints.push_back(this->cvode_steps); - ints.push_back(this->cvode_order); - ints.push_back(this->equal_steps); -} - -void -cxxKinetics::mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd) -{ - int i = *ii; - int d = *dd; - this->n_user = ints[i++]; - this->n_user_end = this->n_user; - this->description = " "; - - int n = ints[i++]; - this->kineticsComps.clear(); - for (int j = 0; j < n; j++) - { - cxxKineticsComp kc; - kc.mpi_unpack(ints, &i, doubles, &d); - this->kineticsComps.push_back(kc); - } - n = ints[i++]; - this->steps.clear(); - for (int j = 0; j < n; j++) - { - this->steps.push_back(doubles[d++]); - } - this->step_divide = doubles[d++]; - this->rk = ints[i++]; - this->bad_step_max = ints[i++]; - this->use_cvode = (ints[i++] == TRUE); - this->cvode_steps = ints[i++]; - this->cvode_order = ints[i++]; - this->equal_steps = ints[i++]; - *ii = i; - *dd = d; -} -#endif void cxxKinetics::add(const cxxKinetics & addee, LDBLE extensive) // diff --git a/cxxKinetics.h b/cxxKinetics.h index ffcb873a..b7235862 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -53,10 +53,6 @@ class cxxKinetics:public cxxNumKeyword cxxKineticsComp * Find(const std::string &str); LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const; -#ifdef USE_MPI_SKIP - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); -#endif protected: void add(const cxxKinetics & addee, LDBLE extensive); diff --git a/phreeqc/input.cpp b/phreeqc/input.cpp index f0ed1419..10d120c8 100644 --- a/phreeqc/input.cpp +++ b/phreeqc/input.cpp @@ -107,7 +107,7 @@ get_line(void) size_t l = (l1 > l2) ? l1 : l2; if (l >= (size_t) max_line) { - max_line = l * 2; + max_line = (int) l * 2; line_save = (char *) PHRQ_realloc(line_save, (size_t) max_line * sizeof(char)); if (line_save == NULL) diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index a9d458c2..8ef9bb6d 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -134,7 +134,7 @@ inverse_models(void) } } - user_punch_count_headings = old_headings.size(); + user_punch_count_headings = (int) old_headings.size(); user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, (size_t) (user_punch_count_headings + 1) * sizeof(char *)); if (user_punch_headings == NULL) @@ -2125,7 +2125,7 @@ punch_model_heading(struct inverse *inv_ptr) size_t j; - user_punch_count_headings = heading_names.size(); + user_punch_count_headings = (int) heading_names.size(); user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, (size_t) (user_punch_count_headings + 1) * sizeof(char *)); if (user_punch_headings == NULL) diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 49ff658d..b1200dde 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -3954,7 +3954,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) pr_si_f = log10(phi_i) - Delta_V_i * (P - 1) / (2.303 * R * TK); */ { - int i, i1, n_g = phase_ptrs.size(); + int i, i1, n_g = (int) phase_ptrs.size(); LDBLE T_c, P_c; LDBLE A, B, B_r, /*b2,*/ kk, oo, a_aa, T_r; LDBLE m_sum, /*b_sum, a_aa_sum,*/ a_aa_sum2; @@ -4746,11 +4746,11 @@ setup_unknowns(void) */ if (solution_ptr->Get_initial_data()) { - max_unknowns += solution_ptr->Get_initial_data()->Get_comps().size(); + max_unknowns += (int) solution_ptr->Get_initial_data()->Get_comps().size(); } else { - max_unknowns += solution_ptr->Get_totals().size(); + max_unknowns += (int) solution_ptr->Get_totals().size(); } /* * Add 5 for ionic strength, activity of water, charge balance, total H, total O @@ -4804,8 +4804,8 @@ setup_unknowns(void) } else { - max_unknowns += use.Get_surface_ptr()->Get_surface_comps().size() + - 4 * (int) use.Get_surface_ptr()->Get_surface_charges().size(); + max_unknowns += (int) (use.Get_surface_ptr()->Get_surface_comps().size() + + 4 * (int) use.Get_surface_ptr()->Get_surface_charges().size()); } } /* @@ -4817,7 +4817,7 @@ setup_unknowns(void) if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME && (gas_phase_ptr->Get_pr_in() || force_numerical_fixed_volume) && numerical_fixed_volume) { - max_unknowns += gas_phase_ptr->Get_gas_comps().size(); + max_unknowns += (int) gas_phase_ptr->Get_gas_comps().size(); } else { @@ -4832,7 +4832,7 @@ setup_unknowns(void) std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); for (size_t i = 0; i < ss_ptrs.size(); i++) { - max_unknowns += ss_ptrs[i]->Get_ss_comps().size(); + max_unknowns += (int) ss_ptrs[i]->Get_ss_comps().size(); } } /* @@ -6011,7 +6011,7 @@ save_model(void) if (use.Get_ss_assemblage_ptr() != NULL) { size_t count_ss = use.Get_ss_assemblage_ptr()->Get_SSs().size(); - last_model.count_ss_assemblage = count_ss; + last_model.count_ss_assemblage = (int) count_ss; last_model.ss_assemblage = (const char **) PHRQ_malloc(count_ss * sizeof(char *)); if (last_model.ss_assemblage == NULL) diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index ba31db62..8f25d8a5 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -346,10 +346,6 @@ clean_up(void) #endif title_x = (char *) free_check_null(title_x); -#if defined(USE_MPI_SKIP) && defined(HDF5_CREATE) && defined(MERGE_FILES) - MergeFinalize(); -#endif - count_elements = 0; count_master = 0; count_phases = 0; From 03b0b8848cd2d51eee5251e9e666c270716d0126 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Oct 2012 18:36:59 +0000 Subject: [PATCH 0576/1077] Remove Dictionary, Linux changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7051 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cxx | 157 ----------------------------------------- Dictionary.h | 46 ------------ Phreeqc.cpp | 2 +- phreeqc/basicsubs.cpp | 2 - phreeqc/structures.cpp | 2 +- 5 files changed, 2 insertions(+), 207 deletions(-) delete mode 100644 Dictionary.cxx delete mode 100644 Dictionary.h diff --git a/Dictionary.cxx b/Dictionary.cxx deleted file mode 100644 index a2e64ac3..00000000 --- a/Dictionary.cxx +++ /dev/null @@ -1,157 +0,0 @@ -// StorageBin.cxx: implementation of the cxxStorageBin class. -// -////////////////////////////////////////////////////////////////////// -#ifdef _DEBUG -#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) -#endif - -#include "Dictionary.h" // define first -#define EXTERNAL extern -#include "global.h" -#include "phqalloc.h" -#include "phrqproto.h" -#include "output.h" -#include // assert -#include // std::sort - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// -cxxDictionary::cxxDictionary() -{ - // default constructor for cxxStorageBin -} - -cxxDictionary::~cxxDictionary() -{ -} - -void -cxxDictionary::add_phreeqc() -{ - HashTable *Table = strings_hash_table; - int i, j; - Segment *seg; - Element *p, *q; - - if (Table != NULL) - { - for (i = 0; i < Table->SegmentCount; i++) - { - /* test probably unnecessary */ - if ((seg = Table->Directory[i]) != NULL) - { - for (j = 0; j < SegmentSize; j++) - { - p = seg[j]; - while (p != NULL) - { - q = p->Next; - //p->Data = (char*) free_check_null((void*)p->Data); - this->putString((char *) (p->Data)); - p = q; - } - } - } - } - } - this->putString(std::string("")); - - -} - -int -cxxDictionary::putString(std::string str) -{ - int n; - std::map < std::string, int >::iterator it = stringkey.find(str); - if (it != stringkey.end()) - { - n = it->second; - } - else - { - n = (int) stringkey.size(); - stringkey[str] = n; - intkey[n] = str; - } - return (n); -} - -int -cxxDictionary::putString(char *str) -{ - std::string str1(str); - return (putString(str1)); -} - -int -cxxDictionary::string2int(std::string str) -{ - int n; - std::map < std::string, int >::iterator it = stringkey.find(str); - if (it != stringkey.end()) - { - n = it->second; - } - else - { - n = -1; - } - return (n); -} - -int -cxxDictionary::string2int(char *str) -{ - if (str == NULL) - return (-1); - std::string str1(str); - return (string2int(str1)); -} - - -std::string * cxxDictionary::int2string(int i) -{ - std::map < int, - std::string >::iterator - it = intkey.find(i); - if (it != intkey.end()) - { - return (&it->second); - } - else - { - return (NULL); - } -} - -std::string & cxxDictionary::int2stdstring(int i) -{ - std::map < int, - std::string >::iterator - it = intkey.find(i); - if (it != intkey.end()) - { - return (it->second); - } - else - { - exit(4); - } -} - -char * -cxxDictionary::int2char(int i) -{ - std::map < int, std::string >::iterator it = intkey.find(i); - if (it != intkey.end()) - { - return (string_hsave(it->second.c_str())); - } - else - { - return (NULL); - } -} - diff --git a/Dictionary.h b/Dictionary.h deleted file mode 100644 index 7043e6c8..00000000 --- a/Dictionary.h +++ /dev/null @@ -1,46 +0,0 @@ -#if !defined(DICTIONARY_H_INCLUDED) -#define DICTIONARY_H_INCLUDED - -#include // assert -#include // std::map -#include // std::string -#include // std::list -#include // std::vector - -class cxxDictionary -{ - - public: - cxxDictionary(); - - ~cxxDictionary(); - - void add_phreeqc(); - - int size() - { - return (int) stringkey.size(); - } - - int putString(std::string str); - int putString(char *str); - - int string2int(std::string str); - - int string2int(char *str); - - std::string * int2string(int i); - std::string & int2stdstring(int i); - - char *int2char(int i); - - protected: - std::map < std::string, int >stringkey; - std::map < int, std::string > intkey; - - public: - - -}; - -#endif // !defined(DICTIONARY_H_INCLUDED) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e431889a..e3eebff0 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1309,7 +1309,7 @@ void Phreeqc::init(void) * ---------------------------------------------------------------------- */ error_string = NULL; simulation = 0; - int state = INITIALIZE; + state = INITIALIZE; reaction_step = 0; transport_step = 0; transport_start = 0; diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index 353af799..a73b1111 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -948,7 +948,6 @@ equi_phase_delta(const char *phase_name) cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); if (state != TRANSPORT && state != PHAST) { - LDBLE moles = x[j]->moles; LDBLE delta_moles = x[j]->moles - comp_ptr->Get_moles() - comp_ptr->Get_delta(); @@ -956,7 +955,6 @@ equi_phase_delta(const char *phase_name) } else { - LDBLE moles = x[j]->moles; LDBLE delta_moles = x[j]->moles - comp_ptr->Get_initial_moles(); return(delta_moles); diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index 8f25d8a5..d2cfc935 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -1763,7 +1763,7 @@ cxxChemRxn2rxn(cxxChemRxn &cr) * * Return: rxn_ptr_new, pointer to new structure */ - for (int i = 0; i < cr.Get_tokens().size(); i++) + for (int i = 0; i < (int) cr.Get_tokens().size(); i++) { cr.Get_tokens()[i].s = s_store(cr.Get_tokens()[i].s->name, cr.Get_tokens()[i].s->z, FALSE); if (cr.Get_tokens()[i].name != NULL) From af6f13be9de2a37550eea0761780c1ca2d36d48a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 9 Nov 2012 03:55:10 +0000 Subject: [PATCH 0577/1077] changed read_delete to reuse StorageBinList for each call git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7068 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index e097a1f7..c6ea66c9 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -114,8 +114,7 @@ read_delete(void) parser.set_echo_file(CParser::EO_NOKEYWORDS); } - StorageBinList deleter(parser, phrq_io); - delete_info = deleter; + delete_info.Read(parser); // Need to output the next keyword From 283ff2dff0b1392c1d49ccff336dae2f5fa678ef Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Nov 2012 17:15:28 +0000 Subject: [PATCH 0578/1077] Tony turned off PR in mainsubs.cpp Kinetics deltas had wrong sign. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7071 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 2 ++ phreeqc/mainsubs.cpp | 9 +++++++++ phreeqc/print.cpp | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index ad3f5cbc..27dac704 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -130,6 +130,8 @@ main_method(int argc, char *argv[]) this->phrq_io->push_istream(input_cookie); errors = run_simulations(); + + //Phreeqc mycopy(*this); this->phrq_io->clear_istream(); if (errors != 0) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 2f98ff10..1403a29f 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2952,7 +2952,16 @@ run_simulations(void) * Calculate distribution of species for initial solutions */ if (new_solution) + { initial_solutions(TRUE); +/* For further printout, remove Peng-Robinson equilibration (if done) */ + for (int i = 0; i < count_phases; i++) + { + if (phases[i]->pr_in) + (phases[i]->pr_in) = FALSE; + } + } + /* * Calculate distribution for exchangers */ diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 6fb898a0..dd8ba315 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -3095,14 +3095,14 @@ punch_kinetics(void) fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t", (double) moles); fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t", - (double) -delta_moles); + (double) delta_moles); } else { fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t", (double) moles); fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t", - (double) -delta_moles); + (double) delta_moles); } } return (OK); From d7b2ab1ba5a6720101670cecd9487116892ba826 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Nov 2012 20:25:56 +0000 Subject: [PATCH 0579/1077] Fixed spacing for PRINT command high precision. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7072 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index d1f1669c..5cf4bf31 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -478,7 +478,7 @@ numtostr(char * Result, LDBLE n) } else { - sprintf(l_s, "%19g", (double) n); + sprintf(l_s, "%20g", (double) n); } } else From 6ac877e770d2a6f6cf7cf26d65e0cbe668ac62e1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Nov 2012 23:23:49 +0000 Subject: [PATCH 0580/1077] Step, problem mu requires ah2o to be 1.0. changed mix constructor to reset ah2o 0.0 before mixing. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7073 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 1 + phreeqc/step.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index 198e848b..efc2e12a 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -98,6 +98,7 @@ cxxSolution::cxxSolution(std::map < int, cxxSolution > &solutions, this->zero(); this->n_user = this->n_user_end = l_n_user; this->new_def = false; + this->ah2o = 0; // // Mix solutions // diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index 7a8b2811..c8793882 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -308,7 +308,7 @@ xsolution_zero(void) ph_x = 0.0; solution_pe_x = 0.0; mu_x = 0.0; - ah2o_x = 0.0; + ah2o_x = 1.0; density_x = 0.0; total_h_x = 0.0; total_o_x = 0.0; From cfdbf58dce04ae5797031c095aee1d4136e8a7f8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 15 Nov 2012 17:13:43 +0000 Subject: [PATCH 0581/1077] new def removed for raw Gas Phase and Surface. Latest examples run on Parkplace git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7084 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 4 ++-- Surface.cxx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index 8e969239..b9e58c4e 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -282,7 +282,7 @@ cxxGasPhase::read_raw(CParser & parser, bool check) // Read gas_phase number and description this->read_number_description(parser); - this->Set_new_def(true); + this->Set_new_def(false); opt_save = CParser::OPT_ERROR; bool type_defined(false); @@ -578,4 +578,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("temperature"), //11 std::vector< std::string >::value_type("totals") //12 }; -const std::vector< std::string > cxxGasPhase::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxGasPhase::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/Surface.cxx b/Surface.cxx index 6948fda3..feecf284 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -243,7 +243,7 @@ cxxSurface::read_raw(CParser & parser, bool check) // Read surface number and description this->read_number_description(parser); - this->Set_new_def(true); + this->Set_new_def(false); opt_save = CParser::OPT_ERROR; bool only_counter_ions_defined(false); @@ -768,4 +768,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("n_solution"), // 16 std::vector< std::string >::value_type("totals") // 17 }; -const std::vector< std::string > cxxSurface::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxSurface::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); From f6498feecc2095c16c20847e1179ada1d160d0a0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 16 Nov 2012 01:18:33 +0000 Subject: [PATCH 0582/1077] DELETE; -cells #no list of cells Causes all reactants to be deleted, same as DELETE; -all git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7085 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 53a37660..9f7587b9 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -264,7 +264,14 @@ bool StorageBinList::Read(CParser & parser) break; case 14: case 15: - this->TransferAll(cell_list); + if (cell_list.Get_numbers().empty()) + { + this->SetAll(true); + } + else + { + this->TransferAll(cell_list); + } break; default: case CParser::OPT_DEFAULT: From 31efde4669c8ba9b0527a0f80788df7a9035b43c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 27 Nov 2012 06:28:39 +0000 Subject: [PATCH 0583/1077] working on configure git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7112 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Makefile.am diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 00000000..46147336 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,130 @@ +AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqc + +bin_PROGRAMS = phreeqc + +# sources for phreeqc +phreeqc_SOURCES=\ + class_main.cpp\ + cxxKinetics.cxx\ + cxxKinetics.h\ + cxxMix.cxx\ + cxxMix.h\ + dumper.cpp\ + dumper.h\ + Exchange.cxx\ + Exchange.h\ + ExchComp.cxx\ + ExchComp.h\ + GasComp.cxx\ + GasComp.h\ + GasPhase.cxx\ + GasPhase.h\ + ISolution.cxx\ + ISolution.h\ + ISolutionComp.cxx\ + ISolutionComp.h\ + Keywords.cpp\ + Keywords.h\ + KineticsComp.cxx\ + KineticsComp.h\ + NameDouble.cxx\ + NameDouble.h\ + NumKeyword.cxx\ + NumKeyword.h\ + Parser.cxx\ + Parser.h\ + PBasic.cpp\ + PBasic.h\ + Phreeqc.cpp\ + Phreeqc.h\ + PHRQ_base.cxx\ + PHRQ_base.h\ + PHRQ_io.cpp\ + PHRQ_io.h\ + PPassemblage.cxx\ + PPassemblage.h\ + PPassemblageComp.cxx\ + PPassemblageComp.h\ + Pressure.cxx\ + Pressure.h\ + Reaction.cxx\ + Reaction.h\ + ReadClass.cxx\ + runner.cpp\ + runner.h\ + Solution.cxx\ + Solution.h\ + SolutionIsotope.cxx\ + SolutionIsotope.h\ + SSassemblage.cxx\ + SSassemblage.h\ + SS.cxx\ + SS.h\ + SScomp.cxx\ + SScomp.h\ + StorageBin.cxx\ + StorageBin.h\ + StorageBinList.cpp\ + StorageBinList.h\ + Surface.cxx\ + Surface.h\ + SurfaceCharge.cxx\ + SurfaceCharge.h\ + SurfaceComp.cxx\ + SurfaceComp.h\ + System.cxx\ + System.h\ + Temperature.cxx\ + Temperature.h\ + Use.cpp\ + Use.h\ + Utils.cxx\ + Utils.h\ + phreeqc/advection.cpp\ + phreeqc/basicsubs.cpp\ + phreeqc/cl1.cpp\ + phreeqc/cvdense.cpp\ + phreeqc/cvdense.h\ + phreeqc/cvode.cpp\ + phreeqc/cvode.h\ + phreeqc/dense.cpp\ + phreeqc/dense.h\ + phreeqc/dw.cpp\ + phreeqc/gases.cpp\ + phreeqc/global_structures.h\ + phreeqc/input.cpp\ + phreeqc/integrate.cpp\ + phreeqc/inverse.cpp\ + phreeqc/isotopes.cpp\ + phreeqc/kinetics.cpp\ + phreeqc/mainsubs.cpp\ + phreeqc/model.cpp\ + phreeqc/NA.h\ + phreeqc/nvector.cpp\ + phreeqc/nvector.h\ + phreeqc/nvector_serial.cpp\ + phreeqc/nvector_serial.h\ + phreeqc/parse.cpp\ + phreeqc/phqalloc.cpp\ + phreeqc/phqalloc.h\ + phreeqc/PHRQ_io_output.cpp\ + phreeqc/phrqtype.h\ + phreeqc/pitzer.cpp\ + phreeqc/pitzer_structures.cpp\ + phreeqc/prep.cpp\ + phreeqc/print.cpp\ + phreeqc/read.cpp\ + phreeqc/readtr.cpp\ + phreeqc/sit.cpp\ + phreeqc/smalldense.cpp\ + phreeqc/smalldense.h\ + phreeqc/spread.cpp\ + phreeqc/step.cpp\ + phreeqc/structures.cpp\ + phreeqc/sundialsmath.cpp\ + phreeqc/sundialsmath.h\ + phreeqc/sundialstypes.h\ + phreeqc/tally.cpp\ + phreeqc/tidy.cpp\ + phreeqc/transport.cpp\ + phreeqc/utilities.cpp From 378f2ff70ee423a9bc521f4bef6b9010bd2d51cb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Nov 2012 07:31:46 +0000 Subject: [PATCH 0584/1077] fixed buffer overwrite in fpunchf; updated unit tests for phreeqc3 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7132 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 103 ++++++++++++++++++++++++++++++++----- PHRQ_io.h | 2 + phreeqc/PHRQ_io_output.cpp | 45 ++++++++++++++-- phreeqc/print.cpp | 3 +- 4 files changed, 134 insertions(+), 19 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 76162e32..2dd27d63 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -414,11 +414,7 @@ fpunchf(const char *name, const char *format, double d) { if (punch_ostream != NULL && punch_on) { - { - char token[256]; - sprintf(token, format, d); - (*punch_ostream) << token; - } + fpunchf_helper(punch_ostream, format, d); } } /* ---------------------------------------------------------------------- */ @@ -428,11 +424,7 @@ fpunchf(const char *name, const char *format, char * s) { if (punch_ostream != NULL && punch_on) { - { - char token[256]; - sprintf(token, format, s); - (*punch_ostream) << token; - } + fpunchf_helper(punch_ostream, format, s); } } /* ---------------------------------------------------------------------- */ @@ -442,13 +434,98 @@ fpunchf(const char *name, const char *format, int d) { if (punch_ostream != NULL && punch_on) { + fpunchf_helper(punch_ostream, format, d); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf_helper(std::ostream *os, const char *format, ...) +/* ---------------------------------------------------------------------- */ +{ + if (os) + { + const size_t STACK_MAX = 2048; + char stack_buffer[STACK_MAX]; + + va_list args; + va_start(args, format); + int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); + bool success = (j > 0 && j < (int) STACK_MAX); + va_end(args); + + if (success) { - char token[256]; - sprintf(token, format, d); - (*punch_ostream) << token; + (*os) << stack_buffer; + } + else + { + size_t alloc_buffer_size = STACK_MAX * 2; + char *alloc_buffer = new char[alloc_buffer_size]; + do + { + va_list args; + va_start(args, format); + j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); + success = (j > 0 && j < (int) alloc_buffer_size); + va_end(args); + if (!success) + { + delete[] alloc_buffer; + alloc_buffer_size *= 2; + char *alloc_buffer = new char[alloc_buffer_size]; + } + } + while (!success); + (*os) << alloc_buffer; + delete alloc_buffer; } } } +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf_helper(std::string *str, const char *format, ...) +/* ---------------------------------------------------------------------- */ +{ + if (str) + { + const size_t STACK_MAX = 2048; + char stack_buffer[STACK_MAX]; + + va_list args; + va_start(args, format); + int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); + bool success = (j > 0 && j < (int) STACK_MAX); + va_end(args); + + if (success) + { + (*str) += stack_buffer; + } + else + { + size_t alloc_buffer_size = STACK_MAX * 2; + char *alloc_buffer = new char[alloc_buffer_size]; + do + { + va_list args; + va_start(args, format); + j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); + success = (j > 0 && j < (int) alloc_buffer_size); + va_end(args); + if (!success) + { + delete[] alloc_buffer; + alloc_buffer_size *= 2; + char *alloc_buffer = new char[alloc_buffer_size]; + } + } + while (!success); + (*str) += alloc_buffer; + delete alloc_buffer; + } + } +} + /* ---------------------------------------------------------------------- */ void PHRQ_io::fpunchf_end_row(const char *format) /* ---------------------------------------------------------------------- */ diff --git a/PHRQ_io.h b/PHRQ_io.h index d0a0e2a0..30fa9e21 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -122,6 +122,8 @@ public: virtual void fpunchf(const char *name, const char *format, char * d); virtual void fpunchf(const char *name, const char *format, int d); virtual void fpunchf_end_row(const char *format); + static void fpunchf_helper(std::ostream *os, const char *format, ...); + static void fpunchf_helper(std::string *str, const char *format, ...); virtual void screen_msg(const char * str); void Set_screen_on(bool tf) {this->screen_on = tf;}; diff --git a/phreeqc/PHRQ_io_output.cpp b/phreeqc/PHRQ_io_output.cpp index 40e84a89..40872425 100644 --- a/phreeqc/PHRQ_io_output.cpp +++ b/phreeqc/PHRQ_io_output.cpp @@ -75,17 +75,38 @@ fpunchf_heading(const char *name) void Phreeqc:: fpunchf(const char *name, const char *format, double d) { - if (phrq_io) phrq_io->fpunchf(name, format, d); + try + { + if (phrq_io) phrq_io->fpunchf(name, format, d); + } + catch(std::bad_alloc) + { + malloc_error(); + } } void Phreeqc:: fpunchf(const char *name, const char *format, char * s) { - if (phrq_io) phrq_io->fpunchf(name, format, s); + try + { + if (phrq_io) phrq_io->fpunchf(name, format, s); + } + catch(std::bad_alloc) + { + malloc_error(); + } } void Phreeqc:: fpunchf(const char *name, const char *format, int d) { - if (phrq_io) phrq_io->fpunchf(name, format, d); + try + { + if (phrq_io) phrq_io->fpunchf(name, format, d); + } + catch(std::bad_alloc) + { + malloc_error(); + } } void Phreeqc:: @@ -111,7 +132,14 @@ fpunchf_user(int user_index, const char *format, double d) (user_index - user_punch_count_headings) + 1); name = fpunchf_user_buffer; } - if (phrq_io) phrq_io->fpunchf(name, format, (double) d); + try + { + if (phrq_io) phrq_io->fpunchf(name, format, (double) d); + } + catch(std::bad_alloc) + { + malloc_error(); + } } void Phreeqc:: @@ -137,7 +165,14 @@ fpunchf_user(int user_index, const char *format, char * d) (user_index - user_punch_count_headings) + 1); name = fpunchf_user_buffer; } - if (phrq_io) phrq_io->fpunchf(name, format, d); + try + { + if (phrq_io) phrq_io->fpunchf(name, format, d); + } + catch(std::bad_alloc) + { + malloc_error(); + } } int Phreeqc:: diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index dd8ba315..5259fc40 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -3358,7 +3358,7 @@ sformatf(const char *format, ...) va_list args; va_start(args, format); int j = vsnprintf(sformatf_buffer, sformatf_buffer_size, format, args); - success = (j > 0 && j <= (int) sformatf_buffer_size); + success = (j > 0 && j < (int) sformatf_buffer_size); va_end(args); if (!success) { @@ -3371,6 +3371,7 @@ sformatf(const char *format, ...) return sformatf_buffer; } + /* ---------------------------------------------------------------------- */ int Phreeqc:: print_alkalinity(void) From ed6ad167a5a19085b17f8665666d4a3159be5d04 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Nov 2012 08:10:36 +0000 Subject: [PATCH 0585/1077] fixed hidden var declaration git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7134 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 2dd27d63..f0a72c8f 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -472,7 +472,7 @@ fpunchf_helper(std::ostream *os, const char *format, ...) { delete[] alloc_buffer; alloc_buffer_size *= 2; - char *alloc_buffer = new char[alloc_buffer_size]; + alloc_buffer = new char[alloc_buffer_size]; } } while (!success); @@ -516,7 +516,7 @@ fpunchf_helper(std::string *str, const char *format, ...) { delete[] alloc_buffer; alloc_buffer_size *= 2; - char *alloc_buffer = new char[alloc_buffer_size]; + alloc_buffer = new char[alloc_buffer_size]; } } while (!success); From 1f52fff82593908e77f00340dce35d574f1e82db Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 5 Dec 2012 00:26:28 +0000 Subject: [PATCH 0586/1077] Kinniburgh found bug in surf_total. Made a mistake when allowing redox states. Added test case surf_check.out Needed to checkin ex20b. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7161 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/basicsubs.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index a73b1111..d58a405e 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -2078,7 +2078,7 @@ surf_total(const char *total_name, const char *surface_name) */ int j; - if (use.Get_surface_ptr() == NULL) + if (use.Get_surface_ptr() == NULL || surface_name == NULL) return (0); /* @@ -2096,15 +2096,8 @@ surf_total(const char *total_name, const char *surface_name) std::string::iterator e = token.end(); std::string name; CParser::copy_token(name, b, e); - if (surface_name != NULL) - { - if (strcmp(name.c_str(), surface_name) == 0) + if (strcmp(name.c_str(), surface_name) == 0) break; - } - else - { - break; - } } if (j >= count_unknowns) return (0); @@ -2122,7 +2115,33 @@ surf_total(const char *total_name, const char *surface_name) if (s_x[j]->type != SURF) continue; - std::string token; + std::string token; + bool match = false; + + // find if surface matches + for (int i = 0; s_x[j]->next_elt[i].elt != NULL; i++) + { + if (s_x[j]->next_elt[i].elt->master->type != SURF) continue; + + //strcpy(token, s_x[j]->next_elt[i].elt->name); + //replace("_", " ", token); + //ptr = token; + //copy_token(name, &ptr, &k); + token = s_x[j]->next_elt[i].elt->name; + replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + std::string name; + CParser::copy_token(name, b, e); + if (strcmp(name.c_str(), surface_name) == 0) + { + match = true; + break; + } + } + if (!match) continue; + + // surface matches, now match element or redox state struct rxn_token *rxn_ptr; for (rxn_ptr = s_x[j]->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { @@ -2158,6 +2177,8 @@ surf_total(const char *total_name, const char *surface_name) } if (strcmp(token.c_str(), total_name) == 0) { + assert(false); + error_msg("Error in surf_total", STOP); t += rxn_ptr->coef * s_x[j]->moles; break; } From 58fdf9686676db44511feff3bcba38de25aae304 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 5 Dec 2012 00:46:46 +0000 Subject: [PATCH 0587/1077] stdarg for fpunchf_helper git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7162 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index f0a72c8f..6903e74c 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -9,6 +9,7 @@ #include #include #include +#include PHRQ_io:: PHRQ_io(void) From 21801d62d324a75e7c954e4d49bfa10dba4ded2a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 5 Dec 2012 00:52:01 +0000 Subject: [PATCH 0588/1077] added stdio.h git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7163 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 6903e74c..5f08b934 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -8,7 +8,9 @@ #include #include #include + #include +#include #include PHRQ_io:: From 5852b6a306309a45da0dd06fec90130275ff3247 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 6 Dec 2012 06:14:39 +0000 Subject: [PATCH 0589/1077] added check for gmp.h and -lgmp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7172 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Makefile.am b/Makefile.am index 46147336..4d129144 100644 --- a/Makefile.am +++ b/Makefile.am @@ -128,3 +128,13 @@ phreeqc_SOURCES=\ phreeqc/tidy.cpp\ phreeqc/transport.cpp\ phreeqc/utilities.cpp + +if BUILD_GMP + +phreeqc_SOURCES+=\ + phreeqc/cl1mp.cpp + +endif + + +LDADD = $(LIBGMP) From 65c2d5288bbe255b95ff5b9752d4fe4cd8da08ab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 6 Dec 2012 22:00:39 +0000 Subject: [PATCH 0590/1077] Tony change of numtostr. Removed assert for surf_total. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7179 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 4 ++-- phreeqc/basicsubs.cpp | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 5cf4bf31..35ac0f4a 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -474,11 +474,11 @@ numtostr(char * Result, LDBLE n) { if (PhreeqcPtr->punch.high_precision == FALSE) { - sprintf(l_s, "%12g", (double) n); + sprintf(l_s, "%12.0f", (double) n); } else { - sprintf(l_s, "%20g", (double) n); + sprintf(l_s, "%20.0f", (double) n); } } else diff --git a/phreeqc/basicsubs.cpp b/phreeqc/basicsubs.cpp index d58a405e..eb05aa8a 100644 --- a/phreeqc/basicsubs.cpp +++ b/phreeqc/basicsubs.cpp @@ -2167,7 +2167,7 @@ surf_total(const char *total_name, const char *surface_name) break; } else - // sum all sites in case total_name is a surface name without underscore + // sum all sites in case total_name is a surface name without underscore surf ("Hfo_w", "Hfo") { if (rxn_ptr->s->type == SURF) { @@ -2177,8 +2177,6 @@ surf_total(const char *total_name, const char *surface_name) } if (strcmp(token.c_str(), total_name) == 0) { - assert(false); - error_msg("Error in surf_total", STOP); t += rxn_ptr->coef * s_x[j]->moles; break; } From c0a8627fbea5356c58a3dea6dfb9cff9e80ba48e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 13 Dec 2012 22:20:53 +0000 Subject: [PATCH 0591/1077] fixed all System::Threading::Interlocked::CompareExchange and added some debugging code git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7200 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 21 +++++++++++---------- ChartObject.cpp | 3 +-- CurveObject.cpp | 2 ++ phreeqc/Form1.h | 43 +++++++++++++++++++++++++++++++++---------- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 54dbe50b..a868bb82 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -44,9 +44,8 @@ ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) if (it->second->Get_active()) { #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 4)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 4, 0)) { - ::OutputDebugString("Sleeping 4\n"); System::Threading::Thread::Sleep(5); } #endif @@ -58,7 +57,8 @@ ChartHandler::Punch_user_graph(Phreeqc * phreeqc_ptr) catch (...) { #if defined(__cplusplus_cli) - System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + assert(n == 4); #endif throw; } @@ -98,9 +98,8 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) // Read/update ChartObject #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 5)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 5, 0)) { - ::OutputDebugString("Sleeping 5\n"); System::Threading::Thread::Sleep(5); } #endif @@ -124,13 +123,15 @@ ChartHandler::Read(Phreeqc * phreeqc_ptr, CParser &parser) { #if defined(__cplusplus_cli) // Release lock - System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + assert(n == 5); throw; #endif } #if defined(__cplusplus_cli) // Release lock - System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + assert(n == 5); #endif // if detached, wait for thread to acknowledge and then erase chart @@ -162,9 +163,8 @@ ChartHandler::End_timer() if (it->second->Get_form_started()) { #if defined(__cplusplus_cli) - while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 0, 6)) + while (0 != System::Threading::Interlocked::CompareExchange(it->second->usingResource, 6, 0)) { - ::OutputDebugString("Sleeping 6\n"); //if (i > max_tries) break; i++; System::Threading::Thread::Sleep(60); @@ -172,7 +172,8 @@ ChartHandler::End_timer() #endif it->second->Set_end_timer(true); #if defined(__cplusplus_cli) - System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); + assert(n == 6); #endif i2 = 0; diff --git a/ChartObject.cpp b/ChartObject.cpp index 7604f9a9..41a5f692 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -113,9 +113,8 @@ cxxNumKeyword(io) ChartObject::~ChartObject() { - while (0 != System::Threading::Interlocked::CompareExchange(this->usingResource, 0, 7)) + while (0 != System::Threading::Interlocked::CompareExchange(this->usingResource, 7, 0)) { - ::OutputDebugString("Sleeping 7\n"); System::Threading::Thread::Sleep(5); } this->Rate_free(); diff --git a/CurveObject.cpp b/CurveObject.cpp index 504c4658..42710b99 100644 --- a/CurveObject.cpp +++ b/CurveObject.cpp @@ -1,6 +1,7 @@ // CurveObject.cpp: implementation of the CurveObject class. // ////////////////////////////////////////////////////////////////////// +#ifdef MULTICHART #ifdef _DEBUG #pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) #endif @@ -31,3 +32,4 @@ CurveObject::~CurveObject() { } +#endif // MULTICHART \ No newline at end of file diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index b7134253..223532ac 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -412,9 +412,8 @@ namespace zdg_ui2 { GraphPane ^myPane = z1->GraphPane; // lock thread - while (0 != System::Threading::Interlocked::CompareExchange(this->chartobject_ptr->usingResource, 0, 2)) + while (0 != System::Threading::Interlocked::CompareExchange(this->chartobject_ptr->usingResource, 2, 0)) { - ::OutputDebugString("Sleeping 2\n"); System::Threading::Thread::Sleep(5); } @@ -492,12 +491,14 @@ namespace zdg_ui2 { catch (...) { //unlock thread - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + assert(n == 2); throw; } //unlock thread - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + assert(n == 2); } /// @@ -965,9 +966,8 @@ namespace zdg_ui2 { if (chart == NULL) return; //lock for thread - while (0 != System::Threading::Interlocked::CompareExchange(chart->usingResource, 0, 3)) + while (0 != System::Threading::Interlocked::CompareExchange(chart->usingResource, 3, 0)) { - ::OutputDebugString("Sleeping 3\n"); System::Threading::Thread::Sleep(5); } @@ -1082,7 +1082,25 @@ namespace zdg_ui2 { zg1->AxisChange(); zg1->Refresh(); } - + for (size_t j = 0; j < chart->Get_CurvesCSV().size(); j++) + { + if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_CurvesCSV()[j]->Get_x().size()) + { + fprintf(stderr, "graph points = %d\n", zg1->GraphPane->CurveList[j]->Points->Count); + fprintf(stderr, "phreeqc points = %d\n", chart->Get_CurvesCSV()[j]->Get_x().size()); + } + assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_CurvesCSV()[j]->Get_x().size()); + } + for (int j = chart->Get_CurvesCSV().size(); j < zg1->GraphPane->CurveList->Count; j++) + { + int k = j - chart->Get_CurvesCSV().size(); + if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_Curves()[k]->Get_x().size()) + { + fprintf(stderr, "graph points = %d\n", zg1->GraphPane->CurveList[j]->Points->Count); + fprintf(stderr, "phreeqc points = %d\n", chart->Get_Curves()[k]->Get_x().size()); + } + assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_Curves()[k]->Get_x().size()); + } chart->Set_point_added(false); if (chart->Get_end_timer()) { @@ -1097,7 +1115,9 @@ namespace zdg_ui2 { } //unlock thread before setting chartobject_ptr to NULL - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + assert(n == 3); + this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; if (batch >= 0) @@ -1109,12 +1129,15 @@ namespace zdg_ui2 { } catch(...) { - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + assert(n == 3); + throw; } //unlock thread - System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + assert(n == 3); //tickStart = Environment::TickCount; return; } From c2f8b3bb429aecd0d2edbedb3f240bfbf4b71f8b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 16:36:06 +0000 Subject: [PATCH 0592/1077] Saved list of newly read entities (including _raw and _modify). Limit checking to new versions. Limit loop to new for initial calculations (solution, exchange, surface, gas phase). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7218 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 3 +- PPassemblage.cxx | 2 +- Phreeqc.h | 23 ++++++- SSassemblage.cxx | 2 +- Solution.cxx | 2 +- phreeqc/mainsubs.cpp | 28 +++++--- phreeqc/prep.cpp | 25 +++++-- phreeqc/read.cpp | 70 +++++++++++++------- phreeqc/step.cpp | 27 ++++++-- phreeqc/tidy.cpp | 152 +++++++++++++++++++++++++------------------ 10 files changed, 225 insertions(+), 109 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 7a849213..39f33eb6 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -205,7 +205,8 @@ cxxExchange::read_raw(CParser & parser, bool check) // Read exchange number and description this->read_number_description(parser); - this->Set_new_def(true); + this->Set_new_def(false); + opt_save = CParser::OPT_ERROR; bool pitzer_exchange_gammas_defined(false); diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 5ca7982d..15659010 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -134,7 +134,7 @@ cxxPPassemblage::read_raw(CParser & parser, bool check) // Read PPassemblage number and description this->read_number_description(parser); - this->Set_new_def(true); + this->Set_new_def(false); opt_save = CParser::OPT_ERROR; diff --git a/Phreeqc.h b/Phreeqc.h index a7fff436..8452a0ab 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1211,6 +1211,20 @@ protected: std::map Rxn_pp_assemblage_mix_map; std::map Rxn_ss_assemblage_mix_map; std::map Rxn_surface_mix_map; + /* + * List new definitions + */ + std::vector Rxn_new_exchange; + std::vector Rxn_new_gas_phase; + std::vector Rxn_new_kinetics; // not used + std::vector Rxn_new_mix; // not used + std::vector Rxn_new_pp_assemblage; + std::vector Rxn_new_pressure; // not used + std::vector Rxn_new_reaction; // not used + std::vector Rxn_new_solution; + std::vector Rxn_new_ss_assemblage; + std::vector Rxn_new_surface; + std::vector Rxn_new_temperature; // not used /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ @@ -1980,7 +1994,7 @@ namespace Utilities } } template < typename T > - int Rxn_read_raw(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + int Rxn_read_raw(std::map < int, T > &m, std::vector < int > &v, Phreeqc * phreeqc_cookie) { typename std::map < int, T >::iterator it; assert(!phreeqc_cookie->reading_database()); @@ -1998,11 +2012,15 @@ namespace Utilities // Make copies if necessary Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end()); + for (int i = entity.Get_n_user(); i <= entity.Get_n_user_end(); i++) + { + v.push_back(i); + } return phreeqc_cookie->cleanup_after_parser(parser); } template < typename T > - int Rxn_read_modify(std::map < int, T > &m, Phreeqc * phreeqc_cookie) + int Rxn_read_modify(std::map < int, T > &m, std::vector < int > &v, Phreeqc * phreeqc_cookie) { typename std::map < int, T >::iterator it; @@ -2024,6 +2042,7 @@ namespace Utilities } entity_ptr->read_raw(parser, false); + v.push_back(entity_ptr->Get_n_user()); return phreeqc_cookie->cleanup_after_parser(parser); } diff --git a/SSassemblage.cxx b/SSassemblage.cxx index e50913bf..c187cbd9 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -136,7 +136,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check) // Read SSassemblage number and description this->read_number_description(parser); - this->Set_new_def(true); + this->Set_new_def(false); opt_save = CParser::OPT_ERROR; diff --git a/Solution.cxx b/Solution.cxx index efc2e12a..9350bbef 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -304,7 +304,7 @@ cxxSolution::read_raw(CParser & parser, bool check) // Read solution number and description this->read_number_description(parser.line()); - this->Set_new_def(true); + this->Set_new_def(false); opt_save = CParser::OPT_ERROR; bool tc_defined(false); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 1403a29f..dd3cda64 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1278,9 +1278,12 @@ initial_solutions(int print) set_use(); print1 = TRUE; dl_type_x = cxxSurface::NO_DL; - std::map::iterator it = Rxn_solution_map.begin(); - for ( ; it != Rxn_solution_map.end(); it++) + //std::map::iterator it = Rxn_solution_map.begin(); + //for ( ; it != Rxn_solution_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_solution.size(); nn++) { + std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[nn]); cxxSolution &solution_ref = it->second; initial_solution_isotopes = FALSE; if (solution_ref.Get_new_def()) @@ -1378,9 +1381,12 @@ initial_exchangers(int print) set_use(); print1 = TRUE; dl_type_x = cxxSurface::NO_DL; - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) + //std::map::iterator it = Rxn_exchange_map.begin(); + //for ( ; it != Rxn_exchange_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { + std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); if (!it->second.Get_new_def()) continue; cxxExchange *exchange_ptr = &(it->second); @@ -1458,9 +1464,12 @@ initial_gas_phases(int print) set_use(); print1 = TRUE; dl_type_x = cxxSurface::NO_DL; - std::map::iterator it = Rxn_gas_phase_map.begin(); - for ( ; it != Rxn_gas_phase_map.end(); it++) + //std::map::iterator it = Rxn_gas_phase_map.begin(); + //for ( ; it != Rxn_gas_phase_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) { + std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); cxxGasPhase *gas_phase_ptr = &it->second; if (!gas_phase_ptr->Get_new_def()) continue; @@ -1568,9 +1577,12 @@ initial_surfaces(int print) set_use(); print1 = TRUE; - std::map::iterator it = Rxn_surface_map.begin(); - for ( ; it != Rxn_surface_map.end(); it++) + //std::map::iterator it = Rxn_surface_map.begin(); + //for ( ; it != Rxn_surface_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { + std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); cxxSurface * surface_ptr = &it->second; if (!surface_ptr->Get_new_def()) continue; diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index b1200dde..29d938c3 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -3311,6 +3311,17 @@ setup_exchange(void) for (size_t j = 0; j < use.Get_exchange_ptr()->Get_exchange_comps().size(); j++) { cxxExchComp & comp_ref = use.Get_exchange_ptr()->Get_exchange_comps()[j]; + { + element * elt_ptr = element_store(comp_ref.Get_formula().c_str()); + if (elt_ptr == NULL || elt_ptr->master == NULL) + { + error_string = sformatf( "Component not in database, %s", comp_ref.Get_formula().c_str()); + input_error++; + error_msg(error_string, CONTINUE); + continue; + } + } + cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); for ( ; it != nd.end(); it++) @@ -3321,8 +3332,8 @@ setup_exchange(void) element * elt_ptr = element_store(it->first.c_str()); if (elt_ptr == NULL || elt_ptr->master == NULL) { - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", it->first.c_str()); input_error++; error_msg(error_string, CONTINUE); @@ -3535,7 +3546,7 @@ setup_surface(void) if (master_ptr == NULL) { error_string = sformatf( - "Master species not in data base for %s, skipping element.", + "Master species not in database for %s, skipping element.", elt_ptr->name); warning_msg(error_string); continue; @@ -3600,6 +3611,12 @@ setup_surface(void) */ cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()-> Find_charge(comp_ptr->Get_charge_name()); + if (charge_ptr == NULL) + { + input_error++; + error_msg(sformatf("Charge structure not defined for surface, %s", use.Get_surface_ptr()->Get_description().c_str()), CONTINUE); + continue; + } x[count_unknowns]->type = SURFACE_CB; x[count_unknowns]->surface_charge = string_hsave(charge_ptr->Get_name().c_str()); x[count_unknowns]->related_moles = charge_ptr->Get_grams(); @@ -4371,7 +4388,7 @@ setup_solution(void) if (master_ptr == NULL) { error_string = sformatf( - "Master species not in data base for %s, skipping element.", + "Master species not in database for %s, skipping element.", it->first.c_str()); warning_msg(error_string); free_check_null(temp_desc); diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index a01c3826..d8a9473b 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -31,6 +31,18 @@ read_input(void) input_error = 0; next_keyword = Keywords::KEY_NONE; count_warnings = 0; + + Rxn_new_exchange.clear(); + Rxn_new_gas_phase.clear(); + Rxn_new_kinetics.clear(); // not used + Rxn_new_mix.clear(); // not used + Rxn_new_pp_assemblage.clear(); + Rxn_new_pressure.clear(); // not used + Rxn_new_reaction.clear(); // not used + Rxn_new_solution.clear(); + Rxn_new_ss_assemblage.clear(); + Rxn_new_surface.clear(); + Rxn_new_temperature.clear(); // not used /* * Initialize keyword counters */ @@ -279,58 +291,58 @@ read_input(void) read_sit(); break; case Keywords::KEY_SOLUTION_RAW: - Utilities::Rxn_read_raw(Rxn_solution_map, this); + Utilities::Rxn_read_raw(Rxn_solution_map, Rxn_new_solution, this); break; case Keywords::KEY_EXCHANGE_RAW: - Utilities::Rxn_read_raw(Rxn_exchange_map, this); + Utilities::Rxn_read_raw(Rxn_exchange_map, Rxn_new_exchange, this); break; case Keywords::KEY_SURFACE_RAW: - Utilities::Rxn_read_raw(Rxn_surface_map, this); + Utilities::Rxn_read_raw(Rxn_surface_map, Rxn_new_surface, this); break; case Keywords::KEY_EQUILIBRIUM_PHASES_RAW: - Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, this); + Utilities::Rxn_read_raw(Rxn_pp_assemblage_map, Rxn_new_pp_assemblage, this); break; case Keywords::KEY_KINETICS_RAW: - Utilities::Rxn_read_raw(Rxn_kinetics_map, this); + Utilities::Rxn_read_raw(Rxn_kinetics_map, Rxn_new_kinetics, this); break; case Keywords::KEY_SOLID_SOLUTIONS_RAW: - Utilities::Rxn_read_raw(Rxn_ss_assemblage_map, this); + Utilities::Rxn_read_raw(Rxn_ss_assemblage_map, Rxn_new_ss_assemblage, this); break; case Keywords::KEY_GAS_PHASE_RAW: - Utilities::Rxn_read_raw(Rxn_gas_phase_map, this); + Utilities::Rxn_read_raw(Rxn_gas_phase_map, Rxn_new_gas_phase, this); break; case Keywords::KEY_REACTION_RAW: - Utilities::Rxn_read_raw(Rxn_reaction_map, this); + Utilities::Rxn_read_raw(Rxn_reaction_map, Rxn_new_reaction, this); break; case Keywords::KEY_MIX_RAW: - Utilities::Rxn_read_raw(Rxn_mix_map, this); + Utilities::Rxn_read_raw(Rxn_mix_map, Rxn_new_mix, this); break; case Keywords::KEY_REACTION_TEMPERATURE_RAW: - Utilities::Rxn_read_raw(Rxn_temperature_map, this); + Utilities::Rxn_read_raw(Rxn_temperature_map, Rxn_new_temperature, this); break; case Keywords::KEY_DUMP: read_dump(); break; case Keywords::KEY_SOLUTION_MODIFY: - Utilities::Rxn_read_modify(Rxn_solution_map, this); + Utilities::Rxn_read_modify(Rxn_solution_map, Rxn_new_solution, this); break; case Keywords::KEY_EQUILIBRIUM_PHASES_MODIFY: - Utilities::Rxn_read_modify(Rxn_pp_assemblage_map, this); + Utilities::Rxn_read_modify(Rxn_pp_assemblage_map, Rxn_new_pp_assemblage, this); break; case Keywords::KEY_EXCHANGE_MODIFY: - Utilities::Rxn_read_modify(Rxn_exchange_map, this); + Utilities::Rxn_read_modify(Rxn_exchange_map, Rxn_new_exchange, this); break; case Keywords::KEY_SURFACE_MODIFY: - Utilities::Rxn_read_modify(Rxn_surface_map, this); + Utilities::Rxn_read_modify(Rxn_surface_map, Rxn_new_surface, this); break; case Keywords::KEY_SOLID_SOLUTIONS_MODIFY: - Utilities::Rxn_read_modify(Rxn_ss_assemblage_map, this); + Utilities::Rxn_read_modify(Rxn_ss_assemblage_map, Rxn_new_ss_assemblage, this); break; case Keywords::KEY_GAS_PHASE_MODIFY: - Utilities::Rxn_read_modify(Rxn_gas_phase_map, this); + Utilities::Rxn_read_modify(Rxn_gas_phase_map, Rxn_new_gas_phase, this); break; case Keywords::KEY_KINETICS_MODIFY: - Utilities::Rxn_read_modify(Rxn_kinetics_map, this); + Utilities::Rxn_read_modify(Rxn_kinetics_map, Rxn_new_kinetics, this); break; case Keywords::KEY_DELETE: read_delete(); @@ -339,7 +351,7 @@ read_input(void) read_run_cells(); break; case Keywords::KEY_REACTION_MODIFY: - Utilities::Rxn_read_modify(Rxn_reaction_map, this); + Utilities::Rxn_read_modify(Rxn_reaction_map, Rxn_new_reaction, this); break; //case LAST_C_KEYWORD + 22: //reaction_temperature_modify // keyword[LAST_C_KEYWORD + 22].keycount++; @@ -349,7 +361,7 @@ read_input(void) read_reaction_pressure(); break; case Keywords::KEY_REACTION_PRESSURE_RAW: - Utilities::Rxn_read_raw(Rxn_pressure_map, this); + Utilities::Rxn_read_raw(Rxn_pressure_map, Rxn_new_pressure, this); break; default: error_msg("Error in keyword switch", STOP); @@ -1098,6 +1110,7 @@ read_exchange(void) break; } Rxn_exchange_map[n_user] = temp_exchange; + Rxn_new_exchange.push_back(n_user); return (return_value); } @@ -1390,7 +1403,7 @@ read_gas_phase(void) Rxn_gas_phase_map[n_user] = temp_gas_phase; - + Rxn_new_gas_phase.push_back(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -4191,7 +4204,7 @@ read_pp_assemblage(void) } temp_pp_assemblage.Set_pp_assemblage_comps(comps); Rxn_pp_assemblage_map[n_user] = temp_pp_assemblage; - + Rxn_new_pp_assemblage.push_back(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -5356,7 +5369,7 @@ read_solution(void) } } Rxn_solution_map[n_user] = temp_solution; - + Rxn_new_solution.push_back(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -7132,6 +7145,7 @@ read_surface(void) } temp_surface.Sort_comps(); Rxn_surface_map[n_user] = temp_surface; + Rxn_new_surface.push_back(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -9660,8 +9674,14 @@ read_solid_solutions(void) 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; + if (ss_ptr != NULL && comps.size() > 0) + { + ss_ptr->Set_ss_comps(comps); + } + if (ss_ptr != NULL && ss_ptr->Get_name().size() > 0) + { + temp_ss_assemblage.Get_SSs()[ss_ptr->Get_name()] = *ss_ptr; + } delete ss_ptr; ss_ptr = NULL; comps.clear(); @@ -9689,7 +9709,7 @@ read_solid_solutions(void) // Add to map Rxn_ss_assemblage_map[n_user] = temp_ss_assemblage; - + Rxn_new_ss_assemblage.push_back(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ diff --git a/phreeqc/step.cpp b/phreeqc/step.cpp index c8793882..1591bce3 100644 --- a/phreeqc/step.cpp +++ b/phreeqc/step.cpp @@ -373,7 +373,15 @@ add_solution(cxxSolution *solution_ptr, LDBLE extensive, LDBLE intensive) for ( ; jit != solution_ptr->Get_totals().end(); jit++) { master_ptr = master_bsearch_primary(jit->first.c_str()); - master_ptr->total += jit->second * extensive; + if (master_ptr != NULL) + { + master_ptr->total += jit->second * extensive; + } + else + { + input_error++; + error_msg(sformatf("Undefined element in solution, %s\n", jit->first.c_str()), CONTINUE); + } } /* * Accumulate initial guesses for activities @@ -495,6 +503,10 @@ add_surface(cxxSurface *surface_ptr) { cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); struct element *elt_ptr = element_store(comp_ptr->Get_master_element().c_str()); + if (elt_ptr->master == NULL) + { + error_msg(sformatf("Data not defined for master in SURFACE, %s\n", comp_ptr->Get_formula().c_str()), STOP); + } struct master *master_i_ptr = elt_ptr->master; if (surface_ptr->Get_type() == cxxSurface::NO_EDL) @@ -1001,9 +1013,16 @@ add_gas_phase(cxxGasPhase *gas_phase_ptr) cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); int k; struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); - assert(phase_ptr); - - add_elt_list(phase_ptr->next_elt, gc_ptr->Get_moles()); + if (phase_ptr == NULL) + { + input_error++; + error_msg(sformatf("PHASE not found in database, %s\n", gc_ptr->Get_phase_name().c_str()), CONTINUE); + } + //assert(phase_ptr); + else + { + add_elt_list(phase_ptr->next_elt, gc_ptr->Get_moles()); + } } /* * Sort elements in reaction and combine diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 2c4dff09..d45a25c6 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -888,12 +888,14 @@ tidy_gas_phase(void) /* * Find all gases for each gas_phase in phase list */ - std::map::iterator it = Rxn_gas_phase_map.begin(); - for ( ; it != Rxn_gas_phase_map.end(); it++) + //std::map::iterator it = Rxn_gas_phase_map.begin(); + //for ( ; it != Rxn_gas_phase_map.end(); it++) + for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) { + std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); cxxGasPhase *gas_phase_ptr = &(it->second); - if (gas_phase_ptr->Get_new_def() != TRUE) - continue; + //if (gas_phase_ptr->Get_new_def() != TRUE) + // continue; gas_phase_ptr->Set_new_def(false); PR = false; P = 0.0; @@ -906,7 +908,7 @@ tidy_gas_phase(void) { input_error++; error_string = sformatf( - "Gas not found in PHASES data base, %s.", + "Gas not found in PHASES database, %s.", gc[j].Get_phase_name().c_str()); error_msg(error_string, CONTINUE); continue; @@ -1500,12 +1502,15 @@ tidy_pp_assemblage(void) /* * Find pointers for pure phases */ - std::map::iterator it; - it = Rxn_pp_assemblage_map.begin(); - for ( ; it != Rxn_pp_assemblage_map.end(); it++) + //std::map::iterator it; + //it = Rxn_pp_assemblage_map.begin(); + //for ( ; it != Rxn_pp_assemblage_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_pp_assemblage.size(); nn++) { - if (!it->second.Get_new_def()) continue; - cxxPPassemblage *pp_assemblage_ptr = &(it->second); + std::map::iterator kit = Rxn_pp_assemblage_map.find(Rxn_new_pp_assemblage[nn]); + //if (!kit->second.Get_new_def()) continue; + cxxPPassemblage *pp_assemblage_ptr = &(kit->second); count_elts = 0; paren_count = 0; coef = 1.0; @@ -1520,7 +1525,7 @@ tidy_pp_assemblage(void) if (phase_ptr == NULL) { input_error++; - error_string = sformatf( "Phase not found in data base, %s.", + error_string = sformatf( "Phase not found in database, %s.", it->first.c_str()); error_msg(error_string, CONTINUE); continue; @@ -1588,10 +1593,13 @@ tidy_ss_assemblage(void) /* * Find pointers for pure phases */ - std::map::iterator it; - for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + //std::map::iterator it; + //for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_ss_assemblage.size(); nn++) { - if (!it->second.Get_new_def()) continue; + std::map::iterator it = Rxn_ss_assemblage_map.find(Rxn_new_ss_assemblage[nn]); + //if (!it->second.Get_new_def()) continue; count_elts = 0; paren_count = 0; cxxSSassemblage *ss_assemblage_ptr = &(it->second); @@ -1608,7 +1616,7 @@ tidy_ss_assemblage(void) { input_error++; error_string = sformatf( - "Phase not found in data base, %s, assemblage %d.", + "Phase not found in database, %s, assemblage %d.", comp_ptr->Get_name().c_str(), ss_assemblage_ptr->Get_n_user()); error_msg(error_string, CONTINUE); @@ -2375,10 +2383,13 @@ tidy_surface(void) */ char *ptr1; cxxSurface *surface_ptr; - std::map::iterator kit; - for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) + //std::map::iterator kit; + //for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) + //{ + for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { - if (!kit->second.Get_new_def()) continue; + std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + //if (!kit->second.Get_new_def()) continue; surface_ptr = &(kit->second); for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { @@ -2395,7 +2406,7 @@ tidy_surface(void) { input_error++; error_string = sformatf( - "Master species not in data base for %s, " + "Master species not in database for %s, " "skipping element.", elt_ptr->name); error_msg(error_string, CONTINUE); @@ -2533,17 +2544,20 @@ tidy_solutions(void) { unnumbered_solutions[i].Set_n_user_both(++last); Rxn_solution_map[last] = unnumbered_solutions[i]; + Rxn_new_solution.push_back(last); } unnumbered_solutions.clear(); } /* * Check that elements are in database */ - std::map::iterator it; - for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) + //std::map::iterator it; + //for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) + for(size_t n = 0; n < Rxn_new_solution.size(); n++) { + std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[n]); cxxSolution &solution_ref = it->second; - if (solution_ref.Get_new_def()) + //if (solution_ref.Get_new_def()) { cxxISolution *initial_data_ptr = solution_ref.Get_initial_data(); if (initial_data_ptr != NULL) @@ -2834,14 +2848,16 @@ tidy_kin_exchange(void) char *ptr; LDBLE conc; - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) + //std::map::iterator it = Rxn_exchange_map.begin(); + //for ( ; it != Rxn_exchange_map.end(); it++) + for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { + std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); cxxExchange * exchange_ptr = &(it->second); - if (!exchange_ptr->Get_new_def()) - continue; - if (exchange_ptr->Get_n_user() < 0) - continue; + //if (!exchange_ptr->Get_new_def()) + // continue; + //if (exchange_ptr->Get_n_user() < 0) + // continue; // check elements for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { @@ -2859,8 +2875,8 @@ tidy_kin_exchange(void) if (elt_ptr == NULL || elt_ptr->master == NULL) { input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", elt_ptr->name); error_msg(error_string, CONTINUE); continue; @@ -2943,14 +2959,17 @@ tidy_min_exchange(void) char *ptr; LDBLE conc; - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) + //std::map::iterator it = Rxn_exchange_map.begin(); + //for ( ; it != Rxn_exchange_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { + std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); cxxExchange * exchange_ptr = &(it->second); - if (!exchange_ptr->Get_new_def()) - continue; - if (exchange_ptr->Get_n_user() < 0) - continue; + //if (!exchange_ptr->Get_new_def()) + // continue; + //if (exchange_ptr->Get_n_user() < 0) + // continue; n = exchange_ptr->Get_n_user(); // check elements for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) @@ -2969,8 +2988,8 @@ tidy_min_exchange(void) if (elt_ptr == NULL || elt_ptr->master == NULL) { input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", kit->first.c_str()); error_msg(error_string, CONTINUE); continue; @@ -3082,14 +3101,17 @@ tidy_min_surface(void) * set in proportion */ { - std::map::iterator kit; - for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) + //std::map::iterator kit; + //for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) + //{ + for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { + std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); cxxSurface *surface_ptr = &(kit->second); - if (!surface_ptr->Get_new_def()) - continue; - if (surface_ptr->Get_n_user() < 0) - continue; + //if (!surface_ptr->Get_new_def()) + // continue; + //if (surface_ptr->Get_n_user() < 0) + // continue; for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { cxxSurfaceComp *surface_comp_ptr = &(surface_ptr->Get_surface_comps()[j]); @@ -3109,8 +3131,8 @@ tidy_min_surface(void) if (master_ptr == NULL) { input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", elt_ptr->name); error_msg(error_string, CONTINUE); continue; @@ -3325,14 +3347,17 @@ tidy_kin_surface(void) struct elt_list *elt_list_kinetics; int count_elts_kinetics; - std::map::iterator it; - for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) + //std::map::iterator it; + //for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) + //{ + for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { + std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); cxxSurface *surface_ptr = &(it->second); - if (!surface_ptr->Get_new_def()) - continue; - if (surface_ptr->Get_n_user() < 0) - continue; + //if (!surface_ptr->Get_new_def()) + // continue; + //if (surface_ptr->Get_n_user() < 0) + // continue; int n = surface_ptr->Get_n_user(); for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { @@ -3352,8 +3377,8 @@ tidy_kin_surface(void) if (master_ptr == NULL) { input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", elt_ptr->name); error_msg(error_string, CONTINUE); continue; @@ -4679,14 +4704,17 @@ tidy_exchange(void) * set in proportion */ { - std::map::iterator it = Rxn_exchange_map.begin(); - for ( ; it != Rxn_exchange_map.end(); it++) + //std::map::iterator it = Rxn_exchange_map.begin(); + //for ( ; it != Rxn_exchange_map.end(); it++) + for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { + std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + //std::map::iterator it = Rxn_exchange_map.begin(); cxxExchange * exchange_ptr = &(it->second); - if (!exchange_ptr->Get_new_def()) - continue; - if (exchange_ptr->Get_n_user() < 0) - continue; + //if (!exchange_ptr->Get_new_def()) + // continue; + //if (exchange_ptr->Get_n_user() < 0) + // continue; // check elements for (size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) { @@ -4706,8 +4734,8 @@ tidy_exchange(void) if (elt_ptr == NULL || elt_ptr->master == NULL) { input_error++; - error_string = sformatf( "Master species not in data " - "base for %s, skipping element.", + error_string = sformatf( "Master species not in database " + "for %s, skipping element.", kit->first.c_str()); error_msg(error_string, CONTINUE); break; From b75ce1b704a9229c08749df917de69d1538ef243 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 18:04:57 +0000 Subject: [PATCH 0593/1077] Fixed bug with _modify. Did not get correct n_user! Added asserts for n_user not found from Rxn_new. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7221 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ phreeqc/mainsubs.cpp | 16 ++++++++++++++++ phreeqc/prep.cpp | 20 ++++++++++---------- phreeqc/tidy.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 10 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 8452a0ab..9d202498 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -2042,6 +2042,9 @@ namespace Utilities } entity_ptr->read_raw(parser, false); + entity_ptr->Set_n_user(nk.Get_n_user()); + entity_ptr->Set_n_user_end(nk.Get_n_user_end()); + entity_ptr->Set_description(nk.Get_description()); v.push_back(entity_ptr->Get_n_user()); return phreeqc_cookie->cleanup_after_parser(parser); diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index dd3cda64..ba87abb3 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1284,6 +1284,10 @@ initial_solutions(int print) for (size_t nn = 0; nn < Rxn_new_solution.size(); nn++) { std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[nn]); + if (it == Rxn_solution_map.end()) + { + assert(false); + } cxxSolution &solution_ref = it->second; initial_solution_isotopes = FALSE; if (solution_ref.Get_new_def()) @@ -1387,6 +1391,10 @@ initial_exchangers(int print) for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + if (it == Rxn_exchange_map.end()) + { + assert(false); + } if (!it->second.Get_new_def()) continue; cxxExchange *exchange_ptr = &(it->second); @@ -1470,6 +1478,10 @@ initial_gas_phases(int print) for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) { std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + if (it == Rxn_gas_phase_map.end()) + { + assert(false); + } cxxGasPhase *gas_phase_ptr = &it->second; if (!gas_phase_ptr->Get_new_def()) continue; @@ -1583,6 +1595,10 @@ initial_surfaces(int print) for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + if (it == Rxn_surface_map.end()) + { + assert(false); + } cxxSurface * surface_ptr = &it->second; if (!surface_ptr->Get_new_def()) continue; diff --git a/phreeqc/prep.cpp b/phreeqc/prep.cpp index 29d938c3..04471c7d 100644 --- a/phreeqc/prep.cpp +++ b/phreeqc/prep.cpp @@ -3311,16 +3311,16 @@ setup_exchange(void) for (size_t j = 0; j < use.Get_exchange_ptr()->Get_exchange_comps().size(); j++) { cxxExchComp & comp_ref = use.Get_exchange_ptr()->Get_exchange_comps()[j]; - { - element * elt_ptr = element_store(comp_ref.Get_formula().c_str()); - if (elt_ptr == NULL || elt_ptr->master == NULL) - { - error_string = sformatf( "Component not in database, %s", comp_ref.Get_formula().c_str()); - input_error++; - error_msg(error_string, CONTINUE); - continue; - } - } + //{ + // element * elt_ptr = element_store(comp_ref.Get_formula().c_str()); + // if (elt_ptr == NULL || elt_ptr->master == NULL) + // { + // error_string = sformatf( "Component not in database, %s", comp_ref.Get_formula().c_str()); + // input_error++; + // error_msg(error_string, CONTINUE); + // continue; + // } + //} cxxNameDouble nd(comp_ref.Get_totals()); cxxNameDouble::iterator it = nd.begin(); diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index d45a25c6..1827f56a 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -893,6 +893,10 @@ tidy_gas_phase(void) for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) { std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + if (it == Rxn_gas_phase_map.end()) + { + assert(false); + } cxxGasPhase *gas_phase_ptr = &(it->second); //if (gas_phase_ptr->Get_new_def() != TRUE) // continue; @@ -1509,6 +1513,10 @@ tidy_pp_assemblage(void) for (size_t nn = 0; nn < Rxn_new_pp_assemblage.size(); nn++) { std::map::iterator kit = Rxn_pp_assemblage_map.find(Rxn_new_pp_assemblage[nn]); + if (kit == Rxn_pp_assemblage_map.end()) + { + assert(false); + } //if (!kit->second.Get_new_def()) continue; cxxPPassemblage *pp_assemblage_ptr = &(kit->second); count_elts = 0; @@ -1599,6 +1607,10 @@ tidy_ss_assemblage(void) for (size_t nn = 0; nn < Rxn_new_ss_assemblage.size(); nn++) { std::map::iterator it = Rxn_ss_assemblage_map.find(Rxn_new_ss_assemblage[nn]); + if (it == Rxn_ss_assemblage_map.end()) + { + assert(false); + } //if (!it->second.Get_new_def()) continue; count_elts = 0; paren_count = 0; @@ -2389,6 +2401,10 @@ tidy_surface(void) for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + if (kit == Rxn_surface_map.end()) + { + assert(false); + } //if (!kit->second.Get_new_def()) continue; surface_ptr = &(kit->second); for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) @@ -2556,6 +2572,10 @@ tidy_solutions(void) for(size_t n = 0; n < Rxn_new_solution.size(); n++) { std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[n]); + if (it == Rxn_solution_map.end()) + { + assert(false); + } cxxSolution &solution_ref = it->second; //if (solution_ref.Get_new_def()) { @@ -2853,6 +2873,10 @@ tidy_kin_exchange(void) for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + if (it == Rxn_exchange_map.end()) + { + assert(false); + } cxxExchange * exchange_ptr = &(it->second); //if (!exchange_ptr->Get_new_def()) // continue; @@ -2965,6 +2989,10 @@ tidy_min_exchange(void) for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + if (it == Rxn_exchange_map.end()) + { + assert(false); + } cxxExchange * exchange_ptr = &(it->second); //if (!exchange_ptr->Get_new_def()) // continue; @@ -3107,6 +3135,10 @@ tidy_min_surface(void) for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + if (kit == Rxn_surface_map.end()) + { + assert(false); + } cxxSurface *surface_ptr = &(kit->second); //if (!surface_ptr->Get_new_def()) // continue; @@ -3353,6 +3385,10 @@ tidy_kin_surface(void) for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) { std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + if (it == Rxn_surface_map.end()) + { + assert(false); + } cxxSurface *surface_ptr = &(it->second); //if (!surface_ptr->Get_new_def()) // continue; @@ -4709,6 +4745,10 @@ tidy_exchange(void) for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) { std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + if (it == Rxn_exchange_map.end()) + { + assert(false); + } //std::map::iterator it = Rxn_exchange_map.begin(); cxxExchange * exchange_ptr = &(it->second); //if (!exchange_ptr->Get_new_def()) From f74bc4442b8b469cb13752f3fb0972e277e272fd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 18:28:44 +0000 Subject: [PATCH 0594/1077] Solution_spread did not set Rxn_new_solution git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7222 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/spread.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index 23a33c63..cefaade3 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -562,6 +562,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, n_user_end = nk.Get_n_user_end(); description = nk.Get_description(); next_keyword = next_keyword_save; + Rxn_new_solution.push_back(n_user); } } /* From 6f22118508eb3c5ec0c7969a63f7b734c3948fed Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 19:23:46 +0000 Subject: [PATCH 0595/1077] Changed Rxn_new from vector to set. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7223 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 30 +++++++++--------- phreeqc/mainsubs.cpp | 30 ++++++++++++------ phreeqc/read.cpp | 12 ++++---- phreeqc/spread.cpp | 2 +- phreeqc/tidy.cpp | 72 +++++++++++++++++++++++++++++++------------- 5 files changed, 93 insertions(+), 53 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 9d202498..4e646f93 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1214,17 +1214,17 @@ protected: /* * List new definitions */ - std::vector Rxn_new_exchange; - std::vector Rxn_new_gas_phase; - std::vector Rxn_new_kinetics; // not used - std::vector Rxn_new_mix; // not used - std::vector Rxn_new_pp_assemblage; - std::vector Rxn_new_pressure; // not used - std::vector Rxn_new_reaction; // not used - std::vector Rxn_new_solution; - std::vector Rxn_new_ss_assemblage; - std::vector Rxn_new_surface; - std::vector Rxn_new_temperature; // not used + std::set Rxn_new_exchange; + std::set Rxn_new_gas_phase; + std::set Rxn_new_kinetics; // not used + std::set Rxn_new_mix; // not used + std::set Rxn_new_pp_assemblage; + std::set Rxn_new_pressure; // not used + std::set Rxn_new_reaction; // not used + std::set Rxn_new_solution; + std::set Rxn_new_ss_assemblage; + std::set Rxn_new_surface; + std::set Rxn_new_temperature; // not used /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ @@ -1994,7 +1994,7 @@ namespace Utilities } } template < typename T > - int Rxn_read_raw(std::map < int, T > &m, std::vector < int > &v, Phreeqc * phreeqc_cookie) + int Rxn_read_raw(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) { typename std::map < int, T >::iterator it; assert(!phreeqc_cookie->reading_database()); @@ -2014,13 +2014,13 @@ namespace Utilities Utilities::Rxn_copies(m, entity.Get_n_user(), entity.Get_n_user_end()); for (int i = entity.Get_n_user(); i <= entity.Get_n_user_end(); i++) { - v.push_back(i); + s.insert(i); } return phreeqc_cookie->cleanup_after_parser(parser); } template < typename T > - int Rxn_read_modify(std::map < int, T > &m, std::vector < int > &v, Phreeqc * phreeqc_cookie) + int Rxn_read_modify(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) { typename std::map < int, T >::iterator it; @@ -2045,7 +2045,7 @@ namespace Utilities entity_ptr->Set_n_user(nk.Get_n_user()); entity_ptr->Set_n_user_end(nk.Get_n_user_end()); entity_ptr->Set_description(nk.Get_description()); - v.push_back(entity_ptr->Get_n_user()); + s.insert(entity_ptr->Get_n_user()); return phreeqc_cookie->cleanup_after_parser(parser); } diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index ba87abb3..e0efc183 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -1281,9 +1281,10 @@ initial_solutions(int print) //std::map::iterator it = Rxn_solution_map.begin(); //for ( ; it != Rxn_solution_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_solution.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_solution.size(); nn++) + for (std::set::const_iterator nit = Rxn_new_solution.begin(); nit != Rxn_new_solution.end(); nit++) { - std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[nn]); + std::map::iterator it = Rxn_solution_map.find(*nit); if (it == Rxn_solution_map.end()) { assert(false); @@ -1388,9 +1389,12 @@ initial_exchangers(int print) //std::map::iterator it = Rxn_exchange_map.begin(); //for ( ; it != Rxn_exchange_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //{ + //std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + for (std::set::const_iterator nit = Rxn_new_exchange.begin(); nit != Rxn_new_exchange.end(); nit++) { - std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + std::map::iterator it = Rxn_exchange_map.find(*nit); if (it == Rxn_exchange_map.end()) { assert(false); @@ -1475,9 +1479,12 @@ initial_gas_phases(int print) //std::map::iterator it = Rxn_gas_phase_map.begin(); //for ( ; it != Rxn_gas_phase_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) + //{ + //std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) { - std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + std::map::iterator it = Rxn_gas_phase_map.find(*nit); if (it == Rxn_gas_phase_map.end()) { assert(false); @@ -1592,9 +1599,12 @@ initial_surfaces(int print) //std::map::iterator it = Rxn_surface_map.begin(); //for ( ; it != Rxn_surface_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //{ + //std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + for (std::set::const_iterator nit = Rxn_new_surface.begin(); nit != Rxn_new_surface.end(); nit++) { - std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + std::map::iterator it = Rxn_surface_map.find(*nit); if (it == Rxn_surface_map.end()) { assert(false); @@ -2932,12 +2942,12 @@ run_simulations(void) /* ---------------------------------------------------------------------- */ { char token[MAX_LENGTH]; -#ifdef SKIP_KEEP +//#ifdef SKIP_KEEP #if defined(WIN32) unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif -#endif +//#endif /* * Prepare error handling */ diff --git a/phreeqc/read.cpp b/phreeqc/read.cpp index d8a9473b..103ae19f 100644 --- a/phreeqc/read.cpp +++ b/phreeqc/read.cpp @@ -1110,7 +1110,7 @@ read_exchange(void) break; } Rxn_exchange_map[n_user] = temp_exchange; - Rxn_new_exchange.push_back(n_user); + Rxn_new_exchange.insert(n_user); return (return_value); } @@ -1403,7 +1403,7 @@ read_gas_phase(void) Rxn_gas_phase_map[n_user] = temp_gas_phase; - Rxn_new_gas_phase.push_back(n_user); + Rxn_new_gas_phase.insert(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -4204,7 +4204,7 @@ read_pp_assemblage(void) } temp_pp_assemblage.Set_pp_assemblage_comps(comps); Rxn_pp_assemblage_map[n_user] = temp_pp_assemblage; - Rxn_new_pp_assemblage.push_back(n_user); + Rxn_new_pp_assemblage.insert(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -5369,7 +5369,7 @@ read_solution(void) } } Rxn_solution_map[n_user] = temp_solution; - Rxn_new_solution.push_back(n_user); + Rxn_new_solution.insert(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -7145,7 +7145,7 @@ read_surface(void) } temp_surface.Sort_comps(); Rxn_surface_map[n_user] = temp_surface; - Rxn_new_surface.push_back(n_user); + Rxn_new_surface.insert(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ @@ -9709,7 +9709,7 @@ read_solid_solutions(void) // Add to map Rxn_ss_assemblage_map[n_user] = temp_ss_assemblage; - Rxn_new_ss_assemblage.push_back(n_user); + Rxn_new_ss_assemblage.insert(n_user); return (return_value); } /* ---------------------------------------------------------------------- */ diff --git a/phreeqc/spread.cpp b/phreeqc/spread.cpp index cefaade3..3f35fb86 100644 --- a/phreeqc/spread.cpp +++ b/phreeqc/spread.cpp @@ -562,7 +562,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, n_user_end = nk.Get_n_user_end(); description = nk.Get_description(); next_keyword = next_keyword_save; - Rxn_new_solution.push_back(n_user); + Rxn_new_solution.insert(n_user); } } /* diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 1827f56a..936e23f0 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -890,9 +890,12 @@ tidy_gas_phase(void) */ //std::map::iterator it = Rxn_gas_phase_map.begin(); //for ( ; it != Rxn_gas_phase_map.end(); it++) - for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) + //{ + //std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) { - std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); + std::map::iterator it = Rxn_gas_phase_map.find(*nit); if (it == Rxn_gas_phase_map.end()) { assert(false); @@ -1510,9 +1513,12 @@ tidy_pp_assemblage(void) //it = Rxn_pp_assemblage_map.begin(); //for ( ; it != Rxn_pp_assemblage_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_pp_assemblage.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_pp_assemblage.size(); nn++) + //{ + //std::map::iterator kit = Rxn_pp_assemblage_map.find(Rxn_new_pp_assemblage[nn]); + for (std::set::const_iterator nit = Rxn_new_pp_assemblage.begin(); nit != Rxn_new_pp_assemblage.end(); nit++) { - std::map::iterator kit = Rxn_pp_assemblage_map.find(Rxn_new_pp_assemblage[nn]); + std::map::iterator kit = Rxn_pp_assemblage_map.find(*nit); if (kit == Rxn_pp_assemblage_map.end()) { assert(false); @@ -1604,9 +1610,12 @@ tidy_ss_assemblage(void) //std::map::iterator it; //for (it = Rxn_ss_assemblage_map.begin(); it != Rxn_ss_assemblage_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_ss_assemblage.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_ss_assemblage.size(); nn++) + //{ + //std::map::iterator it = Rxn_ss_assemblage_map.find(Rxn_new_ss_assemblage[nn]); + for (std::set::const_iterator nit = Rxn_new_ss_assemblage.begin(); nit != Rxn_new_ss_assemblage.end(); nit++) { - std::map::iterator it = Rxn_ss_assemblage_map.find(Rxn_new_ss_assemblage[nn]); + std::map::iterator it = Rxn_ss_assemblage_map.find(*nit); if (it == Rxn_ss_assemblage_map.end()) { assert(false); @@ -2398,9 +2407,12 @@ tidy_surface(void) //std::map::iterator kit; //for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) //{ - for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //{ + //std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + for (std::set::const_iterator nit = Rxn_new_surface.begin(); nit != Rxn_new_surface.end(); nit++) { - std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + std::map::iterator kit = Rxn_surface_map.find(*nit); if (kit == Rxn_surface_map.end()) { assert(false); @@ -2560,7 +2572,7 @@ tidy_solutions(void) { unnumbered_solutions[i].Set_n_user_both(++last); Rxn_solution_map[last] = unnumbered_solutions[i]; - Rxn_new_solution.push_back(last); + Rxn_new_solution.insert(last); } unnumbered_solutions.clear(); } @@ -2569,9 +2581,12 @@ tidy_solutions(void) */ //std::map::iterator it; //for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++) - for(size_t n = 0; n < Rxn_new_solution.size(); n++) + //for(size_t n = 0; n < Rxn_new_solution.size(); n++) + //{ + //std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[n]); + for (std::set::const_iterator nit = Rxn_new_solution.begin(); nit != Rxn_new_solution.end(); nit++) { - std::map::iterator it = Rxn_solution_map.find(Rxn_new_solution[n]); + std::map::iterator it = Rxn_solution_map.find(*nit); if (it == Rxn_solution_map.end()) { assert(false); @@ -2870,9 +2885,12 @@ tidy_kin_exchange(void) //std::map::iterator it = Rxn_exchange_map.begin(); //for ( ; it != Rxn_exchange_map.end(); it++) - for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //{ + //std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + for (std::set::const_iterator nit = Rxn_new_exchange.begin(); nit != Rxn_new_exchange.end(); nit++) { - std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + std::map::iterator it = Rxn_exchange_map.find(*nit); if (it == Rxn_exchange_map.end()) { assert(false); @@ -2986,9 +3004,12 @@ tidy_min_exchange(void) //std::map::iterator it = Rxn_exchange_map.begin(); //for ( ; it != Rxn_exchange_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //{ + //std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + for (std::set::const_iterator nit = Rxn_new_exchange.begin(); nit != Rxn_new_exchange.end(); nit++) { - std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + std::map::iterator it = Rxn_exchange_map.find(*nit); if (it == Rxn_exchange_map.end()) { assert(false); @@ -3132,9 +3153,12 @@ tidy_min_surface(void) //std::map::iterator kit; //for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++) //{ - for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //{ + // std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + for (std::set::const_iterator nit = Rxn_new_surface.begin(); nit != Rxn_new_surface.end(); nit++) { - std::map::iterator kit = Rxn_surface_map.find(Rxn_new_surface[nn]); + std::map::iterator kit = Rxn_surface_map.find(*nit); if (kit == Rxn_surface_map.end()) { assert(false); @@ -3382,9 +3406,12 @@ tidy_kin_surface(void) //std::map::iterator it; //for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++) //{ - for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_surface.size(); nn++) + //{ + // std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + for (std::set::const_iterator nit = Rxn_new_surface.begin(); nit != Rxn_new_surface.end(); nit++) { - std::map::iterator it = Rxn_surface_map.find(Rxn_new_surface[nn]); + std::map::iterator it = Rxn_surface_map.find(*nit); if (it == Rxn_surface_map.end()) { assert(false); @@ -4742,9 +4769,12 @@ tidy_exchange(void) { //std::map::iterator it = Rxn_exchange_map.begin(); //for ( ; it != Rxn_exchange_map.end(); it++) - for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //for (size_t nn = 0; nn < Rxn_new_exchange.size(); nn++) + //{ + // std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + for (std::set::const_iterator nit = Rxn_new_exchange.begin(); nit != Rxn_new_exchange.end(); nit++) { - std::map::iterator it = Rxn_exchange_map.find(Rxn_new_exchange[nn]); + std::map::iterator it = Rxn_exchange_map.find(*nit); if (it == Rxn_exchange_map.end()) { assert(false); From af148da62bd2e6a4593b48844a53226aeee0c8d6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 20:40:42 +0000 Subject: [PATCH 0596/1077] Freed s_x by mistake git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7224 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/inverse.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phreeqc/inverse.cpp b/phreeqc/inverse.cpp index 8ef9bb6d..85c898b1 100644 --- a/phreeqc/inverse.cpp +++ b/phreeqc/inverse.cpp @@ -4721,7 +4721,9 @@ dump_netpath_pat(struct inverse *inv_ptr) fprintf(netpath_file, "%14d # Well number\n", count_pat_solutions); } - free_model_allocs(); + //free_model_allocs(); + array = (LDBLE *) free_check_null(array); + delta = (LDBLE *) free_check_null(delta); array = array_save; delta = l_delta_save; count_unknowns = count_unknowns_save; From bd10ce021fb0b8b031e2c222c695ed65df9a91ab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 21:04:11 +0000 Subject: [PATCH 0597/1077] Fixed memory leak for CD_MUSIC git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7225 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/tidy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phreeqc/tidy.cpp b/phreeqc/tidy.cpp index 936e23f0..15fcc8b4 100644 --- a/phreeqc/tidy.cpp +++ b/phreeqc/tidy.cpp @@ -3348,8 +3348,8 @@ tidy_min_surface(void) elt_ptr->master->s->name); warning_msg(error_string); } - free_check_null(temp_formula); } + free_check_null(temp_formula); } } qsort(elt_list, (size_t) count_elts, From bd446838bb38c88fce21b7a704ffbbc0baa4aded Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Dec 2012 23:01:35 +0000 Subject: [PATCH 0598/1077] accidently checked in 2-digit exponent git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7228 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/mainsubs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index e0efc183..2a7fe05a 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -2942,12 +2942,12 @@ run_simulations(void) /* ---------------------------------------------------------------------- */ { char token[MAX_LENGTH]; -//#ifdef SKIP_KEEP +#ifdef SKIP_KEEP #if defined(WIN32) unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif -//#endif +#endif /* * Prepare error handling */ From e765dc43091549b4fe2fdee07dced9905cad69ae Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Dec 2012 17:21:15 +0000 Subject: [PATCH 0599/1077] Updated makefiles for parallel testing. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7236 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eda516e9..7c1ab22f 100644 --- a/Makefile +++ b/Makefile @@ -979,8 +979,8 @@ dependencies: cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp tester: - cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../mytest; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples From 2109cc8f22abd4fdf0c1537d549199eb26fddc22 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 20 Dec 2012 23:22:16 +0000 Subject: [PATCH 0600/1077] Added active_charts to ChartHandler. Incremented when form starts, decremented when form ends. Removed revisions and PHREEQCPP-RELEASE.txt git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7248 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 1 + ChartHandler.h | 10 + PHREEQCPP-RELEASE.txt | 751 ---------- Phreeqc.h | 4 +- phreeqc/Form1.h | 45 +- phreeqc/print.cpp | 1 + phreeqc/revisions | 3102 ---------------------------------------- phreeqc/structures.cpp | 5 + 8 files changed, 44 insertions(+), 3875 deletions(-) delete mode 100644 PHREEQCPP-RELEASE.txt delete mode 100644 phreeqc/revisions diff --git a/ChartHandler.cpp b/ChartHandler.cpp index a868bb82..efa759fe 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -25,6 +25,7 @@ PHRQ_base(io) current_chart_n_user = -1000; u_g_defined = false; timer = true; + active_charts = 0; } ChartHandler::~ChartHandler() diff --git a/ChartHandler.h b/ChartHandler.h index e8d5c0f2..f0ca405b 100644 --- a/ChartHandler.h +++ b/ChartHandler.h @@ -31,6 +31,15 @@ public: { return timer; } + int Get_active_charts() {return this->active_charts;} + void Increment_active_charts() + { + System::Threading::Interlocked::Increment(this->active_charts); + } + void Decrement_active_charts() + { + System::Threading::Interlocked::Decrement(this->active_charts); + } bool Read(Phreeqc * phreeqc_ptr, CParser &parser); void Punch_user_graph(Phreeqc * phreeqc_ptr); bool End_timer(); @@ -41,6 +50,7 @@ protected: ChartObject * current_chart; bool u_g_defined; bool timer; + int active_charts; public: diff --git a/PHREEQCPP-RELEASE.txt b/PHREEQCPP-RELEASE.txt deleted file mode 100644 index 546b59bb..00000000 --- a/PHREEQCPP-RELEASE.txt +++ /dev/null @@ -1,751 +0,0 @@ -************************************************************ -************************************************************ -* Features in PHREEQC++ Not in PHREEQC * -* Revisions and Bug Fixes * -* PHREEQC++ is used only in IPhreeqc Modules * -************************************************************ ------------------------------------------------------------- -Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------- - See PHREEQC release notes. - ------------------------------------------------------------- -Version 2.18.2: April 9, 2011 ------------------------------------------------------------- -------- - -------- - svn 5471 - -------- - Added PHASE_FORMULA and LIST_S_S Basic functions. - - PHASE_FORMULA returns a string value with the - chemical formula for the phase as defined in - PHASES data. If 4 arguments are provide, a list - of the elements and stoichiometric coefficients for - elements are returned. - - USER_PRINT - 10 min$ = "Calcite" - 20 form$ = PHASE_FORMULA(min$) - 30 print min$, form$ - 40 form$ = PHASE_FORMULA(min$, count, elts$, coefs) - 50 for i = 1 to count - 60 print " ", PAD(elts$[i], 20), coefs[i] - 70 next i - - This example produces the following output: - -Calcite CaCO3 - C 1 - Ca 1 - O 3 - - LIST_S_S returns the sum of moles of all components - in a specified solid solution. Lists of the components - and the number of moles of each component are also - returned. - - - SOLID_SOLUTIONS 1 - Calcite_s_s - -comp Calcite 0.01 - -comp Smithsonite 0.001 - -comp Strontianite 0.02 - USER_PRINT - 10 name$ = "Calcite_s_s" - 20 total = LIST_S_S(name$, count, comp$, moles) - 30 print PAD(name$, 20), total - 40 for i = 1 to count - 50 print " ", PAD(comp$[i], 20), moles[i], moles[i]/total - 60 next i - - This example produces the following output: - -Calcite_s_s 3.0876e-002 - Calcite 9.9316e-003 3.2166e-001 - Smithsonite 9.6666e-004 3.1308e-002 - Strontianite 1.9978e-002 6.4704e-001 - - -------- - svn 5455 - -------- - REACTION_MODIFY keyword was added to the modules. Previously, - REACTION_MODIFY was not recognized as a keyword. - - -------- - svn 5453 - -------- - Fixed bug with in READ_SOLUTION_RAW. A read error occurred - when -isotopes was encountered. - - -------- - svn 5448 - -------- - Reading of default user number, but specified description - was in error under some conditions. - - -------- - svn 5431 - -------- - RUN_CELLS was rewritten to perform multiple calculations - if multiple steps are defined in REACTION, REACTION_TEMPERATURE, - or KINETICS. It now operates in the same way that a - series of USE and SAVES would operate. Previously, only - one step of a series of reaction steps was taken. If a - time step is provided in RUN_CELLS for kinetic reactions and - nmax is the maximum number of steps defined for REACTION, - REACTION_TEMPERATURE, and KINETICS, the time step is divided - into nmax equal increments. It is equivalent to the following - definition in kinetics: -step time_step in nmax steps. - - -------- - svn 5324 - -------- - Modified solution method for solid solutions so that - mole transfers were limited to the total amount - available in the system. - ------------------------------------------------------------- -Version 2.18.0: April 9, 2011 ------------------------------------------------------------- - - -------- - svn 5281 - -------- - If SOLUTION_MODIFY is used to change a total for an element, - the activities for the master species of the element are - automatically updated by the ratio of the new total to the - old total, unless activities are specifically set for the - element with -activities. All valence states of redox elements - are adjusted. - - -------- - svn 5270 - -------- - Added logic to update estimates of log activity when - modifying totals in SOLUTION_MODIFY. The initial - guesses for activities are adjusted proportionally - to the change in total moles of elements (as defined - by SOLUTION_MODIFY; -totals). - - This automatic adjustment is suggested rather than - explicit definition of the initial guesses through - SOLUTION_MODIFY; -activities. However, the -activities - identifier may be used and will supercede the automatic - adjustment. - - The adjustment of the initial guesses for activities - should reduce the number of iterations needed to solve - a given set of equations and, consequently, should - lessen the total CPU time for a simulation. - - -------- - svn 4897 - -------- - Added capability to include files within the input - file. Files included in include files are also - included. Files are included verbatim and need not - contain complete keyword datablocks; however, the - combination of included files must result in a - legal PHREEQC input file. Files are included as - simulations are proceeding, so it is possible to - write a file at one point of a run that is included - later in the same run. Included files can contain - INCLUDE$ directives. - - SOLUTION - INCLUDE$ file_name - END - - where "file_name" contains: - EQUILIBRIUM_PHASES - Calcite 0 10 - - is the same as a single file with - SOLUTION - EQUILIBRIUM_PHASES - Calcite 0 10 - END - - -------- - svn 4856 - -------- - Revised logic of searching pitzer parameters so that - order of ions in a parameter definition does not - matter. - - -------- - svn 4823 - -------- - Added -cells to DUMP and DELETE; cell option to COPY. - Example: - - COPY cell 1 4 - COPY cell 1 5-10 - DUMP - -cell 1 2-3 10 - DELETE - -cell 1-3 4 8-10 - - COPY cell n range - - The cell option of the COPY keyword causes all reactants - defined with identifying number n to be copied to a single - range of numbers. The range of numbers can be a single - number or a range of numbers given by an integer, a - hyphen, and an integer, with no intervening spaces. - - DUMP - -cell list - - The -cell option writes _RAW formatted output to a - specified file(see below for more details) for each - reactant that is defined in the list. - - DUMP - -cell list - The -cell deletes from memory all reactants that are - defined with identifying numbers in the list. - - The list of numbers for DUMP and DELETE are - more flexible than for COPY. A list of ranges can be - given for DUMP and DELETE, where each element of - the list can be a single number or a range of numbers - defined by an integer, a hyphen, and an ingeger, with - no intervening spaces. - - -------- - svn 4816 - -------- - Added compile capability to use #include file_name - in input and database files. PHREEQCPP process the - files at the start of the run, possibly following - multiple layers of include files, to produce a stream - that is then used as input. Compile define is - MERGE_INCLUDE_FILES; PHREEQC_CLASS also must be defined. - - Input file: - SOLUTION 1 - #INCLUDE t2 - #include t4 - END - - File t2: - REACTION - NaCl - 1 mmol - #include t3 - - File t3: - REACTION_TEMPERATURE - 10 20 30 - - File t4: - SAVE solution 1 - - When compiled with the include file #defines, the above - set of files produces the following input for PHREEQC: - - SOLUTION 1 - REACTION - NaCl - 1 mmol - REACTION_TEMPERATURE - 10 20 30 - SAVE solution 1 - END - - -------- - svn 4800 - -------- - - Added capability to dump REACTIONs, REACTION_TEMPERATUREs, - and MIXes. - - DUMP - -mix 1 4 6 - -reaction 1-5 - -reaction_temperature 1 3-9 - - List of numbers may be formatted as described for DUMP. - Data are written in a format suitable for an input file - to PHREEQCPP. - - Example of dumped keywords: - - MIX 1 - 1 0.33 - 2 0.33 - 3 0.34 - REACTION_RAW 1 - -units Mol - -reactant_list - Ba 1 - Br 2 - -element_list - -steps - 0.01 - -equal_increments 1 - -count_steps 2 - REACTION_TEMPERATURE_RAW 1 - -count_temps 3 - -equal_increments 1 - -temps - 25 45 - - -------- - - Added -cells option to DUMP. - - DUMP - -cells 1-19 20 - - This -cells option will dump any reactant with numbers - between 1 and 20, including SOLUTIONs, EXCHANGERs, - GAS_PHASEs, KINETICS, SOLID_SOLUTIONs, SURFACEs, REACTIONs, - REACTION_TEMPERATUREs, and MIXes. - - - -------- - svn 3730 - -------- - - Added keyword RUN_CELLS. - - RUN_CELLS - -cells 1 2 - 5-6 - 7 - -time_step 10000 - -start_time 100 - - - For each i listed in -cells - it is the equivalent of the following: - - USE solution i - USE equilibrium_phases i - USE exchange i - USE surface i - USE solid_solution i - USE gas_phase i - USE kinetics i - USE reaction i - USE reaction_temperature i - SAVE solution i - SAVE equilibrium_phases i - SAVE exchange i - SAVE surface i - SAVE solid_solution i - SAVE gas_phase i - - If MIX i is defined, it is used in place of USE solution i. - A MIX i or SOLUTION i must be defined to use RUN_CELLS; -cells i. - All other entities are used only if they are defined. - - -start_time and -time_step are needed if any kinetic reactions - are calculated. -start_time is the time at the start of the - calculation, and -time_step is the length of time over which - to integrate the kinetic reactions. - - -------- - svn 3727 - -------- - Added keywords to allow modification of each reactant. - A reactant must have been defined previously, but then - each data item of the reactant can be changed and new - components added. Data items read are changed, all - other data items remain the same. Input format is the - same as the RAW formats produced by DUMP. - - - New keywords are as follows: - - SOLUTION_MODIFY - EQUILIBRIUM_PHASES_MODIFY - EXCHANGE_MODIFY - SURFACE_MODIFY - SOLID_SOLUTIONS_MODIFY - GAS_PHASE_MODIFY - KINETICS_MODIFY - - The example below is indented to indicate which - information is necessary to change a data item. - Working back through the indention levels for - and item, each heading of a lower order is - necessary to define the data item. In the example - below, to change the number of moles of barite from - 10 to 5 in the equilibrium phase assemblage, it - is necessary to define EQUILIBRIUM_PHASES_MODIFY 1; - -component; -name Barite; -moles 5. - - Items identified by an asterisk are most likely to - consider for redefinition. Items with (*) are - marked to indicate that care is needed to maintain - charge balance relations. Unwanted redox and pH - reactions may result from incorrect redefinition - of these quantities. Items not marked are either - initial estimates of variables calculated in the - simulation, or are parameters thought not likely - to be changed. - - The MODIFY data blocks change the data in the - PHREEQC storage structures. They do not cause - any initial composition calculations. Neither - do they generate default reactions to be simulated. - USE statements are needed to specify explicitly - the desired reactions. - - -SOLUTION_MODIFY 1 - -temp 25 * - -total_h 111.01243359981 (*) - -total_o 55.506216800086 (*) - -cb -3.6579285790756e-010 (*) - -totals - Cl 0.0010000000000003 (*) - H(0) 1.4155655514601e-025 (*) - Na 0.0010000000000003 (*) - -Isotopes - -pH 7 - -pe 4 - -mu 0.0010001035690258 - -ah2o 0.99996599647757 - -mass_water 1 - -total_alkalinity 3.6579283856577e-010 - -activities - Cl -3.0155266404974 - E -4 - H(0) -25.15 - Na -3.0153891985103 - O(0) -42.080029535586 - -gammas -EQUILIBRIUM_PHASES_MODIFY 1 - -eltList - Ba 1 - O 4 - S 1 - -component * - -name Barite - -si 0 * - -moles 10 * - -delta 0 - -initial_moles 0 - -force_equality 0 - -dissolve_only 0 - -precipitate_only 0 -EXCHANGE_MODIFY 1 - -pitzer_exchange_gammas 1 - -component - -formula X - -totals - Na 1.0000000058717 (*) - X 1.0000000058717 (*) - -charge_balance 0 - -moles 0 - -la 3.0000000302372 - -phase_proportion 0 - -formula_z 0 - -formula_totals - X 1 -SURFACE_MODIFY 1 . - -type 2 - -dl_type 0 - -sites_units 0 - -only_counter_ions 0 - -thickness 1e-008 - -debye_lengths 0 - -DDL_viscosity 1 - -DDL_limit 0.8 - -transport 0 - -component - -formula Hfo_s - -formula_z 0 - -moles 0 - -la -0.11486188676541 - -charge_balance 3.7853465372651e-005 - -phase_proportion 0 - -Dw 0 - -formula_totals - Hfo_s 0.01 - -totals - H 0.01003785346547 (*) - Hfo_s 0.010000000000097 (*) - O 0.010000000000097 (*) - -charge_component - -name Hfo - -specific_area 600 - -grams 1 - -charge_balance 3.7853465372651e-005 (*) - -mass_water 0 - -la_psi 0.55146269389617 - -la_psi1 0 - -la_psi2 0 - -capacitance0 1 - -capacitance1 5 - -diffuse_layer_totals -SOLID_SOLUTIONS_MODIFY 1 - -solid_solution - -name Calcite - -a0 0 - -a1 0 - -ag0 0 - -ag1 0 - -miscibility 0 - -xb1 0.0 - -xb2 0.0 - -component - calcite 0.1 * - siderite 0.001 * -GAS_PHASE_MODIFY 1 - -type 0 - -total_p 1 - -volume 1 - -component - CO2(g) 1.4305508698401e-005 * -KINETICS_MODIFY 1 - -step_divide 1 - -rk 1 - -bad_step_max 500 - -use_cvode 0 - -cvode_steps 100 - -cvode_order 5 - -component - -rate_name Calcite - -tol 1e-008 - -m 0.9999999999991 * - -m0 1 - -moles 8.9805940461929e-013 - -namecoef - CaCO3 1 - -d_params - 1 1 1 1 * - -totals - C 8.9801193858101e-013 - Ca 8.9801193858101e-013 - O 2.694035815743e-012 - -steps - - -------- - svn 3719 - -------- - Added DELETE keyword to delete any numbered reactant, as - listed in the example below. A list of single numbers and - number ranges are used to define the reactants to delete - from PHREEQC memory. Lists may continue on subsequent - lines. Deletion occurs as the last step of simulation - calculations, after all other calculations (initial - compositions, reactions, transport, inverse modeling) and - COPYing have occurred. - - - DELETE - -solution 2 3 - -equilibrium_phases 2-3 - -exchange 2 - 3 - -surface - 2-3 - -solid_solution - 2 3 - -gas_phase 2-3 - -kinetics 3 2 - -mix 2 - -mix 3 - -reaction 2-3 - -temperature - 2 - 3 - -------- - svn 3704 - -------- - Added DUMP keyword. Writes complete data for solution, - equilibrium_phases, exchange, surface, solid solution, - gas phase, and kinetics classes. The format of the - output is suitable for data input to the C++ version - of PHREEQC. This feature allows the chemical state - of a simulation to be saved and read back in as - initial conditions for subsequent model runs. - - Examples: - DUMP - -all - -file myfile.dmp - END - DUMP - -file myfile.dmp - -append true - -solution 1-2 3 - -equi 3 1-2 - -exch 1 2 3 - -surf 1 - 2 - 3 - - -s_s 1 - 2-3 - -gas 1 - -gas 2 - -gas 3 - -kin 1-3 - END - - Explanation: - The first DUMP datablock will write the compositions at - the end of the simulation (after all simulation calculations, - TRANSPORTs, SAVEs, and COPYs are complete) for - every solution, equilibrium_phases, exchange, surface, - solid solution, gas phase, and kinetics entities that have - been defined or produced in the run. This write includes - internally saved entities (usually assigned negative numbers). - - The second DUMP data appends the compositions of items - numbered 1-3 to myfile.dmp, if they exist. The second example - shows multiple ways to define the entities to be dumped to - file. - - ------ - Begin - ------ - PHREEQC++ has classes that are equivalent to the PHREEQC C - structures. Each class has a method to "dump_raw" the - entire set of class data. The lines generated by dump_raw - can be read as keyword data blocks in an input file. The following - keywords are available in PHREEQC++: SOLUTION_RAW, - EQUILIBRIUM_PHASES_RAW, EXCHANGE_RAW, SURFACE_RAW, - SOLID_SOLUTIONS_RAW, GAS_PHASE_RAW, and KINETICS_RAW. - PHAST uses these classes and data blocks to dump the chemical - state of a simulation and read it back in as a starting - point for subsequent simulations. - - Examples of raw output are given below. Some of the fields - are required and some are not. - - SOLUTION_RAW 1 - -temp 25 - -pH 7 - -pe 4 - -mu 0.0010001035690258 - -ah2o 0.99996599647757 - -total_h 111.01243359981 - -total_o 55.506216800086 - -cb -3.6579285790756e-010 - -mass_water 1 - -total_alkalinity 3.6579283856577e-010 - -totals - Cl 0.0010000000000003 - H(0) 1.4155655514601e-025 - Na 0.0010000000000003 - -activities - Cl -3.0155266404974 - E -4 - H(0) -25.15 - Na -3.0153891985103 - O(0) -42.080029535586 - -gammas - -Isotopes - EQUILIBRIUM_PHASES_RAW 1 - -eltList - Ba 1 - O 4 - S 1 - -component - -name Barite - -si 0 - -moles 10 - -delta 0 - -initial_moles 0 - -force_equality 0 - -dissolve_only 0 - -precipitate_only 0 - EXCHANGE_RAW 1 Exchange assemblage after simulation 3. - -pitzer_exchange_gammas 1 - -component - -formula X - -moles 0 - -la 3.0000000302372 - -charge_balance 0 - -phase_proportion 0 - -formula_z 0 - -totals - Na 1.0000000058717 - X 1.0000000058717 - -formula_totals - X 1 - SURFACE_RAW 1 Surface assemblage after simulation 4. - -type 2 - -dl_type 0 - -sites_units 0 - -only_counter_ions 0 - -thickness 1e-008 - -debye_lengths 0 - -DDL_viscosity 1 - -DDL_limit 0.8 - -transport 0 - -component - -formula Hfo_s - -formula_z 0 - -moles 0 - -la -0.11486188676541 - -charge_balance 3.7853465372651e-005 - -phase_proportion 0 - -Dw 0 - -formula_totals - Hfo_s 0.01 - -totals - H 0.01003785346547 - Hfo_s 0.010000000000097 - O 0.010000000000097 - -charge_component - -name Hfo - -specific_area 600 - -grams 1 - -charge_balance 3.7853465372651e-005 - -mass_water 0 - -la_psi 0.55146269389617 - -la_psi1 0 - -la_psi2 0 - -capacitance0 1 - -capacitance1 5 - -diffuse_layer_totals - SOLID_SOLUTIONS_RAW 1 - -solid_solution - -name Calcite - -a0 0 - -a1 0 - -ag0 0 - -ag1 0 - -miscibility 0 - -xb1 -6.2774385622042e+066 - -xb2 -6.2774385622042e+066 - -component - calcite 0.1 - siderite 0.001 - GAS_PHASE_RAW 1 - -type 0 - -total_p 1 - -volume 1 - -component - CO2(g) 1.4305508698401e-005 - KINETICS_RAW 1 - -step_divide 1 - -rk 3 - -bad_step_max 500 - -use_cvode 0 - -cvode_steps 100 - -cvode_order 5 - -component - -rate_name Calcite - -tol 1e-008 - -m 1 - -m0 1 - -moles 0 - -namecoef - CaCO3 1 - -d_params - 1 1 1 1 - -totals - -steps - - - - diff --git a/Phreeqc.h b/Phreeqc.h index 4e646f93..281efe24 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1521,11 +1521,11 @@ protected: #if defined MULTICHART ChartHandler chart_handler; public: - ChartHandler& Get_ChartHandler(void) + ChartHandler& Get_chart_handler(void) { return chart_handler; } - const ChartHandler& Get_ChartHandler(void)const + const ChartHandler& Get_chart_handler(void)const { return chart_handler; } diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 223532ac..3c7e030d 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -84,6 +84,7 @@ namespace zdg_ui2 { chart->Set_done(true); System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); } + phreeqc_ptr->Get_chart_handler().Decrement_active_charts(); this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; } @@ -1082,25 +1083,29 @@ namespace zdg_ui2 { zg1->AxisChange(); zg1->Refresh(); } - for (size_t j = 0; j < chart->Get_CurvesCSV().size(); j++) - { - if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_CurvesCSV()[j]->Get_x().size()) - { - fprintf(stderr, "graph points = %d\n", zg1->GraphPane->CurveList[j]->Points->Count); - fprintf(stderr, "phreeqc points = %d\n", chart->Get_CurvesCSV()[j]->Get_x().size()); - } - assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_CurvesCSV()[j]->Get_x().size()); - } - for (int j = chart->Get_CurvesCSV().size(); j < zg1->GraphPane->CurveList->Count; j++) - { - int k = j - chart->Get_CurvesCSV().size(); - if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_Curves()[k]->Get_x().size()) - { - fprintf(stderr, "graph points = %d\n", zg1->GraphPane->CurveList[j]->Points->Count); - fprintf(stderr, "phreeqc points = %d\n", chart->Get_Curves()[k]->Get_x().size()); - } - assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_Curves()[k]->Get_x().size()); - } + // + // Following asserts may not be true for Log scales + // negative values are rejected, so chart may have fewer points than phreeqc + // + //for (size_t j = 0; j < chart->Get_CurvesCSV().size(); j++) + //{ + // if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_CurvesCSV()[j]->Get_x().size()) + // { + // fprintf(stderr, "graph points = %d\n", zg1->GraphPane->CurveList[j]->Points->Count); + // fprintf(stderr, "phreeqc points = %d\n", chart->Get_CurvesCSV()[j]->Get_x().size()); + // } + // assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_CurvesCSV()[j]->Get_x().size()); + //} + //for (int j = chart->Get_CurvesCSV().size(); j < zg1->GraphPane->CurveList->Count; j++) + //{ + // int k = j - chart->Get_CurvesCSV().size(); + // if (zg1->GraphPane->CurveList[j]->Points->Count != chart->Get_Curves()[k]->Get_x().size()) + // { + // fprintf(stderr, "%d %d graph points = %d\n", j, k, zg1->GraphPane->CurveList[j]->Points->Count); + // fprintf(stderr, "phreeqc points = %d\n", chart->Get_Curves()[k]->Get_x().size()); + // } + // assert(zg1->GraphPane->CurveList[j]->Points->Count == chart->Get_Curves()[k]->Get_x().size()); + //} chart->Set_point_added(false); if (chart->Get_end_timer()) { @@ -1118,7 +1123,7 @@ namespace zdg_ui2 { int n = System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); assert(n == 3); - this->phreeqc_ptr = NULL; + //this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; if (batch >= 0) { diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 5259fc40..87d0f277 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -3340,6 +3340,7 @@ punch_user_graph(void) if (chart->Get_FirstCallToUSER_GRAPH()) { chart->start_chart(); + chart_handler.Increment_active_charts(); } chart->Set_new_ug(false); diff --git a/phreeqc/revisions b/phreeqc/revisions deleted file mode 100644 index 88fd31db..00000000 --- a/phreeqc/revisions +++ /dev/null @@ -1,3102 +0,0 @@ -File contains: - "Features not documented in WRIR 99-4295" - "Revisions and Bug Fixes" - -************************************************************ -************************************************************ -* Features not documented in WRIR 99-4259. * -************************************************************ -************************************************************ ------------------------------------------------------------- -Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------- - - -------- - svn 5556 - -------- - If -high_precision is set to true in SELECTED_OUTPUT, - convergence tolerance is set to 1e-12. If - -high_precision is set to false, convergence tolerance - is not changed. KNOBS; -convergence_tolerance sets the - convergence tolerance to a specified number. The last - definition (-high_precision true or - -convergence_tolerance) takes precedence for a - calculation. - ------------------------------------------------------------- -Version 2.18.0: April 9, 2011 ------------------------------------------------------------- - -------- - svn 5212 - -------- - Added gfm (gram formula mass) as a synonym to gfw in - reading concentration data for SOLUTION. - - S(6) 1 gfm 96 - - is equivalent to - - S(6) 1 gfw 96. - - -------- - svn 5170 - -------- - Added ceil and floor Basic functions. Ceil(x) is the - smallest integer greater than or equal to x. Floor(x) - is the largest integer less than or equal to x. Note - that all numbers in Basic are of type double in C. - - USER_PRINT - 10 print ceil(2.8), floor(2.8), ceil(-2.8), floor(-2.8) - - This USER_PRINT Basic program has the following output: - - 3 2 -2 -3 - - - -------- - svn 4988 - -------- - Added EOL$ Basic function. EOL$ is the end of line - character for whatever operating system you are - running. - - USER_PRINT - 10 PRINT "line 1"+EOL$+"line 2"+EOL$ - - The result of this USER_PRINT is - - line 1 - line 2 - - -------- - svn 4942 - -------- - Added additional parameter in PRINT for status. Writing - the status line to the screen can slow calculations - substantially under some conditions. - - PRINT - -status (t|f|n) - - t--Print status line. - f--Do not print status line. - n--Print status line every n milliseconds. - - -status 1000 would print the status line every - second. - - -------- - svn 4830 - -------- - Changed default for exchange species activty - coefficients to be equal to the Pitzer - aqueous activity coefficients when using Pitzer - aqueous model. Default is - -pitzer_exchange_gammas true. - - ------------------------------------------------------------- -Version 2.17.5: September 7, 2010 ------------------------------------------------------------- - ------------------------------------------------------------- -Version 2.17.4: September 2, 2010 ------------------------------------------------------------- - - -------- - svn 4771 - -------- - Added synonyms to TOTMOLE: TOTMOL, TOTMOLES - ------------------------------------------------------------- -Version 2.17.3: August 12, 2010 ------------------------------------------------------------- - - -------- - svn 4191 - -------- - Added new Basic functions: - - 10 total_Ca_in_moles = TOTMOLE("Ca") - - TOTMOLE provides the total number of moles of an element - or element valence state in solution. Special values are - "water", which gives number of moles of water, and - "charge", which gives total equivalents of charge - imbalance in solution (same as Basic function - CHARGE_BALANCE). In contrast, the Basic function TOT - returns moles per kilogram of water, or equivalents per - kilogram of water for TOT("charge"). - - 10 O18_permil = ISO("[18O]") - - - ISO gives an isotopic composition in the input units for - an isotope--permil, pmc, or TU in current version of - iso.dat. The string argument can be an isotope name, or - any item defined in the ISOTOPE_RATIOS data block, For - example, ISO("R(13C)_Calcite") will return the carbon-13 - composition of the calcite solid solution in permil - because of the definitions in iso.dat. - - 10 D_units$ = ISO_UNITS("D") - - ISO_UNITS gives the input units for the isotope, D_units$ = - "permil" in the example. The string argument can be an - isotope name or an item defined in the ISOTOPE_RATIOS data - block as explained for the Basic function ISO. - ------------------------------------------------------------- -Version 2.17.0: February 25, 2010 ------------------------------------------------------------- - - -------- - svn 4006 - -------- - - Changed the calculation of Specific Conductance (SC, uS/cm) - to be for the actual temperature of the SOLUTION (in output - and in BASIC function SC). - Previous versions calculated SC for 25 oC, whereas the - complexation model is done at the actual temperature. - To obtain SC at 25 oC, use keyword REACTION_TEMPERATURE, - for example: - - SOLUTION 1; K 1; Cl 1; -temp 99 - REACTION_TEMPERATURE; 25 - END - - The following example prints to the selected output - file the equivalent conductance in (mmho/cm / eq/L) at - 20 degrees C for a 1:1 chloride salt solution: - - USER_PUNCH - -head conc eq_EC_20 - -start - 10 punch tot("Cl"), SC / tot("Cl") * 1e-3 - -end - - where 1e-3 converts from microSiemens/cm to mmho/cm. - (The example given with svn 2448 multiplies SC's incorrectly - with the ratio of the temperatures.) - -------- - svn 3986 - -------- - Added an option for time-substepping in multicomponent - diffusion (-multi_D true), keyword TRANSPORT: - - -time_step 3600 3.0 # 3 time-substeps of 1200 seconds - - This option is useful to avoid a warning about negative - concentrations that may occur in MCD simulations. - - -------- - svn 3902 - -------- - Added four basic functions for use only with PHAST. The - functions are related to the volume, porosity, and - water saturation of a PHAST finite-difference cell: - - CELL_VOLUME--The total volume of the cell in liters. - CELL_PORE_VOLUME--The void volume of the cell in liters. - CELL_SATURATION--The fraction of the void volume filled - with water, unitless. - CELL_POROSITY--The porosity of the cell, equal to - CELL_PORE_VOLUME / CELL_VOLUME, unitless. - - - For example, in a USER_PUNCH program for a PHAST run, - the number of moles of dissolved chloride in a cell is - TOT("Cl")*CELL_PORE_VOLUME for confined flow simulations. - More generally, the number of moles of dissolved chloride - is TOT("Cl")*CELL_SATURATION*CELL_PORE_VOLUME, for confined - or unconfined flow. - - For solids, the number of moles of calcite in the - saturated part of a cell is - EQUI("Calcite")*CELL_SATURATION*CELL_PORE_VOLUME. For - unconfined flow, the solid reactants are distributed - between the saturated and unsaturated part of a water- - table cell. It is a limitation of PHAST that it is not - possible to determine the amounts of solid reactants - in the unsaturated part of a cell. Note that for - steady-state, unconfined flow, the saturation of cells is - constant and the unsaturated part of a water-table cell - is never part of the active domain. - - -------- - svn 3600 - -------- - A new 1/T^2 term (A5 coefficient) was added for all Pitzer-parameter - temperature expressions. - - P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + - A4*(TK*TK - TR*TR) + A5*(1/(TK*TK) - 1/(TR*TR)) - - where TK is temperature in Kelvin. The optional A5 parameter - is read following A4. - - -------- - svn 3591 - -------- - Added T^2 term to analytical expressions for log k. A T^2 term - can now be used in the analytical expressions for any log K. - The analytical expression is as follows: - - log10(K) = A1 + A2*TK + A3/TK + A4*log10(TK) + A5/TK^2 + A6*TK^2, - - where TK is in Kelvin. The A6 term is the new addition. The optional - A6 parameter is read following A5. - - -------- - svn 3485 - -------- - Added the active fraction model for calculating exchanger - compositions described by Appelo (1994), Water Resour. Res. 30, - 2793-2805. The active fraction model is useful for calculating - the decrease of selectivity when concentrations increase (more - specific sites being filled first). In the active fraction model, - log(K) of an exchange-half reaction depends on the equivalent - fraction on the exchanger: - - log(K) = log_k + a_f * (1 - ß_i) - - where log_k is the log of the equilibrium constant when all the - sites are occupied by ion i, - a_f is an empirical coefficient, and - ß_i is the equivalent fraction of i. - - a_f can be defined in EXCHANGE_SPECIES with -gamma after the WATEQ - Debye-Hueckel parameters. - Example: - - EXCHANGE_SPECIES - Na+ + X- = NaX; log_k -0.5 - -gamma 4.0 0.075 0.50 - - The association constant for NaX becomes: - log(K) = -0.5 + 0.50 * (1 - ß_Na) - - -------- - svn 3453 - -------- - Added Specific ion Interaction Theory (SIT) activity coefficient - model as described in Grenthe, Ingmar, Plyasunov, A.V., and - Spahiu, Kastriot, 1997, Estimations of medium effects on - thermodynamic data, in Modelling in Aquatic Chemistry, - Grenthe, Ingmar, and Puigdomenech, Inasi, eds, OECD - Publications, ISBN 92-64-15569-4, 724 p. - - Implementation is similar to the PITZER implementation, a - database with the SIT keyword invokes the SIT activity - coefficient model. Currently, No database is provided. - - The SIT keyword has two identifiers, - -epsilon and -epsilon1, where -epsilon gives the pairwise - interaction parameters and -epsilon1 gives the linear ionic - strength dependency of epsilon, if available. Both parameters - allow for temperature dependence with the same expression used - in PITZER. The five-term expression for temperature dependence is - as follows: - - P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + - A4*(TK*TK - TR*TR), - - where TK is Kelvin and TR is 298.15. - - Example: - SIT - -epsilon - Na+ Br- 0.05 # 0.01 - Na+ Cl- 0.03 # 0.01 - - -epsilon1 # not currently used - - - -------- - svn 3288 - -------- - - Additional arguments for the EDL function for the CD_MUSIC - surface complexation model. The values of charge, sigma, and psi - for the 0, 1, and 2 planes can be obtained from the EDL function. - - EDL("element", "surface") gives the amount of - element in the diffuse layer for "surface". - not including sorbed species. "surface" should - be the surface name, not the surface-site name - (that is, no underscore). - - Special values for "element" include: - "charge" - surface charge, equivalents. - For CD_MUSIC "charge" refers to plane 0. - "charge1"- surface charge on plane 1, equivalents - (CD_MUSIC only). - "charge2"- surface charge on plane 2, equivalents - (CD_MUSIC only). - "sigma" - surface charge density, C/m**2. - For CD_MUSIC "sigma" refers to plane 0. - "sigma1" - surface charge density on plane 1, - equivalents (CD_MUSIC only). - "sigma2" - surface charge density on plane 2, - equivalents (CD_MUSIC only). - "psi" - potential at the surface, Volts. - For CD_MUSIC "psi" refers to plane 0. - "psi1" - surface charge density on plane 1, - equivalents (CD_MUSIC only). - "psi2" - surface charge density on plane 2, - equivalents (CD_MUSIC only). - "water" - mass of water in the diffuse layer, kg. - -------- - svn 3189 - -------- - Density of solutions is now calculated from the concentrations - of dissolved species. The algorithm has been described by Millero - (1974), Millero (2000), Millero (2001) and has been used - successfully by Millero and Lepple (1973), Millero et al (1976), - Fernendez et al. (1982) and Millero (2000) to calculate the - density of seawater, estuaries, lagoons and lakes. - - The calculation relies on apparent molar volumes phi(i), - for individual aqueous species according to the following formula: - - phi(i) = phi(i,inf) + s(t)I^0.5 + beta(i)I - - where phi(i,inf) is the apparent molar volume of species i at - infinite dilution, s(t) is the Debije-Huckel limiting slope, beta(i) - is an empirical constant, and I is the ionic strength. - - s(t) is calculated as a function of temperature. Parameterizations of - phi(i,inf) and beta(i) use the following formulas: - - phi(i,inf) = a + bt +ct^2 - beta(i) = d + et + ft^2 - - where a, b, c, d, e, and f are empirical constants and t in Celcius. - Data input of the constants are in the keyword data block SOLUTION_SPECIES - using the new identifier -millero. - - Example: - - SOLUTION_SPECIES - Na+ = Na+ - log k 0.0 - -gamma 4.0 0.075 - -dw 1.33e-9 - -millero -3.46 0.1092 -0.000768 2.698 -0.106 0.001651 - - Apparent molar volume parameters have been included in the database - phreeqd.dat. Calculations made with this database will include - the calculated density in the "Description of solution". - - A new basic function, RHO, can be used to obtain the density in - USER_PRINT, USER_PUNCH, and RATES data blocks. - - Example: - - USER_PUNCH - -heading density - 10 PUNCH RHO - - -------- - svn 3183 - -------- - Added option for an equilibrium-phase to precipitate only, - parallel to dissolve_only option. - "pre" is added at the end of a line defining an equilibrium- - phase. No data fields may be omitted. Should not - be used when adding an alternative reaction. - Example: - EQUILIBRIUM_PHASES - Dolomite 0 0.1 dissolve_only - Quartz 0 1.5 precipitate_only - - -------- - svn 3160 - -------- - - Surface charge must be higher than -3000 equivalents, - when the diffuse double layer composition is - calculated with option -donnan. - - -------- - svn 3149 - -------- - - Diffusion through DDL water is multiplied with c_DDL,i / c_i - with option -only_counter false. c_DDL,i is the concentration in - DDL water, c_i is the concentration in free porewater. (Previous - versions used a multiplier of 1). - - Added -erm_ddl as parameter for aqueous species, to be defined - with keyword SOLUTION_SPECIES. erm_ddl (> 0) is an - enrichment factor in DDL water calculated with option -donnan: - c_DDL,i = c_i * Boltzmann_factor * erm_ddl - Example: - SOLUTION_SPECIES; Cs+ = Cs+; log_k 0; -erm_ddl 2.1 - Default: erm_ddl = 1.0. - - Added optional multicomponent diffusion of cations in interlayer - space of montmorillonite to keyword TRANSPORT. - In the example, - interlayer diffusion is true (default = false), - interlayer porosity is 0.09 (default = 0.1), - the porosity where interlayer diffusion stops is 0.01 - (default is 0), - the tortuosity factor is 150 (default = 100). - - TRANSPORT - -interlayer_D true 0.09 0.01 150 - - With interlayer_D true, also -multi_D true (and other - parameters) must be set, for example: - -multi_d true 1e-9 0.3 0.05 1.0 - Interlayer diffusion is calculated for the cations associated with X-, - defined with keyword EXCHANGE. - Mass_transfer = -A * (Dw' / t_f) * c_CEC * grad(beta) - A is surface area, A_porewater * (interlayer porosity / free - porewater porosity), - Dw' is the temperature corrected diffusion coefficient of the - aqueous species (defined in SOLUTION_SPECIES), - corrected to zero charge transfer, - t_f is the interlayer tortuosity factor (-), - c_CEC is concentration of total X-, mol(X-) / (L interlayer - water). L interlayer water = (L porewater + L DDL- - water) * (interlayer porosity / free porewater porosity), - grad(beta) is the gradient of the equivalent fraction. - - -------- - svn 2969 - -------- - Added basic functions that return the activity coefficient of - an aqueous species (gamma) and the log base 10 of the activity - coefficient of an aqueous species (lg). - - USER_PUNCH - -start - 10 punch gamma("H+") # activity coefficient - 20 punch lg("H+") # log base 10 activity coefficient - -end - - The functions return zero if the species is not defined for - the aqueous model or if the species is an exchange or surface - species. - ------------------------------------------------------------- -Version 2.15.0: February 5, 2008 ------------------------------------------------------------- - - -------- - svn 2680 - -------- - - Identifiers for paramaters controlling the integration by - CVODE have been added in the KINETICS data block. - - -bad_step_max bad_steps - -cvode_steps steps - -cvode_order order - - -bad_step_max bad_steps--This option was used only in the - Runge-Kutta method. Now, the value of this option is used for - CVODE as well. The value entered is the number of times that - PHREEQC will invoke CVODE to try to integrate a set of - rates over a time interval. Default is 500. - - -cvode_steps steps--The value given is the maximum number of - steps that will taken during one invocation of CVODE. - Default is 100. - - -cvode_order order--CVODE uses a specified number of terms in - an extrapolation of rates using the BFD method. Legal values - are 1 through 5. A smaller value (2) may be needed if the rate - equations are poorly behaved. The default is 5. - - -------- - svn 2457 - -------- - Added options to inverse modeling to translate current - solution definitions in PHREEQC to a Netpath .lon file and - (or) to .pat and model files. - - INVERSE_MODELING - -lon_netpath prefix - - At the beginning of the inverse modeling calculation, each - solution that has been defined (or saved) to PHREEQC, is - written to the file prefix.lon in a format readable by - DBXL (NetpathXL distribution). - - INVERSE_MODELING - -pat_netpath prefix - - A NETPATH model file is written for each inverse model that is - found. The model files are named prefix-n.mod, where n refers - to the sequence number of the model. In addition, a file named - prefix.pat is written that contains the solutions associated - with each model. The solutions are adjusted in accordance with - the deltas calculated for the inverse model. Thus, a solution - could be used for model 1 and model 2, but the concentrations - could be slightly different for the two models. The solutions - are identified by an initial integer corresponding to the - sequence number of the model, followed by the solution description. - - -------- - svn 2448 - -------- - Added calculation of specific conductance. Requires the - use of phreeqd.dat, which contains the diffusion coefficients - of aqueous species. If phreeqd.dat is used, the specific - conductance (uS/cm at 25 C) is printed in the - "Description of solution". - - The Basic function SC returns the value of the specific - conductance for the solution at 25 C. The following example - would print to the selected output file the equivalent conductance - in (mmho/cm / eq/L) at 20 degrees C for a 1:1 chloride salt - solution: - - USER_PUNCH - -head conc eq_EC_20 - -start - 10 punch tot("Cl"), SC / tot("Cl") / 1e3 * .89 * 298 / 293 - -end - - where 1e-3 converts from microSiemens/cm to mmho/cm, .89 - accounts for the viscosity at 20 C, and 298/293 - accounts for the temperature of 20 C. - ------------------------------------------------------------- -Version 2.14.3: November 17, 2007 ------------------------------------------------------------- - -------- - svn 2312 - -------- - Added new option to PITZER datablock, use_etheta t/f. - If true, the nonsymmetric mixing terms--cation/cation and - anion/anion of different charge--are included; if false - these terms are excluded from all equations. Default is true. - - PITZER - -use_etheta true - - - -------- - svn 2270 - -------- - Added additional parameters Pitzer activity formulation for - neutral species, MU and ETA. MU applies to nnn, nnn', nn'n'', - nna, nn'a, nnc, nn'c interactions, where n, n', and n'' are - neutral species, a is an anion and c is a cation. ETA applies - to ncc' and naa' interactions. Also modified LAMDA for the - special case of nn interactions (coefficients in osmotic and - ln equations are different than other interaction types). - Source of equations is Clegg and Whitfield, 1991, Activity - coefficients in natural waters, Chapter 6, in Pitzer, K.S. - (Ed.) Activity Coefficients in Electrolyte Solutions, 2nd - Ed. CRC Press, Boca Raton. Removal of the 6 coefficient in - last two terms of eq 35 and 36 (p. 2404) per Cleg and - Whitfield, 1995, Geochimica et Cosmochemica Acta, v. 59, - no. 12, pp 2403-2421. Order of species in definitions should - not matter. - - PITZER - -MU - CO2 CO2 CO2 ? # nnn - CO2 CO2 NH3 ? # nnn' - CO2 B(OH)3 NH3 ? # nn'n'' - CO2 CO2 Ca+2 ? # nnc - CO2 CO2 Cl- ? # nna - CO2 NH3 Ca+2 ? # nn'c - CO2 NH3 Cl- ? # nn'a - -ETA - CO2 Ca+2 Mg+2 ? # ncc' - CO2 Cl- SO4-2 ? # naa' - - As with all other Pitzer parameters, a five-term expression - for temperature dependence is available: - - P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + - A4*(TK*TK - TR*TR), - - where TK is Kelvin and TR is 298.15. A0 through A4 are - defined in order. Any undefined values are assumed to - be zero. - - -MU - CO2 CO2 CO2 ? ? ? ? ? # nnn - ------------------------------------------------------------- -Version 2.14.2: September 17, 2007 ------------------------------------------------------------- - - Fixed logic of memory checking for PhreeqcI. This serious - bug makes versions 2.14.0 and 2.14.1 unusable. - ------------------------------------------------------------- -Version 2.14.1: September 5, 2007 ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.14.0: August 30, 2007 ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.13.3: February 15, 2007 ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.13.2: February 1, 2007 ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.13.1: January 16, 2007 ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.13.0: November 3, 2006 ------------------------------------------------------------- - - -------- - svn 1368 - -------- -(1) Added multicomponent diffusion (MCD) to transport - capabilities. MCD allows different tracer diffusion - coefficients for species, but calculates charge balanced - transport. In the example, MCD is specified to be true, - default tracer diffusion coefficient for species (Dw) is 1e-9, - porosity is set to 0.3, porosity limit is set to 0.05, and an - exponent of porosity (n) is set to 1.0. Effective diffusion - coefficient is defined by the equation: De = Dw * porosity^n. - Diffusion stops when the porosity falls below the porosity - limit. - - TRANSPORT - -multi_d true 1e-9 0.3 0.05 1.0 - - Added tracer diffusion coefficient to SOLUTION_SPECIES - definitions, -dw identifier. - - SOLUTION_SPECIES - H+ = H+ - log_k 0.0 - -gamma 9.0 0.0 - -dw 9.31e-9 - -(2) Added phreeqd.dat database with diffusion coefficients (-dw) - defined for aqueous species in database directory. - -(3) Added BASIC functions to obtain and modify the porosity - in a cell. The functions can be used in BASIC programs - defined with keyword RATES, USER_PRINT, USER_PUNCH and - USER_GRAPH. - - get_por(cell_no) # returns the porosity in cell - # 'cell_no' - - change_por(0.21, cell_no) # porosity of cell 'cell_no' - # becomes 0.21 - -(4) Mobile surface and Donnan option in SURFACE. Mobile surfaces - are meant for modeling transport of colloids. Only surfaces with - a diffuse double layer can be transported (the ensemble must be - electrically neutral). Surfaces related to equilibrium-phases - and kinetics cannot be transported. - - Example 1: Use donnan assumption to calculate the explicit - composition of the diffuse layer of surfaces. Thickness of the - diffuse layer is defined to be 1e-7 meters. (Default thickness - is 1e-8 meters.) Hfo (both sites Hfo_w and Hfo_s) is a surface - that is transported with advection and dispersion. The diffusion - coefficient of 1e-13 m^2/s is used with option -multi_d true in - TRANSPORT. Sfo is an immobile surface (Dw = 0). - - SURFACE - -donnan 1e-7 - Hfo_w 97.5e-5 600 88e-3 Dw 1e-13 - Hfo_s 2.5e-5 - Sfo_w 97.5e-5 600 88e-3 Dw 0 - Sfo_s 2.5e-5 - - - Example 2: Define Donnan calculation information. Thickness - of the diffuse layer is 1e-8 meters, and relative viscosity is - 0.5. Relative viscosity only applies to multicomponent diffusion - of solutes in the diffuse layer. (Default viscosity is 1.0.) - - SURFACE - -donnan 1e-8 viscosity 0.5 - - Example 3: Define Donnan calculation information. Thickness - of the diffuse layer is 1.5 Debye lengths, maximum fraction of - water that can be in the diffuse layer is 0.9. (Default - thickness in Debye lengths is 1, default limit is 0.8.) - - SURFACE - -donnan debye_lengths 1.5 limit_ddl 0.9 - - When option '-only_counter_ions' is used in conjunction with - with '-donnan', all the co-ions (with the same sign of charge as - the surface) will be excluded from the DDL, and will be given a - concentration of (near) zero in the DDL. - -(5) Added special BASIC function to change the diffusion - coefficient of (part of) a SURFACE, and hence to change the - status from mobile to immobile or immobile to mobile. - - Example 1: take a fraction 0.2 of 'Hfo', rename it to - 'Sorbedhfo', with a diffusion coefficient of 0, in cell 'cell_no' - - USER_PRINT - 10 print 'Changing surface in cell ', cell_no - 20 change_surf("Hfo", 0.2, "Sorbedhfo", 0, cell_no) - - - Example 2: change the diffusion coefficient of 'Hfo' to 1e-12 - m2/s in cell 'cell_no' - - 10 change_surf("Hfo", 1, "Hfo", 1e-12, cell_no) - - This function can be used in BASIC programs defined with keywords - RATES, USER_PRINT, USER_PUNCH and USER_GRAPH. For correct - operation of 'change_surf', the surface components must have - been defined with the same surface species (the association - constants may differ) and the same diffuse layer thickness or - Debye length. The surfaces will be adapted at the end of a - calculation step. The result of change_surf does not show up in - print or punch results of that step, but the reformatting is - effective in the next timestep calculations. - - - -------- - svn 1337 - -------- - Added -add_logk to NAMED_EXPRESSIONS keyword. - - NAMED_EXPRESSIONS - Log_alpha_14C_CO3-2/CO2(aq) - -add_logk Log_alpha_14C_CO3-2/CO2(g) 1 - -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 - - -------- - svn 1281 - -------- - Added new option to PITZER data block to allow definition of - alpha1 and alpha2 for specific electrolytes. Entries are - following -ALPHAS are Ion1, Ion2, alpha1, alpha2. Both - alpha1 and alpha2 should be defined. Default is 0.0 for - undefined values following Ion1 and Ion2. - - Example: - - PITZER - -ALPHAS - # - # Defaults for ion valences in salts - # - # 1-N (only B1): alpha1 = 2 - # 2-2: alpha1 = 1.4 alpha2 = 12.0 - # 3-2, 4-2: alpha1 = 2 alpha2 = 50 - # - #Ion1 Ion2 Alpha1 Alpha2 - Fe+2 Cl- 2 1 - Fe+2 SO4-2 1.559 5.268 - - -------- - svn 1279 - -------- - Added new Basic function OSMOTIC that returns the - osmotic coefficient if the Pitzer model (PITZER keyword data - block) is used or 0.0 if the ion-association model is used. - - Example: - - USER_PRINT - 10 PRINT "Osmotic coefficient: ", OSMOTIC - - - -------- - svn 1245 - -------- - Enabled redox in Pitzer model with option in - PITZER keyword. Typically, the option will be included - in the pitzer database file. - - Example: - - PITZER - -redox TRUE - - The default database for the Pitzer model does not contain - any redox definitions and the default value for the option - is FALSE. At a minimum, species O2 and H2 must be defined - in the database or input file to allow redox calculations. - - -------- - svn 1207 - -------- - Added option to force an equilibrium phase to be - included in the equality constraints. Normally, the SIs of - equilibrium phases are optimized to be negative and the - sum of SIs is minimized. If -force_equality is used, then - the phase must reach its target SI or the calculation fails - with an error. - - Example: - - EQUILIBRIUM_PHASES - Fix_pH -7 NaOH - -force_equality - Calcite 0 - Dolomite 0 - CO2 -3.5 - - One example of using the new option would be to ensure that - a target pH is attained, as in the example above. - - -------- - svn 1179 - -------- - New option (-sites_units or -sites) allows alternative - units (sites/nm^2) for definition of number of sites for a - surface. This approach requires better consistency among the - parameters as both the number of sites and the surface area - are based on the mass. It makes more sense than the default, - which requires the number of sites (first numeric item in a - line) to be defined in units of moles, independently of the - number of grams of sorbent. Units descriptor is either DENSITY, - for defining number sites/nm^2, or ABSOLUTE, for defining - number of sites in moles. Optionally, sites, sites_units, or - -s[ites_units]. ABSOLUTE is the default for backward - compatibility with input files. - - Example: - - SURFACE 1 - -sites_units DENSITY - SurfOH 2.6 600. 1.0 - SurfaOH 2.6 30. 2.0 - - Explanation: - - In this example, Surf has a site density of 2.6 sites per - nanometer squared, a specific area of 600 meters squared per - gram, and a mass of 1 gram. Surfa has a site density of 2.6 - sites per nanometer squared, a specific area of 30 meters - squared per gram, and mass of 2 grams. - - - -------- - svn 1096 - -------- - - Allows solids and gases in the equations for PHASES. This - capability simplifies the definitions for gas and solid - isotopic components. Solids must be identified with "(s)" and - gases with "(g)". The first entity on the left- hand-side of - the equation must be the stoichiometric formula of the solid - or gas component being defined, optionally with (g) or (s). In - turn gases and solids included in the equation must be defined - with reactions that ultimately allow the defined species - (C[18O]2(g) in this case) in terms of aqueous species. - - Example: - - PHASES - C[18O]2(g) - C[18O]2(g) + CO2(g) = 2CO[18O](g) - log_k 0.602059991327962396 # log10(4) - - -------- - svn 1092 - -------- - CD_MUSIC sorption model has been implemented. - Still missing logic for surfaces related to equilibrium- - phases and kinetics. Has explicit calculation of diffuse - layer composition with Donnan assumption. Old diffuse-layer - calculation will not be implemented. - - Example: - - SURFACE - Goe_uniOH .000552 96.387 1 - -capacitance 1.1 5 - Goe_triO .000432 - -cd_music - -donnan - - Explanation: - - 1.1 5 are capacitances for the cd-music model for 0-1 and 1-2 - planes, respectively. - -cd_music specifies that the surface is a cd-music surface. - -donnan optionally calculates the diffuse layer composition - with the Donnan model. - - Example: - - SURFACE_SPECIES - Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O - log_k 20.1 # eq 7 K1, Kin1 - -cd_music -1 -6 0 0.25 5 - - Explanation: - - -cd_music--this option is used to specify the change in charge - by the reaction for three planes, 0 (specific sorption at the - surface), 1 (Stern layer), and 2 (or d, the diffuse layer). - The five numbers in the form above are (1) the change - in charge for plane 0 due to loss or gain of hydrogen and - oxygen at plane 0, (2) the change in charge for plane 1 due to - the hydrogen and oxygen in the ligand that are located at - plane 1, (3) the change in charge in diffuse layer, plane 2, - (4) the fraction of the central ion charge that is - associated with plane 0, and (5) the charge on the central - ion. - - In this example the change in charge at plane 0 is (delta z0) = - -1 (loss of one hydrogen) + 0.25*5 (contribution from As+5) = - 0.25. The charge at plane 0 becomes -0.5 + 0.25 = -0.25. - The change in charge at plane 1 is (delta z1) = -6 (3 oxygens of - the ligand are located at plane 1) + (1-0.25)*5 (contribution - from As+5) = -2.25. The charge at plane 1 becomes 0 + (-2.25) = - -2.25. There is no change in charge associated with plane 2. - The total charge of the species is -0.25 (plane 0) + -2.25 - (plane 1) + 0 (plane 2) = -2.5. - - Alternatively to the form above, the changes in charge - on the three planes can be entered directly as the first - three numbers in the option, followed by two zeros. Thus, the - following is equivalent to the -cd_music definition above, and - consistent with more recent papers which would list - delta z0 = 0.25, delta z1 = -2.25 and delta z2 = 0: - - SURFACE_SPECIES - Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O - log_k 20.1 # eq 7 K1, Kin1 - -cd_music 0.25 -2.25 0 0 0 - - -------- - svn 675: - -------- - Added PRINT option to print the species that contribute - to alkalinity. Alkalinity distribution is printed in - the output file following the distribution of species. - Default at program startup is false. - - Example: - - PRINT - -alkalinity true - ------------------------------------------------------------- -Version 2.12: ------------------------------------------------------------- - -* Made aqueous activity coefficients the default activity - coefficients for exchange species when using the - Pitzer formulation. New option in EXCHANGE is - -pitzer_exchange_gammas T/F, default is true; - defining "false" sets exchange activity coefficients - to 1.0. Option has no effect for ion-association - model (non-Pitzer). - - -* Added multiplier format to REACTION steps and KINETICS steps, - which simplifies definition of multiple equal reaction increments. - - This definition: - - INCREMENTAL_REACTIONS true - REACTION - H2O 1 - -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles - - is equivalent to this definition: - - INCREMENTAL_REACTIONS true - REACTION - H2O 1 - -36 -4 -4 -4 -.25 -.25 -0.19 -0.1 -0.1 -0.1 - -0.1 -0.05 -0.05 -0.05 moles - - - -* Added Pitzer activity formulation. Use pitzer.dat database - to invoke the Pitzer model. Should have same capabilities - as ion-association model except explicit diffuse layer - calculation is not implemented with the Pitzer model. - New keyword is PITZER with following options: - - PITZER - -MacInnes T/F # uses MacInnes assumption or unscaled for - # individual activities and activity coefficients - -B0 - Na+ Cl- 0.0765 -777.03 -4.4706 0.008946 -3.3158E-6 - -B1 - Na+ Cl- 0.2664 0 0 6.1608E-5 1.0715E-6 - -B2 - Mg+2 SO4-2 -37.23 0 0 -0.253 - -C0 - Na+ Cl- 0.00127 33.317 0.09421 -4.655E-5 - -THETA - K+ Na+ -0.012 - -LAMDA - Na+ CO2 0.1 - -ZETA - H+ Cl- B(OH)3 -0.0102 - -PSI - Na+ K+ Cl- -0.0018 - - A five-term expression for temperature dependence is available - for all Pitzer parameter values: - P = A0 + A1*(1/TK - 1/TR) + A2log(TK/TR) + A3*(TK-TR) + - A4*(TK*TK - TR*TR), - where TK is Kelvin and TR is 298.15. - -* Cl1mp is a new multiple precision version of routine cl1, - a simplex-based optimization routine. Cl1mp was develeped - by using the Gnu Multiple Precision package (gmp). - Calculations are carried out to about 30 significant - digits. Cl1mp may help in some situations where roundoff - errors are a problem, but it is still possible that roundoff - errors will cause cl1mp to fail to find a solution to an - optimization problem. The mp version has the following - options in INVERSE_MODELING: - - -multiple_precision T/F--causes the mp version - to be used in inverse modeling calculations. - -mp_tolerance 1e-12--tolerance for mp version of - cl1. As in cl1, numbers less than the - tolerance are considered to be zero. - 1e-12 is the default. - -censor_mp 1e-20--as calculations occur in the - linear equation array, elements less - than this value are set to zero. Default - is 1e-20. A value of 0.0 causes no - censoring to occur. - ------------------------------------------------------------- -Version 2.11: ------------------------------------------------------------- - -* A new database, minteq.v4.dat, has been translated from - version 4.02 of MINTEQA2 and is included in all - distributions. The database minteq.dat from earlier - version of MINTEQA2 has been slightly revised and is - also included. - ------------------------------------------------------------- -Version 2.10: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.9: ------------------------------------------------------------- -* Added new keyword COPY that allows a data entity - to be copied from one index to a new index - or to a range of indicies. Format is - - COPY keyword index index_start[-index_end] - - where keyword may be SOLUTION - EQUILIBRIUM_PHASES - EXCHANGE - GAS_PHASE - KINETICS - MIX - REACTION - REACTION_TEMPERATURE - SOLID_SOLUTION - SURFACE - -* Added new Basic functions - b$ = PAD(a$, 20) pads a$ to a total of 20 characters - with spaces and stores result in b$. PAD returns - a copy of a$ if a$ is more than 20 characters. - i = INSTR(a$, b$) sets i to the character position of - string b$ in a$, 0 in not found. - b$ = LTRIM(a$) trims white space from beginning of - string a$ and stores result in b$. - b$ = RTRIM(a$) trims white space from end of string - a$ and stores result in b$. - b$ = TRIM(a$) trims white space from beginning and - end of string a$ and stores result in b$. - - -* Added new Basic function SYS that calculates the - total amount of an element in all phases (solution, - equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase). KINETIC reactions are not included. - The function has two forms: (1) one element name as an - argument (variable names are user specified) - - 10 t = SYS("As") - - the function will return the total arsenic in the system. - (2) 5 argumens - - 10 t = SYS("As", count_species, names$, types$, moles) - - will return the total arsenic in the system to t; count_species-- - the number of species that contain arsenic, including - solution, equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase species; names$--a character array that has the - name of each species; type$--a character array that specifies the - type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. - Diff refers to the amount of the element in the diffuse layer of - a surface when the explicit diffuse layer calculation is used; - moles--an array containing the number of moles of the element in - the species. The sum of moles(i) is equal to tot. - - SYS has several special arguments for the form - SYS("arg", count, names$, types$, values) - arg is one of the options listed below. - count is a single numeric value and is the number of elements - in the following arrays. - name$ is an array of string values. - type$ is an array of string values. - values is an array of numeric values. - - Values of arg: - - elt_name returns total number of moles of element in system. - count is the number of species for the element in - the system, including aqueous, exchange, surface, - equilibrium_phase, solid solution component, and - gas phase "species". - Arrays are filled for each "species"; values are moles. - "elements" returns total number of moles of dissolved elements other - than H and O. - count is number of elements, valence states, - exchangers, and surfaces. - Arrays are filled for each element and valence state, - type is "dis"; exchanger, type is "ex", - and surface, type is "surf". Values are moles. - "phases" returns maximum saturation index of all phases. - count is number of phases in system. - Arrays are filled for each phase; values are - saturation indexes. - "aq" returns sum of moles of all aqueous species. - count is number of aqueous species in system. - Arrays are filled with each aqueous species; - values are moles. - "ex" returns sum of moles of all exchange species. - count is number of exchange species in system. - Arrays are filled with each exchange species; - values are moles. - "surf" returns sum of moles of all surface species. - count is number of surface species in system. - Arrays are filled with each surface species; - values are moles. - "s_s" returns sum of moles of all solid solution components. - count is number of solid solution components in system. - Arrays are filled with each solid solution component; - values are moles. - "gas" returns sum of moles of all gas components. - count is number of gas components in system. - Arrays are filled with each gas component; - values are moles. - -* Added new Basic function, DESCRIPTION, that has the value - defined for the description field of the SOLUTION keyword line. - -* Added alternative ordinary differential equation solver - called CVODE, a set of C routines from the Lawrence - Livermore National Labs. CVODE is part of the SUNDIALS - package. CVODE is used in place of the Runge Kutta method - when "-cvode true" is used within a KINETICS data block. - - KINETICS - -cvode true - ------------------------------------------------------------- -Version 2.8: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.7: ------------------------------------------------------------- -Changed format of selected output file: - Removed quotations surrounding strings in headings. - Removed quotations surrounding strings in state variable. - All fields are 12 or 20 places depending on - -high_precision. - Headings are not truncated even if longer than - specified precision. - For isotopes, missing value is -9999.9 - Selected output is updated each simulation. - If a species or phase is defined - subsequent to the simulation where SELECTED_OUTPUT - was defined it will appear in the selected output - file in the simulation in which it is defined and - in subsequent simulations. - -Added strings for each file, which can be extracted from the - executable file with the "ident" command. - -Fixed null pointer for isotope_ratios if Basic routine - was undefined. - -Fixed problem in C++ if structure name is same as member name. - logk member of logk structure was renamed to log_k. - -Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, - SOLUTION_SPECIES, and SURFACE_SPECIES. - - -add_constant -0.301 - - log K is augmented by the specified constant. - - -Theory and implementation of isotopes in PHREEQC is documented in: - -Thorstenson, D.C., and Parkhurst, D.L., 2002, Calculation of -individual isotope equilibrium constants for implementation in -geochemical models: U.S. Geological Survey Water-Resources -Investigations Report 02-4172, 129 p. - -Added KEYWORDS: - -ISOTOPES - Element - -isotope isotope_name units standard_ratio - -total_is_major T/F (OPTION IS DISABLED!!) - -CALCULATE_VALUES - Name - -start - Basic statements, must have SAVE - -end - -ISOTOPE_RATIOS (for printing) - Name=Calculate_values_name Isotope_name - -ISOTOPE_ALPHAS (for printing) - Name=Calculate_values_name Named_logk=named_expression_name - -Basic functions: - calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES - lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS - lk_phase("name") log10(K) of definition in PHASES - lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES - sum_gas("template","element") Sum of element in gases with specified template, moles. - Example: - template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases - sum_species("template","element") Sum of element in aqueous, exchange, and surface species with - specified template (moles) - sum_s_s("s_s_name","element") Sum of element in a specified solid solution (moles) - -PRINT keyword: - -initial_isotopes T/F - -isotope_ratios T/F - -isotope_alphas T/F - -censor_species 1e-8 # omit species from Distribution of Species if less than - # relative minimum of an element or element redox state - # total concentration - -SELECTED_OUTPUT keyword: - -calculate_values name1 name2 ... - -isotopes minor_isotope1 minor_isotope2 .... - -Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic - interpreter. LK_SPECIES("CaHCO3+") returns the - log k for the association reaction for the ion pair - CaHCO3+ at the current temperature. The log K is - for the reaction as defined in the database or - input file. Similarly, - LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the - value for the log K at the current temperature using - expressions defined in NAMED_LOG_K data block; - LK_PHASE("Calcite") returns the value of log K - for calcite at the current temperature for the - dissociation reaction defined in the database or - input file. Values are "log10" values. -Example for Basic program: - 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") - 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") - 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 - -NAMED_EXPRESSION--New keyword data block. - - This data block was implemented to facilitate isotopic - calculations. It allows analytical expressions that - are functions of temperature to be defined. The purpose - is to separate the fractionation factors from the log - K, so that the fractionation factor or its temperature - dependence can be easily modified. The named expression - can be added to a log K for a species or phase by the - -add_logk identifier in SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data - block. Log K, Delta H, and analytical expressions for a - log K can be defined with identifiers -log_k, -delta_h, - and -analytical_expression as described in SOLUTION_SPECIES - in WRIR 99-4259. Fractionation factors are often defined - as 1000*ln(alpha). The identifier -ln_alpha1000 can be used - to enter data in this form. The analytical expression is the - same as defined in SOLUTION_SPECIES, but the result of the - expression is converted to log10(alpha) by dividing by - 1000*ln(10) before it is summed into log K values. - -NAMED_EXPRESSIONS - Log_K_calcite # CaCO3 + 2H3O+ = Ca+2 + 3H2O + CO2 - log_k 8.201 - delta_h -8.035 kcal - -analytic 292.29 0.015455 -24146.841 -94.16451 2248628.9 - - Log_alpha_18O_CO2(aq)/Calcite - -ln_alpha1000 3.8498 0.0 10.611e3 0.0 -1.8034e6 - - Log_alpha_13C_CO2(aq)/Calcite - -ln_alpha1000 2.72 0.0 0.0 0.0 -1.1877e6 - ------------------------------------------------------------- -Added identifier -add_logk to SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, and PHASES data - block. - - Allows a named expression to be added to the definition - of the log K for a species or phase. In the following - example, the log K for the phase Ca[14C][18O]3 is summed from - four parts, one defined with the log_k identifier and the - other three parts from expressions defined in NAMED_EXPRESSIONS. - The named expression is multiplied by the coefficient at the - end of the line before it is summed into the log K. A missing - coefficient is 1.0 by default. - -PHASES - Ca[13C][18O]3 - Ca[13C][18O]3 + 3CO2 + 2H3O+ = Ca+2 + 3H2O + 3CO[18O] + [13C]O2 - log_k 0.903089986991 # 3*log10(2) - -add_logk Log_K_calcite 1.0 - -add_logk Log_alpha_13C_CO2(aq)/Calcite 1.0 - -add_logk Log_alpha_18O_CO2(aq)/Calcite 3.0 - - -SOLUTION keyword: - At present, can only define isotopes in the units defined in ISOTOPES. - ------------------------------------------------------------- -Version 2.6: ------------------------------------------------------------- - - No new features. - ------------------------------------------------------------- -Version 2.5: ------------------------------------------------------------- -Added the capability to use square brackets to define an - "element" name. The brackets act like quotation marks - in that any character string can be used within the - brackets as an element name. For example, [Fe3], [13C], - and [N5] are now legal "element" names. All element - names without brackets must begin with a capital letter, - followed by zero or more lower case letters and underscores. - -Added identifier -activity_water for a species in SOLUTION_SPECIES - data block. This identifier has been added for future updates - that will allow isotopic calculations. It is intended to be - used only for isotopic variations of H2O, like D2O or - H2[O18]. It forces the activity coefficient for the - species to be activity(water)/55.5. This effectively sets - the activity of the species to the mole fraction in - solution. - -Added identifier -bad_step_max to KINETICS data block. - An integer following -bad_step_max gives the maximum number - of times a rate integration may fail before execution of the - program is terminated. Default is 500. - ------------------------------------------------------------- -Version 2.4: ------------------------------------------------------------- - ------------------------------------------------------------- -Added identifier -warnings to PRINT keyword. - - An integer following -warnings gives the maximum number - of warnings to print into the output file. A negative - number allows all warnings to be printed. - - Example: -warnings 20 - ------------------------------------------------------------- -Changed the results of the function CELL_NO in Basic programs. - - Function cell_no in Basic now prints a number equivalent - to -solution in SELECTED_OUTPUT data block. It gives the - solution number for initial solution calculations and the - solution being used in batch reaction calculations. - Result is the same as previous versions for ADVECTION or - TRANSPORT calculations. - ------------------------------------------------------------- -Version 2.3: ------------------------------------------------------------- -DATABASE--New keyword data block - - It must be the first keyword in the input file. - The character string following the keyword is - the pathname for the database file to be used - in the calculation. The file that is specified - takes precedence over any default database - name, including environmental variable - PHREEQC_DATABASE and command line arguments. - -LLNL_AQUEOUS_MODEL_PARAMETERS--New keyword data block - - Added new keyword to make aqueous model similar to - EQ3/6 and Geochemists Workbench when using - llnl.dat as the database file. Values - of Debye-Huckel a and b and bdot (ionic strength - coefficient) are read at fixed temperatures. - Linear interpolation occurs between temperatures. - - New options for SOLUTION_SPECIES are - -llnl_gamma a , where a is the ion-size parameter. - -co2_llnl_gamma , indicates the temperature dependent - function for the bdot term given in - -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS - will be used. Applies to uncharged - species only. - -LLNL_AQUEOUS_MODEL_PARAMETERS --temperatures - 0.0100 25.0000 60.0000 100.0000 - 150.0000 200.0000 250.0000 300.0000 -#debye huckel a (adh) --dh_a - 0.4939 0.5114 0.5465 0.5995 - 0.6855 0.7994 0.9593 1.2180 -#debye huckel b (bdh) --dh_b - 0.3253 0.3288 0.3346 0.3421 - 0.3525 0.3639 0.3766 0.3925 --bdot - 0.0394 0.0410 0.0438 0.0460 - 0.0470 0.0470 0.0340 0.0000 -#cco2 (coefficients for the Drummond (1981) polynomial) --co2_coefs - -1.0312 0.0012806 - 255.9 0.4445 - -0.001606 - ------------------------------------------------------------- -Added function SURF to Basic. - - SURF("element", "surface") gives the amount of element - sorbed on "surface". "surface" should be the surface - name, not the surface-site name (that is, no underscore). - ------------------------------------------------------------- -Allow decimals in definition of secondary master species. - - Some redox states do not average to integers, - for convenience in identifying them, decimal numbers - may be used within the parentheses that define the - redox state, example S(0.3) could be used in the - MASTER_SPECIES data block for the valence state of - aqueous species S6-2. - ------------------------------------------------------------- -Eliminate echo of input file in PRINT data block. - - -echo_input T/F turns echoing on and off. - Default is true, initial value is true. - ------------------------------------------------------------- -Added option for an equilibrium-phase to dissolve only. - "dis" is added at the end of a line defining an equilibrium- - phase. No data fields may be omitted. Should not - be used when adding an alternative reaction. - Example: - EQUILIBRIUM_PHASES - Dolomite 0.0 0.001 dis - ------------------------------------------------------------- -Version 2.2: ------------------------------------------------------------- -Added function EDL to Basic. - EDL("element", "surface") gives the amount of - element in the diffuse layer for "surface", not - including sorbed species. "surface" should be - the surface name, not the surface-site name - (that is, no underscore). - - Special values for "element" include: - "charge" - gives surface charge, equivalents. - "sigma" - surface charge density, C/m**2. - "psi" - potential at the surface, Volts. - "water" - mass of water in the diffuse layer, kg. - ------------------------------------------------------------- -End of Features not documented in WRIR 99-4259. ------------------------------------------------------------- - - - -************************************************************ -************************************************************ -* Revisions and Bug Fixes * -************************************************************ -************************************************************ - ------------------------------------------------------------- -Version @PHREEQC_VER@: @PHREEQC_DATE@ ------------------------------------------------------------- - -------- - svn 5570 - -------- - In SELECTED_OUTPUT; -totals, a redox state defined - with a "+" sign, such as Fe(+3), was not recognized - ("Fe(3)" worked correctly). Now Fe(+3) is - synonymous with Fe(3). - ------------------------------------------------------------- -Version 2.18.0: April 9, 2011 ------------------------------------------------------------- - -------- - svn 5212 - -------- - Subscript error in solver (ineq) when reseting deltas - after optimization failed. - - -------- - svn 4996 - -------- - Had conversion conversion to Kelvin as 273.16 in Basic - function TK, should be 273.15. - - -------- - svn 4955 - -------- - Changed O2(g) constant in Amm.dat and iso.dat to - definition from llnl.dat. - - -------- - svn 4954 - -------- - Added two more parameter sets in series of attempts - to converge: tolerance/100 and tolerance/1000. - - -------- - svn 4943 - -------- - Added separate As(3) in sit.dat. - - -------- - svn 4854 - -------- - Added two additional convergence parameter sets: - ineq_tol/100 and ineq_tol/1000. - - -------- - svn 4840 - -------- - Added missing -dw parameters to MgCO3, MgHCO3, and - MgSO4 aqueous species in phreeqc.dat. - ------------------------------------------------------------- -Version 2.17.5: September 7, 2010 ------------------------------------------------------------- - -------- - svn 4793 - -------- - Revised fix for exponential of negative number - in Basic. Error message for negative number raised - to a fractional power. - - ------------------------------------------------------------- -Version 2.17.4: September 2, 2010 ------------------------------------------------------------- - -------- - svn 4771 - -------- - Added synonyms to TOTMOLE: TOTMOL, TOTMOLES - Fixed bug with negative exponential in basic, - for example -0.006^0.9 - ------------------------------------------------------------- -Version 2.17.3: August 12, 2010 ------------------------------------------------------------- - - -------- - svn 4727 - -------- - Increased maximum iterations in cl1 solver. One test - case failed after new compiler was installed. - - -------- - svn 4700 - -------- - Initialized (nearly) all variables in class. - - -------- - svn 4697 - -------- - Fixed bug with second PITZER data block, parameters - were not updated if temperature was not changed. - - -------- - svn 4698 - -------- - Modified PHRQ_malloc and PHRQ_free logic. These routines - are used in almost all cases. - - -------- - svn 4694 - -------- - Initialized variables for V_M structure, rxn->dz (for CD_MUSIC), - Fixed problem where definitions in second SIT data block were - not added to model. - - -------- - svn 4677 - -------- - Renamed all variables that "shadowed" class variables. - - -------- - svn 4643 - -------- - Made isfinite a macro. - - -------- - svn 4539 - -------- - Fixed bug with long file names in inverse modeling files - netpath.fil or model.fil. - - -------- - svn 4490 - -------- - Redox had never been enabled for the SIT formulation. - Added the switch to include the hydrogen balance - equation for SIT. - - -------- - svn 4458 - -------- - Tweaked the convergence parameters for Pitzer log - gamma unknowns. Set a maximum step size for these - unknowns. Also changed usage of internal flags - for Pitzer calculations related to initial solution - calculations. Corrected print of Gamma iterations. - - -------- - svn 4399 - -------- - Error in PHRQ_calloc. Size of allocated block was - not set. Under some situations, could cause serious - errors and a crash. - - -------- - svn 4376 - -------- - Error in logic for removing unstable phases for Pitzer - and SIT. - - -------- - svn 4233 - -------- - Removed duplicate parameter for Na+ -- Cl- in sit.dat. - Value of 0.03 was entered erroneously for both Na/Cl and Cl/Na. - ------------------------------------------------------------- -Version 2.17.0: February 25, 2010 ------------------------------------------------------------- - -------- - svn 4115 - -------- - Fixed bugs with unititialized strings in Basic, which - caused an error in renumbering with PhreeqcI. Tested - most Basic functions. Fixed bugs with LG and GAMMA - functions, which did not return the correct values - for H+. GET_POR now returns 0 if it is not a TRANSPORT - calculation. - - - -------- - svn 4066 - -------- - Fixed bug with SIT calculations (and Pitzer). The - number of solver iterations was too few (200). With - SIT and Pitzer, each species has an unknown, so the - number of unknowns is large for a system with many - elements. Now set the maximum iterations to be - equal to the number of unknows plus the number of - equations/inequalities. - - -------- - svn 4023 - -------- - Trapped error when -mole_balance option was used in - SOLUTION_SPECIES and one of the stated elements was - not defined. - - -------- - svn 4022 - -------- - Redefined CN- and SCN- to be new elements Cyanide and - thiocyanate in llnl.dat. Former definitions were not - useful because cyanide and thiocyanate were never - stable and defining a master species as CN- caused - problems with mole balances, appearing in solutions - without any carbon. - - -------- - svn 3901 - -------- - Error with equations that included (s) or (g). The - equation and log K were correct only for the simulation - when initially read. Now equations an log Ks are correct - for all simulations. Calculates saturation index from - the equation after (s) and (g) are eliminated. - - - -------- - svn 3695 - -------- - For transport calculations, fixed step_fraction when - nmix == 1 and ishift == 0. - - -------- - svn 3684 - -------- - Added more precision in writing dump file fields. - - Multiple REACTIONS were not sorted correctly. Added sort - routine to tidy.c. - - -------- - svn 3640 - -------- - Print correct temperature for gas phase dump. - - Correct total moles of exchanger for function sys("X"). - - -------- - svn 3568 - -------- - minteq.dat: Changing log K of gypsum to minteq version - 4 value (-4.61). Old value (-4.848) is too stable. - - -------- - svn 3483 - -------- - Alkalinity is now printed to the selected output file - when the Alkalinity is used with -totals. - - SELECTED_OUTPUT; -totals Alkalinity - - Modified numerical method to attempt to produce a numerical - solution when complexes are extremely strong. llnl.dat As and F - complexes caused PHREEQC to fail on an initial solution - calculation. The terms of the As and F mass balance equations - were identical to machine precision. One unknown log activity - was adjusted but the other was not. Now attempts an adjustment - for the unadjusted log activity. - - - -------- - svn 3463 - -------- - Modified handling of not-a-number in places that - affected the adjustment of log activities (reset and - revise guesses). Uses isfinite function that is available - on Linux and is ifdef'd in global.h for Visual Studio. - The NaN problem occurred rarely and was related to - bad results from the solver and when poor estimates were - available in revise_guesses. Also insured that log activity - for new master species was well defined in switch_bases. - - -------- - svn 3446 - -------- - Fixed errors in casting for long double version. - - -------- - svn 3440 - -------- - Adjusted numerical calculation to avoid extremely large - calculated specific conductances in high ionic strength - waters. - - -------- - svn 3433 - -------- - -dw and -millero added to phreeqc.dat, which allows - calculation of specific conductance and density. - phreeqd.dat is now redundant and removed from distribution. - - -------- - svn 3425 - -------- - Added error message to require -multi_d for transport of - surfaces. - - -------- - svn 3424 - -------- - Checked for misspellings in EXCHANGE definitions, which - previously caused crash. - - -------- - svn 3423 - -------- - -dw and -millero added to pitzer.dat, which allows - calculation of specific conductance and density. - - -------- - svn 3292 - -------- - Removed redundant warnings related to transport of exchanger - and surface. - - -------- - svn 3287 - -------- - Fixed error in CD_MUSIC surface complexation model. - If reaction equation for a surface species was not - written with the primary surface species, the calculation - was incorrect. The logic to accumulate the change in - charges on the planes was erroneously not included when - rewriting the equations to the master species. - - -------- - svn 3247 - -------- - Revised donnan layer calculation with CD_MUSIC. Fixed - a bug related to moles versus concentration and stream - lined calculation. Minor differences in relevant test - cases. - - -------- - svn 3207 - -------- - Modifications to convergence criteria for surfaces - related to minerals, when moles of mineral is near - zero (<= 1e-14). - - -------- - svn 3100 - -------- - Error when multiple surfaces were used. Sometimes the - surface area from one surface was used for another. - Results were probably incorrect if the surfaces were - not in alphabetical order in their definition in - SURFACE. - - -------- - svn 2711 - -------- - Cleaned up compiler warnings for functions called - with constant strings. ------------------------------------------------------------- -Version 2.15.0: February 5, 2008 ------------------------------------------------------------- - -------- - svn 2386 - -------- - Fixed bug for SELECTED_OUTPUT; -activities H2O. The - resulting value was -30; now produces the correct - result. - ------------------------------------------------------------- -Version 2.14.3: November 17, 2007 ------------------------------------------------------------- - - -------- - svn 2386 - -------- - Fixed bug in routine find_Jstag. Incorrect index (cell_no) - caused segmentation violation in rare instances. - - -------- - svn 2312 - -------- - Added new option to PITZER datablock, use_etheta t/f. - - -------- - svn 2279 - -------- - Error lost 200 moles of mineral. Should only be a problem - in some cases where moles of mineral is greater than 200. - - -------- - svn 2270 - -------- - Added additional parameters Pitzer activity formulation for - neutral species, MU and ETA. - - -------- - svn 2269 - -------- - Fixed buffer overrun in SOLUTION_SPREAD when pasting. - - -------- - svn 2268 - -------- - Fixed error in prep.c where realloc was called instead - of PHRQ_realloc, which eliminated a memory leak. - ------------------------------------------------------------- -Version 2.14.2: September 17, 2007 ------------------------------------------------------------- - - -------- - svn 2267 - -------- - Fixed logic of memory checking for PhreeqcI. This serious - bug makes versions 2.14.0 and 2.14.1 unusable. - ------------------------------------------------------------- -Version 2.14.1: September 5, 2007 ------------------------------------------------------------- - -------- - svn 2219 - -------- - Updated transport.c to adjust transport in diffuse - layer to be charge balanced for MCD calculation. - ------------------------------------------------------------- -Version 2.14.0: August 30, 2007 ------------------------------------------------------------- - ------------- - svn 2203-2204 - ------------- - Revised logic for using phqalloc memory checker. Compiler - option USE_PHRQ_ALLOC now turns on memory checker. If - USE_PHRQ_ALLOC is defined and NDEBUG is not defined, file name - and line number are also used in memory checking. Model.c - now uses same compile options as all other files. - - -------- - svn 2199 - -------- - Initialized variables that caused problems when rerunning - simulations in PfW and PhreeqcI. - - -------- - svn 2138 - -------- - Fixed bugs in MCD calculation related to saving solutions - after initialization. - - -------- - svn 2055 - -------- - Profiled and optimized of code. Automatic string in Basic - factor saves many mallocs. Reordered to minimize call to - strcmp_nocase in basicsubs.c and xsolution_save. Minimized - mallocs for solver. - - -------- - svn 2051 - -------- - Fixed bugs in MCD calculation. - - -------- - svn 2040 - -------- - Fixed warnings for type-punned with new gcc. - - Reverted to 2.12 for infilling solutions for transport. - Only solutions are used, not additional reactants for solution - 0 and n+1. - - Added digits to printout of REACTION stoichiometry. - - -------- - svn 1852 - -------- - Fixed error in CDMUSIC surface related to a phase. - Stoichiometry of H was calculated incorrectly. - - -------- - svn 1837 - -------- - Initialize flag for MCD calculation. PhreeqcI would - do MCD calculation after TRANSPORT was redefined not - to do MCD calculation. - ------------------------------------------------------------- -Version 2.13.2: February 1, 2007 ------------------------------------------------------------- - -------- - svn 1700 - -------- - Fixed bug with redox elements in multi_diffusion - stagnant zones. - - -------- - svn 1683 - -------- - Worked on convergence problems when optimizer fails to - find a solution. Censored values greater than 1e8. - - -------- - svn 1637 - -------- - Fixed bug with dissolve only in ADVECTION calculations. - - -------- - svn 1629 - -------- - Fixed bug with redox elements in multi_diffusions. Added - Phreeqc For Windows changes from 2.13.1. - ------------------------------------------------------------- -Version 2.13.1: January 16, 2007 ------------------------------------------------------------- - -------- - svn 1600 - -------- - Fixed logic error that required rebuilding aqueous model - when not necessary. Now runs faster (sometimes 3X) than - version 2.13.0. - - -------- - svn 1590 - -------- - Removed porosity from one statement to eliminate oscillations - in multicomponent diffusion calculation. - - -------- - svn 1558 - -------- - Dissolve-only option did not work correctly for stagnant cells - in TRANSPORT calculations. The moles of equilibrium phases, - kinetics, gas_phase, and solid solutions were not initialized - at the beginning of each transport step. Thus, the printed values - for delta moles for the step in the output and punch file were - incorrect for stagnant-zone cells. "Dissolve only" was - always tested relative to the number of moles initially in the - cells, not the amount remaining at a given time step. - - -------- - svn 1485 - -------- - Pitzer version with gas_phase did not work. Added - gas_phase and cd_music to numerical derivative routine. - - - - svn 1368: (1) Added multicomponent diffusion in transport and - SOLUTION_SPECIES. (2) Added BASIC functions to obtain and - modify the porosity in a cell. (3) Aded mobile surface and Donnan - option in SURFACE. (4) Added special BASIC function to change - the diffusion coefficient of a SURFACE, and hence to - change the status from mobile to immobile or immobile to - mobile. - - svn 1337: Added -add_logk to NAMED_EXPRESSIONS keyword. - - svn 1306: Revised printing of distribution of species, - pure phase assemblages, and solid solutions to use - longer fields for names. More revisions to logic - for using gases and solids in equations for phases. - Revised logic for solid solutions with small (1e-25) amounts - of component. - - svn 1282: Fixed bug when gas phase had no gas components. - Looked the same as not having a gas phase at all. - - svn 1245: Enabled redox in Pitzer model with option in - PITZER keyword. Typically, the option will be included - in the pitzer database file. - -PITZER - -redox TRUE - - The default database for the Pitzer model does not contain - any redox definitions and the default value for the option - is FALSE. At a minimum, species O2 and H2 must be defined - in the database or input file to allow redox calculations. - - svn 1179: New option (-sites_units density) allows alternative - units (sites/nm^2) for definition of number of sites for a - surface. This approach requires better consistency among the - parameters as both the number of sites and the surface area - are based on the mass. It makes more sense than the default, - which requires the number of sites (first numeric item in a - line) to be defined in units of moles, independently of the - number of grams of sorbent. - -SURFACE 1 - -sites DENSITY - SurfOH 2.6 600. 1.0 - SurfaOH 2.6 30. 2.0 - - In this example, Surf has a site density of 2.6 sites per - nanometer squared, a specific area of 600 meters squared per - gram, and a mass of 1 gram. Surfa has a site density of 2.6 - sites per nanometer squared, a specific area of 30 meters - squared per gram, and mass of 2 grams. - - svn 1128: Fixed bug with value of time printed to selected - output file when using cvode. Value printed was an - intermediate integration time step, not time at end - of integration. - - svn 1096: Allows solids and gases in the equations for - PHASES. This capability simplifies the definitions for - gas and solid isotopic components. Solids must be identified - with "(s)" and gases with "(g)". The first entity on the left- - hand-side of the equation must be the stoichiometric formula - of the solid of gas component being defined, optionally with - (g) or (s). In turn gases and solids included in the equation - must be defined with reactions that ultimately allow the - defined species (C[18O]2(g) in this case) in terms of aqueous - species. - -C[18O]2(g) - C[18O]2(g) + CO2(g) = 2CO[18O](g) - log_k 0.602059991327962396 # log10(4) - - svn 1092: CD_MUSIC sorption model has been implemented. - Still missing logic for surfaces related to equilibrium- - phases and kinetics. Has explicit calculation of diffuse - layer composition with Donnan assumption. Old diffuse-layer - calculation will not be implemented. - - Example: - -SURFACE - Goe_uniOH .000552 96.387 1 - -capacitance 1.1 5 - Goe_triO .000432 - -cd_music - -donnan - - 1.1 5 are capacitances for the cd-music model for 0-1 and 1-2 - planes, respectively. - -cd_music specifies that the surface is a cd-music surface. - -donnan optionally calculates the diffuse layer composition - with the Donnan model. - -SURFACE_SPECIES - Goe_uniOH-0.5 + H+ + AsO4-3 = Goe_uniOAsO3-2.5 + H2O - log_k 20.1 # eq 7 K1, Kin1 - -cd_music -1 -6 0 0.25 5 - - -cd_music gives the charge contribution of the surface - species to the three planes. Plane 0 is - -1 + 0.25*5; Plane 1 is -6 + (1-0.25)*5; - Plane 2 (or d) is 0. - - - svn 1030: Fixed bug in tranport. Mixing was not printed - when using -cvode in kinetics. - - svn 984: Fixed bug in transport when cell without a - surface followed a cell with a diffuse-layer surface. - Fixed bug in TOTAL function; code ran of the end of - the list of master species; changed logic to recognize - the end of the list. - - svn 874: Fixed bug in check_same_model. Thought surface - calculation was the same even though -edl switch was - different, which gave irratic results and possible - crash. Now checks more carefully to make sure calculation - for surfaces is really the same and reinitializes if - not. - - svn 847: Fixed bug with DESCRIPTION function. Did not - give correct solution description for reactions. - - svn 826: Update tally.c to avoid conflicts in C++ - version of phast. - - svn 801: Wrote around underflow in fabs in subroutine - reset. - - svn 794: Errors in minteq.v4.dat database. Several redox - reactions had delta H listed as kcal instead of kJ. kcal - is correct only for the following species H2, NO2-, and - NH4+. - - svn 675: - Added PRINT option to print the species that contribute - to alkalinity. Alkalinity distribution is printed in - the output file following the distribution of species. - Default at program startup is false. - - PRINT - -alkalinity true - - svn 655: - IAP and log K printed in Phase assemblage data - block were calculated from reactions rewritten to - new master species. Now the original data base - reaction is used to calculate IAP and log K. - Also fixed check that ensured all elements of - phase in are in solution before SI is calculated. - - svn 631: - Fixed bug with alternate formula for equilibrium phase, - nothing happened if all other equations were satisfied - at beginning of reaction calculation. - - svn 603: - Link gmp library statically. - - svn 601: - Fixed statement on multiprecision. - - svn 581: - Fixed bug in PhreeqcI that did not reinitialize - Chebyschev parameters leading to incorrect results - with Pitzer activity coefficients. Results were - correct on first run, but erroneous on subsequent - runs. - - Added statement to identify multiprecision or - standard solver for inverse modeling. - - svn 578: - - Distribution changes. Fixed names in README file. - Modified Makefile to use specified version. Split - Linux and source distribution procedure. - ------------------------------------------------------------- -Version 2.12 Date: Wed September 28, 2005 ------------------------------------------------------------- - - Executables and output files for Sun operating systems - are no longer provided. - - Limited log activities of master species to be greater - than the smallest machine precision exponential number. - Avoids a matherr exception and allows trial of additional - parameter sets to attempt to solve the system of - equations. - - Made aqueous activity coefficients the default activity - coefficients for exchange species when using the - Pitzer formulation. New option in EXCHANGE is - -pitzer_exchange_gammas T/F, default is true; - defining "false" sets exchange activity coefficients - to 1.0. Option has no effect for ion-association - model (non-Pitzer). - - Edited phreeqc.dat to add -gamma expression for - CdX2 and PbX2. - - Replaced O2(g) log K in phreeqc.dat and wateq4f.dat - with data from llnl.dat, which appears to be better. - - Added multiplier format to REACTION increments, which - simplifies definition of multiple equal reaction increments. - - REACTION - H2O 1 - -36 3*-4 2*-.25 -0.19 4*-0.1 3*-0.05 moles - - Added Pitzer activity formulation. Use pizer.dat database - to invoke the Pitzer model. Should have same capabilities - as ion-association model except explicit diffuse layer - calculation is not implemented with the Pitzer model. - - - Fixed bug in surface sites related to mineral and exchange - sites related to mineral. Did not have complete logic to - handle redox valence states in formula for species. - - Modified to remove non standard usage of va_list. - - Removed exchange master species from SYS("ex",..) - list of species. This species is fictive and should - not be included in the list. - - Changed -redox in SOLUTION so that if one of the - redox states of a couple is not defined, then - redox defaults to pe. - - Fixed buffer overrun in PhreeqcI with SOLUTION_SPREAD, - caused segmenatation fault with lines greater than - 500 characters. - - Added bigger string for some error messages to avoid - access violation in cvode. - - Changed output_msg to warning_msg for combinations - of convergence parameters so that message would - be controlled by -warnings identifier. - - Carriage returns are now stripped from Basic program - statements. Switching files from Windows to Unix sometimes - leaves extra carriage returns at the ends of lines, which - caused a syntax error for some Basic commands. - - Two bugs were fixed in inverse modeling. (1) Potential - models are now checked for all equality and inequality - constraints. Previously some constraints were not checked. - (2) One loop of cl1 did not include the last row when - checking for the pivot element. Also printing of headers - was slightly modified for inverse modeling. - - A new multiple precision version of cl1 was develeped by - using the Gnu Multiple Precision package (gmp). Calculations - are carried out to about 30 significant digits. The mp - version may help in some situations where roundoff errors are - a problem, but it is still possible that roundoff errors will - cause cl1mp to fail to find a solution to the optimization - problem. The mp version has the following options in - INVERSE_MODELING: - -multiple_precision T/F--causes the mp version - to be used in inverse modeling calculations. - -mp_tolerance 1e-12--tolerance for mp version of - cl1. As in cl1, numbers less than the - tolerance are considered to be zero. - 1e-12 is the default. - -censor_mp 1e-20--as calculations occur in the - linear equation array, elements less - than this value are set to zero. Default - is 1e-20. A value of 0.0 causes no - censoring to occur. - ------------------------------------------------------------- -Version 2.11 Date: Mon February 7, 2005 ------------------------------------------------------------- - - Fixed error in selected output file with mixing reaction. - MIX number was written to two columns, should be one. - - Fixed memory leak with PAD function. - - New database minteq.v4.dat has been translated from version - 4.02 of MINTEQA2. An older version of the MINTEQA2 database is - retained in file minteq.dat. - - Switched version control to subversion. Simplified, - reorganized makefiles. - - Fixed bug with PRINT; -warnings n. Use of this option - generally eliminated all warning messages instead of - all messages after the nth. Default number of warning - messages printed in now 100 per simulation. - - Fixed memory leaks in cvode that caused phreeqci to crash. - Now uses PHRQ_malloc in case of other memory leaks. Also - fixed potential memory error with PAD Basic function. - - Saturation index phases that included water had wrong - value if distribution of species, exchange, or surface - not written also. - - Fixed error message in cvode, if max iterations exceeded - the error caused a segmentation fault. - - Made printing of parameter combination message a warning - message so that it could be turned off. - ------------------------------------------------------------- -Version 2.10 Date: Tue November 2, 2004 ------------------------------------------------------------- - - Rearranged i/o for PHREEQC and reorganized driver - subroutine. The object of these changes is to make - the program more functional as a module for other - programs (PHAST) and eventually to produce a callable - C and Fortran module. - - Fixed a problem with surface related to a phase, when - phase was not part of system (for example, Fe(OH)3a when - there is no iron in system. - - Added convergence parameter set that requires mineral - transfers to produce positive concentrations in the - event that negative concentrations have been produced in - the prior Newton-Raphson iteration. (Fluorite example). - - Fixed bug with kinetics formulas; did not account for - stoichiometric coefficient correctly when using - phase names. Generalized to allow multiple phase - names in the -formula definition. - ------------------------------------------------------------- -Version 2.9 Date: Wed September 15, 2004 ------------------------------------------------------------- - - In inverse modeling, program terminates if sum of initial - solutions and phases is > 32. - - Fixed bug with isotopes. Log activity estimate after initial - solution calculation was inf under some conditions. An initial - surface calculation failed when using D. - - Changed saturation index print out to use reaction and log K - defined in PHASES definition. Previously, reaction could be - rewritten to predominant redox species. - - Fixed incorrect print of elapsed time for kinetics in advection. - - Added phrqproto.h prototype file and phrqtype.h for - switching compilation to long double. - - Fixed incorrect printout of kinetics delta moles with - advection. - - Added convergence parameter set that skips mineral - equations for first 5 iterations. - - Added entity_exists for module. - - Tried to fix bug with mix index incorrect (-2) for - mixing with kinetics. - - Added new keyword COPY that allows a data entity - to be copied from one index to a new index - or to a range of indicies. Format is - - COPY keyword index index_start[-index_end] - - where keyword is one of the following: - SOLUTION - EQUILIBRIUM_PHASES - EXCHANGE - GAS_PHASE - KINETICS - MIX - REACTION - REACTION_TEMPERATURE - SOLID_SOLUTION - SURFACE - - Numerical method had a bug with ionic strength, if - mass of water was not approximately 1. Routine - revise_guesses did not divide by the mass of - water. Also changed check in routine molalities - to check by molality, not moles. - - Fixed a null pointer when surface was related to a - mineral and mineral was not in database. - - Added new Basic functions - i = INSTR(a$, b$) sets i to the character position of - string b$ in a$, 0 in not found. - b$ = LTRIM(a$) trims white space from beginning of - string a$ and stores result in b$. - b$ = RTRIM(a$) trims white space from end of string - a$ and stores result in b$. - b$ = LTRIM(a$) trims white space from beginning and - end of string a$ and stores result in b$. - - Added new Basic function SYS that calculates the to - total amount of an element in all phases (solution, - equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase). KINETIC reactions are not included. - The function has two forms: (1) one element name as an - argument (variable names are user specified) - - 10 t = SYS("As") - - the function will return the total arsenic in the system. - (2) 5 argumens - - 10 t = SYS("As", count_species, names$, types$, moles) - - will return the total arsenic in the system to tot; count_species-- - the number of species that contain arsenic, including - solution, equilibrium_phases, surfaces, exchangers, solid solutions, - and gas phase species; names$--a character array that has the - name of each species; type$--a character array that specifies the - type of phase for the species, aq, equi, surf, ex, s_s, gas, diff. - Diff refers to the amount of the element in the diffuse layer of - a surface when the explicit diffuse layer calculation is used; - moles--an array containing the number of moles of the element in - the species. The sum of moles(i) is equal to tot. - - SYS has several special arguments for the form - SYS("arg", count, names$, types$, values) - arg is one of the options listed below. - count is a single numeric value and is the number of elements - in the following arrays. - name$ is an array of string values. - type$ is an array of string values. - values is an array of numeric values. - - Values of arg: - - elt_name returns total number of moles of element in system. - count is the number of species for the element in - the system, including aqueous, exchange, surface, - equilibrium_phase, solid solution component, and - gas phase "species". - Arrays are filled for each "species"; values are moles. - "elements" returns total number of moles of all elements, - valence states, exchangers, and surfaces. - count is number of elements, valence states, - exchangers, and surfaces. - Arrays are filled for each element, valence state, - exchanger, and surface; values are moles. - "phases" returns maximum saturation index of all phases. - count is number of phases in system. - Arrays are filled for each phase; values are - saturation indexes. - "aq" returns sum of moles of all aqueous species. - count is number of aqueous species in system. - Arrays are filled with each aqueous species; - values are moles. - "ex" returns sum of moles of all exchange species. - count is number of exchange species in system. - Arrays are filled with each exchange species; - values are moles. - "surf" returns sum of moles of all surface species. - count is number of surface species in system. - Arrays are filled with each surface species; - values are moles. - "s_s" returns sum of moles of all solid solution components. - count is number of solid solution components in system. - Arrays are filled with each solid solution component; - values are moles. - "gas" returns sum of moles of all gas components. - count is number of gas components in system. - Arrays are filled with each gas component; - values are moles. - - Added new Basic function, DESCRIPTION, that has the value - defined for the description field of the SOLUTION keyword line. - - Added alternative ordinary differential equation solver - called CVODE, a set of C routines from the Lawrence - Livermore National Labs. CVODE is part of the SUNDIALS - package. CVODE is used in place of the Runge Kutta method - when "-cvode true" is used within a KINETICS data block. - - KINETICS - -cvode true - - Fixed error in SOLUTION_SPREAD, defining -redox - did not set the default redox for the solutions - that were defined; pe was always used as default. - - Modified code to allocate space differently for - pp_assemblage, exchange, surface, gas_phase, - kinetics, and s_s_assemblage. Enough space is allocated - at beginning of distribute_initial_conditions. - May speed up phast initialization and make better - use of available memory. - - Changed gfw of water to 18 if isotopes of water are - included. Solvent is [1H]2[16O]. - - Fixed a bug in surface integration where order of ions - in the list of g's was incorrect. - - Pyrite rate was not 0 if supersaturated in phreeqc.dat - and wateq4f.dat - - Segmentation error if a surface species was not - defined with an equation that contained another surface - species. In this case, the surface master species - had been redefined to be an aqueous species (SOLUTION_SPECIES). - ------------------------------------------------------------- -Version 2.8 Date: Tue April 15, 2003 ------------------------------------------------------------- - - Updated arsenic data in wateq4f.dat to be consistent with - Archer and Nordstrom (2002). - - Revised Basic interpreter to allow lines of any length - and character strings of any length. - - Renumbering basic statement that included the function - SURF in PhreeqcI caused SURF to be omitted and generated - a syntax error. SURF and other functions had not been - implemented in PhreeqcI. - - Fixed a bug in the Basic Interpreter. If elements of - a dimensioned variable (character or number) were used on - both sides of an equation, the result was erroneously - stored in the last element of the variable used on the - right-hand side instead of the element specified on the - left-hand side. - - Using comma in some fields caused an infinite loop. - - Fixed bug with SOLUTION_SPREAD, Phreeqc was not - calculating solution numbers for solution_spread - solutions without solution numbers. - - Fixed bug with stagnant zone calculations. If solutions - not defined for stagnant cells, PhreeqcI crashed. - - Added new state for calculations, PHAST. Previously - phast used the state TRANSPORT, which caused some - erroneous results with temperature when TRANSPORT was - used in the PHREEQC part of the calculation. - - Trying to define dump file in TRANSPORT caused a file - opening error. Fixed logic so now can open a file - and the name can include blanks. - ------------------------------------------------------------- -Version 2.7 Date: Fri February 14, 2003 ------------------------------------------------------------- - - Initialized gfw in elements structure. - - Fixed bug where "time" would be wrong for initial - solution calculation. Needed to initialize - rate variables for PhreeqcI. - - Added print of simulation number to error file for - phreeqci - - Limited printing of cell numbers to output file in advection - calculations. Cell numbers only printed if results - for cell are going to be printed. - - PhreeqcI captured status messages for kinetics, which - made a very large error file in some cases and - a long wait to view the output file in PhreeqcI. - Now PhreeqcI does not capture these intermediate - status messages. - - Removed old code related to redirecting error file - - - Corrected error in transport where wrong time step was used - for integration. - - Changes to speed up transport algorithm. - - Allow file names with spaces in selected_output file name and - dump_file name. - - Modifications to work with RC1 phast log file. - - Allow any characters in square brackets for element name. - - and + and perhaps others caused problems before. - - Fixed log molality of water in species printout, was - equal to log activity of water. Also fixed - basic function for LM. - - Changed solid solution prints to print 0 if solid solution - is not present. - - Fixed bug if no rate name was defined before options - in RATES. - - Fixed warning on Mac compilation in fpunchf. - - Fixed bug if isotopes were used but H and O isotopes - were not defined. - - Fixed bug where special initial solution calculations - were done at later calculation stages. - Needed to set initial_solution_isotopes = FALSE; - - Fixed problem in C++ if structure name is same as member name. - logk member of logk structure was renamed to log_k. - - Added identifier -add_constant to PHASES, EXCHANGE_SPECIES, - SOLUTION_SPECIES, and SURFACE_SPECIES. - - -add_constant -0.301 - - log K is augmented by the specified constant. - - - Added punch_isotopes and punch_calculate_values to allow - printing isotope ratios and any CALCULATE_VALUES result. - - Added KEYWORDS: - - ISOTOPES - Element - -isotope isotope_name units standard_ratio - -total_is_major T/F (OPTION IS DISABLED!!) - - CALCULATE_VALUES - Name - -start - Basic statements, must have SAVE - -end - - ISOTOPE_RATIOS (for printing) - Name=Calculate_values_name Isotope_name - - ISOTOPE_ALPHAS (for printing) - Name=Calculate_values_name Named_logk=named_expression_name - - Basic functions: - calc_value("calc_value_name") evaluates a definition of CALCULATE_VALUES - lk_named("name") log10(K) of definition in NAMED_EXPRESSIONS - lk_phase("name") log10(K) of definition in PHASES - lk_species("name") log10(K) of definition in (SOLUTION, EXCHANGE, SURFACE)_SPECIES - sum_gas("template","element") Sum of element in gases with specified template - template="{C,[13C],[14C]}{O,[18O]}2" includes all CO2 gases - sum_species("template","element") Sum of element in aqueous, exchange, and surface species with - specified template - sum_s_s("s_s_name","element") Sum of element in a specified solid solution - - PRINT keyword: - -initial_isotopes T/F - -isotope_ratios T/F - -isotope_alphas T/F - -censor_species 1e-8 # Omits print of species if less than relative criterion - - SELECTED_OUTPUT keyword: - -calculate_values name1 name2 ... - -isotopes minor_isotope1 minor_isotope2 .... - - Added functions LK_SPECIES, LK_NAMED, LK_PHASE for Basic - interpreter. LK_SPECIES("CaHCO3+") returns the - log k for the association reaction for the ion pair - CaHCO3+ at the current temperature. The log K is - for the reaction as defined in the database or - input file. Similarly, - LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)") returns the - value for the log K at the current temperature using - expressions defined in NAMED_LOG_K data block; - LK_PHASE("Calcite") returns the value of log K - for calcite at the current temperature for the - dissociation reaction defined in the database or - input file. Values are "log10" values. - Example for Basic program: - - 10 PRINT "Log10 KCalcite: ", LK_PHASE("Calcite") - 20 PRINT "Log10 KCaHCO3+: ", LK_SPECIES("CaHCO3+") - 30 PRINT " 1000ln(alpha): ", LK_NAMED("Log_alpha_18O_CO2(aq)/CO2(g)")*LOG(10)*1000 - - Added NAMED_EXPRESSIONS data block. This data block was - implemented to facilitate isotopic calculations. - It allows analytical expressions that are functions - of temperature to be defined. The purpose is to - separate the fractionation factors from the log K, - so that the fractionation factor or its temperature - dependence can be easily modified. The named - expression can be added to a log K for a species - or phase by the -add_logk identifier in SOLUTION_SPECIES - EXCHANGE_SPECIES, SURFACE_SPECIES, or PHASES data - block. - ------------------------------------------------------------- -Version 2.6 Date: Mon April 22, 2002 ------------------------------------------------------------- - - PhreeqcI released. - - All selected_output is routed through a single routine. - - Allow "_" inside square brackets, [A_bcd]. - - Fixed bug match_elts_in_species, check for "e-" was wrong. - - Modified minteq.dat to put CuS4S5-3, Cu(S4)2-3 in - in Cu(1) mole balance equations instead of - Cu(2). Before the change, the program would - not converge if Cu(2) were defined in an - initial solution. - - Made revisions hopefully to improve SOLID_SOLUTIONS - convergence with small numbers of moles of - solids. - - Made changes related to dump file and PhreeqcI. - - Iterations now sums iterations in all kinetics calculations - - Fixed bug with LA("H2O"), which was returning natural log - of activity of water. - - ------------------------------------------------------------- -Version 2.5 Date: Mon October 1, 2001 ------------------------------------------------------------- - - In llnl.dat, fixed sign errors in RRE (rare earth elements) - for some redox reactions and removed some redundant - species, generally ReeO2- was retained and Ree(OH)4- - was removed. - - Added the capability to use square brackets to define an - "element" name. The brackets act like quotation marks - in that any character string can be used within the - brackets as an element name. This was introduced to - simplify expansion of the model to isotopic species. - [13C], [14C], and [18O] are legal element names. - - Added identifier -activity_water for a species in - SOLUTION_SPECIES data block. This identifier has been - added for future updates that will allow isotopic - calculations. It is intended to be used only for - isotopic variations of H2O, like D2O or H2[O18]. It - forces the activity coefficient for the species to be - activity(water)/55.5. This effectively sets the activity - of the species to the mole fraction in solution. - - Fixed bug in checking solid solutions for presence or - absence of elements in the system. Programming - error caused segmentation fault if an error - was detected under certain conditions. - - Changed return value of MOL to be molality of water - if argument is "H2O". Also changed return value - of LA to be activity of water if argument is - "H2O". - - Diffuse layer calculation was incorrect if aqueous phase did not - have 1 kilogram of water. Eq. 74 of manual has molality, - but code used moles. The code was corrected by adding - the mass of water to the formulation. - - Stagnant zones with first-order exchange approximation (1 stagnant - cell, exchange factor, and porosities defined) did not work - correctly if mobile and immobile cells did not have equal - volumes of water. The mixing factors were revised to account - for the masses of water in the stagnant and mobile zones. - - A fatal error was erroneously detected if the database file - had a DATABASE data block. DATABASE data block is - now ignored while reading the database file. - - Added identifier -bad_step_max to KINETICS data block. - An integer following -bad_step_max gives the maximum number - of times a rate integration may fail before execution of the - program is terminated. Default is 500. - ------------------------------------------------------------- -Version 2.4.2: Date: Fri June 15, 2001 ------------------------------------------------------------- - - Fixed spreadsheet bug. Program was not ignoring columns - that could not be identified as either element - names or allowed data (ph, pe, number, description, - etc). Also, the program failed if a spreadsheet solution - number was negative. - ------------------------------------------------------------- -Version 2.4.1: Date: Mon June 4, 2001 ------------------------------------------------------------- - - Fixed spreadsheet bugs with isotopes. - ------------------------------------------------------------- -Version 2.4: Date: Fri June 1, 2001 ------------------------------------------------------------- - - Added structure for spreadsheet for use by PhreeqcI. - - Isotope value initialized incorrectly if only an -uncertainty was - defined in SOLUTION_SPREAD. - - Fixed segmentation violation when primary and secondary master - species were defined improperly. - - Corrected enthalpies of reaction in llnl.dat. Previous release had - erroneously had enthalpies of formation in -delta_H - parameter; the values should be enthalpies of reaction. - Enthalpies of reaction were calculated from the - enthalpies of formation and these values are now included - in the -delta_H parameter. This change will have very - little impact on calculations because the analytical - expression has precedence over -delta_H in calculating - temperature dependence of log K, and nearly all species - and minerals have an analytical expression or lack both - an analytical expression and an enthalpy of reaction. - - Corrected bugs in punch of solid solution components that caused - both selected output and output file errors: moles - were incorrect in selected output, and total moles and - mole fraction were incorrect in output file. - - Added surface complexation constants for Fe+2; two complexes for - weak sites and one complex for strong sites. phreeqc.dat - and wateq4f.dat modified. - - Comment for units of parameters for calcite rate equation was - wrong. Rate equation now uses cm^2/L for area parameter. - Previously the correct units would have been 1/decimeter. - phreeqc.dat and wateq4f.dat modified. - - Fixed a bug when rates were equal within tolerance, but negative - concentrations occurred because of small initial - concentrations. - - Added -warnings to PRINT keyword for specification of maximum - number of warnings to print. Negative number allows - all warnings to be printed. - - Function CELL_NO in Basic now prints a number equivalent to - -solution in SELECTED_OUTPUT data block. This does not - change printing for ADVECTION or TRANSPORT calculations. - - Kinetics time is halved for advective part of reaction in - transport; time incorrectly accounted for before. - - -punch_ identifiers printed -1 instead of the correct solution - number for batch-reaction calculations. - - -high_precision is no longer reset to false with every - SELECTED_OUTPUT data block. - - SELECTED_OUTPUT file name stored for use by PhreeqcI. - - Alkalinity for NH3 corrected to 1.0 in llnl.dat. - - Fixed bug with USER_PRINT of kinetics. Did not find correct - kinetics information in some cases. - - Fixed bug in default values for SOLUTION_SPREAD. Cannot use phase - name and SI for pH or pe, and bug did not allow PHREEQC - to run. Now PHREEQC runs, but warns that this is not - allowed. - ------------------------------------------------------------- -Version 2.3: Date: Tue January 2, 2001 ------------------------------------------------------------- - - Added new keyword DATABASE. It must be the first keyword in - the input file. The character string following the - keyword is the pathname for the database file to - be used in the calculation. The file that is - specified takes precedence over any default - database name, including environmental variable - PHREEQC_DATABASE and command line arguments. - - Fixed bug in SOLUTION_SPREAD. If first heading in - the spread-sheet input was an identifier--pH, - pe, units, etc--then the headings were interpreted - as an identifier and bad things happened. - - Added new keyword to make aqueous model similar to - LLNL and Geochemists Workbench when using - llnl.dat as the database file. Values - of Debye-Huckel a and b and bdot (ionic strength - coefficient) are read at fixed temperatures. - Linear interpolation occurs between temperatures. - - New options for SOLUTION_SPECIES are - -llnl_gamma a , where a is the ion-size parameter. - -co2_llnl_gamma , indicates the temperature dependent - function for the bdot term given in - -co2_coefs of LLNL_AQUEOUS_MODEL_PARAMETERS - will be used. Applies to uncharged - species only. - -LLNL_AQUEOUS_MODEL_PARAMETERS --temperatures - 0.0100 25.0000 60.0000 100.0000 - 150.0000 200.0000 250.0000 300.0000 -#debye huckel a (adh) --dh_a - 0.4939 0.5114 0.5465 0.5995 - 0.6855 0.7994 0.9593 1.2180 -#debye huckel b (bdh) --dh_b - 0.3253 0.3288 0.3346 0.3421 - 0.3525 0.3639 0.3766 0.3925 --bdot - 0.0394 0.0410 0.0438 0.0460 - 0.0470 0.0470 0.0340 0.0000 -#cco2 (coefficients for the Drummond (1981) polynomial) --co2_coefs - -1.0312 0.0012806 - 255.9 0.4445 - -0.001606 - - - Fixed bug in basic interpreter. A number like "..524" would - cause an infinite loop. - - Added function SURF to Basic. - SURF("element", "surface") gives the amount of - element sorbed on "surface". "surface" - should be the surface name, not the - surface-site name (that is, no underscore). - - Fixed option to "runge_kutta" from "runge-kutta" to match - documentation for KINETICS. - - Fixed UO2+2 and Mn+2 reaction stoichiometry for Hfo surface complexation - in wateq4f.dat. - - Added option for an equilibrium-phase to dissolve only. - "dis" is added at the end of a line defining an equilibrium- - phase. No data fields may be omitted. Should not - be used when adding an alternative reaction. - Example: - EQUILIBRIUM_PHASES - Dolomite 0.0 0.001 dis - R-K integration failed when only the final rate generated - negative concentrations. - Allow decimals in definition of secondary master species, for - example S(0.3). - Fixed bug if description was more than about 85 characters; - now allows about 400 characters. - Fixed bug for surface/exchange sites related to phases. Was - checking internal copies of surfaces/exchange with negative - numbers. - Fixed bug in quick prep that did not set the correct pointer - for gas phases. - Fixed segmentation fault that occurred if all elements for - phase-boundary mineral were not in the solution. - Only applied to a phase used to define concentration - in an initial solution calculation. - Added option to eliminate echo of input file in PRINT - data block. -echo_input T/F turns echoing on - and off. Default is on. - - ------------------------------------------------------------- -Release 2.2: Date: Wed March 1, 2000 ------------------------------------------------------------- - - Fixed bug in MIX if no solutions are defined. - Changed printout for surface. - Only gives net surface charge for diffuse layer - calculation. - Prints correct value for the surface charge and - surface charge density for diffuse-layer - calculation. - - Added function EDL to Basic. - EDL("element", "surface") gives the amount of - element in the diffuse layer for "surface". - not including sorbed species. "surface" should - be the surface name, not the surface-site name - (that is, no underscore). - - Special values for "element" include: - "charge" - gives surface charge, equivalents. - "sigma" - surface charge density, C/m**2. - "psi" - potential at the surface, Volts. - "water" - mass of water in the diffuse layer, kg. - Changed distribution to be more consistent with other USGS - water-resources applications. - ------------------------------------------------------------- -Release 2.1: Date: Wed January 19, 2000 ------------------------------------------------------------- - - Added additional #ifdef's for PhreeqcI. - Fixed problem with formats for USER_PUNCH and - others with Microsoft C++ 3 digit - exponents. - -Initial Release 2.0: Date: Wed December 15, 1999 - -Version: C_54 = Version 2.0 - diff --git a/phreeqc/structures.cpp b/phreeqc/structures.cpp index d2cfc935..70f19eed 100644 --- a/phreeqc/structures.cpp +++ b/phreeqc/structures.cpp @@ -27,6 +27,11 @@ clean_up(void) int i, j; #if defined MULTICHART chart_handler.End_timer(); + // Wait for charts to end + while (0 != this->chart_handler.Get_active_charts()) + { + System::Threading::Thread::Sleep(60); + } #endif description_x = (char *) free_check_null(description_x); From a42ef3aa720ca268116724386bb2dc03bb22b317 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 22 Dec 2012 07:18:28 +0000 Subject: [PATCH 0601/1077] updated for COM git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7253 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h | 24 ++++++------------------ phreeqc/print.cpp | 1 - 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/phreeqc/Form1.h b/phreeqc/Form1.h index 3c7e030d..7d238d5e 100644 --- a/phreeqc/Form1.h +++ b/phreeqc/Form1.h @@ -1,7 +1,6 @@ #pragma once #include #include -#define P_INSTANCE_POINTER1 phreeqc_ptr-> namespace zdg_ui2 { using namespace System; @@ -31,22 +30,11 @@ namespace zdg_ui2 { public ref class Form1 : public System::Windows::Forms::Form { public: long int tickStart; - public: Form1 ^myForm; - public: Form1() - { - InitializeComponent(); - col_use = 0; - symbol_use = 0; - Y2 = false; - phreeqc_done = false; - background = true; - hints = true; - grid = true; - } public: Form1(ChartObject *ptr) { this->chartobject_ptr = ptr; this->phreeqc_ptr = chartobject_ptr->Get_phreeqc(); + this->phreeqc_ptr->Get_chart_handler().Increment_active_charts(); InitializeComponent(); col_use = 0; symbol_use = 0; @@ -84,7 +72,7 @@ namespace zdg_ui2 { chart->Set_done(true); System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); } - phreeqc_ptr->Get_chart_handler().Decrement_active_charts(); + this->phreeqc_ptr->Get_chart_handler().Decrement_active_charts(); this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; } @@ -110,7 +98,7 @@ namespace zdg_ui2 { if (LogX && chart->Get_axis_scale_x()[4] == 10.0 && Curves[i]->Get_x()[i2] <= 0) { - P_INSTANCE_POINTER1 warning_msg("Obtained x_value <= 0, removing point..."); + this->phreeqc_ptr->warning_msg("Obtained x_value <= 0, removing point..."); //axis_scale_x[4] = NA; /* if reverting to linear... */ //LogX = false; return true; @@ -121,14 +109,14 @@ namespace zdg_ui2 { { if (Curves[i]->Get_y_axis() == 2 && LogY2) { - P_INSTANCE_POINTER1 warning_msg("Obtained sy_value <= 0, removing point......"); + this->phreeqc_ptr->warning_msg("Obtained sy_value <= 0, removing point......"); //axis_scale_y2[4] = NA; //LogY2 = false; return true; } else if (LogY) { - P_INSTANCE_POINTER1 warning_msg("Obtained y_value <= 0, removing point......"); + this->phreeqc_ptr->warning_msg("Obtained y_value <= 0, removing point......"); //axis_scale_y[4] = NA; //LogY = false; return true; @@ -553,7 +541,7 @@ namespace zdg_ui2 { { if (this->chartobject_ptr != NULL) { - P_INSTANCE_POINTER1 error_msg(estring.c_str(), CONTINUE); + this->phreeqc_ptr->error_msg(estring.c_str(), CONTINUE); } else { diff --git a/phreeqc/print.cpp b/phreeqc/print.cpp index 87d0f277..5259fc40 100644 --- a/phreeqc/print.cpp +++ b/phreeqc/print.cpp @@ -3340,7 +3340,6 @@ punch_user_graph(void) if (chart->Get_FirstCallToUSER_GRAPH()) { chart->start_chart(); - chart_handler.Increment_active_charts(); } chart->Set_new_ug(false); From 2832b3ad718583fb3261f29f74a53c778c7d6a8a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 31 Dec 2012 16:21:17 +0000 Subject: [PATCH 0602/1077] Flushing error file. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7262 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 13 +++++++++- phreeqc/mainsubs.cpp | 62 +++++++++++++++++++++++--------------------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index efa759fe..c32a2995 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -155,7 +155,14 @@ ChartHandler::End_timer() size_t max_tries = 6000; // 1 h, but not used std::map::iterator it = this->chart_map.begin(); - if (chart_map.size() > 0) screen_msg("Detaching charts...");; + if (chart_map.size() > 0) + { + screen_msg("Detaching charts..."); + if (io != NULL) + { + io->error_flush(); + } + } size_t i(0), i2(0); for ( ; it != chart_map.end(); it++) { @@ -195,6 +202,10 @@ ChartHandler::End_timer() if (chart_map.size() > 0) { screen_msg("\rCharts detached. \n"); + if (io != NULL) + { + io->error_flush(); + } } this->timer = false; diff --git a/phreeqc/mainsubs.cpp b/phreeqc/mainsubs.cpp index 2a7fe05a..3039143d 100644 --- a/phreeqc/mainsubs.cpp +++ b/phreeqc/mainsubs.cpp @@ -350,7 +350,7 @@ initialize(void) if (user_punch_headings == NULL) malloc_error(); user_punch_count_headings = 0; -#if defined PHREEQ98 +#if defined PHREEQ98 /* * user_graph */ @@ -492,7 +492,7 @@ initialize(void) sizeof(struct isotope_alpha *)); hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); - /* + /* * define constant named log_k */ strcpy(token, "XconstantX"); @@ -897,7 +897,7 @@ initialize(void) if (user_punch_headings == NULL) malloc_error(); user_punch_count_headings = 0; -#if defined PHREEQ98 +#if defined PHREEQ98 /* * user_graph */ @@ -982,7 +982,7 @@ initialize(void) sizeof(struct isotope_alpha *)); hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); - /* + /* * define constant named log_k */ strcpy(token, "XconstantX"); @@ -1027,9 +1027,9 @@ set_use(void) /* ---------------------------------------------------------------------- */ { /* - * Structure "use" has list of solution, ex, surf, pp_assemblage, - * gas_phase and solid solution to use in current calculations, - * also mix, irrev, and temp. + * Structure "use" has list of solution, ex, surf, pp_assemblage, + * gas_phase and solid solution to use in current calculations, + * also mix, irrev, and temp. * This routine searches for the user numbers in each list * (solution, ex, ...) and sets a pointer in structure use */ @@ -1375,7 +1375,7 @@ initial_exchangers(int print) { /* * Go through list of exchangers, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a + * for any marked "new" that are defined to be in equilibrium with a * solution. */ int i, converge, converge1; @@ -1461,7 +1461,7 @@ initial_gas_phases(int print) { /* * Go through list of gas_phases, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a + * for any marked "new" that are defined to be in equilibrium with a * solution. */ int converge, converge1; @@ -1511,7 +1511,7 @@ initial_gas_phases(int print) dup_print(token, FALSE); } - /* Try to obtain a solution pointer */ + /* Try to obtain a solution pointer */ use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, gas_phase_ptr->Get_n_solution())); prep(); k_temp(use.Get_solution_ptr()->Get_tc(), use.Get_solution_ptr()->Get_patm()); @@ -1557,7 +1557,7 @@ initial_gas_phases(int print) } if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->Get_patm()) > 5) { - sprintf(token, + sprintf(token, "WARNING: While initializing gas phase composition by equilibrating:\n%s (%.2f atm) %s (%.2f atm).\n%s.", " Gas phase pressure", (double) gas_phase_ptr->Get_total_p(), @@ -1587,7 +1587,7 @@ initial_surfaces(int print) { /* * Go through list of surfaces, make initial calculations - * for any marked "new" that are defined to be in equilibrium with a + * for any marked "new" that are defined to be in equilibrium with a * solution. */ int last, n_user, print1; @@ -1715,7 +1715,7 @@ reactions(void) * save data for saving solutions */ memcpy(&save_data, &save, sizeof(struct save)); - /* + /* *Copy everything to -2 */ copy_use(-2); @@ -1795,7 +1795,7 @@ saver(void) { /* * Save results of calcuations (data in variables with _x, - * in unknown structure x, in master, or s) into structure + * in unknown structure x, in master, or s) into structure * arrays. Structure "save" has info on whether to save * data for each entity (solution, ex, surf, pp, gas, or s_s). * Initial calculation may be saved into multiple "n_user" @@ -1881,7 +1881,7 @@ xexchange_save(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save exchanger assemblage into structure exchange with user + * Save exchanger assemblage into structure exchange with user * number n_user. */ int i, j; @@ -1958,7 +1958,7 @@ xexchange_save(int n_user) /* * Finish up */ - Rxn_exchange_map[n_user] = temp_exchange; + Rxn_exchange_map[n_user] = temp_exchange; use.Set_exchange_ptr(NULL); return (OK); @@ -1969,7 +1969,7 @@ xgas_save(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save gas composition into structure gas_phase with user + * Save gas composition into structure gas_phase with user * number n_user. */ char token[MAX_LENGTH]; @@ -2010,7 +2010,7 @@ xss_assemblage_save(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save ss_assemblage composition into structure ss_assemblage with user + * Save ss_assemblage composition into structure ss_assemblage with user * number n_user. */ cxxSSassemblage temp_ss_assemblage; @@ -2053,7 +2053,7 @@ xpp_assemblage_save(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save pure_phase assemblage into instance of cxxPPassemblage with user + * Save pure_phase assemblage into instance of cxxPPassemblage with user * number n_user. */ std::string token; @@ -2225,7 +2225,7 @@ xsolution_save(int n_user) } } /* - * Save solution + * Save solution */ Rxn_solution_map[n_user] = temp_solution; return (OK); @@ -2236,7 +2236,7 @@ xsurface_save(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save surface data into structure surface with user + * Save surface data into structure surface with user * number n_user. */ LDBLE charge; @@ -2501,7 +2501,7 @@ step_save_exch(int n_user) /* ---------------------------------------------------------------------- */ { /* - * Save exchange composition + * Save exchange composition * * input: n_user is user exchange number of target */ @@ -2549,7 +2549,7 @@ step_save_exch(int n_user) } } } - + Rxn_exchange_map[n_user] = temp_exchange; return (OK); } @@ -2710,7 +2710,7 @@ copy_entities(void) { for (i = copy_mix.start[j]; i <= copy_mix.end[j]; i++) { - if (i != copy_mix.n_user[j]) + if (i != copy_mix.n_user[j]) { Utilities::Rxn_copy(Rxn_mix_map, copy_mix.n_user[j], i); } @@ -2726,7 +2726,7 @@ copy_entities(void) } } } - + if (copy_exchange.count > 0) { for (j = 0; j < copy_exchange.count; j++) @@ -2783,7 +2783,7 @@ copy_entities(void) { for (i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++) { - if (i != copy_temperature.n_user[j]) + if (i != copy_temperature.n_user[j]) { Utilities::Rxn_copy(Rxn_temperature_map, copy_temperature.n_user[j], i); } @@ -2807,7 +2807,7 @@ copy_entities(void) { for (i = copy_pressure.start[j]; i <= copy_pressure.end[j]; i++) { - if (i != copy_pressure.n_user[j]) + if (i != copy_pressure.n_user[j]) { Utilities::Rxn_copy(Rxn_pressure_map, copy_pressure.n_user[j], i); } @@ -2959,7 +2959,7 @@ run_simulations(void) for (simulation = 1;; simulation++) { -#if defined PHREEQ98 +#if defined PHREEQ98 AddSeries = !connect_simulations; #endif @@ -3064,11 +3064,12 @@ run_simulations(void) * End of simulation */ dup_print("End of simulation.", TRUE); + output_flush(); + error_flush(); #ifdef PHREEQ98 } /* if (!phreeq98_debug) */ #endif } - } catch (PhreeqcStop e) { @@ -3117,6 +3118,9 @@ do_status(void) LDBLE ext = (double) clock() / CLOCKS_PER_SEC; dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE); screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext)); +// appt this gives output when the charts are active... + phrq_io->output_flush(); + phrq_io->error_flush(); } catch (PhreeqcStop e) { From b1241f43d303d772bd83674e793f7ce4b8bac6c4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Jan 2013 17:48:28 +0000 Subject: [PATCH 0603/1077] check exp for isfinite git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7293 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index a1ef8016..65ff956e 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -2348,10 +2348,36 @@ molalities(int allow_overflow) if (s_x[i]->type == EX) { s_x[i]->moles = exp(s_x[i]->lm * LOG_10); + if (!isfinite(s_x[i]->moles)) + { + if (s_x[i]->lm < 0.0) + { + s_x[i]->moles = 1e-200; + fprintf(stderr, "ExchNaN-\n"); + } + else + { + s_x[i]->moles = 1e200; + fprintf(stderr, "ExchNaN+\n"); + } + } } else if (s_x[i]->type == SURF) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); /* formerly * mass water */ + s_x[i]->moles = exp(s_x[i]->lm * LOG_10); + if (!isfinite(s_x[i]->moles)) + { + if (s_x[i]->lm < 0.0) + { + s_x[i]->moles = 1e-200; + fprintf(stderr, "SurfNaN-\n"); + } + else + { + s_x[i]->moles = 1e200; + fprintf(stderr, "SurfNaN+\n"); + } + } } else { From 0daf341ef0ce81d4d12bc6cf1acd259fbd8d9d53 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Jan 2013 17:54:58 +0000 Subject: [PATCH 0604/1077] Use PHR_ISFINITE git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7294 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 65ff956e..9f616d8a 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -2348,7 +2348,7 @@ molalities(int allow_overflow) if (s_x[i]->type == EX) { s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!isfinite(s_x[i]->moles)) + if (!PHR_ISFINITE(s_x[i]->moles)) { if (s_x[i]->lm < 0.0) { @@ -2365,7 +2365,7 @@ molalities(int allow_overflow) else if (s_x[i]->type == SURF) { s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!isfinite(s_x[i]->moles)) + if (!PHR_ISFINITE(s_x[i]->moles)) { if (s_x[i]->lm < 0.0) { From 564a0f8af55b6c9be5b2596b5d91fa948f6b4d6c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 10 Jan 2013 06:04:12 +0000 Subject: [PATCH 0605/1077] moved phreeqc files into src git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7308 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/Form1.h => Form1.h | 0 phreeqc/Form1.resX => Form1.resX | 0 phreeqc/NA.h => NA.h | 0 .../PHRQ_io_output.cpp => PHRQ_io_output.cpp | 0 phreeqc/ZedGraph.dll => ZedGraph.dll | Bin phreeqc/advection.cpp => advection.cpp | 0 phreeqc/basicsubs.cpp => basicsubs.cpp | 0 phreeqc/chart_icon.gif => chart_icon.gif | Bin phreeqc/cl1.cpp => cl1.cpp | 0 phreeqc/cl1mp.cpp => cl1mp.cpp | 0 phreeqc/cvdense.cpp => cvdense.cpp | 0 phreeqc/cvdense.h => cvdense.h | 0 phreeqc/cvode.cpp => cvode.cpp | 0 phreeqc/cvode.h => cvode.h | 0 phreeqc/dense.cpp => dense.cpp | 0 phreeqc/dense.h => dense.h | 0 phreeqc/distribution.mk => distribution.mk | 0 phreeqc/dw.cpp => dw.cpp | 0 phreeqc/gases.cpp => gases.cpp | 0 ...global_structures.h => global_structures.h | 0 phreeqc/input.cpp => input.cpp | 0 phreeqc/integrate.cpp => integrate.cpp | 0 phreeqc/inverse.cpp => inverse.cpp | 0 phreeqc/isotopes.cpp => isotopes.cpp | 0 phreeqc/kinetics.cpp => kinetics.cpp | 0 phreeqc/mainsubs.cpp => mainsubs.cpp | 0 phreeqc/model.cpp => model.cpp | 0 phreeqc/newiso.dat => newiso.dat | 0 phreeqc/nvector.cpp => nvector.cpp | 0 phreeqc/nvector.h => nvector.h | 0 .../nvector_serial.cpp => nvector_serial.cpp | 0 phreeqc/nvector_serial.h => nvector_serial.h | 0 phreeqc/parse.cpp => parse.cpp | 0 phreeqc/phqalloc.cpp => phqalloc.cpp | 0 phreeqc/phqalloc.h => phqalloc.h | 0 phreeqc/Makefile => phreeqc.Makefile | 0 ...hecklist => phreeqc.distribution.checklist | 0 phreeqc/phreeqc.rev | 4579 ----------------- phreeqc/phreex.ico => phreex.ico | Bin phreeqc/phrqtype.h => phrqtype.h | 0 phreeqc/pitzer.cpp => pitzer.cpp | 0 ...er_structures.cpp => pitzer_structures.cpp | 0 phreeqc/prep.cpp => prep.cpp | 0 phreeqc/print.cpp => print.cpp | 0 phreeqc/read.cpp => read.cpp | 0 phreeqc/readtr.cpp => readtr.cpp | 0 phreeqc/sit.cpp => sit.cpp | 0 phreeqc/smalldense.cpp => smalldense.cpp | 0 phreeqc/smalldense.h => smalldense.h | 0 phreeqc/spread.cpp => spread.cpp | 0 phreeqc/step.cpp => step.cpp | 0 phreeqc/structures.cpp => structures.cpp | 0 phreeqc/sundialsmath.cpp => sundialsmath.cpp | 0 phreeqc/sundialsmath.h => sundialsmath.h | 0 phreeqc/sundialstypes.h => sundialstypes.h | 0 phreeqc/tally.cpp => tally.cpp | 0 phreeqc/tidy.cpp => tidy.cpp | 0 phreeqc/transport.cpp => transport.cpp | 0 phreeqc/utilities.cpp => utilities.cpp | 0 59 files changed, 4579 deletions(-) rename phreeqc/Form1.h => Form1.h (100%) rename phreeqc/Form1.resX => Form1.resX (100%) rename phreeqc/NA.h => NA.h (100%) rename phreeqc/PHRQ_io_output.cpp => PHRQ_io_output.cpp (100%) rename phreeqc/ZedGraph.dll => ZedGraph.dll (100%) rename phreeqc/advection.cpp => advection.cpp (100%) rename phreeqc/basicsubs.cpp => basicsubs.cpp (100%) rename phreeqc/chart_icon.gif => chart_icon.gif (100%) rename phreeqc/cl1.cpp => cl1.cpp (100%) rename phreeqc/cl1mp.cpp => cl1mp.cpp (100%) rename phreeqc/cvdense.cpp => cvdense.cpp (100%) rename phreeqc/cvdense.h => cvdense.h (100%) rename phreeqc/cvode.cpp => cvode.cpp (100%) rename phreeqc/cvode.h => cvode.h (100%) rename phreeqc/dense.cpp => dense.cpp (100%) rename phreeqc/dense.h => dense.h (100%) rename phreeqc/distribution.mk => distribution.mk (100%) rename phreeqc/dw.cpp => dw.cpp (100%) rename phreeqc/gases.cpp => gases.cpp (100%) rename phreeqc/global_structures.h => global_structures.h (100%) rename phreeqc/input.cpp => input.cpp (100%) rename phreeqc/integrate.cpp => integrate.cpp (100%) rename phreeqc/inverse.cpp => inverse.cpp (100%) rename phreeqc/isotopes.cpp => isotopes.cpp (100%) rename phreeqc/kinetics.cpp => kinetics.cpp (100%) rename phreeqc/mainsubs.cpp => mainsubs.cpp (100%) rename phreeqc/model.cpp => model.cpp (100%) rename phreeqc/newiso.dat => newiso.dat (100%) rename phreeqc/nvector.cpp => nvector.cpp (100%) rename phreeqc/nvector.h => nvector.h (100%) rename phreeqc/nvector_serial.cpp => nvector_serial.cpp (100%) rename phreeqc/nvector_serial.h => nvector_serial.h (100%) rename phreeqc/parse.cpp => parse.cpp (100%) rename phreeqc/phqalloc.cpp => phqalloc.cpp (100%) rename phreeqc/phqalloc.h => phqalloc.h (100%) rename phreeqc/Makefile => phreeqc.Makefile (100%) rename phreeqc/distribution.checklist => phreeqc.distribution.checklist (100%) delete mode 100644 phreeqc/phreeqc.rev rename phreeqc/phreex.ico => phreex.ico (100%) rename phreeqc/phrqtype.h => phrqtype.h (100%) rename phreeqc/pitzer.cpp => pitzer.cpp (100%) rename phreeqc/pitzer_structures.cpp => pitzer_structures.cpp (100%) rename phreeqc/prep.cpp => prep.cpp (100%) rename phreeqc/print.cpp => print.cpp (100%) rename phreeqc/read.cpp => read.cpp (100%) rename phreeqc/readtr.cpp => readtr.cpp (100%) rename phreeqc/sit.cpp => sit.cpp (100%) rename phreeqc/smalldense.cpp => smalldense.cpp (100%) rename phreeqc/smalldense.h => smalldense.h (100%) rename phreeqc/spread.cpp => spread.cpp (100%) rename phreeqc/step.cpp => step.cpp (100%) rename phreeqc/structures.cpp => structures.cpp (100%) rename phreeqc/sundialsmath.cpp => sundialsmath.cpp (100%) rename phreeqc/sundialsmath.h => sundialsmath.h (100%) rename phreeqc/sundialstypes.h => sundialstypes.h (100%) rename phreeqc/tally.cpp => tally.cpp (100%) rename phreeqc/tidy.cpp => tidy.cpp (100%) rename phreeqc/transport.cpp => transport.cpp (100%) rename phreeqc/utilities.cpp => utilities.cpp (100%) diff --git a/phreeqc/Form1.h b/Form1.h similarity index 100% rename from phreeqc/Form1.h rename to Form1.h diff --git a/phreeqc/Form1.resX b/Form1.resX similarity index 100% rename from phreeqc/Form1.resX rename to Form1.resX diff --git a/phreeqc/NA.h b/NA.h similarity index 100% rename from phreeqc/NA.h rename to NA.h diff --git a/phreeqc/PHRQ_io_output.cpp b/PHRQ_io_output.cpp similarity index 100% rename from phreeqc/PHRQ_io_output.cpp rename to PHRQ_io_output.cpp diff --git a/phreeqc/ZedGraph.dll b/ZedGraph.dll similarity index 100% rename from phreeqc/ZedGraph.dll rename to ZedGraph.dll diff --git a/phreeqc/advection.cpp b/advection.cpp similarity index 100% rename from phreeqc/advection.cpp rename to advection.cpp diff --git a/phreeqc/basicsubs.cpp b/basicsubs.cpp similarity index 100% rename from phreeqc/basicsubs.cpp rename to basicsubs.cpp diff --git a/phreeqc/chart_icon.gif b/chart_icon.gif similarity index 100% rename from phreeqc/chart_icon.gif rename to chart_icon.gif diff --git a/phreeqc/cl1.cpp b/cl1.cpp similarity index 100% rename from phreeqc/cl1.cpp rename to cl1.cpp diff --git a/phreeqc/cl1mp.cpp b/cl1mp.cpp similarity index 100% rename from phreeqc/cl1mp.cpp rename to cl1mp.cpp diff --git a/phreeqc/cvdense.cpp b/cvdense.cpp similarity index 100% rename from phreeqc/cvdense.cpp rename to cvdense.cpp diff --git a/phreeqc/cvdense.h b/cvdense.h similarity index 100% rename from phreeqc/cvdense.h rename to cvdense.h diff --git a/phreeqc/cvode.cpp b/cvode.cpp similarity index 100% rename from phreeqc/cvode.cpp rename to cvode.cpp diff --git a/phreeqc/cvode.h b/cvode.h similarity index 100% rename from phreeqc/cvode.h rename to cvode.h diff --git a/phreeqc/dense.cpp b/dense.cpp similarity index 100% rename from phreeqc/dense.cpp rename to dense.cpp diff --git a/phreeqc/dense.h b/dense.h similarity index 100% rename from phreeqc/dense.h rename to dense.h diff --git a/phreeqc/distribution.mk b/distribution.mk similarity index 100% rename from phreeqc/distribution.mk rename to distribution.mk diff --git a/phreeqc/dw.cpp b/dw.cpp similarity index 100% rename from phreeqc/dw.cpp rename to dw.cpp diff --git a/phreeqc/gases.cpp b/gases.cpp similarity index 100% rename from phreeqc/gases.cpp rename to gases.cpp diff --git a/phreeqc/global_structures.h b/global_structures.h similarity index 100% rename from phreeqc/global_structures.h rename to global_structures.h diff --git a/phreeqc/input.cpp b/input.cpp similarity index 100% rename from phreeqc/input.cpp rename to input.cpp diff --git a/phreeqc/integrate.cpp b/integrate.cpp similarity index 100% rename from phreeqc/integrate.cpp rename to integrate.cpp diff --git a/phreeqc/inverse.cpp b/inverse.cpp similarity index 100% rename from phreeqc/inverse.cpp rename to inverse.cpp diff --git a/phreeqc/isotopes.cpp b/isotopes.cpp similarity index 100% rename from phreeqc/isotopes.cpp rename to isotopes.cpp diff --git a/phreeqc/kinetics.cpp b/kinetics.cpp similarity index 100% rename from phreeqc/kinetics.cpp rename to kinetics.cpp diff --git a/phreeqc/mainsubs.cpp b/mainsubs.cpp similarity index 100% rename from phreeqc/mainsubs.cpp rename to mainsubs.cpp diff --git a/phreeqc/model.cpp b/model.cpp similarity index 100% rename from phreeqc/model.cpp rename to model.cpp diff --git a/phreeqc/newiso.dat b/newiso.dat similarity index 100% rename from phreeqc/newiso.dat rename to newiso.dat diff --git a/phreeqc/nvector.cpp b/nvector.cpp similarity index 100% rename from phreeqc/nvector.cpp rename to nvector.cpp diff --git a/phreeqc/nvector.h b/nvector.h similarity index 100% rename from phreeqc/nvector.h rename to nvector.h diff --git a/phreeqc/nvector_serial.cpp b/nvector_serial.cpp similarity index 100% rename from phreeqc/nvector_serial.cpp rename to nvector_serial.cpp diff --git a/phreeqc/nvector_serial.h b/nvector_serial.h similarity index 100% rename from phreeqc/nvector_serial.h rename to nvector_serial.h diff --git a/phreeqc/parse.cpp b/parse.cpp similarity index 100% rename from phreeqc/parse.cpp rename to parse.cpp diff --git a/phreeqc/phqalloc.cpp b/phqalloc.cpp similarity index 100% rename from phreeqc/phqalloc.cpp rename to phqalloc.cpp diff --git a/phreeqc/phqalloc.h b/phqalloc.h similarity index 100% rename from phreeqc/phqalloc.h rename to phqalloc.h diff --git a/phreeqc/Makefile b/phreeqc.Makefile similarity index 100% rename from phreeqc/Makefile rename to phreeqc.Makefile diff --git a/phreeqc/distribution.checklist b/phreeqc.distribution.checklist similarity index 100% rename from phreeqc/distribution.checklist rename to phreeqc.distribution.checklist diff --git a/phreeqc/phreeqc.rev b/phreeqc/phreeqc.rev deleted file mode 100644 index 8dc8253f..00000000 --- a/phreeqc/phreeqc.rev +++ /dev/null @@ -1,4579 +0,0 @@ - -RCS file: RCS/README.TXT,v -Working file: README.TXT -head: 1.17 -branch: -locks: strict -access list: -symbolic names: -keyword substitution: kv -total revisions: 17 -============================================================================= - -RCS file: RCS/NOTICE.TXT,v -Working file: NOTICE.TXT -head: 1.1 -branch: -locks: strict -access list: -symbolic names: -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: RCS/RELEASE.TXT,v -Working file: RELEASE.TXT -head: 1.16 -branch: -locks: strict - dlpark: 1.16 -access list: -symbolic names: -keyword substitution: kv -total revisions: 16 -============================================================================= - -RCS file: src/RCS/Makefile,v -Working file: src/Makefile -head: 1.35 -branch: -locks: strict -access list: -symbolic names: - C_260: 1.33 - C_259: 1.33 - C_258: 1.33 - C_257: 1.31 - C_256: 1.31 - C_255: 1.31 - C_254: 1.30 - C_253: 1.26 - C_252: 1.25 - C_251: 1.25 - C_250: 1.25 - C_249: 1.24 - C_248: 1.24 - C_247: 1.24 - C_246: 1.24 - C_245: 1.24 - C_244: 1.24 - C_243: 1.24 - C_242: 1.23 - C_241: 1.22 - C_240: 1.22 - C_239: 1.22 - C_238: 1.22 - C_237: 1.22 - C_236: 1.22 - C_235: 1.22 - C_234: 1.22 - C_233: 1.22 - C_232: 1.22 - C_231: 1.22 - C_230: 1.22 - C_229: 1.22 - C_227: 1.22 - C_226: 1.22 - C_225: 1.22 - C_224: 1.22 - C_222: 1.21 - C_221: 1.21 - C_220: 1.21 - C_219: 1.21 - C_218: 1.21 - RC1: 1.20 - C_216: 1.20 - C_215: 1.20 - C_214: 1.20 - C_213: 1.20 - C_212: 1.20 - C_206: 1.18 - C_205_3: 1.15 - C_205_2: 1.15 - C_205_1: 1.15 - C_205: 1.15 - C_204_2: 1.14 - C_204_1: 1.14 - C_204: 1.14 - C_202: 1.10 - C_201: 1.5 - C_200: 1.5 -keyword substitution: kv -total revisions: 35 -============================================================================= - -RCS file: src/RCS/advection.c,v -Working file: src/advection.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.5 - C_246: 2.5 - C_245: 2.5 - C_244: 2.5 - C_243: 2.5 - C_242: 2.4 - C_241: 2.4 - C_240: 2.4 - C_239: 2.4 - C_238: 2.3 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/basic.c,v -Working file: src/basic.c -head: 2.44 -branch: -locks: strict - dlpark: 2.44 -access list: -symbolic names: - C_260: 2.44 - C_259: 2.44 - C_258: 2.44 - C_257: 2.44 - C_256: 2.43 - C_255: 2.43 - C_254: 2.43 - C_253: 2.42 - C_252: 2.42 - C_251: 2.42 - C_250: 2.42 - C_249: 2.41 - C_248: 2.41 - C_247: 2.41 - C_246: 2.41 - C_245: 2.41 - C_244: 2.41 - C_243: 2.41 - C_242: 2.39 - C_241: 2.39 - C_240: 2.39 - C_239: 2.39 - C_238: 2.38 - C_237: 2.37 - C_236: 2.37 - C_235: 2.37 - C_234: 2.37 - C_233: 2.36 - C_232: 2.34 - C_231: 2.33 - C_230: 2.30 - C_229: 2.30 - C_227: 2.30 - C_226: 2.30 - C_225: 2.30 - C_224: 2.30 - C_222: 2.30 - C_221: 2.20 - C_220: 2.20 - C_219: 2.19 - C_218: 2.19 - RC1: 2.19 - C_216: 2.19 - C_215: 2.18 - C_214: 2.17 - C_213: 2.17 - C_212: 2.16 - C_206: 2.16 - C_205_3: 2.14 - C_205_2: 2.14 - C_205_1: 2.13 - C_205: 2.11 - C_204_2: 2.11 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.10 - C_202_1: 2.10 - C_202: 2.6 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 45 -============================================================================= - -RCS file: src/RCS/basicsubs.c,v -Working file: src/basicsubs.c -head: 2.18 -branch: -locks: strict - dlpark: 2.18 -access list: -symbolic names: - C_260: 2.18 - C_259: 2.18 - C_258: 2.18 - C_257: 2.18 - C_256: 2.17 - C_255: 2.17 - C_254: 2.17 - C_253: 2.16 - C_252: 2.16 - C_251: 2.15 - C_250: 2.15 - C_249: 2.14 - C_248: 2.14 - C_247: 2.14 - C_246: 2.14 - C_245: 2.14 - C_244: 2.14 - C_243: 2.14 - C_242: 2.13 - C_241: 2.13 - C_240: 2.13 - C_239: 2.13 - C_238: 2.12 - C_237: 2.12 - C_236: 2.12 - C_235: 2.12 - C_234: 2.12 - C_233: 2.11 - C_232: 2.9 - C_231: 2.9 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.6 - C_222: 2.6 - C_221: 2.6 - C_220: 2.6 - C_219: 2.6 - C_218: 2.6 - RC1: 2.6 - C_216: 2.6 - C_215: 2.6 - C_214: 2.5 - C_213: 2.4 - C_212: 2.3 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.1 - C_205_1: 2.1 -keyword substitution: kv -total revisions: 18 -============================================================================= - -RCS file: src/RCS/cl1.c,v -Working file: src/cl1.c -head: 2.7 -branch: -locks: strict - dlpark: 2.7 -access list: -symbolic names: - C_260: 2.7 - C_259: 2.7 - C_258: 2.7 - C_257: 2.6 - C_256: 2.5 - C_255: 2.5 - C_254: 2.5 - C_253: 2.5 - C_252: 2.5 - C_251: 2.5 - C_250: 2.5 - C_249: 2.4 - C_248: 2.4 - C_247: 2.4 - C_246: 2.4 - C_245: 2.4 - C_244: 2.4 - C_243: 2.4 - C_242: 2.3 - C_241: 2.3 - C_240: 2.3 - C_239: 2.2 - C_238: 2.1 - C_237: 2.1 - C_236: 2.1 - C_235: 2.1 - C_234: 2.1 - C_233: 2.1 - C_232: 2.1 - C_231: 2.1 - C_230: 2.1 - C_229: 2.1 - C_227: 2.1 - C_226: 2.1 - C_225: 2.1 - C_224: 2.1 - C_222: 2.1 - C_221: 2.1 - C_220: 2.1 - C_219: 2.1 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: src/RCS/cvdense.c,v -Working file: src/cvdense.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 - C_225: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/cvode.c,v -Working file: src/cvode.c -head: 1.10 -branch: -locks: strict -access list: -symbolic names: - C_260: 1.10 - C_259: 1.9 - C_258: 1.9 - C_257: 1.9 - C_256: 1.8 - C_255: 1.8 - C_254: 1.8 - C_253: 1.8 - C_252: 1.8 - C_251: 1.8 - C_250: 1.7 - C_249: 1.6 - C_248: 1.6 - C_247: 1.6 - C_246: 1.6 - C_245: 1.6 - C_244: 1.6 - C_243: 1.6 - C_242: 1.4 - C_241: 1.4 - C_240: 1.4 - C_239: 1.4 - C_238: 1.2 - C_237: 1.2 - C_236: 1.2 - C_235: 1.2 - C_234: 1.2 - C_233: 1.2 - C_232: 1.2 - C_231: 1.2 - C_230: 1.2 - C_229: 1.2 - C_227: 1.2 - C_226: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: src/RCS/dense.c,v -Working file: src/dense.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/input.c,v -Working file: src/input.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.1 - C_254: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/integrate.c,v -Working file: src/integrate.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.4 - C_237: 2.4 - C_236: 2.4 - C_235: 2.4 - C_234: 2.4 - C_233: 2.4 - C_232: 2.4 - C_231: 2.4 - C_230: 2.4 - C_229: 2.4 - C_227: 2.4 - C_226: 2.4 - C_225: 2.4 - C_224: 2.3 - C_222: 2.3 - C_221: 2.3 - C_220: 2.3 - C_219: 2.3 - C_218: 2.3 - RC1: 2.3 - C_216: 2.3 - C_215: 2.3 - C_214: 2.3 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/inverse.c,v -Working file: src/inverse.c -head: 2.10 -branch: -locks: strict - dlpark: 2.10 -access list: -symbolic names: - C_260: 2.10 - C_259: 2.10 - C_258: 2.10 - C_257: 2.10 - C_256: 2.9 - C_255: 2.9 - C_254: 2.9 - C_253: 2.8 - C_252: 2.8 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.4 - C_241: 2.4 - C_240: 2.4 - C_239: 2.4 - C_238: 2.3 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.1 - C_206: 2.1 - C_205_3: 2.1 - C_205_2: 2.1 - C_205_1: 2.1 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: src/RCS/isotopes.c,v -Working file: src/isotopes.c -head: 2.12 -branch: -locks: strict - dlpark: 2.12 -access list: -symbolic names: - C_260: 2.12 - C_259: 2.12 - C_258: 2.12 - C_257: 2.12 - C_256: 2.11 - C_255: 2.11 - C_254: 2.11 - C_253: 2.11 - C_252: 2.11 - C_251: 2.11 - C_250: 2.10 - C_249: 2.9 - C_248: 2.9 - C_247: 2.9 - C_246: 2.9 - C_245: 2.9 - C_244: 2.9 - C_243: 2.9 - C_242: 2.8 - C_241: 2.8 - C_240: 2.8 - C_239: 2.8 - C_238: 2.7 - C_237: 2.7 - C_236: 2.7 - C_235: 2.7 - C_234: 2.7 - C_233: 2.7 - C_232: 2.7 - C_231: 2.7 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.7 - C_222: 2.7 - C_221: 2.7 - C_220: 2.7 - C_219: 2.7 - C_218: 2.7 - RC1: 2.7 - C_216: 2.7 - C_215: 2.7 - C_214: 2.7 - C_213: 2.7 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.2 - C_205_2: 2.1 - C_205_1: 2.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: src/RCS/kinetics.c,v -Working file: src/kinetics.c -head: 2.36 -branch: -locks: strict - dlpark: 2.36 -access list: -symbolic names: - C_260: 2.36 - C_259: 2.36 - C_258: 2.36 - C_257: 2.33 - C_256: 2.32 - C_255: 2.31 - C_254: 2.31 - C_253: 2.30 - C_252: 2.30 - C_251: 2.29 - C_250: 2.29 - C_249: 2.28 - C_248: 2.28 - C_247: 2.26 - C_246: 2.26 - C_245: 2.26 - C_244: 2.26 - C_243: 2.26 - C_242: 2.24 - C_241: 2.24 - C_240: 2.24 - C_239: 2.23 - C_238: 2.22 - C_237: 2.22 - C_236: 2.22 - C_235: 2.22 - C_234: 2.21 - C_233: 2.21 - C_232: 2.21 - C_231: 2.21 - C_230: 2.21 - C_229: 2.21 - C_227: 2.21 - C_226: 2.20 - C_225: 2.19 - C_224: 2.19 - C_222: 2.19 - C_221: 2.19 - C_220: 2.19 - C_219: 2.18 - C_218: 2.17 - RC1: 2.17 - C_216: 2.17 - C_215: 2.17 - C_214: 2.17 - C_213: 2.17 - C_212: 2.16 - C_206: 2.16 - C_205_3: 2.16 - C_205_2: 2.16 - C_205_1: 2.15 - C_205: 2.11 - C_204_2: 2.7 - C_204_1: 2.7 - C_204: 2.7 - C_202_2: 2.6 - C_202_1: 2.6 - C_202: 2.4 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 37 -============================================================================= - -RCS file: src/RCS/main.c,v -Working file: src/main.c -head: 2.35 -branch: -locks: strict -access list: -symbolic names: - C_260: 2.35 - C_259: 2.34 - C_258: 2.34 - C_257: 2.34 - C_256: 2.33 - C_255: 2.33 - C_254: 2.32 - C_253: 2.31 - C_252: 2.30 - C_251: 2.30 - C_250: 2.30 - C_249: 2.29 - C_248: 2.29 - C_247: 2.29 - C_246: 2.29 - C_245: 2.29 - C_244: 2.28 - C_243: 2.28 - C_242: 2.26 - C_241: 2.25 - C_240: 2.25 - C_239: 2.25 - C_238: 2.25 - C_237: 2.24 - C_236: 2.24 - C_235: 2.24 - C_234: 2.23 - C_233: 2.23 - C_232: 2.23 - C_231: 2.23 - C_230: 2.23 - C_229: 2.23 - C_227: 2.23 - C_226: 2.23 - C_225: 2.23 - C_224: 2.23 - C_222: 2.22 - C_221: 2.22 - C_220: 2.22 - C_219: 2.22 - C_218: 2.20 - RC1: 2.19 - C_216: 2.19 - C_215: 2.18 - C_214: 2.18 - C_213: 2.18 - C_212: 2.14 - C_206: 2.14 - C_205_3: 2.13 - C_205_2: 2.13 - C_205_1: 2.13 - C_205: 2.13 - C_204_2: 2.12 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.9 - C_202_1: 2.6 - C_202: 2.4 - C_201: 2.2 - C_200: 2.1 -keyword substitution: kv -total revisions: 36 -============================================================================= - -RCS file: src/RCS/mainsubs.c,v -Working file: src/mainsubs.c -head: 2.38 -branch: -locks: strict - dlpark: 2.38 -access list: -symbolic names: - C_260: 2.38 - C_259: 2.38 - C_258: 2.38 - C_257: 2.36 - C_256: 2.35 - C_255: 2.35 - C_254: 2.34 - C_253: 2.33 - C_252: 2.33 - C_251: 2.32 - C_250: 2.32 - C_249: 2.31 - C_248: 2.31 - C_247: 2.30 - C_246: 2.30 - C_245: 2.30 - C_244: 2.30 - C_243: 2.30 - C_242: 2.28 - C_241: 2.28 - C_240: 2.28 - C_239: 2.27 - C_238: 2.25 - C_237: 2.24 - C_236: 2.24 - C_235: 2.24 - C_234: 2.23 - C_233: 2.23 - C_232: 2.23 - C_231: 2.23 - C_230: 2.23 - C_229: 2.23 - C_227: 2.22 - C_226: 2.22 - C_225: 2.22 - C_224: 2.22 - C_222: 2.22 - C_221: 2.22 - C_220: 2.22 - C_219: 2.22 - C_218: 2.21 - RC1: 2.21 - C_216: 2.21 - C_215: 2.21 - C_214: 2.20 - C_213: 2.20 - C_212: 2.17 - C_206: 2.15 - C_205_3: 2.14 - C_205_2: 2.13 - C_205_1: 2.12 - C_205: 2.11 - C_204_2: 2.10 - C_204_1: 2.10 - C_204: 2.10 - C_202_2: 2.6 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 39 -============================================================================= - -RCS file: src/RCS/model.c,v -Working file: src/model.c -head: 2.27 -branch: -locks: strict - dlpark: 2.27 -access list: -symbolic names: - C_260: 2.27 - C_259: 2.27 - C_258: 2.27 - C_257: 2.26 - C_256: 2.25 - C_255: 2.25 - C_254: 2.25 - C_253: 2.24 - C_252: 2.24 - C_251: 2.24 - C_250: 2.24 - C_249: 2.23 - C_248: 2.23 - C_247: 2.22 - C_246: 2.22 - C_245: 2.22 - C_244: 2.22 - C_243: 2.22 - C_242: 2.20 - C_241: 2.19 - C_240: 2.19 - C_239: 2.19 - C_238: 2.17 - C_237: 2.17 - C_236: 2.17 - C_235: 2.17 - C_234: 2.17 - C_233: 2.16 - C_232: 2.15 - C_231: 2.15 - C_230: 2.14 - C_229: 2.14 - C_227: 2.14 - C_226: 2.14 - C_225: 2.14 - C_224: 2.14 - C_222: 2.14 - C_221: 2.14 - C_220: 2.14 - C_219: 2.14 - C_218: 2.14 - RC1: 2.13 - C_216: 2.13 - C_215: 2.13 - C_214: 2.12 - C_213: 2.12 - C_212: 2.11 - C_206: 2.11 - C_205_3: 2.11 - C_205_2: 2.11 - C_205_1: 2.10 - C_205: 2.8 - C_204_2: 2.6 - C_204_1: 2.6 - C_204: 2.6 - C_202_2: 2.5 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 28 -============================================================================= - -RCS file: src/RCS/nvector.c,v -Working file: src/nvector.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/nvector_serial.c,v -Working file: src/nvector_serial.c -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_260: 1.5 - C_259: 1.5 - C_258: 1.5 - C_257: 1.5 - C_256: 1.4 - C_255: 1.4 - C_254: 1.4 - C_253: 1.4 - C_252: 1.4 - C_251: 1.4 - C_250: 1.4 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: src/RCS/output.c,v -Working file: src/output.c -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_260: 1.2 - C_259: 1.2 - C_258: 1.2 - C_257: 1.1 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: src/RCS/p2clib.c,v -Working file: src/p2clib.c -head: 2.6 -branch: -locks: strict - dlpark: 2.6 -access list: -symbolic names: - C_260: 2.6 - C_259: 2.6 - C_258: 2.6 - C_257: 2.6 - C_256: 2.5 - C_255: 2.5 - C_254: 2.5 - C_253: 2.5 - C_252: 2.5 - C_251: 2.5 - C_250: 2.5 - C_249: 2.5 - C_248: 2.5 - C_247: 2.5 - C_246: 2.5 - C_245: 2.5 - C_244: 2.5 - C_243: 2.5 - C_242: 2.3 - C_241: 2.3 - C_240: 2.3 - C_239: 2.3 - C_238: 2.3 - C_237: 2.3 - C_236: 2.3 - C_235: 2.3 - C_234: 2.3 - C_233: 2.3 - C_232: 2.3 - C_231: 2.3 - C_230: 2.3 - C_229: 2.3 - C_227: 2.3 - C_226: 2.3 - C_225: 2.3 - C_224: 2.3 - C_222: 2.3 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.1 - C_206: 2.1 - C_205_3: 2.1 - C_205_2: 2.1 - C_205_1: 2.1 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: src/RCS/parse.c,v -Working file: src/parse.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.4 - C_237: 2.4 - C_236: 2.4 - C_235: 2.4 - C_234: 2.4 - C_233: 2.4 - C_232: 2.4 - C_231: 2.4 - C_230: 2.4 - C_229: 2.4 - C_227: 2.4 - C_226: 2.4 - C_225: 2.4 - C_224: 2.4 - C_222: 2.4 - C_221: 2.4 - C_220: 2.4 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.4 - C_212: 2.3 - C_206: 2.3 - C_205_3: 2.3 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/phqalloc.c,v -Working file: src/phqalloc.c -head: 2.9 -branch: -locks: strict - dlpark: 2.9 -access list: -symbolic names: - C_260: 2.9 - C_259: 2.9 - C_258: 2.9 - C_257: 2.9 - C_256: 2.8 - C_255: 2.8 - C_254: 2.8 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.7 - C_248: 2.7 - C_247: 2.7 - C_246: 2.7 - C_245: 2.7 - C_244: 2.7 - C_243: 2.7 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.5 - C_237: 2.5 - C_236: 2.5 - C_235: 2.5 - C_234: 2.5 - C_233: 2.5 - C_232: 2.5 - C_231: 2.5 - C_230: 2.5 - C_229: 2.5 - C_227: 2.5 - C_226: 2.5 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.5 - C_218: 2.5 - RC1: 2.5 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.4 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.2 - C_204_1: 2.2 - C_204: 2.2 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: src/RCS/phreeqc_files.c,v -Working file: src/phreeqc_files.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.3 - C_257: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/prep.c,v -Working file: src/prep.c -head: 2.15 -branch: -locks: strict - dlpark: 2.15 -access list: -symbolic names: - C_260: 2.15 - C_259: 2.15 - C_258: 2.15 - C_257: 2.15 - C_256: 2.14 - C_255: 2.14 - C_254: 2.14 - C_253: 2.14 - C_252: 2.14 - C_251: 2.14 - C_250: 2.14 - C_249: 2.13 - C_248: 2.13 - C_247: 2.13 - C_246: 2.13 - C_245: 2.13 - C_244: 2.13 - C_243: 2.13 - C_242: 2.11 - C_241: 2.11 - C_240: 2.11 - C_239: 2.11 - C_238: 2.10 - C_237: 2.9 - C_236: 2.9 - C_235: 2.9 - C_234: 2.9 - C_233: 2.9 - C_232: 2.8 - C_231: 2.8 - C_230: 2.8 - C_229: 2.8 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.6 - C_222: 2.6 - C_221: 2.6 - C_220: 2.6 - C_219: 2.5 - C_218: 2.5 - RC1: 2.5 - C_216: 2.5 - C_215: 2.5 - C_214: 2.5 - C_213: 2.5 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.4 - C_205_2: 2.4 - C_205_1: 2.3 - C_205: 2.3 - C_204_2: 2.3 - C_204_1: 2.3 - C_204: 2.3 - C_202_2: 2.3 - C_202_1: 2.3 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 16 -============================================================================= - -RCS file: src/RCS/print.c,v -Working file: src/print.c -head: 2.38 -branch: -locks: strict - dlpark: 2.38 -access list: -symbolic names: - C_260: 2.38 - C_259: 2.38 - C_258: 2.38 - C_257: 2.38 - C_256: 2.37 - C_255: 2.36 - C_254: 2.35 - C_253: 2.34 - C_252: 2.34 - C_251: 2.32 - C_250: 2.32 - C_249: 2.31 - C_248: 2.31 - C_247: 2.31 - C_246: 2.31 - C_245: 2.31 - C_244: 2.31 - C_243: 2.31 - C_242: 2.30 - C_241: 2.30 - C_240: 2.30 - C_239: 2.30 - C_238: 2.29 - C_237: 2.29 - C_236: 2.29 - C_235: 2.28 - C_234: 2.27 - C_233: 2.27 - C_232: 2.27 - C_231: 2.27 - C_230: 2.27 - C_229: 2.27 - C_227: 2.27 - C_226: 2.27 - C_225: 2.26 - C_224: 2.26 - C_222: 2.26 - C_221: 2.25 - C_220: 2.25 - C_219: 2.24 - C_218: 2.24 - RC1: 2.24 - C_216: 2.24 - C_215: 2.24 - C_214: 2.21 - C_213: 2.20 - C_212: 2.15 - C_206: 2.15 - C_205_3: 2.11 - C_205_2: 2.10 - C_205_1: 2.9 - C_205: 2.8 - C_204_2: 2.7 - C_204_1: 2.7 - C_204: 2.7 - C_202_2: 2.5 - C_202_1: 2.4 - C_202: 2.4 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 39 -============================================================================= - -RCS file: src/RCS/read.c,v -Working file: src/read.c -head: 2.43 -branch: -locks: strict - dlpark: 2.43 -access list: -symbolic names: - C_260: 2.43 - C_259: 2.43 - C_258: 2.43 - C_257: 2.43 - C_256: 2.42 - C_255: 2.41 - C_254: 2.41 - C_253: 2.39 - C_252: 2.39 - C_251: 2.39 - C_250: 2.39 - C_249: 2.38 - C_248: 2.38 - C_247: 2.38 - C_246: 2.38 - C_245: 2.38 - C_244: 2.38 - C_243: 2.38 - C_242: 2.36 - C_241: 2.36 - C_240: 2.36 - C_239: 2.36 - C_238: 2.35 - C_237: 2.33 - C_236: 2.33 - C_235: 2.32 - C_234: 2.31 - C_233: 2.31 - C_232: 2.31 - C_231: 2.31 - C_230: 2.31 - C_229: 2.31 - C_227: 2.30 - C_226: 2.29 - C_225: 2.29 - C_224: 2.29 - C_222: 2.29 - C_221: 2.29 - C_220: 2.29 - C_219: 2.29 - C_218: 2.29 - RC1: 2.29 - C_216: 2.29 - C_215: 2.28 - C_214: 2.27 - C_213: 2.27 - C_212: 2.23 - C_206: 2.21 - C_205_3: 2.20 - C_205_2: 2.19 - C_205_1: 2.18 - C_205: 2.17 - C_204_2: 2.12 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.8 - C_202_1: 2.6 - C_202: 2.2 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 44 -============================================================================= - -RCS file: src/RCS/readtr.c,v -Working file: src/readtr.c -head: 2.13 -branch: -locks: strict - dlpark: 2.13 -access list: -symbolic names: - C_260: 2.13 - C_259: 2.13 - C_258: 2.12 - C_257: 2.12 - C_256: 2.11 - C_255: 2.10 - C_254: 2.10 - C_253: 2.9 - C_252: 2.9 - C_251: 2.9 - C_250: 2.9 - C_249: 2.8 - C_248: 2.8 - C_247: 2.8 - C_246: 2.8 - C_245: 2.8 - C_244: 2.8 - C_243: 2.8 - C_242: 2.6 - C_241: 2.6 - C_240: 2.6 - C_239: 2.6 - C_238: 2.5 - C_237: 2.5 - C_236: 2.5 - C_235: 2.5 - C_234: 2.5 - C_233: 2.5 - C_232: 2.5 - C_231: 2.5 - C_230: 2.5 - C_229: 2.5 - C_227: 2.5 - C_226: 2.5 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.3 - C_214: 2.3 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/smalldense.c,v -Working file: src/smalldense.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/spread.c,v -Working file: src/spread.c -head: 2.17 -branch: -locks: strict - dlpark: 2.17 -access list: -symbolic names: - C_260: 2.17 - C_259: 2.17 - C_258: 2.16 - C_257: 2.16 - C_256: 2.15 - C_255: 2.15 - C_254: 2.15 - C_253: 2.15 - C_252: 2.15 - C_251: 2.15 - C_250: 2.15 - C_249: 2.14 - C_248: 2.14 - C_247: 2.14 - C_246: 2.14 - C_245: 2.14 - C_244: 2.14 - C_243: 2.14 - C_242: 2.13 - C_241: 2.13 - C_240: 2.13 - C_239: 2.13 - C_238: 2.12 - C_237: 2.12 - C_236: 2.12 - C_235: 2.12 - C_234: 2.12 - C_233: 2.12 - C_232: 2.12 - C_231: 2.12 - C_230: 2.11 - C_229: 2.11 - C_227: 2.11 - C_226: 2.11 - C_225: 2.11 - C_224: 2.11 - C_222: 2.11 - C_221: 2.11 - C_220: 2.11 - C_219: 2.11 - C_218: 2.11 - RC1: 2.11 - C_216: 2.11 - C_215: 2.11 - C_214: 2.11 - C_213: 2.11 - C_212: 2.10 - C_206: 2.10 - C_205_3: 2.10 - C_205_2: 2.10 - C_205_1: 2.9 - C_205: 2.8 - C_204_2: 2.8 - C_204_1: 2.7 - C_204: 2.6 - C_202_2: 2.3 - C_202_1: 2.2 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 18 -============================================================================= - -RCS file: src/RCS/step.c,v -Working file: src/step.c -head: 2.13 -branch: -locks: strict - dlpark: 2.13 -access list: -symbolic names: - C_260: 2.13 - C_259: 2.13 - C_258: 2.13 - C_257: 2.13 - C_256: 2.12 - C_255: 2.12 - C_254: 2.12 - C_253: 2.12 - C_252: 2.12 - C_251: 2.12 - C_250: 2.12 - C_249: 2.11 - C_248: 2.11 - C_247: 2.11 - C_246: 2.11 - C_245: 2.11 - C_244: 2.11 - C_243: 2.11 - C_242: 2.10 - C_241: 2.10 - C_240: 2.10 - C_239: 2.10 - C_238: 2.9 - C_237: 2.7 - C_236: 2.7 - C_235: 2.7 - C_234: 2.7 - C_233: 2.7 - C_232: 2.7 - C_231: 2.7 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.6 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/structures.c,v -Working file: src/structures.c -head: 2.35 -branch: -locks: strict - dlpark: 2.35 -access list: -symbolic names: - C_260: 2.35 - C_259: 2.35 - C_258: 2.34 - C_257: 2.33 - C_256: 2.32 - C_255: 2.32 - C_254: 2.31 - C_253: 2.29 - C_252: 2.29 - C_251: 2.29 - C_250: 2.29 - C_249: 2.28 - C_248: 2.28 - C_247: 2.28 - C_246: 2.28 - C_245: 2.28 - C_244: 2.28 - C_243: 2.28 - C_242: 2.26 - C_241: 2.25 - C_240: 2.25 - C_239: 2.24 - C_238: 2.23 - C_237: 2.22 - C_236: 2.22 - C_235: 2.22 - C_234: 2.21 - C_233: 2.21 - C_232: 2.20 - C_231: 2.20 - C_230: 2.20 - C_229: 2.20 - C_227: 2.19 - C_226: 2.19 - C_225: 2.19 - C_224: 2.19 - C_222: 2.19 - C_221: 2.19 - C_220: 2.19 - C_219: 2.19 - C_218: 2.18 - RC1: 2.18 - C_216: 2.18 - C_215: 2.18 - C_214: 2.17 - C_213: 2.17 - C_212: 2.15 - C_206: 2.14 - C_205_3: 2.13 - C_205_2: 2.13 - C_205_1: 2.12 - C_205: 2.11 - C_204_2: 2.10 - C_204_1: 2.10 - C_204: 2.10 - C_202_2: 2.6 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 36 -============================================================================= - -RCS file: src/RCS/sundialsmath.c,v -Working file: src/sundialsmath.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/tally.c,v -Working file: src/tally.c -head: 1.14 -branch: -locks: strict - dlpark: 1.14 -access list: -symbolic names: - C_260: 1.14 - C_259: 1.14 - C_258: 1.14 - C_257: 1.14 - C_256: 1.13 - C_255: 1.13 - C_254: 1.13 - C_253: 1.13 - C_252: 1.13 - C_251: 1.12 - C_250: 1.12 - C_249: 1.11 - C_248: 1.11 - C_247: 1.11 - C_246: 1.10 - C_245: 1.10 - C_244: 1.9 - C_243: 1.8 - C_242: 1.6 - C_241: 1.5 - C_240: 1.4 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/tidy.c,v -Working file: src/tidy.c -head: 2.30 -branch: -locks: strict -access list: -symbolic names: - C_260: 2.30 - C_259: 2.29 - C_258: 2.29 - C_257: 2.29 - C_256: 2.28 - C_255: 2.28 - C_254: 2.28 - C_253: 2.27 - C_252: 2.27 - C_251: 2.27 - C_250: 2.27 - C_249: 2.26 - C_248: 2.26 - C_247: 2.26 - C_246: 2.26 - C_245: 2.26 - C_244: 2.26 - C_243: 2.26 - C_242: 2.24 - C_241: 2.23 - C_240: 2.23 - C_239: 2.22 - C_238: 2.21 - C_237: 2.19 - C_236: 2.19 - C_235: 2.19 - C_234: 2.19 - C_233: 2.19 - C_232: 2.17 - C_231: 2.17 - C_230: 2.17 - C_229: 2.16 - C_227: 2.16 - C_226: 2.16 - C_225: 2.16 - C_224: 2.16 - C_222: 2.16 - C_221: 2.16 - C_220: 2.15 - C_219: 2.15 - C_218: 2.15 - RC1: 2.15 - C_216: 2.15 - C_215: 2.15 - C_214: 2.15 - C_213: 2.15 - C_212: 2.10 - C_206: 2.9 - C_205_3: 2.9 - C_205_2: 2.8 - C_205_1: 2.7 - C_205: 2.6 - C_204_2: 2.5 - C_204_1: 2.4 - C_204: 2.3 - C_202_2: 2.2 - C_202_1: 2.2 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 31 -============================================================================= - -RCS file: src/RCS/transport.c,v -Working file: src/transport.c -head: 2.14 -branch: -locks: strict - dlpark: 2.14 -access list: -symbolic names: - C_260: 2.14 - C_259: 2.14 - C_258: 2.14 - C_257: 2.14 - C_256: 2.13 - C_255: 2.13 - C_254: 2.13 - C_253: 2.13 - C_252: 2.13 - C_251: 2.13 - C_250: 2.13 - C_249: 2.12 - C_248: 2.12 - C_247: 2.12 - C_246: 2.12 - C_245: 2.12 - C_244: 2.12 - C_243: 2.12 - C_242: 2.10 - C_241: 2.10 - C_240: 2.10 - C_239: 2.10 - C_238: 2.9 - C_237: 2.8 - C_236: 2.8 - C_235: 2.8 - C_234: 2.8 - C_233: 2.8 - C_232: 2.8 - C_231: 2.8 - C_230: 2.8 - C_229: 2.8 - C_227: 2.8 - C_226: 2.8 - C_225: 2.8 - C_224: 2.8 - C_222: 2.8 - C_221: 2.8 - C_220: 2.7 - C_219: 2.7 - C_218: 2.7 - RC1: 2.6 - C_216: 2.5 - C_215: 2.5 - C_214: 2.5 - C_213: 2.5 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.4 - C_205_2: 2.4 - C_205_1: 2.4 - C_205: 2.3 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 15 -============================================================================= - -RCS file: src/RCS/utilities.c,v -Working file: src/utilities.c -head: 2.30 -branch: -locks: strict - dlpark: 2.30 -access list: -symbolic names: - C_260: 2.30 - C_259: 2.30 - C_258: 2.30 - C_257: 2.30 - C_256: 2.29 - C_255: 2.29 - C_254: 2.29 - C_253: 2.28 - C_252: 2.28 - C_251: 2.28 - C_250: 2.28 - C_249: 2.27 - C_248: 2.27 - C_247: 2.27 - C_246: 2.27 - C_245: 2.27 - C_244: 2.27 - C_243: 2.27 - C_242: 2.25 - C_241: 2.24 - C_240: 2.24 - C_239: 2.24 - C_238: 2.23 - C_237: 2.22 - C_236: 2.22 - C_235: 2.21 - C_234: 2.21 - C_233: 2.21 - C_232: 2.19 - C_231: 2.18 - C_230: 2.18 - C_229: 2.16 - C_227: 2.15 - C_226: 2.15 - C_225: 2.15 - C_224: 2.15 - C_222: 2.15 - C_221: 2.15 - C_220: 2.14 - C_219: 2.13 - C_218: 2.13 - RC1: 2.13 - C_216: 2.13 - C_215: 2.13 - C_214: 2.11 - C_213: 2.11 - C_212: 2.9 - C_206: 2.9 - C_205_3: 2.8 - C_205_2: 2.8 - C_205_1: 2.7 - C_205: 2.6 - C_204_2: 2.5 - C_204_1: 2.5 - C_204: 2.5 - C_202_2: 2.4 - C_202_1: 2.4 - C_202: 2.3 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 31 -============================================================================= - -RCS file: src/RCS/cvdense.h,v -Working file: src/cvdense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/cvode.h,v -Working file: src/cvode.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/dense.h,v -Working file: src/dense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/global.h,v -Working file: src/global.h -head: 2.47 -branch: -locks: strict - dlpark: 2.47 -access list: -symbolic names: - C_260: 2.47 - C_259: 2.47 - C_258: 2.46 - C_257: 2.44 - C_256: 2.44 - C_255: 2.44 - C_254: 2.43 - C_253: 2.42 - C_252: 2.42 - C_251: 2.42 - C_250: 2.42 - C_249: 2.41 - C_248: 2.41 - C_247: 2.40 - C_246: 2.40 - C_245: 2.40 - C_244: 2.39 - C_243: 2.39 - C_242: 2.36 - C_241: 2.35 - C_240: 2.35 - C_239: 2.34 - C_238: 2.33 - C_237: 2.32 - C_236: 2.32 - C_235: 2.32 - C_234: 2.31 - C_233: 2.31 - C_232: 2.30 - C_231: 2.30 - C_230: 2.30 - C_229: 2.30 - C_227: 2.29 - C_226: 2.28 - C_225: 2.28 - C_224: 2.28 - C_222: 2.28 - C_221: 2.28 - C_220: 2.28 - C_219: 2.27 - C_218: 2.27 - RC1: 2.27 - C_216: 2.27 - C_215: 2.26 - C_214: 2.25 - C_213: 2.24 - C_212: 2.19 - C_206: 2.18 - C_205_3: 2.17 - C_205_2: 2.16 - C_205_1: 2.15 - C_205: 2.13 - C_204_2: 2.11 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.7 - C_202_1: 2.5 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 48 -============================================================================= - -RCS file: src/RCS/input.h,v -Working file: src/input.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/kinetics.h,v -Working file: src/kinetics.h -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_260: 1.2 - C_259: 1.2 - C_258: 1.2 - C_257: 1.2 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: src/RCS/nvector.h,v -Working file: src/nvector.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/nvector_serial.h,v -Working file: src/nvector_serial.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/output.h,v -Working file: src/output.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/p2c.h,v -Working file: src/p2c.h -head: 2.2 -branch: -locks: strict - dlpark: 2.2 -access list: -symbolic names: - C_260: 2.2 - C_259: 2.2 - C_258: 2.2 - C_257: 2.2 - C_256: 2.2 - C_255: 2.2 - C_254: 2.2 - C_253: 2.2 - C_252: 2.2 - C_251: 2.2 - C_250: 2.2 - C_249: 2.2 - C_248: 2.2 - C_247: 2.2 - C_246: 2.2 - C_245: 2.2 - C_244: 2.2 - C_243: 2.2 - C_242: 2.2 - C_241: 2.2 - C_240: 2.2 - C_239: 2.2 - C_238: 2.1 - C_237: 2.1 - C_236: 2.1 - C_235: 2.1 - C_234: 2.1 - C_233: 2.1 - C_232: 2.1 - C_231: 2.1 - C_230: 2.1 - C_229: 2.1 - C_227: 2.1 - C_226: 2.1 - C_225: 2.1 - C_224: 2.1 - C_222: 2.1 - C_221: 2.1 - C_220: 2.1 - C_219: 2.1 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/phqalloc.h,v -Working file: src/phqalloc.h -head: 2.3 -branch: -locks: strict - dlpark: 2.3 -access list: -symbolic names: - C_260: 2.3 - C_259: 2.3 - C_258: 2.3 - C_257: 2.2 - C_256: 2.2 - C_255: 2.2 - C_254: 2.2 - C_253: 2.2 - C_252: 2.2 - C_251: 2.2 - C_250: 2.2 - C_249: 2.2 - C_248: 2.2 - C_247: 2.2 - C_246: 2.2 - C_245: 2.2 - C_244: 2.2 - C_243: 2.2 - C_242: 2.2 - C_241: 2.2 - C_240: 2.2 - C_239: 2.2 - C_238: 2.2 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/phrqproto.h,v -Working file: src/phrqproto.h -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_260: 1.6 - C_259: 1.6 - C_258: 1.6 - C_257: 1.6 - C_256: 1.5 - C_255: 1.5 - C_254: 1.4 - C_253: 1.2 - C_252: 1.2 - C_251: 1.1 - C_250: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: src/RCS/phrqtype.h,v -Working file: src/phrqtype.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/smalldense.h,v -Working file: src/smalldense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/sundialsmath.h,v -Working file: src/sundialsmath.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/sundialstypes.h,v -Working file: src/sundialstypes.h -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.4 - C_255: 1.4 - C_254: 1.4 - C_253: 1.4 - C_252: 1.4 - C_251: 1.4 - C_250: 1.4 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.3 - C_241: 1.3 - C_240: 1.3 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: database/RCS/llnl.dat,v -Working file: database/llnl.dat -head: 1.14 -branch: -locks: strict -access list: -symbolic names: - C_210: 1.14 - C_209: 1.14 - C_224: 1.12 - C_207: 1.12 - C_206: 1.11 - C_205: 1.11 - C_204: 1.10 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: database/RCS/minteq.dat,v -Working file: database/minteq.dat -head: 2.1 -branch: -locks: strict -access list: -symbolic names: - C_210: 2.1 - C_209: 2.1 - C_224: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: database/RCS/phreeqc.dat,v -Working file: database/phreeqc.dat -head: 2.3 -branch: -locks: strict - dlpark: 2.3 -access list: -symbolic names: - C_210: 2.3 - C_209: 2.3 - C_224: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: database/RCS/wateq4f.dat,v -Working file: database/wateq4f.dat -head: 2.6 -branch: -locks: strict - dlpark: 2.6 -access list: -symbolic names: - C_210: 2.6 - C_209: 2.6 - C_224: 2.4 - C_207: 2.2 - C_206: 2.2 - C_205: 2.2 - C_204: 2.2 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: database/RCS/iso.dat,v -Working file: database/iso.dat -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_210: 1.4 - C_209: 1.4 - C_224: 1.4 - C_207: 1.4 - C_206: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex1,v -Working file: examples/ex1 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex1.out,v -Working file: examples/ex1.out -head: 1.7 -branch: -locks: strict - dlpark: 1.7 -access list: -symbolic names: - C_212: 1.7 - C_211: 1.5 - C_210: 1.5 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: examples/RCS/ex2,v -Working file: examples/ex2 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex2.out,v -Working file: examples/ex2.out -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex2.sel,v -Working file: examples/ex2.sel -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex3,v -Working file: examples/ex3 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex3.out,v -Working file: examples/ex3.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex4,v -Working file: examples/ex4 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex4.out,v -Working file: examples/ex4.out -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_212: 1.6 - C_211: 1.4 - C_210: 1.4 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: examples/RCS/ex5,v -Working file: examples/ex5 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex5.out,v -Working file: examples/ex5.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex5.sel,v -Working file: examples/ex5.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex6,v -Working file: examples/ex6 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex6.out,v -Working file: examples/ex6.out -head: 1.13 -branch: -locks: strict - dlpark: 1.13 -access list: -symbolic names: - C_212: 1.13 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.9 - C_206: 1.7 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 13 -============================================================================= - -RCS file: examples/RCS/ex6A-B.sel,v -Working file: examples/ex6A-B.sel -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex6C.sel,v -Working file: examples/ex6C.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex7,v -Working file: examples/ex7 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex7.out,v -Working file: examples/ex7.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex7.sel,v -Working file: examples/ex7.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex8,v -Working file: examples/ex8 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex8.out,v -Working file: examples/ex8.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex8.sel,v -Working file: examples/ex8.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex9,v -Working file: examples/ex9 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex9.out,v -Working file: examples/ex9.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.5 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex9.sel,v -Working file: examples/ex9.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex10,v -Working file: examples/ex10 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex10.out,v -Working file: examples/ex10.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex10.sel,v -Working file: examples/ex10.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex11,v -Working file: examples/ex11 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.1 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex11.out,v -Working file: examples/ex11.out -head: 1.13 -branch: -locks: strict - dlpark: 1.13 -access list: -symbolic names: - C_212: 1.13 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 13 -============================================================================= - -RCS file: examples/RCS/ex11adv.sel,v -Working file: examples/ex11adv.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex11trn.sel,v -Working file: examples/ex11trn.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex12,v -Working file: examples/ex12 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex12.out,v -Working file: examples/ex12.out -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_212: 1.3 - C_211: 1.1 - C_210: 1.1 - C_224: 1.1 - C_208: 1.1 - C_207: 1.1 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: examples/RCS/ex12.sel,v -Working file: examples/ex12.sel -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.9 - C_206: 1.7 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex13a,v -Working file: examples/ex13a -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13a.out,v -Working file: examples/ex13a.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13a.sel,v -Working file: examples/ex13a.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13b,v -Working file: examples/ex13b -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13b.out,v -Working file: examples/ex13b.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13b.sel,v -Working file: examples/ex13b.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13c,v -Working file: examples/ex13c -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13c.out,v -Working file: examples/ex13c.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13c.sel,v -Working file: examples/ex13c.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex14,v -Working file: examples/ex14 -head: 2.2 -branch: -locks: strict - dlpark: 2.2 -access list: -symbolic names: - C_212: 2.2 - C_211: 2.2 - C_210: 2.2 - C_224: 2.2 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.1 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: examples/RCS/ex14.out,v -Working file: examples/ex14.out -head: 1.15 -branch: -locks: strict - dlpark: 1.15 -access list: -symbolic names: - C_212: 1.15 - C_211: 1.13 - C_210: 1.12 - C_224: 1.11 - C_208: 1.9 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 15 -============================================================================= - -RCS file: examples/RCS/ex14.sel,v -Working file: examples/ex14.sel -head: 1.8 -branch: -locks: strict - dlpark: 1.8 -access list: -symbolic names: - C_212: 1.8 - C_211: 1.7 - C_210: 1.7 - C_224: 1.6 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: examples/RCS/ex15,v -Working file: examples/ex15 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex15.dat,v -Working file: examples/ex15.dat -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex15.out,v -Working file: examples/ex15.out -head: 1.8 -branch: -locks: strict - dlpark: 1.8 -access list: -symbolic names: - C_212: 1.8 - C_211: 1.6 - C_210: 1.6 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: examples/RCS/ex15.sel,v -Working file: examples/ex15.sel -head: 1.7 -branch: -locks: strict - dlpark: 1.7 -access list: -symbolic names: - C_212: 1.7 - C_211: 1.7 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.5 - C_205: 1.4 - C_204: 1.4 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: examples/RCS/ex16,v -Working file: examples/ex16 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex16.out,v -Working file: examples/ex16.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex17,v -Working file: examples/ex17 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex17.out,v -Working file: examples/ex17.out -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex18,v -Working file: examples/ex18 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex18.out,v -Working file: examples/ex18.out -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_212: 1.6 - C_211: 1.4 - C_210: 1.4 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: doc/RCS/manual.pdf,v -Working file: doc/manual.pdf -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_211: 1.1 - C_210: 1.1 - C_224: 1.1 - C_208: 1.1 - C_207: 1.1 - C_206: 1.1 - C_205: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: doc/RCS/phreeqc.txt,v -Working file: doc/phreeqc.txt -head: 1.11 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.8 - C_207: 1.8 - C_206: 1.7 - C_205: 1.6 - C_204_2: 1.5 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: bin/RCS/phreeqc.orig,v -Working file: bin/phreeqc.orig -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_209: 1.4 - C_208: 1.4 - C_224: 1.4 - C_206: 1.4 - C_205: 1.4 - C_202: 1.4 - C_201: 1.4 - C_200: 1.4 - C_1: 1.4 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: test/RCS/test.sh,v -Working file: test/test.sh -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_211: 1.2 - C_210: 1.2 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: test/RCS/clean.sh,v -Working file: test/clean.sh -head: 1.2 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.2 - C_210: 1.2 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: test/RCS/check.sh,v -Working file: test/check.sh -head: 1.3 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.3 - C_210: 1.3 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 -keyword substitution: kv -total revisions: 3 -============================================================================= diff --git a/phreeqc/phreex.ico b/phreex.ico similarity index 100% rename from phreeqc/phreex.ico rename to phreex.ico diff --git a/phreeqc/phrqtype.h b/phrqtype.h similarity index 100% rename from phreeqc/phrqtype.h rename to phrqtype.h diff --git a/phreeqc/pitzer.cpp b/pitzer.cpp similarity index 100% rename from phreeqc/pitzer.cpp rename to pitzer.cpp diff --git a/phreeqc/pitzer_structures.cpp b/pitzer_structures.cpp similarity index 100% rename from phreeqc/pitzer_structures.cpp rename to pitzer_structures.cpp diff --git a/phreeqc/prep.cpp b/prep.cpp similarity index 100% rename from phreeqc/prep.cpp rename to prep.cpp diff --git a/phreeqc/print.cpp b/print.cpp similarity index 100% rename from phreeqc/print.cpp rename to print.cpp diff --git a/phreeqc/read.cpp b/read.cpp similarity index 100% rename from phreeqc/read.cpp rename to read.cpp diff --git a/phreeqc/readtr.cpp b/readtr.cpp similarity index 100% rename from phreeqc/readtr.cpp rename to readtr.cpp diff --git a/phreeqc/sit.cpp b/sit.cpp similarity index 100% rename from phreeqc/sit.cpp rename to sit.cpp diff --git a/phreeqc/smalldense.cpp b/smalldense.cpp similarity index 100% rename from phreeqc/smalldense.cpp rename to smalldense.cpp diff --git a/phreeqc/smalldense.h b/smalldense.h similarity index 100% rename from phreeqc/smalldense.h rename to smalldense.h diff --git a/phreeqc/spread.cpp b/spread.cpp similarity index 100% rename from phreeqc/spread.cpp rename to spread.cpp diff --git a/phreeqc/step.cpp b/step.cpp similarity index 100% rename from phreeqc/step.cpp rename to step.cpp diff --git a/phreeqc/structures.cpp b/structures.cpp similarity index 100% rename from phreeqc/structures.cpp rename to structures.cpp diff --git a/phreeqc/sundialsmath.cpp b/sundialsmath.cpp similarity index 100% rename from phreeqc/sundialsmath.cpp rename to sundialsmath.cpp diff --git a/phreeqc/sundialsmath.h b/sundialsmath.h similarity index 100% rename from phreeqc/sundialsmath.h rename to sundialsmath.h diff --git a/phreeqc/sundialstypes.h b/sundialstypes.h similarity index 100% rename from phreeqc/sundialstypes.h rename to sundialstypes.h diff --git a/phreeqc/tally.cpp b/tally.cpp similarity index 100% rename from phreeqc/tally.cpp rename to tally.cpp diff --git a/phreeqc/tidy.cpp b/tidy.cpp similarity index 100% rename from phreeqc/tidy.cpp rename to tidy.cpp diff --git a/phreeqc/transport.cpp b/transport.cpp similarity index 100% rename from phreeqc/transport.cpp rename to transport.cpp diff --git a/phreeqc/utilities.cpp b/utilities.cpp similarity index 100% rename from phreeqc/utilities.cpp rename to utilities.cpp From 709e117619a5ef1420848e952b767efeeefce3ca Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 11 Jan 2013 01:05:51 +0000 Subject: [PATCH 0606/1077] modified source files for rearranged directories git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7310 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 98 +++++++++++++++++++++++++------------------------- basicsubs.cpp | 8 ++--- class_main.cpp | 2 +- readtr.cpp | 4 +-- structures.cpp | 2 +- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4d129144..8785171b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,59 +80,59 @@ phreeqc_SOURCES=\ Use.h\ Utils.cxx\ Utils.h\ - phreeqc/advection.cpp\ - phreeqc/basicsubs.cpp\ - phreeqc/cl1.cpp\ - phreeqc/cvdense.cpp\ - phreeqc/cvdense.h\ - phreeqc/cvode.cpp\ - phreeqc/cvode.h\ - phreeqc/dense.cpp\ - phreeqc/dense.h\ - phreeqc/dw.cpp\ - phreeqc/gases.cpp\ - phreeqc/global_structures.h\ - phreeqc/input.cpp\ - phreeqc/integrate.cpp\ - phreeqc/inverse.cpp\ - phreeqc/isotopes.cpp\ - phreeqc/kinetics.cpp\ - phreeqc/mainsubs.cpp\ - phreeqc/model.cpp\ - phreeqc/NA.h\ - phreeqc/nvector.cpp\ - phreeqc/nvector.h\ - phreeqc/nvector_serial.cpp\ - phreeqc/nvector_serial.h\ - phreeqc/parse.cpp\ - phreeqc/phqalloc.cpp\ - phreeqc/phqalloc.h\ - phreeqc/PHRQ_io_output.cpp\ - phreeqc/phrqtype.h\ - phreeqc/pitzer.cpp\ - phreeqc/pitzer_structures.cpp\ - phreeqc/prep.cpp\ - phreeqc/print.cpp\ - phreeqc/read.cpp\ - phreeqc/readtr.cpp\ - phreeqc/sit.cpp\ - phreeqc/smalldense.cpp\ - phreeqc/smalldense.h\ - phreeqc/spread.cpp\ - phreeqc/step.cpp\ - phreeqc/structures.cpp\ - phreeqc/sundialsmath.cpp\ - phreeqc/sundialsmath.h\ - phreeqc/sundialstypes.h\ - phreeqc/tally.cpp\ - phreeqc/tidy.cpp\ - phreeqc/transport.cpp\ - phreeqc/utilities.cpp + advection.cpp\ + basicsubs.cpp\ + cl1.cpp\ + cvdense.cpp\ + cvdense.h\ + cvode.cpp\ + cvode.h\ + dense.cpp\ + dense.h\ + dw.cpp\ + gases.cpp\ + global_structures.h\ + input.cpp\ + integrate.cpp\ + inverse.cpp\ + isotopes.cpp\ + kinetics.cpp\ + mainsubs.cpp\ + model.cpp\ + NA.h\ + nvector.cpp\ + nvector.h\ + nvector_serial.cpp\ + nvector_serial.h\ + parse.cpp\ + phqalloc.cpp\ + phqalloc.h\ + PHRQ_io_output.cpp\ + phrqtype.h\ + pitzer.cpp\ + pitzer_structures.cpp\ + prep.cpp\ + print.cpp\ + read.cpp\ + readtr.cpp\ + sit.cpp\ + smalldense.cpp\ + smalldense.h\ + spread.cpp\ + step.cpp\ + structures.cpp\ + sundialsmath.cpp\ + sundialsmath.h\ + sundialstypes.h\ + tally.cpp\ + tidy.cpp\ + transport.cpp\ + utilities.cpp if BUILD_GMP phreeqc_SOURCES+=\ - phreeqc/cl1mp.cpp + cl1mp.cpp endif diff --git a/basicsubs.cpp b/basicsubs.cpp index eb05aa8a..ae7c722a 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2,10 +2,10 @@ #include "phqalloc.h" #include "Utils.h" -#include "../NameDouble.h" -#include "../PBasic.h" -#include "../Exchange.h" -#include "../GasPhase.h" +#include "NameDouble.h" +#include "PBasic.h" +#include "Exchange.h" +#include "GasPhase.h" #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" diff --git a/class_main.cpp b/class_main.cpp index 27dac704..7da4e96a 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -61,7 +61,7 @@ unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. //_controlfp(cwOriginal, MCW_EM); #endif Phreeqc phreeqc_instance; - phreeqc_instance.main_method(argc, argv); + return phreeqc_instance.main_method(argc, argv); } diff --git a/readtr.cpp b/readtr.cpp index cf11ffb3..a6bc54c6 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1,8 +1,8 @@ #include /* std::cout std::cerr */ #include #include -#include "../StorageBin.h" -#include "../SS.h" +#include "StorageBin.h" +#include "SS.h" typedef unsigned char boolean; #include "Phreeqc.h" diff --git a/structures.cpp b/structures.cpp index 70f19eed..2a057e0a 100644 --- a/structures.cpp +++ b/structures.cpp @@ -3615,7 +3615,7 @@ copier_init(struct copier *copier_ptr) (int *) PHRQ_malloc((size_t) (copier_ptr->max * sizeof(int))); return (OK); } -#include "../StorageBin.h" +#include "StorageBin.h" void Phreeqc:: Use2cxxStorageBin(cxxStorageBin & sb) From 9976920fbfeb60937921481f6bf07933de0dfc7f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 11 Jan 2013 01:23:36 +0000 Subject: [PATCH 0607/1077] updated dependencies git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7311 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7c1ab22f..c19d5b6a 100644 --- a/Makefile +++ b/Makefile @@ -976,7 +976,7 @@ clean: dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp tester: cd ../mytest; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From bb2ea3d7121826a21fb5c371fbff4b28772ab226 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 11 Jan 2013 01:24:45 +0000 Subject: [PATCH 0608/1077] updated dependencies git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7312 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GNUmakefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 8487e8d6..2fcecf49 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -368,11 +368,11 @@ clean: dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../phreeqc ../*.cxx ../*.cpp ../phreeqc/*.cpp + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp tester: - cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../mytest; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples From 662894ffb3e17194211d45f2b216e0e7091b6be5 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 11 Jan 2013 01:29:17 +0000 Subject: [PATCH 0609/1077] renamed GNUmakefile to Makefile git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7313 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GNUmakefile | 388 ------------------------- Makefile | 798 +++++++--------------------------------------------- 2 files changed, 95 insertions(+), 1091 deletions(-) delete mode 100644 GNUmakefile diff --git a/GNUmakefile b/GNUmakefile deleted file mode 100644 index 2fcecf49..00000000 --- a/GNUmakefile +++ /dev/null @@ -1,388 +0,0 @@ -# Makefile for PHREEQCPP -# -# Generates object files and executables for 2 versions of PHREEQCPP -# Release -# Debug -# -# Serial verisons: Release Debug -# -# Makefile sets CFG variable, cd's to appropriate directory, runs Makefile recursively -# Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC -# - -PROGRAM = phreeqcpp - -CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else - SPOOL=>& - SPOOL2= -endif - -all: class_release class_debug - -Debug: class_debug -debug: class_debug -Class_debug: class_debug - -Release: class_release -release: class_release -Class_release: class_release - -Debug_64: class_debug_64 -debug_64: class_debug_64 -Class_debug_64: class_debug_64 - -Release_64: class_release_64 -release_64: class_release_64 -Class_release_64: class_release_64 - - -CLASS_DEBUG_DIR = Class_debug -CLASS_DIR = Class_release -CLASS_DEBUG_64_DIR = Class_debug_64 -CLASS_64_DIR = Class_release_64 -MAKEFILE = GNUmakefile -DEPDIR = .deps - -# ----------------------------------------------------------------------------- -# fixes shared object lookup error(SIGFPE floating point exception) -HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) - - -######################### -#### Serial Versions #### -######################### -.PHONY : Class_debug -class_debug: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) - -.PHONY : Class_release -class_release: - mkdir -p $(CLASS_DIR) - cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) -.PHONY : Class_debug_64 -class_debug_64: - mkdir -p $(CLASS_DEBUG_64_DIR) - cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) - -.PHONY : Class_release_64 -class_release_64: - mkdir -p $(CLASS_64_DIR) - cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) - -# Recursive make begins here -# -# ============================================================================= -# Significant suffixes [assuming Fortran 90 (.f90) source code]: -# Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: -# ============================================================================= - -#SRC = ../phreeqc -.SUFFIXES : .o .c .cxx .cpp - -# compilers - -# ----------------------------------------------------------------------------- -.c.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po - -.cxx.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po - -.cpp.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po - -# ----------------------------------------------------------------------------- -#hdf options -#HDF5_ROOT=$(HOME)/../../usr -#HDF5_INCLUDES=-I$(HDF5_ROOT)/src -#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread - -# ----------------------------------------------------------------------------- -# #define compile options - -# ----------------------------------------------------------------------------- -# #define gmp for inverse modeling -# comment the following lines to remove multiprecision option - -# ----------------------------------------------------------------------------- -#efence for debugging -EFENCE_LIB=-L$(HOME)/packages/efence - -# ----------------------------------------------------------------------------- -# 4 Versions -# ----------------------------------------------------------------------------- -ifeq ($(CFG), CLASS_DEBUG) - INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o -# CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a - endif - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -ifeq ($(CFG), CLASS_RELEASE) - INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o -# CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a - endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -ifeq ($(CFG), CLASS_DEBUG_64) - DEFINES = -DUSE_PHRQ_ALLOC # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -ifeq ($(CFG), CLASS_RELEASE_64) - DEFINES = -DNDEBUG # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -# ----------------------------------------------------------------------------- -# - -COMMON_COBJS = \ - advection.o \ - basicsubs.o \ - cl1.o \ - cvdense.o \ - cvode.o \ - dense.o \ - dw.o \ - gases.o \ - input.o \ - integrate.o \ - inverse.o \ - isotopes.o \ - kinetics.o \ - mainsubs.o \ - model.o \ - nvector.o \ - nvector_serial.o \ - parse.o \ - PHRQ_io_output.o \ - phqalloc.o \ - pitzer.o \ - pitzer_structures.o \ - prep.o \ - print.o \ - read.o \ - readtr.o \ - sit.o \ - smalldense.o \ - spread.o \ - step.o \ - structures.o \ - sundialsmath.o \ - tally.o \ - tidy.o \ - transport.o \ - utilities.o - -MAIN_FILE = main.o - -CLASS_FILES = \ - class_main.o \ - Phreeqc.o - - -COMMON_CXXOBJS = \ - dumper.o \ - Exchange.o \ - ExchComp.o \ - GasPhase.o \ - GasComp.o \ - ISolution.o \ - ISolutionComp.o \ - Keywords.o \ - KineticsComp.o \ - cxxKinetics.o \ - cxxMix.o \ - NameDouble.o \ - NumKeyword.o \ - Parser.o \ - PBasic.o \ - PHRQ_base.o \ - PHRQ_io.o \ - PPassemblageComp.o \ - PPassemblage.o \ - Pressure.o \ - Reaction.o \ - ReadClass.o \ - runner.o \ - Solution.o \ - SolutionIsotope.o \ - SSassemblage.o \ - SScomp.o \ - SS.o \ - StorageBin.o \ - StorageBinList.o \ - Surface.o \ - SurfaceCharge.o \ - SurfaceComp.o \ - System.o \ - Temperature.o \ - Use.o \ - Utils.o - -# ----------------------------------------------------------------------------- -# Assign dependents to target on dependency line & link options on command -# line. Command line is initiated with a tab. ($@ is an internal macro for -# the current target.) - -${PROGRAM} : ${OBJECT_FILES} -# ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} - ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} - @echo; echo Done making for phreeqcpp -# ----------------------------------------------------------------------------- -# Module dependency list -# ----------------------------------------------------------------------------- -# -# CXX files -# --include $(DEPDIR)/cxxKinetics.Po --include $(DEPDIR)/cxxMix.Po --include $(DEPDIR)/Exchange.Po --include $(DEPDIR)/ExchComp.Po --include $(DEPDIR)/GasComp.Po --include $(DEPDIR)/GasPhase.Po --include $(DEPDIR)/ISolutionComp.Po --include $(DEPDIR)/ISolution.Po --include $(DEPDIR)/KineticsComp.Po --include $(DEPDIR)/NameDouble.Po --include $(DEPDIR)/NumKeyword.Po --include $(DEPDIR)/Parser.Po --include $(DEPDIR)/PHRQ_base.Po --include $(DEPDIR)/PPassemblageComp.Po --include $(DEPDIR)/PPassemblage.Po --include $(DEPDIR)/Pressure.Po --include $(DEPDIR)/Reaction.Po --include $(DEPDIR)/ReadClass.Po --include $(DEPDIR)/Solution.Po --include $(DEPDIR)/SolutionIsotope.Po --include $(DEPDIR)/SSassemblage.Po --include $(DEPDIR)/SScomp.Po --include $(DEPDIR)/SS.Po --include $(DEPDIR)/StorageBin.Po --include $(DEPDIR)/SurfaceCharge.Po --include $(DEPDIR)/SurfaceComp.Po --include $(DEPDIR)/Surface.Po --include $(DEPDIR)/System.Po --include $(DEPDIR)/Temperature.Po --include $(DEPDIR)/Utils.Po --include $(DEPDIR)/ChartHandler.Po --include $(DEPDIR)/ChartObject.Po --include $(DEPDIR)/class_main.Po --include $(DEPDIR)/CurveObject.Po --include $(DEPDIR)/dumper.Po --include $(DEPDIR)/Keywords.Po --include $(DEPDIR)/PBasic.Po --include $(DEPDIR)/Phreeqc.Po --include $(DEPDIR)/PHRQ_io.Po --include $(DEPDIR)/runner.Po --include $(DEPDIR)/StorageBinList.Po --include $(DEPDIR)/Use.Po --include $(DEPDIR)/advection.Po --include $(DEPDIR)/basicsubs.o --include $(DEPDIR)/cl1.Po --include $(DEPDIR)/cl1mp.Po --include $(DEPDIR)/cvdense.Po --include $(DEPDIR)/cvode.Po --include $(DEPDIR)/dense.Po --include $(DEPDIR)/dw.Po --include $(DEPDIR)/gases.Po --include $(DEPDIR)/input.Po --include $(DEPDIR)/integrate.Po --include $(DEPDIR)/inverse.Po --include $(DEPDIR)/isotopes.Po --include $(DEPDIR)/kinetics.Po --include $(DEPDIR)/mainsubs.Po --include $(DEPDIR)/model.Po --include $(DEPDIR)/nvector.Po --include $(DEPDIR)/nvector_serial.Po --include $(DEPDIR)/parse.Po --include $(DEPDIR)/phqalloc.Po --include $(DEPDIR)/PHRQ_io_output.Po --include $(DEPDIR)/pitzer.Po --include $(DEPDIR)/pitzer_structures.Po --include $(DEPDIR)/prep.Po --include $(DEPDIR)/print.Po --include $(DEPDIR)/read.Po --include $(DEPDIR)/readtr.Po --include $(DEPDIR)/sit.Po --include $(DEPDIR)/smalldense.Po --include $(DEPDIR)/spread.Po --include $(DEPDIR)/step.Po --include $(DEPDIR)/structures.Po --include $(DEPDIR)/sundialsmath.Po --include $(DEPDIR)/tally.Po --include $(DEPDIR)/tidy.Po --include $(DEPDIR)/transport.Po --include $(DEPDIR)/utilities.Po - -# ----------------------------------------------------------------------------- -clean: - rm -rf Class_release Class_debug Class_release_64 Class_debug_64 - -dependencies: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp - -tester: - cd ../mytest; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - svn status -q ../mytest - svn status -q ../examples - -#ld-option -# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) -comma=, -ld-option = $(shell if $(CC) $(1) \ - -nostdlib -o /dev/null -xc /dev/null \ - > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) - -# ============================================================================= -# End of makefile. -# ============================================================================= diff --git a/Makefile b/Makefile index c19d5b6a..2fcecf49 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,8 @@ CLASS_DEBUG_DIR = Class_debug CLASS_DIR = Class_release CLASS_DEBUG_64_DIR = Class_debug_64 CLASS_64_DIR = Class_release_64 -MAKEFILE = Makefile +MAKEFILE = GNUmakefile +DEPDIR = .deps # ----------------------------------------------------------------------------- # fixes shared object lookup error(SIGFPE floating point exception) @@ -88,13 +89,22 @@ class_release_64: # ----------------------------------------------------------------------------- .c.o : - ${CXX} ${CXXFLAGS} -c -o $@ $< + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po .cxx.o : - ${CXX} ${CXXFLAGS} -c -o $@ $< + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po .cpp.o : - ${CXX} ${CXXFLAGS} -c -o $@ $< + test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" + depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + mv -f $$depbase.Tpo $$depbase.Po # ----------------------------------------------------------------------------- #hdf options @@ -209,7 +219,7 @@ COMMON_COBJS = \ tally.o \ tidy.o \ transport.o \ - utilities.o + utilities.o MAIN_FILE = main.o @@ -272,704 +282,86 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../cxxKinetics.h ../KineticsComp.h \ - ../phreeqc/phqalloc.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../Exchange.h ../ExchComp.h ../phreeqc/phqalloc.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../ExchComp.h ../phreeqc/phqalloc.h -GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../GasComp.h \ - ../phreeqc/phqalloc.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../GasPhase.h ../GasComp.h ../phreeqc/phqalloc.h -ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../ISolutionComp.h ../Solution.h \ - ../ISolution.h ../phreeqc/phqalloc.h -ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../ISolution.h ../ISolutionComp.h \ - ../phreeqc/phqalloc.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../KineticsComp.h ../phreeqc/phqalloc.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h ../ISolutionComp.h -NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h ../Utils.h \ - ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ - ../phreeqc/NA.h -Parser.o: ../Parser.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h -PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../PPassemblageComp.h ../phreeqc/phqalloc.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../PPassemblage.h ../PPassemblageComp.h \ - ../phreeqc/phqalloc.h -Pressure.o: ../Pressure.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../Reaction.h ../phreeqc/phqalloc.h -ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../Temperature.h ../phreeqc/phqalloc.h -Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../Solution.h ../ISolution.h ../ISolutionComp.h ../phreeqc/phqalloc.h -SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../SolutionIsotope.h ../phreeqc/phqalloc.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../phreeqc/phqalloc.h -SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SScomp.h \ - ../phreeqc/phqalloc.h -SS.o: ../SS.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../SS.h \ - ../SScomp.h ../phreeqc/phqalloc.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../StorageBin.h ../System.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Reaction.h ../Temperature.h \ - ../phreeqc/phqalloc.h -SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -Surface.o: ../Surface.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -System.o: ../System.cxx ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../System.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Reaction.h ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Temperature.h ../phreeqc/phqalloc.h -Utils.o: ../Utils.cxx ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h -ChartHandler.o: ../ChartHandler.cpp -ChartObject.o: ../ChartObject.cpp -class_main.o: ../class_main.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h -CurveObject.o: ../CurveObject.cpp ../CurveObject.h ../phreeqc/phrqtype.h -dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h ../PHRQ_io.h -Keywords.o: ../Keywords.cpp ../Keywords.h -PBasic.o: ../PBasic.cpp ../PBasic.h ../phreeqc/phrqtype.h ../PHRQ_base.h \ - ../phreeqc/global_structures.h ../Surface.h ../NumKeyword.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../Keywords.h ../PHRQ_io.h ../SurfaceCharge.h ../phreeqc/NA.h \ - ../Phreeqc.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../phreeqc/phqalloc.h ../Utils.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../Solution.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h ../phreeqc/phqalloc.h ../PBasic.h \ - ../Temperature.h -PHRQ_io.o: ../PHRQ_io.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h -runner.o: ../runner.cpp ../runner.h ../phreeqc/phrqtype.h \ - ../StorageBinList.h ../PHRQ_base.h ../Parser.h ../Keywords.h \ - ../PHRQ_io.h ../phreeqc/NA.h -StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../phreeqc/phrqtype.h ../Keywords.h \ - ../PHRQ_io.h -Use.o: ../Use.cpp ../Use.h -advection.o: ../phreeqc/advection.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h -basicsubs.o: ../phreeqc/basicsubs.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../PBasic.h ../phreeqc/../PHRQ_base.h \ - ../phreeqc/../Exchange.h ../phreeqc/../NumKeyword.h \ - ../phreeqc/../ExchComp.h ../phreeqc/../NameDouble.h \ - ../phreeqc/../GasPhase.h ../phreeqc/\ - ../phreeqc/../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ - ../Parser.h -cl1.o: ../phreeqc/cl1.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -cl1mp.o: ../phreeqc/cl1mp.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -cvdense.o: ../phreeqc/cvdense.cpp ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../phreeqc/sundialsmath.h \ - ../Phreeqc.h ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -cvode.o: ../phreeqc/cvode.cpp ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/sundialsmath.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -dense.o: ../phreeqc/dense.cpp ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/sundialsmath.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h -dw.o: ../phreeqc/dw.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h -gases.o: ../phreeqc/gases.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../GasPhase.h ../GasComp.h -input.o: ../phreeqc/input.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h -integrate.o: ../phreeqc/integrate.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -inverse.o: ../phreeqc/inverse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h ../SolutionIsotope.h -isotopes.o: ../phreeqc/isotopes.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h -kinetics.o: ../phreeqc/kinetics.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ - ../KineticsComp.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ - ../cxxMix.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../Temperature.h ../phreeqc/nvector_serial.h -mainsubs.o: ../phreeqc/mainsubs.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ - ../Solution.h ../ISolution.h ../ISolutionComp.h -model.o: ../phreeqc/model.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../Solution.h ../ISolution.h ../ISolutionComp.h -nvector.o: ../phreeqc/nvector.cpp ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h -nvector_serial.o: ../phreeqc/nvector_serial.cpp \ - ../phreeqc/nvector_serial.h ../phreeqc/nvector.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h -parse.o: ../phreeqc/parse.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h -phqalloc.o: ../phreeqc/phqalloc.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h -PHRQ_io_output.o: ../phreeqc/PHRQ_io_output.cpp ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -pitzer.o: ../phreeqc/pitzer.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -pitzer_structures.o: ../phreeqc/pitzer_structures.cpp ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../phreeqc/phqalloc.h -prep.o: ../phreeqc/prep.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../SS.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h -print.o: ../phreeqc/print.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ - ../Solution.h ../ISolution.h ../ISolutionComp.h -read.o: ../phreeqc/read.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Pressure.h ../Temperature.h ../Parser.h \ - ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -readtr.o: ../phreeqc/readtr.cpp ../phreeqc/../StorageBin.h \ - ../phreeqc/../System.h ../phreeqc/../NameDouble.h ../phreeqc/../Parser.h \ - ../phreeqc/phrqtype.h ../phreeqc/../PHRQ_base.h ../phreeqc/../Keywords.h \ - ../phreeqc/../PHRQ_io.h ../phreeqc/../phreeqc/../SS.h \ - ../phreeqc/../SScomp.h ../Phreeqc.h ../phreeqc/cvdense.h \ - ../phreeqc/cvode.h ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/nvector.h ../phreeqc/dense.h ../phreeqc/smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../SurfaceCharge.h ../phreeqc/global_structures.h ../Surface.h \ - ../phreeqc/NA.h ../phreeqc/phqalloc.h -sit.o: ../phreeqc/sit.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -smalldense.o: ../phreeqc/smalldense.cpp ../phreeqc/smalldense.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h \ - ../phreeqc/sundialsmath.h -spread.o: ../phreeqc/spread.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ - ../Utils.h ../Phreeqc.h -step.o: ../phreeqc/step.cpp ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h \ - ../phreeqc/phqalloc.h ../Utils.h ../Phreeqc.h ../StorageBin.h \ - ../System.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../SS.h ../NameDouble.h ../Temperature.h ../cxxMix.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ - ../cxxKinetics.h ../KineticsComp.h -structures.o: ../phreeqc/structures.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../Temperature.h ../cxxMix.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../Use.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ - ../KineticsComp.h ../Solution.h ../ISolution.h ../ISolutionComp.h \ - ../phreeqc/../StorageBin.h ../phreeqc/../System.h \ - ../phreeqc/../NameDouble.h ../phreeqc/../PHRQ_base.h \ - ../phreeqc/../phreeqc/../PHRQ_io.h -sundialsmath.o: ../phreeqc/sundialsmath.cpp ../phreeqc/sundialsmath.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h -tally.o: ../phreeqc/tally.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -tidy.o: ../phreeqc/tidy.cpp ../Utils.h ../Phreeqc.h ../phreeqc/phrqtype.h \ - ../phreeqc/cvdense.h ../phreeqc/cvode.h ../phreeqc/sundialstypes.h \ - ../phreeqc/phrqtype.h ../phreeqc/nvector.h ../phreeqc/dense.h \ - ../phreeqc/smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../phreeqc/global_structures.h ../Surface.h ../phreeqc/NA.h ../Phreeqc.h \ - ../phreeqc/phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../ISolution.h ../ISolutionComp.h -transport.o: ../phreeqc/transport.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h -utilities.o: ../phreeqc/utilities.cpp ../Utils.h ../Phreeqc.h \ - ../phreeqc/phrqtype.h ../phreeqc/cvdense.h ../phreeqc/cvode.h \ - ../phreeqc/sundialstypes.h ../phreeqc/phrqtype.h ../phreeqc/nvector.h \ - ../phreeqc/dense.h ../phreeqc/smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../phreeqc/global_structures.h \ - ../Surface.h ../phreeqc/NA.h ../Phreeqc.h ../phreeqc/phqalloc.h \ - ../NameDouble.h ../Exchange.h ../ExchComp.h ../Solution.h ../ISolution.h \ - ../ISolutionComp.h +-include $(DEPDIR)/cxxKinetics.Po +-include $(DEPDIR)/cxxMix.Po +-include $(DEPDIR)/Exchange.Po +-include $(DEPDIR)/ExchComp.Po +-include $(DEPDIR)/GasComp.Po +-include $(DEPDIR)/GasPhase.Po +-include $(DEPDIR)/ISolutionComp.Po +-include $(DEPDIR)/ISolution.Po +-include $(DEPDIR)/KineticsComp.Po +-include $(DEPDIR)/NameDouble.Po +-include $(DEPDIR)/NumKeyword.Po +-include $(DEPDIR)/Parser.Po +-include $(DEPDIR)/PHRQ_base.Po +-include $(DEPDIR)/PPassemblageComp.Po +-include $(DEPDIR)/PPassemblage.Po +-include $(DEPDIR)/Pressure.Po +-include $(DEPDIR)/Reaction.Po +-include $(DEPDIR)/ReadClass.Po +-include $(DEPDIR)/Solution.Po +-include $(DEPDIR)/SolutionIsotope.Po +-include $(DEPDIR)/SSassemblage.Po +-include $(DEPDIR)/SScomp.Po +-include $(DEPDIR)/SS.Po +-include $(DEPDIR)/StorageBin.Po +-include $(DEPDIR)/SurfaceCharge.Po +-include $(DEPDIR)/SurfaceComp.Po +-include $(DEPDIR)/Surface.Po +-include $(DEPDIR)/System.Po +-include $(DEPDIR)/Temperature.Po +-include $(DEPDIR)/Utils.Po +-include $(DEPDIR)/ChartHandler.Po +-include $(DEPDIR)/ChartObject.Po +-include $(DEPDIR)/class_main.Po +-include $(DEPDIR)/CurveObject.Po +-include $(DEPDIR)/dumper.Po +-include $(DEPDIR)/Keywords.Po +-include $(DEPDIR)/PBasic.Po +-include $(DEPDIR)/Phreeqc.Po +-include $(DEPDIR)/PHRQ_io.Po +-include $(DEPDIR)/runner.Po +-include $(DEPDIR)/StorageBinList.Po +-include $(DEPDIR)/Use.Po +-include $(DEPDIR)/advection.Po +-include $(DEPDIR)/basicsubs.o +-include $(DEPDIR)/cl1.Po +-include $(DEPDIR)/cl1mp.Po +-include $(DEPDIR)/cvdense.Po +-include $(DEPDIR)/cvode.Po +-include $(DEPDIR)/dense.Po +-include $(DEPDIR)/dw.Po +-include $(DEPDIR)/gases.Po +-include $(DEPDIR)/input.Po +-include $(DEPDIR)/integrate.Po +-include $(DEPDIR)/inverse.Po +-include $(DEPDIR)/isotopes.Po +-include $(DEPDIR)/kinetics.Po +-include $(DEPDIR)/mainsubs.Po +-include $(DEPDIR)/model.Po +-include $(DEPDIR)/nvector.Po +-include $(DEPDIR)/nvector_serial.Po +-include $(DEPDIR)/parse.Po +-include $(DEPDIR)/phqalloc.Po +-include $(DEPDIR)/PHRQ_io_output.Po +-include $(DEPDIR)/pitzer.Po +-include $(DEPDIR)/pitzer_structures.Po +-include $(DEPDIR)/prep.Po +-include $(DEPDIR)/print.Po +-include $(DEPDIR)/read.Po +-include $(DEPDIR)/readtr.Po +-include $(DEPDIR)/sit.Po +-include $(DEPDIR)/smalldense.Po +-include $(DEPDIR)/spread.Po +-include $(DEPDIR)/step.Po +-include $(DEPDIR)/structures.Po +-include $(DEPDIR)/sundialsmath.Po +-include $(DEPDIR)/tally.Po +-include $(DEPDIR)/tidy.Po +-include $(DEPDIR)/transport.Po +-include $(DEPDIR)/utilities.Po + # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug Class_release_64 Class_debug_64 From 7ef536ffbec2128cf56296b0cbee733b07c70c64 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 11 Jan 2013 02:22:26 +0000 Subject: [PATCH 0610/1077] working on linux dist git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7315 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 2fcecf49..9a6a98f3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC # -PROGRAM = phreeqcpp +PROGRAM = phreeqc CFG1 :=`uname` CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") @@ -45,7 +45,7 @@ CLASS_DEBUG_DIR = Class_debug CLASS_DIR = Class_release CLASS_DEBUG_64_DIR = Class_debug_64 CLASS_64_DIR = Class_release_64 -MAKEFILE = GNUmakefile +MAKEFILE = Makefile DEPDIR = .deps # ----------------------------------------------------------------------------- @@ -82,7 +82,6 @@ class_release_64: # Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: # ============================================================================= -#SRC = ../phreeqc .SUFFIXES : .o .c .cxx .cpp # compilers @@ -127,7 +126,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 4 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - INVERSE_CL1MP=TRUE + INVERSE_CL1MP=FALSE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o @@ -135,8 +134,8 @@ ifeq ($(CFG), CLASS_DEBUG) CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. + VPATH = .. + INCLUDES = -I.. CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -275,7 +274,7 @@ COMMON_CXXOBJS = \ ${PROGRAM} : ${OBJECT_FILES} # ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} - @echo; echo Done making for phreeqcpp + @echo; echo Done making for phreeqc # ----------------------------------------------------------------------------- # Module dependency list # ----------------------------------------------------------------------------- From d23bd01f386152668e6af5ccee7e986727bf6f34 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Jan 2013 17:00:38 +0000 Subject: [PATCH 0611/1077] Changes for Kinniburgh's underflow and overflow problems. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7319 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 12 ++++- Utils.cxx | 16 +++++++ Utils.h | 1 + phreeqc/model.cpp | 114 ++++++++++++++++++++++++++++++++-------------- 4 files changed, 108 insertions(+), 35 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 35ac0f4a..82007114 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3143,7 +3143,17 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_solution_volume(); break; case toklog10: - n.UU.val = log10(realfactor(LINK)); + { + double t = realfactor(LINK); + if (t > 0.0) + { + n.UU.val = log10(t); + } + else + { + n.UU.val = 0; + } + } break; case tokvm: { diff --git a/Utils.cxx b/Utils.cxx index 5e011032..cbd5169c 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -155,6 +155,22 @@ Utilities::convert_time(double t, std::string in, std::string out) return t; } +double +Utilities::safe_exp(double t) +//////////////////////////////////////////////////////////////////////////// +{ + double f = 1.442695*t; // convert to exp for 2.0 + + if (f > DBL_MAX_EXP - 50.0) + { + return pow(2, DBL_MAX_EXP - 50.0); + } + else if (f < DBL_MIN_EXP + 50.0) + { + return pow(2, DBL_MIN_EXP + 50.0); + } + return exp(t); +} //+NAN LDBLE: 7ff8000000000000 //-NAN LDBLE: fff8000000000000 /* diff --git a/Utils.h b/Utils.h index c51603ac..bdc59b0b 100644 --- a/Utils.h +++ b/Utils.h @@ -23,5 +23,6 @@ namespace Utilities void squeeze_white(std::string & s_l); double convert_time(double t, std::string in, std::string out); + double safe_exp(double t); } #endif // UTILITIES_H_INCLUDED diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 9f616d8a..c4bc85fa 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -2347,37 +2347,13 @@ molalities(int allow_overflow) } if (s_x[i]->type == EX) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!PHR_ISFINITE(s_x[i]->moles)) - { - if (s_x[i]->lm < 0.0) - { - s_x[i]->moles = 1e-200; - fprintf(stderr, "ExchNaN-\n"); - } - else - { - s_x[i]->moles = 1e200; - fprintf(stderr, "ExchNaN+\n"); - } - } + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + } else if (s_x[i]->type == SURF) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!PHR_ISFINITE(s_x[i]->moles)) - { - if (s_x[i]->lm < 0.0) - { - s_x[i]->moles = 1e-200; - fprintf(stderr, "SurfNaN-\n"); - } - else - { - s_x[i]->moles = 1e200; - fprintf(stderr, "SurfNaN+\n"); - } - } + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + } else { @@ -4312,7 +4288,15 @@ residuals(void) } /* add fictitious monovalent ion that balances charge */ - sum += fabs(sum1) * (exp(-sum1 / fabs(sum1) * negfpsirt) - 1); + //sum += fabs(sum1) * (exp(-sum1 / fabs(sum1) * negfpsirt) - 1); + if (sum1 >= 0) + { + sum += fabs(sum1) * (exp(-negfpsirt) - 1); + } + else + { + sum += fabs(sum1) * (exp(negfpsirt) - 1); + } if (sum < 0) { @@ -4667,15 +4651,44 @@ revise_guesses(void) else { repeat = TRUE; +#ifdef SKIP d = weight * log10(fabs(x[i]->moles / x[i]->sum)); - /*if (!isnan(d) && _finite(d))*/ - if (PHR_ISFINITE((double) d)) + double d1 = d; +#else + // avoid underflows and overflows + if (x[i]->moles > 1e101 || x[i]->moles < 1e-101 || + x[i]->sum > 1e101 || x[i]->sum < 1e-101) { - x[i]->master[0]->s->la += d; + double d1 = log10(x[i]->moles); + double d2 = log10(x[i]->sum); + double d3 = d1 - d2; + if (d3 > DBL_MAX_10_EXP/2) + { + d = pow(10.0, DBL_MAX_10_EXP/2.); + } + else if (d3 < DBL_MIN_10_EXP/2.) + { + d = pow(10.0, DBL_MIN_10_EXP/2.); + } } else { - warning_msg("Adjustment to la in revise_guesses was NaN\n"); + d = fabs(x[i]->moles / x[i]->sum); + } + double d1 = weight * log10(d); +#endif + /*if (!isnan(d) && _finite(d))*/ + if (PHR_ISFINITE((double) d1) && d1 < 5.0) + { + x[i]->master[0]->s->la += d1; + } + else + { + //warning_msg("Adjustment to la in revise_guesses was NaN\n"); + if (!PHR_ISFINITE((double) d1)) + { + fprintf(stderr, "revise_guesses: %e, %e, %e\n", x[i]->moles, x[i]->sum, d); + } x[i]->master[0]->s->la += 5.0; } @@ -5302,7 +5315,40 @@ numerical_jacobian(void) //output_msg(sformatf( "%d\n", i)); for (j = 0; j < count_unknowns; j++) { - array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + // avoid overflow + if (residual[j] > 1.0e101) + { + double t = pow(10.0, DBL_MAX_10_EXP - 50.0); + if (residual[j] > t) + { + array[j * (count_unknowns + 1) + i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + } + } + else if (residual[j] < -1.0e101) + { + double t = pow(10.0, DBL_MIN_10_EXP + 50.0); + if (residual[j] < -t) + { + array[j * (count_unknowns + 1) + i] = pow(10.0, DBL_MIN_10_EXP + 50.0); + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + } + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + if (!PHR_ISFINITE(array[j * (count_unknowns + 1) + i])) + { + fprintf(stderr, "oops, got NaN: %e, %e, %e, %e\n", residual[j], base[j], d2, array[j * (count_unknowns + 1) + i]); + } + } + //output_msg(sformatf( "\t%d %e %e %e %e\n", j, array[j*(count_unknowns + 1) + i] , residual[j], base[j], d2)); } switch (x[i]->type) From 801d7ed3876c8f0dd084d31e4a445ebc9393d7d3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Jan 2013 17:29:26 +0000 Subject: [PATCH 0612/1077] Linux changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7320 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Utils.cxx | 2 ++ phreeqc/model.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Utils.cxx b/Utils.cxx index cbd5169c..f20fd211 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -9,6 +9,8 @@ #include "Utils.h" #include "Parser.h" +#include "float.h" +#include "math.h" //////////////////////////////////////////////////////////////////////////// int diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index c4bc85fa..25593a15 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -7,6 +7,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "Solution.h" +#include "float.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -4651,6 +4652,7 @@ revise_guesses(void) else { repeat = TRUE; + d = 0; #ifdef SKIP d = weight * log10(fabs(x[i]->moles / x[i]->sum)); double d1 = d; From 11b005510e79e79918b7a7c68ad7b348907c5767 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Jan 2013 18:04:03 +0000 Subject: [PATCH 0613/1077] tweaked changes to make zn.test run on linux git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7321 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 25593a15..7944b809 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -4680,7 +4680,7 @@ revise_guesses(void) double d1 = weight * log10(d); #endif /*if (!isnan(d) && _finite(d))*/ - if (PHR_ISFINITE((double) d1) && d1 < 5.0) + if (PHR_ISFINITE((double) d1) /*&& d1 < 5.0*/) { x[i]->master[0]->s->la += d1; } From d759535cb1d6e2ca70a988a87c28b7f09148738b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Jan 2013 18:55:07 +0000 Subject: [PATCH 0614/1077] check for zero before log10 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7322 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc/model.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/phreeqc/model.cpp b/phreeqc/model.cpp index 7944b809..0a90916d 100644 --- a/phreeqc/model.cpp +++ b/phreeqc/model.cpp @@ -4677,23 +4677,29 @@ revise_guesses(void) { d = fabs(x[i]->moles / x[i]->sum); } - double d1 = weight * log10(d); -#endif - /*if (!isnan(d) && _finite(d))*/ - if (PHR_ISFINITE((double) d1) /*&& d1 < 5.0*/) + double d1; + if (d > 0) { - x[i]->master[0]->s->la += d1; + d1 = weight * log10(d); + if (PHR_ISFINITE((double) d1) /*&& d1 < 5.0*/) + { + x[i]->master[0]->s->la += d1; + } + else + { + //warning_msg("Adjustment to la in revise_guesses was NaN\n"); + if (!PHR_ISFINITE((double) d1)) + { + fprintf(stderr, "revise_guesses: %e, %e, %e\n", x[i]->moles, x[i]->sum, d); + } + x[i]->master[0]->s->la += 5.0; + } } else { - //warning_msg("Adjustment to la in revise_guesses was NaN\n"); - if (!PHR_ISFINITE((double) d1)) - { - fprintf(stderr, "revise_guesses: %e, %e, %e\n", x[i]->moles, x[i]->sum, d); - } x[i]->master[0]->s->la += 5.0; } - +#endif } if (debug_set == TRUE) { From ea2bd44559c390570119c6f1e1e58b1d0c40ce80 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 15 Jan 2013 21:46:19 +0000 Subject: [PATCH 0615/1077] working on 3.0 dist git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/reorg@7330 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- distribution.mk | 533 ++++++++++++++++++++++-------------------------- 1 file changed, 242 insertions(+), 291 deletions(-) diff --git a/distribution.mk b/distribution.mk index 800088e7..3c702666 100644 --- a/distribution.mk +++ b/distribution.mk @@ -29,343 +29,294 @@ else endif # list of files for distribution -FILES= \ - $(CURSRC)/Makefile \ - $(CURSRC)/advection.c \ - $(CURSRC)/basic.c \ - $(CURSRC)/basicsubs.c \ - $(CURSRC)/cl1.c \ - $(CURSRC)/cl1mp.c \ - $(CURSRC)/cvdense.c \ - $(CURSRC)/cvode.c \ - $(CURSRC)/dense.c \ - $(CURSRC)/dw.c \ - $(CURSRC)/input.c \ - $(CURSRC)/integrate.c \ - $(CURSRC)/inverse.c \ - $(CURSRC)/isotopes.c \ - $(CURSRC)/kinetics.c \ - $(CURSRC)/main.c \ - $(CURSRC)/mainsubs.c \ - $(CURSRC)/model.c \ - $(CURSRC)/nvector.c \ - $(CURSRC)/nvector_serial.c \ - $(CURSRC)/output.c \ - $(CURSRC)/p2clib.c \ - $(CURSRC)/parse.c \ - $(CURSRC)/phqalloc.c \ - $(CURSRC)/phreeqc_files.c \ - $(CURSRC)/pitzer.c \ - $(CURSRC)/pitzer_structures.c \ - $(CURSRC)/prep.c \ - $(CURSRC)/print.c \ - $(CURSRC)/read.c \ - $(CURSRC)/readtr.c \ - $(CURSRC)/sit.c \ - $(CURSRC)/smalldense.c \ - $(CURSRC)/spread.c \ - $(CURSRC)/step.c \ - $(CURSRC)/structures.c \ - $(CURSRC)/sundialsmath.c \ - $(CURSRC)/tally.c \ - $(CURSRC)/tidy.c \ - $(CURSRC)/transport.c \ - $(CURSRC)/utilities.c \ - $(CURSRC)/basic.h \ - $(CURSRC)/cvdense.h \ - $(CURSRC)/cvode.h \ - $(CURSRC)/dense.h \ - $(CURSRC)/global.h \ - $(CURSRC)/global_structures.h \ - $(CURSRC)/input.h \ - $(CURSRC)/kinetics.h \ - $(CURSRC)/nvector.h \ - $(CURSRC)/nvector_serial.h \ - $(CURSRC)/output.h \ - $(CURSRC)/p2c.h \ - $(CURSRC)/phqalloc.h \ - $(CURSRC)/phrqproto.h \ - $(CURSRC)/phrqtype.h \ - $(CURSRC)/pitzer.h \ - $(CURSRC)/pitzer_structures.h \ - $(CURSRC)/smalldense.h \ - $(CURSRC)/sundialsmath.h \ - $(CURSRC)/sundialstypes.h \ - database/*.dat \ - examples/ex1 examples/ex1.out \ - examples/ex2 examples/ex2.out examples/ex2.sel \ - examples/ex3 examples/ex3.out \ - examples/ex4 examples/ex4.out \ - examples/ex5 examples/ex5.out examples/ex5.sel \ - examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ - examples/ex7 examples/ex7.out examples/ex7.sel \ - examples/ex8 examples/ex8.out examples/ex8.sel \ - examples/ex9 examples/ex9.out examples/ex9.sel \ - examples/ex10 examples/ex10.out examples/ex10.sel \ - examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ - examples/ex12 examples/ex12.out examples/ex12.sel \ - examples/ex12a examples/ex12a.out examples/ex12a.sel \ - examples/ex13a examples/ex13a.out examples/ex13a.sel \ - examples/ex13b examples/ex13b.out examples/ex13b.sel \ - examples/ex13c examples/ex13c.out examples/ex13c.sel \ - examples/ex14 examples/ex14.out examples/ex14.sel \ - examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ - examples/ex16 examples/ex16.out \ - examples/ex17 examples/ex17.out \ - examples/ex18 examples/ex18.out \ - NOTICE.TXT \ - README.TXT \ - RELEASE.TXT \ - doc/manual.pdf \ - doc/wrir02-4172.pdf \ - doc/phreeqc.txt \ - bin/phreeqc.orig \ - test/test.sh \ - test/clean.sh \ - test/check.sh +##FILES= \ +## $(CURSRC)/Makefile \ +## $(CURSRC)/advection.c \ +## $(CURSRC)/basic.c \ +## $(CURSRC)/basicsubs.c \ +## $(CURSRC)/cl1.c \ +## $(CURSRC)/cl1mp.c \ +## $(CURSRC)/cvdense.c \ +## $(CURSRC)/cvode.c \ +## $(CURSRC)/dense.c \ +## $(CURSRC)/dw.c \ +## $(CURSRC)/input.c \ +## $(CURSRC)/integrate.c \ +## $(CURSRC)/inverse.c \ +## $(CURSRC)/isotopes.c \ +## $(CURSRC)/kinetics.c \ +## $(CURSRC)/main.c \ +## $(CURSRC)/mainsubs.c \ +## $(CURSRC)/model.c \ +## $(CURSRC)/nvector.c \ +## $(CURSRC)/nvector_serial.c \ +## $(CURSRC)/output.c \ +## $(CURSRC)/p2clib.c \ +## $(CURSRC)/parse.c \ +## $(CURSRC)/phqalloc.c \ +## $(CURSRC)/phreeqc_files.c \ +## $(CURSRC)/pitzer.c \ +## $(CURSRC)/pitzer_structures.c \ +## $(CURSRC)/prep.c \ +## $(CURSRC)/print.c \ +## $(CURSRC)/read.c \ +## $(CURSRC)/readtr.c \ +## $(CURSRC)/sit.c \ +## $(CURSRC)/smalldense.c \ +## $(CURSRC)/spread.c \ +## $(CURSRC)/step.c \ +## $(CURSRC)/structures.c \ +## $(CURSRC)/sundialsmath.c \ +## $(CURSRC)/tally.c \ +## $(CURSRC)/tidy.c \ +## $(CURSRC)/transport.c \ +## $(CURSRC)/utilities.c \ +## $(CURSRC)/basic.h \ +## $(CURSRC)/cvdense.h \ +## $(CURSRC)/cvode.h \ +## $(CURSRC)/dense.h \ +## $(CURSRC)/global.h \ +## $(CURSRC)/global_structures.h \ +## $(CURSRC)/input.h \ +## $(CURSRC)/kinetics.h \ +## $(CURSRC)/nvector.h \ +## $(CURSRC)/nvector_serial.h \ +## $(CURSRC)/output.h \ +## $(CURSRC)/p2c.h \ +## $(CURSRC)/phqalloc.h \ +## $(CURSRC)/phrqproto.h \ +## $(CURSRC)/phrqtype.h \ +## $(CURSRC)/pitzer.h \ +## $(CURSRC)/pitzer_structures.h \ +## $(CURSRC)/smalldense.h \ +## $(CURSRC)/sundialsmath.h \ +## $(CURSRC)/sundialstypes.h \ +## database/*.dat \ +## examples/ex1 examples/ex1.out \ +## examples/ex2 examples/ex2.out examples/ex2.sel \ +## examples/ex3 examples/ex3.out \ +## examples/ex4 examples/ex4.out \ +## examples/ex5 examples/ex5.out examples/ex5.sel \ +## examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ +## examples/ex7 examples/ex7.out examples/ex7.sel \ +## examples/ex8 examples/ex8.out examples/ex8.sel \ +## examples/ex9 examples/ex9.out examples/ex9.sel \ +## examples/ex10 examples/ex10.out examples/ex10.sel \ +## examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ +## examples/ex12 examples/ex12.out examples/ex12.sel \ +## examples/ex12a examples/ex12a.out examples/ex12a.sel \ +## examples/ex13a examples/ex13a.out examples/ex13a.sel \ +## examples/ex13b examples/ex13b.out examples/ex13b.sel \ +## examples/ex13c examples/ex13c.out examples/ex13c.sel \ +## examples/ex14 examples/ex14.out examples/ex14.sel \ +## examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ +## examples/ex16 examples/ex16.out \ +## examples/ex17 examples/ex17.out \ +## examples/ex18 examples/ex18.out \ +## NOTICE.TXT \ +## README.TXT \ +## RELEASE.TXT \ +## doc/manual.pdf \ +## doc/wrir02-4172.pdf \ +## doc/phreeqc.txt \ +## bin/phreeqc.orig \ +## test/test.sh \ +## test/clean.sh \ +## test/check.sh -SED_ARGS= \ - -e "s/@VERSION@/$(VERSION)/" \ - -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ - -e "s/VERSION_DATE/$(VERSION)/" \ - -e "s^@GCC_VER@^$(GCC_VER)^" \ - -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ - -e "s/@REVISION@/$(REVISION)/" \ - -e "s/@PHREEQC_VER@/$(VERSION)/" \ - -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" +##SED_ARGS= \ +## -e "s/@VERSION@/$(VERSION)/" \ +## -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ +## -e "s/VERSION_DATE/$(VERSION)/" \ +## -e "s^@GCC_VER@^$(GCC_VER)^" \ +## -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ +## -e "s/@REVISION@/$(REVISION)/" \ +## -e "s/@PHREEQC_VER@/$(VERSION)/" \ +## -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" +## -SED_ARGS2=\ +##SED_ARGS2=\ -e "s/^\# Remove the following definition if you do not have /\# Add the following definition if you have/" \ -e "s/^INVERSE_CL1MP=TRUE/\#INVERSE_CL1MP=TRUE/" -remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files +##remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files -output_files: linux_output_files # sun_output_files +##output_files: linux_output_files # sun_output_files # make sure program is compiles, run examples and mytest -linux_output_files: all - cd ../examples; make >& make.out - cd ../mytest; make >& make.out +##linux_output_files: all +## cd ../examples; make >& make.out +## cd ../mytest; make >& make.out -clean_linux_output_files: - cd ../examples; make clean - cd ../mytest; make clean +##clean_linux_output_files: +## cd ../examples; make clean +## cd ../mytest; make clean -sun_output_files: phreeqc.sun - ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" +##sun_output_files: phreeqc.sun +## ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" -phreeqc.sun: - ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" +##phreeqc.sun: +## ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" -clean_sun_output_files: - cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean +##clean_sun_output_files: +## cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean -all_dist: clean_dist linux source # win # sun +##all_dist: clean_dist linux source # win # sun -test_dist: linux_test source_test # sun_test +##test_dist: linux_test source_test # sun_test # #Linux # -linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist +##linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist -source: source_export source_clean source_sed_files source_dist +##source: source_export source_clean source_sed_files source_dist -linux_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Linux - svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux +##linux_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Linux +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux -linux_clean: - rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o +##linux_clean: +## rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o -linux_sed_list= \ - "$(EXPORT_DIR)/Linux/doc/README.TXT \ - $(EXPORT_DIR)/Linux/src/main.c" +##linux_sed_list= \ +## "$(EXPORT_DIR)/Linux/doc/README.TXT \ +## $(EXPORT_DIR)/Linux/src/main.c" -linux_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT - for FILE in "$(linux_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT - mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT +##linux_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT +## for FILE in "$(linux_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done +## mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT +## mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT -linux_compile: - make -C $(EXPORT_DIR)/Linux/src +##linux_compile: +## make -C $(EXPORT_DIR)/Linux/src -linux_output: - cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out +##linux_output: +## cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out -linux_dist: - cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar +##linux_dist: +## cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar +## +## cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) +## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +## cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile +## cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz +## cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) - cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile - cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz - cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) +##source_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Source +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source -source_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Source - svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source +##source_clean: +## rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o -source_clean: - rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o +##source_sed_list= \ +## "$(EXPORT_DIR)/Source/doc/README.TXT \ +## $(EXPORT_DIR)/Source/src/main.c" -source_sed_list= \ - "$(EXPORT_DIR)/Source/doc/README.TXT \ - $(EXPORT_DIR)/Source/src/main.c" +##source_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT +## sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile +## for FILE in "$(source_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done +## mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT +## mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT -source_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT - sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile - for FILE in "$(source_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT - mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT +##source_dist: +## cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar +## cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar +## cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz +## cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) +## +##linux_test: +## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux +## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh +## rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh -source_dist: - cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar - cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz - cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) +##source_test: +## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source +## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source +## cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k +## cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh -linux_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh - rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k - cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh +##clean_dist: +## rm -rf $(EXPORT_DIR) -source_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source - cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k - cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh - -# -#Sun -# -sun: sun_export sun_clean sun_sed_files sun_compile sun_output sun_dist - -sun_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Sun - svn export .. $(EXPORT_DIR)/Sun - -sun_clean: - rm -f $(EXPORT_DIR)/Sun/bin/$(PROGRAM) $(EXPORT_DIR)/Sun/src/*.o - -sun_sed_list= \ - "$(EXPORT_DIR)/Sun/doc/README.TXT \ - $(EXPORT_DIR)/Sun/src/main.c" - -sun_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Sun/src/revisions > $(EXPORT_DIR)/Sun/doc/RELEASE.TXT - for FILE in "$(sun_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done - -sun_compile: - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/src" - -sun_output: - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples clean" - ssh u450rcolkr "make -C $(EXPORT_DIR)/Sun/examples" > $(EXPORT_DIR)/Sun/examples/make.out 2>> $(EXPORT_DIR)/Sun/examples/make.out - -sun_dist: - cd $(EXPORT_DIR)/Sun; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Sun; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Sun; tar -rf $(PROGRAM).tar bin/$(PROGRAM) - cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar - cd $(EXPORT_DIR)/Sun; tar -czf $(PROGRAM).Sun.tar.gz $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Sun; mv $(PROGRAM).Sun.tar.gz $(DIST_DIR)/$(ROOTNAME).Sun.tar.gz - cd $(EXPORT_DIR)/Sun; echo $(ROOTNAME).Sun.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Sun; rm -rf $(PROGRAM)-$(VERSION) - -sun_test: - rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Sun - cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Sun.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Sun - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./test.sh" - rm -f $(DIST_DIR)/phreeqc-$(VERSION).Sun/bin/phreeqc - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/src; make -k" - ssh u450rcolkr "cd $(DIST_DIR)/phreeqc-$(VERSION).Sun/test; ./clean.sh; ./test.sh" - -clean_dist: - rm -rf $(EXPORT_DIR) - -clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files +##clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files # #Win # -win: win_export win_sed_files win_dist +##win: win_export win_sed_files win_dist -win_export: - mkdir -p $(EXPORT_DIR) - rm -rf $(EXPORT_DIR)/Win - svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win +##win_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Win +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win -win_sed_list= \ +##win_sed_list= \ "$(EXPORT_DIR)/Win/src/main.c" -win_sed_files: - sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT - $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT - sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT - $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT - for FILE in "$(win_sed_list)"; do \ - sed $(SED_ARGS) < $$FILE > t; \ +##win_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT +## $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT +## sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT +## $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT +## for FILE in "$(win_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; \ mv t $$FILE; \ $(UNIX2DOS) $$FILE; \ done - mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT +## mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT -win_dist: - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar +##win_dist: +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar # Translate cr/lf - cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ +## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done - cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) - cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar # remove example output - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel # remove bin directory - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin # remove test directory files - cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat # copy bat file - cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat - cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz - cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . - @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). - cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat +## cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz +## cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . +## @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) -win_echo_files: - @echo $(FILES) +##win_echo_files: +## @echo $(FILES) debug: mkdir -p $(DEBUG_DIR) @@ -375,14 +326,14 @@ debug_nomp: mkdir -p $(DEBUG_DIR) cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) -web: - cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc - cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT - cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT - cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT - cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT - cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt - cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT +##web: +## cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc +## cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT +## cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT +## cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT +## cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT +## cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt +## cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT tester: cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From 67c08b44d0bfb5c25227e742157feaf974835093 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 23 Jan 2013 15:13:50 +0000 Subject: [PATCH 0616/1077] Fixed activity and gamma Basic functions to include EX and SURF git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7360 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index ae7c722a..fef80d66 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -47,7 +47,7 @@ activity_coefficient(const char *species_name) LDBLE g; s_ptr = s_search(species_name); - if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { g = pow((LDBLE) 10., s_ptr->lg); } @@ -67,7 +67,7 @@ log_activity_coefficient(const char *species_name) LDBLE g; s_ptr = s_search(species_name); - if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { g = s_ptr->lg; } From c8c26e81e95e61672f2b9e9a52cc0b0eb0f925c3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jan 2013 16:37:25 +0000 Subject: [PATCH 0617/1077] Tony's new Pitzer test cases Updated Run_salt.bat Updated Makefile Tony's changes through 20130129a git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7400 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Form1.h | 1 + Phreeqc.cpp | 2 +- pitzer.cpp | 6 +++++- structures.cpp | 1 + transport.cpp | 2 +- utilities.cpp | 6 +++++- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Form1.h b/Form1.h index 7d238d5e..1056e753 100644 --- a/Form1.h +++ b/Form1.h @@ -746,6 +746,7 @@ namespace zdg_ui2 { // Create form Form ^graphOptions = gcnew Form; graphOptions->Text = "Chart options"; + graphOptions->ShowIcon = false; graphOptions->BringToFront(); graphOptions->MinimumSize = System::Drawing::Size(255, 230); graphOptions->MaximumSize = System::Drawing::Size(255, 230); diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e3eebff0..52289091 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1266,7 +1266,7 @@ void Phreeqc::init(void) pr.hdf = FALSE; pr.alkalinity = FALSE; status_on = true; - status_interval = 0; + status_interval = 40; status_timer = clock(); count_warnings = 0; /* ---------------------------------------------------------------------- diff --git a/pitzer.cpp b/pitzer.cpp index a4a612cf..aa879afc 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -744,7 +744,11 @@ C /* C Set DW0 */ - DW(TK); + //DW(TK); + //rho_0 = DW0; + //patm_x = VP; + DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); + VP = patm_x; for (i = 0; i < count_pitz_param; i++) { calc_pitz_param(pitz_params[i], TK, TR); diff --git a/structures.cpp b/structures.cpp index 2a057e0a..5c6cd612 100644 --- a/structures.cpp +++ b/structures.cpp @@ -27,6 +27,7 @@ clean_up(void) int i, j; #if defined MULTICHART chart_handler.End_timer(); + output_flush(); // Wait for charts to end while (0 != this->chart_handler.Get_active_charts()) { diff --git a/transport.cpp b/transport.cpp index 7fdac262..75ebe64a 100644 --- a/transport.cpp +++ b/transport.cpp @@ -563,6 +563,7 @@ transport(void) { if (i == first_c && count_cells > 1) kin_time /= 2; + cell_no = i; if (multi_Dflag) sprintf(token, "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", @@ -572,7 +573,6 @@ transport(void) "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, 0, i, max_iter); status(0, token); - cell_no = i; run_reactions(i, kin_time, NOMIX, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); diff --git a/utilities.cpp b/utilities.cpp index 4322ebfd..bbf6d1b8 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1415,7 +1415,11 @@ status(int count, const char *str, bool rk_string) return (OK); } t2 = clock(); - if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) + if (((state < ADVECTION && reaction_step < count_total_steps) || + (state == ADVECTION && (advection_step < count_ad_shifts || cell_no < count_cells)) || + (state == TRANSPORT && (transport_step < count_shifts || cell_no < count_cells + (stag_data->count_stag == 0 ? + 0 : stag_data->count_stag * count_cells + 2)))) + && (int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) return (OK); else status_timer = t2; From 2628e3aa045286f04a97dc476837a7b119ae5e69 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 30 Jan 2013 04:52:41 +0000 Subject: [PATCH 0618/1077] added NOTICE to configure git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7404 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 965 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 606 insertions(+), 359 deletions(-) diff --git a/Makefile b/Makefile index 9a6a98f3..78f33ce8 100644 --- a/Makefile +++ b/Makefile @@ -1,387 +1,634 @@ -# Makefile for PHREEQCPP -# -# Generates object files and executables for 2 versions of PHREEQCPP -# Release -# Debug -# -# Serial verisons: Release Debug -# -# Makefile sets CFG variable, cd's to appropriate directory, runs Makefile recursively -# Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC -# +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# src/Makefile. Generated from Makefile.in by configure. -PROGRAM = phreeqc +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. -CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else - SPOOL=>& - SPOOL2= -endif - -all: class_release class_debug - -Debug: class_debug -debug: class_debug -Class_debug: class_debug - -Release: class_release -release: class_release -Class_release: class_release - -Debug_64: class_debug_64 -debug_64: class_debug_64 -Class_debug_64: class_debug_64 - -Release_64: class_release_64 -release_64: class_release_64 -Class_release_64: class_release_64 +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. -CLASS_DEBUG_DIR = Class_debug -CLASS_DIR = Class_release -CLASS_DEBUG_64_DIR = Class_debug_64 -CLASS_64_DIR = Class_release_64 -MAKEFILE = Makefile -DEPDIR = .deps - -# ----------------------------------------------------------------------------- -# fixes shared object lookup error(SIGFPE floating point exception) -HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) -######################### -#### Serial Versions #### -######################### -.PHONY : Class_debug -class_debug: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) +pkgdatadir = $(datadir)/phreeqc +pkgincludedir = $(includedir)/phreeqc +pkglibdir = $(libdir)/phreeqc +pkglibexecdir = $(libexecdir)/phreeqc +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +bin_PROGRAMS = phreeqc$(EXEEXT) +am__append_1 = \ + cl1mp.cpp -.PHONY : Class_release -class_release: - mkdir -p $(CLASS_DIR) - cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) -.PHONY : Class_debug_64 -class_debug_64: - mkdir -p $(CLASS_DEBUG_64_DIR) - cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) +subdir = src +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(bindir)" +PROGRAMS = $(bin_PROGRAMS) +am__phreeqc_SOURCES_DIST = class_main.cpp cxxKinetics.cxx \ + cxxKinetics.h cxxMix.cxx cxxMix.h dumper.cpp dumper.h \ + Exchange.cxx Exchange.h ExchComp.cxx ExchComp.h GasComp.cxx \ + GasComp.h GasPhase.cxx GasPhase.h ISolution.cxx ISolution.h \ + ISolutionComp.cxx ISolutionComp.h Keywords.cpp Keywords.h \ + KineticsComp.cxx KineticsComp.h NameDouble.cxx NameDouble.h \ + NumKeyword.cxx NumKeyword.h Parser.cxx Parser.h PBasic.cpp \ + PBasic.h Phreeqc.cpp Phreeqc.h PHRQ_base.cxx PHRQ_base.h \ + PHRQ_io.cpp PHRQ_io.h PPassemblage.cxx PPassemblage.h \ + PPassemblageComp.cxx PPassemblageComp.h Pressure.cxx \ + Pressure.h Reaction.cxx Reaction.h ReadClass.cxx runner.cpp \ + runner.h Solution.cxx Solution.h SolutionIsotope.cxx \ + SolutionIsotope.h SSassemblage.cxx SSassemblage.h SS.cxx SS.h \ + SScomp.cxx SScomp.h StorageBin.cxx StorageBin.h \ + StorageBinList.cpp StorageBinList.h Surface.cxx Surface.h \ + SurfaceCharge.cxx SurfaceCharge.h SurfaceComp.cxx \ + SurfaceComp.h System.cxx System.h Temperature.cxx \ + Temperature.h Use.cpp Use.h Utils.cxx Utils.h advection.cpp \ + basicsubs.cpp cl1.cpp cvdense.cpp cvdense.h cvode.cpp cvode.h \ + dense.cpp dense.h dw.cpp gases.cpp global_structures.h \ + input.cpp integrate.cpp inverse.cpp isotopes.cpp kinetics.cpp \ + mainsubs.cpp model.cpp NA.h nvector.cpp nvector.h \ + nvector_serial.cpp nvector_serial.h parse.cpp phqalloc.cpp \ + phqalloc.h PHRQ_io_output.cpp phrqtype.h pitzer.cpp \ + pitzer_structures.cpp prep.cpp print.cpp read.cpp readtr.cpp \ + sit.cpp smalldense.cpp smalldense.h spread.cpp step.cpp \ + structures.cpp sundialsmath.cpp sundialsmath.h sundialstypes.h \ + tally.cpp tidy.cpp transport.cpp utilities.cpp cl1mp.cpp +am__objects_1 = cl1mp.$(OBJEXT) +am_phreeqc_OBJECTS = class_main.$(OBJEXT) cxxKinetics.$(OBJEXT) \ + cxxMix.$(OBJEXT) dumper.$(OBJEXT) Exchange.$(OBJEXT) \ + ExchComp.$(OBJEXT) GasComp.$(OBJEXT) GasPhase.$(OBJEXT) \ + ISolution.$(OBJEXT) ISolutionComp.$(OBJEXT) Keywords.$(OBJEXT) \ + KineticsComp.$(OBJEXT) NameDouble.$(OBJEXT) \ + NumKeyword.$(OBJEXT) Parser.$(OBJEXT) PBasic.$(OBJEXT) \ + Phreeqc.$(OBJEXT) PHRQ_base.$(OBJEXT) PHRQ_io.$(OBJEXT) \ + PPassemblage.$(OBJEXT) PPassemblageComp.$(OBJEXT) \ + Pressure.$(OBJEXT) Reaction.$(OBJEXT) ReadClass.$(OBJEXT) \ + runner.$(OBJEXT) Solution.$(OBJEXT) SolutionIsotope.$(OBJEXT) \ + SSassemblage.$(OBJEXT) SS.$(OBJEXT) SScomp.$(OBJEXT) \ + StorageBin.$(OBJEXT) StorageBinList.$(OBJEXT) \ + Surface.$(OBJEXT) SurfaceCharge.$(OBJEXT) \ + SurfaceComp.$(OBJEXT) System.$(OBJEXT) Temperature.$(OBJEXT) \ + Use.$(OBJEXT) Utils.$(OBJEXT) advection.$(OBJEXT) \ + basicsubs.$(OBJEXT) cl1.$(OBJEXT) cvdense.$(OBJEXT) \ + cvode.$(OBJEXT) dense.$(OBJEXT) dw.$(OBJEXT) gases.$(OBJEXT) \ + input.$(OBJEXT) integrate.$(OBJEXT) inverse.$(OBJEXT) \ + isotopes.$(OBJEXT) kinetics.$(OBJEXT) mainsubs.$(OBJEXT) \ + model.$(OBJEXT) nvector.$(OBJEXT) nvector_serial.$(OBJEXT) \ + parse.$(OBJEXT) phqalloc.$(OBJEXT) PHRQ_io_output.$(OBJEXT) \ + pitzer.$(OBJEXT) pitzer_structures.$(OBJEXT) prep.$(OBJEXT) \ + print.$(OBJEXT) read.$(OBJEXT) readtr.$(OBJEXT) sit.$(OBJEXT) \ + smalldense.$(OBJEXT) spread.$(OBJEXT) step.$(OBJEXT) \ + structures.$(OBJEXT) sundialsmath.$(OBJEXT) tally.$(OBJEXT) \ + tidy.$(OBJEXT) transport.$(OBJEXT) utilities.$(OBJEXT) \ + $(am__objects_1) +phreeqc_OBJECTS = $(am_phreeqc_OBJECTS) +phreeqc_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +phreeqc_DEPENDENCIES = $(am__DEPENDENCIES_1) +DEFAULT_INCLUDES = -I. +depcomp = $(SHELL) $(top_srcdir)/config/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +CXXLD = $(CXX) +CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ + -o $@ +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(phreeqc_SOURCES) +DIST_SOURCES = $(am__phreeqc_SOURCES_DIST) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run aclocal-1.11 +AMTAR = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run tar +AUTOCONF = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run autoconf +AUTOHEADER = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run autoheader +AUTOMAKE = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run automake-1.11 +AWK = gawk +CPPFLAGS = +CXX = g++ +CXXCPP = g++ -E +CXXDEPMODE = depmode=gcc3 +CXXFLAGS = -g -O2 +CYGPATH_W = echo +DEFS = -DPACKAGE_NAME=\"phreeqc\" -DPACKAGE_TARNAME=\"phreeqc\" -DPACKAGE_VERSION=\"3.0.0-7109\" -DPACKAGE_STRING=\"phreeqc\ 3.0.0-7109\" -DPACKAGE_BUGREPORT=\"dlpark@usgs.gov\" -DPACKAGE=\"phreeqc\" -DVERSION=\"3.0.0-7109\" -DNDEBUG=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FLOAT_H=1 -DHAVE_LIMITS_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STDDEF_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_STDLIB_H=1 -DHAVE_REALLOC=1 -DHAVE_MEMMOVE=1 -DHAVE_MEMSET=1 -DHAVE_STRCHR=1 -DHAVE_STRCSPN=1 -DHAVE_STRTOL=1 -DHAVE_FLOOR=1 -DHAVE_POW=1 -DHAVE_SQRT=1 -DHAVE_ISFINITE=/\*\*/ -DHAVE_FINITE=/\*\*/ -DHAVE_ISNAN=1 -DINVERSE_CL1MP=1 +DEPDIR = .deps +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /bin/grep -E +EXEEXT = +GREP = /bin/grep +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +LDFLAGS = +LIBGMP = -lgmp +LIBOBJS = +LIBS = +LTLIBOBJS = +MAKEINFO = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run makeinfo +MKDIR_P = /bin/mkdir -p +OBJEXT = o +PACKAGE = phreeqc +PACKAGE_BUGREPORT = dlpark@usgs.gov +PACKAGE_NAME = phreeqc +PACKAGE_STRING = phreeqc 3.0.0-7109 +PACKAGE_TARNAME = phreeqc +PACKAGE_VERSION = 3.0.0-7109 +PATH_SEPARATOR = : +POW_LIB = +SET_MAKE = +SHELL = /bin/sh +STRIP = +VERSION = 3.0.0-7109 +abs_builddir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/src +abs_srcdir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/src +abs_top_builddir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk +abs_top_srcdir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk +ac_ct_CXX = g++ +am__include = include +am__leading_dot = . +am__quote = +am__tar = ${AMTAR} chof - "$$tardir" +am__untar = ${AMTAR} xf - +bindir = ${exec_prefix}/bin +build_alias = +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host_alias = +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = /bin/mkdir -p +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqc -.PHONY : Class_release_64 -class_release_64: - mkdir -p $(CLASS_64_DIR) - cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) +# sources for phreeqc +phreeqc_SOURCES = class_main.cpp cxxKinetics.cxx cxxKinetics.h \ + cxxMix.cxx cxxMix.h dumper.cpp dumper.h Exchange.cxx \ + Exchange.h ExchComp.cxx ExchComp.h GasComp.cxx GasComp.h \ + GasPhase.cxx GasPhase.h ISolution.cxx ISolution.h \ + ISolutionComp.cxx ISolutionComp.h Keywords.cpp Keywords.h \ + KineticsComp.cxx KineticsComp.h NameDouble.cxx NameDouble.h \ + NumKeyword.cxx NumKeyword.h Parser.cxx Parser.h PBasic.cpp \ + PBasic.h Phreeqc.cpp Phreeqc.h PHRQ_base.cxx PHRQ_base.h \ + PHRQ_io.cpp PHRQ_io.h PPassemblage.cxx PPassemblage.h \ + PPassemblageComp.cxx PPassemblageComp.h Pressure.cxx \ + Pressure.h Reaction.cxx Reaction.h ReadClass.cxx runner.cpp \ + runner.h Solution.cxx Solution.h SolutionIsotope.cxx \ + SolutionIsotope.h SSassemblage.cxx SSassemblage.h SS.cxx SS.h \ + SScomp.cxx SScomp.h StorageBin.cxx StorageBin.h \ + StorageBinList.cpp StorageBinList.h Surface.cxx Surface.h \ + SurfaceCharge.cxx SurfaceCharge.h SurfaceComp.cxx \ + SurfaceComp.h System.cxx System.h Temperature.cxx \ + Temperature.h Use.cpp Use.h Utils.cxx Utils.h advection.cpp \ + basicsubs.cpp cl1.cpp cvdense.cpp cvdense.h cvode.cpp cvode.h \ + dense.cpp dense.h dw.cpp gases.cpp global_structures.h \ + input.cpp integrate.cpp inverse.cpp isotopes.cpp kinetics.cpp \ + mainsubs.cpp model.cpp NA.h nvector.cpp nvector.h \ + nvector_serial.cpp nvector_serial.h parse.cpp phqalloc.cpp \ + phqalloc.h PHRQ_io_output.cpp phrqtype.h pitzer.cpp \ + pitzer_structures.cpp prep.cpp print.cpp read.cpp readtr.cpp \ + sit.cpp smalldense.cpp smalldense.h spread.cpp step.cpp \ + structures.cpp sundialsmath.cpp sundialsmath.h sundialstypes.h \ + tally.cpp tidy.cpp transport.cpp utilities.cpp $(am__append_1) +LDADD = $(LIBGMP) +all: all-am -# Recursive make begins here -# -# ============================================================================= -# Significant suffixes [assuming Fortran 90 (.f90) source code]: -# Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: -# ============================================================================= +.SUFFIXES: +.SUFFIXES: .cpp .cxx .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; -.SUFFIXES : .o .c .cxx .cpp +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -# compilers +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done -# ----------------------------------------------------------------------------- -.c.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files -.cxx.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) +phreeqc$(EXEEXT): $(phreeqc_OBJECTS) $(phreeqc_DEPENDENCIES) + @rm -f phreeqc$(EXEEXT) + $(CXXLINK) $(phreeqc_OBJECTS) $(phreeqc_LDADD) $(LIBS) -.cpp.o : - test -z "$(DEPDIR)" || /bin/mkdir -p "$(DEPDIR)" - depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ - ${CXX} ${CXXFLAGS} -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ - mv -f $$depbase.Tpo $$depbase.Po +mostlyclean-compile: + -rm -f *.$(OBJEXT) -# ----------------------------------------------------------------------------- -#hdf options -#HDF5_ROOT=$(HOME)/../../usr -#HDF5_INCLUDES=-I$(HDF5_ROOT)/src -#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread +distclean-compile: + -rm -f *.tab.c -# ----------------------------------------------------------------------------- -# #define compile options +include ./$(DEPDIR)/ExchComp.Po +include ./$(DEPDIR)/Exchange.Po +include ./$(DEPDIR)/GasComp.Po +include ./$(DEPDIR)/GasPhase.Po +include ./$(DEPDIR)/ISolution.Po +include ./$(DEPDIR)/ISolutionComp.Po +include ./$(DEPDIR)/Keywords.Po +include ./$(DEPDIR)/KineticsComp.Po +include ./$(DEPDIR)/NameDouble.Po +include ./$(DEPDIR)/NumKeyword.Po +include ./$(DEPDIR)/PBasic.Po +include ./$(DEPDIR)/PHRQ_base.Po +include ./$(DEPDIR)/PHRQ_io.Po +include ./$(DEPDIR)/PHRQ_io_output.Po +include ./$(DEPDIR)/PPassemblage.Po +include ./$(DEPDIR)/PPassemblageComp.Po +include ./$(DEPDIR)/Parser.Po +include ./$(DEPDIR)/Phreeqc.Po +include ./$(DEPDIR)/Pressure.Po +include ./$(DEPDIR)/Reaction.Po +include ./$(DEPDIR)/ReadClass.Po +include ./$(DEPDIR)/SS.Po +include ./$(DEPDIR)/SSassemblage.Po +include ./$(DEPDIR)/SScomp.Po +include ./$(DEPDIR)/Solution.Po +include ./$(DEPDIR)/SolutionIsotope.Po +include ./$(DEPDIR)/StorageBin.Po +include ./$(DEPDIR)/StorageBinList.Po +include ./$(DEPDIR)/Surface.Po +include ./$(DEPDIR)/SurfaceCharge.Po +include ./$(DEPDIR)/SurfaceComp.Po +include ./$(DEPDIR)/System.Po +include ./$(DEPDIR)/Temperature.Po +include ./$(DEPDIR)/Use.Po +include ./$(DEPDIR)/Utils.Po +include ./$(DEPDIR)/advection.Po +include ./$(DEPDIR)/basicsubs.Po +include ./$(DEPDIR)/cl1.Po +include ./$(DEPDIR)/cl1mp.Po +include ./$(DEPDIR)/class_main.Po +include ./$(DEPDIR)/cvdense.Po +include ./$(DEPDIR)/cvode.Po +include ./$(DEPDIR)/cxxKinetics.Po +include ./$(DEPDIR)/cxxMix.Po +include ./$(DEPDIR)/dense.Po +include ./$(DEPDIR)/dumper.Po +include ./$(DEPDIR)/dw.Po +include ./$(DEPDIR)/gases.Po +include ./$(DEPDIR)/input.Po +include ./$(DEPDIR)/integrate.Po +include ./$(DEPDIR)/inverse.Po +include ./$(DEPDIR)/isotopes.Po +include ./$(DEPDIR)/kinetics.Po +include ./$(DEPDIR)/mainsubs.Po +include ./$(DEPDIR)/model.Po +include ./$(DEPDIR)/nvector.Po +include ./$(DEPDIR)/nvector_serial.Po +include ./$(DEPDIR)/parse.Po +include ./$(DEPDIR)/phqalloc.Po +include ./$(DEPDIR)/pitzer.Po +include ./$(DEPDIR)/pitzer_structures.Po +include ./$(DEPDIR)/prep.Po +include ./$(DEPDIR)/print.Po +include ./$(DEPDIR)/read.Po +include ./$(DEPDIR)/readtr.Po +include ./$(DEPDIR)/runner.Po +include ./$(DEPDIR)/sit.Po +include ./$(DEPDIR)/smalldense.Po +include ./$(DEPDIR)/spread.Po +include ./$(DEPDIR)/step.Po +include ./$(DEPDIR)/structures.Po +include ./$(DEPDIR)/sundialsmath.Po +include ./$(DEPDIR)/tally.Po +include ./$(DEPDIR)/tidy.Po +include ./$(DEPDIR)/transport.Po +include ./$(DEPDIR)/utilities.Po -# ----------------------------------------------------------------------------- -# #define gmp for inverse modeling -# comment the following lines to remove multiprecision option +.cpp.o: + $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ +# $(CXXCOMPILE) -c -o $@ $< -# ----------------------------------------------------------------------------- -#efence for debugging -EFENCE_LIB=-L$(HOME)/packages/efence +.cpp.obj: + $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ +# $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` -# ----------------------------------------------------------------------------- -# 4 Versions -# ----------------------------------------------------------------------------- -ifeq ($(CFG), CLASS_DEBUG) - INVERSE_CL1MP=FALSE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o -# CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a - endif - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = .. - INCLUDES = -I.. - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif +.cxx.o: + $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< + $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ +# $(CXXCOMPILE) -c -o $@ $< -ifeq ($(CFG), CLASS_RELEASE) - INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o -# CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a - endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif +.cxx.obj: + $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` + $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +# source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) \ +# $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` -ifeq ($(CFG), CLASS_DEBUG_64) - DEFINES = -DUSE_PHRQ_ALLOC # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS -ifeq ($(CFG), CLASS_RELEASE_64) - DEFINES = -DNDEBUG # $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../phreeqc - INCLUDES = -I../phreeqc -I.. - CXX = g++ - CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique -# ----------------------------------------------------------------------------- -# +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" -COMMON_COBJS = \ - advection.o \ - basicsubs.o \ - cl1.o \ - cvdense.o \ - cvode.o \ - dense.o \ - dw.o \ - gases.o \ - input.o \ - integrate.o \ - inverse.o \ - isotopes.o \ - kinetics.o \ - mainsubs.o \ - model.o \ - nvector.o \ - nvector_serial.o \ - parse.o \ - PHRQ_io_output.o \ - phqalloc.o \ - pitzer.o \ - pitzer_structures.o \ - prep.o \ - print.o \ - read.o \ - readtr.o \ - sit.o \ - smalldense.o \ - spread.o \ - step.o \ - structures.o \ - sundialsmath.o \ - tally.o \ - tidy.o \ - transport.o \ - utilities.o +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -MAIN_FILE = main.o +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: + for dir in "$(DESTDIR)$(bindir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am -CLASS_FILES = \ - class_main.o \ - Phreeqc.o +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-generic mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ + clean-generic ctags distclean distclean-compile \ + distclean-generic distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-binPROGRAMS \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-binPROGRAMS -COMMON_CXXOBJS = \ - dumper.o \ - Exchange.o \ - ExchComp.o \ - GasPhase.o \ - GasComp.o \ - ISolution.o \ - ISolutionComp.o \ - Keywords.o \ - KineticsComp.o \ - cxxKinetics.o \ - cxxMix.o \ - NameDouble.o \ - NumKeyword.o \ - Parser.o \ - PBasic.o \ - PHRQ_base.o \ - PHRQ_io.o \ - PPassemblageComp.o \ - PPassemblage.o \ - Pressure.o \ - Reaction.o \ - ReadClass.o \ - runner.o \ - Solution.o \ - SolutionIsotope.o \ - SSassemblage.o \ - SScomp.o \ - SS.o \ - StorageBin.o \ - StorageBinList.o \ - Surface.o \ - SurfaceCharge.o \ - SurfaceComp.o \ - System.o \ - Temperature.o \ - Use.o \ - Utils.o - -# ----------------------------------------------------------------------------- -# Assign dependents to target on dependency line & link options on command -# line. Command line is initiated with a tab. ($@ is an internal macro for -# the current target.) - -${PROGRAM} : ${OBJECT_FILES} -# ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} - ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} - @echo; echo Done making for phreeqc -# ----------------------------------------------------------------------------- -# Module dependency list -# ----------------------------------------------------------------------------- -# -# CXX files -# --include $(DEPDIR)/cxxKinetics.Po --include $(DEPDIR)/cxxMix.Po --include $(DEPDIR)/Exchange.Po --include $(DEPDIR)/ExchComp.Po --include $(DEPDIR)/GasComp.Po --include $(DEPDIR)/GasPhase.Po --include $(DEPDIR)/ISolutionComp.Po --include $(DEPDIR)/ISolution.Po --include $(DEPDIR)/KineticsComp.Po --include $(DEPDIR)/NameDouble.Po --include $(DEPDIR)/NumKeyword.Po --include $(DEPDIR)/Parser.Po --include $(DEPDIR)/PHRQ_base.Po --include $(DEPDIR)/PPassemblageComp.Po --include $(DEPDIR)/PPassemblage.Po --include $(DEPDIR)/Pressure.Po --include $(DEPDIR)/Reaction.Po --include $(DEPDIR)/ReadClass.Po --include $(DEPDIR)/Solution.Po --include $(DEPDIR)/SolutionIsotope.Po --include $(DEPDIR)/SSassemblage.Po --include $(DEPDIR)/SScomp.Po --include $(DEPDIR)/SS.Po --include $(DEPDIR)/StorageBin.Po --include $(DEPDIR)/SurfaceCharge.Po --include $(DEPDIR)/SurfaceComp.Po --include $(DEPDIR)/Surface.Po --include $(DEPDIR)/System.Po --include $(DEPDIR)/Temperature.Po --include $(DEPDIR)/Utils.Po --include $(DEPDIR)/ChartHandler.Po --include $(DEPDIR)/ChartObject.Po --include $(DEPDIR)/class_main.Po --include $(DEPDIR)/CurveObject.Po --include $(DEPDIR)/dumper.Po --include $(DEPDIR)/Keywords.Po --include $(DEPDIR)/PBasic.Po --include $(DEPDIR)/Phreeqc.Po --include $(DEPDIR)/PHRQ_io.Po --include $(DEPDIR)/runner.Po --include $(DEPDIR)/StorageBinList.Po --include $(DEPDIR)/Use.Po --include $(DEPDIR)/advection.Po --include $(DEPDIR)/basicsubs.o --include $(DEPDIR)/cl1.Po --include $(DEPDIR)/cl1mp.Po --include $(DEPDIR)/cvdense.Po --include $(DEPDIR)/cvode.Po --include $(DEPDIR)/dense.Po --include $(DEPDIR)/dw.Po --include $(DEPDIR)/gases.Po --include $(DEPDIR)/input.Po --include $(DEPDIR)/integrate.Po --include $(DEPDIR)/inverse.Po --include $(DEPDIR)/isotopes.Po --include $(DEPDIR)/kinetics.Po --include $(DEPDIR)/mainsubs.Po --include $(DEPDIR)/model.Po --include $(DEPDIR)/nvector.Po --include $(DEPDIR)/nvector_serial.Po --include $(DEPDIR)/parse.Po --include $(DEPDIR)/phqalloc.Po --include $(DEPDIR)/PHRQ_io_output.Po --include $(DEPDIR)/pitzer.Po --include $(DEPDIR)/pitzer_structures.Po --include $(DEPDIR)/prep.Po --include $(DEPDIR)/print.Po --include $(DEPDIR)/read.Po --include $(DEPDIR)/readtr.Po --include $(DEPDIR)/sit.Po --include $(DEPDIR)/smalldense.Po --include $(DEPDIR)/spread.Po --include $(DEPDIR)/step.Po --include $(DEPDIR)/structures.Po --include $(DEPDIR)/sundialsmath.Po --include $(DEPDIR)/tally.Po --include $(DEPDIR)/tidy.Po --include $(DEPDIR)/transport.Po --include $(DEPDIR)/utilities.Po - -# ----------------------------------------------------------------------------- -clean: - rm -rf Class_release Class_debug Class_release_64 Class_debug_64 - -dependencies: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp - -tester: - cd ../mytest; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make -k -j 4 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - svn status -q ../mytest - svn status -q ../examples - -#ld-option -# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) -comma=, -ld-option = $(shell if $(CC) $(1) \ - -nostdlib -o /dev/null -xc /dev/null \ - > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) - -# ============================================================================= -# End of makefile. -# ============================================================================= +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: From 4cb545599e33f23beff90e32a63a3a35c77dfdd6 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 31 Jan 2013 05:06:34 +0000 Subject: [PATCH 0619/1077] added some UNREFERENCED_PARAMETER; removed g_spread_sheet git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7422 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 52289091..92fac58c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1383,9 +1383,6 @@ void Phreeqc::init(void) dump_file_name = NULL; remove_unstable_phases = FALSE; // auto screen_string; -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif spread_length = 10; /* ---------------------------------------------------------------------- */ /* @@ -2631,9 +2628,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) //dump_file_name = NULL; //remove_unstable_phases = FALSE; // auto screen_string; -#ifdef PHREEQCI_GUI - struct spread_sheet g_spread_sheet; -#endif spread_length = 10; /* ---------------------------------------------------------------------- */ /* From a1d93167aee4e8c6cf9bcda89a79eda4e406563f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Feb 2013 19:25:05 +0000 Subject: [PATCH 0620/1077] Tony's changes to the status timer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7438 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- transport.cpp | 9 +++++++-- utilities.cpp | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 281efe24..caff613b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1358,7 +1358,7 @@ protected: LDBLE interlayer_tortf; /* tortuosity_factor in interlayer porosity, Dpil = Dw / interlayer_tortf */ - int cell_no; + int cell_no, mixrun; /*---------------------------------------------------------------------- * Advection data *---------------------------------------------------------------------- */ diff --git a/transport.cpp b/transport.cpp index 75ebe64a..f4889805 100644 --- a/transport.cpp +++ b/transport.cpp @@ -357,6 +357,7 @@ transport(void) (transport_step - 1) * timest + (j - 1) * kin_time; rate_sim_time = rate_sim_time_start + kin_time; + mixrun = j; if (multi_Dflag) sprintf(token, "Transport step %3d. Multicomponent diffusion run %3d.", @@ -394,6 +395,8 @@ transport(void) if (iterations > max_iter) max_iter = iterations; + cell_no = i; + mixrun = j; if (multi_Dflag) sprintf(token, "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", @@ -404,7 +407,6 @@ transport(void) transport_step, j, i, max_iter); status(0, token); - cell_no = i; run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag) fill_spec(i); @@ -564,6 +566,7 @@ transport(void) if (i == first_c && count_cells > 1) kin_time /= 2; cell_no = i; + mixrun = 0; if (multi_Dflag) sprintf(token, "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", @@ -669,6 +672,8 @@ transport(void) { if (iterations > max_iter) max_iter = iterations; + cell_no = i; + mixrun = j; if (multi_Dflag) sprintf(token, "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", @@ -678,7 +683,7 @@ transport(void) "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", transport_step, j, i, max_iter); status(0, token); - cell_no = i; + run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); diff --git a/utilities.cpp b/utilities.cpp index bbf6d1b8..e07a0cbb 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1417,8 +1417,8 @@ status(int count, const char *str, bool rk_string) t2 = clock(); if (((state < ADVECTION && reaction_step < count_total_steps) || (state == ADVECTION && (advection_step < count_ad_shifts || cell_no < count_cells)) || - (state == TRANSPORT && (transport_step < count_shifts || cell_no < count_cells + (stag_data->count_stag == 0 ? - 0 : stag_data->count_stag * count_cells + 2)))) + (state == TRANSPORT && (transport_step < count_shifts || (mixrun < nmix && + cell_no < count_cells)))) && (int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) return (OK); else From c9380090edf11fbbbe90492014cd68571a9202c7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Feb 2013 20:54:30 +0000 Subject: [PATCH 0621/1077] There was a long gap before this was checked in. I think the load balancing by cell is done. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7444 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 9f7587b9..4d1333f4 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -145,7 +145,7 @@ bool StorageBinList::Read(CParser & parser) bool useLastLine(false); opt_save = CParser::OPT_DEFAULT; - + StorageBinListItem cell_list; for (;;) { int opt; @@ -161,7 +161,7 @@ bool StorageBinList::Read(CParser & parser) // Select StorageBinListItem StorageBinListItem *item = NULL; - StorageBinListItem cell_list; + //StorageBinListItem cell_list; switch (opt) { case 0: @@ -264,14 +264,14 @@ bool StorageBinList::Read(CParser & parser) break; case 14: case 15: - if (cell_list.Get_numbers().empty()) - { - this->SetAll(true); - } - else - { - this->TransferAll(cell_list); - } + //if (cell_list.Get_numbers().empty()) + //{ + // this->SetAll(true); + //} + //else + //{ + //this->TransferAll(cell_list); + //} break; default: case CParser::OPT_DEFAULT: @@ -287,6 +287,19 @@ bool StorageBinList::Read(CParser & parser) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } + + // Now check to see if cell_list defined + if (cell_list.Get_defined()) + { + if (cell_list.Get_numbers().empty()) + { + this->SetAll(true); + } + else + { + this->TransferAll(cell_list); + } + } return(return_value); } From b3e59d93959e23a1a9f5fe7cc2178ea6e9712824 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Feb 2013 16:08:13 +0000 Subject: [PATCH 0622/1077] has _DEBUG #defines for extended ascii/ANSI character set to avoid assert. isdigit, isalpha, isspace, islower, isupper git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7448 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Parser.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Parser.h b/Parser.h index 3b7e135d..3bf093a1 100644 --- a/Parser.h +++ b/Parser.h @@ -17,8 +17,13 @@ #include "Keywords.h" #include "PHRQ_io.h" - - +#ifdef _DEBUG +#define isspace(a) isspace((a) < -1 ? (a) + 256 : (a)) +#define isupper(a) isupper((a) < -1 ? (a) + 256 : (a)) +#define islower(a) islower((a) < -1 ? (a) + 256 : (a)) +#define isdigit(a) isdigit((a) < -1 ? (a) + 256 : (a)) +#define isalpha(a) isalpha((a) < -1 ? (a) + 256 : (a)) +#endif class CParser: public PHRQ_base { From 047414274f4449e3f386fcb892afd135dc84806f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Feb 2013 22:07:33 +0000 Subject: [PATCH 0623/1077] Working on Phreeqc copy Running ion association model with equilibrium phases Running Pitzer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7449 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 177 ++++++++++++++++++------------------------ Phreeqc.h | 5 +- global_structures.h | 1 + pitzer.cpp | 2 +- pitzer_structures.cpp | 46 +++++++++-- prep.cpp | 2 +- sit.cpp | 2 +- structures.cpp | 14 +++- 8 files changed, 136 insertions(+), 113 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 92fac58c..d8beac53 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1860,6 +1860,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /*---------------------------------------------------------------------- * Mix *---------------------------------------------------------------------- */ + // Should be empty after each END // auto Rxn_mix_map; // auto Dispersion_mix_map; // auto Rxn_solution_mix_map; @@ -2079,30 +2080,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) s_o2 = NULL; */ // logk -#ifdef SKIP - count_logk = pSrc->count_logk; - max_logk = pSrc->max_logk; - logk = (struct logk **) free_check_null(logk); - logk = (struct logk **) PHRQ_malloc((size_t) max_logk * sizeof(struct logk *)); - if (logk == NULL) malloc_error(); - for (int i = 0; i < count_logk; i++) - { - logk[i] = (struct logk *) PHRQ_malloc((size_t) max_logk * sizeof(struct logk)); - memcpy(logk[i], pSrc->logk[i], sizeof(struct logk)); - logk[i]->name = string_hsave(pSrc->logk[i]->name); - logk[i]->add_logk = NULL; - if (logk[i]->count_add_logk > 0) - { - logk[i]->add_logk = (struct name_coef *) PHRQ_malloc((size_t) logk[i]->count_add_logk * sizeof(struct name_coef)); - if (logk[i]->add_logk == NULL) malloc_error(); - for (int j = 0; j < logk[i]->count_add_logk; j++) - { - logk[i]->add_logk[j].coef = pSrc->logk[i]->add_logk[j].coef; - logk[i]->add_logk[j].name = string_hsave( pSrc->logk[i]->add_logk[j].name); - } - } - } -#endif for (int i = 0; i < pSrc->count_logk; i++) { char * name = string_duplicate(pSrc->logk[i]->name); @@ -2134,6 +2111,8 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) { s_ptr->mole_balance = string_hsave(pSrc->s[i]->mole_balance); } + s_ptr->primary = NULL; + s_ptr->secondary = NULL; //add_logk s_ptr->add_logk = NULL; if (s_ptr->count_add_logk > 0) @@ -2147,28 +2126,43 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } //next_elt - cxxNameDouble next_elt(pSrc->s[i]->next_elt); - s_ptr->next_elt = NameDouble2elt_list(next_elt); + s_ptr->next_elt = NULL; + if (pSrc->s[i]->next_elt) + { + cxxNameDouble next_elt(pSrc->s[i]->next_elt); + s_ptr->next_elt = NameDouble2elt_list(next_elt); + } //next_secondary - cxxNameDouble next_secondary(pSrc->s[i]->next_secondary); - s_ptr->next_secondary = NameDouble2elt_list(next_secondary); + s_ptr->next_secondary = NULL; + if (pSrc->s[i]->next_secondary) + { + cxxNameDouble next_secondary(pSrc->s[i]->next_secondary); + s_ptr->next_secondary = NameDouble2elt_list(next_secondary); + } //next_sys_total - cxxNameDouble next_sys_total(pSrc->s[i]->next_sys_total); - s_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + s_ptr->next_sys_total = NULL; + if (pSrc->s[i]->next_sys_total) + { + cxxNameDouble next_sys_total(pSrc->s[i]->next_sys_total); + s_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + } //rxn + s_ptr->rxn = NULL; if (pSrc->s[i]->rxn != NULL) { cxxChemRxn rxn(pSrc->s[i]->rxn); s_ptr->rxn = cxxChemRxn2rxn(rxn); //s_ptr->rxn = rxn_copy_operator(pSrc->s[i]->rxn); } - //rxn_s + //rxn_s + s_ptr->rxn_s = NULL; if (pSrc->s[i]->rxn_s != NULL) { cxxChemRxn rxn_s(pSrc->s[i]->rxn_s); s_ptr->rxn_s = cxxChemRxn2rxn(rxn_s); } //rxn_x + s_ptr->rxn_x = NULL; if (pSrc->s[i]->rxn_x != NULL) { cxxChemRxn rxn_x(pSrc->s[i]->rxn_x); @@ -2190,49 +2184,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) count_phases = 0; max_phases = MAX_PHASES; */ -#ifdef SKIP - count_phases = pSrc->count_phases; - max_phases = pSrc->max_phases; - phases = (struct phase **) free_check_null(phases); - phases = (struct phase **) PHRQ_malloc((size_t) max_phases * sizeof(struct phase *)); - if (phases == NULL) malloc_error(); - for (int i = 0; i < count_phases; i++) - { - phases[i] = (struct phase *) PHRQ_malloc( sizeof(struct phase)); - if (phases[i] == NULL) malloc_error(); - memcpy(phases[i], pSrc->phases[i], sizeof(struct phase)); - // clean up pointers - phases[i]->name = string_hsave(pSrc->phases[i]->name); - phases[i]->formula = string_hsave(pSrc->phases[i]->formula); - //add_logk - phases[i]->add_logk = NULL; - if (phases[i]->count_add_logk > 0) - { - phases[i]->add_logk = (struct name_coef *) PHRQ_malloc((size_t) pSrc->phases[i]->count_add_logk * sizeof(struct name_coef)); - if (phases[i]->add_logk == NULL) malloc_error(); - for (int j = 0; j < phases[i]->count_add_logk; j++) - { - phases[i]->add_logk[j].coef = pSrc->phases[i]->add_logk[j].coef; - phases[i]->add_logk[j].name = string_hsave( pSrc->phases[i]->add_logk[j].name); - } - } - //next_elt - cxxNameDouble next_elt(pSrc->phases[i]->next_elt); - phases[i]->next_elt = NameDouble2elt_list(next_elt); - //next_sys_total - cxxNameDouble next_sys_total(pSrc->phases[i]->next_sys_total); - phases[i]->next_sys_total = NameDouble2elt_list(next_sys_total); - //rxn - cxxChemRxn rxn(pSrc->phases[i]->rxn); - phases[i]->rxn = cxxChemRxn2rxn(rxn); - //rxn_s - cxxChemRxn rxn_s(pSrc->phases[i]->rxn_s); - phases[i]->rxn_s = cxxChemRxn2rxn(rxn_s); - //rxn_x - cxxChemRxn rxn_x(pSrc->phases[i]->rxn_x); - phases[i]->rxn_x = cxxChemRxn2rxn(rxn_x); - } -#endif for (int i = 0; i < pSrc->count_phases; i++) { struct phase *phase_ptr = phase_store(pSrc->phases[i]->name); @@ -2253,24 +2204,35 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } //next_elt - cxxNameDouble next_elt(pSrc->phases[i]->next_elt); - phase_ptr->next_elt = NameDouble2elt_list(next_elt); + phase_ptr->next_elt = NULL; + if (pSrc->phases[i]->next_elt) + { + cxxNameDouble next_elt(pSrc->phases[i]->next_elt); + phase_ptr->next_elt = NameDouble2elt_list(next_elt); + } //next_sys_total - cxxNameDouble next_sys_total(pSrc->phases[i]->next_sys_total); - phase_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + phase_ptr->next_sys_total = NULL; + if (pSrc->phases[i]->next_sys_total) + { + cxxNameDouble next_sys_total(pSrc->phases[i]->next_sys_total); + phase_ptr->next_sys_total = NameDouble2elt_list(next_sys_total); + } //rxn + phase_ptr->rxn = NULL; if (pSrc->phases[i]->rxn != NULL) { cxxChemRxn rxn(pSrc->phases[i]->rxn); phase_ptr->rxn = cxxChemRxn2rxn(rxn); } //rxn_s + phase_ptr->rxn_s = NULL; if (pSrc->phases[i]->rxn_s != NULL) { cxxChemRxn rxn_s(pSrc->phases[i]->rxn_s); phase_ptr->rxn_s = cxxChemRxn2rxn(rxn_s); } //rxn_x + phase_ptr->rxn_x = NULL; if (pSrc->phases[i]->rxn_x != NULL) { cxxChemRxn rxn_x(pSrc->phases[i]->rxn_x); @@ -2307,12 +2269,14 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) master[i]->unknown = NULL; master[i]->s = s_store(pSrc->master[i]->s->name, pSrc->master[i]->s->z, false); //rxn_primary + master[i]->rxn_primary = NULL; if (pSrc->master[i]->rxn_primary != NULL) { cxxChemRxn rxn_primary(pSrc->master[i]->rxn_primary); master[i]->rxn_primary = cxxChemRxn2rxn(rxn_primary); } //rxn_secondary + master[i]->rxn_secondary = NULL; if (pSrc->master[i]->rxn_secondary != NULL) { cxxChemRxn rxn_secondary(pSrc->master[i]->rxn_secondary); @@ -2538,25 +2502,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) debug_diffuse_layer = FALSE; debug_inverse = FALSE; */ -#ifdef SKIP -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -#else - inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -#endif -#endif inv_tol_default = pSrc->inv_tol_default; itmax = pSrc->itmax; max_tries = pSrc->max_tries; -#ifdef SKIP -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#else - ineq_tol = pow((double) 10, (double) -DBL_DIG); -#endif -#endif ineq_tol = pSrc->ineq_tol; convergence_tolerance = pSrc->convergence_tolerance; step_size = pSrc->step_size; @@ -2678,7 +2626,11 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) struct calculate_value *calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); memcpy(calculate_value_ptr, pSrc->calculate_value[i], sizeof(struct calculate_value)); calculate_value_ptr->value = pSrc->calculate_value[i]->value; - calculate_value_ptr->commands = string_duplicate(pSrc->calculate_value[i]->commands); + calculate_value_ptr->commands = NULL; + if (pSrc->calculate_value[i]->commands) + { + calculate_value_ptr->commands = string_duplicate(pSrc->calculate_value[i]->commands); + } calculate_value_ptr->new_def = TRUE; calculate_value_ptr->calculated = FALSE; calculate_value_ptr->linebase = NULL; @@ -2934,9 +2886,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) VP = 0; DW0 = 0; #endif -#ifdef TODO_PITZER -#endif - + ICON = pSrc->ICON; /* pitz_params = NULL; count_pitz_param = 0; @@ -2944,7 +2894,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) */ for (int i = 0; i < pSrc->count_pitz_param; i++) { - pitz_param_store(pSrc->pitz_params[i]); + pitz_param_store(pSrc->pitz_params[i], true); } // auto pitz_param_map @@ -2977,7 +2927,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) DK[i] = 0.0; } */ - pitzer_tidy(); #ifdef PHREEQ98 int connect_simulations, graph_initial_solutions; @@ -3090,6 +3039,34 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) keycount.push_back(0); } #endif + // make sure new_model gets set + this->keycount[Keywords::KEY_SOLUTION_SPECIES] = 1; this->tidy_model(); return; } +// Operator overloaded using a member function +Phreeqc &Phreeqc::operator=(const Phreeqc &rhs) +{ + if (this == &rhs) // Same object? + return *this; + + // clean up this here + this->clean_up(); + + this->free_check_null(default_data_base); + this->free_check_null(sformatf_buffer); + + this->PHRQ_free_all(); + if (this->phrq_io == &this->ioInstance) + { + this->phrq_io->clear_istream(); + this->phrq_io->close_ostreams(); + } + + // copy Phreeqc object to this + this->phrq_io = rhs.phrq_io; + this->init(); + this->initialize(); + this->InternalCopy(&rhs); + return *this; +} diff --git a/Phreeqc.h b/Phreeqc.h index caff613b..c2a0b412 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -64,6 +64,7 @@ public: Phreeqc(PHRQ_io *io = NULL); Phreeqc(const Phreeqc &src); void InternalCopy(const Phreeqc *pSrc); + Phreeqc &operator=(const Phreeqc &rhs); ~Phreeqc(void); public: @@ -493,8 +494,8 @@ public: // pitzer.cpp ------------------------------- struct pitz_param *pitz_param_read(char *string, int n); - void pitz_param_store(struct pitz_param *pzp_ptr); - void sit_param_store(struct pitz_param *pzp_ptr); + void pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy); + void sit_param_store(struct pitz_param *pzp_ptr, bool force_copy); struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); struct theta_param *theta_param_alloc(void); int theta_param_init(struct theta_param *theta_param_ptr); diff --git a/global_structures.h b/global_structures.h index c22aeed6..2476ff0d 100644 --- a/global_structures.h +++ b/global_structures.h @@ -607,6 +607,7 @@ public: } struct rxn_token *next_token; next_token = rxn->token; + this->tokens.push_back(*next_token++); while (next_token->s != NULL) { this->tokens.push_back(*next_token++); diff --git a/pitzer.cpp b/pitzer.cpp index aa879afc..1f93fb58 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -636,7 +636,7 @@ read_pitzer(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - pitz_param_store(pzp_ptr); + pitz_param_store(pzp_ptr, false); } break; case OPTION_ERROR: diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 6fd15e9c..f433d241 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -136,7 +136,7 @@ pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr) /* ---------------------------------------------------------------------- */ void Phreeqc:: -pitz_param_store(struct pitz_param *pzp_ptr) +pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy) /* ---------------------------------------------------------------------- */ { /* @@ -188,8 +188,25 @@ pitz_param_store(struct pitz_param *pzp_ptr) count_pitz_param, &max_pitz_param, sizeof(struct pitz_param *)); } - - pitz_params[count_pitz_param] = pzp_ptr; + if (force_copy) + { + pitz_params[count_pitz_param] = pitz_param_duplicate(pzp_ptr); + // clean up pointers + // species + for (i = 0; i < 3; i++) + { + if (pzp_ptr->species[i] != NULL) + { + pitz_params[count_pitz_param]->species[i] = string_hsave(pzp_ptr->species[i]); + } + } + // thetas + pitz_params[count_pitz_param]->thetas = NULL; + } + else + { + pitz_params[count_pitz_param] = pzp_ptr; + } pitz_param_map[key] = count_pitz_param; count_pitz_param++; } @@ -197,7 +214,7 @@ pitz_param_store(struct pitz_param *pzp_ptr) /* ---------------------------------------------------------------------- */ void Phreeqc:: -sit_param_store(struct pitz_param *pzp_ptr) +sit_param_store(struct pitz_param *pzp_ptr, bool force_copy) /* ---------------------------------------------------------------------- */ { /* @@ -247,8 +264,25 @@ sit_param_store(struct pitz_param *pzp_ptr) count_sit_param, &max_sit_param, sizeof(struct pitz_param *)); } - - sit_params[count_sit_param] = pzp_ptr; + if (force_copy) + { + sit_params[count_sit_param] = pitz_param_duplicate(pzp_ptr); + // clean up pointers + // species + for (i = 0; i < 3; i++) + { + if (pzp_ptr->species[i] != NULL) + { + sit_params[count_sit_param]->species[i] = string_hsave(pzp_ptr->species[i]); + } + } + // thetas + sit_params[count_sit_param]->thetas = NULL; + } + else + { + sit_params[count_sit_param] = pzp_ptr; + } sit_param_map[key] = count_sit_param; count_sit_param++; } diff --git a/prep.cpp b/prep.cpp index 04471c7d..6bdd7558 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1246,7 +1246,7 @@ build_model(void) } if (debug_prep == TRUE) { - output_msg(sformatf( "\tElement composition\n", + output_msg(sformatf( "\tElement composition %s\n", trxn.token[0].s->name)); for (j = 0; j < count_elts; j++) { diff --git a/sit.cpp b/sit.cpp index b34024fb..67cfc1ee 100644 --- a/sit.cpp +++ b/sit.cpp @@ -198,7 +198,7 @@ read_sit(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - sit_param_store(pzp_ptr); + sit_param_store(pzp_ptr, false); } break; case OPTION_ERROR: diff --git a/structures.cpp b/structures.cpp index 5c6cd612..6d3c5810 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1771,14 +1771,24 @@ cxxChemRxn2rxn(cxxChemRxn &cr) */ for (int i = 0; i < (int) cr.Get_tokens().size(); i++) { - cr.Get_tokens()[i].s = s_store(cr.Get_tokens()[i].s->name, cr.Get_tokens()[i].s->z, FALSE); + if (cr.Get_tokens()[i].s != NULL) + { + cr.Get_tokens()[i].s = s_store(cr.Get_tokens()[i].s->name, cr.Get_tokens()[i].s->z, FALSE); + } if (cr.Get_tokens()[i].name != NULL) { cr.Get_tokens()[i].name = string_hsave(cr.Get_tokens()[i].name); } else { - cr.Get_tokens()[i].name = string_hsave(cr.Get_tokens()[i].s->name); + if (cr.Get_tokens()[i].s != NULL) + { + cr.Get_tokens()[i].name = string_hsave(cr.Get_tokens()[i].s->name); + } + else + { + cr.Get_tokens()[i].name=NULL; + } } } From fc1c2b1155005ca5d322d46630f7d788e7c51ad7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 7 Feb 2013 23:03:05 +0000 Subject: [PATCH 0624/1077] class main to test copy. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7450 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/class_main.cpp b/class_main.cpp index 7da4e96a..4c68addd 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -63,8 +63,95 @@ unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. Phreeqc phreeqc_instance; return phreeqc_instance.main_method(argc, argv); } +//#define TEST_COPY +#ifdef TEST_COPY +int Phreeqc:: +main_method(int argc, char *argv[]) +/* + * Main program for PHREEQC + */ +{ + int errors; + std::istream *db_cookie = NULL; + std::istream *input_cookie = NULL; +#if defined(WIN32_MEMORY_DEBUG) + int tmpDbgFlag; + /* + * Set the debug-heap flag to keep freed blocks in the + * heap's linked list - This will allow us to catch any + * inadvertent use of freed memory + */ + tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); + //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; + tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; + ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; + _CrtSetDbgFlag(tmpDbgFlag); + //_crtBreakAlloc = 9482; +#endif + + phast = FALSE; +/* + * Open input/output files + */ + errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); + if (errors != 0) + { + return errors; + } +#ifdef DOS + write_banner(); +#endif + +/* + * Initialize arrays + */ + errors = do_initialize(); + if (errors != 0) + { + return errors; + } +/* + * Load database into memory + */ + this->phrq_io->push_istream(db_cookie); + errors = read_database(); + this->phrq_io->clear_istream(); + + if (errors != 0) + { + return errors; + } + Phreeqc MyCopy; + MyCopy = *this; + //this->clean_up(); +/* + * Read input data for simulation + */ + + MyCopy.phrq_io->push_istream(input_cookie); + errors = MyCopy.run_simulations(); + + //Phreeqc mycopy(*this); + MyCopy.phrq_io->clear_istream(); + + if (errors != 0) + { + return errors; + } +/* + * Display successful status + */ + pr.headings = TRUE; + errors = do_status(); + if (errors != 0) + { + return errors; + } + return 0; +} +#else int Phreeqc:: main_method(int argc, char *argv[]) /* @@ -149,7 +236,7 @@ main_method(int argc, char *argv[]) } return 0; } - +#endif //TEST_COPY /* ---------------------------------------------------------------------- */ int Phreeqc:: write_banner(void) From f38caf062ef5d88a94ae545df647bb19d1a4c4a7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 8 Feb 2013 20:18:17 +0000 Subject: [PATCH 0625/1077] Lost revisions to model.cpp in reorg. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7452 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 119 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 35 deletions(-) diff --git a/model.cpp b/model.cpp index 9f616d8a..6d5eda0f 100644 --- a/model.cpp +++ b/model.cpp @@ -2347,37 +2347,13 @@ molalities(int allow_overflow) } if (s_x[i]->type == EX) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!PHR_ISFINITE(s_x[i]->moles)) - { - if (s_x[i]->lm < 0.0) - { - s_x[i]->moles = 1e-200; - fprintf(stderr, "ExchNaN-\n"); - } - else - { - s_x[i]->moles = 1e200; - fprintf(stderr, "ExchNaN+\n"); - } - } + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + } else if (s_x[i]->type == SURF) { - s_x[i]->moles = exp(s_x[i]->lm * LOG_10); - if (!PHR_ISFINITE(s_x[i]->moles)) - { - if (s_x[i]->lm < 0.0) - { - s_x[i]->moles = 1e-200; - fprintf(stderr, "SurfNaN-\n"); - } - else - { - s_x[i]->moles = 1e200; - fprintf(stderr, "SurfNaN+\n"); - } - } + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + } else { @@ -4312,7 +4288,15 @@ residuals(void) } /* add fictitious monovalent ion that balances charge */ - sum += fabs(sum1) * (exp(-sum1 / fabs(sum1) * negfpsirt) - 1); + //sum += fabs(sum1) * (exp(-sum1 / fabs(sum1) * negfpsirt) - 1); + if (sum1 >= 0) + { + sum += fabs(sum1) * (exp(-negfpsirt) - 1); + } + else + { + sum += fabs(sum1) * (exp(negfpsirt) - 1); + } if (sum < 0) { @@ -4667,18 +4651,50 @@ revise_guesses(void) else { repeat = TRUE; + d = 0; +#ifdef SKIP d = weight * log10(fabs(x[i]->moles / x[i]->sum)); - /*if (!isnan(d) && _finite(d))*/ - if (PHR_ISFINITE((double) d)) + double d1 = d; +#else + // avoid underflows and overflows + if (x[i]->moles > 1e101 || x[i]->moles < 1e-101 || + x[i]->sum > 1e101 || x[i]->sum < 1e-101) { - x[i]->master[0]->s->la += d; + double d1 = log10(x[i]->moles); + double d2 = log10(x[i]->sum); + double d3 = d1 - d2; + if (d3 > DBL_MAX_10_EXP/2) + { + d = pow(10.0, DBL_MAX_10_EXP/2.); + } + else if (d3 < DBL_MIN_10_EXP/2.) + { + d = pow(10.0, DBL_MIN_10_EXP/2.); + } + } + else + { + d = fabs(x[i]->moles / x[i]->sum); + } + double d1; + if (d > 0) + { + d1 = weight * log10(d); + if (PHR_ISFINITE((double) d1) /*&& d1 < 5.0*/) + { + x[i]->master[0]->s->la += d1; + } + else + { + warning_msg("Adjustment to la in revise_guesses was NaN\n"); + x[i]->master[0]->s->la += 5.0; + } } else { - warning_msg("Adjustment to la in revise_guesses was NaN\n"); x[i]->master[0]->s->la += 5.0; } - +#endif } if (debug_set == TRUE) { @@ -5302,7 +5318,40 @@ numerical_jacobian(void) //output_msg(sformatf( "%d\n", i)); for (j = 0; j < count_unknowns; j++) { - array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + // avoid overflow + if (residual[j] > 1.0e101) + { + double t = pow(10.0, DBL_MAX_10_EXP - 50.0); + if (residual[j] > t) + { + array[j * (count_unknowns + 1) + i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + } + } + else if (residual[j] < -1.0e101) + { + double t = pow(10.0, DBL_MIN_10_EXP + 50.0); + if (residual[j] < -t) + { + array[j * (count_unknowns + 1) + i] = pow(10.0, DBL_MIN_10_EXP + 50.0); + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + } + } + else + { + array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + if (!PHR_ISFINITE(array[j * (count_unknowns + 1) + i])) + { + //fprintf(stderr, "oops, got NaN: %e, %e, %e, %e\n", residual[j], base[j], d2, array[j * (count_unknowns + 1) + i]); + } + } + //output_msg(sformatf( "\t%d %e %e %e %e\n", j, array[j*(count_unknowns + 1) + i] , residual[j], base[j], d2)); } switch (x[i]->type) From 6412a827dd01c7ccb888ba8191eed62ff38c1dff Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 8 Feb 2013 21:20:33 +0000 Subject: [PATCH 0626/1077] Forgot to copy sit_param git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7453 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index d8beac53..9470aa8d 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -2983,6 +2983,11 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) sit_M = NULL; sit_LGAMMA = NULL; #endif + + for (int i = 0; i < pSrc->count_sit_param; i++) + { + sit_param_store(pSrc->sit_params[i], true); + } #ifdef SKIP /* tidy.cpp ------------------------------- */ a0 = 0; From 916ccdafa89eb3c413386fcd646047489173c593 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 8 Feb 2013 23:02:14 +0000 Subject: [PATCH 0627/1077] Working on copy operator. Fixing problems with iso.dat. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7454 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 31 +++++++++++++++++++++++-------- global_structures.h | 2 +- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9470aa8d..98c165c4 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -2604,15 +2604,29 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) { struct master_isotope *master_isotope_ptr = master_isotope_store(pSrc->master_isotope[i]->name, FALSE); memcpy(master_isotope_ptr, pSrc->master_isotope[i], sizeof(struct master_isotope)); + master_isotope_ptr->name = string_hsave(pSrc->master_isotope[i]->name); int n; - char * name = string_duplicate(pSrc->master_isotope[i]->master->elt->name); - master_isotope_ptr->master = master_search(name, &n); + master_isotope_ptr->master = NULL; + if (pSrc->master_isotope[i]->master) + { + char * name = string_duplicate(pSrc->master_isotope[i]->master->elt->name); + master_isotope_ptr->master = master_search(name, &n); + free_check_null(name); + } if (master_isotope_ptr->master == NULL) { - error_msg("Error in copy constructor for master_isotope.", STOP); + //error_msg("Error in copy constructor for master_isotope.", STOP); + } + master_isotope_ptr->elt = NULL; + if (pSrc->master_isotope[i]->elt) + { + master_isotope_ptr->elt = element_store(pSrc->master_isotope[i]->elt->name); + } + master_isotope_ptr->units = NULL; + if (pSrc->master_isotope[i]->units) + { + master_isotope_ptr->units = string_hsave(pSrc->master_isotope[i]->units); } - master_isotope_ptr->elt = element_store(pSrc->master_isotope[i]->elt->name); - master_isotope_ptr->units = string_hsave(pSrc->master_isotope[i]->units); } initial_solution_isotopes = pSrc->initial_solution_isotopes; /* @@ -2646,9 +2660,10 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) for (int i = 0; i < pSrc->count_isotope_ratio; i++) { struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); + isotope_ratio_ptr->name = string_hsave(pSrc->isotope_ratio[i]->name); isotope_ratio_ptr->isotope_name = string_hsave(pSrc->isotope_ratio[i]->isotope_name); - isotope_ratio_ptr->ratio = 0; - isotope_ratio_ptr->converted_ratio = -999.9; + isotope_ratio_ptr->ratio = pSrc->isotope_ratio[i]->ratio; + isotope_ratio_ptr->converted_ratio = pSrc->isotope_ratio[i]->converted_ratio; } /* count_isotope_alpha = 0; @@ -2660,7 +2675,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) { struct isotope_alpha *isotope_alpha_ptr = isotope_alpha_store(pSrc->isotope_alpha[i]->name, FALSE); isotope_alpha_ptr->named_logk = string_hsave(pSrc->isotope_alpha[i]->named_logk); - isotope_alpha_ptr->value = -999.9; + isotope_alpha_ptr->value = pSrc->isotope_alpha[i]->value; } phreeqc_mpi_myself = 0; diff --git a/global_structures.h b/global_structures.h index 2476ff0d..c741b8f5 100644 --- a/global_structures.h +++ b/global_structures.h @@ -608,7 +608,7 @@ public: struct rxn_token *next_token; next_token = rxn->token; this->tokens.push_back(*next_token++); - while (next_token->s != NULL) + while (next_token->s != NULL || next_token->name != NULL) { this->tokens.push_back(*next_token++); } From 85528955b4374778fa7156770922c6afd4aeb17b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 Feb 2013 19:04:35 +0000 Subject: [PATCH 0628/1077] more testing of copy operator. set new_def false for solid_solution mix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7455 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SSassemblage.cxx | 3 ++- class_main.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/SSassemblage.cxx b/SSassemblage.cxx index c187cbd9..4ef7b77c 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -49,6 +49,7 @@ cxxNumKeyword(io) this->add(*entity_ptr, it->second); } } + this->new_def = false; } cxxSSassemblage::~cxxSSassemblage() @@ -116,7 +117,7 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) s_oss << indent1 << "# SOLID_SOLUTION candidate identifiers with new_def=true #\n"; s_oss << indent1; - s_oss << "-new_def " << this->new_def << "\n"; + s_oss << "-new_def " << (this->new_def ? 1 : 0) << "\n"; s_oss << indent1 << "# solid solution workspace variables #\n"; s_oss << indent1; diff --git a/class_main.cpp b/class_main.cpp index 4c68addd..c4e7add1 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -36,7 +36,7 @@ main(int argc, char *argv[]) tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 9482; + //_crtBreakAlloc = 329203; #endif #ifdef SKIP //Set the x86 floating-point control word according to what @@ -125,7 +125,9 @@ main_method(int argc, char *argv[]) } Phreeqc MyCopy; MyCopy = *this; - //this->clean_up(); + this->clean_up(); + this->init(); + this->initialize(); /* * Read input data for simulation */ From deace44a7a89fd7a3eb58e7d56fb226c2c6a8ff8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 Feb 2013 19:48:57 +0000 Subject: [PATCH 0629/1077] make IPhreeqcPhast and Reaction_module a friend of Phreeqc. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7456 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index c2a0b412..f72cba37 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1894,6 +1894,8 @@ protected: friend class TestIPhreeqc; friend class TestSelectedOutput; friend class IPhreeqcMMS; + friend class IPhreeqcPhast; + friend class Reaction_module; std::vector keycount; // used to mark keywords that have been read From bdadfbeba4ff75a6391b653d5b86e59fc5b54e05 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 15 Feb 2013 01:24:37 +0000 Subject: [PATCH 0630/1077] added GetAllItems method git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7465 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 64 ++++++++++++++++++++++------------------------ StorageBinList.h | 63 --------------------------------------------- 2 files changed, 30 insertions(+), 97 deletions(-) delete mode 100644 StorageBinList.h diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 4d1333f4..47e5d4e7 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -108,31 +108,32 @@ StorageBinList::~StorageBinList(void) { } +std::set StorageBinList::GetAllItems(void) +{ + std::set items; + items.insert(&this->solution); + items.insert(&this->pp_assemblage); + items.insert(&this->exchange); + items.insert(&this->surface); + items.insert(&this->ss_assemblage); + items.insert(&this->gas_phase); + items.insert(&this->kinetics); + items.insert(&this->mix); + items.insert(&this->reaction); + items.insert(&this->temperature); + items.insert(&this->pressure); + return items; +} + void StorageBinList::SetAll(bool tf) { - this->solution.Clear(); - this->pp_assemblage.Clear(); - this->exchange.Clear(); - this->surface.Clear(); - this->ss_assemblage.Clear(); - this->gas_phase.Clear(); - this->kinetics.Clear(); - this->mix.Clear(); - this->reaction.Clear(); - this->temperature.Clear(); - this->pressure.Clear(); - - this->solution.Set_defined(tf); - this->pp_assemblage.Set_defined(tf); - this->exchange.Set_defined(tf); - this->surface.Set_defined(tf); - this->ss_assemblage.Set_defined(tf); - this->gas_phase.Set_defined(tf); - this->kinetics.Set_defined(tf); - this->mix.Set_defined(tf); - this->reaction.Set_defined(tf); - this->temperature.Set_defined(tf); - this->pressure.Set_defined(tf); + std::set all = this->GetAllItems(); + std::set::iterator it = all.begin(); + for (; it != all.end(); ++it) + { + (*it)->Clear(); + (*it)->Set_defined(tf); + } } bool StorageBinList::Read(CParser & parser) @@ -305,20 +306,15 @@ bool StorageBinList::Read(CParser & parser) void StorageBinList::TransferAll(StorageBinListItem &source) { + std::set items = this->GetAllItems(); std::set < int >::iterator it; for (it = source.Get_numbers().begin(); it != source.Get_numbers().end(); it++) { - this->solution.Augment(*it); - this->pp_assemblage.Augment(*it); - this->exchange.Augment(*it); - this->surface.Augment(*it); - this->ss_assemblage.Augment(*it); - this->gas_phase.Augment(*it); - this->kinetics.Augment(*it); - this->mix.Augment(*it); - this->reaction.Augment(*it); - this->temperature.Augment(*it); - this->pressure.Augment(*it); + std::set::iterator item = items.begin(); + for (; item != items.end(); ++item) + { + (*item)->Augment(*it); + } } } const std::vector< std::string >::value_type temp_vopts[] = { diff --git a/StorageBinList.h b/StorageBinList.h deleted file mode 100644 index 0825bb19..00000000 --- a/StorageBinList.h +++ /dev/null @@ -1,63 +0,0 @@ -#if !defined(STORAGEBINLIST_H_INCLUDED) -#define STORAGEBINLIST_H_INCLUDED -#include // std::set -#include // std::string -#include // std::list -#include // std::vector -#include "PHRQ_base.h" -class CParser; - -class StorageBinListItem -{ -public: - StorageBinListItem(void); - StorageBinListItem(CParser & parser); - ~StorageBinListItem(void); - void Set_defined(bool tf) { this->defined = tf; }; - bool Get_defined(void) { return(this->defined); }; - void Augment(std::string token); - void Augment(int i); - std::set < int > &Get_numbers(void) { return(this->numbers); }; - void Clear(void) { this->numbers.clear(); }; -protected: - std::set < int > numbers; - bool defined; -}; -class StorageBinList: public PHRQ_base -{ -public: - StorageBinList(PHRQ_io *io=NULL); - StorageBinList(CParser & parser, PHRQ_io *io=NULL); - virtual ~StorageBinList(void); - bool Read(CParser & parser); - void SetAll(bool tf); - void TransferAll(StorageBinListItem &source); - - StorageBinListItem & Get_solution(void) { return(this->solution); }; - StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; - StorageBinListItem & Get_exchange(void) { return(this->exchange); }; - StorageBinListItem & Get_surface(void) { return(this->surface); }; - StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; - StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; - StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; - StorageBinListItem & Get_mix(void) { return(this->mix); }; - StorageBinListItem & Get_reaction(void) { return(this->reaction); }; - StorageBinListItem & Get_temperature(void) { return(this->temperature); }; - StorageBinListItem & Get_pressure(void) { return(this->pressure); }; -protected: - StorageBinListItem solution; - StorageBinListItem pp_assemblage; - StorageBinListItem exchange; - StorageBinListItem surface; - StorageBinListItem ss_assemblage; - StorageBinListItem gas_phase; - StorageBinListItem kinetics; - StorageBinListItem mix; - StorageBinListItem reaction; - StorageBinListItem temperature; - StorageBinListItem pressure; - const static std::vector < std::string > vopts; -}; - - -#endif // !defined(STORAGEBINLIST_H_INCLUDED) From b44c54f955a4d36f937a083371faa39f55f94980 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 15 Feb 2013 01:28:30 +0000 Subject: [PATCH 0631/1077] for some reason TortoiseSVN deleted StorageBinList.h on checkin git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7466 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 StorageBinList.h diff --git a/StorageBinList.h b/StorageBinList.h new file mode 100644 index 00000000..e18fc8a3 --- /dev/null +++ b/StorageBinList.h @@ -0,0 +1,65 @@ +#if !defined(STORAGEBINLIST_H_INCLUDED) +#define STORAGEBINLIST_H_INCLUDED +#include // std::set +#include // std::string +#include // std::list +#include // std::vector +#include "PHRQ_base.h" +class CParser; + +class StorageBinListItem +{ +public: + StorageBinListItem(void); + StorageBinListItem(CParser & parser); + ~StorageBinListItem(void); + void Set_defined(bool tf) { this->defined = tf; }; + bool Get_defined(void) { return(this->defined); }; + void Augment(std::string token); + void Augment(int i); + std::set < int > &Get_numbers(void) { return(this->numbers); }; + void Clear(void) { this->numbers.clear(); }; +protected: + std::set < int > numbers; + bool defined; +}; +class StorageBinList: public PHRQ_base +{ +public: + StorageBinList(PHRQ_io *io=NULL); + StorageBinList(CParser & parser, PHRQ_io *io=NULL); + virtual ~StorageBinList(void); + bool Read(CParser & parser); + void SetAll(bool tf); + void TransferAll(StorageBinListItem &source); + std::set GetAllItems(void); + + StorageBinListItem & Get_solution(void) { return(this->solution); }; + StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; + StorageBinListItem & Get_exchange(void) { return(this->exchange); }; + StorageBinListItem & Get_surface(void) { return(this->surface); }; + StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; + StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; + StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; + StorageBinListItem & Get_mix(void) { return(this->mix); }; + StorageBinListItem & Get_reaction(void) { return(this->reaction); }; + StorageBinListItem & Get_temperature(void) { return(this->temperature); }; + StorageBinListItem & Get_pressure(void) { return(this->pressure); }; +protected: + // update GetAllItems() if StorageBinListItem is added/removed + StorageBinListItem solution; + StorageBinListItem pp_assemblage; + StorageBinListItem exchange; + StorageBinListItem surface; + StorageBinListItem ss_assemblage; + StorageBinListItem gas_phase; + StorageBinListItem kinetics; + StorageBinListItem mix; + StorageBinListItem reaction; + StorageBinListItem temperature; + StorageBinListItem pressure; + const static std::vector < std::string > vopts; +}; + + +#endif // !defined(STORAGEBINLIST_H_INCLUDED) From dd104e8dd0234cecde7d93373f384af62d589f22 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 15 Feb 2013 02:04:48 +0000 Subject: [PATCH 0632/1077] trying to fix history git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7467 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.h | 65 ------------------------------------------------ 1 file changed, 65 deletions(-) delete mode 100644 StorageBinList.h diff --git a/StorageBinList.h b/StorageBinList.h deleted file mode 100644 index e18fc8a3..00000000 --- a/StorageBinList.h +++ /dev/null @@ -1,65 +0,0 @@ -#if !defined(STORAGEBINLIST_H_INCLUDED) -#define STORAGEBINLIST_H_INCLUDED -#include // std::set -#include // std::string -#include // std::list -#include // std::vector -#include "PHRQ_base.h" -class CParser; - -class StorageBinListItem -{ -public: - StorageBinListItem(void); - StorageBinListItem(CParser & parser); - ~StorageBinListItem(void); - void Set_defined(bool tf) { this->defined = tf; }; - bool Get_defined(void) { return(this->defined); }; - void Augment(std::string token); - void Augment(int i); - std::set < int > &Get_numbers(void) { return(this->numbers); }; - void Clear(void) { this->numbers.clear(); }; -protected: - std::set < int > numbers; - bool defined; -}; -class StorageBinList: public PHRQ_base -{ -public: - StorageBinList(PHRQ_io *io=NULL); - StorageBinList(CParser & parser, PHRQ_io *io=NULL); - virtual ~StorageBinList(void); - bool Read(CParser & parser); - void SetAll(bool tf); - void TransferAll(StorageBinListItem &source); - std::set GetAllItems(void); - - StorageBinListItem & Get_solution(void) { return(this->solution); }; - StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; - StorageBinListItem & Get_exchange(void) { return(this->exchange); }; - StorageBinListItem & Get_surface(void) { return(this->surface); }; - StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; - StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; - StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; - StorageBinListItem & Get_mix(void) { return(this->mix); }; - StorageBinListItem & Get_reaction(void) { return(this->reaction); }; - StorageBinListItem & Get_temperature(void) { return(this->temperature); }; - StorageBinListItem & Get_pressure(void) { return(this->pressure); }; -protected: - // update GetAllItems() if StorageBinListItem is added/removed - StorageBinListItem solution; - StorageBinListItem pp_assemblage; - StorageBinListItem exchange; - StorageBinListItem surface; - StorageBinListItem ss_assemblage; - StorageBinListItem gas_phase; - StorageBinListItem kinetics; - StorageBinListItem mix; - StorageBinListItem reaction; - StorageBinListItem temperature; - StorageBinListItem pressure; - const static std::vector < std::string > vopts; -}; - - -#endif // !defined(STORAGEBINLIST_H_INCLUDED) From 342bf39fad3c168e338f3221fcdce35d29a05489 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 15 Feb 2013 02:27:21 +0000 Subject: [PATCH 0633/1077] trying to fix history git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7468 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 StorageBinList.h diff --git a/StorageBinList.h b/StorageBinList.h new file mode 100644 index 00000000..0825bb19 --- /dev/null +++ b/StorageBinList.h @@ -0,0 +1,63 @@ +#if !defined(STORAGEBINLIST_H_INCLUDED) +#define STORAGEBINLIST_H_INCLUDED +#include // std::set +#include // std::string +#include // std::list +#include // std::vector +#include "PHRQ_base.h" +class CParser; + +class StorageBinListItem +{ +public: + StorageBinListItem(void); + StorageBinListItem(CParser & parser); + ~StorageBinListItem(void); + void Set_defined(bool tf) { this->defined = tf; }; + bool Get_defined(void) { return(this->defined); }; + void Augment(std::string token); + void Augment(int i); + std::set < int > &Get_numbers(void) { return(this->numbers); }; + void Clear(void) { this->numbers.clear(); }; +protected: + std::set < int > numbers; + bool defined; +}; +class StorageBinList: public PHRQ_base +{ +public: + StorageBinList(PHRQ_io *io=NULL); + StorageBinList(CParser & parser, PHRQ_io *io=NULL); + virtual ~StorageBinList(void); + bool Read(CParser & parser); + void SetAll(bool tf); + void TransferAll(StorageBinListItem &source); + + StorageBinListItem & Get_solution(void) { return(this->solution); }; + StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; + StorageBinListItem & Get_exchange(void) { return(this->exchange); }; + StorageBinListItem & Get_surface(void) { return(this->surface); }; + StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; + StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; + StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; + StorageBinListItem & Get_mix(void) { return(this->mix); }; + StorageBinListItem & Get_reaction(void) { return(this->reaction); }; + StorageBinListItem & Get_temperature(void) { return(this->temperature); }; + StorageBinListItem & Get_pressure(void) { return(this->pressure); }; +protected: + StorageBinListItem solution; + StorageBinListItem pp_assemblage; + StorageBinListItem exchange; + StorageBinListItem surface; + StorageBinListItem ss_assemblage; + StorageBinListItem gas_phase; + StorageBinListItem kinetics; + StorageBinListItem mix; + StorageBinListItem reaction; + StorageBinListItem temperature; + StorageBinListItem pressure; + const static std::vector < std::string > vopts; +}; + + +#endif // !defined(STORAGEBINLIST_H_INCLUDED) From c6261d5f9e92f0c9a74ab8c581ac73633933b309 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 15 Feb 2013 02:29:32 +0000 Subject: [PATCH 0634/1077] added GetAllItems method - with fixed history git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7469 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/StorageBinList.h b/StorageBinList.h index 0825bb19..9fefdb7a 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -1,9 +1,9 @@ #if !defined(STORAGEBINLIST_H_INCLUDED) #define STORAGEBINLIST_H_INCLUDED -#include // std::set -#include // std::string -#include // std::list -#include // std::vector +#include // std::set +#include // std::string +#include // std::list +#include // std::vector #include "PHRQ_base.h" class CParser; @@ -32,19 +32,21 @@ public: bool Read(CParser & parser); void SetAll(bool tf); void TransferAll(StorageBinListItem &source); + std::set GetAllItems(void); - StorageBinListItem & Get_solution(void) { return(this->solution); }; + StorageBinListItem & Get_solution(void) { return(this->solution); }; StorageBinListItem & Get_pp_assemblage(void) { return(this->pp_assemblage); }; - StorageBinListItem & Get_exchange(void) { return(this->exchange); }; - StorageBinListItem & Get_surface(void) { return(this->surface); }; + StorageBinListItem & Get_exchange(void) { return(this->exchange); }; + StorageBinListItem & Get_surface(void) { return(this->surface); }; StorageBinListItem & Get_ss_assemblage(void) { return(this->ss_assemblage); }; - StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; - StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; - StorageBinListItem & Get_mix(void) { return(this->mix); }; - StorageBinListItem & Get_reaction(void) { return(this->reaction); }; - StorageBinListItem & Get_temperature(void) { return(this->temperature); }; - StorageBinListItem & Get_pressure(void) { return(this->pressure); }; + StorageBinListItem & Get_gas_phase(void) { return(this->gas_phase); }; + StorageBinListItem & Get_kinetics(void) { return(this->kinetics); }; + StorageBinListItem & Get_mix(void) { return(this->mix); }; + StorageBinListItem & Get_reaction(void) { return(this->reaction); }; + StorageBinListItem & Get_temperature(void) { return(this->temperature); }; + StorageBinListItem & Get_pressure(void) { return(this->pressure); }; protected: + // update GetAllItems() if StorageBinListItem is added/removed StorageBinListItem solution; StorageBinListItem pp_assemblage; StorageBinListItem exchange; From 27e3f75c4e3e2b1adc32d40a0d1703034a30b391 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 15 Feb 2013 18:06:29 +0000 Subject: [PATCH 0635/1077] Optimized sum_species. Keeps lists of species in a map > sum_species_map. resets map whenever s_x changes (tidy and prep) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7470 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ basicsubs.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ prep.cpp | 4 ++++ tidy.cpp | 2 ++ 4 files changed, 62 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index f72cba37..bc5421b0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1888,6 +1888,9 @@ protected: /* utilities.cpp ------------------------------- */ int spinner; + /* new after release of Version 3 */ + std::map > sum_species_map; + friend class PBasic; friend class ChartObject; friend class IPhreeqc; diff --git a/basicsubs.cpp b/basicsubs.cpp index fef80d66..1bf4751d 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -1465,6 +1465,7 @@ sum_match_gases(const char *mytemplate, const char *name) } return (tot); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sum_match_species(const char *mytemplate, const char *name) @@ -1501,6 +1502,58 @@ sum_match_species(const char *mytemplate, const char *name) } return (tot); } +#else +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_species(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + count_elts = 0; + paren_count = 0; + tot = 0; + if (sum_species_map.find(mytemplate) == sum_species_map.end()) + { + std::vector species_list; + for (i = 0; i < count_s_x; i++) + { + struct species *s_ptr = s_x[i]; + if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE) + { + species_list.push_back(s_ptr->name); + } + } + sum_species_map[mytemplate] = species_list; + } + std::vector &species_list = (sum_species_map.find(mytemplate))->second; + for (size_t i=0; i < species_list.size(); i++) + { + struct species *s_ptr = s_search(species_list[i].c_str()); + if (s_ptr->in == FALSE) continue; + if (name == NULL) + { + tot += s_ptr->moles; + } + else + { + for (next_elt = s_ptr->next_elt; next_elt->elt != NULL; + next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += next_elt->coef * s_ptr->moles; + break; + } + } + } + } + return (tot); +} +#endif + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sum_match_ss(const char *mytemplate, const char *name) diff --git a/prep.cpp b/prep.cpp index 6bdd7558..1b88c214 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1129,6 +1129,10 @@ build_model(void) */ max_s_x = MAX_S; + + // clear sum_species_map, which is built from s_x + sum_species_map.clear(); + space((void **) ((void *) &s_x), INIT, &max_s_x, sizeof(struct species *)); diff --git a/tidy.cpp b/tidy.cpp index 15fcc8b4..a94f31da 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -180,6 +180,8 @@ tidy_model(void) */ if (new_model) { + sum_species_map.clear(); + tidy_species(); tidy_phases(); From 3461797c9560503fb12f37b890a98e2046bb4824 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Feb 2013 18:13:43 +0000 Subject: [PATCH 0636/1077] Copied Advection and Transport data in InternalCopy. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7472 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 145 +++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 63 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 98c165c4..c55b9c38 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1966,51 +1966,70 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /*---------------------------------------------------------------------- * Transport data *---------------------------------------------------------------------- */ - /* - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - correct_disp = FALSE; - tempr = 2.0; - timest = 0.0; - simul_tr = 0; - diffc = 0.3e-9; - heat_diffc = -0.1; - cell = 0; - mcd_substeps = 1.0; - stag_data = NULL; - print_modulus = 1; - punch_modulus = 1; - dump_in = FALSE; - dump_modulus = 0; - transport_warnings = TRUE; - cell_data = FALSE; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - default_Dw = 0; - multi_Dpor = 0; - interlayer_Dpor = 0.1; - multi_Dpor_lim = 0; - interlayer_Dpor_lim = 0; - multi_Dn = 0; - interlayer_tortf = 100.0; - cell_no = 0; - */ + count_cells = pSrc->count_cells; + count_shifts = pSrc->count_shifts; + ishift = pSrc->ishift; + bcon_first = pSrc->bcon_first; + bcon_last = pSrc->bcon_last; + correct_disp = pSrc->correct_disp; + tempr = pSrc->tempr; + timest = pSrc->timest; + simul_tr = pSrc->simul_tr; + diffc = pSrc->diffc; + heat_diffc = pSrc->heat_diffc; + cell = pSrc->cell; + mcd_substeps = pSrc->mcd_substeps; + /* stag_data */ + memcpy(stag_data, pSrc->stag_data, sizeof(struct stag_data)); + print_modulus = pSrc->print_modulus; + punch_modulus = pSrc->punch_modulus; + dump_in = pSrc->dump_in; + dump_modulus = pSrc->dump_modulus; + transport_warnings = pSrc->transport_warnings; + /* cell_data */ + if (count_cells > 0) + { + cell_data = (struct cell_data *) free_check_null(cell_data); + cell_data = (struct cell_data *) PHRQ_malloc((size_t) (count_cells * sizeof(struct cell_data))); + if (cell_data == NULL) malloc_error(); + memcpy(cell_data, pSrc->cell_data, ((size_t) (count_cells * sizeof(struct cell_data)))); + } + multi_Dflag = pSrc->multi_Dflag; + interlayer_Dflag = pSrc->interlayer_Dflag; + default_Dw = pSrc->default_Dw; + multi_Dpor = pSrc->multi_Dpor; + interlayer_Dpor = pSrc->interlayer_Dpor; + multi_Dpor_lim = pSrc->multi_Dpor_lim; + interlayer_Dpor_lim = pSrc->interlayer_Dpor_lim; + multi_Dn = pSrc->multi_Dn; + interlayer_tortf = pSrc->interlayer_tortf; + cell_no = pSrc->cell_no; /*---------------------------------------------------------------------- * Advection data *---------------------------------------------------------------------- */ - /* - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - advection_punch = NULL; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = NULL; - advection_warnings = TRUE; - */ + count_ad_cells = pSrc->count_ad_cells; + count_ad_shifts = pSrc->count_ad_shifts; + print_ad_modulus = pSrc->print_ad_modulus; + punch_ad_modulus = pSrc->punch_ad_modulus; + /* advection_punch */ + if (count_ad_cells > 0) + { + advection_punch = (int *) free_check_null(advection_punch); + advection_punch = (int *) PHRQ_malloc((size_t) (count_ad_cells * sizeof(int))); + if (advection_punch == NULL) malloc_error(); + memcpy(advection_punch, pSrc->advection_punch, (size_t) (count_ad_cells * sizeof(int))); + } + /* advection_print */ + if (count_ad_cells > 0) + { + advection_print = (int *) free_check_null(advection_print); + advection_print = (int *) PHRQ_malloc((size_t) (count_ad_cells * sizeof(int))); + if (advection_print == NULL) malloc_error(); + memcpy(advection_print, pSrc->advection_print, (size_t) (count_ad_cells * sizeof(int))); + } + advection_kin_time = pSrc->advection_kin_time; + advection_kin_time_defined = pSrc->advection_kin_time_defined; + advection_warnings = pSrc->advection_warnings; /*---------------------------------------------------------------------- * Tidy data *---------------------------------------------------------------------- */ @@ -2982,7 +3001,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) /* readtr.cpp */ // auto dump_file_name_cpp; /* sit.cpp ------------------------------- */ -#ifdef TODO_SIT +/* sit_params = NULL; count_sit_param = 0; max_sit_param = 100; @@ -2997,7 +3016,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) sit_IPRSNT = NULL; sit_M = NULL; sit_LGAMMA = NULL; -#endif +*/ for (int i = 0; i < pSrc->count_sit_param; i++) { @@ -3017,32 +3036,32 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) count_tally_table_rows = 0; #endif /* transport.cpp ------------------------------- */ -#ifdef TODO_transport - sol_D = NULL; + /* storage is created and freed in tranport.cpp */ + sol_D = NULL; sol_D_dbg = NULL; J_ij = NULL; J_ij_il = NULL; - J_ij_count_spec = 0; + J_ij_count_spec = pSrc->J_ij_count_spec; m_s = NULL; - count_m_s = 0; - tot1_h = 0; - tot1_o = 0; - tot2_h = 0; - tot2_o = 0; - diffc_max = 0; - diffc_tr = 0; - J_ij_sum = 0; - transp_surf = FALSE; + count_m_s = pSrc->count_m_s; + tot1_h = pSrc->tot1_h; + tot1_o = pSrc->tot1_o; + tot2_h = pSrc->tot2_h; + tot2_o = pSrc->tot2_o; + diffc_max = pSrc->diffc_max; + diffc_tr = pSrc->diffc_tr; + J_ij_sum = pSrc->J_ij_sum; + transp_surf = pSrc->transp_surf; heat_mix_array = NULL; temp1 = NULL; temp2 = NULL; - nmix = 0; - heat_nmix = 0; - heat_mix_f_imm = 0; - heat_mix_f_m = 0; - warn_MCD_X = 0; - warn_fixed_Surf = 0; -#endif + nmix = pSrc->nmix; + heat_nmix = pSrc->heat_nmix; + heat_mix_f_imm = pSrc->heat_mix_f_imm; + heat_mix_f_m = pSrc->heat_mix_f_m; + warn_MCD_X = pSrc->warn_MCD_X; + warn_fixed_Surf = pSrc->warn_fixed_Surf; + #ifdef PHREEQ98 int AutoLoadOutputFile, CreateToC; int ProcessMessages, ShowProgress, ShowProgressWindow, ShowChart; From 1342a5c580ca39adc591be203bdfe74dd8a2738c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Feb 2013 19:40:11 +0000 Subject: [PATCH 0637/1077] Alternate method for sum_species fixed memory leak when copying phreeqc instance with llnl.dat git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7473 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 5 ++++ Phreeqc.h | 1 + basicsubs.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ prep.cpp | 1 + 4 files changed, 74 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c55b9c38..72fa6a31 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -2559,6 +2559,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) llnl_count_temp = pSrc->llnl_count_temp; if (llnl_count_temp > 0) { + llnl_temp = (LDBLE *) free_check_null(llnl_temp); llnl_temp = (LDBLE *) PHRQ_malloc((size_t) llnl_count_temp * sizeof(LDBLE)); if (llnl_temp == NULL) malloc_error(); memcpy(llnl_temp, pSrc->llnl_temp, (size_t) llnl_count_temp * sizeof(LDBLE)); @@ -2566,6 +2567,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) llnl_count_adh = pSrc->llnl_count_adh; if (llnl_count_adh > 0) { + llnl_adh = (LDBLE *) free_check_null(llnl_adh); llnl_adh = (LDBLE *) PHRQ_malloc((size_t) llnl_count_adh * sizeof(LDBLE)); if (llnl_adh == NULL) malloc_error(); memcpy(llnl_adh, pSrc->llnl_adh, (size_t) llnl_count_adh * sizeof(LDBLE)); @@ -2573,6 +2575,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) llnl_count_bdh = pSrc->llnl_count_bdh; if (llnl_count_bdh > 0) { + llnl_bdh = (LDBLE *) free_check_null(llnl_bdh); llnl_bdh = (LDBLE *) PHRQ_malloc((size_t) llnl_count_bdh * sizeof(LDBLE)); if (llnl_bdh == NULL) malloc_error(); memcpy(llnl_bdh, pSrc->llnl_bdh, (size_t) llnl_count_bdh * sizeof(LDBLE)); @@ -2580,6 +2583,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) llnl_count_bdot = pSrc->llnl_count_bdot; if (llnl_count_bdot > 0) { + llnl_bdot = (LDBLE *) free_check_null(llnl_bdot); llnl_bdot = (LDBLE *) PHRQ_malloc((size_t) llnl_count_bdot * sizeof(LDBLE)); if (llnl_bdot == NULL) malloc_error(); memcpy(llnl_bdot, pSrc->llnl_bdot, (size_t) llnl_count_bdot * sizeof(LDBLE)); @@ -2587,6 +2591,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) llnl_count_co2_coefs = pSrc->llnl_count_co2_coefs; if (llnl_count_co2_coefs > 0) { + llnl_co2_coefs = (LDBLE *) free_check_null(llnl_co2_coefs); llnl_co2_coefs = (LDBLE *) PHRQ_malloc((size_t) llnl_count_co2_coefs * sizeof(LDBLE)); if (llnl_co2_coefs == NULL) malloc_error(); memcpy(llnl_co2_coefs, pSrc->llnl_co2_coefs, (size_t) llnl_count_co2_coefs * sizeof(LDBLE)); diff --git a/Phreeqc.h b/Phreeqc.h index bc5421b0..ef7ebbe0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1890,6 +1890,7 @@ protected: /* new after release of Version 3 */ std::map > sum_species_map; + std::map > sum_species_map_db; friend class PBasic; friend class ChartObject; diff --git a/basicsubs.cpp b/basicsubs.cpp index 1bf4751d..2926b0bd 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -1503,6 +1503,7 @@ sum_match_species(const char *mytemplate, const char *name) return (tot); } #else +#ifndef SUM_SPECIES_METHOD_2 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sum_match_species(const char *mytemplate, const char *name) @@ -1552,6 +1553,72 @@ sum_match_species(const char *mytemplate, const char *name) } return (tot); } +#else +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sum_match_species(const char *mytemplate, const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + LDBLE tot; + struct elt_list *next_elt; + + count_elts = 0; + paren_count = 0; + tot = 0; + if (sum_species_map.find(mytemplate) == sum_species_map.end()) + { + if (sum_species_map_db.find(mytemplate) == sum_species_map_db.end()) + { + std::vector species_list_db; + for (i = 0; i < count_s; i++) + { + struct species *s_ptr = s[i]; + if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE) + { + species_list_db.push_back(s_ptr->name); + } + } + sum_species_map_db[mytemplate] = species_list_db; + } + std::vector &species_list = (sum_species_map_db.find(mytemplate))->second; + std::vector species_list_x; + for (size_t i=0; i < species_list.size(); i++) + { + struct species *s_ptr = s_search(species_list[i].c_str()); + if (s_ptr->in == TRUE) + { + species_list_x.push_back(species_list[i]); + } + } + sum_species_map[mytemplate] = species_list_x; + } + std::vector &species_list = (sum_species_map.find(mytemplate))->second; + for (size_t i=0; i < species_list.size(); i++) + { + struct species *s_ptr = s_search(species_list[i].c_str()); + if (s_ptr->in == FALSE) continue; + if (name == NULL) + { + tot += s_ptr->moles; + } + else + { + for (next_elt = s_ptr->next_elt; next_elt->elt != NULL; + next_elt++) + { + if (strcmp(next_elt->elt->name, name) == 0) + { + tot += next_elt->coef * s_ptr->moles; + break; + } + } + } + } + return (tot); +} + +#endif #endif /* ---------------------------------------------------------------------- */ diff --git a/prep.cpp b/prep.cpp index 1b88c214..8341e939 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1131,6 +1131,7 @@ build_model(void) max_s_x = MAX_S; // clear sum_species_map, which is built from s_x + sum_species_map_db.clear(); sum_species_map.clear(); space((void **) ((void *) &s_x), INIT, &max_s_x, From a2a1aafe9db6e887e334648339f0912ffeadce56 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 22 Feb 2013 19:15:42 +0000 Subject: [PATCH 0638/1077] PBasic use phreeqc_ptr warning msg instead of default phrq_io warning msg. Fixed bug in s_s assemblage print git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7495 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 26 +++++++++++++------------- print.cpp | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 82007114..d9aa7bb9 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -121,7 +121,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) { char * error_string = PhreeqcPtr->sformatf("%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } } else @@ -208,7 +208,7 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) { char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } else { @@ -278,7 +278,7 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) { char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } } else @@ -347,7 +347,7 @@ basic_main(char *commands) { char * error_string = PhreeqcPtr->sformatf( "%d/%d", (int) P_escapecode, (int) P_ioresult); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } else { @@ -3375,7 +3375,7 @@ term(struct LOC_exec * LINK) if (!parse_all) { char * error_string = PhreeqcPtr->sformatf( "Zero divide in BASIC line\n %ld %s.\nValue set to zero.", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } n.UU.val = 0; } @@ -5201,7 +5201,7 @@ exec(void) { //_Ltry1: if (P_escapecode == -20) - warning_msg("Break"); + PhreeqcPtr->warning_msg("Break"); /* printf("Break"); */ else if (P_escapecode != 42) { @@ -5211,28 +5211,28 @@ exec(void) case -4: { char * error_string = PhreeqcPtr->sformatf( "Integer overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; case -5: { char * error_string = PhreeqcPtr->sformatf( "Divide by zero in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; case -6: { char * error_string = PhreeqcPtr->sformatf( "Real math overflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; case -7: { char * error_string = PhreeqcPtr->sformatf( "Real math underflow in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; @@ -5244,14 +5244,14 @@ exec(void) case -15: { char * error_string = PhreeqcPtr->sformatf( "Value range error in BASIC line\n %ld %s", stmtline->num, stmtline->inbuf); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; case -10: { char * error_string = PhreeqcPtr->sformatf("I/O Error %d", (int) P_ioresult); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } break; @@ -5259,7 +5259,7 @@ exec(void) if (EXCP_LINE != -1) { char * error_string = PhreeqcPtr->sformatf( "%12ld\n", EXCP_LINE); - warning_msg(error_string); + PhreeqcPtr->warning_msg(error_string); } _Escape(P_escapecode); break; diff --git a/print.cpp b/print.cpp index 5259fc40..ab401a4c 100644 --- a/print.cpp +++ b/print.cpp @@ -2431,9 +2431,9 @@ punch_ss_assemblage(void) for (j = 0; j < (int) ss_ptrs.size(); j++) { cxxSS * ss_ptr = ss_ptrs[j]; - for (k = 0; k < (int) ss_ptr->Get_ss_comps().size(); k++) + for (int i = 0; i < (int) ss_ptr->Get_ss_comps().size(); i++) { - cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[k]); + cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); if (strcmp_nocase(punch.s_s[k].name, comp_ptr->Get_name().c_str()) == 0) { From ebe3cbf710aad8639815a863d7e6e903937e308b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 28 Feb 2013 17:22:51 +0000 Subject: [PATCH 0639/1077] SOLUTION_MASTER_SPECIES was not defined correctly. Fixed Null pointer. Abort if input_error in build_model. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7500 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/prep.cpp b/prep.cpp index 8341e939..3756f62e 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1209,6 +1209,7 @@ build_model(void) /* * Write mass action equation for current model */ + //if (write_mass_action_eqn_x(STOP) == ERROR) continue; write_mass_action_eqn_x(STOP); if (s[i]->type == SURF) { @@ -1402,6 +1403,11 @@ build_model(void) * Save model description */ save_model(); + + if (input_error > 0) + { + error_msg("Stopping due to input errors.", STOP); + } return (OK); } /* ---------------------------------------------------------------------- */ @@ -2857,12 +2863,19 @@ write_mass_action_eqn_x(int stop) count++; if (count > MAX_ADD_EQUATIONS) { + std::string name; + name = "Unknown"; + if (trxn.token[0].s != NULL) + { + name = trxn.token[0].s->name; + } + + input_error++; error_string = sformatf( "Could not reduce equation " "to primary and secondary species that are " - "in the model\n\t Species: %s.", trxn.token[0].s->name); + "in the model. Species: %s.", name.c_str()); if (stop == STOP) { - input_error++; error_msg(error_string, CONTINUE); } else @@ -4953,7 +4966,7 @@ store_dn(int k, LDBLE * source, int row, LDBLE coef_in, LDBLE * gamma_source) { output_msg(sformatf( "\t\t%s\n", master_ptr->s->name)); } - if (master_ptr->unknown == NULL) + if (master_ptr == NULL ||master_ptr->unknown == NULL) continue; col = master_ptr->unknown->number; coef = coef_in * rxn_ptr->coef; @@ -5291,9 +5304,15 @@ write_mb_eqn_x(void) count++; if (count > MAX_ADD_EQUATIONS) { + std::string name; + name = "Unknown"; + if (trxn.token[0].s != NULL) + { + name = trxn.token[0].s->name; + } error_string = sformatf( "Could not reduce equation " "to primary and secondary species that are " - "in the model, %s.", trxn.token[0].s->name); + "in the model. Species: %s.", name.c_str()); error_msg(error_string, CONTINUE); return (ERROR); } From 9849ed1aee8fbb3a08dd2e30510702a32f611664 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 7 Mar 2013 05:42:24 +0000 Subject: [PATCH 0640/1077] added Setters for time params git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7523 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- runner.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runner.h b/runner.h index 86049879..f492a7fd 100644 --- a/runner.h +++ b/runner.h @@ -18,6 +18,8 @@ public: StorageBinListItem & Get_cells(void) { return(this->cells); }; LDBLE Get_time_step() { return(this->time_step); }; LDBLE Get_start_time() { return(this->start_time); }; + void Set_time_step(LDBLE ts) { this->time_step = ts; }; + void Set_start_time(LDBLE st) { this->start_time = st; }; bool Get_run_cells() { return(this->run_cells); }; void Set_run_cells(bool tf) { this->run_cells = tf; }; From 6899bc4ba762f2ac4f94b6d4febf68fc55578407 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Mar 2013 18:07:31 +0000 Subject: [PATCH 0641/1077] fixes bug with cd_psi in model.cpp. Bug with printed saturation indices with pressure. prep: rewrote calc_delta_v(reaction *r_ptr, bool phase) to handle phase and species separately. print: calculate pressure term for rxn before printing value. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7547 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 4 ++++ prep.cpp | 38 ++++++++++++++++++++++++++------------ print.cpp | 4 ++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/model.cpp b/model.cpp index 6d5eda0f..12d1df38 100644 --- a/model.cpp +++ b/model.cpp @@ -4138,6 +4138,10 @@ residuals(void) if (charge_ptr->Get_grams() == 0) { residual[i] = 0.0; + cd_psi.clear(); + cd_psi.push_back(0.0); + cd_psi.push_back(0.0); + cd_psi.push_back(0.0); } else { diff --git a/prep.cpp b/prep.cpp index 3756f62e..158a3d57 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5521,22 +5521,36 @@ calc_delta_v(reaction *r_ptr, bool phase) { /* calculate delta_v from molar volumes */ - int p = -1; LDBLE d_v = 0.0; if (phase) - p = 1; /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ - - for (size_t i = 0; r_ptr->token[i].name; i++) { - if (!r_ptr->token[i].s) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += p * r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ + for (size_t i = 1; r_ptr->token[i].s /*|| r_ptr->token[i].s*/ ; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + } + } + else + { + for (size_t i = 0; r_ptr->token[i].name /*|| r_ptr->token[i].s*/ ; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + } } return d_v; } diff --git a/print.cpp b/print.cpp index ab401a4c..4b60f5c1 100644 --- a/print.cpp +++ b/print.cpp @@ -1283,6 +1283,10 @@ print_pp_assemblage(void) PR_inprint = true; phase_ptr->pr_in = false; } + phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - + phase_ptr->logk[vm0]; + if (phase_ptr->rxn->logk[delta_v]) + mu_terms_in_logk = true; lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); if (PR_inprint) phase_ptr->pr_in = true; From acd7d32d59fcdde356a417e4e39d01164fd9306a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 14 Mar 2013 00:23:24 +0000 Subject: [PATCH 0642/1077] Fixed bug in SI of pure phase assemblage that did not account for pressure (Tony's version). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7550 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 71 +++++++++++++++++++++++++++++++++++-------------------- print.cpp | 17 +++++++++---- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/prep.cpp b/prep.cpp index 158a3d57..f942f46a 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5521,38 +5521,57 @@ calc_delta_v(reaction *r_ptr, bool phase) { /* calculate delta_v from molar volumes */ + int p = -1; LDBLE d_v = 0.0; if (phase) + p = 1; /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ + + for (size_t i = 0; r_ptr->token[i].name; i++) { - /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ - for (size_t i = 1; r_ptr->token[i].s /*|| r_ptr->token[i].s*/ ; i++) - { - if (!r_ptr->token[i].s) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; - } - } - else - { - for (size_t i = 0; r_ptr->token[i].name /*|| r_ptr->token[i].s*/ ; i++) - { - if (!r_ptr->token[i].s) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; - } + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += p * r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; } return d_v; +//dlp + //LDBLE d_v = 0.0; + + //if (phase) + //{ + // /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ + // for (size_t i = 1; r_ptr->token[i].s /*|| r_ptr->token[i].s*/ ; i++) + // { + // //if (!r_ptr->token[i].s) + // // continue; + // if (!strcmp(r_ptr->token[i].s->name, "H+")) + // continue; + // if (!strcmp(r_ptr->token[i].s->name, "e-")) + // continue; + // else if (r_ptr->token[i].s->logk[vm_tc]) + // d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + // } + //} + //else + //{ + // for (size_t i = 0; r_ptr->token[i].name /*|| r_ptr->token[i].s*/ ; i++) + // { + // if (!r_ptr->token[i].s) + // continue; + // if (!strcmp(r_ptr->token[i].s->name, "H+")) + // continue; + // if (!strcmp(r_ptr->token[i].s->name, "e-")) + // continue; + // else if (r_ptr->token[i].s->logk[vm_tc]) + // d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + // } + //} + //return d_v; } #ifdef PHREEQC2 /* ---------------------------------------------------------------------- */ diff --git a/print.cpp b/print.cpp index 4b60f5c1..86d5b3db 100644 --- a/print.cpp +++ b/print.cpp @@ -1282,12 +1282,19 @@ print_pp_assemblage(void) { PR_inprint = true; phase_ptr->pr_in = false; - } - phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - + phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn_x, true) - phase_ptr->logk[vm0]; - if (phase_ptr->rxn->logk[delta_v]) - mu_terms_in_logk = true; - lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); + lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); + } + else + lk = phase_ptr->lk; +// dlp + //phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - + // phase_ptr->logk[vm0]; + //if (phase_ptr->rxn->logk[delta_v]) + // mu_terms_in_logk = true; +// end +// lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); if (PR_inprint) phase_ptr->pr_in = true; for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; From 82fc3b7ef55478c59c83fe09632c507f1a1e7eac Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 14 Mar 2013 17:00:53 +0000 Subject: [PATCH 0643/1077] Reverting from Tony's fix to my fix for saturation index of pure phases with pressure. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7553 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 66 ++++++++++++++++++++++++++++--------------------------- print.cpp | 8 +++++++ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/prep.cpp b/prep.cpp index f942f46a..1fef2627 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5520,7 +5520,7 @@ calc_delta_v(reaction *r_ptr, bool phase) /* ---------------------------------------------------------------------- */ { /* calculate delta_v from molar volumes */ - +#ifdef TONY int p = -1; LDBLE d_v = 0.0; @@ -5539,39 +5539,41 @@ calc_delta_v(reaction *r_ptr, bool phase) d_v += p * r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; } return d_v; +#else //dlp - //LDBLE d_v = 0.0; + LDBLE d_v = 0.0; - //if (phase) - //{ - // /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ - // for (size_t i = 1; r_ptr->token[i].s /*|| r_ptr->token[i].s*/ ; i++) - // { - // //if (!r_ptr->token[i].s) - // // continue; - // if (!strcmp(r_ptr->token[i].s->name, "H+")) - // continue; - // if (!strcmp(r_ptr->token[i].s->name, "e-")) - // continue; - // else if (r_ptr->token[i].s->logk[vm_tc]) - // d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; - // } - //} - //else - //{ - // for (size_t i = 0; r_ptr->token[i].name /*|| r_ptr->token[i].s*/ ; i++) - // { - // if (!r_ptr->token[i].s) - // continue; - // if (!strcmp(r_ptr->token[i].s->name, "H+")) - // continue; - // if (!strcmp(r_ptr->token[i].s->name, "e-")) - // continue; - // else if (r_ptr->token[i].s->logk[vm_tc]) - // d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; - // } - //} - //return d_v; + if (phase) + { + /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ + for (size_t i = 1; r_ptr->token[i].s /*|| r_ptr->token[i].s*/ ; i++) + { + //if (!r_ptr->token[i].s) + // continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + } + } + else + { + for (size_t i = 0; r_ptr->token[i].name /*|| r_ptr->token[i].s*/ ; i++) + { + if (!r_ptr->token[i].s) + continue; + if (!strcmp(r_ptr->token[i].s->name, "H+")) + continue; + if (!strcmp(r_ptr->token[i].s->name, "e-")) + continue; + else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + } + } + return d_v; +#endif } #ifdef PHREEQC2 /* ---------------------------------------------------------------------- */ diff --git a/print.cpp b/print.cpp index 86d5b3db..9098fa9c 100644 --- a/print.cpp +++ b/print.cpp @@ -1278,6 +1278,7 @@ print_pp_assemblage(void) { phase_ptr = x[j]->phase; PR_inprint = false; +#ifdef TONY if (phase_ptr->pr_in) { PR_inprint = true; @@ -1288,6 +1289,13 @@ print_pp_assemblage(void) } else lk = phase_ptr->lk; +#else + phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - + phase_ptr->logk[vm0]; + if (phase_ptr->rxn->logk[delta_v]) + mu_terms_in_logk = true; + lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); +#endif // dlp //phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - // phase_ptr->logk[vm0]; From 2ba41a620a75e93d68ec56ffcd3f29a9f64ce915 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 18 Mar 2013 20:06:03 +0000 Subject: [PATCH 0644/1077] More fixes to saturation index. Tony added some for NPP. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7558 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 5 ++++- class_main.cpp | 4 ++-- print.cpp | 24 +++--------------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 40872425..c4f36b89 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -356,11 +356,14 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.beta, compiled on August 6, 2012\n")); + output_msg(sformatf("Using PHREEQC: version 3.0, compiled on March 16, 2013\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); output_msg(sformatf("Database file: %s\n\n", token)); +#ifdef NPP + output_flush(); +#endif /* * local cleanup */ diff --git a/class_main.cpp b/class_main.cpp index c4e7add1..e4f8d0f2 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -253,7 +253,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.beta"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.0"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -277,7 +277,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "July 19, 2012"); + len = sprintf(buffer, "%s", "March 16, 2013"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif diff --git a/print.cpp b/print.cpp index 9098fa9c..c4d768f1 100644 --- a/print.cpp +++ b/print.cpp @@ -1193,8 +1193,10 @@ print_saturation_indices(void) PR_inprint = true; phases[i]->pr_in = false; } - reaction_ptr->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - + reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) - phases[i]->logk[vm0]; + if (reaction_ptr->logk[delta_v]) + mu_terms_in_logk = true; lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); if (PR_inprint) phases[i]->pr_in = true; @@ -1278,31 +1280,11 @@ print_pp_assemblage(void) { phase_ptr = x[j]->phase; PR_inprint = false; -#ifdef TONY - if (phase_ptr->pr_in) - { - PR_inprint = true; - phase_ptr->pr_in = false; - phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn_x, true) - - phase_ptr->logk[vm0]; - lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); - } - else - lk = phase_ptr->lk; -#else phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - phase_ptr->logk[vm0]; if (phase_ptr->rxn->logk[delta_v]) mu_terms_in_logk = true; lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); -#endif -// dlp - //phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - - // phase_ptr->logk[vm0]; - //if (phase_ptr->rxn->logk[delta_v]) - // mu_terms_in_logk = true; -// end -// lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); if (PR_inprint) phase_ptr->pr_in = true; for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; From 7bb4d371892a22b850def5c437287f3381190ee2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Mar 2013 16:03:51 +0000 Subject: [PATCH 0645/1077] cvode MAX_ITERS 40 hnew = hg predict_fail CVMEM cvode_error == TRUE || predict_fail after CVnls if (CVMEM cvode_error == TRUE) after CVNewtonIteration CVDoErrorTest exit(4); model Phreeqc.cpp pitzer.cpp sit.cpp new status ifdef'd with NPP 250 ms delay new global variable std::string string_status !!prep: switch_bases 10 to 100 orders of mag. Need to check utilities.cpp: new status git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7585 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 4 ++ Phreeqc.h | 1 + cvode.cpp | 18 +++++-- model.cpp | 4 ++ pitzer.cpp | 4 ++ sit.cpp | 4 ++ utilities.cpp | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 173 insertions(+), 3 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 72fa6a31..e4b3c3d8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1266,7 +1266,11 @@ void Phreeqc::init(void) pr.hdf = FALSE; pr.alkalinity = FALSE; status_on = true; +#ifdef NPP status_interval = 40; +#else + status_interval = 250; +#endif status_timer = clock(); count_warnings = 0; /* ---------------------------------------------------------------------- diff --git a/Phreeqc.h b/Phreeqc.h index ef7ebbe0..6fb98e5c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1490,6 +1490,7 @@ protected: bool status_on; clock_t status_interval; clock_t status_timer; + std::string status_string; int count_warnings; /* ---------------------------------------------------------------------- diff --git a/cvode.cpp b/cvode.cpp index 33dd970e..277fbb11 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -101,7 +101,7 @@ #define HLB_FACTOR RCONST(100.0) #define HUB_FACTOR RCONST(0.1) #define H_BIAS HALF -#define MAX_ITERS 4 +#define MAX_ITERS 40 /* CVSet */ @@ -1680,10 +1680,11 @@ CVHin(CVodeMem cv_mem, realtype tout) /* Set lower and upper bounds on h0, and take geometric mean Exit with this value if the bounds cross each other */ - + hlb = HLB_FACTOR * tround; hub = CVUpperBoundH0(cv_mem, tdist); hg = RSqrt(hlb * hub); + hnew = hg; if (hub < hlb) { if (sign == -1) @@ -1848,11 +1849,13 @@ CVStep(CVodeMem cv_mem) /* Looping point for attempts to take a step */ loop { + bool predict_fail = false; CVMEM cvode_test = TRUE; f(N, tn, y, ftemp, f_data); CVMEM cvode_test = FALSE; if (CVMEM cvode_error == TRUE) { + predict_fail = true; #ifdef DEBUG_CVODE CVMEM warning_msg("Before predict, y Fail, time %e\n", tn); #endif @@ -1910,6 +1913,10 @@ CVStep(CVodeMem cv_mem) CVSet(cv_mem); nflag = CVnls(cv_mem, nflag); + if (CVMEM cvode_error == TRUE || predict_fail) + { + nflag = -1; + } #ifdef DEBUG_CVODE cvode_test = TRUE; f(N, tn, y, ftemp, f_data); @@ -1934,6 +1941,7 @@ CVStep(CVodeMem cv_mem) CVMEM warning_msg("After CVnls, zn OK\n"); } #endif + //fprintf(stderr, "\nTime %e,\th %e\n", tn, h); kflag = CVHandleNFlag(cv_mem, &nflag, saved_t, &ncf); if (kflag == PREDICT_AGAIN) continue; @@ -2753,7 +2761,10 @@ CVnlsNewton(CVodeMem cv_mem, int nflag) /* Do the Newton iteration */ ier = CVNewtonIteration(cv_mem); - + if (CVMEM cvode_error == TRUE) + { + return (CONV_FAIL); + } CVMEM cvode_test = TRUE; f(N, tn, y, ftemp, f_data); CVMEM cvode_test = FALSE; @@ -3062,6 +3073,7 @@ CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, CVMEM warning_msg("CVDoErrorTest"); /*exit(8); */ CVMEM error_msg("CVDoErrorTest", 1 /* STOP */ ); + exit(4); } nfe++; N_VScale(h, tempv, zn[1]); diff --git a/model.cpp b/model.cpp index 12d1df38..5aab9385 100644 --- a/model.cpp +++ b/model.cpp @@ -76,7 +76,11 @@ model(void) debug_model_save = debug_model; pe_step_size_now = pe_step_size; step_size_now = step_size; +#ifdef NPP if (!use.Get_kinetics_in()) status(0, NULL); +#else + status(0, NULL); +#endif iterations = 0; count_basis_change = count_infeasible = 0; stop_program = FALSE; diff --git a/pitzer.cpp b/pitzer.cpp index 1f93fb58..ec6d7e8c 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1841,7 +1841,11 @@ model_pz(void) debug_model_save = debug_model; pe_step_size_now = pe_step_size; step_size_now = step_size; +#ifdef NPP if (!use.Get_kinetics_in()) status(0, NULL); +#else + status(0, NULL); +#endif iterations = 0; gamma_iterations = 0; count_basis_change = count_infeasible = 0; diff --git a/sit.cpp b/sit.cpp index 67cfc1ee..cc478c20 100644 --- a/sit.cpp +++ b/sit.cpp @@ -959,7 +959,11 @@ model_sit(void) debug_model_save = debug_model; pe_step_size_now = pe_step_size; step_size_now = step_size; +#ifdef NPP if (!use.Get_kinetics_in()) status(0, NULL); +#else + status(0, NULL); +#endif iterations = 0; gamma_iterations = 0; count_basis_change = count_infeasible = 0; diff --git a/utilities.cpp b/utilities.cpp index e07a0cbb..fa1e9995 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1388,6 +1388,7 @@ under(LDBLE xval) /* return (exp(xval * LOG_10)) */; } #ifndef PHREEQCI_GUI +#ifdef NPP /* ---------------------------------------------------------------------- */ int Phreeqc:: status(int count, const char *str, bool rk_string) @@ -1526,6 +1527,146 @@ status(int count, const char *str, bool rk_string) } return (OK); } +#else +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +status(int count, const char *str, bool rk_string) +/* ---------------------------------------------------------------------- */ +{ + char sim_str[20]; + char state_str[45]; + char spin_str[2]; + clock_t t2; + +#ifdef PHREEQ98 + if (ProcessMessages) + ApplicationProcessMessages(); + if (stop_calculations == TRUE) + error_msg("Execution canceled by user.", STOP); +#endif + if (pr.status == FALSE || phast == TRUE) + return (OK); + + if (state == INITIALIZE) + { + screen_string = sformatf("\n%-80s", "Initializing..."); + screen_msg(screen_string.c_str()); + status_on = true; + return (OK); + } + + switch (state) + { + case INITIALIZE: + break; + case TRANSPORT: + if (str != NULL) + { + if (rk_string) + { + + screen_string = screen_string.substr(0, 43); + screen_string.append(str); + status_string = screen_string; + } + else + { + screen_string = "\r"; + screen_string.append(str); + status_string = screen_string; + } + status_on = true; + } + case PHAST: + break; + default: + // if str not NULL, print it + if (str != NULL && !rk_string) + { + screen_string = "\r"; + screen_string.append(str); + status_string = screen_string; + } + else + // print state + { + std::string stdstr; + if (str != NULL && rk_string) + { + stdstr = str; + } + sprintf(sim_str, "\rSimulation %d.", simulation); + sprintf(state_str, " "); + sprintf(spin_str, " "); + switch (state) + { + default: + break; + case INITIAL_SOLUTION: + sprintf(state_str, "Initial solution %d.", use.Get_solution_ptr()->Get_n_user()); + break; + case INITIAL_EXCHANGE: + sprintf(state_str, "Initial exchange %d.", use.Get_exchange_ptr()->Get_n_user()); + break; + case INITIAL_SURFACE: + sprintf(state_str, "Initial surface %d.", use.Get_surface_ptr()->Get_n_user()); + break; + case INVERSE: + sprintf(state_str, "Inverse %d. Models = %d.", use.Get_inverse_ptr()->n_user, count); + break; + case REACTION: + if (use.Get_kinetics_in() == TRUE) + { + sprintf(state_str, "Kinetic step %d.", reaction_step); + } + else + { + sprintf(state_str, "Reaction step %d.", reaction_step); + } + break; + case ADVECTION: + sprintf(state_str, "Advection, shift %d.", advection_step); + break; + } + spinner++; + if (spinner == 1) + { + spin_str[0] = '/'; + } + else if (spinner == 2) + { + spin_str[0] = '-'; + } + else + { + spin_str[0] = '\\'; + spinner = 0; + } + if (use.Get_kinetics_in() == TRUE) + { + screen_string = sformatf("%-15s%-27s%38s", sim_str, state_str, stdstr.c_str()); + status_string = screen_string; + } + else + { + screen_string = sformatf("%-15s%-27s%1s%37s", sim_str, state_str, spin_str, stdstr.c_str()); + status_string = screen_string; + } + } + status_on = true; + break; + } + + t2 = clock(); + if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) > status_interval) + { + status_timer = t2; + screen_msg(status_string.c_str()); + status_string.clear(); + } + return (OK); +} +#endif /* NPP */ #endif /*PHREEQCI_GUI */ /* ** Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson. From c42bd892803b078da832df55d4c3ac5d8a4f0ba7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Mar 2013 17:42:27 +0000 Subject: [PATCH 0646/1077] LDBLEs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7588 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 2 +- PBasic.cpp | 2 +- SS.cxx | 4 ++-- Utils.cxx | 6 +++--- Utils.h | 4 ++-- model.cpp | 12 ++++++------ read.cpp | 2 +- structures.cpp | 2 +- tidy.cpp | 4 ++-- utilities.cpp | 12 ++++++------ 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index e2b2dc53..b1d1624d 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -233,7 +233,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case 6: // d_params while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - double dd; + LDBLE dd; sscanf(token.c_str(), "%lf", &dd); temp_d_params.push_back((LDBLE) dd); d_params_defined = true; diff --git a/PBasic.cpp b/PBasic.cpp index d9aa7bb9..d440b864 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3144,7 +3144,7 @@ factor(struct LOC_exec * LINK) break; case toklog10: { - double t = realfactor(LINK); + LDBLE t = realfactor(LINK); if (t > 0.0) { n.UU.val = log10(t); diff --git a/SS.cxx b/SS.cxx index 5c607af4..066bb7b2 100644 --- a/SS.cxx +++ b/SS.cxx @@ -482,7 +482,7 @@ cxxSS::add(const cxxSS & addee_in, LDBLE extensive) if (Utilities::strcmp_nocase(this->ss_comps[i].Get_name().c_str(), addee.Get_ss_comps()[j].Get_name().c_str()) == 0) { - double d = this->ss_comps[i].Get_initial_moles() + + LDBLE d = this->ss_comps[i].Get_initial_moles() + addee.Get_ss_comps()[j].Get_initial_moles() * extensive; this->ss_comps[i].Set_initial_moles(d); d = this->ss_comps[i].Get_moles() + @@ -511,7 +511,7 @@ cxxSS::multiply(LDBLE extensive) size_t i; for (i = 0; i < this->ss_comps.size(); i++) { - double d = this->ss_comps[i].Get_initial_moles() * extensive; + LDBLE d = this->ss_comps[i].Get_initial_moles() * extensive; this->ss_comps[i].Set_initial_moles(d); d = this->ss_comps[i].Get_moles() * extensive; this->ss_comps[i].Set_moles(d); diff --git a/Utils.cxx b/Utils.cxx index f20fd211..453218d3 100644 --- a/Utils.cxx +++ b/Utils.cxx @@ -157,11 +157,11 @@ Utilities::convert_time(double t, std::string in, std::string out) return t; } -double -Utilities::safe_exp(double t) +LDBLE +Utilities::safe_exp(LDBLE t) //////////////////////////////////////////////////////////////////////////// { - double f = 1.442695*t; // convert to exp for 2.0 + LDBLE f = 1.442695*t; // convert to exp for 2.0 if (f > DBL_MAX_EXP - 50.0) { diff --git a/Utils.h b/Utils.h index bdc59b0b..74997731 100644 --- a/Utils.h +++ b/Utils.h @@ -6,7 +6,7 @@ #include // std::ostream #include // std::istream #include // std::map - +#include "phrqtype.h" namespace Utilities { @@ -23,6 +23,6 @@ namespace Utilities void squeeze_white(std::string & s_l); double convert_time(double t, std::string in, std::string out); - double safe_exp(double t); + LDBLE safe_exp(LDBLE t); } #endif // UTILITIES_H_INCLUDED diff --git a/model.cpp b/model.cpp index 5aab9385..e757ca61 100644 --- a/model.cpp +++ b/model.cpp @@ -4668,9 +4668,9 @@ revise_guesses(void) if (x[i]->moles > 1e101 || x[i]->moles < 1e-101 || x[i]->sum > 1e101 || x[i]->sum < 1e-101) { - double d1 = log10(x[i]->moles); - double d2 = log10(x[i]->sum); - double d3 = d1 - d2; + LDBLE d1 = log10(x[i]->moles); + LDBLE d2 = log10(x[i]->sum); + LDBLE d3 = d1 - d2; if (d3 > DBL_MAX_10_EXP/2) { d = pow(10.0, DBL_MAX_10_EXP/2.); @@ -4684,7 +4684,7 @@ revise_guesses(void) { d = fabs(x[i]->moles / x[i]->sum); } - double d1; + LDBLE d1; if (d > 0) { d1 = weight * log10(d); @@ -5329,7 +5329,7 @@ numerical_jacobian(void) // avoid overflow if (residual[j] > 1.0e101) { - double t = pow(10.0, DBL_MAX_10_EXP - 50.0); + LDBLE t = pow((LDBLE) 10.0, LDBLE(DBL_MAX_10_EXP - 50.0)); if (residual[j] > t) { array[j * (count_unknowns + 1) + i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); @@ -5341,7 +5341,7 @@ numerical_jacobian(void) } else if (residual[j] < -1.0e101) { - double t = pow(10.0, DBL_MIN_10_EXP + 50.0); + LDBLE t = pow((LDBLE) 10.0, (LDBLE) (DBL_MIN_10_EXP + 50.0)); if (residual[j] < -t) { array[j * (count_unknowns + 1) + i] = pow(10.0, DBL_MIN_10_EXP + 50.0); diff --git a/read.cpp b/read.cpp index 103ae19f..70c408c0 100644 --- a/read.cpp +++ b/read.cpp @@ -2449,7 +2449,7 @@ read_kinetics(void) } else if (stdunits.size() > 0) { - std::vector::iterator it; + std::vector::iterator it; for (it = temp_kinetics.Get_steps().begin(); it != temp_kinetics.Get_steps().end(); it++) { *it = Utilities::convert_time(*it, stdunits, "s"); diff --git a/structures.cpp b/structures.cpp index 6d3c5810..996e859a 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1803,7 +1803,7 @@ cxxChemRxn2rxn(cxxChemRxn &cr) for (int i = 0; rxn_ptr_new->token[i].s != NULL; i++) { rxn_ptr_new->token[i].name = string_hsave(rxn_ptr_new->token[i].name); - double z = rxn_ptr_new->token[i].s->z; + LDBLE z = rxn_ptr_new->token[i].s->z; rxn_ptr_new->token[i].s = s_store(rxn_ptr_new->token[i].name, z, false); } return (rxn_ptr_new); diff --git a/tidy.cpp b/tidy.cpp index a94f31da..17ebb1da 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2349,7 +2349,7 @@ tidy_species(void) * Find valence of cation from coefficients of reaction components * Changed to be coefficient of exchanger */ - double exchange_coef = 0.0; + LDBLE exchange_coef = 0.0; for (j = 1; s[i]->rxn_s->token[j].s != NULL; j++) { if (s[i]->rxn_s->token[j].s->type == EX) @@ -2370,7 +2370,7 @@ tidy_species(void) } if (s[i]->type == SURF) { - double surface_coef = 0.0; + LDBLE surface_coef = 0.0; /* * Find coefficient of surface in rxn, store in equiv */ diff --git a/utilities.cpp b/utilities.cpp index fa1e9995..3de97094 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -169,7 +169,7 @@ calc_rho_0(LDBLE tc, LDBLE pa) but may give densities < 0 outside the limits, e.g. tc = 250, p = 2.5e3... */ /* The minimal pressure equals the saturation pressure... */ - double tk = tc + 273.15; + LDBLE tk = tc + 273.15; p_sat = exp(11.6702 - 3816.44 / (tk - 46.13)); if (ah2o_x <= 1.0) p_sat *= ah2o_x; @@ -180,11 +180,11 @@ calc_rho_0(LDBLE tc, LDBLE pa) } if (!use.Get_gas_phase_in()) patm_x = pa; - double pasc = pa * 1.01325e5; - double Rg = 0.461526e3; //J / kg / K - double Tref = 1386.0, Pref = 16.53e6; // K, Pa - double t_t = Tref / tk, p_p = pasc / Pref; - double ni[34] = {0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, + LDBLE pasc = pa * 1.01325e5; + LDBLE Rg = 0.461526e3; //J / kg / K + LDBLE Tref = 1386.0, Pref = 16.53e6; // K, Pa + LDBLE t_t = Tref / tk, p_p = pasc / Pref; + LDBLE ni[34] = {0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, -0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3, 0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1, -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3, From 6a9624d2e253a1141f616e5ddd28a2b8d868179b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Mar 2013 19:47:01 +0000 Subject: [PATCH 0647/1077] ah2o_x should be set to zero. ah2o is then summed from solution or mix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7589 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 2 ++ step.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/model.cpp b/model.cpp index e757ca61..123426ec 100644 --- a/model.cpp +++ b/model.cpp @@ -3141,6 +3141,8 @@ reset(void) else if (x[i]->type == AH2O) { down = up; + up = 0.05; + down = -0.03; } else if (x[i]->type == MH) { diff --git a/step.cpp b/step.cpp index 1591bce3..d8ee1d15 100644 --- a/step.cpp +++ b/step.cpp @@ -308,7 +308,7 @@ xsolution_zero(void) ph_x = 0.0; solution_pe_x = 0.0; mu_x = 0.0; - ah2o_x = 1.0; + ah2o_x = 0.0; density_x = 0.0; total_h_x = 0.0; total_o_x = 0.0; From 0d6e0bc895449c96865af098b7c699b4bf16ee65 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Mar 2013 20:37:10 +0000 Subject: [PATCH 0648/1077] used small activity water step for pizter, sit git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7590 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/model.cpp b/model.cpp index 123426ec..1bda5bac 100644 --- a/model.cpp +++ b/model.cpp @@ -3141,8 +3141,11 @@ reset(void) else if (x[i]->type == AH2O) { down = up; - up = 0.05; - down = -0.03; + if (pitzer_model || sit_model) + { + up = 0.05; + down = -0.03; + } } else if (x[i]->type == MH) { From c3bd2ecaa992117a681f769275e5eb715af0523b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Apr 2013 22:33:12 +0000 Subject: [PATCH 0649/1077] LDBLE fix git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7603 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KineticsComp.cxx b/KineticsComp.cxx index b1d1624d..3164fa4f 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -233,7 +233,7 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) case 6: // d_params while (parser.copy_token(token, next_char) == CParser::TT_DIGIT) { - LDBLE dd; + double dd; sscanf(token.c_str(), "%lf", &dd); temp_d_params.push_back((LDBLE) dd); d_params_defined = true; @@ -318,4 +318,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("d_params"), // 6 std::vector< std::string >::value_type("initial_moles") // 7 }; -const std::vector< std::string > cxxKineticsComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxKineticsComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); From 31ebd3d30e0c82272a2663416e321effee830083 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Apr 2013 22:33:52 +0000 Subject: [PATCH 0650/1077] LDBLE fix git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7604 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model.cpp b/model.cpp index 1bda5bac..0d7fe228 100644 --- a/model.cpp +++ b/model.cpp @@ -5334,7 +5334,7 @@ numerical_jacobian(void) // avoid overflow if (residual[j] > 1.0e101) { - LDBLE t = pow((LDBLE) 10.0, LDBLE(DBL_MAX_10_EXP - 50.0)); + LDBLE t = (LDBLE) pow((LDBLE) 10.0, (LDBLE) (DBL_MAX_10_EXP - 50.0)); if (residual[j] > t) { array[j * (count_unknowns + 1) + i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); From 28e082bc519db0e3d6770648e62bca0d6940ad5c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 2 Apr 2013 20:05:34 +0000 Subject: [PATCH 0651/1077] NameDouble dump failed with string greater than 21 characters. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7607 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NameDouble.cxx b/NameDouble.cxx index c6a64027..04c0fc4b 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -195,7 +195,14 @@ cxxNameDouble::dump_raw(std::ostream & s_oss, unsigned int indent) const for (const_iterator it = (*this).begin(); it != (*this).end(); it++) { s_oss << indent0; - s_oss << Utilities::pad_right(it->first, 29 - indent0.size()) << it->second << "\n"; + if (it->first.size() < 29 - indent0.size()) + { + s_oss << Utilities::pad_right(it->first, 29 - indent0.size()) << it->second << "\n"; + } + else + { + s_oss << Utilities::pad_right(it->first, it->first.size() + indent0.size()) << " " << it->second << "\n"; + } } } From 8696224afa743daf3b0554dd4d5e41c0af95179e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 2 Apr 2013 21:38:16 +0000 Subject: [PATCH 0652/1077] Bug with gas_phase_modify. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7608 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 183 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 94 insertions(+), 89 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 17ebb1da..6921ae42 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -903,7 +903,7 @@ tidy_gas_phase(void) assert(false); } cxxGasPhase *gas_phase_ptr = &(it->second); - //if (gas_phase_ptr->Get_new_def() != TRUE) + //if (!gas_phase_ptr->Get_new_def()) // continue; gas_phase_ptr->Set_new_def(false); PR = false; @@ -927,114 +927,119 @@ tidy_gas_phase(void) if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) PR = true; } -/* - * Fixed pressure - */ - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + gas_phase_ptr->Set_pr_in(PR); + if (gas_phase_ptr->Get_new_def()) { - if (gas_phase_ptr->Get_solution_equilibria()) + /* + * Fixed pressure + */ + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { - input_error++; - error_string = sformatf( + if (gas_phase_ptr->Get_solution_equilibria()) + { + input_error++; + error_string = sformatf( "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", gas_phase_ptr->Get_n_user()); - error_msg(error_string, CONTINUE); - } - /* calculate moles */ - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - gc[j].Set_moles( - gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / - R_LITER_ATM / gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: partial pressure of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - else - { -/* - * Fixed volume - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { + error_msg(error_string, CONTINUE); + } + /* calculate moles */ if (gc[j].Get_p_read() != NAN) { P += gc[j].Get_p_read(); - gc[j].Set_moles ( - gc[j].Get_p_read() * - gas_phase_ptr->Get_volume() / R_LITER_ATM / - gas_phase_ptr->Get_temperature()); + gc[j].Set_moles( + gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); } else { input_error++; error_string = sformatf( - "Gas phase %d: moles of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), - gc[j].Get_phase_name().c_str()); + "Gas phase %d: partial pressure of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); error_msg(error_string, CONTINUE); } } - } - } - gas_phase_ptr->Set_gas_comps(gc); - gas_phase_ptr->Set_pr_in(PR); + else + { + /* + * Fixed volume + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles ( + gc[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: moles of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + } - if (PR && P > 0) - { - std::vector phase_ptrs; - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) - continue; - phase_ptr->moles_x = gc[j].Get_p_read() / P; - phase_ptrs.push_back(phase_ptr); - } - V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); - gas_phase_ptr->Set_v_m(V_m); - gas_phase_ptr->Set_total_p(P); - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) + + gas_phase_ptr->Set_gas_comps(gc); + + if (PR && P > 0) { - gc[j].Set_moles(0.0); - } else + std::vector phase_ptrs; + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + continue; + phase_ptr->moles_x = gc[j].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + } + V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); + gas_phase_ptr->Set_v_m(V_m); + gas_phase_ptr->Set_total_p(P); + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + { + gc[j].Set_moles(0.0); + } else + { + gc[j].Set_moles(phase_ptr->moles_x * + gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + } + } + gas_phase_ptr->Set_gas_comps(gc); + } + /* + * Duplicate gas phase, only if not solution equilibria + */ + if (!gas_phase_ptr->Get_solution_equilibria()) { - gc[j].Set_moles(phase_ptr->moles_x * - gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + for (int j = n_user + 1; j <= last; j++) + { + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + } + } + else + { + gas_phase_ptr->Set_new_def(true); } } - gas_phase_ptr->Set_gas_comps(gc); - } -/* - * Duplicate gas phase, only if not solution equilibria - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - n_user = gas_phase_ptr->Get_n_user(); - last = gas_phase_ptr->Get_n_user_end(); - gas_phase_ptr->Set_n_user_end(n_user); - for (int j = n_user + 1; j <= last; j++) - { - Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); - } - } - else - { - gas_phase_ptr->Set_new_def(true); } } return (OK); From da493bbb7cb03c740bdc8fd52e98236e38067af4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 2 Apr 2013 22:47:47 +0000 Subject: [PATCH 0653/1077] One more fix for gas_phase (new_def) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7612 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tidy.cpp b/tidy.cpp index 6921ae42..73cfe3e6 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -905,7 +905,7 @@ tidy_gas_phase(void) cxxGasPhase *gas_phase_ptr = &(it->second); //if (!gas_phase_ptr->Get_new_def()) // continue; - gas_phase_ptr->Set_new_def(false); + //gas_phase_ptr->Set_new_def(false); PR = false; P = 0.0; std::vector gc = gas_phase_ptr->Get_gas_comps(); @@ -930,6 +930,7 @@ tidy_gas_phase(void) gas_phase_ptr->Set_pr_in(PR); if (gas_phase_ptr->Get_new_def()) { + gas_phase_ptr->Set_new_def(false); /* * Fixed pressure */ From d5fa02a72a952142ebfe80784fdb2207e936707a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Apr 2013 21:36:03 +0000 Subject: [PATCH 0654/1077] a little rearranging of global_structures and under git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7613 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 14 ++++++++++++-- utilities.cpp | 7 ++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/global_structures.h b/global_structures.h index c741b8f5..ce9fe9c4 100644 --- a/global_structures.h +++ b/global_structures.h @@ -115,8 +115,6 @@ #define MAX_ELEMENTS 50 /* default estimate of the number of elements */ #define MAX_LENGTH 256 /* maximum number of characters component name */ #define MAX_LINE 4096 /* estimate of maximum line length */ -#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ -#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ #define MAX_MASS_BALANCE 10 /* initial guess of number mass balance equations for a solution */ #define MAX_MASTER 50 /* default estimate of the number of master species */ #define MAX_ELTS 15 /* default estimate for maximum number of times elements occur in @@ -130,11 +128,23 @@ #define MAX_TRXN 16 /* default estimate for maximum number of components in an eqn */ #define MAX_UNKNOWNS 15 /* default estimate for maximum number of unknowns in model */ #define TOL 1e-9 /* tolerance for comparisons of double numbers */ +#define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ +#define MAX_M 1000.0 +#ifdef USE_DECIMAL128 +#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ +#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +#define MIN_TOTAL 1e-60 +#define MIN_TOTAL_SS MIN_TOTAL/100 +#define MIN_RELATED_SURFACE MIN_TOTAL*100 +#define MIN_RELATED_LOG_ACTIVITY -60 +#else +#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ #define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ #define MIN_TOTAL 1e-25 #define MIN_TOTAL_SS MIN_TOTAL/100 #define MIN_RELATED_SURFACE MIN_TOTAL*100 #define MIN_RELATED_LOG_ACTIVITY -30 +#endif #define REF_PRES_PASCAL 1.01325E5 /* Reference pressure: 1 atm */ /* * Hash definitions diff --git a/utilities.cpp b/utilities.cpp index 3de97094..d367b0f9 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1378,14 +1378,11 @@ under(LDBLE xval) { return (0.0); } -/* if (xval > MAX_LM) { */ - if (xval > 3.) + if (xval > MAX_LM) { - return (1.0e3); -/* return ( pow (10.0, MAX_LM));*/ + return ( MAX_M ); } return (pow ((LDBLE) 10.0, xval)); -/* return (exp(xval * LOG_10)) */; } #ifndef PHREEQCI_GUI #ifdef NPP From dc977aee06991bdf8a2899b5f7fb936b63bb918c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Apr 2013 22:06:01 +0000 Subject: [PATCH 0655/1077] LDBLE for SScomp Changed sundials to use LDBLE git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7614 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SScomp.cxx | 2 +- SScomp.h | 2 +- sundialstypes.h | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/SScomp.cxx b/SScomp.cxx index 0c14376c..6088bf47 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -271,7 +271,7 @@ cxxSScomp::totalize(Phreeqc * phreeqc_ptr) } #endif void -cxxSScomp::multiply(double extensive) +cxxSScomp::multiply(LDBLE extensive) { this->moles *= extensive; this->delta *= extensive; diff --git a/SScomp.h b/SScomp.h index afacc0e7..7aaaa2fd 100644 --- a/SScomp.h +++ b/SScomp.h @@ -43,7 +43,7 @@ class cxxSScomp: public PHRQ_base LDBLE Get_dnb() const {return this->dnb;} void Set_dnb(LDBLE t) {this->dnb = t;} - void multiply(double extensive); + void multiply(LDBLE extensive); protected: std::string name; diff --git a/sundialstypes.h b/sundialstypes.h index f343d63e..3054a063 100644 --- a/sundialstypes.h +++ b/sundialstypes.h @@ -82,11 +82,7 @@ * * ******************************************************************/ -#ifdef USE_LONG_DOUBLE - typedef long double realtype; -#else - typedef double realtype; -#endif + typedef LDBLE realtype; typedef long int integertype; #define SUNDIALS_FLOAT 0 From 5330549e534f5fbb0d506d87db3626cabbbfd183 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Apr 2013 14:03:53 +0000 Subject: [PATCH 0656/1077] Revising cvode git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7616 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 369 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) diff --git a/kinetics.cpp b/kinetics.cpp index 4f0c4e9b..7c38ab39 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1855,6 +1855,374 @@ set_reaction(int i, int use_mix, int use_kinetics) */ return (OK); } +//#define REVISED_CVODE +#ifdef REVISED_CVODE +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) +/* ---------------------------------------------------------------------- */ +{ +/* + * Kinetics calculations + * Rates and moles of each reaction are calculated in calc_kinetic_reaction + * Total number of moles in reaction is stored in kinetics[i].totals + */ + + int converge, m_iter; + int pr_all_save; + int nsaver; + cxxKinetics *kinetics_ptr; + cxxPPassemblage *pp_assemblage_ptr; + cxxSSassemblage *ss_assemblage_ptr; + cxxUse use_save; + int save_old, n_reactions /*, nok, nbad */ ; + + /* CVODE definitions */ + realtype ropt[OPT_SIZE], reltol, t, tout, tout1, sum_t; + long int iopt[OPT_SIZE]; + int flag; +/* + * Set nsaver + */ + run_reactions_iterations = 0; + kin_time_x = kin_time; + nsaver = i; + if (state == TRANSPORT || state == PHAST) + { + if (use_mix == DISP) + { + nsaver = -2; + } + else if (use_mix == STAG) + { + nsaver = -2 - i; + } + } + if (state == ADVECTION) + { + nsaver = -2; + } +/* + * Check that reaction exists for this cell .. + */ + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + if (kin_time <= 0 || + (state == REACTION && use.Get_kinetics_in() == FALSE) || + (state == TRANSPORT && kinetics_ptr == NULL) || + (state == PHAST && kinetics_ptr == NULL) || + (state == ADVECTION && kinetics_ptr == NULL)) + { + converge = + set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + run_reactions_iterations += iterations; + } + else + { +/* + * Save moles of kinetic reactants for printout... + */ + size_t count_comps = kinetics_ptr->Get_kinetics_comps().size(); + m_temp = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); + if (m_temp == NULL) + malloc_error(); + + m_original = + (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); + if (m_original == NULL) + malloc_error(); + + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + m_original[j] = kinetics_comp_ptr->Get_m(); + m_temp[j] = kinetics_comp_ptr->Get_m(); + } +/* +* Start the loop for timestepping ... + * Use either Runge-Kutta-Fehlberg, or final result extrapolation + */ + pr_all_save = pr.all; + pr.all = FALSE; +/* + * This condition makes output equal for incremental_reactions TRUE/FALSE... + * (if (incremental_reactions == FALSE || reaction_step == 1) + */ + store_get_equi_reactants(i, FALSE); + if (!kinetics_ptr->Get_use_cvode()) + { + rk_kinetics(i, kin_time, use_mix, nsaver, step_fraction); + + // finish up + rate_sim_time = rate_sim_time_start + kin_time; + store_get_equi_reactants(i, TRUE); + pr.all = pr_all_save; + + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); + } + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + } + else + { + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); + if (nsaver != i) + { + Utilities::Rxn_copy(Rxn_solution_map, i, save_old); + } + for (int j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + +/* + * Do mix first + */ + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); + cvode_n_user = i; + cvode_kinetics_ptr = (void *) kinetics_ptr; + cvode_n_reactions = n_reactions; + cvode_rate_sim_time_start = rate_sim_time_start; + cvode_rate_sim_time = rate_sim_time; + + if (multi_Dflag) + converge = set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + else + converge = set_and_run_wrapper(i, use_mix, FALSE, i, 0.0); + if (converge == MASS_BALANCE) + error_msg + ("Negative concentration in system. Stopping calculation.", + STOP); + saver(); + pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); + ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); + if (pp_assemblage_ptr != NULL) + { + cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (ss_assemblage_ptr != NULL) + { + cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } + + /* allocate space for CVODE */ + kinetics_machEnv = M_EnvInit_Serial(n_reactions); + kinetics_machEnv->phreeqc_ptr = this; + kinetics_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (kinetics_y == NULL) + malloc_error(); + cvode_last_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_last_good_y == NULL) + malloc_error(); + cvode_prev_good_y = N_VNew(n_reactions, kinetics_machEnv); /* Allocate y, abstol vectors */ + if (cvode_prev_good_y == NULL) + malloc_error(); + kinetics_abstol = N_VNew(n_reactions, kinetics_machEnv); + if (kinetics_abstol == NULL) + malloc_error(); + for (int j = 0; j < n_reactions; j++) + { + Ith(cvode_last_good_y, j + 1) = 0.0; + Ith(cvode_prev_good_y, j + 1) = 0.0; + Ith(kinetics_abstol, j + 1) = 0.0; + } +/* + * Set y to 0.0 + */ + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(0.0); + Ith(kinetics_y, j + 1) = 0.0; + Ith(kinetics_abstol, j + 1) = kinetics_comp_ptr->Get_tol(); + /*Ith(abstol,j+1) = 1e-8; */ + /* m_temp[j] = kinetics_ptr->comps[j].m; */ + } + reltol = 0.0; + + /* Call CVodeMalloc to initialize CVODE: + + NEQ is the problem size = number of equations + f is the user's right hand side function in y'=f(t,y) + T0 is the initial time + y is the initial dependent variable vector + BDF specifies the Backward Differentiation Formula + NEWTON specifies a Newton iteration + SV specifies scalar relative and vector absolute tolerances + &reltol is a pointer to the scalar relative tolerance + abstol is the absolute tolerance vector + FALSE indicates there are no optional inputs in iopt and ropt + iopt is an array used to communicate optional integer input and output + ropt is an array used to communicate optional real input and output + + A pointer to CVODE problem memory is returned and stored in cvode_mem. */ + /* Don't know what this does */ + /* + iopt[SLDET] = TRUE; + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); + cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, ADAMS, FUNCTIONAL, SV, &reltol, abstol, NULL, NULL, FALSE, iopt, ropt, machEnv); + iopt[MXSTEP] is maximum number of steps that CVODE tries. + */ + iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); + iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, SV, + &reltol, kinetics_abstol, this, NULL, TRUE, iopt, + ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + t = 0; + tout = kin_time; + /*ropt[HMAX] = tout/10.; */ + /*ropt[HMIN] = 1e-17; */ + use_save = use; + flag = CVode(kinetics_cvode_mem, tout, kinetics_y, &t, NORMAL); + rate_sim_time = rate_sim_time_start + t; + /* + printf("At t = %0.4e y =%14.6e %14.6e %14.6e\n", + t, Ith(y,1), Ith(y,2), Ith(y,3)); + */ + m_iter = 0; + sum_t = 0; + RESTART: + while (flag != SUCCESS) + { + sum_t += cvode_last_good_time; + error_string = sformatf( + "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", + (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); + warning_msg(error_string); +#ifdef DEBUG_KINETICS + if (m_iter > 5) + dump_kinetics_stderr(cell_no); +#endif + + cvode_last_good_time = 0; + if (++m_iter >= kinetics_ptr->Get_bad_step_max()) + { + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + error_msg("Repeated restart of integration.", STOP); + } + tout1 = tout - sum_t; + t = 0; + N_VScale(1.0, cvode_last_good_y, kinetics_y); + for (int j = 0; j < OPT_SIZE; j++) + { + iopt[j] = 0; + ropt[j] = 0; + } + CVodeFree(kinetics_cvode_mem); /* Free the CVODE problem memory */ + iopt[MXSTEP] = kinetics_ptr->Get_cvode_steps(); + iopt[MAXORD] = kinetics_ptr->Get_cvode_order(); + kinetics_cvode_mem = + CVodeMalloc(n_reactions, f, 0.0, kinetics_y, BDF, NEWTON, + SV, &reltol, kinetics_abstol, this, NULL, + TRUE, iopt, ropt, kinetics_machEnv); + if (kinetics_cvode_mem == NULL) + malloc_error(); + + /* Call CVDense to specify the CVODE dense linear solver with the + user-supplied Jacobian routine Jac. */ + flag = CVDense(kinetics_cvode_mem, Jac, this); + if (flag != SUCCESS) + { + error_msg("CVDense failed.", STOP); + } + flag = CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); + } + // end integration + // update + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(Ith(kinetics_y, j + 1)); + kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_moles(m_original[j]); + kinetics_comp_ptr->Set_m(0.0); + } + } + if (use.Get_pp_assemblage_ptr() != NULL) + { + Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); + } + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) + { + warning_msg("FAIL 2 after successful integration in CVode"); + flag = -1; + goto RESTART; + } + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); + } +/* + * Restore solution i, if necessary + */ + if (nsaver != i) + { + Utilities::Rxn_copy(Rxn_solution_map, save_old, i); + } + free_cvode(); + use.Set_mix_in(use_save.Get_mix_in()); + use.Set_mix_ptr(use_save.Get_mix_ptr()); + + // finish up + rate_sim_time = rate_sim_time_start + kin_time; + store_get_equi_reactants(i, TRUE); + pr.all = pr_all_save; + + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); + } + m_temp = (LDBLE *) free_check_null(m_temp); + m_original = (LDBLE *) free_check_null(m_original); + } // end cvode + } + iterations = run_reactions_iterations; + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = NULL; + } + if (cvode_ss_assemblage_save != NULL) + { + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = NULL; + } + return (OK); +} +#else /* ---------------------------------------------------------------------- */ int Phreeqc:: run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) @@ -2219,6 +2587,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: free_cvode(void) From 4733f935edfe638d343ce9fc1376485a98093f26 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Apr 2013 19:41:26 +0000 Subject: [PATCH 0657/1077] Working on REVISED_CVODE ifdef. Runs correctly, but does not produce correct deltas. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7617 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + StorageBin.cxx | 73 +++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 1 + kinetics.cpp | 88 +++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 147 insertions(+), 16 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 6fb98e5c..cf32cfca 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -375,6 +375,7 @@ public: // kinetics.cpp ------------------------------- void cvode_init(void); + bool cvode_update_reactants(int i, int nsaver); int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); diff --git a/StorageBin.cxx b/StorageBin.cxx index e6756126..39d43786 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -38,8 +38,81 @@ PHRQ_base(io) { // default constructor for cxxStorageBin this->system.Set_io(io); + this->system.Initialize(); } +cxxStorageBin::cxxStorageBin(cxxUse &use_ref, PHRQ_io *io) +: +PHRQ_base(io) +{ + this->system.Set_io(io); + this->system.Initialize(); + // Solution + if (use_ref.Get_solution_ptr() != NULL) + { + this->Set_Solution(use_ref.Get_solution_ptr()->Get_n_user(), use_ref.Get_solution_ptr()); + } + + // Exchange + if (use_ref.Get_exchange_ptr() != NULL) + { + this->Set_Exchange(use_ref.Get_exchange_ptr()->Get_n_user(), use_ref.Get_exchange_ptr()); + } + + // gas_phase + if (use_ref.Get_gas_phase_ptr() != NULL) + { + this->Set_GasPhase(use_ref.Get_gas_phase_ptr()->Get_n_user(), use_ref.Get_gas_phase_ptr()); + } + + // kinetics + if (use_ref.Get_kinetics_ptr() != NULL) + { + this->Set_Kinetics(use_ref.Get_kinetics_ptr()->Get_n_user(), use_ref.Get_kinetics_ptr()); + } + + // pp_assemblage + if (use_ref.Get_pp_assemblage_ptr() != NULL) + { + this->Set_PPassemblage(use_ref.Get_pp_assemblage_ptr()->Get_n_user(), use_ref.Get_pp_assemblage_ptr()); + } + + // ss_assemblage + if (use_ref.Get_ss_assemblage_ptr() != NULL) + { + this->Set_SSassemblage(use_ref.Get_ss_assemblage_ptr()->Get_n_user(), use_ref.Get_ss_assemblage_ptr()); + } + + // surface + if (use_ref.Get_surface_ptr() != NULL) + { + this->Set_Surface(use_ref.Get_surface_ptr()->Get_n_user(), use_ref.Get_surface_ptr()); + } + + // mix + if (use_ref.Get_mix_ptr() != NULL) + { + this->Set_Mix(use_ref.Get_mix_ptr()->Get_n_user(), use_ref.Get_mix_ptr()); + } + + // reaction + if (use_ref.Get_reaction_ptr() != NULL) + { + this->Set_Reaction(use_ref.Get_reaction_ptr()->Get_n_user(), use_ref.Get_reaction_ptr()); + } + + // reaction temperature + if (use_ref.Get_temperature_ptr() != NULL) + { + this->Set_Temperature(use_ref.Get_temperature_ptr()->Get_n_user(), use_ref.Get_temperature_ptr()); + } + + // reaction pressure + if (use_ref.Get_pressure_ptr() != NULL) + { + this->Set_Pressure(use_ref.Get_pressure_ptr()->Get_n_user(), use_ref.Get_pressure_ptr()); + } +} cxxStorageBin::~cxxStorageBin() { } diff --git a/StorageBin.h b/StorageBin.h index e93111e9..f9a14fe4 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -25,6 +25,7 @@ class cxxStorageBin: public PHRQ_base public: cxxStorageBin(PHRQ_io *io=NULL); + cxxStorageBin(cxxUse &use_ref, PHRQ_io *io=NULL); virtual ~cxxStorageBin(); void Remove(int n); diff --git a/kinetics.cpp b/kinetics.cpp index 7c38ab39..72fb5728 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1912,12 +1912,11 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) (state == PHAST && kinetics_ptr == NULL) || (state == ADVECTION && kinetics_ptr == NULL)) { - converge = - set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); + converge = set_and_run_wrapper(i, use_mix, FALSE, nsaver, step_fraction); if (converge == MASS_BALANCE) - error_msg - ("Negative concentration in system. Stopping calculation.", - STOP); + { + error_msg("Negative concentration in system. Stopping calculation.", STOP); + } run_reactions_iterations += iterations; } else @@ -1930,8 +1929,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) if (m_temp == NULL) malloc_error(); - m_original = - (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); + m_original = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE)); if (m_original == NULL) malloc_error(); @@ -1972,6 +1970,9 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) } else { + // save initial reactants + // cxxStorageBin save_bin(use); // if needed + save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2); if (nsaver != i) { @@ -2044,8 +2045,6 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) kinetics_comp_ptr->Set_moles(0.0); Ith(kinetics_y, j + 1) = 0.0; Ith(kinetics_abstol, j + 1) = kinetics_comp_ptr->Get_tol(); - /*Ith(abstol,j+1) = 1e-8; */ - /* m_temp[j] = kinetics_ptr->comps[j].m; */ } reltol = 0.0; @@ -2101,7 +2100,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) */ m_iter = 0; sum_t = 0; - RESTART: +RESTART: while (flag != SUCCESS) { sum_t += cvode_last_good_time; @@ -2109,10 +2108,9 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) "CVode incomplete at cvode_steps %d. Cell: %d\tTime: %e\tCvode calls: %d, continuing...\n", (int) iopt[NST], cell_no, (double) sum_t, m_iter + 1); warning_msg(error_string); -#ifdef DEBUG_KINETICS - if (m_iter > 5) - dump_kinetics_stderr(cell_no); -#endif + + // run with last good y, update reactants + cvode_update_reactants(i, nsaver); cvode_last_good_time = 0; if (++m_iter >= kinetics_ptr->Get_bad_step_max()) @@ -2147,9 +2145,11 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) error_msg("CVDense failed.", STOP); } flag = CVode(kinetics_cvode_mem, tout1, kinetics_y, &t, NORMAL); - } - // end integration + } + // end cvode integration + // update +#ifdef SKIP for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); @@ -2161,6 +2161,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) kinetics_comp_ptr->Set_m(0.0); } } +#endif if (use.Get_pp_assemblage_ptr() != NULL) { Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; @@ -2171,6 +2172,15 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); } + + + if (!cvode_update_reactants(i, nsaver)) + { + warning_msg("FAIL 2 after successful integration in CVode"); + flag = -1; + goto RESTART; + } +#ifdef SKIP calc_final_kinetic_reaction(kinetics_ptr); if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) { @@ -2183,6 +2193,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); } +#endif /* * Restore solution i, if necessary */ @@ -2199,12 +2210,23 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) store_get_equi_reactants(i, TRUE); pr.all = pr_all_save; +#ifdef SKIP kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m()); } +#else + kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); + cxxKinetics *kinetics_original_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_kinetics_user()); + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + cxxKineticsComp * kinetics_original_comp_ptr = &(kinetics_original_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(kinetics_original_comp_ptr->Get_m() - kinetics_comp_ptr->Get_m()); + } +#endif m_temp = (LDBLE *) free_check_null(m_temp); m_original = (LDBLE *) free_check_null(m_original); } // end cvode @@ -3254,3 +3276,37 @@ cvode_init(void) cvode_ss_assemblage_save = NULL; return; } +bool Phreeqc:: +cvode_update_reactants(int i, int nsaver) +{ + cxxKinetics *kinetics_ptr = use.Get_kinetics_ptr(); + int n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); + + for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + kinetics_comp_ptr->Set_moles(Ith(cvode_last_good_y, j + 1)); + //kinetics_comp_ptr->Set_m(kinetics_comp_ptr->Get_m() - kinetics_comp_ptr->Get_moles()); + kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); + m_original[j] = kinetics_comp_ptr->Get_m(); + if (kinetics_comp_ptr->Get_m() < 0) + { + kinetics_comp_ptr->Set_moles(m_original[j]); + kinetics_comp_ptr->Set_m(0.0); + } + } + calc_final_kinetic_reaction(kinetics_ptr); + if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) + { + error_msg("CVODE step was bad", STOP); + return false; + } + saver(); + + for (int j = 0; j < n_reactions; j++) + { + Ith(cvode_last_good_y, j + 1) = 0.0; + Ith(cvode_prev_good_y, j + 1) = 0.0; + } + return true; +} \ No newline at end of file From 6917e9be1efcffa3e44a74cde4d3122d10acca24 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Apr 2013 21:40:35 +0000 Subject: [PATCH 0658/1077] Error, used last_good_y instead of kinetic_y at final step. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7618 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/kinetics.cpp b/kinetics.cpp index 72fb5728..c974837e 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -2173,7 +2173,8 @@ RESTART: use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); } - + // put remaining kinetic reaction in last_good_y for update + N_VScale(1.0, kinetics_y, cvode_last_good_y); if (!cvode_update_reactants(i, nsaver)) { warning_msg("FAIL 2 after successful integration in CVode"); @@ -3284,23 +3285,31 @@ cvode_update_reactants(int i, int nsaver) for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) { - cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + + // Adds reaction defined by last_good_y kinetics_comp_ptr->Set_moles(Ith(cvode_last_good_y, j + 1)); - //kinetics_comp_ptr->Set_m(kinetics_comp_ptr->Get_m() - kinetics_comp_ptr->Get_moles()); + // Reduces m kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); m_original[j] = kinetics_comp_ptr->Get_m(); + m_temp[j] = kinetics_comp_ptr->Get_m(); if (kinetics_comp_ptr->Get_m() < 0) { kinetics_comp_ptr->Set_moles(m_original[j]); kinetics_comp_ptr->Set_m(0.0); } } + // calculates net reaction calc_final_kinetic_reaction(kinetics_ptr); + + // runs previous solution plus net reaction if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) { error_msg("CVODE step was bad", STOP); return false; } + + // saves result to reactants defined by saver saver(); for (int j = 0; j < n_reactions; j++) From 40e97fd96cdab6b6b9f08acf727b62616a33f9ef Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Apr 2013 23:03:02 +0000 Subject: [PATCH 0659/1077] Fix to the incremental updating. f uses saved pp_assemblage and ss_assemblage. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7619 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kinetics.cpp b/kinetics.cpp index c974837e..1126e755 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -2161,7 +2161,6 @@ RESTART: kinetics_comp_ptr->Set_m(0.0); } } -#endif if (use.Get_pp_assemblage_ptr() != NULL) { Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; @@ -2172,6 +2171,7 @@ RESTART: Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); } +#endif // put remaining kinetic reaction in last_good_y for update N_VScale(1.0, kinetics_y, cvode_last_good_y); @@ -3312,6 +3312,19 @@ cvode_update_reactants(int i, int nsaver) // saves result to reactants defined by saver saver(); + cxxPPassemblage *pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, nsaver); + cxxSSassemblage *ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, nsaver); + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (cvode_ss_assemblage_save != NULL) + { + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } + for (int j = 0; j < n_reactions; j++) { Ith(cvode_last_good_y, j + 1) = 0.0; From 4cb5d32f0d4cc7ba0f653301d389f39afc2aa43f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 24 Apr 2013 15:31:49 +0000 Subject: [PATCH 0660/1077] Added phi to gas_phase print. Test case gas_phase_pressure Still need to debug problem with gas_phase not working correctly from Thomas Baumann. Fixed spread problem with mass of water. Test case MassWater Problems with kinetics and small concentrations (Benoit and Janek) still unresolved. Added test cases to Makefile git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7642 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 12 ++++++++++-- spread.cpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/print.cpp b/print.cpp index c4d768f1..9b0e30a9 100644 --- a/print.cpp +++ b/print.cpp @@ -1220,10 +1220,18 @@ print_saturation_indices(void) phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, phases[i]->formula)); if (gas && phases[i]->pr_in && phases[i]->pr_p) - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + { + if (fabs(phases[i]->pr_p - pow(10, si) / phases[i]->pr_phi) > 0.1) + { + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + " Pressure ", (double) pow(10, si) / phases[i]->pr_phi, " atm, phi ", (double) phases[i]->pr_phi, ".")); + } else + { + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + } + } output_msg("\n"); - } output_msg("\n\n"); diff --git a/spread.cpp b/spread.cpp index 3f35fb86..4d1071e8 100644 --- a/spread.cpp +++ b/spread.cpp @@ -801,7 +801,8 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; case 10: /* water */ { - next_char = char_string; + //next_char = char_string; + //int j = copy_token(token, &next_char); // read identifier "water" int j = copy_token(token, &next_char); if (j == EMPTY) { From ce037cb208a03686a95f9921e58d7b7aa1a417eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 24 Apr 2013 19:13:03 +0000 Subject: [PATCH 0661/1077] Fixed gas_phase problem. total_p was reset for fixed pressure in a couple of places (prep and tidy). Added test case ch4-valid and added to Makefile. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7643 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 5 ++++- tidy.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/prep.cpp b/prep.cpp index 1fef2627..3b976db8 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4230,7 +4230,10 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) } if (gas_phase_ptr && iterations > 2) { - gas_phase_ptr->Set_total_p(P); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_p(P); + } gas_phase_ptr->Set_v_m(V_m); return (OK); } diff --git a/tidy.cpp b/tidy.cpp index 73cfe3e6..7a4748b5 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1005,7 +1005,10 @@ tidy_gas_phase(void) } V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); gas_phase_ptr->Set_v_m(V_m); - gas_phase_ptr->Set_total_p(P); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_p(P); + } std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { From 2c9611d04aeb6943a010b88406aacee998dfc64c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 25 Apr 2013 16:42:21 +0000 Subject: [PATCH 0662/1077] tony fix to print 20130425 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7644 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 9b0e30a9..2e2010aa 100644 --- a/print.cpp +++ b/print.cpp @@ -1219,7 +1219,7 @@ print_saturation_indices(void) output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, phases[i]->formula)); - if (gas && phases[i]->pr_in && phases[i]->pr_p) + if (gas_in && phases[i]->pr_in && phases[i]->pr_p) { if (fabs(phases[i]->pr_p - pow(10, si) / phases[i]->pr_phi) > 0.1) { From 0cb1337f19ca9c45c5de725382888ba2bdce84e9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 26 Apr 2013 01:06:27 +0000 Subject: [PATCH 0663/1077] added patch from tmishima@jcity.maeda.co.jp for multi-threaded IPhreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7649 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index cf32cfca..1b8a8c69 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -36,6 +36,9 @@ #include "cxxMix.h" #include "Use.h" #include "Surface.h" +#ifdef SWIG_SHARED_OBJ +#include "thread.h" +#endif class cxxNameDouble; class cxxKinetics; From f73a156b02d03b984096d6c2bf0df9925112388b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Apr 2013 14:08:29 +0000 Subject: [PATCH 0664/1077] revised cvode is working I think. Had to be careful when updating m_temp and use the saved solutions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7650 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- cvode.cpp | 32 ++++++++++++++----------- kinetics.cpp | 66 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 1b8a8c69..53f4c684 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -378,7 +378,7 @@ public: // kinetics.cpp ------------------------------- void cvode_init(void); - bool cvode_update_reactants(int i, int nsaver); + bool cvode_update_reactants(int i, int nsaver, bool save_it); int run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction); int set_and_run(int i, int use_mix, int use_kinetics, int nsaver, LDBLE step_fraction); diff --git a/cvode.cpp b/cvode.cpp index 277fbb11..ab34280d 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -15,8 +15,8 @@ * It is independent of the CVODE linear solver in use. * * * *******************************************************************/ - - +#include "nvector_serial.h" +#define Ith(v,i) NV_Ith_S(v,i-1) /************************************************************/ /******************* BEGIN Imports **************************/ /************************************************************/ @@ -1342,17 +1342,23 @@ CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype * t, int itask) /* * check interpolation */ - cvode_test = TRUE; + CVMEM cvode_test = TRUE; f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) + CVMEM cvode_test = FALSE; + if (CVMEM cvode_error == TRUE) { - CVMEM warning_msg("End of cvode, Interpolated y Fail\n"); + //CVMEM warning_msg("End of cvode, Interpolated y Fail\n"); + fprintf(stderr, "End of cvode, Interpolated y Fail\n"); return (-1); } else { - CVMEM warning_msg("End of cvode, Interpolated y OK\n"); + //CVMEM warning_msg("End of cvode, Interpolated y OK\n"); + //fprintf(stderr, "End of cvode, Interpolated y OK\n"); + //for (int i = 0; i <= N; i++) + //{ + // fprintf(stderr, "%d %e\n", i, Ith(y, i)); + //} } #endif return (istate); @@ -2015,10 +2021,10 @@ CVStep(CVodeMem cv_mem) CVCompleteStep(cv_mem); #ifdef DEBUG_CVODE - cvode_test = TRUE; + CVMEM cvode_test = TRUE; f(N, tn, y, ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) + CVMEM cvode_test = FALSE; + if (CVMEM cvode_error == TRUE) { CVMEM warning_msg("After complete step, y Fail\n"); } @@ -2026,10 +2032,10 @@ CVStep(CVodeMem cv_mem) { CVMEM warning_msg("After complete step, y OK\n"); } - cvode_test = TRUE; + CVMEM cvode_test = TRUE; f(N, tn, zn[0], ftemp, f_data); - cvode_test = FALSE; - if (cvode_error == TRUE) + CVMEM cvode_test = FALSE; + if (CVMEM cvode_error == TRUE) { CVMEM warning_msg("After complete step, zn Fail\n"); } diff --git a/kinetics.cpp b/kinetics.cpp index 1126e755..faddee0b 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -241,6 +241,9 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) } } kinetics_ptr->Set_totals(elt_list_NameDouble()); + + //std::cerr << "\n"; + //kinetics_ptr->Get_totals().dump_raw(std::cerr, 1); return (OK); } @@ -2110,7 +2113,7 @@ RESTART: warning_msg(error_string); // run with last good y, update reactants - cvode_update_reactants(i, nsaver); + cvode_update_reactants(i, nsaver, true); cvode_last_good_time = 0; if (++m_iter >= kinetics_ptr->Get_bad_step_max()) @@ -2175,7 +2178,7 @@ RESTART: // put remaining kinetic reaction in last_good_y for update N_VScale(1.0, kinetics_y, cvode_last_good_y); - if (!cvode_update_reactants(i, nsaver)) + if (!cvode_update_reactants(i, nsaver, false)) { warning_msg("FAIL 2 after successful integration in CVode"); flag = -1; @@ -3278,7 +3281,7 @@ cvode_init(void) return; } bool Phreeqc:: -cvode_update_reactants(int i, int nsaver) +cvode_update_reactants(int i, int nsaver, bool save_it) { cxxKinetics *kinetics_ptr = use.Get_kinetics_ptr(); int n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size(); @@ -3291,8 +3294,9 @@ cvode_update_reactants(int i, int nsaver) kinetics_comp_ptr->Set_moles(Ith(cvode_last_good_y, j + 1)); // Reduces m kinetics_comp_ptr->Set_m(m_original[j] - kinetics_comp_ptr->Get_moles()); - m_original[j] = kinetics_comp_ptr->Get_m(); - m_temp[j] = kinetics_comp_ptr->Get_m(); + // Don't update until after calc_final_reaction + //m_original[j] = kinetics_comp_ptr->Get_m(); + //m_temp[j] = kinetics_comp_ptr->Get_m(); if (kinetics_comp_ptr->Get_m() < 0) { kinetics_comp_ptr->Set_moles(m_original[j]); @@ -3301,7 +3305,16 @@ cvode_update_reactants(int i, int nsaver) } // calculates net reaction calc_final_kinetic_reaction(kinetics_ptr); - + if (use.Get_pp_assemblage_ptr() != NULL) + { + Rxn_pp_assemblage_map[cvode_pp_assemblage_save->Get_n_user()] = *cvode_pp_assemblage_save; + use.Set_pp_assemblage_ptr(Utilities::Rxn_find(Rxn_pp_assemblage_map, cvode_pp_assemblage_save->Get_n_user())); + } + if (use.Get_ss_assemblage_ptr() != NULL) + { + Rxn_ss_assemblage_map[cvode_ss_assemblage_save->Get_n_user()] = *cvode_ss_assemblage_save; + use.Set_ss_assemblage_ptr(Utilities::Rxn_find(Rxn_ss_assemblage_map, cvode_ss_assemblage_save->Get_n_user())); + } // runs previous solution plus net reaction if (set_and_run_wrapper(i, NOMIX, TRUE, nsaver, 1.0) == MASS_BALANCE) { @@ -3310,25 +3323,32 @@ cvode_update_reactants(int i, int nsaver) } // saves result to reactants defined by saver - saver(); + if (save_it) + { + saver(); - cxxPPassemblage *pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, nsaver); - cxxSSassemblage *ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, nsaver); - if (cvode_pp_assemblage_save != NULL) - { - delete cvode_pp_assemblage_save; - cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); - } - if (cvode_ss_assemblage_save != NULL) - { - delete cvode_ss_assemblage_save; - cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); - } + cxxPPassemblage *pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, nsaver); + cxxSSassemblage *ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, nsaver); + if (cvode_pp_assemblage_save != NULL) + { + delete cvode_pp_assemblage_save; + cvode_pp_assemblage_save = new cxxPPassemblage(*pp_assemblage_ptr); + } + if (cvode_ss_assemblage_save != NULL) + { + delete cvode_ss_assemblage_save; + cvode_ss_assemblage_save = new cxxSSassemblage(*ss_assemblage_ptr); + } - for (int j = 0; j < n_reactions; j++) - { - Ith(cvode_last_good_y, j + 1) = 0.0; - Ith(cvode_prev_good_y, j + 1) = 0.0; + for (int j = 0; j < n_reactions; j++) + { + Ith(cvode_last_good_y, j + 1) = 0.0; + Ith(cvode_prev_good_y, j + 1) = 0.0; + + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); + m_original[j] = kinetics_comp_ptr->Get_m(); + m_temp[j] = kinetics_comp_ptr->Get_m(); + } } return true; } \ No newline at end of file From e60d708c8468e91958590700aa70eb9779c655dc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Apr 2013 14:26:24 +0000 Subject: [PATCH 0665/1077] Some of Tony's changes that I missed. Removed some but not all ' git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7652 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 12 ++-- Phreeqc.cpp | 4 -- basicsubs.cpp | 10 +++- inverse.cpp | 8 +-- isotopes.cpp | 10 ++-- kinetics.cpp | 2 +- print.cpp | 6 +- utilities.cpp | 140 ++------------------------------------------- 8 files changed, 32 insertions(+), 160 deletions(-) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index c4f36b89..6170c4db 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -124,7 +124,7 @@ fpunchf_user(int user_index, const char *format, double d) if (fpunchf_user_s_warning == 0) { error_string = sformatf( - "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + "USER_PUNCH: Headings count does not match number of calls to PUNCH.\n"); warning_msg(error_string); fpunchf_user_s_warning = 1; } @@ -157,7 +157,7 @@ fpunchf_user(int user_index, const char *format, char * d) if (fpunchf_user_s_warning == 0) { error_string = sformatf( - "USER_PUNCH: Headings count doesn't match number of calls to PUNCH.\n"); + "USER_PUNCH: Headings count does not match number of calls to PUNCH.\n"); warning_msg(error_string); fpunchf_user_s_warning = 1; } @@ -623,10 +623,10 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, #else phrq_io->Set_error_file(stderr); #endif - error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); #ifdef NPP - error_msg(sformatf( "\nERROR: Can't open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP); + error_msg(sformatf( "\nERROR: Cannot open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP); break; #endif error_flush(); @@ -699,7 +699,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else phrq_io->Set_error_file(stderr); #endif - error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); error_flush(); batch = FALSE; @@ -772,7 +772,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, phrq_io->Set_error_file(stderr); #endif - error_string = sformatf( "\nERROR: Can't open file, %s.\n", name); + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); error_flush(); batch = FALSE; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e4b3c3d8..cea3da4f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1266,11 +1266,7 @@ void Phreeqc::init(void) pr.hdf = FALSE; pr.alkalinity = FALSE; status_on = true; -#ifdef NPP - status_interval = 40; -#else status_interval = 250; -#endif status_timer = clock(); count_warnings = 0; /* ---------------------------------------------------------------------- diff --git a/basicsubs.cpp b/basicsubs.cpp index 2926b0bd..926e0902 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -504,7 +504,13 @@ calc_logk_s(const char *name) { l_logk[i] = 0.0; } - select_log_k_expression(s_ptr->logk, l_logk); + if (s_ptr->moles) + select_log_k_expression(s_ptr->rxn_x->logk, l_logk); + else + { + // perhaps calculate species' delta_v if absent? + select_log_k_expression(s_ptr->rxn_s->logk, l_logk); + } add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk); lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); return (lk); @@ -1161,7 +1167,7 @@ get_calculate_value(const char *name) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); error_msg(error_string, STOP); } diff --git a/inverse.cpp b/inverse.cpp index 85c898b1..dc0a7a1b 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -77,7 +77,7 @@ inverse_models(void) netpath_file = fopen(string, "w"); if (netpath_file == NULL) { - error_string = sformatf( "Can't open file, %s.", string); + error_string = sformatf( "Cannot open file, %s.", string); error_msg(error_string, STOP); } count_inverse_models = 0; @@ -3922,7 +3922,7 @@ dump_netpath(struct inverse *inverse_ptr) netpath_file = fopen(string.c_str(), "w"); if (netpath_file == NULL) { - error_string = sformatf( "Can't open file, %s.", inverse_ptr->netpath); + error_string = sformatf( "Cannot open file, %s.", inverse_ptr->netpath); error_msg(error_string, STOP); } add_to_file("netpath.fil", inverse_ptr->netpath); @@ -4741,7 +4741,7 @@ dump_netpath_pat(struct inverse *inv_ptr) model_file = fopen(string1.c_str(), "w"); if (model_file == NULL) { - error_string = sformatf( "Can't open file, %s.", string.c_str()); + error_string = sformatf( "Cannot open file, %s.", string.c_str()); error_msg(error_string, STOP); } add_to_file("model.fil", string1.c_str()); @@ -5117,7 +5117,7 @@ add_to_file(const char *filename, const char *string) model_file = fopen(filename, "w"); if (model_file == NULL) { - error_string = sformatf( "Can't open file, %s.", filename); + error_string = sformatf( "Cannot open file, %s.", filename); error_msg(error_string, STOP); } } diff --git a/isotopes.cpp b/isotopes.cpp index 05cfc83d..4f247cd6 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -908,7 +908,7 @@ punch_calculate_values(void) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); error_msg(error_string, STOP); } @@ -1134,7 +1134,7 @@ calculate_values(void) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value[j]->name); error_msg(error_string, STOP); } @@ -1181,7 +1181,7 @@ calculate_values(void) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); error_msg(error_string, STOP); } @@ -1244,7 +1244,7 @@ calculate_values(void) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); error_msg(error_string, STOP); } @@ -1316,7 +1316,7 @@ calculate_values(void) } if (rate_moles == NAN) { - error_string = sformatf( "Calculated value not SAVE'd for %s.", + error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value[j]->name); error_msg(error_string, STOP); } diff --git a/kinetics.cpp b/kinetics.cpp index faddee0b..c6f3a966 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -108,7 +108,7 @@ calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step) } if (rate_moles == NAN) { - error_string = sformatf( "Moles of reaction not SAVE'd for %s.", + error_string = sformatf( "Moles of reaction not SAVEed for %s.", kinetics_comp_ptr->Get_rate_name().c_str()); error_msg(error_string, STOP); } diff --git a/print.cpp b/print.cpp index 2e2010aa..857e3577 100644 --- a/print.cpp +++ b/print.cpp @@ -538,7 +538,7 @@ print_gas_phase(void) if (PR) output_msg(" (Peng-Robinson calculation)\n"); else if (gas_phase_ptr->Get_total_p() >= 1500) - output_msg(" WARNING: Program's limit.\n"); + output_msg(" WARNING: Program limit.\n"); else output_msg(" \n"); output_msg(sformatf(" Gas volume: %10.2e liters\n", @@ -547,7 +547,7 @@ print_gas_phase(void) output_msg(sformatf(" Molar volume: %10.2e liters/mole", (double) (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()))); if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles() <= 0.03) || (PR && gas_phase_ptr->Get_v_m() <= 0.03))) - output_msg(" WARNING: Program's limit for Peng-Robinson.\n"); + output_msg(" WARNING: Program limit for Peng-Robinson.\n"); else output_msg("\n"); if (PR) @@ -626,7 +626,7 @@ print_gas_phase(void) (double) moles, (double) delta_moles)); if (!strcmp(phase_ptr->name, "H2O(g)") && phase_ptr->p_soln_x == 90) - output_msg(" WARNING: The pressure of H2O(g) is above program's limit: use the polynomial for log_k.\n"); + output_msg(" WARNING: The pressure of H2O(g) is above the program limit: use the polynomial for log_k.\n"); } output_msg("\n"); diff --git a/utilities.cpp b/utilities.cpp index d367b0f9..1f99f163 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1385,7 +1385,6 @@ under(LDBLE xval) return (pow ((LDBLE) 10.0, xval)); } #ifndef PHREEQCI_GUI -#ifdef NPP /* ---------------------------------------------------------------------- */ int Phreeqc:: status(int count, const char *str, bool rk_string) @@ -1412,145 +1411,15 @@ status(int count, const char *str, bool rk_string) status_on = true; return (OK); } +#ifdef NPP t2 = clock(); if (((state < ADVECTION && reaction_step < count_total_steps) || (state == ADVECTION && (advection_step < count_ad_shifts || cell_no < count_cells)) || - (state == TRANSPORT && (transport_step < count_shifts || (mixrun < nmix && - cell_no < count_cells)))) + (state == TRANSPORT && (transport_step < count_shifts || (mixrun < nmix /*&& + cell_no < count_cells*/)))) && (int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) < status_interval) return (OK); - else - status_timer = t2; - - switch (state) - { - case INITIALIZE: - break; - case TRANSPORT: - if (str != NULL) - { - if (rk_string) - { - - screen_string = screen_string.substr(0, 43); - screen_string.append(str); - screen_msg(screen_string.c_str()); - } - else - { - screen_string = "\r"; - screen_string.append(str); - screen_msg(screen_string.c_str()); - } - status_on = true; - } - case PHAST: - break; - default: - // if str not NULL, print it - if (str != NULL && !rk_string) - { - screen_string = "\r"; - screen_string.append(str); - screen_msg(screen_string.c_str()); } - else - // print state - { - std::string stdstr; - if (str != NULL && rk_string) - { - stdstr = str; - } - sprintf(sim_str, "\rSimulation %d.", simulation); - sprintf(state_str, " "); - sprintf(spin_str, " "); - switch (state) - { - default: - break; - case INITIAL_SOLUTION: - sprintf(state_str, "Initial solution %d.", use.Get_solution_ptr()->Get_n_user()); - break; - case INITIAL_EXCHANGE: - sprintf(state_str, "Initial exchange %d.", use.Get_exchange_ptr()->Get_n_user()); - break; - case INITIAL_SURFACE: - sprintf(state_str, "Initial surface %d.", use.Get_surface_ptr()->Get_n_user()); - break; - case INVERSE: - sprintf(state_str, "Inverse %d. Models = %d.", use.Get_inverse_ptr()->n_user, count); - break; - case REACTION: - if (use.Get_kinetics_in() == TRUE) - { - sprintf(state_str, "Kinetic step %d.", reaction_step); - } - else - { - sprintf(state_str, "Reaction step %d.", reaction_step); - } - break; - case ADVECTION: - sprintf(state_str, "Advection, shift %d.", advection_step); - break; - } - spinner++; - if (spinner == 1) - { - spin_str[0] = '/'; - } - else if (spinner == 2) - { - spin_str[0] = '-'; - } - else - { - spin_str[0] = '\\'; - spinner = 0; - } - if (use.Get_kinetics_in() == TRUE) - { - screen_string = sformatf("%-15s%-27s%38s", sim_str, state_str, stdstr.c_str()); - screen_msg(screen_string.c_str()); - } - else - { - screen_string = sformatf("%-15s%-27s%1s%37s", sim_str, state_str, spin_str, stdstr.c_str()); - screen_msg(screen_string.c_str()); - } - } - status_on = true; - break; - } - return (OK); -} -#else -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -status(int count, const char *str, bool rk_string) -/* ---------------------------------------------------------------------- */ -{ - char sim_str[20]; - char state_str[45]; - char spin_str[2]; - clock_t t2; - -#ifdef PHREEQ98 - if (ProcessMessages) - ApplicationProcessMessages(); - if (stop_calculations == TRUE) - error_msg("Execution canceled by user.", STOP); #endif - if (pr.status == FALSE || phast == TRUE) - return (OK); - - if (state == INITIALIZE) - { - screen_string = sformatf("\n%-80s", "Initializing..."); - screen_msg(screen_string.c_str()); - status_on = true; - return (OK); - } switch (state) { @@ -1654,8 +1523,10 @@ status(int count, const char *str, bool rk_string) break; } +#ifndef NPP t2 = clock(); if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) > status_interval) +#endif { status_timer = t2; screen_msg(status_string.c_str()); @@ -1663,7 +1534,6 @@ status(int count, const char *str, bool rk_string) } return (OK); } -#endif /* NPP */ #endif /*PHREEQCI_GUI */ /* ** Dynamic hashing, after CACM April 1988 pp 446-457, by Per-Ake Larson. From 24ed8b5cc054c588243a1b5a54a9004b757b3a7c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Apr 2013 16:57:25 +0000 Subject: [PATCH 0666/1077] Tony's changes for gases. Removes some more 's. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7653 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Form1.h | 14 +++++++------- PBasic.cpp | 14 +++++++------- PHRQ_io_output.cpp | 6 +++--- Parser.cxx | 2 +- Phreeqc.cpp | 4 ++++ Solution.cxx | 2 +- class_main.cpp | 4 ++-- cvdense.cpp | 2 +- cvode.cpp | 2 +- dense.cpp | 2 +- gases.cpp | 7 +++++++ global_structures.h | 2 +- inverse.cpp | 10 +++++----- kinetics.cpp | 9 +++------ model.cpp | 4 ++-- nvector_serial.cpp | 2 +- prep.cpp | 12 ++++++++++-- read.cpp | 8 ++++---- smalldense.cpp | 2 +- tidy.cpp | 2 +- utilities.cpp | 4 ++-- 21 files changed, 65 insertions(+), 49 deletions(-) diff --git a/Form1.h b/Form1.h index 1056e753..1831bc96 100644 --- a/Form1.h +++ b/Form1.h @@ -234,7 +234,7 @@ namespace zdg_ui2 { myCurve->Line->Width = (float) Curves[i]->Get_line_w(); else myCurve->Line->IsVisible = false; - /* hmm... dash/dot don't display well */ + /* hmm... dash/dot don`t display well */ // myCurve->Line->Style = System::Drawing::Drawing2D::DashStyle::Dot; myCurve->Symbol->Fill = gcnew Fill( Color::FromName("White") ); if (Curves[i]->Get_symbol_size() > 0.0) @@ -283,13 +283,13 @@ namespace zdg_ui2 { // Make the Y axis scale red // myPane->YAxis->Scale->FontSpec->FontColor = Color::Red; // myPane->YAxis->Title->FontSpec->FontColor = Color::Red; - // turn off the opposite tics so the Y tics don't show up on the Y2 axis + // turn off the opposite tics so the Y tics don`t show up on the Y2 axis if (Y2show) { myPane->YAxis->MajorTic->IsOpposite = false; myPane->YAxis->MinorTic->IsOpposite = false; } - // Don't display the Y zero line + // Don`t display the Y zero line myPane->YAxis->MajorGrid->IsZeroLine = false; // Align the Y axis labels so they are flush to the axis myPane->YAxis->Scale->Align = AlignP::Inside; @@ -325,10 +325,10 @@ namespace zdg_ui2 { // Make the Y2 axis scale blue // myPane->Y2Axis->Scale->FontSpec->FontColor = Color::Blue; // myPane->Y2Axis->Title->FontSpec->FontColor = Color::Blue; - // turn off the opposite tics so the Y2 tics don't show up on the Y axis + // turn off the opposite tics so the Y2 tics don`t show up on the Y axis myPane->Y2Axis->MajorTic->IsOpposite = false; myPane->Y2Axis->MinorTic->IsOpposite = false; - // Don't display the Y2 axis grid lines + // Don`t display the Y2 axis grid lines myPane->Y2Axis->MajorGrid->IsVisible = false; // Align the Y2 axis labels so they are flush to the axis myPane->Y2Axis->Scale->Align = AlignP::Inside; @@ -876,7 +876,7 @@ namespace zdg_ui2 { // Save GraphObjList ZedGraph::GraphObjList ^GOL_copy = gcnew ZedGraph::GraphObjList(zg1->GraphPane->GraphObjList); - // Don't write red hint boxes + // Don`t write red hint boxes zg1->GraphPane->GraphObjList = GOL_no_hints; // Set background @@ -1031,7 +1031,7 @@ namespace zdg_ui2 { // } // } //} - /* explicitly reset the max in case of log scale, zedgraphs doesn't do this... */ + /* explicitly reset the max in case of log scale, zedgraphs doesn`t do this... */ if ((fabs(chart->Get_axis_scale_x()[1] - NA) < 1e-3) && zg1->GraphPane->XAxis->Type == AxisType::Log) { double max = -1e99; diff --git a/PBasic.cpp b/PBasic.cpp index d440b864..bf8d8f80 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1830,7 +1830,7 @@ findvar(struct LOC_exec *LINK) long FORLIM; if (LINK->t == NULL || LINK->t->kind != tokvar) - snerr(": can't find variable"); + snerr(": can`t find variable"); v = LINK->t->UU.vp; LINK->t = LINK->t->next; if (LINK->t == NULL || LINK->t->kind != toklp) @@ -2470,28 +2470,28 @@ factor(struct LOC_exec * LINK) LINK->t = LINK->t->next; count_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) - snerr(": can't find variable"); + snerr(": can`t find variable"); /* return number of names of species */ LINK->t = LINK->t->next; require(tokcomma, LINK); names_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) - snerr(": can't find name of species"); + snerr(": can`t find name of species"); /* return number of types of species */ LINK->t = LINK->t->next; require(tokcomma, LINK); types_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || types_varrec->stringvar != 1) - snerr(": can't find type of species"); + snerr(": can`t find type of species"); /* return number of moles of species */ LINK->t = LINK->t->next; require(tokcomma, LINK); moles_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) - snerr(": can't find moles of species"); + snerr(": can`t find moles of species"); LINK->t = LINK->t->next; arg_num = 4; } @@ -5915,7 +5915,7 @@ P_trimname(register char * fn, register int len) return fnbuf; } -/* Pascal's "memavail" doesn't make much sense in Unix with virtual memory. +/* Pascal's "memavail" doesn`t make much sense in Unix with virtual memory. We fix memory size as 10Meg as a reasonable compromise. */ long PBasic:: @@ -5931,7 +5931,7 @@ maxavail(void) } /* Sets are stored as an array of longs. S[0] is the size of the set; - S[N] is the N'th 32-bit chunk of the set. S[0] equals the maximum + S[N] is the n`th 32-bit chunk of the set. S[0] equals the maximum I such that S[I] is nonzero. S[0] is zero for an empty set. Within each long, bits are packed from lsb to msb. The first bit of the set is the element with ordinal value 0. (Thus, for a "set of 5..99", diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 6170c4db..bd18915b 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -274,7 +274,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, { if (!phrq_io->log_open("phreeqc.log")) { - error_msg("Can't open log file, phreeqc.log.", STOP); + error_msg("Cannot open log file, phreeqc.log.", STOP); } } /* @@ -356,7 +356,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.0, compiled on March 16, 2013\n")); + output_msg(sformatf("Using PHREEQC: version 3.0.2, compiled on April 9, 2013\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); @@ -470,7 +470,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, { if (!phrq_io->log_open("phreeqc.log")) { - error_msg("Can't open log file, phreeqc.log.", STOP); + error_msg("Cannot open log file, phreeqc.log.", STOP); } } /* diff --git a/Parser.cxx b/Parser.cxx index 8e6c3b17..33281f81 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -1163,7 +1163,7 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, } else { - if (flag_error) // don't throw error + if (flag_error) // don`t throw error { if (true) // (database_file == NULL) { diff --git a/Phreeqc.cpp b/Phreeqc.cpp index cea3da4f..e4b3c3d8 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1266,7 +1266,11 @@ void Phreeqc::init(void) pr.hdf = FALSE; pr.alkalinity = FALSE; status_on = true; +#ifdef NPP + status_interval = 40; +#else status_interval = 250; +#endif status_timer = clock(); count_warnings = 0; /* ---------------------------------------------------------------------- diff --git a/Solution.cxx b/Solution.cxx index 9350bbef..ba4088c9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -992,7 +992,7 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->total_o = o_tot; this->cb = charge; - // Don't bother to update activities? + // Don`t bother to update activities? //this->Update(const_nd); this->totals = const_nd; } diff --git a/class_main.cpp b/class_main.cpp index e4f8d0f2..611520e4 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -253,7 +253,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.0"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.0.2"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -277,7 +277,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "March 16, 2013"); + len = sprintf(buffer, "%s", "April 9, 2013"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif diff --git a/cvdense.cpp b/cvdense.cpp index fb782aa3..deebc3d0 100644 --- a/cvdense.cpp +++ b/cvdense.cpp @@ -35,7 +35,7 @@ #define CVMEM_MALLOC CVMEM #include "phqalloc.h" -/* WARNING don't include any headers below here */ +/* WARNING don`t include any headers below here */ /* Error Messages */ diff --git a/cvode.cpp b/cvode.cpp index ab34280d..d52617d8 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -35,7 +35,7 @@ #define CVMEM_MALLOC CVMEM #include "phqalloc.h" -/* WARNING don't include any headers below here */ +/* WARNING don`t include any headers below here */ /************************************************************/ diff --git a/dense.cpp b/dense.cpp index 35b536e1..c8f753f9 100644 --- a/dense.cpp +++ b/dense.cpp @@ -22,7 +22,7 @@ #include "dense.h" #include "smalldense.h" -/* WARNING don't include any headers below here */ +/* WARNING don`t include any headers below here */ #define ZERO RCONST(0.0) #define ONE RCONST(1.0) diff --git a/gases.cpp b/gases.cpp index ec13799e..c813d922 100644 --- a/gases.cpp +++ b/gases.cpp @@ -554,6 +554,7 @@ calc_PR(void) phase_ptr->pr_p = 0; phase_ptr->pr_phi = 1; phase_ptr->pr_si_f = 0.0; + //phase_ptr->logk[vm0] = 0.0; // *** continue; } phase_ptr->pr_p = phase_ptr->fraction_x * P; @@ -568,12 +569,18 @@ calc_PR(void) B = b_sum * P / R_TK; B_r = phase_ptr->pr_b / b_sum; if (rz > B) + { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + if (phi > 4.44) + phi = 4.44; + } else phi = -3.0; // fugacity coefficient > 0.05 phase_ptr->pr_phi = exp(phi); phase_ptr->pr_si_f = phi / LOG_10; // pr_si_f updated + // **** + //phase_ptr->logk[vm0] = V_m * 1e3 * phase_ptr->fraction_x; phase_ptr->pr_in = true; } return (V_m); diff --git a/global_structures.h b/global_structures.h index ce9fe9c4..c94e2f06 100644 --- a/global_structures.h +++ b/global_structures.h @@ -202,7 +202,7 @@ typedef struct Element /* ** The user only sees the first two fields, ** as we pretend to pass back only a pointer to ENTRY. - ** {S}he doesn't know what else is in here. + ** {S}he doesn`t know what else is in here. */ const char *Key; char *Data; diff --git a/inverse.cpp b/inverse.cpp index dc0a7a1b..7c7af7df 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -77,7 +77,7 @@ inverse_models(void) netpath_file = fopen(string, "w"); if (netpath_file == NULL) { - error_string = sformatf( "Cannot open file, %s.", string); + error_string = sformatf( "Can`t open file, %s.", string); error_msg(error_string, STOP); } count_inverse_models = 0; @@ -2879,7 +2879,7 @@ check_solns(struct inverse *inv_ptr) (size_t) max_column_count * sizeof(LDBLE)); } /* - * Can't Zero out epsilon constraint rows for other solutions because not sure which + * Can`t Zero out epsilon constraint rows for other solutions because not sure which * are which */ @@ -3922,7 +3922,7 @@ dump_netpath(struct inverse *inverse_ptr) netpath_file = fopen(string.c_str(), "w"); if (netpath_file == NULL) { - error_string = sformatf( "Cannot open file, %s.", inverse_ptr->netpath); + error_string = sformatf( "Can`t open file, %s.", inverse_ptr->netpath); error_msg(error_string, STOP); } add_to_file("netpath.fil", inverse_ptr->netpath); @@ -4741,7 +4741,7 @@ dump_netpath_pat(struct inverse *inv_ptr) model_file = fopen(string1.c_str(), "w"); if (model_file == NULL) { - error_string = sformatf( "Cannot open file, %s.", string.c_str()); + error_string = sformatf( "Can`t open file, %s.", string.c_str()); error_msg(error_string, STOP); } add_to_file("model.fil", string1.c_str()); @@ -5117,7 +5117,7 @@ add_to_file(const char *filename, const char *string) model_file = fopen(filename, "w"); if (model_file == NULL) { - error_string = sformatf( "Cannot open file, %s.", filename); + error_string = sformatf( "Can`t open file, %s.", filename); error_msg(error_string, STOP); } } diff --git a/kinetics.cpp b/kinetics.cpp index c6f3a966..b30e3f69 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -241,9 +241,6 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) } } kinetics_ptr->Set_totals(elt_list_NameDouble()); - - //std::cerr << "\n"; - //kinetics_ptr->Get_totals().dump_raw(std::cerr, 1); return (OK); } @@ -2067,7 +2064,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) ropt is an array used to communicate optional real input and output A pointer to CVODE problem memory is returned and stored in cvode_mem. */ - /* Don't know what this does */ + /* Don`t know what this does */ /* iopt[SLDET] = TRUE; cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); @@ -2448,7 +2445,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) ropt is an array used to communicate optional real input and output A pointer to CVODE problem memory is returned and stored in cvode_mem. */ - /* Don't know what this does */ + /* Don`t know what this does */ /* iopt[SLDET] = TRUE; cvode_mem = CVodeMalloc(n_reactions, f, 0.0, y, BDF, NEWTON, SV, &reltol, abstol, NULL, NULL, TRUE, iopt, ropt, machEnv); @@ -3348,7 +3345,7 @@ cvode_update_reactants(int i, int nsaver, bool save_it) cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); m_original[j] = kinetics_comp_ptr->Get_m(); m_temp[j] = kinetics_comp_ptr->Get_m(); - } + } } return true; } \ No newline at end of file diff --git a/model.cpp b/model.cpp index 0d7fe228..ed580a76 100644 --- a/model.cpp +++ b/model.cpp @@ -2557,7 +2557,7 @@ calc_gas_pressures(void) } if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { - if (PR /*&& gas_unknown->gas_phase->total_p > 1 */ && iterations > 2) + if (PR /*&& gas_unknown->gas_phase->total_p > 1 */ && iterations > 0) { calc_PR(phase_ptrs, gas_phase_ptr->Get_total_p(), tk_x, 0); } @@ -2953,7 +2953,7 @@ reset(void) && calculating_deriv == FALSE) { /* - * Don't take out more mineral than is present + * Don`t take out more mineral than is present */ for (i = 0; i < count_unknowns; i++) { diff --git a/nvector_serial.cpp b/nvector_serial.cpp index 50ce7a78..581f4367 100644 --- a/nvector_serial.cpp +++ b/nvector_serial.cpp @@ -25,7 +25,7 @@ #include "sundialstypes.h" #include "sundialsmath.h" -/* WARNING don't include any headers below here */ +/* WARNING don`t include any headers below here */ #define ZERO RCONST(0.0) #define HALF RCONST(0.5) diff --git a/prep.cpp b/prep.cpp index 3b976db8..a199a820 100644 --- a/prep.cpp +++ b/prep.cpp @@ -115,7 +115,7 @@ prep(void) else { /* - * If model is same, just update masses, don't rebuild unknowns and lists + * If model is same, just update masses, don`t rebuild unknowns and lists */ quick_setup(); } @@ -4213,8 +4213,12 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) B = b_sum * P / R_TK; B_r = phase_ptr->pr_b / b_sum; if (rz > B) + { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + if (phi > 4.44) + phi = 4.44; + } else phi = -3.0; // fugacity coefficient > 0.05 phase_ptr->pr_phi = exp(phi); @@ -4325,6 +4329,8 @@ adjust_setup_pure_phases(void) si_org = comp_ptr->Get_si_org(); if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { + if (si_org > 3.5) + si_org = 3.5; p = exp(si_org * LOG_10); patm_x = p; t = use.Get_solution_ptr()->Get_tc() + 273.15; @@ -4731,6 +4737,8 @@ adjust_setup_solution(void) phase_ptrs.push_back(phase_ptr); if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { + if (x[i]->si > 3.5) + x[i]->si = 3.5; p = exp(x[i]->si * LOG_10); patm_x = p; t = use.Get_solution_ptr()->Get_tc() + 273.15; @@ -5298,7 +5306,7 @@ write_mb_eqn_x(void) struct master *master_ptr; /* * Rewrite any secondary master species flagged REWRITE - * Don't add in any pe reactions + * Don`t add in any pe reactions */ count = 0; repeat = TRUE; diff --git a/read.cpp b/read.cpp index 70c408c0..04a37eef 100644 --- a/read.cpp +++ b/read.cpp @@ -4702,7 +4702,7 @@ read_selected_output(void) punch_close(); if (punch_open(file_name) != OK) { - error_string = sformatf( "Can't open file, %s.", file_name); + error_string = sformatf( "Can`t open file, %s.", file_name); input_error++; error_msg(error_string, CONTINUE); } @@ -5038,7 +5038,7 @@ read_selected_output(void) punch_close(); if (punch_open("selected.out") != OK) { - error_string = sformatf( "Can't open file, %s.", "selected.out"); + error_string = sformatf( "Can`t open file, %s.", "selected.out"); input_error++; error_msg(error_string, CONTINUE); } @@ -7030,7 +7030,7 @@ read_surface(void) || temp_surface.Get_related_phases()) { error_msg - ("Can't transport surfaces related to phases or rates (yet).", + ("Can`t transport surfaces related to phases or rates (yet).", CONTINUE); input_error++; } @@ -9095,7 +9095,7 @@ read_user_graph(void) strcpy(file_name, next_char); if (!OpenCSVFile(file_name)) { - error_string = sformatf( "Can't open file, %s. Give the full path + name, or copy the file to the working directory.", file_name); + error_string = sformatf( "Can`t open file, %s. Give the full path + name, or copy the file to the working directory.", file_name); input_error++; error_msg(error_string, CONTINUE); } diff --git a/smalldense.cpp b/smalldense.cpp index b7ac1d58..a803b10c 100644 --- a/smalldense.cpp +++ b/smalldense.cpp @@ -19,7 +19,7 @@ #include "smalldense.h" #include "sundialstypes.h" #include "sundialsmath.h" -/* WARNING don't include any headers below here */ +/* WARNING don`t include any headers below here */ #define ZERO RCONST(0.0) #define ONE RCONST(1.0) diff --git a/tidy.cpp b/tidy.cpp index 7a4748b5..e787ced1 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2553,7 +2553,7 @@ tidy_solutions(void) { /* * Define n_user for any solutions read by solution_spread that - * don't have n_user defined + * don`t have n_user defined */ struct master *master_ptr; diff --git a/utilities.cpp b/utilities.cpp index 1f99f163..2d080d0d 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1525,7 +1525,7 @@ status(int count, const char *str, bool rk_string) #ifndef NPP t2 = clock(); - if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) > status_interval) + if ((int) (1e3 / clocks_per_sec * (t2 - status_timer)) > status_interval) #endif { status_timer = t2; @@ -1725,7 +1725,7 @@ hsearch_multi(HashTable * Table, ENTRY item, ACTION action) /* if (++Table->KeyCount / MUL(Table->SegmentCount,SegmentSize) > Table->MaxLoadFactor) */ if (++Table->KeyCount / ((Table->SegmentCount) << (SegmentSizeShift)) > Table->MaxLoadFactor) - ExpandTable_multi(Table); /* doesn't affect q */ + ExpandTable_multi(Table); /* doesn`t affect q */ return ((ENTRY *) q); } From 691125972593d493a403961d87aeab3cf7b31595 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Apr 2013 20:53:22 +0000 Subject: [PATCH 0667/1077] CLOCKS_PER_SEC git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7654 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities.cpp b/utilities.cpp index 2d080d0d..0423b2e2 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -1525,7 +1525,7 @@ status(int count, const char *str, bool rk_string) #ifndef NPP t2 = clock(); - if ((int) (1e3 / clocks_per_sec * (t2 - status_timer)) > status_interval) + if ((int) (1e3 / CLOCKS_PER_SEC * (t2 - status_timer)) > status_interval) #endif { status_timer = t2; From 0607e086c593c46e5afb5ec96dbd6cf9c5ba6902 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Apr 2013 16:05:21 +0000 Subject: [PATCH 0668/1077] Fix print of PR gases in saturation_indices. more replacing '. Amm.dat and pitzer.dat updated to GCA paper. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7656 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- mainsubs.cpp | 2 +- print.cpp | 13 +++---------- read.cpp | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index 3039143d..33509ce5 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1570,7 +1570,7 @@ initial_gas_phases(int print) print_gas_phase(); if (PR /*&& use.Get_gas_phase_ptr()->total_p > 1.0*/) warning_msg("While initializing gas phase composition by equilibrating:\n" - " Found definitions of gas' critical temperature and pressure.\n" + " Found definitions of gas` critical temperature and pressure.\n" " Going to use Peng-Robinson in subsequent calculations.\n"); xgas_save(n_user); punch_all(); diff --git a/print.cpp b/print.cpp index 857e3577..1163070f 100644 --- a/print.cpp +++ b/print.cpp @@ -1219,17 +1219,10 @@ print_saturation_indices(void) output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, phases[i]->formula)); - if (gas_in && phases[i]->pr_in && phases[i]->pr_p) + if (gas && phases[i]->pr_in && phases[i]->pr_p && (phases[i]->moles_x || state == 1)) { - if (fabs(phases[i]->pr_p - pow(10, si) / phases[i]->pr_phi) > 0.1) - { - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", - " Pressure ", (double) pow(10, si) / phases[i]->pr_phi, " atm, phi ", (double) phases[i]->pr_phi, ".")); - } else - { - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", - " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); - } + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); } output_msg("\n"); } diff --git a/read.cpp b/read.cpp index 04a37eef..3564c7f3 100644 --- a/read.cpp +++ b/read.cpp @@ -2842,7 +2842,7 @@ read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) if (j < 1) { input_error++; - error_msg("Expecting numeric values for calculating the species' molar volume from the supcrt database.", + error_msg("Expecting numeric values for calculating the species molar volume from the supcrt database.", CONTINUE); return (ERROR); } From b23fb304f56483fc5e0545fbfe2417554acebd75 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Apr 2013 19:23:45 +0000 Subject: [PATCH 0669/1077] still working on print of saturation indices for gases git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7657 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/print.cpp b/print.cpp index 1163070f..67a640d9 100644 --- a/print.cpp +++ b/print.cpp @@ -1219,10 +1219,27 @@ print_saturation_indices(void) output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, phases[i]->formula)); - if (gas && phases[i]->pr_in && phases[i]->pr_p && (phases[i]->moles_x || state == 1)) + if (gas && phases[i]->pr_in && phases[i]->pr_p) { - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", - " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + if (phases[i]->moles_x || state == INITIAL_SOLUTION) + { + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + } else + { + for (int j = 0; j < count_unknowns; j++) + { + if (x[j]->type != PP) + continue; + if (!strcmp(x[j]->phase->name, phases[i]->name)) + { + if (x[j]->moles) + output_msg(sformatf("\t%s%5.1f%s%5.3f%s", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + break; + } + } + } } output_msg("\n"); } From 28d649ab93d88e33d36741721e6dac7d2509230c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 30 Apr 2013 04:35:34 +0000 Subject: [PATCH 0670/1077] fixed for input file having spaces ie phreeqc "C:\Users\charlton\Documents\Visual Studio 2005\Projects\phreeqci-trunk\Bugs\jmahoney@mahoneygeochem.com\no_selected_output_error\ex2" would try to open "C:\Users\charlton\Documents\Visual.out" for the output file git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7660 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index bd18915b..5bb7abd6 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -249,6 +249,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, strcpy(query, "Name of output file?"); ptr = default_name; copy_token(token, &ptr, &l); + strcpy(token, default_name); strcat(token, ".out"); std::ofstream * local_output_stream; if (argc <= 1) From 8e3394ca8c05f6814624a7203e51de8edd2d6063 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 30 Apr 2013 04:38:05 +0000 Subject: [PATCH 0671/1077] fixed checks for successful opening of std::ofstream git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7661 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 39 ++++++++++++++++++--------------------- PHRQ_io.h | 3 +++ read.cpp | 4 ++-- readtr.cpp | 8 ++++++++ 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 5f08b934..1d0a72cb 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -44,16 +44,25 @@ PHRQ_io:: // ---------------------------------------------------------------------- */ // output ostream methods // ---------------------------------------------------------------------- */ + +bool PHRQ_io:: +ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode) +{ + std::ofstream *ofs = new std::ofstream(file_name, mode); + if (ofs && ofs->is_open()) + { + *os = ofs; + return true; + } + return false; +} + /* ---------------------------------------------------------------------- */ bool PHRQ_io:: output_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - if ((output_ostream = new std::ofstream(file_name, mode)) == NULL) - { - return false; // error - } - return true; + return ofstream_open(&output_ostream, file_name, mode); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -90,11 +99,7 @@ bool PHRQ_io:: log_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - if ((log_ostream = new std::ofstream(file_name, mode)) == NULL) - { - return false; // error - } - return true; + return ofstream_open(&log_ostream, file_name, mode); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -130,11 +135,7 @@ bool PHRQ_io:: punch_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - if ((punch_ostream = new std::ofstream(file_name, mode)) == NULL) - { - return false; // error - } - return true; + return ofstream_open(&punch_ostream, file_name, mode); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: @@ -174,7 +175,7 @@ error_open(const char *file_name, std::ios_base::openmode mode) { if (file_name != NULL) { - if ((error_ostream = new std::ofstream(file_name, mode)) == NULL) + if (!ofstream_open(&error_ostream, file_name, mode)) { error_ostream = &std::cerr; return false; @@ -362,11 +363,7 @@ bool PHRQ_io:: dump_open(const char *file_name, std::ios_base::openmode mode) /* ---------------------------------------------------------------------- */ { - if ((dump_ostream = new std::ofstream(file_name, mode)) == NULL) - { - return false; // error - } - return true; + return ofstream_open(&dump_ostream, file_name, mode); } /* ---------------------------------------------------------------------- */ void PHRQ_io:: diff --git a/PHRQ_io.h b/PHRQ_io.h index 30fa9e21..af47bf42 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -54,6 +54,9 @@ public: void push_istream(std::istream * cookie, bool auto_delete = true); void clear_istream(void); + // helper + bool ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + // output_ostream virtual bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); void output_flush(void); diff --git a/read.cpp b/read.cpp index 3564c7f3..2fe11293 100644 --- a/read.cpp +++ b/read.cpp @@ -4700,7 +4700,7 @@ read_selected_output(void) strcpy(file_name, next_char); have_punch_name = TRUE; punch_close(); - if (punch_open(file_name) != OK) + if (!punch_open(file_name)) { error_string = sformatf( "Can`t open file, %s.", file_name); input_error++; @@ -5036,7 +5036,7 @@ read_selected_output(void) if (!have_punch_name) { punch_close(); - if (punch_open("selected.out") != OK) + if (!punch_open("selected.out")) { error_string = sformatf( "Can`t open file, %s.", "selected.out"); input_error++; diff --git a/readtr.cpp b/readtr.cpp index a6bc54c6..2c34be80 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -969,6 +969,14 @@ dump_cpp(void) phreeqc2cxxStorageBin(phreeqcBin); std::ofstream fs(dump_file_name_cpp.c_str()); + if (!fs.is_open()) + { + error_string = sformatf( "Can`t open file, %s.", dump_file_name_cpp.c_str()); + input_error++; + error_msg(error_string, CONTINUE); + return (OK); + } + fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n"; phreeqcBin.dump_raw(fs, 0); fs << "END" << "\n"; From d71ea17a3e1b315fa778df355c1b12fc01e49084 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Apr 2013 16:41:40 +0000 Subject: [PATCH 0672/1077] Added logic for rate limiter, but not used. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7666 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- KineticsComp.h | 4 + Phreeqc.h | 2 + kinetics.cpp | 219 ++++++++++++++++++++++++++++++++++++++++++++++++- mainsubs.cpp | 1 + 4 files changed, 225 insertions(+), 1 deletion(-) diff --git a/KineticsComp.h b/KineticsComp.h index 704c8d17..8e503a10 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -51,6 +51,9 @@ public: std::vector < LDBLE > &Get_d_params(void) {return d_params;}; const std::vector < LDBLE > &Get_d_params(void)const {return d_params;}; std::vector < std::string > &Get_c_params(void) {return c_params;}; + cxxNameDouble &Get_moles_of_reaction(void) {return moles_of_reaction;} + const cxxNameDouble &Get_moles_of_reaction(void)const {return moles_of_reaction;} + void Set_moles_of_reaction(const cxxNameDouble nd) {moles_of_reaction = nd;} void add(const cxxKineticsComp & comp, LDBLE extensive); void multiply(LDBLE extensive); @@ -67,6 +70,7 @@ public: // kinetics workspace variables LDBLE moles; LDBLE initial_moles; + cxxNameDouble moles_of_reaction; const static std::vector < std::string > vopts; public: diff --git a/Phreeqc.h b/Phreeqc.h index 53f4c684..836b9c3f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -397,6 +397,7 @@ public: int calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr); int calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step); + bool limit_rates(cxxKinetics *kinetics_ptr); int rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, LDBLE step_fraction); int set_reaction(int i, int use_mix, int use_kinetics); @@ -1169,6 +1170,7 @@ protected: * Kinetics * ---------------------------------------------------------------------- */ std::map Rxn_kinetics_map; + bool use_kinetics_limiter; /*---------------------------------------------------------------------- * Save diff --git a/kinetics.cpp b/kinetics.cpp index b30e3f69..cf4673ff 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -135,6 +135,137 @@ int Phreeqc:: calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) /* ---------------------------------------------------------------------- */ { +/* + * Go through kinetic components to + * using extrapolated values, which were + * stored in moles in run_kinetics + */ + LDBLE coef; + struct phase *phase_ptr; + struct master *master_ptr; + int count= 0; +/* + * Go through list and generate list of elements and + * coefficient of elements in reaction + */ +RESTART: // if limiting rates, jump to here + count++; + kinetics_ptr->Get_totals().clear(); + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + count_elts = 0; + paren_count = 0; + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + if (kinetics_comp_ptr->Get_moles() > m_temp[i]) + { + kinetics_comp_ptr->Set_moles(m_temp[i]); + kinetics_comp_ptr->Set_m(0); + } + coef = kinetics_comp_ptr->Get_moles(); + if (coef == 0.0) + continue; +/* + * Reactant is a pure phase, copy formula into token + */ + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin(); + for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++) + { + std::string name = it->first; + LDBLE coef1 = it->second; + phase_ptr = NULL; + int k; + phase_ptr = phase_bsearch(name.c_str(), &k, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, + coef *coef1); + } + else + { + char * temp_name = string_duplicate(name.c_str()); + char * ptr = temp_name; + get_elts_in_species(&ptr, coef * coef1); + free_check_null(temp_name); + } + } + if (use.Get_exchange_ptr() != NULL + && use.Get_exchange_ptr()->Get_related_rate()) + { + cxxExchange * exchange_ptr = use.Get_exchange_ptr(); + for(size_t j = 0; j < exchange_ptr->Get_exchange_comps().size(); j++) + { + std::string name(exchange_ptr->Get_exchange_comps()[j].Get_rate_name()); + if (name.size() > 0) + { + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), + name.c_str()) == 0) + { + /* found kinetics component */ + char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str()); + char * ptr = formula; + get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()); + free_check_null(formula); + } + } + } + + } + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_related_rate()) + { + for (size_t j = 0; j < use.Get_surface_ptr()->Get_surface_comps().size(); j++) + { + cxxSurfaceComp *surface_comp_ptr = &(use.Get_surface_ptr()->Get_surface_comps()[j]); + if (surface_comp_ptr->Get_rate_name().size() > 0) + { + if (strcmp_nocase + (kinetics_comp_ptr->Get_rate_name().c_str(), + surface_comp_ptr->Get_rate_name().c_str()) == 0) + { + /* found kinetics component */ + char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str()); + char *ptr = temp_formula; + /* Surface = 0 when m becomes low ... + */ + if (0.9 * surface_comp_ptr->Get_phase_proportion() * + (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) + { + master_ptr = master_bsearch(ptr); + master_ptr->total = 0.0; + } + else + { + get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()); + } + free_check_null(temp_formula); + } + } + } + } + kinetics_comp_ptr->Set_moles_of_reaction(elt_list_NameDouble()); + kinetics_ptr->Get_totals().add_extensive(kinetics_comp_ptr->Get_moles_of_reaction(), 1.0); + } + if (count > 2) + { + fprintf(stderr, "Too many limit_rates-.\n"); + } + else + { + if (limit_rates(kinetics_ptr)) + goto RESTART; + } + if (count > 2) + { + fprintf(stderr, "Too many limit_rates+.\n"); + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ /* * Go through kinetic components to * using extrapolated values, which were @@ -243,7 +374,7 @@ calc_final_kinetic_reaction(cxxKinetics *kinetics_ptr) kinetics_ptr->Set_totals(elt_list_NameDouble()); return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, @@ -3027,6 +3158,11 @@ f(integertype N, realtype t, N_Vector y, N_Vector ydot, /* Ith(y,i + 1) = m_original[i]; */ + //if (kinetics_ptr->Get_use_cvode()) + //{ + // pThis->cvode_error = TRUE; + // return; + //} kinetics_comp_ptr->Set_moles(pThis->m_original[i]); kinetics_comp_ptr->Set_m(0.0); } @@ -3347,5 +3483,86 @@ cvode_update_reactants(int i, int nsaver, bool save_it) m_temp[j] = kinetics_comp_ptr->Get_m(); } } + return true; +} +/* ---------------------------------------------------------------------- */ +bool Phreeqc:: +limit_rates(cxxKinetics *kinetics_ptr) +/* ---------------------------------------------------------------------- */ +{ +/* + * Go through kinetic components to + * determine rates and + * a list of elements and amounts in + * the reaction. + */ + + // check if any small concentrations with negative rates + if (!use_kinetics_limiter) + { + return false; + } + std::vector negative_rate; + cxxNameDouble::iterator it = kinetics_ptr->Get_totals().begin(); + for ( ; it != kinetics_ptr->Get_totals().end(); it++) + { + if (total(it->first.c_str()) < 1e-10 && it->second < -1e-20) + { + //if (total(it->first.c_str()) > fabs(it->second)) + // continue; + negative_rate.push_back(it->first); + } + } + if (negative_rate.size() == 0) return false; + + for (size_t j = 0; j < negative_rate.size(); j++) + { + std::string elt = negative_rate[j]; + LDBLE positive_rates = 0; + LDBLE negative_rates = 0; + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_moles_of_reaction().find(elt); + if (it != kinetics_comp_ptr->Get_moles_of_reaction().end()) + { + if (it->second >= 0.0) + { + positive_rates += it->second; + } + else + { + negative_rates += it->second; + } + } + } + + // factor to reduce precipitation to equal dissolution + LDBLE limiter_fraction = 1.0; + if (negative_rates < 0.0) + { + limiter_fraction = fabs(positive_rates / negative_rates); + //limiter_fraction = fabs((0.9*total(elt.c_str()) + positive_rates) / negative_rates); + } + else + { + assert(false); + } + + // Now limit precipitation + for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) + { + cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]); + cxxNameDouble::iterator it = kinetics_comp_ptr->Get_moles_of_reaction().find(elt); + if (it != kinetics_comp_ptr->Get_moles_of_reaction().end()) + { + if (it->second < 0.0) + { + kinetics_comp_ptr->Set_moles(kinetics_comp_ptr->Get_moles() * limiter_fraction); + } + } + } + } + return true; } \ No newline at end of file diff --git a/mainsubs.cpp b/mainsubs.cpp index 33509ce5..d8f3cf28 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1018,6 +1018,7 @@ initialize(void) malloc_error(); zeros[0] = 0.0; zeros_max = 1; + use_kinetics_limiter = false; return; } From 47d0c62fc38f64c0adf8cf5254edd76c93c7caf2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 May 2013 16:14:16 +0000 Subject: [PATCH 0673/1077] Added new Basic function kin_time, which is the time interval for the current kinetic integration. kin_delta/kin_time is the average rate over the time interval. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7676 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 13 ++++++++++++- PBasic.h | 3 ++- Phreeqc.cpp | 2 ++ Phreeqc.h | 2 +- kinetics.cpp | 2 ++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index bf8d8f80..a42eb057 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1303,6 +1303,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("KIN_DELTA"); break; + case tokkin_time: + output_msg("KIN_TIME"); + break; + case toks_s: output_msg("S_S"); break; @@ -2221,6 +2225,12 @@ factor(struct LOC_exec * LINK) } break; + case tokkin_time: + { + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rate_kin_time; + } + break; + case tokgas: { const char * str = stringfactor(STR1, LINK); @@ -6464,7 +6474,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("gfw", PBasic::tokgfw), std::map::value_type("soln_vol", PBasic::toksoln_vol), std::map::value_type("equi_delta", PBasic::tokequi_delta), - std::map::value_type("kin_delta", PBasic::tokkin_delta) + std::map::value_type("kin_delta", PBasic::tokkin_delta), + std::map::value_type("kin_time", PBasic::tokkin_time) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 97451760..d989297b 100644 --- a/PBasic.h +++ b/PBasic.h @@ -312,7 +312,8 @@ public: tokgfw, toksoln_vol, tokequi_delta, - tokkin_delta + tokkin_delta, + tokkin_time }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e4b3c3d8..25d9bba7 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1281,6 +1281,7 @@ void Phreeqc::init(void) rate_m = 0; rate_m0 = 0; rate_time = 0; + rate_kin_time = 1.0; rate_sim_time_start = 0; rate_sim_time_end = 0; rate_sim_time = 0; @@ -2406,6 +2407,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) rate_m = 0; rate_m0 = 0; rate_time = 0; + rate_kin_time = 1.0; rate_sim_time_start = 0; rate_sim_time_end = 0; rate_sim_time = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 836b9c3f..b2d53e1a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1504,7 +1504,7 @@ protected: * ---------------------------------------------------------------------- */ struct rate *rates; int count_rates; - LDBLE rate_m, rate_m0, rate_time, rate_sim_time_start, + LDBLE rate_m, rate_m0, rate_time, rate_kin_time, rate_sim_time_start, rate_sim_time_end, rate_sim_time, rate_moles, initial_total_time; std::vector rate_p; int count_rate_p; diff --git a/kinetics.cpp b/kinetics.cpp index cf4673ff..5b0d3e29 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -2017,6 +2017,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) */ run_reactions_iterations = 0; kin_time_x = kin_time; + rate_kin_time = kin_time; nsaver = i; if (state == TRANSPORT || state == PHAST) { @@ -2406,6 +2407,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction) */ run_reactions_iterations = 0; kin_time_x = kin_time; + rate_kin_time = kin_time; nsaver = i; if (state == TRANSPORT || state == PHAST) { From c9c8a7ac658d811df3ced9d8968a23dff5e090ab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 8 May 2013 18:43:42 +0000 Subject: [PATCH 0674/1077] Fixed volume print for -gas in SELECTED_OUTPUT. Added Gas_FixVolume test case. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7702 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/print.cpp b/print.cpp index 67a640d9..4263b0d6 100644 --- a/print.cpp +++ b/print.cpp @@ -2361,6 +2361,7 @@ punch_gas_phase(void) int i; LDBLE p, total_moles, volume; LDBLE moles; + bool PR = false; if (punch.count_gases <= 0) return (OK); @@ -2368,20 +2369,34 @@ punch_gas_phase(void) total_moles = 0.0; volume = 0.0; cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); + if (gas_unknown != NULL && use.Get_gas_phase_ptr() != NULL) { + if (gas_phase_ptr->Get_v_m() >= 0.01) + { + PR = true; + } if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { - gas_phase_ptr->Set_total_moles(gas_unknown->moles); - gas_phase_ptr->Set_volume( - gas_phase_ptr->Get_total_moles() * R_LITER_ATM * tk_x / - gas_phase_ptr->Get_total_p()); + if (gas_unknown->moles >= 1e-12) + { + gas_phase_ptr->Set_total_moles(gas_unknown->moles); + gas_phase_ptr->Set_volume( + gas_phase_ptr->Get_total_moles() * R_LITER_ATM * tk_x / + gas_phase_ptr->Get_total_p()); + if (PR) + { + gas_phase_ptr->Set_volume(gas_phase_ptr->Get_v_m() * gas_unknown->moles); + } + } } p = gas_phase_ptr->Get_total_p(); total_moles = gas_phase_ptr->Get_total_moles(); - volume = total_moles * R_LITER_ATM * tk_x / gas_phase_ptr->Get_total_p(); - if (gas_phase_ptr->Get_v_m() > 0.03) - volume = 0.03 * gas_phase_ptr->Get_total_moles(); + //volume = total_moles * R_LITER_ATM * tk_x / gas_phase_ptr->Get_total_p(); + //if (gas_phase_ptr->Get_v_m() > 0.03) + // volume = 0.03 * gas_phase_ptr->Get_total_moles(); + volume = gas_phase_ptr->Get_volume(); + } if (punch.high_precision == FALSE) { @@ -2425,7 +2440,6 @@ punch_gas_phase(void) } return (OK); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_ss_assemblage(void) From c176fe3b2ef74b6166bf9ee5bdd863c4e83b8569 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 May 2013 20:15:31 +0000 Subject: [PATCH 0675/1077] Cleaning up code. Removed PHREEQC2 ifdef. Some SKIP. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7717 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Form1.h | 82 ------ Phreeqc.cpp | 735 +++----------------------------------------------- Phreeqc.h | 10 +- basicsubs.cpp | 233 +--------------- mainsubs.cpp | 695 ----------------------------------------------- model.cpp | 88 +----- pitzer.cpp | 6 +- prep.cpp | 402 +-------------------------- sit.cpp | 6 +- utilities.cpp | 108 +------- 10 files changed, 51 insertions(+), 2314 deletions(-) diff --git a/Form1.h b/Form1.h index 1831bc96..fde8ff90 100644 --- a/Form1.h +++ b/Form1.h @@ -548,89 +548,7 @@ namespace zdg_ui2 { std::cerr << "ERROR: " << estring << std::endl; } } -#ifdef SKIP - void SaveCurves( System::Object ^sender, System::EventArgs ^e ) - { - std::string file_name = "curves.u_g"; - // Get the graph curves... - std::ofstream f_out(file_name.c_str(), std::ifstream::out); - if (!f_out.is_open()) - { - std::ostringstream estream; - estream << "Could not open csv file for USER_GRAPH " << file_name; - form_error_msg(estream.str()); - return; - } - - // write headings - size_t max_points = 0; - f_out.precision(4); - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - LineItem ^curve; - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - // Get the PointPairList - IPointListEdit ^ip = (IPointListEdit^) curve->Points; - - // Calculate max_points - if ((size_t) ip->Count > max_points) - max_points = ip->Count; - - // write headers - std::string s_std; - ToString(curve->Label->Text, s_std); - f_out.width(12); - f_out << "x" << "\t"; - f_out.width(12); - if (s_std.size() > 0) - { - f_out << s_std << "\t"; - } - else - { - f_out << "y" << "\t"; - } - } - - f_out << std::endl; - - // write data - size_t i2 = 0; - f_out << std::scientific; - f_out.precision(4); - - while (i2 < max_points) - { - for (int i = 0; i < zg1->GraphPane->CurveList->Count; i++) - { - LineItem ^curve; - curve = (LineItem ^) zg1->GraphPane->CurveList[i]; - // Get the PointPairList - IPointListEdit ^ip = (IPointListEdit^) curve->Points; - if (i2 < (size_t) ip->Count) - { - //double x = ip[i]->X; - f_out.width(12); - f_out << ip[i2]->X << "\t"; - f_out.width(12); - f_out << ip[i2]->Y << "\t"; - } - else if (i2 < max_points) - { - f_out.width(13); - f_out << "\t"; - f_out.width(13); - f_out << "\t"; - } - } - f_out << std::endl; - i2++; - } - f_out.close(); - return; - } -#endif void SaveCurves( System::Object ^sender, System::EventArgs ^e ) { SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 25d9bba7..36fbc627 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -29,98 +29,7 @@ const struct const_iso Phreeqc::iso_defaults[] = { }; const int Phreeqc::count_iso_defaults = (sizeof(iso_defaults) / sizeof(struct const_iso)); -#ifdef SKIP -Phreeqc::Phreeqc(PHRQ_io *io) -{ - if (io) - { - phrq_io = io; - } - else - { - phrq_io = &this->ioInstance; - } - phast = FALSE; - s_pTail = NULL; - user_database = NULL; - rates = NULL; - tally_table = NULL; - spec = NULL; - cations = NULL; - anions = NULL; - neutrals = NULL; - IPRSNT = NULL; - M = NULL; - LGAMMA = NULL; - sit_params = NULL; - sit_LGAMMA = NULL; - sit_IPRSNT = NULL; - sit_M = NULL; - - // counters for enum KEYWORDS - for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) - { - keycount.push_back(0); - } - - // basic.c - basic_interpreter = NULL; - - //cl1.c - x_arg = NULL, res_arg = NULL, scratch = NULL; - x_arg_max = 0, res_arg_max = 0, scratch_max = 0; - - // dw.c - GASCON = 0.461522e0; - TZ = 647.073e0; - AA = 1.e0; - G1 = 11.e0; - G2 = 44.333333333333e0; - GF = 3.5e0; - - // model.c - min_value = 1e-10; - normal = NULL; - ineq_array = NULL; - res = NULL; - cu = NULL; - zero = NULL; - delta1 = NULL; - iu = NULL; - is = NULL; - back_eq = NULL; - normal_max = 0; - ineq_array_max = 0; - res_max = 0; - cu_max = 0; - zero_max = 0; - delta1_max = 0; - iu_max = 0; - is_max = 0; - back_eq_max = 0; - - // output.c - forward_output_to_log = 0; - - // phqalloc.c - - // print.c - sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); - if (sformatf_buffer == NULL) - malloc_error(); - sformatf_buffer_size = 256; - - // transport.c - J_ij = NULL; - J_ij_il = NULL; - m_s = NULL; - - default_data_base = string_duplicate("phreeqc.dat"); - - init(); -} -#endif Phreeqc::~Phreeqc(void) { @@ -259,570 +168,7 @@ size_t Phreeqc::list_components(std::list &list_c) } return(list_c.size()); } -#ifdef SKIP -void Phreeqc::init(void) -{ - int i; - moles_per_kilogram_string = 0; - pe_string = 0; - - debug_model = FALSE; - debug_prep = FALSE; - debug_set = FALSE; - debug_diffuse_layer = FALSE; - debug_inverse = FALSE; - itmax = 100; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#else - ineq_tol = pow((double) 10, (double) -DBL_DIG); -#endif - convergence_tolerance = 1e-8; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -#else - inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -#endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; - negative_concentrations = FALSE; - - LOG_10 = log(10.0); - - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; - - count_elements = 0; - count_master = 0; - count_phases = 0; - count_s = 0; - count_logk = 0; - count_master_isotope = 0; -/* - * Initialize advection - */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - - advection_punch = 0; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = 0; - advection_warnings = TRUE; -/* - * Initialize transport - */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; -/* !!!! count_stag = 0; */ - mcd_substeps = 1.0; - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; - - cell_data = 0; - elements = 0; - elt_list = 0; - - inverse = 0; - count_inverse = 0; - line = 0; - line_save = 0; - - master = 0; - - mb_unknowns = 0; -/* !!!! */ - stag_data = 0; - phases = 0; - trxn.token = 0; - s = 0; - logk = 0; - master_isotope = 0; - - title_x = NULL; - //pe_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; - - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; - - //isotopes_x = 0; - - x = NULL; - max_unknowns = 0; - - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; - - logk_hash_table = 0; - master_isotope_hash_table = 0; - elements_hash_table = 0; - species_hash_table = 0; - phases_hash_table = 0; -/* - * Initialize punch - */ - punch.in = FALSE; - punch.count_totals = 0; - punch.totals = 0; - punch.count_molalities = 0; - - punch.molalities = 0; - punch.count_activities = 0; - - punch.activities = 0; - punch.count_pure_phases = 0; - - punch.pure_phases = 0; - punch.count_si = 0; - - punch.si = 0; - punch.count_gases = 0; - - punch.gases = 0; - punch.count_s_s = 0; - punch.s_s = 0; - - punch.count_kinetics = 0; - punch.kinetics = 0; - - punch.count_isotopes = 0; - punch.isotopes = 0; - - punch.count_calculate_values = 0; - punch.calculate_values = 0; - - count_save_values = 0; - save_values = 0; - - - punch.inverse = TRUE; - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -/* - * last model - */ - last_model.exchange = NULL; - last_model.gas_phase = NULL; - last_model.ss_assemblage = NULL; - last_model.kinetics = NULL; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.surface_comp = NULL; - last_model.surface_charge = NULL; -/* - * rates - */ - rates = 0; - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; - -/* - * user_print, user_punch - */ - user_print = 0; - user_punch = 0; - user_punch_headings = 0; - user_punch_count_headings = 0; - n_user_punch_index = 0; - fpunchf_user_s_warning = 0; - - spread_length = 10; - /* - Initialize llnl aqueous model parameters - */ - llnl_temp = 0; - llnl_count_temp = 0; - - llnl_adh = 0; - llnl_count_adh = 0; - - llnl_bdh = 0; - llnl_count_bdh = 0; - - llnl_bdot = 0; - llnl_count_bdot = 0; - - llnl_co2_coefs = 0; - llnl_count_co2_coefs = 0; - - - change_surf = 0; - change_surf_count = 0; - - /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.ss_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; - if (phast == TRUE) - { - pr.status = FALSE; - } - else - { - pr.status = TRUE; - } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - species_list = NULL; - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; - selected_output_file_name = NULL; - dump_file_name = NULL; - - /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - - calculate_value = 0; - calculate_value_hash_table = 0; - - /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - isotope_ratio = 0; - isotope_ratio_hash_table = 0; - - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - isotope_alpha = 0; - isotope_alpha_hash_table = 0; - - phreeqc_mpi_myself = 0; - - copy_solution.n_user = copy_solution.start = copy_solution.end = 0; - copy_pp_assemblage.n_user = copy_pp_assemblage.start = copy_pp_assemblage.end = 0; - copy_exchange.n_user = copy_exchange.start = copy_exchange.end = 0; - copy_surface.n_user = copy_surface.start = copy_surface.end = 0; - copy_ss_assemblage.n_user = copy_ss_assemblage.start = copy_ss_assemblage.end = 0; - copy_gas_phase.n_user = copy_gas_phase.start = copy_gas_phase.end = 0; - copy_kinetics.n_user = copy_kinetics.start = copy_kinetics.end = 0; - copy_mix.n_user = copy_mix.start = copy_mix.end = 0; - copy_reaction.n_user = copy_reaction.start = copy_reaction.end = 0; - copy_temperature.n_user = copy_temperature.start = copy_temperature.end = 0; - copy_pressure.n_user = copy_pressure.start = copy_pressure.end = 0; - - set_forward_output_to_log(FALSE); - simulation = 0; - /* - * cvode - */ - - cvode_init(); - /* - * Pitzer - */ - pitzer_model = FALSE; - max_pitz_param = 100; - count_pitz_param = 0; - use_etheta = TRUE; - pitz_params = 0; - - max_theta_param = 100; - count_theta_param = 0; - theta_params = 0; - - ICON = TRUE; - OTEMP = 0.0; - for (i = 0; i < 23; i++) - { - BK[i] = 0.0; - DK[i] = 0.0; - } - pitzer_pe = FALSE; - - count_pp = count_pg = count_ss = 0; // used in store_get_equi_reactants - x0_moles = NULL; - /* - * SIT - */ - sit_model = FALSE; - max_sit_param = 100; - count_sit_param = 0; - sit_params = 0; - - /* - * to facilitate debuging - */ - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; - - zeros = 0; - zeros_max = 1; - - cell_pore_volume = 0; - cell_volume = 0; - cell_porosity = 0; - cell_saturation = 0; - - print_density = 0; - - /* basic.c */ - - /* dw.c */ - Q0 = 0; - Q5 = 0; - Z = 0; - DZ = 0; - Y = 0; - B1 = 0; - B2 = 0; - B1T = 0; - B2T = 0; - B1TT = 0; - B2TT = 0; - - /* input.c */ - reading_db = FALSE; - - /* integrate.c */ - z_global = 0; - xd_global = 0; - alpha_global = 0; - - /* inverse.c */ - max_row_count = 50; - max_column_count = 50; - carbon = FALSE; - col_name = NULL; - row_name = NULL; - count_rows = 0; - count_optimize = 0; - col_phases = 0; - col_redox = 0; - col_epsilon = 0; - col_ph = 0; - col_water = 0; - col_isotopes = 0; - col_phase_isotopes = 0; - row_mb = 0; - row_fract = 0; - row_charge = 0; - row_carbon = 0; - row_isotopes = 0; - row_epsilon = 0; - row_isotope_epsilon = 0; - row_water = 0; - inv_zero = NULL; - array1 = 0; - inv_delta1 = NULL; - delta2 = NULL; - delta3 = NULL; - inv_cu = NULL; - delta_save = NULL; - min_delta = NULL; - max_delta = NULL; - klmd = 0; - nklmd = 0; - n2d = 0; - kode = 0; - iter = 0; - toler = 0; - error = 0; - max_pct = 0; - scaled_error = 0; - master_alk = NULL; - row_back = NULL; - col_back = NULL; - good = NULL; - bad = NULL; - minimal = NULL; - max_good = 0; - max_bad = 0; - max_minimal = 0; - count_good = 0; - count_bad = 0; - count_minimal = 0; - count_calls = 0; - soln_bits = 0; - phase_bits = 0; - current_bits = 0; - temp_bits = 0; - netpath_file = NULL; - count_inverse_models = 0; - count_pat_solutions = 0; - inv_res = NULL; - inv_iu = NULL; - inv_is = NULL; - /* kinetics.c */ - m_original = NULL; - m_temp = NULL; - rk_moles = NULL; - - /* pitzer.c */ - A0 = 0; - count_cations = 0; - count_anions = 0; - count_neutrals = 0; - MAXCATIONS = 0; - FIRSTANION = 0; - MAXNEUTRAL = 0; - mcb0 = NULL; - mcb1 = NULL; - mcc0 = NULL; - /* read.c */ - dummy = 0; - prev_next_char = NULL; - /* sit.c */ - sit_A0 = 0; - sit_count_cations = 0; - sit_count_anions = 0; - sit_count_neutrals = 0; - sit_MAXCATIONS = 0; - sit_FIRSTANION = 0; - sit_MAXNEUTRAL = 0; - /* tidy.c */ - a0 = 0; - a1 = 0; - kc = 0; - kb = 0; - /* tally.c */ - t_buffer = NULL; - tally_count_component = 0; - count_tally_table_columns = 0; - count_tally_table_rows = 0; - /* transport.c */ - sol_D = NULL; - sol_D_dbg = NULL; - J_ij_count_spec = 0; - count_m_s = 0; - tot1_h = 0; - tot1_o = 0; - tot2_h = 0; - tot2_o = 0; - diffc_max = 0; - diffc_tr = 0; - J_ij_sum = 0; - transp_surf = FALSE; - heat_mix_array = NULL; - temp1 = NULL; - temp2 = NULL; - nmix = 0; - heat_nmix = 0; - heat_mix_f_imm = 0; - heat_mix_f_m = 0; - warn_MCD_X = 0; - warn_fixed_Surf = 0; - /* model.c */ - gas_in = FALSE; - - /* utilities.c */ - spinner = 0; - - count_strings = 0; -#ifdef MULTICHART - chart_handler.Set_io(phrq_io); -#endif - run_info.Set_io(phrq_io); - - phrq_io->clear_istream(); - - return; -} -#endif Phreeqc::Phreeqc(PHRQ_io *io) { // phrq_io @@ -1207,7 +553,6 @@ void Phreeqc::init(void) solution_phase_boundary_unknown = NULL; surface_unknown = NULL; gas_unknown = NULL; - slack_unknown = NULL; ss_unknown = NULL; // auto gas_unknowns; /*---------------------------------------------------------------------- @@ -1366,7 +711,6 @@ void Phreeqc::init(void) mass_water_switch = FALSE; delay_mass_water = FALSE; dampen_ah2o = false; - slack = false; censor = 0.0; aqueous_only = 0; negative_concentrations = FALSE; @@ -1438,14 +782,7 @@ void Phreeqc::init(void) count_sys = 0; max_sys = 0; sys_tot = 0; -#ifdef PHREEQC2 - AA_basic = 0; - BB_basic = 0; - CC = 0; - I_m = 0; - rho_0 = 0; - eps_r = EPSILON; -#else + V_solutes = 0.0; rho_0 = 0; kappa_0 = 0.0; @@ -1457,7 +794,7 @@ void Phreeqc::init(void) QBrn = 0.0; ZBrn = 0.0; dgdP = 0.0; -#endif + need_temp_msg = 0; solution_mass = 0; solution_volume = 0; @@ -2329,7 +1666,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) solution_phase_boundary_unknown = NULL; surface_unknown = NULL; gas_unknown = NULL; - slack_unknown = NULL; ss_unknown = NULL; */ // auto gas_unknowns; @@ -2542,7 +1878,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) mass_water_switch = pSrc->mass_water_switch; delay_mass_water = pSrc->delay_mass_water; dampen_ah2o = pSrc->dampen_ah2o; - slack = pSrc->slack; censor = pSrc->censor; aqueous_only = pSrc->aqueous_only; negative_concentrations = pSrc->negative_concentrations; @@ -2725,14 +2060,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) max_sys = 0; sys_tot = 0; -#ifdef PHREEQC2 - AA_basic = 0; - BB_basic = 0; - CC = 0; - I_m = 0; - rho_0 = 0; - eps_r = EPSILON; -#else V_solutes = 0.0; rho_0 = 0; kappa_0 = 0.0; @@ -2744,7 +2071,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) QBrn = 0.0; ZBrn = 0.0; dgdP = 0.0; -#endif + need_temp_msg = 0; solution_mass = 0; solution_volume = 0; @@ -2921,16 +2248,16 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) pitzer_model = pSrc->pitzer_model; sit_model = pSrc->sit_model; pitzer_pe = pSrc->pitzer_pe; -#ifdef SKIP - full_pitzer = FALSE; - always_full_pitzer = FALSE; - ICON = TRUE; - IC = -1; - COSMOT = 0; - AW = 0; - VP = 0; - DW0 = 0; -#endif + + //full_pitzer = FALSE; + //always_full_pitzer = FALSE; + //ICON = TRUE; + //IC = -1; + //COSMOT = 0; + //AW = 0; + //VP = 0; + //DW0 = 0; + ICON = pSrc->ICON; /* pitz_params = NULL; @@ -3033,19 +2360,18 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) { sit_param_store(pSrc->sit_params[i], true); } -#ifdef SKIP /* tidy.cpp ------------------------------- */ - a0 = 0; - a1 = 0; - kc = 0; - kb = 0; + //a0 = 0; + //a1 = 0; + //kc = 0; + //kb = 0; /* tally.cpp ------------------------------- */ - t_buffer = NULL; - tally_count_component = 0; - tally_table = NULL; - count_tally_table_columns = 0; - count_tally_table_rows = 0; -#endif + //t_buffer = NULL; + //tally_count_component = 0; + //tally_table = NULL; + //count_tally_table_columns = 0; + //count_tally_table_rows = 0; + /* transport.cpp ------------------------------- */ /* storage is created and freed in tranport.cpp */ sol_D = NULL; @@ -3080,15 +2406,14 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) int stop_calculations; char err_str98[80]; #endif -#ifdef SKIP /* utilities.cpp ------------------------------- */ - spinner = 0; - // keycount; - for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) - { - keycount.push_back(0); - } -#endif + //spinner = 0; + //// keycount; + //for (int i = 0; i < Keywords::KEY_COUNT_KEYWORDS; i++) + //{ + // keycount.push_back(0); + //} + // make sure new_model gets set this->keycount[Keywords::KEY_SOLUTION_SPECIES] = 1; this->tidy_model(); diff --git a/Phreeqc.h b/Phreeqc.h index b2d53e1a..c75ffd5f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -576,7 +576,6 @@ public: int setup_exchange(void); int setup_gas_phase(void); int setup_fixed_volume_gas(void); - int setup_slack(void); int setup_master_rxn(struct master **master_ptr_list, const std::string &pe_rxn); int setup_pure_phases(void); @@ -1473,7 +1472,6 @@ protected: struct unknown *solution_phase_boundary_unknown; struct unknown *surface_unknown; struct unknown *gas_unknown; - struct unknown *slack_unknown; struct unknown *ss_unknown; std::vector gas_unknowns; @@ -1596,7 +1594,6 @@ protected: int mass_water_switch; int delay_mass_water; bool dampen_ah2o; - bool slack; LDBLE censor; int aqueous_only; int negative_concentrations; @@ -1676,17 +1673,14 @@ protected: struct system_species *sys; int count_sys, max_sys; LDBLE sys_tot; -#ifdef PHREEQC2 - LDBLE AA_basic, BB_basic, CC, I_m, rho_0; - LDBLE eps_r; // relative dielectric permittivity -#else + LDBLE V_solutes, rho_0, kappa_0, p_sat/*, ah2o_x0*/; LDBLE eps_r; // relative dielectric permittivity LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume LDBLE ZBrn; // Born function (-1/eps_r + 1) * 41.84004, for supcrt calc'n of molal volume LDBLE dgdP; // dg / dP, pressure derivative of g-function, for supcrt calc'n of molal volume -#endif + int need_temp_msg; LDBLE solution_mass, solution_volume; diff --git a/basicsubs.cpp b/basicsubs.cpp index 926e0902..11ea5871 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -155,135 +155,7 @@ calc_SC(void) return (SC); } -#ifdef PHREEQC2 -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -calc_dens(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculates density based on the formulas and parameters from Millero, - * 2000. - * - * Millero, F.J. (2000) The equation of state of lakes. Aquatic geochemistry - * volume 6, pages 1-17 - */ - int i; - /* - LDBLE rho_0; - LDBLE solution_mass, solution_volume; - */ - LDBLE rho_new, rho_old; - LDBLE M_T; - LDBLE a, b, c, d, e, f; - LDBLE phi_0_i, b_v_i, s_v_i, PHI_v, B_v, S_v; - /* - LDBLE k, I_m, I_v; - LDBLE AA_basic, BB, CC; - */ - LDBLE gfw; - int l_z; - struct species *s_ptr; - /* Density of pure water (UNESCO, 1983) */ - //rho_0 = 999.842594 + (6.793952e-2 + (-9.095290e-3 + (1.001685e-4 + (-1.120083e-6 + 6.536332e-9 * tc_x) * tc_x) * tc_x) * tc_x) * tc_x; - //rho_0 = calc_rho_0(tc_x, patm_x); // done in k_temp - //rho_0 /= 1000; - s_v_i = 1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc_x) * tc_x) * tc_x; - rho_new = rho_0; - rho_old = 0.0; - - M_T = 0.0; - I_m = 0.0; - PHI_v = 0.0; - B_v = 0.0; - S_v = 0.0; - for (i = 0; i < count_species_list; i++) - { - if (species_list[i].s->type != AQ) - continue; - if (strcmp(species_list[i].s->name, "CO2") == 0) - continue; - - if (species_list[i].master_s->secondary != NULL) - gfw = species_list[i].master_s->secondary->gfw; - else - gfw = species_list[i].master_s->primary->gfw; - - if (species_list[i].s->millero[0] == 0) - s_ptr = species_list[i].master_s; - else - s_ptr = species_list[i].s; - - /* Special case: CO3-2 species */ - if (strcmp(s_ptr->name, "CO3-2") == 0) - { - if (strstr(species_list[i].s->name, "HCO3") != NULL) - { - s_ptr = s_search("HCO3-"); - } else if (strstr(species_list[i].s->name, "CO3") != NULL) - { - compute_gfw("CO3-2", &gfw); - } - } - - l_z = abs((int) s_ptr->z); - a = s_ptr->millero[0]; - b = s_ptr->millero[1]; - c = s_ptr->millero[2]; - d = s_ptr->millero[3]; - e = s_ptr->millero[4]; - f = s_ptr->millero[5]; - phi_0_i = a + (b + c * tc_x) * tc_x; - b_v_i = d + (e + f * tc_x) * tc_x; - - PHI_v += (species_list[i].s->moles * phi_0_i); - B_v += (species_list[i].s->moles * b_v_i); - S_v += (species_list[i].s->moles * l_z * (s_v_i * l_z / 2)); - M_T += (species_list[i].s->moles * gfw); - I_m += (species_list[i].s->moles * (l_z * l_z)); - } - - /* If pure water then return rho_0 */ - if (PHI_v == 0) - return rho_0; - - solution_mass = mass_water_aq_x * 1000 + M_T; - I_m /= 2; - AA_basic = M_T - rho_0 * PHI_v; - BB_basic = -rho_0 * S_v; - CC = -rho_0 * B_v; - rho_new = halve(f_rho, 0.5, 2.0, 1e-7); -/* DP: End Replace Pickard iteration with interval halving */ - - /*if (isnan(rho_new) || rho_new > 1.99999) rho_new = 1.99999;*/ - if (!PHR_ISFINITE(rho_new) || rho_new > 1.99999) rho_new = 1.99999; - - return rho_new; /*(rho_new - rho_0) * 1e3; */ -} -/* VP: Density End */ -/* DP: Function for interval halving */ - -LDBLE Phreeqc:: -f_rho(LDBLE rho_old, void *cookie) -/* ---------------------------------------------------------------------- */ -{ - LDBLE rho, I_v; - Phreeqc * pThis; - - pThis = (Phreeqc *) cookie; - - pThis->solution_volume = pThis->solution_mass / rho_old / 1000; - rho = 1e3; - if (pThis->solution_volume != 0) - { - I_v = pThis->I_m / pThis->solution_volume; // Ionic Strength in mol/L - rho = (pThis->AA_basic + pThis->BB_basic * sqrt(I_v) + pThis->CC * I_v) / pThis->solution_volume; - } - rho = rho / 1000 + pThis->rho_0; - return (rho - rho_old); -} -#else /* VP: Density Start */ /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -396,7 +268,7 @@ f_rho(LDBLE rho_old, void *cookie) rho = rho + pThis->rho_0; return (rho - rho_old); } -#endif + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_solution_volume(void) @@ -1471,45 +1343,7 @@ sum_match_gases(const char *mytemplate, const char *name) } return (tot); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -sum_match_species(const char *mytemplate, const char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE tot; - struct elt_list *next_elt; - count_elts = 0; - paren_count = 0; - tot = 0; - for (i = 0; i < count_s_x; i++) - { - if (match_elts_in_species(s_x[i]->name, mytemplate) == TRUE) - { - if (name == NULL) - { - tot += s_x[i]->moles; - } - else - { - for (next_elt = s_x[i]->next_elt; next_elt->elt != NULL; - next_elt++) - { - if (strcmp(next_elt->elt->name, name) == 0) - { - tot += next_elt->coef * s_x[i]->moles; - break; - } - } - } - } - } - return (tot); -} -#else -#ifndef SUM_SPECIES_METHOD_2 /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sum_match_species(const char *mytemplate, const char *name) @@ -1559,73 +1393,8 @@ sum_match_species(const char *mytemplate, const char *name) } return (tot); } -#else -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -sum_match_species(const char *mytemplate, const char *name) -/* ---------------------------------------------------------------------- */ -{ - int i; - LDBLE tot; - struct elt_list *next_elt; - count_elts = 0; - paren_count = 0; - tot = 0; - if (sum_species_map.find(mytemplate) == sum_species_map.end()) - { - if (sum_species_map_db.find(mytemplate) == sum_species_map_db.end()) - { - std::vector species_list_db; - for (i = 0; i < count_s; i++) - { - struct species *s_ptr = s[i]; - if (match_elts_in_species(s_ptr->name, mytemplate) == TRUE) - { - species_list_db.push_back(s_ptr->name); - } - } - sum_species_map_db[mytemplate] = species_list_db; - } - std::vector &species_list = (sum_species_map_db.find(mytemplate))->second; - std::vector species_list_x; - for (size_t i=0; i < species_list.size(); i++) - { - struct species *s_ptr = s_search(species_list[i].c_str()); - if (s_ptr->in == TRUE) - { - species_list_x.push_back(species_list[i]); - } - } - sum_species_map[mytemplate] = species_list_x; - } - std::vector &species_list = (sum_species_map.find(mytemplate))->second; - for (size_t i=0; i < species_list.size(); i++) - { - struct species *s_ptr = s_search(species_list[i].c_str()); - if (s_ptr->in == FALSE) continue; - if (name == NULL) - { - tot += s_ptr->moles; - } - else - { - for (next_elt = s_ptr->next_elt; next_elt->elt != NULL; - next_elt++) - { - if (strcmp(next_elt->elt->name, name) == 0) - { - tot += next_elt->coef * s_ptr->moles; - break; - } - } - } - } - return (tot); -} -#endif -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: diff --git a/mainsubs.cpp b/mainsubs.cpp index d8f3cf28..1e8345cb 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -16,702 +16,7 @@ #if defined(WINDOWS) || defined(_WINDOWS) #include #endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -void Phreeqc:: -initialize(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Initialize global variables - */ - int i; - struct logk *logk_ptr; - char token[MAX_LENGTH]; - moles_per_kilogram_string = string_duplicate("Mol/kgw"); - pe_string = string_duplicate("pe"); - - debug_model = FALSE; - debug_prep = FALSE; - debug_set = FALSE; - debug_diffuse_layer = FALSE; - debug_inverse = FALSE; - itmax = 100; - max_tries = 1000; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#else - ineq_tol = pow((double) 10, (double) -DBL_DIG); -#endif - convergence_tolerance = 1e-8; -#ifdef USE_LONG_DOUBLE - /* from float.h, sets tolerance for cl1 routine */ - inv_tol_default = pow((long double) 10, (long double) -LDBL_DIG + 5); -#else - inv_tol_default = pow((double) 10, (double) -DBL_DIG + 5); -#endif - step_size = 100.; - pe_step_size = 10.; - pp_scale = 1.0; - pp_column_scale = 1.0; - diagonal_scale = FALSE; - censor = 0.0; - mass_water_switch = FALSE; - /* mass_water_switch = TRUE; */ - delay_mass_water = FALSE; - incremental_reactions = FALSE; - aqueous_only = 0; - negative_concentrations = FALSE; - - LOG_10 = log(10.0); - /* Use space for all memory allocation */ - max_elements = MAX_ELEMENTS; - max_elts = MAX_ELTS; - max_line = MAX_LINE; - max_master = MAX_MASTER; - max_mb_unknowns = MAX_TRXN; - max_phases = MAX_PHASES; - max_s = MAX_S; - max_trxn = MAX_TRXN; - max_logk = MAX_S; - max_master_isotope = MAX_ELTS; - count_elements = 0; - count_master = 0; - count_phases = 0; - count_s = 0; - count_logk = 0; - count_master_isotope = 0; -/* - * Initialize advection - */ - count_ad_cells = 1; - count_ad_shifts = 1; - print_ad_modulus = 1; - punch_ad_modulus = 1; - advection_punch = (int *) PHRQ_malloc(sizeof(int)); - if (advection_punch == NULL) - malloc_error(); - advection_punch[0] = TRUE; - advection_kin_time = 0.0; - advection_kin_time_defined = FALSE; - advection_print = (int *) PHRQ_malloc(sizeof(int)); - if (advection_print == NULL) - malloc_error(); - advection_print[0] = TRUE; - advection_warnings = TRUE; -/* - * Initialize transport - */ - count_cells = 1; - count_shifts = 1; - ishift = 1; - bcon_first = bcon_last = 3; - diffc = 0.3e-9; - simul_tr = 0; - tempr = 2.0; - heat_diffc = -0.1; - timest = 0.0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - interlayer_tortf = 100.0; - interlayer_Dpor = 0.1; -/* !!!! count_stag = 0; */ - mcd_substeps = 1.0; - print_modulus = 1; - punch_modulus = 1; - dump_modulus = 0; - dump_in = FALSE; - transport_warnings = TRUE; -/* - * Allocate space - */ - - space((void **) ((void *) &cell_data), INIT, &count_cells, - sizeof(struct cell_data)); - - space((void **) ((void *) &elements), INIT, &max_elements, - sizeof(struct element *)); - - space((void **) ((void *) &elt_list), INIT, &max_elts, - sizeof(struct elt_list)); - - inverse = (struct inverse *) PHRQ_malloc((size_t) sizeof(struct inverse)); - if (inverse == NULL) - malloc_error(); - count_inverse = 0; - space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); - - space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); - - space((void **) ((void *) &master), INIT, &max_master, - sizeof(struct master *)); - - space((void **) ((void *) &mb_unknowns), INIT, &max_mb_unknowns, - sizeof(struct unknown_list)); - -/* !!!! */ - stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data)); - if (stag_data == NULL) - malloc_error(); - stag_data->count_stag = 0; - stag_data->exch_f = 0; - stag_data->th_m = 0; - stag_data->th_im = 0; - - space((void **) ((void *) &phases), INIT, &max_phases, - sizeof(struct phase *)); - - space((void **) ((void *) &trxn.token), INIT, &max_trxn, - sizeof(struct rxn_token_temp)); - - space((void **) ((void *) &s), INIT, &max_s, sizeof(struct species *)); - - space((void **) ((void *) &logk), INIT, &max_logk, sizeof(struct logk *)); - - space((void **) ((void *) &master_isotope), INIT, &max_master_isotope, - sizeof(struct master_isotope *)); - title_x = NULL; - description_x = NULL; - units_x = NULL; - s_x = NULL; -/* SRC ADDED */ - sum_mb1 = NULL; - sum_mb2 = NULL; - sum_jacob0 = NULL; - sum_jacob1 = NULL; - sum_jacob2 = NULL; - sum_delta = NULL; -/* SRC ADDED */ - x = NULL; - max_unknowns = 0; - - array = NULL; - delta = NULL; - residual = NULL; - s_h2o = NULL; - s_hplus = NULL; - s_h3oplus = NULL; - s_eminus = NULL; - s_co3 = NULL; - s_h2 = NULL; - s_o2 = NULL; - - hcreate_multi((unsigned) max_logk, &logk_hash_table); - hcreate_multi((unsigned) max_master_isotope, &master_isotope_hash_table); -/* - * Create hash tables - */ - hcreate_multi((unsigned) max_elements, &elements_hash_table); - hcreate_multi((unsigned) max_s, &species_hash_table); - hcreate_multi((unsigned) max_phases, &phases_hash_table); -/* - * Initialize punch - */ - punch.in = FALSE; - punch.new_def = FALSE; - punch.count_totals = 0; - punch.totals = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.totals == NULL) - malloc_error(); - punch.count_molalities = 0; - punch.molalities = - (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.molalities == NULL) - malloc_error(); - punch.count_activities = 0; - punch.activities = - (struct name_species *) PHRQ_malloc(sizeof(struct name_species)); - if (punch.activities == NULL) - malloc_error(); - punch.count_pure_phases = 0; - punch.pure_phases = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.pure_phases == NULL) - malloc_error(); - punch.count_si = 0; - punch.si = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.si == NULL) - malloc_error(); - punch.count_gases = 0; - punch.gases = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.gases == NULL) - malloc_error(); - punch.count_s_s = 0; - punch.s_s = (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.s_s == NULL) - malloc_error(); - - punch.count_kinetics = 0; - punch.kinetics = - (struct name_phase *) PHRQ_malloc(sizeof(struct name_phase)); - if (punch.kinetics == NULL) - malloc_error(); - - punch.count_isotopes = 0; - punch.isotopes = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.isotopes == NULL) - malloc_error(); - - punch.count_calculate_values = 0; - punch.calculate_values = - (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); - if (punch.calculate_values == NULL) - malloc_error(); - - count_save_values = 0; - save_values = - (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); - if (save_values == NULL) - malloc_error(); - - punch.inverse = TRUE; - - punch.sim = TRUE; - punch.state = TRUE; - punch.soln = TRUE; - punch.dist = TRUE; - punch.time = TRUE; - punch.step = TRUE; - punch.rxn = FALSE; - punch.temp = FALSE; - punch.ph = TRUE; - punch.pe = TRUE; - punch.alk = FALSE; - punch.mu = FALSE; - punch.water = FALSE; - punch.high_precision = FALSE; - punch.user_punch = TRUE; - punch.charge_balance = FALSE; - punch.percent_error = FALSE; -/* - * last model - */ - last_model.force_prep = TRUE; - last_model.temperature = -100; - last_model.pressure = 0; - last_model.count_exchange = -1; - last_model.exchange = NULL; - last_model.count_kinetics = -1; - last_model.kinetics = NULL; - last_model.count_gas_phase = -1; - last_model.gas_phase = NULL; - last_model.count_ss_assemblage = -1; - last_model.ss_assemblage = NULL; - last_model.count_pp_assemblage = -1; - last_model.pp_assemblage = NULL; - last_model.add_formula = NULL; - last_model.si = NULL; - last_model.dl_type = cxxSurface::NO_DL; - last_model.surface_type = cxxSurface::UNKNOWN_DL; - last_model.only_counter_ions = FALSE; - last_model.thickness = 1e-8; - last_model.count_surface_comp = -1; - last_model.surface_comp = NULL; - last_model.count_surface_charge = -1; - last_model.surface_charge = NULL; -/* - * rates - */ - rates = (struct rate *) PHRQ_malloc(sizeof(struct rate)); - if (rates == NULL) - malloc_error(); - count_rates = 0; - initial_total_time = 0; - rate_m = 0; - rate_m0 = 0; - rate_time = 0; - rate_sim_time_start = 0; - rate_sim_time_end = 0; - rate_sim_time = 0; - rate_moles = 0; -/* - * user_print, user_punch - */ - user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); - if (user_print == NULL) - malloc_error(); - user_print->commands = NULL; - user_print->linebase = NULL; - user_print->varbase = NULL; - user_print->loopbase = NULL; - user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); - if (user_punch == NULL) - malloc_error(); - user_punch->commands = NULL; - user_punch->linebase = NULL; - user_punch->varbase = NULL; - user_punch->loopbase = NULL; - user_punch_headings = (const char **) PHRQ_malloc(sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); - user_punch_count_headings = 0; -#if defined PHREEQ98 -/* - * user_graph - */ - user_graph = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); - if (user_graph == NULL) - malloc_error(); - user_graph->commands = NULL; - user_graph->linebase = NULL; - user_graph->varbase = NULL; - user_graph->loopbase = NULL; - user_graph_headings = (char **) PHRQ_malloc(sizeof(char *)); - if (user_graph_headings == NULL) - malloc_error(); - user_graph_count_headings = 0; -#endif - /* - Initialize llnl aqueous model parameters - */ - llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_temp == NULL) - malloc_error(); - llnl_count_temp = 0; - llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_adh == NULL) - malloc_error(); - llnl_count_adh = 0; - llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_bdh == NULL) - malloc_error(); - llnl_count_bdh = 0; - llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_bdot == NULL) - malloc_error(); - llnl_count_bdot = 0; - llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (llnl_co2_coefs == NULL) - malloc_error(); - llnl_count_co2_coefs = 0; -/* - * - */ - basic_interpreter = new PBasic(this, phrq_io); - - change_surf = - (struct Change_Surf *) - PHRQ_malloc((size_t) (2 * sizeof(struct Change_Surf))); - if (change_surf == NULL) - malloc_error(); - change_surf[0].cell_no = -99; - change_surf[0].next = TRUE; - change_surf[1].cell_no = -99; - change_surf[1].next = FALSE; - change_surf_count = 0; - - -#if defined(WINDOWS) || defined(_WINDOWS) - /* SRC pr.status = FALSE; */ -#endif - /* Initialize print here, not in global.h */ - pr.all = TRUE; - pr.initial_solutions = TRUE; - pr.initial_exchangers = TRUE; - pr.reactions = TRUE; - pr.gas_phase = TRUE; - pr.ss_assemblage = TRUE; - pr.pp_assemblage = TRUE; - pr.surface = TRUE; - pr.exchange = TRUE; - pr.kinetics = TRUE; - pr.totals = TRUE; - pr.eh = TRUE; - pr.species = TRUE; - pr.saturation_indices = TRUE; - pr.irrev = TRUE; - pr.mix = TRUE; - pr.reaction = TRUE; - pr.use = TRUE; - pr.logfile = FALSE; - pr.punch = TRUE; - if (phast == TRUE) - { - pr.status = FALSE; - } - else - { - pr.status = TRUE; - } - pr.inverse = TRUE; - pr.dump = TRUE; - pr.user_print = TRUE; - pr.headings = TRUE; - pr.user_graph = TRUE; - pr.echo_input = TRUE; - count_warnings = 0; - pr.warnings = 100; - pr.initial_isotopes = TRUE; - pr.isotope_ratios = TRUE; - pr.isotope_alphas = TRUE; - pr.hdf = FALSE; - pr.alkalinity = FALSE; - species_list = NULL; - - user_database = NULL; - first_read_input = TRUE; - have_punch_name = FALSE; - selected_output_file_name = NULL; - dump_file_name = NULL; - -#ifdef PHREEQCI_GUI - g_spread_sheet.heading = NULL; - g_spread_sheet.units = NULL; - g_spread_sheet.count_rows = 0; - g_spread_sheet.rows = NULL; - g_spread_sheet.defaults.units = NULL; - g_spread_sheet.defaults.count_iso = 0; - g_spread_sheet.defaults.iso = NULL; - g_spread_sheet.defaults.redox = NULL; -#endif - - /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - space((void **) ((void *) &calculate_value), INIT, &max_calculate_value, - sizeof(struct calculate_value *)); - hcreate_multi((unsigned) max_calculate_value, - &calculate_value_hash_table); - - /* isotope_ratio */ - max_isotope_ratio = MAX_ELTS; - count_isotope_ratio = 0; - space((void **) ((void *) &isotope_ratio), INIT, &max_isotope_ratio, - sizeof(struct isotope_ratio *)); - hcreate_multi((unsigned) max_isotope_ratio, &isotope_ratio_hash_table); - - /* isotope_value */ - max_isotope_alpha = MAX_ELTS; - count_isotope_alpha = 0; - space((void **) ((void *) &isotope_alpha), INIT, &max_isotope_alpha, - sizeof(struct isotope_alpha *)); - hcreate_multi((unsigned) max_isotope_alpha, &isotope_alpha_hash_table); - - /* - * define constant named log_k - */ - strcpy(token, "XconstantX"); - logk_ptr = logk_store(token, TRUE); - strcpy(token, "1.0"); - read_log_k_only(token, &logk_ptr->log_k[0]); - - phreeqc_mpi_myself = 0; - - copier_init(©_solution); - copier_init(©_pp_assemblage); - copier_init(©_exchange); - copier_init(©_surface); - copier_init(©_ss_assemblage); - copier_init(©_gas_phase); - copier_init(©_kinetics); - copier_init(©_mix); - copier_init(©_reaction); - copier_init(©_temperature); - copier_init(©_pressure); - - set_forward_output_to_log(FALSE); - simulation = 0; - /* - * cvode - */ - - cvode_init(); - /* - * Pitzer - */ - pitzer_init(); - /* - * SIT - */ - sit_init(); - /* - * to facilitate debuging - */ - dbg_master = master; - calculating_deriv = FALSE; - numerical_deriv = FALSE; - - zeros = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); - if (zeros == NULL) - malloc_error(); - zeros[0] = 0.0; - zeros_max = 1; - - cell_pore_volume = 0; - cell_volume = 0; - cell_porosity = 0; - cell_saturation = 0; - - print_density = 0; - - same_model = FALSE; - current_tc = NAN; - current_pa = NAN; - current_mu = NAN; - mu_terms_in_logk = true; - - g_iterations = -1; - G_TOL = 1e-8; - save_init(-1); - count_species_list = 0; - max_species_list = 0; - count_sum_jacob0 = 0; - max_sum_jacob0 = 0; - count_sum_mb1 = 0; - max_sum_mb1 = 0; - count_sum_jacob1 = 0; - max_sum_jacob1 = 0; - count_sum_mb2 = 0; - max_sum_mb2 = 0; - count_sum_jacob2 = 0; - max_sum_jacob2 = 0; - count_sum_delta = 0; - max_sum_delta = 0; - new_x = FALSE; - tc_x = 0; - tk_x = 0; - ph_x = 0; - solution_pe_x = 0; - mu_x = 0; - density_x = 0; - total_h_x = 0; - total_o_x = 0; - cb_x = 0; - total_ions_x = 0; - mass_water_aq_x = 0; - mass_water_surfaces_x = 0; - mass_water_bulk_x = 0; - dl_type_x = cxxSurface::NO_DL; - total_carbon = 0; - total_co2 = 0; - total_alkalinity = 0; - gfw_water = 0; - step_x = 0; - kin_time_x = 0; - correct_disp = FALSE; - cell = 0; - multi_Dflag = FALSE; - interlayer_Dflag = FALSE; - default_Dw = 0; - multi_Dpor = 0; - interlayer_Dpor = 0.1; - multi_Dpor_lim = 0; - interlayer_Dpor_lim = 0; - multi_Dn = 0; - interlayer_tortf = 100; - cell_no = 0; - new_model = TRUE; - new_exchange = FALSE; - new_pp_assemblage = FALSE; - new_surface = FALSE; - new_reaction = FALSE; - new_temperature = FALSE; - new_mix = FALSE; - new_solution = FALSE; - new_gas_phase = FALSE; - new_inverse = FALSE; - new_punch = FALSE; - new_ss_assemblage = FALSE; - new_kinetics = FALSE; - new_copy = FALSE; - new_pitzer = FALSE; - element_h_one = NULL; - count_elts = 0; - count_s_x = 0; - max_s_x = 0; - count_unknowns = 0; - ah2o_unknown = NULL; - alkalinity_unknown = NULL; - carbon_unknown = NULL; - charge_balance_unknown = NULL; - exchange_unknown = NULL; - mass_hydrogen_unknown = NULL; - mass_oxygen_unknown = NULL; - mb_unknown = NULL; - mu_unknown = NULL; - pe_unknown = NULL; - ph_unknown = NULL; - pure_phase_unknown = NULL; - solution_phase_boundary_unknown = NULL; - surface_unknown = NULL; - gas_unknown = NULL; - ss_unknown = NULL; - for (i = 0; i < MAX_LOG_K_INDICES; i++) - { - trxn.logk[i] = 0; - } - for (i = 0; i < 3; i++) - { - trxn.dz[i] = 0; - } - count_trxn = 0; - count_mb_unknowns = 0; - status_on = true; - status_timer = clock(); - status_interval = 0; - count_rate_p = 0; - reaction_step = 0; - transport_step = 0; - transport_start = 0; - advection_step = 0; - stop_program = FALSE; - count_strings = 0; - input_error = 0; - parse_error = 0; - paren_count = 0; - iterations = 0; - gamma_iterations = 0; - run_reactions_iterations = 0; - step_size_now = step_size; - dampen_ah2o = false; - slack = false; - numerical_fixed_volume = false; - force_numerical_fixed_volume = false; - switch_numerical = false; - pe_step_size_now = pe_step_size; - count_total_steps = 0; - remove_unstable_phases = FALSE; - //for (i = 0; i < 50; i++) - //{ - // match_tokens[i].name = NULL; - // match_tokens[i].coef = 0; - //} - //count_match_tokens = 0; - initial_solution_isotopes = FALSE; - full_pitzer = FALSE; - always_full_pitzer = FALSE; - IC = -1; - COSMOT = 0; - AW = 0; - sys = NULL; - count_sys = 0; - max_sys = 0; - sys_tot = 0; -#ifdef PHREEQC2 - AA_basic = 0; - BB_basic = 0; - CC = 0; - I_m = 0; - eps_r = EPSILON; -#endif - rho_0 = 0; - need_temp_msg = 0; - solution_mass = 0; - solution_volume = 0; - - patm_x = 1; /* Initialize pressure of component x to 1 atm */ - ah2o_x = 1.0; - - /* model_min_value = 0; */ - - return; -} -#endif /* ---------------------------------------------------------------------- */ void Phreeqc:: initialize(void) diff --git a/model.cpp b/model.cpp index ed580a76..ac38f0e1 100644 --- a/model.cpp +++ b/model.cpp @@ -576,40 +576,11 @@ gammas(LDBLE mu) /* * compute temperature dependence of a and b for debye-huckel */ -#ifdef PHREEQC2 - LDBLE s1, s2, s3; - s1 = 374.11 - tc_x; - s2 = pow(s1, (LDBLE) 1.0 / (LDBLE) 3.0); - s3 = 1.0 + 0.1342489 * s2 - 3.946263e-03 * s1; - s3 = s3 / (3.1975 - 0.3151548 * s2 - 1.203374e-03 * s1 + - 7.48908e-13 * (s1 * s1 * s1 * s1)); - s3 = sqrt(s3); - if (tk_x >= 373.15) - { - c1 = 5321.0 / tk_x + 233.76 - - tk_x * (tk_x * (8.292e-07 * tk_x - 1.417e-03) + 0.9297); - } - else - { - /* replaced by wateq4f expression - c1=87.74-tc_x*(tc_x*(1.41e-06*tc_x-9.398e-04)+0.4008); - */ - c1 = 2727.586 + 0.6224107 * tk_x - 466.9151 * log(tk_x) - - 52000.87 / tk_x; - } - c1 = sqrt(c1 * tk_x); - /* replaced by wateq4f expressions - a=1824600.0*s3/(c1 * c1 * c1); - b=50.29*s3/c1; - */ - a = 1824827.7 * s3 / (c1 * c1 * c1); - b = 50.2905 * s3 / c1; -#else // a and b are calc'd in calc_dielectrics(tc_x, patm_x); k_temp(tc_x, patm_x); a = DH_A; b = DH_B; -#endif + /* * LLNL temperature dependence */ @@ -1008,37 +979,7 @@ ineq(int in_kode) } } } -/* -* Slack unknown -*/ - if (slack && slack_unknown) - { - int n = slack_unknown->number; - // slack row - for (j = 0; j <= count_unknowns + 1; j++) - { - array[n * (count_unknowns + 1) + j] = 0.0; - } - // slack column - for (j = 0; j < count_unknowns; j++) - { - array[j * (count_unknowns + 1) + n] = 1.0; - } - } -#ifdef SKIP - if (slack && slack_unknown) - { - for (j = 0; j < count_unknowns; j++) - { - if (x[j]->type == SLACK) - { - array[j * (count_unknowns + 1) + x[j]->number] = 1.0; - array[x[j]->mb_number * (count_unknowns + 1) + x[j]->number] = 1.0; - } - } - } -#endif /* * Initialize space if necessary */ @@ -1172,17 +1113,6 @@ ineq(int in_kode) { if (iterations < aqueous_only) continue; -/* - * slack - */ - if (slack && slack_unknown && x[i]->type == SLACK) - { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(array[i * (count_unknowns + 1)]), - (size_t) (count_unknowns + 1) * sizeof(LDBLE)); - back_eq[l_count_rows] = i; - l_count_rows++; - } /* * Pure phases */ @@ -1309,7 +1239,6 @@ ineq(int in_kode) x[i]->type != ALK && x[i]->type != GAS_MOLES && x[i]->type != SS_MOLES /* && x[i]->type != PP */ - && x[i]->type != SLACK ) { if (x[i]->type == PP && !comp_ptr->Get_force_equality()) @@ -4455,11 +4384,8 @@ set(int initial) tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; -#ifdef PHREEQC2 + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) -#else - patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) -#endif /* * H+, e-, H2O @@ -4777,11 +4703,7 @@ sum_species(void) ph_x = -s_hplus->la; solution_pe_x = -s_eminus->la; ah2o_x = exp(s_h2o->la * LOG_10); -#ifdef PHREEQC2 - ah2o_x = exp(s_h2o->la * LOG_10); -#else - //ah2o_x = exp(s_h2o->la * LOG_10); -#endif + density_x = 1.0; if (s_o2 != NULL) s_o2->moles = under(s_o2->lm) * mass_water_aq_x; @@ -5000,9 +4922,7 @@ surface_model(void) debug_model = TRUE; debug_diffuse_layer = TRUE; } -#ifdef PHREEQC2 - k_temp(tc_x, patm_x); -#endif + gammas(mu_x); molalities(TRUE); mb_sums(); diff --git a/pitzer.cpp b/pitzer.cpp index ec6d7e8c..f20de9e8 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1384,11 +1384,9 @@ set_pz(int initial) tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; -#ifdef PHREEQC2 + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) -#else - patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) -#endif + /* * H+, e-, H2O */ diff --git a/prep.cpp b/prep.cpp index a199a820..2e3976ad 100644 --- a/prep.cpp +++ b/prep.cpp @@ -71,7 +71,6 @@ prep(void) setup_gas_phase(); setup_ss_assemblage(); setup_related_surface(); - setup_slack(); tidy_redox(); if (get_input_errors() > 0) { @@ -2029,161 +2028,7 @@ convert_units(cxxSolution *solution_ptr) return (OK); } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -convert_units(struct solution *solution_ptr) -/* ---------------------------------------------------------------------- */ -{ -/* - * Converts solution concentrations to moles/kg water - * Uses totals.input conc to calculate totals.moles. - */ - int i, l; - LDBLE sum_solutes; - char c; - struct master *master_ptr; - struct conc *tot_ptr; - char token[MAX_LENGTH]; -/* - * Convert units - */ - sum_solutes = exp(-solution_ptr->ph * LOG_10); - for (i = 0; solution_ptr->totals[i].description != NULL; i++) - { - master_ptr = master_bsearch(solution_ptr->totals[i].description); - if (master_ptr != NULL) - { - if (master_ptr->minor_isotope == TRUE) - continue; - } - tot_ptr = &(solution_ptr->totals[i]); - tot_ptr->moles = 0.0; - if (strcmp(tot_ptr->description, "H(1)") == 0 || - strcmp(tot_ptr->description, "E") == 0) - { - continue; - } - if (tot_ptr->input_conc <= 0) - continue; -/* - * Get gfw - */ - /* use given gfw if gfw > 0.0 */ - /* use formula give with "as" */ - if (tot_ptr->gfw <= 0.0) - { - if (tot_ptr->as != NULL) - { - /* use given chemical formula to calculate gfw */ - if (compute_gfw(tot_ptr->as, &(tot_ptr->gfw)) == ERROR) - { - error_string = sformatf( "Could not compute gfw, %s.", - tot_ptr->as); - error_msg(error_string, CONTINUE); - input_error++; - } - if (strcmp(tot_ptr->description, "Alkalinity") == 0 && - strcmp(tot_ptr->as, "CaCO3") == 0) - { - tot_ptr->gfw /= 2.; - error_string = sformatf( - "Equivalent wt for alkalinity should be Ca.5(CO3).5. Using %g g/eq.", - (double) tot_ptr->gfw); - warning_msg(error_string); - } - /* use gfw of master species */ - } - else - { - char * temp_desc = string_duplicate(tot_ptr->description); - char *ptr = temp_desc; - copy_token(token, &ptr, &l); - master_ptr = master_bsearch(token); - free_check_null(temp_desc); - if (master_ptr != NULL) - { - /* use gfw for element redox state */ - tot_ptr->gfw = master_ptr->gfw; - } - else - { - error_string = sformatf( "Could not find gfw, %s.", - tot_ptr->description); - error_msg(error_string, CONTINUE); - input_error++; - continue; - } - } - } -/* - * Convert liters to kg solution - */ - tot_ptr->moles = tot_ptr->input_conc; - if (strstr(solution_ptr->units, "/l") != NULL) - { - tot_ptr->moles *= 1.0 / (solution_ptr->density); - } -/* - * Convert milli or micro - */ - c = tot_ptr->units[0]; - if (c == 'm') - { - tot_ptr->moles *= 1e-3; - } - else if (c == 'u') - { - tot_ptr->moles *= 1e-6; - } -/* - * Sum grams of solute, convert from moles necessary - */ - if (strstr(tot_ptr->units, "g/kgs") != NULL || - strstr(tot_ptr->units, "g/l") != NULL) - { - sum_solutes += tot_ptr->moles; - } - else if (strstr(tot_ptr->units, "Mol/kgs") != NULL || - strstr(tot_ptr->units, "Mol/l") != NULL || - strstr(tot_ptr->units, "eq/l") != NULL) - { - sum_solutes += (tot_ptr->moles) * (tot_ptr->gfw); - } -/* - * Convert grams to moles, if necessary - */ - if (strstr(tot_ptr->units, "g/") != NULL && tot_ptr->gfw != 0.0) - { - tot_ptr->moles /= tot_ptr->gfw; - } - } -/* - * Convert /kgs to /kgw - */ - if (strstr(solution_ptr->units, "kgs") != NULL || - strstr(solution_ptr->units, "/l") != NULL) - { - mass_water_aq_x = 1.0 - 1e-3 * sum_solutes; - for (i = 0; solution_ptr->totals[i].description != NULL; i++) - { - solution_ptr->totals[i].moles /= mass_water_aq_x; - } - } -/* - * Scale by mass of water in solution - */ - mass_water_aq_x = solution_ptr->mass_water; - for (i = 0; solution_ptr->totals[i].description != NULL; i++) - { - solution_ptr->totals[i].moles *= mass_water_aq_x; - } - solution_ptr->units = moles_per_kilogram_string; - - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ struct master ** Phreeqc:: get_list_master_ptrs(char *ptr, struct master *master_ptr) @@ -3428,64 +3273,7 @@ setup_gas_phase(void) return (OK); } -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -setup_slack(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for slack unknown - */ - slack_unknown = NULL; - if (slack) - { - x[count_unknowns]->type = SLACK; - x[count_unknowns]->description = string_hsave("slack"); - x[count_unknowns]->moles = 0.0; - x[count_unknowns]->number = count_unknowns; - slack_unknown = x[count_unknowns]; - count_unknowns++; - } - return (OK); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -setup_slack(void) -/* ---------------------------------------------------------------------- */ -{ -/* - * Fill in data for slack unknown - */ - - slack_unknown = NULL; - if (slack) - { - int i = count_unknowns; - int j; - for (j = 0; j < i; j++) - { - if (x[j]->type == MB) - { - x[count_unknowns]->type = SLACK; - x[count_unknowns]->description = string_hsave("slack"); - x[count_unknowns]->moles = 0.0; - x[count_unknowns]->number = count_unknowns; - x[count_unknowns]->mb_number = j; - slack_unknown = x[count_unknowns]; - count_unknowns++; - } - } - if (count_unknowns > i) - { - slack_unknown = x[i]; - } - } - - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: setup_ss_assemblage(void) @@ -4889,10 +4677,6 @@ setup_unknowns(void) { max_unknowns += count_s; } -/* - * One for slack - */ - max_unknowns++; /* * Allocate space for pointer array and structures @@ -5586,154 +5370,6 @@ calc_delta_v(reaction *r_ptr, bool phase) return d_v; #endif } -#ifdef PHREEQC2 -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) -/* ---------------------------------------------------------------------- */ -{ -/* - * calculate log_k for a single phase, correct for pressure - */ - - reaction *r_ptr = (p_ptr->rxn_x ? p_ptr->rxn_x :\ - (p_ptr->rxn_s ? p_ptr->rxn_s : NULL)); - if (!r_ptr) - return 0.0; - if (!r_ptr->logk[vm0]) - return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); - - LDBLE tc = TK - 273.15; - LDBLE kp_t, d_v = 0.0; - - for (size_t i = 0; r_ptr->token[i].name; i++) - { - if (!r_ptr->token[i].s) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H2O")) - { - d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); - } - else if (r_ptr->token[i].s->logk[vm0]) - { - d_v += r_ptr->token[i].coef * (r_ptr->token[i].s->logk[vm0] +\ - (r_ptr->token[i].s->logk[vm1] + r_ptr->token[i].s->logk[vm2] * tc) * tc); - if (r_ptr->token[i].s->logk[kappa]) - { - kp_t = r_ptr->token[i].s->logk[kappa]; - d_v += kp_t * pa; - } - } - } - d_v -= p_ptr->logk[vm0] + (p_ptr->logk[vm1] * tc + p_ptr->logk[vm2] * tc) * tc; - r_ptr->logk[delta_v] = d_v; - - if (!strcmp(r_ptr->token[0].name, "H2O(g)")) - r_ptr->logk[delta_v] = 0.0; - - return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); -} -#ifdef SKIP_THIS_VM -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_vm(LDBLE tc, LDBLE pa) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculate molar volumes for aqueous species, using the millero parm's. - * Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm. - */ - LDBLE kp_t; - - /* S_v * Iv^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221, - Use mu_x for the volume averaged Iv, the difference is negligible....*/ - LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(mu_x); - // Sv_I = 0.0; - for (int i = 0; i < count_s_x; i++) - { - if (!strcmp(s_x[i]->name, "H2O")) - { - s_x[i]->logk[vm_tc] = 18.016 / rho_0; - continue; - } - if (!s_x[i]->logk[vm0]) - continue; - /* the volume terms... */ - s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; - if (s_x[i]->logk[kappa]) - { - kp_t = s_x[i]->logk[kappa]; - //if (s_x[i]->z > 0) - //{ - // /* correct kappa of cations for temperature, but kappa should be <= 0, Table 43.6 */ - // kp_t += 4e-5 * (tc - 25); - // if (kp_t > 0) - // kp_t = 0; - //} - s_x[i]->rxn_x->logk[vm_tc] += kp_t * pa; - } - - /* the ionic strength term * Iv^0.5... */ - s_x[i]->rxn_x->logk[vm_tc] += 0.5 * s_x[i]->z * s_x[i]->z * Sv_I; - /* plus the volume terms * Iv, take mu_x for Iv... */ - //s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x; - - /* for calculating delta_v of the reaction... */ - s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; - } - return OK; -} -#endif -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -calc_vm(LDBLE tc, LDBLE pa) -/* ---------------------------------------------------------------------- */ -{ -/* - * Calculate molar volumes for aqueous species, using the millero parm's. - * Read.cpp copies millero[0..3] into logk[vm0 + 0..3], or reads them directly with -Vm. - */ - LDBLE I_v; - - /* S_v * I_v^0.5 is from Redlich and Meyer, Chem. Rev. 64, 221, - Use mu_x for the volume averaged Iv, the difference is negligible for mu < 10....*/ - //if (mu_x > 0.7) - //{ - // calc_dens(); - // I_v = I_m / solution_volume; - //} - //else - I_v = mu_x; - - LDBLE Sv_I = 0.5 * (1.444 + (0.016799 + (-8.4055e-6 + 5.5153e-7 * tc) * tc) * tc) * sqrt(I_v); - for (int i = 0; i < count_s_x; i++) - { - if (!strcmp(s_x[i]->name, "H2O")) - { - s_x[i]->logk[vm_tc] = 18.016 / rho_0; - continue; - } - if (!s_x[i]->logk[vm0]) - continue; - /* the volume terms... */ - s_x[i]->rxn_x->logk[vm_tc] = s_x[i]->logk[vm0] + (s_x[i]->logk[vm1] + s_x[i]->logk[vm2] * tc) * tc; - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->logk[kappa] * pa; - - /* the ionic strength term * Iv^0.5... */ - s_x[i]->rxn_x->logk[vm_tc] += s_x[i]->z * s_x[i]->z * Sv_I; - /* plus the volume terms * Iv, take mu_x for Iv... */ - //s_x[i]->rxn_x->logk[vm_tc] += (s_x[i]->millero[3] + (s_x[i]->millero[4] + s_x[i]->millero[5] * tc) * tc) * mu_x; - - /* for calculating delta_v of the reaction... */ - s_search(s_x[i]->name)->logk[vm_tc] = s_x[i]->rxn_x->logk[vm_tc]; - } - return OK; -} -#else /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) @@ -5912,7 +5548,7 @@ calc_vm(LDBLE tc, LDBLE pa) } return OK; } -#endif + /* ---------------------------------------------------------------------- */ int Phreeqc:: k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ @@ -5921,13 +5557,10 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ /* * Calculates log k's for all species and pure_phases */ -#ifndef PHREEQC2 + if (tc == current_tc && pa == current_pa && ((fabs(mu_x - current_mu) < 1e-3 * mu_x) || !mu_terms_in_logk)) return OK; -#else - if (tc == current_tc && pa == current_pa) - return OK; -#endif + int i; LDBLE tempk = tc + 273.15; /* @@ -5935,11 +5568,10 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ */ /* calculate relative molar volumes for tc... */ rho_0 = calc_rho_0(tc, pa); -#ifndef PHREEQC2 + pa = patm_x; - //calc_dielectrics(tc_x, pa); calc_dielectrics(tc, pa); -#endif + calc_vm(tc, pa); mu_terms_in_logk = false; @@ -5960,17 +5592,13 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ { if (phases[i]->in == TRUE) { -#ifdef PHREEQC2 - phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - - (phases[i]->logk[vm0] + phases[i]->logk[vm1] * tc + phases[i]->logk[vm2] * tc * tc); - phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); -#else + phases[i]->rxn_x->logk[delta_v] = calc_delta_v(phases[i]->rxn_x, true) - phases[i]->logk[vm0]; if (phases[i]->rxn_x->logk[delta_v]) mu_terms_in_logk = true; phases[i]->lk = k_calc(phases[i]->rxn_x->logk, tempk, pa * PASCAL_PER_ATM); -#endif + } } /* @@ -6610,21 +6238,7 @@ build_min_surface(void) -comp_ptr->Get_formula_z() * comp_ptr->Get_phase_proportion()); count_elts = 0; paren_count = 0; -#ifdef SKIP - if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) - { - /* Add formula for CD_MUSIC */ - char * formula = string_duplicate(comp_ptr->Get_formula().c_str()); - char *ptr1 = formula; - get_elts_in_species(&ptr1, 1.0); - free_check_null(formula); - } - else - { - /* Add master species for non CD_MUSIC */ - add_elt_list(x[j]->master[0]->s->next_elt, 1.0); - } -#endif + // { /* Add specified formula for all types of surfaces */ diff --git a/sit.cpp b/sit.cpp index cc478c20..ea376c0c 100644 --- a/sit.cpp +++ b/sit.cpp @@ -501,11 +501,9 @@ set_sit(int initial) */ tc_x = solution_ptr->Get_tc(); tk_x = tc_x + 273.15; -#ifdef PHREEQC2 - patm_x = solution_ptr->Get_patm(); -#else + patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) -#endif + /* * H+, e-, H2O */ diff --git a/utilities.cpp b/utilities.cpp index 0423b2e2..a37846b3 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -81,37 +81,12 @@ calc_alk(struct reaction * rxn_ptr) } return (return_value); } -#ifdef PHREEQC2 + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_rho_0(LDBLE tc, LDBLE pa) /* ---------------------------------------------------------------------- */ { - /* Density of pure water - Millero, 2009, Aq. Geochem. 15, 7-41, 1 - 200 oC, 1 - 1000 atm... */ - - LDBLE rho_0 = (999.83952 + (16.952577 + (-7.9905127e-3 + (-4.6241757e-5 + (1.0584601e-7 -\ - 2.8103006e-10 * tc) * tc) * tc) * tc) * tc) / (1 + 0.016887236 * tc); - /* pressure... */ -/* - //LDBLE A = 5.08531e-2 + (-3.338927e-4 + (5.112457e-6 + (-3.226571e-8 + (1.186388e-10 -\ - // 1.437927e-13 * tc) * tc) * tc) * tc); - //LDBLE B = -5.6999022e-6 + (6.370734e-8 + (-1.047053e-9 + (5.836798e-12 + (-1.658343e-14 +\ - // 3.977591e-22 * tc) * tc) * tc) * tc); - //rho_0 += (A + B * patm_x) * patm_x; - */ - /* But, A and B are near-constants, the pressure term is equal to... */ - rho_0 += 0.046 * pa; - - return (1e-3 * rho_0); -} -#else -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -calc_rho_0(LDBLE tc, LDBLE pa) -/* ---------------------------------------------------------------------- */ -{ -//#ifdef SKIP /* Density of pure water Wagner and Pruss, 2002, JPCRD 31, 387, eqn. 2.6, along the saturation pressure line + interpolation 0 - 300 oC, 0.006 - 1000 atm... @@ -161,85 +136,6 @@ calc_rho_0(LDBLE tc, LDBLE pa) kappa_0 = (p0 + pa * (2 * p1 + pa * (3 * p2 + sqrt(pa) * 3.5 * p3))) / rho_0; return (rho_0 / 1e3); -//#endif -#ifdef SKIP - /* Calculate the density and compressibility of pure water, - IAPWS, IF97, region 1, 273 < Tk < 623, p_sat < p < 1e8 Pascal. - Seems to give somewhat better rho's and kappa's for p < 2e3 than above, - but may give densities < 0 outside the limits, e.g. tc = 250, p = 2.5e3... */ - - /* The minimal pressure equals the saturation pressure... */ - LDBLE tk = tc + 273.15; - p_sat = exp(11.6702 - 3816.44 / (tk - 46.13)); - if (ah2o_x <= 1.0) - p_sat *= ah2o_x; - //ah2o_x0 = ah2o_x; // for updating rho in model(): compare with new ah2o_x - if (pa < p_sat || (use.Get_solution_ptr() && use.Get_solution_ptr()->Get_patm() < p_sat)) - { - pa = p_sat; - } - if (!use.Get_gas_phase_in()) - patm_x = pa; - LDBLE pasc = pa * 1.01325e5; - LDBLE Rg = 0.461526e3; //J / kg / K - LDBLE Tref = 1386.0, Pref = 16.53e6; // K, Pa - LDBLE t_t = Tref / tk, p_p = pasc / Pref; - LDBLE ni[34] = {0.14632971213167, -0.84548187169114, -0.37563603672040e1, 0.33855169168385e1, - -0.95791963387872, 0.15772038513228, -0.16616417199501e-1, 0.81214629983568e-3, - 0.28319080123804e-3, -0.60706301565874e-3, -0.18990068218419e-1, -0.32529748770505e-1, - -0.21841717175414e-1, -0.52838357969930e-4, -0.47184321073267e-3, -0.30001780793026e-3, - 0.47661393906987e-4, -0.44141845330846e-5, -0.72694996297594e-15, -0.31679644845054e-4, - -0.28270797985312e-5, -0.85205128120103e-9, -0.22425281908000e-5, -0.65171222895601e-6, - -0.14341729937924e-12, -0.40516996860117e-6, -0.12734301741641e-8, -0.17424871230634e-9, - -0.68762131295531e-18, 0.14478307828521e-19, 0.26335781662795e-22, -0.11947622640071e-22, - 0.18228094581404e-23, -0.93537087292458e-25}; - int ii[34] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, - 2, 2, 3, 3, 3, 4, 4, 4, 5, 8, 8, 21, 23, 29, 30, 31, 32}; - int jj[34] = {-2, -1, 0, 1, 2, 3, 4, 5, -9, -7, -1, 0, 1, 3, -3, 0, 1, - 3, 17, -4, 0, 6, -5, -2, 10, -8, -11, -6, -29, -31, -38, -39, -40, -41}; - /* v (m3/kg) = dG/dp = - (p_p * Rg * tk / pasc) * Sum_i (-ni[i] * ii[i] * (7.1 - p_p)^(ii[i] - 1) * (t_t - 1.222)^jj[i]) - kappa_0 (1 / Pa) = -1/v * dv/dp = -1/v * d2G/dp2 = - -1 / (v * Pref) * Sum_i (ni[i] * ii[i] * (ii[i] - 1) * (7.1 - p_p)^(ii[i] - 2) * (t_t - 1.222)^jj[i]) */ - - double v = -ni[11] - (7.1 - p_p) * (ni[15] * ii[15] + ni[20] * ii[20] * (7.1 - p_p)); - double dvdp = ni[15] * ii[15] + ni[20] * ii[20] * (ii[20] - 1) * (7.1 - p_p); - for (int i = 8; i < 34; i++) - { - if (i == 11 || i == 15 || i == 20) - continue; - if (ii[i] == 1) - { - if (jj[i] == 1) - v -= ni[i] * (t_t - 1.222); - else - v -= ni[i] * pow(t_t - 1.222, jj[i]); - } - else if (ii[i] == 2) - { - if (jj[i] == 1) - { - v -= ni[i] * ii[i] * (7.1 - p_p) * (t_t - 1.222); - dvdp += ni[i] * ii[i] * (ii[i] - 1) * (t_t - 1.222); - } - else - { - v -= ni[i] * ii[i] * (7.1 - p_p) * pow(t_t - 1.222, jj[i]); - dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(t_t - 1.222, jj[i]); - } - } - else - { - v -= ni[i] * ii[i] * pow(7.1 - p_p, ii[i] - 1) * pow(t_t - 1.222, jj[i]); - dvdp += ni[i] * ii[i] * (ii[i] - 1) * pow(7.1 - p_p, ii[i] - 2) * pow(t_t - 1.222, jj[i]); - } - } - if (v < 0) - error_msg("Calculating negative densities:\n Pressure and/or Temperature are outside the model's domain.\n", TRUE); - kappa_0 = -dvdp / v / Pref * 1.01325e5; // compressibility, 1/atm - rho_0 = 1e-3 / (v * (p_p * Rg * tk / pasc)); // density, kg/L - return rho_0; -#endif } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -302,7 +198,7 @@ calc_dielectrics(LDBLE tc, LDBLE pa) return (OK); } -#endif + /* ---------------------------------------------------------------------- */ int Phreeqc:: From ed46140f3c9d6337f48420bb24408863cb6f32bf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 May 2013 20:40:44 +0000 Subject: [PATCH 0676/1077] Remove strcmp from calc_vm, calc_delta_v, calc_lk_phase git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7718 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 57 +++++++++++++++++++------------------------------------ print.cpp | 3 ++- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/prep.cpp b/prep.cpp index 2e3976ad..b76f53b4 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5315,26 +5315,6 @@ calc_delta_v(reaction *r_ptr, bool phase) /* ---------------------------------------------------------------------- */ { /* calculate delta_v from molar volumes */ -#ifdef TONY - int p = -1; - LDBLE d_v = 0.0; - - if (phase) - p = 1; /* for phases: reactants have coef's < 0, products have coef's > 0, v.v. for species */ - - for (size_t i = 0; r_ptr->token[i].name; i++) - { - if (!r_ptr->token[i].s) - continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += p * r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; - } - return d_v; -#else //dlp LDBLE d_v = 0.0; @@ -5345,12 +5325,12 @@ calc_delta_v(reaction *r_ptr, bool phase) { //if (!r_ptr->token[i].s) // continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + //if (!strcmp(r_ptr->token[i].s->name, "H+")) + // continue; + //if (!strcmp(r_ptr->token[i].s->name, "e-")) + // continue; + //else if (r_ptr->token[i].s->logk[vm_tc]) + d_v += r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; } } else @@ -5359,16 +5339,15 @@ calc_delta_v(reaction *r_ptr, bool phase) { if (!r_ptr->token[i].s) continue; - if (!strcmp(r_ptr->token[i].s->name, "H+")) - continue; - if (!strcmp(r_ptr->token[i].s->name, "e-")) - continue; - else if (r_ptr->token[i].s->logk[vm_tc]) - d_v += - r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; + //if (!strcmp(r_ptr->token[i].s->name, "H+")) + // continue; + //if (!strcmp(r_ptr->token[i].s->name, "e-")) + // continue; + //else if (r_ptr->token[i].s->logk[vm_tc]) + d_v -= r_ptr->token[i].coef * r_ptr->token[i].s->logk[vm_tc]; } } return d_v; -#endif } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -5397,11 +5376,14 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) if (!r_ptr->token[i].s) continue; s_ptr = r_ptr->token[i].s; - if (!strcmp(s_ptr->name, "H+")) + //if (!strcmp(s_ptr->name, "H+")) + if (s_ptr == s_hplus) continue; - if (!strcmp(s_ptr->name, "e-")) + //if (!strcmp(s_ptr->name, "e-")) + if (s_ptr == s_eminus) continue; - if (!strcmp(s_ptr->name, "H2O")) + //if (!strcmp(s_ptr->name, "H2O")) + if (s_ptr == s_h2o) { d_v += r_ptr->token[i].coef * 18.016 / calc_rho_0(tc, pa); continue; @@ -5483,7 +5465,8 @@ calc_vm(LDBLE tc, LDBLE pa) LDBLE pb_s = 2600. + pa * 1.01325, TK_s = tc + 45.15, sqrt_mu = sqrt(mu_x); for (int i = 0; i < count_s_x; i++) { - if (!strcmp(s_x[i]->name, "H2O")) + //if (!strcmp(s_x[i]->name, "H2O")) + if (s_x[i] == s_h2o) { s_x[i]->logk[vm_tc] = 18.016 / rho_0; continue; diff --git a/print.cpp b/print.cpp index 4263b0d6..da405890 100644 --- a/print.cpp +++ b/print.cpp @@ -1479,7 +1479,8 @@ print_species(void) (double) (species_list[i].s->lm + species_list[i].s->lg), (double) species_list[i].s->lg)); - if (species_list[i].s->logk[vm_tc] || !strcmp(species_list[i].s->name, "H+")) + //if (species_list[i].s->logk[vm_tc] || !strcmp(species_list[i].s->name, "H+")) + if (species_list[i].s->logk[vm_tc] || species_list[i].s == s_hplus) output_msg(sformatf("%10.2f\n", (double) species_list[i].s->logk[vm_tc])); else From ba25fabd6846b2386a2f3f666fd1d415dc552949 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 May 2013 22:05:03 +0000 Subject: [PATCH 0677/1077] optimizing surface references in molalities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7719 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/model.cpp b/model.cpp index ac38f0e1..061cceac 100644 --- a/model.cpp +++ b/model.cpp @@ -2229,7 +2229,209 @@ mb_ss(void) } return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +molalities(int allow_overflow) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculates la for master species + * Calculates lm and moles from lk, lg, and la's of master species + * Adjusts lm of h2 and o2. + */ + int i, j; + LDBLE total_g; + struct rxn_token *rxn_ptr; +/* + * la for master species + */ + for (i = 0; i < count_master; i++) + { + if (master[i]->in == REWRITE) + { + master[i]->s->la = master[i]->s->lm + master[i]->s->lg; + } + } + if (dl_type_x != cxxSurface::NO_DL) + { + s_h2o->tot_g_moles = s_h2o->moles; + s_h2o->tot_dh2o_moles = 0.0; + } + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type > HPLUS && s_x[i]->type != EX + && s_x[i]->type != SURF) + continue; +/* + * lm and moles for all aqueous species + */ + s_x[i]->lm = s_x[i]->lk - s_x[i]->lg; + for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL; + rxn_ptr++) + { + s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef; + /* + if (isnan(rxn_ptr->s->la)) + { + fprintf(stderr,"molalities la %s %e\n", rxn_ptr->s->name, rxn_ptr->s->la); + } + */ + } + if (s_x[i]->type == EX) + { + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + } + else if (s_x[i]->type == SURF) + { + s_x[i]->moles = Utilities::safe_exp(s_x[i]->lm * LOG_10); + + } + else + { + s_x[i]->moles = under(s_x[i]->lm) * mass_water_aq_x; + //if (s_x[i]->moles / mass_water_aq_x > 100) + //{ + // log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", + // s_x[i]->name, + // (double) (s_x[i]->moles / mass_water_aq_x), + // (double) s_x[i]->lm, iterations)); + + // if (iterations >= 0 && allow_overflow == FALSE) + // { + // return (ERROR); + // } + //} + + } + } +/* + * other terms for diffuse layer model + */ + if (use.Get_surface_ptr() != NULL + && use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC + && dl_type_x != cxxSurface::NO_DL) + { + calc_all_donnan(); + } + + struct species *s_ptr = NULL; + for (i = 0; i < count_s_x; i++) + { + s_ptr = s_x[i]; + if (s_ptr->type > HPLUS && s_ptr->type != EX && s_ptr->type != SURF) + continue; + if (use.Get_surface_ptr() != NULL && dl_type_x != cxxSurface::NO_DL && s_ptr->type <= HPLUS) + { + total_g = 0.0; + s_ptr->tot_dh2o_moles = 0.0; + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSurfaceCharge & charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + cxxSpeciesDL & dl_ref = s_diff_layer[s_ptr->number][charge_ref.Get_name()]; + cxxSurfDL & surf_dl_ref = charge_ref.Get_g_map()[s_ptr->z]; + + //s_diff_layer[is][charge_ref.Get_name()] = dl_ref + //charge_ref.Get_g_map()[s_ptr->z] = surf_dl +/* + * partially corrected formulation assumes mass of water in diffuse layer + * is insignificant. Excess is calculated on the basis of moles_water_aq_x + * instead of moles_water_bulk. + */ + /* revised eq. 61 */ + dl_ref.Set_g_moles(s_ptr->moles * s_ptr->erm_ddl * + (surf_dl_ref.Get_g() + charge_ref.Get_mass_water() / mass_water_aq_x)); + if (s_ptr->moles > 1e-30) + { + dl_ref.Set_dg_g_moles(s_ptr->dg * dl_ref.Get_g_moles() / s_ptr->moles); + } + + /* + * first term of 63 is summed for all surfaces in + * s_ptr->tot_g_moles. This sum is then used in + * the jacobian for species i + */ + total_g += surf_dl_ref.Get_g() + charge_ref.Get_mass_water() / mass_water_aq_x; + /* revised eq. 63, second term */ + /* g.dg is dg/dx(-2y**2) or dg/d(ln y) */ + dl_ref.Set_dx_moles(s_ptr->moles * s_ptr->erm_ddl * surf_dl_ref.Get_dg()); + /* revised eq. 63, third term */ + dl_ref.Set_dh2o_moles(-s_ptr->moles * s_ptr->erm_ddl * + charge_ref.Get_mass_water() / mass_water_aq_x); + s_ptr->tot_dh2o_moles += dl_ref.Get_dh2o_moles(); + + /* surface related to phase */ + dl_ref.Set_drelated_moles(s_ptr->moles * s_ptr->erm_ddl * charge_ref.Get_specific_area() * + use.Get_surface_ptr()->Get_thickness() / mass_water_aq_x); + } + s_ptr->tot_g_moles = s_ptr->moles * (1 + total_g /* s_ptr->erm_ddl */ ); + + /* note that dg is for cb, act water, mu eqns */ + /* dg_total_g for mole balance eqns */ + /* dg_g_moles for surface cb */ + + if (s_ptr->moles > 1e-30) + { + s_ptr->dg_total_g = s_ptr->dg * s_ptr->tot_g_moles / s_ptr->moles; + } + else + { + s_ptr->dg_total_g = 0.0; + } + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf( "%s\t%e\t%e\n", s_ptr->name, + (double) s_ptr->moles, + (double) s_ptr->tot_g_moles)); + output_msg(sformatf( "\tg\n")); + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + output_msg(sformatf( "\t%e", + (double) charge_ref.Get_g_map()[s_ptr->z].Get_g())); + } + output_msg(sformatf( "\n\tg_moles\n")); + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + int is = s_ptr->number; + output_msg(sformatf( "\t%e", + (double) s_diff_layer[is][charge_ref.Get_name()].Get_g_moles())); + } + output_msg(sformatf( "\n\tdg\n")); + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + output_msg(sformatf( "\t%e", + (double) charge_ref.Get_g_map()[s_ptr->z].Get_dg())); + } + output_msg(sformatf( "\n\tdx_moles\n")); + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + int is = s_ptr->number; + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + output_msg(sformatf( "\t%e", + (double) s_diff_layer[is][charge_ref.Get_name()].Get_dx_moles())); + } + output_msg(sformatf( "\n\tdh2o_moles\t%e\n", + (double) s_ptr->tot_dh2o_moles)); + for (j = 0; j < (int) use.Get_surface_ptr()->Get_surface_charges().size(); j++) + { + cxxSurfaceCharge &charge_ref = use.Get_surface_ptr()->Get_surface_charges()[j]; + int is = s_ptr->number; + output_msg(sformatf( "\t%e", + s_diff_layer[is][charge_ref.Get_name()].Get_dh2o_moles())); + } + output_msg(sformatf( "\n")); + } + } + } + calc_gas_pressures(); + calc_ss_fractions(); + + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: molalities(int allow_overflow) @@ -2439,6 +2641,7 @@ molalities(int allow_overflow) return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: calc_gas_pressures(void) From 96285f225026093481b46d19f40db56cd72fe643 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 May 2013 22:52:24 +0000 Subject: [PATCH 0678/1077] put back piece in molalities that was necessary after all git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7720 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/model.cpp b/model.cpp index 061cceac..64644fa7 100644 --- a/model.cpp +++ b/model.cpp @@ -2290,18 +2290,18 @@ molalities(int allow_overflow) else { s_x[i]->moles = under(s_x[i]->lm) * mass_water_aq_x; - //if (s_x[i]->moles / mass_water_aq_x > 100) - //{ - // log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", - // s_x[i]->name, - // (double) (s_x[i]->moles / mass_water_aq_x), - // (double) s_x[i]->lm, iterations)); + if (s_x[i]->moles / mass_water_aq_x > 100) + { + log_msg(sformatf( "Overflow: %s\t%e\t%e\t%d\n", + s_x[i]->name, + (double) (s_x[i]->moles / mass_water_aq_x), + (double) s_x[i]->lm, iterations)); - // if (iterations >= 0 && allow_overflow == FALSE) - // { - // return (ERROR); - // } - //} + if (iterations >= 0 && allow_overflow == FALSE) + { + return (ERROR); + } + } } } From d7321bd3e9129da159dc3088307d50f19af2a8e6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 May 2013 19:51:34 +0000 Subject: [PATCH 0679/1077] skip inverse in no inverse defined. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7721 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inverse.cpp b/inverse.cpp index 7c7af7df..d45abf2d 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -23,7 +23,7 @@ inverse_models(void) */ int n, print1; char string[MAX_LENGTH]; - + if (count_inverse <= 0) return OK; // Revert to previous headings after inverse modeling std::vector old_headings; int i; From f127add44ad4c33e1e69c979124ccf10a558ba52 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 May 2013 20:46:20 +0000 Subject: [PATCH 0680/1077] Default_pe is now const char *, saves some string_hsave in clear in prep. Test cases are OK. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7722 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.h | 6 +++--- prep.cpp | 7 +++++-- read.cpp | 4 +++- spread.cpp | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ISolution.h b/ISolution.h index d2e42f61..4e42ff07 100644 --- a/ISolution.h +++ b/ISolution.h @@ -31,8 +31,8 @@ class cxxISolution: public PHRQ_base else this->units.clear(); } - std::string Get_default_pe() const {return default_pe;} - void Set_default_pe(std::string pe) {default_pe = pe;} + const char * Get_default_pe() const {return default_pe;} + void Set_default_pe(const char * pe) {default_pe = pe;} std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;} const std::map < std::string, cxxISolutionComp > &Get_comps(void)const {return this->comps;} void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;} @@ -46,7 +46,7 @@ class cxxISolution: public PHRQ_base std::string units; std::map < std::string, cxxISolutionComp > comps; std::map pe_reactions; - std::string default_pe; + const char * default_pe; }; #endif // !defined(ISOLUTION_H_INCLUDED) diff --git a/prep.cpp b/prep.cpp index b76f53b4..99218ed0 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1804,17 +1804,20 @@ clear(void) /* * Clear master species solution-dependent data */ + const char * pe_str = string_hsave("pe"); for (i = 0; i < count_master; i++) { master[i]->in = FALSE; master[i]->unknown = NULL; if (solution_ptr->Get_initial_data()) { - master[i]->pe_rxn = string_hsave(solution_ptr->Get_initial_data()->Get_default_pe().c_str()); + //master[i]->pe_rxn = string_hsave(solution_ptr->Get_initial_data()->Get_default_pe().c_str()); + master[i]->pe_rxn = solution_ptr->Get_initial_data()->Get_default_pe(); } else { - master[i]->pe_rxn = string_hsave("pe"); + //master[i]->pe_rxn = string_hsave("pe"); + master[i]->pe_rxn = pe_str; } /* * copy primary reaction to secondary reaction diff --git a/read.cpp b/read.cpp index 2fe11293..65b516f9 100644 --- a/read.cpp +++ b/read.cpp @@ -5172,7 +5172,9 @@ read_solution(void) break; if (parser.parse_couple(token) == CParser::PARSER_OK) { - isoln_ptr->Set_default_pe(token); + const char * str = string_hsave(token.c_str()); + //isoln_ptr->Set_default_pe(token); + isoln_ptr->Set_default_pe(str); cxxChemRxn temp_chem_reaction; isoln_ptr->Get_pe_reactions()[token] = temp_chem_reaction; } diff --git a/spread.cpp b/spread.cpp index 4d1071e8..d26f2233 100644 --- a/spread.cpp +++ b/spread.cpp @@ -688,7 +688,8 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; if (parser.parse_couple(token) == OK) { - initial_data_ptr->Set_default_pe(token); + const char * pe_str = string_hsave(token.c_str()); + initial_data_ptr->Set_default_pe(pe_str); cxxChemRxn temp_chem_reaction; initial_data_ptr->Get_pe_reactions()[token] = temp_chem_reaction; } From 11ef24eb4bb40d5a86bc243983711712ce051be5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 May 2013 17:58:27 +0000 Subject: [PATCH 0681/1077] replaced Find with pp_assemblage_comp_ptr stored in struct unknown git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7723 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 25 +++++++++++++------- global_structures.h | 3 +++ model.cpp | 57 +++++++++++++++++++++++++++++---------------- prep.cpp | 27 ++++++++++++++------- print.cpp | 6 +++-- 5 files changed, 78 insertions(+), 40 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 11ea5871..11a89192 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -823,7 +823,8 @@ equi_phase_delta(const char *phase_name) } else { - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[j]->pp_assemblage_comp_ptr; if (state != TRANSPORT && state != PHAST) { LDBLE delta_moles = @@ -2890,14 +2891,17 @@ system_total_elt(const char *total_name) { if (x[i]->type != PP) continue; - std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); - if (it->second.Get_add_formula().size() > 0) + //std::map::iterator it; + //it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[i]->pp_assemblage_comp_ptr; + //if (it->second.Get_add_formula().size() > 0) + if (comp_ptr->Get_add_formula().size() > 0) continue; count_elts = 0; paren_count = 0; int j; - struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + //struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + struct phase * phase_ptr = x[i]->phase; add_elt_list(phase_ptr->next_elt, x[i]->moles); if (count_elts > 0) { @@ -3161,14 +3165,17 @@ system_total_elt_secondary(const char *total_name) { if (x[i]->type != PP) continue; - std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); - if (it->second.Get_add_formula().size() > 0) + //std::map::iterator it; + //it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[i]->pp_assemblage_comp_ptr; + //if (it->second.Get_add_formula().size() > 0) + if (comp_ptr->Get_add_formula().size() > 0) continue; count_elts = 0; paren_count = 0; int j; - struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + //struct phase * phase_ptr = phase_bsearch(x[i]->pp_assemblage_comp_name, &j, FALSE); + struct phase * phase_ptr = x[i]->phase; add_elt_list(phase_ptr->next_sys_total, x[i]->moles); if (count_elts > 0) { diff --git a/global_structures.h b/global_structures.h index c94e2f06..6253cb5a 100644 --- a/global_structures.h +++ b/global_structures.h @@ -809,8 +809,11 @@ struct unknown struct species *s; const char * exch_comp; const char *pp_assemblage_comp_name; + void *pp_assemblage_comp_ptr; const char * ss_name; + void *ss_ptr; const char * ss_comp_name; + void *ss_comp_ptr; int ss_comp_number; int ss_in; const char *surface_comp; diff --git a/model.cpp b/model.cpp index 64644fa7..a958a8b7 100644 --- a/model.cpp +++ b/model.cpp @@ -407,7 +407,8 @@ check_residuals(void) else if (x[i]->type == PP) { cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; if (comp_ptr->Get_add_formula().size() == 0) { if (x[i]->dissolve_only == TRUE) @@ -930,11 +931,13 @@ ineq(int in_kode) if (x[i]->type == PP) { - std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); - assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); + //std::map::iterator it; + //it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + //assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; if (residual[i] > 0e-8 && x[i]->moles > 0 && - it->second.Get_add_formula().size() == 0 + //it->second.Get_add_formula().size() == 0 + comp_ptr->Get_add_formula().size() == 0 && x[i]->dissolve_only == FALSE) { /* @@ -1118,22 +1121,27 @@ ineq(int in_kode) */ if (x[i]->type == PP) { - std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + //std::map::iterator it; + //it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + /* not in model, ignore */ if (x[i]->phase->in == FALSE) - continue; - if (it->second.Get_force_equality()) + continue; + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; + //if (it->second.Get_force_equality()) + if (comp_ptr->Get_force_equality()) continue; /* Undersaturated and no mass, ignore */ //if (x[i]->f > 1e-14/*0e-8*/ && x[i]->moles <= 0 if (x[i]->f > 0e-8 && x[i]->moles <= 0 - && it->second.Get_add_formula().size() == 0) + //&& it->second.Get_add_formula().size() == 0) + && comp_ptr->Get_add_formula().size() == 0) { continue; } else if (x[i]->f < 0e-8 && x[i]->dissolve_only == TRUE - && (x[i]->moles - it->second.Get_initial_moles() >= 0)) + //&& (x[i]->moles - it->second.Get_initial_moles() >= 0)) + && (x[i]->moles - comp_ptr->Get_initial_moles() >= 0)) { continue; } @@ -1144,7 +1152,8 @@ ineq(int in_kode) (void *) &(array[i * (count_unknowns + 1)]), (size_t) (count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; - if (it->second.Get_add_formula().size() == 0 + //if (it->second.Get_add_formula().size() == 0 + if (comp_ptr->Get_add_formula().size() == 0 && x[i]->dissolve_only == FALSE) { res[l_count_rows] = 1.0; @@ -1223,7 +1232,8 @@ ineq(int in_kode) cxxPPassemblageComp *comp_ptr1 = NULL; if (x[i]->type == PP) { - comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; } if (x[i]->type == SURFACE && x[i]->phase_unknown != NULL) { @@ -1314,7 +1324,8 @@ ineq(int in_kode) { if (x[i]->type == PP) { - comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; /* not in model, ignore */ if (x[i]->phase->in == FALSE) continue; @@ -1410,7 +1421,8 @@ ineq(int in_kode) { if (x[i]->type == PP) { - comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; if ((x[i]->moles <= 0.0 && x[i]->f > 0e-8 && comp_ptr->Get_add_formula().size() == 0) || x[i]->phase->in == FALSE) @@ -3103,7 +3115,8 @@ reset(void) if (x[i]->dissolve_only == TRUE) { assert (x[i]->type == PP); - comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; assert(comp_ptr); if ((delta[i] < 0.0) && (-delta[i] > @@ -3700,7 +3713,8 @@ reset(void) } else if (x[i]->type == PP) { - comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; /*if (fabs(delta[i]) > epsilon) converge=FALSE; */ if (debug_model == TRUE) { @@ -4042,7 +4056,8 @@ residuals(void) } else if (x[i]->type == PP) { - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; residual[i] = x[i]->f * LOG_10; if (comp_ptr->Get_add_formula().size() == 0) { @@ -5633,7 +5648,8 @@ set_inert_moles(void) for (j = 0; j < count_unknowns; j++) { if (x[j]->type != PP) continue; - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[j]->pp_assemblage_comp_ptr; if (comp_ptr->Get_precipitate_only()) { x[j]->inert_moles = x[j]->moles; @@ -5652,7 +5668,8 @@ unset_inert_moles() for (j = 0; j < count_unknowns; j++) { if (x[j]->type != PP) continue; - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[j]->pp_assemblage_comp_ptr; if (comp_ptr->Get_precipitate_only()) { x[j]->moles += x[j]->inert_moles; diff --git a/prep.cpp b/prep.cpp index 99218ed0..0fef219d 100644 --- a/prep.cpp +++ b/prep.cpp @@ -198,7 +198,7 @@ quick_setup(void) it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); cxxPPassemblageComp * comp_ptr = &(it->second); - + x[i]->pp_assemblage_comp_ptr = comp_ptr; x[i]->moles = comp_ptr->Get_moles(); /* A. Crapsi */ x[i]->si = comp_ptr->Get_si(); @@ -954,7 +954,8 @@ build_jacobian_sums(int k) { if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + //if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + if (strcmp_nocase(x[kk]->phase->name, comp_ptr->Get_phase_name().c_str()) == 0) break; } @@ -1012,7 +1013,8 @@ build_jacobian_sums(int k) { if (x[kk]->type != PP) continue; - if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + //if (x[kk]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + if (strcmp_nocase(x[kk]->phase->name, comp_ptr->Get_phase_name().c_str()) == 0) break; } if (kk >= 0) @@ -1482,7 +1484,8 @@ build_pure_phases(void) */ count_elts = 0; paren_count = 0; - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; if (comp_ptr->Get_add_formula().size() > 0) { char * char_name = string_duplicate(comp_ptr->Get_add_formula().c_str()); @@ -4076,6 +4079,7 @@ setup_pure_phases(void) x[count_unknowns]->type = PP; x[count_unknowns]->description = string_hsave(comp_ptr->Get_name().c_str()); x[count_unknowns]->pp_assemblage_comp_name = x[count_unknowns]->description; + x[count_unknowns]->pp_assemblage_comp_ptr = comp_ptr; x[count_unknowns]->moles = comp_ptr->Get_moles(); x[count_unknowns]->phase = phase_ptr; x[count_unknowns]->si = comp_ptr->Get_si(); @@ -4116,7 +4120,8 @@ adjust_setup_pure_phases(void) { phase_ptr = x[i]->phase; phase_ptrs.push_back(phase_ptr); - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[i]->pp_assemblage_comp_ptr; si_org = comp_ptr->Get_si_org(); if (phase_ptr->p_c > 0 && phase_ptr->t_c > 0) { @@ -6067,7 +6072,8 @@ build_min_exch(void) { if (x[k]->type != PP) continue; - if (x[k]->phase->name == string_hsave(comp_ref.Get_phase_name().c_str())) + //if (x[k]->phase->name == string_hsave(comp_ref.Get_phase_name().c_str())) + if (strcmp_nocase(x[k]->phase->name, comp_ref.Get_phase_name().c_str()) == 0) break; } if (j == -1) @@ -6197,7 +6203,8 @@ build_min_surface(void) { if (x[k]->type != PP) continue; - if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + //if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + if (strcmp_nocase(x[k]->phase->name, comp_ptr->Get_phase_name().c_str()) == 0) break; } if (j == -1) @@ -6324,7 +6331,8 @@ setup_related_surface(void) { if (x[k]->type != PP) continue; - if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + //if (x[k]->phase->name == string_hsave(comp_ptr->Get_phase_name().c_str())) + if (strcmp_nocase(x[k]->phase->name, comp_ptr->Get_phase_name().c_str()) == 0) break; } if (k == -1) @@ -6347,7 +6355,8 @@ setup_related_surface(void) { if (x[k]->type != PP) continue; - if (x[k]->phase->name == string_hsave(comp_i_ptr->Get_phase_name().c_str())) + //if (x[k]->phase->name == string_hsave(comp_i_ptr->Get_phase_name().c_str())) + if (strcmp_nocase(x[k]->phase->name, comp_i_ptr->Get_phase_name().c_str()) == 0) break; } if (k == -1) diff --git a/print.cpp b/print.cpp index da405890..deeacd3b 100644 --- a/print.cpp +++ b/print.cpp @@ -1283,7 +1283,8 @@ print_pp_assemblage(void) { if (x[j]->type != PP) continue; - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[j]->pp_assemblage_comp_ptr; /* * Print saturation index */ @@ -2646,7 +2647,8 @@ punch_pp_assemblage(void) { if (x == NULL || x[j]->type != PP) continue; - cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[j]->pp_assemblage_comp_ptr; /* * Print pure phase assemblage data */ From 0b7b5f7c0749a6b17596826c4034cb931ba5b31a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 May 2013 20:42:28 +0000 Subject: [PATCH 0682/1077] added pointers for solid solution and ss component in unknown struct to speed calculations, all test cases run git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7724 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.cxx | 20 +++++++++++++++++++- model.cpp | 9 ++++++--- prep.cpp | 9 +++++++-- structures.cpp | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 15659010..1b9dd944 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -281,7 +281,7 @@ cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) //cxxNameDouble eltList; this->eltList.add_extensive(addee.eltList, extensive); } - +#ifdef SKIP cxxPPassemblageComp * cxxPPassemblage:: Find(const std::string name_in) { @@ -303,6 +303,24 @@ Find(const std::string name_in) } return comp; } +#endif +cxxPPassemblageComp * cxxPPassemblage:: +Find(const std::string name_in) +{ + cxxPPassemblageComp * comp = NULL; + std::map::iterator it; + it = this->pp_assemblage_comps.begin(); + for ( ; it != this->pp_assemblage_comps.end(); it++) + { + if (Utilities::strcmp_nocase(name_in.c_str(), it->first.c_str()) == 0) + { + comp = &it->second; + break; + } + } + return comp; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("eltlist"), // 0 std::vector< std::string >::value_type("component"), // 1 diff --git a/model.cpp b/model.cpp index a958a8b7..cf0e2577 100644 --- a/model.cpp +++ b/model.cpp @@ -2236,7 +2236,8 @@ mb_ss(void) { if (x[i]->type != SS_MOLES) break; - cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + //cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + cxxSS *ss_ptr = (cxxSS *) x[i]->ss_ptr; x[i]->ss_in = ss_ptr->Get_ss_in() ? TRUE : FALSE; } return (OK); @@ -3798,8 +3799,10 @@ reset(void) x[i]->moles -= delta[i]; if (x[i]->moles < MIN_TOTAL_SS && calculating_deriv == FALSE) x[i]->moles = MIN_TOTAL_SS; - cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); - cxxSScomp *comp_ptr = ss_ptr->Find(x[i]->ss_comp_name); + //cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + cxxSS *ss_ptr = (cxxSS *) x[i]->ss_ptr; + //cxxSScomp *comp_ptr = ss_ptr->Find(x[i]->ss_comp_name); + cxxSScomp *comp_ptr = (cxxSScomp *) x[i]->ss_comp_ptr; comp_ptr->Set_moles(x[i]->moles); /* Pitzer gamma */ } diff --git a/prep.cpp b/prep.cpp index 0fef219d..69275533 100644 --- a/prep.cpp +++ b/prep.cpp @@ -262,7 +262,9 @@ quick_setup(void) { for (size_t k = 0; k < ss_ptrs[j]->Get_ss_comps().size(); k++) { + x[i]->ss_ptr = ss_ptrs[j]; cxxSScomp *comp_ptr = &(ss_ptrs[j]->Get_ss_comps()[k]); + x[i]->ss_comp_ptr = comp_ptr; x[i]->moles = comp_ptr->Get_moles(); if (x[i]->moles <= 0) { @@ -331,7 +333,7 @@ quick_setup(void) /* moles picked up from master->total */ } else if (x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - { + { cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); x[i]->related_moles = charge_ptr->Get_grams(); x[i]->mass_water = charge_ptr->Get_mass_water(); @@ -663,7 +665,8 @@ build_ss_assemblage(void) { if (x[i]->type != SS_MOLES) continue; - cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + //cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); + cxxSS *ss_ptr = (cxxSS *) x[i]->ss_ptr; assert(ss_ptr); if (ss_ptr != ss_ptr_old) { @@ -3314,7 +3317,9 @@ setup_ss_assemblage(void) comp_ptr->Set_initial_moles(x[count_unknowns]->moles); x[count_unknowns]->ln_moles = log(x[count_unknowns]->moles); x[count_unknowns]->ss_name = string_hsave(ss_ptrs[j]->Get_name().c_str()); + x[count_unknowns]->ss_ptr = ss_ptrs[j]; x[count_unknowns]->ss_comp_name = string_hsave(comp_ptr->Get_name().c_str()); + x[count_unknowns]->ss_comp_ptr = comp_ptr; x[count_unknowns]->ss_comp_number = (int) i; x[count_unknowns]->phase = phase_ptr; x[count_unknowns]->number = count_unknowns; diff --git a/structures.cpp b/structures.cpp index 996e859a..7ceed374 100644 --- a/structures.cpp +++ b/structures.cpp @@ -3118,8 +3118,11 @@ unknown_alloc(void) unknown_ptr->si = 0.0; unknown_ptr->s = NULL; unknown_ptr->exch_comp = NULL; + unknown_ptr->pp_assemblage_comp_ptr = NULL; unknown_ptr->ss_name = NULL; + unknown_ptr->ss_ptr = NULL; unknown_ptr->ss_comp_name = NULL; + unknown_ptr->ss_comp_ptr = NULL; unknown_ptr->ss_comp_number = 0; unknown_ptr->ss_in = FALSE; unknown_ptr->surface_comp = NULL; From 26614f7098dc5551eecbd4ee48ded606a3c9eb18 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 20 May 2013 23:15:15 +0000 Subject: [PATCH 0683/1077] minor optimizations of tidy_model git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7731 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 158 ++++++++++++++++++++++++++----------------------------- 1 file changed, 74 insertions(+), 84 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index e787ced1..fd44c54a 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -169,7 +169,6 @@ tidy_model(void) phases[i]->pr_p = 0.0; phases[i]->pr_phi = 1.0; } - /* named_log_k */ if (new_named_logk) { @@ -241,13 +240,7 @@ tidy_model(void) if (new_exchange) { tidy_exchange(); - } - if (new_exchange) - { tidy_min_exchange(); - } - if (new_exchange) - { tidy_kin_exchange(); } /* @@ -256,9 +249,6 @@ tidy_model(void) if (new_surface) { tidy_min_surface(); - } - if (new_surface) - { tidy_kin_surface(); } /* @@ -271,9 +261,6 @@ tidy_model(void) if (new_model) { tidy_isotope_ratios(); - } - if (new_model) - { tidy_isotope_alphas(); } /* @@ -328,84 +315,87 @@ tidy_model(void) /* * make sure essential species are defined */ - if (s_h2o == NULL) + if (new_model) { - input_error++; - error_msg("H2O not defined.", STOP); - } - if (s_h2o->primary == NULL) - { - input_error++; - error_msg("H2O, primary master species for O, not defined.", - CONTINUE); - } - if (s_h2o->secondary == NULL) - { - input_error++; - error_msg("H2O, secondary master species for O(-2), not defined.", - CONTINUE); - } - if (s_hplus == NULL && s_h3oplus == NULL) - { - input_error++; - error_msg("Neither H+ nor H3O+ are defined in solution_species.", - STOP); - } - else if (s_hplus == NULL && s_h3oplus != NULL) - { - s_hplus = s_h3oplus; - s_h3oplus = NULL; - } - else if (s_hplus != NULL && s_h3oplus == NULL) - { - } - else if (s_hplus != NULL && s_h3oplus != NULL) - { - input_error++; - error_msg("Cannot define both H+ and H3O+ in solution_species.", - STOP); - } - if (s_hplus->primary == NULL) - { - input_error++; - error_msg("H3O+, primary master species for H, not defined.", - CONTINUE); - } - if (s_hplus->secondary == NULL) - { - input_error++; - error_msg("H3O+, secondary master species for H(1), not defined.", - CONTINUE); - } - if (s_eminus == NULL) - { - input_error++; - error_msg("e- not defined in solution_species.", CONTINUE); - } - if (s_eminus->primary == NULL) - { - input_error++; - error_msg("e-, primary master species for E-, not defined.", - CONTINUE); - } - if (pitzer_model == FALSE || pitzer_pe == TRUE) - { - if (s_h2 == NULL) + if (s_h2o == NULL) { input_error++; - error_msg("H2(aq) not defined in solution_species.", CONTINUE); + error_msg("H2O not defined.", STOP); } - if (s_o2 == NULL) + if (s_h2o->primary == NULL) { input_error++; - error_msg("O2(aq) not defined in solution_species.", CONTINUE); + error_msg("H2O, primary master species for O, not defined.", + CONTINUE); + } + if (s_h2o->secondary == NULL) + { + input_error++; + error_msg("H2O, secondary master species for O(-2), not defined.", + CONTINUE); + } + if (s_hplus == NULL && s_h3oplus == NULL) + { + input_error++; + error_msg("Neither H+ nor H3O+ are defined in solution_species.", + STOP); + } + else if (s_hplus == NULL && s_h3oplus != NULL) + { + s_hplus = s_h3oplus; + s_h3oplus = NULL; + } + else if (s_hplus != NULL && s_h3oplus == NULL) + { + } + else if (s_hplus != NULL && s_h3oplus != NULL) + { + input_error++; + error_msg("Cannot define both H+ and H3O+ in solution_species.", + STOP); + } + if (s_hplus->primary == NULL) + { + input_error++; + error_msg("H3O+, primary master species for H, not defined.", + CONTINUE); + } + if (s_hplus->secondary == NULL) + { + input_error++; + error_msg("H3O+, secondary master species for H(1), not defined.", + CONTINUE); + } + if (s_eminus == NULL) + { + input_error++; + error_msg("e- not defined in solution_species.", CONTINUE); + } + if (s_eminus->primary == NULL) + { + input_error++; + error_msg("e-, primary master species for E-, not defined.", + CONTINUE); + } + if (pitzer_model == FALSE || pitzer_pe == TRUE) + { + if (s_h2 == NULL) + { + input_error++; + error_msg("H2(aq) not defined in solution_species.", CONTINUE); + } + if (s_o2 == NULL) + { + input_error++; + error_msg("O2(aq) not defined in solution_species.", CONTINUE); + } + } + element_h_one = element_store("H(1)"); + if (element_h_one == NULL) + { + input_error++; + error_msg("H(1) not defined in solution_master_species.", CONTINUE); } - } - element_h_one = element_store("H(1)"); - if (element_h_one == NULL) - { - input_error++; - error_msg("H(1) not defined in solution_master_species.", CONTINUE); } /* * Error check, program termination From a52fc625d941a34569c276ae608bcf5c0eb37aa2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 23 May 2013 22:01:07 +0000 Subject: [PATCH 0684/1077] added get/set StorageBinList method git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7732 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dumper.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dumper.h b/dumper.h index 063af4e0..7f953e74 100644 --- a/dumper.h +++ b/dumper.h @@ -42,8 +42,11 @@ public: std::set < int > & Get_reaction(void) { return(this->binList.Get_reaction().Get_numbers()); }; std::set < int > & Get_temperature(void) { return(this->binList.Get_temperature().Get_numbers()); }; std::set < int > & Get_pressure(void) { return(this->binList.Get_pressure().Get_numbers()); }; - bool Get_on(void) {return this->on;}; - void Set_on(bool tf) {this->on = tf;}; + bool Get_on(void) { return this->on; }; + void Set_on(bool tf) { this->on = tf; }; + + StorageBinList & Get_StorageBinList(void) { return this->binList; }; + void Set_StorageBinList(StorageBinList sbl) { this->binList = sbl; }; protected: std::string file_name; bool append; From 701878af445b88c6329f740cef2636aed7094be3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 May 2013 17:33:53 +0000 Subject: [PATCH 0685/1077] If total set to zero in Solution_modify, took log of zero to update la and failed to converge. Added check not to update la unless both old and new totals are greater than zero. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7739 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index ba4088c9..92b3b6be 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -967,7 +967,7 @@ cxxSolution::read_raw(CParser & parser, bool check) cxxNameDouble::iterator jit = simple_this_totals.find(it->first); if (jit != simple_this_totals.end()) { - if (it->second != 0) + if (it->second > 0 && jit->second > 0.0) { LDBLE f = jit->second / it->second; if (f != 1) From 145fcc00baeafad4d28ada86137aa6b6ab95e4aa Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 May 2013 19:56:14 +0000 Subject: [PATCH 0686/1077] vcxproj has some change. Tony's updates to initialize pr_in git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7741 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 2 +- Phreeqc.h | 1 + class_main.cpp | 5 ++-- mainsubs.cpp | 34 +++++++++++++++++++---- prep.cpp | 5 ++-- print.cpp | 69 +++++++++++++++++++++++++++++----------------- tidy.cpp | 17 +----------- 7 files changed, 79 insertions(+), 54 deletions(-) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 5bb7abd6..63e1b8b0 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -357,7 +357,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.0.2, compiled on April 9, 2013\n")); + output_msg(sformatf("Using PHREEQC: version 3.0.5, compiled on May 29, 2013\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); diff --git a/Phreeqc.h b/Phreeqc.h index c75ffd5f..dd37e10f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -614,6 +614,7 @@ public: char *sformatf(const char *format, ...); int array_print(LDBLE * array_l, int row_count, int column_count, int max_column_count); + int set_pr_in_false(void); int print_all(void); int print_exchange(void); int print_gas_phase(void); diff --git a/class_main.cpp b/class_main.cpp index 611520e4..18b42a3a 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -236,6 +236,7 @@ main_method(int argc, char *argv[]) { return errors; } + output_close(); return 0; } #endif //TEST_COPY @@ -253,7 +254,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.0.2"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.0.5"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -277,7 +278,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "April 9, 2013"); + len = sprintf(buffer, "%s", "May 11, 2013"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif diff --git a/mainsubs.cpp b/mainsubs.cpp index 1e8345cb..dabd8876 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -631,6 +631,13 @@ initial_solutions(int print) punch_all(); print_all(); /* free_model_allocs(); */ +// remove pr_in + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type == SOLUTION_PHASE_BOUNDARY) + x[i]->phase->pr_in = false; + } + if (converge == ERROR || converge1 == ERROR) { error_msg("Model failed to converge for initial solution.", @@ -1090,6 +1097,27 @@ reactions(void) saver(); /* free_model_allocs(); */ +//// set pr_in to false for following steps... +// if (use.Get_pp_assemblage_in()) +// { +// for (int i = 0; i < count_unknowns; i++) +// { +// if (x[i]->type == PP) +// x[i]->phase->pr_in = false; +// } +// } +// if (use.Get_gas_phase_in()) +// { +// cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); +// for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) +// { +// cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); +// int k; +// struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); +// assert(phase_ptr); +// phase_ptr->pr_in = false; +// } +// } /* last_model.force_prep = TRUE; */ return (OK); } @@ -2298,12 +2326,6 @@ run_simulations(void) if (new_solution) { initial_solutions(TRUE); -/* For further printout, remove Peng-Robinson equilibration (if done) */ - for (int i = 0; i < count_phases; i++) - { - if (phases[i]->pr_in) - (phases[i]->pr_in) = FALSE; - } } /* diff --git a/prep.cpp b/prep.cpp index 69275533..221fd614 100644 --- a/prep.cpp +++ b/prep.cpp @@ -3825,7 +3825,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); phase_ptr->pr_tk = TK; - phase_ptr->pr_in = true; +// phase_ptr->pr_in = true; } if (phase_ptr->pr_tk != TK) { @@ -3834,7 +3834,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) kk = 0.37464 + oo * (1.54226 - 0.26992 * oo); phase_ptr->pr_alpha = pow(1 + kk * (1 - sqrt(T_r)), 2); phase_ptr->pr_tk = TK; - phase_ptr->pr_in = true; +// phase_ptr->pr_in = true; } } for (i = 0; i < n_g; i++) @@ -4513,7 +4513,6 @@ setup_solution(void) " or solution phase boundary constraints.", CONTINUE); input_error++; } - return (OK); } /* ---------------------------------------------------------------------- */ diff --git a/print.cpp b/print.cpp index deeacd3b..24a176ad 100644 --- a/print.cpp +++ b/print.cpp @@ -45,6 +45,34 @@ array_print(LDBLE * array_l, int row_count, int column_count, return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +set_pr_in_false(void) +/* ---------------------------------------------------------------------- */ +{ + // set pr_in to false for subsequent steps... + if (use.Get_pp_assemblage_in()) + { + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type == PP) + x[i]->phase->pr_in = false; + } + } + if (use.Get_gas_phase_in() && use.Get_gas_phase_ptr()) + { + cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); + for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) + { + cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); + int k; + struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr) + phase_ptr->pr_in = false; + } + } + return (OK); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: print_all(void) @@ -60,7 +88,10 @@ print_all(void) * Makes sorted list including all species for each valence state */ if (pr.all == FALSE) + { + set_pr_in_false(); return (OK); + } if (pr.surface == TRUE || pr.exchange == TRUE || pr.species == TRUE) { species_list_sort(); @@ -87,6 +118,7 @@ print_all(void) print_species(); print_alkalinity(); print_saturation_indices(); + set_pr_in_false(); return (OK); } @@ -609,6 +641,7 @@ print_gas_phase(void) if (fabs(delta_moles) <= MIN_TOTAL) delta_moles = 0.0; if (PR) + { output_msg(sformatf("%-11s%12.2f%12.3e%7.3f%12.3e%12.3e%12.3e\n", phase_ptr->name, (double) lp, @@ -617,6 +650,7 @@ print_gas_phase(void) (double) initial_moles, (double) moles, (double) delta_moles)); + } else output_msg(sformatf("%-18s%12.2f%12.3e%12.3e%12.3e%12.3e\n", phase_ptr->name, @@ -1136,8 +1170,7 @@ print_saturation_indices(void) LDBLE la_eminus; struct rxn_token *rxn_ptr; struct reaction *reaction_ptr; - const char *pr_in; - bool PR_inprint, gas = true; + bool gas = true; if (pr.saturation_indices == FALSE || pr.all == FALSE) return (OK); @@ -1187,19 +1220,11 @@ print_saturation_indices(void) /* * Print saturation index */ - PR_inprint = false; - if (phases[i]->pr_in) - { - PR_inprint = true; - phases[i]->pr_in = false; - } reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) - phases[i]->logk[vm0]; if (reaction_ptr->logk[delta_v]) mu_terms_in_logk = true; lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); - if (PR_inprint) - phases[i]->pr_in = true; iap = 0.0; for (rxn_ptr = reaction_ptr->token + 1; rxn_ptr->s != NULL; rxn_ptr++) @@ -1214,17 +1239,16 @@ print_saturation_indices(void) } } si = -lk + iap; - pr_in = " "; - output_msg(sformatf("\t%-15s%7.2f%2s%8.2f%8.2f %s", - phases[i]->name, (double) si, pr_in, (double) iap, (double) lk, + output_msg(sformatf("\t%-15s%7.2f %8.2f%8.2f %s", + phases[i]->name, (double) si, (double) iap, (double) lk, phases[i]->formula)); if (gas && phases[i]->pr_in && phases[i]->pr_p) { if (phases[i]->moles_x || state == INITIAL_SOLUTION) { - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", - " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + output_msg(sformatf("\t%s%5.1f%s%5.3f", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi)); } else { for (int j = 0; j < count_unknowns; j++) @@ -1234,8 +1258,8 @@ print_saturation_indices(void) if (!strcmp(x[j]->phase->name, phases[i]->name)) { if (x[j]->moles) - output_msg(sformatf("\t%s%5.1f%s%5.3f%s", - " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi, ".")); + output_msg(sformatf("\t%s%5.1f%s%5.3f", + " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi)); break; } } @@ -1260,8 +1284,6 @@ print_pp_assemblage(void) char token[MAX_LENGTH]; struct rxn_token *rxn_ptr; struct phase *phase_ptr; - bool PR_inprint; - const char *pr_in; if (pr.pp_assemblage == FALSE || pr.all == FALSE) return (OK); @@ -1298,14 +1320,11 @@ print_pp_assemblage(void) else { phase_ptr = x[j]->phase; - PR_inprint = false; phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) - phase_ptr->logk[vm0]; if (phase_ptr->rxn->logk[delta_v]) mu_terms_in_logk = true; lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM); - if (PR_inprint) - phase_ptr->pr_in = true; for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { @@ -1326,10 +1345,8 @@ print_pp_assemblage(void) si = -x[j]->phase->lk + iap; output_msg(OUTPUT_MESSAGE,"\t%-15s%7.2f%8.2f%8.2f", x[j]->phase->name, (double) si, (double) iap, (double) x[j]->phase->lk); */ - pr_in = " "; - output_msg(sformatf("%-14s%8.2f%2s%7.2f %8.2f", - x[j]->phase->name, (double) si, pr_in, (double) iap, - (double) lk)); + output_msg(sformatf("%-14s%8.2f %7.2f %8.2f", + x[j]->phase->name, (double) si, (double) iap, (double) lk)); } /* * Print pure phase assemblage data diff --git a/tidy.cpp b/tidy.cpp index fd44c54a..9e6f98db 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -15,7 +15,6 @@ int Phreeqc:: tidy_model(void) /* ---------------------------------------------------------------------- */ { - int i; int n_user, last; int new_named_logk; /* @@ -162,14 +161,7 @@ tidy_model(void) } -/* reset Peng-Robinson parms... */ - for (i = 0; i < count_phases; i++) - { - phases[i]->pr_in = false; - phases[i]->pr_p = 0.0; - phases[i]->pr_phi = 1.0; - } - /* named_log_k */ +/* named_log_k */ if (new_named_logk) { tidy_logk(); @@ -213,13 +205,6 @@ tidy_model(void) { tidy_gas_phase(); } -/* reset Peng-Robinson parms... */ - for (i = 0; i < count_phases; i++) - { - phases[i]->pr_in = false; - phases[i]->pr_p = 0.0; - phases[i]->pr_phi = 1.0; - } /* * tidy pp_assemblage data */ From 6c4f7253a9ac24f01ebc684fd86cdd97cd424fbc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 29 May 2013 23:38:00 +0000 Subject: [PATCH 0687/1077] added some const and added cell for use in phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7743 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 11 +++++------ StorageBinList.h | 18 +++++++++++++++++- dumper.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 47e5d4e7..acb678f6 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -110,6 +110,7 @@ StorageBinList::~StorageBinList(void) std::set StorageBinList::GetAllItems(void) { + // don't include this->cell std::set items; items.insert(&this->solution); items.insert(&this->pp_assemblage); @@ -146,7 +147,6 @@ bool StorageBinList::Read(CParser & parser) bool useLastLine(false); opt_save = CParser::OPT_DEFAULT; - StorageBinListItem cell_list; for (;;) { int opt; @@ -162,7 +162,6 @@ bool StorageBinList::Read(CParser & parser) // Select StorageBinListItem StorageBinListItem *item = NULL; - //StorageBinListItem cell_list; switch (opt) { case 0: @@ -201,7 +200,7 @@ bool StorageBinList::Read(CParser & parser) break; case 14: case 15: - item = &cell_list; + item = &(this->Get_cell()); break; case 17: case 18: @@ -290,15 +289,15 @@ bool StorageBinList::Read(CParser & parser) } // Now check to see if cell_list defined - if (cell_list.Get_defined()) + if (this->Get_cell().Get_defined()) { - if (cell_list.Get_numbers().empty()) + if (this->Get_cell().Get_numbers().empty()) { this->SetAll(true); } else { - this->TransferAll(cell_list); + this->TransferAll(this->Get_cell()); } } return(return_value); diff --git a/StorageBinList.h b/StorageBinList.h index 9fefdb7a..f55a6735 100644 --- a/StorageBinList.h +++ b/StorageBinList.h @@ -14,10 +14,11 @@ public: StorageBinListItem(CParser & parser); ~StorageBinListItem(void); void Set_defined(bool tf) { this->defined = tf; }; - bool Get_defined(void) { return(this->defined); }; + bool Get_defined(void)const { return(this->defined); }; void Augment(std::string token); void Augment(int i); std::set < int > &Get_numbers(void) { return(this->numbers); }; + const std::set < int > &Get_numbers(void)const { return(this->numbers); }; void Clear(void) { this->numbers.clear(); }; protected: std::set < int > numbers; @@ -45,6 +46,20 @@ public: StorageBinListItem & Get_reaction(void) { return(this->reaction); }; StorageBinListItem & Get_temperature(void) { return(this->temperature); }; StorageBinListItem & Get_pressure(void) { return(this->pressure); }; + StorageBinListItem & Get_cell(void) { return(this->cell); }; + + const StorageBinListItem & Get_solution(void)const { return(this->solution); }; + const StorageBinListItem & Get_pp_assemblage(void)const { return(this->pp_assemblage); }; + const StorageBinListItem & Get_exchange(void)const { return(this->exchange); }; + const StorageBinListItem & Get_surface(void)const { return(this->surface); }; + const StorageBinListItem & Get_ss_assemblage(void)const { return(this->ss_assemblage); }; + const StorageBinListItem & Get_gas_phase(void)const { return(this->gas_phase); }; + const StorageBinListItem & Get_kinetics(void)const { return(this->kinetics); }; + const StorageBinListItem & Get_mix(void)const { return(this->mix); }; + const StorageBinListItem & Get_reaction(void)const { return(this->reaction); }; + const StorageBinListItem & Get_temperature(void)const { return(this->temperature); }; + const StorageBinListItem & Get_pressure(void)const { return(this->pressure); }; + const StorageBinListItem & Get_cell(void)const { return(this->cell); }; protected: // update GetAllItems() if StorageBinListItem is added/removed StorageBinListItem solution; @@ -59,6 +74,7 @@ protected: StorageBinListItem temperature; StorageBinListItem pressure; const static std::vector < std::string > vopts; + StorageBinListItem cell; // not included in GetAllItems }; diff --git a/dumper.h b/dumper.h index 7f953e74..dd95d3fa 100644 --- a/dumper.h +++ b/dumper.h @@ -46,6 +46,7 @@ public: void Set_on(bool tf) { this->on = tf; }; StorageBinList & Get_StorageBinList(void) { return this->binList; }; + const StorageBinList & Get_StorageBinList(void)const { return this->binList; }; void Set_StorageBinList(StorageBinList sbl) { this->binList = sbl; }; protected: std::string file_name; From 6ab5932f2cb6caf4b391e0a53c8bd9d22c73a8c5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 May 2013 21:45:38 +0000 Subject: [PATCH 0688/1077] Removed lower limit on mu. At low T, Kwater can be much smaller and pure water has lower ionic strength. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7745 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/model.cpp b/model.cpp index cf0e2577..ff862646 100644 --- a/model.cpp +++ b/model.cpp @@ -3617,7 +3617,7 @@ reset(void) (double) delta[i])); } d = mu_x + delta[i]; - if (d < 1e-7) + if (d < 1e-11) { delta[i] = sqrt(mu_calc * mu_x) - mu_x; mu_x = sqrt(mu_calc * mu_x); @@ -3626,10 +3626,10 @@ reset(void) { mu_x += delta[i]; } - if (mu_x <= 1e-8) - { - mu_x = 1e-8; - } + //if (mu_x <= 1e-8) + //{ + // mu_x = 1e-8; + //} /* Activity of water */ } else if (x[i]->type == AH2O) From 037b2bb818b0bc9b88956ea9029cca825e15c183 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 31 May 2013 05:39:52 +0000 Subject: [PATCH 0689/1077] added Set_append git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7747 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dumper.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dumper.h b/dumper.h index dd95d3fa..7ff0aac0 100644 --- a/dumper.h +++ b/dumper.h @@ -17,7 +17,8 @@ public: void SetAll(bool tf); std::string Get_file_name(void) { return(this->file_name); }; void Set_file_name(std::string fn) { this->file_name = fn; }; - bool Get_append(void) { return(this->append); }; + bool Get_append(void)const { return(this->append); }; + void Set_append(bool app) { this->append = app; }; bool Get_bool_solution(void) { return(this->binList.Get_solution().Get_defined()); }; bool Get_bool_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_defined()); }; bool Get_bool_exchange(void) { return(this->binList.Get_exchange().Get_defined()); }; @@ -35,7 +36,7 @@ public: std::set < int > & Get_pp_assemblage(void) { return(this->binList.Get_pp_assemblage().Get_numbers()); }; std::set < int > & Get_exchange(void) { return(this->binList.Get_exchange().Get_numbers()); }; std::set < int > & Get_surface(void) { return(this->binList.Get_surface().Get_numbers()); }; - std::set < int > & Get_ss_assemblage(void) { return(this->binList.Get_ss_assemblage().Get_numbers()); }; + std::set < int > & Get_ss_assemblage(void) { return(this->binList.Get_ss_assemblage().Get_numbers()); }; std::set < int > & Get_gas_phase(void) { return(this->binList.Get_gas_phase().Get_numbers()); }; std::set < int > & Get_kinetics(void) { return(this->binList.Get_kinetics().Get_numbers()); }; std::set < int > & Get_mix(void) { return(this->binList.Get_mix().Get_numbers()); }; From 8fdb7313f9cbe65a4bdc04002364cb95ff5b3aa5 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 3 Jun 2013 22:05:52 +0000 Subject: [PATCH 0690/1077] fixed bug in DELETE reported by laurin.wissmeier@web.de 2013-06-01 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7755 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBinList.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/StorageBinList.cpp b/StorageBinList.cpp index acb678f6..2311534f 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -147,6 +147,9 @@ bool StorageBinList::Read(CParser & parser) bool useLastLine(false); opt_save = CParser::OPT_DEFAULT; + // reset cells + this->cell.Clear(); + this->cell.Set_defined(false); for (;;) { int opt; From 87fea86961c85649413bce1805566298859fda64 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 3 Jun 2013 22:41:44 +0000 Subject: [PATCH 0691/1077] Tony's changes 6/1 for pr. Set gas volume to zero if fixed pressure and no moles of gas. Add test cases low_t (minimum mu), modify_zero (set total to zero in SOLUTION_MODIFY), and volume-zero (no moles of gas in fixed pressure gas phase, volume should be zero). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7756 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/print.cpp b/print.cpp index 24a176ad..decf25e8 100644 --- a/print.cpp +++ b/print.cpp @@ -59,7 +59,7 @@ set_pr_in_false(void) x[i]->phase->pr_in = false; } } - if (use.Get_gas_phase_in() && use.Get_gas_phase_ptr()) + if (use.Get_gas_phase_ptr()) { cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) @@ -83,15 +83,15 @@ print_all(void) * also print selected output to punch_file * Each routine is controlled by a variable in structure print. * print.all == FALSE will turn off all prints. - */ -/* - * Makes sorted list including all species for each valence state */ if (pr.all == FALSE) { set_pr_in_false(); return (OK); } +/* + * Makes sorted list including all species for each valence state + */ if (pr.surface == TRUE || pr.exchange == TRUE || pr.species == TRUE) { species_list_sort(); @@ -118,7 +118,8 @@ print_all(void) print_species(); print_alkalinity(); print_saturation_indices(); - set_pr_in_false(); + if (!pr.saturation_indices) + set_pr_in_false(); return (OK); } @@ -1265,6 +1266,7 @@ print_saturation_indices(void) } } } + phases[i]->pr_in = false; output_msg("\n"); } output_msg("\n\n"); @@ -2408,6 +2410,10 @@ punch_gas_phase(void) gas_phase_ptr->Set_volume(gas_phase_ptr->Get_v_m() * gas_unknown->moles); } } + else + { + gas_phase_ptr->Set_volume(0); + } } p = gas_phase_ptr->Get_total_p(); total_moles = gas_phase_ptr->Get_total_moles(); From f2cccb003a4a52be6bf9b73093c608e1117c21f1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 11 Jun 2013 16:51:20 +0000 Subject: [PATCH 0692/1077] Isotopes moles and molalities were not correct when mass of water was not equal to 1. Added test case 14C_isotopes; added to Makefile. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7763 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- isotopes.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/isotopes.cpp b/isotopes.cpp index 4f247cd6..107501c3 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -492,7 +492,7 @@ add_isotopes(cxxSolution &solution_ref) continue; if (master_isotope_ptr->minor_isotope == FALSE) { - total_moles = total(master_isotope_ptr->name); + total_moles = total(master_isotope_ptr->name) * mass_water_aq_x; calculate_isotope_moles(master_isotope_ptr->elt, &solution_ref, total_moles); } @@ -671,17 +671,17 @@ calculate_isotope_moles(struct element *elt_ptr, { total_o_x = m_major; } - cxxNameDouble nd(solution_ptr->Get_totals()); - cxxNameDouble::iterator iit = solution_ptr->Get_totals().begin(); - for ( ; iit != solution_ptr->Get_totals().end(); iit++) - { - master_isotope_ptr = master_isotope_search(iit->first.c_str()); - if (master_isotope_ptr == NULL) - continue; - if (master_isotope_ptr->elt != elt_ptr) - continue; - nd[iit->first] = master_isotope_ptr->moles; - } + //cxxNameDouble nd(solution_ptr->Get_totals()); + //cxxNameDouble::iterator iit = solution_ptr->Get_totals().begin(); + //for ( ; iit != solution_ptr->Get_totals().end(); iit++) + //{ + // master_isotope_ptr = master_isotope_search(iit->first.c_str()); + // if (master_isotope_ptr == NULL) + // continue; + // if (master_isotope_ptr->elt != elt_ptr) + // continue; + // nd[iit->first] = master_isotope_ptr->moles; + //} return (OK); } From 56ca1c2c0e089db106f4c96ce89d50fc543299ad Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 14 Jun 2013 22:35:45 +0000 Subject: [PATCH 0693/1077] Added Basic function STR_F$(x, w, d), where x is the number to format, w is the field width, and d is the number of decimal places. PRINT STR_F$(1/3, 10, 2) produces " 0.33" git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7765 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++- PBasic.h | 3 +- 2 files changed, 210 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index a42eb057..36e25148 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1541,7 +1541,10 @@ listtokens(FILE * f, tokenrec * l_buf) break; case toksoln_vol: output_msg("SOLN_VOL"); // volume of solution - break; + break; + case tokstr_f_: + output_msg("STR_F$"); + break; } l_buf = l_buf->next; } @@ -3212,8 +3215,210 @@ factor(struct LOC_exec * LINK) if (n.UU.sval == NULL) PhreeqcPtr->malloc_error(); numtostr(n.UU.sval, realfactor(LINK)); + + case tokstr_f_: + { + // left parenthesis + require(toklp, LINK); + + // set number + LDBLE nmbr; + nmbr = realexpr(LINK); + + // set total length + require(tokcomma, LINK); + int length = (int) realexpr(LINK); + + // set total length + require(tokcomma, LINK); + int width = (int) realexpr(LINK); + + // right parenthesis + require(tokrp, LINK); + + // determine whether decimal point is needed + int decimal_width = (width > 0) ? 1 : 0; + + // Make work space + int max_length = length < 256 ? 256 : length; + char *token = (char *) PhreeqcPtr->PHRQ_calloc(size_t (max_length + 1), sizeof(char)); + if (token == NULL) PhreeqcPtr->malloc_error(); + + // Write formatted number + int int_part = (int) nmbr; + sprintf(token, "%d", int_part); + std::string std_num; + if (strlen(token) > length - width - decimal_width || + length - width - decimal_width < 0) + { + // number too big for places left of the decimal or + // too many decimal places for length + // set a string for overflow + int i = 0; + std::string std_frac; + while (i < width && i < length) + { + std_frac.append("*"); + i++; + } + std::string std_dec; + if (i < length && width > 0) + { + std_dec = "."; + i++; + } + std::string std_int; + while (i < length) + { + std_int.append("*"); + i++; + } + std_num = std_int + std_dec + std_frac; + } + else + { + // print, no decimal if width is zero + sprintf(token, "%*.*f", length, width, nmbr); + std_num = token; + } + + // set function value + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(std_num.size() + 2, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + strcpy(n.UU.sval, std_num.c_str()); + n.stringval = true; + + // free work space + PhreeqcPtr->free_check_null(token); + + } break; +#ifdef SKIP + case tokstr_f_: + { + require(toklp, LINK); + + const char * orig_string = stringfactor(STR1, LINK); + char * strf = PhreeqcPtr->string_duplicate(orig_string); + PhreeqcPtr->squeeze_white(strf); + int l = strlen(strf); + + require(tokcomma, LINK); + + LDBLE nmbr; + nmbr = realexpr(LINK); + + require(tokrp, LINK); + + int decimal = -1; + int length = 0, width = 0; + + for (int i = 0; i < l; i++) + { + if (PhreeqcPtr->isamong(strf[i], "0123456789")) + { + continue; + } + else if (strf[i] == '.') + { + if (decimal < 0) + { + decimal = i; + } + else + { + snerr(": More than one decimal point in STR_F$ format."); + } + } + else + { + snerr(": STR_F$ format must be l.w, where l and w are integers."); + } + } + + char *tokenf = (char *) PhreeqcPtr->PHRQ_calloc(l + 1, sizeof(char)); + if (tokenf == NULL) PhreeqcPtr->malloc_error(); + if (decimal < 0) + { + length = atoi(strf); + } + else + { + std::string std_s(strf); + int p = std_s.find("."); + if (p > 0) + { + std::string std_l = std_s.substr(0,p); + length = atoi(std_l.c_str()); + } + std::string std_f = std_s.substr(p+1); + if (std_f.size() > 0) + { + width = atoi(std_f.c_str()); + } + } + + int int_part = (int) nmbr; + int decimal_width = (decimal >= 0) ? 1 : 0; + int max_length = length + width + decimal_width; + max_length = (max_length < 256) ? 256 : max_length; + char *token = (char *) PhreeqcPtr->PHRQ_calloc(max_length + 2, sizeof(char)); + if (token == NULL) PhreeqcPtr->malloc_error(); + + std::string std_num; + sprintf(token, "%*d", length, int_part); + if (strlen(token) > length) + { + if (nmbr >= pow(10, length) || nmbr <= -pow(10, length - 1)) + { + for (int i = 0; i < length; i++) + { + std_num.append("*"); + } + if (decimal >= 0) + { + std_num.append("."); + for (int i = 0; i < width; i++) + { + std_num.append("*"); + } + } + } + } + else + { + if (width > 0) + { + sprintf(token, "%*.*f", length + width + decimal_width, width, nmbr); + std_num = token; + } + else + { + sprintf(token, "%*d", length, int_part); + std_num = token; + if (decimal >= 0) + { + std_num.append("."); + } + } + } + + n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(std_num.size() + 2, sizeof(char)); + if (n.UU.sval == NULL) + PhreeqcPtr->malloc_error(); + + strcpy(n.UU.sval, std_num.c_str()); + + PhreeqcPtr->free_check_null(tokenf); + PhreeqcPtr->free_check_null(token); + + n.stringval = true; + PhreeqcPtr->free_check_null(strf); + } + break; +#endif case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -6475,7 +6680,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("soln_vol", PBasic::toksoln_vol), std::map::value_type("equi_delta", PBasic::tokequi_delta), std::map::value_type("kin_delta", PBasic::tokkin_delta), - std::map::value_type("kin_time", PBasic::tokkin_time) + std::map::value_type("kin_time", PBasic::tokkin_time), + std::map::value_type("str_f$", PBasic::tokstr_f_) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index d989297b..14b26cf1 100644 --- a/PBasic.h +++ b/PBasic.h @@ -313,7 +313,8 @@ public: toksoln_vol, tokequi_delta, tokkin_delta, - tokkin_time + tokkin_time, + tokstr_f_ }; #if !defined(PHREEQCI_GUI) From f1a98f8c3fa889a0637d3b663da2898a3c98ef61 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 14 Jun 2013 22:49:02 +0000 Subject: [PATCH 0694/1077] Decided to widen fields if necessary rather than print *** for STR_F$. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7766 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 36e25148..b8704ee9 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3248,34 +3248,34 @@ factor(struct LOC_exec * LINK) int int_part = (int) nmbr; sprintf(token, "%d", int_part); std::string std_num; - if (strlen(token) > length - width - decimal_width || - length - width - decimal_width < 0) - { - // number too big for places left of the decimal or - // too many decimal places for length - // set a string for overflow - int i = 0; - std::string std_frac; - while (i < width && i < length) - { - std_frac.append("*"); - i++; - } - std::string std_dec; - if (i < length && width > 0) - { - std_dec = "."; - i++; - } - std::string std_int; - while (i < length) - { - std_int.append("*"); - i++; - } - std_num = std_int + std_dec + std_frac; - } - else + //if (strlen(token) > length - width - decimal_width || + // length - width - decimal_width < 0) + //{ + // // number too big for places left of the decimal or + // // too many decimal places for length + // // set a string for overflow + // int i = 0; + // std::string std_frac; + // while (i < width && i < length) + // { + // std_frac.append("*"); + // i++; + // } + // std::string std_dec; + // if (i < length && width > 0) + // { + // std_dec = "."; + // i++; + // } + // std::string std_int; + // while (i < length) + // { + // std_int.append("*"); + // i++; + // } + // std_num = std_int + std_dec + std_frac; + //} + //else { // print, no decimal if width is zero sprintf(token, "%*.*f", length, width, nmbr); From 102ce319808b4f5de0fd98a97f9a2d8625d8fd35 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Jul 2013 19:04:05 +0000 Subject: [PATCH 0695/1077] Revised manual: Figure 8 had part B twice and was missing part A. Fixed in Version 3 in previous check in. Fixed in doc. Fixed in HTMLversion examples.fm, and reset cross refs so all .fm files changed. Replaced phreeqc3-232.gif with revised figure. Fixed system_total_si to return max SI, returned zero if max SI was less than zero. Added Basic function tokstr_e$ to format a number in exponential form. log10 not checked for positive argument, probably will print NaN if result is printed. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7782 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 176 +++++++++----------------------------------------- PBasic.h | 3 +- basicsubs.cpp | 1 + 3 files changed, 34 insertions(+), 146 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index b8704ee9..fc235266 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1545,6 +1545,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokstr_f_: output_msg("STR_F$"); break; + case tokstr_e_: + output_msg("STR_E$"); + break; } l_buf = l_buf->next; } @@ -3158,14 +3161,14 @@ factor(struct LOC_exec * LINK) case toklog10: { LDBLE t = realfactor(LINK); - if (t > 0.0) + //if (t > 0.0) { n.UU.val = log10(t); } - else - { - n.UU.val = 0; - } + //else + //{ + // n.UU.val = 0; + //} } break; case tokvm: @@ -3236,48 +3239,13 @@ factor(struct LOC_exec * LINK) // right parenthesis require(tokrp, LINK); - // determine whether decimal point is needed - int decimal_width = (width > 0) ? 1 : 0; - // Make work space int max_length = length < 256 ? 256 : length; char *token = (char *) PhreeqcPtr->PHRQ_calloc(size_t (max_length + 1), sizeof(char)); if (token == NULL) PhreeqcPtr->malloc_error(); - // Write formatted number - int int_part = (int) nmbr; - sprintf(token, "%d", int_part); std::string std_num; - //if (strlen(token) > length - width - decimal_width || - // length - width - decimal_width < 0) - //{ - // // number too big for places left of the decimal or - // // too many decimal places for length - // // set a string for overflow - // int i = 0; - // std::string std_frac; - // while (i < width && i < length) - // { - // std_frac.append("*"); - // i++; - // } - // std::string std_dec; - // if (i < length && width > 0) - // { - // std_dec = "."; - // i++; - // } - // std::string std_int; - // while (i < length) - // { - // std_int.append("*"); - // i++; - // } - // std_num = std_int + std_dec + std_frac; - //} - //else { - // print, no decimal if width is zero sprintf(token, "%*.*f", length, width, nmbr); std_num = token; } @@ -3291,134 +3259,51 @@ factor(struct LOC_exec * LINK) // free work space PhreeqcPtr->free_check_null(token); - } break; -#ifdef SKIP - case tokstr_f_: + case tokstr_e_: { + // left parenthesis require(toklp, LINK); - const char * orig_string = stringfactor(STR1, LINK); - char * strf = PhreeqcPtr->string_duplicate(orig_string); - PhreeqcPtr->squeeze_white(strf); - int l = strlen(strf); - - require(tokcomma, LINK); - + // set number LDBLE nmbr; nmbr = realexpr(LINK); + // set total length + require(tokcomma, LINK); + int length = (int) realexpr(LINK); + + // set total length + require(tokcomma, LINK); + int width = (int) realexpr(LINK); + + // right parenthesis require(tokrp, LINK); - int decimal = -1; - int length = 0, width = 0; - - for (int i = 0; i < l; i++) - { - if (PhreeqcPtr->isamong(strf[i], "0123456789")) - { - continue; - } - else if (strf[i] == '.') - { - if (decimal < 0) - { - decimal = i; - } - else - { - snerr(": More than one decimal point in STR_F$ format."); - } - } - else - { - snerr(": STR_F$ format must be l.w, where l and w are integers."); - } - } - - char *tokenf = (char *) PhreeqcPtr->PHRQ_calloc(l + 1, sizeof(char)); - if (tokenf == NULL) PhreeqcPtr->malloc_error(); - if (decimal < 0) - { - length = atoi(strf); - } - else - { - std::string std_s(strf); - int p = std_s.find("."); - if (p > 0) - { - std::string std_l = std_s.substr(0,p); - length = atoi(std_l.c_str()); - } - std::string std_f = std_s.substr(p+1); - if (std_f.size() > 0) - { - width = atoi(std_f.c_str()); - } - } - - int int_part = (int) nmbr; - int decimal_width = (decimal >= 0) ? 1 : 0; - int max_length = length + width + decimal_width; - max_length = (max_length < 256) ? 256 : max_length; - char *token = (char *) PhreeqcPtr->PHRQ_calloc(max_length + 2, sizeof(char)); + // Make work space + int max_length = length < 256 ? 256 : length; + char *token = (char *) PhreeqcPtr->PHRQ_calloc(size_t (max_length + 1), sizeof(char)); if (token == NULL) PhreeqcPtr->malloc_error(); std::string std_num; - sprintf(token, "%*d", length, int_part); - if (strlen(token) > length) { - if (nmbr >= pow(10, length) || nmbr <= -pow(10, length - 1)) - { - for (int i = 0; i < length; i++) - { - std_num.append("*"); - } - if (decimal >= 0) - { - std_num.append("."); - for (int i = 0; i < width; i++) - { - std_num.append("*"); - } - } - } - } - else - { - if (width > 0) - { - sprintf(token, "%*.*f", length + width + decimal_width, width, nmbr); - std_num = token; - } - else - { - sprintf(token, "%*d", length, int_part); - std_num = token; - if (decimal >= 0) - { - std_num.append("."); - } - } + sprintf(token, "%*.*e", length, width, nmbr); + std_num = token; } + // set function value n.UU.sval = (char *) PhreeqcPtr->PHRQ_calloc(std_num.size() + 2, sizeof(char)); if (n.UU.sval == NULL) PhreeqcPtr->malloc_error(); - strcpy(n.UU.sval, std_num.c_str()); - - PhreeqcPtr->free_check_null(tokenf); - PhreeqcPtr->free_check_null(token); - n.stringval = true; - PhreeqcPtr->free_check_null(strf); + + // free work space + PhreeqcPtr->free_check_null(token); } break; -#endif case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -6681,7 +6566,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("equi_delta", PBasic::tokequi_delta), std::map::value_type("kin_delta", PBasic::tokkin_delta), std::map::value_type("kin_time", PBasic::tokkin_time), - std::map::value_type("str_f$", PBasic::tokstr_f_) + std::map::value_type("str_f$", PBasic::tokstr_f_), + std::map::value_type("str_e$", PBasic::tokstr_e_) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 14b26cf1..aa6efddb 100644 --- a/PBasic.h +++ b/PBasic.h @@ -314,7 +314,8 @@ public: tokequi_delta, tokkin_delta, tokkin_time, - tokstr_f_ + tokstr_f_, + tokstr_e_ }; #if !defined(PHREEQCI_GUI) diff --git a/basicsubs.cpp b/basicsubs.cpp index 11a89192..aa7bc816 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2570,6 +2570,7 @@ system_total_si(void) struct rxn_token *rxn_ptr; char name[MAX_LENGTH]; + sys_tot = -999.9; for (i = 0; i < count_phases; i++) { if (phases[i]->in == FALSE || phases[i]->type != SOLID) From 6b36a70531100fbdfcab863ddb232764c7f51fa6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Jul 2013 19:51:24 +0000 Subject: [PATCH 0696/1077] Lost break after tokstr_ case git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7783 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PBasic.cpp b/PBasic.cpp index fc235266..e0de1884 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3218,6 +3218,7 @@ factor(struct LOC_exec * LINK) if (n.UU.sval == NULL) PhreeqcPtr->malloc_error(); numtostr(n.UU.sval, realfactor(LINK)); + break; case tokstr_f_: { From 6a0b9146b872538b6b224a0892a298ceab2608ef Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 16 Jul 2013 04:38:44 +0000 Subject: [PATCH 0697/1077] change req'd to compile in MinGW git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7822 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index e0de1884..a9282140 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1,4 +1,4 @@ -#if defined(WIN32) +#if defined(WIN32) && !defined(__GNUC__) #include #if defined(PHREEQCI_GUI) #include "../../resource.h" From 7d90df4e695820d95942a9911feb2e3918f21e6e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 16 Jul 2013 14:38:04 +0000 Subject: [PATCH 0698/1077] Pointers for MacInnis scaling were not reset when -B0 was redefined with Cl- K+ order. Now check for either order. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7825 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index f20de9e8..63382dbd 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -204,8 +204,10 @@ pitzer_tidy(void) IC = ISPEC(string2); for (i = 0; i < count_pitz_param; i++) { - if (pitz_params[i]->species[0] == string1 && - pitz_params[i]->species[1] == string2) + if ((pitz_params[i]->species[0] == string1 && + pitz_params[i]->species[1] == string2) || + (pitz_params[i]->species[0] == string2 && + pitz_params[i]->species[1] == string1) ) { switch (pitz_params[i]->type) { From ff764f3fe563daf68537065985ca13c02b0eab4e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 16 Jul 2013 16:37:19 +0000 Subject: [PATCH 0699/1077] Added species_formula("CaOH+", count, elt$, coef) returns Ca 1 O 1 H 1 charge 1 in elt$ and coef. count is 4. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7827 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++- PBasic.h | 1 + Phreeqc.h | 1 + basicsubs.cpp | 29 ++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index a9282140..7fcbf53e 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1496,6 +1496,9 @@ listtokens(FILE * f, tokenrec * l_buf) break; case tokphase_formula: output_msg("PHASE_FORMULA"); + break; + case tokspecies_formula: + output_msg("SPECIES_FORMULA"); break; case toklist_s_s: output_msg("LIST_S_S"); @@ -2796,7 +2799,106 @@ factor(struct LOC_exec * LINK) } break; } + case tokspecies_formula: + { + require(toklp, LINK); + std::string species_name(stringfactor(STR1, LINK)); + varrec *elts_varrec = NULL, *coef_varrec = NULL; + cxxNameDouble stoichiometry; + /* + * Parse arguments + */ + //require(tokcomma, LINK); + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + //else + //{ + // arg_num = 1; + //} + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + std::string type = PhreeqcPtr->species_formula(species_name, stoichiometry); + + // put type as return value + n.stringval = true; + n.UU.sval = PhreeqcPtr->string_duplicate(type.c_str()); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + + } + break; + } case tokrxn: if (PhreeqcPtr->state == REACTION || PhreeqcPtr->state == ADVECTION || @@ -6568,7 +6670,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("kin_delta", PBasic::tokkin_delta), std::map::value_type("kin_time", PBasic::tokkin_time), std::map::value_type("str_f$", PBasic::tokstr_f_), - std::map::value_type("str_e$", PBasic::tokstr_e_) + std::map::value_type("str_e$", PBasic::tokstr_e_), + std::map::value_type("species_formula", PBasic::tokspecies_formula) + }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index aa6efddb..2ca5cd96 100644 --- a/PBasic.h +++ b/PBasic.h @@ -295,6 +295,7 @@ public: tokceil, tokfloor, tokphase_formula, + tokspecies_formula, toklist_s_s, tokpr_p, tokpr_phi, diff --git a/Phreeqc.h b/Phreeqc.h index dd37e10f..724012c4 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -128,6 +128,7 @@ public: LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); + std::string species_formula(std::string phase_name, cxxNameDouble &stoichiometry); LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); int system_total_elements(void); int system_total_si(void); diff --git a/basicsubs.cpp b/basicsubs.cpp index aa7bc816..459e92db 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2437,6 +2437,35 @@ phase_formula(std::string phase_name, cxxNameDouble &stoichiometry) return (formula); } +/* ---------------------------------------------------------------------- */ +std::string Phreeqc:: +species_formula(std::string phase_name, cxxNameDouble &stoichiometry) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns formula of mineral + * Also returns arrays of elements and stoichiometry in elts_arg and coef_arg + */ + stoichiometry.clear(); + std::string formula; + formula = "aq"; + struct species *s_ptr = s_search(phase_name.c_str()); + if (s_ptr != NULL) + { + cxxNameDouble nd(s_ptr->next_elt); + stoichiometry = nd; + stoichiometry["charge"] = s_ptr->z; + if (s_ptr->type == EX) + { + formula = "ex"; + } + else if (s_ptr->type == SURF) + { + formula = "surf"; + } + } + return (formula); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: From 4b643b866b5384c23766636de4201af2047c5fcc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 16 Jul 2013 17:10:07 +0000 Subject: [PATCH 0700/1077] Finishing touches on species_formula. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7828 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 127 ++++++++++++++++++++++---------------------------- basicsubs.cpp | 6 ++- 2 files changed, 62 insertions(+), 71 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 7fcbf53e..97e614fb 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2808,42 +2808,32 @@ factor(struct LOC_exec * LINK) /* * Parse arguments */ - //require(tokcomma, LINK); - if (LINK->t != NULL && LINK->t->kind == tokcomma) - { - LINK->t = LINK->t->next; - count_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) - snerr(": Cannot find count variable"); + require(tokcomma, LINK); - /* return number of names of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - elts_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) - snerr(": Cannot find element string variable"); + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; - /* return coefficients of species */ - LINK->t = LINK->t->next; - require(tokcomma, LINK); - coef_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) - snerr(": Cannot find coefficient variable"); - LINK->t = LINK->t->next; - arg_num = 4; - } - //else - //{ - // arg_num = 1; - //} require(tokrp, LINK); - if (arg_num > 1) - { - free_dim_stringvar(elts_varrec); - PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); - coef_varrec->UU.U0.arr = NULL; - } + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; /* * Call subroutine */ @@ -2857,46 +2847,43 @@ factor(struct LOC_exec * LINK) * fill in varrec structure */ - if (arg_num > 1) + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) { - size_t count = stoichiometry.size(); - *count_varrec->UU.U0.val = (LDBLE) count; - /* - * malloc space - */ - elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); - if (elts_varrec->UU.U1.sarr == NULL) - PhreeqcPtr->malloc_error(); - coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); - if (coef_varrec->UU.U0.arr == NULL) - PhreeqcPtr->malloc_error(); - - // first position not used - elts_varrec->UU.U1.sarr[0] = NULL; - coef_varrec->UU.U0.arr[0] = 0; - - // set dims for Basic array - for (i = 0; i < maxdims; i++) - { - elts_varrec->dims[i] = 0; - coef_varrec->dims[i] = 0; - } - // set dims for first dimension and number of dims - elts_varrec->dims[0] = (long) (count + 1); - coef_varrec->dims[0] = (long) (count + 1); - elts_varrec->numdims = 1; - coef_varrec->numdims = 1; - - // fill in arrays - i = 1; - for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) - { - elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); - coef_varrec->UU.U0.arr[i] = it->second; - i++; - } - + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + break; } case tokrxn: diff --git a/basicsubs.cpp b/basicsubs.cpp index 459e92db..64edd288 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2448,7 +2448,7 @@ species_formula(std::string phase_name, cxxNameDouble &stoichiometry) */ stoichiometry.clear(); std::string formula; - formula = "aq"; + formula = "none"; struct species *s_ptr = s_search(phase_name.c_str()); if (s_ptr != NULL) { @@ -2463,6 +2463,10 @@ species_formula(std::string phase_name, cxxNameDouble &stoichiometry) { formula = "surf"; } + else + { + formula = "aq"; + } } return (formula); } From a03d2ae87e373e536cfdef99605fb42c0d77068a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 16 Jul 2013 19:25:14 +0000 Subject: [PATCH 0701/1077] Added f = EQ_FRAC("AlX3", eq, x$) Also added synonyms PHASE_FORMULA$ and SPECIES_FORMULA$. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7829 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++--- PBasic.h | 5 +++- Phreeqc.h | 1 + basicsubs.cpp | 31 +++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 97e614fb..56ac7f9e 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1495,10 +1495,12 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("ISO_UNIT"); break; case tokphase_formula: - output_msg("PHASE_FORMULA"); + case tokphase_formula_: + output_msg("PHASE_FORMULA$"); break; case tokspecies_formula: - output_msg("SPECIES_FORMULA"); + case tokspecies_formula_: + output_msg("SPECIES_FORMULA$"); break; case toklist_s_s: output_msg("LIST_S_S"); @@ -1551,6 +1553,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokstr_e_: output_msg("STR_E$"); break; + case tokeq_frac: + output_msg("EQ_FRAC"); + break; } l_buf = l_buf->next; } @@ -2695,6 +2700,7 @@ factor(struct LOC_exec * LINK) } case tokphase_formula: + case tokphase_formula_: { require(toklp, LINK); std::string phase_name(stringfactor(STR1, LINK)); @@ -2800,6 +2806,7 @@ factor(struct LOC_exec * LINK) break; } case tokspecies_formula: + case tokspecies_formula_: { require(toklp, LINK); std::string species_name(stringfactor(STR1, LINK)); @@ -3394,6 +3401,58 @@ factor(struct LOC_exec * LINK) PhreeqcPtr->free_check_null(token); } break; + case tokeq_frac: + { + // left parenthesis + require(toklp, LINK); + + // species name + std::string species_name(stringfactor(STR1, LINK)); + + require(tokcomma, LINK); + + // equivalents + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find equivalents variable"); + + LINK->t = LINK->t->next; + require(tokcomma, LINK); + + // exchange or surface element + varrec *elt_varrec = NULL; + elt_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elt_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + free_dim_stringvar(elt_varrec); + + // right parenthesis + LINK->t = LINK->t->next; + require(tokrp, LINK); + + // Make work space + //int max_length = length < 256 ? 256 : length; + //char *token = (char *) PhreeqcPtr->PHRQ_calloc(size_t (max_length + 1), sizeof(char)); + //if (token == NULL) PhreeqcPtr->malloc_error(); + + // set function value + LDBLE eq; + std::string elt_name; + + // return equivalent fraction + n.UU.val = PhreeqcPtr->equivalent_fraction(species_name.c_str(), &eq, elt_name); + + // set equivalents + *count_varrec->UU.U0.val = eq; + + // set element name + size_t l = elt_name.size(); + l = l < 256 ? 256 : l + 1; + char * token = (char *) PhreeqcPtr->PHRQ_malloc( l, sizeof(char)); + strcpy(token, elt_name.c_str()); + *elt_varrec->UU.U1.sval = token; + } + break; case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -6638,6 +6697,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("iso", PBasic::tokiso), std::map::value_type("iso_unit", PBasic::tokiso_unit), std::map::value_type("phase_formula", PBasic::tokphase_formula), + std::map::value_type("phase_formula$", PBasic::tokphase_formula_), std::map::value_type("list_s_s", PBasic::toklist_s_s), std::map::value_type("pr_p", PBasic::tokpr_p), std::map::value_type("pr_phi", PBasic::tokpr_phi), @@ -6658,7 +6718,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("kin_time", PBasic::tokkin_time), std::map::value_type("str_f$", PBasic::tokstr_f_), std::map::value_type("str_e$", PBasic::tokstr_e_), - std::map::value_type("species_formula", PBasic::tokspecies_formula) + std::map::value_type("species_formula", PBasic::tokspecies_formula), + std::map::value_type("species_formula$", PBasic::tokspecies_formula_), + std::map::value_type("eq_frac", PBasic::tokeq_frac) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 2ca5cd96..aae6844d 100644 --- a/PBasic.h +++ b/PBasic.h @@ -295,7 +295,9 @@ public: tokceil, tokfloor, tokphase_formula, + tokphase_formula_, tokspecies_formula, + tokspecies_formula_, toklist_s_s, tokpr_p, tokpr_phi, @@ -316,7 +318,8 @@ public: tokkin_delta, tokkin_time, tokstr_f_, - tokstr_e_ + tokstr_e_, + tokeq_frac }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 724012c4..d0b636f6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -98,6 +98,7 @@ public: LDBLE diff_layer_total(const char *total_name, const char *surface_name); LDBLE equi_phase(const char *phase_name); LDBLE equi_phase_delta(const char *phase_name); + LDBLE equivalent_fraction(const char *name, LDBLE *eq, std::string &elt_name); LDBLE find_gas_comp(const char *gas_comp_name); LDBLE find_gas_p(void); LDBLE find_gas_vm(void); diff --git a/basicsubs.cpp b/basicsubs.cpp index 64edd288..e83fac5d 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -841,6 +841,37 @@ equi_phase_delta(const char *phase_name) } return (0); } + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +equivalent_fraction(const char *name, LDBLE *eq, std::string &elt_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr = s_search(name); + *eq = 0; + elt_name.clear(); + LDBLE f = 0; + if (s_ptr != NULL && (s_ptr->type == EX || s_ptr->type == SURF)) + { + *eq = s_ptr->equiv; + struct elt_list *next_elt; + LDBLE tot=0.0; + for (next_elt = s_ptr->next_elt; next_elt->elt != NULL; next_elt++) + { + if (next_elt->elt->master->s->type == SURF || + next_elt->elt->master->s->type == EX) + { + tot = total_mole(next_elt->elt->name); + elt_name = next_elt->elt->name; + } + } + if (s_ptr->in == TRUE && tot > 0.0) + { + f = s_ptr->moles * s_ptr->equiv / tot; + } + } + return f; +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: find_gas_comp(const char *gas_comp_name) From 7848242e28d627c15c72cf7ea9add94a765219b9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 17 Jul 2013 21:15:01 +0000 Subject: [PATCH 0702/1077] Fixed error for malloc introduced in recent Basic function. Fixed error with Pitzer paramenters that were not recalculated with a change in pressure. Parameters depend on density of water I think. Also changed SIT, although I am not sure the parameters have a pressure dependence. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7837 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 6 +++--- Phreeqc.cpp | 3 ++- Phreeqc.h | 2 +- pitzer.cpp | 5 ++++- sit.cpp | 6 +++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 56ac7f9e..a9de1a81 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3440,15 +3440,15 @@ factor(struct LOC_exec * LINK) std::string elt_name; // return equivalent fraction - n.UU.val = PhreeqcPtr->equivalent_fraction(species_name.c_str(), &eq, elt_name); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->equivalent_fraction(species_name.c_str(), &eq, elt_name); // set equivalents - *count_varrec->UU.U0.val = eq; + *count_varrec->UU.U0.val = (parse_all) ? 1 : eq; // set element name size_t l = elt_name.size(); l = l < 256 ? 256 : l + 1; - char * token = (char *) PhreeqcPtr->PHRQ_malloc( l, sizeof(char)); + char * token = (char *) PhreeqcPtr->PHRQ_malloc( l * sizeof(char)); strcpy(token, elt_name.c_str()); *elt_varrec->UU.U1.sval = token; } diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 36fbc627..528227f7 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -986,7 +986,8 @@ void Phreeqc::init(void) count_theta_param = 0; max_theta_param = 100; use_etheta = TRUE; - OTEMP = 0.0; + OTEMP = -100.; + OPRESS = -100.; A0 = 0; spec = NULL; cations = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index d0b636f6..ac0d05bc 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1799,7 +1799,7 @@ protected: struct theta_param **theta_params; int count_theta_param, max_theta_param; int use_etheta; - LDBLE OTEMP; + LDBLE OTEMP, OPRESS; LDBLE A0; struct species **spec, **cations, **anions, **neutrals; int count_cations, count_anions, count_neutrals; diff --git a/pitzer.cpp b/pitzer.cpp index 63382dbd..35124292 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -28,6 +28,7 @@ pitzer_init(void) ICON = TRUE; OTEMP = -100.; + OPRESS = -100.; for (i = 0; i < 23; i++) { BK[i] = 0.0; @@ -58,6 +59,7 @@ pitzer_tidy(void) * Ensure new parameters are calculated */ OTEMP = -100.; + OPRESS = -100.; /* * allocate pointers to species structures */ @@ -740,9 +742,10 @@ C int i; LDBLE TR = 298.15; - if (fabs(TK - OTEMP) < 0.001e0) + if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.001) return OK; OTEMP = TK; + OPRESS = patm_x; /* C Set DW0 */ diff --git a/sit.cpp b/sit.cpp index ea376c0c..60beb5bf 100644 --- a/sit.cpp +++ b/sit.cpp @@ -17,6 +17,7 @@ sit_init(void) space((void **) ((void *) &sit_params), INIT, &max_sit_param, sizeof(struct pitz_param *)); OTEMP = -100.; + OPRESS = -100.; return OK; } @@ -33,6 +34,7 @@ sit_tidy(void) * Ensure new parameters are calculated */ OTEMP = -100.; + OPRESS = -100.; /* * allocate pointers to species structures */ @@ -1333,8 +1335,10 @@ C int i; LDBLE TR = 298.15; - if (fabs(TK - OTEMP) < 0.001e0) return OK; + if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.001) + return OK; OTEMP = TK; + OPRESS = patm_x; /* C Set DW0 */ From 6b8ccd828c1203a14e35bc9884b71d4fcd57bbc4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 17 Jul 2013 21:52:44 +0000 Subject: [PATCH 0703/1077] latest tests 7837; some Linux warnings in src git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7838 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 2 -- model.cpp | 8 -------- prep.cpp | 2 -- print.cpp | 2 -- 4 files changed, 14 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index e83fac5d..e9d2539b 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2951,7 +2951,6 @@ system_total_elt(const char *total_name) */ if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < count_unknowns; i++) { if (x[i]->type != PP) @@ -3225,7 +3224,6 @@ system_total_elt_secondary(const char *total_name) */ if (use.Get_pp_assemblage_in() == TRUE && use.Get_pp_assemblage_ptr() != NULL) { - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < count_unknowns; i++) { if (x[i]->type != PP) diff --git a/model.cpp b/model.cpp index ff862646..b75e71e5 100644 --- a/model.cpp +++ b/model.cpp @@ -406,7 +406,6 @@ check_residuals(void) } else if (x[i]->type == PP) { - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; if (comp_ptr->Get_add_formula().size() == 0) @@ -3088,7 +3087,6 @@ reset(void) /* * Calculate interphase mass transfers */ - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); cxxPPassemblageComp * comp_ptr; step_up = log(step_size_now); @@ -3799,9 +3797,6 @@ reset(void) x[i]->moles -= delta[i]; if (x[i]->moles < MIN_TOTAL_SS && calculating_deriv == FALSE) x[i]->moles = MIN_TOTAL_SS; - //cxxSS *ss_ptr = use.Get_ss_assemblage_ptr()->Find(x[i]->ss_name); - cxxSS *ss_ptr = (cxxSS *) x[i]->ss_ptr; - //cxxSScomp *comp_ptr = ss_ptr->Find(x[i]->ss_comp_name); cxxSScomp *comp_ptr = (cxxSScomp *) x[i]->ss_comp_ptr; comp_ptr->Set_moles(x[i]->moles); /* Pitzer gamma */ @@ -3873,7 +3868,6 @@ residuals(void) LDBLE sigmaddl, negfpsirt; int print_fail; std::vector cd_psi; - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); print_fail = FALSE; sum_residual = 0.0; sigmaddl = 0; @@ -5646,7 +5640,6 @@ set_inert_moles(void) { int j; if (use.Get_pp_assemblage_ptr() == NULL) return; - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (j = 0; j < count_unknowns; j++) { @@ -5667,7 +5660,6 @@ unset_inert_moles() { int j; if (use.Get_pp_assemblage_ptr() == NULL) return; - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (j = 0; j < count_unknowns; j++) { if (x[j]->type != PP) continue; diff --git a/prep.cpp b/prep.cpp index 221fd614..125e3658 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1435,7 +1435,6 @@ build_pure_phases(void) if (pure_phase_unknown == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Calculate inverse saturation index */ @@ -4114,7 +4113,6 @@ adjust_setup_pure_phases(void) if (use.Get_pp_assemblage_ptr() == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Adjust si for gases */ diff --git a/print.cpp b/print.cpp index decf25e8..8509fbbd 100644 --- a/print.cpp +++ b/print.cpp @@ -1291,7 +1291,6 @@ print_pp_assemblage(void) return (OK); if (pure_phase_unknown == NULL) return (OK); - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); /* * Print heading */ @@ -2659,7 +2658,6 @@ punch_pp_assemblage(void) */ int i, j; LDBLE moles, delta_moles; - cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); for (i = 0; i < punch.count_pure_phases; i++) { delta_moles = 0; From 7da9c7b1e366efea95ac22d08ed0f54353791f27 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 18 Jul 2013 15:54:14 +0000 Subject: [PATCH 0704/1077] Merge Tony's changes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7844 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 3 ++- pitzer.cpp | 19 ++++++++++++------- sit.cpp | 10 +++++----- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 528227f7..6e64c393 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -2276,7 +2276,8 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) count_theta_param = 0; max_theta_param = 100; use_etheta = TRUE; - OTEMP = 0.0; + OTEMP = -100.0; + OPRESS = -100.0; A0 = 0; spec = NULL; cations = NULL; diff --git a/pitzer.cpp b/pitzer.cpp index 35124292..28783dfd 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -199,7 +199,7 @@ pitzer_tidy(void) } } /* - * McGinnis data + * MacInnes data */ string1 = string_hsave("K+"); string2 = string_hsave("Cl-"); @@ -742,10 +742,8 @@ C int i; LDBLE TR = 298.15; - if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.001) + if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.1) return OK; - OTEMP = TK; - OPRESS = patm_x; /* C Set DW0 */ @@ -758,8 +756,11 @@ C Set DW0 { calc_pitz_param(pitz_params[i], TK, TR); } - DC0 = DC(TK); - if (fabs(TK - TR) < 0.001e0) + //DC0 = DC(TK); + calc_dielectrics(TK - 273.15, patm_x); + DC0 = eps_r; + // Only at 1.0 atm??? if (fabs(TK - TR) < 0.001 && fabs(patm_x - OPRESS) < 0.1) + if (fabs(TK - TR) < 0.001 && fabs(patm_x - 1.0) < 0.1) { A0 = 0.392e0; //Cite Jonathan Toner @@ -768,10 +769,14 @@ C Set DW0 } else { - DC0 = DC(TK); + //DC0 = DC(TK); + calc_dielectrics(TK - 273.15, patm_x); + DC0 = eps_r; A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); /*A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ } + OTEMP = TK; + OPRESS = patm_x; return OK; } diff --git a/sit.cpp b/sit.cpp index 60beb5bf..50491bf1 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1335,10 +1335,7 @@ C int i; LDBLE TR = 298.15; - if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.001) - return OK; - OTEMP = TK; - OPRESS = patm_x; + if (fabs(TK - OTEMP) < 0.001 && fabs(patm_x - OPRESS) < 0.1) return OK; /* C Set DW0 */ @@ -1348,7 +1345,8 @@ C Set DW0 calc_sit_param(sit_params[i], TK, TR); } DC0 = DC(TK); - if (fabs(TK - TR) < 0.001e0) + // Only at 1.0 atm??? if (fabs(TK - TR) < 0.001 && fabs(patm_x - OPRESS) < 0.1) + if (fabs(TK - TR) < 0.001 && fabs(patm_x - 1.0) < 0.1) { sit_A0 = 0.392e0; } @@ -1358,5 +1356,7 @@ C Set DW0 sit_A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); /*sit_A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ } + OTEMP = TK; + OPRESS = patm_x; return OK; } From 79698b010d75a92540e9f0fe7e7a9c4e8f3de885 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 23 Jul 2013 14:51:26 +0000 Subject: [PATCH 0705/1077] Tony's fixes for Pitzer, High Pressure is still not right, will require more fitting. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7854 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- pitzer.cpp | 27 +-------------------------- sit.cpp | 18 ++++-------------- utilities.cpp | 20 +++++++++++++------- 4 files changed, 19 insertions(+), 48 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index ac0d05bc..6df8472e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1677,7 +1677,7 @@ protected: int count_sys, max_sys; LDBLE sys_tot; - LDBLE V_solutes, rho_0, kappa_0, p_sat/*, ah2o_x0*/; + LDBLE V_solutes, rho_0, rho_0_sat, kappa_0, p_sat/*, ah2o_x0*/; LDBLE eps_r; // relative dielectric permittivity LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume diff --git a/pitzer.cpp b/pitzer.cpp index 28783dfd..f70e319e 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -738,43 +738,18 @@ C C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER C */ - LDBLE DC0; int i; LDBLE TR = 298.15; - if (fabs(TK - OTEMP) < 0.001e0 && fabs(patm_x - OPRESS) < 0.1) + if (fabs(TK - OTEMP) < 0.001 && fabs(patm_x - OPRESS) < 0.1) return OK; -/* -C Set DW0 -*/ - //DW(TK); - //rho_0 = DW0; - //patm_x = VP; DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); VP = patm_x; for (i = 0; i < count_pitz_param; i++) { calc_pitz_param(pitz_params[i], TK, TR); } - //DC0 = DC(TK); calc_dielectrics(TK - 273.15, patm_x); - DC0 = eps_r; - // Only at 1.0 atm??? if (fabs(TK - TR) < 0.001 && fabs(patm_x - OPRESS) < 0.1) - if (fabs(TK - TR) < 0.001 && fabs(patm_x - 1.0) < 0.1) - { - A0 = 0.392e0; - //Cite Jonathan Toner - //A0 = 86.6836498e0 + (TK)*0.084879594e0 - (0.0000888785e0)*pow(TK,(LDBLE) 2.0e0) + (4.88096e-8)*pow(TK,(LDBLE) 3.0e0) - (1327.31477e0/(TK)) - 17.6460172e0*log(TK); - - } - else - { - //DC0 = DC(TK); - calc_dielectrics(TK - 273.15, patm_x); - DC0 = eps_r; - A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); - /*A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ - } OTEMP = TK; OPRESS = patm_x; return OK; diff --git a/sit.cpp b/sit.cpp index 50491bf1..734bb3d2 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1331,7 +1331,6 @@ C C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER C */ - LDBLE DC0; int i; LDBLE TR = 298.15; @@ -1339,23 +1338,14 @@ C /* C Set DW0 */ - DW(TK); + DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); + VP = patm_x; for (i = 0; i < count_sit_param; i++) { calc_sit_param(sit_params[i], TK, TR); } - DC0 = DC(TK); - // Only at 1.0 atm??? if (fabs(TK - TR) < 0.001 && fabs(patm_x - OPRESS) < 0.1) - if (fabs(TK - TR) < 0.001 && fabs(patm_x - 1.0) < 0.1) - { - sit_A0 = 0.392e0; - } - else - { - DC0 = DC(TK); - sit_A0 = 1.400684e6 * sqrt(DW0 / (pow((DC0 * TK), (LDBLE) 3.0e0))); - /*sit_A0=1.400684D6*(DW0/(DC0*TK)**3.0D0)**0.5D0 */ - } + calc_dielectrics(TK - 273.15, patm_x); + sit_A0 = A0; OTEMP = TK; OPRESS = patm_x; return OK; diff --git a/utilities.cpp b/utilities.cpp index a37846b3..54fefcf5 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -108,7 +108,7 @@ calc_rho_0(LDBLE tc, LDBLE pa) LDBLE Tc = 647.096, th = 1 - T / Tc; LDBLE b1 = 1.99274064, b2 = 1.09965342, b3 = -0.510839303, b4 = -1.75493479, b5 = -45.5170352, b6 = -6.7469445e5; - rho_0 = 322.0 * (1.0 + b1 * pow(th, (LDBLE) 1./3.) + b2 * pow(th, (LDBLE) 2./3.) + b3 * pow(th, (LDBLE) 5./3.) +\ + rho_0_sat = 322.0 * (1.0 + b1 * pow(th, (LDBLE) 1./3.) + b2 * pow(th, (LDBLE) 2./3.) + b3 * pow(th, (LDBLE) 5./3.) +\ b4 * pow(th, (LDBLE) 16./3.) + b5 * pow(th, (LDBLE) 43./3.) + b6 * pow(th, (LDBLE) 110./3)); //pressure... LDBLE p0 = 5.1880000E-02 + tc * (-4.1885519E-04 + tc * ( 6.6780748E-06 + tc * (-3.6648699E-08 + tc * 8.3501912E-11))); @@ -128,7 +128,7 @@ calc_rho_0(LDBLE tc, LDBLE pa) if (!use.Get_gas_phase_in()) patm_x = pa; pa -= (p_sat - 1e-6); - rho_0 += pa * (p0 + pa * (p1 + pa * (p2 + sqrt(pa) * p3))); + rho_0 = rho_0_sat + pa * (p0 + pa * (p1 + pa * (p2 + sqrt(pa) * p3))); if (rho_0 < 0.01) rho_0 = 0.01; @@ -159,8 +159,8 @@ calc_dielectrics(LDBLE tc, LDBLE pa) LDBLE d1000 = u1 * exp(T * (u2 + T * u3)); // relative dielectric constant at 1000 bar LDBLE c = u4 + u5 / (u6 + T); LDBLE b = u7 + u8 / T + u9 * T; - pa *= 1.01325; // pa in bar - eps_r = d1000 + c * log((b + pa) / (b + 1e3)); // relative dielectric constant + LDBLE pb = pa * 1.01325; // pa in bar + eps_r = d1000 + c * log((b + pb) / (b + 1e3)); // relative dielectric constant /* qe^2 / (eps_r * kB * T) = 4.803204e-10**2 / 1.38065e-16 / (eps_r * T) = 1.671008e-3 (esu^2 / (erg/K)) / (eps_r * T) */ @@ -170,14 +170,20 @@ calc_dielectrics(LDBLE tc, LDBLE pa) DH_A = DH_B * e2_DkT / (2. * LOG_10); //(mol/kg)^-0.5 + /* A0 in pitzer */ + if (pitzer_model || sit_model) + { + A0 = DH_B * e2_DkT / 6.0; + } + /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ - DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pa) * 1.01325 / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 + DH_Av = DH_B * e2_DkT * R_LITER_ATM * 1e3 * T * (c / (b + pb) * 1.01325 / eps_r - kappa_0 / 3.); // (cm3/mol)(mol/kg)^-0.5 DH_B /= 1e8; // kappa, 1/Angstrom(mol/kg)^-0.5 /* the Born functions, * 41.84 to give molal volumes in cm3/mol... */ ZBrn = (- 1 / eps_r + 1.0) * 41.84004; - QBrn = c / (b + pa) / eps_r / eps_r * 41.84004; + QBrn = c / (b + pb) / eps_r / eps_r * 41.84004; /* dgdP from subroutine gShok2 in supcrt92, g is neglected here (at tc < 300)... and, dgdP is small. Better, adapt Wref to experimental Vm's */ dgdP = 0; @@ -192,7 +198,7 @@ calc_dielectrics(LDBLE tc, LDBLE pa) // dgdP = - sa * sb * pow(1.0 - rho_0, sb - 1.0) * rho_0 * kappa_0 / 1.01325; // LDBLE ft = pow((tc - 155.0)/300.0, 4.8) + csc[1] * pow((tc - 155.0)/300.0, 16.0); - // LDBLE dfdP = ft * (-3.0 * csc[2] * pow(1000.0 - pa, 2) - 4.0 * csc[3] * pow(1000.0 - pa, 3)); + // LDBLE dfdP = ft * (-3.0 * csc[2] * pow(1000.0 - pb, 2) - 4.0 * csc[3] * pow(1000.0 - pb, 3)); // dgdP -= dfdP; //} From d26571fbd74ca75ea2256714708db6d87400e5ad Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 23 Jul 2013 14:52:33 +0000 Subject: [PATCH 0706/1077] Tony cleaned up XI in Pitzer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7855 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index f70e319e..c6ffaaa1 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -835,7 +835,7 @@ pitzer(void) CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, BMXPHI, PHIPHI, AW, A, B; */ - LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + LDBLE CONV, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, B; LDBLE I, TK; int LNEUT; @@ -845,7 +845,6 @@ pitzer(void) C */ CONV = 1.0 / log(10.0); - XI = 0.0e0; XX = 0.0e0; OSUM = 0.0e0; LNEUT = FALSE; @@ -898,12 +897,9 @@ pitzer(void) if (IPRSNT[i] == TRUE) { XX = XX + M[i] * fabs(spec[i]->z); - XI = XI + M[i] * spec[i]->z * spec[i]->z; OSUM = OSUM + M[i]; } } - I = XI / 2.0e0; - I = mu_x; // Added equation for MU /* C C EQUATION (8) From e92025752e5c0fb15f081305f0f32ed079d66c07 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 26 Jul 2013 22:36:39 +0000 Subject: [PATCH 0707/1077] Caught SS definition errors if 2 components not defined. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7857 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index 9e6f98db..8399bac8 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -4242,6 +4242,15 @@ ss_calc_a0_a1(cxxSS *ss_ptr) tol = 1e-6; rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; + if (ss_ptr->Get_ss_comps().size() < 2) + { + input_error++; + error_string = sformatf( + "Two components were not defined for %s solid solution", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + return (ERROR); + } cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); int k; From 276322a936d5f70470eec1b4e56dbd76715d5f36 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 31 Jul 2013 19:26:34 +0000 Subject: [PATCH 0708/1077] Have multiple SELECTED_OUTPUT working. Need to have multiple USER_PUNCH. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7864 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 12 +- PHRQ_io_output.cpp | 2 +- Phreeqc.cpp | 15 +- Phreeqc.h | 10 +- SelectedOutput.cpp | 79 ++++++++ SelectedOutput.h | 108 +++++++++++ global_structures.h | 3 +- inverse.cpp | 303 ++++++++++++++++-------------- isotopes.cpp | 48 ++--- mainsubs.cpp | 3 +- print.cpp | 260 ++++++++++++++------------ read.cpp | 439 +++++++++++++++++++++++++++++++++++++++++++ readtr.cpp | 171 +++++++++-------- structures.cpp | 10 +- tidy.cpp | 446 +++++++++++++++++++++++++++++++++++++++++++- 15 files changed, 1530 insertions(+), 379 deletions(-) create mode 100644 SelectedOutput.cpp create mode 100644 SelectedOutput.h diff --git a/PBasic.cpp b/PBasic.cpp index a9de1a81..4b2e064f 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -472,7 +472,8 @@ numtostr(char * Result, LDBLE n) /* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ if (ceil(n) == floor(n)) { - if (PhreeqcPtr->punch.high_precision == FALSE) + if (!PhreeqcPtr->current_selected_output != NULL && + !PhreeqcPtr->current_selected_output->Get_high_precision()) { sprintf(l_s, "%12.0f", (double) n); } @@ -483,7 +484,8 @@ numtostr(char * Result, LDBLE n) } else { - if (PhreeqcPtr->punch.high_precision == FALSE) + if (!PhreeqcPtr->current_selected_output != NULL && + !PhreeqcPtr->current_selected_output->Get_high_precision()) { sprintf(l_s, "%12.4e", (double) n); } @@ -4395,7 +4397,8 @@ cmdpunch(struct LOC_exec *LINK) if (n.stringval) { /* fputs(n.UU.sval, stdout); */ - if (PhreeqcPtr->punch.high_precision == FALSE) + if (!PhreeqcPtr->current_selected_output != NULL && + !PhreeqcPtr->current_selected_output->Get_high_precision()) { if (strlen(n.UU.sval) <= 12) { @@ -4419,7 +4422,8 @@ cmdpunch(struct LOC_exec *LINK) } PhreeqcPtr->PHRQ_free(n.UU.sval); } - else if (PhreeqcPtr->punch.high_precision == FALSE) + else if (!PhreeqcPtr->current_selected_output != NULL && + !PhreeqcPtr->current_selected_output->Get_high_precision()) { PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); } diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 63e1b8b0..69dc97a8 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -67,7 +67,7 @@ get_forward_output_to_log(void) void Phreeqc:: fpunchf_heading(const char *name) { - if (pr.punch == TRUE && punch.in == TRUE) + if (pr.punch == TRUE && current_selected_output != NULL) { punch_msg(name); } diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6e64c393..55390cb6 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -223,6 +223,8 @@ void Phreeqc::init(void) last_model.count_surface_charge = -1; last_model.surface_charge = NULL; + current_selected_output = NULL; +#ifdef SKIP //struct punch punch; /* * Initialize punch @@ -266,7 +268,7 @@ void Phreeqc::init(void) punch.user_punch = TRUE; punch.charge_balance = FALSE; punch.percent_error = FALSE; - +#endif // auto Rxn_temperature_map; // auto Rxn_pressure_map; @@ -728,7 +730,7 @@ void Phreeqc::init(void) llnl_count_bdot = 0; llnl_co2_coefs = 0; llnl_count_co2_coefs = 0; - selected_output_file_name = NULL; + //selected_output_file_name = NULL; dump_file_name = NULL; remove_unstable_phases = FALSE; // auto screen_string; @@ -770,7 +772,7 @@ void Phreeqc::init(void) phreeqc_mpi_myself = 0; first_read_input = TRUE; user_database = NULL; - have_punch_name = FALSE; + //have_punch_name = FALSE; print_density = 0; zeros = NULL; zeros_max = 1; @@ -1938,6 +1940,11 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) if (llnl_co2_coefs == NULL) malloc_error(); memcpy(llnl_co2_coefs, pSrc->llnl_co2_coefs, (size_t) llnl_count_co2_coefs * sizeof(LDBLE)); } + + // Not implemented for now + //SelectedOutput_map = pSrc->SelectedOutput_map; + SelectedOutput_map.clear(); + //selected_output_file_name = NULL; //dump_file_name = NULL; //remove_unstable_phases = FALSE; @@ -2047,7 +2054,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) phreeqc_mpi_myself = 0; first_read_input = TRUE; user_database = string_duplicate(pSrc->user_database); - have_punch_name = pSrc->have_punch_name; + //have_punch_name = pSrc->have_punch_name; print_density = pSrc->print_density; #ifdef SKIP zeros = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 6df8472e..1c0607ef 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -28,6 +28,7 @@ #include "runner.h" #include "dumper.h" #include "PHRQ_io.h" +#include "SelectedOutput.h" #ifdef MULTICHART #include "ChartHandler.h" #endif @@ -1139,7 +1140,7 @@ protected: * ---------------------------------------------------------------------- */ struct model last_model; - struct punch punch; + //struct punch punch; /* ---------------------------------------------------------------------- * Temperatures @@ -1609,7 +1610,10 @@ protected: int llnl_count_temp, llnl_count_adh, llnl_count_bdh, llnl_count_bdot, llnl_count_co2_coefs; - char *selected_output_file_name; + //char *selected_output_file_name; + std::map SelectedOutput_map; + SelectedOutput * current_selected_output; + char *dump_file_name; int remove_unstable_phases; std::string screen_string; @@ -1661,7 +1665,7 @@ protected: int first_read_input; char *user_database; - int have_punch_name; + //int have_punch_name; /* VP: Density Start */ int print_density; /* VP: Density End */ diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp new file mode 100644 index 00000000..35948f03 --- /dev/null +++ b/SelectedOutput.cpp @@ -0,0 +1,79 @@ +#include "SelectedOutput.h" + +SelectedOutput::SelectedOutput(int n, PHRQ_io *io) +: cxxNumKeyword(io) +{ + this->Set_file_name(n); + this->punch_ostream = NULL; + this->active = true; + this->new_def = false; + this->user_punch_new_def = false; + //std::map totals; + //std::map molalities; + //std::map activities; + //std::map pure_phases; + //std::map si; + //std::map gases; + //std::map s_s; + //std::map kinetics; + //std::map isotopes; + //std::map calculate_values; + //std::map kinetics; + //std::map kinetics; + this->inverse = true; + this->sim = true; + this->state = true; + this->soln = true; + this->dist = true; + this->time = true; + this->step = true; + this->rxn = false; + this->temp = false; + this->ph = true; + this->pe = true; + this->alk = false; + this->mu = false; + this->water = false; + this->high_precision = false; + this->user_punch = true; + this->charge_balance = false; + this->percent_error = false; + this->punch = false; + +} + + +SelectedOutput::~SelectedOutput(void) +{ + if (this->punch_ostream != NULL) + { + delete this->punch_ostream; + } + this->punch_ostream = NULL; +} +void +SelectedOutput::Reset(bool value) +{ + sim = value; + state = value; + soln = value; + dist = value; + time = value; + step = value; + ph = value; + pe = value; + rxn = value; + temp = value; + alk = value; + mu = value; + water = value; + charge_balance = value; + percent_error = value; +} +void +SelectedOutput::Set_file_name(int n) +{ + std::ostringstream os; + os << "selected_output_" << n << ".sel"; + file_name = os.str(); +} \ No newline at end of file diff --git a/SelectedOutput.h b/SelectedOutput.h new file mode 100644 index 00000000..2befd46f --- /dev/null +++ b/SelectedOutput.h @@ -0,0 +1,108 @@ +#if !defined(SELECTEDOUTPUT_H_INCLUDED) +#define SELECTEDOUTPUT_H_INCLUDED +#include // std::string +#include +#include +#include "NumKeyword.h" +class SelectedOutput:public cxxNumKeyword +{ +public: + SelectedOutput(int n=1, PHRQ_io *io=NULL); + ~SelectedOutput(void); + void Reset(bool tf); + + std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} + std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} + std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} + std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;} + std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;} + std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;} + std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;} + std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;} + std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} + std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} + + std::string & Get_file_name(void) {return this->file_name;} + bool Get_new_def(void) {return this->new_def;} + bool Get_sim(void) {return this->sim;} + bool Get_state(void) {return this->state;} + bool Get_soln(void) {return this->soln;} + bool Get_dist(void) {return this->dist;} + bool Get_time(void) {return this->time;} + bool Get_step(void) {return this->step;} + bool Get_rxn(void) {return this->rxn;} + bool Get_temp(void) {return this->temp;} + bool Get_ph(void) {return this->ph;} + bool Get_pe(void) {return this->pe;} + bool Get_alk(void) {return this->alk;} + bool Get_mu(void) {return this->mu;} + bool Get_water(void) {return this->water;} + bool Get_high_precision(void) {return this->high_precision;} + bool Get_user_punch(void) {return this->user_punch;} + bool Get_charge_balance(void) {return this->charge_balance;} + bool Get_percent_error(void) {return this->percent_error;} + bool Get_inverse(void) {return this->inverse;} + bool Get_punch(void) {return this->punch;} + bool Get_active(void) {return this->active;} + + void Set_file_name(int i); + void Set_file_name(std::string s) {this->file_name = s;} + void Set_new_def(bool tf) {this->new_def = tf;} + void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} + void Set_sim(bool tf) {this->sim = tf;} + void Set_state(bool tf) {this->state = tf;} + void Set_soln(bool tf) {this->soln = tf;} + void Set_dist(bool tf) {this->dist = tf;} + void Set_time(bool tf) {this->time = tf;} + void Set_step(bool tf) {this->step = tf;} + void Set_rxn(bool tf) {this->rxn = tf;} + void Set_temp(bool tf) {this->temp = tf;} + void Set_ph(bool tf) {this->ph = tf;} + void Set_pe(bool tf) {this->pe = tf;} + void Set_alk(bool tf) {this->alk = tf;} + void Set_mu(bool tf) {this->mu = tf;} + void Set_water(bool tf) {this->water = tf;} + void Set_high_precision(bool tf) {this->high_precision = tf;} + void Set_user_punch(bool tf) {this->user_punch = tf;} + void Set_charge_balance(bool tf) {this->charge_balance = tf;} + void Set_percent_error(bool tf) {this->percent_error = tf;} + void Set_inverse(bool tf) {this->inverse = tf;} + void Set_punch(bool tf) {this->punch = tf;} + void Set_active(bool tf) {this->active = tf;} + + std::string file_name; + std::ostream * punch_ostream; + bool active; + bool new_def; + bool user_punch_new_def; + std::vector< std::pair< std::string, void * > > totals; + std::vector< std::pair< std::string, void * > > molalities; + std::vector< std::pair< std::string, void * > > activities; + std::vector< std::pair< std::string, void * > > pure_phases; + std::vector< std::pair< std::string, void * > > si; + std::vector< std::pair< std::string, void * > > gases; + std::vector< std::pair< std::string, void * > > s_s; + std::vector< std::pair< std::string, void * > > kinetics; + std::vector< std::pair< std::string, void * > > isotopes; + std::vector< std::pair< std::string, void * > > calculate_values; + bool sim; + bool state; + bool soln; + bool dist; + bool time; + bool step; + bool rxn; + bool temp; + bool ph; + bool pe; + bool alk; + bool mu; + bool water; + bool high_precision; + bool user_punch; + bool charge_balance; + bool percent_error; + bool inverse; + bool punch; +}; +#endif // !defined(SELECTEDOUTPUT_H_INCLUDED) \ No newline at end of file diff --git a/global_structures.h b/global_structures.h index 6253cb5a..d2157219 100644 --- a/global_structures.h +++ b/global_structures.h @@ -284,6 +284,7 @@ struct name_phase const char *name; struct phase *phase; }; +#ifdef SKIP struct punch { int in; @@ -327,7 +328,7 @@ struct punch int charge_balance; int percent_error; }; - +#endif struct Change_Surf { const char *comp_name; diff --git a/inverse.cpp b/inverse.cpp index d45abf2d..8cc799d1 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -158,7 +158,7 @@ setup_inverse(struct inverse *inv_ptr) int max; int count_rows_t; int column, row; - int temp, temppun; + int temp; LDBLE isotope_number; LDBLE f, coef, cb, conc; char token[MAX_LENGTH]; @@ -180,11 +180,12 @@ setup_inverse(struct inverse *inv_ptr) carbon = 1; temp = pr.status; pr.status = FALSE; - temppun = punch.in; - punch.in = FALSE; + + // current_selected_output is NULL at this point carbon_derivs(inv_ptr); pr.status = temp; - punch.in = temppun; + + //current_selected_output->Set_inverse(temp_inv); state = INVERSE; /* * tidy isotopes if necessary @@ -2079,64 +2080,81 @@ punch_model_heading(struct inverse *inv_ptr) */ int i; char token[MAX_LENGTH]; - if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) - return (OK); - std::vector heading_names; - int l = (punch.high_precision == FALSE) ? 15 : 20; - -/* - * Print sum of residuals and maximum fractional error - */ - heading_names.push_back(sformatf("%*s\t", l, "Sum_resid")); - heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U")); - heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr")); - -/* - * Print solution numbers - */ - for (i = 0; i < inv_ptr->count_solns; i++) + //if (/*punch.in == FALSE ||*/ pr.punch == FALSE || punch.inverse == FALSE) + // return (OK); + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) { - sprintf(token, "Soln_%d", inv_ptr->solns[i]); - std::string tok1(token); - tok1.append("_min"); - std::string tok2(token); - tok2.append("_max"); + // set punch file + current_selected_output = &(so_it->second); + if (pr.punch == FALSE || + current_selected_output == NULL || + current_selected_output->punch_ostream == NULL || + !current_selected_output->Get_inverse() || + !current_selected_output->Get_active()) + continue; + phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); - heading_names.push_back(sformatf("%*s\t", l, token)); - heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); - heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + std::vector heading_names; + int l = (!current_selected_output->Get_high_precision()) ? 15 : 20; + + /* + * Print sum of residuals and maximum fractional error + */ + heading_names.push_back(sformatf("%*s\t", l, "Sum_resid")); + heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U")); + heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr")); + + /* + * Print solution numbers + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "Soln_%d", inv_ptr->solns[i]); + std::string tok1(token); + tok1.append("_min"); + std::string tok2(token); + tok2.append("_max"); + + heading_names.push_back(sformatf("%*s\t", l, token)); + heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + } + /* + * Print phase names + */ + for (i = col_phases; i < col_redox; i++) + { + + std::string tok1(col_name[i]); + tok1.append("_max"); + std::string tok2(col_name[i]); + tok2.append("_max"); + + heading_names.push_back(sformatf("%*s\t", l, col_name[i])); + heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + + } + + size_t j; + + // punch headings + user_punch_count_headings = (int) heading_names.size(); + user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, + (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + if (user_punch_headings == NULL) + malloc_error(); + + for (j = 0; j < heading_names.size(); j++) + { + fpunchf_heading(heading_names[j].c_str()); + user_punch_headings[j] = string_hsave(heading_names[j].c_str()); + } + fpunchf_heading("\n"); } -/* - * Print phase names - */ - for (i = col_phases; i < col_redox; i++) - { - - std::string tok1(col_name[i]); - tok1.append("_max"); - std::string tok2(col_name[i]); - tok2.append("_max"); - - heading_names.push_back(sformatf("%*s\t", l, col_name[i])); - heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); - heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); - - } - - size_t j; - - user_punch_count_headings = (int) heading_names.size(); - user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, - (size_t) (user_punch_count_headings + 1) * sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); - - for (j = 0; j < heading_names.size(); j++) - { - fpunchf_heading(heading_names[j].c_str()); - user_punch_headings[j] = string_hsave(heading_names[j].c_str()); - } - fpunchf_heading("\n"); + current_selected_output = NULL; + phrq_io->Set_punch_ostream(NULL); /* * Flush buffer after each model */ @@ -2154,84 +2172,99 @@ punch_model(struct inverse *inv_ptr) */ int i; LDBLE d1, d2, d3; - if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) - return (OK); - n_user_punch_index = 0; -/* - * write residual info - */ - if (punch.high_precision == FALSE) + //if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) + // return (OK); + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) (error / SCALE_EPSILON)); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) scaled_error); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) max_pct); - } - else - { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) (error / SCALE_EPSILON)); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) scaled_error); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) max_pct); - } -/* - * write solution fractions - */ - for (i = 0; i < inv_ptr->count_solns; i++) - { - d1 = inv_delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d3 = 0.0; - if (punch.high_precision == FALSE) - { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); - } - else - { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); - } - } -/* - * write phase transfers - */ - for (i = col_phases; i < col_redox; i++) - { - d1 = inv_delta1[i]; - d2 = min_delta[i]; - d3 = max_delta[i]; - if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d1 = 0.0; - if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d2 = 0.0; - if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) - d3 = 0.0; - if (punch.high_precision == FALSE) - { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); - } - else - { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); - } - } - punch_msg("\n"); + current_selected_output = &(so_it->second); + if (pr.punch == FALSE || + current_selected_output == NULL || + current_selected_output->punch_ostream == NULL || + !current_selected_output->Get_inverse() || + !current_selected_output->Get_active()) + continue; + phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); -/* - * Flush buffer after each model - */ - punch_flush(); + n_user_punch_index = 0; + /* + * write residual info + */ + if (!current_selected_output->Get_high_precision()) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) (error / SCALE_EPSILON)); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) scaled_error); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) max_pct); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) (error / SCALE_EPSILON)); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) scaled_error); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) max_pct); + } + /* + * write solution fractions + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + if (!current_selected_output->Get_high_precision()) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + } + } + /* + * write phase transfers + */ + for (i = col_phases; i < col_redox; i++) + { + d1 = inv_delta1[i]; + d2 = min_delta[i]; + d3 = max_delta[i]; + if (equal(d1, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d1 = 0.0; + if (equal(d2, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d2 = 0.0; + if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) + d3 = 0.0; + if (!current_selected_output->Get_high_precision()) + { + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + } + else + { + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); + fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + } + } + punch_msg("\n"); + + /* + * Flush buffer after each model + */ + punch_flush(); + } + current_selected_output = NULL; + phrq_io->Set_punch_ostream(NULL); return (OK); } diff --git a/isotopes.cpp b/isotopes.cpp index 107501c3..3d9d6373 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -810,21 +810,24 @@ punch_isotopes(void) /* * Punch isotope ratios relative to standards */ - int i; + //int i; LDBLE iso; struct isotope_ratio *isotope_ratio_ptr; struct master_isotope *master_isotope_ptr; - if (punch.in == FALSE || punch.isotopes == FALSE) - return (OK); - if (punch.count_isotopes == 0) - return (OK); - for (i = 0; i < punch.count_isotopes; i++) + //if (punch.in == FALSE || punch.isotopes == FALSE) + // return (OK); + if (current_selected_output->Get_isotopes().size() == 0) + return(OK); + //if (punch.count_isotopes == 0) + // return (OK); + //for (i = 0; i < punch.count_isotopes; i++) + for (size_t i = 0; i < current_selected_output->Get_isotopes().size(); i++) { iso = MISSING; if (state == INITIAL_SOLUTION) { - isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + isotope_ratio_ptr = isotope_ratio_search(current_selected_output->Get_isotopes()[i].first.c_str()); if (isotope_ratio_ptr != NULL) { master_isotope_ptr = @@ -838,20 +841,20 @@ punch_isotopes(void) } else { - isotope_ratio_ptr = isotope_ratio_search(punch.isotopes[i].name); + isotope_ratio_ptr = isotope_ratio_search(current_selected_output->Get_isotopes()[i].first.c_str()); if (isotope_ratio_ptr != NULL) { iso = isotope_ratio_ptr->converted_ratio; } } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%12.4e\t", + fpunchf(sformatf("I_%s", current_selected_output->Get_isotopes()[i].first.c_str()), "%12.4e\t", (double) iso); } else { - fpunchf(sformatf("I_%s", punch.isotopes[i].name), "%20.12e\t", + fpunchf(sformatf("I_%s", current_selected_output->Get_isotopes()[i].first.c_str()), "%20.12e\t", (double) iso); } @@ -867,20 +870,23 @@ punch_calculate_values(void) /* * Punch calculate values */ - int i; + //int i; LDBLE result; struct calculate_value *calculate_value_ptr; char l_command[] = "run"; - if (punch.in == FALSE || punch.calculate_values == FALSE) - return (OK); - if (punch.count_calculate_values == 0) - return (OK); - for (i = 0; i < punch.count_calculate_values; i++) + if (current_selected_output->Get_calculate_values().size() == 0) + return OK; + //if (punch.in == FALSE || punch.calculate_values == FALSE) + // return (OK); + //if (punch.count_calculate_values == 0) + // return (OK); + //for (i = 0; i < punch.count_calculate_values; i++) + for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) { result = MISSING; calculate_value_ptr = - calculate_value_search(punch.calculate_values[i].name); + calculate_value_search(current_selected_output->Get_calculate_values()[i].first.c_str()); if (calculate_value_ptr->calculated == FALSE) { rate_moles = NAN; @@ -922,14 +928,14 @@ punch_calculate_values(void) { result = calculate_value_ptr->value; } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("V_%s", punch.calculate_values[i].name), + fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first), "%12.4e\t", (double) result); } else { - fpunchf(sformatf("V_%s", punch.calculate_values[i].name), + fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first), "%20.12e\t", (double) result); } } diff --git a/mainsubs.cpp b/mainsubs.cpp index dabd8876..874801a1 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -96,6 +96,7 @@ initialize(void) hcreate_multi((unsigned) max_elements, &elements_hash_table); hcreate_multi((unsigned) max_s, &species_hash_table); hcreate_multi((unsigned) max_phases, &phases_hash_table); +#ifdef SKIP_OLD_SELECTED_OUTPUT /* * Initialize punch */ @@ -169,7 +170,7 @@ initialize(void) (struct name_master *) PHRQ_malloc(sizeof(struct name_master)); if (punch.calculate_values == NULL) malloc_error(); - +#endif // one save_values save_values = (struct save_values *) PHRQ_malloc(sizeof(struct save_values)); diff --git a/print.cpp b/print.cpp index 8509fbbd..c1b39956 100644 --- a/print.cpp +++ b/print.cpp @@ -162,31 +162,44 @@ punch_all(void) chart_handler.Punch_user_graph(this); } #endif - if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) + //if (pr.hdf == FALSE && (punch.in == FALSE || pr.punch == FALSE)) + if (pr.hdf == FALSE && (SelectedOutput_map.size() == 0 || pr.punch == FALSE)) return (OK); - punch_identifiers(); - punch_totals(); - punch_molalities(); - punch_activities(); - punch_pp_assemblage(); - punch_saturation_indices(); - punch_gas_phase(); - punch_kinetics(); - punch_ss_assemblage(); - punch_isotopes(); - punch_calculate_values(); - punch_user_punch(); -/* - * new line for punch_file - */ - punch_msg("\n"); - -/* - * signal end of row - */ - fpunchf_end_row("\n"); - punch_flush(); + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) + { + current_selected_output = &(so_it->second); + if (pr.punch == FALSE || + current_selected_output == NULL || + !current_selected_output->Get_active() || + current_selected_output->punch_ostream == NULL) + continue; + phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + punch_identifiers(); + punch_totals(); + punch_molalities(); + punch_activities(); + punch_pp_assemblage(); + punch_saturation_indices(); + punch_gas_phase(); + punch_kinetics(); + punch_ss_assemblage(); + punch_isotopes(); + punch_calculate_values(); + punch_user_punch(); + /* + * new line for punch_file + */ + punch_msg("\n"); + /* + * signal end of row + */ + fpunchf_end_row("\n"); + punch_flush(); + } + current_selected_output = NULL; + phrq_io->Set_punch_ostream(NULL); return (OK); } /* ---------------------------------------------------------------------- */ @@ -2378,12 +2391,13 @@ punch_gas_phase(void) /* * Prints selected gas phase data */ - int i; + //int i; LDBLE p, total_moles, volume; LDBLE moles; bool PR = false; - if (punch.count_gases <= 0) + //if (punch.count_gases <= 0) + if (current_selected_output->Get_gases().size() == 0) return (OK); p = 0.0; total_moles = 0.0; @@ -2422,7 +2436,7 @@ punch_gas_phase(void) volume = gas_phase_ptr->Get_volume(); } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("pressure", "%12.4e\t", (double) p); fpunchf("total mol", "%12.4e\t", (double) total_moles); @@ -2434,17 +2448,17 @@ punch_gas_phase(void) fpunchf("total mol", "%20.12e\t", (double) total_moles); fpunchf("volume", "%20.12e\t", (double) volume); } - for (i = 0; i < punch.count_gases; i++) + for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++) { moles = 0.0; - if (gas_phase_ptr != NULL && punch.gases[i].phase != NULL) + if (gas_phase_ptr != NULL && current_selected_output->Get_gases()[i].second != NULL) { for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]); int k; struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str() , &k, FALSE); - if (phase_ptr != punch.gases[i].phase) + if (phase_ptr != current_selected_output->Get_gases()[i].second) continue; moles = phase_ptr->moles_x; if (moles <= MIN_TOTAL) @@ -2452,13 +2466,13 @@ punch_gas_phase(void) break; } } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("g_%s", punch.gases[i].name), "%12.4e\t", (double) moles); + fpunchf(sformatf("g_%s", current_selected_output->Get_gases()[i].first.c_str()), "%12.4e\t", (double) moles); } else { - fpunchf(sformatf("g_%s", punch.gases[i].name), "%20.12e\t", + fpunchf(sformatf("g_%s", current_selected_output->Get_gases()[i].first.c_str()), "%20.12e\t", (double) moles); } } @@ -2472,27 +2486,27 @@ punch_ss_assemblage(void) /* * Prints solid solution composition if present */ - int j, k; + //int j, k; int found; LDBLE moles; /* * Print solid solutions */ - for (k = 0; k < punch.count_s_s; k++) + for (size_t k = 0; k < current_selected_output->Get_s_s().size(); k++) { found = FALSE; if (use.Get_ss_assemblage_ptr() != NULL) { std::vector ss_ptrs = use.Get_ss_assemblage_ptr()->Vectorize(); - for (j = 0; j < (int) ss_ptrs.size(); j++) + for (int j = 0; j < (int) ss_ptrs.size(); j++) { cxxSS * ss_ptr = ss_ptrs[j]; for (int i = 0; i < (int) ss_ptr->Get_ss_comps().size(); i++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[i]); - if (strcmp_nocase(punch.s_s[k].name, comp_ptr->Get_name().c_str()) == 0) + if (strcmp_nocase(current_selected_output->Get_s_s()[k].first.c_str(), comp_ptr->Get_name().c_str()) == 0) { if (ss_ptr->Get_ss_in()) { @@ -2502,14 +2516,14 @@ punch_ss_assemblage(void) { moles = 0; } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("s_%s", punch.s_s[k].name), + fpunchf(sformatf("ss_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%12.4e\t", (double) moles); } else { - fpunchf(sformatf("s_%s", punch.s_s[k].name), + fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%20.12e\t", (double) moles); } found = TRUE; @@ -2522,13 +2536,13 @@ punch_ss_assemblage(void) } if (found == FALSE) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%12.4e\t", (double) 0.0); + fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%12.4e\t", (double) 0.0); } else { - fpunchf(sformatf("s_%s", punch.s_s[k].name), "%20.12e\t", + fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%20.12e\t", (double) 0.0); } } @@ -2544,37 +2558,37 @@ punch_totals(void) /* * Print total concentrations of elements, molality and moles. */ - int j; + //int j; LDBLE molality; - for (j = 0; j < punch.count_totals; j++) + for (size_t j = 0; j < current_selected_output->Get_totals().size(); j++) { - if (punch.totals[j].master == NULL) + if (current_selected_output->Get_totals()[j].second == NULL) { molality = 0.0; } - else if (punch.totals[j].master->primary == TRUE) + else if (((struct master *) current_selected_output->Get_totals()[j].second)->primary == TRUE) { - if (strncmp(punch.totals[j].name, "Alkalinity", 20) == 0) + if (strncmp(current_selected_output->Get_totals()[j].first.c_str(), "Alkalinity", 20) == 0) { molality = total_alkalinity / mass_water_aq_x; } else { - molality = punch.totals[j].master->total_primary / mass_water_aq_x; + molality = ((struct master *) current_selected_output->Get_totals()[j].second)->total_primary / mass_water_aq_x; } } else { - molality = punch.totals[j].master->total / mass_water_aq_x; + molality = ((struct master *) current_selected_output->Get_totals()[j].second)->total / mass_water_aq_x; } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name), + fpunchf(sformatf("%s(mol/kgw)", current_selected_output->Get_totals()[j].first.c_str()), "%12.4e\t", (double) molality); } else { - fpunchf(sformatf("%s(mol/kgw)", punch.totals[j].name), + fpunchf(sformatf("%s(mol/kgw)", current_selected_output->Get_totals()[j].first.c_str()), "%20.12e\t", (double) molality); } } @@ -2589,25 +2603,25 @@ punch_molalities(void) /* * Print concentrations of species (aq, ex, surf) */ - int j; + //int j; LDBLE molality; - for (j = 0; j < punch.count_molalities; j++) + for (size_t j = 0; j < current_selected_output->Get_molalities().size(); j++) { molality = 0.0; - if (punch.molalities[j].s != NULL - && punch.molalities[j].s->in == TRUE) + if (current_selected_output->Get_molalities()[j].second != NULL + && ((struct species *) current_selected_output->Get_molalities()[j].second)->in == TRUE) { - molality = punch.molalities[j].s->moles / mass_water_aq_x; + molality = ((struct species *) current_selected_output->Get_molalities()[j].second)->moles / mass_water_aq_x; } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name), + fpunchf(sformatf("m_%s(mol/kgw)", current_selected_output->Get_molalities()[j].first.c_str()), "%12.4e\t", (double) molality); } else { - fpunchf(sformatf("m_%s(mol/kgw)", punch.molalities[j].name), + fpunchf(sformatf("m_%s(mol/kgw)", current_selected_output->Get_molalities()[j].first.c_str()), "%20.12e\t", (double) molality); } } @@ -2622,26 +2636,26 @@ punch_activities(void) /* * Print concentrations of species (aq, ex, surf) */ - int j; + //int j; LDBLE la; - for (j = 0; j < punch.count_activities; j++) + for (size_t j = 0; j < current_selected_output->Get_activities().size(); j++) { la = -999.999; - if (punch.activities[j].s != NULL - && punch.activities[j].s->in == TRUE) + if (current_selected_output->Get_activities()[j].second != NULL + && ((struct species *) current_selected_output->Get_activities()[j].second)->in == TRUE) { /*la = punch.activities[j].s->lm + punch.activities[j].s->lg; */ - la = log_activity(punch.activities[j].s->name); + la = log_activity(current_selected_output->Get_activities()[j].first.c_str()); } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("la_%s", punch.activities[j].name), "%12.4e\t", + fpunchf(sformatf("la_%s", current_selected_output->Get_activities()[j].first.c_str()), "%12.4e\t", (double) la); } else { - fpunchf(sformatf("la_%s", punch.activities[j].name), + fpunchf(sformatf("la_%s", current_selected_output->Get_activities()[j].first.c_str()), "%20.12e\t", (double) la); } } @@ -2656,15 +2670,15 @@ punch_pp_assemblage(void) /* * Prints masses of selected pure_phases in pp_assemblage */ - int i, j; + //int i, j; LDBLE moles, delta_moles; - for (i = 0; i < punch.count_pure_phases; i++) + for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++) { delta_moles = 0; moles = 0.0; - if (punch.pure_phases[i].phase != NULL) + if (current_selected_output->Get_pure_phases()[i].second != NULL) { - for (j = 0; j < count_unknowns; j++) + for (int j = 0; j < count_unknowns; j++) { if (x == NULL || x[j]->type != PP) continue; @@ -2673,7 +2687,7 @@ punch_pp_assemblage(void) /* * Print pure phase assemblage data */ - if (punch.pure_phases[i].phase != x[j]->phase) + if (current_selected_output->Get_pure_phases()[i].second != x[j]->phase) continue; if (state != TRANSPORT && state != PHAST) { @@ -2691,16 +2705,16 @@ punch_pp_assemblage(void) break; } } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(punch.pure_phases[i].name, "%12.4e\t", (double) moles); - fpunchf(sformatf("d_%s", punch.pure_phases[i].name), "%12.4e\t", + fpunchf(current_selected_output->Get_pure_phases()[i].first.c_str(), "%12.4e\t", (double) moles); + fpunchf(sformatf("d_%s", current_selected_output->Get_pure_phases()[i].first.c_str()), "%12.4e\t", (double) delta_moles); } else { - fpunchf(punch.pure_phases[i].name, "%20.12e\t", (double) moles); - fpunchf(sformatf("d_%s", punch.pure_phases[i].name), + fpunchf(current_selected_output->Get_pure_phases()[i].first.c_str(), "%20.12e\t", (double) moles); + fpunchf(sformatf("d_%s", current_selected_output->Get_pure_phases()[i].first.c_str()), "%20.12e\t", (double) delta_moles); } } @@ -2725,9 +2739,9 @@ punch_identifiers(void) int i, l; char token[MAX_LENGTH]; - if (punch.in == FALSE) - return (OK); - if (punch.high_precision == FALSE) + //if (punch.in == FALSE) + // return (OK); + if (!current_selected_output->Get_high_precision()) { l = 12; sformat = "%12s\t"; @@ -2746,7 +2760,7 @@ punch_identifiers(void) * simulation or simul_tr */ - if (punch.sim == TRUE) + if (current_selected_output->Get_sim()) { if (state != TRANSPORT && state != PHAST) { @@ -2757,7 +2771,7 @@ punch_identifiers(void) fpunchf(PHAST_NULL("sim"), dformat, simul_tr); } } - if (punch.state == TRUE) + if (current_selected_output->Get_state()) { switch (state) { @@ -2795,7 +2809,7 @@ punch_identifiers(void) /* * solution number or cell number and time */ - if (punch.soln == TRUE) + if (current_selected_output->Get_soln()) { if (state == TRANSPORT || state == PHAST) { @@ -2829,7 +2843,7 @@ punch_identifiers(void) } } } - if (punch.dist == TRUE) + if (current_selected_output->Get_dist()) { if (state == ADVECTION) { @@ -2845,7 +2859,7 @@ punch_identifiers(void) fpunchf(PHAST_NULL("dist_x"), dformat, -99); } } - if (punch.time == TRUE) + if (current_selected_output->Get_time()) { LDBLE reaction_time = kin_time_x; if (state == REACTION && incremental_reactions == TRUE @@ -2911,7 +2925,7 @@ punch_identifiers(void) /* * reaction or transport step */ - if (punch.step == TRUE) + if (current_selected_output->Get_step()) { if (state == REACTION) { @@ -2930,9 +2944,9 @@ punch_identifiers(void) fpunchf(PHAST_NULL("step"), dformat, -99); } } - if (punch.ph == TRUE) + if (current_selected_output->Get_ph()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("pH", "%12g\t", (double) (-s_hplus->la)); } @@ -2941,9 +2955,9 @@ punch_identifiers(void) fpunchf("pH", "%20.12e\t", (double) (-s_hplus->la)); } } - if (punch.pe == TRUE) + if (current_selected_output->Get_pe()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("pe", "%12g\t", (double) (-s_eminus->la)); } @@ -2952,11 +2966,11 @@ punch_identifiers(void) fpunchf("pe", "%20.12e\t", (double) (-s_eminus->la)); } } - if (punch.rxn == TRUE) + if (current_selected_output->Get_rxn()) { if (state >= REACTION && use.Get_reaction_in() == TRUE) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("reaction", "%12.4e\t", (double) step_x); } @@ -2967,7 +2981,7 @@ punch_identifiers(void) } else { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("reaction", "%12d\t", -99); } @@ -2977,9 +2991,9 @@ punch_identifiers(void) } } } - if (punch.temp == TRUE) + if (current_selected_output->Get_temp()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("temp(C)", "%12.3f\t", (double) tc_x); } @@ -2988,9 +3002,9 @@ punch_identifiers(void) fpunchf("temp(C)", "%20.12e\t", (double) tc_x); } } - if (punch.alk == TRUE) + if (current_selected_output->Get_alk()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("Alk(eq/kgw)", "%12g\t", (double) (total_alkalinity / mass_water_aq_x)); @@ -3001,9 +3015,9 @@ punch_identifiers(void) (double) (total_alkalinity / mass_water_aq_x)); } } - if (punch.mu == TRUE) + if (current_selected_output->Get_mu()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("mu", "%12g\t", (double) mu_x); } @@ -3012,9 +3026,9 @@ punch_identifiers(void) fpunchf("mu", "%20.12e\t", (double) mu_x); } } - if (punch.water == TRUE) + if (current_selected_output->Get_water()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("mass_H2O", "%12g\t", (double) mass_water_aq_x); } @@ -3023,9 +3037,9 @@ punch_identifiers(void) fpunchf("mass_H2O", "%20.12e\t", (double) mass_water_aq_x); } } - if (punch.charge_balance == TRUE) + if (current_selected_output->Get_charge_balance()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("charge(eq)", "%12g\t", (double) cb_x); } @@ -3034,9 +3048,9 @@ punch_identifiers(void) fpunchf("charge(eq)", "%20.12e\t", (double) cb_x); } } - if (punch.percent_error == TRUE) + if (current_selected_output->Get_percent_error()) { - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { fpunchf("pct_err", "%12g\t", (double) (100 * cb_x / total_ions_x)); @@ -3060,13 +3074,13 @@ punch_saturation_indices(void) /* * Prints saturation indices of selected phases */ - int i; + //int i; LDBLE si, iap; struct rxn_token *rxn_ptr; - for (i = 0; i < punch.count_si; i++) + for (size_t i = 0; i < current_selected_output->Get_si().size(); i++) { - if (punch.si[i].phase == NULL || punch.si[i].phase->in == FALSE) + if (current_selected_output->Get_si()[i].second == NULL || ((struct phase *) current_selected_output->Get_si()[i].second)->in == FALSE) { si = -999.999; } @@ -3076,20 +3090,20 @@ punch_saturation_indices(void) * Print saturation index */ iap = 0.0; - for (rxn_ptr = punch.si[i].phase->rxn_x->token + 1; + for (rxn_ptr = ((struct phase *) current_selected_output->Get_si()[i].second)->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) { iap += rxn_ptr->s->la * rxn_ptr->coef; } - si = -punch.si[i].phase->lk + iap; + si = -((struct phase *) current_selected_output->Get_si()[i].second)->lk + iap; } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("si_%s", punch.si[i].name), "%12.4f\t", (double) si); + fpunchf(sformatf("si_%s", current_selected_output->Get_si()[i].first.c_str()), "%12.4f\t", (double) si); } else { - fpunchf(sformatf("si_%s", punch.si[i].name), "%20.12e\t", (double) si); + fpunchf(sformatf("si_%s", current_selected_output->Get_si()[i].first.c_str()), "%20.12e\t", (double) si); } } return (OK); @@ -3118,7 +3132,7 @@ punch_kinetics(void) kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, -2); } } - for (int i = 0; i < punch.count_kinetics; i++) + for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++) { moles = 0.0; delta_moles = 0.0; @@ -3128,7 +3142,7 @@ punch_kinetics(void) { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); if (strcmp_nocase - (punch.kinetics[i].name, + (current_selected_output->Get_kinetics()[i].first.c_str(), kinetics_comp_ptr->Get_rate_name().c_str()) == 0) { if (state != TRANSPORT && state != PHAST) @@ -3147,18 +3161,18 @@ punch_kinetics(void) } } } - if (punch.high_precision == FALSE) + if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%12.4e\t", + fpunchf(sformatf("k_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%12.4e\t", (double) moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%12.4e\t", + fpunchf(sformatf("dk_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%12.4e\t", (double) delta_moles); } else { - fpunchf(sformatf("k_%s", punch.kinetics[i].name), "%20.12e\t", + fpunchf(sformatf("k_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%20.12e\t", (double) moles); - fpunchf(sformatf("dk_%s", punch.kinetics[i].name), "%20.12e\t", + fpunchf(sformatf("dk_%s", current_selected_output->Get_kinetics()[i].first.c_str()), "%20.12e\t", (double) delta_moles); } } @@ -3175,8 +3189,8 @@ punch_user_punch(void) char l_command[] = "run"; n_user_punch_index = 0; - if (punch.user_punch == FALSE) - return (OK); + //if (punch.user_punch == FALSE) + // return (OK); if (user_punch->commands == NULL) return (OK); if (user_punch->new_def == TRUE) diff --git a/read.cpp b/read.cpp index 65b516f9..266d1555 100644 --- a/read.cpp +++ b/read.cpp @@ -16,6 +16,7 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "Solution.h" +#include "SelectedOutput.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -4588,7 +4589,444 @@ read_save(void) /* empty, eof, keyword, print */ return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_selected_output(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read data for to output to flat file + */ + int value; + int return_value, opt, opt_save; + char *next_char; + const char *opt_list[] = { + "file", /* 0 */ + "totals", /* 1 */ + "molalities", /* 2 */ + "activities", /* 3 */ + "pure_phases", /* 4 */ + "si", /* 5 */ + "saturation_indices", /* 6 */ + "gases", /* 7 */ + "equilibrium_phases", /* 8 */ + "equilibria", /* 9 */ + "equilibrium", /* 10 */ + "pure", /* 11 */ + "inverse", /* 12 */ + "kinetic_reactants", /* 13 */ + "kinetics", /* 14 */ + "solid_solutions", /* 15 */ + "inverse_modeling", /* 16 */ + "reset", /* 17 */ + "simulation", /* 18 */ + "sim", /* 19 */ + "state", /* 20 */ + "solution", /* 21 */ + "soln", /* 22 */ + "distance", /* 23 */ + "dist", /* 24 */ + "time", /* 25 */ + "step", /* 26 */ + "reaction", /* 27 */ + "rxn", /* 28 */ + "temperature", /* 29 */ + "temp", /* 30 */ + "ph", /* 31 */ + "pe", /* 32 */ + "alkalinity", /* 33 */ + "alk", /* 34 */ + "ionic_strength", /* 35 */ + "mu", /* 36 */ + "water", /* 37 */ + "high_precision", /* 38 */ + "user_punch", /* 39 */ + "mol", /* 40 */ + "kin", /* 41 */ + "charge_balance", /* 42 */ + "percent_error", /* 43 */ + "selected_out", /* 44 */ + "selected_output", /* 45 */ + "isotopes", /* 46 */ + "calculate_values", /* 47 */ + "equilibrium_phase", /* 48 */ + "active" /* 49 */ + }; + int count_opt_list = 50; + int i, l; + char file_name[MAX_LENGTH], token[MAX_LENGTH]; + + char *ptr; + ptr = line; + int n_user, n_user_end; + char *description; + read_number_description(ptr, &n_user, &n_user_end, &description); + + SelectedOutput temp_selected_output; + temp_selected_output.Set_new_def(false); + temp_selected_output.Set_file_name(n_user); + temp_selected_output.Set_n_user(n_user); + temp_selected_output.Set_n_user_end(n_user_end); + temp_selected_output.Set_description(description); + free_check_null(description); + + // find if it exists + std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); + + CParser parser(this->phrq_io); + +/* + * Read eqn from file and call parser + */ + opt_save = OPTION_ERROR; + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + opt_save = opt; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_DEFAULT: + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in SELECTED_OUTPUT keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* file name */ + temp_selected_output.Set_new_def(true); + if (string_trim(next_char) != EMPTY) + { + strcpy(file_name, next_char); + temp_selected_output.Set_file_name(file_name); + } + opt_save = OPTION_ERROR; + break; + case 1: /* totals */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '[') + { + error_string = sformatf( "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_totals().push_back(t_pair); + } + } + break; + case 2: /* molalities */ + case 40: /* mol */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) + { + error_string = sformatf( "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_molalities().push_back(t_pair); + } + } + break; + case 3: /* activities */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '(' && (token[0] != '[')) + { + error_string = sformatf( "Expected species name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_activities().push_back(t_pair); + } + } + break; + case 4: /* pure_phases */ + case 8: /* equilibrium_phases */ + case 9: /* equilibria */ + case 10: /* equilibrium */ + case 11: /* pure */ + case 48: /* equilibrium_phase */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_pure_phases().push_back(t_pair); + } + break; + case 5: /* si */ + case 6: /* saturation_index */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_si().push_back(t_pair); + } + break; + case 7: /* gases */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_gases().push_back(t_pair); + } + break; + case 12: /* inverse */ + case 16: /* inverse_modeling */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_inverse(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 13: /* kinetic_reactants */ + case 14: /* kinetics */ + case 41: /* kin */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_kinetics().push_back(t_pair); + } + break; + case 15: /* solid_solutions */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_s_s().push_back(t_pair); + } + break; + case 46: /* isotopes */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + if (i != UPPER && token[0] != '[') + { + error_string = sformatf( "Expected element name to" + " begin with upper case letter."); + warning_msg(error_string); + } + else + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_isotopes().push_back(t_pair); + } + } + break; + case 47: /* calculate_values */ + temp_selected_output.Set_new_def(true); + while ((i = copy_token(token, &next_char, &l)) != EMPTY) + { + std::pair< std::string, void *> t_pair(token, NULL); + temp_selected_output.Get_calculate_values().push_back(t_pair); + } + break; + case 17: /* reset */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + /* matches print order */ + temp_selected_output.Reset(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 18: /* simulation */ + case 19: /* sim */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_sim(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 20: /* state */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_state(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 21: /* solution */ + case 22: /* soln */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_soln(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 23: /* distance */ + case 24: /* dist */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_dist(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 25: /* time */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_time(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 26: /* step */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_step(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 27: /* reaction */ + case 28: /* rxn */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_rxn(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 29: /* temperature */ + case 30: /* temp */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_temp(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 31: /* ph */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_ph(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 32: /* pe */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_pe(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 33: /* alkalinity */ + case 34: /* alk */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_alk(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 35: /* ionic strength */ + case 36: /* mu */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_mu(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 37: /* water */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_water(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 38: /* high_precision */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_high_precision(value!=FALSE); + if (value == TRUE) + { + convergence_tolerance = 1e-12; + } + opt_save = OPTION_ERROR; + break; + case 39: /* user_punch */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_user_punch(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 42: /* charge_balance */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_charge_balance(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 43: /* percent_error */ + temp_selected_output.Set_new_def(true); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_percent_error(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 44: /* selected_out */ + case 45: /* selected_output */ + temp_selected_output.Set_new_def(true); + warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_punch(value!=FALSE); + opt_save = OPTION_ERROR; + break; + case 49: /* active */ + value = get_true_false(next_char, TRUE); + temp_selected_output.Set_active(value!=FALSE); + if (so != SelectedOutput_map.end()) + { + so->second.Set_active(value!=FALSE); + } + opt_save = OPTION_ERROR; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + + if (temp_selected_output.Get_new_def()) + { + + // delete if exists + if (so != SelectedOutput_map.end()) + { + SelectedOutput_map.erase(so); + } + + // store new selected output + SelectedOutput_map[n_user] = temp_selected_output; + + // open file + std::ofstream *ofs = new std::ofstream(temp_selected_output.Get_file_name().c_str(), std::ios_base::out ); + if (ofs && ofs->is_open()) + { + SelectedOutput_map[n_user].Set_punch_ostream(ofs); + + } + else + { + error_string = sformatf( "Can`t open file, %s.", file_name); + input_error++; + error_msg(error_string, CONTINUE); + } + } + + //if (!have_punch_name) + //{ + // punch_close(); + // if (!punch_open("selected.out")) + // { + // error_string = sformatf( "Can`t open file, %s.", "selected.out"); + // input_error++; + // error_msg(error_string, CONTINUE); + // } + //} + + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_selected_output(void) @@ -5046,6 +5484,7 @@ read_selected_output(void) return (return_value); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: read_solution(void) diff --git a/readtr.cpp b/readtr.cpp index 2c34be80..dce894c3 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -960,7 +960,7 @@ dump_cpp(void) * dumps solution compositions to file */ - int i, j, l; + int j, l; if (dump_in == FALSE || pr.dump == FALSE) return (OK); @@ -1004,106 +1004,113 @@ dump_cpp(void) sprintf(token, "false\n"); fs << token; } + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) + { + current_selected_output = &(so_it->second); - sprintf(token, "SELECTED_OUTPUT\n"); - fs << token; - sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); - fs << token; - if (punch.count_totals != 0) - { - sprintf(token, "\t-tot "); - fs << token; - for (i = 0; i < punch.count_totals; i++) + sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user()); + fs << token ; + //sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); + //fs << token; + fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n"; + //if (punch.count_totals != 0) + if (current_selected_output->Get_totals().size() > 0) { - sprintf(token, " %s", punch.totals[i].name); + sprintf(token, "\t-tot "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_totals()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_molalities != 0) - { - sprintf(token, "\t-mol "); - fs << token; - for (i = 0; i < punch.count_molalities; i++) + if (current_selected_output->Get_molalities().size() > 0) { - sprintf(token, " %s", punch.molalities[i].name); + sprintf(token, "\t-mol "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_molalities()[i].first.size()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_activities != 0) - { - sprintf(token, "\t-act "); - fs << token; - for (i = 0; i < punch.count_activities; i++) + if (current_selected_output->Get_activities().size() > 0) { - sprintf(token, " %s", punch.activities[i].name); + sprintf(token, "\t-act "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_activities()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_pure_phases != 0) - { - sprintf(token, "\t-equ "); - fs << token; - for (i = 0; i < punch.count_pure_phases; i++) + if (current_selected_output->Get_pure_phases().size() > 0) { - sprintf(token, " %s", punch.pure_phases[i].name); + sprintf(token, "\t-equ "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_pure_phases()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_si != 0) - { - sprintf(token, "\t-si "); - fs << token; - for (i = 0; i < punch.count_si; i++) + if (current_selected_output->Get_si().size() > 0) { - sprintf(token, " %s", punch.si[i].name); + sprintf(token, "\t-si "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_si().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_si()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_gases != 0) - { - sprintf(token, "\t-gas "); - fs << token; - for (i = 0; i < punch.count_gases; i++) + if (current_selected_output->Get_gases().size() > 0) { - sprintf(token, " %s", punch.gases[i].name); + sprintf(token, "\t-gas "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_gases()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_s_s != 0) - { - sprintf(token, "\t-solid_solutions "); - fs << token; - for (i = 0; i < punch.count_s_s; i++) + if (current_selected_output->Get_s_s().size() > 0) { - sprintf(token, " %s", punch.s_s[i].name); + sprintf(token, "\t-solid_solutions "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_s_s()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; - } - if (punch.count_kinetics != 0) - { - sprintf(token, "\t-kin "); - fs << token; - for (i = 0; i < punch.count_kinetics; i++) + if (current_selected_output->Get_kinetics().size() > 0) { - sprintf(token, " %s", punch.kinetics[i].name); + sprintf(token, "\t-kin "); + fs << token; + for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++) + { + sprintf(token, " %s", current_selected_output->Get_kinetics()[i].first.c_str()); + fs << token; + } + sprintf(token, "\n"); fs << token; } - sprintf(token, "\n"); - fs << token; } sprintf(token, "TRANSPORT\n"); fs << token; @@ -1120,7 +1127,7 @@ dump_cpp(void) fs << token; sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; - if (punch.high_precision == FALSE) + if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) { sprintf(token, "\t-diffc %13.5e\n", (double) diffc); fs << token; @@ -1144,7 +1151,7 @@ dump_cpp(void) } sprintf(token, "\t-length\n"); fs << token; - for (i = 0; i < count_cells; i++) + for (size_t i = 0; i < count_cells; i++) { sprintf(token, "%12.3e", (double) cell_data[i].length); fs << token; @@ -1158,9 +1165,9 @@ dump_cpp(void) fs << token; sprintf(token, "\t-disp\n"); fs << token; - for (i = 0; i < count_cells; i++) + for (size_t i = 0; i < count_cells; i++) { - if (punch.high_precision == FALSE) + if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) { sprintf(token, "%12.3e", (double) cell_data[i].disp); fs << token; @@ -1185,7 +1192,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (i = 0; i < j; i++) + for (size_t i = 0; i < j; i++) { if (cell_data[i].punch != TRUE) continue; @@ -1207,7 +1214,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (i = 0; i < j; i++) + for (size_t i = 0; i < j; i++) { if (cell_data[i].print != TRUE) continue; diff --git a/structures.cpp b/structures.cpp index 7ceed374..49be79b0 100644 --- a/structures.cpp +++ b/structures.cpp @@ -185,7 +185,7 @@ clean_up(void) cell_data = (struct cell_data *) free_check_null(cell_data); /* punch */ - +#ifdef SKIP punch.totals = (struct name_master *) free_check_null(punch.totals); punch.molalities = (struct name_species *) free_check_null(punch.molalities); @@ -197,11 +197,15 @@ clean_up(void) punch.gases = (struct name_phase *) free_check_null(punch.gases); punch.s_s = (struct name_phase *) free_check_null(punch.s_s); punch.kinetics = (struct name_phase *) free_check_null(punch.kinetics); +#endif advection_punch = (int *) free_check_null(advection_punch); advection_print = (int *) free_check_null(advection_print); +#ifdef SKIP punch.isotopes = (struct name_master *) free_check_null(punch.isotopes); punch.calculate_values = (struct name_master *) free_check_null(punch.calculate_values); +#endif + SelectedOutput_map.clear(); /* user_print and user_punch */ rate_free(user_print); @@ -344,8 +348,8 @@ clean_up(void) /* free user database name if defined */ user_database = (char *) free_check_null(user_database); - selected_output_file_name = - (char *) free_check_null(selected_output_file_name); + //selected_output_file_name = + // (char *) free_check_null(selected_output_file_name); dump_file_name = (char *) free_check_null(dump_file_name); #ifdef PHREEQCI_GUI free_spread(); diff --git a/tidy.cpp b/tidy.cpp index 8399bac8..8ecc3f98 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1768,6 +1768,450 @@ tidy_ss_assemblage(void) int Phreeqc:: tidy_punch(void) /* ---------------------------------------------------------------------- */ +{ + //int i, j, l; + int punch_save; + //char token[MAX_LENGTH]; +/* + * tidy punch information + */ + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) + { + current_selected_output = &(so_it->second); + if (pr.punch == FALSE || + current_selected_output == NULL || + current_selected_output->punch_ostream == NULL) + continue; + phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + int l; + SelectedOutput *so_ptr = &so_it->second; + if (so_ptr->Get_high_precision() == false) + { + l = 12; + } + else + { + l = 20; + } + //if (punch.in == TRUE) + //{ + /* totals */ + + for (size_t i = 0; i < so_ptr->Get_totals().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_totals()[i]; + pair_ptr.second = master_bsearch(pair_ptr.first.c_str()); + //punch.totals[i].master = master_bsearch(punch.totals[i].name); + } + + /* molalities */ + for (size_t i = 0; i < so_ptr->Get_molalities().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_molalities()[i]; + pair_ptr.second = s_search(pair_ptr.first.c_str()); + //punch.molalities[i].s = s_search(punch.molalities[i].name); + } + + /* log activities */ + + //for (i = 0; i < punch.count_activities; i++) + for (size_t i = 0; i < so_ptr->Get_activities().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_activities()[i]; + pair_ptr.second = s_search(pair_ptr.first.c_str()); + //punch.activities[i].s = s_search(punch.activities[i].name); + } + + /* equilibrium phases */ + + //for (i = 0; i < punch.count_pure_phases; i++) + for (size_t i = 0; i < so_ptr->Get_pure_phases().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_pure_phases()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + //punch.pure_phases[i].phase = + // phase_bsearch(punch.pure_phases[i].name, &j, FALSE); + } + + /* saturation indices */ + + //for (i = 0; i < punch.count_si; i++) + for (size_t i = 0; i < so_ptr->Get_si().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_si()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + //punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); + } + + /* gases */ + + //for (i = 0; i < punch.count_gases; i++) + for (size_t i = 0; i < so_ptr->Get_gases().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = so_ptr->Get_gases()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + //punch.gases[i].phase = + // phase_bsearch(punch.gases[i].name, &j, FALSE); + } + //} + /* + * Always write new headings when SELECTED_OUTPUT is read + */ + if (so_ptr->Get_new_def()) + { + punch_save = pr.punch; + pr.punch = TRUE; + phrq_io->Set_punch_on(true); + + /* constant stuff, sim, pH, etc. */ + + if (so_ptr->Get_sim() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "sim")); + } + if (so_ptr->Get_state() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "state")); + } + if (so_ptr->Get_soln() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "soln")); + } + if (so_ptr->Get_dist() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "dist_x")); + } + if (so_ptr->Get_time() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "time")); + } + if (so_ptr->Get_step() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "step")); + } + if (so_ptr->Get_ph() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pH")); + } + if (so_ptr->Get_pe() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pe")); + } + if (so_ptr->Get_rxn() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "reaction")); + } + if (so_ptr->Get_temp() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "temp")); + } + if (so_ptr->Get_alk() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "Alk")); + } + if (so_ptr->Get_mu() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mu")); + } + if (so_ptr->Get_water() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mass_H2O")); + } + if (so_ptr->Get_charge_balance() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "charge")); + } + if (so_ptr->Get_percent_error() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pct_err")); + } + /* totals */ + + //for (i = 0; i < punch.count_totals; i++) + for (size_t i = 0; i < so_ptr->Get_totals().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_totals()[i]; + fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find master species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name)); + //if (punch.totals[i].master == NULL) + //{ + // error_string = sformatf( "Did not find master species," + // " %s.", punch.totals[i].name); + // warning_msg(error_string); + //} + } + + /* molalities */ + + //for (i = 0; i < punch.count_molalities; i++) + for (size_t i = 0; i < so_ptr->Get_molalities().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_molalities()[i]; + std::string name = "m_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "m_"); + //strcat(token, punch.molalities[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.molalities[i].s == NULL) + //{ + // error_string = sformatf( "Did not find species," + // " %s.", punch.molalities[i].name); + // warning_msg(error_string); + //} + } + + /* log activities */ + + //for (i = 0; i < punch.count_activities; i++) + for (size_t i = 0; i < so_ptr->Get_activities().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_activities()[i]; + std::string name = "la_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "la_"); + //strcat(token, punch.activities[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.activities[i].s == NULL) + //{ + // error_string = sformatf( "Did not find species, " + // "%s.", punch.activities[i].name); + // warning_msg(error_string); + //} + } + + /* equilibrium phases */ + + //for (i = 0; i < punch.count_pure_phases; i++) + for (size_t i = 0; i < so_ptr->Get_pure_phases().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_pure_phases()[i]; + fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); + std::string name = "d_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "d_"); + //strcat(token, punch.pure_phases[i].name); + //fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name)); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.pure_phases[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.pure_phases[i].name); + // warning_msg(error_string); + //} + } + + /* saturation indices */ + + //for (i = 0; i < punch.count_si; i++) + for (size_t i = 0; i < so_ptr->Get_si().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_si()[i]; + std::string name = "si_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "si_"); + //strcat(token, punch.si[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.si[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.si[i].name); + // warning_msg(error_string); + //} + } + + /* gases */ + + //if (punch.count_gases > 0) + if (so_ptr->Get_gases().size() > 0) + { + fpunchf_heading(sformatf("%*s\t", l, "pressure")); + fpunchf_heading(sformatf("%*s\t", l, "total mol")); + fpunchf_heading(sformatf("%*s\t", l, "volume")); + } + //for (i = 0; i < punch.count_gases; i++) + for (size_t i = 0; i < so_ptr->Get_gases().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_gases()[i]; + std::string name = "g_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "g_"); + //strcat(token, punch.gases[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.gases[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.gases[i].name); + // warning_msg(error_string); + //} + } + + /* kinetics */ + + //for (i = 0; i < punch.count_kinetics; i++) + for (size_t i = 0; i < so_ptr->Get_kinetics().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_kinetics()[i]; + std::string name = "k_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + name = "dk_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //strcpy(token, "k_"); + //strcat(token, punch.kinetics[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //strcpy(token, "dk_"); + //strcat(token, punch.kinetics[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* solid solutions */ + + //for (i = 0; i < punch.count_s_s; i++) + for (size_t i = 0; i < so_ptr->Get_s_s().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_s_s()[i]; + std::string name = "ss_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //strcpy(token, "s_"); + //strcat(token, punch.s_s[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* isotopes */ + + //for (i = 0; i < punch.count_isotopes; i++) + for (size_t i = 0; i < so_ptr->Get_isotopes().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_isotopes()[i]; + if (isotope_ratio_search(pair_ref.first.c_str()) == NULL) + { + error_string = sformatf( + "Did not find isotope_ratio definition for " + "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", + pair_ref.first.c_str(), pair_ref.first.c_str()); + warning_msg(error_string); + } + std::string name = "I_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //if (isotope_ratio_search(punch.isotopes[i].name) == NULL) + //{ + // error_string = sformatf( + // "Did not find isotope_ratio definition for " + // "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", + // punch.isotopes[i].name, punch.isotopes[i].name); + // warning_msg(error_string); + //} + //strcpy(token, "I_"); + //strcat(token, punch.isotopes[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* calculate_values */ + + //for (i = 0; i < punch.count_calculate_values; i++) + for (size_t i = 0; i < so_ptr->Get_calculate_values().size(); i++) + { + std::pair< std::string, void *> &pair_ref = so_ptr->Get_calculate_values()[i]; + if (calculate_value_search(pair_ref.first.c_str()) == NULL) + { + error_string = sformatf( + "Did not find calculate_values definition for " + "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", + pair_ref.first.c_str(), + pair_ref.first.c_str()); + warning_msg(error_string); + } + std::string name = "V_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //if (calculate_value_search(punch.calculate_values[i].name) == NULL) + //{ + // error_string = sformatf( + // "Did not find calculate_values definition for " + // "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", + // punch.calculate_values[i].name, + // punch.calculate_values[i].name); + // warning_msg(error_string); + //} + //strcpy(token, "V_"); + //strcat(token, punch.calculate_values[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* user_punch */ + // TODO, implement user_punch n TODO + //if (punch.user_punch == TRUE) + //{ + // for (i = 0; i < user_punch_count_headings; i++) + // { + // fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); + // } + //} + fpunchf_heading("\n"); + + so_ptr->Set_new_def(false); + pr.punch = punch_save; + phrq_io->Set_punch_on(pr.punch == TRUE); + } + punch_flush(); + } + current_selected_output = NULL; + phrq_io->Set_punch_ostream(NULL); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_punch(void) +/* ---------------------------------------------------------------------- */ { int i, j, l; int punch_save; @@ -2068,7 +2512,7 @@ tidy_punch(void) punch_flush(); return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_species(void) From 3893414278036b7e803f2ec20bcdc034556531d8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 31 Jul 2013 23:07:07 +0000 Subject: [PATCH 0709/1077] Think multiple instances of both SELECTED_OUTPUT and USER_PUNCH are working. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7865 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 11 +++- Phreeqc.cpp | 7 +++ Phreeqc.h | 11 +++- UserPunch.cpp | 19 ++++++ UserPunch.h | 25 ++++++++ inverse.cpp | 51 ++++++++------- mainsubs.cpp | 2 + print.cpp | 11 ++++ read.cpp | 151 ++++++++++++++++++++++++++++++++++++++++++++- structures.cpp | 3 + tidy.cpp | 17 ++++- 11 files changed, 277 insertions(+), 31 deletions(-) create mode 100644 UserPunch.cpp create mode 100644 UserPunch.h diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 69dc97a8..5e70d8a1 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -115,9 +115,12 @@ fpunchf_user(int user_index, const char *format, double d) const char *name; // check headings + //if (user_index < user_punch_count_headings) + int user_punch_count_headings = (int) current_user_punch->Get_headings().size(); if (user_index < user_punch_count_headings) { - name = user_punch_headings[user_index]; + //name = user_punch_headings[user_index]; + name = current_user_punch->Get_headings()[user_index].c_str(); } else { @@ -146,11 +149,13 @@ void Phreeqc:: fpunchf_user(int user_index, const char *format, char * d) { const char *name; - + + int user_punch_count_headings = (int) current_user_punch->Get_headings().size(); // check headings if (user_index < user_punch_count_headings) { - name = user_punch_headings[user_index]; + //name = user_punch_headings[user_index]; + name = current_user_punch->Get_headings()[user_index].c_str(); } else { diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 55390cb6..1d96a06a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -224,6 +224,7 @@ void Phreeqc::init(void) last_model.surface_charge = NULL; current_selected_output = NULL; + current_user_punch = NULL; #ifdef SKIP //struct punch punch; /* @@ -640,9 +641,11 @@ void Phreeqc::init(void) * USER PRINT COMMANDS * ---------------------------------------------------------------------- */ user_print = NULL; +#ifdef SKIP user_punch = NULL; user_punch_headings = NULL; user_punch_count_headings = 0; +#endif n_user_punch_index = 0; fpunchf_user_s_warning = 0; fpunchf_user_buffer[0] = 0; @@ -1789,6 +1792,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) user_print->varbase = NULL; user_print->loopbase = NULL; } + + // For now, User Punch is not copied +#ifdef SKIP /* user_punch = NULL; */ @@ -1819,6 +1825,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) user_punch_headings[i] = string_hsave(pSrc->user_punch_headings[i]); } } +#endif n_user_punch_index = pSrc->n_user_punch_index; fpunchf_user_s_warning = pSrc->fpunchf_user_s_warning; //fpunchf_user_buffer[0] = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 1c0607ef..a23beb97 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -29,6 +29,7 @@ #include "dumper.h" #include "PHRQ_io.h" #include "SelectedOutput.h" +#include "UserPunch.h" #ifdef MULTICHART #include "ChartHandler.h" #endif @@ -1515,9 +1516,9 @@ protected: * USER PRINT COMMANDS * ---------------------------------------------------------------------- */ struct rate *user_print; - struct rate *user_punch; - const char **user_punch_headings; - int user_punch_count_headings; + //struct rate *user_punch; + //const char **user_punch_headings; + //int user_punch_count_headings; int n_user_punch_index; int fpunchf_user_s_warning; @@ -1613,6 +1614,9 @@ protected: //char *selected_output_file_name; std::map SelectedOutput_map; SelectedOutput * current_selected_output; + + std::map UserPunch_map; + UserPunch * current_user_punch; char *dump_file_name; int remove_unstable_phases; @@ -1744,6 +1748,7 @@ protected: FILE *netpath_file; int count_inverse_models, count_pat_solutions; int min_position[32], max_position[32], now[32]; + std::vector inverse_heading_names; /* kinetics.cpp ------------------------------- */ public: diff --git a/UserPunch.cpp b/UserPunch.cpp new file mode 100644 index 00000000..661f0ac3 --- /dev/null +++ b/UserPunch.cpp @@ -0,0 +1,19 @@ +#include "UserPunch.h" +#include "Phreeqc.h" +UserPunch::UserPunch(int n, PHRQ_io *io) +: cxxNumKeyword(io) +{ + this->PhreeqcPtr = NULL; + this->rate = NULL; +} + + +UserPunch::~UserPunch(void) +{ + if (this->rate != NULL) + { + this->PhreeqcPtr->rate_free(this->rate); + } + this->PhreeqcPtr->free_check_null(this->rate); + this->rate = NULL; +} diff --git a/UserPunch.h b/UserPunch.h new file mode 100644 index 00000000..bc331696 --- /dev/null +++ b/UserPunch.h @@ -0,0 +1,25 @@ +#if !defined(USERPUNCH_H_INCLUDED) +#define USERPUNCH_H_INCLUDED +#include +#include // std::string +#include "NumKeyword.h" +class Phreeqc; +class UserPunch:public cxxNumKeyword +{ +public: + UserPunch(int n=1, PHRQ_io *io=NULL); + ~UserPunch(void); + + std::vector &Get_headings() {return this->headings;} + void Set_headings(std::vector & h) {this->headings = h;} + Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} + void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} + struct rate * Get_rate() {return this->rate;} + void Set_rate(struct rate * r) {this->rate = r;} + +protected: + std::vector headings; + struct rate * rate; + Phreeqc * PhreeqcPtr; +}; +#endif // !defined(USERPUNCH_H_INCLUDED) \ No newline at end of file diff --git a/inverse.cpp b/inverse.cpp index 8cc799d1..05d89696 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -27,10 +27,11 @@ inverse_models(void) // Revert to previous headings after inverse modeling std::vector old_headings; int i; - for (i = 0; i < user_punch_count_headings; i++) - { - old_headings.push_back(user_punch_headings[i]); - } + + //for (i = 0; i < user_punch_count_headings; i++) + //{ + // old_headings.push_back(user_punch_headings[i]); + //} array1 = NULL; inv_zero = NULL; @@ -134,15 +135,15 @@ inverse_models(void) } } - user_punch_count_headings = (int) old_headings.size(); - user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, - (size_t) (user_punch_count_headings + 1) * sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); - for (i = 0; i < user_punch_count_headings; i++) - { - user_punch_headings[i] = string_hsave(old_headings[i].c_str()); - } + //user_punch_count_headings = (int) old_headings.size(); + //user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, + // (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + //if (user_punch_headings == NULL) + // malloc_error(); + //for (i = 0; i < user_punch_count_headings; i++) + //{ + // user_punch_headings[i] = string_hsave(old_headings[i].c_str()); + //} return (OK); } @@ -2082,6 +2083,7 @@ punch_model_heading(struct inverse *inv_ptr) char token[MAX_LENGTH]; //if (/*punch.in == FALSE ||*/ pr.punch == FALSE || punch.inverse == FALSE) // return (OK); + std::vector heading_names; std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); for ( ; so_it != SelectedOutput_map.end(); so_it++) { @@ -2095,9 +2097,8 @@ punch_model_heading(struct inverse *inv_ptr) continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); - std::vector heading_names; int l = (!current_selected_output->Get_high_precision()) ? 15 : 20; - + heading_names.clear(); /* * Print sum of residuals and maximum fractional error */ @@ -2140,21 +2141,22 @@ punch_model_heading(struct inverse *inv_ptr) size_t j; // punch headings - user_punch_count_headings = (int) heading_names.size(); - user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, - (size_t) (user_punch_count_headings + 1) * sizeof(char *)); - if (user_punch_headings == NULL) - malloc_error(); + //user_punch_count_headings = (int) heading_names.size(); + //user_punch_headings = (const char **) PHRQ_realloc(user_punch_headings, + // (size_t) (user_punch_count_headings + 1) * sizeof(char *)); + //if (user_punch_headings == NULL) + // malloc_error(); for (j = 0; j < heading_names.size(); j++) { fpunchf_heading(heading_names[j].c_str()); - user_punch_headings[j] = string_hsave(heading_names[j].c_str()); + //user_punch_headings[j] = string_hsave(heading_names[j].c_str()); } fpunchf_heading("\n"); } current_selected_output = NULL; phrq_io->Set_punch_ostream(NULL); + inverse_heading_names = heading_names; /* * Flush buffer after each model */ @@ -2174,6 +2176,11 @@ punch_model(struct inverse *inv_ptr) LDBLE d1, d2, d3; //if (punch.in == FALSE || pr.punch == FALSE || punch.inverse == FALSE) // return (OK); + + UserPunch temp_user_punch; + current_user_punch = & temp_user_punch; + temp_user_punch.Set_headings(inverse_heading_names); + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); for ( ; so_it != SelectedOutput_map.end(); so_it++) { @@ -2185,7 +2192,7 @@ punch_model(struct inverse *inv_ptr) !current_selected_output->Get_active()) continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); - + n_user_punch_index = 0; /* * write residual info diff --git a/mainsubs.cpp b/mainsubs.cpp index 874801a1..851b67e5 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -191,6 +191,7 @@ initialize(void) user_print->varbase = NULL; user_print->loopbase = NULL; +#ifdef SKIP // user_punch user_punch = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate)); if (user_punch == NULL) @@ -203,6 +204,7 @@ initialize(void) if (user_punch_headings == NULL) malloc_error(); user_punch_count_headings = 0; +#endif #if defined PHREEQ98 /* * user_graph diff --git a/print.cpp b/print.cpp index c1b39956..3d4fbd19 100644 --- a/print.cpp +++ b/print.cpp @@ -175,6 +175,11 @@ punch_all(void) current_selected_output->punch_ostream == NULL) continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + + // UserPunch + std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user()); + current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second); + punch_identifiers(); punch_totals(); punch_molalities(); @@ -199,6 +204,7 @@ punch_all(void) punch_flush(); } current_selected_output = NULL; + current_user_punch = NULL; phrq_io->Set_punch_ostream(NULL); return (OK); } @@ -3191,6 +3197,11 @@ punch_user_punch(void) n_user_punch_index = 0; //if (punch.user_punch == FALSE) // return (OK); + if (current_user_punch == NULL) + return OK; + + struct rate * user_punch = current_user_punch->Get_rate(); + if (user_punch->commands == NULL) return (OK); if (user_punch->new_def == TRUE) diff --git a/read.cpp b/read.cpp index 266d1555..91e27f4d 100644 --- a/read.cpp +++ b/read.cpp @@ -17,6 +17,7 @@ #include "cxxKinetics.h" #include "Solution.h" #include "SelectedOutput.h" +#include "UserPunch.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -9211,7 +9212,155 @@ read_user_print(void) /* output_msg(sformatf( "%s", rates[0].commands)); */ return (return_value); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_user_punch(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Reads basic code with which to calculate rates + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ + int length, line_length; + int return_value, opt, opt_save; + std::string stdtoken; + char *next_char; + const char *opt_list[] = { + "start", /* 0 */ + "end", /* 1 */ + "heading", /* 2 */ + "headings" /* 3 */ + }; + int count_opt_list = 4; + opt_save = OPTION_DEFAULT; +/* + * Read lines + */ + + int n_user, n_user_end; + char *description; + char *ptr; + ptr = line; + read_number_description(ptr, &n_user, &n_user_end, &description); + + UserPunch temp_user_punch; + temp_user_punch.Set_PhreeqcPtr(this); + temp_user_punch.Set_n_user(n_user); + temp_user_punch.Set_n_user_end(n_user_end); + temp_user_punch.Set_description(description); + free_check_null(description); + + //std::map < int, UserPunch >::iterator up = UserPunch_map.find(n_user); + //if (up != UserPunch_map.end()) + //{ + // UserPunch_map.erase(up); + //} + + // Malloc rate structure + struct rate *r = (struct rate *) PHRQ_malloc(sizeof(struct rate)); + if (r == NULL) malloc_error(); + r->new_def = TRUE; + r->linebase = NULL; + r->varbase = NULL; + r->loopbase = NULL; + r->name = string_hsave("user defined Basic punch routine"); + + return_value = UNKNOWN; + for (;;) + { + opt = get_option(opt_list, count_opt_list, &next_char); + if (opt == OPTION_DEFAULT) + { + opt = opt_save; + } + opt_save = OPTION_DEFAULT; + switch (opt) + { + case OPTION_EOF: /* end of file */ + return_value = EOF; + break; + case OPTION_KEYWORD: /* keyword */ + return_value = KEYWORD; + break; + case OPTION_ERROR: + input_error++; + error_msg("Unknown input in USER_PUNCH keyword.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + case 0: /* start */ + opt_save = OPTION_DEFAULT; + break; + case 1: /* end */ + opt_save = OPTION_DEFAULT; + break; + case 2: /* headings */ + case 3: /* heading */ + while (copy_token(stdtoken, &next_char) != EMPTY) + { + temp_user_punch.Get_headings().push_back(stdtoken); + } + break; + case OPTION_DEFAULT: /* read first command */ + { + r->commands = (char *) PHRQ_malloc(sizeof(char)); + if (r->commands == NULL) malloc_error(); + r->commands[0] = '\0'; + } + //rate_free(user_punch); + //user_punch->new_def = TRUE; + //user_punch->commands = (char *) PHRQ_malloc(sizeof(char)); + //if (user_punch->commands == NULL) + // malloc_error(); + //user_punch->commands[0] = '\0'; + //user_punch->linebase = NULL; + //user_punch->varbase = NULL; + //user_punch->loopbase = NULL; + //user_punch->name = + // string_hsave("user defined Basic punch routine"); + case OPT_1: /* read command */ + length = (int) strlen(r->commands); + line_length = (int) strlen(line); + r->commands = (char *) PHRQ_realloc(r->commands, + (size_t) (length + line_length + 2) * sizeof(char)); + if (r->commands == NULL) malloc_error(); + + r->commands[length] = ';'; + r->commands[length + 1] = '\0'; + strcat((r->commands), line); + //length = (int) strlen(user_punch->commands); + //line_length = (int) strlen(line); + //user_punch->commands = + // (char *) PHRQ_realloc(user_punch->commands, + // (size_t) (length + line_length + + // 2) * sizeof(char)); + //if (user_punch->commands == NULL) + // malloc_error(); + //user_punch->commands[length] = ';'; + //user_punch->commands[length + 1] = '\0'; + //strcat((user_punch->commands), line); + opt_save = OPT_1; + break; + } + if (return_value == EOF || return_value == KEYWORD) + break; + } + + UserPunch_map[n_user] = temp_user_punch; + UserPunch_map[n_user].Set_rate(r); + + return (return_value); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: read_user_punch(void) @@ -9323,7 +9472,7 @@ read_user_punch(void) } return (return_value); } - +#endif #if defined PHREEQ98 /* ---------------------------------------------------------------------- */ int Phreeqc:: diff --git a/structures.cpp b/structures.cpp index 49be79b0..8272c23c 100644 --- a/structures.cpp +++ b/structures.cpp @@ -206,14 +206,17 @@ clean_up(void) (struct name_master *) free_check_null(punch.calculate_values); #endif SelectedOutput_map.clear(); + UserPunch_map.clear(); /* user_print and user_punch */ rate_free(user_print); +#ifdef SKIP rate_free(user_punch); user_print = (struct rate *) free_check_null(user_print); user_punch = (struct rate *) free_check_null(user_punch); user_punch_headings = (const char **) free_check_null(user_punch_headings); +#endif /* Free llnl aqueous model parameters diff --git a/tidy.cpp b/tidy.cpp index 8ecc3f98..faff973c 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1784,6 +1784,11 @@ tidy_punch(void) current_selected_output->punch_ostream == NULL) continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + + // UserPunch + std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user()); + current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second); + int l; SelectedOutput *so_ptr = &so_it->second; if (so_ptr->Get_high_precision() == false) @@ -2187,7 +2192,14 @@ tidy_punch(void) } /* user_punch */ - // TODO, implement user_punch n TODO + if (current_user_punch != NULL) + { + for (size_t i = 0; i < current_user_punch->Get_headings().size(); i++) + { + fpunchf_heading(sformatf("%*s\t", l, current_user_punch->Get_headings()[i].c_str())); + } + } + fpunchf_heading("\n"); //if (punch.user_punch == TRUE) //{ // for (i = 0; i < user_punch_count_headings; i++) @@ -2195,7 +2207,7 @@ tidy_punch(void) // fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); // } //} - fpunchf_heading("\n"); + //fpunchf_heading("\n"); so_ptr->Set_new_def(false); pr.punch = punch_save; @@ -2204,6 +2216,7 @@ tidy_punch(void) punch_flush(); } current_selected_output = NULL; + current_user_punch = NULL; phrq_io->Set_punch_ostream(NULL); return (OK); } From 1afe3e43f3ae8e403e7c72bc3eb341a7cefda471 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 31 Jul 2013 23:17:54 +0000 Subject: [PATCH 0710/1077] Fixed up inverse.cpp a bit. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7866 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index 05d89696..caebfd51 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -26,7 +26,7 @@ inverse_models(void) if (count_inverse <= 0) return OK; // Revert to previous headings after inverse modeling std::vector old_headings; - int i; + //int i; //for (i = 0; i < user_punch_count_headings; i++) //{ @@ -2075,6 +2075,87 @@ print_model(struct inverse *inv_ptr) int Phreeqc:: punch_model_heading(struct inverse *inv_ptr) /* ---------------------------------------------------------------------- */ +{ + /* + * Prints model headings to selected output file + */ + int i; + char token[MAX_LENGTH]; + + std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) + { + // set punch file + current_selected_output = &(so_it->second); + if (pr.punch == FALSE || + current_selected_output == NULL || + current_selected_output->punch_ostream == NULL || + !current_selected_output->Get_inverse() || + !current_selected_output->Get_active()) + continue; + phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + + int l = (!current_selected_output->Get_high_precision()) ? 15 : 20; + inverse_heading_names.clear(); + /* + * Print sum of residuals and maximum fractional error + */ + inverse_heading_names.push_back(sformatf("%*s\t", l, "Sum_resid")); + inverse_heading_names.push_back(sformatf("%*s\t", l, "Sum_Delta/U")); + inverse_heading_names.push_back(sformatf("%*s\t", l, "MaxFracErr")); + + /* + * Print solution numbers + */ + for (i = 0; i < inv_ptr->count_solns; i++) + { + sprintf(token, "Soln_%d", inv_ptr->solns[i]); + std::string tok1(token); + tok1.append("_min"); + std::string tok2(token); + tok2.append("_max"); + + inverse_heading_names.push_back(sformatf("%*s\t", l, token)); + inverse_heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + inverse_heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + } + /* + * Print phase names + */ + for (i = col_phases; i < col_redox; i++) + { + + std::string tok1(col_name[i]); + tok1.append("_max"); + std::string tok2(col_name[i]); + tok2.append("_max"); + + inverse_heading_names.push_back(sformatf("%*s\t", l, col_name[i])); + inverse_heading_names.push_back(sformatf("%*s\t", l, tok1.c_str())); + inverse_heading_names.push_back(sformatf("%*s\t", l, tok2.c_str())); + } + + size_t j; + for (j = 0; j < inverse_heading_names.size(); j++) + { + fpunchf_heading(inverse_heading_names[j].c_str()); + //user_punch_headings[j] = string_hsave(heading_names[j].c_str()); + } + fpunchf_heading("\n"); + } + current_selected_output = NULL; + phrq_io->Set_punch_ostream(NULL); + /* + * Flush buffer after each model + */ + punch_flush(); + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +punch_model_heading(struct inverse *inv_ptr) +/* ---------------------------------------------------------------------- */ { /* * Prints model headings to selected output file @@ -2163,7 +2244,7 @@ punch_model_heading(struct inverse *inv_ptr) punch_flush(); return (OK); } - +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_model(struct inverse *inv_ptr) From 6fd2cc8b59253eda4db25cf211641cc645628ab2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 31 Jul 2013 23:22:25 +0000 Subject: [PATCH 0711/1077] Fixed missing -pressure in solution dump_raw and read_raw. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7867 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 92b3b6be..e1783fb7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -219,6 +219,9 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1; s_oss << "-temp " << this->tc << "\n"; + s_oss << indent1; + s_oss << "-pressure " << this->patm << "\n"; + // new identifier s_oss << indent1; s_oss << "-total_h " << this->total_h << "\n"; @@ -880,12 +883,21 @@ cxxSolution::read_raw(CParser & parser, bool check) this->density = 1.0; parser.incr_input_error(); parser.error_msg("Expected numeric value for density.", - PHRQ_io::OT_CONTINUE); + PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; + case 22: // pressure + if (!(parser.get_iss() >> this->patm)) + { + this->patm = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for pressure.", + PHRQ_io::OT_CONTINUE); } opt_save = CParser::OPT_DEFAULT; break; } - if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; } @@ -1392,6 +1404,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("total_alk"), // 18 std::vector< std::string >::value_type("cb"), // 19 std::vector< std::string >::value_type("charge_balance"), // 20 - std::vector< std::string >::value_type("density") // 21 + std::vector< std::string >::value_type("density"), // 21 + std::vector< std::string >::value_type("pressure") // 22 }; const std::vector< std::string > cxxSolution::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file From d436c9cf4f963577569617a95bc41e87d703701c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Aug 2013 20:35:33 +0000 Subject: [PATCH 0712/1077] bugs linux caught, something different about when to print headings git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7874 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 8 ++++---- SelectedOutput.cpp | 4 ++-- SelectedOutput.h | 8 ++++---- isotopes.cpp | 4 ++-- read.cpp | 2 +- readtr.cpp | 10 +++++----- tidy.cpp | 1 + 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 4b2e064f..40129b03 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -472,7 +472,7 @@ numtostr(char * Result, LDBLE n) /* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ if (ceil(n) == floor(n)) { - if (!PhreeqcPtr->current_selected_output != NULL && + if (PhreeqcPtr->current_selected_output != NULL && !PhreeqcPtr->current_selected_output->Get_high_precision()) { sprintf(l_s, "%12.0f", (double) n); @@ -484,7 +484,7 @@ numtostr(char * Result, LDBLE n) } else { - if (!PhreeqcPtr->current_selected_output != NULL && + if (PhreeqcPtr->current_selected_output != NULL && !PhreeqcPtr->current_selected_output->Get_high_precision()) { sprintf(l_s, "%12.4e", (double) n); @@ -4397,7 +4397,7 @@ cmdpunch(struct LOC_exec *LINK) if (n.stringval) { /* fputs(n.UU.sval, stdout); */ - if (!PhreeqcPtr->current_selected_output != NULL && + if (PhreeqcPtr->current_selected_output != NULL && !PhreeqcPtr->current_selected_output->Get_high_precision()) { if (strlen(n.UU.sval) <= 12) @@ -4422,7 +4422,7 @@ cmdpunch(struct LOC_exec *LINK) } PhreeqcPtr->PHRQ_free(n.UU.sval); } - else if (!PhreeqcPtr->current_selected_output != NULL && + else if (PhreeqcPtr->current_selected_output != NULL && !PhreeqcPtr->current_selected_output->Get_high_precision()) { PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 35948f03..6d0fd607 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -38,7 +38,7 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io) this->user_punch = true; this->charge_balance = false; this->percent_error = false; - this->punch = false; + //this->punch = false; } @@ -76,4 +76,4 @@ SelectedOutput::Set_file_name(int n) std::ostringstream os; os << "selected_output_" << n << ".sel"; file_name = os.str(); -} \ No newline at end of file +} diff --git a/SelectedOutput.h b/SelectedOutput.h index 2befd46f..44943934 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -42,7 +42,7 @@ public: bool Get_charge_balance(void) {return this->charge_balance;} bool Get_percent_error(void) {return this->percent_error;} bool Get_inverse(void) {return this->inverse;} - bool Get_punch(void) {return this->punch;} + //bool Get_punch(void) {return this->punch;} bool Get_active(void) {return this->active;} void Set_file_name(int i); @@ -67,7 +67,7 @@ public: void Set_charge_balance(bool tf) {this->charge_balance = tf;} void Set_percent_error(bool tf) {this->percent_error = tf;} void Set_inverse(bool tf) {this->inverse = tf;} - void Set_punch(bool tf) {this->punch = tf;} + //void Set_punch(bool tf) {this->punch = tf;} void Set_active(bool tf) {this->active = tf;} std::string file_name; @@ -103,6 +103,6 @@ public: bool charge_balance; bool percent_error; bool inverse; - bool punch; + //bool punch; }; -#endif // !defined(SELECTEDOUTPUT_H_INCLUDED) \ No newline at end of file +#endif // !defined(SELECTEDOUTPUT_H_INCLUDED) diff --git a/isotopes.cpp b/isotopes.cpp index 3d9d6373..f77f213a 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -930,12 +930,12 @@ punch_calculate_values(void) } if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first), + fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first.c_str()), "%12.4e\t", (double) result); } else { - fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first), + fpunchf(sformatf("V_%s", current_selected_output->Get_calculate_values()[i].first.c_str()), "%20.12e\t", (double) result); } } diff --git a/read.cpp b/read.cpp index 91e27f4d..1f53d4bb 100644 --- a/read.cpp +++ b/read.cpp @@ -4970,7 +4970,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); value = get_true_false(next_char, TRUE); - temp_selected_output.Set_punch(value!=FALSE); + temp_selected_output.Set_active(value!=FALSE); opt_save = OPTION_ERROR; break; case 49: /* active */ diff --git a/readtr.cpp b/readtr.cpp index dce894c3..3910c381 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1033,7 +1033,7 @@ dump_cpp(void) fs << token; for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++) { - sprintf(token, " %s", current_selected_output->Get_molalities()[i].first.size()); + sprintf(token, " %s", current_selected_output->Get_molalities()[i].first.c_str()); fs << token; } sprintf(token, "\n"); @@ -1151,7 +1151,7 @@ dump_cpp(void) } sprintf(token, "\t-length\n"); fs << token; - for (size_t i = 0; i < count_cells; i++) + for (int i = 0; i < count_cells; i++) { sprintf(token, "%12.3e", (double) cell_data[i].length); fs << token; @@ -1165,7 +1165,7 @@ dump_cpp(void) fs << token; sprintf(token, "\t-disp\n"); fs << token; - for (size_t i = 0; i < count_cells; i++) + for (int i = 0; i < count_cells; i++) { if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) { @@ -1192,7 +1192,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (size_t i = 0; i < j; i++) + for (int i = 0; i < j; i++) { if (cell_data[i].punch != TRUE) continue; @@ -1214,7 +1214,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (size_t i = 0; i < j; i++) + for (int i = 0; i < j; i++) { if (cell_data[i].print != TRUE) continue; diff --git a/tidy.cpp b/tidy.cpp index faff973c..0367fff4 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1781,6 +1781,7 @@ tidy_punch(void) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || + !current_selected_output->Get_active() || current_selected_output->punch_ostream == NULL) continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); From 27b3c056841f41de84051edce26d9283c71274a2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Aug 2013 21:00:50 +0000 Subject: [PATCH 0713/1077] Working on multipunch git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7875 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 27 ++++++++++++++++++--------- PHRQ_io_output.cpp | 6 +++++- read.cpp | 2 +- readtr.cpp | 24 ++++++++++++------------ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 40129b03..664fc2a4 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -472,26 +472,35 @@ numtostr(char * Result, LDBLE n) /* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ if (ceil(n) == floor(n)) { + //if (PhreeqcPtr->current_selected_output != NULL && + // !PhreeqcPtr->current_selected_output->Get_high_precision()) + //{ + // sprintf(l_s, "%12.0f", (double) n); + //} + //else + //{ + // sprintf(l_s, "%20.0f", (double) n); + //} if (PhreeqcPtr->current_selected_output != NULL && - !PhreeqcPtr->current_selected_output->Get_high_precision()) + PhreeqcPtr->current_selected_output->Get_high_precision()) { - sprintf(l_s, "%12.0f", (double) n); + sprintf(l_s, "%20.0f", (double) n); } else { - sprintf(l_s, "%20.0f", (double) n); + sprintf(l_s, "%12.0f", (double) n); } } else { if (PhreeqcPtr->current_selected_output != NULL && - !PhreeqcPtr->current_selected_output->Get_high_precision()) + PhreeqcPtr->current_selected_output->Get_high_precision()) { - sprintf(l_s, "%12.4e", (double) n); + sprintf(l_s, "%20.4e", (double) n); } else { - sprintf(l_s, "%20.12e", (double) n); + sprintf(l_s, "%12.12e", (double) n); } } i = (int) strlen(l_s) + 1; @@ -4423,13 +4432,13 @@ cmdpunch(struct LOC_exec *LINK) PhreeqcPtr->PHRQ_free(n.UU.sval); } else if (PhreeqcPtr->current_selected_output != NULL && - !PhreeqcPtr->current_selected_output->Get_high_precision()) + PhreeqcPtr->current_selected_output->Get_high_precision()) { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.4e\t", (double) n.UU.val); } else { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.12e\t", (double) n.UU.val); + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.12e\t", (double) n.UU.val); } ++PhreeqcPtr->n_user_punch_index; } diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 5e70d8a1..cb7b94a5 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -113,7 +113,9 @@ void Phreeqc:: fpunchf_user(int user_index, const char *format, double d) { const char *name; - + + if (current_user_punch == NULL) + return; // check headings //if (user_index < user_punch_count_headings) int user_punch_count_headings = (int) current_user_punch->Get_headings().size(); @@ -150,6 +152,8 @@ fpunchf_user(int user_index, const char *format, char * d) { const char *name; + if (current_user_punch == NULL) + return; int user_punch_count_headings = (int) current_user_punch->Get_headings().size(); // check headings if (user_index < user_punch_count_headings) diff --git a/read.cpp b/read.cpp index 1f53d4bb..0652e0df 100644 --- a/read.cpp +++ b/read.cpp @@ -4968,7 +4968,7 @@ read_selected_output(void) case 44: /* selected_out */ case 45: /* selected_output */ temp_selected_output.Set_new_def(true); - warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); + //warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); value = get_true_false(next_char, TRUE); temp_selected_output.Set_active(value!=FALSE); opt_save = OPTION_ERROR; diff --git a/readtr.cpp b/readtr.cpp index 3910c381..d128fc9e 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1127,12 +1127,12 @@ dump_cpp(void) fs << token; sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; - if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) - { - sprintf(token, "\t-diffc %13.5e\n", (double) diffc); - fs << token; - } - else + //if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) + //{ + // sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + // fs << token; + //} + //else { sprintf(token, "\t-diffc %20.12e\n", (double) diffc); fs << token; @@ -1167,12 +1167,12 @@ dump_cpp(void) fs << token; for (int i = 0; i < count_cells; i++) { - if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) - { - sprintf(token, "%12.3e", (double) cell_data[i].disp); - fs << token; - } - else + //if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) + //{ + // sprintf(token, "%12.3e", (double) cell_data[i].disp); + // fs << token; + //} + //else { sprintf(token, "%20.12e", (double) cell_data[i].disp); fs << token; From ce4284a561ed57012f62448c5926914673a42c17 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Aug 2013 22:48:14 +0000 Subject: [PATCH 0714/1077] working on high_precision, using SELECTED_OUTPUT 1 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7876 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 34 ++++++++++++++++++++-------------- Phreeqc.cpp | 2 ++ Phreeqc.h | 1 + read.cpp | 4 ++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 664fc2a4..917ba738 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -481,26 +481,30 @@ numtostr(char * Result, LDBLE n) //{ // sprintf(l_s, "%20.0f", (double) n); //} - if (PhreeqcPtr->current_selected_output != NULL && - PhreeqcPtr->current_selected_output->Get_high_precision()) + bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ? + PhreeqcPtr->current_selected_output->Get_high_precision() : + PhreeqcPtr->high_precision; + if (!temp_high_precision) { - sprintf(l_s, "%20.0f", (double) n); + sprintf(l_s, "%12.0f", (double) n); } else { - sprintf(l_s, "%12.0f", (double) n); + sprintf(l_s, "%20.0f", (double) n); } } else { - if (PhreeqcPtr->current_selected_output != NULL && - PhreeqcPtr->current_selected_output->Get_high_precision()) + bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ? + PhreeqcPtr->current_selected_output->Get_high_precision() : + PhreeqcPtr->high_precision; + if (!temp_high_precision) { - sprintf(l_s, "%20.4e", (double) n); + sprintf(l_s, "%12.4e", (double) n); } else { - sprintf(l_s, "%12.12e", (double) n); + sprintf(l_s, "%20.12e", (double) n); } } i = (int) strlen(l_s) + 1; @@ -4403,11 +4407,14 @@ cmdpunch(struct LOC_exec *LINK) continue; } n = expr(LINK); + bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ? + PhreeqcPtr->current_selected_output->Get_high_precision() : + PhreeqcPtr->high_precision; if (n.stringval) { /* fputs(n.UU.sval, stdout); */ - if (PhreeqcPtr->current_selected_output != NULL && - !PhreeqcPtr->current_selected_output->Get_high_precision()) + + if (!temp_high_precision) { if (strlen(n.UU.sval) <= 12) { @@ -4431,14 +4438,13 @@ cmdpunch(struct LOC_exec *LINK) } PhreeqcPtr->PHRQ_free(n.UU.sval); } - else if (PhreeqcPtr->current_selected_output != NULL && - PhreeqcPtr->current_selected_output->Get_high_precision()) + else if (!temp_high_precision) { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.4e\t", (double) n.UU.val); + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.4e\t", (double) n.UU.val); } else { - PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%12.12e\t", (double) n.UU.val); + PhreeqcPtr->fpunchf_user(PhreeqcPtr->n_user_punch_index, "%20.12e\t", (double) n.UU.val); } ++PhreeqcPtr->n_user_punch_index; } diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1d96a06a..c40c949c 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -225,6 +225,7 @@ void Phreeqc::init(void) current_selected_output = NULL; current_user_punch = NULL; + high_precision = false; #ifdef SKIP //struct punch punch; /* @@ -1158,6 +1159,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) * Initialize punch */ //-- skip punch, accept init + high_precision = pSrc->high_precision; Rxn_temperature_map = pSrc->Rxn_temperature_map; Rxn_pressure_map = pSrc->Rxn_pressure_map; diff --git a/Phreeqc.h b/Phreeqc.h index a23beb97..42a29f5f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1142,6 +1142,7 @@ protected: struct model last_model; //struct punch punch; + bool high_precision; /* ---------------------------------------------------------------------- * Temperatures diff --git a/read.cpp b/read.cpp index 0652e0df..8eb26351 100644 --- a/read.cpp +++ b/read.cpp @@ -4941,6 +4941,10 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); value = get_true_false(next_char, TRUE); temp_selected_output.Set_high_precision(value!=FALSE); + if (n_user == 1) + { + high_precision = (value != FALSE); + } if (value == TRUE) { convergence_tolerance = 1e-12; From 8474b5352070b9cee7fb50cddabd96e18b167420 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Aug 2013 23:37:05 +0000 Subject: [PATCH 0715/1077] dump precision git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7877 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index d128fc9e..c3cdba7f 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1127,12 +1127,12 @@ dump_cpp(void) fs << token; sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; - //if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) - //{ - // sprintf(token, "\t-diffc %13.5e\n", (double) diffc); - // fs << token; - //} - //else + if (!high_precision) + { + sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + fs << token; + } + else { sprintf(token, "\t-diffc %20.12e\n", (double) diffc); fs << token; @@ -1167,12 +1167,12 @@ dump_cpp(void) fs << token; for (int i = 0; i < count_cells; i++) { - //if (current_selected_output != NULL && !current_selected_output->Get_high_precision()) - //{ - // sprintf(token, "%12.3e", (double) cell_data[i].disp); - // fs << token; - //} - //else + if (!high_precision) + { + sprintf(token, "%12.3e", (double) cell_data[i].disp); + fs << token; + } + else { sprintf(token, "%20.12e", (double) cell_data[i].disp); fs << token; From 62feec3f96dea5fd09643c0187ce78008085a643 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 2 Aug 2013 16:00:45 +0000 Subject: [PATCH 0716/1077] Making backward compatible. Copying all but lists. Revised tidy_punch logic. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7879 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 22 ++ tidy.cpp | 833 +++++++++++++++++++++++++++---------------------------- 2 files changed, 437 insertions(+), 418 deletions(-) diff --git a/read.cpp b/read.cpp index 8eb26351..b2092599 100644 --- a/read.cpp +++ b/read.cpp @@ -4674,6 +4674,28 @@ read_selected_output(void) // find if it exists std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); + if (so != SelectedOutput_map.end()) + { + SelectedOutput & so_ref = so->second; + temp_selected_output.inverse = so_ref.inverse; + temp_selected_output.sim = so_ref.sim; + temp_selected_output.state = so_ref.state; + temp_selected_output.soln = so_ref.soln; + temp_selected_output.dist = so_ref.dist; + temp_selected_output.time = so_ref.time; + temp_selected_output.step = so_ref.step; + temp_selected_output.rxn = so_ref.rxn; + temp_selected_output.temp = so_ref.temp; + temp_selected_output.ph = so_ref.ph; + temp_selected_output.pe = so_ref.pe; + temp_selected_output.alk = so_ref.alk; + temp_selected_output.mu = so_ref.mu; + temp_selected_output.water = so_ref.water; + temp_selected_output.high_precision = so_ref.high_precision; + temp_selected_output.user_punch = so_ref.user_punch; + temp_selected_output.charge_balance = so_ref.charge_balance; + temp_selected_output.percent_error = so_ref.percent_error; + } CParser parser(this->phrq_io); diff --git a/tidy.cpp b/tidy.cpp index 0367fff4..69ebcf98 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1779,20 +1779,81 @@ tidy_punch(void) for ( ; so_it != SelectedOutput_map.end(); so_it++) { current_selected_output = &(so_it->second); - if (pr.punch == FALSE || - current_selected_output == NULL || - !current_selected_output->Get_active() || + if (current_selected_output == NULL || current_selected_output->punch_ostream == NULL) continue; + + + /* totals */ + + for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_totals()[i]; + pair_ptr.second = master_bsearch(pair_ptr.first.c_str()); + } + + /* molalities */ + for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_molalities()[i]; + pair_ptr.second = s_search(pair_ptr.first.c_str()); + } + + /* log activities */ + + //for (i = 0; i < punch.count_activities; i++) + for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++) + { + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_activities()[i]; + pair_ptr.second = s_search(pair_ptr.first.c_str()); + } + + /* equilibrium phases */ + + //for (i = 0; i < punch.count_pure_phases; i++) + for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_pure_phases()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + } + + /* saturation indices */ + + //for (i = 0; i < punch.count_si; i++) + for (size_t i = 0; i < current_selected_output->Get_si().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_si()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + } + + /* gases */ + + //for (i = 0; i < punch.count_gases; i++) + for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++) + { + int j; + std::pair< std::string, void *> &pair_ptr = current_selected_output->Get_gases()[i]; + pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); + } + } + /* + * Always write new headings when SELECTED_OUTPUT is read + */ + so_it = SelectedOutput_map.begin(); + for ( ; so_it != SelectedOutput_map.end(); so_it++) + { + current_selected_output = &(so_it->second); + if (current_selected_output == NULL || + current_selected_output->punch_ostream == NULL || + !current_selected_output->Get_new_def()) + continue; phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); - - // UserPunch - std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user()); - current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second); + int l; - SelectedOutput *so_ptr = &so_it->second; - if (so_ptr->Get_high_precision() == false) + if (current_selected_output->Get_high_precision() == false) { l = 12; } @@ -1800,422 +1861,358 @@ tidy_punch(void) { l = 20; } - //if (punch.in == TRUE) - //{ - /* totals */ + // UserPunch + std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user()); + current_user_punch = up_it == UserPunch_map.end() ? NULL : &(up_it->second); - for (size_t i = 0; i < so_ptr->Get_totals().size(); i++) - { - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_totals()[i]; - pair_ptr.second = master_bsearch(pair_ptr.first.c_str()); - //punch.totals[i].master = master_bsearch(punch.totals[i].name); - } + punch_save = pr.punch; + pr.punch = TRUE; + phrq_io->Set_punch_on(true); - /* molalities */ - for (size_t i = 0; i < so_ptr->Get_molalities().size(); i++) - { - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_molalities()[i]; - pair_ptr.second = s_search(pair_ptr.first.c_str()); - //punch.molalities[i].s = s_search(punch.molalities[i].name); - } + /* constant stuff, sim, pH, etc. */ - /* log activities */ - - //for (i = 0; i < punch.count_activities; i++) - for (size_t i = 0; i < so_ptr->Get_activities().size(); i++) - { - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_activities()[i]; - pair_ptr.second = s_search(pair_ptr.first.c_str()); - //punch.activities[i].s = s_search(punch.activities[i].name); - } - - /* equilibrium phases */ - - //for (i = 0; i < punch.count_pure_phases; i++) - for (size_t i = 0; i < so_ptr->Get_pure_phases().size(); i++) - { - int j; - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_pure_phases()[i]; - pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); - //punch.pure_phases[i].phase = - // phase_bsearch(punch.pure_phases[i].name, &j, FALSE); - } - - /* saturation indices */ - - //for (i = 0; i < punch.count_si; i++) - for (size_t i = 0; i < so_ptr->Get_si().size(); i++) - { - int j; - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_si()[i]; - pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); - //punch.si[i].phase = phase_bsearch(punch.si[i].name, &j, FALSE); - } - - /* gases */ - - //for (i = 0; i < punch.count_gases; i++) - for (size_t i = 0; i < so_ptr->Get_gases().size(); i++) - { - int j; - std::pair< std::string, void *> &pair_ptr = so_ptr->Get_gases()[i]; - pair_ptr.second = phase_bsearch(pair_ptr.first.c_str(), &j, FALSE); - //punch.gases[i].phase = - // phase_bsearch(punch.gases[i].name, &j, FALSE); - } - //} - /* - * Always write new headings when SELECTED_OUTPUT is read - */ - if (so_ptr->Get_new_def()) + if (current_selected_output->Get_sim() == TRUE) { - punch_save = pr.punch; - pr.punch = TRUE; - phrq_io->Set_punch_on(true); - - /* constant stuff, sim, pH, etc. */ - - if (so_ptr->Get_sim() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "sim")); - } - if (so_ptr->Get_state() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "state")); - } - if (so_ptr->Get_soln() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "soln")); - } - if (so_ptr->Get_dist() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "dist_x")); - } - if (so_ptr->Get_time() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "time")); - } - if (so_ptr->Get_step() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "step")); - } - if (so_ptr->Get_ph() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pH")); - } - if (so_ptr->Get_pe() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pe")); - } - if (so_ptr->Get_rxn() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "reaction")); - } - if (so_ptr->Get_temp() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "temp")); - } - if (so_ptr->Get_alk() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "Alk")); - } - if (so_ptr->Get_mu() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "mu")); - } - if (so_ptr->Get_water() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "mass_H2O")); - } - if (so_ptr->Get_charge_balance() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "charge")); - } - if (so_ptr->Get_percent_error() == TRUE) - { - fpunchf_heading(sformatf("%*s\t", l, "pct_err")); - } - /* totals */ - - //for (i = 0; i < punch.count_totals; i++) - for (size_t i = 0; i < so_ptr->Get_totals().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_totals()[i]; - fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find master species," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name)); - //if (punch.totals[i].master == NULL) - //{ - // error_string = sformatf( "Did not find master species," - // " %s.", punch.totals[i].name); - // warning_msg(error_string); - //} - } - - /* molalities */ - - //for (i = 0; i < punch.count_molalities; i++) - for (size_t i = 0; i < so_ptr->Get_molalities().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_molalities()[i]; - std::string name = "m_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find species," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //strcpy(token, "m_"); - //strcat(token, punch.molalities[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //if (punch.molalities[i].s == NULL) - //{ - // error_string = sformatf( "Did not find species," - // " %s.", punch.molalities[i].name); - // warning_msg(error_string); - //} - } - - /* log activities */ - - //for (i = 0; i < punch.count_activities; i++) - for (size_t i = 0; i < so_ptr->Get_activities().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_activities()[i]; - std::string name = "la_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find species," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //strcpy(token, "la_"); - //strcat(token, punch.activities[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //if (punch.activities[i].s == NULL) - //{ - // error_string = sformatf( "Did not find species, " - // "%s.", punch.activities[i].name); - // warning_msg(error_string); - //} - } - - /* equilibrium phases */ - - //for (i = 0; i < punch.count_pure_phases; i++) - for (size_t i = 0; i < so_ptr->Get_pure_phases().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_pure_phases()[i]; - fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); - std::string name = "d_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find phase," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //strcpy(token, "d_"); - //strcat(token, punch.pure_phases[i].name); - //fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name)); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //if (punch.pure_phases[i].phase == NULL) - //{ - // error_string = sformatf( "Did not find phase, " - // "%s.", punch.pure_phases[i].name); - // warning_msg(error_string); - //} - } - - /* saturation indices */ - - //for (i = 0; i < punch.count_si; i++) - for (size_t i = 0; i < so_ptr->Get_si().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_si()[i]; - std::string name = "si_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find phase," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //strcpy(token, "si_"); - //strcat(token, punch.si[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //if (punch.si[i].phase == NULL) - //{ - // error_string = sformatf( "Did not find phase, " - // "%s.", punch.si[i].name); - // warning_msg(error_string); - //} - } - - /* gases */ - - //if (punch.count_gases > 0) - if (so_ptr->Get_gases().size() > 0) - { - fpunchf_heading(sformatf("%*s\t", l, "pressure")); - fpunchf_heading(sformatf("%*s\t", l, "total mol")); - fpunchf_heading(sformatf("%*s\t", l, "volume")); - } - //for (i = 0; i < punch.count_gases; i++) - for (size_t i = 0; i < so_ptr->Get_gases().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_gases()[i]; - std::string name = "g_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - if (pair_ref.second == NULL) - { - error_string = sformatf( "Did not find phase," - " %s.", pair_ref.first.c_str()); - warning_msg(error_string); - } - //strcpy(token, "g_"); - //strcat(token, punch.gases[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //if (punch.gases[i].phase == NULL) - //{ - // error_string = sformatf( "Did not find phase, " - // "%s.", punch.gases[i].name); - // warning_msg(error_string); - //} - } - - /* kinetics */ - - //for (i = 0; i < punch.count_kinetics; i++) - for (size_t i = 0; i < so_ptr->Get_kinetics().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_kinetics()[i]; - std::string name = "k_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - name = "dk_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - //strcpy(token, "k_"); - //strcat(token, punch.kinetics[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - //strcpy(token, "dk_"); - //strcat(token, punch.kinetics[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* solid solutions */ - - //for (i = 0; i < punch.count_s_s; i++) - for (size_t i = 0; i < so_ptr->Get_s_s().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_s_s()[i]; - std::string name = "ss_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - //strcpy(token, "s_"); - //strcat(token, punch.s_s[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* isotopes */ - - //for (i = 0; i < punch.count_isotopes; i++) - for (size_t i = 0; i < so_ptr->Get_isotopes().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_isotopes()[i]; - if (isotope_ratio_search(pair_ref.first.c_str()) == NULL) - { - error_string = sformatf( - "Did not find isotope_ratio definition for " - "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", - pair_ref.first.c_str(), pair_ref.first.c_str()); - warning_msg(error_string); - } - std::string name = "I_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - //if (isotope_ratio_search(punch.isotopes[i].name) == NULL) - //{ - // error_string = sformatf( - // "Did not find isotope_ratio definition for " - // "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", - // punch.isotopes[i].name, punch.isotopes[i].name); - // warning_msg(error_string); - //} - //strcpy(token, "I_"); - //strcat(token, punch.isotopes[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* calculate_values */ - - //for (i = 0; i < punch.count_calculate_values; i++) - for (size_t i = 0; i < so_ptr->Get_calculate_values().size(); i++) - { - std::pair< std::string, void *> &pair_ref = so_ptr->Get_calculate_values()[i]; - if (calculate_value_search(pair_ref.first.c_str()) == NULL) - { - error_string = sformatf( - "Did not find calculate_values definition for " - "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", - pair_ref.first.c_str(), - pair_ref.first.c_str()); - warning_msg(error_string); - } - std::string name = "V_"; - name.append(pair_ref.first); - fpunchf_heading(sformatf("%*s\t", l, name.c_str())); - //if (calculate_value_search(punch.calculate_values[i].name) == NULL) - //{ - // error_string = sformatf( - // "Did not find calculate_values definition for " - // "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", - // punch.calculate_values[i].name, - // punch.calculate_values[i].name); - // warning_msg(error_string); - //} - //strcpy(token, "V_"); - //strcat(token, punch.calculate_values[i].name); - //fpunchf_heading(sformatf("%*s\t", l, token)); - } - - /* user_punch */ - if (current_user_punch != NULL) - { - for (size_t i = 0; i < current_user_punch->Get_headings().size(); i++) - { - fpunchf_heading(sformatf("%*s\t", l, current_user_punch->Get_headings()[i].c_str())); - } - } - fpunchf_heading("\n"); - //if (punch.user_punch == TRUE) - //{ - // for (i = 0; i < user_punch_count_headings; i++) - // { - // fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); - // } - //} - //fpunchf_heading("\n"); - - so_ptr->Set_new_def(false); - pr.punch = punch_save; - phrq_io->Set_punch_on(pr.punch == TRUE); + fpunchf_heading(sformatf("%*s\t", l, "sim")); } + if (current_selected_output->Get_state() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "state")); + } + if (current_selected_output->Get_soln() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "soln")); + } + if (current_selected_output->Get_dist() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "dist_x")); + } + if (current_selected_output->Get_time() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "time")); + } + if (current_selected_output->Get_step() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "step")); + } + if (current_selected_output->Get_ph() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pH")); + } + if (current_selected_output->Get_pe() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pe")); + } + if (current_selected_output->Get_rxn() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "reaction")); + } + if (current_selected_output->Get_temp() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "temp")); + } + if (current_selected_output->Get_alk() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "Alk")); + } + if (current_selected_output->Get_mu() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mu")); + } + if (current_selected_output->Get_water() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "mass_H2O")); + } + if (current_selected_output->Get_charge_balance() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "charge")); + } + if (current_selected_output->Get_percent_error() == TRUE) + { + fpunchf_heading(sformatf("%*s\t", l, "pct_err")); + } + /* totals */ + + //for (i = 0; i < punch.count_totals; i++) + for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_totals()[i]; + fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find master species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //fpunchf_heading(sformatf("%*s\t", l, punch.totals[i].name)); + //if (punch.totals[i].master == NULL) + //{ + // error_string = sformatf( "Did not find master species," + // " %s.", punch.totals[i].name); + // warning_msg(error_string); + //} + } + + /* molalities */ + + //for (i = 0; i < punch.count_molalities; i++) + for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_molalities()[i]; + std::string name = "m_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "m_"); + //strcat(token, punch.molalities[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.molalities[i].s == NULL) + //{ + // error_string = sformatf( "Did not find species," + // " %s.", punch.molalities[i].name); + // warning_msg(error_string); + //} + } + + /* log activities */ + + //for (i = 0; i < punch.count_activities; i++) + for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_activities()[i]; + std::string name = "la_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find species," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "la_"); + //strcat(token, punch.activities[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.activities[i].s == NULL) + //{ + // error_string = sformatf( "Did not find species, " + // "%s.", punch.activities[i].name); + // warning_msg(error_string); + //} + } + + /* equilibrium phases */ + + //for (i = 0; i < punch.count_pure_phases; i++) + for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_pure_phases()[i]; + fpunchf_heading(sformatf("%*s\t", l, pair_ref.first.c_str())); + std::string name = "d_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "d_"); + //strcat(token, punch.pure_phases[i].name); + //fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name)); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.pure_phases[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.pure_phases[i].name); + // warning_msg(error_string); + //} + } + + /* saturation indices */ + + //for (i = 0; i < punch.count_si; i++) + for (size_t i = 0; i < current_selected_output->Get_si().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_si()[i]; + std::string name = "si_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "si_"); + //strcat(token, punch.si[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.si[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.si[i].name); + // warning_msg(error_string); + //} + } + + /* gases */ + + //if (punch.count_gases > 0) + if (current_selected_output->Get_gases().size() > 0) + { + fpunchf_heading(sformatf("%*s\t", l, "pressure")); + fpunchf_heading(sformatf("%*s\t", l, "total mol")); + fpunchf_heading(sformatf("%*s\t", l, "volume")); + } + //for (i = 0; i < punch.count_gases; i++) + for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_gases()[i]; + std::string name = "g_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + if (pair_ref.second == NULL) + { + error_string = sformatf( "Did not find phase," + " %s.", pair_ref.first.c_str()); + warning_msg(error_string); + } + //strcpy(token, "g_"); + //strcat(token, punch.gases[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //if (punch.gases[i].phase == NULL) + //{ + // error_string = sformatf( "Did not find phase, " + // "%s.", punch.gases[i].name); + // warning_msg(error_string); + //} + } + + /* kinetics */ + + //for (i = 0; i < punch.count_kinetics; i++) + for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_kinetics()[i]; + std::string name = "k_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + name = "dk_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //strcpy(token, "k_"); + //strcat(token, punch.kinetics[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + //strcpy(token, "dk_"); + //strcat(token, punch.kinetics[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* solid solutions */ + + //for (i = 0; i < punch.count_s_s; i++) + for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_s_s()[i]; + std::string name = "s_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //strcpy(token, "s_"); + //strcat(token, punch.s_s[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* isotopes */ + + //for (i = 0; i < punch.count_isotopes; i++) + for (size_t i = 0; i < current_selected_output->Get_isotopes().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_isotopes()[i]; + if (isotope_ratio_search(pair_ref.first.c_str()) == NULL) + { + error_string = sformatf( + "Did not find isotope_ratio definition for " + "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", + pair_ref.first.c_str(), pair_ref.first.c_str()); + warning_msg(error_string); + } + std::string name = "I_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //if (isotope_ratio_search(punch.isotopes[i].name) == NULL) + //{ + // error_string = sformatf( + // "Did not find isotope_ratio definition for " + // "%s in -isotopes of SELECTED_OUTPUT.\n%s must be defined in ISOTOPE_RATIO data block.", + // punch.isotopes[i].name, punch.isotopes[i].name); + // warning_msg(error_string); + //} + //strcpy(token, "I_"); + //strcat(token, punch.isotopes[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* calculate_values */ + + //for (i = 0; i < punch.count_calculate_values; i++) + for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) + { + std::pair< std::string, void *> &pair_ref = current_selected_output->Get_calculate_values()[i]; + if (calculate_value_search(pair_ref.first.c_str()) == NULL) + { + error_string = sformatf( + "Did not find calculate_values definition for " + "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", + pair_ref.first.c_str(), + pair_ref.first.c_str()); + warning_msg(error_string); + } + std::string name = "V_"; + name.append(pair_ref.first); + fpunchf_heading(sformatf("%*s\t", l, name.c_str())); + //if (calculate_value_search(punch.calculate_values[i].name) == NULL) + //{ + // error_string = sformatf( + // "Did not find calculate_values definition for " + // "%s in -calculate_values of SELECTED_OUTPUT.\n%s must be defined in CALCULATE_VALUES data block.", + // punch.calculate_values[i].name, + // punch.calculate_values[i].name); + // warning_msg(error_string); + //} + //strcpy(token, "V_"); + //strcat(token, punch.calculate_values[i].name); + //fpunchf_heading(sformatf("%*s\t", l, token)); + } + + /* user_punch */ + if (current_user_punch != NULL && current_selected_output->Get_user_punch()) + { + for (size_t i = 0; i < current_user_punch->Get_headings().size(); i++) + { + fpunchf_heading(sformatf("%*s\t", l, current_user_punch->Get_headings()[i].c_str())); + } + } + fpunchf_heading("\n"); + //if (punch.user_punch == TRUE) + //{ + // for (i = 0; i < user_punch_count_headings; i++) + // { + // fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i])); + // } + //} + //fpunchf_heading("\n"); + + current_selected_output->Set_new_def(false); + pr.punch = punch_save; + phrq_io->Set_punch_on(pr.punch == TRUE); + punch_flush(); } + current_selected_output = NULL; current_user_punch = NULL; phrq_io->Set_punch_ostream(NULL); From 04141a30987bcb1bb8d257494faf51bed2f34677 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 2 Aug 2013 17:38:40 +0000 Subject: [PATCH 0717/1077] Still working to make backward compatible. Think there will be one diff, headings will not be rewritten (ddl_flux). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7880 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.cpp | 1 - SelectedOutput.h | 1 - print.cpp | 2 +- read.cpp | 16 +++++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 6d0fd607..c53d1acc 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -38,7 +38,6 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io) this->user_punch = true; this->charge_balance = false; this->percent_error = false; - //this->punch = false; } diff --git a/SelectedOutput.h b/SelectedOutput.h index 44943934..9debdbc0 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -103,6 +103,5 @@ public: bool charge_balance; bool percent_error; bool inverse; - //bool punch; }; #endif // !defined(SELECTEDOUTPUT_H_INCLUDED) diff --git a/print.cpp b/print.cpp index 3d4fbd19..1152bf39 100644 --- a/print.cpp +++ b/print.cpp @@ -3197,7 +3197,7 @@ punch_user_punch(void) n_user_punch_index = 0; //if (punch.user_punch == FALSE) // return (OK); - if (current_user_punch == NULL) + if (current_user_punch == NULL || !current_selected_output->Get_user_punch()) return OK; struct rate * user_punch = current_user_punch->Get_rate(); diff --git a/read.cpp b/read.cpp index b2092599..87f5b57a 100644 --- a/read.cpp +++ b/read.cpp @@ -4677,6 +4677,7 @@ read_selected_output(void) if (so != SelectedOutput_map.end()) { SelectedOutput & so_ref = so->second; + temp_selected_output.active = so_ref.active; temp_selected_output.inverse = so_ref.inverse; temp_selected_output.sim = so_ref.sim; temp_selected_output.state = so_ref.state; @@ -4974,10 +4975,12 @@ read_selected_output(void) opt_save = OPTION_ERROR; break; case 39: /* user_punch */ - temp_selected_output.Set_new_def(true); value = get_true_false(next_char, TRUE); temp_selected_output.Set_user_punch(value!=FALSE); - opt_save = OPTION_ERROR; + if (so != SelectedOutput_map.end()) + { + so->second.Set_user_punch(value!=FALSE); + } opt_save = OPTION_ERROR; break; case 42: /* charge_balance */ temp_selected_output.Set_new_def(true); @@ -4993,12 +4996,11 @@ read_selected_output(void) break; case 44: /* selected_out */ case 45: /* selected_output */ - temp_selected_output.Set_new_def(true); //warning_msg("Use PRINT; -selected_output, not SELECTED_OUTPUT; -selected_output"); - value = get_true_false(next_char, TRUE); - temp_selected_output.Set_active(value!=FALSE); - opt_save = OPTION_ERROR; - break; + //value = get_true_false(next_char, TRUE); + //temp_selected_output.Set_active(value!=FALSE); + //opt_save = OPTION_ERROR; + //break; case 49: /* active */ value = get_true_false(next_char, TRUE); temp_selected_output.Set_active(value!=FALSE); From 346cf2239b9fd7a5e56fec72af20df86f74a89ef Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 5 Aug 2013 18:56:31 +0000 Subject: [PATCH 0718/1077] Added a Fortran callback. Will try to revise so that the same callback works for Fortran and C. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7883 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 36 ++++++++++++++++++++++++++++++++++-- PBasic.h | 4 +++- Phreeqc.cpp | 2 ++ Phreeqc.h | 3 +++ basicsubs.cpp | 18 ++++++++++++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index a9de1a81..a29166f9 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1554,8 +1554,12 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("STR_E$"); break; case tokeq_frac: + case tokequiv_frac: output_msg("EQ_FRAC"); break; + case tokcallback: + output_msg("CALLBACK"); + break; } l_buf = l_buf->next; } @@ -3453,6 +3457,33 @@ factor(struct LOC_exec * LINK) *elt_varrec->UU.U1.sval = token; } break; + case tokcallback: + { + double x1, x2; + char * str; + + // left parenthesis + require(toklp, LINK); + + // first double arugument + x1 = realfactor(LINK); + require(tokcomma, LINK); + + // second double arugument + x2 = realfactor(LINK); + require(tokcomma, LINK); + + // string arugument + str = strexpr(LINK); + + require(tokrp, LINK); + + // call callback Basic function + + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x2, str); + + } + break; case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -6720,8 +6751,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("str_e$", PBasic::tokstr_e_), std::map::value_type("species_formula", PBasic::tokspecies_formula), std::map::value_type("species_formula$", PBasic::tokspecies_formula_), - std::map::value_type("eq_frac", PBasic::tokeq_frac) - + std::map::value_type("eq_frac", PBasic::tokeq_frac), + std::map::value_type("equiv_frac", PBasic::tokequiv_frac), + std::map::value_type("callback", PBasic::tokcallback) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index aae6844d..63f8e716 100644 --- a/PBasic.h +++ b/PBasic.h @@ -319,7 +319,9 @@ public: tokkin_time, tokstr_f_, tokstr_e_, - tokeq_frac + tokeq_frac, + tokequiv_frac, + tokcallback }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 6e64c393..c329d212 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -802,6 +802,8 @@ void Phreeqc::init(void) s_pTail = NULL; /* Basic */ basic_interpreter = NULL; + basic_fortran_callback_ptr = NULL; + /* cl1.cpp ------------------------------- */ x_arg = NULL; res_arg = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 6df8472e..2bae2b4f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -82,6 +82,8 @@ public: int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); + double basic_callback(double x1, double x2, char * str); + void register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)); LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); @@ -1692,6 +1694,7 @@ protected: /* Basic */ PBasic * basic_interpreter; + double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; diff --git a/basicsubs.cpp b/basicsubs.cpp index e9d2539b..f61fc670 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3599,3 +3599,21 @@ basic_free(void) delete this->basic_interpreter; } +double Phreeqc:: +basic_callback(double x1, double x2, char * str) +{ + double local_x1 = x1; + double local_x2 = x2; + + if (basic_fortran_callback_ptr != NULL) + { + return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, strlen(str)); + } + return 0; +} + +void +Phreeqc::register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)) +{ + this->basic_fortran_callback_ptr = cookie; +} From 305cd8631d75f573551960ae4fc0e4620fe8ed70 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 5 Aug 2013 20:53:54 +0000 Subject: [PATCH 0719/1077] Revised name to BasicFortran Added methods for C call SetBasicCallback. Need to check C side and documentation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7884 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 ++ basicsubs.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 2bae2b4f..d9550a9b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -83,6 +83,7 @@ public: int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); double basic_callback(double x1, double x2, char * str); + void register_basic_callback(double ( *cookie)(double *x1, double *x2, char *str)); void register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)); LDBLE activity(const char *species_name); @@ -1694,6 +1695,7 @@ protected: /* Basic */ PBasic * basic_interpreter; + double (*basic_callback_ptr) (double *x1, double *x2, char *str); double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); /* cl1.cpp ------------------------------- */ diff --git a/basicsubs.cpp b/basicsubs.cpp index f61fc670..978384cc 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3612,6 +3612,12 @@ basic_callback(double x1, double x2, char * str) return 0; } +void +Phreeqc::register_basic_callback(double ( *cookie)(double *x1, double *x2, char *str)) +{ + this->basic_callback_ptr = cookie; +} + void Phreeqc::register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)) { From 3682cff05bf0aeb862b5723333f47ca8eef11654 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 6 Aug 2013 21:03:02 +0000 Subject: [PATCH 0720/1077] use reset -false by default for SELECTED_OUTPUT n != 1 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7886 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/read.cpp b/read.cpp index 87f5b57a..08831493 100644 --- a/read.cpp +++ b/read.cpp @@ -4674,7 +4674,7 @@ read_selected_output(void) // find if it exists std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); - if (so != SelectedOutput_map.end()) + if (so != SelectedOutput_map.end() && n_user == 1) { SelectedOutput & so_ref = so->second; temp_selected_output.active = so_ref.active; @@ -4697,6 +4697,10 @@ read_selected_output(void) temp_selected_output.charge_balance = so_ref.charge_balance; temp_selected_output.percent_error = so_ref.percent_error; } + else + { + temp_selected_output.Reset(false); + } CParser parser(this->phrq_io); From 88742cdb36406d96dd073027c400bc07736cba6e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Aug 2013 17:01:30 +0000 Subject: [PATCH 0721/1077] Fixed post-build in project Phreeqc.h was jacked up??? The has_infinite block did not end until the end of the file. Made the arguments for the C callback double, double, const char *. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7888 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 16 ++++++++-------- basicsubs.cpp | 6 +++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index d9550a9b..b67566f1 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -83,7 +83,7 @@ public: int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); double basic_callback(double x1, double x2, char * str); - void register_basic_callback(double ( *cookie)(double *x1, double *x2, char *str)); + void register_basic_callback(double ( *cookie)(double x1, double x2, const char *str)); void register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)); LDBLE activity(const char *species_name); @@ -1695,7 +1695,7 @@ protected: /* Basic */ PBasic * basic_interpreter; - double (*basic_callback_ptr) (double *x1, double *x2, char *str); + double (*basic_callback_ptr) (double x1, double x2, const char *str); double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); /* cl1.cpp ------------------------------- */ @@ -1912,7 +1912,12 @@ protected: std::vector keycount; // used to mark keywords that have been read +public: + static const struct const_iso iso_defaults[]; + static const int count_iso_defaults; +}; #endif /* _INC_PHREEQC_H */ + #ifndef _INC_ISFINITE_H #define _INC_ISFINITE_H /********************************* @@ -1938,11 +1943,7 @@ protected: #else # define PHR_ISFINITE(x) ( ((x) == 0.0) || (((x) == (x)) && ((x) != (2.0 * (x)))) ) #endif - -public: - static const struct const_iso iso_defaults[]; - static const int count_iso_defaults; -}; +#endif // _INC_ISFINITE_H namespace Utilities { @@ -2093,4 +2094,3 @@ void PhreeqcIWait(Phreeqc *phreeqc); char * _string_duplicate(const char *token, const char *szFileName, int nLine); #endif -#endif diff --git a/basicsubs.cpp b/basicsubs.cpp index 978384cc..b5401197 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3605,6 +3605,10 @@ basic_callback(double x1, double x2, char * str) double local_x1 = x1; double local_x2 = x2; + if (basic_callback_ptr != NULL) + { + return (*basic_callback_ptr) (x1, x2, (const char *) str); + } if (basic_fortran_callback_ptr != NULL) { return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, strlen(str)); @@ -3613,7 +3617,7 @@ basic_callback(double x1, double x2, char * str) } void -Phreeqc::register_basic_callback(double ( *cookie)(double *x1, double *x2, char *str)) +Phreeqc::register_basic_callback(double ( *cookie)(double x1, double x2, const char *str)) { this->basic_callback_ptr = cookie; } From 1e8a8c036a16620e653d042412b6f4e5c202d003 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Aug 2013 19:11:07 +0000 Subject: [PATCH 0722/1077] Update RELEASE.TXT Added print about fugacity for SI. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7889 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 8509fbbd..a0bab985 100644 --- a/print.cpp +++ b/print.cpp @@ -1206,7 +1206,7 @@ print_saturation_indices(void) * Print heading */ print_centered("Saturation indices"); - output_msg(sformatf("\t%-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI ", + output_msg(sformatf("\t%-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI**", "log IAP", "log K(", int(tk_x), " K, ", int(floor(patm_x + 0.5)), " atm)")); for (i = 0; i < count_phases; i++) @@ -1269,6 +1269,9 @@ print_saturation_indices(void) phases[i]->pr_in = false; output_msg("\n"); } + output_msg(sformatf("\n%s\n%s", + "**For a gas, the value is log10(fugacity). For an ideal gas, fugacity equals partial pressure.", + "For a Peng-Robinson gas, fugacity = (P * phi / 1 atm); P and phi are printed at end of line.")); output_msg("\n\n"); return (OK); From ca3e1128a2bde8fe8ce95afee2576017d7dda150 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 Aug 2013 19:46:57 +0000 Subject: [PATCH 0723/1077] Initialize basic_callback_ptr git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7890 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index c329d212..2b27369e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -802,6 +802,7 @@ void Phreeqc::init(void) s_pTail = NULL; /* Basic */ basic_interpreter = NULL; + basic_callback_ptr = NULL; basic_fortran_callback_ptr = NULL; /* cl1.cpp ------------------------------- */ From 30164dc7fd2de58abbbca0cb5cfd1d8f79a974fb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Aug 2013 19:53:31 +0000 Subject: [PATCH 0724/1077] functions are fcn Added cookie to c callback. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7895 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + Phreeqc.h | 7 ++++--- basicsubs.cpp | 11 ++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 2b27369e..f4d77a12 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -803,6 +803,7 @@ void Phreeqc::init(void) /* Basic */ basic_interpreter = NULL; basic_callback_ptr = NULL; + basic_callback_cookie = NULL; basic_fortran_callback_ptr = NULL; /* cl1.cpp ------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index b67566f1..d73e89d5 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -83,8 +83,8 @@ public: int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); double basic_callback(double x1, double x2, char * str); - void register_basic_callback(double ( *cookie)(double x1, double x2, const char *str)); - void register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)); + void register_basic_callback(double ( *fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1); + void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)); LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); @@ -1695,7 +1695,8 @@ protected: /* Basic */ PBasic * basic_interpreter; - double (*basic_callback_ptr) (double x1, double x2, const char *str); + double (*basic_callback_ptr) (double x1, double x2, const char *str, void *cookie); + void *basic_callback_cookie; double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); /* cl1.cpp ------------------------------- */ diff --git a/basicsubs.cpp b/basicsubs.cpp index b5401197..a140c150 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3607,7 +3607,7 @@ basic_callback(double x1, double x2, char * str) if (basic_callback_ptr != NULL) { - return (*basic_callback_ptr) (x1, x2, (const char *) str); + return (*basic_callback_ptr) (x1, x2, (const char *) str, basic_callback_cookie); } if (basic_fortran_callback_ptr != NULL) { @@ -3617,13 +3617,14 @@ basic_callback(double x1, double x2, char * str) } void -Phreeqc::register_basic_callback(double ( *cookie)(double x1, double x2, const char *str)) +Phreeqc::register_basic_callback(double (*fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1) { - this->basic_callback_ptr = cookie; + this->basic_callback_ptr = fcn; + this->basic_callback_cookie = cookie1; } void -Phreeqc::register_fortran_basic_callback(double ( *cookie)(double *x1, double *x2, char *str, int l)) +Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)) { - this->basic_fortran_callback_ptr = cookie; + this->basic_fortran_callback_ptr = fcn; } From a49f540ee5405d5a817614a501656e6a8302f85c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Aug 2013 19:54:14 +0000 Subject: [PATCH 0725/1077] Tony's wording for fugacity git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7896 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/print.cpp b/print.cpp index a0bab985..894e39cb 100644 --- a/print.cpp +++ b/print.cpp @@ -1270,8 +1270,8 @@ print_saturation_indices(void) output_msg("\n"); } output_msg(sformatf("\n%s\n%s", - "**For a gas, the value is log10(fugacity). For an ideal gas, fugacity equals partial pressure.", - "For a Peng-Robinson gas, fugacity = (P * phi / 1 atm); P and phi are printed at end of line.")); + "**For a gas, SI = log10(fugacity). For ideal gases, fugacity = pressure / 1 atm.", + "For a Peng-Robinson gas, fugacity = pressure * phi / 1 atm")); output_msg("\n\n"); return (OK); From 8609b3dfb2ff98da7af4ace40a687efe940925a2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Aug 2013 21:17:07 +0000 Subject: [PATCH 0726/1077] Added row ntally_row + 1 that contains the moles of each reactant. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7898 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tally.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tally.cpp b/tally.cpp index 23899ec9..33e487a1 100644 --- a/tally.cpp +++ b/tally.cpp @@ -274,6 +274,15 @@ store_tally_table(LDBLE * l_array, int row_dim, int col_dim, LDBLE fill_factor) tally_table[i].total[2][j].moles / fill_factor; } } + + /* + * Add row for total moles of reactant + */ + for (i = 0; i < count_tally_table_columns; i++) + { + l_array[i * row_dim + count_tally_table_rows] = + tally_table[i].moles / fill_factor; + } return (OK); } @@ -622,6 +631,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) count_elts = 0; paren_count = 0; moles = it->second.Get_moles(); + tally_table[i].moles = moles; add_elt_list(tally_table[i].formula, moles); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -710,6 +720,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) break; count_elts = 0; paren_count = 0; + tally_table[i].moles = moles; add_elt_list(tally_table[i].formula, moles); elt_list_to_tally_table(tally_table[i].total[n_buffer]); } @@ -732,8 +743,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) int k; struct phase *phase_ptr = phase_bsearch((*gc)[l].Get_phase_name().c_str(), &k, FALSE); - add_elt_list(phase_ptr->next_elt, - (*gc)[l].Get_moles()); + add_elt_list(phase_ptr->next_elt, (*gc)[l].Get_moles()); } qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); @@ -765,6 +775,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) if (j >= kinetics_ptr->Get_kinetics_comps().size()) break; moles = kinetics_comp_ptr->Get_m(); + tally_table[i].moles = moles; count_elts = 0; paren_count = 0; add_elt_list(tally_table[i].formula, moles); From b18d2ff0d2cb2e22fe4a4341939029e9be9e9e8f Mon Sep 17 00:00:00 2001 From: Richard M Webb Date: Thu, 8 Aug 2013 21:49:04 +0000 Subject: [PATCH 0727/1077] Guard namespace. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7899 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index d73e89d5..8f3b052d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1946,6 +1946,8 @@ public: #endif #endif // _INC_ISFINITE_H +#ifndef _INC_UTILITIES_NAMESPACE_H +#define _INC_UTILITIES_NAMESPACE_H namespace Utilities { LDBLE get_nan(void); @@ -2095,3 +2097,4 @@ void PhreeqcIWait(Phreeqc *phreeqc); char * _string_duplicate(const char *token, const char *szFileName, int nLine); #endif +#endif //_INC_UTILITIES_NAMESPACE_H \ No newline at end of file From 59b456bdd58499eb5b6a392bdc22a6dd0d8f0ed4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 8 Aug 2013 22:11:52 +0000 Subject: [PATCH 0728/1077] Change in store_tally_table to try to line up with Fortran. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7900 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tally.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tally.cpp b/tally.cpp index 33e487a1..20fdc76a 100644 --- a/tally.cpp +++ b/tally.cpp @@ -216,10 +216,11 @@ get_all_components(void) #endif /* ---------------------------------------------------------------------- */ int Phreeqc:: -store_tally_table(LDBLE * l_array, int row_dim, int col_dim, LDBLE fill_factor) +store_tally_table(LDBLE * l_array, int row_dim_in, int col_dim, LDBLE fill_factor) /* ---------------------------------------------------------------------- */ { int i, j; + int row_dim = row_dim_in + 1; if (tally_table == NULL) { input_error++; From 6eaca680af4e4b3c08bdca8fc3c5cd26375554d9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 12 Aug 2013 22:24:18 +0000 Subject: [PATCH 0729/1077] all tests passing for one selected_output file; may still need additional tests for TestIPhreeqc case1 and case2 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7919 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 +- PHRQ_io.h | 2 +- PHRQ_io_output.cpp | 4 +- Phreeqc.h | 2 +- SelectedOutput.cpp | 2 +- SelectedOutput.h | 117 +++++++++++++++++++++++---------------------- inverse.cpp | 8 ++-- print.cpp | 6 +-- read.cpp | 60 ++++++++++++----------- tidy.cpp | 6 +-- 10 files changed, 108 insertions(+), 101 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 1d0a72cb..c881d124 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -132,7 +132,7 @@ log_msg(const char * str) // punch ostream methods // ---------------------------------------------------------------------- */ bool PHRQ_io:: -punch_open(const char *file_name, std::ios_base::openmode mode) +punch_open(const char *file_name, std::ios_base::openmode mode, int n_user) /* ---------------------------------------------------------------------- */ { return ofstream_open(&punch_ostream, file_name, mode); diff --git a/PHRQ_io.h b/PHRQ_io.h index af47bf42..8c469248 100644 --- a/PHRQ_io.h +++ b/PHRQ_io.h @@ -78,7 +78,7 @@ public: bool Get_log_on(void) {return this->log_on;} // punch_ostream - virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out, int n_user = 1); void punch_flush(void); void punch_close(void); virtual void punch_msg(const char * str); diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index cb7b94a5..1c5b61fd 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -985,11 +985,11 @@ output_msg(const char * str) /* ---------------------------------------------------------------------- */ bool Phreeqc:: -punch_open(const char *file_name) +punch_open(const char *file_name, int n_user) /* ---------------------------------------------------------------------- */ { if (phrq_io) - return this->phrq_io->punch_open(file_name); + return this->phrq_io->punch_open(file_name, std::ios_base::out, n_user); return false; } /* ---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index 42a29f5f..36a366f9 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -232,7 +232,7 @@ public: void output_msg(const char * str); // punch_ostream - bool punch_open(const char *file_name); + bool punch_open(const char *file_name, int n_user); void punch_flush(void); void punch_close(void); void punch_msg(const char * str); diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index c53d1acc..005694f4 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -38,7 +38,7 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io) this->user_punch = true; this->charge_balance = false; this->percent_error = false; - + this->have_punch_name = false; } diff --git a/SelectedOutput.h b/SelectedOutput.h index 9debdbc0..b9a3c726 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -11,65 +11,69 @@ public: ~SelectedOutput(void); void Reset(bool tf); - std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} - std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} - std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} - std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;} - std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;} - std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;} - std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;} - std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;} - std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} - std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} + inline std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} + inline std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} + inline std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} + inline std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;} + inline std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;} + inline std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;} + inline std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;} + inline std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;} + inline std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} + inline std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} - std::string & Get_file_name(void) {return this->file_name;} - bool Get_new_def(void) {return this->new_def;} - bool Get_sim(void) {return this->sim;} - bool Get_state(void) {return this->state;} - bool Get_soln(void) {return this->soln;} - bool Get_dist(void) {return this->dist;} - bool Get_time(void) {return this->time;} - bool Get_step(void) {return this->step;} - bool Get_rxn(void) {return this->rxn;} - bool Get_temp(void) {return this->temp;} - bool Get_ph(void) {return this->ph;} - bool Get_pe(void) {return this->pe;} - bool Get_alk(void) {return this->alk;} - bool Get_mu(void) {return this->mu;} - bool Get_water(void) {return this->water;} - bool Get_high_precision(void) {return this->high_precision;} - bool Get_user_punch(void) {return this->user_punch;} - bool Get_charge_balance(void) {return this->charge_balance;} - bool Get_percent_error(void) {return this->percent_error;} - bool Get_inverse(void) {return this->inverse;} - //bool Get_punch(void) {return this->punch;} - bool Get_active(void) {return this->active;} + inline std::string & Get_file_name(void) {return this->file_name;} + inline bool Get_new_def(void) {return this->new_def;} + inline bool Get_sim(void) {return this->sim;} + inline bool Get_state(void) {return this->state;} + inline bool Get_soln(void) {return this->soln;} + inline bool Get_dist(void) {return this->dist;} + inline bool Get_time(void) {return this->time;} + inline bool Get_step(void) {return this->step;} + inline bool Get_rxn(void) {return this->rxn;} + inline bool Get_temp(void) {return this->temp;} + inline bool Get_ph(void) {return this->ph;} + inline bool Get_pe(void) {return this->pe;} + inline bool Get_alk(void) {return this->alk;} + inline bool Get_mu(void) {return this->mu;} + inline bool Get_water(void) {return this->water;} + inline bool Get_high_precision(void) {return this->high_precision;} + inline bool Get_user_punch(void) {return this->user_punch;} + inline bool Get_charge_balance(void) {return this->charge_balance;} + inline bool Get_percent_error(void) {return this->percent_error;} + inline bool Get_inverse(void) {return this->inverse;} + //inline bool Get_punch(void) {return this->punch;} + inline bool Get_active(void) {return this->active;} + inline bool Get_have_punch_name(void) {return this->have_punch_name;} + inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} - void Set_file_name(int i); - void Set_file_name(std::string s) {this->file_name = s;} - void Set_new_def(bool tf) {this->new_def = tf;} - void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} - void Set_sim(bool tf) {this->sim = tf;} - void Set_state(bool tf) {this->state = tf;} - void Set_soln(bool tf) {this->soln = tf;} - void Set_dist(bool tf) {this->dist = tf;} - void Set_time(bool tf) {this->time = tf;} - void Set_step(bool tf) {this->step = tf;} - void Set_rxn(bool tf) {this->rxn = tf;} - void Set_temp(bool tf) {this->temp = tf;} - void Set_ph(bool tf) {this->ph = tf;} - void Set_pe(bool tf) {this->pe = tf;} - void Set_alk(bool tf) {this->alk = tf;} - void Set_mu(bool tf) {this->mu = tf;} - void Set_water(bool tf) {this->water = tf;} - void Set_high_precision(bool tf) {this->high_precision = tf;} - void Set_user_punch(bool tf) {this->user_punch = tf;} - void Set_charge_balance(bool tf) {this->charge_balance = tf;} - void Set_percent_error(bool tf) {this->percent_error = tf;} - void Set_inverse(bool tf) {this->inverse = tf;} - //void Set_punch(bool tf) {this->punch = tf;} - void Set_active(bool tf) {this->active = tf;} + inline void Set_file_name(int i); + inline void Set_file_name(std::string s) {this->file_name = s;} + inline void Set_new_def(bool tf) {this->new_def = tf;} + inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} + inline void Set_sim(bool tf) {this->sim = tf;} + inline void Set_state(bool tf) {this->state = tf;} + inline void Set_soln(bool tf) {this->soln = tf;} + inline void Set_dist(bool tf) {this->dist = tf;} + inline void Set_time(bool tf) {this->time = tf;} + inline void Set_step(bool tf) {this->step = tf;} + inline void Set_rxn(bool tf) {this->rxn = tf;} + inline void Set_temp(bool tf) {this->temp = tf;} + inline void Set_ph(bool tf) {this->ph = tf;} + inline void Set_pe(bool tf) {this->pe = tf;} + inline void Set_alk(bool tf) {this->alk = tf;} + inline void Set_mu(bool tf) {this->mu = tf;} + inline void Set_water(bool tf) {this->water = tf;} + inline void Set_high_precision(bool tf) {this->high_precision = tf;} + inline void Set_user_punch(bool tf) {this->user_punch = tf;} + inline void Set_charge_balance(bool tf) {this->charge_balance = tf;} + inline void Set_percent_error(bool tf) {this->percent_error = tf;} + inline void Set_inverse(bool tf) {this->inverse = tf;} + //inline void Set_punch(bool tf) {this->punch = tf;} + inline void Set_active(bool tf) {this->active = tf;} + inline void Set_have_punch_name(bool tf) {this->have_punch_name = tf;} +protected: std::string file_name; std::ostream * punch_ostream; bool active; @@ -103,5 +107,6 @@ public: bool charge_balance; bool percent_error; bool inverse; + bool have_punch_name; }; #endif // !defined(SELECTEDOUTPUT_H_INCLUDED) diff --git a/inverse.cpp b/inverse.cpp index caebfd51..157a88b5 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2089,11 +2089,11 @@ punch_model_heading(struct inverse *inv_ptr) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - current_selected_output->punch_ostream == NULL || + current_selected_output->Get_punch_ostream() == NULL || !current_selected_output->Get_inverse() || !current_selected_output->Get_active()) continue; - phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream()); int l = (!current_selected_output->Get_high_precision()) ? 15 : 20; inverse_heading_names.clear(); @@ -2268,11 +2268,11 @@ punch_model(struct inverse *inv_ptr) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - current_selected_output->punch_ostream == NULL || + current_selected_output->Get_punch_ostream() == NULL || !current_selected_output->Get_inverse() || !current_selected_output->Get_active()) continue; - phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream()); n_user_punch_index = 0; /* diff --git a/print.cpp b/print.cpp index 1152bf39..18ed344a 100644 --- a/print.cpp +++ b/print.cpp @@ -171,10 +171,10 @@ punch_all(void) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - !current_selected_output->Get_active() || - current_selected_output->punch_ostream == NULL) + !current_selected_output->Get_active() /* || + current_selected_output->Get_punch_ostream() == NULL*/) continue; - phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream()); // UserPunch std::map < int, UserPunch >::iterator up_it = UserPunch_map.find(current_selected_output->Get_n_user()); diff --git a/read.cpp b/read.cpp index 08831493..e4a787c6 100644 --- a/read.cpp +++ b/read.cpp @@ -4674,30 +4674,32 @@ read_selected_output(void) // find if it exists std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); - if (so != SelectedOutput_map.end() && n_user == 1) + if (so != SelectedOutput_map.end()) { SelectedOutput & so_ref = so->second; - temp_selected_output.active = so_ref.active; - temp_selected_output.inverse = so_ref.inverse; - temp_selected_output.sim = so_ref.sim; - temp_selected_output.state = so_ref.state; - temp_selected_output.soln = so_ref.soln; - temp_selected_output.dist = so_ref.dist; - temp_selected_output.time = so_ref.time; - temp_selected_output.step = so_ref.step; - temp_selected_output.rxn = so_ref.rxn; - temp_selected_output.temp = so_ref.temp; - temp_selected_output.ph = so_ref.ph; - temp_selected_output.pe = so_ref.pe; - temp_selected_output.alk = so_ref.alk; - temp_selected_output.mu = so_ref.mu; - temp_selected_output.water = so_ref.water; - temp_selected_output.high_precision = so_ref.high_precision; - temp_selected_output.user_punch = so_ref.user_punch; - temp_selected_output.charge_balance = so_ref.charge_balance; - temp_selected_output.percent_error = so_ref.percent_error; + temp_selected_output.Set_active ( so_ref.Get_active() ); + temp_selected_output.Set_inverse ( so_ref.Get_inverse() ); + temp_selected_output.Set_sim ( so_ref.Get_sim() ); + temp_selected_output.Set_state ( so_ref.Get_state() ); + temp_selected_output.Set_soln ( so_ref.Get_soln() ); + temp_selected_output.Set_dist ( so_ref.Get_dist() ); + temp_selected_output.Set_time ( so_ref.Get_time() ); + temp_selected_output.Set_step ( so_ref.Get_step() ); + temp_selected_output.Set_rxn ( so_ref.Get_rxn() ); + temp_selected_output.Set_temp ( so_ref.Get_temp() ); + temp_selected_output.Set_ph ( so_ref.Get_ph() ); + temp_selected_output.Set_pe ( so_ref.Get_pe() ); + temp_selected_output.Set_alk ( so_ref.Get_alk() ); + temp_selected_output.Set_mu ( so_ref.Get_mu() ); + temp_selected_output.Set_water ( so_ref.Get_water() ); + temp_selected_output.Set_high_precision ( so_ref.Get_high_precision() ); + temp_selected_output.Set_user_punch ( so_ref.Get_user_punch() ); + temp_selected_output.Set_charge_balance ( so_ref.Get_charge_balance() ); + temp_selected_output.Set_percent_error ( so_ref.Get_percent_error() ); + temp_selected_output.Set_have_punch_name ( so_ref.Get_have_punch_name() ); + temp_selected_output.Set_file_name ( so_ref.Get_file_name() ); } - else + else if(n_user != 1) { temp_selected_output.Reset(false); } @@ -4737,6 +4739,7 @@ read_selected_output(void) { strcpy(file_name, next_char); temp_selected_output.Set_file_name(file_name); + temp_selected_output.Set_have_punch_name(true); } opt_save = OPTION_ERROR; break; @@ -5019,7 +5022,7 @@ read_selected_output(void) break; } - if (temp_selected_output.Get_new_def()) + if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) { // delete if exists @@ -5031,16 +5034,17 @@ read_selected_output(void) // store new selected output SelectedOutput_map[n_user] = temp_selected_output; - // open file - std::ofstream *ofs = new std::ofstream(temp_selected_output.Get_file_name().c_str(), std::ios_base::out ); - if (ofs && ofs->is_open()) + if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) { - SelectedOutput_map[n_user].Set_punch_ostream(ofs); - + if (this->phrq_io) + { + SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); + this->phrq_io->Set_punch_ostream(NULL); + } } else { - error_string = sformatf( "Can`t open file, %s.", file_name); + error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); input_error++; error_msg(error_string, CONTINUE); } diff --git a/tidy.cpp b/tidy.cpp index 69ebcf98..831b0e5d 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -1779,8 +1779,7 @@ tidy_punch(void) for ( ; so_it != SelectedOutput_map.end(); so_it++) { current_selected_output = &(so_it->second); - if (current_selected_output == NULL || - current_selected_output->punch_ostream == NULL) + if (current_selected_output == NULL) continue; @@ -1846,10 +1845,9 @@ tidy_punch(void) { current_selected_output = &(so_it->second); if (current_selected_output == NULL || - current_selected_output->punch_ostream == NULL || !current_selected_output->Get_new_def()) continue; - phrq_io->Set_punch_ostream(current_selected_output->punch_ostream); + phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream()); int l; From 2abb2f228354ba1c87098d5bdd7dffee915f003d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 13 Aug 2013 15:15:47 +0000 Subject: [PATCH 0730/1077] Revised tidy_gases. Structure was wrong and j was used in two loops. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7920 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index 8399bac8..2ffb2a6e 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -858,6 +858,165 @@ rewrite_eqn_to_primary(void) int Phreeqc:: tidy_gas_phase(void) /* ---------------------------------------------------------------------- */ +{ + int n_user, last; + LDBLE P, V_m; + bool PR; +/* + * Find all gases for each gas_phase in phase list + */ + for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) + { + std::map::iterator it = Rxn_gas_phase_map.find(*nit); + if (it == Rxn_gas_phase_map.end()) + { + assert(false); + } + cxxGasPhase *gas_phase_ptr = &(it->second); + PR = false; + P = 0.0; + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_phase_ptr->Get_solution_equilibria()) + { + input_error++; + error_string = sformatf( + "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", + gas_phase_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + } + } + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gc.size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Gas not found in PHASES database, %s.", + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + else + { + if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) + PR = true; + } + gas_phase_ptr->Set_pr_in(PR); + /* + * Fixed pressure + */ + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + /* calculate moles */ + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles( + gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: partial pressure of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + else + { + /* + * Fixed volume + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles ( + gc[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: moles of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + } + } + + gas_phase_ptr->Set_gas_comps(gc); + + if (PR && P > 0) + { + std::vector phase_ptrs; + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + continue; + phase_ptr->moles_x = gc[j].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + } + V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); + gas_phase_ptr->Set_v_m(V_m); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_p(P); + } + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + { + gc[j].Set_moles(0.0); + } else + { + gc[j].Set_moles(phase_ptr->moles_x * gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + } + } + gas_phase_ptr->Set_gas_comps(gc); + } + /* + * Duplicate gas phase, only if not solution equilibria + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + for (int j = n_user + 1; j <= last; j++) + { + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + } + } + else + { + gas_phase_ptr->Set_new_def(true); + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_gas_phase(void) +/* ---------------------------------------------------------------------- */ { int n_user, last; LDBLE P, V_m; @@ -1023,6 +1182,7 @@ tidy_gas_phase(void) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_inverse(void) From ee4cd5ec90b43cef1b4e3bd2c7db8162bb9632b9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 13 Aug 2013 19:22:20 +0000 Subject: [PATCH 0731/1077] Next try on tidy_gas_phase git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7922 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 192 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 93 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 2ffb2a6e..16a7c538 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -875,17 +875,6 @@ tidy_gas_phase(void) cxxGasPhase *gas_phase_ptr = &(it->second); PR = false; P = 0.0; - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) - { - if (gas_phase_ptr->Get_solution_equilibria()) - { - input_error++; - error_string = sformatf( - "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", - gas_phase_ptr->Get_n_user()); - error_msg(error_string, CONTINUE); - } - } std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gc.size(); j++) { @@ -905,109 +894,126 @@ tidy_gas_phase(void) if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) PR = true; } - gas_phase_ptr->Set_pr_in(PR); + } + gas_phase_ptr->Set_pr_in(PR); + + if (gas_phase_ptr->Get_new_def()) // true GAS_PHASE, false GAS_PHASE_MODIFY + { + for (size_t j = 0; j < gc.size(); j++) + { + gas_phase_ptr->Set_new_def(false); /* * Fixed pressure */ - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) - { - /* calculate moles */ - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - gc[j].Set_moles( - gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / - R_LITER_ATM / gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: partial pressure of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - else - { - /* - * Fixed volume - */ - if (!gas_phase_ptr->Get_solution_equilibria()) + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { + if (gas_phase_ptr->Get_solution_equilibria()) + { + input_error++; + error_string = sformatf( + "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", + gas_phase_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + } + /* calculate moles */ if (gc[j].Get_p_read() != NAN) { P += gc[j].Get_p_read(); - gc[j].Set_moles ( - gc[j].Get_p_read() * - gas_phase_ptr->Get_volume() / R_LITER_ATM / - gas_phase_ptr->Get_temperature()); + gc[j].Set_moles( + gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); } else { input_error++; error_string = sformatf( - "Gas phase %d: moles of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), - gc[j].Get_phase_name().c_str()); + "Gas phase %d: partial pressure of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); error_msg(error_string, CONTINUE); } } - } - } - - gas_phase_ptr->Set_gas_comps(gc); - - if (PR && P > 0) - { - std::vector phase_ptrs; - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) - continue; - phase_ptr->moles_x = gc[j].Get_p_read() / P; - phase_ptrs.push_back(phase_ptr); - } - V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); - gas_phase_ptr->Set_v_m(V_m); - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) - { - gas_phase_ptr->Set_total_p(P); - } - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) + else { - gc[j].Set_moles(0.0); - } else - { - gc[j].Set_moles(phase_ptr->moles_x * gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + /* + * Fixed volume + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + if (gc[j].Get_p_read() != NAN) + { + P += gc[j].Get_p_read(); + gc[j].Set_moles ( + gc[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: moles of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), + gc[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } } } + gas_phase_ptr->Set_gas_comps(gc); - } - /* - * Duplicate gas phase, only if not solution equilibria - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - n_user = gas_phase_ptr->Get_n_user(); - last = gas_phase_ptr->Get_n_user_end(); - gas_phase_ptr->Set_n_user_end(n_user); - for (int j = n_user + 1; j <= last; j++) + + if (PR && P > 0) { - Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + std::vector phase_ptrs; + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + continue; + phase_ptr->moles_x = gc[j].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + } + V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); + gas_phase_ptr->Set_v_m(V_m); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_p(P); + } + std::vector gc = gas_phase_ptr->Get_gas_comps(); + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); + if (gc[j].Get_p_read() == 0) + { + gc[j].Set_moles(0.0); + } else + { + gc[j].Set_moles(phase_ptr->moles_x * + gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + } + } + gas_phase_ptr->Set_gas_comps(gc); + } + /* + * Duplicate gas phase, only if not solution equilibria + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + for (int j = n_user + 1; j <= last; j++) + { + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + } + } + else + { + gas_phase_ptr->Set_new_def(true); } - } - else - { - gas_phase_ptr->Set_new_def(true); } } return (OK); From 9faaee66d4fe60bf6cbd39b9287ed71fa17237e8 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 13 Aug 2013 21:26:16 +0000 Subject: [PATCH 0732/1077] fixes compile error on linux; changes made for TestIPhreeqc::case2 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7923 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/read.cpp b/read.cpp index e4a787c6..6e96f6cd 100644 --- a/read.cpp +++ b/read.cpp @@ -5034,20 +5034,28 @@ read_selected_output(void) // store new selected output SelectedOutput_map[n_user] = temp_selected_output; - if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) + //{{ + if (!SelectedOutput_map[n_user].Get_have_punch_name()) { - if (this->phrq_io) + assert(SelectedOutput_map[n_user].Get_punch_ostream() == 0); + //}} + if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) { - SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); - this->phrq_io->Set_punch_ostream(NULL); + if (this->phrq_io) + { + SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); + this->phrq_io->Set_punch_ostream(NULL); + } } + else + { + error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); + input_error++; + error_msg(error_string, CONTINUE); + } + //{{ } - else - { - error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); - input_error++; - error_msg(error_string, CONTINUE); - } + //}} } //if (!have_punch_name) From 1773d7e5924875994741a9c0fbaf89787fa89d41 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 13 Aug 2013 22:50:56 +0000 Subject: [PATCH 0733/1077] removed inline from Set_file_name git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7929 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SelectedOutput.h b/SelectedOutput.h index b9a3c726..42d1f3ee 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -47,7 +47,7 @@ public: inline bool Get_have_punch_name(void) {return this->have_punch_name;} inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} - inline void Set_file_name(int i); + void Set_file_name(int i); inline void Set_file_name(std::string s) {this->file_name = s;} inline void Set_new_def(bool tf) {this->new_def = tf;} inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} From 9069b4a8b828641a5aff5877d0f625c69b7d88f5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 14 Aug 2013 00:59:02 +0000 Subject: [PATCH 0734/1077] logic for headings of selected_output 1; logic of opening selected_output file git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7931 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/read.cpp b/read.cpp index 6e96f6cd..686bcf3f 100644 --- a/read.cpp +++ b/read.cpp @@ -4674,8 +4674,9 @@ read_selected_output(void) // find if it exists std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); - if (so != SelectedOutput_map.end()) + if (n_user == 1 && so != SelectedOutput_map.end()) { + // n_user = 1, old definition, keep old definition SelectedOutput & so_ref = so->second; temp_selected_output.Set_active ( so_ref.Get_active() ); temp_selected_output.Set_inverse ( so_ref.Get_inverse() ); @@ -4699,9 +4700,15 @@ read_selected_output(void) temp_selected_output.Set_have_punch_name ( so_ref.Get_have_punch_name() ); temp_selected_output.Set_file_name ( so_ref.Get_file_name() ); } - else if(n_user != 1) + else if (n_user == 1 && so == SelectedOutput_map.end()) { - temp_selected_output.Reset(false); + // n_user = 1, new definition, do nothing use; constructor default + } + else + { + // n_user != 1 then reset false + + temp_selected_output.Reset(false); } CParser parser(this->phrq_io); @@ -5035,8 +5042,8 @@ read_selected_output(void) SelectedOutput_map[n_user] = temp_selected_output; //{{ - if (!SelectedOutput_map[n_user].Get_have_punch_name()) - { + //if (!SelectedOutput_map[n_user].Get_have_punch_name()) + //{ assert(SelectedOutput_map[n_user].Get_punch_ostream() == 0); //}} if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) @@ -5054,7 +5061,7 @@ read_selected_output(void) error_msg(error_string, CONTINUE); } //{{ - } + //} //}} } From a6f82d990e00551554ef4e6e5ed9a75b595c4c28 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 14 Aug 2013 02:16:56 +0000 Subject: [PATCH 0735/1077] minor reformatting git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7932 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/read.cpp b/read.cpp index 686bcf3f..c9e58e4f 100644 --- a/read.cpp +++ b/read.cpp @@ -4676,7 +4676,7 @@ read_selected_output(void) std::map< int, SelectedOutput >::iterator so = SelectedOutput_map.find(n_user); if (n_user == 1 && so != SelectedOutput_map.end()) { - // n_user = 1, old definition, keep old definition + // n_user = 1, old definition, keep old definition SelectedOutput & so_ref = so->second; temp_selected_output.Set_active ( so_ref.Get_active() ); temp_selected_output.Set_inverse ( so_ref.Get_inverse() ); @@ -4702,13 +4702,13 @@ read_selected_output(void) } else if (n_user == 1 && so == SelectedOutput_map.end()) { - // n_user = 1, new definition, do nothing use; constructor default + // n_user = 1, new definition, do nothing use; constructor default } else { - // n_user != 1 then reset false + // n_user != 1 then reset false - temp_selected_output.Reset(false); + temp_selected_output.Reset(false); } CParser parser(this->phrq_io); @@ -5031,7 +5031,6 @@ read_selected_output(void) if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) { - // delete if exists if (so != SelectedOutput_map.end()) { @@ -5041,28 +5040,20 @@ read_selected_output(void) // store new selected output SelectedOutput_map[n_user] = temp_selected_output; - //{{ - //if (!SelectedOutput_map[n_user].Get_have_punch_name()) - //{ - assert(SelectedOutput_map[n_user].Get_punch_ostream() == 0); - //}} - if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) + if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) + { + if (this->phrq_io) { - if (this->phrq_io) - { - SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); - this->phrq_io->Set_punch_ostream(NULL); - } + SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); + this->phrq_io->Set_punch_ostream(NULL); } - else - { - error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); - input_error++; - error_msg(error_string, CONTINUE); - } - //{{ - //} - //}} + } + else + { + error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); + input_error++; + error_msg(error_string, CONTINUE); + } } //if (!have_punch_name) From 25a990751b35b974861e2dabc94de5c635721808 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 14 Aug 2013 15:34:04 +0000 Subject: [PATCH 0736/1077] Tony's rewrite of tidy_gas_phase, still pretty ugly. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7933 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 6 +- print.cpp | 6 +- tidy.cpp | 229 ++++++------------------------------------------------ 3 files changed, 31 insertions(+), 210 deletions(-) diff --git a/model.cpp b/model.cpp index b75e71e5..2cf338e6 100644 --- a/model.cpp +++ b/model.cpp @@ -2712,14 +2712,14 @@ calc_gas_pressures(void) if (gas_phase_ptr->Get_total_moles() > 0) { V_m = gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles(); - if (V_m < 0.03) + if (V_m < 0.016) { - V_m = 0.03; + V_m = 0.016; } else if (V_m > 1e4) { V_m = 1e4; } - if (gas_phase_ptr->Get_v_m() > 0.03) + if (gas_phase_ptr->Get_v_m() > 0.016) { if (V_m < 0.04) V_m = (9. * gas_phase_ptr->Get_v_m() + V_m) / 10; diff --git a/print.cpp b/print.cpp index 894e39cb..ecec3647 100644 --- a/print.cpp +++ b/print.cpp @@ -578,8 +578,8 @@ print_gas_phase(void) (double) gas_phase_ptr->Get_volume())); if(gas_phase_ptr->Get_total_moles() > 0) output_msg(sformatf(" Molar volume: %10.2e liters/mole", - (double) (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()))); - if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles() <= 0.03) || (PR && gas_phase_ptr->Get_v_m() <= 0.03))) + (double) (gas_phase_ptr->Get_v_m()))); + if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_v_m() <= 0.016))) output_msg(" WARNING: Program limit for Peng-Robinson.\n"); else output_msg("\n"); @@ -590,7 +590,7 @@ print_gas_phase(void) output_msg(sformatf("\n%68s\n%78s\n", "Moles in gas", "----------------------------------")); - if (gas_phase_ptr->Get_v_m() >= 0.03) + if (PR) output_msg(sformatf( "%-11s%12s%12s%7s%12s%12s%12s\n\n", "Component", "log P", "P", "phi", "Initial", "Final", "Delta")); else diff --git a/tidy.cpp b/tidy.cpp index 16a7c538..6f237e55 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -877,179 +877,6 @@ tidy_gas_phase(void) P = 0.0; std::vector gc = gas_phase_ptr->Get_gas_comps(); for (size_t j = 0; j < gc.size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (phase_ptr == NULL) - { - input_error++; - error_string = sformatf( - "Gas not found in PHASES database, %s.", - gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - continue; - } - else - { - if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) - PR = true; - } - } - gas_phase_ptr->Set_pr_in(PR); - - if (gas_phase_ptr->Get_new_def()) // true GAS_PHASE, false GAS_PHASE_MODIFY - { - for (size_t j = 0; j < gc.size(); j++) - { - gas_phase_ptr->Set_new_def(false); - /* - * Fixed pressure - */ - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) - { - if (gas_phase_ptr->Get_solution_equilibria()) - { - input_error++; - error_string = sformatf( - "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", - gas_phase_ptr->Get_n_user()); - error_msg(error_string, CONTINUE); - } - /* calculate moles */ - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - gc[j].Set_moles( - gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / - R_LITER_ATM / gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: partial pressure of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - else - { - /* - * Fixed volume - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - if (gc[j].Get_p_read() != NAN) - { - P += gc[j].Get_p_read(); - gc[j].Set_moles ( - gc[j].Get_p_read() * - gas_phase_ptr->Get_volume() / R_LITER_ATM / - gas_phase_ptr->Get_temperature()); - } - else - { - input_error++; - error_string = sformatf( - "Gas phase %d: moles of gas component %s not defined.", - gas_phase_ptr->Get_n_user(), - gc[j].Get_phase_name().c_str()); - error_msg(error_string, CONTINUE); - } - } - } - } - - gas_phase_ptr->Set_gas_comps(gc); - - if (PR && P > 0) - { - std::vector phase_ptrs; - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) - continue; - phase_ptr->moles_x = gc[j].Get_p_read() / P; - phase_ptrs.push_back(phase_ptr); - } - V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); - gas_phase_ptr->Set_v_m(V_m); - if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) - { - gas_phase_ptr->Set_total_p(P); - } - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) - { - int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) - { - gc[j].Set_moles(0.0); - } else - { - gc[j].Set_moles(phase_ptr->moles_x * - gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); - } - } - gas_phase_ptr->Set_gas_comps(gc); - } - /* - * Duplicate gas phase, only if not solution equilibria - */ - if (!gas_phase_ptr->Get_solution_equilibria()) - { - n_user = gas_phase_ptr->Get_n_user(); - last = gas_phase_ptr->Get_n_user_end(); - gas_phase_ptr->Set_n_user_end(n_user); - for (int j = n_user + 1; j <= last; j++) - { - Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); - } - } - else - { - gas_phase_ptr->Set_new_def(true); - } - } - } - return (OK); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -tidy_gas_phase(void) -/* ---------------------------------------------------------------------- */ -{ - int n_user, last; - LDBLE P, V_m; - bool PR; -/* - * Find all gases for each gas_phase in phase list - */ - //std::map::iterator it = Rxn_gas_phase_map.begin(); - //for ( ; it != Rxn_gas_phase_map.end(); it++) - //for (size_t nn = 0; nn < Rxn_new_gas_phase.size(); nn++) - //{ - //std::map::iterator it = Rxn_gas_phase_map.find(Rxn_new_gas_phase[nn]); - for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) - { - std::map::iterator it = Rxn_gas_phase_map.find(*nit); - if (it == Rxn_gas_phase_map.end()) - { - assert(false); - } - cxxGasPhase *gas_phase_ptr = &(it->second); - //if (!gas_phase_ptr->Get_new_def()) - // continue; - //gas_phase_ptr->Set_new_def(false); - PR = false; - P = 0.0; - std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gc.size(); j++) { int k; struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); @@ -1070,7 +897,8 @@ tidy_gas_phase(void) gas_phase_ptr->Set_pr_in(PR); if (gas_phase_ptr->Get_new_def()) { - gas_phase_ptr->Set_new_def(false); + if (j == gc.size() - 1) + gas_phase_ptr->Set_new_def(false); /* * Fixed pressure */ @@ -1088,9 +916,10 @@ tidy_gas_phase(void) if (gc[j].Get_p_read() != NAN) { P += gc[j].Get_p_read(); - gc[j].Set_moles( - gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / - R_LITER_ATM / gas_phase_ptr->Get_temperature()); + if (!PR) + gc[j].Set_moles( + gc[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); } else { @@ -1111,10 +940,11 @@ tidy_gas_phase(void) if (gc[j].Get_p_read() != NAN) { P += gc[j].Get_p_read(); - gc[j].Set_moles ( - gc[j].Get_p_read() * - gas_phase_ptr->Get_volume() / R_LITER_ATM / - gas_phase_ptr->Get_temperature()); + if (!PR) + gc[j].Set_moles ( + gc[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); } else { @@ -1131,16 +961,17 @@ tidy_gas_phase(void) gas_phase_ptr->Set_gas_comps(gc); - if (PR && P > 0) + if (PR && P > 0 && j == gc.size() - 1) { std::vector phase_ptrs; - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + size_t j_PR; + for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) { int k; - struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j_PR].Get_phase_name().c_str(), &k, FALSE); + if (gc[j_PR].Get_p_read() == 0) continue; - phase_ptr->moles_x = gc[j].Get_p_read() / P; + phase_ptr->moles_x = gc[j_PR].Get_p_read() / P; phase_ptrs.push_back(phase_ptr); } V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); @@ -1150,18 +981,18 @@ tidy_gas_phase(void) gas_phase_ptr->Set_total_p(P); } std::vector gc = gas_phase_ptr->Get_gas_comps(); - for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) { int k; - struct phase *phase_ptr = phase_bsearch(gc[j].Get_phase_name().c_str(), &k, FALSE); - if (gc[j].Get_p_read() == 0) + struct phase *phase_ptr = phase_bsearch(gc[j_PR].Get_phase_name().c_str(), &k, FALSE); + if (gc[j_PR].Get_p_read() == 0) { - gc[j].Set_moles(0.0); + gc[j_PR].Set_moles(0.0); } else { - gc[j].Set_moles(phase_ptr->moles_x * + gc[j_PR].Set_moles(phase_ptr->moles_x * gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j].Get_moles()); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j_PR].Get_moles()); } } gas_phase_ptr->Set_gas_comps(gc); @@ -1174,9 +1005,9 @@ tidy_gas_phase(void) n_user = gas_phase_ptr->Get_n_user(); last = gas_phase_ptr->Get_n_user_end(); gas_phase_ptr->Set_n_user_end(n_user); - for (int j = n_user + 1; j <= last; j++) + for (int j1 = n_user + 1; j1 <= last; j1++) { - Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j); + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j1); } } else @@ -1188,7 +1019,6 @@ tidy_gas_phase(void) } return (OK); } -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_inverse(void) @@ -4408,15 +4238,6 @@ ss_calc_a0_a1(cxxSS *ss_ptr) tol = 1e-6; rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; - if (ss_ptr->Get_ss_comps().size() < 2) - { - input_error++; - error_string = sformatf( - "Two components were not defined for %s solid solution", - ss_ptr->Get_name().c_str()); - error_msg(error_string, CONTINUE); - return (ERROR); - } cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); int k; From ec4fa77cba4170dc11859b2585b5ba2aa2f6395c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 14 Aug 2013 19:06:36 +0000 Subject: [PATCH 0737/1077] changed print.cpp for Molar volume when not PR Revised Tony organization of tidy_gas_phase. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7935 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 12 +++- tidy.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index ecec3647..4eb805f6 100644 --- a/print.cpp +++ b/print.cpp @@ -577,8 +577,18 @@ print_gas_phase(void) output_msg(sformatf(" Gas volume: %10.2e liters\n", (double) gas_phase_ptr->Get_volume())); if(gas_phase_ptr->Get_total_moles() > 0) - output_msg(sformatf(" Molar volume: %10.2e liters/mole", + { + if (PR) + { + output_msg(sformatf(" Molar volume: %10.2e liters/mole", (double) (gas_phase_ptr->Get_v_m()))); + } + else + { + output_msg(sformatf(" Molar volume: %10.2e liters/mole", + (double) (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()))); + } + } if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_v_m() <= 0.016))) output_msg(" WARNING: Program limit for Peng-Robinson.\n"); else diff --git a/tidy.cpp b/tidy.cpp index 6f237e55..3e64db4b 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -858,6 +858,170 @@ rewrite_eqn_to_primary(void) int Phreeqc:: tidy_gas_phase(void) /* ---------------------------------------------------------------------- */ +{ + int n_user, last; + LDBLE P, V_m; + bool PR; +/* + * Find all gases for each gas_phase in phase list + */ + for (std::set::const_iterator nit = Rxn_new_gas_phase.begin(); nit != Rxn_new_gas_phase.end(); nit++) + { + std::map::iterator it = Rxn_gas_phase_map.find(*nit); + if (it == Rxn_gas_phase_map.end()) + { + assert(false); + } + cxxGasPhase *gas_phase_ptr = &(it->second); + PR = false; + P = 0.0; + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str(), &k, FALSE); + if (phase_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Gas not found in PHASES database, %s.", + gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + else + { + if (phase_ptr->t_c > 0 && phase_ptr->p_c > 0) + PR = true; + } + } + gas_phase_ptr->Set_pr_in(PR); + + if (gas_phase_ptr->Get_new_def()) + { + for (size_t j = 0; j < gas_phase_ptr->Get_gas_comps().size(); j++) + { + /* + * Fixed pressure + */ + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + if (gas_phase_ptr->Get_solution_equilibria()) + { + input_error++; + error_string = sformatf( + "Gas phase %d: cannot use '-equilibrium' option with fixed pressure gas phase.", + gas_phase_ptr->Get_n_user()); + error_msg(error_string, CONTINUE); + } + /* calculate moles */ + if (gas_phase_ptr->Get_gas_comps()[j].Get_p_read() != NAN) + { + P += gas_phase_ptr->Get_gas_comps()[j].Get_p_read(); + if (!PR) + gas_phase_ptr->Get_gas_comps()[j].Set_moles( + gas_phase_ptr->Get_gas_comps()[j].Get_p_read() * gas_phase_ptr->Get_volume() / + R_LITER_ATM / gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: partial pressure of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + else + { + /* + * Fixed volume + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + if (gas_phase_ptr->Get_gas_comps()[j].Get_p_read() != NAN) + { + P += gas_phase_ptr->Get_gas_comps()[j].Get_p_read(); + if (!PR) + gas_phase_ptr->Get_gas_comps()[j].Set_moles ( + gas_phase_ptr->Get_gas_comps()[j].Get_p_read() * + gas_phase_ptr->Get_volume() / R_LITER_ATM / + gas_phase_ptr->Get_temperature()); + } + else + { + input_error++; + error_string = sformatf( + "Gas phase %d: moles of gas component %s not defined.", + gas_phase_ptr->Get_n_user(), + gas_phase_ptr->Get_gas_comps()[j].Get_phase_name().c_str()); + error_msg(error_string, CONTINUE); + } + } + } + } + + if (PR && P > 0) + { + std::vector phase_ptrs; + size_t j_PR; + std::vector &gc = gas_phase_ptr->Get_gas_comps(); + for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j_PR].Get_phase_name().c_str(), &k, FALSE); + if (gc[j_PR].Get_p_read() == 0) + continue; + phase_ptr->moles_x = gc[j_PR].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + } + V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); + gas_phase_ptr->Set_v_m(V_m); + if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) + { + gas_phase_ptr->Set_total_p(P); + } + for (j_PR = 0; j_PR < gas_phase_ptr->Get_gas_comps().size(); j_PR++) + { + int k; + struct phase *phase_ptr = phase_bsearch(gc[j_PR].Get_phase_name().c_str(), &k, FALSE); + if (gc[j_PR].Get_p_read() == 0) + { + gc[j_PR].Set_moles(0.0); + } else + { + gc[j_PR].Set_moles(phase_ptr->moles_x * + gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j_PR].Get_moles()); + } + } + } + /* + * Duplicate gas phase, only if not solution equilibria + */ + if (!gas_phase_ptr->Get_solution_equilibria()) + { + gas_phase_ptr->Set_new_def(false); + n_user = gas_phase_ptr->Get_n_user(); + last = gas_phase_ptr->Get_n_user_end(); + gas_phase_ptr->Set_n_user_end(n_user); + for (int j1 = n_user + 1; j1 <= last; j1++) + { + Utilities::Rxn_copy(Rxn_gas_phase_map, n_user, j1); + } + } + else + { + gas_phase_ptr->Set_new_def(true); + } + } + } + return (OK); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +tidy_gas_phase(void) +/* ---------------------------------------------------------------------- */ { int n_user, last; LDBLE P, V_m; @@ -1019,6 +1183,7 @@ tidy_gas_phase(void) } return (OK); } +#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: tidy_inverse(void) From 2c6f8c22841b58b04fbcc6c49b13be03e8277c2f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 17 Aug 2013 06:18:06 +0000 Subject: [PATCH 0738/1077] working on multi_punch tests for IPhreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7946 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/read.cpp b/read.cpp index c9e58e4f..5597e378 100644 --- a/read.cpp +++ b/read.cpp @@ -5040,15 +5040,7 @@ read_selected_output(void) // store new selected output SelectedOutput_map[n_user] = temp_selected_output; - if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) - { - if (this->phrq_io) - { - SelectedOutput_map[n_user].Set_punch_ostream(this->phrq_io->Get_punch_ostream()); - this->phrq_io->Set_punch_ostream(NULL); - } - } - else + if (!punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) { error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); input_error++; From 695d6d4e2d5a51e2baba5e305eb08f9126618bf9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 23 Aug 2013 19:46:12 +0000 Subject: [PATCH 0739/1077] Tony trying to fix v_m in model.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7957 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/model.cpp b/model.cpp index 2cf338e6..f717dde3 100644 --- a/model.cpp +++ b/model.cpp @@ -2714,22 +2714,21 @@ calc_gas_pressures(void) V_m = gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles(); if (V_m < 0.016) { - V_m = 0.016; + V_m = 0.016; } else if (V_m > 1e4) { V_m = 1e4; } - if (gas_phase_ptr->Get_v_m() > 0.016) - { - if (V_m < 0.04) - V_m = (9. * gas_phase_ptr->Get_v_m() + V_m) / 10; - else if (V_m < 0.045) - V_m = (6. * gas_phase_ptr->Get_v_m() + V_m) / 7; - else if (V_m < 0.07) - V_m = (3. * gas_phase_ptr->Get_v_m() + V_m) / 4; - else - V_m = (1. * gas_phase_ptr->Get_v_m() + V_m) / 2; - } + if (V_m < 0.02) + V_m = (8. * gas_phase_ptr->Get_v_m() + V_m) / 9; + else if (V_m < 0.03) + V_m = (6. * gas_phase_ptr->Get_v_m() + V_m) / 7; + else if (V_m < 0.05) + V_m = (4. * gas_phase_ptr->Get_v_m() + V_m) / 5; + else if (V_m < 0.07) + V_m = (2. * gas_phase_ptr->Get_v_m() + V_m) / 3; + else + V_m = (1. * gas_phase_ptr->Get_v_m() + V_m) / 2; if (iterations > 99) { //V_m *= 1; /* debug */ From 43f5baf0bd48bade589cfc5946d5bc34a5a46d94 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 26 Aug 2013 20:20:16 +0000 Subject: [PATCH 0740/1077] Tony's latest changes, including F1 and F2. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7962 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 69 ++++++++++++++++++++++++++++++++++++------------------ print.cpp | 24 +++++++++---------- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index c6ffaaa1..06b5cc0f 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -835,8 +835,8 @@ pitzer(void) CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, BMXPHI, PHIPHI, AW, A, B; */ - LDBLE CONV, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, - B; + LDBLE CONV, XX, OSUM, BIGZ, DI, F, F1, F2, F_var, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + B, B1, B2; LDBLE I, TK; int LNEUT; /* @@ -845,8 +845,8 @@ pitzer(void) C */ CONV = 1.0 / log(10.0); - XX = 0.0e0; - OSUM = 0.0e0; + XX = 0.0; + OSUM = 0.0; LNEUT = FALSE; /*n I = *I_X; @@ -913,22 +913,35 @@ pitzer(void) C */ B = 1.2; - F = -A0 * (DI / (1.0e0 + B * DI) + 2.0e0 * log(1.0e0 + B * DI) / B); - XXX = 2.0e0 * DI; + F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B); + if (patm_x > 1.0) + { + LDBLE pap; + pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x; + B1 = B - (pap > 0.2 ? 0.2 : pap); + pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); + //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + B2 = B - (pap > 0.2 ? 0.2 : pap); + if (B1 != 0) + F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); + if (B2 != 0) + F2 = -A0 * (DI / (1.0 + B2 * DI) + 2.0 * log(1.0 + B2 * DI) / B2); + } + XXX = 2.0 * DI; XXX = - (1.0e0 - (1.0e0 + XXX - XXX * XXX * 0.5e0) * exp(-XXX)) / (XXX * XXX); + (1.0 - (1.0 + XXX - XXX * XXX * 0.5) * exp(-XXX)) / (XXX * XXX); /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I; */ /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I; */ /*GAMCLM = F + I * 2.0e0 * (mcb0->p + mcb1->p * XXX) + 1.5e0 * mcc0->p * I * I; */ - GAMCLM = F; + GAMCLM = F1; if (mcb0 != NULL) - GAMCLM += I * 2.0e0 * mcb0->p; + GAMCLM += I * 2.0 * mcb0->p; if (mcb1 != NULL) - GAMCLM += I * 2.0e0 * mcb1->p * XXX; + GAMCLM += I * 2.0 * mcb1->p * XXX; if (mcc0 != NULL) - GAMCLM += 1.5e0 * mcc0->p * I * I; - CSUM = 0.0e0; - OSMOT = -(A0) * pow(I, (LDBLE) 1.5e0) / (1.0e0 + B * DI); + GAMCLM += 1.5 * mcc0->p * I * I; + CSUM = 0.0; + OSMOT = -(A0) * pow(I, (LDBLE) 1.5) / (1.0 + B * DI); /* * Calculate ethetas */ @@ -953,6 +966,7 @@ pitzer(void) z1 = spec[i1]->z; param = pitz_params[i]->p; l_alpha = pitz_params[i]->alpha; + F_var = 0; switch (pitz_params[i]->type) { case TYPE_B0: @@ -963,7 +977,7 @@ pitzer(void) case TYPE_B1: if (param != 0.0) { - F += M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + F_var = M[i0] * M[i1] * param * GP(l_alpha * DI) / I; LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); @@ -972,7 +986,7 @@ pitzer(void) case TYPE_B2: if (param != 0.0) { - F += M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + F_var = M[i0] * M[i1] * param * GP(l_alpha * DI) / I; LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); @@ -980,7 +994,7 @@ pitzer(void) break; case TYPE_C0: CSUM += - M[i0] * M[i1] * pitz_params[i]->p / (2.0e0 * + M[i0] * M[i1] * pitz_params[i]->p / (2.0 * sqrt(fabs(z0 * z1))); LGAMMA[i0] += M[i1] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); LGAMMA[i1] += M[i0] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); @@ -1000,7 +1014,7 @@ pitzer(void) { etheta = pitz_params[i]->thetas->etheta; ethetap = pitz_params[i]->thetas->ethetap; - F += M[i0] * M[i1] * ethetap; + F_var = M[i0] * M[i1] * ethetap; LGAMMA[i0] += 2.0 * M[i1] * etheta; LGAMMA[i1] += 2.0 * M[i0] * etheta; OSMOT += M[i0] * M[i1] * (etheta + I * ethetap); @@ -1062,6 +1076,9 @@ pitzer(void) error_msg("TYPE_Other in pitz_param list.", STOP); break; } + F += F_var; + F1 += F_var; + F2 += F_var; } /* @@ -1070,13 +1087,19 @@ pitzer(void) for (i = 0; i < count_cations; i++) { - z0 = spec[i]->z; - LGAMMA[i] += z0 * z0 * F + fabs(z0) * CSUM; + if (!IPRSNT[i]) + continue; + z0 = fabs(spec[i]->z); + F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; } for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) { - z0 = spec[i]->z; - LGAMMA[i] += z0 * z0 * F + fabs(z0) * CSUM; + if (!IPRSNT[i]) + continue; + z0 = fabs(spec[i]->z); + F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; } /* C @@ -1100,13 +1123,13 @@ pitzer(void) } } - COSMOT = 1.0e0 + 2.0e0 * OSMOT / OSUM; + COSMOT = 1.0 + 2.0 * OSMOT / OSUM; /* C C CALCULATE THE ACTIVITY OF WATER C */ - AW = exp(-OSUM * COSMOT / 55.50837e0); + AW = exp(-OSUM * COSMOT / 55.50837); /* if (AW > 1.0) AW = 1.0; diff --git a/print.cpp b/print.cpp index 4eb805f6..fb05369b 100644 --- a/print.cpp +++ b/print.cpp @@ -568,10 +568,10 @@ print_gas_phase(void) print_centered("Gas phase"); output_msg(sformatf("Total pressure: %5.2f atmospheres", (double) gas_phase_ptr->Get_total_p())); - if (PR) - output_msg(" (Peng-Robinson calculation)\n"); - else if (gas_phase_ptr->Get_total_p() >= 1500) + if (gas_phase_ptr->Get_total_p() >= 1500) output_msg(" WARNING: Program limit.\n"); + else if (PR) + output_msg(" (Peng-Robinson calculation)\n"); else output_msg(" \n"); output_msg(sformatf(" Gas volume: %10.2e liters\n", @@ -589,7 +589,7 @@ print_gas_phase(void) (double) (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()))); } } - if (!numerical_fixed_volume && ((PR && gas_phase_ptr->Get_v_m() <= 0.016))) + if (/*!numerical_fixed_volume && */((PR && gas_phase_ptr->Get_v_m() <= 0.016))) output_msg(" WARNING: Program limit for Peng-Robinson.\n"); else output_msg("\n"); @@ -1216,7 +1216,7 @@ print_saturation_indices(void) * Print heading */ print_centered("Saturation indices"); - output_msg(sformatf("\t%-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI**", + output_msg(sformatf(" %-15s%9s%8s%9s%3d%4s%3d%4s\n\n", "Phase", "SI**", "log IAP", "log K(", int(tk_x), " K, ", int(floor(patm_x + 0.5)), " atm)")); for (i = 0; i < count_phases; i++) @@ -1251,7 +1251,7 @@ print_saturation_indices(void) } si = -lk + iap; - output_msg(sformatf("\t%-15s%7.2f %8.2f%8.2f %s", + output_msg(sformatf(" %-15s%7.2f %8.2f%8.2f %s", phases[i]->name, (double) si, (double) iap, (double) lk, phases[i]->formula)); if (gas && phases[i]->pr_in && phases[i]->pr_p) @@ -1280,8 +1280,8 @@ print_saturation_indices(void) output_msg("\n"); } output_msg(sformatf("\n%s\n%s", - "**For a gas, SI = log10(fugacity). For ideal gases, fugacity = pressure / 1 atm.", - "For a Peng-Robinson gas, fugacity = pressure * phi / 1 atm")); + "**For a gas, SI = log10(fugacity). Fugacity = pressure * phi / 1 atm.", + " For ideal gases, phi = 1.")); output_msg("\n\n"); return (OK); @@ -1435,9 +1435,9 @@ print_species(void) } else { - output_msg(sformatf("%67s%11s\n", "Unscaled", "Unscaled")); - output_msg(sformatf("\t%-15s%12s%12s%10s%10s%10s\n", " ", - " ", "Unscaled", "Log ", "Log ", "Log ")); + output_msg(sformatf("%60s%10s\n", "Unscaled", "Unscaled")); + output_msg(sformatf("%40s%10s%10s%10s%10s\n", + "Unscaled", "Log", "Log", "Log", "mole V")); } } else @@ -2136,7 +2136,7 @@ print_totals(void) dens = calc_dens(); output_msg(sformatf("%45s%9.5f", "Density (g/cm3) = ", (double) dens)); - if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program's limit)")); + if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program limit)")); else output_msg(sformatf("\n")); output_msg(sformatf("%45s%9.5f\n", " Volume (L) = ", (double) calc_solution_volume())); From a99ef8b3a8c29c2e884a51fa735eaa88e265eb76 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 27 Aug 2013 05:07:46 +0000 Subject: [PATCH 0741/1077] changes req'd for multi_punch git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7967 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index 157a88b5..f049af0b 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2089,7 +2089,6 @@ punch_model_heading(struct inverse *inv_ptr) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - current_selected_output->Get_punch_ostream() == NULL || !current_selected_output->Get_inverse() || !current_selected_output->Get_active()) continue; @@ -2268,7 +2267,6 @@ punch_model(struct inverse *inv_ptr) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - current_selected_output->Get_punch_ostream() == NULL || !current_selected_output->Get_inverse() || !current_selected_output->Get_active()) continue; @@ -2280,15 +2278,15 @@ punch_model(struct inverse *inv_ptr) */ if (!current_selected_output->Get_high_precision()) { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) (error / SCALE_EPSILON)); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) scaled_error); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) max_pct); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) (error / SCALE_EPSILON)); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) scaled_error); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) max_pct); } else { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) (error / SCALE_EPSILON)); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) scaled_error); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) max_pct); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) (error / SCALE_EPSILON)); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) scaled_error); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) max_pct); } /* * write solution fractions @@ -2306,15 +2304,15 @@ punch_model(struct inverse *inv_ptr) d3 = 0.0; if (!current_selected_output->Get_high_precision()) { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d1); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d2); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d3); } else { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d1); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d2); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d3); } } /* @@ -2333,15 +2331,15 @@ punch_model(struct inverse *inv_ptr) d3 = 0.0; if (!current_selected_output->Get_high_precision()) { - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%15.4e\t", (double) d3); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d1); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d2); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d3); } else { - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d1); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d2); - fpunchf_user(n_user_punch_index++, "%20.12e\t", (double) d3); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d1); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d2); + fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d3); } } punch_msg("\n"); From 32b9285dfad177cda1627f56f30eb1256ffa7306 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 27 Aug 2013 21:36:03 +0000 Subject: [PATCH 0742/1077] changes req'd for multi_punch git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7974 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index f049af0b..a14f610f 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2125,7 +2125,7 @@ punch_model_heading(struct inverse *inv_ptr) { std::string tok1(col_name[i]); - tok1.append("_max"); + tok1.append("_min"); std::string tok2(col_name[i]); tok2.append("_max"); @@ -2278,15 +2278,15 @@ punch_model(struct inverse *inv_ptr) */ if (!current_selected_output->Get_high_precision()) { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) (error / SCALE_EPSILON)); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) scaled_error); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) max_pct); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) (error / SCALE_EPSILON)); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) scaled_error); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) max_pct); } else { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) (error / SCALE_EPSILON)); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) scaled_error); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) max_pct); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) (error / SCALE_EPSILON)); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) scaled_error); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) max_pct); } /* * write solution fractions @@ -2304,15 +2304,15 @@ punch_model(struct inverse *inv_ptr) d3 = 0.0; if (!current_selected_output->Get_high_precision()) { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d1); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d2); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d3); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d1); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d2); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d3); } else { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d1); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d2); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d3); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d1); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d2); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d3); } } /* @@ -2331,15 +2331,15 @@ punch_model(struct inverse *inv_ptr) d3 = 0.0; if (!current_selected_output->Get_high_precision()) { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d1); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d2); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%15.4e\t", (double) d3); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d1); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d2); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%15.4e\t", (double) d3); } else { - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d1); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d2); - fpunchf(inverse_heading_names[n_user_punch_index++].c_str(), "%20.12e\t", (double) d3); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d1); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d2); + fpunchf(trim(inverse_heading_names[n_user_punch_index++]).c_str(), "%20.12e\t", (double) d3); } } punch_msg("\n"); From ab6875b5f2286d76979061ef2bf274a75fe388cc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 28 Aug 2013 04:59:11 +0000 Subject: [PATCH 0743/1077] solid_solutions had extra s in selected_output headings git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7977 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 18ed344a..35f7fafe 100644 --- a/print.cpp +++ b/print.cpp @@ -2524,7 +2524,7 @@ punch_ss_assemblage(void) } if (!current_selected_output->Get_high_precision()) { - fpunchf(sformatf("ss_%s", current_selected_output->Get_s_s()[k].first.c_str()), + fpunchf(sformatf("s_%s", current_selected_output->Get_s_s()[k].first.c_str()), "%12.4e\t", (double) moles); } else From b88c4901d60dfb2c3644da9455885d0e81731f7b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 28 Aug 2013 05:03:26 +0000 Subject: [PATCH 0744/1077] fixed for phreeqc3-multi-punch; passes all unit tests git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/multi_punch@7979 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/read.cpp b/read.cpp index 5597e378..9c08bc8d 100644 --- a/read.cpp +++ b/read.cpp @@ -5040,7 +5040,15 @@ read_selected_output(void) // store new selected output SelectedOutput_map[n_user] = temp_selected_output; - if (!punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) + if (punch_open(SelectedOutput_map[n_user].Get_file_name().c_str(), n_user)) + { + if (phrq_io) + { + SelectedOutput_map[n_user].Set_punch_ostream(phrq_io->Get_punch_ostream()); + phrq_io->Set_punch_ostream(NULL); + } + } + else { error_string = sformatf( "Can`t open file, %s.", SelectedOutput_map[n_user].Get_file_name().c_str()); input_error++; From 92a7861814bdef2dbd1637a0b3068b9570ce953d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Aug 2013 16:43:04 +0000 Subject: [PATCH 0745/1077] Added -high_precision to PRINT for USER_PRINT. Made dump_cpp always high precision. Needed to modify ex12a to be consistent with new SELECTED_OUTPUT -active; SELECTED_OUTPUT -user_print now has different meaning. No longer set global high_precision from SELECTED_OUTPUT; only SelectedOutput instance value git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7992 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 17 +++++++++++------ readtr.cpp | 24 ++++++++++++------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/read.cpp b/read.cpp index 9c08bc8d..5cf9c017 100644 --- a/read.cpp +++ b/read.cpp @@ -4978,10 +4978,10 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); value = get_true_false(next_char, TRUE); temp_selected_output.Set_high_precision(value!=FALSE); - if (n_user == 1) - { - high_precision = (value != FALSE); - } + //if (n_user == 1) + //{ + // high_precision = (value != FALSE); + //} if (value == TRUE) { convergence_tolerance = 1e-12; @@ -8341,10 +8341,11 @@ read_print(void) "isotope_alphas", /* 36 */ "censor_species", /* 37 */ "alkalinity", /* 38 */ - "equilibrium_phase" /* 39 */ + "equilibrium_phase", /* 39 */ + "high_precision" /* 40 */ }; - int count_opt_list = 40; + int count_opt_list = 41; int value; /* * Read flags: @@ -8509,6 +8510,10 @@ read_print(void) case 38: /* alkalinity */ pr.alkalinity = get_true_false(next_char, TRUE); break; + case 40: /* high_precision */ + value = get_true_false(next_char, TRUE); + high_precision = (value != FALSE); + break; } if (return_value == EOF || return_value == KEYWORD) break; diff --git a/readtr.cpp b/readtr.cpp index c3cdba7f..77469405 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1127,12 +1127,12 @@ dump_cpp(void) fs << token; sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; - if (!high_precision) - { - sprintf(token, "\t-diffc %13.5e\n", (double) diffc); - fs << token; - } - else + //if (!high_precision) + //{ + // sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + // fs << token; + //} + //else { sprintf(token, "\t-diffc %20.12e\n", (double) diffc); fs << token; @@ -1167,12 +1167,12 @@ dump_cpp(void) fs << token; for (int i = 0; i < count_cells; i++) { - if (!high_precision) - { - sprintf(token, "%12.3e", (double) cell_data[i].disp); - fs << token; - } - else + //if (!high_precision) + //{ + // sprintf(token, "%12.3e", (double) cell_data[i].disp); + // fs << token; + //} + //else { sprintf(token, "%20.12e", (double) cell_data[i].disp); fs << token; From 39abad331d77918206fe6fcf30cd066758737862 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Aug 2013 16:49:03 +0000 Subject: [PATCH 0746/1077] makefile's to run test cases git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7993 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 823 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 823 insertions(+) create mode 100644 Makefile.old diff --git a/Makefile.old b/Makefile.old new file mode 100644 index 00000000..1815601e --- /dev/null +++ b/Makefile.old @@ -0,0 +1,823 @@ +# Makefile for PHREEQCPP +# +# Generates object files and executables for 2 versions of PHREEQCPP +# Release +# Debug +# +# Serial verisons: Release Debug +# +# Makefile sets CFG variable, cd's to appropriate directory, runs Makefile recursively +# Recursive make sets appropriate compiler, objects, options, libraries, and compiles PHREEQC +# + +PROGRAM = phreeqc + +CFG1 :=`uname` +CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") +ifeq ($(CFG), CYGWIN) + SPOOL=> + SPOOL2=2>&1 +else + SPOOL=>& + SPOOL2= +endif + +all: class_release class_debug + +Debug: class_debug +debug: class_debug +Class_debug: class_debug + +Release: class_release +release: class_release +Class_release: class_release + +Debug_64: class_debug_64 +debug_64: class_debug_64 +Class_debug_64: class_debug_64 + +Release_64: class_release_64 +release_64: class_release_64 +Class_release_64: class_release_64 + + +CLASS_DEBUG_DIR = Class_debug +CLASS_DIR = Class_release +CLASS_DEBUG_64_DIR = Class_debug_64 +CLASS_64_DIR = Class_release_64 +MAKEFILE = Makefile.old + +# ----------------------------------------------------------------------------- +# fixes shared object lookup error(SIGFPE floating point exception) +HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) + + +######################### +#### Serial Versions #### +######################### +.PHONY : Class_debug +class_debug: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) + +.PHONY : Class_release +class_release: + mkdir -p $(CLASS_DIR) + cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) +.PHONY : Class_debug_64 +class_debug_64: + mkdir -p $(CLASS_DEBUG_64_DIR) + cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) + +.PHONY : Class_release_64 +class_release_64: + mkdir -p $(CLASS_64_DIR) + cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) + +# Recursive make begins here +# +# ============================================================================= +# Significant suffixes [assuming Fortran 90 (.f90) source code]: +# Significant suffixes [assuming Fortran 90 (.F90) source code, needs to be preprocessed ]: +# ============================================================================= + +#SRC = ../phreeqc +.SUFFIXES : .o .c .cxx .cpp + +# compilers + +# ----------------------------------------------------------------------------- +.c.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< + +.cxx.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< + +.cpp.o : + ${CXX} ${CXXFLAGS} -c -o $@ $< + +# ----------------------------------------------------------------------------- +#hdf options +#HDF5_ROOT=$(HOME)/../../usr +#HDF5_INCLUDES=-I$(HDF5_ROOT)/src +#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread + +# ----------------------------------------------------------------------------- +# #define compile options + +# ----------------------------------------------------------------------------- +# #define gmp for inverse modeling +# comment the following lines to remove multiprecision option + +# ----------------------------------------------------------------------------- +#efence for debugging +EFENCE_LIB=-L$(HOME)/packages/efence + +# ----------------------------------------------------------------------------- +# 4 Versions +# ----------------------------------------------------------------------------- +ifeq ($(CFG), CLASS_DEBUG) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = .. + INCLUDES = -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o +# CL1MP_LIB=-lgmp + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = .. + INCLUDES = -I.. + CXX = g++ + CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_DEBUG_64) +# INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o + CL1MP_LIB=libgmp.a + endif + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = .. + INCLUDES = -I.. + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +ifeq ($(CFG), CLASS_RELEASE_64) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o + CL1MP_LIB=/usr/lib64/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = .. + INCLUDES = -I.. + CXX = g++ + PROFILE = + CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} +endif + +# ----------------------------------------------------------------------------- +# + +COMMON_COBJS = \ + advection.o \ + basicsubs.o \ + cl1.o \ + cvdense.o \ + cvode.o \ + dense.o \ + dw.o \ + gases.o \ + input.o \ + integrate.o \ + inverse.o \ + isotopes.o \ + kinetics.o \ + mainsubs.o \ + model.o \ + nvector.o \ + nvector_serial.o \ + parse.o \ + PHRQ_io_output.o \ + phqalloc.o \ + pitzer.o \ + pitzer_structures.o \ + prep.o \ + print.o \ + read.o \ + readtr.o \ + sit.o \ + smalldense.o \ + spread.o \ + step.o \ + structures.o \ + sundialsmath.o \ + tally.o \ + tidy.o \ + transport.o \ + utilities.o + +MAIN_FILE = main.o + +CLASS_FILES = \ + class_main.o \ + Phreeqc.o + + +COMMON_CXXOBJS = \ + dumper.o \ + Exchange.o \ + ExchComp.o \ + GasPhase.o \ + GasComp.o \ + ISolution.o \ + ISolutionComp.o \ + Keywords.o \ + KineticsComp.o \ + cxxKinetics.o \ + cxxMix.o \ + NameDouble.o \ + NumKeyword.o \ + Parser.o \ + PBasic.o \ + PHRQ_base.o \ + PHRQ_io.o \ + PPassemblageComp.o \ + PPassemblage.o \ + Pressure.o \ + Reaction.o \ + ReadClass.o \ + runner.o \ + SelectedOutput.o \ + Solution.o \ + SolutionIsotope.o \ + SSassemblage.o \ + SScomp.o \ + SS.o \ + StorageBin.o \ + StorageBinList.o \ + Surface.o \ + SurfaceCharge.o \ + SurfaceComp.o \ + System.o \ + Temperature.o \ + Use.o \ + UserPunch.o \ + Utils.o + +# ----------------------------------------------------------------------------- +# Assign dependents to target on dependency line & link options on command +# line. Command line is initiated with a tab. ($@ is an internal macro for +# the current target.) + +${PROGRAM} : ${OBJECT_FILES} +# ${CXX} -p -o $@ ${OBJECT_FILES} ${LD_FLAGS} + ${CXX} -o $@ ${OBJECT_FILES} ${LD_FLAGS} + @echo; echo Done making for phreeqcpp +# ----------------------------------------------------------------------------- +# Module dependency list +# ----------------------------------------------------------------------------- +# +# CXX files +# +cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../cxxKinetics.h ../KineticsComp.h ../phqalloc.h +cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Exchange.h ../ExchComp.h ../phqalloc.h +ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../ExchComp.h ../phqalloc.h +GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../GasComp.h ../phqalloc.h +GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../GasPhase.h ../GasComp.h ../phqalloc.h +ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../ISolutionComp.h \ + ../phrqtype.h ../Parser.h ../PHRQ_base.h ../Keywords.h ../PHRQ_io.h \ + ../Solution.h ../NumKeyword.h ../SolutionIsotope.h ../NameDouble.h \ + ../ISolution.h ../global_structures.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../NA.h ../phqalloc.h +ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../ISolution.h ../ISolutionComp.h ../phqalloc.h +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../KineticsComp.h ../phqalloc.h +NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../ISolutionComp.h +NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ + ../Parser.h ../Keywords.h ../PHRQ_io.h ../Utils.h +Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../PHRQ_io.h +PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ + ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ + ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ + ../NA.h ../PPassemblageComp.h ../phqalloc.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../PPassemblage.h ../PPassemblageComp.h ../phqalloc.h +Pressure.o: ../Pressure.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Reaction.h ../phqalloc.h +ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Exchange.h ../ExchComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../cxxKinetics.h ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../GasPhase.h ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h +Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../phqalloc.h +SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ + ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ + ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ + ../NA.h ../SolutionIsotope.h ../phqalloc.h +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../phqalloc.h +SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../SScomp.h ../phqalloc.h +SS.o: ../SS.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Utils.h ../SS.h \ + ../SScomp.h ../phqalloc.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../StorageBin.h ../System.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h \ + ../Temperature.h ../phqalloc.h +SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ + ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ + ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ + ../NA.h ../phqalloc.h +SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Surface.o: ../Surface.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +System.o: ../System.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../System.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h ../Temperature.h +Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ + ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ + ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Temperature.h ../phqalloc.h +Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ../Keywords.h \ + ../PHRQ_io.h +advection.o: ../advection.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +basicsubs.o: ../basicsubs.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Utils.h ../PBasic.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h +ChartHandler.o: ../ChartHandler.cpp +ChartObject.o: ../ChartObject.cpp +cl1.o: ../cl1.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +cl1mp.o: ../cl1mp.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +class_main.o: ../class_main.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h +CurveObject.o: ../CurveObject.cpp +cvdense.o: ../cvdense.cpp ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../phrqtype.h ../nvector.h ../dense.h ../smalldense.h ../sundialsmath.h \ + ../Phreeqc.h ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h \ + ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ + ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +cvode.o: ../cvode.cpp ../cvode.h ../sundialstypes.h ../phrqtype.h \ + ../nvector.h ../sundialsmath.h ../Phreeqc.h ../cvdense.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +dense.o: ../dense.cpp ../sundialstypes.h ../phrqtype.h ../sundialsmath.h \ + ../dense.h ../smalldense.h +dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ + ../Parser.h ../Keywords.h ../PHRQ_io.h +dw.o: ../dw.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h +gases.o: ../gases.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../GasPhase.h \ + ../GasComp.h +input.o: ../input.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +integrate.o: ../integrate.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Utils.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h +inverse.o: ../inverse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Utils.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h +isotopes.o: ../isotopes.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +Keywords.o: ../Keywords.cpp ../Keywords.h +kinetics.o: ../kinetics.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ + ../KineticsComp.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../Temperature.h ../nvector_serial.h +mainsubs.o: ../mainsubs.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +model.o: ../model.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h ../phrqtype.h +nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.h \ + ../sundialstypes.h ../phrqtype.h ../sundialsmath.h +parse.o: ../parse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +PBasic.o: ../PBasic.cpp ../PBasic.h ../phrqtype.h ../PHRQ_base.h \ + ../global_structures.h ../Surface.h ../NumKeyword.h ../SurfaceComp.h \ + ../NameDouble.h ../Parser.h ../Keywords.h ../PHRQ_io.h \ + ../SurfaceCharge.h ../NA.h ../Phreeqc.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../phqalloc.h ../Utils.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +phqalloc.o: ../phqalloc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h +Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../phqalloc.h ../PBasic.h \ + ../Temperature.h +PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h ../Keywords.h ../Parser.h \ + ../PHRQ_base.h +PHRQ_io_output.o: ../PHRQ_io_output.cpp ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +pitzer.o: ../pitzer.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Exchange.h ../ExchComp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +pitzer_structures.o: ../pitzer_structures.cpp ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +prep.o: ../prep.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +print.o: ../print.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +read.o: ../read.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +readtr.o: ../readtr.cpp ../StorageBin.h ../System.h ../NameDouble.h \ + ../Parser.h ../PHRQ_base.h ../Keywords.h ../PHRQ_io.h ../phrqtype.h \ + ../SS.h ../SScomp.h ../Phreeqc.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../dumper.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h +runner.o: ../runner.cpp ../runner.h ../phrqtype.h ../StorageBinList.h \ + ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h ../NA.h ../Utils.h +sit.o: ../sit.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Exchange.h ../ExchComp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +smalldense.o: ../smalldense.cpp ../smalldense.h ../sundialstypes.h \ + ../phrqtype.h ../sundialsmath.h +spread.o: ../spread.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Utils.h +step.o: ../step.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Utils.h ../StorageBin.h ../System.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../cxxKinetics.h ../KineticsComp.h +StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ + ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h +structures.o: ../structures.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../StorageBin.h ../System.h +sundialsmath.o: ../sundialsmath.cpp ../sundialsmath.h ../sundialstypes.h \ + ../phrqtype.h +tally.o: ../tally.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +tidy.o: ../tidy.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +transport.o: ../transport.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +Use.o: ../Use.cpp ../Use.h +utilities.o: ../utilities.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +# ----------------------------------------------------------------------------- +clean: + rm -rf Class_release Class_debug Class_release_64 Class_debug_64 + +dependencies: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp + +tester: + cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make -f Makefile.old clean; make -f Makefile.old -k -j 1 $(SPOOL) make.out $(SPOOL2); make -f Makefile.old diff $(SPOOL) diff.out $(SPOOL2) + svn status -q ../mytest + svn status -q ../examples + +#ld-option +# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=sysv) +comma=, +ld-option = $(shell if $(CC) $(1) \ + -nostdlib -o /dev/null -xc /dev/null \ + > /dev/null 2>&1 ; then echo "$(1)" ; else echo "$(2)"; fi) + +# ============================================================================= +# End of makefile. +# ============================================================================= From 7c66a50b9b8111fd98c70306709cb08b8c8a99d6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 29 Aug 2013 17:17:13 +0000 Subject: [PATCH 0747/1077] changed back to using high_precision bool for diffc and disp in dump_cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7994 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 77469405..c3cdba7f 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -1127,12 +1127,12 @@ dump_cpp(void) fs << token; sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; - //if (!high_precision) - //{ - // sprintf(token, "\t-diffc %13.5e\n", (double) diffc); - // fs << token; - //} - //else + if (!high_precision) + { + sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + fs << token; + } + else { sprintf(token, "\t-diffc %20.12e\n", (double) diffc); fs << token; @@ -1167,12 +1167,12 @@ dump_cpp(void) fs << token; for (int i = 0; i < count_cells; i++) { - //if (!high_precision) - //{ - // sprintf(token, "%12.3e", (double) cell_data[i].disp); - // fs << token; - //} - //else + if (!high_precision) + { + sprintf(token, "%12.3e", (double) cell_data[i].disp); + fs << token; + } + else { sprintf(token, "%20.12e", (double) cell_data[i].disp); fs << token; From d3ed690461ced1dd6995c2eb4b64dc6953c14504 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 30 Aug 2013 04:29:19 +0000 Subject: [PATCH 0748/1077] updated to allow charts to stay open in phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@7997 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 1 + Form1.h | 36 +++++++++++++++++++++++++----------- structures.cpp | 2 ++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index c32a2995..9f9bee89 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -179,6 +179,7 @@ ChartHandler::End_timer() } #endif it->second->Set_end_timer(true); + it->second->Set_phreeqc(NULL); #if defined(__cplusplus_cli) int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); assert(n == 6); diff --git a/Form1.h b/Form1.h index fde8ff90..3c4d6be5 100644 --- a/Form1.h +++ b/Form1.h @@ -18,12 +18,10 @@ namespace zdg_ui2 { // Form1 is only used with MULTICHART public ref class ChartObj : public System::Object { - public: Phreeqc* phreeqc_ptr; public: ChartObject* chartobject_ptr; public: ChartObj(ChartObject* ptr) { this->chartobject_ptr = ptr; - this->phreeqc_ptr = this->chartobject_ptr->Get_phreeqc(); } }; @@ -33,8 +31,10 @@ namespace zdg_ui2 { public: Form1(ChartObject *ptr) { this->chartobject_ptr = ptr; - this->phreeqc_ptr = chartobject_ptr->Get_phreeqc(); - this->phreeqc_ptr->Get_chart_handler().Increment_active_charts(); + if (Phreeqc* ptr = this->chartobject_ptr->Get_phreeqc()) + { + ptr->Get_chart_handler().Increment_active_charts(); + } InitializeComponent(); col_use = 0; symbol_use = 0; @@ -71,9 +71,12 @@ namespace zdg_ui2 { { chart->Set_done(true); System::Threading::Interlocked::Exchange(this->chartobject_ptr->usingResource, 0); + if (Phreeqc* ptr = chart->Get_phreeqc()) + { + ptr->Get_chart_handler().Decrement_active_charts(); + chart->Set_phreeqc(NULL); + } } - this->phreeqc_ptr->Get_chart_handler().Decrement_active_charts(); - this->phreeqc_ptr = NULL; this->chartobject_ptr = NULL; } @@ -98,7 +101,10 @@ namespace zdg_ui2 { if (LogX && chart->Get_axis_scale_x()[4] == 10.0 && Curves[i]->Get_x()[i2] <= 0) { - this->phreeqc_ptr->warning_msg("Obtained x_value <= 0, removing point..."); + if (Phreeqc* ptr = chart->Get_phreeqc()) + { + ptr->warning_msg("Obtained x_value <= 0, removing point..."); + } //axis_scale_x[4] = NA; /* if reverting to linear... */ //LogX = false; return true; @@ -109,14 +115,20 @@ namespace zdg_ui2 { { if (Curves[i]->Get_y_axis() == 2 && LogY2) { - this->phreeqc_ptr->warning_msg("Obtained sy_value <= 0, removing point......"); + if (Phreeqc* ptr = chart->Get_phreeqc()) + { + ptr->warning_msg("Obtained sy_value <= 0, removing point......"); + } //axis_scale_y2[4] = NA; //LogY2 = false; return true; } else if (LogY) { - this->phreeqc_ptr->warning_msg("Obtained y_value <= 0, removing point......"); + if (Phreeqc* ptr = chart->Get_phreeqc()) + { + ptr->warning_msg("Obtained y_value <= 0, removing point......"); + } //axis_scale_y[4] = NA; //LogY = false; return true; @@ -541,7 +553,10 @@ namespace zdg_ui2 { { if (this->chartobject_ptr != NULL) { - this->phreeqc_ptr->error_msg(estring.c_str(), CONTINUE); + if (Phreeqc* ptr = this->chartobject_ptr->Get_phreeqc()) + { + ptr->error_msg(estring.c_str(), CONTINUE); + } } else { @@ -1071,7 +1086,6 @@ namespace zdg_ui2 { public: ZedGraph::ZedGraphControl ^zg1; private: System::Windows::Forms::Timer ^timer1; private: System::ComponentModel::Container ^components; - private: Phreeqc * phreeqc_ptr; ChartObject * chartobject_ptr; public: diff --git a/structures.cpp b/structures.cpp index 8272c23c..77f8cf57 100644 --- a/structures.cpp +++ b/structures.cpp @@ -28,11 +28,13 @@ clean_up(void) #if defined MULTICHART chart_handler.End_timer(); output_flush(); +#if 0 // Wait for charts to end while (0 != this->chart_handler.Get_active_charts()) { System::Threading::Thread::Sleep(60); } +#endif #endif description_x = (char *) free_check_null(description_x); From 4983afc68e10b10259e088921eccc7a0d8f52ff3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Sep 2013 17:06:20 +0000 Subject: [PATCH 0749/1077] Got a request for interacting sites, such as this surface complex. Anat_uniOH(Anat_diO)Sn(OH)2-1 Not sure how one would calculate an activity (equivalent fraction), so did not change, but added add_elt_list_multi_surf for a start. Would also need to change gammas to change the way the activity coefficient for the mixed species was calculated. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8009 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + mainsubs.cpp | 2 ++ prep.cpp | 3 +- utilities.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 50f1188d..aec1372d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1050,6 +1050,7 @@ public: // utilities.cpp ------------------------------- public: int add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef); + int add_elt_list_multi_surf(struct elt_list *elt_list_ptr, LDBLE coef, struct element *surf_elt_ptr); int add_elt_list(const cxxNameDouble & nd, LDBLE coef); protected: int backspace_screen(int spaces); diff --git a/mainsubs.cpp b/mainsubs.cpp index 851b67e5..65dae176 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1624,6 +1624,8 @@ xsurface_save(int n_user) { add_elt_list(species_list[j].s->next_elt, species_list[j].s->moles); + //add_elt_list_multi_surf(species_list[j].s->next_elt, + // species_list[j].s->moles, x[i]->master[0]->elt); charge += species_list[j].s->moles * species_list[j].s->z; } } diff --git a/prep.cpp b/prep.cpp index 125e3658..0c89258b 100644 --- a/prep.cpp +++ b/prep.cpp @@ -3371,7 +3371,8 @@ setup_surface(void) continue; /* * Check that data not already given - */ if (master_ptr->in != FALSE) + */ + if (master_ptr->in != FALSE) { error_string = sformatf( "Analytical data entered twice for %s.", diff --git a/utilities.cpp b/utilities.cpp index 54fefcf5..30f25df2 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -31,6 +31,83 @@ add_elt_list(struct elt_list *elt_list_ptr, LDBLE coef) return (OK); } +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +add_elt_list_multi_surf(struct elt_list *elt_list_ptr, LDBLE coef, struct element *surf_elt_ptr) +/* ---------------------------------------------------------------------- */ +{ + struct elt_list *elt_list_ptr1; + + if (elt_list_ptr == NULL || surf_elt_ptr == NULL) + return (OK); + + // determine if surf_elt_ptr is first surface + bool first_surface = true; + for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; + elt_list_ptr1++) + { + if (elt_list_ptr1->elt->master->type == SURF) + { + if (elt_list_ptr1->elt == surf_elt_ptr) + { + first_surface = true; + break; + } + else + { + first_surface = false; + break; + } + } + } + if (first_surface) + { + for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; + elt_list_ptr1++) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + if (elt_list_ptr1->elt == surf_elt_ptr) + { + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } + else if (elt_list_ptr1->elt->master->type == SURF) + { + continue; + } + else + { + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } + } + } + else + { + for (elt_list_ptr1 = elt_list_ptr; elt_list_ptr1->elt != NULL; + elt_list_ptr1++) + { + if (count_elts >= max_elts) + { + space((void **) ((void *) &elt_list), count_elts, &max_elts, + sizeof(struct elt_list)); + } + if (elt_list_ptr1->elt == surf_elt_ptr) + { + elt_list[count_elts].elt = elt_list_ptr1->elt; + elt_list[count_elts].coef = elt_list_ptr1->coef * coef; + count_elts++; + } + } + } + return (OK); +} int Phreeqc:: add_elt_list(const cxxNameDouble & nd, LDBLE coef) /* ---------------------------------------------------------------------- */ @@ -50,7 +127,6 @@ add_elt_list(const cxxNameDouble & nd, LDBLE coef) return (OK); } - /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_alk(struct reaction * rxn_ptr) From c1687e21b27a855c8e4dea8aa8b2ef21b45256a7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 10 Sep 2013 22:57:00 +0000 Subject: [PATCH 0750/1077] updates reqd for vs2010 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8025 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/read.cpp b/read.cpp index 5cf9c017..34d9a5c5 100644 --- a/read.cpp +++ b/read.cpp @@ -4762,7 +4762,7 @@ read_selected_output(void) } else { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_totals().push_back(t_pair); } } @@ -4780,7 +4780,7 @@ read_selected_output(void) } else { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_molalities().push_back(t_pair); } } @@ -4797,7 +4797,7 @@ read_selected_output(void) } else { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_activities().push_back(t_pair); } } @@ -4811,7 +4811,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_pure_phases().push_back(t_pair); } break; @@ -4820,7 +4820,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_si().push_back(t_pair); } break; @@ -4828,7 +4828,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_gases().push_back(t_pair); } break; @@ -4845,7 +4845,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_kinetics().push_back(t_pair); } break; @@ -4853,7 +4853,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_s_s().push_back(t_pair); } break; @@ -4869,7 +4869,7 @@ read_selected_output(void) } else { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_isotopes().push_back(t_pair); } } @@ -4878,7 +4878,7 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); while ((i = copy_token(token, &next_char, &l)) != EMPTY) { - std::pair< std::string, void *> t_pair(token, NULL); + std::pair< std::string, void *> t_pair(token, ((void *)0)); temp_selected_output.Get_calculate_values().push_back(t_pair); } break; From b3d02ae5a72c7c531b0f7ba48b71deb83f9434e0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 13 Sep 2013 21:18:23 +0000 Subject: [PATCH 0751/1077] Added river turning into drain in IPhreeqc version of PHAST git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8034 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index a140c150..1f0b5aa9 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3611,7 +3611,7 @@ basic_callback(double x1, double x2, char * str) } if (basic_fortran_callback_ptr != NULL) { - return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, strlen(str)); + return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, (int) strlen(str)); } return 0; } From 9d1f0e34e54ef3756e9a53cce885bbfe954fc444 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 23 Sep 2013 18:25:40 +0000 Subject: [PATCH 0752/1077] set unknown state just in case. extra indent in write_raw for solution in front of -pH git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8071 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 1 - print.cpp | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index e1783fb7..2218a706 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -244,7 +244,6 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con this->totals.dump_raw(s_oss, indent + 2); // Isotopes - s_oss << indent1; { for (std::map < std::string, cxxSolutionIsotope >::const_iterator it = this->isotopes.begin(); it != isotopes.end(); ++it) diff --git a/print.cpp b/print.cpp index 432f69c9..6deca68c 100644 --- a/print.cpp +++ b/print.cpp @@ -2821,6 +2821,9 @@ punch_identifiers(void) case 8: strcpy(token, "transp"); break; + default: + strcpy(token, "unknown"); + break; } fpunchf(PHAST_NULL("state"), sformat, token); From b956c83779c60d69031ba0dd382f32aef5c9b01d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 30 Sep 2013 20:49:43 +0000 Subject: [PATCH 0753/1077] fixed memory leak git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8087 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- structures.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/structures.cpp b/structures.cpp index 77f8cf57..b2f0973e 100644 --- a/structures.cpp +++ b/structures.cpp @@ -212,6 +212,7 @@ clean_up(void) /* user_print and user_punch */ rate_free(user_print); + user_print = (struct rate *) free_check_null(user_print); #ifdef SKIP rate_free(user_punch); user_print = (struct rate *) free_check_null(user_print); From 5edcc20bb9f04f36a06c9aefb5c7f15649125dc9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 1 Oct 2013 05:31:36 +0000 Subject: [PATCH 0754/1077] added assert for phreeqci git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8092 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/read.cpp b/read.cpp index 34d9a5c5..645a57c7 100644 --- a/read.cpp +++ b/read.cpp @@ -4699,6 +4699,9 @@ read_selected_output(void) temp_selected_output.Set_percent_error ( so_ref.Get_percent_error() ); temp_selected_output.Set_have_punch_name ( so_ref.Get_have_punch_name() ); temp_selected_output.Set_file_name ( so_ref.Get_file_name() ); +#if PHREEQCI_GUI + assert(false); +#endif } else if (n_user == 1 && so == SelectedOutput_map.end()) { From 314db2a5536171667eea98851b41acb4489ede23 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 1 Oct 2013 05:34:06 +0000 Subject: [PATCH 0755/1077] rearranged vars and added code to track changes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8093 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.cpp | 95 +++++++++++++-------- SelectedOutput.h | 202 +++++++++++++++++++++++++++++++++------------ 2 files changed, 208 insertions(+), 89 deletions(-) diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 005694f4..3c92b621 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -3,44 +3,66 @@ SelectedOutput::SelectedOutput(int n, PHRQ_io *io) : cxxNumKeyword(io) { + // file_name this->Set_file_name(n); + + // punch_ostream this->punch_ostream = NULL; - this->active = true; - this->new_def = false; + + // state vars + this->active = true; + this->new_def = false; this->user_punch_new_def = false; - //std::map totals; - //std::map molalities; - //std::map activities; - //std::map pure_phases; - //std::map si; - //std::map gases; - //std::map s_s; - //std::map kinetics; - //std::map isotopes; - //std::map calculate_values; - //std::map kinetics; - //std::map kinetics; + this->have_punch_name = false; + + // as-is vars + // + this->user_punch = true; + this->high_precision = false; this->inverse = true; + this->sim = true; this->state = true; this->soln = true; this->dist = true; this->time = true; + this->step = true; - this->rxn = false; - this->temp = false; this->ph = true; this->pe = true; + this->rxn = false; + this->temp = false; + this->alk = false; this->mu = false; this->water = false; - this->high_precision = false; - this->user_punch = true; this->charge_balance = false; this->percent_error = false; - this->have_punch_name = false; -} + // as-is set flags + // + this->set_user_punch = false; + this->set_high_precision = false; + this->set_inverse = false; + + this->set_sim = false; + this->set_state = false; + this->set_soln = false; + this->set_dist = false; + this->set_time = false; + + this->set_step = false; + this->set_ph = false; + this->set_pe = false; + this->set_rxn = false; + this->set_temp = false; + + this->set_alk = false; + this->set_mu = false; + this->set_water = false; + this->set_charge_balance = false; + this->set_percent_error = false; +} SelectedOutput::~SelectedOutput(void) { @@ -50,25 +72,30 @@ SelectedOutput::~SelectedOutput(void) } this->punch_ostream = NULL; } + void SelectedOutput::Reset(bool value) { - sim = value; - state = value; - soln = value; - dist = value; - time = value; - step = value; - ph = value; - pe = value; - rxn = value; - temp = value; - alk = value; - mu = value; - water = value; + // as-is vars + sim = value; + state = value; + soln = value; + dist = value; + time = value; + + step = value; + ph = value; + pe = value; + rxn = value; + temp = value; + + alk = value; + mu = value; + water = value; charge_balance = value; - percent_error = value; + percent_error = value; } + void SelectedOutput::Set_file_name(int n) { diff --git a/SelectedOutput.h b/SelectedOutput.h index 42d1f3ee..41053e39 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -4,13 +4,16 @@ #include #include #include "NumKeyword.h" + class SelectedOutput:public cxxNumKeyword { public: SelectedOutput(int n=1, PHRQ_io *io=NULL); ~SelectedOutput(void); + void Reset(bool tf); + // vector getters inline std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} inline std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} inline std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} @@ -22,63 +25,113 @@ public: inline std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} inline std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} - inline std::string & Get_file_name(void) {return this->file_name;} - inline bool Get_new_def(void) {return this->new_def;} - inline bool Get_sim(void) {return this->sim;} - inline bool Get_state(void) {return this->state;} - inline bool Get_soln(void) {return this->soln;} - inline bool Get_dist(void) {return this->dist;} - inline bool Get_time(void) {return this->time;} - inline bool Get_step(void) {return this->step;} - inline bool Get_rxn(void) {return this->rxn;} - inline bool Get_temp(void) {return this->temp;} - inline bool Get_ph(void) {return this->ph;} - inline bool Get_pe(void) {return this->pe;} - inline bool Get_alk(void) {return this->alk;} - inline bool Get_mu(void) {return this->mu;} - inline bool Get_water(void) {return this->water;} - inline bool Get_high_precision(void) {return this->high_precision;} - inline bool Get_user_punch(void) {return this->user_punch;} - inline bool Get_charge_balance(void) {return this->charge_balance;} - inline bool Get_percent_error(void) {return this->percent_error;} - inline bool Get_inverse(void) {return this->inverse;} - //inline bool Get_punch(void) {return this->punch;} - inline bool Get_active(void) {return this->active;} - inline bool Get_have_punch_name(void) {return this->have_punch_name;} - inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} + // const vector getters + inline const std::vector< std::pair< std::string, void * > > & Get_totals(void)const {return this->totals;} + inline const std::vector< std::pair< std::string, void * > > & Get_molalities(void)const {return this->molalities;} + inline const std::vector< std::pair< std::string, void * > > & Get_activities(void)const {return this->activities;} + inline const std::vector< std::pair< std::string, void * > > & Get_pure_phases(void)const {return this->pure_phases;} + inline const std::vector< std::pair< std::string, void * > > & Get_si(void)const {return this->si;} + inline const std::vector< std::pair< std::string, void * > > & Get_gases(void)const {return this->gases;} + inline const std::vector< std::pair< std::string, void * > > & Get_s_s(void)const {return this->s_s;} + inline const std::vector< std::pair< std::string, void * > > & Get_kinetics(void)const {return this->kinetics;} + inline const std::vector< std::pair< std::string, void * > > & Get_isotopes(void)const {return this->isotopes;} + inline const std::vector< std::pair< std::string, void * > > & Get_calculate_values(void)const {return this->calculate_values;} + // file_name getters/setters void Set_file_name(int i); inline void Set_file_name(std::string s) {this->file_name = s;} - inline void Set_new_def(bool tf) {this->new_def = tf;} + inline std::string & Get_file_name(void) {return this->file_name;} + inline const std::string & Get_file_name(void)const {return this->file_name;} + + // punch_ostream getters/setters + inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} + inline const std::ostream* Get_punch_ostream(void)const {return this->punch_ostream;} inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} - inline void Set_sim(bool tf) {this->sim = tf;} - inline void Set_state(bool tf) {this->state = tf;} - inline void Set_soln(bool tf) {this->soln = tf;} - inline void Set_dist(bool tf) {this->dist = tf;} - inline void Set_time(bool tf) {this->time = tf;} - inline void Set_step(bool tf) {this->step = tf;} - inline void Set_rxn(bool tf) {this->rxn = tf;} - inline void Set_temp(bool tf) {this->temp = tf;} - inline void Set_ph(bool tf) {this->ph = tf;} - inline void Set_pe(bool tf) {this->pe = tf;} - inline void Set_alk(bool tf) {this->alk = tf;} - inline void Set_mu(bool tf) {this->mu = tf;} - inline void Set_water(bool tf) {this->water = tf;} - inline void Set_high_precision(bool tf) {this->high_precision = tf;} - inline void Set_user_punch(bool tf) {this->user_punch = tf;} - inline void Set_charge_balance(bool tf) {this->charge_balance = tf;} - inline void Set_percent_error(bool tf) {this->percent_error = tf;} - inline void Set_inverse(bool tf) {this->inverse = tf;} - //inline void Set_punch(bool tf) {this->punch = tf;} + + // state var getters + inline bool Get_active(void)const {return this->active;} + inline bool Get_new_def(void)const {return this->new_def;} + inline bool Get_user_punch_new_def(void)const {return this->user_punch_new_def;} + inline bool Get_have_punch_name(void)const {return this->have_punch_name;} + + // state var setters inline void Set_active(bool tf) {this->active = tf;} + inline void Set_new_def(bool tf) {this->new_def = tf;} + inline void Set_user_punch_new_def(bool tf) {this->user_punch_new_def = tf;} inline void Set_have_punch_name(bool tf) {this->have_punch_name = tf;} + // as_is getters + inline bool Get_user_punch(void)const {return this->user_punch;} + inline bool Get_high_precision(void)const {return this->high_precision;} + inline bool Get_inverse(void)const {return this->inverse;} + + inline bool Get_sim(void)const {return this->sim;} + inline bool Get_state(void)const {return this->state;} + inline bool Get_soln(void)const {return this->soln;} + inline bool Get_dist(void)const {return this->dist;} + inline bool Get_time(void)const {return this->time;} + + inline bool Get_step(void)const {return this->step;} + inline bool Get_ph(void)const {return this->ph;} + inline bool Get_pe(void)const {return this->pe;} + inline bool Get_rxn(void)const {return this->rxn;} + inline bool Get_temp(void)const {return this->temp;} + + inline bool Get_alk(void)const {return this->alk;} + inline bool Get_mu(void)const {return this->mu;} + inline bool Get_water(void)const {return this->water;} + inline bool Get_charge_balance(void)const {return this->charge_balance;} + inline bool Get_percent_error(void)const {return this->percent_error;} + + // as-is setters + inline void Set_user_punch(bool tf) {this->user_punch = tf; this->set_user_punch = true;} + inline void Set_high_precision(bool tf) {this->high_precision = tf; this->set_high_precision = true;} + inline void Set_inverse(bool tf) {this->inverse = tf; this->set_inverse = true;} + + inline void Set_sim(bool tf) {this->sim = tf; this->set_sim = true;} + inline void Set_state(bool tf) {this->state = tf; this->set_state = true;} + inline void Set_soln(bool tf) {this->soln = tf; this->set_soln = true;} + inline void Set_dist(bool tf) {this->dist = tf; this->set_dist = true;} + inline void Set_time(bool tf) {this->time = tf; this->set_time = true;} + + inline void Set_step(bool tf) {this->step = tf; this->set_step = true;} + inline void Set_ph(bool tf) {this->ph = tf; this->set_ph = true;} + inline void Set_pe(bool tf) {this->pe = tf; this->set_pe = true;} + inline void Set_rxn(bool tf) {this->rxn = tf; this->set_rxn = true;} + inline void Set_temp(bool tf) {this->temp = tf; this->set_temp = true;} + + inline void Set_alk(bool tf) {this->alk = tf; this->set_alk = true;} + inline void Set_mu(bool tf) {this->mu = tf; this->set_mu = true;} + inline void Set_water(bool tf) {this->water = tf; this->set_water = true;} + inline void Set_charge_balance(bool tf) {this->charge_balance = tf; this->set_charge_balance = true;} + inline void Set_percent_error(bool tf) {this->percent_error = tf; this->set_percent_error = true;} + + // set flag getters + inline bool was_set_user_punch()const {return this->set_user_punch;} + inline bool was_set_high_precision()const {return this->set_high_precision;} + inline bool was_set_inverse()const {return this->set_inverse;} + + inline bool was_set_sim()const {return this->set_sim;} + inline bool was_set_state()const {return this->set_state;} + inline bool was_set_soln()const {return this->set_soln;} + inline bool was_set_dist()const {return this->set_dist;} + inline bool was_set_time()const {return this->set_time;} + + inline bool was_set_step()const {return this->set_step;} + inline bool was_set_ph()const {return this->set_ph;} + inline bool was_set_pe()const {return this->set_pe;} + inline bool was_set_rxn()const {return this->set_rxn;} + inline bool was_set_temp()const {return this->set_temp;} + + inline bool was_set_alk()const {return this->set_alk;} + inline bool was_set_mu()const {return this->set_mu;} + inline bool was_set_water()const {return this->set_water;} + inline bool was_set_charge_balance()const {return this->set_charge_balance;} + inline bool was_set_percent_error()const {return this->set_percent_error;} + protected: - std::string file_name; - std::ostream * punch_ostream; - bool active; - bool new_def; - bool user_punch_new_def; + + // vectors std::vector< std::pair< std::string, void * > > totals; std::vector< std::pair< std::string, void * > > molalities; std::vector< std::pair< std::string, void * > > activities; @@ -89,24 +142,63 @@ protected: std::vector< std::pair< std::string, void * > > kinetics; std::vector< std::pair< std::string, void * > > isotopes; std::vector< std::pair< std::string, void * > > calculate_values; + + // file_name + std::string file_name; + + // punch_ostream + std::ostream * punch_ostream; + + // state vars + bool active; + bool new_def; + bool user_punch_new_def; + bool have_punch_name; + + // as-is vars + bool user_punch; + bool high_precision; + bool inverse; + bool sim; bool state; bool soln; bool dist; bool time; + bool step; - bool rxn; - bool temp; bool ph; bool pe; + bool rxn; + bool temp; + bool alk; bool mu; bool water; - bool high_precision; - bool user_punch; bool charge_balance; bool percent_error; - bool inverse; - bool have_punch_name; + + // as-is set flags + bool set_user_punch; + bool set_high_precision; + bool set_inverse; + + bool set_sim; + bool set_state; + bool set_soln; + bool set_dist; + bool set_time; + + bool set_step; + bool set_ph; + bool set_pe; + bool set_rxn; + bool set_temp; + + bool set_alk; + bool set_mu; + bool set_water; + bool set_charge_balance; + bool set_percent_error; }; #endif // !defined(SELECTEDOUTPUT_H_INCLUDED) From 257b2805cfb6f7c1a5d289bf9f0c32ddc9184157 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 25 Oct 2013 03:59:43 +0000 Subject: [PATCH 0756/1077] fixed reset now acts like setting as-is vars git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8135 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index 3c92b621..e2b5c5c6 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -77,23 +77,23 @@ void SelectedOutput::Reset(bool value) { // as-is vars - sim = value; - state = value; - soln = value; - dist = value; - time = value; + Set_sim(value); + Set_state(value); + Set_soln(value); + Set_dist(value); + Set_time(value); - step = value; - ph = value; - pe = value; - rxn = value; - temp = value; + Set_step(value); + Set_ph(value); + Set_pe(value); + Set_rxn(value); + Set_temp(value); - alk = value; - mu = value; - water = value; - charge_balance = value; - percent_error = value; + Set_alk(value); + Set_mu(value); + Set_water(value); + Set_charge_balance(value); + Set_percent_error(value); } void From 8c78708f5fc40b9e18faa391b73a0b8c713f82d4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 29 Oct 2013 22:22:19 +0000 Subject: [PATCH 0757/1077] added const versions for Get_headings and Get_rate git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8139 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- UserPunch.h | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 UserPunch.h diff --git a/UserPunch.h b/UserPunch.h deleted file mode 100644 index bc331696..00000000 --- a/UserPunch.h +++ /dev/null @@ -1,25 +0,0 @@ -#if !defined(USERPUNCH_H_INCLUDED) -#define USERPUNCH_H_INCLUDED -#include -#include // std::string -#include "NumKeyword.h" -class Phreeqc; -class UserPunch:public cxxNumKeyword -{ -public: - UserPunch(int n=1, PHRQ_io *io=NULL); - ~UserPunch(void); - - std::vector &Get_headings() {return this->headings;} - void Set_headings(std::vector & h) {this->headings = h;} - Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} - void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} - struct rate * Get_rate() {return this->rate;} - void Set_rate(struct rate * r) {this->rate = r;} - -protected: - std::vector headings; - struct rate * rate; - Phreeqc * PhreeqcPtr; -}; -#endif // !defined(USERPUNCH_H_INCLUDED) \ No newline at end of file From fda47b4bad9f82757d95e9c0eedca7cab4f727b7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 30 Oct 2013 05:29:11 +0000 Subject: [PATCH 0758/1077] recovering tortoisesvn deletion of UserPunch.h (i think it's a problem with externals (was working on iphreeqc)) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8142 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- UserPunch.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 UserPunch.h diff --git a/UserPunch.h b/UserPunch.h new file mode 100644 index 00000000..bc331696 --- /dev/null +++ b/UserPunch.h @@ -0,0 +1,25 @@ +#if !defined(USERPUNCH_H_INCLUDED) +#define USERPUNCH_H_INCLUDED +#include +#include // std::string +#include "NumKeyword.h" +class Phreeqc; +class UserPunch:public cxxNumKeyword +{ +public: + UserPunch(int n=1, PHRQ_io *io=NULL); + ~UserPunch(void); + + std::vector &Get_headings() {return this->headings;} + void Set_headings(std::vector & h) {this->headings = h;} + Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} + void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} + struct rate * Get_rate() {return this->rate;} + void Set_rate(struct rate * r) {this->rate = r;} + +protected: + std::vector headings; + struct rate * rate; + Phreeqc * PhreeqcPtr; +}; +#endif // !defined(USERPUNCH_H_INCLUDED) \ No newline at end of file From be614498d45c58a3c0d05eb2e693c67cbef4667c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 30 Oct 2013 05:32:42 +0000 Subject: [PATCH 0759/1077] added const routines git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8143 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- UserPunch.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/UserPunch.h b/UserPunch.h index bc331696..994568f0 100644 --- a/UserPunch.h +++ b/UserPunch.h @@ -10,11 +10,25 @@ public: UserPunch(int n=1, PHRQ_io *io=NULL); ~UserPunch(void); + // headings + // std::vector &Get_headings() {return this->headings;} + const std::vector &Get_headings()const {return this->headings;} + void Set_headings(std::vector & h) {this->headings = h;} + + // phreeqc pointer + // Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} + const Phreeqc * Get_PhreeqcPtr()const {return this->PhreeqcPtr;} + void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} + + // rate + // struct rate * Get_rate() {return this->rate;} + const struct rate * Get_rate()const {return this->rate;} + void Set_rate(struct rate * r) {this->rate = r;} protected: From 634211a2bec32d7c972f58db0574e22ea9b26809 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Nov 2013 00:05:13 +0000 Subject: [PATCH 0760/1077] added SelectedOutput and UserPunch to automake git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8166 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile.am b/Makefile.am index 8785171b..08ed9d98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -52,6 +52,8 @@ phreeqc_SOURCES=\ ReadClass.cxx\ runner.cpp\ runner.h\ + SelectedOutput.cpp\ + SelectedOutput.h\ Solution.cxx\ Solution.h\ SolutionIsotope.cxx\ @@ -78,6 +80,8 @@ phreeqc_SOURCES=\ Temperature.h\ Use.cpp\ Use.h\ + UserPunch.cpp\ + UserPunch.h\ Utils.cxx\ Utils.h\ advection.cpp\ From c80ebbc6300de3e36dcdb668637ae6f2f5d917b0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Nov 2013 16:26:46 +0000 Subject: [PATCH 0761/1077] added soln_vol to cxxSolution. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8171 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 26 +++++++++++++++++++++++++- Solution.h | 3 +++ basicsubs.cpp | 4 ---- mainsubs.cpp | 1 + 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 2218a706..46b06b5e 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -39,6 +39,7 @@ cxxSolution::cxxSolution(PHRQ_io * io) this->cb = 0.0; this->density = 1.0; this->mass_water = 1.0; + this->soln_vol = 1.0; this->total_alkalinity = 0.0; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; @@ -71,6 +72,7 @@ cxxSolution::operator =(const cxxSolution &rhs) this->density = rhs.density; this->cb = rhs.cb; this->mass_water = rhs.mass_water; + this->soln_vol = rhs.soln_vol; this->total_alkalinity = rhs.total_alkalinity; this->totals = rhs.totals; this->master_activity = rhs.master_activity; @@ -175,6 +177,9 @@ cxxSolution::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "soln_mass_water=\"" << this->mass_water << "\"" << "\n"; + s_oss << indent1; + s_oss << "soln_vol=\"" << this->soln_vol << "\"" << "\n"; + s_oss << indent1; s_oss << "soln_total_alkalinity=\"" << this-> total_alkalinity << "\"" << "\n"; @@ -271,6 +276,10 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1; s_oss << "-mass_water " << this->mass_water << "\n"; + // new identifier + s_oss << indent1; + s_oss << "-soln_vol " << this->soln_vol << "\n"; + // new identifier s_oss << indent1; s_oss << "-total_alkalinity " << this->total_alkalinity << "\n"; @@ -896,6 +905,17 @@ cxxSolution::read_raw(CParser & parser, bool check) } opt_save = CParser::OPT_DEFAULT; break; + + case 23: // soln_vol + if (!(parser.get_iss() >> this->soln_vol)) + { + this->soln_vol = 1.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for solution volume.", + PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -1221,6 +1241,7 @@ cxxSolution::zero() this->cb = 0.0; this->density = 1.0; this->mass_water = 0.0; + this->soln_vol = 1.0; this->total_alkalinity = 0.0; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; @@ -1251,6 +1272,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->cb += addee.cb * extensive; this->density = f1 * this->density + f2 * addee.density; this->mass_water += addee.mass_water * extensive; + this->soln_vol += addee.soln_vol * extensive; this->total_alkalinity += addee.total_alkalinity * extensive; this->totals.add_extensive(addee.totals, extensive); this->master_activity.add_log_activities(addee.master_activity, f1, f2); @@ -1270,6 +1292,7 @@ cxxSolution::multiply(LDBLE extensive) this->total_o *= extensive; this->cb *= extensive; this->mass_water *= extensive; + this->soln_vol *= extensive; this->total_alkalinity *= extensive; this->totals.multiply(extensive); this->Multiply_isotopes(extensive); @@ -1404,6 +1427,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("cb"), // 19 std::vector< std::string >::value_type("charge_balance"), // 20 std::vector< std::string >::value_type("density"), // 21 - std::vector< std::string >::value_type("pressure") // 22 + std::vector< std::string >::value_type("pressure"), // 22 + std::vector< std::string >::value_type("soln_vol") // 23 }; 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/Solution.h b/Solution.h index de8812fa..3ec9924c 100644 --- a/Solution.h +++ b/Solution.h @@ -51,6 +51,8 @@ class cxxSolution:public cxxNumKeyword void Set_mass_water(LDBLE l_mass_water) {this->mass_water = l_mass_water;} LDBLE Get_total_alkalinity() const {return this->total_alkalinity;} void Set_total_alkalinity(LDBLE l_total_alkalinity) {this->total_alkalinity = l_total_alkalinity;} + LDBLE Get_soln_vol() const {return this->soln_vol;} + void Set_soln_vol(LDBLE t) {this->soln_vol = t;} cxxNameDouble & Get_totals(void) {return this->totals;} const cxxNameDouble & Get_totals(void)const {return this->totals;} void Set_totals(cxxNameDouble & nd) @@ -119,6 +121,7 @@ class cxxSolution:public cxxNumKeyword LDBLE cb; LDBLE mass_water; LDBLE density; + LDBLE soln_vol; LDBLE total_alkalinity; cxxNameDouble totals; cxxNameDouble master_activity; diff --git a/basicsubs.cpp b/basicsubs.cpp index 1f0b5aa9..b0b7938a 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -291,16 +291,12 @@ calc_solution_volume(void) if (master_ptr->primary == TRUE) { total_mass += master_ptr->total_primary * master_ptr->gfw; - //if (master_ptr->total_primary > 0) - // std::cerr << master_ptr->elt->name << " " << master_ptr->total_primary << "\n"; } } LDBLE rho = calc_dens(); LDBLE vol = 1e-3 * total_mass / rho; return (vol); - } -/* DP: End function for interval halving */ /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: diff --git a/mainsubs.cpp b/mainsubs.cpp index 65dae176..171e3046 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1457,6 +1457,7 @@ xsolution_save(int n_user) /* does include surface charge after step */ temp_solution.Set_mass_water(mass_water_aq_x); temp_solution.Set_total_alkalinity(total_alkalinity); + temp_solution.Set_soln_vol(this->calc_solution_volume()); /* * Copy pe data */ From ab5384de2af4533dc275c0844be3fd654c795fe1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 18 Nov 2013 20:58:12 +0000 Subject: [PATCH 0762/1077] Tony's vm revisions, phreeqc.dat gfw for N redox states git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8204 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 79 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 78f33ce8..d8538f05 100644 --- a/Makefile +++ b/Makefile @@ -58,13 +58,14 @@ am__phreeqc_SOURCES_DIST = class_main.cpp cxxKinetics.cxx \ PHRQ_io.cpp PHRQ_io.h PPassemblage.cxx PPassemblage.h \ PPassemblageComp.cxx PPassemblageComp.h Pressure.cxx \ Pressure.h Reaction.cxx Reaction.h ReadClass.cxx runner.cpp \ - runner.h Solution.cxx Solution.h SolutionIsotope.cxx \ - SolutionIsotope.h SSassemblage.cxx SSassemblage.h SS.cxx SS.h \ - SScomp.cxx SScomp.h StorageBin.cxx StorageBin.h \ - StorageBinList.cpp StorageBinList.h Surface.cxx Surface.h \ - SurfaceCharge.cxx SurfaceCharge.h SurfaceComp.cxx \ - SurfaceComp.h System.cxx System.h Temperature.cxx \ - Temperature.h Use.cpp Use.h Utils.cxx Utils.h advection.cpp \ + runner.h SelectedOutput.cpp SelectedOutput.h Solution.cxx \ + Solution.h SolutionIsotope.cxx SolutionIsotope.h \ + SSassemblage.cxx SSassemblage.h SS.cxx SS.h SScomp.cxx \ + SScomp.h StorageBin.cxx StorageBin.h StorageBinList.cpp \ + StorageBinList.h Surface.cxx Surface.h SurfaceCharge.cxx \ + SurfaceCharge.h SurfaceComp.cxx SurfaceComp.h System.cxx \ + System.h Temperature.cxx Temperature.h Use.cpp Use.h \ + UserPunch.cpp UserPunch.h Utils.cxx Utils.h advection.cpp \ basicsubs.cpp cl1.cpp cvdense.cpp cvdense.h cvode.cpp cvode.h \ dense.cpp dense.h dw.cpp gases.cpp global_structures.h \ input.cpp integrate.cpp inverse.cpp isotopes.cpp kinetics.cpp \ @@ -85,20 +86,21 @@ am_phreeqc_OBJECTS = class_main.$(OBJEXT) cxxKinetics.$(OBJEXT) \ Phreeqc.$(OBJEXT) PHRQ_base.$(OBJEXT) PHRQ_io.$(OBJEXT) \ PPassemblage.$(OBJEXT) PPassemblageComp.$(OBJEXT) \ Pressure.$(OBJEXT) Reaction.$(OBJEXT) ReadClass.$(OBJEXT) \ - runner.$(OBJEXT) Solution.$(OBJEXT) SolutionIsotope.$(OBJEXT) \ - SSassemblage.$(OBJEXT) SS.$(OBJEXT) SScomp.$(OBJEXT) \ - StorageBin.$(OBJEXT) StorageBinList.$(OBJEXT) \ + runner.$(OBJEXT) SelectedOutput.$(OBJEXT) Solution.$(OBJEXT) \ + SolutionIsotope.$(OBJEXT) SSassemblage.$(OBJEXT) SS.$(OBJEXT) \ + SScomp.$(OBJEXT) StorageBin.$(OBJEXT) StorageBinList.$(OBJEXT) \ Surface.$(OBJEXT) SurfaceCharge.$(OBJEXT) \ SurfaceComp.$(OBJEXT) System.$(OBJEXT) Temperature.$(OBJEXT) \ - Use.$(OBJEXT) Utils.$(OBJEXT) advection.$(OBJEXT) \ - basicsubs.$(OBJEXT) cl1.$(OBJEXT) cvdense.$(OBJEXT) \ - cvode.$(OBJEXT) dense.$(OBJEXT) dw.$(OBJEXT) gases.$(OBJEXT) \ - input.$(OBJEXT) integrate.$(OBJEXT) inverse.$(OBJEXT) \ - isotopes.$(OBJEXT) kinetics.$(OBJEXT) mainsubs.$(OBJEXT) \ - model.$(OBJEXT) nvector.$(OBJEXT) nvector_serial.$(OBJEXT) \ - parse.$(OBJEXT) phqalloc.$(OBJEXT) PHRQ_io_output.$(OBJEXT) \ - pitzer.$(OBJEXT) pitzer_structures.$(OBJEXT) prep.$(OBJEXT) \ - print.$(OBJEXT) read.$(OBJEXT) readtr.$(OBJEXT) sit.$(OBJEXT) \ + Use.$(OBJEXT) UserPunch.$(OBJEXT) Utils.$(OBJEXT) \ + advection.$(OBJEXT) basicsubs.$(OBJEXT) cl1.$(OBJEXT) \ + cvdense.$(OBJEXT) cvode.$(OBJEXT) dense.$(OBJEXT) dw.$(OBJEXT) \ + gases.$(OBJEXT) input.$(OBJEXT) integrate.$(OBJEXT) \ + inverse.$(OBJEXT) isotopes.$(OBJEXT) kinetics.$(OBJEXT) \ + mainsubs.$(OBJEXT) model.$(OBJEXT) nvector.$(OBJEXT) \ + nvector_serial.$(OBJEXT) parse.$(OBJEXT) phqalloc.$(OBJEXT) \ + PHRQ_io_output.$(OBJEXT) pitzer.$(OBJEXT) \ + pitzer_structures.$(OBJEXT) prep.$(OBJEXT) print.$(OBJEXT) \ + read.$(OBJEXT) readtr.$(OBJEXT) sit.$(OBJEXT) \ smalldense.$(OBJEXT) spread.$(OBJEXT) step.$(OBJEXT) \ structures.$(OBJEXT) sundialsmath.$(OBJEXT) tally.$(OBJEXT) \ tidy.$(OBJEXT) transport.$(OBJEXT) utilities.$(OBJEXT) \ @@ -125,11 +127,11 @@ DIST_SOURCES = $(am__phreeqc_SOURCES_DIST) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run aclocal-1.11 -AMTAR = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run tar -AUTOCONF = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run autoconf -AUTOHEADER = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run autoheader -AUTOMAKE = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run automake-1.11 +ACLOCAL = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run aclocal-1.11 +AMTAR = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run tar +AUTOCONF = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run autoconf +AUTOHEADER = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run autoheader +AUTOMAKE = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run automake-1.11 AWK = gawk CPPFLAGS = CXX = g++ @@ -155,7 +157,7 @@ LIBGMP = -lgmp LIBOBJS = LIBS = LTLIBOBJS = -MAKEINFO = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/missing --run makeinfo +MAKEINFO = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run makeinfo MKDIR_P = /bin/mkdir -p OBJEXT = o PACKAGE = phreeqc @@ -170,10 +172,10 @@ SET_MAKE = SHELL = /bin/sh STRIP = VERSION = 3.0.0-7109 -abs_builddir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/src -abs_srcdir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/src -abs_top_builddir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk -abs_top_srcdir = /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk +abs_builddir = /lobo02home/dlpark/programs/phreeqc3-trunk/src +abs_srcdir = /lobo02home/dlpark/programs/phreeqc3-trunk/src +abs_top_builddir = /lobo02home/dlpark/programs/phreeqc3-trunk +abs_top_srcdir = /lobo02home/dlpark/programs/phreeqc3-trunk ac_ct_CXX = g++ am__include = include am__leading_dot = . @@ -192,7 +194,7 @@ host_alias = htmldir = ${docdir} includedir = ${prefix}/include infodir = ${datarootdir}/info -install_sh = ${SHELL} /lobo02home/dlpark/charlton/programs/phreeqc/phreeqc3-trunk/config/install-sh +install_sh = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/install-sh libdir = ${exec_prefix}/lib libexecdir = ${exec_prefix}/libexec localedir = ${datarootdir}/locale @@ -226,13 +228,14 @@ phreeqc_SOURCES = class_main.cpp cxxKinetics.cxx cxxKinetics.h \ PHRQ_io.cpp PHRQ_io.h PPassemblage.cxx PPassemblage.h \ PPassemblageComp.cxx PPassemblageComp.h Pressure.cxx \ Pressure.h Reaction.cxx Reaction.h ReadClass.cxx runner.cpp \ - runner.h Solution.cxx Solution.h SolutionIsotope.cxx \ - SolutionIsotope.h SSassemblage.cxx SSassemblage.h SS.cxx SS.h \ - SScomp.cxx SScomp.h StorageBin.cxx StorageBin.h \ - StorageBinList.cpp StorageBinList.h Surface.cxx Surface.h \ - SurfaceCharge.cxx SurfaceCharge.h SurfaceComp.cxx \ - SurfaceComp.h System.cxx System.h Temperature.cxx \ - Temperature.h Use.cpp Use.h Utils.cxx Utils.h advection.cpp \ + runner.h SelectedOutput.cpp SelectedOutput.h Solution.cxx \ + Solution.h SolutionIsotope.cxx SolutionIsotope.h \ + SSassemblage.cxx SSassemblage.h SS.cxx SS.h SScomp.cxx \ + SScomp.h StorageBin.cxx StorageBin.h StorageBinList.cpp \ + StorageBinList.h Surface.cxx Surface.h SurfaceCharge.cxx \ + SurfaceCharge.h SurfaceComp.cxx SurfaceComp.h System.cxx \ + System.h Temperature.cxx Temperature.h Use.cpp Use.h \ + UserPunch.cpp UserPunch.h Utils.cxx Utils.h advection.cpp \ basicsubs.cpp cl1.cpp cvdense.cpp cvdense.h cvode.cpp cvode.h \ dense.cpp dense.h dw.cpp gases.cpp global_structures.h \ input.cpp integrate.cpp inverse.cpp isotopes.cpp kinetics.cpp \ @@ -349,6 +352,7 @@ include ./$(DEPDIR)/ReadClass.Po include ./$(DEPDIR)/SS.Po include ./$(DEPDIR)/SSassemblage.Po include ./$(DEPDIR)/SScomp.Po +include ./$(DEPDIR)/SelectedOutput.Po include ./$(DEPDIR)/Solution.Po include ./$(DEPDIR)/SolutionIsotope.Po include ./$(DEPDIR)/StorageBin.Po @@ -359,6 +363,7 @@ include ./$(DEPDIR)/SurfaceComp.Po include ./$(DEPDIR)/System.Po include ./$(DEPDIR)/Temperature.Po include ./$(DEPDIR)/Use.Po +include ./$(DEPDIR)/UserPunch.Po include ./$(DEPDIR)/Utils.Po include ./$(DEPDIR)/advection.Po include ./$(DEPDIR)/basicsubs.Po From 70482839c5e08aa7d9e62c82fac27d787e8dd86b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Dec 2013 23:49:22 +0000 Subject: [PATCH 0763/1077] Added GetMpiTasks Restart may be working. Need to clean up RMHelper and WriteFiles. Need to add dump facility. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8278 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/StorageBin.cxx b/StorageBin.cxx index 39d43786..73affc34 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -725,6 +725,17 @@ cxxStorageBin::read_raw(CParser & parser) } break; default: + { + for (;;) + { + PHRQ_io::LINE_TYPE lt; + lt = parser.check_line("read_raw", false, true, true, false); + if (lt == PHRQ_io::LT_KEYWORD) + break; + if (lt != PHRQ_io::LT_EOF) + goto END_OF_SIMULATION_INPUT; + } + } break; } } From a191ef4b4250e3191afa19ec3af52a99c3acf964 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Dec 2013 22:22:58 +0000 Subject: [PATCH 0764/1077] Still working on selected output. Moved DumpModule Fixed logic in InitialPhreeqc2Concentrations Fixed logic in cxxStorageBin::read_raw git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8283 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StorageBin.cxx b/StorageBin.cxx index 73affc34..44e36a4c 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -732,7 +732,7 @@ cxxStorageBin::read_raw(CParser & parser) lt = parser.check_line("read_raw", false, true, true, false); if (lt == PHRQ_io::LT_KEYWORD) break; - if (lt != PHRQ_io::LT_EOF) + if (lt == PHRQ_io::LT_EOF) goto END_OF_SIMULATION_INPUT; } } From 11de08945d1a3ea3b4c004ac84e39f29507ecf86 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 5 Dec 2013 23:57:46 +0000 Subject: [PATCH 0765/1077] removed unnecessary erase to fix bug in IPhreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8284 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/read.cpp b/read.cpp index 645a57c7..0da7b686 100644 --- a/read.cpp +++ b/read.cpp @@ -5034,12 +5034,6 @@ read_selected_output(void) if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) { - // delete if exists - if (so != SelectedOutput_map.end()) - { - SelectedOutput_map.erase(so); - } - // store new selected output SelectedOutput_map[n_user] = temp_selected_output; From a3110d47c36d0535ac1d91fd7351425a98ac1cfd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 6 Dec 2013 20:59:49 +0000 Subject: [PATCH 0766/1077] Should zero soln_vol And missed calculation of patm (pressure). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8293 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index 46b06b5e..81a7aed7 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1241,7 +1241,7 @@ cxxSolution::zero() this->cb = 0.0; this->density = 1.0; this->mass_water = 0.0; - this->soln_vol = 1.0; + this->soln_vol = 0.0; this->total_alkalinity = 0.0; this->totals.type = cxxNameDouble::ND_ELT_MOLES; this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; @@ -1271,6 +1271,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->total_o += addee.total_o * extensive; this->cb += addee.cb * extensive; this->density = f1 * this->density + f2 * addee.density; + this->patm = f1 * this->patm + f2 * addee.patm; this->mass_water += addee.mass_water * extensive; this->soln_vol += addee.soln_vol * extensive; this->total_alkalinity += addee.total_alkalinity * extensive; From 23deef141872d8768f6b9399be173273e4810bbd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Dec 2013 21:21:27 +0000 Subject: [PATCH 0767/1077] Revised GetDensity to retrieve from workers. Also, density was not saved correctly with the solution (mainsubs.cpp updated). InitialPhreeqc2Module had an id argument which was not needed. Wrote a test case advection_example.cpp, which is roughed into the code for now. Needs to be a standalone program linked to the reaction_module library. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8301 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- mainsubs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index 171e3046..e8df945a 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1450,7 +1450,8 @@ xsolution_save(int n_user) temp_solution.Set_pe(solution_pe_x); temp_solution.Set_mu(mu_x); temp_solution.Set_ah2o(ah2o_x); - temp_solution.Set_density(density_x); + //temp_solution.Set_density(density_x); + temp_solution.Set_density(calc_dens()); temp_solution.Set_total_h(total_h_x); temp_solution.Set_total_o(total_o_x); temp_solution.Set_cb(cb_x); /* cb_x does not include surface charge sfter sum_species */ From 57014d0f5ce9a9ec75e42736ebd38870f75875de Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Dec 2013 18:16:37 +0000 Subject: [PATCH 0768/1077] Renamed Reaction_module to PhreeqcRM git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8309 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index aec1372d..4ea61765 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1920,7 +1920,7 @@ protected: friend class TestSelectedOutput; friend class IPhreeqcMMS; friend class IPhreeqcPhast; - friend class Reaction_module; + friend class PhreeqcRM; std::vector keycount; // used to mark keywords that have been read From 7c40b44eff3144e5a7828fb5583f7d0d7a1378e7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Dec 2013 22:51:14 +0000 Subject: [PATCH 0769/1077] removed all refs to MERGE_FILE, MPICH_NAME, GZIP_RESTART, and HDF5_CREATE ifdefs (except HDF5.props). Ifdef'd gzstream.h. removed advection_example, it is now a separate project in PhreeqcRM Just comments in PHRQ_io_output.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8315 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 1c5b61fd..dd7db7b7 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -59,11 +59,6 @@ get_forward_output_to_log(void) return forward_output_to_log; } -//#if defined(HDF5_CREATE) -//extern void HDFWriteHyperSlabV(const char *name, const char *format, -// va_list argptr); -//#endif - void Phreeqc:: fpunchf_heading(const char *name) { From 4ec2784a6b5353304acabab01b43d8bb668e9923 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 7 Jan 2014 16:11:24 +0000 Subject: [PATCH 0770/1077] Tony's fix to solution volume. Added test case, updated Makefile Added comment to Release.txt git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8356 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 4 ++-- print.cpp | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index b0b7938a..a96c832a 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -288,9 +288,9 @@ calc_solution_volume(void) { if (master[i]->s->type != AQ) continue; struct master *master_ptr = master[i]; - if (master_ptr->primary == TRUE) + if (master_ptr->primary == TRUE && strcmp(master_ptr->elt->name, "Alkalinity")) { - total_mass += master_ptr->total_primary * master_ptr->gfw; + total_mass += master_ptr->total_primary * master_ptr->elt->gfw; } } LDBLE rho = calc_dens(); diff --git a/print.cpp b/print.cpp index 6deca68c..8301e1fa 100644 --- a/print.cpp +++ b/print.cpp @@ -1464,7 +1464,7 @@ print_species(void) output_msg(sformatf("%50s%10s%10s%10s\n", "Log", "Log", "Log", "mole V")); } output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n\n", "Species", - "Molality", "Activity", "Molality", "Activity", "Gamma", "cm3/mol")); + "Molality", "Activity", "Molality", "Activity", "Gamma", "cm³/mol")); /* * Print list of species */ @@ -1620,14 +1620,14 @@ print_surface(void) if ((charge_ptr->Get_specific_area() * charge_ptr->Get_grams()) > 0) { - output_msg(sformatf("\t%11.3e sigma, C/m**2\n", + output_msg(sformatf("\t%11.3e sigma, C/m²\n", (double) (charge * F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams())))); } else { - output_msg(sformatf("\tundefined sigma, C/m**2\n")); + output_msg(sformatf("\tundefined sigma, C/m²\n")); } output_msg(sformatf("\t%11.3e psi, V\n", (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * @@ -1640,11 +1640,11 @@ print_surface(void) if (comp_ptr->Get_phase_name().size() > 0) { output_msg(sformatf( - "\t%11.3e specific area, m**2/mol %s\n", + "\t%11.3e specific area, m²/mol %s\n", (double) charge_ptr->Get_specific_area(), comp_ptr->Get_phase_name().c_str())); output_msg(sformatf( - "\t%11.3e m**2 for %11.3e moles of %s\n\n", + "\t%11.3e m² for %11.3e moles of %s\n\n", (double) (charge_ptr->Get_grams() * charge_ptr->Get_specific_area()), (double) charge_ptr->Get_grams(), @@ -1653,11 +1653,11 @@ print_surface(void) else if (comp_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( - "\t%11.3e specific area, m**2/mol %s\n", + "\t%11.3e specific area, m²/mol %s\n", (double) charge_ptr->Get_specific_area(), comp_ptr->Get_rate_name().c_str())); output_msg(sformatf( - "\t%11.3e m**2 for %11.3e moles of %s\n\n", + "\t%11.3e m² for %11.3e moles of %s\n\n", (double) (charge_ptr->Get_grams() * charge_ptr->Get_specific_area()), (double) charge_ptr->Get_grams(), @@ -1666,9 +1666,9 @@ print_surface(void) else { output_msg(sformatf( - "\t%11.3e specific area, m**2/g\n", + "\t%11.3e specific area, m²/g\n", (double) charge_ptr->Get_specific_area())); - output_msg(sformatf("\t%11.3e m**2 for %11.3e g\n\n", + output_msg(sformatf("\t%11.3e m² for %11.3e g\n\n", (double) (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()), (double) charge_ptr->Get_grams())); @@ -1880,21 +1880,21 @@ print_surface_cd_music(void) charge_ptr->Get_grams()) > 0) { output_msg(sformatf( - "\t%11.3e sigma, plane 0, C/m**2\n", + "\t%11.3e sigma, plane 0, C/m²\n", (double) charge_ptr->Get_sigma0())); output_msg(sformatf( - "\t%11.3e sigma, plane 1, C/m**2\n", + "\t%11.3e sigma, plane 1, C/m²\n", (double) charge_ptr->Get_sigma1())); output_msg(sformatf( - "\t%11.3e sigma, plane 2, C/m**2\n", + "\t%11.3e sigma, plane 2, C/m²\n", (double) charge_ptr->Get_sigma2())); output_msg(sformatf( - "\t%11.3e sigma, diffuse layer, C/m**2\n\n", + "\t%11.3e sigma, diffuse layer, C/m²\n\n", (double) charge_ptr->Get_sigmaddl())); } else { - output_msg(sformatf("\tundefined sigma, C/m**2\n")); + output_msg(sformatf("\tundefined sigma, C/m²\n")); } output_msg(sformatf("\t%11.3e psi, plane 0, V\n", (double) (-master_ptr0->s->la * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ))); @@ -2147,13 +2147,13 @@ print_totals(void) if (EC > 0) { output_msg(sformatf("%36s%i%7s%i\n", - "Specific Conductance (uS/cm, ", (int) tc_x, " oC) = ", (int) EC)); + "Specific Conductance (µS/cm, ", (int) tc_x, "°C) = ", (int) EC)); } /* VP: Density Start */ if (print_density) { dens = calc_dens(); - output_msg(sformatf("%45s%9.5f", "Density (g/cm3) = ", + output_msg(sformatf("%45s%9.5f", "Density (g/cm³) = ", (double) dens)); if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program limit)")); else output_msg(sformatf("\n")); @@ -2181,7 +2181,7 @@ print_totals(void) } output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", (double) (total_co2 / mass_water_aq_x))); - output_msg(sformatf("%45s%6.2f\n", "Temperature (deg C) = ", + output_msg(sformatf("%45s%6.2f\n", "Temperature (°C) = ", (double) tc_x)); if (patm_x != 1.0) From e9b05399a59361f25afb082b1d7e1969c74843b4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 13 Jan 2014 23:09:50 +0000 Subject: [PATCH 0771/1077] Clean up initial_data git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8369 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Solution.h b/Solution.h index 3ec9924c..f20d8d74 100644 --- a/Solution.h +++ b/Solution.h @@ -75,12 +75,14 @@ class cxxSolution:public cxxNumKeyword } void Create_initial_data() { - delete initial_data; + if (this->initial_data != NULL) + delete initial_data; initial_data = new cxxISolution; } void Destroy_initial_data() { - delete initial_data; + if (this->initial_data != NULL) + delete initial_data; initial_data = NULL; } From 9048a9be860868f7370561885d56273c45ce94ab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 Jan 2014 20:42:12 +0000 Subject: [PATCH 0772/1077] Bugs fixes noted by Marco De-Vroed git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8371 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolutionComp.cxx | 4 +++ Phreeqc.cpp | 4 +-- Phreeqc.h | 2 +- basicsubs.cpp | 3 ++ global_structures.h | 1 + isotopes.cpp | 27 +++++++++------- kinetics.cpp | 1 + mainsubs.cpp | 31 ++++++++++++++++++ model.cpp | 11 +++++-- prep.cpp | 77 +++++++++++++++++++++++++++++++++++++++------ 10 files changed, 135 insertions(+), 26 deletions(-) diff --git a/ISolutionComp.cxx b/ISolutionComp.cxx index 356bd4e0..7e0ca016 100644 --- a/ISolutionComp.cxx +++ b/ISolutionComp.cxx @@ -356,6 +356,10 @@ read(const char *line_in, cxxSolution *solution_ptr) * Check for units info */ CParser parser(this->io); + if (solution_ptr->Get_initial_data() == NULL) + { + error_msg("Initial_data instance not defined in cxxISolutionComp::read", 1); + } if (parser.check_units(token1, alk, false, solution_ptr->Get_initial_data()->Get_units().c_str(), false) == CParser::PARSER_OK) { if (parser.check_units(token1, alk, false, solution_ptr->Get_initial_data()->Get_units().c_str(), true) == CParser::PARSER_OK) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index a610f02f..efe5bca3 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -402,7 +402,7 @@ void Phreeqc::init(void) last_patm_x = 1; numerical_fixed_volume = false; force_numerical_fixed_volume = false; - switch_numerical = false; + //switch_numerical = false; ph_x = 0; solution_pe_x = 0; mu_x = 0; @@ -1290,7 +1290,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) last_patm_x = 1; numerical_fixed_volume = false; force_numerical_fixed_volume = false; - switch_numerical = false; + //switch_numerical = false; ph_x = 0; solution_pe_x = 0; mu_x = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 4ea61765..81d972af 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1314,7 +1314,7 @@ protected: LDBLE last_patm_x; bool numerical_fixed_volume; bool force_numerical_fixed_volume; - bool switch_numerical; + //bool switch_numerical; LDBLE ph_x; LDBLE solution_pe_x; LDBLE mu_x; diff --git a/basicsubs.cpp b/basicsubs.cpp index a96c832a..3d0c10c5 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3593,6 +3593,9 @@ void Phreeqc:: basic_free(void) { delete this->basic_interpreter; + + // Reset pointer to make sure we cannot attempt to free it twice (which obviously will result in a crash) + this->basic_interpreter = 0; } double Phreeqc:: diff --git a/global_structures.h b/global_structures.h index d2157219..d36d8834 100644 --- a/global_structures.h +++ b/global_structures.h @@ -265,6 +265,7 @@ struct model int count_surface_charge; const char **surface_charge; LDBLE pressure; + bool numerical_fixed_volume; }; diff --git a/isotopes.cpp b/isotopes.cpp index f77f213a..ac8c37b2 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -564,21 +564,24 @@ calculate_isotope_moles(struct element *elt_ptr, } count_isotopes++; } - std::map::iterator it = solution_ptr->Get_initial_data()->Get_comps().begin(); - for ( ; it != solution_ptr->Get_initial_data()->Get_comps().end(); it++) + if (solution_ptr->Get_initial_data() != NULL) { - master_isotope_ptr = master_isotope_search(it->first.c_str()); - if (master_isotope_ptr == NULL) - continue; - if (master_isotope_ptr->elt != elt_ptr) - continue; - memcpy(&(list[count_isotopes]), master_isotope_ptr, - sizeof(struct master_isotope)); - if (list[count_isotopes].minor_isotope == FALSE) + std::map::iterator it = solution_ptr->Get_initial_data()->Get_comps().begin(); + for ( ; it != solution_ptr->Get_initial_data()->Get_comps().end(); it++) { - total_is_major = list[count_isotopes].total_is_major; + master_isotope_ptr = master_isotope_search(it->first.c_str()); + if (master_isotope_ptr == NULL) + continue; + if (master_isotope_ptr->elt != elt_ptr) + continue; + memcpy(&(list[count_isotopes]), master_isotope_ptr, + sizeof(struct master_isotope)); + if (list[count_isotopes].minor_isotope == FALSE) + { + total_is_major = list[count_isotopes].total_is_major; + } + count_isotopes++; } - count_isotopes++; } /* * Loop to calculate isotope molalities diff --git a/kinetics.cpp b/kinetics.cpp index 5b0d3e29..d1101307 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1512,6 +1512,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, "Numerical method failed on all combinations of convergence parameters"); error_msg(error_string, STOP); } + numerical_fixed_volume = false; if (converge == MASS_BALANCE) { return (MASS_BALANCE); diff --git a/mainsubs.cpp b/mainsubs.cpp index e8df945a..ba863069 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1563,6 +1563,37 @@ xsolution_save(int n_user) it->second.Set_total(mass_water_aq_x / gfw_water); } } +#ifdef SKIP +/* + * Bug-fix + * Create and initialize intial data (this object should always be present even if it is left empty) + */ + + temp_solution.Create_initial_data(); + cxxISolution* initialData = temp_solution.Get_initial_data(); + + initialData->Set_units( "Mol/kgw" ); + + // Copy totals to initialdata when present + if ( !temp_solution.Get_totals().empty() ) + { + cxxNameDouble& totals = temp_solution.Get_totals(); + + for (cxxNameDouble::iterator jit = totals.begin(); jit != totals.end(); jit++) + { + std::string compName( jit->first ); + double compConc = jit->second; + + SolutionCompMap& comps = initialData->Get_comps(); + + cxxISolutionComp& tempComp = comps[ compName ]; + + tempComp.Set_description( compName.c_str() ); + tempComp.Set_input_conc( compConc / temp_solution.Get_mass_water()); + tempComp.Set_units( initialData->Get_units().c_str() ); + } + } +#endif /* * Save solution */ diff --git a/model.cpp b/model.cpp index f717dde3..5ca65ac1 100644 --- a/model.cpp +++ b/model.cpp @@ -2733,11 +2733,11 @@ calc_gas_pressures(void) { //V_m *= 1; /* debug */ numerical_fixed_volume = true; - switch_numerical = true; + //switch_numerical = true; warning_msg ("Numerical method failed, switching to numerical derivatives."); prep(); - switch_numerical = false; + //switch_numerical = false; } } else V_m = 1.0; @@ -5189,12 +5189,19 @@ free_model_allocs(void) delta = (LDBLE *) free_check_null(delta); residual = (LDBLE *) free_check_null(residual); s_x = (struct species **) free_check_null(s_x); + count_s_x = 0; sum_mb1 = (struct list1 *) free_check_null(sum_mb1); + count_sum_mb1 = 0; sum_mb2 = (struct list2 *) free_check_null(sum_mb2); + count_sum_mb2 = 0; sum_jacob0 = (struct list0 *) free_check_null(sum_jacob0); + count_sum_jacob0 = 0; sum_jacob1 = (struct list1 *) free_check_null(sum_jacob1); + count_sum_jacob1 = 0; sum_jacob2 = (struct list2 *) free_check_null(sum_jacob2); + count_sum_jacob2 = 0; sum_delta = (struct list2 *) free_check_null(sum_delta); + count_sum_delta = 0; return (OK); } diff --git a/prep.cpp b/prep.cpp index 0c89258b..d6dfc559 100644 --- a/prep.cpp +++ b/prep.cpp @@ -53,9 +53,9 @@ prep(void) * X are set. */ - if (!same_model && !switch_numerical) - numerical_fixed_volume = false; - if (same_model == FALSE || switch_numerical) + //if (!same_model && !switch_numerical) + // numerical_fixed_volume = false; + if (same_model == FALSE /*|| switch_numerical*/) { clear(); setup_unknowns(); @@ -1804,6 +1804,8 @@ clear(void) else { default_pe_x = "pe"; + cxxChemRxn chem_rxn; + pe_x[default_pe_x] = chem_rxn; } /* @@ -1814,14 +1816,13 @@ clear(void) { master[i]->in = FALSE; master[i]->unknown = NULL; + master[i]->total = 0.0; if (solution_ptr->Get_initial_data()) { - //master[i]->pe_rxn = string_hsave(solution_ptr->Get_initial_data()->Get_default_pe().c_str()); master[i]->pe_rxn = solution_ptr->Get_initial_data()->Get_default_pe(); } else { - //master[i]->pe_rxn = string_hsave("pe"); master[i]->pe_rxn = pe_str; } /* @@ -1865,7 +1866,37 @@ clear(void) * Free arrays used in model */ free_model_allocs(); +#ifdef SKIP + // Bug-fix + // The standard implementation of clear() sets the unknown pointer of some of the + // masters to NULL. However, the function quick_setup presumes that a master pointer + // is valid when the masters total is larger than zero. This results in a crash + // when the unknown pointer is dereferenced. The same goes for the secondary master + // species. + // + // Perhaps this should be part of the 'Clear master species solution-dependent data'-loop above?! + for ( int i = 0; i < count_master; i++ ) + { + if (master[i]->s->type == SURF_PSI) + continue; + if ( master[i]->s == s_eminus || + master[i]->s == s_hplus || + master[i]->s == s_h2o || + master[i]->s == s_h2 || + master[i]->s == s_o2 ) + continue; + + if (master[i]->total > 0 ) + { + // Make sure masters total is set to zero when unknown pointer for master species is not set + if ( ( master[i]->s->secondary && !master[i]->s->secondary->unknown ) || !master[i]->unknown ) + { + master[i]->total = 0.0; + } + } + } +#endif return (OK); } /* ---------------------------------------------------------------------- */ @@ -1881,10 +1912,10 @@ convert_units(cxxSolution *solution_ptr) struct master *master_ptr; std::string token; if (!solution_ptr->Get_new_def() || !solution_ptr->Get_initial_data()) - { - input_error++; - error_msg("Missing data for convert_units"); - } + { + input_error++; + error_msg("Missing data for convert_units"); + } /* * Convert units */ @@ -2753,8 +2784,32 @@ write_mass_action_eqn_x(int stop) trxn.token[i].coef, FALSE); if (equal(coef_e, 0.0, TOL) == FALSE) { + assert(pe_x.find(trxn.token[i].s->secondary->pe_rxn) != pe_x.end()); cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); +#ifdef SKIP + // Bugfix + // Prevent inserting entry with empty string key in pe_x map + // This will result in "Cannot find master species for redox couple" + // in function tidy_redox which in turn will result in non-convergence e.g. in deck GCM_1D_STflash_CPA.INP. + // This differs from the 2.18 behaviour where pe_x array is never + // updated as a side effect of a lookup operation. + + std::map < std::string, cxxChemRxn >::iterator chemRxnIt = pe_x.find(trxn.token[i].s->secondary->pe_rxn); + if ( chemRxnIt == pe_x.end() ) + { + cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; + trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); + // Create temporary rxn object and add reactions together + cxxChemRxn rxn; + trxn_add(rxn, trxn.token[i].coef * coef_e, FALSE); + } + else + { + // Get reaction referred to by iterator and add reactions together + trxn_add(chemRxnIt->second, trxn.token[i].coef * coef_e, FALSE); + } +#endif } } } @@ -5833,6 +5888,8 @@ save_model(void) current_mu = NAN; mu_terms_in_logk = true; + last_model.numerical_fixed_volume = numerical_fixed_volume; + return (OK); } @@ -5886,6 +5943,8 @@ check_same_model(void) cxxGasPhase * gas_phase_ptr = use.Get_gas_phase_ptr(); if (last_model.gas_phase == NULL) return (FALSE); + if (last_model.numerical_fixed_volume != numerical_fixed_volume) + return (FALSE); if (last_model.count_gas_phase != (int) gas_phase_ptr->Get_gas_comps().size()) return (FALSE); for (i = 0; i < (int) gas_phase_ptr->Get_gas_comps().size(); i++) From 2a37e8067484b4542e4efbd60802168d90e71054 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 14 Jan 2014 22:07:42 +0000 Subject: [PATCH 0773/1077] Do not set master_bsearch[i]->total = 0.0 in clear() for now. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8372 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/prep.cpp b/prep.cpp index d6dfc559..fde00693 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1816,7 +1816,6 @@ clear(void) { master[i]->in = FALSE; master[i]->unknown = NULL; - master[i]->total = 0.0; if (solution_ptr->Get_initial_data()) { master[i]->pe_rxn = solution_ptr->Get_initial_data()->Get_default_pe(); From 6f849b215fe8d3f95f28d62b5a519c012778f73a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 Jan 2014 15:59:50 +0000 Subject: [PATCH 0774/1077] More changes for Marco. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8374 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/prep.cpp b/prep.cpp index fde00693..7e24ae2f 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1913,7 +1913,7 @@ convert_units(cxxSolution *solution_ptr) if (!solution_ptr->Get_new_def() || !solution_ptr->Get_initial_data()) { input_error++; - error_msg("Missing data for convert_units"); + error_msg("Missing data for convert_units", 1); } /* * Convert units @@ -2783,32 +2783,21 @@ write_mass_action_eqn_x(int stop) trxn.token[i].coef, FALSE); if (equal(coef_e, 0.0, TOL) == FALSE) { - assert(pe_x.find(trxn.token[i].s->secondary->pe_rxn) != pe_x.end()); - cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; - trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); -#ifdef SKIP - // Bugfix - // Prevent inserting entry with empty string key in pe_x map - // This will result in "Cannot find master species for redox couple" - // in function tidy_redox which in turn will result in non-convergence e.g. in deck GCM_1D_STflash_CPA.INP. - // This differs from the 2.18 behaviour where pe_x array is never - // updated as a side effect of a lookup operation. - - std::map < std::string, cxxChemRxn >::iterator chemRxnIt = pe_x.find(trxn.token[i].s->secondary->pe_rxn); - if ( chemRxnIt == pe_x.end() ) - { - cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; - trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); - // Create temporary rxn object and add reactions together - cxxChemRxn rxn; - trxn_add(rxn, trxn.token[i].coef * coef_e, FALSE); - } - else - { - // Get reaction referred to by iterator and add reactions together - trxn_add(chemRxnIt->second, trxn.token[i].coef * coef_e, FALSE); - } -#endif + std::map < std::string, cxxChemRxn >::iterator chemRxnIt = pe_x.find(trxn.token[i].s->secondary->pe_rxn); + if ( chemRxnIt == pe_x.end() ) + { + error_msg("pe undefined in Phreeqc::write_mass_action_eqn_x", 1); + cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; + trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); + // Create temporary rxn object and add reactions together + cxxChemRxn rxn; + trxn_add(rxn, trxn.token[i].coef * coef_e, FALSE); + } + else + { + // Get reaction referred to by iterator and add reactions together + trxn_add(chemRxnIt->second, trxn.token[i].coef * coef_e, FALSE); + } } } } From 1e48b85c86c3c5922b26193f0203ccf3585c2e8a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 Jan 2014 17:11:46 +0000 Subject: [PATCH 0775/1077] Removed error trap in write_mass_action_eqn_x git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8375 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/prep.cpp b/prep.cpp index 7e24ae2f..b973ac72 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2786,7 +2786,6 @@ write_mass_action_eqn_x(int stop) std::map < std::string, cxxChemRxn >::iterator chemRxnIt = pe_x.find(trxn.token[i].s->secondary->pe_rxn); if ( chemRxnIt == pe_x.end() ) { - error_msg("pe undefined in Phreeqc::write_mass_action_eqn_x", 1); cxxChemRxn &rxn_ref = pe_x[trxn.token[i].s->secondary->pe_rxn]; trxn_add(rxn_ref, trxn.token[i].coef * coef_e, FALSE); // Create temporary rxn object and add reactions together From aee342676bde6f05183e9db06e8aa388c8dfc14b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Jan 2014 15:54:30 +0000 Subject: [PATCH 0776/1077] Removed yellow for graphing. Changed Li molar volume in Pitzer, Amm, phreeqc.dat Added test case Vm_LiCl_sol git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8378 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 2 +- Form1.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChartObject.cpp b/ChartObject.cpp index 41a5f692..14e95fd5 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -53,7 +53,7 @@ cxxNumKeyword(io) Color_vector.push_back("Blue"); Color_vector.push_back("Orange"); Color_vector.push_back("Magenta"); - Color_vector.push_back("Yellow"); +// Color_vector.push_back("Yellow"); Color_vector.push_back("Black"); Color_vector.push_back("Cyan"); Color_vector.push_back("Brown"); diff --git a/Form1.h b/Form1.h index 3c4d6be5..1eced151 100644 --- a/Form1.h +++ b/Form1.h @@ -140,7 +140,8 @@ namespace zdg_ui2 { private: PointPairList ^list; int col_use, symbol_use; bool Y2, Y2show; - static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black", "Cyan", "Brown", "Lime", "Gray" }; + // static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Yellow", "Black", "Cyan", "Brown", "Lime", "Gray" }; + static cli::array ^ColorList = {"Red", "Green", "Blue", "Orange", "Magenta", "Black", "Cyan", "Brown", "Lime", "Gray" }; bool background, hints, grid; ZedGraph::GraphObjList ^GOL_no_hints; From ab9b2ddd28098596156263bcdcd87aa28a693beb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Jan 2014 17:20:14 +0000 Subject: [PATCH 0777/1077] ex4 works with old flow from 8056. Will now try to keep all other changes, but go back to updated flow calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8380 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- mainsubs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index ba863069..a678e162 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -2314,12 +2314,12 @@ run_simulations(void) /* ---------------------------------------------------------------------- */ { char token[MAX_LENGTH]; -#ifdef SKIP_KEEP +//#ifdef SKIP_KEEP #if defined(WIN32) unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif -#endif +//#endif /* * Prepare error handling */ From aab6347c98b0d751afac9b44ef6a10661bca2286 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 23 Jan 2014 01:31:19 +0000 Subject: [PATCH 0778/1077] changed EOL to native git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8391 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SelectedOutput.cpp | 210 +++++++++++------------ SelectedOutput.h | 408 ++++++++++++++++++++++----------------------- UserPunch.cpp | 38 ++--- UserPunch.h | 76 ++++----- 4 files changed, 366 insertions(+), 366 deletions(-) diff --git a/SelectedOutput.cpp b/SelectedOutput.cpp index e2b5c5c6..63937185 100644 --- a/SelectedOutput.cpp +++ b/SelectedOutput.cpp @@ -1,105 +1,105 @@ -#include "SelectedOutput.h" - -SelectedOutput::SelectedOutput(int n, PHRQ_io *io) -: cxxNumKeyword(io) -{ - // file_name - this->Set_file_name(n); - - // punch_ostream - this->punch_ostream = NULL; - - // state vars - this->active = true; - this->new_def = false; - this->user_punch_new_def = false; - this->have_punch_name = false; - - // as-is vars - // - this->user_punch = true; - this->high_precision = false; - this->inverse = true; - - this->sim = true; - this->state = true; - this->soln = true; - this->dist = true; - this->time = true; - - this->step = true; - this->ph = true; - this->pe = true; - this->rxn = false; - this->temp = false; - - this->alk = false; - this->mu = false; - this->water = false; - this->charge_balance = false; - this->percent_error = false; - - // as-is set flags - // - this->set_user_punch = false; - this->set_high_precision = false; - this->set_inverse = false; - - this->set_sim = false; - this->set_state = false; - this->set_soln = false; - this->set_dist = false; - this->set_time = false; - - this->set_step = false; - this->set_ph = false; - this->set_pe = false; - this->set_rxn = false; - this->set_temp = false; - - this->set_alk = false; - this->set_mu = false; - this->set_water = false; - this->set_charge_balance = false; - this->set_percent_error = false; -} - -SelectedOutput::~SelectedOutput(void) -{ - if (this->punch_ostream != NULL) - { - delete this->punch_ostream; - } - this->punch_ostream = NULL; -} - -void -SelectedOutput::Reset(bool value) -{ - // as-is vars - Set_sim(value); - Set_state(value); - Set_soln(value); - Set_dist(value); - Set_time(value); - - Set_step(value); - Set_ph(value); - Set_pe(value); - Set_rxn(value); - Set_temp(value); - - Set_alk(value); - Set_mu(value); - Set_water(value); - Set_charge_balance(value); - Set_percent_error(value); -} - -void -SelectedOutput::Set_file_name(int n) -{ - std::ostringstream os; - os << "selected_output_" << n << ".sel"; - file_name = os.str(); -} +#include "SelectedOutput.h" + +SelectedOutput::SelectedOutput(int n, PHRQ_io *io) +: cxxNumKeyword(io) +{ + // file_name + this->Set_file_name(n); + + // punch_ostream + this->punch_ostream = NULL; + + // state vars + this->active = true; + this->new_def = false; + this->user_punch_new_def = false; + this->have_punch_name = false; + + // as-is vars + // + this->user_punch = true; + this->high_precision = false; + this->inverse = true; + + this->sim = true; + this->state = true; + this->soln = true; + this->dist = true; + this->time = true; + + this->step = true; + this->ph = true; + this->pe = true; + this->rxn = false; + this->temp = false; + + this->alk = false; + this->mu = false; + this->water = false; + this->charge_balance = false; + this->percent_error = false; + + // as-is set flags + // + this->set_user_punch = false; + this->set_high_precision = false; + this->set_inverse = false; + + this->set_sim = false; + this->set_state = false; + this->set_soln = false; + this->set_dist = false; + this->set_time = false; + + this->set_step = false; + this->set_ph = false; + this->set_pe = false; + this->set_rxn = false; + this->set_temp = false; + + this->set_alk = false; + this->set_mu = false; + this->set_water = false; + this->set_charge_balance = false; + this->set_percent_error = false; +} + +SelectedOutput::~SelectedOutput(void) +{ + if (this->punch_ostream != NULL) + { + delete this->punch_ostream; + } + this->punch_ostream = NULL; +} + +void +SelectedOutput::Reset(bool value) +{ + // as-is vars + Set_sim(value); + Set_state(value); + Set_soln(value); + Set_dist(value); + Set_time(value); + + Set_step(value); + Set_ph(value); + Set_pe(value); + Set_rxn(value); + Set_temp(value); + + Set_alk(value); + Set_mu(value); + Set_water(value); + Set_charge_balance(value); + Set_percent_error(value); +} + +void +SelectedOutput::Set_file_name(int n) +{ + std::ostringstream os; + os << "selected_output_" << n << ".sel"; + file_name = os.str(); +} diff --git a/SelectedOutput.h b/SelectedOutput.h index 41053e39..39a8bac0 100644 --- a/SelectedOutput.h +++ b/SelectedOutput.h @@ -1,204 +1,204 @@ -#if !defined(SELECTEDOUTPUT_H_INCLUDED) -#define SELECTEDOUTPUT_H_INCLUDED -#include // std::string -#include -#include -#include "NumKeyword.h" - -class SelectedOutput:public cxxNumKeyword -{ -public: - SelectedOutput(int n=1, PHRQ_io *io=NULL); - ~SelectedOutput(void); - - void Reset(bool tf); - - // vector getters - inline std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} - inline std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} - inline std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} - inline std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;} - inline std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;} - inline std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;} - inline std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;} - inline std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;} - inline std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} - inline std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} - - // const vector getters - inline const std::vector< std::pair< std::string, void * > > & Get_totals(void)const {return this->totals;} - inline const std::vector< std::pair< std::string, void * > > & Get_molalities(void)const {return this->molalities;} - inline const std::vector< std::pair< std::string, void * > > & Get_activities(void)const {return this->activities;} - inline const std::vector< std::pair< std::string, void * > > & Get_pure_phases(void)const {return this->pure_phases;} - inline const std::vector< std::pair< std::string, void * > > & Get_si(void)const {return this->si;} - inline const std::vector< std::pair< std::string, void * > > & Get_gases(void)const {return this->gases;} - inline const std::vector< std::pair< std::string, void * > > & Get_s_s(void)const {return this->s_s;} - inline const std::vector< std::pair< std::string, void * > > & Get_kinetics(void)const {return this->kinetics;} - inline const std::vector< std::pair< std::string, void * > > & Get_isotopes(void)const {return this->isotopes;} - inline const std::vector< std::pair< std::string, void * > > & Get_calculate_values(void)const {return this->calculate_values;} - - // file_name getters/setters - void Set_file_name(int i); - inline void Set_file_name(std::string s) {this->file_name = s;} - inline std::string & Get_file_name(void) {return this->file_name;} - inline const std::string & Get_file_name(void)const {return this->file_name;} - - // punch_ostream getters/setters - inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} - inline const std::ostream* Get_punch_ostream(void)const {return this->punch_ostream;} - inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} - - // state var getters - inline bool Get_active(void)const {return this->active;} - inline bool Get_new_def(void)const {return this->new_def;} - inline bool Get_user_punch_new_def(void)const {return this->user_punch_new_def;} - inline bool Get_have_punch_name(void)const {return this->have_punch_name;} - - // state var setters - inline void Set_active(bool tf) {this->active = tf;} - inline void Set_new_def(bool tf) {this->new_def = tf;} - inline void Set_user_punch_new_def(bool tf) {this->user_punch_new_def = tf;} - inline void Set_have_punch_name(bool tf) {this->have_punch_name = tf;} - - // as_is getters - inline bool Get_user_punch(void)const {return this->user_punch;} - inline bool Get_high_precision(void)const {return this->high_precision;} - inline bool Get_inverse(void)const {return this->inverse;} - - inline bool Get_sim(void)const {return this->sim;} - inline bool Get_state(void)const {return this->state;} - inline bool Get_soln(void)const {return this->soln;} - inline bool Get_dist(void)const {return this->dist;} - inline bool Get_time(void)const {return this->time;} - - inline bool Get_step(void)const {return this->step;} - inline bool Get_ph(void)const {return this->ph;} - inline bool Get_pe(void)const {return this->pe;} - inline bool Get_rxn(void)const {return this->rxn;} - inline bool Get_temp(void)const {return this->temp;} - - inline bool Get_alk(void)const {return this->alk;} - inline bool Get_mu(void)const {return this->mu;} - inline bool Get_water(void)const {return this->water;} - inline bool Get_charge_balance(void)const {return this->charge_balance;} - inline bool Get_percent_error(void)const {return this->percent_error;} - - // as-is setters - inline void Set_user_punch(bool tf) {this->user_punch = tf; this->set_user_punch = true;} - inline void Set_high_precision(bool tf) {this->high_precision = tf; this->set_high_precision = true;} - inline void Set_inverse(bool tf) {this->inverse = tf; this->set_inverse = true;} - - inline void Set_sim(bool tf) {this->sim = tf; this->set_sim = true;} - inline void Set_state(bool tf) {this->state = tf; this->set_state = true;} - inline void Set_soln(bool tf) {this->soln = tf; this->set_soln = true;} - inline void Set_dist(bool tf) {this->dist = tf; this->set_dist = true;} - inline void Set_time(bool tf) {this->time = tf; this->set_time = true;} - - inline void Set_step(bool tf) {this->step = tf; this->set_step = true;} - inline void Set_ph(bool tf) {this->ph = tf; this->set_ph = true;} - inline void Set_pe(bool tf) {this->pe = tf; this->set_pe = true;} - inline void Set_rxn(bool tf) {this->rxn = tf; this->set_rxn = true;} - inline void Set_temp(bool tf) {this->temp = tf; this->set_temp = true;} - - inline void Set_alk(bool tf) {this->alk = tf; this->set_alk = true;} - inline void Set_mu(bool tf) {this->mu = tf; this->set_mu = true;} - inline void Set_water(bool tf) {this->water = tf; this->set_water = true;} - inline void Set_charge_balance(bool tf) {this->charge_balance = tf; this->set_charge_balance = true;} - inline void Set_percent_error(bool tf) {this->percent_error = tf; this->set_percent_error = true;} - - // set flag getters - inline bool was_set_user_punch()const {return this->set_user_punch;} - inline bool was_set_high_precision()const {return this->set_high_precision;} - inline bool was_set_inverse()const {return this->set_inverse;} - - inline bool was_set_sim()const {return this->set_sim;} - inline bool was_set_state()const {return this->set_state;} - inline bool was_set_soln()const {return this->set_soln;} - inline bool was_set_dist()const {return this->set_dist;} - inline bool was_set_time()const {return this->set_time;} - - inline bool was_set_step()const {return this->set_step;} - inline bool was_set_ph()const {return this->set_ph;} - inline bool was_set_pe()const {return this->set_pe;} - inline bool was_set_rxn()const {return this->set_rxn;} - inline bool was_set_temp()const {return this->set_temp;} - - inline bool was_set_alk()const {return this->set_alk;} - inline bool was_set_mu()const {return this->set_mu;} - inline bool was_set_water()const {return this->set_water;} - inline bool was_set_charge_balance()const {return this->set_charge_balance;} - inline bool was_set_percent_error()const {return this->set_percent_error;} - -protected: - - // vectors - std::vector< std::pair< std::string, void * > > totals; - std::vector< std::pair< std::string, void * > > molalities; - std::vector< std::pair< std::string, void * > > activities; - std::vector< std::pair< std::string, void * > > pure_phases; - std::vector< std::pair< std::string, void * > > si; - std::vector< std::pair< std::string, void * > > gases; - std::vector< std::pair< std::string, void * > > s_s; - std::vector< std::pair< std::string, void * > > kinetics; - std::vector< std::pair< std::string, void * > > isotopes; - std::vector< std::pair< std::string, void * > > calculate_values; - - // file_name - std::string file_name; - - // punch_ostream - std::ostream * punch_ostream; - - // state vars - bool active; - bool new_def; - bool user_punch_new_def; - bool have_punch_name; - - // as-is vars - bool user_punch; - bool high_precision; - bool inverse; - - bool sim; - bool state; - bool soln; - bool dist; - bool time; - - bool step; - bool ph; - bool pe; - bool rxn; - bool temp; - - bool alk; - bool mu; - bool water; - bool charge_balance; - bool percent_error; - - // as-is set flags - bool set_user_punch; - bool set_high_precision; - bool set_inverse; - - bool set_sim; - bool set_state; - bool set_soln; - bool set_dist; - bool set_time; - - bool set_step; - bool set_ph; - bool set_pe; - bool set_rxn; - bool set_temp; - - bool set_alk; - bool set_mu; - bool set_water; - bool set_charge_balance; - bool set_percent_error; -}; -#endif // !defined(SELECTEDOUTPUT_H_INCLUDED) +#if !defined(SELECTEDOUTPUT_H_INCLUDED) +#define SELECTEDOUTPUT_H_INCLUDED +#include // std::string +#include +#include +#include "NumKeyword.h" + +class SelectedOutput:public cxxNumKeyword +{ +public: + SelectedOutput(int n=1, PHRQ_io *io=NULL); + ~SelectedOutput(void); + + void Reset(bool tf); + + // vector getters + inline std::vector< std::pair< std::string, void * > > & Get_totals(void) {return this->totals;} + inline std::vector< std::pair< std::string, void * > > & Get_molalities(void) {return this->molalities;} + inline std::vector< std::pair< std::string, void * > > & Get_activities(void) {return this->activities;} + inline std::vector< std::pair< std::string, void * > > & Get_pure_phases(void) {return this->pure_phases;} + inline std::vector< std::pair< std::string, void * > > & Get_si(void) {return this->si;} + inline std::vector< std::pair< std::string, void * > > & Get_gases(void) {return this->gases;} + inline std::vector< std::pair< std::string, void * > > & Get_s_s(void) {return this->s_s;} + inline std::vector< std::pair< std::string, void * > > & Get_kinetics(void) {return this->kinetics;} + inline std::vector< std::pair< std::string, void * > > & Get_isotopes(void) {return this->isotopes;} + inline std::vector< std::pair< std::string, void * > > & Get_calculate_values(void) {return this->calculate_values;} + + // const vector getters + inline const std::vector< std::pair< std::string, void * > > & Get_totals(void)const {return this->totals;} + inline const std::vector< std::pair< std::string, void * > > & Get_molalities(void)const {return this->molalities;} + inline const std::vector< std::pair< std::string, void * > > & Get_activities(void)const {return this->activities;} + inline const std::vector< std::pair< std::string, void * > > & Get_pure_phases(void)const {return this->pure_phases;} + inline const std::vector< std::pair< std::string, void * > > & Get_si(void)const {return this->si;} + inline const std::vector< std::pair< std::string, void * > > & Get_gases(void)const {return this->gases;} + inline const std::vector< std::pair< std::string, void * > > & Get_s_s(void)const {return this->s_s;} + inline const std::vector< std::pair< std::string, void * > > & Get_kinetics(void)const {return this->kinetics;} + inline const std::vector< std::pair< std::string, void * > > & Get_isotopes(void)const {return this->isotopes;} + inline const std::vector< std::pair< std::string, void * > > & Get_calculate_values(void)const {return this->calculate_values;} + + // file_name getters/setters + void Set_file_name(int i); + inline void Set_file_name(std::string s) {this->file_name = s;} + inline std::string & Get_file_name(void) {return this->file_name;} + inline const std::string & Get_file_name(void)const {return this->file_name;} + + // punch_ostream getters/setters + inline std::ostream* Get_punch_ostream(void) {return this->punch_ostream;} + inline const std::ostream* Get_punch_ostream(void)const {return this->punch_ostream;} + inline void Set_punch_ostream(std::ostream * os) {this->punch_ostream = os;} + + // state var getters + inline bool Get_active(void)const {return this->active;} + inline bool Get_new_def(void)const {return this->new_def;} + inline bool Get_user_punch_new_def(void)const {return this->user_punch_new_def;} + inline bool Get_have_punch_name(void)const {return this->have_punch_name;} + + // state var setters + inline void Set_active(bool tf) {this->active = tf;} + inline void Set_new_def(bool tf) {this->new_def = tf;} + inline void Set_user_punch_new_def(bool tf) {this->user_punch_new_def = tf;} + inline void Set_have_punch_name(bool tf) {this->have_punch_name = tf;} + + // as_is getters + inline bool Get_user_punch(void)const {return this->user_punch;} + inline bool Get_high_precision(void)const {return this->high_precision;} + inline bool Get_inverse(void)const {return this->inverse;} + + inline bool Get_sim(void)const {return this->sim;} + inline bool Get_state(void)const {return this->state;} + inline bool Get_soln(void)const {return this->soln;} + inline bool Get_dist(void)const {return this->dist;} + inline bool Get_time(void)const {return this->time;} + + inline bool Get_step(void)const {return this->step;} + inline bool Get_ph(void)const {return this->ph;} + inline bool Get_pe(void)const {return this->pe;} + inline bool Get_rxn(void)const {return this->rxn;} + inline bool Get_temp(void)const {return this->temp;} + + inline bool Get_alk(void)const {return this->alk;} + inline bool Get_mu(void)const {return this->mu;} + inline bool Get_water(void)const {return this->water;} + inline bool Get_charge_balance(void)const {return this->charge_balance;} + inline bool Get_percent_error(void)const {return this->percent_error;} + + // as-is setters + inline void Set_user_punch(bool tf) {this->user_punch = tf; this->set_user_punch = true;} + inline void Set_high_precision(bool tf) {this->high_precision = tf; this->set_high_precision = true;} + inline void Set_inverse(bool tf) {this->inverse = tf; this->set_inverse = true;} + + inline void Set_sim(bool tf) {this->sim = tf; this->set_sim = true;} + inline void Set_state(bool tf) {this->state = tf; this->set_state = true;} + inline void Set_soln(bool tf) {this->soln = tf; this->set_soln = true;} + inline void Set_dist(bool tf) {this->dist = tf; this->set_dist = true;} + inline void Set_time(bool tf) {this->time = tf; this->set_time = true;} + + inline void Set_step(bool tf) {this->step = tf; this->set_step = true;} + inline void Set_ph(bool tf) {this->ph = tf; this->set_ph = true;} + inline void Set_pe(bool tf) {this->pe = tf; this->set_pe = true;} + inline void Set_rxn(bool tf) {this->rxn = tf; this->set_rxn = true;} + inline void Set_temp(bool tf) {this->temp = tf; this->set_temp = true;} + + inline void Set_alk(bool tf) {this->alk = tf; this->set_alk = true;} + inline void Set_mu(bool tf) {this->mu = tf; this->set_mu = true;} + inline void Set_water(bool tf) {this->water = tf; this->set_water = true;} + inline void Set_charge_balance(bool tf) {this->charge_balance = tf; this->set_charge_balance = true;} + inline void Set_percent_error(bool tf) {this->percent_error = tf; this->set_percent_error = true;} + + // set flag getters + inline bool was_set_user_punch()const {return this->set_user_punch;} + inline bool was_set_high_precision()const {return this->set_high_precision;} + inline bool was_set_inverse()const {return this->set_inverse;} + + inline bool was_set_sim()const {return this->set_sim;} + inline bool was_set_state()const {return this->set_state;} + inline bool was_set_soln()const {return this->set_soln;} + inline bool was_set_dist()const {return this->set_dist;} + inline bool was_set_time()const {return this->set_time;} + + inline bool was_set_step()const {return this->set_step;} + inline bool was_set_ph()const {return this->set_ph;} + inline bool was_set_pe()const {return this->set_pe;} + inline bool was_set_rxn()const {return this->set_rxn;} + inline bool was_set_temp()const {return this->set_temp;} + + inline bool was_set_alk()const {return this->set_alk;} + inline bool was_set_mu()const {return this->set_mu;} + inline bool was_set_water()const {return this->set_water;} + inline bool was_set_charge_balance()const {return this->set_charge_balance;} + inline bool was_set_percent_error()const {return this->set_percent_error;} + +protected: + + // vectors + std::vector< std::pair< std::string, void * > > totals; + std::vector< std::pair< std::string, void * > > molalities; + std::vector< std::pair< std::string, void * > > activities; + std::vector< std::pair< std::string, void * > > pure_phases; + std::vector< std::pair< std::string, void * > > si; + std::vector< std::pair< std::string, void * > > gases; + std::vector< std::pair< std::string, void * > > s_s; + std::vector< std::pair< std::string, void * > > kinetics; + std::vector< std::pair< std::string, void * > > isotopes; + std::vector< std::pair< std::string, void * > > calculate_values; + + // file_name + std::string file_name; + + // punch_ostream + std::ostream * punch_ostream; + + // state vars + bool active; + bool new_def; + bool user_punch_new_def; + bool have_punch_name; + + // as-is vars + bool user_punch; + bool high_precision; + bool inverse; + + bool sim; + bool state; + bool soln; + bool dist; + bool time; + + bool step; + bool ph; + bool pe; + bool rxn; + bool temp; + + bool alk; + bool mu; + bool water; + bool charge_balance; + bool percent_error; + + // as-is set flags + bool set_user_punch; + bool set_high_precision; + bool set_inverse; + + bool set_sim; + bool set_state; + bool set_soln; + bool set_dist; + bool set_time; + + bool set_step; + bool set_ph; + bool set_pe; + bool set_rxn; + bool set_temp; + + bool set_alk; + bool set_mu; + bool set_water; + bool set_charge_balance; + bool set_percent_error; +}; +#endif // !defined(SELECTEDOUTPUT_H_INCLUDED) diff --git a/UserPunch.cpp b/UserPunch.cpp index 661f0ac3..42dac9f3 100644 --- a/UserPunch.cpp +++ b/UserPunch.cpp @@ -1,19 +1,19 @@ -#include "UserPunch.h" -#include "Phreeqc.h" -UserPunch::UserPunch(int n, PHRQ_io *io) -: cxxNumKeyword(io) -{ - this->PhreeqcPtr = NULL; - this->rate = NULL; -} - - -UserPunch::~UserPunch(void) -{ - if (this->rate != NULL) - { - this->PhreeqcPtr->rate_free(this->rate); - } - this->PhreeqcPtr->free_check_null(this->rate); - this->rate = NULL; -} +#include "UserPunch.h" +#include "Phreeqc.h" +UserPunch::UserPunch(int n, PHRQ_io *io) +: cxxNumKeyword(io) +{ + this->PhreeqcPtr = NULL; + this->rate = NULL; +} + + +UserPunch::~UserPunch(void) +{ + if (this->rate != NULL) + { + this->PhreeqcPtr->rate_free(this->rate); + } + this->PhreeqcPtr->free_check_null(this->rate); + this->rate = NULL; +} diff --git a/UserPunch.h b/UserPunch.h index 994568f0..fb8c123f 100644 --- a/UserPunch.h +++ b/UserPunch.h @@ -1,39 +1,39 @@ -#if !defined(USERPUNCH_H_INCLUDED) -#define USERPUNCH_H_INCLUDED -#include -#include // std::string -#include "NumKeyword.h" -class Phreeqc; -class UserPunch:public cxxNumKeyword -{ -public: - UserPunch(int n=1, PHRQ_io *io=NULL); - ~UserPunch(void); - - // headings - // - std::vector &Get_headings() {return this->headings;} - const std::vector &Get_headings()const {return this->headings;} - - void Set_headings(std::vector & h) {this->headings = h;} - - // phreeqc pointer - // - Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} - const Phreeqc * Get_PhreeqcPtr()const {return this->PhreeqcPtr;} - - void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} - - // rate - // - struct rate * Get_rate() {return this->rate;} - const struct rate * Get_rate()const {return this->rate;} - - void Set_rate(struct rate * r) {this->rate = r;} - -protected: - std::vector headings; - struct rate * rate; - Phreeqc * PhreeqcPtr; -}; +#if !defined(USERPUNCH_H_INCLUDED) +#define USERPUNCH_H_INCLUDED +#include +#include // std::string +#include "NumKeyword.h" +class Phreeqc; +class UserPunch:public cxxNumKeyword +{ +public: + UserPunch(int n=1, PHRQ_io *io=NULL); + ~UserPunch(void); + + // headings + // + std::vector &Get_headings() {return this->headings;} + const std::vector &Get_headings()const {return this->headings;} + + void Set_headings(std::vector & h) {this->headings = h;} + + // phreeqc pointer + // + Phreeqc * Get_PhreeqcPtr() {return this->PhreeqcPtr;} + const Phreeqc * Get_PhreeqcPtr()const {return this->PhreeqcPtr;} + + void Set_PhreeqcPtr(Phreeqc * p) {this->PhreeqcPtr = p;} + + // rate + // + struct rate * Get_rate() {return this->rate;} + const struct rate * Get_rate()const {return this->rate;} + + void Set_rate(struct rate * r) {this->rate = r;} + +protected: + std::vector headings; + struct rate * rate; + Phreeqc * PhreeqcPtr; +}; #endif // !defined(USERPUNCH_H_INCLUDED) \ No newline at end of file From 9d9e86f875c95b3361577c797785e5d96cdae182 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 24 Jan 2014 00:34:03 +0000 Subject: [PATCH 0779/1077] Added next_user_number to Phreeqc. Added a template function Rxn_next_user_number. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8397 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- Phreeqc.h | 12 ++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index efe5bca3..4b97fd9a 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -168,7 +168,6 @@ size_t Phreeqc::list_components(std::list &list_c) } return(list_c.size()); } - Phreeqc::Phreeqc(PHRQ_io *io) { // phrq_io @@ -2467,3 +2466,46 @@ Phreeqc &Phreeqc::operator=(const Phreeqc &rhs) this->InternalCopy(&rhs); return *this; } + +int Phreeqc::next_user_number(Keywords::KEYWORDS key) +{ + switch (key) + { + case Keywords::KEY_REACTION_TEMPERATURE: + return Utilities::Rxn_next_user_number(Rxn_temperature_map); + break; + case Keywords::KEY_REACTION_PRESSURE: + return Utilities::Rxn_next_user_number(Rxn_pressure_map); + break; + case Keywords::KEY_SURFACE: + return Utilities::Rxn_next_user_number(Rxn_surface_map); + break; + case Keywords::KEY_EXCHANGE: + return Utilities::Rxn_next_user_number(Rxn_exchange_map); + break; + case Keywords::KEY_KINETICS: + return Utilities::Rxn_next_user_number(Rxn_kinetics_map); + break; + case Keywords::KEY_MIX: + return Utilities::Rxn_next_user_number(Rxn_mix_map); + break; + case Keywords::KEY_REACTION: + return Utilities::Rxn_next_user_number(Rxn_reaction_map); + break; + case Keywords::KEY_GAS_PHASE: + return Utilities::Rxn_next_user_number(Rxn_gas_phase_map); + break; + case Keywords::KEY_SOLID_SOLUTIONS: + return Utilities::Rxn_next_user_number(Rxn_ss_assemblage_map); + break; + case Keywords::KEY_EQUILIBRIUM_PHASES: + return Utilities::Rxn_next_user_number(Rxn_pp_assemblage_map); + break; + case Keywords::KEY_SOLUTION: + return Utilities::Rxn_next_user_number(Rxn_solution_map); + break; + default: + assert(false); + return -999; + } +} \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index 81d972af..840d9fff 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1122,6 +1122,7 @@ protected: public: int main_method(int argc, char *argv[]); void set_phast(int); + int next_user_number(Keywords::KEYWORDS key); size_t list_components(std::list &list_c); PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} protected: @@ -1988,6 +1989,17 @@ namespace Utilities } } + template < typename T > + int Rxn_next_user_number(std::map < int, T > &b) + { + int ret = 0; + if (b.size() != 0) + { + ret = b.rbegin()->first + 1; + } + return ret; + } + template < typename T > T * Rxn_copy(std::map < int, T > &b, int i, int j) { From 473ea39b19b4925159053332dea12119e093ff91 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 24 Jan 2014 03:46:46 +0000 Subject: [PATCH 0780/1077] Added additional check to LoadDatabase git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8399 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index c6ea66c9..ad2f7928 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -97,7 +97,7 @@ read_delete(void) std::istringstream iss_in; return_value = streamify_to_next_keyword(iss_in); CParser parser(iss_in, phrq_io); - assert(!reading_database()); + //assert(!reading_database()); //For testing, need to read line to get started parser.set_echo_file(CParser::EO_NONE); From f9eff4b835ea2622b454572d493492c4457cbbfb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Jan 2014 22:04:45 +0000 Subject: [PATCH 0781/1077] Use MIX_RAW in dump to read negative numbered mixes. Added testcase negative_user_number Tony's fix for start time units git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8403 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxMix.cxx | 2 +- read.cpp | 26 ++++++++++++++++++++++++-- readtr.cpp | 11 ++++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cxxMix.cxx b/cxxMix.cxx index 404f1f6d..a9161c36 100644 --- a/cxxMix.cxx +++ b/cxxMix.cxx @@ -80,7 +80,7 @@ cxxMix::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) const // Mix element and attributes s_oss << indent0; int n_user_local = (n_out != NULL) ? *n_out : this->n_user; - s_oss << "MIX " << n_user_local << " " << this->description << "\n"; + s_oss << "MIX_RAW " << n_user_local << " " << this->description << "\n"; for (std::map < int, LDBLE >::const_iterator it = this->mixComps.begin(); it != this->mixComps.end(); it++) diff --git a/read.cpp b/read.cpp index 0da7b686..35dc0287 100644 --- a/read.cpp +++ b/read.cpp @@ -2832,7 +2832,10 @@ read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) delta_v[j] = 0.0; } delta_v[9] = 1.0; - j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, +/* Vmax, dmax... + delta_v[10] = 999.0; + delta_v[11] = 1.0; */ + j = sscanf(ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT /*SCANFORMAT SCANFORMAT */, /* a1..a4 */ &(delta_v[0]), &(delta_v[1]), &(delta_v[2]), &(delta_v[3]), /* wref */ @@ -2841,6 +2844,8 @@ read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) &(delta_v[5]), /* c1..c4 */ &(delta_v[6]), &(delta_v[7]), &(delta_v[8]), &(delta_v[9])); + /* vmax, dmax + &(delta_v[10]), &(delta_v[11])); */ if (j < 1) { input_error++; @@ -5034,6 +5039,12 @@ read_selected_output(void) if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) { + // delete if exists + if (so != SelectedOutput_map.end()) + { + SelectedOutput_map.erase(so); + } + // store new selected output SelectedOutput_map[n_user] = temp_selected_output; @@ -8054,7 +8065,18 @@ read_advection(void) } break; case 15: /* initial_time */ - sscanf(next_char, SCANFORMAT, &initial_total_time); + char token[MAX_LENGTH]; + int j; + if (copy_token(token, &next_char, &j) == DIGIT) + sscanf(token, SCANFORMAT, &initial_total_time); + { + std::string stdtoken; + j = copy_token(stdtoken, &next_char); + if (j == UPPER || j == LOWER) + { + initial_total_time = Utilities::convert_time(initial_total_time, stdtoken, "s"); + } + } opt_save = OPTION_DEFAULT; break; case 16: /* warning */ diff --git a/readtr.cpp b/readtr.cpp index c3cdba7f..551e566b 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -478,7 +478,16 @@ read_transport(void) opt_save = OPTION_DEFAULT; break; case 36: /* initial_time */ - sscanf(next_char, SCANFORMAT, &initial_total_time); + if (copy_token(token, &next_char, &l) == DIGIT) + sscanf(token, SCANFORMAT, &initial_total_time); + { + std::string stdtoken; + j = copy_token(stdtoken, &next_char); + if (j == UPPER || j == LOWER) + { + initial_total_time = Utilities::convert_time(initial_total_time, stdtoken, "s"); + } + } opt_save = OPTION_DEFAULT; break; case 37: /* warning */ From 5e788df19599e4bdff501f170d264a88c353b9c7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 Jan 2014 19:53:57 +0000 Subject: [PATCH 0782/1077] modifications to STORAGEBIN, added Copy. Check for missing solution in run_cells. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8408 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 3 ++ StorageBin.cxx | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 1 + 3 files changed, 97 insertions(+) diff --git a/ReadClass.cxx b/ReadClass.cxx index ad2f7928..0dbed169 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -700,6 +700,9 @@ run_as_cells(void) { int i = *it; if (i < 0) continue; + if (Utilities::Rxn_find(Rxn_solution_map, i) == NULL + && Utilities::Rxn_find(Rxn_mix_map, i) == NULL) + continue; initial_total_time = initial_total_time_save; set_advection(i, TRUE, TRUE, i); /* diff --git a/StorageBin.cxx b/StorageBin.cxx index 44e36a4c..7721ff14 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -116,6 +116,99 @@ PHRQ_base(io) cxxStorageBin::~cxxStorageBin() { } +void +cxxStorageBin::Copy(int destination, int source) +{ + this->Remove(destination); + // Solution + { + std::map < int, cxxSolution >::iterator it = this->Solutions.find(source); + if (it != this->Solutions.end()) + { + this->Set_Solution(destination, &(it->second)); + } + } + + // Exchange + { + std::map < int, cxxExchange >::iterator it = this->Exchangers.find(source); + if (it != this->Exchangers.end()) + { + this->Set_Exchange(destination, &(it->second)); + } + } + + // gas_phase + { + std::map < int, cxxGasPhase >::iterator it = this->GasPhases.find(source); + if (it != this->GasPhases.end()) + { + this->Set_GasPhase(destination, &(it->second)); + } + } + // kinetics + { + std::map < int, cxxKinetics >::iterator it = this->Kinetics.find(source); + if (it != this->Kinetics.end()) + { + this->Set_Kinetics(destination, &(it->second)); + } + } + // pp_assemblage + { + std::map < int, cxxPPassemblage >::iterator it = this->PPassemblages.find(source); + if (it != this->PPassemblages.end()) + { + this->Set_PPassemblage(destination, &(it->second)); + } + } + // ss_assemblage + { + std::map < int, cxxSSassemblage >::iterator it = this->SSassemblages.find(source); + if (it != this->SSassemblages.end()) + { + this->Set_SSassemblage(destination, &(it->second)); + } + } + // surface + { + std::map < int, cxxSurface >::iterator it = this->Surfaces.find(source); + if (it != this->Surfaces.end()) + { + this->Set_Surface(destination, &(it->second)); + } + } + // mix + { + std::map < int, cxxMix >::iterator it = this->Mixes.find(source); + if (it != this->Mixes.end()) + { + this->Set_Mix(destination, &(it->second)); + } + } + // reaction + { + std::map < int, cxxReaction >::iterator it = this->Reactions.find(source); + if (it != this->Reactions.end()) + { + this->Set_Reaction(destination, &(it->second)); + } + } + // reaction temperature + { + std::map < int, cxxTemperature >::iterator it = this->Temperatures.find(source); + if (it != this->Temperatures.end()) + { + this->Set_Temperature(destination, &(it->second)); + } + } + + // reaction pressure + { + this->Set_Pressure(destination, Utilities::Rxn_find(this->Pressures, source)); + } +} + cxxSolution * cxxStorageBin::Get_Solution(int n_user) { diff --git a/StorageBin.h b/StorageBin.h index f9a14fe4..3d70c167 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -28,6 +28,7 @@ class cxxStorageBin: public PHRQ_base cxxStorageBin(cxxUse &use_ref, PHRQ_io *io=NULL); virtual ~cxxStorageBin(); + void Copy(int destination, int source); void Remove(int n); void Clear(void); From 7cad09da674e6a3fe1f969808d886388fce7c569 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 Jan 2014 20:12:37 +0000 Subject: [PATCH 0783/1077] Only solutions, not mix in run_cells git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8409 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 0dbed169..58096d3b 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -701,7 +701,7 @@ run_as_cells(void) int i = *it; if (i < 0) continue; if (Utilities::Rxn_find(Rxn_solution_map, i) == NULL - && Utilities::Rxn_find(Rxn_mix_map, i) == NULL) + /*&& Utilities::Rxn_find(Rxn_mix_map, i) == NULL*/) continue; initial_total_time = initial_total_time_save; set_advection(i, TRUE, TRUE, i); From b6f962428e17508ad734539264cc7b37c46530b6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Jan 2014 01:36:11 +0000 Subject: [PATCH 0784/1077] guarded gzstream in FileHandler.cpp rewrote WriteRestart to use DumpModule Don't call DumpModule from manager/worker, now only in WriteFils fixed DumpModule to work for serial and parallel. Uses dump_file_name with no adjustments to extensions. added LastInitialPhreeqc2Module(vector cell_numbers). Changed args in RunFile and RunString in PhreeqcRM to bools, affected RM_interface.cpp, RM_interface_C.cpp, Tests/advection_cpp.cpp In Copy for cxxStorageBin, check if destination == source. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8411 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/StorageBin.cxx b/StorageBin.cxx index 7721ff14..96df5128 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -119,6 +119,8 @@ cxxStorageBin::~cxxStorageBin() void cxxStorageBin::Copy(int destination, int source) { + if (destination == source) + return; this->Remove(destination); // Solution { From 5bbe7db623af62eed6b4b5adc51a6eadff086516 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 4 Feb 2014 00:01:04 +0000 Subject: [PATCH 0785/1077] changes to Tests and include mix in RUN_CELLS git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8419 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ReadClass.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadClass.cxx b/ReadClass.cxx index 58096d3b..0dbed169 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -701,7 +701,7 @@ run_as_cells(void) int i = *it; if (i < 0) continue; if (Utilities::Rxn_find(Rxn_solution_map, i) == NULL - /*&& Utilities::Rxn_find(Rxn_mix_map, i) == NULL*/) + && Utilities::Rxn_find(Rxn_mix_map, i) == NULL) continue; initial_total_time = initial_total_time_save; set_advection(i, TRUE, TRUE, i); From 63a9c36ad87aae08e1f6da890e25619a885d6af9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 6 Feb 2014 00:40:58 +0000 Subject: [PATCH 0786/1077] changed so that 'dist' and 'time' are always doubles for R git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8446 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/print.cpp b/print.cpp index 8301e1fa..b365ce59 100644 --- a/print.cpp +++ b/print.cpp @@ -2869,7 +2869,7 @@ punch_identifiers(void) { if (state == ADVECTION) { - fpunchf(PHAST_NULL("dist_x"), dformat, use.Get_n_solution_user()); + fpunchf(PHAST_NULL("dist_x"), gformat, (double)use.Get_n_solution_user()); } else if (state == TRANSPORT) { @@ -2878,7 +2878,7 @@ punch_identifiers(void) } else { - fpunchf(PHAST_NULL("dist_x"), dformat, -99); + fpunchf(PHAST_NULL("dist_x"), gformat, (double)-99); } } if (current_selected_output->Get_time()) @@ -2935,12 +2935,12 @@ punch_identifiers(void) } else { - fpunchf(PHAST_NULL("time"), dformat, advection_step); + fpunchf(PHAST_NULL("time"), gformat, (double)advection_step); } } else { - fpunchf(PHAST_NULL("time"), dformat, -99); + fpunchf(PHAST_NULL("time"), gformat, (double)-99); } } From 063ba6202a674b1a0201f15368cb767de43e2bb1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 6 Feb 2014 16:57:39 +0000 Subject: [PATCH 0787/1077] Tony's punch_stream error when Basic error. Test case punch_stream added. run_cell_range adjusted to account for including MIX in RUN_CELLS git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8452 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index c881d124..4dbf0af7 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -541,7 +541,7 @@ close_ostreams(void) streams.insert(output_ostream); streams.insert(log_ostream); - streams.insert(punch_ostream); +// streams.insert(punch_ostream); // Should be removed in ~SelectedOutput #ifdef ERROR_OSTREAM streams.insert(error_ostream); #else From aee604b56e7e3a8f74f7169373f740c5ff87fd36 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 6 Feb 2014 18:28:24 +0000 Subject: [PATCH 0788/1077] Changed read _modify to warning if entity not found. Tony's bug in phrq_io. punch_ostream was deleted twice. roughed in REACTION_TEMPERATURE_MODIFY and REACTION_PRESSURE_MODIFY. Think they work, and added to test case modify_ignore. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8453 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 2 +- Phreeqc.h | 40 ++++++++++++++++++++++++++++++++++++++++ Pressure.cxx | 25 ++++++++++++++----------- Pressure.h | 2 +- Temperature.cxx | 33 ++++++++++++++++++--------------- Temperature.h | 2 +- read.cpp | 6 ++++++ 7 files changed, 81 insertions(+), 29 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 4dbf0af7..8db0e8fa 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -541,7 +541,7 @@ close_ostreams(void) streams.insert(output_ostream); streams.insert(log_ostream); -// streams.insert(punch_ostream); // Should be removed in ~SelectedOutput +// streams.insert(punch_ostream); // Should be deleted in ~SelectedOutput #ifdef ERROR_OSTREAM streams.insert(error_ostream); #else diff --git a/Phreeqc.h b/Phreeqc.h index 840d9fff..3369bbf4 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -2062,6 +2062,7 @@ namespace Utilities return phreeqc_cookie->cleanup_after_parser(parser); } +#ifdef SKIP template < typename T > int Rxn_read_modify(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) { @@ -2092,6 +2093,45 @@ namespace Utilities return phreeqc_cookie->cleanup_after_parser(parser); } +#endif + + template < typename T > + int Rxn_read_modify(std::map < int, T > &m, std::set < int > &s, Phreeqc * phreeqc_cookie) + { + typename std::map < int, T >::iterator it; + + CParser parser(phreeqc_cookie->Get_phrq_io()); + + std::string key_name; + std::string::iterator b = parser.line().begin(); + std::string::iterator e = parser.line().end(); + CParser::copy_token(key_name, b, e); + + cxxNumKeyword nk; + nk.read_number_description(parser); + T * entity_ptr = Utilities::Rxn_find(m, nk.Get_n_user()); + if (!entity_ptr) + { + std::ostringstream errstr; + errstr << "Could not find " << key_name << " " << nk.Get_n_user() << ", ignoring modify data.\n"; + phreeqc_cookie->warning_msg(errstr.str().c_str()); + //phreeqc_cookie->error_msg(errstr.str().c_str(), PHRQ_io::OT_STOP); + + // Don't throw, read data into dummy entity, then ignore + T entity; + entity_ptr = &entity; + entity_ptr->read_raw(parser, false); + return phreeqc_cookie->cleanup_after_parser(parser); + } + + entity_ptr->read_raw(parser, false); + entity_ptr->Set_n_user(nk.Get_n_user()); + entity_ptr->Set_n_user_end(nk.Get_n_user_end()); + entity_ptr->Set_description(nk.Get_description()); + s.insert(entity_ptr->Get_n_user()); + + return phreeqc_cookie->cleanup_after_parser(parser); + } template < typename T > void Rxn_mix(std::map &mix_map, std::map < int, T > &entity_map, Phreeqc * phreeqc_cookie) diff --git a/Pressure.cxx b/Pressure.cxx index b91249da..82e6735f 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -192,7 +192,7 @@ cxxPressure::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con } void -cxxPressure::read_raw(CParser & parser) +cxxPressure::read_raw(CParser & parser, bool check) { // clear steps for modify operation, if pressures are read bool cleared_once = false; @@ -294,17 +294,20 @@ cxxPressure::read_raw(CParser & parser) break; } // members that must be defined - if (equalIncrements_defined == false) + if (check) { - parser.incr_input_error(); - parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (count_defined == false) - { - parser.incr_input_error(); - parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", - PHRQ_io::OT_CONTINUE); + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Equal_increments not defined for REACTION_PRESSURE_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (count_defined == false) + { + parser.incr_input_error(); + parser.error_msg("Count_temps not defined for REACTION_PRESSURE_RAW input.", + PHRQ_io::OT_CONTINUE); + } } } #ifdef SKIP diff --git a/Pressure.h b/Pressure.h index 31e2ee38..7a6b7fd0 100644 --- a/Pressure.h +++ b/Pressure.h @@ -21,7 +21,7 @@ class cxxPressure:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; int read(CParser & parser); - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = false); LDBLE Pressure_for_step(int step_number); std::vector & Get_pressures(void) {return pressures;} const std::vector & Get_pressures(void)const {return pressures;} diff --git a/Temperature.cxx b/Temperature.cxx index bc5a5666..6b4102cb 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -229,7 +229,7 @@ cxxTemperature::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) } void -cxxTemperature::read_raw(CParser & parser) +cxxTemperature::read_raw(CParser & parser, bool check) { LDBLE d; CParser::TOKEN_TYPE k; @@ -335,21 +335,24 @@ cxxTemperature::read_raw(CParser & parser) break; } // members that must be defined - if (equalIncrements_defined == false) + if (check) { - parser.incr_input_error(); - parser. - error_msg - ("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", - PHRQ_io::OT_CONTINUE); - } - if (countTemps_defined == false) - { - parser.incr_input_error(); - parser. - error_msg - ("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", - PHRQ_io::OT_CONTINUE); + if (equalIncrements_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Equal_increments not defined for REACTION_TEMPERATURE_RAW input.", + PHRQ_io::OT_CONTINUE); + } + if (countTemps_defined == false) + { + parser.incr_input_error(); + parser. + error_msg + ("Count_temps not defined for REACTION_TEMPERATURE_RAW input.", + PHRQ_io::OT_CONTINUE); + } } } /* ---------------------------------------------------------------------- */ diff --git a/Temperature.h b/Temperature.h index f9d546c1..ed7e90d9 100644 --- a/Temperature.h +++ b/Temperature.h @@ -20,7 +20,7 @@ class cxxTemperature:public cxxNumKeyword void dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out=NULL) const; - void read_raw(CParser & parser); + void read_raw(CParser & parser, bool check = false); int read(CParser & parser); LDBLE Temperature_for_step(int step_number); std::vector & Get_temps(void) {return temps;} diff --git a/read.cpp b/read.cpp index 35dc0287..1121a52c 100644 --- a/read.cpp +++ b/read.cpp @@ -355,6 +355,9 @@ read_input(void) case Keywords::KEY_REACTION_MODIFY: Utilities::Rxn_read_modify(Rxn_reaction_map, Rxn_new_reaction, this); break; + case Keywords::KEY_REACTION_TEMPERATURE_MODIFY: + Utilities::Rxn_read_modify(Rxn_temperature_map, Rxn_new_temperature, this); + break; //case LAST_C_KEYWORD + 22: //reaction_temperature_modify // keyword[LAST_C_KEYWORD + 22].keycount++; // read_reaction_temperature_modify(); @@ -365,6 +368,9 @@ read_input(void) case Keywords::KEY_REACTION_PRESSURE_RAW: Utilities::Rxn_read_raw(Rxn_pressure_map, Rxn_new_pressure, this); break; + case Keywords::KEY_REACTION_PRESSURE_MODIFY: + Utilities::Rxn_read_modify(Rxn_pressure_map, Rxn_new_pressure, this); + break; default: error_msg("Error in keyword switch", STOP); break; From c9fb95a0d64bed616b4c51c41c461b817f9654a8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 7 Feb 2014 23:25:04 +0000 Subject: [PATCH 0789/1077] Tony's change to connecting graphs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8469 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartObject.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ChartObject.cpp b/ChartObject.cpp index 14e95fd5..826ca59b 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -401,6 +401,11 @@ ChartObject::Read(CParser & parser) /* End of modifications */ case 15: /* active */ this->active = parser.get_true_false(next_char, true); + if (this->active && this->Get_connect_simulations()) + { + this->ColumnOffset = 0;//this->Curves.size(); + this->new_ug = false; + } break; /* End of modifications */ case 16: /* batch */ From 4922f9efe0a29247ef3512b4e69081436fb7323d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 12 Feb 2014 17:26:54 +0000 Subject: [PATCH 0790/1077] Tony's fix for unequal cells in diffusion. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8484 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 55 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/transport.cpp b/transport.cpp index f4889805..4e1b9060 100644 --- a/transport.cpp +++ b/transport.cpp @@ -779,13 +779,14 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE dav, lav, mixf, maxmix, corr_disp, diffc_here, mD; + LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; int i, l_nmix; - std::vector m; + std::vector m, m1; for(i = 0; i < count_cells + 1; i++) { m.push_back(0); + m1.push_back(0); } if (multi_Dflag == TRUE) diffc_here = 0.0; @@ -806,6 +807,7 @@ init_mix(void) for (i = 1; i < count_cells; i++) { +// find mix with lower numbered cell... lav = (cell_data[i - 1].length + cell_data[i].length) / 2; if (ishift != 0) dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; @@ -813,8 +815,8 @@ init_mix(void) dav = 0; mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; - if (mixf > maxmix) - maxmix = mixf; + //if (mixf > maxmix) + // maxmix = mixf; m[i] = mixf; /* m[i] has mixf with lower cell */ if (multi_Dflag == TRUE) { @@ -822,6 +824,13 @@ init_mix(void) if (mD > maxmix) maxmix = mD; } + +// and with higher numbered cell... + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; + mf12 = m[i] + mixf; + if (mf12 > maxmix) + maxmix = mf12; + m1[i] = mixf; /* m1[i] has mixf with higher cell */ } /* * Also for boundary cells @@ -835,8 +844,9 @@ init_mix(void) dav = 0; mixf = (diffc_here * timest / lav + dav) / lav; - if (mixf > maxmix) - maxmix = mixf; + mf12 = m1[1] + 2 * mixf; + if (mf12 > maxmix) + maxmix = mf12; m[0] = 2 * mixf; if (multi_Dflag == TRUE) { @@ -857,9 +867,10 @@ init_mix(void) dav = 0; mixf = (diffc_here * timest / lav + dav) / lav; - if (mixf > maxmix) - maxmix = mixf; - m[count_cells] = 2 * mixf; + mf12 = m[count_cells - 1] + 2 * mixf; + if (mf12 > maxmix) + maxmix = mf12; + m1[count_cells] = 2 * mixf; if (multi_Dflag == TRUE) { mD = diffc_max * timest / (lav * lav); @@ -882,10 +893,7 @@ init_mix(void) } else { - if ((bcon_first == 1) || (bcon_last == 1)) - l_nmix = 1 + (int) floor(4.5 * maxmix); - else - l_nmix = 1 + (int) floor(3.0 * maxmix); + l_nmix = 1 + (int) floor(1.5 * maxmix); if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { @@ -896,7 +904,10 @@ init_mix(void) l_nmix = (int) ceil(l_nmix * mcd_substeps); for (i = 0; i <= count_cells; i++) + { m[i] /= l_nmix; + m1[i] /= l_nmix; + } } /* * Fill mix structure @@ -904,28 +915,16 @@ init_mix(void) if (l_nmix != 0) { -/* - * max_mix brings n_user outside range of active cells - * mix[n].n_user = mix[n].n_user_end = -999 has same effect - * but max_mix keeps mix in sort order in case mix_bsearch - * is used - */ for (i = 1; i <= count_cells; i++) { cxxMix temp_mix; - dav = 0; -/* - * again, max_mix brings n_user outside range of active cells, etc... - */ temp_mix.Set_n_user(i); temp_mix.Set_n_user_end(i); + temp_mix.Add(i - 1, m[i - 1]); + temp_mix.Add(i + 1, m1[i]); + temp_mix.Add(i, 1.0 - m[i - 1] - m1[i]); - dav += m[i - 1]; - temp_mix.Add(i + 1, m[i]); - - dav += m[i]; - temp_mix.Add(i, 1.0 - dav); Dispersion_mix_map[i] = temp_mix; } } From 01a54bdb7dadb93342017fde8ab84469d22e19fd Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 14 Feb 2014 07:15:24 +0000 Subject: [PATCH 0791/1077] added assert header file for MINGW-R git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8490 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PBasic.cpp b/PBasic.cpp index c40ec49d..ad5df860 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -4,6 +4,7 @@ #include "../../resource.h" #endif #else +#include #define _ASSERTE assert #endif #include From b5e86c636eb6e76337e7a575d77b581b13a3653a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Feb 2014 16:57:35 +0000 Subject: [PATCH 0792/1077] Do not dump negative entities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8502 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 6 +++++- ReadClass.cxx | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 3369bbf4..0b5565ed 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1971,7 +1971,11 @@ namespace Utilities typename T::const_iterator it; for (it = b.begin(); it != b.end(); ++it) { - it->second.dump_raw(s_oss, indent); + // Adding logic to dump only non-negative entities + if (it->second.Get_n_user() >= 0) + { + it->second.dump_raw(s_oss, indent); + } } return; } diff --git a/ReadClass.cxx b/ReadClass.cxx index 0dbed169..06dbb045 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -856,7 +856,7 @@ dump_ostream(std::ostream& os) for (it = dump_info.Get_solution().begin(); it != dump_info.Get_solution().end(); it++) { cxxSolution *p = Utilities::Rxn_find(Rxn_solution_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -878,7 +878,7 @@ dump_ostream(std::ostream& os) { cxxPPassemblage *p = Utilities::Rxn_find(Rxn_pp_assemblage_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -899,7 +899,7 @@ dump_ostream(std::ostream& os) { cxxExchange *p = Utilities::Rxn_find(Rxn_exchange_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -921,7 +921,7 @@ dump_ostream(std::ostream& os) { cxxSurface *p = Utilities::Rxn_find(Rxn_surface_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -942,7 +942,7 @@ dump_ostream(std::ostream& os) { cxxSSassemblage *p = Utilities::Rxn_find(Rxn_ss_assemblage_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -963,7 +963,7 @@ dump_ostream(std::ostream& os) { cxxGasPhase *p = Utilities::Rxn_find(Rxn_gas_phase_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -985,7 +985,7 @@ dump_ostream(std::ostream& os) { cxxKinetics *p = Utilities::Rxn_find(Rxn_kinetics_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -1006,7 +1006,7 @@ dump_ostream(std::ostream& os) { cxxMix *p = Utilities::Rxn_find(Rxn_mix_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -1028,7 +1028,7 @@ dump_ostream(std::ostream& os) { cxxReaction *p = Utilities::Rxn_find(Rxn_reaction_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -1050,7 +1050,7 @@ dump_ostream(std::ostream& os) { cxxTemperature *p = Utilities::Rxn_find(Rxn_temperature_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } @@ -1071,7 +1071,7 @@ dump_ostream(std::ostream& os) { cxxPressure *p = Utilities::Rxn_find(Rxn_pressure_map, *it); - if (p != NULL) + if (p != NULL && p->Get_n_user() >= 0) { p->dump_raw(os, 0); } From a59b8b7abfe163b614ea36c1e8d6e348962b4ca3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 24 Feb 2014 15:41:21 +0000 Subject: [PATCH 0793/1077] Tony's fix for MCD after unequal cell lengths for diffusion. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8518 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/transport.cpp b/transport.cpp index 4e1b9060..f8e000f7 100644 --- a/transport.cpp +++ b/transport.cpp @@ -826,11 +826,11 @@ init_mix(void) } // and with higher numbered cell... - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; - mf12 = m[i] + mixf; - if (mf12 > maxmix) - maxmix = mf12; - m1[i] = mixf; /* m1[i] has mixf with higher cell */ + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; + mf12 = m[i] + mixf; + if (mf12 > maxmix && !multi_Dflag) + maxmix = mf12; + m1[i] = mixf; /* m1[i] has mixf with higher cell */ } /* * Also for boundary cells @@ -845,7 +845,7 @@ init_mix(void) mixf = (diffc_here * timest / lav + dav) / lav; mf12 = m1[1] + 2 * mixf; - if (mf12 > maxmix) + if (mf12 > maxmix && !multi_Dflag) maxmix = mf12; m[0] = 2 * mixf; if (multi_Dflag == TRUE) @@ -868,11 +868,12 @@ init_mix(void) mixf = (diffc_here * timest / lav + dav) / lav; mf12 = m[count_cells - 1] + 2 * mixf; - if (mf12 > maxmix) + if (mf12 > maxmix && !multi_Dflag) maxmix = mf12; m1[count_cells] = 2 * mixf; if (multi_Dflag == TRUE) { + m[count_cells] = 2 * mixf; mD = diffc_max * timest / (lav * lav); if (mD > maxmix) maxmix = mD; @@ -893,8 +894,17 @@ init_mix(void) } else { - l_nmix = 1 + (int) floor(1.5 * maxmix); - + if (!multi_Dflag) + { + l_nmix = 1 + (int) floor(1.5 * maxmix); + } + else + { + if ((bcon_first == 1) || (bcon_last == 1)) + l_nmix = 1 + (int) floor(4.5 * maxmix); + else + l_nmix = 1 + (int) floor(3.0 * maxmix); + } if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { if (l_nmix < 2) @@ -922,9 +932,16 @@ init_mix(void) temp_mix.Set_n_user_end(i); temp_mix.Add(i - 1, m[i - 1]); + if (multi_Dflag) + { + temp_mix.Add(i + 1, m[i]); + temp_mix.Add(i, 1.0 - m[i - 1] - m[i]); + } + else + { temp_mix.Add(i + 1, m1[i]); temp_mix.Add(i, 1.0 - m[i - 1] - m1[i]); - + } Dispersion_mix_map[i] = temp_mix; } } From e284f1167e46b7d8f6714ee3131bd97d21684610 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 24 Feb 2014 19:35:03 +0000 Subject: [PATCH 0794/1077] Next fix for MCD git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8520 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 277 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 169 insertions(+), 108 deletions(-) diff --git a/transport.cpp b/transport.cpp index f8e000f7..cffdacb0 100644 --- a/transport.cpp +++ b/transport.cpp @@ -788,13 +788,6 @@ init_mix(void) m.push_back(0); m1.push_back(0); } - if (multi_Dflag == TRUE) - diffc_here = 0.0; - else - diffc_here = diffc_tr; -/* - * Define mixing factors among inner cells - */ corr_disp = 1.; if (correct_disp == TRUE && ishift != 0) { @@ -804,99 +797,72 @@ init_mix(void) corr_disp += 1. / count_cells; } maxmix = 0.0; - - for (i = 1; i < count_cells; i++) + if (multi_Dflag) { -// find mix with lower numbered cell... - lav = (cell_data[i - 1].length + cell_data[i].length) / 2; - if (ishift != 0) - dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; - //if (mixf > maxmix) - // maxmix = mixf; - m[i] = mixf; /* m[i] has mixf with lower cell */ - if (multi_Dflag == TRUE) + for (i = 1; i < count_cells; i++) { + lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + if (ishift != 0) + dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + else + dav = 0; + mixf = dav * corr_disp / cell_data[i].length; + if (mixf > maxmix) + maxmix = mixf; + m[i] = mixf; /* m[i] has mixf with lower cell */ mD = diffc_max * timest / (lav * lav); if (mD > maxmix) maxmix = mD; } - -// and with higher numbered cell... - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; - mf12 = m[i] + mixf; - if (mf12 > maxmix && !multi_Dflag) - maxmix = mf12; - m1[i] = mixf; /* m1[i] has mixf with higher cell */ - } /* * Also for boundary cells */ - if (bcon_first == 1) - { - lav = cell_data[0].length; - if (ishift != 0) - dav = cell_data[0].disp; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) / lav; - mf12 = m1[1] + 2 * mixf; - if (mf12 > maxmix && !multi_Dflag) - maxmix = mf12; - m[0] = 2 * mixf; - if (multi_Dflag == TRUE) + if (bcon_first == 1) { + lav = cell_data[0].length; + if (ishift != 0) + dav = cell_data[0].disp; + else + dav = 0; + + mixf = dav / lav; + if (mixf > maxmix) + maxmix = mixf; + m[0] = 2 * mixf; mD = diffc_max * timest / (lav * lav); if (mD > maxmix) maxmix = mD; } - } - else - m[0] = 0; - - if (bcon_last == 1) - { - lav = cell_data[count_cells - 1].length; - if (ishift != 0) - dav = cell_data[count_cells - 1].disp; else - dav = 0; + m[0] = 0; - mixf = (diffc_here * timest / lav + dav) / lav; - mf12 = m[count_cells - 1] + 2 * mixf; - if (mf12 > maxmix && !multi_Dflag) - maxmix = mf12; - m1[count_cells] = 2 * mixf; - if (multi_Dflag == TRUE) + if (bcon_last == 1) { + lav = cell_data[count_cells - 1].length; + if (ishift != 0) + dav = cell_data[count_cells - 1].disp; + else + dav = 0; + + mixf = dav / lav; + if (mixf > maxmix) + maxmix = mixf; m[count_cells] = 2 * mixf; mD = diffc_max * timest / (lav * lav); if (mD > maxmix) maxmix = mD; } - } - else - m[count_cells] = 0; + else + m[count_cells] = 0; /* * Find number of mixes */ - if (maxmix == 0) - { - l_nmix = 0; - if (multi_Dflag == TRUE && mcd_substeps > 1 - && stag_data->count_stag > 0) - l_nmix = (int) ceil(mcd_substeps); - } - else - { - if (!multi_Dflag) + if (maxmix == 0) { - l_nmix = 1 + (int) floor(1.5 * maxmix); + l_nmix = 0; + if (mcd_substeps > 1 && stag_data->count_stag > 0) + l_nmix = (int) ceil(mcd_substeps); } else { @@ -904,48 +870,143 @@ init_mix(void) l_nmix = 1 + (int) floor(4.5 * maxmix); else l_nmix = 1 + (int) floor(3.0 * maxmix); - } - if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) - { - if (l_nmix < 2) - l_nmix = 2; - } - if (multi_Dflag == TRUE && mcd_substeps > 1) - l_nmix = (int) ceil(l_nmix * mcd_substeps); - for (i = 0; i <= count_cells; i++) - { - m[i] /= l_nmix; - m1[i] /= l_nmix; - } - } - /* - * Fill mix structure - */ - - if (l_nmix != 0) - { - for (i = 1; i <= count_cells; i++) - { - cxxMix temp_mix; - temp_mix.Set_n_user(i); - temp_mix.Set_n_user_end(i); - - temp_mix.Add(i - 1, m[i - 1]); - if (multi_Dflag) + if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { + if (l_nmix < 2) + l_nmix = 2; + } + if (mcd_substeps > 1) + l_nmix = (int) ceil(l_nmix * mcd_substeps); + + for (i = 0; i <= count_cells; i++) + m[i] /= l_nmix; + } +/* + * Fill mix structure + */ + + if (l_nmix != 0) + { + for (i = 1; i <= count_cells; i++) + { + cxxMix temp_mix; + temp_mix.Set_n_user(i); + temp_mix.Set_n_user_end(i); + + temp_mix.Add(i - 1, m[i - 1]); temp_mix.Add(i + 1, m[i]); temp_mix.Add(i, 1.0 - m[i - 1] - m[i]); + Dispersion_mix_map[i] = temp_mix; } - else - { - temp_mix.Add(i + 1, m1[i]); - temp_mix.Add(i, 1.0 - m[i - 1] - m1[i]); - } - Dispersion_mix_map[i] = temp_mix; } + return (l_nmix); + } + else // multi_D false + { + diffc_here = diffc_tr; +/* + * Define mixing factors among inner cells + */ + for (i = 1; i < count_cells; i++) + { +// find mix with lower numbered cell... + lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + if (ishift != 0) + dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; + m[i] = mixf; /* m[i] has mixf with lower cell */ + +// and with higher numbered cell... + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; + mf12 = m[i] + mixf; + if (mf12 > maxmix) + maxmix = mf12; + m1[i] = mixf; /* m1[i] has mixf with higher cell */ + } +/* + * Also for boundary cells + */ + if (bcon_first == 1) + { + lav = cell_data[0].length; + if (ishift != 0) + dav = cell_data[0].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + mf12 = m1[1] + 2 * mixf; + if (mf12 > maxmix) + maxmix = mf12; + m[0] = 2 * mixf; + } + else + m[0] = 0; + + if (bcon_last == 1) + { + lav = cell_data[count_cells - 1].length; + if (ishift != 0) + dav = cell_data[count_cells - 1].disp; + else + dav = 0; + + mixf = (diffc_here * timest / lav + dav) / lav; + mf12 = m[count_cells - 1] + 2 * mixf; + if (mf12 > maxmix && !multi_Dflag) + maxmix = mf12; + m1[count_cells] = 2 * mixf; + } + else + m[count_cells] = 0; + +/* + * Find number of mixes + */ + if (maxmix == 0) + { + l_nmix = 0; + } + else + { + l_nmix = 1 + (int) floor(1.5 * maxmix); + + if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) + { + if (l_nmix < 2) + l_nmix = 2; + } + + for (i = 0; i <= count_cells; i++) + { + m[i] /= l_nmix; + m1[i] /= l_nmix; + } + } + /* + * Fill mix structure + */ + + if (l_nmix != 0) + { + for (i = 1; i <= count_cells; i++) + { + cxxMix temp_mix; + temp_mix.Set_n_user(i); + temp_mix.Set_n_user_end(i); + + temp_mix.Add(i - 1, m[i - 1]); + temp_mix.Add(i + 1, m1[i]); + temp_mix.Add(i, 1.0 - m[i - 1] - m1[i]); + Dispersion_mix_map[i] = temp_mix; + } + } + return (l_nmix); } - return (l_nmix); } /* ---------------------------------------------------------------------- */ int Phreeqc:: From 38bfd3328b251c13867227f8b5b48cc317c5bf2e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 28 Feb 2014 15:33:20 +0000 Subject: [PATCH 0795/1077] Modification to use REACTION_PRESSURE for a fixed-pressure gas phase. Fixed Basic function GAS_VM for a fixed-pressure gas phase. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8532 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 11 ++++++----- step.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 3d0c10c5..f53cb6b9 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -922,9 +922,13 @@ find_gas_vm(void) return (0); if (gas_unknown->moles < 1e-12) return (0); + gas_phase_ptr->Set_total_moles(gas_unknown->moles); + gas_phase_ptr->Set_volume(gas_phase_ptr->Get_total_moles() * R_LITER_ATM * tk_x / + gas_phase_ptr->Get_total_p()); + if (gas_phase_ptr->Get_v_m() >= 0.01) + gas_phase_ptr->Set_volume(gas_phase_ptr->Get_v_m() * gas_unknown->moles); } - // also for non-PR gas phases... - return (gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles()); + return gas_phase_ptr->Get_volume() / gas_phase_ptr->Get_total_moles(); } /* ---------------------------------------------------------------------- */ @@ -3593,9 +3597,6 @@ void Phreeqc:: basic_free(void) { delete this->basic_interpreter; - - // Reset pointer to make sure we cannot attempt to free it twice (which obviously will result in a crash) - this->basic_interpreter = 0; } double Phreeqc:: diff --git a/step.cpp b/step.cpp index d8ee1d15..edf38fad 100644 --- a/step.cpp +++ b/step.cpp @@ -1211,6 +1211,13 @@ gas_phase_check(cxxGasPhase *gas_phase_ptr) if (gas_phase_ptr == NULL) return (OK); +// set gas pressure to reaction_pressure... + if (use.Get_pressure_ptr() != NULL && gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) + { + gas_phase_ptr->Set_total_p(patm_x); + k_temp(tc_x, patm_x); + } + /* * Check that all elements are in solution for phases with zero mass */ From c43019c4963ec9b5cc0bf470d6fa19cf9b112760 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 28 Feb 2014 21:29:53 +0000 Subject: [PATCH 0796/1077] Roughing in mcd capability. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8536 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 1 + Solution.h | 2 ++ mainsubs.cpp | 8 ++++++++ 4 files changed, 13 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 4b97fd9a..19093da5 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -389,6 +389,7 @@ void Phreeqc::init(void) *---------------------------------------------------------------------- */ // auto Rxn_solution_map; // auto unnumbered_solutions; + save_species = false; /*---------------------------------------------------------------------- * Global solution *---------------------------------------------------------------------- */ @@ -1274,6 +1275,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) * Solution *---------------------------------------------------------------------- */ Rxn_solution_map = pSrc->Rxn_solution_map; + save_species = pSrc->save_species; // auto Rxn_solution_map; // auto unnumbered_solutions; /*---------------------------------------------------------------------- diff --git a/Phreeqc.h b/Phreeqc.h index 0b5565ed..2cc289f6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1302,6 +1302,7 @@ protected: *---------------------------------------------------------------------- */ std::map Rxn_solution_map; std::vector unnumbered_solutions; + bool save_species; /*---------------------------------------------------------------------- * Global solution diff --git a/Solution.h b/Solution.h index f20d8d74..580950d3 100644 --- a/Solution.h +++ b/Solution.h @@ -62,6 +62,7 @@ class cxxSolution:public cxxNumKeyword } cxxNameDouble & Get_master_activity(void) {return this->master_activity;} cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;} + std::map & Get_species_map(void) {return this->species_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;} @@ -132,6 +133,7 @@ class cxxSolution:public cxxNumKeyword std::map < std::string, cxxSolutionIsotope > isotopes; cxxISolution *initial_data; const static std::vector < std::string > vopts; + std::map species_map; }; #endif // !defined(SOLUTION_H_INCLUDED) diff --git a/mainsubs.cpp b/mainsubs.cpp index a678e162..30016eff 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1594,6 +1594,14 @@ xsolution_save(int n_user) } } #endif + if (this->save_species) + { + temp_solution.Get_species_map().clear(); + for (int i = 0; i < this->count_s_x; i++) + { + temp_solution.Get_species_map()[s_x[i]->number] = s_x[i]->moles; + } + } /* * Save solution */ From 3f0cd06d6ed43fcdbb044e19433135b030719e0e Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 1 Mar 2014 07:31:56 +0000 Subject: [PATCH 0797/1077] Added Peng/Robinson gas parameters and molar volume for solids to keyword PHASES git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8538 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 2 +- read.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/global_structures.h b/global_structures.h index d36d8834..6a1402fc 100644 --- a/global_structures.h +++ b/global_structures.h @@ -160,7 +160,7 @@ // Typedefs and structure definitions // typedef enum { kcal, cal, kjoules, joules } DELTA_H_UNIT; -typedef enum { cm3_per_mol } DELTA_V_UNIT; +typedef enum { cm3_per_mol, dm3_per_mol, m3_per_mol } DELTA_V_UNIT; enum entity_type { Solution, Reaction, Exchange, Surface, Gas_phase, Pure_phase, Ss_phase, Kinetics, Mix, Temperature, Pressure, UnKnown diff --git a/read.cpp b/read.cpp index 1121a52c..1f7fd1b7 100644 --- a/read.cpp +++ b/read.cpp @@ -2987,11 +2987,13 @@ read_phase_vm(char *ptr, LDBLE * delta_v, DELTA_V_UNIT * units) { /* Convert dm3/mol to cm3/mol */ factor = 1e3; + *units = dm3_per_mol; } else if (strstr(token, "m3") != NULL) { /* Convert m3/mol to cm3/mol */ factor = 1e6; + *units = m3_per_mol; } for (int i = 0; i < 1; i++) From f10f51371644a760be71a74b672b6f799f18decc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 4 Mar 2014 20:08:26 +0000 Subject: [PATCH 0798/1077] Save only aqueous species in phreeqc species_map. Added species_map to copy operator made mg/L default for Solution.cxx default species_save_on is false. Added some defaults to documentation added species_cpp test. bug in species_utility_cpp.txt git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8543 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 16 ++++++++++++++++ mainsubs.cpp | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index 81a7aed7..e9621d0f 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -78,6 +78,7 @@ cxxSolution::operator =(const cxxSolution &rhs) this->master_activity = rhs.master_activity; this->species_gamma = rhs.species_gamma; this->isotopes = rhs.isotopes; + this->species_map = rhs.species_map; if (this->initial_data) delete initial_data; if (rhs.initial_data != NULL) @@ -1279,6 +1280,21 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->master_activity.add_log_activities(addee.master_activity, f1, f2); this->species_gamma.add_intensive(addee.species_gamma, f1, f2); this->Add_isotopes(addee.isotopes, f2, extensive); + { + // Add species + std::map::const_iterator it = addee.species_map.begin(); + for ( ; it != addee.species_map.end(); it++) + { + if (this->species_map.find(it->first) != this->species_map.end()) + { + this->species_map[it->first] = this->species_map[it->first] * f1 + it->second * f2; + } + else + { + this->species_map[it->first] = it->second; + } + } + } } void diff --git a/mainsubs.cpp b/mainsubs.cpp index 30016eff..c3835538 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1596,10 +1596,14 @@ xsolution_save(int n_user) #endif if (this->save_species) { + // saves mol/L temp_solution.Get_species_map().clear(); for (int i = 0; i < this->count_s_x; i++) { - temp_solution.Get_species_map()[s_x[i]->number] = s_x[i]->moles; + if (s_x[i]->type <= H2O) + { + temp_solution.Get_species_map()[s_x[i]->number] = s_x[i]->moles / temp_solution.Get_soln_vol(); + } } } /* From c843de8fb0892b1565e9922c1356c897415eac83 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 13 Mar 2014 01:06:32 +0000 Subject: [PATCH 0799/1077] Got all Tests working with MPI except the units tester. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8556 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index e9621d0f..da1a4561 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -295,6 +295,19 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << "-gammas" << "\n"; this->species_gamma.dump_raw(s_oss, indent + 2); + // species_map + if (species_map.size() > 0) + { + s_oss << indent1; + s_oss << "-species_map" << "\n"; + std::map::const_iterator it = this->species_map.begin(); + for ( ; it != species_map.end(); it++) + { + s_oss << indent2; + s_oss << it->first << " " << it->second << "\n"; + } + } + return; } @@ -917,6 +930,33 @@ cxxSolution::read_raw(CParser & parser, bool check) } opt_save = CParser::OPT_DEFAULT; break; + + case 24: // species_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 concentration.", + PHRQ_io::OT_CONTINUE); + } + this->species_map[s_num] = d; + } + } + opt_save = 24; + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -1445,6 +1485,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("charge_balance"), // 20 std::vector< std::string >::value_type("density"), // 21 std::vector< std::string >::value_type("pressure"), // 22 - std::vector< std::string >::value_type("soln_vol") // 23 + std::vector< std::string >::value_type("soln_vol"), // 23 + std::vector< std::string >::value_type("species_map") // 24 }; const std::vector< std::string > cxxSolution::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file From 78a273ebe25f65fe081d146897d7fb5c97cad574 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 17 Mar 2014 22:34:03 +0000 Subject: [PATCH 0800/1077] All IPhreeqc checks passing on windows git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8564 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 2ecd3d98..46c9bb85 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -300,24 +300,28 @@ tidy_model(void) /* * make sure essential species are defined */ - if (new_model) + //if (new_model) { if (s_h2o == NULL) { input_error++; - error_msg("H2O not defined.", STOP); + //error_msg("H2O not defined.", STOP); + error_msg("H2O not defined.", CONTINUE); } - if (s_h2o->primary == NULL) + else { - input_error++; - error_msg("H2O, primary master species for O, not defined.", - CONTINUE); - } - if (s_h2o->secondary == NULL) - { - input_error++; - error_msg("H2O, secondary master species for O(-2), not defined.", - CONTINUE); + if (s_h2o->primary == NULL) + { + input_error++; + error_msg("H2O, primary master species for O, not defined.", + CONTINUE); + } + if (s_h2o->secondary == NULL) + { + input_error++; + error_msg("H2O, secondary master species for O(-2), not defined.", + CONTINUE); + } } if (s_hplus == NULL && s_h3oplus == NULL) { From 47eec62e40cfaeef572b7de123130e07e6665f8d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Mar 2014 21:19:11 +0000 Subject: [PATCH 0801/1077] Redefinition of Pitzer parameter was bad wrong. First exchange and surface species were included in lists. Second, a map used to lookup the pitzer parameter number got out of date when tidy_pitzer was called. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8576 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pitzer.cpp b/pitzer.cpp index 06b5cc0f..1daf5c10 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -109,6 +109,8 @@ pitzer_tidy(void) continue; if (s[i] == s_h2o) continue; + if (s[i]->type == EX || s[i]->type == SURF) + continue; if (s[i]->z < -.001) { anions[count_anions++] = s[i]; @@ -538,6 +540,28 @@ pitzer_tidy(void) } } */ + /* remake map */ + { + pitz_param_map.clear(); + for (size_t j = 0; j < count_pitz_param; j++) + { + std::set< std::string > header; + for (int i = 0; i < 3; i++) + { + if (pitz_params[j]->species[i] != NULL) header.insert(pitz_params[j]->species[i]); + } + std::ostringstream key_str; + key_str << pitz_params[j]->type << " "; + std::set< std::string >::iterator it = header.begin(); + for(; it != header.end(); ++it) + { + key_str << *it << " "; + } + std::string key = key_str.str().c_str(); + pitz_param_map[key] = j; + } + assert ((int) pitz_param_map.size() == count_pitz_param); + } return OK; } From 7359b9dcb645daaeebdacf7149d40134db2866be Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 21 Mar 2014 00:00:00 +0000 Subject: [PATCH 0802/1077] changed input_units_* to units_*. thru GetMpiTasks Changed GetIPhreeqcId to GetIPhreeqcPointer added to tests RM_GetIPhreeqcId git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8586 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 2 +- sit.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pitzer.cpp b/pitzer.cpp index 1daf5c10..ffd52db0 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -543,7 +543,7 @@ pitzer_tidy(void) /* remake map */ { pitz_param_map.clear(); - for (size_t j = 0; j < count_pitz_param; j++) + for (int j = 0; j < count_pitz_param; j++) { std::set< std::string > header; for (int i = 0; i < 3; i++) diff --git a/sit.cpp b/sit.cpp index 734bb3d2..df3897e8 100644 --- a/sit.cpp +++ b/sit.cpp @@ -73,6 +73,8 @@ sit_tidy(void) continue; if (s[i] == s_h2o) continue; + if (s[i]->type == EX || s[i]->type == SURF) + continue; if (s[i]->z < -.001) { anions[sit_count_anions++] = s[i]; @@ -112,6 +114,27 @@ sit_tidy(void) error_msg(error_string, CONTINUE); } } + } /* remake map */ + { + sit_param_map.clear(); + for (int j = 0; j < count_sit_param; j++) + { + std::set< std::string > header; + for (int i = 0; i < 3; i++) + { + if (sit_params[j]->species[i] != NULL) header.insert(sit_params[j]->species[i]); + } + std::ostringstream key_str; + key_str << sit_params[j]->type << " "; + std::set< std::string >::iterator it = header.begin(); + for(; it != header.end(); ++it) + { + key_str << *it << " "; + } + std::string key = key_str.str().c_str(); + sit_param_map[key] = j; + } + assert ((int) sit_param_map.size() == count_sit_param); } if (get_input_errors() > 0) return (ERROR); return OK; From 7c0b1106aa9d307a5704d55a271ddc6d5c98acf7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 5 Apr 2014 04:14:16 +0000 Subject: [PATCH 0803/1077] first pass @ removing std::cerr, std::cout, exit, stderr, stdout from R version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8619 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 10 ++++++++++ PHRQ_io.cpp | 16 +++++++++++++--- PHRQ_io_output.cpp | 16 ++++++++++++++++ Parser.cxx | 6 ++++++ cvode.cpp | 15 ++++++++++++++- cvode.h | 2 ++ kinetics.cpp | 8 ++++++++ 7 files changed, 69 insertions(+), 4 deletions(-) diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx index 63599c8e..0e07d1f0 100644 --- a/PHRQ_base.cxx +++ b/PHRQ_base.cxx @@ -35,8 +35,10 @@ error_msg(const std::string & stdstr, int stop) } else { +#if !defined(R_SO) std::cerr << msg.str().c_str(); std::cout << msg.str().c_str(); +#endif } if (stop != 0) { @@ -53,8 +55,10 @@ warning_msg(const std::string & stdstr) } else { +#if !defined(R_SO) std::cerr << stdstr << "\n"; std::cout << stdstr << "\n"; +#endif } } @@ -67,7 +71,9 @@ output_msg(const std::string & stdstr) } else { +#if !defined(R_SO) std::cout << stdstr << "\n"; +#endif } } @@ -80,7 +86,9 @@ screen_msg(const std::string & stdstr) } else { +#if !defined(R_SO) std::cerr << stdstr << "\n"; +#endif } } @@ -93,6 +101,8 @@ echo_msg(const std::string & stdstr) } else { +#if !defined(R_SO) std::cout << stdstr << "\n"; +#endif } } \ No newline at end of file diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 8db0e8fa..40a7639c 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -177,13 +177,17 @@ error_open(const char *file_name, std::ios_base::openmode mode) { if (!ofstream_open(&error_ostream, file_name, mode)) { +#if !defined(R_SO) error_ostream = &std::cerr; +#endif return false; } } else { +#if !defined(R_SO) error_ostream = &std::cerr; +#endif } return true; } @@ -572,9 +576,12 @@ void PHRQ_io:: safe_close(std::ostream **stream_ptr) /* ---------------------------------------------------------------------- */ { - if (*stream_ptr != &std::cerr && + if ( +#if !defined(R_SO) + *stream_ptr != &std::cerr && *stream_ptr != &std::cout && *stream_ptr != &std::clog && +#endif *stream_ptr != NULL) { delete *stream_ptr; @@ -585,10 +592,13 @@ void PHRQ_io:: safe_close(FILE **file_ptr) /* ---------------------------------------------------------------------- */ { - if (*file_ptr != NULL && + if ( +#if !defined(R_SO) *file_ptr != stderr && *file_ptr != stdout && - *file_ptr != stdin ) + *file_ptr != stdin && +#endif + *file_ptr != NULL) { fclose(*file_ptr); *file_ptr = NULL; diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index dd7db7b7..7db054a3 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -207,7 +207,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, try { if (phrq_io == NULL) { +#if !defined(R_SO) std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; +#endif } /* * Prep for get_line @@ -404,7 +406,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, try { if (phrq_io == NULL) { +#if !defined(R_SO) std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; +#endif } /* * Prep for get_line @@ -599,10 +603,12 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, strcpy(name, default_name); if (!batch ) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') @@ -623,10 +629,12 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, new_stream = new std::ifstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); @@ -674,10 +682,12 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode strcpy(name, default_name); if (!batch ) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif screen_msg(sformatf("%s\n", query)); @@ -699,10 +709,12 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode new_stream = new std::ofstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); @@ -747,10 +759,12 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, strcpy(name, default_name); if (!batch ) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') @@ -771,10 +785,12 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, new_stream = new std::ofstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { +#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); +#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); diff --git a/Parser.cxx b/Parser.cxx index 33281f81..97a86208 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -651,7 +651,9 @@ CParser::get_option(const std::vector < std::string > &opt_list, std::string::iterator opt_ptr; std::string option; +#if !defined(R_SO) fprintf(stderr, "Did not think this get_option was called\n"); +#endif // // Read line // @@ -728,7 +730,9 @@ CParser::get_option(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { +#if !defined(R_SO) std::cout << "\t" << m_line_save << "\n"; +#endif } } } @@ -1098,7 +1102,9 @@ CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, { if (true) // database_file == NULL { +#if !defined(R_SO) std::cout << "\t" << m_line_save << "\n"; +#endif } } } diff --git a/cvode.cpp b/cvode.cpp index d52617d8..ad0d4b0f 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -516,12 +516,16 @@ CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, booleantype allocOK, ioptExists, roptExists, neg_abstol, ewtsetOK; int maxord; CVodeMem cv_mem; +#if !defined(R_SO) FILE *fp; +#endif int i, k; /* Check for legal input parameters */ +#if !defined(R_SO) fp = (errfp == NULL) ? stdout : errfp; +#endif if (y0 == NULL) { @@ -659,7 +663,9 @@ CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, cv_mem->cv_optIn = optIn; cv_mem->cv_iopt = iopt; cv_mem->cv_ropt = ropt; +#if !defined(R_SO) cv_mem->cv_errfp = fp; +#endif tn = t0; machenv = machEnv; @@ -789,11 +795,14 @@ CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, booleantype ioptExists, roptExists, neg_abstol, ewtsetOK; int maxord, i, k; CVodeMem cv_mem; +#if !defined(R_SO) FILE *fp; - +#endif /* Check for legal input parameters */ +#if !defined(R_SO) fp = (errfp == NULL) ? stdout : errfp; +#endif if (cvode_mem == NULL) { @@ -916,7 +925,9 @@ CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, cv_mem->cv_optIn = optIn; cv_mem->cv_iopt = iopt; cv_mem->cv_ropt = ropt; +#if !defined(R_SO) cv_mem->cv_errfp = fp; +#endif tn = t0; machenv = machEnv; @@ -3079,7 +3090,9 @@ CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, CVMEM warning_msg("CVDoErrorTest"); /*exit(8); */ CVMEM error_msg("CVDoErrorTest", 1 /* STOP */ ); +#if !defined(R_SO) exit(4); +#endif } nfe++; N_VScale(h, tempv, zn[1]); diff --git a/cvode.h b/cvode.h index fdbe25ae..c7c68b71 100644 --- a/cvode.h +++ b/cvode.h @@ -706,7 +706,9 @@ /* Error File */ +#if !defined(R_SO) FILE *cv_errfp; /* CVODE error messages are sent to errfp */ +#endif /* Pointer to Machine Environment-Specific Information */ diff --git a/kinetics.cpp b/kinetics.cpp index d1101307..9ab60fe1 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -247,7 +247,11 @@ RESTART: // if limiting rates, jump to here } if (count > 2) { +#if !defined(R_SO) fprintf(stderr, "Too many limit_rates-.\n"); +#else + error_msg("Too many limit_rates-.\n"); +#endif } else { @@ -256,7 +260,11 @@ RESTART: // if limiting rates, jump to here } if (count > 2) { +#if !defined(R_SO) fprintf(stderr, "Too many limit_rates+.\n"); +#else + error_msg("Too many limit_rates+.\n"); +#endif } return (OK); } From 3abc37a82de6c2ec8dbfbcc3feaf2aba73223071 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 5 Apr 2014 04:50:54 +0000 Subject: [PATCH 0804/1077] replaced putchar('\n') with output_msg("\n") in PBasic.cpp (reqd for R) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8621 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index ad5df860..e8ec9a99 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -133,7 +133,8 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } else { - putchar('\n'); + /* putchar('\n');*/ + output_msg("\n"); } } } @@ -213,7 +214,8 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) } else { - putchar('\n'); + /* putchar('\n');*/ + output_msg("\n"); } } } @@ -284,7 +286,8 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } else { - putchar('\n'); + /* putchar('\n');*/ + output_msg("\n"); } } } @@ -352,7 +355,8 @@ basic_main(char *commands) } else { - putchar('\n'); + /* putchar('\n');*/ + output_msg("\n"); } } } From 0030e8dafd2e2cf6ee0ec46648370e275c27b0e7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 5 Apr 2014 05:23:11 +0000 Subject: [PATCH 0805/1077] replaced printf(...) with output_msg(PhreeqcPtr->sformatf(...)) req'd for R. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8622 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index e8ec9a99..85a86ab8 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -4063,7 +4063,8 @@ cmdload(bool merging, char * name, struct LOC_exec *LINK) parseinput(&l_buf); if (curline == 0) { - printf("Bad line in file\n"); + /* printf("Bad line in file\n"); */ + output_msg("Bad line in file\n"); disposetokens(&l_buf); } } @@ -4359,8 +4360,9 @@ cmdrenum(struct LOC_exec *LINK) l1 = l1->next; if (l1 == NULL) { - printf("Undefined line %ld in line %ld\n", lnum, - l->num2); + /* printf("Undefined line %ld in line %ld\n", lnum, + l->num2); */ + output_msg(PhreeqcPtr->sformatf("Undefined line %ld in line %ld\n", lnum, l->num2)); } else { From de0ec2ad7568854386c19ba4ec19e3bc7f4395ce Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Apr 2014 15:06:20 +0000 Subject: [PATCH 0806/1077] Fixed bug with redefinition of sit parameters git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8627 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer_structures.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index f433d241..b655985c 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -232,13 +232,16 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy) { if (pzp_ptr->species[i] != NULL) header.insert(pzp_ptr->species[i]); } - std::string key; + + std::ostringstream key_str; + key_str << pzp_ptr->type << " "; std::set< std::string >::iterator it = header.begin(); for(; it != header.end(); ++it) { - key += (*it); - key += " "; + key_str << *it << " "; } + std::string key = key_str.str().c_str(); + std::map< std::string, size_t>::iterator jit = sit_param_map.find(key); if (jit != sit_param_map.end()) { From 3945c0d78e80c6ca4a111aaafb3a5373c2a50ad5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Apr 2014 14:43:24 +0000 Subject: [PATCH 0807/1077] bug in writing error, loop limit used wrong counter. (PhreeqcRM.cpp) Saturation was not set correctly (phast_manager.F90) Added OLD_STYLE_XYZ to configuration for debug (phreeqcpp.vcxproj) Basic function equiv_frac was not handled. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8653 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 85a86ab8..29df29b8 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -6778,7 +6778,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("species_formula", PBasic::tokspecies_formula), std::map::value_type("species_formula$", PBasic::tokspecies_formula_), std::map::value_type("eq_frac", PBasic::tokeq_frac), - std::map::value_type("equiv_frac", PBasic::tokequiv_frac), + std::map::value_type("equiv_frac", PBasic::tokeq_frac), std::map::value_type("callback", PBasic::tokcallback) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); From 53e3bd59e6c4263075351eb67f77dd8ddf0da182 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Apr 2014 22:55:59 +0000 Subject: [PATCH 0808/1077] Moved uz_bin to workers to avoid possible data conflicts. PartitionUZ updated Added TransferCellsUZ Added Add(src_bin, n) to StorageBin Need to document partitioning. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8658 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- StorageBin.cxx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ StorageBin.h | 2 +- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/StorageBin.cxx b/StorageBin.cxx index 96df5128..efe3ffb2 100644 --- a/StorageBin.cxx +++ b/StorageBin.cxx @@ -117,6 +117,75 @@ cxxStorageBin::~cxxStorageBin() { } void +cxxStorageBin::Add(cxxStorageBin &src, int n) +{ + // Solution + if (src.Get_Solution(n) != NULL) + { + this->Set_Solution(n, src.Get_Solution(n)); + } + + // Exchange + if (src.Get_Exchange(n) != NULL) + { + this->Set_Exchange(n, src.Get_Exchange(n)); + } + + // gas_phase + if (src.Get_GasPhase(n) != NULL) + { + this->Set_GasPhase(n, src.Get_GasPhase(n)); + } + + // kinetics + if (src.Get_Kinetics(n) != NULL) + { + this->Set_Kinetics(n, src.Get_Kinetics(n)); + } + + // pp_assemblage + if (src.Get_PPassemblage(n) != NULL) + { + this->Set_PPassemblage(n, src.Get_PPassemblage(n)); + } + + // ss_assemblage + if (src.Get_SSassemblage(n) != NULL) + { + this->Set_SSassemblage(n, src.Get_SSassemblage(n)); + } + + // surface + if (src.Get_Surface(n) != NULL) + { + this->Set_Surface(n, src.Get_Surface(n)); + } + + // mix + if (src.Get_Mix(n) != NULL) + { + this->Set_Mix(n, src.Get_Mix(n)); + } + + // reaction + if (src.Get_Reaction(n) != NULL) + { + this->Set_Reaction(n, src.Get_Reaction(n)); + } + + // reaction temperature + if (src.Get_Temperature(n) != NULL) + { + this->Set_Temperature(n, src.Get_Temperature(n)); + } + + // reaction pressure + if (src.Get_Pressure(n) != NULL) + { + this->Set_Pressure(n, src.Get_Pressure(n)); + } +} +void cxxStorageBin::Copy(int destination, int source) { if (destination == source) diff --git a/StorageBin.h b/StorageBin.h index 3d70c167..cf83d7f7 100644 --- a/StorageBin.h +++ b/StorageBin.h @@ -98,7 +98,7 @@ class cxxStorageBin: public PHRQ_base void read_raw(CParser & parser); int read_raw_keyword(CParser & parser); - //void add(struct system *sys_ptr); + void Add(cxxStorageBin &src, int n); //cxxSolution *mix_cxxSolutions(cxxMix &mixmap); cxxExchange *mix_cxxExchange(cxxMix & mixmap); From 112feb81b9fffc7d32db146031b62173a9a74096 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 25 Apr 2014 18:55:19 +0000 Subject: [PATCH 0809/1077] Delete all before filling module. multithreaded debug dll in project gas phase create from mix had a bug. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8677 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index b9e58c4e..d9645319 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -36,7 +36,7 @@ cxxGasPhase::cxxGasPhase(PHRQ_io * io) pr_in = false; temperature = 298.15; } - +#ifdef SKIP cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, cxxMix & mx, int l_n_user, PHRQ_io * io) : cxxNumKeyword(io) @@ -117,6 +117,90 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, this->gas_comps.push_back(comp_it->second); } } +#endif +cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, + cxxMix & mx, int l_n_user, PHRQ_io * io) +: cxxNumKeyword(io) +{ + this->n_user = this->n_user_end = l_n_user; + total_p = 0; + volume = 0; + v_m = 0; + pr_in = false; + bool first = true; +// +// Mix +// + // accumulate in map + std::map comp_map; + std::map::iterator comp_it; + + const std::map < int, LDBLE > & mixcomps = mx.Get_mixComps(); + std::map < int, LDBLE >::const_iterator it; + for (it = mixcomps.begin(); it != mixcomps.end(); it++) + { + if (entity_map.find(it->first) != entity_map.end()) + { + const cxxGasPhase *entity_ptr = &(entity_map.find(it->first)->second); + if (first) + { + this->new_def = entity_ptr->new_def; + this->solution_equilibria = entity_ptr->solution_equilibria; + this->n_solution = entity_ptr->n_solution; + this->type = entity_ptr->type; + this->total_p = entity_ptr->total_p * it->second; + this->total_moles = entity_ptr->total_moles * it->second; + this->volume = entity_ptr->volume * it->second; + this->v_m = entity_ptr->v_m * it->second; + this->pr_in = entity_ptr->pr_in; + this->temperature = entity_ptr->temperature; + first = false; + } + else + { + if (this->type != entity_ptr->type) + { + std::ostringstream oss; + oss << "Cannot mix two gas_phases with differing types."; + error_msg(oss.str().c_str(), CONTINUE); + return; + } + + this->total_p += entity_ptr->total_p * it->second; + this->volume += entity_ptr->volume * it->second; + this->v_m += entity_ptr->v_m * it->second; + } + } + cxxGasPhase *gas_phase_ptr = Utilities::Rxn_find(entity_map, it->first); + if (gas_phase_ptr) + { + std::vector add_comps = gas_phase_ptr->Get_gas_comps(); + for (size_t i = 0; i < add_comps.size(); i++) + { + comp_it = comp_map.find(add_comps[i].Get_phase_name()); + if (comp_it != comp_map.end()) + { + comp_it->second.add(add_comps[i], it->second); + } + else + { + cxxGasComp gc(add_comps[i]); + gc.multiply(it->second); + comp_map[add_comps[i].Get_phase_name()] = gc; + } + } + + } + } + + // put map into vector + this->gas_comps.clear(); + std::vector gc; + for (comp_it = comp_map.begin(); comp_it != comp_map.end(); comp_it++) + { + this->gas_comps.push_back(comp_it->second); + } +} #ifdef SKIP cxxGasPhase::cxxGasPhase(const std::map < int, cxxGasPhase > &entities, cxxMix & mix, int l_n_user, PHRQ_io * io): From d77460e6722fab51ad2606baa57efbaf3e81f8eb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Apr 2014 21:35:06 +0000 Subject: [PATCH 0810/1077] Added error print after each worker RunString. Fixed uninitialized variables when cxxKinetics was constructed from a mix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8682 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cxxKinetics.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 32f74439..5d71ba27 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -46,6 +46,8 @@ cxxNumKeyword(io) cvode_steps = 100; cvode_order = 5; totals.type = cxxNameDouble::ND_ELT_MOLES; + equalIncrements = false; + count = 0; // // Mix // From cfa58371feb81e0ecbc1240476238f486b403f00 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 29 Apr 2014 23:29:04 +0000 Subject: [PATCH 0811/1077] changes req'd for R git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8684 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- nvector_serial.cpp | 2 ++ smalldense.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/nvector_serial.cpp b/nvector_serial.cpp index 581f4367..5541fe91 100644 --- a/nvector_serial.cpp +++ b/nvector_serial.cpp @@ -801,10 +801,12 @@ N_VPrint_Serial(N_Vector x) N = NV_LENGTH_S(x); xd = NV_DATA_S(x); +#if !defined(R_SO) for (i = 0; i < N; i++) printf("%11.8g\n", (double) (*xd++)); printf("\n"); +#endif } diff --git a/smalldense.cpp b/smalldense.cpp index a803b10c..c1e4e59b 100644 --- a/smalldense.cpp +++ b/smalldense.cpp @@ -257,6 +257,7 @@ denprint(realtype ** a, integertype n) { integertype i, j; +#if !defined(R_SO) printf("\n"); for (i = 0; i < n; i++) { @@ -267,4 +268,5 @@ denprint(realtype ** a, integertype n) printf("\n"); } printf("\n"); +#endif } From 504bcf6dd09581e0c8b10f7c1ef44248469740b9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 May 2014 22:11:48 +0000 Subject: [PATCH 0812/1077] Gentisic problem. H2O was defined as a SURFACE_SPECIES. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8700 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 39 ++++++++++++++++++++++++++++++++++++--- tidy.cpp | 6 ++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/prep.cpp b/prep.cpp index b973ac72..467bf193 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2821,6 +2821,15 @@ add_potential_factor(void) struct master *master_ptr; struct unknown *unknown_ptr; + if (use.Get_surface_ptr() == NULL) + { + input_error++; + error_string = sformatf( + "SURFACE not defined for surface species %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + return(OK); + } if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) return (OK); sum_z = 0.0; @@ -2911,7 +2920,15 @@ add_cd_music_factors(int n) std::string token; struct master *master_ptr; struct unknown *unknown_ptr; - + if (use.Get_surface_ptr() == NULL) + { + input_error++; + error_string = sformatf( + "SURFACE not defined for surface species %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + return(OK); + } if (use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) return (OK); master_ptr = NULL; @@ -3031,7 +3048,15 @@ add_surface_charge_balance(void) struct master *master_ptr; struct unknown *unknown_ptr; - + if (use.Get_surface_ptr() == NULL) + { + input_error++; + error_string = sformatf( + "SURFACE not defined for surface species %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + return(OK); + } if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) return (OK); master_ptr = NULL; @@ -3090,7 +3115,15 @@ add_cd_music_charge_balances(int n) struct master *master_ptr; struct unknown *unknown_ptr; - + if (use.Get_surface_ptr() == NULL) + { + input_error++; + error_string = sformatf( + "SURFACE not defined for surface species %s", + trxn.token[0].name); + error_msg(error_string, CONTINUE); + return(OK); + } if (use.Get_surface_ptr()->Get_type() != cxxSurface::CD_MUSIC) return (OK); master_ptr = NULL; diff --git a/tidy.cpp b/tidy.cpp index 46c9bb85..2e02565b 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -322,6 +322,12 @@ tidy_model(void) error_msg("H2O, secondary master species for O(-2), not defined.", CONTINUE); } + if (s_h2o->type != H2O) + { + input_error++; + error_msg("H2O can only be defined in SOLUTION_SPECIES.", + CONTINUE); + } } if (s_hplus == NULL && s_h3oplus == NULL) { From f92afa36fb67016a22689e8723406cd7353eb5f2 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 2 May 2014 03:36:26 +0000 Subject: [PATCH 0813/1077] moved Phreeqc methods process_file_names, open_input_stream, open_output_stream, and open_output_file from PHRQ_io_output.cpp to class_main.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8701 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io_output.cpp | 625 --------------------------------------------- class_main.cpp | 624 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 624 insertions(+), 625 deletions(-) diff --git a/PHRQ_io_output.cpp b/PHRQ_io_output.cpp index 7db054a3..149388af 100644 --- a/PHRQ_io_output.cpp +++ b/PHRQ_io_output.cpp @@ -188,631 +188,6 @@ fpunchf_end_row(const char *format) } return OK; } -#ifdef ERROR_OSTREAM -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -process_file_names(int argc, char *argv[], std::istream **db_cookie, - std::istream **input_cookie, int log) -/* ---------------------------------------------------------------------- */ -{ - int l; - char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; - char query[2 * MAX_LENGTH]; - char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; - char *env_ptr; - char *ptr; -/* - * Prepare error handling - */ - try { - if (phrq_io == NULL) - { -#if !defined(R_SO) - std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; -#endif - } -/* - * Prep for get_line - */ - max_line = MAX_LINE; - space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); - space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); -/* - * Open error ostream - */ - if (argc > 4) - { - if (!phrq_io->error_open(argv[4])) - { - error_string = sformatf( "Error opening file, %s.", argv[4]); - warning_msg(error_string); - } - } - else - { - phrq_io->error_open(NULL); - } -/* - * Open user-input file - */ - strcpy(query, "Name of input file?"); - std::ifstream * local_input_stream = NULL; - if (argc <= 1) - { - default_name[0] = '\0'; - local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); - } - else - { - strcpy(default_name, argv[1]); - local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); - } - screen_msg(sformatf("Input file: %s\n\n", default_name)); - strcpy(in_file, default_name); -/* - * Open file for output - */ - strcpy(query, "Name of output file?"); - ptr = default_name; - copy_token(token, &ptr, &l); - strcpy(token, default_name); - strcat(token, ".out"); - std::ofstream * local_output_stream; - if (argc <= 1) - { - local_output_stream = open_output_stream(query, token, std::ios_base::out, false); - } - else if (argc == 2) - { - local_output_stream = open_output_stream(query, token, std::ios_base::out, true); - } - else if (argc >= 3) - { - strcpy(token, argv[2]); - local_output_stream = open_output_stream(query, token, std::ios_base::out, true); - } - screen_msg(sformatf("Output file: %s\n\n", token)); - strcpy(out_file, token); - phrq_io->Set_output_ostream(local_output_stream); -/* - * Open log file - */ - if (log == TRUE) - { - if (!phrq_io->log_open("phreeqc.log")) - { - error_msg("Cannot open log file, phreeqc.log.", STOP); - } - } -/* - * Read input file for DATABASE keyword - */ - if (local_input_stream->is_open()) - { - phrq_io->push_istream(local_input_stream); - if (get_line() == KEYWORD) - { - ptr = line; - copy_token(token, &ptr, &l); - if (strcmp_nocase(token, "database") == 0) - { -#ifdef PHREEQ98 - user_database = string_duplicate(prefix_database_dir(ptr)); -#else - user_database = string_duplicate(ptr); -#endif - if (string_trim(user_database) == EMPTY) - { - warning_msg("DATABASE file name is missing; default database will be used."); - user_database = (char *) free_check_null(user_database); - } - } - } - phrq_io->pop_istream(); - } - else - { - delete local_input_stream; - error_string = sformatf( "Error opening file, %s.", in_file); - error_msg(error_string, STOP); - } - -/* - * Open data base - */ - strcpy(query, "Name of database file?"); - env_ptr = getenv("PHREEQC_DATABASE"); - if (user_database != NULL) - { - strcpy(token, user_database); - } - else if (env_ptr != NULL) - { - strcpy(token, env_ptr); - } - else - { - strcpy(token, default_data_base); - } - - std::ifstream * local_database_file; - if (argc <= 1) - { - local_database_file = open_input_stream(query, token, std::ios_base::in, false); - } - else if (argc < 4) - { - local_database_file = open_input_stream(query, token, std::ios_base::in, true); - } - else if (argc >= 4) - { - if (user_database == NULL) - { - strcpy(token, argv[3]); - } - else - { -#ifndef PHREEQCI_GUI - warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); -#endif - } - local_database_file = open_input_stream(query, token, std::ios_base::in, true); - } - local_database_file->close(); - delete local_database_file; - screen_msg(sformatf("Database file: %s\n\n", token)); - strcpy(db_file, token); -#ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.0.5, compiled on May 29, 2013\n")); -#endif - output_msg(sformatf(" Input file: %s\n", in_file)); - output_msg(sformatf(" Output file: %s\n", out_file)); - output_msg(sformatf("Database file: %s\n\n", token)); -#ifdef NPP - output_flush(); -#endif - /* - * local cleanup - */ - user_database = (char *) free_check_null(user_database); - line = (char *) free_check_null(line); - line_save = (char *) free_check_null(line_save); - - *db_cookie = new std::ifstream(db_file, std::ios_base::in); - *input_cookie = new std::ifstream(in_file, std::ios_base::in); - } - catch (PhreeqcStop e) - { - return get_input_errors(); - } - return 0; -} -#else -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -process_file_names(int argc, char *argv[], std::istream **db_cookie, - std::istream **input_cookie, int log) -/* ---------------------------------------------------------------------- */ -{ - int l; - char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; - char query[2 * MAX_LENGTH]; - char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; - char *env_ptr; - char *ptr; -/* - * Prepare error handling - */ - try { - if (phrq_io == NULL) - { -#if !defined(R_SO) - std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; -#endif - } -/* - * Prep for get_line - */ - max_line = MAX_LINE; - space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); - space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); -/* - * Open error ostream - */ - if (argc > 4) - { - if (!phrq_io->error_open(argv[4])) - { - error_string = sformatf( "Error opening file, %s.", argv[4]); - warning_msg(error_string); - } - } - else - { - phrq_io->error_open(NULL); - } -/* - * Open user-input file - */ - strcpy(query, "Name of input file?"); - std::ifstream * local_input_stream = NULL; - if (argc <= 1) - { - default_name[0] = '\0'; - local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); - } - else - { - strcpy(default_name, argv[1]); - local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); - } - screen_msg(sformatf("Input file: %s\n\n", default_name)); - strcpy(in_file, default_name); -/* - * Open file for output - */ - strcpy(query, "Name of output file?"); - ptr = default_name; - copy_token(token, &ptr, &l); - strcat(token, ".out"); - std::ofstream * local_output_stream; - if (argc <= 1) - { - local_output_stream = open_output_stream(query, token, std::ios_base::out, false); - } - else if (argc == 2) - { - local_output_stream = open_output_stream(query, token, std::ios_base::out, true); - } - else if (argc >= 3) - { - strcpy(token, argv[2]); - local_output_stream = open_output_stream(query, token, std::ios_base::out, true); - } - screen_msg(sformatf("Output file: %s\n\n", token)); - strcpy(out_file, token); - phrq_io->Set_output_ostream(local_output_stream); -/* - * Open log file - */ - if (log == TRUE) - { - if (!phrq_io->log_open("phreeqc.log")) - { - error_msg("Cannot open log file, phreeqc.log.", STOP); - } - } -/* - * Read input file for DATABASE keyword - */ - if (local_input_stream->is_open()) - { - phrq_io->push_istream(local_input_stream); - if (get_line() == KEYWORD) - { - ptr = line; - copy_token(token, &ptr, &l); - if (strcmp_nocase(token, "database") == 0) - { -#ifdef PHREEQ98 - user_database = string_duplicate(prefix_database_dir(ptr)); -#else - user_database = string_duplicate(ptr); -#endif - if (string_trim(user_database) == EMPTY) - { - warning_msg("DATABASE file name is missing; default database will be used."); - user_database = (char *) free_check_null(user_database); - } - } - } - phrq_io->pop_istream(); - } - else - { - delete local_input_stream; - error_string = sformatf( "Error opening file, %s.", in_file); - error_msg(error_string, STOP); - } - -/* - * Open data base - */ - strcpy(query, "Name of database file?"); - env_ptr = getenv("PHREEQC_DATABASE"); - if (user_database != NULL) - { - strcpy(token, user_database); - } - else if (env_ptr != NULL) - { - strcpy(token, env_ptr); - } - else - { - strcpy(token, default_data_base); - } - - std::ifstream * local_database_file; - if (argc <= 1) - { - local_database_file = open_input_stream(query, token, std::ios_base::in, false); - } - else if (argc < 4) - { - local_database_file = open_input_stream(query, token, std::ios_base::in, true); - } - else if (argc >= 4) - { - if (user_database == NULL) - { - strcpy(token, argv[3]); - } - else - { -#ifndef PHREEQCI_GUI - warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); -#endif - } - local_database_file = open_input_stream(query, token, std::ios_base::in, true); - } - local_database_file->close(); - delete local_database_file; - screen_msg(sformatf("Database file: %s\n\n", token)); - strcpy(db_file, token); - - output_msg(sformatf(" Input file: %s\n", in_file)); - output_msg(sformatf(" Output file: %s\n", out_file)); - output_msg(sformatf("Database file: %s\n\n", token)); - /* - * local cleanup - */ - user_database = (char *) free_check_null(user_database); - line = (char *) free_check_null(line); - line_save = (char *) free_check_null(line_save); - - *db_cookie = new std::ifstream(db_file, std::ios_base::in); - *input_cookie = new std::ifstream(in_file, std::ios_base::in); - } - catch (PhreeqcStop e) - { - return get_input_errors(); - } - return 0; -} -#endif -/* ---------------------------------------------------------------------- */ -std::ifstream * Phreeqc:: -open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) -/* ---------------------------------------------------------------------- */ -{ - char name[MAX_LENGTH]; - std::ifstream *new_stream; - int l; -#ifdef ERROR_OSTREAM - std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); -#else - FILE * error_file_save = phrq_io->Get_error_file(); -#endif - - for (;;) - { -/* - * Get file name - */ - strcpy(name, default_name); - if (!batch ) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - screen_msg(sformatf("%s\n", query)); - if (default_name[0] != '\0') - { - screen_msg(sformatf("Default: %s\n", default_name)); - } - fgets(name, MAX_LENGTH, stdin); - l = (int) strlen(name); - name[l - 1] = '\0'; - if (name[0] == '\0') - { - strcpy(name, default_name); - } - } -/* - * Open existing file to read - */ - new_stream = new std::ifstream(name, mode); - if (new_stream == NULL || !new_stream->is_open()) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); - screen_msg(error_string); -#ifdef NPP - error_msg(sformatf( "\nERROR: Cannot open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP); - break; -#endif - error_flush(); - batch = FALSE; - continue; - } - break; - } - strncpy(default_name, name, MAX_LENGTH); - if (!batch ) - { - //phrq_io->Set_error_ostream(error_file_save); -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(error_ostream_save); -#else - phrq_io->Set_error_file(error_file_save); -#endif - } - return (new_stream); -} -/* ---------------------------------------------------------------------- */ -std::ofstream * Phreeqc:: -open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) -/* ---------------------------------------------------------------------- */ -{ - char name[MAX_LENGTH]; - std::ofstream *new_stream; - int l; -#ifdef ERROR_OSTREAM - std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); -#else - FILE * error_file_save = phrq_io->Get_error_file(); -#endif - - for (;;) - { -/* - * Get file name - */ - strcpy(name, default_name); - if (!batch ) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - - screen_msg(sformatf("%s\n", query)); - if (default_name[0] != '\0') - { - screen_msg(sformatf("Default: %s\n", default_name)); - } - fgets(name, MAX_LENGTH, stdin); - l = (int) strlen(name); - name[l - 1] = '\0'; - if (name[0] == '\0') - { - strcpy(name, default_name); - } - } -/* - * Open existing file to read - */ - new_stream = new std::ofstream(name, mode); - if (new_stream == NULL || !new_stream->is_open()) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); - screen_msg(error_string); - error_flush(); - batch = FALSE; - continue; - } - break; - } - strncpy(default_name, name, MAX_LENGTH); - if (!batch ) - { -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(error_ostream_save); -#else - phrq_io->Set_error_file(error_file_save); -#endif - } - return (new_stream); -} -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -std::ofstream * Phreeqc:: -open_output_file(char *query, char *default_name, std::ios_base::openmode mode, bool batch) -/* ---------------------------------------------------------------------- */ -{ - char name[MAX_LENGTH]; - std::ofstream *new_stream; - int l; -#ifdef ERROR_OSTREAM - std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); -#else - FILE * error_file_save = phrq_io->Get_error_file(); -#endif - - - for (;;) - { -/* - * Get file name - */ - strcpy(name, default_name); - if (!batch ) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - screen_msg(sformatf("%s\n", query)); - if (default_name[0] != '\0') - { - screen_msg(sformatf("Default: %s\n", default_name)); - } - fgets(name, MAX_LENGTH, stdin); - l = (int) strlen(name); - name[l - 1] = '\0'; - if (name[0] == '\0') - { - strcpy(name, default_name); - } - } -/* - * Open existing file to read - */ - new_stream = new std::ofstream(name, mode); - if (new_stream == NULL || !new_stream->is_open()) - { -#if !defined(R_SO) -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(&std::cerr); -#else - phrq_io->Set_error_file(stderr); -#endif -#endif - - error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); - screen_msg(error_string); - error_flush(); - batch = FALSE; - continue; - } - break; - } - strncpy(default_name, name, MAX_LENGTH); - if (!batch ) - { -#ifdef ERROR_OSTREAM - phrq_io->Set_error_ostream(error_ostream_save); -#else - phrq_io->Set_error_file(error_file_save); -#endif - } - return (new_stream); -} -#endif /* ---------------------------------------------------------------------- */ void Phreeqc:: screen_msg(const char *err_str) diff --git a/class_main.cpp b/class_main.cpp index 18b42a3a..060b1e54 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -291,3 +291,627 @@ write_banner(void) return 0; } +#ifdef ERROR_OSTREAM +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log) +/* ---------------------------------------------------------------------- */ +{ + int l; + char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; + char query[2 * MAX_LENGTH]; + char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; + char *env_ptr; + char *ptr; +/* + * Prepare error handling + */ + try { + if (phrq_io == NULL) + { +#if !defined(R_SO) + std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; +#endif + } +/* + * Prep for get_line + */ + max_line = MAX_LINE; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); +/* + * Open error ostream + */ + if (argc > 4) + { + if (!phrq_io->error_open(argv[4])) + { + error_string = sformatf( "Error opening file, %s.", argv[4]); + warning_msg(error_string); + } + } + else + { + phrq_io->error_open(NULL); + } +/* + * Open user-input file + */ + strcpy(query, "Name of input file?"); + std::ifstream * local_input_stream = NULL; + if (argc <= 1) + { + default_name[0] = '\0'; + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); + } + else + { + strcpy(default_name, argv[1]); + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); + } + screen_msg(sformatf("Input file: %s\n\n", default_name)); + strcpy(in_file, default_name); +/* + * Open file for output + */ + strcpy(query, "Name of output file?"); + ptr = default_name; + copy_token(token, &ptr, &l); + strcpy(token, default_name); + strcat(token, ".out"); + std::ofstream * local_output_stream; + if (argc <= 1) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, false); + } + else if (argc == 2) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + else if (argc >= 3) + { + strcpy(token, argv[2]); + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + screen_msg(sformatf("Output file: %s\n\n", token)); + strcpy(out_file, token); + phrq_io->Set_output_ostream(local_output_stream); +/* + * Open log file + */ + if (log == TRUE) + { + if (!phrq_io->log_open("phreeqc.log")) + { + error_msg("Cannot open log file, phreeqc.log.", STOP); + } + } +/* + * Read input file for DATABASE keyword + */ + if (local_input_stream->is_open()) + { + phrq_io->push_istream(local_input_stream); + if (get_line() == KEYWORD) + { + ptr = line; + copy_token(token, &ptr, &l); + if (strcmp_nocase(token, "database") == 0) + { +#ifdef PHREEQ98 + user_database = string_duplicate(prefix_database_dir(ptr)); +#else + user_database = string_duplicate(ptr); +#endif + if (string_trim(user_database) == EMPTY) + { + warning_msg("DATABASE file name is missing; default database will be used."); + user_database = (char *) free_check_null(user_database); + } + } + } + phrq_io->pop_istream(); + } + else + { + delete local_input_stream; + error_string = sformatf( "Error opening file, %s.", in_file); + error_msg(error_string, STOP); + } + +/* + * Open data base + */ + strcpy(query, "Name of database file?"); + env_ptr = getenv("PHREEQC_DATABASE"); + if (user_database != NULL) + { + strcpy(token, user_database); + } + else if (env_ptr != NULL) + { + strcpy(token, env_ptr); + } + else + { + strcpy(token, default_data_base); + } + + std::ifstream * local_database_file; + if (argc <= 1) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, false); + } + else if (argc < 4) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + else if (argc >= 4) + { + if (user_database == NULL) + { + strcpy(token, argv[3]); + } + else + { +#ifndef PHREEQCI_GUI + warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); +#endif + } + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + local_database_file->close(); + delete local_database_file; + screen_msg(sformatf("Database file: %s\n\n", token)); + strcpy(db_file, token); +#ifdef NPP + output_msg(sformatf("Using PHREEQC: version 3.0.5, compiled on May 29, 2013\n")); +#endif + output_msg(sformatf(" Input file: %s\n", in_file)); + output_msg(sformatf(" Output file: %s\n", out_file)); + output_msg(sformatf("Database file: %s\n\n", token)); +#ifdef NPP + output_flush(); +#endif + /* + * local cleanup + */ + user_database = (char *) free_check_null(user_database); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + *db_cookie = new std::ifstream(db_file, std::ios_base::in); + *input_cookie = new std::ifstream(in_file, std::ios_base::in); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} +#else +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +process_file_names(int argc, char *argv[], std::istream **db_cookie, + std::istream **input_cookie, int log) +/* ---------------------------------------------------------------------- */ +{ + int l; + char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH]; + char query[2 * MAX_LENGTH]; + char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH]; + char *env_ptr; + char *ptr; +/* + * Prepare error handling + */ + try { + if (phrq_io == NULL) + { +#if !defined(R_SO) + std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; +#endif + } +/* + * Prep for get_line + */ + max_line = MAX_LINE; + space((void **) ((void *) &line), INIT, &max_line, sizeof(char)); + space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char)); +/* + * Open error ostream + */ + if (argc > 4) + { + if (!phrq_io->error_open(argv[4])) + { + error_string = sformatf( "Error opening file, %s.", argv[4]); + warning_msg(error_string); + } + } + else + { + phrq_io->error_open(NULL); + } +/* + * Open user-input file + */ + strcpy(query, "Name of input file?"); + std::ifstream * local_input_stream = NULL; + if (argc <= 1) + { + default_name[0] = '\0'; + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false); + } + else + { + strcpy(default_name, argv[1]); + local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true); + } + screen_msg(sformatf("Input file: %s\n\n", default_name)); + strcpy(in_file, default_name); +/* + * Open file for output + */ + strcpy(query, "Name of output file?"); + ptr = default_name; + copy_token(token, &ptr, &l); + strcat(token, ".out"); + std::ofstream * local_output_stream; + if (argc <= 1) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, false); + } + else if (argc == 2) + { + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + else if (argc >= 3) + { + strcpy(token, argv[2]); + local_output_stream = open_output_stream(query, token, std::ios_base::out, true); + } + screen_msg(sformatf("Output file: %s\n\n", token)); + strcpy(out_file, token); + phrq_io->Set_output_ostream(local_output_stream); +/* + * Open log file + */ + if (log == TRUE) + { + if (!phrq_io->log_open("phreeqc.log")) + { + error_msg("Cannot open log file, phreeqc.log.", STOP); + } + } +/* + * Read input file for DATABASE keyword + */ + if (local_input_stream->is_open()) + { + phrq_io->push_istream(local_input_stream); + if (get_line() == KEYWORD) + { + ptr = line; + copy_token(token, &ptr, &l); + if (strcmp_nocase(token, "database") == 0) + { +#ifdef PHREEQ98 + user_database = string_duplicate(prefix_database_dir(ptr)); +#else + user_database = string_duplicate(ptr); +#endif + if (string_trim(user_database) == EMPTY) + { + warning_msg("DATABASE file name is missing; default database will be used."); + user_database = (char *) free_check_null(user_database); + } + } + } + phrq_io->pop_istream(); + } + else + { + delete local_input_stream; + error_string = sformatf( "Error opening file, %s.", in_file); + error_msg(error_string, STOP); + } + +/* + * Open data base + */ + strcpy(query, "Name of database file?"); + env_ptr = getenv("PHREEQC_DATABASE"); + if (user_database != NULL) + { + strcpy(token, user_database); + } + else if (env_ptr != NULL) + { + strcpy(token, env_ptr); + } + else + { + strcpy(token, default_data_base); + } + + std::ifstream * local_database_file; + if (argc <= 1) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, false); + } + else if (argc < 4) + { + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + else if (argc >= 4) + { + if (user_database == NULL) + { + strcpy(token, argv[3]); + } + else + { +#ifndef PHREEQCI_GUI + warning_msg ("Database file from DATABASE keyword is used; command line argument ignored."); +#endif + } + local_database_file = open_input_stream(query, token, std::ios_base::in, true); + } + local_database_file->close(); + delete local_database_file; + screen_msg(sformatf("Database file: %s\n\n", token)); + strcpy(db_file, token); + + output_msg(sformatf(" Input file: %s\n", in_file)); + output_msg(sformatf(" Output file: %s\n", out_file)); + output_msg(sformatf("Database file: %s\n\n", token)); + /* + * local cleanup + */ + user_database = (char *) free_check_null(user_database); + line = (char *) free_check_null(line); + line_save = (char *) free_check_null(line_save); + + *db_cookie = new std::ifstream(db_file, std::ios_base::in); + *input_cookie = new std::ifstream(in_file, std::ios_base::in); + } + catch (PhreeqcStop e) + { + return get_input_errors(); + } + return 0; +} +#endif +/* ---------------------------------------------------------------------- */ +std::ifstream * Phreeqc:: +open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH]; + std::ifstream *new_stream; + int l; +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif + + for (;;) + { +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + screen_msg(sformatf("%s\n", query)); + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ifstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); + screen_msg(error_string); +#ifdef NPP + error_msg(sformatf( "\nERROR: Cannot open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP); + break; +#endif + error_flush(); + batch = FALSE; + continue; + } + break; + } + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { + //phrq_io->Set_error_ostream(error_file_save); +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif + } + return (new_stream); +} +/* ---------------------------------------------------------------------- */ +std::ofstream * Phreeqc:: +open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH]; + std::ofstream *new_stream; + int l; +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif + + for (;;) + { +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + + screen_msg(sformatf("%s\n", query)); + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ofstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); + screen_msg(error_string); + error_flush(); + batch = FALSE; + continue; + } + break; + } + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif + } + return (new_stream); +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +std::ofstream * Phreeqc:: +open_output_file(char *query, char *default_name, std::ios_base::openmode mode, bool batch) +/* ---------------------------------------------------------------------- */ +{ + char name[MAX_LENGTH]; + std::ofstream *new_stream; + int l; +#ifdef ERROR_OSTREAM + std::ostream * error_ostream_save = phrq_io->Get_error_ostream(); +#else + FILE * error_file_save = phrq_io->Get_error_file(); +#endif + + + for (;;) + { +/* + * Get file name + */ + strcpy(name, default_name); + if (!batch ) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + screen_msg(sformatf("%s\n", query)); + if (default_name[0] != '\0') + { + screen_msg(sformatf("Default: %s\n", default_name)); + } + fgets(name, MAX_LENGTH, stdin); + l = (int) strlen(name); + name[l - 1] = '\0'; + if (name[0] == '\0') + { + strcpy(name, default_name); + } + } +/* + * Open existing file to read + */ + new_stream = new std::ofstream(name, mode); + if (new_stream == NULL || !new_stream->is_open()) + { +#if !defined(R_SO) +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(&std::cerr); +#else + phrq_io->Set_error_file(stderr); +#endif +#endif + error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); + screen_msg(error_string); + error_flush(); + batch = FALSE; + continue; + } + break; + } + strncpy(default_name, name, MAX_LENGTH); + if (!batch ) + { +#ifdef ERROR_OSTREAM + phrq_io->Set_error_ostream(error_ostream_save); +#else + phrq_io->Set_error_file(error_file_save); +#endif + } + return (new_stream); +} +#endif From c343330920ce00ef0a9a2fbe38c406a697e5b4b4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 2 May 2014 03:41:04 +0000 Subject: [PATCH 0814/1077] removed no longer needed R_SO ifdefs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8702 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 060b1e54..31174a31 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -310,9 +310,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, try { if (phrq_io == NULL) { -#if !defined(R_SO) std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; -#endif } /* * Prep for get_line @@ -509,9 +507,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, try { if (phrq_io == NULL) { -#if !defined(R_SO) std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; -#endif } /* * Prep for get_line @@ -706,12 +702,10 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, strcpy(name, default_name); if (!batch ) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') @@ -732,12 +726,10 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, new_stream = new std::ifstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); @@ -785,12 +777,10 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode strcpy(name, default_name); if (!batch ) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif screen_msg(sformatf("%s\n", query)); @@ -812,12 +802,10 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode new_stream = new std::ofstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); @@ -862,12 +850,10 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, strcpy(name, default_name); if (!batch ) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') @@ -888,12 +874,10 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, new_stream = new std::ofstream(name, mode); if (new_stream == NULL || !new_stream->is_open()) { -#if !defined(R_SO) #ifdef ERROR_OSTREAM phrq_io->Set_error_ostream(&std::cerr); #else phrq_io->Set_error_file(stderr); -#endif #endif error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name); screen_msg(error_string); From 8b2c1a8d07daaa105b20f3e249f465b39736c985 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 5 May 2014 21:49:38 +0000 Subject: [PATCH 0815/1077] R problem for ex16. memcpy was overwriting the same space if i = row. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8703 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index a14f610f..cf2230ae 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -2790,9 +2790,18 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), (size_t) max_column_count * sizeof(LDBLE)); */ - memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + if (i > row) + { + if ((row*max_column_count + (*n + 1)) >= (i * max_column_count)) + { + assert(false); + } + + + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + } row_back_l[row] = i; row++; k1++; @@ -2826,9 +2835,17 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), (size_t) max_column_count * sizeof(LDBLE)); */ - memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + + if (i > row) + { + if ((row*max_column_count + (*n + 1)) >= (i * max_column_count)) + { + assert(false); + } + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + } row_back_l[row] = i; row++; l1++; @@ -2861,9 +2878,17 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, memcpy(&(array_out[row * max_column_count]), &(array_out[i * max_column_count]), (size_t) max_column_count * sizeof(LDBLE)); */ - memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + + if (i > row) + { + if ((row*max_column_count + (*n + 1)) >= (i * max_column_count)) + { + assert(false); + } + memcpy(&(array_out[row * max_column_count]), + &(array_out[i * max_column_count]), + (size_t) (*n + 1) * sizeof(LDBLE)); + } row_back_l[row] = i; row++; m1++; From b2a5ed444e5615f76a2bde13581bae83e1163a27 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 May 2014 23:12:44 +0000 Subject: [PATCH 0816/1077] added undef SS suggested by Ripley for x86 Solaris git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8708 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cvode.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cvode.h b/cvode.h index c7c68b71..a4fbb891 100644 --- a/cvode.h +++ b/cvode.h @@ -23,6 +23,8 @@ #include "sundialstypes.h" #include "nvector.h" +#undef SS + /****************************************************************** * * * CVODE is used to solve numerically the ordinary initial value * From 9b9e34a2413ddee194c6b7fd98433ddfe7122780 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 May 2014 15:32:19 +0000 Subject: [PATCH 0817/1077] git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8721 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 29df29b8..0cd0cce5 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -18,7 +18,7 @@ /* Run-time library for PhreeqcPtr->use with "p2c", the Pascal to C translator */ /* "p2c" Copyright (C) 1989, 1990, 1991 Free Software Foundation. - * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version --VERSION--. + * By Dave Gillespie, daveg@csvax.cs.caltech.edu. Version 1.20. * This file may be copied, modified, etc. in any way. It is not restricted * by the licence agreement accompanying p2c itself. */ From 8e81c17eb27d6b3898c20d6285526f490b3c51be Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 7 May 2014 21:27:47 +0000 Subject: [PATCH 0818/1077] Next try on DELETE; -all Fixed warnings for MAC lion operating system git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8724 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 4 +-- print.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ read.cpp | 9 ++++--- transport.cpp | 2 +- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/model.cpp b/model.cpp index 5ca65ac1..6777cd97 100644 --- a/model.cpp +++ b/model.cpp @@ -4417,8 +4417,8 @@ residuals(void) { /* eqns A-6 and A-7 */ sinh_constant = - sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * - tk_x * 1000); + //sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * + // tk_x * 1000); sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * 1000); /* diff --git a/print.cpp b/print.cpp index b365ce59..033fefda 100644 --- a/print.cpp +++ b/print.cpp @@ -1464,7 +1464,11 @@ print_species(void) output_msg(sformatf("%50s%10s%10s%10s\n", "Log", "Log", "Log", "mole V")); } output_msg(sformatf(" %-13s%12s%12s%10s%10s%10s%10s\n\n", "Species", +#ifdef NO_UTF8_ENCODING + "Molality", "Activity", "Molality", "Activity", "Gamma", "cm3/mol")); +#else "Molality", "Activity", "Molality", "Activity", "Gamma", "cm³/mol")); +#endif /* * Print list of species */ @@ -1620,14 +1624,22 @@ print_surface(void) if ((charge_ptr->Get_specific_area() * charge_ptr->Get_grams()) > 0) { +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("\t%11.3e sigma, C/m2\n", +#else output_msg(sformatf("\t%11.3e sigma, C/m²\n", +#endif (double) (charge * F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams())))); } else { +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("\tundefined sigma, C/m2\n")); +#else output_msg(sformatf("\tundefined sigma, C/m²\n")); +#endif } output_msg(sformatf("\t%11.3e psi, V\n", (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * @@ -1640,11 +1652,19 @@ print_surface(void) if (comp_ptr->Get_phase_name().size() > 0) { output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e specific area, m2/mol %s\n", +#else "\t%11.3e specific area, m²/mol %s\n", +#endif (double) charge_ptr->Get_specific_area(), comp_ptr->Get_phase_name().c_str())); output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e m2 for %11.3e moles of %s\n\n", +#else "\t%11.3e m² for %11.3e moles of %s\n\n", +#endif (double) (charge_ptr->Get_grams() * charge_ptr->Get_specific_area()), (double) charge_ptr->Get_grams(), @@ -1653,11 +1673,19 @@ print_surface(void) else if (comp_ptr->Get_rate_name().size() > 0) { output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e specific area, m2/mol %s\n", +#else "\t%11.3e specific area, m²/mol %s\n", +#endif (double) charge_ptr->Get_specific_area(), comp_ptr->Get_rate_name().c_str())); output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e m2 for %11.3e moles of %s\n\n", +#else "\t%11.3e m² for %11.3e moles of %s\n\n", +#endif (double) (charge_ptr->Get_grams() * charge_ptr->Get_specific_area()), (double) charge_ptr->Get_grams(), @@ -1666,9 +1694,17 @@ print_surface(void) else { output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e specific area, m2/g\n", +#else "\t%11.3e specific area, m²/g\n", +#endif (double) charge_ptr->Get_specific_area())); +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("\t%11.3e m2 for %11.3e g\n\n",, +#else output_msg(sformatf("\t%11.3e m² for %11.3e g\n\n", +#endif (double) (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()), (double) charge_ptr->Get_grams())); @@ -1880,21 +1916,41 @@ print_surface_cd_music(void) charge_ptr->Get_grams()) > 0) { output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e sigma, plane 0, C/m2\n", +#else "\t%11.3e sigma, plane 0, C/m²\n", +#endif (double) charge_ptr->Get_sigma0())); output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e sigma, plane 1, C/m2\n", +#else "\t%11.3e sigma, plane 1, C/m²\n", +#endif (double) charge_ptr->Get_sigma1())); output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e sigma, plane 2, C/m2\n", +#else "\t%11.3e sigma, plane 2, C/m²\n", +#endif (double) charge_ptr->Get_sigma2())); output_msg(sformatf( +#ifdef NO_UTF8_ENCODING + "\t%11.3e sigma, diffuse layer, C/m2\n\n", +#else "\t%11.3e sigma, diffuse layer, C/m²\n\n", +#endif (double) charge_ptr->Get_sigmaddl())); } else { +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("\tundefined sigma, C/m2\n")); +#else output_msg(sformatf("\tundefined sigma, C/m²\n")); +#endif } output_msg(sformatf("\t%11.3e psi, plane 0, V\n", (double) (-master_ptr0->s->la * LOG_10 * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ))); @@ -2147,13 +2203,21 @@ print_totals(void) if (EC > 0) { output_msg(sformatf("%36s%i%7s%i\n", +#ifdef NO_UTF8_ENCODING + "Specific Conductance (uS/cm, ", (int) tc_x, "oC) = ", (int) EC)); +#else "Specific Conductance (µS/cm, ", (int) tc_x, "°C) = ", (int) EC)); +#endif } /* VP: Density Start */ if (print_density) { dens = calc_dens(); +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("%45s%9.5f", "Density (g/cm3) = ", +#else output_msg(sformatf("%45s%9.5f", "Density (g/cm³) = ", +#endif (double) dens)); if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program limit)")); else output_msg(sformatf("\n")); @@ -2181,7 +2245,11 @@ print_totals(void) } output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", (double) (total_co2 / mass_water_aq_x))); +#ifdef NO_UTF8_ENCODING + output_msg(sformatf("%45s%6.2f\n", "Temperature (oC) = ", +#else output_msg(sformatf("%45s%6.2f\n", "Temperature (°C) = ", +#endif (double) tc_x)); if (patm_x != 1.0) diff --git a/read.cpp b/read.cpp index 1f7fd1b7..2a369aae 100644 --- a/read.cpp +++ b/read.cpp @@ -8476,11 +8476,14 @@ read_print(void) { char * tptr = token; get_num(&tptr, &num); - status_interval = (int) floor(num); + num = floor(num); + if (num < 0.0) num = 0.0; + //status_interval = (int) floor(num); + status_interval = (clock_t) num; } } - if (status_interval < 0) - status_interval = 0; + //if (status_interval < 0) + // status_interval = 0; break; case 20: /* inverse */ case 27: /* inverse_modeling */ diff --git a/transport.cpp b/transport.cpp index cffdacb0..82b129b6 100644 --- a/transport.cpp +++ b/transport.cpp @@ -164,7 +164,7 @@ transport(void) { fill_spec(cell_no); } - if ((cell_data[k - 1].punch == TRUE)) + if (cell_data[k - 1].punch == TRUE) punch_all(); if ((cell_data[k - 1].print == TRUE) && (transport_step % print_modulus == 0)) From 48ec1a3837189e49d9db88890b0fda3ca223dde3 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 May 2014 02:23:14 +0000 Subject: [PATCH 0819/1077] added LICENSE to cvode files git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8727 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cvdense.cpp | 92 ++++++++++++++------ cvdense.h | 86 ++++++++++++++----- cvode.cpp | 206 +++++++++++++++++++++++++++------------------ cvode.h | 88 ++++++++++++++----- dense.cpp | 76 +++++++++++++---- dense.h | 124 ++++++++++++++++++--------- nvector.cpp | 76 +++++++++++++---- nvector.h | 130 ++++++++++++++++++---------- nvector_serial.cpp | 87 ++++++++++++++----- nvector_serial.h | 166 ++++++++++++++++++++++-------------- smalldense.cpp | 74 ++++++++++++---- smalldense.h | 88 ++++++++++++++----- sundialsmath.cpp | 72 +++++++++++++--- sundialsmath.h | 92 ++++++++++++++------ sundialstypes.h | 170 +++++++++++++++++++++++-------------- 15 files changed, 1143 insertions(+), 484 deletions(-) diff --git a/cvdense.cpp b/cvdense.cpp index deebc3d0..fde663e6 100644 --- a/cvdense.cpp +++ b/cvdense.cpp @@ -1,19 +1,63 @@ -/******************************************************************* - * * - * File : cvdense.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for the CVODE dense linear * - * solver, CVDENSE. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : cvdense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for the CVODE dense linear * + * solver, CVDENSE. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include @@ -32,7 +76,7 @@ #define MACHENV machEnv->phreeqc_ptr-> #define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> #define MACHENV_MALLOC MACHENV -#define CVMEM_MALLOC CVMEM +#define CVMEM_MALLOC CVMEM #include "phqalloc.h" /* WARNING don`t include any headers below here */ @@ -56,7 +100,7 @@ /****************************************************************** - * * + * * * Types : CVDenseMemRec, CVDenseMem * *----------------------------------------------------------------* * The type CVDenseMem is pointer to a CVDenseMemRec. This * @@ -215,13 +259,13 @@ CVDenseDQJac(integertype N, DenseMat J, RhsFn f, void *f_data, address of this structure. It sets setupNonNull in (*cvode_mem) to TRUE, the d_J_data field in CVDenseMemRec to be the input parameter jac_data, and the d_jac field to be: - (1) the input parameter djac if djac != NULL or - (2) CVDenseDQJac if djac == NULL. + (1) the input parameter djac if djac != NULL or + (2) CVDenseDQJac if djac == NULL. Finally, it allocates memory for M, savedJ, and pivots. The return value is SUCCESS = 0, or LMEM_FAIL = -1. NOTE: The dense linear solver assumes a serial implementation - of the NVECTOR package. Therefore, CVDense will first + of the NVECTOR package. Therefore, CVDense will first test for compatible a compatible N_Vector internal representation by checking (1) the machine environment ID tag and (2) that the functions N_VMake, N_VDispose, @@ -396,9 +440,9 @@ CVDenseInit(CVodeMem cv_mem) This routine does the setup operations for the dense linear solver. It makes a decision whether or not to call the Jacobian evaluation - routine based on various state variables, and if not it uses the - saved copy. In any case, it constructs the Newton matrix - M = I - gamma*J, updates counters, and calls the dense LU + routine based on various state variables, and if not it uses the + saved copy. In any case, it constructs the Newton matrix + M = I - gamma*J, updates counters, and calls the dense LU factorization routine. **********************************************************************/ diff --git a/cvdense.h b/cvdense.h index 1e8b25d8..cd2bcc25 100644 --- a/cvdense.h +++ b/cvdense.h @@ -1,24 +1,68 @@ #ifndef _INC_CVDENSE_H #define _INC_CVDENSE_H -/******************************************************************* - * * - * File : cvdense.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for the CVODE dense linear solver, * - * CVDENSE. * - * * - * Note: The type integertype must be large enough to store the * - * value of the linear system size N. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : cvdense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the header file for the CVODE dense linear solver, * + * CVDENSE. * + * * + * Note: The type integertype must be large enough to store the * + * value of the linear system size N. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _cvdense_h #define _cvdense_h @@ -74,7 +118,7 @@ /****************************************************************** - * * + * * * Type : CVDenseJacFn * *----------------------------------------------------------------* * A dense Jacobian approximation function Jac must have the * @@ -96,7 +140,7 @@ * col_j[i] = J_ij; * * } * * } * - * * + * * * (2) (without macros - explicit data structure references) * * for (j=0; j < N; j++) { * * col_j = (J->data)[j]; * diff --git a/cvode.cpp b/cvode.cpp index ad0d4b0f..4d439d9d 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -1,21 +1,65 @@ /*#define DEBUG_CVODE*/ -/******************************************************************* - * * - * File : cvode.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, * - * and Dan Shumaker @ LLNL * - * Version of : 24 July 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for the main CVODE integrator. * - * It is independent of the CVODE linear solver in use. * - * * - *******************************************************************/ -#include "nvector_serial.h" +/************************************************************************** + * * + * File : cvode.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, * + * and Dan Shumaker @ LLNL * + * Version of : 24 July 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for the main CVODE integrator. * + * It is independent of the CVODE linear solver in use. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ +#include "nvector_serial.h" #define Ith(v,i) NV_Ith_S(v,i-1) /************************************************************/ /******************* BEGIN Imports **************************/ @@ -32,7 +76,7 @@ #define MACHENV machEnv->phreeqc_ptr-> #define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> #define MACHENV_MALLOC MACHENV -#define CVMEM_MALLOC CVMEM +#define CVMEM_MALLOC CVMEM #include "phqalloc.h" /* WARNING don`t include any headers below here */ @@ -503,7 +547,7 @@ static int CVHandleFailure(CVodeMem cv_mem, int kflag); error occurs during initialization, it is reported to the file whose file pointer is errfp and NULL is returned. Otherwise, the pointer to successfully initialized problem memory is returned. - + *****************************************************************/ void * @@ -782,7 +826,7 @@ CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0, file whose file pointer is errfp. The return value is SUCCESS = 0 if no errors occurred, or a negative value otherwise. - + *****************************************************************/ int @@ -1047,7 +1091,7 @@ CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0, /********************* CVode **************************************** - This routine is the main driver of the CVODE package. + This routine is the main driver of the CVODE package. It integrates over a time interval defined by the user, by calling CVStep to do internal time steps. @@ -1148,7 +1192,7 @@ CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype * t, int itask) } } - /* On the first call, call f at (t0,y0), set zn[1] = y'(t0), + /* On the first call, call f at (t0,y0), set zn[1] = y'(t0), set initial h (from H0 or CVHin), and scale zn[1] by h */ CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tn; CVMEM cvode_step_fraction = 0; @@ -1380,9 +1424,9 @@ CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype * t, int itask) This routine computes the k-th derivative of the interpolating polynomial at the time t and stores the result in the vector dky. The formula is: - q - dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] , - j=k + q + dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] , + j=k where c(j,k) = j*(j-1)*...*(j-k+1), q is the current order, and zn[j] is the j-th column of the Nordsieck history array. @@ -1566,7 +1610,7 @@ CVAllocVectors(CVodeMem cv_mem, integertype neq, int maxord, M_Env machEnv) } /***************** CVFreeVectors ********************************* - + This routine frees the CVODE vectors allocated in CVAllocVectors. ******************************************************************/ @@ -1585,7 +1629,7 @@ CVFreeVectors(CVodeMem cv_mem, int maxord) } /*********************** CVEwtSet ************************************** - + This routine is responsible for setting the error weight vector ewt, according to tol_type, as follows: @@ -1599,7 +1643,7 @@ CVFreeVectors(CVodeMem cv_mem, int maxord) considered undefined after the FALSE return from CVEwtSet. All the real work is done in the routines CVEwtSetSS, CVEwtSetSV. - + ***********************************************************************/ static booleantype @@ -1666,13 +1710,13 @@ CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur) /******************* CVHin *************************************** - This routine computes a tentative initial step size h0. + This routine computes a tentative initial step size h0. If tout is too close to tn (= t0), then CVHin returns FALSE and - h remains uninitialized. Otherwise, CVHin sets h to the chosen + h remains uninitialized. Otherwise, CVHin sets h to the chosen value h0 and returns TRUE. The algorithm used seeks to find h0 as a solution of - (WRMS norm of (h0^2 ydd / 2)) = 1, + (WRMS norm of (h0^2 ydd / 2)) = 1, where ydd = estimated second derivative of y. *****************************************************************/ @@ -1695,9 +1739,9 @@ CVHin(CVodeMem cv_mem, realtype tout) if (tdist < TWO * tround) return (FALSE); - /* Set lower and upper bounds on h0, and take geometric mean + /* Set lower and upper bounds on h0, and take geometric mean Exit with this value if the bounds cross each other */ - + hlb = HLB_FACTOR * tround; hub = CVUpperBoundH0(cv_mem, tdist); hg = RSqrt(hlb * hub); @@ -1828,7 +1872,7 @@ CVYddNorm(CVodeMem cv_mem, realtype hg) } /********************* CVStep ************************************** - + This routine performs one internal cvode step, from tn to tn + h. It calls other routines to do all the work. @@ -2088,7 +2132,7 @@ CVStep(CVodeMem cv_mem) #endif etamax = (nst <= SMALL_NST) ? ETAMX2 : ETAMX3; - /* Finally, we rescale the acor array to be the + /* Finally, we rescale the acor array to be the estimated local error vector. */ N_VScale(ONE / tq[2], acor, acor); @@ -2169,7 +2213,7 @@ CVAdjustAdams(CVodeMem cv_mem, int deltaq) } /* On an order decrease, each zn[j] is adjusted by a multiple - of zn[q]. The coefficients in the adjustment are the + of zn[q]. The coefficients in the adjustment are the coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_j), integrated, where xi_j = [t_n - t_(n-j)]/h. */ @@ -2195,8 +2239,8 @@ CVAdjustAdams(CVodeMem cv_mem, int deltaq) /********************** CVAdjustBDF ******************************* This is a high level routine which handles adjustments to the - history array on a change of order by deltaq in the case that - lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and + history array on a change of order by deltaq in the case that + lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and CVDecreaseBDF if deltaq = -1 to do the actual work. ******************************************************************/ @@ -2217,11 +2261,11 @@ CVAdjustBDF(CVodeMem cv_mem, int deltaq) /******************** CVIncreaseBDF ********************************** - This routine adjusts the history array on an increase in the - order q in the case that lmm == BDF. - A new column zn[q+1] is set equal to a multiple of the saved + This routine adjusts the history array on an increase in the + order q in the case that lmm == BDF. + A new column zn[q+1] is set equal to a multiple of the saved vector (= acor) in zn[qmax]. Then each zn[j] is adjusted by - a multiple of zn[q+1]. The coefficients in the adjustment are the + a multiple of zn[q+1]. The coefficients in the adjustment are the coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-1)), where xi_j = [t_n - t_(n-j)]/h. @@ -2262,8 +2306,8 @@ CVIncreaseBDF(CVodeMem cv_mem) /********************* CVDecreaseBDF ****************************** - This routine adjusts the history array on a decrease in the - order q in the case that lmm == BDF. + This routine adjusts the history array on a decrease in the + order q in the case that lmm == BDF. Each zn[j] is adjusted by a multiple of zn[q]. The coefficients in the adjustment are the coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-2)), where xi_j = [t_n - t_(n-j)]/h. @@ -2339,7 +2383,7 @@ CVPredict(CVodeMem cv_mem) /************************** CVSet ********************************* This routine is a high level routine which calls CVSetAdams or - CVSetBDF to set the polynomial l, the test quantity array tq, + CVSetBDF to set the polynomial l, the test quantity array tq, and the related variables rl1, gamma, and gamrat. ******************************************************************/ @@ -2407,7 +2451,7 @@ CVSetAdams(CVodeMem cv_mem) This routine generates in m[] the coefficients of the product polynomial needed for the Adams l and tq coefficients for q > 1. - + ******************************************************************/ static realtype @@ -2471,7 +2515,7 @@ CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype hsum) } /****************** CVAltSum ************************************** - + CVAltSum returns the value of the alternating sum sum (i= 0 ... iend) [ (-1)^i * (a[i] / (i + k)) ]. If iend < 0 then CVAltSum returns 0. @@ -2503,7 +2547,7 @@ CVAltSum(int iend, realtype a[], int k) This routine computes the coefficients l and tq in the case lmm == BDF. CVSetBDF calls CVSetTqBDF to set the test - quantity array tq. + quantity array tq. The components of the array l are the coefficients of a polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by @@ -2612,7 +2656,7 @@ CVnls(CVodeMem cv_mem, int nflag) /***************** CVnlsFunctional ******************************** - This routine attempts to solve the nonlinear system using + This routine attempts to solve the nonlinear system using functional iteration (no matrices involved). ******************************************************************/ @@ -2695,8 +2739,8 @@ CVnlsFunctional(CVodeMem cv_mem) /*********************** CVnlsNewton ********************************** - This routine handles the Newton iteration. It calls lsetup if - indicated, calls CVNewtonIteration to perform the iteration, and + This routine handles the Newton iteration. It calls lsetup if + indicated, calls CVNewtonIteration to perform the iteration, and retries a failed attempt at Newton iteration if that is indicated. See return values at top of this file. @@ -2800,7 +2844,7 @@ CVnlsNewton(CVodeMem cv_mem, int nflag) ier)); #endif } - /* If there is a convergence failure and the Jacobian-related + /* If there is a convergence failure and the Jacobian-related data appears not to be current, loop again with a call to lsetup in which convfail=FAIL_BAD_J. Otherwise return. */ if (ier != TRY_AGAIN_CVODE) @@ -2813,11 +2857,11 @@ CVnlsNewton(CVodeMem cv_mem, int nflag) /********************** CVNewtonIteration **************************** This routine performs the Newton iteration. If the iteration succeeds, - it returns the value SOLVED. If not, it may signal the CVnlsNewton + it returns the value SOLVED. If not, it may signal the CVnlsNewton routine to call lsetup again and reattempt the iteration, by - returning the value TRY_AGAIN_CVODE. (In this case, CVnlsNewton must set - convfail to FAIL_BAD_J before calling setup again). - Otherwise, this routine returns one of the appropriate values + returning the value TRY_AGAIN_CVODE. (In this case, CVnlsNewton must set + convfail to FAIL_BAD_J before calling setup again). + Otherwise, this routine returns one of the appropriate values SOLVE_FAIL_UNREC or CONV_FAIL back to CVnlsNewton. *********************************************************************/ @@ -2895,7 +2939,7 @@ CVNewtonIteration(CVodeMem cv_mem) mnewt = ++m; /* Stop at maxcor iterations or if iter. seems to be diverging. - If still not converged and Jacobian data is not current, + If still not converged and Jacobian data is not current, signal to try the solution again */ if ((m == maxcor) || ((m >= 2) && (del > RDIV * delp))) { @@ -2929,7 +2973,7 @@ CVNewtonIteration(CVodeMem cv_mem) This routine takes action on the return value nflag = *nflagPtr returned by CVnls, as follows: - + If CVnls succeeded in solving the nonlinear system, then CVHandleNFlag returns the constant DO_ERROR_TEST, which tells CVStep to perform the error test. @@ -2943,10 +2987,10 @@ CVNewtonIteration(CVodeMem cv_mem) If it failed due to an unrecoverable failure in solve, then we return the value SOLVE_FAILED. - Otherwise, a recoverable failure occurred when solving the - nonlinear system (CVnls returned nflag == CONV_FAIL). + Otherwise, a recoverable failure occurred when solving the + nonlinear system (CVnls returned nflag == CONV_FAIL). In this case, we return the value REP_CONV_FAIL if ncf is now - equal to MXNCF or |h| = hmin. + equal to MXNCF or |h| = hmin. If not, we set *nflagPtr = PREV_CONV_FAIL and return the value PREDICT_AGAIN, telling CVStep to reattempt the step. @@ -3008,14 +3052,14 @@ CVRestore(CVodeMem cv_mem, realtype saved_t) /******************* CVDoErrorTest ******************************** - This routine performs the local error test. - The weighted local error norm dsm is loaded into *dsmPtr, and + This routine performs the local error test. + The weighted local error norm dsm is loaded into *dsmPtr, and the test dsm ?<= 1 is made. - If the test passes, CVDoErrorTest returns TRUE. + If the test passes, CVDoErrorTest returns TRUE. - If the test fails, we undo the step just taken (call CVRestore), - set *nflagPtr to PREV_ERR_FAIL, and return FALSE. + If the test fails, we undo the step just taken (call CVRestore), + set *nflagPtr to PREV_ERR_FAIL, and return FALSE. If MXNEF error test failures have occurred or if ABS(h) = hmin, we set *kflagPtr = REP_ERR_FAIL. (Otherwise *kflagPtr has the @@ -3102,7 +3146,7 @@ CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr, /*************** CVCompleteStep ********************************** This routine performs various update operations when the solution - to the nonlinear system has passed the local error test. + to the nonlinear system has passed the local error test. We increment the step counter nst, record the values hu and qu, update the tau array, and apply the corrections to the zn array. The tau[i] are the last q values of h, with tau[1] the most recent. @@ -3141,8 +3185,8 @@ CVCompleteStep(CVodeMem cv_mem) This routine handles the setting of stepsize and order for the next step -- hprime and qprime. Along with hprime, it sets the - ratio eta = hprime/h. It also updates other state variables - related to a change of step size or order. + ratio eta = hprime/h. It also updates other state variables + related to a change of step size or order. ******************************************************************/ @@ -3171,7 +3215,7 @@ CVPrepareNextStep(CVodeMem cv_mem, realtype dsm) return; } - /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are + /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are the ratios of new to old h at orders q-1 and q+1, respectively. CVChooseEta selects the largest; CVSetEta adjusts eta and acor */ qwait = 2; @@ -3259,7 +3303,7 @@ CVComputeEtaqp1(CVodeMem cv_mem) /******************* CVChooseEta ********************************** Given etaqm1, etaq, etaqp1 (the values of eta for qprime = - q - 1, q, or q + 1, respectively), this routine chooses the + q - 1, q, or q + 1, respectively), this routine chooses the maximum eta value, sets eta to that value, and sets qprime to the corresponding value of q. If there is a tie, the preference order is to (1) keep the same order, then (2) decrease the order, @@ -3340,7 +3384,7 @@ CVHandleFailure(CVodeMem cv_mem, int kflag) } return (SETUP_FAILURE); case SOLVE_FAILED: - { + { char * error_string = CVMEM sformatf(MSG_SOLVE_FAILED, (double) tn); CVMEM warning_msg(error_string); } @@ -3415,21 +3459,21 @@ CVBDFStab(CVodeMem cv_mem) } else { - /* Otherwise, let order increase happen, and + /* Otherwise, let order increase happen, and reset stability limit counter, nscon. */ nscon = 0; } } /********************* CVsldet ************************************ - This routine detects stability limitation using stored scaled + This routine detects stability limitation using stored scaled derivatives data. CVsldet returns the magnitude of the dominate characteristic root, rr. The presents of a stability - limit is indicated by rr > "something a little less then 1.0", + limit is indicated by rr > "something a little less then 1.0", and a positive kflag. This routine should only be called if order is greater than or equal to 3, and data has been collected - for 5 time steps. - + for 5 time steps. + Returned values: kflag = 1 -> Found stable characteristic root, normal matrix case kflag = 2 -> Found stable characteristic root, quartic solution @@ -3440,14 +3484,14 @@ CVBDFStab(CVodeMem cv_mem) kflag = 6 -> Found stability violation, quartic solution, with Newton correction - kflag < 0 -> No stability limitation, + kflag < 0 -> No stability limitation, or could not compute limitation. kflag = -1 -> Min/max ratio of ssdat too small. kflag = -2 -> For normal matrix case, vmax > vrrt2*vrrt2 kflag = -3 -> For normal matrix case, The three ratios are inconsistent. - kflag = -4 -> Small coefficient prevents elimination of quartics. + kflag = -4 -> Small coefficient prevents elimination of quartics. kflag = -5 -> R value from quartics not consistent. kflag = -6 -> No corrected root passes test on qk values kflag = -7 -> Trouble solving for sigsq. @@ -3532,8 +3576,8 @@ CVsldet(CVodeMem cv_mem) } /* End of k loop */ /* Isolate normal or nearly-normal matrix case. Three quartic will - have common or nearly-common roots in this case. - Return a kflag = 1 if this procedure works. If three root + have common or nearly-common roots in this case. + Return a kflag = 1 if this procedure works. If three root differ more than vrrt2, return error kflag = -3. */ vmin = MIN(vrat[1], MIN(vrat[2], vrat[3])); diff --git a/cvode.h b/cvode.h index a4fbb891..57e72692 100644 --- a/cvode.h +++ b/cvode.h @@ -1,20 +1,64 @@ #ifndef _INC_CVODE_H #define _INC_CVODE_H -/******************************************************************* - * * - * File : cvode.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban * - * and Dan Shumaker @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/cvode/LICENSE * - *-----------------------------------------------------------------* - * This is the interface file for the main CVODE integrator. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : cvode.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban * + * and Dan Shumaker @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the interface file for the main CVODE integrator. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _cvode_h #define _cvode_h @@ -95,11 +139,11 @@ /****************************************************************** * * * Type : RhsFn * - *----------------------------------------------------------------* + *----------------------------------------------------------------* * The f function which defines the right hand side of the ODE * * system y' = f(t,y) must have type RhsFn. * * f takes as input the problem size N, the independent variable * - * value t, and the dependent variable vector y. It stores the * + * value t, and the dependent variable vector y. It stores the * * result of f(t,y) in the vector ydot. The y and ydot arguments * * are of type N_Vector. * * (Allocation of memory for ydot is handled within CVODE.) * @@ -124,7 +168,7 @@ * * * N is the number of equations in the ODE system. * * * - * f is the right hand side function in y' = f(t,y). * + * f is the right hand side function in y' = f(t,y). * * * * t0 is the initial value of t. * * * @@ -195,7 +239,7 @@ * (*reltol) and either (*abstol), for a scalar absolute * * tolerance, or the components of abstol, for a vector * * absolute tolerance. * - * * + * * * If successful, CVodeMalloc returns a pointer to initialized * * problem memory. This pointer should be passed to CVode. If * * an initialization error occurs, CVodeMalloc prints an error * @@ -401,7 +445,7 @@ * BAD_DKY : The dky argument was NULL. * * * * DKY_NO_MEM : The cvode_mem argument was NULL. * - * * + * * ******************************************************************/ @@ -452,7 +496,7 @@ * the solver in its attempt to reach tout. * * Optional input. (Default = 500). * * * - * iopt[MXHNIL] : maximum number of warning messages issued by the* + * iopt[MXHNIL] : maximum number of warning messages issued by the* * solver that t + h = t on the next internal step.* * A value of -1 means no such messages are issued.* * Optional input. (Default = 10). * @@ -760,7 +804,7 @@ * NO_FAILURES : Either this is the first cv_setup call for this * * step, or the local error test failed on the * * previous attempt at this step (but the Newton * - * iteration converged). * + * iteration converged). * * * * FAIL_BAD_J : This value is passed to cv_lsetup if * * * diff --git a/dense.cpp b/dense.cpp index c8f753f9..059fa6cc 100644 --- a/dense.cpp +++ b/dense.cpp @@ -1,19 +1,63 @@ -/******************************************************************* - * * - * File : dense.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic DENSE linear * - * solver package. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : dense.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include #include diff --git a/dense.h b/dense.h index ac8c69bf..2e23263f 100644 --- a/dense.h +++ b/dense.h @@ -1,42 +1,86 @@ #ifndef _INC_DENSE_H #define _INC_DENSE_H -/******************************************************************* - * * - * File : dense.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * - * Radu Serban @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic DENSE linear solver * - * package. The routines listed in this file all use type * - * DenseMat, defined below, for matrices. These routines in turn * - * call routines in the smalldense.h/smalldense.c module, which * - * use the type realtype** for matrices. This separation allows * - * for possible modifications in which matrices of type DenseMat * - * may not be stored contiguously, while small matrices can still * - * be treated with the routines in smalldense. * - * * - * Routines that work with the type DenseMat begin with "Dense". * - * The DenseAllocMat function allocates a dense matrix for use in * - * the other DenseMat routines listed in this file. Matrix * - * storage details are given in the documentation for the type * - * DenseMat. The DenseAllocPiv function allocates memory for * - * pivot information. The storage allocated by DenseAllocMat and * - * DenseAllocPiv is deallocated by the routines DenseFreeMat and * - * DenseFreePiv, respectively. The DenseFactor and DenseBacksolve * - * routines perform the actual solution of a dense linear system. * - * * - * Routines that work with realtype** begin with "den" (except for * - * the factor and solve routines which are called gefa and gesl, * - * respectively). The underlying matrix storage is described in * - * the documentation for denalloc in smalldense.h * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : dense.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, and * + * Radu Serban @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the header file for a generic DENSE linear solver * + * package. The routines listed in this file all use type * + * DenseMat, defined below, for matrices. These routines in turn * + * call routines in the smalldense.h/smalldense.c module, which * + * use the type realtype** for matrices. This separation allows * + * for possible modifications in which matrices of type DenseMat * + * may not be stored contiguously, while small matrices can still * + * be treated with the routines in smalldense. * + * * + * Routines that work with the type DenseMat begin with "Dense". * + * The DenseAllocMat function allocates a dense matrix for use in * + * the other DenseMat routines listed in this file. Matrix * + * storage details are given in the documentation for the type * + * DenseMat. The DenseAllocPiv function allocates memory for * + * pivot information. The storage allocated by DenseAllocMat and * + * DenseAllocPiv is deallocated by the routines DenseFreeMat and * + * DenseFreePiv, respectively. The DenseFactor and DenseBacksolve * + * routines perform the actual solution of a dense linear system. * + * * + * Routines that work with realtype** begin with "den" (except for * + * the factor and solve routines which are called gefa and gesl, * + * respectively). The underlying matrix storage is described in * + * the documentation for denalloc in smalldense.h * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _dense_h #define _dense_h @@ -121,8 +165,8 @@ * returns the storage allocated (type DenseMat). DenseAllocMat * * returns NULL if the request for matrix storage cannot be * * satisfied. See the above documentation for the type DenseMat * - * for matrix storage details. * - * * + * for matrix storage details. * + * * ******************************************************************/ DenseMat DenseAllocMat(integertype N); @@ -140,7 +184,7 @@ * information is an array of N integers and this routine returns * * the pointer to the memory it allocates. If the request for * * pivot storage cannot be satisfied, DenseAllocPiv returns NULL. * - * * + * * ******************************************************************/ integertype *DenseAllocPiv(integertype N); diff --git a/nvector.cpp b/nvector.cpp index f467c77d..010ac16a 100644 --- a/nvector.cpp +++ b/nvector.cpp @@ -1,19 +1,63 @@ -/******************************************************************* - * * - * File : nvector.c * - * Programmers : Radu Serban, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic NVECTOR * - * package. It contains the implementation of the N_Vector * - * kernels listed in nvector.h. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : nvector.c * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for a generic NVECTOR * + * package. It contains the implementation of the N_Vector * + * kernels listed in nvector.h. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include "nvector.h" /* generic M_Env and N_Vector */ diff --git a/nvector.h b/nvector.h index 77673d9c..fa32f832 100644 --- a/nvector.h +++ b/nvector.h @@ -1,44 +1,88 @@ -/******************************************************************* - * * - * File : nvector.h * - * Programmers : Radu Serban, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic NVECTOR package. * - * It defines the N_Vector and M_Env structures: * - * M_Env has an implementation-dependent 'content' field * - * which contains the data needed to generate a new * - * nvector in that implementation and an 'ops' filed * - * which is a structure listing operations acting on * - * such nvectors. * - * N_Vector has an implementation-dependent 'content' field * - * which contains the description and actual data of * - * the nvector and a 'menv' field which points to the * - * M_Env structure used in creating the nvector. * - * * - * Part I of this file contains type declarations for the * - * the following structures: _generic_M_Env, _generic_N_Vector, * - * and _generic_N_Vector_Ops, as well as references to pointers * - * to such structures (M_Env and N_Vector). * - * * - * Part II of this file contains the prototypes for the vector * - * kernels which operate on N_Vector. * - * * - * A particular implementation of an NVECTOR package must then * - * specify the 'content' fields of M_Env and N_Vector, define * - * the propotypes for kernel operations on those N_Vectors * - * (NOTE: kernel routine names must be unique to that * - * implementation), and finally provide an initialization * - * routine (which generates an M_Env with that particular * - * 'content' field and links the defined vector kernel routines * - * into the 'ops' field). * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : nvector.h * + * Programmers : Radu Serban, LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the header file for a generic NVECTOR package. * + * It defines the N_Vector and M_Env structures: * + * M_Env has an implementation-dependent 'content' field * + * which contains the data needed to generate a new * + * nvector in that implementation and an 'ops' filed * + * which is a structure listing operations acting on * + * such nvectors. * + * N_Vector has an implementation-dependent 'content' field * + * which contains the description and actual data of * + * the nvector and a 'menv' field which points to the * + * M_Env structure used in creating the nvector. * + * * + * Part I of this file contains type declarations for the * + * the following structures: _generic_M_Env, _generic_N_Vector, * + * and _generic_N_Vector_Ops, as well as references to pointers * + * to such structures (M_Env and N_Vector). * + * * + * Part II of this file contains the prototypes for the vector * + * kernels which operate on N_Vector. * + * * + * A particular implementation of an NVECTOR package must then * + * specify the 'content' fields of M_Env and N_Vector, define * + * the propotypes for kernel operations on those N_Vectors * + * (NOTE: kernel routine names must be unique to that * + * implementation), and finally provide an initialization * + * routine (which generates an M_Env with that particular * + * 'content' field and links the defined vector kernel routines * + * into the 'ops' field). * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ class Phreeqc; #ifndef included_nvector_h @@ -99,7 +143,7 @@ class Phreeqc; /* A machine environment is a structure with an implementation dependent 'content' representation (used to generate a new vector - in that implementation), a set of operations defined in the above + in that implementation), a set of operations defined in the above structure, and an ID tag */ struct _generic_M_Env { @@ -110,7 +154,7 @@ class Phreeqc; }; /* A vector is a structure with an implementation dependent content - representation and a pointer to the machine environment + representation and a pointer to the machine environment corresponding to that implementation */ struct _generic_N_Vector { diff --git a/nvector_serial.cpp b/nvector_serial.cpp index 5541fe91..9c7527a9 100644 --- a/nvector_serial.cpp +++ b/nvector_serial.cpp @@ -1,23 +1,66 @@ -/******************************************************************* - * * - * File : nvector_serial.c * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * - * Radu Serban, and Allan G. Taylor, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a serial implementation * - * of the NVECTOR package. It contains the implementation of * - * the serial machine environment intialization and free * - * routines (and of the Fortran callable interfaces to them) * - * and of the N_Vector kernels listed in nvector_serial.h. * - * * - *******************************************************************/ - +/************************************************************************** + * * + * File : nvector_serial.c * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * + * Radu Serban, and Allan G. Taylor, LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for a serial implementation * + * of the NVECTOR package. It contains the implementation of * + * the serial machine environment intialization and free * + * routines (and of the Fortran callable interfaces to them) * + * and of the N_Vector kernels listed in nvector_serial.h. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include #include #include @@ -57,7 +100,7 @@ static void VScaleBy_Serial(realtype a, N_Vector x); /********************* Exported Functions ************************/ -/* Serial implementation of the machine environment +/* Serial implementation of the machine environment initialization routine */ M_Env @@ -128,7 +171,7 @@ M_EnvInit_Serial(integertype vec_length) } -/* Serial implementation of the machine environment +/* Serial implementation of the machine environment free routine */ void diff --git a/nvector_serial.h b/nvector_serial.h index 288b1a7a..8a5ecb90 100644 --- a/nvector_serial.h +++ b/nvector_serial.h @@ -1,59 +1,103 @@ #ifndef _INC_NVECTOR_SERIAL_H #define _INC_NVECTOR_SERIAL_H -/******************************************************************* - * * - * File : nvector_serial.h * - * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * - * : Radu Serban, and Allan G. Taylor, LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a serial implementation of the * - * NVECTOR package. * - * * - * Part I of this file contains declarations which are specific * - * to the particular machine environment in which this version * - * of the vector package is to be used. This includes the * - * typedef for the 'content' fields of the structures M_Env and * - * N_Vector (M_EnvSerialContent and N_VectorSerialContent, * - * respectively). * - * * - * Part II of this file defines accessor macros that allow the * - * user to use efficiently the type N_Vector without making * - * explicit references to its underlying representation. * - * * - * Part III of this file contains the prototype for the * - * initialization routine specific to this implementation * - * (M_EnvInit_Serial) as well as prototypes for the vector * - * kernels which operate on the serial N_Vector. These * - * prototypes are unique to this particular implementation of * - * the vector package. * - * * - * NOTES: * - * * - * The definitions of the generic M_Env and N_Vector structures * - * are in the header file nvector.h. * - * * - * The definitions of the types realtype and integertype are in * - * the header file sundialstypes.h and these may be changed * - * according to the user's needs. The sundialstypes.h file also * - * contains the definition for the type booleantype. * - * * - * N_Vector arguments to arithmetic kernels need not be * - * distinct. Thus, for example, the call * - * N_VLinearSum_Serial(a,x,b,y,y); y <- ax+by * - * is legal. * - * * - * This version of nvector is for the ordinary sequential * - * machine environment. In the documentation given below, N is * - * the length of all N_Vector parameters and x[i] denotes the * - * ith component of the N_Vector x, where 0 <= i <= N-1. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : nvector_serial.h * + * Programmers : Scott D. Cohen, Alan C. Hindmarsh, * + * : Radu Serban, and Allan G. Taylor, LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the header file for a serial implementation of the * + * NVECTOR package. * + * * + * Part I of this file contains declarations which are specific * + * to the particular machine environment in which this version * + * of the vector package is to be used. This includes the * + * typedef for the 'content' fields of the structures M_Env and * + * N_Vector (M_EnvSerialContent and N_VectorSerialContent, * + * respectively). * + * * + * Part II of this file defines accessor macros that allow the * + * user to use efficiently the type N_Vector without making * + * explicit references to its underlying representation. * + * * + * Part III of this file contains the prototype for the * + * initialization routine specific to this implementation * + * (M_EnvInit_Serial) as well as prototypes for the vector * + * kernels which operate on the serial N_Vector. These * + * prototypes are unique to this particular implementation of * + * the vector package. * + * * + * NOTES: * + * * + * The definitions of the generic M_Env and N_Vector structures * + * are in the header file nvector.h. * + * * + * The definitions of the types realtype and integertype are in * + * the header file sundialstypes.h and these may be changed * + * according to the user's needs. The sundialstypes.h file also * + * contains the definition for the type booleantype. * + * * + * N_Vector arguments to arithmetic kernels need not be * + * distinct. Thus, for example, the call * + * N_VLinearSum_Serial(a,x,b,y,y); y <- ax+by * + * is legal. * + * * + * This version of nvector is for the ordinary sequential * + * machine environment. In the documentation given below, N is * + * the length of all N_Vector parameters and x[i] denotes the * + * ith component of the N_Vector x, where 0 <= i <= N-1. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef included_nvector_serial_h #define included_nvector_serial_h @@ -66,7 +110,7 @@ * Serial implementaion of M_Env and N_Vector * ****************************************************************/ -/* The serial implementation of the machine environment has +/* The serial implementation of the machine environment has ID tag 'serial' */ #define ID_TAG_S "serial" @@ -80,8 +124,8 @@ typedef struct _M_EnvSerialContent *M_EnvSerialContent; -/* The serial implementation of the N_Vector 'content' - structure contains the length of the vector and a pointer +/* The serial implementation of the N_Vector 'content' + structure contains the length of the vector and a pointer to an array of realtype components */ struct _N_VectorSerialContent @@ -148,11 +192,11 @@ * (3) ME_CONTENT_S, NV_CONTENT_S * * * * These routines give access to the contents of the serial * - * machine environment and N_Vector, respectively. * + * machine environment and N_Vector, respectively. * * * * The assignment m_cont = ME_CONTENT_S(machenv) sets * * m_cont to be a pointer to the serial machine * - * environment content structure. * + * environment content structure. * * * * The assignment v_cont = NV_CONTENT_S(v) sets * * v_cont to be a pointer to the serial N_Vector content * @@ -166,7 +210,7 @@ * The assignment v_data=NV_DATA_S(v) sets v_data to be * * a pointer to the first component of v. The assignment * * NV_DATA_S(v)=v_data sets the component array of v to * - * be v_data by storing the pointer v_data. * + * be v_data by storing the pointer v_data. * * * * The assignment v_len=NV_LENGTH_S(v) sets v_len to be * * the length of v. The call NV_LENGTH_S(v)=len_v sets * @@ -277,7 +321,7 @@ void M_EnvFree_Serial(M_Env machenv); /*--------------------------------------------------------------* - * Serial implementations of the vector operations * + * Serial implementations of the vector operations * * * * For a complete description of each of the following routines * * see the header file nvector.h * diff --git a/smalldense.cpp b/smalldense.cpp index c1e4e59b..e6365efa 100644 --- a/smalldense.cpp +++ b/smalldense.cpp @@ -1,18 +1,62 @@ -/******************************************************************* - * * - * File : smalldense.c * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a generic DENSE linear * - * solver package, intended for small dense matrices. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : smalldense.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for a generic DENSE linear * + * solver package, intended for small dense matrices. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include #include diff --git a/smalldense.h b/smalldense.h index c7410427..f7a3e79a 100644 --- a/smalldense.h +++ b/smalldense.h @@ -1,24 +1,68 @@ -/******************************************************************* - * * - * File : smalldense.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a generic DENSE linear solver * - * package, intended for small dense matrices. These routines * - * use the type realtype** for dense matrix arguments. * - * * - * These routines begin with "den" (except for the factor and * - * solve routines which are called gefa and gesl, respectively). * - * The underlying matrix storage is described in the * - * documentation for denalloc. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : smalldense.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *----------------------------------------------------------------- * + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *----------------------------------------------------------------- * + * This is the header file for a generic DENSE linear solver * + * package, intended for small dense matrices. These routines * + * use the type realtype** for dense matrix arguments. * + * * + * These routines begin with "den" (except for the factor and * + * solve routines which are called gefa and gesl, respectively). * + * The underlying matrix storage is described in the * + * documentation for denalloc. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _smalldense_h #define _smalldense_h @@ -88,7 +132,7 @@ * triangular matrix, then the upper triangular part of a * * (including its diagonal) contains U and the strictly lower * * triangular part of a contains the multipliers, I-L. * - * * + * * * gefa returns 0 if successful. Otherwise it encountered a zero * * diagonal element during the factorization. In this case it * * returns the column index (numbered from one) at which it * diff --git a/sundialsmath.cpp b/sundialsmath.cpp index 7d753816..c060716f 100644 --- a/sundialsmath.cpp +++ b/sundialsmath.cpp @@ -1,17 +1,61 @@ -/******************************************************************* - * * - * File : sundialsmath.c * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the implementation file for a C math library. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : sundialsmath.c * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the implementation file for a C math library. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #include diff --git a/sundialsmath.h b/sundialsmath.h index 0cb022fb..59e49d3a 100644 --- a/sundialsmath.h +++ b/sundialsmath.h @@ -1,27 +1,71 @@ -/******************************************************************* - * * - * File : sundialsmath.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This is the header file for a C math library. The routines * - * listed here work with the type realtype as defined in * - * sundialstypes.h. * - * To do single precision floating point arithmetic, set the type * - * realtype to be float. To do double precision arithmetic, set * - * the type realtype to be double. The default implementations * - * for RPowerR and RSqrt call standard math library functions * - * which do double precision arithmetic. If this is unacceptable * - * when realtype is float, then the user should re-implement * - * these two routines by calling single precision routines * - * available on his/her machine. * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : sundialsmath.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This is the header file for a C math library. The routines * + * listed here work with the type realtype as defined in * + * sundialstypes.h. * + * To do single precision floating point arithmetic, set the type * + * realtype to be float. To do double precision arithmetic, set * + * the type realtype to be double. The default implementations * + * for RPowerR and RSqrt call standard math library functions * + * which do double precision arithmetic. If this is unacceptable * + * when realtype is float, then the user should re-implement * + * these two routines by calling single precision routines * + * available on his/her machine. * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _sundialsmath_h #define _sundialsmath_h diff --git a/sundialstypes.h b/sundialstypes.h index 3054a063..1003410f 100644 --- a/sundialstypes.h +++ b/sundialstypes.h @@ -4,69 +4,113 @@ #include "phrqtype.h" #ifndef _INC_SUNDIALSTYPES_H #define _INC_SUNDIALSTYPES_H -/******************************************************************* - * * - * File : sundialstypes.h * - * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * - * Version of : 26 June 2002 * - *-----------------------------------------------------------------* - * Copyright (c) 2002, The Regents of the University of California * - * Produced at the Lawrence Livermore National Laboratory * - * All rights reserved * - * For details, see sundials/shared/LICENSE * - *-----------------------------------------------------------------* - * This header file exports three types: realtype, integertype, * - * and booleantype, as well as the constants TRUE and FALSE. * - * * - * Users should #include "sundialstypes.h" in any file that * - * shhould be easily modifiable to work with different real or * - * integer types and use the exported names realtype and * - * integertype within such a file. * - * The types for realtype and integertype below have been set to * - * double and long int, respectively. A user should modify these * - * type declarations as he/she sees fit. For example, if a user * - * wants the work with type float because double precision * - * floating point arithmetic is too expensive on the user's * - * machine, then the definition below should be changed to: * - * * - * typedef float realtype; * - * * - * Similarly, if a user does not need to work with extremely large * - * integers (see the system header file for the limits * - * on type int and long int on your machine), then the user * - * should change the definition below to: * - * * - * typedef int integertype; * - * * - * The constants SUNDIALS_FLOAT, SUNDIALS_DOUBLE, SUNDIALS_INT, * - * SUNDIALS_LONG indicate the underlying types for realtype and * - * integertype. They should be set as follows: * - * * - * (1) #define SUNDIALS_FLOAT 1 * - * #define SUNDIALS_DOUBLE 0 (real is float) * - * * - * (2) #define SUNDIALS_FLOAT 0 * - * #define SUNDIALS_DOUBLE 1 (real is double) * - * * - * (3) #define SUNDIALS_INT 1 * - * #define SUNDIALS_LONG 0 (integer is int) * - * * - * (4) #define SUNDIALS_INT 0 * - * #define SUNDIALS_LONG 1 (integer is long int) * - * * - * Thus the legal types for realtype are float and double, while * - * the legal types for integertype are int and long int. * - * The macro RCONST gives a user a convenient way to define real * - * constants. To use the real constant 1.0, for example, the * - * user should write * - * * - * #define ONE RCONST(1.0) * - * * - * If realtype is double, then RCONST(1.0) expands to 1.0. * - * If realtype is float, then RCONST(1.0) expands to 1.0F. * - * There is never a need to explicitly cast 1.0 to (realtype). * - * * - *******************************************************************/ +/************************************************************************** + * * + * File : sundialstypes.h * + * Programmers : Scott D. Cohen and Alan C. Hindmarsh @ LLNL * + * Version of : 26 June 2002 * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California * + * Produced at the Lawrence Livermore National Laboratory * + * All rights reserved * + * For details, see LICENSE below * + *------------------------------------------------------------------------* + * This header file exports three types: realtype, integertype, * + * and booleantype, as well as the constants TRUE and FALSE. * + * * + * Users should #include "sundialstypes.h" in any file that * + * shhould be easily modifiable to work with different real or * + * integer types and use the exported names realtype and * + * integertype within such a file. * + * The types for realtype and integertype below have been set to * + * double and long int, respectively. A user should modify these * + * type declarations as he/she sees fit. For example, if a user * + * wants the work with type float because double precision * + * floating point arithmetic is too expensive on the user's * + * machine, then the definition below should be changed to: * + * * + * typedef float realtype; * + * * + * Similarly, if a user does not need to work with extremely large * + * integers (see the system header file for the limits * + * on type int and long int on your machine), then the user * + * should change the definition below to: * + * * + * typedef int integertype; * + * * + * The constants SUNDIALS_FLOAT, SUNDIALS_DOUBLE, SUNDIALS_INT, * + * SUNDIALS_LONG indicate the underlying types for realtype and * + * integertype. They should be set as follows: * + * * + * (1) #define SUNDIALS_FLOAT 1 * + * #define SUNDIALS_DOUBLE 0 (real is float) * + * * + * (2) #define SUNDIALS_FLOAT 0 * + * #define SUNDIALS_DOUBLE 1 (real is double) * + * * + * (3) #define SUNDIALS_INT 1 * + * #define SUNDIALS_LONG 0 (integer is int) * + * * + * (4) #define SUNDIALS_INT 0 * + * #define SUNDIALS_LONG 1 (integer is long int) * + * * + * Thus the legal types for realtype are float and double, while * + * the legal types for integertype are int and long int. * + * The macro RCONST gives a user a convenient way to define real * + * constants. To use the real constant 1.0, for example, the * + * user should write * + * * + * #define ONE RCONST(1.0) * + * * + * If realtype is double, then RCONST(1.0) expands to 1.0. * + * If realtype is float, then RCONST(1.0) expands to 1.0F. * + * There is never a need to explicitly cast 1.0 to (realtype). * + * * + *------------------------------------------------------------------------* + * LICENSE * + *------------------------------------------------------------------------* + * Copyright (c) 2002, The Regents of the University of California. * + * Produced at the Lawrence Livermore National Laboratory. * + * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, * + * D. Shumaker, and A.G. Taylor. * + * UCRL-CODE-155951 (CVODE) * + * UCRL-CODE-155950 (CVODES) * + * UCRL-CODE-155952 (IDA) * + * UCRL-CODE-237203 (IDAS) * + * UCRL-CODE-155953 (KINSOL) * + * All rights reserved. * + * * + * This file is part of SUNDIALS. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the disclaimer below. * + * * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the disclaimer (as noted below) * + * in the documentation and/or other materials provided with the * + * distribution. * + * * + * 3. Neither the name of the UC/LLNL nor the names of its contributors * + * may be used to endorse or promote products derived from this software * + * without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * + * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY * + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + **************************************************************************/ #ifndef _sundialstypes_h #define _sundialstypes_h From 9d05f14cbdd264225e88376b9e3fd7b855ef94a1 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 8 May 2014 02:38:33 +0000 Subject: [PATCH 0820/1077] removed extra comma git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8729 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/print.cpp b/print.cpp index 033fefda..e0765620 100644 --- a/print.cpp +++ b/print.cpp @@ -63,7 +63,7 @@ set_pr_in_false(void) { cxxGasPhase *gas_phase_ptr = use.Get_gas_phase_ptr(); for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++) - { + { cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[i]); int k; struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); @@ -151,7 +151,7 @@ punch_all(void) { use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, -2)); } -#if defined PHREEQ98 +#if defined PHREEQ98 if (pr.user_graph == TRUE) { punch_user_graph(); @@ -171,7 +171,7 @@ punch_all(void) current_selected_output = &(so_it->second); if (pr.punch == FALSE || current_selected_output == NULL || - !current_selected_output->Get_active() /* || + !current_selected_output->Get_active() /* || current_selected_output->Get_punch_ostream() == NULL*/) continue; phrq_io->Set_punch_ostream(current_selected_output->Get_punch_ostream()); @@ -630,7 +630,7 @@ print_gas_phase(void) { /* * Calculate partial pressure - */ + */ cxxGasComp *gc_ptr = &(gas_phase_ptr->Get_gas_comps()[j]); int k; struct phase *phase_ptr = phase_bsearch(gc_ptr->Get_phase_name().c_str(), &k, FALSE); @@ -677,7 +677,7 @@ print_gas_phase(void) (double) lp, (double) phase_ptr->p_soln_x, (double) phase_ptr->pr_phi, - (double) initial_moles, + (double) initial_moles, (double) moles, (double) delta_moles)); } @@ -686,7 +686,7 @@ print_gas_phase(void) phase_ptr->name, (double) lp, (double) phase_ptr->p_soln_x, - (double) initial_moles, + (double) initial_moles, (double) moles, (double) delta_moles)); if (!strcmp(phase_ptr->name, "H2O(g)") && phase_ptr->p_soln_x == 90) @@ -938,7 +938,7 @@ print_kinetics(void) } } } - else + else { if (reaction_step > kinetics_ptr->Get_count()) { @@ -1201,7 +1201,7 @@ print_saturation_indices(void) struct rxn_token *rxn_ptr; struct reaction *reaction_ptr; bool gas = true; - + if (pr.saturation_indices == FALSE || pr.all == FALSE) return (OK); if (state == INITIAL_SOLUTION) @@ -1279,7 +1279,7 @@ print_saturation_indices(void) { output_msg(sformatf("\t%s%5.1f%s%5.3f", " Pressure ", (double) phases[i]->pr_p, " atm, phi ", (double) phases[i]->pr_phi)); - } else + } else { for (int j = 0; j < count_unknowns; j++) { @@ -1298,7 +1298,7 @@ print_saturation_indices(void) phases[i]->pr_in = false; output_msg("\n"); } - output_msg(sformatf("\n%s\n%s", + output_msg(sformatf("\n%s\n%s", "**For a gas, SI = log10(fugacity). Fugacity = pressure * phi / 1 atm.", " For ideal gases, phi = 1.")); output_msg("\n\n"); @@ -1338,7 +1338,7 @@ print_pp_assemblage(void) { if (x[j]->type != PP) continue; - //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); + //cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[j]->pp_assemblage_comp_name); cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp * ) x[j]->pp_assemblage_comp_ptr; /* * Print saturation index @@ -1701,7 +1701,7 @@ print_surface(void) #endif (double) charge_ptr->Get_specific_area())); #ifdef NO_UTF8_ENCODING - output_msg(sformatf("\t%11.3e m2 for %11.3e g\n\n",, + output_msg(sformatf("\t%11.3e m2 for %11.3e g\n\n", #else output_msg(sformatf("\t%11.3e m² for %11.3e g\n\n", #endif @@ -2251,7 +2251,7 @@ print_totals(void) output_msg(sformatf("%45s%6.2f\n", "Temperature (°C) = ", #endif (double) tc_x)); - + if (patm_x != 1.0) { /* only print if different than default */ @@ -2447,7 +2447,7 @@ print_using(void) { if (state != TRANSPORT || transport_step > 0) { - cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); + cxxReaction *reaction_ptr = Utilities::Rxn_find(Rxn_reaction_map, use.Get_n_reaction_user()); output_msg(sformatf("Using reaction %d.\t%s\n", use.Get_n_reaction_user(), reaction_ptr->Get_description().c_str())); } @@ -2518,7 +2518,7 @@ punch_gas_phase(void) p = gas_phase_ptr->Get_total_p(); total_moles = gas_phase_ptr->Get_total_moles(); //volume = total_moles * R_LITER_ATM * tk_x / gas_phase_ptr->Get_total_p(); - //if (gas_phase_ptr->Get_v_m() > 0.03) + //if (gas_phase_ptr->Get_v_m() > 0.03) // volume = 0.03 * gas_phase_ptr->Get_total_moles(); volume = gas_phase_ptr->Get_volume(); @@ -2971,7 +2971,7 @@ punch_identifiers(void) } } } - else + else { if (reaction_step > use.Get_kinetics_ptr()->Get_count()) { @@ -3307,7 +3307,7 @@ punch_user_punch(void) return (OK); } -#if defined PHREEQ98 +#if defined PHREEQ98 /* ---------------------------------------------------------------------- */ int Phreeqc:: punch_user_graph(void) @@ -3474,7 +3474,7 @@ punch_user_graph(void) { chart->Add_new_series(); } - + chart->Set_colnr(chart->Get_ColumnOffset()); chart->Initialize_graph_pts(); if (chart->Get_rate_new_def()) @@ -3519,7 +3519,7 @@ char * Phreeqc:: sformatf(const char *format, ...) { bool success = false; - do + do { va_list args; va_start(args, format); @@ -3529,7 +3529,7 @@ sformatf(const char *format, ...) if (!success) { sformatf_buffer_size *= 2; - sformatf_buffer = (char *) PHRQ_realloc(sformatf_buffer, sformatf_buffer_size * sizeof(char)); + sformatf_buffer = (char *) PHRQ_realloc(sformatf_buffer, sformatf_buffer_size * sizeof(char)); if (sformatf_buffer == NULL) malloc_error(); } } From 0ff6f4815f31d846447a63fe0b00b71634243320 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 12 May 2014 18:07:46 +0000 Subject: [PATCH 0821/1077] Fixed bug with 18O, redox states not defined in default. Also, the logic for using -isotopes data was changed so that the last defined applies to all remaining solutions. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8741 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 4 ++++ inverse.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 19093da5..35a6286d 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -23,7 +23,11 @@ const struct const_iso Phreeqc::iso_defaults[] = { {"34S(6)", 10, 1}, {"34S(-2)", -30, 5}, {"2H", -28, 1}, + {"2H(1)", -28, 1}, + {"2H(0)", -28, 1}, {"18O", -5, .1}, + {"18O(-2)", -5, .1}, + {"18O(0)", -5, .1}, {"87Sr", .71, .01}, {"11B", 20, 5} }; diff --git a/inverse.cpp b/inverse.cpp index cf2230ae..a2cbda78 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -3772,6 +3772,13 @@ check_isotopes(struct inverse *inv_ptr) /* use solution-defined uncertainties second */ } + else if (inv_ptr->i_u[i].count_uncertainties > 0 + && inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1] != NAN) + { + kit->second.Set_x_ratio_uncertainty(inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1]); + + /* use solution-defined uncertainties second */ + } else if (kit->second.Get_ratio_uncertainty() != NAN) { kit->second.Set_x_ratio_uncertainty( From caf7554690d27671faa85f2b46410ee0fc4fa843 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 May 2014 20:07:04 +0000 Subject: [PATCH 0822/1077] Added solution number method. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8754 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 3 +++ Phreeqc.h | 1 + basicsubs.cpp | 38 +++++++++++++++++++++++++++++++++++++- kinetics.cpp | 4 ++-- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 0cd0cce5..2f6b0f97 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3006,6 +3006,8 @@ factor(struct LOC_exec * LINK) n.UU.val = 1; break; } + n.UU.val = PhreeqcPtr->solution_number(); +#ifdef SKIP if (PhreeqcPtr->state == TRANSPORT) { n.UU.val = PhreeqcPtr->cell_no; @@ -3033,6 +3035,7 @@ factor(struct LOC_exec * LINK) n.UU.val = PhreeqcPtr->use.Get_n_solution_user(); } } +#endif break; case toksim_no: diff --git a/Phreeqc.h b/Phreeqc.h index 2cc289f6..7d318a86 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -123,6 +123,7 @@ public: LDBLE pr_phi(const char *phase_name); LDBLE saturation_ratio(const char *phase_name); int saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si); + int solution_number(void); LDBLE solution_sum_secondary(const char *total_name); LDBLE sum_match_gases(const char *stemplate, const char *name); LDBLE sum_match_species(const char *stemplate, const char *name); diff --git a/basicsubs.cpp b/basicsubs.cpp index f53cb6b9..58a20b4c 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -9,6 +9,7 @@ #include "PPassemblage.h" #include "SSassemblage.h" #include "cxxKinetics.h" +#include "Solution.h" #include "Parser.h" /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -3356,7 +3357,42 @@ system_total_elt_secondary(const char *total_name) } return (OK); } - +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +solution_number(void) +/* ---------------------------------------------------------------------- */ +{ + Phreeqc * PhreeqcPtr = this; + int soln_no = -999; + if (PhreeqcPtr->state == TRANSPORT) + { + soln_no = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == PHAST) + { + soln_no = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state == ADVECTION) + { + soln_no = PhreeqcPtr->cell_no; + } + else if (PhreeqcPtr->state < REACTION) + { + soln_no = PhreeqcPtr->use.Get_solution_ptr()->Get_n_user(); + } + else + { + if (PhreeqcPtr->use.Get_mix_in()) + { + soln_no = PhreeqcPtr->use.Get_n_mix_user(); + } + else + { + soln_no = PhreeqcPtr->use.Get_n_solution_user(); + } + } + return soln_no; +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: solution_sum_secondary(const char *total_name) diff --git a/kinetics.cpp b/kinetics.cpp index 9ab60fe1..e1aa04c0 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1484,7 +1484,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, && use.Get_kinetics_ptr()->Get_use_cvode()) { error_string = sformatf( - "Numerical method failed on all parameter combinations, retrying integration"); + "Numerical method failed on all parameter combinations, retrying integration, cell/soln %d", this->solution_number()); warning_msg(error_string); converge = MASS_BALANCE; } @@ -1517,7 +1517,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, sum_species(); print_all(); error_string = sformatf( - "Numerical method failed on all combinations of convergence parameters"); + "Numerical method failed on all combinations of convergence parameters, cell/soln/mix %d", this->solution_number()); error_msg(error_string, STOP); } numerical_fixed_volume = false; From 6a75a7f38bf2c062728ddd43ec0748dfbefd8c70 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 May 2014 20:12:05 +0000 Subject: [PATCH 0823/1077] Changed calc_logk_s to use original equation. Checking for 0 gfws git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8755 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 12 ++++++------ tidy.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 58a20b4c..75714204 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -373,13 +373,13 @@ calc_logk_s(const char *name) { l_logk[i] = 0.0; } - if (s_ptr->moles) - select_log_k_expression(s_ptr->rxn_x->logk, l_logk); - else - { + //if (s_ptr->moles) + //select_log_k_expression(s_ptr->rxn_x->logk, l_logk); + select_log_k_expression(s_ptr->rxn->logk, l_logk); + //{ // perhaps calculate species' delta_v if absent? - select_log_k_expression(s_ptr->rxn_s->logk, l_logk); - } + // select_log_k_expression(s_ptr->rxn_s->logk, l_logk); + //} add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk); lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); return (lk); diff --git a/tidy.cpp b/tidy.cpp index 2e02565b..d8b37fc5 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3001,6 +3001,21 @@ tidy_species(void) s[i]->equiv = surface_coef; } } + + for (i = 0; i < count_master; i++) + { + if (master[i]->gfw <= 0.0) + { + if (master[i]->type >= EMINUS) continue; + if ((strcmp(master[i]->elt->name, "E") != 0) && (strcmp(master[i]->elt->name, "e") != 0)) + { + input_error++; + error_string = sformatf( + "Gram formula wt in SOLUTION_MASTER_SPECIES should not be <= 0.0, %s.\n", master[i]->elt->name); + error_msg(error_string, CONTINUE); + } + } + } return (OK); } /* ---------------------------------------------------------------------- */ From aa40f2e705ac10d09e765d5ebb63d6d8507cf4d5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 20 May 2014 20:42:32 +0000 Subject: [PATCH 0824/1077] latest, fixed bug from R with relative dielectric git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8756 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 2 +- tidy.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.old b/Makefile.old index 1815601e..373874be 100644 --- a/Makefile.old +++ b/Makefile.old @@ -173,7 +173,7 @@ ifeq ($(CFG), CLASS_RELEASE_64) CL1MP_OBJS=cl1mp.o CL1MP_LIB=/usr/lib64/libgmp.a endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DR_SO # -DPHREEQC2 VPATH = .. INCLUDES = -I.. CXX = g++ diff --git a/tidy.cpp b/tidy.cpp index d8b37fc5..a2168f42 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3007,7 +3007,11 @@ tidy_species(void) if (master[i]->gfw <= 0.0) { if (master[i]->type >= EMINUS) continue; - if ((strcmp(master[i]->elt->name, "E") != 0) && (strcmp(master[i]->elt->name, "e") != 0)) + if ((strcmp(master[i]->elt->name, "E") != 0) && + (strcmp(master[i]->elt->name, "e") != 0) && + (strcmp(master[i]->elt->name, "H(1)") != 0) && + (strcmp(master[i]->elt->name, "O(-2)") != 0) + ) { input_error++; error_string = sformatf( From 1c49558308a8578423d894cecd50607e1e84e7ee Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Jun 2014 19:04:46 +0000 Subject: [PATCH 0825/1077] Revised error message to give solution number, mainsubs.cpp. Don't call timing_barrier in phast_manager, time_parallel. Array to Concentrations2Solutions is nchem in size rather than nxyz in size. Modified: SetConcentrations Concentrations2Solutions Concentrations2SolutionsH2O Concentrations2SolutionsNoH2O git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8775 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- mainsubs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index c3835538..a13a29d2 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -643,7 +643,7 @@ initial_solutions(int print) if (converge == ERROR || converge1 == ERROR) { - error_msg("Model failed to converge for initial solution.", + error_msg(sformatf("%s %d.", "Model failed to converge for initial solution ", solution_ref.Get_n_user()), STOP); } n_user = solution_ref.Get_n_user(); From ab43d75b5f2017481f86d9c93bef3b72f470a762 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 Jun 2014 17:05:57 +0000 Subject: [PATCH 0826/1077] Had timing reversed in PhreeqcRM.cpp for heterogeneous case. Added AH2O_FACTOR 0.017 definition. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8778 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 1 + model.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/global_structures.h b/global_structures.h index 6a1402fc..e05e59fb 100644 --- a/global_structures.h +++ b/global_structures.h @@ -22,6 +22,7 @@ #define PASCAL_PER_ATM 1.01325E5 /* conversion from atm to Pa */ #define AVOGADRO 6.02252e23 /* atoms / mole */ #define pi 3.14159265358979 +#define AH2O_FACTOR 0.017 #define TRUE 1 #define FALSE 0 diff --git a/model.cpp b/model.cpp index 6777cd97..1c05cdeb 100644 --- a/model.cpp +++ b/model.cpp @@ -1941,7 +1941,7 @@ jacobian_sums(void) // factors for tanh attenuation to make ah2o positive LDBLE y_sum = ah2o_unknown->f; LDBLE x_h2o = mass_water_aq_x; - LDBLE a = 0.017; + LDBLE a = AH2O_FACTOR; LDBLE lim = 95.0 - 100.0*a*y_sum/x_h2o; LDBLE factor = -a*(x_h2o*(-0.5*tanh(lim) - 0.5) + (50.0*a*y_sum - 47.5 * x_h2o) / (cosh(lim)*cosh(lim))) / (x_h2o*x_h2o); @@ -1966,7 +1966,7 @@ jacobian_sums(void) { for (i = 0; i < count_unknowns; i++) { - array[ah2o_unknown->number * (count_unknowns + 1) + i] *= -0.017; + array[ah2o_unknown->number * (count_unknowns + 1) + i] *= -AH2O_FACTOR; } array[ah2o_unknown->number * (count_unknowns + 1) + ah2o_unknown->number] -= mass_water_aq_x * exp(s_h2o->la * LOG_10); @@ -3956,14 +3956,19 @@ residuals(void) { // a = 0.017; Y = sum(m(i)); X = Mw (mass of water) // Aw = (1 - a y/x) 0.5 (tanh(100 (0.95 - ay/x)) + 1) + 0.05 (0.5 (1 - tanh(100(0.95 - ay/x)))) - residual[i] = exp(s_h2o->la * LOG_10) - ((1.0 - 0.017 * x[i]->f/mass_water_aq_x) * - 0.5*(tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)) + 1) + - 0.05*0.5*(1.0 - tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)))) ; + //residual[i] = exp(s_h2o->la * LOG_10) - ((1.0 - 0.017 * x[i]->f/mass_water_aq_x) * + // 0.5*(tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)) + 1) + + // 0.05*0.5*(1.0 - tanh(100.0*(0.95 - 0.017*x[i]->f/mass_water_aq_x)))) ; + residual[i] = exp(s_h2o->la * LOG_10) - ((1.0 - AH2O_FACTOR * x[i]->f/mass_water_aq_x) * + 0.5*(tanh(100.0*(0.95 - AH2O_FACTOR*x[i]->f/mass_water_aq_x)) + 1) + + 0.05*0.5*(1.0 - tanh(100.0*(0.95 - AH2O_FACTOR*x[i]->f/mass_water_aq_x)))) ; } else { + //residual[i] = mass_water_aq_x * exp(s_h2o->la * LOG_10) - mass_water_aq_x + + // 0.017 * x[i]->f; residual[i] = mass_water_aq_x * exp(s_h2o->la * LOG_10) - mass_water_aq_x + - 0.017 * x[i]->f; + AH2O_FACTOR * x[i]->f; } if (pitzer_model || sit_model) From e4229340b02f8a3ec29938fb21e8966aad8baaea Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jun 2014 23:51:13 +0000 Subject: [PATCH 0827/1077] fixed memory leaks. commented lines are directives for visual studio _CRTDBG_MAP_ALLOC, _CrtSetDbgFlag VarClear in GetSelectedOutputHeading. RebalanceLoadPerCell fixed for serial version, clear clock times. delete out stream and punch stream before new, RunCells also set streams to NULL after deleted. also serial version. VarClear in RunCellsThreadNoPrint timing only if rebalance cell, RunCellsThreadNoPrint VarClear in RunCellsThread. changed methods to return pointer instead of reference, Get_out_stream ~IPhreeqcPhast, delete streams if necessary. phast_manager did not delete module for flow-only. phast_worker did not delete module for flow-only. return pointers: Get_out_stream Get_punch_stream IPhreeqc, delete default_data_base and sformatf_buffer in clean_up, not in operator = or ~phreeqc git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8784 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 14 ++++---------- structures.cpp | 2 ++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 35a6286d..83aefe68 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -38,10 +38,7 @@ Phreeqc::~Phreeqc(void) { clean_up(); - - free_check_null(default_data_base); - free_check_null(sformatf_buffer); - + PHRQ_free_all(); if (phrq_io == &ioInstance) { @@ -974,7 +971,7 @@ void Phreeqc::init(void) /* phrq_io_output.cpp ------------------------------- */ forward_output_to_log = 0; /* phreeqc_files.cpp ------------------------------- */ - default_data_base = string_duplicate("phreeqc.dat"); + default_data_base = string_duplicate("phreeqc.dat"); #ifdef PHREEQ98 int outputlinenr; char *LogFileNameC; @@ -1035,8 +1032,8 @@ void Phreeqc::init(void) /* print.cpp ------------------------------- */ sformatf_buffer = (char *) PHRQ_malloc(256 * sizeof(char)); if (sformatf_buffer == NULL) - malloc_error(); - sformatf_buffer_size = 256; + malloc_error(); + sformatf_buffer_size = 256; #ifdef PHREEQ98 int colnr, rownr; int graph_initial_solutions; @@ -2455,9 +2452,6 @@ Phreeqc &Phreeqc::operator=(const Phreeqc &rhs) // clean up this here this->clean_up(); - this->free_check_null(default_data_base); - this->free_check_null(sformatf_buffer); - this->PHRQ_free_all(); if (this->phrq_io == &this->ioInstance) { diff --git a/structures.cpp b/structures.cpp index b2f0973e..52f1bdc4 100644 --- a/structures.cpp +++ b/structures.cpp @@ -382,6 +382,8 @@ clean_up(void) count_isotope_ratio = 0; count_isotope_alpha = 0; + default_data_base = (char *) free_check_null(default_data_base); + sformatf_buffer = (char *) free_check_null(sformatf_buffer); return (OK); } /* ---------------------------------------------------------------------- */ From b93eda4643a402efc16db451253f9488d160262e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Jul 2014 19:05:54 +0000 Subject: [PATCH 0828/1077] Fixed leaks: SELECTED_OUTPUT redefinition, read_selected_output zero in cl1mp.cpp leak in eq_frac Basic function if file open failed, leaked ofstream pointer Don't close files in class_main.cpp cvdense and cvode changed to allow use of MS memory debugging git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8815 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 1 + PHRQ_io.cpp | 4 ++++ cl1mp.cpp | 1 + class_main.cpp | 12 ++++++++++-- cvdense.cpp | 6 ++++++ cvode.cpp | 2 ++ read.cpp | 2 +- 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 2f6b0f97..bfb2b17b 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3452,6 +3452,7 @@ factor(struct LOC_exec * LINK) if (LINK->t->kind != tokvar || elt_varrec->stringvar != 1) snerr(": Cannot find element string variable"); free_dim_stringvar(elt_varrec); + *elt_varrec->UU.U1.sval = (char *) PhreeqcPtr->free_check_null(*elt_varrec->UU.U1.sval); // right parenthesis LINK->t = LINK->t->next; diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 40a7639c..4bbb4404 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -54,6 +54,10 @@ ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode *os = ofs; return true; } + if (ofs) + { + delete ofs; + } return false; } diff --git a/cl1mp.cpp b/cl1mp.cpp index 170f7006..09b557a7 100644 --- a/cl1mp.cpp +++ b/cl1mp.cpp @@ -1109,6 +1109,7 @@ cl1mp(int k, int l, int m, int n, mpf_clear(cu[i]); } cu = (mpf_t *) free_check_null(cu); + mpf_clear(zero); mpf_clear(dummy); mpf_clear(dummy1); mpf_clear(sum); diff --git a/class_main.cpp b/class_main.cpp index 31174a31..837115fa 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -31,12 +31,21 @@ main(int argc, char *argv[]) * heap's linked list - This will allow us to catch any * inadvertent use of freed memory */ +#ifdef SKIP + // Send messages (leaks) to stderr + _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); + _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); + _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); + _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); +#endif tmpDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); //tmpDbgFlag |= _CRTDBG_DELAY_FREE_MEM_DF; tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 329203; + //_crtBreakAlloc = 31195; #endif #ifdef SKIP //Set the x86 floating-point control word according to what @@ -236,7 +245,6 @@ main_method(int argc, char *argv[]) { return errors; } - output_close(); return 0; } #endif //TEST_COPY diff --git a/cvdense.cpp b/cvdense.cpp index fde663e6..6101ddb1 100644 --- a/cvdense.cpp +++ b/cvdense.cpp @@ -72,7 +72,9 @@ #include "Phreeqc.h" +#if !defined(WIN32_MEMORY_DEBUG) #define malloc PHRQ_malloc +#endif #define MACHENV machEnv->phreeqc_ptr-> #define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> #define MACHENV_MALLOC MACHENV @@ -306,7 +308,11 @@ CVDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) lfree = CVDenseFree; /* Get memory for CVDenseMemRec */ +#if defined(WIN32_MEMORY_DEBUG) + lmem = cvdense_mem = (CVDenseMem) malloc(sizeof(CVDenseMemRec)); +#else lmem = cvdense_mem = (CVDenseMem) CVMEM_MALLOC malloc(sizeof(CVDenseMemRec)); +#endif if (cvdense_mem == NULL) { CVMEM warning_msg( MSG_MEM_FAIL); diff --git a/cvode.cpp b/cvode.cpp index 4d439d9d..e0baff80 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -72,7 +72,9 @@ #include "sundialsmath.h" #include "Phreeqc.h" +#if !defined(WIN32_MEMORY_DEBUG) #define malloc MACHENV_MALLOC PHRQ_malloc +#endif #define MACHENV machEnv->phreeqc_ptr-> #define CVMEM cv_mem->cv_machenv->phreeqc_ptr-> #define MACHENV_MALLOC MACHENV diff --git a/read.cpp b/read.cpp index 2a369aae..e4f1924a 100644 --- a/read.cpp +++ b/read.cpp @@ -9431,7 +9431,7 @@ read_user_punch(void) if (return_value == EOF || return_value == KEYWORD) break; } - + UserPunch_map.erase(n_user); UserPunch_map[n_user] = temp_user_punch; UserPunch_map[n_user].Set_rate(r); From 38ded3b2c6fafc192a647be31e1ac815ee32fb4d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 8 Jul 2014 19:53:00 +0000 Subject: [PATCH 0829/1077] valgrind changes/set-but-unused vars git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8818 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- integrate.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/integrate.cpp b/integrate.cpp index 73c688ae..4c9759d0 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -728,7 +728,6 @@ calc_all_donnan(void) int cd_m; LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif, var1; - LDBLE cz, cm, cp; if (use.Get_surface_ptr() == NULL) return (OK); @@ -736,8 +735,6 @@ calc_all_donnan(void) // tk_x * mu_x); f_sinh = sqrt(8000.0 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000.0) * tk_x * mu_x); - cz = cm = 1.0; - cp = 1.0; /* * calculate g for each surface... */ From 25508288fb17814790a2dd65f432052b9c02dad1 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 9 Jul 2014 01:46:43 +0000 Subject: [PATCH 0830/1077] removed set but not used variables using gcc 4.8.2[-Wunused-but-set-variable] git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8821 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 5 +---- GasComp.cxx | 6 +++--- GasPhase.cxx | 4 ---- KineticsComp.cxx | 2 -- PHRQ_io.cpp | 4 ---- PPassemblageComp.cxx | 6 +----- ReadClass.cxx | 2 -- StorageBinList.cpp | 4 +--- Surface.cxx | 3 --- cvode.cpp | 9 +++++---- cxxKinetics.cxx | 4 ---- dumper.cpp | 4 +--- inverse.cpp | 7 ++----- isotopes.cpp | 20 ++++++-------------- kinetics.cpp | 9 ++++----- mainsubs.cpp | 8 ++------ model.cpp | 4 ++-- pitzer.cpp | 11 ++--------- prep.cpp | 9 +++------ print.cpp | 4 +--- read.cpp | 9 ++------- runner.cpp | 4 +--- sit.cpp | 11 +++-------- tally.cpp | 22 ---------------------- transport.cpp | 13 ++----------- 25 files changed, 42 insertions(+), 142 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index 39f33eb6..b2b2c836 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -200,14 +200,12 @@ cxxExchange::read_raw(CParser & parser, bool check) std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; - int opt_save; bool useLastLine(false); // Read exchange number and description this->read_number_description(parser); this->Set_new_def(false); - opt_save = CParser::OPT_ERROR; bool pitzer_exchange_gammas_defined(false); for (;;) @@ -329,7 +327,6 @@ cxxExchange::read_raw(CParser & parser, bool check) ("Expected element name and molality for Exchange totals.", PHRQ_io::OT_CONTINUE); } - opt_save = 6; break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -446,4 +443,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("n_solution"), // 5 std::vector< std::string >::value_type("totals") // 6 }; -const std::vector< std::string > cxxExchange::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxExchange::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/GasComp.cxx b/GasComp.cxx index af3973b8..79aca1ad 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -67,9 +67,7 @@ cxxGasComp::read_raw(CParser & parser, bool check) std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; - int opt_save; - opt_save = CParser::OPT_ERROR; bool moles_defined(false); int opt; for (;;) @@ -145,12 +143,13 @@ cxxGasComp::read_raw(CParser & parser, bool check) void cxxGasComp::add(const cxxGasComp & addee, LDBLE extensive) { - LDBLE ext1, ext2, f1, f2; + //LDBLE ext1, ext2; if (extensive == 0.0) return; if (addee.phase_name.size() == 0) return; + /* ext1 = this->moles; ext2 = addee.moles * extensive; if (ext1 + ext2 != 0) @@ -163,6 +162,7 @@ cxxGasComp::add(const cxxGasComp & addee, LDBLE extensive) f1 = 0.5; f2 = 0.5; } + */ assert(this->phase_name == addee.phase_name); diff --git a/GasPhase.cxx b/GasPhase.cxx index d9645319..a99d3e3b 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -372,8 +372,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) bool type_defined(false); bool total_p_defined(false); bool volume_defined(false); - bool v_m_defined(false); - bool pr_in_defined(false); for (;;) { @@ -457,7 +455,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for v_m.", PHRQ_io::OT_CONTINUE); } - v_m_defined = true; useLastLine = false; break; case 4: // component @@ -509,7 +506,6 @@ cxxGasPhase::read_raw(CParser & parser, bool check) { this->pr_in = (i == 0) ? false : true; } - pr_in_defined = true; useLastLine = false; break; case 7: // new_def diff --git a/KineticsComp.cxx b/KineticsComp.cxx index 3164fa4f..d18be8fa 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -145,7 +145,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) bool tol_defined(false); bool m_defined(false); bool m0_defined(false); - bool moles_defined(false); bool d_params_defined(false); for (;;) @@ -214,7 +213,6 @@ cxxKineticsComp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for moles.", PHRQ_io::OT_CONTINUE); } - moles_defined = true; break; case 5: // namecoef diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 4bbb4404..23d08b1a 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -685,8 +685,6 @@ get_line(void) * OK, * OPTION */ - int i; - bool empty; std::string stdtoken; bool continue_loop = true;; @@ -704,8 +702,6 @@ get_line(void) /* * Eliminate all characters after # sign as a comment */ - i = -1; - empty = true; /* * Get line, check for eof */ diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 3bd2b185..0ab0f026 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -113,13 +113,11 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) opt_save = CParser::OPT_ERROR; bool si_defined(false); - bool si_org_defined(false); bool moles_defined(false); bool delta_defined(false); bool initial_moles_defined(false); bool dissolve_only_defined(false); bool force_equality_defined(false); - bool precipitate_only_defined(false); for (;;) { @@ -238,7 +236,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) parser.error_msg("Expected boolean value for precipitate_only.", PHRQ_io::OT_CONTINUE); } - precipitate_only_defined = true; if (this->precipitate_only) { this->dissolve_only = false; @@ -252,7 +249,6 @@ cxxPPassemblageComp::read_raw(CParser & parser, bool check) parser.error_msg("Expected numeric value for si_org.", PHRQ_io::OT_CONTINUE); } - si_org_defined = true; break; case 10: // totals if (this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) @@ -400,4 +396,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("si_org"), // 9 std::vector< std::string >::value_type("totals") // 10 }; -const std::vector< std::string > cxxPPassemblageComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxPPassemblageComp::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/ReadClass.cxx b/ReadClass.cxx index 06dbb045..7c416fd7 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -257,8 +257,6 @@ int Phreeqc:: delete_entities(void) /* ---------------------------------------------------------------------- */ { - int return_value; - return_value = OK; if (!delete_info.Get_solution().Get_defined() && !delete_info.Get_pp_assemblage().Get_defined() && !delete_info.Get_exchange().Get_defined() && diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 2311534f..1cbc4a54 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -145,7 +145,6 @@ bool StorageBinList::Read(CParser & parser) std::string token; int opt_save; - bool useLastLine(false); opt_save = CParser::OPT_DEFAULT; // reset cells this->cell.Clear(); @@ -283,7 +282,6 @@ bool StorageBinList::Read(CParser & parser) parser.error_msg("Unknown input reading DELETE definition.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; return_value = false; break; } @@ -340,4 +338,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pressure"), // 17 std::vector< std::string >::value_type("reaction_pressure") // 18 }; -const std::vector< std::string > StorageBinList::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > StorageBinList::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/Surface.cxx b/Surface.cxx index feecf284..359ba8ac 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -238,14 +238,12 @@ cxxSurface::read_raw(CParser & parser, bool check) std::istream::pos_type ptr; std::istream::pos_type next_char; std::string token; - int opt_save; bool useLastLine(false); // Read surface number and description this->read_number_description(parser); this->Set_new_def(false); - opt_save = CParser::OPT_ERROR; bool only_counter_ions_defined(false); bool thickness_defined(false); bool type_defined(false); @@ -516,7 +514,6 @@ cxxSurface::read_raw(CParser & parser, bool check) ("Expected element name and molality for Surface totals.", PHRQ_io::OT_CONTINUE); } - opt_save = 17; break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) diff --git a/cvode.cpp b/cvode.cpp index e0baff80..760fd464 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -3510,7 +3510,7 @@ CVsldet(CVodeMem cv_mem) realtype drr[4], rrc[4], sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4]; realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol; realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr; - realtype small_cvode, tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; + realtype /*small_cvode,*/ tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin; realtype rsa, rsb, rsc, rsd, rse, rd1a, rd1b, rd1c, rd1d; realtype rd2a, rd2b, rd2c, rd3a, rd3b, cest1, corr1; realtype ratp, ratm, qfac1, qfac2, bb, rrb; @@ -3620,7 +3620,7 @@ CVsldet(CVodeMem cv_mem) if (ABS(qco[1][1]) < TINY * ssmax[1]) { - small_cvode = qco[1][1]; + //small_cvode = qco[1][1]; kflag = -4; return (kflag); } @@ -3641,7 +3641,7 @@ CVsldet(CVodeMem cv_mem) if (ABS(qco[2][2]) < TINY * ssmax[2]) { - small_cvode = qco[2][2]; + //small_cvode = qco[2][2]; kflag = -4; return (kflag); } @@ -3654,7 +3654,7 @@ CVsldet(CVodeMem cv_mem) if (ABS(qco[4][3]) < TINY * ssmax[3]) { - small_cvode = qco[4][3]; + //small_cvode = qco[4][3]; kflag = -4; return (kflag); } @@ -3777,6 +3777,7 @@ CVsldet(CVodeMem cv_mem) rd2c = rd1c - rd1d; rd3a = rd2a - rd2b; rd3b = rd2b - rd2c; + rd3b = rd3b; if (ABS(rd1b) < TINY * smax[k]) { diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index 5d71ba27..c9fc7dc8 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -209,8 +209,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) bool cvode_steps_defined(false); bool cvode_order_defined(false); bool steps_defined(false); - bool equalIncrements_defined(false); - bool count_defined(false); for (;;) { @@ -387,7 +385,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser.error_msg("Expected boolean value for equalIncrements.", PHRQ_io::OT_CONTINUE); } - equalIncrements_defined = true; break; case 10: // count if (!(parser.get_iss() >> this->count)) @@ -397,7 +394,6 @@ cxxKinetics::read_raw(CParser & parser, bool check) parser.error_msg("Expected integer value for count.", PHRQ_io::OT_CONTINUE); } - count_defined = true; break; } diff --git a/dumper.cpp b/dumper.cpp index 2d708e43..031571ab 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -38,7 +38,6 @@ bool dumper::Read(CParser & parser) std::istream::pos_type next_char; std::string token; int opt_save; - bool useLastLine(false); opt_save = CParser::OPT_DEFAULT; bool cleared_once = false; @@ -211,7 +210,6 @@ bool dumper::Read(CParser & parser) parser.error_msg("Unknown input reading DUMP definition.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; return_value = false; break; } @@ -268,4 +266,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("reaction_pressure"), // 26 std::vector< std::string >::value_type("reaction_pressures") // 27 }; -const std::vector< std::string > dumper::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > dumper::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/inverse.cpp b/inverse.cpp index a2cbda78..fe49db44 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -21,7 +21,7 @@ inverse_models(void) * Go through list of inverse models, make calculations * for any marked "new". */ - int n, print1; + int n/*, print1*/; char string[MAX_LENGTH]; if (count_inverse <= 0) return OK; // Revert to previous headings after inverse modeling @@ -51,7 +51,6 @@ inverse_models(void) bad = NULL; minimal = NULL; - print1 = TRUE; state = INVERSE; dl_type_x = cxxSurface::NO_DL; @@ -3172,8 +3171,6 @@ test_cl1_solution(void) */ int i, j; LDBLE sum; - int local_debug_inverse = debug_inverse; - local_debug_inverse = TRUE; /* * Check equalities */ @@ -3252,7 +3249,7 @@ test_cl1_solution(void) } } - return (OK); + return (rv); } /* ---------------------------------------------------------------------- */ int Phreeqc:: diff --git a/isotopes.cpp b/isotopes.cpp index ac8c37b2..fc2eae2e 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -22,8 +22,8 @@ read_isotopes(void) * */ - int j, l; - struct master_isotope *master_isotope_ptr, *master_isotope_ptr_major; + int l; + struct master_isotope *master_isotope_ptr; char token[MAX_LENGTH]; struct element *elt_ptr; @@ -76,7 +76,7 @@ read_isotopes(void) * Save an isotope */ master_isotope_ptr = NULL; - j = copy_token(token, &next_char, &l); + copy_token(token, &next_char, &l); master_isotope_ptr = master_isotope_store(token, TRUE); master_isotope_ptr->elt = elt_ptr; master_isotope_ptr->minor_isotope = TRUE; @@ -130,7 +130,6 @@ read_isotopes(void) } elt_ptr = element_store(token); master_isotope_ptr = master_isotope_store(token, TRUE); - master_isotope_ptr_major = master_isotope_ptr; master_isotope_ptr->elt = elt_ptr; master_isotope_ptr->minor_isotope = FALSE; master_isotope_ptr->total_is_major = FALSE; @@ -162,7 +161,7 @@ read_calculate_values(void) * */ char *ptr; - int l, length, line_length, n; + int l, length, line_length; int return_value, opt, opt_save; char token[MAX_LENGTH]; struct calculate_value *calculate_value_ptr; @@ -177,7 +176,6 @@ read_calculate_values(void) /* * Read advection number (not currently used) */ - n = -1; ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); description = (char *) free_check_null(description); @@ -281,7 +279,7 @@ read_isotope_ratios(void) * */ char *ptr; - int l, n; + int l; int return_value, opt, opt_save; char token[MAX_LENGTH]; struct isotope_ratio *isotope_ratio_ptr; @@ -295,7 +293,6 @@ read_isotope_ratios(void) /* * Read number (not currently used) */ - n = -1; ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); description = (char *) free_check_null(description); @@ -381,7 +378,7 @@ read_isotope_alphas(void) * */ char *ptr; - int l, n; + int l; int return_value, opt, opt_save; char token[MAX_LENGTH]; struct isotope_alpha *isotope_alpha_ptr; @@ -395,7 +392,6 @@ read_isotope_alphas(void) /* * Read number (not currently used) */ - n = -1; ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); description = (char *) free_check_null(description); @@ -957,7 +953,6 @@ print_isotope_ratios(void) int print_isotope; struct master *master_ptr; struct master_isotope *master_isotope_ptr; - struct isotope_ratio *isotope_ratio_ptr; char token[MAX_LENGTH]; @@ -993,7 +988,6 @@ print_isotope_ratios(void) { if (isotope_ratio[j]->ratio == MISSING) continue; - isotope_ratio_ptr = isotope_ratio[j]; master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name); /* @@ -1021,7 +1015,6 @@ print_isotope_alphas(void) int i, j; int print_isotope; struct master *master_ptr; - struct isotope_alpha *isotope_alpha_ptr; char token[MAX_LENGTH]; LDBLE log_alpha; @@ -1060,7 +1053,6 @@ print_isotope_alphas(void) { if (isotope_alpha[j]->value == MISSING) continue; - isotope_alpha_ptr = isotope_alpha[j]; /* * Print isotope ratio */ diff --git a/kinetics.cpp b/kinetics.cpp index e1aa04c0..e7dcaea1 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -3135,16 +3135,15 @@ void Phreeqc:: f(integertype N, realtype t, N_Vector y, N_Vector ydot, void *f_data) { - int n_reactions, n_user; - LDBLE step_fraction; + int n_user; + //LDBLE step_fraction; cxxKinetics *kinetics_ptr; Phreeqc *pThis = (Phreeqc *) f_data; pThis->cvode_error = FALSE; - n_reactions = pThis->cvode_n_reactions; n_user = pThis->cvode_n_user; kinetics_ptr = (cxxKinetics *) pThis->cvode_kinetics_ptr; - step_fraction = pThis->cvode_step_fraction; + //step_fraction = pThis->cvode_step_fraction; pThis->rate_sim_time = pThis->cvode_rate_sim_time; for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++) @@ -3576,4 +3575,4 @@ limit_rates(cxxKinetics *kinetics_ptr) } return true; -} \ No newline at end of file +} diff --git a/mainsubs.cpp b/mainsubs.cpp index a13a29d2..e0754d05 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1223,7 +1223,6 @@ xexchange_save(int n_user) */ int i, j; char token[MAX_LENGTH]; - int count_comps; LDBLE charge; if (use.Get_exchange_ptr() == NULL) @@ -1245,7 +1244,6 @@ xexchange_save(int n_user) /* * Write exch_comp structure for each exchange component */ - count_comps = 0; for (i = 0; i < count_unknowns; i++) { if (x[i]->type == EXCH) @@ -1889,7 +1887,6 @@ step_save_exch(int n_user) * * input: n_user is user exchange number of target */ - bool found; if (use.Get_exchange_ptr() == NULL) return (OK); @@ -1911,7 +1908,6 @@ step_save_exch(int n_user) { if (master[i]->s->type != EX) continue; - found = false; std::string e(master[i]->elt->name); for (size_t j = 0; j < temp_exchange.Get_exchange_comps().size(); j++) { @@ -2291,7 +2287,7 @@ copy_entities(void) copy_temperature.count = 0; copy_pressure.count = 0; new_copy = FALSE; - return (OK); + return return_value; } /* ---------------------------------------------------------------------- */ @@ -2547,4 +2543,4 @@ Phreeqc::do_mixes(void) Utilities::Rxn_mix(Rxn_pp_assemblage_mix_map, Rxn_pp_assemblage_map, this); Utilities::Rxn_mix(Rxn_ss_assemblage_mix_map, Rxn_ss_assemblage_map, this); Utilities::Rxn_mix(Rxn_surface_mix_map, Rxn_surface_map, this); -} \ No newline at end of file +} diff --git a/model.cpp b/model.cpp index 1c05cdeb..b763f880 100644 --- a/model.cpp +++ b/model.cpp @@ -42,7 +42,6 @@ model(void) int count_infeasible, count_basis_change; int debug_model_save; int mass_water_switch_save; - LDBLE old_mu; set_inert_moles(); /* debug_model = TRUE; */ @@ -97,7 +96,6 @@ model(void) PhreeqcIWait(this); #endif iterations++; - old_mu = mu_x; if (iterations > itmax - 1 && debug_model == FALSE && pr.logfile == TRUE) { @@ -2988,6 +2986,8 @@ ss_binary(cxxSS *ss_ptr) xb2 = xb * xb; xb3 = xb2 * xb; xb4 = xb3 * xb; + xb4 = xb4; + xc3 = xc3; /* used derivation that did not substitute x2 = 1-x1 */ diff --git a/pitzer.cpp b/pitzer.cpp index ffd52db0..56916fed 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -852,7 +852,7 @@ pitzer(void) /* ---------------------------------------------------------------------- */ { int i, i0, i1, i2; - LDBLE param, l_alpha, z0, z1, z2; + LDBLE param, l_alpha, z0, z1; LDBLE etheta, ethetap; /* LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, @@ -862,7 +862,6 @@ pitzer(void) LDBLE CONV, XX, OSUM, BIGZ, DI, F, F1, F2, F_var, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, B, B1, B2; LDBLE I, TK; - int LNEUT; /* C C INITIALIZE @@ -871,7 +870,6 @@ pitzer(void) CONV = 1.0 / log(10.0); XX = 0.0; OSUM = 0.0; - LNEUT = FALSE; /*n I = *I_X; TK = *TK_X; @@ -1054,7 +1052,6 @@ pitzer(void) i2 = pitz_params[i]->ispec[2]; if (IPRSNT[i2] == FALSE) continue; - z2 = spec[i2]->z; LGAMMA[i0] += M[i1] * M[i2] * param; LGAMMA[i1] += M[i0] * M[i2] * param; LGAMMA[i2] += M[i0] * M[i1] * param; @@ -1261,18 +1258,15 @@ C */ LDBLE *AK; LDBLE L_Z; - int II; int i; if (X <= 1.0e0) { - II = 1; L_Z = 4.0e0 * pow(X, (LDBLE) 0.2e0) - 2.0e0; AK = &AKX[0]; } else { - II = 2; L_Z = 40.0e0 * pow(X, (LDBLE) -1.0e-1) / 9.0e0 - 22.0e0 / 9.0e0; AK = &AKX[21]; } @@ -2052,11 +2046,10 @@ int Phreeqc:: check_gammas_pz(void) /* ---------------------------------------------------------------------- */ { - LDBLE old_aw, old_mu, tol; + LDBLE /*old_aw,*/ old_mu, tol; int converge, i; old_mu = mu_x; - old_aw = s_h2o->la; pitzer(); molalities(TRUE); mb_sums(); diff --git a/prep.cpp b/prep.cpp index 467bf193..bed9d014 100644 --- a/prep.cpp +++ b/prep.cpp @@ -136,7 +136,7 @@ quick_setup(void) * been accumulated in array master, usually by subroutine step. * Updates essential information for the model. */ - int i, j, k; + int i; for (i = 0; i < count_master; i++) { if (master[i]->s->type == SURF_PSI) @@ -188,7 +188,6 @@ quick_setup(void) /* * pp_assemblage */ - j = 0; for (i = 0; i < count_unknowns; i++) { if (x[i]->type == PP) @@ -299,8 +298,6 @@ quick_setup(void) break; } } - j = 0; - k = 0; for (; i < count_unknowns; i++) { if (x[i]->type == SURFACE_CB) @@ -4137,7 +4134,7 @@ int Phreeqc:: setup_pure_phases(void) /* ---------------------------------------------------------------------- */ { - LDBLE si_org; + //LDBLE si_org; /* * Fills in data for pure_phase assemglage in unknown structure */ @@ -4163,7 +4160,7 @@ setup_pure_phases(void) x[count_unknowns]->moles = comp_ptr->Get_moles(); x[count_unknowns]->phase = phase_ptr; x[count_unknowns]->si = comp_ptr->Get_si(); - si_org = comp_ptr->Get_si_org(); + //si_org = comp_ptr->Get_si_org(); /* si_org is used for Peng-Robinson gas, with the fugacity coefficient added later in adjust_pure_phases, when rxn_x has been defined for each phase in the model */ diff --git a/print.cpp b/print.cpp index e0765620..96f9d623 100644 --- a/print.cpp +++ b/print.cpp @@ -2823,21 +2823,19 @@ punch_identifiers(void) const char *sformat; const char *dformat; const char *gformat; - int i, l; + int i; char token[MAX_LENGTH]; //if (punch.in == FALSE) // return (OK); if (!current_selected_output->Get_high_precision()) { - l = 12; sformat = "%12s\t"; dformat = "%12d\t"; gformat = "%12g\t"; } else { - l = 20; sformat = "%20s\t"; dformat = "%20d\t"; gformat = "%20g\t"; diff --git a/read.cpp b/read.cpp index e4f1924a..eccf93e4 100644 --- a/read.cpp +++ b/read.cpp @@ -1849,7 +1849,6 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) /* ---------------------------------------------------------------------- */ { int j, l; - int count_isotopes; char token[MAX_LENGTH], token1[MAX_LENGTH]; char *ptr1; std::vector isotopes; @@ -1873,7 +1872,6 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) */ inverse_ptr->phases[inverse_ptr->count_phases].constraint = EITHER; inverse_ptr->phases[inverse_ptr->count_phases].force = FALSE; - count_isotopes = 0; for (;;) { cxxSolutionIsotope temp_isotope; @@ -7659,7 +7657,6 @@ read_surface_master_species(void) int l, return_value; char *ptr, *ptr1; LDBLE l_z; - struct master *m_ptr; struct species *s_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH]; int opt, opt_save; @@ -7671,7 +7668,6 @@ read_surface_master_species(void) int count_opt_list = 0; opt_save = OPTION_DEFAULT; return_value = UNKNOWN; - m_ptr = NULL; for (;;) { opt = get_option(opt_list, count_opt_list, &next_char); @@ -7727,7 +7723,6 @@ read_surface_master_species(void) master[count_master] = master_alloc(); master[count_master]->type = SURF; master[count_master]->elt = element_store(token); - m_ptr = master[count_master]; if (copy_token(token, &ptr, &l) != UPPER && token[0] != '[') { parse_error++; @@ -10731,7 +10726,7 @@ read_named_logk(void) * */ - int j, l; + int l; int i, empty; struct logk *logk_ptr; char token[MAX_LENGTH]; @@ -10934,7 +10929,7 @@ read_named_logk(void) * Get space for logk information */ logk_ptr = NULL; - j = copy_token(token, &next_char, &l); + copy_token(token, &next_char, &l); logk_ptr = logk_store(token, TRUE); /* diff --git a/runner.cpp b/runner.cpp index ddbb124b..d8e78cb8 100644 --- a/runner.cpp +++ b/runner.cpp @@ -33,7 +33,6 @@ bool runner::Read(CParser & parser) std::istream::pos_type next_char; std::string token; int opt_save; - bool useLastLine(false); this->Get_cells().Set_defined(true); opt_save = CParser::OPT_DEFAULT; @@ -126,7 +125,6 @@ bool runner::Read(CParser & parser) parser.error_msg("Unknown input reading RUN_CELLS definition.", PHRQ_io::OT_CONTINUE); parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE); - useLastLine = false; return_value = false; break; } @@ -148,4 +146,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("step"), // 5 std::vector< std::string >::value_type("steps") // 6 }; -const std::vector< std::string > runner::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > runner::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); diff --git a/sit.cpp b/sit.cpp index df3897e8..f3e75a9f 100644 --- a/sit.cpp +++ b/sit.cpp @@ -305,19 +305,17 @@ sit(void) LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, B; */ - LDBLE CONV, XI, XX, OSUM, DI, F,CSUM, OSMOT, B; + LDBLE XI, XX, OSUM, DI, F, OSMOT, B; LDBLE I, TK; - int LNEUT; /* C C INITIALIZE C */ - CONV = 1.0 / log(10.0); + //CONV = 1.0 / log(10.0); XI = 0.0e0; XX = 0.0e0; OSUM = 0.0e0; - LNEUT = FALSE; /*n I = *I_X; TK = *TK_X; @@ -378,7 +376,6 @@ sit(void) F = -A * (DI / (1.0e0 + B * DI)); - CSUM = 0.0e0; /*OSMOT = -(sit_A0) * pow(I, 1.5e0) / (1.0e0 + B * DI);*/ T = 1.0 + B*DI; OSMOT = -2.0*A/(B*B*B)*(T - 2.0*log(T) - 1.0/T); @@ -1167,11 +1164,10 @@ int Phreeqc:: check_gammas_sit(void) /* ---------------------------------------------------------------------- */ { - LDBLE old_aw, old_mu, tol, t; + LDBLE old_mu, tol; int converge, i; old_mu = mu_x; - old_aw = s_h2o->la; sit(); molalities(TRUE); mb_sums(); @@ -1190,7 +1186,6 @@ check_gammas_sit(void) { converge = FALSE; } - t = pow((LDBLE) 10.0, s_h2o->la); if ((pow((LDBLE) 10.0, s_h2o->la) - AW) > tol) { converge = FALSE; diff --git a/tally.cpp b/tally.cpp index 20fdc76a..7f0178ca 100644 --- a/tally.cpp +++ b/tally.cpp @@ -895,8 +895,6 @@ build_tally_table(void) * stores in global variable first_user_number. */ int j, k, l, n, p, save_print_use; - int count_tt_reaction, count_tt_exchange, count_tt_surface, - count_tt_gas_phase; int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics; struct phase *phase_ptr; char token[MAX_LENGTH]; @@ -932,61 +930,41 @@ build_tally_table(void) */ if (Rxn_reaction_map.size() > 0) { - count_tt_reaction = 1; n = count_tally_table_columns; extend_tally_table(); tally_table[n].name = string_hsave("Reaction"); tally_table[n].type = Reaction; } - else - { - count_tt_reaction = 0; - } /* * add one for exchangers */ if (Rxn_exchange_map.size() > 0) { - count_tt_exchange = 1; n = count_tally_table_columns; extend_tally_table(); tally_table[n].name = string_hsave("Exchange"); tally_table[n].type = Exchange; } - else - { - count_tt_exchange = 0; - } /* * add one for surface */ if (Rxn_surface_map.size() > 0) { - count_tt_surface = 1; n = count_tally_table_columns; extend_tally_table(); tally_table[n].name = string_hsave("Surface"); tally_table[n].type = Surface; } - else - { - count_tt_surface = 0; - } /* * add one for gases */ if (Rxn_gas_phase_map.size() > 0) { - count_tt_gas_phase = 1; n = count_tally_table_columns; extend_tally_table(); tally_table[n].name = string_hsave("Gas_phase"); tally_table[n].type = Gas_phase; } - else - { - count_tt_gas_phase = 0; - } /* * Count pure phases */ diff --git a/transport.cpp b/transport.cpp index 82b129b6..69daeddc 100644 --- a/transport.cpp +++ b/transport.cpp @@ -23,12 +23,10 @@ transport(void) int punch_boolean; LDBLE step_fraction; - LDBLE cb_tol; state = TRANSPORT; diffc_tr = diffc; diffc_max = 0.0; - cb_tol = 1e-9; transp_surf = warn_fixed_Surf = warn_MCD_X = 0; /* mass_water_switch = TRUE; */ /* @@ -2979,7 +2977,7 @@ disp_surf(LDBLE DDt) * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. */ { - int i, i1, i2, k, k1, n1, n2; + int i, i1, i2, k, k1; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store, mcd_mixf; LDBLE lav, A_ij, por, Dp1, Dp2; @@ -2992,9 +2990,6 @@ disp_surf(LDBLE DDt) viscos_f = viscosity(); viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); - n1 = 0; - n2 = n1 + 1; - cxxSurface surface_n1, surface_n2; cxxSurface *surface_n2_ptr; @@ -3334,7 +3329,6 @@ disp_surf(LDBLE DDt) /* * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... */ - n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for ( ; jit != Rxn_temp_surface_map.end(); jit++) { @@ -3654,7 +3648,7 @@ diff_stag_surf(int mobile_cell) * for any cell in MCD, need only include the mixing factors for higher numbered cells. */ { - int i, i1, i2, k, k1, n1, n2, ns; + int i, i1, i2, k, k1, ns; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store; LDBLE Dp1, Dp2; @@ -3722,7 +3716,6 @@ diff_stag_surf(int mobile_cell) if (surface_n1_ptr != NULL) { surface_n1 = *surface_n1_ptr; - n1 = 0; } /* if not found... */ else @@ -3758,7 +3751,6 @@ diff_stag_surf(int mobile_cell) /* if not found... */ else { - n2 = 1; /* copy it from surface_ptr2... */ if (surface_ptr2 != NULL) { @@ -3941,7 +3933,6 @@ diff_stag_surf(int mobile_cell) /* * Step 4. Diffusion is done. New surfaces can be copied in the cells... */ - n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for ( ; jit != Rxn_temp_surface_map.end(); jit++) { From 04ecf346a6f6265dd37b29b262ba06234e0dbd80 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Jul 2014 16:19:57 +0000 Subject: [PATCH 0831/1077] Avoid overlapping memcpy in cl1.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8823 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cl1.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/cl1.cpp b/cl1.cpp index 96017f17..9c424862 100644 --- a/cl1.cpp +++ b/cl1.cpp @@ -442,12 +442,15 @@ cl1(int k, int l, int m, int n, /* switch row ia with row iout, use memcpy */ if (xmax > l_toler) { - memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), - (size_t) n2 * sizeof(LDBLE)); - memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[iout * q_dim]), - (size_t) n2 * sizeof(LDBLE)); - memcpy((void *) &(q2[iout * q_dim]), (void *) &(scratch[0]), - (size_t) n2 * sizeof(LDBLE)); + if (ia != iout) + { + memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[iout * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[iout * q_dim]), (void *) &(scratch[0]), + (size_t) n2 * sizeof(LDBLE)); + } /* L320: */ /* set pivot to row ia, column in */ iout = ia; @@ -701,12 +704,15 @@ cl1(int k, int l, int m, int n, /* L540: */ ++ia; /* switch row */ - memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), - (size_t) n2 * sizeof(LDBLE)); - memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[i * q_dim]), - (size_t) n2 * sizeof(LDBLE)); - memcpy((void *) &(q2[i * q_dim]), (void *) &(scratch[0]), - (size_t) n2 * sizeof(LDBLE)); + if (ia != i) + { + memcpy((void *) &(scratch[0]), (void *) &(q2[ia * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[ia * q_dim]), (void *) &(q2[i * q_dim]), + (size_t) n2 * sizeof(LDBLE)); + memcpy((void *) &(q2[i * q_dim]), (void *) &(scratch[0]), + (size_t) n2 * sizeof(LDBLE)); + } /* L550: */ } /* L560: */ From c7d153e77b0f6f1ca0ba9fd5c7edc7cb7015439d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Jul 2014 16:20:46 +0000 Subject: [PATCH 0832/1077] unused variables git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8824 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- nvector_serial.cpp | 2 +- smalldense.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nvector_serial.cpp b/nvector_serial.cpp index 9c7527a9..7af46342 100644 --- a/nvector_serial.cpp +++ b/nvector_serial.cpp @@ -838,7 +838,7 @@ N_VMinQuotient_Serial(N_Vector num, N_Vector denom) void N_VPrint_Serial(N_Vector x) { - integertype i, N; + integertype /*i,*/ N; realtype *xd; N = NV_LENGTH_S(x); diff --git a/smalldense.cpp b/smalldense.cpp index e6365efa..b62cb486 100644 --- a/smalldense.cpp +++ b/smalldense.cpp @@ -299,7 +299,7 @@ denfree(realtype ** a) void denprint(realtype ** a, integertype n) { - integertype i, j; + //integertype i, j; #if !defined(R_SO) printf("\n"); From be4e769edbab72fde1ac72e2c68c9a727264a545 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 9 Jul 2014 19:46:08 +0000 Subject: [PATCH 0833/1077] fixed if R_SO not set git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8825 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- nvector_serial.cpp | 4 ++-- smalldense.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/nvector_serial.cpp b/nvector_serial.cpp index 7af46342..8760a599 100644 --- a/nvector_serial.cpp +++ b/nvector_serial.cpp @@ -838,14 +838,14 @@ N_VMinQuotient_Serial(N_Vector num, N_Vector denom) void N_VPrint_Serial(N_Vector x) { - integertype /*i,*/ N; + integertype N; realtype *xd; N = NV_LENGTH_S(x); xd = NV_DATA_S(x); #if !defined(R_SO) - for (i = 0; i < N; i++) + for (integertype i = 0; i < N; i++) printf("%11.8g\n", (double) (*xd++)); printf("\n"); diff --git a/smalldense.cpp b/smalldense.cpp index b62cb486..6cfd7c07 100644 --- a/smalldense.cpp +++ b/smalldense.cpp @@ -299,9 +299,8 @@ denfree(realtype ** a) void denprint(realtype ** a, integertype n) { - //integertype i, j; - #if !defined(R_SO) + integertype i, j; printf("\n"); for (i = 0; i < n; i++) { From ccfac52c4f64e2ec6a02f52c284e3f3d74fd4d6a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 9 Jul 2014 23:56:56 +0000 Subject: [PATCH 0834/1077] init ctor; changed success to include 0; fixed delete[] git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8827 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 23d08b1a..8b0612ee 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -32,9 +32,13 @@ PHRQ_io(void) punch_on = true; error_on = true; dump_on = true; - screen_on = true; echo_on = true; + screen_on = true; echo_destination = ECHO_OUTPUT; + + m_next_keyword = Keywords::KEY_NONE; + accumulate = false; + m_line_type = PHRQ_io::LT_EMPTY; } PHRQ_io:: @@ -458,7 +462,7 @@ fpunchf_helper(std::ostream *os, const char *format, ...) va_list args; va_start(args, format); int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); - bool success = (j > 0 && j < (int) STACK_MAX); + bool success = (j >= 0 && j < (int) STACK_MAX); va_end(args); if (success) @@ -474,7 +478,7 @@ fpunchf_helper(std::ostream *os, const char *format, ...) va_list args; va_start(args, format); j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); - success = (j > 0 && j < (int) alloc_buffer_size); + success = (j >= 0 && j < (int) alloc_buffer_size); va_end(args); if (!success) { @@ -484,8 +488,9 @@ fpunchf_helper(std::ostream *os, const char *format, ...) } } while (!success); + (*os) << alloc_buffer; - delete alloc_buffer; + delete[] alloc_buffer; } } } @@ -502,7 +507,7 @@ fpunchf_helper(std::string *str, const char *format, ...) va_list args; va_start(args, format); int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); - bool success = (j > 0 && j < (int) STACK_MAX); + bool success = (j >= 0 && j < (int) STACK_MAX); va_end(args); if (success) @@ -518,7 +523,7 @@ fpunchf_helper(std::string *str, const char *format, ...) va_list args; va_start(args, format); j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); - success = (j > 0 && j < (int) alloc_buffer_size); + success = (j >= 0 && j < (int) alloc_buffer_size); va_end(args); if (!success) { @@ -528,8 +533,9 @@ fpunchf_helper(std::string *str, const char *format, ...) } } while (!success); + (*str) += alloc_buffer; - delete alloc_buffer; + delete[] alloc_buffer; } } } From fd1e3265a41b8b22a44bff425b66736b98b26b08 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Jul 2014 14:15:18 +0000 Subject: [PATCH 0835/1077] remove R_SO from class_release_64 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8832 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.old b/Makefile.old index 373874be..506679f2 100644 --- a/Makefile.old +++ b/Makefile.old @@ -173,7 +173,7 @@ ifeq ($(CFG), CLASS_RELEASE_64) CL1MP_OBJS=cl1mp.o CL1MP_LIB=/usr/lib64/libgmp.a endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DR_SO # -DPHREEQC2 + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DR_SO VPATH = .. INCLUDES = -I.. CXX = g++ From 8b6631a00014df6615cb57c0282626e41e9b2047 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Jul 2014 18:08:02 +0000 Subject: [PATCH 0836/1077] memory error on units line git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8833 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- spread.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spread.cpp b/spread.cpp index d26f2233..dfdf538f 100644 --- a/spread.cpp +++ b/spread.cpp @@ -240,7 +240,8 @@ read_solution_spread(void) { numbers = 0; strings = 0; - for (int i = 0; i < heading->count; i++) + //for (int i = 0; i < heading->count; i++) + for (int i = 0; i < row_ptr->count; i++) { if (row_ptr->type_vector[i] == STRING) { From 96f839e181f1c5c32bf7f1d4d401e3694be14715 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Jul 2014 20:12:14 +0000 Subject: [PATCH 0837/1077] fixed uninitialized values git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8834 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Exchange.cxx | 1 + readtr.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Exchange.cxx b/Exchange.cxx index b2b2c836..3abf1de4 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -38,6 +38,7 @@ cxxNumKeyword(io) this->n_user = this->n_user_end = l_n_user; this->pitzer_exchange_gammas = true; this->new_def = false; + this->n_solution = -999; // // Mix exchangers // diff --git a/readtr.cpp b/readtr.cpp index 551e566b..ba229941 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -36,7 +36,7 @@ read_transport(void) */ char *ptr; int i, j, l; - int old_cells, max; + int old_cells, max, all_cells; int count_length, count_disp, count_punch, count_print; int count_length_alloc, count_disp_alloc; char token[MAX_LENGTH]; @@ -103,6 +103,8 @@ read_transport(void) { correct_disp = FALSE; old_cells = 0; + max = 0; + all_cells = 0; } else old_cells = count_cells; @@ -660,15 +662,29 @@ read_transport(void) /* * Allocate space for cell_data */ - cell_data = - (struct cell_data *) PHRQ_realloc(cell_data, - (size_t) (max * - (1 + - stag_data->count_stag) + - 1) * - sizeof(struct cell_data)); + cell_data = (struct cell_data *) PHRQ_realloc(cell_data, + (size_t) (max * (1 + stag_data->count_stag) + 1) * sizeof(struct cell_data)); if (cell_data == NULL) malloc_error(); + + // initialize new cells + int all_cells_now = max * (1 + stag_data->count_stag) + 1; + if (all_cells_now > all_cells) + { + for (int i = all_cells; i < all_cells_now; i++) + { + cell_data[i].length = 1.0; + cell_data[i].mid_cell_x = 1.0; + cell_data[i].disp = 1.0; + cell_data[i].temp = 25.0; + cell_data[i].por = 0.1; + cell_data[i].por_il = 0.01; + cell_data[i].punch = FALSE; + cell_data[i].print = FALSE; + } + all_cells = all_cells_now; + } + /* * Fill in data for lengths */ From 660042da0e66f93cf3fb94ed0895050ca51d1457 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 11 Jul 2014 20:05:09 +0000 Subject: [PATCH 0838/1077] Changed variable from max to max_cells. Added variable all_cells to be able to initialize new cell_data. moved old_cells, max_cells, all_cells to phreeqc class. initialized old_cells, max_cells, all_cells in init of phreeqc class. Added to copy constructor. changed logic for switching to numerical derivatives by adding && numerical_fixed_volume == false if (iterations > 99 && numerical_fixed_volume == false) Added gammas_pz(); jacobian_sums(); For restart in pitzer.cpp Added gammas_sit(); jacobian_sums(); for restart in sit.cpp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8835 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 8 ++++++- Phreeqc.h | 1 + model.cpp | 2 +- pitzer.cpp | 6 +++-- readtr.cpp | 65 ++++++++++++++++++++++++++--------------------------- sit.cpp | 6 +++-- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 83aefe68..f2e44dcc 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -448,7 +448,10 @@ void Phreeqc::init(void) dump_in = FALSE; dump_modulus = 0; transport_warnings = TRUE; - cell_data = FALSE; + cell_data = NULL; + old_cells = 0; + max_cells = 0; + all_cells = 0; multi_Dflag = FALSE; interlayer_Dflag = FALSE; default_Dw = 0; @@ -1350,6 +1353,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) if (cell_data == NULL) malloc_error(); memcpy(cell_data, pSrc->cell_data, ((size_t) (count_cells * sizeof(struct cell_data)))); } + old_cells = pSrc->old_cells; + max_cells = pSrc->max_cells; + all_cells = pSrc->all_cells; multi_Dflag = pSrc->multi_Dflag; interlayer_Dflag = pSrc->interlayer_Dflag; default_Dw = pSrc->default_Dw; diff --git a/Phreeqc.h b/Phreeqc.h index 7d318a86..7f385c50 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1365,6 +1365,7 @@ protected: int dump_modulus; int transport_warnings; struct cell_data *cell_data; + int old_cells, max_cells, all_cells; int multi_Dflag; /* signals calc'n of multicomponent diffusion */ int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ diff --git a/model.cpp b/model.cpp index b763f880..1ca269a8 100644 --- a/model.cpp +++ b/model.cpp @@ -2727,7 +2727,7 @@ calc_gas_pressures(void) V_m = (2. * gas_phase_ptr->Get_v_m() + V_m) / 3; else V_m = (1. * gas_phase_ptr->Get_v_m() + V_m) / 2; - if (iterations > 99) + if (iterations > 99 && numerical_fixed_volume == false) { //V_m *= 1; /* debug */ numerical_fixed_volume = true; diff --git a/pitzer.cpp b/pitzer.cpp index 56916fed..17b0c552 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1751,8 +1751,10 @@ Restart: molalities(TRUE); if (max_unknowns > pz_max_unknowns) { - base = (LDBLE *) free_check_null(base); - goto Restart; + base = (LDBLE *) free_check_null(base); + gammas_pz(); + jacobian_sums(); + goto Restart; } if (full_pitzer == TRUE) pitzer(); diff --git a/readtr.cpp b/readtr.cpp index ba229941..129517ff 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -36,7 +36,6 @@ read_transport(void) */ char *ptr; int i, j, l; - int old_cells, max, all_cells; int count_length, count_disp, count_punch, count_print; int count_length_alloc, count_disp_alloc; char token[MAX_LENGTH]; @@ -103,7 +102,7 @@ read_transport(void) { correct_disp = FALSE; old_cells = 0; - max = 0; + max_cells = 0; all_cells = 0; } else @@ -637,14 +636,14 @@ read_transport(void) /* * Determine number of cells */ - max = count_cells; - if (count_length > max) - max = count_length; - if (count_disp > max) - max = count_disp; - if (max > count_cells) + max_cells = count_cells; + if (count_length > max_cells) + max_cells = count_length; + if (count_disp > max_cells) + max_cells = count_disp; + if (max_cells > count_cells) { - if (max == count_length) + if (max_cells == count_length) { sprintf(token, "Number of cells is increased to number of 'lengths' %d.", @@ -663,12 +662,12 @@ read_transport(void) * Allocate space for cell_data */ cell_data = (struct cell_data *) PHRQ_realloc(cell_data, - (size_t) (max * (1 + stag_data->count_stag) + 1) * sizeof(struct cell_data)); + (size_t) (max_cells * (1 + stag_data->count_stag) + 1) * sizeof(struct cell_data)); if (cell_data == NULL) malloc_error(); // initialize new cells - int all_cells_now = max * (1 + stag_data->count_stag) + 1; + int all_cells_now = max_cells * (1 + stag_data->count_stag) + 1; if (all_cells_now > all_cells) { for (int i = all_cells; i < all_cells_now; i++) @@ -690,12 +689,12 @@ read_transport(void) */ if (count_length == 0) { - if (old_cells < max) + if (old_cells < max_cells) { error_string = sformatf( "No cell-lengths were read; length = 1 m assumed."); warning_msg(error_string); - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].length = 1.0; } } @@ -705,35 +704,35 @@ read_transport(void) { cell_data[i].length = length[i]; } - if (max > count_length) + if (max_cells > count_length) { error_string = sformatf( "Cell-lengths were read for %d cells. Last value is used till cell %d.", - count_length, max); + count_length, max_cells); warning_msg(error_string); - for (i = count_length - 1; i < max; i++) + for (i = count_length - 1; i < max_cells; i++) cell_data[i].length = length[count_length - 1]; } } cell_data[0].mid_cell_x = cell_data[0].length / 2; - for (i = 1; i < max; i++) + for (i = 1; i < max_cells; i++) { cell_data[i].mid_cell_x = cell_data[i - 1].mid_cell_x + (cell_data[i - 1].length + cell_data[i].length) / 2; } - cell_data[max].mid_cell_x = - cell_data[max - 1].mid_cell_x + cell_data[max - 1].length; + cell_data[max_cells].mid_cell_x = + cell_data[max_cells - 1].mid_cell_x + cell_data[max_cells - 1].length; /* * Fill in data for dispersivities */ if (count_disp == 0) { - if (old_cells < max) + if (old_cells < max_cells) { error_string = sformatf( "No dispersivities were read; disp = 0 assumed."); warning_msg(error_string); - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].disp = 0.0; } } @@ -741,23 +740,23 @@ read_transport(void) { for (i = 0; i < count_disp; i++) cell_data[i].disp = disp[i]; - if (max > count_disp) + if (max_cells > count_disp) { error_string = sformatf( "Dispersivities were read for %d cells. Last value is used till cell %d.", - count_disp, max); + count_disp, max_cells); warning_msg(error_string); - for (i = count_disp - 1; i < max; i++) + for (i = count_disp - 1; i < max_cells; i++) cell_data[i].disp = disp[count_disp - 1]; } } - count_cells = max; + count_cells = max_cells; /* * Account for stagnant cells */ if (stag_data->count_stag > 0) { - max = count_cells * (1 + stag_data->count_stag) + 1; + max_cells = count_cells * (1 + stag_data->count_stag) + 1; for (i = 0; i < count_cells; i++) { for (l = 1; l <= stag_data->count_stag; l++) @@ -770,11 +769,11 @@ read_transport(void) */ if (count_punch != 0) { - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].punch = FALSE; for (i = 0; i < count_punch; i++) { - if (punch_temp[i] > max || punch_temp[i] < 1) + if (punch_temp[i] > max_cells || punch_temp[i] < 1) { error_string = sformatf( "Cell number for punch is out of range, %d. Request ignored.", @@ -786,18 +785,18 @@ read_transport(void) } } else if (simul_tr == 1) - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].punch = TRUE; /* * Fill in data for print */ if (count_print != 0) { - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].print = FALSE; for (i = 0; i < count_print; i++) { - if (print_temp[i] > max || print_temp[i] < 1) + if (print_temp[i] > max_cells || print_temp[i] < 1) { error_string = sformatf( "Cell number for print is out of range, %d. Request ignored.", @@ -809,7 +808,7 @@ read_transport(void) } } else if (simul_tr == 1) - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) cell_data[i].print = TRUE; /* * Fill in porosities @@ -822,7 +821,7 @@ read_transport(void) error_msg(error_string, CONTINUE); } - for (i = 0; i < max; i++) + for (i = 0; i < max_cells; i++) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); diff --git a/sit.cpp b/sit.cpp index f3e75a9f..9b4061d1 100644 --- a/sit.cpp +++ b/sit.cpp @@ -870,8 +870,10 @@ Restart: molalities(TRUE); if (max_unknowns > pz_max_unknowns) { - base = (LDBLE *) free_check_null(base); - goto Restart; + base = (LDBLE *) free_check_null(base); + gammas_sit(); + jacobian_sums(); + goto Restart; } if (full_pitzer == TRUE) sit(); From 9689a12d6ad181288192ee5eea91773100e1bf46 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Jul 2014 20:23:12 +0000 Subject: [PATCH 0839/1077] no need to check for null with delete. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8841 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index 8b0612ee..be19f048 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -58,10 +58,7 @@ ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode *os = ofs; return true; } - if (ofs) - { - delete ofs; - } + delete ofs; return false; } From 86a2b0461de4dd06244e8f5696c00521b86aacd9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Jul 2014 15:37:53 +0000 Subject: [PATCH 0840/1077] Clean up PBasic memory on syntax error. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8847 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PBasic.cpp b/PBasic.cpp index bfb2b17b..d1c90e56 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -138,6 +138,16 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } } } + catch (PhreeqcStop s) + { + // clean up memory + disposetokens(&buf); + PhreeqcPtr->PHRQ_free(inbuf); + *lnbase = (void *) linebase; + *vbase = (void *) varbase; + *lpbase = (void *) loopbase; + throw s; + } } while (!(exitflag || P_eof())); /* exit(EXIT_SUCCESS); */ From cf02876f8723524a53bde9c737239447203259af Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Jul 2014 22:39:56 +0000 Subject: [PATCH 0841/1077] after Valgrind fixes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8848 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.old b/Makefile.old index 506679f2..1a9d6222 100644 --- a/Makefile.old +++ b/Makefile.old @@ -173,12 +173,12 @@ ifeq ($(CFG), CLASS_RELEASE_64) CL1MP_OBJS=cl1mp.o CL1MP_LIB=/usr/lib64/libgmp.a endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DR_SO + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DUSE_PHRQ_ALLOC # -DR_SO VPATH = .. INCLUDES = -I.. CXX = g++ PROFILE = - CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} endif From 76bd0c2908ccf4143444286f62b97a0e17aa14c0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 24 Jul 2014 23:30:00 +0000 Subject: [PATCH 0842/1077] Fixes for dumped no_edl SURFACE. and EDL("charge", "xx") for no_edl SURFACE. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8875 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 2 +- tidy.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 75714204..b2cb5d57 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -490,7 +490,7 @@ diff_layer_total(const char *total_name, const char *surface_name) Utilities::replace("_", " ", token); std::string::iterator b = token.begin(); std::string::iterator e = token.end(); - CParser::copy_token(token, b, e); + CParser::copy_token(name, b, e); } if (surface_name != NULL) { diff --git a/tidy.cpp b/tidy.cpp index a2168f42..01d15021 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3900,7 +3900,10 @@ tidy_min_surface(void) } /* area */ - surface_charge_ptr->Set_grams(jit->second.Get_moles()); + if (surface_charge_ptr) + { + surface_charge_ptr->Set_grams(jit->second.Get_moles()); + } /* * make sure surface elements are in phase * logically necessary for mass balance and to avoid negative concentrations when dissolving phase From 1c3b39653697a0106df17a48a8c3ef182cafb6f0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 28 Jul 2014 21:23:33 +0000 Subject: [PATCH 0843/1077] r-found error in type mismatch of conditional git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8877 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- utilities.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities.cpp b/utilities.cpp index 30f25df2..cf22f0cb 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -874,7 +874,7 @@ parse_couple(char *token) paren_count = 1; paren1[0] = '('; p1 = 1; - while (ptr != '\0') + while (*ptr != '\0') { ptr++; if (*ptr == '/' || *ptr == '\0') From 87ad76934beecd53e2c1360cc0afa66e6ef465ae Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jul 2014 17:25:52 +0000 Subject: [PATCH 0844/1077] Working with gas phase. Bug in calculation of total pressure of mix. Other issues when element of a gas component was not present in the system. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8879 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 8 +++++++- Solution.cxx | 8 ++++++++ gases.cpp | 18 ++++++++++-------- prep.cpp | 19 ++++++++++--------- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index a99d3e3b..cd60dc61 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -137,6 +137,12 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, const std::map < int, LDBLE > & mixcomps = mx.Get_mixComps(); std::map < int, LDBLE >::const_iterator it; + this->total_p = 0; + double sum_fractions = 0.0; + for (it = mixcomps.begin(); it != mixcomps.end(); it++) + { + sum_fractions += it->second; + } for (it = mixcomps.begin(); it != mixcomps.end(); it++) { if (entity_map.find(it->first) != entity_map.end()) @@ -148,7 +154,7 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, this->solution_equilibria = entity_ptr->solution_equilibria; this->n_solution = entity_ptr->n_solution; this->type = entity_ptr->type; - this->total_p = entity_ptr->total_p * it->second; + this->total_p += entity_ptr->total_p * it->second / sum_fractions; this->total_moles = entity_ptr->total_moles * it->second; this->volume = entity_ptr->volume * it->second; this->v_m = entity_ptr->v_m * it->second; diff --git a/Solution.cxx b/Solution.cxx index da1a4561..84fd8a7b 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1067,6 +1067,14 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble // Don`t bother to update activities? //this->Update(const_nd); this->totals = const_nd; + cxxNameDouble::iterator it; + for (it = this->totals.begin(); it != this->totals.end(); it++) + { + if (it->second < 1e-14) + { + it->second = 0.0; + } + } } void cxxSolution::Update_activities(const cxxNameDouble &original_tot) diff --git a/gases.cpp b/gases.cpp index c813d922..9610dc7a 100644 --- a/gases.cpp +++ b/gases.cpp @@ -183,17 +183,14 @@ build_fixed_volume_gas(void) { master_ptr = rxn_ptr->s->secondary; } - else + else if (rxn_ptr->s->primary != NULL && rxn_ptr->s->primary->in == TRUE) { master_ptr = rxn_ptr->s->primary; } - if (master_ptr == NULL) + else { - error_string = sformatf( - "Element needed for gas component, %s, is not in model.", - phase_ptr->name); - warning_msg(error_string); - continue; + master_ptr = master_bsearch_primary(rxn_ptr->s->name); + master_ptr->s->la = -999.0; } if (debug_prep == TRUE) { @@ -265,10 +262,15 @@ build_fixed_volume_gas(void) { master_ptr = rxn_ptr->s->secondary; } - else + else if (rxn_ptr->s->primary != NULL && rxn_ptr->s->primary->in == TRUE) { master_ptr = rxn_ptr->s->primary; } + else + { + master_ptr = master_bsearch_primary(rxn_ptr->s->name); + master_ptr->s->la = -999.0; + } if (master_ptr == NULL) { diff --git a/prep.cpp b/prep.cpp index bed9d014..4ab3ac88 100644 --- a/prep.cpp +++ b/prep.cpp @@ -509,17 +509,14 @@ build_gas_phase(void) { master_ptr = rxn_ptr->s->secondary; } - else + else if (rxn_ptr->s->primary != NULL && rxn_ptr->s->primary->in == TRUE) { master_ptr = rxn_ptr->s->primary; } - if (master_ptr == NULL) + else { - error_string = sformatf( - "Element needed for gas component, %s, is not in model.", - phase_ptr->name); - warning_msg(error_string); - continue; + master_ptr = master_bsearch_primary(rxn_ptr->s->name); + master_ptr->s->la = -999.0; } if (debug_prep == TRUE) { @@ -591,11 +588,15 @@ build_gas_phase(void) { master_ptr = rxn_ptr->s->secondary; } - else + else if (rxn_ptr->s->primary != NULL && rxn_ptr->s->primary->in == TRUE) { master_ptr = rxn_ptr->s->primary; } - + else + { + master_ptr = master_bsearch_primary(rxn_ptr->s->name); + master_ptr->s->la = -999.0; + } if (master_ptr == NULL) { error_string = sformatf( From 9f0ee02150bd7a1ca1eb00c1ed086179958b57ff Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jul 2014 18:51:51 +0000 Subject: [PATCH 0845/1077] Trying to optimize compute_gfw. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8884 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + read.cpp | 1 + utilities.cpp | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 7f385c50..50d94851 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1912,6 +1912,7 @@ protected: #endif /* utilities.cpp ------------------------------- */ int spinner; + std::map gfw_map; /* new after release of Version 3 */ std::map > sum_species_map; diff --git a/read.cpp b/read.cpp index eccf93e4..10a1cd9f 100644 --- a/read.cpp +++ b/read.cpp @@ -3360,6 +3360,7 @@ read_master_species(void) } } + gfw_map.clear(); return (j); } /* ---------------------------------------------------------------------- */ diff --git a/utilities.cpp b/utilities.cpp index cf22f0cb..baa32647 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -291,6 +291,15 @@ compute_gfw(const char *string, LDBLE * gfw) * Input: string contains a chemical formula * Output: gfw contains the calculated gfw */ + std::string str(string); + std::map::iterator it; + it = gfw_map.find(str); + if (it != gfw_map.end()) + { + *gfw = it->second; + return OK; + } + int i; char token[MAX_LENGTH]; char *ptr; @@ -312,6 +321,7 @@ compute_gfw(const char *string, LDBLE * gfw) } *gfw += elt_list[i].coef * (elt_list[i].elt)->gfw; } + gfw_map[str] = *gfw; return (OK); } From 685a4d45b3beb722b239273d0c314d4c7f9efd6f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jul 2014 19:19:14 +0000 Subject: [PATCH 0846/1077] Optimizing compute_gfw git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8885 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 3 ++- prep.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index b2cb5d57..dfe1d8ea 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -230,7 +230,8 @@ calc_dens(void) if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; - compute_gfw(s_x[i]->name, &gfw); + //compute_gfw(s_x[i]->name, &gfw); + gfw = s_x[i]->gfw; M_T += s_x[i]->moles * gfw; V_solutes += s_x[i]->moles * s_x[i]->logk[vm_tc]; } diff --git a/prep.cpp b/prep.cpp index 4ab3ac88..a7f453dd 100644 --- a/prep.cpp +++ b/prep.cpp @@ -1207,7 +1207,9 @@ build_model(void) space((void **) ((void *) &s_x), count_s_x + 1, &max_s_x, sizeof(struct species *)); } + compute_gfw(s[i]->name, &s[i]->gfw); s_x[count_s_x++] = s[i]; + /* * Write mass action equation for current model */ From 98741bbe3269d8fe63695e1a80b97e4607c9f829 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jul 2014 20:39:38 +0000 Subject: [PATCH 0847/1077] finalizing compute_gfw using map for rates git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8888 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + basicsubs.cpp | 6 ++++-- read.cpp | 4 +++- structures.cpp | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 50d94851..175a69e2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1913,6 +1913,7 @@ protected: /* utilities.cpp ------------------------------- */ int spinner; std::map gfw_map; + std::map rates_map; /* new after release of Version 3 */ std::map > sum_species_map; diff --git a/basicsubs.cpp b/basicsubs.cpp index dfe1d8ea..4d5bc043 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -281,9 +281,11 @@ calc_solution_volume(void) */ LDBLE total_mass = 0; LDBLE gfw; - compute_gfw("H", &gfw); + //compute_gfw("H", &gfw); + gfw = s_hplus->primary->gfw; total_mass = total_h_x * gfw; - compute_gfw("O", &gfw); + //compute_gfw("O", &gfw); + gfw = s_h2o->primary->gfw; total_mass += total_o_x * gfw; for (int i = 0; i < count_master; i++) diff --git a/read.cpp b/read.cpp index 10a1cd9f..ade31c25 100644 --- a/read.cpp +++ b/read.cpp @@ -9190,7 +9190,9 @@ read_rates(void) break; } /* output_msg(sformatf( "%s", rates[0].commands)); - */ return (return_value); + */ + rates_map.clear(); + return (return_value); } /* ---------------------------------------------------------------------- */ diff --git a/structures.cpp b/structures.cpp index 52f1bdc4..b082b1ac 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1649,6 +1649,19 @@ rate_search(const char *name, int *n) * if found, the address of the pp_assemblage element * if not found, NULL */ + std::string str(name); + std::map::iterator it; + it = rates_map.find(str); + if (it != rates_map.end()) + { + *n = it->second; + if (*n >= 0) + { + return &(rates[it->second]); + } + return NULL; + } + int i; *n = -1; for (i = 0; i < count_rates; i++) @@ -1656,12 +1669,14 @@ rate_search(const char *name, int *n) if (strcmp_nocase(rates[i].name, name) == 0) { *n = i; + rates_map[str] = i; return (&(rates[i])); } } /* * rate name not found */ + rates_map[str] = *n; return (NULL); } From e168691097bca06f4863ee4c033c2c9b66d5f5be Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Jul 2014 22:07:19 +0000 Subject: [PATCH 0848/1077] Another try to speed up rates. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8890 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- read.cpp | 5 ++++- structures.cpp | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 175a69e2..e0bd0c10 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1913,7 +1913,7 @@ protected: /* utilities.cpp ------------------------------- */ int spinner; std::map gfw_map; - std::map rates_map; + std::map rates_map; /* new after release of Version 3 */ std::map > sum_species_map; diff --git a/read.cpp b/read.cpp index ade31c25..075e89d2 100644 --- a/read.cpp +++ b/read.cpp @@ -9135,7 +9135,10 @@ read_rates(void) case OPTION_DEFAULT: /* read rate name */ ptr = line; copy_token(token, &ptr, &l); - rate_ptr = rate_search(token, &n); + { + const char *name = string_hsave(token); + rate_ptr = rate_search(name, &n); + } if (rate_ptr == NULL) { rates = diff --git a/structures.cpp b/structures.cpp index b082b1ac..54a4bf6c 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1649,9 +1649,8 @@ rate_search(const char *name, int *n) * if found, the address of the pp_assemblage element * if not found, NULL */ - std::string str(name); - std::map::iterator it; - it = rates_map.find(str); + std::map::iterator it; + it = rates_map.find(name); if (it != rates_map.end()) { *n = it->second; @@ -1669,14 +1668,14 @@ rate_search(const char *name, int *n) if (strcmp_nocase(rates[i].name, name) == 0) { *n = i; - rates_map[str] = i; + rates_map[name] = i; return (&(rates[i])); } } /* * rate name not found */ - rates_map[str] = *n; + rates_map[name] = *n; return (NULL); } From 0236d42a7c286adeeb81c818e7b5f0c380d039ee Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Jul 2014 15:22:15 +0000 Subject: [PATCH 0849/1077] memset not used for NDEBUG git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8891 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phqalloc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phqalloc.cpp b/phqalloc.cpp index d8b82906..3823f397 100644 --- a/phqalloc.cpp +++ b/phqalloc.cpp @@ -27,8 +27,9 @@ PHRQ_malloc(size_t size) if (p == NULL) return NULL; - +#if !defined(NDEBUG) memset(p, 0, sizeof(PHRQMemHeader) + size); +#endif p->pNext = NULL; if ((p->pPrev = s_pTail) != NULL) @@ -199,10 +200,12 @@ PHRQ_realloc(void *ptr, size_t size if (p != NULL) { p->size = new_size; +#if !defined(NDEBUG) if (new_size > old_size) { memset((char *) p + old_size, 0, new_size - old_size); } +#endif } if (p == NULL) From 88c8cbeeb819908f578ee12de05586d90dff873b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 30 Jul 2014 21:42:12 +0000 Subject: [PATCH 0850/1077] initialized local_database_file and local_output_stream git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8895 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 837115fa..59e5cced 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -366,7 +366,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, copy_token(token, &ptr, &l); strcpy(token, default_name); strcat(token, ".out"); - std::ofstream * local_output_stream; + std::ofstream * local_output_stream = NULL; if (argc <= 1) { local_output_stream = open_output_stream(query, token, std::ios_base::out, false); @@ -444,7 +444,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, strcpy(token, default_data_base); } - std::ifstream * local_database_file; + std::ifstream * local_database_file = NULL; if (argc <= 1) { local_database_file = open_input_stream(query, token, std::ios_base::in, false); From db91bf076722487e30a06437e4d0a687aba03c00 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 31 Jul 2014 15:25:11 +0000 Subject: [PATCH 0851/1077] ready for next release git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8896 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.old b/Makefile.old index 1a9d6222..1d5c0d11 100644 --- a/Makefile.old +++ b/Makefile.old @@ -179,8 +179,9 @@ ifeq ($(CFG), CLASS_RELEASE_64) CXX = g++ PROFILE = CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g +# CXXFLAGS = -fprofile-arcs -ftest-coverage $(DEFINES) $(INCLUDES) # -g OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} + LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov endif # ----------------------------------------------------------------------------- From f2a25dacfab2f02a8e6a8b8216e017244f3062a5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Aug 2014 14:44:08 +0000 Subject: [PATCH 0852/1077] copy/paste error for surface in totalize system. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8904 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- System.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/System.cxx b/System.cxx index 1a276b8d..467363de 100644 --- a/System.cxx +++ b/System.cxx @@ -88,7 +88,7 @@ cxxSystem::totalize(Phreeqc * phreeqc_ptr) } if (this->surface != NULL) { - this->ssassemblage->totalize(phreeqc_ptr); + this->surface->totalize(); this->totals.add_extensive(this->surface->Get_totals(), 1.0); } return; From fbb95d10b07d6d808f8447822c330810681b34fc Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Aug 2014 02:49:22 +0000 Subject: [PATCH 0853/1077] made catch(...) always rethrow; changed catches to const references git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8906 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 34 +++++++++++++++++----------------- class_main.cpp | 4 ++-- mainsubs.cpp | 8 ++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index d1c90e56..34d24f91 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -110,7 +110,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } while (!(exitflag || P_eof())); } - catch (PBasicStop e) + catch (const PBasicStop& e) { if (P_escapecode != -20) { @@ -138,7 +138,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } } } - catch (PhreeqcStop s) + catch (const PhreeqcStop& s) { // clean up memory disposetokens(&buf); @@ -146,7 +146,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) *lnbase = (void *) linebase; *vbase = (void *) varbase; *lpbase = (void *) loopbase; - throw s; + throw; // rethrow } } while (!(exitflag || P_eof())); @@ -214,7 +214,7 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) } while (!(exitflag || P_eof())); } - catch (PBasicStop e) + catch (const PhreeqcStop& e) { if (P_escapecode != -20) { @@ -279,7 +279,7 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } while (!(exitflag || P_eof())); } - catch (PBasicStop e) + catch (const PhreeqcStop& e) { if (P_escapecode != -20) { @@ -355,7 +355,7 @@ basic_main(char *commands) } while (!(exitflag || P_eof())); } - catch (PBasicStop e) + catch (const PhreeqcStop& e) { if (P_escapecode != -20) { @@ -3159,9 +3159,9 @@ factor(struct LOC_exec * LINK) 1) * sizeof(int)); if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = j; - s_v.count_subscripts++; - } + s_v.subscripts[s_v.count_subscripts] = j; + s_v.count_subscripts++; + } else { /* get right parentheses */ @@ -5155,13 +5155,13 @@ cmdon(struct LOC_exec *LINK) l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); if (l == NULL) PhreeqcPtr->malloc_error(); - l->next = loopbase; - loopbase = l; - l->kind = gosubloop; - l->homeline = stmtline; - l->hometok = LINK->t; - LINK->t = LINK->t->next; - } + l->next = loopbase; + loopbase = l; + l->kind = gosubloop; + l->homeline = stmtline; + l->hometok = LINK->t; + LINK->t = LINK->t->next; + } else require(tokgoto, LINK); if (i < 1) @@ -5517,7 +5517,7 @@ exec(void) } while (stmtline != NULL); } - catch (PBasicStop e) + catch (const PhreeqcStop& e) { //_Ltry1: if (P_escapecode == -20) diff --git a/class_main.cpp b/class_main.cpp index 59e5cced..ff831af7 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -490,7 +490,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, *db_cookie = new std::ifstream(db_file, std::ios_base::in); *input_cookie = new std::ifstream(in_file, std::ios_base::in); } - catch (PhreeqcStop e) + catch (const PhreeqcStop& e) { return get_input_errors(); } @@ -681,7 +681,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, *db_cookie = new std::ifstream(db_file, std::ios_base::in); *input_cookie = new std::ifstream(in_file, std::ios_base::in); } - catch (PhreeqcStop e) + catch (const PhreeqcStop& e) { return get_input_errors(); } diff --git a/mainsubs.cpp b/mainsubs.cpp index e0754d05..24d71a9f 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -2308,7 +2308,7 @@ read_database(void) tidy_model(); status(0, NULL); } - catch (PhreeqcStop e) + catch (const PhreeqcStop&) { return get_input_errors(); } @@ -2445,7 +2445,7 @@ run_simulations(void) #endif } } - catch (PhreeqcStop e) + catch (const PhreeqcStop&) { return get_input_errors(); } @@ -2466,7 +2466,7 @@ do_initialize(void) initialize(); } - catch (PhreeqcStop e) + catch (const PhreeqcStop&) { return get_input_errors(); } @@ -2496,7 +2496,7 @@ do_status(void) phrq_io->output_flush(); phrq_io->error_flush(); } - catch (PhreeqcStop e) + catch (const PhreeqcStop&) { return get_input_errors(); } From f1438518eb2ba100505b294058f7b9a350bf802f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Aug 2014 02:51:35 +0000 Subject: [PATCH 0854/1077] fixed some of the easier clang++ scan-build bugs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8907 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 10 ++++++++ Parser.cxx | 24 +++++++++--------- isotopes.cpp | 67 +++++++++++++++++++++++++++++++------------------- parse.cpp | 15 +++++++---- prep.cpp | 14 ++++++++--- read.cpp | 45 +++++++++++++++++++++------------ structures.cpp | 38 +++++++++++++++++----------- 7 files changed, 139 insertions(+), 74 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 34d24f91..18bf9186 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3158,10 +3158,15 @@ factor(struct LOC_exec * LINK) (size_t) (s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) + { PhreeqcPtr->malloc_error(); + } + else + { s_v.subscripts[s_v.count_subscripts] = j; s_v.count_subscripts++; } + } else { /* get right parentheses */ @@ -5154,7 +5159,11 @@ cmdon(struct LOC_exec *LINK) { l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); if (l == NULL) + { PhreeqcPtr->malloc_error(); + } + else + { l->next = loopbase; loopbase = l; l->kind = gosubloop; @@ -5162,6 +5171,7 @@ cmdon(struct LOC_exec *LINK) l->hometok = LINK->t; LINK->t = LINK->t->next; } + } else require(tokgoto, LINK); if (i < 1) diff --git a/Parser.cxx b/Parser.cxx index 97a86208..c0e13059 100644 --- a/Parser.cxx +++ b/Parser.cxx @@ -28,17 +28,19 @@ m_next_keyword(Keywords::KEY_NONE) { error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP); } - m_line_save = io->Get_m_line(); - m_line = io->Get_m_line(); - m_line_type = io->Get_m_line_type(); - m_line_iss.str(m_line); - m_line_iss.seekg(0, std::ios_base::beg); - m_line_iss.clear(); - echo_file = EO_ALL; - echo_stream = EO_NONE; - accumulate = false; - phrq_io_only = true; - + else + { + m_line_save = io->Get_m_line(); + m_line = io->Get_m_line(); + m_line_type = io->Get_m_line_type(); + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = true; + } } CParser::CParser(std::istream & input, PHRQ_io *io): diff --git a/isotopes.cpp b/isotopes.cpp index fc2eae2e..ee421ecd 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -229,11 +229,16 @@ read_calculate_values(void) calculate_value_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); if (calculate_value_ptr->commands == NULL) + { malloc_error(); - calculate_value_ptr->commands[0] = '\0'; - calculate_value_ptr->linebase = NULL; - calculate_value_ptr->varbase = NULL; - calculate_value_ptr->loopbase = NULL; + } + else + { + calculate_value_ptr->commands[0] = '\0'; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + } opt_save = OPT_1; break; @@ -1518,15 +1523,18 @@ master_isotope_init(struct master_isotope *master_isotope_ptr) /* * set pointers in structure to NULL */ - master_isotope_ptr->name = NULL; - master_isotope_ptr->master = NULL; - master_isotope_ptr->elt = NULL; - master_isotope_ptr->units = NULL; - master_isotope_ptr->standard = 0; - master_isotope_ptr->ratio = 0; - master_isotope_ptr->moles = 0; - master_isotope_ptr->total_is_major = 0; - master_isotope_ptr->minor_isotope = 1; + if (master_isotope_ptr) + { + master_isotope_ptr->name = NULL; + master_isotope_ptr->master = NULL; + master_isotope_ptr->elt = NULL; + master_isotope_ptr->units = NULL; + master_isotope_ptr->standard = 0; + master_isotope_ptr->ratio = 0; + master_isotope_ptr->moles = 0; + master_isotope_ptr->total_is_major = 0; + master_isotope_ptr->minor_isotope = 1; + } return (OK); } @@ -1685,11 +1693,14 @@ calculate_value_init(struct calculate_value *calculate_value_ptr) /* * set pointers in structure to NULL */ - calculate_value_ptr->name = NULL; - calculate_value_ptr->commands = NULL; - calculate_value_ptr->linebase = NULL; - calculate_value_ptr->varbase = NULL; - calculate_value_ptr->loopbase = NULL; + if (calculate_value_ptr) + { + calculate_value_ptr->name = NULL; + calculate_value_ptr->commands = NULL; + calculate_value_ptr->linebase = NULL; + calculate_value_ptr->varbase = NULL; + calculate_value_ptr->loopbase = NULL; + } return (OK); } @@ -1869,10 +1880,13 @@ isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr) /* * set pointers in structure to NULL */ - isotope_ratio_ptr->name = NULL; - isotope_ratio_ptr->isotope_name = NULL; - isotope_ratio_ptr->ratio = MISSING; - isotope_ratio_ptr->converted_ratio = MISSING; + if (isotope_ratio_ptr) + { + isotope_ratio_ptr->name = NULL; + isotope_ratio_ptr->isotope_name = NULL; + isotope_ratio_ptr->ratio = MISSING; + isotope_ratio_ptr->converted_ratio = MISSING; + } return (OK); } @@ -2028,9 +2042,12 @@ isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr) /* * set pointers in structure to NULL */ - isotope_alpha_ptr->name = NULL; - isotope_alpha_ptr->named_logk = NULL; - isotope_alpha_ptr->value = MISSING; + if (isotope_alpha_ptr) + { + isotope_alpha_ptr->name = NULL; + isotope_alpha_ptr->named_logk = NULL; + isotope_alpha_ptr->value = MISSING; + } return (OK); } diff --git a/parse.cpp b/parse.cpp index ea261556..5904b604 100644 --- a/parse.cpp +++ b/parse.cpp @@ -151,13 +151,18 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association) (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * sizeof(struct elt_list)); if (*elt_ptr == NULL) - malloc_error(); - for (i = 0; i < count_elts; i++) { - (*elt_ptr)[i].elt = elt_list[i].elt; - (*elt_ptr)[i].coef = -elt_list[i].coef; + malloc_error(); + } + else + { + for (i = 0; i < count_elts; i++) + { + (*elt_ptr)[i].elt = elt_list[i].elt; + (*elt_ptr)[i].coef = -elt_list[i].coef; + } + (*elt_ptr)[count_elts].elt = NULL; } - (*elt_ptr)[count_elts].elt = NULL; /* * Debugging print of parsed equation trxn_print(); diff --git a/prep.cpp b/prep.cpp index a7f453dd..fd6e18dc 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2877,7 +2877,10 @@ add_potential_factor(void) "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); } - master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + else + { + master_ptr = unknown_ptr->master[0]; /* potential for surface component */ + } /* * Make sure there is space */ @@ -4639,9 +4642,14 @@ unknown_alloc_master(void) master_ptr = (struct master **) PHRQ_malloc(2 * sizeof(struct master *)); if (master_ptr == NULL) + { malloc_error(); - master_ptr[0] = NULL; - master_ptr[1] = NULL; + } + else + { + master_ptr[0] = NULL; + master_ptr[1] = NULL; + } return (master_ptr); } diff --git a/read.cpp b/read.cpp index 075e89d2..41127120 100644 --- a/read.cpp +++ b/read.cpp @@ -840,11 +840,14 @@ read_exchange_species(void) error_string = sformatf( "Copying exchange to phases."); error_msg(error_string, CONTINUE); } - phase_ptr->formula = s_ptr->name; - phase_ptr->check_equation = FALSE; - phase_ptr->type = EX; - phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt); - phase_ptr->rxn = rxn_dup(s_ptr->rxn); + else + { + phase_ptr->formula = s_ptr->name; + phase_ptr->check_equation = FALSE; + phase_ptr->type = EX; + phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt); + phase_ptr->rxn = rxn_dup(s_ptr->rxn); + } break; } if (return_value == EOF || return_value == KEYWORD) @@ -9158,12 +9161,17 @@ read_rates(void) rate_ptr->new_def = TRUE; rate_ptr->commands = (char *) PHRQ_malloc(sizeof(char)); if (rate_ptr->commands == NULL) + { malloc_error(); - rate_ptr->commands[0] = '\0'; - rate_ptr->name = string_hsave(token); - rate_ptr->linebase = NULL; - rate_ptr->varbase = NULL; - rate_ptr->loopbase = NULL; + } + else + { + rate_ptr->commands[0] = '\0'; + rate_ptr->name = string_hsave(token); + rate_ptr->linebase = NULL; + rate_ptr->varbase = NULL; + rate_ptr->loopbase = NULL; + } opt_save = OPT_1; break; case OPT_1: /* read command */ @@ -9392,7 +9400,7 @@ read_user_punch(void) { r->commands = (char *) PHRQ_malloc(sizeof(char)); if (r->commands == NULL) malloc_error(); - r->commands[0] = '\0'; + else r->commands[0] = '\0'; } //rate_free(user_punch); //user_punch->new_def = TRUE; @@ -9410,11 +9418,16 @@ read_user_punch(void) line_length = (int) strlen(line); r->commands = (char *) PHRQ_realloc(r->commands, (size_t) (length + line_length + 2) * sizeof(char)); - if (r->commands == NULL) malloc_error(); - - r->commands[length] = ';'; - r->commands[length + 1] = '\0'; - strcat((r->commands), line); + if (r->commands == NULL) + { + malloc_error(); + } + else + { + r->commands[length] = ';'; + r->commands[length + 1] = '\0'; + strcat((r->commands), line); + } //length = (int) strlen(user_punch->commands); //line_length = (int) strlen(line); //user_punch->commands = diff --git a/structures.cpp b/structures.cpp index 54a4bf6c..f29038bc 100644 --- a/structures.cpp +++ b/structures.cpp @@ -667,13 +667,18 @@ elt_list_save(void) (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * sizeof(struct elt_list)); if (elt_list_ptr == NULL) - malloc_error(); - for (j = 0; j < count_elts; j++) { - elt_list_ptr[j].elt = elt_list[j].elt; - elt_list_ptr[j].coef = elt_list[j].coef; + malloc_error(); + } + else + { + for (j = 0; j < count_elts; j++) + { + elt_list_ptr[j].elt = elt_list[j].elt; + elt_list_ptr[j].coef = elt_list[j].coef; + } + elt_list_ptr[count_elts].elt = NULL; } - elt_list_ptr[count_elts].elt = NULL; return (elt_list_ptr); } /* ---------------------------------------------------------------------- */ @@ -686,17 +691,22 @@ NameDouble2elt_list(const cxxNameDouble &nd) */ struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((nd.size() + 1) * sizeof(struct elt_list)); if (elt_list_ptr == NULL) - malloc_error(); - cxxNameDouble::const_iterator it = nd.begin(); - int i = 0; - for( ; it != nd.end(); it++) { - elt_list_ptr[i].elt = element_store(it->first.c_str()); - elt_list_ptr[i].coef = it->second; - i++; + malloc_error(); + } + else + { + cxxNameDouble::const_iterator it = nd.begin(); + int i = 0; + for( ; it != nd.end(); it++) + { + elt_list_ptr[i].elt = element_store(it->first.c_str()); + elt_list_ptr[i].coef = it->second; + i++; + } + elt_list_ptr[i].elt = NULL; + elt_list_ptr[i].coef = 0; } - elt_list_ptr[i].elt = NULL; - elt_list_ptr[i].coef = 0; return (elt_list_ptr); } /* ********************************************************************** From 9f77e000d5f257101de3d50c7960959a51556515 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Aug 2014 05:51:47 +0000 Subject: [PATCH 0855/1077] fixed some of the easier clang++ scan-build bugs git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8908 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 36 ++++++++++++++++++++++++--------- PHRQ_io.cpp | 5 ++++- inverse.cpp | 9 +++++++++ prep.cpp | 5 +++++ print.cpp | 3 +++ read.cpp | 44 +++++++++++++++++++++++++++++++++++++--- sit.cpp | 3 +++ spread.cpp | 52 ++++++++++++++++++++++++++++++++++++++--------- step.cpp | 55 +++++++++++++++++++++++++++----------------------- structures.cpp | 35 +++++++++++++++++++++++++++++++- 10 files changed, 198 insertions(+), 49 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 18bf9186..9389b956 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -110,7 +110,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } while (!(exitflag || P_eof())); } - catch (const PBasicStop& e) + catch (const PBasicStop&) { if (P_escapecode != -20) { @@ -138,7 +138,7 @@ basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase) } } } - catch (const PhreeqcStop& s) + catch (const PhreeqcStop&) { // clean up memory disposetokens(&buf); @@ -214,7 +214,7 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop& e) + catch (const PhreeqcStop&) { if (P_escapecode != -20) { @@ -279,7 +279,7 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop& e) + catch (const PhreeqcStop&) { if (P_escapecode != -20) { @@ -355,7 +355,7 @@ basic_main(char *commands) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop& e) + catch (const PhreeqcStop&) { if (P_escapecode != -20) { @@ -3135,9 +3135,14 @@ factor(struct LOC_exec * LINK) (size_t) (s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) + { PhreeqcPtr->malloc_error(); - s_v.subscripts[s_v.count_subscripts] = i; - s_v.count_subscripts++; + } + else + { + s_v.subscripts[s_v.count_subscripts] = i; + s_v.count_subscripts++; + } } /* get other subscripts */ @@ -4866,7 +4871,10 @@ cmdwhile(struct LOC_exec *LINK) l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); if (l == NULL) + { PhreeqcPtr->malloc_error(); + return; + } l->next = loopbase; loopbase = l; l->kind = whileloop; @@ -4969,7 +4977,10 @@ cmdgosub(struct LOC_exec *LINK) l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); if (l == NULL) + { PhreeqcPtr->malloc_error(); + return; + } l->next = loopbase; loopbase = l; l->kind = gosubloop; @@ -5244,9 +5255,14 @@ cmddim(struct LOC_exec *LINK) { v->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc(j * sizeof(LDBLE)); if (v->UU.U0.arr == NULL) + { PhreeqcPtr->malloc_error(); - for (i = 0; i < j; i++) - v->UU.U0.arr[i] = 0.0; + } + else + { + for (i = 0; i < j; i++) + v->UU.U0.arr[i] = 0.0; + } } if (!iseos(LINK)) require(tokcomma, LINK); @@ -5527,7 +5543,7 @@ exec(void) } while (stmtline != NULL); } - catch (const PhreeqcStop& e) + catch (const PhreeqcStop) { //_Ltry1: if (P_escapecode == -20) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index be19f048..fd2d4cd0 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -795,7 +795,10 @@ get_line(void) error_msg(errstr.str().c_str(), OT_STOP); #endif } - this->push_istream(next_stream); + else + { + this->push_istream(next_stream); + } continue; } } diff --git a/inverse.cpp b/inverse.cpp index fe49db44..d79e5b5b 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -3579,7 +3579,10 @@ count_isotope_unknowns(struct inverse *inv_ptr, isotopes = (struct isotope *) PHRQ_malloc((size_t) sizeof(struct isotope)); if (isotopes == NULL) + { malloc_error(); + return (0); + } count_isotopes = 0; for (i = 0; i < inv_ptr->count_isotopes; i++) @@ -3615,7 +3618,10 @@ count_isotope_unknowns(struct inverse *inv_ptr, 1) * sizeof(struct isotope)); if (isotopes == NULL) + { malloc_error(); + return (0); + } isotopes[count_isotopes].primary = primary_ptr; isotopes[count_isotopes].master = primary_ptr; isotopes[count_isotopes].isotope_number = isotope_number; @@ -3647,7 +3653,10 @@ count_isotope_unknowns(struct inverse *inv_ptr, 1) * sizeof(struct isotope)); if (isotopes == NULL) + { malloc_error(); + return (0); + } isotopes[count_isotopes].primary = primary_ptr; isotopes[count_isotopes].master = master[k]; isotopes[count_isotopes].isotope_number = isotope_number; diff --git a/prep.cpp b/prep.cpp index fd6e18dc..63c2bb1c 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2975,6 +2975,7 @@ add_cd_music_factors(int n) error_string = sformatf( "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); + return (ERROR); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3004,6 +3005,7 @@ add_cd_music_factors(int n) error_string = sformatf( "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); + return (ERROR); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3023,6 +3025,7 @@ add_cd_music_factors(int n) error_string = sformatf( "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); + return (ERROR); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* @@ -3079,6 +3082,7 @@ add_surface_charge_balance(void) error_string = sformatf( "No surface master species found for surface species."); error_msg(error_string, STOP); + return(OK); } /* * Find potential unknown for surface species @@ -3090,6 +3094,7 @@ add_surface_charge_balance(void) error_string = sformatf( "No potential unknown found for surface species %s.", token.c_str()); error_msg(error_string, STOP); + return(OK); } master_ptr = unknown_ptr->master[0]; /* potential for surface component */ /* diff --git a/print.cpp b/print.cpp index 96f9d623..3c115eb5 100644 --- a/print.cpp +++ b/print.cpp @@ -3557,7 +3557,10 @@ print_alkalinity(void) (struct species_list *) PHRQ_malloc((size_t) (count_s_x * sizeof(struct species_list))); if (alk_list == NULL) + { malloc_error(); + return (OK); + } j = 0; for (i = 0; i < count_s_x; i++) { diff --git a/read.cpp b/read.cpp index 41127120..81cb8116 100644 --- a/read.cpp +++ b/read.cpp @@ -646,7 +646,10 @@ read_exchange_species(void) (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK); + } } else { @@ -660,7 +663,10 @@ read_exchange_species(void) (struct name_coef))); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK); + } } /* read name */ if (copy_token(token, &next_char, &i) == EMPTY) @@ -698,7 +704,10 @@ read_exchange_species(void) (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK); + } } else { @@ -712,7 +721,10 @@ read_exchange_species(void) (struct name_coef))); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK); + } } i = sscanf(next_char, SCANFORMAT, &s_ptr->add_logk[s_ptr->count_add_logk].coef); @@ -1834,7 +1846,10 @@ read_inv_isotopes(struct inverse *inverse_ptr, char *ptr) 1) * sizeof(struct inv_isotope)); if (inverse_ptr->i_u == NULL) + { malloc_error(); + return (OK); + } inverse_ptr->i_u[inverse_ptr->count_i_u].elt_name = redox_name; inverse_ptr->i_u[inverse_ptr->count_i_u].isotope_number = isotope_number; /* @@ -2584,7 +2599,10 @@ read_list_ints(char **ptr, int *count_ints, int positive) (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof(int)); if (int_list == NULL) + { malloc_error(); + return (NULL); + } int_list[(*count_ints) - 1] = value; if (value <= 0 && positive == TRUE) { @@ -2632,7 +2650,10 @@ read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list) { int_list = (int *) PHRQ_malloc(sizeof(int)); if (int_list == NULL) + { malloc_error(); + return (NULL); + } *count_ints = 0; } ptr_save = *ptr; @@ -2646,7 +2667,10 @@ read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list) (int *) PHRQ_realloc(int_list, (size_t) (*count_ints) * sizeof(int)); if (int_list == NULL) + { malloc_error(); + return (NULL); + } int_list[(*count_ints) - 1] = value; if (value <= 0 && positive == TRUE) { @@ -2687,7 +2711,10 @@ read_list_ints_range(char **ptr, int *count_ints, int positive, int *int_list) (size_t) (*count_ints) * sizeof(int)); if (int_list == NULL) + { malloc_error(); + return (NULL); + } int_list[(*count_ints) - 1] = i; } } @@ -6823,7 +6850,10 @@ read_surface_species(void) (struct name_coef *) PHRQ_malloc(sizeof(struct name_coef)); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK): + } } else { @@ -6837,7 +6867,10 @@ read_surface_species(void) (struct name_coef))); if (s_ptr->add_logk == NULL) + { malloc_error(); + return (OK): + } } /* read name */ if (copy_token(token, &next_char, &i) == EMPTY) @@ -9190,10 +9223,15 @@ read_rates(void) (size_t) (length + line_length + 2) * sizeof(char)); if (rate_ptr->commands == NULL) + { malloc_error(); - rate_ptr->commands[length] = ';'; - rate_ptr->commands[length + 1] = '\0'; - strcat((rate_ptr->commands), line); + } + else + { + rate_ptr->commands[length] = ';'; + rate_ptr->commands[length + 1] = '\0'; + strcat((rate_ptr->commands), line); + } opt_save = OPT_1; break; } diff --git a/sit.cpp b/sit.cpp index 9b4061d1..3cab673e 100644 --- a/sit.cpp +++ b/sit.cpp @@ -792,7 +792,10 @@ Restart: } base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); if (base == NULL) + { malloc_error(); + return OK; + } for (i = 0; i < count_unknowns; i++) { base[i] = residual[i]; diff --git a/spread.cpp b/spread.cpp index dfdf538f..5c2c6ede 100644 --- a/spread.cpp +++ b/spread.cpp @@ -345,11 +345,16 @@ read_solution_spread(void) 1) * sizeof(struct iso)); if (soln_defaults.iso == NULL) + { malloc_error(); - soln_defaults.iso[i].name = string_hsave(token.c_str()); - soln_defaults.iso[i].value = NAN; - soln_defaults.iso[i].uncertainty = NAN; - soln_defaults.count_iso++; + } + else + { + soln_defaults.iso[i].name = string_hsave(token.c_str()); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } } /* read and store isotope ratio uncertainty */ @@ -418,11 +423,16 @@ read_solution_spread(void) 1) * sizeof(struct iso)); if (soln_defaults.iso == NULL) + { malloc_error(); - soln_defaults.iso[i].name = string_hsave(token.c_str()); - soln_defaults.iso[i].value = NAN; - soln_defaults.iso[i].uncertainty = NAN; - soln_defaults.count_iso++; + } + else + { + soln_defaults.iso[i].name = string_hsave(token.c_str()); + soln_defaults.iso[i].value = NAN; + soln_defaults.iso[i].uncertainty = NAN; + soln_defaults.count_iso++; + } } /* read and store isotope ratio */ if (copy_token(token, &next_char) != DIGIT) @@ -923,29 +933,44 @@ string_to_spread_row(char *string) /* possible memory error if length of line is smaller than previous line */ char *token; char *ptr; - struct spread_row *spread_row_ptr; + struct spread_row *spread_row_ptr = NULL; /* * Allocate space */ token = (char *) PHRQ_malloc(strlen(line) + 1); if (token == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr = (struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row)); if (spread_row_ptr == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->char_vector = (char **) PHRQ_malloc((size_t) spread_length * sizeof(char *)); if (spread_row_ptr->char_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->d_vector = (LDBLE *) PHRQ_malloc((size_t) spread_length * sizeof(LDBLE)); if (spread_row_ptr->d_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->type_vector = (int *) PHRQ_malloc((size_t) spread_length * sizeof(int)); if (spread_row_ptr->type_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->count = 0; spread_row_ptr->empty = 0; spread_row_ptr->string = 0; @@ -964,19 +989,28 @@ string_to_spread_row(char *string) (char **) PHRQ_realloc(spread_row_ptr->char_vector, (size_t) spread_length * sizeof(char *)); if (spread_row_ptr->char_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->d_vector = (LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector, (size_t) spread_length * sizeof(LDBLE)); if (spread_row_ptr->d_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } spread_row_ptr->type_vector = (int *) PHRQ_realloc(spread_row_ptr->type_vector, (size_t) spread_length * sizeof(int)); if (spread_row_ptr->type_vector == NULL) + { malloc_error(); + return spread_row_ptr; + } } j = copy_token_tab(token, &ptr, &l); if (j == EOL) diff --git a/step.cpp b/step.cpp index edf38fad..283024ac 100644 --- a/step.cpp +++ b/step.cpp @@ -903,26 +903,28 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) LDBLE coef = it->second; if (elt_ptr == NULL) { - assert (false); } - master_ptr = elt_ptr->primary; - if (master_ptr == NULL) - { - // error msg has been called in reaction_calc - continue; - } - if (master_ptr->s == s_hplus) - { - total_h_x += coef * step_x * step_fraction; - } - else if (master_ptr->s == s_h2o) - { - total_o_x += coef * step_x * step_fraction; - } else { - master_ptr->total += coef * step_x * step_fraction; + master_ptr = elt_ptr->primary; + if (master_ptr == NULL) + { + // error msg has been called in reaction_calc + continue; + } + if (master_ptr->s == s_hplus) + { + total_h_x += coef * step_x * step_fraction; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += coef * step_x * step_fraction; + } + else + { + master_ptr->total += coef * step_x * step_fraction; + } } } return (OK); @@ -1184,17 +1186,20 @@ add_kinetics(cxxKinetics *kinetics_ptr) it->first.c_str()); error_msg(error_string, STOP); } - if (master_ptr->s == s_hplus) - { - total_h_x += coef; - } - else if (master_ptr->s == s_h2o) - { - total_o_x += coef; - } else { - master_ptr->total += coef; + if (master_ptr->s == s_hplus) + { + total_h_x += coef; + } + else if (master_ptr->s == s_h2o) + { + total_o_x += coef; + } + else + { + master_ptr->total += coef; + } } } return (OK); diff --git a/structures.cpp b/structures.cpp index f29038bc..f906afd2 100644 --- a/structures.cpp +++ b/structures.cpp @@ -727,7 +727,7 @@ inverse_alloc(void) * return: OK */ { - struct inverse *inverse_ptr; + struct inverse *inverse_ptr = NULL; count_inverse++; inverse = @@ -735,7 +735,10 @@ inverse_alloc(void) (size_t) count_inverse * sizeof(struct inverse)); if (inverse == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr = &(inverse[count_inverse - 1]); /* * Initialize variables @@ -755,16 +758,25 @@ inverse_alloc(void) inverse_ptr->uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); if (inverse_ptr->uncertainties == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->ph_uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); if (inverse_ptr->ph_uncertainties == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->force_solns = (int *) PHRQ_malloc((size_t) sizeof(int)); if (inverse_ptr->force_solns == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->dalk_dph = NULL; inverse_ptr->dalk_dc = NULL; @@ -774,7 +786,10 @@ inverse_alloc(void) inverse_ptr->elts = (struct inv_elts *) PHRQ_malloc((size_t) sizeof(struct inv_elts)); if (inverse_ptr->elts == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->elts[0].name = NULL; inverse_ptr->elts[0].uncertainties = NULL; @@ -782,7 +797,10 @@ inverse_alloc(void) (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); if (inverse_ptr->isotopes == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->isotopes[0].isotope_name = NULL; inverse_ptr->isotopes[0].isotope_number = 0; inverse_ptr->isotopes[0].elt_name = NULL; @@ -791,7 +809,10 @@ inverse_alloc(void) (struct inv_isotope *) PHRQ_malloc((size_t) sizeof(struct inv_isotope)); if (inverse_ptr->i_u == NULL) + { malloc_error(); + return inverse_ptr; + } inverse_ptr->i_u[0].isotope_name = NULL; inverse_ptr->i_u[0].isotope_number = 0; inverse_ptr->i_u[0].elt_name = NULL; @@ -799,7 +820,10 @@ inverse_alloc(void) inverse_ptr->phases = (struct inv_phases *) PHRQ_malloc((size_t) sizeof(struct inv_phases)); if (inverse_ptr->phases == NULL) + { malloc_error(); + return inverse_ptr; + } return (inverse_ptr); } @@ -3612,17 +3636,26 @@ copier_add(struct copier *copier_ptr, int n_user, int start, int end) (int *) PHRQ_realloc(copier_ptr->n_user, (size_t) (copier_ptr->max * sizeof(int))); if (copier_ptr->n_user == NULL) + { malloc_error(); + return (OK); + } copier_ptr->start = (int *) PHRQ_realloc(copier_ptr->start, (size_t) (copier_ptr->max * sizeof(int))); if (copier_ptr->start == NULL) + { malloc_error(); + return (OK); + } copier_ptr->end = (int *) PHRQ_realloc(copier_ptr->end, (size_t) (copier_ptr->max * sizeof(int))); if (copier_ptr->end == NULL) + { malloc_error(); + return (OK); + } } copier_ptr->n_user[copier_ptr->count] = n_user; copier_ptr->start[copier_ptr->count] = start; From a2c90e9ea7d4476bf55c243cb18dcff7a0ddd03a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Aug 2014 06:04:53 +0000 Subject: [PATCH 0856/1077] changed : to ; git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8909 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/read.cpp b/read.cpp index 81cb8116..f418dd17 100644 --- a/read.cpp +++ b/read.cpp @@ -6852,7 +6852,7 @@ read_surface_species(void) if (s_ptr->add_logk == NULL) { malloc_error(); - return (OK): + return (OK); } } else @@ -6869,7 +6869,7 @@ read_surface_species(void) if (s_ptr->add_logk == NULL) { malloc_error(); - return (OK): + return (OK); } } /* read name */ From 0eb0264b8b7ffc7436e96e980c5b735bf74d356b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 5 Aug 2014 06:05:49 +0000 Subject: [PATCH 0857/1077] fixed for bug that occurred when elt_ptr was NULL git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8910 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidy.cpp b/tidy.cpp index 01d15021..1815df8f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3548,7 +3548,7 @@ tidy_kin_exchange(void) input_error++; error_string = sformatf( "Master species not in database " "for %s, skipping element.", - elt_ptr->name); + kit->first.c_str()); error_msg(error_string, CONTINUE); continue; } From 4f60c8774e708bcb0b4576c1d603e22451962986 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 Aug 2014 15:49:15 +0000 Subject: [PATCH 0858/1077] PBasicStop accidently changed to PhreeqcStop at version 8906. test negexp_totmol failed. Switched back to PBasicStop. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8911 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 9389b956..0390b5ae 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -214,7 +214,7 @@ basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop&) + catch (const PBasicStop&) { if (P_escapecode != -20) { @@ -279,7 +279,7 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop&) + catch (const PBasicStop&) { if (P_escapecode != -20) { @@ -355,7 +355,7 @@ basic_main(char *commands) } while (!(exitflag || P_eof())); } - catch (const PhreeqcStop&) + catch (const PBasicStop&) { if (P_escapecode != -20) { @@ -5543,7 +5543,7 @@ exec(void) } while (stmtline != NULL); } - catch (const PhreeqcStop) + catch (const PBasicStop&) { //_Ltry1: if (P_escapecode == -20) From e62cc9cba3857eed8348a11dd2ec42a7f59ba747 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 6 Aug 2014 16:42:07 +0000 Subject: [PATCH 0859/1077] try/catch in class_main.cpp reset rate_sim_time in reactions to avoid carryover to transport. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8920 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 117 ++++++++++++++++++++++++++++--------------------- mainsubs.cpp | 1 + 2 files changed, 67 insertions(+), 51 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index ff831af7..0d202d5a 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -188,62 +188,77 @@ main_method(int argc, char *argv[]) _CrtSetDbgFlag(tmpDbgFlag); //_crtBreakAlloc = 9482; #endif - - phast = FALSE; -/* - * Open input/output files - */ - errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); - if (errors != 0) + try { - return errors; - } + phast = FALSE; + /* + * Open input/output files + */ + errors = process_file_names(argc, argv, &db_cookie, &input_cookie, TRUE); + if (errors != 0) + { + return errors; + } #ifdef DOS - write_banner(); + write_banner(); #endif -/* - * Initialize arrays - */ - errors = do_initialize(); - if (errors != 0) - { - return errors; + /* + * Initialize arrays + */ + errors = do_initialize(); + if (errors != 0) + { + return errors; + } + /* + * Load database into memory + */ + this->phrq_io->push_istream(db_cookie); + errors = read_database(); + this->phrq_io->clear_istream(); + + if (errors != 0) + { + return errors; + } + + /* + * Read input data for simulation + */ + + this->phrq_io->push_istream(input_cookie); + errors = run_simulations(); + + //Phreeqc mycopy(*this); + this->phrq_io->clear_istream(); + + if (errors != 0) + { + return errors; + } + /* + * Display successful status + */ + pr.headings = TRUE; + errors = do_status(); + if (errors != 0) + { + return errors; + } } -/* - * Load database into memory - */ - this->phrq_io->push_istream(db_cookie); - errors = read_database(); - this->phrq_io->clear_istream(); - - if (errors != 0) + catch (...) { - return errors; - } - -/* - * Read input data for simulation - */ - - this->phrq_io->push_istream(input_cookie); - errors = run_simulations(); - - //Phreeqc mycopy(*this); - this->phrq_io->clear_istream(); - - if (errors != 0) - { - return errors; - } -/* - * Display successful status - */ - pr.headings = TRUE; - errors = do_status(); - if (errors != 0) - { - return errors; + int e = get_input_errors(); + std::cerr << "Unhandled exception in PHREEQC." << std::endl; + if (e > 0) + { + return e; + } + else + { + return 1; + } } return 0; } @@ -490,7 +505,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, *db_cookie = new std::ifstream(db_file, std::ios_base::in); *input_cookie = new std::ifstream(in_file, std::ios_base::in); } - catch (const PhreeqcStop& e) + catch (const PhreeqcStop&) { return get_input_errors(); } diff --git a/mainsubs.cpp b/mainsubs.cpp index 24d71a9f..01b699f6 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1122,6 +1122,7 @@ reactions(void) // } // } /* last_model.force_prep = TRUE; */ + rate_sim_time = 0; return (OK); } From 8945b19b89039ac0ae3e3a3e2f1751f474679c0a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 18 Aug 2014 16:32:54 +0000 Subject: [PATCH 0860/1077] Another bug in mixing gas phase. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8925 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index cd60dc61..b8062c42 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -157,7 +157,7 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, this->total_p += entity_ptr->total_p * it->second / sum_fractions; this->total_moles = entity_ptr->total_moles * it->second; this->volume = entity_ptr->volume * it->second; - this->v_m = entity_ptr->v_m * it->second; + this->v_m = entity_ptr->v_m * it->second / sum_fractions; this->pr_in = entity_ptr->pr_in; this->temperature = entity_ptr->temperature; first = false; From e036c2c40caacf405e412dae2e9c0ffc3d48e2e6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 12 Sep 2014 22:11:27 +0000 Subject: [PATCH 0861/1077] Added logic to run only one step in RunCells git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8951 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 3 ++- ReadClass.cxx | 45 ++++++++++++++++++++++++--------------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index f2e44dcc..210c8b18 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -345,6 +345,7 @@ void Phreeqc::init(void) /*---------------------------------------------------------------------- * Irreversible reaction *---------------------------------------------------------------------- */ + run_cells_one_step = false; // auto Rxn_reaction_map; /*---------------------------------------------------------------------- * Gas phase @@ -1232,6 +1233,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) * Irreversible reaction *---------------------------------------------------------------------- */ Rxn_reaction_map = pSrc->Rxn_reaction_map; + run_cells_one_step = pSrc->run_cells_one_step; /*---------------------------------------------------------------------- * Gas phase *---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index e0bd0c10..230d8a6e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1126,6 +1126,7 @@ public: int next_user_number(Keywords::KEYWORDS key); size_t list_components(std::list &list_c); 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;} protected: void init(void); @@ -1419,7 +1420,7 @@ protected: /*---------------------------------------------------------------------- * Reaction *---------------------------------------------------------------------- */ - + bool run_cells_one_step; /*---------------------------------------------------------------------- * Species *---------------------------------------------------------------------- */ diff --git a/ReadClass.cxx b/ReadClass.cxx index 7c416fd7..a6350745 100644 --- a/ReadClass.cxx +++ b/ReadClass.cxx @@ -711,31 +711,34 @@ run_as_cells(void) */ dup_print("Beginning of batch-reaction calculations.", TRUE); count_steps = 1; - if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) + if (!this->run_cells_one_step) { - int count = use.Get_reaction_ptr()->Get_reaction_steps(); - if (count > count_steps) - count_steps = count; - } - if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) - { - if (use.Get_kinetics_ptr()->Get_reaction_steps() > count_steps) - count_steps = use.Get_kinetics_ptr()->Get_reaction_steps(); - } - if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) - { - int count = use.Get_temperature_ptr()->Get_countTemps(); - if (count > count_steps) + if (use.Get_reaction_in() == TRUE && use.Get_reaction_ptr() != NULL) { - count_steps = count; + int count = use.Get_reaction_ptr()->Get_reaction_steps(); + if (count > count_steps) + count_steps = count; } - } - if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) - { - int count = use.Get_pressure_ptr()->Get_count(); - if (count > count_steps) + if (use.Get_kinetics_in() == TRUE && use.Get_kinetics_ptr() != NULL) { - count_steps = count; + if (use.Get_kinetics_ptr()->Get_reaction_steps() > count_steps) + count_steps = use.Get_kinetics_ptr()->Get_reaction_steps(); + } + if (use.Get_temperature_in() == TRUE && use.Get_temperature_ptr() != NULL) + { + int count = use.Get_temperature_ptr()->Get_countTemps(); + if (count > count_steps) + { + count_steps = count; + } + } + if (use.Get_pressure_in() == TRUE && use.Get_pressure_ptr() != NULL) + { + int count = use.Get_pressure_ptr()->Get_count(); + if (count > count_steps) + { + count_steps = count; + } } } count_total_steps = count_steps; From e04d253995e76c705d9726f9a6d2a81aaa3ef81b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 24 Sep 2014 16:50:02 +0000 Subject: [PATCH 0862/1077] Added andsurfcomplex4, USER_PUNCH was redefined without commands, caused a segv. Set commands to NULL in read_user_punch. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8957 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/read.cpp b/read.cpp index f418dd17..0057e504 100644 --- a/read.cpp +++ b/read.cpp @@ -9393,6 +9393,7 @@ read_user_punch(void) // Malloc rate structure struct rate *r = (struct rate *) PHRQ_malloc(sizeof(struct rate)); if (r == NULL) malloc_error(); + r->commands = NULL; r->new_def = TRUE; r->linebase = NULL; r->varbase = NULL; From eb41112a912ce4870b690cea088fa93af45c9179 Mon Sep 17 00:00:00 2001 From: Richard M Webb Date: Wed, 22 Oct 2014 19:34:51 +0000 Subject: [PATCH 0863/1077] Looks like kinetic names were not saved with string_hsave. Need to check again. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9000 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- structures.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/structures.cpp b/structures.cpp index f906afd2..67781a29 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1670,7 +1670,7 @@ rate_free(struct rate *rate_ptr) /* ---------------------------------------------------------------------- */ struct rate * Phreeqc:: -rate_search(const char *name, int *n) +rate_search(const char *name_in, int *n) /* ---------------------------------------------------------------------- */ { /* Linear search of the structure array "rates" for name. @@ -1684,6 +1684,10 @@ rate_search(const char *name, int *n) * if not found, NULL */ std::map::iterator it; + + const char * name; + name = string_hsave(name_in); + it = rates_map.find(name); if (it != rates_map.end()) { From a28ca9a3001ac477d42ff3c166735a31df7f4c99 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 29 Oct 2014 01:59:37 +0000 Subject: [PATCH 0864/1077] changed all fortran string length parameters to be size_t simplified fortran wrappers for windows git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9015 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 ++-- basicsubs.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 230d8a6e..09d3fd6c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -86,7 +86,7 @@ public: void basic_free(void); double basic_callback(double x1, double x2, char * str); void register_basic_callback(double ( *fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1); - void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)); + void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)); LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); @@ -1712,7 +1712,7 @@ protected: PBasic * basic_interpreter; double (*basic_callback_ptr) (double x1, double x2, const char *str, void *cookie); void *basic_callback_cookie; - double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); + double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, size_t l); /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; diff --git a/basicsubs.cpp b/basicsubs.cpp index 4d5bc043..22772319 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3663,7 +3663,7 @@ Phreeqc::register_basic_callback(double (*fcn)(double x1, double x2, const char } void -Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)) +Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)) { this->basic_fortran_callback_ptr = fcn; } From dff3691e29ecd2c72bbaec1d4163bc836a13b26a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Oct 2014 22:00:37 +0000 Subject: [PATCH 0865/1077] Made native git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9024 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- distribution.mk | 684 ++++++++++++++++++++++++------------------------ 1 file changed, 342 insertions(+), 342 deletions(-) diff --git a/distribution.mk b/distribution.mk index 3c702666..3102cc37 100644 --- a/distribution.mk +++ b/distribution.mk @@ -1,342 +1,342 @@ -# Locations to save compressed tar file for distribution -EXPORT=$(TOPDIR)/src/phreeqc_export -EXPORT_DIR=$(EXPORT) -WIN_DIR=$(TOPDIR)/win -DIST_DIR=$(EXPORT_DIR) -DEBUG_DIR=phreeqc_debug -CURSRC=$(CURDIR) -DEBUG_EXE=$(CURSRC)/phreeqc -VERSION=2.12 -VER_DATE:=November 10, 2005 -VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") -V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") -GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") -KERNEL_VER:=$(shell uname -r) -ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) -TEXTCP=textcp DOS -SUN_DIR=$(TOPDIR)/src/Sun -UNIX2DOS=unix2dos -CCFLAGS_DBG=-Wall -ansi -g -DUSE_PHRQ_ALLOC # -std=c99 - -CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else - SPOOL=>& - SPOOL2= -endif - -# list of files for distribution -##FILES= \ -## $(CURSRC)/Makefile \ -## $(CURSRC)/advection.c \ -## $(CURSRC)/basic.c \ -## $(CURSRC)/basicsubs.c \ -## $(CURSRC)/cl1.c \ -## $(CURSRC)/cl1mp.c \ -## $(CURSRC)/cvdense.c \ -## $(CURSRC)/cvode.c \ -## $(CURSRC)/dense.c \ -## $(CURSRC)/dw.c \ -## $(CURSRC)/input.c \ -## $(CURSRC)/integrate.c \ -## $(CURSRC)/inverse.c \ -## $(CURSRC)/isotopes.c \ -## $(CURSRC)/kinetics.c \ -## $(CURSRC)/main.c \ -## $(CURSRC)/mainsubs.c \ -## $(CURSRC)/model.c \ -## $(CURSRC)/nvector.c \ -## $(CURSRC)/nvector_serial.c \ -## $(CURSRC)/output.c \ -## $(CURSRC)/p2clib.c \ -## $(CURSRC)/parse.c \ -## $(CURSRC)/phqalloc.c \ -## $(CURSRC)/phreeqc_files.c \ -## $(CURSRC)/pitzer.c \ -## $(CURSRC)/pitzer_structures.c \ -## $(CURSRC)/prep.c \ -## $(CURSRC)/print.c \ -## $(CURSRC)/read.c \ -## $(CURSRC)/readtr.c \ -## $(CURSRC)/sit.c \ -## $(CURSRC)/smalldense.c \ -## $(CURSRC)/spread.c \ -## $(CURSRC)/step.c \ -## $(CURSRC)/structures.c \ -## $(CURSRC)/sundialsmath.c \ -## $(CURSRC)/tally.c \ -## $(CURSRC)/tidy.c \ -## $(CURSRC)/transport.c \ -## $(CURSRC)/utilities.c \ -## $(CURSRC)/basic.h \ -## $(CURSRC)/cvdense.h \ -## $(CURSRC)/cvode.h \ -## $(CURSRC)/dense.h \ -## $(CURSRC)/global.h \ -## $(CURSRC)/global_structures.h \ -## $(CURSRC)/input.h \ -## $(CURSRC)/kinetics.h \ -## $(CURSRC)/nvector.h \ -## $(CURSRC)/nvector_serial.h \ -## $(CURSRC)/output.h \ -## $(CURSRC)/p2c.h \ -## $(CURSRC)/phqalloc.h \ -## $(CURSRC)/phrqproto.h \ -## $(CURSRC)/phrqtype.h \ -## $(CURSRC)/pitzer.h \ -## $(CURSRC)/pitzer_structures.h \ -## $(CURSRC)/smalldense.h \ -## $(CURSRC)/sundialsmath.h \ -## $(CURSRC)/sundialstypes.h \ -## database/*.dat \ -## examples/ex1 examples/ex1.out \ -## examples/ex2 examples/ex2.out examples/ex2.sel \ -## examples/ex3 examples/ex3.out \ -## examples/ex4 examples/ex4.out \ -## examples/ex5 examples/ex5.out examples/ex5.sel \ -## examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ -## examples/ex7 examples/ex7.out examples/ex7.sel \ -## examples/ex8 examples/ex8.out examples/ex8.sel \ -## examples/ex9 examples/ex9.out examples/ex9.sel \ -## examples/ex10 examples/ex10.out examples/ex10.sel \ -## examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ -## examples/ex12 examples/ex12.out examples/ex12.sel \ -## examples/ex12a examples/ex12a.out examples/ex12a.sel \ -## examples/ex13a examples/ex13a.out examples/ex13a.sel \ -## examples/ex13b examples/ex13b.out examples/ex13b.sel \ -## examples/ex13c examples/ex13c.out examples/ex13c.sel \ -## examples/ex14 examples/ex14.out examples/ex14.sel \ -## examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ -## examples/ex16 examples/ex16.out \ -## examples/ex17 examples/ex17.out \ -## examples/ex18 examples/ex18.out \ -## NOTICE.TXT \ -## README.TXT \ -## RELEASE.TXT \ -## doc/manual.pdf \ -## doc/wrir02-4172.pdf \ -## doc/phreeqc.txt \ -## bin/phreeqc.orig \ -## test/test.sh \ -## test/clean.sh \ -## test/check.sh - -##SED_ARGS= \ -## -e "s/@VERSION@/$(VERSION)/" \ -## -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ -## -e "s/VERSION_DATE/$(VERSION)/" \ -## -e "s^@GCC_VER@^$(GCC_VER)^" \ -## -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ -## -e "s/@REVISION@/$(REVISION)/" \ -## -e "s/@PHREEQC_VER@/$(VERSION)/" \ -## -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" -## - -##SED_ARGS2=\ - -e "s/^\# Remove the following definition if you do not have /\# Add the following definition if you have/" \ - -e "s/^INVERSE_CL1MP=TRUE/\#INVERSE_CL1MP=TRUE/" - -##remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files - -##output_files: linux_output_files # sun_output_files - -# make sure program is compiles, run examples and mytest -##linux_output_files: all -## cd ../examples; make >& make.out -## cd ../mytest; make >& make.out - -##clean_linux_output_files: -## cd ../examples; make clean -## cd ../mytest; make clean - -##sun_output_files: phreeqc.sun -## ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" - -##phreeqc.sun: -## ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" - -##clean_sun_output_files: -## cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean - -##all_dist: clean_dist linux source # win # sun - -##test_dist: linux_test source_test # sun_test - -# -#Linux -# -##linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist - -##source: source_export source_clean source_sed_files source_dist - -##linux_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Linux -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux - -##linux_clean: -## rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o - -##linux_sed_list= \ -## "$(EXPORT_DIR)/Linux/doc/README.TXT \ -## $(EXPORT_DIR)/Linux/src/main.c" - -##linux_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT -## for FILE in "$(linux_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done -## mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT -## mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT - -##linux_compile: -## make -C $(EXPORT_DIR)/Linux/src - -##linux_output: -## cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out - -##linux_dist: -## cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar -## -## cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) -## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar -## cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile -## cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz -## cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - -##source_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Source -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source - -##source_clean: -## rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o - -##source_sed_list= \ -## "$(EXPORT_DIR)/Source/doc/README.TXT \ -## $(EXPORT_DIR)/Source/src/main.c" - -##source_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT -## sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile -## for FILE in "$(source_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done -## mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT -## mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT - -##source_dist: -## cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar -## cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar -## cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz -## cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) -## -##linux_test: -## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux -## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh -## rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh - -##source_test: -## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source -## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source -## cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k -## cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh - -##clean_dist: -## rm -rf $(EXPORT_DIR) - -##clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files - -# -#Win -# -##win: win_export win_sed_files win_dist - -##win_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Win -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win - -##win_sed_list= \ - "$(EXPORT_DIR)/Win/src/main.c" - -##win_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT -## $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT -## sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT -## $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT -## for FILE in "$(win_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; \ - mv t $$FILE; \ - $(UNIX2DOS) $$FILE; \ - done -## mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT - -##win_dist: -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar -# Translate cr/lf -## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ - if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ - else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done -## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar -# remove example output -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel -# remove bin directory -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin -# remove test directory files -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat -# copy bat file -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat -## cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz -## cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . -## @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) - -##win_echo_files: -## @echo $(FILES) - -debug: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) - -debug_nomp: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) - -##web: -## cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc -## cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT -## cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT -## cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT -## cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT -## cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt -## cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT - -tester: - cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - svn status -q ../mytest - svn status -q ../examples +# Locations to save compressed tar file for distribution +EXPORT=$(TOPDIR)/src/phreeqc_export +EXPORT_DIR=$(EXPORT) +WIN_DIR=$(TOPDIR)/win +DIST_DIR=$(EXPORT_DIR) +DEBUG_DIR=phreeqc_debug +CURSRC=$(CURDIR) +DEBUG_EXE=$(CURSRC)/phreeqc +VERSION=2.12 +VER_DATE:=November 10, 2005 +VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") +V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") +GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") +KERNEL_VER:=$(shell uname -r) +ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) +TEXTCP=textcp DOS +SUN_DIR=$(TOPDIR)/src/Sun +UNIX2DOS=unix2dos +CCFLAGS_DBG=-Wall -ansi -g -DUSE_PHRQ_ALLOC # -std=c99 + +CFG1 :=`uname` +CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") +ifeq ($(CFG), CYGWIN) + SPOOL=> + SPOOL2=2>&1 +else + SPOOL=>& + SPOOL2= +endif + +# list of files for distribution +##FILES= \ +## $(CURSRC)/Makefile \ +## $(CURSRC)/advection.c \ +## $(CURSRC)/basic.c \ +## $(CURSRC)/basicsubs.c \ +## $(CURSRC)/cl1.c \ +## $(CURSRC)/cl1mp.c \ +## $(CURSRC)/cvdense.c \ +## $(CURSRC)/cvode.c \ +## $(CURSRC)/dense.c \ +## $(CURSRC)/dw.c \ +## $(CURSRC)/input.c \ +## $(CURSRC)/integrate.c \ +## $(CURSRC)/inverse.c \ +## $(CURSRC)/isotopes.c \ +## $(CURSRC)/kinetics.c \ +## $(CURSRC)/main.c \ +## $(CURSRC)/mainsubs.c \ +## $(CURSRC)/model.c \ +## $(CURSRC)/nvector.c \ +## $(CURSRC)/nvector_serial.c \ +## $(CURSRC)/output.c \ +## $(CURSRC)/p2clib.c \ +## $(CURSRC)/parse.c \ +## $(CURSRC)/phqalloc.c \ +## $(CURSRC)/phreeqc_files.c \ +## $(CURSRC)/pitzer.c \ +## $(CURSRC)/pitzer_structures.c \ +## $(CURSRC)/prep.c \ +## $(CURSRC)/print.c \ +## $(CURSRC)/read.c \ +## $(CURSRC)/readtr.c \ +## $(CURSRC)/sit.c \ +## $(CURSRC)/smalldense.c \ +## $(CURSRC)/spread.c \ +## $(CURSRC)/step.c \ +## $(CURSRC)/structures.c \ +## $(CURSRC)/sundialsmath.c \ +## $(CURSRC)/tally.c \ +## $(CURSRC)/tidy.c \ +## $(CURSRC)/transport.c \ +## $(CURSRC)/utilities.c \ +## $(CURSRC)/basic.h \ +## $(CURSRC)/cvdense.h \ +## $(CURSRC)/cvode.h \ +## $(CURSRC)/dense.h \ +## $(CURSRC)/global.h \ +## $(CURSRC)/global_structures.h \ +## $(CURSRC)/input.h \ +## $(CURSRC)/kinetics.h \ +## $(CURSRC)/nvector.h \ +## $(CURSRC)/nvector_serial.h \ +## $(CURSRC)/output.h \ +## $(CURSRC)/p2c.h \ +## $(CURSRC)/phqalloc.h \ +## $(CURSRC)/phrqproto.h \ +## $(CURSRC)/phrqtype.h \ +## $(CURSRC)/pitzer.h \ +## $(CURSRC)/pitzer_structures.h \ +## $(CURSRC)/smalldense.h \ +## $(CURSRC)/sundialsmath.h \ +## $(CURSRC)/sundialstypes.h \ +## database/*.dat \ +## examples/ex1 examples/ex1.out \ +## examples/ex2 examples/ex2.out examples/ex2.sel \ +## examples/ex3 examples/ex3.out \ +## examples/ex4 examples/ex4.out \ +## examples/ex5 examples/ex5.out examples/ex5.sel \ +## examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ +## examples/ex7 examples/ex7.out examples/ex7.sel \ +## examples/ex8 examples/ex8.out examples/ex8.sel \ +## examples/ex9 examples/ex9.out examples/ex9.sel \ +## examples/ex10 examples/ex10.out examples/ex10.sel \ +## examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ +## examples/ex12 examples/ex12.out examples/ex12.sel \ +## examples/ex12a examples/ex12a.out examples/ex12a.sel \ +## examples/ex13a examples/ex13a.out examples/ex13a.sel \ +## examples/ex13b examples/ex13b.out examples/ex13b.sel \ +## examples/ex13c examples/ex13c.out examples/ex13c.sel \ +## examples/ex14 examples/ex14.out examples/ex14.sel \ +## examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ +## examples/ex16 examples/ex16.out \ +## examples/ex17 examples/ex17.out \ +## examples/ex18 examples/ex18.out \ +## NOTICE.TXT \ +## README.TXT \ +## RELEASE.TXT \ +## doc/manual.pdf \ +## doc/wrir02-4172.pdf \ +## doc/phreeqc.txt \ +## bin/phreeqc.orig \ +## test/test.sh \ +## test/clean.sh \ +## test/check.sh + +##SED_ARGS= \ +## -e "s/@VERSION@/$(VERSION)/" \ +## -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ +## -e "s/VERSION_DATE/$(VERSION)/" \ +## -e "s^@GCC_VER@^$(GCC_VER)^" \ +## -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ +## -e "s/@REVISION@/$(REVISION)/" \ +## -e "s/@PHREEQC_VER@/$(VERSION)/" \ +## -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" +## + +##SED_ARGS2=\ + -e "s/^\# Remove the following definition if you do not have /\# Add the following definition if you have/" \ + -e "s/^INVERSE_CL1MP=TRUE/\#INVERSE_CL1MP=TRUE/" + +##remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files + +##output_files: linux_output_files # sun_output_files + +# make sure program is compiles, run examples and mytest +##linux_output_files: all +## cd ../examples; make >& make.out +## cd ../mytest; make >& make.out + +##clean_linux_output_files: +## cd ../examples; make clean +## cd ../mytest; make clean + +##sun_output_files: phreeqc.sun +## ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" + +##phreeqc.sun: +## ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" + +##clean_sun_output_files: +## cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean + +##all_dist: clean_dist linux source # win # sun + +##test_dist: linux_test source_test # sun_test + +# +#Linux +# +##linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist + +##source: source_export source_clean source_sed_files source_dist + +##linux_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Linux +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux + +##linux_clean: +## rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o + +##linux_sed_list= \ +## "$(EXPORT_DIR)/Linux/doc/README.TXT \ +## $(EXPORT_DIR)/Linux/src/main.c" + +##linux_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT +## for FILE in "$(linux_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done +## mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT +## mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT + +##linux_compile: +## make -C $(EXPORT_DIR)/Linux/src + +##linux_output: +## cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out + +##linux_dist: +## cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar +## +## cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) +## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +## cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile +## cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz +## cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) + +##source_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Source +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source + +##source_clean: +## rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o + +##source_sed_list= \ +## "$(EXPORT_DIR)/Source/doc/README.TXT \ +## $(EXPORT_DIR)/Source/src/main.c" + +##source_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT +## sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile +## for FILE in "$(source_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done +## mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT +## mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT + +##source_dist: +## cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar +## cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar +## cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz +## cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) +## +##linux_test: +## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux +## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh +## rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k +## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh + +##source_test: +## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source +## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source +## cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k +## cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh + +##clean_dist: +## rm -rf $(EXPORT_DIR) + +##clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files + +# +#Win +# +##win: win_export win_sed_files win_dist + +##win_export: +## mkdir -p $(EXPORT_DIR) +## rm -rf $(EXPORT_DIR)/Win +## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win + +##win_sed_list= \ + "$(EXPORT_DIR)/Win/src/main.c" + +##win_sed_files: +## sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT +## $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT +## sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT +## $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT +## for FILE in "$(win_sed_list)"; do \ +## sed $(SED_ARGS) < $$FILE > t; \ + mv t $$FILE; \ + $(UNIX2DOS) $$FILE; \ + done +## mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT + +##win_dist: +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar +# Translate cr/lf +## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ + if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ + else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done +## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) +## cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar +# remove example output +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel +# remove bin directory +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin +# remove test directory files +## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat +# copy bat file +## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat +## cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz +## cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . +## @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). +## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) + +##win_echo_files: +## @echo $(FILES) + +debug: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) + +debug_nomp: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) + +##web: +## cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc +## cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT +## cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT +## cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT +## cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT +## cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt +## cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT + +tester: + cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + svn status -q ../mytest + svn status -q ../examples From bbd0d318b9dc8aecac4e4fabe54f6b8201dcf6c2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 3 Nov 2014 16:54:22 +0000 Subject: [PATCH 0866/1077] Bryant Jurgens, bug with pat file for Netpath. Vendome files were wrong in mytest. Need to update. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9029 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/inverse.cpp b/inverse.cpp index d79e5b5b..ff68ad0a 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -5242,6 +5242,7 @@ set_initial_solution(int n_user_old, int n_user_new) { cxxSolution *solution_ptr; Utilities::Rxn_copy(Rxn_solution_map, n_user_old, n_user_new); + Rxn_new_solution.insert(n_user_new); solution_ptr = Utilities::Rxn_find(Rxn_solution_map, n_user_new); solution_ptr->Set_new_def(true); if (solution_ptr->Get_initial_data() == NULL) From 77aa5ae5a92ce559d5e1b813727c992514e773a3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 3 Nov 2014 17:38:37 +0000 Subject: [PATCH 0867/1077] latest test cases, minor changes except for .pat file, which were wrong git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9030 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index d8538f05..f1a978bb 100644 --- a/Makefile +++ b/Makefile @@ -127,11 +127,11 @@ DIST_SOURCES = $(am__phreeqc_SOURCES_DIST) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run aclocal-1.11 -AMTAR = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run tar -AUTOCONF = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run autoconf -AUTOHEADER = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run autoheader -AUTOMAKE = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run automake-1.11 +ACLOCAL = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run aclocal-1.11 +AMTAR = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run tar +AUTOCONF = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run autoconf +AUTOHEADER = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run autoheader +AUTOMAKE = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run automake-1.11 AWK = gawk CPPFLAGS = CXX = g++ @@ -157,7 +157,7 @@ LIBGMP = -lgmp LIBOBJS = LIBS = LTLIBOBJS = -MAKEINFO = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/missing --run makeinfo +MAKEINFO = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/missing --run makeinfo MKDIR_P = /bin/mkdir -p OBJEXT = o PACKAGE = phreeqc @@ -172,10 +172,10 @@ SET_MAKE = SHELL = /bin/sh STRIP = VERSION = 3.0.0-7109 -abs_builddir = /lobo02home/dlpark/programs/phreeqc3-trunk/src -abs_srcdir = /lobo02home/dlpark/programs/phreeqc3-trunk/src -abs_top_builddir = /lobo02home/dlpark/programs/phreeqc3-trunk -abs_top_srcdir = /lobo02home/dlpark/programs/phreeqc3-trunk +abs_builddir = /raid/home/dlpark/programs/phreeqc3-trunk/src +abs_srcdir = /raid/home/dlpark/programs/phreeqc3-trunk/src +abs_top_builddir = /raid/home/dlpark/programs/phreeqc3-trunk +abs_top_srcdir = /raid/home/dlpark/programs/phreeqc3-trunk ac_ct_CXX = g++ am__include = include am__leading_dot = . @@ -194,7 +194,7 @@ host_alias = htmldir = ${docdir} includedir = ${prefix}/include infodir = ${datarootdir}/info -install_sh = ${SHELL} /lobo02home/dlpark/programs/phreeqc3-trunk/config/install-sh +install_sh = ${SHELL} /raid/home/dlpark/programs/phreeqc3-trunk/config/install-sh libdir = ${exec_prefix}/lib libexecdir = ${exec_prefix}/libexec localedir = ${datarootdir}/locale From 8262d5f224c17a01fcf7d77ec3eb0d9575bf7fe8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 18 Nov 2014 18:29:27 +0000 Subject: [PATCH 0868/1077] Added diff_c function to basic. Added test case diff_c to mytest. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9072 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 13 ++++++++++++- PBasic.h | 3 ++- Phreeqc.h | 1 + basicsubs.cpp | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 0390b5ae..aac02498 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1590,6 +1590,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokcallback: output_msg("CALLBACK"); break; + case tokdiff_c: + output_msg("DIFF_C"); + break; } l_buf = l_buf->next; } @@ -3528,6 +3531,13 @@ factor(struct LOC_exec * LINK) } break; + case tokdiff_c: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->diff_c(str); + } + break; + case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -6819,7 +6829,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("species_formula$", PBasic::tokspecies_formula_), std::map::value_type("eq_frac", PBasic::tokeq_frac), std::map::value_type("equiv_frac", PBasic::tokeq_frac), - std::map::value_type("callback", PBasic::tokcallback) + std::map::value_type("callback", PBasic::tokcallback), + std::map::value_type("diff_c", PBasic::tokdiff_c) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 63f8e716..8d4a0281 100644 --- a/PBasic.h +++ b/PBasic.h @@ -321,7 +321,8 @@ public: tokstr_e_, tokeq_frac, tokequiv_frac, - tokcallback + tokcallback, + tokdiff_c }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 09d3fd6c..edfb6f6d 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -92,6 +92,7 @@ public: LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); LDBLE aqueous_vm(const char *species_name); + LDBLE diff_c(const char *species_name); LDBLE calc_SC(void); /* VP: Density Start */ LDBLE calc_dens(void); diff --git a/basicsubs.cpp b/basicsubs.cpp index 22772319..73d61f46 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -98,7 +98,24 @@ aqueous_vm(const char *species_name) } return (g); } +LDBLE Phreeqc:: +diff_c(const char *species_name) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE g; + s_ptr = s_search(species_name); + if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + { + g = s_ptr->dw; + } + else + { + g = 0; + } + return (g); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_SC(void) From 3ad52ff74425c395996b7805d6c1fa399c85ac05 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 19 Nov 2014 16:04:06 +0000 Subject: [PATCH 0869/1077] Fixed bug, H+ was missing from SYS("AQ", ... git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9073 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 73d61f46..05ae689b 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2697,7 +2697,8 @@ system_total_aq(void) */ for (i = 0; i < count_s_x; i++) { - if (s_x[i]->type != AQ) + //if (s_x[i]->type != AQ) + if (s_x[i]->type > AQ) continue; sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = s_x[i]->moles; From fcff4cc3b7366b7fb19ba6c88335b7d523bb71a9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 3 Dec 2014 05:19:35 +0000 Subject: [PATCH 0870/1077] Fixed left shift operator error and null pointer error for R UBSAN check; Added INVERSE_CL1MP guard to cl1mp.cpp; Added test for ex10 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9084 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- UserPunch.cpp | 8 ++++++-- cl1mp.cpp | 2 ++ inverse.cpp | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/UserPunch.cpp b/UserPunch.cpp index 42dac9f3..290a427f 100644 --- a/UserPunch.cpp +++ b/UserPunch.cpp @@ -12,8 +12,12 @@ UserPunch::~UserPunch(void) { if (this->rate != NULL) { - this->PhreeqcPtr->rate_free(this->rate); + if (this->PhreeqcPtr != NULL) + { + this->PhreeqcPtr->rate_free(this->rate); + this->PhreeqcPtr->free_check_null(this->rate); + } } - this->PhreeqcPtr->free_check_null(this->rate); + this->PhreeqcPtr = NULL; this->rate = NULL; } diff --git a/cl1mp.cpp b/cl1mp.cpp index 09b557a7..e581cdcf 100644 --- a/cl1mp.cpp +++ b/cl1mp.cpp @@ -1,3 +1,4 @@ +#ifdef INVERSE_CL1MP #include #include #include @@ -1130,3 +1131,4 @@ cl1mp(int k, int l, int m, int n, kode = (int *) free_check_null(kode); return 0; } +#endif // INVERSE_CL1MP \ No newline at end of file diff --git a/inverse.cpp b/inverse.cpp index ff68ad0a..ffffa31b 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -1592,7 +1592,7 @@ get_bits(unsigned long bits, int position, int number) * Returns number of bits from position and below. * position begins at 0. */ - return ((bits >> (position + 1 - number)) & ~(~0 << number)); + return ((bits >> (position + 1 - number)) & ~(~0ul << number)); } /* ---------------------------------------------------------------------- */ From f6931e58fa039a791f7bd609baff912df90a570f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Dec 2014 00:51:01 +0000 Subject: [PATCH 0871/1077] removed USE_GMP git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9086 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cl1.cpp | 54 +----------------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/cl1.cpp b/cl1.cpp index 9c424862..ce47b201 100644 --- a/cl1.cpp +++ b/cl1.cpp @@ -2,10 +2,6 @@ #include #include #include -//#define USE_GMP -#if defined(USE_GMP) -#include -#endif #include "Phreeqc.h" #include "phqalloc.h" @@ -46,19 +42,7 @@ cl1(int k, int l, int m, int n, LDBLE tpivot; int klm, jmn, nkl, jpn; LDBLE cuv; -#if defined(USE_GMP) - mpf_set_default_prec(256); - mpf_t sum; - mpf_t z_mpf; - mpf_t q_mpf; - mpf_t d_mpf; - mpf_init(sum); - mpf_init(z_mpf); - mpf_init(q_mpf); - mpf_init(d_mpf); -#else long double sum; -#endif int klm1; int q_dim, cu_dim; int kode_arg; @@ -314,11 +298,7 @@ cl1(int k, int l, int m, int n, #endif for (j = js; j < n1; ++j) { -#if defined(USE_GMP) - mpf_set_d(sum, 0.0); -#else sum = 0.; -#endif for (i = 0; i < klm; ++i) { ii = q2[i * q_dim + n1].ival; @@ -330,21 +310,9 @@ cl1(int k, int l, int m, int n, { l_z = l_cu[ii - 1]; } -#if defined(USE_GMP) - mpf_set_d(z_mpf, l_z); - mpf_set_d(q_mpf, q2[i * q_dim + j].dval); - mpf_mul(d_mpf, z_mpf, q_mpf); - mpf_add(sum, sum, d_mpf); -#else - sum += (long double) q2[i * q_dim + j].dval * (long double) l_z; -#endif - + sum += (long double) q2[i * q_dim + j].dval * (long double) l_z; } -#if defined(USE_GMP) - q2[klm * q_dim + j].dval = mpf_get_d(sum); -#else q2[klm * q_dim + j].dval = (double)sum; -#endif } for (j = js; j < n; ++j) { @@ -724,11 +692,7 @@ cl1(int k, int l, int m, int n, #ifdef DEBUG_CL1 output_msg(sformatf( "L590\n")); #endif -#if defined(USE_GMP) - mpf_set_d(sum, 0.0); -#else sum = 0.; -#endif for (j = 0; j < n; ++j) { l_x[j] = 0.; @@ -760,13 +724,7 @@ cl1(int k, int l, int m, int n, if (ii >= n1 && ii <= nk) { /* * DBLE(Q(I,N1)) */ -#if defined(USE_GMP) - mpf_set_d(q_mpf, q2[i * q_dim + n].dval); - mpf_add(sum, sum, d_mpf); -#else sum += (long double) q2[i * q_dim + n].dval; -#endif - } } } @@ -774,17 +732,7 @@ cl1(int k, int l, int m, int n, #ifdef DEBUG_CL1 output_msg(sformatf( "L640\n")); #endif -#if defined(USE_GMP) - *l_error = mpf_get_d(sum); -#else *l_error = (double)sum; -#endif -#if defined(USE_GMP) - mpf_clear(sum); - mpf_clear(z_mpf); - mpf_clear(q_mpf); - mpf_clear(d_mpf); -#endif /* * Check calculation */ From 1d876f55e0494e9fade0604fa191accae9bea7bf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Dec 2014 23:25:08 +0000 Subject: [PATCH 0872/1077] Initialize type in NameDouble.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9165 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/NameDouble.cxx b/NameDouble.cxx index 04c0fc4b..c0bbc4c2 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -26,6 +26,7 @@ cxxNameDouble::cxxNameDouble() // default constructor for cxxNameDouble // { + this->type = ND_ELT_MOLES; } cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr) From cf9fa724b87a5970ceb1ad64a87bb32f39bc4c00 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Jan 2015 06:20:24 +0000 Subject: [PATCH 0873/1077] added initialization code for cxxPPassemblage git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9166 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PPassemblage.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PPassemblage.cxx b/PPassemblage.cxx index 1b9dd944..df8e5ba9 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -24,6 +24,7 @@ cxxPPassemblage::cxxPPassemblage(PHRQ_io * io) // : cxxNumKeyword(io) { + new_def = false; eltList.type = cxxNameDouble::ND_ELT_MOLES; } @@ -327,4 +328,4 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("new_def"), // 2 std::vector< std::string >::value_type("assemblage_totals") // 3 }; -const std::vector< std::string > cxxPPassemblage::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file +const std::vector< std::string > cxxPPassemblage::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); From 8e104d546361e20ad55eb735d45819b8924edf10 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Feb 2015 15:58:09 +0000 Subject: [PATCH 0874/1077] Roughed in surface area calculation by DeClercq (sa_declercq for now). Fixed bug where H+ was missing from list of aqueous species generated by SYS. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9230 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 42 ++++++++++++++++++++++++++++++++++++++- PBasic.h | 3 ++- Phreeqc.h | 1 + basicsubs.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index aac02498..e5c70934 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1593,6 +1593,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokdiff_c: output_msg("DIFF_C"); break; + case toksa_declercq: + output_msg("SA_DECLERCQ"); + break; } l_buf = l_buf->next; } @@ -3531,6 +3534,42 @@ factor(struct LOC_exec * LINK) } break; + + case toksa_declercq: + { + double type, sa, d, m, m0, gfw; + + // left parenthesis + require(toklp, LINK); + + // first double arugument, type + type = realfactor(LINK); + require(tokcomma, LINK); + + // second double arugument, Sa + sa = realfactor(LINK); + require(tokcomma, LINK); + + // third double arugument, Sa + d = realfactor(LINK); + require(tokcomma, LINK); + + // fourth double arugument, m + m = realfactor(LINK); + require(tokcomma, LINK); + + // fifth double arugument, m0 + m0 = realfactor(LINK); + require(tokcomma, LINK); + + // sixth double arugument, gfw + gfw = realfactor(LINK); + require(tokrp, LINK); + + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->sa_declercq(type, sa, d, m, m0, gfw); + } + break; + case tokdiff_c: { const char * str = stringfactor(STR1, LINK); @@ -6830,7 +6869,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("eq_frac", PBasic::tokeq_frac), std::map::value_type("equiv_frac", PBasic::tokeq_frac), std::map::value_type("callback", PBasic::tokcallback), - std::map::value_type("diff_c", PBasic::tokdiff_c) + std::map::value_type("diff_c", PBasic::tokdiff_c), + std::map::value_type("sa_declercq", PBasic::toksa_declercq) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 8d4a0281..cadcef8f 100644 --- a/PBasic.h +++ b/PBasic.h @@ -322,7 +322,8 @@ public: tokeq_frac, tokequiv_frac, tokcallback, - tokdiff_c + tokdiff_c, + toksa_declercq }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index edfb6f6d..98984748 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -93,6 +93,7 @@ public: LDBLE log_activity_coefficient(const char *species_name); LDBLE aqueous_vm(const char *species_name); LDBLE diff_c(const char *species_name); + LDBLE sa_declercq(double type, double sa, double d, double m, double m0, double gfw); LDBLE calc_SC(void); /* VP: Density Start */ LDBLE calc_dens(void); diff --git a/basicsubs.cpp b/basicsubs.cpp index 05ae689b..feff1dc2 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -98,6 +98,58 @@ aqueous_vm(const char *species_name) } return (g); } + +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +sa_declercq(double sa_type, double Sa, double d, double m, double m0, double gfw) +/* ---------------------------------------------------------------------- */ +{ + if (sa_type == 0) + { + // surface-area-calculation-Fixed_Surface + return Sa; + } + else if (sa_type == 1) + // surface-area-calculation-Square + { + double mass0 = m0 * gfw; + double V0 = mass0 / d; + double St0 = mass0 * Sa; // total surface + double a0 = pow(V0, 1.0/3.0); // side length + double Sp0 = 6.0 * a0*a0; // surface particle + double np = St0 / Sp0; // number of particles + double RATS = Sa / St0; + double mass = m * gfw; + double V = mass / d; + double a = pow(V, 1.0/3.0); + double St = 6.0 * a*a*np; + return St * RATS; // total current surface + } + else if (sa_type == 2) + { + //double pi = 3.14159265359; + double mass0 = m0 * gfw; + double V0 = mass0 / d; // volume + double St0 = mass0 * Sa; // total surface + double a0 = pow(3.0 * V0/(4.0 * pi), 1.0/3.0); // ((3*V0)/(4 * 3.14159265359))^(1/3) + double Sp0 = (4.0 * pi) * a0 * a0; // surface particle + double np = St0 / Sp0; // number of particles + double RATS = Sa / St0; + + double mass = m * gfw; + double V = mass / d; + double a = pow(3.0 * V/(4.0 * pi), 1.0/3.0); //((3*V)/(4 * 3.14159265359))^(1/3) + double St = 4.0 * pi * a * a * np; + return St * RATS; // total current surface + } + error_string = sformatf( "Unknown surface area type in SA_DECLERCQ %d.", (int) sa_type); + error_msg(error_string, CONTINUE); + input_error++; + return (MISSING); + +} + +/* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: diff_c(const char *species_name) /* ---------------------------------------------------------------------- */ @@ -2698,7 +2750,7 @@ system_total_aq(void) for (i = 0; i < count_s_x; i++) { //if (s_x[i]->type != AQ) - if (s_x[i]->type > AQ) + if (s_x[i]->type > HPLUS) continue; sys[count_sys].name = string_duplicate(s_x[i]->name); sys[count_sys].moles = s_x[i]->moles; From 82d57719f7fe69070a734dd01274cd7b17962992 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 Feb 2015 23:40:34 +0000 Subject: [PATCH 0875/1077] moved keywords to PhreeqcKeywords directory git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9252 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Keywords.cpp => PhreeqcKeywords/Keywords.cpp | 0 Keywords.h => PhreeqcKeywords/Keywords.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Keywords.cpp => PhreeqcKeywords/Keywords.cpp (100%) rename Keywords.h => PhreeqcKeywords/Keywords.h (100%) diff --git a/Keywords.cpp b/PhreeqcKeywords/Keywords.cpp similarity index 100% rename from Keywords.cpp rename to PhreeqcKeywords/Keywords.cpp diff --git a/Keywords.h b/PhreeqcKeywords/Keywords.h similarity index 100% rename from Keywords.h rename to PhreeqcKeywords/Keywords.h From c4bf48e6a2f671b7b55985841667e1c9f39868e7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 24 Feb 2015 02:42:04 +0000 Subject: [PATCH 0876/1077] updated for PhreeqcKeywords git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9297 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 08ed9d98..45edab87 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/phreeqc +AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/PhreeqcKeywords bin_PROGRAMS = phreeqc @@ -23,8 +23,6 @@ phreeqc_SOURCES=\ ISolution.h\ ISolutionComp.cxx\ ISolutionComp.h\ - Keywords.cpp\ - Keywords.h\ KineticsComp.cxx\ KineticsComp.h\ NameDouble.cxx\ @@ -37,6 +35,8 @@ phreeqc_SOURCES=\ PBasic.h\ Phreeqc.cpp\ Phreeqc.h\ + PhreeqcKeywords/Keywords.cpp\ + PhreeqcKeywords/Keywords.h\ PHRQ_base.cxx\ PHRQ_base.h\ PHRQ_io.cpp\ From a9906af5f65b85d6335db067e160679542547170 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Feb 2015 19:22:09 +0000 Subject: [PATCH 0877/1077] Fixing VS static checker warnings. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9300 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 116 +++++++++++++++++++++++++++++++++++++++------ StorageBinList.cpp | 29 ++++++++---- cvdense.cpp | 3 +- cvode.cpp | 5 +- dumper.cpp | 4 +- gases.cpp | 5 +- inverse.cpp | 13 +++-- isotopes.cpp | 20 ++++++++ prep.cpp | 12 +++-- structures.cpp | 39 ++++++++------- tally.cpp | 8 +++- 11 files changed, 197 insertions(+), 57 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index e5c70934..56161bc3 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -482,7 +482,10 @@ numtostr(char * Result, LDBLE n) l_s = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char)); if (l_s == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } l_s[PhreeqcPtr->max_line - 1] = '\0'; /* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ if (ceil(n) == floor(n)) @@ -604,7 +607,10 @@ parse(char * l_inbuf, tokenrec ** l_buf) m = j + 1; t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); if (t->UU.sp == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } strncpy(t->UU.sp, l_inbuf + begin - 1, j); t->UU.sp[j] = '\0'; /* p2c: basic.p, line 415: @@ -726,7 +732,10 @@ parse(char * l_inbuf, tokenrec ** l_buf) m = 256; t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char)); if (t->UU.sp == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } sprintf(t->UU.sp, "%.*s", (int) (strlen(l_inbuf) - i + 1), l_inbuf + i - 1); @@ -743,7 +752,10 @@ parse(char * l_inbuf, tokenrec ** l_buf) { v = (varrec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(varrec)); if (v == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } v->UU.U0.arr = NULL; v->next = varbase; varbase = v; @@ -1670,7 +1682,10 @@ parseinput(tokenrec ** l_buf) { l1 = (linerec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(linerec)); if (l1 == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } l1->next = l; if (l0 == NULL) linebase = l1; @@ -1854,6 +1869,7 @@ require(int k, struct LOC_exec *LINK) strcpy(str, ": missing "); snerr(strcat(str, item->first.c_str())); } + exit(4); } LINK->t = LINK->t->next; } @@ -1865,7 +1881,10 @@ skipparen(struct LOC_exec *LINK) do { if (LINK->t == NULL) + { snerr(": parenthesis missing"); + exit(4); + } if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) goto _L1; if (LINK->t->kind == toklp) @@ -1888,7 +1907,10 @@ findvar(struct LOC_exec *LINK) long FORLIM; if (LINK->t == NULL || LINK->t->kind != tokvar) + { snerr(": can`t find variable"); + exit(4); + } v = LINK->t->UU.vp; LINK->t = LINK->t->next; if (LINK->t == NULL || LINK->t->kind != toklp) @@ -2533,15 +2555,21 @@ factor(struct LOC_exec * LINK) /* return number of species */ LINK->t = LINK->t->next; count_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + if (LINK->t->kind != tokvar || !count_varrec || count_varrec->stringvar != 0) + { snerr(": can`t find variable"); + exit(4); + } /* return number of names of species */ LINK->t = LINK->t->next; require(tokcomma, LINK); names_varrec = LINK->t->UU.vp; - if (LINK->t->kind != tokvar || names_varrec->stringvar != 1) + if (LINK->t->kind != tokvar || !names_varrec || names_varrec->stringvar != 1) + { snerr(": can`t find name of species"); + exit(4); + } /* return number of types of species */ LINK->t = LINK->t->next; @@ -2585,13 +2613,22 @@ factor(struct LOC_exec * LINK) int count_sys = PhreeqcPtr->count_sys; names_arg = (char **) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (names_arg == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } types_arg = (char **)PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (types_arg == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); if (moles_arg == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } names_arg[0] = NULL; types_arg[0] = NULL; moles_arg[0] = 0; @@ -2650,6 +2687,7 @@ factor(struct LOC_exec * LINK) /* * Parse arguments */ + arg_num = -1; if (LINK->t != NULL && LINK->t->kind == tokcomma) { LINK->t = LINK->t->next; @@ -2676,14 +2714,18 @@ factor(struct LOC_exec * LINK) else { snerr(": Expected 4 arguments for list_s_s"); + exit(4); } require(tokrp, LINK); if (arg_num > 1) { free_dim_stringvar(names_varrec); - PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); - moles_varrec->UU.U0.arr = NULL; + if (moles_varrec) + { + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + } } /* * Call subroutine @@ -2703,10 +2745,16 @@ factor(struct LOC_exec * LINK) */ names_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); if (names_varrec->UU.U1.sarr == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } moles_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); if (moles_varrec->UU.U0.arr == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } // first position not used names_varrec->UU.U1.sarr[0] = NULL; @@ -2901,10 +2949,16 @@ factor(struct LOC_exec * LINK) */ elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); if (elts_varrec->UU.U1.sarr == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); if (coef_varrec->UU.U0.arr == NULL) + { PhreeqcPtr->malloc_error(); + exit(4); + } // first position not used elts_varrec->UU.U1.sarr[0] = NULL; @@ -3777,15 +3831,32 @@ sexpr(struct LOC_exec * LINK) { if (n.stringval) { - m = (int) strlen(n.UU.sval) + (int) strlen(n2.UU.sval) + 1; + m = 1; + if (n.UU.sval) + { + m += (int) strlen(n.UU.sval); + } + if (n2.UU.sval) + { + m += (int) strlen(n2.UU.sval); + } + //m = (int) strlen(n.UU.sval) + (int) strlen(n2.UU.sval) + 1; if (m < 256) m = 256; n.UU.sval = (char *) PhreeqcPtr->PHRQ_realloc(n.UU.sval, (size_t) m * sizeof(char)); if (n.UU.sval == NULL) + { PhreeqcPtr->malloc_error(); - strcat(n.UU.sval, n2.UU.sval); - PhreeqcPtr->PHRQ_free(n2.UU.sval); + } + else + { + if (n2.UU.sval) + { + strcat(n.UU.sval, n2.UU.sval); + PhreeqcPtr->PHRQ_free(n2.UU.sval); + } + } } else n.UU.val += n2.UU.val; @@ -4127,7 +4198,10 @@ cmdload(bool merging, char * name, struct LOC_exec *LINK) f = fopen(STR1, "r"); } if (f == NULL) + { _EscIO(FileNotFound); + return; + } while (fgets(inbuf, 256, f) != NULL) { TEMP = strchr(inbuf, '\n'); @@ -4860,9 +4934,14 @@ cmdfor(struct LOC_exec *LINK) } l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec)); if (l == NULL) + { PhreeqcPtr->malloc_error(); - *l = lr; - loopbase = l; + } + else + { + *l = lr; + loopbase = l; + } } void PBasic:: @@ -5295,6 +5374,11 @@ cmddim(struct LOC_exec *LINK) if (v->stringvar) { v->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc(j * sizeof(char *)); + if (!v->UU.U1.sarr) + { + PhreeqcPtr->malloc_error(); + exit(4); + } if (v->UU.U1.sarr == NULL) PhreeqcPtr->malloc_error(); for (i = 0; i < j; i++) @@ -5326,12 +5410,16 @@ cmderase(struct LOC_exec *LINK) do { if (LINK->t == NULL || LINK->t->kind != tokvar) + { snerr(": error in DIM command"); - - v = LINK->t->UU.vp; - LINK->t = LINK->t->next; - clearvar(v); - if (!iseos(LINK)) require(tokcomma, LINK); + } + else + { + v = LINK->t->UU.vp; + LINK->t = LINK->t->next; + clearvar(v); + if (!iseos(LINK)) require(tokcomma, LINK); + } } while (!iseos(LINK)); } diff --git a/StorageBinList.cpp b/StorageBinList.cpp index 1cbc4a54..71a89692 100644 --- a/StorageBinList.cpp +++ b/StorageBinList.cpp @@ -218,20 +218,29 @@ bool StorageBinList::Read(CParser & parser) for (;;) { CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - if (j == CParser::TT_DIGIT) + if (item) { - item->Augment(token); - } - else if (j == CParser::TT_EMPTY) - { - item->Augment(token); - break; + if (j == CParser::TT_DIGIT) + { + item->Augment(token); + } + else if (j == CParser::TT_EMPTY) + { + item->Augment(token); + break; + } + else + { + parser.error_msg("Expected single number or range of numbers.", + PHRQ_io::OT_CONTINUE); + break; + } } else { - parser.error_msg("Expected single number or range of numbers.", - PHRQ_io::OT_CONTINUE); - break; + parser.error_msg("Dump entity type not defined.", + PHRQ_io::OT_CONTINUE); + break; } } } diff --git a/cvdense.cpp b/cvdense.cpp index 6101ddb1..f365136b 100644 --- a/cvdense.cpp +++ b/cvdense.cpp @@ -378,7 +378,8 @@ CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) cv_mem = (CVodeMem) cvode_mem; if (cv_mem == NULL) { /* CVode reports this error */ - CVMEM warning_msg( MSG_CVMEM_NULL); + //CVMEM warning_msg( MSG_CVMEM_NULL); + std::cerr << MSG_CVMEM_NULL << std::endl; return (LMEM_FAIL); } diff --git a/cvode.cpp b/cvode.cpp index 760fd464..9cffd81f 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -2299,7 +2299,10 @@ CVIncreaseBDF(CVodeMem cv_mem) } } A1 = (-alpha0 - alpha1) / prod; - N_VScale(A1, zn[qmax], zn[L]); + if (L >= 0 && L <= qmax) + { + N_VScale(A1, zn[qmax], zn[L]); + } for (j = 2; j <= q; j++) { N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); diff --git a/dumper.cpp b/dumper.cpp index 031571ab..bc89a50e 100644 --- a/dumper.cpp +++ b/dumper.cpp @@ -125,11 +125,11 @@ bool dumper::Read(CParser & parser) for (;;) { CParser::TOKEN_TYPE j = parser.copy_token(token, next_char); - if (j == CParser::TT_DIGIT) + if (item && j == CParser::TT_DIGIT) { item->Augment(token); } - else if (j == CParser::TT_EMPTY) + else if (item && j == CParser::TT_EMPTY) { item->Augment(token); break; diff --git a/gases.cpp b/gases.cpp index 9610dc7a..1869e616 100644 --- a/gases.cpp +++ b/gases.cpp @@ -269,7 +269,10 @@ build_fixed_volume_gas(void) else { master_ptr = master_bsearch_primary(rxn_ptr->s->name); - master_ptr->s->la = -999.0; + if (master_ptr && master_ptr->s) + { + master_ptr->s->la = -999.0; + } } if (master_ptr == NULL) diff --git a/inverse.cpp b/inverse.cpp index ffffa31b..2d4b9137 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -79,6 +79,7 @@ inverse_models(void) { error_string = sformatf( "Can`t open file, %s.", string); error_msg(error_string, STOP); + exit(4); } count_inverse_models = 0; count_pat_solutions = 0; @@ -4081,6 +4082,7 @@ dump_netpath(struct inverse *inverse_ptr) { error_string = sformatf( "Can`t open file, %s.", inverse_ptr->netpath); error_msg(error_string, STOP); + exit(4); } add_to_file("netpath.fil", inverse_ptr->netpath); @@ -5273,11 +5275,12 @@ add_to_file(const char *filename, const char *string) if (model_file == NULL) { model_file = fopen(filename, "w"); - if (model_file == NULL) - { - error_string = sformatf( "Can`t open file, %s.", filename); - error_msg(error_string, STOP); - } + } + if (model_file == NULL) + { + error_string = sformatf( "Can`t open file, %s.", filename); + error_msg(error_string, STOP); + exit(4); } i = 0; /* diff --git a/isotopes.cpp b/isotopes.cpp index ee421ecd..4351f0f0 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -243,6 +243,8 @@ read_calculate_values(void) break; case OPT_1: /* read command */ + if (calculate_value_ptr) + { length = (int) strlen(calculate_value_ptr->commands); line_length = (int) strlen(line); calculate_value_ptr->commands = @@ -255,6 +257,15 @@ read_calculate_values(void) calculate_value_ptr->commands[length + 1] = '\0'; strcat((calculate_value_ptr->commands), line); opt_save = OPT_1; + } + else + { + error_string = sformatf( + "Expecting a calculate_value definition, %s. CALCULATE_VALUES data block.", + line); + error_msg(error_string, CONTINUE); + input_error++; + } break; } if (return_value == EOF || return_value == KEYWORD) @@ -891,6 +902,15 @@ punch_calculate_values(void) result = MISSING; calculate_value_ptr = calculate_value_search(current_selected_output->Get_calculate_values()[i].first.c_str()); + if (!calculate_value_ptr) + { + error_string = sformatf( + "Definition not found for CALCULATE_VALUES %s.", + current_selected_output->Get_calculate_values()[i].first.c_str()); + error_msg(error_string, STOP); + exit(4); + } + if (calculate_value_ptr->calculated == FALSE) { rate_moles = NAN; diff --git a/prep.cpp b/prep.cpp index 63c2bb1c..ae96fcb0 100644 --- a/prep.cpp +++ b/prep.cpp @@ -44,6 +44,7 @@ prep(void) { error_msg("Solution needed for calculation not found, stopping.", STOP); + exit(4); } description_x = (char *) free_check_null(description_x); description_x = string_duplicate(solution_ptr->Get_description().c_str()); @@ -595,7 +596,10 @@ build_gas_phase(void) else { master_ptr = master_bsearch_primary(rxn_ptr->s->name); - master_ptr->s->la = -999.0; + if (master_ptr && master_ptr->s) + { + master_ptr->s->la = -999.0; + } } if (master_ptr == NULL) { @@ -3146,11 +3150,12 @@ add_cd_music_charge_balances(int n) break; } } - if (i >= count_elts) + if (i >= count_elts || master_ptr == NULL) { error_string = sformatf( "No surface master species found for surface species."); error_msg(error_string, STOP); + return ERROR; } /* * Find potential unknown for plane 0 @@ -5538,7 +5543,7 @@ calc_lk_phase(phase *p_ptr, LDBLE TK, LDBLE pa) } d_v -= p_ptr->logk[vm0]; r_ptr->logk[delta_v] = d_v; - if (!strcmp(r_ptr->token[0].name, "H2O(g)")) + if (r_ptr->token[0].name && !strcmp(r_ptr->token[0].name, "H2O(g)")) r_ptr->logk[delta_v] = 0.0; return k_calc(r_ptr->logk, TK, pa * PASCAL_PER_ATM); @@ -6124,6 +6129,7 @@ build_min_exch(void) error_string = sformatf( "Exchange %d not found.", use.Get_n_exchange_user()); error_msg(error_string, CONTINUE); + return ERROR; } n_user = exchange_ptr->Get_n_user(); if (!exchange_ptr->Get_related_phases()) diff --git a/structures.cpp b/structures.cpp index 67781a29..b41a615a 100644 --- a/structures.cpp +++ b/structures.cpp @@ -1212,7 +1212,7 @@ master_bsearch_secondary(char *ptr) int l; char *ptr1; char elt[MAX_LENGTH]; - struct master *master_ptr_primary, *master_ptr, *master_ptr_secondary=NULL; + struct master *master_ptr_primary, *master_ptr=NULL, *master_ptr_secondary=NULL; int j; /* * Find element name @@ -1233,36 +1233,39 @@ master_bsearch_secondary(char *ptr) /* * If last in list or not redox */ - if ((master_ptr_primary->number >= count_master - 1) || - (master[master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) + if (master_ptr_primary) { - return(master_ptr_primary); - } -/* - * Find secondary master with same species as primary - */ - master_ptr = NULL; - for (j = master_ptr_primary->number + 1; j < count_master; j++) - { - if (master[j]->s == master_ptr_primary->s) + if ((master_ptr_primary->number >= count_master - 1) || + (master[master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) { - master_ptr = master[j]; + return(master_ptr_primary); + } + /* + * Find secondary master with same species as primary + */ + master_ptr = NULL; + for (j = master_ptr_primary->number + 1; j < count_master; j++) + { + if (master[j]->s == master_ptr_primary->s) + { + master_ptr = master[j]; + } } } /* * */ - if (master_ptr->elt->primary != master_ptr_primary) + if (master_ptr != NULL && master_ptr->elt != NULL && (master_ptr->elt->primary == master_ptr_primary)) { + master_ptr_secondary = master_ptr; + } + else + { input_error++; error_string = sformatf( "Could not find secondary master species for %s.", ptr); error_msg(error_string, STOP); } - else - { - master_ptr_secondary = master_ptr; - } return (master_ptr_secondary); diff --git a/tally.cpp b/tally.cpp index 7f0178ca..a7405e87 100644 --- a/tally.cpp +++ b/tally.cpp @@ -710,7 +710,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) if (strcmp_nocase(phase_ptr->name, tally_table[i].name) == 0) break; } - if (k < ss_ptr->Get_ss_comps().size()) + if (k < ss_ptr->Get_ss_comps().size() && comp_ptr) { moles = comp_ptr->Get_moles(); found = TRUE; @@ -775,7 +775,11 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer) } if (j >= kinetics_ptr->Get_kinetics_comps().size()) break; - moles = kinetics_comp_ptr->Get_m(); + moles = 0.0; + if (kinetics_comp_ptr) + { + moles = kinetics_comp_ptr->Get_m(); + } tally_table[i].moles = moles; count_elts = 0; paren_count = 0; From 4a2f590f0e939dd41b002c8b00fc15dbc14afab2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Feb 2015 20:07:51 +0000 Subject: [PATCH 0878/1077] fixed for Keyword git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9301 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 594 ++++++++++++++++++++++++++++----------------------- 1 file changed, 326 insertions(+), 268 deletions(-) diff --git a/Makefile.old b/Makefile.old index 1d5c0d11..8cef0b75 100644 --- a/Makefile.old +++ b/Makefile.old @@ -125,8 +125,8 @@ ifeq ($(CFG), CLASS_DEBUG) CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = .. - INCLUDES = -I.. + VPATH = ..:../PhreeqcKeywords + INCLUDES = -I.. -I../PhreeqcKeywords CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -142,8 +142,8 @@ ifeq ($(CFG), CLASS_RELEASE) CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = .. - INCLUDES = -I.. + VPATH = ..:../PhreeqcKeywords + INCLUDES = -I.. -I../PhreeqcKeywords CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -158,8 +158,8 @@ ifeq ($(CFG), CLASS_DEBUG_64) CL1MP_LIB=libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = .. - INCLUDES = -I.. + VPATH = ..:../PhreeqcKeywords + INCLUDES = -I.. -I../PhreeqcKeywords CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -174,8 +174,8 @@ ifeq ($(CFG), CLASS_RELEASE_64) CL1MP_LIB=/usr/lib64/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DUSE_PHRQ_ALLOC # -DR_SO - VPATH = .. - INCLUDES = -I.. + VPATH = ..:../PhreeqcKeywords + INCLUDES = -I.. -I../PhreeqcKeywords CXX = g++ PROFILE = CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g @@ -288,157 +288,178 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../cxxKinetics.h ../KineticsComp.h ../phqalloc.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -Exchange.o: ../Exchange.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +cxxMix.o: ../cxxMix.cxx ../Utils.h ../phrqtype.h ../Parser.h \ + ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +Exchange.o: ../Exchange.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../Exchange.h ../ExchComp.h ../phqalloc.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +ExchComp.o: ../ExchComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../ExchComp.h ../phqalloc.h -GasComp.o: ../GasComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +GasComp.o: ../GasComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../GasComp.h ../phqalloc.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +GasPhase.o: ../GasPhase.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../GasPhase.h ../GasComp.h ../phqalloc.h -ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../ISolutionComp.h \ - ../phrqtype.h ../Parser.h ../PHRQ_base.h ../Keywords.h ../PHRQ_io.h \ - ../Solution.h ../NumKeyword.h ../SolutionIsotope.h ../NameDouble.h \ - ../ISolution.h ../global_structures.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../NA.h ../phqalloc.h -ISolution.o: ../ISolution.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../phrqtype.h \ + ../ISolutionComp.h ../Parser.h ../PHRQ_base.h \ + ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotope.h ../NameDouble.h ../ISolution.h \ + ../global_structures.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../NA.h ../phqalloc.h +ISolution.o: ../ISolution.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../ISolution.h ../ISolutionComp.h ../phqalloc.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../KineticsComp.h ../phqalloc.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +NameDouble.o: ../NameDouble.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../ISolutionComp.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../PHRQ_io.h ../Utils.h -Parser.o: ../Parser.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../PHRQ_io.h -PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h ../Keywords.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../Phreeqc.h \ - ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ + ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Utils.h \ + ../phrqtype.h +Parser.o: ../Parser.cxx ../Utils.h ../phrqtype.h ../Parser.h \ + ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h +PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../phrqtype.h \ + ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ - ../NA.h ../PPassemblageComp.h ../phqalloc.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../PPassemblageComp.h ../phqalloc.h +PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../PPassemblage.h ../PPassemblageComp.h ../phqalloc.h -Pressure.o: ../Pressure.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -Reaction.o: ../Reaction.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +Pressure.o: ../Pressure.cxx ../Utils.h ../phrqtype.h ../Parser.h \ + ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +Reaction.o: ../Reaction.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../Reaction.h ../phqalloc.h -ReadClass.o: ../ReadClass.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +ReadClass.o: ../ReadClass.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ ../Exchange.h ../ExchComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../cxxKinetics.h ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ ../GasPhase.h ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h -Solution.o: ../Solution.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +Solution.o: ../Solution.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ ../phqalloc.h -SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../Phreeqc.h \ - ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ +SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../phrqtype.h \ + ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ - ../NA.h ../SolutionIsotope.h ../phqalloc.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../SolutionIsotope.h ../phqalloc.h +SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../phqalloc.h -SScomp.o: ../SScomp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +SScomp.o: ../SScomp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../SScomp.h ../phqalloc.h SS.o: ../SS.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Utils.h ../SS.h \ - ../SScomp.h ../phqalloc.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Utils.h ../SS.h ../SScomp.h \ + ../phqalloc.h +StorageBin.o: ../StorageBin.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../StorageBin.h ../System.h ../SSassemblage.h ../SS.h ../SScomp.h \ @@ -446,50 +467,56 @@ StorageBin.o: ../StorageBin.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h \ ../Temperature.h ../phqalloc.h -SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../Phreeqc.h \ - ../phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ +SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../phrqtype.h \ + ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../SurfaceCharge.h ../global_structures.h \ - ../NA.h ../phqalloc.h -SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h -Surface.o: ../Surface.cxx ../Utils.h ../Phreeqc.h ../phrqtype.h \ +SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Surface.o: ../Surface.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h System.o: ../System.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../System.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../cxxKinetics.h ../KineticsComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../Parser.h ../PHRQ_base.h \ - ../Keywords.h ../PHRQ_io.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../Pressure.h \ - ../NumKeyword.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Temperature.h ../phqalloc.h -Utils.o: ../Utils.cxx ../Utils.h ../Parser.h ../PHRQ_base.h ../Keywords.h \ - ../PHRQ_io.h -advection.o: ../advection.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../System.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Reaction.h ../Temperature.h +Temperature.o: ../Temperature.cxx ../Utils.h ../phrqtype.h ../Parser.h \ + ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Temperature.h \ + ../phqalloc.h +Utils.o: ../Utils.cxx ../Utils.h ../phrqtype.h ../Parser.h ../PHRQ_base.h \ + ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h +advection.o: ../advection.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ @@ -497,101 +524,105 @@ advection.o: ../advection.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ basicsubs.o: ../basicsubs.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Utils.h ../PBasic.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../PBasic.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ChartHandler.o: ../ChartHandler.cpp ChartObject.o: ../ChartObject.cpp cl1.o: ../cl1.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h -cl1mp.o: ../cl1mp.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +cl1mp.o: ../cl1mp.cpp class_main.o: ../class_main.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ + ../KineticsComp.h CurveObject.o: ../CurveObject.cpp cvdense.o: ../cvdense.cpp ../cvdense.h ../cvode.h ../sundialstypes.h \ ../phrqtype.h ../nvector.h ../dense.h ../smalldense.h ../sundialsmath.h \ ../Phreeqc.h ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h \ - ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h \ - ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ + ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h -cvode.o: ../cvode.cpp ../cvode.h ../sundialstypes.h ../phrqtype.h \ - ../nvector.h ../sundialsmath.h ../Phreeqc.h ../cvdense.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ +cvode.o: ../cvode.cpp ../nvector_serial.h ../nvector.h ../sundialstypes.h \ + ../phrqtype.h ../cvode.h ../sundialsmath.h ../Phreeqc.h ../cvdense.h \ + ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h dense.o: ../dense.cpp ../sundialstypes.h ../phrqtype.h ../sundialsmath.h \ ../dense.h ../smalldense.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../Keywords.h ../PHRQ_io.h + ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h dw.o: ../dw.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h gases.o: ../gases.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../GasPhase.h \ - ../GasComp.h -input.o: ../input.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../GasPhase.h ../GasComp.h +input.o: ../input.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h integrate.o: ../integrate.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Utils.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h inverse.o: ../inverse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Utils.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h isotopes.o: ../isotopes.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -Keywords.o: ../Keywords.cpp ../Keywords.h -kinetics.o: ../kinetics.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +kinetics.o: ../kinetics.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ @@ -599,10 +630,11 @@ kinetics.o: ../kinetics.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ ../ISolutionComp.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../Temperature.h ../nvector_serial.h -mainsubs.o: ../mainsubs.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ +mainsubs.o: ../mainsubs.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h \ @@ -610,146 +642,160 @@ mainsubs.o: ../mainsubs.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ ../ISolution.h ../ISolutionComp.h -model.o: ../model.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +model.o: ../model.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h ../phrqtype.h nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.h \ ../sundialstypes.h ../phrqtype.h ../sundialsmath.h parse.o: ../parse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h PBasic.o: ../PBasic.cpp ../PBasic.h ../phrqtype.h ../PHRQ_base.h \ ../global_structures.h ../Surface.h ../NumKeyword.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../Keywords.h ../PHRQ_io.h \ + ../NameDouble.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ ../SurfaceCharge.h ../NA.h ../Phreeqc.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../phqalloc.h ../Utils.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h + ../StorageBinList.h ../dumper.h ../SelectedOutput.h ../UserPunch.h \ + ../Pressure.h ../cxxMix.h ../Use.h ../phqalloc.h ../Utils.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h phqalloc.o: ../phqalloc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h ../phqalloc.h ../PBasic.h \ - ../Temperature.h -PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h ../Keywords.h ../Parser.h \ - ../PHRQ_base.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../Reaction.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ + ../KineticsComp.h ../phqalloc.h ../PBasic.h ../Temperature.h +PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../Parser.h ../PHRQ_base.h PHRQ_io_output.o: ../PHRQ_io_output.cpp ../Phreeqc.h ../phrqtype.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h pitzer.o: ../pitzer.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Exchange.h ../ExchComp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h pitzer_structures.o: ../pitzer_structures.cpp ../Phreeqc.h ../phrqtype.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h -prep.o: ../prep.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +prep.o: ../prep.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -print.o: ../print.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h +print.o: ../print.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -read.o: ../read.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +read.o: ../read.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h readtr.o: ../readtr.cpp ../StorageBin.h ../System.h ../NameDouble.h \ - ../Parser.h ../PHRQ_base.h ../Keywords.h ../PHRQ_io.h ../phrqtype.h \ - ../SS.h ../SScomp.h ../Phreeqc.h ../cvdense.h ../cvode.h \ + ../Parser.h ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ + ../phrqtype.h ../SS.h ../SScomp.h ../Phreeqc.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../Pressure.h ../NumKeyword.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h + ../StorageBinList.h ../dumper.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h ../Utils.h runner.o: ../runner.cpp ../runner.h ../phrqtype.h ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h ../NA.h ../Utils.h + ../PHRQ_base.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ + ../NA.h ../Utils.h +SelectedOutput.o: ../SelectedOutput.cpp ../SelectedOutput.h \ + ../NumKeyword.h ../PHRQ_base.h sit.o: ../sit.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Exchange.h ../ExchComp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h smalldense.o: ../smalldense.cpp ../smalldense.h ../sundialstypes.h \ ../phrqtype.h ../sundialsmath.h spread.o: ../spread.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../Utils.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Utils.h step.o: ../step.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Utils.h ../StorageBin.h ../System.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../cxxKinetics.h ../KineticsComp.h + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../StorageBin.h \ + ../System.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Temperature.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h ../cxxKinetics.h \ + ../KineticsComp.h StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../Keywords.h ../PHRQ_io.h -structures.o: ../structures.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PHRQ_base.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h +structures.o: ../structures.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ @@ -759,30 +805,32 @@ structures.o: ../structures.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ ../StorageBin.h ../System.h sundialsmath.o: ../sundialsmath.cpp ../sundialsmath.h ../sundialstypes.h \ ../phrqtype.h -tally.o: ../tally.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +tally.o: ../tally.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ - ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -tidy.o: ../tidy.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +tidy.o: ../tidy.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../Keywords.h ../Pressure.h ../NumKeyword.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h -transport.o: ../transport.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +transport.o: ../transport.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ @@ -790,21 +838,31 @@ transport.o: ../transport.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h Use.o: ../Use.cpp ../Use.h -utilities.o: ../utilities.cpp ../Utils.h ../Phreeqc.h ../phrqtype.h \ +UserPunch.o: ../UserPunch.cpp ../UserPunch.h ../NumKeyword.h \ + ../PHRQ_base.h ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h +utilities.o: ../utilities.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../Keywords.h ../Pressure.h ../NumKeyword.h \ + ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +Keywords.o: ../PhreeqcKeywords/Keywords.cpp ../PhreeqcKeywords/Keywords.h + # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug Class_release_64 Class_debug_64 dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. ../*.cxx ../*.cpp + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp tester: cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From c3defbf429bec6aff6100b1b2ac5863157bb9e88 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Feb 2015 20:09:29 +0000 Subject: [PATCH 0879/1077] Fixing VS static checker warnings. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9302 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cvode.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cvode.cpp b/cvode.cpp index 9cffd81f..c03a679c 100644 --- a/cvode.cpp +++ b/cvode.cpp @@ -2302,10 +2302,10 @@ CVIncreaseBDF(CVodeMem cv_mem) if (L >= 0 && L <= qmax) { N_VScale(A1, zn[qmax], zn[L]); - } - for (j = 2; j <= q; j++) - { - N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); + for (j = 2; j <= q; j++) + { + N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]); + } } } From a67f52b86395adf7fbcd4c69cc8cb20f5bd47a89 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Feb 2015 23:39:34 +0000 Subject: [PATCH 0880/1077] Bug with quick_setup, pp_assemblage did not compare without case. Failed in transport when one cell had Ferrihydrite and the other had ferrihydrite. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9308 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- phreeqc.rev | 4579 --------------------------------------------------- prep.cpp | 8 +- 2 files changed, 5 insertions(+), 4582 deletions(-) delete mode 100644 phreeqc.rev diff --git a/phreeqc.rev b/phreeqc.rev deleted file mode 100644 index 8dc8253f..00000000 --- a/phreeqc.rev +++ /dev/null @@ -1,4579 +0,0 @@ - -RCS file: RCS/README.TXT,v -Working file: README.TXT -head: 1.17 -branch: -locks: strict -access list: -symbolic names: -keyword substitution: kv -total revisions: 17 -============================================================================= - -RCS file: RCS/NOTICE.TXT,v -Working file: NOTICE.TXT -head: 1.1 -branch: -locks: strict -access list: -symbolic names: -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: RCS/RELEASE.TXT,v -Working file: RELEASE.TXT -head: 1.16 -branch: -locks: strict - dlpark: 1.16 -access list: -symbolic names: -keyword substitution: kv -total revisions: 16 -============================================================================= - -RCS file: src/RCS/Makefile,v -Working file: src/Makefile -head: 1.35 -branch: -locks: strict -access list: -symbolic names: - C_260: 1.33 - C_259: 1.33 - C_258: 1.33 - C_257: 1.31 - C_256: 1.31 - C_255: 1.31 - C_254: 1.30 - C_253: 1.26 - C_252: 1.25 - C_251: 1.25 - C_250: 1.25 - C_249: 1.24 - C_248: 1.24 - C_247: 1.24 - C_246: 1.24 - C_245: 1.24 - C_244: 1.24 - C_243: 1.24 - C_242: 1.23 - C_241: 1.22 - C_240: 1.22 - C_239: 1.22 - C_238: 1.22 - C_237: 1.22 - C_236: 1.22 - C_235: 1.22 - C_234: 1.22 - C_233: 1.22 - C_232: 1.22 - C_231: 1.22 - C_230: 1.22 - C_229: 1.22 - C_227: 1.22 - C_226: 1.22 - C_225: 1.22 - C_224: 1.22 - C_222: 1.21 - C_221: 1.21 - C_220: 1.21 - C_219: 1.21 - C_218: 1.21 - RC1: 1.20 - C_216: 1.20 - C_215: 1.20 - C_214: 1.20 - C_213: 1.20 - C_212: 1.20 - C_206: 1.18 - C_205_3: 1.15 - C_205_2: 1.15 - C_205_1: 1.15 - C_205: 1.15 - C_204_2: 1.14 - C_204_1: 1.14 - C_204: 1.14 - C_202: 1.10 - C_201: 1.5 - C_200: 1.5 -keyword substitution: kv -total revisions: 35 -============================================================================= - -RCS file: src/RCS/advection.c,v -Working file: src/advection.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.5 - C_246: 2.5 - C_245: 2.5 - C_244: 2.5 - C_243: 2.5 - C_242: 2.4 - C_241: 2.4 - C_240: 2.4 - C_239: 2.4 - C_238: 2.3 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/basic.c,v -Working file: src/basic.c -head: 2.44 -branch: -locks: strict - dlpark: 2.44 -access list: -symbolic names: - C_260: 2.44 - C_259: 2.44 - C_258: 2.44 - C_257: 2.44 - C_256: 2.43 - C_255: 2.43 - C_254: 2.43 - C_253: 2.42 - C_252: 2.42 - C_251: 2.42 - C_250: 2.42 - C_249: 2.41 - C_248: 2.41 - C_247: 2.41 - C_246: 2.41 - C_245: 2.41 - C_244: 2.41 - C_243: 2.41 - C_242: 2.39 - C_241: 2.39 - C_240: 2.39 - C_239: 2.39 - C_238: 2.38 - C_237: 2.37 - C_236: 2.37 - C_235: 2.37 - C_234: 2.37 - C_233: 2.36 - C_232: 2.34 - C_231: 2.33 - C_230: 2.30 - C_229: 2.30 - C_227: 2.30 - C_226: 2.30 - C_225: 2.30 - C_224: 2.30 - C_222: 2.30 - C_221: 2.20 - C_220: 2.20 - C_219: 2.19 - C_218: 2.19 - RC1: 2.19 - C_216: 2.19 - C_215: 2.18 - C_214: 2.17 - C_213: 2.17 - C_212: 2.16 - C_206: 2.16 - C_205_3: 2.14 - C_205_2: 2.14 - C_205_1: 2.13 - C_205: 2.11 - C_204_2: 2.11 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.10 - C_202_1: 2.10 - C_202: 2.6 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 45 -============================================================================= - -RCS file: src/RCS/basicsubs.c,v -Working file: src/basicsubs.c -head: 2.18 -branch: -locks: strict - dlpark: 2.18 -access list: -symbolic names: - C_260: 2.18 - C_259: 2.18 - C_258: 2.18 - C_257: 2.18 - C_256: 2.17 - C_255: 2.17 - C_254: 2.17 - C_253: 2.16 - C_252: 2.16 - C_251: 2.15 - C_250: 2.15 - C_249: 2.14 - C_248: 2.14 - C_247: 2.14 - C_246: 2.14 - C_245: 2.14 - C_244: 2.14 - C_243: 2.14 - C_242: 2.13 - C_241: 2.13 - C_240: 2.13 - C_239: 2.13 - C_238: 2.12 - C_237: 2.12 - C_236: 2.12 - C_235: 2.12 - C_234: 2.12 - C_233: 2.11 - C_232: 2.9 - C_231: 2.9 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.6 - C_222: 2.6 - C_221: 2.6 - C_220: 2.6 - C_219: 2.6 - C_218: 2.6 - RC1: 2.6 - C_216: 2.6 - C_215: 2.6 - C_214: 2.5 - C_213: 2.4 - C_212: 2.3 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.1 - C_205_1: 2.1 -keyword substitution: kv -total revisions: 18 -============================================================================= - -RCS file: src/RCS/cl1.c,v -Working file: src/cl1.c -head: 2.7 -branch: -locks: strict - dlpark: 2.7 -access list: -symbolic names: - C_260: 2.7 - C_259: 2.7 - C_258: 2.7 - C_257: 2.6 - C_256: 2.5 - C_255: 2.5 - C_254: 2.5 - C_253: 2.5 - C_252: 2.5 - C_251: 2.5 - C_250: 2.5 - C_249: 2.4 - C_248: 2.4 - C_247: 2.4 - C_246: 2.4 - C_245: 2.4 - C_244: 2.4 - C_243: 2.4 - C_242: 2.3 - C_241: 2.3 - C_240: 2.3 - C_239: 2.2 - C_238: 2.1 - C_237: 2.1 - C_236: 2.1 - C_235: 2.1 - C_234: 2.1 - C_233: 2.1 - C_232: 2.1 - C_231: 2.1 - C_230: 2.1 - C_229: 2.1 - C_227: 2.1 - C_226: 2.1 - C_225: 2.1 - C_224: 2.1 - C_222: 2.1 - C_221: 2.1 - C_220: 2.1 - C_219: 2.1 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: src/RCS/cvdense.c,v -Working file: src/cvdense.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 - C_225: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/cvode.c,v -Working file: src/cvode.c -head: 1.10 -branch: -locks: strict -access list: -symbolic names: - C_260: 1.10 - C_259: 1.9 - C_258: 1.9 - C_257: 1.9 - C_256: 1.8 - C_255: 1.8 - C_254: 1.8 - C_253: 1.8 - C_252: 1.8 - C_251: 1.8 - C_250: 1.7 - C_249: 1.6 - C_248: 1.6 - C_247: 1.6 - C_246: 1.6 - C_245: 1.6 - C_244: 1.6 - C_243: 1.6 - C_242: 1.4 - C_241: 1.4 - C_240: 1.4 - C_239: 1.4 - C_238: 1.2 - C_237: 1.2 - C_236: 1.2 - C_235: 1.2 - C_234: 1.2 - C_233: 1.2 - C_232: 1.2 - C_231: 1.2 - C_230: 1.2 - C_229: 1.2 - C_227: 1.2 - C_226: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: src/RCS/dense.c,v -Working file: src/dense.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/input.c,v -Working file: src/input.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.1 - C_254: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/integrate.c,v -Working file: src/integrate.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.4 - C_237: 2.4 - C_236: 2.4 - C_235: 2.4 - C_234: 2.4 - C_233: 2.4 - C_232: 2.4 - C_231: 2.4 - C_230: 2.4 - C_229: 2.4 - C_227: 2.4 - C_226: 2.4 - C_225: 2.4 - C_224: 2.3 - C_222: 2.3 - C_221: 2.3 - C_220: 2.3 - C_219: 2.3 - C_218: 2.3 - RC1: 2.3 - C_216: 2.3 - C_215: 2.3 - C_214: 2.3 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/inverse.c,v -Working file: src/inverse.c -head: 2.10 -branch: -locks: strict - dlpark: 2.10 -access list: -symbolic names: - C_260: 2.10 - C_259: 2.10 - C_258: 2.10 - C_257: 2.10 - C_256: 2.9 - C_255: 2.9 - C_254: 2.9 - C_253: 2.8 - C_252: 2.8 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.4 - C_241: 2.4 - C_240: 2.4 - C_239: 2.4 - C_238: 2.3 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.1 - C_206: 2.1 - C_205_3: 2.1 - C_205_2: 2.1 - C_205_1: 2.1 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: src/RCS/isotopes.c,v -Working file: src/isotopes.c -head: 2.12 -branch: -locks: strict - dlpark: 2.12 -access list: -symbolic names: - C_260: 2.12 - C_259: 2.12 - C_258: 2.12 - C_257: 2.12 - C_256: 2.11 - C_255: 2.11 - C_254: 2.11 - C_253: 2.11 - C_252: 2.11 - C_251: 2.11 - C_250: 2.10 - C_249: 2.9 - C_248: 2.9 - C_247: 2.9 - C_246: 2.9 - C_245: 2.9 - C_244: 2.9 - C_243: 2.9 - C_242: 2.8 - C_241: 2.8 - C_240: 2.8 - C_239: 2.8 - C_238: 2.7 - C_237: 2.7 - C_236: 2.7 - C_235: 2.7 - C_234: 2.7 - C_233: 2.7 - C_232: 2.7 - C_231: 2.7 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.7 - C_222: 2.7 - C_221: 2.7 - C_220: 2.7 - C_219: 2.7 - C_218: 2.7 - RC1: 2.7 - C_216: 2.7 - C_215: 2.7 - C_214: 2.7 - C_213: 2.7 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.2 - C_205_2: 2.1 - C_205_1: 2.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: src/RCS/kinetics.c,v -Working file: src/kinetics.c -head: 2.36 -branch: -locks: strict - dlpark: 2.36 -access list: -symbolic names: - C_260: 2.36 - C_259: 2.36 - C_258: 2.36 - C_257: 2.33 - C_256: 2.32 - C_255: 2.31 - C_254: 2.31 - C_253: 2.30 - C_252: 2.30 - C_251: 2.29 - C_250: 2.29 - C_249: 2.28 - C_248: 2.28 - C_247: 2.26 - C_246: 2.26 - C_245: 2.26 - C_244: 2.26 - C_243: 2.26 - C_242: 2.24 - C_241: 2.24 - C_240: 2.24 - C_239: 2.23 - C_238: 2.22 - C_237: 2.22 - C_236: 2.22 - C_235: 2.22 - C_234: 2.21 - C_233: 2.21 - C_232: 2.21 - C_231: 2.21 - C_230: 2.21 - C_229: 2.21 - C_227: 2.21 - C_226: 2.20 - C_225: 2.19 - C_224: 2.19 - C_222: 2.19 - C_221: 2.19 - C_220: 2.19 - C_219: 2.18 - C_218: 2.17 - RC1: 2.17 - C_216: 2.17 - C_215: 2.17 - C_214: 2.17 - C_213: 2.17 - C_212: 2.16 - C_206: 2.16 - C_205_3: 2.16 - C_205_2: 2.16 - C_205_1: 2.15 - C_205: 2.11 - C_204_2: 2.7 - C_204_1: 2.7 - C_204: 2.7 - C_202_2: 2.6 - C_202_1: 2.6 - C_202: 2.4 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 37 -============================================================================= - -RCS file: src/RCS/main.c,v -Working file: src/main.c -head: 2.35 -branch: -locks: strict -access list: -symbolic names: - C_260: 2.35 - C_259: 2.34 - C_258: 2.34 - C_257: 2.34 - C_256: 2.33 - C_255: 2.33 - C_254: 2.32 - C_253: 2.31 - C_252: 2.30 - C_251: 2.30 - C_250: 2.30 - C_249: 2.29 - C_248: 2.29 - C_247: 2.29 - C_246: 2.29 - C_245: 2.29 - C_244: 2.28 - C_243: 2.28 - C_242: 2.26 - C_241: 2.25 - C_240: 2.25 - C_239: 2.25 - C_238: 2.25 - C_237: 2.24 - C_236: 2.24 - C_235: 2.24 - C_234: 2.23 - C_233: 2.23 - C_232: 2.23 - C_231: 2.23 - C_230: 2.23 - C_229: 2.23 - C_227: 2.23 - C_226: 2.23 - C_225: 2.23 - C_224: 2.23 - C_222: 2.22 - C_221: 2.22 - C_220: 2.22 - C_219: 2.22 - C_218: 2.20 - RC1: 2.19 - C_216: 2.19 - C_215: 2.18 - C_214: 2.18 - C_213: 2.18 - C_212: 2.14 - C_206: 2.14 - C_205_3: 2.13 - C_205_2: 2.13 - C_205_1: 2.13 - C_205: 2.13 - C_204_2: 2.12 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.9 - C_202_1: 2.6 - C_202: 2.4 - C_201: 2.2 - C_200: 2.1 -keyword substitution: kv -total revisions: 36 -============================================================================= - -RCS file: src/RCS/mainsubs.c,v -Working file: src/mainsubs.c -head: 2.38 -branch: -locks: strict - dlpark: 2.38 -access list: -symbolic names: - C_260: 2.38 - C_259: 2.38 - C_258: 2.38 - C_257: 2.36 - C_256: 2.35 - C_255: 2.35 - C_254: 2.34 - C_253: 2.33 - C_252: 2.33 - C_251: 2.32 - C_250: 2.32 - C_249: 2.31 - C_248: 2.31 - C_247: 2.30 - C_246: 2.30 - C_245: 2.30 - C_244: 2.30 - C_243: 2.30 - C_242: 2.28 - C_241: 2.28 - C_240: 2.28 - C_239: 2.27 - C_238: 2.25 - C_237: 2.24 - C_236: 2.24 - C_235: 2.24 - C_234: 2.23 - C_233: 2.23 - C_232: 2.23 - C_231: 2.23 - C_230: 2.23 - C_229: 2.23 - C_227: 2.22 - C_226: 2.22 - C_225: 2.22 - C_224: 2.22 - C_222: 2.22 - C_221: 2.22 - C_220: 2.22 - C_219: 2.22 - C_218: 2.21 - RC1: 2.21 - C_216: 2.21 - C_215: 2.21 - C_214: 2.20 - C_213: 2.20 - C_212: 2.17 - C_206: 2.15 - C_205_3: 2.14 - C_205_2: 2.13 - C_205_1: 2.12 - C_205: 2.11 - C_204_2: 2.10 - C_204_1: 2.10 - C_204: 2.10 - C_202_2: 2.6 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 39 -============================================================================= - -RCS file: src/RCS/model.c,v -Working file: src/model.c -head: 2.27 -branch: -locks: strict - dlpark: 2.27 -access list: -symbolic names: - C_260: 2.27 - C_259: 2.27 - C_258: 2.27 - C_257: 2.26 - C_256: 2.25 - C_255: 2.25 - C_254: 2.25 - C_253: 2.24 - C_252: 2.24 - C_251: 2.24 - C_250: 2.24 - C_249: 2.23 - C_248: 2.23 - C_247: 2.22 - C_246: 2.22 - C_245: 2.22 - C_244: 2.22 - C_243: 2.22 - C_242: 2.20 - C_241: 2.19 - C_240: 2.19 - C_239: 2.19 - C_238: 2.17 - C_237: 2.17 - C_236: 2.17 - C_235: 2.17 - C_234: 2.17 - C_233: 2.16 - C_232: 2.15 - C_231: 2.15 - C_230: 2.14 - C_229: 2.14 - C_227: 2.14 - C_226: 2.14 - C_225: 2.14 - C_224: 2.14 - C_222: 2.14 - C_221: 2.14 - C_220: 2.14 - C_219: 2.14 - C_218: 2.14 - RC1: 2.13 - C_216: 2.13 - C_215: 2.13 - C_214: 2.12 - C_213: 2.12 - C_212: 2.11 - C_206: 2.11 - C_205_3: 2.11 - C_205_2: 2.11 - C_205_1: 2.10 - C_205: 2.8 - C_204_2: 2.6 - C_204_1: 2.6 - C_204: 2.6 - C_202_2: 2.5 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 28 -============================================================================= - -RCS file: src/RCS/nvector.c,v -Working file: src/nvector.c -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_260: 1.3 - C_259: 1.3 - C_258: 1.3 - C_257: 1.3 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/nvector_serial.c,v -Working file: src/nvector_serial.c -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_260: 1.5 - C_259: 1.5 - C_258: 1.5 - C_257: 1.5 - C_256: 1.4 - C_255: 1.4 - C_254: 1.4 - C_253: 1.4 - C_252: 1.4 - C_251: 1.4 - C_250: 1.4 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: src/RCS/output.c,v -Working file: src/output.c -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_260: 1.2 - C_259: 1.2 - C_258: 1.2 - C_257: 1.1 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: src/RCS/p2clib.c,v -Working file: src/p2clib.c -head: 2.6 -branch: -locks: strict - dlpark: 2.6 -access list: -symbolic names: - C_260: 2.6 - C_259: 2.6 - C_258: 2.6 - C_257: 2.6 - C_256: 2.5 - C_255: 2.5 - C_254: 2.5 - C_253: 2.5 - C_252: 2.5 - C_251: 2.5 - C_250: 2.5 - C_249: 2.5 - C_248: 2.5 - C_247: 2.5 - C_246: 2.5 - C_245: 2.5 - C_244: 2.5 - C_243: 2.5 - C_242: 2.3 - C_241: 2.3 - C_240: 2.3 - C_239: 2.3 - C_238: 2.3 - C_237: 2.3 - C_236: 2.3 - C_235: 2.3 - C_234: 2.3 - C_233: 2.3 - C_232: 2.3 - C_231: 2.3 - C_230: 2.3 - C_229: 2.3 - C_227: 2.3 - C_226: 2.3 - C_225: 2.3 - C_224: 2.3 - C_222: 2.3 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.1 - C_206: 2.1 - C_205_3: 2.1 - C_205_2: 2.1 - C_205_1: 2.1 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: src/RCS/parse.c,v -Working file: src/parse.c -head: 2.8 -branch: -locks: strict - dlpark: 2.8 -access list: -symbolic names: - C_260: 2.8 - C_259: 2.8 - C_258: 2.8 - C_257: 2.8 - C_256: 2.7 - C_255: 2.7 - C_254: 2.7 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.6 - C_248: 2.6 - C_247: 2.6 - C_246: 2.6 - C_245: 2.6 - C_244: 2.6 - C_243: 2.6 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.4 - C_237: 2.4 - C_236: 2.4 - C_235: 2.4 - C_234: 2.4 - C_233: 2.4 - C_232: 2.4 - C_231: 2.4 - C_230: 2.4 - C_229: 2.4 - C_227: 2.4 - C_226: 2.4 - C_225: 2.4 - C_224: 2.4 - C_222: 2.4 - C_221: 2.4 - C_220: 2.4 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.4 - C_212: 2.3 - C_206: 2.3 - C_205_3: 2.3 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: src/RCS/phqalloc.c,v -Working file: src/phqalloc.c -head: 2.9 -branch: -locks: strict - dlpark: 2.9 -access list: -symbolic names: - C_260: 2.9 - C_259: 2.9 - C_258: 2.9 - C_257: 2.9 - C_256: 2.8 - C_255: 2.8 - C_254: 2.8 - C_253: 2.7 - C_252: 2.7 - C_251: 2.7 - C_250: 2.7 - C_249: 2.7 - C_248: 2.7 - C_247: 2.7 - C_246: 2.7 - C_245: 2.7 - C_244: 2.7 - C_243: 2.7 - C_242: 2.5 - C_241: 2.5 - C_240: 2.5 - C_239: 2.5 - C_238: 2.5 - C_237: 2.5 - C_236: 2.5 - C_235: 2.5 - C_234: 2.5 - C_233: 2.5 - C_232: 2.5 - C_231: 2.5 - C_230: 2.5 - C_229: 2.5 - C_227: 2.5 - C_226: 2.5 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.5 - C_218: 2.5 - RC1: 2.5 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.4 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.2 - C_204_1: 2.2 - C_204: 2.2 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: src/RCS/phreeqc_files.c,v -Working file: src/phreeqc_files.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.3 - C_257: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/prep.c,v -Working file: src/prep.c -head: 2.15 -branch: -locks: strict - dlpark: 2.15 -access list: -symbolic names: - C_260: 2.15 - C_259: 2.15 - C_258: 2.15 - C_257: 2.15 - C_256: 2.14 - C_255: 2.14 - C_254: 2.14 - C_253: 2.14 - C_252: 2.14 - C_251: 2.14 - C_250: 2.14 - C_249: 2.13 - C_248: 2.13 - C_247: 2.13 - C_246: 2.13 - C_245: 2.13 - C_244: 2.13 - C_243: 2.13 - C_242: 2.11 - C_241: 2.11 - C_240: 2.11 - C_239: 2.11 - C_238: 2.10 - C_237: 2.9 - C_236: 2.9 - C_235: 2.9 - C_234: 2.9 - C_233: 2.9 - C_232: 2.8 - C_231: 2.8 - C_230: 2.8 - C_229: 2.8 - C_227: 2.7 - C_226: 2.7 - C_225: 2.7 - C_224: 2.6 - C_222: 2.6 - C_221: 2.6 - C_220: 2.6 - C_219: 2.5 - C_218: 2.5 - RC1: 2.5 - C_216: 2.5 - C_215: 2.5 - C_214: 2.5 - C_213: 2.5 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.4 - C_205_2: 2.4 - C_205_1: 2.3 - C_205: 2.3 - C_204_2: 2.3 - C_204_1: 2.3 - C_204: 2.3 - C_202_2: 2.3 - C_202_1: 2.3 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 16 -============================================================================= - -RCS file: src/RCS/print.c,v -Working file: src/print.c -head: 2.38 -branch: -locks: strict - dlpark: 2.38 -access list: -symbolic names: - C_260: 2.38 - C_259: 2.38 - C_258: 2.38 - C_257: 2.38 - C_256: 2.37 - C_255: 2.36 - C_254: 2.35 - C_253: 2.34 - C_252: 2.34 - C_251: 2.32 - C_250: 2.32 - C_249: 2.31 - C_248: 2.31 - C_247: 2.31 - C_246: 2.31 - C_245: 2.31 - C_244: 2.31 - C_243: 2.31 - C_242: 2.30 - C_241: 2.30 - C_240: 2.30 - C_239: 2.30 - C_238: 2.29 - C_237: 2.29 - C_236: 2.29 - C_235: 2.28 - C_234: 2.27 - C_233: 2.27 - C_232: 2.27 - C_231: 2.27 - C_230: 2.27 - C_229: 2.27 - C_227: 2.27 - C_226: 2.27 - C_225: 2.26 - C_224: 2.26 - C_222: 2.26 - C_221: 2.25 - C_220: 2.25 - C_219: 2.24 - C_218: 2.24 - RC1: 2.24 - C_216: 2.24 - C_215: 2.24 - C_214: 2.21 - C_213: 2.20 - C_212: 2.15 - C_206: 2.15 - C_205_3: 2.11 - C_205_2: 2.10 - C_205_1: 2.9 - C_205: 2.8 - C_204_2: 2.7 - C_204_1: 2.7 - C_204: 2.7 - C_202_2: 2.5 - C_202_1: 2.4 - C_202: 2.4 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 39 -============================================================================= - -RCS file: src/RCS/read.c,v -Working file: src/read.c -head: 2.43 -branch: -locks: strict - dlpark: 2.43 -access list: -symbolic names: - C_260: 2.43 - C_259: 2.43 - C_258: 2.43 - C_257: 2.43 - C_256: 2.42 - C_255: 2.41 - C_254: 2.41 - C_253: 2.39 - C_252: 2.39 - C_251: 2.39 - C_250: 2.39 - C_249: 2.38 - C_248: 2.38 - C_247: 2.38 - C_246: 2.38 - C_245: 2.38 - C_244: 2.38 - C_243: 2.38 - C_242: 2.36 - C_241: 2.36 - C_240: 2.36 - C_239: 2.36 - C_238: 2.35 - C_237: 2.33 - C_236: 2.33 - C_235: 2.32 - C_234: 2.31 - C_233: 2.31 - C_232: 2.31 - C_231: 2.31 - C_230: 2.31 - C_229: 2.31 - C_227: 2.30 - C_226: 2.29 - C_225: 2.29 - C_224: 2.29 - C_222: 2.29 - C_221: 2.29 - C_220: 2.29 - C_219: 2.29 - C_218: 2.29 - RC1: 2.29 - C_216: 2.29 - C_215: 2.28 - C_214: 2.27 - C_213: 2.27 - C_212: 2.23 - C_206: 2.21 - C_205_3: 2.20 - C_205_2: 2.19 - C_205_1: 2.18 - C_205: 2.17 - C_204_2: 2.12 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.8 - C_202_1: 2.6 - C_202: 2.2 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 44 -============================================================================= - -RCS file: src/RCS/readtr.c,v -Working file: src/readtr.c -head: 2.13 -branch: -locks: strict - dlpark: 2.13 -access list: -symbolic names: - C_260: 2.13 - C_259: 2.13 - C_258: 2.12 - C_257: 2.12 - C_256: 2.11 - C_255: 2.10 - C_254: 2.10 - C_253: 2.9 - C_252: 2.9 - C_251: 2.9 - C_250: 2.9 - C_249: 2.8 - C_248: 2.8 - C_247: 2.8 - C_246: 2.8 - C_245: 2.8 - C_244: 2.8 - C_243: 2.8 - C_242: 2.6 - C_241: 2.6 - C_240: 2.6 - C_239: 2.6 - C_238: 2.5 - C_237: 2.5 - C_236: 2.5 - C_235: 2.5 - C_234: 2.5 - C_233: 2.5 - C_232: 2.5 - C_231: 2.5 - C_230: 2.5 - C_229: 2.5 - C_227: 2.5 - C_226: 2.5 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.3 - C_214: 2.3 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.1 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.1 - C_202_1: 2.1 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/smalldense.c,v -Working file: src/smalldense.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/spread.c,v -Working file: src/spread.c -head: 2.17 -branch: -locks: strict - dlpark: 2.17 -access list: -symbolic names: - C_260: 2.17 - C_259: 2.17 - C_258: 2.16 - C_257: 2.16 - C_256: 2.15 - C_255: 2.15 - C_254: 2.15 - C_253: 2.15 - C_252: 2.15 - C_251: 2.15 - C_250: 2.15 - C_249: 2.14 - C_248: 2.14 - C_247: 2.14 - C_246: 2.14 - C_245: 2.14 - C_244: 2.14 - C_243: 2.14 - C_242: 2.13 - C_241: 2.13 - C_240: 2.13 - C_239: 2.13 - C_238: 2.12 - C_237: 2.12 - C_236: 2.12 - C_235: 2.12 - C_234: 2.12 - C_233: 2.12 - C_232: 2.12 - C_231: 2.12 - C_230: 2.11 - C_229: 2.11 - C_227: 2.11 - C_226: 2.11 - C_225: 2.11 - C_224: 2.11 - C_222: 2.11 - C_221: 2.11 - C_220: 2.11 - C_219: 2.11 - C_218: 2.11 - RC1: 2.11 - C_216: 2.11 - C_215: 2.11 - C_214: 2.11 - C_213: 2.11 - C_212: 2.10 - C_206: 2.10 - C_205_3: 2.10 - C_205_2: 2.10 - C_205_1: 2.9 - C_205: 2.8 - C_204_2: 2.8 - C_204_1: 2.7 - C_204: 2.6 - C_202_2: 2.3 - C_202_1: 2.2 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 18 -============================================================================= - -RCS file: src/RCS/step.c,v -Working file: src/step.c -head: 2.13 -branch: -locks: strict - dlpark: 2.13 -access list: -symbolic names: - C_260: 2.13 - C_259: 2.13 - C_258: 2.13 - C_257: 2.13 - C_256: 2.12 - C_255: 2.12 - C_254: 2.12 - C_253: 2.12 - C_252: 2.12 - C_251: 2.12 - C_250: 2.12 - C_249: 2.11 - C_248: 2.11 - C_247: 2.11 - C_246: 2.11 - C_245: 2.11 - C_244: 2.11 - C_243: 2.11 - C_242: 2.10 - C_241: 2.10 - C_240: 2.10 - C_239: 2.10 - C_238: 2.9 - C_237: 2.7 - C_236: 2.7 - C_235: 2.7 - C_234: 2.7 - C_233: 2.7 - C_232: 2.7 - C_231: 2.7 - C_230: 2.7 - C_229: 2.7 - C_227: 2.7 - C_226: 2.6 - C_225: 2.5 - C_224: 2.5 - C_222: 2.5 - C_221: 2.5 - C_220: 2.5 - C_219: 2.4 - C_218: 2.4 - RC1: 2.4 - C_216: 2.4 - C_215: 2.4 - C_214: 2.4 - C_213: 2.3 - C_212: 2.2 - C_206: 2.2 - C_205_3: 2.2 - C_205_2: 2.2 - C_205_1: 2.2 - C_205: 2.2 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/structures.c,v -Working file: src/structures.c -head: 2.35 -branch: -locks: strict - dlpark: 2.35 -access list: -symbolic names: - C_260: 2.35 - C_259: 2.35 - C_258: 2.34 - C_257: 2.33 - C_256: 2.32 - C_255: 2.32 - C_254: 2.31 - C_253: 2.29 - C_252: 2.29 - C_251: 2.29 - C_250: 2.29 - C_249: 2.28 - C_248: 2.28 - C_247: 2.28 - C_246: 2.28 - C_245: 2.28 - C_244: 2.28 - C_243: 2.28 - C_242: 2.26 - C_241: 2.25 - C_240: 2.25 - C_239: 2.24 - C_238: 2.23 - C_237: 2.22 - C_236: 2.22 - C_235: 2.22 - C_234: 2.21 - C_233: 2.21 - C_232: 2.20 - C_231: 2.20 - C_230: 2.20 - C_229: 2.20 - C_227: 2.19 - C_226: 2.19 - C_225: 2.19 - C_224: 2.19 - C_222: 2.19 - C_221: 2.19 - C_220: 2.19 - C_219: 2.19 - C_218: 2.18 - RC1: 2.18 - C_216: 2.18 - C_215: 2.18 - C_214: 2.17 - C_213: 2.17 - C_212: 2.15 - C_206: 2.14 - C_205_3: 2.13 - C_205_2: 2.13 - C_205_1: 2.12 - C_205: 2.11 - C_204_2: 2.10 - C_204_1: 2.10 - C_204: 2.10 - C_202_2: 2.6 - C_202_1: 2.4 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 36 -============================================================================= - -RCS file: src/RCS/sundialsmath.c,v -Working file: src/sundialsmath.c -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.3 - C_255: 1.3 - C_254: 1.3 - C_253: 1.3 - C_252: 1.3 - C_251: 1.3 - C_250: 1.3 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/tally.c,v -Working file: src/tally.c -head: 1.14 -branch: -locks: strict - dlpark: 1.14 -access list: -symbolic names: - C_260: 1.14 - C_259: 1.14 - C_258: 1.14 - C_257: 1.14 - C_256: 1.13 - C_255: 1.13 - C_254: 1.13 - C_253: 1.13 - C_252: 1.13 - C_251: 1.12 - C_250: 1.12 - C_249: 1.11 - C_248: 1.11 - C_247: 1.11 - C_246: 1.10 - C_245: 1.10 - C_244: 1.9 - C_243: 1.8 - C_242: 1.6 - C_241: 1.5 - C_240: 1.4 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: src/RCS/tidy.c,v -Working file: src/tidy.c -head: 2.30 -branch: -locks: strict -access list: -symbolic names: - C_260: 2.30 - C_259: 2.29 - C_258: 2.29 - C_257: 2.29 - C_256: 2.28 - C_255: 2.28 - C_254: 2.28 - C_253: 2.27 - C_252: 2.27 - C_251: 2.27 - C_250: 2.27 - C_249: 2.26 - C_248: 2.26 - C_247: 2.26 - C_246: 2.26 - C_245: 2.26 - C_244: 2.26 - C_243: 2.26 - C_242: 2.24 - C_241: 2.23 - C_240: 2.23 - C_239: 2.22 - C_238: 2.21 - C_237: 2.19 - C_236: 2.19 - C_235: 2.19 - C_234: 2.19 - C_233: 2.19 - C_232: 2.17 - C_231: 2.17 - C_230: 2.17 - C_229: 2.16 - C_227: 2.16 - C_226: 2.16 - C_225: 2.16 - C_224: 2.16 - C_222: 2.16 - C_221: 2.16 - C_220: 2.15 - C_219: 2.15 - C_218: 2.15 - RC1: 2.15 - C_216: 2.15 - C_215: 2.15 - C_214: 2.15 - C_213: 2.15 - C_212: 2.10 - C_206: 2.9 - C_205_3: 2.9 - C_205_2: 2.8 - C_205_1: 2.7 - C_205: 2.6 - C_204_2: 2.5 - C_204_1: 2.4 - C_204: 2.3 - C_202_2: 2.2 - C_202_1: 2.2 - C_202: 2.1 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 31 -============================================================================= - -RCS file: src/RCS/transport.c,v -Working file: src/transport.c -head: 2.14 -branch: -locks: strict - dlpark: 2.14 -access list: -symbolic names: - C_260: 2.14 - C_259: 2.14 - C_258: 2.14 - C_257: 2.14 - C_256: 2.13 - C_255: 2.13 - C_254: 2.13 - C_253: 2.13 - C_252: 2.13 - C_251: 2.13 - C_250: 2.13 - C_249: 2.12 - C_248: 2.12 - C_247: 2.12 - C_246: 2.12 - C_245: 2.12 - C_244: 2.12 - C_243: 2.12 - C_242: 2.10 - C_241: 2.10 - C_240: 2.10 - C_239: 2.10 - C_238: 2.9 - C_237: 2.8 - C_236: 2.8 - C_235: 2.8 - C_234: 2.8 - C_233: 2.8 - C_232: 2.8 - C_231: 2.8 - C_230: 2.8 - C_229: 2.8 - C_227: 2.8 - C_226: 2.8 - C_225: 2.8 - C_224: 2.8 - C_222: 2.8 - C_221: 2.8 - C_220: 2.7 - C_219: 2.7 - C_218: 2.7 - RC1: 2.6 - C_216: 2.5 - C_215: 2.5 - C_214: 2.5 - C_213: 2.5 - C_212: 2.4 - C_206: 2.4 - C_205_3: 2.4 - C_205_2: 2.4 - C_205_1: 2.4 - C_205: 2.3 - C_204_2: 2.1 - C_204_1: 2.1 - C_204: 2.1 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 15 -============================================================================= - -RCS file: src/RCS/utilities.c,v -Working file: src/utilities.c -head: 2.30 -branch: -locks: strict - dlpark: 2.30 -access list: -symbolic names: - C_260: 2.30 - C_259: 2.30 - C_258: 2.30 - C_257: 2.30 - C_256: 2.29 - C_255: 2.29 - C_254: 2.29 - C_253: 2.28 - C_252: 2.28 - C_251: 2.28 - C_250: 2.28 - C_249: 2.27 - C_248: 2.27 - C_247: 2.27 - C_246: 2.27 - C_245: 2.27 - C_244: 2.27 - C_243: 2.27 - C_242: 2.25 - C_241: 2.24 - C_240: 2.24 - C_239: 2.24 - C_238: 2.23 - C_237: 2.22 - C_236: 2.22 - C_235: 2.21 - C_234: 2.21 - C_233: 2.21 - C_232: 2.19 - C_231: 2.18 - C_230: 2.18 - C_229: 2.16 - C_227: 2.15 - C_226: 2.15 - C_225: 2.15 - C_224: 2.15 - C_222: 2.15 - C_221: 2.15 - C_220: 2.14 - C_219: 2.13 - C_218: 2.13 - RC1: 2.13 - C_216: 2.13 - C_215: 2.13 - C_214: 2.11 - C_213: 2.11 - C_212: 2.9 - C_206: 2.9 - C_205_3: 2.8 - C_205_2: 2.8 - C_205_1: 2.7 - C_205: 2.6 - C_204_2: 2.5 - C_204_1: 2.5 - C_204: 2.5 - C_202_2: 2.4 - C_202_1: 2.4 - C_202: 2.3 - C_201: 2.1 - C_200: 2.0 -keyword substitution: kv -total revisions: 31 -============================================================================= - -RCS file: src/RCS/cvdense.h,v -Working file: src/cvdense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/cvode.h,v -Working file: src/cvode.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/dense.h,v -Working file: src/dense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/global.h,v -Working file: src/global.h -head: 2.47 -branch: -locks: strict - dlpark: 2.47 -access list: -symbolic names: - C_260: 2.47 - C_259: 2.47 - C_258: 2.46 - C_257: 2.44 - C_256: 2.44 - C_255: 2.44 - C_254: 2.43 - C_253: 2.42 - C_252: 2.42 - C_251: 2.42 - C_250: 2.42 - C_249: 2.41 - C_248: 2.41 - C_247: 2.40 - C_246: 2.40 - C_245: 2.40 - C_244: 2.39 - C_243: 2.39 - C_242: 2.36 - C_241: 2.35 - C_240: 2.35 - C_239: 2.34 - C_238: 2.33 - C_237: 2.32 - C_236: 2.32 - C_235: 2.32 - C_234: 2.31 - C_233: 2.31 - C_232: 2.30 - C_231: 2.30 - C_230: 2.30 - C_229: 2.30 - C_227: 2.29 - C_226: 2.28 - C_225: 2.28 - C_224: 2.28 - C_222: 2.28 - C_221: 2.28 - C_220: 2.28 - C_219: 2.27 - C_218: 2.27 - RC1: 2.27 - C_216: 2.27 - C_215: 2.26 - C_214: 2.25 - C_213: 2.24 - C_212: 2.19 - C_206: 2.18 - C_205_3: 2.17 - C_205_2: 2.16 - C_205_1: 2.15 - C_205: 2.13 - C_204_2: 2.11 - C_204_1: 2.11 - C_204: 2.11 - C_202_2: 2.7 - C_202_1: 2.5 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 48 -============================================================================= - -RCS file: src/RCS/input.h,v -Working file: src/input.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/kinetics.h,v -Working file: src/kinetics.h -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_260: 1.2 - C_259: 1.2 - C_258: 1.2 - C_257: 1.2 - C_256: 1.2 - C_255: 1.2 - C_254: 1.2 - C_253: 1.2 - C_252: 1.2 - C_251: 1.2 - C_250: 1.2 - C_249: 1.2 - C_248: 1.2 - C_247: 1.2 - C_246: 1.2 - C_245: 1.2 - C_244: 1.2 - C_243: 1.2 - C_242: 1.2 - C_241: 1.2 - C_240: 1.2 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: src/RCS/nvector.h,v -Working file: src/nvector.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/nvector_serial.h,v -Working file: src/nvector_serial.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/output.h,v -Working file: src/output.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/p2c.h,v -Working file: src/p2c.h -head: 2.2 -branch: -locks: strict - dlpark: 2.2 -access list: -symbolic names: - C_260: 2.2 - C_259: 2.2 - C_258: 2.2 - C_257: 2.2 - C_256: 2.2 - C_255: 2.2 - C_254: 2.2 - C_253: 2.2 - C_252: 2.2 - C_251: 2.2 - C_250: 2.2 - C_249: 2.2 - C_248: 2.2 - C_247: 2.2 - C_246: 2.2 - C_245: 2.2 - C_244: 2.2 - C_243: 2.2 - C_242: 2.2 - C_241: 2.2 - C_240: 2.2 - C_239: 2.2 - C_238: 2.1 - C_237: 2.1 - C_236: 2.1 - C_235: 2.1 - C_234: 2.1 - C_233: 2.1 - C_232: 2.1 - C_231: 2.1 - C_230: 2.1 - C_229: 2.1 - C_227: 2.1 - C_226: 2.1 - C_225: 2.1 - C_224: 2.1 - C_222: 2.1 - C_221: 2.1 - C_220: 2.1 - C_219: 2.1 - C_218: 2.1 - RC1: 2.1 - C_216: 2.1 - C_215: 2.1 - C_214: 2.1 - C_213: 2.1 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: src/RCS/phqalloc.h,v -Working file: src/phqalloc.h -head: 2.3 -branch: -locks: strict - dlpark: 2.3 -access list: -symbolic names: - C_260: 2.3 - C_259: 2.3 - C_258: 2.3 - C_257: 2.2 - C_256: 2.2 - C_255: 2.2 - C_254: 2.2 - C_253: 2.2 - C_252: 2.2 - C_251: 2.2 - C_250: 2.2 - C_249: 2.2 - C_248: 2.2 - C_247: 2.2 - C_246: 2.2 - C_245: 2.2 - C_244: 2.2 - C_243: 2.2 - C_242: 2.2 - C_241: 2.2 - C_240: 2.2 - C_239: 2.2 - C_238: 2.2 - C_237: 2.2 - C_236: 2.2 - C_235: 2.2 - C_234: 2.2 - C_233: 2.2 - C_232: 2.2 - C_231: 2.2 - C_230: 2.2 - C_229: 2.2 - C_227: 2.2 - C_226: 2.2 - C_225: 2.2 - C_224: 2.2 - C_222: 2.2 - C_221: 2.2 - C_220: 2.2 - C_219: 2.2 - C_218: 2.2 - RC1: 2.2 - C_216: 2.2 - C_215: 2.2 - C_214: 2.2 - C_213: 2.2 - C_212: 2.0 - C_206: 2.0 - C_205_3: 2.0 - C_205_2: 2.0 - C_205_1: 2.0 - C_205: 2.0 - C_204_2: 2.0 - C_204_1: 2.0 - C_204: 2.0 - C_202_2: 2.0 - C_202_1: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: src/RCS/phrqproto.h,v -Working file: src/phrqproto.h -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_260: 1.6 - C_259: 1.6 - C_258: 1.6 - C_257: 1.6 - C_256: 1.5 - C_255: 1.5 - C_254: 1.4 - C_253: 1.2 - C_252: 1.2 - C_251: 1.1 - C_250: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: src/RCS/phrqtype.h,v -Working file: src/phrqtype.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/smalldense.h,v -Working file: src/smalldense.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/sundialsmath.h,v -Working file: src/sundialsmath.h -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_260: 1.1 - C_259: 1.1 - C_258: 1.1 - C_257: 1.1 - C_256: 1.1 - C_255: 1.1 - C_254: 1.1 - C_253: 1.1 - C_252: 1.1 - C_251: 1.1 - C_250: 1.1 - C_249: 1.1 - C_248: 1.1 - C_247: 1.1 - C_246: 1.1 - C_245: 1.1 - C_244: 1.1 - C_243: 1.1 - C_242: 1.1 - C_241: 1.1 - C_240: 1.1 - C_239: 1.1 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: src/RCS/sundialstypes.h,v -Working file: src/sundialstypes.h -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_260: 1.4 - C_259: 1.4 - C_258: 1.4 - C_257: 1.4 - C_256: 1.4 - C_255: 1.4 - C_254: 1.4 - C_253: 1.4 - C_252: 1.4 - C_251: 1.4 - C_250: 1.4 - C_249: 1.3 - C_248: 1.3 - C_247: 1.3 - C_246: 1.3 - C_245: 1.3 - C_244: 1.3 - C_243: 1.3 - C_242: 1.3 - C_241: 1.3 - C_240: 1.3 - C_239: 1.2 - C_238: 1.1 - C_237: 1.1 - C_236: 1.1 - C_235: 1.1 - C_234: 1.1 - C_233: 1.1 - C_232: 1.1 - C_231: 1.1 - C_230: 1.1 - C_229: 1.1 - C_227: 1.1 - C_226: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: database/RCS/llnl.dat,v -Working file: database/llnl.dat -head: 1.14 -branch: -locks: strict -access list: -symbolic names: - C_210: 1.14 - C_209: 1.14 - C_224: 1.12 - C_207: 1.12 - C_206: 1.11 - C_205: 1.11 - C_204: 1.10 -keyword substitution: kv -total revisions: 14 -============================================================================= - -RCS file: database/RCS/minteq.dat,v -Working file: database/minteq.dat -head: 2.1 -branch: -locks: strict -access list: -symbolic names: - C_210: 2.1 - C_209: 2.1 - C_224: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: database/RCS/phreeqc.dat,v -Working file: database/phreeqc.dat -head: 2.3 -branch: -locks: strict - dlpark: 2.3 -access list: -symbolic names: - C_210: 2.3 - C_209: 2.3 - C_224: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: database/RCS/wateq4f.dat,v -Working file: database/wateq4f.dat -head: 2.6 -branch: -locks: strict - dlpark: 2.6 -access list: -symbolic names: - C_210: 2.6 - C_209: 2.6 - C_224: 2.4 - C_207: 2.2 - C_206: 2.2 - C_205: 2.2 - C_204: 2.2 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: database/RCS/iso.dat,v -Working file: database/iso.dat -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_210: 1.4 - C_209: 1.4 - C_224: 1.4 - C_207: 1.4 - C_206: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex1,v -Working file: examples/ex1 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex1.out,v -Working file: examples/ex1.out -head: 1.7 -branch: -locks: strict - dlpark: 1.7 -access list: -symbolic names: - C_212: 1.7 - C_211: 1.5 - C_210: 1.5 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: examples/RCS/ex2,v -Working file: examples/ex2 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex2.out,v -Working file: examples/ex2.out -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex2.sel,v -Working file: examples/ex2.sel -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex3,v -Working file: examples/ex3 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex3.out,v -Working file: examples/ex3.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex4,v -Working file: examples/ex4 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex4.out,v -Working file: examples/ex4.out -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_212: 1.6 - C_211: 1.4 - C_210: 1.4 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: examples/RCS/ex5,v -Working file: examples/ex5 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex5.out,v -Working file: examples/ex5.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex5.sel,v -Working file: examples/ex5.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex6,v -Working file: examples/ex6 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex6.out,v -Working file: examples/ex6.out -head: 1.13 -branch: -locks: strict - dlpark: 1.13 -access list: -symbolic names: - C_212: 1.13 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.9 - C_206: 1.7 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 13 -============================================================================= - -RCS file: examples/RCS/ex6A-B.sel,v -Working file: examples/ex6A-B.sel -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex6C.sel,v -Working file: examples/ex6C.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex7,v -Working file: examples/ex7 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex7.out,v -Working file: examples/ex7.out -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.9 - C_210: 1.8 - C_224: 1.7 - C_208: 1.7 - C_207: 1.7 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex7.sel,v -Working file: examples/ex7.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex8,v -Working file: examples/ex8 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex8.out,v -Working file: examples/ex8.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex8.sel,v -Working file: examples/ex8.sel -head: 1.9 -branch: -locks: strict - dlpark: 1.9 -access list: -symbolic names: - C_212: 1.9 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.5 - C_205: 1.5 - C_204: 1.5 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 9 -============================================================================= - -RCS file: examples/RCS/ex9,v -Working file: examples/ex9 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex9.out,v -Working file: examples/ex9.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.5 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex9.sel,v -Working file: examples/ex9.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex10,v -Working file: examples/ex10 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex10.out,v -Working file: examples/ex10.out -head: 1.12 -branch: -locks: strict - dlpark: 1.12 -access list: -symbolic names: - C_212: 1.12 - C_211: 1.10 - C_210: 1.9 - C_224: 1.8 - C_208: 1.8 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 12 -============================================================================= - -RCS file: examples/RCS/ex10.sel,v -Working file: examples/ex10.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex11,v -Working file: examples/ex11 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.1 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex11.out,v -Working file: examples/ex11.out -head: 1.13 -branch: -locks: strict - dlpark: 1.13 -access list: -symbolic names: - C_212: 1.13 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 13 -============================================================================= - -RCS file: examples/RCS/ex11adv.sel,v -Working file: examples/ex11adv.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex11trn.sel,v -Working file: examples/ex11trn.sel -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_212: 1.4 - C_211: 1.4 - C_210: 1.4 - C_224: 1.4 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: examples/RCS/ex12,v -Working file: examples/ex12 -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex12.out,v -Working file: examples/ex12.out -head: 1.3 -branch: -locks: strict - dlpark: 1.3 -access list: -symbolic names: - C_212: 1.3 - C_211: 1.1 - C_210: 1.1 - C_224: 1.1 - C_208: 1.1 - C_207: 1.1 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: examples/RCS/ex12.sel,v -Working file: examples/ex12.sel -head: 1.11 -branch: -locks: strict - dlpark: 1.11 -access list: -symbolic names: - C_212: 1.11 - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.9 - C_207: 1.9 - C_206: 1.7 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: examples/RCS/ex13a,v -Working file: examples/ex13a -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13a.out,v -Working file: examples/ex13a.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13a.sel,v -Working file: examples/ex13a.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13b,v -Working file: examples/ex13b -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13b.out,v -Working file: examples/ex13b.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13b.sel,v -Working file: examples/ex13b.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13c,v -Working file: examples/ex13c -head: 2.1 -branch: -locks: strict - dlpark: 2.1 -access list: -symbolic names: - C_212: 2.1 - C_211: 2.1 - C_210: 2.1 - C_224: 2.1 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: examples/RCS/ex13c.out,v -Working file: examples/ex13c.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex13c.sel,v -Working file: examples/ex13c.sel -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.5 - C_210: 1.5 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex14,v -Working file: examples/ex14 -head: 2.2 -branch: -locks: strict - dlpark: 2.2 -access list: -symbolic names: - C_212: 2.2 - C_211: 2.2 - C_210: 2.2 - C_224: 2.2 - C_208: 2.1 - C_207: 2.1 - C_206: 2.1 - C_205: 2.1 - C_204: 2.1 - C_202: 2.1 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 3 -============================================================================= - -RCS file: examples/RCS/ex14.out,v -Working file: examples/ex14.out -head: 1.15 -branch: -locks: strict - dlpark: 1.15 -access list: -symbolic names: - C_212: 1.15 - C_211: 1.13 - C_210: 1.12 - C_224: 1.11 - C_208: 1.9 - C_207: 1.8 - C_206: 1.6 - C_205: 1.6 - C_204: 1.6 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 15 -============================================================================= - -RCS file: examples/RCS/ex14.sel,v -Working file: examples/ex14.sel -head: 1.8 -branch: -locks: strict - dlpark: 1.8 -access list: -symbolic names: - C_212: 1.8 - C_211: 1.7 - C_210: 1.7 - C_224: 1.6 - C_208: 1.4 - C_207: 1.4 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: examples/RCS/ex15,v -Working file: examples/ex15 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex15.dat,v -Working file: examples/ex15.dat -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex15.out,v -Working file: examples/ex15.out -head: 1.8 -branch: -locks: strict - dlpark: 1.8 -access list: -symbolic names: - C_212: 1.8 - C_211: 1.6 - C_210: 1.6 - C_224: 1.5 - C_208: 1.5 - C_207: 1.5 - C_206: 1.4 - C_205: 1.3 - C_204: 1.3 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 8 -============================================================================= - -RCS file: examples/RCS/ex15.sel,v -Working file: examples/ex15.sel -head: 1.7 -branch: -locks: strict - dlpark: 1.7 -access list: -symbolic names: - C_212: 1.7 - C_211: 1.7 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.5 - C_205: 1.4 - C_204: 1.4 - C_202: 1.3 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 7 -============================================================================= - -RCS file: examples/RCS/ex16,v -Working file: examples/ex16 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex16.out,v -Working file: examples/ex16.out -head: 1.5 -branch: -locks: strict - dlpark: 1.5 -access list: -symbolic names: - C_212: 1.5 - C_211: 1.3 - C_210: 1.3 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.1 - C_205: 1.1 - C_204: 1.1 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 5 -============================================================================= - -RCS file: examples/RCS/ex17,v -Working file: examples/ex17 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex17.out,v -Working file: examples/ex17.out -head: 1.10 -branch: -locks: strict - dlpark: 1.10 -access list: -symbolic names: - C_212: 1.10 - C_211: 1.8 - C_210: 1.7 - C_224: 1.6 - C_208: 1.6 - C_207: 1.6 - C_206: 1.4 - C_205: 1.4 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 10 -============================================================================= - -RCS file: examples/RCS/ex18,v -Working file: examples/ex18 -head: 2.0 -branch: -locks: strict - dlpark: 2.0 -access list: -symbolic names: - C_212: 2.0 - C_211: 2.0 - C_210: 2.0 - C_224: 2.0 - C_208: 2.0 - C_207: 2.0 - C_206: 2.0 - C_205: 2.0 - C_204: 2.0 - C_202: 2.0 - C_201: 2.0 - C_200: 2.0 - C_1: 2.0 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: examples/RCS/ex18.out,v -Working file: examples/ex18.out -head: 1.6 -branch: -locks: strict - dlpark: 1.6 -access list: -symbolic names: - C_212: 1.6 - C_211: 1.4 - C_210: 1.4 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 - C_201: 1.2 - C_200: 1.1 - C_1: 1.1 -keyword substitution: kv -total revisions: 6 -============================================================================= - -RCS file: doc/RCS/manual.pdf,v -Working file: doc/manual.pdf -head: 1.1 -branch: -locks: strict - dlpark: 1.1 -access list: -symbolic names: - C_211: 1.1 - C_210: 1.1 - C_224: 1.1 - C_208: 1.1 - C_207: 1.1 - C_206: 1.1 - C_205: 1.1 -keyword substitution: kv -total revisions: 1 -============================================================================= - -RCS file: doc/RCS/phreeqc.txt,v -Working file: doc/phreeqc.txt -head: 1.11 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.11 - C_210: 1.10 - C_224: 1.9 - C_208: 1.8 - C_207: 1.8 - C_206: 1.7 - C_205: 1.6 - C_204_2: 1.5 - C_204: 1.4 - C_202: 1.1 - C_201: 1.1 -keyword substitution: kv -total revisions: 11 -============================================================================= - -RCS file: bin/RCS/phreeqc.orig,v -Working file: bin/phreeqc.orig -head: 1.4 -branch: -locks: strict - dlpark: 1.4 -access list: -symbolic names: - C_209: 1.4 - C_208: 1.4 - C_224: 1.4 - C_206: 1.4 - C_205: 1.4 - C_202: 1.4 - C_201: 1.4 - C_200: 1.4 - C_1: 1.4 -keyword substitution: kv -total revisions: 4 -============================================================================= - -RCS file: test/RCS/test.sh,v -Working file: test/test.sh -head: 1.2 -branch: -locks: strict - dlpark: 1.2 -access list: -symbolic names: - C_211: 1.2 - C_210: 1.2 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: test/RCS/clean.sh,v -Working file: test/clean.sh -head: 1.2 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.2 - C_210: 1.2 - C_224: 1.2 - C_208: 1.2 - C_207: 1.2 - C_206: 1.2 - C_205: 1.2 - C_204: 1.2 - C_202: 1.2 -keyword substitution: kv -total revisions: 2 -============================================================================= - -RCS file: test/RCS/check.sh,v -Working file: test/check.sh -head: 1.3 -branch: -locks: strict -access list: -symbolic names: - C_211: 1.3 - C_210: 1.3 - C_224: 1.3 - C_208: 1.3 - C_207: 1.3 - C_206: 1.3 - C_205: 1.3 - C_204: 1.3 - C_202: 1.3 -keyword substitution: kv -total revisions: 3 -============================================================================= diff --git a/prep.cpp b/prep.cpp index ae96fcb0..74823339 100644 --- a/prep.cpp +++ b/prep.cpp @@ -195,9 +195,11 @@ quick_setup(void) { cxxPPassemblage * pp_assemblage_ptr = use.Get_pp_assemblage_ptr(); std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); - assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); - cxxPPassemblageComp * comp_ptr = &(it->second); + //it = pp_assemblage_ptr->Get_pp_assemblage_comps().find(x[i]->pp_assemblage_comp_name); + cxxPPassemblageComp * comp_ptr = pp_assemblage_ptr->Find(x[i]->pp_assemblage_comp_name); + assert(comp_ptr != NULL); + //assert(it != pp_assemblage_ptr->Get_pp_assemblage_comps().end()); + //cxxPPassemblageComp * comp_ptr = &(it->second); x[i]->pp_assemblage_comp_ptr = comp_ptr; x[i]->moles = comp_ptr->Get_moles(); /* A. Crapsi */ From cfa5f98e1fb3026809ff1c03d84ccee90403ce27 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 25 Feb 2015 00:36:03 +0000 Subject: [PATCH 0881/1077] Fixed bug in SURF(O/H,surf). H and O not counted correctly. Went back to old method before it was changed to account for redox master species (Fe(2)), for example. H(0) H(+1), O(-2) and O(0) probably do not work correctly, but I think everything else will. Added test case surf_total.out git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9309 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + basicsubs.cpp | 128 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 98984748..80989284 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -133,6 +133,7 @@ public: int match_elts_in_species(const char *name, const char *stemplate); int extract_bracket(char **string, char *bracket_string); LDBLE surf_total(const char *total_name, const char *surface_name); + LDBLE surf_total_no_redox(const char *total_name, const char *surface_name); static int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); diff --git a/basicsubs.cpp b/basicsubs.cpp index feff1dc2..dc416d0d 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2078,6 +2078,129 @@ surf_total(const char *total_name, const char *surface_name) */ int j; + if (use.Get_surface_ptr() == NULL || surface_name == NULL || total_name == NULL) + return (0); + + bool redox = false; + if (strstr(total_name, "(") != NULL) + { + redox = true; + } + if (!redox) + { + return surf_total_no_redox(total_name, surface_name); + } +/* + * Find surface... + */ + for (j = 0; j < count_unknowns; j++) + { + if (x[j]->type != SURFACE) + continue; + + std::string token; + token = x[j]->master[0]->elt->name; + replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + std::string name; + CParser::copy_token(name, b, e); + if (strcmp(name.c_str(), surface_name) == 0) + break; + } + if (j >= count_unknowns) + return (0); +/* + * find total moles for redox state + */ + LDBLE t = 0; + for (j = 0; j < count_s_x; j++) + { + if (s_x[j]->type != SURF) + continue; + + std::string token; + bool match = false; + + // find if surface matches + for (int i = 0; s_x[j]->next_elt[i].elt != NULL; i++) + { + if (s_x[j]->next_elt[i].elt->master->type != SURF) continue; + + //strcpy(token, s_x[j]->next_elt[i].elt->name); + //replace("_", " ", token); + //ptr = token; + //copy_token(name, &ptr, &k); + token = s_x[j]->next_elt[i].elt->name; + replace("_", " ", token); + std::string::iterator b = token.begin(); + std::string::iterator e = token.end(); + std::string name; + CParser::copy_token(name, b, e); + if (strcmp(name.c_str(), surface_name) == 0) + { + match = true; + break; + } + } + if (!match) continue; + + // surface matches, now match element or redox state + struct rxn_token *rxn_ptr; + for (rxn_ptr = s_x[j]->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++) + { + if (redox && rxn_ptr->s->secondary) + { + token = rxn_ptr->s->secondary->elt->name; + } + else if (!redox && rxn_ptr->s->secondary) + { + token = rxn_ptr->s->secondary->elt->primary->elt->name; + } + else if (!redox && rxn_ptr->s->primary) + { + token = rxn_ptr->s->primary->elt->name; + } + else + { + continue; + } + if (strcmp(token.c_str(), total_name) == 0) + { + t += rxn_ptr->coef * s_x[j]->moles; + break; + } + else + // sum all sites in case total_name is a surface name without underscore surf ("Hfo_w", "Hfo") + { + if (rxn_ptr->s->type == SURF) + { + if (token.find("_") != std::string::npos) + { + token = token.substr(0, token.find("_")); + } + if (strcmp(token.c_str(), total_name) == 0) + { + t += rxn_ptr->coef * s_x[j]->moles; + break; + } + } + } + } + } + return t; +} +#ifdef SKIP +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +surf_total(const char *total_name, const char *surface_name) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in LDBLE layer + */ + int j; + if (use.Get_surface_ptr() == NULL || surface_name == NULL) return (0); @@ -2186,10 +2309,10 @@ surf_total(const char *total_name, const char *surface_name) } return t; } -#ifdef SKIP +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: -surf_total(const char *total_name, const char *surface_name) +surf_total_no_redox(const char *total_name, const char *surface_name) /* ---------------------------------------------------------------------- */ { /* @@ -2273,7 +2396,6 @@ surf_total(const char *total_name, const char *surface_name) } return (0); } -#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: total(const char *total_name) From 8914d2c58ccd96b5f811f5971f634bbe7fc169bb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Mar 2015 18:53:02 +0000 Subject: [PATCH 0882/1077] needed to check sum_fractions for zero git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9324 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index b8062c42..0fbac2a8 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -154,16 +154,24 @@ cxxGasPhase::cxxGasPhase(std::map < int, cxxGasPhase > &entity_map, this->solution_equilibria = entity_ptr->solution_equilibria; this->n_solution = entity_ptr->n_solution; this->type = entity_ptr->type; - this->total_p += entity_ptr->total_p * it->second / sum_fractions; this->total_moles = entity_ptr->total_moles * it->second; this->volume = entity_ptr->volume * it->second; - this->v_m = entity_ptr->v_m * it->second / sum_fractions; + if (sum_fractions > 0.0) + { + this->v_m = entity_ptr->v_m * it->second / sum_fractions; + this->total_p += entity_ptr->total_p * it->second / sum_fractions; + } + else + { + this->v_m = 0.0; + this->total_p = 0.0; + } this->pr_in = entity_ptr->pr_in; this->temperature = entity_ptr->temperature; first = false; - } - else - { + } + else + { if (this->type != entity_ptr->type) { std::ostringstream oss; From 6309425ae9d11b2b09efce112ec5a8ecc2c9b6cf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 5 Mar 2015 18:12:53 +0000 Subject: [PATCH 0883/1077] First try at constant capacitance model. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9331 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 8 ++-- mainsubs.cpp | 4 +- model.cpp | 130 ++++++++++++++++++++++++++++++++++++++++---------- prep.cpp | 6 +-- print.cpp | 17 ++++++- read.cpp | 15 ++++-- step.cpp | 4 +- 7 files changed, 142 insertions(+), 42 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index dc416d0d..d9fa797b 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -540,7 +540,7 @@ diff_layer_total(const char *total_name, const char *surface_name) int j; for (j = 0; j < count_unknowns; j++) { - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) { if (x[j]->type != SURFACE_CB) continue; @@ -582,7 +582,7 @@ diff_layer_total(const char *total_name, const char *surface_name) */ if (strcmp_nocase("psi", total_name) == 0) { - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) { return ((LDBLE) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ)); @@ -636,7 +636,7 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("charge", total_name) == 0) { - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL && dl_type_x == cxxSurface::NO_DL) + if ((use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) && dl_type_x == cxxSurface::NO_DL) { return ((LDBLE) (x[j]->f)); } @@ -682,7 +682,7 @@ diff_layer_total(const char *total_name, const char *surface_name) } else if (strcmp_nocase("sigma", total_name) == 0) { - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) { cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); if (dl_type_x != cxxSurface::NO_DL) diff --git a/mainsubs.cpp b/mainsubs.cpp index 01b699f6..d55e5763 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1679,7 +1679,7 @@ xsurface_save(int n_user) } comp_ptr->Set_charge_balance(charge); } - else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + else if (x[i]->type == SURFACE_CB && (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM)) { cxxSurfaceCharge *charge_ptr = temp_surface.Find_charge(x[i]->surface_charge); assert(charge_ptr); @@ -1977,7 +1977,7 @@ step_save_surf(int n_user) /* * Update grams */ - if ((surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) + if ((surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CCM || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) && surface_ptr->Get_related_rate() && use.Get_kinetics_ptr() != NULL) { for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) diff --git a/model.cpp b/model.cpp index 1ca269a8..8e61542a 100644 --- a/model.cpp +++ b/model.cpp @@ -1981,35 +1981,61 @@ jacobian_sums(void) */ if (surface_unknown != NULL && dl_type_x == cxxSurface::NO_DL) { - sinh_constant = - //sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * - // 1000); - sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * - 1000); - for (i = 0; i < count_unknowns; i++) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::CCM) { - cxxSurfaceCharge *charge_ptr = NULL; - if (x[i]->type == SURFACE_CB) + sinh_constant = + //sqrt(8 * EPSILON * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * + // 1000); + sqrt(8 * eps_r * EPSILON_ZERO * (R_KJ_DEG_MOL * 1000) * tk_x * + 1000); + for (i = 0; i < count_unknowns; i++) { - charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); - } - if (x[i]->type == SURFACE_CB && charge_ptr->Get_grams() > 0) - { - for (j = 0; j < count_unknowns; j++) + cxxSurfaceCharge *charge_ptr = NULL; + if (x[i]->type == SURFACE_CB) { - array[x[i]->number * (count_unknowns + 1) + j] *= - F_C_MOL / (charge_ptr->Get_specific_area() * - charge_ptr->Get_grams()); + charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); } - array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= - sinh_constant * sqrt(mu_x) * - cosh(x[i]->master[0]->s->la * LOG_10); - if (mu_unknown != NULL) + if (x[i]->type == SURFACE_CB && charge_ptr->Get_grams() > 0) { - array[x[i]->number * (count_unknowns + 1) + - mu_unknown->number] -= - 0.5 * sinh_constant / sqrt(mu_x) * - sinh(x[i]->master[0]->s->la * LOG_10); + for (j = 0; j < count_unknowns; j++) + { + array[x[i]->number * (count_unknowns + 1) + j] *= + F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()); + } + array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= + sinh_constant * sqrt(mu_x) * + cosh(x[i]->master[0]->s->la * LOG_10); + if (mu_unknown != NULL) + { + array[x[i]->number * (count_unknowns + 1) + + mu_unknown->number] -= + 0.5 * sinh_constant / sqrt(mu_x) * + sinh(x[i]->master[0]->s->la * LOG_10); + } + } + } + } + else + { + for (i = 0; i < count_unknowns; i++) + { + cxxSurfaceCharge *charge_ptr = NULL; + if (x[i]->type == SURFACE_CB) + { + charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + } + if (x[i]->type == SURFACE_CB && charge_ptr->Get_grams() > 0) + { + for (j = 0; j < count_unknowns; j++) + { + array[x[i]->number * (count_unknowns + 1) + j] *= + F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()); + } + array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= + charge_ptr->Get_capacitance0() * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ; } } } @@ -3524,7 +3550,7 @@ reset(void) /* recalculate g's for component */ if (dl_type_x != cxxSurface::NO_DL - && (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL + && (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM || (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC && x[i]->type == SURFACE_CB2))) { @@ -4349,6 +4375,60 @@ residuals(void) iterations, x[i]->description, i, residual[i])); converge = FALSE; } + } + else if (x[i]->type == SURFACE_CB && use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) + { + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + if (charge_ptr->Get_grams() == 0) + { + residual[i] = 0.0; + } + else if (dl_type_x != cxxSurface::NO_DL) + { + residual[i] = -x[i]->f; + } + else + { + residual[i] = + charge_ptr->Get_capacitance0() * x[i]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ - + x[i]->f * F_C_MOL / (charge_ptr->Get_specific_area() * + charge_ptr->Get_grams()); + } + if (debug_model == TRUE) + { + output_msg(sformatf( "Charge/Potential\n")); + if (charge_ptr->Get_grams() > 0) + { + output_msg(sformatf( + "\tSum of surface charge %e eq\n", + (double) (x[i]->f + /* F_C_MOL / (x[i]->surface_charge->specific_area * x[i]->surface_charge->grams) */ + ))); + } + else + { + output_msg(sformatf( "\tResidual %e\n", + (double) x[i]->f)); + } + output_msg(sformatf( "\t grams %g\n", + (double) charge_ptr->Get_grams())); + output_msg(sformatf( "\tCharge from potential %e eq\n", + (double) (charge_ptr->Get_capacitance0() * x[i]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ))); + output_msg(sformatf( "\t Psi %e\n", + (double) (x[i]->master[0]->s->la * 2 * R_KJ_DEG_MOL * + tk_x * LOG_10 / F_KJ_V_EQ))); + } + if (charge_ptr->Get_grams() > MIN_RELATED_SURFACE + && fabs(residual[i]) > l_toler) + { + if (print_fail) + output_msg(sformatf( + "Failed Residual %d: %s %d %e\n", iterations, + x[i]->description, i, residual[i])); + converge = FALSE; + } } else if (x[i]->type == SURFACE_CB1) { diff --git a/prep.cpp b/prep.cpp index 74823339..a198a408 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2836,7 +2836,7 @@ add_potential_factor(void) error_msg(error_string, CONTINUE); return(OK); } - if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL && use.Get_surface_ptr()->Get_type() != cxxSurface::CCM) return (OK); sum_z = 0.0; master_ptr = NULL; @@ -3069,7 +3069,7 @@ add_surface_charge_balance(void) error_msg(error_string, CONTINUE); return(OK); } - if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() != cxxSurface::DDL && use.Get_surface_ptr()->Get_type() != cxxSurface::CCM) return (OK); master_ptr = NULL; /* @@ -3492,7 +3492,7 @@ setup_surface(void) x[count_unknowns]->potential_unknown = NULL; count_unknowns++; /*if (use.Get_surface_ptr()->edl == FALSE) continue; */ - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) { /* * Setup surface-potential unknown diff --git a/print.cpp b/print.cpp index 3c115eb5..2ccb2588 100644 --- a/print.cpp +++ b/print.cpp @@ -1577,10 +1577,18 @@ print_surface(void) */ s_h2o->lm = s_h2o->la; + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + { + output_msg(sformatf("%-14s\n", "Diffuse Double Layer Surface-Complexation Model\n")); + } + else if (use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) + { + output_msg(sformatf("%-14s\n", "Constant Capacitance Surface-Complexation Model\n")); + } for (int j = 0; j < count_unknowns; j++) { /*if (use.Get_surface_ptr()->edl == TRUE) { */ - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL) + if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) { if (x[j]->type != SURFACE_CB) continue; @@ -1608,7 +1616,7 @@ print_surface(void) (double) x[j]->f)); } /*if (use.Get_surface_ptr()->edl == TRUE && diffuse_layer_x == FALSE) { */ - if (use.Get_surface_ptr()->Get_type() == cxxSurface::DDL && dl_type_x == cxxSurface::NO_DL) + if ((use.Get_surface_ptr()->Get_type() == cxxSurface::DDL || use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) && dl_type_x == cxxSurface::NO_DL) { charge = x[j]->f; } @@ -1641,6 +1649,11 @@ print_surface(void) output_msg(sformatf("\tundefined sigma, C/m²\n")); #endif } + if (use.Get_surface_ptr()->Get_type() == cxxSurface::CCM) + { + output_msg(sformatf("\t%11.3e capacitance, F/m^2\n", + (double) (charge_ptr->Get_capacitance0()))); + } output_msg(sformatf("\t%11.3e psi, V\n", (double) (x[j]->master[0]->s->la * 2 * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ))); diff --git a/read.cpp b/read.cpp index 0057e504..84f16166 100644 --- a/read.cpp +++ b/read.cpp @@ -7358,6 +7358,13 @@ read_surface(void) case 13: /* ccm */ temp_surface.Set_type(cxxSurface::CCM); copy_token(token1, &next_char); + if (charge_ptr == NULL) + { + error_msg("A surface must be defined before the capacitance is defined.\n", + CONTINUE); + input_error++; + break; + } if (sscanf(token1.c_str(), SCANFORMAT, &dummy) != 1) { error_msg("Expected capacitance for constant_capacitance model.\n", @@ -7371,8 +7378,8 @@ read_surface(void) } /* constant capacitance model not implemented yet */ - error_msg("Constant capacitance model not implemented.", CONTINUE); - input_error++; + //error_msg("Constant capacitance model not implemented.", CONTINUE); + //input_error++; break; case OPTION_DEFAULT: @@ -7623,7 +7630,7 @@ read_surface(void) /* * Make sure surface area is defined */ - if (temp_surface.Get_type() == cxxSurface::DDL || temp_surface.Get_type() == cxxSurface::CD_MUSIC) + if (temp_surface.Get_type() == cxxSurface::DDL || temp_surface.Get_type() == cxxSurface::CCM || temp_surface.Get_type() == cxxSurface::CD_MUSIC) { for (size_t i = 0; i < temp_surface.Get_surface_charges().size(); i++) { @@ -7657,7 +7664,7 @@ read_surface(void) temp_surface.Set_dl_type(cxxSurface::NO_DL); } } - else if (temp_surface.Get_type() == cxxSurface::DDL) + else if (temp_surface.Get_type() == cxxSurface::DDL || temp_surface.Get_type() == cxxSurface::CCM) { /* all values of dl_type are valid */ } diff --git a/step.cpp b/step.cpp index 283024ac..57a4a860 100644 --- a/step.cpp +++ b/step.cpp @@ -553,12 +553,12 @@ add_surface(cxxSurface *surface_ptr) } } } - if (surface_ptr->Get_type() != cxxSurface::DDL && surface_ptr->Get_type() != cxxSurface::CD_MUSIC) + if (surface_ptr->Get_type() != cxxSurface::DDL && surface_ptr->Get_type() != cxxSurface::CCM && surface_ptr->Get_type() != cxxSurface::CD_MUSIC) return (OK); for (size_t i = 0; i < surface_ptr->Get_surface_charges().size(); i++) { cxxSurfaceCharge *charge_ptr = &(surface_ptr->Get_surface_charges()[i]); - if (surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) + if (surface_ptr->Get_type() == cxxSurface::DDL || surface_ptr->Get_type() == cxxSurface::CCM || surface_ptr->Get_type() == cxxSurface::CD_MUSIC) { cb_x += charge_ptr->Get_charge_balance(); } From eafa16d0f1c8cf43e6291acc3e7ae2e046a97464 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 9 Mar 2015 19:00:17 +0000 Subject: [PATCH 0884/1077] CCM only for NO_DL (not donnan or diffuse_layer). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9338 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index 1815df8f..a6cfd884 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3048,6 +3048,17 @@ tidy_surface(void) } //if (!kit->second.Get_new_def()) continue; surface_ptr = &(kit->second); + // ccm incompatible with Donnan or diffuse_layer + if (surface_ptr->Get_type() == cxxSurface::CCM) + { + if (surface_ptr->Get_dl_type() == cxxSurface::BORKOVEK_DL || surface_ptr->Get_dl_type() == cxxSurface::DONNAN_DL) + { + input_error++; + error_string = "Cannot use -diffuse_layer or -donnan calculation with Constant Capacity Model."; + error_msg(error_string, CONTINUE); + continue; + } + } for (size_t i = 0; i < surface_ptr->Get_surface_comps().size(); i++) { cxxSurfaceComp *comp_ptr = &(surface_ptr->Get_surface_comps()[i]); From 544db5a230bde073e98f905080335ca196103ac2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 11 Mar 2015 14:59:02 +0000 Subject: [PATCH 0885/1077] Tony fixed problem with Peng Robinson SO2 (Marc Parmentier). Added test case peng_SO2, which should test for fix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9345 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- gases.cpp | 7 +++++-- prep.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gases.cpp b/gases.cpp index 1869e616..f9e5c26f 100644 --- a/gases.cpp +++ b/gases.cpp @@ -474,7 +474,7 @@ calc_PR(void) it = 0; halved = false; ddp = 1e-9; - v1 = vinit = 0.429; + v1 = vinit = 0.729; dp_dv = f_Vm(v1, this); while (fabs(dp_dv) > 1e-11 && it < 40) { @@ -483,7 +483,10 @@ calc_PR(void) v1 -= (dp_dv * ddp / (dp_dv - dp_dv2)); if (!halved && (v1 > vinit || v1 < 0.03)) { - vinit -= 0.05; + if (vinit > 0.329) + vinit -= 0.1; + else + vinit -=0.05; if (vinit < 0.03) { vinit = halve(f_Vm, 0.03, 1.0, 1e-3); diff --git a/prep.cpp b/prep.cpp index a198a408..f7be045f 100644 --- a/prep.cpp +++ b/prep.cpp @@ -44,7 +44,7 @@ prep(void) { error_msg("Solution needed for calculation not found, stopping.", STOP); - exit(4); + return ERROR; } description_x = (char *) free_check_null(description_x); description_x = string_duplicate(solution_ptr->Get_description().c_str()); @@ -4008,7 +4008,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) it = 0; halved = false; ddp = 1e-9; - v1 = vinit = 0.429; + v1 = vinit = 0.729; dp_dv = f_Vm(v1, this); while (fabs(dp_dv) > 1e-11 && it < 40) { @@ -4017,7 +4017,10 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) v1 -= (dp_dv * ddp / (dp_dv - dp_dv2)); if (!halved && (v1 > vinit || v1 < 0.03)) { - vinit -= 0.05; + if (vinit > 0.329) + vinit -= 0.1; + else + vinit -=0.05; if (vinit < 0.03) { vinit = halve(f_Vm, 0.03, 1.0, 1e-3); From 66f047f9c4a9413d00354ea7eb2b5eb8d62ac777 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 16 Mar 2015 18:46:40 +0000 Subject: [PATCH 0886/1077] default initial solution for the reaction calculation was not defined properly when using only SOLUTION_SPREAD. Modified tidy_solutions to assign first number (1) for that case. Added example num_spread. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9364 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index a6cfd884..0a5152e6 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3210,6 +3210,10 @@ tidy_solutions(void) // put unnumbered solutions in map for (size_t i = 0; i < unnumbered_solutions.size(); i++) { + if (use.Get_n_solution_user() < 0) + { + use.Set_n_solution_user(last + 1); + } unnumbered_solutions[i].Set_n_user_both(++last); Rxn_solution_map[last] = unnumbered_solutions[i]; Rxn_new_solution.insert(last); From ffd459c6db13cd53b6ac64c01dfce1046f4e6d6a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Mar 2015 19:41:09 +0000 Subject: [PATCH 0887/1077] Added SYS("equi", count, name$, type$, moles). Equi option was never implemented. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9388 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + basicsubs.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 80989284..1bd88af2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -146,6 +146,7 @@ public: int system_total_ex(void); int system_total_surf(void); int system_total_gas(void); + int system_total_equi(void); int system_total_ss(void); int system_total_elt(const char *total_name); int system_total_elt_secondary(const char *total_name); diff --git a/basicsubs.cpp b/basicsubs.cpp index d9fa797b..38963edf 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2580,6 +2580,10 @@ system_total(const char *total_name, LDBLE * count, char ***names, { system_total_gas(); } + else if (strcmp_nocase(total_name, "equi") == 0) + { + system_total_equi(); + } else { if (strstr(total_name, "(") == NULL) @@ -2973,6 +2977,33 @@ system_total_gas(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +system_total_equi(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Equilibrium phases + */ + if (use.Get_pp_assemblage_ptr() == NULL) + return (OK); + std::map comps = use.Get_pp_assemblage_ptr()->Get_pp_assemblage_comps(); + std::map ::iterator it = comps.begin(); + for ( ; it != comps.end(); it++) + { + cxxPPassemblageComp *comp_ptr = &(it->second); + int l; + struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); + sys[count_sys].name = string_duplicate(phase_ptr->name); + sys[count_sys].moles = comp_ptr->Get_moles(); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("equi"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: system_total_ss(void) /* ---------------------------------------------------------------------- */ { From 4d47ed13fc8c19789ff82008e5acd14cb46da349 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 24 Mar 2015 20:25:58 +0000 Subject: [PATCH 0888/1077] limit on eps_r in utilities.cpp. Added check when reading pitzer parameters that the right number of species is read. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9390 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer_structures.cpp | 10 +++++++++- utilities.cpp | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index b655985c..5da167bf 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -79,8 +79,16 @@ pitz_param_read(char *string, int n) ptr = string; for (i = 0; i < n; i++) { - if (copy_token(token, &ptr, &l) == EMPTY) + int j = copy_token(token, &ptr, &l); + if (j == EMPTY) return (NULL); + if (j != UPPER) + { + input_error++; + std::ostringstream err; + err << "Wrong number of species for a Pitzer parameter.\n" << line; + error_msg(err.str().c_str(), CONTINUE); + } pzp.species[i] = string_hsave(token); } k = 0; diff --git a/utilities.cpp b/utilities.cpp index baa32647..c63e4595 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -237,6 +237,11 @@ calc_dielectrics(LDBLE tc, LDBLE pa) LDBLE b = u7 + u8 / T + u9 * T; LDBLE pb = pa * 1.01325; // pa in bar eps_r = d1000 + c * log((b + pb) / (b + 1e3)); // relative dielectric constant + if (eps_r <= 0) + { + eps_r = 10.; + warning_msg("Relative dielectric constant is negative.\nTemperature is out of range of parameterization."); + } /* qe^2 / (eps_r * kB * T) = 4.803204e-10**2 / 1.38065e-16 / (eps_r * T) = 1.671008e-3 (esu^2 / (erg/K)) / (eps_r * T) */ From a6d63e33b5cdbaf038c62f847c4e120561e9007c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 25 Mar 2015 16:47:42 +0000 Subject: [PATCH 0889/1077] Commented dead code related to density of water in Pitzer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9396 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 10 ++++++---- dw.cpp | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 210c8b18..8f59b000 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -824,6 +824,7 @@ void Phreeqc::init(void) x_arg_max = 0; res_arg_max = 0; scratch_max = 0; +#ifdef SKIP /* dw.cpp ------------------------------- */ /* COMMON /QQQQ/ */ Q0 = 0; @@ -843,6 +844,7 @@ void Phreeqc::init(void) B2T = 0; B1TT = 0; B2TT = 0; +#endif /* gases.cpp ------------------------------- */ a_aa_sum = 0; b2 = 0; diff --git a/Phreeqc.h b/Phreeqc.h index 1bd88af2..104e728b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -252,7 +252,7 @@ public: void fpunchf_user(int user_index, const char *format, double d); void fpunchf_user(int user_index, const char *format, char * d); int fpunchf_end_row(const char *format); - +#ifdef SKIP // dw.cpp ------------------------------- int BB(LDBLE T); LDBLE PS(LDBLE T); @@ -260,7 +260,7 @@ public: int DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T); int QQ(LDBLE T, LDBLE D); LDBLE BASE(LDBLE D); - +#endif // input.cpp ------------------------------- int reading_database(void); void set_reading_database(int reading_database); @@ -526,8 +526,10 @@ public: int set_pz(int initial); int calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR); int check_gammas_pz(void); +#ifdef SKIP LDBLE DC(LDBLE T); int DW(LDBLE T); +#endif int ISPEC(const char *name); LDBLE G(LDBLE Y); LDBLE GP(LDBLE Y); @@ -1721,7 +1723,7 @@ protected: /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; int x_arg_max, res_arg_max, scratch_max; - +#ifdef SKIP /* dw.cpp ------------------------------- */ /* COMMON /QQQQ/ */ LDBLE Q0, Q5; @@ -1729,7 +1731,7 @@ protected: LDBLE Z, DZ, Y; LDBLE G1, G2, GF; LDBLE B1, B2, B1T, B2T, B1TT, B2TT; - +#endif /* gases.cpp ------------------------------- */ LDBLE a_aa_sum, b2, b_sum, R_TK; diff --git a/dw.cpp b/dw.cpp index d0c557c7..5c1e25c8 100644 --- a/dw.cpp +++ b/dw.cpp @@ -1,6 +1,6 @@ #include "Phreeqc.h" - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: DW(LDBLE T) @@ -412,3 +412,4 @@ C B = U[7] + U[8] / T + U[9] * T; return (D1000 + C * log((B + VP * 1.01325e0) / (B + 1000.0e0))); } +#endif \ No newline at end of file From 793df0c22a4f6045a289a2609e7b1f7f56024b27 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 27 Mar 2015 14:33:23 +0000 Subject: [PATCH 0890/1077] error check for Pitzer parameter was wrong git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9421 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pitzer.cpp b/pitzer.cpp index 17b0c552..84e01962 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -186,7 +186,7 @@ pitzer_tidy(void) continue; pitz_params[i]->ispec[j] = ISPEC(pitz_params[i]->species[j]); if ((j < 2 && pitz_params[i]->ispec[j] == -1) || - (j == 3 + (j == 2 && (pitz_params[i]->type == TYPE_PSI || pitz_params[i]->type == TYPE_ZETA) && pitz_params[i]->ispec[j] == -1)) From ab440058fbea10abf764cb4858eef62d9edc911b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 27 Mar 2015 22:03:36 +0000 Subject: [PATCH 0891/1077] Working on IPhreeqc Basic callback. Compiles with ISO_C_BINDING, but may need some more debugging. Need to merge this change with PhreeqcRM-trunk. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9424 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 ++++++++ basicsubs.cpp | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index 104e728b..fddc6004 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -86,7 +86,11 @@ public: void basic_free(void); double basic_callback(double x1, double x2, char * str); void register_basic_callback(double ( *fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1); +#ifdef IPHREEQC_NO_FORTRAN_MODULE void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)); +#else + void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str)); +#endif LDBLE activity(const char *species_name); LDBLE activity_coefficient(const char *species_name); @@ -1718,7 +1722,11 @@ protected: PBasic * basic_interpreter; double (*basic_callback_ptr) (double x1, double x2, const char *str, void *cookie); void *basic_callback_cookie; +#ifdef IPHREEQC_NO_FORTRAN_MODULE double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, size_t l); +#else + double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str); +#endif /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; diff --git a/basicsubs.cpp b/basicsubs.cpp index 38963edf..6096c637 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3873,7 +3873,11 @@ basic_callback(double x1, double x2, char * str) } if (basic_fortran_callback_ptr != NULL) { +#ifdef IPHREEQC_NO_FORTRAN_MODULE return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, (int) strlen(str)); +#else + return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str); +#endif } return 0; } @@ -3884,9 +3888,17 @@ Phreeqc::register_basic_callback(double (*fcn)(double x1, double x2, const char this->basic_callback_ptr = fcn; this->basic_callback_cookie = cookie1; } - +#ifdef IPHREEQC_NO_FORTRAN_MODULE void Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)) { this->basic_fortran_callback_ptr = fcn; } +#else + +void +Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str)) +{ + this->basic_fortran_callback_ptr = fcn; +} +#endif From 9ca2302555e42c3c18faae27afd2723157e4c855 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 30 Mar 2015 16:32:34 +0000 Subject: [PATCH 0892/1077] worked on pressure dependence in lk_phase git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9434 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 6096c637..aa8a6547 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -408,25 +408,38 @@ calc_logk_p(const char *name) int i, j; char token[MAX_LENGTH]; struct phase *phase_ptr; - LDBLE lk; + LDBLE lk=-999.9; LDBLE l_logk[MAX_LOG_K_INDICES]; strcpy(token, name); phase_ptr = phase_bsearch(token, &j, FALSE); + if (phase_ptr != NULL) - { + { + struct reaction *reaction_ptr; + if (phase_ptr->replaced) + reaction_ptr = phase_ptr->rxn_s; + else + reaction_ptr = phase_ptr->rxn; + /* + * Print saturation index + */ + reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) - + phase_ptr->logk[vm0]; + if (reaction_ptr->logk[delta_v]) + mu_terms_in_logk = true; for (i = 0; i < MAX_LOG_K_INDICES; i++) { l_logk[i] = 0.0; } - select_log_k_expression(phase_ptr->logk, l_logk); - add_other_logk(l_logk, phase_ptr->count_add_logk, phase_ptr->add_logk); + //lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM); + select_log_k_expression(reaction_ptr->logk, l_logk); + add_other_logk(l_logk, phase_ptr->count_add_logk, phase_ptr->add_logk); lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); - return (lk); } - return (-999.99); + return (lk); } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_logk_s(const char *name) @@ -458,7 +471,36 @@ calc_logk_s(const char *name) } return (-999.99); } +#endif +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_logk_s(const char *name) +/* ---------------------------------------------------------------------- */ +{ + int i; + char token[MAX_LENGTH]; + struct species *s_ptr; + LDBLE lk, l_logk[MAX_LOG_K_INDICES]; + strcpy(token, name); + s_ptr = s_search(token); + if (s_ptr != NULL) + { + if (s_ptr->logk[vm_tc]) + /* calculate delta_v for the reaction... */ + s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false); + for (i = 0; i < MAX_LOG_K_INDICES; i++) + { + l_logk[i] = 0.0; + } + select_log_k_expression(s_ptr->logk, l_logk); + mu_terms_in_logk = true; + add_other_logk(l_logk, s_ptr->count_add_logk, s_ptr->add_logk); + lk = k_calc(l_logk, tk_x, patm_x * PASCAL_PER_ATM); + return (lk); + } + return (-999.99); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: calc_surface_charge(const char *surface_name) From b255de16437a58d85cf61d617db43a2be02d49ab Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 30 Mar 2015 18:38:56 +0000 Subject: [PATCH 0893/1077] length argument needed for callback. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9435 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 ++-- basicsubs.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index fddc6004..69917b8c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -89,7 +89,7 @@ public: #ifdef IPHREEQC_NO_FORTRAN_MODULE void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)); #else - void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str)); + void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)); #endif LDBLE activity(const char *species_name); @@ -1725,7 +1725,7 @@ protected: #ifdef IPHREEQC_NO_FORTRAN_MODULE double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, size_t l); #else - double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str); + double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); #endif /* cl1.cpp ------------------------------- */ diff --git a/basicsubs.cpp b/basicsubs.cpp index aa8a6547..afb459e4 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3918,7 +3918,7 @@ basic_callback(double x1, double x2, char * str) #ifdef IPHREEQC_NO_FORTRAN_MODULE return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, (int) strlen(str)); #else - return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str); + return (*basic_fortran_callback_ptr) (&local_x1, &local_x2, str, (int) strlen(str)); #endif } return 0; @@ -3939,7 +3939,7 @@ Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, #else void -Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str)) +Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)) { this->basic_fortran_callback_ptr = fcn; } From 76e16420f557884313a72bdcaebd28857a0c230e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 2 Apr 2015 19:07:59 +0000 Subject: [PATCH 0894/1077] Added METHOD_REGISTERBASICCALLBACK for MPI. CALL register_basic_callback_fortran() in InitializeRM CALL register_basic_callback_fortran() in mpi_methods phast_manager my_basic_fortran_callback and register_basic_callback_fortran PBasic defined tokcell_pore_volume, tokcell_volume, tokcell_porosity, and tokcell_saturation git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9457 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 56161bc3..3b81ddc6 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3297,6 +3297,10 @@ factor(struct LOC_exec * LINK) case tokcell_pore_volume: case tokporevolume: + { + double x1 = (double) PhreeqcPtr->solution_number(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_pore_volume"); + } n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_pore_volume; break; @@ -3306,13 +3310,24 @@ factor(struct LOC_exec * LINK) break; /* VP: Density End */ case tokcell_volume: - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_volume; + { + double x1 = (double) PhreeqcPtr->solution_number(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_volume"); + } break; case tokcell_porosity: - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_porosity; + { + double x1 = (double) PhreeqcPtr->solution_number(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_porosity"); + } + //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_porosity; break; case tokcell_saturation: - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_saturation; + { + double x1 = (double) PhreeqcPtr->solution_number(); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_saturation"); + } + //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_saturation; break; case toksc: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_SC(); From 678fd85c15f10fd8a35fb21d614f14ce090d96e5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 2 Apr 2015 20:34:05 +0000 Subject: [PATCH 0895/1077] Debugged Basic callback for PHAST mpi. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9458 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 3b81ddc6..e5a4aa6a 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3301,7 +3301,6 @@ factor(struct LOC_exec * LINK) double x1 = (double) PhreeqcPtr->solution_number(); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_pore_volume"); } - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_pore_volume; break; /* VP : Density Start */ @@ -3320,14 +3319,12 @@ factor(struct LOC_exec * LINK) double x1 = (double) PhreeqcPtr->solution_number(); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_porosity"); } - //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_porosity; break; case tokcell_saturation: { double x1 = (double) PhreeqcPtr->solution_number(); n.UU.val = (parse_all) ? 1 : PhreeqcPtr->basic_callback(x1, x1, "cell_saturation"); } - //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_saturation; break; case toksc: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_SC(); From 18f0512be66ac4d7e3ac417fab2cac21e5d01565 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 2 Apr 2015 22:59:33 +0000 Subject: [PATCH 0896/1077] len=l for callback fortran string. Made basic callback string a "const" in 8 places. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9463 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 6 +++--- basicsubs.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 69917b8c..981bbe26 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -84,12 +84,12 @@ public: int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); - double basic_callback(double x1, double x2, char * str); + double basic_callback(double x1, double x2, const char * str); void register_basic_callback(double ( *fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1); #ifdef IPHREEQC_NO_FORTRAN_MODULE void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)); #else - void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)); + void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, const char *str, int l)); #endif LDBLE activity(const char *species_name); @@ -1725,7 +1725,7 @@ protected: #ifdef IPHREEQC_NO_FORTRAN_MODULE double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, size_t l); #else - double (*basic_fortran_callback_ptr) (double *x1, double *x2, char *str, int l); + double (*basic_fortran_callback_ptr) (double *x1, double *x2, const char *str, int l); #endif /* cl1.cpp ------------------------------- */ diff --git a/basicsubs.cpp b/basicsubs.cpp index afb459e4..f5270193 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3904,7 +3904,7 @@ basic_free(void) } double Phreeqc:: -basic_callback(double x1, double x2, char * str) +basic_callback(double x1, double x2, const char * str) { double local_x1 = x1; double local_x2 = x2; @@ -3939,7 +3939,7 @@ Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, #else void -Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, int l)) +Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, const char *str, int l)) { this->basic_fortran_callback_ptr = fcn; } From c66718096bf26491d5ba2fbcf02528801c6c923f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 13 Apr 2015 23:23:13 +0000 Subject: [PATCH 0897/1077] Bad input for SURFACE_SPECIES and SURFACE_MASTER_SPECIES generated a NULL pointer. Added additional error checks. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9507 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index 0a5152e6..7c864cb0 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -4172,6 +4172,14 @@ tidy_kin_surface(void) if (!surface_ptr->Get_related_rate()) continue; kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, n); + if (kinetics_ptr == NULL) + { + input_error++; + error_string = sformatf( + "Error in SURFACE related to KINETICS. "); + error_msg(error_string, CONTINUE); + continue; + } for (size_t k = 0; k < kinetics_ptr->Get_kinetics_comps().size(); k++) { cxxKineticsComp *kin_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[k]); @@ -4237,6 +4245,34 @@ tidy_kin_surface(void) } for (int j = 0; j < count_elts; j++) { + if (elt_list[j].elt == NULL) + { + input_error++; + error_string = sformatf( + "Cannot identify elements in kinetics component %s.", + comp_ptr_save->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_list[j].elt->primary == NULL ) + { + input_error++; + error_string = sformatf( + "Cannot identify primary element in kinetics component %s.", + comp_ptr_save->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_list[j].elt->primary->s == NULL) + { + input_error++; + error_string = sformatf( + "Cannot identify primary species for an element in kinetics component %s.", + comp_ptr_save->Get_formula().c_str()); + error_msg(error_string, CONTINUE); + continue; + } + if (elt_list[j].elt->primary->s->type <= H2O) { int l; From ba6f7f7bef484e125c333a7335ad2578383fcd2d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Mon, 13 Apr 2015 23:31:45 +0000 Subject: [PATCH 0898/1077] fixed crash that occurred when pitzer.dat was loaded twice git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9509 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/pitzer.cpp b/pitzer.cpp index 84e01962..4cd89cc7 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1356,6 +1356,7 @@ pitzer_clean_up(void) (struct pitz_param *) free_check_null(pitz_params[i]); } count_pitz_param = 0; + pitz_param_map.clear(); pitz_params = (struct pitz_param **) free_check_null(pitz_params); for (i = 0; i < count_theta_param; i++) { From 371548b50ca6783917b9003a773a8ffbeaf7a14d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 14 Apr 2015 00:39:33 +0000 Subject: [PATCH 0899/1077] added initializing to pitz_param git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9511 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer_structures.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 5da167bf..245a1871 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -49,6 +49,11 @@ pitz_param_init(struct pitz_param *pitz_param_ptr) } pitz_param_ptr->alpha = 0.0; pitz_param_ptr->thetas = NULL; + pitz_param_ptr->os_coef = 0.; + for (i = 0; i < 3; i++) + { + pitz_param_ptr->ln_coef[i] = 0.0; + } return (OK); } @@ -82,7 +87,7 @@ pitz_param_read(char *string, int n) int j = copy_token(token, &ptr, &l); if (j == EMPTY) return (NULL); - if (j != UPPER) + if (j != UPPER && token[0] != '(') { input_error++; std::ostringstream err; From 8e9134e325dede9c41399d56cf262d894abb7aeb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 14 Apr 2015 00:43:12 +0000 Subject: [PATCH 0900/1077] fixed crash that occurred when sit.dat was loaded twice git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9512 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- sit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/sit.cpp b/sit.cpp index 3cab673e..f6a55d03 100644 --- a/sit.cpp +++ b/sit.cpp @@ -482,6 +482,7 @@ sit_clean_up(void) } count_sit_param = 0; sit_params = (struct pitz_param **) free_check_null(sit_params); + sit_param_map.clear(); sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); spec = (struct species **) free_check_null(spec); From 413fa2a7d4757c6a5b07003b83b4eb2615432187 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 28 Apr 2015 06:44:08 +0000 Subject: [PATCH 0901/1077] fixed g++ warnings git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9561 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 +- structures.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 981bbe26..f5c7a342 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -932,7 +932,7 @@ public: struct unknown *unknown_alloc(void); int unknown_delete(int i); int unknown_free(struct unknown *unknown_ptr); - int entity_exists(char *name, int n_user); + int entity_exists(const char *name, int n_user); static int inverse_compare(const void *ptr1, const void *ptr2); int inverse_free(struct inverse *inverse_ptr); static int kinetics_compare_int(const void *ptr1, const void *ptr2); diff --git a/structures.cpp b/structures.cpp index b41a615a..1f4cbe6b 100644 --- a/structures.cpp +++ b/structures.cpp @@ -3449,7 +3449,7 @@ logk_search(const char *name_in) /* ---------------------------------------------------------------------- */ int Phreeqc:: -entity_exists(char *name, int n_user) +entity_exists(const char *name, int n_user) /* ---------------------------------------------------------------------- */ { /* @@ -3465,15 +3465,14 @@ entity_exists(char *name, int n_user) * reaction_temperature 9 Temperature * unknown 10 UnKnown */ - int i, return_value; - char *ptr; + int return_value; char token[MAX_LENGTH]; enum entity_type type; /* * Read keyword */ - ptr = name; - copy_token(token, &ptr, &i); + strncpy(token, name, MAX_LENGTH-1); + token[MAX_LENGTH-1] = '\0'; type = get_entity_enum(token); return_value = TRUE; switch (type) From 9779f9078deb8f9386b0173a7ab067760cfb0a8e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 5 May 2015 18:09:02 +0000 Subject: [PATCH 0902/1077] Revised sit to use lists. Runs maybe 2-3 times faster. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9579 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 2 + sit.cpp | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 300 insertions(+), 1 deletion(-) diff --git a/Phreeqc.h b/Phreeqc.h index f5c7a342..39cbad3b 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -801,6 +801,7 @@ public: int sit_initial_guesses(void); int sit_revise_guesses(void); int PTEMP_SIT(LDBLE tk); + void sit_make_lists(void); int jacobian_sit(void); // spread.cpp ------------------------------- @@ -1890,6 +1891,7 @@ protected: int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL; int *sit_IPRSNT; LDBLE *sit_M, *sit_LGAMMA; + std::vector s_list, cation_list, neutral_list, anion_list, ion_list, param_list; /* tidy.cpp ------------------------------- */ LDBLE a0, a1, kc, kb; diff --git a/sit.cpp b/sit.cpp index f6a55d03..50e46015 100644 --- a/sit.cpp +++ b/sit.cpp @@ -287,7 +287,7 @@ calc_sit_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) } return OK; } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: sit(void) @@ -465,7 +465,218 @@ sit(void) } return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +sit(void) +/* ---------------------------------------------------------------------- */ +{ + int i, i0, i1; + LDBLE param, z0, z1; + LDBLE A, AGAMMA, T; + /* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, + BMXPHI, PHIPHI, AW, A, B; + */ +/* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + B; +*/ + LDBLE XI, XX, OSUM, DI, F, OSMOT, B; + LDBLE I, TK; + /* + C + C INITIALIZE + C + */ + //CONV = 1.0 / log(10.0); + XI = 0.0e0; + XX = 0.0e0; + OSUM = 0.0e0; + /*n + I = *I_X; + TK = *TK_X; + */ + I = mu_x; + TK = tk_x; + /* DH_AB(TK, &A, &B); */ + /* + C + C TRANSFER DATA FROM TO sit_M + C + */ + double log_min = log10(MIN_TOTAL); + for (size_t j = 0; j < s_list.size(); j++) + { + i = s_list[j]; + if (spec[i]->lm > log_min) + { + sit_M[i] = under(spec[i]->lm); + } + else + { + sit_M[i] = 0.0; + } + } + //for (i = 0; i < 3 * count_s; i++) + //{ + // sit_IPRSNT[i] = FALSE; + // sit_M[i] = 0.0; + // if (spec[i] != NULL && spec[i]->in == TRUE) + // { + // if (spec[i]->type == EX || + // spec[i]->type == SURF || spec[i]->type == SURF_PSI) + // continue; + // sit_M[i] = under(spec[i]->lm); + // if (sit_M[i] > MIN_TOTAL) + // sit_IPRSNT[i] = TRUE; + // } + //} + /* + C + C COMPUTE SIT COEFFICIENTS' TEMPERATURE DEPENDENCE + C + */ + PTEMP_SIT(TK); + for (size_t j = 0; j < s_list.size(); j++) + { + int i = s_list[j]; + sit_LGAMMA[i] = 0.0; + XX = XX + sit_M[i] * fabs(spec[i]->z); + XI = XI + sit_M[i] * spec[i]->z * spec[i]->z; + OSUM = OSUM + sit_M[i]; + } + //for (i = 0; i < 2 * count_s + sit_count_anions; i++) + //{ + // sit_LGAMMA[i] = 0.0; + // if (sit_IPRSNT[i] == TRUE) + // { + // XX = XX + sit_M[i] * fabs(spec[i]->z); + // XI = XI + sit_M[i] * spec[i]->z * spec[i]->z; + // OSUM = OSUM + sit_M[i]; + // } + //} + I = XI / 2.0e0; + I = mu_x; // Added equation for MU + DI = sqrt(I); + /* + C + C CALCULATE F & GAMCLM + C + */ + AGAMMA = 3*sit_A0; /* Grenthe p 379 */ + A = AGAMMA / log(10.0); + /* + * F is now for log10 gamma + */ + B = 1.5; + F = -A * (DI / (1.0e0 + B * DI)); + + + /*OSMOT = -(sit_A0) * pow(I, 1.5e0) / (1.0e0 + B * DI);*/ + T = 1.0 + B*DI; + OSMOT = -2.0*A/(B*B*B)*(T - 2.0*log(T) - 1.0/T); + /* + * Sums for sit_LGAMMA, and OSMOT + * epsilons are tabulated for log10 gamma (not ln gamma) + */ + //for (i = 0; i < count_sit_param; i++) + //{ + for (size_t j = 0; j < param_list.size(); j++) + { + int i = param_list[j]; + i0 = sit_params[i]->ispec[0]; + i1 = sit_params[i]->ispec[1]; + //if (sit_IPRSNT[i0] == FALSE || sit_IPRSNT[i1] == FALSE) continue; + z0 = spec[i0]->z; + z1 = spec[i1]->z; + param = sit_params[i]->p; + switch (sit_params[i]->type) + { + case TYPE_SIT_EPSILON: + sit_LGAMMA[i0] += sit_M[i1] * param; + sit_LGAMMA[i1] += sit_M[i0] * param; + if (z0 == 0.0 && z1 == 0.0) + { + OSMOT += sit_M[i0] * sit_M[i1] * param / 2.0; + } + else + { + OSMOT += sit_M[i0] * sit_M[i1] * param; + } + break; + case TYPE_SIT_EPSILON_MU: + sit_LGAMMA[i0] += sit_M[i1] * I * param; + sit_LGAMMA[i1] += sit_M[i0] * I * param; + OSMOT += sit_M[i0] * sit_M[i1] * param; + if (z0 == 0.0 && z1 == 0.0) + { + OSMOT += sit_M[i0] * sit_M[i1] * param * I / 2.0; + } + else + { + OSMOT += sit_M[i0] * sit_M[i1] * param * I; + } + break; + default: + case TYPE_Other: + error_msg("TYPE_Other in pitz_param list.", STOP); + break; + } + } + + /* + * Add F and CSUM terms to sit_LGAMMA + */ + for (size_t j = 0; j < ion_list.size(); j++) + { + int i = ion_list[j]; + z0 = spec[i]->z; + sit_LGAMMA[i] += z0 * z0 * F; + } + //for (i = 0; i < sit_count_cations; i++) + //{ + // z0 = spec[i]->z; + // sit_LGAMMA[i] += z0 * z0 * F; + //} + //for (i = 2 * count_s; i < 2 * count_s + sit_count_anions; i++) + //{ + // z0 = spec[i]->z; + // sit_LGAMMA[i] += z0 * z0 * F; + //} + /* + C + C CONVERT TO MACINNES CONVENTION + C + */ + /*COSMOT = 1.0e0 + 2.0e0 * OSMOT / OSUM;*/ + COSMOT = 1.0e0 + OSMOT*log(10.0) / OSUM; + /* + C + C CALCULATE THE ACTIVITY OF WATER + C + */ + AW = exp(-OSUM * COSMOT / 55.50837e0); + /*if (AW > 1.0) AW = 1.0;*/ + /*s_h2o->la=log10(AW); */ + mu_x = I; + for (size_t j = 0; j < s_list.size(); j++) + { + int i = s_list[j]; + spec[i]->lg_pitzer = sit_LGAMMA[i]; + } +// for (i = 0; i < 2 * count_s + sit_count_anions; i++) +// { +// if (sit_IPRSNT[i] == FALSE) continue; +// spec[i]->lg_pitzer = sit_LGAMMA[i]; +///* +// output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, sit_M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); +//*/ +// } + return (OK); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: sit_clean_up(void) @@ -1003,6 +1214,7 @@ model_sit(void) { full_pitzer = FALSE; } + sit_make_lists(); for (;;) { mb_gases(); @@ -1345,6 +1557,7 @@ gammas_sit() return (OK); } +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: PTEMP_SIT(LDBLE TK) @@ -1374,3 +1587,87 @@ C Set DW0 OPRESS = patm_x; return OK; } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +PTEMP_SIT(LDBLE TK) +/* ---------------------------------------------------------------------- */ +{ +/* +C +C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER +C +*/ + LDBLE TR = 298.15; + + if (fabs(TK - OTEMP) < 0.001 && fabs(patm_x - OPRESS) < 0.1) return OK; +/* +C Set DW0 +*/ + DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); + VP = patm_x; + for (size_t j = 0; j < param_list.size(); j++) + { + int i = param_list[j]; + calc_sit_param(sit_params[i], TK, TR); + } + calc_dielectrics(TK - 273.15, patm_x); + sit_A0 = A0; + OTEMP = TK; + OPRESS = patm_x; + return OK; +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +sit_make_lists(void) +/* ---------------------------------------------------------------------- */ +{ + double log_min = log10(MIN_TOTAL); + s_list.clear(); + cation_list.clear(); + neutral_list.clear(); + anion_list.clear(); + ion_list.clear(); + param_list.clear(); + for (int i = 0; i < 3 * count_s; i++) + { + sit_IPRSNT[i] = FALSE; + sit_M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + sit_IPRSNT[i] = TRUE; + s_list.push_back(i); + if (i < count_s) + { + cation_list.push_back(i); + } + if (i >= count_s && i < 2*count_s) + { + neutral_list.push_back(i); + } + if (i >= 2*count_s) + { + anion_list.push_back(i); + } + if (i < count_s || i >= 2*count_s) + { + ion_list.push_back(i); + } + if (spec[i]->lm > log_min) + { + sit_M[i] = under(spec[i]->lm); + } + } + } + for (int i = 0; i < count_sit_param; i++) + { + int i0 = sit_params[i]->ispec[0]; + int i1 = sit_params[i]->ispec[1]; + if (sit_IPRSNT[i0] == FALSE || sit_IPRSNT[i1] == FALSE) continue; + param_list.push_back(i); + } +} \ No newline at end of file From 75cce6a2a29ecbbd7587e7288b9f791236dfcaaf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 8 May 2015 17:52:03 +0000 Subject: [PATCH 0903/1077] Do not use full pitzer for all retries in run_wrapper only number 4. Eliminate lg rows from array if not full_pitzer. Make lists at the end of prep (may be in error on trunk for initial solutions). sit_revise_guesses had some bad logic, now tries to get within a factor of 2 (fail logic revised). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/sit@9614 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 4 +++- model.cpp | 5 +++-- prep.cpp | 1 + sit.cpp | 20 +++++++++++--------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/kinetics.cpp b/kinetics.cpp index e7dcaea1..8830f696 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1309,7 +1309,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, { if (j == 1) { - always_full_pitzer = TRUE; + /*always_full_pitzer = TRUE;*/ if (pe_step_size <= small_pe_step && step_size <= small_step) continue; itmax *= 2; @@ -1338,6 +1338,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } else if (j == 4) { + always_full_pitzer = TRUE; itmax *= 2; if (diagonal_scale == TRUE) { @@ -1469,6 +1470,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, pp_column_scale = old_pp_column_scale; aqueous_only = 0; negative_concentrations = FALSE; + always_full_pitzer = FALSE; if (converge == TRUE) { break; diff --git a/model.cpp b/model.cpp index 8e61542a..e6f66608 100644 --- a/model.cpp +++ b/model.cpp @@ -1244,7 +1244,8 @@ ineq(int in_kode) } if (x[i]->type != SOLUTION_PHASE_BOUNDARY && x[i]->type != ALK && - x[i]->type != GAS_MOLES && x[i]->type != SS_MOLES + x[i]->type != GAS_MOLES && x[i]->type != SS_MOLES && + x[i]->type != PITZER_GAMMA /* && x[i]->type != PP */ ) { @@ -1302,7 +1303,7 @@ ineq(int in_kode) } l_count_rows++; } - else if (x[i]->type == PITZER_GAMMA) + else if (x[i]->type == PITZER_GAMMA && full_pitzer == TRUE) { memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), (void *) &(array[i * (count_unknowns + 1)]), diff --git a/prep.cpp b/prep.cpp index f7be045f..6b2a7206 100644 --- a/prep.cpp +++ b/prep.cpp @@ -123,6 +123,7 @@ prep(void) { error_msg("Program stopping due to input errors.", STOP); } + if (sit_model) sit_make_lists(); return (OK); } diff --git a/sit.cpp b/sit.cpp index 50e46015..3b22db33 100644 --- a/sit.cpp +++ b/sit.cpp @@ -837,12 +837,14 @@ sit_revise_guesses(void) int l_iter, max_iter, repeat, fail; LDBLE weight, f; - max_iter = 10; + max_iter = 100; /* gammas(mu_x); */ l_iter = 0; repeat = TRUE; - fail = FALSE;; - while (repeat == TRUE) + fail = FALSE; + double d = 2; + double logd = log10(d); + while (repeat == TRUE && fail == FALSE) { l_iter++; if (debug_set == TRUE) @@ -917,18 +919,18 @@ sit_revise_guesses(void) else if (f == 0) { repeat = TRUE; - x[i]->master[0]->s->la += 5; + x[i]->master[0]->s->la += logd; /*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; } else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) { continue; - } + } else if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) + || f < 1.0/d * fabs(x[i]->moles)) { - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; if (x[i]->moles <= 0) { x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; @@ -957,10 +959,10 @@ sit_revise_guesses(void) continue; } if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) + || f < 1.0/d * fabs(x[i]->moles)) { repeat = TRUE; - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); if (debug_set == TRUE) From 383cc7f2c7e1d761b60f8652701d67e1dc05424e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 10 May 2015 19:36:18 +0000 Subject: [PATCH 0904/1077] Estimate activities in PhreeqcRM git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9632 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index 84fd8a7b..add3b449 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1065,8 +1065,8 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->cb = charge; // Don`t bother to update activities? - //this->Update(const_nd); - this->totals = const_nd; + this->Update(const_nd); + //this->totals = const_nd; cxxNameDouble::iterator it; for (it = this->totals.begin(); it != this->totals.end(); it++) { From ca572ee976973f7975166820e7b872d4d2d54d72 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sun, 10 May 2015 19:40:10 +0000 Subject: [PATCH 0905/1077] Revised Basic function surf. I broke some functionality when I modified to get correct values for H and O. Reverted, but check for H and O, which uses another method (surf_total_no_redox). Modified As to do more checking, including Hfo_w, Hfo_s, and H. Update As.out. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9633 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index f5270193..16eaafd8 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2130,8 +2130,11 @@ surf_total(const char *total_name, const char *surface_name) } if (!redox) { - return surf_total_no_redox(total_name, surface_name); - } + if (strcmp(total_name, "H") == 0 || strcmp(total_name, "O") == 0) + { + return surf_total_no_redox(total_name, surface_name); + } + } /* * Find surface... */ From ef8611e0ed2150757a675277d4c4476ab3b3b29f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 May 2015 22:20:49 +0000 Subject: [PATCH 0906/1077] Switch bases for SIT. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9637 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 4 +++- sit.cpp | 48 +++++++++++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/prep.cpp b/prep.cpp index 6b2a7206..8a236983 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5028,6 +5028,8 @@ switch_bases(void) { if (x[i]->type != MB) continue; + if (x[i]->type == PITZER_GAMMA) + break; first = 0; la = x[i]->master[0]->s->la; for (j = 1; x[i]->master[j] != NULL; j++) @@ -5056,7 +5058,7 @@ switch_bases(void) x[i]->master[0]->s->name, iterations, la, x[i]->master[0]->s->la); */ x[i]->master[0]->s->la = la; - + x[i]->la = la; log_msg(sformatf( "Switching bases to %s.\tIteration %d\n", x[i]->master[0]->s->name, iterations)); return_value = TRUE; diff --git a/sit.cpp b/sit.cpp index 3b22db33..b23cfa16 100644 --- a/sit.cpp +++ b/sit.cpp @@ -894,19 +894,19 @@ sit_revise_guesses(void) if (x[i] == ph_unknown || x[i] == pe_unknown) continue; if (x[i]->type == MB || -/* x[i]->type == ALK || */ - x[i]->type == CB || - x[i]->type == SOLUTION_PHASE_BOUNDARY || - x[i]->type == EXCH || x[i]->type == SURFACE) + /* x[i]->type == ALK || */ + x[i]->type == CB || + x[i]->type == SOLUTION_PHASE_BOUNDARY || + x[i]->type == EXCH || x[i]->type == SURFACE) { if (debug_set == TRUE) { output_msg(sformatf( - "\n\t%5s at beginning of set %d: %e\t%e\t%e\n", - x[i]->description, l_iter, (double) x[i]->sum, - (double) x[i]->moles, - (double) x[i]->master[0]->s->la)); + "\n\t%5s at beginning of set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, (double) x[i]->sum, + (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); } if (fabs(x[i]->moles) < 1e-30) x[i]->moles = 0; @@ -923,12 +923,8 @@ sit_revise_guesses(void) /*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; } - else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) - { - continue; - } - else if (f > 1.5 * fabs(x[i]->moles) - || f < 1.0/d * fabs(x[i]->moles)) + else if (f > d * fabs(x[i]->moles) + || f < 1.0/d * fabs(x[i]->moles)) { weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; if (x[i]->moles <= 0) @@ -944,10 +940,10 @@ sit_revise_guesses(void) if (debug_set == TRUE) { output_msg(sformatf( - "\t%5s not converged in set %d: %e\t%e\t%e\n", - x[i]->description, l_iter, - (double) x[i]->sum, (double) x[i]->moles, - (double) x[i]->master[0]->s->la)); + "\t%5s not converged in set %d: %e\t%e\t%e\n", + x[i]->description, l_iter, + (double) x[i]->sum, (double) x[i]->moles, + (double) x[i]->master[0]->s->la)); } } } @@ -1297,7 +1293,10 @@ model_sit(void) { full_pitzer = FALSE; } - molalities(TRUE); + if (molalities(FALSE) == ERROR) + { + sit_revise_guesses(); + } if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && use.Get_surface_ptr()->Get_related_phases() == TRUE) @@ -1305,6 +1304,17 @@ model_sit(void) mb_sums(); mb_gases(); mb_ss(); +/* + * Switch bases if necessary + */ + if (switch_bases() == TRUE) + { + + count_basis_change++; + count_unknowns -= (int) s_list.size(); + reprep(); + full_pitzer = false; + } /* debug species_list_sort(); sum_species(); From 3e1e2bae17b85553ea4307e424fbcacc0c301c9a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 12 May 2015 04:48:46 +0000 Subject: [PATCH 0907/1077] created IPHREEQC_ENABLE_MODULE option git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9638 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 4 ++++ basicsubs.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Phreeqc.h b/Phreeqc.h index 39cbad3b..7b5bcb2e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -84,7 +84,11 @@ public: int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase); int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase); void basic_free(void); +#ifdef IPHREEQC_NO_FORTRAN_MODULE + double basic_callback(double x1, double x2, char * str); +#else double basic_callback(double x1, double x2, const char * str); +#endif void register_basic_callback(double ( *fcn)(double x1, double x2, const char *str, void *cookie), void *cookie1); #ifdef IPHREEQC_NO_FORTRAN_MODULE void register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, char *str, size_t l)); diff --git a/basicsubs.cpp b/basicsubs.cpp index 16eaafd8..89713680 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3906,8 +3906,13 @@ basic_free(void) delete this->basic_interpreter; } +#ifdef IPHREEQC_NO_FORTRAN_MODULE +double Phreeqc:: +basic_callback(double x1, double x2, char * str) +#else double Phreeqc:: basic_callback(double x1, double x2, const char * str) +#endif { double local_x1 = x1; double local_x2 = x2; From b157d11a46061225f92285705a529acadbc9eb22 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 May 2015 19:46:51 +0000 Subject: [PATCH 0908/1077] Reading a dumped SURFACE was processed as a new surface, which caused a problem. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9640 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tidy.cpp b/tidy.cpp index 7c864cb0..1053c49f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3808,6 +3808,7 @@ tidy_min_surface(void) assert(false); } cxxSurface *surface_ptr = &(kit->second); + if (!surface_ptr->Get_new_def()) continue; //if (!surface_ptr->Get_new_def()) // continue; //if (surface_ptr->Get_n_user() < 0) From 51db3a1569a6b6a57bfa8f078ac70d8e72cc8d1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 13 May 2015 20:42:47 +0000 Subject: [PATCH 0909/1077] Shrink array for SIT git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9648 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 36 +++++++++++++++++++++++++++++++----- pitzer.cpp | 3 ++- sit.cpp | 3 ++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/model.cpp b/model.cpp index e6f66608..4695da9f 100644 --- a/model.cpp +++ b/model.cpp @@ -1672,8 +1672,31 @@ ineq(int in_kode) { output_msg(sformatf( "k, l, m\t%d\t%d\t%d\n", k, l, m)); } - +#define SHRINK_ARRAY +#ifdef SHRINK_ARRAY + if (sit_model && full_pitzer == FALSE) + { + n = count_unknowns - (int) s_list.size(); + for (int i = 0; i < l_count_rows; i++) + { + //for (int j = 0; j < n; j++) + //{ + // ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; + //} + if (i > 0) + { + memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); + } + ineq_array[i*(n+2) + n] = ineq_array[i*(count_unknowns+2) + count_unknowns]; + } + } + else + { + n = count_unknowns; /* columns in A, C, E */ + } +#else n = count_unknowns; /* columns in A, C, E */ +#endif l_klmd = max_row_count - 2; l_nklmd = n + l_klmd; l_n2d = n + 2; @@ -1687,7 +1710,7 @@ ineq(int in_kode) { l_kode = 1; } - l_iter = 2*(count_unknowns + l_count_rows); + l_iter = 2*(n + l_count_rows); /* * Allocate space for arrays */ @@ -1787,10 +1810,13 @@ ineq(int in_kode) } #endif /* Copy delta1 into delta and scale */ - - memcpy((void *) &(delta[0]), (void *) &(delta1[0]), +#ifdef SHRINK_ARRAY + memcpy((void *) &(delta[0]), (void *) &(zero[0]), (size_t) count_unknowns * sizeof(LDBLE)); - for (i = 0; i < count_unknowns; i++) +#endif + memcpy((void *) &(delta[0]), (void *) &(delta1[0]), + (size_t) n * sizeof(LDBLE)); + for (i = 0; i < n; i++) delta[i] *= normal[i]; /* * Rescale columns of array diff --git a/pitzer.cpp b/pitzer.cpp index 4cd89cc7..c5247bd9 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -2034,7 +2034,8 @@ model_pz(void) count_infeasible)); log_msg(sformatf( "Number of basis changes: %d\n\n", count_basis_change)); - log_msg(sformatf( "Number of iterations: %d\n\n", iterations)); + log_msg(sformatf( "Number of iterations: %d\n", iterations)); + log_msg(sformatf( "Number of gamma iterations: %d\n\n", gamma_iterations)); debug_model = debug_model_save; set_forward_output_to_log(FALSE); if (stop_program == TRUE) diff --git a/sit.cpp b/sit.cpp index b23cfa16..1222205f 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1379,7 +1379,8 @@ model_sit(void) count_infeasible)); log_msg(sformatf( "Number of basis changes: %d\n\n", count_basis_change)); - log_msg(sformatf( "Number of iterations: %d\n\n", iterations)); + log_msg(sformatf( "Number of iterations: %d\n", iterations)); + log_msg(sformatf( "Number of gamma iterations: %d\n\n", gamma_iterations)); debug_model = debug_model_save; set_forward_output_to_log(FALSE); if (stop_program == TRUE) From 7b75b1c9e76b76d5b7230765605fb761b22c5713 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 27 May 2015 05:07:32 +0000 Subject: [PATCH 0910/1077] removed building of 32-bit and 64-bit linux versions; added missing CMake files git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9726 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Makefile.am b/Makefile.am index 45edab87..a0285cf2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,14 @@ +EXTRA_DIST=\ + ChartHandler.cpp\ + ChartHandler.h\ + ChartObject.cpp\ + ChartObject.h\ + CurveObject.cpp\ + CurveObject.h\ + Form1.h\ + Form1.resX\ + ZedGraph.dll + AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/PhreeqcKeywords bin_PROGRAMS = phreeqc From 0e78b1723090197b5c9f6f8e48921efe159a29ce Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 28 May 2015 23:38:01 +0000 Subject: [PATCH 0911/1077] memory leak when chart was closed before it plotting was finished. ex15b was used for debugging. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9735 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ChartHandler.cpp | 2 +- ChartObject.cpp | 20 ++++++++++++++------ Form1.h | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ChartHandler.cpp b/ChartHandler.cpp index 9f9bee89..edee12d4 100644 --- a/ChartHandler.cpp +++ b/ChartHandler.cpp @@ -179,7 +179,7 @@ ChartHandler::End_timer() } #endif it->second->Set_end_timer(true); - it->second->Set_phreeqc(NULL); + //it->second->Set_phreeqc(NULL); #if defined(__cplusplus_cli) int n = System::Threading::Interlocked::Exchange(it->second->usingResource, 0); assert(n == 6); diff --git a/ChartObject.cpp b/ChartObject.cpp index 826ca59b..510a667d 100644 --- a/ChartObject.cpp +++ b/ChartObject.cpp @@ -259,7 +259,7 @@ ChartObject::Read(CParser & parser) } else { - this->ColumnOffset = this->Curves.size(); + this->ColumnOffset = (int) this->Curves.size(); this->new_ug = true; } this->new_plotxy_curves.clear(); @@ -849,7 +849,10 @@ ChartObject::Set_rate_struct(void) oss << *it << "\n"; } this->Rate_free(); - this->user_graph->commands = (char *) phreeqc_ptr-> PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); + if (this->phreeqc_ptr) + { + this->user_graph->commands = (char *) phreeqc_ptr-> PHRQ_malloc((oss.str().size()) + 100 * sizeof(char)); + } ::strcpy(this->user_graph->commands, oss.str().c_str()); this->user_graph->new_def = this->rate_new_def; this->user_graph->loopbase = NULL; @@ -1080,13 +1083,18 @@ void ChartObject::Rate_free(void) { - - user_graph->commands = (char *) phreeqc_ptr-> free_check_null(user_graph->commands); - + + if (this->phreeqc_ptr) + { + user_graph->commands = (char *) phreeqc_ptr-> free_check_null(user_graph->commands); + } if (user_graph->linebase != NULL) { char cmd[] = "new; quit"; - phreeqc_ptr-> basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase); + if (this->phreeqc_ptr) + { + phreeqc_ptr-> basic_run(cmd, user_graph->linebase, user_graph->varbase, user_graph->loopbase); + } user_graph->linebase = NULL; user_graph->varbase = NULL; user_graph->loopbase = NULL; diff --git a/Form1.h b/Form1.h index 1eced151..30edf3f4 100644 --- a/Form1.h +++ b/Form1.h @@ -74,7 +74,7 @@ namespace zdg_ui2 { if (Phreeqc* ptr = chart->Get_phreeqc()) { ptr->Get_chart_handler().Decrement_active_charts(); - chart->Set_phreeqc(NULL); + //chart->Set_phreeqc(NULL); } } this->chartobject_ptr = NULL; @@ -640,9 +640,9 @@ namespace zdg_ui2 { { //double x = ip[i]->X; f_out.width(12); - f_out << ip[i2]->X << "\t"; + f_out << ip[(int) i2]->X << "\t"; f_out.width(12); - f_out << ip[i2]->Y << "\t"; + f_out << ip[(int) i2]->Y << "\t"; } else if (i2 < max_points) { From 4e07ab28e7ca3dea3b5b5d7e7aca3ad46b7e904d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 8 Jun 2015 15:43:42 +0000 Subject: [PATCH 0912/1077] Optimizations for pitzer.cpp Change in PTEMP did not work for unknown reasons. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9793 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 +- pitzer.cpp | 575 ++++++++++++++++++++++++++++++++++++++++++++++++++++- prep.cpp | 1 + 3 files changed, 578 insertions(+), 6 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 7b5bcb2e..829afe43 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -524,6 +524,7 @@ public: struct theta_param *theta_param_search(LDBLE zj, LDBLE zk); struct theta_param *theta_param_alloc(void); int theta_param_init(struct theta_param *theta_param_ptr); + void pitzer_make_lists(void); int gammas_pz(void); int model_pz(void); int pitzer(void); @@ -543,12 +544,13 @@ public: LDBLE GP(LDBLE Y); int ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap); - int BDK(LDBLE X); + void ETHETA_PARAMS(LDBLE X, LDBLE& JAY, LDBLE& JPRIME ); + //int BDK(LDBLE X); int pitzer_initial_guesses(void); int pitzer_revise_guesses(void); int PTEMP(LDBLE TK); - LDBLE JAY(LDBLE X); - LDBLE JPRIME(LDBLE Y); + //LDBLE JAY(LDBLE X); + //LDBLE JPRIME(LDBLE Y); int jacobian_pz(void); // pitzer_structures.cpp ------------------------------- diff --git a/pitzer.cpp b/pitzer.cpp index c5247bd9..576cb7f8 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -770,7 +770,9 @@ C DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); VP = patm_x; for (i = 0; i < count_pitz_param; i++) + //for (size_t j = 0; j < param_list.size(); j++) { + //int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } calc_dielectrics(TK - 273.15, patm_x); @@ -845,7 +847,7 @@ calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) } return OK; } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: pitzer(void) @@ -1180,7 +1182,385 @@ pitzer(void) */ return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +pitzer(void) +/* ---------------------------------------------------------------------- */ +{ + int i, i0, i1, i2; + LDBLE param, l_alpha, z0, z1; + LDBLE etheta, ethetap; + /* + LDBLE CONV, XI, XX, OSUM, BIGZ, DI, F, XXX, GAMCLM, + CSUM, PHIMAC, OSMOT, BMXP, ETHEAP, CMX, BMX, PHI, + BMXPHI, PHIPHI, AW, A, B; + */ + LDBLE CONV, XX, OSUM, BIGZ, DI, F, F1, F2, F_var, XXX, GAMCLM, CSUM, PHIMAC, OSMOT, + B, B1, B2; + LDBLE I, TK; + /* + C + C INITIALIZE + C + */ + CONV = 1.0 / log(10.0); + XX = 0.0; + OSUM = 0.0; + /*n + I = *I_X; + TK = *TK_X; + */ + I = mu_x; + TK = tk_x; + /* DH_AB(TK, &A, &B); */ + /* + C + C TRANSFER DATA FROM TO M + C + */ + double log_min = log10(MIN_TOTAL); + for (size_t j = 0; j < s_list.size(); j++) + { + i = s_list[j]; + if (spec[i]->lm > log_min) + { + M[i] = under(spec[i]->lm); + } + else + { + M[i] = 0.0; + } + } +#ifdef SKIP + for (i = 0; i < 3 * count_s; i++) + { + IPRSNT[i] = FALSE; + M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + M[i] = under(spec[i]->lm); + if (M[i] > MIN_TOTAL) + IPRSNT[i] = TRUE; + } + } +#endif + if (ICON == TRUE) + { + IPRSNT[IC] = TRUE; + } + /* + ICON = 0; + M[1] = 1.40070736; + M[4] = 2.52131086E-05; + M[140] = 4.59985435E-09; + */ + /* + C + C COMPUTE PITZER COEFFICIENTS' TEMPERATURE DEPENDENCE + C + */ + PTEMP(TK); + for (size_t j = 0; j < s_list.size(); j++) + { + int i = s_list[j]; + LGAMMA[i] = 0.0; + XX = XX + M[i] * fabs(spec[i]->z); + OSUM = OSUM + M[i]; + } + //for (i = 0; i < 2 * count_s + count_anions; i++) + //{ + // LGAMMA[i] = 0.0; + // if (IPRSNT[i] == TRUE) + // { + // XX = XX + M[i] * fabs(spec[i]->z); + // OSUM = OSUM + M[i]; + // } + //} + /* + C + C EQUATION (8) + C + */ + BIGZ = XX; + DI = sqrt(I); + /* + C + C CALCULATE F & GAMCLM + C + */ + B = 1.2; + F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B); + if (patm_x > 1.0) + { + LDBLE pap; + pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x; + B1 = B - (pap > 0.2 ? 0.2 : pap); + pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); + //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + B2 = B - (pap > 0.2 ? 0.2 : pap); + if (B1 != 0) + F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); + if (B2 != 0) + F2 = -A0 * (DI / (1.0 + B2 * DI) + 2.0 * log(1.0 + B2 * DI) / B2); + } + XXX = 2.0 * DI; + XXX = (1.0 - (1.0 + XXX - XXX * XXX * 0.5) * exp(-XXX)) / (XXX * XXX); + /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I; */ + /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I; */ + /*GAMCLM = F + I * 2.0e0 * (mcb0->p + mcb1->p * XXX) + 1.5e0 * mcc0->p * I * I; */ + GAMCLM = F1; + if (mcb0 != NULL) + GAMCLM += I * 2.0 * mcb0->p; + if (mcb1 != NULL) + GAMCLM += I * 2.0 * mcb1->p * XXX; + if (mcc0 != NULL) + GAMCLM += 1.5 * mcc0->p * I * I; + CSUM = 0.0; + OSMOT = -(A0) * pow(I, (LDBLE) 1.5) / (1.0 + B * DI); + /* + * Calculate ethetas + */ + if (use_etheta == TRUE) + { + for (i = 0; i < count_theta_param; i++) + { + z0 = theta_params[i]->zj; + z1 = theta_params[i]->zk; + ETHETAS(z0, z1, I, ðeta, ðetap); + theta_params[i]->etheta = etheta; + theta_params[i]->ethetap = ethetap; + } + } + /* + * Sums for F, LGAMMA, and OSMOT + */ + //for (i = 0; i < count_pitz_param; i++) + for (size_t j = 0; j < param_list.size(); j++) + { + int i = param_list[j]; + i0 = pitz_params[i]->ispec[0]; + i1 = pitz_params[i]->ispec[1]; + //if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) + // continue; + z0 = spec[i0]->z; + z1 = spec[i1]->z; + param = pitz_params[i]->p; + l_alpha = pitz_params[i]->alpha; + F_var = 0; + switch (pitz_params[i]->type) + { + case TYPE_B0: + LGAMMA[i0] += M[i1] * 2.0 * param; + LGAMMA[i1] += M[i0] * 2.0 * param; + OSMOT += M[i0] * M[i1] * param; + break; + case TYPE_B1: + if (param != 0.0) + { + F_var = M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); + LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); + OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); + } + break; + case TYPE_B2: + if (param != 0.0) + { + F_var = M[i0] * M[i1] * param * GP(l_alpha * DI) / I; + LGAMMA[i0] += M[i1] * 2.0 * param * G(l_alpha * DI); + LGAMMA[i1] += M[i0] * 2.0 * param * G(l_alpha * DI); + OSMOT += M[i0] * M[i1] * param * exp(-l_alpha * DI); + } + break; + case TYPE_C0: + CSUM += + M[i0] * M[i1] * pitz_params[i]->p / (2.0 * + sqrt(fabs(z0 * z1))); + LGAMMA[i0] += M[i1] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + LGAMMA[i1] += M[i0] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + OSMOT += + M[i0] * M[i1] * BIGZ * param / (2.0 * sqrt(fabs(z0 * z1))); + break; + case TYPE_THETA: + LGAMMA[i0] += 2.0 * M[i1] * (param /*+ ETHETA(z0, z1, I) */ ); + LGAMMA[i1] += 2.0 * M[i0] * (param /*+ ETHETA(z0, z1, I) */ ); + OSMOT += M[i0] * M[i1] * param; + break; + case TYPE_ETHETA: + /* + ETHETAS(z0, z1, I, ðeta, ðetap); + */ + if (use_etheta == TRUE) + { + etheta = pitz_params[i]->thetas->etheta; + ethetap = pitz_params[i]->thetas->ethetap; + F_var = M[i0] * M[i1] * ethetap; + LGAMMA[i0] += 2.0 * M[i1] * etheta; + LGAMMA[i1] += 2.0 * M[i0] * etheta; + OSMOT += M[i0] * M[i1] * (etheta + I * ethetap); + /* + F += M[i0]*M[i1]*ETHETAP(z0, z1, I); + LGAMMA[i0] += 2.0*M[i1]*(ETHETA(z0, z1, I) ); + LGAMMA[i1] += 2.0*M[i0]*(ETHETA(z0, z1, I) ); + OSMOT += M[i0]*M[i1]*(ETHETA(z0, z1, I) + I*ETHETAP(z0, z1, I) ); + */ + } + break; + case TYPE_PSI: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_LAMDA: + LGAMMA[i0] += M[i1] * param * pitz_params[i]->ln_coef[0]; + LGAMMA[i1] += M[i0] * param * pitz_params[i]->ln_coef[1]; + OSMOT += M[i0] * M[i1] * param * pitz_params[i]->os_coef; + break; + case TYPE_ZETA: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_MU: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + + LGAMMA[i0] += M[i1] * M[i2] * param * pitz_params[i]->ln_coef[0]; + LGAMMA[i1] += M[i0] * M[i2] * param * pitz_params[i]->ln_coef[1]; + LGAMMA[i2] += M[i0] * M[i1] * param * pitz_params[i]->ln_coef[2]; + OSMOT += M[i0] * M[i1] * M[i2] * param * pitz_params[i]->os_coef; + break; + case TYPE_ETA: + i2 = pitz_params[i]->ispec[2]; + if (IPRSNT[i2] == FALSE) + continue; + LGAMMA[i0] += M[i1] * M[i2] * param; + LGAMMA[i1] += M[i0] * M[i2] * param; + LGAMMA[i2] += M[i0] * M[i1] * param; + OSMOT += M[i0] * M[i1] * M[i2] * param; + break; + case TYPE_ALPHAS: + break; + case TYPE_Other: + default: + error_msg("TYPE_Other in pitz_param list.", STOP); + break; + } + F += F_var; + F1 += F_var; + F2 += F_var; + } + + /* + * Add F and CSUM terms to LGAMMA + */ + + for (size_t j = 0; j < ion_list.size(); j++) + { + int i = ion_list[j]; + z0 = fabs(spec[i]->z); + F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; + } + //for (i = 0; i < count_cations; i++) + //{ + // if (!IPRSNT[i]) + // continue; + // z0 = fabs(spec[i]->z); + // F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + // LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; + //} + //for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) + //{ + // if (!IPRSNT[i]) + // continue; + // z0 = fabs(spec[i]->z); + // F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + // LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; + //} + /* + C + C CONVERT TO MACINNES CONVENTION + C + */ + if (ICON == TRUE) + { + PHIMAC = LGAMMA[IC] - GAMCLM; + /* + C + C CORRECTED ERROR IN PHIMAC, NOVEMBER, 1989 + C + */ + for (size_t j = 0; j < s_list.size(); j++) + { + int i = s_list[j]; + LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; + } + //for (i = 0; i < 2 * count_s + count_anions; i++) + //{ + // if (IPRSNT[i] == TRUE) + // { + // LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; + // } + //} + } + + COSMOT = 1.0 + 2.0 * OSMOT / OSUM; + /* + C + C CALCULATE THE ACTIVITY OF WATER + C + */ + AW = exp(-OSUM * COSMOT / 55.50837); + /* + if (AW > 1.0) + AW = 1.0; + */ + /*s_h2o->la=log10(AW); */ + mu_x = I; + for (size_t j = 0; j < s_list.size(); j++) + { + int i = s_list[j]; + spec[i]->lg_pitzer = LGAMMA[i] * CONV; + } + //for (i = 0; i < 2 * count_s + count_anions; i++) + //{ + // if (IPRSNT[i] == FALSE) + // continue; + // /*spec[i]->lg=LGAMMA[i]*CONV; */ + // spec[i]->lg_pitzer = LGAMMA[i] * CONV; + // /* + // output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); + // */ + //} + /* + output_msg(sformatf( "OSUM: %e\n", OSUM)); + output_msg(sformatf( "OSMOT: %e\n", OSMOT)); + output_msg(sformatf( "COSMOT: %e\n", COSMOT)); + output_msg(sformatf( "F: %e\n", F)); + output_msg(sformatf( "AW: %e\n", AW)); + */ + /* + *I_X = I; + *COSMOT_X = COSMOT; + */ + return (OK); +} +#ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: JAY(LDBLE X) @@ -1217,7 +1597,6 @@ JPRIME(LDBLE L_Y) return (L_Y * (.25e0 + L_DZ * (DK[0] - DK[2]) / 2.0e0)); } - /* ---------------------------------------------------------------------- */ int Phreeqc:: BDK(LDBLE X) @@ -1277,6 +1656,7 @@ C } return OK; } +#endif /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -1305,7 +1685,7 @@ GP(LDBLE L_Y) } return d; } - +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap) @@ -1340,6 +1720,124 @@ C JPRIME(XKK) / 2.0e0) / (8.0e0 * I * I) - *etheta / I; return (OK); } +#endif +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap) +/* ---------------------------------------------------------------------- */ +{ + *etheta = 0.0; + *ethetap = 0.0; + + if (ZJ == ZK) + return (OK); + + const LDBLE XCON = 6.0e0 * A0 * sqrt(I); + const LDBLE ZZ = ZJ * ZK; +/* +C +C NEXT 3 ARE EQUATION (A1) +C +*/ + const LDBLE XJK = XCON * ZZ; + const LDBLE XJJ = XCON * ZJ * ZJ; + const LDBLE XKK = XCON * ZK * ZK; + +/* +C +C EQUATION (A3) +C +*/ + LDBLE JAY_XJK; + LDBLE JPRIME_XJK; + ETHETA_PARAMS( XJK, JAY_XJK, JPRIME_XJK ); + + LDBLE JAY_XJJ; + LDBLE JPRIME_XJJ; + ETHETA_PARAMS( XJJ, JAY_XJJ, JPRIME_XJJ ); + + LDBLE JAY_XKK; + LDBLE JPRIME_XKK; + ETHETA_PARAMS( XKK, JAY_XKK, JPRIME_XKK ); + + *etheta = + ZZ * (JAY_XJK - JAY_XJJ / 2.0e0 - JAY_XKK / 2.0e0) / (4.0e0 * I); + *ethetap = + ZZ * (JPRIME_XJK - JPRIME_XJJ / 2.0e0 - + JPRIME_XKK / 2.0e0) / (8.0e0 * I * I) - *etheta / I; + + return (OK); +} + +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +ETHETA_PARAMS(LDBLE X, LDBLE& JAY, LDBLE& JPRIME ) +/* ---------------------------------------------------------------------- */ +/* +C +C NUMERICAL APPROXIMATION TO THE INTEGRALS IN THE EXPRESSIONS FOR J0 +C AND J1. CHEBYSHEV APPROXIMATION IS USED. THE CONSTANTS 'AK' ARE +C DEFINED IN BLOCK COMMON. +C +*/ +/* +C +C AK IS USED TO CALCULATE HIGHER ORDER ELECTROSTATIC TERMS IN +C SUBROUTINE PITZER +C +*/ +{ + static const LDBLE AKX[42] = { + 1.925154014814667e0, -.060076477753119e0, -.029779077456514e0, + -.007299499690937e0, 0.000388260636404e0, 0.000636874599598e0, + 0.000036583601823e0, -.000045036975204e0, -.000004537895710e0, + 0.000002937706971e0, 0.000000396566462e0, -.000000202099617e0, + -.000000025267769e0, 0.000000013522610e0, 0.000000001229405e0, + -.000000000821969e0, -.000000000050847e0, 0.000000000046333e0, + 0.000000000001943e0, -.000000000002563e0, -.000000000010991e0, + 0.628023320520852e0, 0.462762985338493e0, 0.150044637187895e0, + -.028796057604906e0, -.036552745910311e0, -.001668087945272e0, + 0.006519840398744e0, 0.001130378079086e0, -.000887171310131e0, + -.000242107641309e0, 0.000087294451594e0, 0.000034682122751e0, + -.000004583768938e0, -.000003548684306e0, -.000000250453880e0, + 0.000000216991779e0, 0.000000080779570e0, 0.000000004558555e0, + -.000000006944757e0, -.000000002849257e0, 0.000000000237816e0 + }; +/* + LDBLE PRECISION AK, BK, DK + COMMON / MX8 / AK(0:20,2),BK(0:22),DK(0:22) +*/ + const LDBLE *AK; + LDBLE L_Z = 0.0; + LDBLE L_DZ = 0.0; + + if ( X <= 1.0e0 ) + { + const LDBLE powX0_2 = pow( X, 0.2 ); + L_Z = 4.0e0 * powX0_2 - 2.0e0; + L_DZ = 0.8e0 * powX0_2 / 2.0e0; + AK = &AKX[0]; + } + else + { + const LDBLE powXmin0_1 = pow( X, -0.1 ); + L_Z = ( 40.0e0 * powXmin0_1 - 22.0e0 ) / 9.0e0; + L_DZ = -4.0e0 * powXmin0_1 / 18.0e0; + AK = &AKX[21]; + } + + BK[20] = AK[20]; + BK[19] = L_Z * AK[20] + AK[19]; + DK[19] = AK[20]; + for ( int i = 18; i >= 0; i-- ) + { + BK[i] = L_Z * BK[i + 1] - BK[i + 2] + AK[i]; + DK[i] = BK[i + 1] + L_Z * DK[i + 1] - DK[i + 2]; + } + + JAY = X / 4.0e0 - 1.0e0 + 0.5e0 * (BK[0] - BK[2]); + JPRIME = X * .25e0 + L_DZ * (DK[0] - DK[2]); +} /* ---------------------------------------------------------------------- */ int Phreeqc:: @@ -2222,3 +2720,74 @@ gammas_pz() return (OK); } +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +pitzer_make_lists(void) +/* ---------------------------------------------------------------------- */ +{ + double log_min = log10(MIN_TOTAL); + s_list.clear(); + cation_list.clear(); + neutral_list.clear(); + anion_list.clear(); + ion_list.clear(); + param_list.clear(); + for (int i = 0; i < 3 * count_s; i++) + { + IPRSNT[i] = FALSE; + M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + IPRSNT[i] = TRUE; + s_list.push_back(i); + if (i < count_s) + { + cation_list.push_back(i); + } + if (i >= count_s && i < 2*count_s) + { + neutral_list.push_back(i); + } + if (i >= 2*count_s) + { + anion_list.push_back(i); + } + if (i < count_s || i >= 2*count_s) + { + ion_list.push_back(i); + } + if (spec[i]->lm > log_min) + { + M[i] = under(spec[i]->lm); + } + } + } + if (ICON == TRUE) + { + IPRSNT[IC] = TRUE; + } + for (int i = 0; i < count_pitz_param; i++) + { + /* + TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, + TYPE_PSI, TYPE_ETHETA, TYPE_ALPHAS, TYPE_MU, TYPE_ETA, TYPE_Other, + TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU + */ + int i0 = pitz_params[i]->ispec[0]; + int i1 = pitz_params[i]->ispec[1]; + if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) continue; + int i2 = pitz_params[i]->ispec[2]; + if (pitz_params[i]->type == TYPE_PSI || + pitz_params[i]->type == TYPE_ZETA || + pitz_params[i]->type == TYPE_MU || + pitz_params[i]->type == TYPE_ETA) + { + if (IPRSNT[i2] == FALSE) + continue; + } + param_list.push_back(i); + } +} \ No newline at end of file diff --git a/prep.cpp b/prep.cpp index 8a236983..e5125572 100644 --- a/prep.cpp +++ b/prep.cpp @@ -124,6 +124,7 @@ prep(void) error_msg("Program stopping due to input errors.", STOP); } if (sit_model) sit_make_lists(); + if (pitzer_model) pitzer_make_lists(); return (OK); } From c319dc836ee1c08a7b3f9b6528278654ede71042 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 8 Jun 2015 16:49:50 +0000 Subject: [PATCH 0913/1077] reverted Pitzer optimization. Not sure what goes wrong. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9794 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 15 ++++++++------- prep.cpp | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index 576cb7f8..ac1d2e23 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -847,7 +847,6 @@ calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) } return OK; } -#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: pitzer(void) @@ -1182,7 +1181,7 @@ pitzer(void) */ return (OK); } -#endif +#ifdef SKIP /* ---------------------------------------------------------------------- */ int Phreeqc:: pitzer(void) @@ -1560,6 +1559,7 @@ pitzer(void) */ return (OK); } +#endif #ifdef SKIP /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: @@ -2736,7 +2736,8 @@ pitzer_make_lists(void) { IPRSNT[i] = FALSE; M[i] = 0.0; - if (spec[i] != NULL && spec[i]->in == TRUE) + if ((spec[i] != NULL && spec[i]->in == TRUE) || + (ICON == TRUE && i == IC)) { if (spec[i]->type == EX || spec[i]->type == SURF || spec[i]->type == SURF_PSI) @@ -2765,10 +2766,10 @@ pitzer_make_lists(void) } } } - if (ICON == TRUE) - { - IPRSNT[IC] = TRUE; - } + //if (ICON == TRUE) + //{ + // IPRSNT[IC] = TRUE; + //} for (int i = 0; i < count_pitz_param; i++) { /* diff --git a/prep.cpp b/prep.cpp index e5125572..d68058ff 100644 --- a/prep.cpp +++ b/prep.cpp @@ -124,7 +124,7 @@ prep(void) error_msg("Program stopping due to input errors.", STOP); } if (sit_model) sit_make_lists(); - if (pitzer_model) pitzer_make_lists(); + //if (pitzer_model) pitzer_make_lists(); return (OK); } From 6de09799c96b6c12ffe08f8e31255a1a5f7c1b0d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 Jun 2015 13:46:17 +0000 Subject: [PATCH 0914/1077] Trying Pitzer lists again. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9802 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 19 ++++++++++++++++--- prep.cpp | 2 +- sit.cpp | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index ac1d2e23..e95c1b31 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -2,7 +2,7 @@ #include "phqalloc.h" #include "Exchange.h" #include "Solution.h" - +#define PITZER_LISTS #define PITZER /* ---------------------------------------------------------------------- */ @@ -762,19 +762,27 @@ C C SUBROUTINE TO CALUCLATE TEMPERATURE DEPENDENCE OF PITZER PARAMETER C */ - int i; LDBLE TR = 298.15; if (fabs(TK - OTEMP) < 0.001 && fabs(patm_x - OPRESS) < 0.1) return OK; DW0 = rho_0 = calc_rho_0(TK - 273.15, patm_x); VP = patm_x; +#if !defined(PITZER_LISTS) + int i; for (i = 0; i < count_pitz_param; i++) //for (size_t j = 0; j < param_list.size(); j++) { //int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } +#else + for (size_t j = 0; j < param_list.size(); j++) + { + int i = param_list[j]; + calc_pitz_param(pitz_params[i], TK, TR); + } +#endif calc_dielectrics(TK - 273.15, patm_x); OTEMP = TK; OPRESS = patm_x; @@ -847,6 +855,7 @@ calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) } return OK; } +#if !defined(PITZER_LISTS) /* ---------------------------------------------------------------------- */ int Phreeqc:: pitzer(void) @@ -1181,7 +1190,7 @@ pitzer(void) */ return (OK); } -#ifdef SKIP +#else /* ---------------------------------------------------------------------- */ int Phreeqc:: pitzer(void) @@ -2380,6 +2389,9 @@ model_pz(void) { full_pitzer = FALSE; } +#if defined(PITZER_LISTS) + pitzer_make_lists(); +#endif for (;;) { mb_gases(); @@ -2732,6 +2744,7 @@ pitzer_make_lists(void) anion_list.clear(); ion_list.clear(); param_list.clear(); + OTEMP = -100.0; for (int i = 0; i < 3 * count_s; i++) { IPRSNT[i] = FALSE; diff --git a/prep.cpp b/prep.cpp index d68058ff..e5125572 100644 --- a/prep.cpp +++ b/prep.cpp @@ -124,7 +124,7 @@ prep(void) error_msg("Program stopping due to input errors.", STOP); } if (sit_model) sit_make_lists(); - //if (pitzer_model) pitzer_make_lists(); + if (pitzer_model) pitzer_make_lists(); return (OK); } diff --git a/sit.cpp b/sit.cpp index 1222205f..2d3664bf 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1643,6 +1643,7 @@ sit_make_lists(void) anion_list.clear(); ion_list.clear(); param_list.clear(); + OTEMP = -100.0; for (int i = 0; i < 3 * count_s; i++) { sit_IPRSNT[i] = FALSE; From 7e2a34cc7d33dcc2436dee94477e9a11aa282a90 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 Jun 2015 15:32:12 +0000 Subject: [PATCH 0915/1077] Make sure MacInnis pitzer parameters are calculated. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9806 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 115 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 45 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index e95c1b31..18b67adc 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -771,9 +771,7 @@ C #if !defined(PITZER_LISTS) int i; for (i = 0; i < count_pitz_param; i++) - //for (size_t j = 0; j < param_list.size(); j++) { - //int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } #else @@ -782,6 +780,9 @@ C int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } + calc_pitz_param(mcb0, TK, TR); + calc_pitz_param(mcb1, TK, TR); + calc_pitz_param(mcc0, TK, TR); #endif calc_dielectrics(TK - 273.15, patm_x); OTEMP = TK; @@ -1227,6 +1228,7 @@ pitzer(void) C TRANSFER DATA FROM TO M C */ +#ifdef SKIP double log_min = log10(MIN_TOTAL); for (size_t j = 0; j < s_list.size(); j++) { @@ -1240,6 +1242,7 @@ pitzer(void) M[i] = 0.0; } } +#endif #ifdef SKIP for (i = 0; i < 3 * count_s; i++) { @@ -1256,6 +1259,21 @@ pitzer(void) } } #endif + for (size_t j = 0; j < s_list.size(); j++) + { + i = s_list[j]; + IPRSNT[i] = FALSE; + M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) + { + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + M[i] = under(spec[i]->lm); + if (M[i] > MIN_TOTAL) + IPRSNT[i] = TRUE; + } + } if (ICON == TRUE) { IPRSNT[IC] = TRUE; @@ -1280,15 +1298,17 @@ pitzer(void) XX = XX + M[i] * fabs(spec[i]->z); OSUM = OSUM + M[i]; } - //for (i = 0; i < 2 * count_s + count_anions; i++) - //{ - // LGAMMA[i] = 0.0; - // if (IPRSNT[i] == TRUE) - // { - // XX = XX + M[i] * fabs(spec[i]->z); - // OSUM = OSUM + M[i]; - // } - //} +#ifdef SKIP + for (i = 0; i < 2 * count_s + count_anions; i++) + { + LGAMMA[i] = 0.0; + if (IPRSNT[i] == TRUE) + { + XX = XX + M[i] * fabs(spec[i]->z); + OSUM = OSUM + M[i]; + } + } +#endif /* C C EQUATION (8) @@ -1476,7 +1496,6 @@ pitzer(void) /* * Add F and CSUM terms to LGAMMA */ - for (size_t j = 0; j < ion_list.size(); j++) { int i = ion_list[j]; @@ -1484,22 +1503,24 @@ pitzer(void) F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; } - //for (i = 0; i < count_cations; i++) - //{ - // if (!IPRSNT[i]) - // continue; - // z0 = fabs(spec[i]->z); - // F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); - // LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; - //} - //for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) - //{ - // if (!IPRSNT[i]) - // continue; - // z0 = fabs(spec[i]->z); - // F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); - // LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; - //} +#ifdef SKIP + for (i = 0; i < count_cations; i++) + { + if (!IPRSNT[i]) + continue; + z0 = fabs(spec[i]->z); + F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; + } + for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) + { + if (!IPRSNT[i]) + continue; + z0 = fabs(spec[i]->z); + F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); + LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; + } +#endif /* C C CONVERT TO MACINNES CONVENTION @@ -1518,13 +1539,15 @@ pitzer(void) int i = s_list[j]; LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; } - //for (i = 0; i < 2 * count_s + count_anions; i++) - //{ - // if (IPRSNT[i] == TRUE) - // { - // LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; - // } - //} +#ifdef SKIP + for (i = 0; i < 2 * count_s + count_anions; i++) + { + if (IPRSNT[i] == TRUE) + { + LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; + } + } +#endif } COSMOT = 1.0 + 2.0 * OSMOT / OSUM; @@ -1545,16 +1568,18 @@ pitzer(void) int i = s_list[j]; spec[i]->lg_pitzer = LGAMMA[i] * CONV; } - //for (i = 0; i < 2 * count_s + count_anions; i++) - //{ - // if (IPRSNT[i] == FALSE) - // continue; - // /*spec[i]->lg=LGAMMA[i]*CONV; */ - // spec[i]->lg_pitzer = LGAMMA[i] * CONV; - // /* - // output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); - // */ - //} +#ifdef SKIP + for (i = 0; i < 2 * count_s + count_anions; i++) + { + if (IPRSNT[i] == FALSE) + continue; + /*spec[i]->lg=LGAMMA[i]*CONV; */ + spec[i]->lg_pitzer = LGAMMA[i] * CONV; + /* + output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); + */ + } +#endif /* output_msg(sformatf( "OSUM: %e\n", OSUM)); output_msg(sformatf( "OSMOT: %e\n", OSMOT)); From b9b841411a7b13aea3109405b2fee5157d0457f0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 Jun 2015 15:58:10 +0000 Subject: [PATCH 0916/1077] Tweaking lists. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9808 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 81 +++++++++++++++++++++++++++++++++--------------------- sit.cpp | 75 +++++++++++++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 59 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index 18b67adc..d2fb8d93 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -2770,44 +2770,63 @@ pitzer_make_lists(void) ion_list.clear(); param_list.clear(); OTEMP = -100.0; - for (int i = 0; i < 3 * count_s; i++) + for (int j = 0; j < 3; j++) { - IPRSNT[i] = FALSE; - M[i] = 0.0; + int min, max; + switch (j) + { + case 0: + min = 0; + max = count_cations; + break; + case 1: + min = count_s; + max = count_s + count_neutrals; + break; + case 2: + min = 2*count_s; + max = 2*count_s + count_anions; + break; + } + for (int i = min; i < max; i++) + { + IPRSNT[i] = FALSE; + M[i] = 0.0; if ((spec[i] != NULL && spec[i]->in == TRUE) || (ICON == TRUE && i == IC)) - { - if (spec[i]->type == EX || - spec[i]->type == SURF || spec[i]->type == SURF_PSI) - continue; - IPRSNT[i] = TRUE; - s_list.push_back(i); - if (i < count_s) { - cation_list.push_back(i); - } - if (i >= count_s && i < 2*count_s) - { - neutral_list.push_back(i); - } - if (i >= 2*count_s) - { - anion_list.push_back(i); - } - if (i < count_s || i >= 2*count_s) - { - ion_list.push_back(i); - } - if (spec[i]->lm > log_min) - { - M[i] = under(spec[i]->lm); + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + IPRSNT[i] = TRUE; + s_list.push_back(i); + if (i < count_s) + { + cation_list.push_back(i); + } + if (i >= count_s && i < 2*count_s) + { + neutral_list.push_back(i); + } + if (i >= 2*count_s) + { + anion_list.push_back(i); + } + if (i < count_s || i >= 2*count_s) + { + ion_list.push_back(i); + } + if (spec[i]->lm > log_min) + { + M[i] = under(spec[i]->lm); + } } } } - //if (ICON == TRUE) - //{ - // IPRSNT[IC] = TRUE; - //} + if (ICON == TRUE) + { + IPRSNT[IC] = TRUE; + } for (int i = 0; i < count_pitz_param; i++) { /* diff --git a/sit.cpp b/sit.cpp index 2d3664bf..f10f9456 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1643,37 +1643,56 @@ sit_make_lists(void) anion_list.clear(); ion_list.clear(); param_list.clear(); - OTEMP = -100.0; - for (int i = 0; i < 3 * count_s; i++) + OTEMP = -100.0; + for (int j = 0; j < 3; j++) { - sit_IPRSNT[i] = FALSE; - sit_M[i] = 0.0; - if (spec[i] != NULL && spec[i]->in == TRUE) + int min, max; + switch (j) { - if (spec[i]->type == EX || - spec[i]->type == SURF || spec[i]->type == SURF_PSI) - continue; - sit_IPRSNT[i] = TRUE; - s_list.push_back(i); - if (i < count_s) + case 0: + min = 0; + max = count_cations; + break; + case 1: + min = count_s; + max = count_s + count_neutrals; + break; + case 2: + min = 2*count_s; + max = 2*count_s + count_anions; + break; + } + for (int i = min; i < max; i++) + { + sit_IPRSNT[i] = FALSE; + sit_M[i] = 0.0; + if (spec[i] != NULL && spec[i]->in == TRUE) { - cation_list.push_back(i); - } - if (i >= count_s && i < 2*count_s) - { - neutral_list.push_back(i); - } - if (i >= 2*count_s) - { - anion_list.push_back(i); - } - if (i < count_s || i >= 2*count_s) - { - ion_list.push_back(i); - } - if (spec[i]->lm > log_min) - { - sit_M[i] = under(spec[i]->lm); + if (spec[i]->type == EX || + spec[i]->type == SURF || spec[i]->type == SURF_PSI) + continue; + sit_IPRSNT[i] = TRUE; + s_list.push_back(i); + if (i < count_s) + { + cation_list.push_back(i); + } + if (i >= count_s && i < 2*count_s) + { + neutral_list.push_back(i); + } + if (i >= 2*count_s) + { + anion_list.push_back(i); + } + if (i < count_s || i >= 2*count_s) + { + ion_list.push_back(i); + } + if (spec[i]->lm > log_min) + { + sit_M[i] = under(spec[i]->lm); + } } } } From e5a96004470de379297123e3682b5612f15cd3e7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 9 Jun 2015 16:16:20 +0000 Subject: [PATCH 0917/1077] Removed dead code from pitzer Make lists only in prep. Fixed bug, needed to use sit_count_cations, etc. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9809 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 254 ++--------------------------------------------------- sit.cpp | 8 +- 2 files changed, 9 insertions(+), 253 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index d2fb8d93..617090b3 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1216,10 +1216,6 @@ pitzer(void) CONV = 1.0 / log(10.0); XX = 0.0; OSUM = 0.0; - /*n - I = *I_X; - TK = *TK_X; - */ I = mu_x; TK = tk_x; /* DH_AB(TK, &A, &B); */ @@ -1228,37 +1224,6 @@ pitzer(void) C TRANSFER DATA FROM TO M C */ -#ifdef SKIP - double log_min = log10(MIN_TOTAL); - for (size_t j = 0; j < s_list.size(); j++) - { - i = s_list[j]; - if (spec[i]->lm > log_min) - { - M[i] = under(spec[i]->lm); - } - else - { - M[i] = 0.0; - } - } -#endif -#ifdef SKIP - for (i = 0; i < 3 * count_s; i++) - { - IPRSNT[i] = FALSE; - M[i] = 0.0; - if (spec[i] != NULL && spec[i]->in == TRUE) - { - if (spec[i]->type == EX || - spec[i]->type == SURF || spec[i]->type == SURF_PSI) - continue; - M[i] = under(spec[i]->lm); - if (M[i] > MIN_TOTAL) - IPRSNT[i] = TRUE; - } - } -#endif for (size_t j = 0; j < s_list.size(); j++) { i = s_list[j]; @@ -1278,13 +1243,6 @@ pitzer(void) { IPRSNT[IC] = TRUE; } - /* - ICON = 0; - M[1] = 1.40070736; - M[4] = 2.52131086E-05; - M[140] = 4.59985435E-09; - */ - /* C C COMPUTE PITZER COEFFICIENTS' TEMPERATURE DEPENDENCE @@ -1298,17 +1256,6 @@ pitzer(void) XX = XX + M[i] * fabs(spec[i]->z); OSUM = OSUM + M[i]; } -#ifdef SKIP - for (i = 0; i < 2 * count_s + count_anions; i++) - { - LGAMMA[i] = 0.0; - if (IPRSNT[i] == TRUE) - { - XX = XX + M[i] * fabs(spec[i]->z); - OSUM = OSUM + M[i]; - } - } -#endif /* C C EQUATION (8) @@ -1338,9 +1285,6 @@ pitzer(void) } XXX = 2.0 * DI; XXX = (1.0 - (1.0 + XXX - XXX * XXX * 0.5) * exp(-XXX)) / (XXX * XXX); - /*GAMCLM=F+I*2.0e0*(BCX(1,IK,IC)+BCX(2,IK,IC)*XXX)+1.5e0*BCX(4,IK,IC)*I*I; */ - /*GAMCLM=F+I*2.0e0*(mcb0->U.b0 + mcb1->U.b1*XXX) + 1.5e0*mcc0->U.c0*I*I; */ - /*GAMCLM = F + I * 2.0e0 * (mcb0->p + mcb1->p * XXX) + 1.5e0 * mcc0->p * I * I; */ GAMCLM = F1; if (mcb0 != NULL) GAMCLM += I * 2.0 * mcb0->p; @@ -1367,14 +1311,11 @@ pitzer(void) /* * Sums for F, LGAMMA, and OSMOT */ - //for (i = 0; i < count_pitz_param; i++) for (size_t j = 0; j < param_list.size(); j++) { int i = param_list[j]; i0 = pitz_params[i]->ispec[0]; i1 = pitz_params[i]->ispec[1]; - //if (IPRSNT[i0] == FALSE || IPRSNT[i1] == FALSE) - // continue; z0 = spec[i0]->z; z1 = spec[i1]->z; param = pitz_params[i]->p; @@ -1431,12 +1372,6 @@ pitzer(void) LGAMMA[i0] += 2.0 * M[i1] * etheta; LGAMMA[i1] += 2.0 * M[i0] * etheta; OSMOT += M[i0] * M[i1] * (etheta + I * ethetap); - /* - F += M[i0]*M[i1]*ETHETAP(z0, z1, I); - LGAMMA[i0] += 2.0*M[i1]*(ETHETA(z0, z1, I) ); - LGAMMA[i1] += 2.0*M[i0]*(ETHETA(z0, z1, I) ); - OSMOT += M[i0]*M[i1]*(ETHETA(z0, z1, I) + I*ETHETAP(z0, z1, I) ); - */ } break; case TYPE_PSI: @@ -1488,9 +1423,9 @@ pitzer(void) error_msg("TYPE_Other in pitz_param list.", STOP); break; } - F += F_var; - F1 += F_var; - F2 += F_var; + F += F_var; + F1 += F_var; + F2 += F_var; } /* @@ -1503,24 +1438,6 @@ pitzer(void) F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; } -#ifdef SKIP - for (i = 0; i < count_cations; i++) - { - if (!IPRSNT[i]) - continue; - z0 = fabs(spec[i]->z); - F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); - LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; - } - for (i = 2 * count_s; i < 2 * count_s + count_anions; i++) - { - if (!IPRSNT[i]) - continue; - z0 = fabs(spec[i]->z); - F_var = (z0 == 1 ? F1 : (z0 == 2.0 ? F2 : F)); - LGAMMA[i] += z0 * z0 * F_var + z0 * CSUM; - } -#endif /* C C CONVERT TO MACINNES CONVENTION @@ -1539,15 +1456,6 @@ pitzer(void) int i = s_list[j]; LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; } -#ifdef SKIP - for (i = 0; i < 2 * count_s + count_anions; i++) - { - if (IPRSNT[i] == TRUE) - { - LGAMMA[i] = LGAMMA[i] + spec[i]->z * PHIMAC; - } - } -#endif } COSMOT = 1.0 + 2.0 * OSMOT / OSUM; @@ -1568,25 +1476,6 @@ pitzer(void) int i = s_list[j]; spec[i]->lg_pitzer = LGAMMA[i] * CONV; } -#ifdef SKIP - for (i = 0; i < 2 * count_s + count_anions; i++) - { - if (IPRSNT[i] == FALSE) - continue; - /*spec[i]->lg=LGAMMA[i]*CONV; */ - spec[i]->lg_pitzer = LGAMMA[i] * CONV; - /* - output_msg(sformatf( "%d %s:\t%e\t%e\t%e\t%e \n", i, spec[i]->name, M[i], spec[i]->la, spec[i]->lg_pitzer, spec[i]->lg)); - */ - } -#endif - /* - output_msg(sformatf( "OSUM: %e\n", OSUM)); - output_msg(sformatf( "OSMOT: %e\n", OSMOT)); - output_msg(sformatf( "COSMOT: %e\n", COSMOT)); - output_msg(sformatf( "F: %e\n", F)); - output_msg(sformatf( "AW: %e\n", AW)); - */ /* *I_X = I; *COSMOT_X = COSMOT; @@ -1594,104 +1483,6 @@ pitzer(void) return (OK); } #endif -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -JAY(LDBLE X) -/* ---------------------------------------------------------------------- */ -/* -C -C FUNCTION TO CALCULATE JAY AND JPRIME -C -C J0 AND J1, USED IN CALCULATION OF ETHETA AND ETHEAP -C -*/ -{ - LDBLE JAY; - BDK(X); - JAY = X / 4.0e0 - 1.0e0 + 0.5e0 * (BK[0] - BK[2]); - return JAY; -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -JPRIME(LDBLE L_Y) -/* ---------------------------------------------------------------------- */ -{ - LDBLE L_DZ; - BDK(L_Y); - if (L_Y > 1.0e0) - { - L_DZ = -4.0e0 * pow(L_Y, (LDBLE) -1.1e0) / 9.0e0; - } - else - { - L_DZ = 0.8e0 * pow(L_Y, (LDBLE) -0.8e0); - } - return (L_Y * (.25e0 + L_DZ * (DK[0] - DK[2]) / 2.0e0)); -} - -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -BDK(LDBLE X) -/* ---------------------------------------------------------------------- */ -/* -C -C NUMERICAL APPROXIMATION TO THE INTEGRALS IN THE EXPRESSIONS FOR J0 -C AND J1. CHEBYSHEV APPROXIMATION IS USED. THE CONSTANTS 'AK' ARE -C DEFINED IN BLOCK COMMON. -C -*/ -/* -C -C AK IS USED TO CALCULATE HIGHER ORDER ELECTROSTATIC TERMS IN -C SUBROUTINE PITZER -C -*/ -{ - LDBLE AKX[42] = { - 1.925154014814667e0, -.060076477753119e0, -.029779077456514e0, - -.007299499690937e0, 0.000388260636404e0, 0.000636874599598e0, - 0.000036583601823e0, -.000045036975204e0, -.000004537895710e0, - 0.000002937706971e0, 0.000000396566462e0, -.000000202099617e0, - -.000000025267769e0, 0.000000013522610e0, 0.000000001229405e0, - -.000000000821969e0, -.000000000050847e0, 0.000000000046333e0, - 0.000000000001943e0, -.000000000002563e0, -.000000000010991e0, - 0.628023320520852e0, 0.462762985338493e0, 0.150044637187895e0, - -.028796057604906e0, -.036552745910311e0, -.001668087945272e0, - 0.006519840398744e0, 0.001130378079086e0, -.000887171310131e0, - -.000242107641309e0, 0.000087294451594e0, 0.000034682122751e0, - -.000004583768938e0, -.000003548684306e0, -.000000250453880e0, - 0.000000216991779e0, 0.000000080779570e0, 0.000000004558555e0, - -.000000006944757e0, -.000000002849257e0, 0.000000000237816e0 - }; -/* - LDBLE PRECISION AK, BK, DK - COMMON / MX8 / AK(0:20,2),BK(0:22),DK(0:22) -*/ - LDBLE *AK; - LDBLE L_Z; - int i; - - if (X <= 1.0e0) - { - L_Z = 4.0e0 * pow(X, (LDBLE) 0.2e0) - 2.0e0; - AK = &AKX[0]; - } - else - { - L_Z = 40.0e0 * pow(X, (LDBLE) -1.0e-1) / 9.0e0 - 22.0e0 / 9.0e0; - AK = &AKX[21]; - } - for (i = 20; i >= 0; i--) - { - BK[i] = L_Z * BK[i + 1] - BK[i + 2] + AK[i]; - DK[i] = BK[i + 1] + L_Z * DK[i + 1] - DK[i + 2]; - } - return OK; -} -#endif - /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: G(LDBLE L_Y) @@ -1719,47 +1510,12 @@ GP(LDBLE L_Y) } return d; } -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap) -/* ---------------------------------------------------------------------- */ -{ - LDBLE XCON, ZZ; - LDBLE XJK, XJJ, XKK; - - *etheta = 0.0; - *ethetap = 0.0; - if (ZJ == ZK) - return (OK); - XCON = 6.0e0 * A0 * sqrt(I); - ZZ = ZJ * ZK; -/* -C -C NEXT 3 ARE EQUATION (A1) -C -*/ - XJK = XCON * ZZ; - XJJ = XCON * ZJ * ZJ; - XKK = XCON * ZK * ZK; -/* -C -C EQUATION (A3) -C -*/ - *etheta = - ZZ * (JAY(XJK) - JAY(XJJ) / 2.0e0 - JAY(XKK) / 2.0e0) / (4.0e0 * I); - *ethetap = - ZZ * (JPRIME(XJK) - JPRIME(XJJ) / 2.0e0 - - JPRIME(XKK) / 2.0e0) / (8.0e0 * I * I) - *etheta / I; - return (OK); -} -#endif /* ---------------------------------------------------------------------- */ int Phreeqc:: ETHETAS(LDBLE ZJ, LDBLE ZK, LDBLE I, LDBLE * etheta, LDBLE * ethetap) /* ---------------------------------------------------------------------- */ { + /* Revised ETHETAS code thanks to Wouter Falkena and the MoReS team, June, 2015 */ *etheta = 0.0; *ethetap = 0.0; @@ -2415,7 +2171,7 @@ model_pz(void) full_pitzer = FALSE; } #if defined(PITZER_LISTS) - pitzer_make_lists(); + //pitzer_make_lists(); #endif for (;;) { diff --git a/sit.cpp b/sit.cpp index f10f9456..d84186b2 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1212,7 +1212,7 @@ model_sit(void) { full_pitzer = FALSE; } - sit_make_lists(); + //sit_make_lists(); for (;;) { mb_gases(); @@ -1651,15 +1651,15 @@ sit_make_lists(void) { case 0: min = 0; - max = count_cations; + max = sit_count_cations; break; case 1: min = count_s; - max = count_s + count_neutrals; + max = count_s + sit_count_neutrals; break; case 2: min = 2*count_s; - max = 2*count_s + count_anions; + max = 2*count_s + sit_count_anions; break; } for (int i = min; i < max; i++) From 37b8b3f49ec062bb88818ee33625f07e403e94b1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 25 Jun 2015 22:44:39 +0000 Subject: [PATCH 0918/1077] Have surface species data saved in the charge class. Now need to expose it with PhreeqcRM git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9896 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SurfaceCharge.h | 2 ++ mainsubs.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 3cb7b9ad..a3a46265 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -103,6 +103,7 @@ public: void Set_diffuse_layer_totals(cxxNameDouble & nd) {this->diffuse_layer_totals = nd;} std::map &Get_g_map(void) {return g_map;} void Set_g_map(std::map & t) {g_map = t;} + std::map & Get_dl_species_map(void) {return this->dl_species_map;} protected: std::string name; @@ -117,6 +118,7 @@ protected: LDBLE sigma0, sigma1, sigma2, sigmaddl; std::map g_map; const static std::vector < std::string > vopts; + std::map dl_species_map; }; #endif // !defined(SURFACECHARGE_H_INCLUDED) diff --git a/mainsubs.cpp b/mainsubs.cpp index d55e5763..df0b05af 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1534,7 +1534,7 @@ xsolution_save(int n_user) */ temp_solution.Get_totals()[master[i]->elt->name] = master[i]->total; } - if (pitzer_model == TRUE || sit_model == TRUE) + if (pitzer_model == TRUE || sit_model == TRUE || this->save_species) { for (int j = 0; j < count_s_x; j++) { @@ -1603,7 +1603,7 @@ xsolution_save(int n_user) { temp_solution.Get_species_map()[s_x[i]->number] = s_x[i]->moles / temp_solution.Get_soln_vol(); } - } + } } /* * Save solution @@ -1731,6 +1731,28 @@ xsurface_save(int n_user) } } } + if (!(dl_type_x == cxxSurface::NO_DL)) + { + cxxSurface *surface_ptr = &temp_surface; + for (size_t i = 0; i < surface_ptr->Get_surface_charges().size(); i++) + { + cxxSurfaceCharge & charge_ref = surface_ptr->Get_surface_charges()[i]; + double mass_water_surface = charge_ref.Get_mass_water(); + for (int j = 0; j < count_s_x; j++) + { + if (s_x[j]->type > HPLUS) + continue; + double molality = under(s_x[j]->lm); + double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); + double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; + charge_ref.Get_dl_species_map()[s_x[j]->number] = c; + } + } + } + /* * Finish up */ From f15d9155fca063b79c6481fe64e328f6ae4d73e0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 29 Jun 2015 18:23:12 +0000 Subject: [PATCH 0919/1077] GetSpeciesLogGammas GetSurfaceDiffuseLayerConcentrations GetSurfaceDiffuseLayerNames Roughed in new methods. They appear to work but not tested much. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9907 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++- Solution.h | 2 ++ SurfaceCharge.cxx | 44 ++++++++++++++++++++++++++++++++++++- mainsubs.cpp | 11 +++++++++- 4 files changed, 109 insertions(+), 3 deletions(-) diff --git a/Solution.cxx b/Solution.cxx index add3b449..aa91fa6d 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -79,6 +79,7 @@ cxxSolution::operator =(const cxxSolution &rhs) this->species_gamma = rhs.species_gamma; this->isotopes = rhs.isotopes; this->species_map = rhs.species_map; + this->log_gamma_map = rhs.log_gamma_map; if (this->initial_data) delete initial_data; if (rhs.initial_data != NULL) @@ -308,6 +309,18 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con } } + // log_gamma_map + if (log_gamma_map.size() > 0) + { + s_oss << indent1; + s_oss << "-log_gamma_map" << "\n"; + std::map::const_iterator it = this->log_gamma_map.begin(); + for ( ; it != log_gamma_map.end(); it++) + { + s_oss << indent2; + s_oss << it->first << " " << it->second << "\n"; + } + } return; } @@ -957,6 +970,32 @@ cxxSolution::read_raw(CParser & parser, bool check) opt_save = 24; } break; + case 25: // log_gamma_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 concentration.", + PHRQ_io::OT_CONTINUE); + } + this->log_gamma_map[s_num] = d; + } + } + opt_save = 25; + } + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -1342,6 +1381,19 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->species_map[it->first] = it->second; } } + // Add gammas + std::map::const_iterator git = addee.log_gamma_map.begin(); + for ( ; git != addee.log_gamma_map.end(); git++) + { + if (this->log_gamma_map.find(git->first) != this->log_gamma_map.end()) + { + this->log_gamma_map[git->first] = this->log_gamma_map[git->first] * f1 + git->second * f2; + } + else + { + this->log_gamma_map[git->first] = it->second; + } + } } } @@ -1494,6 +1546,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("density"), // 21 std::vector< std::string >::value_type("pressure"), // 22 std::vector< std::string >::value_type("soln_vol"), // 23 - std::vector< std::string >::value_type("species_map") // 24 + std::vector< std::string >::value_type("species_map"), // 24 + std::vector< std::string >::value_type("log_gamma_map") // 25 }; 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/Solution.h b/Solution.h index 580950d3..a2a48c4c 100644 --- a/Solution.h +++ b/Solution.h @@ -63,6 +63,7 @@ class cxxSolution:public cxxNumKeyword cxxNameDouble & Get_master_activity(void) {return this->master_activity;} 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 < 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;} @@ -134,6 +135,7 @@ class cxxSolution:public cxxNumKeyword cxxISolution *initial_data; const static std::vector < std::string > vopts; std::map species_map; + std::map log_gamma_map; }; #endif // !defined(SOLUTION_H_INCLUDED) diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 142ab454..6f52a563 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -98,6 +98,20 @@ cxxSurfaceCharge::dump_raw(std::ostream & s_oss, unsigned int indent) const s_oss << "-diffuse_layer_totals" << "\n"; this->diffuse_layer_totals.dump_raw(s_oss, indent + 1); + // DL species + //s_oss << indent0; + //s_oss << "-diffuse_layer_species" << "\n"; + if (dl_species_map.size() > 0) + { + s_oss << indent0; + s_oss << "-diffuse_layer_species" << "\n"; + std::map::const_iterator it = this->dl_species_map.begin(); + for ( ; it != dl_species_map.end(); it++) + { + s_oss << indent1; + s_oss << it->first << " " << it->second << "\n"; + } + } s_oss << indent0 << "# Surface workspace variables #\n"; s_oss << indent0 << "-sigma0 " << this->sigma0 << "\n"; s_oss << indent0 << "-sigma1 " << this->sigma1 << "\n"; @@ -320,6 +334,33 @@ cxxSurfaceCharge::read_raw(CParser & parser, bool check) else git->second.Set_psi_to_z(dummy); } + break; + case 16: // dl_species_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 concentration.", + PHRQ_io::OT_CONTINUE); + } + this->dl_species_map[s_num] = d; + } + } + opt_save = 16; + + + break; } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) @@ -435,6 +476,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("sigma1"), // 12 std::vector< std::string >::value_type("sigma2"), // 13 std::vector< std::string >::value_type("sigmaddl"), // 14 - std::vector< std::string >::value_type("g_map") // 15 + std::vector< std::string >::value_type("g_map"), // 15 + std::vector< std::string >::value_type("diffuse_layer_species") // 16 }; const std::vector< std::string > cxxSurfaceCharge::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file diff --git a/mainsubs.cpp b/mainsubs.cpp index df0b05af..df548f8c 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1534,7 +1534,7 @@ xsolution_save(int n_user) */ temp_solution.Get_totals()[master[i]->elt->name] = master[i]->total; } - if (pitzer_model == TRUE || sit_model == TRUE || this->save_species) + if (pitzer_model == TRUE || sit_model == TRUE) { for (int j = 0; j < count_s_x; j++) { @@ -1604,6 +1604,15 @@ xsolution_save(int n_user) temp_solution.Get_species_map()[s_x[i]->number] = s_x[i]->moles / temp_solution.Get_soln_vol(); } } + // saves gamma + temp_solution.Get_log_gamma_map().clear(); + for (int i = 0; i < this->count_s_x; i++) + { + if (s_x[i]->type <= H2O) + { + temp_solution.Get_log_gamma_map()[s_x[i]->number] = s_x[i]->lg; + } + } } /* * Save solution From 49ba8bca71018de2714353556b9f59893fd84cfc Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Jun 2015 17:06:53 +0000 Subject: [PATCH 0920/1077] Working on edl for PHREEQCRM Adding edl_species for PHREEQC. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9915 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++- PBasic.h | 3 +- Phreeqc.h | 2 + basicsubs.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++ mainsubs.cpp | 9 +++- 5 files changed, 245 insertions(+), 3 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index e5a4aa6a..0c62276e 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1445,6 +1445,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("SURF"); break; + case tokedl_species: + output_msg("EDL_SPECIES"); + break; + case tokstep_no: output_msg("STEP_NO"); break; @@ -2677,6 +2681,107 @@ factor(struct LOC_exec * LINK) } break; + case tokedl_species: + { + double area, thickness; + require(toklp, LINK); + const char *surf_name = stringfactor(STR1, LINK); + require(tokcomma, LINK); + // variable for number of species + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || !count_varrec || count_varrec->stringvar != 0) + { + snerr(": can`t find variable"); + exit(4); + } + require(tokcomma, LINK); + // variable for species names + LINK->t = LINK->t->next; + require(tokcomma, LINK); + names_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || !names_varrec || names_varrec->stringvar != 1) + { + snerr(": can`t find name of species"); + exit(4); + } + // variable for species concentrations + LINK->t = LINK->t->next; + require(tokcomma, LINK); + moles_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) + snerr(": can`t find concentrations of species"); + LINK->t = LINK->t->next; + // variable for area + LINK->t = LINK->t->next; + require(tokcomma, LINK); + varrec *area_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || area_varrec->stringvar != 0) + snerr(": can`t find area varaiable"); + LINK->t = LINK->t->next; + // varaiable for thickness + LINK->t = LINK->t->next; + require(tokcomma, LINK); + varrec *thickness_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || thickness_varrec->stringvar != 0) + snerr(": can`t find thickness variable"); + LINK->t = LINK->t->next; + require(tokrp, LINK); + + free_dim_stringvar(names_varrec); + PhreeqcPtr->free_check_null(moles_varrec->UU.U0.arr); + moles_varrec->UU.U0.arr = NULL; + + // Call subroutine + if (parse_all) + { + PhreeqcPtr->sys_tot = 0; + PhreeqcPtr->count_sys = 1000; + int count_sys = PhreeqcPtr->count_sys; + names_arg = (char **) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); + if (names_arg == NULL) + { + PhreeqcPtr->malloc_error(); + exit(4); + } + moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); + if (moles_arg == NULL) + { + PhreeqcPtr->malloc_error(); + exit(4); + } + names_arg[0] = NULL; + moles_arg[0] = 0; + count_species = (LDBLE) count_sys; + n.UU.val = 0; + } + else + { + //n.UU.val = PhreeqcPtr->system_total(elt_name, &count_species, &(names_arg), + // &(types_arg), &(moles_arg)); + n.UU.val = PhreeqcPtr->edl_species(surf_name, &count_species, &(names_arg), &(moles_arg), &area, &thickness); + } + /* + * fill in varrec structures + */ + *count_varrec->UU.U0.val = count_species; + names_varrec->UU.U1.sarr = names_arg; + moles_varrec->UU.U0.arr = moles_arg; + *area_varrec->UU.U0.val = area; + *thickness_varrec->UU.U0.val = thickness; + + for (i = 0; i < maxdims; i++) + { + names_varrec->dims[i] = 0; + moles_varrec->dims[i] = 0; + } + names_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + moles_varrec->dims[0] = (long) (*count_varrec->UU.U0.val) + 1; + names_varrec->numdims = 1; + moles_varrec->numdims = 1; + } + break; + case toklist_s_s: { /* list_s_s("calcite", count, name$, moles) */ @@ -6970,7 +7075,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("equiv_frac", PBasic::tokeq_frac), std::map::value_type("callback", PBasic::tokcallback), std::map::value_type("diff_c", PBasic::tokdiff_c), - std::map::value_type("sa_declercq", PBasic::toksa_declercq) + std::map::value_type("sa_declercq", PBasic::toksa_declercq), + std::map::value_type("edl_species", PBasic::tokedl_species) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index cadcef8f..6f8626de 100644 --- a/PBasic.h +++ b/PBasic.h @@ -323,7 +323,8 @@ public: tokequiv_frac, tokcallback, tokdiff_c, - toksa_declercq + toksa_declercq, + tokedl_species }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 829afe43..9b261cd3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -111,6 +111,8 @@ public: LDBLE calc_logk_s(const char *name); LDBLE calc_surface_charge(const char *surface_name); LDBLE diff_layer_total(const char *total_name, const char *surface_name); + LDBLE edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, LDBLE * area, LDBLE * thickness); + int get_edl_species(cxxSurfaceCharge & charge_ref); LDBLE equi_phase(const char *phase_name); LDBLE equi_phase_delta(const char *phase_name); LDBLE equivalent_fraction(const char *name, LDBLE *eq, std::string &elt_name); diff --git a/basicsubs.cpp b/basicsubs.cpp index 89713680..10a93ea3 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2581,7 +2581,133 @@ total_mole(const char *total_name) } return (t); } + /* ---------------------------------------------------------------------- */ +int Phreeqc:: +get_edl_species(cxxSurfaceCharge & charge_ref) +/* ---------------------------------------------------------------------- */ +{ + + double mass_water_surface = charge_ref.Get_mass_water(); + space((void **) ((void *) &sys), count_s_x, &max_sys, sizeof(struct system_species)); + count_sys = 0; + for (int j = 0; j < count_s_x; j++) + { + if (s_x[j]->type == H2O) + { + sys[count_sys].name = string_duplicate(s_x[j]->name); + sys[count_sys].moles = mass_water_surface / gfw_water; + sys_tot += sys[count_sys].moles; + } + else if (s_x[j]->type < H2O) + { + double molality = under(s_x[j]->lm); + double moles_excess = mass_water_aq_x * molality * charge_ref.Get_g_map()[s_x[j]->z].Get_g(); + double moles_surface = mass_water_surface * molality + moles_excess; + sys[count_sys].name = string_duplicate(s_x[j]->name); + sys[count_sys].moles = moles_surface; + sys_tot += sys[count_sys].moles; + count_sys++; +#ifdef SKIP + double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); + double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; + charge_ref.Get_dl_species_map()[s_x[j]->number] = c; +#endif + } + else + { + continue; + } + } +#ifdef SKIP +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; +/* + * find total moles in aq, surface, and exchange + */ + + for (i = 0; i < count_s_x; i++) + { + //if (s_x[i]->type != AQ) + if (s_x[i]->type > HPLUS) + continue; + sys[count_sys].name = string_duplicate(s_x[i]->name); + sys[count_sys].moles = s_x[i]->moles; + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("aq"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + +#endif + return (OK); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, LDBLE * area, LDBLE * thickness) +/* ---------------------------------------------------------------------- */ +{ +/* + * Provides total moles in system and lists of species/phases in sort order + */ + int i; + sys_tot = 0; + count_sys = 0; + max_sys = 100; + space((void **) ((void *) &sys), INIT, &max_sys, + sizeof(struct system_species)); + if (!(dl_type_x == cxxSurface::NO_DL)) + { + cxxSurface *surface_ptr = use.Get_surface_ptr(); + for (size_t i = 0; i < surface_ptr->Get_surface_charges().size(); i++) + { + cxxSurfaceCharge & charge_ref = surface_ptr->Get_surface_charges()[i]; + if (strcmp(charge_ref.Get_name().c_str(), surf_name) == 0) + { + get_edl_species(charge_ref); + *area = charge_ref.Get_specific_area() * charge_ref.Get_grams(); + *thickness = surface_ptr->Get_thickness(); + break; + } + } + } + /* + * Sort system species + */ + if (count_sys > 1) + { + qsort(sys, (size_t) count_sys, + (size_t) sizeof(struct system_species), system_species_compare); + } + /* + * malloc space + */ + *names = (char **) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(char *)); + if (names == NULL) + malloc_error(); + *moles = (LDBLE *) PHRQ_malloc((size_t) (count_sys + 1) * sizeof(LDBLE)); + if (moles == NULL) + malloc_error(); + + (*names)[0] = NULL; + (*moles)[0] = 0; + for (i = 0; i < count_sys; i++) + { + (*names)[i + 1] = sys[i].name; + (*moles)[i + 1] = sys[i].moles; + } + *count = (LDBLE) count_sys; + + PHRQ_free(sys); + return (sys_tot); +} + /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles) diff --git a/mainsubs.cpp b/mainsubs.cpp index df548f8c..a685a78a 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1749,16 +1749,23 @@ xsurface_save(int n_user) double mass_water_surface = charge_ref.Get_mass_water(); for (int j = 0; j < count_s_x; j++) { - if (s_x[j]->type > HPLUS) + if (s_x[j]->type > H2O) continue; double molality = under(s_x[j]->lm); + double moles_excess = mass_water_aq_x * molality * charge_ref.Get_g_map()[s_x[j]->z].Get_g(); + double moles_surface = mass_water_surface * molality + moles_excess; + charge_ref.Get_dl_species_map()[s_x[j]->number] = moles_surface/mass_water_surface; +#ifdef SKIP double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + mass_water_surface / mass_water_aq_x * (s_x[j]->erm_ddl - 1)); double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; charge_ref.Get_dl_species_map()[s_x[j]->number] = c; +#endif } + //charge_ref.Get_dl_species_map()[s_h2o->number] = 0.0; + charge_ref.Get_dl_species_map()[s_h2o->number] = 1.0/gfw_water; } } From e7915af7ac4961b4dde62805de80adac70c0a11f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 30 Jun 2015 18:01:55 +0000 Subject: [PATCH 0921/1077] Test case edl_species tests the function. Works, but maybe questions on thickness for Debye length calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9916 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 14 +++++--------- basicsubs.cpp | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 0c62276e..469251b8 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -2688,21 +2688,19 @@ factor(struct LOC_exec * LINK) const char *surf_name = stringfactor(STR1, LINK); require(tokcomma, LINK); // variable for number of species - LINK->t = LINK->t->next; count_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || !count_varrec || count_varrec->stringvar != 0) { - snerr(": can`t find variable"); + snerr(": Missing or wrong type count variable."); exit(4); } - require(tokcomma, LINK); // variable for species names LINK->t = LINK->t->next; require(tokcomma, LINK); names_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || !names_varrec || names_varrec->stringvar != 1) { - snerr(": can`t find name of species"); + snerr(": Missing or wrong type name variable."); exit(4); } // variable for species concentrations @@ -2710,21 +2708,19 @@ factor(struct LOC_exec * LINK) require(tokcomma, LINK); moles_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || moles_varrec->stringvar != 0) - snerr(": can`t find concentrations of species"); - LINK->t = LINK->t->next; + snerr(": Missing or wrong type moles variable."); // variable for area LINK->t = LINK->t->next; require(tokcomma, LINK); varrec *area_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || area_varrec->stringvar != 0) - snerr(": can`t find area varaiable"); - LINK->t = LINK->t->next; + snerr(": Missing or wrong type area varaiable."); // varaiable for thickness LINK->t = LINK->t->next; require(tokcomma, LINK); varrec *thickness_varrec = LINK->t->UU.vp; if (LINK->t->kind != tokvar || thickness_varrec->stringvar != 0) - snerr(": can`t find thickness variable"); + snerr(": Missing or wrong type thickness variable."); LINK->t = LINK->t->next; require(tokrp, LINK); diff --git a/basicsubs.cpp b/basicsubs.cpp index 10a93ea3..935e0333 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2598,6 +2598,7 @@ get_edl_species(cxxSurfaceCharge & charge_ref) sys[count_sys].name = string_duplicate(s_x[j]->name); sys[count_sys].moles = mass_water_surface / gfw_water; sys_tot += sys[count_sys].moles; + count_sys++; } else if (s_x[j]->type < H2O) { From 2fcfd8e79f9331b72d113466cf1034a17197b426 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 15 Jul 2015 19:15:43 +0000 Subject: [PATCH 0922/1077] Hack for bug with pressure, caused ternary to have low pressure result. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@9994 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- gases.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/gases.cpp b/gases.cpp index f9e5c26f..52add3cd 100644 --- a/gases.cpp +++ b/gases.cpp @@ -455,7 +455,16 @@ calc_PR(void) if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_VOLUME) { V_m = gas_phase_ptr->Get_volume() / m_sum; - P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); + P = 0.0; + while (P <= 0) + { + P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); + if (P <= 0.0) + { + V_m *= 2.0; + //a_aa_sum /= 2.0; + } + } if (iterations > 0 && P < 150 && V_m < 1.01) { // check for 3-roots... From 72352f536a968b77e659b226d3b4c7e72d452458 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Jul 2015 15:55:10 +0000 Subject: [PATCH 0923/1077] mu=0 in one of Kinniburgh's problems. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10006 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/model.cpp b/model.cpp index 4695da9f..27ecc7cb 100644 --- a/model.cpp +++ b/model.cpp @@ -566,6 +566,7 @@ gammas(LDBLE mu) LDBLE c1, c2, a, b; LDBLE muhalf, equiv; /* Initialize */ + if (mu <= 0) mu = 1e-10; if (pitzer_model == TRUE) return gammas_pz(); if (sit_model == TRUE) From 2dd34675ab8bd9048bf970ac5eac82fe0ee90f00 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 21 Jul 2015 20:37:03 +0000 Subject: [PATCH 0924/1077] Tony's fix for erm (enrichment factors). New test case erm. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10013 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- integrate.cpp | 9 ++++++++- mainsubs.cpp | 21 ++++++++++++++++----- model.cpp | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/integrate.cpp b/integrate.cpp index 4c9759d0..1d501355 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -702,7 +702,14 @@ sum_diffuse_layer(cxxSurfaceCharge *charge_ptr) if (s_x[j]->type > HPLUS) continue; molality = under(s_x[j]->lm); - moles_excess = mass_water_aq_x * molality * charge_ptr->Get_g_map()[s_x[j]->z].Get_g(); + LDBLE g = charge_ptr->Get_g_map()[s_x[j]->z].Get_g(); + if (s_x[j]->erm_ddl != 1) + { + LDBLE ratio_aq = mass_water_surface / mass_water_aq_x; + LDBLE g2 = g / ratio_aq + 1; + g = ratio_aq * (g2 * s_x[j]->erm_ddl - 1); + } + moles_excess = mass_water_aq_x * molality * g; moles_surface = mass_water_surface * molality + moles_excess; /* * Accumulate elements in diffuse layer diff --git a/mainsubs.cpp b/mainsubs.cpp index a685a78a..885957fd 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -1755,14 +1755,25 @@ xsurface_save(int n_user) double moles_excess = mass_water_aq_x * molality * charge_ref.Get_g_map()[s_x[j]->z].Get_g(); double moles_surface = mass_water_surface * molality + moles_excess; charge_ref.Get_dl_species_map()[s_x[j]->number] = moles_surface/mass_water_surface; -#ifdef SKIP +//#ifdef SKIP double g = charge_ref.Get_g_map()[s_x[j]->z].Get_g(); - double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + - mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + //double moles_excess = mass_water_aq_x * molality * (g * s_x[j]->erm_ddl + + // mass_water_surface / + // mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + + //LDBLE g = charge_ptr->Get_g_map()[s_x[j]->z].Get_g(); + if (s_x[j]->erm_ddl != 1) + { + LDBLE ratio_aq = mass_water_surface / mass_water_aq_x; + LDBLE g2 = g / ratio_aq + 1; + g = ratio_aq * (g2 * s_x[j]->erm_ddl - 1); + } + moles_excess = mass_water_aq_x * molality * g; double c = (mass_water_surface * molality + moles_excess) / mass_water_surface; charge_ref.Get_dl_species_map()[s_x[j]->number] = c; -#endif + + +//#endif } //charge_ref.Get_dl_species_map()[s_h2o->number] = 0.0; charge_ref.Get_dl_species_map()[s_h2o->number] = 1.0/gfw_water; diff --git a/model.cpp b/model.cpp index 27ecc7cb..df2ca4de 100644 --- a/model.cpp +++ b/model.cpp @@ -2428,7 +2428,7 @@ molalities(int allow_overflow) dl_ref.Set_drelated_moles(s_ptr->moles * s_ptr->erm_ddl * charge_ref.Get_specific_area() * use.Get_surface_ptr()->Get_thickness() / mass_water_aq_x); } - s_ptr->tot_g_moles = s_ptr->moles * (1 + total_g /* s_ptr->erm_ddl */ ); + s_ptr->tot_g_moles = s_ptr->moles * (1 + total_g * s_ptr->erm_ddl); /* note that dg is for cb, act water, mu eqns */ /* dg_total_g for mole balance eqns */ From 1b4a3076097314410962e94e9b44fd0bb62e8edb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Jul 2015 23:17:50 +0000 Subject: [PATCH 0925/1077] Null pointer if K-Cl interaction parameters (b0, b1, c0) were not defined. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10030 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index 617090b3..2220083f 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -780,9 +780,18 @@ C int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } - calc_pitz_param(mcb0, TK, TR); - calc_pitz_param(mcb1, TK, TR); - calc_pitz_param(mcc0, TK, TR); + if (mcb0) + { + calc_pitz_param(mcb0, TK, TR); + } + if (mcb1) + { + calc_pitz_param(mcb1, TK, TR); + } + if (mcc0) + { + calc_pitz_param(mcc0, TK, TR); + } #endif calc_dielectrics(TK - 273.15, patm_x); OTEMP = TK; From eef31c954dcfa9664587504075eb81bfe308fff7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 4 Aug 2015 19:18:25 +0000 Subject: [PATCH 0926/1077] Iterator bug. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10040 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index aa91fa6d..b948f0f4 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1391,7 +1391,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) } else { - this->log_gamma_map[git->first] = it->second; + this->log_gamma_map[git->first] = git->second; } } } From adbe4d666f3e99abe05bfc204d56a176fb786e0d Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 8 Aug 2015 00:32:59 +0000 Subject: [PATCH 0927/1077] added common directory for Parser/PHRQ_base/PHRQ_io/phrqtype/Utils git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10053 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 116 +++++++++++++------------- PHRQ_base.cxx => common/PHRQ_base.cxx | 0 PHRQ_base.h => common/PHRQ_base.h | 0 PHRQ_io.cpp => common/PHRQ_io.cpp | 0 PHRQ_io.h => common/PHRQ_io.h | 0 Parser.cxx => common/Parser.cxx | 0 Parser.h => common/Parser.h | 0 Utils.cxx => common/Utils.cxx | 0 Utils.h => common/Utils.h | 0 phrqtype.h => common/phrqtype.h | 0 10 files changed, 58 insertions(+), 58 deletions(-) rename PHRQ_base.cxx => common/PHRQ_base.cxx (100%) rename PHRQ_base.h => common/PHRQ_base.h (100%) rename PHRQ_io.cpp => common/PHRQ_io.cpp (100%) rename PHRQ_io.h => common/PHRQ_io.h (100%) rename Parser.cxx => common/Parser.cxx (100%) rename Parser.h => common/Parser.h (100%) rename Utils.cxx => common/Utils.cxx (100%) rename Utils.h => common/Utils.h (100%) rename phrqtype.h => common/phrqtype.h (100%) diff --git a/Makefile.am b/Makefile.am index a0285cf2..f6e6e408 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,76 +9,122 @@ EXTRA_DIST=\ Form1.resX\ ZedGraph.dll -AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/PhreeqcKeywords +AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_srcdir)/src/common -I$(top_srcdir)/src/PhreeqcKeywords bin_PROGRAMS = phreeqc # sources for phreeqc phreeqc_SOURCES=\ + advection.cpp\ + basicsubs.cpp\ + cl1.cpp\ class_main.cpp\ + common/Parser.cxx\ + common/Parser.h\ + common/PHRQ_base.cxx\ + common/PHRQ_base.h\ + common/PHRQ_io.cpp\ + common/PHRQ_io.h\ + common/phrqtype.h\ + common/Utils.cxx\ + common/Utils.h\ + cvdense.cpp\ + cvdense.h\ + cvode.cpp\ + cvode.h\ cxxKinetics.cxx\ cxxKinetics.h\ cxxMix.cxx\ cxxMix.h\ + dense.cpp\ + dense.h\ dumper.cpp\ dumper.h\ + dw.cpp\ Exchange.cxx\ Exchange.h\ ExchComp.cxx\ ExchComp.h\ GasComp.cxx\ GasComp.h\ + gases.cpp\ GasPhase.cxx\ GasPhase.h\ + global_structures.h\ + input.cpp\ + integrate.cpp\ + inverse.cpp\ ISolution.cxx\ ISolution.h\ ISolutionComp.cxx\ ISolutionComp.h\ + isotopes.cpp\ + kinetics.cpp\ KineticsComp.cxx\ KineticsComp.h\ + mainsubs.cpp\ + model.cpp\ + NA.h\ NameDouble.cxx\ NameDouble.h\ NumKeyword.cxx\ NumKeyword.h\ - Parser.cxx\ - Parser.h\ + nvector.cpp\ + nvector.h\ + nvector_serial.cpp\ + nvector_serial.h\ + parse.cpp\ PBasic.cpp\ PBasic.h\ + phqalloc.cpp\ + phqalloc.h\ Phreeqc.cpp\ Phreeqc.h\ PhreeqcKeywords/Keywords.cpp\ PhreeqcKeywords/Keywords.h\ - PHRQ_base.cxx\ - PHRQ_base.h\ - PHRQ_io.cpp\ - PHRQ_io.h\ + PHRQ_io_output.cpp\ + pitzer.cpp\ + pitzer_structures.cpp\ PPassemblage.cxx\ PPassemblage.h\ PPassemblageComp.cxx\ PPassemblageComp.h\ + prep.cpp\ Pressure.cxx\ Pressure.h\ + print.cpp\ Reaction.cxx\ Reaction.h\ + read.cpp\ ReadClass.cxx\ + readtr.cpp\ runner.cpp\ runner.h\ SelectedOutput.cpp\ SelectedOutput.h\ + sit.cpp\ + smalldense.cpp\ + smalldense.h\ Solution.cxx\ Solution.h\ SolutionIsotope.cxx\ SolutionIsotope.h\ - SSassemblage.cxx\ - SSassemblage.h\ + spread.cpp\ SS.cxx\ SS.h\ + SSassemblage.cxx\ + SSassemblage.h\ SScomp.cxx\ SScomp.h\ + step.cpp\ StorageBin.cxx\ StorageBin.h\ StorageBinList.cpp\ StorageBinList.h\ + structures.cpp\ + sundialsmath.cpp\ + sundialsmath.h\ + sundialstypes.h\ Surface.cxx\ Surface.h\ SurfaceCharge.cxx\ @@ -87,61 +133,15 @@ phreeqc_SOURCES=\ SurfaceComp.h\ System.cxx\ System.h\ + tally.cpp\ Temperature.cxx\ Temperature.h\ + tidy.cpp\ + transport.cpp\ Use.cpp\ Use.h\ UserPunch.cpp\ UserPunch.h\ - Utils.cxx\ - Utils.h\ - advection.cpp\ - basicsubs.cpp\ - cl1.cpp\ - cvdense.cpp\ - cvdense.h\ - cvode.cpp\ - cvode.h\ - dense.cpp\ - dense.h\ - dw.cpp\ - gases.cpp\ - global_structures.h\ - input.cpp\ - integrate.cpp\ - inverse.cpp\ - isotopes.cpp\ - kinetics.cpp\ - mainsubs.cpp\ - model.cpp\ - NA.h\ - nvector.cpp\ - nvector.h\ - nvector_serial.cpp\ - nvector_serial.h\ - parse.cpp\ - phqalloc.cpp\ - phqalloc.h\ - PHRQ_io_output.cpp\ - phrqtype.h\ - pitzer.cpp\ - pitzer_structures.cpp\ - prep.cpp\ - print.cpp\ - read.cpp\ - readtr.cpp\ - sit.cpp\ - smalldense.cpp\ - smalldense.h\ - spread.cpp\ - step.cpp\ - structures.cpp\ - sundialsmath.cpp\ - sundialsmath.h\ - sundialstypes.h\ - tally.cpp\ - tidy.cpp\ - transport.cpp\ utilities.cpp if BUILD_GMP diff --git a/PHRQ_base.cxx b/common/PHRQ_base.cxx similarity index 100% rename from PHRQ_base.cxx rename to common/PHRQ_base.cxx diff --git a/PHRQ_base.h b/common/PHRQ_base.h similarity index 100% rename from PHRQ_base.h rename to common/PHRQ_base.h diff --git a/PHRQ_io.cpp b/common/PHRQ_io.cpp similarity index 100% rename from PHRQ_io.cpp rename to common/PHRQ_io.cpp diff --git a/PHRQ_io.h b/common/PHRQ_io.h similarity index 100% rename from PHRQ_io.h rename to common/PHRQ_io.h diff --git a/Parser.cxx b/common/Parser.cxx similarity index 100% rename from Parser.cxx rename to common/Parser.cxx diff --git a/Parser.h b/common/Parser.h similarity index 100% rename from Parser.h rename to common/Parser.h diff --git a/Utils.cxx b/common/Utils.cxx similarity index 100% rename from Utils.cxx rename to common/Utils.cxx diff --git a/Utils.h b/common/Utils.h similarity index 100% rename from Utils.h rename to common/Utils.h diff --git a/phrqtype.h b/common/phrqtype.h similarity index 100% rename from phrqtype.h rename to common/phrqtype.h From caecf8b8d6a235161d7e7131fd3141ee29e70694 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 8 Aug 2015 00:32:59 +0000 Subject: [PATCH 0928/1077] added common directory for Parser/PHRQ_base/PHRQ_io/phrqtype/Utils git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10053 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.cxx | 108 ++++ PHRQ_base.h | 46 ++ PHRQ_io.cpp | 901 +++++++++++++++++++++++++++++++++ PHRQ_io.h | 211 ++++++++ Parser.cxx | 1317 +++++++++++++++++++++++++++++++++++++++++++++++++ Parser.h | 296 +++++++++++ Utils.cxx | 186 +++++++ Utils.h | 28 ++ phrqtype.h | 18 + 9 files changed, 3111 insertions(+) create mode 100644 PHRQ_base.cxx create mode 100644 PHRQ_base.h create mode 100644 PHRQ_io.cpp create mode 100644 PHRQ_io.h create mode 100644 Parser.cxx create mode 100644 Parser.h create mode 100644 Utils.cxx create mode 100644 Utils.h create mode 100644 phrqtype.h diff --git a/PHRQ_base.cxx b/PHRQ_base.cxx new file mode 100644 index 00000000..0e07d1f0 --- /dev/null +++ b/PHRQ_base.cxx @@ -0,0 +1,108 @@ +#include "PHRQ_base.h" +#include +#include "PHRQ_io.h" +PHRQ_base:: +PHRQ_base(void) +{ + this->io = NULL; + base_error_count = 0; +} + +PHRQ_base:: +PHRQ_base(PHRQ_io * p_io) +{ + this->io = p_io; + base_error_count = 0; +} + +PHRQ_base:: +~PHRQ_base() +{ +} + +void PHRQ_base:: +error_msg(const std::string & stdstr, int stop) +{ + this->base_error_count++; + std::ostringstream msg; + msg << "ERROR: " << stdstr << "\n"; + if (this->io) + { + this->io->output_msg(msg.str().c_str()); + this->io->log_msg(msg.str().c_str()); + this->io->error_msg("\n"); + this->io->error_msg(msg.str().c_str(), stop!=0); + } + else + { +#if !defined(R_SO) + std::cerr << msg.str().c_str(); + std::cout << msg.str().c_str(); +#endif + } + if (stop != 0) + { + throw PhreeqcStop(); + } +} + +void PHRQ_base:: +warning_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->warning_msg(stdstr.c_str()); + } + else + { +#if !defined(R_SO) + std::cerr << stdstr << "\n"; + std::cout << stdstr << "\n"; +#endif + } +} + +void PHRQ_base:: +output_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->output_msg(stdstr.c_str()); + } + else + { +#if !defined(R_SO) + std::cout << stdstr << "\n"; +#endif + } +} + +void PHRQ_base:: +screen_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->screen_msg(stdstr.c_str()); + } + else + { +#if !defined(R_SO) + std::cerr << stdstr << "\n"; +#endif + } +} + +void PHRQ_base:: +echo_msg(const std::string & stdstr) +{ + if (this->io) + { + this->io->echo_msg(stdstr.c_str()); + } + else + { +#if !defined(R_SO) + std::cout << stdstr << "\n"; +#endif + } +} \ No newline at end of file diff --git a/PHRQ_base.h b/PHRQ_base.h new file mode 100644 index 00000000..4750cb13 --- /dev/null +++ b/PHRQ_base.h @@ -0,0 +1,46 @@ +#ifndef _PHRQBASE_H +#define _PHRQBASE_H + +#include + +class PHRQ_io; +class PHRQ_base +{ +public: + // constructors + PHRQ_base(void); + PHRQ_base(PHRQ_io *); + virtual ~ PHRQ_base(); + + + // methods + void output_msg(const std::string &); + void error_msg(const std::string &, int stop=0); + void warning_msg(const std::string &); + void screen_msg(const std::string &); + void echo_msg(const std::string &); + + + void Set_io(PHRQ_io * p_io) + { + this->io = p_io; + } + PHRQ_io * Get_io(void) + { + return this->io; + } + void Set_base_error_count(int i) + { + this->base_error_count = i; + } + int Get_base_error_count(void) + { + return this->base_error_count; + } + // data +protected: + PHRQ_io * io; + int base_error_count; +}; + +#endif /* _PHRQBASE_H */ diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp new file mode 100644 index 00000000..fd2d4cd0 --- /dev/null +++ b/PHRQ_io.cpp @@ -0,0 +1,901 @@ +#include +#include "PHRQ_io.h" +#include "Parser.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +PHRQ_io:: +PHRQ_io(void) +{ + output_ostream = NULL; + log_ostream = NULL; + punch_ostream = NULL; +#ifdef ERROR_OSTREAM + error_ostream = NULL; +#else + error_file = NULL; +#endif + dump_ostream = NULL; + io_error_count = 0; + + output_on = true; + log_on = false; + punch_on = true; + error_on = true; + dump_on = true; + echo_on = true; + screen_on = true; + echo_destination = ECHO_OUTPUT; + + m_next_keyword = Keywords::KEY_NONE; + accumulate = false; + m_line_type = PHRQ_io::LT_EMPTY; +} + +PHRQ_io:: +~PHRQ_io() +{ +} +// ---------------------------------------------------------------------- */ +// output ostream methods +// ---------------------------------------------------------------------- */ + +bool PHRQ_io:: +ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode) +{ + std::ofstream *ofs = new std::ofstream(file_name, mode); + if (ofs && ofs->is_open()) + { + *os = ofs; + return true; + } + delete ofs; + return false; +} + +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +output_open(const char *file_name, std::ios_base::openmode mode) +/* ---------------------------------------------------------------------- */ +{ + return ofstream_open(&output_ostream, file_name, mode); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (output_ostream) + { + output_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&output_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +output_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (output_ostream != NULL && output_on) + { + (*output_ostream) << str; + } + //output_flush(); +} +// ---------------------------------------------------------------------- */ +// log ostream methods +// ---------------------------------------------------------------------- */ +bool PHRQ_io:: +log_open(const char *file_name, std::ios_base::openmode mode) +/* ---------------------------------------------------------------------- */ +{ + return ofstream_open(&log_ostream, file_name, mode); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +log_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (log_ostream) + { + log_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +log_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&log_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +log_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (log_ostream != NULL && log_on) + { + (*log_ostream) << str; + } +} +// ---------------------------------------------------------------------- */ +// punch ostream methods +// ---------------------------------------------------------------------- */ +bool PHRQ_io:: +punch_open(const char *file_name, std::ios_base::openmode mode, int n_user) +/* ---------------------------------------------------------------------- */ +{ + return ofstream_open(&punch_ostream, file_name, mode); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +punch_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (punch_ostream) + { + punch_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +punch_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&punch_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +punch_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (punch_ostream != NULL && punch_on) + { + (*punch_ostream) << str; + } +} +// ---------------------------------------------------------------------- */ +// error file methods +// ---------------------------------------------------------------------- */ +#ifdef ERROR_OSTREAM +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +error_open(const char *file_name, std::ios_base::openmode mode) +/* ---------------------------------------------------------------------- */ +{ + if (file_name != NULL) + { + if (!ofstream_open(&error_ostream, file_name, mode)) + { +#if !defined(R_SO) + error_ostream = &std::cerr; +#endif + return false; + } + } + else + { +#if !defined(R_SO) + error_ostream = &std::cerr; +#endif + } + return true; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_ostream) + { + error_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&error_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + + io_error_count++; + if (error_ostream != NULL && error_on) + { + //(*error_ostream) << err_str; + screen_msg(err_str); + error_flush(); + } + if (stop) + { + if (error_ostream != NULL && error_on) + { + //(*error_ostream) << "Stopping.\n"; + screen_msg("Stopping.\n"); + error_ostream->flush(); + } + output_msg("Stopping.\n"); + log_msg("Stopping.\n"); + + throw PhreeqcStop(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (error_ostream != NULL && error_on) + { + //(*error_ostream) << err_str << "\n"; + std::string err_stdstr(err_str); + err_stdstr.append("\n"); + screen_msg(err_stdstr.c_str()); + error_ostream->flush(); + } + std::ostringstream warn_str; + warn_str << err_str << "\n"; + log_msg(warn_str.str().c_str()); + log_flush(); + output_msg(warn_str.str().c_str()); + output_flush(); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (error_ostream != NULL && screen_on) + { + (*error_ostream) << str; + } +} +#else +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +error_open(const char *file_name, const char * mode) +/* ---------------------------------------------------------------------- */ +{ + if (file_name != NULL) + { + if ((error_file = fopen(file_name, mode)) == NULL) + { + error_file = stderr; + return false; + } + } + else + { + error_file = stderr; + } + return true; +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (error_file) + { + fflush(error_file); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&error_file); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +error_msg(const char *err_str, bool stop) +/* ---------------------------------------------------------------------- */ +{ + + io_error_count++; + if (error_file != NULL && error_on) + { + //(*error_file) << err_str; + screen_msg(err_str); + error_flush(); + } + if (stop) + { + if (error_file != NULL && error_on) + { + //(*error_file) << "Stopping.\n"; + screen_msg("Stopping.\n"); + fflush(error_file); + } + output_msg("Stopping.\n"); + log_msg("Stopping.\n"); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +warning_msg(const char *err_str) +/* ---------------------------------------------------------------------- */ +{ + if (error_file != NULL && error_on) + { + //(*error_file) << err_str << "\n"; + std::string err_stdstr(err_str); + err_stdstr.append("\n"); + screen_msg(err_stdstr.c_str()); + error_flush(); + } + std::ostringstream warn_str; + warn_str << err_str << "\n"; + log_msg(warn_str.str().c_str()); + log_flush(); + output_msg(warn_str.str().c_str()); + output_flush(); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +screen_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + std::string stdstr(str); + if (error_file != NULL && screen_on) + { + fprintf(error_file, "%s", str); + } +} +#endif +// ---------------------------------------------------------------------- */ +// dump ostream methods +// ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- */ +bool PHRQ_io:: +dump_open(const char *file_name, std::ios_base::openmode mode) +/* ---------------------------------------------------------------------- */ +{ + return ofstream_open(&dump_ostream, file_name, mode); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +dump_flush(void) +/* ---------------------------------------------------------------------- */ +{ + if (dump_ostream) + { + dump_ostream->flush(); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +dump_close(void) +/* ---------------------------------------------------------------------- */ +{ + safe_close(&dump_ostream); +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +dump_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (dump_ostream != NULL && dump_on) + { + (*dump_ostream) << str; + } +} +int PHRQ_io:: +getc(void) +{ + if (std::istream* is = get_istream()) + { + int n = is->get(); + if (n == 13 && is->peek() == 10) + { + n = is->get(); + } + return n; + } + return EOF; +} + +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf(const char *name, const char *format, double d) +/* ---------------------------------------------------------------------- */ +{ + if (punch_ostream != NULL && punch_on) + { + fpunchf_helper(punch_ostream, format, d); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf(const char *name, const char *format, char * s) +/* ---------------------------------------------------------------------- */ +{ + if (punch_ostream != NULL && punch_on) + { + fpunchf_helper(punch_ostream, format, s); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf(const char *name, const char *format, int d) +/* ---------------------------------------------------------------------- */ +{ + if (punch_ostream != NULL && punch_on) + { + fpunchf_helper(punch_ostream, format, d); + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf_helper(std::ostream *os, const char *format, ...) +/* ---------------------------------------------------------------------- */ +{ + if (os) + { + const size_t STACK_MAX = 2048; + char stack_buffer[STACK_MAX]; + + va_list args; + va_start(args, format); + int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); + bool success = (j >= 0 && j < (int) STACK_MAX); + va_end(args); + + if (success) + { + (*os) << stack_buffer; + } + else + { + size_t alloc_buffer_size = STACK_MAX * 2; + char *alloc_buffer = new char[alloc_buffer_size]; + do + { + va_list args; + va_start(args, format); + j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); + success = (j >= 0 && j < (int) alloc_buffer_size); + va_end(args); + if (!success) + { + delete[] alloc_buffer; + alloc_buffer_size *= 2; + alloc_buffer = new char[alloc_buffer_size]; + } + } + while (!success); + + (*os) << alloc_buffer; + delete[] alloc_buffer; + } + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +fpunchf_helper(std::string *str, const char *format, ...) +/* ---------------------------------------------------------------------- */ +{ + if (str) + { + const size_t STACK_MAX = 2048; + char stack_buffer[STACK_MAX]; + + va_list args; + va_start(args, format); + int j = ::vsnprintf(stack_buffer, STACK_MAX, format, args); + bool success = (j >= 0 && j < (int) STACK_MAX); + va_end(args); + + if (success) + { + (*str) += stack_buffer; + } + else + { + size_t alloc_buffer_size = STACK_MAX * 2; + char *alloc_buffer = new char[alloc_buffer_size]; + do + { + va_list args; + va_start(args, format); + j = ::vsnprintf(alloc_buffer, alloc_buffer_size, format, args); + success = (j >= 0 && j < (int) alloc_buffer_size); + va_end(args); + if (!success) + { + delete[] alloc_buffer; + alloc_buffer_size *= 2; + alloc_buffer = new char[alloc_buffer_size]; + } + } + while (!success); + + (*str) += alloc_buffer; + delete[] alloc_buffer; + } + } +} + +/* ---------------------------------------------------------------------- */ +void PHRQ_io::fpunchf_end_row(const char *format) +/* ---------------------------------------------------------------------- */ +{ + //NOOP for Phreeqc +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +close_ostreams(void) +/* ---------------------------------------------------------------------- */ +{ + std::set streams; + + streams.insert(output_ostream); + streams.insert(log_ostream); +// streams.insert(punch_ostream); // Should be deleted in ~SelectedOutput +#ifdef ERROR_OSTREAM + streams.insert(error_ostream); +#else + safe_close(&error_file); +#endif + streams.insert(dump_ostream); + + std::set::iterator it = streams.begin(); + for (; it != streams.end(); it++) + { + std::ostream * x = *it; + safe_close(&x); + } + + output_ostream = NULL; + log_ostream = NULL; + punch_ostream = NULL; +#ifdef ERROR_OSTREAM + error_ostream = NULL; +#else + error_file = NULL; +#endif + dump_ostream = NULL; +} +//safe_close is static method +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +safe_close(std::ostream **stream_ptr) +/* ---------------------------------------------------------------------- */ +{ + if ( +#if !defined(R_SO) + *stream_ptr != &std::cerr && + *stream_ptr != &std::cout && + *stream_ptr != &std::clog && +#endif + *stream_ptr != NULL) + { + delete *stream_ptr; + *stream_ptr = NULL; + } +} +void PHRQ_io:: +safe_close(FILE **file_ptr) +/* ---------------------------------------------------------------------- */ +{ + if ( +#if !defined(R_SO) + *file_ptr != stderr && + *file_ptr != stdout && + *file_ptr != stdin && +#endif + *file_ptr != NULL) + { + fclose(*file_ptr); + *file_ptr = NULL; + } +} +/* ---------------------------------------------------------------------- */ +void PHRQ_io:: +echo_msg(const char * str) +/* ---------------------------------------------------------------------- */ +{ + if (echo_on) + { + switch (this->echo_destination) + { + case ECHO_LOG: + log_msg(str); + break; + case ECHO_OUTPUT: + output_msg(str); + break; + } + } +} + +std::istream * PHRQ_io:: +get_istream() +{ + if (istream_list.size() > 0) + { + return istream_list.front(); + } + else + { + return NULL; + } +} +void PHRQ_io:: +push_istream(std::istream * cookie, bool auto_delete) +{ + istream_list.push_front(cookie); + delete_istream_list.push_front(auto_delete); +} +void PHRQ_io:: +clear_istream(void) +{ + while (istream_list.size() > 0) + { + pop_istream(); + } +} +void PHRQ_io:: +pop_istream() +{ + if (istream_list.size() > 0) + { + if (delete_istream_list.front()) + { + delete istream_list.front(); + } + istream_list.pop_front(); + delete_istream_list.pop_front(); + } +} +/* ---------------------------------------------------------------------- */ +PHRQ_io::LINE_TYPE PHRQ_io:: +get_line(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Read a line from input file put in "line". + * Copy of input line is stored in "line_save". + * Characters after # are discarded in line but retained in "line_save" + * + * Arguments: + * fp is file name + * Returns: + * EMPTY, + * EOF, + * KEYWORD, + * OK, + * OPTION + */ + std::string stdtoken; + bool continue_loop = true;; + + PHRQ_io::LINE_TYPE return_value; + // loop for include files + for (;;) + { + if (this->get_istream() == NULL) + { + break; + } + return_value = LT_EMPTY; + while (return_value == LT_EMPTY) + { + /* + * Eliminate all characters after # sign as a comment + */ + /* + * Get line, check for eof + */ + continue_loop = false; + + if (get_logical_line() == LT_EOF) + { + //pop next file + this->pop_istream(); + continue_loop = true; + break; + } + /* + * Get long lines + */ + bool empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + if (this->accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + // + // New line character encountered + // + return_value = (empty ? LT_EMPTY : LT_OK); + + } + if (continue_loop) continue; + // + // Determine return_value + // + if (return_value == LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + CParser::copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) + { + return_value = LT_OPTION; + } + } + } + + // add new include file to stack + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + CParser::copy_token(stdtoken, beg, end); + std::transform(stdtoken.begin(), stdtoken.end(), stdtoken.begin(), ::tolower); + if ((strstr(stdtoken.c_str(),"include$") == stdtoken.c_str()) || + (strstr(stdtoken.c_str(),"include_file") == stdtoken.c_str())) + { + std::string file_name; + file_name.assign(beg, end); + file_name = trim(file_name); + + if (file_name.size() > 0) + { + std::ifstream *next_stream = new std::ifstream(file_name.c_str(), std::ios_base::in); + if (!next_stream->is_open()) + { + std::ostringstream errstr; + errstr << "\n*********** Could not open include file " << file_name + <<".\n Please, write the full path to this file. ***********\n\n"; + delete next_stream; +#if defined(PHREEQCI_GUI) + warning_msg(errstr.str().c_str()); + continue; +#else + output_msg(errstr.str().c_str()); + error_msg(errstr.str().c_str(), OT_STOP); +#endif + } + else + { + this->push_istream(next_stream); + } + continue; + } + } + return return_value; + } + m_next_keyword = Keywords::KEY_END; + return LT_EOF; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +PHRQ_io::LINE_TYPE PHRQ_io:: +get_logical_line(void) +{ + int j; + unsigned int pos; + char c; + + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + while ((j = getc()) != EOF) + { + c = (char) j; + if (c == '#') + { + // ignore all chars after # until newline + do + { + c = (char) j; + if (c == '\n') + { + break; + } + m_line_save += c; + } + while ((j = getc()) != EOF); + } + if (c == ';') + break; + if (c == '\n') + { + break; + } + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + while ((j = getc()) != EOF) + { + c = (char) j; + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') + { + // remove '\\' + m_line_save = m_line_save.substr(0,pos); + break; + } + m_line_save += c; + if (!::isspace(j)) + break; + } + } + else + { + m_line_save += c; + } + } + if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) + { + return (LT_EOF); + } + return (LT_OK); +} + +bool PHRQ_io:: +check_key(std::string::iterator begin, std::string::iterator end) +{ + std::string lowercase; + CParser::copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), + tolower); + + m_next_keyword = Keywords::Keyword_search(lowercase); + if (m_next_keyword == Keywords::KEY_NONE) + { + return false; + } + return true; +} + diff --git a/PHRQ_io.h b/PHRQ_io.h new file mode 100644 index 00000000..8c469248 --- /dev/null +++ b/PHRQ_io.h @@ -0,0 +1,211 @@ +#ifndef _PHRQIO_H +#define _PHRQIO_H + +#if defined(_WINDLL) +#define IPQ_DLL_EXPORT __declspec(dllexport) +#else +#define IPQ_DLL_EXPORT +#endif + +#include +#include +#include +#include "Keywords.h" +#include + +#define ERROR_OSTREAM + +class PhreeqcStop : public std::exception +{ +}; + +class IPQ_DLL_EXPORT PHRQ_io +{ +public: + enum LINE_TYPE + { + LT_EOF = -1, + LT_OK = 1, + LT_EMPTY = 2, + LT_KEYWORD = 3, + LT_OPTION = 8 + }; + + enum ONERROR_TYPE + { + OT_CONTINUE = 0, + OT_STOP = 1 + }; + // constructor/destructor + PHRQ_io(void); + virtual ~ PHRQ_io(); + + // methods + static void safe_close(std::ostream **stream_ptr); + static void safe_close(FILE **file_ptr); + void close_ostreams(void); + void Set_io_error_count(int i) {this->io_error_count = i;}; + int Get_io_error_count(void) {return this->io_error_count;}; + + + // istreams + std::istream *get_istream(); + void pop_istream(); + void push_istream(std::istream * cookie, bool auto_delete = true); + void clear_istream(void); + + // helper + bool ofstream_open(std::ostream **os, const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + + // output_ostream + virtual bool output_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void output_flush(void); + void output_close(void); + virtual void output_msg(const char * str); + void Set_output_ostream(std::ostream * out) {this->output_ostream = out;}; + std::ostream *Get_output_ostream(void) {return this->output_ostream;}; + void Set_output_on(bool tf) {this->output_on = tf;}; + bool Get_output_on(void) {return this->output_on;}; + + // log_ostream + virtual bool log_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void log_flush(void); + void log_close(void); + virtual void log_msg(const char * str); + void Set_log_ostream(std::ostream * out) {this->log_ostream = out;} + std::ostream *Get_log_ostream(void) {return this->log_ostream;} + void Set_log_on(bool tf) {this->log_on = tf;} + bool Get_log_on(void) {return this->log_on;} + + // punch_ostream + virtual bool punch_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out, int n_user = 1); + void punch_flush(void); + void punch_close(void); + virtual void punch_msg(const char * str); + void Set_punch_ostream(std::ostream * out) {this->punch_ostream = out;} + std::ostream *Get_punch_ostream(void) {return this->punch_ostream;} + void Set_punch_on(bool tf) {this->punch_on = tf;} + bool Get_punch_on(void) {return this->punch_on;} + + // error_ostream +#ifdef ERROR_OSTREAM + virtual bool error_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void error_flush(void); + void error_close(void); + virtual void error_msg(const char * str, bool stop=false); + void Set_error_ostream(std::ostream * out) {this->error_ostream = out;} + std::ostream *Get_error_ostream(void) {return this->error_ostream;} + void Set_error_on(bool tf) {this->error_on = tf;} + bool Get_error_on(void) {return this->error_on;} + virtual void warning_msg(const char *err_str); +#else + virtual bool error_open(const char *file_name, const char * mode = "w"); + void error_flush(void); + void error_close(void); + virtual void error_msg(const char * str, bool stop=false); + void Set_error_file(FILE * out) {this->error_file = out;} + FILE *Get_error_file(void) {return this->error_file;} + void Set_error_on(bool tf) {this->error_on = tf;} + bool Get_error_on(void) {return this->error_on;} + virtual void warning_msg(const char *err_str); +#endif + + // dump_ostream + virtual bool dump_open(const char *file_name, std::ios_base::openmode mode = std::ios_base::out); + void dump_flush(void); + void dump_close(void); + virtual void dump_msg(const char * str); + void Set_dump_ostream(std::ostream * out) {this->dump_ostream = out;}; + std::ostream *Get_dump_ostream(void) {return this->dump_ostream;}; + void Set_dump_on(bool tf) {this->dump_on = tf;}; + bool Get_dump_on(void) {return this->dump_on;}; + + // fpunchf + virtual void fpunchf(const char *name, const char *format, double d); + virtual void fpunchf(const char *name, const char *format, char * d); + virtual void fpunchf(const char *name, const char *format, int d); + virtual void fpunchf_end_row(const char *format); + static void fpunchf_helper(std::ostream *os, const char *format, ...); + static void fpunchf_helper(std::string *str, const char *format, ...); + + virtual void screen_msg(const char * str); + void Set_screen_on(bool tf) {this->screen_on = tf;}; + bool Get_screen_on(void) {return this->screen_on;}; + + // input methods + virtual int getc(void); + virtual LINE_TYPE get_line(void); + virtual LINE_TYPE get_logical_line(void); + bool check_key(std::string::iterator begin, std::string::iterator end); + std::string & Get_m_line() {return m_line;} + std::string & Get_m_line_save() {return m_line_save;} + std::string & Get_accumulated() {return accumulated;} + LINE_TYPE Get_m_line_type() {return m_line_type;}; + void Set_accumulate(bool tf) + { + if (tf) + { + accumulated.clear(); + } + this->accumulate = tf; + } + Keywords::KEYWORDS Get_m_next_keyword() const {return m_next_keyword;} + + // echo + enum ECHO_OPTION + { + ECHO_LOG, + ECHO_OUTPUT + }; + virtual void echo_msg(const char * str); + void Set_echo_on(bool tf) {this->echo_on = tf;}; + bool Get_echo_on(void) {return this->echo_on;}; + void Set_echo_destination(ECHO_OPTION eo) {this->echo_destination = eo;}; + ECHO_OPTION Get_echo_destination(void) {return this->echo_destination;}; + + // data +protected: + std::ostream *output_ostream; + std::ostream *log_ostream; + std::ostream *punch_ostream; +#ifdef ERROR_OSTREAM + std::ostream *error_ostream; +#else + FILE * error_file; +#endif + std::ostream *dump_ostream; + int io_error_count; + + bool output_on; + bool log_on; + bool punch_on; + bool error_on; + bool dump_on; + bool echo_on; + bool screen_on; + ECHO_OPTION echo_destination; + +#if defined(_MSC_VER) +/* disable warning C4251: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' */ +#pragma warning(disable:4251) +#endif + + std::list istream_list; + std::list delete_istream_list; + + std::string m_line; + std::string m_line_save; + std::string accumulated; + +#if defined(_MSC_VER) +/* reset warning C4251 */ +#pragma warning(default:4251) +#endif + + // input data members + Keywords::KEYWORDS m_next_keyword; + bool accumulate; + LINE_TYPE m_line_type; +}; + +#endif /* _PHRQIO_H */ diff --git a/Parser.cxx b/Parser.cxx new file mode 100644 index 00000000..c0e13059 --- /dev/null +++ b/Parser.cxx @@ -0,0 +1,1317 @@ +// Parser.cpp: implementation of the CParser class. +// +////////////////////////////////////////////////////////////////////// +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif + +#include // std::transform +#include // std::map +#include // assert +#include +#include // std::cout std::cerr +#include "Utils.h" +#include +#include "Parser.h" +#include "PHRQ_io.h" + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +CParser::CParser(PHRQ_io *io): +PHRQ_base(io), +m_input_stream(std::cin), +m_input_error(0), +m_next_keyword(Keywords::KEY_NONE) +{ + if (!io) + { + error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP); + } + else + { + m_line_save = io->Get_m_line(); + m_line = io->Get_m_line(); + m_line_type = io->Get_m_line_type(); + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = true; + } +} + +CParser::CParser(std::istream & input, PHRQ_io *io): +PHRQ_base(io), +m_input_stream(input), +m_input_error(0), +m_next_keyword(Keywords::KEY_NONE) +{ + m_line_save.reserve(80); + m_line.reserve(80); + echo_file = EO_ALL; + echo_stream = EO_NONE; + accumulate = false; + phrq_io_only = false; +} + +CParser::~CParser() +{ +} + +PHRQ_io::LINE_TYPE CParser::check_line(const std::string & str, + bool allow_empty, bool allow_eof, + bool allow_keyword, bool print) +{ + PHRQ_io::LINE_TYPE + i; + + // Get line + do + { + i = get_line(); + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + // output for stream + switch (this->echo_stream) + { + case EO_NONE: + break; + case EO_ALL: + if (i != PHRQ_io::LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + //get_output() << msg; + io->output_msg(msg.str().c_str()); + } + break; + case EO_KEYWORDS: + if (i == PHRQ_io::LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + //get_output() << msg; + io->output_msg(msg.str().c_str()); + } + break; + case EO_NOKEYWORDS: + if (i != PHRQ_io::LT_KEYWORD && i != PHRQ_io::LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + //get_output() << msg; + io->output_msg(msg.str().c_str()); + } + break; + } + // output for file + switch (this->echo_file) + { + case EO_NONE: + break; + case EO_ALL: + if (i != PHRQ_io::LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + this->echo_msg(msg.str()); + } + break; + case EO_KEYWORDS: + if (i == PHRQ_io::LT_KEYWORD) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + this->echo_msg(msg.str()); + } + break; + + case EO_NOKEYWORDS: + if (i != PHRQ_io::LT_KEYWORD && i != PHRQ_io::LT_EOF) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + this->echo_msg(msg.str().c_str()); + } + break; + } + } + while (i == PHRQ_io::LT_EMPTY && allow_empty == false); + + // Check eof + if (i == PHRQ_io::LT_EOF && allow_eof == false) + { + std::ostringstream msg; + msg << "Unexpected eof while reading " << str << + "\nExecution terminated.\n"; + error_msg(msg.str().c_str(), PHRQ_io::OT_STOP); + } + + // Check keyword + if (i == PHRQ_io::LT_KEYWORD && allow_keyword == false) + { + std::ostringstream msg; + msg << "Expected data for " << str << + ", but got a keyword ending data block."; + error_msg(msg.str().c_str(), PHRQ_io::OT_CONTINUE); + incr_input_error(); + } + m_line_type = i; + return i; +} +PHRQ_io::LINE_TYPE CParser::get_line_phrq_io() +{ + m_line_type = io->get_line(); + m_line_save = io->Get_m_line_save(); + m_line = io->Get_m_line(); + m_next_keyword = io->Get_m_next_keyword(); + if (accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + return m_line_type; +} + +PHRQ_io::LINE_TYPE CParser::get_line() +{ + if (this->phrq_io_only) + { + return get_line_phrq_io(); + } + PHRQ_io::LINE_TYPE return_value = PHRQ_io::LT_EMPTY; + while (return_value == PHRQ_io::LT_EMPTY) + { + // + // Eliminate all characters after # sign as a comment + // + + // + // Get line, check for eof + // + if (get_logical_line() == PHRQ_io::LT_EOF) + { + if (!m_input_stream.eof()) + { + error_msg("Reading input file.", PHRQ_io::OT_CONTINUE); + error_msg("istream::get() returned an error.", PHRQ_io::OT_STOP); + } + else + { + //{{MOD + m_line.erase(m_line.begin(), m_line.end()); // m_line.clear(); + //}}MOD + m_next_keyword = Keywords::KEY_END; + return PHRQ_io::LT_EOF; + } + } + + // + // Get long lines + // + bool + empty = true; + m_line = m_line_save.substr(0, m_line_save.find_first_of('#')); + for (unsigned int i = 0; i < m_line.size(); ++i) + { + if (!::isspace(m_line[i])) + { + empty = false; + break; + } + } + + if (this->accumulate) + { + this->accumulated.append(m_line_save); + this->accumulated.append("\n"); + } + // + // New line character encountered + // + return_value = (empty ? PHRQ_io::LT_EMPTY : PHRQ_io::LT_OK); + } + + // + // Determine return_value + // + if (return_value == PHRQ_io::LT_OK) + { + if (check_key(m_line.begin(), m_line.end())) + { + return_value = PHRQ_io::LT_KEYWORD; + } + else + { + std::string::iterator beg = m_line.begin(); + std::string::iterator end = m_line.end(); + std::string token; + copy_token(token, beg, end); + + if (token.size() > 1 && token[0] == '-' &&::isalpha(token[1])) + { + return_value = PHRQ_io::LT_OPTION; + } + } + } + return return_value; +} + +/** + Reads input stream until end of line, ";", or eof + stores characters in line_save + + returns: + EOF on empty line on end of file or + OK otherwise +*/ +PHRQ_io::LINE_TYPE CParser::get_logical_line() +{ + int + j; + unsigned int + pos; + char + c; + + m_line_save.erase(m_line_save.begin(), m_line_save.end()); // m_line_save.clear(); + + while ((j = m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '#') + { + // ignore all chars after # until newline + do + { + c = (char) j; + if (c == '\n') + { + break; + } + m_line_save += c; + } + while ((j = + m_input_stream.get()) != std::char_traits < + char >::eof()); + } + if (c == ';') + break; + if (c == '\n') + { + break; + } + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + while ((j = + m_input_stream.get()) != std::char_traits < char >::eof()) + { + c = (char) j; + if (c == '\\') + { + pos = (int) m_line_save.size(); + m_line_save += c; + continue; + } + if (c == '\n') + { + // remove '\\' + for (; pos < m_line_save.size(); pos++) + { + m_line_save[pos] = m_line_save[pos + 1]; + } + m_line_save.erase(m_line_save.size() - 1, 1); + break; + } + m_line_save += c; + if (!::isspace(j)) + break; + } + } + else + { + m_line_save += c; + } + } + if (j == std::char_traits < char >::eof() && m_line_save.size() == 0) + { + return (PHRQ_io::LT_EOF); + } + return (PHRQ_io::LT_OK); +} + +bool +CParser::check_key(std::string::iterator begin, std::string::iterator end) +{ + std::string lowercase; + copy_token(lowercase, begin, end); + std::transform(lowercase.begin(), lowercase.end(), lowercase.begin(), + tolower); + m_next_keyword = Keywords::Keyword_search(lowercase); + if (m_next_keyword == Keywords::KEY_NONE) + { + return false; + } + return true; +} +CParser::STATUS_TYPE CParser::check_units(std::string & tot_units, + bool alkalinity, + bool check_compatibility, + const std::string & default_units, + bool print) +{ +/* + * Check if legitimate units + * Input: + * tot_units character string to check, + * alkalinity true if alkalinity, false if any other total, + * check_compatibility true check alk and default units, false otherwise + * default_units character string of default units (check /L, /kg, etc) + * print true print warning messages + * Output: + * tot_units standard form for unit + */ + using + Utilities::str_tolower; + using + Utilities::replace; + using + Utilities::squeeze_white; + + static const char * + units[] = { + "Mol/l", /* 0 */ + "mMol/l", /* 1 */ + "uMol/l", /* 2 */ + "g/l", /* 3 */ + "mg/l", /* 4 */ + "ug/l", /* 5 */ + "Mol/kgs", /* 6 */ + "mMol/kgs", /* 7 */ + "uMol/kgs", /* 8 */ + "g/kgs", /* 9 = ppt */ + "mg/kgs", /* 10 = ppm */ + "ug/kgs", /* 11 = ppb */ + "Mol/kgw", /* 12 = mol/kg H2O */ + "mMol/kgw", /* 13 = mmol/kg H2O */ + "uMol/kgw", /* 14 = umol/kg H2O */ + "g/kgw", /* 15 = mol/kg H2O */ + "mg/kgw", /* 16 = mmol/kg H2O */ + "ug/kgw", /* 17 = umol/kg H2O */ + "eq/l", /* 18 */ + "meq/l", /* 19 */ + "ueq/l", /* 20 */ + "eq/kgs", /* 21 */ + "meq/kgs", /* 22 */ + "ueq/kgs", /* 23 */ + "eq/kgw", /* 24 */ + "meq/kgw", /* 25 */ + "ueq/kgw", /* 26 */ + }; + + squeeze_white(tot_units); + str_tolower(tot_units); + replace("milli", "m", tot_units); + replace("micro", "u", tot_units); + replace("grams", "g", tot_units); + replace("gram", "g", tot_units); + replace("moles", "Mol", tot_units); + replace("mole", "Mol", tot_units); + replace("mol", "Mol", tot_units); + replace("liter", "l", tot_units); + replace("kgh", "kgw", tot_units); + replace("ppt", "g/kgs", tot_units); + replace("ppm", "mg/kgs", tot_units); + replace("ppb", "ug/kgs", tot_units); + replace("equivalents", "eq", tot_units); + replace("equivalent", "eq", tot_units); + replace("equiv", "eq", tot_units); + + std::string::size_type end; + if ((end = tot_units.find("/l")) != std::string::npos) + { + tot_units.resize(end + 2); + } + if ((end = tot_units.find("/kgs")) != std::string::npos) + { + tot_units.resize(end + 4); + } + if ((end = tot_units.find("/kgw")) != std::string::npos) + { + tot_units.resize(end + 4); + } + + // + // Check if unit in list + // + bool + found = false; + for (unsigned int i = 0; i < sizeof(units) / sizeof(char *); ++i) + { + if (tot_units.compare(units[i]) == 0) + { + found = true; + break; + } + } + if (!found) + { + if (print) + { + std::ostringstream err; + err << "Unknown unit, " << tot_units; + this->error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // Check if units are compatible with default_units + // + if (check_compatibility == false) + return PARSER_OK; + + // + // Special cases for alkalinity + // + if (alkalinity == true && tot_units.find("Mol") != std::string::npos) + { + if (print) + { + this->warning_msg + ("Alkalinity given in moles, assumed to be equivalents."); + } + replace("Mol", "eq", tot_units); + } + if (alkalinity == false && tot_units.find("eq") != std::string::npos) + { + if (print) + { + this->error_msg("Only alkalinity can be entered in equivalents.", + PHRQ_io::OT_CONTINUE); + } + return PARSER_ERROR; + } + + // + // See if default_units are compatible with tot_units + // + if (default_units.find("/l") != std::string::npos + && tot_units.find("/l") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgs") != std::string::npos + && tot_units.find("/kgs") != std::string::npos) + return PARSER_OK; + if (default_units.find("/kgw") != std::string::npos + && tot_units.find("/kgw") != std::string::npos) + return PARSER_OK; + + std::string str = default_units; + replace("kgs", "kg solution", str); + replace("kgs", "kg solution", tot_units); + replace("kgw", "kg water", str); + replace("kgw", "kg water", tot_units); + replace("/l", "/L", str); + replace("Mol", "mol", str); + replace("/l", "/L", tot_units); + replace("Mol", "mol", tot_units); + + if (print) + { + std::ostringstream err; + err << "Units for master species, " << tot_units << + ", are not compatible with default units, " << str << "."; + this->error_msg(err.str().c_str(), PHRQ_io::OT_CONTINUE); + } + return PARSER_ERROR; +} +CParser::TOKEN_TYPE CParser::token_type(const std::string & token) +{ + if (!token.empty()) + { + if (::isupper(token[0])) + { + return CParser::TT_UPPER; + } + else if (::islower(token[0])) + { + return CParser::TT_LOWER; + } + else if (::isdigit(token[0]) || token[0] == '.' || token[0] == '-') + { + return CParser::TT_DIGIT; + } + else + { + assert(!::isspace(token[0])); + return CParser::TT_UNKNOWN; + } + } + else + { + return CParser::TT_EMPTY; + } +} + +CParser::TOKEN_TYPE CParser::peek_token() +{ + std::istringstream::pos_type pos = m_line_iss.tellg(); + std::string token; + m_line_iss >> token; + m_line_iss.seekg(pos); + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) +{ + if (begin != end) + { + std::string::iterator b = begin; + for (; b < end &&::isspace(*b); ++b); + + begin = b; + for (; begin < end && !::isspace(*begin); ++begin); + + token.assign(b, begin); + } + else + { + token.resize(0); + } + + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::istream & is) +{ + is >> token; + return token_type(token); +} + +CParser::TOKEN_TYPE CParser::copy_token(std::string & token, + std::istream::pos_type & pos) +{ + m_line_iss.seekg(pos); + if (!(m_line_iss >> token)) + { + token.erase(token.begin(), token.end()); // token.clear(); + } + pos = m_line_iss.tellg(); + return token_type(token); +} + +CParser::FIND_TYPE CParser::find_option(const std::string & item, int *n, + const std::vector < std::string > + &list, bool exact) +{ + std::string token(item); + std::transform(token.begin(), token.end(), token.begin(), tolower); + for (unsigned int i = 0; i < list.size(); i++) + { + if (exact == true) + { + if (list[i].compare(token) == 0) + { + *n = i; + return FT_OK; + } + } + else + { + if (list[i].find(token) == 0) + { + *n = i; + return FT_OK; + } + } + } + + *n = -1; + return FT_ERROR; +} + +int +CParser::get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + std::string::iterator opt_ptr; + std::string option; + +#if !defined(R_SO) + fprintf(stderr, "Did not think this get_option was called\n"); +#endif + // + // Read line + // + PHRQ_io::LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == PHRQ_io::LT_EOF) + { + j = OPT_EOF; + } + else if (lt == PHRQ_io::LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == PHRQ_io::LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + } + } + else + { + if (true) // (database_file == NULL) + { + //get_output() << "\t" << m_line_save << "\n"; + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + + std::ostringstream err; + err << "Unknown option." << "\n"; + err << m_line_save << "\n"; + error_msg(err.str().c_str()); + + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { +#if !defined(R_SO) + std::cout << "\t" << m_line_save << "\n"; +#endif + } + } + } + return (j); +} + +int +CParser::get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + PHRQ_io::LINE_TYPE lt = check_line("get_option", false, true, true, true); + if (lt == PHRQ_io::LT_EOF) + { + j = OPT_EOF; + } + else if (lt == PHRQ_io::LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == PHRQ_io::LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + } + else + { + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = m_line_iss.tellg(); + m_line_iss >> option; + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = m_line_iss.tellg(); + } + else + { + j = OPT_DEFAULT; + m_line_iss.seekg(pos_ptr); + m_line_iss.clear(); + next_pos = pos_ptr; + } + } + return (j); +} +CParser::STATUS_TYPE CParser::get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element) +{ + element.erase(element.begin(), element.end()); // element.clear(); + + if (begin == end) + { + error_msg("Empty string in get_elt. Expected an element name.", + PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + + // + // Load name into char array element + // + char + c = *begin; + ++begin; + element.insert(element.end(), c); // element.push_back(c); + if (c == '[') + { + while ((c = *begin) != ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if ((c = *begin) == ']') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + break; + } + else if (begin == end) + { + error_msg("No ending bracket (]) for element name", + PHRQ_io::OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + } + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + else + { + while (::islower(c = *begin) || c == '_') + { + element.insert(element.end(), c); // element.push_back(c); + ++begin; + if (begin == end) + break; + } + } + return PARSER_OK; +} + +CParser::STATUS_TYPE CParser::parse_couple(std::string & token) +{ + // Parse couple puts redox couples in standard form + // "+" is removed and couples are rewritten in sort + // order. + + if (Utilities::strcmp_nocase_arg1(token.c_str(), "pe") == 0) + { + Utilities::str_tolower(token); + return PARSER_OK; + } + + while (Utilities::replace("+", "", token)); + + std::string::iterator ptr = token.begin(); + std::string elt1; + get_elt(ptr, token.end(), elt1); + + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " << + "parentheses in redox couple, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + + int + paren_count = 1; + std::string paren1 = "("; + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + paren1.insert(paren1.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } + + ++ptr; + if (ptr == token.end() || *ptr != '/') + { + std::ostringstream err_msg; + err_msg << " " "/" " must follow parentheses " << + "ending first half of redox couple, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + ++ptr; + std::string elt2; + get_elt(ptr, token.end(), elt2); + if (elt1.compare(elt2) != 0) + { + std::ostringstream err_msg; + err_msg << "Redox couple must be two redox states " << + "of the same element, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + if (*ptr != '(') + { + std::ostringstream err_msg; + err_msg << "Element name must be followed by " + "parentheses in redox couple, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + incr_input_error(); + return PARSER_ERROR; + } + std::string paren2 = "("; + paren_count = 1; + + while (ptr != token.end()) + { + ++ptr; + if (*ptr == '/' || ptr == token.end()) + { + std::ostringstream err_msg; + err_msg << "End of line or " "/" + " encountered before end of parentheses, " << token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + paren2.insert(paren2.end(), *ptr); // element.push_back(c); + if (*ptr == '(') + ++paren_count; + if (*ptr == ')') + --paren_count; + if (paren_count == 0) + break; + } + if (paren1.compare(paren2) < 0) + { + token = elt1 + paren1 + std::string("/") + elt2 + paren2; + } + else if (paren1.compare(paren2) > 0) + { + token = elt2 + paren2 + std::string("/") + elt1 + paren1; + } + else + { + std::ostringstream err_msg; + err_msg << "Both parts of redox couple are the same, " << + token << "."; + error_msg(err_msg.str().c_str(), PHRQ_io::OT_CONTINUE); + return PARSER_ERROR; + } + return PARSER_OK; +} + +template +CParser::STATUS_TYPE CParser::addPair(std::map < std::string, T >&totals, + std::istream::pos_type & pos) +{ + std::string token; + T d; + CParser::TOKEN_TYPE j; + + m_line_iss.seekg(pos); + + j = copy_token(token, pos); + + if (j == CParser::TT_EMPTY) + return PARSER_OK; + + if (!(m_line_iss >> d)) + { + return PARSER_ERROR; + } + totals[token] = d; + return PARSER_OK; +} + +int +CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char, bool flag_error) +{ + // + // Read a line and check for options + // + int j; + int /* opt_l, */ opt; + std::string::iterator opt_ptr; + std::string option; + + // + // Read line + // + PHRQ_io::LINE_TYPE lt = m_line_type; + if (lt == PHRQ_io::LT_EOF) + { + j = OPT_EOF; + } + else if (lt == PHRQ_io::LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == PHRQ_io::LT_OPTION) + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, false) == CParser::FT_OK) + { + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + next_char = opt_ptr; + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + } + } + else + { + if (flag_error) + { + if (true) // (database_file == NULL) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + std::ostringstream err; + err << "Unknown option." << "\n"; + err << m_line_save << "\n"; + error_msg(err.str().c_str()); + } + j = OPT_ERROR; + next_char = m_line.begin(); + } + } + else + { + opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_char = opt_ptr; + } + else + { + j = OPT_DEFAULT; + next_char = m_line.begin(); + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { +#if !defined(R_SO) + std::cout << "\t" << m_line_save << "\n"; +#endif + } + } + } + return (j); +} + +int +CParser::getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos, bool flag_error) +{ + // + // Read a line and check for options + // + int j; + int opt; + std::istream::pos_type pos_ptr; + std::string option; + + // + // Read line + // + PHRQ_io::LINE_TYPE lt = m_line_type; + if (lt == PHRQ_io::LT_EOF) + { + j = OPT_EOF; + } + else if (lt == PHRQ_io::LT_KEYWORD) + { + j = OPT_KEYWORD; + } + else if (lt == PHRQ_io::LT_OPTION) + { + std::string::iterator opt_ptr = m_line.begin(); + std::string::iterator end = m_line.end(); + copy_token(option, opt_ptr, end); + if (find_option(option.substr(1), &opt, opt_list, false) == FT_OK) + { + // replace -option with option + j = opt; + m_line_save.replace(m_line_save.find(option), option.size(), + opt_list[opt]); + m_line.replace(m_line.find(option), option.size(), opt_list[opt]); + + // reset iss + m_line_iss.str(m_line); + m_line_iss.seekg(0, std::ios_base::beg); + m_line_iss.clear(); + + pos_ptr = 0; + copy_token(option, pos_ptr); + next_pos = pos_ptr; + //if (this->echo_file) // pr.echo_input == TRUE + if (false) + { + if (true) // database_file == NULL + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + } + } + else + { + if (flag_error) // don`t throw error + { + if (true) // (database_file == NULL) + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + error_msg("Unknown option.", PHRQ_io::OT_CONTINUE); + error_msg(m_line_save.c_str(), PHRQ_io::OT_CONTINUE); + incr_input_error(); + } + j = OPT_ERROR; + next_pos = pos_ptr; + } + } + else + { + pos_ptr = 0; + copy_token(option, pos_ptr); + if (find_option(option, &opt, opt_list, true) == FT_OK) + { + j = opt; + next_pos = pos_ptr; + } + else + { + j = OPT_DEFAULT; + next_pos = 0; + } + if (true) // pr.echo_input == TRUE + { + if (true) // database_file == NULL + { + std::ostringstream msg; + msg << "\t" << m_line_save << "\n"; + io->output_msg(msg.str().c_str()); + } + } + } + return (j); +} +int CParser:: +incr_input_error() +{ + return ++m_input_error; +} + +CParser::TOKEN_TYPE CParser::copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end) +{ + if (begin != end) + { + std::string::iterator b = begin; + std::string::iterator e = end; + for (; b < end && (::isspace(*b) || (*b == ',')); ++b); + begin = b; + if (*begin == '"') + { + begin = ++b; + for (; begin != end && !(*begin == '"'); ++begin); + e = begin; + if (begin != end && *begin == '"') + { + e = begin++; + } + } + else if (*begin == '\'') + { + begin = ++b; + for (; begin != end && !(*begin == '\''); ++begin); + e = begin; + if (begin != end && *begin == '\'') + { + e = begin++; + } + } + else + { + for (; begin < end && !(*begin == ',') && !(::isspace(*begin)); ++begin); + e = begin; + } + token.assign(b, e); + } + else + { + token.resize(0); + } + token = trim(token); + return token_type(token); +} +bool CParser::get_true_false(std::istream::pos_type & pos, bool def) +{ + std::string token; + this->copy_token(token, pos); + std::string::iterator b = token.begin(); + for (; b != token.end() && (::isspace(*b)); ++b); + if (b != token.end()) + { + if (*b == 'f' || *b == 'F') + { + return false; + } + else if (*b == 't' || *b == 'T') + { + return true; + } + } + return def; +} +CParser::TOKEN_TYPE CParser::get_rest_of_line(std::string &token) +{ + token.clear(); + int j; + while ((j = m_line_iss.get()) != std::char_traits < char >::eof()) + { + char c = (char) j; + token += c; + } + token = trim(token); + return token_type(token); +} +CParser::TOKEN_TYPE CParser::parse_delimited(std::string & source, std::string & result, + const std::string& t = " \t") +{ + + size_t pos = source.find_first_of(t); + std::string temp; + if (pos != std::string::npos) + { + result = source.substr(0, pos); + temp = source.substr(pos+1); + source = temp; + } + else + { + result = source; + source.clear(); + } + std::string str = result; + + return token_type(trim_left(str)); +} \ No newline at end of file diff --git a/Parser.h b/Parser.h new file mode 100644 index 00000000..3bf093a1 --- /dev/null +++ b/Parser.h @@ -0,0 +1,296 @@ +#if !defined(PARSER_H_INCLUDED) +#define PARSER_H_INCLUDED +#if defined(WIN32) +#include +#endif +#include // std::string +#include // std::map +#include // std::vector +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include // std::isspace +#include // std::find_if +#include // std::ptr_fun std::not1 + +#include "PHRQ_base.h" +#include "Keywords.h" +#include "PHRQ_io.h" + +#ifdef _DEBUG +#define isspace(a) isspace((a) < -1 ? (a) + 256 : (a)) +#define isupper(a) isupper((a) < -1 ? (a) + 256 : (a)) +#define islower(a) islower((a) < -1 ? (a) + 256 : (a)) +#define isdigit(a) isdigit((a) < -1 ? (a) + 256 : (a)) +#define isalpha(a) isalpha((a) < -1 ? (a) + 256 : (a)) +#endif + +class CParser: public PHRQ_base +{ + public: + CParser(PHRQ_io *io=NULL); + CParser(std::istream & input, PHRQ_io *io=NULL); + //CParser(std::istream & input, std::ostream & output, PHRQ_io *io=NULL); + //CParser(std::istream & input, std::ostream & output, + // std::ostream & error, PHRQ_io *io=NULL); + + virtual ~ CParser(); + enum TOKEN_TYPE + { + TT_EMPTY = 2, + TT_UPPER = 4, + TT_LOWER = 5, + TT_DIGIT = 6, + TT_UNKNOWN = 7 + }; + + enum FIND_TYPE + { + FT_OK = 0, + FT_ERROR = 1 + }; + + enum OPT_TYPE + { + OPT_DEFAULT = -4, + OPT_ERROR = -3, + OPT_KEYWORD = -2, + OPT_EOF = -1 + }; + enum ECHO_OPTION + { + EO_NONE = 0, + EO_ALL = 1, + EO_KEYWORDS = 2, + EO_NOKEYWORDS = 3 + }; + + enum STATUS_TYPE + { + PARSER_ERROR = 0, + PARSER_OK = 1 + }; + + + /** + Function gets a new line and checks for empty, eof, and keywords. + + Arguments: + string Input, character string used in printing error message + allow_empty Input, True or false, if a blank line is accepable + if false, another line is read + allow_eof Input, True or false, if EOF is acceptable + allow_keyword Input, True or false, if a keyword is acceptable + + Returns: + LT_EMPTY if empty line read and allow_empty == true + LT_KEYWORD if line begins with keyword + LT_EOF if eof and allow_eof == true + LT_OK otherwise + LT_OPTION if line begins with -[alpha] + + Terminates if EOF and allow_eof == false. + */ + PHRQ_io::LINE_TYPE check_line(const std::string & str, bool allow_empty, + bool allow_eof, bool allow_keyword, bool print); + + /** + Read a line from input file put in "line". + Copy of input line is stored in "line_save". + Characters after # are discarded in line but retained in "line_save" + + Arguments: + None + Returns: + LT_EMPTY, + LT_EOF, + LT_KEYWORD, + LT_OK, + LT_OPTION + */ + PHRQ_io::LINE_TYPE get_line(); + PHRQ_io::LINE_TYPE get_line_phrq_io(); + + // bool check_key(const std::string::iterator ptr); + bool check_key(std::string::iterator begin, std::string::iterator end); + + STATUS_TYPE check_units(std::string & tot_units, bool alkalinity, + bool check_compatibility, + const std::string & default_units, bool print); + + + //KEY_TYPE next_keyword() const + Keywords::KEYWORDS next_keyword() const + { + return m_next_keyword; + } + int get_option(const std::vector < std::string > &opt_list, + std::string::iterator & next_char); + int get_option(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::string::iterator & next_char, bool flag_error); + int getOptionFromLastLine(const std::vector < std::string > &opt_list, + std::istream::pos_type & next_pos, bool flag_error); + + + std::string & line() + { + return m_line; + } + std::string & line_save() + { + return m_line_save; + } + std::string & get_accumulated() + { + return accumulated; + } + void set_accumulate(bool tf) + { + if (tf) + { + accumulated.clear(); + } + this->accumulate = tf; + } + std::istringstream & get_iss() + { + return m_line_iss; + } + int incr_input_error(); + int get_input_error() + { + return m_input_error; + } + + /** + Copies from begin to token until first space is encountered. + + Arguments: + token output, the token + begin input, begin iterator + end input, end iterator + + Returns: + TT_EMPTY + TT_UPPER + TT_LOWER + TT_DIGIT + TT_UNKNOWN + */ + static CParser::TOKEN_TYPE copy_token(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); + static CParser::TOKEN_TYPE copy_title(std::string & token, + std::string::iterator & begin, + std::string::iterator & end); + static CParser::TOKEN_TYPE token_type(const std::string & token); + static CParser::TOKEN_TYPE copy_token(std::string & token, std::istream & is); + CParser::TOKEN_TYPE copy_token(std::string & token, std::istream::pos_type & pos); + bool get_true_false(std::istream::pos_type & pos, bool def); + CParser::TOKEN_TYPE get_rest_of_line(std::string &token); + static CParser::TOKEN_TYPE parse_delimited(std::string & source, std::string & result, const std::string& t); + CParser::TOKEN_TYPE peek_token(); + PHRQ_io::LINE_TYPE get_m_line_type(void) const {return this->m_line_type;} + + /** + Function reads an element name out of the equation string. + An element name is composed of a capital letter followed by any number + of lower case characters. + + Arguments: + begin input, points to position in the equation to begin + output, points to next character of equation after + element name. + end input, points to last position in the equation + element input pointer to place to return element character string + */ + STATUS_TYPE get_elt(std::string::iterator & begin, + const std::string::iterator end, + std::string & element); + + + /** + Compares a string value to match beginning letters of a list of options + + Arguments: + item entry: pointer to string to compare + n exit: item in list that was matched + list entry: pointer to list of character values, assumed to + be lower case + count_list entry: number of character values in list + + Returns: + OK item matched + ERROR item not matched + n -1 item not matched + i position of match in list + */ + static FIND_TYPE find_option(const std::string & item, int *n, + const std::vector < std::string > &list, + bool exact); + + void set_echo_file(ECHO_OPTION opt) + { + echo_file = opt; + } + ECHO_OPTION get_echo_file() + { + return this->echo_file; + }; + + void set_echo_stream(ECHO_OPTION opt) + { + echo_stream = opt; + } + ECHO_OPTION get_echo_stream() + { + return this->echo_stream; + }; + + STATUS_TYPE parse_couple(std::string & token); + + template + STATUS_TYPE addPair(std::map < std::string, T >&totals, + std::istream::pos_type & pos); + + protected: + PHRQ_io::LINE_TYPE get_logical_line(); + + protected: + std::istream & m_input_stream; + //std::ostream & m_output_stream; + //std::ostream & m_error_stream; + int m_input_error; + //KEY_TYPE m_next_keyword; + Keywords::KEYWORDS m_next_keyword; + std::string m_line; + std::string m_line_save; + std::istringstream m_line_iss; + PHRQ_io::LINE_TYPE m_line_type; + ECHO_OPTION echo_stream; + ECHO_OPTION echo_file; + std::string accumulated; + bool accumulate; + bool phrq_io_only; + +}; + +// Global functions +static inline std::string &trim_left(std::string &s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); + return s; +} +static inline std::string &trim_right(std::string &s) +{ + s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + return s; +} +static inline std::string &trim(std::string &s) +{ + return trim_left(trim_right(s)); +} + +#endif // PARSER_H_INCLUDED diff --git a/Utils.cxx b/Utils.cxx new file mode 100644 index 00000000..453218d3 --- /dev/null +++ b/Utils.cxx @@ -0,0 +1,186 @@ +#ifdef _DEBUG +#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger) +#endif +#include // ::tolower +#include // ::tolower +#include // std::transform +#include // std::cout std::cerr +#include + +#include "Utils.h" +#include "Parser.h" +#include "float.h" +#include "math.h" + +//////////////////////////////////////////////////////////////////////////// +int +Utilities::strcmp_nocase_arg1(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 =::tolower(*str1++)) == (c2 = *str2++)) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); +} + +//////////////////////////////////////////////////////////////////////////// +int +Utilities::strcmp_nocase(const char *str1, const char *str2) +//////////////////////////////////////////////////////////////////////////// +{ + // + // Compare two strings disregarding case + // + int c1, c2; + while ((c1 =::tolower(*str1++)) == (c2 =::tolower(*str2++))) + { + if (c1 == '\0') + return (0); + } + if (c1 < c2) + return (-1); + return (1); +} + +//////////////////////////////////////////////////////////////////////////// +void +Utilities::str_tolower(std::string & str) +//////////////////////////////////////////////////////////////////////////// +{ + std::transform(str.begin(), str.end(), str.begin(), tolower); +} + +//////////////////////////////////////////////////////////////////////////// +void +Utilities::str_toupper(std::string & str) +//////////////////////////////////////////////////////////////////////////// +{ + std::transform(str.begin(), str.end(), str.begin(), toupper); +} +//////////////////////////////////////////////////////////////////////////// +std::string +Utilities::pad_right(const std::string & str, size_t l) +//////////////////////////////////////////////////////////////////////////// +{ + std::string new_str(str); + size_t length = new_str.size(); + if (length < l) + { + new_str = new_str.insert(length, l - length, ' '); + } + return new_str; +} + + +//////////////////////////////////////////////////////////////////////////// +bool +Utilities::replace(const char *str1, const char *str2, std::string & str) +//////////////////////////////////////////////////////////////////////////// +{ + std::string::size_type n = str.find(str1, 0); + if (n == std::string::npos) + return false; + + str.replace(n, ::strlen(str1), str2); + return true; +} + +//////////////////////////////////////////////////////////////////////////// +void +Utilities::squeeze_white(std::string & s_l) +//////////////////////////////////////////////////////////////////////////// +{ + std::string str; + std::string::iterator beg = s_l.begin(); + std::string::iterator end = s_l.end(); + //CParser::copy_token(str, beg, end); + std::string::iterator pos; + for (pos = beg; pos != end; pos++) + { + int c = *pos; + if (!::isspace(c)) + { + str += c; + } + } + s_l = str; +} +//////////////////////////////////////////////////////////////////////////// +double +Utilities::convert_time(double t, std::string in, std::string out) +//////////////////////////////////////////////////////////////////////////// +{ + Utilities::str_tolower(in); + + // convert t to seconds + if (in.substr(0,1) == "m") + { + t = t * 60.; + } + if (in.substr(0,1) == "h") + { + t = t * 3600.; + } + if (in.substr(0,1) == "d") + { + t = t * 3600. * 24.; + } + if (in.substr(0,1) == "y") + { + t = t * 3600. * 24. * 365.25; + } + // convert to ouput units + if (out.substr(0,1) == "m") + { + t = t / 60.; + } + if (out.substr(0,1) == "h") + { + t = t / 3600.; + } + if (out.substr(0,1) == "d") + { + t = t / ( 3600. * 24.); + } + if (out.substr(0,1) == "y") + { + t = t / (3600. * 24. * 365.25); + } + return t; + +} +LDBLE +Utilities::safe_exp(LDBLE t) +//////////////////////////////////////////////////////////////////////////// +{ + LDBLE f = 1.442695*t; // convert to exp for 2.0 + + if (f > DBL_MAX_EXP - 50.0) + { + return pow(2, DBL_MAX_EXP - 50.0); + } + else if (f < DBL_MIN_EXP + 50.0) + { + return pow(2, DBL_MIN_EXP + 50.0); + } + return exp(t); +} +//+NAN LDBLE: 7ff8000000000000 +//-NAN LDBLE: fff8000000000000 +/* +LDBLE Utilities::get_nan(void) +{ + unsigned long long raw = 0x7ff0000000000000; + LDBLE d = *( LDBLE* )&raw; + return(d); + +} +*/ diff --git a/Utils.h b/Utils.h new file mode 100644 index 00000000..74997731 --- /dev/null +++ b/Utils.h @@ -0,0 +1,28 @@ +#if !defined(UTILITIES_H_INCLUDED) +#define UTILITIES_H_INCLUDED + +#include +#include // std::istringstream std::ostringstream +#include // std::ostream +#include // std::istream +#include // std::map +#include "phrqtype.h" +namespace Utilities +{ + + const char INDENT[] = " "; + + int strcmp_nocase(const char *str1, const char *str2); + + int strcmp_nocase_arg1(const char *str1, const char *str2); + + void str_tolower(std::string & str); + void str_toupper(std::string & str); + std::string pad_right(const std::string & str, size_t l); + bool replace(const char *str1, const char *str2, std::string & str); + + void squeeze_white(std::string & s_l); + double convert_time(double t, std::string in, std::string out); + LDBLE safe_exp(LDBLE t); +} +#endif // UTILITIES_H_INCLUDED diff --git a/phrqtype.h b/phrqtype.h new file mode 100644 index 00000000..ab7160b5 --- /dev/null +++ b/phrqtype.h @@ -0,0 +1,18 @@ +#ifndef _INC_PHRQTYPE_H +#define _INC_PHRQTYPE_H +/* + * The following implements long double + * Many machines long double = double so there is no advantage + * Check float.h include file for number of digits (LDBL_DIG) + * Need to define here and in cl1.c + */ + +/*#define USE_LONG_DOUBLE*/ +#ifdef USE_LONG_DOUBLE +#define LDBLE long double +#define SCANFORMAT "%Lf" +#else +#define LDBLE double +#define SCANFORMAT "%lf" +#endif +#endif /* _INC_PHRQTYPE_H */ From e6d44638b3659543a373c83f2ca35f68c517a830 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 27 Aug 2015 15:22:34 +0000 Subject: [PATCH 0929/1077] Extra print for Donnan Layer psi from Tony. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10177 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 2ccb2588..cbc043e5 100644 --- a/print.cpp +++ b/print.cpp @@ -329,8 +329,13 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) } else { + LDBLE exp_g = charge_ptr->Get_g_map()[1].Get_g() * mass_water_aq_x / mass_water_surface + 1; + LDBLE psi_DL = -log(exp_g) * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ; output_msg(sformatf( - "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation \n\n")); + "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation.")); + output_msg(sformatf( + "\n\tDonnan Layer potential, psi_DL = %10.3e V.\n\tBoltzmann factor, exp(-psi_DL * F / RT) = %9.3e (= c_DL / c_free if z is +1).\n\n", + psi_DL, exp_g)); } output_msg(sformatf("\tElement \t Moles\n")); for (j = 0; j < count_elts; j++) @@ -2238,6 +2243,23 @@ print_totals(void) (double) calc_solution_volume())); } /* VP: Density End */ +#ifdef NPP + if (print_viscosity) + { + output_msg(sformatf("%45s%9.5f", "Viscosity (mPa s) = ", + (double) viscos)); + if (tc_x > 200 && !pure_water) + { + output_msg(sformatf("%18s\n", +#ifdef NO_UTF8_ENCODING + " (solute contributions limited to 200 oC)")); +#else + " (solute contributions limited to 200 °C)")); +#endif + } + else output_msg(sformatf("\n")); + } +#endif output_msg(sformatf("%45s%7.3f\n", "Activity of water = ", exp(s_h2o->la * LOG_10))); output_msg(sformatf("%45s%11.3e\n", "Ionic strength = ", From 560306e061bf1abc8ea5097bb56a9d9089307687 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Sep 2015 22:10:13 +0000 Subject: [PATCH 0930/1077] reran test cases. Diffs caused by CO2 changes in database git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10233 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 1037 +++++++++++++++++++++++++++----------------------- 1 file changed, 563 insertions(+), 474 deletions(-) diff --git a/Makefile.old b/Makefile.old index 8cef0b75..5e1f32bc 100644 --- a/Makefile.old +++ b/Makefile.old @@ -125,8 +125,8 @@ ifeq ($(CFG), CLASS_DEBUG) CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../PhreeqcKeywords - INCLUDES = -I.. -I../PhreeqcKeywords + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -142,8 +142,8 @@ ifeq ($(CFG), CLASS_RELEASE) CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../PhreeqcKeywords - INCLUDES = -I.. -I../PhreeqcKeywords + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common CXX = g++ CXXFLAGS = -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -158,8 +158,8 @@ ifeq ($(CFG), CLASS_DEBUG_64) CL1MP_LIB=libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../PhreeqcKeywords - INCLUDES = -I.. -I../PhreeqcKeywords + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common CXX = g++ CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) @@ -174,8 +174,8 @@ ifeq ($(CFG), CLASS_RELEASE_64) CL1MP_LIB=/usr/lib64/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DUSE_PHRQ_ALLOC # -DR_SO - VPATH = ..:../PhreeqcKeywords - INCLUDES = -I.. -I../PhreeqcKeywords + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common CXX = g++ PROFILE = CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g @@ -288,573 +288,662 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # -cxxKinetics.o: ../cxxKinetics.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../cxxKinetics.h ../KineticsComp.h ../phqalloc.h -cxxMix.o: ../cxxMix.cxx ../Utils.h ../phrqtype.h ../Parser.h \ - ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h -Exchange.o: ../Exchange.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Exchange.h ../ExchComp.h ../phqalloc.h -ExchComp.o: ../ExchComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../ExchComp.h ../phqalloc.h -GasComp.o: ../GasComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../GasComp.h ../phqalloc.h -GasPhase.o: ../GasPhase.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../GasPhase.h ../GasComp.h ../phqalloc.h -ISolutionComp.o: ../ISolutionComp.cxx ../Utils.h ../phrqtype.h \ - ../ISolutionComp.h ../Parser.h ../PHRQ_base.h \ - ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Solution.h ../NumKeyword.h \ - ../SolutionIsotope.h ../NameDouble.h ../ISolution.h \ +cxxKinetics.o: ../cxxKinetics.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../cxxKinetics.h ../KineticsComp.h \ + ../phqalloc.h +cxxMix.o: ../cxxMix.cxx ../common/Utils.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h \ + ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Exchange.o: ../Exchange.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Exchange.h ../ExchComp.h ../phqalloc.h +ExchComp.o: ../ExchComp.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../ExchComp.h ../phqalloc.h +GasComp.o: ../GasComp.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../GasComp.h ../phqalloc.h +GasPhase.o: ../GasPhase.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../GasPhase.h ../GasComp.h ../phqalloc.h +ISolutionComp.o: ../ISolutionComp.cxx ../common/Utils.h \ + ../common/phrqtype.h ../ISolutionComp.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../common/PHRQ_base.h ../Solution.h ../NumKeyword.h \ + ../SolutionIsotope.h ../NameDouble.h ../common/PHRQ_io.h ../ISolution.h \ ../global_structures.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ ../NA.h ../phqalloc.h -ISolution.o: ../ISolution.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../ISolution.h ../ISolutionComp.h ../phqalloc.h -KineticsComp.o: ../KineticsComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../KineticsComp.h ../phqalloc.h -NameDouble.o: ../NameDouble.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../ISolutionComp.h -NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../PHRQ_base.h \ - ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Utils.h \ - ../phrqtype.h -Parser.o: ../Parser.cxx ../Utils.h ../phrqtype.h ../Parser.h \ - ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h -PHRQ_base.o: ../PHRQ_base.cxx ../PHRQ_base.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h -PPassemblageComp.o: ../PPassemblageComp.cxx ../Utils.h ../phrqtype.h \ - ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ - ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../PPassemblageComp.h ../phqalloc.h -PPassemblage.o: ../PPassemblage.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../PPassemblage.h ../PPassemblageComp.h ../phqalloc.h -Pressure.o: ../Pressure.cxx ../Utils.h ../phrqtype.h ../Parser.h \ - ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h -Reaction.o: ../Reaction.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Reaction.h ../phqalloc.h -ReadClass.o: ../ReadClass.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../Exchange.h ../ExchComp.h ../PPassemblage.h ../PPassemblageComp.h \ - ../cxxKinetics.h ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../GasPhase.h ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h -Solution.o: ../Solution.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../phqalloc.h -SolutionIsotope.o: ../SolutionIsotope.cxx ../Utils.h ../phrqtype.h \ - ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ - ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../SolutionIsotope.h ../phqalloc.h -SSassemblage.o: ../SSassemblage.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../phqalloc.h -SScomp.o: ../SScomp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../SScomp.h ../phqalloc.h -SS.o: ../SS.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ +ISolution.o: ../ISolution.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../Utils.h ../SS.h ../SScomp.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../ISolution.h ../ISolutionComp.h \ ../phqalloc.h -StorageBin.o: ../StorageBin.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../StorageBin.h ../System.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../cxxKinetics.h \ - ../KineticsComp.h ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h \ - ../Temperature.h ../phqalloc.h -SurfaceCharge.o: ../SurfaceCharge.cxx ../Utils.h ../phrqtype.h \ - ../Phreeqc.h ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h \ - ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -SurfaceComp.o: ../SurfaceComp.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -Surface.o: ../Surface.cxx ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -System.o: ../System.cxx ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +KineticsComp.o: ../KineticsComp.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../KineticsComp.h ../phqalloc.h +NameDouble.o: ../NameDouble.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../ISolutionComp.h +NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../common/PHRQ_base.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../common/Utils.h ../common/phrqtype.h +PPassemblageComp.o: ../PPassemblageComp.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../PPassemblageComp.h ../phqalloc.h +PPassemblage.o: ../PPassemblage.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../PPassemblage.h ../PPassemblageComp.h \ + ../phqalloc.h +Pressure.o: ../Pressure.cxx ../common/Utils.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h \ + ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../phqalloc.h +Reaction.o: ../Reaction.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Reaction.h ../phqalloc.h +ReadClass.o: ../ReadClass.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../Exchange.h ../ExchComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../cxxKinetics.h \ + ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h \ + ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h +Solution.o: ../Solution.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../phqalloc.h +SolutionIsotope.o: ../SolutionIsotope.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../SolutionIsotope.h ../phqalloc.h +SSassemblage.o: ../SSassemblage.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../phqalloc.h +SScomp.o: ../SScomp.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../SScomp.h ../phqalloc.h +SS.o: ../SS.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../common/Utils.h ../common/phrqtype.h \ + ../SS.h ../SScomp.h ../phqalloc.h +StorageBin.o: ../StorageBin.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../StorageBin.h ../System.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ + ../ISolution.h ../ISolutionComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../cxxKinetics.h ../KineticsComp.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Reaction.h ../Temperature.h \ + ../phqalloc.h +SurfaceCharge.o: ../SurfaceCharge.cxx ../common/Utils.h \ + ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +SurfaceComp.o: ../SurfaceComp.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +Surface.o: ../Surface.cxx ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +System.o: ../System.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../System.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ ../ISolutionComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../Reaction.h ../Temperature.h -Temperature.o: ../Temperature.cxx ../Utils.h ../phrqtype.h ../Parser.h \ - ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Temperature.h \ - ../phqalloc.h -Utils.o: ../Utils.cxx ../Utils.h ../phrqtype.h ../Parser.h ../PHRQ_base.h \ - ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h -advection.o: ../advection.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -basicsubs.o: ../basicsubs.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ +Temperature.o: ../Temperature.cxx ../common/Utils.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../PBasic.h \ - ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h \ + ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../Temperature.h ../phqalloc.h +advection.o: ../advection.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../cxxKinetics.h \ + ../KineticsComp.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h +basicsubs.o: ../basicsubs.cpp ../Phreeqc.h ../common/phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../common/Utils.h ../common/phrqtype.h ../PBasic.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../PPassemblage.h \ ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ ../ISolution.h ../ISolutionComp.h ChartHandler.o: ../ChartHandler.cpp ChartObject.o: ../ChartObject.cpp -cl1.o: ../cl1.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ +cl1.o: ../cl1.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h cl1mp.o: ../cl1mp.cpp -class_main.o: ../class_main.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ - ../KineticsComp.h +class_main.o: ../class_main.cpp ../Phreeqc.h ../common/phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h CurveObject.o: ../CurveObject.cpp cvdense.o: ../cvdense.cpp ../cvdense.h ../cvode.h ../sundialstypes.h \ - ../phrqtype.h ../nvector.h ../dense.h ../smalldense.h ../sundialsmath.h \ - ../Phreeqc.h ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h \ - ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ - ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../Parser.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h -cvode.o: ../cvode.cpp ../nvector_serial.h ../nvector.h ../sundialstypes.h \ - ../phrqtype.h ../cvode.h ../sundialsmath.h ../Phreeqc.h ../cvdense.h \ - ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ - ../PHRQ_base.h ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -dense.o: ../dense.cpp ../sundialstypes.h ../phrqtype.h ../sundialsmath.h \ - ../dense.h ../smalldense.h -dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h ../PHRQ_base.h \ - ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h -dw.o: ../dw.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../common/phrqtype.h ../nvector.h ../dense.h ../smalldense.h \ + ../sundialsmath.h ../Phreeqc.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h -gases.o: ../gases.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../GasPhase.h ../GasComp.h -input.o: ../input.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h -integrate.o: ../integrate.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ +cvode.o: ../cvode.cpp ../nvector_serial.h ../nvector.h ../sundialstypes.h \ + ../common/phrqtype.h ../cvode.h ../sundialsmath.h ../Phreeqc.h \ + ../cvdense.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -inverse.o: ../inverse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +dense.o: ../dense.cpp ../sundialstypes.h ../common/phrqtype.h \ + ../sundialsmath.h ../dense.h ../smalldense.h +dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ + ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/PHRQ_io.h +dw.o: ../dw.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h +gases.o: ../gases.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../GasPhase.h ../GasComp.h +input.o: ../input.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -isotopes.o: ../isotopes.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -kinetics.o: ../kinetics.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +integrate.o: ../integrate.cpp ../Phreeqc.h ../common/phrqtype.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../StorageBin.h ../System.h ../Reaction.h ../cxxKinetics.h \ - ../KineticsComp.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../Temperature.h ../nvector_serial.h -mainsubs.o: ../mainsubs.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../common/Utils.h ../common/phrqtype.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +inverse.o: ../inverse.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../common/Utils.h \ + ../common/phrqtype.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h +isotopes.o: ../isotopes.cpp ../Phreeqc.h ../common/phrqtype.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../PBasic.h ../Temperature.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../Reaction.h ../PPassemblage.h \ - ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h -model.o: ../model.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +kinetics.o: ../kinetics.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../StorageBin.h ../System.h \ + ../Reaction.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ + ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../Temperature.h \ + ../nvector_serial.h +mainsubs.o: ../mainsubs.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../PBasic.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h \ + ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +model.o: ../model.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ ../ISolution.h ../ISolutionComp.h -nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h ../phrqtype.h +nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h \ + ../common/phrqtype.h nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.h \ - ../sundialstypes.h ../phrqtype.h ../sundialsmath.h -parse.o: ../parse.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../sundialstypes.h ../common/phrqtype.h ../sundialsmath.h +parse.o: ../parse.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h -PBasic.o: ../PBasic.cpp ../PBasic.h ../phrqtype.h ../PHRQ_base.h \ - ../global_structures.h ../Surface.h ../NumKeyword.h ../SurfaceComp.h \ - ../NameDouble.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ +PBasic.o: ../PBasic.cpp ../PBasic.h ../common/phrqtype.h \ + ../common/PHRQ_base.h ../global_structures.h ../Surface.h \ + ../NumKeyword.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ ../SurfaceCharge.h ../NA.h ../Phreeqc.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../SelectedOutput.h ../UserPunch.h \ - ../Pressure.h ../cxxMix.h ../Use.h ../phqalloc.h ../Utils.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -phqalloc.o: ../phqalloc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../StorageBinList.h ../dumper.h ../common/PHRQ_io.h ../SelectedOutput.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../phqalloc.h \ + ../common/Utils.h ../common/phrqtype.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +phqalloc.o: ../phqalloc.cpp ../Phreeqc.h ../common/phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h +Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h -Phreeqc.o: ../Phreeqc.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ ../ISolution.h ../ISolutionComp.h ../Reaction.h ../PPassemblage.h \ ../PPassemblageComp.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h \ ../KineticsComp.h ../phqalloc.h ../PBasic.h ../Temperature.h -PHRQ_io.o: ../PHRQ_io.cpp ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../Parser.h ../PHRQ_base.h -PHRQ_io_output.o: ../PHRQ_io_output.cpp ../Phreeqc.h ../phrqtype.h \ +PHRQ_io_output.o: ../PHRQ_io_output.cpp ../Phreeqc.h ../common/phrqtype.h \ ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -pitzer.o: ../pitzer.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h ../phqalloc.h +pitzer.o: ../pitzer.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -pitzer_structures.o: ../pitzer_structures.cpp ../Phreeqc.h ../phrqtype.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h -prep.o: ../prep.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ +pitzer_structures.o: ../pitzer_structures.cpp ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h +prep.o: ../prep.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ ../ISolution.h ../ISolutionComp.h -print.o: ../print.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ +print.o: ../print.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -read.o: ../read.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ +read.o: ../read.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h readtr.o: ../readtr.cpp ../StorageBin.h ../System.h ../NameDouble.h \ - ../Parser.h ../PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ - ../phrqtype.h ../SS.h ../SScomp.h ../Phreeqc.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../Utils.h -runner.o: ../runner.cpp ../runner.h ../phrqtype.h ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h \ - ../NA.h ../Utils.h + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h ../common/phrqtype.h ../common/PHRQ_base.h \ + ../common/PHRQ_io.h ../SS.h ../SScomp.h ../Phreeqc.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../global_structures.h \ + ../NA.h ../phqalloc.h ../common/Utils.h ../common/phrqtype.h +runner.o: ../runner.cpp ../runner.h ../common/phrqtype.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../common/Parser.h \ + ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ + ../NA.h ../common/Utils.h ../common/phrqtype.h SelectedOutput.o: ../SelectedOutput.cpp ../SelectedOutput.h \ - ../NumKeyword.h ../PHRQ_base.h -sit.o: ../sit.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../NumKeyword.h ../common/PHRQ_base.h +sit.o: ../sit.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h smalldense.o: ../smalldense.cpp ../smalldense.h ../sundialstypes.h \ - ../phrqtype.h ../sundialsmath.h -spread.o: ../spread.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h \ + ../common/phrqtype.h ../sundialsmath.h +spread.o: ../spread.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Utils.h -step.o: ../step.cpp ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../Utils.h ../StorageBin.h \ - ../System.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../Temperature.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h ../cxxKinetics.h \ - ../KineticsComp.h -StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ - ../PHRQ_base.h ../Parser.h ../PhreeqcKeywords/Keywords.h ../PHRQ_io.h -structures.o: ../structures.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h \ - ../GasComp.h ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h \ - ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../StorageBin.h ../System.h -sundialsmath.o: ../sundialsmath.cpp ../sundialsmath.h ../sundialstypes.h \ - ../phrqtype.h -tally.o: ../tally.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../common/Utils.h \ + ../common/phrqtype.h +step.o: ../step.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ + ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../common/Utils.h \ + ../common/phrqtype.h ../StorageBin.h ../System.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../Temperature.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ + ../Reaction.h ../cxxKinetics.h ../KineticsComp.h +StorageBinList.o: ../StorageBinList.cpp ../StorageBinList.h \ + ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ + ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h +structures.o: ../structures.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ + ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../StorageBin.h \ + ../System.h +sundialsmath.o: ../sundialsmath.cpp ../sundialsmath.h ../sundialstypes.h \ + ../common/phrqtype.h +tally.o: ../tally.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Temperature.h \ ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h ../Reaction.h \ ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -tidy.o: ../tidy.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../PHRQ_base.h ../dumper.h ../PHRQ_io.h \ +tidy.o: ../tidy.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ + ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ + ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ + ../common/PHRQ_base.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ - ../SurfaceComp.h ../NameDouble.h ../Parser.h ../SurfaceCharge.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ + ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h +transport.o: ../transport.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../cxxKinetics.h ../KineticsComp.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h -transport.o: ../transport.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../Exchange.h ../ExchComp.h ../GasPhase.h ../GasComp.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h Use.o: ../Use.cpp ../Use.h UserPunch.o: ../UserPunch.cpp ../UserPunch.h ../NumKeyword.h \ - ../PHRQ_base.h ../Phreeqc.h ../phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../dumper.h ../PHRQ_io.h \ + ../common/PHRQ_base.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../common/PHRQ_io.h \ ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h -utilities.o: ../utilities.cpp ../Utils.h ../phrqtype.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../PHRQ_base.h \ - ../dumper.h ../PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ - ../Parser.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../phqalloc.h ../Exchange.h ../ExchComp.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h + ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h +utilities.o: ../utilities.cpp ../common/Utils.h ../common/phrqtype.h \ + ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ + ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ + ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h Keywords.o: ../PhreeqcKeywords/Keywords.cpp ../PhreeqcKeywords/Keywords.h +Parser.o: ../common/Parser.cxx ../common/Utils.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h +PHRQ_base.o: ../common/PHRQ_base.cxx ../common/PHRQ_base.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h +Utils.o: ../common/Utils.cxx ../common/Utils.h ../common/phrqtype.h \ + ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ + ../common/PHRQ_io.h + # ----------------------------------------------------------------------------- clean: @@ -862,7 +951,7 @@ clean: dependencies: mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx tester: cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) From 8f1eb25c3ae22f1d6b56ee6573b63f5a8fb9704c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Sep 2015 16:41:50 +0000 Subject: [PATCH 0931/1077] Added SetScreenOn to C++, C, and Fortran. Updated PhreeqcRM tests to include a call to the new methods. Set minimum concentration (moles) to 1e-18 in Solution.cxx. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10255 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index b948f0f4..23224e81 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1109,7 +1109,7 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble cxxNameDouble::iterator it; for (it = this->totals.begin(); it != this->totals.end(); it++) { - if (it->second < 1e-14) + if (it->second < 1e-18) { it->second = 0.0; } From fbaeb7dcbdfd134ead5fd5ee00be7663a121c046 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 23 Sep 2015 04:24:40 +0000 Subject: [PATCH 0932/1077] working on swig callback git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10293 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/basicsubs.cpp b/basicsubs.cpp index 935e0333..8b6ed42d 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -4033,6 +4033,7 @@ basic_free(void) delete this->basic_interpreter; } +#ifndef SWIG_DIRECTOR #ifdef IPHREEQC_NO_FORTRAN_MODULE double Phreeqc:: basic_callback(double x1, double x2, char * str) @@ -4079,3 +4080,14 @@ Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, this->basic_fortran_callback_ptr = fcn; } #endif + +#else /* SWIG_DIRECTOR */ + +double Phreeqc:: +basic_callback(double x1, double x2, const char * str) +{ + return 2014.; +} + + +#endif /* SWIG_DIRECTOR */ From 6e752e26c43ff858b917381f5031517cadc4badb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 24 Sep 2015 06:10:03 +0000 Subject: [PATCH 0933/1077] windows java working with callback git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10300 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 4 ++++ Phreeqc.h | 4 ++++ basicsubs.cpp | 28 +++++++++++++++++----------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 8f59b000..4ddbf9d9 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -184,6 +184,10 @@ Phreeqc::Phreeqc(PHRQ_io *io) // initialize data members init(); + +#if defined(SWIG) || defined(SWIG_IPHREEQC) + basicCallback = NULL; +#endif } void Phreeqc::init(void) { diff --git a/Phreeqc.h b/Phreeqc.h index 9b261cd3..500deafb 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1736,6 +1736,10 @@ protected: #else double (*basic_fortran_callback_ptr) (double *x1, double *x2, const char *str, int l); #endif +#if defined(SWIG) || defined(SWIG_IPHREEQC) + class BasicCallback *basicCallback; + void SetCallback(BasicCallback *cb) { basicCallback = cb; } +#endif /* cl1.cpp ------------------------------- */ LDBLE *x_arg, *res_arg, *scratch; diff --git a/basicsubs.cpp b/basicsubs.cpp index 8b6ed42d..c9e30af2 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -4033,7 +4033,22 @@ basic_free(void) delete this->basic_interpreter; } -#ifndef SWIG_DIRECTOR +#if defined(SWIG) || defined(SWIG_IPHREEQC) + +#include "BasicCallback.h" + +double Phreeqc:: +basic_callback(double x1, double x2, const char * str) +{ + if (this->basicCallback) + { + return this->basicCallback->Callback(x1, x2, str); + } + return 0.0; +} + +#else /* defined(SWIG) || defined(SWIG_IPHREEQC) */ + #ifdef IPHREEQC_NO_FORTRAN_MODULE double Phreeqc:: basic_callback(double x1, double x2, char * str) @@ -4081,13 +4096,4 @@ Phreeqc::register_fortran_basic_callback(double ( *fcn)(double *x1, double *x2, } #endif -#else /* SWIG_DIRECTOR */ - -double Phreeqc:: -basic_callback(double x1, double x2, const char * str) -{ - return 2014.; -} - - -#endif /* SWIG_DIRECTOR */ +#endif /* defined(SWIG) || defined(SWIG_IPHREEQC) */ From 190128c155170a9c41b999d4869e77d0b61f7342 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 25 Sep 2015 06:18:48 +0000 Subject: [PATCH 0934/1077] updated for R git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10310 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- cvdense.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cvdense.cpp b/cvdense.cpp index f365136b..330ef02b 100644 --- a/cvdense.cpp +++ b/cvdense.cpp @@ -379,7 +379,9 @@ CVReInitDense(void *cvode_mem, CVDenseJacFn djac, void *jac_data) if (cv_mem == NULL) { /* CVode reports this error */ //CVMEM warning_msg( MSG_CVMEM_NULL); +#if !defined(R_SO) std::cerr << MSG_CVMEM_NULL << std::endl; +#endif return (LMEM_FAIL); } From 64703778f051773fadb405a156766eae2a2dc72c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 25 Sep 2015 06:30:33 +0000 Subject: [PATCH 0935/1077] updated for R git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10311 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ inverse.cpp | 6 ++++++ isotopes.cpp | 2 ++ 3 files changed, 54 insertions(+) diff --git a/PBasic.cpp b/PBasic.cpp index 469251b8..219d2b0e 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -484,7 +484,9 @@ numtostr(char * Result, LDBLE n) if (l_s == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } l_s[PhreeqcPtr->max_line - 1] = '\0'; /* if ((n != 0 && fabs(n) < 1e-2) || fabs(n) >= 1e12) { */ @@ -609,7 +611,9 @@ parse(char * l_inbuf, tokenrec ** l_buf) if (t->UU.sp == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } strncpy(t->UU.sp, l_inbuf + begin - 1, j); t->UU.sp[j] = '\0'; @@ -734,7 +738,9 @@ parse(char * l_inbuf, tokenrec ** l_buf) if (t->UU.sp == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } sprintf(t->UU.sp, "%.*s", (int) (strlen(l_inbuf) - i + 1), @@ -754,7 +760,9 @@ parse(char * l_inbuf, tokenrec ** l_buf) if (v == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } v->UU.U0.arr = NULL; v->next = varbase; @@ -1688,7 +1696,9 @@ parseinput(tokenrec ** l_buf) if (l1 == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } l1->next = l; if (l0 == NULL) @@ -1873,7 +1883,9 @@ require(int k, struct LOC_exec *LINK) strcpy(str, ": missing "); snerr(strcat(str, item->first.c_str())); } +#if !defined(R_SO) exit(4); +#endif } LINK->t = LINK->t->next; } @@ -1887,7 +1899,9 @@ skipparen(struct LOC_exec *LINK) if (LINK->t == NULL) { snerr(": parenthesis missing"); +#if !defined(R_SO) exit(4); +#endif } if (LINK->t->kind == tokrp || LINK->t->kind == tokcomma) goto _L1; @@ -1913,7 +1927,9 @@ findvar(struct LOC_exec *LINK) if (LINK->t == NULL || LINK->t->kind != tokvar) { snerr(": can`t find variable"); +#if !defined(R_SO) exit(4); +#endif } v = LINK->t->UU.vp; LINK->t = LINK->t->next; @@ -2562,7 +2578,9 @@ factor(struct LOC_exec * LINK) if (LINK->t->kind != tokvar || !count_varrec || count_varrec->stringvar != 0) { snerr(": can`t find variable"); +#if !defined(R_SO) exit(4); +#endif } /* return number of names of species */ @@ -2572,7 +2590,9 @@ factor(struct LOC_exec * LINK) if (LINK->t->kind != tokvar || !names_varrec || names_varrec->stringvar != 1) { snerr(": can`t find name of species"); +#if !defined(R_SO) exit(4); +#endif } /* return number of types of species */ @@ -2619,19 +2639,25 @@ factor(struct LOC_exec * LINK) if (names_arg == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } types_arg = (char **)PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(char *)); if (types_arg == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); if (moles_arg == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } names_arg[0] = NULL; types_arg[0] = NULL; @@ -2692,7 +2718,9 @@ factor(struct LOC_exec * LINK) if (LINK->t->kind != tokvar || !count_varrec || count_varrec->stringvar != 0) { snerr(": Missing or wrong type count variable."); +#if !defined(R_SO) exit(4); +#endif } // variable for species names LINK->t = LINK->t->next; @@ -2701,7 +2729,9 @@ factor(struct LOC_exec * LINK) if (LINK->t->kind != tokvar || !names_varrec || names_varrec->stringvar != 1) { snerr(": Missing or wrong type name variable."); +#if !defined(R_SO) exit(4); +#endif } // variable for species concentrations LINK->t = LINK->t->next; @@ -2738,13 +2768,17 @@ factor(struct LOC_exec * LINK) if (names_arg == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } moles_arg = (LDBLE *) PhreeqcPtr->PHRQ_calloc((size_t) (count_sys + 1), sizeof(LDBLE)); if (moles_arg == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } names_arg[0] = NULL; moles_arg[0] = 0; @@ -2815,7 +2849,9 @@ factor(struct LOC_exec * LINK) else { snerr(": Expected 4 arguments for list_s_s"); +#if !defined(R_SO) exit(4); +#endif } require(tokrp, LINK); @@ -2848,13 +2884,17 @@ factor(struct LOC_exec * LINK) if (names_varrec->UU.U1.sarr == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } moles_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); if (moles_varrec->UU.U0.arr == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } // first position not used @@ -3052,13 +3092,17 @@ factor(struct LOC_exec * LINK) if (elts_varrec->UU.U1.sarr == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); if (coef_varrec->UU.U0.arr == NULL) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } // first position not used @@ -5490,7 +5534,9 @@ cmddim(struct LOC_exec *LINK) if (!v->UU.U1.sarr) { PhreeqcPtr->malloc_error(); +#if !defined(R_SO) exit(4); +#endif } if (v->UU.U1.sarr == NULL) PhreeqcPtr->malloc_error(); diff --git a/inverse.cpp b/inverse.cpp index 2d4b9137..8057c28f 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -79,7 +79,9 @@ inverse_models(void) { error_string = sformatf( "Can`t open file, %s.", string); error_msg(error_string, STOP); +#if !defined(R_SO) exit(4); +#endif } count_inverse_models = 0; count_pat_solutions = 0; @@ -4082,7 +4084,9 @@ dump_netpath(struct inverse *inverse_ptr) { error_string = sformatf( "Can`t open file, %s.", inverse_ptr->netpath); error_msg(error_string, STOP); +#if !defined(R_SO) exit(4); +#endif } add_to_file("netpath.fil", inverse_ptr->netpath); @@ -5280,7 +5284,9 @@ add_to_file(const char *filename, const char *string) { error_string = sformatf( "Can`t open file, %s.", filename); error_msg(error_string, STOP); +#if !defined(R_SO) exit(4); +#endif } i = 0; /* diff --git a/isotopes.cpp b/isotopes.cpp index 4351f0f0..a1fb2ec5 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -908,7 +908,9 @@ punch_calculate_values(void) "Definition not found for CALCULATE_VALUES %s.", current_selected_output->Get_calculate_values()[i].first.c_str()); error_msg(error_string, STOP); +#if !defined(R_SO) exit(4); +#endif } if (calculate_value_ptr->calculated == FALSE) From 3f332d180bf04d47658c226f5d71c0969a74266c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Sep 2015 19:33:39 +0000 Subject: [PATCH 0936/1077] Trap null pointer missing gas components. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10317 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 1053c49f..743d2b82 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -981,8 +981,11 @@ tidy_gas_phase(void) struct phase *phase_ptr = phase_bsearch(gas_phase_ptr->Get_gas_comps()[j_PR].Get_phase_name().c_str(), &k, FALSE); if (gc[j_PR].Get_p_read() == 0) continue; - phase_ptr->moles_x = gc[j_PR].Get_p_read() / P; - phase_ptrs.push_back(phase_ptr); + if (phase_ptr) + { + phase_ptr->moles_x = gc[j_PR].Get_p_read() / P; + phase_ptrs.push_back(phase_ptr); + } } V_m = calc_PR(phase_ptrs, P, gas_phase_ptr->Get_temperature(), 0); gas_phase_ptr->Set_v_m(V_m); @@ -999,9 +1002,11 @@ tidy_gas_phase(void) gc[j_PR].Set_moles(0.0); } else { - gc[j_PR].Set_moles(phase_ptr->moles_x * - gas_phase_ptr->Get_volume() / V_m); - gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j_PR].Get_moles()); + if (phase_ptr) + { + gc[j_PR].Set_moles(phase_ptr->moles_x * gas_phase_ptr->Get_volume() / V_m); + gas_phase_ptr->Set_total_moles(gas_phase_ptr->Get_total_moles() + gc[j_PR].Get_moles()); + } } } } From e8553de46e9ad2ac7d310fd05fee05ce38e6e06f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Oct 2015 15:46:09 +0000 Subject: [PATCH 0937/1077] Debug prints for Peter de Moel. Possible null reference in tidy_solution. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10325 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 8 ++++++ spread.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tidy.cpp | 1 + 3 files changed, 86 insertions(+) diff --git a/read.cpp b/read.cpp index 84f16166..c034728d 100644 --- a/read.cpp +++ b/read.cpp @@ -5756,6 +5756,14 @@ read_solution(void) error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "In read_solution\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "token: ", token.c_str()); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "next_char: ", next_char); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "line_save: ", line_save); + error_msg(error_string, PHRQ_io::OT_CONTINUE); continue; } temp_isotope.Set_isotope_name(token.c_str()); diff --git a/spread.cpp b/spread.cpp index 5c2c6ede..1146da3d 100644 --- a/spread.cpp +++ b/spread.cpp @@ -327,6 +327,14 @@ read_solution_spread(void) error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); error_msg(error_string, CONTINUE); + error_string = sformatf( "In read_solution_spread isotope_uncertainty\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "token: ", token.c_str()); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "next_char: ", next_char); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "line_save: ", line_save); + error_msg(error_string, PHRQ_io::OT_CONTINUE); continue; } int i; @@ -405,6 +413,14 @@ read_solution_spread(void) error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); error_msg(error_string, CONTINUE); + error_string = sformatf( "In read_solution_spread isotope\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "token: ", token.c_str()); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "next_char: ", next_char); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "line_save: ", line_save); + error_msg(error_string, PHRQ_io::OT_CONTINUE); continue; } int i; @@ -755,6 +771,67 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, error_string = sformatf( "Expected isotope name to" " begin with an isotopic number."); error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "In spread_row_to_solution isotope\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "token: ", token.c_str()); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "next_char: ", next_char); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "char_string: ", char_string); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + error_string = sformatf( "\t%s\t%s\n", "line_save: ", line_save); + error_msg(error_string, PHRQ_io::OT_CONTINUE); +//struct spread_row +//{ +// int count; +// int empty, string, number; +// char **char_vector; +// LDBLE *d_vector; +// int *type_vector; +//}; + error_string = sformatf("Heading spread_row\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + if (heading) + { + for (int ii = 0; ii < heading->count; ii++) + { + error_string = sformatf("%d\t%s\n",ii,heading->char_vector[ii]); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + } + } + else + { + error_msg("heading is null", PHRQ_io::OT_CONTINUE); + } + + error_string = sformatf("Data spread_row\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + if (data) + { + for (int ii = 0; ii < data->count; ii++) + { + error_string = sformatf("%d\t%s\t%d\n",ii,data->char_vector[ii],data->type_vector[ii]); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + } + } + else + { + error_msg("Data is null", PHRQ_io::OT_CONTINUE); + } + error_string = sformatf("Units spread_row\n"); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + if (units) + { + for (int ii = 0; ii < units->count; ii++) + { + error_string = sformatf("%d\t%s\n",ii,units->char_vector[ii]); + error_msg(error_string, PHRQ_io::OT_CONTINUE); + } + } + else + { + error_msg("Units is null", PHRQ_io::OT_CONTINUE); + } free_check_null(char_string); continue; } diff --git a/tidy.cpp b/tidy.cpp index 743d2b82..5d1e57e8 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3239,6 +3239,7 @@ tidy_solutions(void) if (it == Rxn_solution_map.end()) { assert(false); + continue; } cxxSolution &solution_ref = it->second; //if (solution_ref.Get_new_def()) From f997d62a137df8bc5e7274dd744e901ea0bd7adf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 1 Oct 2015 17:07:17 +0000 Subject: [PATCH 0938/1077] [ not handled as upper for solution_spread in copy_token_tab. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10327 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- spread.cpp | 10 +++++++++- utilities.cpp | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/spread.cpp b/spread.cpp index 1146da3d..6fac7712 100644 --- a/spread.cpp +++ b/spread.cpp @@ -1112,6 +1112,14 @@ string_to_spread_row(char *string) strtod(token, NULL); spread_row_ptr->type_vector[spread_row_ptr->count] = NUMBER; } + else + { + input_error++; + error_msg("Unknown input in string_to_spread_row keyword.", CONTINUE); + error_string = sformatf("\tcopy_token j: %d, token: %s\n", j, token); + error_msg(error_string, CONTINUE); + error_msg(line_save, CONTINUE); + } spread_row_ptr->count++; } /* @@ -1212,7 +1220,7 @@ copy_token_tab(char *token_ptr, char **ptr, int *length) /* * Check what we have */ - if (isupper((int) c)) + if (isupper((int) c) || c == '[') { return_value = UPPER; } diff --git a/utilities.cpp b/utilities.cpp index c63e4595..13b703c5 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -526,7 +526,7 @@ copy_title(char *token_ptr, char **ptr, int *length) /* * Check what we have */ - if (isupper((int) c)) + if (isupper((int) c) || c == '[') { return_value = UPPER; } From 34f7921371ba8d3d39b005fdaa64a487c42b3853 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Oct 2015 03:15:13 +0000 Subject: [PATCH 0939/1077] fixed BUILD_SHARED_LIBS build on windows git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10347 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- NameDouble.h | 8 +++++++- common/PHRQ_base.h | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NameDouble.h b/NameDouble.h index cae4cbda..0e833d33 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -1,6 +1,12 @@ #if !defined(NAMEDOUBLE_H_INCLUDED) #define NAMEDOUBLE_H_INCLUDED +#if defined(_WINDLL) +#define IPQ_DLL_EXPORT __declspec(dllexport) +#else +#define IPQ_DLL_EXPORT +#endif + #include // assert #include // std::map #include // std::string @@ -11,7 +17,7 @@ class Phreeqc; #include "phrqtype.h" class cxxISolutionComp; -class cxxNameDouble:public +class IPQ_DLL_EXPORT cxxNameDouble:public std::map < std::string, LDBLE > { diff --git a/common/PHRQ_base.h b/common/PHRQ_base.h index 4750cb13..037d0881 100644 --- a/common/PHRQ_base.h +++ b/common/PHRQ_base.h @@ -3,8 +3,14 @@ #include +#if defined(_WINDLL) +#define IPQ_DLL_EXPORT __declspec(dllexport) +#else +#define IPQ_DLL_EXPORT +#endif + class PHRQ_io; -class PHRQ_base +class IPQ_DLL_EXPORT PHRQ_base { public: // constructors From 33b4ae373ed0e6d31eee669004163c832e477e9b Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 6 Oct 2015 03:15:13 +0000 Subject: [PATCH 0940/1077] fixed BUILD_SHARED_LIBS build on windows git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10347 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_base.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PHRQ_base.h b/PHRQ_base.h index 4750cb13..037d0881 100644 --- a/PHRQ_base.h +++ b/PHRQ_base.h @@ -3,8 +3,14 @@ #include +#if defined(_WINDLL) +#define IPQ_DLL_EXPORT __declspec(dllexport) +#else +#define IPQ_DLL_EXPORT +#endif + class PHRQ_io; -class PHRQ_base +class IPQ_DLL_EXPORT PHRQ_base { public: // constructors From 218f4f5fab2ac1ac825958e98a5b4a6829cc3e63 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 9 Oct 2015 13:29:30 +0000 Subject: [PATCH 0941/1077] Avoid negative moles of equilibrium phase. Typo in RELEASE git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10368 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/read.cpp b/read.cpp index c034728d..4b2ff3a2 100644 --- a/read.cpp +++ b/read.cpp @@ -4207,6 +4207,12 @@ read_pp_assemblage(void) if (j == EMPTY) continue; j = sscanf(token.c_str(), SCANFORMAT, &dummy); + if (dummy < 0) + { + error_string = sformatf( "Moles of mineral < 0, reset to 0."); + dummy = 0; + warning_msg(error_string); + } comp->Set_moles(dummy); if (j != 1) { From bef66de3c3e202ee7a4142ca39dc932080060bb8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 15 Oct 2015 20:04:36 +0000 Subject: [PATCH 0942/1077] Fixed formula for pressure dependence of B1, B2, F1, F2. Previously had a limit of -10C, otherwise produced a floating point exception. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10385 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- pitzer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pitzer.cpp b/pitzer.cpp index 2220083f..b5fa7e24 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1281,11 +1281,14 @@ pitzer(void) F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B); if (patm_x > 1.0) { - LDBLE pap; + LDBLE pap = 0.0; pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x; B1 = B - (pap > 0.2 ? 0.2 : pap); - pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); - //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + if (TK > 263.0) + { + pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); + //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + } B2 = B - (pap > 0.2 ? 0.2 : pap); if (B1 != 0) F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); From 2fe6313f47a41210c53ad9800b37067f40f2a1d2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 26 Oct 2015 20:05:47 +0000 Subject: [PATCH 0943/1077] Avoid a null pointer. Not really sure what causes it, combination of charge balance, pe constraint, alkalinity, and C(4). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10432 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prep.cpp b/prep.cpp index e5125572..a15d4208 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2398,6 +2398,11 @@ mb_for_species_aq(int n) { continue; } + else if (master_ptr->unknown == NULL) + { + //std::cerr << "NULL: " << master_ptr->s->name << std::endl; + continue; + } else if (master_ptr->unknown->type == SOLUTION_PHASE_BOUNDARY) { continue; From fb18be24e24fcb455b1e22880b3ed5098c6be988 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 8 Dec 2015 16:54:38 +0000 Subject: [PATCH 0944/1077] Tony's implementation of electric current. Test case current1. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10550 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 61 +- PBasic.h | 7 +- Phreeqc.cpp | 17 +- Phreeqc.h | 7 + Solution.cxx | 19 + Solution.h | 3 + basicsubs.cpp | 201 +++++- class_main.cpp | 26 +- gases.cpp | 4 +- global_structures.h | 14 +- mainsubs.cpp | 5 +- model.cpp | 1 + pitzer.cpp | 11 +- print.cpp | 2 +- read.cpp | 69 +- readtr.cpp | 68 +- sit.cpp | 1 + spread.cpp | 14 +- step.cpp | 10 +- transport.cpp | 1570 ++++++++++++++++++++++++++----------------- 20 files changed, 1399 insertions(+), 711 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 219d2b0e..2c56b1a1 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1620,6 +1620,21 @@ listtokens(FILE * f, tokenrec * l_buf) case toksa_declercq: output_msg("SA_DECLERCQ"); break; + case tokviscos: + output_msg("VISCOS"); + break; + case tokviscos_0: + output_msg("VISCOS_0"); + break; + case tokrho_0: + output_msg("RHO_0"); + break; + case tokcurrent_a: + output_msg("CURRENT_A"); + break; + case tokpot_v: + output_msg("POT_V"); + break; } l_buf = l_buf->next; } @@ -2251,7 +2266,7 @@ factor(struct LOC_exec * LINK) break; } else - n.UU.val = PhreeqcPtr->cell_data[i - 1].por; + n.UU.val = PhreeqcPtr->cell_data[i].por; break; } else @@ -3152,7 +3167,7 @@ factor(struct LOC_exec * LINK) } else if (PhreeqcPtr->state == TRANSPORT) { - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_data[PhreeqcPtr->cell - 1].mid_cell_x; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->cell_data[PhreeqcPtr->cell].mid_cell_x; } else if (PhreeqcPtr->state == ADVECTION) { @@ -3518,6 +3533,33 @@ factor(struct LOC_exec * LINK) case toksoln_vol: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_solution_volume(); break; + case tokvm: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str); + } + break; + case tokviscos: + { + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos; + } + break; + case tokviscos_0: + { + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos_0; + } + break; + case tokrho_0: + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rho_0; + break; + case tokcurrent_a: + //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_x; + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_A; + break; + case tokpot_v: + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->use.Get_solution_ptr()->Get_potV(); + break; + case toklog10: { LDBLE t = realfactor(LINK); @@ -3531,12 +3573,6 @@ factor(struct LOC_exec * LINK) //} } break; - case tokvm: - { - const char * str = stringfactor(STR1, LINK); - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str); - } - break; case toksin: n.UU.val = sin(realfactor(LINK)); @@ -4507,7 +4543,7 @@ cmdchange_por(struct LOC_exec *LINK) require(tokrp, LINK); if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1 && j != PhreeqcPtr->count_cells + 1) - PhreeqcPtr->cell_data[j - 1].por = TEMP; + PhreeqcPtr->cell_data[j].por = TEMP; } void PBasic:: @@ -7118,7 +7154,12 @@ const std::map::value_type temp_tokens[] std::map::value_type("callback", PBasic::tokcallback), std::map::value_type("diff_c", PBasic::tokdiff_c), std::map::value_type("sa_declercq", PBasic::toksa_declercq), - std::map::value_type("edl_species", PBasic::tokedl_species) + std::map::value_type("edl_species", PBasic::tokedl_species), + std::map::value_type("viscos", PBasic::tokviscos), + std::map::value_type("viscos_0", PBasic::tokviscos_0), + std::map::value_type("rho_0", PBasic::tokrho_0), + std::map::value_type("current_a", PBasic::tokcurrent_a), + std::map::value_type("pot_v", PBasic::tokpot_v) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 6f8626de..f2f39cc9 100644 --- a/PBasic.h +++ b/PBasic.h @@ -324,7 +324,12 @@ public: tokcallback, tokdiff_c, toksa_declercq, - tokedl_species + tokedl_species, + tokviscos, + tokviscos_0, + tokrho_0, + tokcurrent_a, + tokpot_v }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 4ddbf9d9..24e5bbc1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -196,7 +196,8 @@ void Phreeqc::init(void) current_pa = NAN; current_mu = NAN; mu_terms_in_logk = true; - + current_A = 0.0; + current_x = 0.0; /* ---------------------------------------------------------------------- * STRUCTURES * ---------------------------------------------------------------------- */ @@ -406,6 +407,7 @@ void Phreeqc::init(void) tk_x = 0; patm_x = 1; last_patm_x = 1; + potV_x = 0; numerical_fixed_volume = false; force_numerical_fixed_volume = false; //switch_numerical = false; @@ -713,7 +715,9 @@ void Phreeqc::init(void) /* from float.h, sets tolerance for cl1 routine */ ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); #else - ineq_tol = pow((double) 10, (double) -DBL_DIG); + //ineq_tol = pow((double) 10, (double) -DBL_DIG); +// appt: + ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); #endif convergence_tolerance = 1e-8; step_size = 100.; @@ -787,6 +791,7 @@ void Phreeqc::init(void) user_database = NULL; //have_punch_name = FALSE; print_density = 0; + print_viscosity = 0; zeros = NULL; zeros_max = 1; cell_pore_volume = 0; @@ -799,6 +804,8 @@ void Phreeqc::init(void) sys_tot = 0; V_solutes = 0.0; + viscos = 0.0; + viscos_0 = 0.0; rho_0 = 0; kappa_0 = 0.0; p_sat = 0.0; @@ -981,7 +988,7 @@ void Phreeqc::init(void) /* phrq_io_output.cpp ------------------------------- */ forward_output_to_log = 0; /* phreeqc_files.cpp ------------------------------- */ - default_data_base = string_duplicate("phreeqc.dat"); + default_data_base = string_duplicate("phreeqc.dat"); #ifdef PHREEQ98 int outputlinenr; char *LogFileNameC; @@ -1357,9 +1364,9 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) if (count_cells > 0) { cell_data = (struct cell_data *) free_check_null(cell_data); - cell_data = (struct cell_data *) PHRQ_malloc((size_t) (count_cells * sizeof(struct cell_data))); + cell_data = (struct cell_data *) PHRQ_malloc((size_t) ((count_cells + 2) * sizeof(struct cell_data))); if (cell_data == NULL) malloc_error(); - memcpy(cell_data, pSrc->cell_data, ((size_t) (count_cells * sizeof(struct cell_data)))); + memcpy(cell_data, pSrc->cell_data, ((size_t) ((count_cells + 2) * sizeof(struct cell_data)))); } old_cells = pSrc->old_cells; max_cells = pSrc->max_cells; diff --git a/Phreeqc.h b/Phreeqc.h index 500deafb..1833cc52 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -702,6 +702,7 @@ public: /* VP: Density Start */ int read_millero_abcdef (char *ptr, LDBLE * abcdef); /* VP: Density End */ + int read_viscosity_parms(char *ptr, LDBLE * Jones_Dole); int read_copy(void); int read_debug(void); int read_delta_h_only(char *ptr, LDBLE * delta_h, @@ -1050,9 +1051,11 @@ public: int reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, LDBLE new_Dw, int cell); LDBLE viscosity(void); + LDBLE calc_vm_Cl(void); int multi_D(LDBLE DDt, int mobile_cell, int stagnant); int find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant); int fill_spec(int cell_no); + void define_ct_structures(void); int fill_m_s(struct J_ij *J_ij, int J_ij_count_spec); static int sort_species_name(const void *ptr1, const void *ptr2); int disp_surf(LDBLE stagkin_time); @@ -1335,6 +1338,7 @@ protected: LDBLE tk_x; LDBLE patm_x; LDBLE last_patm_x; + LDBLE potV_x; bool numerical_fixed_volume; bool force_numerical_fixed_volume; //bool switch_numerical; @@ -1703,9 +1707,11 @@ protected: int print_density; /* VP: Density End */ + int print_viscosity; LDBLE *zeros; int zeros_max; + LDBLE viscos, viscos_0, viscos_0_25; // viscosity of the solution, of pure water, of pure water at 25 C LDBLE cell_pore_volume; LDBLE cell_porosity; LDBLE cell_volume; @@ -1931,6 +1937,7 @@ protected: int nmix, heat_nmix; LDBLE heat_mix_f_imm, heat_mix_f_m; int warn_MCD_X, warn_fixed_Surf; + LDBLE current_x, current_A; // current: coulomb * s, ampere #ifdef PHREEQ98 int AutoLoadOutputFile, CreateToC; diff --git a/Solution.cxx b/Solution.cxx index 23224e81..f4d4405d 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -29,6 +29,7 @@ cxxSolution::cxxSolution(PHRQ_io * io) this->io = io; this->new_def = false; this->patm = 1.0; + this->potV = 0.0; this->tc = 25.0; this->ph = 7.0; this->pe = 4.0; @@ -62,6 +63,7 @@ cxxSolution::operator =(const cxxSolution &rhs) this->description = rhs.description; this->new_def = rhs.new_def; this->patm = rhs.patm; + this->potV = rhs.potV; this->tc = rhs.tc; this->ph = rhs.ph; this->pe = rhs.pe; @@ -229,6 +231,9 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con s_oss << indent1; s_oss << "-pressure " << this->patm << "\n"; + s_oss << indent1; + s_oss << "-potential " << this->potV << "\n"; + // new identifier s_oss << indent1; s_oss << "-total_h " << this->total_h << "\n"; @@ -996,6 +1001,18 @@ cxxSolution::read_raw(CParser & parser, bool check) opt_save = 25; } break; + + case 26: // potential + if (!(parser.get_iss() >> this->potV)) + { + this->potV = 0.0; + parser.incr_input_error(); + parser.error_msg("Expected numeric value for potential (V).", + PHRQ_io::OT_CONTINUE); + } + opt_save = CParser::OPT_DEFAULT; + break; + } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -1335,6 +1352,7 @@ cxxSolution::zero() this->master_activity.type = cxxNameDouble::ND_SPECIES_LA; this->species_gamma.type = cxxNameDouble::ND_SPECIES_GAMMA; this->patm = 1.0; + this->potV = 0.0; this->initial_data = NULL; } @@ -1360,6 +1378,7 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive) this->cb += addee.cb * extensive; this->density = f1 * this->density + f2 * addee.density; this->patm = f1 * this->patm + f2 * addee.patm; + this->potV = f1 * this->potV + f2 * addee.potV; this->mass_water += addee.mass_water * extensive; this->soln_vol += addee.soln_vol * extensive; this->total_alkalinity += addee.total_alkalinity * extensive; diff --git a/Solution.h b/Solution.h index a2a48c4c..1fc63265 100644 --- a/Solution.h +++ b/Solution.h @@ -29,6 +29,8 @@ class cxxSolution:public cxxNumKeyword void Set_new_def(bool p) {this->new_def = p;} LDBLE Get_patm() const {return this->patm;} void Set_patm(LDBLE p) {this->patm = p;} + LDBLE Get_potV() const {return this->potV;} + void Set_potV(LDBLE p) {this->potV = p;} LDBLE Get_tc() const {return this->tc;} void Set_tc(LDBLE l_tc) {this->tc = l_tc;} LDBLE Get_ph() const {return this->ph;} @@ -115,6 +117,7 @@ class cxxSolution:public cxxNumKeyword protected: bool new_def; LDBLE patm; + LDBLE potV; LDBLE tc; LDBLE ph; LDBLE pe; diff --git a/basicsubs.cpp b/basicsubs.cpp index c9e30af2..4d803dfd 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -161,6 +161,9 @@ diff_c(const char *species_name) if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) { g = s_ptr->dw; + if (s_ptr->dw_t) + g *= exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15); + g *= viscos_0_25 / viscos; } else { @@ -177,6 +180,7 @@ calc_SC(void) LDBLE lm, a, l_z, Dw, SC, ff; SC = 0; +# ifdef SKIP for (i = 0; i < count_species_list; i++) { if (species_list[i].s->type == EX) @@ -197,33 +201,204 @@ calc_SC(void) lm = species_list[i].s->lm; if (lm > -9) { -/* - if (l_z < 1.5) { - ff = (mu_x < 0.36 ? 0.6 : - sqrt(mu_x)); - } - else { - ff = (mu_x < pow(0.4*l_z, 2.0) ? 0.4 : - sqrt(mu_x) / l_z); - } -*/ ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z); ff *= species_list[i].s->lg; if (ff > 0) ff = 0; a = under(lm + ff); + if (species_list[i].s->dw_t) + Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier is done in SC SC += a * l_z * l_z * Dw; } } SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); -/* correct for temperature dependency... + /* correct for temperature dependency... SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: SC_T = SC_298 * (viscos_298 / viscos_T) */ - SC *= 0.88862 / viscosity(); + SC *= viscos_0_25 / viscos; return (SC); +# endif + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) + continue; + if ((Dw = s_x[i]->dw) == 0) + continue; + if ((l_z = fabs(s_x[i]->z)) == 0) + continue; + + lm = s_x[i]->lm; + if (lm > -9) + { + ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z); + + ff *= s_x[i]->lg; + if (ff > 0) ff = 0; + a = under(lm + ff); + if (s_x[i]->dw_t) + Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); // the viscosity multiplier is done in SC + SC += a * l_z * l_z * Dw; + } + } + SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); + /* correct for temperature dependency... + SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and + Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: + SC_T = SC_298 * (viscos_298 / viscos_T) + */ + SC *= viscos_0_25 / viscos; + + return (SC); + +#ifdef SKIP + int i; + LDBLE lm, a, ka, l_z, Dw, SC, ff, sqrt_mu; + boolean DebOns_sc = false; + sqrt_mu = sqrt(mu_x); + + SC = 0; + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].s->dw_a || species_list[i].s->dw_a_exp) + { + DebOns_sc = true; + break; + } + if (species_list[i].s->type > HPLUS) + continue; + if (i > 0 + && strcmp(species_list[i].s->name, + species_list[i - 1].s->name) == 0) + continue; + if (species_list[i].s == s_h2o) + continue; + if ((Dw = species_list[i].s->dw) == 0) + continue; + if ((l_z = fabs(species_list[i].s->z)) == 0) + continue; + + lm = species_list[i].s->lm; + if (lm > -9) + { + ka = DH_B * (species_list[i].s->dha ? species_list[i].s->dha : 4.0); + if (mu_x > 1) + ka *= pow(mu_x, 0.25 / mu_x); + else + ka *= pow(mu_x, 0.25); //sqrt_mu; + ff = pow((int) 10, -l_z * l_z * DH_A * sqrt_mu / (1 + ka)); + ff = pow(ff, 0.7 / sqrt(l_z)); + //ff = pow(ff, 0.6); + a = species_list[i].s->moles / mass_water_aq_x * ff; + if (species_list[i].s->dw_t) + Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier is done in SC + SC += a * l_z * l_z * Dw; + } + } + if (!DebOns_sc) + { + SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); + SC *= viscos_0_25 / viscos_0; + return (SC); + } + +/*Debye-Onsager according to Robinson and Stokes, 1954, JACS 75, 1991, + but with sqrt charge multiplier for B2 and mu^ff dependent ka */ + LDBLE q, B1, B2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, z_plus, z_min, t1, t2, t2a, Dw_SC; + + m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = z_plus = z_min = 0; + SC = 0; + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].s->type > HPLUS) + continue; + if (i > 0 + && strcmp(species_list[i].s->name, + species_list[i - 1].s->name) == 0) + continue; + if (species_list[i].s == s_h2o) + continue; + if ((Dw = species_list[i].s->dw) == 0) + continue; + if ((l_z = species_list[i].s->z) == 0) + continue; + if ((lm = species_list[i].s->lm) < -9) + continue; +// ** for optimizing... + if (!strcmp(species_list[i].s->name, "H+")) + t2a = species_list[i].s->Jones_Dole[2]; +// + if (species_list[i].s->dw_t) + Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier cancels in q... + if (l_z > 0) + { + m_plus += species_list[i].s->moles; + t1 = species_list[i].s->moles * l_z; + eq_plus += t1; + eq_dw_plus += t1 * Dw; + } + else + { + m_min += species_list[i].s->moles; + t1 = species_list[i].s->moles * l_z; + eq_min -= t1; + eq_dw_min -= t1 * Dw; + } + } + // Dw's weighted by eq... + eq_dw_plus /= eq_plus; eq_dw_min /= eq_min; + z_plus = eq_plus / m_plus; // |z1| + z_min = eq_min / m_min; // |z2| + q = z_plus * z_min / (z_plus + z_min) * (eq_dw_plus + eq_dw_min) / (z_min * eq_dw_plus + z_plus * eq_dw_min); + t1 = pow(1.60218e-19, 2) / (6 * pi); + B1 = t1 / (2 * 8.8542e-12 * eps_r * 1.38066e-23 * tk_x) * + q / (1 + sqrt(q)) * DH_B * 1e10 * z_plus * z_min; // DH_B is per Angstrom (*1e10) + t2 = 1e3 * calc_solution_volume(); + t2 = (1 - t2a) * viscos_0 + t2a * viscos; + B2 = t1 * AVOGADRO / t2 * DH_B * 1e17; // DH_B per Angstrom (*1e10), viscos in mPa.s (*1e3), B2 in cm2 (*1e4) + + Dw_SC = viscos_0_25 / t2 * 1e4 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); + for (i = 0; i < count_species_list; i++) + { + if (species_list[i].s->type > HPLUS) + continue; + if (i > 0 + && strcmp(species_list[i].s->name, + species_list[i - 1].s->name) == 0) + continue; + if (species_list[i].s == s_h2o) + continue; + if ((Dw = species_list[i].s->dw) == 0) + continue; + if ((l_z = fabs(species_list[i].s->z)) == 0) + continue; + if ((lm = species_list[i].s->lm) < -9) + continue; + + Dw *= Dw_SC; + if (species_list[i].s->dw_t) + Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity factor is in Dw_SC + a = (species_list[i].s->dw_a ? species_list[i].s->dw_a : 3.5); + ka = DH_B * a; + if (species_list[i].s->dw_a_exp) + ka *= pow((double) mu_x, species_list[i].s->dw_a_exp); + else + ka *= sqrt_mu; + + // Falkenhagen... + /*SC += under(lm) * l_z * l_z * (Dw - B2 * l_z * sqrt_mu / (1 + ka)) * (1 - B1 * sqrt_mu / + ((1 + ka) * (1 + ka * sqrt(q) + ka * ka / 6)));*/ + + t1 = (Dw - (B1 * Dw + B2) * sqrt_mu / (1 + ka)); + //t1 = (Dw - (B1 * Dw + B2 * sqrt(l_z)) * sqrt_mu / (1 + ka)); + //t1 = (Dw - (B1 * Dw + B2 * l_z * l_z) * sqrt_mu / (1 + ka)); + if (t1 > 0) + SC += under(lm) * l_z * l_z * t1; + } + return (SC * 1e3); +#endif } /* VP: Density Start */ @@ -2708,7 +2883,7 @@ edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, PHRQ_free(sys); return (sys_tot); } - /* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles) diff --git a/class_main.cpp b/class_main.cpp index 0d202d5a..213dcbc4 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -277,7 +277,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.0.5"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.2.2a AmpŠre"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -301,7 +301,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "May 11, 2013"); + len = sprintf(buffer, "%s", "November 25, 2015"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif @@ -331,7 +331,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -440,7 +440,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -487,7 +487,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.0.5, compiled on May 29, 2013\n")); + output_msg(sformatf("Using PHREEQC: version 3.2.2a Ampère, compiled November 25, 2015\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); @@ -528,7 +528,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -636,7 +636,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -762,7 +762,7 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, #endif error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -791,7 +791,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { /* @@ -805,7 +805,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else phrq_io->Set_error_file(stderr); #endif - + screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') { @@ -834,7 +834,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -863,7 +863,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { @@ -906,7 +906,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } diff --git a/gases.cpp b/gases.cpp index 52add3cd..871d41a9 100644 --- a/gases.cpp +++ b/gases.cpp @@ -459,10 +459,10 @@ calc_PR(void) while (P <= 0) { P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); - if (P <= 0.0) + if (P <= 0.0) { V_m *= 2.0; - //a_aa_sum /= 2.0; + //a_aa_sum /= 2.0; } } if (iterations > 0 && P < 150 && V_m < 1.01) diff --git a/global_structures.h b/global_structures.h index e05e59fb..cc934658 100644 --- a/global_structures.h +++ b/global_structures.h @@ -540,8 +540,9 @@ struct cell_data LDBLE mid_cell_x; LDBLE disp; LDBLE temp; - LDBLE por; /* free (uncharged) porewater porosities */ - LDBLE por_il; /* interlayer water porosities */ + LDBLE por; /* free (uncharged) porewater porosities */ + LDBLE por_il; /* interlayer water porosities */ + LDBLE potV; /* potential (V) */ int punch; int print; }; @@ -666,6 +667,9 @@ struct species LDBLE gfw; /* gram formula wt of species */ LDBLE z; /* charge of species */ LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */ + LDBLE dw_t; /* correct Dw for temperature: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15) */ + LDBLE dw_a; /* ion size parm for calc'ng SC = SC0 - (B1 * SC0 + B2) * kk * dw_a / (1 + kk * dw_a) */ + LDBLE dw_a_exp; /* power term for ionic strength correction of dw_a */ LDBLE erm_ddl; /* enrichment factor in DDL */ LDBLE equiv; /* equivalents in exchange species */ LDBLE alk; /* alkalinity of species, used for cec in exchange */ @@ -676,6 +680,7 @@ struct species LDBLE dha, dhb, a_f; /* WATEQ Debye Huckel a and b-dot; active_fraction coef for exchange species */ LDBLE lk; /* log10 k at working temperature */ LDBLE logk[MAX_LOG_K_INDICES]; /* log kt0, delh, 6 coefficients analytical expression + volume terms */ + LDBLE Jones_Dole[10]; /* 7 coefficients analytical expression for B, D, anion terms and pressure in Jones_Dole viscosity eqn */ /* VP: Density Start */ LDBLE millero[7]; /* regression coefficients to calculate temperature dependent phi_0 and b_v of Millero density model */ /* VP: Density End */ @@ -1031,13 +1036,14 @@ struct sol_D { int count_spec; /* number of aqueous + exchange species */ int count_exch_spec; /* number of exchange species */ - LDBLE exch_total, x_max; /* total moles of X-, max X- in transport step in sol_D[1] */ + LDBLE exch_total, x_max, tk_x; /* total moles of X-, max X- in transport step in sol_D[1], tk */ struct spec *spec; }; struct J_ij { const char *name; - LDBLE tot1, tot2; + LDBLE tot1, tot2; /* species change in cells i and j */ + int sol_D_number; /* the number of the species in sol_D */ }; struct M_S { diff --git a/mainsubs.cpp b/mainsubs.cpp index 885957fd..19f5894d 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -44,7 +44,7 @@ initialize(void) /* * Allocate space */ - space((void **) ((void *) &cell_data), INIT, &count_cells, + space((void **) ((void *) &cell_data), INIT, &count_cells + 2, sizeof(struct cell_data)); space((void **) ((void *) &elements), INIT, &max_elements, @@ -630,6 +630,7 @@ initial_solutions(int print) } converge1 = check_residuals(); sum_species(); + viscosity(); add_isotopes(solution_ref); punch_all(); print_all(); @@ -751,6 +752,7 @@ initial_exchangers(int print) converge = model(); converge1 = check_residuals(); sum_species(); + viscosity(); species_list_sort(); print_exchange(); xexchange_save(n_user); @@ -1445,6 +1447,7 @@ xsolution_save(int n_user) temp_solution.Set_description(description_x); temp_solution.Set_tc(tc_x); temp_solution.Set_patm(patm_x); + temp_solution.Set_potV(potV_x); temp_solution.Set_ph(ph_x); temp_solution.Set_pe(solution_pe_x); temp_solution.Set_mu(mu_x); diff --git a/model.cpp b/model.cpp index df2ca4de..8db40bec 100644 --- a/model.cpp +++ b/model.cpp @@ -4713,6 +4713,7 @@ set(int initial) tk_x = tc_x + 273.15; patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + potV_x = solution_ptr->Get_potV(); /* * H+, e-, H2O diff --git a/pitzer.cpp b/pitzer.cpp index b5fa7e24..b0af2f7c 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1281,14 +1281,14 @@ pitzer(void) F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B); if (patm_x > 1.0) { - LDBLE pap = 0.0; + LDBLE pap; pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x; B1 = B - (pap > 0.2 ? 0.2 : pap); - if (TK > 263.0) - { + if (TK <= 263) + pap = 0; + else pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); - //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); - } + //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); B2 = B - (pap > 0.2 ? 0.2 : pap); if (B1 != 0) F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); @@ -1709,6 +1709,7 @@ set_pz(int initial) tk_x = tc_x + 273.15; patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + potV_x = solution_ptr->Get_potV(); /* * H+, e-, H2O diff --git a/print.cpp b/print.cpp index cbc043e5..43e5cbac 100644 --- a/print.cpp +++ b/print.cpp @@ -2975,7 +2975,7 @@ punch_identifiers(void) else if (state == TRANSPORT) { fpunchf(PHAST_NULL("dist_x"), gformat, - (double) cell_data[cell - 1].mid_cell_x); + (double) cell_data[cell].mid_cell_x); } else { diff --git a/read.cpp b/read.cpp index 4b2ff3a2..1367c117 100644 --- a/read.cpp +++ b/read.cpp @@ -3157,6 +3157,35 @@ read_millero_abcdef (char *ptr, LDBLE * abcdef) } /* VP: Density End */ +/* ---------------------------------------------------------------------- */ +int Phreeqc:: +read_viscosity_parms(char *ptr, LDBLE * Jones_Dole) +/* ---------------------------------------------------------------------- */ +{ + int j; +/* + * Read . + */ + for (j = 0; j <= 9; j++) + { + Jones_Dole[j] = 0.0; + } + j = + sscanf (ptr, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, + &(Jones_Dole[0]), &(Jones_Dole[1]), &(Jones_Dole[2]), &(Jones_Dole[3]), &(Jones_Dole[4]), &(Jones_Dole[5]), &(Jones_Dole[6]), &(Jones_Dole[7]), &(Jones_Dole[8]), &(Jones_Dole[9])); + if (j < 1) + { + input_error++; + error_msg ("Expecting numeric values for viscosity calculation.", + CONTINUE); + return (ERROR); + } + // The B0 are for 25°C, subtract the temperature factor... + if (Jones_Dole[1] != 0) + Jones_Dole[0] -= Jones_Dole[1] * exp(Jones_Dole[2] * 25.0); + return (OK); +} + /* ---------------------------------------------------------------------- */ int Phreeqc:: read_incremental_reactions(void) @@ -5615,9 +5644,10 @@ read_solution(void) "isotope", /* 9 */ "water", /* 10 */ "press", /* 11 */ - "pressure" /* 12 */ + "pressure", /* 12 */ + "potential" /* 13 */ }; - int count_opt_list = 13; + int count_opt_list = 14; /* * Read solution number and description */ @@ -5856,6 +5886,18 @@ read_solution(void) } } break; + case 13: /* potential, Volt */ + { + if (sscanf(next_char, SCANFORMAT, &dummy) != 1) + { + temp_solution.Set_potV(0); + } + else + { + temp_solution.Set_potV(dummy); + } + } + break; case OPTION_DEFAULT: /* * Read concentration @@ -5956,9 +5998,10 @@ read_species(void) /* VP: Density Start */ "millero", /* 21 */ /* VP: Density End */ - "vm" /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */ + "vm", /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */ + "viscosity" /* 23, b and d parms for viscosity, (b1 + b2 * exp(-b3 * tc)) * c + (d1 * exp(-d2 * tc)) * c ^ d3 */ }; - int count_opt_list = 23; + int count_opt_list = 24; association = TRUE; s_ptr = NULL; @@ -6265,7 +6308,9 @@ read_species(void) input_error++; break; } - i = sscanf(next_char, SCANFORMAT, &s_ptr->dw); + s_ptr->dw_t = s_ptr->dw_a = s_ptr->dw_a_exp = 0; + i = sscanf(next_char, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &s_ptr->dw, &s_ptr->dw_t, + &s_ptr->dw_a, &s_ptr->dw_a_exp); opt_save = OPTION_DEFAULT; break; case 20: /* enrichment factor in the DDL */ @@ -6325,6 +6370,20 @@ read_species(void) print_density = OK; opt_save = OPTION_DEFAULT; break; + case 23: /* viscosity parms for the Jones-Dole eqn */ + if (s_ptr == NULL) + { + error_string = sformatf( + "No reaction defined before option, %s.", + opt_list[opt]); + error_msg(error_string, CONTINUE); + input_error++; + break; + } + read_viscosity_parms(next_char, &s_ptr->Jones_Dole[0]); + print_viscosity = OK; + opt_save = OPTION_DEFAULT; + break; case OPTION_DEFAULT: /* * Get space for species information and parse equation diff --git a/readtr.cpp b/readtr.cpp index 129517ff..c55c73a7 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -193,7 +193,7 @@ read_transport(void) case 2: /* print */ case 20: /* print_cells */ print_temp = - read_list_ints_range(&next_char, &count_print, TRUE, + read_list_ints_range(&next_char, &count_print, FALSE, print_temp); opt_save = 2; break; @@ -353,7 +353,7 @@ read_transport(void) case 21: /* selected_cells */ case 30: /* punch_cells */ punch_temp = - read_list_ints_range(&next_char, &count_punch, TRUE, + read_list_ints_range(&next_char, &count_punch, FALSE, punch_temp); opt_save = 10; break; @@ -662,12 +662,12 @@ read_transport(void) * Allocate space for cell_data */ cell_data = (struct cell_data *) PHRQ_realloc(cell_data, - (size_t) (max_cells * (1 + stag_data->count_stag) + 1) * sizeof(struct cell_data)); + (size_t) (max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); if (cell_data == NULL) malloc_error(); // initialize new cells - int all_cells_now = max_cells * (1 + stag_data->count_stag) + 1; + int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; if (all_cells_now > all_cells) { for (int i = all_cells; i < all_cells_now; i++) @@ -678,6 +678,7 @@ read_transport(void) cell_data[i].temp = 25.0; cell_data[i].por = 0.1; cell_data[i].por_il = 0.01; + cell_data[i].potV = 0; cell_data[i].punch = FALSE; cell_data[i].print = FALSE; } @@ -694,15 +695,15 @@ read_transport(void) error_string = sformatf( "No cell-lengths were read; length = 1 m assumed."); warning_msg(error_string); - for (i = 0; i < max_cells; i++) + for (i = 1; i <= max_cells; i++) cell_data[i].length = 1.0; } } else { - for (i = 0; i < count_length; i++) + for (i = 1; i <= count_length; i++) { - cell_data[i].length = length[i]; + cell_data[i].length = length[i - 1]; } if (max_cells > count_length) { @@ -710,18 +711,19 @@ read_transport(void) "Cell-lengths were read for %d cells. Last value is used till cell %d.", count_length, max_cells); warning_msg(error_string); - for (i = count_length - 1; i < max_cells; i++) - cell_data[i].length = length[count_length - 1]; + for (i = count_length; i <= max_cells; i++) + cell_data[i + 1].length = length[count_length - 1]; } } - cell_data[0].mid_cell_x = cell_data[0].length / 2; - for (i = 1; i < max_cells; i++) + cell_data[0].mid_cell_x = 0; + cell_data[1].mid_cell_x = cell_data[1].length / 2; + for (i = 2; i <= max_cells; i++) { cell_data[i].mid_cell_x = cell_data[i - 1].mid_cell_x + (cell_data[i - 1].length + cell_data[i].length) / 2; } - cell_data[max_cells].mid_cell_x = - cell_data[max_cells - 1].mid_cell_x + cell_data[max_cells - 1].length; + cell_data[max_cells + 1].mid_cell_x = + cell_data[max_cells].mid_cell_x + cell_data[max_cells].length / 2; /* * Fill in data for dispersivities */ @@ -732,22 +734,22 @@ read_transport(void) error_string = sformatf( "No dispersivities were read; disp = 0 assumed."); warning_msg(error_string); - for (i = 0; i < max_cells; i++) + for (i = 1; i <= max_cells; i++) cell_data[i].disp = 0.0; } } else { - for (i = 0; i < count_disp; i++) - cell_data[i].disp = disp[i]; + for (i = 1; i <= count_disp; i++) + cell_data[i].disp = disp[i - 1]; if (max_cells > count_disp) { error_string = sformatf( "Dispersivities were read for %d cells. Last value is used till cell %d.", count_disp, max_cells); warning_msg(error_string); - for (i = count_disp - 1; i < max_cells; i++) - cell_data[i].disp = disp[count_disp - 1]; + for (i = count_disp; i <= max_cells; i++) + cell_data[i + 1].disp = disp[count_disp - 1]; } } count_cells = max_cells; @@ -756,8 +758,8 @@ read_transport(void) */ if (stag_data->count_stag > 0) { - max_cells = count_cells * (1 + stag_data->count_stag) + 1; - for (i = 0; i < count_cells; i++) + max_cells = count_cells * (1 + stag_data->count_stag) + 2; + for (i = 1; i <= count_cells; i++) { for (l = 1; l <= stag_data->count_stag; l++) cell_data[i + 1 + l * count_cells].mid_cell_x = @@ -769,11 +771,11 @@ read_transport(void) */ if (count_punch != 0) { - for (i = 0; i < max_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].punch = FALSE; for (i = 0; i < count_punch; i++) { - if (punch_temp[i] > max_cells || punch_temp[i] < 1) + if (punch_temp[i] > all_cells - 1 || punch_temp[i] < 0) { error_string = sformatf( "Cell number for punch is out of range, %d. Request ignored.", @@ -781,22 +783,22 @@ read_transport(void) warning_msg(error_string); } else - cell_data[punch_temp[i] - 1].punch = TRUE; + cell_data[punch_temp[i]].punch = TRUE; } } else if (simul_tr == 1) - for (i = 0; i < max_cells; i++) + for (i = 1; i < all_cells; i++) cell_data[i].punch = TRUE; /* * Fill in data for print */ if (count_print != 0) { - for (i = 0; i < max_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].print = FALSE; for (i = 0; i < count_print; i++) { - if (print_temp[i] > max_cells || print_temp[i] < 1) + if (print_temp[i] > all_cells - 1 || print_temp[i] < 0) { error_string = sformatf( "Cell number for print is out of range, %d. Request ignored.", @@ -804,11 +806,11 @@ read_transport(void) warning_msg(error_string); } else - cell_data[print_temp[i] - 1].print = TRUE; + cell_data[print_temp[i]].print = TRUE; } } else if (simul_tr == 1) - for (i = 0; i < max_cells; i++) + for (i = 1; i < all_cells; i++) cell_data[i].print = TRUE; /* * Fill in porosities @@ -821,7 +823,7 @@ read_transport(void) error_msg(error_string, CONTINUE); } - for (i = 0; i < max_cells; i++) + for (i = 1; i < all_cells; i++) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); @@ -1175,7 +1177,7 @@ dump_cpp(void) } sprintf(token, "\t-length\n"); fs << token; - for (int i = 0; i < count_cells; i++) + for (int i = 1; i <= count_cells; i++) { sprintf(token, "%12.3e", (double) cell_data[i].length); fs << token; @@ -1189,7 +1191,7 @@ dump_cpp(void) fs << token; sprintf(token, "\t-disp\n"); fs << token; - for (int i = 0; i < count_cells; i++) + for (int i = 1; i <= count_cells; i++) { if (!high_precision) { @@ -1216,7 +1218,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (int i = 0; i < j; i++) + for (int i = 1; i <= j; i++) { if (cell_data[i].punch != TRUE) continue; @@ -1238,7 +1240,7 @@ dump_cpp(void) else j = count_cells; l = 0; - for (int i = 0; i < j; i++) + for (int i = 1; i <= j; i++) { if (cell_data[i].print != TRUE) continue; diff --git a/sit.cpp b/sit.cpp index d84186b2..cb86f7c9 100644 --- a/sit.cpp +++ b/sit.cpp @@ -737,6 +737,7 @@ set_sit(int initial) tk_x = tc_x + 273.15; patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) + potV_x = solution_ptr->Get_potV(); /* * H+, e-, H2O diff --git a/spread.cpp b/spread.cpp index 6fac7712..0d4a18ac 100644 --- a/spread.cpp +++ b/spread.cpp @@ -547,9 +547,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, "desc", /* 12 */ "descriptor", /* 13 */ "pressure", /* 14 */ - "press" /* 15 */ + "press", /* 15 */ + "potential" /* 16 */ }; - int count_opt_list = 16; + int count_opt_list = 17; /* * look for solution number @@ -613,6 +614,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, temp_solution.Set_description(description); temp_solution.Set_tc(defaults.temp); temp_solution.Set_patm(defaults.pressure); + temp_solution.Set_potV(0); temp_solution.Set_ph(defaults.ph); temp_solution.Set_density(defaults.density); temp_solution.Set_pe(defaults.pe); @@ -927,6 +929,14 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, } } break; + case 16: /* pote, V */ + { + if (sscanf(next_char, SCANFORMAT, &dummy) == 1) + { + temp_solution.Set_potV(dummy); + } + } + break; case OPTION_DEFAULT: /* * Read concentration diff --git a/step.cpp b/step.cpp index 57a4a860..62cc917f 100644 --- a/step.cpp +++ b/step.cpp @@ -106,11 +106,11 @@ step(LDBLE step_fraction) tc_x = t_ptr->Temperature_for_step(step_number); } if ((state == TRANSPORT) && (transport_step != 0) && - (cell > 0) && (cell != count_cells + 1)) + (cell > 0) && (cell != count_cells + 1)) // ** needs potV correction { - difftemp = tc_x - cell_data[cell - 1].temp; - cell_data[cell - 1].temp += difftemp / tempr; - tc_x = cell_data[cell - 1].temp; + difftemp = tc_x - cell_data[cell].temp; + cell_data[cell].temp += difftemp / tempr; + tc_x = cell_data[cell].temp; } /* * Pressure @@ -305,6 +305,7 @@ xsolution_zero(void) tc_x = 0.0; patm_x = 0; + potV_x = 0; ph_x = 0.0; solution_pe_x = 0.0; mu_x = 0.0; @@ -357,6 +358,7 @@ add_solution(cxxSolution *solution_ptr, LDBLE extensive, LDBLE intensive) tc_x += solution_ptr->Get_tc() * intensive; ph_x += solution_ptr->Get_ph() * intensive; patm_x += solution_ptr->Get_patm() * intensive; + potV_x += solution_ptr->Get_potV() * intensive; solution_pe_x += solution_ptr->Get_pe() * intensive; mu_x += solution_ptr->Get_mu() * intensive; ah2o_x += solution_ptr->Get_ah2o() * intensive; diff --git a/transport.cpp b/transport.cpp index 69daeddc..fa12f822 100644 --- a/transport.cpp +++ b/transport.cpp @@ -7,6 +7,33 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "Solution.h" + +LDBLE F_Re3 = F_C_MOL / (R_KJ_DEG_MOL * 1e3); +LDBLE tk_x2; // average tx_x of icell and jcell +LDBLE dV_dcell; // difference in Volt among icell and jcell +int find_current; +struct CURRENT_CELLS +{ + LDBLE dif, ele, R; // diffusive and electric components, relative cell resistance +} *current_cells; +LDBLE sum_R; // sum of R +struct V_M +{ + LDBLE grad, D, z, c, zc, Dz, Dzc, Dzc_dl, g_dl; + int o_c; +}; +struct CT /* contains the mcd transfer in a timestep for all cells, for free + DL water */ +{ + LDBLE dl_s, A_ij, Dz2c, Dz2c_dl, visc1, visc2, J_ij_sum; + int J_ij_count_spec; + struct V_M *v_m; + struct J_ij *J_ij; +} *ct = NULL; +struct MOLES_ADDED /* total moles added to balance negative conc's */ +{ + char *name; + LDBLE moles; +} *moles_added; /* ---------------------------------------------------------------------- */ int Phreeqc:: transport(void) @@ -28,6 +55,8 @@ transport(void) diffc_tr = diffc; diffc_max = 0.0; transp_surf = warn_fixed_Surf = warn_MCD_X = 0; + dV_dcell = current_A = 0.0; + /* mass_water_switch = TRUE; */ /* * Check existence of solutions @@ -46,29 +75,46 @@ transport(void) error_msg(error_string, CONTINUE); } else - cell_data[i - 1].temp = use.Get_solution_ptr()->Get_tc(); + { + cell_data[i].temp = use.Get_solution_ptr()->Get_tc(); + } } if (multi_Dflag) { - sol_D = (struct sol_D *) PHRQ_malloc((size_t) - (count_cells + 2 + stag_data->count_stag * count_cells) * - sizeof(struct sol_D)); + sol_D = (struct sol_D *) PHRQ_malloc((size_t) (all_cells) * sizeof(struct sol_D)); if (sol_D == NULL) malloc_error(); sol_D_dbg = sol_D; - for (i = 0; i < count_cells + 2 + stag_data->count_stag * count_cells; - i++) + + ct = (struct CT *) PHRQ_malloc((size_t) (all_cells) * sizeof(struct CT)); + if (ct == NULL) + malloc_error(); + + moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t) (count_elements) * sizeof(struct MOLES_ADDED)); + if (moles_added == NULL) + malloc_error(); + + for (i = 0; i < all_cells; i++) { sol_D[i].count_spec = 0; sol_D[i].count_exch_spec = 0; sol_D[i].exch_total = 0; sol_D[i].x_max = 0; sol_D[i].spec = NULL; + + ct[i].J_ij = NULL; + ct[i].v_m = NULL; + } + for (i = 0; i < count_elements; i++) + { + moles_added[i].name = NULL; + moles_added[i].moles = 0; } } /* check solution 0 */ - if (Utilities::Rxn_find(Rxn_solution_map, 0) == NULL) + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, 0)); + if (!use.Get_solution_ptr()) { if (ishift == 1) { @@ -80,9 +126,15 @@ transport(void) else Utilities::Rxn_copy(Rxn_solution_map, 1, 0); } + else + { + if ((cell_data[0].potV = use.Get_solution_ptr()->Get_potV())) + dV_dcell = 1; + } /* check solution count_cells */ - if (Utilities::Rxn_find(Rxn_solution_map, count_cells + 1) == NULL) + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, count_cells + 1)); + if (!use.Get_solution_ptr()) { if (ishift == -1) { @@ -95,6 +147,11 @@ transport(void) else Utilities::Rxn_copy(Rxn_solution_map, count_cells, count_cells + 1); } + else + { + if ((cell_data[count_cells + 1].potV = use.Get_solution_ptr()->Get_potV())) + dV_dcell = 1; + } /* * Initialize temperature in stagnant cells ... */ @@ -105,7 +162,32 @@ transport(void) k = i + 1 + n * count_cells; use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, k)); if (use.Get_solution_ptr() != NULL) - cell_data[k - 1].temp = use.Get_solution_ptr()->Get_tc(); + cell_data[k].temp = use.Get_solution_ptr()->Get_tc(); + } + } + + if (dV_dcell) + { + if (stag_data->count_stag || !multi_Dflag || ishift) + { + input_error++; + error_string = sformatf( + "Electrical Field (potential) was defined, but needs -mult_D, \n\t and is not possible with -stagnant or with advective flow."); + error_msg(error_string, CONTINUE); + free_check_null(sol_D); + } + else + { + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) + (count_cells + 1) * sizeof(struct CURRENT_CELLS)); + if (current_cells == NULL) + malloc_error(); + for (int i = 0; i < count_cells + 1; i++) + { + current_cells[i].dif = 0.0; + current_cells[i].ele = 0.0; + current_cells[i].R = 0.0; + } } } /* @@ -133,15 +215,11 @@ transport(void) { fill_spec(cell_no); } - if (cell_no > 0 && cell_no <= count_cells) - { - if ((cell_data[i - 1].punch == TRUE) - && (cell_no != count_cells + 1)) - punch_all(); - if ((cell_data[i - 1].print == TRUE) - && (cell_no != count_cells + 1)) - print_all(); - } + if (cell_data[i].punch == TRUE) + punch_all(); + if (cell_data[i].print == TRUE) + print_all(); + /* if (i > 0 && i <= count_cells)*/ saver(); } @@ -162,9 +240,9 @@ transport(void) { fill_spec(cell_no); } - if (cell_data[k - 1].punch == TRUE) + if (cell_data[k].punch == TRUE) punch_all(); - if ((cell_data[k - 1].print == TRUE) + if ((cell_data[k].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); saver(); @@ -186,7 +264,7 @@ transport(void) warning_msg(token); } */ - + Rxn_mix_map.clear(); /* @@ -210,10 +288,6 @@ transport(void) kin_time_save = kin_time; /* Reaction defined for a shift... */ - //if (ishift == 0 && nmix == 1) - // step_fraction = 1.0; - //else - // step_fraction = 1.0 / (1.0 + nmix); if (!ishift) { if (nmix < 2) @@ -326,8 +400,12 @@ transport(void) /* * Set initial moles of phases */ - for (i = 1; i <= count_cells; i++) - set_initial_moles(i); + for (i = 0; i <= count_cells + 1; i++) + { + if (!dV_dcell && (i == 0 || i == count_cells + 1)) + continue; + set_initial_moles(i); + } /* * Also stagnant cells */ @@ -356,14 +434,19 @@ transport(void) rate_sim_time = rate_sim_time_start + kin_time; mixrun = j; - if (multi_Dflag) - sprintf(token, - "Transport step %3d. Multicomponent diffusion run %3d.", - transport_step, j); - else + if (multi_Dflag && j == floor((LDBLE) nmix / 2)) + { + //sprintf(token, + // "Transport step %3d. Multicomponent diffusion run %3d.", + // transport_step, j); + //dup_print(token, FALSE); + } + else if (!multi_Dflag) + { sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); - dup_print(token, FALSE); + dup_print(token, FALSE); + } if (heat_nmix > 0) { @@ -388,9 +471,10 @@ transport(void) if (multi_Dflag) multi_D(stagkin_time, 1, FALSE); - for (i = 1; i <= count_cells; i++) + for (i = 0; i <= count_cells + 1; i++) { - + //if (!dV_dcell && (i == 0 || i == count_cells + 1)) + // continue; if (iterations > max_iter) max_iter = iterations; cell_no = i; @@ -405,7 +489,10 @@ transport(void) transport_step, j, i, max_iter); status(0, token); - run_reactions(i, kin_time, DISP, step_fraction); + if (i == 0 || i == count_cells + 1) + run_reactions(i, kin_time, NOMIX, step_fraction); + else + run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag) fill_spec(i); @@ -414,10 +501,10 @@ transport(void) && ((stag_data->count_stag == 0) || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { - if ((cell_data[i - 1].punch == TRUE) + if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i - 1].print == TRUE) + if ((cell_data[i].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); } @@ -582,10 +669,10 @@ transport(void) if ((nmix == 0) && ((stag_data->count_stag == 0) || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { - if ((cell_data[i - 1].punch == TRUE) + if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i - 1].print == TRUE) + if ((cell_data[i].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); } @@ -629,14 +716,19 @@ transport(void) j = 1; for (j = j; j <= nmix; j++) { - if (multi_Dflag) + if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0)) + { sprintf(token, "Transport step %3d. Multicomponent diffusion run %3d.", transport_step, j); - else + dup_print(token, FALSE); + } + else if (!multi_Dflag) + { sprintf(token, "Transport step %3d. Mixrun %3d.", transport_step, j); - dup_print(token, FALSE); + dup_print(token, FALSE); + } rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * kin_time; if (ishift != 0) @@ -666,8 +758,10 @@ transport(void) multi_D(stagkin_time, 1, FALSE); /* for each cell in column */ - for (i = 1; i <= count_cells; i++) + for (i = 0; i <= count_cells + 1; i++) { + if (!dV_dcell && (i == 0 || i == count_cells + 1)) + continue; if (iterations > max_iter) max_iter = iterations; cell_no = i; @@ -682,16 +776,20 @@ transport(void) transport_step, j, i, max_iter); status(0, token); - run_reactions(i, kin_time, DISP, step_fraction); + if (i == 0 || i == count_cells + 1) + //set_and_run_wrapper(i, NOMIX, FALSE, -2 - i, 0.0); + run_reactions(i, kin_time, NOMIX, step_fraction); + else + run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); if ((j == nmix) && ((stag_data->count_stag == 0) || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { - if ((cell_data[i - 1].punch == TRUE) + if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i - 1].print == TRUE) + if ((cell_data[i].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); } @@ -743,7 +841,23 @@ transport(void) } screen_msg("\n"); - /* free_model_allocs(); */ + if (multi_Dflag && moles_added[0].moles > 0) + { + sprintf(token, + "\nFor balancing negative concentrations in MCD, added in total to the system:"); + if (phrq_io) + phrq_io->warning_msg(token); + for (i = 0; i < count_elements; i++) + { + if (!moles_added[i].moles) + break; + sprintf(token, + "\t %.4e moles %s.", + (double) moles_added[i].moles, moles_added[i].name); + if (phrq_io) + phrq_io->warning_msg(token); + } + } /* * free mix structures */ @@ -761,11 +875,16 @@ transport(void) } if (multi_Dflag) { - for (i = 0; i < count_cells + 2 + stag_data->count_stag * count_cells; - i++) + for (i = 0; i < all_cells; i++) + { sol_D[i].spec = (struct spec *) free_check_null(sol_D[i].spec); + } sol_D = (struct sol_D *) free_check_null(sol_D); + ct = (struct CT *) free_check_null(ct); + moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } + if (dV_dcell) + free_check_null(current_cells); initial_total_time += rate_sim_time; rate_sim_time = 0; @@ -777,14 +896,26 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; + LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD, dx = 0; int i, l_nmix; - std::vector m, m1; + //std::vector m, m1; + //for(i = 0; i < count_cells + 1; i++) + //{ + // m.push_back(0); // this takes 5* more time than malloc & m[i] = 0 + // m1.push_back(0); + //} + LDBLE *m, *m1; + m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + if (m == NULL) + malloc_error(); + m1 = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + if (m1 == NULL) + malloc_error(); for(i = 0; i < count_cells + 1; i++) { - m.push_back(0); - m1.push_back(0); + m[i] = 0; + m1[i] = 0; } corr_disp = 1.; if (correct_disp == TRUE && ishift != 0) @@ -797,14 +928,16 @@ init_mix(void) maxmix = 0.0; if (multi_Dflag) { + if (dV_dcell) + dV_dcell = (cell_data[count_cells + 1].potV - cell_data[0].potV) / count_cells; for (i = 1; i < count_cells; i++) { - lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + lav = (cell_data[i + 1].length + cell_data[i].length) / 2; if (ishift != 0) - dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + dav = (cell_data[i + 1].disp + cell_data[i].disp) / 2; else dav = 0; - mixf = dav * corr_disp / cell_data[i].length; + mixf = dav * corr_disp / cell_data[i + 1].length; if (mixf > maxmix) maxmix = mixf; m[i] = mixf; /* m[i] has mixf with lower cell */ @@ -817,9 +950,9 @@ init_mix(void) */ if (bcon_first == 1) { - lav = cell_data[0].length; + lav = cell_data[1].length; if (ishift != 0) - dav = cell_data[0].disp; + dav = cell_data[1].disp; else dav = 0; @@ -836,9 +969,9 @@ init_mix(void) if (bcon_last == 1) { - lav = cell_data[count_cells - 1].length; + lav = cell_data[count_cells].length; if (ishift != 0) - dav = cell_data[count_cells - 1].disp; + dav = cell_data[count_cells].disp; else dav = 0; @@ -883,7 +1016,7 @@ init_mix(void) /* * Fill mix structure */ - + if (l_nmix != 0) { for (i = 1; i <= count_cells; i++) @@ -898,6 +1031,8 @@ init_mix(void) Dispersion_mix_map[i] = temp_mix; } } + m = (LDBLE *) free_check_null(m); + m1 = (LDBLE *) free_check_null(m1); return (l_nmix); } else // multi_D false @@ -909,17 +1044,17 @@ init_mix(void) for (i = 1; i < count_cells; i++) { // find mix with lower numbered cell... - lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + lav = (cell_data[i + 1].length + cell_data[i].length) / 2; if (ishift != 0) - dav = (cell_data[i - 1].disp + cell_data[i].disp) / 2; + dav = (cell_data[i + 1].disp + cell_data[i].disp) / 2; else dav = 0; - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i + 1].length; m[i] = mixf; /* m[i] has mixf with lower cell */ // and with higher numbered cell... - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i - 1].length; + mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; mf12 = m[i] + mixf; if (mf12 > maxmix) maxmix = mf12; @@ -930,9 +1065,9 @@ init_mix(void) */ if (bcon_first == 1) { - lav = cell_data[0].length; + lav = cell_data[1].length; if (ishift != 0) - dav = cell_data[0].disp; + dav = cell_data[1].disp; else dav = 0; @@ -947,9 +1082,9 @@ init_mix(void) if (bcon_last == 1) { - lav = cell_data[count_cells - 1].length; + lav = cell_data[count_cells].length; if (ishift != 0) - dav = cell_data[count_cells - 1].disp; + dav = cell_data[count_cells].disp; else dav = 0; @@ -988,7 +1123,7 @@ init_mix(void) /* * Fill mix structure */ - + if (l_nmix != 0) { for (i = 1; i <= count_cells; i++) @@ -1003,6 +1138,8 @@ init_mix(void) Dispersion_mix_map[i] = temp_mix; } } + m = (LDBLE *) free_check_null(m); + m1 = (LDBLE *) free_check_null(m1); return (l_nmix); } } @@ -1035,8 +1172,8 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) heat_mix_f_m * ptr_imm->Get_tc() + (1 - heat_mix_f_m) * ptr_m->Get_tc()); - cell_data[i - 1].temp = ptr_m->Get_tc(); - cell_data[k - 1].temp= t_imm = ptr_imm->Get_tc(); + cell_data[i].temp = ptr_m->Get_tc(); + cell_data[k].temp= t_imm = ptr_imm->Get_tc(); /* equilibrate again ... */ cell_no = i; set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); @@ -1071,10 +1208,10 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) use.Set_kinetics_in(true); } - if (l_punch && (cell_data[i - 1].print == TRUE) && + if (l_punch && (cell_data[i].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); - if (l_punch && (cell_data[i - 1].punch == TRUE) && + if (l_punch && (cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); saver(); @@ -1102,10 +1239,10 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) if (multi_Dflag == TRUE) fill_spec(cell_no); - if ((cell_data[k - 1].print == TRUE) && (l_punch == TRUE) && + if ((cell_data[k].print == TRUE) && (l_punch == TRUE) && (transport_step % print_modulus == 0)) print_all(); - if ((cell_data[k - 1].punch == TRUE) && (l_punch == TRUE) && + if ((cell_data[k].punch == TRUE) && (l_punch == TRUE) && (transport_step % punch_modulus == 0)) punch_all(); saver(); @@ -1160,7 +1297,7 @@ init_heat_mix(int l_nmix) l_heat_nmix = 0; t0 = Utilities::Rxn_find(Rxn_solution_map, 0)->Get_tc(); - for (i = 0; i < count_cells; i++) + for (i = 1; i <= count_cells; i++) { if (fabs(cell_data[i].temp - t0) > 1.0) { @@ -1179,7 +1316,7 @@ init_heat_mix(int l_nmix) k = i + 1 + n * count_cells; if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { - if (fabs(cell_data[k - 1].temp - t0) > 1.0) + if (fabs(cell_data[k].temp - t0) > 1.0) { l_heat_nmix = 1; break; @@ -1220,7 +1357,7 @@ init_heat_mix(int l_nmix) maxmix = 0.0; for (i = 1; i < count_cells; i++) { - lav = (cell_data[i - 1].length + cell_data[i].length) / 2; + lav = (cell_data[i + 1].length + cell_data[i].length) / 2; mixf = (heat_diffc - diffc_tr) * timest * corr_disp / tempr / (lav * lav); @@ -1233,7 +1370,7 @@ init_heat_mix(int l_nmix) */ if (bcon_first == 1) { - lav = cell_data[0].length; + lav = cell_data[1].length; mixf = (heat_diffc - diffc_tr) * timest * corr_disp / tempr / (lav * lav); @@ -1246,7 +1383,7 @@ init_heat_mix(int l_nmix) if (bcon_last == 1) { - lav = cell_data[count_cells - 1].length; + lav = cell_data[count_cells].length; mixf = (heat_diffc - diffc_tr) * timest * corr_disp / tempr / (lav * lav); @@ -1288,8 +1425,7 @@ heat_mix(int l_heat_nmix) { for (j = 1; j <= count_cells; j++) temp2[j] = - heat_mix_array[j] * temp1[j - 1] + heat_mix_array[j + - 1] * + heat_mix_array[j] * temp1[j - 1] + heat_mix_array[j + 1] * temp1[j + 1] + (1 - heat_mix_array[j] - heat_mix_array[j + 1]) * temp1[j]; for (j = 1; j <= count_cells; j++) @@ -1298,7 +1434,7 @@ heat_mix(int l_heat_nmix) for (i = 1; i <= count_cells; i++) { - cell_data[i - 1].temp = temp1[i]; + cell_data[i].temp = temp1[i]; Utilities::Rxn_find(Rxn_solution_map, i)->Set_tc(temp1[i]); } @@ -1442,21 +1578,23 @@ fill_spec(int l_cell_no) if (sol_D[l_cell_no].spec == NULL) malloc_error(); + sol_D[l_cell_no].tk_x = tk_x; + temp_factor = temp_il_factor = 1.0; if (l_cell_no == 0) { - por = cell_data[0].por; - por_il = cell_data[0].por_il; + por = cell_data[1].por; + por_il = cell_data[1].por_il; } else if (l_cell_no == count_cells + 1) { - por = cell_data[count_cells - 1].por; - por_il = cell_data[count_cells - 1].por_il; + por = cell_data[count_cells].por; + por_il = cell_data[count_cells].por_il; } else { - por = cell_data[l_cell_no - 1].por; - por_il = cell_data[l_cell_no - 1].por_il; + por = cell_data[l_cell_no].por; + por_il = cell_data[l_cell_no].por_il; } if (por < multi_Dpor_lim) por = temp_factor = 0.0; @@ -1465,13 +1603,14 @@ fill_spec(int l_cell_no) por_il = temp_il_factor = 0.0; /* * correct diffusion coefficient for temperature and viscosity, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + * modify viscosity effect: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15), SC data from Robinson and Stokes, 1959 */ - viscos = viscosity(); + viscos = viscos_0; /* * put temperature factor in por_factor which corrects for porous medium... */ - temp_factor *= tk_x * 0.88862 / (298.15 * viscos); - temp_il_factor *= tk_x * 0.88862 / (298.15 * viscos); + temp_factor *= tk_x * viscos_0_25 / (298.15 * viscos); + temp_il_factor *= tk_x * viscos_0_25 / (298.15 * viscos); count_spec = count_exch_spec = 0; /* @@ -1562,8 +1701,13 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].Dwt = default_Dw * temp_il_factor; else - sol_D[l_cell_no].spec[count_spec].Dwt = - s_ptr2->dw * temp_il_factor; + { + if (s_ptr->dw_t) + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * exp(s_ptr2->dw_t / 298.15 - s_ptr2->dw_t / tk_x) * temp_il_factor; + else + + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * temp_il_factor; + } count_exch_spec++; count_spec++; } @@ -1573,7 +1717,6 @@ fill_spec(int l_cell_no) lm = s_ptr->lm; if (lm > MIN_LM) { - //sol_D[l_cell_no].spec[count_spec].name = string_hsave(s_ptr->name); sol_D[l_cell_no].spec[count_spec].name = s_ptr->name; sol_D[l_cell_no].spec[count_spec].type = AQ; sol_D[l_cell_no].spec[count_spec].c = @@ -1586,7 +1729,12 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].Dwt = default_Dw * temp_factor; else - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * temp_factor; + { + if (s_ptr->dw_t) + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * temp_factor; + else + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * temp_factor; + } if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = @@ -1633,260 +1781,257 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) * NOTE. Define the water content of stagnant cells relative to the * mobile cell (with, for example, 1 kg water) * Define properties of each interface only 1 time with MIX. + * If an electrical field is applied (dV_dcell != 0), the currents j_i = current_cells[i].ele (C * s) + are calculated for all cells. Then dV is distributed according to + relative cell resistance, R_i / sum_R, and the smallest j_x is the current_x (C * s), + equal for all cells. */ int icell, jcell, i, l, n, length, length2, il_calcs; - int i1; + int i1, loop_f_c; int first_c, last_c; char token[MAX_LENGTH]; LDBLE mixf, temp; - for (n = 0; n < (stagnant ? stag_data->count_stag : 1); n++) - { - icell = mobile_cell + 1 + n * count_cells; - if (stagnant) - { - if (n == 0) - icell -= 1; - /* - * find the mix ptr for icell and go along the cells that mix with it - */ - use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); - if (use.Get_mix_ptr() == NULL) - continue; - first_c = 0; - last_c = (int) (use.Get_mix_ptr()->Get_mixComps().size() - 1); - } - else - { /* regular column... */ - if (bcon_first == 1) - first_c = 0; - else - first_c = 1; - if (bcon_last == 1) - last_c = count_cells; - else - last_c = count_cells - 1; - } + current_x = sum_R = 0.0; + if (dV_dcell) + find_current = loop_f_c = 1; // calculate J_ij once for all cells, find smallest j_x, next with this j_x. + else + find_current = loop_f_c = 0; - for (i = first_c; i <= last_c; i++) + for (int f_c = 0; f_c <= loop_f_c; f_c++) + { + for (n = 0; n < (stagnant ? stag_data->count_stag : 1); n++) { + icell = mobile_cell + 1 + n * count_cells; if (stagnant) { - std::vector n_solution; - std::vector fraction; - (use.Get_mix_ptr())->Vectorize(n_solution, fraction); - - if ((jcell = n_solution[i]) <= icell) + if (n == 0) + icell -= 1; + /* + * find the mix ptr for icell and go along the cells that mix with it + */ + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); + if (use.Get_mix_ptr() == NULL) continue; - - mixf = fraction[i]; - if (mcd_substeps > 1) - mixf /= nmix; + first_c = 0; + last_c = (int) (use.Get_mix_ptr()->Get_mixComps().size() - 1); } else - { /* regular column... */ - icell = i; - jcell = i + 1; - mixf = 1.0; + { /* regular column... */ + if (bcon_first == 1) + first_c = 0; + else + first_c = 1; + if (bcon_last == 1) + last_c = count_cells; + else + last_c = count_cells - 1; } - /* - * 1. obtain J_ij... - */ - il_calcs = find_J(icell, jcell, mixf, DDt, stagnant); - /* - * 2. sum up the primary or secondary master_species - */ - if (!il_calcs) - { - tot1_h = tot1_o = tot2_h = tot2_o = 0.0; - m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * - sizeof(struct M_S)); - if (m_s == NULL) - malloc_error(); - for (i1 = 0; i1 < count_elements; i1++) - { - m_s[i1].name = NULL; - m_s[i1].tot1 = 0; - m_s[i1].tot2 = 0; - } - count_m_s = 0; - } - fill_m_s(J_ij, J_ij_count_spec); - /* - * 3. find the solutions, add or subtract the moles... - */ - if (i > 0 || stagnant) + for (i = first_c; i <= last_c; i++) { - use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); - use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); - use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); - use.Get_solution_ptr()->Set_cb(use.Get_solution_ptr()->Get_cb() - J_ij_sum); - for (l = 0; l < count_m_s; l++) + if (stagnant) { - temp = 0.0; - length = (int) strlen(m_s[l].name); - cxxNameDouble::iterator it; - for (it = use.Get_solution_ptr()->Get_totals().begin(); - it != use.Get_solution_ptr()->Get_totals().end(); it++) + std::vector n_solution; + std::vector fraction; + (use.Get_mix_ptr())->Vectorize(n_solution, fraction); + + if ((jcell = n_solution[i]) <= icell) + continue; + + mixf = fraction[i]; + if (mcd_substeps > 1) + mixf /= nmix; + } + else + { /* regular column... */ + icell = i; + jcell = i + 1; + mixf = 1.0; + } + if (dV_dcell) + { + tk_x2 = (sol_D[icell].tk_x + sol_D[jcell].tk_x) / 2; + } + /* + * 1. obtain J_ij... + */ + il_calcs = find_J(icell, jcell, mixf, DDt, stagnant); + if (find_current) + { + if (i < last_c) + continue; + else { - LDBLE moles = it->second; - length2 = - (int) (size_t) strcspn(it->first.c_str(), "("); - if (strncmp - (m_s[l].name, - it->first.c_str(), - length) == 0 && length == length2) + LDBLE dV, dVc, jx; + // distribute dV_dcell according to relative resistance, calculate current_x + dV = dV_dcell * count_cells; + for (i1 = 0; i1 <= count_cells; i1 ++) { - if (moles < m_s[l].tot1) - { - temp = moles; - it->second = 0.0; - /* see if other redox states have more moles... */ - cxxNameDouble::iterator kit = it; - kit++; - for ( ; kit != use.Get_solution_ptr()->Get_totals().end(); kit++) - { - length2 = (int) (size_t) strcspn( - kit->first.c_str(), "("); - if (strncmp(m_s[l].name, - kit->first.c_str(), length) == 0 - && length == length2) - { - temp += kit->second; - if (temp < m_s[l].tot1) - { - kit->second = 0; - } - else - { - kit->second = temp - m_s[l].tot1; - temp = 0.0; - break; - } - } - } - if (temp != 0.0 && m_s[l].tot1 - temp > 1e-12) - { - sprintf(token, - "Negative concentration in MCD: added %.1e moles %s in cell %d.", - (double) (m_s[l].tot1 - temp), - m_s[l].name, icell); - warning_msg(token); - } - } - else - it->second -= m_s[l].tot1; - break; + dVc = current_cells[i1].R / sum_R * dV; + if (i1 < count_cells) + cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; + jx = current_cells[i1].ele * dVc / dV_dcell; + if (i1 == 0 || (abs(jx) < abs(current_x))) + current_x = jx; } + find_current = 0; + continue; } - if (it == use.Get_solution_ptr()->Get_totals().end()) + } + + /* + * 2. sum up the primary or secondary master_species + */ + if (!il_calcs) + { + tot1_h = tot1_o = tot2_h = tot2_o = 0.0; + m_s = (struct M_S *) free_check_null(m_s); + m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * + sizeof(struct M_S)); + if (m_s == NULL) + malloc_error(); + for (i1 = 0; i1 < count_elements; i1++) { - use.Get_solution_ptr()->Get_totals()[m_s[l].name] = -m_s[l].tot1; - if (-m_s[l].tot1 < 0) + m_s[i1].name = NULL; + m_s[i1].tot1 = 0; + m_s[i1].tot2 = 0; + } + count_m_s = 0; + } + fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); + + /* + * 3. find the solutions, add or subtract the moles... + */ + if (i > 0 || stagnant || (i == 0 && dV_dcell)) + { + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); + use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); + use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); + if (dV_dcell && i > 0) + { + use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); + } + for (l = 0; l < count_m_s; l++) + { + length = (int) strlen(m_s[l].name); + cxxNameDouble::iterator it; + for (it = use.Get_solution_ptr()->Get_totals().begin(); + it != use.Get_solution_ptr()->Get_totals().end(); it++) { - if (-m_s[l].tot1 < -1e-12) + length2 = + (int) (size_t) strcspn(it->first.c_str(), "("); + if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { - sprintf(token, - "Negative concentration in MCD: added %.2e moles %s in cell %d", - (double) m_s[l].tot1, m_s[l].name, icell); - warning_msg(token); + it->second -= m_s[l].tot1; + break; } - use.Get_solution_ptr()->Get_totals()[m_s[l].name] = 0; + } + if (it == use.Get_solution_ptr()->Get_totals().end()) + { + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = -m_s[l].tot1; } } } - } - if (i < count_cells || stagnant) - { - use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, jcell)); - dummy = use.Get_solution_ptr()->Get_total_h(); - use.Get_solution_ptr()->Set_total_h(dummy + tot2_h); - dummy = use.Get_solution_ptr()->Get_total_o(); - use.Get_solution_ptr()->Set_total_o(dummy + tot2_o); - dummy = use.Get_solution_ptr()->Get_cb(); - use.Get_solution_ptr()->Set_cb(dummy + J_ij_sum); - for (l = 0; l < count_m_s; l++) + if (i < count_cells || stagnant || (i == count_cells && dV_dcell)) { - temp = 0.0; - length = (int) strlen(m_s[l].name); - cxxNameDouble::iterator it; - for (it = use.Get_solution_ptr()->Get_totals().begin(); - it != use.Get_solution_ptr()->Get_totals().end(); it++) + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, jcell)); + dummy = use.Get_solution_ptr()->Get_total_h(); + use.Get_solution_ptr()->Set_total_h(dummy + tot1_h); + dummy = use.Get_solution_ptr()->Get_total_o(); + use.Get_solution_ptr()->Set_total_o(dummy + tot1_o); + for (l = 0; l < count_m_s; l++) { - length2 = (int) (size_t) strcspn( - it->first.c_str(), "("); - if (strncmp(m_s[l].name, - it->first.c_str(), length) == 0 - && length == length2) + length = (int) strlen(m_s[l].name); + cxxNameDouble::iterator it; + for (it = use.Get_solution_ptr()->Get_totals().begin(); + it != use.Get_solution_ptr()->Get_totals().end(); it++) { - if (it->second < -m_s[l].tot2) + length2 = (int) (size_t) strcspn(it->first.c_str(), "("); + if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { - temp = it->second; - it->second = 0; - /* see if other redox states have more moles... */ - cxxNameDouble::iterator kit = it; - kit++; - for ( ; kit != use.Get_solution_ptr()->Get_totals().end(); kit++) - { - length2 = (int) (size_t) strcspn( - kit->first.c_str(), "("); - if (strncmp - (m_s[l].name, - kit->first.c_str(), length) == 0 - && length == length2) - { - temp += kit->second; - if (temp < -m_s[l].tot2) - { - kit->second = 0; - } - else - { - kit->second = temp + m_s[l].tot2; - temp = 0.0; - break; - } - } - } - if (temp != 0.0 - && -m_s[l].tot2 - temp > 1e-12) - { - sprintf(token, - "Negative concentration in MCD: added %.3e moles %s in cell %d", - (double) (-m_s[l].tot2 - temp), - m_s[l].name, jcell); - warning_msg(token); - } + it->second += m_s[l].tot1; + break; } - else - it->second += m_s[l].tot2; - break; } - } - if (it == use.Get_solution_ptr()->Get_totals().end()) - { - use.Get_solution_ptr()->Get_totals()[m_s[l].name] = m_s[l].tot2; - if (m_s[l].tot2 < 0) + if (it == use.Get_solution_ptr()->Get_totals().end()) { - if (m_s[l].tot2 < -1e-12) - { - sprintf(token, - "Negative concentration in MCD: added %.4e moles %s in cell %d", - (double) -m_s[l].tot2, m_s[l].name, jcell); - warning_msg(token); - } - use.Get_solution_ptr()->Get_totals()[m_s[l].name] = 0; + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = m_s[l].tot1; } } } } } } + // check for negative conc's... + for (i = first_c; i <= last_c + 1; i++) + { + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); + cxxNameDouble::iterator it; + for (it = use.Get_solution_ptr()->Get_totals().begin(); + it != use.Get_solution_ptr()->Get_totals().end(); it++) + { + LDBLE moles = it->second; + if (moles < 0) + { + temp = moles; + it->second = 0; + /* see if other redox states have more moles... */ + length = (int) strlen(it->first.c_str()); + cxxNameDouble::iterator kit; + for (kit = use.Get_solution_ptr()->Get_totals().begin(); + kit != use.Get_solution_ptr()->Get_totals().end(); kit++) + { + length2 = (int) (size_t) strcspn(kit->first.c_str(), "("); + if (!strncmp(it->first.c_str(), kit->first.c_str(), length2)) + { + temp += kit->second; + if (temp < 0) + { + kit->second = 0; + } + else + { + kit->second = temp; + break; + } + } + } + if (temp < -1e-12) + { + sprintf(token, + "Negative concentration in MCD: added %.4e moles %s in cell %d", + (double) -temp, it->first.c_str(), i); + warning_msg(token); + for (i1 = 0; i1 < count_elements; i1++) + { + if (moles_added[i1].name && !strcmp(moles_added[i1].name, it->first.c_str())) + { + moles_added[i1].moles -= temp; + break; + } + else if (!moles_added[i1].moles) + { + moles_added[i1].name = string_duplicate(it->first.c_str()); + moles_added[i1].moles -= temp; + break; + } + } + } + } + } + } + m_s = (struct M_S *) free_check_null(m_s); - J_ij = (struct J_ij *) free_check_null(J_ij); J_ij_il = (struct J_ij *) free_check_null(J_ij_il); + for (i = 0; i < all_cells; i++) + { + { + ct[i].J_ij = (struct J_ij *) free_check_null(ct[i].J_ij); + ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); + } + } return (OK); } @@ -1903,6 +2048,8 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) for (j = 0; j < l_J_ij_count_spec; j++) { + if (!l_J_ij[j].tot1) + continue; { char * temp_name = string_duplicate(l_J_ij[j].name); ptr = temp_name; @@ -1917,12 +2064,10 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) if (strcmp(elt_list[k].elt->name, "H") == 0) { tot1_h += elt_list[k].coef * l_J_ij[j].tot1; - tot2_h += elt_list[k].coef * l_J_ij[j].tot2; } else if (strcmp(elt_list[k].elt->name, "O") == 0) { tot1_o += elt_list[k].coef * l_J_ij[j].tot1; - tot2_o += elt_list[k].coef * l_J_ij[j].tot2; } else { @@ -1931,16 +2076,13 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) if (strcmp(m_s[l].name, elt_list[k].elt->name) == 0) { m_s[l].tot1 += elt_list[k].coef * l_J_ij[j].tot1; - m_s[l].tot2 += elt_list[k].coef * l_J_ij[j].tot2; break; } } if (l == count_m_s) { - //m_s[l].name = string_hsave(elt_list[k].elt->name); m_s[l].name = elt_list[k].elt->name; m_s[l].tot1 = elt_list[k].coef * l_J_ij[j].tot1; - m_s[l].tot2 = elt_list[k].coef * l_J_ij[j].tot2; count_m_s++; } } @@ -1962,7 +2104,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / * (length_icell / 2) * lav = A_icell + A_jcell - * grad(c) is concentration difference in icell and jcell, + * grad(c) is concentration difference in icell and jcell (dx is in lav), for activity corrections see Appelo & Wersin, 2007. * stagnant TRUE: * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) @@ -1974,7 +2116,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) stagnant: mixf_il is mixf * por_il / por. por_il = interlayer porosity, from -interlayer_D true 'por_il'. por = total porosity, from -multi_D true 'multi_Dpor'. - **nov. 12, 2011**: + **nov. 12, 2011**: mixf is corrected, * (1 - por_il / por). new_pf = (por - por_il)^(-multi_Dn). in regular column, A is calc'd from (free + DL porewater) and cell-length. @@ -1987,60 +2129,61 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) */ int i, i_max, j, j_max, k, k_il, only_counter, il_calcs; int i1; - LDBLE lav, A1, A2, A_ij, A_ij_il, ddlm, aq1, aq2, mixf_il; - LDBLE dl_s, dl_aq1, dl_aq2, c_dl, visc1, visc2, dum, dum2, tort1, tort2; + LDBLE lav, A1, A2, A_ij_il, ddlm, aq1, aq2, mixf_il; + LDBLE dl_aq1, dl_aq2, c_dl, dum, dum2, tort1, tort2; + LDBLE c, Dz2c_il, aq_il1, aq_il2; LDBLE por_il1, por_il2, por_il12; - LDBLE c, Dz2c, Dz2c_dl, Dz2c_il, aq_il1, aq_il2; LDBLE cec1, cec2, cec12, rc1, rc2; - struct V_M - { - LDBLE grad, D, z, Dz, Dzc, Dzc_dl, g_dl; - int o_c; - } *V_M, *V_M_il; + LDBLE dV, c1, c2; + struct V_M *V_M_il; + cxxSurface *s_ptr1, *s_ptr2; cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; char token[MAX_LENGTH], token1[MAX_LENGTH]; - V_M = V_M_il = NULL; /* check for immediate return and interlayer diffusion calcs... */ if (interlayer_Dflag) { il_calcs = 1; - if (icell == 0 && cell_data[0].por_il < interlayer_Dpor_lim) + if (icell == 0 && cell_data[1].por_il < interlayer_Dpor_lim) il_calcs = 0; else if (icell == count_cells && - cell_data[count_cells - 1].por_il < interlayer_Dpor_lim) + cell_data[count_cells].por_il < interlayer_Dpor_lim) il_calcs = 0; else if (icell > 0 - && (cell_data[icell - 1].por_il < interlayer_Dpor_lim - || cell_data[jcell - 1].por_il < interlayer_Dpor_lim)) + && (cell_data[icell].por_il < interlayer_Dpor_lim + || cell_data[jcell].por_il < interlayer_Dpor_lim)) il_calcs = 0; } else il_calcs = 0; + if (dV_dcell && !find_current) + goto dV_dcell2; + + ct[icell].v_m = V_M_il = NULL; if (stagnant) { - if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim - || cell_data[jcell - 1].por < multi_Dpor_lim)) + if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim + || cell_data[jcell].por < multi_Dpor_lim)) return (OK); } else { /* regular column... */ if (icell == 0) { - if (!il_calcs && cell_data[0].por < multi_Dpor_lim) + if (!il_calcs && cell_data[1].por < multi_Dpor_lim) return (OK); } else if (icell == count_cells) { - if (!il_calcs && cell_data[count_cells - 1].por < multi_Dpor_lim) + if (!il_calcs && cell_data[count_cells].por < multi_Dpor_lim) return (OK); } else { - if (!il_calcs && (cell_data[icell - 1].por < multi_Dpor_lim - || cell_data[jcell - 1].por < multi_Dpor_lim)) + if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim + || cell_data[jcell].por < multi_Dpor_lim)) return (OK); } } @@ -2053,8 +2196,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) */ s_charge_ptr1 = s_charge_ptr2 = NULL; s_ptr1 = s_ptr2 = NULL; - dl_s = dl_aq1 = dl_aq2 = 0.0; - visc1 = visc2 = 1.0; + ct[icell].dl_s = dl_aq1 = dl_aq2 = 0.0; + ct[icell].visc1 = ct[icell].visc2 = 1.0; only_counter = FALSE; s_ptr1 = Utilities::Rxn_find(Rxn_surface_map, icell); @@ -2067,18 +2210,18 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* find the one (and only one...) immobile surface comp with DL... */ for (i = 0; i < (int) s_ptr1->Get_surface_comps().size(); i++) { - cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); + cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); if (comp_i_ptr->Get_Dw() == 0) { s_charge_ptr1 = s_ptr1->Find_charge(comp_i_ptr->Get_charge_name()); dl_aq1 = s_charge_ptr1->Get_mass_water(); - visc1 = s_ptr1->Get_DDL_viscosity(); + ct[icell].visc1 = s_ptr1->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ for (j = i + 1; j < (int) s_ptr1->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr1->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 - && (comp_j_ptr->Get_charge_name() != + && (comp_j_ptr->Get_charge_name() != comp_i_ptr->Get_charge_name())) { if (!warn_fixed_Surf) @@ -2114,13 +2257,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { s_charge_ptr2 = s_ptr2->Find_charge(comp_i_ptr->Get_charge_name()); dl_aq2 = s_charge_ptr2->Get_mass_water(); - visc2 = s_ptr2->Get_DDL_viscosity(); + ct[icell].visc2 = s_ptr2->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ for (j = i + 1; j < (int) s_ptr2->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr2->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 - && (comp_j_ptr->Get_charge_name() != + && (comp_j_ptr->Get_charge_name() != comp_i_ptr->Get_charge_name())) { if (!warn_fixed_Surf) @@ -2145,95 +2288,95 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (!stagnant) { if (icell == 0) - visc1 = visc2; + ct[icell].visc1 = ct[icell].visc2; else if (icell == count_cells) - visc2 = visc1; + ct[icell].visc2 = ct[icell].visc1; } /* in each cell: DL surface = mass_water_DL / (cell_length) free pore surface = mass_water_free / (cell_length) determine DL surface as a fraction of the total pore surface... */ if (dl_aq1 > 0) - dl_s = dl_aq1 / (dl_aq1 + aq1); + ct[icell].dl_s = dl_aq1 / (dl_aq1 + aq1); if (dl_aq2 > 0) { dum = dl_aq2 / (dl_aq2 + aq2); if (dl_aq1 > 0) /* average the 2... */ - dl_s = (dl_s + dum) / 2; + ct[icell].dl_s = (ct[icell].dl_s + dum) / 2; else /* there is one DL surface... */ - dl_s = dum; + ct[icell].dl_s = dum; } por_il1 = por_il2 = por_il12 = 0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; if (il_calcs) { - /* find interlayer porosity por_il, + /* find interlayer porosity por_il, make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). Find amounts of IL water and cec. Must do this separately, since por and por_il are in cell_data structure. */ if (icell == 0) { por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * - cell_data[0].por_il; + cell_data[1].por_il; por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * - cell_data[0].por_il; + cell_data[1].por_il; if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) /* take the average... */ por_il12 = (por_il1 + por_il2) / 2; else /* at column ends, take the clay... */ por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[0].por) - por_il12 = 0.999 * cell_data[0].por; + if (por_il12 > 0.999 * cell_data[1].por) + por_il12 = 0.999 * cell_data[1].por; - if (por_il2 > 0.999 * cell_data[0].por) - por_il2 = 0.999 * cell_data[0].por; + if (por_il2 > 0.999 * cell_data[1].por) + por_il2 = 0.999 * cell_data[1].por; aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[0].por - por_il2); + (cell_data[1].por - por_il2); /* Assume interlayer water is proportional with CEC... */ aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; } else if (icell == count_cells) { por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * - cell_data[count_cells - 1].por_il; + cell_data[count_cells].por_il; por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * - cell_data[count_cells - 1].por_il; + cell_data[count_cells].por_il; if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) por_il12 = (por_il1 + por_il2) / 2; else por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[count_cells - 1].por) - por_il12 = 0.999 * cell_data[count_cells - 1].por; + if (por_il12 > 0.999 * cell_data[count_cells].por) + por_il12 = 0.999 * cell_data[count_cells].por; - if (por_il1 > 0.999 * cell_data[count_cells - 1].por) - por_il1 = 0.999 * cell_data[count_cells - 1].por; + if (por_il1 > 0.999 * cell_data[count_cells].por) + por_il1 = 0.999 * cell_data[count_cells].por; aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[count_cells - 1].por - por_il1); + (cell_data[count_cells].por - por_il1); aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / sol_D[count_cells].exch_total; } else { por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * - cell_data[icell - 1].por_il; + cell_data[icell].por_il; por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * - cell_data[jcell - 1].por_il; - + cell_data[jcell].por_il; + if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) por_il12 = (por_il1 + por_il2) / 2; else por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[icell - 1].por || por_il12 > 0.999 * cell_data[jcell - 1].por) - por_il12 = (cell_data[icell - 1].por >= cell_data[jcell - 1].por ? - 0.999 * cell_data[jcell - 1].por : - 0.999 * cell_data[icell - 1].por); + if (por_il12 > 0.999 * cell_data[icell].por || por_il12 > 0.999 * cell_data[jcell].por) + por_il12 = (cell_data[icell].por >= cell_data[jcell].por ? + 0.999 * cell_data[jcell].por : + 0.999 * cell_data[icell].por); aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[icell - 1].por - por_il1); - aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[jcell - 1].por - por_il2); + (cell_data[icell].por - por_il1); + aq_il2 = (aq2 + dl_aq2) * por_il2 / + (cell_data[jcell].por - por_il2); } if (por_il12 == 0) il_calcs = 0; @@ -2259,12 +2402,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* In stagnant calc's, find mixf_il for IL diffusion, correct mixf. In regular column, find surface areas A and A_il */ tort1 = tort2 = lav = 1.0; - A_ij = A_ij_il = mixf_il = 0.0; + ct[icell].A_ij = A_ij_il = mixf_il = 0.0; if (stagnant) { mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); - dum = (cell_data[icell - 1].por <= cell_data[jcell - 1].por ? - cell_data[icell - 1].por : cell_data[jcell - 1].por); + dum = (cell_data[icell].por <= cell_data[jcell].por ? + cell_data[icell].por : cell_data[jcell].por); if (il_calcs) { mixf_il = mixf * por_il12 / interlayer_tortf; @@ -2276,75 +2419,79 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { /* regular column... */ if (icell == 0) { - tort1 = tort2 = pow(cell_data[0].por, -multi_Dn); - lav = cell_data[0].length; - A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); + tort1 = tort2 = pow(cell_data[1].por, -multi_Dn); + lav = cell_data[1].length; + ct[icell].A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); if (il_calcs) A_ij_il = - A_ij * por_il12 / ((cell_data[0].por - por_il12) * + ct[icell].A_ij * por_il12 / ((cell_data[1].por - por_il12) * interlayer_tortf); - A_ij /= tort1; + ct[icell].A_ij /= tort1; } else if (icell == count_cells) { - tort1 = tort2 = pow(cell_data[count_cells - 1].por, -multi_Dn); - lav = cell_data[count_cells - 1].length; - A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); + tort1 = tort2 = pow(cell_data[count_cells].por, -multi_Dn); + lav = cell_data[count_cells].length; + ct[icell].A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); if (il_calcs) - A_ij_il = A_ij * por_il12 / - ((cell_data[count_cells - 1].por - por_il12) * interlayer_tortf); - A_ij /= tort2; + A_ij_il = ct[icell].A_ij * por_il12 / + ((cell_data[count_cells].por - por_il12) * interlayer_tortf); + ct[icell].A_ij /= tort2; } else { - tort1 = pow(cell_data[icell - 1].por, -multi_Dn); - tort2 = pow(cell_data[jcell - 1].por, -multi_Dn); - A1 = (aq1 + dl_aq1) / (cell_data[icell - 1].length * - 0.5 * cell_data[icell - 1].length); - A2 = (aq2 + dl_aq2) / (cell_data[jcell - 1].length * - 0.5 * cell_data[jcell - 1].length); + tort1 = pow(cell_data[icell].por, -multi_Dn); + tort2 = pow(cell_data[jcell].por, -multi_Dn); + A1 = (aq1 + dl_aq1) / (cell_data[icell].length * + 0.5 * cell_data[icell].length); + A2 = (aq2 + dl_aq2) / (cell_data[jcell].length * + 0.5 * cell_data[jcell].length); if (il_calcs) { dum = A1 * por_il12 / - ((cell_data[icell - 1].por - por_il12) * interlayer_tortf); + ((cell_data[icell].por - por_il12) * interlayer_tortf); dum2 = A2 * por_il12 / - ((cell_data[jcell - 1].por - por_il12) * interlayer_tortf); + ((cell_data[jcell].por - por_il12) * interlayer_tortf); A_ij_il = dum * dum2 / (dum + dum2); } A1 /= tort1; A2 /= tort2; - A_ij = A1 * A2 / (A1 + A2); + ct[icell].A_ij = A1 * A2 / (A1 + A2); } } /* diffuse... */ - J_ij_count_spec = 0; - J_ij_sum = 0.0; + ct[icell].J_ij_count_spec = 0; + ct[icell].J_ij_sum = 0.0; /* * malloc sufficient space... */ k = sol_D[icell].count_spec + sol_D[jcell].count_spec; - J_ij = (struct J_ij *) free_check_null(J_ij); - J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); - if (J_ij == NULL) + ct[icell].J_ij = (struct J_ij *) free_check_null(ct[icell].J_ij); + ct[icell].J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + if (ct[icell].J_ij == NULL) malloc_error(); - V_M = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); - if (V_M == NULL) + ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); + ct[icell].v_m = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + if (ct[icell].v_m == NULL) malloc_error(); for (i = 0; i < k; i++) { - J_ij[i].tot1 = 0.0; - V_M[i].grad = 0.0; - V_M[i].D = 0.0; - V_M[i].Dz = 0.0; - V_M[i].Dzc = 0.0; - V_M[i].Dzc_dl = 0.0; - V_M[i].g_dl = 1.0; - V_M[i].o_c = 1; + ct[icell].J_ij[i].tot1 = 0.0; + ct[icell].v_m[i].grad = 0.0; + ct[icell].v_m[i].D = 0.0; + ct[icell].v_m[i].z = 0.0; + ct[icell].v_m[i].c = 0.0; + ct[icell].v_m[i].zc = 0.0; + ct[icell].v_m[i].Dz = 0.0; + ct[icell].v_m[i].Dzc = 0.0; + ct[icell].v_m[i].Dzc_dl = 0.0; + ct[icell].v_m[i].g_dl = 1.0; + ct[icell].v_m[i].o_c = 1; } - Dz2c = Dz2c_dl = Dz2c_il = 0.0; + ct[icell].Dz2c = ct[icell].Dz2c_dl = Dz2c_il = 0.0; if (il_calcs) { @@ -2364,6 +2511,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) J_ij_il[i].tot1 = 0.0; V_M_il[i].grad = 0.0; V_M_il[i].D = 0.0; + V_M_il[i].z = 0.0; + V_M_il[i].zc = 0.0; V_M_il[i].Dz = 0.0; V_M_il[i].Dzc = 0.0; V_M_il[i].Dzc_dl = 0.0; @@ -2388,74 +2537,72 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is only in icell */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - //J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); J_ij_il[k_il].name = sol_D[icell].spec[i].name; V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; V_M_il[k_il].z = sol_D[icell].spec[i].z; V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * sol_D[icell].spec[i].c * cec12 / (2 * - V_M_il - [k_il]. - z); + dum = sol_D[icell].spec[i].c * cec12 / (2 * V_M_il[k_il].z); + V_M_il[k_il].Dzc = V_M_il[k_il].Dz * dum; Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; V_M_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ k_il++; } else { - //J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); - J_ij[k].name = sol_D[icell].spec[i].name; - V_M[k].D = sol_D[icell].spec[i].Dwt; - V_M[k].z = sol_D[icell].spec[i].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = V_M[k].Dz * sol_D[icell].spec[i].c / 2; - if (dl_s > 0) + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + c1 = sol_D[icell].spec[i].c / 2; + if (dV_dcell) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1 * dV_dcell; + // don't transport unavailable moles against the gradient + if (-dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z > 0) // no transport against the dV_dcell gradient if c = 0 in jcell + c1 = 0; + } + ct[icell].v_m[k].c = c1; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; + if (ct[icell].dl_s > 0) { s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - LDBLE g = s_charge_ptr->Get_g_map()[V_M[k].z].Get_g(); + LDBLE g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { { if (only_counter) { - if ((s_charge_ptr->Get_la_psi() < 0 && V_M[k].z < 0) - || (s_charge_ptr->Get_la_psi() > 0 - && V_M[k].z > 0)) + if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].Dzc_dl = 0; } else /* assume for counter ions in the DDL the free pore space conc's... */ { - V_M[k].g_dl = 1.0; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2; + ct[icell].v_m[k].g_dl = 1.0; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; } } else { if (dl_aq1 > 0) { - V_M[k].g_dl = - (1 + - g * aq1 / dl_aq1) * - sol_D[icell].spec[i].erm_ddl; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / - 2 * V_M[k].g_dl; + ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; + ct[icell].v_m[k].Dzc_dl = + ct[icell].v_m[k].Dz * c1 * ct[icell].v_m[k].g_dl; } else - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[icell].spec[i].c / 2; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; } //break; } } - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; k++; } if (i < i_max) @@ -2469,7 +2616,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is only in jcell */ if (il_calcs && sol_D[jcell].spec[j].type == EX) { - //J_ij_il[k_il].name = string_hsave(sol_D[jcell].spec[j].name); J_ij_il[k_il].name = sol_D[jcell].spec[j].name; V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; V_M_il[k_il].z = sol_D[jcell].spec[j].z; @@ -2485,60 +2631,60 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - //J_ij[k].name = string_hsave(sol_D[jcell].spec[j].name); - J_ij[k].name = sol_D[jcell].spec[j].name; - V_M[k].D = sol_D[jcell].spec[j].Dwt; - V_M[k].z = sol_D[jcell].spec[j].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = V_M[k].Dz * sol_D[jcell].spec[j].c / 2; - if (dl_s > 0) + ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; + ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; + ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + c2 = sol_D[jcell].spec[j].c / 2; + if (dV_dcell) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2 * dV_dcell; + // don't transport unavailable moles against the gradient + if (dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z < 0) // no transport against the dV_dcell gradient if c = 0 in jcell + c2 = 0; + } + ct[icell].v_m[k].c = c2; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; + if (ct[icell].dl_s > 0) { s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - LDBLE g = s_charge_ptr->Get_g_map()[V_M[k].z].Get_g(); + LDBLE g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { { if (only_counter) { - if ((s_charge_ptr->Get_la_psi() < 0 && V_M[k].z < 0) - || (s_charge_ptr->Get_la_psi() > 0 - && V_M[k].z > 0)) + if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].Dzc_dl = 0; } else /* assume for counter ions in the DDL the free pore space conc's... */ { - V_M[k].g_dl = 1.0; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2; + ct[icell].v_m[k].g_dl = 1.0; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; } } else { if (dl_aq2 > 0) { - V_M[k].g_dl = - (1 + - g * aq2 / - dl_aq2) * - sol_D[jcell].spec[j].erm_ddl; - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2 * V_M[k].g_dl; + ct[icell].v_m[k].g_dl = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; + ct[icell].v_m[k].Dzc_dl = + ct[icell].v_m[k].Dz * c2 * ct[icell].v_m[k].g_dl; } else - V_M[k].Dzc_dl = - V_M[k].Dz * sol_D[jcell].spec[j].c / - 2; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; } //break; } } - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; k++; } if (j < j_max) @@ -2550,7 +2696,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* species 'name' is in both cells */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - //J_ij_il[k_il].name = string_hsave(sol_D[icell].spec[i].name); J_ij_il[k_il].name = sol_D[icell].spec[i].name; if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) @@ -2574,118 +2719,111 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - //J_ij[k].name = string_hsave(sol_D[icell].spec[i].name); - J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) - V_M[k].D = 0.0; + ct[icell].v_m[k].D = 0.0; else - V_M[k].D = + ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - V_M[k].z = sol_D[icell].spec[i].z; - V_M[k].Dz = V_M[k].D * V_M[k].z; - V_M[k].Dzc = - V_M[k].Dz * (sol_D[icell].spec[i].c + - sol_D[jcell].spec[j].c) / 2; - /* Dzc[k] = Dz[k] * (sol_D[icell].spec[i].c > sol_D[jcell].spec[j].c ? sol_D[icell].spec[i].c : sol_D[jcell].spec[j].c); - */ - if (dl_s > 0) + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + c1 = sol_D[icell].spec[i].c / 2; + c2 = sol_D[jcell].spec[j].c / 2; + if (dV_dcell) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2) * dV_dcell; + // don't transport unavailable moles against the gradient + if (abs(dum) < abs(dum2) && + ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || + (dum2 <= 0 && sol_D[icell].spec[i].c * aq1 < 1e-12))) + { + c1 = 0; + c2 = 0; + } + } + ct[icell].v_m[k].c = (c1 + c2); + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * (c1 + c2); + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * (c1 + c2); + + if (ct[icell].dl_s > 0) { c_dl = 0.0; if (dl_aq1 > 0) { - LDBLE g = s_charge_ptr1->Get_g_map()[V_M[k].z].Get_g(); + LDBLE g = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { { if (only_counter) { - if ((s_charge_ptr1->Get_la_psi() < 0 - && V_M[k].z < 0) - || (s_charge_ptr1->Get_la_psi() > 0 - && V_M[k].z > 0)) + if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].Dzc_dl = 0; } else /* assume for counter ions in the DDL the free pore space conc's... */ { - V_M[k].g_dl = 1.0; - c_dl = sol_D[icell].spec[i].c / 2; + ct[icell].v_m[k].g_dl = 1.0; + c_dl = c1; } } else { - V_M[k].g_dl = - (1 + - g * aq1 / - dl_aq1) * - sol_D[icell].spec[i].erm_ddl; - c_dl = - sol_D[icell].spec[i].c / 2 * - V_M[k].g_dl; + ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; + c_dl = c1 * ct[icell].v_m[k].g_dl; } //break; } } } else - c_dl = sol_D[icell].spec[i].c / 2; + c_dl = c1; if (dl_aq2 > 0) { - LDBLE g = s_charge_ptr2->Get_g_map()[V_M[k].z].Get_g(); + LDBLE g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { { if (only_counter) { - if ((s_charge_ptr2->Get_la_psi() < 0 - && V_M[k].z < 0) - || (s_charge_ptr2->Get_la_psi() > 0 - && V_M[k].z > 0)) + if (s_charge_ptr2->Get_la_psi() * ct[icell].v_m[k].z > 0) { - V_M[k].o_c = 0; - V_M[k].Dzc_dl = 0; + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].Dzc_dl = 0; } else /* assume for counter ions in the DDL the free pore space conc's... */ { dum = 1.0; - c_dl += - sol_D[jcell].spec[j].c / 2 * dum; - V_M[k].g_dl = - (V_M[k].g_dl + dum) / 2; + c_dl += c2 * dum; + ct[icell].v_m[k].g_dl = + (ct[icell].v_m[k].g_dl + dum) / 2; } } else { - dum = - (1 + - g * aq2 / - dl_aq2) * - sol_D[jcell].spec[j].erm_ddl; - c_dl += sol_D[jcell].spec[j].c / 2 * dum; - V_M[k].g_dl = (V_M[k].g_dl + dum) / 2; + dum = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; + c_dl += c2 * dum; + ct[icell].v_m[k].g_dl = (ct[icell].v_m[k].g_dl + dum) / 2; } //break; } } } - else if (V_M[k].o_c == 1) - c_dl += sol_D[jcell].spec[j].c / 2; + else if (ct[icell].v_m[k].o_c == 1) + c_dl += c2; - V_M[k].Dzc_dl = V_M[k].Dz * c_dl; - Dz2c_dl += V_M[k].Dzc_dl * V_M[k].z; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c_dl; + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; } - Dz2c += V_M[k].Dzc * V_M[k].z; - V_M[k].grad = - (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; if (fabs(ddlm) > 1e-10) - V_M[k].grad *= - (1 + - (sol_D[jcell].spec[j].lg - - sol_D[icell].spec[i].lg) / ddlm); + ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); k++; } if (i < i_max) @@ -2697,29 +2835,117 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* * fill in J_ij... */ - if (Dz2c == 0) + if (ct[icell].Dz2c == 0) k = 0; - J_ij_count_spec = i_max = k; - J_ij_sum = 0; + ct[icell].J_ij_count_spec = i_max = k; + + // dV_dcell, 2nd pass, current_x has been calculated, but needs + // V_M, dl_s, A_ij, Dz2c, Dz2c_dl, J_ij_count_spec, visc1, visc2... +dV_dcell2 : + + ct[icell].J_ij_sum = 0; c = c_dl = 0.0; - for (i = 0; i < i_max; i++) + LDBLE D_harm = 0, zspec = 0; + if (dV_dcell) { - c += V_M[i].Dz * V_M[i].grad; - c_dl += V_M[i].o_c * V_M[i].Dz * V_M[i].g_dl * V_M[i].grad; + //current_cells[icell].dif = 0; // including dif in dV gives higher percent error + current_cells[icell].ele = 0; } - for (i = 0; i < i_max; i++) + + for (i = 0; i < ct[icell].J_ij_count_spec; i++) { - J_ij[i].tot1 = -V_M[i].D * V_M[i].grad + c * V_M[i].Dzc / Dz2c; - J_ij[i].tot1 *= (1 - dl_s); - if (Dz2c_dl > 0) + ct[icell].J_ij[i].tot1 = 0; + if (!ct[icell].v_m[i].c) + continue; + c += ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; + c_dl += ct[icell].v_m[i].o_c * ct[icell].v_m[i].Dz * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; + + if (dV_dcell) { - dum = - (-V_M[i].D * V_M[i].g_dl * V_M[i].grad + - c_dl * V_M[i].Dzc_dl / Dz2c_dl) * (2 / (visc1 + visc2)); - if ((J_ij[i].tot1 <= 0 && dum <= 0) - || (J_ij[i].tot1 > 0 && dum > 0)) + if (!ct[icell].v_m[i].z) + continue; + zspec += abs(ct[icell].v_m[i].zc); + D_harm += 1e-9 * abs(ct[icell].v_m[i].zc) / ct[icell].v_m[i].D; + } + } + if (D_harm) + D_harm = zspec * 1e-9 / D_harm; + + if (dV_dcell && !find_current) // correct dV to get equal current for all cells... + { + dV = cell_data[jcell].potV - cell_data[icell].potV; + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (!ct[icell].v_m[i].c || !ct[icell].v_m[i].z) + continue; + //current_cells[icell].dif -= ct[icell].v_m[i].z * D_harm * ct[icell].v_m[i].grad * + // (1 - ct[icell].dl_s); + current_cells[icell].ele -= ct[icell].v_m[i].z * ct[icell].v_m[i].zc * D_harm * dV * + F_Re3 / tk_x2 * (1 - ct[icell].dl_s); + if (ct[icell].dl_s > 0) { - J_ij[i].tot1 += V_M[i].o_c * dum * dl_s; + // assume D_harm_dl equal to D_harm + dum = -D_harm * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; + dum2 = ct[icell].v_m[i].z * ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * D_harm * + dV * F_Re3 / tk_x2; + //current_cells[icell].dif += ct[icell].v_m[i].z * ct[icell].v_m[i].o_c * dum * 2 / + // (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + current_cells[icell].ele -= ct[icell].v_m[i].o_c * dum2 * 2 / + (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + } + } + //current_cells[icell].ele += current_cells[icell].dif; + dV *= current_x / (current_cells[icell].ele * ct[icell].A_ij * DDt); + } + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (!ct[icell].v_m[i].c) + continue; + ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + if (ct[icell].v_m[i].z && ct[icell].Dz2c > 0) + ct[icell].J_ij[i].tot1 += c * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; + ct[icell].J_ij[i].tot1 *= (1 - ct[icell].dl_s); + if (ct[icell].dl_s > 0) + { + dum = -ct[icell].v_m[i].D * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; + if (ct[icell].Dz2c_dl > 0) + dum2 = c_dl * ct[icell].v_m[i].Dzc_dl / ct[icell].Dz2c_dl; + else + dum2 = 0; + if ((ct[icell].J_ij[i].tot1 <= 0 && dum <= 0) + || (ct[icell].J_ij[i].tot1 > 0 && dum > 0)) + { + ct[icell].J_ij[i].tot1 += ct[icell].v_m[i].o_c * (dum + dum2) * 2 / + (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + } + } + if (ct[icell].v_m[i].z) + { + if (find_current) + { + //current_cells[icell].dif -= ct[icell].v_m[i].z * D_harm * + // ct[icell].v_m[i].grad * (1 - ct[icell].dl_s); + current_cells[icell].ele -= ct[icell].v_m[i].z * ct[icell].v_m[i].zc * D_harm * + dV_dcell * F_Re3 / tk_x2 * (1 - ct[icell].dl_s); + if (ct[icell].dl_s > 0) + { + // assume D_harm_dl equal to D_harm + dum2 = ct[icell].v_m[i].z * ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * D_harm * + dV_dcell * F_Re3 / tk_x2; + //current_cells[icell].dif += ct[icell].v_m[i].z * ct[icell].v_m[i].o_c * dum * 2 / + // (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + current_cells[icell].ele -= ct[icell].v_m[i].o_c * dum2 * 2 / + (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + } + } + else if (dV_dcell) + { + dum = D_harm * dV * F_Re3 / tk_x2; + ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].zc * dum * (1 - ct[icell].dl_s); + + dum2 = ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * dum; + ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].o_c * dum2 * 2 / + (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; } } /* @@ -2731,18 +2957,32 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) * Dw used for calculating mixf must be given as default_Dw in the input file. */ if (stagnant) - J_ij[i].tot1 *= mixf; + ct[icell].J_ij[i].tot1 *= mixf; else - J_ij[i].tot1 *= A_ij * DDt; - J_ij_sum += V_M[i].z * J_ij[i].tot1; - J_ij[i].tot2 = J_ij[i].tot1; + ct[icell].J_ij[i].tot1 *= ct[icell].A_ij * DDt; + ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; + ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; } + if (find_current) + { + //current_cells[icell].dif *= ct[icell].A_ij * DDt; + current_cells[icell].ele *= ct[icell].A_ij * DDt; + //current_cells[icell].ele += current_cells[icell].dif; + current_cells[icell].R = current_cells[0].ele / current_cells[icell].ele; + sum_R += current_cells[icell].R; + return(il_calcs); + } + if (dV_dcell) + { + current_A = current_x * F_C_MOL / DDt; + } + /* * calculate interlayer mass transfer... */ if (il_calcs && Dz2c_il != 0 && k_il > 0) { - + cxxExchange *ex_ptr1 = Utilities::Rxn_find(Rxn_exchange_map, icell); cxxExchange *ex_ptr2 = Utilities::Rxn_find(Rxn_exchange_map, jcell); c = 0.0; @@ -2757,7 +2997,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) J_ij_il[i].tot1 *= mixf_il; else J_ij_il[i].tot1 *= A_ij_il * DDt; - J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; + ct[icell].J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; J_ij_il[i].tot2 = J_ij_il[i].tot1; } @@ -2787,7 +3027,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cxxNameDouble::iterator it = nd.begin(); i_max = 0; for (; it != nd.end(); it++) - { + { if (strcmp("X", it->first.c_str()) == 0) i_max = 1; } @@ -2802,7 +3042,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cxxNameDouble::iterator it = nd.begin(); /* transfer O and H... */ for (; it != nd.end(); it++) - { + { struct element *elt_ptr = element_store(it->first.c_str()); LDBLE coef = it->second; if (strcmp("H", elt_ptr->name) == 0) @@ -2873,7 +3113,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cxxNameDouble::iterator it = nd.begin(); i_max = 0; for (; it != nd.end(); it++) - { + { if (strcmp("X", it->first.c_str()) == 0) i_max = 1; } @@ -2949,9 +3189,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } } - /* appt 3 July 07, improved convergence without transporting charge imbalance */ - J_ij_sum = 0; - V_M = (struct V_M *) free_check_null(V_M); + /* do not transport charge imbalance */ + //ct[icell].J_ij_sum = 0; + //V_M = (struct V_M *) free_check_null(V_M); if (il_calcs) V_M_il = (struct V_M *) free_check_null(V_M_il); return (il_calcs); @@ -2977,7 +3217,7 @@ disp_surf(LDBLE DDt) * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. */ { - int i, i1, i2, k, k1; + int i, i1, i2, k, k1, n1, n2; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store, mcd_mixf; LDBLE lav, A_ij, por, Dp1, Dp2; @@ -2987,9 +3227,11 @@ disp_surf(LDBLE DDt) /* * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) */ - viscos_f = viscosity(); - viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); + viscos_f = viscos_0; + viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); + n1 = 0; + n2 = n1 + 1; cxxSurface surface_n1, surface_n2; cxxSurface *surface_n2_ptr; @@ -2997,7 +3239,7 @@ disp_surf(LDBLE DDt) for (i1 = 1; i1 <= count_cells + 1; i1++) { - if (i1 <= count_cells && cell_data[i1 - 1].por < multi_Dpor_lim) + if (i1 <= count_cells && cell_data[i1].por < multi_Dpor_lim) continue; if (i1 == 1 && bcon_first != 1) @@ -3006,7 +3248,7 @@ disp_surf(LDBLE DDt) continue; i2 = i1 - 1; - if (i2 > 0 && cell_data[i2 - 1].por < multi_Dpor_lim) + if (i2 > 0 && cell_data[i2].por < multi_Dpor_lim) continue; /* * step 1. define surface n1 from cell i1, if it exists... @@ -3072,7 +3314,7 @@ disp_surf(LDBLE DDt) if (surface_n1.Get_surface_charges().size() > 1) { std::string charge_name = surface_n1.Get_surface_charges()[0].Get_name(); - surface_n1 = sum_surface_comp(&surface_n1, 0, + surface_n1 = sum_surface_comp(&surface_n1, 0, &surface_n1, charge_name, 1, surface_n1.Get_surface_comps()[0].Get_Dw()); } f1 = 0; @@ -3119,36 +3361,33 @@ disp_surf(LDBLE DDt) */ if (i1 == 1) { - por = cell_data[0].por; - lav = cell_data[0].length / 2; - A_ij = Utilities::Rxn_find(Rxn_solution_map, 1)->Get_mass_water() / cell_data[0].length; + por = cell_data[1].por; + lav = cell_data[1].length / 2; + A_ij = Utilities::Rxn_find(Rxn_solution_map, 1)->Get_mass_water() / cell_data[1].length; } else if (i1 == count_cells + 1) { - por = cell_data[count_cells - 1].por; - lav = cell_data[count_cells - 1].length / 2; + por = cell_data[count_cells].por; + lav = cell_data[count_cells].length / 2; A_ij = Utilities::Rxn_find(Rxn_solution_map, count_cells)->Get_mass_water() / - cell_data[count_cells - 1].length; + cell_data[count_cells].length; } else { - por = cell_data[i2 - 1].por; + por = cell_data[i2].por; lav = - (cell_data[i1 - 1].length + cell_data[i2 - 1].length) / 2; + (cell_data[i1].length + cell_data[i2].length) / 2; A_ij = - Utilities::Rxn_find(Rxn_solution_map, i1)->Get_mass_water() / - (cell_data[i1 - 1].length * cell_data[i1 - 1].por); + Utilities::Rxn_find(Rxn_solution_map, i1)->Get_mass_water() / + (cell_data[i1].length * cell_data[i1].por); A_ij += - Utilities::Rxn_find(Rxn_solution_map, i2)->Get_mass_water() / - (cell_data[i2 - 1].length * cell_data[i2 - 1].por); + Utilities::Rxn_find(Rxn_solution_map, i2)->Get_mass_water() / + (cell_data[i2].length * cell_data[i2].por); A_ij /= 2; A_ij *= - (cell_data[i1 - 1].por < - cell_data[i2 - 1].por ? cell_data[i1 - - 1].por : cell_data[i2 - - 1]. - por); + (cell_data[i1].por < + cell_data[i2].por ? cell_data[i1].por : cell_data[i2].por); } /* mix in comps with the same charge structure... */ @@ -3160,7 +3399,7 @@ disp_surf(LDBLE DDt) std::string charge_name = comp_k_ptr->Get_charge_name(); if (comp_k_ptr->Get_Dw() == 0) continue; - + charge_done = FALSE; for (k1 = 0; k1 < k; k1++) { @@ -3191,7 +3430,7 @@ disp_surf(LDBLE DDt) continue; Dp1 = comp_k1_ptr->Get_Dw() * - pow(cell_data[i1 - 1].por, multi_Dn); + pow(cell_data[i1].por, multi_Dn); break; } } @@ -3252,7 +3491,7 @@ disp_surf(LDBLE DDt) { Dp1 = comp_k_ptr->Get_Dw() * - pow(cell_data[i1 - 1].por, multi_Dn); + pow(cell_data[i1].por, multi_Dn); } else { @@ -3329,6 +3568,7 @@ disp_surf(LDBLE DDt) /* * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... */ + n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for ( ; jit != Rxn_temp_surface_map.end(); jit++) { @@ -3585,7 +3825,7 @@ mobile_surface_copy(cxxSurface *surface_old_ptr, // Return value is temp_surface temp_surface.Set_n_user_both(n_user_new); } - + /* delete moved parts from old surface */ if (move_old && i1 > 0) { @@ -3648,7 +3888,7 @@ diff_stag_surf(int mobile_cell) * for any cell in MCD, need only include the mixing factors for higher numbered cells. */ { - int i, i1, i2, k, k1, ns; + int i, i1, i2, k, k1, n1, n2, ns; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store; LDBLE Dp1, Dp2; @@ -3658,8 +3898,8 @@ diff_stag_surf(int mobile_cell) /* * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) */ - viscos_f = viscosity(); - viscos_f = tk_x * 0.88862 / (298.15 * viscos_f); + viscos_f = viscos_0; + viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); cxxSurface surface_n1, surface_n2; cxxSurface *surface_n1_ptr = &surface_n1; @@ -3673,7 +3913,7 @@ diff_stag_surf(int mobile_cell) if (ns == 0) i1--; - if (cell_data[i1 - 1].por < multi_Dpor_lim) + if (cell_data[i1].por < multi_Dpor_lim) continue; surface_n1.Set_n_user_both(-99); surface_n2.Set_n_user_both(-99); @@ -3692,7 +3932,7 @@ diff_stag_surf(int mobile_cell) { if ((i2 = num[i3]) <= i1) continue; - if (cell_data[i2 - 1].por < multi_Dpor_lim) + if (cell_data[i2].por < multi_Dpor_lim) continue; surface_ptr2 = Utilities::Rxn_find(Rxn_surface_map, i2); surf1 = surf2 = 0; @@ -3716,6 +3956,7 @@ diff_stag_surf(int mobile_cell) if (surface_n1_ptr != NULL) { surface_n1 = *surface_n1_ptr; + n1 = 0; } /* if not found... */ else @@ -3751,6 +3992,7 @@ diff_stag_surf(int mobile_cell) /* if not found... */ else { + n2 = 1; /* copy it from surface_ptr2... */ if (surface_ptr2 != NULL) { @@ -3775,10 +4017,8 @@ diff_stag_surf(int mobile_cell) if (multi_Dflag) { mixf_store *= - (cell_data[i1 - 1].por <= - cell_data[i2 - 1].por ? cell_data[i1 - - 1].por : cell_data[i2 - - 1]. + (cell_data[i1].por <= + cell_data[i2].por ? cell_data[i1].por : cell_data[i2]. por); mixf_store /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); @@ -3811,7 +4051,7 @@ diff_stag_surf(int mobile_cell) if (multi_Dflag) { Dp2 = comp_k_ptr->Get_Dw() * - pow(cell_data[i2 - 1].por, multi_Dn) * viscos_f; + pow(cell_data[i2].por, multi_Dn) * viscos_f; Dp1 = 0; if (surf1) { @@ -3823,7 +4063,7 @@ diff_stag_surf(int mobile_cell) continue; Dp1 = comp_k1_ptr->Get_Dw() * - pow(cell_data[i1 - 1].por, + pow(cell_data[i1].por, multi_Dn) * viscos_f; break; } @@ -3876,7 +4116,7 @@ diff_stag_surf(int mobile_cell) { Dp1 = comp_k_ptr->Get_Dw() * - pow(cell_data[i1 - 1].por, multi_Dn) * viscos_f; + pow(cell_data[i1].por, multi_Dn) * viscos_f; Dp2 = 0; if (surf2) @@ -3889,7 +4129,7 @@ diff_stag_surf(int mobile_cell) continue; Dp2 = comp_k1_ptr->Get_Dw() * - pow(cell_data[i2 - 1].por, + pow(cell_data[i2].por, multi_Dn) * viscos_f; break; } @@ -3933,6 +4173,7 @@ diff_stag_surf(int mobile_cell) /* * Step 4. Diffusion is done. New surfaces can be copied in the cells... */ + n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for ( ; jit != Rxn_temp_surface_map.end(); jit++) { @@ -4050,11 +4291,116 @@ LDBLE Phreeqc:: viscosity(void) /* ---------------------------------------------------------------------- */ { - LDBLE viscos; + /* from Atkins, 1994. Physical Chemistry, 5th ed. */ - viscos = - pow((LDBLE) 10., - -(1.37023 * (tc_x - 20) + - 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); - return viscos; + //viscos = + // pow((LDBLE) 10., + // -(1.37023 * (tc_x - 20) + + // 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); +/* Huber et al., 2009, J. Phys. Chem. Ref. Data, Vol. 38, 101-125 */ + LDBLE H[4] = { 1.67752, 2.20462, 0.6366564, -0.241605 }; + LDBLE Tb = tk_x / 647.096, denom = H[0], mu0; + int i, j, i1; + for (i = 1; i < 4; i++) + denom += H[i] / pow(Tb, i); + mu0 = 100.0 * sqrt(Tb) / denom; + + LDBLE H2[42] = + { 5.20094e-1, 2.22531e-1, -2.81378e-1, 1.61913e-1, -3.25372e-2, 0, 0, + 8.50895e-2, 9.99115e-1, -9.06851e-1, 2.57399e-1, 0, 0, 0, + -1.08374, 1.88797, -7.72479e-1, 0, 0, 0, 0, + -2.89555e-1, 1.26613, -4.89837e-1, 0, 6.98452e-2, 0, -4.35673e-3, + 0, 0, -2.57040e-1, 0, 0, 8.72102e-3, 0, + 0, 1.20573e-1, 0, 0, 0, 0, -5.93264e-4 }; + LDBLE Rb = rho_0 / 0.322, Tb_1, Rb_1, S1 = 0.0, S2, mu1; + Tb_1 = 1.0 / Tb - 1.0; Rb_1 = Rb - 1.0; + for (i = 0; i < 6; i++) + { + S2 = 0.0; + for (j = 0; j < 7; j++) + { + i1 = 7 * i; + if (!H2[i1 + j]) + continue; + if (j) + S2 += H2[i1 + j] * pow(Rb_1, j); + else + S2 += H2[i1]; + } + if (i) + S1 += S2 * pow(Tb_1, i); + else + S1 += S2; + } + mu1 = exp(Rb * S1); + viscos_0 = viscos = mu0 * mu1 / 1e3; + viscos_0_25 = 0.8900239182946; + return viscos; +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_vm_Cl(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Calculate molar volume of Cl- with a Redlich type eqn: + Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I^(b4). + * Vm0(tc) is calc'd using supcrt parms, or from millero[0] + millero[1] * tc + millero[2] * tc^2 + * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. + Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av. + If b_Av != 0, the extended DH formula is used: I^0.5 /(1 + b_Av * DH_B * I^0.5). + DH_Av and DH_B are from calc_dielectrics(tc, pa). + * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228) + logk[vmi3] * (TK - 228). + * b4 = logk[vmi4], or + * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 + */ + LDBLE V_Cl = 0; + LDBLE pb_s = 2600. + patm_x * 1.01325, TK_s = tc_x + 45.15, sqrt_mu = sqrt(mu_x); + struct species *s_ptr; + + s_ptr = s_search("Cl-"); + if (!s_ptr) + return V_Cl; + + if (s_ptr->logk[vma1]) + { + /* supcrt volume at I = 0... */ + V_Cl = s_ptr->logk[vma1] + s_ptr->logk[vma2] / pb_s + + (s_ptr->logk[vma3] + s_ptr->logk[vma4] / pb_s) / TK_s - + s_ptr->logk[wref] * QBrn; + /* the ionic strength term * I^0.5... */ + if (s_ptr->logk[b_Av] < 1e-5) + V_Cl += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt_mu; + else + { + /* limit the Debye-Hueckel slope by b... */ + /* pitzer... */ + //s_ptr->rxn_x->logk[vm_tc] += s_ptr->z * s_ptr->z * 0.5 * DH_Av * + // log(1 + s_ptr->logk[b_Av] * sqrt(mu_x)) / s_ptr->logk[b_Av]; + /* extended DH... */ + V_Cl += s_ptr->z * s_ptr->z * 0.5 * DH_Av * + sqrt_mu / (1 + s_ptr->logk[b_Av] * DH_B * sqrt_mu); + } + /* plus the volume terms * I... */ + if (s_ptr->logk[vmi1] != 0.0 || s_ptr->logk[vmi2] != 0.0 || s_ptr->logk[vmi3] != 0.0) + { + LDBLE bi = s_ptr->logk[vmi1] + s_ptr->logk[vmi2] / TK_s + s_ptr->logk[vmi3] * TK_s; + if (s_ptr->logk[vmi4] == 1.0) + V_Cl += bi * mu_x; + else + V_Cl += bi * pow(mu_x, s_ptr->logk[vmi4]); + } + } + else if (s_ptr->millero[0]) + { + /* Millero volume at I = 0... */ + V_Cl = s_ptr->millero[0] + tc_x * (s_ptr->millero[1] + tc_x * s_ptr->millero[2]); + if (s_ptr->z) + { + /* the ionic strength terms... */ + V_Cl += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt_mu + + (s_ptr->millero[3] + tc_x * (s_ptr->millero[4] + tc_x * s_ptr->millero[5])) * mu_x; + } + } + return V_Cl; } From c15e56ad5b4aeda07a1f789ab7cb8944d5a58c73 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Dec 2015 20:09:32 +0000 Subject: [PATCH 0945/1077] -potential not defined for solution read_raw. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10567 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Solution.cxx b/Solution.cxx index f4d4405d..0eeeaaae 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1566,6 +1566,7 @@ const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pressure"), // 22 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("log_gamma_map"), // 25 + std::vector< std::string >::value_type("potential") // 26 }; const std::vector< std::string > cxxSolution::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]); \ No newline at end of file From 301d2d009c1b035249308fa05f62bd20bd6eac49 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Dec 2015 20:35:26 +0000 Subject: [PATCH 0946/1077] transport.cpp, ifdefd old viscosity, initialized variables; basicsubs call viscosity();phreeqc, revert ineq_tol git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10569 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 6 +++--- basicsubs.cpp | 2 +- transport.cpp | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 24e5bbc1..14096e91 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -715,9 +715,9 @@ void Phreeqc::init(void) /* from float.h, sets tolerance for cl1 routine */ ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); #else - //ineq_tol = pow((double) 10, (double) -DBL_DIG); + ineq_tol = pow((double) 10, (double) -DBL_DIG); // appt: - ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); + //ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); #endif convergence_tolerance = 1e-8; step_size = 100.; @@ -2529,4 +2529,4 @@ int Phreeqc::next_user_number(Keywords::KEYWORDS key) assert(false); return -999; } -} \ No newline at end of file +} diff --git a/basicsubs.cpp b/basicsubs.cpp index 4d803dfd..c8f729eb 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -218,7 +218,6 @@ calc_SC(void) SC_T = SC_298 * (viscos_298 / viscos_T) */ SC *= viscos_0_25 / viscos; - return (SC); # endif for (i = 0; i < count_s_x; i++) @@ -249,6 +248,7 @@ calc_SC(void) Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: SC_T = SC_298 * (viscos_298 / viscos_T) */ + viscosity(); SC *= viscos_0_25 / viscos; return (SC); diff --git a/transport.cpp b/transport.cpp index fa12f822..01c2e53b 100644 --- a/transport.cpp +++ b/transport.cpp @@ -896,7 +896,7 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD, dx = 0; + LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; //, dx = 0; int i, l_nmix; //std::vector m, m1; @@ -1792,6 +1792,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) char token[MAX_LENGTH]; LDBLE mixf, temp; + first_c = last_c = -1; current_x = sum_R = 0.0; if (dV_dcell) find_current = loop_f_c = 1; // calculate J_ij once for all cells, find smallest j_x, next with this j_x. @@ -2141,6 +2142,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; char token[MAX_LENGTH], token1[MAX_LENGTH]; + k_il = 0; + A_ij_il = mixf_il = 0.0; + Dz2c_il = 0.0; + cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; + V_M_il = NULL; + dV = 0.0; + /* check for immediate return and interlayer diffusion calcs... */ if (interlayer_Dflag) { @@ -4335,6 +4343,18 @@ viscosity(void) mu1 = exp(Rb * S1); viscos_0 = viscos = mu0 * mu1 / 1e3; viscos_0_25 = 0.8900239182946; + + //#define OLD_VISCOSITY +#ifdef OLD_VISCOSITY + viscos = + pow((LDBLE) 10., + -(1.37023 * (tc_x - 20) + + 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); +/* Huber et al., 2009, J. Phys. Chem. Ref. Data, Vol. 38, 101-125 */ + viscos_0 = viscos; + viscos_0_25 = 0.88862; +#endif + return viscos; } /* ---------------------------------------------------------------------- */ From 0970c44067a2f84d0b16bbfb3f11cadf0fc6e8ac Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 14 Dec 2015 21:18:25 +0000 Subject: [PATCH 0947/1077] using old viscosity git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10570 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport.cpp b/transport.cpp index 01c2e53b..e2c254ef 100644 --- a/transport.cpp +++ b/transport.cpp @@ -4344,7 +4344,7 @@ viscosity(void) viscos_0 = viscos = mu0 * mu1 / 1e3; viscos_0_25 = 0.8900239182946; - //#define OLD_VISCOSITY +#define OLD_VISCOSITY #ifdef OLD_VISCOSITY viscos = pow((LDBLE) 10., From ca4c8f9e550d383809fb66b1034556fa8e3adbee Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 15 Dec 2015 19:42:49 +0000 Subject: [PATCH 0948/1077] delay removing phases in ineq, should be unchanged until delay is > 0 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10575 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 1 + model.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/global_structures.h b/global_structures.h index e05e59fb..c7fc48a7 100644 --- a/global_structures.h +++ b/global_structures.h @@ -833,6 +833,7 @@ struct unknown LDBLE V_m; LDBLE pressure; int mb_number; + int iteration; }; /*---------------------------------------------------------------------- diff --git a/model.cpp b/model.cpp index df2ca4de..438db0a2 100644 --- a/model.cpp +++ b/model.cpp @@ -1125,15 +1125,20 @@ ineq(int in_kode) /* not in model, ignore */ if (x[i]->phase->in == FALSE) continue; + // delay removing phase + int delay = 0; + if (x[i]->moles > 0.0 || x[i]->f <= 0.0 || iterations == 0 || delay == 0) + { + x[i]->iteration = iterations; + } cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; //if (it->second.Get_force_equality()) if (comp_ptr->Get_force_equality()) continue; /* Undersaturated and no mass, ignore */ - //if (x[i]->f > 1e-14/*0e-8*/ && x[i]->moles <= 0 if (x[i]->f > 0e-8 && x[i]->moles <= 0 - //&& it->second.Get_add_formula().size() == 0) - && comp_ptr->Get_add_formula().size() == 0) + && iterations >= x[i]->iteration + delay + && comp_ptr->Get_add_formula().size() == 0) { continue; } From 547698218690bc8da4749d7a1d3a77de4a9eaa18 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 16 Dec 2015 00:53:27 +0000 Subject: [PATCH 0949/1077] roughed in equi_delay git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10582 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 1 + kinetics.cpp | 10 ++++++++++ model.cpp | 5 ++--- read.cpp | 12 ++++++++---- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 4ddbf9d9..cbe54eb1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -725,6 +725,7 @@ void Phreeqc::init(void) diagonal_scale = FALSE; mass_water_switch = FALSE; delay_mass_water = FALSE; + equi_delay = 0; dampen_ah2o = false; censor = 0.0; aqueous_only = 0; @@ -1909,6 +1910,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) diagonal_scale = pSrc->diagonal_scale; mass_water_switch = pSrc->mass_water_switch; delay_mass_water = pSrc->delay_mass_water; + equi_delay = pSrc->equi_delay; dampen_ah2o = pSrc->dampen_ah2o; censor = pSrc->censor; aqueous_only = pSrc->aqueous_only; diff --git a/Phreeqc.h b/Phreeqc.h index 500deafb..3ad3391f 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1627,6 +1627,7 @@ protected: int diagonal_scale; /* 0 not used, 1 used */ int mass_water_switch; int delay_mass_water; + int equi_delay; bool dampen_ah2o; LDBLE censor; int aqueous_only; diff --git a/kinetics.cpp b/kinetics.cpp index 8830f696..549b033b 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1265,6 +1265,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, old_pe = pe_step_size; old_min_value = min_value; old_pp_column_scale = pp_column_scale; + int old_equi_delay = equi_delay; if (state == TRANSPORT || state == PHAST) { @@ -1338,6 +1339,14 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } else if (j == 4) { + if (equi_delay > 0) + { + equi_delay = 0; + } + else + { + equi_delay = 1; + } always_full_pitzer = TRUE; itmax *= 2; if (diagonal_scale == TRUE) @@ -1468,6 +1477,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, pe_step_size = old_pe; min_value = old_min_value; pp_column_scale = old_pp_column_scale; + equi_delay = old_equi_delay; aqueous_only = 0; negative_concentrations = FALSE; always_full_pitzer = FALSE; diff --git a/model.cpp b/model.cpp index 438db0a2..74b74579 100644 --- a/model.cpp +++ b/model.cpp @@ -1126,8 +1126,7 @@ ineq(int in_kode) if (x[i]->phase->in == FALSE) continue; // delay removing phase - int delay = 0; - if (x[i]->moles > 0.0 || x[i]->f <= 0.0 || iterations == 0 || delay == 0) + if (x[i]->moles > 0.0 || x[i]->f <= 0.0 || iterations == 0 || equi_delay == 0) { x[i]->iteration = iterations; } @@ -1137,7 +1136,7 @@ ineq(int in_kode) continue; /* Undersaturated and no mass, ignore */ if (x[i]->f > 0e-8 && x[i]->moles <= 0 - && iterations >= x[i]->iteration + delay + && iterations >= x[i]->iteration + equi_delay && comp_ptr->Get_add_formula().size() == 0) { continue; diff --git a/read.cpp b/read.cpp index 4b2ff3a2..77a3435b 100644 --- a/read.cpp +++ b/read.cpp @@ -8255,11 +8255,12 @@ read_debug(void) "convergence_tolerance", /* 14 */ "numerical_derivatives", /* 15 */ "tries", /* 16 */ - "try", /* 17 */ - "numerical_fixed_volume", /* 18 */ - "force_numerical_fixed_volume" /* 19 */ + "try", /* 17 */ + "numerical_fixed_volume", /* 18 */ + "force_numerical_fixed_volume", /* 19 */ + "equi_delay" /* 20 */ }; - int count_opt_list = 20; + int count_opt_list = 21; /* * Read parameters: * ineq_tol; @@ -8352,6 +8353,9 @@ read_debug(void) case 19: /* debug_inverse */ force_numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); break; + case 20: /* equi_delay */ + sscanf(next_char, "%d", &equi_delay); + break; } if (return_value == EOF || return_value == KEYWORD) break; From c6f09779a8bd00400272f013675ef3ee325df568 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 16 Dec 2015 18:01:29 +0000 Subject: [PATCH 0950/1077] added equi_delay to the convergence sets git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10585 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/kinetics.cpp b/kinetics.cpp index 549b033b..e2409cbc 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1302,7 +1302,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } else { - max_try = 13; + max_try = 14; } max_try = (max_tries < max_try) ? max_tries : max_try; /*max_try = 1; */ @@ -1339,14 +1339,6 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } else if (j == 4) { - if (equi_delay > 0) - { - equi_delay = 0; - } - else - { - equi_delay = 1; - } always_full_pitzer = TRUE; itmax *= 2; if (diagonal_scale == TRUE) @@ -1406,6 +1398,22 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, warning_msg(error_string); } else if (j == 8) + { + if (use.Get_pp_assemblage_ptr() == NULL) continue; + if (equi_delay > 0) + { + equi_delay = 0; + } + else + { + equi_delay = 1; + } + error_string = sformatf( "Trying delay removal of equilibrium phases %g ...\n", + (double) equi_delay); + warning_msg(error_string); + } + + else if (j == 9) { if (pitzer_model == TRUE || sit_model == TRUE) continue; itmax *= 2; @@ -1414,7 +1422,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, (double) min_value); warning_msg(error_string); } - else if (j == 9) + else if (j == 10) { if (pitzer_model == TRUE || sit_model == TRUE) continue; aqueous_only = 5; @@ -1423,7 +1431,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, aqueous_only); warning_msg(error_string); } - else if (j == 10) + else if (j == 11) { if (pitzer_model == TRUE || sit_model == TRUE) continue; negative_concentrations = TRUE; @@ -1431,7 +1439,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, "Adding inequality to make concentrations greater than zero.\n"); warning_msg(error_string); } - else if (j == 11) + else if (j == 12) { itmax *= 2; ineq_tol /= 100.; @@ -1439,7 +1447,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, (double) ineq_tol); warning_msg(error_string); } - else if (j == 12) + else if (j == 13) { itmax *= 2; ineq_tol /= 1000.; From 4dc54757e615c6f454fd1a32d04c91d54308abc4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 28 Dec 2015 22:12:48 +0000 Subject: [PATCH 0951/1077] Bug showed up in PHAST. Errors in definition of surface related to mineral or kinetics were not detected. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10606 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/prep.cpp b/prep.cpp index a15d4208..bca3f6ce 100644 --- a/prep.cpp +++ b/prep.cpp @@ -9,6 +9,7 @@ #include "SSassemblage.h" #include "SS.h" #include "Solution.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: prep(void) @@ -3655,6 +3656,23 @@ setup_surface(void) */ if (use.Get_surface_ptr()->Get_related_phases()) { + cxxPPassemblage *pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_surface_user()); + for (size_t i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) + { + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name().size() > 0) + { + if (pp_ptr == NULL || + (pp_ptr->Get_pp_assemblage_comps().find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name()) == + pp_ptr->Get_pp_assemblage_comps().end())) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); + this->tidy_min_surface(); + return (FALSE); + } + } + } for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) @@ -3702,7 +3720,21 @@ setup_surface(void) * check related kinetics */ if (use.Get_surface_ptr()->Get_related_rate()) - { + { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); + for (size_t i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) + { + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) + { + if (kinetics_ptr == NULL || + (kinetics_ptr->Find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name()) == NULL)) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + this->tidy_kin_surface(); + return (FALSE); + } + } + } for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) @@ -6099,6 +6131,30 @@ check_same_model(void) if (last_model.surface_comp[i] != string_hsave(use.Get_surface_ptr()->Get_surface_comps()[i].Get_formula().c_str())) return (FALSE); + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name().size() > 0) + { + cxxPPassemblage *pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_surface_user()); + if (pp_ptr == NULL || (pp_ptr->Get_pp_assemblage_comps().find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name()) == + pp_ptr->Get_pp_assemblage_comps().end())) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); + this->tidy_min_surface(); + return (FALSE); + } + } + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) + { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); + if (kinetics_ptr == NULL || + (kinetics_ptr->Find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name()) == NULL)) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + this->tidy_kin_surface(); + return (FALSE); + } + } } for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) { From af2dbfdce28cf94ec83a78680c6457ffde54db8c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 28 Dec 2015 23:35:36 +0000 Subject: [PATCH 0952/1077] Added changes for serializing. Copied files from concrete_parallel, without merging or svn_copy. Added Dictionary.cpp and Serializer.cxx + header files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10607 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cpp | 32 +++++++ Dictionary.h | 28 ++++++ ExchComp.cxx | 29 +++++++ ExchComp.h | 4 +- Exchange.cxx | 45 ++++++++++ Exchange.h | 2 + GasComp.cxx | 20 +++++ GasComp.h | 8 +- GasPhase.cxx | 54 ++++++++++++ GasPhase.h | 2 + KineticsComp.cxx | 36 ++++++++ KineticsComp.h | 2 + Makefile.am | 4 + NameDouble.cxx | 30 ++++++- NameDouble.h | 3 + PPassemblage.cxx | 42 +++++++++ PPassemblage.h | 2 + PPassemblageComp.cxx | 36 +++++++- PPassemblageComp.h | 2 + Phreeqc.h | 13 +++ Pressure.cxx | 36 ++++++++ Pressure.h | 5 +- SS.cxx | 79 ++++++++++++++++- SS.h | 3 + SSassemblage.cxx | 46 ++++++++++ SSassemblage.h | 4 +- SScomp.cxx | 39 +++++++++ SScomp.h | 4 +- Serializer.cxx | 198 +++++++++++++++++++++++++++++++++++++++++++ Serializer.h | 42 +++++++++ Solution.cxx | 152 +++++++++++++++++++++++++++++++++ Solution.h | 2 + SolutionIsotope.cxx | 29 ++++++- SolutionIsotope.h | 3 + Surface.cxx | 84 ++++++++++++++++++ Surface.h | 4 +- SurfaceCharge.cxx | 97 +++++++++++++++++++++ SurfaceCharge.h | 8 +- SurfaceComp.cxx | 35 ++++++++ SurfaceComp.h | 4 +- Temperature.cxx | 34 ++++++++ Temperature.h | 4 +- cxxKinetics.cxx | 61 +++++++++++++ cxxKinetics.h | 2 + gases.cpp | 4 +- 45 files changed, 1353 insertions(+), 20 deletions(-) create mode 100644 Dictionary.cpp create mode 100644 Dictionary.h create mode 100644 Serializer.cxx create mode 100644 Serializer.h diff --git a/Dictionary.cpp b/Dictionary.cpp new file mode 100644 index 00000000..bd5348d8 --- /dev/null +++ b/Dictionary.cpp @@ -0,0 +1,32 @@ +#include "Dictionary.h" +Dictionary::Dictionary(void) +{ +} + +Dictionary::Dictionary(std::string & words_string) +{ + std::istringstream words_stream(words_string); + char str[256]; + while (words_stream.getline(str,256)) + { + this->Find(str); + } +} +Dictionary::~Dictionary(void) +{ +} + +int +Dictionary::Find(std::string str) +{ + std::map::iterator it = this->dictionary_map.find(str); + if (it != this->dictionary_map.end()) + { + return it->second; + } + int i = this->MapSize(); + this->dictionary_map[str] = i; + this->words.push_back(str); + this->dictionary_oss << str << "\n"; + return i; +} diff --git a/Dictionary.h b/Dictionary.h new file mode 100644 index 00000000..ffe86fc5 --- /dev/null +++ b/Dictionary.h @@ -0,0 +1,28 @@ +#if !defined(DICTIONARY_H_INCLUDED) +#define DICTIONARY_H_INCLUDED +#include +#include +#include +#include +class Phreeqc; +class Dictionary +{ +public: + Dictionary(void); + Dictionary(std::string & words_string); + ~Dictionary(void); + int Find(std::string str); + int MapSize() {return (int) this->dictionary_map.size();} + int OssSize() {return (int) this->dictionary_oss.str().size();} + std::ostringstream &GetDictionaryOss() {return this->dictionary_oss;} + std::vector &GetWords() {return this->words;} + +protected: + std::map dictionary_map; + std::vector words; + std::ostringstream dictionary_oss; + +}; + +#endif // !defined(DICTIONARY_H_INCLUDED) + diff --git a/ExchComp.cxx b/ExchComp.cxx index 4ebd1f07..5af520b7 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -13,6 +13,7 @@ #include "Phreeqc.h" #include "ExchComp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -406,6 +407,34 @@ cxxExchComp::multiply(LDBLE extensive) this->phase_proportion *= extensive; } +void +cxxExchComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->formula)); + this->totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->la); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.Find(this->rate_name)); + doubles.push_back(this->formula_z); +} + +void +cxxExchComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->formula = dictionary.GetWords()[ints[ii++]]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->la = doubles[dd++]; + this->charge_balance = doubles[dd++]; + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->phase_proportion = doubles[dd++]; + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->formula_z = doubles[dd++]; +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("formula"), // 0 std::vector< std::string >::value_type("moles"), // 1 diff --git a/ExchComp.h b/ExchComp.h index a0d4fe65..c2846f7a 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -104,8 +104,10 @@ class cxxExchComp: public PHRQ_base void add(const cxxExchComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); - protected: +protected: std::string formula; // EXCHANGE_MODIFY candidates cxxNameDouble totals; diff --git a/Exchange.cxx b/Exchange.cxx index 3abf1de4..117123dd 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -435,6 +435,51 @@ Sort_comps(void) } } } +/* ---------------------------------------------------------------------- */ +void +cxxExchange::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + ints.push_back(this->n_user); + ints.push_back((int) this->exchange_comps.size()); + for (size_t i = 0; i < this->exchange_comps.size(); i++) + { + exchange_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back(this->pitzer_exchange_gammas ? 1 : 0); + ints.push_back(this->new_def ? 1 : 0); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back(this->n_solution); + this->totals.Serialize(dictionary, ints, doubles); + +} + +/* ---------------------------------------------------------------------- */ +void +cxxExchange::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + int count = ints[ii++]; + this->exchange_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxExchComp ec; + ec.Deserialize(dictionary, ints, doubles, ii, dd); + this->exchange_comps.push_back(ec); + } + this->pitzer_exchange_gammas = (ints[ii++] != 0); + this->new_def = (ints[ii++] != 0); + this->solution_equilibria = (ints[ii++] != 0); + this->n_solution = ints[ii++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pitzer_exchange_gammas"), // 0 std::vector< std::string >::value_type("component"), // 1 diff --git a/Exchange.h b/Exchange.h index 81c694cf..f387f2fe 100644 --- a/Exchange.h +++ b/Exchange.h @@ -46,6 +46,8 @@ public: void totalize(); const cxxNameDouble & Get_totals() const; + 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); protected: void add(const cxxExchange & addee, LDBLE extensive); diff --git a/GasComp.cxx b/GasComp.cxx index 79aca1ad..21a13c71 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -13,6 +13,7 @@ #include "Phreeqc.h" #include "GasComp.h" #include "phqalloc.h" +#include "Dictionary.h" @@ -178,6 +179,25 @@ cxxGasComp::multiply(LDBLE extensive) this->moles *= extensive; this->initial_moles *= extensive; } +void +cxxGasComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->moles); + doubles.push_back(this->p_read); + doubles.push_back(this->initial_moles); +} + +void +cxxGasComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->moles = doubles[dd++]; + this->p_read = doubles[dd++]; + this->initial_moles = doubles[dd++]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("phase_name"), // 0 std::vector< std::string >::value_type("name"), // 1 diff --git a/GasComp.h b/GasComp.h index e4ab7663..d4661a6b 100644 --- a/GasComp.h +++ b/GasComp.h @@ -33,11 +33,9 @@ class cxxGasComp: public PHRQ_base void add(const cxxGasComp & addee, LDBLE extensive); void multiply(LDBLE extensive); - -#ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif + 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); + protected: std::string phase_name; // GAS_PHASE_MODIFY candidates diff --git a/GasPhase.cxx b/GasPhase.cxx index 0fbac2a8..b3652787 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -657,6 +657,60 @@ cxxGasPhase::Find_comp(const char * comp_name) } return NULL; } +void +cxxGasPhase::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + ints.push_back((this->type == cxxGasPhase::GP_PRESSURE) ? 0 : 1); + doubles.push_back(this->total_p); + doubles.push_back(this->volume); + ints.push_back((int) this->gas_comps.size()); + for (size_t i = 0; i < this->gas_comps.size(); i++) + { + this->gas_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back(this->new_def ? 1 : 0); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back(this->n_solution); + doubles.push_back(this->temperature); + doubles.push_back(this->total_moles); + doubles.push_back(this->v_m); + ints.push_back(this->pr_in ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + +} + +void +cxxGasPhase::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : this->type = cxxGasPhase::GP_VOLUME; + this->total_p = doubles[dd++]; + this->volume = doubles[dd++]; + int count = ints[ii++]; + this->gas_comps.clear(); + for (int i = 0; i < count; i++) + { + cxxGasComp gc; + gc.Deserialize(dictionary, ints, doubles, ii, dd); + this->gas_comps.push_back(gc); + } + this->new_def = (ints[ii++] != 0) ? 1 : 0; + this->solution_equilibria = (ints[ii++] != 0) ? 1 : 0; + this->n_solution = ints[ii++]; + this->temperature = doubles[dd++]; + this->total_moles = doubles[dd++]; + this->v_m = doubles[dd++]; + this->pr_in = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("type"), //0 std::vector< std::string >::value_type("total_p"), //1 diff --git a/GasPhase.h b/GasPhase.h index d3664041..7dde49d1 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -67,6 +67,8 @@ class cxxGasPhase:public cxxNumKeyword void Set_temperature(LDBLE t) {temperature = t;}; LDBLE Calc_total_moles(void)const; cxxGasComp *Find_comp(const char * comp_name); + 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); protected: void add(const cxxGasPhase & addee, LDBLE extensive); diff --git a/KineticsComp.cxx b/KineticsComp.cxx index d18be8fa..3c9cd177 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -12,6 +12,7 @@ #include "KineticsComp.h" //#include "Dictionary.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -306,6 +307,41 @@ cxxKineticsComp::multiply(LDBLE extensive) this->m0 *= extensive; this->moles *= extensive; } +void +cxxKineticsComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->rate_name)); + this->namecoef.Serialize(dictionary, ints, doubles); + doubles.push_back(this->tol); + doubles.push_back(this->m); + doubles.push_back(this->m0); + ints.push_back((int) this->d_params.size()); + for (size_t i = 0; i < this->d_params.size(); i++) + { + doubles.push_back(d_params[i]); + } + doubles.push_back(this->moles); + doubles.push_back(this->initial_moles); + this->moles_of_reaction.Serialize(dictionary, ints, doubles); +} +void +cxxKineticsComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->namecoef.Deserialize(dictionary, ints, doubles, ii, dd); + this->tol = doubles[dd++]; + this->m = doubles[dd++]; + this->m0 = doubles[dd++]; + int n = ints[ii++]; + this->d_params.clear(); + for (int j = 0; j < n; j++) + { + this->d_params.push_back(doubles[dd++]); + } + this->moles = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->moles_of_reaction.Deserialize(dictionary, ints, doubles, ii, dd); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("rate_name_not_used"), // 0 std::vector< std::string >::value_type("tol"), // 1 diff --git a/KineticsComp.h b/KineticsComp.h index 8e503a10..eb3d954f 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -57,6 +57,8 @@ public: void add(const cxxKineticsComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: std::string rate_name; diff --git a/Makefile.am b/Makefile.am index f6e6e408..21629594 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,8 @@ phreeqc_SOURCES=\ cxxMix.h\ dense.cpp\ dense.h\ + Dictionary.cpp\ + Dictionary.h\ dumper.cpp\ dumper.h\ dw.cpp\ @@ -102,6 +104,8 @@ phreeqc_SOURCES=\ runner.h\ SelectedOutput.cpp\ SelectedOutput.h\ + Serializer.cxx\ + Serializer.h\ sit.cpp\ smalldense.cpp\ smalldense.h\ diff --git a/NameDouble.cxx b/NameDouble.cxx index c0bbc4c2..5780cfc8 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -12,6 +12,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "NameDouble.h" +#include "Dictionary.h" //#include "Dictionary.h" #include "phqalloc.h" #include "ISolutionComp.h" @@ -597,4 +598,31 @@ cxxNameDouble::sort_second(void) return myvec; } - +void +cxxNameDouble::Serialize(Dictionary &dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back((int) (*this).size()); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) + { + int n = dictionary.Find(it->first); + ints.push_back(n); + doubles.push_back(it->second); + } +} +void +cxxNameDouble::Deserialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles, int &ii, int &dd) +{ + this->clear(); + int count = ints[ii++]; + for (int j = 0; j < count; j++) + { + int n = ints[ii++]; + assert(n >= 0); + std::string str = dictionary.GetWords()[n]; + if (str.size() != 0) + { + (*this)[str] = doubles[dd++]; + } + } +} diff --git a/NameDouble.h b/NameDouble.h index 0e833d33..7df7e53b 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -15,6 +15,7 @@ class Phreeqc; #include "Parser.h" #include "phrqtype.h" +class Dictionary; class cxxISolutionComp; class IPQ_DLL_EXPORT cxxNameDouble:public @@ -60,6 +61,8 @@ class IPQ_DLL_EXPORT cxxNameDouble:public { (*this)[str] = d; } + void Serialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles); + void Deserialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles, int &ii, int &dd); enum ND_TYPE type; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index df8e5ba9..aed9983b 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -321,7 +321,49 @@ Find(const std::string name_in) } return comp; } +/* ---------------------------------------------------------------------- */ +void +cxxPPassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + ints.push_back(this->new_def ? 1 : 0); + ints.push_back((int) this->pp_assemblage_comps.size()); + for (std::map < std::string, cxxPPassemblageComp >::iterator it = + this->pp_assemblage_comps.begin(); it != this->pp_assemblage_comps.end(); + it++) + { + (*it).second.Serialize(dictionary, ints, doubles); + } + this->eltList.Serialize(dictionary, ints, doubles); + this->assemblage_totals.Serialize(dictionary, ints, doubles); +} +/* ---------------------------------------------------------------------- */ +void +cxxPPassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->new_def = (ints[ii++] != 0); + int count = ints[ii++]; + this->pp_assemblage_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxPPassemblageComp ppc; + ppc.Deserialize(dictionary, ints, doubles, ii, dd); + std::string str(ppc.Get_name()); + this->pp_assemblage_comps[str] = ppc; + } + this->eltList.Deserialize(dictionary, ints, doubles, ii, dd); + this->assemblage_totals.Deserialize(dictionary, ints, doubles, ii, dd); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("eltlist"), // 0 std::vector< std::string >::value_type("component"), // 1 diff --git a/PPassemblage.h b/PPassemblage.h index 7fadd9a3..5b735ad3 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -51,6 +51,8 @@ class cxxPPassemblage:public cxxNumKeyword cxxPPassemblageComp *Find(const std::string name); 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); protected: void add(const cxxPPassemblage & addee, LDBLE extensive); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0ab0f026..ea35b2b6 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "PPassemblageComp.h" -//#include "Dictionary.h" +#include "Dictionary.h" #include "phqalloc.h" ////////////////////////////////////////////////////////////////////// @@ -383,6 +383,40 @@ cxxPPassemblageComp::multiply(LDBLE extensive) this->delta *= extensive; this->initial_moles *= extensive; } +void +cxxPPassemblageComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->name)); + ints.push_back(dictionary.Find(this->add_formula)); + doubles.push_back(this->si); + doubles.push_back(this->si_org); + doubles.push_back(this->moles); + doubles.push_back(this->delta); + doubles.push_back(this->initial_moles); + ints.push_back( this->force_equality ? 1 : 0); + ints.push_back(this->dissolve_only ? 1 : 0); + ints.push_back(this->precipitate_only ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxPPassemblageComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->add_formula = dictionary.GetWords()[ints[ii++]]; + this->si = doubles[dd++]; + this->si_org = doubles[dd++]; + this->moles = doubles[dd++]; + this->delta = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->force_equality = (ints[ii++] != 0); + this->dissolve_only = (ints[ii++] != 0); + this->precipitate_only = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("add_formula"), // 1 diff --git a/PPassemblageComp.h b/PPassemblageComp.h index fa01a0c0..318707c1 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -60,6 +60,8 @@ class cxxPPassemblageComp: public PHRQ_base void add(const cxxPPassemblageComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: std::string name; diff --git a/Phreeqc.h b/Phreeqc.h index 3ad3391f..59e335fc 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1146,6 +1146,19 @@ public: size_t list_components(std::list &list_c); 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;} + + + std::map & Get_Rxn_solution_map() {return this->Rxn_solution_map;} + std::map & Get_Rxn_exchange_map() {return this->Rxn_exchange_map;} + std::map & Get_Rxn_gas_phase_map() {return this->Rxn_gas_phase_map;} + std::map & Get_Rxn_kinetics_map() {return this->Rxn_kinetics_map;} + std::map & Get_Rxn_pp_assemblage_map() {return this->Rxn_pp_assemblage_map;} + std::map & Get_Rxn_ss_assemblage_map() {return this->Rxn_ss_assemblage_map;} + std::map & Get_Rxn_surface_map() {return this->Rxn_surface_map;} + std::map & Get_Rxn_temperature_map() {return this->Rxn_temperature_map;} + std::map & Get_Rxn_pressure_map() {return this->Rxn_pressure_map;} + + protected: void init(void); diff --git a/Pressure.cxx b/Pressure.cxx index 82e6735f..03bd30ca 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -399,6 +399,42 @@ Get_count(void) const } return (int) this->pressures.size(); } +void +cxxPressure::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + { + ints.push_back((int) this->pressures.size()); + for (size_t i = 0; i < this->pressures.size(); i++) + { + doubles.push_back(pressures[i]); + } + } + ints.push_back(this->count); + ints.push_back(this->equalIncrements ? 1 : 0); + +} + +void +cxxPressure::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + { + int count = ints[ii++]; + this->pressures.clear(); + for (int i = 0; i < count; i++) + { + this->pressures.push_back(doubles[dd++]); + } + } + this->count = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pressures"), //0 std::vector< std::string >::value_type("equal_increments"), //1 diff --git a/Pressure.h b/Pressure.h index 7a6b7fd0..377f2039 100644 --- a/Pressure.h +++ b/Pressure.h @@ -8,6 +8,7 @@ #include // std::vector #include "NumKeyword.h" +class Dictionary; class cxxPressure:public cxxNumKeyword { @@ -29,7 +30,9 @@ class cxxPressure:public cxxNumKeyword void Set_count(int i) {count = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} - + 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); + protected: std::vector < LDBLE >pressures; int count; diff --git a/SS.cxx b/SS.cxx index 066bb7b2..2ed2edc6 100644 --- a/SS.cxx +++ b/SS.cxx @@ -10,7 +10,7 @@ #include "Phreeqc.h" #include "Utils.h" // define first #include "SS.h" -//#include "Dictionary.h" +#include "Dictionary.h" #include "phqalloc.h" @@ -532,6 +532,83 @@ cxxSS::Find(const char * comp_name) } return NULL; } +void +cxxSS::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->ag0); + doubles.push_back(this->ag1); + { + ints.push_back((int) ss_comps.size()); + for (size_t i = 0; i < ss_comps.size(); i++) + { + ss_comps[i].Serialize(dictionary, ints, doubles); + } + } + doubles.push_back(this->a0); + doubles.push_back(this->a1); + ints.push_back(this->miscibility ? 1 : 0); + ints.push_back(this->spinodal ? 1 : 0); + doubles.push_back(this->tk); + doubles.push_back(this->xb1); + doubles.push_back(this->xb2); + ints.push_back((int) this->input_case); + { + ints.push_back((int) p.size()); + for (size_t i = 0; i < p.size(); i++) + { + doubles.push_back(p[i]); + } + } + doubles.push_back(this->total_moles); + doubles.push_back(this->dn); + ints.push_back(this->ss_in ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + +} + +void +cxxSS::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->ag0 = doubles[dd++]; + this->ag1 = doubles[dd++]; + { + int count = ints[ii++]; + this->ss_comps.clear(); + for (int i = 0; i < count; i++) + { + cxxSScomp ssc; + ssc.Deserialize(dictionary, ints, doubles, ii, dd); + this->ss_comps.push_back(ssc); + } + } + this->a0 = doubles[dd++]; + this->a1 = doubles[dd++]; + this->miscibility = (ints[ii++] != 0); + this->spinodal = (ints[ii++] != 0); + this->tk = doubles[dd++]; + this->xb1 = doubles[dd++]; + this->xb2 = doubles[dd++]; + this->input_case = (SS_PARAMETER_TYPE) ints[ii++]; + { + int count = ints[ii++]; + this->p.clear(); + for (int i = 0; i < count; i++) + { + p.push_back(doubles[dd++]); + } + } + this->total_moles = doubles[dd++]; + this->dn = doubles[dd++]; + this->ss_in = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("ss_name"), // 0 std::vector< std::string >::value_type("total_moles"), // 1 diff --git a/SS.h b/SS.h index 67277148..d5e5a30d 100644 --- a/SS.h +++ b/SS.h @@ -98,6 +98,9 @@ class cxxSS: public PHRQ_base std::vector & Get_p(void) {return this->p;} const std::vector & Get_p(void)const {return this->p;} void Set_p(const std::vector & t) {this->p = t;} + 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); + protected: std::string name; // candidates for SOLID_SOLUTION_MODIFY diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 4ef7b77c..471127bb 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -14,6 +14,7 @@ #include "SS.h" #include "cxxMix.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -287,6 +288,51 @@ Find(const std::string &s) return &(it->second); return NULL; } +void +cxxSSassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + /* int n_user; */ + ints.push_back(this->n_user); + { + ints.push_back((int) this->SSs.size()); + std::map < std::string, cxxSS >::iterator it; + for (it = this->SSs.begin(); it != this->SSs.end(); it++) + { + (*it).second.Serialize(dictionary, ints, doubles); + } + } + ints.push_back(this->new_def ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxSSassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + { + int count = ints[ii++]; + this->SSs.clear(); + for (int n = 0; n < count; n++) + { + cxxSS ssc; + ssc.Deserialize(dictionary, ints, doubles, ii, dd); + std::string str(ssc.Get_name()); + this->SSs[str] = ssc; + } + } + this->new_def = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("solid_solution"), // 0 std::vector< std::string >::value_type("ssassemblage_totals"), // 1 diff --git a/SSassemblage.h b/SSassemblage.h index 909f0f0f..d69a6962 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -43,7 +43,9 @@ public: std::vector Vectorize(void); void add(const cxxSSassemblage & addee, LDBLE extensive); cxxSS *Find(const std::string &s); - + 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); + protected: // SOLID_SOLUTION_MODIFY candidate std::map < std::string, cxxSS > SSs; diff --git a/SScomp.cxx b/SScomp.cxx index 6088bf47..a750a627 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SScomp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -277,6 +278,44 @@ cxxSScomp::multiply(LDBLE extensive) this->delta *= extensive; this->initial_moles *= extensive; } +void +cxxSScomp::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->moles); + doubles.push_back(this->initial_moles); + doubles.push_back(this->init_moles); + doubles.push_back(this->delta); + doubles.push_back(this->fraction_x); + doubles.push_back(this->log10_lambda); + doubles.push_back(this->log10_fraction_x); + doubles.push_back(this->dn); + doubles.push_back(this->dnc); + doubles.push_back(this->dnb); + +} + +void +cxxSScomp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + + this->name = dictionary.GetWords()[ints[ii++]]; + this->moles = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->init_moles = doubles[dd++]; + this->delta = doubles[dd++]; + this->fraction_x = doubles[dd++]; + this->log10_lambda = doubles[dd++]; + this->log10_fraction_x = doubles[dd++]; + this->dn = doubles[dd++]; + this->dnc = doubles[dd++]; + this->dnb = doubles[dd++]; + +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("initial_moles"), // 1 diff --git a/SScomp.h b/SScomp.h index 7aaaa2fd..1afa66e5 100644 --- a/SScomp.h +++ b/SScomp.h @@ -44,7 +44,9 @@ class cxxSScomp: public PHRQ_base void Set_dnb(LDBLE t) {this->dnb = t;} void multiply(LDBLE extensive); - + 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); + protected: std::string name; // SOLID_SOLUTION_MODIFY candidate identifier diff --git a/Serializer.cxx b/Serializer.cxx new file mode 100644 index 00000000..0c57297d --- /dev/null +++ b/Serializer.cxx @@ -0,0 +1,198 @@ +#include "Serializer.h" +#include "Phreeqc.h" +#include "Utils.h" +#include "Solution.h" +#include "Exchange.h" +#include "Temperature.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" +Serializer::Serializer(PHRQ_io *io) + : PHRQ_base(io) +{ +} +Serializer::~Serializer(void) +{ +} +bool Serializer::Serialize(Phreeqc &phreeqc_ref, int start, int end, bool include_t, bool include_p, PHRQ_io *io) +{ + for (int i = start; i <= end; i++) + { + cxxSolution *soln_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_solution_map(), i); + if (soln_ptr) + { + ints.push_back((int) PT_SOLUTION); + soln_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + // Exchangers + { + cxxExchange *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_exchange_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_EXCHANGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // GasPhases + { + cxxGasPhase *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_gas_phase_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_GASPHASE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Kinetics + { + cxxKinetics *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_kinetics_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_KINETICS); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // PPassemblages + { + cxxPPassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pp_assemblage_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_PPASSEMBLAGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // SSassemblages + { + cxxSSassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_ss_assemblage_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_SSASSEMBLAGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Surfaces + { + cxxSurface *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_surface_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_SURFACES); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Temperature + if (include_t) + { + cxxTemperature *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_temperature_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_TEMPERATURE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Pressure + if (include_p) + { + cxxPressure *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pressure_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_PRESSURE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + } + return true; +} + +bool +Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vector &ints, std::vector &doubles) +{ + int ii = 0; + int dd = 0; + while (ii < ints.size()) + { + PACK_TYPE type = (PACK_TYPE) ints[ii++]; + switch (type) + { + case PT_SOLUTION: + { + cxxSolution soln; + soln.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = soln.Get_n_user(); + //std::cerr << "unpacked solution " << n_user << std::endl; + phreeqc_ref.Get_Rxn_solution_map()[n_user] = soln; + } + break; + case PT_EXCHANGE: + { + cxxExchange entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_exchange_map()[n_user] = entity; + } + break; + case PT_GASPHASE: + { + cxxGasPhase entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_gas_phase_map()[n_user] = entity; + } + break; + case PT_KINETICS: + { + cxxKinetics entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_kinetics_map()[n_user] = entity; + } + break; + case PT_PPASSEMBLAGE: + { + cxxPPassemblage entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + //std::cerr << "unpacked pp assemblage " << n_user << std::endl; + phreeqc_ref.Get_Rxn_pp_assemblage_map()[n_user] = entity; + } + break; + case PT_SSASSEMBLAGE: + { + cxxSSassemblage entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_ss_assemblage_map()[n_user] = entity; + } + break; + case PT_SURFACES: + { + cxxSurface entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_surface_map()[n_user] = entity; + } + break; + case PT_TEMPERATURE: + { + cxxTemperature entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_temperature_map()[n_user] = entity; + } + break; + case PT_PRESSURE: + { + cxxPressure entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_pressure_map()[n_user] = entity; + } + break; + default: + std::cerr << "Unknown pack type in deserialize " << type << std::endl; + exit(4); + break; + } + } + return true; +} \ No newline at end of file diff --git a/Serializer.h b/Serializer.h new file mode 100644 index 00000000..80c285d8 --- /dev/null +++ b/Serializer.h @@ -0,0 +1,42 @@ +#if !defined(SERIALIZER_H_INCLUDED) +#define SERIALIZER_H_INCLUDED +#include +#include +#include +#include +#include "PHRQ_base.h" +#include "Dictionary.h" +class Phreeqc; +class Serializer : public PHRQ_base +{ +public: + Serializer(PHRQ_io *io = NULL); + ~Serializer(void); + + enum PACK_TYPE + { + PT_SOLUTION = 0, + PT_EXCHANGE = 1, + PT_GASPHASE = 2, + PT_KINETICS = 3, + PT_PPASSEMBLAGE = 4, + PT_SSASSEMBLAGE = 5, + PT_SURFACES = 6, + PT_TEMPERATURE = 7, + PT_PRESSURE = 8 + }; + bool Serialize(Phreeqc &phreeqc_ptr, int start, int end, bool include_t, bool include_p, PHRQ_io *io = NULL); + bool Deserialize(Phreeqc &phreeqc_ptr, Dictionary &dictionary, std::vector &ints, std::vector &doubles); + Dictionary &GetDictionary(void) {return this->dictionary;} + std::vector &GetInts(void) {return this->ints;} + std::vector &GetDoubles(void) {return this->doubles;} + //std::string &GetWordsString(void) {return this->words_string;} + + +protected: + std::vector ints; + std::vector doubles; + //std::string words_string; + Dictionary dictionary; +}; +#endif // !defined(SERIALIZER_H_INCLUDED) \ No newline at end of file diff --git a/Solution.cxx b/Solution.cxx index 23224e81..2ed55a72 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -13,6 +13,7 @@ #include "Solution.h" #include "cxxMix.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -1521,6 +1522,157 @@ cxxSolution::Multiply_isotopes(LDBLE extensive) it->second.Set_total(total); } } + +/* ---------------------------------------------------------------------- */ +void +cxxSolution::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + ints.push_back(this->n_user); + ints.push_back(this->new_def ? 1 : 0); + doubles.push_back(this->patm); + doubles.push_back(this->tc); + doubles.push_back(this->ph); + doubles.push_back(this->pe); + doubles.push_back(this->mu); + doubles.push_back(this->ah2o); + doubles.push_back(this->total_h); + doubles.push_back(this->total_o); + doubles.push_back(this->cb); + doubles.push_back(this->mass_water); + doubles.push_back(this->density); + doubles.push_back(this->soln_vol); + doubles.push_back(this->total_alkalinity); +/* + * struct conc *totals; +*/ + this->totals.Serialize(dictionary, ints, doubles); +/* + * struct master_activity *master_activity; + */ + this->master_activity.Serialize(dictionary, ints, doubles); +/* + * struct master_activity *species_gamma + */ + this->species_gamma.Serialize(dictionary, ints, doubles); +/* + * isotopes + */ + ints.push_back((int) isotopes.size()); + { + std::map < std::string, cxxSolutionIsotope >::iterator it; + for (it = isotopes.begin(); it != isotopes.end(); it++) + { + ints.push_back(dictionary.Find(it->first)); + it->second.Serialize(dictionary, ints, doubles); + } + } +/* + * species_map + */ + ints.push_back((int) species_map.size()); + { + std::map < int, double >::iterator it; + for (it = species_map.begin(); it != species_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +/* + * log_gamma_map + */ + ints.push_back((int) log_gamma_map.size()); + { + std::map < int, double >::iterator it; + for (it = log_gamma_map.begin(); it != log_gamma_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +} + +/* ---------------------------------------------------------------------- */ +void +cxxSolution::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->new_def = (ints[ii++] != 0); + this->patm = doubles[dd++]; + this->tc = doubles[dd++]; + this->ph = doubles[dd++]; + this->pe = doubles[dd++]; + this->mu = doubles[dd++]; + this->ah2o = doubles[dd++]; + this->total_h = doubles[dd++]; + this->total_o = doubles[dd++]; + this->cb = doubles[dd++]; + this->mass_water = doubles[dd++]; + this->density = doubles[dd++]; + this->soln_vol = doubles[dd++]; + this->total_alkalinity = doubles[dd++]; +/* + * struct conc *totals; +*/ + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * struct master_activity *master_activity; + */ + this->master_activity.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * struct master_activity *species_gamma; + */ + this->species_gamma.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * isotopes + */ + { + isotopes.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + std::string str = dictionary.GetWords()[ints[ii++]]; + cxxSolutionIsotope iso; + iso.Deserialize(dictionary, ints, doubles, ii, dd); + isotopes[str] = iso; + } + } +/* + * species_map + */ + { + species_map.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + species_map[ints[ii++]] = doubles[dd++]; + } + } +/* + * log_gamma_map + */ + { + log_gamma_map.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + log_gamma_map[ints[ii++]] = doubles[dd++]; + } + } +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("totals"), // 0 std::vector< std::string >::value_type("activities"), // 1 diff --git a/Solution.h b/Solution.h index a2a48c4c..04fe4876 100644 --- a/Solution.h +++ b/Solution.h @@ -111,6 +111,8 @@ class cxxSolution:public cxxNumKeyword void Update(const cxxNameDouble &nd); void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); void Update_activities(const cxxNameDouble &original_tot); + 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); protected: bool new_def; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 4ce3dc95..ecf72c4c 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -8,7 +8,7 @@ #include "Phreeqc.h" #include "SolutionIsotope.h" #include "phqalloc.h" - +#include "Dictionary.h" cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io) : @@ -285,6 +285,33 @@ cxxSolutionIsotope::multiply(LDBLE extensive) { this->total *= extensive; } +void +cxxSolutionIsotope::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + doubles.push_back(this->isotope_number); + ints.push_back(dictionary.Find(this->elt_name)); + ints.push_back(dictionary.Find(this->isotope_name)); + doubles.push_back(this->total); + doubles.push_back(this->ratio); + doubles.push_back(this->ratio_uncertainty); + ints.push_back(this->ratio_uncertainty_defined ? 1 : 0); + doubles.push_back(this->x_ratio_uncertainty); + doubles.push_back(this->coef); +} +void +cxxSolutionIsotope::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->isotope_number = doubles[dd++]; + this->elt_name = dictionary.GetWords()[ints[ii++]]; + this->isotope_name = dictionary.GetWords()[ints[ii++]]; + this->total = doubles[dd++]; + this->ratio = doubles[dd++]; + this->ratio_uncertainty = doubles[dd++]; + this->ratio_uncertainty_defined = (ints[ii++] != 0); + this->x_ratio_uncertainty = doubles[dd++]; + this->coef = doubles[dd++]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("isotope_number"), // 0 std::vector< std::string >::value_type("elt_name"), // 1 diff --git a/SolutionIsotope.h b/SolutionIsotope.h index ff83b876..231fe0ab 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -5,6 +5,7 @@ #include // std::string #include // std::list #include "Parser.h" +class Dictionary; class cxxSolutionIsotope: public PHRQ_base { @@ -66,6 +67,8 @@ class cxxSolutionIsotope: public PHRQ_base void add(const cxxSolutionIsotope & isotope_ptr, LDBLE intensive, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: LDBLE isotope_number; diff --git a/Surface.cxx b/Surface.cxx index 359ba8ac..b2e7ef2f 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -745,6 +745,90 @@ Sort_comps(void) } } } +/* ---------------------------------------------------------------------- */ +void +cxxSurface::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + + ints.push_back(this->n_user); + ints.push_back((int) this->surface_comps.size()); + { + for (size_t i = 0; i < this->surface_comps.size(); i++) + { + surface_comps[i].Serialize(dictionary, ints, doubles); + } + } + ints.push_back((int) this->surface_charges.size()); + { + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + surface_charges[i].Serialize(dictionary, ints, doubles); + } + } + ints.push_back(this->new_def ? 1 : 0); + ints.push_back((int) this->type); + ints.push_back((int) this->dl_type); + ints.push_back((int) this->sites_units); + ints.push_back(this->only_counter_ions ? 1 : 0); + doubles.push_back(this->thickness); + doubles.push_back(this->debye_lengths); + doubles.push_back(this->DDL_viscosity); + doubles.push_back(this->DDL_limit); + ints.push_back(this->transport ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back((int) this->n_solution); + +} + +/* ---------------------------------------------------------------------- */ +void +cxxSurface::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + { + int count = ints[ii++]; + this->surface_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxSurfaceComp sc; + sc.Deserialize(dictionary, ints, doubles, ii, dd); + this->surface_comps.push_back(sc); + } + } + { + int count = ints[ii++]; + this->surface_charges.clear(); + for (int n = 0; n < count; n++) + { + cxxSurfaceCharge sc; + sc.Deserialize(dictionary, ints, doubles, ii, dd); + this->surface_charges.push_back(sc); + } + } + this->new_def = (ints[ii++] != 0); + this->type = (SURFACE_TYPE) ints[ii++]; + this->dl_type = (DIFFUSE_LAYER_TYPE) ints[ii++]; + this->sites_units = (SITES_UNITS) ints[ii++]; + this->only_counter_ions = (ints[ii++] != 0); + this->thickness = doubles[dd++]; + this->debye_lengths = doubles[dd++]; + this->DDL_viscosity = doubles[dd++]; + this->DDL_limit = doubles[dd++]; + this->transport = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->solution_equilibria = (ints[ii++] != 0); + this->n_solution = ints[ii++]; + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("diffuse_layer"), // 0 std::vector< std::string >::value_type("edl"), // 1 diff --git a/Surface.h b/Surface.h index a1edb99c..4a197453 100644 --- a/Surface.h +++ b/Surface.h @@ -73,7 +73,9 @@ public: void Set_solution_equilibria(bool tf) {solution_equilibria = tf;} int Get_n_solution(void)const {return n_solution;} void Set_n_solution(int i) {n_solution = i;} - + 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); + protected: std::vector < cxxSurfaceComp > surface_comps; std::vector < cxxSurfaceCharge > surface_charges; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 6f52a563..6ee4ff1c 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SurfaceCharge.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -460,6 +461,102 @@ cxxSurfaceCharge::multiply(LDBLE extensive) this->mass_water *= extensive; this->diffuse_layer_totals.multiply(extensive); } +void +cxxSurfaceCharge::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->specific_area); + doubles.push_back(this->grams); + doubles.push_back(this->charge_balance); + doubles.push_back(this->mass_water); + doubles.push_back(this->la_psi); + doubles.push_back(this->capacitance[0]); + doubles.push_back(this->capacitance[1]); + this->diffuse_layer_totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->sigma0); + doubles.push_back(this->sigma1); + doubles.push_back(this->sigma2); + doubles.push_back(this->sigmaddl); + ints.push_back((int) this->g_map.size()); + { + std::map::iterator it; + for (it = this->g_map.begin(); it != this->g_map.end(); it++) + { + doubles.push_back(it->first); + it->second.Serialize(dictionary, ints, doubles); + } + } + ints.push_back((int) this->dl_species_map.size()); + { + std::map::iterator it; + for (it = this->dl_species_map.begin(); it != this->dl_species_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +} + +void +cxxSurfaceCharge::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->specific_area = doubles[dd++]; + this->grams = doubles[dd++]; + this->charge_balance = doubles[dd++]; + this->mass_water = doubles[dd++]; + this->la_psi = doubles[dd++]; + this->capacitance[0] = doubles[dd++]; + this->capacitance[1] = doubles[dd++]; + this->diffuse_layer_totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->sigma0 = doubles[dd++]; + this->sigma1 = doubles[dd++]; + this->sigma2 = doubles[dd++]; + this->sigmaddl = doubles[dd++]; + { + this->g_map.clear(); + int count = ints[ii++]; + for (int i = 0; i < count; i++) + { + double d = doubles[dd++]; + cxxSurfDL sdl; + sdl.Deserialize(dictionary, ints, doubles, ii, dd); + this->g_map[d] = sdl; + } + } + { + this->dl_species_map.clear(); + int count = ints[ii++]; + for (int i = 0; i < count; i++) + { + int j = ints[ii++]; + double d = doubles[dd++]; + dl_species_map[j] = d; + } + } + + +} +void +cxxSurfDL::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + doubles.push_back(this->g); + doubles.push_back(this->dg); + doubles.push_back(this->psi_to_z); +} + +void +cxxSurfDL::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->g = doubles[dd++]; + this->dg = doubles[dd++]; + this->psi_to_z = doubles[dd++]; +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("specific_area"), // 1 diff --git a/SurfaceCharge.h b/SurfaceCharge.h index a3a46265..7d284fbc 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -32,8 +32,7 @@ public: LDBLE *Get_dx_moles_address(void) {return &dx_moles;} LDBLE *Get_dh2o_moles_address(void) {return &dh2o_moles;} LDBLE *Get_drelated_moles_address(void) {return &drelated_moles;} - - + protected: LDBLE g_moles; LDBLE dg_g_moles; /* g_moles*dgterm */ @@ -54,6 +53,9 @@ public: void Set_dg(LDBLE t) {dg = t;} LDBLE Get_psi_to_z(void) const {return psi_to_z;} void Set_psi_to_z(LDBLE t) {psi_to_z = t;} + 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); + protected: LDBLE g; LDBLE dg; @@ -104,6 +106,8 @@ public: std::map &Get_g_map(void) {return g_map;} void Set_g_map(std::map & t) {g_map = t;} std::map & Get_dl_species_map(void) {return this->dl_species_map;} + 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); protected: std::string name; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index bfb9f15a..5a23eb16 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SurfaceComp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -445,6 +446,40 @@ cxxSurfaceComp::multiply(LDBLE extensive) this->charge_balance *= extensive; } +void +cxxSurfaceComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->formula)); + doubles.push_back(this->formula_z); + doubles.push_back(this->moles); + this->totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->la); + ints.push_back(dictionary.Find(this->charge_name)); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.Find(this->rate_name)); + doubles.push_back(this->Dw); + ints.push_back(dictionary.Find(this->master_element)); +} + +void +cxxSurfaceComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->formula = dictionary.GetWords()[ints[ii++]]; + this->formula_z = doubles[dd++]; + this->moles = doubles[dd++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->la = doubles[dd++]; + this->charge_name = dictionary.GetWords()[ints[ii++]]; + this->charge_balance = doubles[dd++]; + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->phase_proportion = doubles[dd++]; + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->Dw = doubles[dd++]; + this->master_element = dictionary.GetWords()[ints[ii++]]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("formula"), // 0 std::vector< std::string >::value_type("moles"), // 1 diff --git a/SurfaceComp.h b/SurfaceComp.h index 6bd14eb7..d3708acf 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -46,7 +46,9 @@ public: void Set_Dw(LDBLE d) {this->Dw = d;} const std::string &Get_master_element() const {return this->master_element;} void Set_master_element(const char * f) {this->master_element = f ? f : "";} - + 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); + protected: std::string formula; LDBLE formula_z; diff --git a/Temperature.cxx b/Temperature.cxx index 6b4102cb..a1df2da2 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -410,6 +410,40 @@ Get_countTemps(void) const } return (int) this->temps.size(); } +void +cxxTemperature::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + { + ints.push_back((int) this->temps.size()); + for (size_t i = 0; i < this->temps.size(); i++) + { + doubles.push_back(temps[i]); + } + } + ints.push_back(this->countTemps); + ints.push_back(this->equalIncrements ? 1 : 0); +} + +void +cxxTemperature::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + { + int count = ints[ii++]; + this->temps.clear(); + for (int i = 0; i < count; i++) + { + this->temps.push_back(doubles[dd++]); + } + } + this->countTemps = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("temps"), //0 std::vector< std::string >::value_type("equal_increments"), //1 diff --git a/Temperature.h b/Temperature.h index ed7e90d9..6af70b38 100644 --- a/Temperature.h +++ b/Temperature.h @@ -29,7 +29,9 @@ class cxxTemperature:public cxxNumKeyword void Set_countTemps(int i) {countTemps = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} - + 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); + protected: std::vector < LDBLE >temps; int countTemps; diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index c9fc7dc8..17ad6626 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -13,6 +13,7 @@ #include "cxxMix.h" #include "phqalloc.h" #include "PHRQ_io.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -566,6 +567,66 @@ Current_step(bool incremental_reactions, int reaction_step) const } return kin_time; } +void +cxxKinetics::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + ints.push_back((int) this->kinetics_comps.size()); + for (size_t i = 0; i < this->kinetics_comps.size(); i++) + { + this->kinetics_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back((int) this->steps.size()); + for (size_t i = 0; i < this->steps.size(); i++) + { + doubles.push_back(this->steps[i]); + } + ints.push_back(this->count); + ints.push_back(this->equalIncrements ? 1 : 0); + doubles.push_back(this->step_divide); + ints.push_back(this->rk); + ints.push_back(this->bad_step_max); + ints.push_back(this->use_cvode ? 1 : 0); + ints.push_back(this->cvode_steps); + ints.push_back(this->cvode_order); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxKinetics::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + int n = ints[ii++]; + this->kinetics_comps.clear(); + for (int i = 0; i < n; i++) + { + cxxKineticsComp kc; + kc.Deserialize(dictionary, ints, doubles, ii, dd); + this->kinetics_comps.push_back(kc); + } + n = ints[ii++]; + this->steps.clear(); + for (int i = 0; i < n; i++) + { + this->steps.push_back(doubles[dd++]); + } + this->count = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); + this->step_divide = doubles[dd++]; + this->rk = ints[ii++]; + this->bad_step_max = ints[ii++]; + this->use_cvode = (ints[ii++] != 0); + this->cvode_steps = ints[ii++]; + this->cvode_order = ints[ii++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("step_divide"), // 0 std::vector< std::string >::value_type("rk"), // 1 diff --git a/cxxKinetics.h b/cxxKinetics.h index b7235862..eff885ae 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -52,6 +52,8 @@ class cxxKinetics:public cxxNumKeyword int Get_reaction_steps(void) const; cxxKineticsComp * Find(const std::string &str); LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const; + 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); protected: void add(const cxxKinetics & addee, LDBLE extensive); diff --git a/gases.cpp b/gases.cpp index 52add3cd..871d41a9 100644 --- a/gases.cpp +++ b/gases.cpp @@ -459,10 +459,10 @@ calc_PR(void) while (P <= 0) { P = R_TK / (V_m - b_sum) - a_aa_sum / (V_m * (V_m + 2 * b_sum) - b2); - if (P <= 0.0) + if (P <= 0.0) { V_m *= 2.0; - //a_aa_sum /= 2.0; + //a_aa_sum /= 2.0; } } if (iterations > 0 && P < 150 && V_m < 1.01) From eb7e91ebad890a6cf85d32fafb495ffeac227d26 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Dec 2015 00:02:35 +0000 Subject: [PATCH 0953/1077] fixed Makefile.old, Linux warnings git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10608 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 52 +++++++++++++++++++++++++++++++++++--------------- Serializer.cxx | 4 ++-- prep.cpp | 4 ++-- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Makefile.old b/Makefile.old index 5e1f32bc..9bc2b402 100644 --- a/Makefile.old +++ b/Makefile.old @@ -234,6 +234,7 @@ CLASS_FILES = \ COMMON_CXXOBJS = \ dumper.o \ + Dictionary.o \ Exchange.o \ ExchComp.o \ GasPhase.o \ @@ -257,6 +258,7 @@ COMMON_CXXOBJS = \ ReadClass.o \ runner.o \ SelectedOutput.o \ + Serializer.o \ Solution.o \ SolutionIsotope.o \ SSassemblage.o \ @@ -288,6 +290,7 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # + cxxKinetics.o: ../cxxKinetics.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -297,7 +300,7 @@ cxxKinetics.o: ../cxxKinetics.cxx ../common/Utils.h ../common/phrqtype.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../cxxKinetics.h ../KineticsComp.h \ - ../phqalloc.h + ../phqalloc.h ../Dictionary.h cxxMix.o: ../cxxMix.cxx ../common/Utils.h ../common/phrqtype.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ @@ -324,7 +327,8 @@ ExchComp.o: ../ExchComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../ExchComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../ExchComp.h ../phqalloc.h \ + ../Dictionary.h GasComp.o: ../GasComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -333,7 +337,8 @@ GasComp.o: ../GasComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../GasComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../GasComp.h ../phqalloc.h \ + ../Dictionary.h GasPhase.o: ../GasPhase.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -368,7 +373,8 @@ KineticsComp.o: ../KineticsComp.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../KineticsComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../KineticsComp.h ../phqalloc.h \ + ../Dictionary.h NameDouble.o: ../NameDouble.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -377,7 +383,8 @@ NameDouble.o: ../NameDouble.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../ISolutionComp.h + ../global_structures.h ../NA.h ../Dictionary.h ../phqalloc.h \ + ../ISolutionComp.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../common/PHRQ_base.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h ../common/Utils.h ../common/phrqtype.h @@ -389,7 +396,8 @@ PPassemblageComp.o: ../PPassemblageComp.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../PPassemblageComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../PPassemblageComp.h ../Dictionary.h \ + ../phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -431,6 +439,19 @@ ReadClass.o: ../ReadClass.cxx ../common/Utils.h ../common/phrqtype.h \ ../PPassemblage.h ../PPassemblageComp.h ../cxxKinetics.h \ ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h \ ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h +Serializer.o: ../Serializer.cxx ../Serializer.h ../common/PHRQ_base.h \ + ../Dictionary.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../common/PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../common/Utils.h ../common/phrqtype.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Exchange.h ../ExchComp.h ../Temperature.h ../GasPhase.h ../GasComp.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h Solution.o: ../Solution.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -440,7 +461,7 @@ Solution.o: ../Solution.cxx ../common/Utils.h ../common/phrqtype.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h ../phqalloc.h + ../ISolution.h ../ISolutionComp.h ../phqalloc.h ../Dictionary.h SolutionIsotope.o: ../SolutionIsotope.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -449,7 +470,8 @@ SolutionIsotope.o: ../SolutionIsotope.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../SolutionIsotope.h ../phqalloc.h + ../global_structures.h ../NA.h ../SolutionIsotope.h ../phqalloc.h \ + ../Dictionary.h SSassemblage.o: ../SSassemblage.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -459,7 +481,7 @@ SSassemblage.o: ../SSassemblage.cxx ../common/Utils.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../phqalloc.h + ../phqalloc.h ../Dictionary.h SScomp.o: ../SScomp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -468,7 +490,7 @@ SScomp.o: ../SScomp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../SScomp.h ../phqalloc.h + ../global_structures.h ../NA.h ../SScomp.h ../phqalloc.h ../Dictionary.h SS.o: ../SS.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ @@ -477,7 +499,7 @@ SS.o: ../SS.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../common/Utils.h ../common/phrqtype.h \ - ../SS.h ../SScomp.h ../phqalloc.h + ../SS.h ../SScomp.h ../Dictionary.h ../phqalloc.h StorageBin.o: ../StorageBin.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -500,7 +522,7 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h + ../global_structures.h ../NA.h ../phqalloc.h ../Dictionary.h SurfaceComp.o: ../SurfaceComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -509,7 +531,7 @@ SurfaceComp.o: ../SurfaceComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h + ../global_structures.h ../NA.h ../phqalloc.h ../Dictionary.h Surface.o: ../Surface.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -608,6 +630,7 @@ cvode.o: ../cvode.cpp ../nvector_serial.h ../nvector.h ../sundialstypes.h \ ../global_structures.h ../NA.h ../phqalloc.h dense.o: ../dense.cpp ../sundialstypes.h ../common/phrqtype.h \ ../sundialsmath.h ../dense.h ../smalldense.h +Dictionary.o: ../Dictionary.cpp ../Dictionary.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h \ ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/PHRQ_io.h @@ -783,7 +806,7 @@ prep.o: ../prep.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h + ../ISolution.h ../ISolutionComp.h ../cxxKinetics.h ../KineticsComp.h print.o: ../print.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ @@ -944,7 +967,6 @@ Utils.o: ../common/Utils.cxx ../common/Utils.h ../common/phrqtype.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h - # ----------------------------------------------------------------------------- clean: rm -rf Class_release Class_debug Class_release_64 Class_debug_64 diff --git a/Serializer.cxx b/Serializer.cxx index 0c57297d..018f56ca 100644 --- a/Serializer.cxx +++ b/Serializer.cxx @@ -109,7 +109,7 @@ Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vecto { int ii = 0; int dd = 0; - while (ii < ints.size()) + while (ii < (int) ints.size()) { PACK_TYPE type = (PACK_TYPE) ints[ii++]; switch (type) @@ -195,4 +195,4 @@ Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vecto } } return true; -} \ No newline at end of file +} diff --git a/prep.cpp b/prep.cpp index bca3f6ce..ea75d995 100644 --- a/prep.cpp +++ b/prep.cpp @@ -3657,7 +3657,7 @@ setup_surface(void) if (use.Get_surface_ptr()->Get_related_phases()) { cxxPPassemblage *pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_surface_user()); - for (size_t i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) + for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) { if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name().size() > 0) { @@ -3722,7 +3722,7 @@ setup_surface(void) if (use.Get_surface_ptr()->Get_related_rate()) { cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); - for (size_t i = 0; i < (int) use.Get_surface_ptr()->Get_surface_comps().size(); i++) + for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) { if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) { From b88bd3f955a0f469dfd9474d4b85473fffe9a8e6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Dec 2015 00:10:20 +0000 Subject: [PATCH 0954/1077] more Linux warnings git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10609 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 +- cl1mp.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index b3652787..7be3206c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -688,7 +688,7 @@ cxxGasPhase::Deserialize(Dictionary & dictionary, std::vector < int >&ints, this->n_user_end = this->n_user; this->description = " "; - this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : this->type = cxxGasPhase::GP_VOLUME; + this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : cxxGasPhase::GP_VOLUME; this->total_p = doubles[dd++]; this->volume = doubles[dd++]; int count = ints[ii++]; diff --git a/cl1mp.cpp b/cl1mp.cpp index e581cdcf..0d1d2d1d 100644 --- a/cl1mp.cpp +++ b/cl1mp.cpp @@ -36,7 +36,7 @@ cl1mp(int k, int l, int m, int n, int iout = 0; // static i runs faster int i, j; - int maxit, n1, n2; + int maxit, n1; //, n2; int ia, ii, kk, nk, js; int in = 0; int iphase, kforce; @@ -221,7 +221,7 @@ cl1mp(int k, int l, int m, int n, /* Function Body */ maxit = *iter; n1 = n + 1; - n2 = n + 2; + // n2 = n + 2; nk = n + k; nkl = nk + l; klm = k + l + m; @@ -1131,4 +1131,4 @@ cl1mp(int k, int l, int m, int n, kode = (int *) free_check_null(kode); return 0; } -#endif // INVERSE_CL1MP \ No newline at end of file +#endif // INVERSE_CL1MP From b33a28fa91c533429991dd1d55950b16c5fabea6 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 29 Dec 2015 00:27:52 +0000 Subject: [PATCH 0955/1077] fgets warning git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10610 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 0d202d5a..538be065 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -735,7 +735,11 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -811,7 +815,11 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -883,7 +891,11 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') From 6ae25495c53895c6a5a7de101ecb14939d1ad487 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 29 Dec 2015 05:17:03 +0000 Subject: [PATCH 0956/1077] added ifdef for R (R_SO) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10618 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Serializer.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Serializer.cxx b/Serializer.cxx index 018f56ca..4b67baeb 100644 --- a/Serializer.cxx +++ b/Serializer.cxx @@ -189,8 +189,10 @@ Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vecto } break; default: +#if !defined(R_SO) std::cerr << "Unknown pack type in deserialize " << type << std::endl; exit(4); +#endif break; } } From a702035139952e5c9238dd0685c963a7a1ae7cdd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Dec 2015 17:39:12 +0000 Subject: [PATCH 0957/1077] totals of surface comp set incorrectly after read_raw. Skipping tidy for these cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10630 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 5d1e57e8..139d74cc 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -4071,10 +4071,10 @@ tidy_kin_surface(void) assert(false); } cxxSurface *surface_ptr = &(it->second); - //if (!surface_ptr->Get_new_def()) - // continue; - //if (surface_ptr->Get_n_user() < 0) - // continue; + if (!surface_ptr->Get_new_def()) + continue; + if (surface_ptr->Get_n_user() < 0) + continue; int n = surface_ptr->Get_n_user(); for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { @@ -4161,8 +4161,15 @@ tidy_kin_surface(void) free_check_null(temp_formula); } { - cxxNameDouble nd = elt_list_NameDouble(); - comp_ptr->Set_totals(nd); + if (surface_ptr->Get_new_def()) + { + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); + } + else + { + comp_ptr->Get_totals()[comp_ptr->Get_master_element()] = conc; + } } /* area */ From ae2286eb41ebcab7c0912fc2aff85a6866b4f117 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Dec 2015 18:14:48 +0000 Subject: [PATCH 0958/1077] Added serializer for rebalance by cell. Made fix to tidy_min_surface, same as tidy_kin_surface; skip if not new def. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10632 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 139d74cc..88e01a9f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3815,10 +3815,10 @@ tidy_min_surface(void) } cxxSurface *surface_ptr = &(kit->second); if (!surface_ptr->Get_new_def()) continue; - //if (!surface_ptr->Get_new_def()) - // continue; - //if (surface_ptr->Get_n_user() < 0) - // continue; + if (!surface_ptr->Get_new_def()) + continue; + if (surface_ptr->Get_n_user() < 0) + continue; for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { cxxSurfaceComp *surface_comp_ptr = &(surface_ptr->Get_surface_comps()[j]); @@ -3938,40 +3938,6 @@ tidy_min_surface(void) get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } -#ifdef SKIP - for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) - { - cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]); - continue; - if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) - { - char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str()); - char *ptr = temp_formula; - get_elts_in_species(&ptr, - -comp_jj_ptr->Get_phase_proportion()); - free_check_null(temp_formula); - } - else - { - struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); - if (elt_ptr->master->s->z != 0.0) - { - input_error++; - error_string = sformatf( - "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", - elt_ptr->master->s->name); - error_msg(error_string, CONTINUE); - } - { - char * temp_name = string_duplicate(elt_ptr->master->s->name); - char *ptr = temp_name; - get_elts_in_species(&ptr, - -comp_jj_ptr->Get_phase_proportion()); - free_check_null(temp_name); - } - } - } -#endif // Revise logic for surface related to mineral for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) { From dec66bb848a41d7d1185d79f63ab816940f28f7b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Dec 2015 18:23:01 +0000 Subject: [PATCH 0959/1077] tweak if tidy_min_surface is invoked on a _raw definition. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10633 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tidy.cpp b/tidy.cpp index 88e01a9f..198ef47f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3917,8 +3917,15 @@ tidy_min_surface(void) free_check_null(temp_formula); } { - cxxNameDouble nd = elt_list_NameDouble(); - surface_comp_ptr->Set_totals(nd); + if (surface_ptr->Get_new_def()) + { + cxxNameDouble nd = elt_list_NameDouble(); + surface_comp_ptr->Set_totals(nd); + } + else + { + surface_comp_ptr->Get_totals()[surface_comp_ptr->Get_master_element()] = conc; + } } /* area */ From 8f51d9279b3f0dfc486adcffbade6bc59f651597 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Dec 2015 21:25:06 +0000 Subject: [PATCH 0960/1077] Need to set new_def to trap error with surface related to rate. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10634 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prep.cpp b/prep.cpp index ea75d995..a775c235 100644 --- a/prep.cpp +++ b/prep.cpp @@ -6151,6 +6151,8 @@ check_same_model(void) (kinetics_ptr->Find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name()) == NULL)) { Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); this->tidy_kin_surface(); return (FALSE); } From a94659326b92b48c0ce6b24bd39814c317e6418f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 4 Jan 2016 17:17:15 +0000 Subject: [PATCH 0961/1077] Fixed formatting for temperature of Specific Conductance. Added test cases missing_surf_related_equi, missing_surf_related_kin, and SC_temp. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10641 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/print.cpp b/print.cpp index cbc043e5..a8dac445 100644 --- a/print.cpp +++ b/print.cpp @@ -2220,11 +2220,12 @@ print_totals(void) EC = calc_SC(); if (EC > 0) { - output_msg(sformatf("%36s%i%7s%i\n", + //output_msg(sformatf("%36s%i%7s%i\n", + output_msg(sformatf("%35s%3.0f%7s%i\n", #ifdef NO_UTF8_ENCODING - "Specific Conductance (uS/cm, ", (int) tc_x, "oC) = ", (int) EC)); + "Specific Conductance (uS/cm, ", tc_x, "oC) = ", (int) EC)); #else - "Specific Conductance (µS/cm, ", (int) tc_x, "°C) = ", (int) EC)); + "Specific Conductance (µS/cm, ", tc_x, "°C) = ", (int) EC)); #endif } /* VP: Density Start */ From 6f7a2e50dd0228d133acab3a04a0f663fc606f29 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 Jan 2016 21:01:54 +0000 Subject: [PATCH 0962/1077] Fixed segvs from Kinniburgh. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10663 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tidy.cpp b/tidy.cpp index 198ef47f..86f01f95 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3961,13 +3961,20 @@ tidy_min_surface(void) // Warn if not master species and charge balanced struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); + if (elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf("Unknown element definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", + surface_ptr->Get_n_user()); + error_msg(error_string); + continue; + } if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) { error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", elt_ptr->master->s->name); warning_msg(error_string); } - else if (elt_ptr->master->s->z != 0.0) { error_string = sformatf( @@ -4926,6 +4933,15 @@ ss_calc_a0_a1(cxxSS *ss_ptr) tol = 1e-6; rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; + if (ss_ptr->Get_ss_comps().size() < 2) + { + input_error++; + error_string = sformatf( + "Two components not defined for solid solution ", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + return (ERROR); + } cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); int k; From 516d6937ee19d5ec57b8b37660ade2ad382543fd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 11 Jan 2016 21:47:58 +0000 Subject: [PATCH 0963/1077] Another check for null pointers. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10664 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tidy.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index 86f01f95..d641a570 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3969,6 +3969,14 @@ tidy_min_surface(void) error_msg(error_string); continue; } + if (elt_ptr->master->s == NULL || elt_ptr->master->s->name == NULL) + { + input_error++; + error_string = sformatf("Unknown master species definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", + surface_ptr->Get_n_user()); + error_msg(error_string); + continue; + } if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) { error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", From 716a978be00f71dc7bfb803732af0e2dd00bfbd2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 19 Jan 2016 23:06:50 +0000 Subject: [PATCH 0964/1077] Made diagonal_scale true by default. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10703 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- mainsubs.cpp | 6 ++++-- step.cpp | 11 ++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index cbe54eb1..cfee755b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -722,7 +722,7 @@ void Phreeqc::init(void) pe_step_size_now = pe_step_size; pp_scale = 1.0; pp_column_scale = 1.0; - diagonal_scale = FALSE; + diagonal_scale = TRUE; mass_water_switch = FALSE; delay_mass_water = FALSE; equi_delay = 0; diff --git a/mainsubs.cpp b/mainsubs.cpp index 885957fd..2f367e9b 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -619,15 +619,17 @@ initial_solutions(int print) k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); set(TRUE); always_full_pitzer = FALSE; + bool diag = (diagonal_scale == TRUE) ? true : false; + diagonal_scale = TRUE; converge = model(); - if (converge == ERROR && diagonal_scale == FALSE) + if (converge == ERROR /*&& diagonal_scale == FALSE*/) { diagonal_scale = TRUE; always_full_pitzer = TRUE; set(TRUE); converge = model(); - diagonal_scale = FALSE; } + diagonal_scale = (diag) ? TRUE : FALSE; converge1 = check_residuals(); sum_species(); add_isotopes(solution_ref); diff --git a/step.cpp b/step.cpp index 57a4a860..ffcf1940 100644 --- a/step.cpp +++ b/step.cpp @@ -1444,13 +1444,18 @@ solution_check(void) for (i = 0; i < count_master; i++) { master_ptr = master[i]; - if (master_ptr->total >= 0.0) - continue; - if (master_ptr->total > -MIN_TOTAL) + if (master_ptr->total <= MIN_TOTAL && master_ptr->total >= -MIN_TOTAL) { master_ptr->total = 0; continue; } + if (master_ptr->total >= 0.0) + continue; + //if (master_ptr->total > -MIN_TOTAL) + //{ + // master_ptr->total = 0; + // continue; + //} if (master_ptr->s == s_eminus || master_ptr->s == s_h2o || master_ptr->s == s_hplus || master_ptr->s == s_h3oplus) { From 5af5488477c58b7de7f7cc8079b0a9660a9ffec7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 20 Jan 2016 16:01:03 +0000 Subject: [PATCH 0965/1077] Switching back to diagonal_scale false for default. No obvious advantage in test cases to change, and it could break someone's runs. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10711 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index cfee755b..cbe54eb1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -722,7 +722,7 @@ void Phreeqc::init(void) pe_step_size_now = pe_step_size; pp_scale = 1.0; pp_column_scale = 1.0; - diagonal_scale = TRUE; + diagonal_scale = FALSE; mass_water_switch = FALSE; delay_mass_water = FALSE; equi_delay = 0; From 174c739d268a93cf3a4ecf7ebdb0888da7d06007 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 20 Jan 2016 18:12:15 +0000 Subject: [PATCH 0966/1077] Updated concrete source from concrete_parallel source (not using parallel). Now going to run test cases on Linux. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10719 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ExchComp.cxx | 29 + ExchComp.h | 4 +- Exchange.cxx | 45 + Exchange.h | 2 + GasComp.cxx | 20 + GasComp.h | 8 +- GasPhase.cxx | 54 + GasPhase.h | 2 + KineticsComp.cxx | 36 + KineticsComp.h | 2 + Makefile.old | 385 ++++++-- NameDouble.cxx | 30 +- NameDouble.h | 3 + PPassemblage.cxx | 42 + PPassemblage.h | 2 + PPassemblageComp.cxx | 36 +- PPassemblageComp.h | 2 + Phreeqc.cpp | 9 +- Phreeqc.h | 16 + Pressure.cxx | 36 + Pressure.h | 5 +- SS.cxx | 79 +- SS.h | 3 + SSassemblage.cxx | 46 + SSassemblage.h | 4 +- SScomp.cxx | 39 + SScomp.h | 4 +- Solution.cxx | 158 ++- Solution.h | 2 + SolutionIsotope.cxx | 29 +- SolutionIsotope.h | 3 + Surface.cxx | 84 ++ Surface.h | 4 +- SurfaceCharge.cxx | 97 ++ SurfaceCharge.h | 8 +- SurfaceComp.cxx | 35 + SurfaceComp.h | 4 +- Temperature.cxx | 34 + Temperature.h | 4 +- basicsubs.cpp | 2 +- class_main.cpp | 100 +- cxxKinetics.cxx | 61 ++ cxxKinetics.h | 2 + global_structures.h | 3 +- kinetics.cpp | 1 + mainsubs.cpp | 17 +- read.cpp | 35 +- readtr.cpp | 29 +- transport.cpp | 2240 +++++++++++++++++++++++------------------- 49 files changed, 2768 insertions(+), 1127 deletions(-) diff --git a/ExchComp.cxx b/ExchComp.cxx index 4ebd1f07..5af520b7 100644 --- a/ExchComp.cxx +++ b/ExchComp.cxx @@ -13,6 +13,7 @@ #include "Phreeqc.h" #include "ExchComp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -406,6 +407,34 @@ cxxExchComp::multiply(LDBLE extensive) this->phase_proportion *= extensive; } +void +cxxExchComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->formula)); + this->totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->la); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.Find(this->rate_name)); + doubles.push_back(this->formula_z); +} + +void +cxxExchComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->formula = dictionary.GetWords()[ints[ii++]]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->la = doubles[dd++]; + this->charge_balance = doubles[dd++]; + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->phase_proportion = doubles[dd++]; + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->formula_z = doubles[dd++]; +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("formula"), // 0 std::vector< std::string >::value_type("moles"), // 1 diff --git a/ExchComp.h b/ExchComp.h index a0d4fe65..c2846f7a 100644 --- a/ExchComp.h +++ b/ExchComp.h @@ -104,8 +104,10 @@ class cxxExchComp: public PHRQ_base void add(const cxxExchComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); - protected: +protected: std::string formula; // EXCHANGE_MODIFY candidates cxxNameDouble totals; diff --git a/Exchange.cxx b/Exchange.cxx index 3abf1de4..117123dd 100644 --- a/Exchange.cxx +++ b/Exchange.cxx @@ -435,6 +435,51 @@ Sort_comps(void) } } } +/* ---------------------------------------------------------------------- */ +void +cxxExchange::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + ints.push_back(this->n_user); + ints.push_back((int) this->exchange_comps.size()); + for (size_t i = 0; i < this->exchange_comps.size(); i++) + { + exchange_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back(this->pitzer_exchange_gammas ? 1 : 0); + ints.push_back(this->new_def ? 1 : 0); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back(this->n_solution); + this->totals.Serialize(dictionary, ints, doubles); + +} + +/* ---------------------------------------------------------------------- */ +void +cxxExchange::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + int count = ints[ii++]; + this->exchange_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxExchComp ec; + ec.Deserialize(dictionary, ints, doubles, ii, dd); + this->exchange_comps.push_back(ec); + } + this->pitzer_exchange_gammas = (ints[ii++] != 0); + this->new_def = (ints[ii++] != 0); + this->solution_equilibria = (ints[ii++] != 0); + this->n_solution = ints[ii++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pitzer_exchange_gammas"), // 0 std::vector< std::string >::value_type("component"), // 1 diff --git a/Exchange.h b/Exchange.h index 81c694cf..f387f2fe 100644 --- a/Exchange.h +++ b/Exchange.h @@ -46,6 +46,8 @@ public: void totalize(); const cxxNameDouble & Get_totals() const; + 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); protected: void add(const cxxExchange & addee, LDBLE extensive); diff --git a/GasComp.cxx b/GasComp.cxx index 79aca1ad..21a13c71 100644 --- a/GasComp.cxx +++ b/GasComp.cxx @@ -13,6 +13,7 @@ #include "Phreeqc.h" #include "GasComp.h" #include "phqalloc.h" +#include "Dictionary.h" @@ -178,6 +179,25 @@ cxxGasComp::multiply(LDBLE extensive) this->moles *= extensive; this->initial_moles *= extensive; } +void +cxxGasComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->moles); + doubles.push_back(this->p_read); + doubles.push_back(this->initial_moles); +} + +void +cxxGasComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->moles = doubles[dd++]; + this->p_read = doubles[dd++]; + this->initial_moles = doubles[dd++]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("phase_name"), // 0 std::vector< std::string >::value_type("name"), // 1 diff --git a/GasComp.h b/GasComp.h index e4ab7663..d4661a6b 100644 --- a/GasComp.h +++ b/GasComp.h @@ -33,11 +33,9 @@ class cxxGasComp: public PHRQ_base void add(const cxxGasComp & addee, LDBLE extensive); void multiply(LDBLE extensive); - -#ifdef USE_MPI - void mpi_pack(std::vector < int >&ints, std::vector < LDBLE >&doubles); - void mpi_unpack(int *ints, int *ii, LDBLE *doubles, int *dd); -#endif + 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); + protected: std::string phase_name; // GAS_PHASE_MODIFY candidates diff --git a/GasPhase.cxx b/GasPhase.cxx index 0fbac2a8..b3652787 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -657,6 +657,60 @@ cxxGasPhase::Find_comp(const char * comp_name) } return NULL; } +void +cxxGasPhase::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + ints.push_back((this->type == cxxGasPhase::GP_PRESSURE) ? 0 : 1); + doubles.push_back(this->total_p); + doubles.push_back(this->volume); + ints.push_back((int) this->gas_comps.size()); + for (size_t i = 0; i < this->gas_comps.size(); i++) + { + this->gas_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back(this->new_def ? 1 : 0); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back(this->n_solution); + doubles.push_back(this->temperature); + doubles.push_back(this->total_moles); + doubles.push_back(this->v_m); + ints.push_back(this->pr_in ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + +} + +void +cxxGasPhase::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : this->type = cxxGasPhase::GP_VOLUME; + this->total_p = doubles[dd++]; + this->volume = doubles[dd++]; + int count = ints[ii++]; + this->gas_comps.clear(); + for (int i = 0; i < count; i++) + { + cxxGasComp gc; + gc.Deserialize(dictionary, ints, doubles, ii, dd); + this->gas_comps.push_back(gc); + } + this->new_def = (ints[ii++] != 0) ? 1 : 0; + this->solution_equilibria = (ints[ii++] != 0) ? 1 : 0; + this->n_solution = ints[ii++]; + this->temperature = doubles[dd++]; + this->total_moles = doubles[dd++]; + this->v_m = doubles[dd++]; + this->pr_in = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("type"), //0 std::vector< std::string >::value_type("total_p"), //1 diff --git a/GasPhase.h b/GasPhase.h index d3664041..7dde49d1 100644 --- a/GasPhase.h +++ b/GasPhase.h @@ -67,6 +67,8 @@ class cxxGasPhase:public cxxNumKeyword void Set_temperature(LDBLE t) {temperature = t;}; LDBLE Calc_total_moles(void)const; cxxGasComp *Find_comp(const char * comp_name); + 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); protected: void add(const cxxGasPhase & addee, LDBLE extensive); diff --git a/KineticsComp.cxx b/KineticsComp.cxx index d18be8fa..3c9cd177 100644 --- a/KineticsComp.cxx +++ b/KineticsComp.cxx @@ -12,6 +12,7 @@ #include "KineticsComp.h" //#include "Dictionary.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -306,6 +307,41 @@ cxxKineticsComp::multiply(LDBLE extensive) this->m0 *= extensive; this->moles *= extensive; } +void +cxxKineticsComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->rate_name)); + this->namecoef.Serialize(dictionary, ints, doubles); + doubles.push_back(this->tol); + doubles.push_back(this->m); + doubles.push_back(this->m0); + ints.push_back((int) this->d_params.size()); + for (size_t i = 0; i < this->d_params.size(); i++) + { + doubles.push_back(d_params[i]); + } + doubles.push_back(this->moles); + doubles.push_back(this->initial_moles); + this->moles_of_reaction.Serialize(dictionary, ints, doubles); +} +void +cxxKineticsComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->namecoef.Deserialize(dictionary, ints, doubles, ii, dd); + this->tol = doubles[dd++]; + this->m = doubles[dd++]; + this->m0 = doubles[dd++]; + int n = ints[ii++]; + this->d_params.clear(); + for (int j = 0; j < n; j++) + { + this->d_params.push_back(doubles[dd++]); + } + this->moles = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->moles_of_reaction.Deserialize(dictionary, ints, doubles, ii, dd); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("rate_name_not_used"), // 0 std::vector< std::string >::value_type("tol"), // 1 diff --git a/KineticsComp.h b/KineticsComp.h index 8e503a10..eb3d954f 100644 --- a/KineticsComp.h +++ b/KineticsComp.h @@ -57,6 +57,8 @@ public: void add(const cxxKineticsComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: std::string rate_name; diff --git a/Makefile.old b/Makefile.old index 5e1f32bc..dc037c02 100644 --- a/Makefile.old +++ b/Makefile.old @@ -12,6 +12,8 @@ PROGRAM = phreeqc +MPI_DIR=/usr/lib64/openmpi + CFG1 :=`uname` CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") ifeq ($(CFG), CYGWIN) @@ -22,29 +24,26 @@ else SPOOL2= endif -all: class_release class_debug +all: release_openmp -Debug: class_debug -debug: class_debug -Class_debug: class_debug +Debug: debug +Debug_openmp: debug_openmp +Debug_mpi: debug_mpi + +Release: release +Release_omp: release_openmp +Release_mpi: release_mpi + + +DEBUG_DIR = debug +DEBUG_OPENMP_DIR = debug_openmp +DEBUG_MPI_DIR = debug_mpi +RELEASE_DIR = release +RELEASE_OPENMP_DIR = release_openmp +RELEASE_MPI_DIR = release_mpi -Release: class_release -release: class_release -Class_release: class_release - -Debug_64: class_debug_64 -debug_64: class_debug_64 -Class_debug_64: class_debug_64 - -Release_64: class_release_64 -release_64: class_release_64 -Class_release_64: class_release_64 -CLASS_DEBUG_DIR = Class_debug -CLASS_DIR = Class_release -CLASS_DEBUG_64_DIR = Class_debug_64 -CLASS_64_DIR = Class_release_64 MAKEFILE = Makefile.old # ----------------------------------------------------------------------------- @@ -55,24 +54,35 @@ HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) ######################### #### Serial Versions #### ######################### -.PHONY : Class_debug -class_debug: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) +.PHONY : debug +debug: + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG $(PROGRAM) -.PHONY : Class_release -class_release: - mkdir -p $(CLASS_DIR) - cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) -.PHONY : Class_debug_64 -class_debug_64: - mkdir -p $(CLASS_DEBUG_64_DIR) - cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) +.PHONY : release +release: + mkdir -p $(RELEASE_DIR) + cd $(RELEASE_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE $(PROGRAM) -.PHONY : Class_release_64 -class_release_64: - mkdir -p $(CLASS_64_DIR) - cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) +.PHONY : debug_openmp +debug_openmp: + mkdir -p $(DEBUG_OPENMP_DIR) + cd $(DEBUG_OPENMP_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG_OPENMP $(PROGRAM) + +.PHONY : release_openmp +release_openmp: + mkdir -p $(RELEASE_OPENMP_DIR) + cd $(RELEASE_OPENMP_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE_OPENMP $(PROGRAM) + +.PHONY : debug_mpi +debug_mpi: + mkdir -p $(DEBUG_MPI_DIR) + cd $(DEBUG_MPI_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG_MPI $(PROGRAM) + +.PHONY : release_mpi +release_mpi: + mkdir -p $(RELEASE_MPI_DIR) + cd $(RELEASE_MPI_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE_MPI $(PROGRAM) # Recursive make begins here # @@ -96,11 +106,6 @@ class_release_64: .cpp.o : ${CXX} ${CXXFLAGS} -c -o $@ $< -# ----------------------------------------------------------------------------- -#hdf options -#HDF5_ROOT=$(HOME)/../../usr -#HDF5_INCLUDES=-I$(HDF5_ROOT)/src -#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread # ----------------------------------------------------------------------------- # #define compile options @@ -114,15 +119,15 @@ class_release_64: EFENCE_LIB=-L$(HOME)/packages/efence # ----------------------------------------------------------------------------- -# 4 Versions +# Versions # ----------------------------------------------------------------------------- -ifeq ($(CFG), CLASS_DEBUG) +ifeq ($(CFG), DEBUG) INVERSE_CL1MP=TRUE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o # CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + CL1MP_LIB=/usr/lib64/libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../PhreeqcKeywords:../common @@ -133,13 +138,13 @@ ifeq ($(CFG), CLASS_DEBUG) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif -ifeq ($(CFG), CLASS_RELEASE) +ifeq ($(CFG), RELEASE) INVERSE_CL1MP=TRUE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o # CL1MP_LIB=-lgmp - CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a + CL1MP_LIB=/usr/lib64/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../PhreeqcKeywords:../common @@ -150,40 +155,76 @@ ifeq ($(CFG), CLASS_RELEASE) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif -ifeq ($(CFG), CLASS_DEBUG_64) -# INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o - CL1MP_LIB=libgmp.a - endif - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 - VPATH = ..:../PhreeqcKeywords:../common - INCLUDES = -I.. -I../PhreeqcKeywords -I../common - CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -endif - -ifeq ($(CFG), CLASS_RELEASE_64) +ifeq ($(CFG), DEBUG_OPENMP) INVERSE_CL1MP=TRUE ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o CL1MP_LIB=/usr/lib64/libgmp.a endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DUSE_PHRQ_ALLOC # -DR_SO - VPATH = ..:../PhreeqcKeywords:../common - INCLUDES = -I.. -I../PhreeqcKeywords -I../common + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_OPENMP + VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc + INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc + CXX = g++ + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) -fopenmp + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(PARALLELIZER_OBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -lgomp +endif + +ifeq ($(CFG), RELEASE_OPENMP) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o + CL1MP_LIB=/usr/lib64/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_OPENMP # -DUSE_PHRQ_ALLOC + VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc + INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc CXX = g++ PROFILE = - CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g + CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) -fopenmp # CXXFLAGS = -fprofile-arcs -ftest-coverage $(DEFINES) $(INCLUDES) # -g - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) - LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) + LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} -lgomp # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov endif +ifeq ($(CFG), DEBUG_MPI) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o + CL1MP_LIB=/usr/lib64/libgmp.a + endif + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_MPI + VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc + INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc + CXX = $(MPI_DIR)/bin/mpiCC + CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -lmpi_usempi +endif + +ifeq ($(CFG), RELEASE_MPI) + INVERSE_CL1MP=TRUE + ifdef INVERSE_CL1MP + DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP + CL1MP_OBJS=cl1mp.o + CL1MP_LIB=/usr/lib64/libgmp.a + endif + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_MPI # -DUSE_PHRQ_ALLOC + VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc + INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc + CXX = $(MPI_DIR)/bin/mpiCC + PROFILE = + CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) +# CXXFLAGS = -fprofile-arcs -ftest-coverage $(DEFINES) $(INCLUDES) # -g + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) + LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} -lmpi_usempi +endif + + + # ----------------------------------------------------------------------------- # @@ -234,6 +275,7 @@ CLASS_FILES = \ COMMON_CXXOBJS = \ dumper.o \ + Dictionary.o \ Exchange.o \ ExchComp.o \ GasPhase.o \ @@ -257,6 +299,7 @@ COMMON_CXXOBJS = \ ReadClass.o \ runner.o \ SelectedOutput.o \ + Serializer.o \ Solution.o \ SolutionIsotope.o \ SSassemblage.o \ @@ -273,6 +316,16 @@ COMMON_CXXOBJS = \ UserPunch.o \ Utils.o +PARALLELIZER_OBJS = \ + Parallelizer.o \ + PhreeqcRM.o \ + IPhreeqcPhast.o \ + IPhreeqcPhastLib.o \ + IPhreeqc.o \ + IPhreeqcLib.o \ + Var.o \ + CSelectedOutput.o + # ----------------------------------------------------------------------------- # Assign dependents to target on dependency line & link options on command # line. Command line is initiated with a tab. ($@ is an internal macro for @@ -288,6 +341,7 @@ ${PROGRAM} : ${OBJECT_FILES} # # CXX files # + cxxKinetics.o: ../cxxKinetics.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -297,7 +351,7 @@ cxxKinetics.o: ../cxxKinetics.cxx ../common/Utils.h ../common/phrqtype.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../cxxKinetics.h ../KineticsComp.h \ - ../phqalloc.h + ../phqalloc.h ../Dictionary.h cxxMix.o: ../cxxMix.cxx ../common/Utils.h ../common/phrqtype.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ @@ -324,7 +378,8 @@ ExchComp.o: ../ExchComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../ExchComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../ExchComp.h ../phqalloc.h \ + ../Dictionary.h GasComp.o: ../GasComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -333,7 +388,8 @@ GasComp.o: ../GasComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../GasComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../GasComp.h ../phqalloc.h \ + ../Dictionary.h GasPhase.o: ../GasPhase.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -368,7 +424,8 @@ KineticsComp.o: ../KineticsComp.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../KineticsComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../KineticsComp.h ../phqalloc.h \ + ../Dictionary.h NameDouble.o: ../NameDouble.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -377,7 +434,8 @@ NameDouble.o: ../NameDouble.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h ../ISolutionComp.h + ../global_structures.h ../NA.h ../Dictionary.h ../phqalloc.h \ + ../ISolutionComp.h NumKeyword.o: ../NumKeyword.cxx ../NumKeyword.h ../common/PHRQ_base.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h ../common/Utils.h ../common/phrqtype.h @@ -389,7 +447,8 @@ PPassemblageComp.o: ../PPassemblageComp.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../PPassemblageComp.h ../phqalloc.h + ../global_structures.h ../NA.h ../PPassemblageComp.h ../Dictionary.h \ + ../phqalloc.h PPassemblage.o: ../PPassemblage.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -431,6 +490,19 @@ ReadClass.o: ../ReadClass.cxx ../common/Utils.h ../common/phrqtype.h \ ../PPassemblage.h ../PPassemblageComp.h ../cxxKinetics.h \ ../KineticsComp.h ../SSassemblage.h ../SS.h ../SScomp.h ../GasPhase.h \ ../GasComp.h ../Reaction.h ../Temperature.h ../phqalloc.h +Serializer.o: ../Serializer.cxx ../Serializer.h ../common/PHRQ_base.h \ + ../Dictionary.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../common/PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h ../NumKeyword.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h \ + ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h ../common/Utils.h ../common/phrqtype.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Exchange.h ../ExchComp.h ../Temperature.h ../GasPhase.h ../GasComp.h \ + ../cxxKinetics.h ../KineticsComp.h ../PPassemblage.h \ + ../PPassemblageComp.h ../SSassemblage.h ../SS.h ../SScomp.h Solution.o: ../Solution.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -440,7 +512,7 @@ Solution.o: ../Solution.cxx ../common/Utils.h ../common/phrqtype.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h ../phqalloc.h + ../ISolution.h ../ISolutionComp.h ../phqalloc.h ../Dictionary.h SolutionIsotope.o: ../SolutionIsotope.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -449,7 +521,8 @@ SolutionIsotope.o: ../SolutionIsotope.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../SolutionIsotope.h ../phqalloc.h + ../global_structures.h ../NA.h ../SolutionIsotope.h ../phqalloc.h \ + ../Dictionary.h SSassemblage.o: ../SSassemblage.cxx ../common/Utils.h \ ../common/phrqtype.h ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ @@ -459,7 +532,7 @@ SSassemblage.o: ../SSassemblage.cxx ../common/Utils.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../phqalloc.h + ../phqalloc.h ../Dictionary.h SScomp.o: ../SScomp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -468,7 +541,7 @@ SScomp.o: ../SScomp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../SScomp.h ../phqalloc.h + ../global_structures.h ../NA.h ../SScomp.h ../phqalloc.h ../Dictionary.h SS.o: ../SS.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ @@ -477,7 +550,7 @@ SS.o: ../SS.cxx ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ ../global_structures.h ../NA.h ../common/Utils.h ../common/phrqtype.h \ - ../SS.h ../SScomp.h ../phqalloc.h + ../SS.h ../SScomp.h ../Dictionary.h ../phqalloc.h StorageBin.o: ../StorageBin.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -500,7 +573,7 @@ SurfaceCharge.o: ../SurfaceCharge.cxx ../common/Utils.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h + ../global_structures.h ../NA.h ../phqalloc.h ../Dictionary.h SurfaceComp.o: ../SurfaceComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -509,7 +582,7 @@ SurfaceComp.o: ../SurfaceComp.cxx ../common/Utils.h ../common/phrqtype.h \ ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h ../phqalloc.h + ../global_structures.h ../NA.h ../phqalloc.h ../Dictionary.h Surface.o: ../Surface.cxx ../common/Utils.h ../common/phrqtype.h \ ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ @@ -582,11 +655,11 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../common/phrqtype.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ - ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ - ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ - ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ - ../cxxKinetics.h ../KineticsComp.h + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Parallelizer.h \ + ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ + ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ + ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h CurveObject.o: ../CurveObject.cpp cvdense.o: ../cvdense.cpp ../cvdense.h ../cvode.h ../sundialstypes.h \ ../common/phrqtype.h ../nvector.h ../dense.h ../smalldense.h \ @@ -608,6 +681,7 @@ cvode.o: ../cvode.cpp ../nvector_serial.h ../nvector.h ../sundialstypes.h \ ../global_structures.h ../NA.h ../phqalloc.h dense.o: ../dense.cpp ../sundialstypes.h ../common/phrqtype.h \ ../sundialsmath.h ../dense.h ../smalldense.h +Dictionary.o: ../Dictionary.cpp ../Dictionary.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h \ ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/PHRQ_io.h @@ -708,6 +782,7 @@ nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h \ ../common/phrqtype.h nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.h \ ../sundialstypes.h ../common/phrqtype.h ../sundialsmath.h +Parallelizer.o: ../Parallelizer.cpp parse.o: ../parse.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ @@ -943,15 +1018,147 @@ PHRQ_base.o: ../common/PHRQ_base.cxx ../common/PHRQ_base.h \ Utils.o: ../common/Utils.cxx ../common/Utils.h ../common/phrqtype.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h +PhreeqcRM.o: ../PhreeqcRM/PhreeqcRM.cpp ../PhreeqcRM/PhreeqcRM.h \ + ../NameDouble.h ../common/Parser.h ../common/PHRQ_base.h \ + ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/phrqtype.h \ + ../PhreeqcRM/IrmResult.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../StorageBin.h ../System.h \ + ../NameDouble.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../System.h ../cxxMix.h \ + ../NumKeyword.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h ../global_structures.h ../Surface.h ../SurfaceComp.h \ + ../SurfaceCharge.h ../NA.h ../Exchange.h ../ExchComp.h ../Surface.h \ + ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ + ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../GasPhase.h \ + ../GasComp.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx ../Phreeqc.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../SelectedOutput.h \ + ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h +RM_interface_C.o: ../PhreeqcRM/RM_interface_C.cpp \ + ../PhreeqcRM/PhreeqcRM.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ + ../common/phrqtype.h ../PhreeqcRM/IrmResult.h \ + ../PhreeqcRM/RM_interface_C.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ + ../StorageBin.h ../System.h ../NameDouble.h ../common/PHRQ_io.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h +RM_interface_F.o: ../PhreeqcRM/RM_interface_F.cpp \ + ../PhreeqcRM/PhreeqcRM.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ + ../common/phrqtype.h ../PhreeqcRM/IrmResult.h \ + ../PhreeqcRM/RM_interface_F.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ + ../StorageBin.h ../System.h ../NameDouble.h ../common/PHRQ_io.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h ../Phreeqc.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ + ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ + ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ + ../global_structures.h ../NA.h +IPhreeqcPhastLib.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.cpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ + ../StorageBin.h ../System.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../common/PHRQ_io.h ../common/phrqtype.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h +IPhreeqcPhast.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.cxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ + ../StorageBin.h ../System.h ../NameDouble.h ../common/Parser.h \ + ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ + ../common/phrqtype.h ../common/PHRQ_io.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h ../Phreeqc.h ../cvdense.h \ + ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ + ../runner.h ../StorageBinList.h ../dumper.h ../SelectedOutput.h \ + ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ + ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../global_structures.h \ + ../NA.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ + ../ISolutionComp.h ../GasPhase.h ../GasComp.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx +CSelectedOutput.o: \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.cpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Debug.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h +fwrap1.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap1.cpp +fwrap2.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap2.cpp +fwrap3.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap3.cpp +fwrap4.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap4.cpp +fwrap5.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap5.cpp +fwrap6.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap6.cpp +fwrap7.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap7.cpp +fwrap8.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap8.cpp +fwrap.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap.cpp +IPhreeqc.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.cpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h ../common/PHRQ_io.h \ + ../PhreeqcKeywords/Keywords.h ../Phreeqc.h ../common/phrqtype.h \ + ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ + ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ + ../dumper.h ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h \ + ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ + ../NameDouble.h ../common/Parser.h ../common/PHRQ_base.h \ + ../common/PHRQ_io.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/thread.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Version.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Debug.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/ErrorReporter.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx ../SelectedOutput.h \ + ../dumper.h +IPhreeqc_interface_F.o: \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc_interface_F.cpp \ + ../common/phrqtype.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc_interface_F.h +IPhreeqcLib.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcLib.cpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ + ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/thread.h +pp_sys.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/pp_sys.cpp +Var.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.c \ + ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h # ----------------------------------------------------------------------------- clean: - rm -rf Class_release Class_debug Class_release_64 Class_debug_64 + rm -rf release debug release_openmp debug_openmp release_mpi debug_mpi dependencies: - mkdir -p $(CLASS_DEBUG_DIR) - cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx + mkdir -p $(DEBUG_DIR) + cd $(DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx \ + -I../PhreeqcRM ../PhreeqcRM/*.cpp \ + -I../PhreeqcRM/IPhreeqcPhast ../PhreeqcRM/IPhreeqcPhast/*.cpp ../PhreeqcRM/IPhreeqcPhast/*.cxx \ + -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.cpp ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.c tester: cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/NameDouble.cxx b/NameDouble.cxx index c0bbc4c2..5780cfc8 100644 --- a/NameDouble.cxx +++ b/NameDouble.cxx @@ -12,6 +12,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "NameDouble.h" +#include "Dictionary.h" //#include "Dictionary.h" #include "phqalloc.h" #include "ISolutionComp.h" @@ -597,4 +598,31 @@ cxxNameDouble::sort_second(void) return myvec; } - +void +cxxNameDouble::Serialize(Dictionary &dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back((int) (*this).size()); + for (const_iterator it = (*this).begin(); it != (*this).end(); it++) + { + int n = dictionary.Find(it->first); + ints.push_back(n); + doubles.push_back(it->second); + } +} +void +cxxNameDouble::Deserialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles, int &ii, int &dd) +{ + this->clear(); + int count = ints[ii++]; + for (int j = 0; j < count; j++) + { + int n = ints[ii++]; + assert(n >= 0); + std::string str = dictionary.GetWords()[n]; + if (str.size() != 0) + { + (*this)[str] = doubles[dd++]; + } + } +} diff --git a/NameDouble.h b/NameDouble.h index 0e833d33..7df7e53b 100644 --- a/NameDouble.h +++ b/NameDouble.h @@ -15,6 +15,7 @@ class Phreeqc; #include "Parser.h" #include "phrqtype.h" +class Dictionary; class cxxISolutionComp; class IPQ_DLL_EXPORT cxxNameDouble:public @@ -60,6 +61,8 @@ class IPQ_DLL_EXPORT cxxNameDouble:public { (*this)[str] = d; } + void Serialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles); + void Deserialize(Dictionary &dictionary, std::vector &ints, std::vector &doubles, int &ii, int &dd); enum ND_TYPE type; diff --git a/PPassemblage.cxx b/PPassemblage.cxx index df8e5ba9..aed9983b 100644 --- a/PPassemblage.cxx +++ b/PPassemblage.cxx @@ -321,7 +321,49 @@ Find(const std::string name_in) } return comp; } +/* ---------------------------------------------------------------------- */ +void +cxxPPassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + ints.push_back(this->n_user); + ints.push_back(this->new_def ? 1 : 0); + ints.push_back((int) this->pp_assemblage_comps.size()); + for (std::map < std::string, cxxPPassemblageComp >::iterator it = + this->pp_assemblage_comps.begin(); it != this->pp_assemblage_comps.end(); + it++) + { + (*it).second.Serialize(dictionary, ints, doubles); + } + this->eltList.Serialize(dictionary, ints, doubles); + this->assemblage_totals.Serialize(dictionary, ints, doubles); +} +/* ---------------------------------------------------------------------- */ +void +cxxPPassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + /* int n_user; */ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->new_def = (ints[ii++] != 0); + int count = ints[ii++]; + this->pp_assemblage_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxPPassemblageComp ppc; + ppc.Deserialize(dictionary, ints, doubles, ii, dd); + std::string str(ppc.Get_name()); + this->pp_assemblage_comps[str] = ppc; + } + this->eltList.Deserialize(dictionary, ints, doubles, ii, dd); + this->assemblage_totals.Deserialize(dictionary, ints, doubles, ii, dd); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("eltlist"), // 0 std::vector< std::string >::value_type("component"), // 1 diff --git a/PPassemblage.h b/PPassemblage.h index 7fadd9a3..5b735ad3 100644 --- a/PPassemblage.h +++ b/PPassemblage.h @@ -51,6 +51,8 @@ class cxxPPassemblage:public cxxNumKeyword cxxPPassemblageComp *Find(const std::string name); 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); protected: void add(const cxxPPassemblage & addee, LDBLE extensive); diff --git a/PPassemblageComp.cxx b/PPassemblageComp.cxx index 0ab0f026..ea35b2b6 100644 --- a/PPassemblageComp.cxx +++ b/PPassemblageComp.cxx @@ -10,7 +10,7 @@ #include "Utils.h" // define first #include "Phreeqc.h" #include "PPassemblageComp.h" -//#include "Dictionary.h" +#include "Dictionary.h" #include "phqalloc.h" ////////////////////////////////////////////////////////////////////// @@ -383,6 +383,40 @@ cxxPPassemblageComp::multiply(LDBLE extensive) this->delta *= extensive; this->initial_moles *= extensive; } +void +cxxPPassemblageComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->name)); + ints.push_back(dictionary.Find(this->add_formula)); + doubles.push_back(this->si); + doubles.push_back(this->si_org); + doubles.push_back(this->moles); + doubles.push_back(this->delta); + doubles.push_back(this->initial_moles); + ints.push_back( this->force_equality ? 1 : 0); + ints.push_back(this->dissolve_only ? 1 : 0); + ints.push_back(this->precipitate_only ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxPPassemblageComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->add_formula = dictionary.GetWords()[ints[ii++]]; + this->si = doubles[dd++]; + this->si_org = doubles[dd++]; + this->moles = doubles[dd++]; + this->delta = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->force_equality = (ints[ii++] != 0); + this->dissolve_only = (ints[ii++] != 0); + this->precipitate_only = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("add_formula"), // 1 diff --git a/PPassemblageComp.h b/PPassemblageComp.h index fa01a0c0..318707c1 100644 --- a/PPassemblageComp.h +++ b/PPassemblageComp.h @@ -60,6 +60,8 @@ class cxxPPassemblageComp: public PHRQ_base void add(const cxxPPassemblageComp & comp, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: std::string name; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 14096e91..9bd9ba5e 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -438,6 +438,7 @@ void Phreeqc::init(void) * Transport data *---------------------------------------------------------------------- */ count_cells = 1; + cell_data_max_cells = count_cells; count_shifts = 1; ishift = 1; bcon_first = bcon_last = 3; @@ -714,10 +715,11 @@ void Phreeqc::init(void) #ifdef USE_LONG_DOUBLE /* from float.h, sets tolerance for cl1 routine */ ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); +#elif WIN32 +// appt: + ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); #else ineq_tol = pow((double) 10, (double) -DBL_DIG); -// appt: - //ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); #endif convergence_tolerance = 1e-8; step_size = 100.; @@ -1341,6 +1343,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) * Transport data *---------------------------------------------------------------------- */ count_cells = pSrc->count_cells; + cell_data_max_cells = pSrc->cell_data_max_cells; count_shifts = pSrc->count_shifts; ishift = pSrc->ishift; bcon_first = pSrc->bcon_first; @@ -2529,4 +2532,4 @@ int Phreeqc::next_user_number(Keywords::KEYWORDS key) assert(false); return -999; } -} +} \ No newline at end of file diff --git a/Phreeqc.h b/Phreeqc.h index 1833cc52..16f2f4a6 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1149,6 +1149,19 @@ public: size_t list_components(std::list &list_c); 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;} + + + std::map & Get_Rxn_solution_map() {return this->Rxn_solution_map;} + std::map & Get_Rxn_exchange_map() {return this->Rxn_exchange_map;} + std::map & Get_Rxn_gas_phase_map() {return this->Rxn_gas_phase_map;} + std::map & Get_Rxn_kinetics_map() {return this->Rxn_kinetics_map;} + std::map & Get_Rxn_pp_assemblage_map() {return this->Rxn_pp_assemblage_map;} + std::map & Get_Rxn_ss_assemblage_map() {return this->Rxn_ss_assemblage_map;} + std::map & Get_Rxn_surface_map() {return this->Rxn_surface_map;} + std::map & Get_Rxn_temperature_map() {return this->Rxn_temperature_map;} + std::map & Get_Rxn_pressure_map() {return this->Rxn_pressure_map;} + + protected: void init(void); @@ -1370,6 +1383,7 @@ protected: * Transport data *---------------------------------------------------------------------- */ int count_cells; + int cell_data_max_cells; int count_shifts; int ishift; int bcon_first; @@ -1765,6 +1779,7 @@ protected: /* input.cpp ------------------------------- */ int check_line_return; int reading_db; + std::ostringstream definitions_for_parallelizer; /* integrate.cpp ------------------------------- */ LDBLE midpoint_sv; @@ -1963,6 +1978,7 @@ protected: friend class IPhreeqcMMS; friend class IPhreeqcPhast; friend class PhreeqcRM; + friend class Parallelizer; std::vector keycount; // used to mark keywords that have been read diff --git a/Pressure.cxx b/Pressure.cxx index 82e6735f..03bd30ca 100644 --- a/Pressure.cxx +++ b/Pressure.cxx @@ -399,6 +399,42 @@ Get_count(void) const } return (int) this->pressures.size(); } +void +cxxPressure::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + { + ints.push_back((int) this->pressures.size()); + for (size_t i = 0; i < this->pressures.size(); i++) + { + doubles.push_back(pressures[i]); + } + } + ints.push_back(this->count); + ints.push_back(this->equalIncrements ? 1 : 0); + +} + +void +cxxPressure::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + { + int count = ints[ii++]; + this->pressures.clear(); + for (int i = 0; i < count; i++) + { + this->pressures.push_back(doubles[dd++]); + } + } + this->count = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("pressures"), //0 std::vector< std::string >::value_type("equal_increments"), //1 diff --git a/Pressure.h b/Pressure.h index 7a6b7fd0..377f2039 100644 --- a/Pressure.h +++ b/Pressure.h @@ -8,6 +8,7 @@ #include // std::vector #include "NumKeyword.h" +class Dictionary; class cxxPressure:public cxxNumKeyword { @@ -29,7 +30,9 @@ class cxxPressure:public cxxNumKeyword void Set_count(int i) {count = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} - + 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); + protected: std::vector < LDBLE >pressures; int count; diff --git a/SS.cxx b/SS.cxx index 066bb7b2..2ed2edc6 100644 --- a/SS.cxx +++ b/SS.cxx @@ -10,7 +10,7 @@ #include "Phreeqc.h" #include "Utils.h" // define first #include "SS.h" -//#include "Dictionary.h" +#include "Dictionary.h" #include "phqalloc.h" @@ -532,6 +532,83 @@ cxxSS::Find(const char * comp_name) } return NULL; } +void +cxxSS::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->ag0); + doubles.push_back(this->ag1); + { + ints.push_back((int) ss_comps.size()); + for (size_t i = 0; i < ss_comps.size(); i++) + { + ss_comps[i].Serialize(dictionary, ints, doubles); + } + } + doubles.push_back(this->a0); + doubles.push_back(this->a1); + ints.push_back(this->miscibility ? 1 : 0); + ints.push_back(this->spinodal ? 1 : 0); + doubles.push_back(this->tk); + doubles.push_back(this->xb1); + doubles.push_back(this->xb2); + ints.push_back((int) this->input_case); + { + ints.push_back((int) p.size()); + for (size_t i = 0; i < p.size(); i++) + { + doubles.push_back(p[i]); + } + } + doubles.push_back(this->total_moles); + doubles.push_back(this->dn); + ints.push_back(this->ss_in ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + +} + +void +cxxSS::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->ag0 = doubles[dd++]; + this->ag1 = doubles[dd++]; + { + int count = ints[ii++]; + this->ss_comps.clear(); + for (int i = 0; i < count; i++) + { + cxxSScomp ssc; + ssc.Deserialize(dictionary, ints, doubles, ii, dd); + this->ss_comps.push_back(ssc); + } + } + this->a0 = doubles[dd++]; + this->a1 = doubles[dd++]; + this->miscibility = (ints[ii++] != 0); + this->spinodal = (ints[ii++] != 0); + this->tk = doubles[dd++]; + this->xb1 = doubles[dd++]; + this->xb2 = doubles[dd++]; + this->input_case = (SS_PARAMETER_TYPE) ints[ii++]; + { + int count = ints[ii++]; + this->p.clear(); + for (int i = 0; i < count; i++) + { + p.push_back(doubles[dd++]); + } + } + this->total_moles = doubles[dd++]; + this->dn = doubles[dd++]; + this->ss_in = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("ss_name"), // 0 std::vector< std::string >::value_type("total_moles"), // 1 diff --git a/SS.h b/SS.h index 67277148..d5e5a30d 100644 --- a/SS.h +++ b/SS.h @@ -98,6 +98,9 @@ class cxxSS: public PHRQ_base std::vector & Get_p(void) {return this->p;} const std::vector & Get_p(void)const {return this->p;} void Set_p(const std::vector & t) {this->p = t;} + 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); + protected: std::string name; // candidates for SOLID_SOLUTION_MODIFY diff --git a/SSassemblage.cxx b/SSassemblage.cxx index 4ef7b77c..471127bb 100644 --- a/SSassemblage.cxx +++ b/SSassemblage.cxx @@ -14,6 +14,7 @@ #include "SS.h" #include "cxxMix.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -287,6 +288,51 @@ Find(const std::string &s) return &(it->second); return NULL; } +void +cxxSSassemblage::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + /* int n_user; */ + ints.push_back(this->n_user); + { + ints.push_back((int) this->SSs.size()); + std::map < std::string, cxxSS >::iterator it; + for (it = this->SSs.begin(); it != this->SSs.end(); it++) + { + (*it).second.Serialize(dictionary, ints, doubles); + } + } + ints.push_back(this->new_def ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxSSassemblage::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + { + int count = ints[ii++]; + this->SSs.clear(); + for (int n = 0; n < count; n++) + { + cxxSS ssc; + ssc.Deserialize(dictionary, ints, doubles, ii, dd); + std::string str(ssc.Get_name()); + this->SSs[str] = ssc; + } + } + this->new_def = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + +} + + + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("solid_solution"), // 0 std::vector< std::string >::value_type("ssassemblage_totals"), // 1 diff --git a/SSassemblage.h b/SSassemblage.h index 909f0f0f..d69a6962 100644 --- a/SSassemblage.h +++ b/SSassemblage.h @@ -43,7 +43,9 @@ public: std::vector Vectorize(void); void add(const cxxSSassemblage & addee, LDBLE extensive); cxxSS *Find(const std::string &s); - + 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); + protected: // SOLID_SOLUTION_MODIFY candidate std::map < std::string, cxxSS > SSs; diff --git a/SScomp.cxx b/SScomp.cxx index 6088bf47..a750a627 100644 --- a/SScomp.cxx +++ b/SScomp.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SScomp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -277,6 +278,44 @@ cxxSScomp::multiply(LDBLE extensive) this->delta *= extensive; this->initial_moles *= extensive; } +void +cxxSScomp::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->moles); + doubles.push_back(this->initial_moles); + doubles.push_back(this->init_moles); + doubles.push_back(this->delta); + doubles.push_back(this->fraction_x); + doubles.push_back(this->log10_lambda); + doubles.push_back(this->log10_fraction_x); + doubles.push_back(this->dn); + doubles.push_back(this->dnc); + doubles.push_back(this->dnb); + +} + +void +cxxSScomp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + + this->name = dictionary.GetWords()[ints[ii++]]; + this->moles = doubles[dd++]; + this->initial_moles = doubles[dd++]; + this->init_moles = doubles[dd++]; + this->delta = doubles[dd++]; + this->fraction_x = doubles[dd++]; + this->log10_lambda = doubles[dd++]; + this->log10_fraction_x = doubles[dd++]; + this->dn = doubles[dd++]; + this->dnc = doubles[dd++]; + this->dnb = doubles[dd++]; + +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("initial_moles"), // 1 diff --git a/SScomp.h b/SScomp.h index 7aaaa2fd..1afa66e5 100644 --- a/SScomp.h +++ b/SScomp.h @@ -44,7 +44,9 @@ class cxxSScomp: public PHRQ_base void Set_dnb(LDBLE t) {this->dnb = t;} void multiply(LDBLE extensive); - + 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); + protected: std::string name; // SOLID_SOLUTION_MODIFY candidate identifier diff --git a/Solution.cxx b/Solution.cxx index 0eeeaaae..b6910e36 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -13,6 +13,7 @@ #include "Solution.h" #include "cxxMix.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -1009,10 +1010,10 @@ cxxSolution::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser.error_msg("Expected numeric value for potential (V).", PHRQ_io::OT_CONTINUE); - } + } opt_save = CParser::OPT_DEFAULT; break; - + } if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break; @@ -1540,6 +1541,159 @@ cxxSolution::Multiply_isotopes(LDBLE extensive) it->second.Set_total(total); } } + +/* ---------------------------------------------------------------------- */ +void +cxxSolution::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ +/* + * Make list of list of ints and doubles from solution structure + * This list is not the complete structure, but only enough + * for batch-reaction, advection, and transport calculations + */ + ints.push_back(this->n_user); + ints.push_back(this->new_def ? 1 : 0); + doubles.push_back(this->patm); + doubles.push_back(this->potV); + doubles.push_back(this->tc); + doubles.push_back(this->ph); + doubles.push_back(this->pe); + doubles.push_back(this->mu); + doubles.push_back(this->ah2o); + doubles.push_back(this->total_h); + doubles.push_back(this->total_o); + doubles.push_back(this->cb); + doubles.push_back(this->mass_water); + doubles.push_back(this->density); + doubles.push_back(this->soln_vol); + doubles.push_back(this->total_alkalinity); +/* + * struct conc *totals; +*/ + this->totals.Serialize(dictionary, ints, doubles); +/* + * struct master_activity *master_activity; + */ + this->master_activity.Serialize(dictionary, ints, doubles); +/* + * struct master_activity *species_gamma + */ + this->species_gamma.Serialize(dictionary, ints, doubles); +/* + * isotopes + */ + ints.push_back((int) isotopes.size()); + { + std::map < std::string, cxxSolutionIsotope >::iterator it; + for (it = isotopes.begin(); it != isotopes.end(); it++) + { + ints.push_back(dictionary.Find(it->first)); + it->second.Serialize(dictionary, ints, doubles); + } + } +/* + * species_map + */ + ints.push_back((int) species_map.size()); + { + std::map < int, double >::iterator it; + for (it = species_map.begin(); it != species_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +/* + * log_gamma_map + */ + ints.push_back((int) log_gamma_map.size()); + { + std::map < int, double >::iterator it; + for (it = log_gamma_map.begin(); it != log_gamma_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +} + +/* ---------------------------------------------------------------------- */ +void +cxxSolution::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + this->new_def = (ints[ii++] != 0); + this->patm = doubles[dd++]; + this->potV = doubles[dd++]; + this->tc = doubles[dd++]; + this->ph = doubles[dd++]; + this->pe = doubles[dd++]; + this->mu = doubles[dd++]; + this->ah2o = doubles[dd++]; + this->total_h = doubles[dd++]; + this->total_o = doubles[dd++]; + this->cb = doubles[dd++]; + this->mass_water = doubles[dd++]; + this->density = doubles[dd++]; + this->soln_vol = doubles[dd++]; + this->total_alkalinity = doubles[dd++]; +/* + * struct conc *totals; +*/ + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * struct master_activity *master_activity; + */ + this->master_activity.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * struct master_activity *species_gamma; + */ + this->species_gamma.Deserialize(dictionary, ints, doubles, ii, dd); +/* + * isotopes + */ + { + isotopes.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + std::string str = dictionary.GetWords()[ints[ii++]]; + cxxSolutionIsotope iso; + iso.Deserialize(dictionary, ints, doubles, ii, dd); + isotopes[str] = iso; + } + } +/* + * species_map + */ + { + species_map.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + species_map[ints[ii++]] = doubles[dd++]; + } + } +/* + * log_gamma_map + */ + { + log_gamma_map.clear(); + int n = ints[ii++]; + for (int i = 0; i < n; i++) + { + log_gamma_map[ints[ii++]] = doubles[dd++]; + } + } +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("totals"), // 0 std::vector< std::string >::value_type("activities"), // 1 diff --git a/Solution.h b/Solution.h index 1fc63265..1ab18654 100644 --- a/Solution.h +++ b/Solution.h @@ -113,6 +113,8 @@ class cxxSolution:public cxxNumKeyword void Update(const cxxNameDouble &nd); void Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble &nd); void Update_activities(const cxxNameDouble &original_tot); + 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); protected: bool new_def; diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index 4ce3dc95..ecf72c4c 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -8,7 +8,7 @@ #include "Phreeqc.h" #include "SolutionIsotope.h" #include "phqalloc.h" - +#include "Dictionary.h" cxxSolutionIsotope::cxxSolutionIsotope(PHRQ_io *io) : @@ -285,6 +285,33 @@ cxxSolutionIsotope::multiply(LDBLE extensive) { this->total *= extensive; } +void +cxxSolutionIsotope::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + doubles.push_back(this->isotope_number); + ints.push_back(dictionary.Find(this->elt_name)); + ints.push_back(dictionary.Find(this->isotope_name)); + doubles.push_back(this->total); + doubles.push_back(this->ratio); + doubles.push_back(this->ratio_uncertainty); + ints.push_back(this->ratio_uncertainty_defined ? 1 : 0); + doubles.push_back(this->x_ratio_uncertainty); + doubles.push_back(this->coef); +} +void +cxxSolutionIsotope::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->isotope_number = doubles[dd++]; + this->elt_name = dictionary.GetWords()[ints[ii++]]; + this->isotope_name = dictionary.GetWords()[ints[ii++]]; + this->total = doubles[dd++]; + this->ratio = doubles[dd++]; + this->ratio_uncertainty = doubles[dd++]; + this->ratio_uncertainty_defined = (ints[ii++] != 0); + this->x_ratio_uncertainty = doubles[dd++]; + this->coef = doubles[dd++]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("isotope_number"), // 0 std::vector< std::string >::value_type("elt_name"), // 1 diff --git a/SolutionIsotope.h b/SolutionIsotope.h index ff83b876..231fe0ab 100644 --- a/SolutionIsotope.h +++ b/SolutionIsotope.h @@ -5,6 +5,7 @@ #include // std::string #include // std::list #include "Parser.h" +class Dictionary; class cxxSolutionIsotope: public PHRQ_base { @@ -66,6 +67,8 @@ class cxxSolutionIsotope: public PHRQ_base void add(const cxxSolutionIsotope & isotope_ptr, LDBLE intensive, LDBLE extensive); void multiply(LDBLE extensive); + 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); protected: LDBLE isotope_number; diff --git a/Surface.cxx b/Surface.cxx index 359ba8ac..b2e7ef2f 100644 --- a/Surface.cxx +++ b/Surface.cxx @@ -745,6 +745,90 @@ Sort_comps(void) } } } +/* ---------------------------------------------------------------------- */ +void +cxxSurface::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +/* ---------------------------------------------------------------------- */ +{ + + ints.push_back(this->n_user); + ints.push_back((int) this->surface_comps.size()); + { + for (size_t i = 0; i < this->surface_comps.size(); i++) + { + surface_comps[i].Serialize(dictionary, ints, doubles); + } + } + ints.push_back((int) this->surface_charges.size()); + { + for (size_t i = 0; i < this->surface_charges.size(); i++) + { + surface_charges[i].Serialize(dictionary, ints, doubles); + } + } + ints.push_back(this->new_def ? 1 : 0); + ints.push_back((int) this->type); + ints.push_back((int) this->dl_type); + ints.push_back((int) this->sites_units); + ints.push_back(this->only_counter_ions ? 1 : 0); + doubles.push_back(this->thickness); + doubles.push_back(this->debye_lengths); + doubles.push_back(this->DDL_viscosity); + doubles.push_back(this->DDL_limit); + ints.push_back(this->transport ? 1 : 0); + this->totals.Serialize(dictionary, ints, doubles); + ints.push_back(this->solution_equilibria ? 1 : 0); + ints.push_back((int) this->n_solution); + +} + +/* ---------------------------------------------------------------------- */ +void +cxxSurface::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +/* ---------------------------------------------------------------------- */ +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + { + int count = ints[ii++]; + this->surface_comps.clear(); + for (int n = 0; n < count; n++) + { + cxxSurfaceComp sc; + sc.Deserialize(dictionary, ints, doubles, ii, dd); + this->surface_comps.push_back(sc); + } + } + { + int count = ints[ii++]; + this->surface_charges.clear(); + for (int n = 0; n < count; n++) + { + cxxSurfaceCharge sc; + sc.Deserialize(dictionary, ints, doubles, ii, dd); + this->surface_charges.push_back(sc); + } + } + this->new_def = (ints[ii++] != 0); + this->type = (SURFACE_TYPE) ints[ii++]; + this->dl_type = (DIFFUSE_LAYER_TYPE) ints[ii++]; + this->sites_units = (SITES_UNITS) ints[ii++]; + this->only_counter_ions = (ints[ii++] != 0); + this->thickness = doubles[dd++]; + this->debye_lengths = doubles[dd++]; + this->DDL_viscosity = doubles[dd++]; + this->DDL_limit = doubles[dd++]; + this->transport = (ints[ii++] != 0); + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->solution_equilibria = (ints[ii++] != 0); + this->n_solution = ints[ii++]; + +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("diffuse_layer"), // 0 std::vector< std::string >::value_type("edl"), // 1 diff --git a/Surface.h b/Surface.h index a1edb99c..4a197453 100644 --- a/Surface.h +++ b/Surface.h @@ -73,7 +73,9 @@ public: void Set_solution_equilibria(bool tf) {solution_equilibria = tf;} int Get_n_solution(void)const {return n_solution;} void Set_n_solution(int i) {n_solution = i;} - + 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); + protected: std::vector < cxxSurfaceComp > surface_comps; std::vector < cxxSurfaceCharge > surface_charges; diff --git a/SurfaceCharge.cxx b/SurfaceCharge.cxx index 6f52a563..6ee4ff1c 100644 --- a/SurfaceCharge.cxx +++ b/SurfaceCharge.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SurfaceCharge.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// @@ -460,6 +461,102 @@ cxxSurfaceCharge::multiply(LDBLE extensive) this->mass_water *= extensive; this->diffuse_layer_totals.multiply(extensive); } +void +cxxSurfaceCharge::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + + ints.push_back(dictionary.Find(this->name)); + doubles.push_back(this->specific_area); + doubles.push_back(this->grams); + doubles.push_back(this->charge_balance); + doubles.push_back(this->mass_water); + doubles.push_back(this->la_psi); + doubles.push_back(this->capacitance[0]); + doubles.push_back(this->capacitance[1]); + this->diffuse_layer_totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->sigma0); + doubles.push_back(this->sigma1); + doubles.push_back(this->sigma2); + doubles.push_back(this->sigmaddl); + ints.push_back((int) this->g_map.size()); + { + std::map::iterator it; + for (it = this->g_map.begin(); it != this->g_map.end(); it++) + { + doubles.push_back(it->first); + it->second.Serialize(dictionary, ints, doubles); + } + } + ints.push_back((int) this->dl_species_map.size()); + { + std::map::iterator it; + for (it = this->dl_species_map.begin(); it != this->dl_species_map.end(); it++) + { + ints.push_back(it->first); + doubles.push_back(it->second); + } + } +} + +void +cxxSurfaceCharge::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->name = dictionary.GetWords()[ints[ii++]]; + this->specific_area = doubles[dd++]; + this->grams = doubles[dd++]; + this->charge_balance = doubles[dd++]; + this->mass_water = doubles[dd++]; + this->la_psi = doubles[dd++]; + this->capacitance[0] = doubles[dd++]; + this->capacitance[1] = doubles[dd++]; + this->diffuse_layer_totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->sigma0 = doubles[dd++]; + this->sigma1 = doubles[dd++]; + this->sigma2 = doubles[dd++]; + this->sigmaddl = doubles[dd++]; + { + this->g_map.clear(); + int count = ints[ii++]; + for (int i = 0; i < count; i++) + { + double d = doubles[dd++]; + cxxSurfDL sdl; + sdl.Deserialize(dictionary, ints, doubles, ii, dd); + this->g_map[d] = sdl; + } + } + { + this->dl_species_map.clear(); + int count = ints[ii++]; + for (int i = 0; i < count; i++) + { + int j = ints[ii++]; + double d = doubles[dd++]; + dl_species_map[j] = d; + } + } + + +} +void +cxxSurfDL::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + doubles.push_back(this->g); + doubles.push_back(this->dg); + doubles.push_back(this->psi_to_z); +} + +void +cxxSurfDL::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->g = doubles[dd++]; + this->dg = doubles[dd++]; + this->psi_to_z = doubles[dd++]; +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("name"), // 0 std::vector< std::string >::value_type("specific_area"), // 1 diff --git a/SurfaceCharge.h b/SurfaceCharge.h index a3a46265..7d284fbc 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -32,8 +32,7 @@ public: LDBLE *Get_dx_moles_address(void) {return &dx_moles;} LDBLE *Get_dh2o_moles_address(void) {return &dh2o_moles;} LDBLE *Get_drelated_moles_address(void) {return &drelated_moles;} - - + protected: LDBLE g_moles; LDBLE dg_g_moles; /* g_moles*dgterm */ @@ -54,6 +53,9 @@ public: void Set_dg(LDBLE t) {dg = t;} LDBLE Get_psi_to_z(void) const {return psi_to_z;} void Set_psi_to_z(LDBLE t) {psi_to_z = t;} + 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); + protected: LDBLE g; LDBLE dg; @@ -104,6 +106,8 @@ public: std::map &Get_g_map(void) {return g_map;} void Set_g_map(std::map & t) {g_map = t;} std::map & Get_dl_species_map(void) {return this->dl_species_map;} + 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); protected: std::string name; diff --git a/SurfaceComp.cxx b/SurfaceComp.cxx index bfb9f15a..5a23eb16 100644 --- a/SurfaceComp.cxx +++ b/SurfaceComp.cxx @@ -11,6 +11,7 @@ #include "Phreeqc.h" #include "SurfaceComp.h" #include "phqalloc.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -445,6 +446,40 @@ cxxSurfaceComp::multiply(LDBLE extensive) this->charge_balance *= extensive; } +void +cxxSurfaceComp::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(dictionary.Find(this->formula)); + doubles.push_back(this->formula_z); + doubles.push_back(this->moles); + this->totals.Serialize(dictionary, ints, doubles); + doubles.push_back(this->la); + ints.push_back(dictionary.Find(this->charge_name)); + doubles.push_back(this->charge_balance); + ints.push_back(dictionary.Find(this->phase_name)); + doubles.push_back(this->phase_proportion); + ints.push_back(dictionary.Find(this->rate_name)); + doubles.push_back(this->Dw); + ints.push_back(dictionary.Find(this->master_element)); +} + +void +cxxSurfaceComp::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd) +{ + this->formula = dictionary.GetWords()[ints[ii++]]; + this->formula_z = doubles[dd++]; + this->moles = doubles[dd++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); + this->la = doubles[dd++]; + this->charge_name = dictionary.GetWords()[ints[ii++]]; + this->charge_balance = doubles[dd++]; + this->phase_name = dictionary.GetWords()[ints[ii++]]; + this->phase_proportion = doubles[dd++]; + this->rate_name = dictionary.GetWords()[ints[ii++]]; + this->Dw = doubles[dd++]; + this->master_element = dictionary.GetWords()[ints[ii++]]; +} + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("formula"), // 0 std::vector< std::string >::value_type("moles"), // 1 diff --git a/SurfaceComp.h b/SurfaceComp.h index 6bd14eb7..d3708acf 100644 --- a/SurfaceComp.h +++ b/SurfaceComp.h @@ -46,7 +46,9 @@ public: void Set_Dw(LDBLE d) {this->Dw = d;} const std::string &Get_master_element() const {return this->master_element;} void Set_master_element(const char * f) {this->master_element = f ? f : "";} - + 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); + protected: std::string formula; LDBLE formula_z; diff --git a/Temperature.cxx b/Temperature.cxx index 6b4102cb..a1df2da2 100644 --- a/Temperature.cxx +++ b/Temperature.cxx @@ -410,6 +410,40 @@ Get_countTemps(void) const } return (int) this->temps.size(); } +void +cxxTemperature::Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + { + ints.push_back((int) this->temps.size()); + for (size_t i = 0; i < this->temps.size(); i++) + { + doubles.push_back(temps[i]); + } + } + ints.push_back(this->countTemps); + ints.push_back(this->equalIncrements ? 1 : 0); +} + +void +cxxTemperature::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + { + int count = ints[ii++]; + this->temps.clear(); + for (int i = 0; i < count; i++) + { + this->temps.push_back(doubles[dd++]); + } + } + this->countTemps = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); +} const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("temps"), //0 std::vector< std::string >::value_type("equal_increments"), //1 diff --git a/Temperature.h b/Temperature.h index ed7e90d9..6af70b38 100644 --- a/Temperature.h +++ b/Temperature.h @@ -29,7 +29,9 @@ class cxxTemperature:public cxxNumKeyword void Set_countTemps(int i) {countTemps = i;} bool Get_equalIncrements(void) const {return equalIncrements;} void Set_equalIncrements(bool tf) {equalIncrements = tf;} - + 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); + protected: std::vector < LDBLE >temps; int countTemps; diff --git a/basicsubs.cpp b/basicsubs.cpp index c8f729eb..4d803dfd 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -218,6 +218,7 @@ calc_SC(void) SC_T = SC_298 * (viscos_298 / viscos_T) */ SC *= viscos_0_25 / viscos; + return (SC); # endif for (i = 0; i < count_s_x; i++) @@ -248,7 +249,6 @@ calc_SC(void) Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: SC_T = SC_298 * (viscos_298 / viscos_T) */ - viscosity(); SC *= viscos_0_25 / viscos; return (SC); diff --git a/class_main.cpp b/class_main.cpp index 213dcbc4..586240c4 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,5 +1,5 @@ #include "Phreeqc.h" - +#include "Parallelizer.h" #include "NameDouble.h" #include "Solution.h" #include "Reaction.h" @@ -11,6 +11,10 @@ #include "cxxKinetics.h" //#include //#include +#if defined(USE_MPI) +#include +int worker_tasks(int *task_number, void * cookie); +#endif /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ @@ -68,9 +72,73 @@ unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. //MCW_EM is defined in float.h. //Restore the original value when done: //_controlfp(cwOriginal, MCW_EM); +#endif +#if defined(USE_MPI) + int mpi_tasks, mpi_myself; + if (MPI_Init(&argc, &argv) != MPI_SUCCESS) + { + return EXIT_FAILURE; + } + + if (MPI_Comm_size(MPI_COMM_WORLD, &mpi_tasks) != MPI_SUCCESS) + { + return EXIT_FAILURE; + } + + if (MPI_Comm_rank(MPI_COMM_WORLD, &mpi_myself) != MPI_SUCCESS) + { + return EXIT_FAILURE; + } + if (mpi_myself > 0) + { + for (;;) + { + //MPI_Status mpi_status; + int task_no; + MPI_Bcast(&task_no, 1, MPI_INT, 0, MPI_COMM_WORLD); + if (task_no > 0) + { + Parallelizer *phreeqcrm_ptr = new Parallelizer(task_no, MPI_COMM_WORLD); + phreeqcrm_ptr->SetMpiWorkerCallbackC(worker_tasks); + phreeqcrm_ptr->SetMpiWorkerCallbackCookie(phreeqcrm_ptr); + phreeqcrm_ptr->MpiWorker(); + delete phreeqcrm_ptr; + //{ + // std::ostringstream os; + // os << "Worker " << mpi_myself << " deleting Parallelizer. " << std::endl; + // std::cerr << os.str(); + //} + } + else + { + break; + } + } + { + std::ostringstream os; + os << "End worker " << mpi_myself << std::endl; + std::cerr << os.str(); + } + MPI_Barrier(MPI_COMM_WORLD); + MPI_Finalize(); + return 0; + } #endif Phreeqc phreeqc_instance; - return phreeqc_instance.main_method(argc, argv); + int return_value = phreeqc_instance.main_method(argc, argv); + +#if defined(USE_MPI) + int task_no = 0; + MPI_Bcast(&task_no, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); + MPI_Finalize(); + { + std::ostringstream os; + os << "End master " << mpi_myself << std::endl; + std::cerr << os.str(); + } +#endif + return return_value; } //#define TEST_COPY #ifdef TEST_COPY @@ -420,6 +488,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, copy_token(token, &ptr, &l); if (strcmp_nocase(token, "database") == 0) { + user_database = (char *) free_check_null(user_database); #ifdef PHREEQ98 user_database = string_duplicate(prefix_database_dir(ptr)); #else @@ -484,6 +553,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, } local_database_file->close(); delete local_database_file; + + user_database = (char *) free_check_null(user_database); + user_database = string_duplicate(token); screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP @@ -498,7 +570,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, /* * local cleanup */ - user_database = (char *) free_check_null(user_database); + //user_database = (char *) free_check_null(user_database); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); @@ -616,6 +688,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, copy_token(token, &ptr, &l); if (strcmp_nocase(token, "database") == 0) { + user_database = (char *) free_check_null(user_database); #ifdef PHREEQ98 user_database = string_duplicate(prefix_database_dir(ptr)); #else @@ -690,6 +763,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * local cleanup */ user_database = (char *) free_check_null(user_database); + user_database = string_duplicate(token); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); @@ -922,3 +996,23 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, return (new_stream); } #endif + +#ifdef USE_MPI +int worker_tasks(int *task_number, void * cookie) +{ + Parallelizer *phreeqcrm_ptr = (Parallelizer *) cookie; + Phreeqc *phreeqc_ptr = phreeqcrm_ptr->GetPhreeqcPtr(); + if (*task_number == 1000) + { + phreeqcrm_ptr->Phreeqc2RM(phreeqc_ptr); + } + else if (*task_number == 1001) + { + phreeqcrm_ptr->RM2Phreeqc(phreeqc_ptr); + } + else + { + } + return 0; +} +#endif diff --git a/cxxKinetics.cxx b/cxxKinetics.cxx index c9fc7dc8..17ad6626 100644 --- a/cxxKinetics.cxx +++ b/cxxKinetics.cxx @@ -13,6 +13,7 @@ #include "cxxMix.h" #include "phqalloc.h" #include "PHRQ_io.h" +#include "Dictionary.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -566,6 +567,66 @@ Current_step(bool incremental_reactions, int reaction_step) const } return kin_time; } +void +cxxKinetics::Serialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles) +{ + ints.push_back(this->n_user); + ints.push_back((int) this->kinetics_comps.size()); + for (size_t i = 0; i < this->kinetics_comps.size(); i++) + { + this->kinetics_comps[i].Serialize(dictionary, ints, doubles); + } + ints.push_back((int) this->steps.size()); + for (size_t i = 0; i < this->steps.size(); i++) + { + doubles.push_back(this->steps[i]); + } + ints.push_back(this->count); + ints.push_back(this->equalIncrements ? 1 : 0); + doubles.push_back(this->step_divide); + ints.push_back(this->rk); + ints.push_back(this->bad_step_max); + ints.push_back(this->use_cvode ? 1 : 0); + ints.push_back(this->cvode_steps); + ints.push_back(this->cvode_order); + this->totals.Serialize(dictionary, ints, doubles); +} + +void +cxxKinetics::Deserialize(Dictionary & dictionary, std::vector < int >&ints, + std::vector < double >&doubles, int &ii, int &dd) +{ + this->n_user = ints[ii++]; + this->n_user_end = this->n_user; + this->description = " "; + + int n = ints[ii++]; + this->kinetics_comps.clear(); + for (int i = 0; i < n; i++) + { + cxxKineticsComp kc; + kc.Deserialize(dictionary, ints, doubles, ii, dd); + this->kinetics_comps.push_back(kc); + } + n = ints[ii++]; + this->steps.clear(); + for (int i = 0; i < n; i++) + { + this->steps.push_back(doubles[dd++]); + } + this->count = ints[ii++]; + this->equalIncrements = (ints[ii++] != 0); + this->step_divide = doubles[dd++]; + this->rk = ints[ii++]; + this->bad_step_max = ints[ii++]; + this->use_cvode = (ints[ii++] != 0); + this->cvode_steps = ints[ii++]; + this->cvode_order = ints[ii++]; + this->totals.Deserialize(dictionary, ints, doubles, ii, dd); +} + + const std::vector< std::string >::value_type temp_vopts[] = { std::vector< std::string >::value_type("step_divide"), // 0 std::vector< std::string >::value_type("rk"), // 1 diff --git a/cxxKinetics.h b/cxxKinetics.h index b7235862..eff885ae 100644 --- a/cxxKinetics.h +++ b/cxxKinetics.h @@ -52,6 +52,8 @@ class cxxKinetics:public cxxNumKeyword int Get_reaction_steps(void) const; cxxKineticsComp * Find(const std::string &str); LDBLE Current_step(const bool incremental_reactions, const int reaction_step) const; + 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); protected: void add(const cxxKinetics & addee, LDBLE extensive); diff --git a/global_structures.h b/global_structures.h index cc934658..10a0278b 100644 --- a/global_structures.h +++ b/global_structures.h @@ -1042,8 +1042,7 @@ struct sol_D struct J_ij { const char *name; - LDBLE tot1, tot2; /* species change in cells i and j */ - int sol_D_number; /* the number of the species in sol_D */ + LDBLE tot1; /* species change in cells i and j */ }; struct M_S { diff --git a/kinetics.cpp b/kinetics.cpp index 8830f696..2fa8f5c3 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1618,6 +1618,7 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, converge = model(); } sum_species(); + viscosity(); return (converge); } diff --git a/mainsubs.cpp b/mainsubs.cpp index 19f5894d..b85eb002 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -44,8 +44,21 @@ initialize(void) /* * Allocate space */ - space((void **) ((void *) &cell_data), INIT, &count_cells + 2, - sizeof(struct cell_data)); + cell_data_max_cells = count_cells + 2; + space((void **) ((void *) &cell_data), INIT, &cell_data_max_cells, + sizeof(struct cell_data)); + for (int i = 0; i < cell_data_max_cells; i++) + { + cell_data[i].length = 1.0; + cell_data[i].mid_cell_x = 1.0; + cell_data[i].disp = 1.0; + cell_data[i].temp = 25.0; + cell_data[i].por = 0.1; + cell_data[i].por_il = 0.01; + cell_data[i].potV = 0; + cell_data[i].punch = FALSE; + cell_data[i].print = FALSE; + } space((void **) ((void *) &elements), INIT, &max_elements, sizeof(struct element *)); diff --git a/read.cpp b/read.cpp index 1367c117..311bbb58 100644 --- a/read.cpp +++ b/read.cpp @@ -256,6 +256,8 @@ read_input(void) #if defined(SWIG_SHARED_OBJ) warning_msg("DATABASE keyword is ignored by IPhreeqc."); #else + + user_database = (char *) free_check_null(user_database); user_database = string_duplicate(ptr); if (string_trim(user_database) == EMPTY) { @@ -427,6 +429,7 @@ read_exchange_species(void) association = TRUE; s_ptr = NULL; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read eqn from file and call parser */ @@ -864,6 +867,7 @@ read_exchange_species(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -1151,6 +1155,7 @@ read_exchange_master_species(void) struct element *elts_ptr; struct species *s_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH]; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; for (;;) { j = check_line("Exchange species equation", FALSE, TRUE, TRUE, TRUE); @@ -1158,6 +1163,7 @@ read_exchange_master_species(void) { break; } + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Get element name with valence, allocate space, store */ @@ -3246,6 +3252,7 @@ read_master_species(void) struct species *s_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH]; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; elts_ptr = NULL; for (;;) { @@ -3254,6 +3261,7 @@ read_master_species(void) { break; } + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Get element name with valence, allocate space, store */ @@ -3819,7 +3827,7 @@ read_phases(void) "vm" /* 15, molar volume, must replace delta_v */ }; int count_opt_list = 16; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = FALSE; /* * Read eqn from file and call parser @@ -4002,6 +4010,7 @@ read_phases(void) */ phase_ptr = NULL; ptr = line; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; copy_token(token, &ptr, &l); /* * Get and parse equation @@ -4090,6 +4099,7 @@ read_phases(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -4739,6 +4749,7 @@ read_selected_output(void) ptr = line; int n_user, n_user_end; char *description; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; read_number_description(ptr, &n_user, &n_user_end, &description); SelectedOutput temp_selected_output; @@ -5107,6 +5118,7 @@ read_selected_output(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) @@ -6002,7 +6014,7 @@ read_species(void) "viscosity" /* 23, b and d parms for viscosity, (b1 + b2 * exp(-b3 * tc)) * c + (d1 * exp(-d2 * tc)) * c ^ d3 */ }; int count_opt_list = 24; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = TRUE; s_ptr = NULL; /* @@ -6497,6 +6509,7 @@ read_species(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -6763,7 +6776,7 @@ read_surface_species(void) "vm" /* 18 */ }; int count_opt_list = 19; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = TRUE; /* * Read eqn from file and call parser @@ -7142,6 +7155,7 @@ read_surface_species(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -7785,6 +7799,7 @@ read_surface_master_species(void) int count_opt_list = 0; opt_save = OPTION_DEFAULT; return_value = UNKNOWN; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; for (;;) { opt = get_option(opt_list, count_opt_list, &next_char); @@ -7875,6 +7890,7 @@ read_surface_master_species(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -9208,6 +9224,7 @@ read_rates(void) "end" /* 1 */ }; int count_opt_list = 2; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read advection number (not currently used) */ @@ -9317,6 +9334,7 @@ read_rates(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } /* output_msg(sformatf( "%s", rates[0].commands)); */ @@ -9350,7 +9368,7 @@ read_user_print(void) "end" /* 1 */ }; int count_opt_list = 2; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9412,6 +9430,7 @@ read_user_print(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } /* output_msg(sformatf( "%s", rates[0].commands)); */ return (return_value); @@ -9445,7 +9464,7 @@ read_user_punch(void) "headings" /* 3 */ }; int count_opt_list = 4; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9563,6 +9582,7 @@ read_user_punch(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } UserPunch_map.erase(n_user); UserPunch_map[n_user] = temp_user_punch; @@ -9725,7 +9745,7 @@ read_user_graph(void) }; int count_opt_list = 14; int i; - + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9931,6 +9951,7 @@ read_user_graph(void) if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } #ifdef PHREEQ98 for (i = 0; i < user_graph_count_headings; i++) @@ -10886,6 +10907,7 @@ read_named_logk(void) }; int count_opt_list = 11; logk_ptr = NULL; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read name followed by options */ @@ -11078,6 +11100,7 @@ read_named_logk(void) } if (return_value == EOF || return_value == KEYWORD) break; + if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } diff --git a/readtr.cpp b/readtr.cpp index c55c73a7..29726614 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -662,10 +662,9 @@ read_transport(void) * Allocate space for cell_data */ cell_data = (struct cell_data *) PHRQ_realloc(cell_data, - (size_t) (max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); + (size_t)(max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); if (cell_data == NULL) malloc_error(); - // initialize new cells int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; if (all_cells_now > all_cells) @@ -986,7 +985,7 @@ dump_cpp(void) * dumps solution compositions to file */ - int j, l; + int l; if (dump_in == FALSE || pr.dump == FALSE) return (OK); @@ -1213,16 +1212,16 @@ dump_cpp(void) fs << token; sprintf(token, "\t-punch_cells"); fs << token; - if (stag_data->count_stag > 0) - j = 1 + (1 + stag_data->count_stag) * count_cells; - else - j = count_cells; + //if (stag_data->count_stag > 0) + // j = 1 + (1 + stag_data->count_stag) * count_cells; + //else + // j = count_cells; l = 0; - for (int i = 1; i <= j; i++) + for (int i = 0; i < all_cells; i++) { if (cell_data[i].punch != TRUE) continue; - sprintf(token, " %d", i + 1); + sprintf(token, " %d", i); fs << token; l++; if ((l % 20) == 0) @@ -1235,16 +1234,16 @@ dump_cpp(void) fs << token; sprintf(token, "\t-print_cells"); fs << token; - if (stag_data->count_stag > 0) - j = 1 + (1 + stag_data->count_stag) * count_cells; - else - j = count_cells; + //if (stag_data->count_stag > 0) + // j = 1 + (1 + stag_data->count_stag) * count_cells; + //else + // j = count_cells; l = 0; - for (int i = 1; i <= j; i++) + for (int i = 0; i < all_cells; i++) { if (cell_data[i].print != TRUE) continue; - sprintf(token, " %d", i + 1); + sprintf(token, " %d", i); fs << token; l++; if ((l % 20) == 0) diff --git a/transport.cpp b/transport.cpp index e2c254ef..ff091798 100644 --- a/transport.cpp +++ b/transport.cpp @@ -7,6 +7,22 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "Solution.h" +#ifdef PHREEQC_PARALLEL +#include "Parallelizer.h" +#include "PhreeqcRM.h" +#include "IPhreeqcPhast.h" +#include "IPhreeqc.hpp" +#include "Serializer.h" +#endif +#ifdef USE_MPI +#include +#define CLOCK MPI_Wtime +#elif USE_OPENMP +#include +#define CLOCK omp_get_wtime +#else +#define CLOCK clock +#endif LDBLE F_Re3 = F_C_MOL / (R_KJ_DEG_MOL * 1e3); LDBLE tk_x2; // average tx_x of icell and jcell @@ -16,18 +32,20 @@ struct CURRENT_CELLS { LDBLE dif, ele, R; // diffusive and electric components, relative cell resistance } *current_cells; -LDBLE sum_R; // sum of R -struct V_M +LDBLE sum_R, sum_Rd; // sum of R, sum of (current_cells[0].dif - current_cells[i].dif) * R +struct V_M // For calculating Vinograd and McBain's zero-charge, diffusive tranfer of individual solutes { LDBLE grad, D, z, c, zc, Dz, Dzc, Dzc_dl, g_dl; + LDBLE b_ij; // harmonic mean of cell properties, with EDL enrichment int o_c; }; -struct CT /* contains the mcd transfer in a timestep for all cells, for free + DL water */ +struct CT /* summed parts of V_M and mcd transfer in a timestep for all cells, for free + DL water */ { - LDBLE dl_s, A_ij, Dz2c, Dz2c_dl, visc1, visc2, J_ij_sum; - int J_ij_count_spec; - struct V_M *v_m; - struct J_ij *J_ij; + LDBLE dl_s, Dz2c, Dz2c_dl, visc1, visc2, J_ij_sum; + LDBLE A_ij_il, Dz2c_il, mixf_il; + int J_ij_count_spec, J_ij_il_count_spec; + struct V_M *v_m, *v_m_il; + struct J_ij *J_ij, *J_ij_il; } *ct = NULL; struct MOLES_ADDED /* total moles added to balance negative conc's */ { @@ -56,11 +74,29 @@ transport(void) diffc_max = 0.0; transp_surf = warn_fixed_Surf = warn_MCD_X = 0; dV_dcell = current_A = 0.0; + current_cells = NULL; + double rm_time = 0.0; + double phreeqc_time = 0.0; + double rm_comm_time = 0.0; + double rm_calc_time = 0.0; -/* mass_water_switch = TRUE; */ -/* - * Check existence of solutions - */ +#ifdef PHREEQC_PARALLEL + Parallelizer *phreeqcrm_ptr; +#ifdef USE_MPI + int nxyz = count_cells + 2; + MPI_Bcast(&nxyz, 1, MPI_INT, 0, MPI_COMM_WORLD); + phreeqcrm_ptr = new Parallelizer(nxyz, MPI_COMM_WORLD, this->phrq_io); +#else + phreeqcrm_ptr = new Parallelizer(count_cells + 1, 3, this->phrq_io); +#endif + phreeqcrm_ptr->SetPhreeqcPtr(this); + phreeqcrm_ptr->Initialize(); +#endif + + /* mass_water_switch = TRUE; */ + /* + * Check existence of solutions + */ j = -1; /* check column solutions */ for (i = 1; i <= count_cells; i++) @@ -70,8 +106,8 @@ transport(void) { input_error++; error_string = sformatf( - "Solution %d is needed for transport, but is not defined.", - i); + "Solution %d is needed for transport, but is not defined.", + i); error_msg(error_string, CONTINUE); } else @@ -82,16 +118,37 @@ transport(void) if (multi_Dflag) { - sol_D = (struct sol_D *) PHRQ_malloc((size_t) (all_cells) * sizeof(struct sol_D)); + sol_D = (struct sol_D *) PHRQ_malloc((size_t)(all_cells)* sizeof(struct sol_D)); if (sol_D == NULL) malloc_error(); sol_D_dbg = sol_D; - ct = (struct CT *) PHRQ_malloc((size_t) (all_cells) * sizeof(struct CT)); + ct = (struct CT *) PHRQ_malloc((size_t)(all_cells)* sizeof(struct CT)); if (ct == NULL) malloc_error(); + { + for (int i = 0; i < all_cells; i++) + { + ct[i].dl_s = 0.0; + ct[i].Dz2c = 0.0; + ct[i].Dz2c_dl = 0.0; + ct[i].visc1 = 0.0; + ct[i].visc2 = 0.0; + ct[i].J_ij_sum = 0.0; + ct[i].A_ij_il = 0.0; + ct[i].Dz2c_il = 0.0; + ct[i].mixf_il = 0.0; + ct[i].A_ij_il = 0.0; + ct[i].J_ij_count_spec = -1; + ct[i].J_ij_il_count_spec = -1; + ct[i].v_m = NULL; + ct[i].v_m_il = NULL; + ct[i].J_ij = NULL; + ct[i].J_ij_il = NULL; + } + } - moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t) (count_elements) * sizeof(struct MOLES_ADDED)); + moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t)(count_elements)* sizeof(struct MOLES_ADDED)); if (moles_added == NULL) malloc_error(); @@ -102,9 +159,6 @@ transport(void) sol_D[i].exch_total = 0; sol_D[i].x_max = 0; sol_D[i].spec = NULL; - - ct[i].J_ij = NULL; - ct[i].v_m = NULL; } for (i = 0; i < count_elements; i++) { @@ -120,7 +174,7 @@ transport(void) { input_error++; error_string = sformatf( - "Solution 0 is needed for transport, but is not defined."); + "Solution 0 is needed for transport, but is not defined."); error_msg(error_string, CONTINUE); } else @@ -140,8 +194,8 @@ transport(void) { input_error++; error_string = sformatf( - "Solution %d is needed for transport, but is not defined.", - count_cells + 1); + "Solution %d is needed for transport, but is not defined.", + count_cells + 1); error_msg(error_string, CONTINUE); } else @@ -152,9 +206,9 @@ transport(void) if ((cell_data[count_cells + 1].potV = use.Get_solution_ptr()->Get_potV())) dV_dcell = 1; } -/* - * Initialize temperature in stagnant cells ... - */ + /* + * Initialize temperature in stagnant cells ... + */ for (n = 1; n <= stag_data->count_stag; n++) { for (i = 1; i <= count_cells; i++) @@ -172,7 +226,7 @@ transport(void) { input_error++; error_string = sformatf( - "Electrical Field (potential) was defined, but needs -mult_D, \n\t and is not possible with -stagnant or with advective flow."); + "Electrical Field (potential) was defined, but needs -mult_D, \n\t and is not possible with -stagnant or with advective flow."); error_msg(error_string, CONTINUE); free_check_null(sol_D); } @@ -190,9 +244,9 @@ transport(void) } } } -/* - * First equilibrate solutions - */ + /* + * First equilibrate solutions + */ dup_print("Equilibrating initial solutions", TRUE); transport_step = 0; for (i = 0; i <= count_cells + 1; i++) @@ -208,7 +262,7 @@ transport(void) if (transp_surf && !multi_Dflag) { error_string = sformatf( - "-multi_d must be defined for surface transport"); + "-multi_d must be defined for surface transport"); error_msg(error_string, CONTINUE); } if (multi_Dflag == TRUE) @@ -220,12 +274,12 @@ transport(void) if (cell_data[i].print == TRUE) print_all(); -/* if (i > 0 && i <= count_cells)*/ + /* if (i > 0 && i <= count_cells)*/ saver(); } -/* - * Also stagnant cells - */ + /* + * Also stagnant cells + */ for (n = 1; n <= stag_data->count_stag; n++) { for (i = 1; i <= count_cells; i++) @@ -249,32 +303,31 @@ transport(void) } } } -/* - * Initialize mixing factors, define kinetics times - * for multicomponent diffusion, limit mixing by diffc_max (usually from H+) - */ + /* + * Initialize mixing factors, define kinetics times + * for multicomponent diffusion, limit mixing by diffc_max (usually from H+) + */ if (multi_Dflag == TRUE) diffc_tr = diffc_max; if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { /* multi_D calc's are OK if all cells have the same amount of water */ -/* if (multi_Dflag == TRUE) - { - sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give all cells the same amount of water."); - warning_msg(token); - } - */ + /* if (multi_Dflag == TRUE) + { + sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give all cells the same amount of water."); + warning_msg(token); + } + */ Rxn_mix_map.clear(); -/* - * stagnant mix factors go in mix[0 .. count_cells] - */ - + /* + * stagnant mix factors go in mix[0 .. count_cells] + */ } -/* - * mix[] is extended in init_mix(), to accommodate column mix factors - */ + /* + * mix[] is extended in init_mix(), to accommodate column mix factors + */ nmix = init_mix(); heat_nmix = init_heat_mix(nmix); if (nmix < 2) @@ -287,7 +340,7 @@ transport(void) kin_time = stagkin_time; kin_time_save = kin_time; -/* Reaction defined for a shift... */ + /* Reaction defined for a shift... */ if (!ishift) { if (nmix < 2) @@ -297,9 +350,9 @@ transport(void) } else step_fraction = 1.0 / (1.0 + nmix); -/* - * Set boundary conditions, transport direction - */ + /* + * Set boundary conditions, transport direction + */ last_model.force_prep = TRUE; if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) b_c = 1; @@ -315,15 +368,15 @@ transport(void) last_c = 1; first_c = count_cells; } -/* - * Define stagnant/mobile mix structure, if not read explicitly. - * - * With count_stag = 1, mix factors are calculated from exchange factor à - * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. - * These variables are read under keyword TRANSPORT, after stagnant, in - * structure stag_data. - * MIX 'cell_no' in input file can be an alternative for the calculation here. - */ + /* + * Define stagnant/mobile mix structure, if not read explicitly. + * + * With count_stag = 1, mix factors are calculated from exchange factor à + * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. + * These variables are read under keyword TRANSPORT, after stagnant, in + * structure stag_data. + * MIX 'cell_no' in input file can be an alternative for the calculation here. + */ if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); @@ -337,17 +390,17 @@ transport(void) j_imm = j + (1 + count_cells); if (Utilities::Rxn_find(Rxn_solution_map, j) == NULL) error_msg - ("Could not find mobile cell solution in TRANSPORT.", - STOP); + ("Could not find mobile cell solution in TRANSPORT.", + STOP); if (Utilities::Rxn_find(Rxn_solution_map, j_imm) == NULL) error_msg - ("Could not find immobile cell solution in TRANSPORT.", - STOP); + ("Could not find immobile cell solution in TRANSPORT.", + STOP); water_m = Utilities::Rxn_find(Rxn_solution_map, j)->Get_mass_water(); water_imm = Utilities::Rxn_find(Rxn_solution_map, j_imm)->Get_mass_water(); -/* - * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 - */ + /* + * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 + */ { cxxMix temp_mix; temp_mix.Set_n_user(j); @@ -357,9 +410,9 @@ transport(void) Rxn_mix_map[j] = temp_mix; n++; } -/* - * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... - */ + /* + * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... + */ { cxxMix temp_mix; temp_mix.Set_n_user(j_imm); @@ -373,9 +426,9 @@ transport(void) if (heat_nmix > 0) { -/* - * Assumption: D_e used for calculating exch_f in input file equals diffc - */ + /* + * Assumption: D_e used for calculating exch_f in input file equals diffc + */ f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; f = exp(-f * stagkin_time / (b * stag_data->th_im)); heat_mix_f_imm = b - b * f; @@ -383,23 +436,23 @@ transport(void) heat_mix_f_imm * stag_data->th_im / stag_data->th_m; } } -/* - * Stop if error - */ + /* + * Stop if error + */ if (get_input_errors() > 0) { error_msg("Program terminating due to input errors.", STOP); } -/* - * Now transport - */ + /* + * Now transport + */ max_iter = 0; for (transport_step = transport_start; transport_step <= count_shifts; - transport_step++) + transport_step++) { /* - * Set initial moles of phases - */ + * Set initial moles of phases + */ for (i = 0; i <= count_cells + 1; i++) { if (!dV_dcell && (i == 0 || i == count_cells + 1)) @@ -407,8 +460,8 @@ transport(void) set_initial_moles(i); } /* - * Also stagnant cells - */ + * Also stagnant cells + */ for (n = 1; n <= stag_data->count_stag; n++) { for (i = 1; i <= count_cells; i++) @@ -421,20 +474,20 @@ transport(void) } } } -/* - * Start diffusing if boundary cond = 1, (fixed c, or closed) - */ + /* + * Start diffusing if boundary cond = 1, (fixed c, or closed) + */ if (b_c == 1) { /* For half of mixing steps */ - for (j = 1; j <= floor((LDBLE) nmix / 2); j++) + for (j = 1; j <= floor((LDBLE)nmix / 2); j++) { rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * kin_time; rate_sim_time = rate_sim_time_start + kin_time; mixrun = j; - if (multi_Dflag && j == floor((LDBLE) nmix / 2)) + if (multi_Dflag && j == floor((LDBLE)nmix / 2)) { //sprintf(token, // "Transport step %3d. Multicomponent diffusion run %3d.", @@ -444,7 +497,7 @@ transport(void) else if (!multi_Dflag) { sprintf(token, "Transport step %3d. Mixrun %3d.", - transport_step, j); + transport_step, j); dup_print(token, FALSE); } @@ -466,27 +519,60 @@ transport(void) { if (disp_surf(stagkin_time) == ERROR) error_msg("Error in surface transport, stopping.", - STOP); + STOP); } if (multi_Dflag) multi_D(stagkin_time, 1, FALSE); + double time_rm_start = CLOCK(); +#ifdef PHREEQC_PARALLEL + { + //Serializer serial; + //serial.Serialize(*this, 0, count_cells + 1, false, false); + ////this->Rxn_solution_map.clear(); + //Dictionary d1(serial.GetDictionary().GetDictionaryOss().str()); + //Serializer serial1; + //serial1.Deserialize(*this, d1, serial.GetInts(), serial.GetDoubles()); + } + // move data to workers + phreeqcrm_ptr->Phreeqc2RM(this); + rm_comm_time += (CLOCK() - time_rm_start); + double time_rm_calc_start = CLOCK(); + // Run cells + phreeqcrm_ptr->SetTimeStep(kin_time); + phreeqcrm_ptr->RunCellsParallel(); + rm_time += (CLOCK() - time_rm_start); + rm_calc_time += (CLOCK() - time_rm_calc_start); + //std::cerr << phreeqcrm_ptr->GetErrorString() << std::endl; + // move data back to phreeqc + phreeqcrm_ptr->RM2Phreeqc(this); +#endif + +#ifdef PHREEQC_PARALLELyyy + // Copy to PhreeqcRM + // Run reactions + // Copy to PHREEQC + // Do other stuff + +#else + + time_rm_start = CLOCK(); for (i = 0; i <= count_cells + 1; i++) { - //if (!dV_dcell && (i == 0 || i == count_cells + 1)) - // continue; + if (!dV_dcell && (i == 0 || i == count_cells + 1)) + continue; if (iterations > max_iter) max_iter = iterations; cell_no = i; mixrun = j; if (multi_Dflag) sprintf(token, - "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); else sprintf(token, - "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); status(0, token); if (i == 0 || i == count_cells + 1) @@ -499,7 +585,7 @@ transport(void) /* punch and output file */ if ((ishift == 0) && (j == nmix) && ((stag_data->count_stag == 0) - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -515,7 +601,7 @@ transport(void) /* maybe sorb a surface component... */ if ((ishift == 0) && (j == nmix) && ((stag_data->count_stag == 0) - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { if (change_surf_count > 0) { @@ -524,20 +610,25 @@ transport(void) if (change_surf[k].cell_no != i) break; reformat_surf(change_surf[k].comp_name, - change_surf[k].fraction, - change_surf[k].new_comp_name, - change_surf[k].new_Dw, - change_surf[k].cell_no); + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); change_surf[k].cell_no = -99; } change_surf_count = 0; } } } - Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); - + //phreeqc_time += (CLOCK() - time_rm_start); + //std::cerr << "RM: " << rm_time << " PHREEQC: " << phreeqc_time << std::endl; + //std::cerr << "RM comm: " << rm_comm_time << " RM calc: " << rm_calc_time << std::endl; + //std::cerr << " transport_step: " << transport_step << " j: " << j << std::endl; +#endif + if (!dV_dcell) + Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ + diffusive/dispersive step ... */ rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * stagkin_time; rate_sim_time = rate_sim_time_start + stagkin_time; @@ -550,20 +641,20 @@ transport(void) punch_boolean = FALSE; for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, - step_fraction); + step_fraction); } } } -/* - * Advective transport - */ + /* + * Advective transport + */ if (ishift != 0) { sprintf(token, "Transport step %3d.", transport_step); dup_print(token, FALSE); if (b_c == 1) rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; + (transport_step - 1) * timest + (j - 1) * kin_time; else rate_sim_time_start = (transport_step - 1) * timest; rate_sim_time = rate_sim_time_start + kin_time; @@ -582,16 +673,16 @@ transport(void) for (i = last_c; i != (first_c - ishift); i -= ishift) Utilities::Rxn_copy(Rxn_solution_map, i - ishift, i); -/* if boundary_solutions must be flushed by the flux from the column... - if (ishift == 1 && bcon_last == 3) - solution_duplicate (last_c, last_c + 1); - else if (ishift == -1 && bcon_first == 3) - solution_duplicate (last_c, last_c - 1); - */ + /* if boundary_solutions must be flushed by the flux from the column... + if (ishift == 1 && bcon_last == 3) + solution_duplicate (last_c, last_c + 1); + else if (ishift == -1 && bcon_first == 3) + solution_duplicate (last_c, last_c - 1); + */ if (transp_surf) { for (i = last_c + ishift; i != (first_c - ishift); - i -= ishift) + i -= ishift) { if ((ishift == 1 && i == last_c + 1 && bcon_last != 3) || (ishift == -1 && i == last_c - 1 && bcon_first != 3)) @@ -599,7 +690,7 @@ transport(void) cxxSurface * surface_ptr = Utilities::Rxn_find(Rxn_surface_map, i - ishift); if (surface_ptr == NULL) { - if ((Utilities::Rxn_find(Rxn_surface_map,i) != NULL) && + if ((Utilities::Rxn_find(Rxn_surface_map, i) != NULL) && ((i == 0 && bcon_first == 3) || (i == count_cells + 1 && bcon_last == 3))) { @@ -629,9 +720,9 @@ transport(void) } } -/* - * thermal diffusion when nmix = 0... - */ + /* + * thermal diffusion when nmix = 0... + */ if ((nmix == 0) && (heat_nmix > 0)) { heat_mix(heat_nmix); @@ -654,12 +745,12 @@ transport(void) mixrun = 0; if (multi_Dflag) sprintf(token, - "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, 0, i, max_iter); + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); else sprintf(token, - "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, 0, i, max_iter); + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); status(0, token); run_reactions(i, kin_time, NOMIX, step_fraction); if (multi_Dflag == TRUE) @@ -667,7 +758,7 @@ transport(void) if (iterations > max_iter) max_iter = iterations; if ((nmix == 0) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -682,7 +773,7 @@ transport(void) /* maybe sorb a surface component... */ if ((nmix == 0) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -691,10 +782,10 @@ transport(void) if (change_surf[k].cell_no != i) break; reformat_surf(change_surf[k].comp_name, - change_surf[k].fraction, - change_surf[k].new_comp_name, - change_surf[k].new_Dw, - change_surf[k].cell_no); + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); change_surf[k].cell_no = -99; } change_surf_count = 0; @@ -702,16 +793,16 @@ transport(void) } /* If nmix is zero, stagnant zone mixing after - advective step ... */ + advective step ... */ if ((nmix == 0) && (stag_data->count_stag > 0)) { mix_stag(i, stagkin_time, TRUE, step_fraction); } } } -/* - * Further dispersive and diffusive transport - */ + /* + * Further dispersive and diffusive transport + */ if (b_c != 1) j = 1; for (j = j; j <= nmix; j++) @@ -719,14 +810,14 @@ transport(void) if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0)) { sprintf(token, - "Transport step %3d. Multicomponent diffusion run %3d.", - transport_step, j); + "Transport step %3d. Multicomponent diffusion run %3d.", + transport_step, j); dup_print(token, FALSE); } else if (!multi_Dflag) { sprintf(token, "Transport step %3d. Mixrun %3d.", - transport_step, j); + transport_step, j); dup_print(token, FALSE); } rate_sim_time_start = @@ -739,6 +830,16 @@ transport(void) { heat_mix(heat_nmix); /* equilibrate again ... */ +#ifdef PHREEQC_PARALLEL + // move data to workers + phreeqcrm_ptr->Phreeqc2RM(this); + // Run cells + phreeqcrm_ptr->RunCells(); + // move data back to phreeqc +#ifdef SKIP + phreeqcrm_ptr->RM2phreeqc(this); +#endif +#endif for (i = 1; i <= count_cells; i++) { cell_no = i; @@ -768,23 +869,22 @@ transport(void) mixrun = j; if (multi_Dflag) sprintf(token, - "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); else sprintf(token, - "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); status(0, token); if (i == 0 || i == count_cells + 1) - //set_and_run_wrapper(i, NOMIX, FALSE, -2 - i, 0.0); run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); if ((j == nmix) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -799,7 +899,7 @@ transport(void) /* maybe sorb a surface component... */ if ((j == nmix) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -808,20 +908,20 @@ transport(void) if (change_surf[k].cell_no != i) break; reformat_surf(change_surf[k].comp_name, - change_surf[k].fraction, - change_surf[k].new_comp_name, - change_surf[k].new_Dw, - change_surf[k].cell_no); + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); change_surf[k].cell_no = -99; } change_surf_count = 0; } } } - Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); - + if (!dV_dcell) + Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ + diffusive/dispersive step ... */ rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * stagkin_time; rate_sim_time = rate_sim_time_start + stagkin_time; @@ -853,14 +953,14 @@ transport(void) break; sprintf(token, "\t %.4e moles %s.", - (double) moles_added[i].moles, moles_added[i].name); + (double)moles_added[i].moles, moles_added[i].name); if (phrq_io) phrq_io->warning_msg(token); } } -/* - * free mix structures - */ + /* + * free mix structures + */ Dispersion_mix_map.clear(); if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { @@ -869,9 +969,9 @@ transport(void) if (heat_nmix > 0) { - heat_mix_array = (LDBLE *) free_check_null(heat_mix_array); - temp1 = (LDBLE *) free_check_null(temp1); - temp2 = (LDBLE *) free_check_null(temp2); + heat_mix_array = (LDBLE *)free_check_null(heat_mix_array); + temp1 = (LDBLE *)free_check_null(temp1); + temp2 = (LDBLE *)free_check_null(temp2); } if (multi_Dflag) { @@ -883,12 +983,18 @@ transport(void) ct = (struct CT *) free_check_null(ct); moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } - if (dV_dcell) - free_check_null(current_cells); + //if (dV_dcell) + free_check_null(current_cells); initial_total_time += rate_sim_time; rate_sim_time = 0; mass_water_switch = FALSE; +#ifdef PHREEQC_PARALLEL +#ifdef USE_MPI + phreeqcrm_ptr->MpiWorkerBreak(); +#endif + delete phreeqcrm_ptr; +#endif return (OK); } /* ---------------------------------------------------------------------- */ @@ -898,21 +1004,14 @@ init_mix(void) { LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; //, dx = 0; int i, l_nmix; - - //std::vector m, m1; - //for(i = 0; i < count_cells + 1; i++) - //{ - // m.push_back(0); // this takes 5* more time than malloc & m[i] = 0 - // m1.push_back(0); - //} LDBLE *m, *m1; - m = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + m = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); if (m == NULL) malloc_error(); - m1 = (LDBLE *) PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + m1 = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); if (m1 == NULL) malloc_error(); - for(i = 0; i < count_cells + 1; i++) + for (i = 0; i < count_cells + 1; i++) { m[i] = 0; m1[i] = 0; @@ -945,9 +1044,9 @@ init_mix(void) if (mD > maxmix) maxmix = mD; } -/* - * Also for boundary cells - */ + /* + * Also for boundary cells + */ if (bcon_first == 1) { lav = cell_data[1].length; @@ -986,21 +1085,21 @@ init_mix(void) else m[count_cells] = 0; -/* - * Find number of mixes - */ + /* + * Find number of mixes + */ if (maxmix == 0) { l_nmix = 0; if (mcd_substeps > 1 && stag_data->count_stag > 0) - l_nmix = (int) ceil(mcd_substeps); + l_nmix = (int)ceil(mcd_substeps); } else { if ((bcon_first == 1) || (bcon_last == 1)) - l_nmix = 1 + (int) floor(4.5 * maxmix); + l_nmix = 1 + (int)floor(4.5 * maxmix); else - l_nmix = 1 + (int) floor(3.0 * maxmix); + l_nmix = 1 + (int)floor(3.0 * maxmix); if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { @@ -1008,14 +1107,14 @@ init_mix(void) l_nmix = 2; } if (mcd_substeps > 1) - l_nmix = (int) ceil(l_nmix * mcd_substeps); + l_nmix = (int)ceil(l_nmix * mcd_substeps); for (i = 0; i <= count_cells; i++) m[i] /= l_nmix; } -/* - * Fill mix structure - */ + /* + * Fill mix structure + */ if (l_nmix != 0) { @@ -1031,19 +1130,19 @@ init_mix(void) Dispersion_mix_map[i] = temp_mix; } } - m = (LDBLE *) free_check_null(m); - m1 = (LDBLE *) free_check_null(m1); + m = (LDBLE *)free_check_null(m); + m1 = (LDBLE *)free_check_null(m1); return (l_nmix); } else // multi_D false { diffc_here = diffc_tr; -/* - * Define mixing factors among inner cells - */ + /* + * Define mixing factors among inner cells + */ for (i = 1; i < count_cells; i++) { -// find mix with lower numbered cell... + // find mix with lower numbered cell... lav = (cell_data[i + 1].length + cell_data[i].length) / 2; if (ishift != 0) dav = (cell_data[i + 1].disp + cell_data[i].disp) / 2; @@ -1053,16 +1152,16 @@ init_mix(void) mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i + 1].length; m[i] = mixf; /* m[i] has mixf with lower cell */ -// and with higher numbered cell... + // and with higher numbered cell... mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; mf12 = m[i] + mixf; if (mf12 > maxmix) maxmix = mf12; m1[i] = mixf; /* m1[i] has mixf with higher cell */ } -/* - * Also for boundary cells - */ + /* + * Also for boundary cells + */ if (bcon_first == 1) { lav = cell_data[1].length; @@ -1097,16 +1196,16 @@ init_mix(void) else m[count_cells] = 0; -/* - * Find number of mixes - */ + /* + * Find number of mixes + */ if (maxmix == 0) { l_nmix = 0; } else { - l_nmix = 1 + (int) floor(1.5 * maxmix); + l_nmix = 1 + (int)floor(1.5 * maxmix); if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { @@ -1121,8 +1220,8 @@ init_mix(void) } } /* - * Fill mix structure - */ + * Fill mix structure + */ if (l_nmix != 0) { @@ -1138,8 +1237,8 @@ init_mix(void) Dispersion_mix_map[i] = temp_mix; } } - m = (LDBLE *) free_check_null(m); - m1 = (LDBLE *) free_check_null(m1); + m = (LDBLE *)free_check_null(m); + m1 = (LDBLE *)free_check_null(m1); return (l_nmix); } } @@ -1151,9 +1250,9 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) int j, n, k; LDBLE t_imm; cxxSolution *ptr_imm, *ptr_m; -/* - * Kinetics in transport cell is done while transporting - */ + /* + * Kinetics in transport cell is done while transporting + */ for (n = 1; n <= stag_data->count_stag; n++) { k = i + 1 + n * count_cells; @@ -1166,14 +1265,14 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) ptr_m = Utilities::Rxn_find(Rxn_solution_map, i); t_imm = heat_mix_f_imm * ptr_m->Get_tc() + (1 - - heat_mix_f_imm) * + heat_mix_f_imm) * ptr_imm->Get_tc(); ptr_m->Set_tc( heat_mix_f_m * ptr_imm->Get_tc() + (1 - - heat_mix_f_m) * + heat_mix_f_m) * ptr_m->Get_tc()); cell_data[i].temp = ptr_m->Get_tc(); - cell_data[k].temp= t_imm = ptr_imm->Get_tc(); + cell_data[k].temp = t_imm = ptr_imm->Get_tc(); /* equilibrate again ... */ cell_no = i; set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); @@ -1186,15 +1285,15 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) fill_spec(cell_no); saver(); } -/* - * Mobile cell, kinetics already done ... - */ + /* + * Mobile cell, kinetics already done ... + */ cell_no = i; if (transp_surf) { if (diff_stag_surf(i) == ERROR) error_msg("Error in surface transport, stopping.", - STOP); + STOP); } if (multi_Dflag == TRUE) multi_D(1.0, i, TRUE); @@ -1224,10 +1323,10 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) if (change_surf[j].cell_no != i) break; reformat_surf(change_surf[j].comp_name, - change_surf[j].fraction, - change_surf[j].new_comp_name, - change_surf[j].new_Dw, - change_surf[j].cell_no); + change_surf[j].fraction, + change_surf[j].new_comp_name, + change_surf[j].new_Dw, + change_surf[j].cell_no); change_surf[j].cell_no = -99; } change_surf_count = 0; @@ -1255,10 +1354,10 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) if (change_surf[j].cell_no != k) break; reformat_surf(change_surf[j].comp_name, - change_surf[j].fraction, - change_surf[j].new_comp_name, - change_surf[j].new_Dw, - change_surf[j].cell_no); + change_surf[j].fraction, + change_surf[j].new_comp_name, + change_surf[j].new_Dw, + change_surf[j].cell_no); change_surf[j].cell_no = -99; } change_surf_count = 0; @@ -1287,9 +1386,9 @@ init_heat_mix(int l_nmix) int i, k, n; int l_heat_nmix; LDBLE t0; -/* - * Check for need to model thermal diffusion... - */ + /* + * Check for need to model thermal diffusion... + */ if (heat_diffc <= diffc) return (0); if (count_cells < 2) @@ -1327,23 +1426,23 @@ init_heat_mix(int l_nmix) } if (l_heat_nmix == 0) return (0); -/* - * Initialize arrays... - */ - heat_mix_array = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + /* + * Initialize arrays... + */ + heat_mix_array = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); if (heat_mix_array == NULL) malloc_error(); - temp1 = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + temp1 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); if (temp1 == NULL) malloc_error(); - temp2 = (LDBLE *) PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + temp2 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); if (temp2 == NULL) malloc_error(); -/* - * Define mixing factors among inner cells... - */ + /* + * Define mixing factors among inner cells... + */ corr_disp = 1.; if (correct_disp == TRUE && ishift != 0) { @@ -1360,20 +1459,20 @@ init_heat_mix(int l_nmix) lav = (cell_data[i + 1].length + cell_data[i].length) / 2; mixf = (heat_diffc - - diffc_tr) * timest * corr_disp / tempr / (lav * lav); + diffc_tr) * timest * corr_disp / tempr / (lav * lav); if (mixf > maxmix) maxmix = mixf; heat_mix_array[i + 1] = mixf; /* m[i] has mixf with lower cell */ } -/* - * Also for boundary cells - */ + /* + * Also for boundary cells + */ if (bcon_first == 1) { lav = cell_data[1].length; mixf = (heat_diffc - - diffc_tr) * timest * corr_disp / tempr / (lav * lav); + diffc_tr) * timest * corr_disp / tempr / (lav * lav); if (2 * mixf > maxmix) maxmix = 2 * mixf; heat_mix_array[1] = 2 * mixf; @@ -1386,21 +1485,21 @@ init_heat_mix(int l_nmix) lav = cell_data[count_cells].length; mixf = (heat_diffc - - diffc_tr) * timest * corr_disp / tempr / (lav * lav); + diffc_tr) * timest * corr_disp / tempr / (lav * lav); if (2 * mixf > maxmix) maxmix = 2 * mixf; heat_mix_array[count_cells + 1] = 2 * mixf; } else heat_mix_array[count_cells + 1] = 0; -/* - * Find number of mixes - */ + /* + * Find number of mixes + */ if (maxmix == 0) l_heat_nmix = 0; else { - l_heat_nmix = 1 + (int) floor(3.0 * maxmix); + l_heat_nmix = 1 + (int)floor(3.0 * maxmix); for (i = 1; i <= count_cells + 1; i++) heat_mix_array[i] /= l_heat_nmix; } @@ -1425,9 +1524,9 @@ heat_mix(int l_heat_nmix) { for (j = 1; j <= count_cells; j++) temp2[j] = - heat_mix_array[j] * temp1[j - 1] + heat_mix_array[j + 1] * - temp1[j + 1] + (1 - heat_mix_array[j] - - heat_mix_array[j + 1]) * temp1[j]; + heat_mix_array[j] * temp1[j - 1] + heat_mix_array[j + 1] * + temp1[j + 1] + (1 - heat_mix_array[j] - + heat_mix_array[j + 1]) * temp1[j]; for (j = 1; j <= count_cells; j++) temp1[j] = temp2[j]; } @@ -1450,15 +1549,15 @@ set_initial_moles(int i) char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr; int j, k, l; /* - * Pure phase assemblage - */ + * Pure phase assemblage + */ { cxxPPassemblage * pp_assemblage_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, i); if (pp_assemblage_ptr != NULL) { std::map::iterator it; - it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); - for ( ; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) + it = pp_assemblage_ptr->Get_pp_assemblage_comps().begin(); + for (; it != pp_assemblage_ptr->Get_pp_assemblage_comps().end(); it++) { it->second.Set_initial_moles(it->second.Get_moles()); if (it->second.Get_initial_moles() < 0) @@ -1467,8 +1566,8 @@ set_initial_moles(int i) } } /* - * Gas phase - */ + * Gas phase + */ { cxxGasPhase * gas_phase_ptr = Utilities::Rxn_find(Rxn_gas_phase_map, i); if (gas_phase_ptr != NULL) @@ -1482,29 +1581,29 @@ set_initial_moles(int i) } } /* - * Kinetics - */ + * Kinetics + */ kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); if (kinetics_ptr != NULL) { - for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) + for (j = 0; j < (int)kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); kinetics_comp_ptr->Set_initial_moles(kinetics_comp_ptr->Get_m()); } } /* - * Solid solutions - */ + * Solid solutions + */ { cxxSSassemblage *ss_assemblage_ptr = Utilities::Rxn_find(Rxn_ss_assemblage_map, i); if (ss_assemblage_ptr != NULL) { std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); - for (k = 0; k < (int) ss_ptrs.size(); k++) + for (k = 0; k < (int)ss_ptrs.size(); k++) { cxxSS * ss_ptr = ss_ptrs[k]; - for (j = 0; j < (int) ss_ptr->Get_ss_comps().size(); j++) + for (j = 0; j < (int)ss_ptr->Get_ss_comps().size(); j++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); comp_ptr->Set_init_moles(comp_ptr->Get_moles()); @@ -1513,8 +1612,8 @@ set_initial_moles(int i) } } /* - * For interlayer diffusion: add tiny bit of exchanger if absent - */ + * For interlayer diffusion: add tiny bit of exchanger if absent + */ cxxExchange * exchange_ptr = Utilities::Rxn_find(Rxn_exchange_map, i); if (interlayer_Dflag && exchange_ptr == NULL) { @@ -1556,7 +1655,7 @@ int Phreeqc:: fill_spec(int l_cell_no) /* ---------------------------------------------------------------------- */ { -/* copy species activities into sol_D.spec... */ + /* copy species activities into sol_D.spec... */ int i, i2, count_spec, count_exch_spec; char token[MAX_LENGTH]; @@ -1573,8 +1672,8 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec = (struct spec *) free_check_null(sol_D[l_cell_no].spec); sol_D[l_cell_no].spec = - (struct spec *) PHRQ_malloc((size_t) count_species_list * - sizeof(struct spec)); + (struct spec *) PHRQ_malloc((size_t)count_species_list * + sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); @@ -1601,30 +1700,30 @@ fill_spec(int l_cell_no) if (por_il < interlayer_Dpor_lim) por_il = temp_il_factor = 0.0; -/* - * correct diffusion coefficient for temperature and viscosity, D_T = D_298 * Tk * viscos_298 / (298 * viscos) - * modify viscosity effect: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15), SC data from Robinson and Stokes, 1959 - */ + /* + * correct diffusion coefficient for temperature and viscosity, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + * modify viscosity effect: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15), SC data from Robinson and Stokes, 1959 + */ viscos = viscos_0; -/* - * put temperature factor in por_factor which corrects for porous medium... - */ + /* + * put temperature factor in por_factor which corrects for porous medium... + */ temp_factor *= tk_x * viscos_0_25 / (298.15 * viscos); temp_il_factor *= tk_x * viscos_0_25 / (298.15 * viscos); count_spec = count_exch_spec = 0; -/* - * sort species by name... - */ + /* + * sort species by name... + */ if (count_species_list > 0) - qsort(&species_list[0], (size_t) count_species_list, - (size_t) sizeof(struct species_list), sort_species_name); + qsort(&species_list[0], (size_t)count_species_list, + (size_t) sizeof(struct species_list), sort_species_name); for (i = 0; i < count_species_list; i++) { -/* - * copy species data - */ + /* + * copy species data + */ s_ptr = species_list[i].s; if (s_ptr->type == EX && !interlayer_Dflag) @@ -1668,16 +1767,16 @@ fill_spec(int l_cell_no) } dum2 = s_ptr->moles * dum; /* equivalent fraction */ sol_D[l_cell_no].spec[count_spec].name = s_ptr->name; - //string_hsave(s_ptr->name); + //string_hsave(s_ptr->name); sol_D[l_cell_no].spec[count_spec].type = EX; sol_D[l_cell_no].spec[count_spec].c = dum2; sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg - log10(dum); sol_D[l_cell_no].spec[count_spec].a = dum2 * pow(10, - sol_D - [l_cell_no]. - spec - [count_spec]. - lg); + sol_D + [l_cell_no]. + spec + [count_spec]. + lg); sol_D[l_cell_no].exch_total = master_ptr->total; if (transport_step == 0 && !x_max_done) { @@ -1695,11 +1794,11 @@ fill_spec(int l_cell_no) } /* copy its name and Dw and charge... */ sol_D[l_cell_no].spec[count_spec].aq_name = s_ptr2->name; - //string_hsave(s_ptr2->name); + //string_hsave(s_ptr2->name); sol_D[l_cell_no].spec[count_spec].z = s_ptr2->z; if (s_ptr2->dw == 0) sol_D[l_cell_no].spec[count_spec].Dwt = - default_Dw * temp_il_factor; + default_Dw * temp_il_factor; else { if (s_ptr->dw_t) @@ -1727,7 +1826,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].z = s_ptr->z; if (s_ptr->dw == 0) sol_D[l_cell_no].spec[count_spec].Dwt = - default_Dw * temp_factor; + default_Dw * temp_factor; else { if (s_ptr->dw_t) @@ -1738,7 +1837,7 @@ fill_spec(int l_cell_no) if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = - sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); + sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); sol_D[l_cell_no].spec[count_spec].erm_ddl = s_ptr->erm_ddl; count_spec++; @@ -1746,8 +1845,8 @@ fill_spec(int l_cell_no) } sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, - (size_t) count_spec * - sizeof(struct spec)); + (size_t)count_spec * + sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); @@ -1775,25 +1874,31 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) /* ---------------------------------------------------------------------- */ { /* - * 1. determine mole transfer (mol/s) of solute species for the interface between 2 cells. - * 2. sum up as mole transfer of master_species - * 3. add moles of master_species to the 2 cells - * NOTE. Define the water content of stagnant cells relative to the - * mobile cell (with, for example, 1 kg water) - * Define properties of each interface only 1 time with MIX. - * If an electrical field is applied (dV_dcell != 0), the currents j_i = current_cells[i].ele (C * s) - are calculated for all cells. Then dV is distributed according to - relative cell resistance, R_i / sum_R, and the smallest j_x is the current_x (C * s), - equal for all cells. - */ + * 1. determine mole transfer (mol/s) of solute species for the interface between 2 cells. + * 2. sum up as mole transfer of master_species + * 3. add moles of master_species to the 2 cells + * NOTE. Define the water content of stagnant cells relative to the + * mobile cell (with, for example, 1 kg water) + * Define properties of each interface only 1 time with MIX. + * If an electrical field is applied (dV_dcell != 0), the currents j_i = current_cells[i].ele + dif (C * s) + are calculated for all cells. Then the ele part from cell 0 -> 1 is calculated: + current_x = (j_0d + j_0e) = j_0 = j_1 = ... = j_i + j_0e * (R0 + R1 + ...) + (j_0d - j_1d) * R1 + ... + (j_0d - j_id) * Ri = Vtot + or + j_0e * Sum_R + Sum_Rd = Vtot. + Ri = dV_dcell / j_ie, the relative cell resistance. + Solve j_0e, find (V1 - V0) = j_0e * R0. j_1e = current_x - j_1d, find (V2 - V1) = j_1e * R1, etc. + */ int icell, jcell, i, l, n, length, length2, il_calcs; int i1, loop_f_c; - int first_c, last_c; + int first_c, last_c, last_c2 = 0; char token[MAX_LENGTH]; LDBLE mixf, temp; + icell = jcell = -1; first_c = last_c = -1; - current_x = sum_R = 0.0; + + current_x = sum_R = sum_Rd = 0.0; if (dV_dcell) find_current = loop_f_c = 1; // calculate J_ij once for all cells, find smallest j_x, next with this j_x. else @@ -1809,13 +1914,13 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) if (n == 0) icell -= 1; /* - * find the mix ptr for icell and go along the cells that mix with it - */ + * find the mix ptr for icell and go along the cells that mix with it + */ use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); if (use.Get_mix_ptr() == NULL) continue; first_c = 0; - last_c = (int) (use.Get_mix_ptr()->Get_mixComps().size() - 1); + last_c = (int)(use.Get_mix_ptr()->Get_mixComps().size() - 1); } else { /* regular column... */ @@ -1855,8 +1960,10 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) tk_x2 = (sol_D[icell].tk_x + sol_D[jcell].tk_x) / 2; } /* - * 1. obtain J_ij... - */ + * 1. obtain J_ij... + */ + if (jcell > last_c2) + last_c2 = jcell; il_calcs = find_J(icell, jcell, mixf, DDt, stagnant); if (find_current) { @@ -1864,17 +1971,17 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) continue; else { - LDBLE dV, dVc, jx; + LDBLE dVc, j_0e; // distribute dV_dcell according to relative resistance, calculate current_x - dV = dV_dcell * count_cells; - for (i1 = 0; i1 <= count_cells; i1 ++) + j_0e = (dV_dcell * count_cells - sum_Rd) / sum_R; + dVc = j_0e * current_cells[0].R; + cell_data[1].potV = cell_data[0].potV + dVc; + current_x = j_0e + current_cells[0].dif; + for (i1 = 1; i1 <= count_cells; i1 ++) { - dVc = current_cells[i1].R / sum_R * dV; + dVc = current_cells[i1].R * (current_x - current_cells[i1].dif); if (i1 < count_cells) cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; - jx = current_cells[i1].ele * dVc / dV_dcell; - if (i1 == 0 || (abs(jx) < abs(current_x))) - current_x = jx; } find_current = 0; continue; @@ -1882,14 +1989,14 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } /* - * 2. sum up the primary or secondary master_species - */ + * 2. sum up the primary or secondary master_species + */ if (!il_calcs) { tot1_h = tot1_o = tot2_h = tot2_o = 0.0; m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * - sizeof(struct M_S)); + m_s = (struct M_S *) PHRQ_malloc((size_t)count_elements * + sizeof(struct M_S)); if (m_s == NULL) malloc_error(); for (i1 = 0; i1 < count_elements; i1++) @@ -1903,8 +2010,8 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); /* - * 3. find the solutions, add or subtract the moles... - */ + * 3. find the solutions, add or subtract the moles... + */ if (i > 0 || stagnant || (i == 0 && dV_dcell)) { use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); @@ -1916,13 +2023,13 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } for (l = 0; l < count_m_s; l++) { - length = (int) strlen(m_s[l].name); + length = (int)strlen(m_s[l].name); cxxNameDouble::iterator it; for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) { length2 = - (int) (size_t) strcspn(it->first.c_str(), "("); + (int)(size_t)strcspn(it->first.c_str(), "("); if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { it->second -= m_s[l].tot1; @@ -1944,12 +2051,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Get_solution_ptr()->Set_total_o(dummy + tot1_o); for (l = 0; l < count_m_s; l++) { - length = (int) strlen(m_s[l].name); + length = (int)strlen(m_s[l].name); cxxNameDouble::iterator it; for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) { - length2 = (int) (size_t) strcspn(it->first.c_str(), "("); + length2 = (int)(size_t)strcspn(it->first.c_str(), "("); if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { it->second += m_s[l].tot1; @@ -1966,9 +2073,11 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } // check for negative conc's... - for (i = first_c; i <= last_c + 1; i++) + for (i = first_c; i <= last_c2; i++) { use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); + if (!use.Get_solution_ptr()) + continue; cxxNameDouble::iterator it; for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) @@ -1979,12 +2088,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) temp = moles; it->second = 0; /* see if other redox states have more moles... */ - length = (int) strlen(it->first.c_str()); + length = (int)strlen(it->first.c_str()); cxxNameDouble::iterator kit; for (kit = use.Get_solution_ptr()->Get_totals().begin(); kit != use.Get_solution_ptr()->Get_totals().end(); kit++) { - length2 = (int) (size_t) strcspn(kit->first.c_str(), "("); + length2 = (int)(size_t)strcspn(kit->first.c_str(), "("); if (!strncmp(it->first.c_str(), kit->first.c_str(), length2)) { temp += kit->second; @@ -2002,8 +2111,8 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) if (temp < -1e-12) { sprintf(token, - "Negative concentration in MCD: added %.4e moles %s in cell %d", - (double) -temp, it->first.c_str(), i); + "Negative concentration in MCD: added %.4e moles %s in cell %d", + (double)-temp, it->first.c_str(), i); warning_msg(token); for (i1 = 0; i1 < count_elements; i1++) { @@ -2025,13 +2134,14 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } m_s = (struct M_S *) free_check_null(m_s); - J_ij_il = (struct J_ij *) free_check_null(J_ij_il); - for (i = 0; i < all_cells; i++) + + for (i = first_c; i < last_c2; i++) { - { - ct[i].J_ij = (struct J_ij *) free_check_null(ct[i].J_ij); - ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); - } + ct[i].J_ij = (struct J_ij *) free_check_null(ct[i].J_ij); + if (il_calcs) + ct[i].J_ij_il = (struct J_ij *) free_check_null(ct[i].J_ij_il); + ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); + } return (OK); } @@ -2041,9 +2151,9 @@ int Phreeqc:: fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) /* ---------------------------------------------------------------------- */ { -/* sum up the primary or secondary master_species from solute species - * H and O go in tot1&2_h and tot1&2_o - */ + /* sum up the primary or secondary master_species from solute species + * H and O go in tot1&2_h and tot1&2_o + */ int j, k, l; char *ptr; @@ -2097,56 +2207,59 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* ---------------------------------------------------------------------- */ { /* mole transfer of the individual master_species: - * Eqn 1: - * J_ij = DDt * (A_ij / lav) * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) - * regular column, stagnant FALSE: - * D_i = temperature-corrected Dw - * A_ij = A_icell * A_jcell - * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / - * (length_icell / 2) - * lav = A_icell + A_jcell - * grad(c) is concentration difference in icell and jcell (dx is in lav), - for activity corrections see Appelo & Wersin, 2007. - * stagnant TRUE: - * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) - * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por - * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; - * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. - * Interlayer diffusion (IL) takes the gradient in the equivalent concentrations on X-. - surface area A for IL: - stagnant: mixf_il is mixf * por_il / por. - por_il = interlayer porosity, from -interlayer_D true 'por_il'. - por = total porosity, from -multi_D true 'multi_Dpor'. - **nov. 12, 2011**: - mixf is corrected, * (1 - por_il / por). - new_pf = (por - por_il)^(-multi_Dn). - in regular column, A is calc'd from (free + DL porewater) and cell-length. - for IL: A * por_il / (por - por_il). + * Eqn 1: + * J_ij = DDt * (A_ij / lav) * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * regular column, stagnant FALSE: + * D_i = temperature-corrected Dw + * A_ij = A_icell * A_jcell + * A_icell = (L porewater in i_cell / length_icell) / tort_f_icell / + * (length_icell / 2) + * lav = A_icell + A_jcell + * grad(c) is concentration difference in icell and jcell (dx is in lav), + for activity corrections see Appelo & Wersin, 2007. + ** dec. 28, 2015** + included aq_dl in the harmonic mean: + J_ij = - b_i * b_j / (b_i + b_j) * (c_j - c_i) in mol/s (see ex 21 in the manual 3). + b_i = A_i / (G_i * h_i / 2) * Dw for a pore without EDL. A_i = aq_i / h_i (m^2). + with EDL (no aq_il_i in A_i, for now): + aqt_i = aq_i + aq_dl_i. A_i = aqt_i / h_i. f_free_i = aq_i / aqt_i. + b_i_cat = A_i / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) * Bm}. Bm = Boltzmann enrichment in EDL = g_dl. + b_i_ani = A_i / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) / Bm)}. + * stagnant TRUE: + * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por + * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; + * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. + * Interlayer diffusion (IL) takes the gradient in the equivalent concentrations on X-. + surface area A for IL: + stagnant: ct[icell].mixf_il is mixf * por_il / por. + por_il = interlayer porosity, from -interlayer_D true 'por_il'. + por = total porosity, from -multi_D true 'multi_Dpor'. + **nov. 12, 2011**: + mixf is corrected, * (1 - por_il / por). + new_pf = (por - por_il)^(-multi_Dn). + in regular column, A is calc'd from (free + DL porewater) and cell-length. + for IL: A * por_il / (por - por_il). - por_il is entered as a single value. It is limited to 0.999 * por. - por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) + por_il is entered as a single value. It is limited to 0.999 * por. + por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) - IL-water = (free + DL porewater) * por_il / (por - por_il). - */ + IL-water = (free + DL porewater) * por_il / (por - por_il). + */ int i, i_max, j, j_max, k, k_il, only_counter, il_calcs; int i1; - LDBLE lav, A1, A2, A_ij_il, ddlm, aq1, aq2, mixf_il; - LDBLE dl_aq1, dl_aq2, c_dl, dum, dum2, tort1, tort2; - LDBLE c, Dz2c_il, aq_il1, aq_il2; + LDBLE A_i, A_j, ddlm, aq_i, aq_j, aqt_i, aqt_j, f_free_i, f_free_j; + LDBLE dl_aq_i, dl_aq_j, c_dl, dum, dum1, dum2, tort_i, tort_j, b_i, b_j; + LDBLE Sum_zM, aq_il1, aq_il2; LDBLE por_il1, por_il2, por_il12; LDBLE cec1, cec2, cec12, rc1, rc2; LDBLE dV, c1, c2; - struct V_M *V_M_il; - cxxSurface *s_ptr1, *s_ptr2; cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; + LDBLE g, g_i, g_j; char token[MAX_LENGTH], token1[MAX_LENGTH]; - k_il = 0; - A_ij_il = mixf_il = 0.0; - Dz2c_il = 0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; - V_M_il = NULL; dV = 0.0; /* check for immediate return and interlayer diffusion calcs... */ @@ -2156,11 +2269,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (icell == 0 && cell_data[1].por_il < interlayer_Dpor_lim) il_calcs = 0; else if (icell == count_cells && - cell_data[count_cells].por_il < interlayer_Dpor_lim) + cell_data[count_cells].por_il < interlayer_Dpor_lim) il_calcs = 0; else if (icell > 0 - && (cell_data[icell].por_il < interlayer_Dpor_lim - || cell_data[jcell].por_il < interlayer_Dpor_lim)) + && (cell_data[icell].por_il < interlayer_Dpor_lim + || cell_data[jcell].por_il < interlayer_Dpor_lim)) il_calcs = 0; } else @@ -2169,11 +2282,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dV_dcell && !find_current) goto dV_dcell2; - ct[icell].v_m = V_M_il = NULL; + ct[icell].v_m = ct[icell].v_m_il = NULL; if (stagnant) { if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim - || cell_data[jcell].por < multi_Dpor_lim)) + || cell_data[jcell].por < multi_Dpor_lim)) return (OK); } else @@ -2191,20 +2304,20 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else { if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim - || cell_data[jcell].por < multi_Dpor_lim)) + || cell_data[jcell].por < multi_Dpor_lim)) return (OK); } } /* do the calcs */ - aq1 = Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mass_water(); - aq2 = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mass_water(); + aq_i = Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mass_water(); + aq_j = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mass_water(); /* - * check if DL calculations must be made, find amounts of water... - */ + * check if DL calculations must be made, find amounts of water... + */ s_charge_ptr1 = s_charge_ptr2 = NULL; s_ptr1 = s_ptr2 = NULL; - ct[icell].dl_s = dl_aq1 = dl_aq2 = 0.0; + ct[icell].dl_s = dl_aq_i = dl_aq_j = 0.0; ct[icell].visc1 = ct[icell].visc2 = 1.0; only_counter = FALSE; @@ -2216,16 +2329,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (s_ptr1->Get_only_counter_ions()) only_counter = TRUE; /* find the one (and only one...) immobile surface comp with DL... */ - for (i = 0; i < (int) s_ptr1->Get_surface_comps().size(); i++) + for (i = 0; i < (int)s_ptr1->Get_surface_comps().size(); i++) { cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); if (comp_i_ptr->Get_Dw() == 0) { s_charge_ptr1 = s_ptr1->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq1 = s_charge_ptr1->Get_mass_water(); + dl_aq_i = s_charge_ptr1->Get_mass_water(); ct[icell].visc1 = s_ptr1->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int) s_ptr1->Get_surface_comps().size(); j++) + for (j = i + 1; j < (int)s_ptr1->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr1->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 @@ -2234,12 +2347,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (!warn_fixed_Surf) { - k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + k = (int)strcspn(comp_i_ptr->Get_formula().c_str(), "_"); strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); + token1); warning_msg(token); warn_fixed_Surf = 1; } @@ -2258,16 +2371,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (s_ptr2->Get_only_counter_ions()) only_counter = TRUE; - for (i = 0; i < (int) s_ptr2->Get_surface_comps().size(); i++) + for (i = 0; i < (int)s_ptr2->Get_surface_comps().size(); i++) { cxxSurfaceComp * comp_i_ptr = &(s_ptr2->Get_surface_comps()[i]); if (comp_i_ptr->Get_Dw() == 0) { s_charge_ptr2 = s_ptr2->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq2 = s_charge_ptr2->Get_mass_water(); + dl_aq_j = s_charge_ptr2->Get_mass_water(); ct[icell].visc2 = s_ptr2->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int) s_ptr2->Get_surface_comps().size(); j++) + for (j = i + 1; j < (int)s_ptr2->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr2->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 @@ -2276,7 +2389,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (!warn_fixed_Surf) { - k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + k = (int)strcspn(comp_i_ptr->Get_formula().c_str(), "_"); strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, @@ -2301,34 +2414,38 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].visc2 = ct[icell].visc1; } /* in each cell: DL surface = mass_water_DL / (cell_length) - free pore surface = mass_water_free / (cell_length) - determine DL surface as a fraction of the total pore surface... */ - if (dl_aq1 > 0) - ct[icell].dl_s = dl_aq1 / (dl_aq1 + aq1); - if (dl_aq2 > 0) + free pore surface = mass_water_free / (cell_length) + determine DL surface as a fraction of the total pore surface... */ + if (dl_aq_i > 0) + ct[icell].dl_s = dl_aq_i / (dl_aq_i + aq_i); + if (dl_aq_j > 0) { - dum = dl_aq2 / (dl_aq2 + aq2); - if (dl_aq1 > 0) - /* average the 2... */ + dum = dl_aq_j / (dl_aq_j + aq_j); + if (dl_aq_i > 0) + /* average the 2... */ ct[icell].dl_s = (ct[icell].dl_s + dum) / 2; else - /* there is one DL surface... */ + /* there is one DL surface... */ ct[icell].dl_s = dum; } + aqt_i = aq_i + dl_aq_i; + aqt_j = aq_j + dl_aq_j; + f_free_i = aq_i / aqt_i; + f_free_j = aq_j / aqt_j; - por_il1 = por_il2 = por_il12 = 0.0; - cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; if (il_calcs) { /* find interlayer porosity por_il, - make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). - Find amounts of IL water and cec. - Must do this separately, since por and por_il are in cell_data structure. */ + make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). + Find amounts of IL water and cec. + Must do this separately, since por and por_il are in cell_data structure. */ + por_il1 = por_il2 = por_il12 = 0.0; + cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; if (icell == 0) { - por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * + por_il1 = sol_D[0].exch_total / aq_i / sol_D[1].x_max * cell_data[1].por_il; - por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * + por_il2 = sol_D[1].exch_total / aq_j / sol_D[1].x_max * cell_data[1].por_il; if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) /* take the average... */ @@ -2341,16 +2458,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (por_il2 > 0.999 * cell_data[1].por) por_il2 = 0.999 * cell_data[1].por; - aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[1].por - por_il2); + aq_il2 = (aq_j + dl_aq_j) * por_il2 / + (cell_data[1].por - por_il2); /* Assume interlayer water is proportional with CEC... */ aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; } else if (icell == count_cells) { - por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * + por_il1 = sol_D[count_cells].exch_total / aq_i / sol_D[1].x_max * cell_data[count_cells].por_il; - por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * + por_il2 = sol_D[count_cells + 1].exch_total / aq_j / sol_D[1].x_max * cell_data[count_cells].por_il; if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) por_il12 = (por_il1 + por_il2) / 2; @@ -2361,16 +2478,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (por_il1 > 0.999 * cell_data[count_cells].por) por_il1 = 0.999 * cell_data[count_cells].por; - aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[count_cells].por - por_il1); + aq_il1 = (aq_i + dl_aq_i) * por_il1 / + (cell_data[count_cells].por - por_il1); aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / sol_D[count_cells].exch_total; } else { - por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * + por_il1 = sol_D[icell].exch_total / aq_i / sol_D[1].x_max * cell_data[icell].por_il; - por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * + por_il2 = sol_D[jcell].exch_total / aq_j / sol_D[1].x_max * cell_data[jcell].por_il; if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) @@ -2379,12 +2496,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); if (por_il12 > 0.999 * cell_data[icell].por || por_il12 > 0.999 * cell_data[jcell].por) por_il12 = (cell_data[icell].por >= cell_data[jcell].por ? - 0.999 * cell_data[jcell].por : - 0.999 * cell_data[icell].por); - aq_il1 = (aq1 + dl_aq1) * por_il1 / - (cell_data[icell].por - por_il1); - aq_il2 = (aq2 + dl_aq2) * por_il2 / - (cell_data[jcell].por - por_il2); + 0.999 * cell_data[jcell].por : + 0.999 * cell_data[icell].por); + aq_il1 = (aq_i + dl_aq_i) * por_il1 / + (cell_data[icell].por - por_il1); + aq_il2 = (aq_j + dl_aq_j) * por_il2 / + (cell_data[jcell].por - por_il2); } if (por_il12 == 0) il_calcs = 0; @@ -2407,18 +2524,19 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } - /* In stagnant calc's, find mixf_il for IL diffusion, correct mixf. - In regular column, find surface areas A and A_il */ - tort1 = tort2 = lav = 1.0; - ct[icell].A_ij = A_ij_il = mixf_il = 0.0; + /* In stagnant calc's, find ct[icell].mixf_il for IL diffusion, correct mixf. + In regular column, find surface areas A_i, j and A_il */ + + tort_i = tort_j = 1.0; + ct[icell].A_ij_il = ct[icell].mixf_il = 0.0; if (stagnant) { mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); dum = (cell_data[icell].por <= cell_data[jcell].por ? - cell_data[icell].por : cell_data[jcell].por); + cell_data[icell].por : cell_data[jcell].por); if (il_calcs) { - mixf_il = mixf * por_il12 / interlayer_tortf; + ct[icell].mixf_il = mixf * por_il12 / interlayer_tortf; dum -= por_il12; } mixf *= (dum * pow(dum, multi_Dn)); @@ -2427,61 +2545,66 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { /* regular column... */ if (icell == 0) { - tort1 = tort2 = pow(cell_data[1].por, -multi_Dn); - lav = cell_data[1].length; - ct[icell].A_ij = (aq2 + dl_aq2) / (lav * 0.5 * lav); + tort_i = tort_j = pow(cell_data[1].por, -multi_Dn); + A_j = aqt_j / + (cell_data[1].length * 0.5 * cell_data[1].length); + if (il_calcs) - A_ij_il = - ct[icell].A_ij * por_il12 / ((cell_data[1].por - por_il12) * - interlayer_tortf); - ct[icell].A_ij /= tort1; + ct[icell].A_ij_il = A_j * por_il12 / + ((cell_data[1].por - por_il12) * interlayer_tortf); + + + A_j /= tort_j; + A_i = A_j; } else if (icell == count_cells) { - tort1 = tort2 = pow(cell_data[count_cells].por, -multi_Dn); - lav = cell_data[count_cells].length; - ct[icell].A_ij = (aq1 + dl_aq1) / (lav * 0.5 * lav); + tort_i = tort_j = pow(cell_data[count_cells].por, -multi_Dn); + A_i = aqt_i / + (cell_data[count_cells].length * 0.5 * cell_data[count_cells].length); + if (il_calcs) - A_ij_il = ct[icell].A_ij * por_il12 / - ((cell_data[count_cells].por - por_il12) * interlayer_tortf); - ct[icell].A_ij /= tort2; + ct[icell].A_ij_il = A_i * por_il12 / + ((cell_data[count_cells].por - por_il12) * interlayer_tortf); + + A_i /= tort_i; + A_j = A_i; } else { - tort1 = pow(cell_data[icell].por, -multi_Dn); - tort2 = pow(cell_data[jcell].por, -multi_Dn); - A1 = (aq1 + dl_aq1) / (cell_data[icell].length * - 0.5 * cell_data[icell].length); - A2 = (aq2 + dl_aq2) / (cell_data[jcell].length * - 0.5 * cell_data[jcell].length); + tort_i = pow(cell_data[icell].por, -multi_Dn); + tort_j = pow(cell_data[jcell].por, -multi_Dn); + A_i = aqt_i / + (cell_data[icell].length * 0.5 * cell_data[icell].length) / tort_i; + + A_j = aqt_j / + (cell_data[jcell].length * 0.5 * cell_data[jcell].length) / tort_j; + if (il_calcs) { - dum = A1 * por_il12 / + dum = A_i * por_il12 / ((cell_data[icell].por - por_il12) * interlayer_tortf); - dum2 = A2 * por_il12 / + dum2 = A_j * por_il12 / ((cell_data[jcell].por - por_il12) * interlayer_tortf); - A_ij_il = dum * dum2 / (dum + dum2); + ct[icell].A_ij_il = dum * dum2 / (dum + dum2); } - A1 /= tort1; - A2 /= tort2; - ct[icell].A_ij = A1 * A2 / (A1 + A2); } } /* diffuse... */ ct[icell].J_ij_count_spec = 0; ct[icell].J_ij_sum = 0.0; /* - * malloc sufficient space... - */ + * malloc sufficient space... + */ k = sol_D[icell].count_spec + sol_D[jcell].count_spec; ct[icell].J_ij = (struct J_ij *) free_check_null(ct[icell].J_ij); - ct[icell].J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); + ct[icell].J_ij = (struct J_ij *) PHRQ_malloc((size_t)k * sizeof(struct J_ij)); if (ct[icell].J_ij == NULL) malloc_error(); ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); - ct[icell].v_m = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); + ct[icell].v_m = (struct V_M *) PHRQ_malloc((size_t)k * sizeof(struct V_M)); if (ct[icell].v_m == NULL) malloc_error(); @@ -2499,38 +2622,39 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[i].g_dl = 1.0; ct[icell].v_m[i].o_c = 1; } - ct[icell].Dz2c = ct[icell].Dz2c_dl = Dz2c_il = 0.0; + ct[icell].Dz2c = ct[icell].Dz2c_dl = ct[icell].Dz2c_il = 0.0; if (il_calcs) { /* also for interlayer cations */ k = sol_D[icell].count_exch_spec + sol_D[jcell].count_exch_spec; - J_ij_il = (struct J_ij *) free_check_null(J_ij_il); - J_ij_il = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); - if (J_ij_il == NULL) + ct[icell].J_ij_il = (struct J_ij *) free_check_null(ct[icell].J_ij_il); + ct[icell].J_ij_il = (struct J_ij *) PHRQ_malloc((size_t)k * sizeof(struct J_ij)); + if (ct[icell].J_ij_il == NULL) malloc_error(); - V_M_il = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); - if (V_M_il == NULL) + ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); + ct[icell].v_m_il = (struct V_M *) PHRQ_malloc((size_t)k * sizeof(struct V_M)); + if (ct[icell].v_m_il == NULL) malloc_error(); for (i = 0; i < k; i++) { - J_ij_il[i].tot1 = 0.0; - V_M_il[i].grad = 0.0; - V_M_il[i].D = 0.0; - V_M_il[i].z = 0.0; - V_M_il[i].zc = 0.0; - V_M_il[i].Dz = 0.0; - V_M_il[i].Dzc = 0.0; - V_M_il[i].Dzc_dl = 0.0; - V_M_il[i].g_dl = 1.0; - V_M_il[i].o_c = 1; + ct[icell].J_ij_il[i].tot1 = 0.0; + ct[icell].v_m_il[i].grad = 0.0; + ct[icell].v_m_il[i].D = 0.0; + ct[icell].v_m_il[i].z = 0.0; + ct[icell].v_m_il[i].zc = 0.0; + ct[icell].v_m_il[i].Dz = 0.0; + ct[icell].v_m_il[i].Dzc = 0.0; + //ct[icell].v_m_il[i].Dzc_dl = 0.0; + //ct[icell].v_m_il[i].g_dl = 1.0; + //ct[icell].v_m_il[i].o_c = 1; } } /* - * coefficients in Eqn (1)... - */ + * coefficients in Eqn (1)... + */ i = j = k = k_il = 0; i_max = sol_D[icell].count_spec; j_max = sol_D[jcell].count_spec; @@ -2539,263 +2663,357 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (j == j_max || (i < i_max - && strcmp(sol_D[icell].spec[i].name, - sol_D[jcell].spec[j].name) < 0)) + && strcmp(sol_D[icell].spec[i].name, + sol_D[jcell].spec[j].name) < 0)) { /* species 'name' is only in icell */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - J_ij_il[k_il].name = sol_D[icell].spec[i].name; - V_M_il[k_il].D = sol_D[icell].spec[i].Dwt; - V_M_il[k_il].z = sol_D[icell].spec[i].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - dum = sol_D[icell].spec[i].c * cec12 / (2 * V_M_il[k_il].z); - V_M_il[k_il].Dzc = V_M_il[k_il].Dz * dum; - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + ct[icell].J_ij_il[k_il].name = sol_D[icell].spec[i].name; + ct[icell].v_m_il[k_il].D = sol_D[icell].spec[i].Dwt; + ct[icell].v_m_il[k_il].z = sol_D[icell].spec[i].z; + ct[icell].v_m_il[k_il].Dz = ct[icell].v_m_il[k_il].D * ct[icell].v_m_il[k_il].z; + dum = sol_D[icell].spec[i].c * cec12 / (2 * ct[icell].v_m_il[k_il].z); + ct[icell].v_m_il[k_il].Dzc = ct[icell].v_m_il[k_il].Dz * dum; + ct[icell].Dz2c_il += ct[icell].v_m_il[k_il].Dzc * ct[icell].v_m_il[k_il].z; + ct[icell].v_m_il[k_il].grad = -sol_D[icell].spec[i].c * cec12 / ct[icell].v_m_il[k_il].z; /* use equivalent fraction */ k_il++; } else { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ - c1 = sol_D[icell].spec[i].c / 2; - if (dV_dcell) + if (stagnant) { - // compare diffuse and electromotive forces - dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1 * dV_dcell; - // don't transport unavailable moles against the gradient - if (-dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z > 0) // no transport against the dV_dcell gradient if c = 0 in jcell - c1 = 0; - } - ct[icell].v_m[k].c = c1; - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; - if (ct[icell].dl_s > 0) - { - s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - LDBLE g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + c1 = sol_D[icell].spec[i].c / 2; + ct[icell].v_m[k].c = c1; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; + + if (ct[icell].dl_s > 0) { + s_charge_ptr = (dl_aq_i > 0) ? s_charge_ptr1 : s_charge_ptr2; + g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (only_counter) { - if (only_counter) + if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) { - if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - ct[icell].v_m[k].g_dl = 1.0; - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; - } + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; + } + else + { + if (dl_aq_i > 0) + { + ct[icell].v_m[k].g_dl = (1 + g * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + ct[icell].v_m[k].Dzc_dl = + ct[icell].v_m[k].Dz * c1 * ct[icell].v_m[k].g_dl; } else - { - if (dl_aq1 > 0) - { - ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - ct[icell].v_m[k].Dzc_dl = - ct[icell].v_m[k].Dz * c1 * ct[icell].v_m[k].g_dl; - } - else - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; - } - //break; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; + } + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + } + ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + k++; + } + else // regular column + { + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + c1 = sol_D[icell].spec[i].c / 2; + if (dV_dcell) + { + // compare diffusive and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1 * dV_dcell; + if (-dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z > 0) + { + // step out: no transport against the dV_dcell gradient if c = 0 in jcell... + if (i < i_max) + i++; + continue; } } - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + g_i = g_j = dum2 = 0; + if (ct[icell].dl_s > 0) + { + if (ct[icell].v_m[k].z) + { + if (dl_aq_i > 0) + g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (dl_aq_j > 0) + { + if (abs(ct[icell].v_m[k].z) == 1) + // there is always H+ and OH-... + g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + else + { + dum = ct[icell].v_m[k].z > 0 ? 1 : -1; + g_j = s_charge_ptr2->Get_g_map()[dum].Get_g(); + g_j = pow((1 + g_j * aq_j / dl_aq_j), ct[icell].v_m[k].z) - 1; + } + } + } + if (only_counter) + { + s_charge_ptr = (dl_aq_i > 0) ? s_charge_ptr1 : s_charge_ptr2; + if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) + { + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... + dum2 = 1; + } + else + { + if (dl_aq_i > 0) + ct[icell].v_m[k].g_dl = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + if (dl_aq_j) + dum2 = (1 + g_j * aq_j / dl_aq_j) * sol_D[icell].spec[i].erm_ddl; + } + } + b_i = A_i * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_j = A_j * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + if (icell == 0) + ct[icell].v_m[k].b_ij = b_j; + else if (icell == count_cells) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + + ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; + + ct[icell].v_m[k].c = c1; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + k++; } - ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - k++; } if (i < i_max) i++; } - else if (i == i_max - || (j < j_max - && strcmp(sol_D[icell].spec[i].name, - sol_D[jcell].spec[j].name) > 0)) + + else if (i == i_max || + (j < j_max && strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) > 0)) { /* species 'name' is only in jcell */ if (il_calcs && sol_D[jcell].spec[j].type == EX) { - J_ij_il[k_il].name = sol_D[jcell].spec[j].name; - V_M_il[k_il].D = sol_D[jcell].spec[j].Dwt; - V_M_il[k_il].z = sol_D[jcell].spec[j].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * sol_D[jcell].spec[j].c * cec12 / (2 * - V_M_il - [k_il]. - z); - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = sol_D[jcell].spec[j].c * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + ct[icell].J_ij_il[k_il].name = sol_D[jcell].spec[j].name; + ct[icell].v_m_il[k_il].D = sol_D[jcell].spec[j].Dwt; + ct[icell].v_m_il[k_il].z = sol_D[jcell].spec[j].z; + ct[icell].v_m_il[k_il].Dz = ct[icell].v_m_il[k_il].D * ct[icell].v_m_il[k_il].z; + ct[icell].v_m_il[k_il].Dzc = ct[icell].v_m_il[k_il].Dz * sol_D[jcell].spec[j].c * + cec12 / (2 * ct[icell].v_m_il[k_il].z); + ct[icell].Dz2c_il += ct[icell].v_m_il[k_il].Dzc * ct[icell].v_m_il[k_il].z; + ct[icell].v_m_il[k_il].grad = sol_D[jcell].spec[j].c * cec12 / ct[icell].v_m_il[k_il].z; /* use equivalent fraction */ k_il++; } else { - ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; - ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; - ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ - c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell) + if (stagnant) { - // compare diffuse and electromotive forces - dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2 * dV_dcell; - // don't transport unavailable moles against the gradient - if (dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z < 0) // no transport against the dV_dcell gradient if c = 0 in jcell - c2 = 0; - } - ct[icell].v_m[k].c = c2; - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; - if (ct[icell].dl_s > 0) - { - s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - LDBLE g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; + ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; + ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + c2 = sol_D[jcell].spec[j].c / 2; + ct[icell].v_m[k].c = c2; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; + + if (ct[icell].dl_s > 0) { + s_charge_ptr = (dl_aq_j > 0) ? s_charge_ptr2 : s_charge_ptr1; + g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (only_counter) { - if (only_counter) + if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) { - if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - ct[icell].v_m[k].g_dl = 1.0; - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; - } + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; + } + else + { + if (dl_aq_j > 0) + { + ct[icell].v_m[k].g_dl = (1 + g * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; + ct[icell].v_m[k].Dzc_dl = + ct[icell].v_m[k].Dz * c2 * ct[icell].v_m[k].g_dl; } else - { - if (dl_aq2 > 0) - { - ct[icell].v_m[k].g_dl = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; - ct[icell].v_m[k].Dzc_dl = - ct[icell].v_m[k].Dz * c2 * ct[icell].v_m[k].g_dl; - } - else - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; - } - //break; + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; + } + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + } + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + k++; + } + else // regular column + { + ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; + ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; + ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + c2 = sol_D[jcell].spec[j].c / 2; + if (dV_dcell) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2 * dV_dcell; + // don't transport unavailable moles against the gradient + if (dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z < 0) + { + // step out... + if (j < j_max) + j++; + continue; } } - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + + g_i = g_j = dum1 = 0; + if (ct[icell].dl_s > 0) + { + if (ct[icell].v_m[k].z) + { + if (dl_aq_j > 0) + g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (dl_aq_i > 0) + { + if (abs(ct[icell].v_m[k].z) == 1) + g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + else + { + dum = ct[icell].v_m[k].z > 0 ? 1 : -1; + g_i = s_charge_ptr1->Get_g_map()[dum].Get_g(); + g_i = pow((1 + g_i * aq_i / dl_aq_i), ct[icell].v_m[k].z) - 1; + } + } + } + if (only_counter) + { + s_charge_ptr = (dl_aq_j > 0) ? s_charge_ptr2 : s_charge_ptr1; + if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) + { + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... + dum1 = 1; + } + else + { + if (dl_aq_j) + ct[icell].v_m[k].g_dl = (1 + g_j * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; + if (dl_aq_i) + dum1 = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + } + } + b_i = A_i * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); + b_j = A_j * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); + if (icell == 0) + ct[icell].v_m[k].b_ij = b_j; + else if (icell == count_cells) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + + ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; + + ct[icell].v_m[k].c = c2; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + k++; } - ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - k++; } if (j < j_max) j++; } - else if (strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) - == 0) + else if (strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) == 0) { /* species 'name' is in both cells */ if (il_calcs && sol_D[icell].spec[i].type == EX) { - J_ij_il[k_il].name = sol_D[icell].spec[i].name; - if (sol_D[icell].spec[i].Dwt == 0 - || sol_D[jcell].spec[j].Dwt == 0) - V_M_il[k_il].D = 0.0; + ct[icell].J_ij_il[k_il].name = sol_D[icell].spec[i].name; + if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) + ct[icell].v_m_il[k_il].D = 0.0; else - V_M_il[k_il].D = - (sol_D[icell].spec[i].Dwt + - sol_D[jcell].spec[j].Dwt) / 2; + ct[icell].v_m_il[k_il].D = + (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - V_M_il[k_il].z = sol_D[icell].spec[i].z; - V_M_il[k_il].Dz = V_M_il[k_il].D * V_M_il[k_il].z; - V_M_il[k_il].Dzc = - V_M_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + - sol_D[jcell].spec[j].c * cec2) / (2 * - V_M_il - [k_il]. - z); - Dz2c_il += V_M_il[k_il].Dzc * V_M_il[k_il].z; - V_M_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * cec12 / V_M_il[k_il].z; /* use equivalent fraction */ + ct[icell].v_m_il[k_il].z = sol_D[icell].spec[i].z; + ct[icell].v_m_il[k_il].Dz = ct[icell].v_m_il[k_il].D * ct[icell].v_m_il[k_il].z; + ct[icell].v_m_il[k_il].Dzc = ct[icell].v_m_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + + sol_D[jcell].spec[j].c * cec2) / (2 * ct[icell].v_m_il[k_il].z); + ct[icell].Dz2c_il += ct[icell].v_m_il[k_il].Dzc * ct[icell].v_m_il[k_il].z; + ct[icell].v_m_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * + cec12 / ct[icell].v_m_il[k_il].z; /* use equivalent fraction */ k_il++; } else { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - if (sol_D[icell].spec[i].Dwt == 0 - || sol_D[jcell].spec[j].Dwt == 0) - ct[icell].v_m[k].D = 0.0; - else - ct[icell].v_m[k].D = - (sol_D[icell].spec[i].Dwt + - sol_D[jcell].spec[j].Dwt) / 2; - - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); - c1 = sol_D[icell].spec[i].c / 2; - c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell) + if (stagnant) { - // compare diffuse and electromotive forces - dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2) * dV_dcell; - // don't transport unavailable moles against the gradient - if (abs(dum) < abs(dum2) && - ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || - (dum2 <= 0 && sol_D[icell].spec[i].c * aq1 < 1e-12))) - { - c1 = 0; - c2 = 0; - } - } - ct[icell].v_m[k].c = (c1 + c2); - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * (c1 + c2); - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * (c1 + c2); + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) + ct[icell].v_m[k].D = 0.0; + else + ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - if (ct[icell].dl_s > 0) - { - c_dl = 0.0; - if (dl_aq1 > 0) + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + c1 = sol_D[icell].spec[i].c / 2; + c2 = sol_D[jcell].spec[j].c / 2; + ct[icell].v_m[k].c = (c1 + c2); + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * ct[icell].v_m[k].c; + + if (ct[icell].dl_s > 0) { - LDBLE g = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + c_dl = 0.0; + if (dl_aq_i > 0) { + g = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (only_counter) { - if (only_counter) + if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) { - if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - ct[icell].v_m[k].g_dl = 1.0; - c_dl = c1; - } + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].Dzc_dl = 0; + ct[icell].v_m[k].g_dl = 0; } - else - { - ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - c_dl = c1 * ct[icell].v_m[k].g_dl; - } - //break; + else /* assume for counter ions in the DDL the free pore space conc's... */ + c_dl = c1; + } + else + { + ct[icell].v_m[k].g_dl = (1 + g * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + c_dl = c1 * ct[icell].v_m[k].g_dl; } } - } - else - c_dl = c1; + else + c_dl = c1; - if (dl_aq2 > 0) - { - LDBLE g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + if (dl_aq_j > 0) { + g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { if (only_counter) { @@ -2814,25 +3032,115 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - dum = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; + dum = (1 + g * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; c_dl += c2 * dum; ct[icell].v_m[k].g_dl = (ct[icell].v_m[k].g_dl + dum) / 2; } - //break; + } + } + else if (ct[icell].v_m[k].o_c == 1) + c_dl += c2; + + ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c_dl; + ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + } + ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; + if (fabs(ddlm) > 1e-10) + ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); + k++; + } + else // regular column + { + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + c1 = sol_D[icell].spec[i].c / 2; + c2 = sol_D[jcell].spec[j].c / 2; + if (dV_dcell) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2) * dV_dcell; + // don't transport unavailable moles against the gradient + if (abs(dum) < abs(dum2) && + ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq_j < 1e-12) || + (dum2 <= 0 && sol_D[icell].spec[i].c * aq_i < 1e-12))) + { + // step out: + if (i < i_max) + i++; + if (j < j_max) + j++; + continue; + } + } + ct[icell].v_m[k].c = (c1 + c2); + g_i = g_j = dum2 = 0; + if (ct[icell].dl_s > 0) + { + if (dl_aq_i > 0) + { + if (only_counter) + { + if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) + { + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + //else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... + } + else + { + g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + ct[icell].v_m[k].g_dl = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + } + } + + if (dl_aq_j > 0) + { + if (only_counter) + { + if (s_charge_ptr2->Get_la_psi() * ct[icell].v_m[k].z > 0) + { + ct[icell].v_m[k].o_c = 0; + ct[icell].v_m[k].g_dl = 0; + } + else /* assume for counter ions in the DDL the free pore space conc's... */ + dum2 = 1.0; + } + else + { + g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + dum2 = (1 + g_j * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; } } } - else if (ct[icell].v_m[k].o_c == 1) - c_dl += c2; + b_i = A_i * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_j = A_j * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + if (icell == 0) + ct[icell].v_m[k].b_ij = b_j; + else if (icell == count_cells) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c_dl; - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; + if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) + ct[icell].v_m[k].D = 0.0; + else + ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; + + ct[icell].v_m[k].c = c1 + c2; + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; + ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; + ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * ct[icell].v_m[k].c; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + + ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; + if (fabs(ddlm) > 1e-10) + ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); + k++; } - ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; - if (fabs(ddlm) > 1e-10) - ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); - k++; } if (i < i_max) i++; @@ -2841,179 +3149,142 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } /* - * fill in J_ij... - */ - if (ct[icell].Dz2c == 0) + * fill in J_ij... + */ + if (!dV_dcell && !ct[icell].Dz2c) k = 0; ct[icell].J_ij_count_spec = i_max = k; + ct[icell].J_ij_il_count_spec = k_il; - // dV_dcell, 2nd pass, current_x has been calculated, but needs - // V_M, dl_s, A_ij, Dz2c, Dz2c_dl, J_ij_count_spec, visc1, visc2... -dV_dcell2 : - - ct[icell].J_ij_sum = 0; - c = c_dl = 0.0; - LDBLE D_harm = 0, zspec = 0; if (dV_dcell) { - //current_cells[icell].dif = 0; // including dif in dV gives higher percent error - current_cells[icell].ele = 0; - } - - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - ct[icell].J_ij[i].tot1 = 0; - if (!ct[icell].v_m[i].c) - continue; - c += ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; - c_dl += ct[icell].v_m[i].o_c * ct[icell].v_m[i].Dz * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; - - if (dV_dcell) + current_cells[icell].ele = current_cells[icell].dif = 0; + dum = dV_dcell * F_Re3 / tk_x2; + for (i = 0; i < ct[icell].J_ij_count_spec; i++) { if (!ct[icell].v_m[i].z) continue; - zspec += abs(ct[icell].v_m[i].zc); - D_harm += 1e-9 * abs(ct[icell].v_m[i].zc) / ct[icell].v_m[i].D; + current_cells[icell].ele -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * + ct[icell].v_m[i].zc * ct[icell].v_m[i].D * dum; + current_cells[icell].dif -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * + ct[icell].v_m[i].D * ct[icell].v_m[i].grad; } - } - if (D_harm) - D_harm = zspec * 1e-9 / D_harm; - - if (dV_dcell && !find_current) // correct dV to get equal current for all cells... - { - dV = cell_data[jcell].potV - cell_data[icell].potV; - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - if (!ct[icell].v_m[i].c || !ct[icell].v_m[i].z) - continue; - //current_cells[icell].dif -= ct[icell].v_m[i].z * D_harm * ct[icell].v_m[i].grad * - // (1 - ct[icell].dl_s); - current_cells[icell].ele -= ct[icell].v_m[i].z * ct[icell].v_m[i].zc * D_harm * dV * - F_Re3 / tk_x2 * (1 - ct[icell].dl_s); - if (ct[icell].dl_s > 0) - { - // assume D_harm_dl equal to D_harm - dum = -D_harm * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; - dum2 = ct[icell].v_m[i].z * ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * D_harm * - dV * F_Re3 / tk_x2; - //current_cells[icell].dif += ct[icell].v_m[i].z * ct[icell].v_m[i].o_c * dum * 2 / - // (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - current_cells[icell].ele -= ct[icell].v_m[i].o_c * dum2 * 2 / - (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - } - } - //current_cells[icell].ele += current_cells[icell].dif; - dV *= current_x / (current_cells[icell].ele * ct[icell].A_ij * DDt); - } - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - if (!ct[icell].v_m[i].c) - continue; - ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].D * ct[icell].v_m[i].grad; - if (ct[icell].v_m[i].z && ct[icell].Dz2c > 0) - ct[icell].J_ij[i].tot1 += c * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; - ct[icell].J_ij[i].tot1 *= (1 - ct[icell].dl_s); - if (ct[icell].dl_s > 0) - { - dum = -ct[icell].v_m[i].D * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; - if (ct[icell].Dz2c_dl > 0) - dum2 = c_dl * ct[icell].v_m[i].Dzc_dl / ct[icell].Dz2c_dl; - else - dum2 = 0; - if ((ct[icell].J_ij[i].tot1 <= 0 && dum <= 0) - || (ct[icell].J_ij[i].tot1 > 0 && dum > 0)) - { - ct[icell].J_ij[i].tot1 += ct[icell].v_m[i].o_c * (dum + dum2) * 2 / - (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - } - } - if (ct[icell].v_m[i].z) - { - if (find_current) - { - //current_cells[icell].dif -= ct[icell].v_m[i].z * D_harm * - // ct[icell].v_m[i].grad * (1 - ct[icell].dl_s); - current_cells[icell].ele -= ct[icell].v_m[i].z * ct[icell].v_m[i].zc * D_harm * - dV_dcell * F_Re3 / tk_x2 * (1 - ct[icell].dl_s); - if (ct[icell].dl_s > 0) - { - // assume D_harm_dl equal to D_harm - dum2 = ct[icell].v_m[i].z * ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * D_harm * - dV_dcell * F_Re3 / tk_x2; - //current_cells[icell].dif += ct[icell].v_m[i].z * ct[icell].v_m[i].o_c * dum * 2 / - // (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - current_cells[icell].ele -= ct[icell].v_m[i].o_c * dum2 * 2 / - (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - } - } - else if (dV_dcell) - { - dum = D_harm * dV * F_Re3 / tk_x2; - ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].zc * dum * (1 - ct[icell].dl_s); - - dum2 = ct[icell].v_m[i].Dzc_dl / ct[icell].v_m[i].D * dum; - ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].o_c * dum2 * 2 / - (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - } - } - /* - * multiply with timestep... - * for stagnant, DDt = 1, the timestep is in mixf. - * NOTE (for stagnant). The timestep calculated in init_mix for MCD (by PHREEQC) must be equal - * or smaller than the timestep taken (by the user) for calculating mixf in MIX. - * Make this timestep small enough, consider the largest Dw in phreeqd.dat (usually H+). - * Dw used for calculating mixf must be given as default_Dw in the input file. - */ - if (stagnant) - ct[icell].J_ij[i].tot1 *= mixf; - else - ct[icell].J_ij[i].tot1 *= ct[icell].A_ij * DDt; - ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; - ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; - } - if (find_current) - { - //current_cells[icell].dif *= ct[icell].A_ij * DDt; - current_cells[icell].ele *= ct[icell].A_ij * DDt; - //current_cells[icell].ele += current_cells[icell].dif; - current_cells[icell].R = current_cells[0].ele / current_cells[icell].ele; + current_cells[icell].R = dV_dcell / current_cells[icell].ele; sum_R += current_cells[icell].R; + sum_Rd += (current_cells[0].dif - current_cells[icell].dif) * current_cells[icell].R; return(il_calcs); } + + // dV_dcell, 2nd pass, current_x has been calculated, and + // voltage has been adapted to give equal current in the cells. +dV_dcell2: + + ct[icell].J_ij_sum = 0; + Sum_zM = c_dl = 0.0; + + if (stagnant) + { + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (ct[icell].v_m[i].z) + { + Sum_zM += ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; + c_dl += ct[icell].v_m[i].o_c * ct[icell].v_m[i].Dz * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; + } + } + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + if (ct[icell].v_m[i].z && ct[icell].Dz2c > 0) + ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; + ct[icell].J_ij[i].tot1 *= (1 - ct[icell].dl_s); + if (ct[icell].dl_s > 0) + { + dum = -ct[icell].v_m[i].D * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; + if (ct[icell].Dz2c_dl > 0) + dum2 = c_dl * ct[icell].v_m[i].Dzc_dl / ct[icell].Dz2c_dl; + else + dum2 = 0; + if (ct[icell].J_ij[i].tot1 * dum >= 0) + ct[icell].J_ij[i].tot1 += ct[icell].v_m[i].o_c * (dum + dum2) * 2 / + (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; + } + ct[icell].J_ij[i].tot1 *= mixf; + } + } + else // diffusion in regular column + { + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (ct[icell].v_m[i].z) + Sum_zM += ct[icell].v_m[i].b_ij * ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; + } + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + if (abs(dV_dcell) < 1e-10 && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) + ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; + ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * DDt; + ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; + } + } + if (dV_dcell) { - current_A = current_x * F_C_MOL / DDt; + // perhaps adapt dV for getting equal current... + current_cells[icell].ele = current_cells[icell].dif = 0; + dV = cell_data[jcell].potV - cell_data[icell].potV; + dum = dV * F_Re3 / tk_x2; + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (!ct[icell].v_m[i].z) + continue; + current_cells[icell].ele -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * + ct[icell].v_m[i].zc * ct[icell].v_m[i].D * dum; + current_cells[icell].dif -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * + ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + } + dV *= (current_x - current_cells[icell].dif) / current_cells[icell].ele; + dum = dV * F_Re3 / tk_x2; + for (i = 0; i < ct[icell].J_ij_count_spec; i++) + { + if (!ct[icell].v_m[i].z) + continue; + ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].D * ct[icell].v_m[i].b_ij * + ct[icell].v_m[i].zc * dum * DDt; + } + current_A = current_x * F_C_MOL; } /* - * calculate interlayer mass transfer... - */ - if (il_calcs && Dz2c_il != 0 && k_il > 0) + * calculate interlayer mass transfer... + */ + if (il_calcs && ct[icell].Dz2c_il != 0 && ct[icell].J_ij_il_count_spec > 0) { cxxExchange *ex_ptr1 = Utilities::Rxn_find(Rxn_exchange_map, icell); cxxExchange *ex_ptr2 = Utilities::Rxn_find(Rxn_exchange_map, jcell); - c = 0.0; - i_max = k_il; + Sum_zM = 0.0; + i_max = k_il = ct[icell].J_ij_il_count_spec; for (i = 0; i < i_max; i++) - c += V_M_il[i].Dz * V_M_il[i].grad; + Sum_zM += ct[icell].v_m_il[i].Dz * ct[icell].v_m_il[i].grad; for (i = 0; i < i_max; i++) { - J_ij_il[i].tot1 = -V_M_il[i].D * V_M_il[i].grad + - c * V_M_il[i].Dzc / Dz2c_il; + ct[icell].J_ij_il[i].tot1 = -ct[icell].v_m_il[i].D * ct[icell].v_m_il[i].grad + + Sum_zM * ct[icell].v_m_il[i].Dzc / ct[icell].Dz2c_il; if (stagnant) - J_ij_il[i].tot1 *= mixf_il; + ct[icell].J_ij_il[i].tot1 *= ct[icell].mixf_il; else - J_ij_il[i].tot1 *= A_ij_il * DDt; - ct[icell].J_ij_sum += V_M_il[i].z * J_ij_il[i].tot1; - J_ij_il[i].tot2 = J_ij_il[i].tot1; + ct[icell].J_ij_il[i].tot1 *= ct[icell].A_ij_il * DDt; + ct[icell].J_ij_sum += ct[icell].v_m_il[i].z * ct[icell].J_ij_il[i].tot1; + //ct[icell].J_ij_il[i].tot2 = ct[icell].J_ij_il[i].tot1; } /* express the transfer in elemental moles... */ tot1_h = tot1_o = tot2_h = tot2_o = 0.0; m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * - sizeof(struct M_S)); + m_s = (struct M_S *) PHRQ_malloc((size_t)count_elements * + sizeof(struct M_S)); if (m_s == NULL) malloc_error(); for (i1 = 0; i1 < count_elements; i1++) @@ -3023,7 +3294,7 @@ dV_dcell2 : m_s[i1].tot2 = 0; } count_m_s = 0; - fill_m_s(J_ij_il, k_il); + fill_m_s(ct[icell].J_ij_il, k_il); /* do the mass transfer... */ if (icell > 0 || stagnant) @@ -3201,7 +3472,7 @@ dV_dcell2 : //ct[icell].J_ij_sum = 0; //V_M = (struct V_M *) free_check_null(V_M); if (il_calcs) - V_M_il = (struct V_M *) free_check_null(V_M_il); + ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); return (il_calcs); } /* ---------------------------------------------------------------------- */ @@ -3209,21 +3480,21 @@ int Phreeqc:: disp_surf(LDBLE DDt) /* ---------------------------------------------------------------------- */ /* - * Disperse/diffuse surfaces: - * surface[n1] = SS(mixf * surface[n2]) + (1 - SS(mixf) * surface[i1]) - * where SS is Sum of, f2 is a mixing factor. - * Implementation: - * Mobile surface comps and charges are mixed face by face and 1 by 1 in surface[n1]: - Step (from cell 1 to count_cells + 1): - * 1. Surface n1 is made a copy of cell[i1]'s surface, if it exists, or else - * b. a copy of the first encountered mobile surface[n2] from cell i2 = i1 - 1. - * 2 a. Column surfaces are mixed by dispersion/diffusion - * b. Column surfaces are mixed by MCD (if multi_Dflag is true) - * 3. Surfaces n1 and n2 are stored in a temporary surface, with n_user = i1 or i2. - * 4. When done for all cells, new surfaces are copied into the cells. - * NOTE... The surfaces' diffuse_layer, edl and phases/kinetics relations must be identical, - * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. - */ +* Disperse/diffuse surfaces: +* surface[n1] = SS(mixf * surface[n2]) + (1 - SS(mixf) * surface[i1]) +* where SS is Sum of, f2 is a mixing factor. +* Implementation: +* Mobile surface comps and charges are mixed face by face and 1 by 1 in surface[n1]: +Step (from cell 1 to count_cells + 1): +* 1. Surface n1 is made a copy of cell[i1]'s surface, if it exists, or else +* b. a copy of the first encountered mobile surface[n2] from cell i2 = i1 - 1. +* 2 a. Column surfaces are mixed by dispersion/diffusion +* b. Column surfaces are mixed by MCD (if multi_Dflag is true) +* 3. Surfaces n1 and n2 are stored in a temporary surface, with n_user = i1 or i2. +* 4. When done for all cells, new surfaces are copied into the cells. +* NOTE... The surfaces' diffuse_layer, edl and phases/kinetics relations must be identical, +* but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. +*/ { int i, i1, i2, k, k1, n1, n2; int charge_done, surf1, surf2; @@ -3232,9 +3503,9 @@ disp_surf(LDBLE DDt) cxxMix * mix_ptr; cxxSurface *surface_ptr1, *surface_ptr2; LDBLE viscos_f; -/* - * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) - */ + /* + * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + */ viscos_f = viscos_0; viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); @@ -3258,9 +3529,9 @@ disp_surf(LDBLE DDt) i2 = i1 - 1; if (i2 > 0 && cell_data[i2].por < multi_Dpor_lim) continue; -/* - * step 1. define surface n1 from cell i1, if it exists... - */ + /* + * step 1. define surface n1 from cell i1, if it exists... + */ surface_n1.Set_n_user(-99); surface_n2.Set_n_user(-99); @@ -3286,9 +3557,9 @@ disp_surf(LDBLE DDt) mixf = mixf_store = 0; if (surf1 || surf2) { -/* - * step 2a. Dispersive mixing of mobile surfaces from column cells i2 < i1... - */ + /* + * step 2a. Dispersive mixing of mobile surfaces from column cells i2 < i1... + */ if (i1 <= count_cells) mix_ptr = Utilities::Rxn_find(Dispersion_mix_map, i1); else @@ -3297,7 +3568,7 @@ disp_surf(LDBLE DDt) std::vector num; std::vector frac; mix_ptr->Vectorize(num, frac); - for(size_t i3 = 0; i3 < num.size(); i3++) + for (size_t i3 = 0; i3 < num.size(); i3++) { if (i1 <= count_cells) { @@ -3364,9 +3635,9 @@ disp_surf(LDBLE DDt) } } -/* - * For MCD, step 2b. Find physical dimensions and porosity of the cells... - */ + /* + * For MCD, step 2b. Find physical dimensions and porosity of the cells... + */ if (i1 == 1) { por = cell_data[1].por; @@ -3395,13 +3666,13 @@ disp_surf(LDBLE DDt) A_ij /= 2; A_ij *= (cell_data[i1].por < - cell_data[i2].por ? cell_data[i1].por : cell_data[i2].por); + cell_data[i2].por ? cell_data[i1].por : cell_data[i2].por); } /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) + for (k = 0; k < (int)surface_ptr2->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -3430,7 +3701,7 @@ disp_surf(LDBLE DDt) Dp1 = 0; if (surface_ptr1 != NULL && surface_ptr1->Get_transport()) { - for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int)surface_ptr1->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -3471,7 +3742,7 @@ disp_surf(LDBLE DDt) } if (surf1) { - for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) + for (k = 0; k < (int)surface_ptr1->Get_surface_comps().size(); k++) { cxxSurfaceComp * comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -3508,7 +3779,7 @@ disp_surf(LDBLE DDt) Dp2 = 0; if (surface_ptr2 != NULL && surface_ptr2->Get_transport()) { - for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int)surface_ptr2->Get_surface_comps().size(); k1++) { cxxSurfaceComp * comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -3534,14 +3805,14 @@ disp_surf(LDBLE DDt) { surface_n2 = sum_surface_comp (&surface_n2, f2, surface_ptr1, charge_name, mixf, - surface_ptr1->Get_surface_comps()[k].Get_Dw()); + surface_ptr1->Get_surface_comps()[k].Get_Dw()); f2 = 1; } if (i1 <= count_cells) { surface_n1 = sum_surface_comp (&surface_n1, f1, surface_ptr1, charge_name, -mixf, - surface_ptr1->Get_surface_comps()[k].Get_Dw()); + surface_ptr1->Get_surface_comps()[k].Get_Dw()); f1 = 1; } surface_n2.Set_n_user_both(i2); @@ -3549,9 +3820,9 @@ disp_surf(LDBLE DDt) } } -/* - * Step 3. copy surface[n1] and [n2] in a new temporary surface... - */ + /* + * Step 3. copy surface[n1] and [n2] in a new temporary surface... + */ if (surface_n1.Get_n_user() == -99) continue; @@ -3573,16 +3844,16 @@ disp_surf(LDBLE DDt) surface_n2.Set_n_user_both(-99); } } -/* - * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... - */ + /* + * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... + */ n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); - for ( ; jit != Rxn_temp_surface_map.end(); jit++) + for (; jit != Rxn_temp_surface_map.end(); jit++) { i = jit->first; - assert (i == jit->second.Get_n_user()); - if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) + assert(i == jit->second.Get_n_user()); + if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) { continue; } @@ -3606,45 +3877,45 @@ disp_surf(LDBLE DDt) /* ---------------------------------------------------------------------- */ cxxSurface Phreeqc:: -sum_surface_comp(cxxSurface *source1, LDBLE f1, cxxSurface *source2, - std::string charge_name, LDBLE f2, LDBLE new_Dw) +sum_surface_comp(cxxSurface *source1, LDBLE f1, cxxSurface *source2, +std::string charge_name, LDBLE f2, LDBLE new_Dw) /* ---------------------------------------------------------------------- */ { -/* - * Takes fraction f1 of the 1st surface, adds fraction f2 of the 2nd surface's comps[k] and its charge. - * The result goes in target - */ + /* + * Takes fraction f1 of the 1st surface, adds fraction f2 of the 2nd surface's comps[k] and its charge. + * The result goes in target + */ int new_n_user; cxxSurface *surface_ptr1, *surface_ptr2; std::string token; -/* - * Find surfaces - */ + /* + * Find surfaces + */ surface_ptr1 = source1; if (surface_ptr1 == NULL) { - error_string = sformatf( "Null pointer for surface 1 in sum_surface."); + error_string = sformatf("Null pointer for surface 1 in sum_surface."); error_msg(error_string, STOP); input_error++; return (ERROR); } surface_ptr2 = source2; -/* - * Store data for structure surface - */ + /* + * Store data for structure surface + */ new_n_user = surface_ptr1->Get_n_user(); cxxSurface temp_surface(*surface_ptr1); temp_surface.Set_n_user_both(new_n_user); temp_surface.Set_description("Copy"); temp_surface.Set_solution_equilibria(false); temp_surface.Set_n_solution(-99); -/* - * Multiply component compositions by f1 - */ + /* + * Multiply component compositions by f1 + */ temp_surface.multiply(f1); -/* - * Add in surface_ptr2 - */ + /* + * Add in surface_ptr2 + */ // Only components with same charge as component k cxxSurface addee(*surface_ptr2); addee.Get_surface_comps().clear(); @@ -3682,9 +3953,9 @@ sum_surface_comp(cxxSurface *source1, LDBLE f1, cxxSurface *source2, temp_surface.Set_transport(true); } } -/* - * Finish up - */ + /* + * Finish up + */ temp_surface.Sort_comps(); return (temp_surface); } @@ -3694,8 +3965,8 @@ int Phreeqc:: check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) /* ---------------------------------------------------------------------- */ { -/* checks if surfaces can be mixed... - */ + /* checks if surfaces can be mixed... + */ int n_user1, n_user2, return_code; return_code = OK; @@ -3705,8 +3976,8 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_dl_type() != surface_ptr2->Get_dl_type()) { error_string = sformatf( - "Surfaces %d and %d differ in definition of diffuse layer. Cannot mix.", - n_user1, n_user2); + "Surfaces %d and %d differ in definition of diffuse layer. Cannot mix.", + n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; input_error++; @@ -3715,8 +3986,8 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_type() != surface_ptr2->Get_type()) { error_string = sformatf( - "Surfaces %d and %d differ in use of electrical double layer. Cannot mix.", - n_user1, n_user2); + "Surfaces %d and %d differ in use of electrical double layer. Cannot mix.", + n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; input_error++; @@ -3724,8 +3995,8 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_only_counter_ions() != surface_ptr2->Get_only_counter_ions()) { error_string = sformatf( - "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Cannot mix.", - n_user1, n_user2); + "Surfaces %d and %d differ in use of only counter ions in the diffuse layer. Cannot mix.", + n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; input_error++; @@ -3733,8 +4004,8 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_related_phases() != surface_ptr2->Get_related_phases()) { error_string = sformatf( - "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Cannot mix.", - n_user1, n_user2); + "Surfaces %d and %d differ in use of related phases (sites proportional to moles of an equilibrium phase). Cannot mix.", + n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; input_error++; @@ -3742,8 +4013,8 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) if (surface_ptr1->Get_related_rate() != surface_ptr2->Get_related_rate()) { error_string = sformatf( - "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Cannot mix.", - n_user1, n_user2); + "Surfaces %d and %d differ in use of related rate (sites proportional to moles of a kinetic reactant). Cannot mix.", + n_user1, n_user2); error_msg(error_string, STOP); return_code = ERROR; input_error++; @@ -3754,20 +4025,20 @@ check_surfaces(cxxSurface *surface_ptr1, cxxSurface *surface_ptr2) /* ---------------------------------------------------------------------- */ cxxSurface Phreeqc:: mobile_surface_copy(cxxSurface *surface_old_ptr, - int n_user_new, bool move_old) +int n_user_new, bool move_old) /* ---------------------------------------------------------------------- */ { -/* - * Copies mobile comps from surface_old_ptr to surf_ptr1, - * comps and charges with Dw > 0 are moved if move_old == TRUE, else copied. - * NOTE... when all comps are moved, the old surface is deleted and surfaces are sorted again, - * which will modify pointers and surface numbers. - * User number of new surface structure is n_user_new, structure is freed when n_user_new is already defined - */ + /* + * Copies mobile comps from surface_old_ptr to surf_ptr1, + * comps and charges with Dw > 0 are moved if move_old == TRUE, else copied. + * NOTE... when all comps are moved, the old surface is deleted and surfaces are sorted again, + * which will modify pointers and surface numbers. + * User number of new surface structure is n_user_new, structure is freed when n_user_new is already defined + */ cxxSurface temp_surface(*surface_old_ptr); -/* - * Store moving surface's properties in temp_surface - */ + /* + * Store moving surface's properties in temp_surface + */ temp_surface.Set_n_user_both(n_user_new); std::ostringstream desc; desc << "Surface defined in simulation " << simulation << "."; @@ -3806,7 +4077,7 @@ mobile_surface_copy(cxxSurface *surface_old_ptr, if (i1 > 0) { /* OK, store moved parts from old surface, but first: - get immobile surface comps from new surface... */ + get immobile surface comps from new surface... */ cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, n_user_new); if (surf_ptr != NULL) { @@ -3839,7 +4110,7 @@ mobile_surface_copy(cxxSurface *surface_old_ptr, { cxxSurface replace_old(temp_surface); int n_user_old = surface_old_ptr->Get_n_user(); - if ((size_t) i1 != count_comps) + if ((size_t)i1 != count_comps) { /* redefine old surface with only unmovable comps (Dw = 0) */ /* other temp_surface members were set above */ @@ -3888,13 +4159,13 @@ int Phreeqc:: diff_stag_surf(int mobile_cell) /* ---------------------------------------------------------------------- */ /* - * Diffuse stagnant and mobile surfaces, following the steps of disp_surf. - * First the mobile/stagnant surfaces are mixed, then the stagnant surfaces - * when not already done. - * If mixing factors among the cells are defined expicitly, it is assumed that - * mixing with a lower numbered cell was done when that cell was processed: - * for any cell in MCD, need only include the mixing factors for higher numbered cells. - */ +* Diffuse stagnant and mobile surfaces, following the steps of disp_surf. +* First the mobile/stagnant surfaces are mixed, then the stagnant surfaces +* when not already done. +* If mixing factors among the cells are defined expicitly, it is assumed that +* mixing with a lower numbered cell was done when that cell was processed: +* for any cell in MCD, need only include the mixing factors for higher numbered cells. +*/ { int i, i1, i2, k, k1, n1, n2, ns; int charge_done, surf1, surf2; @@ -3903,9 +4174,9 @@ diff_stag_surf(int mobile_cell) cxxMix *mix_ptr; cxxSurface *surface_ptr1, *surface_ptr2; LDBLE viscos_f; -/* - * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) - */ + /* + * temperature and viscosity correction for MCD coefficient, D_T = D_298 * Tk * viscos_298 / (298 * viscos) + */ viscos_f = viscos_0; viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); @@ -3926,9 +4197,9 @@ diff_stag_surf(int mobile_cell) surface_n1.Set_n_user_both(-99); surface_n2.Set_n_user_both(-99); surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i1); -/* - * step 2a. mix surfaces... - */ + /* + * step 2a. mix surfaces... + */ mix_ptr = Utilities::Rxn_find(Rxn_mix_map, i1); if (mix_ptr == NULL) continue; @@ -4026,16 +4297,16 @@ diff_stag_surf(int mobile_cell) { mixf_store *= (cell_data[i1].por <= - cell_data[i2].por ? cell_data[i1].por : cell_data[i2]. - por); + cell_data[i2].por ? cell_data[i1].por : cell_data[i2]. + por); mixf_store /= (default_Dw * pow(multi_Dpor, multi_Dn) * - multi_Dpor); + multi_Dpor); } /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) + for (k = 0; k < (int)surface_ptr2->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -4063,7 +4334,7 @@ diff_stag_surf(int mobile_cell) Dp1 = 0; if (surf1) { - for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int)surface_ptr1->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -4072,7 +4343,7 @@ diff_stag_surf(int mobile_cell) Dp1 = comp_k1_ptr->Get_Dw() * pow(cell_data[i1].por, - multi_Dn) * viscos_f; + multi_Dn) * viscos_f; break; } } @@ -4099,7 +4370,7 @@ diff_stag_surf(int mobile_cell) if (surf1) { - for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) + for (k = 0; k < (int)surface_ptr1->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -4129,7 +4400,7 @@ diff_stag_surf(int mobile_cell) Dp2 = 0; if (surf2) { - for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int)surface_ptr2->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -4138,7 +4409,7 @@ diff_stag_surf(int mobile_cell) Dp2 = comp_k1_ptr->Get_Dw() * pow(cell_data[i2].por, - multi_Dn) * viscos_f; + multi_Dn) * viscos_f; break; } } @@ -4163,9 +4434,9 @@ diff_stag_surf(int mobile_cell) } } -/* - * Step 3. copy surface[n1] and [n2] in a new temporary surface... - */ + /* + * Step 3. copy surface[n1] and [n2] in a new temporary surface... + */ if (surface_n1.Get_n_user() == -99) continue; @@ -4178,16 +4449,16 @@ diff_stag_surf(int mobile_cell) Rxn_temp_surface_map[i2] = surface_n2; } } -/* - * Step 4. Diffusion is done. New surfaces can be copied in the cells... - */ + /* + * Step 4. Diffusion is done. New surfaces can be copied in the cells... + */ n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); - for ( ; jit != Rxn_temp_surface_map.end(); jit++) + for (; jit != Rxn_temp_surface_map.end(); jit++) { i = jit->first; assert(i == jit->second.Get_n_user()); - if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) + if ((i == 0 && bcon_first == 1) || (i == count_cells + 1 && bcon_last == 1)) { continue; } @@ -4210,7 +4481,7 @@ diff_stag_surf(int mobile_cell) /* ---------------------------------------------------------------------- */ int Phreeqc:: reformat_surf(const char *comp_name, LDBLE fraction, const char *new_comp_name, - LDBLE new_Dw, int l_cell) +LDBLE new_Dw, int l_cell) /* ---------------------------------------------------------------------- */ { cxxSurface *surface_ptr; @@ -4300,26 +4571,26 @@ viscosity(void) /* ---------------------------------------------------------------------- */ { -/* from Atkins, 1994. Physical Chemistry, 5th ed. */ + /* from Atkins, 1994. Physical Chemistry, 5th ed. */ //viscos = // pow((LDBLE) 10., // -(1.37023 * (tc_x - 20) + // 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); -/* Huber et al., 2009, J. Phys. Chem. Ref. Data, Vol. 38, 101-125 */ - LDBLE H[4] = { 1.67752, 2.20462, 0.6366564, -0.241605 }; - LDBLE Tb = tk_x / 647.096, denom = H[0], mu0; + /* Huber et al., 2009, J. Phys. Chem. Ref. Data, Vol. 38, 101-125 */ + LDBLE H[4] = { 1.67752, 2.20462, 0.6366564, -0.241605 }; + LDBLE Tb = tk_x / 647.096, denom = H[0], mu0; int i, j, i1; for (i = 1; i < 4; i++) denom += H[i] / pow(Tb, i); mu0 = 100.0 * sqrt(Tb) / denom; LDBLE H2[42] = - { 5.20094e-1, 2.22531e-1, -2.81378e-1, 1.61913e-1, -3.25372e-2, 0, 0, - 8.50895e-2, 9.99115e-1, -9.06851e-1, 2.57399e-1, 0, 0, 0, - -1.08374, 1.88797, -7.72479e-1, 0, 0, 0, 0, - -2.89555e-1, 1.26613, -4.89837e-1, 0, 6.98452e-2, 0, -4.35673e-3, - 0, 0, -2.57040e-1, 0, 0, 8.72102e-3, 0, - 0, 1.20573e-1, 0, 0, 0, 0, -5.93264e-4 }; + { 5.20094e-1, 2.22531e-1, -2.81378e-1, 1.61913e-1, -3.25372e-2, 0, 0, + 8.50895e-2, 9.99115e-1, -9.06851e-1, 2.57399e-1, 0, 0, 0, + -1.08374, 1.88797, -7.72479e-1, 0, 0, 0, 0, + -2.89555e-1, 1.26613, -4.89837e-1, 0, 6.98452e-2, 0, -4.35673e-3, + 0, 0, -2.57040e-1, 0, 0, 8.72102e-3, 0, + 0, 1.20573e-1, 0, 0, 0, 0, -5.93264e-4 }; LDBLE Rb = rho_0 / 0.322, Tb_1, Rb_1, S1 = 0.0, S2, mu1; Tb_1 = 1.0 / Tb - 1.0; Rb_1 = Rb - 1.0; for (i = 0; i < 6; i++) @@ -4343,18 +4614,15 @@ viscosity(void) mu1 = exp(Rb * S1); viscos_0 = viscos = mu0 * mu1 / 1e3; viscos_0_25 = 0.8900239182946; - -#define OLD_VISCOSITY +//#define OLD_VISCOSITY #ifdef OLD_VISCOSITY +/* from Atkins, 1994. Physical Chemistry, 5th ed. */ viscos = pow((LDBLE) 10., -(1.37023 * (tc_x - 20) + 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); -/* Huber et al., 2009, J. Phys. Chem. Ref. Data, Vol. 38, 101-125 */ - viscos_0 = viscos; viscos_0_25 = 0.88862; #endif - return viscos; } /* ---------------------------------------------------------------------- */ @@ -4362,18 +4630,18 @@ LDBLE Phreeqc:: calc_vm_Cl(void) /* ---------------------------------------------------------------------- */ { -/* - * Calculate molar volume of Cl- with a Redlich type eqn: - Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I^(b4). - * Vm0(tc) is calc'd using supcrt parms, or from millero[0] + millero[1] * tc + millero[2] * tc^2 - * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. - Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av. - If b_Av != 0, the extended DH formula is used: I^0.5 /(1 + b_Av * DH_B * I^0.5). - DH_Av and DH_B are from calc_dielectrics(tc, pa). - * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228) + logk[vmi3] * (TK - 228). - * b4 = logk[vmi4], or - * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 - */ + /* + * Calculate molar volume of Cl- with a Redlich type eqn: + Vm = Vm0(tc) + (Av / 2) * z^2 * I^0.5 + coef(tc) * I^(b4). + * Vm0(tc) is calc'd using supcrt parms, or from millero[0] + millero[1] * tc + millero[2] * tc^2 + * for Av * z^2 * I^0.5, see Redlich and Meyer, Chem. Rev. 64, 221. + Av is in (cm3/mol)(mol/kg)^-0.5, = DH_Av. + If b_Av != 0, the extended DH formula is used: I^0.5 /(1 + b_Av * DH_B * I^0.5). + DH_Av and DH_B are from calc_dielectrics(tc, pa). + * coef(tc) = logk[vmi1] + logk[vmi2] / (TK - 228) + logk[vmi3] * (TK - 228). + * b4 = logk[vmi4], or + * coef(tc) = millero[3] + millero[4] * tc + millero[5] * tc^2 + */ LDBLE V_Cl = 0; LDBLE pb_s = 2600. + patm_x * 1.01325, TK_s = tc_x + 45.15, sqrt_mu = sqrt(mu_x); struct species *s_ptr; @@ -4384,7 +4652,7 @@ calc_vm_Cl(void) if (s_ptr->logk[vma1]) { - /* supcrt volume at I = 0... */ + /* supcrt volume at I = 0... */ V_Cl = s_ptr->logk[vma1] + s_ptr->logk[vma2] / pb_s + (s_ptr->logk[vma3] + s_ptr->logk[vma4] / pb_s) / TK_s - s_ptr->logk[wref] * QBrn; @@ -4413,11 +4681,11 @@ calc_vm_Cl(void) } else if (s_ptr->millero[0]) { - /* Millero volume at I = 0... */ + /* Millero volume at I = 0... */ V_Cl = s_ptr->millero[0] + tc_x * (s_ptr->millero[1] + tc_x * s_ptr->millero[2]); if (s_ptr->z) { - /* the ionic strength terms... */ + /* the ionic strength terms... */ V_Cl += s_ptr->z * s_ptr->z * 0.5 * DH_Av * sqrt_mu + (s_ptr->millero[3] + tc_x * (s_ptr->millero[4] + tc_x * s_ptr->millero[5])) * mu_x; } From 9644278e491a00efb1321e7e1458f2d496941df5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 20 Jan 2016 18:19:12 +0000 Subject: [PATCH 0967/1077] added Dictionary and Serializer Deleted unused files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10720 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Dictionary.cpp | 32 + Dictionary.h | 28 + Serializer.cxx | 198 ++ Serializer.h | 42 + distribution.checklist | 85 - distribution.mk | 342 -- newiso.dat | 5565 -------------------------------- phreeqc.dat | 1556 --------- phreeqc.distribution.checklist | 85 - 9 files changed, 300 insertions(+), 7633 deletions(-) create mode 100644 Dictionary.cpp create mode 100644 Dictionary.h create mode 100644 Serializer.cxx create mode 100644 Serializer.h delete mode 100644 distribution.checklist delete mode 100644 distribution.mk delete mode 100644 newiso.dat delete mode 100644 phreeqc.dat delete mode 100644 phreeqc.distribution.checklist diff --git a/Dictionary.cpp b/Dictionary.cpp new file mode 100644 index 00000000..bd5348d8 --- /dev/null +++ b/Dictionary.cpp @@ -0,0 +1,32 @@ +#include "Dictionary.h" +Dictionary::Dictionary(void) +{ +} + +Dictionary::Dictionary(std::string & words_string) +{ + std::istringstream words_stream(words_string); + char str[256]; + while (words_stream.getline(str,256)) + { + this->Find(str); + } +} +Dictionary::~Dictionary(void) +{ +} + +int +Dictionary::Find(std::string str) +{ + std::map::iterator it = this->dictionary_map.find(str); + if (it != this->dictionary_map.end()) + { + return it->second; + } + int i = this->MapSize(); + this->dictionary_map[str] = i; + this->words.push_back(str); + this->dictionary_oss << str << "\n"; + return i; +} diff --git a/Dictionary.h b/Dictionary.h new file mode 100644 index 00000000..ffe86fc5 --- /dev/null +++ b/Dictionary.h @@ -0,0 +1,28 @@ +#if !defined(DICTIONARY_H_INCLUDED) +#define DICTIONARY_H_INCLUDED +#include +#include +#include +#include +class Phreeqc; +class Dictionary +{ +public: + Dictionary(void); + Dictionary(std::string & words_string); + ~Dictionary(void); + int Find(std::string str); + int MapSize() {return (int) this->dictionary_map.size();} + int OssSize() {return (int) this->dictionary_oss.str().size();} + std::ostringstream &GetDictionaryOss() {return this->dictionary_oss;} + std::vector &GetWords() {return this->words;} + +protected: + std::map dictionary_map; + std::vector words; + std::ostringstream dictionary_oss; + +}; + +#endif // !defined(DICTIONARY_H_INCLUDED) + diff --git a/Serializer.cxx b/Serializer.cxx new file mode 100644 index 00000000..018f56ca --- /dev/null +++ b/Serializer.cxx @@ -0,0 +1,198 @@ +#include "Serializer.h" +#include "Phreeqc.h" +#include "Utils.h" +#include "Solution.h" +#include "Exchange.h" +#include "Temperature.h" +#include "GasPhase.h" +#include "cxxKinetics.h" +#include "PPassemblage.h" +#include "SSassemblage.h" +#include "Surface.h" +Serializer::Serializer(PHRQ_io *io) + : PHRQ_base(io) +{ +} +Serializer::~Serializer(void) +{ +} +bool Serializer::Serialize(Phreeqc &phreeqc_ref, int start, int end, bool include_t, bool include_p, PHRQ_io *io) +{ + for (int i = start; i <= end; i++) + { + cxxSolution *soln_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_solution_map(), i); + if (soln_ptr) + { + ints.push_back((int) PT_SOLUTION); + soln_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + // Exchangers + { + cxxExchange *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_exchange_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_EXCHANGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // GasPhases + { + cxxGasPhase *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_gas_phase_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_GASPHASE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Kinetics + { + cxxKinetics *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_kinetics_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_KINETICS); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // PPassemblages + { + cxxPPassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pp_assemblage_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_PPASSEMBLAGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // SSassemblages + { + cxxSSassemblage *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_ss_assemblage_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_SSASSEMBLAGE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Surfaces + { + cxxSurface *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_surface_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_SURFACES); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Temperature + if (include_t) + { + cxxTemperature *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_temperature_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_TEMPERATURE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + // Pressure + if (include_p) + { + cxxPressure *entity_ptr = Utilities::Rxn_find(phreeqc_ref.Get_Rxn_pressure_map(), i); + if (entity_ptr) + { + ints.push_back((int) PT_PRESSURE); + entity_ptr->Serialize(this->dictionary, this->ints, this->doubles); + } + } + } + return true; +} + +bool +Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vector &ints, std::vector &doubles) +{ + int ii = 0; + int dd = 0; + while (ii < (int) ints.size()) + { + PACK_TYPE type = (PACK_TYPE) ints[ii++]; + switch (type) + { + case PT_SOLUTION: + { + cxxSolution soln; + soln.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = soln.Get_n_user(); + //std::cerr << "unpacked solution " << n_user << std::endl; + phreeqc_ref.Get_Rxn_solution_map()[n_user] = soln; + } + break; + case PT_EXCHANGE: + { + cxxExchange entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_exchange_map()[n_user] = entity; + } + break; + case PT_GASPHASE: + { + cxxGasPhase entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_gas_phase_map()[n_user] = entity; + } + break; + case PT_KINETICS: + { + cxxKinetics entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_kinetics_map()[n_user] = entity; + } + break; + case PT_PPASSEMBLAGE: + { + cxxPPassemblage entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + //std::cerr << "unpacked pp assemblage " << n_user << std::endl; + phreeqc_ref.Get_Rxn_pp_assemblage_map()[n_user] = entity; + } + break; + case PT_SSASSEMBLAGE: + { + cxxSSassemblage entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_ss_assemblage_map()[n_user] = entity; + } + break; + case PT_SURFACES: + { + cxxSurface entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_surface_map()[n_user] = entity; + } + break; + case PT_TEMPERATURE: + { + cxxTemperature entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_temperature_map()[n_user] = entity; + } + break; + case PT_PRESSURE: + { + cxxPressure entity; + entity.Deserialize(dictionary, ints, doubles, ii, dd); + int n_user = entity.Get_n_user(); + phreeqc_ref.Get_Rxn_pressure_map()[n_user] = entity; + } + break; + default: + std::cerr << "Unknown pack type in deserialize " << type << std::endl; + exit(4); + break; + } + } + return true; +} diff --git a/Serializer.h b/Serializer.h new file mode 100644 index 00000000..80c285d8 --- /dev/null +++ b/Serializer.h @@ -0,0 +1,42 @@ +#if !defined(SERIALIZER_H_INCLUDED) +#define SERIALIZER_H_INCLUDED +#include +#include +#include +#include +#include "PHRQ_base.h" +#include "Dictionary.h" +class Phreeqc; +class Serializer : public PHRQ_base +{ +public: + Serializer(PHRQ_io *io = NULL); + ~Serializer(void); + + enum PACK_TYPE + { + PT_SOLUTION = 0, + PT_EXCHANGE = 1, + PT_GASPHASE = 2, + PT_KINETICS = 3, + PT_PPASSEMBLAGE = 4, + PT_SSASSEMBLAGE = 5, + PT_SURFACES = 6, + PT_TEMPERATURE = 7, + PT_PRESSURE = 8 + }; + bool Serialize(Phreeqc &phreeqc_ptr, int start, int end, bool include_t, bool include_p, PHRQ_io *io = NULL); + bool Deserialize(Phreeqc &phreeqc_ptr, Dictionary &dictionary, std::vector &ints, std::vector &doubles); + Dictionary &GetDictionary(void) {return this->dictionary;} + std::vector &GetInts(void) {return this->ints;} + std::vector &GetDoubles(void) {return this->doubles;} + //std::string &GetWordsString(void) {return this->words_string;} + + +protected: + std::vector ints; + std::vector doubles; + //std::string words_string; + Dictionary dictionary; +}; +#endif // !defined(SERIALIZER_H_INCLUDED) \ No newline at end of file diff --git a/distribution.checklist b/distribution.checklist deleted file mode 100644 index 86f3bb93..00000000 --- a/distribution.checklist +++ /dev/null @@ -1,85 +0,0 @@ -(1) Copy distribution.checklist to checklist.VERSION - -(2) XXX Update version and date in main.c - -(3) XXX Update doc/README.TXT - XXX uname -r - XXX gcc -v - -(4) Update src/revisions - when all_dist is run by make, src/revisions is copied - to doc/RELEASE.TXT - - ( ../doc/phreeqc.txt now static, only RELEASE.TXT - has history 2/2/05) - -(5) Update Makefile and distribution.mk - set VERSION number - set VER_DATE - add any new files to distribution - database files - source files - output files - doc files - -(6) svn status ~/programs/phreeqc -q - svn ci ~/programs/phreeqc - svn update - -(7) remake everything - make clean_all - make output_files (also remakes programs) - -(8) svn status ~/programs/phreeqc -q - should be clean - otherwise commit and restart checklist at item 5 - -(9) make all_dist REVISION=xxx - ls phreeqc_export -Linux/ phreeqc-2.12-577.Linux.tar.gz phreeqc-2.12-577.source.tar.gz Source/ - -(10) test Unix distributions - make test_dist - or - make linux_test, sun_test, source_test - -(11) Scott is making batch windows - -(12) make web - install windows version - copy README.TXT to ~/programs/phreeqc/win - - cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc - cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT - cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT - cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT - cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT - cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt - cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT - -(13) check for latest version of Phreeqc For Windows. - -(14) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/index.html - phreeqci version, date, size - windows batch phreeqc version size - Linux batch phreeqc version size - Generic batch phreeqc version size - phreeqc for windows version, date, size - -(15) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqci/index.html - PhreeqcI version, date, size - -(16) send mail to Brian Marshal - -(17) PHAST - unpack release version in packages - Update table in /z/linarcolkr/home/www/projects/GWC_coupled/phast/index.html - copy release notes - from ~/packages/phast-x.x/doc/RELEASE.TXT - to /z/linarcolkr/home/www/projects/GWC_coupled/phast/RELEASE.TXT - copy readme - from ~/packages/phast-x.x/README - to /z/linarcolkr/home/www/projects/GWC_coupled/phast/README - -(18) Update status.fm - diff --git a/distribution.mk b/distribution.mk deleted file mode 100644 index 3102cc37..00000000 --- a/distribution.mk +++ /dev/null @@ -1,342 +0,0 @@ -# Locations to save compressed tar file for distribution -EXPORT=$(TOPDIR)/src/phreeqc_export -EXPORT_DIR=$(EXPORT) -WIN_DIR=$(TOPDIR)/win -DIST_DIR=$(EXPORT_DIR) -DEBUG_DIR=phreeqc_debug -CURSRC=$(CURDIR) -DEBUG_EXE=$(CURSRC)/phreeqc -VERSION=2.12 -VER_DATE:=November 10, 2005 -VER_LONG_DATE:=$(shell date -d "$(VER_DATE)" "+%B %e, %G") -V_FIXDATE:=$(shell date -d "$(VER_DATE)" "+%d-%b-%G") -GCC_VER:=$(shell gcc -v 2>&1 | egrep ^gcc | sed "s/version //") -KERNEL_VER:=$(shell uname -r) -ROOTNAME=$(PROGRAM)-$(VERSION)-$(REVISION) -TEXTCP=textcp DOS -SUN_DIR=$(TOPDIR)/src/Sun -UNIX2DOS=unix2dos -CCFLAGS_DBG=-Wall -ansi -g -DUSE_PHRQ_ALLOC # -std=c99 - -CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else - SPOOL=>& - SPOOL2= -endif - -# list of files for distribution -##FILES= \ -## $(CURSRC)/Makefile \ -## $(CURSRC)/advection.c \ -## $(CURSRC)/basic.c \ -## $(CURSRC)/basicsubs.c \ -## $(CURSRC)/cl1.c \ -## $(CURSRC)/cl1mp.c \ -## $(CURSRC)/cvdense.c \ -## $(CURSRC)/cvode.c \ -## $(CURSRC)/dense.c \ -## $(CURSRC)/dw.c \ -## $(CURSRC)/input.c \ -## $(CURSRC)/integrate.c \ -## $(CURSRC)/inverse.c \ -## $(CURSRC)/isotopes.c \ -## $(CURSRC)/kinetics.c \ -## $(CURSRC)/main.c \ -## $(CURSRC)/mainsubs.c \ -## $(CURSRC)/model.c \ -## $(CURSRC)/nvector.c \ -## $(CURSRC)/nvector_serial.c \ -## $(CURSRC)/output.c \ -## $(CURSRC)/p2clib.c \ -## $(CURSRC)/parse.c \ -## $(CURSRC)/phqalloc.c \ -## $(CURSRC)/phreeqc_files.c \ -## $(CURSRC)/pitzer.c \ -## $(CURSRC)/pitzer_structures.c \ -## $(CURSRC)/prep.c \ -## $(CURSRC)/print.c \ -## $(CURSRC)/read.c \ -## $(CURSRC)/readtr.c \ -## $(CURSRC)/sit.c \ -## $(CURSRC)/smalldense.c \ -## $(CURSRC)/spread.c \ -## $(CURSRC)/step.c \ -## $(CURSRC)/structures.c \ -## $(CURSRC)/sundialsmath.c \ -## $(CURSRC)/tally.c \ -## $(CURSRC)/tidy.c \ -## $(CURSRC)/transport.c \ -## $(CURSRC)/utilities.c \ -## $(CURSRC)/basic.h \ -## $(CURSRC)/cvdense.h \ -## $(CURSRC)/cvode.h \ -## $(CURSRC)/dense.h \ -## $(CURSRC)/global.h \ -## $(CURSRC)/global_structures.h \ -## $(CURSRC)/input.h \ -## $(CURSRC)/kinetics.h \ -## $(CURSRC)/nvector.h \ -## $(CURSRC)/nvector_serial.h \ -## $(CURSRC)/output.h \ -## $(CURSRC)/p2c.h \ -## $(CURSRC)/phqalloc.h \ -## $(CURSRC)/phrqproto.h \ -## $(CURSRC)/phrqtype.h \ -## $(CURSRC)/pitzer.h \ -## $(CURSRC)/pitzer_structures.h \ -## $(CURSRC)/smalldense.h \ -## $(CURSRC)/sundialsmath.h \ -## $(CURSRC)/sundialstypes.h \ -## database/*.dat \ -## examples/ex1 examples/ex1.out \ -## examples/ex2 examples/ex2.out examples/ex2.sel \ -## examples/ex3 examples/ex3.out \ -## examples/ex4 examples/ex4.out \ -## examples/ex5 examples/ex5.out examples/ex5.sel \ -## examples/ex6 examples/ex6.out examples/ex6A-B.sel examples/ex6C.sel \ -## examples/ex7 examples/ex7.out examples/ex7.sel \ -## examples/ex8 examples/ex8.out examples/ex8.sel \ -## examples/ex9 examples/ex9.out examples/ex9.sel \ -## examples/ex10 examples/ex10.out examples/ex10.sel \ -## examples/ex11 examples/ex11.out examples/ex11adv.sel examples/ex11trn.sel \ -## examples/ex12 examples/ex12.out examples/ex12.sel \ -## examples/ex12a examples/ex12a.out examples/ex12a.sel \ -## examples/ex13a examples/ex13a.out examples/ex13a.sel \ -## examples/ex13b examples/ex13b.out examples/ex13b.sel \ -## examples/ex13c examples/ex13c.out examples/ex13c.sel \ -## examples/ex14 examples/ex14.out examples/ex14.sel \ -## examples/ex15 examples/ex15.dat examples/ex15.out examples/ex15.sel \ -## examples/ex16 examples/ex16.out \ -## examples/ex17 examples/ex17.out \ -## examples/ex18 examples/ex18.out \ -## NOTICE.TXT \ -## README.TXT \ -## RELEASE.TXT \ -## doc/manual.pdf \ -## doc/wrir02-4172.pdf \ -## doc/phreeqc.txt \ -## bin/phreeqc.orig \ -## test/test.sh \ -## test/clean.sh \ -## test/check.sh - -##SED_ARGS= \ -## -e "s/@VERSION@/$(VERSION)/" \ -## -e "s/@VER_DATE@/$(VER_LONG_DATE)/" \ -## -e "s/VERSION_DATE/$(VERSION)/" \ -## -e "s^@GCC_VER@^$(GCC_VER)^" \ -## -e "s^@KERNEL_VER@^$(KERNEL_VER)^" \ -## -e "s/@REVISION@/$(REVISION)/" \ -## -e "s/@PHREEQC_VER@/$(VERSION)/" \ -## -e "s/@PHREEQC_DATE@/$(VER_LONG_DATE)/" -## - -##SED_ARGS2=\ - -e "s/^\# Remove the following definition if you do not have /\# Add the following definition if you have/" \ - -e "s/^INVERSE_CL1MP=TRUE/\#INVERSE_CL1MP=TRUE/" - -##remake_output_files: clean_linux_output_files linux_output_files # clean_sun_output_files sun_output_files - -##output_files: linux_output_files # sun_output_files - -# make sure program is compiles, run examples and mytest -##linux_output_files: all -## cd ../examples; make >& make.out -## cd ../mytest; make >& make.out - -##clean_linux_output_files: -## cd ../examples; make clean -## cd ../mytest; make clean - -##sun_output_files: phreeqc.sun -## ssh u450rcolkr "cd $(SUN_DIR)/examples; make -f $(SUN_DIR)/../../examples/Makefile INPUT=$(SUN_DIR)/../../examples PHREEQCDAT=$(SUN_DIR)/../../database/phreeqc.dat WATEQ4FDAT=$(SUN_DIR)/../../database/wateq4f.dat" - -##phreeqc.sun: -## ssh u450rcolkr "cd $(SUN_DIR)/src; make -f $(SUN_DIR)/../Makefile SRC=$(SUN_DIR)/.. EXE=$(SUN_DIR)/bin/phreeqc" - -##clean_sun_output_files: -## cd $(SUN_DIR)/examples; make -f ../../../examples/Makefile clean - -##all_dist: clean_dist linux source # win # sun - -##test_dist: linux_test source_test # sun_test - -# -#Linux -# -##linux: linux_export linux_clean linux_sed_files linux_compile linux_output linux_dist - -##source: source_export source_clean source_sed_files source_dist - -##linux_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Linux -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Linux - -##linux_clean: -## rm -f $(EXPORT_DIR)/Linux/bin/$(PROGRAM) $(EXPORT_DIR)/Linux/src/*.o - -##linux_sed_list= \ -## "$(EXPORT_DIR)/Linux/doc/README.TXT \ -## $(EXPORT_DIR)/Linux/src/main.c" - -##linux_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Linux/src/revisions > $(EXPORT_DIR)/Linux/RELEASE.TXT -## for FILE in "$(linux_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done -## mv $(EXPORT_DIR)/Linux/doc/README.TXT $(EXPORT_DIR)/Linux/README.TXT -## mv $(EXPORT_DIR)/Linux/doc/NOTICE.TXT $(EXPORT_DIR)/Linux/NOTICE.TXT - -##linux_compile: -## make -C $(EXPORT_DIR)/Linux/src - -##linux_output: -## cd $(EXPORT_DIR)/Linux/examples; make clean; make >& make.out - -##linux_dist: -## cd $(EXPORT_DIR)/Linux; rm -f $(PROGRAM).tar -## -## cd $(EXPORT_DIR)/Linux; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Linux; tar -rf $(PROGRAM).tar bin/$(PROGRAM) -## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar -## cd $(EXPORT_DIR)/Linux; sed $(SED_ARGS2) < $(PROGRAM)-$(VERSION)/src/Makefile > t; mv t $(PROGRAM)-$(VERSION)/src/Makefile -## cd $(EXPORT_DIR)/Linux; tar -czf $(PROGRAM).Linux.tar.gz $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Linux; mv $(PROGRAM).Linux.tar.gz $(DIST_DIR)/$(ROOTNAME).Linux.tar.gz -## cd $(EXPORT_DIR)/Linux; echo $(ROOTNAME).Linux.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Linux; rm -rf $(PROGRAM)-$(VERSION) - -##source_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Source -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Source - -##source_clean: -## rm -f $(EXPORT_DIR)/Source/bin/$(PROGRAM) $(EXPORT_DIR)/Source/src/*.o - -##source_sed_list= \ -## "$(EXPORT_DIR)/Source/doc/README.TXT \ -## $(EXPORT_DIR)/Source/src/main.c" - -##source_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Source/src/revisions > $(EXPORT_DIR)/Source/RELEASE.TXT -## sed $(SED_ARGS2) < $(EXPORT_DIR)/Source/src/Makefile > t; mv t $(EXPORT_DIR)/Source/src/Makefile -## for FILE in "$(source_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; mv t $$FILE; done -## mv $(EXPORT_DIR)/Source/doc/README.TXT $(EXPORT_DIR)/Source/README.TXT -## mv $(EXPORT_DIR)/Source/doc/NOTICE.TXT $(EXPORT_DIR)/Source/NOTICE.TXT - -##source_dist: -## cd $(EXPORT_DIR)/Source; rm -f $(PROGRAM).tar -## cd $(EXPORT_DIR)/Source; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm $(PROGRAM).tar -## cd $(EXPORT_DIR)/Source; tar -czf $(PROGRAM).source.tar.gz $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Source; mv $(PROGRAM).source.tar.gz $(DIST_DIR)/$(ROOTNAME).source.tar.gz -## cd $(EXPORT_DIR)/Source; echo $(ROOTNAME).source.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Source; rm -rf $(PROGRAM)-$(VERSION) -## -##linux_test: -## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).Linux -## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.Linux.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).Linux -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./test.sh -## rm -f $(DIST_DIR)/phreeqc-$(VERSION).Linux/bin/phreeqc -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/src; make -k -## cd $(DIST_DIR)/phreeqc-$(VERSION).Linux/test; ./clean.sh; ./test.sh - -##source_test: -## rm -rf $(DIST_DIR)/phreeqc-$(VERSION).source -## cd $(DIST_DIR); tar -xzf phreeqc-$(VERSION)-*.source.tar.gz; mv phreeqc-$(VERSION) phreeqc-$(VERSION).source -## cd $(DIST_DIR)/phreeqc-$(VERSION).source/src; make -k -## cd $(DIST_DIR)/phreeqc-$(VERSION).source/test; ./test.sh - -##clean_dist: -## rm -rf $(EXPORT_DIR) - -##clean_all: clean_dist clean_linux_output_files clean # clean_sun_output_files - -# -#Win -# -##win: win_export win_sed_files win_dist - -##win_export: -## mkdir -p $(EXPORT_DIR) -## rm -rf $(EXPORT_DIR)/Win -## svn export -r $(REVISION) http://internalbrr/svn_GW/phreeqc/trunk $(EXPORT_DIR)/Win - -##win_sed_list= \ - "$(EXPORT_DIR)/Win/src/main.c" - -##win_sed_files: -## sed $(SED_ARGS) < $(EXPORT_DIR)/Win/src/revisions > $(EXPORT_DIR)/Win/RELEASE.TXT -## $(UNIX2DOS) $(EXPORT_DIR)/Win/RELEASE.TXT -## sed $(SED_ARGS) < $(WIN_DIR)/README.TXT > $(EXPORT_DIR)/Win/README.TXT -## $(UNIX2DOS) $(EXPORT_DIR)/Win/README.TXT -## for FILE in "$(win_sed_list)"; do \ -## sed $(SED_ARGS) < $$FILE > t; \ - mv t $$FILE; \ - $(UNIX2DOS) $$FILE; \ - done -## mv $(EXPORT_DIR)/Win/doc/NOTICE.TXT $(EXPORT_DIR)/Win/NOTICE.TXT - -##win_dist: -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM).tar -# Translate cr/lf -## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do \ - if [ $$FILE = doc/manual.pdf -o $$FILE = doc/wrir02-4172.pdf ]; then cp $$FILE t; mv t $$FILE; \ - else $(TEXTCP) $$FILE t; mv t $$FILE; fi; done -## cd $(EXPORT_DIR)/Win; for FILE in $(FILES); do tar -rf $(PROGRAM).tar $$FILE; done -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; mkdir $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; mv $(PROGRAM).tar $(PROGRAM)-$(VERSION) -## cd $(EXPORT_DIR)/Win; cd $(PROGRAM)-$(VERSION); tar -xf $(PROGRAM).tar; rm -f $(PROGRAM).tar -# remove example output -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/examples/*.out $(PROGRAM)-$(VERSION)/examples/*.sel -# remove bin directory -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION)/bin -# remove test directory files -## cd $(EXPORT_DIR)/Win; rm -f $(PROGRAM)-$(VERSION)/test/* -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/clean.bat $(PROGRAM)-$(VERSION)/test/clean.bat -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/check.bat $(PROGRAM)-$(VERSION)/test/check.bat -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/test.bat $(PROGRAM)-$(VERSION)/test/test.bat -# copy bat file -## cd $(EXPORT_DIR)/Win; $(TEXTCP) $(WIN_DIR)/phreeqc.bat $(PROGRAM)-$(VERSION)/phreeqc.bat -## cd $(EXPORT_DIR); rm -f $(PROGRAM).Windows.tar.gz -## cd $(EXPORT_DIR)/Win/$(PROGRAM)-$(VERSION); tar -czf $(DIST_DIR)/$(ROOTNAME).Windows.tar.gz . -## @echo $(ROOTNAME).Windows.tar.gz saved in $(DIST_DIR). -## cd $(EXPORT_DIR)/Win; rm -rf $(PROGRAM)-$(VERSION) - -##win_echo_files: -## @echo $(FILES) - -debug: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG) -DINVERSE_CL1MP" EXE=$(DEBUG_EXE) - -debug_nomp: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); make -f $(CURSRC)/Makefile SRC=$(CURSRC) CCFLAGS="$(CCFLAGS_DBG)" INVERSE_CL1MP= EXE=$(DEBUG_EXE) - -##web: -## cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc -## cp $(EXPORT_DIR)/Linux/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT -## cp $(EXPORT_DIR)/Linux/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT -## cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT -## cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT -## cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt -## cp $(EXPORT_DIR)/Linux/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT - -tester: - cd ../mytest; make clean; make -k $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make clean; make $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - svn status -q ../mytest - svn status -q ../examples diff --git a/newiso.dat b/newiso.dat deleted file mode 100644 index b3fb3237..00000000 --- a/newiso.dat +++ /dev/null @@ -1,5565 +0,0 @@ -SOLUTION_MASTER_SPECIES -E e- 0 0 0.0 -H H3O+ -1 H 1.008 -H(0) H2 0 H -H(1) H3O+ -1 H -O H2O 0 O 16.00 -O(0) O2 0 O -O(-2) H2O 0 O -Ca Ca+2 0 Ca 40.08 -Mg Mg+2 0 Mg 24.312 -Na Na+ 0 Na 22.9898 -K K+ 0 K 39.102 -Fe Fe+2 0.0 Fe 55.847 -Fe(+2) Fe+2 0.0 Fe -Fe(+3) Fe+3 -2.0 Fe -Al Al+3 0.0 Al 26.9815 -Si H4SiO4 0.0 SiO2 28.0843 -Cl Cl- 0 Cl 35.453 -C CO2 0 HCO3 12.0111 -C(4) CO2 0 HCO3 -C(-4) CH4 0 CH4 -S SO4-2 0 S 31.972 -S(6) SO4-2 0 SO4 -S(-2) HS- 1 S -N NO3- 0 N 14.0067 -N(+5) NO3- 0 N -N(+3) NO2- 0 N -N(0) N2 0 N -N(-3) NH4+ 0 N -P PO4-3 2.0 P 30.9738 -F F- 0.0 F 18.9984 -Br Br- 0.0 Br 79.904 - -SOLUTION_SPECIES -H3O+ = H3O+ - log_k 0.000 - -gamma 9.0000 0.0000 - -e- = e- - log_k 0.000 - -H2O = H2O - log_k 0.000 - -Ca+2 = Ca+2 - log_k 0.000 - -gamma 5.0000 0.1650 - -Mg+2 = Mg+2 - log_k 0.000 - -gamma 5.5000 0.2000 - -Na+ = Na+ - log_k 0.000 - -gamma 4.0000 0.0750 - -K+ = K+ - log_k 0.000 - -gamma 3.5000 0.0150 - -Fe+2 = Fe+2 - log_k 0.000 - -gamma 6.0000 0.0000 - -Al+3 = Al+3 - log_k 0.000 - -gamma 9.0000 0.0000 - -H4SiO4 = H4SiO4 - log_k 0.000 - -Cl- = Cl- - log_k 0.000 - -gamma 3.5000 0.0150 - -SO4-2 = SO4-2 - log_k 0.000 - -gamma 5.0000 -0.0400 - -NO3- = NO3- - log_k 0.000 - -gamma 3.0000 0.0000 - -PO4-3 = PO4-3 - log_k 0.000 - -gamma 4.0000 0.0000 - -F- = F- - log_k 0.000 - -gamma 3.5000 0.0000 - -Br- = Br- - log_k 0.000 - -gamma 3.0000 0.0000 - -2H2O = OH- + H3O+ - log_k -14.000 - delta_h 13.362 kcal - -analytic -283.971 -0.05069842 13323.0 102.24447 -1119669.0 - -gamma 3.5000 0.0000 - -6 H2O = O2 + 4 H3O+ + 4 e- - log_k -86.08 - delta_h 134.79 kcal - -2 H3O+ + 2 e- = H2 + 2H2O - log_k -3.15 - delta_h -1.759 kcal - -CO2 + 2H2O = HCO3- + H3O+ - log_k -6.352 - delta_h 2.177 kcal - -analytic -356.3094 -0.06092 21834.37 126.8339 -1684915 - -CO2 + 3H2O = CO3-2 + 2H3O+ - log_k -16.681 - delta_h 5.738 kcal - -analytic -464.1965 -0.09344813 26986.16 165.75951 -2248628.9 - -CO3-2 + 10 H3O+ + 8 e- = CH4 + 13 H2O - log_k 41.071 - delta_h -61.039 kcal - -SO4-2 + H3O+ = HSO4- + H2O - log_k 1.988 - delta_h 3.85 kcal - -analytic -56.889 0.006473 2307.9 19.8858 0.0 - -SO4-2 + 9 H3O+ + 8 e- = HS- + 13 H2O - log_k 33.65 - delta_h -60.140 kcal - -gamma 3.5000 0.0000 - -HS- + H2O = S-2 + H3O+ - log_k -12.918 - delta_h 12.1 kcal - -gamma 5.0000 0.0000 - -HS- + H3O+ = H2S + H2O - log_k 6.994 - delta_h -5.300 kcal - -analytic -11.17 0.02386 3279.0 - -NO3- + 2 H3O+ + 2 e- = NO2- + 3H2O - log_k 28.570 - delta_h -43.760 kcal - -gamma 3.0000 0.0000 - -2 NO3- + 12 H3O+ + 10e- = N2 + 18 H2O - log_k 207.080 - delta_h -312.130 kcal - -NH4+ + H2O = NH3 + H3O+ - log_k -9.252 - delta_h 12.48 kcal - -analytic 0.6322 -0.001225 -2835.76 - -NO3- + 10 H3O+ + 8 e- = NH4+ + 13 H2O - log_k 119.077 - delta_h -187.055 kcal - -gamma 2.5000 0.0000 - -NH4+ + SO4-2 = NH4SO4- - log_k 1.11 - -PO4-3 + H3O+ = HPO4-2 + H2O - log_k 12.346 - delta_h -3.530 kcal - -gamma 4.0000 0.0000 - -PO4-3 + 2 H3O+ = H2PO4- + 2H2O - log_k 19.553 - delta_h -4.520 kcal - -gamma 4.5000 0.0000 - -H3O+ + F- = HF + H2O - log_k 3.18 - delta_h 3.18 kcal - -analytic -2.033 0.012645 429.01 - -H3O+ + 2 F- = HF2- + H2O - log_k 3.760 - delta_h 4.550 kcal - -Ca+2 + OH- = CaOH+ - log_k -12.780 - -Ca+2 + CO3-2 = CaCO3 - log_k 3.224 - delta_h 3.545 kcal - -analytic -1228.732 -0.299440 35512.75 485.818 - -#Ca+2 + HCO3- = CaHCO3+ -Ca+2 + CO3-2 + H3O+ = CaHCO3+ + H2O - log_k 11.435 - delta_h -0.871 kcal - -analytic 1317.0071 0.34546894 -39916.84 -517.70761 563713.9 - -gamma 5.4000 0.0000 - -Ca+2 + SO4-2 = CaSO4 - log_k 2.300 - delta_h 1.650 kcal - -Ca+2 + HSO4- = CaHSO4+ - log_k 1.08 - -Ca+2 + PO4-3 = CaPO4- - log_k 6.459 - delta_h 3.100 kcal - -Ca+2 + HPO4-2 = CaHPO4 - log_k 2.739 - delta_h 3.3 kcal - -Ca+2 + H2PO4- = CaH2PO4+ - log_k 1.408 - delta_h 3.4 kcal - -Ca+2 + F- = CaF+ - log_k 0.940 - delta_h 4.120 kcal - -Mg+2 + OH- = MgOH+ - log_k -11.440 - delta_h 15.952 kcal - -Mg+2 + CO3-2 = MgCO3 - log_k 2.98 - delta_h 2.713 kcal - -analytic 0.9910 0.00667 - -Mg+2 + H3O+ + CO3-2 = MgHCO3+ + H2O - log_k 11.399 - delta_h -2.771 kcal - -analytic 48.6721 0.03252849 -2614.335 -18.00263 563713.9 - -Mg+2 + SO4-2 = MgSO4 - log_k 2.370 - delta_h 4.550 kcal - -Mg+2 + PO4-3 = MgPO4- - log_k 6.589 - delta_h 3.100 kcal - -Mg+2 + HPO4-2 = MgHPO4 - log_k 2.87 - delta_h 3.3 kcal - -Mg+2 + H2PO4- = MgH2PO4+ - log_k 1.513 - delta_h 3.4 kcal - -Mg+2 + F- = MgF+ - log_k 1.820 - delta_h 3.200 kcal - -Na+ + OH- = NaOH - log_k -14.180 - -Na+ + CO3-2 = NaCO3- - log_k 1.270 - delta_h 8.910 kcal - -Na+ + HCO3- = NaHCO3 - log_k -0.25 - -Na+ + SO4-2 = NaSO4- - log_k 0.700 - delta_h 1.120 kcal - -Na+ + HPO4-2 = NaHPO4- - log_k 0.29 - -Na+ + F- = NaF - log_k -0.240 - -K+ + OH- = KOH - log_k -14.460 - -K+ + SO4-2 = KSO4- - log_k 0.850 - delta_h 2.250 kcal - -analytic 3.106 0.0 -673.6 - -K+ + HPO4-2 = KHPO4- - log_k 0.29 - -Fe+2 + 2H2O = FeOH+ + H3O+ - log_k -9.500 - delta_h 13.200 kcal - -Fe+2 + Cl- = FeCl+ - log_k 0.140 - -Fe+2 + CO3-2 = FeCO3 - log_k 4.380 - -Fe+2 + HCO3- = FeHCO3+ - log_k 2.0 - -Fe+2 + SO4-2 = FeSO4 - log_k 2.250 - delta_h 3.230 kcal - -Fe+2 + HSO4- = FeHSO4+ - log_k 1.08 - -Fe+2 + 2HS- = Fe(HS)2 - log_k 8.95 - -Fe+2 + 3HS- = Fe(HS)3- - log_k 10.987 - -Fe+2 + HPO4-2 = FeHPO4 - log_k 3.6 - -Fe+2 + H2PO4- = FeH2PO4+ - log_k 2.7 - -Fe+2 + F- = FeF+ - log_k 1.000 - -Fe+2 = Fe+3 + e- - log_k -13.020 - delta_h 9.680 kcal - -gamma 9.0000 0.0000 - -Fe+3 + 2H2O = FeOH+2 + H3O+ - log_k -2.19 - delta_h 10.4 kcal - -Fe+3 + 4H2O = Fe(OH)2+ + 2 H3O+ - log_k -5.67 - delta_h 17.1 kcal - -Fe+3 + 6 H2O = Fe(OH)3 + 3 H3O+ - log_k -12.56 - delta_h 24.8 kcal - -Fe+3 + 8 H2O = Fe(OH)4- + 4 H3O+ - log_k -21.6 - delta_h 31.9 kcal - -2 Fe+3 + 4 H2O = Fe2(OH)2+4 + 2 H3O+ - log_k -2.95 - delta_h 13.5 kcal - -3 Fe+3 + 8 H2O = Fe3(OH)4+5 + 4 H3O+ - log_k -6.3 - delta_h 14.3 kcal - -Fe+3 + Cl- = FeCl+2 - log_k 1.48 - delta_h 5.6 kcal - -Fe+3 + 2 Cl- = FeCl2+ - log_k 2.13 - -Fe+3 + 3 Cl- = FeCl3 - log_k 1.13 - -Fe+3 + SO4-2 = FeSO4+ - log_k 4.04 - delta_h 3.91 kcal - -Fe+3 + HSO4- = FeHSO4+2 - log_k 2.48 - -Fe+3 + 2 SO4-2 = Fe(SO4)2- - log_k 5.38 - delta_h 4.60 kcal - -Fe+3 + HPO4-2 = FeHPO4+ - log_k 5.43 - delta_h 5.76 kcal - -Fe+3 + H2PO4- = FeH2PO4+2 - log_k 5.43 - -Fe+3 + F- = FeF+2 - log_k 6.2 - delta_h 2.7 kcal - -Fe+3 + 2 F- = FeF2+ - log_k 10.8 - delta_h 4.8 kcal - -Fe+3 + 3 F- = FeF3 - log_k 14.0 - delta_h 5.4 kcal - -Al+3 + 2H2O = AlOH+2 + H3O+ - log_k -5.00 - delta_h 11.49 kcal - -analytic -38.253 0.0 -656.27 14.327 - -Al+3 + 4 H2O = Al(OH)2+ + 2 H3O+ - log_k -10.1 - delta_h 26.90 kcal - -analytic 88.500 0.0 -9391.6 -27.121 - -Al+3 + 6 H2O = Al(OH)3 + 3 H3O+ - log_k -16.9 - delta_h 39.89 kcal - -analytic 226.374 0.0 -18247.8 -73.597 - -Al+3 + 8 H2O = Al(OH)4- + 4 H3O+ - log_k -22.7 - delta_h 42.30 kcal - -analytic 51.578 0.0 -11168.9 -14.865 - -Al+3 + SO4-2 = AlSO4+ - log_k 3.5 - delta_h 2.29 kcal - -Al+3 + 2SO4-2 = Al(SO4)2- - log_k 5.0 - delta_h 3.11 kcal - -Al+3 + HSO4- = AlHSO4+2 - log_k 0.46 - -Al+3 + F- = AlF+2 - log_k 7.000 - delta_h 1.060 kcal - -Al+3 + 2 F- = AlF2+ - log_k 12.700 - delta_h 1.980 kcal - -Al+3 + 3 F- = AlF3 - log_k 16.800 - delta_h 2.160 kcal - -Al+3 + 4 F- = AlF4- - log_k 19.400 - delta_h 2.200 kcal - -Al+3 + 5 F- = AlF5-2 - log_k 20.600 - delta_h 1.840 kcal - -Al+3 + 6 F- = AlF6-3 - log_k 20.600 - delta_h -1.670 kcal - -H4SiO4 + H2O = H3SiO4- + H3O+ - log_k -9.83 - delta_h 6.12 kcal - -analytic -302.3724 -0.050698 15669.69 108.18466 -1119669.0 - -H4SiO4 + 2H2O= H2SiO4-2 + 2 H3O+ - log_k -23.0 - delta_h 17.6 kcal - -analytic -294.0184 -0.072650 11204.49 108.18466 -1119669.0 - -H4SiO4 + 4 H3O+ + 6 F- = SiF6-2 + 8 H2O - log_k 30.180 - delta_h -16.260 kcal -PHASES -Calcite - CaCO3 = CO3-2 + Ca+2 - log_k -8.480 - delta_h -2.297 kcal - -analytic -171.9065 -0.077993 2839.319 71.595 - -Dolomite - CaMg(CO3)2 = Ca+2 + Mg+2 + 2 CO3-2 - log_k -17.090 - delta_h -9.436 kcal - -Siderite - FeCO3 = Fe+2 + CO3-2 - log_k -10.890 - delta_h -2.480 kcal - -Gypsum - CaSO4:2H2O = Ca+2 + SO4-2 + 2 H2O - log_k -4.580 - delta_h -0.109 kcal - -analytic 68.2401 0.0 -3221.51 -25.0627 - -Anhydrite - CaSO4 = Ca+2 + SO4-2 - log_k -4.360 - delta_h -1.710 kcal - -analytic 197.52 0.0 -8669.8 -69.835 - -Hydroxyapatite - Ca5(PO4)3OH + 4 H3O+ = 5H2O + 3 HPO4-2 + 5 Ca+2 - log_k -3.421 - delta_h -36.155 kcal - -Fluorite - CaF2 = Ca+2 + 2 F- - log_k -10.600 - delta_h 4.690 kcal - -analytic 66.348 0.0 -4298.2 -25.271 - -SiO2(a) - SiO2 + 2 H2O = H4SiO4 - log_k -2.710 - delta_h 3.340 kcal - -analytic -0.26 0.0 -731.0 - -Chalcedony - SiO2 + 2 H2O = H4SiO4 - log_k -3.550 - delta_h 4.720 kcal - -analytic -0.09 0.0 -1032.0 - -Quartz - SiO2 + 2 H2O = H4SiO4 - log_k -3.980 - delta_h 5.990 kcal - -analytic 0.41 0.0 -1309.0 - -Gibbsite - Al(OH)3 + 3 H3O+ = Al+3 + 6 H2O - log_k 8.110 - delta_h -22.800 kcal - -Al(OH)3(a) - Al(OH)3 + 3 H3O+ = Al+3 + 6 H2O - log_k 10.800 - delta_h -26.500 kcal - -Kaolinite - Al2Si2O5(OH)4 + 6 H3O+ = 7H2O + 2 H4SiO4 + 2 Al+3 - log_k 7.435 - delta_h -35.300 kcal - -Albite - NaAlSi3O8 + 8 H2O = Na+ + Al(OH)4- + 3 H4SiO4 - log_k -18.002 - delta_h 25.896 kcal - -Anorthite - CaAl2Si2O8 + 8 H2O = Ca+2 + 2 Al(OH)4- + 2 H4SiO4 - log_k -19.714 - delta_h 11.580 kcal - -K-feldspar - KAlSi3O8 + 8 H2O = K+ + Al(OH)4- + 3 H4SiO4 - log_k -20.573 - delta_h 30.820 kcal - -K-mica - KAl3Si3O10(OH)2 + 10 H3O+ = K+ + 3 Al+3 + 3 H4SiO4 + 10H2O - log_k 12.703 - delta_h -59.376 kcal - -Chlorite(14A) - Mg5Al2Si3O10(OH)8 + 16 H3O+ = 5Mg+2 + 2Al+3 + 3H4SiO4 + 22H2O - log_k 68.38 - delta_h -151.494 kcal - -Ca-Montmorillonite - Ca0.165Al2.33Si3.67O10(OH)2 + 14 H2O = 0.165Ca+2 + 2.33 Al(OH)4- + 3.67 H4SiO4 + 2 H3O+ - log_k -45.027 - delta_h 58.373 kcal - -Talc - Mg3Si4O10(OH)2 + 4 H2O + 6 H3O+ = 3 Mg+2 + 4 H4SiO4 + 6H2O - log_k 21.399 - delta_h -46.352 kcal - -Illite - K0.6Mg0.25Al2.3Si3.5O10(OH)2 + 12.4H2O = 0.6K+ + 0.25Mg+2 + 2.3Al(OH)4- + 3.5H4SiO4 + 1.2H3O+ - log_k -40.267 - delta_h 54.684 kcal - -Chrysotile - Mg3Si2O5(OH)4 + 6 H3O+ = 7H2O + 2 H4SiO4 + 3 Mg+2 - log_k 32.200 - delta_h -46.800 kcal - -analytic 13.248 0.0 10217.1 -6.1894 - -Sepiolite - Mg2Si3O7.5OH:3H2O + 4 H3O+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + 4H2O - log_k 15.760 - delta_h -10.700 kcal - -Sepiolite(d) - Mg2Si3O7.5OH:3H2O + 4 H3O+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 + 4H2O - log_k 18.660 - -Hematite - Fe2O3 + 6 H3O+ = 2 Fe+3 + 9 H2O - log_k -4.008 - delta_h -30.845 kcal - -Goethite - FeOOH + 3 H3O+ = Fe+3 + 5 H2O - log_k -1.000 - delta_h -14.48 kcal - -Fe(OH)3(a) - Fe(OH)3 + 3 H3O+ = Fe+3 + 6 H2O - log_k 4.891 - -Pyrite - FeS2 + 2H3O+ + 2e- = Fe+2 + 2HS- + 2H2O - log_k -18.479 - delta_h 11.300 kcal - -FeS(ppt) - FeS + H3O+ = Fe+2 + HS- + H2O - log_k -3.915 - -Mackinawite - FeS + H3O+ = Fe+2 + HS- + H2O - log_k -4.648 - -Sulfur - S + 2 H3O+ + 2e- = H2S + 2H2O - log_k 4.882 - delta_h -9.5 kcal - -Vivianite - Fe3(PO4)2:8H2O = 3 Fe+2 + 2 PO4-3 + 8 H2O - log_k -36.000 - -Halite - NaCl = Na+ + Cl- - log_k 1.582 - delta_h 0.918 kcal - -CO2(g) - CO2(g) = CO2 - log_k -1.468 - delta_h -4.776 kcal - -analytic 108.3865 0.01985076 -6919.53 -40.45154 669365.0 - -O2(g) - O2 = O2 - log_k -2.960 - delta_h -1.844 kcal - -H2(g) - H2 = H2 - log_k -3.150 - delta_h -1.759 kcal - -H2O(g) - H2O = H2O - log_k 1.51 - delta_h -44.03 kJ - -N2(g) - N2 = N2 - log_k -3.260 - delta_h -1.358 kcal - -H2S(g) - H2S = H2S - log_k -0.997 - delta_h -4.570 kcal - -CH4(g) - CH4 = CH4 - log_k -2.860 - delta_h -3.373 kcal - -NH3(g) - NH3 = NH3 - log_k 1.770 - delta_h -8.170 kcal - -Melanterite - FeSO4:7H2O = 7 H2O + Fe+2 + SO4-2 - log_k -2.209 - delta_h 4.910 kcal - -analytic 1.447 -0.004153 0.0 0.0 -214949.0 - -Alunite - KAl3(SO4)2(OH)6 + 6 H3O+ = K+ + 3 Al+3 + 2 SO4-2 + 12H2O - log_k -1.400 - delta_h -50.250 kcal - -Jarosite-K - KFe3(SO4)2(OH)6 + 6 H3O+ = 3 Fe+3 + 12 H2O + K+ + 2 SO4-2 - log_k -9.210 - delta_h -31.280 kcal - -EXCHANGE_MASTER_SPECIES - X X- -EXCHANGE_SPECIES - X- = X- - log_k 0.0 - - Na+ + X- = NaX - log_k 0.0 - -gamma 4.0 0.075 - - K+ + X- = KX - log_k 0.7 - -gamma 3.5 0.015 - delta_h -4.3 # Jardine & Sparks, 1984 - - NH4+ + X- = NH4X - log_k 0.6 - -gamma 2.5 0.0 - delta_h -2.4 # Laudelout et al., 1968 - - Ca+2 + 2X- = CaX2 - log_k 0.8 - -gamma 5.0 0.165 - delta_h 7.2 # Van Bladel & Gheyl, 1980 - - Mg+2 + 2X- = MgX2 - log_k 0.6 - -gamma 5.5 0.2 - delta_h 7.4 # Laudelout et al., 1968 - - Fe+2 + 2X- = FeX2 - log_k 0.44 - -gamma 6.0 0.0 - - Al+3 + 3X- = AlX3 - log_k 0.41 - -gamma 9.0 0.0 - - AlOH+2 + 2X- = AlOHX2 - log_k 0.89 - -gamma 0.0 0.0 - -SURFACE_MASTER_SPECIES - Hfo_s Hfo_sOH - Hfo_w Hfo_wOH - -SURFACE_SPECIES -# All surface data from -# Dzombak and Morel, 1990 -# -# -# Acid-base data from table 5.7 -# -# strong binding site--Hfo_s, - - Hfo_sOH = Hfo_sOH - log_k 0.0 - - Hfo_sOH + H3O+ = Hfo_sOH2+ + H2O - log_k 7.29 # = pKa1,int - - Hfo_sOH + H2O = Hfo_sO- + H3O+ - log_k -8.93 # = -pKa2,int - -# weak binding site--Hfo_w - - Hfo_wOH = Hfo_wOH - log_k 0.0 - - Hfo_wOH + H3O+ = Hfo_wOH2+ + H2O - log_k 7.29 # = pKa1,int - - Hfo_wOH + H2O = Hfo_wO- + H3O+ - log_k -8.93 # = -pKa2,int - -############################################### -# CATIONS # -############################################### -# -# Cations from table 10.1 or 10.5 -# -# Calcium - Hfo_sOH + Ca+2 = Hfo_sOHCa+2 - log_k 4.97 - - Hfo_wOH + Ca+2 + H2O = Hfo_wOCa+ + H3O+ - log_k -5.85 -# -# Derived constants table 10.5 -# -# Magnesium - Hfo_wOH + Mg+2 + H2O = Hfo_wOMg+ + H3O+ - log_k -4.6 -# Iron -# Hfo_sOH + Fe+2 + H2O = Hfo_sOFe+ + H3O+ -# log_k 0.7 # LFER using table 10.5 - -# Hfo_wOH + Fe+2 + H2O = Hfo_wOFe+ + H3O+ -# log_k -2.5 # LFER using table 10.5 - -# Iron, strong site: Appelo, Van der Weiden, Tournassat & Charlet, subm. - Hfo_sOH + Fe+2 + H2O = Hfo_sOFe+ + H3O+ - log_k -0.95 -# Iron, weak site: Liger et al., GCA 63, 2939, re-optimized for D&M - Hfo_wOH + Fe+2 + H2O = Hfo_wOFe+ + H3O+ - log_k -2.98 - - Hfo_wOH + Fe+2 + 3H2O = Hfo_wOFeOH + 2H3O+ - log_k -11.55 - -############################################### -# ANIONS # -############################################### -# -# Anions from table 10.6 -# -# Phosphate - Hfo_wOH + PO4-3 + 3 H3O+ = Hfo_wH2PO4 + 4H2O - log_k 31.29 - - Hfo_wOH + PO4-3 + 2 H3O+ = Hfo_wHPO4- + 3H2O - log_k 25.39 - - Hfo_wOH + PO4-3 + H3O+ = Hfo_wPO4-2 + 2H2O - log_k 17.72 -# -# Anions from table 10.7 -# -# Sulfate - Hfo_wOH + SO4-2 + H3O+ = Hfo_wSO4- + 2H2O - log_k 7.78 - - Hfo_wOH + SO4-2 = Hfo_wOHSO4-2 - log_k 0.79 -# -# Derived constants table 10.10 -# - Hfo_wOH + F- + H3O+ = Hfo_wF + 2H2O - log_k 8.7 - - Hfo_wOH + F- = Hfo_wOHF- - log_k 1.6 -# -# Carbonate: Van Geen et al., 1994 reoptimized for HFO -# 0.15 g HFO/L has 0.344 mM sites == 2 g of Van Geen's Goethite/L -# -# Hfo_wOH + CO3-2 + H3O+ = Hfo_wCO3- + 2H2O -# log_k 12.56 -# -# Hfo_wOH + CO3-2 + 2 H3O+= Hfo_wHCO3 + 3 H2O -# log_k 20.62 - -# 9/19/96 -# Added analytical expression for H2S, NH3, KSO4. -# Added species CaHSO4+. -# Added delta H for Goethite. - -# -# Begin Isotope definitions -# -############################################################################################### -SOLUTION_MASTER_SPECIES -############################################################################################### -D D2O 0 D 2 -D(1) D2O 0 D -D(0) HD 0 D -T HTO 0 T 3 -T(1) HTO 0 T -T(0) HT 0 T -[18O] H2[18O] 0 [18O] 18 -[18O](-2) H2[18O] 0 [18O] 18 -[18O](0) O[18O] 0 [18O] 18 -[13C] [13C]O2 0 [13C] 13 -[13C](4) [13C]O2 0 [13C] -[13C](-4) [13C]H4 0 [13C] -[14C] [14C]O2 0 [14C] 14 -[14C](4) [14C]O2 0 [14C] -[14C](-4) [14C]H4 0 [14C] -[34S] [34S]O4-2 0 [34S] 33.967 -[34S](6) [34S]O4-2 0 [34S] -[34S](-2) H[34S]- 0 [34S] -[15N] [15N]O3- 0 [15N] 15.00010897312 -[15N](5) [15N]O3- 0 [15N] -[15N](3) [15N]O2- 0 [15N] -[15N](0) N[15N] 0 [15N] -[15N](-3) [15N]H4+ 0 [15N] -############################################################################################### -ISOTOPES -############################################################################################### -H - -isotope D permil 155.76e-6 # VSMOW (Clark and Fritz, 1997) - -isotope T TU 1e-18 # Solomon and Cook, in eds, Cook and Herczeg, 2000 -H(0) - -isotope D(0) permil 155.76e-6 # VSMOW (Clark and Fritz, 1997) - -isotope T(0) TU 1e-18 # Solomon and Cook, in eds, Cook and Herczeg, 2000 - # 1 THO in 10^18 H2O -# -isotope T pCi/L 3.125e-18 # -#1e-18/3.2 = T/mol H2O -C - -isotope [13C] permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite - # Chang and Li, 1990, Chinese Science Bulletin - -isotope [13C](4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite - # Chang and Li, 1990, Chinese Science Bulletin - -isotope [13C](-4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite - -isotope [14C] pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon - -isotope [14C](4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon - # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) - -isotope [14C](-4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon -C(4) - -isotope [13C](4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite - # Chang and Li, 1990, Chinese Science Bulletin - -isotope [14C](4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon - # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) - # 13.56 Modern Carbon dpm (Kalin, in eds, Cook and Herczeg, 2000) -C(-4) - -isotope [13C](-4) permil 0.0111802 # VPDB, Vienna Pee Dee Belemnite - -isotope [14C](-4) pmc 1.175887709e-12 # Mole fraction of 14C in Modern Carbon - # 14C calculation - # - # lambda = ln(2)/(5730 yrs * 3.15576e7 sec/yr) - # mole/g carbon = -(dn/dt)/lambda = 0.226 dps / 3.8332476e-12 / 6.022136736e23 - # mole C/g C NBS Oxalic Acid with 13C = -19.3: 0.08325783313 - # mole 14C/mol Modern Carbon mol/g carbon/ (mole C/g C) = 1.175887709e-12 - # -O - -isotope [18O] permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) - -isotope [18O](0) permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) -O(0) - -isotope [18O](0) permil 2005.2e-6 # VSMOW (Clark and Fritz, 1997) - -S - # Coplen and others, 2002 - -isotope [34S] permil 0.04416264 # VCDT, Vienna Canyon Diablo Troilite - -isotope [34S](6) permil 0.04416264 # VCDT - -isotope [34S](-2) permil 0.04416264 # VCDT -S(6) - -isotope [34S](6) permil 0.04416264 # VCDT -S(-2) - -isotope [34S](-2) permil 0.04416264 # VCDT -N - # Coplen and others, 2002 - -isotope [15N] permil 0.003676867 # Air - -isotope [15N](5) permil 0.003676867 # Air - -isotope [15N](3) permil 0.003676867 # Air - -isotope [15N](0) permil 0.003676867 # Air - -isotope [15N](-3) permil 0.003676867 # Air -N(5) - -isotope [15N](5) permil 0.003676867 # Air -N(3) - -isotope [15N](3) permil 0.003676867 # Air -N(0) - -isotope [15N](0) permil 0.003676867 # Air -N(-3) - -isotope [15N](-3) permil 0.003676867 # Air -############################################################################################### -ISOTOPE_RATIOS -############################################################################################### -# -# Total aqueous ratios -# - R(D) D - R(T) T - R(18O) [18O] - R(13C) [13C] - R(14C) [14C] - R(15N) [15N] - R(34S) [34S] -# H2O(l) ratios - R(D)_H2O(l) D - R(T)_H2O(l) T - R(18O)_H2O(l) [18O] -# OH- ratios - R(D)_OH- D - R(T)_OH- T - R(18O)_OH- [18O] -# H3O+ ratios - R(D)_H3O+ D - R(T)_H3O+ T - R(18O)_H3O+ [18O] -# O2(aq) ratios - R(18O)_O2(aq) [18O] -# H2(aq) ratios - R(D)_H2(aq) D - R(T)_H2(aq) T -# CO2(aq) ratios - R(13C)_CO2(aq) [13C] - R(14C)_CO2(aq) [14C] - R(18O)_CO2(aq) [18O] -# HCO3- ratios - R(D)_HCO3- D - R(T)_HCO3- T - R(18O)_HCO3- [18O] - R(13C)_HCO3- [13C] - R(14C)_HCO3- [14C] -# CO3-2 ratios - R(18O)_CO3-2 [18O] - R(13C)_CO3-2 [13C] - R(14C)_CO3-2 [14C] -# CH4(aq) ratios - R(D)_CH4(aq) D - R(T)_CH4(aq) T - R(13C)_CH4(aq) [13C] - R(14C)_CH4(aq) [14C] -# SO4-2 ratios - R(34S)_SO4-2 [34S] -# HSO4- ratios - R(D)_HSO4- D - R(T)_HSO4- T - R(34S)_HSO4- [34S] -# S-2 ratios - R(34S)_S-2 [34S] -# HS- ratios - R(D)_HS- D - R(T)_HS- T - R(34S)_HS- [34S] -# H2S ratios - R(D)_H2S(aq) D - R(T)_H2S(aq) T - R(34S)_H2S(aq) [34S] -# NO3- ratios - R(15N)_NO3- [15N] -# NO2- ratios - R(15N)_NO2- [15N] -# N2(aq) ratios - R(15N)_N2(aq) [15N] -# NH3(aq) ratios - R(D)_NH3(aq) D - R(T)_NH3(aq) T - R(15N)_NH3(aq) [15N] -# NH4+ ratios - R(D)_NH4+ D - R(T)_NH4+ T - R(15N)_NH4+ [15N] -# -# Ratios for minerals and gases -# -# H2O(g) ratios - R(D)_H2O(g) D - R(T)_H2O(g) T - R(18O)_H2O(g) [18O] -# O2(g) ratios - R(18O)_O2(g) [18O] -# H2(g) ratios - R(D)_H2(g) D - R(T)_H2(g) T -# CO2(g) ratios - R(18O)_CO2(g) [18O] - R(13C)_CO2(g) [13C] - R(14C)_CO2(g) [14C] -# Calcite ratios - R(18O)_Calcite [18O] - R(13C)_Calcite [13C] - R(14C)_Calcite [14C] -# Pyrite ratios - R(34S)_Pyrite [34S] -# CH4(g) ratios - R(D)_CH4(g) D - R(T)_CH4(g) T - R(13C)_CH4(g) [13C] - R(14C)_CH4(g) [14C] -# H2S(g) ratios - R(D)_H2S(g) D - R(T)_H2S(g) T - R(34S)_H2S(g) [34S] -# Gypsum ratios - R(34S)_Gypsum [34S] -# Anhydrite ratios - R(34S)_Anhydrite [34S] -# N2(g) ratios - R(15N)_N2(g) [15N] -# NH3(g) ratios - R(D)_NH3(g) D - R(T)_NH3(g) T - R(15N)_NH3(g) [15N] - -ISOTOPE_ALPHAS -# OH- - Alpha_D_OH-/H2O(l) Log_alpha_D_OH-/H2O(l) - Alpha_T_OH-/H2O(l) Log_alpha_T_OH-/H2O(l) - Alpha_18O_OH-/H2O(l) Log_alpha_18O_OH-/H2O(l) -# H3O+ - Alpha_D_H3O+/H2O(l) Log_alpha_D_H3O+/H2O(l) - Alpha_T_H3O+/H2O(l) Log_alpha_T_H3O+/H2O(l) - Alpha_18O_H3O+/H2O(l) Log_alpha_18O_H3O+/H2O(l) -# O2(aq) - Alpha_18O_O2(aq)/H2O(l) Log_alpha_18O_O2(aq)/H2O(l) -# H2(aq) - Alpha_D_H2(aq)/H2O(l) Log_alpha_D_H2(aq)/H2O(l) - Alpha_T_H2(aq)/H2O(l) Log_alpha_T_H2(aq)/H2O(l) -# CO2(aq) - Alpha_18O_CO2(aq)/H2O(l) Log_alpha_18O_CO2(aq)/H2O(l) - Alpha_13C_CO2(aq)/CO2(g) Log_alpha_13C_CO2(aq)/CO2(g) - Alpha_14C_CO2(aq)/CO2(g) Log_alpha_14C_CO2(aq)/CO2(g) -# HCO3- - Alpha_D_HCO3-/H2O(l) Log_alpha_D_HCO3-/H2O(l) - Alpha_T_HCO3-/H2O(l) Log_alpha_T_HCO3-/H2O(l) - Alpha_18O_HCO3-/H2O(l) Log_alpha_18O_HCO3-/H2O(l) - Alpha_13C_HCO3-/CO2(aq) Log_alpha_13C_HCO3-/CO2(aq) - Alpha_14C_HCO3-/CO2(aq) Log_alpha_14C_HCO3-/CO2(aq) - Alpha_13C_HCO3-/CO2(g) Log_alpha_13C_HCO3-/CO2(g) - Alpha_14C_HCO3-/CO2(g) Log_alpha_14C_HCO3-/CO2(g) -# CO3-2 - Alpha_18O_CO3-2/H2O(l) Log_alpha_18O_CO3-2/H2O(l) - Alpha_13C_CO3-2/CO2(aq) Log_alpha_13C_CO3-2/CO2(aq) - Alpha_14C_CO3-2/CO2(aq) Log_alpha_14C_CO3-2/CO2(aq) - Alpha_13C_CO3-2/CO2(g) Log_alpha_13C_CO3-2/CO2(g) - Alpha_14C_CO3-2/CO2(g) Log_alpha_14C_CO3-2/CO2(g) -# CH4(aq) - Alpha_D_CH4(aq)/H2O(l) Log_alpha_D_CH4(aq)/H2O(l) - Alpha_T_CH4(aq)/H2O(l) Log_alpha_T_CH4(aq)/H2O(l) - Alpha_13C_CH4(aq)/CO2(aq) Log_alpha_13C_CH4(aq)/CO2(aq) - Alpha_14C_CH4(aq)/CO2(aq) Log_alpha_14C_CH4(aq)/CO2(aq) -# HSO4- - Alpha_D_HSO4-/H2O(l) Log_alpha_D_HSO4-/H2O(l) - Alpha_T_HSO4-/H2O(l) Log_alpha_T_HSO4-/H2O(l) - Alpha_34S_HSO4-/SO4-2 Log_alpha_34S_HSO4-/SO4-2 -# S-2 - Alpha_34S_S-2/HS- Log_alpha_34S_S-2/HS- -# HS- - Alpha_D_HS-/H2O(l) Log_alpha_D_HS-/H2O(l) - Alpha_T_HS-/H2O(l) Log_alpha_T_HS-/H2O(l) - Alpha_34S_HS-/SO4-2 Log_alpha_34S_HS-/SO4-2 -# H2S - Alpha_D_H2S(aq)/H2O(l) Log_alpha_D_H2S(aq)/H2O(l) - Alpha_T_H2S(aq)/H2O(l) Log_alpha_T_H2S(aq)/H2O(l) - Alpha_34S_H2S(aq)/HS- Log_alpha_34S_H2S(aq)/HS- -# NO2- - Alpha_15N_NO2-/NO3- Log_alpha_15N_NO2-/NO3- -# N2(aq) - Alpha_15N_N2(aq)/NO3- Log_alpha_15N_N2(aq)/NO3- -# NH3(aq) - Alpha_D_NH3(aq)/H2O(l) Log_alpha_D_NH3(aq)/H2O(l) - Alpha_T_NH3(aq)/H2O(l) Log_alpha_T_NH3(aq)/H2O(l) - Alpha_15N_NH3(aq)/NO3- Log_alpha_15N_NH3(aq)/NO3- -# NH4+ - Alpha_D_NH4+/H2O(l) Log_alpha_D_NH4+/H2O(l) - Alpha_T_NH4+/H2O(l) Log_alpha_T_NH4+/H2O(l) - Alpha_15N_NH4+/NH3(aq) Log_alpha_15N_NH4+/NH3(aq) -# H2O(g) - Alpha_D_H2O(g)/H2O(l) Log_alpha_D_H2O(g)/H2O(l) - Alpha_T_H2O(g)/H2O(l) Log_alpha_T_H2O(g)/H2O(l) - Alpha_18O_H2O(g)/H2O(l) Log_alpha_18O_H2O(g)/H2O(l) -# O2(g) - Alpha_18O_O2(g)/H2O(l) Log_alpha_18O_O2(g)/H2O(l) #? -# H2(g) - Alpha_D_H2(g)/H2O(l) Log_alpha_D_H2(g)/H2O(l) #? - Alpha_T_H2(g)/H2O(l) Log_alpha_T_H2(g)/H2O(l) #? -# CO2(g) - Alpha_18O_CO2(g)/H2O(l) Log_alpha_18O_CO2(g)/H2O(l) - Alpha_13C_CO2(g)/CO2(aq) Log_alpha_13C_CO2(g)/CO2(aq) - Alpha_14C_CO2(g)/CO2(aq) Log_alpha_14C_CO2(g)/CO2(aq) -# Calcite - Alpha_18O_Calcite/H2O(l) Log_alpha_18O_Calcite/H2O(l) - Alpha_13C_Calcite/CO2(aq) Log_alpha_13C_Calcite/CO2(aq) - Alpha_13C_Calcite/CO2(g) Log_alpha_13C_Calcite/CO2(g) - Alpha_14C_Calcite/CO2(aq) Log_alpha_14C_Calcite/CO2(aq) - Alpha_14C_Calcite/CO2(g) Log_alpha_14C_Calcite/CO2(g) -# Pyrite - Alpha_34S_Pyrite/HS- Log_alpha_34S_Pyrite/HS- -# CH4(g) - Alpha_D_CH4(g)/H2O(l) Log_alpha_D_CH4(g)/H2O(l) - Alpha_T_CH4(g)/H2O(l) Log_alpha_T_CH4(g)/H2O(l) - Alpha_13C_CH4(g)/CO2(aq) Log_alpha_13C_CH4(g)/CO2(aq) #? - Alpha_14C_CH4(g)/CO2(aq) Log_alpha_14C_CH4(g)/CO2(aq) #? -# H2S(g) - Alpha_D_H2S(g)/H2S(aq) Log_alpha_D_H2S(g)/H2S(aq) - Alpha_T_H2S(g)/H2S(aq) Log_alpha_T_H2S(g)/H2S(aq) - Alpha_34S_H2S(g)/H2S(aq) Log_alpha_34S_H2S(g)/H2S(aq) -# Gypsum - Alpha_34S_Gypsum/SO4-2 Log_alpha_34S_Gypsum/SO4-2 -# Anhydrite - Alpha_34S_Anhydrite/SO4-2 Log_alpha_34S_Anhydrite/SO4-2 -# N2(g) - Alpha_15N_N2(g)/N2(aq) Log_alpha_15N_N2(g)/N2(aq) -# NH3(g) - Alpha_D_NH3(g)/H2O(l) Log_alpha_D_NH3(g)/H2O(l) - #Alpha_T_NH3(g)/H2O(l) Log_alpha_T_NH3(g)/H2O(l) - Alpha_15N_NH3(g)/NH3(aq) Log_alpha_15N_NH3(g)/NH3(aq) - -NAMED_EXPRESSIONS -# -# OH- fractionation factors -# -Log_alpha_D_OH-/H2O(l) # 1000ln(alpha(25C)) = -741.9 - # 13.5 C - -ln_alpha1000 -741.9 # Heinzinger and Weston, J Phys Chem, 1964, p. 2179-2183 - # Modified August 22, 2008 - -Log_alpha_T_OH-/H2O(l) # 1000ln(alpha(13.5C)) = -1483.8 - # 13.5 C - -add_logk Log_alpha_D_OH-/H2O(l) 2 # Craig, J Geol, 1954, p 133. - # Modified August 22, 2008 - -Log_alpha_18O_OH-/H2O(l) # - # 25 C - -ln_alpha1000 -39.221 # Green and Taube, J Phys Chem, 1963, v 67, p. 1565-1566. - # 15 C - # -ln_alpha1000 -44.017 # Green and Taube, J Phys Chem, 1963, v 67, p. 1565-1566. - # Modified August 22, 2008 -# -# H3O+ fractionation factors -# -Log_alpha_D_H3O+/H2O(l) # - # 13.5 C - -ln_alpha1000 -364.6431 # Heinzinger and Weston, J Phys Chem, 1964, p. 744-751. - # Modified August 22, 2008 - -Log_alpha_T_H3O+/H2O(l) # 1000ln(alpha(13.5C)) = -799.286 - # 13.5 C - -add_logk Log_alpha_D_H3O+/H2O(l) 2 # Craig, J Geol, 1954, p 133. - # Modified August 22, 2008 - -Log_alpha_18O_H3O+/H2O(l) # 1000ln(alpha(25C)) = 22.9 - # 25 C - -ln_alpha1000 22.86 # Thorton, 1962 Am Chem Soc J, 1962, v 84, p. 2474-2475. - # Checked August 22, 2008 -# -# O2(aq) fractionation factors -# -Log_alpha_18O_O2(aq)/H2O(l) - -ln_alpha1000 0 # Unknown - -# -# H2(aq) fractionation factors -# -Log_alpha_D_H2(aq)/H2O(l) # 1000ln(alpha(25C)) = ??? - -add_logk Log_alpha_D_H2(g)/H2(aq) -1 - -add_logk Log_alpha_D_H2(g)/H2O(l) 1 - # Added August 22, 2008 - -Log_alpha_T_H2(aq)/H2O(l) - -add_logk Log_alpha_T_H2(g)/H2(aq) -1 - -add_logk Log_alpha_T_H2(g)/H2O(l) 1 - # Added August 22, 2008 -# -# CO2(aq) fractionation factors -# -Log_alpha_18O_CO2(aq)/H2O(l) # 1000ln(alpha(25C)) = 41.2 - # 0-100 C - -ln_alpha1000 -21.9285 0.0 19.43596e3 0.0 -0.181115e6 - -Log_alpha_13C_CO2(aq)/CO2(g) # 1000ln(alpha(25C)) -0.84 - # Deines and others (1974) - -ln_alpha1000 -0.91 0.0 0.0 0.0 .0063e6 - -Log_alpha_14C_CO2(aq)/CO2(g) # 1000ln(alpha(25C)) -0.84 - -add_logk Log_alpha_13C_CO2(aq)/CO2(g) 2 -# -# HCO3- fractionation factors -# -Log_alpha_18O_HCO3-/H2O(l) - -ln_alpha1000 0.0 #? - -Log_alpha_D_HCO3-/H2O(l) - -ln_alpha1000 0.0 - -Log_alpha_T_HCO3-/H2O(l) - -ln_alpha1000 0.0 - -Log_alpha_13C_HCO3-/CO2(g) # 1000ln(alpha(25C)) = 7.82 - # Deines and others (1974) - -ln_alpha1000 -4.54 0.0 0.0 0.0 1.099e6 - -Log_alpha_13C_HCO3-/CO2(aq) # 1000ln(alpha(25C)) = 8.7 - # 0-100 C -# -ln_alpha1000 -3.63 0.0 0.0 0.0 1.0927e6 - -add_logk Log_alpha_13C_HCO3-/CO2(g) 1 - -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 - -Log_alpha_14C_HCO3-/CO2(g) # 1000ln(alpha(25C)) = 7.82 - # Deines and others (1974) - -add_logk Log_alpha_13C_HCO3-/CO2(g) 2 - -Log_alpha_14C_HCO3-/CO2(aq) # 1000ln(alpha(25C)) = 17.3 - # 0-100 C -# -ln_alpha1000 -7.26 0.0 0.0 0.0 2.1854e6 - -add_logk Log_alpha_14C_HCO3-/CO2(g) 1 - -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 -# -# CO3-2 fractionation factors -# -Log_alpha_18O_CO3-2/H2O(l) - -ln_alpha1000 0.0 - -Log_alpha_13C_CO3-2/CO2(g) # 1000ln(alpha(25C)) - # Deines and others (1974) - -ln_alpha1000 -3.4 0.0 0.0 0.0 0.870e6 - -Log_alpha_13C_CO3-2/CO2(aq) # 1000ln(alpha(25C)) - # 0-100 C -# -ln_alpha1000 -2.49 0.0 0.0 0.0 0.8637e6 - -add_logk Log_alpha_13C_CO3-2/CO2(g) 1 - -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 - -Log_alpha_14C_CO3-2/CO2(g) # 1000ln(alpha(25C)) - # Deines and others (1974) - -add_logk Log_alpha_13C_CO3-2/CO2(g) 2 - -Log_alpha_14C_CO3-2/CO2(aq) # 1000ln(alpha(25C)) - # -# -ln_alpha1000 -2.49 0.0 0.0 0.0 0.8637e6 - -add_logk Log_alpha_14C_CO3-2/CO2(g) 1 - -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 -# -# CH4(aq) fractionation factors -# -Log_alpha_D_CH4(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_CH4(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_13C_CH4(aq)/CO2(aq) - -ln_alpha1000 0 - -Log_alpha_14C_CH4(aq)/CO2(aq) - -ln_alpha1000 0 -# -# HSO4- fractionation factors -# -Log_alpha_D_HSO4-/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_HSO4-/H2O(l) - -ln_alpha1000 0 - -Log_alpha_34S_HSO4-/SO4-2 - -ln_alpha1000 0.0 -# -# S-2 fractionation factors -# -Log_alpha_34S_S-2/HS- - -ln_alpha1000 0.0 -# -# HS- fractionation factors -# -Log_alpha_D_HS-/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_HS-/H2O(l) - -ln_alpha1000 0 - -Log_alpha_34S_HS-/SO4-2 - -ln_alpha1000 0.0 -# -# H2S fractionation factors -# -Log_alpha_D_H2S(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_H2S(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_34S_H2S(aq)/HS- - -ln_alpha1000 0.0 -# -# NO2- fractionation factors -# -Log_alpha_15N_NO2-/NO3- - -ln_alpha1000 0.0 -# -# N2(aq) fractionation factors -# -Log_alpha_15N_N2(aq)/NO3- - -ln_alpha1000 0.0 -# -# NH3(aq) fractionation factors -# -Log_alpha_D_NH3(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_NH3(aq)/H2O(l) - -ln_alpha1000 0 - -Log_alpha_15N_NH3(aq)/NO3- - -ln_alpha1000 0 -# -# NH4+ fractionation factors -# -Log_alpha_D_NH4+/H2O(l) - -ln_alpha1000 0 - -Log_alpha_T_NH4+/H2O(l) - -ln_alpha1000 0 - -Log_alpha_15N_NH4+/NH3(aq) - -ln_alpha1000 0 -# -# H2O(g) fractionation factors -# -Log_alpha_D_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -76.4 - # 0-100 C - -ln_alpha1000 -52.612 0.0 76.248e3 0.0 -24.844e6 - # Friedman and O'Neil: Majzoub, 1971, J Chim Phys, v 65, p. 563-568. - # Checked August 22, 2008 - -Log_alpha_T_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -152.7 - # 0-100 C - -add_logk Log_alpha_D_H2O(g)/H2O(l) 2 # Craig, J Geol, 1954, p 133. - # Modified August 22, 2008 - -Log_alpha_18O_H2O(g)/H2O(l) # 1000ln(alpha(25C)) = -9.3 - # 0-100 C - -ln_alpha1000 2.0667 0.0 0.4156e3 0.0 -1.137e6 - # Friedman and O'Neil: Majzoub, 1971, J Chim Phys, v 65, p. 563-568. - # Checked August 22, 2008 -# -# O2(g) fractionaton factors -# - -Log_alpha_18O_O2(g)/H2O(l) # Unknown - -ln_alpha1000 0.0 - -Log_alpha_18O_O2(g)/O2(aq) # 1000ln(alpha(25C)) = 0.6 - # 0.85 - 0.01TC 1-23C = 3.5815 - .01TK - -ln_alpha1000 3.5815 -.01 0 0 0 # Kroopnick and Craig, 1972, Science, v. 175, p. 54-55. - # Added August 22, 2008 -# -# H2(g) fractionaton factors -# -Log_alpha_D_H2O(g)/H2(g) # 1000ln(alpha(25C)) = 266. - -ln_alpha1000 -303.9 0.0 467.6e3 0.0 0.0 - # Friedman and O'Neil: Seuss, 1949, Zeitschrift Naturforschung - # Friedman and O'Neil: Battinga, 1969, Geochim Cosmochim Acta, v 33, p. 49-64. - # Added August 22, 2008 - -Log_alpha_T_H2O(g)/H2(g) # 1000ln(alpha(25C)) = 532. - -add_logk Log_alpha_D_H2O(g)/H2(g) 2 # Craig, J Geol, 1954, p 133. - # Added August 22, 2008 - -Log_alpha_D_H2(g)/H2(aq) # 1000ln(alpha(25C)) = 0 - -ln_alpha1000 0 # Assumed August 22, 2008 - -Log_alpha_T_H2(g)/H2(aq) # 1000ln(alpha(25C)) = 0 - -add_logk Log_alpha_T_H2(g)/H2(aq) 2 # Craig, J Geol, 1954, p 133. - # Added August 22, 2008 - -Log_alpha_D_H2(g)/H2O(l) # - -add_logk Log_alpha_D_H2O(g)/H2(g) -1 - -add_logk Log_alpha_D_H2O(g)/H2O(l) 1 - # Added August 22, 2008 - -Log_alpha_T_H2(g)/H2O(l) - -add_logk Log_alpha_T_H2O(g)/H2(g) -1 - -add_logk Log_alpha_T_H2O(g)/H2O(l) 1 - # Added August 22, 2008 - - - -# -# CO2(g) fractionaton factors -# -Log_alpha_18O_CO2(g)/H2O(l) # 1000ln(alpha(25C)) = 40.151 - # 0-100 C - -ln_alpha1000 -19.97 0.0 17.9942e3 0.0 -0.0206e6 - # Battinga, written commun. 1973, cited in Friedman and O'Neil - -Log_alpha_13C_CO2(g)/CO2(aq) # 1000ln(alpha(25C)) = 0.84 - # 0-100 C - -ln_alpha1000 0.91 0.0 0.0 0.0 -0.0063e6 - -Log_alpha_14C_CO2(g)/CO2(aq) # 1000ln(alpha(25C)) = 1.7 - # 0-100 C - -ln_alpha1000 1.82 0.0 0.0 0.0 -0.0126e6 -# -# CO2-Calcite fractionation factors -# -#Log_alpha_18O_CO2(aq)/Calcite # 1000ln(alpha(25C)) = 13.6 -# # 0-100 C -# -ln_alpha1000 -4.7383 0.0 12.05276e3 0.0 -1.963915e6 -Log_alpha_18O_Calcite/H2O(l) # 1000ln(alpha(25C)) = 28.38 - # O'Neil, Clayton and Mayeda (1969) - -ln_alpha1000 -2.89 0 0 0 2.78e6 - -Log_alpha_13C_Calcite/CO2(g) # 1000ln(alpha(25C)) - # Deines and others (1974) - -ln_alpha1000 -3.63 0.0 0.0 0.0 1.194e6 - -Log_alpha_13C_Calcite/CO2(aq) # 1000ln(alpha(25C)) - # Deines and others (1974) - -add_logk Log_alpha_13C_Calcite/CO2(g) 1 - -add_logk Log_alpha_13C_CO2(aq)/CO2(g) -1 - -Log_alpha_14C_Calcite/CO2(g) # 1000ln(alpha(25C)) - -add_logk Log_alpha_13C_Calcite/CO2(g) 2 - -Log_alpha_14C_Calcite/CO2(aq) # 1000ln(alpha(25C)) - # Deines and others (1974) - -add_logk Log_alpha_14C_Calcite/CO2(g) 1 - -add_logk Log_alpha_14C_CO2(aq)/CO2(g) -1 -# -# Pyrite fractionation factors -# -Log_alpha_34S_Pyrite/HS- - -ln_alpha1000 0 -# -# CH4(g) fractionation factors -# -Log_alpha_D_CH4(g)/H2O(l) #? - -ln_alpha1000 0.0 - -Log_alpha_T_CH4(g)/H2O(l) #? - -ln_alpha1000 0.0 - -Log_alpha_13C_CH4(g)/CO2(aq) #? - -ln_alpha1000 0.0 - -Log_alpha_14C_CH4(g)/CO2(aq) #? - -ln_alpha1000 0.0 -# -# H2S(g) fractionation factors -# -Log_alpha_D_H2S(g)/H2S(aq) - -ln_alpha1000 0 - -Log_alpha_T_H2S(g)/H2S(aq) - -ln_alpha1000 0 - -Log_alpha_34S_H2S(g)/H2S(aq) - -ln_alpha1000 0 -# -# Gypsum fractionation factors -# -Log_alpha_34S_Gypsum/SO4-2 - -ln_alpha1000 0 -# -# Anhydrite fractionation factors -# -Log_alpha_34S_Anhydrite/SO4-2 - -ln_alpha1000 0 -# -# N2(g) fractionation factors -# -Log_alpha_15N_N2(g)/N2(aq) - -ln_alpha1000 0 -# -# NH3(g) fractionation factors -# -Log_alpha_D_NH3(g)/H2O(l) #? - -ln_alpha1000 0 - -Log_alpha_T_NH3(g)/H2O(l) #? - -ln_alpha1000 0 - -Log_alpha_15N_NH3(g)/NH3(aq) - -ln_alpha1000 0 - -############################################################################################### -CALCULATE_VALUES -############################################################################################### -# -# Ratios -# -R(D) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = TOT("D") -40 total_H = TOT("H") -50 ratio = total_D/total_H -100 save ratio - -end - -R(T) ?? - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = TOT("T") -40 total_water = MOL("H2O") -50 ratio = total_T/total_water -100 save ratio - -end - -R(18O) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 total_18O = TOT("[18O]") -40 total_16O = TOT("O") -50 ratio = total_18O/total_16O -100 save ratio - -end - -R(13C) - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 100 -30 total_13C = TOT("[13C]") -40 total_12C = TOT("C") -50 ratio = total_13C/total_12C -100 save ratio - -end - -R(14C) - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 100 -30 total_14C = TOT("[14C]") -40 total_C = TOT("C") -50 ratio = total_14C/total_C -100 save ratio - -end - -R(15N) - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = TOT("[15N]") -40 total_14N = TOT("N") -50 ratio = total_15N/total_14N -100 save ratio - -end - -R(34S) - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 100 -30 total_34S = TOT("[34S]") -40 total_32S = TOT("S") -50 ratio = total_34S/total_32S -100 save ratio - -end -# -# H2O(l) ratios -# -R(D)_H2O(l) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("{H,D,T}2{O,[18O]}","D") -40 total_H = sum_species("{H,D,T}2{O,[18O]}","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_H2O(l) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{H,D,T}2{O,[18O]}","T") -40 total_H = sum_species("{H,D,T}2{O,[18O]}","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(18O)_H2O(l) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 total_18O = sum_species("{H,D,T}2[18O]","[18O]") -40 total_16O = sum_species("{H,D,T}2O","O") -50 if (total_16O <= 0) THEN GOTO 100 -60 ratio = total_18O/total_16O -100 save ratio - -end -# -# OH- ratios -# -R(D)_OH- - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("*{O,[18O]}D*","D") -40 total_H = sum_species("*{O,[18O]}H*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_OH- - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("*{O,[18O]}T*","T") -40 total_H = sum_species("*{O,[18O]}H*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(18O)_OH- - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 total_18O = sum_species("*[18O]{H,D,T}*","[18O]") -40 total_16O = sum_species("*O{H,D,T}*","O") -50 ratio = total_18O/total_16O -100 save ratio - -end - -# -# H3O+ ratios -# -R(D)_H3O+ - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("{H,D,T}3{O,[18O]}+","D") -40 total_H = sum_species("{H,D,T}3{O,[18O]}+","H") -50 ratio = total_D/total_H -100 save ratio - -end - -R(T)_H3O+ - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{H,D,T}3{O,[18O]}+","T") -40 total_H = sum_species("{H,D,T}3{O,[18O]}+","H") -50 ratio = total_T/total_H -100 save ratio - -end - -R(18O)_H3O+ - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 total_18O = sum_species("{H,D,T}3{O,[18O]}+","[18O]") -40 total_16O = sum_species("{H,D,T}3{O,[18O]}+","O") -50 ratio = total_18O/total_16O -100 save ratio - -end - -# -# O2(aq) ratios -# -R(18O)_O2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 total_18O = sum_species("{O,[18O]}2","[18O]") -40 total_O = sum_species("{O,[18O]}2","O") -50 if (total_O <= 0) THEN GOTO 100 -60 ratio = total_18O/total_O -100 save ratio - -end -# -# H2(aq) ratios -# -R(D)_H2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("{H,D,T}2","D") -40 total_H = sum_species("{H,D,T}2","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_H2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{H,D,T}2","T") -40 total_H = sum_species("{H,D,T}2","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end -# -# CO2(aq) ratios -# -R(13C)_CO2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 100 -30 total_13C = sum_species("[13C]{O,[18O]}2","[13C]") -40 total_12C = sum_species("C{O,[18O]}2","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_13C/total_12C -100 save ratio - -end - -R(14C)_CO2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 100 -30 total_14C = sum_species("[14C]{O,[18O]}2","[14C]") -40 total_12C = sum_species("C{O,[18O]}2","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_14C/total_12C -100 save ratio - -end - -R(18O)_CO2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 if (TOT("C") <= 0) THEN GOTO 100 -40 total_18O = sum_species("{C,[13C],[14C]}{O,[18O]}2","[18O]") -50 total_16O = sum_species("{C,[13C],[14C]}{O,[18O]}2","O") -60 if (total_16O <= 0) THEN GOTO 100 -70 ratio = total_18O/total_16O -100 save ratio - -end -# -# HCO3- ratios -# -R(D)_HCO3- - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 if (TOT("C") <= 0) THEN GOTO 100 -40 total_D = sum_species("*D{C,[13C],[14C]}{O,[18O]}3*","D") -50 total_H = sum_species("*H{C,[13C],[14C]}{O,[18O]}3*","H") -60 if (total_H <= 0) THEN GOTO 100 -70 ratio = total_D/total_H -100 save ratio - -end - -R(T)_HCO3- - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 if (TOT("C") <= 0) THEN GOTO 100 -40 total_T = sum_species("*T{C,[13C],[14C]}{O,[18O]}3*","T") -50 total_H = sum_species("*H{C,[13C],[14C]}{O,[18O]}3*","H") -60 if (total_H <= 0) THEN GOTO 100 -70 ratio = total_T/total_H -100 save ratio - -end - -R(18O)_HCO3- - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 if (TOT("C") <= 0) THEN GOTO 100 -40 total_18O = sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","[18O]") -50 total_16O = sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","O") -60 if (total_16O <= 0) THEN GOTO 100 -70 ratio = total_18O/total_16O -100 save ratio - -end - -R(13C)_HCO3- - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 100 -30 total_13C = sum_species("*{H,D,T}[13C]{O,[18O]}3*","[13C]") -40 total_12C = sum_species("*{H,D,T}C{O,[18O]}3*","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_13C/total_12C -100 save ratio - -end - -R(14C)_HCO3- - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 100 -30 total_14C = sum_species("*{H,D,T}[14C]{O,[18O]}3*","[14C]") -40 total_12C = sum_species("*{H,D,T}C{O,[18O]}3*","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_14C/total_12C -100 save ratio - -end -# -# CO3-2 ratios -# -R(18O)_CO3-2 - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 100 -30 if (TOT("C") <= 0) THEN GOTO 100 -40 total_18O = sum_species("*{C,[13C],[14C]}{O,[18O]}3*","[18O]") - sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","[18O]") -50 total_16O = sum_species("*{C,[13C],[14C]}{O,[18O]}3*","O") - sum_species("*{H,D,T}{C,[13C],[14C]}{O,[18O]}3*","O") -60 if (total_16O <= 0) THEN GOTO 100 -70 ratio = total_18O/total_16O -100 save ratio - -end - -R(13C)_CO3-2 - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 100 -30 total_13C = sum_species("*[13C]{O,[18O]}3*","[13C]") - sum_species("*{H,D,T}[13C]{O,[18O]}3*","[13C]") -40 total_12C = sum_species("*C{O,[18O]}3*","C") - sum_species("*{H,D,T}C{O,[18O]}3*","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_13C/total_12C -100 save ratio - -end - -R(14C)_CO3-2 - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 100 -30 total_14C = sum_species("*[14C]{O,[18O]}3*","[14C]") - sum_species("*{H,D,T}[14C]{O,[18O]}3*","[14C]") -40 total_12C = sum_species("*C{O,[18O]}3*","C") - sum_species("*{H,D,T}C{O,[18O]}3*","C") -50 if (total_12C <= 0) THEN GOTO 100 -60 ratio = total_14C/total_12C -100 save ratio - -end -# -# CH4(aq) ratios -# -R(D)_CH4(aq) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("{C,[13C],[14C]}{H,D,T}4","D") -40 total_H = sum_species("{C,[13C],[14C]}{H,D,T}4","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_CH4(aq) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{C,[13C],[14C]}{H,D,T}4","T") -40 total_H = sum_species("{C,[13C],[14C]}{H,D,T}4","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(13C)_CH4(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 100 -30 total_13C = sum_species("[13C]{H,D,T}4","[13C]") -40 total_C = sum_species("C{H,D,T}4","C") -50 if (total_C <= 0) THEN GOTO 100 -60 ratio = total_13C/total_C -100 save ratio - -end - -R(14C)_CH4(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 100 -30 total_14C = sum_species("[14C]{H,D,T}4","[14C]") -40 total_C = sum_species("C{H,D,T}4","C") -50 if (total_C <= 0) THEN GOTO 100 -60 ratio = total_14C/total_C -100 save ratio - -end -# -# SO4-2 ratios -# -R(34S)_SO4-2 - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 100 -30 total_34S = sum_species("*[34S]O4*","[34S]") - sum_species("*{H,D,T}[34S]O4*","[34S]") -40 total_S = sum_species("*SO4*","S") - sum_species("*{H,D,T}SO4*","S") -50 if (total_S <= 0) THEN GOTO 100 -60 ratio = total_34S/total_S -100 save ratio - -end -# -# HSO4- ratios -# -R(D)_HSO4- - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("*D{S,[34S]}O4*","D") -40 total_H = sum_species("*H{S,[34S]}O4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_HSO4- - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("*T{S,[34S]}O4*","T") -40 total_H = sum_species("*H{S,[34S]}O4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(34S)_HSO4- - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 100 -30 total_34S = sum_species("*{H,D,T}[34S]O4*","[34S]") -40 total_S = sum_species("*{H,D,T}SO4*","S") -50 if (total_S <= 0) THEN GOTO 100 -60 ratio = total_34S/total_S -100 save ratio - -end -# -# S-2 ratios -# -R(34S)_S-2 - -start -10 ratio = -9999.999 -20 if (TOT("[34S](-2)") <= 0) THEN GOTO 100 -30 total_34S = MOL("[34S]-2") -40 total_S = MOL("S-2") -50 if (total_S <= 0) THEN GOTO 100 -60 ratio = total_34S/total_S -100 save ratio - -end -# -# HS- ratios -# -R(D)_HS- - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("*D{S,[34S]}*","D") - sum_species("*D{S,[34S]}O4*","D") -40 total_H = sum_species("*H{S,[34S]}*","H") - sum_species("*H{S,[34S]}O4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_HS- - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("*T{S,[34S]}*","T") - sum_species("*T{S,[34S]}O4*","T") -40 total_H = sum_species("*H{S,[34S]}*","H") - sum_species("*H{S,[34S]}O4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(34S)_HS- - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 100 -30 total_34S = sum_species("*{H,D,T}[34S]*","[34S]") - sum_species("*{H,D,T}[34S]O4*","[34S]") -40 total_S = sum_species("*{H,D,T}S*","S") - sum_species("*{H,D,T}SO4*","S") -50 if (total_S <= 0) THEN GOTO 100 -60 ratio = total_34S/total_S -100 save ratio - -end -# -# H2S ratios -# -R(D)_H2S(aq) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("*{H,D,T}2{S,[34S]}*","D") - sum_species("*{H,D,T}2{S,[34S]}O4*","D") -40 total_S = sum_species("*{H,D,T}2{S,[34S]}*","H") - sum_species("*{H,D,T}2{S,[34]}SO4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_H2S(aq) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{H,D,T}2{S,[34S]}","T") -40 total_H = sum_species("{H,D,T}2{S,[34S]}","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(34S)_H2S(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 100 -30 total_34S = sum_species("{H,D,T}2[34S]","[34S]") -40 total_S = sum_species("{H,D,T}2S","S") -50 if (total_S <= 0) THEN GOTO 100 -60 ratio = total_34S/total_S -100 save ratio - -end -# -# NO3- ratios -# -R(15N)_NO3- - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = TOT("[15N](5)") -40 total_N = TOT("N(5)") -50 if (total_N <= 0) THEN GOTO 100 -60 ratio = total_15N/total_N -100 save ratio - -end -# -# NO2- ratios -# -R(15N)_NO2- - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = TOT("[15N](3)") -40 total_N = TOT("N(3)") -50 if (total_N <= 0) THEN GOTO 100 -60 ratio = total_15N/total_N -100 save ratio - -end -# -# N2(aq) ratios -# -R(15N)_N2(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = TOT("[15N](0)") -40 total_N = TOT("N(0)") -50 if (total_N <= 0) THEN GOTO 100 -60 ratio = total_15N/total_N -100 save ratio - -end -# -# NH3(aq) ratios -# -R(D)_NH3(aq) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("{[15N],N}{H,D,T}3","D") -40 total_H = sum_species("{[15N],N}{H,D,T}3","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_NH3(aq) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("{[15N],N}{H,D,T}3","T") -40 total_H = sum_species("{[15N],N}{H,D,T}3","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(15N)_NH3(aq) - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = sum_species("[15N]{H,D,T}3","[15N]") -40 total_N = sum_species("N{H,D,T}3","N") -50 if (total_N <= 0) THEN GOTO 100 -60 ratio = total_15N/total_N -100 save ratio - -end -# -# NH4+ ratios -# -R(D)_NH4+ - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 100 -30 total_D = sum_species("*{[15N],N}{H,D,T}4*","D") -40 total_H = sum_species("*{[15N],N}{H,D,T}4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_D/total_H -100 save ratio - -end - -R(T)_NH4+ - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 100 -30 total_T = sum_species("*{[15N],N}{H,D,T}4*","T") -40 total_H = sum_species("*{[15N],N}{H,D,T}4*","H") -50 if (total_H <= 0) THEN GOTO 100 -60 ratio = total_T/total_H -100 save ratio - -end - -R(15N)_NH4+ - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 100 -30 total_15N = sum_species("*[15N]{H,D,T}4*","[15N]") -40 total_N = sum_species("*N{H,D,T}4*","N") -50 if (total_N <= 0) THEN GOTO 100 -60 ratio = total_15N/total_N -100 save ratio - -end -# -# Ratios for minerals and gases -# -# -# H2O(g) ratios -# -R(D)_H2O(g) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 total_D = SUM_GAS("{H,D,T}2{O,[18O]}", "D") -50 total_H = SUM_GAS("{H,D,T}2{O,[18O]}", "H") -60 if (total_h <= 0) THEN GOTO 1000 -70 ratio = total_D/total_H -1000 save ratio - -end - -R(T)_H2O(g) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 total_T = SUM_GAS("{H,D,T}2{O,[18O]}", "T") -50 total_H = SUM_GAS("{H,D,T}2{O,[18O]}", "H") -60 if (total_h <= 0) THEN GOTO 1000 -70 ratio = total_T/total_H -1000 save ratio - -end - -R(18O)_H2O(g) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 total_18O = SUM_GAS("{H,D,T}2[18O]", "[18O]") -50 total_O = SUM_GAS("{H,D,T}2O", "O") -60 if (total_O <= 0) THEN GOTO 1000 -70 ratio = total_18O/total_O -1000 save ratio - -end -# -# O2(g) ratios -# -R(18O)_O2(g) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 -40 total_18O = SUM_GAS("{O,[18O]}2", "[18O]") -50 total_O = SUM_GAS("{O,[18O]}2", "O") -60 if (total_O <= 0) THEN GOTO 1000 -70 ratio = total_18O/total_O -1000 save ratio - -end -# -# H2(g) ratios -# -R(D)_H2(g) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 total_D = SUM_GAS("{H,D,T}2", "D") -50 total_H = SUM_GAS("{H,D,T}2", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_D/total_H -1000 save ratio - -end - -R(T)_H2(g) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 total_T = SUM_GAS("{H,D,T}2", "T") -50 total_H = SUM_GAS("{H,D,T}2", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_T/total_H -1000 save ratio - -end -# -# CO2(g) ratios -# -R(18O)_CO2(g) - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 total_18O = SUM_GAS("{C,[13C],[14C]}{O,[18O]}2", "[18O]") -50 total_O = SUM_GAS("{C,[13C],[14C]}{O,[18O]}2", "O") -60 if (total_O <= 0) THEN GOTO 1000 -70 ratio = total_18O/total_O -1000 save ratio - -end - -R(13C)_CO2(g) - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[13C]O2(g)") <= 0) THEN GOTO 1000 -50 total_13C = SUM_GAS("[13C]{O,[18O]}2", "[13C]") -60 total_C = SUM_GAS("C{O,[18O]}2", "C") -70 if (total_C <= 0) THEN GOTO 1000 -80 ratio = total_13C/total_C -1000 save ratio - -end - -R(14C)_CO2(g) - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[14C]O2(g)") <= 0) THEN GOTO 1000 -50 total_14C = SUM_GAS("[14C]{O,[18O]}2", "[14C]") -60 total_C = SUM_GAS("C{O,[18O]}2", "C") -70 if (total_C <= 0) THEN GOTO 1000 -80 ratio = total_14C/total_C -1000 save ratio - -end -# -# Calcite ratios -# -R(18O)_Calcite - -start -10 ratio = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 total_18O = SUM_S_S("Calcite", "[18O]") -50 total_O = SUM_S_S("Calcite", "O") -60 if (total_O <= 0) THEN GOTO 1000 -70 ratio = total_18O/total_O -1000 save ratio - -end - -R(13C)_Calcite - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 total_13C = SUM_S_S("Calcite", "[13C]") -50 total_C = SUM_S_S("Calcite", "C") -60 if (total_C <= 0) THEN GOTO 1000 -70 ratio = total_13C/total_C -1000 save ratio - -end - -R(14C)_Calcite - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 total_14C = SUM_S_S("Calcite", "[14C]") -50 total_C = SUM_S_S("Calcite", "C") -60 if (total_C <= 0) THEN GOTO 1000 -70 ratio = total_14C/total_C -1000 save ratio - -end -# -# Pyrite ratios -# -R(34S)_Pyrite - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (S_S("Pyrite") <= 0) THEN GOTO 1000 -40 total_34S = SUM_S_S("Pyrite", "[34S]") -50 total_S = SUM_S_S("Pyrite", "S") -60 if (total_S <= 0) THEN GOTO 1000 -70 ratio = total_34S/total_S -1000 save ratio - -end -# -# CH4(g) ratios -# -R(D)_CH4(g) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 total_D = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "D") -50 total_H = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_D/total_H -1000 save ratio - -end - -R(T)_CH4(g) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 total_T = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "T") -50 total_H = SUM_GAS("{C,[13C],[14C]}{H,D,T}4", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_T/total_H -1000 save ratio - -end - -R(13C)_CH4(g) - -start -10 ratio = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 total_13C = SUM_GAS("[13C]{H,D,T}4", "[13C]") -50 total_C = SUM_GAS("C{H,D,T}4", "C") -60 if (total_C <= 0) THEN GOTO 1000 -70 ratio = total_13C/total_C -1000 save ratio - -end - -R(14C)_CH4(g) - -start -10 ratio = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 total_14C = SUM_GAS("[14C]{H,D,T}4", "[14C]") -50 total_C = SUM_GAS("C{H,D,T}4", "C") -60 if (total_C <= 0) THEN GOTO 1000 -70 ratio = total_14C/total_C -1000 save ratio - -end -# -# H2S(g) ratios -# -R(D)_H2S(g) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 -40 total_D = SUM_GAS("{H,D,T}2{S,[34S]}", "D") -50 total_H = SUM_GAS("{H,D,T}2{S,[34S]}", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_D/total_H -1000 save ratio - -end - -R(T)_H2S(g) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 -40 total_T = SUM_GAS("{H,D,T}2{S,[34S]}", "T") -50 total_H = SUM_GAS("{H,D,T}2{S,[34S]}", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_T/total_H -1000 save ratio - -end - -R(34S)_H2S(g) - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (GAS("H2S(g)") <= 0) THEN GOTO 1000 -40 total_34S = SUM_GAS("{H,D,T}2[34S]", "[34S]") -50 total_S = SUM_GAS("{H,D,T}2S", "S") -60 if (total_S <= 0) THEN GOTO 1000 -70 ratio = total_34S/total_S -1000 save ratio - -end -# -# Gypsum ratios -# -R(34S)_Gypsum - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (S_S("Gypsum") <= 0) THEN GOTO 1000 -40 total_34S = SUM_S_S("Gypsum", "[34S]") -50 total_S = SUM_S_S("Gypsum", "S") -60 if (total_S <= 0) THEN GOTO 1000 -70 ratio = total_34S/total_S -1000 save ratio - -end -# -# Anhydrite ratios -# -R(34S)_Anhydrite - -start -10 ratio = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (S_S("Anhydrite") <= 0) THEN GOTO 1000 -40 total_34S = SUM_S_S("Anhydrite", "[34S]") -50 total_S = SUM_S_S("Anhydrite", "S") -60 if (total_S <= 0) THEN GOTO 1000 -70 ratio = total_34S/total_S -1000 save ratio - -end -# -# N2(g) ratios -# -R(15N)_N2(g) - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (GAS("N2(g)") <= 0) THEN GOTO 1000 -40 total_15N = SUM_GAS("{[15N],N}2", "[15N]") -50 total_N = SUM_GAS("{[15N],N}2", "N") -60 if (total_N <= 0) THEN GOTO 1000 -70 ratio = total_15N/total_N -1000 save ratio - -end -# -# NH3(g) ratios -# -R(D)_NH3(g) - -start -10 ratio = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -40 total_D = SUM_GAS("{[15N],N}{H,D,T}3", "D") -50 total_H = SUM_GAS("{[15N],N}{H,D,T}3", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_D/total_H -1000 save ratio - -end - -R(T)_NH3(g) - -start -10 ratio = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -40 total_T = SUM_GAS("{[15N],N}{H,D,T}3", "T") -50 total_H = SUM_GAS("{[15N],N}{H,D,T}3", "H") -60 if (total_H <= 0) THEN GOTO 1000 -70 ratio = total_T/total_H -1000 save ratio - -end - -R(15N)_NH3(g) - -start -10 ratio = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -40 total_15N = SUM_GAS("[15N]{H,D,T}3", "[15N]") -50 total_N = SUM_GAS("N{H,D,T}3", "N") -60 if (total_N <= 0) THEN GOTO 1000 -70 ratio = total_15N/total_N -1000 save ratio - -end -############################################################################################### -CALCULATE_VALUES -############################################################################################### -# -# Alphas -# -# -# H2O(l) ratios -# -# -# OH- ratios -# -Alpha_D_OH-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(D)_OH-") -40 r2 = CALC_VALUE("R(D)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_OH-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(T)_OH-") -40 r2 = CALC_VALUE("R(T)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_OH-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(18O)_OH-") -40 r2 = CALC_VALUE("R(18O)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# H3O+ ratios -# -Alpha_D_H3O+/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(D)_H3O+") -40 r2 = CALC_VALUE("R(D)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H3O+/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(T)_H3O+") -40 r2 = CALC_VALUE("R(T)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_H3O+/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 r1 = CALC_VALUE("R(18O)_H3O+") -40 r2 = CALC_VALUE("R(18O)_H2O(l)") -50 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# O2(aq) ratios -# -Alpha_18O_O2(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(18O)_O2(aq)") -60 r2 = CALC_VALUE("R(18O)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# H2(aq) ratios -# -Alpha_D_H2(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2(aq)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2(aq)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# CO2(aq) ratios -# -Alpha_18O_CO2(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_CO2(aq)") -50 r2 = CALC_VALUE("R(18O)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CO2(aq)/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_CO2(aq)") -50 r2 = CALC_VALUE("R(13C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CO2(aq)/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_CO2(aq)") -50 r2 = CALC_VALUE("R(14C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# HCO3- ratios -# -Alpha_D_HCO3-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(D)_HCO3-") -50 r2 = CALC_VALUE("R(D)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_HCO3-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(T)_HCO3-") -50 r2 = CALC_VALUE("R(T)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_HCO3-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_HCO3-") -50 r2 = CALC_VALUE("R(18O)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_HCO3-/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_HCO3-") -50 r2 = CALC_VALUE("R(18O)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_HCO3-/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_HCO3-") -50 r2 = CALC_VALUE("R(13C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_HCO3-/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_HCO3-") -50 r2 = CALC_VALUE("R(13C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_HCO3-/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_HCO3-") -50 r2 = CALC_VALUE("R(14C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_HCO3-/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_HCO3-") -50 r2 = CALC_VALUE("R(14C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# CO3-2 ratios -# -Alpha_18O_CO3-2/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_CO3-2") -50 r2 = CALC_VALUE("R(18O)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_CO3-2/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_CO3-2") -50 r2 = CALC_VALUE("R(18O)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CO3-2/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_CO3-2") -50 r2 = CALC_VALUE("R(13C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CO3-2/CO2(aq) #? - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_CO3-2") -50 r2 = CALC_VALUE("R(13C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CO3-2/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_CO3-2") -50 r2 = CALC_VALUE("R(14C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CO3-2/CO2(aq) #? - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_CO3-2") -50 r2 = CALC_VALUE("R(14C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# CH4(aq) ratios -# -Alpha_D_CH4(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_CH4(aq)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_CH4(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_CH4(aq)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CH4(aq)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(13C)_CH4(aq)") -60 r2 = CALC_VALUE("R(13C)_CO2(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CH4(aq)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (TOT("C") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(14C)_CH4(aq)") -60 r2 = CALC_VALUE("R(14C)_CO2(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# HSO4-2 ratios -# -Alpha_D_HSO4-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_HSO4-") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_HSO4-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_HSO4-") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_34S_HSO4-/SO4-2 - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_HSO4-") -60 r2 = CALC_VALUE("R(34S)_SO4-2") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# S-2 ratios -# -Alpha_34S_S-2/HS- - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_S-2") -60 r2 = CALC_VALUE("R(34S)_HS-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -# -# HS- ratios -# -Alpha_D_HS-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_HS-") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_HS-/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_HS-") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_34S_HS-/SO4-2 - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -40 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_HS-") -60 r2 = CALC_VALUE("R(34S)_SO4-2") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# H2S ratios -# -Alpha_D_H2S(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2S(aq)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_D_H2S(aq)/HS- - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2S(aq)") -60 r2 = CALC_VALUE("R(D)_HS-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2S(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2S(aq)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2S(aq)/HS- - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2S(aq)") -60 r2 = CALC_VALUE("R(T)_HS-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_34S_H2S(aq)/HS- - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_H2S(aq)") -60 r2 = CALC_VALUE("R(34S)_HS-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# NO3- ratios -# -Alpha_15N_NO2-/NO3- - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(5)") <= 0) THEN GOTO 1000 -40 if (TOT("N(3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_NO2-") -60 r2 = CALC_VALUE("R(15N)_NO3-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# N2(aq) ratios -# -Alpha_15N_N2(aq)/NO3- - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(5)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_N2(aq)") -60 r2 = CALC_VALUE("R(15N)_NO3-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# NH3(aq) ratios -# -Alpha_D_NH3(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_NH3(aq)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_NH3(aq)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_NH3(aq)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_15N_NH3(aq)/NO3- - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_NH3(aq)") -60 r2 = CALC_VALUE("R(15)_NO3-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# NH4+ ratios -# -Alpha_D_NH4+/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_NH4+") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_NH4+/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_NH4+") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_15N_NH4+/NO3- - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(5)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_NH4+") -60 r2 = CALC_VALUE("R(15N)_NO3-") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_15N_NH4+/NH3(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(5)") <= 0) THEN GOTO 1000 -40 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_NH4+") -60 r2 = CALC_VALUE("R(15N)_NH3(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# Ratios for minerals and gases -# -# -# H2O(g) ratios -# -Alpha_D_H2O(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(D)_H2O(g)") -50 r2 = CALC_VALUE("R(D)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2O(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(T)_H2O(g)") -50 r2 = CALC_VALUE("R(T)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_H2O(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("H2O(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_H2O(g)") -50 r2 = CALC_VALUE("R(18O)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# O2(g) ratios -# -Alpha_18O_O2(aq)/O2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("O[18O](g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(18O)_O2(aq)") -60 r2 = CALC_VALUE("R(18O)_O2(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_O2(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("O2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("O[18O](g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(18O)_O2(g)") -60 r2 = CALC_VALUE("R(18O)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -# -# H2(g) ratios -# -Alpha_D_H2(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("HD(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2(g)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("HT(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2(g)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_D_H2(aq)/H2(g) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("HD(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2(aq)") -60 r2 = CALC_VALUE("R(D)_H2(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2(aq)/H2(g) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("H2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("HT(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2(aq)") -60 r2 = CALC_VALUE("R(T)_H2(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# CO2(g) ratios -# -Alpha_18O_CO2(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CO[18O](g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(18O)_CO2(g)") -60 r2 = CALC_VALUE("R(18O)_H2O(l)") -70 if (r1 <= 0) THEN GOTO 1000 -80 if (r2 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_CO2(g)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CO[18O](g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(18O)_CO2(g)") -60 r2 = CALC_VALUE("R(18O)_CO2(aq)") -70 if (r1 <= 0) THEN GOTO 1000 -80 if (r2 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CO2(g)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[13C]O2(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(13C)_CO2(g)") -60 r2 = CALC_VALUE("R(13C)_CO2(aq)") -70 if (r1 <= 0) THEN GOTO 1000 -80 if (r2 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CO2(g)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[134]O2(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(14C)_CO2(g)") -60 r2 = CALC_VALUE("R(14C)_CO2(aq)") -70 if (r1 <= 0) THEN GOTO 1000 -80 if (r2 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# Calcite ratios -# -Alpha_18O_Calcite/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_Calcite") -50 r2 = CALC_VALUE("R(18O)_H2O(l)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_18O_Calcite/CO3-2 - -start -10 alpha = -9999.999 -20 if (TOT("[18O]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(18O)_Calcite") -50 r2 = CALC_VALUE("R(18O)_CO3-2") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_Calcite/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -35 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_Calcite") -50 r2 = CALC_VALUE("R(13C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_Calcite/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_Calcite") -50 r2 = CALC_VALUE("R(13C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_Calcite/CO3-2 - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(13C)_Calcite") -50 r2 = CALC_VALUE("R(13C)_CO3-2") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_Calcite/CO2(g) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -35 if (GAS("CO2(g)") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_Calcite") -50 r2 = CALC_VALUE("R(14C)_CO2(g)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_Calcite/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_Calcite") -50 r2 = CALC_VALUE("R(14C)_CO2(aq)") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_Calcite/CO3-2 - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (S_S("Calcite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(14C)_Calcite") -50 r2 = CALC_VALUE("R(14C)_CO3-2") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# Pyrite ratios -# -Alpha_34S_Pyrite/HS- - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (S_S("Pyrite") <= 0) THEN GOTO 1000 -40 r1 = CALC_VALUE("R(34S)_Pyrite") -50 r2 = CALC_VALUE("R(34S)_HS-") -60 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# CH4(g) ratios -# -Alpha_D_CH4(aq)/CH4(g) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CH3D(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_CH4(aq)") -60 r2 = CALC_VALUE("R(D)_CH4(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_D_CH4(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CH3D(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_CH4(g)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_CH4(aq)/CH4(g) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CH3T(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_CH4(aq)") -60 r2 = CALC_VALUE("R(T)_CH4(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_CH4(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("CH3T(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_CH4(g)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CH4(g)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[13C]H4(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(13C)_CH4(g)") -60 r2 = CALC_VALUE("R(13C)_CO2(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_13C_CH4(aq)/CH4(g) - -start -10 alpha = -9999.999 -20 if (TOT("[13C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[13C]H4(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(13C)_CH4(aq)") -60 r2 = CALC_VALUE("R(13C)_CH4(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CH4(g)/CO2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[14C]H4(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(14C)_CH4(g)") -60 r2 = CALC_VALUE("R(14C)_CO2(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_14C_CH4(aq)/CH4(g) - -start -10 alpha = -9999.999 -20 if (TOT("[14C]") <= 0) THEN GOTO 1000 -30 if (GAS("CH4(g)") <= 0) THEN GOTO 1000 -40 if (GAS("[14C]H4(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(14C)_CH4(aq)") -60 r2 = CALC_VALUE("R(14C)_CH4(g)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# H2S(g) ratios -# -Alpha_D_H2S(g)/H2S(aq) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_H2S(g)") -60 r2 = CALC_VALUE("R(D)_H2S(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_H2S(g)/H2S(aq) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("S(-2)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_H2S(g)") -60 r2 = CALC_VALUE("R(T)_H2S(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_34S_H2S(g)/H2S(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_H2S(g)") -60 r2 = CALC_VALUE("R(34S)_H2S(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# Gypsum ratios -# -Alpha_34S_Gypsum/SO4-2 - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -40 if (S_S("Gypsum") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_Gypsum") -60 r2 = CALC_VALUE("R(34S)_SO4-2") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# Anhydrite ratios -# -Alpha_34S_Anhydrite/SO4-2 - -start -10 alpha = -9999.999 -20 if (TOT("[34S]") <= 0) THEN GOTO 1000 -30 if (TOT("S(6)") <= 0) THEN GOTO 1000 -40 if (S_S("Anhydrite") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(34S)_Anhydrite") -60 r2 = CALC_VALUE("R(34S)_SO4-2") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# N2(g) ratios -# -Alpha_15N_N2(g)/N2(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(0)") <= 0) THEN GOTO 1000 -40 if (GAS("N2(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_N2(g)") -60 r2 = CALC_VALUE("R(15N)_N2(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -# -# NH3(g) ratios -# -Alpha_D_NH3(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("D") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(D)_NH3(g)") -60 r2 = CALC_VALUE("R(D)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_T_NH3(g)/H2O(l) - -start -10 alpha = -9999.999 -20 if (TOT("T") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(T)_NH3(g)") -60 r2 = CALC_VALUE("R(T)_H2O(l)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end - -Alpha_15N_NH3(g)/NH3(aq) - -start -10 alpha = -9999.999 -20 if (TOT("[15N]") <= 0) THEN GOTO 1000 -30 if (TOT("N(-3)") <= 0) THEN GOTO 1000 -40 if (GAS("NH3(g)") <= 0) THEN GOTO 1000 -50 r1 = CALC_VALUE("R(15N)_NH3(g)") -60 r2 = CALC_VALUE("R(15N)_NH3(aq)") -70 if (r2 <= 0) THEN GOTO 1000 -80 if (r1 <= -9999) THEN GOTO 1000 -90 alpha = r1/r2 -1000 save alpha - -end -############################################################################################### -SOLUTION_SPECIES -############################################################################################### -D2O = D2O - -activity_water - log_k 0 - -HTO = HTO - -activity_water - log_k 0 - -H2[18O] = H2[18O] - -activity_water - log_k 0 - -CO2 = CO2 - log_k 0 - -[13C]O2 = [13C]O2 - log_k 0 - -[14C]O2 = [14C]O2 - log_k 0 - -[34S]O4-2 = [34S]O4-2 - log_k 0.0 - -gamma 5.0000 -0.0400 - -[15N]O3- = [15N]O3- - log_k 0.0 - -gamma 3.0000 0.0000 - -# -# H2O reactions -# last update July 31, 2006 -# checked September 19, 2006 -# -0.5H2O + 0.5D2O = HDO - log_k 0.301029995663 # log10(2) - -activity_water - -HDO + HTO = DTO + H2O - -mole_balance DTO - log_k -0.301029995663 # log10(1/2) - -activity_water - -2HTO = T2O + H2O - -mole_balance T2O - log_k -0.6020599913279623960 # log10(1/4) - -activity_water - -H2[18O] + HDO = HD[18O] + H2O - -mole_balance HD[18O] - log_k 0.0 - -activity_water - -H2[18O] + HTO = HT[18O] + H2O - -mole_balance HT[18O] - log_k 0.0 - -activity_water - -DTO + H2[18O] = DT[18O] + H2O - -mole_balance DT[18O] - log_k 0.0 - -activity_water - -D2O + H2[18O] = D2[18O] + H2O - -mole_balance D2[18O] - log_k 0.0 - -activity_water - -H2[18O] + T2O = T2[18O] + H2O - -mole_balance T2[18O] - log_k 0.0 - -activity_water -# -# OH- reactions -# last update July 31, 2006 -# checked September 19, 2006 -# -OH- + HDO = OD- + H2O - -mole_balance OD - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_D_OH-/H2O(l) 1.0 - -gamma 3.5000 0.0000 - -OH- + HTO = OT- + H2O - -mole_balance OT - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_T_OH-/H2O(l) 1.0 - -gamma 3.5000 0.0000 - -OH- + H2[18O] = [18O]H- + H2O - -mole_balance [18O]H - -add_logk Log_alpha_18O_OH-/H2O(l) 1.0 - -gamma 3.5000 0.0000 - -[18O]H- + OD- = [18O]D- + OH- - -mole_balance [18O]D - log_k 0.0 - -gamma 3.5000 0.0000 - -[18O]H- + OT- = [18O]T- + OH- - -mole_balance [18O]T - log_k 0.0 - -gamma 3.5000 0.0000 -# -# H3O+ reactions -# last update July 31, 2006 -# checked September 19, 2006 -# -H3O+ + HDO = H2DO+ + H2O - -mole_balance H2DO - log_k 0.176091259055 # log10(1.5) - -add_logk Log_alpha_D_H3O+/H2O(l) 1.0 - -gamma 9.0000 0.0000 - -2H2DO+ = HD2O+ + H3O+ - -mole_balance HD2O - log_k -0.477121254719662 # log10(1/3) - -gamma 9.0000 0.0000 - -H2DO+ + HD2O+ = D3O+ + H3O+ - -mole_balance D3O - log_k -0.954242509439324 # log10(1/9) - -gamma 9.0000 0.0000 - -H3O+ + HTO = H2TO+ + H2O - -mole_balance H2TO - log_k 0.176091259055 # log10(1.5) - -add_logk Log_alpha_T_H3O+/H2O(l) 1.0 - -gamma 9.0000 0.0000 - -2H2TO+ = HT2O+ + H3O+ - -mole_balance HT2O - log_k -0.477121254719662 # log10(1/3) - -gamma 9.0000 0.0000 - -H2TO+ + HT2O+ = T3O+ + H3O+ - -mole_balance T3O - log_k -0.954242509439324 # log10(1/9) - -gamma 9.0000 0.0000 - -H2TO+ + H2DO+ = HDTO+ + H3O+ - -mole_balance HDTO - log_k -0.477121254719662 # log10(1/3) - -gamma 9.0000 0.0000 - -H2TO+ + HD2O+ = D2TO+ + H3O+ - -mole_balance D2TO - log_k -0.477121254719662 # log10(1/3) - -gamma 9.0000 0.0000 - -H2DO+ + HT2O+ = DT2O+ + H3O+ - -mole_balance DT2O - log_k -0.477121254719662 # log10(1/3) - -gamma 9.0000 0.0000 - -H3O+ + H2[18O] = H3[18O]+ + H2O - -mole_balance H3[18O] - -add_logk Log_alpha_18O_H3O+/H2O(l) 1.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + H2DO+ = H2D[18O]+ + H3O+ - -mole_balance H2D[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + HD2O+ = HD2[18O]+ + H3O+ - -mole_balance HD2[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + D3O+ = D3[18O]+ + H3O+ - -mole_balance D3[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + H2TO+ = H2T[18O]+ + H3O+ - -mole_balance H2T[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + HT2O+ = HT2[18O]+ + H3O+ - -mole_balance HT2[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + T3O+ = T3[18O]+ + H3O+ - -mole_balance T3[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + HDTO+ = HDT[18O]+ + H3O+ - -mole_balance HDT[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + D2TO+ = D2T[18O]+ + H3O+ - -mole_balance D2T[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -H3[18O]+ + DT2O+ = DT2[18O]+ + H3O+ - -mole_balance DT2[18O] - log_k 0.0 - -gamma 9.0000 0.0000 - -# -# O2 reactions -# last update July 31, 2006 -# checked September 19, 2006 -# - -O2 + H2[18O] = O[18O] + H2O - log_k 0.301029995663 # log10(2) - -add_logk Log_alpha_18O_O2(aq)/H2O(l) 1.0 - -mole_balance O(0)[18O](0) - -2O[18O] = [18O]2 + O2 - log_k -0.602059991327962396 # -log10(4) - -mole_balance [18O](0)2 -# -# H2 reactions -# last update July 31, 2006 -# checked September 19, 2006 -# -H2 + HDO = HD + H2O - -mole_balance H(0)D(0) - -add_logk Log_alpha_D_H2(aq)/H2O(l) 1.0 - -2HD = D2 + H2 - -mole_balance D(0)2 - log_k -0.602059991327962396 # -log10(4) - -H2 + HTO = HT + H2O - -mole_balance H(0)T(0) - -add_logk Log_alpha_T_H2(aq)/H2O(l) 1.0 - -2HT = T2 + H2 - -mole_balance T(0)2 - log_k -0.602059991327962396 # -log10(4) - -HT + HD = DT + H2 - -mole_balance D(0)T(0) - log_k -0.301029995663 # -log10(2) -# -# CO2 reactions -# last update July 31, 2006 -# Checked September 19, 2006 -# -CO2 + H2[18O] = CO[18O] + H2O - log_k 0.301029995663 # log10(2) - -add_logk Log_alpha_18O_CO2(aq)/H2O(l) 1.0 - -2CO[18O] = C[18O]2 + CO2 - log_k -0.6020599913279623960 # log10(1/4) - -[13C]O2 + CO[18O] = [13C]O[18O] + CO2 - log_k 0 - -[13C]O2 + C[18O]2 = [13C][18O]2 + CO2 - log_k 0 - -[14C]O2 + CO[18O] = [14C]O[18O] + CO2 - log_k 0 - -[14C]O2 + C[18O]2 = [14C][18O]2 + CO2 - log_k 0 -# -# HCO3- reactions -# last update July 31, 2006 -# Checked September 19, 2006 -# -HCO3- + H2[18O] = HCO2[18O]- + H2O - -add_logk Log_alpha_18O_HCO3-/H2O(l) 1.0 - -HCO2[18O]- = HCO[18O]O- -HCO2[18O]- = HC[18O]O2- -2HCO2[18O]- = HCO[18O]2- + HCO3- -HCO[18O]2- = HC[18O]O[18O]- -HCO[18O]2- = HC[18O]2O- -3HCO2[18O]- = HC[18O]3- + 2HCO3- - -HDO + HCO3- = DCO3- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_D_HCO3-/H2O(l) 1.0 - -DCO3- + HCO2[18O]- = DCO2[18O]- + HCO3- -DCO3- + HCO[18O]O- = DCO[18O]O- + HCO3- -DCO3- + HC[18O]O2- = DC[18O]O2- + HCO3- -DCO3- + HCO[18O]2- = DCO[18O]2- + HCO3- -DCO3- + HC[18O]O[18O]- = DC[18O]O[18O]- + HCO3- -DCO3- + HC[18O]2O- = DC[18O]2O- + HCO3- -DCO3- + HC[18O]3- = DC[18O]3- + HCO3- - -HTO + HCO3- = TCO3- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_T_HCO3-/H2O(l) 1.0 - -TCO3- + HCO2[18O]- = TCO2[18O]- + HCO3- -TCO3- + HCO[18O]O- = TCO[18O]O- + HCO3- -TCO3- + HC[18O]O2- = TC[18O]O2- + HCO3- -TCO3- + HCO[18O]2- = TCO[18O]2- + HCO3- -TCO3- + HC[18O]O[18O]- = TC[18O]O[18O]- + HCO3- -TCO3- + HC[18O]2O- = TC[18O]2O- + HCO3- -TCO3- + HC[18O]3- = TC[18O]3- + HCO3- - -HCO3- + [13C]O2 = H[13C]O3- + CO2 - -add_logk Log_alpha_13C_HCO3-/CO2(aq) 1.0 - -H[13C]O3- + HCO2[18O]- = H[13C]O2[18O]- + HCO3- -H[13C]O3- + HCO[18O]O- = H[13C]O[18O]O- + HCO3- -H[13C]O3- + HC[18O]O2- = H[13C][18O]O2- + HCO3- -H[13C]O3- + HCO[18O]2- = H[13C]O[18O]2- + HCO3- -H[13C]O3- + HC[18O]O[18O]- = H[13C][18O]O[18O]- + HCO3- -H[13C]O3- + HC[18O]2O- = H[13C][18O]2O- + HCO3- -H[13C]O3- + HC[18O]3- = H[13C][18O]3- + HCO3- -DCO3- + H[13C]O3- = D[13C]O3- + HCO3- -H[13C]O3- + DCO2[18O]- = D[13C]O2[18O]- + HCO3- -H[13C]O3- + DCO[18O]O- = D[13C]O[18O]O- + HCO3- -H[13C]O3- + DC[18O]O2- = D[13C][18O]O2- + HCO3- -H[13C]O3- + DCO[18O]2- = D[13C]O[18O]2- + HCO3- -H[13C]O3- + DC[18O]O[18O]- = D[13C][18O]O[18O]- + HCO3- -H[13C]O3- + DC[18O]2O- = D[13C][18O]2O- + HCO3- -H[13C]O3- + DC[18O]3- = D[13C][18O]3- + HCO3- -TCO3- + H[13C]O3- = T[13C]O3- + HCO3- -H[13C]O3- + TCO2[18O]- = T[13C]O2[18O]- + HCO3- -H[13C]O3- + TCO[18O]O- = T[13C]O[18O]O- + HCO3- -H[13C]O3- + TC[18O]O2- = T[13C][18O]O2- + HCO3- -H[13C]O3- + TCO[18O]2- = T[13C]O[18O]2- + HCO3- -H[13C]O3- + TC[18O]O[18O]- = T[13C][18O]O[18O]- + HCO3- -H[13C]O3- + TC[18O]2O- = T[13C][18O]2O- + HCO3- -H[13C]O3- + TC[18O]3- = T[13C][18O]3- + HCO3- - -HCO3- + [14C]O2 = H[14C]O3- + CO2 - -add_logk Log_alpha_14C_HCO3-/CO2(aq) 1.0 - -H[14C]O3- + HCO2[18O]- = H[14C]O2[18O]- + HCO3- -H[14C]O3- + HCO[18O]O- = H[14C]O[18O]O- + HCO3- -H[14C]O3- + HC[18O]O2- = H[14C][18O]O2- + HCO3- -H[14C]O3- + HCO[18O]2- = H[14C]O[18O]2- + HCO3- -H[14C]O3- + HC[18O]O[18O]- = H[14C][18O]O[18O]- + HCO3- -H[14C]O3- + HC[18O]2O- = H[14C][18O]2O- + HCO3- -H[14C]O3- + HC[18O]3- = H[14C][18O]3- + HCO3- -DCO3- + H[14C]O3- = D[14C]O3- + HCO3- -H[14C]O3- + DCO2[18O]- = D[14C]O2[18O]- + HCO3- -H[14C]O3- + DCO[18O]O- = D[14C]O[18O]O- + HCO3- -H[14C]O3- + DC[18O]O2- = D[14C][18O]O2- + HCO3- -H[14C]O3- + DCO[18O]2- = D[14C]O[18O]2- + HCO3- -H[14C]O3- + DC[18O]O[18O]- = D[14C][18O]O[18O]- + HCO3- -H[14C]O3- + DC[18O]2O- = D[14C][18O]2O- + HCO3- -H[14C]O3- + DC[18O]3- = D[14C][18O]3- + HCO3- -TCO3- + H[14C]O3- = T[14C]O3- + HCO3- -H[14C]O3- + TCO2[18O]- = T[14C]O2[18O]- + HCO3- -H[14C]O3- + TCO[18O]O- = T[14C]O[18O]O- + HCO3- -H[14C]O3- + TC[18O]O2- = T[14C][18O]O2- + HCO3- -H[14C]O3- + TCO[18O]2- = T[14C]O[18O]2- + HCO3- -H[14C]O3- + TC[18O]O[18O]- = T[14C][18O]O[18O]- + HCO3- -H[14C]O3- + TC[18O]2O- = T[14C][18O]2O- + HCO3- -H[14C]O3- + TC[18O]3- = T[14C][18O]3- + HCO3- -# -# CO3-2 reactions -# last update July 31, 2006 -# Checked September 19, 2006 -# -CO3-2 + H2[18O] = CO2[18O]-2 + H2O - log_k 0.477121254719 # log10(3) - -add_logk Log_alpha_18O_CO3-2/H2O(l) 1.0 - -2CO2[18O]-2 = CO[18O]2-2 + CO3-2 - log_k -0.477121254719 # -log10(3) - -CO2[18O]-2 + CO[18O]2-2 = C[18O]3-2 + CO3-2 - log_k -0.954242509439324 # log10(1/9) - -CO3-2 + [13C]O2 = [13C]O3-2 + CO2 - -add_logk Log_alpha_13C_CO3-2/CO2(aq) 1.0 - -[13C]O3-2 + CO2[18O]-2 = [13C]O2[18O]-2 + CO3-2 - log_k 0.0 - -[13C]O3-2 + CO[18O]2-2 = [13C]O[18O]2-2 + CO3-2 - log_k 0.0 - -[13C]O3-2 + C[18O]3-2 = [13C][18O]3-2 + CO3-2 - log_k 0.0 - -CO3-2 + [14C]O2 = [14C]O3-2 + CO2 - -add_logk Log_alpha_14C_CO3-2/CO2(aq) 1.0 - -[14C]O3-2 + CO2[18O]-2 = [14C]O2[18O]-2 + CO3-2 - log_k 0.0 - -[14C]O3-2 + CO[18O]2-2 = [14C]O[18O]2-2 + CO3-2 - log_k 0.0 - -[14C]O3-2 + C[18O]3-2 = [14C][18O]3-2 + CO3-2 - log_k 0.0 -# -# CH4 reactions -# Updated September 19, 2006 -# Checked September 19, 2006 -# -CH4 + HDO = CH3D + H2O - log_k 0.301029995663981198 # log10(2) - -add_logk Log_alpha_D_CH4(aq)/H2O(l) 1.0 - -2CH3D = CH2D2 + CH4 - log_k -0.42596873227228 # log10(3/8) - -3CH3D = CHD3 + 2CH4 - log_k -1.20411998265 # log10(1/16) - -4CH3D = CD4 + 3CH4 - log_k -2.408239965311 # log10(1/256) - -CH4 + HTO = CH3T + H2O - log_k 0.301029995663981198 # log10(2) - -add_logk Log_alpha_T_CH4(aq)/H2O(l) 1.0 - -2CH3T = CH2T2 + CH4 - log_k -0.42596873227228 # log10(3/8) - -3CH3T = CHT3 + 2CH4 - log_k -1.20411998265 # log10(1/16) - -4CH3T = CT4 + 3CH4 - log_k -2.408239965311 # log10(1/256) -# -# Added mixed DT C methane species May 19, 2006 -# -CH3T + CHD3 = CD3T + CH4 - log_k -0.602059991327962396 # -log10(4) - -CH2T2 + CH2D2 = CD2T2 + CH4 - log_k -0.7781512503836 # -log10(6) - -CHT3 + CH3D = CDT3 + CH4 - log_k -0.602059991327962396 # -log10(4) - -[13C]O2 + CH4 = [13C]H4 + CO2 - -add_logk Log_alpha_13C_CH4(aq)/CO2(aq) 1.0 - -[13C]H4 + CH3D = [13C]H3D + CH4 -[13C]H4 + CH2D2 = [13C]H2D2 + CH4 -[13C]H4 + CHD3 = [13C]HD3 + CH4 -[13C]H4 + CD4 = [13C]D4 + CH4 -[13C]H4 + CH3T = [13C]H3T + CH4 -[13C]H4 + CH2T2 = [13C]H2T2 + CH4 -[13C]H4 + CHT3 = [13C]HT3 + CH4 -[13C]H4 + CT4 = [13C]T4 + CH4 -[13C]H4 + CD3T = [13C]D3T + CH4 -[13C]H4 + CD2T2 = [13C]D2T2 + CH4 -[13C]H4 + CDT3 = [13C]DT3 + CH4 - -[14C]O2 + CH4 = [14C]H4 + CO2 - -add_logk Log_alpha_14C_CH4(aq)/CO2(aq) 1.0 -# -# Added mixed DT 14C methane species May 19, 2006 -# -[14C]H4 + CH3D = [14C]H3D + CH4 -[14C]H4 + CH2D2 = [14C]H2D2 + CH4 -[14C]H4 + CHD3 = [14C]HD3 + CH4 -[14C]H4 + CD4 = [14C]D4 + CH4 -[14C]H4 + CH3T = [14C]H3T + CH4 -[14C]H4 + CH2T2 = [14C]H2T2 + CH4 -[14C]H4 + CHT3 = [14C]HT3 + CH4 -[14C]H4 + CT4 = [14C]T4 + CH4 -[14C]H4 + CD3T = [14C]D3T + CH4 -[14C]H4 + CD2T2 = [14C]D2T2 + CH4 -[14C]H4 + CDT3 = [14C]DT3 + CH4 -# -# HSO4- reactions -# Updated September 28, 2006 -# Checked September 28, 2006 -# -HSO4- + HDO = DSO4- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_D_HSO4-/H2O(l) 1.0 - -mole_balance DS(6)O4- - -HSO4- + HTO = TSO4- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_T_HSO4-/H2O(l) 1.0 - -mole_balance TS(6)O4- - -[34S]O4-2 + HSO4- = H[34S]O4- + SO4-2 - -add_logk Log_alpha_34S_HSO4-/SO4-2 1.0 - -mole_balance H[34S](6)O4- - -H[34S]O4- + DSO4- = D[34S]O4- + HSO4- - -mole_balance D[34S](6)O4 - -H[34S]O4- + TSO4- = T[34S]O4- + HSO4- - -mole_balance T[34S](6)O4- -# -# S-2 reactions -# -S-2 + H[34S]- = [34S]-2 + HS- - -add_logk Log_alpha_34S_S-2/HS- 1.0 - -mole_balance [34S](-2) - -gamma 5.0000 0.0000 -# -# HS- reactions -# -HS- + HDO = DS- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_D_HS-/H2O(l) 1.0 - -mole_balance DS(-2) - -gamma 3.5000 0.0000 - -HS- + HTO = TS- + H2O - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_T_HS-/H2O(l) 1.0 - -mole_balance TS(-2) - -gamma 3.5000 0.0000 - -HS- + [34S]O4-2 = H[34S]- + SO4-2 - -add_logk Log_alpha_34S_HS-/SO4-2 1.0 - -mole_balance H[34S](-2) - -gamma 3.5000 0.0000 - -H[34S]- + DS- = D[34S]- + HS- - -gamma 3.5000 0.0000 - -mole_balance D[34S](-2) - -H[34S]- + TS- = T[34S]- + HS- - -gamma 3.5000 0.0000 - -mole_balance T[34S](-2) -# -# H2S reactions -# -H2S + HDO = HDS + H2O - -add_logk Log_alpha_D_H2S(aq)/H2O(l) 1.0 - -mole_balance HDS(-2) - -2HDS = D2S + H2S - log_k -0.602059991327962396 # -log10(4) - -mole_balance D2S(-2) - -H2S + HTO = HTS + H2O - -add_logk Log_alpha_T_H2S(aq)/H2O(l) 1.0 - -mole_balance HTS(-2) - -2HTS = T2S + H2S - log_k -0.602059991327962396 # -log10(4) - -mole_balance T2S(-2) - -HDS + HTS = DTS + H2S - log_k -0.301029995663 # log10(1/2) - -mole_balance DTS(-2) - -H[34S]- + H2S = H2[34S] + HS- - -add_logk Log_alpha_34S_H2S(aq)/HS- 1.0 - -mole_balance H2[34S](-2) - -H2[34S] + HDS = HD[34S] + H2S - -mole_balance HD[34S](-2) - -H2[34S] + D2S = D2[34S] + H2S - -mole_balance D2[34S](-2) - -H2[34S] + HTS = HT[34S] + H2S - -mole_balance HT[34S](-2) - -H2[34S] + T2S = T2[34S] + H2S - -mole_balance T2[34S](-2) - -H2[34S] + DTS = DT[34S] + H2S - -mole_balance DT[34S](-2) -# -# NO2- reactions -# Updated March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -[15N]O3- + NO2- = [15N]O2- + NO3- - -add_logk Log_alpha_15N_NO2-/NO3- 1.0 - -gamma 3.0000 0.0000 -# -# N2 reactions -# -N2 + [15N]O3- = N[15N] + NO3- - log_k 0.301029995663 # log10(2) - -add_logk Log_alpha_15N_N2(aq)/NO3- 1.0 - -mole_balance [15N](0)N(0) -2N[15N] = [15N]2 + N2 - log_k -0.602059991327962396 # -log10(4) - -mole_balance [15N](0)2 -# -# NH3 reactions -# -HDO + NH3 = NH2D + H2O - log_k 0.176091259055 # log10(1.5) - -add_logk Log_alpha_D_NH3(aq)/H2O(l) 1.0 - -2NH2D = NHD2 + NH3 - log_k -0.477121254719 # -log10(3) - -3NH2D = ND3 + 2NH3 - -logk -1.431363764158 # log10(1/27) - -HTO + NH3 = NH2T + H2O - log_k 0.176091259055 # log10(1.5) - -add_logk Log_alpha_T_NH3(aq)/H2O(l) 1.0 - -2NH2T = NHT2 + NH3 - log_k -0.477121254719662 # log10(1/3) - -3NH2T = NT3 + 2NH3 - -logk -1.431363764158 # log10(1/27) - -NHD2 + NH2T = ND2T + NH3 - log_k -0.477121254719 # -log10(3) - -NH2D + NHT2 = NDT2 + NH3 - log_k -0.477121254719 # -log10(3) - -# Checked September 19, 2006 - -NH3 + [15N]O3- = [15N]H3 + NO3- - -add_logk Log_alpha_15N_NH3(aq)/NO3- 1.0 - -mole_balance [15N](-3)H3 - -[15N]H3 + NH2D = [15N]H2D + NH3 -[15N]H3 + NHD2 = [15N]HD2 + NH3 -[15N]H3 + ND3 = [15N]D3 + NH3 -[15N]H3 + NH2T = [15N]H2T + NH3 -[15N]H3 + NHT2 = [15N]HT2 + NH3 -[15N]H3 + NT3 = [15N]T3 + NH3 -[15N]H3 + ND2T = [15N]D2T + NH3 -[15N]H3 + NDT2 = [15N]DT2 + NH3 -# -# NH4+ reactions -# Updated September 19, 2006 -# Checked September 19, 2006 -# -HDO + NH4+ = NH3D+ + H2O - log_k 0.301029995663 # log10(2) - -add_logk Log_alpha_D_NH4+/H2O(l) 1.0 - -mole_balance N(-3)H3D - -gamma 2.5000 0.0000 - -2NH3D+ = NH2D2+ + NH4+ - log_k -0.42596873227228 # log10(3/8) - -mole_balance N(-3)H2D2 - -gamma 2.5000 0.0000 - -3NH3D+ = NHD3+ + 2NH4+ - log_k -1.20411998265 # log10(1/16) - -mole_balance N(-3)HD3 - -gamma 2.5000 0.0000 - -4NH3D+ = ND4+ + 3NH4+ - log_k -2.408239965311 # log10(1/256) - -mole_balance N(-3)D4 - -gamma 2.5000 0.0000 - -HTO + NH4+ = NH3T+ + H2O - log_k 0.301029995663 # log10(2) - -add_logk Log_alpha_T_NH4+/H2O(l) 1.0 - -mole_balance N(-3)H3T - -gamma 2.5000 0.0000 - -2NH3T+ = NH2T2+ + NH4+ - log_k -0.42596873227228 # log10(3/8) - -mole_balance N(-3)H2T2 - -gamma 2.5000 0.0000 - -3NH3T+ = NHT3+ + 2NH4+ - log_k -1.20411998265 # log10(1/16) - -mole_balance N(-3)HT3 - -gamma 2.5000 0.0000 - -4NH3T+ = NT4+ + 3NH4+ - log_k -2.408239965311 # log10(1/256) - -mole_balance N(-3)T4 - -gamma 2.5000 0.0000 -# -# Updated September 19, 2006 -# Checked September 19, 2006 -# -NHD3+ + NH3T+ = ND3T+ + NH4+ - log_k -0.602059991327962396 # -log10(4) - -mole_balance N(-3)D3T - -gamma 2.5000 0.0000 - -NH2D2+ + NH2T2+ = ND2T2+ + NH4+ - log_k -0.7781512503836 # -log10(6) - -mole_balance N(-3)D2T2 - -gamma 2.5000 0.0000 - -NH3D+ + NHT3+ = NDT3+ + NH4+ - log_k -0.602059991327962396 # -log10(4) - -mole_balance N(-3)DT3 - -gamma 2.5000 0.0000 - -[15N]H3 + NH4+ = [15N]H4+ + NH3 - -add_logk Log_alpha_15N_NH4+/NH3(aq) 1.0 - -mole_balance [15N](-3)H4 - -gamma 2.5000 0.0000 - -[15N]H4+ + NH3D+ = [15N]H3D+ + NH4+ - -mole_balance [15N](-3)H3D - -gamma 2.5000 0.0000 - -[15N]H4+ + NH2D2+ = [15N]H2D2+ + NH4+ - -mole_balance [15N](-3)H2D2 - -gamma 2.5000 0.0000 - -[15N]H4+ + NHD3+ = [15N]HD3+ + NH4+ - -mole_balance [15N](-3)HD3 - -gamma 2.5000 0.0000 - -[15N]H4+ + ND4+ = [15N]D4+ + NH4+ - -mole_balance [15N](-3)D4+ - -gamma 2.5000 0.0000 - -[15N]H4+ + NH3T+ = [15N]H3T+ + NH4+ - -mole_balance [15N](-3)H3T - -gamma 2.5000 0.0000 - -[15N]H4+ + NH2T2+ = [15N]H2T2+ + NH4+ - -mole_balance [15N](-3)H2T2 - -gamma 2.5000 0.0000 - -[15N]H4+ + NHT3+ = [15N]HT3+ + NH4+ - -mole_balance [15N](-3)HT3 - -gamma 2.5000 0.0000 - -[15N]H4+ + NT4+ = [15N]T4+ + NH4+ - -mole_balance [15N](-3)T4+ - -gamma 2.5000 0.0000 - -[15N]H4+ + ND3T+ = [15N]D3T+ + NH4+ - -mole_balance [15N](-3)D3T - -gamma 2.5000 0.0000 - -[15N]H4+ + ND2T2+ = [15N]D2T2+ + NH4+ - -mole_balance [15N](-3)D2T2 - -gamma 2.5000 0.0000 - -[15N]H4+ + NDT3+ = [15N]DT3+ + NH4+ - -mole_balance [15N](-3)DT3 - -gamma 2.5000 0.0000 -# -# Missing NH4SO4- reactions -# -# -# Missing HPO4-2 reactions -# -# -# Missing H2PO4- reactions -# -# -# Missing HF reactions -# -# -# Missing HF2- reactions -# -# -# CaOH reactions -# -CaOH+ + [18O]H- = Ca[18O]H+ + OH- - -mole_balance Ca[18O]H -CaOH+ + OD- = CaOD+ + OH- - -mole_balance CaOD -CaOH+ + [18O]D- = Ca[18O]D+ + OH- - -mole_balance Ca[18O]D -CaOH+ + OT- = CaOT+ + OH- - -mole_balance CaOT+ -CaOH+ + [18O]T- = Ca[18O]T+ + OH- - -mole_balance Ca[18O]T -# -# CaCO3 reactions -# -CaCO3 + CO2[18O]-2 = CaCO2[18O] + CO3-2 -CaCO3 + CO[18O]2-2 = CaCO[18O]2 + CO3-2 -CaCO3 + C[18O]3-2 = CaC[18O]3 + CO3-2 -CaCO3 + [13C]O3-2 = Ca[13C]O3 + CO3-2 -CaCO3 + [13C]O2[18O]-2 = Ca[13C]O2[18O] + CO3-2 -CaCO3 + [13C]O[18O]2-2 = Ca[13C]O[18O]2 + CO3-2 -CaCO3 + [13C][18O]3-2 = Ca[13C][18O]3 + CO3-2 -CaCO3 + [14C]O3-2 = Ca[14C]O3 + CO3-2 -CaCO3 + [14C]O2[18O]-2 = Ca[14C]O2[18O] + CO3-2 -CaCO3 + [14C]O[18O]2-2 = Ca[14C]O[18O]2 + CO3-2 -CaCO3 + [14C][18O]3-2 = Ca[14C][18O]3 + CO3-2 -# -# CaHCO3+ reactions -# -CaHCO3+ + HCO2[18O]- = CaHCO2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HCO[18O]O- = CaHCO[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HC[18O]O2- = CaHC[18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HCO[18O]2- = CaHCO[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HC[18O]O[18O]- = CaHC[18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HC[18O]2O- = CaHC[18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + HC[18O]3- = CaHC[18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C]O3- = CaH[13C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C]O2[18O]- = CaH[13C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C]O[18O]O- = CaH[13C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C][18O]O2- = CaH[13C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C]O[18O]2- = CaH[13C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C][18O]O[18O]- = CaH[13C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C][18O]2O- = CaH[13C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[13C][18O]3- = CaH[13C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C]O3- = CaH[14C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C]O2[18O]- = CaH[14C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C]O[18O]O- = CaH[14C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C][18O]O2- = CaH[14C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C]O[18O]2- = CaH[14C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C][18O]O[18O]- = CaH[14C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C][18O]2O- = CaH[14C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + H[14C][18O]3- = CaH[14C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -# DCO3- -CaHCO3+ + DCO3- = CaDCO3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DCO2[18O]- = CaDCO2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DCO[18O]O- = CaDCO[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DC[18O]O2- = CaDC[18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DCO[18O]2- = CaDCO[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DC[18O]O[18O]- = CaDC[18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DC[18O]2O- = CaDC[18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + DC[18O]3- = CaDC[18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C]O3- = CaD[13C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C]O2[18O]- = CaD[13C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C]O[18O]O- = CaD[13C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C][18O]O2- = CaD[13C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C]O[18O]2- = CaD[13C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C][18O]O[18O]- = CaD[13C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C][18O]2O- = CaD[13C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[13C][18O]3- = CaD[13C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C]O3- = CaD[14C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C]O2[18O]- = CaD[14C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C]O[18O]O- = CaD[14C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C][18O]O2- = CaD[14C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C]O[18O]2- = CaD[14C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C][18O]O[18O]- = CaD[14C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C][18O]2O- = CaD[14C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + D[14C][18O]3- = CaD[14C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -# TCO3- -CaHCO3+ + TCO3- = CaTCO3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TCO2[18O]- = CaTCO2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TCO[18O]O- = CaTCO[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TC[18O]O2- = CaTC[18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TCO[18O]2- = CaTCO[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TC[18O]O[18O]- = CaTC[18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TC[18O]2O- = CaTC[18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + TC[18O]3- = CaTC[18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C]O3- = CaT[13C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C]O2[18O]- = CaT[13C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C]O[18O]O- = CaT[13C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C][18O]O2- = CaT[13C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C]O[18O]2- = CaT[13C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C][18O]O[18O]- = CaT[13C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C][18O]2O- = CaT[13C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[13C][18O]3- = CaT[13C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C]O3- = CaT[14C]O3+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C]O2[18O]- = CaT[14C]O2[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C]O[18O]O- = CaT[14C]O[18O]O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C][18O]O2- = CaT[14C][18O]O2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C]O[18O]2- = CaT[14C]O[18O]2+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C][18O]O[18O]- = CaT[14C][18O]O[18O]+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C][18O]2O- = CaT[14C][18O]2O+ + HCO3- - -gamma 5.4000 0.0000 - -CaHCO3+ + T[14C][18O]3- = CaT[14C][18O]3+ + HCO3- - -gamma 5.4000 0.0000 -# -# CaSO4 reactions -# -# Updated May 17, 2006 -CaSO4 + [34S]O4-2 = Ca[34S]O4 + SO4-2 -# -# CaHSO4+ reactions -# -CaHSO4+ + H[34S]O4- = CaH[34S]O4+ + HSO4- -CaHSO4+ + D[34S]O4- = CaD[34S]O4+ + HSO4- -CaHSO4+ + T[34S]O4- = CaT[34S]O4+ + HSO4- -# -# Missing CaPO4- reactions -# -# -# Missing CaHPO4 reactions -# -# -# Missing CaH2PO4+ reactions -# -# -# MgOH+ reactions -# -MgOH+ + [18O]H- = Mg[18O]H+ + OH- -MgOH+ + OD- = MgOD+ + OH- -MgOH+ + [18O]D- = Mg[18O]D+ + OH- -MgOH+ + OT- = MgOT+ + OH- -MgOH+ + [18O]T- = Mg[18O]T+ + OH- -# -# MgCO3 reactions -# -MgCO3 + CO2[18O]-2 = MgCO2[18O] + CO3-2 -MgCO3 + CO[18O]2-2 = MgCO[18O]2 + CO3-2 -MgCO3 + C[18O]3-2 = MgC[18O]3 + CO3-2 -MgCO3 + [13C]O3-2 = Mg[13C]O3 + CO3-2 -MgCO3 + [13C]O2[18O]-2 = Mg[13C]O2[18O] + CO3-2 -MgCO3 + [13C]O[18O]2-2 = Mg[13C]O[18O]2 + CO3-2 -MgCO3 + [13C][18O]3-2 = Mg[13C][18O]3 + CO3-2 -MgCO3 + [14C]O3-2 = Mg[14C]O3 + CO3-2 -MgCO3 + [14C]O2[18O]-2 = Mg[14C]O2[18O] + CO3-2 -MgCO3 + [14C]O[18O]2-2 = Mg[14C]O[18O]2 + CO3-2 -MgCO3 + [14C][18O]3-2 = Mg[14C][18O]3 + CO3-2 -# -# MgHCO3+ reactions -# -MgHCO3+ + HCO2[18O]- = MgHCO2[18O]+ + HCO3- -MgHCO3+ + HCO[18O]O- = MgHCO[18O]O+ + HCO3- -MgHCO3+ + HC[18O]O2- = MgHC[18O]O2+ + HCO3- -MgHCO3+ + HCO[18O]2- = MgHCO[18O]2+ + HCO3- -MgHCO3+ + HC[18O]O[18O]- = MgHC[18O]O[18O]+ + HCO3- -MgHCO3+ + HC[18O]2O- = MgHC[18O]2O+ + HCO3- -MgHCO3+ + HC[18O]3- = MgHC[18O]3+ + HCO3- -MgHCO3+ + H[13C]O3- = MgH[13C]O3+ + HCO3- -MgHCO3+ + H[13C]O2[18O]- = MgH[13C]O2[18O]+ + HCO3- -MgHCO3+ + H[13C]O[18O]O- = MgH[13C]O[18O]O+ + HCO3- -MgHCO3+ + H[13C][18O]O2- = MgH[13C][18O]O2+ + HCO3- -MgHCO3+ + H[13C]O[18O]2- = MgH[13C]O[18O]2+ + HCO3- -MgHCO3+ + H[13C][18O]O[18O]- = MgH[13C][18O]O[18O]+ + HCO3- -MgHCO3+ + H[13C][18O]2O- = MgH[13C][18O]2O+ + HCO3- -MgHCO3+ + H[13C][18O]3- = MgH[13C][18O]3+ + HCO3- -MgHCO3+ + H[14C]O3- = MgH[14C]O3+ + HCO3- -MgHCO3+ + H[14C]O2[18O]- = MgH[14C]O2[18O]+ + HCO3- -MgHCO3+ + H[14C]O[18O]O- = MgH[14C]O[18O]O+ + HCO3- -MgHCO3+ + H[14C][18O]O2- = MgH[14C][18O]O2+ + HCO3- -MgHCO3+ + H[14C]O[18O]2- = MgH[14C]O[18O]2+ + HCO3- -MgHCO3+ + H[14C][18O]O[18O]- = MgH[14C][18O]O[18O]+ + HCO3- -MgHCO3+ + H[14C][18O]2O- = MgH[14C][18O]2O+ + HCO3- -MgHCO3+ + H[14C][18O]3- = MgH[14C][18O]3+ + HCO3- - -# DCO3- -MgHCO3+ + DCO3- = MgDCO3+ + HCO3- -MgHCO3+ + DCO2[18O]- = MgDCO2[18O]+ + HCO3- -MgHCO3+ + DCO[18O]O- = MgDCO[18O]O+ + HCO3- -MgHCO3+ + DC[18O]O2- = MgDC[18O]O2+ + HCO3- -MgHCO3+ + DCO[18O]2- = MgDCO[18O]2+ + HCO3- -MgHCO3+ + DC[18O]O[18O]- = MgDC[18O]O[18O]+ + HCO3- -MgHCO3+ + DC[18O]2O- = MgDC[18O]2O+ + HCO3- -MgHCO3+ + DC[18O]3- = MgDC[18O]3+ + HCO3- -MgHCO3+ + D[13C]O3- = MgD[13C]O3+ + HCO3- -MgHCO3+ + D[13C]O2[18O]- = MgD[13C]O2[18O]+ + HCO3- -MgHCO3+ + D[13C]O[18O]O- = MgD[13C]O[18O]O+ + HCO3- -MgHCO3+ + D[13C][18O]O2- = MgD[13C][18O]O2+ + HCO3- -MgHCO3+ + D[13C]O[18O]2- = MgD[13C]O[18O]2+ + HCO3- -MgHCO3+ + D[13C][18O]O[18O]- = MgD[13C][18O]O[18O]+ + HCO3- -MgHCO3+ + D[13C][18O]2O- = MgD[13C][18O]2O+ + HCO3- -MgHCO3+ + D[13C][18O]3- = MgD[13C][18O]3+ + HCO3- -MgHCO3+ + D[14C]O3- = MgD[14C]O3+ + HCO3- -MgHCO3+ + D[14C]O2[18O]- = MgD[14C]O2[18O]+ + HCO3- -MgHCO3+ + D[14C]O[18O]O- = MgD[14C]O[18O]O+ + HCO3- -MgHCO3+ + D[14C][18O]O2- = MgD[14C][18O]O2+ + HCO3- -MgHCO3+ + D[14C]O[18O]2- = MgD[14C]O[18O]2+ + HCO3- -MgHCO3+ + D[14C][18O]O[18O]- = MgD[14C][18O]O[18O]+ + HCO3- -MgHCO3+ + D[14C][18O]2O- = MgD[14C][18O]2O+ + HCO3- -MgHCO3+ + D[14C][18O]3- = MgD[14C][18O]3+ + HCO3- - -# TCO3- -MgHCO3+ + TCO3- = MgTCO3+ + HCO3- -MgHCO3+ + TCO2[18O]- = MgTCO2[18O]+ + HCO3- -MgHCO3+ + TCO[18O]O- = MgTCO[18O]O+ + HCO3- -MgHCO3+ + TC[18O]O2- = MgTC[18O]O2+ + HCO3- -MgHCO3+ + TCO[18O]2- = MgTCO[18O]2+ + HCO3- -MgHCO3+ + TC[18O]O[18O]- = MgTC[18O]O[18O]+ + HCO3- -MgHCO3+ + TC[18O]2O- = MgTC[18O]2O+ + HCO3- -MgHCO3+ + TC[18O]3- = MgTC[18O]3+ + HCO3- -MgHCO3+ + T[13C]O3- = MgT[13C]O3+ + HCO3- -MgHCO3+ + T[13C]O2[18O]- = MgT[13C]O2[18O]+ + HCO3- -MgHCO3+ + T[13C]O[18O]O- = MgT[13C]O[18O]O+ + HCO3- -MgHCO3+ + T[13C][18O]O2- = MgT[13C][18O]O2+ + HCO3- -MgHCO3+ + T[13C]O[18O]2- = MgT[13C]O[18O]2+ + HCO3- -MgHCO3+ + T[13C][18O]O[18O]- = MgT[13C][18O]O[18O]+ + HCO3- -MgHCO3+ + T[13C][18O]2O- = MgT[13C][18O]2O+ + HCO3- -MgHCO3+ + T[13C][18O]3- = MgT[13C][18O]3+ + HCO3- -MgHCO3+ + T[14C]O3- = MgT[14C]O3+ + HCO3- -MgHCO3+ + T[14C]O2[18O]- = MgT[14C]O2[18O]+ + HCO3- -MgHCO3+ + T[14C]O[18O]O- = MgT[14C]O[18O]O+ + HCO3- -MgHCO3+ + T[14C][18O]O2- = MgT[14C][18O]O2+ + HCO3- -MgHCO3+ + T[14C]O[18O]2- = MgT[14C]O[18O]2+ + HCO3- -MgHCO3+ + T[14C][18O]O[18O]- = MgT[14C][18O]O[18O]+ + HCO3- -MgHCO3+ + T[14C][18O]2O- = MgT[14C][18O]2O+ + HCO3- -MgHCO3+ + T[14C][18O]3- = MgT[14C][18O]3+ + HCO3- -# -# MgSO4 reactions -# -MgSO4 + [34S]O4-2 = Mg[34S]O4 + SO4-2 -# -# Missing MgPO4- reactions -# -# -# Missing MgHPO4 reactions -# -# -# Missing Mg2PO4+ reactions -# -# -# NaOH reactions -# -NaOH + [18O]H- = Na[18O]H + OH- -NaOH + OD- = NaOD + OH- -NaOH + [18O]D- = Na[18O]D + OH- -NaOH + OT- = NaOT + OH- -NaOH + [18O]T- = Na[18O]T + OH- -# -# NaCO3- reactions -# -NaCO3- + CO2[18O]-2 = NaCO2[18O]- + CO3-2 -NaCO3- + CO[18O]2-2 = NaCO[18O]2- + CO3-2 -NaCO3- + C[18O]3-2 = NaC[18O]3- + CO3-2 -NaCO3- + [13C]O3-2 = Na[13C]O3- + CO3-2 -NaCO3- + [13C]O2[18O]-2 = Na[13C]O2[18O]- + CO3-2 -NaCO3- + [13C]O[18O]2-2 = Na[13C]O[18O]2- + CO3-2 -NaCO3- + [13C][18O]3-2 = Na[13C][18O]3- + CO3-2 -NaCO3- + [14C]O3-2 = Na[14C]O3- + CO3-2 -NaCO3- + [14C]O2[18O]-2 = Na[14C]O2[18O]- + CO3-2 -NaCO3- + [14C]O[18O]2-2 = Na[14C]O[18O]2- + CO3-2 -NaCO3- + [14C][18O]3-2 = Na[14C][18O]3- + CO3-2 -# -# NaHCO3 reactions -# -NaHCO3 + HCO2[18O]- = NaHCO2[18O] + HCO3- -NaHCO3 + HCO[18O]O- = NaHCO[18O]O + HCO3- -NaHCO3 + HC[18O]O2- = NaHC[18O]O2 + HCO3- -NaHCO3 + HCO[18O]2- = NaHCO[18O]2 + HCO3- -NaHCO3 + HC[18O]O[18O]- = NaHC[18O]O[18O] + HCO3- -NaHCO3 + HC[18O]2O- = NaHC[18O]2O + HCO3- -NaHCO3 + HC[18O]3- = NaHC[18O]3 + HCO3- -NaHCO3 + H[13C]O3- = NaH[13C]O3 + HCO3- -NaHCO3 + H[13C]O2[18O]- = NaH[13C]O2[18O] + HCO3- -NaHCO3 + H[13C]O[18O]O- = NaH[13C]O[18O]O + HCO3- -NaHCO3 + H[13C][18O]O2- = NaH[13C][18O]O2 + HCO3- -NaHCO3 + H[13C]O[18O]2- = NaH[13C]O[18O]2 + HCO3- -NaHCO3 + H[13C][18O]O[18O]- = NaH[13C][18O]O[18O] + HCO3- -NaHCO3 + H[13C][18O]2O- = NaH[13C][18O]2O + HCO3- -NaHCO3 + H[13C][18O]3- = NaH[13C][18O]3 + HCO3- -NaHCO3 + H[14C]O3- = NaH[14C]O3 + HCO3- -NaHCO3 + H[14C]O2[18O]- = NaH[14C]O2[18O] + HCO3- -NaHCO3 + H[14C]O[18O]O- = NaH[14C]O[18O]O + HCO3- -NaHCO3 + H[14C][18O]O2- = NaH[14C][18O]O2 + HCO3- -NaHCO3 + H[14C]O[18O]2- = NaH[14C]O[18O]2 + HCO3- -NaHCO3 + H[14C][18O]O[18O]- = NaH[14C][18O]O[18O] + HCO3- -NaHCO3 + H[14C][18O]2O- = NaH[14C][18O]2O + HCO3- -NaHCO3 + H[14C][18O]3- = NaH[14C][18O]3 + HCO3- - -# DCO3- -NaHCO3 + DCO3- = NaDCO3 + HCO3- -NaHCO3 + DCO2[18O]- = NaDCO2[18O] + HCO3- -NaHCO3 + DCO[18O]O- = NaDCO[18O]O + HCO3- -NaHCO3 + DC[18O]O2- = NaDC[18O]O2 + HCO3- -NaHCO3 + DCO[18O]2- = NaDCO[18O]2 + HCO3- -NaHCO3 + DC[18O]O[18O]- = NaDC[18O]O[18O] + HCO3- -NaHCO3 + DC[18O]2O- = NaDC[18O]2O + HCO3- -NaHCO3 + DC[18O]3- = NaDC[18O]3 + HCO3- -NaHCO3 + D[13C]O3- = NaD[13C]O3 + HCO3- -NaHCO3 + D[13C]O2[18O]- = NaD[13C]O2[18O] + HCO3- -NaHCO3 + D[13C]O[18O]O- = NaD[13C]O[18O]O + HCO3- -NaHCO3 + D[13C][18O]O2- = NaD[13C][18O]O2 + HCO3- -NaHCO3 + D[13C]O[18O]2- = NaD[13C]O[18O]2 + HCO3- -NaHCO3 + D[13C][18O]O[18O]- = NaD[13C][18O]O[18O] + HCO3- -NaHCO3 + D[13C][18O]2O- = NaD[13C][18O]2O + HCO3- -NaHCO3 + D[13C][18O]3- = NaD[13C][18O]3 + HCO3- -NaHCO3 + D[14C]O3- = NaD[14C]O3 + HCO3- -NaHCO3 + D[14C]O2[18O]- = NaD[14C]O2[18O] + HCO3- -NaHCO3 + D[14C]O[18O]O- = NaD[14C]O[18O]O + HCO3- -NaHCO3 + D[14C][18O]O2- = NaD[14C][18O]O2 + HCO3- -NaHCO3 + D[14C]O[18O]2- = NaD[14C]O[18O]2 + HCO3- -NaHCO3 + D[14C][18O]O[18O]- = NaD[14C][18O]O[18O] + HCO3- -NaHCO3 + D[14C][18O]2O- = NaD[14C][18O]2O + HCO3- -NaHCO3 + D[14C][18O]3- = NaD[14C][18O]3 + HCO3- - -# TCO3- -NaHCO3 + TCO3- = NaTCO3 + HCO3- -NaHCO3 + TCO2[18O]- = NaTCO2[18O] + HCO3- -NaHCO3 + TCO[18O]O- = NaTCO[18O]O + HCO3- -NaHCO3 + TC[18O]O2- = NaTC[18O]O2 + HCO3- -NaHCO3 + TCO[18O]2- = NaTCO[18O]2 + HCO3- -NaHCO3 + TC[18O]O[18O]- = NaTC[18O]O[18O] + HCO3- -NaHCO3 + TC[18O]2O- = NaTC[18O]2O + HCO3- -NaHCO3 + TC[18O]3- = NaTC[18O]3 + HCO3- -NaHCO3 + T[13C]O3- = NaT[13C]O3 + HCO3- -NaHCO3 + T[13C]O2[18O]- = NaT[13C]O2[18O] + HCO3- -NaHCO3 + T[13C]O[18O]O- = NaT[13C]O[18O]O + HCO3- -NaHCO3 + T[13C][18O]O2- = NaT[13C][18O]O2 + HCO3- -NaHCO3 + T[13C]O[18O]2- = NaT[13C]O[18O]2 + HCO3- -NaHCO3 + T[13C][18O]O[18O]- = NaT[13C][18O]O[18O] + HCO3- -NaHCO3 + T[13C][18O]2O- = NaT[13C][18O]2O + HCO3- -NaHCO3 + T[13C][18O]3- = NaT[13C][18O]3 + HCO3- -NaHCO3 + T[14C]O3- = NaT[14C]O3 + HCO3- -NaHCO3 + T[14C]O2[18O]- = NaT[14C]O2[18O] + HCO3- -NaHCO3 + T[14C]O[18O]O- = NaT[14C]O[18O]O + HCO3- -NaHCO3 + T[14C][18O]O2- = NaT[14C][18O]O2 + HCO3- -NaHCO3 + T[14C]O[18O]2- = NaT[14C]O[18O]2 + HCO3- -NaHCO3 + T[14C][18O]O[18O]- = NaT[14C][18O]O[18O] + HCO3- -NaHCO3 + T[14C][18O]2O- = NaT[14C][18O]2O + HCO3- -NaHCO3 + T[14C][18O]3- = NaT[14C][18O]3 + HCO3- -# -# NaSO4- reactions -# -NaSO4- + [34S]O4-2 = Na[34S]O4- + SO4-2 -# -# Missing NaHPO4- reactions -# -# -# KOH reactions -# -KOH + [18O]H- = K[18O]H + OH- -KOH + OD- = KOD + OH- -KOH + [18O]D- = K[18O]D + OH- -KOH + OT- = KOT + OH- -KOH + [18O]T- = K[18O]T + OH- -# -# KSO4- reactions -# -KSO4- + [34S]O4-2 = K[34S]O4- + SO4-2 -# -# Missing FeOH+ reactions -# -# -# Missing FeCO3 reactions -# -# -# Missing FeHCO3+ reactions -# -# -# Missing FeSO4 reactions -# -# -# Missing FeHSO4+ reactions -# -# -# Missing Fe(HS)2 reactions -# -# -# Missing Fe(HS)3- reactions -# -# -# Missing FeHPO4 reactions -# -# -# Missing FeH2PO4+ reactions -# -# -# Missing FeOH+2 reactions -# -# -# Missing Fe(OH)2+ reactions -# -# -# Missing Fe(OH)3 reactions -# -# -# Missing Fe(OH)4- reactions -# -# -# Missing Fe2(OH)2+4 reactions -# -# -# Missing Fe3(OH)4+5 reactions -# -# -# Missing FeSO4+ reactions -# -# -# Missing FeHSO4+2 reactions -# -# -# Missing Fe(SO4)2- reactions -# -# -# Missing FeHPO4+ reactions -# -# -# Missing FeH2PO4+2 reactions -# -# -# Missing AlOH+2 reactions -# -# -# Missing Al(OH)2+ reactions -# -# -# Missing Al(OH)3 reactions -# -# -# Missing Al(OH)4- reactions -# -# -# Missing AlSO4+ reactions -# -# -# Missing Al(SO4)2- reactions -# -# -# Missing AlHSO4+2 reactions -# -# -# Missing H4SiO4 reactions -# -# -# Missing H3SiO4- reactions -# -# -# Missing H2SiO4-2 reactions -# - -############################################################################################### -PHASES -############################################################################################### -# -# Water vapor - Water -# last update March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -HDO(g) - HDO(g) + H2O(l) = H2O(g) + HDO(aq) - -add_logk Log_alpha_D_H2O(g)/H2O(l) -1.0 - -HTO(g) - HTO(g) + H2O(l) = H2O(g) + HTO(aq) - -add_logk Log_alpha_T_H2O(g)/H2O(l) -1.0 - -DTO(g) - DTO(g) + H2O(g) = HDO(g) + HTO(g) - log_k 0.301029995663 # log10(2) - -D2O(g) - D2O(g) + H2O(g) = 2HDO(g) - log_k 0.602059991327962396 # log10(4) - -T2O(g) - T2O(g) + H2O(g) = 2HTO(g) - log_k 0.602059991327962396 # log10(4) - -H2[18O](g) - H2[18O](g) + H2O(l) = H2O(g) + H2[18O](aq) - -add_logk Log_alpha_18O_H2O(g)/H2O(l) -1.0 - -HD[18O](g) - HD[18O](g) + H2O(g) = HDO(g) + H2[18O](g) - log_k 0.0 - -HT[18O](g) - HT[18O](g) + H2O(g) = HTO(g) + H2[18O](g) - log_k 0.0 - -D2[18O](g) - D2[18O](g) + H2O(g) = D2O(g) + H2[18O](g) - log_k 0.0 - -T2[18O](g) - T2[18O](g) + H2O(g) = T2O(g) + H2[18O](g) - log_k 0.0 - -DT[18O](g) - DT[18O](g) + H2O(g) = DTO(g) + H2[18O](g) - log_k 0.0 -# -# O2 gas - O2 aqueous -# last update March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -O[18O](g) - O[18O](g) + H2O(l) = O2(g) + H2[18O](aq) -## symmetry K ?? - -add_logk Log_alpha_18O_O2(g)/H2O(l) -1.0 - -[18O]2(g) - [18O]2(g) + O2(g) = 2O[18O](g) - log_k 0.602059991327962396 # log10(4) -# -# H2 gas - H2 aqueous -# last update March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -HD(g) - HD(g) + H2O(l) = H2(g) + HDO(aq) - -add_logk Log_alpha_D_H2(g)/H2O(l) -1.0 - -HT(g) - HT(g) + H2O(l) = H2(g) + HTO(aq) - -add_logk Log_alpha_T_H2(g)/H2O(l) -1.0 - -D2(g) - D2(g) + H2(g) = 2HD(g) - log_k 0.602059991327962396 # log10(4) - -T2(g) - T2(g) + H2(g) = 2HT(g) - log_k 0.602059991327962396 # log10(4) - -DT(g) - DT(g) + H2(g) = HD(g) + HT(g) - log_k 0.301029995663 # log10(2) -# -# CO2 gas - CO2 aqueous -# last update March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -CO[18O](g) - CO[18O](g) + H2O(l) = H2[18O](aq) + CO2(g) - log_k -0.301029995663 # -log10(2) - -add_logk Log_alpha_18O_CO2(g)/H2O(l) -1.0 - -C[18O]2(g) - C[18O]2(g) + CO2(g) = 2CO[18O](g) - log_k 0.602059991327962396 # log10(4) - -[13C]O2(g) - [13C]O2(g) + CO2(aq) = [13C]O2(aq) + CO2(g) - -add_logk Log_alpha_13C_CO2(g)/CO2(aq) -1.0 - -[13C]O[18O](g) - [13C]O[18O](g) + CO2(g) = [13C]O2(g) + CO[18O](g) - log_k 0 - -[13C][18O]2(g) - [13C][18O]2(g) + CO2(g) = C[18O]2(g) + [13C]O2(g) - log_k 0 - -[14C]O2(g) - [14C]O2(g) + CO2(aq) = [14C]O2(aq) + CO2(g) - -add_logk Log_alpha_14C_CO2(g)/CO2(aq) -1.0 - -[14C]O[18O](g) - [14C]O[18O](g) + CO2(g) = [14C]O2(g) + CO[18O](g) - log_k 0 - -[14C][18O]2(g) - [14C][18O]2(g) + CO2(g) = [14C]O2(g) + C[18O]2(g) - log_k 0 -# -# Calcite -# last update Feb 13, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -CaCO2[18O](s) - CaCO2[18O](s) + H2O(l) = H2[18O](aq) + Calcite(s) - log_k -0.477121254719 # -log10(3) ??? - -add_logk Log_alpha_18O_Calcite/H2O(l) -1.0 - -CaCO[18O]2(s) - CaCO[18O]2(s) + Calcite(s) = 2CaCO2[18O](s) - log_k 0.477121254719 # log10(3) - -CaC[18O]3(s) - CaC[18O]3(s) + 2Calcite(s) = 3CaCO2[18O](s) - log_k 1.431363764158 # log10(27) - -Ca[13C]O3(s) - Ca[13C]O3(s) + CO2 = [13C]O2 + Calcite(s) - -add_logk Log_alpha_13C_Calcite/CO2(aq) -1.0 - -Ca[13C]O2[18O](s) - Ca[13C]O2[18O](s) + Calcite(s) = Ca[13C]O3(s) + CaCO2[18O](s) - log_k 0 - -Ca[13C]O[18O]2(s) - Ca[13C]O[18O]2(s) + Calcite(s) = Ca[13C]O3(s) + CaCO[18O]2(s) - log_k 0 - -Ca[13C][18O]3(s) - Ca[13C][18O]3(s) + Calcite(s) = Ca[13C]O3(s) + CaC[18O]3(s) - log_k 0 - -Ca[14C]O3(s) - Ca[14C]O3(s) + CO2 = Calcite(s) + [14C]O2 - -add_logk Log_alpha_14C_Calcite/CO2(aq) -1.0 - -Ca[14C]O2[18O](s) - Ca[14C]O2[18O](s) + Calcite(s) = Ca[14C]O3(s) + CaCO2[18O](s) - log_k 0 - -Ca[14C]O[18O]2(s) - Ca[14C]O[18O]2(s) + Calcite(s) = Ca[14C]O3(s) + CaCO[18O]2(s) - log_k 0 - -Ca[14C][18O]3(s) - Ca[14C][18O]3(s) + Calcite(s) = Ca[14C]O3(s) + CaC[18O]3(s) - log_k 0 -# -# Pyrite, March 20, 2006 -# Update September 28, 2006 -# Checked September 28, 2006 -# -Pyrite_FeS[34S] - FeS[34S](s) + HS- = Pyrite(s) + H[34S]- - -add_logk Log_alpha_34S_Pyrite/HS- -1.0 - -Pyrite_Fe[34S]S - Fe[34S]S(s) = Pyrite_FeS[34S](s) - -Pyrite_Fe[34S]2 - Fe[34S]2(s) + Pyrite(s) = 2Pyrite_FeS[34S](s) -# -# CH4 reactions -# last update March 20, 2006 -# Updated September 19, 2006 -# Checked September 19, 2006 -# -CH3D(g) - CH3D(g) + H2O(l) = CH4(g) + HDO(aq) - log_k -0.301029995663 # -log10(2) ??? - -add_logk Log_alpha_D_CH4(g)/H2O(l) -1.0 - -CH2D2(g) - CH2D2(g) + CH4(g) = 2CH3D(g) - log_k 0.42596873227228 # log10(8/3) - -CHD3(g) - CHD3(g) + 2CH4(g) = 3CH3D(g) - log_k 1.20411998265 # log10(16) - -CD4(g) - CD4(g) + 3CH4(g) = 4CH3D(g) - log_k 2.408239965311 # log10(256) - -CH3T(g) - CH3T(g) + H2O(l) = CH4(g) + HTO(aq) - log_k -0.301029995663 # -log10(2) ??? - -add_logk Log_alpha_T_CH4(g)/H2O(l) -1.0 - -CH2T2(g) - CH2T2(g) + CH4(g) = 2CH3T(g) - log_k 0.42596873227228 # log10(8/3) - -CHT3(g) - CHT3(g) + 2CH4(g) = 3CH3T(g) - log_k 1.20411998265 # log10(16) - -CT4(g) - CT4(g) + 3CH4(g) = 4CH3T(g) - log_k 2.408239965311 # log10(256) - -CD3T(g) - CD3T(g) + CH4(g) = CHD3(g) + CH3T(g) - log_k 0.602059991327962396 # log10(4) - -CD2T2(g) - CD2T2(g) + CH4(g) = CH2D2(g) + CH2T2(g) - log_k 0.7781512503836 # log10(6) - -CDT3(g) - CDT3(g) + CH4(g) = CHT3(g) + CH3D(g) - log_k 0.602059991327962396 # log10(4) - -[13C]H4(g) - [13C]H4(g) + CO2(aq) = [13C]O2(aq) + CH4(g) - -add_logk Log_alpha_13C_CH4(g)/CO2(aq) -1.0 - -[13C]H3D(g) - [13C]H3D(g) + CH4(g) = CH3D(g) + [13C]H4(g) - -[13C]H2D2(g) - [13C]H2D2(g) + CH4(g) = CH2D2(g) + [13C]H4(g) - -[13C]HD3(g) - [13C]HD3(g) + CH4(g) = CHD3(g) + [13C]H4(g) - -[13C]D4(g) - [13C]D4(g) + CH4(g) = CD4(g) + [13C]H4(g) - -[13C]H3T(g) - [13C]H3T(g) + CH4(g) = CH3T(g) + [13C]H4(g) - -[13C]H2T2(g) - [13C]H2T2(g) + CH4(g) = CH2T2(g) + [13C]H4(g) - -[13C]HT3(g) - [13C]HT3(g) + CH4(g) = CHT3(g) + [13C]H4(g) - -[13C]T4(g) - [13C]T4(g) + CH4(g) = CT4(g) + [13C]H4(g) - -[13C]D3T(g) - [13C]D3T(g) + CH4(g) = CD3T(g) + [13C]H4(g) - -[13C]D2T2(g) - [13C]D2T2(g) + CH4(g) = CD2T2(g) + [13C]H4(g) - -[13C]DT3(g) - [13C]DT3(g) + CH4(g) = CDT3(g) + [13C]H4(g) - -[13C]T4(g) - [13C]T4(g) + CH4(g) = CT4(g) + [13C]H4(g) - -[14C]H4(g) - [14C]H4(g) + CO2(aq) = [14C]O2(aq) + CH4(g) - -add_logk Log_alpha_14C_CH4(g)/CO2(aq) -1.0 - -[14C]H3D(g) - [14C]H3D(g) + CH4(g) = CH3D(g) + [14C]H4(g) - -[14C]H2D2(g) - [14C]H2D2(g) + CH4(g) = CH2D2(g) + [14C]H4(g) - -[14C]HD3(g) - [14C]HD3(g) + CH4(g) = CHD3(g) + [14C]H4(g) - -[14C]D4(g) - [14C]D4(g) + CH4(g) = CD4(g) + [14C]H4(g) - -[14C]H3T(g) - [14C]H3T(g) + CH4(g) = CH3T(g) + [14C]H4(g) - -[14C]H2T2(g) - [14C]H2T2(g) + CH4(g) = CH2T2(g) + [14C]H4(g) - -[14C]HT3(g) - [14C]HT3(g) + CH4(g) = CHT3(g) + [14C]H4(g) - -[14C]T4(g) - [14C]T4(g) + CH4(g) = CT4(g) + [14C]H4(g) - -[14C]D3T(g) - [14C]D3T(g) + CH4(g) = CD3T(g) + [14C]H4(g) - -[14C]D2T2(g) - [14C]D2T2(g) + CH4(g) = CD2T2(g) + [14C]H4(g) - -[14C]DT3(g) - [14C]DT3(g) + CH4(g) = CDT3(g) + [14C]H4(g) - -[14C]T4(g) - [14C]T4(g) + CH4(g) = CT4(g) + [14C]H4(g) -# -# updated March 20, 2006 -# Updated September 28, 2006 -# Checked September 28, 2006 -# -HDS(g) - HDS(g) + H2S(aq) = HDS(aq) + H2S(g) - -add_logk Log_alpha_D_H2S(g)/H2S(aq) -1.0 - -D2S(g) - D2S(g) + H2S(g) = 2HDS(g) - log_k 0.602059991327962396 # log10(4) - -HTS(g) - HTS(g) + H2S(aq) = HTS(aq) + H2S(g) - -add_logk Log_alpha_T_H2S(g)/H2S(aq) -1.0 - -T2S(g) - T2S(g) + H2S(g) = 2HTS(g) - log_k 0.602059991327962396 # log10(4) - -DTS(g) - DTS(g) + H2S(g) = HDS(g) + HTS(g) - log_k 0.301029995663 # log10(2) - -H2[34S](g) - H2[34S](g) + H2S(aq) = H2[34S](aq) + H2S(g) - -add_logk Log_alpha_34S_H2S(g)/H2S(aq) -1.0 - -HD[34S](g) - HD[34S](g) + H2S(g) = HDS(g) + H2[34S](g) - -D2[34S](g) - D2[34S](g) + H2S(g) = D2S(g) + H2[34S](g) - -HT[34S](g) - HT[34S](g) + H2S(g) = HTS(g) + H2[34S](g) - -T2[34S](g) - T2[34S](g) + H2S(g) = T2S(g) + H2[34S](g) - -DT[34S](g) - DT[34S](g) + H2S(g) = DTS(g) + H2[34S](g) - -# -# Gypsum and anhydrite -# -Ca[34S]O4:2H2O - Ca[34S]O4:2H2O + SO4-2 = [34S]O4-2 + Gypsum(s) - -add_logk Log_alpha_34S_Gypsum/SO4-2 -1.0 - -Ca[34S]O4 - Ca[34S]O4 + SO4-2 = [34S]O4-2 + Anhydrite(s) - -add_logk Log_alpha_34S_Anhydrite/SO4-2 -1.0 -# -# Nitrogen phases -# Checked September 19, 2006 -# -N[15N](g) - N[15N](g) + N2(aq) = N[15N](aq) + N2(g) - -add_logk Log_alpha_15N_N2(g)/N2(aq) -1.0 - -[15N]2(g) - [15N]2(g) + N2(g) = 2N[15N](g) - log_k 0.602059991327962396 # log10(4) - -NH2D(g) - NH2D(g) + H2O(l) = NH3(g) + HDO(aq) -## symmetry K?? - -add_logk Log_alpha_D_NH3(g)/H2O(l) -1.0 - -NHD2(g) - NHD2(g) + NH3(g) = 2NH2D(g) - log_k 0.477121254719 # log10(3) - -ND3(g) - ND3(g) + 2NH3(g) = 3NH2D(g) - -logk 1.431363764158 # log10(27) - -NH2T(g) - NH2T(g) + H2O(l) = NH3(g) + HTO(aq) -## symmetry K?? - -add_logk Log_alpha_T_NH3(g)/H2O(l) -1.0 - -NHT2(g) - NHT2(g) + NH3(g) = 2NH2T(g) - log_k 0.477121254719 # log10(3) - -NT3(g) - NT3(g) + 2NH3(g) = 3NH2T(g) - -logk 1.431363764158 # log10(27) - -ND2T(g) - ND2T(g) + NH3(g) = NHD2(g) + NH2T(g) - log_k 0.477121254719 # log10(3) - -NDT2(g) - NDT2(g) + NH3(g) = NH2D(g) + NHT2(g) - log_k 0.477121254719 # log10(3) - -[15N]H3(g) - [15N]H3(g) + NH3(aq) = [15N]H3(aq) + NH3(g) - -add_logk Log_alpha_15N_NH3(g)/NH3(aq) -1.0 - -[15N]H2D(g) - [15N]H2D(g) + NH3(g) = NH2D(g) + [15N]H3(g) - -[15N]HD2(g) - [15N]HD2(g) + NH3(g) = NHD2(g) + [15N]H3(g) - -[15N]D3(g) - [15N]D3(g) + NH3(g) = ND3(g) + [15N]H3(g) - -[15N]H2T(g) - [15N]H2T(g) + NH3(g) = NH2T(g) + [15N]H3(g) - -[15N]HT2(g) - [15N]HT2(g) + NH3(g) = NHT2(g) + [15N]H3(g) - -[15N]T3(g) - [15N]T3(g) + NH3(g) = NT3(g) + [15N]H3(g) - -[15N]D2T(g) - [15N]D2T(g) + NH3(g) = ND2T(g) + [15N]H3(g) - -[15N]DT2(g) - [15N]DT2(g) + NH3(g) = NDT2(g) + [15N]H3(g) diff --git a/phreeqc.dat b/phreeqc.dat deleted file mode 100644 index befd93da..00000000 --- a/phreeqc.dat +++ /dev/null @@ -1,1556 +0,0 @@ -SOLUTION_MASTER_SPECIES -# -#element species alk gfw_formula element_gfw -# -H H+ -1. H 1.008 -H(0) H2 0.0 H -H(1) H+ -1. 0.0 -E e- 0.0 0.0 0.0 -O H2O 0.0 O 16.00 -O(0) O2 0.0 O -O(-2) H2O 0.0 0.0 -Ca Ca+2 0.0 Ca 40.08 -Mg Mg+2 0.0 Mg 24.312 -Na Na+ 0.0 Na 22.9898 -K K+ 0.0 K 39.102 -Fe Fe+2 0.0 Fe 55.847 -Fe(+2) Fe+2 0.0 Fe -Fe(+3) Fe+3 -2.0 Fe -Mn Mn+2 0.0 Mn 54.938 -Mn(+2) Mn+2 0.0 Mn -Mn(+3) Mn+3 0.0 Mn -Al Al+3 0.0 Al 26.9815 -Ba Ba+2 0.0 Ba 137.34 -Sr Sr+2 0.0 Sr 87.62 -Si H4SiO4 0.0 SiO2 28.0843 -Cl Cl- 0.0 Cl 35.453 -C CO3-2 2.0 HCO3 12.0111 -C(+4) CO3-2 2.0 HCO3 -C(-4) CH4 0.0 CH4 -Alkalinity CO3-2 1.0 Ca0.5(CO3)0.5 50.05 -S SO4-2 0.0 SO4 32.064 -S(6) SO4-2 0.0 SO4 -S(-2) HS- 1.0 S -N NO3- 0.0 N 14.0067 -N(+5) NO3- 0.0 N -N(+3) NO2- 0.0 N -N(0) N2 0.0 N -N(-3) NH4+ 0.0 N -B H3BO3 0.0 B 10.81 -P PO4-3 2.0 P 30.9738 -F F- 0.0 F 18.9984 -Li Li+ 0.0 Li 6.939 -Br Br- 0.0 Br 79.904 -Zn Zn+2 0.0 Zn 65.37 -Cd Cd+2 0.0 Cd 112.4 -Pb Pb+2 0.0 Pb 207.19 -Cu Cu+2 0.0 Cu 63.546 -Cu(+2) Cu+2 0.0 Cu -Cu(+1) Cu+1 0.0 Cu - -SOLUTION_SPECIES - -H+ = H+ - log_k 0.000 - -gamma 9.0000 0.0000 - -e- = e- - log_k 0.000 - -H2O = H2O - log_k 0.000 - -Ca+2 = Ca+2 - log_k 0.000 - -gamma 5.0000 0.1650 - -Mg+2 = Mg+2 - log_k 0.000 - -gamma 5.5000 0.2000 - -Na+ = Na+ - log_k 0.000 - -gamma 4.0000 0.0750 - -K+ = K+ - log_k 0.000 - -gamma 3.5000 0.0150 - -Fe+2 = Fe+2 - log_k 0.000 - -gamma 6.0000 0.0000 - -Mn+2 = Mn+2 - log_k 0.000 - -gamma 6.0000 0.0000 - -Al+3 = Al+3 - log_k 0.000 - -gamma 9.0000 0.0000 - -Ba+2 = Ba+2 - log_k 0.000 - -gamma 5.0000 0.0000 - -Sr+2 = Sr+2 - log_k 0.000 - -gamma 5.2600 0.1210 - -H4SiO4 = H4SiO4 - log_k 0.000 - -Cl- = Cl- - log_k 0.000 - -gamma 3.5000 0.0150 - -CO3-2 = CO3-2 - log_k 0.000 - -gamma 5.4000 0.0000 - -SO4-2 = SO4-2 - log_k 0.000 - -gamma 5.0000 -0.0400 - -NO3- = NO3- - log_k 0.000 - -gamma 3.0000 0.0000 - -H3BO3 = H3BO3 - log_k 0.000 - -PO4-3 = PO4-3 - log_k 0.000 - -gamma 4.0000 0.0000 - -F- = F- - log_k 0.000 - -gamma 3.5000 0.0000 - -Li+ = Li+ - log_k 0.000 - -gamma 6.0000 0.0000 - -Br- = Br- - log_k 0.000 - -gamma 3.0000 0.0000 - -Zn+2 = Zn+2 - log_k 0.000 - -gamma 5.0000 0.0000 - -Cd+2 = Cd+2 - log_k 0.000 - -Pb+2 = Pb+2 - log_k 0.000 - -Cu+2 = Cu+2 - log_k 0.000 - -gamma 6.0000 0.0000 - -H2O = OH- + H+ - log_k -14.000 - delta_h 13.362 kcal - -analytic -283.971 -0.05069842 13323.0 102.24447 -1119669.0 - -gamma 3.5000 0.0000 - -2 H2O = O2 + 4 H+ + 4 e- - log_k -86.08 - delta_h 134.79 kcal - -2 H+ + 2 e- = H2 - log_k -3.15 - delta_h -1.759 kcal - -CO3-2 + H+ = HCO3- - log_k 10.329 - delta_h -3.561 kcal - -analytic 107.8871 0.03252849 -5151.79 -38.92561 563713.9 - -gamma 5.4000 0.0000 - -CO3-2 + 2 H+ = CO2 + H2O - log_k 16.681 - delta_h -5.738 kcal - -analytic 464.1965 0.09344813 -26986.16 -165.75951 2248628.9 - -CO3-2 + 10 H+ + 8 e- = CH4 + 3 H2O - log_k 41.071 - delta_h -61.039 kcal - -SO4-2 + H+ = HSO4- - log_k 1.988 - delta_h 3.85 kcal - -analytic -56.889 0.006473 2307.9 19.8858 0.0 - -HS- = S-2 + H+ - log_k -12.918 - delta_h 12.1 kcal - -gamma 5.0000 0.0000 - -SO4-2 + 9 H+ + 8 e- = HS- + 4 H2O - log_k 33.65 - delta_h -60.140 kcal - -gamma 3.5000 0.0000 - -HS- + H+ = H2S - log_k 6.994 - delta_h -5.300 kcal - -analytical -11.17 0.02386 3279.0 - - -NO3- + 2 H+ + 2 e- = NO2- + H2O - log_k 28.570 - delta_h -43.760 kcal - -gamma 3.0000 0.0000 - -2 NO3- + 12 H+ + 10 e- = N2 + 6 H2O - log_k 207.080 - delta_h -312.130 kcal - -NH4+ = NH3 + H+ - log_k -9.252 - delta_h 12.48 kcal - -analytic 0.6322 -0.001225 -2835.76 - -NO3- + 10 H+ + 8 e- = NH4+ + 3 H2O - log_k 119.077 - delta_h -187.055 kcal - -gamma 2.5000 0.0000 - -NH4+ + SO4-2 = NH4SO4- - log_k 1.11 - -H3BO3 = H2BO3- + H+ - log_k -9.240 - delta_h 3.224 kcal -# -analytical 24.3919 0.012078 -1343.9 -13.2258 - -H3BO3 + F- = BF(OH)3- - log_k -0.400 - delta_h 1.850 kcal - -H3BO3 + 2 F- + H+ = BF2(OH)2- + H2O - log_k 7.63 - delta_h 1.618 kcal - -H3BO3 + 2 H+ + 3 F- = BF3OH- + 2 H2O - log_k 13.67 - delta_h -1.614 kcal - -H3BO3 + 3 H+ + 4 F- = BF4- + 3 H2O - log_k 20.28 - delta_h -1.846 kcal - -PO4-3 + H+ = HPO4-2 - log_k 12.346 - delta_h -3.530 kcal - -gamma 4.0000 0.0000 - -PO4-3 + 2 H+ = H2PO4- - log_k 19.553 - delta_h -4.520 kcal - -gamma 4.5000 0.0000 - -H+ + F- = HF - log_k 3.18 - delta_h 3.18 kcal - -analytic -2.033 0.012645 429.01 - -H+ + 2 F- = HF2- - log_k 3.760 - delta_h 4.550 kcal - -Ca+2 + H2O = CaOH+ + H+ - log_k -12.780 - -Ca+2 + CO3-2 = CaCO3 - log_k 3.224 - delta_h 3.545 kcal - -analytic -1228.732 -0.299440 35512.75 485.818 - -Ca+2 + CO3-2 + H+ = CaHCO3+ - log_k 11.435 - delta_h -0.871 kcal - -analytic 1317.0071 0.34546894 -39916.84 -517.70761 563713.9 - -gamma 5.4000 0.0000 - -Ca+2 + SO4-2 = CaSO4 - log_k 2.300 - delta_h 1.650 kcal - -Ca+2 + HSO4- = CaHSO4+ - log_k 1.08 - -Ca+2 + PO4-3 = CaPO4- - log_k 6.459 - delta_h 3.100 kcal - -Ca+2 + HPO4-2 = CaHPO4 - log_k 2.739 - delta_h 3.3 kcal - -Ca+2 + H2PO4- = CaH2PO4+ - log_k 1.408 - delta_h 3.4 kcal - -Ca+2 + F- = CaF+ - log_k 0.940 - delta_h 4.120 kcal - -Mg+2 + H2O = MgOH+ + H+ - log_k -11.440 - delta_h 15.952 kcal - -Mg+2 + CO3-2 = MgCO3 - log_k 2.98 - delta_h 2.713 kcal - -analytic 0.9910 0.00667 - -Mg+2 + H+ + CO3-2 = MgHCO3+ - log_k 11.399 - delta_h -2.771 kcal - -analytic 48.6721 0.03252849 -2614.335 -18.00263 563713.9 - -Mg+2 + SO4-2 = MgSO4 - log_k 2.370 - delta_h 4.550 kcal - -Mg+2 + PO4-3 = MgPO4- - log_k 6.589 - delta_h 3.100 kcal - -Mg+2 + HPO4-2 = MgHPO4 - log_k 2.87 - delta_h 3.3 kcal - -Mg+2 + H2PO4- = MgH2PO4+ - log_k 1.513 - delta_h 3.4 kcal - -Mg+2 + F- = MgF+ - log_k 1.820 - delta_h 3.200 kcal - -Na+ + H2O = NaOH + H+ - log_k -14.180 - -Na+ + CO3-2 = NaCO3- - log_k 1.270 - delta_h 8.910 kcal - -Na+ + HCO3- = NaHCO3 - log_k -0.25 - -Na+ + SO4-2 = NaSO4- - log_k 0.700 - delta_h 1.120 kcal - -Na+ + HPO4-2 = NaHPO4- - log_k 0.29 - -Na+ + F- = NaF - log_k -0.240 - -K+ + H2O = KOH + H+ - log_k -14.460 - -K+ + SO4-2 = KSO4- - log_k 0.850 - delta_h 2.250 kcal - -analytical 3.106 0.0 -673.6 - - -K+ + HPO4-2 = KHPO4- - log_k 0.29 - -Fe+2 + H2O = FeOH+ + H+ - log_k -9.500 - delta_h 13.200 kcal - -Fe+2 + Cl- = FeCl+ - log_k 0.140 - -Fe+2 + CO3-2 = FeCO3 - log_k 4.380 - -Fe+2 + HCO3- = FeHCO3+ - log_k 2.0 - -Fe+2 + SO4-2 = FeSO4 - log_k 2.250 - delta_h 3.230 kcal - -Fe+2 + HSO4- = FeHSO4+ - log_k 1.08 - -Fe+2 + 2HS- = Fe(HS)2 - log_k 8.95 - -Fe+2 + 3HS- = Fe(HS)3- - log_k 10.987 - -Fe+2 + HPO4-2 = FeHPO4 - log_k 3.6 - -Fe+2 + H2PO4- = FeH2PO4+ - log_k 2.7 - -Fe+2 + F- = FeF+ - log_k 1.000 - -Fe+2 = Fe+3 + e- - log_k -13.020 - delta_h 9.680 kcal - -gamma 9.0000 0.0000 - -Fe+3 + H2O = FeOH+2 + H+ - log_k -2.19 - delta_h 10.4 kcal - -Fe+3 + 2 H2O = Fe(OH)2+ + 2 H+ - log_k -5.67 - delta_h 17.1 kcal - -Fe+3 + 3 H2O = Fe(OH)3 + 3 H+ - log_k -12.56 - delta_h 24.8 kcal - -Fe+3 + 4 H2O = Fe(OH)4- + 4 H+ - log_k -21.6 - delta_h 31.9 kcal - -2 Fe+3 + 2 H2O = Fe2(OH)2+4 + 2 H+ - log_k -2.95 - delta_h 13.5 kcal - -3 Fe+3 + 4 H2O = Fe3(OH)4+5 + 4 H+ - log_k -6.3 - delta_h 14.3 kcal - -Fe+3 + Cl- = FeCl+2 - log_k 1.48 - delta_h 5.6 kcal - -Fe+3 + 2 Cl- = FeCl2+ - log_k 2.13 - -Fe+3 + 3 Cl- = FeCl3 - log_k 1.13 - -Fe+3 + SO4-2 = FeSO4+ - log_k 4.04 - delta_h 3.91 kcal - -Fe+3 + HSO4- = FeHSO4+2 - log_k 2.48 - -Fe+3 + 2 SO4-2 = Fe(SO4)2- - log_k 5.38 - delta_h 4.60 kcal - -Fe+3 + HPO4-2 = FeHPO4+ - log_k 5.43 - delta_h 5.76 kcal - -Fe+3 + H2PO4- = FeH2PO4+2 - log_k 5.43 - -Fe+3 + F- = FeF+2 - log_k 6.2 - delta_h 2.7 kcal - -Fe+3 + 2 F- = FeF2+ - log_k 10.8 - delta_h 4.8 kcal - -Fe+3 + 3 F- = FeF3 - log_k 14.0 - delta_h 5.4 kcal - -Mn+2 + H2O = MnOH+ + H+ - log_k -10.590 - delta_h 14.400 kcal - -Mn+2 + Cl- = MnCl+ - log_k 0.610 - -Mn+2 + 2 Cl- = MnCl2 - log_k 0.250 - -Mn+2 + 3 Cl- = MnCl3- - log_k -0.310 - -Mn+2 + CO3-2 = MnCO3 - log_k 4.900 - -Mn+2 + HCO3- = MnHCO3+ - log_k 1.95 - -Mn+2 + SO4-2 = MnSO4 - log_k 2.250 - delta_h 3.370 kcal - -Mn+2 + 2 NO3- = Mn(NO3)2 - log_k 0.600 - delta_h -0.396 kcal - -Mn+2 + F- = MnF+ - log_k 0.840 - -Mn+2 = Mn+3 + e- - log_k -25.510 - delta_h 25.800 kcal - -Al+3 + H2O = AlOH+2 + H+ - log_k -5.00 - delta_h 11.49 kcal - -analytic -38.253 0.0 -656.27 14.327 - -Al+3 + 2 H2O = Al(OH)2+ + 2 H+ - log_k -10.1 - delta_h 26.90 kcal - -analytic 88.500 0.0 -9391.6 -27.121 - -Al+3 + 3 H2O = Al(OH)3 + 3 H+ - log_k -16.9 - delta_h 39.89 kcal - -analytic 226.374 0.0 -18247.8 -73.597 - -Al+3 + 4 H2O = Al(OH)4- + 4 H+ - log_k -22.7 - delta_h 42.30 kcal - -analytic 51.578 0.0 -11168.9 -14.865 - -Al+3 + SO4-2 = AlSO4+ - log_k 3.5 - delta_h 2.29 kcal - -Al+3 + 2SO4-2 = Al(SO4)2- - log_k 5.0 - delta_h 3.11 kcal - -Al+3 + HSO4- = AlHSO4+2 - log_k 0.46 - -Al+3 + F- = AlF+2 - log_k 7.000 - delta_h 1.060 kcal - -Al+3 + 2 F- = AlF2+ - log_k 12.700 - delta_h 1.980 kcal - -Al+3 + 3 F- = AlF3 - log_k 16.800 - delta_h 2.160 kcal - -Al+3 + 4 F- = AlF4- - log_k 19.400 - delta_h 2.200 kcal - -Al+3 + 5 F- = AlF5-2 - log_k 20.600 - delta_h 1.840 kcal - -Al+3 + 6 F- = AlF6-3 - log_k 20.600 - delta_h -1.670 kcal - -H4SiO4 = H3SiO4- + H+ - log_k -9.83 - delta_h 6.12 kcal - -analytic -302.3724 -0.050698 15669.69 108.18466 -1119669.0 - -H4SiO4 = H2SiO4-2 + 2 H+ - log_k -23.0 - delta_h 17.6 kcal - -analytic -294.0184 -0.072650 11204.49 108.18466 -1119669.0 - -H4SiO4 + 4 H+ + 6 F- = SiF6-2 + 4 H2O - log_k 30.180 - delta_h -16.260 kcal - -Ba+2 + H2O = BaOH+ + H+ - log_k -13.470 - -Ba+2 + CO3-2 = BaCO3 - log_k 2.71 - delta_h 3.55 kcal - -analytic 0.113 0.008721 - -Ba+2 + HCO3- = BaHCO3+ - log_k 0.982 - delta_h 5.56 kcal - -analytical -3.0938 0.013669 0.0 0.0 0.0 - -Ba+2 + SO4-2 = BaSO4 - log_k 2.700 - -Sr+2 + H2O = SrOH+ + H+ - log_k -13.290 - -gamma 5.0000 0.0000 - -Sr+2 + CO3-2 + H+ = SrHCO3+ - log_k 11.509 - delta_h 2.489 kcal - -analytic 104.6391 0.04739549 -5151.79 -38.92561 563713.9 - -gamma 5.4000 0.0000 - -Sr+2 + CO3-2 = SrCO3 - log_k 2.81 - delta_h 5.22 kcal - -analytic -1.019 0.012826 - -Sr+2 + SO4-2 = SrSO4 - log_k 2.290 - delta_h 2.080 kcal - -Li+ + H2O = LiOH + H+ - log_k -13.640 - -Li+ + SO4-2 = LiSO4- - log_k 0.640 - -Cu+2 + e- = Cu+ - log_k 2.720 - delta_h 1.650 kcal - -gamma 2.5000 0.0000 - -Cu+2 + H2O = CuOH+ + H+ - log_k -8.000 - -gamma 4.0000 0.0000 - -Cu+2 + 2 H2O = Cu(OH)2 + 2 H+ - log_k -13.680 - -Cu+2 + 3 H2O = Cu(OH)3- + 3 H+ - log_k -26.900 - -Cu+2 + 4 H2O = Cu(OH)4-2 + 4 H+ - log_k -39.600 - -Cu+2 + SO4-2 = CuSO4 - log_k 2.310 - delta_h 1.220 kcal - -Zn+2 + H2O = ZnOH+ + H+ - log_k -8.96 - delta_h 13.4 kcal - -Zn+2 + 2 H2O = Zn(OH)2 + 2 H+ - log_k -16.900 - -Zn+2 + 3 H2O = Zn(OH)3- + 3 H+ - log_k -28.400 - -Zn+2 + 4 H2O = Zn(OH)4-2 + 4 H+ - log_k -41.200 - -Zn+2 + Cl- = ZnCl+ - log_k 0.43 - delta_h 7.79 kcal - -Zn+2 + 2 Cl- = ZnCl2 - log_k 0.45 - delta_h 8.5 kcal - -Zn+2 + 3Cl- = ZnCl3- - log_k 0.5 - delta_h 9.56 kcal - -Zn+2 + 4Cl- = ZnCl4-2 - log_k 0.2 - delta_h 10.96 kcal - -Zn+2 + CO3-2 = ZnCO3 - log_k 5.3 - -Zn+2 + 2CO3-2 = Zn(CO3)2-2 - log_k 9.63 - -Zn+2 + HCO3- = ZnHCO3+ - log_k 2.1 - -Zn+2 + SO4-2 = ZnSO4 - log_k 2.37 - delta_h 1.36 kcal - -Zn+2 + 2SO4-2 = Zn(SO4)2-2 - log_k 3.28 - -Cd+2 + H2O = CdOH+ + H+ - log_k -10.080 - delta_h 13.1 kcal - -Cd+2 + 2 H2O = Cd(OH)2 + 2 H+ - log_k -20.350 - -Cd+2 + 3 H2O = Cd(OH)3- + 3 H+ - log_k -33.300 - -Cd+2 + 4 H2O = Cd(OH)4-2 + 4 H+ - log_k -47.350 - -Cd+2 + Cl- = CdCl+ - log_k 1.980 - delta_h 0.59 kcal - -Cd+2 + 2 Cl- = CdCl2 - log_k 2.600 - delta_h 1.24 kcal - -Cd+2 + 3 Cl- = CdCl3- - log_k 2.400 - delta_h 3.9 kcal - -Cd+2 + CO3-2 = CdCO3 - log_k 2.9 - -Cd+2 + 2CO3-2 = Cd(CO3)2-2 - log_k 6.4 - -Cd+2 + HCO3- = CdHCO3+ - log_k 1.5 - -Cd+2 + SO4-2 = CdSO4 - log_k 2.460 - delta_h 1.08 kcal - -Cd+2 + 2SO4-2 = Cd(SO4)2-2 - log_k 3.5 - -Pb+2 + H2O = PbOH+ + H+ - log_k -7.710 - -Pb+2 + 2 H2O = Pb(OH)2 + 2 H+ - log_k -17.120 - -Pb+2 + 3 H2O = Pb(OH)3- + 3 H+ - log_k -28.060 - -Pb+2 + 4 H2O = Pb(OH)4-2 + 4 H+ - log_k -39.700 - -2 Pb+2 + H2O = Pb2OH+3 + H+ - log_k -6.360 - -Pb+2 + Cl- = PbCl+ - log_k 1.600 - delta_h 4.38 kcal - -Pb+2 + 2 Cl- = PbCl2 - log_k 1.800 - delta_h 1.08 kcal - -Pb+2 + 3 Cl- = PbCl3- - log_k 1.700 - delta_h 2.17 kcal - -Pb+2 + 4 Cl- = PbCl4-2 - log_k 1.380 - delta_h 3.53 kcal - -Pb+2 + CO3-2 = PbCO3 - log_k 7.240 - -Pb+2 + 2 CO3-2 = Pb(CO3)2-2 - log_k 10.640 - -Pb+2 + HCO3- = PbHCO3+ - log_k 2.9 - -Pb+2 + SO4-2 = PbSO4 - log_k 2.750 - -Pb+2 + 2 SO4-2 = Pb(SO4)2-2 - log_k 3.470 - -Pb+2 + NO3- = PbNO3+ - log_k 1.170 - -PHASES - -Calcite - CaCO3 = CO3-2 + Ca+2 - log_k -8.480 - delta_h -2.297 kcal - -analytic -171.9065 -0.077993 2839.319 71.595 - -Aragonite - CaCO3 = CO3-2 + Ca+2 - log_k -8.336 - delta_h -2.589 kcal - -analytic -171.9773 -0.077993 2903.293 71.595 - -Dolomite - CaMg(CO3)2 = Ca+2 + Mg+2 + 2 CO3-2 - log_k -17.090 - delta_h -9.436 kcal - -Siderite - FeCO3 = Fe+2 + CO3-2 - log_k -10.890 - delta_h -2.480 kcal - -Rhodochrosite - MnCO3 = Mn+2 + CO3-2 - log_k -11.130 - delta_h -1.430 kcal - -Strontianite - SrCO3 = Sr+2 + CO3-2 - log_k -9.271 - delta_h -0.400 kcal - -analytic 155.0305 0.0 -7239.594 -56.58638 - -Witherite - BaCO3 = Ba+2 + CO3-2 - log_k -8.562 - delta_h 0.703 kcal - -analytic 607.642 0.121098 -20011.25 -236.4948 - -Gypsum - CaSO4:2H2O = Ca+2 + SO4-2 + 2 H2O - log_k -4.580 - delta_h -0.109 kcal - -analytic 68.2401 0.0 -3221.51 -25.0627 - -Anhydrite - CaSO4 = Ca+2 + SO4-2 - log_k -4.360 - delta_h -1.710 kcal - -analytic 197.52 0.0 -8669.8 -69.835 - -Celestite - SrSO4 = Sr+2 + SO4-2 - log_k -6.630 - delta_h -1.037 kcal - -analytic -14805.9622 -2.4660924 756968.533 5436.3588 -40553604.0 - -Barite - BaSO4 = Ba+2 + SO4-2 - log_k -9.970 - delta_h 6.350 kcal - -analytic 136.035 0.0 -7680.41 -48.595 - -Hydroxyapatite - Ca5(PO4)3OH + 4 H+ = H2O + 3 HPO4-2 + 5 Ca+2 - log_k -3.421 - delta_h -36.155 kcal - -Fluorite - CaF2 = Ca+2 + 2 F- - log_k -10.600 - delta_h 4.690 kcal - -analytic 66.348 0.0 -4298.2 -25.271 - -SiO2(a) - SiO2 + 2 H2O = H4SiO4 - log_k -2.710 - delta_h 3.340 kcal - -analytic -0.26 0.0 -731.0 - -Chalcedony - SiO2 + 2 H2O = H4SiO4 - log_k -3.550 - delta_h 4.720 kcal - -analytic -0.09 0.0 -1032.0 - -Quartz - SiO2 + 2 H2O = H4SiO4 - log_k -3.980 - delta_h 5.990 kcal - -analytic 0.41 0.0 -1309.0 - -Gibbsite - Al(OH)3 + 3 H+ = Al+3 + 3 H2O - log_k 8.110 - delta_h -22.800 kcal - -Al(OH)3(a) - Al(OH)3 + 3 H+ = Al+3 + 3 H2O - log_k 10.800 - delta_h -26.500 kcal - -Kaolinite - Al2Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 2 Al+3 - log_k 7.435 - delta_h -35.300 kcal - -Albite - NaAlSi3O8 + 8 H2O = Na+ + Al(OH)4- + 3 H4SiO4 - log_k -18.002 - delta_h 25.896 kcal - -Anorthite - CaAl2Si2O8 + 8 H2O = Ca+2 + 2 Al(OH)4- + 2 H4SiO4 - log_k -19.714 - delta_h 11.580 kcal - -K-feldspar - KAlSi3O8 + 8 H2O = K+ + Al(OH)4- + 3 H4SiO4 - log_k -20.573 - delta_h 30.820 kcal - -K-mica - KAl3Si3O10(OH)2 + 10 H+ = K+ + 3 Al+3 + 3 H4SiO4 - log_k 12.703 - delta_h -59.376 kcal - -Chlorite(14A) - Mg5Al2Si3O10(OH)8 + 16H+ = 5Mg+2 + 2Al+3 + 3H4SiO4 + 6H2O - log_k 68.38 - delta_h -151.494 kcal - -Ca-Montmorillonite - Ca0.165Al2.33Si3.67O10(OH)2 + 12 H2O = 0.165Ca+2 + 2.33 Al(OH)4- + 3.67 H4SiO4 + 2 H+ - log_k -45.027 - delta_h 58.373 kcal - -Talc - Mg3Si4O10(OH)2 + 4 H2O + 6 H+ = 3 Mg+2 + 4 H4SiO4 - log_k 21.399 - delta_h -46.352 kcal - -Illite - K0.6Mg0.25Al2.3Si3.5O10(OH)2 + 11.2H2O = 0.6K+ + 0.25Mg+2 + 2.3Al(OH)4- + 3.5H4SiO4 + 1.2H+ - log_k -40.267 - delta_h 54.684 kcal - -Chrysotile - Mg3Si2O5(OH)4 + 6 H+ = H2O + 2 H4SiO4 + 3 Mg+2 - log_k 32.200 - delta_h -46.800 kcal - -analytic 13.248 0.0 10217.1 -6.1894 - -Sepiolite - Mg2Si3O7.5OH:3H2O + 4 H+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 - log_k 15.760 - delta_h -10.700 kcal - -Sepiolite(d) - Mg2Si3O7.5OH:3H2O + 4 H+ + 0.5H2O = 2 Mg+2 + 3 H4SiO4 - log_k 18.660 - -Hematite - Fe2O3 + 6 H+ = 2 Fe+3 + 3 H2O - log_k -4.008 - delta_h -30.845 kcal - -Goethite - FeOOH + 3 H+ = Fe+3 + 2 H2O - log_k -1.000 - delta_h -14.48 kcal - -Fe(OH)3(a) - Fe(OH)3 + 3 H+ = Fe+3 + 3 H2O - log_k 4.891 - -Pyrite - FeS2 + 2 H+ + 2 e- = Fe+2 + 2 HS- - log_k -18.479 - delta_h 11.300 kcal - -FeS(ppt) - FeS + H+ = Fe+2 + HS- - log_k -3.915 - -Mackinawite - FeS + H+ = Fe+2 + HS- - log_k -4.648 - -Sulfur - S + 2H+ + 2e- = H2S - log_k 4.882 - delta_h -9.5 kcal - -Vivianite - Fe3(PO4)2:8H2O = 3 Fe+2 + 2 PO4-3 + 8 H2O - log_k -36.000 - -Pyrolusite - MnO2 + 4 H+ + 2 e- = Mn+2 + 2 H2O - log_k 41.380 - delta_h -65.110 kcal - -Hausmannite - Mn3O4 + 8 H+ + 2 e- = 3 Mn+2 + 4 H2O - log_k 61.030 - delta_h -100.640 kcal - -Manganite - MnOOH + 3 H+ + e- = Mn+2 + 2 H2O - log_k 25.340 - -Pyrochroite - Mn(OH)2 + 2 H+ = Mn+2 + 2 H2O - log_k 15.200 - -Halite - NaCl = Na+ + Cl- - log_k 1.582 - delta_h 0.918 kcal - -CO2(g) - CO2 = CO2 - log_k -1.468 - delta_h -4.776 kcal - -analytic 108.3865 0.01985076 -6919.53 -40.45154 669365.0 - -O2(g) - O2 = O2 - log_k -2.960 - delta_h -1.844 kcal - -H2(g) - H2 = H2 - log_k -3.150 - delta_h -1.759 kcal - -H2O(g) - H2O = H2O - log_k 1.51 - delta_h -44.03 kJ -# Stumm and Morgan, from NBS and Robie, Hemmingway, and Fischer (1978) - -N2(g) - N2 = N2 - log_k -3.260 - delta_h -1.358 kcal - -H2S(g) - H2S = H2S - log_k -0.997 - delta_h -4.570 kcal - -CH4(g) - CH4 = CH4 - log_k -2.860 - delta_h -3.373 kcal - -NH3(g) - NH3 = NH3 - log_k 1.770 - delta_h -8.170 kcal - -Melanterite - FeSO4:7H2O = 7 H2O + Fe+2 + SO4-2 - log_k -2.209 - delta_h 4.910 kcal - -analytic 1.447 -0.004153 0.0 0.0 -214949.0 - -Alunite - KAl3(SO4)2(OH)6 + 6 H+ = K+ + 3 Al+3 + 2 SO4-2 + 6H2O - log_k -1.400 - delta_h -50.250 kcal - -Jarosite-K - KFe3(SO4)2(OH)6 + 6 H+ = 3 Fe+3 + 6 H2O + K+ + 2 SO4-2 - log_k -9.210 - delta_h -31.280 kcal - -Zn(OH)2(e) - Zn(OH)2 + 2 H+ = Zn+2 + 2 H2O - log_k 11.50 - -Smithsonite - ZnCO3 = Zn+2 + CO3-2 - log_k -10.000 - delta_h -4.36 kcal - -Sphalerite - ZnS + H+ = Zn+2 + HS- - log_k -11.618 - delta_h 8.250 kcal - -Willemite 289 - Zn2SiO4 + 4H+ = 2Zn+2 + H4SiO4 - log_k 15.33 - delta_h -33.37 kcal - -Cd(OH)2 - Cd(OH)2 + 2 H+ = Cd+2 + 2 H2O - log_k 13.650 - -Otavite 315 - CdCO3 = Cd+2 + CO3-2 - log_k -12.1 - delta_h -0.019 kcal - -CdSiO3 328 - CdSiO3 + H2O + 2H+ = Cd+2 + H4SiO4 - log_k 9.06 - delta_h -16.63 kcal - -CdSO4 329 - CdSO4 = Cd+2 + SO4-2 - log_k -0.1 - delta_h -14.74 kcal - -Cerrusite 365 - PbCO3 = Pb+2 + CO3-2 - log_k -13.13 - delta_h 4.86 kcal - -Anglesite 384 - PbSO4 = Pb+2 + SO4-2 - log_k -7.79 - delta_h 2.15 kcal - -Pb(OH)2 389 - Pb(OH)2 + 2H+ = Pb+2 + 2H2O - log_k 8.15 - delta_h -13.99 kcal - -EXCHANGE_MASTER_SPECIES - X X- -EXCHANGE_SPECIES - X- = X- - log_k 0.0 - - Na+ + X- = NaX - log_k 0.0 - -gamma 4.0 0.075 - - K+ + X- = KX - log_k 0.7 - -gamma 3.5 0.015 - delta_h -4.3 # Jardine & Sparks, 1984 - - Li+ + X- = LiX - log_k -0.08 - -gamma 6.0 0.0 - delta_h 1.4 # Merriam & Thomas, 1956 - - NH4+ + X- = NH4X - log_k 0.6 - -gamma 2.5 0.0 - delta_h -2.4 # Laudelout et al., 1968 - - Ca+2 + 2X- = CaX2 - log_k 0.8 - -gamma 5.0 0.165 - delta_h 7.2 # Van Bladel & Gheyl, 1980 - - Mg+2 + 2X- = MgX2 - log_k 0.6 - -gamma 5.5 0.2 - delta_h 7.4 # Laudelout et al., 1968 - - Sr+2 + 2X- = SrX2 - log_k 0.91 - -gamma 5.26 0.121 - delta_h 5.5 # Laudelout et al., 1968 - - Ba+2 + 2X- = BaX2 - log_k 0.91 - -gamma 5.0 0.0 - delta_h 4.5 # Laudelout et al., 1968 - - Mn+2 + 2X- = MnX2 - log_k 0.52 - -gamma 6.0 0.0 - - Fe+2 + 2X- = FeX2 - log_k 0.44 - -gamma 6.0 0.0 - - Cu+2 + 2X- = CuX2 - log_k 0.6 - -gamma 6.0 0.0 - - Zn+2 + 2X- = ZnX2 - log_k 0.8 - -gamma 5.0 0.0 - - Cd+2 + 2X- = CdX2 - log_k 0.8 - - Pb+2 + 2X- = PbX2 - log_k 1.05 - - Al+3 + 3X- = AlX3 - log_k 0.41 - -gamma 9.0 0.0 - - AlOH+2 + 2X- = AlOHX2 - log_k 0.89 - -gamma 0.0 0.0 -SURFACE_MASTER_SPECIES - Hfo_s Hfo_sOH - Hfo_w Hfo_wOH -SURFACE_SPECIES -# All surface data from -# Dzombak and Morel, 1990 -# -# -# Acid-base data from table 5.7 -# -# strong binding site--Hfo_s, - - Hfo_sOH = Hfo_sOH - log_k 0.0 - - Hfo_sOH + H+ = Hfo_sOH2+ - log_k 7.29 # = pKa1,int - - Hfo_sOH = Hfo_sO- + H+ - log_k -8.93 # = -pKa2,int - -# weak binding site--Hfo_w - - Hfo_wOH = Hfo_wOH - log_k 0.0 - - Hfo_wOH + H+ = Hfo_wOH2+ - log_k 7.29 # = pKa1,int - - Hfo_wOH = Hfo_wO- + H+ - log_k -8.93 # = -pKa2,int - -############################################### -# CATIONS # -############################################### -# -# Cations from table 10.1 or 10.5 -# -# Calcium - Hfo_sOH + Ca+2 = Hfo_sOHCa+2 - log_k 4.97 - - Hfo_wOH + Ca+2 = Hfo_wOCa+ + H+ - log_k -5.85 -# Strontium - Hfo_sOH + Sr+2 = Hfo_sOHSr+2 - log_k 5.01 - - Hfo_wOH + Sr+2 = Hfo_wOSr+ + H+ - log_k -6.58 - - Hfo_wOH + Sr+2 + H2O = Hfo_wOSrOH + 2H+ - log_k -17.60 -# Barium - Hfo_sOH + Ba+2 = Hfo_sOHBa+2 - log_k 5.46 - - Hfo_wOH + Ba+2 = Hfo_wOBa+ + H+ - log_k -7.2 # table 10.5 -# -# Cations from table 10.2 -# -# Cadmium - Hfo_sOH + Cd+2 = Hfo_sOCd+ + H+ - log_k 0.47 - - Hfo_wOH + Cd+2 = Hfo_wOCd+ + H+ - log_k -2.91 -# Zinc - Hfo_sOH + Zn+2 = Hfo_sOZn+ + H+ - log_k 0.99 - - Hfo_wOH + Zn+2 = Hfo_wOZn+ + H+ - log_k -1.99 -# Copper - Hfo_sOH + Cu+2 = Hfo_sOCu+ + H+ - log_k 2.89 - - Hfo_wOH + Cu+2 = Hfo_wOCu+ + H+ - log_k 0.6 # table 10.5 -# Lead - Hfo_sOH + Pb+2 = Hfo_sOPb+ + H+ - log_k 4.65 - - Hfo_wOH + Pb+2 = Hfo_wOPb+ + H+ - log_k 0.3 # table 10.5 -# -# Derived constants table 10.5 -# -# Magnesium - Hfo_wOH + Mg+2 = Hfo_wOMg+ + H+ - log_k -4.6 -# Manganese - Hfo_sOH + Mn+2 = Hfo_sOMn+ + H+ - log_k -0.4 # table 10.5 - - Hfo_wOH + Mn+2 = Hfo_wOMn+ + H+ - log_k -3.5 # table 10.5 -# Iron -# Hfo_sOH + Fe+2 = Hfo_sOFe+ + H+ -# log_k 0.7 # LFER using table 10.5 - -# Hfo_wOH + Fe+2 = Hfo_wOFe+ + H+ -# log_k -2.5 # LFER using table 10.5 - -# Iron, strong site: Appelo, Van der Weiden, Tournassat & Charlet, subm. - Hfo_sOH + Fe+2 = Hfo_sOFe+ + H+ - log_k -0.95 -# Iron, weak site: Liger et al., GCA 63, 2939, re-optimized for D&M - Hfo_wOH + Fe+2 = Hfo_wOFe+ + H+ - log_k -2.98 - - Hfo_wOH + Fe+2 + H2O = Hfo_wOFeOH + 2H+ - log_k -11.55 - -############################################### -# ANIONS # -############################################### -# -# Anions from table 10.6 -# -# Phosphate - Hfo_wOH + PO4-3 + 3H+ = Hfo_wH2PO4 + H2O - log_k 31.29 - - Hfo_wOH + PO4-3 + 2H+ = Hfo_wHPO4- + H2O - log_k 25.39 - - Hfo_wOH + PO4-3 + H+ = Hfo_wPO4-2 + H2O - log_k 17.72 -# -# Anions from table 10.7 -# -# Borate - Hfo_wOH + H3BO3 = Hfo_wH2BO3 + H2O - log_k 0.62 -# -# Anions from table 10.8 -# -# Sulfate - Hfo_wOH + SO4-2 + H+ = Hfo_wSO4- + H2O - log_k 7.78 - - Hfo_wOH + SO4-2 = Hfo_wOHSO4-2 - log_k 0.79 -# -# Derived constants table 10.10 -# - Hfo_wOH + F- + H+ = Hfo_wF + H2O - log_k 8.7 - - Hfo_wOH + F- = Hfo_wOHF- - log_k 1.6 -# -# Carbonate: Van Geen et al., 1994 reoptimized for HFO -# 0.15 g HFO/L has 0.344 mM sites == 2 g of Van Geen's Goethite/L -# -# Hfo_wOH + CO3-2 + H+ = Hfo_wCO3- + H2O -# log_k 12.56 -# -# Hfo_wOH + CO3-2 + 2H+= Hfo_wHCO3 + H2O -# log_k 20.62 - -# 9/19/96 -# Added analytical expression for H2S, NH3, KSO4. -# Added species CaHSO4+. -# Added delta H for Goethite. - -RATES - -########### -#K-feldspar -########### -# -# Sverdrup, H.U., 1990, The kinetics of base cation release due to -# chemical weathering: Lund University Press, Lund, 246 p. -# -# Example of KINETICS data block for K-feldspar rate: -# KINETICS 1 -# K-feldspar -# -m0 2.16 # 10% K-fsp, 0.1 mm cubes -# -m 1.94 -# -parms 1.36e4 0.1 - -K-feldspar - -start - 1 rem specific rate from Sverdrup, 1990, in kmol/m2/s - 2 rem parm(1) = 10 * (A/V, 1/dm) (recalc's sp. rate to mol/kgw) - 3 rem parm(2) = corrects for field rate relative to lab rate - 4 rem temp corr: from p. 162. E (kJ/mol) / R / 2.303 = H in H*(1/T-1/298) - - 10 dif_temp = 1/TK - 1/298 - 20 pk_H = 12.5 + 3134 * dif_temp - 30 pk_w = 15.3 + 1838 * dif_temp - 40 pk_OH = 14.2 + 3134 * dif_temp - 50 pk_CO2 = 14.6 + 1677 * dif_temp - #60 pk_org = 13.9 + 1254 * dif_temp # rate increase with DOC - 70 rate = 10^-pk_H * ACT("H+")^0.5 + 10^-pk_w + 10^-pk_OH * ACT("OH-")^0.3 - 71 rate = rate + 10^-pk_CO2 * (10^SI("CO2(g)"))^0.6 - #72 rate = rate + 10^-pk_org * TOT("Doc")^0.4 - 80 moles = parm(1) * parm(2) * rate * (1 - SR("K-feldspar")) * time - 81 rem decrease rate on precipitation - 90 if SR("K-feldspar") > 1 then moles = moles * 0.1 - 100 save moles - -end - -########### -#Albite -########### -# -# Sverdrup, H.U., 1990, The kinetics of base cation release due to -# chemical weathering: Lund University Press, Lund, 246 p. -# -# Example of KINETICS data block for Albite rate: -# KINETICS 1 -# Albite -# -m0 0.43 # 2% Albite, 0.1 mm cubes -# -parms 2.72e3 0.1 - -Albite - -start - 1 rem specific rate from Sverdrup, 1990, in kmol/m2/s - 2 rem parm(1) = 10 * (A/V, 1/dm) (recalc's sp. rate to mol/kgw) - 3 rem parm(2) = corrects for field rate relative to lab rate - 4 rem temp corr: from p. 162. E (kJ/mol) / R / 2.303 = H in H*(1/T-1/298) - - 10 dif_temp = 1/TK - 1/298 - 20 pk_H = 12.5 + 3359 * dif_temp - 30 pk_w = 14.8 + 2648 * dif_temp - 40 pk_OH = 13.7 + 3359 * dif_temp - #41 rem ^12.9 in Sverdrup, but larger than for oligoclase... - 50 pk_CO2 = 14.0 + 1677 * dif_temp - #60 pk_org = 12.5 + 1254 * dif_temp # ...rate increase for DOC - 70 rate = 10^-pk_H * ACT("H+")^0.5 + 10^-pk_w + 10^-pk_OH * ACT("OH-")^0.3 - 71 rate = rate + 10^-pk_CO2 * (10^SI("CO2(g)"))^0.6 - #72 rate = rate + 10^-pk_org * TOT("Doc")^0.4 - 80 moles = parm(1) * parm(2) * rate * (1 - SR("Albite")) * time - 81 rem decrease rate on precipitation - 90 if SR("Albite") > 1 then moles = moles * 0.1 - 100 save moles - -end - -######## -#Calcite -######## -# -# Plummer, L.N., Wigley, T.M.L., and Parkhurst, D.L., 1978, -# American Journal of Science, v. 278, p. 179-216. -# -# Example of KINETICS data block for calcite rate: -# -# KINETICS 1 -# Calcite -# -tol 1e-8 -# -m0 3.e-3 -# -m 3.e-3 -# -parms 5.0 0.6 -Calcite - -start - 1 REM Modified from Plummer and others, 1978 - 2 REM M = current moles of calcite - 3 REM M0 = initial moles of calcite - 4 REM parm(1) = Area/Volume, cm^2/L (or cm^2 per cell) - 5 REM parm(2) = exponent for M/M0 for surface area correction - 10 REM rate = 0 if no calcite and undersaturated - 20 si_cc = SI("Calcite") - 30 if (M <= 0 and si_cc < 0) then goto 300 - 40 k1 = 10^(0.198 - 444.0 / TK ) - 50 k2 = 10^(2.84 - 2177.0 / TK ) - 60 if TC <= 25 then k3 = 10^(-5.86 - 317.0 / TK ) - 70 if TC > 25 then k3 = 10^(-1.1 - 1737.0 / TK ) - 80 REM surface area calculation - 90 t = 1 - 100 if M0 > 0 then t = M/M0 - 110 if t = 0 then t = 1 - 120 area = PARM(1) * (t)^PARM(2) - 130 rf = k1 * ACT("H+") + k2 * ACT("CO2") + k3 * ACT("H2O") - 140 REM 1e-3 converts mmol to mol - 150 rate = area * 1e-3 * rf * (1 - 10^(2/3*si_cc)) - 160 moles = rate * TIME - 170 REM do not dissolve more calcite than present - 180 if (moles > M) then moles = M - 190 if (moles >= 0) then goto 300 - 200 REM do not precipitate more Ca or C(4) than present - 210 temp = TOT("Ca") - 220 mc = TOT("C(4)") - 230 if mc < temp then temp = mc - 240 if -moles > temp then moles = -temp - 300 SAVE moles - -end - -####### -#Pyrite -####### -# -# Williamson, M.A. and Rimstidt, J.D., 1994, -# Geochimica et Cosmochimica Acta, v. 58, p. 5443-5454. -# -# Example of KINETICS data block for pyrite rate: -# KINETICS 1 -# Pyrite -# -tol 1e-8 -# -m0 5.e-4 -# -m 5.e-4 -# -parms 2.0 0.67 .5 -0.11 -Pyrite - -start - 1 rem Williamson and Rimstidt, 1994 - 2 rem parm(1) = log10(A/V, 1/dm) parm(2) = exp for (m/m0) - 3 rem parm(3) = exp for O2 parm(4) = exp for H+ - - 10 if (m <= 0) then goto 200 - 20 if (si("Pyrite") >= 0) then goto 200 - 20 rate = -10.19 + parm(1) + parm(3)*lm("O2") + parm(4)*lm("H+") + parm(2)*log10(m/m0) - 30 moles = 10^rate * time - 40 if (moles > m) then moles = m - 200 save moles - -end - -########## -#Organic_C -########## -# -# Example of KINETICS data block for Organic_C rate: -# KINETICS 1 -# Organic_C -# -tol 1e-8 -# # m in mol/kgw -# -m0 5e-3 -# -m 5e-3 -Organic_C - -start - 1 rem Additive Monod kinetics - 2 rem Electron acceptors: O2, NO3, and SO4 - - 10 if (m <= 0) then goto 200 - 20 mO2 = mol("O2") - 30 mNO3 = tot("N(5)") - 40 mSO4 = tot("S(6)") - 50 rate = 1.57e-9*mO2/(2.94e-4 + mO2) + 1.67e-11*mNO3/(1.55e-4 + mNO3) - 60 rate = rate + 1.e-13*mSO4/(1.e-4 + mSO4) - 70 moles = rate * m * (m/m0) * time - 80 if (moles > m) then moles = m - 200 save moles - -end - -########### -#Pyrolusite -########### -# -# Postma, D. and Appelo, C.A.J., 2000, GCA 64, in press -# -# Example of KINETICS data block for Pyrolusite -# KINETICS 1-12 -# Pyrolusite -# -tol 1.e-7 -# -m0 0.1 -# -m 0.1 -Pyrolusite - -start - 5 if (m <= 0.0) then goto 200 - 7 sr_pl = sr("Pyrolusite") - 9 if abs(1 - sr_pl) < 0.1 then goto 200 - 10 if (sr_pl > 1.0) then goto 100 - #20 rem initially 1 mol Fe+2 = 0.5 mol pyrolusite. k*A/V = 1/time (3 cells) - #22 rem time (3 cells) = 1.432e4. 1/time = 6.98e-5 - 30 Fe_t = tot("Fe(2)") - 32 if Fe_t < 1.e-8 then goto 200 - 40 moles = 6.98e-5 * Fe_t * (m/m0)^0.67 * time * (1 - sr_pl) - 50 if moles > Fe_t / 2 then moles = Fe_t / 2 - 70 if moles > m then moles = m - 90 goto 200 - 100 Mn_t = tot("Mn") - 110 moles = 2e-3 * 6.98e-5 * (1-sr_pl) * time - 120 if moles <= -Mn_t then moles = -Mn_t - 200 save moles - -end -END diff --git a/phreeqc.distribution.checklist b/phreeqc.distribution.checklist deleted file mode 100644 index 86f3bb93..00000000 --- a/phreeqc.distribution.checklist +++ /dev/null @@ -1,85 +0,0 @@ -(1) Copy distribution.checklist to checklist.VERSION - -(2) XXX Update version and date in main.c - -(3) XXX Update doc/README.TXT - XXX uname -r - XXX gcc -v - -(4) Update src/revisions - when all_dist is run by make, src/revisions is copied - to doc/RELEASE.TXT - - ( ../doc/phreeqc.txt now static, only RELEASE.TXT - has history 2/2/05) - -(5) Update Makefile and distribution.mk - set VERSION number - set VER_DATE - add any new files to distribution - database files - source files - output files - doc files - -(6) svn status ~/programs/phreeqc -q - svn ci ~/programs/phreeqc - svn update - -(7) remake everything - make clean_all - make output_files (also remakes programs) - -(8) svn status ~/programs/phreeqc -q - should be clean - otherwise commit and restart checklist at item 5 - -(9) make all_dist REVISION=xxx - ls phreeqc_export -Linux/ phreeqc-2.12-577.Linux.tar.gz phreeqc-2.12-577.source.tar.gz Source/ - -(10) test Unix distributions - make test_dist - or - make linux_test, sun_test, source_test - -(11) Scott is making batch windows - -(12) make web - install windows version - copy README.TXT to ~/programs/phreeqc/win - - cp $(DIST_DIR)/phreeqc-$(VERSION)*.tar.gz /var/anonymous/ftp/dlpark/geochem/unix/phreeqc - cp $(EXPORT_DIR)/Linux/doc/README.TXT /var/anonymous/ftp/dlpark/geochem/unix/phreeqc/README.TXT - cp $(EXPORT_DIR)/Linux/doc/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Unix.TXT - cp ~/programs/phreeqc/win/README.TXT /var/anonymous/ftp/dlpark/geochem/pc/phreeqc/README.TXT - cp ~/programs/phreeqc/win/README.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/README.Win.TXT - cp $(EXPORT_DIR)/Linux/doc/phreeqc.txt /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/phreeqc.txt - cp $(EXPORT_DIR)/Linux/doc/RELEASE.TXT /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/RELEASE.TXT - -(13) check for latest version of Phreeqc For Windows. - -(14) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqc/index.html - phreeqci version, date, size - windows batch phreeqc version size - Linux batch phreeqc version size - Generic batch phreeqc version size - phreeqc for windows version, date, size - -(15) update web page /z/linarcolkr/home/www/projects/GWC_coupled/phreeqci/index.html - PhreeqcI version, date, size - -(16) send mail to Brian Marshal - -(17) PHAST - unpack release version in packages - Update table in /z/linarcolkr/home/www/projects/GWC_coupled/phast/index.html - copy release notes - from ~/packages/phast-x.x/doc/RELEASE.TXT - to /z/linarcolkr/home/www/projects/GWC_coupled/phast/RELEASE.TXT - copy readme - from ~/packages/phast-x.x/README - to /z/linarcolkr/home/www/projects/GWC_coupled/phast/README - -(18) Update status.fm - From dbaabe0180541363a010bf13fb777c8bdd286e7d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 20 Jan 2016 21:30:24 +0000 Subject: [PATCH 0968/1077] initialize variables git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10722 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/transport.cpp b/transport.cpp index ff091798..ca8d307e 100644 --- a/transport.cpp +++ b/transport.cpp @@ -624,6 +624,8 @@ transport(void) //std::cerr << "RM: " << rm_time << " PHREEQC: " << phreeqc_time << std::endl; //std::cerr << "RM comm: " << rm_comm_time << " RM calc: " << rm_calc_time << std::endl; //std::cerr << " transport_step: " << transport_step << " j: " << j << std::endl; + /* + */ #endif if (!dV_dcell) Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); @@ -1897,6 +1899,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) icell = jcell = -1; first_c = last_c = -1; + il_calcs = -1; current_x = sum_R = sum_Rd = 0.0; if (dV_dcell) @@ -2259,6 +2262,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) LDBLE g, g_i, g_j; char token[MAX_LENGTH], token1[MAX_LENGTH]; + por_il12 = A_i = A_j =0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; dV = 0.0; From 41bb948377436fe0747ed4c1ec1c3608b7e24038 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 20 Jan 2016 22:02:20 +0000 Subject: [PATCH 0969/1077] fix for linux, but Cl has NaN git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10723 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 2 +- class_main.cpp | 2 ++ transport.cpp | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.old b/Makefile.old index dc037c02..c09c9336 100644 --- a/Makefile.old +++ b/Makefile.old @@ -655,7 +655,7 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../common/phrqtype.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h ../Parallelizer.h \ + ../SurfaceCharge.h ../global_structures.h ../NA.h \ ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ diff --git a/class_main.cpp b/class_main.cpp index 586240c4..4e8d61a1 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,5 +1,7 @@ #include "Phreeqc.h" +#ifdef PHREEQC_PARALLEL #include "Parallelizer.h" +#endif #include "NameDouble.h" #include "Solution.h" #include "Reaction.h" diff --git a/transport.cpp b/transport.cpp index ca8d307e..208f7e26 100644 --- a/transport.cpp +++ b/transport.cpp @@ -75,12 +75,12 @@ transport(void) transp_surf = warn_fixed_Surf = warn_MCD_X = 0; dV_dcell = current_A = 0.0; current_cells = NULL; + +#ifdef PHREEQC_PARALLEL double rm_time = 0.0; double phreeqc_time = 0.0; double rm_comm_time = 0.0; double rm_calc_time = 0.0; - -#ifdef PHREEQC_PARALLEL Parallelizer *phreeqcrm_ptr; #ifdef USE_MPI int nxyz = count_cells + 2; From 7fbf8779ce56382cf72008697966b3db8a0c3850 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Jan 2016 00:20:02 +0000 Subject: [PATCH 0970/1077] Removed parallelization. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10726 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 90 +-------------------------------------------------- 1 file changed, 1 insertion(+), 89 deletions(-) diff --git a/transport.cpp b/transport.cpp index 208f7e26..af75ca0e 100644 --- a/transport.cpp +++ b/transport.cpp @@ -7,22 +7,6 @@ #include "SSassemblage.h" #include "cxxKinetics.h" #include "Solution.h" -#ifdef PHREEQC_PARALLEL -#include "Parallelizer.h" -#include "PhreeqcRM.h" -#include "IPhreeqcPhast.h" -#include "IPhreeqc.hpp" -#include "Serializer.h" -#endif -#ifdef USE_MPI -#include -#define CLOCK MPI_Wtime -#elif USE_OPENMP -#include -#define CLOCK omp_get_wtime -#else -#define CLOCK clock -#endif LDBLE F_Re3 = F_C_MOL / (R_KJ_DEG_MOL * 1e3); LDBLE tk_x2; // average tx_x of icell and jcell @@ -76,23 +60,6 @@ transport(void) dV_dcell = current_A = 0.0; current_cells = NULL; -#ifdef PHREEQC_PARALLEL - double rm_time = 0.0; - double phreeqc_time = 0.0; - double rm_comm_time = 0.0; - double rm_calc_time = 0.0; - Parallelizer *phreeqcrm_ptr; -#ifdef USE_MPI - int nxyz = count_cells + 2; - MPI_Bcast(&nxyz, 1, MPI_INT, 0, MPI_COMM_WORLD); - phreeqcrm_ptr = new Parallelizer(nxyz, MPI_COMM_WORLD, this->phrq_io); -#else - phreeqcrm_ptr = new Parallelizer(count_cells + 1, 3, this->phrq_io); -#endif - phreeqcrm_ptr->SetPhreeqcPtr(this); - phreeqcrm_ptr->Initialize(); -#endif - /* mass_water_switch = TRUE; */ /* * Check existence of solutions @@ -523,40 +490,7 @@ transport(void) } if (multi_Dflag) multi_D(stagkin_time, 1, FALSE); - double time_rm_start = CLOCK(); -#ifdef PHREEQC_PARALLEL - { - //Serializer serial; - //serial.Serialize(*this, 0, count_cells + 1, false, false); - ////this->Rxn_solution_map.clear(); - //Dictionary d1(serial.GetDictionary().GetDictionaryOss().str()); - //Serializer serial1; - //serial1.Deserialize(*this, d1, serial.GetInts(), serial.GetDoubles()); - } - // move data to workers - phreeqcrm_ptr->Phreeqc2RM(this); - rm_comm_time += (CLOCK() - time_rm_start); - double time_rm_calc_start = CLOCK(); - // Run cells - phreeqcrm_ptr->SetTimeStep(kin_time); - phreeqcrm_ptr->RunCellsParallel(); - rm_time += (CLOCK() - time_rm_start); - rm_calc_time += (CLOCK() - time_rm_calc_start); - //std::cerr << phreeqcrm_ptr->GetErrorString() << std::endl; - // move data back to phreeqc - phreeqcrm_ptr->RM2Phreeqc(this); -#endif - -#ifdef PHREEQC_PARALLELyyy - // Copy to PhreeqcRM - // Run reactions - // Copy to PHREEQC - // Do other stuff - -#else - - time_rm_start = CLOCK(); for (i = 0; i <= count_cells + 1; i++) { if (!dV_dcell && (i == 0 || i == count_cells + 1)) @@ -620,13 +554,7 @@ transport(void) } } } - //phreeqc_time += (CLOCK() - time_rm_start); - //std::cerr << "RM: " << rm_time << " PHREEQC: " << phreeqc_time << std::endl; - //std::cerr << "RM comm: " << rm_comm_time << " RM calc: " << rm_calc_time << std::endl; - //std::cerr << " transport_step: " << transport_step << " j: " << j << std::endl; - /* - */ -#endif + if (!dV_dcell) Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each @@ -832,16 +760,6 @@ transport(void) { heat_mix(heat_nmix); /* equilibrate again ... */ -#ifdef PHREEQC_PARALLEL - // move data to workers - phreeqcrm_ptr->Phreeqc2RM(this); - // Run cells - phreeqcrm_ptr->RunCells(); - // move data back to phreeqc -#ifdef SKIP - phreeqcrm_ptr->RM2phreeqc(this); -#endif -#endif for (i = 1; i <= count_cells; i++) { cell_no = i; @@ -991,12 +909,6 @@ transport(void) initial_total_time += rate_sim_time; rate_sim_time = 0; mass_water_switch = FALSE; -#ifdef PHREEQC_PARALLEL -#ifdef USE_MPI - phreeqcrm_ptr->MpiWorkerBreak(); -#endif - delete phreeqcrm_ptr; -#endif return (OK); } /* ---------------------------------------------------------------------- */ From 7f842da63ead731323f16b2137041a940761ee16 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Jan 2016 16:29:14 +0000 Subject: [PATCH 0971/1077] removed MPI. Fixed memory leak. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10727 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 87 ++------------------------------------------------ transport.cpp | 12 +++++-- 2 files changed, 12 insertions(+), 87 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 4e8d61a1..186c7fd2 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -13,10 +13,7 @@ #include "cxxKinetics.h" //#include //#include -#if defined(USE_MPI) -#include -int worker_tasks(int *task_number, void * cookie); -#endif + /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ @@ -51,7 +48,7 @@ main(int argc, char *argv[]) tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 31195; + //_crtBreakAlloc = 185092; #endif #ifdef SKIP //Set the x86 floating-point control word according to what @@ -75,71 +72,10 @@ unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. //Restore the original value when done: //_controlfp(cwOriginal, MCW_EM); #endif -#if defined(USE_MPI) - int mpi_tasks, mpi_myself; - if (MPI_Init(&argc, &argv) != MPI_SUCCESS) - { - return EXIT_FAILURE; - } - if (MPI_Comm_size(MPI_COMM_WORLD, &mpi_tasks) != MPI_SUCCESS) - { - return EXIT_FAILURE; - } - - if (MPI_Comm_rank(MPI_COMM_WORLD, &mpi_myself) != MPI_SUCCESS) - { - return EXIT_FAILURE; - } - if (mpi_myself > 0) - { - for (;;) - { - //MPI_Status mpi_status; - int task_no; - MPI_Bcast(&task_no, 1, MPI_INT, 0, MPI_COMM_WORLD); - if (task_no > 0) - { - Parallelizer *phreeqcrm_ptr = new Parallelizer(task_no, MPI_COMM_WORLD); - phreeqcrm_ptr->SetMpiWorkerCallbackC(worker_tasks); - phreeqcrm_ptr->SetMpiWorkerCallbackCookie(phreeqcrm_ptr); - phreeqcrm_ptr->MpiWorker(); - delete phreeqcrm_ptr; - //{ - // std::ostringstream os; - // os << "Worker " << mpi_myself << " deleting Parallelizer. " << std::endl; - // std::cerr << os.str(); - //} - } - else - { - break; - } - } - { - std::ostringstream os; - os << "End worker " << mpi_myself << std::endl; - std::cerr << os.str(); - } - MPI_Barrier(MPI_COMM_WORLD); - MPI_Finalize(); - return 0; - } -#endif Phreeqc phreeqc_instance; int return_value = phreeqc_instance.main_method(argc, argv); -#if defined(USE_MPI) - int task_no = 0; - MPI_Bcast(&task_no, 1, MPI_INT, 0, MPI_COMM_WORLD); - MPI_Barrier(MPI_COMM_WORLD); - MPI_Finalize(); - { - std::ostringstream os; - os << "End master " << mpi_myself << std::endl; - std::cerr << os.str(); - } -#endif return return_value; } //#define TEST_COPY @@ -999,22 +935,3 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, } #endif -#ifdef USE_MPI -int worker_tasks(int *task_number, void * cookie) -{ - Parallelizer *phreeqcrm_ptr = (Parallelizer *) cookie; - Phreeqc *phreeqc_ptr = phreeqcrm_ptr->GetPhreeqcPtr(); - if (*task_number == 1000) - { - phreeqcrm_ptr->Phreeqc2RM(phreeqc_ptr); - } - else if (*task_number == 1001) - { - phreeqcrm_ptr->RM2Phreeqc(phreeqc_ptr); - } - else - { - } - return 0; -} -#endif diff --git a/transport.cpp b/transport.cpp index af75ca0e..6cbd05e0 100644 --- a/transport.cpp +++ b/transport.cpp @@ -105,7 +105,6 @@ transport(void) ct[i].A_ij_il = 0.0; ct[i].Dz2c_il = 0.0; ct[i].mixf_il = 0.0; - ct[i].A_ij_il = 0.0; ct[i].J_ij_count_spec = -1; ct[i].J_ij_il_count_spec = -1; ct[i].v_m = NULL; @@ -900,6 +899,13 @@ transport(void) sol_D[i].spec = (struct spec *) free_check_null(sol_D[i].spec); } sol_D = (struct sol_D *) free_check_null(sol_D); + for (int i = 0; i < all_cells; i++) + { + ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); + ct[i].v_m_il = (struct V_M *) free_check_null(ct[i].v_m_il); + ct[i].J_ij = (struct J_ij *) free_check_null(ct[i].J_ij); + ct[i].J_ij_il = (struct J_ij *) free_check_null(ct[i].J_ij_il); + } ct = (struct CT *) free_check_null(ct); moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } @@ -2198,7 +2204,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dV_dcell && !find_current) goto dV_dcell2; - ct[icell].v_m = ct[icell].v_m_il = NULL; + ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); + ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); + //ct[icell].v_m = ct[icell].v_m_il = NULL; if (stagnant) { if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim From 964b1665eba48eff78973a9585f54074f4b892c5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Jan 2016 17:32:09 +0000 Subject: [PATCH 0972/1077] Initialize sol_D[l_cell_no].spec git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10728 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/transport.cpp b/transport.cpp index 6cbd05e0..2fe8e1a8 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1596,6 +1596,21 @@ fill_spec(int l_cell_no) sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); + { + for (int i = 0; i < count_species_list; i++) + { + sol_D[l_cell_no].spec[i].name = NULL; + sol_D[l_cell_no].spec[i].aq_name = NULL; + sol_D[l_cell_no].spec[i].type = -1; + sol_D[l_cell_no].spec[i].a = 0.0; + sol_D[l_cell_no].spec[i].lm = 0.0; + sol_D[l_cell_no].spec[i].lg = 0.0; + sol_D[l_cell_no].spec[i].c = 0.0; + sol_D[l_cell_no].spec[i].z = 0.0; + sol_D[l_cell_no].spec[i].Dwt = 0.0; + sol_D[l_cell_no].spec[i].erm_ddl = 0.0; + } + } sol_D[l_cell_no].tk_x = tk_x; @@ -1767,9 +1782,24 @@ fill_spec(int l_cell_no) (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (size_t)count_spec * sizeof(struct spec)); + if (sol_D[l_cell_no].spec == NULL) malloc_error(); - + { + for (int i = 0; i < count_spec; i++) + { + sol_D[l_cell_no].spec[i].name = NULL; + sol_D[l_cell_no].spec[i].aq_name = NULL; + sol_D[l_cell_no].spec[i].type = -1; + sol_D[l_cell_no].spec[i].a = 0.0; + sol_D[l_cell_no].spec[i].lm = 0.0; + sol_D[l_cell_no].spec[i].lg = 0.0; + sol_D[l_cell_no].spec[i].c = 0.0; + sol_D[l_cell_no].spec[i].z = 0.0; + sol_D[l_cell_no].spec[i].Dwt = 0.0; + sol_D[l_cell_no].spec[i].erm_ddl = 0.0; + } + } sol_D[l_cell_no].count_spec = count_spec; sol_D[l_cell_no].count_exch_spec = count_exch_spec; From 1fcb85d634bd223d547ad415bc19a99d14d8fc84 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Jan 2016 17:45:57 +0000 Subject: [PATCH 0973/1077] use space for cell_data git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10729 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 29726614..429eccda 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -661,12 +661,15 @@ read_transport(void) /* * Allocate space for cell_data */ - cell_data = (struct cell_data *) PHRQ_realloc(cell_data, - (size_t)(max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); - if (cell_data == NULL) - malloc_error(); - // initialize new cells + //cell_data = (struct cell_data *) PHRQ_realloc(cell_data, + // (size_t)(max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); + //if (cell_data == NULL) + // malloc_error(); int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; + space((void **) ((void *) &cell_data), all_cells_now, &cell_data_max_cells, + sizeof(struct cell_data)); + + // initialize new cells if (all_cells_now > all_cells) { for (int i = all_cells; i < all_cells_now; i++) From 24dd5ede7a5ad5b22c74dfab54afc3ff7c21994a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 22 Jan 2016 00:07:22 +0000 Subject: [PATCH 0974/1077] Working on valgrind uninitialized variables. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10730 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 1 + transport.cpp | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/global_structures.h b/global_structures.h index 10a0278b..4bd38c59 100644 --- a/global_structures.h +++ b/global_structures.h @@ -1038,6 +1038,7 @@ struct sol_D int count_exch_spec; /* number of exchange species */ LDBLE exch_total, x_max, tk_x; /* total moles of X-, max X- in transport step in sol_D[1], tk */ struct spec *spec; + int spec_size; }; struct J_ij { diff --git a/transport.cpp b/transport.cpp index 2fe8e1a8..4fa59914 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1596,6 +1596,7 @@ fill_spec(int l_cell_no) sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); + sol_D[l_cell_no].spec_size = count_species_list; { for (int i = 0; i < count_species_list; i++) { @@ -1785,20 +1786,24 @@ fill_spec(int l_cell_no) if (sol_D[l_cell_no].spec == NULL) malloc_error(); + { + if (count_spec > sol_D[l_cell_no].spec_size) { - for (int i = 0; i < count_spec; i++) - { - sol_D[l_cell_no].spec[i].name = NULL; - sol_D[l_cell_no].spec[i].aq_name = NULL; - sol_D[l_cell_no].spec[i].type = -1; - sol_D[l_cell_no].spec[i].a = 0.0; - sol_D[l_cell_no].spec[i].lm = 0.0; - sol_D[l_cell_no].spec[i].lg = 0.0; - sol_D[l_cell_no].spec[i].c = 0.0; - sol_D[l_cell_no].spec[i].z = 0.0; - sol_D[l_cell_no].spec[i].Dwt = 0.0; - sol_D[l_cell_no].spec[i].erm_ddl = 0.0; + for (int i = sol_D[l_cell_no].spec_size; i < count_spec; i++) + { + sol_D[l_cell_no].spec[i].name = NULL; + sol_D[l_cell_no].spec[i].aq_name = NULL; + sol_D[l_cell_no].spec[i].type = -1; + sol_D[l_cell_no].spec[i].a = 0.0; + sol_D[l_cell_no].spec[i].lm = 0.0; + sol_D[l_cell_no].spec[i].lg = 0.0; + sol_D[l_cell_no].spec[i].c = 0.0; + sol_D[l_cell_no].spec[i].z = 0.0; + sol_D[l_cell_no].spec[i].Dwt = 0.0; + sol_D[l_cell_no].spec[i].erm_ddl = 0.0; + } } + sol_D[l_cell_no].spec_size = count_spec; } sol_D[l_cell_no].count_spec = count_spec; sol_D[l_cell_no].count_exch_spec = count_exch_spec; From 891e33bf47fd824eb8a17bdeff765853ad7c6666 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 22 Jan 2016 01:34:20 +0000 Subject: [PATCH 0975/1077] More initialization git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10731 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/transport.cpp b/transport.cpp index 4fa59914..b3b57410 100644 --- a/transport.cpp +++ b/transport.cpp @@ -2579,6 +2579,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[i].Dzc = 0.0; ct[icell].v_m[i].Dzc_dl = 0.0; ct[icell].v_m[i].g_dl = 1.0; + ct[icell].v_m[i].b_ij = 0.0; ct[icell].v_m[i].o_c = 1; } ct[icell].Dz2c = ct[icell].Dz2c_dl = ct[icell].Dz2c_il = 0.0; @@ -2603,12 +2604,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m_il[i].grad = 0.0; ct[icell].v_m_il[i].D = 0.0; ct[icell].v_m_il[i].z = 0.0; + ct[icell].v_m_il[i].c = 0.0; ct[icell].v_m_il[i].zc = 0.0; ct[icell].v_m_il[i].Dz = 0.0; ct[icell].v_m_il[i].Dzc = 0.0; - //ct[icell].v_m_il[i].Dzc_dl = 0.0; - //ct[icell].v_m_il[i].g_dl = 1.0; - //ct[icell].v_m_il[i].o_c = 1; + ct[icell].v_m_il[i].Dzc_dl = 0.0; + ct[icell].v_m_il[i].g_dl = 1.0; + ct[icell].v_m_il[i].b_ij = 0.0; + ct[icell].v_m_il[i].o_c = 1; } } /* From 96e537f08de09a66587e7897948bafa790783c0e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 22 Jan 2016 15:42:59 +0000 Subject: [PATCH 0976/1077] Initialization, memory leak. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10732 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- structures.cpp | 10 ++++++++-- transport.cpp | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/structures.cpp b/structures.cpp index 1f4cbe6b..f78bc9cc 100644 --- a/structures.cpp +++ b/structures.cpp @@ -2071,6 +2071,9 @@ s_init(struct species *s_ptr) s_ptr->gfw = 0.0; s_ptr->z = 0.0; s_ptr->dw = 0.0; + s_ptr->dw_t = 0.0; + s_ptr->dw_a = 0.0; + s_ptr->dw_a_exp = 0.0; s_ptr->erm_ddl = 1.0; s_ptr->equiv = 0; s_ptr->alk = 0.0; @@ -2086,6 +2089,10 @@ s_init(struct species *s_ptr) { s_ptr->logk[i] = 0.0; } + for (i = 0; i < 10; i++) + { + s_ptr->Jones_Dole[i] = 0.0; + } /* VP: Density Start */ for (i = 0; i < 6; i++) { @@ -2109,8 +2116,6 @@ s_init(struct species *s_ptr) s_ptr->next_secondary = NULL; s_ptr->next_sys_total = NULL; s_ptr->check_equation = TRUE; - s_ptr->original_deltav_units = cm3_per_mol; - s_ptr->rxn = NULL; s_ptr->rxn_s = NULL; s_ptr->rxn_x = NULL; @@ -2124,6 +2129,7 @@ s_init(struct species *s_ptr) { s_ptr->dz[i] = 0.0; } + s_ptr->original_deltav_units = cm3_per_mol; return (OK); } diff --git a/transport.cpp b/transport.cpp index b3b57410..ad92f693 100644 --- a/transport.cpp +++ b/transport.cpp @@ -907,6 +907,10 @@ transport(void) ct[i].J_ij_il = (struct J_ij *) free_check_null(ct[i].J_ij_il); } ct = (struct CT *) free_check_null(ct); + for (int i = 0; i < count_elements; i++) + { + moles_added[i].name = (char *) free_check_null(moles_added[i].name); + } moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } //if (dV_dcell) @@ -2215,6 +2219,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) LDBLE g, g_i, g_j; char token[MAX_LENGTH], token1[MAX_LENGTH]; + dl_aq_i = dl_aq_j = 0.0; por_il12 = A_i = A_j =0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; dV = 0.0; From 8dc42fee7e77f7558f9847a3d93e99a253719021 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 25 Jan 2016 17:40:40 +0000 Subject: [PATCH 0977/1077] Tony fixed the memory problem. Will rerun Valgrind one more time. Revised Amm.dat git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10736 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/transport.cpp b/transport.cpp index ad92f693..d71ed2b2 100644 --- a/transport.cpp +++ b/transport.cpp @@ -192,7 +192,7 @@ transport(void) { input_error++; error_string = sformatf( - "Electrical Field (potential) was defined, but needs -mult_D, \n\t and is not possible with -stagnant or with advective flow."); + "Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with -stagnant or with advective flow."); error_msg(error_string, CONTINUE); free_check_null(sol_D); } @@ -337,8 +337,8 @@ transport(void) /* * Define stagnant/mobile mix structure, if not read explicitly. * - * With count_stag = 1, mix factors are calculated from exchange factor à - * (= exch_f), mobile é_m (= th_m) and immobile é_im (= th_im) porosity. + * With count_stag = 1, mix factors are calculated from exchange factor � + * (= exch_f), mobile �_m (= th_m) and immobile �_im (= th_im) porosity. * These variables are read under keyword TRANSPORT, after stagnant, in * structure stag_data. * MIX 'cell_no' in input file can be an alternative for the calculation here. @@ -926,7 +926,7 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; //, dx = 0; + LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; int i, l_nmix; LDBLE *m, *m1; m = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); @@ -1937,11 +1937,10 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) dVc = j_0e * current_cells[0].R; cell_data[1].potV = cell_data[0].potV + dVc; current_x = j_0e + current_cells[0].dif; - for (i1 = 1; i1 <= count_cells; i1 ++) + for (i1 = 1; i1 < count_cells; i1 ++) { dVc = current_cells[i1].R * (current_x - current_cells[i1].dif); - if (i1 < count_cells) - cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; + cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; } find_current = 0; continue; @@ -2517,7 +2516,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].A_ij_il = A_j * por_il12 / ((cell_data[1].por - por_il12) * interlayer_tortf); - A_j /= tort_j; A_i = A_j; } @@ -2887,7 +2885,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dl_aq_j) ct[icell].v_m[k].g_dl = (1 + g_j * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; if (dl_aq_i) - dum1 = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + dum1 = (1 + g_i * aq_i / dl_aq_i) * sol_D[jcell].spec[j].erm_ddl; } } b_i = A_i * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); @@ -3189,7 +3187,7 @@ dV_dcell2: for (i = 0; i < ct[icell].J_ij_count_spec; i++) { ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].D * ct[icell].v_m[i].grad; - if (abs(dV_dcell) < 1e-10 && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) + if (!dV_dcell && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * DDt; ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; From 95133f2b54cf156d8664d4e8009964f5bca3910c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 26 Jan 2016 21:39:37 +0000 Subject: [PATCH 0978/1077] Tony's changes. Added porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10737 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 2 + readtr.cpp | 104 ++++++++++++++++++++++++++--------- transport.cpp | 130 +++++++++++++++++++++++--------------------- 3 files changed, 149 insertions(+), 87 deletions(-) diff --git a/global_structures.h b/global_structures.h index 4bd38c59..495f3d99 100644 --- a/global_structures.h +++ b/global_structures.h @@ -1030,6 +1030,7 @@ struct spec LDBLE c; /* concentration for AQ, equivalent fraction for EX */ LDBLE z; /* charge number */ LDBLE Dwt; /* temperature corrected free water diffusion coefficient, m2/s */ + LDBLE dw_t; /* temperature factor for Dw */ LDBLE erm_ddl; /* enrichment factor in ddl */ }; struct sol_D @@ -1037,6 +1038,7 @@ struct sol_D int count_spec; /* number of aqueous + exchange species */ int count_exch_spec; /* number of exchange species */ LDBLE exch_total, x_max, tk_x; /* total moles of X-, max X- in transport step in sol_D[1], tk */ + LDBLE viscos_f; /* (tk_x * viscos_0_25) / (298 * viscos) */ struct spec *spec; int spec_size; }; diff --git a/readtr.cpp b/readtr.cpp index 429eccda..ff25fd56 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -36,12 +36,12 @@ read_transport(void) */ char *ptr; int i, j, l; - int count_length, count_disp, count_punch, count_print; - int count_length_alloc, count_disp_alloc; + int count_length, count_disp, count_punch, count_print, count_por; + int count_length_alloc, count_disp_alloc, count_por_alloc; char token[MAX_LENGTH]; char *description; int n_user, n_user_end; - LDBLE *length, *disp; + LDBLE *length, *disp, *pors; int *punch_temp, *print_temp; int return_value, opt, opt_save; char *next_char, *next_char_save; @@ -89,9 +89,11 @@ read_transport(void) "warnings", /* 38 */ "thermal_diffusion", /* 39 */ "multi_d", /* 40 */ - "interlayer_d" /* 41 */ + "interlayer_d", /* 41 */ + "porosities", /* 42 */ + "porosity" /* 43 */ }; - int count_opt_list = 42; + int count_opt_list = 44; strcpy(file_name, "phreeqc.dmp"); /* @@ -107,17 +109,21 @@ read_transport(void) } else old_cells = count_cells; - count_length = count_disp = count_punch = count_print = 0; + count_length = count_disp = count_punch = count_print = count_por = 0; length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); if (length == NULL) malloc_error(); - disp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + disp = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); if (disp == NULL) malloc_error(); - punch_temp = (int *) PHRQ_malloc(sizeof(int)); + pors = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); + if (pors == NULL) + malloc_error(); + + punch_temp = (int *)PHRQ_malloc(sizeof(int)); if (punch_temp == NULL) malloc_error(); @@ -125,7 +131,7 @@ read_transport(void) if (print_temp == NULL) malloc_error(); - count_length_alloc = count_disp_alloc = 1; + count_length_alloc = count_disp_alloc = count_por_alloc = 1; transport_start = 1; /* * Read transport number (not currently used) @@ -629,6 +635,18 @@ read_transport(void) } opt_save = OPTION_DEFAULT; break; + case 42: /* porosities */ + case 43: /* porosity */ + if (read_line_LDBLEs + (next_char, &pors, &count_por, + &count_por_alloc) == ERROR) + { + input_error++; + error_msg("Reading porosities in TRANSPORT keyword.\n", + CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; } if (return_value == EOF || return_value == KEYWORD) break; @@ -641,6 +659,8 @@ read_transport(void) max_cells = count_length; if (count_disp > max_cells) max_cells = count_disp; + if (count_por > max_cells) + max_cells = count_por; if (max_cells > count_cells) { if (max_cells == count_length) @@ -650,21 +670,24 @@ read_transport(void) count_length); warning_msg(token); } + else if (max_cells == count_disp) + { + sprintf(token, + "Number of cells is increased to number of dispersivities %d.", + count_disp); + warning_msg(token); + } else { sprintf(token, - "Number of cells is increased to number of dispersivities %d.", - count_disp); + "Number of cells is increased to number of porosities %d.", + count_por); warning_msg(token); } } /* * Allocate space for cell_data */ - //cell_data = (struct cell_data *) PHRQ_realloc(cell_data, - // (size_t)(max_cells * (1 + stag_data->count_stag) + 2) * sizeof(struct cell_data)); - //if (cell_data == NULL) - // malloc_error(); int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; space((void **) ((void *) &cell_data), all_cells_now, &cell_data_max_cells, sizeof(struct cell_data)); @@ -734,7 +757,7 @@ read_transport(void) if (old_cells < max_cells) { error_string = sformatf( - "No dispersivities were read; disp = 0 assumed."); + "No dispersivities were read; disp = 0 assumed."); warning_msg(error_string); for (i = 1; i <= max_cells; i++) cell_data[i].disp = 0.0; @@ -747,13 +770,46 @@ read_transport(void) if (max_cells > count_disp) { error_string = sformatf( - "Dispersivities were read for %d cells. Last value is used till cell %d.", - count_disp, max_cells); + "Dispersivities were read for %d cells. Last value is used till cell %d.", + count_disp, max_cells); warning_msg(error_string); for (i = count_disp; i <= max_cells; i++) cell_data[i + 1].disp = disp[count_disp - 1]; } } +/* + * Fill in data for porosities + */ + if (count_por == 0) + { + if (old_cells < max_cells && multi_Dflag) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + if (multi_Dpor > 1e-10) + error_string = sformatf( + "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); + else + error_string = sformatf( + "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); + warning_msg(error_string); + for (i = 1; i <= max_cells; i++) + cell_data[i].por = multi_Dpor; + } + } + else + { + for (i = 1; i <= count_por; i++) + cell_data[i].por = pors[i - 1]; + if (max_cells > count_por) + { + error_string = sformatf( + "Porosities were read for %d cells. Last value is used till cell %d.", + count_por, max_cells); + warning_msg(error_string); + for (i = count_por; i <= max_cells; i++) + cell_data[i + 1].por = pors[count_por - 1]; + } + } count_cells = max_cells; /* * Account for stagnant cells @@ -825,11 +881,11 @@ read_transport(void) error_msg(error_string, CONTINUE); } - for (i = 1; i < all_cells; i++) + for (i = 0; i < all_cells; i++) { - multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + //multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - cell_data[i].por = multi_Dpor; + //cell_data[i].por = multi_Dpor; cell_data[i].por_il = interlayer_Dpor; } /* @@ -871,7 +927,7 @@ read_transport(void) */ if (simul_tr > 1) { - if ((count_length == 0) && (count_disp == 0)) + if ((count_length == 0) && (count_disp == 0) && (count_por == 0)) dup_print("Column data retained from former run", TRUE); } /* @@ -963,9 +1019,7 @@ read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) if ((*count_d) + n > (*count_alloc)) { *count_alloc *= 2; - *d = (LDBLE *) PHRQ_realloc(*d, - (size_t) (*count_alloc) * - sizeof(LDBLE)); + *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); if (*d == NULL) malloc_error(); } diff --git a/transport.cpp b/transport.cpp index d71ed2b2..596eb28e 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1613,6 +1613,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[i].c = 0.0; sol_D[l_cell_no].spec[i].z = 0.0; sol_D[l_cell_no].spec[i].Dwt = 0.0; + sol_D[l_cell_no].spec[i].dw_t = 0.0; sol_D[l_cell_no].spec[i].erm_ddl = 0.0; } } @@ -1650,6 +1651,7 @@ fill_spec(int l_cell_no) */ temp_factor *= tk_x * viscos_0_25 / (298.15 * viscos); temp_il_factor *= tk_x * viscos_0_25 / (298.15 * viscos); + sol_D[l_cell_no].viscos_f = tk_x * viscos_0_25 / (298.15 * viscos); count_spec = count_exch_spec = 0; /* @@ -1711,12 +1713,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].type = EX; sol_D[l_cell_no].spec[count_spec].c = dum2; sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg - log10(dum); - sol_D[l_cell_no].spec[count_spec].a = dum2 * pow(10, - sol_D - [l_cell_no]. - spec - [count_spec]. - lg); + sol_D[l_cell_no].spec[count_spec].a = dum2 * pow(10, sol_D[l_cell_no].spec[count_spec].lg); sol_D[l_cell_no].exch_total = master_ptr->total; if (transport_step == 0 && !x_max_done) { @@ -1741,10 +1738,13 @@ fill_spec(int l_cell_no) default_Dw * temp_il_factor; else { - if (s_ptr->dw_t) - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * exp(s_ptr2->dw_t / 298.15 - s_ptr2->dw_t / tk_x) * temp_il_factor; + if (s_ptr2->dw_t) + { + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * + exp(s_ptr2->dw_t / 298.15 - s_ptr2->dw_t / tk_x) * temp_il_factor; + sol_D[l_cell_no].spec[count_spec].dw_t = s_ptr2->dw_t; + } else - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * temp_il_factor; } count_exch_spec++; @@ -1765,19 +1765,20 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg; sol_D[l_cell_no].spec[count_spec].z = s_ptr->z; if (s_ptr->dw == 0) - sol_D[l_cell_no].spec[count_spec].Dwt = - default_Dw * temp_factor; + sol_D[l_cell_no].spec[count_spec].Dwt = default_Dw * temp_factor; else { if (s_ptr->dw_t) - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * temp_factor; + { + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * + exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * temp_factor; + sol_D[l_cell_no].spec[count_spec].dw_t = s_ptr->dw_t; + } else sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * temp_factor; } - if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > - diffc_max) - diffc_max = - sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); + if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) + diffc_max = sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); sol_D[l_cell_no].spec[count_spec].erm_ddl = s_ptr->erm_ddl; count_spec++; @@ -1804,6 +1805,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[i].c = 0.0; sol_D[l_cell_no].spec[i].z = 0.0; sol_D[l_cell_no].spec[i].Dwt = 0.0; + sol_D[l_cell_no].spec[i].dw_t = 0.0; sol_D[l_cell_no].spec[i].erm_ddl = 0.0; } } @@ -2627,9 +2629,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) while (i < i_max || j < j_max) { if (j == j_max - || (i < i_max - && strcmp(sol_D[icell].spec[i].name, - sol_D[jcell].spec[j].name) < 0)) + || (i < i_max + && strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) < 0)) { /* species 'name' is only in icell */ if (il_calcs && sol_D[icell].spec[i].type == EX) @@ -2746,22 +2747,30 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) dum2 = (1 + g_j * aq_j / dl_aq_j) * sol_D[icell].spec[i].erm_ddl; } } - b_i = A_i * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_i = A_i * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); b_j = A_j * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); - if (icell == 0) - ct[icell].v_m[k].b_ij = b_j; - else if (icell == count_cells) + if (icell == count_cells) ct[icell].v_m[k].b_ij = b_i; else - ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - - ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; + { + if (sol_D[icell].tk_x == sol_D[jcell].tk_x) + b_j *= sol_D[icell].spec[i].Dwt; + else + { + dum2 = sol_D[icell].spec[i].Dwt / sol_D[icell].viscos_f; + dum2 *= exp(sol_D[icell].spec[i].dw_t / sol_D[jcell].tk_x - sol_D[icell].spec[i].dw_t / sol_D[icell].tk_x); + dum2 *= sol_D[jcell].viscos_f; + b_j *= dum2; + } + if (icell == 0) + ct[icell].v_m[k].b_ij = b_j; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + } ct[icell].v_m[k].c = c1; ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; k++; } } @@ -2851,7 +2860,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } g_i = g_j = dum1 = 0; - if (ct[icell].dl_s > 0) + if (ct[jcell].dl_s > 0) { if (ct[icell].v_m[k].z) { @@ -2889,21 +2898,29 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } b_i = A_i * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); - b_j = A_j * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); + b_j = A_j * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); if (icell == 0) ct[icell].v_m[k].b_ij = b_j; - else if (icell == count_cells) - ct[icell].v_m[k].b_ij = b_i; else - ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - - ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; + { + if (sol_D[icell].tk_x == sol_D[jcell].tk_x) + b_j *= sol_D[jcell].spec[j].Dwt; + else + { + dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f; + dum2 *= exp(sol_D[jcell].spec[j].dw_t / sol_D[icell].tk_x - sol_D[jcell].spec[j].dw_t / sol_D[jcell].tk_x); + dum2 *= sol_D[icell].viscos_f; + b_i *= dum2; + } + if (icell == count_cells) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + } ct[icell].v_m[k].c = c2; ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; k++; } } @@ -2936,11 +2953,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (stagnant) { ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) - ct[icell].v_m[k].D = 0.0; - else - ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - + ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; ct[icell].v_m[k].z = sol_D[icell].spec[i].z; ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); @@ -3081,8 +3094,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } } - b_i = A_i * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); - b_j = A_j * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + b_i = A_i * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_j = A_j * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); if (icell == 0) ct[icell].v_m[k].b_ij = b_j; else if (icell == count_cells) @@ -3090,16 +3103,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - if (sol_D[icell].spec[i].Dwt == 0 || sol_D[jcell].spec[j].Dwt == 0) - ct[icell].v_m[k].D = 0.0; - else - ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - ct[icell].v_m[k].c = c1 + c2; ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * ct[icell].v_m[k].c; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; if (fabs(ddlm) > 1e-10) @@ -3130,9 +3136,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (!ct[icell].v_m[i].z) continue; current_cells[icell].ele -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * - ct[icell].v_m[i].zc * ct[icell].v_m[i].D * dum; + ct[icell].v_m[i].zc * dum; current_cells[icell].dif -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * - ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + ct[icell].v_m[i].grad; } current_cells[icell].R = dV_dcell / current_cells[icell].ele; sum_R += current_cells[icell].R; @@ -3182,13 +3188,13 @@ dV_dcell2: for (i = 0; i < ct[icell].J_ij_count_spec; i++) { if (ct[icell].v_m[i].z) - Sum_zM += ct[icell].v_m[i].b_ij * ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; + Sum_zM += ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * ct[icell].v_m[i].grad; } for (i = 0; i < ct[icell].J_ij_count_spec; i++) { - ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].grad; if (!dV_dcell && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) - ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; + ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].zc / ct[icell].Dz2c; ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * DDt; ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; } @@ -3205,9 +3211,9 @@ dV_dcell2: if (!ct[icell].v_m[i].z) continue; current_cells[icell].ele -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * - ct[icell].v_m[i].zc * ct[icell].v_m[i].D * dum; + ct[icell].v_m[i].zc * dum; current_cells[icell].dif -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * - ct[icell].v_m[i].D * ct[icell].v_m[i].grad; + ct[icell].v_m[i].grad; } dV *= (current_x - current_cells[icell].dif) / current_cells[icell].ele; dum = dV * F_Re3 / tk_x2; @@ -3215,7 +3221,7 @@ dV_dcell2: { if (!ct[icell].v_m[i].z) continue; - ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].D * ct[icell].v_m[i].b_ij * + ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].zc * dum * DDt; } current_A = current_x * F_C_MOL; From f5ea53e0e401b48805b5e79658888f19a405c07c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 27 Jan 2016 01:17:30 +0000 Subject: [PATCH 0979/1077] Added porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10738 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 129517ff..8b13bb1b 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -36,12 +36,12 @@ read_transport(void) */ char *ptr; int i, j, l; - int count_length, count_disp, count_punch, count_print; - int count_length_alloc, count_disp_alloc; + int count_length, count_disp, count_punch, count_print, count_por; + int count_length_alloc, count_disp_alloc, count_por_alloc; char token[MAX_LENGTH]; char *description; int n_user, n_user_end; - LDBLE *length, *disp; + LDBLE *length, *disp, *pors; int *punch_temp, *print_temp; int return_value, opt, opt_save; char *next_char, *next_char_save; @@ -89,9 +89,11 @@ read_transport(void) "warnings", /* 38 */ "thermal_diffusion", /* 39 */ "multi_d", /* 40 */ - "interlayer_d" /* 41 */ + "interlayer_d", /* 41 */ + "porosities", /* 42 */ + "porosity" /* 43 */ }; - int count_opt_list = 42; + int count_opt_list = 44; strcpy(file_name, "phreeqc.dmp"); /* @@ -107,17 +109,21 @@ read_transport(void) } else old_cells = count_cells; - count_length = count_disp = count_punch = count_print = 0; + count_length = count_disp = count_punch = count_print = count_por = 0; length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); if (length == NULL) malloc_error(); - disp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + disp = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); if (disp == NULL) malloc_error(); - punch_temp = (int *) PHRQ_malloc(sizeof(int)); + pors = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); + if (pors == NULL) + malloc_error(); + + punch_temp = (int *)PHRQ_malloc(sizeof(int)); if (punch_temp == NULL) malloc_error(); @@ -125,7 +131,7 @@ read_transport(void) if (print_temp == NULL) malloc_error(); - count_length_alloc = count_disp_alloc = 1; + count_length_alloc = count_disp_alloc = count_por_alloc = 1; transport_start = 1; /* * Read transport number (not currently used) @@ -629,6 +635,18 @@ read_transport(void) } opt_save = OPTION_DEFAULT; break; + case 42: /* porosities */ + case 43: /* porosity */ + if (read_line_LDBLEs + (next_char, &pors, &count_por, + &count_por_alloc) == ERROR) + { + input_error++; + error_msg("Reading porosities in TRANSPORT keyword.\n", + CONTINUE); + } + opt_save = OPTION_DEFAULT; + break; } if (return_value == EOF || return_value == KEYWORD) break; @@ -641,6 +659,8 @@ read_transport(void) max_cells = count_length; if (count_disp > max_cells) max_cells = count_disp; + if (count_por > max_cells) + max_cells = count_por; if (max_cells > count_cells) { if (max_cells == count_length) @@ -650,11 +670,18 @@ read_transport(void) count_length); warning_msg(token); } + else if (max_cells == count_disp) + { + sprintf(token, + "Number of cells is increased to number of dispersivities %d.", + count_disp); + warning_msg(token); + } else { sprintf(token, - "Number of cells is increased to number of dispersivities %d.", - count_disp); + "Number of cells is increased to number of porosities %d.", + count_por); warning_msg(token); } } @@ -730,7 +757,7 @@ read_transport(void) if (old_cells < max_cells) { error_string = sformatf( - "No dispersivities were read; disp = 0 assumed."); + "No dispersivities were read; disp = 0 assumed."); warning_msg(error_string); for (i = 0; i < max_cells; i++) cell_data[i].disp = 0.0; @@ -743,13 +770,46 @@ read_transport(void) if (max_cells > count_disp) { error_string = sformatf( - "Dispersivities were read for %d cells. Last value is used till cell %d.", - count_disp, max_cells); + "Dispersivities were read for %d cells. Last value is used till cell %d.", + count_disp, max_cells); warning_msg(error_string); for (i = count_disp - 1; i < max_cells; i++) cell_data[i].disp = disp[count_disp - 1]; } } +/* + * Fill in data for porosities + */ + if (count_por == 0) + { + if (old_cells < max_cells && multi_Dflag) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + if (multi_Dpor > 1e-10) + error_string = sformatf( + "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); + else + error_string = sformatf( + "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); + warning_msg(error_string); + for (i = 0; i < max_cells; i++) + cell_data[i].por = multi_Dpor; + } + } + else + { + for (i = 0; i < count_por; i++) + cell_data[i].por = pors[i]; + if (max_cells > count_por) + { + error_string = sformatf( + "Porosities were read for %d cells. Last value is used till cell %d.", + count_por, max_cells); + warning_msg(error_string); + for (i = count_por - 1; i < max_cells; i++) + cell_data[i].por = pors[count_por - 1]; + } + } count_cells = max_cells; /* * Account for stagnant cells @@ -823,9 +883,9 @@ read_transport(void) } for (i = 0; i < max_cells; i++) { - multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + //multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - cell_data[i].por = multi_Dpor; + //cell_data[i].por = multi_Dpor; cell_data[i].por_il = interlayer_Dpor; } /* @@ -867,7 +927,7 @@ read_transport(void) */ if (simul_tr > 1) { - if ((count_length == 0) && (count_disp == 0)) + if ((count_length == 0) && (count_disp == 0) && (count_por == 0)) dup_print("Column data retained from former run", TRUE); } /* From 7c56b9195ea8d412285fc9e6d5e1a96a0c2fcaa7 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 27 Jan 2016 01:49:10 +0000 Subject: [PATCH 0980/1077] free pors. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10739 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/readtr.cpp b/readtr.cpp index ff25fd56..a917aac3 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -977,6 +977,7 @@ read_transport(void) */ length = (LDBLE *) free_check_null(length); disp = (LDBLE *) free_check_null(disp); + pors = (LDBLE *) free_check_null(pors); punch_temp = (int *) free_check_null(punch_temp); print_temp = (int *) free_check_null(print_temp); From a6390ed8c296dcbe8d05ec8c225c1a182c970ec1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 27 Jan 2016 01:53:27 +0000 Subject: [PATCH 0981/1077] free pors git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10740 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/readtr.cpp b/readtr.cpp index 8b13bb1b..dd2ec5e1 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -977,6 +977,7 @@ read_transport(void) */ length = (LDBLE *) free_check_null(length); disp = (LDBLE *) free_check_null(disp); + pors = (LDBLE *) free_check_null(pors); punch_temp = (int *) free_check_null(punch_temp); print_temp = (int *) free_check_null(print_temp); From 4cd0224ee557b698c99ec4fb5efe34c27054457a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 27 Jan 2016 23:06:21 +0000 Subject: [PATCH 0982/1077] Temporary fix for Jenkins. Need Tony's fix for porosity of stagnant zone if porosity defined for mobile zone. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10755 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index dd2ec5e1..984a041a 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -703,7 +703,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = 0.1; + cell_data[i].por = -0.1; //Fix for Jenkins !!!!!!!!!!!! cell_data[i].por_il = 0.01; cell_data[i].punch = FALSE; cell_data[i].print = FALSE; @@ -883,9 +883,12 @@ read_transport(void) } for (i = 0; i < max_cells; i++) { - //multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! + if (cell_data[i].por < 0) + { + cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! + } interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - //cell_data[i].por = multi_Dpor; cell_data[i].por_il = interlayer_Dpor; } /* From b8ee7f645c89e01b9e29584c8bb6f9ba4b770245 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 27 Jan 2016 23:57:15 +0000 Subject: [PATCH 0983/1077] Another temporary fix. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10756 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 984a041a..cb286e04 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -703,7 +703,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = -0.1; //Fix for Jenkins !!!!!!!!!!!! + cell_data[i].por = 0.1; //Fix for Jenkins !!!!!!!!!!!! cell_data[i].por_il = 0.01; cell_data[i].punch = FALSE; cell_data[i].print = FALSE; @@ -884,7 +884,7 @@ read_transport(void) for (i = 0; i < max_cells; i++) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! - if (cell_data[i].por < 0) + //if (cell_data[i].por < 0) { cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! } From 72991f1acc2604ddbf787ec6cc2a3979da5fc247 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 28 Jan 2016 21:24:32 +0000 Subject: [PATCH 0984/1077] First fix of day. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10758 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 74 +++++++++++++++++++++++++-------------------------- transport.cpp | 28 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index a917aac3..9f495b78 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -782,7 +782,7 @@ read_transport(void) */ if (count_por == 0) { - if (old_cells < max_cells && multi_Dflag) + if (old_cells <= max_cells && multi_Dflag) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); if (multi_Dpor > 1e-10) @@ -792,23 +792,49 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = 1; i <= max_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } else { - for (i = 1; i <= count_por; i++) - cell_data[i].por = pors[i - 1]; - if (max_cells > count_por) + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { error_string = sformatf( - "Porosities were read for %d cells. Last value is used till cell %d.", - count_por, max_cells); + "Mobile porosities were read, but mobile/immobile porosity was also defined in -stagnant. Using the values from -stagnant for mobile/immobile exchange and tortuosity factors."); warning_msg(error_string); - for (i = count_por; i <= max_cells; i++) - cell_data[i + 1].por = pors[count_por - 1]; + for (i = 1; i <= max_cells; i++) + cell_data[i].por = stag_data->th_m; + for (i++; i <= 2 * max_cells + 1; i++) + cell_data[i].por = stag_data->th_im; } + else + { + for (i = 1; i <= count_por; i++) + cell_data[i].por = pors[i - 1]; + if (max_cells > count_por) + { + error_string = sformatf( + "Porosities were read for %d cells. Last value is used till cell %d.", + count_por, max_cells); + warning_msg(error_string); + for (i = count_por; i <= max_cells; i++) + cell_data[i + 1].por = pors[count_por - 1]; + } + } + } + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + + } + for (i = 0; i < all_cells; i++) + { + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por_il = interlayer_Dpor; } count_cells = max_cells; /* @@ -870,24 +896,6 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].print = TRUE; -/* - * Fill in porosities - */ - if (interlayer_Dflag && !multi_Dflag) - { - input_error++; - error_string = sformatf( - "-multi_D must be defined, when -interlayer_D true."); - error_msg(error_string, CONTINUE); - - } - for (i = 0; i < all_cells; i++) - { - //multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); - interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - //cell_data[i].por = multi_Dpor; - cell_data[i].por_il = interlayer_Dpor; - } /* * Calculate dump_modulus */ @@ -976,8 +984,8 @@ read_transport(void) * free storage for length, disp, punch */ length = (LDBLE *) free_check_null(length); - disp = (LDBLE *) free_check_null(disp); - pors = (LDBLE *) free_check_null(pors); + disp = (LDBLE *)free_check_null(disp); + pors = (LDBLE *)free_check_null(pors); punch_temp = (int *) free_check_null(punch_temp); print_temp = (int *) free_check_null(print_temp); @@ -1270,10 +1278,6 @@ dump_cpp(void) fs << token; sprintf(token, "\t-punch_cells"); fs << token; - //if (stag_data->count_stag > 0) - // j = 1 + (1 + stag_data->count_stag) * count_cells; - //else - // j = count_cells; l = 0; for (int i = 0; i < all_cells; i++) { @@ -1292,10 +1296,6 @@ dump_cpp(void) fs << token; sprintf(token, "\t-print_cells"); fs << token; - //if (stag_data->count_stag > 0) - // j = 1 + (1 + stag_data->count_stag) * count_cells; - //else - // j = count_cells; l = 0; for (int i = 0; i < all_cells; i++) { diff --git a/transport.cpp b/transport.cpp index 596eb28e..e0ae1be2 100644 --- a/transport.cpp +++ b/transport.cpp @@ -337,8 +337,8 @@ transport(void) /* * Define stagnant/mobile mix structure, if not read explicitly. * - * With count_stag = 1, mix factors are calculated from exchange factor � - * (= exch_f), mobile �_m (= th_m) and immobile �_im (= th_im) porosity. + * With count_stag = 1, mix factors are calculated from exchange factor alpha + * (= exch_f), mobile th_m and immobile th_im porosity. * These variables are read under keyword TRANSPORT, after stagnant, in * structure stag_data. * MIX 'cell_no' in input file can be an alternative for the calculation here. @@ -1588,7 +1588,7 @@ fill_spec(int l_cell_no) struct master *master_ptr; LDBLE dum, dum2; LDBLE lm; - LDBLE por, por_il, temp_factor, temp_il_factor, viscos; + LDBLE por, por_il, viscos_f, viscos_il_f, viscos; bool x_max_done = false; s_ptr2 = NULL; @@ -1620,7 +1620,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].tk_x = tk_x; - temp_factor = temp_il_factor = 1.0; + viscos_f = viscos_il_f = 1.0; if (l_cell_no == 0) { por = cell_data[1].por; @@ -1637,10 +1637,10 @@ fill_spec(int l_cell_no) por_il = cell_data[l_cell_no].por_il; } if (por < multi_Dpor_lim) - por = temp_factor = 0.0; + por = viscos_f = 0.0; if (por_il < interlayer_Dpor_lim) - por_il = temp_il_factor = 0.0; + por_il = viscos_il_f = 0.0; /* * correct diffusion coefficient for temperature and viscosity, D_T = D_298 * Tk * viscos_298 / (298 * viscos) * modify viscosity effect: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15), SC data from Robinson and Stokes, 1959 @@ -1649,8 +1649,8 @@ fill_spec(int l_cell_no) /* * put temperature factor in por_factor which corrects for porous medium... */ - temp_factor *= tk_x * viscos_0_25 / (298.15 * viscos); - temp_il_factor *= tk_x * viscos_0_25 / (298.15 * viscos); + viscos_f *= tk_x * viscos_0_25 / (298.15 * viscos); + viscos_il_f *= tk_x * viscos_0_25 / (298.15 * viscos); sol_D[l_cell_no].viscos_f = tk_x * viscos_0_25 / (298.15 * viscos); count_spec = count_exch_spec = 0; @@ -1735,17 +1735,17 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].z = s_ptr2->z; if (s_ptr2->dw == 0) sol_D[l_cell_no].spec[count_spec].Dwt = - default_Dw * temp_il_factor; + default_Dw * viscos_il_f; else { if (s_ptr2->dw_t) { sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * - exp(s_ptr2->dw_t / 298.15 - s_ptr2->dw_t / tk_x) * temp_il_factor; + exp(s_ptr2->dw_t / 298.15 - s_ptr2->dw_t / tk_x) * viscos_il_f; sol_D[l_cell_no].spec[count_spec].dw_t = s_ptr2->dw_t; } else - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * temp_il_factor; + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr2->dw * viscos_il_f; } count_exch_spec++; count_spec++; @@ -1765,17 +1765,17 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec[count_spec].lg = s_ptr->lg; sol_D[l_cell_no].spec[count_spec].z = s_ptr->z; if (s_ptr->dw == 0) - sol_D[l_cell_no].spec[count_spec].Dwt = default_Dw * temp_factor; + sol_D[l_cell_no].spec[count_spec].Dwt = default_Dw * viscos_f; else { if (s_ptr->dw_t) { sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * - exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * temp_factor; + exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * viscos_f; sol_D[l_cell_no].spec[count_spec].dw_t = s_ptr->dw_t; } else - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * temp_factor; + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * viscos_f; } if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); From 279acc25a1ba81eec4f66bdd53d7650dd02e3e9f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Jan 2016 17:06:45 +0000 Subject: [PATCH 0985/1077] Merging Tony's changes for reading porosity. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10762 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 65 +++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index cb286e04..3351ff1a 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -782,7 +782,7 @@ read_transport(void) */ if (count_por == 0) { - if (old_cells < max_cells && multi_Dflag) + if (old_cells <= max_cells && multi_Dflag) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); if (multi_Dpor > 1e-10) @@ -792,23 +792,49 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = 0; i < max_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } else { - for (i = 0; i < count_por; i++) - cell_data[i].por = pors[i]; - if (max_cells > count_por) + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { error_string = sformatf( - "Porosities were read for %d cells. Last value is used till cell %d.", - count_por, max_cells); + "Mobile porosities were read, but mobile/immobile porosity was also defined in -stagnant. Using the values from -stagnant for mobile/immobile exchange and tortuosity factors."); warning_msg(error_string); - for (i = count_por - 1; i < max_cells; i++) - cell_data[i].por = pors[count_por - 1]; + for (i = 1; i <= max_cells; i++) + cell_data[i].por = stag_data->th_m; + for (i++; i <= 2 * max_cells + 1; i++) + cell_data[i].por = stag_data->th_im; } + else + { + for (i = 0; i < count_por; i++) + cell_data[i].por = pors[i]; + if (max_cells > count_por) + { + error_string = sformatf( + "Porosities were read for %d cells. Last value is used till cell %d.", + count_por, max_cells); + warning_msg(error_string); + for (i = count_por - 1; i <= max_cells; i++) + cell_data[i].por = pors[count_por - 1]; + } + } + } + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + + } + for (i = 0; i < all_cells; i++) + { + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por_il = interlayer_Dpor; } count_cells = max_cells; /* @@ -870,27 +896,6 @@ read_transport(void) else if (simul_tr == 1) for (i = 0; i < max_cells; i++) cell_data[i].print = TRUE; -/* - * Fill in porosities - */ - if (interlayer_Dflag && !multi_Dflag) - { - input_error++; - error_string = sformatf( - "-multi_D must be defined, when -interlayer_D true."); - error_msg(error_string, CONTINUE); - - } - for (i = 0; i < max_cells; i++) - { - multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! - //if (cell_data[i].por < 0) - { - cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! - } - interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - cell_data[i].por_il = interlayer_Dpor; - } /* * Calculate dump_modulus */ From 0bd85c160452be69b8e4f07c037dcb5f79bc9f59 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 29 Jan 2016 17:51:02 +0000 Subject: [PATCH 0986/1077] reverting to old porosity definition. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10764 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/readtr.cpp b/readtr.cpp index 3351ff1a..2cd216c3 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -896,6 +896,30 @@ read_transport(void) else if (simul_tr == 1) for (i = 0; i < max_cells; i++) cell_data[i].print = TRUE; +//#define TONY +#if !defined(TONY) +/* + * Fill in porosities + */ + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + + } + for (i = 0; i < max_cells; i++) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! + //if (cell_data[i].por < 0) + { + cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! + } + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por_il = interlayer_Dpor; + } +#endif /* * Calculate dump_modulus */ From 383227282af49d709866e4634be17da872cef083 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 1 Feb 2016 15:50:11 +0000 Subject: [PATCH 0987/1077] Tony's fixes git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10771 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 73 ++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/transport.cpp b/transport.cpp index e0ae1be2..545a9fcd 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" @@ -909,7 +909,7 @@ transport(void) ct = (struct CT *) free_check_null(ct); for (int i = 0; i < count_elements; i++) { - moles_added[i].name = (char *) free_check_null(moles_added[i].name); + moles_added[i].name = (char *)free_check_null(moles_added[i].name); } moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } @@ -1770,7 +1770,7 @@ fill_spec(int l_cell_no) { if (s_ptr->dw_t) { - sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15) * viscos_f; sol_D[l_cell_no].spec[count_spec].dw_t = s_ptr->dw_t; } @@ -1841,14 +1841,14 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) * NOTE. Define the water content of stagnant cells relative to the * mobile cell (with, for example, 1 kg water) * Define properties of each interface only 1 time with MIX. - * If an electrical field is applied (dV_dcell != 0), the currents j_i = current_cells[i].ele + dif (C * s) - are calculated for all cells. Then the ele part from cell 0 -> 1 is calculated: - current_x = (j_0d + j_0e) = j_0 = j_1 = ... = j_i - j_0e * (R0 + R1 + ...) + (j_0d - j_1d) * R1 + ... + (j_0d - j_id) * Ri = Vtot - or - j_0e * Sum_R + Sum_Rd = Vtot. - Ri = dV_dcell / j_ie, the relative cell resistance. - Solve j_0e, find (V1 - V0) = j_0e * R0. j_1e = current_x - j_1d, find (V2 - V1) = j_1e * R1, etc. + * If an electrical field is applied (dV_dcell != 0), the currents j_i = current_cells[i].ele + dif (C * s) + are calculated for all cells. Then the ele part from cell 0 -> 1 is calculated: + current_x = (j_0d + j_0e) = j_0 = j_1 = ... = j_i + j_0e * (R0 + R1 + ...) + (j_0d - j_1d) * R1 + ... + (j_0d - j_id) * Ri = Vtot + or + j_0e * Sum_R + Sum_Rd = Vtot. + Ri = dV_dcell / j_ie, the relative cell resistance. + Solve j_0e, find (V1 - V0) = j_0e * R0. j_1e = current_x - j_1d, find (V2 - V1) = j_1e * R1, etc. */ int icell, jcell, i, l, n, length, length2, il_calcs; int i1, loop_f_c; @@ -1939,7 +1939,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) dVc = j_0e * current_cells[0].R; cell_data[1].potV = cell_data[0].potV + dVc; current_x = j_0e + current_cells[0].dif; - for (i1 = 1; i1 < count_cells; i1 ++) + for (i1 = 1; i1 < count_cells; i1++) { dVc = current_cells[i1].R * (current_x - current_cells[i1].dif); cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; @@ -2102,7 +2102,6 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) if (il_calcs) ct[i].J_ij_il = (struct J_ij *) free_check_null(ct[i].J_ij_il); ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); - } return (OK); } @@ -2221,7 +2220,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) char token[MAX_LENGTH], token1[MAX_LENGTH]; dl_aq_i = dl_aq_j = 0.0; - por_il12 = A_i = A_j =0.0; + por_il12 = A_i = A_j = 0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; dV = 0.0; @@ -2629,7 +2628,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) while (i < i_max || j < j_max) { if (j == j_max - || (i < i_max + || (i < i_max && strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) < 0)) { /* species 'name' is only in icell */ @@ -2695,7 +2694,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[k].z = sol_D[icell].spec[i].z; ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ c1 = sol_D[icell].spec[i].c / 2; - if (dV_dcell) + if (dV_dcell && ct[icell].v_m[k].z) { // compare diffusive and electromotive forces dum = ct[icell].v_m[k].grad; @@ -2769,8 +2768,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } ct[icell].v_m[k].c = c1; - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + if (ct[icell].v_m[k].z) + { + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + } k++; } } @@ -2844,7 +2846,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell) + if (dV_dcell && ct[icell].v_m[k].z) { // compare diffuse and electromotive forces dum = ct[icell].v_m[k].grad; @@ -2858,7 +2860,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) continue; } } - g_i = g_j = dum1 = 0; if (ct[jcell].dl_s > 0) { @@ -2904,7 +2905,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else { if (sol_D[icell].tk_x == sol_D[jcell].tk_x) - b_j *= sol_D[jcell].spec[j].Dwt; + b_i *= sol_D[jcell].spec[j].Dwt; else { dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f; @@ -2917,10 +2918,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); } - ct[icell].v_m[k].c = c2; - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + if (ct[icell].v_m[k].z) + { + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + } k++; } } @@ -2988,7 +2991,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else c_dl = c1; - if (dl_aq_j > 0) { g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); @@ -3035,7 +3037,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); c1 = sol_D[icell].spec[i].c / 2; c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell) + if (dV_dcell && ct[icell].v_m[k].z) { // compare diffuse and electromotive forces dum = ct[icell].v_m[k].grad; @@ -3053,7 +3055,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) continue; } } - ct[icell].v_m[k].c = (c1 + c2); g_i = g_j = dum2 = 0; if (ct[icell].dl_s > 0) { @@ -3102,11 +3103,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[k].b_ij = b_i; else ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - ct[icell].v_m[k].c = c1 + c2; - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; - + if (ct[icell].v_m[k].z) + { + ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + } ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; if (fabs(ddlm) > 1e-10) ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); @@ -3232,7 +3234,6 @@ dV_dcell2: */ if (il_calcs && ct[icell].Dz2c_il != 0 && ct[icell].J_ij_il_count_spec > 0) { - cxxExchange *ex_ptr1 = Utilities::Rxn_find(Rxn_exchange_map, icell); cxxExchange *ex_ptr2 = Utilities::Rxn_find(Rxn_exchange_map, jcell); Sum_zM = 0.0; @@ -4585,13 +4586,13 @@ viscosity(void) mu1 = exp(Rb * S1); viscos_0 = viscos = mu0 * mu1 / 1e3; viscos_0_25 = 0.8900239182946; -//#define OLD_VISCOSITY + //#define OLD_VISCOSITY #ifdef OLD_VISCOSITY -/* from Atkins, 1994. Physical Chemistry, 5th ed. */ + /* from Atkins, 1994. Physical Chemistry, 5th ed. */ viscos = pow((LDBLE) 10., - -(1.37023 * (tc_x - 20) + - 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); + -(1.37023 * (tc_x - 20) + + 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); viscos_0_25 = 0.88862; #endif return viscos; From 2c3cd3e3bce9ad65373a48a64b67f81ae9ee8c88 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 16:25:36 +0000 Subject: [PATCH 0988/1077] To read multiple lines of porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10798 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readtr.cpp b/readtr.cpp index 2cd216c3..dcd60a43 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -645,7 +645,7 @@ read_transport(void) error_msg("Reading porosities in TRANSPORT keyword.\n", CONTINUE); } - opt_save = OPTION_DEFAULT; + opt_save = 42; break; } if (return_value == EOF || return_value == KEYWORD) From 998f194b9b1db2e2855b7ceff49f73dcbd234239 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 16:27:19 +0000 Subject: [PATCH 0989/1077] To read multiple lines of porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10799 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 312 ++++++++++++++++++++++++++--------------------------- 1 file changed, 156 insertions(+), 156 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 9f495b78..e4eaf741 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -21,19 +21,19 @@ int Phreeqc:: read_transport(void) /* ---------------------------------------------------------------------- */ { -/* - * Reads advection and column information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ + /* + * Reads advection and column information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ char *ptr; int i, j, l; int count_length, count_disp, count_punch, count_print, count_por; @@ -96,9 +96,9 @@ read_transport(void) int count_opt_list = 44; strcpy(file_name, "phreeqc.dmp"); -/* - * Initialize - */ + /* + * Initialize + */ simul_tr++; if (simul_tr == 1) { @@ -111,7 +111,7 @@ read_transport(void) old_cells = count_cells; count_length = count_disp = count_punch = count_print = count_por = 0; - length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + length = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); if (length == NULL) malloc_error(); @@ -127,25 +127,25 @@ read_transport(void) if (punch_temp == NULL) malloc_error(); - print_temp = (int *) PHRQ_malloc(sizeof(int)); + print_temp = (int *)PHRQ_malloc(sizeof(int)); if (print_temp == NULL) malloc_error(); count_length_alloc = count_disp_alloc = count_por_alloc = 1; transport_start = 1; -/* - * Read transport number (not currently used) - */ + /* + * Read transport number (not currently used) + */ ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); -/* - * Set use data to last read - */ + description = (char *)free_check_null(description); + /* + * Set use data to last read + */ use.Set_trans_in(true); -/* - * Read lines - */ + /* + * Read lines + */ opt_save = OPTION_DEFAULT; return_value = UNKNOWN; for (;;) @@ -190,7 +190,7 @@ read_transport(void) input_error++; error_msg ("Expected shift direction, -1, 0, 1. Use -direction instead.", - CONTINUE); + CONTINUE); ishift = 1; } } @@ -200,7 +200,7 @@ read_transport(void) case 20: /* print_cells */ print_temp = read_list_ints_range(&next_char, &count_print, FALSE, - print_temp); + print_temp); opt_save = 2; break; case 3: /* selected_output */ @@ -211,7 +211,7 @@ read_transport(void) if (punch_modulus <= 0) { error_string = sformatf( - "Punch frequency must be greater than 0. Frequency set to 1000."); + "Punch frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); punch_modulus = 1000; } @@ -231,7 +231,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -247,7 +247,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } /* last cell boundary condition */ @@ -261,7 +261,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -277,7 +277,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -304,7 +304,7 @@ read_transport(void) { mcd_substeps = 1.0; warning_msg("Substep factor in MCD must be >= 1.0\n" - "mcd_substeps = 1.0 assumed."); + "mcd_substeps = 1.0 assumed."); } opt_save = OPTION_DEFAULT; break; @@ -324,7 +324,7 @@ read_transport(void) tempr = 1; warning_msg ("Temperature retardation factor < 1 is not possible.\n" - "Temperature retardation factor = 1 assumed."); + "Temperature retardation factor = 1 assumed."); } j = copy_token(token, &next_char, &l); if (j == DIGIT) @@ -335,11 +335,11 @@ read_transport(void) case 24: /* lengths */ if (read_line_LDBLEs (next_char, &length, &count_length, - &count_length_alloc) == ERROR) + &count_length_alloc) == ERROR) { input_error++; error_msg("Reading lengths in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 8; break; @@ -351,7 +351,7 @@ read_transport(void) { input_error++; error_msg("Reading dispersivities in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 9; break; @@ -360,7 +360,7 @@ read_transport(void) case 30: /* punch_cells */ punch_temp = read_list_ints_range(&next_char, &count_punch, FALSE, - punch_temp); + punch_temp); opt_save = 10; break; case 11: /* stagnant */ @@ -371,7 +371,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting number of stagnant layers."); + "Expecting number of stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -384,7 +384,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting exchange factor for stagnant layers."); + "Expecting exchange factor for stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -393,7 +393,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the mobile zone."); + "Expecting porosity in the mobile zone."); error_msg(error_string, CONTINUE); break; } @@ -402,7 +402,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the immobile zone."); + "Expecting porosity in the immobile zone."); error_msg(error_string, CONTINUE); break; } @@ -428,7 +428,7 @@ read_transport(void) input_error++; error_msg ("Expected flow direction to be 'forward', 'back', or 'no_flow'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -452,7 +452,7 @@ read_transport(void) if (print_modulus <= 0) { error_string = sformatf( - "Print frequency must be greater than 0. Frequency set to 1000."); + "Print frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); print_modulus = 1000; } @@ -513,7 +513,7 @@ read_transport(void) input_error++; error_msg ("Expected multicomponent diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } default_Dw = 1e-9; multi_Dpor = 0.3; @@ -528,7 +528,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected default species diffusion coefficient in water at 25oC, m2/s."); + "Expected default species diffusion coefficient in water at 25oC, m2/s."); error_msg(error_string, CONTINUE); break; } @@ -542,7 +542,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity to calculate diffusion coefficient."); + "Expected porosity to calculate diffusion coefficient."); error_msg(error_string, CONTINUE); break; } @@ -556,7 +556,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity limit for diffusive transport."); + "Expected porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -569,7 +569,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); + "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); error_msg(error_string, CONTINUE); break; } @@ -588,7 +588,7 @@ read_transport(void) input_error++; error_msg ("Expected interlayer diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } interlayer_Dpor = 0.1; interlayer_Dpor_lim = 0.0; @@ -601,7 +601,7 @@ read_transport(void) if (sscanf(token, SCANFORMAT, &interlayer_Dpor) != 1) { input_error++; - error_string = sformatf( "Expected interlayer porosity."); + error_string = sformatf("Expected interlayer porosity."); error_msg(error_string, CONTINUE); break; } @@ -615,7 +615,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer porosity limit for diffusive transport."); + "Expected interlayer porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -628,7 +628,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); + "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); error_msg(error_string, CONTINUE); break; } @@ -645,29 +645,29 @@ read_transport(void) error_msg("Reading porosities in TRANSPORT keyword.\n", CONTINUE); } - opt_save = OPTION_DEFAULT; + opt_save = 42; break; } if (return_value == EOF || return_value == KEYWORD) break; } -/* - * Determine number of cells - */ + /* + * Determine number of cells + */ max_cells = count_cells; if (count_length > max_cells) max_cells = count_length; if (count_disp > max_cells) max_cells = count_disp; - if (count_por > max_cells) - max_cells = count_por; + //if (count_por > max_cells) + // max_cells = count_por; if (max_cells > count_cells) { if (max_cells == count_length) { sprintf(token, - "Number of cells is increased to number of 'lengths' %d.", - count_length); + "Number of cells is increased to number of 'lengths' %d.", + count_length); warning_msg(token); } else if (max_cells == count_disp) @@ -677,19 +677,19 @@ read_transport(void) count_disp); warning_msg(token); } - else - { - sprintf(token, - "Number of cells is increased to number of porosities %d.", - count_por); - warning_msg(token); - } + //else + //{ + // sprintf(token, + // "Number of cells is increased to number of porosities %d.", + // count_por); + // warning_msg(token); + //} } -/* - * Allocate space for cell_data - */ + /* + * Allocate space for cell_data + */ int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; - space((void **) ((void *) &cell_data), all_cells_now, &cell_data_max_cells, + space((void **)((void *)&cell_data), all_cells_now, &cell_data_max_cells, sizeof(struct cell_data)); // initialize new cells @@ -701,7 +701,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = 0.1; + cell_data[i].por = 0.3; cell_data[i].por_il = 0.01; cell_data[i].potV = 0; cell_data[i].punch = FALSE; @@ -710,15 +710,15 @@ read_transport(void) all_cells = all_cells_now; } -/* - * Fill in data for lengths - */ + /* + * Fill in data for lengths + */ if (count_length == 0) { if (old_cells < max_cells) { error_string = sformatf( - "No cell-lengths were read; length = 1 m assumed."); + "No cell-lengths were read; length = 1 m assumed."); warning_msg(error_string); for (i = 1; i <= max_cells; i++) cell_data[i].length = 1.0; @@ -733,8 +733,8 @@ read_transport(void) if (max_cells > count_length) { error_string = sformatf( - "Cell-lengths were read for %d cells. Last value is used till cell %d.", - count_length, max_cells); + "Cell-lengths were read for %d cells. Last value is used till cell %d.", + count_length, max_cells); warning_msg(error_string); for (i = count_length; i <= max_cells; i++) cell_data[i + 1].length = length[count_length - 1]; @@ -749,9 +749,9 @@ read_transport(void) } cell_data[max_cells + 1].mid_cell_x = cell_data[max_cells].mid_cell_x + cell_data[max_cells].length / 2; -/* - * Fill in data for dispersivities - */ + /* + * Fill in data for dispersivities + */ if (count_disp == 0) { if (old_cells < max_cells) @@ -777,12 +777,12 @@ read_transport(void) cell_data[i + 1].disp = disp[count_disp - 1]; } } -/* - * Fill in data for porosities - */ + /* + * Fill in data for porosities + */ if (count_por == 0) { - if (old_cells <= max_cells && multi_Dflag) + if (old_cells < all_cells && multi_Dflag) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); if (multi_Dpor > 1e-10) @@ -792,7 +792,7 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = 0; i < all_cells; i++) + for (i = old_cells + 1; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } @@ -816,9 +816,9 @@ read_transport(void) { error_string = sformatf( "Porosities were read for %d cells. Last value is used till cell %d.", - count_por, max_cells); + count_por, all_cells - 1); warning_msg(error_string); - for (i = count_por; i <= max_cells; i++) + for (i = count_por; i < all_cells; i++) cell_data[i + 1].por = pors[count_por - 1]; } } @@ -837,9 +837,9 @@ read_transport(void) cell_data[i].por_il = interlayer_Dpor; } count_cells = max_cells; -/* - * Account for stagnant cells - */ + /* + * Account for stagnant cells + */ if (stag_data->count_stag > 0) { max_cells = count_cells * (1 + stag_data->count_stag) + 2; @@ -847,12 +847,12 @@ read_transport(void) { for (l = 1; l <= stag_data->count_stag; l++) cell_data[i + 1 + l * count_cells].mid_cell_x = - cell_data[i].mid_cell_x; + cell_data[i].mid_cell_x; } } -/* - * Fill in data for punch - */ + /* + * Fill in data for punch + */ if (count_punch != 0) { for (i = 0; i < all_cells; i++) @@ -862,8 +862,8 @@ read_transport(void) if (punch_temp[i] > all_cells - 1 || punch_temp[i] < 0) { error_string = sformatf( - "Cell number for punch is out of range, %d. Request ignored.", - punch_temp[i]); + "Cell number for punch is out of range, %d. Request ignored.", + punch_temp[i]); warning_msg(error_string); } else @@ -873,9 +873,9 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].punch = TRUE; -/* - * Fill in data for print - */ + /* + * Fill in data for print + */ if (count_print != 0) { for (i = 0; i < all_cells; i++) @@ -885,8 +885,8 @@ read_transport(void) if (print_temp[i] > all_cells - 1 || print_temp[i] < 0) { error_string = sformatf( - "Cell number for print is out of range, %d. Request ignored.", - print_temp[i]); + "Cell number for print is out of range, %d. Request ignored.", + print_temp[i]); warning_msg(error_string); } else @@ -896,9 +896,9 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].print = TRUE; -/* - * Calculate dump_modulus - */ + /* + * Calculate dump_modulus + */ if (dump_in == TRUE) { if (dump_modulus == 0) @@ -913,14 +913,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Starting shift for transport, %d, is greater than number of shifts, %d.", - transport_start, count_shifts); + "Starting shift for transport, %d, is greater than number of shifts, %d.", + transport_start, count_shifts); error_msg(error_string, CONTINUE); } } -/* - * Check boundary conditions - */ + /* + * Check boundary conditions + */ if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) { warning_msg @@ -930,17 +930,17 @@ read_transport(void) if (bcon_last == 2) bcon_last = 3; } -/* - * Retain data from previous run - */ + /* + * Retain data from previous run + */ if (simul_tr > 1) { if ((count_length == 0) && (count_disp == 0) && (count_por == 0)) dup_print("Column data retained from former run", TRUE); } -/* - * Check heat_diffc - */ + /* + * Check heat_diffc + */ if (heat_diffc < 0) heat_diffc = diffc; else if (stag_data->count_stag == 1) @@ -951,14 +951,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); + "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } else if (heat_diffc > diffc) { error_string = sformatf( - "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", - (double) diffc); + "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", + (double)diffc); warning_msg(error_string); } } @@ -968,7 +968,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); + "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } } @@ -977,17 +977,17 @@ read_transport(void) { input_error++; error_string = sformatf( - "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); + "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } -/* - * free storage for length, disp, punch - */ - length = (LDBLE *) free_check_null(length); + /* + * free storage for length, disp, punch + */ + length = (LDBLE *)free_check_null(length); disp = (LDBLE *)free_check_null(disp); pors = (LDBLE *)free_check_null(pors); - punch_temp = (int *) free_check_null(punch_temp); - print_temp = (int *) free_check_null(print_temp); + punch_temp = (int *)free_check_null(punch_temp); + print_temp = (int *)free_check_null(print_temp); if (dump_in == TRUE) { @@ -1028,7 +1028,7 @@ read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc) if ((*count_d) + n > (*count_alloc)) { *count_alloc *= 2; - *d = (LDBLE *) PHRQ_realloc(*d, (size_t) (*count_alloc) * sizeof(LDBLE)); + *d = (LDBLE *)PHRQ_realloc(*d, (size_t)(*count_alloc) * sizeof(LDBLE)); if (*d == NULL) malloc_error(); } @@ -1047,9 +1047,9 @@ int Phreeqc:: dump_cpp(void) /* ---------------------------------------------------------------------- */ { -/* - * dumps solution compositions to file - */ + /* + * dumps solution compositions to file + */ int l; @@ -1062,26 +1062,26 @@ dump_cpp(void) std::ofstream fs(dump_file_name_cpp.c_str()); if (!fs.is_open()) { - error_string = sformatf( "Can`t open file, %s.", dump_file_name_cpp.c_str()); + error_string = sformatf("Can`t open file, %s.", dump_file_name_cpp.c_str()); input_error++; error_msg(error_string, CONTINUE); return (OK); } - + fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n"; phreeqcBin.dump_raw(fs, 0); fs << "END" << "\n"; char token[MAX_LENGTH]; sprintf(token, "KNOBS\n"); - fs << token; - sprintf(token, "\t-iter%15d\n", itmax); - fs << token; - sprintf(token, "\t-tol %15.3e\n", (double) ineq_tol); - fs << token; - sprintf(token, "\t-step%15.3e\n", (double) step_size); fs << token; - sprintf(token, "\t-pe_s%15.3e\n", (double) pe_step_size); + sprintf(token, "\t-iter%15d\n", itmax); + fs << token; + sprintf(token, "\t-tol %15.3e\n", (double)ineq_tol); + fs << token; + sprintf(token, "\t-step%15.3e\n", (double)step_size); + fs << token; + sprintf(token, "\t-pe_s%15.3e\n", (double)pe_step_size); fs << token; sprintf(token, "\t-diag "); fs << token; @@ -1096,12 +1096,12 @@ dump_cpp(void) fs << token; } std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); - for ( ; so_it != SelectedOutput_map.end(); so_it++) + for (; so_it != SelectedOutput_map.end(); so_it++) { current_selected_output = &(so_it->second); sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user()); - fs << token ; + fs << token; //sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); //fs << token; fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n"; @@ -1216,19 +1216,19 @@ dump_cpp(void) fs << token; sprintf(token, "\t-bcon %6d%6d\n", bcon_first, bcon_last); fs << token; - sprintf(token, "\t-timest %13.5e\n", (double) timest); + sprintf(token, "\t-timest %13.5e\n", (double)timest); fs << token; if (!high_precision) { - sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + sprintf(token, "\t-diffc %13.5e\n", (double)diffc); fs << token; } else { - sprintf(token, "\t-diffc %20.12e\n", (double) diffc); + sprintf(token, "\t-diffc %20.12e\n", (double)diffc); fs << token; } - sprintf(token, "\t-tempr %13.5e\n", (double) tempr); + sprintf(token, "\t-tempr %13.5e\n", (double)tempr); fs << token; if (correct_disp == TRUE) { @@ -1244,7 +1244,7 @@ dump_cpp(void) fs << token; for (int i = 1; i <= count_cells; i++) { - sprintf(token, "%12.3e", (double) cell_data[i].length); + sprintf(token, "%12.3e", (double)cell_data[i].length); fs << token; if (i > 0 && (i % 8) == 0) { @@ -1260,12 +1260,12 @@ dump_cpp(void) { if (!high_precision) { - sprintf(token, "%12.3e", (double) cell_data[i].disp); + sprintf(token, "%12.3e", (double)cell_data[i].disp); fs << token; } else { - sprintf(token, "%20.12e", (double) cell_data[i].disp); + sprintf(token, "%20.12e", (double)cell_data[i].disp); fs << token; } if (i > 0 && (i % 8) == 0) @@ -1334,9 +1334,9 @@ int Phreeqc:: dump(void) /* ---------------------------------------------------------------------- */ { -/* - * dumps solution compositions to file - */ + /* + * dumps solution compositions to file + */ if (dump_in == FALSE || pr.dump == FALSE) return (OK); From 320aef185a67e79b328cae8b118fc8180a016e09 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 16:37:58 +0000 Subject: [PATCH 0990/1077] Merged Tony's 2/3/16 changes for setting porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10800 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index dcd60a43..a2235085 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -659,8 +659,8 @@ read_transport(void) max_cells = count_length; if (count_disp > max_cells) max_cells = count_disp; - if (count_por > max_cells) - max_cells = count_por; + //if (count_por > max_cells) + // max_cells = count_por; if (max_cells > count_cells) { if (max_cells == count_length) @@ -677,13 +677,13 @@ read_transport(void) count_disp); warning_msg(token); } - else - { - sprintf(token, - "Number of cells is increased to number of porosities %d.", - count_por); - warning_msg(token); - } + //else + //{ + // sprintf(token, + // "Number of cells is increased to number of porosities %d.", + // count_por); + // warning_msg(token); + //} } /* * Allocate space for cell_data @@ -703,7 +703,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = 0.1; //Fix for Jenkins !!!!!!!!!!!! + cell_data[i].por = 0.3; cell_data[i].por_il = 0.01; cell_data[i].punch = FALSE; cell_data[i].print = FALSE; @@ -782,7 +782,7 @@ read_transport(void) */ if (count_por == 0) { - if (old_cells <= max_cells && multi_Dflag) + if (old_cells < all_cells && multi_Dflag) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); if (multi_Dpor > 1e-10) @@ -792,7 +792,7 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = 0; i < all_cells; i++) + for (i = old_cells + 1; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } @@ -816,9 +816,9 @@ read_transport(void) { error_string = sformatf( "Porosities were read for %d cells. Last value is used till cell %d.", - count_por, max_cells); + count_por, all_cells - 1); warning_msg(error_string); - for (i = count_por - 1; i <= max_cells; i++) + for (i = count_por - 1; i < all_cells; i++) cell_data[i].por = pors[count_por - 1]; } } From 7c77eda952c5efab02b456f4035fd0ba2a0eb3a1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 17:54:58 +0000 Subject: [PATCH 0991/1077] Forgot to remove testing code for differences in porosity between old and new version. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10803 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index a2235085..9065900a 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -896,30 +896,7 @@ read_transport(void) else if (simul_tr == 1) for (i = 0; i < max_cells; i++) cell_data[i].print = TRUE; -//#define TONY -#if !defined(TONY) -/* - * Fill in porosities - */ - if (interlayer_Dflag && !multi_Dflag) - { - input_error++; - error_string = sformatf( - "-multi_D must be defined, when -interlayer_D true."); - error_msg(error_string, CONTINUE); - } - for (i = 0; i < max_cells; i++) - { - multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! - //if (cell_data[i].por < 0) - { - cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! - } - interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); - cell_data[i].por_il = interlayer_Dpor; - } -#endif /* * Calculate dump_modulus */ From bde722c21e4d044a74e245fd6ee2f35b87ad25fa Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 21:42:14 +0000 Subject: [PATCH 0992/1077] Another try on porosities. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10804 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/readtr.cpp b/readtr.cpp index 9065900a..27803a92 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -792,7 +792,8 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = old_cells + 1; i < all_cells; i++) + //for (i = old_cells + 1; i < all_cells; i++) + for (i = old_cells; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } @@ -896,7 +897,37 @@ read_transport(void) else if (simul_tr == 1) for (i = 0; i < max_cells; i++) cell_data[i].print = TRUE; +//#define OLD_POROSITY +#if defined(OLD_POROSITY) +/* + * Fill in porosities + */ + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + } + for (i = 0; i < max_cells; i++) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! + //if (cell_data[i].por < 0) + { + cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! + } + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por_il = interlayer_Dpor; + } +#endif + //{ + // for (int i = 0; i < all_cells; i++) + // { + // std::cerr << i << " " << cell_data[i].por << std::endl; + // } + //} + /* * Calculate dump_modulus */ From 81525819204853e0bfcb5633222d782d0fbb4413 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 3 Feb 2016 22:05:56 +0000 Subject: [PATCH 0993/1077] Needed for old test cases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10805 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readtr.cpp b/readtr.cpp index e4eaf741..1dd8d632 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -792,7 +792,8 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = old_cells + 1; i < all_cells; i++) + //for (i = old_cells + 1; i < all_cells; i++) + for (i = old_cells; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } From 2a9ab26516a8cc1985255a9de15864cae2199ab4 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 4 Feb 2016 16:51:39 +0000 Subject: [PATCH 0994/1077] For concrete, this is correct. For phreeqc-trunk without the new transport changes, previous is needed. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10807 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- readtr.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readtr.cpp b/readtr.cpp index 1dd8d632..2a420772 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -792,8 +792,8 @@ read_transport(void) error_string = sformatf( "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - //for (i = old_cells + 1; i < all_cells; i++) - for (i = old_cells; i < all_cells; i++) + for (i = old_cells + 1; i < all_cells; i++) + //for (i = old_cells; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } @@ -897,7 +897,7 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].print = TRUE; - /* +/* * Calculate dump_modulus */ if (dump_in == TRUE) From 78c5daa0a9dbe49467067bbdd0363ea4afbec5df Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 16 Feb 2016 19:34:12 +0000 Subject: [PATCH 0995/1077] Negative mass of water bug. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10834 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/prep.cpp b/prep.cpp index a775c235..89f102d5 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2055,6 +2055,13 @@ convert_units(cxxSolution *solution_ptr) strstr(initial_data_ptr->Get_units().c_str(), "/l") != NULL) { mass_water_aq_x = 1.0 - 1e-3 * sum_solutes; + if (mass_water_aq_x <= 0) + { + error_string = sformatf( "Solute mass exceeds solution mass in conversion from /kgs to /kgw.\n" + "Mass of water is negative."); + error_msg(error_string, CONTINUE); + input_error++; + } cxxNameDouble::iterator it; for (it = solution_ptr->Get_totals().begin(); it != solution_ptr->Get_totals().end(); it++) { From ed231a91094d78f3d8c28f46d02786069dfa45bf Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Mar 2016 17:56:35 +0000 Subject: [PATCH 0996/1077] calc_logk_s, removed if (s_ptr->logk[vm_tc]) at line 489. Added rho_0. k_temp, line 5720 //if (s_x[i]->rxn_x->logk[vm_tc]) Added mol/kgw for units of ionic strength. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10881 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 9 ++++++++- PBasic.h | 1 + basicsubs.cpp | 2 +- prep.cpp | 2 +- print.cpp | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 219d2b0e..5960c8bb 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1529,6 +1529,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokrho: output_msg("RHO"); break; + case tokrho_0: + output_msg("RHO_0"); + break; /* VP: Density End */ case tokcell_volume: output_msg("CELL_VOLUME"); @@ -3452,6 +3455,9 @@ factor(struct LOC_exec * LINK) case tokrho: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_dens(); break; + case tokrho_0: + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rho_0; + break; /* VP: Density End */ case tokcell_volume: { @@ -7118,7 +7124,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("callback", PBasic::tokcallback), std::map::value_type("diff_c", PBasic::tokdiff_c), std::map::value_type("sa_declercq", PBasic::toksa_declercq), - std::map::value_type("edl_species", PBasic::tokedl_species) + std::map::value_type("edl_species", PBasic::tokedl_species), + std::map::value_type("rho_0", PBasic::tokrho_0) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 6f8626de..0efbdd8e 100644 --- a/PBasic.h +++ b/PBasic.h @@ -279,6 +279,7 @@ public: tokgamma, toklg, tokrho, + tokrho_0, tokcell_volume, tokcell_pore_volume, tokcell_porosity, diff --git a/basicsubs.cpp b/basicsubs.cpp index c9e30af2..01c3dcad 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -486,7 +486,7 @@ calc_logk_s(const char *name) s_ptr = s_search(token); if (s_ptr != NULL) { - if (s_ptr->logk[vm_tc]) + //if (s_ptr->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false); for (i = 0; i < MAX_LOG_K_INDICES; i++) diff --git a/prep.cpp b/prep.cpp index 89f102d5..d783dccf 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5717,7 +5717,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ mu_terms_in_logk = false; for (i = 0; i < count_s_x; i++) { - if (s_x[i]->rxn_x->logk[vm_tc]) + //if (s_x[i]->rxn_x->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) diff --git a/print.cpp b/print.cpp index a8dac445..8f983320 100644 --- a/print.cpp +++ b/print.cpp @@ -2263,7 +2263,7 @@ print_totals(void) #endif output_msg(sformatf("%45s%7.3f\n", "Activity of water = ", exp(s_h2o->la * LOG_10))); - output_msg(sformatf("%45s%11.3e\n", "Ionic strength = ", + output_msg(sformatf("%45s%11.3e\n", "Ionic strength (mol/kgw) = ", (double) mu_x)); output_msg(sformatf("%45s%11.3e\n", "Mass of water (kg) = ", (double) mass_water_aq_x)); From 8bc5862769ecd4bb430d9cb006e06b3c0f6b3b57 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 3 Mar 2016 18:44:50 +0000 Subject: [PATCH 0997/1077] Switch back for now. Tony will fix later. if (s_ptr->logk[vm_tc]) git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10883 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 2 +- prep.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 01c3dcad..c9e30af2 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -486,7 +486,7 @@ calc_logk_s(const char *name) s_ptr = s_search(token); if (s_ptr != NULL) { - //if (s_ptr->logk[vm_tc]) + if (s_ptr->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false); for (i = 0; i < MAX_LOG_K_INDICES; i++) diff --git a/prep.cpp b/prep.cpp index d783dccf..89f102d5 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5717,7 +5717,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ mu_terms_in_logk = false; for (i = 0; i < count_s_x; i++) { - //if (s_x[i]->rxn_x->logk[vm_tc]) + if (s_x[i]->rxn_x->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) From 626d678296403b2c778f752b15b6cab517a0bbb1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 4 Mar 2016 16:38:33 +0000 Subject: [PATCH 0998/1077] Added setdiff_c method. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10891 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 24 +++++++++++++++++++++++- PBasic.h | 1 + Phreeqc.h | 1 + basicsubs.cpp | 25 ++++++++++++++++++++++++- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 2c56b1a1..b0016d0d 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1617,6 +1617,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokdiff_c: output_msg("DIFF_C"); break; + case toksetdiff_c: + output_msg("SETDIFF_C"); + break; case toksa_declercq: output_msg("SA_DECLERCQ"); break; @@ -3823,7 +3826,25 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->diff_c(str); } break; + + case toksetdiff_c: + { + double d; + + require(toklp, LINK); + + const char * str = stringfactor(STR1, LINK); + require(tokcomma, LINK); + + // double arugument + d = realexpr(LINK); + require(tokrp, LINK); + + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->setdiff_c(str, d); + //PhreeqcPtr->PHRQ_free((void *) str); + } + break; case tokval: l_s = strfactor(LINK); tok1 = LINK->t; @@ -7159,7 +7180,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("viscos_0", PBasic::tokviscos_0), std::map::value_type("rho_0", PBasic::tokrho_0), std::map::value_type("current_a", PBasic::tokcurrent_a), - std::map::value_type("pot_v", PBasic::tokpot_v) + std::map::value_type("pot_v", PBasic::tokpot_v), + std::map::value_type("setdiff_c", PBasic::toksetdiff_c) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index f2f39cc9..a943186d 100644 --- a/PBasic.h +++ b/PBasic.h @@ -323,6 +323,7 @@ public: tokequiv_frac, tokcallback, tokdiff_c, + toksetdiff_c, toksa_declercq, tokedl_species, tokviscos, diff --git a/Phreeqc.h b/Phreeqc.h index 16f2f4a6..f91a0178 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -101,6 +101,7 @@ public: LDBLE log_activity_coefficient(const char *species_name); LDBLE aqueous_vm(const char *species_name); LDBLE diff_c(const char *species_name); + LDBLE setdiff_c(const char *species_name, double d); LDBLE sa_declercq(double type, double sa, double d, double m, double m0, double gfw); LDBLE calc_SC(void); /* VP: Density Start */ diff --git a/basicsubs.cpp b/basicsubs.cpp index 4d803dfd..b4aa5f63 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -158,7 +158,7 @@ diff_c(const char *species_name) LDBLE g; s_ptr = s_search(species_name); - if (s_ptr != NULL && s_ptr->in != FALSE && s_ptr->type < EMINUS) + if (s_ptr != NULL /*&& s_ptr->in != FALSE && s_ptr->type < EMINUS*/) { g = s_ptr->dw; if (s_ptr->dw_t) @@ -173,6 +173,29 @@ diff_c(const char *species_name) } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: +setdiff_c(const char *species_name, double d) +/* ---------------------------------------------------------------------- */ +{ + struct species *s_ptr; + LDBLE g; + + s_ptr = s_search(species_name); + if (s_ptr != NULL) + { + s_ptr->dw = d; + g = s_ptr->dw; + if (s_ptr->dw_t) + g *= exp(s_ptr->dw_t / tk_x - s_ptr->dw_t / 298.15); + g *= viscos_0_25 / viscos; + } + else + { + g = 0; + } + return (g); +} +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: calc_SC(void) /* ---------------------------------------------------------------------- */ { From 4405e60e4eaf7cf023071c806b90c7f1ffb4138e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 4 Mar 2016 18:13:43 +0000 Subject: [PATCH 0999/1077] Merged source up to phreeqc3-trunk SVN 10892 copied files from trunk and merged changes manually. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10893 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- GasPhase.cxx | 2 +- Makefile.am | 4 + PBasic.cpp | 3 +- Phreeqc.cpp | 4 +- Phreeqc.h | 1 + Serializer.cxx | 2 + Solution.cxx | 2 +- cl1mp.cpp | 6 +- class_main.cpp | 53 ++++---- global_structures.h | 1 + kinetics.cpp | 29 ++++- mainsubs.cpp | 8 +- model.cpp | 10 +- pitzer.cpp | 2 +- prep.cpp | 67 +++++++++- print.cpp | 9 +- read.cpp | 12 +- readtr.cpp | 311 ++++++++++++++++++++++++-------------------- step.cpp | 11 +- tidy.cpp | 98 +++++++------- 20 files changed, 391 insertions(+), 244 deletions(-) diff --git a/GasPhase.cxx b/GasPhase.cxx index b3652787..7be3206c 100644 --- a/GasPhase.cxx +++ b/GasPhase.cxx @@ -688,7 +688,7 @@ cxxGasPhase::Deserialize(Dictionary & dictionary, std::vector < int >&ints, this->n_user_end = this->n_user; this->description = " "; - this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : this->type = cxxGasPhase::GP_VOLUME; + this->type = (ints[ii++] == 0) ? cxxGasPhase::GP_PRESSURE : cxxGasPhase::GP_VOLUME; this->total_p = doubles[dd++]; this->volume = doubles[dd++]; int count = ints[ii++]; diff --git a/Makefile.am b/Makefile.am index f6e6e408..21629594 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,8 @@ phreeqc_SOURCES=\ cxxMix.h\ dense.cpp\ dense.h\ + Dictionary.cpp\ + Dictionary.h\ dumper.cpp\ dumper.h\ dw.cpp\ @@ -102,6 +104,8 @@ phreeqc_SOURCES=\ runner.h\ SelectedOutput.cpp\ SelectedOutput.h\ + Serializer.cxx\ + Serializer.h\ sit.cpp\ smalldense.cpp\ smalldense.h\ diff --git a/PBasic.cpp b/PBasic.cpp index b0016d0d..7e1d69c2 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3576,7 +3576,6 @@ factor(struct LOC_exec * LINK) //} } break; - case toksin: n.UU.val = sin(realfactor(LINK)); break; @@ -3826,7 +3825,7 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->diff_c(str); } break; - + case toksetdiff_c: { double d; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9bd9ba5e..8c3e0bd1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -731,6 +731,7 @@ void Phreeqc::init(void) diagonal_scale = FALSE; mass_water_switch = FALSE; delay_mass_water = FALSE; + equi_delay = 0; dampen_ah2o = false; censor = 0.0; aqueous_only = 0; @@ -990,7 +991,7 @@ void Phreeqc::init(void) /* phrq_io_output.cpp ------------------------------- */ forward_output_to_log = 0; /* phreeqc_files.cpp ------------------------------- */ - default_data_base = string_duplicate("phreeqc.dat"); + default_data_base = string_duplicate("phreeqc.dat"); #ifdef PHREEQ98 int outputlinenr; char *LogFileNameC; @@ -1919,6 +1920,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) diagonal_scale = pSrc->diagonal_scale; mass_water_switch = pSrc->mass_water_switch; delay_mass_water = pSrc->delay_mass_water; + equi_delay = pSrc->equi_delay; dampen_ah2o = pSrc->dampen_ah2o; censor = pSrc->censor; aqueous_only = pSrc->aqueous_only; diff --git a/Phreeqc.h b/Phreeqc.h index f91a0178..6bd47b65 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1646,6 +1646,7 @@ protected: int diagonal_scale; /* 0 not used, 1 used */ int mass_water_switch; int delay_mass_water; + int equi_delay; bool dampen_ah2o; LDBLE censor; int aqueous_only; diff --git a/Serializer.cxx b/Serializer.cxx index 018f56ca..4b67baeb 100644 --- a/Serializer.cxx +++ b/Serializer.cxx @@ -189,8 +189,10 @@ Serializer::Deserialize(Phreeqc &phreeqc_ref, Dictionary &dictionary, std::vecto } break; default: +#if !defined(R_SO) std::cerr << "Unknown pack type in deserialize " << type << std::endl; exit(4); +#endif break; } } diff --git a/Solution.cxx b/Solution.cxx index b6910e36..bb8dd693 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1010,7 +1010,7 @@ cxxSolution::read_raw(CParser & parser, bool check) parser.incr_input_error(); parser.error_msg("Expected numeric value for potential (V).", PHRQ_io::OT_CONTINUE); - } + } opt_save = CParser::OPT_DEFAULT; break; diff --git a/cl1mp.cpp b/cl1mp.cpp index e581cdcf..0d1d2d1d 100644 --- a/cl1mp.cpp +++ b/cl1mp.cpp @@ -36,7 +36,7 @@ cl1mp(int k, int l, int m, int n, int iout = 0; // static i runs faster int i, j; - int maxit, n1, n2; + int maxit, n1; //, n2; int ia, ii, kk, nk, js; int in = 0; int iphase, kforce; @@ -221,7 +221,7 @@ cl1mp(int k, int l, int m, int n, /* Function Body */ maxit = *iter; n1 = n + 1; - n2 = n + 2; + // n2 = n + 2; nk = n + k; nkl = nk + l; klm = k + l + m; @@ -1131,4 +1131,4 @@ cl1mp(int k, int l, int m, int n, kode = (int *) free_check_null(kode); return 0; } -#endif // INVERSE_CL1MP \ No newline at end of file +#endif // INVERSE_CL1MP diff --git a/class_main.cpp b/class_main.cpp index 186c7fd2..0685fecb 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -1,7 +1,5 @@ #include "Phreeqc.h" -#ifdef PHREEQC_PARALLEL -#include "Parallelizer.h" -#endif + #include "NameDouble.h" #include "Solution.h" #include "Reaction.h" @@ -13,7 +11,6 @@ #include "cxxKinetics.h" //#include //#include - /* ---------------------------------------------------------------------- * MAIN * ---------------------------------------------------------------------- */ @@ -48,7 +45,7 @@ main(int argc, char *argv[]) tmpDbgFlag |= _CRTDBG_LEAK_CHECK_DF; ///tmpDbgFlag |= _CRTDBG_CHECK_ALWAYS_DF; _CrtSetDbgFlag(tmpDbgFlag); - //_crtBreakAlloc = 185092; + //_crtBreakAlloc = 31195; #endif #ifdef SKIP //Set the x86 floating-point control word according to what @@ -72,11 +69,8 @@ unsigned int cwOriginal = _controlfp(cw, MCW_EM); //Set it. //Restore the original value when done: //_controlfp(cwOriginal, MCW_EM); #endif - Phreeqc phreeqc_instance; - int return_value = phreeqc_instance.main_method(argc, argv); - - return return_value; + return phreeqc_instance.main_method(argc, argv); } //#define TEST_COPY #ifdef TEST_COPY @@ -337,7 +331,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -447,7 +441,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -508,7 +502,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, /* * local cleanup */ - //user_database = (char *) free_check_null(user_database); + user_database = (char *) free_check_null(user_database); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); @@ -538,7 +532,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -647,7 +641,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -747,7 +741,11 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -774,7 +772,7 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, #endif error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -803,7 +801,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { /* @@ -817,13 +815,17 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else phrq_io->Set_error_file(stderr); #endif - + screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -846,7 +848,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -875,7 +877,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { @@ -895,7 +897,11 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, { screen_msg(sformatf("Default: %s\n", default_name)); } - fgets(name, MAX_LENGTH, stdin); + char *s_ptr = fgets(name, MAX_LENGTH, stdin); + if (s_ptr == NULL) + { + std::cerr << "Failed defining name." << std::endl; + } l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -918,7 +924,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -934,4 +940,3 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, return (new_stream); } #endif - diff --git a/global_structures.h b/global_structures.h index 495f3d99..9c64a3f9 100644 --- a/global_structures.h +++ b/global_structures.h @@ -838,6 +838,7 @@ struct unknown LDBLE V_m; LDBLE pressure; int mb_number; + int iteration; }; /*---------------------------------------------------------------------- diff --git a/kinetics.cpp b/kinetics.cpp index 2fa8f5c3..e2409cbc 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1265,6 +1265,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, old_pe = pe_step_size; old_min_value = min_value; old_pp_column_scale = pp_column_scale; + int old_equi_delay = equi_delay; if (state == TRANSPORT || state == PHAST) { @@ -1301,7 +1302,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, } else { - max_try = 13; + max_try = 14; } max_try = (max_tries < max_try) ? max_tries : max_try; /*max_try = 1; */ @@ -1397,6 +1398,22 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, warning_msg(error_string); } else if (j == 8) + { + if (use.Get_pp_assemblage_ptr() == NULL) continue; + if (equi_delay > 0) + { + equi_delay = 0; + } + else + { + equi_delay = 1; + } + error_string = sformatf( "Trying delay removal of equilibrium phases %g ...\n", + (double) equi_delay); + warning_msg(error_string); + } + + else if (j == 9) { if (pitzer_model == TRUE || sit_model == TRUE) continue; itmax *= 2; @@ -1405,7 +1422,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, (double) min_value); warning_msg(error_string); } - else if (j == 9) + else if (j == 10) { if (pitzer_model == TRUE || sit_model == TRUE) continue; aqueous_only = 5; @@ -1414,7 +1431,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, aqueous_only); warning_msg(error_string); } - else if (j == 10) + else if (j == 11) { if (pitzer_model == TRUE || sit_model == TRUE) continue; negative_concentrations = TRUE; @@ -1422,7 +1439,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, "Adding inequality to make concentrations greater than zero.\n"); warning_msg(error_string); } - else if (j == 11) + else if (j == 12) { itmax *= 2; ineq_tol /= 100.; @@ -1430,7 +1447,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, (double) ineq_tol); warning_msg(error_string); } - else if (j == 12) + else if (j == 13) { itmax *= 2; ineq_tol /= 1000.; @@ -1468,6 +1485,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, pe_step_size = old_pe; min_value = old_min_value; pp_column_scale = old_pp_column_scale; + equi_delay = old_equi_delay; aqueous_only = 0; negative_concentrations = FALSE; always_full_pitzer = FALSE; @@ -1618,7 +1636,6 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, converge = model(); } sum_species(); - viscosity(); return (converge); } diff --git a/mainsubs.cpp b/mainsubs.cpp index b85eb002..329b35a6 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -46,7 +46,7 @@ initialize(void) */ cell_data_max_cells = count_cells + 2; space((void **) ((void *) &cell_data), INIT, &cell_data_max_cells, - sizeof(struct cell_data)); + sizeof(struct cell_data)); for (int i = 0; i < cell_data_max_cells; i++) { cell_data[i].length = 1.0; @@ -632,15 +632,17 @@ initial_solutions(int print) k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); set(TRUE); always_full_pitzer = FALSE; + bool diag = (diagonal_scale == TRUE) ? true : false; + diagonal_scale = TRUE; converge = model(); - if (converge == ERROR && diagonal_scale == FALSE) + if (converge == ERROR /*&& diagonal_scale == FALSE*/) { diagonal_scale = TRUE; always_full_pitzer = TRUE; set(TRUE); converge = model(); - diagonal_scale = FALSE; } + diagonal_scale = (diag) ? TRUE : FALSE; converge1 = check_residuals(); sum_species(); viscosity(); diff --git a/model.cpp b/model.cpp index 8db40bec..28a1fff7 100644 --- a/model.cpp +++ b/model.cpp @@ -1125,15 +1125,19 @@ ineq(int in_kode) /* not in model, ignore */ if (x[i]->phase->in == FALSE) continue; + // delay removing phase + if (x[i]->moles > 0.0 || x[i]->f <= 0.0 || iterations == 0 || equi_delay == 0) + { + x[i]->iteration = iterations; + } cxxPPassemblageComp * comp_ptr = (cxxPPassemblageComp *) x[i]->pp_assemblage_comp_ptr; //if (it->second.Get_force_equality()) if (comp_ptr->Get_force_equality()) continue; /* Undersaturated and no mass, ignore */ - //if (x[i]->f > 1e-14/*0e-8*/ && x[i]->moles <= 0 if (x[i]->f > 0e-8 && x[i]->moles <= 0 - //&& it->second.Get_add_formula().size() == 0) - && comp_ptr->Get_add_formula().size() == 0) + && iterations >= x[i]->iteration + equi_delay + && comp_ptr->Get_add_formula().size() == 0) { continue; } diff --git a/pitzer.cpp b/pitzer.cpp index b0af2f7c..ccf71508 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1288,7 +1288,7 @@ pitzer(void) pap = 0; else pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); - //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); B2 = B - (pap > 0.2 ? 0.2 : pap); if (B1 != 0) F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); diff --git a/prep.cpp b/prep.cpp index a15d4208..89f102d5 100644 --- a/prep.cpp +++ b/prep.cpp @@ -9,6 +9,7 @@ #include "SSassemblage.h" #include "SS.h" #include "Solution.h" +#include "cxxKinetics.h" /* ---------------------------------------------------------------------- */ int Phreeqc:: prep(void) @@ -2054,6 +2055,13 @@ convert_units(cxxSolution *solution_ptr) strstr(initial_data_ptr->Get_units().c_str(), "/l") != NULL) { mass_water_aq_x = 1.0 - 1e-3 * sum_solutes; + if (mass_water_aq_x <= 0) + { + error_string = sformatf( "Solute mass exceeds solution mass in conversion from /kgs to /kgw.\n" + "Mass of water is negative."); + error_msg(error_string, CONTINUE); + input_error++; + } cxxNameDouble::iterator it; for (it = solution_ptr->Get_totals().begin(); it != solution_ptr->Get_totals().end(); it++) { @@ -3655,6 +3663,23 @@ setup_surface(void) */ if (use.Get_surface_ptr()->Get_related_phases()) { + cxxPPassemblage *pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_surface_user()); + for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) + { + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name().size() > 0) + { + if (pp_ptr == NULL || + (pp_ptr->Get_pp_assemblage_comps().find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name()) == + pp_ptr->Get_pp_assemblage_comps().end())) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); + this->tidy_min_surface(); + return (FALSE); + } + } + } for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) @@ -3702,7 +3727,21 @@ setup_surface(void) * check related kinetics */ if (use.Get_surface_ptr()->Get_related_rate()) - { + { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); + for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) + { + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) + { + if (kinetics_ptr == NULL || + (kinetics_ptr->Find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name()) == NULL)) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + this->tidy_kin_surface(); + return (FALSE); + } + } + } for (int i = 0; i < count_unknowns; i++) { if (x[i]->type != SURFACE_CB) @@ -6099,6 +6138,32 @@ check_same_model(void) if (last_model.surface_comp[i] != string_hsave(use.Get_surface_ptr()->Get_surface_comps()[i].Get_formula().c_str())) return (FALSE); + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name().size() > 0) + { + cxxPPassemblage *pp_ptr = Utilities::Rxn_find(Rxn_pp_assemblage_map, use.Get_n_surface_user()); + if (pp_ptr == NULL || (pp_ptr->Get_pp_assemblage_comps().find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_phase_name()) == + pp_ptr->Get_pp_assemblage_comps().end())) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); + this->tidy_min_surface(); + return (FALSE); + } + } + if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) + { + cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); + if (kinetics_ptr == NULL || + (kinetics_ptr->Find(use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name()) == NULL)) + { + Rxn_new_surface.insert(use.Get_n_surface_user()); + cxxSurface *surf_ptr = Utilities::Rxn_find(Rxn_surface_map, use.Get_n_surface_user()); + surf_ptr->Set_new_def(true); + this->tidy_kin_surface(); + return (FALSE); + } + } } for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++) { diff --git a/print.cpp b/print.cpp index 43e5cbac..0d45f206 100644 --- a/print.cpp +++ b/print.cpp @@ -2220,11 +2220,12 @@ print_totals(void) EC = calc_SC(); if (EC > 0) { - output_msg(sformatf("%36s%i%7s%i\n", + //output_msg(sformatf("%36s%i%7s%i\n", + output_msg(sformatf("%35s%3.0f%7s%i\n", #ifdef NO_UTF8_ENCODING - "Specific Conductance (uS/cm, ", (int) tc_x, "oC) = ", (int) EC)); + "Specific Conductance (uS/cm, ", tc_x, "oC) = ", (int) EC)); #else - "Specific Conductance (µS/cm, ", (int) tc_x, "°C) = ", (int) EC)); + "Specific Conductance (µS/cm, ", tc_x, "°C) = ", (int) EC)); #endif } /* VP: Density Start */ @@ -2262,7 +2263,7 @@ print_totals(void) #endif output_msg(sformatf("%45s%7.3f\n", "Activity of water = ", exp(s_h2o->la * LOG_10))); - output_msg(sformatf("%45s%11.3e\n", "Ionic strength = ", + output_msg(sformatf("%45s%11.3e\n", "Ionic strength (mol/kgw) = ", (double) mu_x)); output_msg(sformatf("%45s%11.3e\n", "Mass of water (kg) = ", (double) mass_water_aq_x)); diff --git a/read.cpp b/read.cpp index 311bbb58..7bb33894 100644 --- a/read.cpp +++ b/read.cpp @@ -8330,11 +8330,12 @@ read_debug(void) "convergence_tolerance", /* 14 */ "numerical_derivatives", /* 15 */ "tries", /* 16 */ - "try", /* 17 */ - "numerical_fixed_volume", /* 18 */ - "force_numerical_fixed_volume" /* 19 */ + "try", /* 17 */ + "numerical_fixed_volume", /* 18 */ + "force_numerical_fixed_volume", /* 19 */ + "equi_delay" /* 20 */ }; - int count_opt_list = 20; + int count_opt_list = 21; /* * Read parameters: * ineq_tol; @@ -8427,6 +8428,9 @@ read_debug(void) case 19: /* debug_inverse */ force_numerical_fixed_volume = (get_true_false(next_char, TRUE) == TRUE); break; + case 20: /* equi_delay */ + sscanf(next_char, "%d", &equi_delay); + break; } if (return_value == EOF || return_value == KEYWORD) break; diff --git a/readtr.cpp b/readtr.cpp index 2a420772..facff8d3 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -21,19 +21,19 @@ int Phreeqc:: read_transport(void) /* ---------------------------------------------------------------------- */ { - /* - * Reads advection and column information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ +/* + * Reads advection and column information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ char *ptr; int i, j, l; int count_length, count_disp, count_punch, count_print, count_por; @@ -96,9 +96,9 @@ read_transport(void) int count_opt_list = 44; strcpy(file_name, "phreeqc.dmp"); - /* - * Initialize - */ +/* + * Initialize + */ simul_tr++; if (simul_tr == 1) { @@ -111,7 +111,7 @@ read_transport(void) old_cells = count_cells; count_length = count_disp = count_punch = count_print = count_por = 0; - length = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); + length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); if (length == NULL) malloc_error(); @@ -127,25 +127,25 @@ read_transport(void) if (punch_temp == NULL) malloc_error(); - print_temp = (int *)PHRQ_malloc(sizeof(int)); + print_temp = (int *) PHRQ_malloc(sizeof(int)); if (print_temp == NULL) malloc_error(); count_length_alloc = count_disp_alloc = count_por_alloc = 1; transport_start = 1; - /* - * Read transport number (not currently used) - */ +/* + * Read transport number (not currently used) + */ ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); - description = (char *)free_check_null(description); - /* - * Set use data to last read - */ + description = (char *) free_check_null(description); +/* + * Set use data to last read + */ use.Set_trans_in(true); - /* - * Read lines - */ +/* + * Read lines + */ opt_save = OPTION_DEFAULT; return_value = UNKNOWN; for (;;) @@ -190,7 +190,7 @@ read_transport(void) input_error++; error_msg ("Expected shift direction, -1, 0, 1. Use -direction instead.", - CONTINUE); + CONTINUE); ishift = 1; } } @@ -200,7 +200,7 @@ read_transport(void) case 20: /* print_cells */ print_temp = read_list_ints_range(&next_char, &count_print, FALSE, - print_temp); + print_temp); opt_save = 2; break; case 3: /* selected_output */ @@ -211,7 +211,7 @@ read_transport(void) if (punch_modulus <= 0) { error_string = sformatf( - "Punch frequency must be greater than 0. Frequency set to 1000."); + "Punch frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); punch_modulus = 1000; } @@ -231,7 +231,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -247,7 +247,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } /* last cell boundary condition */ @@ -261,7 +261,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -277,7 +277,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -304,7 +304,7 @@ read_transport(void) { mcd_substeps = 1.0; warning_msg("Substep factor in MCD must be >= 1.0\n" - "mcd_substeps = 1.0 assumed."); + "mcd_substeps = 1.0 assumed."); } opt_save = OPTION_DEFAULT; break; @@ -324,7 +324,7 @@ read_transport(void) tempr = 1; warning_msg ("Temperature retardation factor < 1 is not possible.\n" - "Temperature retardation factor = 1 assumed."); + "Temperature retardation factor = 1 assumed."); } j = copy_token(token, &next_char, &l); if (j == DIGIT) @@ -335,11 +335,11 @@ read_transport(void) case 24: /* lengths */ if (read_line_LDBLEs (next_char, &length, &count_length, - &count_length_alloc) == ERROR) + &count_length_alloc) == ERROR) { input_error++; error_msg("Reading lengths in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 8; break; @@ -351,7 +351,7 @@ read_transport(void) { input_error++; error_msg("Reading dispersivities in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 9; break; @@ -360,7 +360,7 @@ read_transport(void) case 30: /* punch_cells */ punch_temp = read_list_ints_range(&next_char, &count_punch, FALSE, - punch_temp); + punch_temp); opt_save = 10; break; case 11: /* stagnant */ @@ -371,7 +371,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting number of stagnant layers."); + "Expecting number of stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -384,7 +384,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting exchange factor for stagnant layers."); + "Expecting exchange factor for stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -393,7 +393,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the mobile zone."); + "Expecting porosity in the mobile zone."); error_msg(error_string, CONTINUE); break; } @@ -402,7 +402,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the immobile zone."); + "Expecting porosity in the immobile zone."); error_msg(error_string, CONTINUE); break; } @@ -428,7 +428,7 @@ read_transport(void) input_error++; error_msg ("Expected flow direction to be 'forward', 'back', or 'no_flow'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -452,7 +452,7 @@ read_transport(void) if (print_modulus <= 0) { error_string = sformatf( - "Print frequency must be greater than 0. Frequency set to 1000."); + "Print frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); print_modulus = 1000; } @@ -513,7 +513,7 @@ read_transport(void) input_error++; error_msg ("Expected multicomponent diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } default_Dw = 1e-9; multi_Dpor = 0.3; @@ -528,7 +528,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected default species diffusion coefficient in water at 25oC, m2/s."); + "Expected default species diffusion coefficient in water at 25oC, m2/s."); error_msg(error_string, CONTINUE); break; } @@ -542,7 +542,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity to calculate diffusion coefficient."); + "Expected porosity to calculate diffusion coefficient."); error_msg(error_string, CONTINUE); break; } @@ -556,7 +556,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity limit for diffusive transport."); + "Expected porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -569,7 +569,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); + "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); error_msg(error_string, CONTINUE); break; } @@ -588,7 +588,7 @@ read_transport(void) input_error++; error_msg ("Expected interlayer diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } interlayer_Dpor = 0.1; interlayer_Dpor_lim = 0.0; @@ -601,7 +601,7 @@ read_transport(void) if (sscanf(token, SCANFORMAT, &interlayer_Dpor) != 1) { input_error++; - error_string = sformatf("Expected interlayer porosity."); + error_string = sformatf( "Expected interlayer porosity."); error_msg(error_string, CONTINUE); break; } @@ -615,7 +615,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer porosity limit for diffusive transport."); + "Expected interlayer porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -628,7 +628,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); + "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); error_msg(error_string, CONTINUE); break; } @@ -651,9 +651,9 @@ read_transport(void) if (return_value == EOF || return_value == KEYWORD) break; } - /* - * Determine number of cells - */ +/* + * Determine number of cells + */ max_cells = count_cells; if (count_length > max_cells) max_cells = count_length; @@ -666,8 +666,8 @@ read_transport(void) if (max_cells == count_length) { sprintf(token, - "Number of cells is increased to number of 'lengths' %d.", - count_length); + "Number of cells is increased to number of 'lengths' %d.", + count_length); warning_msg(token); } else if (max_cells == count_disp) @@ -685,9 +685,9 @@ read_transport(void) // warning_msg(token); //} } - /* - * Allocate space for cell_data - */ +/* + * Allocate space for cell_data + */ int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; space((void **)((void *)&cell_data), all_cells_now, &cell_data_max_cells, sizeof(struct cell_data)); @@ -701,7 +701,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = 0.3; + cell_data[i].por = 0.3; cell_data[i].por_il = 0.01; cell_data[i].potV = 0; cell_data[i].punch = FALSE; @@ -710,15 +710,15 @@ read_transport(void) all_cells = all_cells_now; } - /* - * Fill in data for lengths - */ +/* + * Fill in data for lengths + */ if (count_length == 0) { if (old_cells < max_cells) { error_string = sformatf( - "No cell-lengths were read; length = 1 m assumed."); + "No cell-lengths were read; length = 1 m assumed."); warning_msg(error_string); for (i = 1; i <= max_cells; i++) cell_data[i].length = 1.0; @@ -733,8 +733,8 @@ read_transport(void) if (max_cells > count_length) { error_string = sformatf( - "Cell-lengths were read for %d cells. Last value is used till cell %d.", - count_length, max_cells); + "Cell-lengths were read for %d cells. Last value is used till cell %d.", + count_length, max_cells); warning_msg(error_string); for (i = count_length; i <= max_cells; i++) cell_data[i + 1].length = length[count_length - 1]; @@ -749,9 +749,9 @@ read_transport(void) } cell_data[max_cells + 1].mid_cell_x = cell_data[max_cells].mid_cell_x + cell_data[max_cells].length / 2; - /* - * Fill in data for dispersivities - */ +/* + * Fill in data for dispersivities + */ if (count_disp == 0) { if (old_cells < max_cells) @@ -777,9 +777,9 @@ read_transport(void) cell_data[i + 1].disp = disp[count_disp - 1]; } } - /* - * Fill in data for porosities - */ +/* + * Fill in data for porosities + */ if (count_por == 0) { if (old_cells < all_cells && multi_Dflag) @@ -838,9 +838,9 @@ read_transport(void) cell_data[i].por_il = interlayer_Dpor; } count_cells = max_cells; - /* - * Account for stagnant cells - */ +/* + * Account for stagnant cells + */ if (stag_data->count_stag > 0) { max_cells = count_cells * (1 + stag_data->count_stag) + 2; @@ -848,12 +848,12 @@ read_transport(void) { for (l = 1; l <= stag_data->count_stag; l++) cell_data[i + 1 + l * count_cells].mid_cell_x = - cell_data[i].mid_cell_x; + cell_data[i].mid_cell_x; } } - /* - * Fill in data for punch - */ +/* + * Fill in data for punch + */ if (count_punch != 0) { for (i = 0; i < all_cells; i++) @@ -863,8 +863,8 @@ read_transport(void) if (punch_temp[i] > all_cells - 1 || punch_temp[i] < 0) { error_string = sformatf( - "Cell number for punch is out of range, %d. Request ignored.", - punch_temp[i]); + "Cell number for punch is out of range, %d. Request ignored.", + punch_temp[i]); warning_msg(error_string); } else @@ -874,9 +874,9 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].punch = TRUE; - /* - * Fill in data for print - */ +/* + * Fill in data for print + */ if (count_print != 0) { for (i = 0; i < all_cells; i++) @@ -886,8 +886,8 @@ read_transport(void) if (print_temp[i] > all_cells - 1 || print_temp[i] < 0) { error_string = sformatf( - "Cell number for print is out of range, %d. Request ignored.", - print_temp[i]); + "Cell number for print is out of range, %d. Request ignored.", + print_temp[i]); warning_msg(error_string); } else @@ -897,9 +897,40 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].print = TRUE; +//#define OLD_POROSITY +#if defined(OLD_POROSITY) /* - * Calculate dump_modulus - */ + * Fill in porosities + */ + if (interlayer_Dflag && !multi_Dflag) + { + input_error++; + error_string = sformatf( + "-multi_D must be defined, when -interlayer_D true."); + error_msg(error_string, CONTINUE); + + } + for (i = 0; i < max_cells; i++) + { + multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); //Fix for Jenkins !!!!!!!!!!!! + //if (cell_data[i].por < 0) + { + cell_data[i].por = multi_Dpor; //Fix for Jenkins !!!!!!!!!!!! + } + interlayer_Dpor = (interlayer_Dpor < 1e-10 ? 1e-10 : interlayer_Dpor); + cell_data[i].por_il = interlayer_Dpor; + } +#endif + //{ + // for (int i = 0; i < all_cells; i++) + // { + // std::cerr << i << " " << cell_data[i].por << std::endl; + // } + //} + +/* + * Calculate dump_modulus + */ if (dump_in == TRUE) { if (dump_modulus == 0) @@ -914,14 +945,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Starting shift for transport, %d, is greater than number of shifts, %d.", - transport_start, count_shifts); + "Starting shift for transport, %d, is greater than number of shifts, %d.", + transport_start, count_shifts); error_msg(error_string, CONTINUE); } } - /* - * Check boundary conditions - */ +/* + * Check boundary conditions + */ if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) { warning_msg @@ -931,17 +962,17 @@ read_transport(void) if (bcon_last == 2) bcon_last = 3; } - /* - * Retain data from previous run - */ +/* + * Retain data from previous run + */ if (simul_tr > 1) { if ((count_length == 0) && (count_disp == 0) && (count_por == 0)) dup_print("Column data retained from former run", TRUE); } - /* - * Check heat_diffc - */ +/* + * Check heat_diffc + */ if (heat_diffc < 0) heat_diffc = diffc; else if (stag_data->count_stag == 1) @@ -952,14 +983,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); + "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } else if (heat_diffc > diffc) { error_string = sformatf( - "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", - (double)diffc); + "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", + (double) diffc); warning_msg(error_string); } } @@ -969,7 +1000,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); + "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } } @@ -978,17 +1009,17 @@ read_transport(void) { input_error++; error_string = sformatf( - "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); + "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } - /* - * free storage for length, disp, punch - */ - length = (LDBLE *)free_check_null(length); - disp = (LDBLE *)free_check_null(disp); - pors = (LDBLE *)free_check_null(pors); - punch_temp = (int *)free_check_null(punch_temp); - print_temp = (int *)free_check_null(print_temp); +/* + * free storage for length, disp, punch + */ + length = (LDBLE *) free_check_null(length); + disp = (LDBLE *) free_check_null(disp); + pors = (LDBLE *) free_check_null(pors); + punch_temp = (int *) free_check_null(punch_temp); + print_temp = (int *) free_check_null(print_temp); if (dump_in == TRUE) { @@ -1048,9 +1079,9 @@ int Phreeqc:: dump_cpp(void) /* ---------------------------------------------------------------------- */ { - /* - * dumps solution compositions to file - */ +/* + * dumps solution compositions to file + */ int l; @@ -1063,26 +1094,26 @@ dump_cpp(void) std::ofstream fs(dump_file_name_cpp.c_str()); if (!fs.is_open()) { - error_string = sformatf("Can`t open file, %s.", dump_file_name_cpp.c_str()); + error_string = sformatf( "Can`t open file, %s.", dump_file_name_cpp.c_str()); input_error++; error_msg(error_string, CONTINUE); return (OK); } - + fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n"; phreeqcBin.dump_raw(fs, 0); fs << "END" << "\n"; char token[MAX_LENGTH]; sprintf(token, "KNOBS\n"); - fs << token; + fs << token; sprintf(token, "\t-iter%15d\n", itmax); + fs << token; + sprintf(token, "\t-tol %15.3e\n", (double) ineq_tol); + fs << token; + sprintf(token, "\t-step%15.3e\n", (double) step_size); fs << token; - sprintf(token, "\t-tol %15.3e\n", (double)ineq_tol); - fs << token; - sprintf(token, "\t-step%15.3e\n", (double)step_size); - fs << token; - sprintf(token, "\t-pe_s%15.3e\n", (double)pe_step_size); + sprintf(token, "\t-pe_s%15.3e\n", (double) pe_step_size); fs << token; sprintf(token, "\t-diag "); fs << token; @@ -1097,12 +1128,12 @@ dump_cpp(void) fs << token; } std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); - for (; so_it != SelectedOutput_map.end(); so_it++) + for ( ; so_it != SelectedOutput_map.end(); so_it++) { current_selected_output = &(so_it->second); sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user()); - fs << token; + fs << token ; //sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); //fs << token; fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n"; @@ -1217,19 +1248,19 @@ dump_cpp(void) fs << token; sprintf(token, "\t-bcon %6d%6d\n", bcon_first, bcon_last); fs << token; - sprintf(token, "\t-timest %13.5e\n", (double)timest); + sprintf(token, "\t-timest %13.5e\n", (double) timest); fs << token; if (!high_precision) { - sprintf(token, "\t-diffc %13.5e\n", (double)diffc); + sprintf(token, "\t-diffc %13.5e\n", (double) diffc); fs << token; } else { - sprintf(token, "\t-diffc %20.12e\n", (double)diffc); + sprintf(token, "\t-diffc %20.12e\n", (double) diffc); fs << token; } - sprintf(token, "\t-tempr %13.5e\n", (double)tempr); + sprintf(token, "\t-tempr %13.5e\n", (double) tempr); fs << token; if (correct_disp == TRUE) { @@ -1245,7 +1276,7 @@ dump_cpp(void) fs << token; for (int i = 1; i <= count_cells; i++) { - sprintf(token, "%12.3e", (double)cell_data[i].length); + sprintf(token, "%12.3e", (double) cell_data[i].length); fs << token; if (i > 0 && (i % 8) == 0) { @@ -1261,12 +1292,12 @@ dump_cpp(void) { if (!high_precision) { - sprintf(token, "%12.3e", (double)cell_data[i].disp); + sprintf(token, "%12.3e", (double) cell_data[i].disp); fs << token; } else { - sprintf(token, "%20.12e", (double)cell_data[i].disp); + sprintf(token, "%20.12e", (double) cell_data[i].disp); fs << token; } if (i > 0 && (i % 8) == 0) @@ -1335,9 +1366,9 @@ int Phreeqc:: dump(void) /* ---------------------------------------------------------------------- */ { - /* - * dumps solution compositions to file - */ +/* + * dumps solution compositions to file + */ if (dump_in == FALSE || pr.dump == FALSE) return (OK); diff --git a/step.cpp b/step.cpp index 62cc917f..fd316275 100644 --- a/step.cpp +++ b/step.cpp @@ -1446,13 +1446,18 @@ solution_check(void) for (i = 0; i < count_master; i++) { master_ptr = master[i]; - if (master_ptr->total >= 0.0) - continue; - if (master_ptr->total > -MIN_TOTAL) + if (master_ptr->total <= MIN_TOTAL && master_ptr->total >= -MIN_TOTAL) { master_ptr->total = 0; continue; } + if (master_ptr->total >= 0.0) + continue; + //if (master_ptr->total > -MIN_TOTAL) + //{ + // master_ptr->total = 0; + // continue; + //} if (master_ptr->s == s_eminus || master_ptr->s == s_h2o || master_ptr->s == s_hplus || master_ptr->s == s_h3oplus) { diff --git a/tidy.cpp b/tidy.cpp index 5d1e57e8..d641a570 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3815,10 +3815,10 @@ tidy_min_surface(void) } cxxSurface *surface_ptr = &(kit->second); if (!surface_ptr->Get_new_def()) continue; - //if (!surface_ptr->Get_new_def()) - // continue; - //if (surface_ptr->Get_n_user() < 0) - // continue; + if (!surface_ptr->Get_new_def()) + continue; + if (surface_ptr->Get_n_user() < 0) + continue; for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { cxxSurfaceComp *surface_comp_ptr = &(surface_ptr->Get_surface_comps()[j]); @@ -3917,8 +3917,15 @@ tidy_min_surface(void) free_check_null(temp_formula); } { - cxxNameDouble nd = elt_list_NameDouble(); - surface_comp_ptr->Set_totals(nd); + if (surface_ptr->Get_new_def()) + { + cxxNameDouble nd = elt_list_NameDouble(); + surface_comp_ptr->Set_totals(nd); + } + else + { + surface_comp_ptr->Get_totals()[surface_comp_ptr->Get_master_element()] = conc; + } } /* area */ @@ -3938,40 +3945,6 @@ tidy_min_surface(void) get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } -#ifdef SKIP - for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) - { - cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]); - continue; - if (surface_ptr->Get_type() == cxxSurface::CD_MUSIC) - { - char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str()); - char *ptr = temp_formula; - get_elts_in_species(&ptr, - -comp_jj_ptr->Get_phase_proportion()); - free_check_null(temp_formula); - } - else - { - struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); - if (elt_ptr->master->s->z != 0.0) - { - input_error++; - error_string = sformatf( - "Master species of surface, %s, must be uncharged if the number of sites is related to a phase.", - elt_ptr->master->s->name); - error_msg(error_string, CONTINUE); - } - { - char * temp_name = string_duplicate(elt_ptr->master->s->name); - char *ptr = temp_name; - get_elts_in_species(&ptr, - -comp_jj_ptr->Get_phase_proportion()); - free_check_null(temp_name); - } - } - } -#endif // Revise logic for surface related to mineral for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++) { @@ -3988,13 +3961,28 @@ tidy_min_surface(void) // Warn if not master species and charge balanced struct element *elt_ptr = element_store(comp_jj_ptr->Get_master_element().c_str()); + if (elt_ptr->master == NULL) + { + input_error++; + error_string = sformatf("Unknown element definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", + surface_ptr->Get_n_user()); + error_msg(error_string); + continue; + } + if (elt_ptr->master->s == NULL || elt_ptr->master->s->name == NULL) + { + input_error++; + error_string = sformatf("Unknown master species definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", + surface_ptr->Get_n_user()); + error_msg(error_string); + continue; + } if (strcmp(elt_ptr->master->s->name, temp_formula) != 0) { error_string = sformatf("Suggest using master species formula in SURFACE \n\t for surface related to equilibrium_phase: %s.", elt_ptr->master->s->name); warning_msg(error_string); } - else if (elt_ptr->master->s->z != 0.0) { error_string = sformatf( @@ -4071,10 +4059,10 @@ tidy_kin_surface(void) assert(false); } cxxSurface *surface_ptr = &(it->second); - //if (!surface_ptr->Get_new_def()) - // continue; - //if (surface_ptr->Get_n_user() < 0) - // continue; + if (!surface_ptr->Get_new_def()) + continue; + if (surface_ptr->Get_n_user() < 0) + continue; int n = surface_ptr->Get_n_user(); for (size_t j = 0; j < surface_ptr->Get_surface_comps().size(); j++) { @@ -4161,8 +4149,15 @@ tidy_kin_surface(void) free_check_null(temp_formula); } { - cxxNameDouble nd = elt_list_NameDouble(); - comp_ptr->Set_totals(nd); + if (surface_ptr->Get_new_def()) + { + cxxNameDouble nd = elt_list_NameDouble(); + comp_ptr->Set_totals(nd); + } + else + { + comp_ptr->Get_totals()[comp_ptr->Get_master_element()] = conc; + } } /* area */ @@ -4946,6 +4941,15 @@ ss_calc_a0_a1(cxxSS *ss_ptr) tol = 1e-6; rt = ss_ptr->Get_tk() * R_KJ_DEG_MOL; + if (ss_ptr->Get_ss_comps().size() < 2) + { + input_error++; + error_string = sformatf( + "Two components not defined for solid solution ", + ss_ptr->Get_name().c_str()); + error_msg(error_string, CONTINUE); + return (ERROR); + } cxxSScomp *comp0_ptr = &(ss_ptr->Get_ss_comps()[0]); cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]); int k; From 810f51a257b87aac5add3a18a7a62f9d602a1bf0 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Mar 2016 17:35:12 +0000 Subject: [PATCH 1000/1077] two changes for vm_tc, always calc_delta_v git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10929 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 2 +- prep.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index c9e30af2..01c3dcad 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -486,7 +486,7 @@ calc_logk_s(const char *name) s_ptr = s_search(token); if (s_ptr != NULL) { - if (s_ptr->logk[vm_tc]) + //if (s_ptr->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false); for (i = 0; i < MAX_LOG_K_INDICES; i++) diff --git a/prep.cpp b/prep.cpp index 89f102d5..d783dccf 100644 --- a/prep.cpp +++ b/prep.cpp @@ -5717,7 +5717,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ mu_terms_in_logk = false; for (i = 0; i < count_s_x; i++) { - if (s_x[i]->rxn_x->logk[vm_tc]) + //if (s_x[i]->rxn_x->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) From d5e7aa0ab30ea38366330bb182f4c4ebcbab6a17 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Mar 2016 19:59:35 +0000 Subject: [PATCH 1001/1077] Tony's changes. Call calc_delta_v always. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10930 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- SurfaceCharge.h | 3 +- basicsubs.cpp | 2 +- prep.cpp | 8 ++-- transport.cpp | 109 +++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 97 insertions(+), 25 deletions(-) diff --git a/SurfaceCharge.h b/SurfaceCharge.h index 7d284fbc..fa5711eb 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -101,7 +101,8 @@ public: void Set_sigma2(LDBLE d) {this->sigma2 = d;} LDBLE Get_sigmaddl() const {return this->sigmaddl;} void Set_sigmaddl(LDBLE d) {this->sigmaddl = d;} - const cxxNameDouble & Get_diffuse_layer_totals(void) const {return this->diffuse_layer_totals;} + cxxNameDouble & Get_diffuse_layer_totals(void) { return this->diffuse_layer_totals; } + const cxxNameDouble & Get_diffuse_layer_totals(void)const { return this->diffuse_layer_totals; } void Set_diffuse_layer_totals(cxxNameDouble & nd) {this->diffuse_layer_totals = nd;} std::map &Get_g_map(void) {return g_map;} void Set_g_map(std::map & t) {g_map = t;} diff --git a/basicsubs.cpp b/basicsubs.cpp index b4aa5f63..9aae8fce 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -684,7 +684,7 @@ calc_logk_s(const char *name) s_ptr = s_search(token); if (s_ptr != NULL) { - if (s_ptr->logk[vm_tc]) + //if (s_ptr->logk[vm_tc]) /* calculate delta_v for the reaction... */ s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false); for (i = 0; i < MAX_LOG_K_INDICES; i++) diff --git a/prep.cpp b/prep.cpp index 89f102d5..beb44728 100644 --- a/prep.cpp +++ b/prep.cpp @@ -3727,7 +3727,7 @@ setup_surface(void) * check related kinetics */ if (use.Get_surface_ptr()->Get_related_rate()) - { + { cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) { @@ -5717,8 +5717,8 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ mu_terms_in_logk = false; for (i = 0; i < count_s_x; i++) { - if (s_x[i]->rxn_x->logk[vm_tc]) - /* calculate delta_v for the reaction... */ + //if (s_x[i]->rxn_x->logk[vm_tc]) + /* calculate delta_v for the reaction, assume Vm = 0 if not defined for a species... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) continue; @@ -6149,7 +6149,7 @@ check_same_model(void) surf_ptr->Set_new_def(true); this->tidy_min_surface(); return (FALSE); - } + } } if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) { diff --git a/transport.cpp b/transport.cpp index 545a9fcd..6764dbcd 100644 --- a/transport.cpp +++ b/transport.cpp @@ -188,16 +188,31 @@ transport(void) if (dV_dcell) { - if (stag_data->count_stag || !multi_Dflag || ishift) + if (/*stag_data->count_stag || */!multi_Dflag || ishift) { input_error++; error_string = sformatf( - "Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with -stagnant or with advective flow."); + //"Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with -stagnant or with advective flow."); + "Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with advective flow."); error_msg(error_string, CONTINUE); free_check_null(sol_D); } else { + if (bcon_first != 1) + { + bcon_first = 1; + error_string = sformatf( + "Electrical Field (potential) was defined, assuming constant boundary condition for first cell."); + warning_msg(error_string); + } + if (bcon_last != 1) + { + bcon_last = 1; + error_string = sformatf( + "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); + warning_msg(error_string); + } current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) (count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) @@ -512,12 +527,12 @@ transport(void) run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag) + if (multi_Dflag && j < nmix) fill_spec(i); /* punch and output file */ if ((ishift == 0) && (j == nmix) - && ((stag_data->count_stag == 0) + && ((stag_data->count_stag == 0) || i == 0 || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { if ((cell_data[i].punch == TRUE) @@ -569,8 +584,18 @@ transport(void) else punch_boolean = FALSE; for (i = 1; i <= count_cells; i++) - mix_stag(i, stagkin_time, punch_boolean, - step_fraction); + mix_stag(i, stagkin_time, punch_boolean, step_fraction); + if (punch_boolean + && ((cell_data[i].punch == TRUE && transport_step % punch_modulus == 0) + || (cell_data[i].print == TRUE && transport_step % print_modulus == 0))) + { + cell_no = i; + run_reactions(i, 0, NOMIX, 0); + if (cell_data[i].punch == TRUE) + punch_all(); + if (cell_data[i].print == TRUE) + print_all(); + } } } } @@ -682,7 +707,7 @@ transport(void) transport_step, 0, i, max_iter); status(0, token); run_reactions(i, kin_time, NOMIX, step_fraction); - if (multi_Dflag == TRUE) + if (multi_Dflag == TRUE && j < nmix) fill_spec(i); if (iterations > max_iter) max_iter = iterations; @@ -800,10 +825,10 @@ transport(void) run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag == TRUE) + if (multi_Dflag == TRUE && j < nmix) fill_spec(i); - if ((j == nmix) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + if ((j == nmix) && (stag_data->count_stag == 0 || i == 0 + || (i != 1 + count_cells && Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -817,8 +842,8 @@ transport(void) saver(); /* maybe sorb a surface component... */ - if ((j == nmix) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + if ((j == nmix) && ((stag_data->count_stag == 0) + || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -853,6 +878,17 @@ transport(void) punch_boolean = FALSE; for (i = 1; i <= count_cells; i++) mix_stag(i, stagkin_time, punch_boolean, step_fraction); + if (punch_boolean + && ((cell_data[i].punch == TRUE && transport_step % punch_modulus == 0) + || (cell_data[i].print == TRUE && transport_step % print_modulus == 0))) + { + cell_no = i; + run_reactions(i, 0, NOMIX, 0); + if (cell_data[i].punch == TRUE) + punch_all(); + if (cell_data[i].print == TRUE) + print_all(); + } } } if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) @@ -1861,7 +1897,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) il_calcs = -1; current_x = sum_R = sum_Rd = 0.0; - if (dV_dcell) + if (dV_dcell && !stagnant) find_current = loop_f_c = 1; // calculate J_ij once for all cells, find smallest j_x, next with this j_x. else find_current = loop_f_c = 0; @@ -1956,11 +1992,13 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) { tot1_h = tot1_o = tot2_h = tot2_o = 0.0; m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t)count_elements * + count_m_s = (ct[icell].J_ij_count_spec < count_elements ? + ct[icell].J_ij_count_spec : count_elements); + m_s = (struct M_S *) PHRQ_malloc((size_t)count_m_s * sizeof(struct M_S)); if (m_s == NULL) malloc_error(); - for (i1 = 0; i1 < count_elements; i1++) + for (i1 = 0; i1 < count_m_s; i1++) { m_s[i1].name = NULL; m_s[i1].tot1 = 0; @@ -1978,7 +2016,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); - if (dV_dcell && i > 0) + if (dV_dcell && i > 0 && !stagnant) { use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); } @@ -2043,7 +2081,37 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) { + if (strcmp(it->first.c_str(), "H(0)") == 0) + continue; + if (strcmp(it->first.c_str(), "O(0)") == 0) + continue; LDBLE moles = it->second; + if (moles < 0 && ct[i].dl_s) + { + use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); + cxxSurface * s_ptr = use.Get_surface_ptr(); + cxxSurfaceCharge * charge_ptr; + for (size_t j = 0; j < s_ptr->Get_surface_charges().size(); j++) + { + if (s_ptr->Get_dl_type() == cxxSurface::DONNAN_DL) + { + charge_ptr = &(s_ptr->Get_surface_charges()[j]); + break; + } + } + cxxNameDouble::iterator jit; + for (jit = charge_ptr->Get_diffuse_layer_totals().begin(); jit != charge_ptr->Get_diffuse_layer_totals().end(); jit++) + { + if (strcmp(jit->first.c_str(), "H") == 0 || strcmp(jit->first.c_str(), "O") == 0) + continue; + if (strcmp(jit->first.c_str(), it->first.c_str()) == 0) + { + moles += jit->second; + it->second += jit->second; + jit->second = 0; + } + } + } if (moles < 0) { temp = moles; @@ -2241,7 +2309,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else il_calcs = 0; - if (dV_dcell && !find_current) + if (dV_dcell && !find_current && !stagnant) goto dV_dcell2; ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); @@ -3129,7 +3197,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].J_ij_count_spec = i_max = k; ct[icell].J_ij_il_count_spec = k_il; - if (dV_dcell) + if (dV_dcell && !stagnant) { current_cells[icell].ele = current_cells[icell].dif = 0; dum = dV_dcell * F_Re3 / tk_x2; @@ -3201,8 +3269,11 @@ dV_dcell2: ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; } } + // ensure that icell has dl water when checking negative conc's in MCD + ct[icell].dl_s = dl_aq_i; + ct[jcell].dl_s = dl_aq_j; - if (dV_dcell) + if (dV_dcell && !stagnant) { // perhaps adapt dV for getting equal current... current_cells[icell].ele = current_cells[icell].dif = 0; From 48b4d8706abb49399b566ec76977d270d3c8fa0c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 10 Mar 2016 16:17:45 +0000 Subject: [PATCH 1002/1077] Added asserts to inverse.cpp (had -1 for a row number). Ensure that master species for an element contains the element. Fixed memory leaks if problems detected in read_master_species. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@10932 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 3 +++ read.cpp | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index 8057c28f..b0d6686f 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -569,6 +569,9 @@ setup_inverse(struct inverse *inv_ptr) { row = master_ptr->in; } + assert(row * max_column_count + column < max_column_count * max_row_count); + assert(row >= 0); + assert(column >= 0); array[row * max_column_count + column] = rxn_ptr->token[j].coef; /* if coefficient of element is not 1.0 in master species */ diff --git a/read.cpp b/read.cpp index 77a3435b..ae0533b1 100644 --- a/read.cpp +++ b/read.cpp @@ -3259,15 +3259,16 @@ read_master_species(void) space((void **) ((void *) &master), count_master + 1, &max_master, sizeof(struct master *)); } - master[count_master] = master_alloc(); + master[count_master++] = master_alloc(); /* * Set type to AQ */ - master[count_master]->type = AQ; + master[count_master-1]->type = AQ; /* * Save element name */ - master[count_master]->elt = element_store(token); + master[count_master-1]->elt = element_store(token); + std::string ename = token; /* * Save pointer to species data for master species */ @@ -3283,20 +3284,33 @@ read_master_species(void) s_ptr = s_search(token); if (s_ptr != NULL) { - master[count_master]->s = s_ptr; + master[count_master-1]->s = s_ptr; } else { ptr1 = token; get_token(&ptr1, token1, &l_z, &l); - master[count_master]->s = s_store(token1, l_z, FALSE); + master[count_master-1]->s = s_store(token1, l_z, FALSE); + } + + std::string sname = token; + replace("("," ", ename); + std::istringstream iss(ename); + iss >> ename; + if (ename != "e" && ename != "E" && ename != "Alkalinity" && std::string::npos == sname.find(ename)) + { + input_error++; + std::ostringstream oss; + oss << "Master species, " << sname << " must contain the element, " << ename; + error_msg(oss.str().c_str(), CONTINUE); + continue; } /* * Read alkalinity for species */ copy_token(token, &ptr, &l); - i = sscanf(token, SCANFORMAT, &master[count_master]->alk); + i = sscanf(token, SCANFORMAT, &master[count_master-1]->alk); if (i != 1) { input_error++; @@ -3320,11 +3334,11 @@ read_master_species(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, SCANFORMAT, &master[count_master]->gfw); + sscanf(token, SCANFORMAT, &master[count_master-1]->gfw); } else if (i == UPPER) { - master[count_master]->gfw_formula = string_hsave(token); + master[count_master-1]->gfw_formula = string_hsave(token); } else { @@ -3346,13 +3360,13 @@ read_master_species(void) /* * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES */ - if (strchr(master[count_master]->elt->name, '(') == NULL) + if (strchr(master[count_master-1]->elt->name, '(') == NULL) { - master[count_master]->primary = TRUE; + master[count_master-1]->primary = TRUE; /* Read gram formula weight for primary */ - if (strcmp(master[count_master]->elt->name, "E") != 0) + if (strcmp(master[count_master-1]->elt->name, "E") != 0) { - elts_ptr = master[count_master]->elt; + elts_ptr = master[count_master-1]->elt; i = copy_token(token, &ptr, &l); if (i == DIGIT) { @@ -3380,9 +3394,8 @@ read_master_species(void) } else { - master[count_master]->primary = FALSE; + master[count_master-1]->primary = FALSE; } - count_master++; if (count_master >= max_master) { space((void **) ((void *) &master), count_master, &max_master, From d2dba8c291db33c5a4a656ef227146f46595e345 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sat, 26 Mar 2016 20:11:29 +0000 Subject: [PATCH 1003/1077] Tony's latest changes. New test case SC_Ohm, added to Makefile. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10983 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + readtr.cpp | 303 ++++++++++++++++++++++++++------------------------ transport.cpp | 22 +++- 3 files changed, 179 insertions(+), 147 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index 6bd47b65..72e1d69c 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1408,6 +1408,7 @@ protected: int multi_Dflag; /* signals calc'n of multicomponent diffusion */ int interlayer_Dflag; /* multicomponent diffusion and diffusion through interlayer porosity */ LDBLE default_Dw; /* default species diffusion coefficient in water at 25oC, m2/s */ + int correct_Dw; /* if true, Dw is adapted in calc_SC */ LDBLE multi_Dpor; /* uniform porosity of free porewater in solid medium */ LDBLE interlayer_Dpor; /* uniform porosity of interlayer space of montmorillonite in solid medium */ LDBLE multi_Dpor_lim; /* limiting free porewater porosity where transport stops */ diff --git a/readtr.cpp b/readtr.cpp index facff8d3..1f987460 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -21,19 +21,19 @@ int Phreeqc:: read_transport(void) /* ---------------------------------------------------------------------- */ { -/* - * Reads advection and column information - * - * Arguments: - * none - * - * Returns: - * KEYWORD if keyword encountered, input_error may be incremented if - * a keyword is encountered in an unexpected position - * EOF if eof encountered while reading mass balance concentrations - * ERROR if error occurred reading data - * - */ + /* + * Reads advection and column information + * + * Arguments: + * none + * + * Returns: + * KEYWORD if keyword encountered, input_error may be incremented if + * a keyword is encountered in an unexpected position + * EOF if eof encountered while reading mass balance concentrations + * ERROR if error occurred reading data + * + */ char *ptr; int i, j, l; int count_length, count_disp, count_punch, count_print, count_por; @@ -96,9 +96,9 @@ read_transport(void) int count_opt_list = 44; strcpy(file_name, "phreeqc.dmp"); -/* - * Initialize - */ + /* + * Initialize + */ simul_tr++; if (simul_tr == 1) { @@ -111,7 +111,7 @@ read_transport(void) old_cells = count_cells; count_length = count_disp = count_punch = count_print = count_por = 0; - length = (LDBLE *) PHRQ_malloc(sizeof(LDBLE)); + length = (LDBLE *)PHRQ_malloc(sizeof(LDBLE)); if (length == NULL) malloc_error(); @@ -127,25 +127,25 @@ read_transport(void) if (punch_temp == NULL) malloc_error(); - print_temp = (int *) PHRQ_malloc(sizeof(int)); + print_temp = (int *)PHRQ_malloc(sizeof(int)); if (print_temp == NULL) malloc_error(); count_length_alloc = count_disp_alloc = count_por_alloc = 1; transport_start = 1; -/* - * Read transport number (not currently used) - */ + /* + * Read transport number (not currently used) + */ ptr = line; read_number_description(ptr, &n_user, &n_user_end, &description); - description = (char *) free_check_null(description); -/* - * Set use data to last read - */ + description = (char *)free_check_null(description); + /* + * Set use data to last read + */ use.Set_trans_in(true); -/* - * Read lines - */ + /* + * Read lines + */ opt_save = OPTION_DEFAULT; return_value = UNKNOWN; for (;;) @@ -190,7 +190,7 @@ read_transport(void) input_error++; error_msg ("Expected shift direction, -1, 0, 1. Use -direction instead.", - CONTINUE); + CONTINUE); ishift = 1; } } @@ -200,7 +200,7 @@ read_transport(void) case 20: /* print_cells */ print_temp = read_list_ints_range(&next_char, &count_print, FALSE, - print_temp); + print_temp); opt_save = 2; break; case 3: /* selected_output */ @@ -211,7 +211,7 @@ read_transport(void) if (punch_modulus <= 0) { error_string = sformatf( - "Punch frequency must be greater than 0. Frequency set to 1000."); + "Punch frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); punch_modulus = 1000; } @@ -231,7 +231,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -247,7 +247,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } /* last cell boundary condition */ @@ -261,7 +261,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant' (1), 'closed' (2) , or 'flux' (3).", - CONTINUE); + CONTINUE); } } else if (i == EMPTY) @@ -277,7 +277,7 @@ read_transport(void) input_error++; error_msg ("Expected boundary condition to be 'constant', 'closed', or 'flux'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -304,7 +304,7 @@ read_transport(void) { mcd_substeps = 1.0; warning_msg("Substep factor in MCD must be >= 1.0\n" - "mcd_substeps = 1.0 assumed."); + "mcd_substeps = 1.0 assumed."); } opt_save = OPTION_DEFAULT; break; @@ -324,7 +324,7 @@ read_transport(void) tempr = 1; warning_msg ("Temperature retardation factor < 1 is not possible.\n" - "Temperature retardation factor = 1 assumed."); + "Temperature retardation factor = 1 assumed."); } j = copy_token(token, &next_char, &l); if (j == DIGIT) @@ -335,11 +335,11 @@ read_transport(void) case 24: /* lengths */ if (read_line_LDBLEs (next_char, &length, &count_length, - &count_length_alloc) == ERROR) + &count_length_alloc) == ERROR) { input_error++; error_msg("Reading lengths in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 8; break; @@ -351,7 +351,7 @@ read_transport(void) { input_error++; error_msg("Reading dispersivities in TRANSPORT keyword.\n", - CONTINUE); + CONTINUE); } opt_save = 9; break; @@ -360,7 +360,7 @@ read_transport(void) case 30: /* punch_cells */ punch_temp = read_list_ints_range(&next_char, &count_punch, FALSE, - punch_temp); + punch_temp); opt_save = 10; break; case 11: /* stagnant */ @@ -371,7 +371,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting number of stagnant layers."); + "Expecting number of stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -384,7 +384,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting exchange factor for stagnant layers."); + "Expecting exchange factor for stagnant layers."); error_msg(error_string, CONTINUE); break; } @@ -393,7 +393,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the mobile zone."); + "Expecting porosity in the mobile zone."); error_msg(error_string, CONTINUE); break; } @@ -402,7 +402,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expecting porosity in the immobile zone."); + "Expecting porosity in the immobile zone."); error_msg(error_string, CONTINUE); break; } @@ -428,7 +428,7 @@ read_transport(void) input_error++; error_msg ("Expected flow direction to be 'forward', 'back', or 'no_flow'.", - CONTINUE); + CONTINUE); } opt_save = OPTION_DEFAULT; break; @@ -452,7 +452,7 @@ read_transport(void) if (print_modulus <= 0) { error_string = sformatf( - "Print frequency must be greater than 0. Frequency set to 1000."); + "Print frequency must be greater than 0. Frequency set to 1000."); warning_msg(error_string); print_modulus = 1000; } @@ -513,12 +513,13 @@ read_transport(void) input_error++; error_msg ("Expected multicomponent diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } default_Dw = 1e-9; multi_Dpor = 0.3; multi_Dpor_lim = 0.0; multi_Dn = 1.0; + correct_Dw = 0; if (copy_token(token, &next_char, &l) == EMPTY) break; else @@ -528,7 +529,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected default species diffusion coefficient in water at 25oC, m2/s."); + "Expected default species diffusion coefficient in water at 25oC, m2/s."); error_msg(error_string, CONTINUE); break; } @@ -542,7 +543,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity to calculate diffusion coefficient."); + "Expected porosity to calculate diffusion coefficient."); error_msg(error_string, CONTINUE); break; } @@ -556,7 +557,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected porosity limit for diffusive transport."); + "Expected porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -569,11 +570,28 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); + "Expected exponent for porosity reduction of diffusion coefficient (Dp = Dw * (por)^n)."); error_msg(error_string, CONTINUE); break; } } + if (copy_token(token, &next_char, &l) == EMPTY) + break; + else + { + str_tolower(token); + if (strstr(token, "f") == token) + correct_Dw = 0; + else if (strstr(token, "t") == token) + correct_Dw = 1; + else + { + input_error++; + error_msg + ("Expected 'true' or 'false' for correcting Dw's as in Specific Conductance.", + CONTINUE); + } + } opt_save = OPTION_DEFAULT; break; case 41: /* interlayer diffusion */ @@ -588,7 +606,7 @@ read_transport(void) input_error++; error_msg ("Expected interlayer diffusion flag: 'true' or 'false'.", - CONTINUE); + CONTINUE); } interlayer_Dpor = 0.1; interlayer_Dpor_lim = 0.0; @@ -601,7 +619,7 @@ read_transport(void) if (sscanf(token, SCANFORMAT, &interlayer_Dpor) != 1) { input_error++; - error_string = sformatf( "Expected interlayer porosity."); + error_string = sformatf("Expected interlayer porosity."); error_msg(error_string, CONTINUE); break; } @@ -615,7 +633,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer porosity limit for diffusive transport."); + "Expected interlayer porosity limit for diffusive transport."); error_msg(error_string, CONTINUE); break; } @@ -628,7 +646,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); + "Expected interlayer tortuosity factor (Dp = Dw /t_f)."); error_msg(error_string, CONTINUE); break; } @@ -651,9 +669,9 @@ read_transport(void) if (return_value == EOF || return_value == KEYWORD) break; } -/* - * Determine number of cells - */ + /* + * Determine number of cells + */ max_cells = count_cells; if (count_length > max_cells) max_cells = count_length; @@ -666,8 +684,8 @@ read_transport(void) if (max_cells == count_length) { sprintf(token, - "Number of cells is increased to number of 'lengths' %d.", - count_length); + "Number of cells is increased to number of 'lengths' %d.", + count_length); warning_msg(token); } else if (max_cells == count_disp) @@ -685,9 +703,9 @@ read_transport(void) // warning_msg(token); //} } -/* - * Allocate space for cell_data - */ + /* + * Allocate space for cell_data + */ int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2; space((void **)((void *)&cell_data), all_cells_now, &cell_data_max_cells, sizeof(struct cell_data)); @@ -701,7 +719,7 @@ read_transport(void) cell_data[i].mid_cell_x = 1.0; cell_data[i].disp = 1.0; cell_data[i].temp = 25.0; - cell_data[i].por = 0.3; + cell_data[i].por = 0.3; cell_data[i].por_il = 0.01; cell_data[i].potV = 0; cell_data[i].punch = FALSE; @@ -710,15 +728,15 @@ read_transport(void) all_cells = all_cells_now; } -/* - * Fill in data for lengths - */ + /* + * Fill in data for lengths + */ if (count_length == 0) { if (old_cells < max_cells) { error_string = sformatf( - "No cell-lengths were read; length = 1 m assumed."); + "No cell-lengths were read; length = 1 m assumed."); warning_msg(error_string); for (i = 1; i <= max_cells; i++) cell_data[i].length = 1.0; @@ -733,8 +751,8 @@ read_transport(void) if (max_cells > count_length) { error_string = sformatf( - "Cell-lengths were read for %d cells. Last value is used till cell %d.", - count_length, max_cells); + "Cell-lengths were read for %d cells. Last value is used till cell %d.", + count_length, max_cells); warning_msg(error_string); for (i = count_length; i <= max_cells; i++) cell_data[i + 1].length = length[count_length - 1]; @@ -749,9 +767,9 @@ read_transport(void) } cell_data[max_cells + 1].mid_cell_x = cell_data[max_cells].mid_cell_x + cell_data[max_cells].length / 2; -/* - * Fill in data for dispersivities - */ + /* + * Fill in data for dispersivities + */ if (count_disp == 0) { if (old_cells < max_cells) @@ -777,9 +795,9 @@ read_transport(void) cell_data[i + 1].disp = disp[count_disp - 1]; } } -/* - * Fill in data for porosities - */ + /* + * Fill in data for porosities + */ if (count_por == 0) { if (old_cells < all_cells && multi_Dflag) @@ -793,7 +811,6 @@ read_transport(void) "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); for (i = old_cells + 1; i < all_cells; i++) - //for (i = old_cells; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } @@ -838,9 +855,9 @@ read_transport(void) cell_data[i].por_il = interlayer_Dpor; } count_cells = max_cells; -/* - * Account for stagnant cells - */ + /* + * Account for stagnant cells + */ if (stag_data->count_stag > 0) { max_cells = count_cells * (1 + stag_data->count_stag) + 2; @@ -848,12 +865,12 @@ read_transport(void) { for (l = 1; l <= stag_data->count_stag; l++) cell_data[i + 1 + l * count_cells].mid_cell_x = - cell_data[i].mid_cell_x; + cell_data[i].mid_cell_x; } } -/* - * Fill in data for punch - */ + /* + * Fill in data for punch + */ if (count_punch != 0) { for (i = 0; i < all_cells; i++) @@ -863,8 +880,8 @@ read_transport(void) if (punch_temp[i] > all_cells - 1 || punch_temp[i] < 0) { error_string = sformatf( - "Cell number for punch is out of range, %d. Request ignored.", - punch_temp[i]); + "Cell number for punch is out of range, %d. Request ignored.", + punch_temp[i]); warning_msg(error_string); } else @@ -874,9 +891,9 @@ read_transport(void) else if (simul_tr == 1) for (i = 1; i < all_cells; i++) cell_data[i].punch = TRUE; -/* - * Fill in data for print - */ + /* + * Fill in data for print + */ if (count_print != 0) { for (i = 0; i < all_cells; i++) @@ -886,8 +903,8 @@ read_transport(void) if (print_temp[i] > all_cells - 1 || print_temp[i] < 0) { error_string = sformatf( - "Cell number for print is out of range, %d. Request ignored.", - print_temp[i]); + "Cell number for print is out of range, %d. Request ignored.", + print_temp[i]); warning_msg(error_string); } else @@ -899,7 +916,7 @@ read_transport(void) cell_data[i].print = TRUE; //#define OLD_POROSITY #if defined(OLD_POROSITY) -/* + /* * Fill in porosities */ if (interlayer_Dflag && !multi_Dflag) @@ -929,8 +946,8 @@ read_transport(void) //} /* - * Calculate dump_modulus - */ + * Calculate dump_modulus + */ if (dump_in == TRUE) { if (dump_modulus == 0) @@ -945,14 +962,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Starting shift for transport, %d, is greater than number of shifts, %d.", - transport_start, count_shifts); + "Starting shift for transport, %d, is greater than number of shifts, %d.", + transport_start, count_shifts); error_msg(error_string, CONTINUE); } } -/* - * Check boundary conditions - */ + /* + * Check boundary conditions + */ if ((ishift != 0) && ((bcon_first == 2) || (bcon_last == 2))) { warning_msg @@ -962,17 +979,17 @@ read_transport(void) if (bcon_last == 2) bcon_last = 3; } -/* - * Retain data from previous run - */ + /* + * Retain data from previous run + */ if (simul_tr > 1) { if ((count_length == 0) && (count_disp == 0) && (count_por == 0)) dup_print("Column data retained from former run", TRUE); } -/* - * Check heat_diffc - */ + /* + * Check heat_diffc + */ if (heat_diffc < 0) heat_diffc = diffc; else if (stag_data->count_stag == 1) @@ -983,14 +1000,14 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); + "Must enter diffusion coefficient (-diffc) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } else if (heat_diffc > diffc) { error_string = sformatf( - "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", - (double) diffc); + "Thermal diffusion is calculated assuming exchange factor was for\n\t effective (non-thermal) diffusion coefficient = %e.", + (double)diffc); warning_msg(error_string); } } @@ -1000,7 +1017,7 @@ read_transport(void) { input_error++; error_string = sformatf( - "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); + "Must enter value for mobile/stagnant exchange factor when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } } @@ -1009,17 +1026,17 @@ read_transport(void) { input_error++; error_string = sformatf( - "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); + "Only one stagnant layer permitted (-stag) when modeling thermal diffusion."); error_msg(error_string, CONTINUE); } -/* - * free storage for length, disp, punch - */ - length = (LDBLE *) free_check_null(length); - disp = (LDBLE *) free_check_null(disp); - pors = (LDBLE *) free_check_null(pors); - punch_temp = (int *) free_check_null(punch_temp); - print_temp = (int *) free_check_null(print_temp); + /* + * free storage for length, disp, punch + */ + length = (LDBLE *)free_check_null(length); + disp = (LDBLE *)free_check_null(disp); + pors = (LDBLE *)free_check_null(pors); + punch_temp = (int *)free_check_null(punch_temp); + print_temp = (int *)free_check_null(print_temp); if (dump_in == TRUE) { @@ -1079,9 +1096,9 @@ int Phreeqc:: dump_cpp(void) /* ---------------------------------------------------------------------- */ { -/* - * dumps solution compositions to file - */ + /* + * dumps solution compositions to file + */ int l; @@ -1094,26 +1111,26 @@ dump_cpp(void) std::ofstream fs(dump_file_name_cpp.c_str()); if (!fs.is_open()) { - error_string = sformatf( "Can`t open file, %s.", dump_file_name_cpp.c_str()); + error_string = sformatf("Can`t open file, %s.", dump_file_name_cpp.c_str()); input_error++; error_msg(error_string, CONTINUE); return (OK); } - + fs << "# Dumpfile" << "\n" << "# Transport simulation " << simul_tr << " Shift " << transport_step << "\n" << "#" << "\n"; phreeqcBin.dump_raw(fs, 0); fs << "END" << "\n"; char token[MAX_LENGTH]; sprintf(token, "KNOBS\n"); - fs << token; - sprintf(token, "\t-iter%15d\n", itmax); - fs << token; - sprintf(token, "\t-tol %15.3e\n", (double) ineq_tol); - fs << token; - sprintf(token, "\t-step%15.3e\n", (double) step_size); fs << token; - sprintf(token, "\t-pe_s%15.3e\n", (double) pe_step_size); + sprintf(token, "\t-iter%15d\n", itmax); + fs << token; + sprintf(token, "\t-tol %15.3e\n", (double)ineq_tol); + fs << token; + sprintf(token, "\t-step%15.3e\n", (double)step_size); + fs << token; + sprintf(token, "\t-pe_s%15.3e\n", (double)pe_step_size); fs << token; sprintf(token, "\t-diag "); fs << token; @@ -1128,12 +1145,12 @@ dump_cpp(void) fs << token; } std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); - for ( ; so_it != SelectedOutput_map.end(); so_it++) + for (; so_it != SelectedOutput_map.end(); so_it++) { current_selected_output = &(so_it->second); sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user()); - fs << token ; + fs << token; //sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn"); //fs << token; fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n"; @@ -1248,19 +1265,19 @@ dump_cpp(void) fs << token; sprintf(token, "\t-bcon %6d%6d\n", bcon_first, bcon_last); fs << token; - sprintf(token, "\t-timest %13.5e\n", (double) timest); + sprintf(token, "\t-timest %13.5e\n", (double)timest); fs << token; if (!high_precision) { - sprintf(token, "\t-diffc %13.5e\n", (double) diffc); + sprintf(token, "\t-diffc %13.5e\n", (double)diffc); fs << token; } else { - sprintf(token, "\t-diffc %20.12e\n", (double) diffc); + sprintf(token, "\t-diffc %20.12e\n", (double)diffc); fs << token; } - sprintf(token, "\t-tempr %13.5e\n", (double) tempr); + sprintf(token, "\t-tempr %13.5e\n", (double)tempr); fs << token; if (correct_disp == TRUE) { @@ -1276,7 +1293,7 @@ dump_cpp(void) fs << token; for (int i = 1; i <= count_cells; i++) { - sprintf(token, "%12.3e", (double) cell_data[i].length); + sprintf(token, "%12.3e", (double)cell_data[i].length); fs << token; if (i > 0 && (i % 8) == 0) { @@ -1292,12 +1309,12 @@ dump_cpp(void) { if (!high_precision) { - sprintf(token, "%12.3e", (double) cell_data[i].disp); + sprintf(token, "%12.3e", (double)cell_data[i].disp); fs << token; } else { - sprintf(token, "%20.12e", (double) cell_data[i].disp); + sprintf(token, "%20.12e", (double)cell_data[i].disp); fs << token; } if (i > 0 && (i % 8) == 0) @@ -1366,9 +1383,9 @@ int Phreeqc:: dump(void) /* ---------------------------------------------------------------------- */ { -/* - * dumps solution compositions to file - */ + /* + * dumps solution compositions to file + */ if (dump_in == FALSE || pr.dump == FALSE) return (OK); diff --git a/transport.cpp b/transport.cpp index 6764dbcd..26dd997d 100644 --- a/transport.cpp +++ b/transport.cpp @@ -527,7 +527,7 @@ transport(void) run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag && j < nmix) + if (multi_Dflag) fill_spec(i); /* punch and output file */ @@ -707,7 +707,7 @@ transport(void) transport_step, 0, i, max_iter); status(0, token); run_reactions(i, kin_time, NOMIX, step_fraction); - if (multi_Dflag == TRUE && j < nmix) + if (multi_Dflag == TRUE) fill_spec(i); if (iterations > max_iter) max_iter = iterations; @@ -825,7 +825,7 @@ transport(void) run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag == TRUE && j < nmix) + if (multi_Dflag == TRUE) fill_spec(i); if ((j == nmix) && (stag_data->count_stag == 0 || i == 0 || (i != 1 + count_cells && Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) @@ -1624,7 +1624,7 @@ fill_spec(int l_cell_no) struct master *master_ptr; LDBLE dum, dum2; LDBLE lm; - LDBLE por, por_il, viscos_f, viscos_il_f, viscos; + LDBLE por, por_il, viscos_f, viscos_il_f, viscos, l_z, l_g, ff; bool x_max_done = false; s_ptr2 = NULL; @@ -1813,6 +1813,20 @@ fill_spec(int l_cell_no) else sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw * viscos_f; } + if (correct_Dw) + { + if ((l_z = fabs(s_x[i]->z)) == 0) + { // first approximation for neutral species (HTO), but is viscosity dependent + l_z = 1; + l_g = -DH_A * (sqrt(mu_x) / (1 + sqrt(mu_x))); + } + else + l_g = s_ptr->lg; + ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z); + ff *= l_g; + if (ff > 0) ff = 0; // is viscosity dependent (ff > 0 in KCl) + sol_D[l_cell_no].spec[count_spec].Dwt *= under(ff); + } if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); sol_D[l_cell_no].spec[count_spec].erm_ddl = s_ptr->erm_ddl; From 8604336e093c8ef428d203b66d05fa89a5be1d55 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Sat, 26 Mar 2016 20:35:41 +0000 Subject: [PATCH 1004/1077] Update from phreeqc3 through 10983. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@10984 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- inverse.cpp | 3 +++ read.cpp | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/inverse.cpp b/inverse.cpp index 8057c28f..b0d6686f 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -569,6 +569,9 @@ setup_inverse(struct inverse *inv_ptr) { row = master_ptr->in; } + assert(row * max_column_count + column < max_column_count * max_row_count); + assert(row >= 0); + assert(column >= 0); array[row * max_column_count + column] = rxn_ptr->token[j].coef; /* if coefficient of element is not 1.0 in master species */ diff --git a/read.cpp b/read.cpp index 7bb33894..72e44676 100644 --- a/read.cpp +++ b/read.cpp @@ -3296,15 +3296,16 @@ read_master_species(void) space((void **) ((void *) &master), count_master + 1, &max_master, sizeof(struct master *)); } - master[count_master] = master_alloc(); + master[count_master++] = master_alloc(); /* * Set type to AQ */ - master[count_master]->type = AQ; + master[count_master-1]->type = AQ; /* * Save element name */ - master[count_master]->elt = element_store(token); + master[count_master-1]->elt = element_store(token); + std::string ename = token; /* * Save pointer to species data for master species */ @@ -3320,20 +3321,33 @@ read_master_species(void) s_ptr = s_search(token); if (s_ptr != NULL) { - master[count_master]->s = s_ptr; + master[count_master-1]->s = s_ptr; } else { ptr1 = token; get_token(&ptr1, token1, &l_z, &l); - master[count_master]->s = s_store(token1, l_z, FALSE); + master[count_master-1]->s = s_store(token1, l_z, FALSE); + } + + std::string sname = token; + replace("("," ", ename); + std::istringstream iss(ename); + iss >> ename; + if (ename != "e" && ename != "E" && ename != "Alkalinity" && std::string::npos == sname.find(ename)) + { + input_error++; + std::ostringstream oss; + oss << "Master species, " << sname << " must contain the element, " << ename; + error_msg(oss.str().c_str(), CONTINUE); + continue; } /* * Read alkalinity for species */ copy_token(token, &ptr, &l); - i = sscanf(token, SCANFORMAT, &master[count_master]->alk); + i = sscanf(token, SCANFORMAT, &master[count_master-1]->alk); if (i != 1) { input_error++; @@ -3357,11 +3371,11 @@ read_master_species(void) i = copy_token(token, &ptr, &l); if (i == DIGIT) { - sscanf(token, SCANFORMAT, &master[count_master]->gfw); + sscanf(token, SCANFORMAT, &master[count_master-1]->gfw); } else if (i == UPPER) { - master[count_master]->gfw_formula = string_hsave(token); + master[count_master-1]->gfw_formula = string_hsave(token); } else { @@ -3383,13 +3397,13 @@ read_master_species(void) /* * MAKE LISTS OF PRIMARY AND SECONDARY MASTER SPECIES */ - if (strchr(master[count_master]->elt->name, '(') == NULL) + if (strchr(master[count_master-1]->elt->name, '(') == NULL) { - master[count_master]->primary = TRUE; + master[count_master-1]->primary = TRUE; /* Read gram formula weight for primary */ - if (strcmp(master[count_master]->elt->name, "E") != 0) + if (strcmp(master[count_master-1]->elt->name, "E") != 0) { - elts_ptr = master[count_master]->elt; + elts_ptr = master[count_master-1]->elt; i = copy_token(token, &ptr, &l); if (i == DIGIT) { @@ -3417,9 +3431,8 @@ read_master_species(void) } else { - master[count_master]->primary = FALSE; + master[count_master-1]->primary = FALSE; } - count_master++; if (count_master >= max_master) { space((void **) ((void *) &master), count_master, &max_master, From 79a496566163a11827aa2cc0873be2d893663280 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Apr 2016 17:48:22 +0000 Subject: [PATCH 1005/1077] Change MIN_TOTAL to 1e-18 MIN_TOTAL added to KNOBS. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11041 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 13 +++++++++++++ Phreeqc.h | 7 +++++++ global_structures.h | 24 ++++++++++++------------ read.cpp | 12 ++++++++++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index cbe54eb1..04983d07 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -275,6 +275,13 @@ void Phreeqc::init(void) punch.charge_balance = FALSE; punch.percent_error = FALSE; #endif + + MIN_LM = -30.0; /* minimum log molality allowed before molality set to zero */ + LOG_ZERO_MOLALITY = -30; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ + MIN_RELATED_LOG_ACTIVITY = -30; + MIN_TOTAL = 1e-18; + MIN_TOTAL_SS = MIN_TOTAL/100; + MIN_RELATED_SURFACE = MIN_TOTAL*100; // auto Rxn_temperature_map; // auto Rxn_pressure_map; @@ -1163,6 +1170,12 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) current_mu = pSrc->current_mu; mu_terms_in_logk = pSrc->mu_terms_in_logk; + MIN_LM = pSrc->MIN_LM; /* minimum log molality allowed before molality set to zero */ + LOG_ZERO_MOLALITY = pSrc->LOG_ZERO_MOLALITY; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ + MIN_RELATED_LOG_ACTIVITY = pSrc->MIN_RELATED_LOG_ACTIVITY; + MIN_TOTAL = pSrc->MIN_TOTAL; + MIN_TOTAL_SS = pSrc->MIN_TOTAL_SS; + MIN_RELATED_SURFACE = pSrc->MIN_RELATED_SURFACE; /* ---------------------------------------------------------------------- * STRUCTURES * ---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index 59e335fc..2a8ff530 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1598,6 +1598,13 @@ protected: int stop_program; int incremental_reactions; + double MIN_LM; + double LOG_ZERO_MOLALITY; + double MIN_TOTAL; + double MIN_TOTAL_SS; + double MIN_RELATED_SURFACE; + double MIN_RELATED_LOG_ACTIVITY; + int count_strings; int max_strings; diff --git a/global_structures.h b/global_structures.h index c7fc48a7..cc28ec66 100644 --- a/global_structures.h +++ b/global_structures.h @@ -132,19 +132,19 @@ #define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ #define MAX_M 1000.0 #ifdef USE_DECIMAL128 -#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ -#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-60 -#define MIN_TOTAL_SS MIN_TOTAL/100 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -60 +//#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ +//#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +//#define MIN_TOTAL 1e-60 +//#define MIN_TOTAL_SS MIN_TOTAL/100 +//#define MIN_RELATED_SURFACE MIN_TOTAL*100 +//#define MIN_RELATED_LOG_ACTIVITY -60 #else -#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ -#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-25 -#define MIN_TOTAL_SS MIN_TOTAL/100 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -30 +//#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +//#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +//#define MIN_TOTAL 1e-25 +//#define MIN_TOTAL_SS MIN_TOTAL/100 +//#define MIN_RELATED_SURFACE MIN_TOTAL*100 +//#define MIN_RELATED_LOG_ACTIVITY -30 #endif #define REF_PRES_PASCAL 1.01325E5 /* Reference pressure: 1 atm */ /* diff --git a/read.cpp b/read.cpp index ae0533b1..30563e9d 100644 --- a/read.cpp +++ b/read.cpp @@ -8271,9 +8271,11 @@ read_debug(void) "try", /* 17 */ "numerical_fixed_volume", /* 18 */ "force_numerical_fixed_volume", /* 19 */ - "equi_delay" /* 20 */ + "equi_delay", /* 20 */ + "minimum_total", /* 21 */ + "min_total" /* 22 */ }; - int count_opt_list = 21; + int count_opt_list = 23; /* * Read parameters: * ineq_tol; @@ -8369,6 +8371,12 @@ read_debug(void) case 20: /* equi_delay */ sscanf(next_char, "%d", &equi_delay); break; + case 21: /* minimum_total */ + case 22: /* min_total */ + sscanf(next_char, "%d", &MIN_TOTAL); + MIN_TOTAL_SS = MIN_TOTAL/100; + MIN_RELATED_SURFACE = MIN_TOTAL*100; + break; } if (return_value == EOF || return_value == KEYWORD) break; From d918a52dd064c432e777a7d21ee539408159c05a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 12 Apr 2016 18:32:14 +0000 Subject: [PATCH 1006/1077] switch back to 1e-25 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11043 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 04983d07..adfdd5fc 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -279,7 +279,7 @@ void Phreeqc::init(void) MIN_LM = -30.0; /* minimum log molality allowed before molality set to zero */ LOG_ZERO_MOLALITY = -30; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ MIN_RELATED_LOG_ACTIVITY = -30; - MIN_TOTAL = 1e-18; + MIN_TOTAL = 1e-25; MIN_TOTAL_SS = MIN_TOTAL/100; MIN_RELATED_SURFACE = MIN_TOTAL*100; // auto Rxn_temperature_map; @@ -2537,4 +2537,4 @@ int Phreeqc::next_user_number(Keywords::KEYWORDS key) assert(false); return -999; } -} \ No newline at end of file +} From e9837bb0d87502635f42051e476712bf7359a2d9 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 20 Apr 2016 03:21:26 +0000 Subject: [PATCH 1007/1077] fixed bug that overwrote selected output files when (re-)opening a .pqi file git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11072 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 8f983320..8005b225 100644 --- a/print.cpp +++ b/print.cpp @@ -3185,7 +3185,7 @@ punch_identifiers(void) (double) (100 * cb_x / total_ions_x)); } } - + punch_flush(); return (OK); } From e37e06ad6025dd7449d4bfd2310a4979cd1b2b10 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 20 Apr 2016 04:40:45 +0000 Subject: [PATCH 1008/1077] fixed selected output missing headers given the following input: solution selected_output end git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11073 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/read.cpp b/read.cpp index 30563e9d..9fff675c 100644 --- a/read.cpp +++ b/read.cpp @@ -4767,6 +4767,7 @@ read_selected_output(void) else if (n_user == 1 && so == SelectedOutput_map.end()) { // n_user = 1, new definition, do nothing use; constructor default + temp_selected_output.Set_new_def(true); } else { From 394f918eaceae4088cce1b877c2ffa9114eee34a Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 20 Apr 2016 22:05:13 +0000 Subject: [PATCH 1009/1077] changed preprocessor guard for windows _set_output_format call git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11088 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- mainsubs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainsubs.cpp b/mainsubs.cpp index 2f367e9b..c76e56ff 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -2375,7 +2375,7 @@ run_simulations(void) { char token[MAX_LENGTH]; //#ifdef SKIP_KEEP -#if defined(WIN32) +#if defined(_MSC_VER) && (_MSC_VER < 1900) // removed in vs2015 unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif From c02d598b4b66d2affaacae915c04f740ee99f5b2 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 21 Apr 2016 15:19:03 +0000 Subject: [PATCH 1010/1077] wrong format in read git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11090 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/read.cpp b/read.cpp index 9fff675c..41aeca74 100644 --- a/read.cpp +++ b/read.cpp @@ -8374,7 +8374,7 @@ read_debug(void) break; case 21: /* minimum_total */ case 22: /* min_total */ - sscanf(next_char, "%d", &MIN_TOTAL); + sscanf(next_char, SCANFORMAT, &MIN_TOTAL); MIN_TOTAL_SS = MIN_TOTAL/100; MIN_RELATED_SURFACE = MIN_TOTAL*100; break; From ad55ede31355cc04735ae8641cd972ecb9600cde Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Sat, 23 Apr 2016 01:53:00 +0000 Subject: [PATCH 1011/1077] fixed selected_output missing headers when SelectedOutputFileOn == true git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11104 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/read.cpp b/read.cpp index 41aeca74..d7c7d919 100644 --- a/read.cpp +++ b/read.cpp @@ -4774,6 +4774,10 @@ read_selected_output(void) // n_user != 1 then reset false temp_selected_output.Reset(false); + if (so == SelectedOutput_map.end()) + { + temp_selected_output.Set_new_def(true); + } } CParser parser(this->phrq_io); From fe3f36ea246c8cb2e4709a61fcabcc55436190b3 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 26 Apr 2016 16:07:41 +0000 Subject: [PATCH 1012/1077] Need to zero moles in tally struct in addition to zeroing totals. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11105 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- tally.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tally.cpp b/tally.cpp index a7405e87..994c6af2 100644 --- a/tally.cpp +++ b/tally.cpp @@ -397,6 +397,7 @@ zero_tally_table(void) int i, j, k; for (i = 0; i < count_tally_table_columns; i++) { + tally_table[i].moles = 0.0; for (j = 0; j < count_tally_table_rows; j++) { for (k = 0; k < 3; k++) From 03c9d56c09649b633d5ebeb8b7f7d07ca54c0eb1 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 May 2016 16:27:32 +0000 Subject: [PATCH 1013/1077] Tony's updates to allow fixed current. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@11133 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 ++ Phreeqc.h | 2 +- readtr.cpp | 25 +++++++++++------- transport.cpp | 73 +++++++++++++++++++++++++++++++++------------------ 4 files changed, 67 insertions(+), 35 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 8c3e0bd1..07f7b776 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -470,6 +470,7 @@ void Phreeqc::init(void) multi_Dn = 0; interlayer_tortf = 100.0; cell_no = 0; + fix_current = 0.0; /*---------------------------------------------------------------------- * Advection data *---------------------------------------------------------------------- */ @@ -1385,6 +1386,7 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) multi_Dn = pSrc->multi_Dn; interlayer_tortf = pSrc->interlayer_tortf; cell_no = pSrc->cell_no; + fix_current = pSrc->fix_current; /*---------------------------------------------------------------------- * Advection data *---------------------------------------------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index 72e1d69c..d1229825 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1955,7 +1955,7 @@ protected: int nmix, heat_nmix; LDBLE heat_mix_f_imm, heat_mix_f_m; int warn_MCD_X, warn_fixed_Surf; - LDBLE current_x, current_A; // current: coulomb * s, ampere + LDBLE current_x, current_A, fix_current; // current: coulomb / s, Ampere, fixed current (Ampere) #ifdef PHREEQ98 int AutoLoadOutputFile, CreateToC; diff --git a/readtr.cpp b/readtr.cpp index 1f987460..c345e45e 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -91,9 +91,10 @@ read_transport(void) "multi_d", /* 40 */ "interlayer_d", /* 41 */ "porosities", /* 42 */ - "porosity" /* 43 */ + "porosity", /* 43 */ + "fix_current" /* 44 */ }; - int count_opt_list = 44; + int count_opt_list = 45; strcpy(file_name, "phreeqc.dmp"); /* @@ -665,6 +666,19 @@ read_transport(void) } opt_save = 42; break; + case 44: /* fix_current */ + if (copy_token(token, &next_char, &l) == DIGIT) + { + sscanf(token, SCANFORMAT, &fix_current); + fix_current = fabs(fix_current); + } + else + { + warning_msg("Expected the fixed value for the current (Ampere)."); + fix_current = 0.0; + } + opt_save = OPTION_DEFAULT; + break; } if (return_value == EOF || return_value == KEYWORD) break; @@ -938,13 +952,6 @@ read_transport(void) cell_data[i].por_il = interlayer_Dpor; } #endif - //{ - // for (int i = 0; i < all_cells; i++) - // { - // std::cerr << i << " " << cell_data[i].por << std::endl; - // } - //} - /* * Calculate dump_modulus */ diff --git a/transport.cpp b/transport.cpp index 26dd997d..01db88d1 100644 --- a/transport.cpp +++ b/transport.cpp @@ -105,8 +105,8 @@ transport(void) ct[i].A_ij_il = 0.0; ct[i].Dz2c_il = 0.0; ct[i].mixf_il = 0.0; - ct[i].J_ij_count_spec = -1; - ct[i].J_ij_il_count_spec = -1; + ct[i].J_ij_count_spec = 0; + ct[i].J_ij_il_count_spec = 0; ct[i].v_m = NULL; ct[i].v_m_il = NULL; ct[i].J_ij = NULL; @@ -186,6 +186,12 @@ transport(void) } } + if (fix_current && !dV_dcell) + { + warning_msg("fix_current (A) was defined, but potential in a boundary cell was not.\n\tUsing 1e-8 V in cell 0 for calculating the potentials."); + cell_data[0].potV = 1e-8; + dV_dcell = 1; + } if (dV_dcell) { if (/*stag_data->count_stag || */!multi_Dflag || ishift) @@ -1815,7 +1821,7 @@ fill_spec(int l_cell_no) } if (correct_Dw) { - if ((l_z = fabs(s_x[i]->z)) == 0) + if ((l_z = fabs(s_ptr->z)) == 0) { // first approximation for neutral species (HTO), but is viscosity dependent l_z = 1; l_g = -DH_A * (sqrt(mu_x) / (1 + sqrt(mu_x))); @@ -1912,7 +1918,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) current_x = sum_R = sum_Rd = 0.0; if (dV_dcell && !stagnant) - find_current = loop_f_c = 1; // calculate J_ij once for all cells, find smallest j_x, next with this j_x. + find_current = loop_f_c = 1; // calculate J_ij once for all cells, loop to dV_dcell2. else find_current = loop_f_c = 0; @@ -1984,16 +1990,27 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) else { LDBLE dVc, j_0e; - // distribute dV_dcell according to relative resistance, calculate current_x + // distribute dV_dcell according to relative resistance, calculate current_x if not fixed j_0e = (dV_dcell * count_cells - sum_Rd) / sum_R; + current_x = j_0e + current_cells[0].dif; + if (fix_current) + { + int sign = (signbit(current_x) == 0 ? 1 : -1); + current_x = sign * fix_current; + j_0e = current_x - current_cells[0].dif; + } dVc = j_0e * current_cells[0].R; cell_data[1].potV = cell_data[0].potV + dVc; - current_x = j_0e + current_cells[0].dif; for (i1 = 1; i1 < count_cells; i1++) { dVc = current_cells[i1].R * (current_x - current_cells[i1].dif); cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; } + if (fix_current) + { + dVc = current_cells[i1].R * (current_x - current_cells[i1].dif); + cell_data[i1 + 1].potV = cell_data[i1].potV + dVc; + } find_current = 0; continue; } @@ -2030,7 +2047,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); - if (dV_dcell && i > 0 && !stagnant) + if (dV_dcell && (i > 0 || fix_current) && !stagnant) { use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); } @@ -2062,6 +2079,10 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Get_solution_ptr()->Set_total_h(dummy + tot1_h); dummy = use.Get_solution_ptr()->Get_total_o(); use.Get_solution_ptr()->Set_total_o(dummy + tot1_o); + if (i == count_cells && fix_current && !stagnant) + { + use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); + } for (l = 0; l < count_m_s; l++) { length = (int)strlen(m_s[l].name); @@ -2329,29 +2350,31 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); //ct[icell].v_m = ct[icell].v_m_il = NULL; - if (stagnant) + if (!il_calcs) { - if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim - || cell_data[jcell].por < multi_Dpor_lim)) - return (OK); - } - else - { /* regular column... */ - if (icell == 0) + if (stagnant) { - if (!il_calcs && cell_data[1].por < multi_Dpor_lim) - return (OK); - } - else if (icell == count_cells) - { - if (!il_calcs && cell_data[count_cells].por < multi_Dpor_lim) + if (cell_data[icell].por < multi_Dpor_lim + || cell_data[jcell].por < multi_Dpor_lim) return (OK); } else - { - if (!il_calcs && (cell_data[icell].por < multi_Dpor_lim - || cell_data[jcell].por < multi_Dpor_lim)) + { /* regular column... */ + if ((icell == 0 && cell_data[1].por < multi_Dpor_lim) + ||(icell == count_cells && cell_data[count_cells].por < multi_Dpor_lim) + || (icell !=0 && icell != count_cells && (cell_data[icell].por < multi_Dpor_lim + || cell_data[jcell].por < multi_Dpor_lim))) + { + if (dV_dcell) + { + current_cells[icell].R = -1e15; + current_cells[icell].ele = dV_dcell / current_cells[icell].R; + current_cells[icell].dif = 0; + sum_R += current_cells[icell].R; + sum_Rd += current_cells[0].dif * current_cells[icell].R; + } return (OK); + } } } @@ -3283,7 +3306,7 @@ dV_dcell2: ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; } } - // ensure that icell has dl water when checking negative conc's in MCD + // assure that icell has dl water when checking negative conc's in MCD ct[icell].dl_s = dl_aq_i; ct[jcell].dl_s = dl_aq_j; From 96839072729c3251c3bd7c76d1ee882eacbdf512 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 May 2016 17:05:03 +0000 Subject: [PATCH 1014/1077] Needed to write around signbit. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@11135 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transport.cpp b/transport.cpp index 01db88d1..ec5e64a6 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1995,7 +1995,8 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) current_x = j_0e + current_cells[0].dif; if (fix_current) { - int sign = (signbit(current_x) == 0 ? 1 : -1); + //int sign = (signbit(current_x) == 0 ? 1 : -1); + int sign = (current_x >= 0) ? 1 : -1; current_x = sign * fix_current; j_0e = current_x - current_cells[0].dif; } From edf7f8f6f6005b18656b1f44e56459f3526f7e1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 4 May 2016 17:01:33 +0000 Subject: [PATCH 1015/1077] Added Basic functions for KINETICS_FORMULA$ and SYS("kin" git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11151 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++++- PBasic.h | 2 + Phreeqc.h | 2 + basicsubs.cpp | 86 +++++++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 5960c8bb..6b396925 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1551,6 +1551,10 @@ listtokens(FILE * f, tokenrec * l_buf) case tokiso_unit: output_msg("ISO_UNIT"); break; + case tokkinetics_formula: + case tokkinetics_formula_: + output_msg("KINETICS_FORMULA$"); + break; case tokphase_formula: case tokphase_formula_: output_msg("PHASE_FORMULA$"); @@ -2931,6 +2935,112 @@ factor(struct LOC_exec * LINK) break; } + case tokkinetics_formula: + case tokkinetics_formula_: + { + require(toklp, LINK); + std::string kinetics_name(stringfactor(STR1, LINK)); + varrec *elts_varrec = NULL, *coef_varrec = NULL; + cxxNameDouble stoichiometry; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /* kinetics_formula("calcite", count, elt, coef) */ + /* return formula */ + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* struct varrec *count_varrec, *elt_varrec, *coef_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of elements */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + std::string form = PhreeqcPtr->kinetics_formula(kinetics_name, stoichiometry); + + // put formula as return value + n.stringval = true; + n.UU.sval = PhreeqcPtr->string_duplicate(form.c_str()); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + + } + break; + } case tokphase_formula: case tokphase_formula_: { @@ -7125,7 +7235,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("diff_c", PBasic::tokdiff_c), std::map::value_type("sa_declercq", PBasic::toksa_declercq), std::map::value_type("edl_species", PBasic::tokedl_species), - std::map::value_type("rho_0", PBasic::tokrho_0) + std::map::value_type("rho_0", PBasic::tokrho_0), + std::map::value_type("kinetics_formula", PBasic::tokkinetics_formula), + std::map::value_type("kinetics_formula$", PBasic::tokkinetics_formula) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 0efbdd8e..b7b7a8ac 100644 --- a/PBasic.h +++ b/PBasic.h @@ -295,6 +295,8 @@ public: tokeol_, tokceil, tokfloor, + tokkinetics_formula, + tokkinetics_formula_, tokphase_formula, tokphase_formula_, tokspecies_formula, diff --git a/Phreeqc.h b/Phreeqc.h index 2a8ff530..368b5dd3 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -147,6 +147,7 @@ public: static int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); + std::string kinetics_formula(std::string kinetics_name, cxxNameDouble &stoichiometry); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); std::string species_formula(std::string phase_name, cxxNameDouble &stoichiometry); LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); @@ -157,6 +158,7 @@ public: int system_total_surf(void); int system_total_gas(void); int system_total_equi(void); + int system_total_kin(void); int system_total_ss(void); int system_total_elt(const char *total_name); int system_total_elt_secondary(const char *total_name); diff --git a/basicsubs.cpp b/basicsubs.cpp index 01c3dcad..b9cca380 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -2756,6 +2756,10 @@ system_total(const char *total_name, LDBLE * count, char ***names, { system_total_equi(); } + else if (strcmp_nocase(total_name, "kin") == 0) + { + system_total_kin(); + } else { if (strstr(total_name, "(") == NULL) @@ -2816,6 +2820,64 @@ system_total(const char *total_name, LDBLE * count, char ***names, return (sys_tot); } +/* ---------------------------------------------------------------------- */ +std::string Phreeqc:: +kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns formula of kinetic reactant + * Also returns arrays of elements and stoichiometry in stoichiometry + */ + stoichiometry.clear(); + std::string formula; + + if (use.Get_kinetics_ptr() == NULL) + return (formula); + std::vector comps = use.Get_kinetics_ptr()->Get_kinetics_comps(); + count_elts = 0; + paren_count = 0; + for (size_t i=0 ; i < comps.size(); i++) + { + cxxKineticsComp *comp_ptr = &comps[i]; + if (kin_name == comp_ptr->Get_rate_name().c_str()) + { + cxxNameDouble nd = comp_ptr->Get_namecoef(); + cxxNameDouble::iterator it = nd.begin(); + for ( ; it != nd.end(); it++) + { + // Try Phases + int l; + struct phase *phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, it->second); + } + else + { + // add formula + std::string name = it->first; + LDBLE coef = it->second; + char * temp_name = string_duplicate(name.c_str()); + char *ptr = temp_name; + get_elts_in_species(&ptr, coef); + free_check_null(temp_name); + } + } + formula.append(kin_name); + //elt_list[count_elts].elt = NULL; + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + stoichiometry = elt_list_NameDouble(); + break; + } + } + return (formula); +} /* ---------------------------------------------------------------------- */ std::string Phreeqc:: phase_formula(std::string phase_name, cxxNameDouble &stoichiometry) @@ -3176,6 +3238,30 @@ system_total_equi(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +system_total_kin(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Equilibrium phases + */ + if (use.Get_kinetics_ptr() == NULL) + return (OK); + std::vector comps = use.Get_kinetics_ptr()->Get_kinetics_comps(); + for (size_t i=0 ; i < comps.size(); i++) + { + cxxKineticsComp *comp_ptr = &comps[i]; + sys[count_sys].name = string_duplicate(comp_ptr->Get_rate_name().c_str()); + sys[count_sys].moles = comp_ptr->Get_m(); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("kin"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: system_total_ss(void) /* ---------------------------------------------------------------------- */ { From 06e41e92ae96a273a3ecb71686a5dbbdb1773862 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 17 May 2016 15:33:46 +0000 Subject: [PATCH 1016/1077] Tony's changes for advection/diffusion with irregular grid. He was not able to get a robust result. Have not run test casees with this change. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@11171 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 225 ++++++++++++++++++++++++++------------------------ 1 file changed, 117 insertions(+), 108 deletions(-) diff --git a/transport.cpp b/transport.cpp index ec5e64a6..fd3a3616 100644 --- a/transport.cpp +++ b/transport.cpp @@ -968,7 +968,8 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE dav, lav, mixf, mf12, maxmix, corr_disp, diffc_here, mD; + LDBLE lav, dav, mf12, maxmix, corr_disp, diffc_here, mD; + bool warning = false; int i, l_nmix; LDBLE *m, *m1; m = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); @@ -995,62 +996,73 @@ init_mix(void) { if (dV_dcell) dV_dcell = (cell_data[count_cells + 1].potV - cell_data[0].potV) / count_cells; - for (i = 1; i < count_cells; i++) + for (i = 1; i <= count_cells; i++) { + // estimate the number of mixes lav = (cell_data[i + 1].length + cell_data[i].length) / 2; - if (ishift != 0) - dav = (cell_data[i + 1].disp + cell_data[i].disp) / 2; - else - dav = 0; - mixf = dav * corr_disp / cell_data[i + 1].length; - if (mixf > maxmix) - maxmix = mixf; - m[i] = mixf; /* m[i] has mixf with lower cell */ mD = diffc_max * timest / (lav * lav); if (mD > maxmix) maxmix = mD; + if (ishift != 0) + { + /* define dispersive mixing (diffusion is done in multi_D), + with harmonic mean of cell properties (manual eqn 49): + M1 = -a1 * (v1 * timest / 2) * A1 * (c12 - c1) / (h1 / 2) + a1 is dispersivity in cell 1, A1 = V1 / h1, v1 * timest / 2 = h1 / 2. + All cells have equal V in advective transport, delta(c) = M1 / V1. + */ + if (i < count_cells) + { + if (cell_data[i].disp) + dav = cell_data[i].length / cell_data[i].disp; + if (cell_data[i + 1].disp) + dav += cell_data[i + 1].length / cell_data[i + 1].disp; + if (dav) + m1[i] = 2 * corr_disp / dav; /* m1[i] has mixf with higher cell */ + } + if (i > 1) + { + if (cell_data[i].disp) + dav = cell_data[i].length / cell_data[i].disp; + if (cell_data[i - 1].disp) + dav += cell_data[i - 1].length / cell_data[i - 1].disp; + if (dav) + m[i] = 2 * corr_disp / dav; /* m[i] has mixf with lower cell */ + } + mf12 = m[i] + m1[i]; + if (mf12 > maxmix) + maxmix = mf12; + } } /* * Also for boundary cells */ if (bcon_first == 1) { - lav = cell_data[1].length; - if (ishift != 0) - dav = cell_data[1].disp; - else - dav = 0; - - mixf = dav / lav; - if (mixf > maxmix) - maxmix = mixf; - m[0] = 2 * mixf; - mD = diffc_max * timest / (lav * lav); + mD = 2 * diffc_max * timest / (cell_data[1].length * cell_data[1].length); if (mD > maxmix) maxmix = mD; + if (ishift != 0) + { + m[1] = 2 * cell_data[1].disp / cell_data[1].length * corr_disp; + mf12 = m[1] + m1[1]; + if (mf12 > maxmix) + maxmix = mf12; + } } - else - m[0] = 0; - if (bcon_last == 1) { - lav = cell_data[count_cells].length; - if (ishift != 0) - dav = cell_data[count_cells].disp; - else - dav = 0; - - mixf = dav / lav; - if (mixf > maxmix) - maxmix = mixf; - m[count_cells] = 2 * mixf; - mD = diffc_max * timest / (lav * lav); + mD = 2 * diffc_max * timest / (cell_data[count_cells].length * cell_data[count_cells].length); if (mD > maxmix) maxmix = mD; + if (ishift != 0) + { + m1[count_cells] = 2 * cell_data[count_cells].disp / cell_data[count_cells].length * corr_disp; + mf12 = m[count_cells] + m1[count_cells]; + if (mf12 > maxmix) + maxmix = mf12; + } } - else - m[count_cells] = 0; - /* * Find number of mixes */ @@ -1062,12 +1074,12 @@ init_mix(void) } else { - if ((bcon_first == 1) || (bcon_last == 1)) - l_nmix = 1 + (int)floor(4.5 * maxmix); + if (bcon_first == 1 || bcon_last == 1) + l_nmix = 1 + (int)floor(2.25 * maxmix); else - l_nmix = 1 + (int)floor(3.0 * maxmix); + l_nmix = 1 + (int)floor(1.5 * maxmix); - if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) + if (ishift != 0 && (bcon_first == 1 || bcon_last == 1)) { if (l_nmix < 2) l_nmix = 2; @@ -1075,24 +1087,20 @@ init_mix(void) if (mcd_substeps > 1) l_nmix = (int)ceil(l_nmix * mcd_substeps); - for (i = 0; i <= count_cells; i++) - m[i] /= l_nmix; - } - /* - * Fill mix structure - */ - - if (l_nmix != 0) - { for (i = 1; i <= count_cells; i++) { + m[i] /= l_nmix; + m1[i] /= l_nmix; + /* + * Fill mix structure + */ cxxMix temp_mix; temp_mix.Set_n_user(i); temp_mix.Set_n_user_end(i); - temp_mix.Add(i - 1, m[i - 1]); - temp_mix.Add(i + 1, m[i]); - temp_mix.Add(i, 1.0 - m[i - 1] - m[i]); + temp_mix.Add(i - 1, m[i]); + temp_mix.Add(i + 1, m1[i]); + temp_mix.Add(i, 1.0 - m[i] - m1[i]); Dispersion_mix_map[i] = temp_mix; } } @@ -1102,73 +1110,81 @@ init_mix(void) } else // multi_D false { - diffc_here = diffc_tr; + diffc_here = 2 * diffc_tr * timest; /* * Define mixing factors among inner cells */ - for (i = 1; i < count_cells; i++) + for (i = 1; i <= count_cells; i++) { - // find mix with lower numbered cell... - lav = (cell_data[i + 1].length + cell_data[i].length) / 2; - if (ishift != 0) - dav = (cell_data[i + 1].disp + cell_data[i].disp) / 2; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i + 1].length; - m[i] = mixf; /* m[i] has mixf with lower cell */ - - // and with higher numbered cell... - mixf = (diffc_here * timest / lav + dav) * corr_disp / cell_data[i].length; - mf12 = m[i] + mixf; + if (i < count_cells) + { + // find mix with higher numbered cell... + if (ishift != 0) + { + if (cell_data[i].disp) + dav = cell_data[i].length / cell_data[i].disp; + if (cell_data[i + 1].disp) + dav += cell_data[i + 1].length / cell_data[i + 1].disp; + if (dav) + m1[i] = 2 / dav; + } + // add diffusive mixf... + m1[i] += diffc_here / + (cell_data[i].length * cell_data[i].length + cell_data[i].length * cell_data[i + 1].length); + m1[i] *= corr_disp; /* m1[i] has mixf with higher cell */ + } + if (i > 1) + { + // and with lower numbered cell... + if (ishift != 0) + { + if (cell_data[i].disp) + dav = cell_data[i].length / cell_data[i].disp; + if (cell_data[i - 1].disp) + dav += cell_data[i - 1].length / cell_data[i - 1].disp; + if (dav) + m[i] = 2 / dav; + } + // add diffusive mixf... + m[i] += diffc_here / + (cell_data[i].length * cell_data[i].length + cell_data[i].length * cell_data[i - 1].length); + m[i] *= corr_disp; /* m[i] has mixf with lower numbered cell */ + if (m[i] != m1[i - 1] && !warning && m[i] / (2 / dav) > 1.00001) + { + warning_msg("Unequal cell-lengths may give mass-balance error, consider using -multi_D"); + warning = true; + } + } + mf12 = m[i] + m1[i]; if (mf12 > maxmix) maxmix = mf12; - m1[i] = mixf; /* m1[i] has mixf with higher cell */ } /* * Also for boundary cells */ if (bcon_first == 1) { - lav = cell_data[1].length; + m[1] = diffc_here / (cell_data[1].length * cell_data[1].length); if (ishift != 0) - dav = cell_data[1].disp; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) / lav; - mf12 = m1[1] + 2 * mixf; + m[1] += cell_data[1].disp / cell_data[1].length; + mf12 = m[1] + m1[1]; if (mf12 > maxmix) maxmix = mf12; - m[0] = 2 * mixf; } - else - m[0] = 0; - if (bcon_last == 1) { - lav = cell_data[count_cells].length; + m1[count_cells] = diffc_here / (cell_data[count_cells].length * cell_data[count_cells].length); if (ishift != 0) - dav = cell_data[count_cells].disp; - else - dav = 0; - - mixf = (diffc_here * timest / lav + dav) / lav; - mf12 = m[count_cells - 1] + 2 * mixf; - if (mf12 > maxmix && !multi_Dflag) + m1[count_cells] += cell_data[count_cells].disp / cell_data[count_cells].length; + mf12 = m[count_cells] + m1[count_cells]; + if (mf12 > maxmix) maxmix = mf12; - m1[count_cells] = 2 * mixf; } - else - m[count_cells] = 0; - /* * Find number of mixes */ if (maxmix == 0) - { l_nmix = 0; - } else { l_nmix = 1 + (int)floor(1.5 * maxmix); @@ -1179,27 +1195,20 @@ init_mix(void) l_nmix = 2; } - for (i = 0; i <= count_cells; i++) + for (i = 1; i <= count_cells; i++) { m[i] /= l_nmix; m1[i] /= l_nmix; - } - } - /* - * Fill mix structure - */ - - if (l_nmix != 0) - { - for (i = 1; i <= count_cells; i++) - { + /* + * Fill mix structure + */ cxxMix temp_mix; temp_mix.Set_n_user(i); temp_mix.Set_n_user_end(i); - temp_mix.Add(i - 1, m[i - 1]); + temp_mix.Add(i - 1, m[i]); temp_mix.Add(i + 1, m1[i]); - temp_mix.Add(i, 1.0 - m[i - 1] - m1[i]); + temp_mix.Add(i, 1.0 - m[i] - m1[i]); Dispersion_mix_map[i] = temp_mix; } } From f65078e910820f9aa5638f266a73e9cde2702e34 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 3 Jun 2016 18:46:13 +0000 Subject: [PATCH 1017/1077] added function phase_vm and test case. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11201 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 12 +++++++++++- PBasic.h | 3 ++- Phreeqc.h | 1 + basicsubs.cpp | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 6b396925..87408956 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1587,6 +1587,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokvm: output_msg("VM"); // mole volume of aqueous solute break; + case tokphase_vm: + output_msg("PHASE_VM"); // mole volume of a phase + break; case tokdh_a: output_msg("DH_A"); // Debye-Hueckel A break; @@ -3653,6 +3656,12 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str); } break; + case tokphase_vm: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->phase_vm(str); + } + break; case toksin: n.UU.val = sin(realfactor(LINK)); @@ -7237,7 +7246,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("edl_species", PBasic::tokedl_species), std::map::value_type("rho_0", PBasic::tokrho_0), std::map::value_type("kinetics_formula", PBasic::tokkinetics_formula), - std::map::value_type("kinetics_formula$", PBasic::tokkinetics_formula) + std::map::value_type("kinetics_formula$", PBasic::tokkinetics_formula), + std::map::value_type("phase_vm", PBasic::tokphase_vm) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index b7b7a8ac..50fec31d 100644 --- a/PBasic.h +++ b/PBasic.h @@ -327,7 +327,8 @@ public: tokcallback, tokdiff_c, toksa_declercq, - tokedl_species + tokedl_species, + tokphase_vm }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 368b5dd3..a943a311 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -100,6 +100,7 @@ public: LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); LDBLE aqueous_vm(const char *species_name); + LDBLE phase_vm(const char *phase_name); LDBLE diff_c(const char *species_name); LDBLE sa_declercq(double type, double sa, double d, double m, double m0, double gfw); LDBLE calc_SC(void); diff --git a/basicsubs.cpp b/basicsubs.cpp index b9cca380..b67698a0 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -98,7 +98,26 @@ aqueous_vm(const char *species_name) } return (g); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +phase_vm(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct phase *phase_ptr; + int l; + LDBLE g; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + g = 0.0; + } + else + { + g = phase_ptr->logk[vm0]; + } + return (g); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sa_declercq(double sa_type, double Sa, double d, double m, double m0, double gfw) From e8aa08af260ff6e483d70f845f5eb569cebb9d30 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 7 Jun 2016 14:43:36 +0000 Subject: [PATCH 1018/1077] Tony's latest. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@11223 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport.cpp b/transport.cpp index fd3a3616..87244fed 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1149,7 +1149,7 @@ init_mix(void) m[i] += diffc_here / (cell_data[i].length * cell_data[i].length + cell_data[i].length * cell_data[i - 1].length); m[i] *= corr_disp; /* m[i] has mixf with lower numbered cell */ - if (m[i] != m1[i - 1] && !warning && m[i] / (2 / dav) > 1.00001) + if (m[i] != m1[i - 1] && !warning && (!dav || m[i] / (2 / dav) > 1.00001)) { warning_msg("Unequal cell-lengths may give mass-balance error, consider using -multi_D"); warning = true; @@ -2006,7 +2006,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) { //int sign = (signbit(current_x) == 0 ? 1 : -1); int sign = (current_x >= 0) ? 1 : -1; - current_x = sign * fix_current; + current_x = sign * fix_current / F_C_MOL; j_0e = current_x - current_cells[0].dif; } dVc = j_0e * current_cells[0].R; @@ -2357,6 +2357,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dV_dcell && !find_current && !stagnant) goto dV_dcell2; + ct[icell].J_ij_count_spec = 0; ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); //ct[icell].v_m = ct[icell].v_m_il = NULL; @@ -2669,7 +2670,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } /* diffuse... */ - ct[icell].J_ij_count_spec = 0; ct[icell].J_ij_sum = 0.0; /* * malloc sufficient space... From 9cf105c93e06dd3b6810ec20d2b8d6639bfd412e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 13 Jun 2016 16:34:00 +0000 Subject: [PATCH 1019/1077] Kinniburgh problem with P(O2) = 10^-51 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11255 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- prep.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/prep.cpp b/prep.cpp index d783dccf..b94dcf98 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4099,6 +4099,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) P = 1.; } else { + if (P < 1e-10) P = 1e-10; r3[1] = b_sum - R_TK / P; r3_12 = r3[1] * r3[1]; r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; From 22fa4499a0362a1cfed4a832ea84bbe6b9057557 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Jun 2016 21:25:19 +0000 Subject: [PATCH 1020/1077] Moved mpi.h to beginning of each file. Conflict with stdio? Fixed TestRM.vcxproj to have zlib defined correctly. Removed dw.cpp from phreeqc. Need to fix all solutions and cmake files. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11284 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- dw.cpp | 415 --------------------------------------------------------- 1 file changed, 415 deletions(-) delete mode 100644 dw.cpp diff --git a/dw.cpp b/dw.cpp deleted file mode 100644 index 5c1e25c8..00000000 --- a/dw.cpp +++ /dev/null @@ -1,415 +0,0 @@ -#include "Phreeqc.h" - -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -DW(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C SUBROUTINE TO CALCULATE THE DENSITY OF WATER AS A FUNCTION OF -C TEMPERATURE. T IS IN KELVIN, P IS IN PASCALS, DW0 IS IN G/CM^3 -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE FP = 9.869232667e0, P, DGSS, D; - - BB(T); - P = 1.0e0 / FP; - if (T > 373.149e0) - P = PS(T); - DGSS = P / T / .4e0; - if (T < TZ) - { - DGSS = 1.0e0 / (VLEST(T)); - } - DFIND(&D, P, DGSS, T); - DW0 = D; - VP = P * FP; - return OK; -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -BB(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* - -C -C THIS SUBROUTINE CALCULATES THE B'S NEEDED FOR FUNCTION DW. -C THE B'S CALCULATED HERE ARE IN CM3/G. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE V[11]; - int I; - /* COMMON /BCONST/ */ - LDBLE P[11] = - { 0, 0.7478629e0, -.3540782e0, 0.e0, 0e0, .007159876e0, 0.e0, - -.003528426e0, 0., 0., 0. - }; - LDBLE Q[11] = - { 0, 1.1278334e0, 0.e0, -.5944001e0, -5.010996e0, 0.e0, .63684256e0, - 0., 0., 0., 0. - }; - - V[1] = 1.0; - for (I = 2; I <= 10; I++) - { - V[I] = V[I - 1] * TZ / T; - } - B1 = P[1] + P[2] * log(1.e0 / V[2]); - B2 = Q[1]; - B1T = P[2] * V[2] / TZ; - B2T = 0.e0; - B1TT = 0.e0; - B2TT = 0.e0; - for (I = 3; I <= 10; I++) - { - B1 = B1 + P[I] * V[I - 1]; - B2 = B2 + Q[I] * V[I - 1]; - B1T = B1T - (I - 2) * P[I] * V[I - 1] / T; - B2T = B2T - (I - 2) * Q[I] * V[I - 1] / T; - B1TT = B1TT + P[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; - B2TT = B2TT + Q[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; - } - B1TT = B1TT - B1T / T; - B2TT = B2TT - B2T / T; - return OK; -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -PS(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES AN APPROXIMATION TO THE VAPOR PRESSURE, P -C AS A FUNCTION OF THE INPUT TEMPERATURE. THE VAPOR PRESSURE -C CALCULATED AGREES WITH THE VAPOR PRESSURE PREDICTED BY THE SURFACE -C TO WITHIN .02% TO WITHIN A DEGREE OR SO OF THE CRITICAL TEMPERATUR -C AND CAN SERVE AS AN INITIAL GUESS FOR FURTHER REFINEMENT BY -C IMPOSING THE CONDITION THAT GL=GV. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE A[9] = { 0, -7.8889166e0, 2.5514255e0, -6.716169e0, - 33.239495e0, -105.38479e0, 174.35319e0, -148.39348e0, - 48.631602e0 - }; - LDBLE PL, V, W, B, L_Z, Q; - int I; - if (T <= 314.e0) - { - PL = 6.3573118e0 - 8858.843e0 / T + 607.56335e0 * pow(T, (LDBLE) -.6e0); - return (.1e0 * exp(PL)); - } - V = T / 647.25e0; - W = fabs(1.e0 - V); - B = 0.e0; - for (I = 1; I <= 8; I++) - { - L_Z = I; - B = B + A[I] * pow(W, ((L_Z + 1.e0) / 2.e0)); - } - Q = B / V; - return (22.093e0 * exp(Q)); -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -VLEST(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE A = -1.59259e1, B = 6.57886e-2, C = -1.12666e-4, D = 7.33191e-8, - E = 1.60229e3, F = 2.88572e0, G = 650.0e0; - - return (A + B * T + C * T * T + D * T * T * T + E / T + F / (G - T)); -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C ROUTINE TO FIND DENSITY CORRESPONDING TO INPUT PRESSURE P(MPA), AN -C TEMPERATURE T(K), USING INITIAL GUESS DENSITY D(G/CM3). THE OUTPUT -C DENSITY IS IN G/CM3. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - int L; - LDBLE DD, RT, PP_dfind, DPD, DPDX, DP, X; - /* LDBLE DD, RT, PP, DPD, DPDX, DP, X; */ - - DD = D; - RT = GASCON * T; - if (DD <= 0.e0) - DD = 1.e-8; - if (DD > 1.9e0) - DD = 1.9e0; - L = 0; - for (L = 1; L <= 30; L++) - { - if (DD <= 0.e0) - DD = 1.e-8; - if (DD > 1.9e0) - DD = 1.9e0; - QQ(T, DD); - PP_dfind = RT * DD * BASE(DD) + Q0; - DPD = RT * (Z + Y * DZ) + Q5; - /* - C - C THE FOLLOWING 3 LINES CHECK FOR NEGATIVE DP/DRHO, AND IF SO ASSUME - C GUESS TO BE IN 2-PHASE REGION, AND CORRECT GUESS ACCORDINGLY. - C - */ - if (DPD <= 0.e0) - { - if (D >= .2967e0) - DD = DD * 1.02e0; - if (D < .2967e0) - DD = DD * .98e0; - if (L <= 10) - continue; - } - else - { -/* 13 */ - DPDX = DPD * 1.1e0; - if (DPDX < 0.1e0) - DPDX = 0.1e0; - DP = fabs(1.e0 - PP_dfind / P); - if (DP < 1.e-8) - break; - if (D > .3e0 && DP < 1.e-7) - break; - if (D > .7e0 && DP < 1.e-6) - break; - X = (P - PP_dfind) / DPDX; - if (fabs(X) > .1e0) - X = X * .1e0 / fabs(X); - DD = DD + X; - if (DD < 0.e0) - DD = 1.e-8; - } - } - if (L > 30) - error_msg("In subroutine DFIND", STOP); - //cite Jonathan Toner, remove error_msg - //DD = 1; -/* 20 CONTINUE */ - *DOUT = DD; - return OK; -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -QQ(LDBLE T, LDBLE D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS ROUTINE CALCULATES, FOR A GIVEN T(K) AND D(G/CM3), THE RESIDUL -C CONTRIBUTIONS TO: PRESSURE (Q), DP/DRHO (Q5) -C THIS SUBROUTINE IS USED IN DENSITY OF WATER CALCULATION. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - /* COMMON /NCONST/ */ - LDBLE G[41] = - { 0, -.53062968529023e3, .22744901424408e4, .78779333020687e3, - -.69830527374994e2, .17863832875422e5, -.39514731563338e5, - .33803884280753e5, - -.13855050202703e5, -.25637436613260e6, .48212575981415e6, - -.34183016969660e6, - .12223156417448e6, .11797433655832e7, -.21734810110373e7, - .10829952168620e7, - -.25441998064049e6, -.31377774947767e7, .52911910757704e7, - -.13802577177877e7, - -.25109914369001e6, .46561826115608e7, -.72752773275387e7, - .41774246148294e6, - .14016358244614e7, -.31555231392127e7, .47929666384584e7, - .40912664781209e6, - -.13626369388386e7, .69625220862664e6, -.10834900096447e7, - -.22722827401688e6, - .38365486000660e6, .68833257944332e4, .21757245522644e5, - -.26627944829770e4, - -.70730418082074e5, -.225e0, -1.68e0, .055e0, -93.0e0 - }; - /*int II[41]={0,4*0,4*1,4*2,4*3,4*4,4*5,4*6,4*8,2*2,0,4,3*2,4}; */ - int II[41] = - { 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, - 5, - 5, 6, 6, 6, 6, 8, 8, 8, 8, 2, 2, 0, 4, 2, 2, 2, 4 - }; - /*int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,3*4,0,2,0,0}; */ - int JJ[41] = - { 0, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, - 5, - 7, 2, 3, 5, 7, 2, 3, 5, 7, 1, 4, 4, 4, 0, 2, 0, 0 - }; - int NC = 36; - /* COMMON /ADDCON/ */ - LDBLE ATZ[5] = { 0, 64.e1, 64.e1, 641.6e0, 27.e1 }, ADZ[5] = - { - 0, .319e0, .319e0, .319e0, 1.55e0}, AAT[5] = - { - 0, 2.e4, 2.e4, 4.e4, 25.e0}, AAD[5] = - { - 0, 34.e0, 4.e1, 3.e1, 1.05e3}; - LDBLE *QZT; - LDBLE QR[12], QT[11] /*, QZT[10] */ ; - /*EQUIVALENCE (QT(2),QZT(1)) */ - - LDBLE E, Q10, Q20, V, QP, DDZ, DEL, EX1, DEX, ATT, TX, - TAU, EX2, TEX, QM, FCT, Q5T; - int I, K, L, J, KM; - QZT = &(QT[1]); - QR[1] = 0.e0; - Q5 = 0.e0; - Q0 = 0.e0; - E = exp(-AA * D); - Q10 = D * D * E; - Q20 = 1.e0 - E; - QR[2] = Q10; - V = TZ / T; - QT[1] = T / TZ; - /*DO 4 I=2,10 */ - for (I = 2; I <= 10; I++) - { - QR[I + 1] = QR[I] * Q20; - /* 4 QT[I]=QT[I-1]*V */ - QT[I] = QT[I - 1] * V; - } - /* DO 10 I=1,NC */ - for (I = 1; I <= NC; I++) - { - K = II[I] + 1; - L = JJ[I]; - QP = G[I] * AA * QR[K + 1] * QZT[L]; - Q0 = Q0 + QP; - /*10 Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP */ - Q5 = Q5 + AA * (2.e0 / D - AA * (1.e0 - E * (K - 1) / Q20)) * QP; - } - QP = 0.e0; - /* DO 20 J=37,40 */ - for (J = 37; J <= 40; J++) - { - if (fabs(G[J]) < 1.0e-20) - continue; - K = II[J]; - KM = JJ[J]; - DDZ = ADZ[J - 36]; - DEL = D / DDZ - 1.e0; - if (fabs(DEL) < 1.e-10) - DEL = 1.e-10; - EX1 = -AAD[J - 36] * pow(DEL, K); - if (EX1 <= -88.028e0) - { - DEX = 0.e0; - } - else - { - DEX = exp(EX1) * pow(DEL, KM); - } - ATT = AAT[J - 36]; - TX = ATZ[J - 36]; - TAU = T / TX - 1.e0; - EX2 = -ATT * TAU * TAU; - if (EX2 <= -88.028e0) - { - TEX = 0.e0; - } - else - { - TEX = exp(EX2); - } - Q10 = DEX * TEX; - QM = KM / DEL - K * AAD[J - 36] * pow(DEL, (K - 1)); - FCT = QM * D * D * Q10 / DDZ; - Q5T = - FCT * (2.e0 / D + QM / DDZ) - pow((D / DDZ), - 2) * Q10 * (KM / DEL / DEL + - K * (K - - 1) * AAD[J - - 36] * - pow(DEL, (K - 2))); - Q5 = Q5 + Q5T * G[J]; - QP = QP + G[J] * FCT; - /* 20 CONTINUE */ - } - Q0 = Q0 + QP; - return OK; -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -BASE(LDBLE D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE Z (=PBASE/(DRT)) NEEDED FOR FUNCTION -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE X, Z0, DZ0; -/* -C -C G1,G2 AND GF ARE THE ALPHA, BETA AND GAMMA FOR DENSITY OF WATER -C CALCULATIONS. B1 AND B2 ARE THE 'EXCLUDED VOLUME' AND '2ND VIRIAL -C SUPPLIED BY THE SUBROUTINE BB(T), WHICH ALSO SUPPLIES THE 1ST AND -C 2ND DERIVATIVES WITH RESPECT TO T (B1T,B2T,B1TT,B2TT). -C -*/ - Y = .25e0 * B1 * D; - X = 1.e0 - Y; - Z0 = (1.e0 + G1 * Y + G2 * Y * Y) / pow(X, 3); - Z = Z0 + 4.e0 * Y * (B2 / B1 - GF); - DZ0 = - (G1 + 2.e0 * G2 * Y) / pow(X, - 3) + 3.e0 * (1.e0 + G1 * Y + - G2 * Y * Y) / pow(X, 4); - DZ = DZ0 + 4.e0 * (B2 / B1 - GF); - return (Z); -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -DC(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE RELATIVE DIELECTRIC CONSTANT AS A -C FUNCTION OF TEMPERATURE, ASSUMING ONE ATMOSPHERE PRESSURE -C ACCORDING TO D. J. BRADLEY AND K. S. PITZER, (1979) -C -*/ -{ - LDBLE D1000, C, B; - LDBLE U[10] = { 0, 3.4279e2, -5.0866e-3, 9.4690e-7, -2.0525e0, 3.1159e3, - -1.8289e2, -8.0325e3, 4.2142e6, 2.1417e0 - }; - D1000 = U[1] * exp(U[2] * T + U[3] * T * T); - C = U[4] + U[5] / (U[6] + T); - B = U[7] + U[8] / T + U[9] * T; - return (D1000 + C * log((B + VP * 1.01325e0) / (B + 1000.0e0))); -} -#endif \ No newline at end of file From 51974df3cab0f0c0a75c212007708ce286399eb5 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 17 Jun 2016 01:44:30 +0000 Subject: [PATCH 1021/1077] removed dw.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11298 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 21629594..b7321931 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,6 @@ phreeqc_SOURCES=\ Dictionary.h\ dumper.cpp\ dumper.h\ - dw.cpp\ Exchange.cxx\ Exchange.h\ ExchComp.cxx\ From 32b2b166863397eb16ae3b3aa43d10cd3c022dae Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Fri, 17 Jun 2016 02:55:53 +0000 Subject: [PATCH 1022/1077] removed dw.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11299 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Makefile.old b/Makefile.old index 9bc2b402..997c9a1f 100644 --- a/Makefile.old +++ b/Makefile.old @@ -194,7 +194,6 @@ COMMON_COBJS = \ cvdense.o \ cvode.o \ dense.o \ - dw.o \ gases.o \ input.o \ integrate.o \ @@ -634,14 +633,6 @@ Dictionary.o: ../Dictionary.cpp ../Dictionary.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h \ ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/PHRQ_io.h -dw.o: ../dw.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ - ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ - ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h gases.o: ../gases.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ From c6e273379ef1a0d4977275bcd81739f9f4867486 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Jun 2016 18:06:16 +0000 Subject: [PATCH 1023/1077] shrink_array for pitzer in model.cpp Mapped changes from sit to PITZER pitzer_revise_guesses model_pz change bases. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11400 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 2 +- pitzer.cpp | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/model.cpp b/model.cpp index 74b74579..f015e71b 100644 --- a/model.cpp +++ b/model.cpp @@ -1679,7 +1679,7 @@ ineq(int in_kode) } #define SHRINK_ARRAY #ifdef SHRINK_ARRAY - if (sit_model && full_pitzer == FALSE) + if ((sit_model || pitzer_model) && full_pitzer == FALSE) { n = count_unknowns - (int) s_list.size(); for (int i = 0; i < l_count_rows; i++) diff --git a/pitzer.cpp b/pitzer.cpp index b5fa7e24..006f4d69 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1811,12 +1811,14 @@ pitzer_revise_guesses(void) int l_iter, max_iter, repeat, fail; LDBLE weight, f; - max_iter = 10; + max_iter = 100; /* gammas(mu_x); */ l_iter = 0; repeat = TRUE; - fail = FALSE;; - while (repeat == TRUE) + fail = FALSE; + double d = 2; + double logd = log10(d); + while (repeat == TRUE && fail == FALSE) { l_iter++; if (debug_set == TRUE) @@ -1891,18 +1893,14 @@ pitzer_revise_guesses(void) else if (f == 0) { repeat = TRUE; - x[i]->master[0]->s->la += 5; + x[i]->master[0]->s->la += logd; /*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; } - else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + else if (f > d * fabs(x[i]->moles) + || f < 1.0/d * fabs(x[i]->moles)) { - continue; - } - else if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) - { - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; if (x[i]->moles <= 0) { x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; @@ -1931,10 +1929,10 @@ pitzer_revise_guesses(void) continue; } if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) + || f < 1.0/d * fabs(x[i]->moles)) { repeat = TRUE; - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); if (debug_set == TRUE) @@ -2265,7 +2263,10 @@ model_pz(void) { full_pitzer = FALSE; } - molalities(TRUE); + if (molalities(FALSE) == ERROR) + { + pitzer_revise_guesses(); + } if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && use.Get_surface_ptr()->Get_related_phases()) @@ -2273,6 +2274,17 @@ model_pz(void) mb_sums(); mb_gases(); mb_ss(); +/* + * Switch bases if necessary + */ + if (switch_bases() == TRUE) + { + + count_basis_change++; + count_unknowns -= (int) s_list.size(); + reprep(); + full_pitzer = false; + } /* debug species_list_sort(); sum_species(); From 85021963193e6e46c41f2fd57b1dd44b63746a74 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 30 Jun 2016 19:33:02 +0000 Subject: [PATCH 1024/1077] removing shrink for pitzer git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11401 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model.cpp b/model.cpp index f015e71b..6bd84527 100644 --- a/model.cpp +++ b/model.cpp @@ -1679,7 +1679,7 @@ ineq(int in_kode) } #define SHRINK_ARRAY #ifdef SHRINK_ARRAY - if ((sit_model || pitzer_model) && full_pitzer == FALSE) + if ((sit_model /* || pitzer_model*/) && full_pitzer == FALSE) { n = count_unknowns - (int) s_list.size(); for (int i = 0; i < l_count_rows; i++) From baf36d4af531699dec6375ea267caa53c219b89e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 30 Jun 2016 21:21:08 +0000 Subject: [PATCH 1025/1077] fix memcpy overwrite git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11412 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- model.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/model.cpp b/model.cpp index 6bd84527..c1be7fde 100644 --- a/model.cpp +++ b/model.cpp @@ -1679,19 +1679,19 @@ ineq(int in_kode) } #define SHRINK_ARRAY #ifdef SHRINK_ARRAY - if ((sit_model /* || pitzer_model*/) && full_pitzer == FALSE) + if ((sit_model || pitzer_model) && full_pitzer == FALSE) { n = count_unknowns - (int) s_list.size(); for (int i = 0; i < l_count_rows; i++) { - //for (int j = 0; j < n; j++) - //{ - // ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; - //} - if (i > 0) + for (int j = 0; j < n; j++) { - memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); + ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; } + //if (i > 0) + //{ + // memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); + //} ineq_array[i*(n+2) + n] = ineq_array[i*(count_unknowns+2) + count_unknowns]; } } From 53fade44b5c1baf74d86f09e6c676292c3602c90 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 7 Nov 2016 22:39:48 +0000 Subject: [PATCH 1026/1077] Bug when related to surface related to kinetics and proportion was zero. Think there was a bug anyway trying to identify the right surface total. Hopefully fixed. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11915 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kinetics.cpp b/kinetics.cpp index e2409cbc..ae822536 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -230,8 +230,12 @@ RESTART: // if limiting rates, jump to here if (0.9 * surface_comp_ptr->Get_phase_proportion() * (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) { - master_ptr = master_bsearch(ptr); - master_ptr->total = 0.0; + //master_ptr = master_bsearch(ptr); + master_ptr = master_bsearch(surface_comp_ptr->Get_master_element().c_str()); + if (master_ptr != NULL) + { + master_ptr->total = 0.0; + } } else { From 52ea72714790ecb8001c5e92f02961da6af93b64 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 9 Nov 2016 21:31:17 +0000 Subject: [PATCH 1027/1077] Had a problem with mismatch between mass_water (1e-6) and total_o (~55.5) from Colman phast run. Now set mass_water based on total_o. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@11937 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Solution.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Solution.cxx b/Solution.cxx index 2ed55a72..93d948c9 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1103,6 +1103,7 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->total_h = h_tot; this->total_o = o_tot; this->cb = charge; + this->mass_water = o_tot / 55.5; // Don`t bother to update activities? this->Update(const_nd); From 9a6ec5b1406f8167c4b2798261b321e49a1e4015 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 10 Jan 2017 16:55:38 +0000 Subject: [PATCH 1028/1077] Error in sys("equi",...). Returned the values from the phases structure rather than from the unknown structure. So, the value from the beginning of the simulation was given rather than the reacted amount. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12204 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index b67698a0..5390c0af 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -3246,7 +3246,8 @@ system_total_equi(void) int l; struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); sys[count_sys].name = string_duplicate(phase_ptr->name); - sys[count_sys].moles = comp_ptr->Get_moles(); + //sys[count_sys].moles = comp_ptr->Get_moles(); + sys[count_sys].moles = equi_phase(sys[count_sys].name); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("equi"); count_sys++; From b06b4f2c3349d7752889198f48ba08455ab682a8 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 31 Jan 2017 22:46:43 +0000 Subject: [PATCH 1029/1077] replace auto_ptr with unique_ptr git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12293 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kinetics.cpp b/kinetics.cpp index ae822536..78c45619 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1253,9 +1253,15 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; +#ifdef SOMETHING std::auto_ptr pp_assemblage_save(NULL); std::auto_ptr ss_assemblage_save(NULL); std::auto_ptr kinetics_save(NULL); +#else + std::unique_ptr pp_assemblage_save=NULL; + std::unique_ptr ss_assemblage_save=NULL; + std::unique_ptr kinetics_save=NULL; +#endif small_pe_step = 5.; From 80f143a6c6404d0311727f8c47f34220342ca4f4 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 1 Feb 2017 00:37:57 +0000 Subject: [PATCH 1030/1077] changed macros for unique_ptr git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12294 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kinetics.cpp b/kinetics.cpp index 78c45619..4fe7885e 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1253,14 +1253,14 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; -#ifdef SOMETHING - std::auto_ptr pp_assemblage_save(NULL); - std::auto_ptr ss_assemblage_save(NULL); - std::auto_ptr kinetics_save(NULL); -#else +#if (__cplusplus >= 201103L) || (_MSC_VER >= 1600) std::unique_ptr pp_assemblage_save=NULL; std::unique_ptr ss_assemblage_save=NULL; std::unique_ptr kinetics_save=NULL; +#else + std::auto_ptr pp_assemblage_save(NULL); + std::auto_ptr ss_assemblage_save(NULL); + std::auto_ptr kinetics_save(NULL); #endif From 424c070370909d1d07b3edbe3d2ad0da55c342e7 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 1 Feb 2017 02:22:14 +0000 Subject: [PATCH 1031/1077] fixed compilation for linux c++11 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12300 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 8 ++++++-- kinetics.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index a943a311..7ef7d7f2 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -2006,7 +2006,11 @@ public: #endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ #if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) +# if __GNUC__ && (__cplusplus >= 201103L) +# define PHR_ISFINITE(x) std::isfinite(x) +# else +# define PHR_ISFINITE(x) isfinite(x) +# endif #elif defined(HAVE_FINITE) # define PHR_ISFINITE(x) finite(x) #elif defined(HAVE_ISNAN) @@ -2222,4 +2226,4 @@ void PhreeqcIWait(Phreeqc *phreeqc); char * _string_duplicate(const char *token, const char *szFileName, int nLine); #endif -#endif //_INC_UTILITIES_NAMESPACE_H \ No newline at end of file +#endif //_INC_UTILITIES_NAMESPACE_H diff --git a/kinetics.cpp b/kinetics.cpp index 4fe7885e..c84170af 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1253,7 +1253,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; -#if (__cplusplus >= 201103L) || (_MSC_VER >= 1600) +#if (__GNUC__ && (__cplusplus >= 201103L) || (_MSC_VER >= 1600) std::unique_ptr pp_assemblage_save=NULL; std::unique_ptr ss_assemblage_save=NULL; std::unique_ptr kinetics_save=NULL; From 8d624a7f00222bd172596238bfb24d2d4359569c Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Wed, 1 Feb 2017 02:25:18 +0000 Subject: [PATCH 1032/1077] fixed compilation for linux c++11 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12301 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- kinetics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kinetics.cpp b/kinetics.cpp index c84170af..03eaefc0 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1253,7 +1253,7 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; -#if (__GNUC__ && (__cplusplus >= 201103L) || (_MSC_VER >= 1600) +#if (__GNUC__ && (__cplusplus >= 201103L)) || (_MSC_VER >= 1600) std::unique_ptr pp_assemblage_save=NULL; std::unique_ptr ss_assemblage_save=NULL; std::unique_ptr kinetics_save=NULL; From d1cf5f96d6228849b7d9b15662fc2089c8cd34a5 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 8 Feb 2017 20:26:12 +0000 Subject: [PATCH 1033/1077] Running tester on Windows. It's been a while since the test cases have been checked in. With lobo gone, will do primary checks on Windows. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12376 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile.old b/Makefile.old index 997c9a1f..5706b006 100644 --- a/Makefile.old +++ b/Makefile.old @@ -13,15 +13,16 @@ PROGRAM = phreeqc CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else +CFG :=$(shell echo $(CFG1) | sed "s/Linux.*/Linux/") +ifeq ($(CFG), Linux) SPOOL=>& SPOOL2= + CONCAT=; +else + SPOOL=> + SPOOL2=2>&1 + CONCAT=& endif - all: class_release class_debug Debug: class_debug @@ -967,8 +968,9 @@ dependencies: cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx tester: - cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make -f Makefile.old clean; make -f Makefile.old -k -j 1 $(SPOOL) make.out $(SPOOL2); make -f Makefile.old diff $(SPOOL) diff.out $(SPOOL2) +# cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../mytest $(CONCAT) make clean $(CONCAT) make -k -j 1 $(SPOOL) make.out $(SPOOL2) $(CONCAT) make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples $(CONCAT) make -f Makefile.old clean $(CONCAT) make -f Makefile.old -k -j 1 $(SPOOL) make.out $(SPOOL2) $(CONCAT) make -f Makefile.old diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples From 9bf1411f4244f9a18205ee026d8198c0c45bcf8e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 9 Feb 2017 16:41:47 +0000 Subject: [PATCH 1034/1077] Updated to PHREEQC3 12386 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12387 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 1 - Makefile.old | 27 ++- PBasic.cpp | 135 +++++++++++++- PBasic.h | 7 +- Phreeqc.cpp | 15 +- Phreeqc.h | 18 +- Solution.cxx | 1 + basicsubs.cpp | 108 +++++++++++- dw.cpp | 415 -------------------------------------------- global_structures.h | 24 +-- kinetics.cpp | 14 +- mainsubs.cpp | 2 +- model.cpp | 14 +- pitzer.cpp | 40 +++-- prep.cpp | 1 + print.cpp | 2 +- read.cpp | 17 +- tally.cpp | 1 + 18 files changed, 358 insertions(+), 484 deletions(-) delete mode 100644 dw.cpp diff --git a/Makefile.am b/Makefile.am index 21629594..b7321931 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,6 @@ phreeqc_SOURCES=\ Dictionary.h\ dumper.cpp\ dumper.h\ - dw.cpp\ Exchange.cxx\ Exchange.h\ ExchComp.cxx\ diff --git a/Makefile.old b/Makefile.old index c09c9336..e81cb2fc 100644 --- a/Makefile.old +++ b/Makefile.old @@ -15,15 +15,16 @@ PROGRAM = phreeqc MPI_DIR=/usr/lib64/openmpi CFG1 :=`uname` -CFG :=$(shell echo $(CFG1) | sed "s/CYGWIN.*/CYGWIN/") -ifeq ($(CFG), CYGWIN) - SPOOL=> - SPOOL2=2>&1 -else +CFG :=$(shell echo $(CFG1) | sed "s/Linux.*/Linux/") +ifeq ($(CFG), Linux) SPOOL=>& SPOOL2= + CONCAT=; +else + SPOOL=> + SPOOL2=2>&1 + CONCAT=& endif - all: release_openmp Debug: debug @@ -235,7 +236,6 @@ COMMON_COBJS = \ cvdense.o \ cvode.o \ dense.o \ - dw.o \ gases.o \ input.o \ integrate.o \ @@ -685,14 +685,6 @@ Dictionary.o: ../Dictionary.cpp ../Dictionary.h dumper.o: ../dumper.cpp ../dumper.h ../StorageBinList.h \ ../common/PHRQ_base.h ../common/Parser.h ../common/PHRQ_base.h \ ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/PHRQ_io.h -dw.o: ../dw.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h ../cvode.h \ - ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h ../runner.h \ - ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ - ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h ../SelectedOutput.h \ - ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../common/PHRQ_io.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h gases.o: ../gases.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ @@ -1161,8 +1153,9 @@ dependencies: -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.cpp ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.c tester: - cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) - cd ../examples; make -f Makefile.old clean; make -f Makefile.old -k -j 1 $(SPOOL) make.out $(SPOOL2); make -f Makefile.old diff $(SPOOL) diff.out $(SPOOL2) +# cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) + cd ../mytest $(CONCAT) make clean $(CONCAT) make -k -j 1 $(SPOOL) make.out $(SPOOL2) $(CONCAT) make diff $(SPOOL) diff.out $(SPOOL2) + cd ../examples $(CONCAT) make -f Makefile.old clean $(CONCAT) make -f Makefile.old -k -j 1 $(SPOOL) make.out $(SPOOL2) $(CONCAT) make -f Makefile.old diff $(SPOOL) diff.out $(SPOOL2) svn status -q ../mytest svn status -q ../examples diff --git a/PBasic.cpp b/PBasic.cpp index 7e1d69c2..c3845ca7 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1529,6 +1529,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokrho: output_msg("RHO"); break; + case tokrho_0: + output_msg("RHO_0"); + break; /* VP: Density End */ case tokcell_volume: output_msg("CELL_VOLUME"); @@ -1548,6 +1551,10 @@ listtokens(FILE * f, tokenrec * l_buf) case tokiso_unit: output_msg("ISO_UNIT"); break; + case tokkinetics_formula: + case tokkinetics_formula_: + output_msg("KINETICS_FORMULA$"); + break; case tokphase_formula: case tokphase_formula_: output_msg("PHASE_FORMULA$"); @@ -1580,6 +1587,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokvm: output_msg("VM"); // mole volume of aqueous solute break; + case tokphase_vm: + output_msg("PHASE_VM"); // mole volume of a phase + break; case tokdh_a: output_msg("DH_A"); // Debye-Hueckel A break; @@ -1629,9 +1639,6 @@ listtokens(FILE * f, tokenrec * l_buf) case tokviscos_0: output_msg("VISCOS_0"); break; - case tokrho_0: - output_msg("RHO_0"); - break; case tokcurrent_a: output_msg("CURRENT_A"); break; @@ -2946,6 +2953,112 @@ factor(struct LOC_exec * LINK) break; } + case tokkinetics_formula: + case tokkinetics_formula_: + { + require(toklp, LINK); + std::string kinetics_name(stringfactor(STR1, LINK)); + varrec *elts_varrec = NULL, *coef_varrec = NULL; + cxxNameDouble stoichiometry; + /* + * Parse arguments + */ + if (LINK->t != NULL && LINK->t->kind == tokcomma) + { + /* kinetics_formula("calcite", count, elt, coef) */ + /* return formula */ + /*int c; */ + /* struct varrec *count_varrec, *names_varrec, *types_varrec, *moles_varrec; */ + /* struct varrec *count_varrec, *elt_varrec, *coef_varrec; */ + /* return number of species */ + LINK->t = LINK->t->next; + count_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || count_varrec->stringvar != 0) + snerr(": Cannot find count variable"); + + /* return number of names of elements */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + elts_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1) + snerr(": Cannot find element string variable"); + + /* return coefficients of species */ + LINK->t = LINK->t->next; + require(tokcomma, LINK); + coef_varrec = LINK->t->UU.vp; + if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0) + snerr(": Cannot find coefficient variable"); + LINK->t = LINK->t->next; + arg_num = 4; + } + else + { + arg_num = 1; + } + require(tokrp, LINK); + + if (arg_num > 1) + { + free_dim_stringvar(elts_varrec); + PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr); + coef_varrec->UU.U0.arr = NULL; + } + /* + * Call subroutine + */ + std::string form = PhreeqcPtr->kinetics_formula(kinetics_name, stoichiometry); + + // put formula as return value + n.stringval = true; + n.UU.sval = PhreeqcPtr->string_duplicate(form.c_str()); + + /* + * fill in varrec structure + */ + + if (arg_num > 1) + { + size_t count = stoichiometry.size(); + *count_varrec->UU.U0.val = (LDBLE) count; + /* + * malloc space + */ + elts_varrec->UU.U1.sarr = (char **) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char *)); + if (elts_varrec->UU.U1.sarr == NULL) + PhreeqcPtr->malloc_error(); + coef_varrec->UU.U0.arr = (LDBLE *) PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE)); + if (coef_varrec->UU.U0.arr == NULL) + PhreeqcPtr->malloc_error(); + + // first position not used + elts_varrec->UU.U1.sarr[0] = NULL; + coef_varrec->UU.U0.arr[0] = 0; + + // set dims for Basic array + for (i = 0; i < maxdims; i++) + { + elts_varrec->dims[i] = 0; + coef_varrec->dims[i] = 0; + } + // set dims for first dimension and number of dims + elts_varrec->dims[0] = (long) (count + 1); + coef_varrec->dims[0] = (long) (count + 1); + elts_varrec->numdims = 1; + coef_varrec->numdims = 1; + + // fill in arrays + i = 1; + for (cxxNameDouble::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++) + { + elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str()); + coef_varrec->UU.U0.arr[i] = it->second; + i++; + } + + } + break; + } case tokphase_formula: case tokphase_formula_: { @@ -3470,6 +3583,9 @@ factor(struct LOC_exec * LINK) case tokrho: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_dens(); break; + case tokrho_0: + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rho_0; + break; /* VP: Density End */ case tokcell_volume: { @@ -3552,9 +3668,6 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos_0; } break; - case tokrho_0: - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->rho_0; - break; case tokcurrent_a: //n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_x; n.UU.val = (parse_all) ? 1 : PhreeqcPtr->current_A; @@ -3576,6 +3689,13 @@ factor(struct LOC_exec * LINK) //} } break; + case tokphase_vm: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->phase_vm(str); + } + break; + case toksin: n.UU.val = sin(realfactor(LINK)); break; @@ -7178,6 +7298,9 @@ const std::map::value_type temp_tokens[] std::map::value_type("viscos", PBasic::tokviscos), std::map::value_type("viscos_0", PBasic::tokviscos_0), std::map::value_type("rho_0", PBasic::tokrho_0), + std::map::value_type("kinetics_formula", PBasic::tokkinetics_formula), + std::map::value_type("kinetics_formula$", PBasic::tokkinetics_formula), + std::map::value_type("phase_vm", PBasic::tokphase_vm), std::map::value_type("current_a", PBasic::tokcurrent_a), std::map::value_type("pot_v", PBasic::tokpot_v), std::map::value_type("setdiff_c", PBasic::toksetdiff_c) diff --git a/PBasic.h b/PBasic.h index a943186d..7ea9079e 100644 --- a/PBasic.h +++ b/PBasic.h @@ -279,6 +279,7 @@ public: tokgamma, toklg, tokrho, + tokrho_0, tokcell_volume, tokcell_pore_volume, tokcell_porosity, @@ -294,6 +295,8 @@ public: tokeol_, tokceil, tokfloor, + tokkinetics_formula, + tokkinetics_formula_, tokphase_formula, tokphase_formula_, tokspecies_formula, @@ -328,9 +331,9 @@ public: tokedl_species, tokviscos, tokviscos_0, - tokrho_0, tokcurrent_a, - tokpot_v + tokpot_v, + tokphase_vm }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 07f7b776..cc163a7d 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -276,6 +276,13 @@ void Phreeqc::init(void) punch.charge_balance = FALSE; punch.percent_error = FALSE; #endif + + MIN_LM = -30.0; /* minimum log molality allowed before molality set to zero */ + LOG_ZERO_MOLALITY = -30; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ + MIN_RELATED_LOG_ACTIVITY = -30; + MIN_TOTAL = 1e-25; + MIN_TOTAL_SS = MIN_TOTAL/100; + MIN_RELATED_SURFACE = MIN_TOTAL*100; // auto Rxn_temperature_map; // auto Rxn_pressure_map; @@ -1173,6 +1180,12 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) current_mu = pSrc->current_mu; mu_terms_in_logk = pSrc->mu_terms_in_logk; + MIN_LM = pSrc->MIN_LM; /* minimum log molality allowed before molality set to zero */ + LOG_ZERO_MOLALITY = pSrc->LOG_ZERO_MOLALITY; /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ + MIN_RELATED_LOG_ACTIVITY = pSrc->MIN_RELATED_LOG_ACTIVITY; + MIN_TOTAL = pSrc->MIN_TOTAL; + MIN_TOTAL_SS = pSrc->MIN_TOTAL_SS; + MIN_RELATED_SURFACE = pSrc->MIN_RELATED_SURFACE; /* ---------------------------------------------------------------------- * STRUCTURES * ---------------------------------------------------------------------- */ @@ -2536,4 +2549,4 @@ int Phreeqc::next_user_number(Keywords::KEYWORDS key) assert(false); return -999; } -} \ No newline at end of file +} diff --git a/Phreeqc.h b/Phreeqc.h index d1229825..850558f0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -100,6 +100,7 @@ public: LDBLE activity_coefficient(const char *species_name); LDBLE log_activity_coefficient(const char *species_name); LDBLE aqueous_vm(const char *species_name); + LDBLE phase_vm(const char *phase_name); LDBLE diff_c(const char *species_name); LDBLE setdiff_c(const char *species_name, double d); LDBLE sa_declercq(double type, double sa, double d, double m, double m0, double gfw); @@ -148,6 +149,7 @@ public: static int system_species_compare(const void *ptr1, const void *ptr2); LDBLE system_total(const char *total_name, LDBLE * count, char ***names, char ***types, LDBLE ** moles); + std::string kinetics_formula(std::string kinetics_name, cxxNameDouble &stoichiometry); std::string phase_formula(std::string phase_name, cxxNameDouble &stoichiometry); std::string species_formula(std::string phase_name, cxxNameDouble &stoichiometry); LDBLE list_ss(std::string ss_name, cxxNameDouble &composition); @@ -158,6 +160,7 @@ public: int system_total_surf(void); int system_total_gas(void); int system_total_equi(void); + int system_total_kin(void); int system_total_ss(void); int system_total_elt(const char *total_name); int system_total_elt_secondary(const char *total_name); @@ -1605,6 +1608,13 @@ protected: int stop_program; int incremental_reactions; + double MIN_LM; + double LOG_ZERO_MOLALITY; + double MIN_TOTAL; + double MIN_TOTAL_SS; + double MIN_RELATED_SURFACE; + double MIN_RELATED_LOG_ACTIVITY; + int count_strings; int max_strings; @@ -2008,7 +2018,11 @@ public: #endif /*defined (PHREEQ98) || defined (_MSC_VER)*/ #if defined(HAVE_ISFINITE) -# define PHR_ISFINITE(x) isfinite(x) +# if __GNUC__ && (__cplusplus >= 201103L) +# define PHR_ISFINITE(x) std::isfinite(x) +# else +# define PHR_ISFINITE(x) isfinite(x) +# endif #elif defined(HAVE_FINITE) # define PHR_ISFINITE(x) finite(x) #elif defined(HAVE_ISNAN) @@ -2224,4 +2238,4 @@ void PhreeqcIWait(Phreeqc *phreeqc); char * _string_duplicate(const char *token, const char *szFileName, int nLine); #endif -#endif //_INC_UTILITIES_NAMESPACE_H \ No newline at end of file +#endif //_INC_UTILITIES_NAMESPACE_H diff --git a/Solution.cxx b/Solution.cxx index bb8dd693..3500128d 100644 --- a/Solution.cxx +++ b/Solution.cxx @@ -1120,6 +1120,7 @@ cxxSolution::Update(LDBLE h_tot, LDBLE o_tot, LDBLE charge, const cxxNameDouble this->total_h = h_tot; this->total_o = o_tot; this->cb = charge; + this->mass_water = o_tot / 55.5; // Don`t bother to update activities? this->Update(const_nd); diff --git a/basicsubs.cpp b/basicsubs.cpp index 9aae8fce..bb13b495 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -98,7 +98,26 @@ aqueous_vm(const char *species_name) } return (g); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +phase_vm(const char *phase_name) +/* ---------------------------------------------------------------------- */ +{ + struct phase *phase_ptr; + int l; + LDBLE g; + phase_ptr = phase_bsearch(phase_name, &l, FALSE); + if (phase_ptr == NULL) + { + g = 0.0; + } + else + { + g = phase_ptr->logk[vm0]; + } + return (g); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: sa_declercq(double sa_type, double Sa, double d, double m, double m0, double gfw) @@ -2954,6 +2973,10 @@ system_total(const char *total_name, LDBLE * count, char ***names, { system_total_equi(); } + else if (strcmp_nocase(total_name, "kin") == 0) + { + system_total_kin(); + } else { if (strstr(total_name, "(") == NULL) @@ -3014,6 +3037,64 @@ system_total(const char *total_name, LDBLE * count, char ***names, return (sys_tot); } +/* ---------------------------------------------------------------------- */ +std::string Phreeqc:: +kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry) +/* ---------------------------------------------------------------------- */ +{ +/* + * Returns formula of kinetic reactant + * Also returns arrays of elements and stoichiometry in stoichiometry + */ + stoichiometry.clear(); + std::string formula; + + if (use.Get_kinetics_ptr() == NULL) + return (formula); + std::vector comps = use.Get_kinetics_ptr()->Get_kinetics_comps(); + count_elts = 0; + paren_count = 0; + for (size_t i=0 ; i < comps.size(); i++) + { + cxxKineticsComp *comp_ptr = &comps[i]; + if (kin_name == comp_ptr->Get_rate_name().c_str()) + { + cxxNameDouble nd = comp_ptr->Get_namecoef(); + cxxNameDouble::iterator it = nd.begin(); + for ( ; it != nd.end(); it++) + { + // Try Phases + int l; + struct phase *phase_ptr = phase_bsearch(it->first.c_str(), &l, FALSE); + if (phase_ptr != NULL) + { + add_elt_list(phase_ptr->next_elt, it->second); + } + else + { + // add formula + std::string name = it->first; + LDBLE coef = it->second; + char * temp_name = string_duplicate(name.c_str()); + char *ptr = temp_name; + get_elts_in_species(&ptr, coef); + free_check_null(temp_name); + } + } + formula.append(kin_name); + //elt_list[count_elts].elt = NULL; + if (count_elts > 0) + { + qsort(elt_list, (size_t) count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + stoichiometry = elt_list_NameDouble(); + break; + } + } + return (formula); +} /* ---------------------------------------------------------------------- */ std::string Phreeqc:: phase_formula(std::string phase_name, cxxNameDouble &stoichiometry) @@ -3363,7 +3444,8 @@ system_total_equi(void) int l; struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE); sys[count_sys].name = string_duplicate(phase_ptr->name); - sys[count_sys].moles = comp_ptr->Get_moles(); + //sys[count_sys].moles = comp_ptr->Get_moles(); + sys[count_sys].moles = equi_phase(sys[count_sys].name); sys_tot += sys[count_sys].moles; sys[count_sys].type = string_duplicate("equi"); count_sys++; @@ -3374,6 +3456,30 @@ system_total_equi(void) } /* ---------------------------------------------------------------------- */ int Phreeqc:: +system_total_kin(void) +/* ---------------------------------------------------------------------- */ +{ +/* + * Equilibrium phases + */ + if (use.Get_kinetics_ptr() == NULL) + return (OK); + std::vector comps = use.Get_kinetics_ptr()->Get_kinetics_comps(); + for (size_t i=0 ; i < comps.size(); i++) + { + cxxKineticsComp *comp_ptr = &comps[i]; + sys[count_sys].name = string_duplicate(comp_ptr->Get_rate_name().c_str()); + sys[count_sys].moles = comp_ptr->Get_m(); + sys_tot += sys[count_sys].moles; + sys[count_sys].type = string_duplicate("kin"); + count_sys++; + space((void **) ((void *) &sys), count_sys, &max_sys, + sizeof(struct system_species)); + } + return (OK); +} +/* ---------------------------------------------------------------------- */ +int Phreeqc:: system_total_ss(void) /* ---------------------------------------------------------------------- */ { diff --git a/dw.cpp b/dw.cpp deleted file mode 100644 index 5c1e25c8..00000000 --- a/dw.cpp +++ /dev/null @@ -1,415 +0,0 @@ -#include "Phreeqc.h" - -#ifdef SKIP -/* ---------------------------------------------------------------------- */ -int Phreeqc:: -DW(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C SUBROUTINE TO CALCULATE THE DENSITY OF WATER AS A FUNCTION OF -C TEMPERATURE. T IS IN KELVIN, P IS IN PASCALS, DW0 IS IN G/CM^3 -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE FP = 9.869232667e0, P, DGSS, D; - - BB(T); - P = 1.0e0 / FP; - if (T > 373.149e0) - P = PS(T); - DGSS = P / T / .4e0; - if (T < TZ) - { - DGSS = 1.0e0 / (VLEST(T)); - } - DFIND(&D, P, DGSS, T); - DW0 = D; - VP = P * FP; - return OK; -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -BB(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* - -C -C THIS SUBROUTINE CALCULATES THE B'S NEEDED FOR FUNCTION DW. -C THE B'S CALCULATED HERE ARE IN CM3/G. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE V[11]; - int I; - /* COMMON /BCONST/ */ - LDBLE P[11] = - { 0, 0.7478629e0, -.3540782e0, 0.e0, 0e0, .007159876e0, 0.e0, - -.003528426e0, 0., 0., 0. - }; - LDBLE Q[11] = - { 0, 1.1278334e0, 0.e0, -.5944001e0, -5.010996e0, 0.e0, .63684256e0, - 0., 0., 0., 0. - }; - - V[1] = 1.0; - for (I = 2; I <= 10; I++) - { - V[I] = V[I - 1] * TZ / T; - } - B1 = P[1] + P[2] * log(1.e0 / V[2]); - B2 = Q[1]; - B1T = P[2] * V[2] / TZ; - B2T = 0.e0; - B1TT = 0.e0; - B2TT = 0.e0; - for (I = 3; I <= 10; I++) - { - B1 = B1 + P[I] * V[I - 1]; - B2 = B2 + Q[I] * V[I - 1]; - B1T = B1T - (I - 2) * P[I] * V[I - 1] / T; - B2T = B2T - (I - 2) * Q[I] * V[I - 1] / T; - B1TT = B1TT + P[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; - B2TT = B2TT + Q[I] * (I - 2) * (I - 2) * V[I - 1] / T / T; - } - B1TT = B1TT - B1T / T; - B2TT = B2TT - B2T / T; - return OK; -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -PS(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES AN APPROXIMATION TO THE VAPOR PRESSURE, P -C AS A FUNCTION OF THE INPUT TEMPERATURE. THE VAPOR PRESSURE -C CALCULATED AGREES WITH THE VAPOR PRESSURE PREDICTED BY THE SURFACE -C TO WITHIN .02% TO WITHIN A DEGREE OR SO OF THE CRITICAL TEMPERATUR -C AND CAN SERVE AS AN INITIAL GUESS FOR FURTHER REFINEMENT BY -C IMPOSING THE CONDITION THAT GL=GV. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE A[9] = { 0, -7.8889166e0, 2.5514255e0, -6.716169e0, - 33.239495e0, -105.38479e0, 174.35319e0, -148.39348e0, - 48.631602e0 - }; - LDBLE PL, V, W, B, L_Z, Q; - int I; - if (T <= 314.e0) - { - PL = 6.3573118e0 - 8858.843e0 / T + 607.56335e0 * pow(T, (LDBLE) -.6e0); - return (.1e0 * exp(PL)); - } - V = T / 647.25e0; - W = fabs(1.e0 - V); - B = 0.e0; - for (I = 1; I <= 8; I++) - { - L_Z = I; - B = B + A[I] * pow(W, ((L_Z + 1.e0) / 2.e0)); - } - Q = B / V; - return (22.093e0 * exp(Q)); -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -VLEST(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE A = -1.59259e1, B = 6.57886e-2, C = -1.12666e-4, D = 7.33191e-8, - E = 1.60229e3, F = 2.88572e0, G = 650.0e0; - - return (A + B * T + C * T * T + D * T * T * T + E / T + F / (G - T)); -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -DFIND(LDBLE * DOUT, LDBLE P, LDBLE D, LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C ROUTINE TO FIND DENSITY CORRESPONDING TO INPUT PRESSURE P(MPA), AN -C TEMPERATURE T(K), USING INITIAL GUESS DENSITY D(G/CM3). THE OUTPUT -C DENSITY IS IN G/CM3. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - int L; - LDBLE DD, RT, PP_dfind, DPD, DPDX, DP, X; - /* LDBLE DD, RT, PP, DPD, DPDX, DP, X; */ - - DD = D; - RT = GASCON * T; - if (DD <= 0.e0) - DD = 1.e-8; - if (DD > 1.9e0) - DD = 1.9e0; - L = 0; - for (L = 1; L <= 30; L++) - { - if (DD <= 0.e0) - DD = 1.e-8; - if (DD > 1.9e0) - DD = 1.9e0; - QQ(T, DD); - PP_dfind = RT * DD * BASE(DD) + Q0; - DPD = RT * (Z + Y * DZ) + Q5; - /* - C - C THE FOLLOWING 3 LINES CHECK FOR NEGATIVE DP/DRHO, AND IF SO ASSUME - C GUESS TO BE IN 2-PHASE REGION, AND CORRECT GUESS ACCORDINGLY. - C - */ - if (DPD <= 0.e0) - { - if (D >= .2967e0) - DD = DD * 1.02e0; - if (D < .2967e0) - DD = DD * .98e0; - if (L <= 10) - continue; - } - else - { -/* 13 */ - DPDX = DPD * 1.1e0; - if (DPDX < 0.1e0) - DPDX = 0.1e0; - DP = fabs(1.e0 - PP_dfind / P); - if (DP < 1.e-8) - break; - if (D > .3e0 && DP < 1.e-7) - break; - if (D > .7e0 && DP < 1.e-6) - break; - X = (P - PP_dfind) / DPDX; - if (fabs(X) > .1e0) - X = X * .1e0 / fabs(X); - DD = DD + X; - if (DD < 0.e0) - DD = 1.e-8; - } - } - if (L > 30) - error_msg("In subroutine DFIND", STOP); - //cite Jonathan Toner, remove error_msg - //DD = 1; -/* 20 CONTINUE */ - *DOUT = DD; - return OK; -} - -/* ---------------------------------------------------------------------- */ - int Phreeqc:: -QQ(LDBLE T, LDBLE D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS ROUTINE CALCULATES, FOR A GIVEN T(K) AND D(G/CM3), THE RESIDUL -C CONTRIBUTIONS TO: PRESSURE (Q), DP/DRHO (Q5) -C THIS SUBROUTINE IS USED IN DENSITY OF WATER CALCULATION. -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - /* COMMON /NCONST/ */ - LDBLE G[41] = - { 0, -.53062968529023e3, .22744901424408e4, .78779333020687e3, - -.69830527374994e2, .17863832875422e5, -.39514731563338e5, - .33803884280753e5, - -.13855050202703e5, -.25637436613260e6, .48212575981415e6, - -.34183016969660e6, - .12223156417448e6, .11797433655832e7, -.21734810110373e7, - .10829952168620e7, - -.25441998064049e6, -.31377774947767e7, .52911910757704e7, - -.13802577177877e7, - -.25109914369001e6, .46561826115608e7, -.72752773275387e7, - .41774246148294e6, - .14016358244614e7, -.31555231392127e7, .47929666384584e7, - .40912664781209e6, - -.13626369388386e7, .69625220862664e6, -.10834900096447e7, - -.22722827401688e6, - .38365486000660e6, .68833257944332e4, .21757245522644e5, - -.26627944829770e4, - -.70730418082074e5, -.225e0, -1.68e0, .055e0, -93.0e0 - }; - /*int II[41]={0,4*0,4*1,4*2,4*3,4*4,4*5,4*6,4*8,2*2,0,4,3*2,4}; */ - int II[41] = - { 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, - 5, - 5, 6, 6, 6, 6, 8, 8, 8, 8, 2, 2, 0, 4, 2, 2, 2, 4 - }; - /*int JJ[41]={0,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,2,3,5,7,1,3*4,0,2,0,0}; */ - int JJ[41] = - { 0, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, 5, 7, 2, 3, - 5, - 7, 2, 3, 5, 7, 2, 3, 5, 7, 1, 4, 4, 4, 0, 2, 0, 0 - }; - int NC = 36; - /* COMMON /ADDCON/ */ - LDBLE ATZ[5] = { 0, 64.e1, 64.e1, 641.6e0, 27.e1 }, ADZ[5] = - { - 0, .319e0, .319e0, .319e0, 1.55e0}, AAT[5] = - { - 0, 2.e4, 2.e4, 4.e4, 25.e0}, AAD[5] = - { - 0, 34.e0, 4.e1, 3.e1, 1.05e3}; - LDBLE *QZT; - LDBLE QR[12], QT[11] /*, QZT[10] */ ; - /*EQUIVALENCE (QT(2),QZT(1)) */ - - LDBLE E, Q10, Q20, V, QP, DDZ, DEL, EX1, DEX, ATT, TX, - TAU, EX2, TEX, QM, FCT, Q5T; - int I, K, L, J, KM; - QZT = &(QT[1]); - QR[1] = 0.e0; - Q5 = 0.e0; - Q0 = 0.e0; - E = exp(-AA * D); - Q10 = D * D * E; - Q20 = 1.e0 - E; - QR[2] = Q10; - V = TZ / T; - QT[1] = T / TZ; - /*DO 4 I=2,10 */ - for (I = 2; I <= 10; I++) - { - QR[I + 1] = QR[I] * Q20; - /* 4 QT[I]=QT[I-1]*V */ - QT[I] = QT[I - 1] * V; - } - /* DO 10 I=1,NC */ - for (I = 1; I <= NC; I++) - { - K = II[I] + 1; - L = JJ[I]; - QP = G[I] * AA * QR[K + 1] * QZT[L]; - Q0 = Q0 + QP; - /*10 Q5 = Q5 + AA*(2.e0/D-AA*(1.e0-E*(K-1)/Q20))*QP */ - Q5 = Q5 + AA * (2.e0 / D - AA * (1.e0 - E * (K - 1) / Q20)) * QP; - } - QP = 0.e0; - /* DO 20 J=37,40 */ - for (J = 37; J <= 40; J++) - { - if (fabs(G[J]) < 1.0e-20) - continue; - K = II[J]; - KM = JJ[J]; - DDZ = ADZ[J - 36]; - DEL = D / DDZ - 1.e0; - if (fabs(DEL) < 1.e-10) - DEL = 1.e-10; - EX1 = -AAD[J - 36] * pow(DEL, K); - if (EX1 <= -88.028e0) - { - DEX = 0.e0; - } - else - { - DEX = exp(EX1) * pow(DEL, KM); - } - ATT = AAT[J - 36]; - TX = ATZ[J - 36]; - TAU = T / TX - 1.e0; - EX2 = -ATT * TAU * TAU; - if (EX2 <= -88.028e0) - { - TEX = 0.e0; - } - else - { - TEX = exp(EX2); - } - Q10 = DEX * TEX; - QM = KM / DEL - K * AAD[J - 36] * pow(DEL, (K - 1)); - FCT = QM * D * D * Q10 / DDZ; - Q5T = - FCT * (2.e0 / D + QM / DDZ) - pow((D / DDZ), - 2) * Q10 * (KM / DEL / DEL + - K * (K - - 1) * AAD[J - - 36] * - pow(DEL, (K - 2))); - Q5 = Q5 + Q5T * G[J]; - QP = QP + G[J] * FCT; - /* 20 CONTINUE */ - } - Q0 = Q0 + QP; - return OK; -} - -/* ---------------------------------------------------------------------- */ - LDBLE Phreeqc:: -BASE(LDBLE D) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE Z (=PBASE/(DRT)) NEEDED FOR FUNCTION -C -C FROM L. HAAR, J. S. GALLAGHER, AND G. S. KELL, (1984) -C -*/ -{ - LDBLE X, Z0, DZ0; -/* -C -C G1,G2 AND GF ARE THE ALPHA, BETA AND GAMMA FOR DENSITY OF WATER -C CALCULATIONS. B1 AND B2 ARE THE 'EXCLUDED VOLUME' AND '2ND VIRIAL -C SUPPLIED BY THE SUBROUTINE BB(T), WHICH ALSO SUPPLIES THE 1ST AND -C 2ND DERIVATIVES WITH RESPECT TO T (B1T,B2T,B1TT,B2TT). -C -*/ - Y = .25e0 * B1 * D; - X = 1.e0 - Y; - Z0 = (1.e0 + G1 * Y + G2 * Y * Y) / pow(X, 3); - Z = Z0 + 4.e0 * Y * (B2 / B1 - GF); - DZ0 = - (G1 + 2.e0 * G2 * Y) / pow(X, - 3) + 3.e0 * (1.e0 + G1 * Y + - G2 * Y * Y) / pow(X, 4); - DZ = DZ0 + 4.e0 * (B2 / B1 - GF); - return (Z); -} - -/* ---------------------------------------------------------------------- */ -LDBLE Phreeqc:: -DC(LDBLE T) -/* ---------------------------------------------------------------------- */ -/* -C -C THIS FUNCTION CALCULATES THE RELATIVE DIELECTRIC CONSTANT AS A -C FUNCTION OF TEMPERATURE, ASSUMING ONE ATMOSPHERE PRESSURE -C ACCORDING TO D. J. BRADLEY AND K. S. PITZER, (1979) -C -*/ -{ - LDBLE D1000, C, B; - LDBLE U[10] = { 0, 3.4279e2, -5.0866e-3, 9.4690e-7, -2.0525e0, 3.1159e3, - -1.8289e2, -8.0325e3, 4.2142e6, 2.1417e0 - }; - D1000 = U[1] * exp(U[2] * T + U[3] * T * T); - C = U[4] + U[5] / (U[6] + T); - B = U[7] + U[8] / T + U[9] * T; - return (D1000 + C * log((B + VP * 1.01325e0) / (B + 1000.0e0))); -} -#endif \ No newline at end of file diff --git a/global_structures.h b/global_structures.h index 9c64a3f9..d1480e3a 100644 --- a/global_structures.h +++ b/global_structures.h @@ -132,19 +132,19 @@ #define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ #define MAX_M 1000.0 #ifdef USE_DECIMAL128 -#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ -#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-60 -#define MIN_TOTAL_SS MIN_TOTAL/100 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -60 +//#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ +//#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +//#define MIN_TOTAL 1e-60 +//#define MIN_TOTAL_SS MIN_TOTAL/100 +//#define MIN_RELATED_SURFACE MIN_TOTAL*100 +//#define MIN_RELATED_LOG_ACTIVITY -60 #else -#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ -#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -#define MIN_TOTAL 1e-25 -#define MIN_TOTAL_SS MIN_TOTAL/100 -#define MIN_RELATED_SURFACE MIN_TOTAL*100 -#define MIN_RELATED_LOG_ACTIVITY -30 +//#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +//#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +//#define MIN_TOTAL 1e-25 +//#define MIN_TOTAL_SS MIN_TOTAL/100 +//#define MIN_RELATED_SURFACE MIN_TOTAL*100 +//#define MIN_RELATED_LOG_ACTIVITY -30 #endif #define REF_PRES_PASCAL 1.01325E5 /* Reference pressure: 1 atm */ /* diff --git a/kinetics.cpp b/kinetics.cpp index e2409cbc..03eaefc0 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -230,8 +230,12 @@ RESTART: // if limiting rates, jump to here if (0.9 * surface_comp_ptr->Get_phase_proportion() * (kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE) { - master_ptr = master_bsearch(ptr); - master_ptr->total = 0.0; + //master_ptr = master_bsearch(ptr); + master_ptr = master_bsearch(surface_comp_ptr->Get_master_element().c_str()); + if (master_ptr != NULL) + { + master_ptr->total = 0.0; + } } else { @@ -1249,9 +1253,15 @@ set_and_run_wrapper(int i, int use_mix, int use_kinetics, int nsaver, int old_diag, old_itmax; LDBLE old_tol, old_min_value, old_step, old_pe, old_pp_column_scale; LDBLE small_pe_step, small_step; +#if (__GNUC__ && (__cplusplus >= 201103L)) || (_MSC_VER >= 1600) + std::unique_ptr pp_assemblage_save=NULL; + std::unique_ptr ss_assemblage_save=NULL; + std::unique_ptr kinetics_save=NULL; +#else std::auto_ptr pp_assemblage_save(NULL); std::auto_ptr ss_assemblage_save(NULL); std::auto_ptr kinetics_save(NULL); +#endif small_pe_step = 5.; diff --git a/mainsubs.cpp b/mainsubs.cpp index 329b35a6..5255df5a 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -2391,7 +2391,7 @@ run_simulations(void) { char token[MAX_LENGTH]; //#ifdef SKIP_KEEP -#if defined(WIN32) +#if defined(_MSC_VER) && (_MSC_VER < 1900) // removed in vs2015 unsigned int old_exponent_format; old_exponent_format = _set_output_format(_TWO_DIGIT_EXPONENT); #endif diff --git a/model.cpp b/model.cpp index 28a1fff7..52fef802 100644 --- a/model.cpp +++ b/model.cpp @@ -1679,19 +1679,19 @@ ineq(int in_kode) } #define SHRINK_ARRAY #ifdef SHRINK_ARRAY - if (sit_model && full_pitzer == FALSE) + if ((sit_model || pitzer_model) && full_pitzer == FALSE) { n = count_unknowns - (int) s_list.size(); for (int i = 0; i < l_count_rows; i++) { - //for (int j = 0; j < n; j++) - //{ - // ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; - //} - if (i > 0) + for (int j = 0; j < n; j++) { - memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); + ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; } + //if (i > 0) + //{ + // memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); + //} ineq_array[i*(n+2) + n] = ineq_array[i*(count_unknowns+2) + count_unknowns]; } } diff --git a/pitzer.cpp b/pitzer.cpp index ccf71508..ae4edfb1 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1812,12 +1812,14 @@ pitzer_revise_guesses(void) int l_iter, max_iter, repeat, fail; LDBLE weight, f; - max_iter = 10; + max_iter = 100; /* gammas(mu_x); */ l_iter = 0; repeat = TRUE; - fail = FALSE;; - while (repeat == TRUE) + fail = FALSE; + double d = 2; + double logd = log10(d); + while (repeat == TRUE && fail == FALSE) { l_iter++; if (debug_set == TRUE) @@ -1892,18 +1894,14 @@ pitzer_revise_guesses(void) else if (f == 0) { repeat = TRUE; - x[i]->master[0]->s->la += 5; + x[i]->master[0]->s->la += logd; /*!!!!*/ if (x[i]->master[0]->s->la < -999.) x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; } - else if (fail == TRUE && f < 1.5 * fabs(x[i]->moles)) + else if (f > d * fabs(x[i]->moles) + || f < 1.0/d * fabs(x[i]->moles)) { - continue; - } - else if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) - { - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; if (x[i]->moles <= 0) { x[i]->master[0]->s->la = MIN_RELATED_LOG_ACTIVITY; @@ -1932,10 +1930,10 @@ pitzer_revise_guesses(void) continue; } if (f > 1.5 * fabs(x[i]->moles) - || f < 1e-5 * fabs(x[i]->moles)) + || f < 1.0/d * fabs(x[i]->moles)) { repeat = TRUE; - weight = (f < 1e-5 * fabs(x[i]->moles)) ? 0.3 : 1.0; + weight = (f < 1.0/d * fabs(x[i]->moles)) ? 0.3 : 1.0; x[i]->master[0]->s->la += weight * log10(fabs(x[i]->moles / x[i]->sum)); if (debug_set == TRUE) @@ -2266,7 +2264,10 @@ model_pz(void) { full_pitzer = FALSE; } - molalities(TRUE); + if (molalities(FALSE) == ERROR) + { + pitzer_revise_guesses(); + } if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_dl_type() != cxxSurface::NO_DL && use.Get_surface_ptr()->Get_related_phases()) @@ -2274,6 +2275,17 @@ model_pz(void) mb_sums(); mb_gases(); mb_ss(); +/* + * Switch bases if necessary + */ + if (switch_bases() == TRUE) + { + + count_basis_change++; + count_unknowns -= (int) s_list.size(); + reprep(); + full_pitzer = false; + } /* debug species_list_sort(); sum_species(); diff --git a/prep.cpp b/prep.cpp index beb44728..db0e3b52 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4099,6 +4099,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) P = 1.; } else { + if (P < 1e-10) P = 1e-10; r3[1] = b_sum - R_TK / P; r3_12 = r3[1] * r3[1]; r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; diff --git a/print.cpp b/print.cpp index 0d45f206..63738391 100644 --- a/print.cpp +++ b/print.cpp @@ -3185,7 +3185,7 @@ punch_identifiers(void) (double) (100 * cb_x / total_ions_x)); } } - + punch_flush(); return (OK); } diff --git a/read.cpp b/read.cpp index 72e44676..43bb516e 100644 --- a/read.cpp +++ b/read.cpp @@ -4807,12 +4807,17 @@ read_selected_output(void) else if (n_user == 1 && so == SelectedOutput_map.end()) { // n_user = 1, new definition, do nothing use; constructor default + temp_selected_output.Set_new_def(true); } else { // n_user != 1 then reset false temp_selected_output.Reset(false); + if (so == SelectedOutput_map.end()) + { + temp_selected_output.Set_new_def(true); + } } CParser parser(this->phrq_io); @@ -8346,9 +8351,11 @@ read_debug(void) "try", /* 17 */ "numerical_fixed_volume", /* 18 */ "force_numerical_fixed_volume", /* 19 */ - "equi_delay" /* 20 */ + "equi_delay", /* 20 */ + "minimum_total", /* 21 */ + "min_total" /* 22 */ }; - int count_opt_list = 21; + int count_opt_list = 23; /* * Read parameters: * ineq_tol; @@ -8444,6 +8451,12 @@ read_debug(void) case 20: /* equi_delay */ sscanf(next_char, "%d", &equi_delay); break; + case 21: /* minimum_total */ + case 22: /* min_total */ + sscanf(next_char, SCANFORMAT, &MIN_TOTAL); + MIN_TOTAL_SS = MIN_TOTAL/100; + MIN_RELATED_SURFACE = MIN_TOTAL*100; + break; } if (return_value == EOF || return_value == KEYWORD) break; diff --git a/tally.cpp b/tally.cpp index a7405e87..994c6af2 100644 --- a/tally.cpp +++ b/tally.cpp @@ -397,6 +397,7 @@ zero_tally_table(void) int i, j, k; for (i = 0; i < count_tally_table_columns; i++) { + tally_table[i].moles = 0.0; for (j = 0; j < count_tally_table_rows; j++) { for (k = 0; k < 3; k++) From 025d2a1ee13a11fb2788a82c80140e8ace0ea461 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 9 Feb 2017 17:17:10 +0000 Subject: [PATCH 1035/1077] Merged in Tony's changes for electro diffusion. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12388 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Form1.h | 3 +- Form1.resX | 25 +- PBasic.cpp | 23 +- PBasic.h | 3 +- Phreeqc.h | 6 +- basicsubs.cpp | 241 ++++++++------- class_main.cpp | 30 +- global_structures.h | 33 +- kinetics.cpp | 1 + pitzer.cpp | 9 +- prep.cpp | 7 +- print.cpp | 10 +- read.cpp | 42 +-- readtr.cpp | 4 +- structures.cpp | 2 +- transport.cpp | 728 ++++++++++++++++++++++++++------------------ 16 files changed, 659 insertions(+), 508 deletions(-) diff --git a/Form1.h b/Form1.h index 30edf3f4..0c9e5162 100644 --- a/Form1.h +++ b/Form1.h @@ -1134,7 +1134,8 @@ namespace zdg_ui2 { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); try { - this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); + //this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); + this->Icon = gcnew System::Drawing::Icon("c:\\phreeqc\\phreex.ico"); } catch (...) { diff --git a/Form1.resX b/Form1.resX index fc36b375..8cb449b9 100644 --- a/Form1.resX +++ b/Form1.resX @@ -3,6 +3,9 @@ text/microsoft-resx @@ -11,23 +14,23 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 - + - AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/ - mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz - k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g - AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - AAAAAAAAAAAAAAAAAAAAAAAA - + AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/ + mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz + k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g + AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA + \ No newline at end of file diff --git a/PBasic.cpp b/PBasic.cpp index c3845ca7..96fa49ae 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1645,6 +1645,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokpot_v: output_msg("POT_V"); break; + case tokt_sc: + output_msg("T_SC"); + break; } l_buf = l_buf->next; } @@ -3658,6 +3661,12 @@ factor(struct LOC_exec * LINK) n.UU.val = (parse_all) ? 1 : PhreeqcPtr->aqueous_vm(str); } break; + case tokphase_vm: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->phase_vm(str); + } + break; case tokviscos: { n.UU.val = (parse_all) ? 1 : PhreeqcPtr->viscos; @@ -3675,6 +3684,12 @@ factor(struct LOC_exec * LINK) case tokpot_v: n.UU.val = (parse_all) ? 1 : PhreeqcPtr->use.Get_solution_ptr()->Get_potV(); break; + case tokt_sc: + { + const char * str = stringfactor(STR1, LINK); + n.UU.val = (parse_all) ? 1 : PhreeqcPtr->calc_t_sc(str); + } + break; case toklog10: { @@ -3689,13 +3704,6 @@ factor(struct LOC_exec * LINK) //} } break; - case tokphase_vm: - { - const char * str = stringfactor(STR1, LINK); - n.UU.val = (parse_all) ? 1 : PhreeqcPtr->phase_vm(str); - } - break; - case toksin: n.UU.val = sin(realfactor(LINK)); break; @@ -7303,6 +7311,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("phase_vm", PBasic::tokphase_vm), std::map::value_type("current_a", PBasic::tokcurrent_a), std::map::value_type("pot_v", PBasic::tokpot_v), + std::map::value_type("t_sc", PBasic::tokt_sc), std::map::value_type("setdiff_c", PBasic::toksetdiff_c) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 7ea9079e..30195c05 100644 --- a/PBasic.h +++ b/PBasic.h @@ -310,6 +310,7 @@ public: tokerase, tokeps_r, tokvm, + tokphase_vm, tokdh_a, tokdh_b, tokdh_av, @@ -333,7 +334,7 @@ public: tokviscos_0, tokcurrent_a, tokpot_v, - tokphase_vm + tokt_sc }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.h b/Phreeqc.h index 850558f0..e1cd4238 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -112,6 +112,7 @@ public: LDBLE calc_logk_p(const char *name); LDBLE calc_logk_s(const char *name); LDBLE calc_surface_charge(const char *surface_name); + LDBLE calc_t_sc(const char *name); LDBLE diff_layer_total(const char *total_name, const char *surface_name); LDBLE edl_species(const char *surf_name, LDBLE * count, char ***names, LDBLE ** moles, LDBLE * area, LDBLE * thickness); int get_edl_species(cxxSurfaceCharge & charge_ref); @@ -1748,6 +1749,7 @@ protected: LDBLE sys_tot; LDBLE V_solutes, rho_0, rho_0_sat, kappa_0, p_sat/*, ah2o_x0*/; + LDBLE SC; // specific conductance mS/cm LDBLE eps_r; // relative dielectric permittivity LDBLE DH_A, DH_B, DH_Av; // Debye-Hueckel A, B and Av LDBLE QBrn; // Born function d(ln(eps_r))/dP / eps_r * 41.84004, for supcrt calc'n of molal volume @@ -1792,7 +1794,6 @@ protected: /* input.cpp ------------------------------- */ int check_line_return; int reading_db; - std::ostringstream definitions_for_parallelizer; /* integrate.cpp ------------------------------- */ LDBLE midpoint_sv; @@ -1991,7 +1992,6 @@ protected: friend class IPhreeqcMMS; friend class IPhreeqcPhast; friend class PhreeqcRM; - friend class Parallelizer; std::vector keycount; // used to mark keywords that have been read @@ -2021,7 +2021,7 @@ public: # if __GNUC__ && (__cplusplus >= 201103L) # define PHR_ISFINITE(x) std::isfinite(x) # else -# define PHR_ISFINITE(x) isfinite(x) +# define PHR_ISFINITE(x) isfinite(x) # endif #elif defined(HAVE_FINITE) # define PHR_ISFINITE(x) finite(x) diff --git a/basicsubs.cpp b/basicsubs.cpp index bb13b495..fd12a91e 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -218,10 +218,10 @@ LDBLE Phreeqc:: calc_SC(void) /* ---------------------------------------------------------------------- */ { - int i; - LDBLE lm, a, l_z, Dw, SC, ff; + //int i; + //LDBLE lm, a, l_z, Dw, SC, ff; - SC = 0; + //SC = 0; # ifdef SKIP for (i = 0; i < count_species_list; i++) { @@ -262,7 +262,7 @@ calc_SC(void) SC *= viscos_0_25 / viscos; return (SC); -# endif +//# endif for (i = 0; i < count_s_x; i++) { if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) @@ -294,144 +294,150 @@ calc_SC(void) SC *= viscos_0_25 / viscos; return (SC); - -#ifdef SKIP +# endif int i; - LDBLE lm, a, ka, l_z, Dw, SC, ff, sqrt_mu; - boolean DebOns_sc = false; + LDBLE ka, l_z, Dw, ff, sqrt_mu; sqrt_mu = sqrt(mu_x); SC = 0; - for (i = 0; i < count_species_list; i++) + LDBLE ta1, ta2, ta3, ta4; + for (i = 0; i < count_s_x; i++) { - if (species_list[i].s->dw_a || species_list[i].s->dw_a_exp) + // ** for optimizing, get numbers from -analyt for H+ = H+... + if (!strcmp(s_x[i]->name, "H+")) { - DebOns_sc = true; + ta1 = s_x[i]->logk[2]; + ta2 = s_x[i]->logk[3]; + ta3 = s_x[i]->logk[4]; + ta4 = s_x[i]->logk[5]; break; } - if (species_list[i].s->type > HPLUS) + // + } + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; - if (i > 0 - && strcmp(species_list[i].s->name, - species_list[i - 1].s->name) == 0) - continue; - if (species_list[i].s == s_h2o) - continue; - if ((Dw = species_list[i].s->dw) == 0) - continue; - if ((l_z = fabs(species_list[i].s->z)) == 0) - continue; - - lm = species_list[i].s->lm; - if (lm > -9) + if ((Dw = s_x[i]->dw) == 0) { - ka = DH_B * (species_list[i].s->dha ? species_list[i].s->dha : 4.0); - if (mu_x > 1) - ka *= pow(mu_x, 0.25 / mu_x); + if (correct_Dw) + Dw = default_Dw; else - ka *= pow(mu_x, 0.25); //sqrt_mu; - ff = pow((int) 10, -l_z * l_z * DH_A * sqrt_mu / (1 + ka)); - ff = pow(ff, 0.7 / sqrt(l_z)); - //ff = pow(ff, 0.6); - a = species_list[i].s->moles / mass_water_aq_x * ff; - if (species_list[i].s->dw_t) - Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier is done in SC - SC += a * l_z * l_z * Dw; + continue; } - } - if (!DebOns_sc) - { - SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); - SC *= viscos_0_25 / viscos_0; - return (SC); - } - -/*Debye-Onsager according to Robinson and Stokes, 1954, JACS 75, 1991, - but with sqrt charge multiplier for B2 and mu^ff dependent ka */ - LDBLE q, B1, B2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, z_plus, z_min, t1, t2, t2a, Dw_SC; - - m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = z_plus = z_min = 0; - SC = 0; - for (i = 0; i < count_species_list; i++) - { - if (species_list[i].s->type > HPLUS) - continue; - if (i > 0 - && strcmp(species_list[i].s->name, - species_list[i - 1].s->name) == 0) - continue; - if (species_list[i].s == s_h2o) - continue; - if ((Dw = species_list[i].s->dw) == 0) - continue; - if ((l_z = species_list[i].s->z) == 0) - continue; - if ((lm = species_list[i].s->lm) < -9) - continue; -// ** for optimizing... - if (!strcmp(species_list[i].s->name, "H+")) - t2a = species_list[i].s->Jones_Dole[2]; -// - if (species_list[i].s->dw_t) - Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity multiplier cancels in q... - if (l_z > 0) + if ((l_z = fabs(s_x[i]->z)) == 0) + l_z = 1; // only a 1st approximation for correct_Dw in electrical field + if (s_x[i]->dw_t) + Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); // the viscosity multiplier is done in SC + if (s_x[i]->dw_a2) + ka = DH_B * s_x[i]->dw_a2 * sqrt_mu / (1 + pow(mu_x, 0.75)); + else { - m_plus += species_list[i].s->moles; - t1 = species_list[i].s->moles * l_z; - eq_plus += t1; - eq_dw_plus += t1 * Dw; + ka = DH_B * 4.73 * sqrt_mu / (1 + pow(mu_x , 0.75)); + //ka = DH_B * ta1 * sqrt_mu / (1 + pow(mu_x, ta2)); + //ka = DH_B * ta1 * sqrt_mu / (1 + mu_x / ta2); + } + if (s_x[i]->dw_a) + { + ff = exp(-s_x[i]->dw_a * DH_A * l_z * sqrt_mu / (1 + ka)); + if (print_viscosity) + { + ff *= pow((viscos_0 / viscos), s_x[i]->dw_a_visc); + } } else { - m_min += species_list[i].s->moles; - t1 = species_list[i].s->moles * l_z; + ff = exp(-1.6 * DH_A * l_z * sqrt_mu / (1 + ka)); + //ff = exp(-ta3 * DH_A * l_z * sqrt_mu / (1 + ka)); + } + Dw *= ff; + s_x[i]->dw_corr = Dw; + + if (s_x[i]->z == 0) + continue; + s_x[i]->dw_t_SC = s_x[i]->moles / mass_water_aq_x * l_z * l_z * Dw; + SC += s_x[i]->dw_t_SC; + } + SC *= 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298150.0); + /* correct for temperature dependency... + SC_T = SC_298 * (Dw_T / T) * (298 / Dw_298) and + Dw_T = Dw_298 * (T / 298) * (viscos_298 / viscos_T) give: + SC_T = SC_298 * (viscos_298 / viscos_T) + */ + SC *= viscos_0_25 / viscos_0; + return (SC); +} +#ifdef SKIP +/*Debye-Onsager according to Robinson and Stokes, 1954, JACS 75, 1991, + but with sqrt charge multiplier for B2 and mu^ff dependent ka */ + LDBLE q, B1, B2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, Sum_m_dw, z_plus, z_min, t1, t2, Dw_SC; + + m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = Sum_m_dw = z_plus = z_min = 0; + SC = 0; + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) + continue; + if ((l_z = s_x[i]->z) == 0) + continue; + if ((lm = s_x[i]->lm) < -9) + continue; + if ((Dw = s_x[i]->dw) == 0) + Dw = 1e-9; + if (s_x[i]->dw_t) + Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); // the viscosity multiplier cancels in q... + if (l_z > 0) + { + m_plus += s_x[i]->moles; + t1 = s_x[i]->moles * l_z; + eq_plus += t1; + eq_dw_plus += t1 * Dw; + Sum_m_dw += s_x[i]->moles * Dw; + } + else + { + m_min += s_x[i]->moles; + t1 = s_x[i]->moles * l_z; eq_min -= t1; eq_dw_min -= t1 * Dw; + Sum_m_dw += s_x[i]->moles * Dw; } } - // Dw's weighted by eq... - eq_dw_plus /= eq_plus; eq_dw_min /= eq_min; - z_plus = eq_plus / m_plus; // |z1| - z_min = eq_min / m_min; // |z2| - q = z_plus * z_min / (z_plus + z_min) * (eq_dw_plus + eq_dw_min) / (z_min * eq_dw_plus + z_plus * eq_dw_min); - t1 = pow(1.60218e-19, 2) / (6 * pi); + // Falkenhagen, q = (Sum(z1 * m1*Dw1) + Sum(z2 *m2*Dw2)) / ((Sum(m1*Dw1) + Sum(m2*Dw2))(av_z1 + av_z2)) + z_plus = eq_plus / m_plus; // |av_z1| + z_min = eq_min / m_min; // |av_z2| + q = (eq_dw_plus + eq_dw_min) / (Sum_m_dw * (z_min + z_plus)); + t1 = 1.60218e-19 * 1.60218e-19 / (6 * pi); B1 = t1 / (2 * 8.8542e-12 * eps_r * 1.38066e-23 * tk_x) * q / (1 + sqrt(q)) * DH_B * 1e10 * z_plus * z_min; // DH_B is per Angstrom (*1e10) - t2 = 1e3 * calc_solution_volume(); - t2 = (1 - t2a) * viscos_0 + t2a * viscos; + t2 = viscos_0; // (1 - 0.5) * viscos_0 + 0.5 * viscos; B2 = t1 * AVOGADRO / t2 * DH_B * 1e17; // DH_B per Angstrom (*1e10), viscos in mPa.s (*1e3), B2 in cm2 (*1e4) Dw_SC = viscos_0_25 / t2 * 1e4 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298160.0); - for (i = 0; i < count_species_list; i++) + for (i = 0; i < count_s_x; i++) { - if (species_list[i].s->type > HPLUS) + if (s_x[i]->type != AQ && s_x[i]->type != HPLUS) continue; - if (i > 0 - && strcmp(species_list[i].s->name, - species_list[i - 1].s->name) == 0) + if ((l_z = fabs(s_x[i]->z)) == 0) continue; - if (species_list[i].s == s_h2o) - continue; - if ((Dw = species_list[i].s->dw) == 0) - continue; - if ((l_z = fabs(species_list[i].s->z)) == 0) - continue; - if ((lm = species_list[i].s->lm) < -9) + if ((lm = s_x[i]->lm) < -9) continue; + if ((Dw = s_x[i]->dw) == 0) + Dw = 1e-9; Dw *= Dw_SC; - if (species_list[i].s->dw_t) - Dw *= exp(species_list[i].s->dw_t / tk_x - species_list[i].s->dw_t / 298.15); // the viscosity factor is in Dw_SC - a = (species_list[i].s->dw_a ? species_list[i].s->dw_a : 3.5); + if (s_x[i]->dw_t) + Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); // the viscosity factor is in Dw_SC + a = (s_x[i]->dw_a ? s_x[i]->dw_a : 3.5); ka = DH_B * a; - if (species_list[i].s->dw_a_exp) - ka *= pow((double) mu_x, species_list[i].s->dw_a_exp); + if (s_x[i]->dw_a2) + ka *= pow((double) mu_x, s_x[i]->dw_a2); else ka *= sqrt_mu; // Falkenhagen... - /*SC += under(lm) * l_z * l_z * (Dw - B2 * l_z * sqrt_mu / (1 + ka)) * (1 - B1 * sqrt_mu / - ((1 + ka) * (1 + ka * sqrt(q) + ka * ka / 6)));*/ + //SC += under(lm) * l_z * l_z * (Dw - B2 * l_z * sqrt_mu / (1 + ka)) * (1 - B1 * sqrt_mu / + // ((1 + ka) * (1 + ka * sqrt(q) + ka * ka / 6))); t1 = (Dw - (B1 * Dw + B2) * sqrt_mu / (1 + ka)); //t1 = (Dw - (B1 * Dw + B2 * sqrt(l_z)) * sqrt_mu / (1 + ka)); @@ -441,7 +447,6 @@ calc_SC(void) } return (SC * 1e3); #endif -} /* VP: Density Start */ /* ---------------------------------------------------------------------- */ @@ -1054,6 +1059,28 @@ diff_layer_total(const char *total_name, const char *surface_name) } return (0); } +/* ---------------------------------------------------------------------- */ +LDBLE Phreeqc:: +calc_t_sc(const char *name) +/* ---------------------------------------------------------------------- */ +{ + char token[MAX_LENGTH]; + struct species *s_ptr; + + strcpy(token, name); + s_ptr = s_search(token); + if (s_ptr != NULL) + { + if (!s_ptr->z) + return (0); + calc_SC(); + if (!SC) + return (0); + LDBLE t = s_ptr->dw_t_SC * 1e7 * F_C_MOL * F_C_MOL / (R_KJ_DEG_MOL * 298150.0) * viscos_0_25 / viscos_0; + return (t / SC); + } + return (-999.99); +} /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: diff --git a/class_main.cpp b/class_main.cpp index 0685fecb..9956308e 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -277,7 +277,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.2.2a AmpŠre"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.3.9 AmpŠre"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -301,7 +301,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "November 25, 2015"); + len = sprintf(buffer, "%s", "November 23, 2016"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif @@ -331,7 +331,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -441,7 +441,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -491,10 +491,11 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.2.2a Ampère, compiled November 25, 2015\n")); + //output_msg(sformatf("Using PHREEQC: version 3.2.2a Ampère, compiled March 9, 2016\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); + output_msg(sformatf("Using PHREEQC: version 3.3.9 Ampère, compiled November 23, 2016\n")); output_msg(sformatf("Database file: %s\n\n", token)); #ifdef NPP output_flush(); @@ -532,7 +533,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, * Prepare error handling */ try { - if (phrq_io == NULL) + if (phrq_io == NULL) { std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n"; } @@ -641,7 +642,7 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, error_string = sformatf( "Error opening file, %s.", in_file); error_msg(error_string, STOP); } - + /* * Open data base */ @@ -746,6 +747,7 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, { std::cerr << "Failed defining name." << std::endl; } + l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -772,7 +774,7 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, #endif error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -801,7 +803,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { /* @@ -815,7 +817,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode #else phrq_io->Set_error_file(stderr); #endif - + screen_msg(sformatf("%s\n", query)); if (default_name[0] != '\0') { @@ -826,6 +828,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode { std::cerr << "Failed defining name." << std::endl; } + l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -848,7 +851,7 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } @@ -877,7 +880,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, #else FILE * error_file_save = phrq_io->Get_error_file(); #endif - + for (;;) { @@ -902,6 +905,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, { std::cerr << "Failed defining name." << std::endl; } + l = (int) strlen(name); name[l - 1] = '\0'; if (name[0] == '\0') @@ -924,7 +928,7 @@ open_output_file(char *query, char *default_name, std::ios_base::openmode mode, screen_msg(error_string); error_flush(); batch = FALSE; - continue; + continue; } break; } diff --git a/global_structures.h b/global_structures.h index d1480e3a..e98a0e7c 100644 --- a/global_structures.h +++ b/global_structures.h @@ -132,19 +132,19 @@ #define MAX_LM 3.0 /* maximum log molality allowed in intermediate iterations */ #define MAX_M 1000.0 #ifdef USE_DECIMAL128 -//#define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ -//#define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -//#define MIN_TOTAL 1e-60 -//#define MIN_TOTAL_SS MIN_TOTAL/100 -//#define MIN_RELATED_SURFACE MIN_TOTAL*100 -//#define MIN_RELATED_LOG_ACTIVITY -60 +// #define MIN_LM -80.0 /* minimum log molality allowed before molality set to zero */ +// #define LOG_ZERO_MOLALITY -80 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +// #define MIN_TOTAL 1e-60 +// #define MIN_TOTAL_SS MIN_TOTAL/100 +// #define MIN_RELATED_SURFACE MIN_TOTAL*100 +// #define MIN_RELATED_LOG_ACTIVITY -60 #else -//#define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ -//#define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ -//#define MIN_TOTAL 1e-25 -//#define MIN_TOTAL_SS MIN_TOTAL/100 -//#define MIN_RELATED_SURFACE MIN_TOTAL*100 -//#define MIN_RELATED_LOG_ACTIVITY -30 +// #define MIN_LM -30.0 /* minimum log molality allowed before molality set to zero */ +// #define LOG_ZERO_MOLALITY -30 /* molalities <= LOG_ZERO_MOLALITY are considered equal to zero */ +// #define MIN_TOTAL 1e-25 +// #define MIN_TOTAL_SS MIN_TOTAL/100 +// #define MIN_RELATED_SURFACE MIN_TOTAL*100 +// #define MIN_RELATED_LOG_ACTIVITY -30 #endif #define REF_PRES_PASCAL 1.01325E5 /* Reference pressure: 1 atm */ /* @@ -668,8 +668,11 @@ struct species LDBLE z; /* charge of species */ LDBLE dw; /* tracer diffusion coefficient in water at 25oC, m2/s */ LDBLE dw_t; /* correct Dw for temperature: Dw(TK) = Dw(298.15) * exp(dw_t / TK - dw_t / 298.15) */ - LDBLE dw_a; /* ion size parm for calc'ng SC = SC0 - (B1 * SC0 + B2) * kk * dw_a / (1 + kk * dw_a) */ - LDBLE dw_a_exp; /* power term for ionic strength correction of dw_a */ + LDBLE dw_a; /* parms for calc'ng SC = SC0 * exp(-dw_a * z * mu^0.5 / (1 + DH_B * dw_a2 * mu^0.5)) */ + LDBLE dw_a2; /* */ + LDBLE dw_a_visc; /* viscosity correction of SC */ + LDBLE dw_t_SC; /* contribution to SC, for calc'ng transport number with BASIC */ + LDBLE dw_corr; /* dw corrected for TK and mu */ LDBLE erm_ddl; /* enrichment factor in DDL */ LDBLE equiv; /* equivalents in exchange species */ LDBLE alk; /* alkalinity of species, used for cec in exchange */ @@ -1046,7 +1049,7 @@ struct sol_D struct J_ij { const char *name; - LDBLE tot1; /* species change in cells i and j */ + LDBLE tot1, tot2; /* species change in cells i and j */ }; struct M_S { diff --git a/kinetics.cpp b/kinetics.cpp index 03eaefc0..1439a33b 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -1646,6 +1646,7 @@ set_and_run(int i, int use_mix, int use_kinetics, int nsaver, converge = model(); } sum_species(); + viscosity(); return (converge); } diff --git a/pitzer.cpp b/pitzer.cpp index ae4edfb1..006f4d69 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -1281,14 +1281,14 @@ pitzer(void) F = F1 = F2 = -A0 * (DI / (1.0 + B * DI) + 2.0 * log(1.0 + B * DI) / B); if (patm_x > 1.0) { - LDBLE pap; + LDBLE pap = 0.0; pap = (7e-5 + 1.93e-9 * pow(TK - 250.0, 2.0)) * patm_x; B1 = B - (pap > 0.2 ? 0.2 : pap); - if (TK <= 263) - pap = 0; - else + if (TK > 263.0) + { pap = (9.65e-10 * pow(TK - 263.0, 2.773)) * pow(patm_x, 0.623); //pap = (-5.22e-4 + 7.19e-8 * pow(TK - 263.0, 2.0)) * pow(patm_x, 0.623); + } B2 = B - (pap > 0.2 ? 0.2 : pap); if (B1 != 0) F1 = -A0 * (DI / (1.0 + B1 * DI) + 2.0 * log(1.0 + B1 * DI) / B1); @@ -1709,7 +1709,6 @@ set_pz(int initial) tk_x = tc_x + 273.15; patm_x = solution_ptr->Get_patm(); // done in calc_rho_0(tc, pa) - potV_x = solution_ptr->Get_potV(); /* * H+, e-, H2O diff --git a/prep.cpp b/prep.cpp index db0e3b52..26ce61d8 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4096,10 +4096,11 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) } } if (P <= 0) // iterations = -1 - P = 1.; + P = 1; } else { - if (P < 1e-10) P = 1e-10; + if (P < 1e-10) + P = 1e-10; r3[1] = b_sum - R_TK / P; r3_12 = r3[1] * r3[1]; r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; @@ -5719,7 +5720,7 @@ k_temp(LDBLE tc, LDBLE pa) /* pa - pressure in atm */ for (i = 0; i < count_s_x; i++) { //if (s_x[i]->rxn_x->logk[vm_tc]) - /* calculate delta_v for the reaction, assume Vm = 0 if not defined for a species... */ + /* calculate delta_v for the reaction... */ s_x[i]->rxn_x->logk[delta_v] = calc_delta_v(s_x[i]->rxn_x, false); if (tc == current_tc && s_x[i]->rxn_x->logk[delta_v] == 0) continue; diff --git a/print.cpp b/print.cpp index 63738391..6aed9f45 100644 --- a/print.cpp +++ b/print.cpp @@ -2108,7 +2108,7 @@ print_totals(void) * Print total concentrations of elements, molality and moles. */ int i, pure_water; - LDBLE EC, dens; + LDBLE dens; if (pr.totals == FALSE || pr.all == FALSE) return (OK); @@ -2217,15 +2217,15 @@ print_totals(void) /* * Others */ - EC = calc_SC(); - if (EC > 0) + calc_SC(); + if (SC > 0) { //output_msg(sformatf("%36s%i%7s%i\n", output_msg(sformatf("%35s%3.0f%7s%i\n", #ifdef NO_UTF8_ENCODING - "Specific Conductance (uS/cm, ", tc_x, "oC) = ", (int) EC)); + "Specific Conductance (uS/cm, ", tc_x, "oC) = ", (int) SC)); #else - "Specific Conductance (µS/cm, ", tc_x, "°C) = ", (int) EC)); + "Specific Conductance (µS/cm, ", tc_x, "°C) = ", (int) SC)); #endif } /* VP: Density Start */ diff --git a/read.cpp b/read.cpp index 43bb516e..9dc241b9 100644 --- a/read.cpp +++ b/read.cpp @@ -429,7 +429,6 @@ read_exchange_species(void) association = TRUE; s_ptr = NULL; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read eqn from file and call parser */ @@ -867,7 +866,6 @@ read_exchange_species(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -1155,7 +1153,6 @@ read_exchange_master_species(void) struct element *elts_ptr; struct species *s_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH]; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; for (;;) { j = check_line("Exchange species equation", FALSE, TRUE, TRUE, TRUE); @@ -1163,7 +1160,6 @@ read_exchange_master_species(void) { break; } - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Get element name with valence, allocate space, store */ @@ -2889,7 +2885,7 @@ read_aq_species_vm_parms(char *ptr, LDBLE * delta_v) if (j < 1) { input_error++; - error_msg("Expecting numeric values for calculating the species molar volume from the supcrt database.", + error_msg("Expecting numeric values for calculating the species molar volume.", CONTINUE); return (ERROR); } @@ -3186,9 +3182,6 @@ read_viscosity_parms(char *ptr, LDBLE * Jones_Dole) CONTINUE); return (ERROR); } - // The B0 are for 25°C, subtract the temperature factor... - if (Jones_Dole[1] != 0) - Jones_Dole[0] -= Jones_Dole[1] * exp(Jones_Dole[2] * 25.0); return (OK); } @@ -3252,7 +3245,6 @@ read_master_species(void) struct species *s_ptr; char token[MAX_LENGTH], token1[MAX_LENGTH]; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; elts_ptr = NULL; for (;;) { @@ -3261,7 +3253,6 @@ read_master_species(void) { break; } - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Get element name with valence, allocate space, store */ @@ -3840,7 +3831,6 @@ read_phases(void) "vm" /* 15, molar volume, must replace delta_v */ }; int count_opt_list = 16; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = FALSE; /* * Read eqn from file and call parser @@ -4023,7 +4013,6 @@ read_phases(void) */ phase_ptr = NULL; ptr = line; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; copy_token(token, &ptr, &l); /* * Get and parse equation @@ -4112,7 +4101,6 @@ read_phases(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -4762,7 +4750,6 @@ read_selected_output(void) ptr = line; int n_user, n_user_end; char *description; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; read_number_description(ptr, &n_user, &n_user_end, &description); SelectedOutput temp_selected_output; @@ -4819,7 +4806,6 @@ read_selected_output(void) temp_selected_output.Set_new_def(true); } } - CParser parser(this->phrq_io); /* @@ -5136,7 +5122,6 @@ read_selected_output(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } if (temp_selected_output.Get_new_def() || so == SelectedOutput_map.end()) @@ -6028,11 +6013,10 @@ read_species(void) /* VP: Density Start */ "millero", /* 21 */ /* VP: Density End */ - "vm", /* 22, parms for molar volume, a1..a4 and w_ref from supcrt, I terms */ + "vm", /* 22, parms for molar volume, a1..a4 and w_ref, I terms */ "viscosity" /* 23, b and d parms for viscosity, (b1 + b2 * exp(-b3 * tc)) * c + (d1 * exp(-d2 * tc)) * c ^ d3 */ }; int count_opt_list = 24; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = TRUE; s_ptr = NULL; /* @@ -6338,9 +6322,10 @@ read_species(void) input_error++; break; } - s_ptr->dw_t = s_ptr->dw_a = s_ptr->dw_a_exp = 0; - i = sscanf(next_char, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &s_ptr->dw, &s_ptr->dw_t, - &s_ptr->dw_a, &s_ptr->dw_a_exp); + s_ptr->dw_t = 0; s_ptr->dw_a = 0; s_ptr->dw_a2 = 0; s_ptr->dw_a_visc = 0; + i = sscanf(next_char, SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT SCANFORMAT, &s_ptr->dw, &s_ptr->dw_t, + &s_ptr->dw_a, &s_ptr->dw_a2, &s_ptr->dw_a_visc); + s_ptr->dw_corr = s_ptr->dw; opt_save = OPTION_DEFAULT; break; case 20: /* enrichment factor in the DDL */ @@ -6527,7 +6512,6 @@ read_species(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -6794,7 +6778,6 @@ read_surface_species(void) "vm" /* 18 */ }; int count_opt_list = 19; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; association = TRUE; /* * Read eqn from file and call parser @@ -7173,7 +7156,6 @@ read_surface_species(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -7817,7 +7799,6 @@ read_surface_master_species(void) int count_opt_list = 0; opt_save = OPTION_DEFAULT; return_value = UNKNOWN; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; for (;;) { opt = get_option(opt_list, count_opt_list, &next_char); @@ -7908,7 +7889,6 @@ read_surface_master_species(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } @@ -9254,7 +9234,6 @@ read_rates(void) "end" /* 1 */ }; int count_opt_list = 2; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read advection number (not currently used) */ @@ -9364,7 +9343,6 @@ read_rates(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } /* output_msg(sformatf( "%s", rates[0].commands)); */ @@ -9398,7 +9376,6 @@ read_user_print(void) "end" /* 1 */ }; int count_opt_list = 2; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9460,7 +9437,6 @@ read_user_print(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } /* output_msg(sformatf( "%s", rates[0].commands)); */ return (return_value); @@ -9494,7 +9470,6 @@ read_user_punch(void) "headings" /* 3 */ }; int count_opt_list = 4; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9612,7 +9587,6 @@ read_user_punch(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } UserPunch_map.erase(n_user); UserPunch_map[n_user] = temp_user_punch; @@ -9775,7 +9749,6 @@ read_user_graph(void) }; int count_opt_list = 14; int i; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; opt_save = OPTION_DEFAULT; /* * Read lines @@ -9981,7 +9954,6 @@ read_user_graph(void) if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } #ifdef PHREEQ98 for (i = 0; i < user_graph_count_headings; i++) @@ -10937,7 +10909,6 @@ read_named_logk(void) }; int count_opt_list = 11; logk_ptr = NULL; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; /* * Read name followed by options */ @@ -11130,7 +11101,6 @@ read_named_logk(void) } if (return_value == EOF || return_value == KEYWORD) break; - if (reading_db == 0) definitions_for_parallelizer << line << "\n"; } return (return_value); } diff --git a/readtr.cpp b/readtr.cpp index c345e45e..9e815d58 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -822,9 +822,9 @@ read_transport(void) "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); else error_string = sformatf( - "No porosities were read; used the minimal value %8.2e from -multi_D.", multi_Dpor); + "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); warning_msg(error_string); - for (i = old_cells + 1; i < all_cells; i++) + for (i = 1; i < all_cells; i++) cell_data[i].por = multi_Dpor; } } diff --git a/structures.cpp b/structures.cpp index f78bc9cc..a3e837c0 100644 --- a/structures.cpp +++ b/structures.cpp @@ -2073,7 +2073,7 @@ s_init(struct species *s_ptr) s_ptr->dw = 0.0; s_ptr->dw_t = 0.0; s_ptr->dw_a = 0.0; - s_ptr->dw_a_exp = 0.0; + s_ptr->dw_a2 = 0.0; s_ptr->erm_ddl = 1.0; s_ptr->equiv = 0; s_ptr->alk = 0.0; diff --git a/transport.cpp b/transport.cpp index 87244fed..4db62597 100644 --- a/transport.cpp +++ b/transport.cpp @@ -85,12 +85,12 @@ transport(void) if (multi_Dflag) { - sol_D = (struct sol_D *) PHRQ_malloc((size_t)(all_cells)* sizeof(struct sol_D)); + sol_D = (struct sol_D *) PHRQ_malloc((size_t) (all_cells)* sizeof(struct sol_D)); if (sol_D == NULL) malloc_error(); sol_D_dbg = sol_D; - ct = (struct CT *) PHRQ_malloc((size_t)(all_cells)* sizeof(struct CT)); + ct = (struct CT *) PHRQ_malloc((size_t) (all_cells)* sizeof(struct CT)); if (ct == NULL) malloc_error(); { @@ -114,7 +114,7 @@ transport(void) } } - moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t)(count_elements)* sizeof(struct MOLES_ADDED)); + moles_added = (struct MOLES_ADDED *) PHRQ_malloc((size_t) (count_elements)* sizeof(struct MOLES_ADDED)); if (moles_added == NULL) malloc_error(); @@ -194,12 +194,19 @@ transport(void) } if (dV_dcell) { - if (/*stag_data->count_stag || */!multi_Dflag || ishift) + if (ishift) { input_error++; error_string = sformatf( - //"Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with -stagnant or with advective flow."); - "Electrical Field (potential) was defined, but needs -multi_D, \n\t and is not possible with advective flow."); + "Electro-diffusion cannot be combined with advective transport."); + error_msg(error_string, CONTINUE); + free_check_null(sol_D); + } + if (!multi_Dflag) + { + input_error++; + error_string = sformatf( + "Electrical Field (potential) was defined, but needs -multi_D."); error_msg(error_string, CONTINUE); free_check_null(sol_D); } @@ -219,7 +226,7 @@ transport(void) "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); warning_msg(error_string); } - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) (count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) malloc_error(); @@ -370,19 +377,18 @@ transport(void) f = exp(-stag_data->exch_f * stagkin_time / (b * stag_data->th_im)); mix_f_imm = b - b * f; mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; - n = 0; - for (i = 1; i <= count_cells; i++) + for (j = 1; j <= count_cells; j++) { - j = i; j_imm = j + (1 + count_cells); if (Utilities::Rxn_find(Rxn_solution_map, j) == NULL) error_msg ("Could not find mobile cell solution in TRANSPORT.", STOP); if (Utilities::Rxn_find(Rxn_solution_map, j_imm) == NULL) - error_msg - ("Could not find immobile cell solution in TRANSPORT.", - STOP); + //error_msg + //("Could not find immobile cell solution in TRANSPORT.", + //STOP); + continue; water_m = Utilities::Rxn_find(Rxn_solution_map, j)->Get_mass_water(); water_imm = Utilities::Rxn_find(Rxn_solution_map, j_imm)->Get_mass_water(); /* @@ -395,7 +401,6 @@ transport(void) temp_mix.Add(j, 1 - mix_f_m); temp_mix.Add(j_imm, mix_f_m * water_m / water_imm); Rxn_mix_map[j] = temp_mix; - n++; } /* * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... @@ -407,7 +412,6 @@ transport(void) temp_mix.Add(j_imm, 1 - mix_f_imm); temp_mix.Add(j, mix_f_imm * water_imm / water_m); Rxn_mix_map[j_imm] = temp_mix; - n++; } } @@ -539,7 +543,8 @@ transport(void) /* punch and output file */ if ((ishift == 0) && (j == nmix) && ((stag_data->count_stag == 0) || i == 0 - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) + || (i == count_cells + 1 && stag_data->count_stag != 1) /* + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0*/)) { if ((cell_data[i].punch == TRUE) && (transport_step % punch_modulus == 0)) @@ -590,16 +595,17 @@ transport(void) else punch_boolean = FALSE; for (i = 1; i <= count_cells; i++) - mix_stag(i, stagkin_time, punch_boolean, step_fraction); - if (punch_boolean - && ((cell_data[i].punch == TRUE && transport_step % punch_modulus == 0) - || (cell_data[i].print == TRUE && transport_step % print_modulus == 0))) { - cell_no = i; + mix_stag(i, stagkin_time, punch_boolean, step_fraction); + } + // i == 1 + count_cells... + if (stag_data->count_stag == 1 && punch_boolean) + { run_reactions(i, 0, NOMIX, 0); - if (cell_data[i].punch == TRUE) + cell_no = i; + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) punch_all(); - if (cell_data[i].print == TRUE) + if (cell_data[i].print && (transport_step % print_modulus == 0)) print_all(); } } @@ -717,14 +723,11 @@ transport(void) fill_spec(i); if (iterations > max_iter) max_iter = iterations; - if ((nmix == 0) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + if ((nmix == 0) && ((stag_data->count_stag == 0))) { - if ((cell_data[i].punch == TRUE) - && (transport_step % punch_modulus == 0)) + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i].print == TRUE) - && (transport_step % print_modulus == 0)) + if (cell_data[i].print && (transport_step % print_modulus == 0)) print_all(); } if (i == first_c && count_cells > 1) @@ -833,14 +836,12 @@ transport(void) run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); - if ((j == nmix) && (stag_data->count_stag == 0 || i == 0 - || (i != 1 + count_cells && Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + if (j == nmix && (stag_data->count_stag == 0 || i == 0 + || (i == 1 + count_cells && stag_data->count_stag != 1))) { - if ((cell_data[i].punch == TRUE) - && (transport_step % punch_modulus == 0)) + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i].print == TRUE) - && (transport_step % print_modulus == 0)) + if (cell_data[i].print && (transport_step % print_modulus == 0)) print_all(); } if (i > 1) @@ -883,19 +884,20 @@ transport(void) else punch_boolean = FALSE; for (i = 1; i <= count_cells; i++) - mix_stag(i, stagkin_time, punch_boolean, step_fraction); - if (punch_boolean - && ((cell_data[i].punch == TRUE && transport_step % punch_modulus == 0) - || (cell_data[i].print == TRUE && transport_step % print_modulus == 0))) { - cell_no = i; - run_reactions(i, 0, NOMIX, 0); - if (cell_data[i].punch == TRUE) - punch_all(); - if (cell_data[i].print == TRUE) - print_all(); + mix_stag(i, stagkin_time, punch_boolean, step_fraction); } } + // i == 1 + count_cells... + if (stag_data->count_stag == 1 && punch_boolean) + { + run_reactions(i, 0, NOMIX, 0); + cell_no = i; + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + punch_all(); + if (cell_data[i].print && (transport_step % print_modulus == 0)) + print_all(); + } } if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) dump(); @@ -999,18 +1001,21 @@ init_mix(void) for (i = 1; i <= count_cells; i++) { // estimate the number of mixes - lav = (cell_data[i + 1].length + cell_data[i].length) / 2; - mD = diffc_max * timest / (lav * lav); - if (mD > maxmix) - maxmix = mD; + if (i < count_cells) + { + lav = (cell_data[i + 1].length + cell_data[i].length) / 2; + mD = diffc_max * timest / (lav * lav); + if (mD > maxmix) + maxmix = mD; + } if (ishift != 0) { - /* define dispersive mixing (diffusion is done in multi_D), - with harmonic mean of cell properties (manual eqn 49): - M1 = -a1 * (v1 * timest / 2) * A1 * (c12 - c1) / (h1 / 2) - a1 is dispersivity in cell 1, A1 = V1 / h1, v1 * timest / 2 = h1 / 2. - All cells have equal V in advective transport, delta(c) = M1 / V1. - */ + /* define dispersive mixing (diffusion is done in multi_D), + with harmonic mean of cell properties (manual eqn 49): + M1 = -a1 * (v1 * timest / 2) * A1 * (c12 - c1) / (h1 / 2) + a1 is dispersivity in cell 1, A1 = V1 / h1, v1 * timest / 2 = h1 / 2. + All cells have equal V in advective transport, delta(c) = M1 / V1. + */ if (i < count_cells) { if (cell_data[i].disp) @@ -1070,14 +1075,14 @@ init_mix(void) { l_nmix = 0; if (mcd_substeps > 1 && stag_data->count_stag > 0) - l_nmix = (int)ceil(mcd_substeps); + l_nmix = (int) ceil(mcd_substeps); } else { if (bcon_first == 1 || bcon_last == 1) - l_nmix = 1 + (int)floor(2.25 * maxmix); + l_nmix = 1 + (int) floor(2.25 * maxmix); else - l_nmix = 1 + (int)floor(1.5 * maxmix); + l_nmix = 1 + (int) floor(1.5 * maxmix); if (ishift != 0 && (bcon_first == 1 || bcon_last == 1)) { @@ -1085,7 +1090,7 @@ init_mix(void) l_nmix = 2; } if (mcd_substeps > 1) - l_nmix = (int)ceil(l_nmix * mcd_substeps); + l_nmix = (int) ceil(l_nmix * mcd_substeps); for (i = 1; i <= count_cells; i++) { @@ -1106,7 +1111,7 @@ init_mix(void) } m = (LDBLE *)free_check_null(m); m1 = (LDBLE *)free_check_null(m1); - return (l_nmix); + return l_nmix; } else // multi_D false { @@ -1187,7 +1192,7 @@ init_mix(void) l_nmix = 0; else { - l_nmix = 1 + (int)floor(1.5 * maxmix); + l_nmix = 1 + (int) floor(1.5 * maxmix); if ((ishift != 0) && ((bcon_first == 1) || (bcon_last == 1))) { @@ -1281,7 +1286,6 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) use.Set_n_kinetics_user(i); use.Set_kinetics_in(true); } - if (l_punch && (cell_data[i].print == TRUE) && (transport_step % print_modulus == 0)) print_all(); @@ -1338,6 +1342,16 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) change_surf_count = 0; } } + else if (n == 1 && l_punch && (cell_data[i].punch || cell_data[i].print)) + { + cell_no = i; + run_reactions(i, 0, NOMIX, 0); + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + punch_all(); + if (cell_data[i].print && (transport_step % print_modulus == 0)) + print_all(); + } + } for (n = 1; n <= stag_data->count_stag; n++) { @@ -1474,7 +1488,7 @@ init_heat_mix(int l_nmix) l_heat_nmix = 0; else { - l_heat_nmix = 1 + (int)floor(3.0 * maxmix); + l_heat_nmix = 1 + (int) floor(3.0 * maxmix); for (i = 1; i <= count_cells + 1; i++) heat_mix_array[i] /= l_heat_nmix; } @@ -1561,7 +1575,7 @@ set_initial_moles(int i) kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, i); if (kinetics_ptr != NULL) { - for (j = 0; j < (int)kinetics_ptr->Get_kinetics_comps().size(); j++) + for (j = 0; j < (int) kinetics_ptr->Get_kinetics_comps().size(); j++) { cxxKineticsComp *kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); kinetics_comp_ptr->Set_initial_moles(kinetics_comp_ptr->Get_m()); @@ -1575,10 +1589,10 @@ set_initial_moles(int i) if (ss_assemblage_ptr != NULL) { std::vector ss_ptrs = ss_assemblage_ptr->Vectorize(); - for (k = 0; k < (int)ss_ptrs.size(); k++) + for (k = 0; k < (int) ss_ptrs.size(); k++) { cxxSS * ss_ptr = ss_ptrs[k]; - for (j = 0; j < (int)ss_ptr->Get_ss_comps().size(); j++) + for (j = 0; j < (int) ss_ptr->Get_ss_comps().size(); j++) { cxxSScomp *comp_ptr = &(ss_ptr->Get_ss_comps()[j]); comp_ptr->Set_init_moles(comp_ptr->Get_moles()); @@ -1639,7 +1653,7 @@ fill_spec(int l_cell_no) struct master *master_ptr; LDBLE dum, dum2; LDBLE lm; - LDBLE por, por_il, viscos_f, viscos_il_f, viscos, l_z, l_g, ff; + LDBLE por, por_il, viscos_f, viscos_il_f, viscos; bool x_max_done = false; s_ptr2 = NULL; @@ -1647,7 +1661,7 @@ fill_spec(int l_cell_no) sol_D[l_cell_no].spec = (struct spec *) free_check_null(sol_D[l_cell_no].spec); sol_D[l_cell_no].spec = - (struct spec *) PHRQ_malloc((size_t)count_species_list * + (struct spec *) PHRQ_malloc((size_t) count_species_list * sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); @@ -1709,7 +1723,7 @@ fill_spec(int l_cell_no) * sort species by name... */ if (count_species_list > 0) - qsort(&species_list[0], (size_t)count_species_list, + qsort(&species_list[0], (size_t) count_species_list, (size_t) sizeof(struct species_list), sort_species_name); for (i = 0; i < count_species_list; i++) @@ -1830,17 +1844,8 @@ fill_spec(int l_cell_no) } if (correct_Dw) { - if ((l_z = fabs(s_ptr->z)) == 0) - { // first approximation for neutral species (HTO), but is viscosity dependent - l_z = 1; - l_g = -DH_A * (sqrt(mu_x) / (1 + sqrt(mu_x))); - } - else - l_g = s_ptr->lg; - ff = (mu_x < .36 * l_z ? 0.6 / sqrt(l_z) : sqrt(mu_x) / l_z); - ff *= l_g; - if (ff > 0) ff = 0; // is viscosity dependent (ff > 0 in KCl) - sol_D[l_cell_no].spec[count_spec].Dwt *= under(ff); + calc_SC(); // note that neutral species are corrected as if z = 1, but is viscosity-dependent + sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw_corr * viscos_f; } if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); @@ -1851,7 +1856,7 @@ fill_spec(int l_cell_no) } sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, - (size_t)count_spec * + (size_t) count_spec * sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) @@ -1920,13 +1925,19 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) int first_c, last_c, last_c2 = 0; char token[MAX_LENGTH]; LDBLE mixf, temp; + LDBLE dVtemp = 0.0; + if (dV_dcell && stagnant) + { + dVtemp = dV_dcell; + dV_dcell = 0; + } icell = jcell = -1; first_c = last_c = -1; il_calcs = -1; current_x = sum_R = sum_Rd = 0.0; - if (dV_dcell && !stagnant) + if (dV_dcell) find_current = loop_f_c = 1; // calculate J_ij once for all cells, loop to dV_dcell2. else find_current = loop_f_c = 0; @@ -1945,9 +1956,15 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) */ use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, icell)); if (use.Get_mix_ptr() == NULL) + { + if (first_c < 0) + first_c = icell; + if (last_c2 < icell) + last_c2 = icell; continue; + } first_c = 0; - last_c = (int)(use.Get_mix_ptr()->Get_mixComps().size() - 1); + last_c = (int) (use.Get_mix_ptr()->Get_mixComps().size() - 1); } else { /* regular column... */ @@ -1959,6 +1976,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) last_c = count_cells; else last_c = count_cells - 1; + last_c2 = (dV_dcell ? count_cells + 1: count_cells); } for (i = first_c; i <= last_c; i++) @@ -1968,13 +1986,11 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) std::vector n_solution; std::vector fraction; (use.Get_mix_ptr())->Vectorize(n_solution, fraction); - if ((jcell = n_solution[i]) <= icell) continue; - mixf = fraction[i]; - if (mcd_substeps > 1) - mixf /= nmix; + last_c2 = jcell; + mixf = fraction[i] / nmix; } else { /* regular column... */ @@ -1989,8 +2005,6 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) /* * 1. obtain J_ij... */ - if (jcell > last_c2) - last_c2 = jcell; il_calcs = find_J(icell, jcell, mixf, DDt, stagnant); if (find_current) { @@ -2004,8 +2018,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) current_x = j_0e + current_cells[0].dif; if (fix_current) { - //int sign = (signbit(current_x) == 0 ? 1 : -1); - int sign = (current_x >= 0) ? 1 : -1; + int sign = (current_x >= 0 ? 1 : -1); current_x = sign * fix_current / F_C_MOL; j_0e = current_x - current_cells[0].dif; } @@ -2035,7 +2048,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) m_s = (struct M_S *) free_check_null(m_s); count_m_s = (ct[icell].J_ij_count_spec < count_elements ? ct[icell].J_ij_count_spec : count_elements); - m_s = (struct M_S *) PHRQ_malloc((size_t)count_m_s * + m_s = (struct M_S *) PHRQ_malloc((size_t) count_m_s * sizeof(struct M_S)); if (m_s == NULL) malloc_error(); @@ -2057,19 +2070,19 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); - if (dV_dcell && (i > 0 || fix_current) && !stagnant) + if (dV_dcell && (i > 0 || fix_current)) { use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); } for (l = 0; l < count_m_s; l++) { - length = (int)strlen(m_s[l].name); + length = (int) strlen(m_s[l].name); cxxNameDouble::iterator it; for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) { length2 = - (int)(size_t)strcspn(it->first.c_str(), "("); + (int) (size_t) strcspn(it->first.c_str(), "("); if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { it->second -= m_s[l].tot1; @@ -2086,30 +2099,30 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) { use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, jcell)); dummy = use.Get_solution_ptr()->Get_total_h(); - use.Get_solution_ptr()->Set_total_h(dummy + tot1_h); + use.Get_solution_ptr()->Set_total_h(dummy + tot2_h); dummy = use.Get_solution_ptr()->Get_total_o(); - use.Get_solution_ptr()->Set_total_o(dummy + tot1_o); + use.Get_solution_ptr()->Set_total_o(dummy + tot2_o); if (i == count_cells && fix_current && !stagnant) { use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); } for (l = 0; l < count_m_s; l++) { - length = (int)strlen(m_s[l].name); + length = (int) strlen(m_s[l].name); cxxNameDouble::iterator it; for (it = use.Get_solution_ptr()->Get_totals().begin(); it != use.Get_solution_ptr()->Get_totals().end(); it++) { - length2 = (int)(size_t)strcspn(it->first.c_str(), "("); + length2 = (int) (size_t) strcspn(it->first.c_str(), "("); if (strncmp(m_s[l].name, it->first.c_str(), length) == 0 && length == length2) { - it->second += m_s[l].tot1; + it->second += m_s[l].tot2; break; } } if (it == use.Get_solution_ptr()->Get_totals().end()) { - use.Get_solution_ptr()->Get_totals()[m_s[l].name] = m_s[l].tot1; + use.Get_solution_ptr()->Get_totals()[m_s[l].name] = m_s[l].tot2; } } } @@ -2117,8 +2130,13 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } // check for negative conc's... + if (stagnant) + first_c = mobile_cell; for (i = first_c; i <= last_c2; i++) { + if (stagnant && i > first_c && i <= count_cells + first_c) + continue; + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (!use.Get_solution_ptr()) continue; @@ -2162,12 +2180,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) temp = moles; it->second = 0; /* see if other redox states have more moles... */ - length = (int)strlen(it->first.c_str()); + length = (int) strlen(it->first.c_str()); cxxNameDouble::iterator kit; for (kit = use.Get_solution_ptr()->Get_totals().begin(); kit != use.Get_solution_ptr()->Get_totals().end(); kit++) { - length2 = (int)(size_t)strcspn(kit->first.c_str(), "("); + length2 = (int) (size_t) strcspn(kit->first.c_str(), "("); if (!strncmp(it->first.c_str(), kit->first.c_str(), length2)) { temp += kit->second; @@ -2211,11 +2229,18 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) for (i = first_c; i < last_c2; i++) { + if (stagnant && i > first_c && i <= count_cells + first_c) + continue; ct[i].J_ij = (struct J_ij *) free_check_null(ct[i].J_ij); if (il_calcs) ct[i].J_ij_il = (struct J_ij *) free_check_null(ct[i].J_ij_il); ct[i].v_m = (struct V_M *) free_check_null(ct[i].v_m); } + if (dVtemp && stagnant) + { + dV_dcell = dVtemp; + } + return (OK); } @@ -2232,8 +2257,6 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) for (j = 0; j < l_J_ij_count_spec; j++) { - if (!l_J_ij[j].tot1) - continue; { char * temp_name = string_duplicate(l_J_ij[j].name); ptr = temp_name; @@ -2248,10 +2271,12 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) if (strcmp(elt_list[k].elt->name, "H") == 0) { tot1_h += elt_list[k].coef * l_J_ij[j].tot1; + tot2_h += elt_list[k].coef * l_J_ij[j].tot2; } else if (strcmp(elt_list[k].elt->name, "O") == 0) { tot1_o += elt_list[k].coef * l_J_ij[j].tot1; + tot2_o += elt_list[k].coef * l_J_ij[j].tot2; } else { @@ -2260,13 +2285,16 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec) if (strcmp(m_s[l].name, elt_list[k].elt->name) == 0) { m_s[l].tot1 += elt_list[k].coef * l_J_ij[j].tot1; + m_s[l].tot2 += elt_list[k].coef * l_J_ij[j].tot2; break; } } if (l == count_m_s) { + //m_s[l].name = string_hsave(elt_list[k].elt->name); m_s[l].name = elt_list[k].elt->name; m_s[l].tot1 = elt_list[k].coef * l_J_ij[j].tot1; + m_s[l].tot2 = elt_list[k].coef * l_J_ij[j].tot2; count_m_s++; } } @@ -2293,11 +2321,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ** dec. 28, 2015** included aq_dl in the harmonic mean: J_ij = - b_i * b_j / (b_i + b_j) * (c_j - c_i) in mol/s (see ex 21 in the manual 3). - b_i = A_i / (G_i * h_i / 2) * Dw for a pore without EDL. A_i = aq_i / h_i (m^2). - with EDL (no aq_il_i in A_i, for now): - aqt_i = aq_i + aq_dl_i. A_i = aqt_i / h_i. f_free_i = aq_i / aqt_i. - b_i_cat = A_i / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) * Bm}. Bm = Boltzmann enrichment in EDL = g_dl. - b_i_ani = A_i / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) / Bm)}. + b_i = A1 / (G_i * h_i / 2) * Dw for a pore without EDL. A1 = aq1 / h_i (m^2). + with EDL (no aq_il_i in A1, for now): + t_aq1 = aq1 + aq_dl_i. A1 = t_aq1 / h_i. f_free_i = aq1 / t_aq1. + b_i_cat = A1 / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) * Bm}. Bm = Boltzmann enrichment in EDL = g_dl. + b_i_ani = A1 / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) / Bm)}. * stagnant TRUE: * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por @@ -2307,22 +2335,19 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) surface area A for IL: stagnant: ct[icell].mixf_il is mixf * por_il / por. por_il = interlayer porosity, from -interlayer_D true 'por_il'. - por = total porosity, from -multi_D true 'multi_Dpor'. - **nov. 12, 2011**: - mixf is corrected, * (1 - por_il / por). - new_pf = (por - por_il)^(-multi_Dn). + por = free + DL porewater porosity, from -multi_D true 'multi_Dpor'. in regular column, A is calc'd from (free + DL porewater) and cell-length. - for IL: A * por_il / (por - por_il). + for IL: A * por_il / por. - por_il is entered as a single value. It is limited to 0.999 * por. - por_il in a cell is reduced by conc of X- / (max conc of X- of all cells) - - IL-water = (free + DL porewater) * por_il / (por - por_il). + por_il should be entered for the cell with the maximal cec. + IL water is related to X-, thus the cec (eq/L IL water) is the same for all cells if X is difined. + IL-water = (free + DL porewater) * por_il / por. + for IL: A * aq_il / t_aq. */ int i, i_max, j, j_max, k, k_il, only_counter, il_calcs; int i1; - LDBLE A_i, A_j, ddlm, aq_i, aq_j, aqt_i, aqt_j, f_free_i, f_free_j; - LDBLE dl_aq_i, dl_aq_j, c_dl, dum, dum1, dum2, tort_i, tort_j, b_i, b_j; + LDBLE A1, A2, ddlm, aq1, aq2, t_aq1, t_aq2, f_free_i, f_free_j; + LDBLE dl_aq1, dl_aq2, c_dl, dum, dum1, dum2, tort1, tort2, b_i, b_j; LDBLE Sum_zM, aq_il1, aq_il2; LDBLE por_il1, por_il2, por_il12; LDBLE cec1, cec2, cec12, rc1, rc2; @@ -2330,37 +2355,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cxxSurface *s_ptr1, *s_ptr2; cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; LDBLE g, g_i, g_j; + LDBLE dV_temp = 0; char token[MAX_LENGTH], token1[MAX_LENGTH]; - dl_aq_i = dl_aq_j = 0.0; - por_il12 = A_i = A_j = 0.0; - cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; - dV = 0.0; + il_calcs = (interlayer_Dflag ? 1 : 0); + ct[icell].dl_s = dl_aq1 = dl_aq2 = 0.0; - /* check for immediate return and interlayer diffusion calcs... */ - if (interlayer_Dflag) - { - il_calcs = 1; - if (icell == 0 && cell_data[1].por_il < interlayer_Dpor_lim) - il_calcs = 0; - else if (icell == count_cells && - cell_data[count_cells].por_il < interlayer_Dpor_lim) - il_calcs = 0; - else if (icell > 0 - && (cell_data[icell].por_il < interlayer_Dpor_lim - || cell_data[jcell].por_il < interlayer_Dpor_lim)) - il_calcs = 0; - } - else - il_calcs = 0; - - if (dV_dcell && !find_current && !stagnant) + if (dV_dcell && !find_current) goto dV_dcell2; - ct[icell].J_ij_count_spec = 0; - ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); - ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); - //ct[icell].v_m = ct[icell].v_m_il = NULL; + /* check for immediate return and interlayer diffusion calcs... */ if (!il_calcs) { if (stagnant) @@ -2372,9 +2376,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else { /* regular column... */ if ((icell == 0 && cell_data[1].por < multi_Dpor_lim) - ||(icell == count_cells && cell_data[count_cells].por < multi_Dpor_lim) - || (icell !=0 && icell != count_cells && (cell_data[icell].por < multi_Dpor_lim - || cell_data[jcell].por < multi_Dpor_lim))) + || (icell == count_cells && cell_data[count_cells].por < multi_Dpor_lim) + || (icell != 0 && icell != count_cells && (cell_data[icell].por < multi_Dpor_lim + || cell_data[jcell].por < multi_Dpor_lim))) { if (dV_dcell) { @@ -2390,14 +2394,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } /* do the calcs */ - aq_i = Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mass_water(); - aq_j = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mass_water(); + aq1 = Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mass_water(); + aq2 = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mass_water(); /* * check if DL calculations must be made, find amounts of water... */ s_charge_ptr1 = s_charge_ptr2 = NULL; s_ptr1 = s_ptr2 = NULL; - ct[icell].dl_s = dl_aq_i = dl_aq_j = 0.0; ct[icell].visc1 = ct[icell].visc2 = 1.0; only_counter = FALSE; @@ -2409,16 +2412,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (s_ptr1->Get_only_counter_ions()) only_counter = TRUE; /* find the one (and only one...) immobile surface comp with DL... */ - for (i = 0; i < (int)s_ptr1->Get_surface_comps().size(); i++) + for (i = 0; i < (int) s_ptr1->Get_surface_comps().size(); i++) { cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); if (comp_i_ptr->Get_Dw() == 0) { s_charge_ptr1 = s_ptr1->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq_i = s_charge_ptr1->Get_mass_water(); + dl_aq1 = s_charge_ptr1->Get_mass_water(); ct[icell].visc1 = s_ptr1->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int)s_ptr1->Get_surface_comps().size(); j++) + for (j = i + 1; j < (int) s_ptr1->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr1->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 @@ -2427,7 +2430,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (!warn_fixed_Surf) { - k = (int)strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, @@ -2451,16 +2454,16 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (s_ptr2->Get_only_counter_ions()) only_counter = TRUE; - for (i = 0; i < (int)s_ptr2->Get_surface_comps().size(); i++) + for (i = 0; i < (int) s_ptr2->Get_surface_comps().size(); i++) { cxxSurfaceComp * comp_i_ptr = &(s_ptr2->Get_surface_comps()[i]); if (comp_i_ptr->Get_Dw() == 0) { s_charge_ptr2 = s_ptr2->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq_j = s_charge_ptr2->Get_mass_water(); + dl_aq2 = s_charge_ptr2->Get_mass_water(); ct[icell].visc2 = s_ptr2->Get_DDL_viscosity(); /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int)s_ptr2->Get_surface_comps().size(); j++) + for (j = i + 1; j < (int) s_ptr2->Get_surface_comps().size(); j++) { cxxSurfaceComp * comp_j_ptr = &(s_ptr2->Get_surface_comps()[j]); if (comp_j_ptr->Get_Dw() == 0 @@ -2469,7 +2472,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (!warn_fixed_Surf) { - k = (int)strcspn(comp_i_ptr->Get_formula().c_str(), "_"); + k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); token1[k] = '\0'; sprintf(token, @@ -2496,99 +2499,82 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* in each cell: DL surface = mass_water_DL / (cell_length) free pore surface = mass_water_free / (cell_length) determine DL surface as a fraction of the total pore surface... */ - if (dl_aq_i > 0) - ct[icell].dl_s = dl_aq_i / (dl_aq_i + aq_i); - if (dl_aq_j > 0) + t_aq1 = aq1 + dl_aq1; + t_aq2 = aq2 + dl_aq2; + f_free_i = aq1 / t_aq1; + f_free_j = aq2 / t_aq2; + if (dl_aq1 > 0) + ct[icell].dl_s = dl_aq1 / t_aq1; + if (dl_aq2 > 0) { - dum = dl_aq_j / (dl_aq_j + aq_j); - if (dl_aq_i > 0) - /* average the 2... */ + dum = dl_aq2 / t_aq2; + if (dl_aq1 > 0) + /* average for stagnant calcs... */ ct[icell].dl_s = (ct[icell].dl_s + dum) / 2; else /* there is one DL surface... */ ct[icell].dl_s = dum; } - aqt_i = aq_i + dl_aq_i; - aqt_j = aq_j + dl_aq_j; - f_free_i = aq_i / aqt_i; - f_free_j = aq_j / aqt_j; if (il_calcs) { /* find interlayer porosity por_il, make it relative to exchange capacity (mol X/L), highest X in sol_D[1].x_max (mol X / L). - Find amounts of IL water and cec. - Must do this separately, since por and por_il are in cell_data structure. */ + Find amounts of IL water and cec. */ por_il1 = por_il2 = por_il12 = 0.0; cec1 = cec2 = cec12 = rc1 = rc2 = 0.0; if (icell == 0) { - por_il1 = sol_D[0].exch_total / aq_i / sol_D[1].x_max * + por_il1 = sol_D[0].exch_total / aq1 / sol_D[1].x_max * cell_data[1].por_il; - por_il2 = sol_D[1].exch_total / aq_j / sol_D[1].x_max * + por_il2 = sol_D[1].exch_total / aq2 / sol_D[1].x_max * cell_data[1].por_il; if (sol_D[0].exch_total > 3e-10 && sol_D[1].exch_total > 3e-10) - /* take the average... */ - por_il12 = (por_il1 + por_il2) / 2; + /* take the harmonic mean... */ + por_il12 = 2 * por_il1 * por_il2 / (por_il1 + por_il2); else /* at column ends, take the clay... */ por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[1].por) - por_il12 = 0.999 * cell_data[1].por; - if (por_il2 > 0.999 * cell_data[1].por) - por_il2 = 0.999 * cell_data[1].por; - aq_il2 = (aq_j + dl_aq_j) * por_il2 / - (cell_data[1].por - por_il2); - /* Assume interlayer water is proportional with CEC... */ - aq_il1 = aq_il2 * sol_D[0].exch_total / sol_D[1].exch_total; + aq_il2 = t_aq2 * por_il12 / cell_data[1].por; + aq_il1 = t_aq2 * por_il12 / cell_data[1].por; } else if (icell == count_cells) { - por_il1 = sol_D[count_cells].exch_total / aq_i / sol_D[1].x_max * + por_il1 = sol_D[count_cells].exch_total / aq1 / sol_D[1].x_max * cell_data[count_cells].por_il; - por_il2 = sol_D[count_cells + 1].exch_total / aq_j / sol_D[1].x_max * + por_il2 = sol_D[count_cells + 1].exch_total / aq2 / sol_D[1].x_max * cell_data[count_cells].por_il; if (sol_D[count_cells].exch_total > 3e-10 && sol_D[count_cells + 1].exch_total > 3e-10) - por_il12 = (por_il1 + por_il2) / 2; + por_il12 = 2 * por_il1 * por_il2 / (por_il1 + por_il2); else por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[count_cells].por) - por_il12 = 0.999 * cell_data[count_cells].por; - if (por_il1 > 0.999 * cell_data[count_cells].por) - por_il1 = 0.999 * cell_data[count_cells].por; - aq_il1 = (aq_i + dl_aq_i) * por_il1 / - (cell_data[count_cells].por - por_il1); - aq_il2 = aq_il1 * sol_D[count_cells + 1].exch_total / - sol_D[count_cells].exch_total; + aq_il1 = t_aq1 * por_il12 / cell_data[count_cells].por; + aq_il2 = t_aq2 * por_il12 / cell_data[count_cells].por; } else { - por_il1 = sol_D[icell].exch_total / aq_i / sol_D[1].x_max * + por_il1 = sol_D[icell].exch_total / aq1 / sol_D[1].x_max * cell_data[icell].por_il; - por_il2 = sol_D[jcell].exch_total / aq_j / sol_D[1].x_max * + por_il2 = sol_D[jcell].exch_total / aq2 / sol_D[1].x_max * cell_data[jcell].por_il; if (sol_D[icell].exch_total > 3e-10 && sol_D[jcell].exch_total > 3e-10) - por_il12 = (por_il1 + por_il2) / 2; + por_il12 = 2 * por_il1 * por_il2 / (por_il1 + por_il2); else por_il12 = (por_il1 >= por_il2 ? por_il1 : por_il2); - if (por_il12 > 0.999 * cell_data[icell].por || por_il12 > 0.999 * cell_data[jcell].por) - por_il12 = (cell_data[icell].por >= cell_data[jcell].por ? - 0.999 * cell_data[jcell].por : - 0.999 * cell_data[icell].por); - aq_il1 = (aq_i + dl_aq_i) * por_il1 / - (cell_data[icell].por - por_il1); - aq_il2 = (aq_j + dl_aq_j) * por_il2 / - (cell_data[jcell].por - por_il2); + + aq_il1 = t_aq1 * por_il12 / cell_data[icell].por; + aq_il2 = t_aq2 * por_il12 / cell_data[jcell].por; } - if (por_il12 == 0) + if (por_il12 < interlayer_Dpor_lim) il_calcs = 0; else { dum = sol_D[icell].exch_total; dum2 = sol_D[jcell].exch_total; + // the rc's are for distributing the mole transfer (later on) over X and solution. rc1 = (dum2 > dum ? dum / dum2 : 1); rc2 = (dum > dum2 ? dum2 / dum : 1); if (sol_D[icell].exch_total > 3e-10) @@ -2599,15 +2585,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) cec2 = dum2 / aq_il2; else cec2 = 2e-10; - /* and the largest for calculating the mass transfer... */ + /* and the largest for calculating the mass transfer since it is usually at the boundary... */ cec12 = (cec1 > cec2 ? cec1 : cec2); } } /* In stagnant calc's, find ct[icell].mixf_il for IL diffusion, correct mixf. - In regular column, find surface areas A_i, j and A_il */ + In regular column, find surface areas A1, j and A_il */ - tort_i = tort_j = 1.0; + tort1 = tort2 = 1.0; ct[icell].A_ij_il = ct[icell].mixf_il = 0.0; if (stagnant) { @@ -2615,74 +2601,74 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) dum = (cell_data[icell].por <= cell_data[jcell].por ? cell_data[icell].por : cell_data[jcell].por); if (il_calcs) - { ct[icell].mixf_il = mixf * por_il12 / interlayer_tortf; - dum -= por_il12; - } mixf *= (dum * pow(dum, multi_Dn)); } else { /* regular column... */ if (icell == 0) { - tort_i = tort_j = pow(cell_data[1].por, -multi_Dn); - A_j = aqt_j / + tort1 = tort2 = pow(cell_data[1].por, -multi_Dn); + A2 = t_aq2 / (cell_data[1].length * 0.5 * cell_data[1].length); if (il_calcs) - ct[icell].A_ij_il = A_j * por_il12 / - ((cell_data[1].por - por_il12) * interlayer_tortf); + ct[icell].A_ij_il = A2 * por_il12 / + (cell_data[1].por * interlayer_tortf); - A_j /= tort_j; - A_i = A_j; + A2 /= tort2; + A1 = A2; } else if (icell == count_cells) { - tort_i = tort_j = pow(cell_data[count_cells].por, -multi_Dn); - A_i = aqt_i / + tort1 = tort2 = pow(cell_data[count_cells].por, -multi_Dn); + A1 = t_aq1 / (cell_data[count_cells].length * 0.5 * cell_data[count_cells].length); if (il_calcs) - ct[icell].A_ij_il = A_i * por_il12 / - ((cell_data[count_cells].por - por_il12) * interlayer_tortf); + ct[icell].A_ij_il = A1 * por_il12 / + (cell_data[count_cells].por * interlayer_tortf); - A_i /= tort_i; - A_j = A_i; + A1 /= tort1; + A2 = A1; } else { - tort_i = pow(cell_data[icell].por, -multi_Dn); - tort_j = pow(cell_data[jcell].por, -multi_Dn); - A_i = aqt_i / - (cell_data[icell].length * 0.5 * cell_data[icell].length) / tort_i; + tort1 = pow(cell_data[icell].por, -multi_Dn); + tort2 = pow(cell_data[jcell].por, -multi_Dn); + A1 = t_aq1 / + (cell_data[icell].length * 0.5 * cell_data[icell].length); - A_j = aqt_j / - (cell_data[jcell].length * 0.5 * cell_data[jcell].length) / tort_j; + A2 = t_aq2 / + (cell_data[jcell].length * 0.5 * cell_data[jcell].length); if (il_calcs) { - dum = A_i * por_il12 / - ((cell_data[icell].por - por_il12) * interlayer_tortf); - dum2 = A_j * por_il12 / - ((cell_data[jcell].por - por_il12) * interlayer_tortf); + dum = A1 * por_il12 / + (cell_data[icell].por * interlayer_tortf); + dum2 = A2 * por_il12 / + (cell_data[jcell].por * interlayer_tortf); ct[icell].A_ij_il = dum * dum2 / (dum + dum2); } + A1 /= tort1; + A2 /= tort2; } } /* diffuse... */ ct[icell].J_ij_sum = 0.0; + ct[icell].J_ij_count_spec = 0; /* * malloc sufficient space... */ k = sol_D[icell].count_spec + sol_D[jcell].count_spec; ct[icell].J_ij = (struct J_ij *) free_check_null(ct[icell].J_ij); - ct[icell].J_ij = (struct J_ij *) PHRQ_malloc((size_t)k * sizeof(struct J_ij)); + ct[icell].J_ij = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); if (ct[icell].J_ij == NULL) malloc_error(); ct[icell].v_m = (struct V_M *) free_check_null(ct[icell].v_m); - ct[icell].v_m = (struct V_M *) PHRQ_malloc((size_t)k * sizeof(struct V_M)); + ct[icell].v_m = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); if (ct[icell].v_m == NULL) malloc_error(); @@ -2709,14 +2695,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) k = sol_D[icell].count_exch_spec + sol_D[jcell].count_exch_spec; ct[icell].J_ij_il = (struct J_ij *) free_check_null(ct[icell].J_ij_il); - ct[icell].J_ij_il = (struct J_ij *) PHRQ_malloc((size_t)k * sizeof(struct J_ij)); + ct[icell].J_ij_il = (struct J_ij *) PHRQ_malloc((size_t) k * sizeof(struct J_ij)); if (ct[icell].J_ij_il == NULL) malloc_error(); ct[icell].v_m_il = (struct V_M *) free_check_null(ct[icell].v_m_il); - ct[icell].v_m_il = (struct V_M *) PHRQ_malloc((size_t)k * sizeof(struct V_M)); + ct[icell].v_m_il = (struct V_M *) PHRQ_malloc((size_t) k * sizeof(struct V_M)); if (ct[icell].v_m_il == NULL) malloc_error(); + for (i = 0; i < k; i++) { ct[icell].J_ij_il[i].tot1 = 0.0; @@ -2775,7 +2762,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (ct[icell].dl_s > 0) { - s_charge_ptr = (dl_aq_i > 0) ? s_charge_ptr1 : s_charge_ptr2; + s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); if (only_counter) { @@ -2789,9 +2776,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (dl_aq_i > 0) + if (dl_aq1 > 0) { - ct[icell].v_m[k].g_dl = (1 + g * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1 * ct[icell].v_m[k].g_dl; } @@ -2827,9 +2814,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (ct[icell].v_m[k].z) { - if (dl_aq_i > 0) + if (dl_aq1 > 0) g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (dl_aq_j > 0) + if (dl_aq2 > 0) { if (abs(ct[icell].v_m[k].z) == 1) // there is always H+ and OH-... @@ -2838,13 +2825,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { dum = ct[icell].v_m[k].z > 0 ? 1 : -1; g_j = s_charge_ptr2->Get_g_map()[dum].Get_g(); - g_j = pow((1 + g_j * aq_j / dl_aq_j), ct[icell].v_m[k].z) - 1; + g_j = pow((1 + g_j * aq2 / dl_aq2), ct[icell].v_m[k].z) - 1; } } } if (only_counter) { - s_charge_ptr = (dl_aq_i > 0) ? s_charge_ptr1 : s_charge_ptr2; + s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) { ct[icell].v_m[k].o_c = 0; @@ -2855,14 +2842,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (dl_aq_i > 0) - ct[icell].v_m[k].g_dl = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; - if (dl_aq_j) - dum2 = (1 + g_j * aq_j / dl_aq_j) * sol_D[icell].spec[i].erm_ddl; + if (dl_aq1 > 0) + ct[icell].v_m[k].g_dl = (1 + g_i * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; + if (dl_aq2) + dum2 = (1 + g_j * aq2 / dl_aq2) * sol_D[icell].spec[i].erm_ddl; } } - b_i = A_i * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); - b_j = A_j * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_j = A2 * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); if (icell == count_cells) ct[icell].v_m[k].b_ij = b_i; else @@ -2927,7 +2914,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (ct[icell].dl_s > 0) { - s_charge_ptr = (dl_aq_j > 0) ? s_charge_ptr2 : s_charge_ptr1; + s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); if (only_counter) { @@ -2941,9 +2928,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (dl_aq_j > 0) + if (dl_aq2 > 0) { - ct[icell].v_m[k].g_dl = (1 + g * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; + ct[icell].v_m[k].g_dl = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2 * ct[icell].v_m[k].g_dl; } @@ -2976,13 +2963,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } g_i = g_j = dum1 = 0; - if (ct[jcell].dl_s > 0) + if (ct[icell].dl_s > 0) { if (ct[icell].v_m[k].z) { - if (dl_aq_j > 0) + if (dl_aq2 > 0) g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (dl_aq_i > 0) + if (dl_aq1 > 0) { if (abs(ct[icell].v_m[k].z) == 1) g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); @@ -2990,13 +2977,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { dum = ct[icell].v_m[k].z > 0 ? 1 : -1; g_i = s_charge_ptr1->Get_g_map()[dum].Get_g(); - g_i = pow((1 + g_i * aq_i / dl_aq_i), ct[icell].v_m[k].z) - 1; + g_i = pow((1 + g_i * aq1 / dl_aq1), ct[icell].v_m[k].z) - 1; } } } if (only_counter) { - s_charge_ptr = (dl_aq_j > 0) ? s_charge_ptr2 : s_charge_ptr1; + s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) { ct[icell].v_m[k].o_c = 0; @@ -3007,14 +2994,14 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (dl_aq_j) - ct[icell].v_m[k].g_dl = (1 + g_j * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; - if (dl_aq_i) - dum1 = (1 + g_i * aq_i / dl_aq_i) * sol_D[jcell].spec[j].erm_ddl; + if (dl_aq2) + ct[icell].v_m[k].g_dl = (1 + g_j * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; + if (dl_aq1) + dum1 = (1 + g_i * aq1 / dl_aq1) * sol_D[jcell].spec[j].erm_ddl; } } - b_i = A_i * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); - b_j = A_j * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); + b_i = A1 * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); + b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); if (icell == 0) ct[icell].v_m[k].b_ij = b_j; else @@ -3059,8 +3046,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m_il[k_il].z = sol_D[icell].spec[i].z; ct[icell].v_m_il[k_il].Dz = ct[icell].v_m_il[k_il].D * ct[icell].v_m_il[k_il].z; - ct[icell].v_m_il[k_il].Dzc = ct[icell].v_m_il[k_il].Dz * (sol_D[icell].spec[i].c * cec1 + - sol_D[jcell].spec[j].c * cec2) / (2 * ct[icell].v_m_il[k_il].z); + ct[icell].v_m_il[k_il].Dzc = ct[icell].v_m_il[k_il].Dz * (sol_D[icell].spec[i].c + + sol_D[jcell].spec[j].c) * cec12 / ct[icell].v_m_il[k_il].z; ct[icell].Dz2c_il += ct[icell].v_m_il[k_il].Dzc * ct[icell].v_m_il[k_il].z; ct[icell].v_m_il[k_il].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c) * cec12 / ct[icell].v_m_il[k_il].z; /* use equivalent fraction */ @@ -3084,7 +3071,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (ct[icell].dl_s > 0) { c_dl = 0.0; - if (dl_aq_i > 0) + if (dl_aq1 > 0) { g = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); if (only_counter) @@ -3100,13 +3087,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - ct[icell].v_m[k].g_dl = (1 + g * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; c_dl = c1 * ct[icell].v_m[k].g_dl; } } else c_dl = c1; - if (dl_aq_j > 0) + if (dl_aq2 > 0) { g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); { @@ -3127,7 +3114,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - dum = (1 + g * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; + dum = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; c_dl += c2 * dum; ct[icell].v_m[k].g_dl = (ct[icell].v_m[k].g_dl + dum) / 2; } @@ -3159,8 +3146,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2) * dV_dcell; // don't transport unavailable moles against the gradient if (abs(dum) < abs(dum2) && - ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq_j < 1e-12) || - (dum2 <= 0 && sol_D[icell].spec[i].c * aq_i < 1e-12))) + ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || + (dum2 <= 0 && sol_D[icell].spec[i].c * aq1 < 1e-12))) { // step out: if (i < i_max) @@ -3173,7 +3160,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) g_i = g_j = dum2 = 0; if (ct[icell].dl_s > 0) { - if (dl_aq_i > 0) + if (dl_aq1 > 0) { if (only_counter) { @@ -3187,11 +3174,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else { g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - ct[icell].v_m[k].g_dl = (1 + g_i * aq_i / dl_aq_i) * sol_D[icell].spec[i].erm_ddl; + ct[icell].v_m[k].g_dl = (1 + g_i * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; } } - if (dl_aq_j > 0) + if (dl_aq2 > 0) { if (only_counter) { @@ -3206,12 +3193,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else { g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - dum2 = (1 + g_j * aq_j / dl_aq_j) * sol_D[jcell].spec[j].erm_ddl; + dum2 = (1 + g_j * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; } } } - b_i = A_i * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); - b_j = A_j * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); + b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); if (icell == 0) ct[icell].v_m[k].b_ij = b_j; else if (icell == count_cells) @@ -3244,7 +3231,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].J_ij_count_spec = i_max = k; ct[icell].J_ij_il_count_spec = k_il; - if (dV_dcell && !stagnant) + if (dV_dcell) { current_cells[icell].ele = current_cells[icell].dif = 0; dum = dV_dcell * F_Re3 / tk_x2; @@ -3264,7 +3251,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } // dV_dcell, 2nd pass, current_x has been calculated, and - // voltage has been adapted to give equal current in the cells. + // voltage was adapted to give equal current in the cells. dV_dcell2: ct[icell].J_ij_sum = 0; @@ -3298,6 +3285,7 @@ dV_dcell2: (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; } ct[icell].J_ij[i].tot1 *= mixf; + ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; } } else // diffusion in regular column @@ -3313,14 +3301,15 @@ dV_dcell2: if (!dV_dcell && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].zc / ct[icell].Dz2c; ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * DDt; + ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; } } // assure that icell has dl water when checking negative conc's in MCD - ct[icell].dl_s = dl_aq_i; - ct[jcell].dl_s = dl_aq_j; + ct[icell].dl_s = dl_aq1; + ct[jcell].dl_s = dl_aq2; - if (dV_dcell && !stagnant) + if (dV_dcell) { // perhaps adapt dV for getting equal current... current_cells[icell].ele = current_cells[icell].dif = 0; @@ -3343,10 +3332,10 @@ dV_dcell2: continue; ct[icell].J_ij[i].tot1 -= ct[icell].v_m[i].b_ij * ct[icell].v_m[i].zc * dum * DDt; + ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; } current_A = current_x * F_C_MOL; } - /* * calculate interlayer mass transfer... */ @@ -3367,13 +3356,13 @@ dV_dcell2: else ct[icell].J_ij_il[i].tot1 *= ct[icell].A_ij_il * DDt; ct[icell].J_ij_sum += ct[icell].v_m_il[i].z * ct[icell].J_ij_il[i].tot1; - //ct[icell].J_ij_il[i].tot2 = ct[icell].J_ij_il[i].tot1; + ct[icell].J_ij_il[i].tot2 = ct[icell].J_ij_il[i].tot1; } /* express the transfer in elemental moles... */ tot1_h = tot1_o = tot2_h = tot2_o = 0.0; m_s = (struct M_S *) free_check_null(m_s); - m_s = (struct M_S *) PHRQ_malloc((size_t)count_elements * + m_s = (struct M_S *) PHRQ_malloc((size_t) count_elements * sizeof(struct M_S)); if (m_s == NULL) malloc_error(); @@ -3762,7 +3751,7 @@ Step (from cell 1 to count_cells + 1): /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < (int)surface_ptr2->Get_surface_comps().size(); k++) + for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -3791,7 +3780,7 @@ Step (from cell 1 to count_cells + 1): Dp1 = 0; if (surface_ptr1 != NULL && surface_ptr1->Get_transport()) { - for (k1 = 0; k1 < (int)surface_ptr1->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -3832,7 +3821,7 @@ Step (from cell 1 to count_cells + 1): } if (surf1) { - for (k = 0; k < (int)surface_ptr1->Get_surface_comps().size(); k++) + for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) { cxxSurfaceComp * comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -3869,7 +3858,7 @@ Step (from cell 1 to count_cells + 1): Dp2 = 0; if (surface_ptr2 != NULL && surface_ptr2->Get_transport()) { - for (k1 = 0; k1 < (int)surface_ptr2->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) { cxxSurfaceComp * comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -4200,7 +4189,7 @@ int n_user_new, bool move_old) { cxxSurface replace_old(temp_surface); int n_user_old = surface_old_ptr->Get_n_user(); - if ((size_t)i1 != count_comps) + if ((size_t) i1 != count_comps) { /* redefine old surface with only unmovable comps (Dw = 0) */ /* other temp_surface members were set above */ @@ -4396,7 +4385,7 @@ diff_stag_surf(int mobile_cell) /* mix in comps with the same charge structure... */ if (surf2) { - for (k = 0; k < (int)surface_ptr2->Get_surface_comps().size(); k++) + for (k = 0; k < (int) surface_ptr2->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr2->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -4424,7 +4413,7 @@ diff_stag_surf(int mobile_cell) Dp1 = 0; if (surf1) { - for (k1 = 0; k1 < (int)surface_ptr1->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int) surface_ptr1->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr1->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -4460,7 +4449,7 @@ diff_stag_surf(int mobile_cell) if (surf1) { - for (k = 0; k < (int)surface_ptr1->Get_surface_comps().size(); k++) + for (k = 0; k < (int) surface_ptr1->Get_surface_comps().size(); k++) { cxxSurfaceComp *comp_k_ptr = &(surface_ptr1->Get_surface_comps()[k]); std::string charge_name = comp_k_ptr->Get_charge_name(); @@ -4490,7 +4479,7 @@ diff_stag_surf(int mobile_cell) Dp2 = 0; if (surf2) { - for (k1 = 0; k1 < (int)surface_ptr2->Get_surface_comps().size(); k1++) + for (k1 = 0; k1 < (int) surface_ptr2->Get_surface_comps().size(); k1++) { cxxSurfaceComp *comp_k1_ptr = &(surface_ptr2->Get_surface_comps()[k1]); if (strcmp(comp_k1_ptr->Get_formula().c_str(), @@ -4713,7 +4702,150 @@ viscosity(void) 0.000836 * (tc_x - 20) * (tc_x - 20)) / (109 + tc_x)); viscos_0_25 = 0.88862; #endif + //return viscos; + if (!print_viscosity) + return viscos; + + /* (modified) Jones-Dole eqn for viscosity: + viscos / viscos_0 = + 1 + A * eq_tot^0.5 + + f_an * (Sum(B_i * m_i) + + Sum(D_i * m_i * ((1 + f_I) * mu_x^d3_i + (m_i * f_z)^d3_i) / (2 + f_I))) + A calculated from Falkenhagen-Dole + B_i = b0 + b1*exp(b2 * tc), b0..2 in Jones_Dole[0..2], read in SOLUTION_SPECIES + D_i = d1 * exp(d2 * tc), d1, 2 in Jones_Dole[3, 4] + d3_i in Jones_Dole[5] + Jones_Dole[6] contains the anion factor, 1 for Cl-, variable for other anions + f_z = (z * z + |z|) / 2, the contribution of the ion to mu_x, if z = 0: f_z = mu_x / m_i + f_I = variable, depends on d3_i > 1, or d3_i < 1. + tc is limited to 200°C. + + + A from Falkenhagen-Dole for a salt: + A = 4.3787e-14 * TK**1.5 / (eps_r**0.5)* (z1 + z2)**-0.5 / (D1 * D2) * psi + psi = (D1*z2 + D2*z1)/4 - z1*z2 * (D1-D2)**2 / ((D1*z1 + D2*z2)**0.5 + ((D1 + D2) * (z1 + z2))**0.5)**2 + D1, z1 for the cation, D2, |z2| for the anion of the salt. + We use the harmonic mean of the Dw's, and the arithmetic mean of the z's, + both weighted by the equivalent concentration. + */ + LDBLE D1, D2, z1, z2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, t1, t2, ta; + LDBLE A, psi, Bc = 0, Dc = 0, Dw, l_z, f_z, lm, V_an, m_an, V_Cl, tc; + + m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = V_an = m_an = V_Cl = ta = 0; + + tc = (tc_x > 200) ? 200 : tc_x; + + for (i = 0; i < count_s_x; i++) + { + if (s_x[i]->type != AQ && s_x[i]->type > HPLUS) + continue; + if ((lm = s_x[i]->lm) < -9) + continue; + if (s_x[i]->Jones_Dole[0] || s_x[i]->Jones_Dole[1] || s_x[i]->Jones_Dole[3]) + { + t1 = s_x[i]->moles / mass_water_aq_x; + l_z = fabs(s_x[i]->z); + if (l_z) + f_z = (l_z * l_z + l_z) / 2; + else + f_z = mu_x / t1; + //if data at tc's other than 25 are scarce, put the values found for 25 C in [7] and [8], optimize [1], [2], and [4]... + if (s_x[i]->Jones_Dole[7] || s_x[i]->Jones_Dole[8]) + { + s_x[i]->Jones_Dole[0] = s_x[i]->Jones_Dole[7] - + s_x[i]->Jones_Dole[1] * exp(-s_x[i]->Jones_Dole[2] * 25.0); + s_x[i]->Jones_Dole[3] = + s_x[i]->Jones_Dole[8] / exp(-s_x[i]->Jones_Dole[4] * 25.0); + } + // find B * m and D * m * mu^d3 + Bc += (s_x[i]->Jones_Dole[0] + + s_x[i]->Jones_Dole[1] * exp(-s_x[i]->Jones_Dole[2] * tc)) * + t1; + // define f_I from the exponent of the D * m^d3 term... + if (s_x[i]->Jones_Dole[5] >= 1) + t2 = mu_x / 3 / s_x[i]->Jones_Dole[5]; + else if (s_x[i]->Jones_Dole[5] > 0.4) + t2 = -0.8 / s_x[i]->Jones_Dole[5]; + else + t2 = -1; + Dc += (s_x[i]->Jones_Dole[3] * exp(-s_x[i]->Jones_Dole[4] * tc)) * + t1 * (pow(mu_x, s_x[i]->Jones_Dole[5])*(1 + t2) + pow(t1 * f_z, s_x[i]->Jones_Dole[5])) / (2 + t2); + //output_msg(sformatf("\t%s\t%e\t%e\t%e\n", s_x[i]->name, t1, Bc, Dc )); + } + // parms for A... + if ((l_z = s_x[i]->z) == 0) + continue; + if (Dw = s_x[i]->dw) + { + Dw *= (0.89 / viscos_0 * tk_x / 298.15); + if (s_x[i]->dw_t) + Dw *= exp(s_x[i]->dw_t / tk_x - s_x[i]->dw_t / 298.15); + } + if (l_z < 0) + { + if (!strcmp(s_x[i]->name, "Cl-")) + // volumina for f_an... + { + V_Cl = s_x[i]->logk[vm_tc]; + V_an += V_Cl * s_x[i]->moles; + ta += s_x[i]->moles; + m_an += s_x[i]->moles; + } + else// if (s_x[i]->Jones_Dole[6]) + { + V_an += s_x[i]->logk[vm_tc] * s_x[i]->Jones_Dole[6] * s_x[i]->moles; + ta += s_x[i]->moles; + m_an += s_x[i]->moles; + } + if (Dw) + { + // anions for A... + m_min += s_x[i]->moles; + t1 = s_x[i]->moles * l_z; + eq_min -= t1; + eq_dw_min -= t1 / Dw; + } + } + else if (Dw) + { + // cations for A... + m_plus += s_x[i]->moles; + t1 = s_x[i]->moles * l_z; + eq_plus += t1; + eq_dw_plus += t1 / Dw; + } + } + if (m_plus && m_min && eq_dw_plus && eq_dw_min) + { + z1 = eq_plus / m_plus; z2 = eq_min / m_min; + D1 = eq_plus / eq_dw_plus; D2 = eq_min / eq_dw_min; + + t1 = (D1 - D2) / (sqrt(D1 * z1 + D2 * z2) + sqrt((D1 + D2) * (z1 + z2))); + psi = (D1 * z2 + D2 * z1) / 4.0 - z1 * z2 * t1 * t1; + // Here A is A * viscos_0, avoids multiplication later on... + A = 4.3787e-14 * pow(tk_x, 1.5) / (sqrt(eps_r * (z1 + z2) / ((z1 > z2) ? z1 : z2)) * (D1 * D2)) * psi; + } + else + A = 0; + viscos = viscos_0 + A * sqrt((eq_plus + eq_min) / 2 / mass_water_aq_x); + if (m_an) + { + V_an /= m_an; + ta /= m_an; + } + if (!V_Cl) + V_Cl = calc_vm_Cl(); + if (V_an && V_Cl && ta) + viscos += (viscos_0 * (2 - ta * V_an / V_Cl) * (Bc + Dc)); + else + viscos += (viscos_0 * (Bc + Dc)); + if (viscos < 0) + { + viscos = 0; + warning_msg("viscosity < 0, reset to 0."); + } return viscos; + } /* ---------------------------------------------------------------------- */ LDBLE Phreeqc:: From cf4a14f00e376074ea8475612a840963aed7c09b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 9 Feb 2017 23:40:49 +0000 Subject: [PATCH 1036/1077] no gmp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12395 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.old b/Makefile.old index 5706b006..6d7279c2 100644 --- a/Makefile.old +++ b/Makefile.old @@ -118,7 +118,7 @@ EFENCE_LIB=-L$(HOME)/packages/efence # 4 Versions # ----------------------------------------------------------------------------- ifeq ($(CFG), CLASS_DEBUG) - INVERSE_CL1MP=TRUE + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o @@ -135,7 +135,7 @@ ifeq ($(CFG), CLASS_DEBUG) endif ifeq ($(CFG), CLASS_RELEASE) - INVERSE_CL1MP=TRUE + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o @@ -152,7 +152,7 @@ ifeq ($(CFG), CLASS_RELEASE) endif ifeq ($(CFG), CLASS_DEBUG_64) -# INVERSE_CL1MP=TRUE +# INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o @@ -168,7 +168,7 @@ ifeq ($(CFG), CLASS_DEBUG_64) endif ifeq ($(CFG), CLASS_RELEASE_64) - INVERSE_CL1MP=TRUE + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o From e9fe756bbecca435d5d3d054aaef561e85871e3b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Feb 2017 00:07:28 +0000 Subject: [PATCH 1037/1077] updated Makefile? fixed compiler warnings in transport.cpp git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12396 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.old | 331 +++++++++++--------------------------------------- transport.cpp | 17 ++- 2 files changed, 81 insertions(+), 267 deletions(-) diff --git a/Makefile.old b/Makefile.old index e81cb2fc..6d7279c2 100644 --- a/Makefile.old +++ b/Makefile.old @@ -12,8 +12,6 @@ PROGRAM = phreeqc -MPI_DIR=/usr/lib64/openmpi - CFG1 :=`uname` CFG :=$(shell echo $(CFG1) | sed "s/Linux.*/Linux/") ifeq ($(CFG), Linux) @@ -25,26 +23,29 @@ else SPOOL2=2>&1 CONCAT=& endif -all: release_openmp +all: class_release class_debug -Debug: debug -Debug_openmp: debug_openmp -Debug_mpi: debug_mpi - -Release: release -Release_omp: release_openmp -Release_mpi: release_mpi - - -DEBUG_DIR = debug -DEBUG_OPENMP_DIR = debug_openmp -DEBUG_MPI_DIR = debug_mpi -RELEASE_DIR = release -RELEASE_OPENMP_DIR = release_openmp -RELEASE_MPI_DIR = release_mpi +Debug: class_debug +debug: class_debug +Class_debug: class_debug +Release: class_release +release: class_release +Class_release: class_release + +Debug_64: class_debug_64 +debug_64: class_debug_64 +Class_debug_64: class_debug_64 + +Release_64: class_release_64 +release_64: class_release_64 +Class_release_64: class_release_64 +CLASS_DEBUG_DIR = Class_debug +CLASS_DIR = Class_release +CLASS_DEBUG_64_DIR = Class_debug_64 +CLASS_64_DIR = Class_release_64 MAKEFILE = Makefile.old # ----------------------------------------------------------------------------- @@ -55,35 +56,24 @@ HASH_STYLE=$(call ld-option, -Wl$(comma)--hash-style=sysv) ######################### #### Serial Versions #### ######################### -.PHONY : debug -debug: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG $(PROGRAM) +.PHONY : Class_debug +class_debug: + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG $(PROGRAM) -.PHONY : release -release: - mkdir -p $(RELEASE_DIR) - cd $(RELEASE_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE $(PROGRAM) +.PHONY : Class_release +class_release: + mkdir -p $(CLASS_DIR) + cd $(CLASS_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE $(PROGRAM) +.PHONY : Class_debug_64 +class_debug_64: + mkdir -p $(CLASS_DEBUG_64_DIR) + cd $(CLASS_DEBUG_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_DEBUG_64 $(PROGRAM) -.PHONY : debug_openmp -debug_openmp: - mkdir -p $(DEBUG_OPENMP_DIR) - cd $(DEBUG_OPENMP_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG_OPENMP $(PROGRAM) - -.PHONY : release_openmp -release_openmp: - mkdir -p $(RELEASE_OPENMP_DIR) - cd $(RELEASE_OPENMP_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE_OPENMP $(PROGRAM) - -.PHONY : debug_mpi -debug_mpi: - mkdir -p $(DEBUG_MPI_DIR) - cd $(DEBUG_MPI_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=DEBUG_MPI $(PROGRAM) - -.PHONY : release_mpi -release_mpi: - mkdir -p $(RELEASE_MPI_DIR) - cd $(RELEASE_MPI_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=RELEASE_MPI $(PROGRAM) +.PHONY : Class_release_64 +class_release_64: + mkdir -p $(CLASS_64_DIR) + cd $(CLASS_64_DIR); $(MAKE) -r -f ../$(MAKEFILE) CFG=CLASS_RELEASE_64 $(PROGRAM) # Recursive make begins here # @@ -107,6 +97,11 @@ release_mpi: .cpp.o : ${CXX} ${CXXFLAGS} -c -o $@ $< +# ----------------------------------------------------------------------------- +#hdf options +#HDF5_ROOT=$(HOME)/../../usr +#HDF5_INCLUDES=-I$(HDF5_ROOT)/src +#HDF5_LIBS=${HDF5_ROOT}/lib/libhdf5.a -lz -lpthread # ----------------------------------------------------------------------------- # #define compile options @@ -120,15 +115,15 @@ release_mpi: EFENCE_LIB=-L$(HOME)/packages/efence # ----------------------------------------------------------------------------- -# Versions +# 4 Versions # ----------------------------------------------------------------------------- -ifeq ($(CFG), DEBUG) - INVERSE_CL1MP=TRUE +ifeq ($(CFG), CLASS_DEBUG) + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o # CL1MP_LIB=-lgmp - CL1MP_LIB=/usr/lib64/libgmp.a + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../PhreeqcKeywords:../common @@ -139,13 +134,13 @@ ifeq ($(CFG), DEBUG) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif -ifeq ($(CFG), RELEASE) - INVERSE_CL1MP=TRUE +ifeq ($(CFG), CLASS_RELEASE) + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o # CL1MP_LIB=-lgmp - CL1MP_LIB=/usr/lib64/libgmp.a + CL1MP_LIB=/z/parkplace/usr/lib/libgmp.a endif DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 VPATH = ..:../PhreeqcKeywords:../common @@ -156,76 +151,40 @@ ifeq ($(CFG), RELEASE) LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif -ifeq ($(CFG), DEBUG_OPENMP) - INVERSE_CL1MP=TRUE +ifeq ($(CFG), CLASS_DEBUG_64) +# INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o - CL1MP_LIB=/usr/lib64/libgmp.a + CL1MP_LIB=libgmp.a endif - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_OPENMP - VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc - INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc + DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) # -DPHREEQC2 + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common CXX = g++ - CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) -fopenmp - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(PARALLELIZER_OBJS) $(CL1MP_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -lgomp -endif - -ifeq ($(CFG), RELEASE_OPENMP) - INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o - CL1MP_LIB=/usr/lib64/libgmp.a - endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_OPENMP # -DUSE_PHRQ_ALLOC - VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc - INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc - CXX = g++ - PROFILE = - CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) -fopenmp -# CXXFLAGS = -fprofile-arcs -ftest-coverage $(DEFINES) $(INCLUDES) # -g - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) - LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} -lgomp # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov -endif - -ifeq ($(CFG), DEBUG_MPI) - INVERSE_CL1MP=TRUE - ifdef INVERSE_CL1MP - DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP - CL1MP_OBJS=cl1mp.o - CL1MP_LIB=/usr/lib64/libgmp.a - endif - DEFINES = -DUSE_PHRQ_ALLOC $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_MPI - VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc - INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc - CXX = $(MPI_DIR)/bin/mpiCC CXXFLAGS = -Wall -g $(DEFINES) $(INCLUDES) - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) - LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} -lmpi_usempi + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = -lm ${CL1MP_LIB} ${HASH_STYLE} endif -ifeq ($(CFG), RELEASE_MPI) - INVERSE_CL1MP=TRUE +ifeq ($(CFG), CLASS_RELEASE_64) + INVERSE_CL1MP= ifdef INVERSE_CL1MP DEFINE_INVERSE_CL1MP=-DINVERSE_CL1MP CL1MP_OBJS=cl1mp.o CL1MP_LIB=/usr/lib64/libgmp.a endif - DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) -DPHREEQC_PARALLEL -DUSE_MPI # -DUSE_PHRQ_ALLOC - VPATH = ..:../PhreeqcKeywords:../common:../PhreeqcRM:../PhreeqcRM/IPhreeqcPhast:../PhreeqcRM/IPhreeqcPhast/IPhreeqc - INCLUDES = -I.. -I../PhreeqcKeywords -I../common -I../PhreeqcRM -I../PhreeqcRM/IPhreeqcPhast -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc - CXX = $(MPI_DIR)/bin/mpiCC + DEFINES = -DNDEBUG $(DEFINE_INVERSE_CL1MP) # -DUSE_PHRQ_ALLOC # -DR_SO + VPATH = ..:../PhreeqcKeywords:../common + INCLUDES = -I.. -I../PhreeqcKeywords -I../common + CXX = g++ PROFILE = - CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) + CXXFLAGS = $(PROFILE) -Wall -pedantic -O3 $(DEFINES) $(INCLUDES) # -g # CXXFLAGS = -fprofile-arcs -ftest-coverage $(DEFINES) $(INCLUDES) # -g - OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) $(PARALLELIZER_OBJS) - LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} -lmpi_usempi + OBJECT_FILES = $(CLASS_FILES) $(COMMON_COBJS) $(COMMON_CXXOBJS) $(CL1MP_OBJS) + LD_FLAGS = $(PROFILE) -lm ${CL1MP_LIB} ${HASH_STYLE} # -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4 -lgcov endif - - # ----------------------------------------------------------------------------- # @@ -316,16 +275,6 @@ COMMON_CXXOBJS = \ UserPunch.o \ Utils.o -PARALLELIZER_OBJS = \ - Parallelizer.o \ - PhreeqcRM.o \ - IPhreeqcPhast.o \ - IPhreeqcPhastLib.o \ - IPhreeqc.o \ - IPhreeqcLib.o \ - Var.o \ - CSelectedOutput.o - # ----------------------------------------------------------------------------- # Assign dependents to target on dependency line & link options on command # line. Command line is initiated with a tab. ($@ is an internal macro for @@ -655,11 +604,11 @@ class_main.o: ../class_main.cpp ../Phreeqc.h ../common/phrqtype.h \ ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../NameDouble.h \ ../common/Parser.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ - ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../Solution.h ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h \ - ../Reaction.h ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h \ - ../ExchComp.h ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../cxxKinetics.h ../KineticsComp.h + ../SurfaceCharge.h ../global_structures.h ../NA.h ../Solution.h \ + ../SolutionIsotope.h ../ISolution.h ../ISolutionComp.h ../Reaction.h \ + ../PPassemblage.h ../PPassemblageComp.h ../Exchange.h ../ExchComp.h \ + ../GasPhase.h ../GasComp.h ../SSassemblage.h ../SS.h ../SScomp.h \ + ../cxxKinetics.h ../KineticsComp.h CurveObject.o: ../CurveObject.cpp cvdense.o: ../cvdense.cpp ../cvdense.h ../cvode.h ../sundialstypes.h \ ../common/phrqtype.h ../nvector.h ../dense.h ../smalldense.h \ @@ -774,7 +723,6 @@ nvector.o: ../nvector.cpp ../nvector.h ../sundialstypes.h \ ../common/phrqtype.h nvector_serial.o: ../nvector_serial.cpp ../nvector_serial.h ../nvector.h \ ../sundialstypes.h ../common/phrqtype.h ../sundialsmath.h -Parallelizer.o: ../Parallelizer.cpp parse.o: ../parse.cpp ../Phreeqc.h ../common/phrqtype.h ../cvdense.h \ ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ ../runner.h ../StorageBinList.h ../common/PHRQ_base.h ../dumper.h \ @@ -850,7 +798,7 @@ prep.o: ../prep.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ ../global_structures.h ../NA.h ../phqalloc.h ../Exchange.h ../ExchComp.h \ ../GasPhase.h ../GasComp.h ../PPassemblage.h ../PPassemblageComp.h \ ../SSassemblage.h ../SS.h ../SScomp.h ../Solution.h ../SolutionIsotope.h \ - ../ISolution.h ../ISolutionComp.h + ../ISolution.h ../ISolutionComp.h ../cxxKinetics.h ../KineticsComp.h print.o: ../print.cpp ../common/Utils.h ../common/phrqtype.h ../Phreeqc.h \ ../common/phrqtype.h ../cvdense.h ../cvode.h ../sundialstypes.h \ ../nvector.h ../dense.h ../smalldense.h ../runner.h ../StorageBinList.h \ @@ -1010,147 +958,14 @@ PHRQ_base.o: ../common/PHRQ_base.cxx ../common/PHRQ_base.h \ Utils.o: ../common/Utils.cxx ../common/Utils.h ../common/phrqtype.h \ ../common/Parser.h ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h \ ../common/PHRQ_io.h -PhreeqcRM.o: ../PhreeqcRM/PhreeqcRM.cpp ../PhreeqcRM/PhreeqcRM.h \ - ../NameDouble.h ../common/Parser.h ../common/PHRQ_base.h \ - ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h ../common/phrqtype.h \ - ../PhreeqcRM/IrmResult.h ../common/PHRQ_base.h ../common/PHRQ_io.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../StorageBin.h ../System.h \ - ../NameDouble.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../System.h ../cxxMix.h \ - ../NumKeyword.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h ../global_structures.h ../Surface.h ../SurfaceComp.h \ - ../SurfaceCharge.h ../NA.h ../Exchange.h ../ExchComp.h ../Surface.h \ - ../PPassemblage.h ../PPassemblageComp.h ../SSassemblage.h ../SS.h \ - ../SScomp.h ../cxxKinetics.h ../KineticsComp.h ../GasPhase.h \ - ../GasComp.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../SelectedOutput.h \ - ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h -RM_interface_C.o: ../PhreeqcRM/RM_interface_C.cpp \ - ../PhreeqcRM/PhreeqcRM.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ - ../common/phrqtype.h ../PhreeqcRM/IrmResult.h \ - ../PhreeqcRM/RM_interface_C.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ - ../StorageBin.h ../System.h ../NameDouble.h ../common/PHRQ_io.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h -RM_interface_F.o: ../PhreeqcRM/RM_interface_F.cpp \ - ../PhreeqcRM/PhreeqcRM.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ - ../common/phrqtype.h ../PhreeqcRM/IrmResult.h \ - ../PhreeqcRM/RM_interface_F.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ - ../StorageBin.h ../System.h ../NameDouble.h ../common/PHRQ_io.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h ../Phreeqc.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../dumper.h \ - ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h ../Pressure.h \ - ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h \ - ../global_structures.h ../NA.h -IPhreeqcPhastLib.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.cpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ - ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ - ../StorageBin.h ../System.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../common/PHRQ_io.h ../common/phrqtype.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhastLib.h -IPhreeqcPhast.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.cxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqcPhast.h ../common/PHRQ_base.h \ - ../StorageBin.h ../System.h ../NameDouble.h ../common/Parser.h \ - ../common/PHRQ_base.h ../PhreeqcKeywords/Keywords.h ../common/PHRQ_io.h \ - ../common/phrqtype.h ../common/PHRQ_io.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h ../Phreeqc.h ../cvdense.h \ - ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h ../smalldense.h \ - ../runner.h ../StorageBinList.h ../dumper.h ../SelectedOutput.h \ - ../NumKeyword.h ../UserPunch.h ../Pressure.h ../cxxMix.h ../Use.h \ - ../Surface.h ../SurfaceComp.h ../SurfaceCharge.h ../global_structures.h \ - ../NA.h ../Solution.h ../SolutionIsotope.h ../ISolution.h \ - ../ISolutionComp.h ../GasPhase.h ../GasComp.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx -CSelectedOutput.o: \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.cpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Debug.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h -fwrap1.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap1.cpp -fwrap2.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap2.cpp -fwrap3.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap3.cpp -fwrap4.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap4.cpp -fwrap5.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap5.cpp -fwrap6.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap6.cpp -fwrap7.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap7.cpp -fwrap8.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap8.cpp -fwrap.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/fwrap.cpp -IPhreeqc.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.cpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h ../common/PHRQ_io.h \ - ../PhreeqcKeywords/Keywords.h ../Phreeqc.h ../common/phrqtype.h \ - ../cvdense.h ../cvode.h ../sundialstypes.h ../nvector.h ../dense.h \ - ../smalldense.h ../runner.h ../StorageBinList.h ../common/PHRQ_base.h \ - ../dumper.h ../SelectedOutput.h ../NumKeyword.h ../UserPunch.h \ - ../Pressure.h ../cxxMix.h ../Use.h ../Surface.h ../SurfaceComp.h \ - ../NameDouble.h ../common/Parser.h ../common/PHRQ_base.h \ - ../common/PHRQ_io.h ../SurfaceCharge.h ../global_structures.h ../NA.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/thread.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Version.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Debug.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/ErrorReporter.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CSelectedOutput.hxx \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/CVar.hxx ../SelectedOutput.h \ - ../dumper.h -IPhreeqc_interface_F.o: \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc_interface_F.cpp \ - ../common/phrqtype.h ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc_interface_F.h -IPhreeqcLib.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcLib.cpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqc.hpp \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/IPhreeqcCallbacks.h \ - ../common/PHRQ_io.h ../PhreeqcKeywords/Keywords.h \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/thread.h -pp_sys.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/pp_sys.cpp -Var.o: ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.c \ - ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/Var.h - # ----------------------------------------------------------------------------- clean: - rm -rf release debug release_openmp debug_openmp release_mpi debug_mpi + rm -rf Class_release Class_debug Class_release_64 Class_debug_64 dependencies: - mkdir -p $(DEBUG_DIR) - cd $(DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx \ - -I../PhreeqcRM ../PhreeqcRM/*.cpp \ - -I../PhreeqcRM/IPhreeqcPhast ../PhreeqcRM/IPhreeqcPhast/*.cpp ../PhreeqcRM/IPhreeqcPhast/*.cxx \ - -I../PhreeqcRM/IPhreeqcPhast/IPhreeqc ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.cpp ../PhreeqcRM/IPhreeqcPhast/IPhreeqc/*.c + mkdir -p $(CLASS_DEBUG_DIR) + cd $(CLASS_DEBUG_DIR); gcc -MM -I.. -I../PhreeqcKeywords -I../common ../*.cxx ../*.cpp ../PhreeqcKeywords/*.cpp ../common/*.cxx tester: # cd ../mytest; make clean; make -k -j 1 $(SPOOL) make.out $(SPOOL2); make diff $(SPOOL) diff.out $(SPOOL2) diff --git a/transport.cpp b/transport.cpp index 4db62597..7b4be003 100644 --- a/transport.cpp +++ b/transport.cpp @@ -50,7 +50,7 @@ transport(void) char token[MAX_LENGTH]; LDBLE kin_time, stagkin_time, kin_time_save; - int punch_boolean; + int punch_boolean = 0; LDBLE step_fraction; state = TRANSPORT; @@ -970,7 +970,7 @@ int Phreeqc:: init_mix(void) /* ---------------------------------------------------------------------- */ { - LDBLE lav, dav, mf12, maxmix, corr_disp, diffc_here, mD; + LDBLE lav, dav = 0.0, mf12, maxmix, corr_disp, diffc_here, mD; bool warning = false; int i, l_nmix; LDBLE *m, *m1; @@ -2153,7 +2153,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) { use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); cxxSurface * s_ptr = use.Get_surface_ptr(); - cxxSurfaceCharge * charge_ptr; + cxxSurfaceCharge * charge_ptr = NULL; for (size_t j = 0; j < s_ptr->Get_surface_charges().size(); j++) { if (s_ptr->Get_dl_type() == cxxSurface::DONNAN_DL) @@ -2346,16 +2346,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) */ int i, i_max, j, j_max, k, k_il, only_counter, il_calcs; int i1; - LDBLE A1, A2, ddlm, aq1, aq2, t_aq1, t_aq2, f_free_i, f_free_j; + LDBLE A1 = 0.0, A2 = 0.0, ddlm, aq1, aq2, t_aq1, t_aq2, f_free_i, f_free_j; LDBLE dl_aq1, dl_aq2, c_dl, dum, dum1, dum2, tort1, tort2, b_i, b_j; LDBLE Sum_zM, aq_il1, aq_il2; - LDBLE por_il1, por_il2, por_il12; - LDBLE cec1, cec2, cec12, rc1, rc2; + LDBLE por_il1, por_il2, por_il12 = 0.0; + LDBLE cec1, cec2, cec12 = 0.0, rc1 = 0.0, rc2 = 0.0; LDBLE dV, c1, c2; cxxSurface *s_ptr1, *s_ptr2; cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; LDBLE g, g_i, g_j; - LDBLE dV_temp = 0; char token[MAX_LENGTH], token1[MAX_LENGTH]; il_calcs = (interlayer_Dflag ? 1 : 0); @@ -4729,7 +4728,7 @@ viscosity(void) both weighted by the equivalent concentration. */ LDBLE D1, D2, z1, z2, m_plus, m_min, eq_plus, eq_min, eq_dw_plus, eq_dw_min, t1, t2, ta; - LDBLE A, psi, Bc = 0, Dc = 0, Dw, l_z, f_z, lm, V_an, m_an, V_Cl, tc; + LDBLE A, psi, Bc = 0, Dc = 0, Dw = 0.0, l_z, f_z, lm, V_an, m_an, V_Cl, tc; m_plus = m_min = eq_plus = eq_min = eq_dw_plus = eq_dw_min = V_an = m_an = V_Cl = ta = 0; @@ -4775,7 +4774,7 @@ viscosity(void) // parms for A... if ((l_z = s_x[i]->z) == 0) continue; - if (Dw = s_x[i]->dw) + if (Dw == s_x[i]->dw) { Dw *= (0.89 / viscos_0 * tk_x / 298.15); if (s_x[i]->dw_t) From 35458cd0afaedaf66defdc2617f6f0b29c293e1e Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Feb 2017 00:28:17 +0000 Subject: [PATCH 1038/1077] Initialize correct_Dw to 0. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12397 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index cc163a7d..77d28fa0 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -470,6 +470,7 @@ void Phreeqc::init(void) multi_Dflag = FALSE; interlayer_Dflag = FALSE; default_Dw = 0; + correct_Dw = 0; multi_Dpor = 0; interlayer_Dpor = 0.1; multi_Dpor_lim = 0; From 6a60c92f57e5cf9a6d844f2fef68fb1397c3733f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Feb 2017 16:51:48 +0000 Subject: [PATCH 1039/1077] Need to set Dw git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12398 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transport.cpp b/transport.cpp index 7b4be003..50b91423 100644 --- a/transport.cpp +++ b/transport.cpp @@ -4774,7 +4774,8 @@ viscosity(void) // parms for A... if ((l_z = s_x[i]->z) == 0) continue; - if (Dw == s_x[i]->dw) + Dw = s_x[i]->dw; + if (Dw) { Dw *= (0.89 / viscos_0 * tk_x / 298.15); if (s_x[i]->dw_t) From 873b98ff7c7a9d5aad54cecff9433c4ce5512dbb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2017 17:22:26 +0000 Subject: [PATCH 1040/1077] Caught error I think caused by defining X as a SURFACE and an EXCHANGEr. Added test case. Initialized unknown structure variables. Caught null pointer in Tony's multi_D. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12439 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 7 +++++++ structures.cpp | 6 ++++++ transport.cpp | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/print.cpp b/print.cpp index 8005b225..ed2b60c0 100644 --- a/print.cpp +++ b/print.cpp @@ -482,6 +482,13 @@ print_exchange(void) output_msg(sformatf("%-14s%12.3e mol", name, (double) master_ptr->unknown->moles)); cxxExchange *exchange_ptr = (cxxExchange *) (use.Get_exchange_ptr()); + if (master_ptr->unknown->exch_comp == NULL) + { + error_string = sformatf("Exchange unknown has no exchange component for exchanger %s." + "\nIs the same name used for a SURFACE and an EXCHANGER?", + master_ptr->unknown->description); + error_msg(error_string, STOP); + } const cxxExchComp *exchange_comp_ptr = exchange_ptr->Find_comp(master_ptr->unknown->exch_comp); assert(exchange_comp_ptr); if (exchange_comp_ptr->Get_phase_name().size() > 0) diff --git a/structures.cpp b/structures.cpp index 1f4cbe6b..5bb0ac11 100644 --- a/structures.cpp +++ b/structures.cpp @@ -3185,6 +3185,7 @@ unknown_alloc(void) unknown_ptr->si = 0.0; unknown_ptr->s = NULL; unknown_ptr->exch_comp = NULL; + unknown_ptr->pp_assemblage_comp_name = NULL; unknown_ptr->pp_assemblage_comp_ptr = NULL; unknown_ptr->ss_name = NULL; unknown_ptr->ss_ptr = NULL; @@ -3203,6 +3204,11 @@ unknown_alloc(void) unknown_ptr->surface_charge = NULL; unknown_ptr->mass_water = 0.0; unknown_ptr->dissolve_only = FALSE; + unknown_ptr->inert_moles = 0.0; + unknown_ptr->V_m = 0.0; + unknown_ptr->pressure = 0.0; + unknown_ptr->mb_number = 0; + unknown_ptr->iteration = 0; return (unknown_ptr); } diff --git a/transport.cpp b/transport.cpp index 69daeddc..bad92a91 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1712,6 +1712,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } + if (J_ij == NULL) + { + error_string = sformatf( "Null pointer for fill_m_s.\n" + "Consider using more substeps in TRANSPORT; -time_step."); + error_msg(error_string, STOP); + } fill_m_s(J_ij, J_ij_count_spec); /* From cff3ae90e2cece2152d576263fe31997f9e8d8bd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 16 Feb 2017 21:50:14 +0000 Subject: [PATCH 1041/1077] Wrote tranport_cleanup. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12440 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.h | 1 + transport.cpp | 1298 +++++++++++++++++++++++++------------------------ 2 files changed, 657 insertions(+), 642 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index e1cd4238..159d8d63 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1069,6 +1069,7 @@ public: cxxSurface mobile_surface_copy(cxxSurface *surface_old_ptr, int n_user_new, bool move_old); + void transport_cleanup(void); int init_mix(void); int init_heat_mix(int nmix); int heat_mix(int heat_nmix); diff --git a/transport.cpp b/transport.cpp index 50b91423..2932806e 100644 --- a/transport.cpp +++ b/transport.cpp @@ -132,323 +132,146 @@ transport(void) moles_added[i].moles = 0; } } - /* check solution 0 */ - use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, 0)); - if (!use.Get_solution_ptr()) + try { - if (ishift == 1) + /* check solution 0 */ + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, 0)); + if (!use.Get_solution_ptr()) { - input_error++; - error_string = sformatf( - "Solution 0 is needed for transport, but is not defined."); - error_msg(error_string, CONTINUE); - } - else - Utilities::Rxn_copy(Rxn_solution_map, 1, 0); - } - else - { - if ((cell_data[0].potV = use.Get_solution_ptr()->Get_potV())) - dV_dcell = 1; - } - - /* check solution count_cells */ - use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, count_cells + 1)); - if (!use.Get_solution_ptr()) - { - if (ishift == -1) - { - input_error++; - error_string = sformatf( - "Solution %d is needed for transport, but is not defined.", - count_cells + 1); - error_msg(error_string, CONTINUE); - } - else - Utilities::Rxn_copy(Rxn_solution_map, count_cells, count_cells + 1); - } - else - { - if ((cell_data[count_cells + 1].potV = use.Get_solution_ptr()->Get_potV())) - dV_dcell = 1; - } - /* - * Initialize temperature in stagnant cells ... - */ - for (n = 1; n <= stag_data->count_stag; n++) - { - for (i = 1; i <= count_cells; i++) - { - k = i + 1 + n * count_cells; - use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, k)); - if (use.Get_solution_ptr() != NULL) - cell_data[k].temp = use.Get_solution_ptr()->Get_tc(); - } - } - - if (fix_current && !dV_dcell) - { - warning_msg("fix_current (A) was defined, but potential in a boundary cell was not.\n\tUsing 1e-8 V in cell 0 for calculating the potentials."); - cell_data[0].potV = 1e-8; - dV_dcell = 1; - } - if (dV_dcell) - { - if (ishift) - { - input_error++; - error_string = sformatf( - "Electro-diffusion cannot be combined with advective transport."); - error_msg(error_string, CONTINUE); - free_check_null(sol_D); - } - if (!multi_Dflag) - { - input_error++; - error_string = sformatf( - "Electrical Field (potential) was defined, but needs -multi_D."); - error_msg(error_string, CONTINUE); - free_check_null(sol_D); - } - else - { - if (bcon_first != 1) + if (ishift == 1) { - bcon_first = 1; + input_error++; error_string = sformatf( - "Electrical Field (potential) was defined, assuming constant boundary condition for first cell."); - warning_msg(error_string); - } - if (bcon_last != 1) - { - bcon_last = 1; - error_string = sformatf( - "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); - warning_msg(error_string); - } - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) - (count_cells + 1) * sizeof(struct CURRENT_CELLS)); - if (current_cells == NULL) - malloc_error(); - for (int i = 0; i < count_cells + 1; i++) - { - current_cells[i].dif = 0.0; - current_cells[i].ele = 0.0; - current_cells[i].R = 0.0; + "Solution 0 is needed for transport, but is not defined."); + error_msg(error_string, CONTINUE); } + else + Utilities::Rxn_copy(Rxn_solution_map, 1, 0); } - } - /* - * First equilibrate solutions - */ - dup_print("Equilibrating initial solutions", TRUE); - transport_step = 0; - for (i = 0; i <= count_cells + 1; i++) - { - if ((bcon_first == 2 && i == 0) || - (bcon_last == 2 && i == count_cells + 1)) - continue; - set_initial_moles(i); - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_transport()) - transp_surf = TRUE; - if (transp_surf && !multi_Dflag) + else { - error_string = sformatf( - "-multi_d must be defined for surface transport"); - error_msg(error_string, CONTINUE); + if ((cell_data[0].potV = use.Get_solution_ptr()->Get_potV())) + dV_dcell = 1; } - if (multi_Dflag == TRUE) - { - fill_spec(cell_no); - } - if (cell_data[i].punch == TRUE) - punch_all(); - if (cell_data[i].print == TRUE) - print_all(); - /* if (i > 0 && i <= count_cells)*/ - saver(); - } - /* - * Also stagnant cells - */ - for (n = 1; n <= stag_data->count_stag; n++) - { - for (i = 1; i <= count_cells; i++) + /* check solution count_cells */ + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, count_cells + 1)); + if (!use.Get_solution_ptr()) { - k = i + 1 + n * count_cells; - cell_no = k; - if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) + if (ishift == -1) { - set_initial_moles(k); - set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); - if (multi_Dflag == TRUE) + input_error++; + error_string = sformatf( + "Solution %d is needed for transport, but is not defined.", + count_cells + 1); + error_msg(error_string, CONTINUE); + } + else + Utilities::Rxn_copy(Rxn_solution_map, count_cells, count_cells + 1); + } + else + { + if ((cell_data[count_cells + 1].potV = use.Get_solution_ptr()->Get_potV())) + dV_dcell = 1; + } + /* + * Initialize temperature in stagnant cells ... + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, k)); + if (use.Get_solution_ptr() != NULL) + cell_data[k].temp = use.Get_solution_ptr()->Get_tc(); + } + } + + if (fix_current && !dV_dcell) + { + warning_msg("fix_current (A) was defined, but potential in a boundary cell was not.\n\tUsing 1e-8 V in cell 0 for calculating the potentials."); + cell_data[0].potV = 1e-8; + dV_dcell = 1; + } + if (dV_dcell) + { + if (ishift) + { + input_error++; + error_string = sformatf( + "Electro-diffusion cannot be combined with advective transport."); + error_msg(error_string, CONTINUE); + free_check_null(sol_D); + } + if (!multi_Dflag) + { + input_error++; + error_string = sformatf( + "Electrical Field (potential) was defined, but needs -multi_D."); + error_msg(error_string, CONTINUE); + free_check_null(sol_D); + } + else + { + if (bcon_first != 1) { - fill_spec(cell_no); + bcon_first = 1; + error_string = sformatf( + "Electrical Field (potential) was defined, assuming constant boundary condition for first cell."); + warning_msg(error_string); + } + if (bcon_last != 1) + { + bcon_last = 1; + error_string = sformatf( + "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); + warning_msg(error_string); + } + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) + (count_cells + 1) * sizeof(struct CURRENT_CELLS)); + if (current_cells == NULL) + malloc_error(); + for (int i = 0; i < count_cells + 1; i++) + { + current_cells[i].dif = 0.0; + current_cells[i].ele = 0.0; + current_cells[i].R = 0.0; } - if (cell_data[k].punch == TRUE) - punch_all(); - if ((cell_data[k].print == TRUE) - && (transport_step % print_modulus == 0)) - print_all(); - saver(); } } - } - /* - * Initialize mixing factors, define kinetics times - * for multicomponent diffusion, limit mixing by diffc_max (usually from H+) - */ - if (multi_Dflag == TRUE) - diffc_tr = diffc_max; - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) - { - /* multi_D calc's are OK if all cells have the same amount of water */ - /* if (multi_Dflag == TRUE) - { - sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give all cells the same amount of water."); - warning_msg(token); - } - */ - - Rxn_mix_map.clear(); - /* - * stagnant mix factors go in mix[0 .. count_cells] - */ - } - /* - * mix[] is extended in init_mix(), to accommodate column mix factors - */ - nmix = init_mix(); - heat_nmix = init_heat_mix(nmix); - if (nmix < 2) - stagkin_time = timest; - else - stagkin_time = timest / nmix; - if (ishift != 0) - kin_time = timest / (1 + nmix); - else - kin_time = stagkin_time; - kin_time_save = kin_time; - - /* Reaction defined for a shift... */ - if (!ishift) - { - if (nmix < 2) - step_fraction = 1.0; - else - step_fraction = 1.0 / nmix; - } - else - step_fraction = 1.0 / (1.0 + nmix); - /* - * Set boundary conditions, transport direction - */ - last_model.force_prep = TRUE; - if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) - b_c = 1; - else - b_c = 0; - if (ishift >= 0) - { - last_c = count_cells; - first_c = 1; - } - else - { - last_c = 1; - first_c = count_cells; - } - /* - * Define stagnant/mobile mix structure, if not read explicitly. - * - * With count_stag = 1, mix factors are calculated from exchange factor alpha - * (= exch_f), mobile th_m and immobile th_im porosity. - * These variables are read under keyword TRANSPORT, after stagnant, in - * structure stag_data. - * MIX 'cell_no' in input file can be an alternative for the calculation here. - */ - if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) - { - b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); - f = exp(-stag_data->exch_f * stagkin_time / (b * stag_data->th_im)); - mix_f_imm = b - b * f; - mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; - for (j = 1; j <= count_cells; j++) - { - j_imm = j + (1 + count_cells); - if (Utilities::Rxn_find(Rxn_solution_map, j) == NULL) - error_msg - ("Could not find mobile cell solution in TRANSPORT.", - STOP); - if (Utilities::Rxn_find(Rxn_solution_map, j_imm) == NULL) - //error_msg - //("Could not find immobile cell solution in TRANSPORT.", - //STOP); - continue; - water_m = Utilities::Rxn_find(Rxn_solution_map, j)->Get_mass_water(); - water_imm = Utilities::Rxn_find(Rxn_solution_map, j_imm)->Get_mass_water(); - /* - * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 - */ - { - cxxMix temp_mix; - temp_mix.Set_n_user(j); - temp_mix.Set_n_user_end(j); - temp_mix.Add(j, 1 - mix_f_m); - temp_mix.Add(j_imm, mix_f_m * water_m / water_imm); - Rxn_mix_map[j] = temp_mix; - } - /* - * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... - */ - { - cxxMix temp_mix; - temp_mix.Set_n_user(j_imm); - temp_mix.Set_n_user_end(j_imm); - temp_mix.Add(j_imm, 1 - mix_f_imm); - temp_mix.Add(j, mix_f_imm * water_imm / water_m); - Rxn_mix_map[j_imm] = temp_mix; - } - } - - if (heat_nmix > 0) - { - /* - * Assumption: D_e used for calculating exch_f in input file equals diffc - */ - f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; - f = exp(-f * stagkin_time / (b * stag_data->th_im)); - heat_mix_f_imm = b - b * f; - heat_mix_f_m = - heat_mix_f_imm * stag_data->th_im / stag_data->th_m; - } - } - /* - * Stop if error - */ - if (get_input_errors() > 0) - { - error_msg("Program terminating due to input errors.", STOP); - } - /* - * Now transport - */ - max_iter = 0; - for (transport_step = transport_start; transport_step <= count_shifts; - transport_step++) - { - /* - * Set initial moles of phases + * First equilibrate solutions */ + dup_print("Equilibrating initial solutions", TRUE); + transport_step = 0; for (i = 0; i <= count_cells + 1; i++) { - if (!dV_dcell && (i == 0 || i == count_cells + 1)) + if ((bcon_first == 2 && i == 0) || + (bcon_last == 2 && i == count_cells + 1)) continue; set_initial_moles(i); + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (use.Get_surface_ptr() != NULL && use.Get_surface_ptr()->Get_transport()) + transp_surf = TRUE; + if (transp_surf && !multi_Dflag) + { + error_string = sformatf( + "-multi_d must be defined for surface transport"); + error_msg(error_string, CONTINUE); + } + if (multi_Dflag == TRUE) + { + fill_spec(cell_no); + } + if (cell_data[i].punch == TRUE) + punch_all(); + if (cell_data[i].print == TRUE) + print_all(); + + /* if (i > 0 && i <= count_cells)*/ + saver(); } /* * Also stagnant cells @@ -462,28 +285,499 @@ transport(void) if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) { set_initial_moles(k); + set_and_run_wrapper(k, NOMIX, FALSE, k, 0.0); + if (multi_Dflag == TRUE) + { + fill_spec(cell_no); + } + if (cell_data[k].punch == TRUE) + punch_all(); + if ((cell_data[k].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + saver(); } } } /* - * Start diffusing if boundary cond = 1, (fixed c, or closed) + * Initialize mixing factors, define kinetics times + * for multicomponent diffusion, limit mixing by diffc_max (usually from H+) */ - if (b_c == 1) + if (multi_Dflag == TRUE) + diffc_tr = diffc_max; + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) { - /* For half of mixing steps */ - for (j = 1; j <= floor((LDBLE)nmix / 2); j++) + /* multi_D calc's are OK if all cells have the same amount of water */ + /* if (multi_Dflag == TRUE) { - rate_sim_time_start = + sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give all cells the same amount of water."); + warning_msg(token); + } + */ + + Rxn_mix_map.clear(); + + /* + * stagnant mix factors go in mix[0 .. count_cells] + */ + } + /* + * mix[] is extended in init_mix(), to accommodate column mix factors + */ + nmix = init_mix(); + heat_nmix = init_heat_mix(nmix); + if (nmix < 2) + stagkin_time = timest; + else + stagkin_time = timest / nmix; + if (ishift != 0) + kin_time = timest / (1 + nmix); + else + kin_time = stagkin_time; + kin_time_save = kin_time; + + /* Reaction defined for a shift... */ + if (!ishift) + { + if (nmix < 2) + step_fraction = 1.0; + else + step_fraction = 1.0 / nmix; + } + else + step_fraction = 1.0 / (1.0 + nmix); + /* + * Set boundary conditions, transport direction + */ + last_model.force_prep = TRUE; + if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1)) + b_c = 1; + else + b_c = 0; + if (ishift >= 0) + { + last_c = count_cells; + first_c = 1; + } + else + { + last_c = 1; + first_c = count_cells; + } + /* + * Define stagnant/mobile mix structure, if not read explicitly. + * + * With count_stag = 1, mix factors are calculated from exchange factor alpha + * (= exch_f), mobile th_m and immobile th_im porosity. + * These variables are read under keyword TRANSPORT, after stagnant, in + * structure stag_data. + * MIX 'cell_no' in input file can be an alternative for the calculation here. + */ + if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1)) + { + b = stag_data->th_m / (stag_data->th_m + stag_data->th_im); + f = exp(-stag_data->exch_f * stagkin_time / (b * stag_data->th_im)); + mix_f_imm = b - b * f; + mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m; + for (j = 1; j <= count_cells; j++) + { + j_imm = j + (1 + count_cells); + if (Utilities::Rxn_find(Rxn_solution_map, j) == NULL) + error_msg + ("Could not find mobile cell solution in TRANSPORT.", + STOP); + if (Utilities::Rxn_find(Rxn_solution_map, j_imm) == NULL) + //error_msg + //("Could not find immobile cell solution in TRANSPORT.", + //STOP); + continue; + water_m = Utilities::Rxn_find(Rxn_solution_map, j)->Get_mass_water(); + water_imm = Utilities::Rxn_find(Rxn_solution_map, j_imm)->Get_mass_water(); + /* + * Define C_m = (1 - mix_f_m) * C_m0 + mix_f_m) * C_im0 + */ + { + cxxMix temp_mix; + temp_mix.Set_n_user(j); + temp_mix.Set_n_user_end(j); + temp_mix.Add(j, 1 - mix_f_m); + temp_mix.Add(j_imm, mix_f_m * water_m / water_imm); + Rxn_mix_map[j] = temp_mix; + } + /* + * Define C_im = mix_f_imm * C_m0 + (1 - mix_f_imm) * C_im0, or... + */ + { + cxxMix temp_mix; + temp_mix.Set_n_user(j_imm); + temp_mix.Set_n_user_end(j_imm); + temp_mix.Add(j_imm, 1 - mix_f_imm); + temp_mix.Add(j, mix_f_imm * water_imm / water_m); + Rxn_mix_map[j_imm] = temp_mix; + } + } + + if (heat_nmix > 0) + { + /* + * Assumption: D_e used for calculating exch_f in input file equals diffc + */ + f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr; + f = exp(-f * stagkin_time / (b * stag_data->th_im)); + heat_mix_f_imm = b - b * f; + heat_mix_f_m = + heat_mix_f_imm * stag_data->th_im / stag_data->th_m; + } + } + /* + * Stop if error + */ + if (get_input_errors() > 0) + { + error_msg("Program terminating due to input errors.", STOP); + } + /* + * Now transport + */ + max_iter = 0; + for (transport_step = transport_start; transport_step <= count_shifts; + transport_step++) + { + /* + * Set initial moles of phases + */ + for (i = 0; i <= count_cells + 1; i++) + { + if (!dV_dcell && (i == 0 || i == count_cells + 1)) + continue; + set_initial_moles(i); + } + /* + * Also stagnant cells + */ + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + cell_no = k; + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) + { + set_initial_moles(k); + } + } + } + /* + * Start diffusing if boundary cond = 1, (fixed c, or closed) + */ + if (b_c == 1) + { + /* For half of mixing steps */ + for (j = 1; j <= floor((LDBLE)nmix / 2); j++) + { + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * kin_time; + rate_sim_time = rate_sim_time_start + kin_time; + + mixrun = j; + if (multi_Dflag && j == floor((LDBLE)nmix / 2)) + { + //sprintf(token, + // "Transport step %3d. Multicomponent diffusion run %3d.", + // transport_step, j); + //dup_print(token, FALSE); + } + else if (!multi_Dflag) + { + sprintf(token, "Transport step %3d. Mixrun %3d.", + transport_step, j); + dup_print(token, FALSE); + } + + if (heat_nmix > 0) + { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i = 1; i <= count_cells; i++) + { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag) + fill_spec(i); + saver(); + } + } + /* Go through cells */ + if (transp_surf) + { + if (disp_surf(stagkin_time) == ERROR) + error_msg("Error in surface transport, stopping.", + STOP); + } + if (multi_Dflag) + multi_D(stagkin_time, 1, FALSE); + + for (i = 0; i <= count_cells + 1; i++) + { + if (!dV_dcell && (i == 0 || i == count_cells + 1)) + continue; + if (iterations > max_iter) + max_iter = iterations; + cell_no = i; + mixrun = j; + if (multi_Dflag) + sprintf(token, + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + else + sprintf(token, + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, j, i, max_iter); + status(0, token); + + if (i == 0 || i == count_cells + 1) + run_reactions(i, kin_time, NOMIX, step_fraction); + else + run_reactions(i, kin_time, DISP, step_fraction); + if (multi_Dflag) + fill_spec(i); + + /* punch and output file */ + if ((ishift == 0) && (j == nmix) + && ((stag_data->count_stag == 0) || i == 0 + || (i == count_cells + 1 && stag_data->count_stag != 1) /* + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0*/)) + { + if ((cell_data[i].punch == TRUE) + && (transport_step % punch_modulus == 0)) + punch_all(); + if ((cell_data[i].print == TRUE) + && (transport_step % print_modulus == 0)) + print_all(); + } + if (i > 1) + Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); + saver(); + + /* maybe sorb a surface component... */ + if ((ishift == 0) && (j == nmix) + && ((stag_data->count_stag == 0) + || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) + { + if (change_surf_count > 0) + { + for (k = 0; k < change_surf_count; k++) + { + if (change_surf[k].cell_no != i) + break; + reformat_surf(change_surf[k].comp_name, + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); + change_surf[k].cell_no = -99; + } + change_surf_count = 0; + } + } + } + + if (!dV_dcell) + Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); + /* Stagnant zone mixing after completion of each + diffusive/dispersive step ... */ + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * stagkin_time; + rate_sim_time = rate_sim_time_start + stagkin_time; + + if (stag_data->count_stag > 0) + { + if ((ishift == 0) && (j == nmix)) + punch_boolean = TRUE; + else + punch_boolean = FALSE; + for (i = 1; i <= count_cells; i++) + { + mix_stag(i, stagkin_time, punch_boolean, step_fraction); + } + // i == 1 + count_cells... + if (stag_data->count_stag == 1 && punch_boolean) + { + run_reactions(i, 0, NOMIX, 0); + cell_no = i; + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + punch_all(); + if (cell_data[i].print && (transport_step % print_modulus == 0)) + print_all(); + } + } + } + } + /* + * Advective transport + */ + if (ishift != 0) + { + sprintf(token, "Transport step %3d.", transport_step); + dup_print(token, FALSE); + if (b_c == 1) + rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * kin_time; + else + rate_sim_time_start = (transport_step - 1) * timest; rate_sim_time = rate_sim_time_start + kin_time; - mixrun = j; - if (multi_Dflag && j == floor((LDBLE)nmix / 2)) + /* halftime kinetics for resident water in first cell ... */ + if (Utilities::Rxn_find(Rxn_kinetics_map, first_c) != NULL && count_cells > 1) { - //sprintf(token, - // "Transport step %3d. Multicomponent diffusion run %3d.", - // transport_step, j); - //dup_print(token, FALSE); + cell_no = first_c; + kin_time = kin_time_save / 2; + run_reactions(first_c, kin_time, NOMIX, 0.0); + saver(); + kin_time = kin_time_save; + } + + /* for each cell in column */ + for (i = last_c; i != (first_c - ishift); i -= ishift) + Utilities::Rxn_copy(Rxn_solution_map, i - ishift, i); + + /* if boundary_solutions must be flushed by the flux from the column... + if (ishift == 1 && bcon_last == 3) + solution_duplicate (last_c, last_c + 1); + else if (ishift == -1 && bcon_first == 3) + solution_duplicate (last_c, last_c - 1); + */ + if (transp_surf) + { + for (i = last_c + ishift; i != (first_c - ishift); + i -= ishift) + { + if ((ishift == 1 && i == last_c + 1 && bcon_last != 3) || + (ishift == -1 && i == last_c - 1 && bcon_first != 3)) + continue; + cxxSurface * surface_ptr = Utilities::Rxn_find(Rxn_surface_map, i - ishift); + if (surface_ptr == NULL) + { + if ((Utilities::Rxn_find(Rxn_surface_map, i) != NULL) && + ((i == 0 && bcon_first == 3) + || (i == count_cells + 1 && bcon_last == 3))) + { + Rxn_surface_map.erase(i); + } + continue; + } + if (surface_ptr->Get_transport()) + { + cxxSurface * surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i); + if (surface_ptr1 == NULL) + { + cxxSurface surf; + surf.Set_n_user(i); + surf.Set_n_user_end(i); + Rxn_surface_map[i] = surf; + } + if (i == first_c) + { + Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, false); + } + else + { + Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, true); + } + } + } + } + + /* + * thermal diffusion when nmix = 0... + */ + if ((nmix == 0) && (heat_nmix > 0)) + { + heat_mix(heat_nmix); + /* equilibrate again ... */ + for (i = 1; i <= count_cells; i++) + { + cell_no = i; + set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); + if (multi_Dflag) + fill_spec(i); + saver(); + } + } + + for (i = 1; i <= count_cells; i++) + { + if (i == first_c && count_cells > 1) + kin_time /= 2; + cell_no = i; + mixrun = 0; + if (multi_Dflag) + sprintf(token, + "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); + else + sprintf(token, + "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", + transport_step, 0, i, max_iter); + status(0, token); + run_reactions(i, kin_time, NOMIX, step_fraction); + if (multi_Dflag == TRUE) + fill_spec(i); + if (iterations > max_iter) + max_iter = iterations; + if ((nmix == 0) && ((stag_data->count_stag == 0))) + { + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + punch_all(); + if (cell_data[i].print && (transport_step % print_modulus == 0)) + print_all(); + } + if (i == first_c && count_cells > 1) + kin_time = kin_time_save; + saver(); + + /* maybe sorb a surface component... */ + if ((nmix == 0) && ((stag_data->count_stag == 0) || + (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) + { + if (change_surf_count > 0) + { + for (k = 0; k < change_surf_count; k++) + { + if (change_surf[k].cell_no != i) + break; + reformat_surf(change_surf[k].comp_name, + change_surf[k].fraction, + change_surf[k].new_comp_name, + change_surf[k].new_Dw, + change_surf[k].cell_no); + change_surf[k].cell_no = -99; + } + change_surf_count = 0; + } + } + + /* If nmix is zero, stagnant zone mixing after + advective step ... */ + if ((nmix == 0) && (stag_data->count_stag > 0)) + { + mix_stag(i, stagkin_time, TRUE, step_fraction); + } + } + } + /* + * Further dispersive and diffusive transport + */ + if (b_c != 1) + j = 1; + for (j = j; j <= nmix; j++) + { + if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0)) + { + sprintf(token, + "Transport step %3d. Multicomponent diffusion run %3d.", + transport_step, j); + dup_print(token, FALSE); } else if (!multi_Dflag) { @@ -491,6 +785,11 @@ transport(void) transport_step, j); dup_print(token, FALSE); } + rate_sim_time_start = + (transport_step - 1) * timest + (j - 1) * kin_time; + if (ishift != 0) + rate_sim_time_start += kin_time; + rate_sim_time = rate_sim_time_start + kin_time; if (heat_nmix > 0) { @@ -505,16 +804,16 @@ transport(void) saver(); } } - /* Go through cells */ if (transp_surf) { if (disp_surf(stagkin_time) == ERROR) - error_msg("Error in surface transport, stopping.", - STOP); + error_msg("Error in surface transport, stopping.", STOP); } - if (multi_Dflag) + + if (multi_Dflag == TRUE) multi_D(stagkin_time, 1, FALSE); + /* for each cell in column */ for (i = 0; i <= count_cells + 1; i++) { if (!dV_dcell && (i == 0 || i == count_cells + 1)) @@ -537,20 +836,14 @@ transport(void) run_reactions(i, kin_time, NOMIX, step_fraction); else run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag) + if (multi_Dflag == TRUE) fill_spec(i); - - /* punch and output file */ - if ((ishift == 0) && (j == nmix) - && ((stag_data->count_stag == 0) || i == 0 - || (i == count_cells + 1 && stag_data->count_stag != 1) /* - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0*/)) + if (j == nmix && (stag_data->count_stag == 0 || i == 0 + || (i == 1 + count_cells && stag_data->count_stag != 1))) { - if ((cell_data[i].punch == TRUE) - && (transport_step % punch_modulus == 0)) + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) punch_all(); - if ((cell_data[i].print == TRUE) - && (transport_step % print_modulus == 0)) + if (cell_data[i].print && (transport_step % print_modulus == 0)) print_all(); } if (i > 1) @@ -558,9 +851,8 @@ transport(void) saver(); /* maybe sorb a surface component... */ - if ((ishift == 0) && (j == nmix) - && ((stag_data->count_stag == 0) - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) + if ((j == nmix) && ((stag_data->count_stag == 0) + || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) { @@ -579,18 +871,17 @@ transport(void) } } } - if (!dV_dcell) Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ + diffusive/dispersive step ... */ rate_sim_time_start = (transport_step - 1) * timest + (j - 1) * stagkin_time; rate_sim_time = rate_sim_time_start + stagkin_time; if (stag_data->count_stag > 0) { - if ((ishift == 0) && (j == nmix)) + if (j == nmix) punch_boolean = TRUE; else punch_boolean = FALSE; @@ -598,329 +889,58 @@ transport(void) { mix_stag(i, stagkin_time, punch_boolean, step_fraction); } - // i == 1 + count_cells... - if (stag_data->count_stag == 1 && punch_boolean) - { - run_reactions(i, 0, NOMIX, 0); - cell_no = i; - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } } - } - } - /* - * Advective transport - */ - if (ishift != 0) - { - sprintf(token, "Transport step %3d.", transport_step); - dup_print(token, FALSE); - if (b_c == 1) - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; - else - rate_sim_time_start = (transport_step - 1) * timest; - rate_sim_time = rate_sim_time_start + kin_time; - - /* halftime kinetics for resident water in first cell ... */ - if (Utilities::Rxn_find(Rxn_kinetics_map, first_c) != NULL && count_cells > 1) - { - cell_no = first_c; - kin_time = kin_time_save / 2; - run_reactions(first_c, kin_time, NOMIX, 0.0); - saver(); - kin_time = kin_time_save; - } - - /* for each cell in column */ - for (i = last_c; i != (first_c - ishift); i -= ishift) - Utilities::Rxn_copy(Rxn_solution_map, i - ishift, i); - - /* if boundary_solutions must be flushed by the flux from the column... - if (ishift == 1 && bcon_last == 3) - solution_duplicate (last_c, last_c + 1); - else if (ishift == -1 && bcon_first == 3) - solution_duplicate (last_c, last_c - 1); - */ - if (transp_surf) - { - for (i = last_c + ishift; i != (first_c - ishift); - i -= ishift) - { - if ((ishift == 1 && i == last_c + 1 && bcon_last != 3) || - (ishift == -1 && i == last_c - 1 && bcon_first != 3)) - continue; - cxxSurface * surface_ptr = Utilities::Rxn_find(Rxn_surface_map, i - ishift); - if (surface_ptr == NULL) - { - if ((Utilities::Rxn_find(Rxn_surface_map, i) != NULL) && - ((i == 0 && bcon_first == 3) - || (i == count_cells + 1 && bcon_last == 3))) - { - Rxn_surface_map.erase(i); - } - continue; - } - if (surface_ptr->Get_transport()) - { - cxxSurface * surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i); - if (surface_ptr1 == NULL) - { - cxxSurface surf; - surf.Set_n_user(i); - surf.Set_n_user_end(i); - Rxn_surface_map[i] = surf; - } - if (i == first_c) - { - Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, false); - } - else - { - Rxn_surface_map[i] = mobile_surface_copy(surface_ptr, i, true); - } - } - } - } - - /* - * thermal diffusion when nmix = 0... - */ - if ((nmix == 0) && (heat_nmix > 0)) - { - heat_mix(heat_nmix); - /* equilibrate again ... */ - for (i = 1; i <= count_cells; i++) + // i == 1 + count_cells... + if (stag_data->count_stag == 1 && punch_boolean) { + run_reactions(i, 0, NOMIX, 0); cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - if (multi_Dflag) - fill_spec(i); - saver(); - } - } - - for (i = 1; i <= count_cells; i++) - { - if (i == first_c && count_cells > 1) - kin_time /= 2; - cell_no = i; - mixrun = 0; - if (multi_Dflag) - sprintf(token, - "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, 0, i, max_iter); - else - sprintf(token, - "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, 0, i, max_iter); - status(0, token); - run_reactions(i, kin_time, NOMIX, step_fraction); - if (multi_Dflag == TRUE) - fill_spec(i); - if (iterations > max_iter) - max_iter = iterations; - if ((nmix == 0) && ((stag_data->count_stag == 0))) - { if (cell_data[i].punch && (transport_step % punch_modulus == 0)) punch_all(); if (cell_data[i].print && (transport_step % print_modulus == 0)) print_all(); } - if (i == first_c && count_cells > 1) - kin_time = kin_time_save; - saver(); - - /* maybe sorb a surface component... */ - if ((nmix == 0) && ((stag_data->count_stag == 0) || - (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) - { - if (change_surf_count > 0) - { - for (k = 0; k < change_surf_count; k++) - { - if (change_surf[k].cell_no != i) - break; - reformat_surf(change_surf[k].comp_name, - change_surf[k].fraction, - change_surf[k].new_comp_name, - change_surf[k].new_Dw, - change_surf[k].cell_no); - change_surf[k].cell_no = -99; - } - change_surf_count = 0; - } - } - - /* If nmix is zero, stagnant zone mixing after - advective step ... */ - if ((nmix == 0) && (stag_data->count_stag > 0)) - { - mix_stag(i, stagkin_time, TRUE, step_fraction); - } } + if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) + dump(); } - /* - * Further dispersive and diffusive transport - */ - if (b_c != 1) - j = 1; - for (j = j; j <= nmix; j++) + screen_msg("\n"); + + if (multi_Dflag && moles_added[0].moles > 0) { - if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0)) - { - sprintf(token, - "Transport step %3d. Multicomponent diffusion run %3d.", - transport_step, j); - dup_print(token, FALSE); - } - else if (!multi_Dflag) - { - sprintf(token, "Transport step %3d. Mixrun %3d.", - transport_step, j); - dup_print(token, FALSE); - } - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; - if (ishift != 0) - rate_sim_time_start += kin_time; - rate_sim_time = rate_sim_time_start + kin_time; - - if (heat_nmix > 0) - { - heat_mix(heat_nmix); - /* equilibrate again ... */ - for (i = 1; i <= count_cells; i++) - { - cell_no = i; - set_and_run_wrapper(i, NOMIX, FALSE, i, 0.0); - if (multi_Dflag) - fill_spec(i); - saver(); - } - } - if (transp_surf) - { - if (disp_surf(stagkin_time) == ERROR) - error_msg("Error in surface transport, stopping.", STOP); - } - - if (multi_Dflag == TRUE) - multi_D(stagkin_time, 1, FALSE); - - /* for each cell in column */ - for (i = 0; i <= count_cells + 1; i++) - { - if (!dV_dcell && (i == 0 || i == count_cells + 1)) - continue; - if (iterations > max_iter) - max_iter = iterations; - cell_no = i; - mixrun = j; - if (multi_Dflag) - sprintf(token, - "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); - else - sprintf(token, - "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", - transport_step, j, i, max_iter); - status(0, token); - - if (i == 0 || i == count_cells + 1) - run_reactions(i, kin_time, NOMIX, step_fraction); - else - run_reactions(i, kin_time, DISP, step_fraction); - if (multi_Dflag == TRUE) - fill_spec(i); - if (j == nmix && (stag_data->count_stag == 0 || i == 0 - || (i == 1 + count_cells && stag_data->count_stag != 1))) - { - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } - if (i > 1) - Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); - saver(); - - /* maybe sorb a surface component... */ - if ((j == nmix) && ((stag_data->count_stag == 0) - || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) - { - if (change_surf_count > 0) - { - for (k = 0; k < change_surf_count; k++) - { - if (change_surf[k].cell_no != i) - break; - reformat_surf(change_surf[k].comp_name, - change_surf[k].fraction, - change_surf[k].new_comp_name, - change_surf[k].new_Dw, - change_surf[k].cell_no); - change_surf[k].cell_no = -99; - } - change_surf_count = 0; - } - } - } - if (!dV_dcell) - Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); - /* Stagnant zone mixing after completion of each - diffusive/dispersive step ... */ - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * stagkin_time; - rate_sim_time = rate_sim_time_start + stagkin_time; - - if (stag_data->count_stag > 0) - { - if (j == nmix) - punch_boolean = TRUE; - else - punch_boolean = FALSE; - for (i = 1; i <= count_cells; i++) - { - mix_stag(i, stagkin_time, punch_boolean, step_fraction); - } - } - // i == 1 + count_cells... - if (stag_data->count_stag == 1 && punch_boolean) - { - run_reactions(i, 0, NOMIX, 0); - cell_no = i; - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } - } - if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) - dump(); - } - screen_msg("\n"); - - if (multi_Dflag && moles_added[0].moles > 0) - { - sprintf(token, - "\nFor balancing negative concentrations in MCD, added in total to the system:"); - if (phrq_io) - phrq_io->warning_msg(token); - for (i = 0; i < count_elements; i++) - { - if (!moles_added[i].moles) - break; sprintf(token, - "\t %.4e moles %s.", - (double)moles_added[i].moles, moles_added[i].name); + "\nFor balancing negative concentrations in MCD, added in total to the system:"); if (phrq_io) phrq_io->warning_msg(token); + for (i = 0; i < count_elements; i++) + { + if (!moles_added[i].moles) + break; + sprintf(token, + "\t %.4e moles %s.", + (double)moles_added[i].moles, moles_added[i].name); + if (phrq_io) + phrq_io->warning_msg(token); + } } } + catch (...) + { + transport_cleanup(); + throw; + } + transport_cleanup(); + initial_total_time += rate_sim_time; + rate_sim_time = 0; + mass_water_switch = FALSE; + return (OK); +} +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +transport_cleanup(void) +/* ---------------------------------------------------------------------- */ +{ + int i; /* * free mix structures */ @@ -957,13 +977,7 @@ transport(void) } moles_added = (struct MOLES_ADDED *) free_check_null(moles_added); } - //if (dV_dcell) - free_check_null(current_cells); - - initial_total_time += rate_sim_time; - rate_sim_time = 0; - mass_water_switch = FALSE; - return (OK); + current_cells = (struct CURRENT_CELLS *) free_check_null(current_cells); } /* ---------------------------------------------------------------------- */ int Phreeqc:: From 9d2762b15e8b7bfd5cacae1548be4e22b8ca40f9 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Feb 2017 00:14:46 +0000 Subject: [PATCH 1042/1077] Merge to trunk 12441. if def comment about Ampere git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12444 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- class_main.cpp | 2 ++ print.cpp | 7 +++++++ structures.cpp | 6 ++++++ transport.cpp | 10 ++++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/class_main.cpp b/class_main.cpp index 9956308e..8fa49a4d 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -495,7 +495,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); +#ifdef NPP output_msg(sformatf("Using PHREEQC: version 3.3.9 Ampère, compiled November 23, 2016\n")); +#endif output_msg(sformatf("Database file: %s\n\n", token)); #ifdef NPP output_flush(); diff --git a/print.cpp b/print.cpp index 6aed9f45..9aaaa181 100644 --- a/print.cpp +++ b/print.cpp @@ -482,6 +482,13 @@ print_exchange(void) output_msg(sformatf("%-14s%12.3e mol", name, (double) master_ptr->unknown->moles)); cxxExchange *exchange_ptr = (cxxExchange *) (use.Get_exchange_ptr()); + if (master_ptr->unknown->exch_comp == NULL) + { + error_string = sformatf("Exchange unknown has no exchange component for exchanger %s." + "\nIs the same name used for a SURFACE and an EXCHANGER?", + master_ptr->unknown->description); + error_msg(error_string, STOP); + } const cxxExchComp *exchange_comp_ptr = exchange_ptr->Find_comp(master_ptr->unknown->exch_comp); assert(exchange_comp_ptr); if (exchange_comp_ptr->Get_phase_name().size() > 0) diff --git a/structures.cpp b/structures.cpp index a3e837c0..0afa8da1 100644 --- a/structures.cpp +++ b/structures.cpp @@ -3191,6 +3191,7 @@ unknown_alloc(void) unknown_ptr->si = 0.0; unknown_ptr->s = NULL; unknown_ptr->exch_comp = NULL; + unknown_ptr->pp_assemblage_comp_name = NULL; unknown_ptr->pp_assemblage_comp_ptr = NULL; unknown_ptr->ss_name = NULL; unknown_ptr->ss_ptr = NULL; @@ -3209,6 +3210,11 @@ unknown_alloc(void) unknown_ptr->surface_charge = NULL; unknown_ptr->mass_water = 0.0; unknown_ptr->dissolve_only = FALSE; + unknown_ptr->inert_moles = 0.0; + unknown_ptr->V_m = 0.0; + unknown_ptr->pressure = 0.0; + unknown_ptr->mb_number = 0; + unknown_ptr->iteration = 0; return (unknown_ptr); } diff --git a/transport.cpp b/transport.cpp index 2932806e..51248972 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" @@ -2074,6 +2074,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } + if (ct[icell].J_ij == NULL) + { + error_string = sformatf( "Null pointer for fill_m_s.\n" + "Consider using more substeps in TRANSPORT; -time_step."); + error_msg(error_string, STOP); + } fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); /* @@ -4731,7 +4737,7 @@ viscosity(void) Jones_Dole[6] contains the anion factor, 1 for Cl-, variable for other anions f_z = (z * z + |z|) / 2, the contribution of the ion to mu_x, if z = 0: f_z = mu_x / m_i f_I = variable, depends on d3_i > 1, or d3_i < 1. - tc is limited to 200°C. + tc is limited to 200°C. A from Falkenhagen-Dole for a salt: From 62286ff4a73d12ddd3d46959e6cbf91464f66875 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Feb 2017 19:45:26 +0000 Subject: [PATCH 1043/1077] Commented out check for null. Not sure how it works for Clogging, will investigate on Linux. Checking in new SC values! git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12447 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/transport.cpp b/transport.cpp index 51248972..3a8bf779 100644 --- a/transport.cpp +++ b/transport.cpp @@ -2074,12 +2074,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } - if (ct[icell].J_ij == NULL) - { - error_string = sformatf( "Null pointer for fill_m_s.\n" - "Consider using more substeps in TRANSPORT; -time_step."); - error_msg(error_string, STOP); - } + //if (ct[icell].J_ij == NULL) + //{ + // error_string = sformatf( "Null pointer for fill_m_s.\n" + // "Consider using more substeps in TRANSPORT; -time_step."); + // error_msg(error_string, STOP); + //} fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); /* From 4df098a2304b23ecef53daedc26a363483830617 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Feb 2017 20:04:43 +0000 Subject: [PATCH 1044/1077] comment check for null after find_J. Don't know how it works. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12449 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/transport.cpp b/transport.cpp index bad92a91..40db26ae 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1712,12 +1712,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } - if (J_ij == NULL) - { - error_string = sformatf( "Null pointer for fill_m_s.\n" - "Consider using more substeps in TRANSPORT; -time_step."); - error_msg(error_string, STOP); - } + //if (J_ij == NULL) + //{ + // error_string = sformatf( "Null pointer for fill_m_s.\n" + // "Consider using more substeps in TRANSPORT; -time_step."); + // error_msg(error_string, STOP); + //} fill_m_s(J_ij, J_ij_count_spec); /* From 63ac5f3c97d2d68d6b1bbb48bbe4cb8d6c7c419a Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 17 Feb 2017 22:06:23 +0000 Subject: [PATCH 1045/1077] Fixed null check, also needs elements > 0. Added more test files that were missing. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12452 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/transport.cpp b/transport.cpp index 3a8bf779..d4ec7353 100644 --- a/transport.cpp +++ b/transport.cpp @@ -2074,12 +2074,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } - //if (ct[icell].J_ij == NULL) - //{ - // error_string = sformatf( "Null pointer for fill_m_s.\n" - // "Consider using more substeps in TRANSPORT; -time_step."); - // error_msg(error_string, STOP); - //} + if (ct[icell].J_ij == NULL && ct[icell].J_ij_count_spec > 0) + { + error_string = sformatf( "Null pointer for fill_m_s.\n" + "Consider using more substeps in TRANSPORT; -time_step."); + error_msg(error_string, STOP); + } fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); /* From a15efe539e1ac0363619efa6b6afc5a16850f340 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Feb 2017 18:17:22 +0000 Subject: [PATCH 1046/1077] Minor updates to databases. Tony fixed potential null pointer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12461 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/transport.cpp b/transport.cpp index d4ec7353..788a66a1 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" @@ -2074,12 +2074,6 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } - if (ct[icell].J_ij == NULL && ct[icell].J_ij_count_spec > 0) - { - error_string = sformatf( "Null pointer for fill_m_s.\n" - "Consider using more substeps in TRANSPORT; -time_step."); - error_msg(error_string, STOP); - } fill_m_s(ct[icell].J_ij, ct[icell].J_ij_count_spec); /* @@ -2384,6 +2378,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) goto dV_dcell2; /* check for immediate return and interlayer diffusion calcs... */ + ct[icell].J_ij_sum = 0.0; + ct[icell].J_ij_count_spec = 0; if (!il_calcs) { if (stagnant) @@ -2674,8 +2670,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } /* diffuse... */ - ct[icell].J_ij_sum = 0.0; - ct[icell].J_ij_count_spec = 0; /* * malloc sufficient space... */ @@ -4737,7 +4731,7 @@ viscosity(void) Jones_Dole[6] contains the anion factor, 1 for Cl-, variable for other anions f_z = (z * z + |z|) / 2, the contribution of the ion to mu_x, if z = 0: f_z = mu_x / m_i f_I = variable, depends on d3_i > 1, or d3_i < 1. - tc is limited to 200°C. + tc is limited to 200°C. A from Falkenhagen-Dole for a salt: From 739dfeb915b3f284a26be21ceb72f85d45fdee64 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 23 Feb 2017 18:25:51 +0000 Subject: [PATCH 1047/1077] Tony's fix for potential null pointer. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12462 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- transport.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/transport.cpp b/transport.cpp index 40db26ae..8ea5616d 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1712,12 +1712,6 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } count_m_s = 0; } - //if (J_ij == NULL) - //{ - // error_string = sformatf( "Null pointer for fill_m_s.\n" - // "Consider using more substeps in TRANSPORT; -time_step."); - // error_msg(error_string, STOP); - //} fill_m_s(J_ij, J_ij_count_spec); /* @@ -2009,6 +2003,8 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) V_M = V_M_il = NULL; /* check for immediate return and interlayer diffusion calcs... */ + J_ij_count_spec = 0; + J_ij_sum = 0.0; if (interlayer_Dflag) { il_calcs = 1; @@ -2323,8 +2319,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } /* diffuse... */ - J_ij_count_spec = 0; - J_ij_sum = 0.0; /* * malloc sufficient space... */ From b121ec3bfeb39f3e4d24fc9e31c2159295f6c4de Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 28 Feb 2017 21:52:19 +0000 Subject: [PATCH 1048/1077] Added tests for PR calculations with water ex7_T_P pr_h2o. Added to Makefile Tony's change to prep.cpp to keep phi(H2O) in a good range. Changes to allow Jonathon Toner to define A(phi). git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12464 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 9 ++++++++- PBasic.h | 3 ++- Phreeqc.cpp | 1 + Phreeqc.h | 1 + global_structures.h | 7 ++++--- pitzer.cpp | 28 +++++++++++++++++++++++++--- pitzer_structures.cpp | 2 +- prep.cpp | 19 ++++++++++--------- sit.cpp | 1 + utilities.cpp | 5 +++++ 10 files changed, 58 insertions(+), 18 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 87408956..2df8d00c 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1590,6 +1590,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokphase_vm: output_msg("PHASE_VM"); // mole volume of a phase break; + case tokaphi: + output_msg("APHI"); // mole volume of a phase + break; case tokdh_a: output_msg("DH_A"); // Debye-Hueckel A break; @@ -3611,6 +3614,9 @@ factor(struct LOC_exec * LINK) case tokeps_r: n.UU.val = PhreeqcPtr->eps_r; break; + case tokaphi: + n.UU.val = PhreeqcPtr->A0; + break; case tokdh_a: n.UU.val = PhreeqcPtr->DH_A; break; @@ -7247,7 +7253,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("rho_0", PBasic::tokrho_0), std::map::value_type("kinetics_formula", PBasic::tokkinetics_formula), std::map::value_type("kinetics_formula$", PBasic::tokkinetics_formula), - std::map::value_type("phase_vm", PBasic::tokphase_vm) + std::map::value_type("phase_vm", PBasic::tokphase_vm), + std::map::value_type("aphi", PBasic::tokaphi) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 50fec31d..ee423841 100644 --- a/PBasic.h +++ b/PBasic.h @@ -328,7 +328,8 @@ public: tokdiff_c, toksa_declercq, tokedl_species, - tokphase_vm + tokphase_vm, + tokaphi }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index adfdd5fc..af6ab18f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1018,6 +1018,7 @@ void Phreeqc::init(void) OTEMP = -100.; OPRESS = -100.; A0 = 0; + aphi = NULL; spec = NULL; cations = NULL; anions = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 7ef7d7f2..c1b94ab7 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1874,6 +1874,7 @@ protected: int use_etheta; LDBLE OTEMP, OPRESS; LDBLE A0; + struct pitz_param *aphi; struct species **spec, **cations, **anions, **neutrals; int count_cations, count_anions, count_neutrals; int MAXCATIONS, FIRSTANION, MAXNEUTRAL; diff --git a/global_structures.h b/global_structures.h index cc28ec66..0883be7f 100644 --- a/global_structures.h +++ b/global_structures.h @@ -1049,7 +1049,7 @@ struct M_S typedef enum { TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, TYPE_PSI, TYPE_ETHETA, TYPE_ALPHAS, TYPE_MU, TYPE_ETA, TYPE_Other, - TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU + TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU, TYPE_APHI } pitz_param_type; struct pitz_param @@ -1071,8 +1071,9 @@ struct pitz_param LDBLE alphas; LDBLE mu; LDBLE eta; - LDBLE eps; - LDBLE eps1; + LDBLE eps; + LDBLE eps1; + LDBLE aphi; } U; LDBLE a[6]; LDBLE alpha; diff --git a/pitzer.cpp b/pitzer.cpp index 006f4d69..546b3cd4 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -634,9 +634,10 @@ read_pitzer(void) "eta", /* 15 */ "etheta", /* 16 */ "use_etheta", /* 17 */ - "lambda" /* 18 */ + "lambda", /* 18 */ + "aphi" /* 19 */ }; - int count_opt_list = 19; + int count_opt_list = 20; /* * Read lines */ @@ -664,7 +665,15 @@ read_pitzer(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - pitz_param_store(pzp_ptr, false); + if (pzp_type == TYPE_APHI) + { + aphi = (struct pitz_param *) free_check_null(aphi); + aphi = pzp_ptr; + } + else + { + pitz_param_store(pzp_ptr, false); + } } break; case OPTION_ERROR: @@ -744,6 +753,11 @@ read_pitzer(void) opt_save = OPTION_ERROR; use_etheta = get_true_false(next_char, TRUE); break; + case 19: /* aphi */ + pzp_type = TYPE_APHI; + n = 0; + opt_save = OPTION_DEFAULT; + break; } if (return_value == EOF || return_value == KEYWORD) break; @@ -780,6 +794,10 @@ C int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } + if (aphi) + { + calc_pitz_param(aphi, TK, TR); + } if (mcb0) { calc_pitz_param(mcb0, TK, TR); @@ -857,6 +875,9 @@ calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) case TYPE_ETA: pz_ptr->U.eta = param; break; + case TYPE_APHI: + pz_ptr->U.aphi = param; + break; case TYPE_Other: default: error_msg("Should not be TYPE_Other in function calc_pitz_param", @@ -1668,6 +1689,7 @@ pitzer_clean_up(void) LGAMMA = (LDBLE *) free_check_null(LGAMMA); IPRSNT = (int *) free_check_null(IPRSNT); spec = (struct species **) free_check_null(spec); + aphi = (struct pitz_param *) free_check_null(aphi); M = (LDBLE *) free_check_null(M); return OK; diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 245a1871..061eb715 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -72,7 +72,7 @@ pitz_param_read(char *string, int n) char token[2 * MAX_LENGTH]; struct pitz_param pzp, *pzp_ptr; - if (n != 2 && n != 3) + if (n != 2 && n != 3 && n != 0) return (NULL); if (string == NULL) return (NULL); diff --git a/prep.cpp b/prep.cpp index b94dcf98..e9fa0ef6 100644 --- a/prep.cpp +++ b/prep.cpp @@ -3727,7 +3727,7 @@ setup_surface(void) * check related kinetics */ if (use.Get_surface_ptr()->Get_related_rate()) - { + { cxxKinetics *kinetics_ptr = Utilities::Rxn_find(Rxn_kinetics_map, use.Get_n_surface_user()); for (size_t i = 0; i < use.Get_surface_ptr()->Get_surface_comps().size(); i++) { @@ -4099,7 +4099,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) P = 1.; } else { - if (P < 1e-10) P = 1e-10; + if (P < 1e-10) + P = 1e-10; r3[1] = b_sum - R_TK / P; r3_12 = r3[1] * r3[1]; r3[2] = -3.0 * b2 + (a_aa_sum - R_TK * 2.0 * b_sum) / P; @@ -4142,11 +4143,6 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) continue; } phase_ptr->pr_p = phase_ptr->fraction_x * P; - //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - //{ - // phase_ptr->pr_phi = 1; - // continue; - //} rz = P * V_m / R_TK; A = a_aa_sum * P / (R_TK * R_TK); B = b_sum * P / R_TK; @@ -4154,12 +4150,17 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) if (rz > B) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * - log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); if (phi > 4.44) phi = 4.44; } else phi = -3.0; // fugacity coefficient > 0.05 + if (/*!strcmp(phase_ptr->name, "H2O(g)") && */phi < -3) + { + // avoid such phi... + phi = -3; + } phase_ptr->pr_phi = exp(phi); phase_ptr->pr_si_f = phi / LOG_10; // for initial equilibrations, adapt log_k of the gas phase... @@ -6150,7 +6151,7 @@ check_same_model(void) surf_ptr->Set_new_def(true); this->tidy_min_surface(); return (FALSE); - } + } } if (use.Get_surface_ptr()->Get_surface_comps()[i].Get_rate_name().size() > 0) { diff --git a/sit.cpp b/sit.cpp index d84186b2..848b2e2c 100644 --- a/sit.cpp +++ b/sit.cpp @@ -697,6 +697,7 @@ sit_clean_up(void) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); spec = (struct species **) free_check_null(spec); + aphi = (struct pitz_param *) free_check_null(aphi); sit_M = (LDBLE *) free_check_null(sit_M); return OK; diff --git a/utilities.cpp b/utilities.cpp index 13b703c5..22b45a0a 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -255,6 +255,11 @@ calc_dielectrics(LDBLE tc, LDBLE pa) if (pitzer_model || sit_model) { A0 = DH_B * e2_DkT / 6.0; + if (pitzer_model && aphi != NULL) + { + calc_pitz_param(aphi, T, 298.15); + A0 = aphi->p; + } } /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ From 6a6e07e0737c6d45869e1fe6472069d7051e574b Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Mar 2017 16:14:08 +0000 Subject: [PATCH 1049/1077] Tony's tweak. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12475 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- gases.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gases.cpp b/gases.cpp index 871d41a9..7b60f76c 100644 --- a/gases.cpp +++ b/gases.cpp @@ -588,9 +588,8 @@ calc_PR(void) if (rz > B) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * - log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); - if (phi > 4.44) - phi = 4.44; + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); } else phi = -3.0; // fugacity coefficient > 0.05 From 8421d08ecac4ee1663da1d88565f6dd0055d9134 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 1 Mar 2017 21:27:37 +0000 Subject: [PATCH 1050/1077] Updated to phreeqc3-trunk 21475 Adds some pr h2o tests. Adds Aphi calculation for Jonathon Toner Latest Tony tweak on PR. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12476 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 9 ++++++++- PBasic.h | 4 +++- Phreeqc.cpp | 1 + Phreeqc.h | 1 + gases.cpp | 5 ++--- global_structures.h | 7 ++++--- pitzer.cpp | 28 +++++++++++++++++++++++++--- pitzer_structures.cpp | 2 +- prep.cpp | 12 ++++++------ sit.cpp | 1 + transport.cpp | 6 +++--- utilities.cpp | 5 +++++ 12 files changed, 60 insertions(+), 21 deletions(-) diff --git a/PBasic.cpp b/PBasic.cpp index 96fa49ae..92283cfb 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1590,6 +1590,9 @@ listtokens(FILE * f, tokenrec * l_buf) case tokphase_vm: output_msg("PHASE_VM"); // mole volume of a phase break; + case tokaphi: + output_msg("APHI"); // mole volume of a phase + break; case tokdh_a: output_msg("DH_A"); // Debye-Hueckel A break; @@ -3629,6 +3632,9 @@ factor(struct LOC_exec * LINK) case tokeps_r: n.UU.val = PhreeqcPtr->eps_r; break; + case tokaphi: + n.UU.val = PhreeqcPtr->A0; + break; case tokdh_a: n.UU.val = PhreeqcPtr->DH_A; break; @@ -7312,7 +7318,8 @@ const std::map::value_type temp_tokens[] std::map::value_type("current_a", PBasic::tokcurrent_a), std::map::value_type("pot_v", PBasic::tokpot_v), std::map::value_type("t_sc", PBasic::tokt_sc), - std::map::value_type("setdiff_c", PBasic::toksetdiff_c) + std::map::value_type("setdiff_c", PBasic::toksetdiff_c), + std::map::value_type("aphi", PBasic::tokaphi) }; std::map PBasic::command_tokens(temp_tokens, temp_tokens + sizeof temp_tokens / sizeof temp_tokens[0]); diff --git a/PBasic.h b/PBasic.h index 30195c05..34b604f1 100644 --- a/PBasic.h +++ b/PBasic.h @@ -334,7 +334,9 @@ public: tokviscos_0, tokcurrent_a, tokpot_v, - tokt_sc + tokt_sc, + tokphase_vm, + tokaphi }; #if !defined(PHREEQCI_GUI) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 77d28fa0..9a3de8bb 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1029,6 +1029,7 @@ void Phreeqc::init(void) OTEMP = -100.; OPRESS = -100.; A0 = 0; + aphi = NULL; spec = NULL; cations = NULL; anions = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 159d8d63..f8d9f3d7 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1886,6 +1886,7 @@ protected: int use_etheta; LDBLE OTEMP, OPRESS; LDBLE A0; + struct pitz_param *aphi; struct species **spec, **cations, **anions, **neutrals; int count_cations, count_anions, count_neutrals; int MAXCATIONS, FIRSTANION, MAXNEUTRAL; diff --git a/gases.cpp b/gases.cpp index 871d41a9..7b60f76c 100644 --- a/gases.cpp +++ b/gases.cpp @@ -588,9 +588,8 @@ calc_PR(void) if (rz > B) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * - log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); - if (phi > 4.44) - phi = 4.44; + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); } else phi = -3.0; // fugacity coefficient > 0.05 diff --git a/global_structures.h b/global_structures.h index e98a0e7c..76de547d 100644 --- a/global_structures.h +++ b/global_structures.h @@ -1060,7 +1060,7 @@ struct M_S typedef enum { TYPE_B0, TYPE_B1, TYPE_B2, TYPE_C0, TYPE_THETA, TYPE_LAMDA, TYPE_ZETA, TYPE_PSI, TYPE_ETHETA, TYPE_ALPHAS, TYPE_MU, TYPE_ETA, TYPE_Other, - TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU + TYPE_SIT_EPSILON, TYPE_SIT_EPSILON_MU, TYPE_APHI } pitz_param_type; struct pitz_param @@ -1082,8 +1082,9 @@ struct pitz_param LDBLE alphas; LDBLE mu; LDBLE eta; - LDBLE eps; - LDBLE eps1; + LDBLE eps; + LDBLE eps1; + LDBLE aphi; } U; LDBLE a[6]; LDBLE alpha; diff --git a/pitzer.cpp b/pitzer.cpp index 006f4d69..546b3cd4 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -634,9 +634,10 @@ read_pitzer(void) "eta", /* 15 */ "etheta", /* 16 */ "use_etheta", /* 17 */ - "lambda" /* 18 */ + "lambda", /* 18 */ + "aphi" /* 19 */ }; - int count_opt_list = 19; + int count_opt_list = 20; /* * Read lines */ @@ -664,7 +665,15 @@ read_pitzer(void) if (pzp_ptr != NULL) { pzp_ptr->type = pzp_type; - pitz_param_store(pzp_ptr, false); + if (pzp_type == TYPE_APHI) + { + aphi = (struct pitz_param *) free_check_null(aphi); + aphi = pzp_ptr; + } + else + { + pitz_param_store(pzp_ptr, false); + } } break; case OPTION_ERROR: @@ -744,6 +753,11 @@ read_pitzer(void) opt_save = OPTION_ERROR; use_etheta = get_true_false(next_char, TRUE); break; + case 19: /* aphi */ + pzp_type = TYPE_APHI; + n = 0; + opt_save = OPTION_DEFAULT; + break; } if (return_value == EOF || return_value == KEYWORD) break; @@ -780,6 +794,10 @@ C int i = param_list[j]; calc_pitz_param(pitz_params[i], TK, TR); } + if (aphi) + { + calc_pitz_param(aphi, TK, TR); + } if (mcb0) { calc_pitz_param(mcb0, TK, TR); @@ -857,6 +875,9 @@ calc_pitz_param(struct pitz_param *pz_ptr, LDBLE TK, LDBLE TR) case TYPE_ETA: pz_ptr->U.eta = param; break; + case TYPE_APHI: + pz_ptr->U.aphi = param; + break; case TYPE_Other: default: error_msg("Should not be TYPE_Other in function calc_pitz_param", @@ -1668,6 +1689,7 @@ pitzer_clean_up(void) LGAMMA = (LDBLE *) free_check_null(LGAMMA); IPRSNT = (int *) free_check_null(IPRSNT); spec = (struct species **) free_check_null(spec); + aphi = (struct pitz_param *) free_check_null(aphi); M = (LDBLE *) free_check_null(M); return OK; diff --git a/pitzer_structures.cpp b/pitzer_structures.cpp index 245a1871..061eb715 100644 --- a/pitzer_structures.cpp +++ b/pitzer_structures.cpp @@ -72,7 +72,7 @@ pitz_param_read(char *string, int n) char token[2 * MAX_LENGTH]; struct pitz_param pzp, *pzp_ptr; - if (n != 2 && n != 3) + if (n != 2 && n != 3 && n != 0) return (NULL); if (string == NULL) return (NULL); diff --git a/prep.cpp b/prep.cpp index 26ce61d8..e35d42e3 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4143,11 +4143,6 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) continue; } phase_ptr->pr_p = phase_ptr->fraction_x * P; - //if (phase_ptr->t_c == 0.0 || phase_ptr->p_c == 0.0) - //{ - // phase_ptr->pr_phi = 1; - // continue; - //} rz = P * V_m / R_TK; A = a_aa_sum * P / (R_TK * R_TK); B = b_sum * P / R_TK; @@ -4155,12 +4150,17 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) if (rz > B) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * - log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); if (phi > 4.44) phi = 4.44; } else phi = -3.0; // fugacity coefficient > 0.05 + if (/*!strcmp(phase_ptr->name, "H2O(g)") && */phi < -3) + { + // avoid such phi... + phi = -3; + } phase_ptr->pr_phi = exp(phi); phase_ptr->pr_si_f = phi / LOG_10; // for initial equilibrations, adapt log_k of the gas phase... diff --git a/sit.cpp b/sit.cpp index cb86f7c9..df222f3e 100644 --- a/sit.cpp +++ b/sit.cpp @@ -697,6 +697,7 @@ sit_clean_up(void) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA); sit_IPRSNT = (int *) free_check_null(sit_IPRSNT); spec = (struct species **) free_check_null(spec); + aphi = (struct pitz_param *) free_check_null(aphi); sit_M = (LDBLE *) free_check_null(sit_M); return OK; diff --git a/transport.cpp b/transport.cpp index 788a66a1..3ce5b820 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" @@ -132,7 +132,7 @@ transport(void) moles_added[i].moles = 0; } } - try + try { /* check solution 0 */ use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, 0)); @@ -228,7 +228,7 @@ transport(void) "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); warning_msg(error_string); } - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) (count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) malloc_error(); diff --git a/utilities.cpp b/utilities.cpp index 13b703c5..22b45a0a 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -255,6 +255,11 @@ calc_dielectrics(LDBLE tc, LDBLE pa) if (pitzer_model || sit_model) { A0 = DH_B * e2_DkT / 6.0; + if (pitzer_model && aphi != NULL) + { + calc_pitz_param(aphi, T, 298.15); + A0 = aphi->p; + } } /* Debye-Hueckel limiting slope = DH_B * e2_DkT * RT * (d(ln(eps_r)) / d(P) - compressibility) */ From 5f165e7e65dabe685a126790c4403c3afaab9137 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 8 Mar 2017 17:19:28 +0000 Subject: [PATCH 1051/1077] Duplicate tok fixed up some of the new features. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12522 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.h | 1 - Phreeqc.cpp | 1 + readtr.cpp | 6 ++++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PBasic.h b/PBasic.h index 34b604f1..ed26b746 100644 --- a/PBasic.h +++ b/PBasic.h @@ -335,7 +335,6 @@ public: tokcurrent_a, tokpot_v, tokt_sc, - tokphase_vm, tokaphi }; diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 9a3de8bb..dada2c4f 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -198,6 +198,7 @@ void Phreeqc::init(void) mu_terms_in_logk = true; current_A = 0.0; current_x = 0.0; + fix_current = 0.0; /* ---------------------------------------------------------------------- * STRUCTURES * ---------------------------------------------------------------------- */ diff --git a/readtr.cpp b/readtr.cpp index 9e815d58..724c3ad1 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -92,9 +92,10 @@ read_transport(void) "interlayer_d", /* 41 */ "porosities", /* 42 */ "porosity", /* 43 */ - "fix_current" /* 44 */ + "fix_current", /* 44 */ + "current" /* 45 */ }; - int count_opt_list = 45; + int count_opt_list = 46; strcpy(file_name, "phreeqc.dmp"); /* @@ -667,6 +668,7 @@ read_transport(void) opt_save = 42; break; case 44: /* fix_current */ + case 45: /* current */ if (copy_token(token, &next_char, &l) == DIGIT) { sscanf(token, SCANFORMAT, &fix_current); From 66481ea61fe9dac800ca1f76141b9955e4cdb8f1 Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Thu, 9 Mar 2017 21:26:40 +0000 Subject: [PATCH 1052/1077] added tokequiv_frac to tokeq_frac git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12528 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/PBasic.cpp b/PBasic.cpp index 2df8d00c..0f427ceb 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -3797,6 +3797,7 @@ factor(struct LOC_exec * LINK) } break; case tokeq_frac: + case tokequiv_frac: { // left parenthesis require(toklp, LINK); From 43ecf1e38a6c32bf6e12d4be5611964556ac8126 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Mar 2017 18:00:15 +0000 Subject: [PATCH 1053/1077] New Basic function TITLE git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12540 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 15 +++++++++++++++ PBasic.h | 1 + Phreeqc.h | 1 + read.cpp | 1 + structures.cpp | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 0f427ceb..cfb7afdf 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1405,6 +1405,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("DESCRIPTION"); break; + case toktitle: + output_msg("TITLE"); + break; + case toksys: output_msg("SYS"); break; @@ -2505,6 +2509,16 @@ factor(struct LOC_exec * LINK) while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); break; + case toktitle: + n.stringval = true; + if (strlen(PhreeqcPtr->last_title_x.c_str()) == 0) + { + PhreeqcPtr->last_title_x = " "; + } + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->last_title_x.c_str()); + while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); + break; + case tokinstr: require(toklp, LINK); string1 = stringfactor(STR1, LINK); @@ -7180,6 +7194,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("sum_s_s", PBasic::toksum_s_s), std::map::value_type("calc_value", PBasic::tokcalc_value), std::map::value_type("description", PBasic::tokdescription), + std::map::value_type("title", PBasic::toktitle), std::map::value_type("sys", PBasic::toksys), std::map::value_type("instr", PBasic::tokinstr), std::map::value_type("ltrim", PBasic::tokltrim), diff --git a/PBasic.h b/PBasic.h index ee423841..4554518f 100644 --- a/PBasic.h +++ b/PBasic.h @@ -264,6 +264,7 @@ public: toksum_s_s, tokcalc_value, tokdescription, + toktitle, toksys, tokinstr, tokltrim, diff --git a/Phreeqc.h b/Phreeqc.h index c1b94ab7..c018b86a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1345,6 +1345,7 @@ protected: * Global solution *---------------------------------------------------------------------- */ char *title_x; + std::string last_title_x; int new_x; char *description_x; LDBLE tc_x; diff --git a/read.cpp b/read.cpp index d7c7d919..798517e4 100644 --- a/read.cpp +++ b/read.cpp @@ -7975,6 +7975,7 @@ read_title(void) } strcat(title_x, line); } + last_title_x = title_x; return (return_value); } diff --git a/structures.cpp b/structures.cpp index 5bb0ac11..08e785e4 100644 --- a/structures.cpp +++ b/structures.cpp @@ -361,7 +361,7 @@ clean_up(void) free_spread(); #endif title_x = (char *) free_check_null(title_x); - + last_title_x.clear(); count_elements = 0; count_master = 0; count_phases = 0; From 6190fb36bef126e64e0642edec2f33117a3f9ada Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Fri, 10 Mar 2017 18:26:53 +0000 Subject: [PATCH 1054/1077] New Basic function TITLE git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12544 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PBasic.cpp | 16 ++++++++++++++++ PBasic.h | 1 + Phreeqc.h | 1 + read.cpp | 1 + structures.cpp | 2 +- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/PBasic.cpp b/PBasic.cpp index 92283cfb..2cfcadc5 100644 --- a/PBasic.cpp +++ b/PBasic.cpp @@ -1405,6 +1405,10 @@ listtokens(FILE * f, tokenrec * l_buf) output_msg("DESCRIPTION"); break; + case toktitle: + output_msg("TITLE"); + break; + case toksys: output_msg("SYS"); break; @@ -2523,6 +2527,16 @@ factor(struct LOC_exec * LINK) while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); break; + case toktitle: + n.stringval = true; + if (strlen(PhreeqcPtr->last_title_x.c_str()) == 0) + { + PhreeqcPtr->last_title_x = " "; + } + n.UU.sval = PhreeqcPtr->string_duplicate(PhreeqcPtr->last_title_x.c_str()); + while (PhreeqcPtr->replace("\t", " ", n.UU.sval)); + break; + case tokinstr: require(toklp, LINK); string1 = stringfactor(STR1, LINK); @@ -3838,6 +3852,7 @@ factor(struct LOC_exec * LINK) } break; case tokeq_frac: + case tokequiv_frac: { // left parenthesis require(toklp, LINK); @@ -7238,6 +7253,7 @@ const std::map::value_type temp_tokens[] std::map::value_type("sum_s_s", PBasic::toksum_s_s), std::map::value_type("calc_value", PBasic::tokcalc_value), std::map::value_type("description", PBasic::tokdescription), + std::map::value_type("title", PBasic::toktitle), std::map::value_type("sys", PBasic::toksys), std::map::value_type("instr", PBasic::tokinstr), std::map::value_type("ltrim", PBasic::tokltrim), diff --git a/PBasic.h b/PBasic.h index ed26b746..45de1df7 100644 --- a/PBasic.h +++ b/PBasic.h @@ -264,6 +264,7 @@ public: toksum_s_s, tokcalc_value, tokdescription, + toktitle, toksys, tokinstr, tokltrim, diff --git a/Phreeqc.h b/Phreeqc.h index f8d9f3d7..fe28512a 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1351,6 +1351,7 @@ protected: * Global solution *---------------------------------------------------------------------- */ char *title_x; + std::string last_title_x; int new_x; char *description_x; LDBLE tc_x; diff --git a/read.cpp b/read.cpp index 9dc241b9..d9f97158 100644 --- a/read.cpp +++ b/read.cpp @@ -8030,6 +8030,7 @@ read_title(void) } strcat(title_x, line); } + last_title_x = title_x; return (return_value); } diff --git a/structures.cpp b/structures.cpp index 0afa8da1..67c39f2a 100644 --- a/structures.cpp +++ b/structures.cpp @@ -361,7 +361,7 @@ clean_up(void) free_spread(); #endif title_x = (char *) free_check_null(title_x); - + last_title_x.clear(); count_elements = 0; count_master = 0; count_phases = 0; From bf6dcd08602b1b090e9767590b68b77c21eebc09 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Mon, 27 Mar 2017 19:59:43 +0000 Subject: [PATCH 1055/1077] Iterate to calculate density in initial solution calculation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12621 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 1 + ISolution.h | 3 +++ mainsubs.cpp | 46 ++++++++++++++++++++++++++++++++++++---------- print.cpp | 8 ++++++-- read.cpp | 27 +++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 14 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 7a36cd45..29afa583 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -25,6 +25,7 @@ units("mMol/kgw") default_pe = "pe"; cxxChemRxn temp_pe_reactions; pe_reactions[default_pe] = temp_pe_reactions; + this->calc_density = false; } cxxISolution::~cxxISolution() diff --git a/ISolution.h b/ISolution.h index 4e42ff07..1c7de94e 100644 --- a/ISolution.h +++ b/ISolution.h @@ -33,6 +33,8 @@ class cxxISolution: public PHRQ_base } const char * Get_default_pe() const {return default_pe;} void Set_default_pe(const char * pe) {default_pe = pe;} + bool Get_calc_density(void) {return this->calc_density;} + void Set_calc_density(bool calc) {this->calc_density = calc;} std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;} const std::map < std::string, cxxISolutionComp > &Get_comps(void)const {return this->comps;} void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;} @@ -44,6 +46,7 @@ class cxxISolution: public PHRQ_base protected: friend class cxxISolutionComp; // for this->pe access std::string units; + bool calc_density; std::map < std::string, cxxISolutionComp > comps; std::map pe_reactions; const char * default_pe; diff --git a/mainsubs.cpp b/mainsubs.cpp index c76e56ff..61a4e2b5 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -615,20 +615,46 @@ initial_solutions(int print) dup_print(token, FALSE); } use.Set_solution_ptr(&solution_ref); - prep(); - k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); - set(TRUE); - always_full_pitzer = FALSE; + LDBLE d0 = solution_ref.Get_density(); + LDBLE d1 = 0; bool diag = (diagonal_scale == TRUE) ? true : false; - diagonal_scale = TRUE; - converge = model(); - if (converge == ERROR /*&& diagonal_scale == FALSE*/) + int count_iterations = 0; + for (;;) { - diagonal_scale = TRUE; - always_full_pitzer = TRUE; + prep(); + k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); set(TRUE); + always_full_pitzer = FALSE; + + diagonal_scale = TRUE; converge = model(); - } + if (converge == ERROR /*&& diagonal_scale == FALSE*/) + { + diagonal_scale = TRUE; + always_full_pitzer = TRUE; + set(TRUE); + converge = model(); + } + if (solution_ref.Get_initial_data()->Get_calc_density()) + { + solution_ref.Set_density(calc_dens()); + if (!equal(d0, solution_ref.Get_density(), 1e-8)) + { + d0 = solution_ref.Get_density(); + if (count_iterations++ < 20) + { + diag = (diagonal_scale == TRUE) ? true : false; + continue; + } + else + { + error_msg(sformatf("%s %d.", "Density calculation failed for initial solution ", solution_ref.Get_n_user()), + STOP); + } + } + } + break; + } diagonal_scale = (diag) ? TRUE : FALSE; converge1 = check_residuals(); sum_species(); diff --git a/print.cpp b/print.cpp index ed2b60c0..884a661b 100644 --- a/print.cpp +++ b/print.cpp @@ -2245,8 +2245,12 @@ print_totals(void) output_msg(sformatf("%45s%9.5f", "Density (g/cm³) = ", #endif (double) dens)); - if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program limit)")); - else output_msg(sformatf("\n")); + if (state == INITIAL_SOLUTION && use.Get_solution_ptr()->Get_initial_data()->Get_calc_density()) + { + output_msg(sformatf(" (Iterated) ")); + } + if (dens > 1.999) output_msg(sformatf("%18s", " (Program limit)")); + output_msg(sformatf("\n")); output_msg(sformatf("%45s%9.5f\n", " Volume (L) = ", (double) calc_solution_volume())); } diff --git a/read.cpp b/read.cpp index 798517e4..200b11c1 100644 --- a/read.cpp +++ b/read.cpp @@ -5699,8 +5699,31 @@ read_solution(void) case 2: /* density */ case 3: { - sscanf(next_char, SCANFORMAT, &dummy); - temp_solution.Set_density(dummy); + copy_token(token, &next_char); + if (sscanf(token.c_str(), SCANFORMAT, &dummy) != 1) + { + error_msg("Expecting numeric value for density.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + temp_solution.Set_density(dummy); + } + int j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + isoln_ptr->Set_calc_density(true); + } + } } break; case 4: /* units */ From 73a34a99b7a412a1f6b1c0a26387ff9e1dfb1afb Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 28 Mar 2017 21:29:45 +0000 Subject: [PATCH 1056/1077] Added "calculate" capability to density in SOLUTION_SPREAD. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12623 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- global_structures.h | 1 + spread.cpp | 54 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/global_structures.h b/global_structures.h index 0883be7f..376cc630 100644 --- a/global_structures.h +++ b/global_structures.h @@ -928,6 +928,7 @@ struct defaults { LDBLE temp; LDBLE density; + bool calc_density; const char *units; const char *redox; LDBLE ph; diff --git a/spread.cpp b/spread.cpp index 6fac7712..81a7d7d2 100644 --- a/spread.cpp +++ b/spread.cpp @@ -63,6 +63,7 @@ read_solution_spread(void) */ soln_defaults.temp = 25; soln_defaults.density = 1.0; + soln_defaults.calc_density = false; soln_defaults.units = string_hsave("mmol/kgw"); soln_defaults.redox = string_hsave("pe"); soln_defaults.ph = 7.0; @@ -150,7 +151,7 @@ read_solution_spread(void) case 2: /* dens */ case 3: /* density */ case 10: /* water */ - if (count == 2 && num == TRUE) + if ((count == 2 || count == 3) && num == TRUE) { opt = opt; } @@ -270,7 +271,34 @@ read_solution_spread(void) break; case 2: /* density */ case 3: - sscanf(next_char, SCANFORMAT, &(soln_defaults.density)); + //sscanf(next_char, SCANFORMAT, &(soln_defaults.density)); + { + copy_token(token, &next_char); + if (sscanf(token.c_str(), SCANFORMAT, &dummy) != 1) + { + error_msg("Expecting numeric value for density.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + soln_defaults.density = dummy; + } + int j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + soln_defaults.calc_density = true; + } + } + } break; case 4: /* units */ case 8: /* unit */ @@ -615,6 +643,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, temp_solution.Set_patm(defaults.pressure); temp_solution.Set_ph(defaults.ph); temp_solution.Set_density(defaults.density); + initial_data_ptr->Set_calc_density(defaults.calc_density); temp_solution.Set_pe(defaults.pe); temp_solution.Set_mass_water(defaults.water); temp_solution.Set_ah2o(1.0); @@ -692,8 +721,25 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; case 2: /* density */ case 3: - sscanf(next_char, SCANFORMAT, &dummy); - temp_solution.Set_density(dummy); + { + int j = copy_token(token, &next_char); + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_solution.Set_density(dummy); + j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + initial_data_ptr->Set_calc_density(true); + } + } + } break; case 4: /* units */ case 8: /* unit */ From e3bac3dbb95ac7ccce98bc65230968ca1b01d59d Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 29 Mar 2017 20:48:54 +0000 Subject: [PATCH 1057/1077] Updated to svn 12361 on trunk Added documentation for density calculate git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12635 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- ISolution.cxx | 1 + ISolution.h | 3 +++ global_structures.h | 1 + mainsubs.cpp | 46 +++++++++++++++++++++++++++++--------- print.cpp | 8 +++++-- read.cpp | 27 +++++++++++++++++++++-- spread.cpp | 54 +++++++++++++++++++++++++++++++++++++++++---- 7 files changed, 122 insertions(+), 18 deletions(-) diff --git a/ISolution.cxx b/ISolution.cxx index 7a36cd45..29afa583 100644 --- a/ISolution.cxx +++ b/ISolution.cxx @@ -25,6 +25,7 @@ units("mMol/kgw") default_pe = "pe"; cxxChemRxn temp_pe_reactions; pe_reactions[default_pe] = temp_pe_reactions; + this->calc_density = false; } cxxISolution::~cxxISolution() diff --git a/ISolution.h b/ISolution.h index 4e42ff07..1c7de94e 100644 --- a/ISolution.h +++ b/ISolution.h @@ -33,6 +33,8 @@ class cxxISolution: public PHRQ_base } const char * Get_default_pe() const {return default_pe;} void Set_default_pe(const char * pe) {default_pe = pe;} + bool Get_calc_density(void) {return this->calc_density;} + void Set_calc_density(bool calc) {this->calc_density = calc;} std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;} const std::map < std::string, cxxISolutionComp > &Get_comps(void)const {return this->comps;} void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;} @@ -44,6 +46,7 @@ class cxxISolution: public PHRQ_base protected: friend class cxxISolutionComp; // for this->pe access std::string units; + bool calc_density; std::map < std::string, cxxISolutionComp > comps; std::map pe_reactions; const char * default_pe; diff --git a/global_structures.h b/global_structures.h index 76de547d..aec2ab56 100644 --- a/global_structures.h +++ b/global_structures.h @@ -936,6 +936,7 @@ struct defaults { LDBLE temp; LDBLE density; + bool calc_density; const char *units; const char *redox; LDBLE ph; diff --git a/mainsubs.cpp b/mainsubs.cpp index 5255df5a..4e72ac01 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -628,20 +628,46 @@ initial_solutions(int print) dup_print(token, FALSE); } use.Set_solution_ptr(&solution_ref); - prep(); - k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); - set(TRUE); - always_full_pitzer = FALSE; + LDBLE d0 = solution_ref.Get_density(); + LDBLE d1 = 0; bool diag = (diagonal_scale == TRUE) ? true : false; - diagonal_scale = TRUE; - converge = model(); - if (converge == ERROR /*&& diagonal_scale == FALSE*/) + int count_iterations = 0; + for (;;) { - diagonal_scale = TRUE; - always_full_pitzer = TRUE; + prep(); + k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); set(TRUE); + always_full_pitzer = FALSE; + + diagonal_scale = TRUE; converge = model(); - } + if (converge == ERROR /*&& diagonal_scale == FALSE*/) + { + diagonal_scale = TRUE; + always_full_pitzer = TRUE; + set(TRUE); + converge = model(); + } + if (solution_ref.Get_initial_data()->Get_calc_density()) + { + solution_ref.Set_density(calc_dens()); + if (!equal(d0, solution_ref.Get_density(), 1e-8)) + { + d0 = solution_ref.Get_density(); + if (count_iterations++ < 20) + { + diag = (diagonal_scale == TRUE) ? true : false; + continue; + } + else + { + error_msg(sformatf("%s %d.", "Density calculation failed for initial solution ", solution_ref.Get_n_user()), + STOP); + } + } + } + break; + } diagonal_scale = (diag) ? TRUE : FALSE; converge1 = check_residuals(); sum_species(); diff --git a/print.cpp b/print.cpp index 9aaaa181..cf0b89e6 100644 --- a/print.cpp +++ b/print.cpp @@ -2245,8 +2245,12 @@ print_totals(void) output_msg(sformatf("%45s%9.5f", "Density (g/cm³) = ", #endif (double) dens)); - if (dens > 1.999) output_msg(sformatf("%18s\n", " (Program limit)")); - else output_msg(sformatf("\n")); + if (state == INITIAL_SOLUTION && use.Get_solution_ptr()->Get_initial_data()->Get_calc_density()) + { + output_msg(sformatf(" (Iterated) ")); + } + if (dens > 1.999) output_msg(sformatf("%18s", " (Program limit)")); + output_msg(sformatf("\n")); output_msg(sformatf("%45s%9.5f\n", " Volume (L) = ", (double) calc_solution_volume())); } diff --git a/read.cpp b/read.cpp index d9f97158..d47ee76c 100644 --- a/read.cpp +++ b/read.cpp @@ -5726,8 +5726,31 @@ read_solution(void) case 2: /* density */ case 3: { - sscanf(next_char, SCANFORMAT, &dummy); - temp_solution.Set_density(dummy); + copy_token(token, &next_char); + if (sscanf(token.c_str(), SCANFORMAT, &dummy) != 1) + { + error_msg("Expecting numeric value for density.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + temp_solution.Set_density(dummy); + } + int j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + isoln_ptr->Set_calc_density(true); + } + } } break; case 4: /* units */ diff --git a/spread.cpp b/spread.cpp index 0d4a18ac..a6f90787 100644 --- a/spread.cpp +++ b/spread.cpp @@ -63,6 +63,7 @@ read_solution_spread(void) */ soln_defaults.temp = 25; soln_defaults.density = 1.0; + soln_defaults.calc_density = false; soln_defaults.units = string_hsave("mmol/kgw"); soln_defaults.redox = string_hsave("pe"); soln_defaults.ph = 7.0; @@ -150,7 +151,7 @@ read_solution_spread(void) case 2: /* dens */ case 3: /* density */ case 10: /* water */ - if (count == 2 && num == TRUE) + if ((count == 2 || count == 3) && num == TRUE) { opt = opt; } @@ -270,7 +271,34 @@ read_solution_spread(void) break; case 2: /* density */ case 3: - sscanf(next_char, SCANFORMAT, &(soln_defaults.density)); + //sscanf(next_char, SCANFORMAT, &(soln_defaults.density)); + { + copy_token(token, &next_char); + if (sscanf(token.c_str(), SCANFORMAT, &dummy) != 1) + { + error_msg("Expecting numeric value for density.", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + soln_defaults.density = dummy; + } + int j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + soln_defaults.calc_density = true; + } + } + } break; case 4: /* units */ case 8: /* unit */ @@ -617,6 +645,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, temp_solution.Set_potV(0); temp_solution.Set_ph(defaults.ph); temp_solution.Set_density(defaults.density); + initial_data_ptr->Set_calc_density(defaults.calc_density); temp_solution.Set_pe(defaults.pe); temp_solution.Set_mass_water(defaults.water); temp_solution.Set_ah2o(1.0); @@ -694,8 +723,25 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units, break; case 2: /* density */ case 3: - sscanf(next_char, SCANFORMAT, &dummy); - temp_solution.Set_density(dummy); + { + int j = copy_token(token, &next_char); + sscanf(token.c_str(), SCANFORMAT, &dummy); + temp_solution.Set_density(dummy); + j = copy_token(token, &next_char); + if (j != EMPTY) + { + if (token[0] != 'c' && token[0] != 'C') + { + error_msg("Only option following density is c[alculate].", PHRQ_io::OT_CONTINUE); + error_msg(line_save, PHRQ_io::OT_CONTINUE); + input_error++; + } + else + { + initial_data_ptr->Set_calc_density(true); + } + } + } break; case 4: /* units */ case 8: /* unit */ From bdef01ca9cf3d6640ea629e8e304b64218bfe22f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 12 Apr 2017 18:36:24 +0000 Subject: [PATCH 1058/1077] Expanded error report for equation balancing. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12678 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- parse.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parse.cpp b/parse.cpp index 5904b604..cf149a4d 100644 --- a/parse.cpp +++ b/parse.cpp @@ -237,7 +237,7 @@ check_eqn(int association) */ if (equal(sumcharge, 0.0, TOL) == FALSE) { - error_string = sformatf( "Equation is not charge balanced."); + error_string = sformatf( "Equation is not charge balanced, right - left = %7.4f moles charge", sumcharge); error_msg(error_string, CONTINUE); oops++; } @@ -250,8 +250,8 @@ check_eqn(int association) strncmp((elt_list[i].elt)->name, "e", MAX_LENGTH) != 0) { error_string = sformatf( - "Equation does not balance for element, %s.", - (elt_list[i].elt)->name); + "Equation does not balance for element, %s: right - left = %7.4f moles", + (elt_list[i].elt)->name, elt_list[i].coef); error_msg(error_string, CONTINUE); oops++; } From 2c1f1b335457c36a307ad7972c759ee36c26bdfe Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 25 Apr 2017 18:03:14 +0000 Subject: [PATCH 1059/1077] Synced with PHREEQC 12683. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12683 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- integrate.cpp | 21 ++++++++-- print.cpp | 114 +++++++++++++++++++++++++------------------------- 2 files changed, 76 insertions(+), 59 deletions(-) diff --git a/integrate.cpp b/integrate.cpp index 1d501355..f8a5050e 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -578,11 +578,20 @@ initial_surface_water(void) charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); } - rd = debye_length * use.Get_surface_ptr()->Get_debye_lengths(); use.Get_surface_ptr()->Set_thickness(rd); - if (state == INITIAL_SURFACE) + if (!sum_surfs) + { + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + charge_ptr->Set_mass_water(0); + } + } + else if (state == INITIAL_SURFACE) { /* distribute water over DDL (rd) and free pore (r - rd) */ /* find r: free pore (m3) = pi * (r - rd)^2 * L, where L = A / (2*pi*r), @@ -808,6 +817,13 @@ calc_all_donnan(void) for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { LDBLE z = it->first; + if (!ratio_aq) + { + charge_ptr->Get_g_map()[z].Set_g(0); + charge_ptr->Get_g_map()[z].Set_dg(0); + converge = true; + continue; + } new_g = ratio_aq * (exp(cd_m * z * psi_avg) - 1); if (use.Get_surface_ptr()->Get_only_counter_ions() && ((surf_chrg_eq < 0 && z < 0) @@ -959,7 +975,6 @@ calc_init_donnan(void) { charge_ptr->Get_g_map()[z].Set_dg(-z); } - /* save g for species */ for (int i = 0; i < count_s_x; i++) { diff --git a/print.cpp b/print.cpp index cf0b89e6..55419060 100644 --- a/print.cpp +++ b/print.cpp @@ -259,7 +259,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) output_msg(sformatf( "\tWater in diffuse layer: %8.3e kg, %4.1f%% of total DDL-water.\n", (double) charge_ptr->Get_mass_water(), (double) d)); - if (use.Get_surface_ptr()->Get_debye_lengths() > 0) + if (use.Get_surface_ptr()->Get_debye_lengths() > 0 && d > 0) { sum_surfs = 0.0; for (j = 0; j < count_unknowns; j++) @@ -284,64 +284,66 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) output_msg(sformatf( "\n\tSpecies \t Moles \tMoles excess\t g\n")); } - mass_water_surface = charge_ptr->Get_mass_water(); - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) + if (mass_water_surface = charge_ptr->Get_mass_water()) { - if (s_x[j]->type > HPLUS) - continue; - molality = under(s_x[j]->lm); - moles_excess = mass_water_aq_x * molality * (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * - s_x[j]->erm_ddl + - mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - 1)); - moles_surface = mass_water_surface * molality + moles_excess; - if (debug_diffuse_layer == TRUE) + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { - output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", - s_x[j]->name, moles_surface, moles_excess, - charge_ptr->Get_g_map()[s_x[j]->z].Get_g())); + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + moles_excess = mass_water_aq_x * molality * (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * + s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + moles_surface = mass_water_surface * molality + moles_excess; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", + s_x[j]->name, moles_surface, moles_excess, + charge_ptr->Get_g_map()[s_x[j]->z].Get_g())); + } + /* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + /* + strcpy(token, s_h2o->name); + ptr = &(token[0]); + get_elts_in_species (&ptr, mass_water_surface / gfw_water); + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t)count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Print totals + */ + if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) + { + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water)\n\n")); + } + else + { + LDBLE exp_g = charge_ptr->Get_g_map()[1].Get_g() * mass_water_aq_x / mass_water_surface + 1; + LDBLE psi_DL = -log(exp_g) * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ; + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation.")); + output_msg(sformatf( + "\n\tDonnan Layer potential, psi_DL = %10.3e V.\n\tBoltzmann factor, exp(-psi_DL * F / RT) = %9.3e (= c_DL / c_free if z is +1).\n\n", + psi_DL, exp_g)); + } + output_msg(sformatf("\tElement \t Moles\n")); + for (j = 0; j < count_elts; j++) + { + output_msg(sformatf("\t%-14s\t%12.4e\n", + elt_list[j].elt->name, (double)elt_list[j].coef)); } -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } -/* - strcpy(token, s_h2o->name); - ptr = &(token[0]); - get_elts_in_species (&ptr, mass_water_surface / gfw_water); - */ - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } -/* - * Print totals - */ - if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) - { - output_msg(sformatf( - "\n\tTotal moles in diffuse layer (excluding water)\n\n")); - } - else - { - LDBLE exp_g = charge_ptr->Get_g_map()[1].Get_g() * mass_water_aq_x / mass_water_surface + 1; - LDBLE psi_DL = -log(exp_g) * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ; - output_msg(sformatf( - "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation.")); - output_msg(sformatf( - "\n\tDonnan Layer potential, psi_DL = %10.3e V.\n\tBoltzmann factor, exp(-psi_DL * F / RT) = %9.3e (= c_DL / c_free if z is +1).\n\n", - psi_DL, exp_g)); - } - output_msg(sformatf("\tElement \t Moles\n")); - for (j = 0; j < count_elts; j++) - { - output_msg(sformatf("\t%-14s\t%12.4e\n", - elt_list[j].elt->name, (double) elt_list[j].coef)); } return (OK); } From 92aa19a44d06b0e3f95279a24e878eadf3f5642f Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 25 Apr 2017 18:03:36 +0000 Subject: [PATCH 1060/1077] Synced with concrete 12683. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12684 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- integrate.cpp | 21 +++++++-- print.cpp | 116 +++++++++++++++++++++++++------------------------- 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/integrate.cpp b/integrate.cpp index 1d501355..f8a5050e 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -578,11 +578,20 @@ initial_surface_water(void) charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); } - rd = debye_length * use.Get_surface_ptr()->Get_debye_lengths(); use.Get_surface_ptr()->Set_thickness(rd); - if (state == INITIAL_SURFACE) + if (!sum_surfs) + { + for (int i = 0; i < count_unknowns; i++) + { + if (x[i]->type != SURFACE_CB) + continue; + cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); + charge_ptr->Set_mass_water(0); + } + } + else if (state == INITIAL_SURFACE) { /* distribute water over DDL (rd) and free pore (r - rd) */ /* find r: free pore (m3) = pi * (r - rd)^2 * L, where L = A / (2*pi*r), @@ -808,6 +817,13 @@ calc_all_donnan(void) for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { LDBLE z = it->first; + if (!ratio_aq) + { + charge_ptr->Get_g_map()[z].Set_g(0); + charge_ptr->Get_g_map()[z].Set_dg(0); + converge = true; + continue; + } new_g = ratio_aq * (exp(cd_m * z * psi_avg) - 1); if (use.Get_surface_ptr()->Get_only_counter_ions() && ((surf_chrg_eq < 0 && z < 0) @@ -959,7 +975,6 @@ calc_init_donnan(void) { charge_ptr->Get_g_map()[z].Set_dg(-z); } - /* save g for species */ for (int i = 0; i < count_s_x; i++) { diff --git a/print.cpp b/print.cpp index 884a661b..3f49850e 100644 --- a/print.cpp +++ b/print.cpp @@ -259,7 +259,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) output_msg(sformatf( "\tWater in diffuse layer: %8.3e kg, %4.1f%% of total DDL-water.\n", (double) charge_ptr->Get_mass_water(), (double) d)); - if (use.Get_surface_ptr()->Get_debye_lengths() > 0) + if (use.Get_surface_ptr()->Get_debye_lengths() > 0 && d > 0) { sum_surfs = 0.0; for (j = 0; j < count_unknowns; j++) @@ -284,64 +284,66 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) output_msg(sformatf( "\n\tSpecies \t Moles \tMoles excess\t g\n")); } - mass_water_surface = charge_ptr->Get_mass_water(); - count_elts = 0; - paren_count = 0; - for (j = 0; j < count_s_x; j++) + if (mass_water_surface = charge_ptr->Get_mass_water()) { - if (s_x[j]->type > HPLUS) - continue; - molality = under(s_x[j]->lm); - moles_excess = mass_water_aq_x * molality * (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * - s_x[j]->erm_ddl + - mass_water_surface / - mass_water_aq_x * (s_x[j]->erm_ddl - 1)); - moles_surface = mass_water_surface * molality + moles_excess; - if (debug_diffuse_layer == TRUE) + count_elts = 0; + paren_count = 0; + for (j = 0; j < count_s_x; j++) { - output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", - s_x[j]->name, moles_surface, moles_excess, - charge_ptr->Get_g_map()[s_x[j]->z].Get_g())); + if (s_x[j]->type > HPLUS) + continue; + molality = under(s_x[j]->lm); + moles_excess = mass_water_aq_x * molality * (charge_ptr->Get_g_map()[s_x[j]->z].Get_g() * + s_x[j]->erm_ddl + + mass_water_surface / + mass_water_aq_x * (s_x[j]->erm_ddl - 1)); + moles_surface = mass_water_surface * molality + moles_excess; + if (debug_diffuse_layer == TRUE) + { + output_msg(sformatf("\t%-12s\t%12.3e\t%12.3e\t%12.3e\n", + s_x[j]->name, moles_surface, moles_excess, + charge_ptr->Get_g_map()[s_x[j]->z].Get_g())); + } + /* + * Accumulate elements in diffuse layer + */ + add_elt_list(s_x[j]->next_elt, moles_surface); + } + /* + strcpy(token, s_h2o->name); + ptr = &(token[0]); + get_elts_in_species (&ptr, mass_water_surface / gfw_water); + */ + if (count_elts > 0) + { + qsort(elt_list, (size_t)count_elts, + (size_t) sizeof(struct elt_list), elt_list_compare); + elt_list_combine(); + } + /* + * Print totals + */ + if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) + { + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water)\n\n")); + } + else + { + LDBLE exp_g = charge_ptr->Get_g_map()[1].Get_g() * mass_water_aq_x / mass_water_surface + 1; + LDBLE psi_DL = -log(exp_g) * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ; + output_msg(sformatf( + "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation.")); + output_msg(sformatf( + "\n\tDonnan Layer potential, psi_DL = %10.3e V.\n\tBoltzmann factor, exp(-psi_DL * F / RT) = %9.3e (= c_DL / c_free if z is +1).\n\n", + psi_DL, exp_g)); + } + output_msg(sformatf("\tElement \t Moles\n")); + for (j = 0; j < count_elts; j++) + { + output_msg(sformatf("\t%-14s\t%12.4e\n", + elt_list[j].elt->name, (double)elt_list[j].coef)); } -/* - * Accumulate elements in diffuse layer - */ - add_elt_list(s_x[j]->next_elt, moles_surface); - } -/* - strcpy(token, s_h2o->name); - ptr = &(token[0]); - get_elts_in_species (&ptr, mass_water_surface / gfw_water); - */ - if (count_elts > 0) - { - qsort(elt_list, (size_t) count_elts, - (size_t) sizeof(struct elt_list), elt_list_compare); - elt_list_combine(); - } -/* - * Print totals - */ - if (use.Get_surface_ptr()->Get_dl_type() != cxxSurface::DONNAN_DL) - { - output_msg(sformatf( - "\n\tTotal moles in diffuse layer (excluding water)\n\n")); - } - else - { - LDBLE exp_g = charge_ptr->Get_g_map()[1].Get_g() * mass_water_aq_x / mass_water_surface + 1; - LDBLE psi_DL = -log(exp_g) * R_KJ_DEG_MOL * tk_x / F_KJ_V_EQ; - output_msg(sformatf( - "\n\tTotal moles in diffuse layer (excluding water), Donnan calculation.")); - output_msg(sformatf( - "\n\tDonnan Layer potential, psi_DL = %10.3e V.\n\tBoltzmann factor, exp(-psi_DL * F / RT) = %9.3e (= c_DL / c_free if z is +1).\n\n", - psi_DL, exp_g)); - } - output_msg(sformatf("\tElement \t Moles\n")); - for (j = 0; j < count_elts; j++) - { - output_msg(sformatf("\t%-14s\t%12.4e\n", - elt_list[j].elt->name, (double) elt_list[j].coef)); } return (OK); } @@ -2987,7 +2989,7 @@ punch_identifiers(void) else if (state == TRANSPORT) { fpunchf(PHAST_NULL("dist_x"), gformat, - (double) cell_data[cell - 1].mid_cell_x); + (double) cell_data[cell].mid_cell_x); } else { From e6a13b700419556374fade8987017d067a79f631 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 May 2017 20:00:03 +0000 Subject: [PATCH 1061/1077] Error when reading PHASES and -no_check was read instead of equation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12702 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 9 +++++++++ tidy.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/read.cpp b/read.cpp index 200b11c1..01f454c8 100644 --- a/read.cpp +++ b/read.cpp @@ -3996,6 +3996,15 @@ read_phases(void) return_value = j; break; } + if (j == OPTION) + { + parse_error++; + error_string = sformatf("Expecting equation for phase %s.", token); + error_msg(error_string, CONTINUE); + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } if (parse_eq(line, &next_elt, association) == ERROR) { parse_error++; diff --git a/tidy.cpp b/tidy.cpp index d641a570..2575e572 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3762,12 +3762,22 @@ tidy_min_exchange(void) } int l; struct phase *phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE); + if (phase_ptr != NULL) { char * temp_formula = string_duplicate(phase_ptr->formula); ptr = temp_formula; get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } + else + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", + comp_ref.Get_phase_name().c_str(), comp_ref.Get_formula().c_str(), n); + error_msg(error_string, CONTINUE); + continue; + } qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); elt_list_combine(); From 5812e21193f2b7a021a2c17c316437a5f13e9388 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 10 May 2017 20:03:07 +0000 Subject: [PATCH 1062/1077] Synced to PHREEQC3 12702 Error when reading PHASES and -no_check was read instead of equation. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12703 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- read.cpp | 9 +++++++++ tidy.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/read.cpp b/read.cpp index d47ee76c..862b1177 100644 --- a/read.cpp +++ b/read.cpp @@ -4023,6 +4023,15 @@ read_phases(void) return_value = j; break; } + if (j == OPTION) + { + parse_error++; + error_string = sformatf("Expecting equation for phase %s.", token); + error_msg(error_string, CONTINUE); + error_msg("Parsing equation.", CONTINUE); + error_msg(line_save, CONTINUE); + break; + } if (parse_eq(line, &next_elt, association) == ERROR) { parse_error++; diff --git a/tidy.cpp b/tidy.cpp index d641a570..2575e572 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3762,12 +3762,22 @@ tidy_min_exchange(void) } int l; struct phase *phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE); + if (phase_ptr != NULL) { char * temp_formula = string_duplicate(phase_ptr->formula); ptr = temp_formula; get_elts_in_species(&ptr, 1.0); free_check_null(temp_formula); } + else + { + input_error++; + error_string = sformatf( + "Mineral, %s, related to exchanger, %s, not found in Equilibrium_Phases %d", + comp_ref.Get_phase_name().c_str(), comp_ref.Get_formula().c_str(), n); + error_msg(error_string, CONTINUE); + continue; + } qsort(elt_list, (size_t) count_elts, (size_t) sizeof(struct elt_list), elt_list_compare); elt_list_combine(); From 29a5848dbb60fdd29f3216c9ac08a4c35044506c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 23 May 2017 19:37:55 +0000 Subject: [PATCH 1063/1077] Tony's fix for LG function for exchange. New test case ExchangeGamma for fix. User requested ability to show contributions to specific conductance. Wrote a Basic program that calculates Specific Conductance (same as SC Basic function) but also shows species contributions to the specific conductance. PercentSC test case added. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12711 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index fd12a91e..608b099a 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -45,12 +45,14 @@ activity_coefficient(const char *species_name) /* ---------------------------------------------------------------------- */ { struct species *s_ptr; - LDBLE g; + LDBLE g, dum = 0.0; s_ptr = s_search(species_name); if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { - g = pow((LDBLE) 10., s_ptr->lg); + if (s_ptr->type == EX && s_ptr->equiv && s_ptr->alk) + dum = log10(s_ptr->equiv / s_ptr->alk); + g = pow((LDBLE) 10., s_ptr->lg - dum); } else { @@ -65,12 +67,14 @@ log_activity_coefficient(const char *species_name) /* ---------------------------------------------------------------------- */ { struct species *s_ptr; - LDBLE g; + LDBLE g, dum = 0.0; s_ptr = s_search(species_name); if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { - g = s_ptr->lg; + if (s_ptr->type == EX && s_ptr->equiv && s_ptr->alk) + dum = log10(s_ptr->equiv / s_ptr->alk); + g = s_ptr->lg - dum; } else { From bdd21cd12a5cc596e5325a17f135156fa2d2a3bd Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 23 May 2017 19:43:24 +0000 Subject: [PATCH 1064/1077] Tony's fix for LG function for exchange. New test case ExchangeGamma for fix. User requested ability to show contributions to specific conductance. Wrote a Basic program that calculates Specific Conductance (same as SC Basic function) but also shows species contributions to the specific conductance. PercentSC test case added. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12712 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- basicsubs.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 5390c0af..d97392e9 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -45,12 +45,14 @@ activity_coefficient(const char *species_name) /* ---------------------------------------------------------------------- */ { struct species *s_ptr; - LDBLE g; + LDBLE g, dum = 0.0; s_ptr = s_search(species_name); if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { - g = pow((LDBLE) 10., s_ptr->lg); + if (s_ptr->type == EX && s_ptr->equiv && s_ptr->alk) + dum = log10(s_ptr->equiv / s_ptr->alk); + g = pow((LDBLE) 10., s_ptr->lg - dum); } else { @@ -65,12 +67,14 @@ log_activity_coefficient(const char *species_name) /* ---------------------------------------------------------------------- */ { struct species *s_ptr; - LDBLE g; + LDBLE g, dum = 0.0; s_ptr = s_search(species_name); if (s_ptr != NULL && s_ptr->in != FALSE && ((s_ptr->type < EMINUS) || (s_ptr->type == EX) || (s_ptr->type == SURF))) { - g = s_ptr->lg; + if (s_ptr->type == EX && s_ptr->equiv && s_ptr->alk) + dum = log10(s_ptr->equiv / s_ptr->alk); + g = s_ptr->lg - dum; } else { From 299188f3cef5e888252bcc1f0444db53121eec0c Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Wed, 30 Aug 2017 19:36:32 +0000 Subject: [PATCH 1065/1077] Fixed dist_x function for transport. Added dist_x test case. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@12814 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print.cpp b/print.cpp index 3f49850e..9ef2fdb9 100644 --- a/print.cpp +++ b/print.cpp @@ -2989,7 +2989,7 @@ punch_identifiers(void) else if (state == TRANSPORT) { fpunchf(PHAST_NULL("dist_x"), gformat, - (double) cell_data[cell].mid_cell_x); + (double) cell_data[cell - 1].mid_cell_x); } else { From b5ef46d09aebe21a22832d1f49ae92bacfe5bfba Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 28 Sep 2017 21:48:05 +0000 Subject: [PATCH 1066/1077] Tony's changes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12858 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Phreeqc.cpp | 2 +- class_main.cpp | 8 ++++---- common/PHRQ_io.cpp | 13 ++++++++----- gases.cpp | 5 +++-- model.cpp | 2 +- parse.cpp | 6 +++--- prep.cpp | 3 +-- read.cpp | 5 +++++ readtr.cpp | 6 +++--- transport.cpp | 10 +++++----- 10 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index dada2c4f..55e52146 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -725,7 +725,7 @@ void Phreeqc::init(void) #ifdef USE_LONG_DOUBLE /* from float.h, sets tolerance for cl1 routine */ ineq_tol = pow((long double) 10, (long double) -LDBL_DIG); -#elif WIN32 +#elif NPP // appt: ineq_tol = pow((double) 10, (double) -DBL_DIG + 2); #else diff --git a/class_main.cpp b/class_main.cpp index 8fa49a4d..ba94562b 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -277,7 +277,7 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.3.9 AmpŠre"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.4.0 AmpŠre"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -301,7 +301,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "November 23, 2016"); + len = sprintf(buffer, "%s", "September 19, 2017"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif @@ -491,12 +491,12 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - //output_msg(sformatf("Using PHREEQC: version 3.2.2a Ampère, compiled March 9, 2016\n")); + //output_msg(sformatf("Using PHREEQC: version 3.4.0 Ampère, compiled September 19, 2017\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.3.9 Ampère, compiled November 23, 2016\n")); + output_msg(sformatf("Using PHREEQC: version 3.4.0 Ampère, compiled September 19, 2017\n")); #endif output_msg(sformatf("Database file: %s\n\n", token)); #ifdef NPP diff --git a/common/PHRQ_io.cpp b/common/PHRQ_io.cpp index fd2d4cd0..ab34f8c1 100644 --- a/common/PHRQ_io.cpp +++ b/common/PHRQ_io.cpp @@ -32,13 +32,13 @@ PHRQ_io(void) punch_on = true; error_on = true; dump_on = true; - echo_on = true; + echo_on = true; //**appt screen_on = true; echo_destination = ECHO_OUTPUT; m_next_keyword = Keywords::KEY_NONE; accumulate = false; - m_line_type = PHRQ_io::LT_EMPTY; + m_line_type = PHRQ_io::LT_EMPTY; } PHRQ_io:: @@ -470,7 +470,7 @@ fpunchf_helper(std::ostream *os, const char *format, ...) { size_t alloc_buffer_size = STACK_MAX * 2; char *alloc_buffer = new char[alloc_buffer_size]; - do + do { va_list args; va_start(args, format); @@ -515,7 +515,7 @@ fpunchf_helper(std::string *str, const char *format, ...) { size_t alloc_buffer_size = STACK_MAX * 2; char *alloc_buffer = new char[alloc_buffer_size]; - do + do { va_list args; va_start(args, format); @@ -784,7 +784,7 @@ get_line(void) if (!next_stream->is_open()) { std::ostringstream errstr; - errstr << "\n*********** Could not open include file " << file_name + errstr << "\n*********** Could not open include file " << file_name <<".\n Please, write the full path to this file. ***********\n\n"; delete next_stream; #if defined(PHREEQCI_GUI) @@ -798,6 +798,9 @@ get_line(void) else { this->push_istream(next_stream); + std::ostringstream errstr; + errstr << "\n\tReading data from " << file_name <<" ...\n"; + output_msg(errstr.str().c_str()); // **appt } continue; } diff --git a/gases.cpp b/gases.cpp index 7b60f76c..871d41a9 100644 --- a/gases.cpp +++ b/gases.cpp @@ -588,8 +588,9 @@ calc_PR(void) if (rz > B) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * - log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); - phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); + log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); + if (phi > 4.44) + phi = 4.44; } else phi = -3.0; // fugacity coefficient > 0.05 diff --git a/model.cpp b/model.cpp index 52fef802..818bfdff 100644 --- a/model.cpp +++ b/model.cpp @@ -680,7 +680,7 @@ gammas(LDBLE mu) case 4: /* Exchange */ /* * Find CEC - * z contains valence of cation for exchange species, alk contains cec + * z contains charge of cation for exchange species, alk contains cec */ /* !!!!! */ for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++) diff --git a/parse.cpp b/parse.cpp index 5904b604..cf149a4d 100644 --- a/parse.cpp +++ b/parse.cpp @@ -237,7 +237,7 @@ check_eqn(int association) */ if (equal(sumcharge, 0.0, TOL) == FALSE) { - error_string = sformatf( "Equation is not charge balanced."); + error_string = sformatf( "Equation is not charge balanced, right - left = %7.4f moles charge", sumcharge); error_msg(error_string, CONTINUE); oops++; } @@ -250,8 +250,8 @@ check_eqn(int association) strncmp((elt_list[i].elt)->name, "e", MAX_LENGTH) != 0) { error_string = sformatf( - "Equation does not balance for element, %s.", - (elt_list[i].elt)->name); + "Equation does not balance for element, %s: right - left = %7.4f moles", + (elt_list[i].elt)->name, elt_list[i].coef); error_msg(error_string, CONTINUE); oops++; } diff --git a/prep.cpp b/prep.cpp index e35d42e3..d5042be2 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4151,8 +4151,7 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); - if (phi > 4.44) - phi = 4.44; + phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); } else phi = -3.0; // fugacity coefficient > 0.05 diff --git a/read.cpp b/read.cpp index 862b1177..405cb7d8 100644 --- a/read.cpp +++ b/read.cpp @@ -45,6 +45,7 @@ read_input(void) Rxn_new_ss_assemblage.clear(); Rxn_new_surface.clear(); Rxn_new_temperature.clear(); // not used + phrq_io->Set_echo_on(true); // **appt /* * Initialize keyword counters */ @@ -8684,6 +8685,10 @@ read_print(void) break; case 31: /* echo_input */ pr.echo_input = get_true_false(next_char, TRUE); + if (pr.echo_input == 0) + phrq_io->Set_echo_on(false); + else + phrq_io->Set_echo_on(true); //**appt break; case 32: /* warning */ case 33: /* warnings */ diff --git a/readtr.cpp b/readtr.cpp index 724c3ad1..505dfa60 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -672,7 +672,7 @@ read_transport(void) if (copy_token(token, &next_char, &l) == DIGIT) { sscanf(token, SCANFORMAT, &fix_current); - fix_current = fabs(fix_current); +// fix_current = fabs(fix_current); } else { @@ -816,7 +816,7 @@ read_transport(void) */ if (count_por == 0) { - if (old_cells < all_cells && multi_Dflag) + if (old_cells < all_cells && multi_Dflag && simul_tr == 1) { multi_Dpor = (multi_Dpor < 1e-10 ? 1e-10 : multi_Dpor); if (multi_Dpor > 1e-10) @@ -824,7 +824,7 @@ read_transport(void) "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); else error_string = sformatf( - "No porosities were read; used the value %8.2e from -multi_D.", multi_Dpor); + "No porosities were read; set to minimal value of 1e-10 for -multi_D."); warning_msg(error_string); for (i = 1; i < all_cells; i++) cell_data[i].por = multi_Dpor; diff --git a/transport.cpp b/transport.cpp index 3ce5b820..22f567c9 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,4 +1,4 @@ -#include "Utils.h" +#include "Utils.h" #include "Phreeqc.h" #include "phqalloc.h" #include "Exchange.h" @@ -132,7 +132,7 @@ transport(void) moles_added[i].moles = 0; } } - try + try { /* check solution 0 */ use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, 0)); @@ -228,7 +228,7 @@ transport(void) "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); warning_msg(error_string); } - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) (count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) malloc_error(); @@ -2118,7 +2118,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Get_solution_ptr()->Set_total_o(dummy + tot2_o); if (i == count_cells && fix_current && !stagnant) { - use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); + use.Get_solution_ptr()->Set_potV(cell_data[jcell].potV); } for (l = 0; l < count_m_s; l++) { @@ -4731,7 +4731,7 @@ viscosity(void) Jones_Dole[6] contains the anion factor, 1 for Cl-, variable for other anions f_z = (z * z + |z|) / 2, the contribution of the ion to mu_x, if z = 0: f_z = mu_x / m_i f_I = variable, depends on d3_i > 1, or d3_i < 1. - tc is limited to 200°C. + tc is limited to 200�C. A from Falkenhagen-Dole for a salt: From 077abe0106b2c1d44d8e996d62ae3e8b2c23bf62 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Thu, 28 Sep 2017 21:48:05 +0000 Subject: [PATCH 1067/1077] Tony's changes. git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12858 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- PHRQ_io.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/PHRQ_io.cpp b/PHRQ_io.cpp index fd2d4cd0..ab34f8c1 100644 --- a/PHRQ_io.cpp +++ b/PHRQ_io.cpp @@ -32,13 +32,13 @@ PHRQ_io(void) punch_on = true; error_on = true; dump_on = true; - echo_on = true; + echo_on = true; //**appt screen_on = true; echo_destination = ECHO_OUTPUT; m_next_keyword = Keywords::KEY_NONE; accumulate = false; - m_line_type = PHRQ_io::LT_EMPTY; + m_line_type = PHRQ_io::LT_EMPTY; } PHRQ_io:: @@ -470,7 +470,7 @@ fpunchf_helper(std::ostream *os, const char *format, ...) { size_t alloc_buffer_size = STACK_MAX * 2; char *alloc_buffer = new char[alloc_buffer_size]; - do + do { va_list args; va_start(args, format); @@ -515,7 +515,7 @@ fpunchf_helper(std::string *str, const char *format, ...) { size_t alloc_buffer_size = STACK_MAX * 2; char *alloc_buffer = new char[alloc_buffer_size]; - do + do { va_list args; va_start(args, format); @@ -784,7 +784,7 @@ get_line(void) if (!next_stream->is_open()) { std::ostringstream errstr; - errstr << "\n*********** Could not open include file " << file_name + errstr << "\n*********** Could not open include file " << file_name <<".\n Please, write the full path to this file. ***********\n\n"; delete next_stream; #if defined(PHREEQCI_GUI) @@ -798,6 +798,9 @@ get_line(void) else { this->push_istream(next_stream); + std::ostringstream errstr; + errstr << "\n\tReading data from " << file_name <<" ...\n"; + output_msg(errstr.str().c_str()); // **appt } continue; } From a46a85a9f0faea86e51d6d5cecbb5c1cdaf40781 Mon Sep 17 00:00:00 2001 From: David L Parkhurst Date: Tue, 3 Oct 2017 20:55:36 +0000 Subject: [PATCH 1068/1077] Making consistent phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete@12860 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- gases.cpp | 3 +-- prep.cpp | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gases.cpp b/gases.cpp index 871d41a9..77a484ce 100644 --- a/gases.cpp +++ b/gases.cpp @@ -589,8 +589,7 @@ calc_PR(void) { phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); - if (phi > 4.44) - phi = 4.44; + phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); } else phi = -3.0; // fugacity coefficient > 0.05 diff --git a/prep.cpp b/prep.cpp index d5042be2..302554ea 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4152,6 +4152,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) phi = B_r * (rz - 1) - log(rz - B) + A / (2.828427 * B) * (B_r - 2.0 * phase_ptr->pr_aa_sum2 / a_aa_sum) * log((rz + 2.41421356 * B) / (rz - 0.41421356 * B)); phi = (phi > 4.44 ? 4.44 : (phi < -3 ? -3 : phi)); + //if (phi > 4.44) + // phi = 4.44; } else phi = -3.0; // fugacity coefficient > 0.05 From db60ab0e3a9c0927663742f11407c6f198c0d91f Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 31 Oct 2017 19:55:15 +0000 Subject: [PATCH 1069/1077] fixed to compile in vs2005 git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete-2005@12903 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Form1.2005.resX | 33 +++++++++++++++++++++++++++++++++ Form1.h | 5 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Form1.2005.resX diff --git a/Form1.2005.resX b/Form1.2005.resX new file mode 100644 index 00000000..fc36b375 --- /dev/null +++ b/Form1.2005.resX @@ -0,0 +1,33 @@ + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAP8AMzOaAGgymgA0Mc0AmWVoAGdlmwBjZssAy5kvAP+ZNQDLmmMAzpmVAP/MLQDLzWUA/8xjAP3/ + mAAAAAAAiIiIiIiIiIiIgAAIhIiIhHAAAAB3KXcXcAeQAAeTk5fQDd0ADdoK3b27uwALugm7u7u7AAtz + k9vbuwAAu2u7Xbu7AAva29u5zMzAAMzMzMzu7u4ADu7szOAO7gAO7u7u4ADuAA7u7u7uAAAA7u7u7u7g + AA7u7u7u7u7u7u7u7u4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA + + + \ No newline at end of file diff --git a/Form1.h b/Form1.h index 0c9e5162..76379b37 100644 --- a/Form1.h +++ b/Form1.h @@ -1134,8 +1134,11 @@ namespace zdg_ui2 { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); try { - //this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); +#ifdef NPP this->Icon = gcnew System::Drawing::Icon("c:\\phreeqc\\phreex.ico"); +#else + this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); +#endif } catch (...) { From 800f2345060ee3db595462e536239b9472c9a0fb Mon Sep 17 00:00:00 2001 From: Scott R Charlton Date: Tue, 31 Oct 2017 20:38:32 +0000 Subject: [PATCH 1070/1077] added Form1.2005.resX to configure dist git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/branches/concrete-2005@12904 1feff8c3-07ed-0310-ac33-dd36852eb9cd --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index b7321931..b7651924 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ EXTRA_DIST=\ CurveObject.cpp\ CurveObject.h\ Form1.h\ + Form1.2005.resX\ Form1.resX\ ZedGraph.dll From fa7a3c7192cc15ff8c8473b7cd972629d3036113 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sat, 17 Feb 2018 20:09:31 -0700 Subject: [PATCH 1071/1077] Tony's changes and bug fixes --- Phreeqc.h | 4 + SolutionIsotope.cxx | 4 + basicsubs.cpp | 4 + class_main.cpp | 9 +- inverse.cpp | 18 +++ isotopes.cpp | 12 ++ kinetics.cpp | 12 +- mainsubs.cpp | 5 +- phreex.ico | Bin 318 -> 318 bytes print.cpp | 11 +- readtr.cpp | 7 +- spread.cpp | 2 + step.cpp | 5 +- tidy.cpp | 16 +++ transport.cpp | 323 +++++++++++++++++++++++++++----------------- 15 files changed, 289 insertions(+), 143 deletions(-) diff --git a/Phreeqc.h b/Phreeqc.h index fe28512a..d02e2326 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -7,6 +7,9 @@ #define _CRTDBG_MAP_ALLOC #include #endif +#ifndef boolean +typedef unsigned char boolean; +#endif /* ---------------------------------------------------------------------- * INCLUDE FILES * ---------------------------------------------------------------------- */ @@ -1049,6 +1052,7 @@ public: // transport.cpp ------------------------------- int transport(void); + void print_punch(int i, boolean active); int set_initial_moles(int i); cxxSurface sum_surface_comp(cxxSurface *source1, LDBLE f1, cxxSurface *source2, std::string charge_name, LDBLE f2, diff --git a/SolutionIsotope.cxx b/SolutionIsotope.cxx index ecf72c4c..d37c90c7 100644 --- a/SolutionIsotope.cxx +++ b/SolutionIsotope.cxx @@ -59,7 +59,11 @@ cxxSolutionIsotope::dump_xml(std::ostream & s_oss, unsigned int indent) const s_oss << indent1; s_oss << "iso_ratio=\"" << this->ratio << "\"" << "\n"; +#ifdef NPP + if (!isnan(this->ratio_uncertainty)) +#else if (this->ratio_uncertainty != NAN) +#endif { s_oss << indent1; s_oss << "iso_ratio_uncertainty=\"" << this-> diff --git a/basicsubs.cpp b/basicsubs.cpp index 608b099a..0e4c7e85 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -1432,7 +1432,11 @@ get_calculate_value(const char *name) calculate_value_ptr->name); error_msg(error_string, STOP); } +#ifdef NPP + if (isnan(rate_moles)) +#else if (rate_moles == NAN) +#endif { error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); diff --git a/class_main.cpp b/class_main.cpp index ba94562b..bc16d111 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -277,7 +277,8 @@ write_banner(void) /* version */ #ifdef NPP - len = sprintf(buffer, "* PHREEQC-%s *", "3.4.0 AmpŠre"); + //len = sprintf(buffer, "* PHREEQC-%s *", "3.4.1 AmpŠre"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.4.1"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -301,7 +302,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "September 19, 2017"); + len = sprintf(buffer, "%s", "February 15, 2018"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif @@ -491,12 +492,12 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - //output_msg(sformatf("Using PHREEQC: version 3.4.0 Ampère, compiled September 19, 2017\n")); + //output_msg(sformatf("Using PHREEQC: version 3.4.1 Ampère, compiled February 15, 2018\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.4.0 Ampère, compiled September 19, 2017\n")); + output_msg(sformatf("Using PHREEQC: version 3.4.1, compiled February 15, 2018\n")); #endif output_msg(sformatf("Database file: %s\n\n", token)); #ifdef NPP diff --git a/inverse.cpp b/inverse.cpp index b0d6686f..f9f500e9 100644 --- a/inverse.cpp +++ b/inverse.cpp @@ -3777,21 +3777,35 @@ check_isotopes(struct inverse *inv_ptr) i = ii; /* use inverse-defined uncertainties first */ +#ifdef NPP + if (j < inv_ptr->i_u[i].count_uncertainties + && !isnan(inv_ptr->i_u[i].uncertainties[j])) +#else if (j < inv_ptr->i_u[i].count_uncertainties && inv_ptr->i_u[i].uncertainties[j] != NAN) +#endif { kit->second.Set_x_ratio_uncertainty(inv_ptr->i_u[i].uncertainties[j]); /* use solution-defined uncertainties second */ } +#ifdef NPP + else if (inv_ptr->i_u[i].count_uncertainties > 0 + && !isnan(inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1])) +#else else if (inv_ptr->i_u[i].count_uncertainties > 0 && inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1] != NAN) +#endif { kit->second.Set_x_ratio_uncertainty(inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1]); /* use solution-defined uncertainties second */ } +#ifdef NPP + else if (!isnan(kit->second.Get_ratio_uncertainty())) +#else else if (kit->second.Get_ratio_uncertainty() != NAN) +#endif { kit->second.Set_x_ratio_uncertainty( kit->second.Get_ratio_uncertainty()); @@ -3819,7 +3833,11 @@ check_isotopes(struct inverse *inv_ptr) } } } +#ifdef NPP + if (isnan(kit->second.Get_x_ratio_uncertainty())) +#else if (kit->second.Get_x_ratio_uncertainty() == NAN) +#endif { error_string = sformatf( "In solution %d, isotope ratio uncertainty is needed for element: %g%s.", diff --git a/isotopes.cpp b/isotopes.cpp index a1fb2ec5..4ced82a5 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -938,7 +938,11 @@ punch_calculate_values(void) calculate_value_ptr->name); error_msg(error_string, STOP); } +#ifdef NPP + if (isnan(rate_moles)) +#else if (rate_moles == NAN) +#endif { error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); @@ -1207,7 +1211,11 @@ calculate_values(void) calculate_value_ptr->name); error_msg(error_string, STOP); } +#ifdef NPP + if (isnan(rate_moles)) +#else if (rate_moles == NAN) +#endif { error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); @@ -1270,7 +1278,11 @@ calculate_values(void) calculate_value_ptr->name); error_msg(error_string, STOP); } +#ifdef NPP + if (isnan(rate_moles)) +#else if (rate_moles == NAN) +#endif { error_string = sformatf( "Calculated value not SAVEed for %s.", calculate_value_ptr->name); diff --git a/kinetics.cpp b/kinetics.cpp index 1439a33b..9b50c43e 100644 --- a/kinetics.cpp +++ b/kinetics.cpp @@ -106,7 +106,11 @@ calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step) kinetics_comp_ptr->Get_rate_name().c_str()); error_msg(error_string, STOP); } +#ifdef NPP + if (isnan(rate_moles)) +#else if (rate_moles == NAN) +#endif { error_string = sformatf( "Moles of reaction not SAVEed for %s.", kinetics_comp_ptr->Get_rate_name().c_str()); @@ -1692,8 +1696,8 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { - error_string = sformatf( "Solution %d not found.", - use.Get_n_solution_user()); + error_string = sformatf( "Solution %d not found, while searching mix structure for solution %d.", + i, use.Get_n_solution_user()); error_msg(error_string, STOP); } use.Set_n_solution_user(i); @@ -1705,8 +1709,8 @@ set_transport(int i, int use_mix, int use_kinetics, int nsaver) use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, i)); if (use.Get_solution_ptr() == NULL) { - error_string = sformatf( "Solution %d not found.", - use.Get_n_solution_user()); + error_string = sformatf( "Solution %d not found, while searching mix structure for solution %d.", + i, use.Get_n_solution_user()); error_msg(error_string, STOP); } use.Set_n_solution_user(i); diff --git a/mainsubs.cpp b/mainsubs.cpp index 4e72ac01..5d43fa0e 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -632,7 +632,9 @@ initial_solutions(int print) LDBLE d1 = 0; bool diag = (diagonal_scale == TRUE) ? true : false; int count_iterations = 0; - for (;;) + std::string input_units = solution_ref.Get_initial_data()->Get_units(); + cxxISolution *initial_data_ptr = solution_ref.Get_initial_data(); + for (;;) { prep(); k_temp(solution_ref.Get_tc(), solution_ref.Get_patm()); @@ -653,6 +655,7 @@ initial_solutions(int print) solution_ref.Set_density(calc_dens()); if (!equal(d0, solution_ref.Get_density(), 1e-8)) { + initial_data_ptr->Set_units(input_units); d0 = solution_ref.Get_density(); if (count_iterations++ < 20) { diff --git a/phreex.ico b/phreex.ico index 65cd87ba82d0f706b3c453b4970c8a72188fca81..8044dda4bdebd3d953d6d54ea920797863f12a78 100644 GIT binary patch delta 20 acmdnTw2z6Kfq@YS1q1{b7&dYnGXel2Bm%Ag delta 20 acmdnTw2z6Kfq@YS1q1{b7&meoGXel2DFUwm diff --git a/print.cpp b/print.cpp index 55419060..9c5abce7 100644 --- a/print.cpp +++ b/print.cpp @@ -2286,13 +2286,14 @@ print_totals(void) "Total alkalinity (eq/kg) = ", (double) (total_alkalinity / mass_water_aq_x))); } - if (carbon_unknown == NULL) + if (carbon_unknown == NULL && total_carbon > 0.0) { output_msg(sformatf("%45s%11.3e\n", "Total carbon (mol/kg) = ", (double) (total_carbon / mass_water_aq_x))); } - output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", + if (total_co2 > 0.0) + output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", (double) (total_co2 / mass_water_aq_x))); #ifdef NO_UTF8_ENCODING output_msg(sformatf("%45s%6.2f\n", "Temperature (oC) = ", @@ -2308,6 +2309,12 @@ print_totals(void) (double) patm_x)); } + if (potV_x != 0.0) + { + output_msg(sformatf("%45s%5.2f\n", "Electrical Potential (Volt) = ", + (double)potV_x)); + } + output_msg(sformatf("%45s%11.3e\n", "Electrical balance (eq) = ", (double) cb_x)); output_msg(sformatf("%45s%6.2f\n", diff --git a/readtr.cpp b/readtr.cpp index 505dfa60..f63d76d6 100644 --- a/readtr.cpp +++ b/readtr.cpp @@ -3,8 +3,9 @@ #include #include "StorageBin.h" #include "SS.h" - +#ifndef boolean typedef unsigned char boolean; +#endif #include "Phreeqc.h" #include "phqalloc.h" #include "Utils.h" @@ -905,7 +906,7 @@ read_transport(void) } } else if (simul_tr == 1) - for (i = 1; i < all_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].punch = TRUE; /* * Fill in data for print @@ -928,7 +929,7 @@ read_transport(void) } } else if (simul_tr == 1) - for (i = 1; i < all_cells; i++) + for (i = 0; i < all_cells; i++) cell_data[i].print = TRUE; //#define OLD_POROSITY #if defined(OLD_POROSITY) diff --git a/spread.cpp b/spread.cpp index a6f90787..8720fd56 100644 --- a/spread.cpp +++ b/spread.cpp @@ -1,4 +1,6 @@ +#ifndef boolean typedef unsigned char boolean; +#endif #include "Phreeqc.h" #include "phqalloc.h" #include "Solution.h" diff --git a/step.cpp b/step.cpp index fd316275..4aeda1f3 100644 --- a/step.cpp +++ b/step.cpp @@ -54,6 +54,7 @@ step(LDBLE step_fraction) else if (use.Get_solution_ptr() != NULL) { add_solution(use.Get_solution_ptr(), 1.0, 1.0); + cell_no = use.Get_n_solution_user(); } else { @@ -1470,8 +1471,8 @@ solution_check(void) master_ptr->elt->name, (LDBLE) master_ptr->total); */ error_string = sformatf( - "Negative moles in solution for %s, %e. Recovering...", - master_ptr->elt->name, (double) master_ptr->total); + "Negative moles in solution %d for %s, %e. Recovering...", + cell_no, master_ptr->elt->name, (double) master_ptr->total); warning_msg(error_string); return (MASS_BALANCE); } diff --git a/tidy.cpp b/tidy.cpp index 2575e572..d307a71b 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -924,7 +924,11 @@ tidy_gas_phase(void) error_msg(error_string, CONTINUE); } /* calculate moles */ +#ifdef NPP + if (!isnan(gas_phase_ptr->Get_gas_comps()[j].Get_p_read())) +#else if (gas_phase_ptr->Get_gas_comps()[j].Get_p_read() != NAN) +#endif { P += gas_phase_ptr->Get_gas_comps()[j].Get_p_read(); if (!PR) @@ -948,7 +952,11 @@ tidy_gas_phase(void) */ if (!gas_phase_ptr->Get_solution_equilibria()) { +#ifdef NPP + if (!isnan(gas_phase_ptr->Get_gas_comps()[j].Get_p_read())) +#else if (gas_phase_ptr->Get_gas_comps()[j].Get_p_read() != NAN) +#endif { P += gas_phase_ptr->Get_gas_comps()[j].Get_p_read(); if (!PR) @@ -1810,7 +1818,11 @@ tidy_ss_assemblage(void) phase_ptr->moles_x = 0; phase_ptr->fraction_x = 0; } +#ifdef NPP + if (isnan(comp_ptr->Get_moles())) +#else if (comp_ptr->Get_moles() == NAN) +#endif { input_error++; error_string = sformatf( @@ -3505,7 +3517,11 @@ tidy_isotopes(void) temp_iso.Set_total(0); temp_iso.Set_ratio(master[k]->isotope_ratio); temp_iso.Set_ratio_uncertainty(master[k]->isotope_ratio_uncertainty); +#ifdef NPP + if (!isnan(master[k]->isotope_ratio_uncertainty)) +#else if (master[k]->isotope_ratio_uncertainty != NAN) +#endif { temp_iso.Set_ratio_uncertainty_defined(true); } diff --git a/transport.cpp b/transport.cpp index 22f567c9..19c2c1f4 100644 --- a/transport.cpp +++ b/transport.cpp @@ -88,7 +88,7 @@ transport(void) sol_D = (struct sol_D *) PHRQ_malloc((size_t) (all_cells)* sizeof(struct sol_D)); if (sol_D == NULL) malloc_error(); - sol_D_dbg = sol_D; + //sol_D_dbg = sol_D; ct = (struct CT *) PHRQ_malloc((size_t) (all_cells)* sizeof(struct CT)); if (ct == NULL) @@ -265,10 +265,7 @@ transport(void) { fill_spec(cell_no); } - if (cell_data[i].punch == TRUE) - punch_all(); - if (cell_data[i].print == TRUE) - print_all(); + print_punch(i, true); /* if (i > 0 && i <= count_cells)*/ saver(); @@ -290,11 +287,7 @@ transport(void) { fill_spec(cell_no); } - if (cell_data[k].punch == TRUE) - punch_all(); - if ((cell_data[k].print == TRUE) - && (transport_step % print_modulus == 0)) - print_all(); + print_punch(k, true); saver(); } } @@ -439,6 +432,9 @@ transport(void) /* * Now transport */ + sprintf(token, "\nCalculating transport: %d cells, %d shifts, %d mixruns...\n\n", + count_cells, count_shifts - transport_start + 1, nmix); + screen_msg(token); max_iter = 0; for (transport_step = transport_start; transport_step <= count_shifts; transport_step++) @@ -536,32 +532,21 @@ transport(void) status(0, token); if (i == 0 || i == count_cells + 1) - run_reactions(i, kin_time, NOMIX, step_fraction); + run_reactions(i, kin_time, NOMIX, step_fraction); // nsaver = i else - run_reactions(i, kin_time, DISP, step_fraction); + run_reactions(i, kin_time, DISP, step_fraction); // nsaver = -2 if (multi_Dflag) fill_spec(i); /* punch and output file */ - if ((ishift == 0) && (j == nmix) - && ((stag_data->count_stag == 0) || i == 0 - || (i == count_cells + 1 && stag_data->count_stag != 1) /* - || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0*/)) - { - if ((cell_data[i].punch == TRUE) - && (transport_step % punch_modulus == 0)) - punch_all(); - if ((cell_data[i].print == TRUE) - && (transport_step % print_modulus == 0)) - print_all(); - } + if (ishift == 0 && j == nmix && stag_data->count_stag == 0) + print_punch(i, true); if (i > 1) Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); saver(); /* maybe sorb a surface component... */ - if ((ishift == 0) && (j == nmix) - && ((stag_data->count_stag == 0) + if (ishift == 0 && j == nmix && (stag_data->count_stag == 0 || Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0)) { if (change_surf_count > 0) @@ -592,23 +577,26 @@ transport(void) if (stag_data->count_stag > 0) { - if ((ishift == 0) && (j == nmix)) + if (ishift == 0 && j == nmix) punch_boolean = TRUE; else punch_boolean = FALSE; - for (i = 1; i <= count_cells; i++) + for (i = 0; i <= count_cells + 1; i++) // allow for stagnant cell mixing with boundary cells { mix_stag(i, stagkin_time, punch_boolean, step_fraction); } - // i == 1 + count_cells... - if (stag_data->count_stag == 1 && punch_boolean) + } + if (ishift == 0 && j == nmix && stag_data->count_stag > 0) + { + for (n = 1; n <= stag_data->count_stag; n++) { - run_reactions(i, 0, NOMIX, 0); - cell_no = i; - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + if (Utilities::Rxn_find(Rxn_solution_map, k) == NULL) + continue; + print_punch(k, false); + } } } } @@ -725,19 +713,14 @@ transport(void) fill_spec(i); if (iterations > max_iter) max_iter = iterations; - if ((nmix == 0) && ((stag_data->count_stag == 0))) - { - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } + if (nmix == 0 && stag_data->count_stag == 0) + print_punch(i, true); if (i == first_c && count_cells > 1) kin_time = kin_time_save; saver(); /* maybe sorb a surface component... */ - if ((nmix == 0) && ((stag_data->count_stag == 0) || + if (nmix == 0 && (stag_data->count_stag == 0 || (Utilities::Rxn_find(Rxn_solution_map, i + 1 + count_cells) == 0))) { if (change_surf_count > 0) @@ -764,6 +747,19 @@ transport(void) mix_stag(i, stagkin_time, TRUE, step_fraction); } } + if (nmix == 0 && stag_data->count_stag > 0) + { + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + if (Utilities::Rxn_find(Rxn_solution_map, k) == NULL) + continue; + print_punch(k, false); + } + } + } } /* * Further dispersive and diffusive transport @@ -838,14 +834,8 @@ transport(void) run_reactions(i, kin_time, DISP, step_fraction); if (multi_Dflag == TRUE) fill_spec(i); - if (j == nmix && (stag_data->count_stag == 0 || i == 0 - || (i == 1 + count_cells && stag_data->count_stag != 1))) - { - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } + if (j == nmix && stag_data->count_stag == 0) + print_punch(i, true); if (i > 1) Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1); saver(); @@ -885,20 +875,21 @@ transport(void) punch_boolean = TRUE; else punch_boolean = FALSE; - for (i = 1; i <= count_cells; i++) - { + for (i = 0; i <= count_cells + 1; i++) // allow for stagnant cell mixing with boundary cells mix_stag(i, stagkin_time, punch_boolean, step_fraction); - } } - // i == 1 + count_cells... - if (stag_data->count_stag == 1 && punch_boolean) + if (j == nmix && stag_data->count_stag > 0) { - run_reactions(i, 0, NOMIX, 0); - cell_no = i; - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); + for (n = 1; n <= stag_data->count_stag; n++) + { + for (i = 1; i <= count_cells; i++) + { + k = i + 1 + n * count_cells; + if (Utilities::Rxn_find(Rxn_solution_map, k) == NULL) + continue; + print_punch(k, false); + } + } } } if (dump_modulus != 0 && (transport_step % dump_modulus) == 0) @@ -979,6 +970,31 @@ transport_cleanup(void) } current_cells = (struct CURRENT_CELLS *) free_check_null(current_cells); } +/* ---------------------------------------------------------------------- */ +void Phreeqc:: +print_punch(int i, boolean active) +/* ---------------------------------------------------------------------- */ +{ + if (!(cell_data[i].punch && (transport_step % punch_modulus == 0)) && + !(cell_data[i].print && (transport_step % print_modulus == 0)) || + (bcon_first == 2 && i == 0) || + (bcon_last == 2 && i == count_cells + 1)) + return; + if (!active) + run_reactions(i, 0, NOMIX, 0); + cell_no = i; + use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); + if (use.Get_kinetics_ptr() != NULL) + { + use.Set_n_kinetics_user(i); + use.Set_kinetics_in(true); + } + if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + punch_all(); + if (cell_data[i].print && (transport_step % print_modulus == 0)) + print_all(); +} + /* ---------------------------------------------------------------------- */ int Phreeqc:: init_mix(void) @@ -1244,13 +1260,38 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) int j, n, k; LDBLE t_imm; cxxSolution *ptr_imm, *ptr_m; + ptr_imm = NULL; /* * Kinetics in transport cell is done while transporting */ for (n = 1; n <= stag_data->count_stag; n++) { - k = i + 1 + n * count_cells; - if ((ptr_imm = Utilities::Rxn_find(Rxn_solution_map, k)) != NULL) + if (i == 0 || i == count_cells + 1) + { + use.Set_mix_ptr(NULL); + use.Set_mix_in(false); + use.Set_mix_ptr(Utilities::Rxn_find(Rxn_mix_map, i)); + if (use.Get_mix_ptr()) + { + for (std::map < int, LDBLE >::const_iterator it = use.Get_mix_ptr()->Get_mixComps().begin(); + it != use.Get_mix_ptr()->Get_mixComps().end(); it++) + { + if (it->first > i && it->first < all_cells) + { + k = it->first; + ptr_imm = Utilities::Rxn_find(Rxn_solution_map, k); + break; + } + } + } + } + else + { + k = i + 1 + n * count_cells; + if (k < all_cells) + ptr_imm = Utilities::Rxn_find(Rxn_solution_map, k); + } + if (ptr_imm != NULL) { if (n == 1) { @@ -1258,13 +1299,8 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) { ptr_m = Utilities::Rxn_find(Rxn_solution_map, i); t_imm = - heat_mix_f_imm * ptr_m->Get_tc() + (1 - - heat_mix_f_imm) * - ptr_imm->Get_tc(); - ptr_m->Set_tc( - heat_mix_f_m * ptr_imm->Get_tc() + (1 - - heat_mix_f_m) * - ptr_m->Get_tc()); + heat_mix_f_imm * ptr_m->Get_tc() + (1 - heat_mix_f_imm) * ptr_imm->Get_tc(); + ptr_m->Set_tc(heat_mix_f_m * ptr_imm->Get_tc() + (1 - heat_mix_f_m) * ptr_m->Get_tc()); cell_data[i].temp = ptr_m->Get_tc(); cell_data[k].temp = t_imm = ptr_imm->Get_tc(); /* equilibrate again ... */ @@ -1294,19 +1330,22 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); if (multi_Dflag == TRUE) fill_spec(cell_no); - use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); - if (use.Get_kinetics_ptr() != NULL) - { - use.Set_n_kinetics_user(i); - use.Set_kinetics_in(true); - } - if (l_punch && (cell_data[i].print == TRUE) && - (transport_step % print_modulus == 0)) - print_all(); - if (l_punch && (cell_data[i].punch == TRUE) && - (transport_step % punch_modulus == 0)) - punch_all(); + //use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); + //if (use.Get_kinetics_ptr() != NULL) + //{ + // use.Set_n_kinetics_user(i); + // use.Set_kinetics_in(true); + //} + //if (l_punch && (cell_data[i].print == TRUE) && + // (transport_step % print_modulus == 0)) + // print_all(); + //if (l_punch && (cell_data[i].punch == TRUE) && + // (transport_step % punch_modulus == 0)) + // punch_all(); + if (l_punch) + print_punch(i, true); saver(); + Utilities::Rxn_copy(Rxn_solution_map, -2, i); /* maybe sorb a surface component... */ if (l_punch && change_surf_count) @@ -1331,13 +1370,14 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) if (multi_Dflag == TRUE) fill_spec(cell_no); - if ((cell_data[k].print == TRUE) && (l_punch == TRUE) && - (transport_step % print_modulus == 0)) - print_all(); - if ((cell_data[k].punch == TRUE) && (l_punch == TRUE) && - (transport_step % punch_modulus == 0)) - punch_all(); + //if ((cell_data[k].print == TRUE) && (l_punch == TRUE) && i != 0 && + // (transport_step % print_modulus == 0)) + // print_all(); + //if ((cell_data[k].punch == TRUE) && (l_punch == TRUE) && i != 0 && + // (transport_step % punch_modulus == 0)) + // punch_all(); saver(); + Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); /* maybe sorb a surface component... */ if (l_punch && change_surf_count) @@ -1356,27 +1396,29 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) change_surf_count = 0; } } - else if (n == 1 && l_punch && (cell_data[i].punch || cell_data[i].print)) - { - cell_no = i; - run_reactions(i, 0, NOMIX, 0); - if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - punch_all(); - if (cell_data[i].print && (transport_step % print_modulus == 0)) - print_all(); - } + //else if (n == 1 && l_punch && (cell_data[i].punch || cell_data[i].print)) + //{ + // cell_no = i; + // run_reactions(i, 0, NOMIX, 0); + // if (cell_data[i].punch && (transport_step % punch_modulus == 0)) + // punch_all(); + // if (cell_data[i].print && (transport_step % print_modulus == 0)) + // print_all(); + //} + else if (n == 1 && l_punch) + print_punch(i, false); } - for (n = 1; n <= stag_data->count_stag; n++) - { - k = i + 1 + n * count_cells; - if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) - { - Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); - if (n == 1) - Utilities::Rxn_copy(Rxn_solution_map, -2, i); - } - } + //for (n = 1; n <= stag_data->count_stag; n++) + //{ + // k = i + 1 + n * count_cells; + // if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) + // { + // Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); + // if (n == 1) + // Utilities::Rxn_copy(Rxn_solution_map, -2, i); + // } + //} return (OK); } @@ -1861,7 +1903,7 @@ fill_spec(int l_cell_no) calc_SC(); // note that neutral species are corrected as if z = 1, but is viscosity-dependent sol_D[l_cell_no].spec[count_spec].Dwt = s_ptr->dw_corr * viscos_f; } - if (sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) + if (l_cell_no <= count_cells + 1 && sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn) > diffc_max) diffc_max = sol_D[l_cell_no].spec[count_spec].Dwt * pow(por, multi_Dn); sol_D[l_cell_no].spec[count_spec].erm_ddl = s_ptr->erm_ddl; @@ -1958,13 +2000,15 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) for (int f_c = 0; f_c <= loop_f_c; f_c++) { - for (n = 0; n < (stagnant ? stag_data->count_stag : 1); n++) - { + for (n = 0; n <= (stagnant ? stag_data->count_stag : 0); n++) // allow for stagnant cell mixing with higher cells in the layer + { icell = mobile_cell + 1 + n * count_cells; if (stagnant) { if (n == 0) icell -= 1; + else if (mobile_cell == 0 || mobile_cell == count_cells + 1) + continue; /* * find the mix ptr for icell and go along the cells that mix with it */ @@ -2000,10 +2044,17 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) std::vector n_solution; std::vector fraction; (use.Get_mix_ptr())->Vectorize(n_solution, fraction); - if ((jcell = n_solution[i]) <= icell) + jcell = n_solution[i]; + if (jcell <= icell) continue; - - last_c2 = jcell; + if (jcell >= all_cells || jcell < 0) + { + error_string = sformatf( + "Multi_D asked for diffusion from cell %d to %d, %d is beyond the number of cells", icell, jcell, jcell); + error_msg(error_string, CONTINUE); + } + if (jcell > last_c2) + last_c2 = jcell; mixf = fraction[i] / nmix; } else @@ -2079,12 +2130,12 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) /* * 3. find the solutions, add or subtract the moles... */ - if (i > 0 || stagnant || (i == 0 && dV_dcell)) + if (dV_dcell || (icell != 0 && icell != count_cells + 1)) { use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, icell)); use.Get_solution_ptr()->Set_total_h(use.Get_solution_ptr()->Get_total_h() - tot1_h); use.Get_solution_ptr()->Set_total_o(use.Get_solution_ptr()->Get_total_o() - tot1_o); - if (dV_dcell && (i > 0 || fix_current)) + if (dV_dcell && (icell > 0 || fix_current)) { use.Get_solution_ptr()->Set_potV(cell_data[icell].potV); } @@ -2109,14 +2160,14 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } } - if (i < count_cells || stagnant || (i == count_cells && dV_dcell)) + if (dV_dcell || jcell != count_cells + 1) { use.Set_solution_ptr(Utilities::Rxn_find(Rxn_solution_map, jcell)); dummy = use.Get_solution_ptr()->Get_total_h(); use.Get_solution_ptr()->Set_total_h(dummy + tot2_h); dummy = use.Get_solution_ptr()->Get_total_o(); use.Get_solution_ptr()->Set_total_o(dummy + tot2_o); - if (i == count_cells && fix_current && !stagnant) + if (icell == count_cells && fix_current && !stagnant) { use.Get_solution_ptr()->Set_potV(cell_data[jcell].potV); } @@ -2144,8 +2195,8 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) } } // check for negative conc's... - if (stagnant) - first_c = mobile_cell; + //if (stagnant) + // first_c = mobile_cell; // allow for stagnant cell mixing with boundary cell 0 for (i = first_c; i <= last_c2; i++) { if (stagnant && i > first_c && i <= count_cells + first_c) @@ -2813,9 +2864,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { // compare diffusive and electromotive forces dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1 * dV_dcell; - if (-dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z > 0) - { + if (icell == 0) + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); + else if (icell == count_cells) + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); + else + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1; + if (dum + dum2 > 0) + { // step out: no transport against the dV_dcell gradient if c = 0 in jcell... if (i < i_max) i++; @@ -2965,9 +3022,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { // compare diffuse and electromotive forces dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2 * dV_dcell; + if (icell == 0) + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); + else if (icell == count_cells) + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); + else + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2; // don't transport unavailable moles against the gradient - if (dum < abs(dum2) && dV_dcell * ct[icell].v_m[k].z < 0) + if (dum + dum2 < 0) { // step out... if (j < j_max) @@ -3156,7 +3219,13 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { // compare diffuse and electromotive forces dum = ct[icell].v_m[k].grad; - dum2 = F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2) * dV_dcell; + if (icell == 0) + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); + else if (icell == count_cells) + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); + else + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2); // don't transport unavailable moles against the gradient if (abs(dum) < abs(dum2) && ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || From 8e121390005e17601ab59b87d61525625cf8cf32 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Thu, 22 Feb 2018 14:45:39 -0700 Subject: [PATCH 1072/1077] Fixed bug from Shell. Segv because s_list.size differed from count_s_x. Fixed compiler warnings from jenkins. --- basicsubs.cpp | 18 +++++++++--------- mainsubs.cpp | 2 +- pitzer.cpp | 3 ++- print.cpp | 2 +- sit.cpp | 3 ++- transport.cpp | 19 ++++++++++--------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/basicsubs.cpp b/basicsubs.cpp index 0e4c7e85..525dc18a 100644 --- a/basicsubs.cpp +++ b/basicsubs.cpp @@ -304,18 +304,18 @@ calc_SC(void) sqrt_mu = sqrt(mu_x); SC = 0; - LDBLE ta1, ta2, ta3, ta4; + //LDBLE ta1, ta2, ta3, ta4; for (i = 0; i < count_s_x; i++) { // ** for optimizing, get numbers from -analyt for H+ = H+... - if (!strcmp(s_x[i]->name, "H+")) - { - ta1 = s_x[i]->logk[2]; - ta2 = s_x[i]->logk[3]; - ta3 = s_x[i]->logk[4]; - ta4 = s_x[i]->logk[5]; - break; - } + //if (!strcmp(s_x[i]->name, "H+")) + //{ + // ta1 = s_x[i]->logk[2]; + // ta2 = s_x[i]->logk[3]; + // ta3 = s_x[i]->logk[4]; + // ta4 = s_x[i]->logk[5]; + // break; + //} // } for (i = 0; i < count_s_x; i++) diff --git a/mainsubs.cpp b/mainsubs.cpp index 5d43fa0e..ee53a2cd 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -629,7 +629,7 @@ initial_solutions(int print) } use.Set_solution_ptr(&solution_ref); LDBLE d0 = solution_ref.Get_density(); - LDBLE d1 = 0; + //LDBLE d1 = 0; bool diag = (diagonal_scale == TRUE) ? true : false; int count_iterations = 0; std::string input_units = solution_ref.Get_initial_data()->Get_units(); diff --git a/pitzer.cpp b/pitzer.cpp index 546b3cd4..b77a77e4 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -2303,7 +2303,8 @@ model_pz(void) { count_basis_change++; - count_unknowns -= (int) s_list.size(); + //count_unknowns -= (int) s_list.size(); + count_unknowns -= count_s_x; reprep(); full_pitzer = false; } diff --git a/print.cpp b/print.cpp index 9c5abce7..3200710e 100644 --- a/print.cpp +++ b/print.cpp @@ -284,7 +284,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr) output_msg(sformatf( "\n\tSpecies \t Moles \tMoles excess\t g\n")); } - if (mass_water_surface = charge_ptr->Get_mass_water()) + if ((mass_water_surface = charge_ptr->Get_mass_water())) { count_elts = 0; paren_count = 0; diff --git a/sit.cpp b/sit.cpp index df222f3e..d395f737 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1313,7 +1313,8 @@ model_sit(void) { count_basis_change++; - count_unknowns -= (int) s_list.size(); + //count_unknowns -= (int) s_list.size(); + count_unknowns -= count_s_x; reprep(); full_pitzer = false; } diff --git a/transport.cpp b/transport.cpp index 19c2c1f4..cb81fd8b 100644 --- a/transport.cpp +++ b/transport.cpp @@ -975,8 +975,8 @@ void Phreeqc:: print_punch(int i, boolean active) /* ---------------------------------------------------------------------- */ { - if (!(cell_data[i].punch && (transport_step % punch_modulus == 0)) && - !(cell_data[i].print && (transport_step % print_modulus == 0)) || + if ((!(cell_data[i].punch && (transport_step % punch_modulus == 0)) && + !(cell_data[i].print && (transport_step % print_modulus == 0))) || (bcon_first == 2 && i == 0) || (bcon_last == 2 && i == count_cells + 1)) return; @@ -1260,6 +1260,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) int j, n, k; LDBLE t_imm; cxxSolution *ptr_imm, *ptr_m; + k = -1000; // compiler says k may be undefined ptr_imm = NULL; /* * Kinetics in transport cell is done while transporting @@ -3657,7 +3658,7 @@ Step (from cell 1 to count_cells + 1): * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. */ { - int i, i1, i2, k, k1, n1, n2; + int i, i1, i2, k, k1, n1; //, n2; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store, mcd_mixf; LDBLE lav, A_ij, por, Dp1, Dp2; @@ -3671,7 +3672,7 @@ Step (from cell 1 to count_cells + 1): viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); n1 = 0; - n2 = n1 + 1; + //n2 = n1 + 1; cxxSurface surface_n1, surface_n2; cxxSurface *surface_n2_ptr; @@ -4008,7 +4009,7 @@ Step (from cell 1 to count_cells + 1): /* * Step 4. Dispersion/diffusion is done. New surfaces can be copied in the cell's surface... */ - n2 = 0; + //n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for (; jit != Rxn_temp_surface_map.end(); jit++) { @@ -4328,7 +4329,7 @@ diff_stag_surf(int mobile_cell) * for any cell in MCD, need only include the mixing factors for higher numbered cells. */ { - int i, i1, i2, k, k1, n1, n2, ns; + int i, i1, i2, k, k1, /*n1, n2,*/ ns; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store; LDBLE Dp1, Dp2; @@ -4396,7 +4397,7 @@ diff_stag_surf(int mobile_cell) if (surface_n1_ptr != NULL) { surface_n1 = *surface_n1_ptr; - n1 = 0; + //n1 = 0; } /* if not found... */ else @@ -4432,7 +4433,7 @@ diff_stag_surf(int mobile_cell) /* if not found... */ else { - n2 = 1; + //n2 = 1; /* copy it from surface_ptr2... */ if (surface_ptr2 != NULL) { @@ -4613,7 +4614,7 @@ diff_stag_surf(int mobile_cell) /* * Step 4. Diffusion is done. New surfaces can be copied in the cells... */ - n2 = 0; + //n2 = 0; std::map::iterator jit = Rxn_temp_surface_map.begin(); for (; jit != Rxn_temp_surface_map.end(); jit++) { From 6c9e9843b7e5c096ff53f8e24d43e862466ab9a7 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 23 Feb 2018 09:39:25 -0700 Subject: [PATCH 1073/1077] One more compiler warning --- transport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport.cpp b/transport.cpp index cb81fd8b..ace10a89 100644 --- a/transport.cpp +++ b/transport.cpp @@ -3658,7 +3658,7 @@ Step (from cell 1 to count_cells + 1): * but only mobile surface_comp's (Dw > 0) and their surface_charge's are transported. */ { - int i, i1, i2, k, k1, n1; //, n2; + int i, i1, i2, k, k1/*, n1, n2*/; int charge_done, surf1, surf2; LDBLE f1, f2, mixf, mixf_store, mcd_mixf; LDBLE lav, A_ij, por, Dp1, Dp2; @@ -3671,7 +3671,7 @@ Step (from cell 1 to count_cells + 1): viscos_f = viscos_0; viscos_f = tk_x * viscos_0_25 / (298.15 * viscos_f); - n1 = 0; + //n1 = 0; //n2 = n1 + 1; cxxSurface surface_n1, surface_n2; cxxSurface *surface_n2_ptr; From b0fdcc41e4c433f9900c51b329b2af16ee63ac18 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 4 Mar 2018 20:48:19 -0700 Subject: [PATCH 1074/1077] Added Mtg(g) in calc_PR --- prep.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prep.cpp b/prep.cpp index 302554ea..c3f29436 100644 --- a/prep.cpp +++ b/prep.cpp @@ -4010,6 +4010,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) a_aa *= 0.81; else if (!strcmp(phase_ptr1->name, "CH4(g)")) a_aa *= 0.51; + else if (!strcmp(phase_ptr->name, "Mtg(g)")) + a_aa *= 0.51; else if (!strcmp(phase_ptr1->name, "N2(g)")) a_aa *= 0.51; } @@ -4021,6 +4023,8 @@ calc_PR(std::vector phase_ptrs, LDBLE P, LDBLE TK, LDBLE V_m) a_aa *= 0.81; else if (!strcmp(phase_ptr->name, "CH4(g)")) a_aa *= 0.51; + else if (!strcmp(phase_ptr->name, "Mtg(g)")) + a_aa *= 0.51; else if (!strcmp(phase_ptr->name, "N2(g)")) a_aa *= 0.51; } From 86a55b5b5d0b37e279f042bed9d4ac903f7773be Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Wed, 7 Mar 2018 17:08:33 -0700 Subject: [PATCH 1075/1077] Tony's changes from 20180305 --- Form1.h | 7 +- SurfaceCharge.h | 2 + class_main.cpp | 10 +- integrate.cpp | 24 +- pitzer.cpp | 1 - print.cpp | 6 +- sit.cpp | 1 - transport.cpp | 934 +++++++++++++++++------------------------------- 8 files changed, 356 insertions(+), 629 deletions(-) diff --git a/Form1.h b/Form1.h index 76379b37..6a17674a 100644 --- a/Form1.h +++ b/Form1.h @@ -1134,11 +1134,8 @@ namespace zdg_ui2 { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); try { -#ifdef NPP - this->Icon = gcnew System::Drawing::Icon("c:\\phreeqc\\phreex.ico"); -#else - this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); -#endif + //this->Icon = gcnew System::Drawing::Icon("c:\\phreeqc\\phreex.ico"); + this->Icon = (cli::safe_cast(resources->GetObject(L"$this.Icon"))); } catch (...) { diff --git a/SurfaceCharge.h b/SurfaceCharge.h index fa5711eb..669172a1 100644 --- a/SurfaceCharge.h +++ b/SurfaceCharge.h @@ -106,6 +106,7 @@ public: void Set_diffuse_layer_totals(cxxNameDouble & nd) {this->diffuse_layer_totals = nd;} std::map &Get_g_map(void) {return g_map;} void Set_g_map(std::map & t) {g_map = t;} + std::map &Get_z_gMCD_map(void) { return z_gMCD_map; } // z, exp(-zF Psi / RT) * fraction of dl water std::map & Get_dl_species_map(void) {return this->dl_species_map;} 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); @@ -122,6 +123,7 @@ protected: // workspace variables LDBLE sigma0, sigma1, sigma2, sigmaddl; std::map g_map; + std::map z_gMCD_map; const static std::vector < std::string > vopts; std::map dl_species_map; }; diff --git a/class_main.cpp b/class_main.cpp index bc16d111..88e19156 100644 --- a/class_main.cpp +++ b/class_main.cpp @@ -277,8 +277,8 @@ write_banner(void) /* version */ #ifdef NPP - //len = sprintf(buffer, "* PHREEQC-%s *", "3.4.1 AmpŠre"); - len = sprintf(buffer, "* PHREEQC-%s *", "3.4.1"); + //len = sprintf(buffer, "* PHREEQC-%s *", "3.4.2 AmpŠre"); + len = sprintf(buffer, "* PHREEQC-%s *", "3.4.2"); #else len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); #endif @@ -302,7 +302,7 @@ write_banner(void) /* date */ #ifdef NPP - len = sprintf(buffer, "%s", "February 15, 2018"); + len = sprintf(buffer, "%s", "February 27, 2018"); #else len = sprintf(buffer, "%s", "@VER_DATE@"); #endif @@ -492,12 +492,12 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie, screen_msg(sformatf("Database file: %s\n\n", token)); strcpy(db_file, token); #ifdef NPP - //output_msg(sformatf("Using PHREEQC: version 3.4.1 Ampère, compiled February 15, 2018\n")); + //output_msg(sformatf("Using PHREEQC: version 3.4.2 Ampère, compiled February 27, 2018\n")); #endif output_msg(sformatf(" Input file: %s\n", in_file)); output_msg(sformatf(" Output file: %s\n", out_file)); #ifdef NPP - output_msg(sformatf("Using PHREEQC: version 3.4.1, compiled February 15, 2018\n")); + output_msg(sformatf("Using PHREEQC: version 3.4.2, compiled February 27, 2018\n")); #endif output_msg(sformatf("Database file: %s\n\n", token)); #ifdef NPP diff --git a/integrate.cpp b/integrate.cpp index f8a5050e..fa3fb255 100644 --- a/integrate.cpp +++ b/integrate.cpp @@ -742,7 +742,7 @@ calc_all_donnan(void) { bool converge; int cd_m; - LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq; + LDBLE new_g, f_psi, surf_chrg_eq, psi_avg, f_sinh, A_surf, ratio_aq, ratio_aq_tot; LDBLE new_g2, f_psi2, surf_chrg_eq2, psi_avg2, dif, var1; if (use.Get_surface_ptr() == NULL) @@ -813,6 +813,7 @@ calc_all_donnan(void) /* fill in g's */ ratio_aq = charge_ptr->Get_mass_water() / mass_water_aq_x; + ratio_aq_tot = charge_ptr->Get_mass_water() / mass_water_bulk_x; for (it = charge_group_map.begin(); it != charge_group_map.end(); it++) { @@ -821,13 +822,14 @@ calc_all_donnan(void) { charge_ptr->Get_g_map()[z].Set_g(0); charge_ptr->Get_g_map()[z].Set_dg(0); + charge_ptr->Get_z_gMCD_map()[z] = 0; converge = true; continue; } new_g = ratio_aq * (exp(cd_m * z * psi_avg) - 1); - if (use.Get_surface_ptr()->Get_only_counter_ions() && - ((surf_chrg_eq < 0 && z < 0) - || (surf_chrg_eq > 0 && z > 0))) + if (use.Get_surface_ptr()->Get_only_counter_ions() && surf_chrg_eq * z > 0) + //((surf_chrg_eq < 0 && z < 0) + // || (surf_chrg_eq > 0 && z > 0))) new_g = -ratio_aq; if (new_g <= -ratio_aq) new_g = -ratio_aq + G_TOL * 1e-3; @@ -861,7 +863,19 @@ calc_all_donnan(void) { charge_ptr->Get_g_map()[z].Set_dg(-z); } - /* save g for species */ + /* save Boltzmann factor * water fraction for MCD calc's in transport */ + if (converge) + { + if (use.Get_surface_ptr()->Get_only_counter_ions()) + { + if (surf_chrg_eq * z > 0) // co-ions are not in the DL + charge_ptr->Get_z_gMCD_map()[z] = 0; + else // assume that counter-ions have the free water conc for diffusion + charge_ptr->Get_z_gMCD_map()[z] = ratio_aq_tot; + } + else + charge_ptr->Get_z_gMCD_map()[z] = (new_g / ratio_aq + 1) * ratio_aq_tot; + } } if (debug_diffuse_layer == TRUE) { diff --git a/pitzer.cpp b/pitzer.cpp index b77a77e4..2becc326 100644 --- a/pitzer.cpp +++ b/pitzer.cpp @@ -2303,7 +2303,6 @@ model_pz(void) { count_basis_change++; - //count_unknowns -= (int) s_list.size(); count_unknowns -= count_s_x; reprep(); full_pitzer = false; diff --git a/print.cpp b/print.cpp index 3200710e..902b1707 100644 --- a/print.cpp +++ b/print.cpp @@ -2286,13 +2286,13 @@ print_totals(void) "Total alkalinity (eq/kg) = ", (double) (total_alkalinity / mass_water_aq_x))); } - if (carbon_unknown == NULL && total_carbon > 0.0) + if (carbon_unknown == NULL && total_carbon) { output_msg(sformatf("%45s%11.3e\n", "Total carbon (mol/kg) = ", (double) (total_carbon / mass_water_aq_x))); } - if (total_co2 > 0.0) + if (total_co2) output_msg(sformatf("%45s%11.3e\n", "Total CO2 (mol/kg) = ", (double) (total_co2 / mass_water_aq_x))); #ifdef NO_UTF8_ENCODING @@ -2309,7 +2309,7 @@ print_totals(void) (double) patm_x)); } - if (potV_x != 0.0) + if (potV_x) { output_msg(sformatf("%45s%5.2f\n", "Electrical Potential (Volt) = ", (double)potV_x)); diff --git a/sit.cpp b/sit.cpp index d395f737..26c8d9aa 100644 --- a/sit.cpp +++ b/sit.cpp @@ -1313,7 +1313,6 @@ model_sit(void) { count_basis_change++; - //count_unknowns -= (int) s_list.size(); count_unknowns -= count_s_x; reprep(); full_pitzer = false; diff --git a/transport.cpp b/transport.cpp index ace10a89..6ab63ae6 100644 --- a/transport.cpp +++ b/transport.cpp @@ -19,9 +19,8 @@ struct CURRENT_CELLS LDBLE sum_R, sum_Rd; // sum of R, sum of (current_cells[0].dif - current_cells[i].dif) * R struct V_M // For calculating Vinograd and McBain's zero-charge, diffusive tranfer of individual solutes { - LDBLE grad, D, z, c, zc, Dz, Dzc, Dzc_dl, g_dl; + LDBLE grad, D, z, c, zc, Dz, Dzc; LDBLE b_ij; // harmonic mean of cell properties, with EDL enrichment - int o_c; }; struct CT /* summed parts of V_M and mcd transfer in a timestep for all cells, for free + DL water */ { @@ -458,9 +457,7 @@ transport(void) k = i + 1 + n * count_cells; cell_no = k; if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) - { set_initial_moles(k); - } } } /* @@ -887,6 +884,7 @@ transport(void) k = i + 1 + n * count_cells; if (Utilities::Rxn_find(Rxn_solution_map, k) == NULL) continue; + cell_no = k; print_punch(k, false); } } @@ -1331,22 +1329,9 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) set_and_run_wrapper(i, STAG, FALSE, -2, 0.0); if (multi_Dflag == TRUE) fill_spec(cell_no); - //use.Set_kinetics_ptr(Utilities::Rxn_find(Rxn_kinetics_map, i)); - //if (use.Get_kinetics_ptr() != NULL) - //{ - // use.Set_n_kinetics_user(i); - // use.Set_kinetics_in(true); - //} - //if (l_punch && (cell_data[i].print == TRUE) && - // (transport_step % print_modulus == 0)) - // print_all(); - //if (l_punch && (cell_data[i].punch == TRUE) && - // (transport_step % punch_modulus == 0)) - // punch_all(); + saver(); // save solution i in -2, original can be used in other stagnant mixes if (l_punch) print_punch(i, true); - saver(); - Utilities::Rxn_copy(Rxn_solution_map, -2, i); /* maybe sorb a surface component... */ if (l_punch && change_surf_count) @@ -1370,15 +1355,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) run_reactions(k, kin_time, STAG, step_fraction); if (multi_Dflag == TRUE) fill_spec(cell_no); - - //if ((cell_data[k].print == TRUE) && (l_punch == TRUE) && i != 0 && - // (transport_step % print_modulus == 0)) - // print_all(); - //if ((cell_data[k].punch == TRUE) && (l_punch == TRUE) && i != 0 && - // (transport_step % punch_modulus == 0)) - // punch_all(); - saver(); - Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); + saver(); // save solution k in -2 - k, original k can be used in other stagnant mixes /* maybe sorb a surface component... */ if (l_punch && change_surf_count) @@ -1397,29 +1374,23 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) change_surf_count = 0; } } - //else if (n == 1 && l_punch && (cell_data[i].punch || cell_data[i].print)) - //{ - // cell_no = i; - // run_reactions(i, 0, NOMIX, 0); - // if (cell_data[i].punch && (transport_step % punch_modulus == 0)) - // punch_all(); - // if (cell_data[i].print && (transport_step % print_modulus == 0)) - // print_all(); - //} else if (n == 1 && l_punch) print_punch(i, false); - } - //for (n = 1; n <= stag_data->count_stag; n++) - //{ - // k = i + 1 + n * count_cells; - // if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) - // { - // Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); - // if (n == 1) - // Utilities::Rxn_copy(Rxn_solution_map, -2, i); - // } - //} + + if (ptr_imm != NULL) // after all mixing is done, the temporal solution becomes the original for the next timestep + { + for (n = 1; n <= stag_data->count_stag; n++) + { + k = i + 1 + n * count_cells; + if (Utilities::Rxn_find(Rxn_solution_map, k) != 0) + { + Utilities::Rxn_copy(Rxn_solution_map, -2 - k, k); + if (n == 1) + Utilities::Rxn_copy(Rxn_solution_map, -2, i); + } + } + } return (OK); } @@ -2220,24 +2191,23 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant) use.Set_surface_ptr(Utilities::Rxn_find(Rxn_surface_map, i)); cxxSurface * s_ptr = use.Get_surface_ptr(); cxxSurfaceCharge * charge_ptr = NULL; + cxxNameDouble::iterator jit; for (size_t j = 0; j < s_ptr->Get_surface_charges().size(); j++) { if (s_ptr->Get_dl_type() == cxxSurface::DONNAN_DL) { charge_ptr = &(s_ptr->Get_surface_charges()[j]); - break; - } - } - cxxNameDouble::iterator jit; - for (jit = charge_ptr->Get_diffuse_layer_totals().begin(); jit != charge_ptr->Get_diffuse_layer_totals().end(); jit++) - { - if (strcmp(jit->first.c_str(), "H") == 0 || strcmp(jit->first.c_str(), "O") == 0) - continue; - if (strcmp(jit->first.c_str(), it->first.c_str()) == 0) - { - moles += jit->second; - it->second += jit->second; - jit->second = 0; + for (jit = charge_ptr->Get_diffuse_layer_totals().begin(); jit != charge_ptr->Get_diffuse_layer_totals().end(); jit++) + { + if (strcmp(jit->first.c_str(), "H") == 0 || strcmp(jit->first.c_str(), "O") == 0) + continue; + if (strcmp(jit->first.c_str(), it->first.c_str()) == 0) + { + moles += jit->second; + it->second += jit->second; + jit->second = 0; + } + } } } } @@ -2392,8 +2362,9 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) t_aq1 = aq1 + aq_dl_i. A1 = t_aq1 / h_i. f_free_i = aq1 / t_aq1. b_i_cat = A1 / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) * Bm}. Bm = Boltzmann enrichment in EDL = g_dl. b_i_ani = A1 / (G_i * h_i / 2) * Dw * {f_free + (1 - f_free) / Bm)}. + 22/2/18: now calculates diffusion through EDL's of multiple, differently charged surfaces * stagnant TRUE: - * J_ij = mixf_ij * (-D_i*grad(c) + D_i*z_i*c_i * SUM(D_i*z_i*grad(c)) / SUM(D_i*(z_i)^2*c_i)) + * same eqn for J_ij, but multplies with 2 * mixf. (times 2, because mixf = A / (G_i * h_i)) * mixf_ij = mixf / (Dw / init_tort_f) / new_tort_f * new_por / init_por * mixf is defined in MIX; Dw is default multicomponent diffusion coefficient; * init_tort_f equals multi_Dpor^(-multi_Dn); new_pf = new tortuosity factor. @@ -2419,9 +2390,15 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) LDBLE cec1, cec2, cec12 = 0.0, rc1 = 0.0, rc2 = 0.0; LDBLE dV, c1, c2; cxxSurface *s_ptr1, *s_ptr2; - cxxSurfaceCharge *s_charge_ptr, *s_charge_ptr1, *s_charge_ptr2; - LDBLE g, g_i, g_j; - char token[MAX_LENGTH], token1[MAX_LENGTH]; + cxxSurfaceCharge *s_charge_ptr1, *s_charge_ptr2; + LDBLE g_i, g_j; + //char token[MAX_LENGTH], token1[MAX_LENGTH]; + + std::vector s_charge_p; + std::vector s_charge_p1; + std::vector s_charge_p2; + std::vector::iterator it_sc; + std::vector s_com_p; il_calcs = (interlayer_Dflag ? 1 : 0); ct[icell].dl_s = dl_aq1 = dl_aq2 = 0.0; @@ -2470,48 +2447,33 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) s_ptr1 = s_ptr2 = NULL; ct[icell].visc1 = ct[icell].visc2 = 1.0; only_counter = FALSE; - + s_ptr1 = Utilities::Rxn_find(Rxn_surface_map, icell); if (s_ptr1 != NULL) { if (s_ptr1->Get_dl_type() != cxxSurface::NO_DL) { + s_charge_p.assign(s_ptr1->Get_surface_charges().begin(), s_ptr1->Get_surface_charges().end()); + s_com_p.assign(s_ptr1->Get_surface_comps().begin(), s_ptr1->Get_surface_comps().end()); + if (s_ptr1->Get_only_counter_ions()) only_counter = TRUE; - /* find the one (and only one...) immobile surface comp with DL... */ - for (i = 0; i < (int) s_ptr1->Get_surface_comps().size(); i++) + + ct[icell].visc1 = s_ptr1->Get_DDL_viscosity(); + /* find the immobile surface charges with DL... */ + for (i = 0; i < (int)s_charge_p.size(); i++) { - cxxSurfaceComp * comp_i_ptr = &(s_ptr1->Get_surface_comps()[i]); - if (comp_i_ptr->Get_Dw() == 0) + for (i1 = 0; i1 < (int)s_com_p.size(); i1++) { - s_charge_ptr1 = s_ptr1->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq1 = s_charge_ptr1->Get_mass_water(); - ct[icell].visc1 = s_ptr1->Get_DDL_viscosity(); - /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int) s_ptr1->Get_surface_comps().size(); j++) + if (!(s_charge_p[i].Get_name().compare(s_com_p[i1].Get_charge_name())) && !s_com_p[i1].Get_Dw()) { - cxxSurfaceComp * comp_j_ptr = &(s_ptr1->Get_surface_comps()[j]); - if (comp_j_ptr->Get_Dw() == 0 - && (comp_j_ptr->Get_charge_name() != - comp_i_ptr->Get_charge_name())) - { - if (!warn_fixed_Surf) - { - k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); - strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); - token1[k] = '\0'; - sprintf(token, - "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); - warning_msg(token); - warn_fixed_Surf = 1; - } - break; - } + dl_aq1 += s_charge_p[i].Get_mass_water(); + s_charge_p1.push_back(s_charge_p[i]); + break; } - break; } } + s_charge_ptr1 = s_ptr1->Find_charge(s_charge_p[0].Get_name()); // appt remove } } s_ptr2 = Utilities::Rxn_find(Rxn_surface_map, jcell); @@ -2519,41 +2481,27 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) { if (s_ptr2->Get_dl_type() != cxxSurface::NO_DL) { + s_charge_p.assign(s_ptr2->Get_surface_charges().begin(), s_ptr2->Get_surface_charges().end()); + s_com_p.assign(s_ptr2->Get_surface_comps().begin(), s_ptr2->Get_surface_comps().end()); + if (s_ptr2->Get_only_counter_ions()) only_counter = TRUE; - for (i = 0; i < (int) s_ptr2->Get_surface_comps().size(); i++) + + ct[icell].visc2 = s_ptr2->Get_DDL_viscosity(); + + for (i = 0; i < (int)s_charge_p.size(); i++) { - cxxSurfaceComp * comp_i_ptr = &(s_ptr2->Get_surface_comps()[i]); - if (comp_i_ptr->Get_Dw() == 0) + for (i1 = 0; i1 < (int)s_com_p.size(); i1++) { - s_charge_ptr2 = s_ptr2->Find_charge(comp_i_ptr->Get_charge_name()); - dl_aq2 = s_charge_ptr2->Get_mass_water(); - ct[icell].visc2 = s_ptr2->Get_DDL_viscosity(); - /* check for more comps with Dw = 0 */ - for (j = i + 1; j < (int) s_ptr2->Get_surface_comps().size(); j++) + if (!(s_charge_p[i].Get_name().compare(s_com_p[i1].Get_charge_name())) && !s_com_p[i1].Get_Dw()) { - cxxSurfaceComp * comp_j_ptr = &(s_ptr2->Get_surface_comps()[j]); - if (comp_j_ptr->Get_Dw() == 0 - && (comp_j_ptr->Get_charge_name() != - comp_i_ptr->Get_charge_name())) - { - if (!warn_fixed_Surf) - { - k = (int) strcspn(comp_i_ptr->Get_formula().c_str(), "_"); - strncpy(token1, comp_i_ptr->Get_formula().c_str(), k); - token1[k] = '\0'; - sprintf(token, - "MCD found more than 1 fixed surface with a DDL,\n\t uses the 1st in alphabetical order: %s.", - token1); - warning_msg(token); - warn_fixed_Surf = 1; - } - break; - } + dl_aq2 += s_charge_p[i].Get_mass_water(); + s_charge_p2.push_back(s_charge_p[i]); + break; } - break; } } + s_charge_ptr2 = s_ptr2->Find_charge(s_charge_p[0].Get_name()); // appt remove } } if (!stagnant) @@ -2563,6 +2511,11 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) else if (icell == count_cells) ct[icell].visc2 = ct[icell].visc1; } + //LDBLE d_damper = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mu() / + // Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mu(); + //d_damper = pow(d_damper, 1); + //if (d_damper > 1) ct[icell].visc1 *= d_damper; else ct[icell].visc2 *= d_damper; + /* in each cell: DL surface = mass_water_DL / (cell_length) free pore surface = mass_water_free / (cell_length) determine DL surface as a fraction of the total pore surface... */ @@ -2573,15 +2526,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) if (dl_aq1 > 0) ct[icell].dl_s = dl_aq1 / t_aq1; if (dl_aq2 > 0) - { - dum = dl_aq2 / t_aq2; - if (dl_aq1 > 0) - /* average for stagnant calcs... */ - ct[icell].dl_s = (ct[icell].dl_s + dum) / 2; - else - /* there is one DL surface... */ - ct[icell].dl_s = dum; - } + ct[icell].dl_s = dl_aq2 / t_aq2; if (il_calcs) { @@ -2657,64 +2602,63 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } - /* In stagnant calc's, find ct[icell].mixf_il for IL diffusion, correct mixf. - In regular column, find surface areas A1, j and A_il */ + /* Find ct[icell].mixf_il for IL diffusion. + In stagnant calc's, correct mixf by default values, A = por / tort. + In regular column, A = surface area / (0.5 * x * tort)*/ tort1 = tort2 = 1.0; ct[icell].A_ij_il = ct[icell].mixf_il = 0.0; if (stagnant) { mixf /= (default_Dw * pow(multi_Dpor, multi_Dn) * multi_Dpor); - dum = (cell_data[icell].por <= cell_data[jcell].por ? - cell_data[icell].por : cell_data[jcell].por); if (il_calcs) ct[icell].mixf_il = mixf * por_il12 / interlayer_tortf; - mixf *= (dum * pow(dum, multi_Dn)); + } + if (icell == 0) + { + tort1 = tort2 = pow(cell_data[1].por, -multi_Dn); + if (stagnant) + A2 = cell_data[1].por / tort2; + else + { + A2 = t_aq2 / (cell_data[1].length * 0.5 * cell_data[1].length); + if (il_calcs && !stagnant) + ct[icell].A_ij_il = A2 * por_il12 / (cell_data[1].por * interlayer_tortf); + A2 /= tort2; + } + A1 = A2; + } + else if (icell == count_cells) + { + tort1 = tort2 = pow(cell_data[count_cells].por, -multi_Dn); + if (stagnant) + A1 = cell_data[count_cells].por / tort1; + else + { + A1 = t_aq1 / (cell_data[count_cells].length * 0.5 * cell_data[count_cells].length); + if (il_calcs && !stagnant) + ct[icell].A_ij_il = A1 * por_il12 / (cell_data[count_cells].por * interlayer_tortf); + A1 /= tort1; + } + A2 = A1; } else - { /* regular column... */ - if (icell == 0) + { + tort1 = pow(cell_data[icell].por, -multi_Dn); + tort2 = pow(cell_data[jcell].por, -multi_Dn); + if (stagnant) { - tort1 = tort2 = pow(cell_data[1].por, -multi_Dn); - A2 = t_aq2 / - (cell_data[1].length * 0.5 * cell_data[1].length); - - if (il_calcs) - ct[icell].A_ij_il = A2 * por_il12 / - (cell_data[1].por * interlayer_tortf); - - A2 /= tort2; - A1 = A2; - } - else if (icell == count_cells) - { - tort1 = tort2 = pow(cell_data[count_cells].por, -multi_Dn); - A1 = t_aq1 / - (cell_data[count_cells].length * 0.5 * cell_data[count_cells].length); - - if (il_calcs) - ct[icell].A_ij_il = A1 * por_il12 / - (cell_data[count_cells].por * interlayer_tortf); - - A1 /= tort1; - A2 = A1; + A1 = cell_data[icell].por / tort1; + A2 = cell_data[jcell].por / tort2; } else { - tort1 = pow(cell_data[icell].por, -multi_Dn); - tort2 = pow(cell_data[jcell].por, -multi_Dn); - A1 = t_aq1 / - (cell_data[icell].length * 0.5 * cell_data[icell].length); - - A2 = t_aq2 / - (cell_data[jcell].length * 0.5 * cell_data[jcell].length); - - if (il_calcs) + A1 = t_aq1 / (cell_data[icell].length * 0.5 * cell_data[icell].length); + A2 = t_aq2 / (cell_data[jcell].length * 0.5 * cell_data[jcell].length); + if (il_calcs && !stagnant) { - dum = A1 * por_il12 / - (cell_data[icell].por * interlayer_tortf); - dum2 = A2 * por_il12 / - (cell_data[jcell].por * interlayer_tortf); + dum = A1 * por_il12 / (cell_data[icell].por * interlayer_tortf); + dum2 = A2 * por_il12 / (cell_data[jcell].por * interlayer_tortf); ct[icell].A_ij_il = dum * dum2 / (dum + dum2); } A1 /= tort1; @@ -2747,10 +2691,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m[i].zc = 0.0; ct[icell].v_m[i].Dz = 0.0; ct[icell].v_m[i].Dzc = 0.0; - ct[icell].v_m[i].Dzc_dl = 0.0; - ct[icell].v_m[i].g_dl = 1.0; ct[icell].v_m[i].b_ij = 0.0; - ct[icell].v_m[i].o_c = 1; } ct[icell].Dz2c = ct[icell].Dz2c_dl = ct[icell].Dz2c_il = 0.0; @@ -2779,10 +2720,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) ct[icell].v_m_il[i].zc = 0.0; ct[icell].v_m_il[i].Dz = 0.0; ct[icell].v_m_il[i].Dzc = 0.0; - ct[icell].v_m_il[i].Dzc_dl = 0.0; - ct[icell].v_m_il[i].g_dl = 1.0; ct[icell].v_m_il[i].b_ij = 0.0; - ct[icell].v_m_il[i].o_c = 1; } } /* @@ -2795,8 +2733,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) while (i < i_max || j < j_max) { if (j == j_max - || (i < i_max - && strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) < 0)) + || (i < i_max && strcmp(sol_D[icell].spec[i].name, sol_D[jcell].spec[j].name) < 0)) { /* species 'name' is only in icell */ if (il_calcs && sol_D[icell].spec[i].type == EX) @@ -2813,141 +2750,95 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (stagnant) - { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - ct[icell].v_m[k].D = sol_D[icell].spec[i].Dwt; - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ - c1 = sol_D[icell].spec[i].c / 2; - ct[icell].v_m[k].c = c1; + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ + c1 = sol_D[icell].spec[i].c / 2; + ct[icell].v_m[k].c = c1; + if (ct[icell].v_m[k].z) ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c1; - if (ct[icell].dl_s > 0) + if (dV_dcell && ct[icell].v_m[k].z) + { + // compare diffusive and electromotive forces + dum = ct[icell].v_m[k].grad; + if (icell == 0) + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); + else if (icell == count_cells) + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); + else + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1; + if (dum + dum2 > 0) { - s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (only_counter) + // step out: no transport against the dV_dcell gradient if c = 0 in jcell... + if (i < i_max) + i++; + continue; + } + } + + g_i = g_j = 0; + if (ct[icell].dl_s > 0) + { + if (dl_aq1) + { + for (it_sc = s_charge_p1.begin(); it_sc != s_charge_p1.end(); it_sc++) { - if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; + g_i += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; } - else + g_i *= sol_D[icell].spec[i].erm_ddl; + } + if (dl_aq2) + { + for (it_sc = s_charge_p2.begin(); it_sc != s_charge_p2.end(); it_sc++) { - if (dl_aq1 > 0) + if (ct[icell].v_m[k].z == 0 || only_counter) { - ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - ct[icell].v_m[k].Dzc_dl = - ct[icell].v_m[k].Dz * c1 * ct[icell].v_m[k].g_dl; + g_j += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; } else - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c1; - } - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; - } - ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - k++; - } - else // regular column - { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].grad = -sol_D[icell].spec[i].c; /* assume d log(gamma) / d log(c) = 0 */ - c1 = sol_D[icell].spec[i].c / 2; - if (dV_dcell && ct[icell].v_m[k].z) - { - // compare diffusive and electromotive forces - dum = ct[icell].v_m[k].grad; - if (icell == 0) - dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); - else if (icell == count_cells) - dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); - else - dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); - dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c1; - if (dum + dum2 > 0) - { - // step out: no transport against the dV_dcell gradient if c = 0 in jcell... - if (i < i_max) - i++; - continue; - } - } - g_i = g_j = dum2 = 0; - if (ct[icell].dl_s > 0) - { - if (ct[icell].v_m[k].z) - { - if (dl_aq1 > 0) - g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (dl_aq2 > 0) { if (abs(ct[icell].v_m[k].z) == 1) // there is always H+ and OH-... - g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + g_j += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; else { - dum = ct[icell].v_m[k].z > 0 ? 1 : -1; - g_j = s_charge_ptr2->Get_g_map()[dum].Get_g(); - g_j = pow((1 + g_j * aq2 / dl_aq2), ct[icell].v_m[k].z) - 1; + dum1 = it_sc->Get_mass_water() / mass_water_bulk_x; + dum2 = it_sc->Get_z_gMCD_map()[1] / dum1; + g_j += pow(dum2, ct[icell].v_m[k].z) * dum1; } } } - if (only_counter) - { - s_charge_ptr = (dl_aq1 > 0) ? s_charge_ptr1 : s_charge_ptr2; - if (s_charge_ptr->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... - dum2 = 1; - } - else - { - if (dl_aq1 > 0) - ct[icell].v_m[k].g_dl = (1 + g_i * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - if (dl_aq2) - dum2 = (1 + g_j * aq2 / dl_aq2) * sol_D[icell].spec[i].erm_ddl; - } + g_j *= sol_D[icell].spec[i].erm_ddl; } - b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); - b_j = A2 * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); - if (icell == count_cells) - ct[icell].v_m[k].b_ij = b_i; + } + + b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + g_i / ct[icell].visc1); + b_j = A2 * (f_free_j + g_j / ct[icell].visc2); + if (icell == count_cells && !stagnant) + ct[icell].v_m[k].b_ij = b_i; + else + { + if (sol_D[icell].tk_x == sol_D[jcell].tk_x) + b_j *= sol_D[icell].spec[i].Dwt; else { - if (sol_D[icell].tk_x == sol_D[jcell].tk_x) - b_j *= sol_D[icell].spec[i].Dwt; - else - { - dum2 = sol_D[icell].spec[i].Dwt / sol_D[icell].viscos_f; - dum2 *= exp(sol_D[icell].spec[i].dw_t / sol_D[jcell].tk_x - sol_D[icell].spec[i].dw_t / sol_D[icell].tk_x); - dum2 *= sol_D[jcell].viscos_f; - b_j *= dum2; - } - if (icell == 0) - ct[icell].v_m[k].b_ij = b_j; - else - ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + dum2 = sol_D[icell].spec[i].Dwt / sol_D[icell].viscos_f; + dum2 *= exp(sol_D[icell].spec[i].dw_t / sol_D[jcell].tk_x - sol_D[icell].spec[i].dw_t / sol_D[icell].tk_x); + dum2 *= sol_D[jcell].viscos_f; + b_j *= dum2; } - - ct[icell].v_m[k].c = c1; - if (ct[icell].v_m[k].z) - { - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c1; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; - } - k++; + if (icell == 0 && !stagnant) + ct[icell].v_m[k].b_ij = b_j; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); } + + if (ct[icell].v_m[k].z) + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + + k++; } if (i < i_max) i++; @@ -2971,140 +2862,93 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (stagnant) - { - ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; - ct[icell].v_m[k].D = sol_D[jcell].spec[j].Dwt; - ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ - c2 = sol_D[jcell].spec[j].c / 2; - ct[icell].v_m[k].c = c2; + ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; + ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; + ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ + c2 = sol_D[jcell].spec[j].c / 2; + ct[icell].v_m[k].c = c2; + if (ct[icell].v_m[k].z) ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * c2; - if (ct[icell].dl_s > 0) + if (dV_dcell && ct[icell].v_m[k].z) + { + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; + if (icell == 0) + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); + else if (icell == count_cells) + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); + else + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2; + // don't transport unavailable moles against the gradient + if (dum + dum2 < 0) { - s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - g = s_charge_ptr->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (only_counter) + // step out... + if (j < j_max) + j++; + continue; + } + } + g_i = g_j = 0; + if (ct[icell].dl_s > 0) + { + if (dl_aq1) + { + for (it_sc = s_charge_p1.begin(); it_sc != s_charge_p1.end(); it_sc++) { - if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) + if (ct[icell].v_m[k].z == 0 || only_counter) { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; - } - else - { - if (dl_aq2 > 0) - { - ct[icell].v_m[k].g_dl = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; - ct[icell].v_m[k].Dzc_dl = - ct[icell].v_m[k].Dz * c2 * ct[icell].v_m[k].g_dl; + g_i += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; } else - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c2; - } - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; - } - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - k++; - } - else // regular column - { - ct[icell].J_ij[k].name = sol_D[jcell].spec[j].name; - ct[icell].v_m[k].z = sol_D[jcell].spec[j].z; - ct[icell].v_m[k].grad = sol_D[jcell].spec[j].c; /* assume d log(gamma) / d log(c) = 0 */ - c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell && ct[icell].v_m[k].z) - { - // compare diffuse and electromotive forces - dum = ct[icell].v_m[k].grad; - if (icell == 0) - dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); - else if (icell == count_cells) - dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); - else - dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); - dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * c2; - // don't transport unavailable moles against the gradient - if (dum + dum2 < 0) - { - // step out... - if (j < j_max) - j++; - continue; - } - } - g_i = g_j = dum1 = 0; - if (ct[icell].dl_s > 0) - { - if (ct[icell].v_m[k].z) - { - if (dl_aq2 > 0) - g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (dl_aq1 > 0) { if (abs(ct[icell].v_m[k].z) == 1) - g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); + // there is always H+ and OH-... + g_i += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; else { - dum = ct[icell].v_m[k].z > 0 ? 1 : -1; - g_i = s_charge_ptr1->Get_g_map()[dum].Get_g(); - g_i = pow((1 + g_i * aq1 / dl_aq1), ct[icell].v_m[k].z) - 1; + dum1 = it_sc->Get_mass_water() / mass_water_bulk_x; + dum2 = it_sc->Get_z_gMCD_map()[1] / dum1; + g_i += pow(dum2, ct[icell].v_m[k].z) * dum1; } } } - if (only_counter) - { - s_charge_ptr = (dl_aq2 > 0) ? s_charge_ptr2 : s_charge_ptr1; - if (s_charge_ptr->Get_la_psi()* ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... - dum1 = 1; - } - else - { - if (dl_aq2) - ct[icell].v_m[k].g_dl = (1 + g_j * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; - if (dl_aq1) - dum1 = (1 + g_i * aq1 / dl_aq1) * sol_D[jcell].spec[j].erm_ddl; - } + g_i *= sol_D[jcell].spec[j].erm_ddl; } - b_i = A1 * (f_free_i + (1 - f_free_i) * dum1 / ct[icell].visc1); - b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * ct[icell].v_m[k].g_dl / ct[icell].visc2); - if (icell == 0) - ct[icell].v_m[k].b_ij = b_j; + if (dl_aq2) + { + for (it_sc = s_charge_p2.begin(); it_sc != s_charge_p2.end(); it_sc++) + { + g_j += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; + } + g_j *= sol_D[jcell].spec[j].erm_ddl; + } + } + b_i = A1 * (f_free_i + g_i / ct[icell].visc1); + b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + g_j / ct[icell].visc2); + if (icell == 0 && !stagnant) + ct[icell].v_m[k].b_ij = b_j; + else + { + if (sol_D[icell].tk_x == sol_D[jcell].tk_x) + b_i *= sol_D[jcell].spec[j].Dwt; else { - if (sol_D[icell].tk_x == sol_D[jcell].tk_x) - b_i *= sol_D[jcell].spec[j].Dwt; - else - { - dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f; - dum2 *= exp(sol_D[jcell].spec[j].dw_t / sol_D[icell].tk_x - sol_D[jcell].spec[j].dw_t / sol_D[jcell].tk_x); - dum2 *= sol_D[icell].viscos_f; - b_i *= dum2; - } - if (icell == count_cells) - ct[icell].v_m[k].b_ij = b_i; - else - ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + dum2 = sol_D[jcell].spec[j].Dwt / sol_D[jcell].viscos_f; + dum2 *= exp(sol_D[jcell].spec[j].dw_t / sol_D[icell].tk_x - sol_D[jcell].spec[j].dw_t / sol_D[jcell].tk_x); + dum2 *= sol_D[icell].viscos_f; + b_i *= dum2; } - ct[icell].v_m[k].c = c2; - if (ct[icell].v_m[k].z) - { - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * c2; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; - } - k++; + if (icell == count_cells && !stagnant) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); } + if (ct[icell].v_m[k].z) + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + + k++; } if (j < j_max) j++; @@ -3132,173 +2976,76 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } else { - if (stagnant) - { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - ct[icell].v_m[k].D = (sol_D[icell].spec[i].Dwt + sol_D[jcell].spec[j].Dwt) / 2; - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].Dz = ct[icell].v_m[k].D * ct[icell].v_m[k].z; - ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); - c1 = sol_D[icell].spec[i].c / 2; - c2 = sol_D[jcell].spec[j].c / 2; - ct[icell].v_m[k].c = (c1 + c2); + ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; + ct[icell].v_m[k].z = sol_D[icell].spec[i].z; + ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); + c1 = sol_D[icell].spec[i].c / 2; + c2 = sol_D[jcell].spec[j].c / 2; + ct[icell].v_m[k].c = c1 + c2; + if (ct[icell].v_m[k].z) ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; - ct[icell].v_m[k].Dzc = ct[icell].v_m[k].Dz * ct[icell].v_m[k].c; - if (ct[icell].dl_s > 0) - { - c_dl = 0.0; - if (dl_aq1 > 0) - { - g = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - if (only_counter) - { - if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].Dzc_dl = 0; - ct[icell].v_m[k].g_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - c_dl = c1; - } - else - { - ct[icell].v_m[k].g_dl = (1 + g * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - c_dl = c1 * ct[icell].v_m[k].g_dl; - } - } - else - c_dl = c1; - if (dl_aq2 > 0) - { - g = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - { - if (only_counter) - { - if (s_charge_ptr2->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].Dzc_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - { - dum = 1.0; - c_dl += c2 * dum; - ct[icell].v_m[k].g_dl = - (ct[icell].v_m[k].g_dl + dum) / 2; - } - } - else - { - dum = (1 + g * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; - c_dl += c2 * dum; - ct[icell].v_m[k].g_dl = (ct[icell].v_m[k].g_dl + dum) / 2; - } - } - } - else if (ct[icell].v_m[k].o_c == 1) - c_dl += c2; - - ct[icell].v_m[k].Dzc_dl = ct[icell].v_m[k].Dz * c_dl; - ct[icell].Dz2c_dl += ct[icell].v_m[k].Dzc_dl * ct[icell].v_m[k].z; - } - ct[icell].Dz2c += ct[icell].v_m[k].Dzc * ct[icell].v_m[k].z; - ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; - if (fabs(ddlm) > 1e-10) - ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); - k++; - } - else // regular column + if (dV_dcell && ct[icell].v_m[k].z) { - ct[icell].J_ij[k].name = sol_D[icell].spec[i].name; - ct[icell].v_m[k].z = sol_D[icell].spec[i].z; - ct[icell].v_m[k].grad = (sol_D[jcell].spec[j].c - sol_D[icell].spec[i].c); - c1 = sol_D[icell].spec[i].c / 2; - c2 = sol_D[jcell].spec[j].c / 2; - if (dV_dcell && ct[icell].v_m[k].z) - { - // compare diffuse and electromotive forces - dum = ct[icell].v_m[k].grad; - if (icell == 0) - dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); - else if (icell == count_cells) - dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); - else - dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); - dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2); - // don't transport unavailable moles against the gradient - if (abs(dum) < abs(dum2) && - ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || - (dum2 <= 0 && sol_D[icell].spec[i].c * aq1 < 1e-12))) - { - // step out: - if (i < i_max) - i++; - if (j < j_max) - j++; - continue; - } - } - g_i = g_j = dum2 = 0; - if (ct[icell].dl_s > 0) - { - if (dl_aq1 > 0) - { - if (only_counter) - { - if (s_charge_ptr1->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - //else // use default g_dl = 1, assume for counter ions in the DDL the free pore space conc's... - } - else - { - g_i = s_charge_ptr1->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - ct[icell].v_m[k].g_dl = (1 + g_i * aq1 / dl_aq1) * sol_D[icell].spec[i].erm_ddl; - } - } - - if (dl_aq2 > 0) - { - if (only_counter) - { - if (s_charge_ptr2->Get_la_psi() * ct[icell].v_m[k].z > 0) - { - ct[icell].v_m[k].o_c = 0; - ct[icell].v_m[k].g_dl = 0; - } - else /* assume for counter ions in the DDL the free pore space conc's... */ - dum2 = 1.0; - } - else - { - g_j = s_charge_ptr2->Get_g_map()[ct[icell].v_m[k].z].Get_g(); - dum2 = (1 + g_j * aq2 / dl_aq2) * sol_D[jcell].spec[j].erm_ddl; - } - } - } - b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + (1 - f_free_i) * ct[icell].v_m[k].g_dl / ct[icell].visc1); - b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + (1 - f_free_j) * dum2 / ct[icell].visc2); + // compare diffuse and electromotive forces + dum = ct[icell].v_m[k].grad; if (icell == 0) - ct[icell].v_m[k].b_ij = b_j; + dum2 = (cell_data[1].potV - cell_data[0].potV) / (cell_data[1].length / 2); else if (icell == count_cells) - ct[icell].v_m[k].b_ij = b_i; + dum2 = (cell_data[count_cells + 1].potV - cell_data[count_cells].potV) / (cell_data[count_cells].length / 2); else - ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); - ct[icell].v_m[k].c = c1 + c2; - if (ct[icell].v_m[k].z) + dum2 = (cell_data[jcell].potV - cell_data[icell].potV) / ((cell_data[jcell].length + cell_data[icell].length) / 2); + dum2 *= F_Re3 / tk_x2 * ct[icell].v_m[k].z * (c1 + c2); + // don't transport unavailable moles against the gradient + if (abs(dum) < abs(dum2) && + ((dum2 >= 0 && sol_D[jcell].spec[j].c * aq2 < 1e-12) || + (dum2 <= 0 && sol_D[icell].spec[i].c * aq1 < 1e-12))) { - ct[icell].v_m[k].zc = ct[icell].v_m[k].z * ct[icell].v_m[k].c; - ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + // step out: + if (i < i_max) + i++; + if (j < j_max) + j++; + continue; } - ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; - if (fabs(ddlm) > 1e-10) - ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); - k++; } + g_i = g_j = 0; + if (ct[icell].dl_s > 0) + { + if (dl_aq1) + { + for (it_sc = s_charge_p1.begin(); it_sc != s_charge_p1.end(); it_sc++) + { + g_i += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; + } + g_i *= sol_D[icell].spec[i].erm_ddl; + } + if (dl_aq2) + { + for (it_sc = s_charge_p2.begin(); it_sc != s_charge_p2.end(); it_sc++) + { + g_j += it_sc->Get_z_gMCD_map()[ct[icell].v_m[k].z]; + } + g_j *= sol_D[jcell].spec[j].erm_ddl; + } + } + b_i = A1 * sol_D[icell].spec[i].Dwt * (f_free_i + g_i / ct[icell].visc1); + b_j = A2 * sol_D[jcell].spec[j].Dwt * (f_free_j + g_j / ct[icell].visc2); + if (icell == 0 && !stagnant) + ct[icell].v_m[k].b_ij = b_j; + else if (icell == count_cells && !stagnant) + ct[icell].v_m[k].b_ij = b_i; + else + ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); + + if (ct[icell].v_m[k].z) + ct[icell].Dz2c += ct[icell].v_m[k].b_ij * ct[icell].v_m[k].zc * ct[icell].v_m[k].z; + + ddlm = sol_D[jcell].spec[j].lm - sol_D[icell].spec[i].lm; + if (fabs(ddlm) > 1e-10) + ct[icell].v_m[k].grad *= (1 + (sol_D[jcell].spec[j].lg - sol_D[icell].spec[i].lg) / ddlm); + + k++; } if (i < i_max) i++; @@ -3340,53 +3087,22 @@ dV_dcell2: ct[icell].J_ij_sum = 0; Sum_zM = c_dl = 0.0; - if (stagnant) + for (i = 0; i < ct[icell].J_ij_count_spec; i++) { - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - if (ct[icell].v_m[i].z) - { - Sum_zM += ct[icell].v_m[i].Dz * ct[icell].v_m[i].grad; - c_dl += ct[icell].v_m[i].o_c * ct[icell].v_m[i].Dz * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; - } - } - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].D * ct[icell].v_m[i].grad; - if (ct[icell].v_m[i].z && ct[icell].Dz2c > 0) - ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].Dzc / ct[icell].Dz2c; - ct[icell].J_ij[i].tot1 *= (1 - ct[icell].dl_s); - if (ct[icell].dl_s > 0) - { - dum = -ct[icell].v_m[i].D * ct[icell].v_m[i].g_dl * ct[icell].v_m[i].grad; - if (ct[icell].Dz2c_dl > 0) - dum2 = c_dl * ct[icell].v_m[i].Dzc_dl / ct[icell].Dz2c_dl; - else - dum2 = 0; - if (ct[icell].J_ij[i].tot1 * dum >= 0) - ct[icell].J_ij[i].tot1 += ct[icell].v_m[i].o_c * (dum + dum2) * 2 / - (ct[icell].visc1 + ct[icell].visc2) * ct[icell].dl_s; - } - ct[icell].J_ij[i].tot1 *= mixf; - ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; - } + if (ct[icell].v_m[i].z) + Sum_zM += ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * ct[icell].v_m[i].grad; } - else // diffusion in regular column + for (i = 0; i < ct[icell].J_ij_count_spec; i++) { - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - if (ct[icell].v_m[i].z) - Sum_zM += ct[icell].v_m[i].b_ij * ct[icell].v_m[i].z * ct[icell].v_m[i].grad; - } - for (i = 0; i < ct[icell].J_ij_count_spec; i++) - { - ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].grad; - if (!dV_dcell && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) - ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].zc / ct[icell].Dz2c; + ct[icell].J_ij[i].tot1 = -ct[icell].v_m[i].grad; + if (!dV_dcell && ct[icell].v_m[i].z && ct[icell].Dz2c > 0) + ct[icell].J_ij[i].tot1 += Sum_zM * ct[icell].v_m[i].zc / ct[icell].Dz2c; + if (stagnant) + ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * 2 * mixf; + else ct[icell].J_ij[i].tot1 *= ct[icell].v_m[i].b_ij * DDt; - ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; - ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; - } + ct[icell].J_ij[i].tot2 = ct[icell].J_ij[i].tot1; + ct[icell].J_ij_sum += ct[icell].v_m[i].z * ct[icell].J_ij[i].tot1; } // assure that icell has dl water when checking negative conc's in MCD ct[icell].dl_s = dl_aq1; From 7d044e79a6c945cdd638048724c8ae35147ea628 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 9 Mar 2018 11:22:22 -0700 Subject: [PATCH 1076/1077] Tony fixed error with sc2 and aquia --- transport.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/transport.cpp b/transport.cpp index 6ab63ae6..5cdfa574 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1260,6 +1260,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) cxxSolution *ptr_imm, *ptr_m; k = -1000; // compiler says k may be undefined ptr_imm = NULL; + boolean done_mixing = false; /* * Kinetics in transport cell is done while transporting */ @@ -1373,12 +1374,14 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction) } change_surf_count = 0; } + + done_mixing = true; } else if (n == 1 && l_punch) print_punch(i, false); } - if (ptr_imm != NULL) // after all mixing is done, the temporal solution becomes the original for the next timestep + if (done_mixing) // after all mixing is done, the temporal solution becomes the original for the next timestep { for (n = 1; n <= stag_data->count_stag; n++) { @@ -2390,7 +2393,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) LDBLE cec1, cec2, cec12 = 0.0, rc1 = 0.0, rc2 = 0.0; LDBLE dV, c1, c2; cxxSurface *s_ptr1, *s_ptr2; - cxxSurfaceCharge *s_charge_ptr1, *s_charge_ptr2; LDBLE g_i, g_j; //char token[MAX_LENGTH], token1[MAX_LENGTH]; @@ -2443,7 +2445,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) /* * check if DL calculations must be made, find amounts of water... */ - s_charge_ptr1 = s_charge_ptr2 = NULL; s_ptr1 = s_ptr2 = NULL; ct[icell].visc1 = ct[icell].visc2 = 1.0; only_counter = FALSE; @@ -2473,7 +2474,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } } - s_charge_ptr1 = s_ptr1->Find_charge(s_charge_p[0].Get_name()); // appt remove } } s_ptr2 = Utilities::Rxn_find(Rxn_surface_map, jcell); @@ -2501,7 +2501,6 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } } } - s_charge_ptr2 = s_ptr2->Find_charge(s_charge_p[0].Get_name()); // appt remove } } if (!stagnant) @@ -2513,7 +2512,7 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) } //LDBLE d_damper = Utilities::Rxn_find(Rxn_solution_map, jcell)->Get_mu() / // Utilities::Rxn_find(Rxn_solution_map, icell)->Get_mu(); - //d_damper = pow(d_damper, 1); + //d_damper = pow(d_damper, 0.3); //if (d_damper > 1) ct[icell].visc1 *= d_damper; else ct[icell].visc2 *= d_damper; /* in each cell: DL surface = mass_water_DL / (cell_length) @@ -2830,7 +2829,12 @@ find_J(int icell, int jcell, LDBLE mixf, LDBLE DDt, int stagnant) b_j *= dum2; } if (icell == 0 && !stagnant) - ct[icell].v_m[k].b_ij = b_j; + { + //if (d_damper < 1 && g_i == 0) + // ct[icell].v_m[k].b_ij = A2 * sol_D[icell].spec[i].Dwt * (f_free_j + g_j * d_damper / ct[icell].visc2); + //else + ct[icell].v_m[k].b_ij = b_j; + } else ct[icell].v_m[k].b_ij = b_i * b_j / (b_i + b_j); } From 114cea674411a4eea23af8658f29c6e4bd562f8d Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Fri, 16 Mar 2018 17:41:34 -0600 Subject: [PATCH 1077/1077] minor memory leak in fail2 --- tidy.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tidy.cpp b/tidy.cpp index d307a71b..2199e67c 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -3993,6 +3993,7 @@ tidy_min_surface(void) error_string = sformatf("Unknown element definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", surface_ptr->Get_n_user()); error_msg(error_string); + free_check_null(temp_formula); continue; } if (elt_ptr->master->s == NULL || elt_ptr->master->s->name == NULL) @@ -4001,6 +4002,7 @@ tidy_min_surface(void) error_string = sformatf("Unknown master species definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.", surface_ptr->Get_n_user()); error_msg(error_string); + free_check_null(temp_formula); continue; } if (strcmp(elt_ptr->master->s->name, temp_formula) != 0)